@wordpress/block-editor 12.3.6 → 12.3.8

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 (143) hide show
  1. package/README.md +0 -4
  2. package/build/components/block-draggable/index.js +6 -3
  3. package/build/components/block-draggable/index.js.map +1 -1
  4. package/build/components/block-removal-warning-modal/index.js +15 -25
  5. package/build/components/block-removal-warning-modal/index.js.map +1 -1
  6. package/build/components/colors-gradients/control.js +4 -2
  7. package/build/components/colors-gradients/control.js.map +1 -1
  8. package/build/components/global-styles/dimensions-panel.js +13 -2
  9. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  10. package/build/components/iframe/index.js +16 -3
  11. package/build/components/iframe/index.js.map +1 -1
  12. package/build/components/iframe/use-compatibility-styles.js +5 -0
  13. package/build/components/iframe/use-compatibility-styles.js.map +1 -1
  14. package/build/components/index.js +1 -10
  15. package/build/components/index.js.map +1 -1
  16. package/build/components/inserter/reusable-block-rename-hint.js +23 -3
  17. package/build/components/inserter/reusable-block-rename-hint.js.map +1 -1
  18. package/build/components/link-control/constants.js +1 -1
  19. package/build/components/link-control/constants.js.map +1 -1
  20. package/build/components/link-control/search-create-button.js +5 -21
  21. package/build/components/link-control/search-create-button.js.map +1 -1
  22. package/build/components/link-control/search-item.js +13 -30
  23. package/build/components/link-control/search-item.js.map +1 -1
  24. package/build/components/link-control/search-results.js +2 -2
  25. package/build/components/link-control/search-results.js.map +1 -1
  26. package/build/components/rich-text/get-rich-text-values.js +7 -1
  27. package/build/components/rich-text/get-rich-text-values.js.map +1 -1
  28. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
  29. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  30. package/build/components/spacing-sizes-control/input-controls/axial.js +6 -2
  31. package/build/components/spacing-sizes-control/input-controls/axial.js.map +1 -1
  32. package/build/components/spacing-sizes-control/input-controls/separated.js +5 -1
  33. package/build/components/spacing-sizes-control/input-controls/separated.js.map +1 -1
  34. package/build/components/spacing-sizes-control/input-controls/single.js +5 -1
  35. package/build/components/spacing-sizes-control/input-controls/single.js.map +1 -1
  36. package/build/components/spacing-sizes-control/utils.js +1 -1
  37. package/build/components/spacing-sizes-control/utils.js.map +1 -1
  38. package/build/components/use-block-display-information/index.js +7 -3
  39. package/build/components/use-block-display-information/index.js.map +1 -1
  40. package/build/hooks/margin.js +1 -1
  41. package/build/hooks/margin.js.map +1 -1
  42. package/build/hooks/padding.js +1 -1
  43. package/build/hooks/padding.js.map +1 -1
  44. package/build/private-apis.js +5 -1
  45. package/build/private-apis.js.map +1 -1
  46. package/build/store/index.js +10 -1
  47. package/build/store/index.js.map +1 -1
  48. package/build/store/private-actions.js +36 -36
  49. package/build/store/private-actions.js.map +1 -1
  50. package/build/store/private-selectors.js +3 -3
  51. package/build/store/private-selectors.js.map +1 -1
  52. package/build/store/reducer.js +16 -8
  53. package/build/store/reducer.js.map +1 -1
  54. package/build/store/selectors.js +1 -1
  55. package/build/store/selectors.js.map +1 -1
  56. package/build-module/components/block-draggable/index.js +6 -3
  57. package/build-module/components/block-draggable/index.js.map +1 -1
  58. package/build-module/components/block-removal-warning-modal/index.js +16 -23
  59. package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
  60. package/build-module/components/colors-gradients/control.js +3 -2
  61. package/build-module/components/colors-gradients/control.js.map +1 -1
  62. package/build-module/components/global-styles/dimensions-panel.js +13 -2
  63. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  64. package/build-module/components/iframe/index.js +16 -3
  65. package/build-module/components/iframe/index.js.map +1 -1
  66. package/build-module/components/iframe/use-compatibility-styles.js +5 -0
  67. package/build-module/components/iframe/use-compatibility-styles.js.map +1 -1
  68. package/build-module/components/index.js +0 -5
  69. package/build-module/components/index.js.map +1 -1
  70. package/build-module/components/inserter/reusable-block-rename-hint.js +22 -3
  71. package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -1
  72. package/build-module/components/link-control/constants.js +1 -1
  73. package/build-module/components/link-control/constants.js.map +1 -1
  74. package/build-module/components/link-control/search-create-button.js +7 -20
  75. package/build-module/components/link-control/search-create-button.js.map +1 -1
  76. package/build-module/components/link-control/search-item.js +14 -28
  77. package/build-module/components/link-control/search-item.js.map +1 -1
  78. package/build-module/components/link-control/search-results.js +3 -3
  79. package/build-module/components/link-control/search-results.js.map +1 -1
  80. package/build-module/components/rich-text/get-rich-text-values.js +7 -1
  81. package/build-module/components/rich-text/get-rich-text-values.js.map +1 -1
  82. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
  83. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  84. package/build-module/components/spacing-sizes-control/input-controls/axial.js +7 -3
  85. package/build-module/components/spacing-sizes-control/input-controls/axial.js.map +1 -1
  86. package/build-module/components/spacing-sizes-control/input-controls/separated.js +6 -2
  87. package/build-module/components/spacing-sizes-control/input-controls/separated.js.map +1 -1
  88. package/build-module/components/spacing-sizes-control/input-controls/single.js +6 -2
  89. package/build-module/components/spacing-sizes-control/input-controls/single.js.map +1 -1
  90. package/build-module/components/spacing-sizes-control/utils.js +1 -1
  91. package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
  92. package/build-module/components/use-block-display-information/index.js +7 -3
  93. package/build-module/components/use-block-display-information/index.js.map +1 -1
  94. package/build-module/hooks/margin.js +1 -1
  95. package/build-module/hooks/margin.js.map +1 -1
  96. package/build-module/hooks/padding.js +1 -1
  97. package/build-module/hooks/padding.js.map +1 -1
  98. package/build-module/private-apis.js +4 -1
  99. package/build-module/private-apis.js.map +1 -1
  100. package/build-module/store/index.js +10 -1
  101. package/build-module/store/index.js.map +1 -1
  102. package/build-module/store/private-actions.js +35 -32
  103. package/build-module/store/private-actions.js.map +1 -1
  104. package/build-module/store/private-selectors.js +2 -2
  105. package/build-module/store/private-selectors.js.map +1 -1
  106. package/build-module/store/reducer.js +16 -8
  107. package/build-module/store/reducer.js.map +1 -1
  108. package/build-module/store/selectors.js +1 -1
  109. package/build-module/store/selectors.js.map +1 -1
  110. package/build-style/style-rtl.css +20 -83
  111. package/build-style/style.css +20 -83
  112. package/package.json +10 -10
  113. package/src/components/block-draggable/index.js +13 -4
  114. package/src/components/block-removal-warning-modal/index.js +13 -27
  115. package/src/components/colors-gradients/control.js +3 -2
  116. package/src/components/global-styles/dimensions-panel.js +8 -2
  117. package/src/components/iframe/index.js +15 -10
  118. package/src/components/iframe/use-compatibility-styles.js +5 -0
  119. package/src/components/index.js +0 -5
  120. package/src/components/inserter/reusable-block-rename-hint.js +18 -1
  121. package/src/components/link-control/constants.js +1 -1
  122. package/src/components/link-control/search-create-button.js +8 -26
  123. package/src/components/link-control/search-item.js +21 -43
  124. package/src/components/link-control/search-results.js +48 -46
  125. package/src/components/link-control/style.scss +25 -95
  126. package/src/components/link-control/test/index.js +6 -7
  127. package/src/components/rich-text/get-rich-text-values.js +11 -1
  128. package/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
  129. package/src/components/spacing-sizes-control/input-controls/axial.js +17 -2
  130. package/src/components/spacing-sizes-control/input-controls/separated.js +17 -2
  131. package/src/components/spacing-sizes-control/input-controls/single.js +12 -2
  132. package/src/components/spacing-sizes-control/utils.js +1 -1
  133. package/src/components/use-block-display-information/index.js +12 -5
  134. package/src/hooks/margin.js +4 -1
  135. package/src/hooks/padding.js +4 -1
  136. package/src/private-apis.js +6 -0
  137. package/src/store/index.js +10 -0
  138. package/src/store/private-actions.js +33 -36
  139. package/src/store/private-selectors.js +2 -2
  140. package/src/store/reducer.js +16 -8
  141. package/src/store/selectors.js +1 -1
  142. package/src/store/test/actions.js +3 -0
  143. package/src/store/test/selectors.js +1 -1
