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

Pattern overrides: use block binding editing API #60721

Merged
merged 44 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
78f9601
Pattern overrides: use block binding editing API
ellatrix May 9, 2024
17b31b8
Update only the needed attributes with bindings
SantosGuillamot May 9, 2024
63c6b6d
Keep blocks as normal when editing pattern
SantosGuillamot May 9, 2024
46063db
Use inner blocks for set edit mode
SantosGuillamot May 9, 2024
f1f78ae
Change indiviual reset logic
SantosGuillamot May 9, 2024
8121723
Move variable after early return
SantosGuillamot May 9, 2024
ec4daec
Add inline comment for bindings setAttributes
SantosGuillamot May 9, 2024
35aa0ab
Change variable to isOverriden
SantosGuillamot May 9, 2024
a71ba38
Change missing isOverriden
SantosGuillamot May 9, 2024
29afc1f
Fix detaching of synced patterns
SantosGuillamot May 9, 2024
31bf94c
Sync values of bound attributes
SantosGuillamot May 9, 2024
6c60eb3
Adapt synced pattern tests
SantosGuillamot May 9, 2024
49b062a
Use overriden values when detaching pattern
SantosGuillamot May 9, 2024
766a762
Adapt pattern-overrides tests
SantosGuillamot May 9, 2024
49286e1
Add workaround for pattern overrides
SantosGuillamot May 9, 2024
ef29ab3
Don't update non-bound attributes when using patterns
SantosGuillamot May 9, 2024
ba8b618
Add test for blocks with a shared name
SantosGuillamot May 9, 2024
e695fb4
Support button rel in bindings editor logic
SantosGuillamot May 9, 2024
d9d9fd6
Solve undo/redo issues
SantosGuillamot May 9, 2024
4a4465f
Stop using syncDerivedUpdates
SantosGuillamot May 9, 2024
1101667
Ensure change is marked as persistent in pattern overrides
SantosGuillamot May 9, 2024
a95749f
Try to solve undo/redo issues
SantosGuillamot May 9, 2024
e2a1b8a
Manage undefined attrs in pattern overrides
SantosGuillamot May 9, 2024
9d444a3
Remove `content` pattern property if empty
SantosGuillamot May 9, 2024
e28da53
Remove pattern-overrides specific code from `withBlockBindingSupport`…
talldan May 13, 2024
ae534d8
Fix persistent issues with setValues API
ellatrix May 13, 2024
4ec7315
Fall back to ''
ellatrix May 13, 2024
3a7311d
Make sure any previous changes are persisted before resetting.
ellatrix May 13, 2024
e013f6d
Add undo/redo test for resetting
kevin940726 May 13, 2024
950aab9
Fix test... 🤦
kevin940726 May 13, 2024
d99ecb7
Fix remaining undo test
ellatrix May 13, 2024
9ec9bba
Fix individual reset
ellatrix May 13, 2024
7d72a34
Add test for undoing loses the focus
kevin940726 May 13, 2024
4ebdb09
Fix reset button test
ellatrix May 13, 2024
44b51dd
Simplify pattern synced blocks test
SantosGuillamot May 13, 2024
5975f74
Remove focus test
SantosGuillamot May 13, 2024
10fa4e8
Use getBlockParentsByBlockName
SantosGuillamot May 14, 2024
3cfdd44
Add early return if blockName doesn't exist
SantosGuillamot May 14, 2024
8c5f574
Add comment for undefined values
SantosGuillamot May 14, 2024
3866446
Remove comment typo
SantosGuillamot May 14, 2024
33bfb86
Remove unnecessary includeHidden from tests
SantosGuillamot May 14, 2024
d80aba7
Check the frontend in patterns test
SantosGuillamot May 14, 2024
6b97321
Check frontend in updated pattern
SantosGuillamot May 14, 2024
c122b79
Stop using `getPatternRecord`
SantosGuillamot May 14, 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
64 changes: 48 additions & 16 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { unlock } from '../lock-unlock';
const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
'core/paragraph': [ 'content' ],
'core/heading': [ 'content' ],
'core/image': [ 'url', 'title', 'alt' ],
'core/button': [ 'url', 'text', 'linkTarget' ],
'core/image': [ 'id', 'url', 'title', 'alt' ],
'core/button': [ 'url', 'text', 'linkTarget', 'rel' ],
};

/**
Expand Down Expand Up @@ -110,34 +110,66 @@ export const withBlockBindingSupport = createHigherOrderComponent(
( nextAttributes ) => {
registry.batch( () => {
if ( ! bindings ) {
return setAttributes( nextAttributes );
setAttributes( nextAttributes );
return;
}

const keptAttributes = { ...nextAttributes };
const updatesBySource = new Map();

for ( const [
attributeName,
boundAttribute,
] of Object.entries( bindings ) ) {
SantosGuillamot marked this conversation as resolved.
Show resolved Hide resolved
const source = sources[ boundAttribute.source ];
// Loop only over the updated attributes to avoid modifying the bound ones that haven't changed.
for ( const [ attributeName, newValue ] of Object.entries(
keptAttributes
) ) {
if (
! source?.setValue ||
! bindings[ attributeName ] ||
! canBindAttribute( name, attributeName )
) {
continue;
}

source.setValue( {
registry,
context,
clientId,
attributeName,
args: boundAttribute.args,
value: nextAttributes[ attributeName ],
const source =
sources[ bindings[ attributeName ].source ];
if ( ! source?.setValue && ! source?.setValues ) {
continue;
}
updatesBySource.set( source, {
...updatesBySource.get( source ),
[ attributeName ]: newValue,
} );
delete keptAttributes[ attributeName ];
}

if ( updatesBySource.size ) {
for ( const [
source,
attributes,
] of updatesBySource ) {
if ( source.setValues ) {
source.setValues( {
registry,
context,
clientId,
attributes,
} );
} else {
for ( const [
attributeName,
value,
] of Object.entries( attributes ) ) {
source.setValue( {
registry,
context,
clientId,
attributeName,
args: bindings[ attributeName ].args,
value,
} );
}
}
}
}

if ( Object.keys( keptAttributes ).length ) {
setAttributes( keptAttributes );
}
Expand Down
Loading
Loading