@wordpress/block-editor 12.22.0 → 12.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +4 -0
  3. package/build/components/block-list/block.js +11 -3
  4. package/build/components/block-list/block.js.map +1 -1
  5. package/build/components/block-mover/button.js +4 -1
  6. package/build/components/block-mover/button.js.map +1 -1
  7. package/build/components/block-mover/index.js +5 -1
  8. package/build/components/block-mover/index.js.map +1 -1
  9. package/build/components/block-patterns-list/index.js +4 -1
  10. package/build/components/block-patterns-list/index.js.map +1 -1
  11. package/build/components/block-settings-menu/block-settings-dropdown.js +7 -3
  12. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  13. package/build/components/block-switcher/index.js +4 -3
  14. package/build/components/block-switcher/index.js.map +1 -1
  15. package/build/components/block-toolbar/index.js +5 -4
  16. package/build/components/block-toolbar/index.js.map +1 -1
  17. package/build/components/block-toolbar/shuffle.js +18 -9
  18. package/build/components/block-toolbar/shuffle.js.map +1 -1
  19. package/build/components/block-tools/block-selection-button.js +48 -8
  20. package/build/components/block-tools/block-selection-button.js.map +1 -1
  21. package/build/components/block-tools/index.js +14 -2
  22. package/build/components/block-tools/index.js.map +1 -1
  23. package/build/components/global-styles/advanced-panel.js +9 -2
  24. package/build/components/global-styles/advanced-panel.js.map +1 -1
  25. package/build/components/global-styles/background-panel.js +444 -0
  26. package/build/components/global-styles/background-panel.js.map +1 -0
  27. package/build/components/global-styles/color-panel.js +2 -1
  28. package/build/components/global-styles/color-panel.js.map +1 -1
  29. package/build/components/global-styles/get-global-styles-changes.js +3 -0
  30. package/build/components/global-styles/get-global-styles-changes.js.map +1 -1
  31. package/build/components/global-styles/hooks.js +1 -1
  32. package/build/components/global-styles/hooks.js.map +1 -1
  33. package/build/components/global-styles/index.js +13 -0
  34. package/build/components/global-styles/index.js.map +1 -1
  35. package/build/components/global-styles/use-global-styles-output.js +15 -14
  36. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  37. package/build/components/global-styles/utils.js +2 -1
  38. package/build/components/global-styles/utils.js.map +1 -1
  39. package/build/components/iframe/index.js +9 -4
  40. package/build/components/iframe/index.js.map +1 -1
  41. package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
  42. package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
  43. package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -1
  44. package/build/components/inserter/library.js +2 -0
  45. package/build/components/inserter/library.js.map +1 -1
  46. package/build/components/inserter/menu.js +8 -2
  47. package/build/components/inserter/menu.js.map +1 -1
  48. package/build/components/inserter/search-items.js +36 -15
  49. package/build/components/inserter/search-items.js.map +1 -1
  50. package/build/components/keyboard-shortcuts/index.js +11 -0
  51. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  52. package/build/components/list-view/block-select-button.js +16 -0
  53. package/build/components/list-view/block-select-button.js.map +1 -1
  54. package/build/components/list-view/block.js +1 -1
  55. package/build/components/list-view/block.js.map +1 -1
  56. package/build/components/list-view/index.js +17 -2
  57. package/build/components/list-view/index.js.map +1 -1
  58. package/build/components/list-view/use-list-view-collapse-items.js +47 -0
  59. package/build/components/list-view/use-list-view-collapse-items.js.map +1 -0
  60. package/build/components/rich-text/index.js +14 -11
  61. package/build/components/rich-text/index.js.map +1 -1
  62. package/build/components/rich-text/index.native.js +17 -11
  63. package/build/components/rich-text/index.native.js.map +1 -1
  64. package/build/components/rich-text/native/get-format-colors.native.js +1 -1
  65. package/build/components/rich-text/native/get-format-colors.native.js.map +1 -1
  66. package/build/components/rich-text/native/index.native.js +2 -2
  67. package/build/components/rich-text/native/index.native.js.map +1 -1
  68. package/build/components/rich-text/with-deprecations.js +0 -3
  69. package/build/components/rich-text/with-deprecations.js.map +1 -1
  70. package/build/components/url-popover/image-url-input-ui.js +50 -36
  71. package/build/components/url-popover/image-url-input-ui.js.map +1 -1
  72. package/build/components/use-block-display-information/index.js +4 -6
  73. package/build/components/use-block-display-information/index.js.map +1 -1
  74. package/build/hooks/anchor.js +2 -2
  75. package/build/hooks/anchor.js.map +1 -1
  76. package/build/hooks/background.js +70 -424
  77. package/build/hooks/background.js.map +1 -1
  78. package/build/hooks/index.js +7 -0
  79. package/build/hooks/index.js.map +1 -1
  80. package/build/hooks/use-zoom-out.js +47 -0
  81. package/build/hooks/use-zoom-out.js.map +1 -0
  82. package/build/index.js +7 -0
  83. package/build/index.js.map +1 -1
  84. package/build/private-apis.js +6 -1
  85. package/build/private-apis.js.map +1 -1
  86. package/build/private-apis.native.js +3 -1
  87. package/build/private-apis.native.js.map +1 -1
  88. package/build/store/private-actions.js +13 -0
  89. package/build/store/private-actions.js.map +1 -1
  90. package/build/store/private-keys.js +2 -1
  91. package/build/store/private-keys.js.map +1 -1
  92. package/build/store/private-selectors.js +24 -3
  93. package/build/store/private-selectors.js.map +1 -1
  94. package/build/store/reducer.js +22 -0
  95. package/build/store/reducer.js.map +1 -1
  96. package/build/store/selectors.js +34 -32
  97. package/build/store/selectors.js.map +1 -1
  98. package/build/store/utils.js +7 -1
  99. package/build/store/utils.js.map +1 -1
  100. package/build/utils/transform-styles/index.js +2 -1
  101. package/build/utils/transform-styles/index.js.map +1 -1
  102. package/build-module/components/block-list/block.js +11 -3
  103. package/build-module/components/block-list/block.js.map +1 -1
  104. package/build-module/components/block-mover/button.js +4 -1
  105. package/build-module/components/block-mover/button.js.map +1 -1
  106. package/build-module/components/block-mover/index.js +5 -1
  107. package/build-module/components/block-mover/index.js.map +1 -1
  108. package/build-module/components/block-patterns-list/index.js +4 -1
  109. package/build-module/components/block-patterns-list/index.js.map +1 -1
  110. package/build-module/components/block-settings-menu/block-settings-dropdown.js +7 -3
  111. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  112. package/build-module/components/block-switcher/index.js +4 -3
  113. package/build-module/components/block-switcher/index.js.map +1 -1
  114. package/build-module/components/block-toolbar/index.js +5 -4
  115. package/build-module/components/block-toolbar/index.js.map +1 -1
  116. package/build-module/components/block-toolbar/shuffle.js +18 -9
  117. package/build-module/components/block-toolbar/shuffle.js.map +1 -1
  118. package/build-module/components/block-tools/block-selection-button.js +50 -10
  119. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  120. package/build-module/components/block-tools/index.js +14 -2
  121. package/build-module/components/block-tools/index.js.map +1 -1
  122. package/build-module/components/global-styles/advanced-panel.js +9 -2
  123. package/build-module/components/global-styles/advanced-panel.js.map +1 -1
  124. package/build-module/components/global-styles/background-panel.js +430 -0
  125. package/build-module/components/global-styles/background-panel.js.map +1 -0
  126. package/build-module/components/global-styles/color-panel.js +2 -1
  127. package/build-module/components/global-styles/color-panel.js.map +1 -1
  128. package/build-module/components/global-styles/get-global-styles-changes.js +3 -0
  129. package/build-module/components/global-styles/get-global-styles-changes.js.map +1 -1
  130. package/build-module/components/global-styles/hooks.js +1 -1
  131. package/build-module/components/global-styles/hooks.js.map +1 -1
  132. package/build-module/components/global-styles/index.js +1 -0
  133. package/build-module/components/global-styles/index.js.map +1 -1
  134. package/build-module/components/global-styles/use-global-styles-output.js +16 -15
  135. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  136. package/build-module/components/global-styles/utils.js +1 -0
  137. package/build-module/components/global-styles/utils.js.map +1 -1
  138. package/build-module/components/iframe/index.js +9 -4
  139. package/build-module/components/iframe/index.js.map +1 -1
  140. package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
  141. package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
  142. package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -1
  143. package/build-module/components/inserter/library.js +2 -0
  144. package/build-module/components/inserter/library.js.map +1 -1
  145. package/build-module/components/inserter/menu.js +8 -2
  146. package/build-module/components/inserter/menu.js.map +1 -1
  147. package/build-module/components/inserter/search-items.js +33 -15
  148. package/build-module/components/inserter/search-items.js.map +1 -1
  149. package/build-module/components/keyboard-shortcuts/index.js +11 -0
  150. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  151. package/build-module/components/list-view/block-select-button.js +16 -0
  152. package/build-module/components/list-view/block-select-button.js.map +1 -1
  153. package/build-module/components/list-view/block.js +1 -1
  154. package/build-module/components/list-view/block.js.map +1 -1
  155. package/build-module/components/list-view/index.js +17 -2
  156. package/build-module/components/list-view/index.js.map +1 -1
  157. package/build-module/components/list-view/use-list-view-collapse-items.js +40 -0
  158. package/build-module/components/list-view/use-list-view-collapse-items.js.map +1 -0
  159. package/build-module/components/rich-text/index.js +15 -12
  160. package/build-module/components/rich-text/index.js.map +1 -1
  161. package/build-module/components/rich-text/index.native.js +16 -11
  162. package/build-module/components/rich-text/index.native.js.map +1 -1
  163. package/build-module/components/rich-text/native/get-format-colors.native.js +1 -1
  164. package/build-module/components/rich-text/native/get-format-colors.native.js.map +1 -1
  165. package/build-module/components/rich-text/native/index.native.js +2 -2
  166. package/build-module/components/rich-text/native/index.native.js.map +1 -1
  167. package/build-module/components/rich-text/with-deprecations.js +0 -3
  168. package/build-module/components/rich-text/with-deprecations.js.map +1 -1
  169. package/build-module/components/url-popover/image-url-input-ui.js +50 -36
  170. package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
  171. package/build-module/components/use-block-display-information/index.js +5 -7
  172. package/build-module/components/use-block-display-information/index.js.map +1 -1
  173. package/build-module/hooks/anchor.js +2 -2
  174. package/build-module/hooks/anchor.js.map +1 -1
  175. package/build-module/hooks/background.js +67 -419
  176. package/build-module/hooks/background.js.map +1 -1
  177. package/build-module/hooks/index.js +1 -0
  178. package/build-module/hooks/index.js.map +1 -1
  179. package/build-module/hooks/use-zoom-out.js +41 -0
  180. package/build-module/hooks/use-zoom-out.js.map +1 -0
  181. package/build-module/index.js +1 -1
  182. package/build-module/index.js.map +1 -1
  183. package/build-module/private-apis.js +7 -2
  184. package/build-module/private-apis.js.map +1 -1
  185. package/build-module/private-apis.native.js +3 -1
  186. package/build-module/private-apis.native.js.map +1 -1
  187. package/build-module/store/private-actions.js +12 -0
  188. package/build-module/store/private-actions.js.map +1 -1
  189. package/build-module/store/private-keys.js +1 -0
  190. package/build-module/store/private-keys.js.map +1 -1
  191. package/build-module/store/private-selectors.js +22 -4
  192. package/build-module/store/private-selectors.js.map +1 -1
  193. package/build-module/store/reducer.js +21 -0
  194. package/build-module/store/reducer.js.map +1 -1
  195. package/build-module/store/selectors.js +35 -33
  196. package/build-module/store/selectors.js.map +1 -1
  197. package/build-module/store/utils.js +6 -1
  198. package/build-module/store/utils.js.map +1 -1
  199. package/build-module/utils/transform-styles/index.js +2 -1
  200. package/build-module/utils/transform-styles/index.js.map +1 -1
  201. package/build-style/content-rtl.css +4 -1
  202. package/build-style/content.css +4 -1
  203. package/build-style/style-rtl.css +84 -79
  204. package/build-style/style.css +84 -79
  205. package/package.json +31 -31
  206. package/src/components/block-list/block.js +19 -3
  207. package/src/components/block-mover/button.js +4 -1
  208. package/src/components/block-mover/index.js +8 -1
  209. package/src/components/block-patterns-list/index.js +22 -17
  210. package/src/components/block-preview/style.scss +28 -0
  211. package/src/components/block-settings-menu/block-settings-dropdown.js +8 -2
  212. package/src/components/block-switcher/index.js +5 -3
  213. package/src/components/block-switcher/style.scss +1 -1
  214. package/src/components/block-toolbar/index.js +22 -19
  215. package/src/components/block-toolbar/shuffle.js +19 -13
  216. package/src/components/block-toolbar/style.scss +1 -1
  217. package/src/components/block-tools/block-selection-button.js +66 -9
  218. package/src/components/block-tools/index.js +18 -1
  219. package/src/components/button-block-appender/content.scss +5 -1
  220. package/src/components/default-block-appender/content.scss +2 -2
  221. package/src/components/global-styles/advanced-panel.js +8 -2
  222. package/src/components/global-styles/background-panel.js +591 -0
  223. package/src/components/global-styles/color-panel.js +2 -1
  224. package/src/components/global-styles/get-global-styles-changes.js +3 -0
  225. package/src/components/global-styles/hooks.js +1 -0
  226. package/src/components/global-styles/index.js +4 -0
  227. package/src/components/global-styles/style.scss +78 -1
  228. package/src/{hooks/test/background.js → components/global-styles/test/background-panel.js} +36 -1
  229. package/src/components/global-styles/test/get-global-styles-changes.js +22 -3
  230. package/src/components/global-styles/test/use-global-styles-output.js +9 -9
  231. package/src/components/global-styles/use-global-styles-output.js +27 -16
  232. package/src/components/global-styles/utils.js +1 -0
  233. package/src/components/iframe/index.js +19 -9
  234. package/src/components/inserter/block-patterns-tab/index.js +1 -0
  235. package/src/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
  236. package/src/components/inserter/library.js +4 -0
  237. package/src/components/inserter/menu.js +8 -1
  238. package/src/components/inserter/search-items.js +37 -15
  239. package/src/components/inserter/style.scss +6 -12
  240. package/src/components/keyboard-shortcuts/index.js +11 -0
  241. package/src/components/list-view/block-select-button.js +13 -1
  242. package/src/components/list-view/block.js +1 -1
  243. package/src/components/list-view/index.js +18 -1
  244. package/src/components/list-view/style.scss +4 -4
  245. package/src/components/list-view/use-list-view-collapse-items.js +33 -0
  246. package/src/components/rich-text/index.js +30 -13
  247. package/src/components/rich-text/index.native.js +14 -11
  248. package/src/components/rich-text/native/get-format-colors.native.js +1 -1
  249. package/src/components/rich-text/native/index.native.js +2 -2
  250. package/src/components/rich-text/with-deprecations.js +0 -3
  251. package/src/components/url-popover/image-url-input-ui.js +68 -51
  252. package/src/components/use-block-display-information/index.js +8 -10
  253. package/src/hooks/anchor.js +11 -9
  254. package/src/hooks/background.js +77 -538
  255. package/src/hooks/index.js +1 -0
  256. package/src/hooks/use-zoom-out.js +36 -0
  257. package/src/index.js +1 -0
  258. package/src/private-apis.js +13 -1
  259. package/src/private-apis.native.js +2 -0
  260. package/src/store/private-actions.js +12 -0
  261. package/src/store/private-keys.js +1 -0
  262. package/src/store/private-selectors.js +54 -27
  263. package/src/store/reducer.js +22 -0
  264. package/src/store/selectors.js +195 -180
  265. package/src/store/test/private-actions.js +10 -0
  266. package/src/store/test/private-selectors.js +13 -0
  267. package/src/store/test/reducer.js +26 -0
  268. package/src/store/test/selectors.js +90 -199
  269. package/src/store/utils.js +13 -0
  270. package/src/style.scss +0 -2
  271. package/src/utils/transform-styles/index.js +2 -1
  272. package/src/hooks/anchor.scss +0 -4
  273. package/src/hooks/background.scss +0 -75
