From 4d64fd1e9f9af0a0f5f162d3ffe9faf18e15f0d3 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Wed, 1 Feb 2023 14:05:32 +0800 Subject: [PATCH 1/2] Stabilize the clearBlockSelection editor setting --- packages/block-editor/README.md | 2 +- .../src/components/block-selection-clearer/index.js | 2 +- .../src/components/block-selection-clearer/test/index.js | 4 ++-- packages/block-editor/src/store/defaults.js | 6 ++++-- .../src/components/provider/use-block-editor-settings.js | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 92d724e80027b0..19433e516f4f5d 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -679,8 +679,8 @@ _Properties_ - _codeEditingEnabled_ `boolean`: Whether or not the user can switch to the code editor - _generateAnchors_ `boolean`: Enable/Disable auto anchor generation for Heading blocks - _enableOpenverseMediaCategory_ `boolean`: Enable/Disable the Openverse media category in the inserter. +- _clearBlockSelection_ `boolean`: Whether the block editor should clear selection on mousedown when a block is not clicked. - _\_\_experimentalCanUserUseUnfilteredHTML_ `boolean`: Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes. -- _\_\_experimentalClearBlockSelection_ `boolean`: Whether the block editor should clear selection on mousedown when a block is not clicked. - _\_\_experimentalBlockDirectory_ `boolean`: Whether the user has enabled the Block Directory - _\_\_experimentalBlockPatterns_ `Array`: Array of objects representing the block patterns - _\_\_experimentalBlockPatternCategories_ `Array`: Array of objects representing the block pattern categories diff --git a/packages/block-editor/src/components/block-selection-clearer/index.js b/packages/block-editor/src/components/block-selection-clearer/index.js index ca2d5eae9e619d..b22fc7ab708101 100644 --- a/packages/block-editor/src/components/block-selection-clearer/index.js +++ b/packages/block-editor/src/components/block-selection-clearer/index.js @@ -20,7 +20,7 @@ export function useBlockSelectionClearer() { const { getSettings, hasSelectedBlock, hasMultiSelection } = useSelect( blockEditorStore ); const { clearSelectedBlock } = useDispatch( blockEditorStore ); - const { __experimentalClearBlockSelection: isEnabled } = getSettings(); + const { clearBlockSelection: isEnabled } = getSettings(); return useRefEffect( ( node ) => { diff --git a/packages/block-editor/src/components/block-selection-clearer/test/index.js b/packages/block-editor/src/components/block-selection-clearer/test/index.js index f4ccf1b6326492..bee73647876e60 100644 --- a/packages/block-editor/src/components/block-selection-clearer/test/index.js +++ b/packages/block-editor/src/components/block-selection-clearer/test/index.js @@ -17,7 +17,7 @@ const defaultUseSelectValues = { hasSelectedBlock: jest.fn().mockReturnValue( false ), hasMultiSelection: jest.fn().mockReturnValue( false ), getSettings: jest.fn().mockReturnValue( { - __experimentalClearBlockSelection: true, + clearBlockSelection: true, } ), }; @@ -98,7 +98,7 @@ describe( 'BlockSelectionClearer component', () => { ...defaultUseSelectValues, hasSelectedBlock: jest.fn().mockReturnValue( true ), getSettings: jest.fn().mockReturnValue( { - __experimentalClearBlockSelection: false, + clearBlockSelection: false, } ), } ) ); useDispatch.mockImplementation( () => ( { diff --git a/packages/block-editor/src/store/defaults.js b/packages/block-editor/src/store/defaults.js index f8e7ab64116ce2..5537c16dea2f47 100644 --- a/packages/block-editor/src/store/defaults.js +++ b/packages/block-editor/src/store/defaults.js @@ -27,8 +27,8 @@ export const PREFERENCES_DEFAULTS = { * @property {boolean} codeEditingEnabled Whether or not the user can switch to the code editor * @property {boolean} generateAnchors Enable/Disable auto anchor generation for Heading blocks * @property {boolean} enableOpenverseMediaCategory Enable/Disable the Openverse media category in the inserter. + * @property {boolean} clearBlockSelection Whether the block editor should clear selection on mousedown when a block is not clicked. * @property {boolean} __experimentalCanUserUseUnfilteredHTML Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes. - * @property {boolean} __experimentalClearBlockSelection Whether the block editor should clear selection on mousedown when a block is not clicked. * @property {boolean} __experimentalBlockDirectory Whether the user has enabled the Block Directory * @property {Array} __experimentalBlockPatterns Array of objects representing the block patterns * @property {Array} __experimentalBlockPatternCategories Array of objects representing the block pattern categories @@ -160,8 +160,10 @@ export const SETTINGS_DEFAULTS = { // Allows to disable Openverse media category in the inserter. enableOpenverseMediaCategory: true, + // Is the selected block cleared upon deselection. + clearBlockSelection: true, + __experimentalCanUserUseUnfilteredHTML: false, - __experimentalClearBlockSelection: true, __experimentalBlockDirectory: false, __mobileEnablePageTemplates: false, __experimentalBlockPatterns: [], 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 c0b102d8e9b3e2..8fbd2cdd548239 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -22,7 +22,6 @@ const EMPTY_BLOCKS_LIST = []; const BLOCK_EDITOR_SETTINGS = [ '__experimentalBlockDirectory', '__experimentalBlockInspectorAnimation', - '__experimentalClearBlockSelection', '__experimentalDiscussionSettings', '__experimentalFeatures', '__experimentalGlobalStylesBaseStyles', @@ -36,6 +35,7 @@ const BLOCK_EDITOR_SETTINGS = [ 'bodyPlaceholder', 'canLockBlocks', 'capabilities', + 'clearBlockSelection', 'codeEditingEnabled', 'colors', 'disableCustomColors', From 7c6c700644db088c2436e3d3d24515c54cbcb2a3 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Wed, 1 Feb 2023 14:47:46 +0800 Subject: [PATCH 2/2] Remove comment --- packages/block-editor/src/store/defaults.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-editor/src/store/defaults.js b/packages/block-editor/src/store/defaults.js index 5537c16dea2f47..18f189dab41054 100644 --- a/packages/block-editor/src/store/defaults.js +++ b/packages/block-editor/src/store/defaults.js @@ -160,7 +160,6 @@ export const SETTINGS_DEFAULTS = { // Allows to disable Openverse media category in the inserter. enableOpenverseMediaCategory: true, - // Is the selected block cleared upon deselection. clearBlockSelection: true, __experimentalCanUserUseUnfilteredHTML: false,