@wordpress/block-editor 15.4.1-next.f56bd8138.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.
Files changed (106) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/background-image-control/index.js +51 -24
  3. package/build/components/background-image-control/index.js.map +1 -1
  4. package/build/components/block-edit/edit.js +13 -5
  5. package/build/components/block-edit/edit.js.map +1 -1
  6. package/build/components/block-list/block.js +14 -4
  7. package/build/components/block-list/block.js.map +1 -1
  8. package/build/components/block-list/use-block-props/index.js +5 -4
  9. package/build/components/block-list/use-block-props/index.js.map +1 -1
  10. package/build/components/block-settings-menu-controls/index.js +10 -2
  11. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  12. package/build/components/block-toolbar/index.js +5 -0
  13. package/build/components/block-toolbar/index.js.map +1 -1
  14. package/build/components/block-visibility/index.js +21 -0
  15. package/build/components/block-visibility/index.js.map +1 -0
  16. package/build/components/block-visibility/menu-item.js +52 -0
  17. package/build/components/block-visibility/menu-item.js.map +1 -0
  18. package/build/components/block-visibility/toolbar.js +88 -0
  19. package/build/components/block-visibility/toolbar.js.map +1 -0
  20. package/build/components/inspector-controls-tabs/index.js +23 -0
  21. package/build/components/inspector-controls-tabs/index.js.map +1 -1
  22. package/build/components/link-control/index.js +1 -1
  23. package/build/components/link-control/index.js.map +1 -1
  24. package/build/components/list-view/block-select-button.js +23 -4
  25. package/build/components/list-view/block-select-button.js.map +1 -1
  26. package/build/components/list-view/block.js +9 -3
  27. package/build/components/list-view/block.js.map +1 -1
  28. package/build/components/rich-text/index.js +4 -2
  29. package/build/components/rich-text/index.js.map +1 -1
  30. package/build/components/use-block-drop-zone/index.js +5 -1
  31. package/build/components/use-block-drop-zone/index.js.map +1 -1
  32. package/build/hooks/block-bindings.js +9 -4
  33. package/build/hooks/block-bindings.js.map +1 -1
  34. package/build/store/private-selectors.js +19 -1
  35. package/build/store/private-selectors.js.map +1 -1
  36. package/build/store/reducer.js +1 -5
  37. package/build/store/reducer.js.map +1 -1
  38. package/build/utils/block-bindings.js +3 -48
  39. package/build/utils/block-bindings.js.map +1 -1
  40. package/build-module/components/background-image-control/index.js +52 -25
  41. package/build-module/components/background-image-control/index.js.map +1 -1
  42. package/build-module/components/block-edit/edit.js +14 -6
  43. package/build-module/components/block-edit/edit.js.map +1 -1
  44. package/build-module/components/block-list/block.js +14 -4
  45. package/build-module/components/block-list/block.js.map +1 -1
  46. package/build-module/components/block-list/use-block-props/index.js +5 -4
  47. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  48. package/build-module/components/block-settings-menu-controls/index.js +10 -2
  49. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  50. package/build-module/components/block-toolbar/index.js +5 -0
  51. package/build-module/components/block-toolbar/index.js.map +1 -1
  52. package/build-module/components/block-visibility/index.js +3 -0
  53. package/build-module/components/block-visibility/index.js.map +1 -0
  54. package/build-module/components/block-visibility/menu-item.js +45 -0
  55. package/build-module/components/block-visibility/menu-item.js.map +1 -0
  56. package/build-module/components/block-visibility/toolbar.js +81 -0
  57. package/build-module/components/block-visibility/toolbar.js.map +1 -0
  58. package/build-module/components/inspector-controls-tabs/index.js +23 -0
  59. package/build-module/components/inspector-controls-tabs/index.js.map +1 -1
  60. package/build-module/components/link-control/index.js +1 -1
  61. package/build-module/components/link-control/index.js.map +1 -1
  62. package/build-module/components/list-view/block-select-button.js +24 -5
  63. package/build-module/components/list-view/block-select-button.js.map +1 -1
  64. package/build-module/components/list-view/block.js +9 -3
  65. package/build-module/components/list-view/block.js.map +1 -1
  66. package/build-module/components/rich-text/index.js +4 -2
  67. package/build-module/components/rich-text/index.js.map +1 -1
  68. package/build-module/components/use-block-drop-zone/index.js +6 -2
  69. package/build-module/components/use-block-drop-zone/index.js.map +1 -1
  70. package/build-module/hooks/block-bindings.js +10 -5
  71. package/build-module/hooks/block-bindings.js.map +1 -1
  72. package/build-module/store/private-selectors.js +18 -1
  73. package/build-module/store/private-selectors.js.map +1 -1
  74. package/build-module/store/reducer.js +1 -5
  75. package/build-module/store/reducer.js.map +1 -1
  76. package/build-module/utils/block-bindings.js +3 -45
  77. package/build-module/utils/block-bindings.js.map +1 -1
  78. package/build-style/content-rtl.css +13 -0
  79. package/build-style/content.css +13 -0
  80. package/build-style/style-rtl.css +27 -0
  81. package/build-style/style.css +27 -0
  82. package/package.json +34 -34
  83. package/src/components/background-image-control/index.js +54 -27
  84. package/src/components/background-image-control/style.scss +28 -0
  85. package/src/components/block-edit/edit.js +23 -5
  86. package/src/components/block-list/block.js +16 -0
  87. package/src/components/block-list/content.scss +19 -0
  88. package/src/components/block-list/use-block-props/index.js +9 -9
  89. package/src/components/block-settings-menu-controls/index.js +21 -1
  90. package/src/components/block-toolbar/index.js +9 -0
  91. package/src/components/block-visibility/index.js +2 -0
  92. package/src/components/block-visibility/menu-item.js +53 -0
  93. package/src/components/block-visibility/toolbar.js +88 -0
  94. package/src/components/inspector-controls-tabs/index.js +33 -1
  95. package/src/components/link-control/index.js +1 -1
  96. package/src/components/link-control/test/index.js +4 -4
  97. package/src/components/list-view/block-select-button.js +32 -9
  98. package/src/components/list-view/block.js +24 -14
  99. package/src/components/list-view/style.scss +1 -0
  100. package/src/components/media-replace-flow/test/index.js +1 -1
  101. package/src/components/rich-text/index.js +6 -2
  102. package/src/components/use-block-drop-zone/index.js +14 -1
  103. package/src/hooks/block-bindings.js +49 -43
  104. package/src/store/private-selectors.js +21 -1
  105. package/src/store/reducer.js +1 -6
  106. 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 } = useSelect(
216
- ( select ) => {
217
- if ( ! bindableAttributes || bindableAttributes.length === 0 ) {
218
- return EMPTY_OBJECT;
219
- }
220
- const registeredSources = getBlockBindingsSources();
221
- Object.entries( registeredSources ).forEach(
222
- ( [ sourceName, { getFieldsList, usesContext } ] ) => {
223
- if ( getFieldsList ) {
224
- // Populate context.
225
- const context = {};
226
- if ( usesContext?.length ) {
227
- for ( const key of usesContext ) {
228
- context[ key ] = blockContext[ key ];
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
- return {
243
- fieldsList:
244
- Object.values( _fieldsList ).length > 0
245
- ? _fieldsList
246
- : EMPTY_OBJECT,
247
- canUpdateBlockBindings:
248
- select( blockEditorStore ).getSettings()
249
- .canUpdateBlockBindings,
250
- };
251
- },
252
- [ blockContext, bindableAttributes ]
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
- ! canBindAttribute( blockName, key ) ||
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 { privateApis as blocksPrivateApis } from '@wordpress/blocks';
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
+ };
@@ -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
- // There's a chance we only just calculated this for the parent,
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} blockName The block name (e.g. 'core/paragraph').
89
- * @param {?Record<string, object>} bindings A block's bindings from the metadata attribute.
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( blockName, bindings ) {
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.