Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block editor: pass patterns selector as setting #58661

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Block editor: pass patterns selector as setting
  • Loading branch information
ellatrix committed Feb 12, 2024
commit 937448c47af9bd00ca9c578cf93a03d443a5b0a4
2 changes: 0 additions & 2 deletions packages/block-editor/src/store/index.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ import reducer from './reducer';
import * as selectors from './selectors';
import * as privateActions from './private-actions';
import * as privateSelectors from './private-selectors';
import * as resolvers from './resolvers';
import * as actions from './actions';
import { STORE_NAME } from './constants';
import { unlock } from '../lock-unlock';
@@ -23,7 +22,6 @@ import { unlock } from '../lock-unlock';
export const storeConfig = {
reducer,
selectors,
resolvers,
actions,
};

11 changes: 4 additions & 7 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
@@ -250,10 +250,6 @@ export const getInserterMediaCategories = createSelector(
]
);

export function getFetchedPatterns( state ) {
return state.blockPatterns;
}

/**
* Returns whether there is at least one allowed pattern for inner blocks children.
* This is useful for deferring the parsing of all patterns until needed.
@@ -285,7 +281,7 @@ export const hasAllowedPatterns = createRegistrySelector( ( select ) =>
} );
},
( state, rootClientId ) => [
getAllPatternsDependants( state ),
getAllPatternsDependants( select )( state ),
state.settings.allowedBlockTypes,
state.settings.templateLock,
state.blockListSettings[ rootClientId ],
@@ -301,6 +297,7 @@ export const getAllPatterns = createRegistrySelector( ( select ) =>
__experimentalBlockPatterns = [],
__experimentalUserPatternCategories = [],
__experimentalReusableBlocks = [],
__experimentalSelectBlockPatterns,
} = state.settings;
const userPatterns = ( __experimentalReusableBlocks ?? [] ).map(
( userPattern ) => {
@@ -325,12 +322,12 @@ export const getAllPatterns = createRegistrySelector( ( select ) =>
return [
...userPatterns,
...__experimentalBlockPatterns,
...unlock( select( STORE_NAME ) ).getFetchedPatterns(),
...( __experimentalSelectBlockPatterns( select ) ?? [] ),
].filter(
( x, index, arr ) =>
index === arr.findIndex( ( y ) => x.name === y.name )
);
}, getAllPatternsDependants )
}, getAllPatternsDependants( select ) )
);

/**
10 changes: 0 additions & 10 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
@@ -2064,15 +2064,6 @@ function blockBindingsSources( state = {}, action ) {
return state;
}

function blockPatterns( state = [], action ) {
switch ( action.type ) {
case 'RECEIVE_BLOCK_PATTERNS':
return action.patterns;
}

return state;
}

const combinedReducers = combineReducers( {
blocks,
isDragging,
@@ -2105,7 +2096,6 @@ const combinedReducers = combineReducers( {
openedBlockSettingsMenu,
registeredInserterMediaCategories,
blockBindingsSources,
blockPatterns,
} );

function withAutomaticChangeReset( reducer ) {
17 changes: 0 additions & 17 deletions packages/block-editor/src/store/resolvers.js

This file was deleted.

12 changes: 6 additions & 6 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
@@ -2307,12 +2307,12 @@ export const __experimentalGetParsedPattern = createRegistrySelector(
__unstableSkipMigrationLogs: true,
} ),
};
}, getAllPatternsDependants )
}, getAllPatternsDependants( select ) )
);

const getAllowedPatternsDependants = ( state, rootClientId ) => {
const getAllowedPatternsDependants = ( select ) => ( state, rootClientId ) => {
return [
...getAllPatternsDependants( state ),
...getAllPatternsDependants( select )( state ),
state.settings.allowedBlockTypes,
state.settings.templateLock,
state.blockListSettings[ rootClientId ],
@@ -2353,7 +2353,7 @@ export const __experimentalGetAllowedPatterns = createRegistrySelector(
);

return patternsAllowed;
}, getAllowedPatternsDependants );
}, getAllowedPatternsDependants( select ) );
}
);

@@ -2392,7 +2392,7 @@ export const getPatternsByBlockTypes = createRegistrySelector( ( select ) =>
return filteredPatterns;
},
( state, blockNames, rootClientId ) =>
getAllowedPatternsDependants( state, rootClientId )
getAllowedPatternsDependants( select )( state, rootClientId )
)
);

@@ -2466,7 +2466,7 @@ export const __experimentalGetPatternTransformItems = createRegistrySelector(
);
},
( state, blocks, rootClientId ) =>
getAllowedPatternsDependants( state, rootClientId )
getAllowedPatternsDependants( select )( state, rootClientId )
)
);

4 changes: 2 additions & 2 deletions packages/block-editor/src/store/utils.js
Original file line number Diff line number Diff line change
@@ -40,12 +40,12 @@ export const checkAllowListRecursive = ( blocks, allowedBlockTypes ) => {
return true;
};

export const getAllPatternsDependants = ( state ) => {
export const getAllPatternsDependants = ( select ) => ( state ) => {
return [
state.settings.__experimentalBlockPatterns,
state.settings.__experimentalUserPatternCategories,
state.settings.__experimentalReusableBlocks,
state.settings.__experimentalFetchBlockPatterns,
state.settings.__experimentalSelectBlockPatterns?.( select ),
state.blockPatterns,
];
};
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import {
store as coreStore,
__experimentalFetchLinkSuggestions as fetchLinkSuggestions,
__experimentalFetchUrlData as fetchUrlData,
fetchBlockPatterns,
} from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
@@ -87,6 +86,7 @@ const BLOCK_EDITOR_SETTINGS = [
*/
function useBlockEditorSettings( settings, postType, postId ) {
const isLargeViewport = useViewportMatch( 'medium' );
const { getBlockPatterns } = useSelect( coreStore );
const {
allowRightClickOverrides,
blockTypes,
@@ -247,17 +247,7 @@ function useBlockEditorSettings( settings, postType, postId ) {
keepCaretInsideBlock,
mediaUpload: hasUploadPermissions ? mediaUpload : undefined,
__experimentalBlockPatterns: blockPatterns,
__experimentalFetchBlockPatterns: async () => {
return ( await fetchBlockPatterns() ).filter(
( { postTypes } ) => {
return (
! postTypes ||
( Array.isArray( postTypes ) &&
postTypes.includes( postType ) )
);
}
);
},
__experimentalSelectBlockPatterns: getBlockPatterns,
__experimentalReusableBlocks: reusableBlocks,
__experimentalBlockPatternCategories: blockPatternCategories,
__experimentalUserPatternCategories: userPatternCategories,
@@ -300,6 +290,7 @@ function useBlockEditorSettings( settings, postType, postId ) {
reusableBlocks,
userPatternCategories,
blockPatterns,
getBlockPatterns,
blockPatternCategories,
canUseUnfilteredHTML,
undo,