@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
@@ -1,15 +1,16 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { getBlockType } from '@wordpress/blocks';
4
+ import { getBlockType, store as blocksStore } from '@wordpress/blocks';
5
5
  import { createHigherOrderComponent } from '@wordpress/compose';
6
6
  import { useSelect } from '@wordpress/data';
7
+ import { useLayoutEffect, useCallback, useState } from '@wordpress/element';
7
8
  import { addFilter } from '@wordpress/hooks';
9
+ import { RichTextData } from '@wordpress/rich-text';
10
+
8
11
  /**
9
12
  * Internal dependencies
10
13
  */
11
- import { store as blockEditorStore } from '../store';
12
- import { useBlockEditContext } from '../components/block-edit/context';
13
14
  import { unlock } from '../lock-unlock';
14
15
 
15
16
  /** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */
@@ -22,89 +23,238 @@ import { unlock } from '../lock-unlock';
22
23
  * @return {WPHigherOrderComponent} Higher-order component.
23
24
  */
24
25
 
25
- export const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
26
+ const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
26
27
  'core/paragraph': [ 'content' ],
27
28
  'core/heading': [ 'content' ],
28
29
  'core/image': [ 'url', 'title', 'alt' ],
29
30
  'core/button': [ 'url', 'text', 'linkTarget' ],
30
31
  };
31
32
 
