@wordpress/block-editor 12.19.3 → 12.19.5

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 (165) hide show
  1. package/build/components/block-actions/index.js +45 -32
  2. package/build/components/block-actions/index.js.map +1 -1
  3. package/build/components/block-bindings-toolbar-indicator/index.js +25 -0
  4. package/build/components/block-bindings-toolbar-indicator/index.js.map +1 -0
  5. package/build/components/block-edit/context.js +2 -1
  6. package/build/components/block-edit/context.js.map +1 -1
  7. package/build/components/block-edit/index.js +8 -3
  8. package/build/components/block-edit/index.js.map +1 -1
  9. package/build/components/block-inspector/index.js +5 -4
  10. package/build/components/block-inspector/index.js.map +1 -1
  11. package/build/components/block-list/use-block-props/index.js +8 -1
  12. package/build/components/block-list/use-block-props/index.js.map +1 -1
  13. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -3
  14. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  15. package/build/components/block-preview/index.js +4 -0
  16. package/build/components/block-preview/index.js.map +1 -1
  17. package/build/components/block-settings-menu/block-settings-dropdown.js +12 -10
  18. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  19. package/build/components/block-toolbar/index.js +14 -5
  20. package/build/components/block-toolbar/index.js.map +1 -1
  21. package/build/components/global-styles/border-panel.js +21 -8
  22. package/build/components/global-styles/border-panel.js.map +1 -1
  23. package/build/components/global-styles/index.js +6 -0
  24. package/build/components/global-styles/index.js.map +1 -1
  25. package/build/components/global-styles/shadow-panel-components.js +80 -23
  26. package/build/components/global-styles/shadow-panel-components.js.map +1 -1
  27. package/build/components/inspector-controls-tabs/styles-tab.js +1 -1
  28. package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  29. package/build/components/link-control/link-preview.js +4 -1
  30. package/build/components/link-control/link-preview.js.map +1 -1
  31. package/build/components/list-view/block-select-button.js +10 -2
  32. package/build/components/list-view/block-select-button.js.map +1 -1
  33. package/build/components/list-view/use-clipboard-handler.js +2 -1
  34. package/build/components/list-view/use-clipboard-handler.js.map +1 -1
  35. package/build/components/rich-text/index.js +46 -26
  36. package/build/components/rich-text/index.js.map +1 -1
  37. package/build/components/rich-text/use-enter.js +3 -0
  38. package/build/components/rich-text/use-enter.js.map +1 -1
  39. package/build/components/url-popover/index.js +3 -3
  40. package/build/components/url-popover/index.js.map +1 -1
  41. package/build/components/writing-flow/use-clipboard-handler.js +2 -1
  42. package/build/components/writing-flow/use-clipboard-handler.js.map +1 -1
  43. package/build/components/writing-flow/utils.js +23 -6
  44. package/build/components/writing-flow/utils.js.map +1 -1
  45. package/build/hooks/block-hooks.js +34 -8
  46. package/build/hooks/block-hooks.js.map +1 -1
  47. package/build/hooks/border.js +6 -4
  48. package/build/hooks/border.js.map +1 -1
  49. package/build/hooks/use-bindings-attributes.js +171 -48
  50. package/build/hooks/use-bindings-attributes.js.map +1 -1
  51. package/build/private-apis.js +5 -1
  52. package/build/private-apis.js.map +1 -1
  53. package/build/store/actions.js +40 -6
  54. package/build/store/actions.js.map +1 -1
  55. package/build/store/private-actions.js +0 -10
  56. package/build/store/private-actions.js.map +1 -1
  57. package/build/store/private-selectors.js +0 -8
  58. package/build/store/private-selectors.js.map +1 -1
  59. package/build/store/reducer.js +1 -16
  60. package/build/store/reducer.js.map +1 -1
  61. package/build-module/components/block-actions/index.js +45 -32
  62. package/build-module/components/block-actions/index.js.map +1 -1
  63. package/build-module/components/block-bindings-toolbar-indicator/index.js +18 -0
  64. package/build-module/components/block-bindings-toolbar-indicator/index.js.map +1 -0
  65. package/build-module/components/block-edit/context.js +1 -0
  66. package/build-module/components/block-edit/context.js.map +1 -1
  67. package/build-module/components/block-edit/index.js +9 -4
  68. package/build-module/components/block-edit/index.js.map +1 -1
  69. package/build-module/components/block-inspector/index.js +6 -5
  70. package/build-module/components/block-inspector/index.js.map +1 -1
  71. package/build-module/components/block-list/use-block-props/index.js +9 -2
  72. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  73. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -3
  74. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  75. package/build-module/components/block-preview/index.js +4 -0
  76. package/build-module/components/block-preview/index.js.map +1 -1
  77. package/build-module/components/block-settings-menu/block-settings-dropdown.js +12 -10
  78. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  79. package/build-module/components/block-toolbar/index.js +14 -5
  80. package/build-module/components/block-toolbar/index.js.map +1 -1
  81. package/build-module/components/global-styles/border-panel.js +22 -10
  82. package/build-module/components/global-styles/border-panel.js.map +1 -1
  83. package/build-module/components/global-styles/index.js +1 -1
  84. package/build-module/components/global-styles/index.js.map +1 -1
  85. package/build-module/components/global-styles/shadow-panel-components.js +82 -24
  86. package/build-module/components/global-styles/shadow-panel-components.js.map +1 -1
  87. package/build-module/components/inspector-controls-tabs/styles-tab.js +2 -2
  88. package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  89. package/build-module/components/link-control/link-preview.js +5 -2
  90. package/build-module/components/link-control/link-preview.js.map +1 -1
  91. package/build-module/components/list-view/block-select-button.js +11 -3
  92. package/build-module/components/list-view/block-select-button.js.map +1 -1
  93. package/build-module/components/list-view/use-clipboard-handler.js +3 -2
  94. package/build-module/components/list-view/use-clipboard-handler.js.map +1 -1
  95. package/build-module/components/rich-text/index.js +47 -28
  96. package/build-module/components/rich-text/index.js.map +1 -1
  97. package/build-module/components/rich-text/use-enter.js +3 -0
  98. package/build-module/components/rich-text/use-enter.js.map +1 -1
  99. package/build-module/components/url-popover/index.js +3 -3
  100. package/build-module/components/url-popover/index.js.map +1 -1
  101. package/build-module/components/writing-flow/use-clipboard-handler.js +3 -2
  102. package/build-module/components/writing-flow/use-clipboard-handler.js.map +1 -1
  103. package/build-module/components/writing-flow/utils.js +22 -7
  104. package/build-module/components/writing-flow/utils.js.map +1 -1
  105. package/build-module/hooks/block-hooks.js +34 -8
  106. package/build-module/hooks/block-hooks.js.map +1 -1
  107. package/build-module/hooks/border.js +7 -5
  108. package/build-module/hooks/border.js.map +1 -1
  109. package/build-module/hooks/use-bindings-attributes.js +172 -49
  110. package/build-module/hooks/use-bindings-attributes.js.map +1 -1
  111. package/build-module/private-apis.js +5 -1
  112. package/build-module/private-apis.js.map +1 -1
  113. package/build-module/store/actions.js +40 -6
  114. package/build-module/store/actions.js.map +1 -1
  115. package/build-module/store/private-actions.js +0 -9
  116. package/build-module/store/private-actions.js.map +1 -1
  117. package/build-module/store/private-selectors.js +0 -6
  118. package/build-module/store/private-selectors.js.map +1 -1
  119. package/build-module/store/reducer.js +1 -16
  120. package/build-module/store/reducer.js.map +1 -1
  121. package/build-style/content-rtl.css +1 -0
  122. package/build-style/content.css +1 -0
  123. package/build-style/default-editor-styles-rtl.css +1 -0
  124. package/build-style/default-editor-styles.css +1 -0
  125. package/build-style/style-rtl.css +70 -14
  126. package/build-style/style.css +70 -14
  127. package/package.json +8 -8
  128. package/src/components/block-actions/index.js +57 -47
  129. package/src/components/block-bindings-toolbar-indicator/index.js +20 -0
  130. package/src/components/block-bindings-toolbar-indicator/style.scss +14 -0
  131. package/src/components/block-edit/context.js +1 -0
  132. package/src/components/block-edit/index.js +5 -1
  133. package/src/components/block-inspector/index.js +7 -5
  134. package/src/components/block-list/use-block-props/index.js +12 -2
  135. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -7
  136. package/src/components/block-preview/index.js +6 -1
  137. package/src/components/block-settings-menu/block-settings-dropdown.js +12 -9
  138. package/src/components/block-toolbar/index.js +14 -4
  139. package/src/components/block-toolbar/style.scss +11 -6
  140. package/src/components/global-styles/border-panel.js +33 -22
  141. package/src/components/global-styles/index.js +5 -1
  142. package/src/components/global-styles/shadow-panel-components.js +92 -23
  143. package/src/components/global-styles/style.scss +33 -10
  144. package/src/components/inspector-controls-tabs/styles-tab.js +2 -2
  145. package/src/components/link-control/link-preview.js +9 -2
  146. package/src/components/link-control/style.scss +9 -0
  147. package/src/components/list-view/block-select-button.js +16 -2
  148. package/src/components/list-view/style.scss +8 -0
  149. package/src/components/list-view/use-clipboard-handler.js +3 -2
  150. package/src/components/rich-text/index.js +75 -52
  151. package/src/components/rich-text/use-enter.js +4 -0
  152. package/src/components/url-popover/index.js +5 -5
  153. package/src/components/url-popover/style.scss +1 -0
  154. package/src/components/writing-flow/use-clipboard-handler.js +3 -2
  155. package/src/components/writing-flow/utils.js +31 -16
  156. package/src/hooks/block-hooks.js +46 -8
  157. package/src/hooks/block-hooks.scss +6 -0
  158. package/src/hooks/border.js +16 -4
  159. package/src/hooks/use-bindings-attributes.js +215 -65
  160. package/src/private-apis.js +4 -0
  161. package/src/store/actions.js +54 -14
  162. package/src/store/private-actions.js +0 -10
  163. package/src/store/private-selectors.js +0 -8
  164. package/src/store/reducer.js +0 -15
  165. package/src/style.scss +1 -0
