Skip to content

Commit

Permalink
[Block Editor]: Stabilize __experimentalGetAllowedBlocks (#47210)
Browse files Browse the repository at this point in the history
* [Block Editor]: Stabilize __experimentalGetAllowedBlocks

* feedback
  • Loading branch information
ntsekouras authored Jan 17, 2023
1 parent 22f8498 commit 71a3344
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
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

0 comments on commit 71a3344

Please sign in to comment.