Skip to content

Commit

Permalink
Use private settings key
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 12, 2024
1 parent 2a5cd4f commit 56adeef
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -56,4 +57,5 @@ lock( privateApis, {
useReusableBlocksRenameHint,
usesContextKey,
useFlashEditableBlocks,
selectBlockPatternsKey,
} );
1 change: 1 addition & 0 deletions packages/block-editor/src/store/private-keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const selectBlockPatternsKey = Symbol( 'selectBlockPatternsKey' );
4 changes: 2 additions & 2 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -297,7 +298,6 @@ export const getAllPatterns = createRegistrySelector( ( select ) =>
__experimentalBlockPatterns = [],
__experimentalUserPatternCategories = [],
__experimentalReusableBlocks = [],
__experimentalSelectBlockPatterns,
} = state.settings;
const userPatterns = ( __experimentalReusableBlocks ?? [] ).map(
( userPattern ) => {
Expand All @@ -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 )
Expand Down
7 changes: 6 additions & 1 deletion packages/block-editor/src/store/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Internal dependencies
*/
import { selectBlockPatternsKey } from './private-keys';

export const checkAllowList = ( list, item, defaultResult = null ) => {
if ( typeof list === 'boolean' ) {
return list;
Expand Down Expand Up @@ -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,
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ 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
*/
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 = [];
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 56adeef

Please sign in to comment.