@@ -16,31 +16,40 @@ import { store as blockEditorStore } from '../store';
16
16
  const EMPTY_OBJECT = {};
17
17
  function BlockHooksControlPure({
18
18
  name,
19
- clientId
19
+ clientId,
20
+ metadata: {
21
+ ignoredHookedBlocks = []
22
+ } = {}
20
23
  }) {
21
24
  const blockTypes = useSelect(select => select(blocksStore).getBlockTypes(), []);
25
+
26
+ // A hooked block added via a filter will not be exposed through a block
27
+ // type's `blockHooks` property; however, if the containing layout has been
28
+ // modified, it will be present in the anchor block's `ignoredHookedBlocks`
29
+ // metadata.
22
30
  const hookedBlocksForCurrentBlock = useMemo(() => blockTypes?.filter(({
31
+ name: blockName,
23
32
  blockHooks
24
- }) => blockHooks && name in blockHooks), [blockTypes, name]);
33
+ }) => blockHooks && name in blockHooks || ignoredHookedBlocks.includes(blockName)), [blockTypes, name, ignoredHookedBlocks]);
25
34
  const {
26
35
  blockIndex,
27
36
  rootClientId,
28
37
  innerBlocksLength
29
38
  } = useSelect(select => {
30
39
  const {
31
- getBlock,
40
+ getBlocks,
32
41
  getBlockIndex,
33
42
  getBlockRootClientId
34
43
  } = select(blockEditorStore);
35
44
  return {
36
45
  blockIndex: getBlockIndex(clientId),
37
- innerBlocksLength: getBlock(clientId)?.innerBlocks?.length,
46
+ innerBlocksLength: getBlocks(clientId)?.length,
38
47
  rootClientId: getBlockRootClientId(clientId)
39
48
  };
40
49
  }, [clientId]);