@@ -18,6 +18,10 @@ import { BlockRemovalWarningModal } from './components/block-removal-warning-mod
18
18
  import { useLayoutClasses, useLayoutStyles } from './hooks';
19
19
  import DimensionsTool from './components/dimensions-tool';
20
20
  import ResolutionTool from './components/resolution-tool';
21
+ import {
22
+ default as ReusableBlocksRenameHint,
23
+ useReusableBlocksRenameHint,
24
+ } from './components/inserter/reusable-block-rename-hint';
21
25
 
22
26
  /**
23
27
  * Private @wordpress/block-editor APIs.
@@ -41,4 +45,6 @@ lock( privateApis, {
41
45
  useLayoutStyles,
42
46
  DimensionsTool,
43
47
  ResolutionTool,
48
+ ReusableBlocksRenameHint,
49
+ useReusableBlocksRenameHint,
44
50
  } );
@@ -43,3 +43,13 @@ const registeredStore = registerStore( STORE_NAME, {
43
43
  } );
44
44
  unlock( registeredStore ).registerPrivateActions( privateActions );
45
45
  unlock( registeredStore ).registerPrivateSelectors( privateSelectors );
46
+
47
+ // TODO: Remove once we switch to the `register` function (see above).
48
+ //
49
+ // Until then, private functions also need to be attached to the original
50
+ // `store` descriptor in order to avoid unit tests failing, which could happen
51
+ // when tests create new registries in which they register stores.
52
+ //
53
+ // @see https://github.com/WordPress/gutenberg/pull/51145#discussion_r1239999590
54
+ unlock( store ).registerPrivateActions( privateActions );
55
+ unlock( store ).registerPrivateSelectors( privateSelectors );
@@ -3,11 +3,6 @@
3
3
  */
