-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): add CustomEditorWrapper
- Loading branch information
Showing
7 changed files
with
88 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ages/frontend/core/src/components/blocksuite/block-suite-editor/custom-editor-wrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters