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

More/backports for beta 2 #59208

Merged
merged 22 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3c9d2cd
Font Library: Replace infinite scroll by pagination (#58794)
pbking Feb 13, 2024
d50c836
Revert "Block Hooks: Set ignoredHookedBlocks metada attr upon inserti…
ockham Feb 13, 2024
16f7948
DataViews: Fix patterns, templates and template parts pagination `z-i…
ntsekouras Feb 13, 2024
50244c6
Block Bindings: Fix disable bindings editing when source is undefined…
SantosGuillamot Feb 13, 2024
942cc3e
Patterns: Fix pattern categories on import (#58926)
ntsekouras Feb 13, 2024
0ef370b
Shadows: Don't assume that core provides defaults (#58973)
scruffian Feb 13, 2024
0f3e9fb
Inserter: Don't select the closest block with editing mode set as dis…
Mamaduka Feb 14, 2024
79dffd9
Make the custom CSS validation error message accessible. (#56690)
afercia Feb 14, 2024
a01f6a7
Inserter: Fix title condition for media tab previews (#58993)
Mamaduka Feb 14, 2024
1e70298
DataViews: Add loading/no results message in grid view (#59002)
ntsekouras Feb 14, 2024
4b25a88
Block editor: pass patterns selector as setting (#58661)
ellatrix Feb 14, 2024
00f7e12
Font Libary: Add missing translation functions (#58104)
t-hamano Feb 15, 2024
9b48e86
Background image support: Fix issue with background position if keybo…
andrewserong Feb 15, 2024
e53ba3b
Editor: Do not open list view by default on mobile (#59016)
youknowriad Feb 15, 2024
18c62df
Refactor to use string instead of an object (#59030)
cbravobernal Feb 15, 2024
81115e7
Fix DFM ui toggling bugs (#59061)
draganescu Feb 15, 2024
2958043
Rich text: fix link paste for internal paste (#59063)
ellatrix Feb 15, 2024
974f545
Image: Mark connected controls as 'readyonly' (#59059)
Mamaduka Feb 15, 2024
ea8ea99
Global Styles: fix console error in block preview (#59112)
t-hamano Feb 16, 2024
1236a04
Site Editor: Fix navigation on mobile web (#59014)
youknowriad Feb 15, 2024
2181591
Revert footer in pages list with DataViews (#59151)
ntsekouras Feb 19, 2024
dfe3d0d
Fix build
youknowriad Feb 20, 2024
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
Revert "Block Hooks: Set ignoredHookedBlocks metada attr upon inserti…
…on (#58553)" (#58969)

This reverts commit 7449074.
  • Loading branch information
ockham authored and youknowriad committed Feb 20, 2024
commit d50c836defae5f76fde56365eb4601cb2bed1dc9
48 changes: 0 additions & 48 deletions docs/reference-guides/data/data-core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,54 +504,6 @@ _Returns_

- `string?`: Name of the block for handling the grouping of blocks.

### getHookedBlocks

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_

```js
import { store as blocksStore } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';

const ExampleComponent = () => {
const hookedBlockNames = useSelect(
( select ) =>
select( blocksStore ).getHookedBlocks( 'core/navigation' ),
[]
);

return (
<ul>
{ 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>
);
};
```

_Parameters_

- _state_ `Object`: Data state.
- _blockName_ `string`: Anchor block type name.

_Returns_

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

### getUnregisteredFallbackBlockName

Returns the name of the block for handling unregistered blocks.
Expand Down
10 changes: 1 addition & 9 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
getBlockType,
getBlockTypes,
getBlockVariations,
getHookedBlocks,
hasBlockSupport,
getPossibleBlockTransformations,
parse,
Expand Down Expand Up @@ -1937,16 +1936,9 @@ const buildBlockTypeItem =
blockType.name,
'inserter'
);

const ignoredHookedBlocks = [
...new Set( Object.values( getHookedBlocks( id ) ).flat() ),
];

return {
...blockItemBase,
initialAttributes: ignoredHookedBlocks.length
? { metadata: { ignoredHookedBlocks } }
: {},
initialAttributes: {},
description: blockType.description,
category: blockType.category,
keywords: blockType.keywords,
Expand Down
14 changes: 0 additions & 14 deletions packages/blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,6 @@ _Returns_

- `?string`: Block name.

### getHookedBlocks

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.

_Parameters_

- _name_ `string`: Anchor block name.

_Returns_

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

### getPhrasingContentSchema

Undocumented declaration.
Expand Down
1 change: 0 additions & 1 deletion packages/blocks/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export {
getBlockTypes,
getBlockSupport,
hasBlockSupport,
getHookedBlocks,
getBlockVariations,
isReusableBlock,
isTemplatePart,
Expand Down
15 changes: 0 additions & 15 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,21 +550,6 @@ export function hasBlockSupport( nameOrType, feature, defaultSupports ) {
);
}

/**
* 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 {string} name Anchor block name.
*
* @return {Object} Lists of hooked block names for each relative position.
*/
export function getHookedBlocks( name ) {
return select( blocksStore ).getHookedBlocks( name );
}

/**
* Determines whether or not the given block is a reusable block. This is a
* special block type that is used to point to a global block stored via the
Expand Down
31 changes: 1 addition & 30 deletions packages/blocks/src/api/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { renderToString } from '@wordpress/element';
*/
import { convertLegacyBlockNameAndAttributes } from './parser/convert-legacy-block';
import { createBlock } from './factory';
import { getBlockType, getHookedBlocks } from './registration';
import { getBlockType } from './registration';

/**
* Checks whether a list of blocks matches a template by comparing the block names.
Expand Down Expand Up @@ -115,35 +115,6 @@ export function synchronizeBlocksWithTemplate( blocks = [], template ) {
normalizedAttributes
);

const ignoredHookedBlocks = [
...new Set(
Object.values( getHookedBlocks( blockName ) ).flat()
),
];

if ( ignoredHookedBlocks.length ) {
const { metadata = {}, ...otherAttributes } = blockAttributes;
const {
ignoredHookedBlocks: ignoredHookedBlocksFromTemplate = [],
...otherMetadata
} = metadata;

const newIgnoredHookedBlocks = [
...new Set( [
...ignoredHookedBlocks,
...ignoredHookedBlocksFromTemplate,
] ),
];

blockAttributes = {
metadata: {
ignoredHookedBlocks: newIgnoredHookedBlocks,
...otherMetadata,
},
...otherAttributes,
};
}

// If a Block is undefined at this point, use the core/missing block as
// a placeholder for a better user experience.
if ( undefined === getBlockType( blockName ) ) {
Expand Down
80 changes: 1 addition & 79 deletions packages/blocks/src/api/test/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ describe( 'templates', () => {

beforeEach( () => {
registerBlockType( 'core/test-block', {
attributes: {
metadata: {
type: 'object',
},
},
attributes: {},
save: noop,
category: 'text',
title: 'test block',
Expand Down Expand Up @@ -136,80 +132,6 @@ describe( 'templates', () => {
] );
} );

it( 'should set ignoredHookedBlocks metadata if a block has hooked blocks', () => {
registerBlockType( 'core/hooked-block', {
attributes: {},
save: noop,
category: 'text',
title: 'hooked block',
blockHooks: { 'core/test-block': 'after' },
} );

const template = [
[ 'core/test-block' ],
[ 'core/test-block-2' ],
[ 'core/test-block-2' ],
];
const blockList = [];

expect(
synchronizeBlocksWithTemplate( blockList, template )
).toMatchObject( [
{
name: 'core/test-block',
attributes: {
metadata: {
ignoredHookedBlocks: [ 'core/hooked-block' ],
},
},
},
{ name: 'core/test-block-2' },
{ name: 'core/test-block-2' },
] );
} );

it( 'retains previously set ignoredHookedBlocks metadata', () => {
registerBlockType( 'core/hooked-block', {
attributes: {},
save: noop,
category: 'text',
title: 'hooked block',
blockHooks: { 'core/test-block': 'after' },
} );

const template = [
[
'core/test-block',
{
metadata: {
ignoredHookedBlocks: [ 'core/other-hooked-block' ],
},
},
],
[ 'core/test-block-2' ],
[ 'core/test-block-2' ],
];
const blockList = [];

expect(
synchronizeBlocksWithTemplate( blockList, template )
).toMatchObject( [
{
name: 'core/test-block',
attributes: {
metadata: {
ignoredHookedBlocks: [
'core/hooked-block',
'core/other-hooked-block',
],
},
},
},
{ name: 'core/test-block-2' },
{ name: 'core/test-block-2' },
] );
} );

it( 'should create nested blocks', () => {
const template = [
[ 'core/test-block', {}, [ [ 'core/test-block-2' ] ] ],
Expand Down
62 changes: 0 additions & 62 deletions packages/blocks/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,68 +106,6 @@ export function getBlockType( state, name ) {
return state.blockTypes[ name ];
}

/**
* 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.
*
* @example
* ```js
* import { store as blocksStore } from '@wordpress/blocks';
* import { useSelect } from '@wordpress/data';
*
* const ExampleComponent = () => {
* const hookedBlockNames = useSelect( ( select ) =>
* select( blocksStore ).getHookedBlocks( 'core/navigation' ),
* []
* );
*
* return (
* <ul>
* { 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 {Object} Lists of hooked block names for each relative position.
*/
export const getHookedBlocks = createSelector(
( state, blockName ) => {
const hookedBlockTypes = getBlockTypes( state ).filter(
( { blockHooks } ) => blockHooks && blockName in blockHooks
);

let hookedBlocks = {};
for ( const blockType of hookedBlockTypes ) {
const relativePosition = blockType.blockHooks[ blockName ];
hookedBlocks = {
...hookedBlocks,
[ relativePosition ]: [
...( hookedBlocks[ relativePosition ] ?? [] ),
blockType.name,
],
};
}
return hookedBlocks;
},
( state ) => [ state.blockTypes ]
);

/**
* Returns block styles by block name.
*
Expand Down
Loading