41
50
  const hookedBlockClientIds = useSelect(select => {
42
51
  const {
43
- getBlock,
52
+ getBlocks,
44
53
  getGlobalBlockCount
45
54
  } = select(blockEditorStore);
46
55
  const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce((clientIds, block) => {
@@ -57,14 +66,20 @@ function BlockHooksControlPure({
57
66
  // Any of the current block's siblings (with the right block type) qualifies
58
67
  // as a hooked block (inserted `before` or `after` the current one), as the block
59
68
  // might've been automatically inserted and then moved around a bit by the user.
60
- candidates = getBlock(rootClientId)?.innerBlocks;
69
+ candidates = getBlocks(rootClientId);
61
70
  break;
62
71
  case 'first_child':
63
72
  case 'last_child':
64
73
  // Any of the current block's child blocks (with the right block type) qualifies
65
74
  // as a hooked first or last child block, as the block might've been automatically
66
75
  // inserted and then moved around a bit by the user.
67
- candidates = getBlock(clientId).innerBlocks;
76
+ candidates = getBlocks(clientId);
77
+ break;
78
+ case undefined:
79
+ // If we haven't found a blockHooks field with a relative position for the hooked
80
+ // block, it means that it was added by a filter. In this case, we look for the block
81
+ // both among the current block's siblings and its children.
82
+ candidates = [...getBlocks(rootClientId), ...getBlocks(clientId)];
68
83
  break;
69
84
  }
70
85
  const hookedBlock = candidates?.find(candidate => candidate.name === block.name);
@@ -120,13 +135,23 @@ function BlockHooksControlPure({
120
135
  // Insert as a child of the current block.
121
136
  false);
122
137
  break;
138
+ case undefined:
139
+ // If we do not know the relative position, it is because the block was
140
+ // added via a filter. In this case, we default to inserting it after the
141
+ // current block.
142
+ insertBlock(block, blockIndex + 1, rootClientId,
143
+ // Insert as a child of the current block's parent
144
+ false);
145
+ break;
123
146
  }
124
147
  };
125
148
  return createElement(InspectorControls, null, createElement(PanelBody, {
126
149
  className: "block-editor-hooks__block-hooks",
127
150
  title: __('Plugins'),
128
151
  initialOpen: true
129
- }, Object.keys(groupedHookedBlocks).map(vendor => {
152
+ }, createElement("p", {
153
+ className: "block-editor-hooks__block-hooks-helptext"
154
+ }, __('Manage the inclusion of blocks added automatically by plugins.')), Object.keys(groupedHookedBlocks).map(vendor => {
130
155
  return createElement(Fragment, {
131
156
  key: vendor
132
157
  }, createElement("h3", null, vendor), groupedHookedBlocks[vendor].map(block => {
@@ -156,6 +181,7 @@ function BlockHooksControlPure({
156
181
  }
157
182
  export default {
158
183
  edit: BlockHooksControlPure,
184
+ attributeKeys: ['metadata'],
159
185
  hasSupport() {
160
186
  return true;
161
187
  }
@@ -1 +1 @@
1
- {"version":3,"names":["__","Fragment","useMemo","__experimentalHStack","HStack","PanelBody","ToggleControl","createBlock","store","blocksStore","useDispatch","useSelect","BlockIcon","InspectorControls","blockEditorStore","EMPTY_OBJECT","BlockHooksControlPure","name","clientId","blockTypes","select","getBlockTypes","hookedBlocksForCurrentBlock","filter","blockHooks","blockIndex","rootClientId","innerBlocksLength","getBlock","getBlockIndex","getBlockRootClientId","innerBlocks","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","relativePosition","candidates","hookedBlock","find","candidate","Object","values","insertBlock","removeBlock","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","className","title","initialOpen","keys","map","vendor","key","checked","label","justify","icon","onChange","edit","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControlPure( { name, clientId } ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { blockHooks } ) => blockHooks && name in blockHooks\n\t\t\t),\n\t\t[ blockTypes, name ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\tinnerBlocksLength: getBlock( clientId )?.innerBlocks?.length,\n\t\t\t\trootClientId: getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to set the toggle to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition = block?.blockHooks?.[ name ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( rootClientId )?.innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( clientId ).innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( candidate ) => candidate.name === block.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// we set the toggle to disabled.\n\t\t\t\t\treturn clientIds;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[ hookedBlocksForCurrentBlock, name, clientId, rootClientId ]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\tif ( ! hookedBlocksForCurrentBlock.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tclientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[ name ];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock(\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default {\n\tedit: BlockHooksControlPure,\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,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AGD;IAAQ,GACvBN,aAAA,aAAMM,MAAY,CAAC,EACjBZ,mBAAmB,CAAEY,MAAM,CAAE,CAACD,GAAG,CAAIrB,KAAK,IAAM;MACjD,MAAMwB,OAAO,IACZxB,KAAK,CAACrB,IAAI,IAAIgB,oBAAoB;MAEnC,OACCqB,aAAA,CAAChD,aAAa;QACbwD,OAAO,EAAGA,OAAS;QACnBD,GAAG,EAAGvB,KAAK,CAACkB,KAAO;QACnBO,KAAK,EACJT,aAAA,CAAClD,MAAM;UAAC4D,OAAO,EAAC;QAAY,GAC3BV,aAAA,CAAC1C,SAAS;UACTqD,IAAI,EAAG3B,KAAK,CAAC2B;QAAM,CACnB,CAAC,EACFX,aAAA,eAAQhB,KAAK,CAACkB,KAAa,CACpB,CACR;QACDU,QAAQ,EAAGA,CAAA,KAAM;UAChB,IAAK,CAAEJ,OAAO,EAAG;YAChB;YACA,MAAMvB,gBAAgB,GACrBD,KAAK,CAACd,UAAU,CAAEP,IAAI,CAAE;YACzBoC,iCAAiC,CAChC9C,WAAW,CAAE+B,KAAK,CAACrB,IAAK,CAAC,EACzBsB,gBACD,CAAC;YACD;UACD;;UAEA;UACAQ,WAAW,CACVd,oBAAoB,CACnBK,KAAK,CAACrB,IAAI,CACV,EACD,KACD,CAAC;QACF;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAEA,eAAe;EACdkD,IAAI,EAAEnD,qBAAqB;EAC3BoD,UAAUA,CAAA,EAAG;IACZ,OAAO,IAAI;EACZ;AACD,CAAC"}
1
+ {"version":3,"names":["__","Fragment","useMemo","__experimentalHStack","HStack","PanelBody","ToggleControl","createBlock","store","blocksStore","useDispatch","useSelect","BlockIcon","InspectorControls","blockEditorStore","EMPTY_OBJECT","BlockHooksControlPure","name","clientId","metadata","ignoredHookedBlocks","blockTypes","select","getBlockTypes","hookedBlocksForCurrentBlock","filter","blockName","blockHooks","includes","blockIndex","rootClientId","innerBlocksLength","getBlocks","getBlockIndex","getBlockRootClientId","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","relativePosition","candidates","undefined","hookedBlock","find","candidate","Object","values","insertBlock","removeBlock","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","className","title","initialOpen","keys","map","vendor","key","checked","label","justify","icon","onChange","edit","attributeKeys","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControlPure( {\n\tname,\n\tclientId,\n\tmetadata: { ignoredHookedBlocks = [] } = {},\n} ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\t// A hooked block added via a filter will not be exposed through a block\n\t// type's `blockHooks` property; however, if the containing layout has been\n\t// modified, it will be present in the anchor block's `ignoredHookedBlocks`\n\t// metadata.\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { name: blockName, blockHooks } ) =>\n\t\t\t\t\t( blockHooks && name in blockHooks ) ||\n\t\t\t\t\tignoredHookedBlocks.includes( blockName )\n\t\t\t),\n\t\t[ blockTypes, name, ignoredHookedBlocks ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\tinnerBlocksLength: getBlocks( clientId )?.length,\n\t\t\t\trootClientId: getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to set the toggle to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition = block?.blockHooks?.[ name ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlocks( rootClientId );\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlocks( clientId );\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase undefined:\n\t\t\t\t\t\t\t// If we haven't found a blockHooks field with a relative position for the hooked\n\t\t\t\t\t\t\t// block, it means that it was added by a filter. In this case, we look for the block\n\t\t\t\t\t\t\t// both among the current block's siblings and its children.\n\t\t\t\t\t\t\tcandidates = [\n\t\t\t\t\t\t\t\t...getBlocks( rootClientId ),\n\t\t\t\t\t\t\t\t...getBlocks( clientId ),\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( candidate ) => candidate.name === block.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// we set the toggle to disabled.\n\t\t\t\t\treturn clientIds;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[ hookedBlocksForCurrentBlock, name, clientId, rootClientId ]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\tif ( ! hookedBlocksForCurrentBlock.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tclientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase undefined:\n\t\t\t\t// If we do not know the relative position, it is because the block was\n\t\t\t\t// added via a filter. In this case, we default to inserting it after the\n\t\t\t\t// current block.\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\tblockIndex + 1,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t<p className=\"block-editor-hooks__block-hooks-helptext\">\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Manage the inclusion of blocks added automatically by plugins.'\n\t\t\t\t\t) }\n\t\t\t\t</p>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[ name ];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock(\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default {\n\tedit: BlockHooksControlPure,\n\tattributeKeys: [ 'metadata' ],\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,SAAS,EACTC,aAAa,QACP,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACrE,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;;AAExD;AACA;AACA;AACA,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,eAAe;AAC5D,SAASL,KAAK,IAAIM,gBAAgB,QAAQ,UAAU;AAEpD,MAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,SAASC,qBAAqBA,CAAE;EAC/BC,IAAI;EACJC,QAAQ;EACRC,QAAQ,EAAE;IAAEC,mBAAmB,GAAG;EAAG,CAAC,GAAG,CAAC;AAC3C,CAAC,EAAG;EACH,MAAMC,UAAU,GAAGV,SAAS,CACzBW,MAAM,IAAMA,MAAM,CAAEb,WAAY,CAAC,CAACc,aAAa,CAAC,CAAC,EACnD,EACD,CAAC;;EAED;EACA;EACA;EACA;EACA,MAAMC,2BAA2B,GAAGtB,OAAO,CAC1C,MACCmB,UAAU,EAAEI,MAAM,CACjB,CAAE;IAAER,IAAI,EAAES,SAAS;IAAEC;EAAW,CAAC,KAC9BA,UAAU,IAAIV,IAAI,IAAIU,UAAU,IAClCP,mBAAmB,CAACQ,QAAQ,CAAEF,SAAU,CAC1C,CAAC,EACF,CAAEL,UAAU,EAAEJ,IAAI,EAAEG,mBAAm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CACR;QACDU,QAAQ,EAAGA,CAAA,KAAM;UAChB,IAAK,CAAEJ,OAAO,EAAG;YAChB;YACA,MAAMxB,gBAAgB,GACrBD,KAAK,CAACd,UAAU,CAAEV,IAAI,CAAE;YACzBwC,iCAAiC,CAChClD,WAAW,CAAEkC,KAAK,CAACxB,IAAK,CAAC,EACzByB,gBACD,CAAC;YACD;UACD;;UAEA;UACAS,WAAW,CACVf,oBAAoB,CACnBK,KAAK,CAACxB,IAAI,CACV,EACD,KACD,CAAC;QACF;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAEA,eAAe;EACdsD,IAAI,EAAEvD,qBAAqB;EAC3BwD,aAAa,EAAE,CAAE,UAAU,CAAE;EAC7BC,UAAUA,CAAA,EAAG;IACZ,OAAO,IAAI;EACZ;AACD,CAAC"}
@@ -19,8 +19,8 @@ import { useSelect } from '@wordpress/data';
19
19
  import { getColorClassName } from '../components/colors';
20
20
  import InspectorControls from '../components/inspector-controls';
21
21
  import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
22
- import { cleanEmptyObject, shouldSkipSerialization } from './utils';
23
- import { useHasBorderPanel, BorderPanel as StylesBorderPanel } from '../components/global-styles';
22
+ import { cleanEmptyObject, shouldSkipSerialization, useBlockSettings } from './utils';
23
+ import { useHasBorderPanel, useHasBorderPanelControls, BorderPanel as StylesBorderPanel } from '../components/global-styles';
24
24
  import { store as blockEditorStore } from '../store';
25
25
  import { __ } from '@wordpress/i18n';
26
26
  export const BORDER_SUPPORT_KEY = '__experimentalBorder';
@@ -200,14 +200,16 @@ export function hasBorderSupport(blockName, feature = 'any') {
200
200
  export function hasShadowSupport(blockName) {
201
201
  return hasBlockSupport(blockName, SHADOW_SUPPORT_KEY);
202
202
  }
203
- export function getBorderPanelLabel({
203
+ export function useBorderPanelLabel({
204
204
  blockName,
205
205
  hasBorderControl,
206
206
  hasShadowControl
207
207
  } = {}) {
208
+ const settings = useBlockSettings(blockName);
209
+ const controls = useHasBorderPanelControls(settings);
208
210
  if (!hasBorderControl && !hasShadowControl && blockName) {
209
- hasBorderControl = hasBorderSupport(blockName);
210
- hasShadowControl = hasShadowSupport(blockName);
211
+ hasBorderControl = controls?.hasBorderColor || controls?.hasBorderStyle || controls?.hasBorderWidth || controls?.hasBorderRadius;
212
+ hasShadowControl = controls?.hasShadow;
211
213
  }
212
214
  if (hasBorderControl && hasShadowControl) {
213
215
  return __('Border & Shadow');
@@ -1 +1 @@
1
- {"version":3,"names":["classnames","hasBlockSupport","getBlockSupport","__experimentalHasSplitBorders","hasSplitBorders","Platform","useCallback","useMemo","addFilter","useSelect","getColorClassName","InspectorControls","useMultipleOriginColorsAndGradients","cleanEmptyObject","shouldSkipSerialization","useHasBorderPanel","BorderPanel","StylesBorderPanel","store","blockEditorStore","__","BORDER_SUPPORT_KEY","SHADOW_SUPPORT_KEY","getColorByProperty","colors","property","value","matchedColor","some","origin","color","getMultiOriginColor","namedColor","customColor","colorObject","undefined","getColorSlugFromVariable","exec","styleToAttributes","style","border","borderColor","borderColorValue","borderColorSlug","startsWith","substring","length","updatedStyle","attributesToStyle","attributes","BordersInspectorControl","label","children","resetAllFilter","attributesResetAllFilter","existingStyle","createElement","group","clientId","name","setAttributes","settings","isEnabled","selector","select","getBlockAttributes","onChange","newStyle","defaultControls","as","panelId","hasBorderSupport","blockName","feature","OS","support","radius","width","hasShadowSupport","getBorderPanelLabel","hasBorderControl","hasShadowControl","removeBorderAttribute","attribute","addAttributes","type","addSaveProps","props","blockNameOrType","borderClasses","getBorderClasses","newClassName","className","borderColorClass","useBlockProps","borderTopColor","top","borderRightColor","right","borderBottomColor","bottom","borderLeftColor","left","extraStyles","attributeKeys","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/border.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, getBlockSupport } from '@wordpress/blocks';\nimport { __experimentalHasSplitBorders as hasSplitBorders } from '@wordpress/components';\nimport { Platform, useCallback, useMemo } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { getColorClassName } from '../components/colors';\nimport InspectorControls from '../components/inspector-controls';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport { cleanEmptyObject, shouldSkipSerialization } from './utils';\nimport {\n\tuseHasBorderPanel,\n\tBorderPanel as StylesBorderPanel,\n} from '../components/global-styles';\nimport { store as blockEditorStore } from '../store';\nimport { __ } from '@wordpress/i18n';\n\nexport const BORDER_SUPPORT_KEY = '__experimentalBorder';\nexport const SHADOW_SUPPORT_KEY = 'shadow';\n\nconst getColorByProperty = ( colors, property, value ) => {\n\tlet matchedColor;\n\n\tcolors.some( ( origin ) =>\n\t\torigin.colors.some( ( color ) => {\n\t\t\tif ( color[ property ] === value ) {\n\t\t\t\tmatchedColor = color;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t} )\n\t);\n\n\treturn matchedColor;\n};\n\nexport const getMultiOriginColor = ( { colors, namedColor, customColor } ) => {\n\t// Search each origin (default, theme, or user) for matching color by name.\n\tif ( namedColor ) {\n\t\tconst colorObject = getColorByProperty( colors, 'slug', namedColor );\n\t\tif ( colorObject ) {\n\t\t\treturn colorObject;\n\t\t}\n\t}\n\n\t// Skip if no custom color or matching named color.\n\tif ( ! customColor ) {\n\t\treturn { color: undefined };\n\t}\n\n\t// Attempt to find color via custom color value or build new object.\n\tconst colorObject = getColorByProperty( colors, 'color', customColor );\n\treturn colorObject ? colorObject : { color: customColor };\n};\n\nfunction getColorSlugFromVariable( value ) {\n\tconst namedColor = /var:preset\\|color\\|(.+)/.exec( value );\n\tif ( namedColor && namedColor[ 1 ] ) {\n\t\treturn namedColor[ 1 ];\n\t}\n\treturn null;\n}\n\nfunction styleToAttributes( style ) {\n\tif ( hasSplitBorders( style?.border ) ) {\n\t\treturn {\n\t\t\tstyle,\n\t\t\tborderColor: undefined,\n\t\t};\n\t}\n\n\tconst borderColorValue = style?.border?.color;\n\tconst borderColorSlug = borderColorValue?.startsWith( 'var:preset|color|' )\n\t\t? borderColorValue.substring( 'var:preset|color|'.length )\n\t\t: undefined;\n\tconst updatedStyle = { ...style };\n\tupdatedStyle.border = {\n\t\t...updatedStyle.border,\n\t\tcolor: borderColorSlug ? undefined : borderColorValue,\n\t};\n\treturn {\n\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\tborderColor: borderColorSlug,\n\t};\n}\n\nfunction attributesToStyle( attributes ) {\n\tif ( hasSplitBorders( attributes.style?.border ) ) {\n\t\treturn attributes.style;\n\t}\n\treturn {\n\t\t...attributes.style,\n\t\tborder: {\n\t\t\t...attributes.style?.border,\n\t\t\tcolor: attributes.borderColor\n\t\t\t\t? 'var:preset|color|' + attributes.borderColor\n\t\t\t\t: attributes.style?.border?.color,\n\t\t},\n\t};\n}\n\nfunction BordersInspectorControl( { label, children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributesToStyle( attributes );\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\t...styleToAttributes( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"border\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t\tlabel={ label }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function BorderPanel( { clientId, name, setAttributes, settings } ) {\n\tconst isEnabled = useHasBorderPanel( settings );\n\tfunction selector( select ) {\n\t\tconst { style, borderColor } =\n\t\t\tselect( blockEditorStore ).getBlockAttributes( clientId ) || {};\n\t\treturn { style, borderColor };\n\t}\n\tconst { style, borderColor } = useSelect( selector, [ clientId ] );\n\tconst value = useMemo( () => {\n\t\treturn attributesToStyle( { style, borderColor } );\n\t}, [ style, borderColor ] );\n\n\tconst onChange = ( newStyle ) => {\n\t\tsetAttributes( styleToAttributes( newStyle ) );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultControls = {\n\t\t...getBlockSupport( name, [\n\t\t\tBORDER_SUPPORT_KEY,\n\t\t\t'__experimentalDefaultControls',\n\t\t] ),\n\t\t...getBlockSupport( name, [\n\t\t\tSHADOW_SUPPORT_KEY,\n\t\t\t'__experimentalDefaultControls',\n\t\t] ),\n\t};\n\n\treturn (\n\t\t<StylesBorderPanel\n\t\t\tas={ BordersInspectorControl }\n\t\t\tpanelId={ clientId }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t/>\n\t);\n}\n\n/**\n * Determine whether there is block support for border properties.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Border feature to check support for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBorderSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BORDER_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (\n\t\t\tsupport?.color ||\n\t\t\tsupport?.radius ||\n\t\t\tsupport?.width ||\n\t\t\tsupport?.style\n\t\t);\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Determine whether there is block support for shadow properties.\n *\n * @param {string} blockName Block name.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasShadowSupport( blockName ) {\n\treturn hasBlockSupport( blockName, SHADOW_SUPPORT_KEY );\n}\n\nexport function getBorderPanelLabel( {\n\tblockName,\n\thasBorderControl,\n\thasShadowControl,\n} = {} ) {\n\tif ( ! hasBorderControl && ! hasShadowControl && blockName ) {\n\t\thasBorderControl = hasBorderSupport( blockName );\n\t\thasShadowControl = hasShadowSupport( blockName );\n\t}\n\n\tif ( hasBorderControl && hasShadowControl ) {\n\t\treturn __( 'Border & Shadow' );\n\t}\n\n\tif ( hasShadowControl ) {\n\t\treturn __( 'Shadow' );\n\t}\n\n\treturn __( 'Border' );\n}\n\n/**\n * Returns a new style object where the specified border attribute has been\n * removed.\n *\n * @param {Object} style Styles from block attributes.\n * @param {string} attribute The border style attribute to clear.\n *\n * @return {Object} Style object with the specified attribute removed.\n */\nexport function removeBorderAttribute( style, attribute ) {\n\treturn cleanEmptyObject( {\n\t\t...style,\n\t\tborder: {\n\t\t\t...style?.border,\n\t\t\t[ attribute ]: undefined,\n\t\t},\n\t} );\n}\n\n/**\n * Filters registered block settings, extending attributes to include\n * `borderColor` if needed.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Updated block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBorderSupport( settings, 'color' ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify default value if needed.\n\tif ( settings.attributes.borderColor ) {\n\t\treturn settings;\n\t}\n\n\t// Add new borderColor attribute to block settings.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tborderColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Override props assigned to save component to inject border color.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object|string} blockNameOrType Block type definition.\n * @param {Object} attributes Block's attributes.\n *\n * @return {Object} Filtered props to apply to save element.\n */\nfunction addSaveProps( props, blockNameOrType, attributes ) {\n\tif (\n\t\t! hasBorderSupport( blockNameOrType, 'color' ) ||\n\t\tshouldSkipSerialization( blockNameOrType, BORDER_SUPPORT_KEY, 'color' )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst borderClasses = getBorderClasses( attributes );\n\tconst newClassName = classnames( props.className, borderClasses );\n\n\t// If we are clearing the last of the previous classes in `className`\n\t// set it to `undefined` to avoid rendering empty DOM attributes.\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Generates a CSS class name consisting of all the applicable border color\n * classes given the current block attributes.\n *\n * @param {Object} attributes Block's attributes.\n *\n * @return {string} CSS class name.\n */\nexport function getBorderClasses( attributes ) {\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\treturn classnames( {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\n}\n\nfunction useBlockProps( { name, borderColor, style } ) {\n\tconst { colors } = useMultipleOriginColorsAndGradients();\n\n\tif (\n\t\t! hasBorderSupport( name, 'color' ) ||\n\t\tshouldSkipSerialization( name, BORDER_SUPPORT_KEY, 'color' )\n\t) {\n\t\treturn {};\n\t}\n\n\tconst { color: borderColorValue } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: borderColor,\n\t} );\n\tconst { color: borderTopColor } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: getColorSlugFromVariable( style?.border?.top?.color ),\n\t} );\n\tconst { color: borderRightColor } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: getColorSlugFromVariable( style?.border?.right?.color ),\n\t} );\n\n\tconst { color: borderBottomColor } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: getColorSlugFromVariable( style?.border?.bottom?.color ),\n\t} );\n\tconst { color: borderLeftColor } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: getColorSlugFromVariable( style?.border?.left?.color ),\n\t} );\n\n\tconst extraStyles = {\n\t\tborderTopColor: borderTopColor || borderColorValue,\n\t\tborderRightColor: borderRightColor || borderColorValue,\n\t\tborderBottomColor: borderBottomColor || borderColorValue,\n\t\tborderLeftColor: borderLeftColor || borderColorValue,\n\t};\n\n\treturn addSaveProps(\n\t\t{ style: cleanEmptyObject( extraStyles ) || {} },\n\t\tname,\n\t\t{ borderColor, style }\n\t);\n}\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'borderColor', 'style' ],\n\thasSupport( name ) {\n\t\treturn hasBorderSupport( name, 'color' );\n\t},\n};\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addAttributes',\n\taddAttributes\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,eAAe,EAAEC,eAAe,QAAQ,mBAAmB;AACpE,SAASC,6BAA6B,IAAIC,eAAe,QAAQ,uBAAuB;AACxF,SAASC,QAAQ,EAAEC,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;AACnE,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,OAAOC,iBAAiB,MAAM,kCAAkC;AAChE,OAAOC,mCAAmC,MAAM,yEAAyE;AACzH,SAASC,gBAAgB,EAAEC,uBAAuB,QAAQ,SAAS;AACnE,SACCC,iBAAiB,EACjBC,WAAW,IAAIC,iBAAiB,QAC1B,6BAA6B;AACpC,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,UAAU;AACpD,SAASC,EAAE,QAAQ,iBAAiB;AAEpC,OAAO,MAAMC,kBAAkB,GAAG,sBAAsB;AACxD,OAAO,MAAMC,kBAAkB,GAAG,QAAQ;AAE1C,MAAMC,kBAAkB,GAAGA,CAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,KAAM;EACzD,IAAIC,YAAY;EAEhBH,MAAM,CAACI,IAAI,CAAIC,MAAM,IACpBA,MAAM,CAACL,MAAM,CAACI,IAAI,CAAIE,KAAK,IAAM;IAChC,IAAKA,KAAK,CAAEL,QAAQ,CAAE,KAAKC,KAAK,EAAG;MAClCC,YAAY,GAAGG,KAAK;MACpB,O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K,EAAEuE;EAAgB,CAAC,GAAGtE,mBAAmB,CAAE;IACvDP,MAAM;IACNQ,UAAU,EAAEI,wBAAwB,CAAEG,KAAK,EAAEC,MAAM,EAAE8D,IAAI,EAAExE,KAAM;EAClE,CAAE,CAAC;EAEH,MAAMyE,WAAW,GAAG;IACnBR,cAAc,EAAEA,cAAc,IAAIrD,gBAAgB;IAClDuD,gBAAgB,EAAEA,gBAAgB,IAAIvD,gBAAgB;IACtDyD,iBAAiB,EAAEA,iBAAiB,IAAIzD,gBAAgB;IACxD2D,eAAe,EAAEA,eAAe,IAAI3D;EACrC,CAAC;EAED,OAAO4C,YAAY,CAClB;IAAE/C,KAAK,EAAE1B,gBAAgB,CAAE0F,WAAY,CAAC,IAAI,CAAC;EAAE,CAAC,EAChD5C,IAAI,EACJ;IAAElB,WAAW;IAAEF;EAAM,CACtB,CAAC;AACF;AAEA,eAAe;EACduD,aAAa;EACbR,YAAY;EACZkB,aAAa,EAAE,CAAE,aAAa,EAAE,OAAO,CAAE;EACzCC,UAAUA,CAAE9C,IAAI,EAAG;IAClB,OAAOY,gBAAgB,CAAEZ,IAAI,EAAE,OAAQ,CAAC;EACzC;AACD,CAAC;AAEDnD,SAAS,CACR,0BAA0B,EAC1B,2BAA2B,EAC3B4E,aACD,CAAC"}
1
+ {"version":3,"names":["classnames","hasBlockSupport","getBlockSupport","__experimentalHasSplitBorders","hasSplitBorders","Platform","useCallback","useMemo","addFilter","useSelect","getColorClassName","InspectorControls","useMultipleOriginColorsAndGradients","cleanEmptyObject","shouldSkipSerialization","useBlockSettings","useHasBorderPanel","useHasBorderPanelControls","BorderPanel","StylesBorderPanel","store","blockEditorStore","__","BORDER_SUPPORT_KEY","SHADOW_SUPPORT_KEY","getColorByProperty","colors","property","value","matchedColor","some","origin","color","getMultiOriginColor","namedColor","customColor","colorObject","undefined","getColorSlugFromVariable","exec","styleToAttributes","style","border","borderColor","borderColorValue","borderColorSlug","startsWith","substring","length","updatedStyle","attributesToStyle","attributes","BordersInspectorControl","label","children","resetAllFilter","attributesResetAllFilter","existingStyle","createElement","group","clientId","name","setAttributes","settings","isEnabled","selector","select","getBlockAttributes","onChange","newStyle","defaultControls","as","panelId","hasBorderSupport","blockName","feature","OS","support","radius","width","hasShadowSupport","useBorderPanelLabel","hasBorderControl","hasShadowControl","controls","hasBorderColor","hasBorderStyle","hasBorderWidth","hasBorderRadius","hasShadow","removeBorderAttribute","attribute","addAttributes","type","addSaveProps","props","blockNameOrType","borderClasses","getBorderClasses","newClassName","className","borderColorClass","useBlockProps","borderTopColor","top","borderRightColor","right","borderBottomColor","bottom","borderLeftColor","left","extraStyles","attributeKeys","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/border.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, getBlockSupport } from '@wordpress/blocks';\nimport { __experimentalHasSplitBorders as hasSplitBorders } from '@wordpress/components';\nimport { Platform, useCallback, useMemo } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { getColorClassName } from '../components/colors';\nimport InspectorControls from '../components/inspector-controls';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tcleanEmptyObject,\n\tshouldSkipSerialization,\n\tuseBlockSettings,\n} from './utils';\nimport {\n\tuseHasBorderPanel,\n\tuseHasBorderPanelControls,\n\tBorderPanel as StylesBorderPanel,\n} from '../components/global-styles';\nimport { store as blockEditorStore } from '../store';\nimport { __ } from '@wordpress/i18n';\n\nexport const BORDER_SUPPORT_KEY = '__experimentalBorder';\nexport const SHADOW_SUPPORT_KEY = 'shadow';\n\nconst getColorByProperty = ( colors, property, value ) => {\n\tlet matchedColor;\n\n\tcolors.some( ( origin ) =>\n\t\torigin.colors.some( ( color ) => {\n\t\t\tif ( color[ property ] === value ) {\n\t\t\t\tmatchedColor = color;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t} )\n\t);\n\n\treturn matchedColor;\n};\n\nexport const getMultiOriginColor = ( { colors, namedColor, customColor } ) => {\n\t// Search each origin (default, theme, or user) for matching color by name.\n\tif ( namedColor ) {\n\t\tconst colorObject = getColorByProperty( colors, 'slug', namedColor );\n\t\tif ( colorObject ) {\n\t\t\treturn colorObject;\n\t\t}\n\t}\n\n\t// Skip if no custom color or matching named color.\n\tif ( ! customColor ) {\n\t\treturn { color: undefined };\n\t}\n\n\t// Attempt to find color via custom color value or build new object.\n\tconst colorObject = getColorByProperty( colors, 'color', customColor );\n\treturn colorObject ? colorObject : { color: customColor };\n};\n\nfunction getColorSlugFromVariable( value ) {\n\tconst namedColor = /var:preset\\|color\\|(.+)/.exec( value );\n\tif ( namedColor && namedColor[ 1 ] ) {\n\t\treturn namedColor[ 1 ];\n\t}\n\treturn null;\n}\n\nfunction styleToAttributes( style ) {\n\tif ( hasSplitBorders( style?.border ) ) {\n\t\treturn {\n\t\t\tstyle,\n\t\t\tborderColor: undefined,\n\t\t};\n\t}\n\n\tconst borderColorValue = style?.border?.color;\n\tconst borderColorSlug = borderColorValue?.startsWith( 'var:preset|color|' )\n\t\t? borderColorValue.substring( 'var:preset|color|'.length )\n\t\t: undefined;\n\tconst updatedStyle = { ...style };\n\tupdatedStyle.border = {\n\t\t...updatedStyle.border,\n\t\tcolor: borderColorSlug ? undefined : borderColorValue,\n\t};\n\treturn {\n\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\tborderColor: borderColorSlug,\n\t};\n}\n\nfunction attributesToStyle( attributes ) {\n\tif ( hasSplitBorders( attributes.style?.border ) ) {\n\t\treturn attributes.style;\n\t}\n\treturn {\n\t\t...attributes.style,\n\t\tborder: {\n\t\t\t...attributes.style?.border,\n\t\t\tcolor: attributes.borderColor\n\t\t\t\t? 'var:preset|color|' + attributes.borderColor\n\t\t\t\t: attributes.style?.border?.color,\n\t\t},\n\t};\n}\n\nfunction BordersInspectorControl( { label, children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributesToStyle( attributes );\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\t...styleToAttributes( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"border\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t\tlabel={ label }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function BorderPanel( { clientId, name, setAttributes, settings } ) {\n\tconst isEnabled = useHasBorderPanel( settings );\n\tfunction selector( select ) {\n\t\tconst { style, borderColor } =\n\t\t\tselect( blockEditorStore ).getBlockAttributes( clientId ) || {};\n\t\treturn { style, borderColor };\n\t}\n\tconst { style, borderColor } = useSelect( selector, [ clientId ] );\n\tconst value = useMemo( () => {\n\t\treturn attributesToStyle( { style, borderColor } );\n\t}, [ style, borderColor ] );\n\n\tconst onChange = ( newStyle ) => {\n\t\tsetAttributes( styleToAttributes( newStyle ) );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultControls = {\n\t\t...getBlockSupport( name, [\n\t\t\tBORDER_SUPPORT_KEY,\n\t\t\t'__experimentalDefaultControls',\n\t\t] ),\n\t\t...getBlockSupport( name, [\n\t\t\tSHADOW_SUPPORT_KEY,\n\t\t\t'__experimentalDefaultControls',\n\t\t] ),\n\t};\n\n\treturn (\n\t\t<StylesBorderPanel\n\t\t\tas={ BordersInspectorControl }\n\t\t\tpanelId={ clientId }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t/>\n\t);\n}\n\n/**\n * Determine whether there is block support for border properties.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Border feature to check support for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBorderSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BORDER_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (\n\t\t\tsupport?.color ||\n\t\t\tsupport?.radius ||\n\t\t\tsupport?.width ||\n\t\t\tsupport?.style\n\t\t);\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Determine whether there is block support for shadow properties.\n *\n * @param {string} blockName Block name.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasShadowSupport( blockName ) {\n\treturn hasBlockSupport( blockName, SHADOW_SUPPORT_KEY );\n}\n\nexport function useBorderPanelLabel( {\n\tblockName,\n\thasBorderControl,\n\thasShadowControl,\n} = {} ) {\n\tconst settings = useBlockSettings( blockName );\n\tconst controls = useHasBorderPanelControls( settings );\n\n\tif ( ! hasBorderControl && ! hasShadowControl && blockName ) {\n\t\thasBorderControl =\n\t\t\tcontrols?.hasBorderColor ||\n\t\t\tcontrols?.hasBorderStyle ||\n\t\t\tcontrols?.hasBorderWidth ||\n\t\t\tcontrols?.hasBorderRadius;\n\t\thasShadowControl = controls?.hasShadow;\n\t}\n\n\tif ( hasBorderControl && hasShadowControl ) {\n\t\treturn __( 'Border & Shadow' );\n\t}\n\n\tif ( hasShadowControl ) {\n\t\treturn __( 'Shadow' );\n\t}\n\n\treturn __( 'Border' );\n}\n\n/**\n * Returns a new style object where the specified border attribute has been\n * removed.\n *\n * @param {Object} style Styles from block attributes.\n * @param {string} attribute The border style attribute to clear.\n *\n * @return {Object} Style object with the specified attribute removed.\n */\nexport function removeBorderAttribute( style, attribute ) {\n\treturn cleanEmptyObject( {\n\t\t...style,\n\t\tborder: {\n\t\t\t...style?.border,\n\t\t\t[ attribute ]: undefined,\n\t\t},\n\t} );\n}\n\n/**\n * Filters registered block settings, extending attributes to include\n * `borderColor` if needed.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Updated block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBorderSupport( settings, 'color' ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify default value if needed.\n\tif ( settings.attributes.borderColor ) {\n\t\treturn settings;\n\t}\n\n\t// Add new borderColor attribute to block settings.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tborderColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Override props assigned to save component to inject border color.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object|string} blockNameOrType Block type definition.\n * @param {Object} attributes Block's attributes.\n *\n * @return {Object} Filtered props to apply to save element.\n */\nfunction addSaveProps( props, blockNameOrType, attributes ) {\n\tif (\n\t\t! hasBorderSupport( blockNameOrType, 'color' ) ||\n\t\tshouldSkipSerialization( blockNameOrType, BORDER_SUPPORT_KEY, 'color' )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst borderClasses = getBorderClasses( attributes );\n\tconst newClassName = classnames( props.className, borderClasses );\n\n\t// If we are clearing the last of the previous classes in `className`\n\t// set it to `undefined` to avoid rendering empty DOM attributes.\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Generates a CSS class name consisting of all the applicable border color\n * classes given the current block attributes.\n *\n * @param {Object} attributes Block's attributes.\n *\n * @return {string} CSS class name.\n */\nexport function getBorderClasses( attributes ) {\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\treturn classnames( {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\n}\n\nfunction useBlockProps( { name, borderColor, style } ) {\n\tconst { colors } = useMultipleOriginColorsAndGradients();\n\n\tif (\n\t\t! hasBorderSupport( name, 'color' ) ||\n\t\tshouldSkipSerialization( name, BORDER_SUPPORT_KEY, 'color' )\n\t) {\n\t\treturn {};\n\t}\n\n\tconst { color: borderColorValue } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: borderColor,\n\t} );\n\tconst { color: borderTopColor } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: getColorSlugFromVariable( style?.border?.top?.color ),\n\t} );\n\tconst { color: borderRightColor } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: getColorSlugFromVariable( style?.border?.right?.color ),\n\t} );\n\n\tconst { color: borderBottomColor } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: getColorSlugFromVariable( style?.border?.bottom?.color ),\n\t} );\n\tconst { color: borderLeftColor } = getMultiOriginColor( {\n\t\tcolors,\n\t\tnamedColor: getColorSlugFromVariable( style?.border?.left?.color ),\n\t} );\n\n\tconst extraStyles = {\n\t\tborderTopColor: borderTopColor || borderColorValue,\n\t\tborderRightColor: borderRightColor || borderColorValue,\n\t\tborderBottomColor: borderBottomColor || borderColorValue,\n\t\tborderLeftColor: borderLeftColor || borderColorValue,\n\t};\n\n\treturn addSaveProps(\n\t\t{ style: cleanEmptyObject( extraStyles ) || {} },\n\t\tname,\n\t\t{ borderColor, style }\n\t);\n}\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'borderColor', 'style' ],\n\thasSupport( name ) {\n\t\treturn hasBorderSupport( name, 'color' );\n\t},\n};\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addAttributes',\n\taddAttributes\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,eAAe,EAAEC,eAAe,QAAQ,mBAAmB;AACpE,SAASC,6BAA6B,IAAIC,eAAe,QAAQ,uBAAuB;AACxF,SAASC,QAAQ,EAAEC,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;AACnE,SAASC,SA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AAgB;IACtD+D,iBAAiB,EAAEA,iBAAiB,IAAI/D,gBAAgB;IACxDiE,eAAe,EAAEA,eAAe,IAAIjE;EACrC,CAAC;EAED,OAAOkD,YAAY,CAClB;IAAErD,KAAK,EAAE5B,gBAAgB,CAAEkG,WAAY,CAAC,IAAI,CAAC;EAAE,CAAC,EAChDlD,IAAI,EACJ;IAAElB,WAAW;IAAEF;EAAM,CACtB,CAAC;AACF;AAEA,eAAe;EACd6D,aAAa;EACbR,YAAY;EACZkB,aAAa,EAAE,CAAE,aAAa,EAAE,OAAO,CAAE;EACzCC,UAAUA,CAAEpD,IAAI,EAAG;IAClB,OAAOY,gBAAgB,CAAEZ,IAAI,EAAE,OAAQ,CAAC;EACzC;AACD,CAAC;AAEDrD,SAAS,CACR,0BAA0B,EAC1B,2BAA2B,EAC3BoF,aACD,CAAC"}
@@ -1,16 +1,17 @@
1
- import { createElement } from "react";
1
+ import { createElement, Fragment } from "react";
2
2
  /**
3
3
  * WordPress dependencies
4
4
  */
5
- import { getBlockType } from '@wordpress/blocks';
5
+ import { getBlockType, store as blocksStore } from '@wordpress/blocks';
6
6
  import { createHigherOrderComponent } from '@wordpress/compose';
7
7
  import { useSelect } from '@wordpress/data';
8
+ import { useLayoutEffect, useCallback, useState } from '@wordpress/element';
8
9
  import { addFilter } from '@wordpress/hooks';
10
+ import { RichTextData } from '@wordpress/rich-text';
11
+
9
12
  /**
10
13
  * Internal dependencies
11
14
  */
12
- import { store as blockEditorStore } from '../store';
13
- import { useBlockEditContext } from '../components/block-edit/context';
14
15
  import { unlock } from '../lock-unlock';
15
16
 
16
17
  /** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */
@@ -23,70 +24,192 @@ import { unlock } from '../lock-unlock';
23
24
  * @return {WPHigherOrderComponent} Higher-order component.
24
25
  */
25
26
 
26
- export const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
27
+ const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
27
28
  'core/paragraph': ['content'],
28
29
  'core/heading': ['content'],
29
30
  'core/image': ['url', 'title', 'alt'],
30
31
  'core/button': ['url', 'text', 'linkTarget']
31
32
  };
32
- const createEditFunctionWithBindingsAttribute = () => createHigherOrderComponent(BlockEdit => props => {
33
- const {
34
- clientId,
35
- name: blockName
36
- } = useBlockEditContext();
33
+
34
+ /**
35
+ * Based on the given block name,
36
+ * check if it is possible to bind the block.
37
+ *
38
+ * @param {string} blockName - The block name.
39
+ * @return {boolean} Whether it is possible to bind the block to sources.
40
+ */
41
+ export function canBindBlock(blockName) {
42
+ return blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;
43
+ }
44
+
45
+ /**
46
+ * Based on the given block name and attribute name,
47
+ * check if it is possible to bind the block attribute.
48
+ *
49
+ * @param {string} blockName - The block name.
50
+ * @param {string} attributeName - The attribute name.
51
+ * @return {boolean} Whether it is possible to bind the block attribute.
52
+ */
53
+ export function canBindAttribute(blockName, attributeName) {
54
+ return canBindBlock(blockName) && BLOCK_BINDINGS_ALLOWED_BLOCKS[blockName].includes(attributeName);
55
+ }
56
+
57
+ /**
58
+ * This component is responsible for detecting and
59
+ * propagating data changes from the source to the block.
60
+ *
61
+ * @param {Object} props - The component props.
62
+ * @param {string} props.attrName - The attribute name.
63
+ * @param {Object} props.blockProps - The block props with bound attribute.
64
+ * @param {Object} props.source - Source handler.
65
+ * @param {Object} props.args - The arguments to pass to the source.
66
+ * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.
67
+ * @return {null} Data-handling component. Render nothing.
68
+ */
69
+ const BindingConnector = ({
70
+ args,
71
+ attrName,
72
+ blockProps,
73
+ source,
74
+ onPropValueChange
75
+ }) => {
37
76
  const {
38
- getBlockBindingsSource
39
- } = unlock(useSelect(blockEditorStore));
77
+ placeholder,
78
+ value: propValue
79
+ } = source.useSource(blockProps, args);
40
80
  const {
41
- getBlockAttributes
42
- } = useSelect(blockEditorStore);
43
- const updatedAttributes = getBlockAttributes(clientId);
44
- if (updatedAttributes?.metadata?.bindings) {
45
- Object.entries(updatedAttributes.metadata.bindings).forEach(([attributeName, settings]) => {
46
- const source = getBlockBindingsSource(settings.source);
47
- if (source && source.useSource) {
48
- // Second argument (`updateMetaValue`) will be used to update the value in the future.
49
- const {
50
- placeholder,
51
- useValue: [metaValue = null] = []
52
- } = source.useSource(props, settings.args);
53
- if (placeholder && !metaValue) {
54
- // If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url.
55
- // Adding this workaround until attributes and metadata fields types are improved and include `url`.
56
- const htmlAttribute = getBlockType(blockName).attributes[attributeName].attribute;
57
- if (htmlAttribute === 'src' || htmlAttribute === 'href') {
58
- updatedAttributes[attributeName] = null;
59
- } else {
60
- updatedAttributes[attributeName] = placeholder;
61
- }
62
- }
63
- if (metaValue) {
64
- updatedAttributes[attributeName] = metaValue;
65
- }
81
+ name: blockName
82
+ } = blockProps;
83
+ const attrValue = blockProps.attributes[attrName];
84
+ const updateBoundAttibute = useCallback((newAttrValue, prevAttrValue) => {
85
+ /*
86
+ * If the attribute is a RichTextData instance,
87
+ * (core/paragraph, core/heading, core/button, etc.)
88
+ * compare its HTML representation with the new value.
89
+ *
90
+ * To do: it looks like a workaround.
91
+ * Consider improving the attribute and metadata fields types.
92
+ */
93
+ if (prevAttrValue instanceof RichTextData) {
94
+ // Bail early if the Rich Text value is the same.
95
+ if (prevAttrValue.toHTMLString() === newAttrValue) {
96
+ return;
66
97
  }
98
+
99
+ /*
100
+ * To preserve the value type,
101
+ * convert the new value to a RichTextData instance.
102
+ */
103
+ newAttrValue = RichTextData.fromHTMLString(newAttrValue);
104
+ }
105
+ if (prevAttrValue === newAttrValue) {
106
+ return;
107
+ }
108
+ onPropValueChange({
109
+ [attrName]: newAttrValue
67
110
  });
68
- }
69
- return createElement(BlockEdit, {
70
- key: "edit",
111
+ }, [attrName, onPropValueChange]);
112
+ useLayoutEffect(() => {
113
+ if (typeof propValue !== 'undefined') {
114
+ updateBoundAttibute(propValue, attrValue);
115
+ } else if (placeholder) {
116
+ /*
117
+ * Placeholder fallback.
118
+ * If the attribute is `src` or `href`,
119
+ * a placeholder can't be used because it is not a valid url.
120
+ * Adding this workaround until
121
+ * attributes and metadata fields types are improved and include `url`.
122
+ */
123
+ const htmlAttribute = getBlockType(blockName).attributes[attrName].attribute;
124
+ if (htmlAttribute === 'src' || htmlAttribute === 'href') {
125
+ updateBoundAttibute(null);
126
+ return;
127
+ }
128
+ updateBoundAttibute(placeholder);
129
+ }
130
+ }, [updateBoundAttibute, propValue, attrValue, placeholder, blockName, attrName]);
131
+ return null;
132
+ };
133
+
134
+ /**
135
+ * BlockBindingBridge acts like a component wrapper
136
+ * that connects the bound attributes of a block
137
+ * to the source handlers.
138
+ * For this, it creates a BindingConnector for each bound attribute.
139
+ *
140
+ * @param {Object} props - The component props.
141
+ * @param {Object} props.blockProps - The BlockEdit props object.
142
+ * @param {Object} props.bindings - The block bindings settings.
143
+ * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.
144
+ * @return {null} Data-handling component. Render nothing.
145
+ */
146
+ function BlockBindingBridge({
147
+ blockProps,
148
+ bindings,
149
+ onPropValueChange
150
+ }) {
151
+ const blockBindingsSources = unlock(useSelect(blocksStore)).getAllBlockBindingsSources();
152
+ return createElement(Fragment, null, Object.entries(bindings).map(([attrName, boundAttribute]) => {
153
+ // Bail early if the block doesn't have a valid source handler.
154
+ const source = blockBindingsSources[boundAttribute.source];
155
+ if (!source?.useSource) {
156
+ return null;
157
+ }
158
+ return createElement(BindingConnector, {
159
+ key: attrName,
160
+ attrName: attrName,
161
+ source: source,
162
+ blockProps: blockProps,
163
+ args: boundAttribute.args,
164
+ onPropValueChange: onPropValueChange
165
+ });
166
+ }));
167
+ }
168
+ const withBlockBindingSupport = createHigherOrderComponent(BlockEdit => props => {
169
+ /*
170
+ * Collect and update the bound attributes
171
+ * in a separate state.
172
+ */
173
+ const [boundAttributes, setBoundAttributes] = useState({});
174
+ const updateBoundAttributes = useCallback(newAttributes => setBoundAttributes(prev => ({
175
+ ...prev,
176
+ ...newAttributes
177
+ })), []);
178
+
179
+ /*
180
+ * Create binding object filtering
181
+ * only the attributes that can be bound.
182
+ */
183
+ const bindings = Object.fromEntries(Object.entries(props.attributes.metadata?.bindings || {}).filter(([attrName]) => canBindAttribute(props.name, attrName)));
184
+ return createElement(Fragment, null, Object.keys(bindings).length > 0 && createElement(BlockBindingBridge, {
185
+ blockProps: props,
186
+ bindings: bindings,
187
+ onPropValueChange: updateBoundAttributes
188
+ }), createElement(BlockEdit, {
71
189
  ...props,
72
- attributes: updatedAttributes
73
- });
74
- }, 'useBoundAttributes');
190
+ attributes: {
191
+ ...props.attributes,
192
+ ...boundAttributes
193
+ }
194
+ }));
195
+ }, 'withBlockBindingSupport');
75
196
 
76
197
  /**
77
198
  * Filters a registered block's settings to enhance a block's `edit` component
78
199
  * to upgrade bound attributes.
79
200
  *
80
- * @param {WPBlockSettings} settings Registered block settings.
81
- *
201
+ * @param {WPBlockSettings} settings - Registered block settings.
202
+ * @param {string} name - Block name.
82
203
  * @return {WPBlockSettings} Filtered block settings.
83
204
  */
84
- function shimAttributeSource(settings) {
85
- if (!(settings.name in BLOCK_BINDINGS_ALLOWED_BLOCKS)) {
205
+ function shimAttributeSource(settings, name) {
206
+ if (!canBindBlock(name)) {
86
207
  return settings;
87
208
  }
88
- settings.edit = createEditFunctionWithBindingsAttribute()(settings.edit);
89
- return settings;
209
+ return {
210
+ ...settings,
211
+ edit: withBlockBindingSupport(settings.edit)
212
+ };
90
213
  }
91
214
  addFilter('blocks.registerBlockType', 'core/editor/custom-sources-backwards-compatibility/shim-attribute-source', shimAttributeSource);
92
215
  //# sourceMappingURL=use-bindings-attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getBlockType","createHigherOrderComponent","useSelect","addFilter","store","blockEditorStore","useBlockEditContext","unlock","BLOCK_BINDINGS_ALLOWED_BLOCKS","createEditFunctionWithBindingsAttribute","BlockEdit","props","clientId","name","blockName","getBlockBindingsSource","getBlockAttributes","updatedAttributes","metadata","bindings","Object","entries","forEach","attributeName","settings","source","useSource","placeholder","useValue","metaValue","args","htmlAttribute","attributes","attribute","createElement","key","shimAttributeSource","edit"],"sources":["@wordpress/block-editor/src/hooks/use-bindings-attributes.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockType } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { addFilter } from '@wordpress/hooks';\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { useBlockEditContext } from '../components/block-edit/context';\nimport { unlock } from '../lock-unlock';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Given a binding of block attributes, returns a higher order component that\n * overrides its `attributes` and `setAttributes` props to sync any changes needed.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\n\nexport const BLOCK_BINDINGS_ALLOWED_BLOCKS = {\n\t'core/paragraph': [ 'content' ],\n\t'core/heading': [ 'content' ],\n\t'core/image': [ 'url', 'title', 'alt' ],\n\t'core/button': [ 'url', 'text', 'linkTarget' ],\n};\n\nconst createEditFunctionWithBindingsAttribute = () =>\n\tcreateHigherOrderComponent(\n\t\t( BlockEdit ) => ( props ) => {\n\t\t\tconst { clientId, name: blockName } = useBlockEditContext();\n\t\t\tconst { getBlockBindingsSource } = unlock(\n\t\t\t\tuseSelect( blockEditorStore )\n\t\t\t);\n\t\t\tconst { getBlockAttributes } = useSelect( blockEditorStore );\n\n\t\t\tconst updatedAttributes = getBlockAttributes( clientId );\n\t\t\tif ( updatedAttributes?.metadata?.bindings ) {\n\t\t\t\tObject.entries( updatedAttributes.metadata.bindings ).forEach(\n\t\t\t\t\t( [ attributeName, settings ] ) => {\n\t\t\t\t\t\tconst source = getBlockBindingsSource(\n\t\t\t\t\t\t\tsettings.source\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif ( source && source.useSource ) {\n\t\t\t\t\t\t\t// Second argument (`updateMetaValue`) will be used to update the value in the future.\n\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\tplaceholder,\n\t\t\t\t\t\t\t\tuseValue: [ metaValue = null ] = [],\n\t\t\t\t\t\t\t} = source.useSource( props, settings.args );\n\n\t\t\t\t\t\t\tif ( placeholder && ! metaValue ) {\n\t\t\t\t\t\t\t\t// If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url.\n\t\t\t\t\t\t\t\t// Adding this workaround until attributes and metadata fields types are improved and include `url`.\n\t\t\t\t\t\t\t\tconst htmlAttribute =\n\t\t\t\t\t\t\t\t\tgetBlockType( blockName ).attributes[\n\t\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t\t].attribute;\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\thtmlAttribute === 'src' ||\n\t\t\t\t\t\t\t\t\thtmlAttribute === 'href'\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tupdatedAttributes[ attributeName ] = null;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tupdatedAttributes[ attributeName ] =\n\t\t\t\t\t\t\t\t\t\tplaceholder;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif ( metaValue ) {\n\t\t\t\t\t\t\t\tupdatedAttributes[ attributeName ] = metaValue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\t<BlockEdit\n\t\t\t\t\tkey=\"edit\"\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tattributes={ updatedAttributes }\n\t\t\t\t/>\n\t\t\t);\n\t\t},\n\t\t'useBoundAttributes'\n\t);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade bound attributes.\n *\n * @param {WPBlockSettings} settings Registered block settings.\n *\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings ) {\n\tif ( ! ( settings.name in BLOCK_BINDINGS_ALLOWED_BLOCKS ) ) {\n\t\treturn settings;\n\t}\n\tsettings.edit = createEditFunctionWithBindingsAttribute()( settings.edit );\n\n\treturn settings;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,mBAAmB;AAChD,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,SAAS,QAAQ,kBAAkB;AAC5C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,UAAU;AACpD,SAASC,mBAAmB,QAAQ,kCAAkC;AACtE,SAASC,MAAM,QAAQ,gBAAgB;;AAEvC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,6BAA6B,GAAG;EAC5C,gBAAgB,EAAE,CAAE,SAAS,CAAE;EAC/B,cAAc,EAAE,CAAE,SAAS,CAAE;EAC7B,YAAY,EAAE,CAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAE;EACvC,aAAa,EAAE,CAAE,KAAK,EAAE,MAAM,EAAE,YAAY;AAC7C,CAAC;AAED,MAAMC,uCAAuC,GAAGA,CAAA,KAC/CR,0BAA0B,CACvBS,SAAS,IAAQC,KAAK,IAAM;EAC7B,MAAM;IAAEC,QAAQ;IAAEC,IAAI,EAAEC;EAAU,CAAC,GAAGR,mBAAmB,CAAC,CAAC;EAC3D,MAAM;IAAES;EAAuB,CAAC,GAAGR,MAAM,CACxCL,SAAS,CAAEG,gBAAiB,CAC7B,CAAC;EACD,MAAM;IAAEW;EAAmB,CAAC,GAAGd,SAAS,CAAEG,gBAAiB,CAAC;EAE5D,MAAMY,iBAAiB,GAAG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A6B,CAAE,EAAG;IAC3D,OAAOgB,QAAQ;EAChB;EACAA,QAAQ,CAACa,IAAI,GAAG5B,uCAAuC,CAAC,CAAC,CAAEe,QAAQ,CAACa,IAAK,CAAC;EAE1E,OAAOb,QAAQ;AAChB;AAEArB,SAAS,CACR,0BAA0B,EAC1B,0EAA0E,EAC1EiC,mBACD,CAAC"}
1
+ {"version":3,"names":["getBlockType","store","blocksStore","createHigherOrderComponent","useSelect","useLayoutEffect","useCallback","useState","addFilter","RichTextData","unlock","BLOCK_BINDINGS_ALLOWED_BLOCKS","canBindBlock","blockName","canBindAttribute","attributeName","includes","BindingConnector","args","attrName","blockProps","source","onPropValueChange","placeholder","value","propValue","useSource","name","attrValue","attributes","updateBoundAttibute","newAttrValue","prevAttrValue","toHTMLString","fromHTMLString","htmlAttribute","attribute","BlockBindingBridge","bindings","blockBindingsSources","getAllBlockBindingsSources","createElement","Fragment","Object","entries","map","boundAttribute","key","withBlockBindingSupport","BlockEdit","props","boundAttributes","setBoundAttributes","updateBoundAttributes","newAttributes","prev","fromEntries","metadata","filter","keys","length","shimAttributeSource","settings","edit"],"sources":["@wordpress/block-editor/src/hooks/use-bindings-attributes.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockType, store as blocksStore } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useLayoutEffect, useCallback, useState } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport { RichTextData } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Given a binding of block attributes, returns a higher order component that\n * overrides its `attributes` and `setAttributes` props to sync any changes needed.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\n\nconst BLOCK_BINDINGS_ALLOWED_BLOCKS = {\n\t'core/paragraph': [ 'content' ],\n\t'core/heading': [ 'content' ],\n\t'core/image': [ 'url', 'title', 'alt' ],\n\t'core/button': [ 'url', 'text', 'linkTarget' ],\n};\n\n/**\n * Based on the given block name,\n * check if it is possible to bind the block.\n *\n * @param {string} blockName - The block name.\n * @return {boolean} Whether it is possible to bind the block to sources.\n */\nexport function canBindBlock( blockName ) {\n\treturn blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;\n}\n\n/**\n * Based on the given block name and attribute name,\n * check if it is possible to bind the block attribute.\n *\n * @param {string} blockName - The block name.\n * @param {string} attributeName - The attribute name.\n * @return {boolean} Whether it is possible to bind the block attribute.\n */\nexport function canBindAttribute( blockName, attributeName ) {\n\treturn (\n\t\tcanBindBlock( blockName ) &&\n\t\tBLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ].includes( attributeName )\n\t);\n}\n\n/**\n * This component is responsible for detecting and\n * propagating data changes from the source to the block.\n *\n * @param {Object} props - The component props.\n * @param {string} props.attrName - The attribute name.\n * @param {Object} props.blockProps - The block props with bound attribute.\n * @param {Object} props.source - Source handler.\n * @param {Object} props.args - The arguments to pass to the source.\n * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.\n * @return {null} Data-handling component. Render nothing.\n */\nconst BindingConnector = ( {\n\targs,\n\tattrName,\n\tblockProps,\n\tsource,\n\tonPropValueChange,\n} ) => {\n\tconst { placeholder, value: propValue } = source.useSource(\n\t\tblockProps,\n\t\targs\n\t);\n\n\tconst { name: blockName } = blockProps;\n\tconst attrValue = blockProps.attributes[ attrName ];\n\n\tconst updateBoundAttibute = useCallback(\n\t\t( newAttrValue, prevAttrValue ) => {\n\t\t\t/*\n\t\t\t * If the attribute is a RichTextData instance,\n\t\t\t * (core/paragraph, core/heading, core/button, etc.)\n\t\t\t * compare its HTML representation with the new value.\n\t\t\t *\n\t\t\t * To do: it looks like a workaround.\n\t\t\t * Consider improving the attribute and metadata fields types.\n\t\t\t */\n\t\t\tif ( prevAttrValue instanceof RichTextData ) {\n\t\t\t\t// Bail early if the Rich Text value is the same.\n\t\t\t\tif ( prevAttrValue.toHTMLString() === newAttrValue ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t/*\n\t\t\t\t * To preserve the value type,\n\t\t\t\t * convert the new value to a RichTextData instance.\n\t\t\t\t */\n\t\t\t\tnewAttrValue = RichTextData.fromHTMLString( newAttrValue );\n\t\t\t}\n\n\t\t\tif ( prevAttrValue === newAttrValue ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tonPropValueChange( { [ attrName ]: newAttrValue } );\n\t\t},\n\t\t[ attrName, onPropValueChange ]\n\t);\n\n\tuseLayoutEffect( () => {\n\t\tif ( typeof propValue !== 'undefined' ) {\n\t\t\tupdateBoundAttibute( propValue, attrValue );\n\t\t} else if ( placeholder ) {\n\t\t\t/*\n\t\t\t * Placeholder fallback.\n\t\t\t * If the attribute is `src` or `href`,\n\t\t\t * a placeholder can't be used because it is not a valid url.\n\t\t\t * Adding this workaround until\n\t\t\t * attributes and metadata fields types are improved and include `url`.\n\t\t\t */\n\t\t\tconst htmlAttribute =\n\t\t\t\tgetBlockType( blockName ).attributes[ attrName ].attribute;\n\n\t\t\tif ( htmlAttribute === 'src' || htmlAttribute === 'href' ) {\n\t\t\t\tupdateBoundAttibute( null );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tupdateBoundAttibute( placeholder );\n\t\t}\n\t}, [\n\t\tupdateBoundAttibute,\n\t\tpropValue,\n\t\tattrValue,\n\t\tplaceholder,\n\t\tblockName,\n\t\tattrName,\n\t] );\n\n\treturn null;\n};\n\n/**\n * BlockBindingBridge acts like a component wrapper\n * that connects the bound attributes of a block\n * to the source handlers.\n * For this, it creates a BindingConnector for each bound attribute.\n *\n * @param {Object} props - The component props.\n * @param {Object} props.blockProps - The BlockEdit props object.\n * @param {Object} props.bindings - The block bindings settings.\n * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.\n * @return {null} Data-handling component. Render nothing.\n */\nfunction BlockBindingBridge( { blockProps, bindings, onPropValueChange } ) {\n\tconst blockBindingsSources = unlock(\n\t\tuseSelect( blocksStore )\n\t).getAllBlockBindingsSources();\n\n\treturn (\n\t\t<>\n\t\t\t{ Object.entries( bindings ).map(\n\t\t\t\t( [ attrName, boundAttribute ] ) => {\n\t\t\t\t\t// Bail early if the block doesn't have a valid source handler.\n\t\t\t\t\tconst source =\n\t\t\t\t\t\tblockBindingsSources[ boundAttribute.source ];\n\t\t\t\t\tif ( ! source?.useSource ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<BindingConnector\n\t\t\t\t\t\t\tkey={ attrName }\n\t\t\t\t\t\t\tattrName={ attrName }\n\t\t\t\t\t\t\tsource={ source }\n\t\t\t\t\t\t\tblockProps={ blockProps }\n\t\t\t\t\t\t\targs={ boundAttribute.args }\n\t\t\t\t\t\t\tonPropValueChange={ onPropValueChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nconst withBlockBindingSupport = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\t/*\n\t\t * Collect and update the bound attributes\n\t\t * in a separate state.\n\t\t */\n\t\tconst [ boundAttributes, setBoundAttributes ] = useState( {} );\n\t\tconst updateBoundAttributes = useCallback(\n\t\t\t( newAttributes ) =>\n\t\t\t\tsetBoundAttributes( ( prev ) => ( {\n\t\t\t\t\t...prev,\n\t\t\t\t\t...newAttributes,\n\t\t\t\t} ) ),\n\t\t\t[]\n\t\t);\n\n\t\t/*\n\t\t * Create binding object filtering\n\t\t * only the attributes that can be bound.\n\t\t */\n\t\tconst bindings = Object.fromEntries(\n\t\t\tObject.entries( props.attributes.metadata?.bindings || {} ).filter(\n\t\t\t\t( [ attrName ] ) => canBindAttribute( props.name, attrName )\n\t\t\t)\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ Object.keys( bindings ).length > 0 && (\n\t\t\t\t\t<BlockBindingBridge\n\t\t\t\t\t\tblockProps={ props }\n\t\t\t\t\t\tbindings={ bindings }\n\t\t\t\t\t\tonPropValueChange={ updateBoundAttributes }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\n\t\t\t\t<BlockEdit\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tattributes={ { ...props.attributes, ...boundAttributes } }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n\t'withBlockBindingSupport'\n);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade bound attributes.\n *\n * @param {WPBlockSettings} settings - Registered block settings.\n * @param {string} name - Block name.\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings, name ) {\n\tif ( ! canBindBlock( name ) ) {\n\t\treturn settings;\n\t}\n\n\treturn {\n\t\t...settings,\n\t\tedit: withBlockBindingSupport( settings.edit ),\n\t};\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACtE,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,eAAe,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC3E,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,YAAY,QAAQ,sBAAsB;;AAEnD;AACA;AACA;AACA,SAASC,MAAM,QAAQ,gBAAgB;;AAEvC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,6BAA6B,GAAG;EACrC,gBAAgB,EAAE,CAAE,SAAS,CAAE;EAC/B,cAAc,EAAE,CAAE,SAAS,CAAE;EAC7B,YAAY,EAAE,CAAE,KAAK,EAAE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