32
- const createEditFunctionWithBindingsAttribute = () =>
33
- createHigherOrderComponent(
34
- ( BlockEdit ) => ( props ) => {
35
- const { clientId, name: blockName } = useBlockEditContext();
36
- const { getBlockBindingsSource } = unlock(
37
- useSelect( blockEditorStore )
38
- );
39
- const { getBlockAttributes } = useSelect( blockEditorStore );
40
-
41
- const updatedAttributes = getBlockAttributes( clientId );
42
- if ( updatedAttributes?.metadata?.bindings ) {
43
- Object.entries( updatedAttributes.metadata.bindings ).forEach(
44
- ( [ attributeName, settings ] ) => {
45
- const source = getBlockBindingsSource(
46
- settings.source
47
- );
48
-
49
- if ( source && source.useSource ) {
50
- // Second argument (`updateMetaValue`) will be used to update the value in the future.
51
- const {
52
- placeholder,
53
- useValue: [ metaValue = null ] = [],
54
- } = source.useSource( props, settings.args );
55
-
56
- if ( placeholder && ! metaValue ) {
57
- // If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url.
58
- // Adding this workaround until attributes and metadata fields types are improved and include `url`.
59
- const htmlAttribute =
60
- getBlockType( blockName ).attributes[
61
- attributeName
62
- ].attribute;
63
- if (
64
- htmlAttribute === 'src' ||
65
- htmlAttribute === 'href'
66
- ) {
67
- updatedAttributes[ attributeName ] = null;
68
- } else {
69
- updatedAttributes[ attributeName ] =
70
- placeholder;
71
- }
72
- }
73
-
74
- if ( metaValue ) {
75
- updatedAttributes[ attributeName ] = metaValue;
76
- }
77
- }
78
- }
79
- );
33
+ /**
34
+ * Based on the given block name,
35
+ * check if it is possible to bind the block.
36
+ *
37
+ * @param {string} blockName - The block name.
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,
46
+ * check if it is possible to bind the block attribute.
47
+ *
48
+ * @param {string} blockName - The block name.
49
+ * @param {string} attributeName - The attribute name.
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
+ * This component is responsible for detecting and
61
+ * propagating data changes from the source to the block.
62
+ *
63
+ * @param {Object} props - The component props.
64
+ * @param {string} props.attrName - The attribute name.
65
+ * @param {Object} props.blockProps - The block props with bound attribute.
66
+ * @param {Object} props.source - Source handler.
67
+ * @param {Object} props.args - The arguments to pass to the source.
68
+ * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.
69
+ * @return {null} Data-handling component. Render nothing.
70
+ */
71
+ const BindingConnector = ( {
72
+ args,
73
+ attrName,
74
+ blockProps,
75
+ source,
76
+ onPropValueChange,
77
+ } ) => {
78
+ const { placeholder, value: propValue } = source.useSource(
79
+ blockProps,
80
+ args
81
+ );
82
+
83
+ const { name: blockName } = blockProps;
84
+ const attrValue = blockProps.attributes[ attrName ];
85
+
86
+ const updateBoundAttibute = useCallback(
87
+ ( newAttrValue, prevAttrValue ) => {
88
+ /*
89
+ * If the attribute is a RichTextData instance,
90
+ * (core/paragraph, core/heading, core/button, etc.)
91
+ * compare its HTML representation with the new value.
92
+ *
93
+ * To do: it looks like a workaround.
94
+ * Consider improving the attribute and metadata fields types.
95
+ */
96
+ if ( prevAttrValue instanceof RichTextData ) {
97
+ // Bail early if the Rich Text value is the same.
98
+ if ( prevAttrValue.toHTMLString() === newAttrValue ) {
99
+ return;
100
+ }
101
+
102
+ /*
103
+ * To preserve the value type,
104
+ * convert the new value to a RichTextData instance.
105
+ */
106
+ newAttrValue = RichTextData.fromHTMLString( newAttrValue );
107
+ }
108
+
109
+ if ( prevAttrValue === newAttrValue ) {
110
+ return;
80
111
  }
81
112
 
82
- return (
113
+ onPropValueChange( { [ attrName ]: newAttrValue } );
114
+ },
115
+ [ attrName, onPropValueChange ]
116
+ );
117
+
118
+ useLayoutEffect( () => {
119
+ if ( typeof propValue !== 'undefined' ) {
120
+ updateBoundAttibute( propValue, attrValue );
121
+ } else if ( placeholder ) {
122
+ /*
123
+ * Placeholder fallback.
124
+ * If the attribute is `src` or `href`,
125
+ * a placeholder can't be used because it is not a valid url.
126
+ * Adding this workaround until
127
+ * attributes and metadata fields types are improved and include `url`.
128
+ */
129
+ const htmlAttribute =
130
+ getBlockType( blockName ).attributes[ attrName ].attribute;
131
+
132
+ if ( htmlAttribute === 'src' || htmlAttribute === 'href' ) {
133
+ updateBoundAttibute( null );
134
+ return;
135
+ }
136
+
137
+ updateBoundAttibute( placeholder );
138
+ }
139
+ }, [
140
+ updateBoundAttibute,
141
+ propValue,
142
+ attrValue,
143
+ placeholder,
144
+ blockName,
145
+ attrName,
146
+ ] );
147
+
148
+ return null;
149
+ };
150
+
151
+ /**
152
+ * BlockBindingBridge acts like a component wrapper
153
+ * that connects the bound attributes of a block
154
+ * to the source handlers.
155
+ * For this, it creates a BindingConnector for each bound attribute.
156
+ *
157
+ * @param {Object} props - The component props.
158
+ * @param {Object} props.blockProps - The BlockEdit props object.
159
+ * @param {Object} props.bindings - The block bindings settings.
160
+ * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.
161
+ * @return {null} Data-handling component. Render nothing.
162
+ */
163
+ function BlockBindingBridge( { blockProps, bindings, onPropValueChange } ) {
164
+ const blockBindingsSources = unlock(
165
+ useSelect( blocksStore )
166
+ ).getAllBlockBindingsSources();
167
+
168
+ return (
169
+ <>
170
+ { Object.entries( bindings ).map(
171
+ ( [ attrName, boundAttribute ] ) => {
172
+ // Bail early if the block doesn't have a valid source handler.
173
+ const source =
174
+ blockBindingsSources[ boundAttribute.source ];
175
+ if ( ! source?.useSource ) {
176
+ return null;
177
+ }
178
+
179
+ return (
180
+ <BindingConnector
181
+ key={ attrName }
182
+ attrName={ attrName }
183
+ source={ source }
184
+ blockProps={ blockProps }
185
+ args={ boundAttribute.args }
186
+ onPropValueChange={ onPropValueChange }
187
+ />
188
+ );
189
+ }
190
+ ) }
191
+ </>
192
+ );
193
+ }
194
+
195
+ const withBlockBindingSupport = createHigherOrderComponent(
196
+ ( BlockEdit ) => ( props ) => {
197
+ /*
198
+ * Collect and update the bound attributes
199
+ * in a separate state.
200
+ */
201
+ const [ boundAttributes, setBoundAttributes ] = useState( {} );
202
+ const updateBoundAttributes = useCallback(
203
+ ( newAttributes ) =>
204
+ setBoundAttributes( ( prev ) => ( {
205
+ ...prev,
206
+ ...newAttributes,
207
+ } ) ),
208
+ []
209
+ );
210
+
211
+ /*
212
+ * Create binding object filtering
213
+ * only the attributes that can be bound.
214
+ */
215
+ const bindings = Object.fromEntries(
216
+ Object.entries( props.attributes.metadata?.bindings || {} ).filter(
217
+ ( [ attrName ] ) => canBindAttribute( props.name, attrName )
218
+ )
219
+ );
220
+
221
+ return (
222
+ <>
223
+ { Object.keys( bindings ).length > 0 && (
224
+ <BlockBindingBridge
225
+ blockProps={ props }
226
+ bindings={ bindings }
227
+ onPropValueChange={ updateBoundAttributes }
228
+ />
229
+ ) }
230
+
83
231
  <BlockEdit
84
- key="edit"
85
232
  { ...props }
86
- attributes={ updatedAttributes }
233
+ attributes={ { ...props.attributes, ...boundAttributes } }
87
234
  />
88
- );
89
- },
90
- 'useBoundAttributes'
91
- );
235
+ </>
236
+ );
237
+ },
238
+ 'withBlockBindingSupport'
239
+ );
92
240
 
93
241
  /**
94
242
  * Filters a registered block's settings to enhance a block's `edit` component
95
243
  * to upgrade bound attributes.
96
244
  *
97
- * @param {WPBlockSettings} settings Registered block settings.
98
- *
245
+ * @param {WPBlockSettings} settings - Registered block settings.
246
+ * @param {string} name - Block name.
99
247
  * @return {WPBlockSettings} Filtered block settings.
100
248
  */
101
- function shimAttributeSource( settings ) {
102
- if ( ! ( settings.name in BLOCK_BINDINGS_ALLOWED_BLOCKS ) ) {
249
+ function shimAttributeSource( settings, name ) {
250
+ if ( ! canBindBlock( name ) ) {
103
251
  return settings;
104
252
  }
105
- settings.edit = createEditFunctionWithBindingsAttribute()( settings.edit );
106
253
 
107
- return settings;
254
+ return {
255
+ ...settings,
256
+ edit: withBlockBindingSupport( settings.edit ),
257
+ };
108
258
  }
109
259
 
110
260
  addFilter(
@@ -27,6 +27,8 @@ import { ExperimentalBlockCanvas } from './components/block-canvas';
27
27
  import { getDuotoneFilter } from './components/duotone/utils';
28
28
  import { useFlashEditableBlocks } from './components/use-flash-editable-blocks';
29
29
  import { selectBlockPatternsKey } from './store/private-keys';
30
+ import { requiresWrapperOnCopy } from './components/writing-flow/utils';
31
+ import { PrivateRichText } from './components/rich-text/';
30
32
 
31
33
  /**
32
34
  * Private @wordpress/block-editor APIs.
@@ -58,4 +60,6 @@ lock( privateApis, {
58
60
  usesContextKey,
59
61
  useFlashEditableBlocks,
60
62
  selectBlockPatternsKey,
63
+ requiresWrapperOnCopy,
64
+ PrivateRichText,
61
65
  } );
@@ -1575,7 +1575,7 @@ export const duplicateBlocks =
1575
1575
  };
1576
1576
 
1577
1577
  /**
1578
- * Action that inserts an empty block before a given block.
1578
+ * Action that inserts a default block before a given block.
1579
1579
  *
1580
1580
  * @param {string} clientId
1581
1581
  */
@@ -1591,16 +1591,34 @@ export const insertBeforeBlock =
1591
1591
  return;
1592
1592
  }
1593
1593
 
1594
- const firstSelectedIndex = select.getBlockIndex( clientId );
1595
- return dispatch.insertDefaultBlock(
1596
- {},
1597
- rootClientId,
1598
- firstSelectedIndex
1599
- );
1594
+ const blockIndex = select.getBlockIndex( clientId );
1595
+ const directInsertBlock = rootClientId
1596
+ ? select.getDirectInsertBlock( rootClientId )
1597
+ : null;
1598
+
1599
+ if ( ! directInsertBlock ) {
1600
+ return dispatch.insertDefaultBlock( {}, rootClientId, blockIndex );
1601
+ }
1602
+
1603
+ const copiedAttributes = {};
1604
+ if ( directInsertBlock.attributesToCopy ) {
1605
+ const attributes = select.getBlockAttributes( clientId );
1606
+ directInsertBlock.attributesToCopy.forEach( ( key ) => {
1607
+ if ( attributes[ key ] ) {
1608
+ copiedAttributes[ key ] = attributes[ key ];
1609
+ }
1610
+ } );
1611
+ }
1612
+
1613
+ const block = createBlock( directInsertBlock.name, {
1614
+ ...directInsertBlock.attributes,
1615
+ ...copiedAttributes,
1616
+ } );
1617
+ return dispatch.insertBlock( block, blockIndex, rootClientId );
1600
1618
  };
1601
1619
 
1602
1620
  /**
1603
- * Action that inserts an empty block after a given block.
1621
+ * Action that inserts a default block after a given block.
1604
1622
  *
1605
1623
  * @param {string} clientId
1606
1624
  */
@@ -1616,12 +1634,34 @@ export const insertAfterBlock =
1616
1634
  return;
1617
1635
  }
1618
1636
 
1619
- const firstSelectedIndex = select.getBlockIndex( clientId );
1620
- return dispatch.insertDefaultBlock(
1621
- {},
1622
- rootClientId,
1623
- firstSelectedIndex + 1
1624
- );
1637
+ const blockIndex = select.getBlockIndex( clientId );
1638
+ const directInsertBlock = rootClientId
1639
+ ? select.getDirectInsertBlock( rootClientId )
1640
+ : null;
1641
+
1642
+ if ( ! directInsertBlock ) {
1643
+ return dispatch.insertDefaultBlock(
1644
+ {},
1645
+ rootClientId,
1646
+ blockIndex + 1
1647
+ );
1648
+ }
1649
+
1650
+ const copiedAttributes = {};
1651
+ if ( directInsertBlock.attributesToCopy ) {
1652
+ const attributes = select.getBlockAttributes( clientId );
1653
+ directInsertBlock.attributesToCopy.forEach( ( key ) => {
1654
+ if ( attributes[ key ] ) {
1655
+ copiedAttributes[ key ] = attributes[ key ];
1656
+ }
1657
+ } );
1658
+ }
1659
+
1660
+ const block = createBlock( directInsertBlock.name, {
1661
+ ...directInsertBlock.attributes,
1662
+ ...copiedAttributes,
1663
+ } );
1664
+ return dispatch.insertBlock( block, blockIndex + 1, rootClientId );
1625
1665
  };
