diff --git a/packages/frontend/core/package.json b/packages/frontend/core/package.json index d017c9fc47020..9c5523362fb89 100644 --- a/packages/frontend/core/package.json +++ b/packages/frontend/core/package.json @@ -34,6 +34,7 @@ "@radix-ui/react-dialog": "^1.1.3", "@radix-ui/react-popover": "^1.1.3", "@radix-ui/react-scroll-area": "^1.2.2", + "@radix-ui/react-slot": "^1.1.1", "@radix-ui/react-toolbar": "^1.1.1", "@sentry/react": "^8.44.0", "@toeverything/pdf-viewer": "^0.1.1", diff --git a/packages/frontend/core/src/components/affine/page-history-modal/history-modal.tsx b/packages/frontend/core/src/components/affine/page-history-modal/history-modal.tsx index e66774cebe888..d3a4cedb1c739 100644 --- a/packages/frontend/core/src/components/affine/page-history-modal/history-modal.tsx +++ b/packages/frontend/core/src/components/affine/page-history-modal/history-modal.tsx @@ -33,7 +33,10 @@ import { import { encodeStateAsUpdate } from 'yjs'; import { pageHistoryModalAtom } from '../../atoms/page-history'; -import { BlockSuiteEditor } from '../../blocksuite/block-suite-editor'; +import { + BlockSuiteEditor, + CustomEditorWrapper, +} from '../../blocksuite/block-suite-editor'; import { PureEditorModeSwitch } from '../../blocksuite/block-suite-mode-switch'; import { AffineErrorBoundary } from '../affine-error-boundary'; import { @@ -131,11 +134,13 @@ const HistoryEditorPreview = ({ - + + + diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/custom-editor-wrapper.tsx b/packages/frontend/core/src/components/blocksuite/block-suite-editor/custom-editor-wrapper.tsx new file mode 100644 index 0000000000000..edc617ad91242 --- /dev/null +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/custom-editor-wrapper.tsx @@ -0,0 +1,43 @@ +import { + EditorSettingService, + fontStyleOptions, +} from '@affine/core/modules/editor-setting'; +import { Slot } from '@radix-ui/react-slot'; +import { useLiveData, useService } from '@toeverything/infra'; +import { cssVar } from '@toeverything/theme'; +import { type CSSProperties, type ReactNode, useMemo } from 'react'; +export const CustomEditorWrapper = ({ children }: { children: ReactNode }) => { + const editorSetting = useService(EditorSettingService).editorSetting; + const settings = useLiveData( + editorSetting.settings$.selector(s => ({ + fontFamily: s.fontFamily, + customFontFamily: s.customFontFamily, + fullWidthLayout: s.fullWidthLayout, + })) + ); + const value = useMemo(() => { + const fontStyle = fontStyleOptions.find( + option => option.key === settings.fontFamily + ); + if (!fontStyle) { + return cssVar('fontSansFamily'); + } + const customFontFamily = settings.customFontFamily; + + return customFontFamily && fontStyle.key === 'Custom' + ? `${customFontFamily}, ${fontStyle.value}` + : fontStyle.value; + }, [settings.customFontFamily, settings.fontFamily]); + + return ( + + {children} + + ); +}; diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/index.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/index.ts index c5b3d3f00cba0..fe3efebcea1c2 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/index.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/index.ts @@ -10,3 +10,4 @@ edgelessEffects(); registerBlocksuitePresetsCustomComponents(); export * from './blocksuite-editor'; +export * from './custom-editor-wrapper'; diff --git a/packages/frontend/core/src/components/page-detail-editor.tsx b/packages/frontend/core/src/components/page-detail-editor.tsx index a50387520bba4..c74950f14e95c 100644 --- a/packages/frontend/core/src/components/page-detail-editor.tsx +++ b/packages/frontend/core/src/components/page-detail-editor.tsx @@ -2,18 +2,15 @@ import './page-detail-editor.css'; import type { AffineEditorContainer } from '@blocksuite/affine/presets'; import { useLiveData, useService } from '@toeverything/infra'; -import { cssVar } from '@toeverything/theme'; import clsx from 'clsx'; -import type { CSSProperties } from 'react'; -import { useMemo } from 'react'; import { DocService } from '../modules/doc'; import { EditorService } from '../modules/editor'; +import { EditorSettingService } from '../modules/editor-setting'; import { - EditorSettingService, - fontStyleOptions, -} from '../modules/editor-setting'; -import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor'; + BlockSuiteEditor as Editor, + CustomEditorWrapper, +} from './blocksuite/block-suite-editor'; import * as styles from './page-detail-editor.css'; declare global { @@ -50,36 +47,19 @@ export const PageDetailEditor = ({ onLoad }: PageDetailEditorProps) => { ? pageWidth === 'fullWidth' : settings.fullWidthLayout; - const value = useMemo(() => { - const fontStyle = fontStyleOptions.find( - option => option.key === settings.fontFamily - ); - if (!fontStyle) { - return cssVar('fontSansFamily'); - } - const customFontFamily = settings.customFontFamily; - - return customFontFamily && fontStyle.key === 'Custom' - ? `${customFontFamily}, ${fontStyle.value}` - : fontStyle.value; - }, [settings.customFontFamily, settings.fontFamily]); - return ( - + + + ); }; diff --git a/packages/frontend/core/src/modules/peek-view/view/doc-preview/doc-peek-view.tsx b/packages/frontend/core/src/modules/peek-view/view/doc-preview/doc-peek-view.tsx index 3b10c4a1d8ff1..825a367468c1a 100644 --- a/packages/frontend/core/src/modules/peek-view/view/doc-preview/doc-peek-view.tsx +++ b/packages/frontend/core/src/modules/peek-view/view/doc-preview/doc-peek-view.tsx @@ -2,14 +2,13 @@ import { Scrollable } from '@affine/component'; import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton'; import { AIProvider } from '@affine/core/blocksuite/presets/ai'; import { AffineErrorBoundary } from '@affine/core/components/affine/affine-error-boundary'; -import { BlockSuiteEditor } from '@affine/core/components/blocksuite/block-suite-editor'; +import { + BlockSuiteEditor, + CustomEditorWrapper, +} from '@affine/core/components/blocksuite/block-suite-editor'; import { EditorOutlineViewer } from '@affine/core/components/blocksuite/outline-viewer'; import { PageNotFound } from '@affine/core/desktop/pages/404'; import { EditorService } from '@affine/core/modules/editor'; -import { - EditorSettingService, - fontStyleOptions, -} from '@affine/core/modules/editor-setting'; import { DebugLogger } from '@affine/debug'; import { type EdgelessRootService, @@ -23,9 +22,8 @@ import { useService, useServices, } from '@toeverything/infra'; -import { cssVar } from '@toeverything/theme'; import clsx from 'clsx'; -import { type CSSProperties, useCallback, useEffect, useMemo } from 'react'; +import { useCallback, useEffect } from 'react'; import { WorkbenchService } from '../../../workbench'; import type { DocReferenceInfo } from '../../entities/peek-view'; @@ -90,14 +88,6 @@ function DocPeekPreviewEditor({ const workbench = useService(WorkbenchService).workbench; const peekView = useService(PeekViewService).peekView; const editorElement = useLiveData(editor.editorContainer$); - const editorSetting = useService(EditorSettingService).editorSetting; - const settings = useLiveData( - editorSetting.settings$.selector(s => ({ - fontFamily: s.fontFamily, - customFontFamily: s.customFontFamily, - fullWidthLayout: s.fullWidthLayout, - })) - ); const handleOnEditorReady = useCallback( (editorContainer: AffineEditorContainer) => { @@ -156,38 +146,21 @@ function DocPeekPreviewEditor({ peekView.close(); }, [doc, peekView, workbench]); - const value = useMemo(() => { - const fontStyle = fontStyleOptions.find( - option => option.key === settings.fontFamily - ); - if (!fontStyle) { - return cssVar('fontSansFamily'); - } - const customFontFamily = settings.customFontFamily; - - return customFontFamily && fontStyle.key === 'Custom' - ? `${customFontFamily}, ${fontStyle.value}` - : fontStyle.value; - }, [settings.customFontFamily, settings.fontFamily]); - return ( - + + + diff --git a/yarn.lock b/yarn.lock index 08b98ec18ebed..2533805b58f75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -370,6 +370,7 @@ __metadata: "@radix-ui/react-dialog": "npm:^1.1.3" "@radix-ui/react-popover": "npm:^1.1.3" "@radix-ui/react-scroll-area": "npm:^1.2.2" + "@radix-ui/react-slot": "npm:^1.1.1" "@radix-ui/react-toolbar": "npm:^1.1.1" "@sentry/react": "npm:^8.44.0" "@swc/core": "npm:^1.10.1"