fix(core): center peek and history dialog does not display custom fonts (#9274)
close AF-1806
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
"@radix-ui/react-dialog": "^1.1.3",
|
"@radix-ui/react-dialog": "^1.1.3",
|
||||||
"@radix-ui/react-popover": "^1.1.3",
|
"@radix-ui/react-popover": "^1.1.3",
|
||||||
"@radix-ui/react-scroll-area": "^1.2.2",
|
"@radix-ui/react-scroll-area": "^1.2.2",
|
||||||
|
"@radix-ui/react-slot": "^1.1.1",
|
||||||
"@radix-ui/react-toolbar": "^1.1.1",
|
"@radix-ui/react-toolbar": "^1.1.1",
|
||||||
"@sentry/react": "^8.44.0",
|
"@sentry/react": "^8.44.0",
|
||||||
"@toeverything/infra": "workspace:*",
|
"@toeverything/infra": "workspace:*",
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ import {
|
|||||||
import { encodeStateAsUpdate } from 'yjs';
|
import { encodeStateAsUpdate } from 'yjs';
|
||||||
|
|
||||||
import { pageHistoryModalAtom } from '../../atoms/page-history';
|
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 { PureEditorModeSwitch } from '../../blocksuite/block-suite-mode-switch';
|
||||||
import { AffineErrorBoundary } from '../affine-error-boundary';
|
import { AffineErrorBoundary } from '../affine-error-boundary';
|
||||||
import {
|
import {
|
||||||
@@ -128,11 +131,13 @@ const HistoryEditorPreview = ({
|
|||||||
<AffineErrorBoundary>
|
<AffineErrorBoundary>
|
||||||
<Scrollable.Root>
|
<Scrollable.Root>
|
||||||
<Scrollable.Viewport className="affine-page-viewport">
|
<Scrollable.Viewport className="affine-page-viewport">
|
||||||
|
<CustomEditorWrapper>
|
||||||
<BlockSuiteEditor
|
<BlockSuiteEditor
|
||||||
className={styles.editor}
|
className={styles.editor}
|
||||||
mode={mode}
|
mode={mode}
|
||||||
page={snapshotPage}
|
page={snapshotPage}
|
||||||
/>
|
/>
|
||||||
|
</CustomEditorWrapper>
|
||||||
</Scrollable.Viewport>
|
</Scrollable.Viewport>
|
||||||
<Scrollable.Scrollbar />
|
<Scrollable.Scrollbar />
|
||||||
</Scrollable.Root>
|
</Scrollable.Root>
|
||||||
|
|||||||
@@ -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 (
|
||||||
|
<Slot
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
'--affine-font-family': value,
|
||||||
|
} as CSSProperties
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Slot>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -10,3 +10,4 @@ edgelessEffects();
|
|||||||
registerBlocksuitePresetsCustomComponents();
|
registerBlocksuitePresetsCustomComponents();
|
||||||
|
|
||||||
export * from './blocksuite-editor';
|
export * from './blocksuite-editor';
|
||||||
|
export * from './custom-editor-wrapper';
|
||||||
|
|||||||
@@ -2,18 +2,15 @@ import './page-detail-editor.css';
|
|||||||
|
|
||||||
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
||||||
import { useLiveData, useService } from '@toeverything/infra';
|
import { useLiveData, useService } from '@toeverything/infra';
|
||||||
import { cssVar } from '@toeverything/theme';
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import type { CSSProperties } from 'react';
|
|
||||||
import { useMemo } from 'react';
|
|
||||||
|
|
||||||
import { DocService } from '../modules/doc';
|
import { DocService } from '../modules/doc';
|
||||||
import { EditorService } from '../modules/editor';
|
import { EditorService } from '../modules/editor';
|
||||||
|
import { EditorSettingService } from '../modules/editor-setting';
|
||||||
import {
|
import {
|
||||||
EditorSettingService,
|
BlockSuiteEditor as Editor,
|
||||||
fontStyleOptions,
|
CustomEditorWrapper,
|
||||||
} from '../modules/editor-setting';
|
} from './blocksuite/block-suite-editor';
|
||||||
import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor';
|
|
||||||
import * as styles from './page-detail-editor.css';
|
import * as styles from './page-detail-editor.css';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -50,36 +47,19 @@ export const PageDetailEditor = ({ onLoad }: PageDetailEditorProps) => {
|
|||||||
? pageWidth === 'fullWidth'
|
? pageWidth === 'fullWidth'
|
||||||
: settings.fullWidthLayout;
|
: 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 (
|
return (
|
||||||
|
<CustomEditorWrapper>
|
||||||
<Editor
|
<Editor
|
||||||
className={clsx(styles.editor, {
|
className={clsx(styles.editor, {
|
||||||
'full-screen': !isSharedMode && fullWidthLayout,
|
'full-screen': !isSharedMode && fullWidthLayout,
|
||||||
'is-public': isSharedMode,
|
'is-public': isSharedMode,
|
||||||
})}
|
})}
|
||||||
style={
|
|
||||||
{
|
|
||||||
'--affine-font-family': value,
|
|
||||||
} as CSSProperties
|
|
||||||
}
|
|
||||||
mode={mode}
|
mode={mode}
|
||||||
defaultOpenProperty={defaultOpenProperty}
|
defaultOpenProperty={defaultOpenProperty}
|
||||||
page={editor.doc.blockSuiteDoc}
|
page={editor.doc.blockSuiteDoc}
|
||||||
shared={isSharedMode}
|
shared={isSharedMode}
|
||||||
onEditorReady={onLoad}
|
onEditorReady={onLoad}
|
||||||
/>
|
/>
|
||||||
|
</CustomEditorWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import { Scrollable } from '@affine/component';
|
|||||||
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
|
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
|
||||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||||
import { AffineErrorBoundary } from '@affine/core/components/affine/affine-error-boundary';
|
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 { EditorOutlineViewer } from '@affine/core/components/blocksuite/outline-viewer';
|
||||||
import { PageNotFound } from '@affine/core/desktop/pages/404';
|
import { PageNotFound } from '@affine/core/desktop/pages/404';
|
||||||
import { EditorService } from '@affine/core/modules/editor';
|
import { EditorService } from '@affine/core/modules/editor';
|
||||||
@@ -153,6 +156,7 @@ function DocPeekPreviewEditor({
|
|||||||
<Scrollable.Viewport
|
<Scrollable.Viewport
|
||||||
className={clsx('affine-page-viewport', styles.affineDocViewport)}
|
className={clsx('affine-page-viewport', styles.affineDocViewport)}
|
||||||
>
|
>
|
||||||
|
<CustomEditorWrapper>
|
||||||
<BlockSuiteEditor
|
<BlockSuiteEditor
|
||||||
className={styles.editor}
|
className={styles.editor}
|
||||||
mode={mode}
|
mode={mode}
|
||||||
@@ -160,6 +164,7 @@ function DocPeekPreviewEditor({
|
|||||||
onEditorReady={handleOnEditorReady}
|
onEditorReady={handleOnEditorReady}
|
||||||
defaultOpenProperty={defaultOpenProperty}
|
defaultOpenProperty={defaultOpenProperty}
|
||||||
/>
|
/>
|
||||||
|
</CustomEditorWrapper>
|
||||||
</Scrollable.Viewport>
|
</Scrollable.Viewport>
|
||||||
<Scrollable.Scrollbar />
|
<Scrollable.Scrollbar />
|
||||||
</Scrollable.Root>
|
</Scrollable.Root>
|
||||||
|
|||||||
@@ -379,6 +379,7 @@ __metadata:
|
|||||||
"@radix-ui/react-dialog": "npm:^1.1.3"
|
"@radix-ui/react-dialog": "npm:^1.1.3"
|
||||||
"@radix-ui/react-popover": "npm:^1.1.3"
|
"@radix-ui/react-popover": "npm:^1.1.3"
|
||||||
"@radix-ui/react-scroll-area": "npm:^1.2.2"
|
"@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"
|
"@radix-ui/react-toolbar": "npm:^1.1.1"
|
||||||
"@sentry/react": "npm:^8.44.0"
|
"@sentry/react": "npm:^8.44.0"
|
||||||
"@swc/core": "npm:^1.10.1"
|
"@swc/core": "npm:^1.10.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user