4
4
  import { Platform } from '@wordpress/element';
5
5
 
6
- /**
7
- * Internal dependencies
8
- */
9
- import { blockTypePromptMessages } from '../components/block-removal-warning-modal';
10
-
11
6
  const castArray = ( maybeArray ) =>
12
7
  Array.isArray( maybeArray ) ? maybeArray : [ maybeArray ];
13
8
 
@@ -155,35 +150,22 @@ export const privateRemoveBlocks =
155
150
  // confirmation that they intended to remove such block(s). However,
156
151
  // the editor instance is responsible for presenting those confirmation
157
152
  // prompts to the user. Any instance opting into removal prompts must
158
- // register using `toggleRemovalPromptSupport()`.
153
+ // register using `setBlockRemovalRules()`.
159
154
  //
160
155
  // @see https://github.com/WordPress/gutenberg/pull/51145
161
- if (
162
- ! forceRemove &&
163
- // FIXME: Without this existence check, the unit tests for
164
- // `__experimentalDeleteReusableBlock` in
165
- // `packages/reusable-blocks/src/store/test/actions.js` fail due to
166
- // the fact that the `registry` object passed to the thunk actions
167
- // doesn't include this private action. This needs to be
168
- // investigated to understand whether it's a real smell or if it's
169
- // because not all store code has been updated to accommodate
170
- // private selectors.
171
- select.isRemovalPromptSupported &&
172
- select.isRemovalPromptSupported()
173
- ) {
156
+ const rules = ! forceRemove && select.getBlockRemovalRules();
157
+ if ( rules ) {
174
158
  const blockNamesForPrompt = new Set();
175
159
 
176
160
  // Given a list of client IDs of blocks that the user intended to
177
161
  // remove, perform a tree search (BFS) to find all block names
178
162
  // corresponding to "important" blocks, i.e. blocks that require a
179
163
  // removal prompt.
180
- //
181
- // @see blockTypePromptMessages
182
164
  const queue = [ ...clientIds ];
183
165
  while ( queue.length ) {
184
166
  const clientId = queue.shift();
185
167
  const blockName = select.getBlockName( clientId );
186
- if ( blockTypePromptMessages[ blockName ] ) {
168
+ if ( rules[ blockName ] ) {
187
169
  blockNamesForPrompt.add( blockName );
188
170
  }
189
171
  const innerBlocks = select.getBlockOrder( clientId );
@@ -194,7 +176,7 @@ export const privateRemoveBlocks =
194
176
  // skip any other steps (thus postponing actual removal).
195
177
  if ( blockNamesForPrompt.size ) {
196
178
  dispatch(
197
- displayRemovalPrompt(
179
+ displayBlockRemovalPrompt(
198
180
  clientIds,
199
181
  selectPrevious,
200
182
  Array.from( blockNamesForPrompt )
@@ -246,7 +228,7 @@ export const ensureDefaultBlock =
246
228
  * Returns an action object used in signalling that a block removal prompt must
247
229
  * be displayed.
248
230
  *
249
- * Contrast with `toggleRemovalPromptSupport`.
231
+ * Contrast with `setBlockRemovalRules`.
250
232
  *
251
233
  * @param {string|string[]} clientIds Client IDs of blocks to remove.
252
234
  * @param {boolean} selectPrevious True if the previous block
@@ -254,16 +236,19 @@ export const ensureDefaultBlock =
254
236
  * (if no previous block exists)
255
237
  * should be selected
256
238
  * when a block is removed.
257
- * @param {string[]} blockNamesForPrompt Names of blocks requiring user
239
+ * @param {string[]} blockNamesForPrompt Names of the blocks that
240
+ * triggered the need for
241
+ * confirmation before removal.
242
+ *
258
243
  * @return {Object} Action object.
259
244
  */
260
- export function displayRemovalPrompt(
245
+ function displayBlockRemovalPrompt(
261
246
  clientIds,
262
247
  selectPrevious,
263
248
  blockNamesForPrompt
264
249
  ) {
265
250
  return {
266
- type: 'DISPLAY_REMOVAL_PROMPT',
251
+ type: 'DISPLAY_BLOCK_REMOVAL_PROMPT',
267
252
  clientIds,
268
253
  selectPrevious,
269
254
  blockNamesForPrompt,
@@ -277,24 +262,36 @@ export function displayRemovalPrompt(
277
262
  *
278
263
  * @return {Object} Action object.
279
264
  */
280
- export function clearRemovalPrompt() {
265
+ export function clearBlockRemovalPrompt() {
281
266
  return {
282
- type: 'CLEAR_REMOVAL_PROMPT',
267
+ type: 'CLEAR_BLOCK_REMOVAL_PROMPT',
283
268
  };
284
269
  }
285
270
 
286
271
  /**
287
- * Returns an action object used in signalling that a removal prompt display
288
- * mechanism is available or unavailable in the current editor.
272
+ * Returns an action object used to set up any rules that a block editor may
273
+ * provide in order to prevent a user from accidentally removing certain
274
+ * blocks. These rules are then used to display a confirmation prompt to the
275
+ * user. For instance, in the Site Editor, the Query Loop block is important
276
+ * enough to warrant such confirmation.
277
+ *
278
+ * IMPORTANT: Registering rules implicitly signals to the `privateRemoveBlocks`
279
+ * action that the editor will be responsible for displaying block removal
280
+ * prompts and confirming deletions. This action is meant to be used by
281
+ * component `BlockRemovalWarningModal` only.
282
+ *
283
+ * The data is a record whose keys are block types (e.g. 'core/query') and
284
+ * whose values are the explanation to be shown to users (e.g. 'Query Loop
285
+ * displays a list of posts or pages.').
289
286
  *
290
- * Contrast with `displayRemovalPrompt`.
287
+ * Contrast with `displayBlockRemovalPrompt`.
291
288
  *
292
- * @param {boolean} status Whether a prompt display mechanism exists.
289
+ * @param {Record<string,string>|false} rules Block removal rules.
293
290
  * @return {Object} Action object.
294
291
  */
295
- export function toggleRemovalPromptSupport( status = true ) {
292
+ export function setBlockRemovalRules( rules = false ) {
296
293
  return {
297
- type: 'TOGGLE_REMOVAL_PROMPT_SUPPORT',
298
- status,
294
+ type: 'SET_BLOCK_REMOVAL_RULES',
295
+ rules,
299
296
  };
300
297
  }
@@ -202,6 +202,6 @@ export function getRemovalPromptData( state ) {
202
202
  *
203
203
  * @return {boolean} Whether removal prompt exists.
204
204
  */
205
- export function isRemovalPromptSupported( state ) {
206
- return state.isRemovalPromptSupported;
205
+ export function getBlockRemovalRules( state ) {
206
+ return state.blockRemovalRules;
207
207
  }
@@ -1480,14 +1480,14 @@ export function isSelectionEnabled( state = true, action ) {
1480
1480
  */
1481
1481
  function removalPromptData( state = false, action ) {
1482
1482
  switch ( action.type ) {
1483
- case 'DISPLAY_REMOVAL_PROMPT':
1483
+ case 'DISPLAY_BLOCK_REMOVAL_PROMPT':
1484
1484
  const { clientIds, selectPrevious, blockNamesForPrompt } = action;
1485
1485
  return {
1486
1486
  clientIds,
1487
1487
  selectPrevious,
1488
1488
  blockNamesForPrompt,
1489
1489
  };
1490
- case 'CLEAR_REMOVAL_PROMPT':
1490
+ case 'CLEAR_BLOCK_REMOVAL_PROMPT':
1491
1491
  return false;
1492
1492
  }
1493
1493
 
@@ -1495,17 +1495,25 @@ function removalPromptData( state = false, action ) {
1495
1495
  }
1496
1496
 
1497
1497
  /**
1498
- * Reducer prompt availability state.
1498
+ * Reducer returning any rules that a block editor may provide in order to
1499
+ * prevent a user from accidentally removing certain blocks. These rules are
1500
+ * then used to display a confirmation prompt to the user. For instance, in the
1501
+ * Site Editor, the Query Loop block is important enough to warrant such
1502
+ * confirmation.
1503
+ *
1504
+ * The data is a record whose keys are block types (e.g. 'core/query') and
1505
+ * whose values are the explanation to be shown to users (e.g. 'Query Loop
1506
+ * displays a list of posts or pages.').
1499
1507
  *
1500
1508
  * @param {boolean} state Current state.
1501
1509
  * @param {Object} action Dispatched action.
1502
1510
  *
1503
- * @return {boolean} Updated state.
1511
+ * @return {Record<string,string>} Updated state.
1504
1512
  */
1505
- function isRemovalPromptSupported( state = false, action ) {
1513
+ function blockRemovalRules( state = false, action ) {
1506
1514
  switch ( action.type ) {
1507
- case 'TOGGLE_REMOVAL_PROMPT_SUPPORT':
1508
- return action.status;
1515
+ case 'SET_BLOCK_REMOVAL_RULES':
1516
+ return action.rules;
1509
1517
  }
1510
1518
 
1511
1519
  return state;
@@ -1924,7 +1932,7 @@ const combinedReducers = combineReducers( {
1924
1932
  blockVisibility,
1925
1933
  blockEditingModes,
1926
1934
  removalPromptData,
1927
- isRemovalPromptSupported,
1935
+ blockRemovalRules,
1928
1936
  } );
1929
1937
 
1930
1938
  function withAutomaticChangeReset( reducer ) {
@@ -2018,7 +2018,7 @@ export const getInserterItems = createSelector(
2018
2018
  title: reusableBlock.title.raw,
2019
2019
  icon,
2020
2020
  category: 'reusable',
2021
- keywords: [],
2021
+ keywords: [ 'reusable' ],
2022
2022
  isDisabled: false,
2023
2023
  utility: 1, // Deprecated.
2024
2024
  frecency,
@@ -617,6 +617,7 @@ describe( 'actions', () => {
617
617
  const select = {
618
618
  getBlockRootClientId: () => undefined,
619
619
  canRemoveBlocks: () => true,
620
+ getBlockRemovalRules: () => false,
620
621
  };
621
622
  const dispatch = Object.assign( jest.fn(), {
622
623
  selectPreviousBlock: jest.fn(),
@@ -727,6 +728,7 @@ describe( 'actions', () => {
727
728
  const select = {
728
729
  getBlockRootClientId: () => null,
729
730
  canRemoveBlocks: () => true,
731
+ getBlockRemovalRules: () => false,
730
732
  };
731
733
  const dispatch = Object.assign( jest.fn(), {
732
734
  selectPreviousBlock: jest.fn(),
@@ -751,6 +753,7 @@ describe( 'actions', () => {
751
753
  const select = {
752
754
  getBlockRootClientId: () => null,
753
755
  canRemoveBlocks: () => true,
756
+ getBlockRemovalRules: () => false,
754
757
  };
755
758
  const dispatch = Object.assign( jest.fn(), {
756
759
  selectPreviousBlock: jest.fn(),
@@ -3351,7 +3351,7 @@ describe( 'selectors', () => {
3351
3351
  id: 'core/block/1',
3352
3352
  initialAttributes: { ref: 1 },
3353
3353
  isDisabled: false,
3354
- keywords: [],
3354
+ keywords: [ 'reusable' ],
3355
3355
  name: 'core/block',
3356
3356
  syncStatus: undefined,
3357
3357
  title: 'Reusable Block 1',