@wordpress/block-editor 15.4.1-next.233ccab9b.0 → 15.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/background-image-control/index.js +51 -24
- package/build/components/background-image-control/index.js.map +1 -1
- package/build/components/block-edit/edit.js +13 -5
- package/build/components/block-edit/edit.js.map +1 -1
- package/build/components/block-list/block.js +14 -4
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +5 -4
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +10 -2
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +5 -0
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-visibility/index.js +21 -0
- package/build/components/block-visibility/index.js.map +1 -0
- package/build/components/block-visibility/menu-item.js +52 -0
- package/build/components/block-visibility/menu-item.js.map +1 -0
- package/build/components/block-visibility/toolbar.js +88 -0
- package/build/components/block-visibility/toolbar.js.map +1 -0
- package/build/components/inspector-controls-tabs/index.js +23 -0
- package/build/components/inspector-controls-tabs/index.js.map +1 -1
- package/build/components/link-control/index.js +1 -1
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +23 -4
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +9 -3
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/rich-text/index.js +4 -2
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +5 -1
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/hooks/block-bindings.js +9 -4
- package/build/hooks/block-bindings.js.map +1 -1
- package/build/store/private-selectors.js +19 -1
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +1 -5
- package/build/store/reducer.js.map +1 -1
- package/build/utils/block-bindings.js +3 -48
- package/build/utils/block-bindings.js.map +1 -1
- package/build-module/components/background-image-control/index.js +52 -25
- package/build-module/components/background-image-control/index.js.map +1 -1
- package/build-module/components/block-edit/edit.js +14 -6
- package/build-module/components/block-edit/edit.js.map +1 -1
- package/build-module/components/block-list/block.js +14 -4
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +5 -4
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +10 -2
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +5 -0
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-visibility/index.js +3 -0
- package/build-module/components/block-visibility/index.js.map +1 -0
- package/build-module/components/block-visibility/menu-item.js +45 -0
- package/build-module/components/block-visibility/menu-item.js.map +1 -0
- package/build-module/components/block-visibility/toolbar.js +81 -0
- package/build-module/components/block-visibility/toolbar.js.map +1 -0
- package/build-module/components/inspector-controls-tabs/index.js +23 -0
- package/build-module/components/inspector-controls-tabs/index.js.map +1 -1
- package/build-module/components/link-control/index.js +1 -1
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +24 -5
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +9 -3
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/rich-text/index.js +4 -2
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +6 -2
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/hooks/block-bindings.js +10 -5
- package/build-module/hooks/block-bindings.js.map +1 -1
- package/build-module/store/private-selectors.js +18 -1
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +1 -5
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/utils/block-bindings.js +3 -45
- package/build-module/utils/block-bindings.js.map +1 -1
- package/build-style/content-rtl.css +13 -0
- package/build-style/content.css +13 -0
- package/build-style/style-rtl.css +27 -0
- package/build-style/style.css +27 -0
- package/package.json +34 -34
- package/src/components/background-image-control/index.js +54 -27
- package/src/components/background-image-control/style.scss +28 -0
- package/src/components/block-edit/edit.js +23 -5
- package/src/components/block-list/block.js +16 -0
- package/src/components/block-list/content.scss +19 -0
- package/src/components/block-list/use-block-props/index.js +9 -9
- package/src/components/block-settings-menu-controls/index.js +21 -1
- package/src/components/block-toolbar/index.js +9 -0
- package/src/components/block-visibility/index.js +2 -0
- package/src/components/block-visibility/menu-item.js +53 -0
- package/src/components/block-visibility/toolbar.js +88 -0
- package/src/components/inspector-controls-tabs/index.js +33 -1
- package/src/components/link-control/index.js +1 -1
- package/src/components/link-control/test/index.js +4 -4
- package/src/components/list-view/block-select-button.js +32 -9
- package/src/components/list-view/block.js +24 -14
- package/src/components/list-view/style.scss +1 -0
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/rich-text/index.js +6 -2
- package/src/components/use-block-drop-zone/index.js +14 -1
- package/src/hooks/block-bindings.js +49 -43
- package/src/store/private-selectors.js +21 -1
- package/src/store/reducer.js +1 -6
- package/src/utils/block-bindings.js +6 -48
|
@@ -23,11 +23,7 @@ import { useViewportMatch } from '@wordpress/compose';
|
|
|
23
23
|
/**
|
|
24
24
|
* Internal dependencies
|
|
25
25
|
*/
|
|
26
|
-
import {
|
|
27
|
-
canBindAttribute,
|
|
28
|
-
getBindableAttributes,
|
|
29
|
-
useBlockBindingsUtils,
|
|
30
|
-
} from '../utils/block-bindings';
|
|
26
|
+
import { useBlockBindingsUtils } from '../utils/block-bindings';
|
|
31
27
|
import { unlock } from '../lock-unlock';
|
|
32
28
|
import InspectorControls from '../components/inspector-controls';
|
|
33
29
|
import BlockContext from '../components/block-context';
|
|
@@ -205,52 +201,62 @@ function EditableBlockBindingsPanelItems( {
|
|
|
205
201
|
export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
206
202
|
const blockContext = useContext( BlockContext );
|
|
207
203
|
const { removeAllBlockBindings } = useBlockBindingsUtils();
|
|
208
|
-
const bindableAttributes = getBindableAttributes( blockName );
|
|
209
204
|
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
210
205
|
|
|
211
206
|
// `useSelect` is used purposely here to ensure `getFieldsList`
|
|
212
207
|
// is updated whenever there are updates in block context.
|
|
213
208
|
// `source.getFieldsList` may also call a selector via `select`.
|
|
214
209
|
const _fieldsList = {};
|
|
215
|
-
const { fieldsList, canUpdateBlockBindings } =
|
|
216
|
-
(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
210
|
+
const { bindableAttributes, fieldsList, canUpdateBlockBindings } =
|
|
211
|
+
useSelect(
|
|
212
|
+
( select ) => {
|
|
213
|
+
const { __experimentalBlockBindingsSupportedAttributes } =
|
|
214
|
+
select( blockEditorStore ).getSettings();
|
|
215
|
+
const _bindableAttributes =
|
|
216
|
+
__experimentalBlockBindingsSupportedAttributes?.[
|
|
217
|
+
blockName
|
|
218
|
+
];
|
|
219
|
+
if (
|
|
220
|
+
! _bindableAttributes ||
|
|
221
|
+
_bindableAttributes.length === 0
|
|
222
|
+
) {
|
|
223
|
+
return EMPTY_OBJECT;
|
|
224
|
+
}
|
|
225
|
+
const registeredSources = getBlockBindingsSources();
|
|
226
|
+
Object.entries( registeredSources ).forEach(
|
|
227
|
+
( [ sourceName, { getFieldsList, usesContext } ] ) => {
|
|
228
|
+
if ( getFieldsList ) {
|
|
229
|
+
// Populate context.
|
|
230
|
+
const context = {};
|
|
231
|
+
if ( usesContext?.length ) {
|
|
232
|
+
for ( const key of usesContext ) {
|
|
233
|
+
context[ key ] = blockContext[ key ];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const sourceList = getFieldsList( {
|
|
237
|
+
select,
|
|
238
|
+
context,
|
|
239
|
+
} );
|
|
240
|
+
// Only add source if the list is not empty.
|
|
241
|
+
if ( Object.keys( sourceList || {} ).length ) {
|
|
242
|
+
_fieldsList[ sourceName ] = { ...sourceList };
|
|
229
243
|
}
|
|
230
|
-
}
|
|
231
|
-
const sourceList = getFieldsList( {
|
|
232
|
-
select,
|
|
233
|
-
context,
|
|
234
|
-
} );
|
|
235
|
-
// Only add source if the list is not empty.
|
|
236
|
-
if ( Object.keys( sourceList || {} ).length ) {
|
|
237
|
-
_fieldsList[ sourceName ] = { ...sourceList };
|
|
238
244
|
}
|
|
239
245
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
246
|
+
);
|
|
247
|
+
return {
|
|
248
|
+
bindableAttributes: _bindableAttributes,
|
|
249
|
+
fieldsList:
|
|
250
|
+
Object.values( _fieldsList ).length > 0
|
|
251
|
+
? _fieldsList
|
|
252
|
+
: EMPTY_OBJECT,
|
|
253
|
+
canUpdateBlockBindings:
|
|
254
|
+
select( blockEditorStore ).getSettings()
|
|
255
|
+
.canUpdateBlockBindings,
|
|
256
|
+
};
|
|
257
|
+
},
|
|
258
|
+
[ blockContext ]
|
|
259
|
+
);
|
|
254
260
|
// Return early if there are no bindable attributes.
|
|
255
261
|
if ( ! bindableAttributes || bindableAttributes.length === 0 ) {
|
|
256
262
|
return null;
|
|
@@ -260,7 +266,7 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
260
266
|
const filteredBindings = { ...bindings };
|
|
261
267
|
Object.keys( filteredBindings ).forEach( ( key ) => {
|
|
262
268
|
if (
|
|
263
|
-
!
|
|
269
|
+
! bindableAttributes.includes( key ) &&
|
|
264
270
|
filteredBindings[ key ].source === 'core/pattern-overrides'
|
|
265
271
|
) {
|
|
266
272
|
delete filteredBindings[ key ];
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { createSelector, createRegistrySelector } from '@wordpress/data';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
hasBlockSupport,
|
|
7
|
+
privateApis as blocksPrivateApis,
|
|
8
|
+
} from '@wordpress/blocks';
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Internal dependencies
|
|
@@ -685,3 +688,20 @@ export function getClosestAllowedInsertionPointForPattern(
|
|
|
685
688
|
export function getInsertionPoint( state ) {
|
|
686
689
|
return state.insertionPoint;
|
|
687
690
|
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Returns true if the block is hidden, or false otherwise.
|
|
694
|
+
*
|
|
695
|
+
* @param {Object} state Global application state.
|
|
696
|
+
* @param {string} clientId Client ID of the block.
|
|
697
|
+
*
|
|
698
|
+
* @return {boolean} Whether the block is hidden.
|
|
699
|
+
*/
|
|
700
|
+
export const isBlockHidden = ( state, clientId ) => {
|
|
701
|
+
const blockName = getBlockName( state, clientId );
|
|
702
|
+
if ( ! hasBlockSupport( state, blockName, 'blockVisibility', true ) ) {
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
const attributes = state.blocks.attributes.get( clientId );
|
|
706
|
+
return attributes?.metadata?.blockVisibility === false;
|
|
707
|
+
};
|
package/src/store/reducer.js
CHANGED
|
@@ -2307,12 +2307,7 @@ function getDerivedBlockEditingModesForTree(
|
|
|
2307
2307
|
let ancestorBlockEditingMode;
|
|
2308
2308
|
let parent = state.blocks.parents.get( clientId );
|
|
2309
2309
|
while ( parent !== undefined ) {
|
|
2310
|
-
|
|
2311
|
-
// if so we can return that value for a faster lookup.
|
|
2312
|
-
if ( derivedBlockEditingModes.has( parent ) ) {
|
|
2313
|
-
ancestorBlockEditingMode =
|
|
2314
|
-
derivedBlockEditingModes.get( parent );
|
|
2315
|
-
} else if ( state.blockEditingModes.has( parent ) ) {
|
|
2310
|
+
if ( state.blockEditingModes.has( parent ) ) {
|
|
2316
2311
|
// Checking the explicit block editing mode will be slower,
|
|
2317
2312
|
// as the block editing mode is more likely to be set on a
|
|
2318
2313
|
// distant ancestor.
|
|
@@ -11,13 +11,6 @@ import { useBlockEditContext } from '../components/block-edit';
|
|
|
11
11
|
|
|
12
12
|
const DEFAULT_ATTRIBUTE = '__default';
|
|
13
13
|
const PATTERN_OVERRIDES_SOURCE = 'core/pattern-overrides';
|
|
14
|
-
const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
|
|
15
|
-
'core/paragraph': [ 'content' ],
|
|
16
|
-
'core/heading': [ 'content' ],
|
|
17
|
-
'core/image': [ 'id', 'url', 'title', 'alt', 'caption' ],
|
|
18
|
-
'core/button': [ 'url', 'text', 'linkTarget', 'rel' ],
|
|
19
|
-
'core/post-date': [ 'datetime' ],
|
|
20
|
-
};
|
|
21
14
|
|
|
22
15
|
/**
|
|
23
16
|
* Checks if the given object is empty.
|
|
@@ -30,43 +23,6 @@ function isObjectEmpty( object ) {
|
|
|
30
23
|
return ! object || Object.keys( object ).length === 0;
|
|
31
24
|
}
|
|
32
25
|
|
|
33
|
-
/**
|
|
34
|
-
* Based on the given block name, checks if it is possible to bind the block.
|
|
35
|
-
*
|
|
36
|
-
* @param {string} blockName The name of the block.
|
|
37
|
-
*
|
|
38
|
-
* @return {boolean} Whether it is possible to bind the block to sources.
|
|
39
|
-
*/
|
|
40
|
-
export function canBindBlock( blockName ) {
|
|
41
|
-
return blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Based on the given block name and attribute name, checks if it is possible to bind the block attribute.
|
|
46
|
-
*
|
|
47
|
-
* @param {string} blockName The name of the block.
|
|
48
|
-
* @param {string} attributeName The name of attribute.
|
|
49
|
-
*
|
|
50
|
-
* @return {boolean} Whether it is possible to bind the block attribute.
|
|
51
|
-
*/
|
|
52
|
-
export function canBindAttribute( blockName, attributeName ) {
|
|
53
|
-
return (
|
|
54
|
-
canBindBlock( blockName ) &&
|
|
55
|
-
BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ].includes( attributeName )
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Gets the bindable attributes for a given block.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} blockName The name of the block.
|
|
63
|
-
*
|
|
64
|
-
* @return {string[]} The bindable attributes for the block.
|
|
65
|
-
*/
|
|
66
|
-
export function getBindableAttributes( blockName ) {
|
|
67
|
-
return BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
26
|
/**
|
|
71
27
|
* Checks if the block has the `__default` binding for pattern overrides.
|
|
72
28
|
*
|
|
@@ -85,15 +41,17 @@ export function hasPatternOverridesDefaultBinding( bindings ) {
|
|
|
85
41
|
* - bindings passed in: `{ __default: { source: 'core/pattern-overrides' } }`
|
|
86
42
|
* - bindings returned: `{ content: { source: 'core/pattern-overrides' } }`
|
|
87
43
|
*
|
|
88
|
-
* @param {string}
|
|
89
|
-
* @param {
|
|
44
|
+
* @param {?Record<string, object>} bindings A block's bindings from the metadata attribute.
|
|
45
|
+
* @param {string[]} supportedAttributes The block's attributes which are supported by block bindings.
|
|
90
46
|
*
|
|
91
47
|
* @return {Object} The bindings with default replaced for pattern overrides.
|
|
92
48
|
*/
|
|
93
|
-
export function replacePatternOverridesDefaultBinding(
|
|
49
|
+
export function replacePatternOverridesDefaultBinding(
|
|
50
|
+
bindings,
|
|
51
|
+
supportedAttributes
|
|
52
|
+
) {
|
|
94
53
|
// The `__default` binding currently only works for pattern overrides.
|
|
95
54
|
if ( hasPatternOverridesDefaultBinding( bindings ) ) {
|
|
96
|
-
const supportedAttributes = BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];
|
|
97
55
|
const bindingsWithDefaults = {};
|
|
98
56
|
for ( const attributeName of supportedAttributes ) {
|
|
99
57
|
// If the block has mixed binding sources, retain any non pattern override bindings.
|