Skip to content

Commit

Permalink
Move EditorFontsResolver inside EditorStyles, use fontFamilies data f…
Browse files Browse the repository at this point in the history
…rom block-editor store
  • Loading branch information
matiasbenedetto committed Sep 13, 2024
1 parent 65d147a commit c6a32f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
3 changes: 0 additions & 3 deletions packages/block-editor/src/components/block-canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import WritingFlow from '../writing-flow';
import { useMouseMoveTypingReset } from '../observe-typing';
import { useBlockSelectionClearer } from '../block-selection-clearer';
import { useBlockCommands } from '../use-block-commands';
import EditorFontsResolver from '../editor-fonts-resolver';

// EditorStyles is a memoized component, so avoid passing a new
// object reference on each render.
Expand Down Expand Up @@ -44,7 +43,6 @@ export function ExperimentalBlockCanvas( {
__unstableContentRef={ localRef }
style={ { height, display: 'flex' } }
>
<EditorFontsResolver />
<EditorStyles
styles={ styles }
scope=":where(.editor-styles-wrapper)"
Expand Down Expand Up @@ -79,7 +77,6 @@ export function ExperimentalBlockCanvas( {
} }
name="editor-canvas"
>
<EditorFontsResolver />
<EditorStyles styles={ styles } />
{ children }
</Iframe>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { useGlobalSetting } from '../global-styles/hooks';
import { getDisplaySrcFromFontFace, loadFontFaceInBrowser } from './utils';
import { store as editorStore } from '../../store';

function EditorFontsResolver() {
const [ loadedFontUrls, setLoadedFontUrls ] = useState( new Set() );

const { currentTheme } = useSelect( ( select ) => {
const { currentTheme, fontFamilies = [] } = useSelect( ( select ) => {
return {
currentTheme:
// Disable Reason: Using 'core' as string to avoid circular dependency importing from @wordpress/core-data.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
select( 'core' ).getCurrentTheme(),
fontFamilies:
select( editorStore ).getSettings()?.__experimentalFeatures
?.typography?.fontFamilies,
};
}, [] );

// Get the fonts from merged theme.json settings.fontFamilies.
const [ fontFamilies = [] ] = useGlobalSetting( 'typography.fontFamilies' );

const fontFaces = useMemo( () => {
return Object.values( fontFamilies )
.flat()
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/editor-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useSelect } from '@wordpress/data';
import transformStyles from '../../utils/transform-styles';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import EditorFontsResolver from '../editor-fonts-resolver';

extend( [ namesPlugin, a11yPlugin ] );

Expand All @@ -27,7 +28,6 @@ function useDarkThemeBodyClassName( styles, scope ) {
if ( ! node ) {
return;
}

const { ownerDocument } = node;
const { defaultView, body } = ownerDocument;
const canvas = scope ? ownerDocument.querySelector( scope ) : body;
Expand Down Expand Up @@ -122,6 +122,7 @@ function EditorStyles( { styles, scope, transformOptions } ) {
} }
dangerouslySetInnerHTML={ { __html: transformedSvgs } }
/>
<EditorFontsResolver />
</>
);
}
Expand Down

0 comments on commit c6a32f9

Please sign in to comment.