diff --git a/libs/components/editor-blocks/src/blocks/code/CodeView.tsx b/libs/components/editor-blocks/src/blocks/code/CodeView.tsx index 86845789c5..bfdabf0199 100644 --- a/libs/components/editor-blocks/src/blocks/code/CodeView.tsx +++ b/libs/components/editor-blocks/src/blocks/code/CodeView.tsx @@ -39,15 +39,17 @@ import { yaml } from '@codemirror/legacy-modes/mode/yaml'; import { Extension } from '@codemirror/state'; import { BlockPendantProvider, - useOnSelect, + useOnSelectActive, } from '@toeverything/components/editor-core'; import { DuplicateIcon } from '@toeverything/components/icons'; import { Option, Select, styled } from '@toeverything/components/ui'; import { CreateView } from '@toeverything/framework/virgo'; import { copyToClipboard } from '@toeverything/utils'; + import { elixir } from 'codemirror-lang-elixir'; import { useEffect, useRef, useState } from 'react'; import { StyleWithAtRules } from 'style9'; + import CodeMirror, { ReactCodeMirrorRef } from './CodeMirror'; interface CreateCodeView extends CreateView { @@ -147,7 +149,8 @@ export const CodeView = ({ block, editor }: CreateCodeView) => { codeMirror?.current?.view?.focus(); } }; - useOnSelect(block.id, (_is_select: boolean) => { + //TODO listen codeMirror.up down event , active + useOnSelectActive(block.id, () => { focusCode(); }); const onChange = (value: string) => { @@ -161,9 +164,9 @@ export const CodeView = ({ block, editor }: CreateCodeView) => { }; useEffect(() => { handleLangChange(langType ? langType : DEFAULT_LANG); - setTimeout(() => { - focusCode(); - }, 100); + // setTimeout(() => { + // focusCode(); + // }, 100); }, []); const copyCode = () => { diff --git a/libs/components/editor-blocks/src/blocks/code/index.ts b/libs/components/editor-blocks/src/blocks/code/index.ts index 4239add745..e7d06cb00a 100644 --- a/libs/components/editor-blocks/src/blocks/code/index.ts +++ b/libs/components/editor-blocks/src/blocks/code/index.ts @@ -1,21 +1,21 @@ +import { Protocol } from '@toeverything/datasource/db-service'; import { - BaseView, AsyncBlock, + BaseView, BlockEditor, HTML2BlockResult, } from '@toeverything/framework/virgo'; -import { Protocol } from '@toeverything/datasource/db-service'; -import { CodeView } from './CodeView'; import { Block2HtmlProps, commonBlock2HtmlContent, commonHTML2block, } from '../../utils/commonBlockClip'; +import { CodeView } from './CodeView'; export class CodeBlock extends BaseView { type = Protocol.Block.Type.code; public override selectable = true; - public override editable = false; + public override editable = true; // View = CodeView; View = CodeView; override async onCreate(block: AsyncBlock): Promise { diff --git a/libs/components/editor-blocks/src/blocks/text/TextView.tsx b/libs/components/editor-blocks/src/blocks/text/TextView.tsx index 402c648287..baae481c91 100644 --- a/libs/components/editor-blocks/src/blocks/text/TextView.tsx +++ b/libs/components/editor-blocks/src/blocks/text/TextView.tsx @@ -97,6 +97,23 @@ export const TextView = ({ const onBackspace: TextProps['handleBackSpace'] = editor.withBatch( async props => { const { isCollAndStart } = props; + const activeBlockIds = + editor.selectionManager.getSelectedNodesIds(); + + // when only one group selected , remove this group block + if (activeBlockIds && activeBlockIds.length === 1) { + const activeBlock = await editor.getBlockById( + activeBlockIds[0] + ); + + if ( + activeBlock && + activeBlock.type === Protocol.Block.Type.group + ) { + await activeBlock.remove(); + return true; + } + } if (!isCollAndStart) { return false; } diff --git a/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx b/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx index 4b32a9da43..df3ab85abb 100644 --- a/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx +++ b/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx @@ -406,6 +406,7 @@ export const TextManage = forwardRef( textRef.current.isEmpty() || textRef.current.isSelectAll(); const ifSelectGroup = await selectGroupBlocks(isSelectAll); + if (ifSelectGroup) { return false; } diff --git a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx index 2772ec0d41..1bdda4e739 100644 --- a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx +++ b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx @@ -118,7 +118,7 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => { ?.getRangeAt(0) ?.getBoundingClientRect(); if (rect) { - let rectTop = rect.top; + const rectTop = rect.top; const clientHeight = document.documentElement.clientHeight; @@ -224,8 +224,10 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => { await commonCommandMenuHandler(blockId, type, editor); } const block = await editor.getBlockById(blockId); - let nextBlock = await block.nextSibling(); - editor.selectionManager.activeNodeByNodeId(nextBlock.id); + const nextBlock = await block.nextSibling(); + setTimeout(() => { + editor.selectionManager.activeNodeByNodeId(nextBlock.id); + }); if (block.blockProvider.isEmpty()) { block.remove(); } diff --git a/libs/components/layout/package.json b/libs/components/layout/package.json index d7a0a26481..a36a746d84 100644 --- a/libs/components/layout/package.json +++ b/libs/components/layout/package.json @@ -11,9 +11,7 @@ "@mui/icons-material": "^5.8.4", "clsx": "^1.2.1", "date-fns": "^2.29.2", - "i18next": "^21.9.1", "jotai": "^1.8.1", - "react-i18next": "^11.18.4", "tinycolor2": "^1.4.2", "turndown": "7.1.1" }, diff --git a/libs/components/layout/src/header/FileSystem.tsx b/libs/components/layout/src/header/FileSystem.tsx index 30c2b68816..5e8440b4ce 100644 --- a/libs/components/layout/src/header/FileSystem.tsx +++ b/libs/components/layout/src/header/FileSystem.tsx @@ -3,8 +3,9 @@ import { useCallback, useMemo, useState } from 'react'; import { CloseIcon } from '@toeverything/components/common'; import { IconButton, MuiSnackbar, styled } from '@toeverything/components/ui'; import { services } from '@toeverything/datasource/db-service'; +import { useTranslation } from '@toeverything/datasource/i18n'; import { useLocalTrigger } from '@toeverything/datasource/state'; -import { useTranslation } from 'react-i18next'; + const cleanupWorkspace = (workspace: string) => new Promise((resolve, reject) => { const req = indexedDB.deleteDatabase(workspace); diff --git a/libs/components/layout/src/header/LayoutHeader.tsx b/libs/components/layout/src/header/LayoutHeader.tsx index 9b104b4442..e6ab719a5a 100644 --- a/libs/components/layout/src/header/LayoutHeader.tsx +++ b/libs/components/layout/src/header/LayoutHeader.tsx @@ -5,13 +5,13 @@ import { SideBarViewIcon, } from '@toeverything/components/icons'; import { IconButton, styled } from '@toeverything/components/ui'; +import { useTranslation } from '@toeverything/datasource/i18n'; import { useCurrentEditors, useLocalTrigger, useShowSettingsSidebar, } from '@toeverything/datasource/state'; import { useCallback, useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; import { EditorBoardSwitcher } from './EditorBoardSwitcher'; import { fsApiSupported } from './FileSystem'; import { CurrentPageTitle } from './Title'; diff --git a/libs/components/layout/src/i18n/index.ts b/libs/components/layout/src/i18n/index.ts deleted file mode 100644 index 20f4e2a3ce..0000000000 --- a/libs/components/layout/src/i18n/index.ts +++ /dev/null @@ -1,40 +0,0 @@ -import i18next from 'i18next'; -import { initReactI18next } from 'react-i18next'; -import en_US from './resources/en.json'; -import zh_CN from './resources/zh.json'; - -// See https://react.i18next.com/latest/typescript -declare module 'react-i18next' { - // and extend them! - interface CustomTypeOptions { - // custom namespace type if you changed it - defaultNS: 'ns1'; - // custom resources type - resources: { - en: typeof en_US.translation; - zh: typeof zh_CN.translation; - }; - } -} - -const resources = { - en: en_US, - zh: zh_CN, -} as const; - -i18next.use(initReactI18next).init({ - lng: 'en', - fallbackLng: 'en', - - resources, - interpolation: { - escapeValue: false, // not needed for react as it escapes by default - }, -}); - -export const options = [ - { value: 'en', text: 'English' }, - { value: 'zh', text: '简体中文' }, -] as const; - -export { i18next }; diff --git a/libs/components/layout/src/i18n/resources/en.json b/libs/components/layout/src/i18n/resources/en.json deleted file mode 100644 index 4c6a714e9b..0000000000 --- a/libs/components/layout/src/i18n/resources/en.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "translation": { - "Sync to Disk": "Sync to Disk", - "Share": "Share", - "WarningTips": { - "IsNotfsApiSupported": "Welcome to the AFFiNE demo. To begin saving changes you can SYNC DATA TO DISK with the latest version of Chromium based browser like Chrome/Edge", - "IsNotLocalWorkspace": "Welcome to the AFFiNE demo. To begin saving changes you can SYNC TO DISK.", - "DoNotStore": "AFFiNE is under active development and the current version is UNSTABLE. Please DO NOT store information or data" - }, - "Layout": "Layout", - "Comment": "Comment", - "Settings": "Settings", - "ComingSoon": "Layout Settings Coming Soon...", - "Duplicate Page": "Duplicate Page", - "Copy Page Link": "Copy Page Link", - "Language": "Language", - "Clear Workspace": "Clear Workspace", - "Export As Markdown": "Export As Markdown", - "Export As HTML": "Export As HTML", - "Export As PDF (Unsupported)": "Export As PDF (Unsupported)", - "Import Workspace": "Import Workspace", - "Export Workspace": "Export Workspace", - "Last edited by": "Last edited by {{name}}", - "Logout": "Logout" - } -} diff --git a/libs/components/layout/src/i18n/resources/zh.json b/libs/components/layout/src/i18n/resources/zh.json deleted file mode 100644 index da86cef6b2..0000000000 --- a/libs/components/layout/src/i18n/resources/zh.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "translation": { - "Sync to Disk": "同步到磁盘", - "Share": "分享", - "WarningTips": { - "IsNotfsApiSupported": "欢迎来到AFFiNE 的演示界面。您可以使用最新版本的基于Chrome的浏览器(如Chrome/Edge)将数据同步到磁盘来进行保存", - "IsNotLocalWorkspace": "欢迎来到AFFiNE 的演示界面,您可以同步到磁盘来进行保存操作。", - "DoNotStore": "AFFINE 正在积极开发中,当前版本不稳定。请不要存储信息或数据。" - }, - "ComingSoon": "布局设置即将到来", - "Layout": "布局", - "Comment": "评论", - "Settings": "设置", - "Duplicate Page": "复制页面", - "Copy Page Link": "复制页面链接", - "Language": "当前语言", - "Clear Workspace": "清空工作区域", - "Export As Markdown": "导出 markdown", - "Export As HTML": "导出 HTML", - "Export As PDF (Unsupported)": "导出 PDF (暂不支持)", - "Import Workspace": "导入 Workspace", - "Export Workspace": "导出 Workspace", - "Last edited by": "最后编辑者为 {{name}}", - "Logout": "退出登录" - } -} diff --git a/libs/components/layout/src/index.ts b/libs/components/layout/src/index.ts index 1aee5a687f..69a6d3ff72 100644 --- a/libs/components/layout/src/index.ts +++ b/libs/components/layout/src/index.ts @@ -1,4 +1,3 @@ export * from './header'; -export * from './i18n'; export * from './settings-sidebar'; export * from './workspace-sidebar'; diff --git a/libs/components/layout/src/settings-sidebar/ContainerTabs/ContainerTabs.tsx b/libs/components/layout/src/settings-sidebar/ContainerTabs/ContainerTabs.tsx index 4503482d05..3aab18642c 100644 --- a/libs/components/layout/src/settings-sidebar/ContainerTabs/ContainerTabs.tsx +++ b/libs/components/layout/src/settings-sidebar/ContainerTabs/ContainerTabs.tsx @@ -4,8 +4,8 @@ import { SettingsIcon, } from '@toeverything/components/icons'; import { styled } from '@toeverything/components/ui'; +import { useTranslation } from '@toeverything/datasource/i18n'; import { cloneElement, useCallback, useMemo, type ReactElement } from 'react'; -import { useTranslation } from 'react-i18next'; import { Comments } from '../Comments'; import { useActiveComment } from '../Comments/use-comments'; import { LayoutSettings } from '../Layout'; diff --git a/libs/components/layout/src/settings-sidebar/Settings/SettingsList.tsx b/libs/components/layout/src/settings-sidebar/Settings/SettingsList.tsx index f462ccf572..a308614d13 100644 --- a/libs/components/layout/src/settings-sidebar/Settings/SettingsList.tsx +++ b/libs/components/layout/src/settings-sidebar/Settings/SettingsList.tsx @@ -6,8 +6,7 @@ import { styled, Switch, } from '@toeverything/components/ui'; -import { useTranslation } from 'react-i18next'; -import { options } from '../../i18n'; +import { LOCALES, useTranslation } from '@toeverything/datasource/i18n'; import { useSettings } from './use-settings'; export const SettingsList = () => { @@ -52,7 +51,7 @@ export const SettingsList = () => { defaultValue={i18n.language} onChange={changeLanguage} > - {options.map(option => ( + {LOCALES.map(option => (