1626
1666
 
1627
1667
  /**
@@ -390,16 +390,6 @@ export function stopEditingAsBlocks( clientId ) {
390
390
  };
391
391
  }
392
392
 
393
- export function registerBlockBindingsSource( source ) {
394
- return {
395
- type: 'REGISTER_BLOCK_BINDINGS_SOURCE',
396
- sourceName: source.name,
397
- sourceLabel: source.label,
398
- useSource: source.useSource,
399
- lockAttributesEditing: source.lockAttributesEditing,
400
- };
401
- }
402
-
403
393
  /**
404
394
  * Returns an action object used in signalling that the user has begun to drag.
405
395
  *
@@ -341,14 +341,6 @@ export function getLastFocus( state ) {
341
341
  return state.lastFocus;
342
342
  }
343
343
 
344
- export function getAllBlockBindingsSources( state ) {
345
- return state.blockBindingsSources;
346
- }
347
-
348
- export function getBlockBindingsSource( state, sourceName ) {
349
- return state.blockBindingsSources[ sourceName ];
350
- }
351
-
352
344
  /**
353
345
  * Returns true if the user is dragging anything, or false otherwise. It is possible for a
354
346
  * user to be dragging data from outside of the editor, so this selector is separate from
@@ -2050,20 +2050,6 @@ export function lastFocus( state = false, action ) {
2050
2050
  return state;
2051
2051
  }
2052
2052
 
2053
- function blockBindingsSources( state = {}, action ) {
2054
- if ( action.type === 'REGISTER_BLOCK_BINDINGS_SOURCE' ) {
2055
- return {
2056
- ...state,
2057
- [ action.sourceName ]: {
2058
- label: action.sourceLabel,
2059
- useSource: action.useSource,
2060
- lockAttributesEditing: action.lockAttributesEditing ?? true,
2061
- },
2062
- };
2063
- }
2064
- return state;
2065
- }
2066
-
2067
2053
  const combinedReducers = combineReducers( {
2068
2054
  blocks,
2069
2055
  isDragging,
@@ -2095,7 +2081,6 @@ const combinedReducers = combineReducers( {
2095
2081
  blockRemovalRules,
2096
2082
  openedBlockSettingsMenu,
2097
2083
  registeredInserterMediaCategories,
2098
- blockBindingsSources,
2099
2084
  } );
2100
2085
 
2101
2086
  function withAutomaticChangeReset( reducer ) {
package/src/style.scss CHANGED
@@ -1,5 +1,6 @@
1
1
  @import "./autocompleters/style.scss";
2
2
  @import "./components/block-alignment-control/style.scss";
3
+ @import "./components/block-bindings-toolbar-indicator/style.scss";
3
4
  @import "./components/block-canvas/style.scss";
4
5
  @import "./components/block-icon/style.scss";
5
6
  @import "./components/block-inspector/style.scss";