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]: Stabilize __experimentalGetAllowedBlocks #47210

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ _Returns_

- `?string`: Return the client ID of the block, or null if none exists.

### getAllowedBlocks

Returns the list of allowed inserter blocks for inner blocks children.

_Parameters_

- _state_ `Object`: Editor state.
- _rootClientId_ `?string`: Optional root client ID of block list.

_Returns_

- `Array?`: The list of allowed block types.

### getBlock

Returns a block given its client ID. This is a parsed copy of the block,
Expand Down
5 changes: 2 additions & 3 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default compose( [
const {
getBlockRootClientId,
hasInserterItems,
__experimentalGetAllowedBlocks,
getAllowedBlocks,
__experimentalGetDirectInsertBlock,
getSettings,
} = select( blockEditorStore );
Expand All @@ -235,8 +235,7 @@ export default compose( [
rootClientId =
rootClientId || getBlockRootClientId( clientId ) || undefined;

const allowedBlocks =
__experimentalGetAllowedBlocks( rootClientId );
const allowedBlocks = getAllowedBlocks( rootClientId );

const directInsertBlock =
shouldDirectInsert &&
Expand Down
22 changes: 20 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2144,14 +2144,14 @@ export const hasInserterItems = createSelector(
);

/**
* Returns the list of allowed inserter blocks for inner blocks children
* Returns the list of allowed inserter blocks for inner blocks children.
*
* @param {Object} state Editor state.
* @param {?string} rootClientId Optional root client ID of block list.
*
* @return {Array?} The list of allowed block types.
*/
export const __experimentalGetAllowedBlocks = createSelector(
export const getAllowedBlocks = createSelector(
( state, rootClientId = null ) => {
if ( ! rootClientId ) {
return;
Expand All @@ -2170,6 +2170,24 @@ export const __experimentalGetAllowedBlocks = createSelector(
]
);

export const __experimentalGetAllowedBlocks = createSelector(
( state, rootClientId = null ) => {
deprecated(
'wp.data.select( "core/block-editor" ).__experimentalGetAllowedBlocks',
{
alternative:
'wp.data.select( "core/block-editor" ).getAllowedBlocks',
since: '6.2',
version: '6.4',
}
);
return getAllowedBlocks( state, rootClientId );
},
( state, rootClientId ) => [
...getAllowedBlocks.getDependants( state, rootClientId ),
]
);

/**
* Returns the block to be directly inserted by the block appender.
*
Expand Down