From 56adeefe1984eef1fa572f6dbd50383829ebc115 Mon Sep 17 00:00:00 2001 From: Ella Date: Thu, 8 Feb 2024 11:22:42 +0200 Subject: [PATCH] Use private settings key --- packages/block-editor/src/private-apis.js | 2 ++ packages/block-editor/src/store/private-keys.js | 1 + packages/block-editor/src/store/private-selectors.js | 4 ++-- packages/block-editor/src/store/utils.js | 7 ++++++- .../src/components/provider/use-block-editor-settings.js | 7 +++++-- 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 packages/block-editor/src/store/private-keys.js diff --git a/packages/block-editor/src/private-apis.js b/packages/block-editor/src/private-apis.js index 0ba05e88a0f9b..220aa5f412727 100644 --- a/packages/block-editor/src/private-apis.js +++ b/packages/block-editor/src/private-apis.js @@ -26,6 +26,7 @@ import { usesContextKey } from './components/rich-text/format-edit'; import { ExperimentalBlockCanvas } from './components/block-canvas'; import { getDuotoneFilter } from './components/duotone/utils'; import { useFlashEditableBlocks } from './components/use-flash-editable-blocks'; +import { selectBlockPatternsKey } from './store/private-keys'; /** * Private @wordpress/block-editor APIs. @@ -56,4 +57,5 @@ lock( privateApis, { useReusableBlocksRenameHint, usesContextKey, useFlashEditableBlocks, + selectBlockPatternsKey, } ); diff --git a/packages/block-editor/src/store/private-keys.js b/packages/block-editor/src/store/private-keys.js new file mode 100644 index 0000000000000..8bfa4bb68297f --- /dev/null +++ b/packages/block-editor/src/store/private-keys.js @@ -0,0 +1 @@ +export const selectBlockPatternsKey = Symbol( 'selectBlockPatternsKey' ); diff --git a/packages/block-editor/src/store/private-selectors.js b/packages/block-editor/src/store/private-selectors.js index 8dacc4081e540..c885e43ba7520 100644 --- a/packages/block-editor/src/store/private-selectors.js +++ b/packages/block-editor/src/store/private-selectors.js @@ -22,6 +22,7 @@ import { checkAllowListRecursive, getAllPatternsDependants } from './utils'; import { INSERTER_PATTERN_TYPES } from '../components/inserter/block-patterns-tab/utils'; import { STORE_NAME } from './constants'; import { unlock } from '../lock-unlock'; +import { selectBlockPatternsKey } from './private-keys'; export { getBlockSettings } from './get-block-settings'; @@ -297,7 +298,6 @@ export const getAllPatterns = createRegistrySelector( ( select ) => __experimentalBlockPatterns = [], __experimentalUserPatternCategories = [], __experimentalReusableBlocks = [], - __experimentalSelectBlockPatterns, } = state.settings; const userPatterns = ( __experimentalReusableBlocks ?? [] ).map( ( userPattern ) => { @@ -322,7 +322,7 @@ export const getAllPatterns = createRegistrySelector( ( select ) => return [ ...userPatterns, ...__experimentalBlockPatterns, - ...( __experimentalSelectBlockPatterns?.( select ) ?? [] ), + ...( state.settings[ selectBlockPatternsKey ]?.( select ) ?? [] ), ].filter( ( x, index, arr ) => index === arr.findIndex( ( y ) => x.name === y.name ) diff --git a/packages/block-editor/src/store/utils.js b/packages/block-editor/src/store/utils.js index 57ee6fc1ffa7f..4d9d114946c1f 100644 --- a/packages/block-editor/src/store/utils.js +++ b/packages/block-editor/src/store/utils.js @@ -1,3 +1,8 @@ +/** + * Internal dependencies + */ +import { selectBlockPatternsKey } from './private-keys'; + export const checkAllowList = ( list, item, defaultResult = null ) => { if ( typeof list === 'boolean' ) { return list; @@ -45,7 +50,7 @@ export const getAllPatternsDependants = ( select ) => ( state ) => { state.settings.__experimentalBlockPatterns, state.settings.__experimentalUserPatternCategories, state.settings.__experimentalReusableBlocks, - state.settings.__experimentalSelectBlockPatterns?.( select ), + state.settings[ selectBlockPatternsKey ]?.( select ), state.blockPatterns, ]; }; 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 06b8904562d2d..0aeadbe26ecd9 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -12,6 +12,7 @@ import { __ } from '@wordpress/i18n'; import { store as preferencesStore } from '@wordpress/preferences'; import { useViewportMatch } from '@wordpress/compose'; import { store as blocksStore } from '@wordpress/blocks'; +import { privateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -19,8 +20,9 @@ import { store as blocksStore } from '@wordpress/blocks'; import inserterMediaCategories from '../media-categories'; import { mediaUpload } from '../../utils'; import { store as editorStore } from '../../store'; +import { unlock } from '../../lock-unlock'; -const __experimentalSelectBlockPatterns = ( select ) => +const selectBlockPatterns = ( select ) => select( coreStore ).getBlockPatterns(); const EMPTY_BLOCKS_LIST = []; @@ -249,7 +251,8 @@ function useBlockEditorSettings( settings, postType, postId ) { keepCaretInsideBlock, mediaUpload: hasUploadPermissions ? mediaUpload : undefined, __experimentalBlockPatterns: blockPatterns, - __experimentalSelectBlockPatterns, + [ unlock( privateApis ).selectBlockPatternsKey ]: + selectBlockPatterns, __experimentalReusableBlocks: reusableBlocks, __experimentalBlockPatternCategories: blockPatternCategories, __experimentalUserPatternCategories: userPatternCategories,