From c2c22b7d0b11c145d1e7958af8b0fc8d1b6f9a08 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 25 Jan 2023 10:12:11 +0100 Subject: [PATCH 1/4] useBlockEditorSettings: stop filtering editor settings when syncing --- .../provider/use-block-editor-settings.js | 52 +------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index d20edad89ed7b..2b0d9d021f658 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -131,57 +131,7 @@ function useBlockEditorSettings( settings, hasTemplate ) { return useMemo( () => ( { - ...Object.fromEntries( - Object.entries( settings ).filter( ( [ key ] ) => - [ - '__experimentalBlockDirectory', - '__experimentalDiscussionSettings', - '__experimentalFeatures', - '__experimentalPreferredStyleVariations', - '__experimentalSetIsInserterOpened', - '__unstableGalleryWithImageBlocks', - 'alignWide', - 'allowedBlockTypes', - 'blockInspectorTabs', - 'allowedMimeTypes', - 'bodyPlaceholder', - 'canLockBlocks', - 'codeEditingEnabled', - 'colors', - 'disableCustomColors', - 'disableCustomFontSizes', - 'disableCustomSpacingSizes', - 'disableCustomGradients', - 'disableLayoutStyles', - 'enableCustomLineHeight', - 'enableCustomSpacing', - 'enableCustomUnits', - 'focusMode', - 'fontSizes', - 'gradients', - 'generateAnchors', - 'hasFixedToolbar', - 'isDistractionFree', - 'hasInlineToolbar', - 'imageDefaultSize', - 'imageDimensions', - 'imageEditing', - 'imageSizes', - 'isRTL', - 'keepCaretInsideBlock', - 'maxWidth', - 'onUpdateDefaultBlockStyles', - 'enableOpenverseMediaCategory', - 'styles', - 'template', - 'templateLock', - 'titlePlaceholder', - 'supportsLayout', - 'widgetTypesToHideFromLegacyWidgetBlock', - '__unstableResolvedAssets', - ].includes( key ) - ) - ), + ...settings, mediaUpload: hasUploadPermissions ? mediaUpload : undefined, __experimentalReusableBlocks: reusableBlocks, __experimentalBlockPatterns: blockPatterns, From 8673a94680cbff31a1e1e608a187a1e9fef995fc Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 19 Jan 2023 15:46:59 +0100 Subject: [PATCH 2/4] Sync settings from editor store to block-editor store --- .../editor/src/components/provider/index.js | 29 ++++++++++++------- .../editor/various/font-size-picker.spec.js | 6 ++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 2618fc33ad1a7..eaf9b1bf7d19d 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -39,22 +39,29 @@ export const ExperimentalEditorProvider = withRegistryProvider( } return { postId: post.id, postType: post.type }; }, [ post.id, post.type ] ); - const { selection, isReady } = useSelect( ( select ) => { - const { getEditorSelection, __unstableIsEditorReady } = - select( editorStore ); - return { - isReady: __unstableIsEditorReady(), - selection: getEditorSelection(), - }; - }, [] ); + const { editorSettings, selection, isReady } = useSelect( + ( select ) => { + const { + getEditorSettings, + getEditorSelection, + __unstableIsEditorReady, + } = select( editorStore ); + return { + editorSettings: getEditorSettings(), + isReady: __unstableIsEditorReady(), + selection: getEditorSelection(), + }; + }, + [] + ); const { id, type } = __unstableTemplate ?? post; const [ blocks, onInput, onChange ] = useEntityBlockEditor( 'postType', type, { id } ); - const editorSettings = useBlockEditorSettings( - settings, + const blockEditorSettings = useBlockEditorSettings( + editorSettings, !! __unstableTemplate ); const { @@ -119,7 +126,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( onChange={ onChange } onInput={ onInput } selection={ selection } - settings={ editorSettings } + settings={ blockEditorSettings } useSubRegistry={ false } > { children } diff --git a/test/e2e/specs/editor/various/font-size-picker.spec.js b/test/e2e/specs/editor/various/font-size-picker.spec.js index 38707c12b261b..69ffa68e602cf 100644 --- a/test/e2e/specs/editor/various/font-size-picker.spec.js +++ b/test/e2e/specs/editor/various/font-size-picker.spec.js @@ -92,11 +92,11 @@ test.describe( 'Font Size Picker', () => { return doSet( obj, 0 ); } - window.wp.data.dispatch( 'core/block-editor' ).updateSettings( + window.wp.data.dispatch( 'core/editor' ).updateEditorSettings( setDeep( window.wp.data - .select( 'core/block-editor' ) - .getSettings(), + .select( 'core/editor' ) + .getEditorSettings(), [ '__experimentalFeatures', 'typography', From 047c1b772e7f8de60fa0b2584da78d713c1fddce Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Fri, 20 Jan 2023 11:54:26 +0100 Subject: [PATCH 3/4] Reset supportsLayout default --- packages/editor/src/store/defaults.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/editor/src/store/defaults.js b/packages/editor/src/store/defaults.js index 66bcdc72dd8be..38b79ad9a84cc 100644 --- a/packages/editor/src/store/defaults.js +++ b/packages/editor/src/store/defaults.js @@ -27,5 +27,4 @@ export const EDITOR_SETTINGS_DEFAULTS = { richEditingEnabled: true, codeEditingEnabled: true, enableCustomFields: undefined, - supportsLayout: true, }; From 8943ba3c2743cb7254e9955b830214446b7e6c43 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Fri, 20 Jan 2023 16:31:26 +0100 Subject: [PATCH 4/4] Send updates to editor settings and let them sync to block editor --- .../src/components/provider/index.native.js | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index 5b4148d5efef7..7ecf3c2bac25b 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -92,10 +92,15 @@ class NativeEditorProvider extends Component { } componentDidMount() { - const { capabilities, locale, hostAppNamespace, updateSettings } = - this.props; + const { + capabilities, + locale, + hostAppNamespace, + updateEditorSettings, + updateBlockEditorSettings, + } = this.props; - updateSettings( { + updateEditorSettings( { ...capabilities, ...this.getThemeColors( this.props ), locale, @@ -152,7 +157,9 @@ class NativeEditorProvider extends Component { window.wp.galleryBlockV2Enabled = galleryWithImageBlocks; } - updateSettings( this.getThemeColors( editorSettings ) ); + updateEditorSettings( + this.getThemeColors( editorSettings ) + ); } ); @@ -177,7 +184,7 @@ class NativeEditorProvider extends Component { const impressions = { ...NEW_BLOCK_TYPES, ...storedImpressions }; // Persist impressions to JavaScript store. - updateSettings( { impressions } ); + updateBlockEditorSettings( { impressions } ); // Persist impressions to native store if they do not include latest // `NEW_BLOCK_TYPES` configuration. @@ -318,7 +325,7 @@ class NativeEditorProvider extends Component { } updateCapabilitiesAction( capabilities ) { - this.props.updateSettings( capabilities ); + this.props.updateEditorSettings( capabilities ); } render() { @@ -352,17 +359,14 @@ const ComposedNativeProvider = compose( [ getEditorBlocks, getEditedPostAttribute, getEditedPostContent, + getEditorSettings, } = select( editorStore ); const { getEditorMode } = select( editPostStore ); - const { - getBlockIndex, - getSelectedBlockClientId, - getGlobalBlockCount, - getSettings: getBlockEditorSettings, - } = select( blockEditorStore ); + const { getBlockIndex, getSelectedBlockClientId, getGlobalBlockCount } = + select( blockEditorStore ); - const settings = getBlockEditorSettings(); + const settings = getEditorSettings(); const defaultEditorColors = settings?.colors ?? []; const defaultEditorGradients = settings?.gradients ?? []; @@ -381,7 +385,8 @@ const ComposedNativeProvider = compose( [ }; } ), withDispatch( ( dispatch ) => { - const { editPost, resetEditorBlocks } = dispatch( editorStore ); + const { editPost, resetEditorBlocks, updateEditorSettings } = + dispatch( editorStore ); const { updateSettings, clearSelectedBlock, @@ -393,7 +398,8 @@ const ComposedNativeProvider = compose( [ const { createSuccessNotice } = dispatch( noticesStore ); return { - updateSettings, + updateBlockEditorSettings: updateSettings, + updateEditorSettings, addEntities, clearSelectedBlock, insertBlock,