@@ -132,6 +132,17 @@ function KeyboardShortcutsRegister() {
132
132
  character: 'y',
133
133
  },
134
134
  } );
135
+
136
+ // List view shortcuts.
137
+ registerShortcut( {
138
+ name: 'core/block-editor/collapse-list-view',
139
+ category: 'list-view',
140
+ description: __( 'Collapse all other items.' ),
141
+ keyCombination: {
142
+ modifier: 'alt',
143
+ character: 'l',
144
+ },
145
+ } );
135
146
  }, [ registerShortcut ] );
136
147
 
137
148
  return null;
@@ -64,6 +64,7 @@ function ListViewBlockSelectButton(
64
64
  getPreviousBlockClientId,
65
65
  getBlockRootClientId,
66
66
  getBlockOrder,
67
+ getBlockParents,
67
68
  getBlocksByClientId,
68
69
  canRemoveBlocks,
69
70
  } = useSelect( blockEditorStore );
@@ -72,7 +73,7 @@ function ListViewBlockSelectButton(
72
73
  const isMatch = useShortcutEventMatch();
73
74
  const isSticky = blockInformation?.positionType === 'sticky';
74
75
  const images = useListViewImages( { clientId, isExpanded } );
75
- const { rootClientId } = useListViewContext();
76
+ const { collapseAll, expand, rootClientId } = useListViewContext();
76
77
 
77
78
  const positionLabel = blockInformation?.positionLabel
78
79
  ? sprintf(
@@ -227,6 +228,17 @@ function ListViewBlockSelectButton(
227
228
  blockClientIds[ blockClientIds.length - 1 ],
228
229
  null
229
230
  );
231
+ } else if ( isMatch( 'core/block-editor/collapse-list-view', event ) ) {
232
+ if ( event.defaultPrevented ) {
233
+ return;
234
+ }
235
+ event.preventDefault();
236
+ const { firstBlockClientId } = getBlocksToUpdate();
237
+ const blockParents = getBlockParents( firstBlockClientId, false );
238
+ // Collapse all blocks.
239
+ collapseAll();
240
+ // Expand all parents of the current block.
241
+ expand( blockParents );
230
242
  }
231
243
  }
