Skip to content

Commit

Permalink
fix: app lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Dec 28, 2023
1 parent 851c3a5 commit 3386879
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { atom, useAtomValue, useSetAtom } from 'jotai';
import { atomWithImmer } from 'jotai-immer';

import { selectedSchemaIdAtom } from '@/atoms/modules/sidebar';
import { getAppDatabaseService } from '@/services/indexeddb';
import { SchemaEntity } from '@/services/indexeddb/modules/schema';
import { selectedSchemaIdAtom } from '@/store/modules/sidebar';

const schemaEntitiesAtom = atomWithImmer<Array<Omit<SchemaEntity, 'value'>>>(
[]
Expand Down
2 changes: 1 addition & 1 deletion packages/erd-editor-app/src/components/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Theme } from '@radix-ui/themes';
import { useAtom } from 'jotai';
import { DevTools } from 'jotai-devtools';

import { themeAtom } from '@/atoms/modules/theme';
import Sidebar from '@/components/sidebar/Sidebar';
import Viewer from '@/components/viewer/Viewer';
import { themeAtom } from '@/store/modules/theme';

import * as styles from './App.styles';

Expand Down
8 changes: 4 additions & 4 deletions packages/erd-editor-app/src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { Button, Flex, ScrollArea } from '@radix-ui/themes';
import { useAtom } from 'jotai';
import { useEffect, useState } from 'react';

import SidebarAddItem from '@/components/sidebar/sidebar-add-item/SidebarAddItem';
import SidebarItem from '@/components/sidebar/sidebar-item/SidebarItem';
import {
useAddSchemaEntity,
useDeleteSchemaEntity,
useSchemaEntities,
useUpdateSchemaEntities,
useUpdateSchemaEntity,
} from '@/store/modules/schema';
import { selectedSchemaIdAtom } from '@/store/modules/sidebar';
} from '@/atoms/modules/schema';
import { selectedSchemaIdAtom } from '@/atoms/modules/sidebar';
import SidebarAddItem from '@/components/sidebar/sidebar-add-item/SidebarAddItem';
import SidebarItem from '@/components/sidebar/sidebar-item/SidebarItem';

import * as styles from './Sidebar.styles';

Expand Down
2 changes: 1 addition & 1 deletion packages/erd-editor-app/src/components/viewer/Viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Flex, Link, Text } from '@radix-ui/themes';
import { lazy, Suspense } from 'react';

import { useSchemaEntity } from '@/store/modules/sidebar';
import { useSchemaEntity } from '@/atoms/modules/sidebar';

import * as styles from './Viewer.styles';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import {
ErdEditorElement,
setGetShikiServiceCallback,
} from '@dineug/erd-editor';
import { getShikiService } from '@dineug/erd-editor-shiki-worker';
import { useAtom } from 'jotai';
import { useLayoutEffect, useRef } from 'react';

import { useUpdateSchemaEntityValue } from '@/atoms/modules/sidebar';
import { themeAtom } from '@/atoms/modules/theme';
import { SchemaEntity } from '@/services/indexeddb/modules/schema';
import { useUpdateSchemaEntityValue } from '@/store/modules/sidebar';
import { themeAtom } from '@/store/modules/theme';

import * as styles from './Editor.styles';

setGetShikiServiceCallback(getShikiService);
import('@dineug/erd-editor-shiki-worker').then(({ getShikiService }) => {
setGetShikiServiceCallback(getShikiService);
});

interface EditorProps {
entity: SchemaEntity;
Expand Down
8 changes: 4 additions & 4 deletions packages/erd-editor/src/components/erd-editor/ErdEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const ErdEditor: FC<ErdEditorProps, ErdEditorElement> = (props, ctx) => {
});

const checkAndFocus = () => {
window.setTimeout(() => {
setTimeout(() => {
if (document.activeElement !== ctx) {
ctx.focus();
}
Expand All @@ -126,7 +126,7 @@ const ErdEditor: FC<ErdEditorProps, ErdEditorElement> = (props, ctx) => {
};

let currentFocus = false;
let timerId = -1;
let timerId: any = -1;

const handleFocus = () => {
currentFocus = true;
Expand All @@ -136,8 +136,8 @@ const ErdEditor: FC<ErdEditorProps, ErdEditorElement> = (props, ctx) => {
const handleFocusout = () => {
currentFocus = false;

window.clearTimeout(timerId);
timerId = window.setTimeout(() => {
clearTimeout(timerId);
timerId = setTimeout(() => {
state.isFocus = currentFocus;
}, 10);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const ColumnDataType: FC<ColumnDataTypeProps> = (props, ctx) => {
};

let currentFocus = false;
let timerId = -1;
let timerId: any = -1;

const handleFocus = () => {
currentFocus = true;
Expand All @@ -156,8 +156,8 @@ const ColumnDataType: FC<ColumnDataTypeProps> = (props, ctx) => {

currentFocus = false;

window.clearTimeout(timerId);
timerId = window.setTimeout(() => {
clearTimeout(timerId);
timerId = setTimeout(() => {
const input = root.value?.querySelector('input');
const isFocus = currentFocus && input && props.edit;

Expand Down
2 changes: 1 addition & 1 deletion packages/erd-editor/src/components/erd/useErdShortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function useErdShortcut(ctx: Ctx) {
event.preventDefault();
store.dispatch(focusMoveTableAction$(event.key, event.shiftKey));

window.setTimeout(() => {
setTimeout(() => {
if (
!editor.focusTable ||
isToggleColumnTypes(editor.focusTable.focusType)
Expand Down
2 changes: 1 addition & 1 deletion packages/erd-editor/src/hooks/useDarkMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { observable, onMounted } from '@dineug/r-html';
import { useUnmounted } from '@/hooks/useUnmounted';

export function useDarkMode() {
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
const mediaQuery = globalThis.matchMedia('(prefers-color-scheme: dark)');
const state = observable(
{
isDark: mediaQuery.matches,
Expand Down
2 changes: 1 addition & 1 deletion packages/erd-editor/src/utils/device-detect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const isSafari =
browser.name === BrowserTypes.MobileSafari;

function getIOS13() {
const nav = window.navigator || navigator;
const nav = globalThis.navigator || navigator;
return (
nav &&
(/iPad|iPhone|iPod/.test(nav.platform) ||
Expand Down

0 comments on commit 3386879

Please sign in to comment.