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 Hooks: Set ignoredHookedBlocks metada attr upon insertion #58553

Merged
merged 24 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Update JSDoc for getHookedBlocks selector
  • Loading branch information
ockham committed Feb 8, 2024
commit e9edc8da41f3627882476e910058bc72ae61f157
21 changes: 16 additions & 5 deletions docs/reference-guides/data/data-core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ _Returns_

### getHookedBlocks

Returns an array with the hooked blocks for a given anchor block.
Returns the hooked blocks for a given anchor block.

Given an anchor block name, returns an object whose keys are relative positions, and whose values are arrays of block names that are hooked to the anchor block at that relative position.

_Usage_

Expand All @@ -523,9 +525,18 @@ const ExampleComponent = () => {

return (
<ul>
{ hookedBlockNames &&
hookedBlockNames.map( ( hookedBlock ) => (
<li key={ hookedBlock }>{ hookedBlock }</li>
{ Object.keys( hookedBlockNames ).length &&
Object.keys( hookedBlockNames ).map( ( relativePosition ) => (
<li key={ relativePosition }>
{ relativePosition }>
<ul>
{ hookedBlockNames[ relativePosition ].map(
( hookedBlock ) => (
<li key={ hookedBlock }>{ hookedBlock }</li>
)
) }
</ul>
</li>
) ) }
</ul>
);
Expand All @@ -539,7 +550,7 @@ _Parameters_

_Returns_

- `Array`: Array of hooked block names.
- `Object`: Lists of hooked block names for each relative position.

### getUnregisteredFallbackBlockName

Expand Down
20 changes: 15 additions & 5 deletions packages/blocks/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ export function getBlockType( state, name ) {
}

/**
* Returns an array with the hooked blocks for a given anchor block.
* Returns the hooked blocks for a given anchor block.
*
* Given an anchor block name, returns an object whose keys are relative positions,
* and whose values are arrays of block names that are hooked to the anchor block
* at that relative position.
*
* @param {Object} state Data state.
* @param {string} blockName Anchor block type name.
Expand All @@ -125,16 +129,22 @@ export function getBlockType( state, name ) {
*
* return (
* <ul>
* { hookedBlockNames &&
* hookedBlockNames.map( ( hookedBlock ) => (
* <li key={ hookedBlock }>{ hookedBlock }</li>
* { Object.keys( hookedBlockNames ).length &&
* Object.keys( hookedBlockNames ).map( ( relativePosition ) => (
* <li key={ relativePosition }>{ relativePosition }>
* <ul>
* { hookedBlockNames[ relativePosition ].map( ( hookedBlock ) => (
* <li key={ hookedBlock }>{ hookedBlock }</li>
* ) ) }
* </ul>
* </li>
* ) ) }
* </ul>
* );
* };
* ```
*
* @return {Array} Array of hooked block names.
* @return {Object} Lists of hooked block names for each relative position.
*/
export const getHookedBlocks = createSelector(
( state, blockName ) => {
Expand Down