232
244
 
@@ -396,7 +396,7 @@ function ListViewBlock( {
396
396
  clientIds={ dropdownClientIds }
397
397
  block={ block }
398
398
  icon={ moreVertical }
399
- label={ __( 'Actions' ) }
399
+ label={ __( 'Options' ) }
400
400
  popoverProps={ {
401
401
  anchor: settingsPopoverAnchor, // Used to position the settings at the cursor on right-click.
402
402
  } }
@@ -37,6 +37,7 @@ import ListViewDropIndicatorPreview from './drop-indicator';
37
37
  import useBlockSelection from './use-block-selection';
38
38
  import useListViewBlockIndexes from './use-list-view-block-indexes';
39
39
  import useListViewClientIds from './use-list-view-client-ids';
40
+ import useListViewCollapseItems from './use-list-view-collapse-items';
40
41
  import useListViewDropZone from './use-list-view-drop-zone';
41
42
  import useListViewExpandSelectedItem from './use-list-view-expand-selected-item';
42
43
  import { store as blockEditorStore } from '../../store';
@@ -45,6 +46,9 @@ import { focusListItem } from './utils';
45
46
  import useClipboardHandler from './use-clipboard-handler';
46
47
 
47
48
  const expanded = ( state, action ) => {
49
+ if ( action.type === 'clear' ) {
50
+ return {};
51
+ }
48
52
  if ( Array.isArray( action.clientIds ) ) {
49
53
  return {
50
54
  ...state,
@@ -194,7 +198,10 @@ function ListViewComponent(
194
198
  if ( ! clientId ) {
195
199
  return;
196
200
  }
197
- setExpandedState( { type: 'expand', clientIds: [ clientId ] } );
201
+ const clientIds = Array.isArray( clientId )
202
+ ? clientId
203
+ : [ clientId ];
204
+ setExpandedState( { type: 'expand', clientIds } );
198
205
  },
199
206
  [ setExpandedState ]
200
207
  );
@@ -207,6 +214,9 @@ function ListViewComponent(
207
214
  },
208
215
  [ setExpandedState ]
209
216
  );
217
+ const collapseAll = useCallback( () => {
218
+ setExpandedState( { type: 'clear' } );
219
+ }, [ setExpandedState ] );
210
220
  const expandRow = useCallback(
211
221
  ( row ) => {
212
222
  expand( row?.dataset?.block );
@@ -232,6 +242,11 @@ function ListViewComponent(
232
242
  [ updateBlockSelection ]
233
243
  );
234
244
 
245
+ useListViewCollapseItems( {
246
+ collapseAll,
247
+ expand,
248
+ } );
249
+
235
250
  const firstDraggedBlockClientId = draggedClientIds?.[ 0 ];
236
251
 
237
252
  // Convert a blockDropTarget into indexes relative to the blocks in the list view.
@@ -282,6 +297,7 @@ function ListViewComponent(
282
297
  expand,
283
298
  firstDraggedBlockIndex,
284
299
  collapse,
300
+ collapseAll,
285
301
  BlockSettingsMenu,
286
302
  listViewInstanceId: instanceId,
287
303
  AdditionalBlockContent,
@@ -299,6 +315,7 @@ function ListViewComponent(
299
315
  expand,
300
316
  firstDraggedBlockIndex,
301
317
  collapse,
318
+ collapseAll,
302
319
  BlockSettingsMenu,
303
320
  instanceId,
304
321
  AdditionalBlockContent,
@@ -212,7 +212,7 @@
212
212
  align-items: center;
213
213
  width: 100%;
214
214
  height: auto;
215
- padding: ($grid-unit-15 * 0.5) $grid-unit-05 ($grid-unit-15 * 0.5) 0;
215
+ padding: ($grid-unit-15 * 0.5) ($grid-unit-15 * 0.5) ($grid-unit-15 * 0.5) 0;
216
216
  text-align: left;
217
217
  border-radius: $radius-block-ui;
218
218
  position: relative;
@@ -309,14 +309,14 @@
309
309
 
310
310
  &,
311
311
  .components-button.has-icon {
312
- width: 24px;
313
- min-width: 24px;
312
+ width: $button-size-small;
313
+ min-width: $button-size-small;
314
314
  padding: 0;
315
315
  }
316
316
  }
317
317
 
318
318
  .block-editor-list-view-block__menu-cell {
319
- padding-right: $grid-unit-05;
319
+ padding-right: $grid-unit-15 * 0.5; // 6px.
320
320
 
321
321
  .components-button.has-icon {
322
322
  height: 24px;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useEffect } from '@wordpress/element';
5
+ import { useSelect } from '@wordpress/data';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { store as blockEditorStore } from '../../store';
11
+ import { unlock } from '../../lock-unlock';
12
+
13
+ export default function useListViewCollapseItems( { collapseAll, expand } ) {
14
+ const { expandedBlock, getBlockParents } = useSelect( ( select ) => {
15
+ const { getBlockParents: _getBlockParents, getExpandedBlock } = unlock(
16
+ select( blockEditorStore )
17
+ );
18
+ return {
19
+ expandedBlock: getExpandedBlock(),
20
+ getBlockParents: _getBlockParents,
21
+ };
22
+ }, [] );
23
+
24
+ // Collapse all but the specified block when the expanded block client Id changes.
25
+ useEffect( () => {
26
+ if ( expandedBlock ) {
27
+ const blockParents = getBlockParents( expandedBlock, false );
28
+ // Collapse all blocks and expand the block's parents.
29
+ collapseAll();
30
+ expand( blockParents );
31
+ }
32
+ }, [ collapseAll, expand, expandedBlock, getBlockParents ] );
33
+ }
@@ -13,7 +13,7 @@ import {
13
13
  createContext,
14
14
  } from '@wordpress/element';
15
15
  import { useDispatch, useSelect } from '@wordpress/data';
16
- import { useMergeRefs } from '@wordpress/compose';
16
+ import { useMergeRefs, useInstanceId } from '@wordpress/compose';
17
17
  import {
18
18
  __unstableUseRichText as useRichText,
19
19
  removeFormat,
@@ -52,6 +52,8 @@ import { canBindBlock } from '../../hooks/use-bindings-attributes';
52
52
  export const keyboardShortcutContext = createContext();
53
53
  export const inputEventContext = createContext();
54
54
 
55
+ const instanceIdKey = Symbol( 'instanceId' );
56
+
55
57
  /**
56
58
  * Removes props used for the native version of RichText so that they are not
57
59
  * passed to the DOM element and log warnings.
@@ -75,7 +77,6 @@ function removeNativeProps( props ) {
75
77
  fontStyle,
76
78
  minWidth,
77
79
  maxWidth,
78
- setRef,
79
80
  disableSuggestions,
80
81
  disableAutocorrection,
81
82
  ...restProps
@@ -110,13 +111,15 @@ export function RichTextWrapper(
110
111
  __unstableDisableFormats: disableFormats,
111
112
  disableLineBreaks,
112
113
  __unstableAllowPrefixTransformations,
113
- disableEditing,
114
+ readOnly,
114
115
  ...props
115
116
  },
116
117
  forwardedRef
117
118
  ) {
118
119
  props = removeNativeProps( props );
119
120
 
121
+ const instanceId = useInstanceId( RichTextWrapper );
122
+
120
123
  const anchorRef = useRef();
121
124
  const context = useBlockEditContext();
122
125
  const { clientId, isSelected: isBlockSelected, name: blockName } = context;
@@ -139,7 +142,9 @@ export function RichTextWrapper(
139
142
  isSelected =
140
143
  selectionStart.clientId === clientId &&
141
144
  selectionEnd.clientId === clientId &&
142
- selectionStart.attributeKey === identifier;
145
+ ( identifier
146
+ ? selectionStart.attributeKey === identifier
147
+ : selectionStart[ instanceIdKey ] === instanceId );
143
148
  } else if ( originalIsSelected ) {
144
149
  isSelected = selectionStart.clientId === clientId;
145
150
  }
@@ -153,6 +158,7 @@ export function RichTextWrapper(
153
158
  const { selectionStart, selectionEnd, isSelected } = useSelect( selector, [
154
159
  clientId,
155
160
  identifier,
161
+ instanceId,
156
162
  originalIsSelected,
157
163
  isBlockSelected,
158
164
  ] );
@@ -196,7 +202,7 @@ export function RichTextWrapper(
196
202
  [ blockBindings, blockName ]
197
203
  );
198
204
 
199
- const shouldDisableEditing = disableEditing || disableBoundBlocks;
205
+ const shouldDisableEditing = readOnly || disableBoundBlocks;
200
206
 
201
207
  const { getSelectionStart, getSelectionEnd, getBlockRootClientId } =
202
208
  useSelect( blockEditorStore );
@@ -213,6 +219,13 @@ export function RichTextWrapper(
213
219
  const selection = {};
214
220
  const unset = start === undefined && end === undefined;
215
221
 
222
+ const baseSelection = {
223
+ clientId,
224
+ [ identifier ? 'attributeKey' : instanceIdKey ]: identifier
225
+ ? identifier
226
+ : instanceId,
227
+ };
228
+
216
229
  if ( typeof start === 'number' || unset ) {
217
230
  // If we are only setting the start (or the end below), which
218
231
  // means a partial selection, and we're not updating a selection
@@ -227,8 +240,7 @@ export function RichTextWrapper(
227
240
  }
228
241
 
229
242
  selection.start = {
230
- clientId,
231
- attributeKey: identifier,
243
+ ...baseSelection,
232
244
  offset: start,
233
245
  };
234
246
  }
@@ -243,15 +255,22 @@ export function RichTextWrapper(
243
255
  }
244
256
 
245
257
  selection.end = {
246
- clientId,
247
- attributeKey: identifier,
258
+ ...baseSelection,
248
259
  offset: end,
249
260
  };
250
261
  }
251
262
 
252
263
  selectionChange( selection );
253
264
  },
254
- [ clientId, identifier ]
265
+ [
266
+ clientId,
267
+ getBlockRootClientId,
268
+ getSelectionEnd,
269
+ getSelectionStart,
270
+ identifier,
271
+ instanceId,
272
+ selectionChange,
273
+ ]
255
274
  );
256
275
 
257
276
  const {
@@ -466,9 +485,7 @@ PrivateRichText.isEmpty = ( value ) => {
466
485
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md
467
486
  */
468
487
  const PublicForwardedRichTextContainer = forwardRef( ( props, ref ) => {
469
- return (
470
- <PrivateRichText ref={ ref } { ...props } disableEditing={ false } />
471
- );
488
+ return <PrivateRichText ref={ ref } { ...props } readOnly={ false } />;
472
489
  } );
473
490
 
474
491
  PublicForwardedRichTextContainer.Content = Content;
@@ -94,14 +94,13 @@ export function RichTextWrapper(
94
94
  minWidth,
95
95
  maxWidth,
96
96
  onBlur,
97
- setRef,
98
97
  disableSuggestions,
99
98
  disableAutocorrection,
100
99
  containerWidth,
101
100
  onEnter: onCustomEnter,
102
101
  ...props
103
102
  },
104
- forwardedRef
103
+ providedRef
105
104
  ) {
106
105
  const instanceId = useInstanceId( RichTextWrapper );
107
106
 
@@ -529,13 +528,13 @@ export function RichTextWrapper(
529
528
  [ onReplace, __unstableMarkAutomaticChange ]
530
529
  );
531
530
 
532
- const mergedRef = useMergeRefs( [ forwardedRef, fallbackRef ] );
531
+ const mergedRef = useMergeRefs( [ providedRef, fallbackRef ] );
533
532
 
534
533
  return (
535
534
  <RichText
536
535
  clientId={ clientId }
537
536
  identifier={ identifier }
538
- ref={ mergedRef }
537
+ nativeEditorRef={ mergedRef }
539
538
  value={ adjustedValue }
540
539
  onChange={ adjustedOnChange }
541
540
  selectionStart={ selectionStart }
@@ -586,7 +585,6 @@ export function RichTextWrapper(
586
585
  minWidth={ minWidth }
587
586
  maxWidth={ maxWidth }
588
587
  onBlur={ onBlur }
589
- setRef={ setRef }
590
588
  disableSuggestions={ disableSuggestions }
591
589
  disableAutocorrection={ disableAutocorrection }
592
590
  containerWidth={ containerWidth }
@@ -657,27 +655,32 @@ export function RichTextWrapper(
657
655
  );
658
656
  }
659
657
 
660
- const ForwardedRichTextContainer = withDeprecations(
658
+ // This export does not actually implement a private API, but was exported
659
+ // under this name for interoperability with the web version of the RichText
660
+ // component.
661
+ export const PrivateRichText = withDeprecations(
661
662
  forwardRef( RichTextWrapper )
662
663
  );
663
664
 
664
- ForwardedRichTextContainer.Content = Content;
665
+ PrivateRichText.Content = Content;
665
666
 
666
- ForwardedRichTextContainer.isEmpty = ( value ) => {
667
+ PrivateRichText.isEmpty = ( value ) => {
667
668
  return ! value || value.length === 0;
668
669
  };
669
670
 
670
- ForwardedRichTextContainer.Content.defaultProps = {
671
+ PrivateRichText.Content.defaultProps = {
671
672
  format: 'string',
672
673
  value: '',
673
674
  };
674
675
 
675
- ForwardedRichTextContainer.Raw = RichText;
676
+ PrivateRichText.Raw = forwardRef( ( props, ref ) => (
677
+ <RichText { ...props } nativeEditorRef={ ref } />
678
+ ) );
676
679
 
677
680
  /**
678
681
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md
679
682
  */
680
- export default ForwardedRichTextContainer;
683
+ export default PrivateRichText;
681
684
  export { RichTextShortcut } from './shortcut';
682
685
  export { RichTextToolbarButton } from './toolbar-button';
683
686
  export { __unstableRichTextInputEvent } from './input-event';
@@ -27,7 +27,7 @@ export function getFormatColors( formats, colors ) {
27
27
  );
28
28
  const currentStyles = currentFormat?.attributes?.style;
29
29
  if (
30
- colorObject &&
30
+ colorObject?.color &&
31
31
  ( ! currentStyles ||
32
32
  currentStyles?.indexOf( colorObject.color ) ===
33
33
  -1 )
@@ -1222,8 +1222,8 @@ export class RichText extends Component {
1222
1222
  ref={ ( ref ) => {
1223
1223
  this._editor = ref;
1224
1224
 
1225
- if ( this.props.setRef ) {
1226
- this.props.setRef( ref );
1225
+ if ( this.props.nativeEditorRef ) {
1226
+ this.props.nativeEditorRef( ref );
1227
1227
  }
1228
1228
  } }
1229
1229
  style={ {
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import { forwardRef } from '@wordpress/element';
5
5
  import { children as childrenSource } from '@wordpress/blocks';
6
- import { useInstanceId } from '@wordpress/compose';
7
6
  import { __unstableCreateElement } from '@wordpress/rich-text';
8
7
  import deprecated from '@wordpress/deprecated';
9
8
 
@@ -36,12 +35,10 @@ export function withDeprecations( Component ) {
36
35
  }
37
36
 
38
37
  const NewComponent = props.multiline ? RichTextMultiline : Component;
39
- const instanceId = useInstanceId( NewComponent );
40
38
 
41
39
  return (
42
40
  <NewComponent
43
41
  { ...props }
44
- identifier={ props.identifier || instanceId }
45
42
  value={ value }
46
43
  onChange={ onChange }
47
44
  ref={ ref }
@@ -46,6 +46,7 @@ const ImageURLInputUI = ( {
46
46
  showLightboxSetting,
47
47
  lightboxEnabled,
48
48
  onSetLightbox,
49
+ resetLightbox,
49
50
  } ) => {
50
51
  const [ isOpen, setIsOpen ] = useState( false );
51
52
  // Use internal state instead of a ref to make sure that the component
@@ -241,7 +242,9 @@ const ImageURLInputUI = ( {
241
242
  );
242
243
 
243
244
  const linkEditorValue = urlInput !== null ? urlInput : url;
244
- const showLinkEditor = ( ! linkEditorValue && ! lightboxEnabled ) === true;
245
+ const hideLightboxPanel =
246
+ ! lightboxEnabled || ( lightboxEnabled && ! showLightboxSetting );
247
+ const showLinkEditor = ! linkEditorValue && hideLightboxPanel;
245
248
 
246
249
  const urlLabel = (
247
250
  getLinkDestinations().find(
@@ -249,6 +252,65 @@ const ImageURLInputUI = ( {
249
252
  ) || {}
250
253
  ).title;
251
254
 
255
+ const PopoverChildren = () => {
256
+ if (
257
+ lightboxEnabled &&
258
+ showLightboxSetting &&
259
+ ! url &&
260
+ ! isEditingLink
261
+ ) {
262
+ return (
263
+ <div className="block-editor-url-popover__expand-on-click">
264
+ <Icon icon={ fullscreen } />
265
+ <div className="text">
266
+ <p>{ __( 'Expand on click' ) }</p>
267
+ <p className="description">
268
+ { __( 'Scales the image with a lightbox effect' ) }
269
+ </p>
270
+ </div>
271
+ <Button
272
+ icon={ linkOff }
273
+ label={ __( 'Disable expand on click' ) }
274
+ onClick={ () => {
275
+ onSetLightbox( false );
276
+ } }
277
+ size="compact"
278
+ />
279
+ </div>
280
+ );
281
+ } else if ( ! url || isEditingLink ) {
282
+ return (
283
+ <URLPopover.LinkEditor
284
+ className="block-editor-format-toolbar__link-container-content"
285
+ value={ linkEditorValue }
286
+ onChangeInputValue={ setUrlInput }
287
+ onSubmit={ onSubmitLinkChange() }
288
+ autocompleteRef={ autocompleteRef }
289
+ />
290
+ );
291
+ } else if ( url && ! isEditingLink ) {
292
+ return (
293
+ <>
294
+ <URLPopover.LinkViewer
295
+ className="block-editor-format-toolbar__link-container-content"
296
+ url={ url }
297
+ onEditLinkClick={ startEditLink }
298
+ urlLabel={ urlLabel }
299
+ />
300
+ <Button
301
+ icon={ linkOff }
302
+ label={ __( 'Remove link' ) }
303
+ onClick={ () => {
304
+ onLinkRemove();
305
+ resetLightbox();
306
+ } }
307
+ size="compact"
308
+ />
309
+ </>
310
+ );
311
+ }
312
+ };
313
+
252
314
  return (
253
315
  <>
254
316
  <ToolbarButton
@@ -258,7 +320,9 @@ const ImageURLInputUI = ( {
258
320
  aria-expanded={ isOpen }
259
321
  onClick={ openLinkUI }
260
322
  ref={ setPopoverAnchor }
261
- isActive={ !! url || lightboxEnabled }
323
+ isActive={
324
+ !! url || ( lightboxEnabled && showLightboxSetting )
325
+ }
262
326
  />
263
327
  { isOpen && (
264
328
  <URLPopover
@@ -267,7 +331,7 @@ const ImageURLInputUI = ( {
267
331
  onFocusOutside={ onFocusOutside() }
268
332
  onClose={ closeLinkUI }
269
333
  renderSettings={
270
- ! lightboxEnabled ? () => advancedOptions : null
334
+ hideLightboxPanel ? () => advancedOptions : null
271
335
  }
272
336
  additionalControls={
273
337
  showLinkEditor && (
@@ -314,54 +378,7 @@ const ImageURLInputUI = ( {
314
378
  }
315
379
  offset={ 13 }
316
380
  >
317
- { ( ! url || isEditingLink ) && ! lightboxEnabled && (
318
- <>
319
- <URLPopover.LinkEditor
320
- className="block-editor-format-toolbar__link-container-content"
321
- value={ linkEditorValue }
322
- onChangeInputValue={ setUrlInput }
323
- onSubmit={ onSubmitLinkChange() }
324
- autocompleteRef={ autocompleteRef }
325
- />
326
- </>
327
- ) }
328
- { url && ! isEditingLink && ! lightboxEnabled && (
329
- <>
330
- <URLPopover.LinkViewer
331
- className="block-editor-format-toolbar__link-container-content"
332
- url={ url }
333
- onEditLinkClick={ startEditLink }
334
- urlLabel={ urlLabel }
335
- />
336
- <Button
337
- icon={ linkOff }
338
- label={ __( 'Remove link' ) }
339
- onClick={ onLinkRemove }
340
- size="compact"
341
- />
342
- </>
343
- ) }
344
- { ! url && ! isEditingLink && lightboxEnabled && (
345
- <div className="block-editor-url-popover__expand-on-click">
346
- <Icon icon={ fullscreen } />
347
- <div className="text">
348
- <p>{ __( 'Expand on click' ) }</p>
349
- <p className="description">
350
- { __(
351
- 'Scales the image with a lightbox effect'
352
- ) }
353
- </p>
354
- </div>
355
- <Button
356
- icon={ linkOff }
357
- label={ __( 'Disable expand on click' ) }
358
- onClick={ () => {
359
- onSetLightbox( false );
360
- } }
361
- size="compact"
362
- />
363
- </div>
364
- ) }
381
+ { PopoverChildren() }
365
382
  </URLPopover>
366
383
  ) }
367
384
  </>
@@ -6,6 +6,7 @@ import {
6
6
  store as blocksStore,
7
7
  isReusableBlock,
8
8
  isTemplatePart,
9
+ __experimentalGetBlockLabel as getBlockLabel,
9
10
  } from '@wordpress/blocks';
10
11
  import { __ } from '@wordpress/i18n';
11
12
 
@@ -68,11 +69,8 @@ export default function useBlockDisplayInformation( clientId ) {
68
69
  return useSelect(
69
70
  ( select ) => {
70
71
  if ( ! clientId ) return null;
71
- const {
72
- getBlockName,
73
- getBlockAttributes,
74
- __experimentalGetReusableBlockTitle,
75
- } = select( blockEditorStore );
72
+ const { getBlockName, getBlockAttributes } =
73
+ select( blockEditorStore );
76
74
  const { getBlockType, getActiveBlockVariation } =
77
75
  select( blocksStore );
78
76
  const blockName = getBlockName( clientId );
@@ -80,12 +78,12 @@ export default function useBlockDisplayInformation( clientId ) {
80
78
  if ( ! blockType ) return null;
81
79
  const attributes = getBlockAttributes( clientId );
82
80
  const match = getActiveBlockVariation( blockName, attributes );
83
- const isReusable = isReusableBlock( blockType );
84
- const resusableTitle = isReusable
85
- ? __experimentalGetReusableBlockTitle( attributes.ref )
81
+ const isSynced =
82
+ isReusableBlock( blockType ) || isTemplatePart( blockType );
83
+ const syncedTitle = isSynced
84
+ ? getBlockLabel( blockType, attributes )
86
85
  : undefined;
87
- const title = resusableTitle || blockType.title;
88
- const isSynced = isReusable || isTemplatePart( blockType );
86
+ const title = syncedTitle || blockType.title;
89
87
  const positionLabel = getPositionTypeLabel( attributes );
90
88
  const blockTypeInfo = {
91
89
  isSynced,
@@ -70,17 +70,19 @@ function BlockEditAnchorControlPure( { anchor, setAttributes } ) {
70
70
  help={
71
71
  <>
72
72
  { __(
73
- 'Enter a word or two — without spaces — to make a unique web address just for this block, called an “anchor.” Then, you’ll be able to link directly to this section of your page.'
73
+ 'Enter a word or two — without spaces — to make a unique web address just for this block, called an “anchor”. Then, you’ll be able to link directly to this section of your page.'
74
74
  ) }
75
-
76
75
  { isWeb && (
77
- <ExternalLink
78
- href={ __(
79
- 'https://wordpress.org/documentation/article/page-jumps/'
80
- ) }
81
- >
82
- { __( 'Learn more about anchors' ) }
83
- </ExternalLink>
76
+ <>
77
+ { ' ' }
78
+ <ExternalLink
79
+ href={ __(
80
+ 'https://wordpress.org/documentation/article/page-jumps/'
81
+ ) }
82
+ >
83
+ { __( 'Learn more about anchors' ) }
84
+ </ExternalLink>
85
+ </>
84
86
  ) }
85
87
  </>
86
88
  }