Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): center peek and history dialog does not display custom fonts #9274

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/frontend/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -131,11 +134,13 @@ const HistoryEditorPreview = ({
<AffineErrorBoundary>
<Scrollable.Root>
<Scrollable.Viewport className="affine-page-viewport">
<BlockSuiteEditor
className={styles.editor}
mode={mode}
page={snapshotPage}
/>
<CustomEditorWrapper>
<BlockSuiteEditor
className={styles.editor}
mode={mode}
page={snapshotPage}
/>
</CustomEditorWrapper>
</Scrollable.Viewport>
<Scrollable.Scrollbar />
</Scrollable.Root>
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ edgelessEffects();
registerBlocksuitePresetsCustomComponents();

export * from './blocksuite-editor';
export * from './custom-editor-wrapper';
54 changes: 17 additions & 37 deletions packages/frontend/core/src/components/page-detail-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 (
<Editor
className={clsx(styles.editor, {
'full-screen': !isSharedMode && fullWidthLayout,
'is-public': isSharedMode,
})}
style={
{
'--affine-font-family': value,
} as CSSProperties
}
mode={mode}
defaultOpenProperty={defaultOpenProperty}
page={editor.doc.blockSuiteDoc}
shared={isSharedMode}
onEditorReady={onLoad}
/>
<CustomEditorWrapper>
<Editor
className={clsx(styles.editor, {
'full-screen': !isSharedMode && fullWidthLayout,
'is-public': isSharedMode,
})}
mode={mode}
defaultOpenProperty={defaultOpenProperty}
page={editor.doc.blockSuiteDoc}
shared={isSharedMode}
onEditorReady={onLoad}
/>
</CustomEditorWrapper>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ 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';
Expand Down Expand Up @@ -149,13 +152,15 @@ function DocPeekPreviewEditor({
<Scrollable.Viewport
className={clsx('affine-page-viewport', styles.affineDocViewport)}
>
<BlockSuiteEditor
className={styles.editor}
mode={mode}
page={doc.blockSuiteDoc}
onEditorReady={handleOnEditorReady}
defaultOpenProperty={defaultOpenProperty}
/>
<CustomEditorWrapper>
<BlockSuiteEditor
className={styles.editor}
mode={mode}
page={doc.blockSuiteDoc}
onEditorReady={handleOnEditorReady}
defaultOpenProperty={defaultOpenProperty}
/>
</CustomEditorWrapper>
</Scrollable.Viewport>
<Scrollable.Scrollbar />
</Scrollable.Root>
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading