@wordpress/block-editor 9.2.0 → 9.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (693) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -8
  3. package/build/autocompleters/block.js +3 -1
  4. package/build/autocompleters/block.js.map +1 -1
  5. package/build/components/block-actions/index.js.map +1 -1
  6. package/build/components/block-alignment-control/ui.js.map +1 -1
  7. package/build/components/block-alignment-matrix-control/index.js +3 -7
  8. package/build/components/block-alignment-matrix-control/index.js.map +1 -1
  9. package/build/components/block-breadcrumb/index.js.map +1 -1
  10. package/build/components/block-content-overlay/index.js.map +1 -1
  11. package/build/components/block-context/index.js.map +1 -1
  12. package/build/components/block-controls/hook.js.map +1 -1
  13. package/build/components/block-draggable/index.js.map +1 -1
  14. package/build/components/block-draggable/index.native.js.map +1 -1
  15. package/build/components/block-list/block-invalid-warning.native.js +54 -6
  16. package/build/components/block-list/block-invalid-warning.native.js.map +1 -1
  17. package/build/components/block-list/block-list-item.native.js.map +1 -1
  18. package/build/components/block-list/block-selection-button.native.js.map +1 -1
  19. package/build/components/block-list/block.js +2 -2
  20. package/build/components/block-list/block.js.map +1 -1
  21. package/build/components/block-list/block.native.js +2 -1
  22. package/build/components/block-list/block.native.js.map +1 -1
  23. package/build/components/block-list/index.js.map +1 -1
  24. package/build/components/block-list/index.native.js +4 -3
  25. package/build/components/block-list/index.native.js.map +1 -1
  26. package/build/components/block-list/layout.js +20 -5
  27. package/build/components/block-list/layout.js.map +1 -1
  28. package/build/components/block-list/use-block-props/index.js.map +1 -1
  29. package/build/components/block-list/use-block-props/use-block-class-names.js +5 -2
  30. package/build/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
  31. package/build/components/block-list/use-block-props/use-block-custom-class-name.js.map +1 -1
  32. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  33. package/build/components/block-list/use-in-between-inserter.js.map +1 -1
  34. package/build/components/block-list-appender/index.js.map +1 -1
  35. package/build/components/block-list-appender/index.native.js.map +1 -1
  36. package/build/components/block-lock/modal.js +35 -5
  37. package/build/components/block-lock/modal.js.map +1 -1
  38. package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  39. package/build/components/block-mover/button.js.map +1 -1
  40. package/build/components/block-mover/index.native.js.map +1 -1
  41. package/build/components/block-parent-selector/index.js.map +1 -1
  42. package/build/components/block-pattern-setup/index.js +8 -26
  43. package/build/components/block-pattern-setup/index.js.map +1 -1
  44. package/build/components/block-pattern-setup/setup-toolbar.js +3 -8
  45. package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
  46. package/build/components/block-popover/inbetween.js +1 -1
  47. package/build/components/block-popover/inbetween.js.map +1 -1
  48. package/build/components/block-popover/index.js +1 -1
  49. package/build/components/block-popover/index.js.map +1 -1
  50. package/build/components/block-preview/auto.js +21 -5
  51. package/build/components/block-preview/auto.js.map +1 -1
  52. package/build/components/block-selection-clearer/index.js.map +1 -1
  53. package/build/components/block-settings-menu/block-edit-visually-button.js +70 -0
  54. package/build/components/block-settings-menu/block-edit-visually-button.js.map +1 -0
  55. package/build/components/block-settings-menu/block-mode-toggle.js +4 -8
  56. package/build/components/block-settings-menu/block-mode-toggle.js.map +1 -1
  57. package/build/components/block-settings-menu/block-settings-dropdown.js +10 -4
  58. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  59. package/build/components/block-settings-menu/index.js +6 -2
  60. package/build/components/block-settings-menu/index.js.map +1 -1
  61. package/build/components/block-settings-menu-controls/index.js +4 -1
  62. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  63. package/build/components/block-styles/index.js +6 -3
  64. package/build/components/block-styles/index.js.map +1 -1
  65. package/build/components/block-styles/menu-items.js +3 -7
  66. package/build/components/block-styles/menu-items.js.map +1 -1
  67. package/build/components/block-styles/preview.native.js +3 -1
  68. package/build/components/block-styles/preview.native.js.map +1 -1
  69. package/build/components/block-switcher/block-transformations-menu.js.map +1 -1
  70. package/build/components/block-switcher/index.js +7 -1
  71. package/build/components/block-switcher/index.js.map +1 -1
  72. package/build/components/block-title/index.js +8 -2
  73. package/build/components/block-title/index.js.map +1 -1
  74. package/build/components/block-title/use-block-display-title.js +15 -15
  75. package/build/components/block-title/use-block-display-title.js.map +1 -1
  76. package/build/components/block-toolbar/index.native.js.map +1 -1
  77. package/build/components/block-toolbar/utils.js +5 -8
  78. package/build/components/block-toolbar/utils.js.map +1 -1
  79. package/build/components/block-tools/block-contextual-toolbar.js +1 -1
  80. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  81. package/build/components/block-tools/index.js.map +1 -1
  82. package/build/components/block-types-list/index.native.js.map +1 -1
  83. package/build/components/block-variation-transforms/index.js.map +1 -1
  84. package/build/components/border-radius-control/index.js +2 -0
  85. package/build/components/border-radius-control/index.js.map +1 -1
  86. package/build/components/color-style-selector/index.js.map +1 -1
  87. package/build/components/colors/with-colors.js +1 -1
  88. package/build/components/colors/with-colors.js.map +1 -1
  89. package/build/components/colors-gradients/control.js +45 -39
  90. package/build/components/colors-gradients/control.js.map +1 -1
  91. package/build/components/colors-gradients/dropdown.js +2 -1
  92. package/build/components/colors-gradients/dropdown.js.map +1 -1
  93. package/build/components/convert-to-group-buttons/toolbar.js.map +1 -1
  94. package/build/components/copy-handler/index.js +17 -1
  95. package/build/components/copy-handler/index.js.map +1 -1
  96. package/build/components/date-format-picker/index.js +1 -1
  97. package/build/components/date-format-picker/index.js.map +1 -1
  98. package/build/components/default-block-appender/index.js.map +1 -1
  99. package/build/components/default-block-appender/index.native.js.map +1 -1
  100. package/build/components/default-style-picker/index.js.map +1 -1
  101. package/build/components/duotone/components.js +145 -0
  102. package/build/components/duotone/components.js.map +1 -0
  103. package/build/components/duotone/index.js +40 -0
  104. package/build/components/duotone/index.js.map +1 -0
  105. package/build/components/duotone/utils.js +38 -0
  106. package/build/components/duotone/utils.js.map +1 -0
  107. package/build/components/duotone-control/index.js +17 -5
  108. package/build/components/duotone-control/index.js.map +1 -1
  109. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  110. package/build/components/iframe/index.js +19 -6
  111. package/build/components/iframe/index.js.map +1 -1
  112. package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  113. package/build/components/image-size-control/index.js +3 -1
  114. package/build/components/image-size-control/index.js.map +1 -1
  115. package/build/components/index.js +32 -0
  116. package/build/components/index.js.map +1 -1
  117. package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
  118. package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  119. package/build/components/inserter/block-types-tab.native.js.map +1 -1
  120. package/build/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
  121. package/build/components/inserter/hooks/use-insertion-point.js.map +1 -1
  122. package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
  123. package/build/components/inserter/index.js +3 -3
  124. package/build/components/inserter/index.js.map +1 -1
  125. package/build/components/inserter/index.native.js.map +1 -1
  126. package/build/components/inserter/library.js +3 -7
  127. package/build/components/inserter/library.js.map +1 -1
  128. package/build/components/inserter/menu.js.map +1 -1
  129. package/build/components/inserter/menu.native.js.map +1 -1
  130. package/build/components/inserter/no-results.native.js.map +1 -1
  131. package/build/components/inserter/quick-inserter.js.map +1 -1
  132. package/build/components/inserter/search-items.js +1 -1
  133. package/build/components/inserter/search-items.js.map +1 -1
  134. package/build/components/inserter/search-results.native.js.map +1 -1
  135. package/build/components/inspector-popover-header/index.js +56 -0
  136. package/build/components/inspector-popover-header/index.js.map +1 -0
  137. package/build/components/line-height-control/index.js.map +1 -1
  138. package/build/components/link-control/index.js +5 -5
  139. package/build/components/link-control/index.js.map +1 -1
  140. package/build/components/link-control/search-create-button.js +1 -3
  141. package/build/components/link-control/search-create-button.js.map +1 -1
  142. package/build/components/link-control/search-input.js +5 -3
  143. package/build/components/link-control/search-input.js.map +1 -1
  144. package/build/components/link-control/settings-drawer.js +3 -7
  145. package/build/components/link-control/settings-drawer.js.map +1 -1
  146. package/build/components/link-control/use-search-handler.js.map +1 -1
  147. package/build/components/list-view/block-contents.js.map +1 -1
  148. package/build/components/list-view/block-select-button.js +15 -7
  149. package/build/components/list-view/block-select-button.js.map +1 -1
  150. package/build/components/list-view/branch.js.map +1 -1
  151. package/build/components/list-view/drop-indicator.js +1 -1
  152. package/build/components/list-view/drop-indicator.js.map +1 -1
  153. package/build/components/list-view/index.js.map +1 -1
  154. package/build/components/list-view/use-block-selection.js.map +1 -1
  155. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  156. package/build/components/list-view/utils.js +1 -7
  157. package/build/components/list-view/utils.js.map +1 -1
  158. package/build/components/media-placeholder/index.js +18 -6
  159. package/build/components/media-placeholder/index.js.map +1 -1
  160. package/build/components/media-placeholder/index.native.js +4 -4
  161. package/build/components/media-placeholder/index.native.js.map +1 -1
  162. package/build/components/media-replace-flow/index.js +25 -17
  163. package/build/components/media-replace-flow/index.js.map +1 -1
  164. package/build/components/media-upload/index.native.js +1 -1
  165. package/build/components/media-upload/index.native.js.map +1 -1
  166. package/build/components/navigable-toolbar/index.js.map +1 -1
  167. package/build/components/plain-text/index.native.js.map +1 -1
  168. package/build/components/preview-options/index.js +4 -0
  169. package/build/components/preview-options/index.js.map +1 -1
  170. package/build/components/provider/use-block-sync.js +5 -3
  171. package/build/components/provider/use-block-sync.js.map +1 -1
  172. package/build/components/publish-date-time-picker/index.js +17 -16
  173. package/build/components/publish-date-time-picker/index.js.map +1 -1
  174. package/build/components/rich-text/embed-handler-picker.native.js +4 -8
  175. package/build/components/rich-text/embed-handler-picker.native.js.map +1 -1
  176. package/build/components/rich-text/index.js.map +1 -1
  177. package/build/components/rich-text/use-format-types.js.map +1 -1
  178. package/build/components/rich-text/use-input-rules.js +4 -13
  179. package/build/components/rich-text/use-input-rules.js.map +1 -1
  180. package/build/components/rich-text/use-mark-persistent.js.map +1 -1
  181. package/build/components/rich-text/use-paste-handler.js +20 -5
  182. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  183. package/build/components/skip-to-selected-block/index.js.map +1 -1
  184. package/build/components/ungroup-button/index.native.js +3 -7
  185. package/build/components/ungroup-button/index.native.js.map +1 -1
  186. package/build/components/url-input/index.js +14 -3
  187. package/build/components/url-input/index.js.map +1 -1
  188. package/build/components/url-popover/index.js +2 -1
  189. package/build/components/url-popover/index.js.map +1 -1
  190. package/build/components/use-block-display-information/index.js.map +1 -1
  191. package/build/components/use-block-drop-zone/index.js.map +1 -1
  192. package/build/components/use-block-drop-zone/index.native.js.map +1 -1
  193. package/build/components/use-display-block-controls/index.native.js.map +1 -1
  194. package/build/components/use-on-block-drop/index.js.map +1 -1
  195. package/build/components/use-on-block-drop/index.native.js.map +1 -1
  196. package/build/components/use-setting/index.js.map +1 -1
  197. package/build/components/writing-flow/use-arrow-nav.js +46 -14
  198. package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
  199. package/build/components/writing-flow/use-click-selection.js.map +1 -1
  200. package/build/components/writing-flow/use-drag-selection.js.map +1 -1
  201. package/build/components/writing-flow/use-multi-selection.js +3 -47
  202. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  203. package/build/components/writing-flow/use-select-all.js.map +1 -1
  204. package/build/components/writing-flow/use-selection-observer.js +1 -3
  205. package/build/components/writing-flow/use-selection-observer.js.map +1 -1
  206. package/build/components/writing-flow/use-tab-nav.js.map +1 -1
  207. package/build/elements/index.js +11 -3
  208. package/build/elements/index.js.map +1 -1
  209. package/build/hooks/aria-label.js +71 -0
  210. package/build/hooks/aria-label.js.map +1 -0
  211. package/build/hooks/color-panel.js.map +1 -1
  212. package/build/hooks/color-panel.native.js.map +1 -1
  213. package/build/hooks/color.js +2 -4
  214. package/build/hooks/color.js.map +1 -1
  215. package/build/hooks/duotone.js +33 -160
  216. package/build/hooks/duotone.js.map +1 -1
  217. package/build/hooks/font-family.js.map +1 -1
  218. package/build/hooks/gap.js.map +1 -1
  219. package/build/hooks/index.js +11 -7
  220. package/build/hooks/index.js.map +1 -1
  221. package/build/hooks/layout.js +74 -8
  222. package/build/hooks/layout.js.map +1 -1
  223. package/build/hooks/utils.js +5 -3
  224. package/build/hooks/utils.js.map +1 -1
  225. package/build/index.js +7 -7
  226. package/build/index.js.map +1 -1
  227. package/build/layouts/flex.js +42 -38
  228. package/build/layouts/flex.js.map +1 -1
  229. package/build/layouts/flow.js +10 -35
  230. package/build/layouts/flow.js.map +1 -1
  231. package/build/layouts/utils.js +35 -3
  232. package/build/layouts/utils.js.map +1 -1
  233. package/build/store/actions.js +24 -31
  234. package/build/store/actions.js.map +1 -1
  235. package/build/store/index.js +0 -4
  236. package/build/store/index.js.map +1 -1
  237. package/build/store/reducer.js +23 -12
  238. package/build/store/reducer.js.map +1 -1
  239. package/build/store/selectors.js +4 -4
  240. package/build/store/selectors.js.map +1 -1
  241. package/build/utils/pasting.js.map +1 -1
  242. package/build/utils/selection.js +34 -0
  243. package/build/utils/selection.js.map +1 -0
  244. package/build/utils/transform-styles/transforms/wrap.js.map +1 -1
  245. package/build-module/autocompleters/block.js +4 -1
  246. package/build-module/autocompleters/block.js.map +1 -1
  247. package/build-module/components/block-actions/index.js.map +1 -1
  248. package/build-module/components/block-alignment-control/ui.js.map +1 -1
  249. package/build-module/components/block-alignment-matrix-control/index.js +2 -5
  250. package/build-module/components/block-alignment-matrix-control/index.js.map +1 -1
  251. package/build-module/components/block-breadcrumb/index.js.map +1 -1
  252. package/build-module/components/block-content-overlay/index.js.map +1 -1
  253. package/build-module/components/block-context/index.js.map +1 -1
  254. package/build-module/components/block-controls/hook.js.map +1 -1
  255. package/build-module/components/block-draggable/index.js.map +1 -1
  256. package/build-module/components/block-draggable/index.native.js.map +1 -1
  257. package/build-module/components/block-list/block-invalid-warning.native.js +50 -6
  258. package/build-module/components/block-list/block-invalid-warning.native.js.map +1 -1
  259. package/build-module/components/block-list/block-list-item.native.js.map +1 -1
  260. package/build-module/components/block-list/block-selection-button.native.js.map +1 -1
  261. package/build-module/components/block-list/block.js +2 -2
  262. package/build-module/components/block-list/block.js.map +1 -1
  263. package/build-module/components/block-list/block.native.js +2 -1
  264. package/build-module/components/block-list/block.native.js.map +1 -1
  265. package/build-module/components/block-list/index.js.map +1 -1
  266. package/build-module/components/block-list/index.native.js +3 -1
  267. package/build-module/components/block-list/index.native.js.map +1 -1
  268. package/build-module/components/block-list/layout.js +19 -4
  269. package/build-module/components/block-list/layout.js.map +1 -1
  270. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  271. package/build-module/components/block-list/use-block-props/use-block-class-names.js +5 -2
  272. package/build-module/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
  273. package/build-module/components/block-list/use-block-props/use-block-custom-class-name.js.map +1 -1
  274. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  275. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  276. package/build-module/components/block-list-appender/index.js.map +1 -1
  277. package/build-module/components/block-list-appender/index.native.js.map +1 -1
  278. package/build-module/components/block-lock/modal.js +37 -6
  279. package/build-module/components/block-lock/modal.js.map +1 -1
  280. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  281. package/build-module/components/block-mover/button.js.map +1 -1
  282. package/build-module/components/block-mover/index.native.js.map +1 -1
  283. package/build-module/components/block-parent-selector/index.js.map +1 -1
  284. package/build-module/components/block-pattern-setup/index.js +9 -27
  285. package/build-module/components/block-pattern-setup/index.js.map +1 -1
  286. package/build-module/components/block-pattern-setup/setup-toolbar.js +3 -8
  287. package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
  288. package/build-module/components/block-popover/inbetween.js +1 -1
  289. package/build-module/components/block-popover/inbetween.js.map +1 -1
  290. package/build-module/components/block-popover/index.js +1 -1
  291. package/build-module/components/block-popover/index.js.map +1 -1
  292. package/build-module/components/block-preview/auto.js +20 -5
  293. package/build-module/components/block-preview/auto.js.map +1 -1
  294. package/build-module/components/block-selection-clearer/index.js.map +1 -1
  295. package/build-module/components/block-settings-menu/block-edit-visually-button.js +56 -0
  296. package/build-module/components/block-settings-menu/block-edit-visually-button.js.map +1 -0
  297. package/build-module/components/block-settings-menu/block-mode-toggle.js +4 -6
  298. package/build-module/components/block-settings-menu/block-mode-toggle.js.map +1 -1
  299. package/build-module/components/block-settings-menu/block-settings-dropdown.js +10 -3
  300. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  301. package/build-module/components/block-settings-menu/index.js +6 -3
  302. package/build-module/components/block-settings-menu/index.js.map +1 -1
  303. package/build-module/components/block-settings-menu-controls/index.js +5 -2
  304. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  305. package/build-module/components/block-styles/index.js +5 -2
  306. package/build-module/components/block-styles/index.js.map +1 -1
  307. package/build-module/components/block-styles/menu-items.js +3 -5
  308. package/build-module/components/block-styles/menu-items.js.map +1 -1
  309. package/build-module/components/block-styles/preview.native.js +3 -2
  310. package/build-module/components/block-styles/preview.native.js.map +1 -1
  311. package/build-module/components/block-switcher/block-transformations-menu.js.map +1 -1
  312. package/build-module/components/block-switcher/index.js +7 -1
  313. package/build-module/components/block-switcher/index.js.map +1 -1
  314. package/build-module/components/block-title/index.js +8 -2
  315. package/build-module/components/block-title/index.js.map +1 -1
  316. package/build-module/components/block-title/use-block-display-title.js +15 -14
  317. package/build-module/components/block-title/use-block-display-title.js.map +1 -1
  318. package/build-module/components/block-toolbar/index.native.js.map +1 -1
  319. package/build-module/components/block-toolbar/utils.js +3 -5
  320. package/build-module/components/block-toolbar/utils.js.map +1 -1
  321. package/build-module/components/block-tools/block-contextual-toolbar.js +1 -1
  322. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  323. package/build-module/components/block-tools/index.js.map +1 -1
  324. package/build-module/components/block-types-list/index.native.js.map +1 -1
  325. package/build-module/components/block-variation-transforms/index.js.map +1 -1
  326. package/build-module/components/border-radius-control/index.js +2 -0
  327. package/build-module/components/border-radius-control/index.js.map +1 -1
  328. package/build-module/components/color-style-selector/index.js.map +1 -1
  329. package/build-module/components/colors/with-colors.js +2 -2
  330. package/build-module/components/colors/with-colors.js.map +1 -1
  331. package/build-module/components/colors-gradients/control.js +46 -40
  332. package/build-module/components/colors-gradients/control.js.map +1 -1
  333. package/build-module/components/colors-gradients/dropdown.js +2 -1
  334. package/build-module/components/colors-gradients/dropdown.js.map +1 -1
  335. package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -1
  336. package/build-module/components/copy-handler/index.js +18 -2
  337. package/build-module/components/copy-handler/index.js.map +1 -1
  338. package/build-module/components/date-format-picker/index.js +1 -1
  339. package/build-module/components/date-format-picker/index.js.map +1 -1
  340. package/build-module/components/default-block-appender/index.js.map +1 -1
  341. package/build-module/components/default-block-appender/index.native.js.map +1 -1
  342. package/build-module/components/default-style-picker/index.js.map +1 -1
  343. package/build-module/components/duotone/components.js +130 -0
  344. package/build-module/components/duotone/components.js.map +1 -0
  345. package/build-module/components/duotone/index.js +3 -0
  346. package/build-module/components/duotone/index.js.map +1 -0
  347. package/build-module/components/duotone/utils.js +30 -0
  348. package/build-module/components/duotone/utils.js.map +1 -0
  349. package/build-module/components/duotone-control/index.js +18 -6
  350. package/build-module/components/duotone-control/index.js.map +1 -1
  351. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  352. package/build-module/components/iframe/index.js +19 -6
  353. package/build-module/components/iframe/index.js.map +1 -1
  354. package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  355. package/build-module/components/image-size-control/index.js +4 -1
  356. package/build-module/components/image-size-control/index.js.map +1 -1
  357. package/build-module/components/index.js +3 -0
  358. package/build-module/components/index.js.map +1 -1
  359. package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
  360. package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  361. package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
  362. package/build-module/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
  363. package/build-module/components/inserter/hooks/use-insertion-point.js.map +1 -1
  364. package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
  365. package/build-module/components/inserter/index.js +3 -2
  366. package/build-module/components/inserter/index.js.map +1 -1
  367. package/build-module/components/inserter/index.native.js.map +1 -1
  368. package/build-module/components/inserter/library.js +2 -5
  369. package/build-module/components/inserter/library.js.map +1 -1
  370. package/build-module/components/inserter/menu.js.map +1 -1
  371. package/build-module/components/inserter/menu.native.js.map +1 -1
  372. package/build-module/components/inserter/no-results.native.js.map +1 -1
  373. package/build-module/components/inserter/quick-inserter.js.map +1 -1
  374. package/build-module/components/inserter/search-items.js +2 -2
  375. package/build-module/components/inserter/search-items.js.map +1 -1
  376. package/build-module/components/inserter/search-results.native.js.map +1 -1
  377. package/build-module/components/inspector-popover-header/index.js +46 -0
  378. package/build-module/components/inspector-popover-header/index.js.map +1 -0
  379. package/build-module/components/line-height-control/index.js.map +1 -1
  380. package/build-module/components/link-control/index.js +3 -2
  381. package/build-module/components/link-control/index.js.map +1 -1
  382. package/build-module/components/link-control/search-create-button.js +1 -2
  383. package/build-module/components/link-control/search-create-button.js.map +1 -1
  384. package/build-module/components/link-control/search-input.js +3 -1
  385. package/build-module/components/link-control/search-input.js.map +1 -1
  386. package/build-module/components/link-control/settings-drawer.js +2 -5
  387. package/build-module/components/link-control/settings-drawer.js.map +1 -1
  388. package/build-module/components/link-control/use-search-handler.js.map +1 -1
  389. package/build-module/components/list-view/block-contents.js.map +1 -1
  390. package/build-module/components/list-view/block-select-button.js +16 -8
  391. package/build-module/components/list-view/block-select-button.js.map +1 -1
  392. package/build-module/components/list-view/branch.js.map +1 -1
  393. package/build-module/components/list-view/drop-indicator.js +1 -1
  394. package/build-module/components/list-view/drop-indicator.js.map +1 -1
  395. package/build-module/components/list-view/index.js.map +1 -1
  396. package/build-module/components/list-view/use-block-selection.js.map +1 -1
  397. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  398. package/build-module/components/list-view/utils.js +1 -6
  399. package/build-module/components/list-view/utils.js.map +1 -1
  400. package/build-module/components/media-placeholder/index.js +16 -3
  401. package/build-module/components/media-placeholder/index.js.map +1 -1
  402. package/build-module/components/media-placeholder/index.native.js +5 -3
  403. package/build-module/components/media-placeholder/index.native.js.map +1 -1
  404. package/build-module/components/media-replace-flow/index.js +27 -18
  405. package/build-module/components/media-replace-flow/index.js.map +1 -1
  406. package/build-module/components/media-upload/index.native.js +1 -1
  407. package/build-module/components/media-upload/index.native.js.map +1 -1
  408. package/build-module/components/navigable-toolbar/index.js.map +1 -1
  409. package/build-module/components/plain-text/index.native.js.map +1 -1
  410. package/build-module/components/preview-options/index.js +4 -0
  411. package/build-module/components/preview-options/index.js.map +1 -1
  412. package/build-module/components/provider/use-block-sync.js +4 -1
  413. package/build-module/components/provider/use-block-sync.js.map +1 -1
  414. package/build-module/components/publish-date-time-picker/index.js +16 -16
  415. package/build-module/components/publish-date-time-picker/index.js.map +1 -1
  416. package/build-module/components/rich-text/embed-handler-picker.native.js +3 -5
  417. package/build-module/components/rich-text/embed-handler-picker.native.js.map +1 -1
  418. package/build-module/components/rich-text/index.js.map +1 -1
  419. package/build-module/components/rich-text/use-format-types.js.map +1 -1
  420. package/build-module/components/rich-text/use-input-rules.js +3 -11
  421. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  422. package/build-module/components/rich-text/use-mark-persistent.js.map +1 -1
  423. package/build-module/components/rich-text/use-paste-handler.js +20 -5
  424. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  425. package/build-module/components/skip-to-selected-block/index.js.map +1 -1
  426. package/build-module/components/ungroup-button/index.native.js +3 -5
  427. package/build-module/components/ungroup-button/index.native.js.map +1 -1
  428. package/build-module/components/url-input/index.js +11 -1
  429. package/build-module/components/url-input/index.js.map +1 -1
  430. package/build-module/components/url-popover/index.js +2 -1
  431. package/build-module/components/url-popover/index.js.map +1 -1
  432. package/build-module/components/use-block-display-information/index.js.map +1 -1
  433. package/build-module/components/use-block-drop-zone/index.js.map +1 -1
  434. package/build-module/components/use-block-drop-zone/index.native.js.map +1 -1
  435. package/build-module/components/use-display-block-controls/index.native.js.map +1 -1
  436. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  437. package/build-module/components/use-on-block-drop/index.native.js.map +1 -1
  438. package/build-module/components/use-setting/index.js.map +1 -1
  439. package/build-module/components/writing-flow/use-arrow-nav.js +47 -14
  440. package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
  441. package/build-module/components/writing-flow/use-click-selection.js.map +1 -1
  442. package/build-module/components/writing-flow/use-drag-selection.js.map +1 -1
  443. package/build-module/components/writing-flow/use-multi-selection.js +3 -45
  444. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  445. package/build-module/components/writing-flow/use-select-all.js.map +1 -1
  446. package/build-module/components/writing-flow/use-selection-observer.js +1 -3
  447. package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
  448. package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
  449. package/build-module/elements/index.js +7 -1
  450. package/build-module/elements/index.js.map +1 -1
  451. package/build-module/hooks/aria-label.js +59 -0
  452. package/build-module/hooks/aria-label.js.map +1 -0
  453. package/build-module/hooks/color-panel.js.map +1 -1
  454. package/build-module/hooks/color-panel.native.js.map +1 -1
  455. package/build-module/hooks/color.js +2 -3
  456. package/build-module/hooks/color.js.map +1 -1
  457. package/build-module/hooks/duotone.js +22 -140
  458. package/build-module/hooks/duotone.js.map +1 -1
  459. package/build-module/hooks/font-family.js.map +1 -1
  460. package/build-module/hooks/gap.js.map +1 -1
  461. package/build-module/hooks/index.js +2 -1
  462. package/build-module/hooks/index.js.map +1 -1
  463. package/build-module/hooks/layout.js +76 -10
  464. package/build-module/hooks/layout.js.map +1 -1
  465. package/build-module/hooks/utils.js +5 -2
  466. package/build-module/hooks/utils.js.map +1 -1
  467. package/build-module/index.js +1 -1
  468. package/build-module/index.js.map +1 -1
  469. package/build-module/layouts/flex.js +43 -35
  470. package/build-module/layouts/flex.js.map +1 -1
  471. package/build-module/layouts/flow.js +11 -36
  472. package/build-module/layouts/flow.js.map +1 -1
  473. package/build-module/layouts/utils.js +33 -3
  474. package/build-module/layouts/utils.js.map +1 -1
  475. package/build-module/store/actions.js +14 -20
  476. package/build-module/store/actions.js.map +1 -1
  477. package/build-module/store/index.js +0 -4
  478. package/build-module/store/index.js.map +1 -1
  479. package/build-module/store/reducer.js +23 -11
  480. package/build-module/store/reducer.js.map +1 -1
  481. package/build-module/store/selectors.js +5 -5
  482. package/build-module/store/selectors.js.map +1 -1
  483. package/build-module/utils/pasting.js.map +1 -1
  484. package/build-module/utils/selection.js +24 -0
  485. package/build-module/utils/selection.js.map +1 -0
  486. package/build-module/utils/transform-styles/transforms/wrap.js.map +1 -1
  487. package/build-style/style-rtl.css +57 -34
  488. package/build-style/style.css +57 -34
  489. package/package.json +28 -28
  490. package/src/autocompleters/block.js +2 -1
  491. package/src/components/block-actions/index.js +2 -3
  492. package/src/components/block-alignment-control/ui.js +4 -6
  493. package/src/components/block-alignment-matrix-control/index.js +2 -4
  494. package/src/components/block-breadcrumb/index.js +2 -5
  495. package/src/components/block-compare/test/block-view.js +2 -1
  496. package/src/components/block-content-overlay/index.js +2 -5
  497. package/src/components/block-context/index.js +4 -4
  498. package/src/components/block-controls/hook.js +2 -3
  499. package/src/components/block-draggable/index.js +6 -13
  500. package/src/components/block-draggable/index.native.js +6 -14
  501. package/src/components/block-draggable/test/helpers.native.js +3 -3
  502. package/src/components/block-draggable/test/index.native.js +12 -15
  503. package/src/components/block-edit/test/edit.js +2 -1
  504. package/src/components/block-list/block-invalid-warning.native.js +42 -7
  505. package/src/components/block-list/block-list-item.native.js +4 -12
  506. package/src/components/block-list/block-selection-button.native.js +2 -3
  507. package/src/components/block-list/block.js +10 -12
  508. package/src/components/block-list/block.native.js +11 -15
  509. package/src/components/block-list/index.js +2 -3
  510. package/src/components/block-list/index.native.js +13 -22
  511. package/src/components/block-list/layout.js +15 -3
  512. package/src/components/block-list/style.scss +2 -2
  513. package/src/components/block-list/test/block-list-context.native.js +8 -16
  514. package/src/components/block-list/use-block-props/index.js +6 -3
  515. package/src/components/block-list/use-block-props/use-block-class-names.js +5 -1
  516. package/src/components/block-list/use-block-props/use-block-custom-class-name.js +2 -3
  517. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +2 -3
  518. package/src/components/block-list/use-in-between-inserter.js +2 -3
  519. package/src/components/block-list-appender/index.js +2 -5
  520. package/src/components/block-list-appender/index.native.js +2 -3
  521. package/src/components/block-lock/modal.js +42 -4
  522. package/src/components/block-lock/style.scss +10 -0
  523. package/src/components/block-mobile-toolbar/block-actions-menu.native.js +4 -6
  524. package/src/components/block-mover/button.js +2 -3
  525. package/src/components/block-mover/index.native.js +4 -6
  526. package/src/components/block-parent-selector/index.js +2 -3
  527. package/src/components/block-pattern-setup/index.js +5 -27
  528. package/src/components/block-pattern-setup/setup-toolbar.js +2 -9
  529. package/src/components/block-pattern-setup/style.scss +4 -2
  530. package/src/components/block-popover/inbetween.js +1 -1
  531. package/src/components/block-popover/index.js +1 -1
  532. package/src/components/block-preview/auto.js +21 -11
  533. package/src/components/block-selection-clearer/index.js +2 -3
  534. package/src/components/block-settings-menu/block-edit-visually-button.js +52 -0
  535. package/src/components/block-settings-menu/block-mode-toggle.js +5 -8
  536. package/src/components/block-settings-menu/block-settings-dropdown.js +13 -9
  537. package/src/components/block-settings-menu/index.js +15 -11
  538. package/src/components/block-settings-menu-controls/index.js +3 -2
  539. package/src/components/block-styles/index.js +3 -1
  540. package/src/components/block-styles/menu-items.js +2 -5
  541. package/src/components/block-styles/preview.native.js +3 -2
  542. package/src/components/block-switcher/block-transformations-menu.js +2 -4
  543. package/src/components/block-switcher/index.js +7 -1
  544. package/src/components/block-title/index.js +3 -2
  545. package/src/components/block-title/use-block-display-title.js +20 -12
  546. package/src/components/block-toolbar/index.native.js +2 -5
  547. package/src/components/block-toolbar/utils.js +3 -11
  548. package/src/components/block-tools/block-contextual-toolbar.js +5 -6
  549. package/src/components/block-tools/index.js +2 -3
  550. package/src/components/block-types-list/index.native.js +2 -4
  551. package/src/components/block-variation-transforms/index.js +4 -6
  552. package/src/components/border-radius-control/index.js +2 -0
  553. package/src/components/color-palette/test/control.js +2 -1
  554. package/src/components/color-style-selector/index.js +27 -28
  555. package/src/components/colors/test/with-colors.js +14 -14
  556. package/src/components/colors/with-colors.js +10 -14
  557. package/src/components/colors-gradients/control.js +77 -65
  558. package/src/components/colors-gradients/dropdown.js +22 -16
  559. package/src/components/colors-gradients/style.scss +4 -0
  560. package/src/components/colors-gradients/test/control.js +25 -32
  561. package/src/components/convert-to-group-buttons/toolbar.js +2 -6
  562. package/src/components/copy-handler/README.md +7 -2
  563. package/src/components/copy-handler/index.js +26 -6
  564. package/src/components/date-format-picker/index.js +1 -0
  565. package/src/components/default-block-appender/index.js +4 -6
  566. package/src/components/default-block-appender/index.native.js +4 -9
  567. package/src/components/default-style-picker/index.js +20 -21
  568. package/src/components/duotone/components.js +133 -0
  569. package/src/components/duotone/index.js +7 -0
  570. package/src/components/duotone/utils.js +25 -0
  571. package/src/components/duotone-control/index.js +12 -7
  572. package/src/components/duotone-control/style.scss +5 -0
  573. package/src/components/font-sizes/with-font-sizes.js +2 -3
  574. package/src/components/iframe/index.js +25 -6
  575. package/src/components/image-editor/aspect-ratio-dropdown.js +2 -6
  576. package/src/components/image-size-control/index.js +4 -7
  577. package/src/components/index.js +3 -0
  578. package/src/components/inner-blocks/use-inner-block-template-sync.js +2 -3
  579. package/src/components/inner-blocks/use-nested-settings-update.js +6 -9
  580. package/src/components/inserter/block-types-tab.native.js +2 -3
  581. package/src/components/inserter/hooks/use-block-type-impressions.native.js +2 -3
  582. package/src/components/inserter/hooks/use-insertion-point.js +3 -2
  583. package/src/components/inserter/hooks/use-patterns-state.js +4 -5
  584. package/src/components/inserter/index.js +7 -11
  585. package/src/components/inserter/index.native.js +6 -11
  586. package/src/components/inserter/library.js +2 -5
  587. package/src/components/inserter/menu.js +14 -19
  588. package/src/components/inserter/menu.native.js +8 -6
  589. package/src/components/inserter/no-results.native.js +2 -1
  590. package/src/components/inserter/quick-inserter.js +2 -3
  591. package/src/components/inserter/search-items.js +6 -6
  592. package/src/components/inserter/search-results.native.js +4 -6
  593. package/src/components/inserter/style.scss +1 -1
  594. package/src/components/inspector-popover-header/README.md +76 -0
  595. package/src/components/inspector-popover-header/index.js +56 -0
  596. package/src/components/inspector-popover-header/style.scss +16 -0
  597. package/src/components/line-height-control/index.js +1 -2
  598. package/src/components/link-control/index.js +5 -4
  599. package/src/components/link-control/search-create-button.js +4 -2
  600. package/src/components/link-control/search-input.js +3 -1
  601. package/src/components/link-control/settings-drawer.js +2 -5
  602. package/src/components/link-control/test/fixtures/index.js +5 -7
  603. package/src/components/link-control/test/index.js +85 -106
  604. package/src/components/link-control/use-search-handler.js +2 -2
  605. package/src/components/list-view/block-contents.js +2 -4
  606. package/src/components/list-view/block-select-button.js +29 -14
  607. package/src/components/list-view/branch.js +22 -23
  608. package/src/components/list-view/drop-indicator.js +1 -1
  609. package/src/components/list-view/index.js +4 -8
  610. package/src/components/list-view/style.scss +18 -4
  611. package/src/components/list-view/use-block-selection.js +5 -5
  612. package/src/components/list-view/use-list-view-drop-zone.js +2 -1
  613. package/src/components/list-view/utils.js +1 -6
  614. package/src/components/media-placeholder/index.js +22 -1
  615. package/src/components/media-placeholder/index.native.js +9 -5
  616. package/src/components/media-replace-flow/index.js +78 -56
  617. package/src/components/media-replace-flow/test/index.js +14 -4
  618. package/src/components/media-upload/README.md +8 -0
  619. package/src/components/media-upload/index.native.js +1 -1
  620. package/src/components/navigable-toolbar/index.js +1 -2
  621. package/src/components/panel-color-settings/test/index.js +2 -1
  622. package/src/components/plain-text/index.native.js +2 -6
  623. package/src/components/preview-options/index.js +4 -0
  624. package/src/components/provider/use-block-sync.js +5 -2
  625. package/src/components/publish-date-time-picker/README.md +1 -1
  626. package/src/components/publish-date-time-picker/index.js +18 -27
  627. package/src/components/responsive-block-control/README.md +3 -1
  628. package/src/components/responsive-block-control/test/index.js +4 -4
  629. package/src/components/rich-text/embed-handler-picker.native.js +2 -5
  630. package/src/components/rich-text/index.js +7 -4
  631. package/src/components/rich-text/use-format-types.js +16 -16
  632. package/src/components/rich-text/use-input-rules.js +6 -15
  633. package/src/components/rich-text/use-mark-persistent.js +2 -3
  634. package/src/components/rich-text/use-paste-handler.js +17 -5
  635. package/src/components/skip-to-selected-block/index.js +2 -3
  636. package/src/components/ungroup-button/index.native.js +4 -8
  637. package/src/components/url-input/index.js +21 -20
  638. package/src/components/url-popover/index.js +1 -0
  639. package/src/components/url-popover/test/__snapshots__/index.js.snap +3 -0
  640. package/src/components/use-block-display-information/index.js +4 -6
  641. package/src/components/use-block-drop-zone/index.js +2 -3
  642. package/src/components/use-block-drop-zone/index.native.js +2 -4
  643. package/src/components/use-block-drop-zone/test/index.js +22 -23
  644. package/src/components/use-display-block-controls/index.native.js +2 -3
  645. package/src/components/use-no-recursive-renders/test/use-no-recursive-renders.js +2 -3
  646. package/src/components/use-on-block-drop/index.js +2 -5
  647. package/src/components/use-on-block-drop/index.native.js +4 -8
  648. package/src/components/use-setting/index.js +8 -6
  649. package/src/components/writing-flow/test/index.js +22 -4
  650. package/src/components/writing-flow/use-arrow-nav.js +54 -11
  651. package/src/components/writing-flow/use-click-selection.js +2 -5
  652. package/src/components/writing-flow/use-drag-selection.js +6 -9
  653. package/src/components/writing-flow/use-multi-selection.js +1 -50
  654. package/src/components/writing-flow/use-select-all.js +2 -5
  655. package/src/components/writing-flow/use-selection-observer.js +6 -9
  656. package/src/components/writing-flow/use-tab-nav.js +2 -5
  657. package/src/elements/index.js +8 -1
  658. package/src/elements/test/index.js +18 -0
  659. package/src/hooks/aria-label.js +67 -0
  660. package/src/hooks/color-panel.js +4 -4
  661. package/src/hooks/color-panel.native.js +2 -2
  662. package/src/hooks/color.js +12 -5
  663. package/src/hooks/duotone.js +18 -139
  664. package/src/hooks/font-family.js +4 -2
  665. package/src/hooks/gap.js +2 -3
  666. package/src/hooks/index.js +2 -1
  667. package/src/hooks/layout.js +102 -15
  668. package/src/hooks/test/align.js +2 -1
  669. package/src/hooks/test/generated-class-name.js +2 -5
  670. package/src/hooks/test/utils.js +2 -5
  671. package/src/hooks/utils.js +7 -3
  672. package/src/index.js +1 -1
  673. package/src/layouts/flex.js +49 -43
  674. package/src/layouts/flow.js +14 -35
  675. package/src/layouts/test/flex.js +21 -0
  676. package/src/layouts/test/flow.js +21 -0
  677. package/src/layouts/test/utils.js +138 -0
  678. package/src/layouts/utils.js +44 -3
  679. package/src/store/actions.js +763 -733
  680. package/src/store/index.js +0 -4
  681. package/src/store/reducer.js +208 -184
  682. package/src/store/selectors.js +57 -58
  683. package/src/store/test/actions.js +2 -1
  684. package/src/store/test/reducer.js +140 -10
  685. package/src/store/test/selectors.js +20 -27
  686. package/src/style.scss +1 -1
  687. package/src/utils/pasting.js +3 -3
  688. package/src/utils/selection.js +26 -0
  689. package/src/utils/test/selection.js +39 -0
  690. package/src/utils/transform-styles/transforms/wrap.js +30 -28
  691. package/tsconfig.json +2 -1
  692. package/tsconfig.tsbuildinfo +1 -1
  693. package/src/components/publish-date-time-picker/style.scss +0 -20
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { castArray, findKey, first, isObject, last, some } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -26,6 +21,13 @@ import deprecated from '@wordpress/deprecated';
26
21
  * Internal dependencies
27
22
  */
28
23
  import { mapRichTextSettings } from './utils';
24
+ import {
25
+ retrieveSelectedAttribute,
26
+ START_OF_SELECTED_AREA,
27
+ } from '../utils/selection';
28
+
29
+ const castArray = ( maybeArray ) =>
30
+ Array.isArray( maybeArray ) ? maybeArray : [ maybeArray ];
29
31
 
30
32
  /**
31
33
  * Action which will insert a default block insert action if there
@@ -33,24 +35,26 @@ import { mapRichTextSettings } from './utils';
33
35
  * in actions which may result in no blocks remaining in the editor (removal,
34
36
  * replacement, etc).
35
37
  */
36
- const ensureDefaultBlock = () => ( { select, dispatch } ) => {
37
- // To avoid a focus loss when removing the last block, assure there is
38
- // always a default block if the last of the blocks have been removed.
39
- const count = select.getBlockCount();
40
- if ( count > 0 ) {
41
- return;
42
- }
38
+ const ensureDefaultBlock =
39
+ () =>
40
+ ( { select, dispatch } ) => {
41
+ // To avoid a focus loss when removing the last block, assure there is
42
+ // always a default block if the last of the blocks have been removed.
43
+ const count = select.getBlockCount();
44
+ if ( count > 0 ) {
45
+ return;
46
+ }
43
47
 
44
- // If there's an custom appender, don't insert default block.
45
- // We have to remember to manually move the focus elsewhere to
46
- // prevent it from being lost though.
47
- const { __unstableHasCustomAppender } = select.getSettings();
48
- if ( __unstableHasCustomAppender ) {
49
- return;
50
- }
48
+ // If there's an custom appender, don't insert default block.
49
+ // We have to remember to manually move the focus elsewhere to
50
+ // prevent it from being lost though.
51
+ const { __unstableHasCustomAppender } = select.getSettings();
52
+ if ( __unstableHasCustomAppender ) {
53
+ return;
54
+ }
51
55
 
52
- dispatch.insertDefaultBlock();
53
- };
56
+ dispatch.insertDefaultBlock();
57
+ };
54
58
 
55
59
  /**
56
60
  * Action that resets blocks state to the specified array of blocks, taking precedence
@@ -58,10 +62,12 @@ const ensureDefaultBlock = () => ( { select, dispatch } ) => {
58
62
  *
59
63
  * @param {Array} blocks Array of blocks.
60
64
  */
61
- export const resetBlocks = ( blocks ) => ( { dispatch } ) => {
62
- dispatch( { type: 'RESET_BLOCKS', blocks } );
63
- dispatch( validateBlocksToTemplate( blocks ) );
64
- };
65
+ export const resetBlocks =
66
+ ( blocks ) =>
67
+ ( { dispatch } ) => {
68
+ dispatch( { type: 'RESET_BLOCKS', blocks } );
69
+ dispatch( validateBlocksToTemplate( blocks ) );
70
+ };
65
71
 
66
72
  /**
67
73
  * Block validity is a function of blocks state (at the point of a
@@ -71,28 +77,27 @@ export const resetBlocks = ( blocks ) => ( { dispatch } ) => {
71
77
  *
72
78
  * @param {Array} blocks Array of blocks.
73
79
  */
74
- export const validateBlocksToTemplate = ( blocks ) => ( {
75
- select,
76
- dispatch,
77
- } ) => {
78
- const template = select.getTemplate();
79
- const templateLock = select.getTemplateLock();
80
-
81
- // Unlocked templates are considered always valid because they act
82
- // as default values only.
83
- const isBlocksValidToTemplate =
84
- ! template ||
85
- templateLock !== 'all' ||
86
- doBlocksMatchTemplate( blocks, template );
87
-
88
- // Update if validity has changed.
89
- const isValidTemplate = select.isValidTemplate();
90
-
91
- if ( isBlocksValidToTemplate !== isValidTemplate ) {
92
- dispatch.setTemplateValidity( isBlocksValidToTemplate );
93
- return isBlocksValidToTemplate;
94
- }
95
- };
80
+ export const validateBlocksToTemplate =
81
+ ( blocks ) =>
82
+ ( { select, dispatch } ) => {
83
+ const template = select.getTemplate();
84
+ const templateLock = select.getTemplateLock();
85
+
86
+ // Unlocked templates are considered always valid because they act
87
+ // as default values only.
88
+ const isBlocksValidToTemplate =
89
+ ! template ||
90
+ templateLock !== 'all' ||
91
+ doBlocksMatchTemplate( blocks, template );
92
+
93
+ // Update if validity has changed.
94
+ const isValidTemplate = select.isValidTemplate();
95
+
96
+ if ( isBlocksValidToTemplate !== isValidTemplate ) {
97
+ dispatch.setTemplateValidity( isBlocksValidToTemplate );
98
+ return isBlocksValidToTemplate;
99
+ }
100
+ };
96
101
 
97
102
  /**
98
103
  * A block selection object.
@@ -228,12 +233,15 @@ export function selectBlock( clientId, initialPosition = 0 ) {
228
233
  *
229
234
  * @param {string} clientId Block client ID.
230
235
  */
231
- export const selectPreviousBlock = ( clientId ) => ( { select, dispatch } ) => {
232
- const previousBlockClientId = select.getPreviousBlockClientId( clientId );
233
- if ( previousBlockClientId ) {
234
- dispatch.selectBlock( previousBlockClientId, -1 );
235
- }
236
- };
236
+ export const selectPreviousBlock =
237
+ ( clientId ) =>
238
+ ( { select, dispatch } ) => {
239
+ const previousBlockClientId =
240
+ select.getPreviousBlockClientId( clientId );
241
+ if ( previousBlockClientId ) {
242
+ dispatch.selectBlock( previousBlockClientId, -1 );
243
+ }
244
+ };
237
245
 
238
246
  /**
239
247
  * Yields action objects used in signalling that the block following the given
@@ -241,12 +249,14 @@ export const selectPreviousBlock = ( clientId ) => ( { select, dispatch } ) => {
241
249
  *
242
250
  * @param {string} clientId Block client ID.
243
251
  */
244
- export const selectNextBlock = ( clientId ) => ( { select, dispatch } ) => {
245
- const nextBlockClientId = select.getNextBlockClientId( clientId );
246
- if ( nextBlockClientId ) {
247
- dispatch.selectBlock( nextBlockClientId );
248
- }
249
- };
252
+ export const selectNextBlock =
253
+ ( clientId ) =>
254
+ ( { select, dispatch } ) => {
255
+ const nextBlockClientId = select.getNextBlockClientId( clientId );
256
+ if ( nextBlockClientId ) {
257
+ dispatch.selectBlock( nextBlockClientId );
258
+ }
259
+ };
250
260
 
251
261
  /**
252
262
  * Action that starts block multi-selection.
@@ -277,37 +287,35 @@ export function stopMultiSelect() {
277
287
  * @param {string} end Last block of the multiselection.
278
288
  * @param {number|null} __experimentalInitialPosition Optional initial position. Pass as null to skip focus within editor canvas.
279
289
  */
280
- export const multiSelect = (
281
- start,
282
- end,
283
- __experimentalInitialPosition = 0
284
- ) => ( { select, dispatch } ) => {
285
- const startBlockRootClientId = select.getBlockRootClientId( start );
286
- const endBlockRootClientId = select.getBlockRootClientId( end );
287
-
288
- // Only allow block multi-selections at the same level.
289
- if ( startBlockRootClientId !== endBlockRootClientId ) {
290
- return;
291
- }
290
+ export const multiSelect =
291
+ ( start, end, __experimentalInitialPosition = 0 ) =>
292
+ ( { select, dispatch } ) => {
293
+ const startBlockRootClientId = select.getBlockRootClientId( start );
294
+ const endBlockRootClientId = select.getBlockRootClientId( end );
295
+
296
+ // Only allow block multi-selections at the same level.
297
+ if ( startBlockRootClientId !== endBlockRootClientId ) {
298
+ return;
299
+ }
292
300
 
293
- dispatch( {
294
- type: 'MULTI_SELECT',
295
- start,
296
- end,
297
- initialPosition: __experimentalInitialPosition,
298
- } );
301
+ dispatch( {
302
+ type: 'MULTI_SELECT',
303
+ start,
304
+ end,
305
+ initialPosition: __experimentalInitialPosition,
306
+ } );
299
307
 
300
- const blockCount = select.getSelectedBlockCount();
308
+ const blockCount = select.getSelectedBlockCount();
301
309
 
302
- speak(
303
- sprintf(
304
- /* translators: %s: number of selected blocks */
305
- _n( '%s block selected.', '%s blocks selected.', blockCount ),
306
- blockCount
307
- ),
308
- 'assertive'
309
- );
310
- };
310
+ speak(
311
+ sprintf(
312
+ /* translators: %s: number of selected blocks */
313
+ _n( '%s block selected.', '%s blocks selected.', blockCount ),
314
+ blockCount
315
+ ),
316
+ 'assertive'
317
+ );
318
+ };
311
319
 
312
320
  /**
313
321
  * Action that clears the block selection.
@@ -377,42 +385,38 @@ function getBlocksWithDefaultStylesApplied( blocks, blockEditorSettings ) {
377
385
  *
378
386
  * @return {Object} Action object.
379
387
  */
380
- export const replaceBlocks = (
381
- clientIds,
382
- blocks,
383
- indexToSelect,
384
- initialPosition = 0,
385
- meta
386
- ) => ( { select, dispatch } ) => {
387
- /* eslint-enable jsdoc/valid-types */
388
- clientIds = castArray( clientIds );
389
- blocks = getBlocksWithDefaultStylesApplied(
390
- castArray( blocks ),
391
- select.getSettings()
392
- );
393
- const rootClientId = select.getBlockRootClientId( first( clientIds ) );
394
- // Replace is valid if the new blocks can be inserted in the root block.
395
- for ( let index = 0; index < blocks.length; index++ ) {
396
- const block = blocks[ index ];
397
- const canInsertBlock = select.canInsertBlockType(
398
- block.name,
399
- rootClientId
388
+ export const replaceBlocks =
389
+ ( clientIds, blocks, indexToSelect, initialPosition = 0, meta ) =>
390
+ ( { select, dispatch } ) => {
391
+ /* eslint-enable jsdoc/valid-types */
392
+ clientIds = castArray( clientIds );
393
+ blocks = getBlocksWithDefaultStylesApplied(
394
+ castArray( blocks ),
395
+ select.getSettings()
400
396
  );
401
- if ( ! canInsertBlock ) {
402
- return;
397
+ const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
398
+ // Replace is valid if the new blocks can be inserted in the root block.
399
+ for ( let index = 0; index < blocks.length; index++ ) {
400
+ const block = blocks[ index ];
401
+ const canInsertBlock = select.canInsertBlockType(
402
+ block.name,
403
+ rootClientId
404
+ );
405
+ if ( ! canInsertBlock ) {
406
+ return;
407
+ }
403
408
  }
404
- }
405
- dispatch( {
406
- type: 'REPLACE_BLOCKS',
407
- clientIds,
408
- blocks,
409
- time: Date.now(),
410
- indexToSelect,
411
- initialPosition,
412
- meta,
413
- } );
414
- dispatch( ensureDefaultBlock() );
415
- };
409
+ dispatch( {
410
+ type: 'REPLACE_BLOCKS',
411
+ clientIds,
412
+ blocks,
413
+ time: Date.now(),
414
+ indexToSelect,
415
+ initialPosition,
416
+ meta,
417
+ } );
418
+ dispatch( ensureDefaultBlock() );
419
+ };
416
420
 
417
421
  /**
418
422
  * Action that replaces a single block with one or more replacement blocks.
@@ -434,18 +438,18 @@ export function replaceBlock( clientId, block ) {
434
438
  *
435
439
  * @return {Function} Action creator.
436
440
  */
437
- const createOnMove = ( type ) => ( clientIds, rootClientId ) => ( {
438
- select,
439
- dispatch,
440
- } ) => {
441
- // If one of the blocks is locked or the parent is locked, we cannot move any block.
442
- const canMoveBlocks = select.canMoveBlocks( clientIds, rootClientId );
443
- if ( ! canMoveBlocks ) {
444
- return;
445
- }
441
+ const createOnMove =
442
+ ( type ) =>
443
+ ( clientIds, rootClientId ) =>
444
+ ( { select, dispatch } ) => {
445
+ // If one of the blocks is locked or the parent is locked, we cannot move any block.
446
+ const canMoveBlocks = select.canMoveBlocks( clientIds, rootClientId );
447
+ if ( ! canMoveBlocks ) {
448
+ return;
449
+ }
446
450
 
447
- dispatch( { type, clientIds: castArray( clientIds ), rootClientId } );
448
- };
451
+ dispatch( { type, clientIds: castArray( clientIds ), rootClientId } );
452
+ };
449
453
 
450
454
  export const moveBlocksDown = createOnMove( 'MOVE_BLOCKS_DOWN' );
451
455
  export const moveBlocksUp = createOnMove( 'MOVE_BLOCKS_UP' );
@@ -458,51 +462,51 @@ export const moveBlocksUp = createOnMove( 'MOVE_BLOCKS_UP' );
458
462
  * @param {?string} toRootClientId Root client ID destination.
459
463
  * @param {number} index The index to move the blocks to.
460
464
  */
461
- export const moveBlocksToPosition = (
462
- clientIds,
463
- fromRootClientId = '',
464
- toRootClientId = '',
465
- index
466
- ) => ( { select, dispatch } ) => {
467
- const canMoveBlocks = select.canMoveBlocks( clientIds, fromRootClientId );
468
-
469
- // If one of the blocks is locked or the parent is locked, we cannot move any block.
470
- if ( ! canMoveBlocks ) {
471
- return;
472
- }
473
-
474
- // If moving inside the same root block the move is always possible.
475
- if ( fromRootClientId !== toRootClientId ) {
476
- const canRemoveBlocks = select.canRemoveBlocks(
465
+ export const moveBlocksToPosition =
466
+ ( clientIds, fromRootClientId = '', toRootClientId = '', index ) =>
467
+ ( { select, dispatch } ) => {
468
+ const canMoveBlocks = select.canMoveBlocks(
477
469
  clientIds,
478
470
  fromRootClientId
479
471
  );
480
472
 
481
- // If we're moving to another block, it means we're deleting blocks from
482
- // the original block, so we need to check if removing is possible.
483
- if ( ! canRemoveBlocks ) {
473
+ // If one of the blocks is locked or the parent is locked, we cannot move any block.
474
+ if ( ! canMoveBlocks ) {
484
475
  return;
485
476
  }
486
477
 
487
- const canInsertBlocks = select.canInsertBlocks(
488
- clientIds,
489
- toRootClientId
490
- );
478
+ // If moving inside the same root block the move is always possible.
479
+ if ( fromRootClientId !== toRootClientId ) {
480
+ const canRemoveBlocks = select.canRemoveBlocks(
481
+ clientIds,
482
+ fromRootClientId
483
+ );
491
484
 
492
- // If moving to other parent block, the move is possible if we can insert a block of the same type inside the new parent block.
493
- if ( ! canInsertBlocks ) {
494
- return;
485
+ // If we're moving to another block, it means we're deleting blocks from
486
+ // the original block, so we need to check if removing is possible.
487
+ if ( ! canRemoveBlocks ) {
488
+ return;
489
+ }
490
+
491
+ const canInsertBlocks = select.canInsertBlocks(
492
+ clientIds,
493
+ toRootClientId
494
+ );
495
+
496
+ // If moving to other parent block, the move is possible if we can insert a block of the same type inside the new parent block.
497
+ if ( ! canInsertBlocks ) {
498
+ return;
499
+ }
495
500
  }
496
- }
497
501
 
498
- dispatch( {
499
- type: 'MOVE_BLOCKS_TO_POSITION',
500
- fromRootClientId,
501
- toRootClientId,
502
- clientIds,
503
- index,
504
- } );
505
- };
502
+ dispatch( {
503
+ type: 'MOVE_BLOCKS_TO_POSITION',
504
+ fromRootClientId,
505
+ toRootClientId,
506
+ clientIds,
507
+ index,
508
+ } );
509
+ };
506
510
 
507
511
  /**
508
512
  * Action that moves given block to a new position.
@@ -566,48 +570,56 @@ export function insertBlock(
566
570
  * @param {?Object} meta Optional Meta values to be passed to the action object.
567
571
  * @return {Object} Action object.
568
572
  */
569
- export const insertBlocks = (
570
- blocks,
571
- index,
572
- rootClientId,
573
- updateSelection = true,
574
- initialPosition = 0,
575
- meta
576
- ) => ( { select, dispatch } ) => {
577
- /* eslint-enable jsdoc/valid-types */
578
- if ( isObject( initialPosition ) ) {
579
- meta = initialPosition;
580
- initialPosition = 0;
581
- deprecated( "meta argument in wp.data.dispatch('core/block-editor')", {
582
- since: '5.8',
583
- hint: 'The meta argument is now the 6th argument of the function',
584
- } );
585
- }
573
+ export const insertBlocks =
574
+ (
575
+ blocks,
576
+ index,
577
+ rootClientId,
578
+ updateSelection = true,
579
+ initialPosition = 0,
580
+ meta
581
+ ) =>
582
+ ( { select, dispatch } ) => {
583
+ /* eslint-enable jsdoc/valid-types */
584
+ if ( initialPosition !== null && typeof initialPosition === 'object' ) {
585
+ meta = initialPosition;
586
+ initialPosition = 0;
587
+ deprecated(
588
+ "meta argument in wp.data.dispatch('core/block-editor')",
589
+ {
590
+ since: '5.8',
591
+ hint: 'The meta argument is now the 6th argument of the function',
592
+ }
593
+ );
594
+ }
586
595
 
587
- blocks = getBlocksWithDefaultStylesApplied(
588
- castArray( blocks ),
589
- select.getSettings()
590
- );
591
- const allowedBlocks = [];
592
- for ( const block of blocks ) {
593
- const isValid = select.canInsertBlockType( block.name, rootClientId );
594
- if ( isValid ) {
595
- allowedBlocks.push( block );
596
+ blocks = getBlocksWithDefaultStylesApplied(
597
+ castArray( blocks ),
598
+ select.getSettings()
599
+ );
600
+ const allowedBlocks = [];
601
+ for ( const block of blocks ) {
602
+ const isValid = select.canInsertBlockType(
603
+ block.name,
604
+ rootClientId
605
+ );
606
+ if ( isValid ) {
607
+ allowedBlocks.push( block );
608
+ }
596
609
  }
597
- }
598
- if ( allowedBlocks.length ) {
599
- dispatch( {
600
- type: 'INSERT_BLOCKS',
601
- blocks: allowedBlocks,
602
- index,
603
- rootClientId,
604
- time: Date.now(),
605
- updateSelection,
606
- initialPosition: updateSelection ? initialPosition : null,
607
- meta,
608
- } );
609
- }
610
- };
610
+ if ( allowedBlocks.length ) {
611
+ dispatch( {
612
+ type: 'INSERT_BLOCKS',
613
+ blocks: allowedBlocks,
614
+ index,
615
+ rootClientId,
616
+ time: Date.now(),
617
+ updateSelection,
618
+ initialPosition: updateSelection ? initialPosition : null,
619
+ meta,
620
+ } );
621
+ }
622
+ };
611
623
 
612
624
  /**
613
625
  * Action that shows the insertion point.
@@ -663,321 +675,324 @@ export function setTemplateValidity( isValid ) {
663
675
  *
664
676
  * @return {Object} Action object.
665
677
  */
666
- export const synchronizeTemplate = () => ( { select, dispatch } ) => {
667
- dispatch( { type: 'SYNCHRONIZE_TEMPLATE' } );
668
- const blocks = select.getBlocks();
669
- const template = select.getTemplate();
670
- const updatedBlockList = synchronizeBlocksWithTemplate( blocks, template );
678
+ export const synchronizeTemplate =
679
+ () =>
680
+ ( { select, dispatch } ) => {
681
+ dispatch( { type: 'SYNCHRONIZE_TEMPLATE' } );
682
+ const blocks = select.getBlocks();
683
+ const template = select.getTemplate();
684
+ const updatedBlockList = synchronizeBlocksWithTemplate(
685
+ blocks,
686
+ template
687
+ );
671
688
 
672
- dispatch.resetBlocks( updatedBlockList );
673
- };
689
+ dispatch.resetBlocks( updatedBlockList );
690
+ };
674
691
 
675
692
  /**
676
693
  * Delete the current selection.
677
694
  *
678
695
  * @param {boolean} isForward
679
696
  */
680
- export const __unstableDeleteSelection = ( isForward ) => ( {
681
- registry,
682
- select,
683
- dispatch,
684
- } ) => {
685
- const selectionAnchor = select.getSelectionStart();
686
- const selectionFocus = select.getSelectionEnd();
687
-
688
- if ( selectionAnchor.clientId === selectionFocus.clientId ) return;
689
-
690
- // It's not mergeable if there's no rich text selection.
691
- if (
692
- ! selectionAnchor.attributeKey ||
693
- ! selectionFocus.attributeKey ||
694
- typeof selectionAnchor.offset === 'undefined' ||
695
- typeof selectionFocus.offset === 'undefined'
696
- )
697
- return false;
698
-
699
- const anchorRootClientId = select.getBlockRootClientId(
700
- selectionAnchor.clientId
701
- );
702
- const focusRootClientId = select.getBlockRootClientId(
703
- selectionFocus.clientId
704
- );
705
-
706
- // It's not mergeable if the selection doesn't start and end in the same
707
- // block list. Maybe in the future it should be allowed.
708
- if ( anchorRootClientId !== focusRootClientId ) {
709
- return;
710
- }
711
-
712
- const blockOrder = select.getBlockOrder( anchorRootClientId );
713
- const anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );
714
- const focusIndex = blockOrder.indexOf( selectionFocus.clientId );
697
+ export const __unstableDeleteSelection =
698
+ ( isForward ) =>
699
+ ( { registry, select, dispatch } ) => {
700
+ const selectionAnchor = select.getSelectionStart();
701
+ const selectionFocus = select.getSelectionEnd();
702
+
703
+ if ( selectionAnchor.clientId === selectionFocus.clientId ) return;
704
+
705
+ // It's not mergeable if there's no rich text selection.
706
+ if (
707
+ ! selectionAnchor.attributeKey ||
708
+ ! selectionFocus.attributeKey ||
709
+ typeof selectionAnchor.offset === 'undefined' ||
710
+ typeof selectionFocus.offset === 'undefined'
711
+ )
712
+ return false;
715
713
 
716
- // Reassign selection start and end based on order.
717
- let selectionStart, selectionEnd;
714
+ const anchorRootClientId = select.getBlockRootClientId(
715
+ selectionAnchor.clientId
716
+ );
717
+ const focusRootClientId = select.getBlockRootClientId(
718
+ selectionFocus.clientId
719
+ );
718
720
 
719
- if ( anchorIndex > focusIndex ) {
720
- selectionStart = selectionFocus;
721
- selectionEnd = selectionAnchor;
722
- } else {
723
- selectionStart = selectionAnchor;
724
- selectionEnd = selectionFocus;
725
- }
721
+ // It's not mergeable if the selection doesn't start and end in the same
722
+ // block list. Maybe in the future it should be allowed.
723
+ if ( anchorRootClientId !== focusRootClientId ) {
724
+ return;
725
+ }
726
726
 
727
- const targetSelection = isForward ? selectionEnd : selectionStart;
728
- const targetBlock = select.getBlock( targetSelection.clientId );
729
- const targetBlockType = getBlockType( targetBlock.name );
727
+ const blockOrder = select.getBlockOrder( anchorRootClientId );
728
+ const anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );
729
+ const focusIndex = blockOrder.indexOf( selectionFocus.clientId );
730
730
 
731
- if ( ! targetBlockType.merge ) {
732
- return;
733
- }
731
+ // Reassign selection start and end based on order.
732
+ let selectionStart, selectionEnd;
734
733
 
735
- const selectionA = selectionStart;
736
- const selectionB = selectionEnd;
734
+ if ( anchorIndex > focusIndex ) {
735
+ selectionStart = selectionFocus;
736
+ selectionEnd = selectionAnchor;
737
+ } else {
738
+ selectionStart = selectionAnchor;
739
+ selectionEnd = selectionFocus;
740
+ }
737
741
 
738
- const blockA = select.getBlock( selectionA.clientId );
739
- const blockAType = getBlockType( blockA.name );
742
+ const targetSelection = isForward ? selectionEnd : selectionStart;
743
+ const targetBlock = select.getBlock( targetSelection.clientId );
744
+ const targetBlockType = getBlockType( targetBlock.name );
740
745
 
741
- const blockB = select.getBlock( selectionB.clientId );
742
- const blockBType = getBlockType( blockB.name );
746
+ if ( ! targetBlockType.merge ) {
747
+ return;
748
+ }
743
749
 
744
- const htmlA = blockA.attributes[ selectionA.attributeKey ];
745
- const htmlB = blockB.attributes[ selectionB.attributeKey ];
750
+ const selectionA = selectionStart;
751
+ const selectionB = selectionEnd;
746
752
 
747
- const attributeDefinitionA =
748
- blockAType.attributes[ selectionA.attributeKey ];
749
- const attributeDefinitionB =
750
- blockBType.attributes[ selectionB.attributeKey ];
753
+ const blockA = select.getBlock( selectionA.clientId );
754
+ const blockAType = getBlockType( blockA.name );
751
755
 
752
- let valueA = create( {
753
- html: htmlA,
754
- ...mapRichTextSettings( attributeDefinitionA ),
755
- } );
756
- let valueB = create( {
757
- html: htmlB,
758
- ...mapRichTextSettings( attributeDefinitionB ),
759
- } );
756
+ const blockB = select.getBlock( selectionB.clientId );
757
+ const blockBType = getBlockType( blockB.name );
760
758
 
761
- // A robust way to retain selection position through various transforms
762
- // is to insert a special character at the position and then recover it.
763
- const START_OF_SELECTED_AREA = '\u0086';
759
+ const htmlA = blockA.attributes[ selectionA.attributeKey ];
760
+ const htmlB = blockB.attributes[ selectionB.attributeKey ];
764
761
 
765
- valueA = remove( valueA, selectionA.offset, valueA.text.length );
766
- valueB = insert( valueB, START_OF_SELECTED_AREA, 0, selectionB.offset );
762
+ const attributeDefinitionA =
763
+ blockAType.attributes[ selectionA.attributeKey ];
764
+ const attributeDefinitionB =
765
+ blockBType.attributes[ selectionB.attributeKey ];
767
766
 
768
- // Clone the blocks so we don't manipulate the original.
769
- const cloneA = cloneBlock( blockA, {
770
- [ selectionA.attributeKey ]: toHTMLString( {
771
- value: valueA,
767
+ let valueA = create( {
768
+ html: htmlA,
772
769
  ...mapRichTextSettings( attributeDefinitionA ),
773
- } ),
774
- } );
775
- const cloneB = cloneBlock( blockB, {
776
- [ selectionB.attributeKey ]: toHTMLString( {
777
- value: valueB,
770
+ } );
771
+ let valueB = create( {
772
+ html: htmlB,
778
773
  ...mapRichTextSettings( attributeDefinitionB ),
779
- } ),
780
- } );
774
+ } );
781
775
 
782
- const followingBlock = isForward ? cloneA : cloneB;
776
+ valueA = remove( valueA, selectionA.offset, valueA.text.length );
777
+ valueB = insert( valueB, START_OF_SELECTED_AREA, 0, selectionB.offset );
783
778
 
784
- // We can only merge blocks with similar types
785
- // thus, we transform the block to merge first
786
- const blocksWithTheSameType =
787
- blockA.name === blockB.name
788
- ? [ followingBlock ]
789
- : switchToBlockType( followingBlock, targetBlockType.name );
779
+ // Clone the blocks so we don't manipulate the original.
780
+ const cloneA = cloneBlock( blockA, {
781
+ [ selectionA.attributeKey ]: toHTMLString( {
782
+ value: valueA,
783
+ ...mapRichTextSettings( attributeDefinitionA ),
784
+ } ),
785
+ } );
786
+ const cloneB = cloneBlock( blockB, {
787
+ [ selectionB.attributeKey ]: toHTMLString( {
788
+ value: valueB,
789
+ ...mapRichTextSettings( attributeDefinitionB ),
790
+ } ),
791
+ } );
790
792
 
791
- // If the block types can not match, do nothing
792
- if ( ! blocksWithTheSameType || ! blocksWithTheSameType.length ) {
793
- return;
794
- }
793
+ const followingBlock = isForward ? cloneA : cloneB;
795
794
 
796
- let updatedAttributes;
795
+ // We can only merge blocks with similar types
796
+ // thus, we transform the block to merge first
797
+ const blocksWithTheSameType =
798
+ blockA.name === blockB.name
799
+ ? [ followingBlock ]
800
+ : switchToBlockType( followingBlock, targetBlockType.name );
797
801
 
798
- if ( isForward ) {
799
- const blockToMerge = blocksWithTheSameType.pop();
800
- updatedAttributes = targetBlockType.merge(
801
- blockToMerge.attributes,
802
- cloneB.attributes
803
- );
804
- } else {
805
- const blockToMerge = blocksWithTheSameType.shift();
806
- updatedAttributes = targetBlockType.merge(
807
- cloneA.attributes,
808
- blockToMerge.attributes
809
- );
810
- }
802
+ // If the block types can not match, do nothing
803
+ if ( ! blocksWithTheSameType || ! blocksWithTheSameType.length ) {
804
+ return;
805
+ }
811
806
 
812
- const newAttributeKey = findKey(
813
- updatedAttributes,
814
- ( v ) =>
815
- typeof v === 'string' && v.indexOf( START_OF_SELECTED_AREA ) !== -1
816
- );
807
+ let updatedAttributes;
817
808
 
818
- const convertedHtml = updatedAttributes[ newAttributeKey ];
819
- const convertedValue = create( {
820
- html: convertedHtml,
821
- ...mapRichTextSettings( targetBlockType.attributes[ newAttributeKey ] ),
822
- } );
823
- const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
824
- const newValue = remove( convertedValue, newOffset, newOffset + 1 );
825
- const newHtml = toHTMLString( {
826
- value: newValue,
827
- ...mapRichTextSettings( targetBlockType.attributes[ newAttributeKey ] ),
828
- } );
809
+ if ( isForward ) {
810
+ const blockToMerge = blocksWithTheSameType.pop();
811
+ updatedAttributes = targetBlockType.merge(
812
+ blockToMerge.attributes,
813
+ cloneB.attributes
814
+ );
815
+ } else {
816
+ const blockToMerge = blocksWithTheSameType.shift();
817
+ updatedAttributes = targetBlockType.merge(
818
+ cloneA.attributes,
819
+ blockToMerge.attributes
820
+ );
821
+ }
829
822
 
830
- updatedAttributes[ newAttributeKey ] = newHtml;
823
+ const newAttributeKey = retrieveSelectedAttribute( updatedAttributes );
831
824
 
832
- const selectedBlockClientIds = select.getSelectedBlockClientIds();
833
- const replacement = [
834
- ...( isForward ? blocksWithTheSameType : [] ),
835
- {
836
- // Preserve the original client ID.
837
- ...targetBlock,
838
- attributes: {
839
- ...targetBlock.attributes,
840
- ...updatedAttributes,
825
+ const convertedHtml = updatedAttributes[ newAttributeKey ];
826
+ const convertedValue = create( {
827
+ html: convertedHtml,
828
+ ...mapRichTextSettings(
829
+ targetBlockType.attributes[ newAttributeKey ]
830
+ ),
831
+ } );
832
+ const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
833
+ const newValue = remove( convertedValue, newOffset, newOffset + 1 );
834
+ const newHtml = toHTMLString( {
835
+ value: newValue,
836
+ ...mapRichTextSettings(
837
+ targetBlockType.attributes[ newAttributeKey ]
838
+ ),
839
+ } );
840
+
841
+ updatedAttributes[ newAttributeKey ] = newHtml;
842
+
843
+ const selectedBlockClientIds = select.getSelectedBlockClientIds();
844
+ const replacement = [
845
+ ...( isForward ? blocksWithTheSameType : [] ),
846
+ {
847
+ // Preserve the original client ID.
848
+ ...targetBlock,
849
+ attributes: {
850
+ ...targetBlock.attributes,
851
+ ...updatedAttributes,
852
+ },
841
853
  },
842
- },
843
- ...( isForward ? [] : blocksWithTheSameType ),
844
- ];
845
-
846
- registry.batch( () => {
847
- dispatch.selectionChange(
848
- targetBlock.clientId,
849
- newAttributeKey,
850
- newOffset,
851
- newOffset
852
- );
854
+ ...( isForward ? [] : blocksWithTheSameType ),
855
+ ];
856
+
857
+ registry.batch( () => {
858
+ dispatch.selectionChange(
859
+ targetBlock.clientId,
860
+ newAttributeKey,
861
+ newOffset,
862
+ newOffset
863
+ );
853
864
 
854
- dispatch.replaceBlocks(
855
- selectedBlockClientIds,
856
- replacement,
857
- 0, // If we don't pass the `indexToSelect` it will default to the last block.
858
- select.getSelectedBlocksInitialCaretPosition()
859
- );
860
- } );
861
- };
865
+ dispatch.replaceBlocks(
866
+ selectedBlockClientIds,
867
+ replacement,
868
+ 0, // If we don't pass the `indexToSelect` it will default to the last block.
869
+ select.getSelectedBlocksInitialCaretPosition()
870
+ );
871
+ } );
872
+ };
862
873
 
863
874
  /**
864
875
  * Split the current selection.
865
876
  */
866
- export const __unstableSplitSelection = () => ( { select, dispatch } ) => {
867
- const selectionAnchor = select.getSelectionStart();
868
- const selectionFocus = select.getSelectionEnd();
869
-
870
- if ( selectionAnchor.clientId === selectionFocus.clientId ) return;
871
-
872
- // Can't split if the selection is not set.
873
- if (
874
- ! selectionAnchor.attributeKey ||
875
- ! selectionFocus.attributeKey ||
876
- typeof selectionAnchor.offset === 'undefined' ||
877
- typeof selectionFocus.offset === 'undefined'
878
- )
879
- return;
880
-
881
- const anchorRootClientId = select.getBlockRootClientId(
882
- selectionAnchor.clientId
883
- );
884
- const focusRootClientId = select.getBlockRootClientId(
885
- selectionFocus.clientId
886
- );
877
+ export const __unstableSplitSelection =
878
+ () =>
879
+ ( { select, dispatch } ) => {
880
+ const selectionAnchor = select.getSelectionStart();
881
+ const selectionFocus = select.getSelectionEnd();
882
+
883
+ if ( selectionAnchor.clientId === selectionFocus.clientId ) return;
884
+
885
+ // Can't split if the selection is not set.
886
+ if (
887
+ ! selectionAnchor.attributeKey ||
888
+ ! selectionFocus.attributeKey ||
889
+ typeof selectionAnchor.offset === 'undefined' ||
890
+ typeof selectionFocus.offset === 'undefined'
891
+ )
892
+ return;
887
893
 
888
- // It's not splittable if the selection doesn't start and end in the same
889
- // block list. Maybe in the future it should be allowed.
890
- if ( anchorRootClientId !== focusRootClientId ) {
891
- return;
892
- }
894
+ const anchorRootClientId = select.getBlockRootClientId(
895
+ selectionAnchor.clientId
896
+ );
897
+ const focusRootClientId = select.getBlockRootClientId(
898
+ selectionFocus.clientId
899
+ );
893
900
 
894
- const blockOrder = select.getBlockOrder( anchorRootClientId );
895
- const anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );
896
- const focusIndex = blockOrder.indexOf( selectionFocus.clientId );
901
+ // It's not splittable if the selection doesn't start and end in the same
902
+ // block list. Maybe in the future it should be allowed.
903
+ if ( anchorRootClientId !== focusRootClientId ) {
904
+ return;
905
+ }
897
906
 
898
- // Reassign selection start and end based on order.
899
- let selectionStart, selectionEnd;
907
+ const blockOrder = select.getBlockOrder( anchorRootClientId );
908
+ const anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );
909
+ const focusIndex = blockOrder.indexOf( selectionFocus.clientId );
900
910
 
901
- if ( anchorIndex > focusIndex ) {
902
- selectionStart = selectionFocus;
903
- selectionEnd = selectionAnchor;
904
- } else {
905
- selectionStart = selectionAnchor;
906
- selectionEnd = selectionFocus;
907
- }
911
+ // Reassign selection start and end based on order.
912
+ let selectionStart, selectionEnd;
908
913
 
909
- const selectionA = selectionStart;
910
- const selectionB = selectionEnd;
914
+ if ( anchorIndex > focusIndex ) {
915
+ selectionStart = selectionFocus;
916
+ selectionEnd = selectionAnchor;
917
+ } else {
918
+ selectionStart = selectionAnchor;
919
+ selectionEnd = selectionFocus;
920
+ }
911
921
 
912
- const blockA = select.getBlock( selectionA.clientId );
913
- const blockAType = getBlockType( blockA.name );
922
+ const selectionA = selectionStart;
923
+ const selectionB = selectionEnd;
914
924
 
915
- const blockB = select.getBlock( selectionB.clientId );
916
- const blockBType = getBlockType( blockB.name );
925
+ const blockA = select.getBlock( selectionA.clientId );
926
+ const blockAType = getBlockType( blockA.name );
917
927
 
918
- const htmlA = blockA.attributes[ selectionA.attributeKey ];
919
- const htmlB = blockB.attributes[ selectionB.attributeKey ];
928
+ const blockB = select.getBlock( selectionB.clientId );
929
+ const blockBType = getBlockType( blockB.name );
920
930
 
921
- const attributeDefinitionA =
922
- blockAType.attributes[ selectionA.attributeKey ];
923
- const attributeDefinitionB =
924
- blockBType.attributes[ selectionB.attributeKey ];
931
+ const htmlA = blockA.attributes[ selectionA.attributeKey ];
932
+ const htmlB = blockB.attributes[ selectionB.attributeKey ];
925
933
 
926
- let valueA = create( {
927
- html: htmlA,
928
- ...mapRichTextSettings( attributeDefinitionA ),
929
- } );
930
- let valueB = create( {
931
- html: htmlB,
932
- ...mapRichTextSettings( attributeDefinitionB ),
933
- } );
934
+ const attributeDefinitionA =
935
+ blockAType.attributes[ selectionA.attributeKey ];
936
+ const attributeDefinitionB =
937
+ blockBType.attributes[ selectionB.attributeKey ];
934
938
 
935
- valueA = remove( valueA, selectionA.offset, valueA.text.length );
936
- valueB = remove( valueB, 0, selectionB.offset );
939
+ let valueA = create( {
940
+ html: htmlA,
941
+ ...mapRichTextSettings( attributeDefinitionA ),
942
+ } );
943
+ let valueB = create( {
944
+ html: htmlB,
945
+ ...mapRichTextSettings( attributeDefinitionB ),
946
+ } );
937
947
 
938
- dispatch.replaceBlocks(
939
- select.getSelectedBlockClientIds(),
940
- [
941
- {
942
- // Preserve the original client ID.
943
- ...blockA,
944
- attributes: {
945
- ...blockA.attributes,
946
- [ selectionA.attributeKey ]: toHTMLString( {
947
- value: valueA,
948
- ...mapRichTextSettings( attributeDefinitionA ),
949
- } ),
948
+ valueA = remove( valueA, selectionA.offset, valueA.text.length );
949
+ valueB = remove( valueB, 0, selectionB.offset );
950
+
951
+ dispatch.replaceBlocks(
952
+ select.getSelectedBlockClientIds(),
953
+ [
954
+ {
955
+ // Preserve the original client ID.
956
+ ...blockA,
957
+ attributes: {
958
+ ...blockA.attributes,
959
+ [ selectionA.attributeKey ]: toHTMLString( {
960
+ value: valueA,
961
+ ...mapRichTextSettings( attributeDefinitionA ),
962
+ } ),
963
+ },
950
964
  },
951
- },
952
- createBlock( getDefaultBlockName() ),
953
- {
954
- // Preserve the original client ID.
955
- ...blockB,
956
- attributes: {
957
- ...blockB.attributes,
958
- [ selectionB.attributeKey ]: toHTMLString( {
959
- value: valueB,
960
- ...mapRichTextSettings( attributeDefinitionB ),
961
- } ),
965
+ createBlock( getDefaultBlockName() ),
966
+ {
967
+ // Preserve the original client ID.
968
+ ...blockB,
969
+ attributes: {
970
+ ...blockB.attributes,
971
+ [ selectionB.attributeKey ]: toHTMLString( {
972
+ value: valueB,
973
+ ...mapRichTextSettings( attributeDefinitionB ),
974
+ } ),
975
+ },
962
976
  },
963
- },
964
- ],
965
- 1, // If we don't pass the `indexToSelect` it will default to the last block.
966
- select.getSelectedBlocksInitialCaretPosition()
967
- );
968
- };
977
+ ],
978
+ 1, // If we don't pass the `indexToSelect` it will default to the last block.
979
+ select.getSelectedBlocksInitialCaretPosition()
980
+ );
981
+ };
969
982
 
970
983
  /**
971
984
  * Expand the selection to cover the entire blocks, removing partial selection.
972
985
  */
973
- export const __unstableExpandSelection = () => ( { select, dispatch } ) => {
974
- const selectionAnchor = select.getSelectionStart();
975
- const selectionFocus = select.getSelectionEnd();
976
- dispatch.selectionChange( {
977
- start: { clientId: selectionAnchor.clientId },
978
- end: { clientId: selectionFocus.clientId },
979
- } );
980
- };
986
+ export const __unstableExpandSelection =
987
+ () =>
988
+ ( { select, dispatch } ) => {
989
+ const selectionAnchor = select.getSelectionStart();
990
+ const selectionFocus = select.getSelectionEnd();
991
+ dispatch.selectionChange( {
992
+ start: { clientId: selectionAnchor.clientId },
993
+ end: { clientId: selectionFocus.clientId },
994
+ } );
995
+ };
981
996
 
982
997
  /**
983
998
  * Action that merges two blocks.
@@ -985,139 +1000,138 @@ export const __unstableExpandSelection = () => ( { select, dispatch } ) => {
985
1000
  * @param {string} firstBlockClientId Client ID of the first block to merge.
986
1001
  * @param {string} secondBlockClientId Client ID of the second block to merge.
987
1002
  */
988
- export const mergeBlocks = ( firstBlockClientId, secondBlockClientId ) => ( {
989
- select,
990
- dispatch,
991
- } ) => {
992
- const blocks = [ firstBlockClientId, secondBlockClientId ];
993
- dispatch( { type: 'MERGE_BLOCKS', blocks } );
994
-
995
- const [ clientIdA, clientIdB ] = blocks;
996
- const blockA = select.getBlock( clientIdA );
997
- const blockAType = getBlockType( blockA.name );
998
-
999
- // Only focus the previous block if it's not mergeable.
1000
- if ( blockAType && ! blockAType.merge ) {
1001
- dispatch.selectBlock( blockA.clientId );
1002
- return;
1003
- }
1004
-
1005
- const blockB = select.getBlock( clientIdB );
1006
- const blockBType = getBlockType( blockB.name );
1007
- const { clientId, attributeKey, offset } = select.getSelectionStart();
1008
- const selectedBlockType = clientId === clientIdA ? blockAType : blockBType;
1009
- const attributeDefinition = selectedBlockType.attributes[ attributeKey ];
1010
- const canRestoreTextSelection =
1011
- ( clientId === clientIdA || clientId === clientIdB ) &&
1012
- attributeKey !== undefined &&
1013
- offset !== undefined &&
1014
- // We cannot restore text selection if the RichText identifier
1015
- // is not a defined block attribute key. This can be the case if the
1016
- // fallback intance ID is used to store selection (and no RichText
1017
- // identifier is set), or when the identifier is wrong.
1018
- !! attributeDefinition;
1019
-
1020
- if ( ! attributeDefinition ) {
1021
- if ( typeof attributeKey === 'number' ) {
1022
- window.console.error(
1023
- `RichText needs an identifier prop that is the block attribute key of the attribute it controls. Its type is expected to be a string, but was ${ typeof attributeKey }`
1024
- );
1025
- } else {
1026
- window.console.error(
1027
- 'The RichText identifier prop does not match any attributes defined by the block.'
1028
- );
1003
+ export const mergeBlocks =
1004
+ ( firstBlockClientId, secondBlockClientId ) =>
1005
+ ( { select, dispatch } ) => {
1006
+ const blocks = [ firstBlockClientId, secondBlockClientId ];
1007
+ dispatch( { type: 'MERGE_BLOCKS', blocks } );
1008
+
1009
+ const [ clientIdA, clientIdB ] = blocks;
1010
+ const blockA = select.getBlock( clientIdA );
1011
+ const blockAType = getBlockType( blockA.name );
1012
+
1013
+ // Only focus the previous block if it's not mergeable.
1014
+ if ( blockAType && ! blockAType.merge ) {
1015
+ dispatch.selectBlock( blockA.clientId );
1016
+ return;
1029
1017
  }
1030
- }
1031
1018
 
1032
- // A robust way to retain selection position through various transforms
1033
- // is to insert a special character at the position and then recover it.
1034
- const START_OF_SELECTED_AREA = '\u0086';
1019
+ const blockB = select.getBlock( clientIdB );
1020
+ const blockBType = getBlockType( blockB.name );
1021
+ const { clientId, attributeKey, offset } = select.getSelectionStart();
1022
+ const selectedBlockType =
1023
+ clientId === clientIdA ? blockAType : blockBType;
1024
+ const attributeDefinition =
1025
+ selectedBlockType.attributes[ attributeKey ];
1026
+ const canRestoreTextSelection =
1027
+ ( clientId === clientIdA || clientId === clientIdB ) &&
1028
+ attributeKey !== undefined &&
1029
+ offset !== undefined &&
1030
+ // We cannot restore text selection if the RichText identifier
1031
+ // is not a defined block attribute key. This can be the case if the
1032
+ // fallback intance ID is used to store selection (and no RichText
1033
+ // identifier is set), or when the identifier is wrong.
1034
+ !! attributeDefinition;
1035
+
1036
+ if ( ! attributeDefinition ) {
1037
+ if ( typeof attributeKey === 'number' ) {
1038
+ window.console.error(
1039
+ `RichText needs an identifier prop that is the block attribute key of the attribute it controls. Its type is expected to be a string, but was ${ typeof attributeKey }`
1040
+ );
1041
+ } else {
1042
+ window.console.error(
1043
+ 'The RichText identifier prop does not match any attributes defined by the block.'
1044
+ );
1045
+ }
1046
+ }
1035
1047
 
1036
- // Clone the blocks so we don't insert the character in a "live" block.
1037
- const cloneA = cloneBlock( blockA );
1038
- const cloneB = cloneBlock( blockB );
1048
+ // Clone the blocks so we don't insert the character in a "live" block.
1049
+ const cloneA = cloneBlock( blockA );
1050
+ const cloneB = cloneBlock( blockB );
1051
+
1052
+ if ( canRestoreTextSelection ) {
1053
+ const selectedBlock = clientId === clientIdA ? cloneA : cloneB;
1054
+ const html = selectedBlock.attributes[ attributeKey ];
1055
+ const value = insert(
1056
+ create( {
1057
+ html,
1058
+ ...mapRichTextSettings( attributeDefinition ),
1059
+ } ),
1060
+ START_OF_SELECTED_AREA,
1061
+ offset,
1062
+ offset
1063
+ );
1039
1064
 
1040
- if ( canRestoreTextSelection ) {
1041
- const selectedBlock = clientId === clientIdA ? cloneA : cloneB;
1042
- const html = selectedBlock.attributes[ attributeKey ];
1043
- const value = insert(
1044
- create( {
1045
- html,
1065
+ selectedBlock.attributes[ attributeKey ] = toHTMLString( {
1066
+ value,
1046
1067
  ...mapRichTextSettings( attributeDefinition ),
1047
- } ),
1048
- START_OF_SELECTED_AREA,
1049
- offset,
1050
- offset
1051
- );
1052
-
1053
- selectedBlock.attributes[ attributeKey ] = toHTMLString( {
1054
- value,
1055
- ...mapRichTextSettings( attributeDefinition ),
1056
- } );
1057
- }
1058
-
1059
- // We can only merge blocks with similar types
1060
- // thus, we transform the block to merge first.
1061
- const blocksWithTheSameType =
1062
- blockA.name === blockB.name
1063
- ? [ cloneB ]
1064
- : switchToBlockType( cloneB, blockA.name );
1068
+ } );
1069
+ }
1065
1070
 
1066
- // If the block types can not match, do nothing.
1067
- if ( ! blocksWithTheSameType || ! blocksWithTheSameType.length ) {
1068
- return;
1069
- }
1071
+ // We can only merge blocks with similar types
1072
+ // thus, we transform the block to merge first.
1073
+ const blocksWithTheSameType =
1074
+ blockA.name === blockB.name
1075
+ ? [ cloneB ]
1076
+ : switchToBlockType( cloneB, blockA.name );
1070
1077
 
1071
- // Calling the merge to update the attributes and remove the block to be merged.
1072
- const updatedAttributes = blockAType.merge(
1073
- cloneA.attributes,
1074
- blocksWithTheSameType[ 0 ].attributes
1075
- );
1078
+ // If the block types can not match, do nothing.
1079
+ if ( ! blocksWithTheSameType || ! blocksWithTheSameType.length ) {
1080
+ return;
1081
+ }
1076
1082
 
1077
- if ( canRestoreTextSelection ) {
1078
- const newAttributeKey = findKey(
1079
- updatedAttributes,
1080
- ( v ) =>
1081
- typeof v === 'string' &&
1082
- v.indexOf( START_OF_SELECTED_AREA ) !== -1
1083
+ // Calling the merge to update the attributes and remove the block to be merged.
1084
+ const updatedAttributes = blockAType.merge(
1085
+ cloneA.attributes,
1086
+ blocksWithTheSameType[ 0 ].attributes
1083
1087
  );
1084
- const convertedHtml = updatedAttributes[ newAttributeKey ];
1085
- const convertedValue = create( {
1086
- html: convertedHtml,
1087
- ...mapRichTextSettings( blockAType.attributes[ newAttributeKey ] ),
1088
- } );
1089
- const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
1090
- const newValue = remove( convertedValue, newOffset, newOffset + 1 );
1091
- const newHtml = toHTMLString( {
1092
- value: newValue,
1093
- ...mapRichTextSettings( blockAType.attributes[ newAttributeKey ] ),
1094
- } );
1095
1088
 
1096
- updatedAttributes[ newAttributeKey ] = newHtml;
1097
-
1098
- dispatch.selectionChange(
1099
- blockA.clientId,
1100
- newAttributeKey,
1101
- newOffset,
1102
- newOffset
1103
- );
1104
- }
1089
+ if ( canRestoreTextSelection ) {
1090
+ const newAttributeKey =
1091
+ retrieveSelectedAttribute( updatedAttributes );
1092
+ const convertedHtml = updatedAttributes[ newAttributeKey ];
1093
+ const convertedValue = create( {
1094
+ html: convertedHtml,
1095
+ ...mapRichTextSettings(
1096
+ blockAType.attributes[ newAttributeKey ]
1097
+ ),
1098
+ } );
1099
+ const newOffset = convertedValue.text.indexOf(
1100
+ START_OF_SELECTED_AREA
1101
+ );
1102
+ const newValue = remove( convertedValue, newOffset, newOffset + 1 );
1103
+ const newHtml = toHTMLString( {
1104
+ value: newValue,
1105
+ ...mapRichTextSettings(
1106
+ blockAType.attributes[ newAttributeKey ]
1107
+ ),
1108
+ } );
1109
+
1110
+ updatedAttributes[ newAttributeKey ] = newHtml;
1111
+
1112
+ dispatch.selectionChange(
1113
+ blockA.clientId,
1114
+ newAttributeKey,
1115
+ newOffset,
1116
+ newOffset
1117
+ );
1118
+ }
1105
1119
 
1106
- dispatch.replaceBlocks(
1107
- [ blockA.clientId, blockB.clientId ],
1108
- [
1109
- {
1110
- ...blockA,
1111
- attributes: {
1112
- ...blockA.attributes,
1113
- ...updatedAttributes,
1120
+ dispatch.replaceBlocks(
1121
+ [ blockA.clientId, blockB.clientId ],
1122
+ [
1123
+ {
1124
+ ...blockA,
1125
+ attributes: {
1126
+ ...blockA.attributes,
1127
+ ...updatedAttributes,
1128
+ },
1114
1129
  },
1115
- },
1116
- ...blocksWithTheSameType.slice( 1 ),
1117
- ],
1118
- 0 // If we don't pass the `indexToSelect` it will default to the last block.
1119
- );
1120
- };
1130
+ ...blocksWithTheSameType.slice( 1 ),
1131
+ ],
1132
+ 0 // If we don't pass the `indexToSelect` it will default to the last block.
1133
+ );
1134
+ };
1121
1135
 
1122
1136
  /**
1123
1137
  * Yields action objects used in signalling that the blocks corresponding to
@@ -1127,32 +1141,34 @@ export const mergeBlocks = ( firstBlockClientId, secondBlockClientId ) => ( {
1127
1141
  * @param {boolean} selectPrevious True if the previous block should be
1128
1142
  * selected when a block is removed.
1129
1143
  */
1130
- export const removeBlocks = ( clientIds, selectPrevious = true ) => ( {
1131
- select,
1132
- dispatch,
1133
- } ) => {
1134
- if ( ! clientIds || ! clientIds.length ) {
1135
- return;
1136
- }
1144
+ export const removeBlocks =
1145
+ ( clientIds, selectPrevious = true ) =>
1146
+ ( { select, dispatch } ) => {
1147
+ if ( ! clientIds || ! clientIds.length ) {
1148
+ return;
1149
+ }
1137
1150
 
1138
- clientIds = castArray( clientIds );
1139
- const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
1140
- const canRemoveBlocks = select.canRemoveBlocks( clientIds, rootClientId );
1151
+ clientIds = castArray( clientIds );
1152
+ const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
1153
+ const canRemoveBlocks = select.canRemoveBlocks(
1154
+ clientIds,
1155
+ rootClientId
1156
+ );
1141
1157
 
1142
- if ( ! canRemoveBlocks ) {
1143
- return;
1144
- }
1158
+ if ( ! canRemoveBlocks ) {
1159
+ return;
1160
+ }
1145
1161
 
1146
- if ( selectPrevious ) {
1147
- dispatch.selectPreviousBlock( clientIds[ 0 ] );
1148
- }
1162
+ if ( selectPrevious ) {
1163
+ dispatch.selectPreviousBlock( clientIds[ 0 ] );
1164
+ }
1149
1165
 
1150
- dispatch( { type: 'REMOVE_BLOCKS', clientIds } );
1166
+ dispatch( { type: 'REMOVE_BLOCKS', clientIds } );
1151
1167
 
1152
- // To avoid a focus loss when removing the last block, assure there is
1153
- // always a default block if the last of the blocks have been removed.
1154
- dispatch( ensureDefaultBlock() );
1155
- };
1168
+ // To avoid a focus loss when removing the last block, assure there is
1169
+ // always a default block if the last of the blocks have been removed.
1170
+ dispatch( ensureDefaultBlock() );
1171
+ };
1156
1172
 
1157
1173
  /**
1158
1174
  * Returns an action object used in signalling that the block with the
@@ -1329,19 +1345,19 @@ export function selectionChange(
1329
1345
  * to append.
1330
1346
  * @param {?number} index Optional index where to insert the default block.
1331
1347
  */
1332
- export const insertDefaultBlock = ( attributes, rootClientId, index ) => ( {
1333
- dispatch,
1334
- } ) => {
1335
- // Abort if there is no default block type (if it has been unregistered).
1336
- const defaultBlockName = getDefaultBlockName();
1337
- if ( ! defaultBlockName ) {
1338
- return;
1339
- }
1348
+ export const insertDefaultBlock =
1349
+ ( attributes, rootClientId, index ) =>
1350
+ ( { dispatch } ) => {
1351
+ // Abort if there is no default block type (if it has been unregistered).
1352
+ const defaultBlockName = getDefaultBlockName();
1353
+ if ( ! defaultBlockName ) {
1354
+ return;
1355
+ }
1340
1356
 
1341
- const block = createBlock( defaultBlockName, attributes );
1357
+ const block = createBlock( defaultBlockName, attributes );
1342
1358
 
1343
- return dispatch.insertBlock( block, index, rootClientId );
1344
- };
1359
+ return dispatch.insertBlock( block, index, rootClientId );
1360
+ };
1345
1361
 
1346
1362
  /**
1347
1363
  * Action that changes the nested settings of a given block.
@@ -1416,57 +1432,60 @@ export function __unstableMarkNextChangeAsNotPersistent() {
1416
1432
  * consequence of it, so it is recommended to be called at the next idle period to ensure all
1417
1433
  * selection changes have been recorded.
1418
1434
  */
1419
- export const __unstableMarkAutomaticChange = () => ( { dispatch } ) => {
1420
- dispatch( { type: 'MARK_AUTOMATIC_CHANGE' } );
1421
- const { requestIdleCallback = ( cb ) => setTimeout( cb, 100 ) } = window;
1422
- requestIdleCallback( () => {
1423
- dispatch( { type: 'MARK_AUTOMATIC_CHANGE_FINAL' } );
1424
- } );
1425
- };
1435
+ export const __unstableMarkAutomaticChange =
1436
+ () =>
1437
+ ( { dispatch } ) => {
1438
+ dispatch( { type: 'MARK_AUTOMATIC_CHANGE' } );
1439
+ const { requestIdleCallback = ( cb ) => setTimeout( cb, 100 ) } =
1440
+ window;
1441
+ requestIdleCallback( () => {
1442
+ dispatch( { type: 'MARK_AUTOMATIC_CHANGE_FINAL' } );
1443
+ } );
1444
+ };
1426
1445
 
1427
1446
  /**
1428
1447
  * Action that enables or disables the navigation mode.
1429
1448
  *
1430
1449
  * @param {string} isNavigationMode Enable/Disable navigation mode.
1431
1450
  */
1432
- export const setNavigationMode = ( isNavigationMode = true ) => ( {
1433
- dispatch,
1434
- } ) => {
1435
- dispatch( { type: 'SET_NAVIGATION_MODE', isNavigationMode } );
1436
-
1437
- if ( isNavigationMode ) {
1438
- speak(
1439
- __(
1440
- 'You are currently in navigation mode. Navigate blocks using the Tab key and Arrow keys. Use Left and Right Arrow keys to move between nesting levels. To exit navigation mode and edit the selected block, press Enter.'
1441
- )
1442
- );
1443
- } else {
1444
- speak(
1445
- __(
1446
- 'You are currently in edit mode. To return to the navigation mode, press Escape.'
1447
- )
1448
- );
1449
- }
1450
- };
1451
+ export const setNavigationMode =
1452
+ ( isNavigationMode = true ) =>
1453
+ ( { dispatch } ) => {
1454
+ dispatch( { type: 'SET_NAVIGATION_MODE', isNavigationMode } );
1455
+
1456
+ if ( isNavigationMode ) {
1457
+ speak(
1458
+ __(
1459
+ 'You are currently in navigation mode. Navigate blocks using the Tab key and Arrow keys. Use Left and Right Arrow keys to move between nesting levels. To exit navigation mode and edit the selected block, press Enter.'
1460
+ )
1461
+ );
1462
+ } else {
1463
+ speak(
1464
+ __(
1465
+ 'You are currently in edit mode. To return to the navigation mode, press Escape.'
1466
+ )
1467
+ );
1468
+ }
1469
+ };
1451
1470
 
1452
1471
  /**
1453
1472
  * Action that enables or disables the block moving mode.
1454
1473
  *
1455
1474
  * @param {string|null} hasBlockMovingClientId Enable/Disable block moving mode.
1456
1475
  */
1457
- export const setBlockMovingClientId = ( hasBlockMovingClientId = null ) => ( {
1458
- dispatch,
1459
- } ) => {
1460
- dispatch( { type: 'SET_BLOCK_MOVING_MODE', hasBlockMovingClientId } );
1461
-
1462
- if ( hasBlockMovingClientId ) {
1463
- speak(
1464
- __(
1465
- 'Use the Tab key and Arrow keys to choose new block location. Use Left and Right Arrow keys to move between nesting levels. Once location is selected press Enter or Space to move the block.'
1466
- )
1467
- );
1468
- }
1469
- };
1476
+ export const setBlockMovingClientId =
1477
+ ( hasBlockMovingClientId = null ) =>
1478
+ ( { dispatch } ) => {
1479
+ dispatch( { type: 'SET_BLOCK_MOVING_MODE', hasBlockMovingClientId } );
1480
+
1481
+ if ( hasBlockMovingClientId ) {
1482
+ speak(
1483
+ __(
1484
+ 'Use the Tab key and Arrow keys to choose new block location. Use Left and Right Arrow keys to move between nesting levels. Once location is selected press Enter or Space to move the block.'
1485
+ )
1486
+ );
1487
+ }
1488
+ };
1470
1489
 
1471
1490
  /**
1472
1491
  * Action that duplicates a list of blocks.
@@ -1474,93 +1493,102 @@ export const setBlockMovingClientId = ( hasBlockMovingClientId = null ) => ( {
1474
1493
  * @param {string[]} clientIds
1475
1494
  * @param {boolean} updateSelection
1476
1495
  */
1477
- export const duplicateBlocks = ( clientIds, updateSelection = true ) => ( {
1478
- select,
1479
- dispatch,
1480
- } ) => {
1481
- if ( ! clientIds || ! clientIds.length ) {
1482
- return;
1483
- }
1496
+ export const duplicateBlocks =
1497
+ ( clientIds, updateSelection = true ) =>
1498
+ ( { select, dispatch } ) => {
1499
+ if ( ! clientIds || ! clientIds.length ) {
1500
+ return;
1501
+ }
1484
1502
 
1485
- // Return early if blocks don't exist.
1486
- const blocks = select.getBlocksByClientId( clientIds );
1487
- if ( some( blocks, ( block ) => ! block ) ) {
1488
- return;
1489
- }
1503
+ // Return early if blocks don't exist.
1504
+ const blocks = select.getBlocksByClientId( clientIds );
1505
+ if ( blocks.some( ( block ) => ! block ) ) {
1506
+ return;
1507
+ }
1490
1508
 
1491
- // Return early if blocks don't support multiple usage.
1492
- const blockNames = blocks.map( ( block ) => block.name );
1493
- if (
1494
- blockNames.some(
1495
- ( blockName ) => ! hasBlockSupport( blockName, 'multiple', true )
1496
- )
1497
- ) {
1498
- return;
1499
- }
1509
+ // Return early if blocks don't support multiple usage.
1510
+ const blockNames = blocks.map( ( block ) => block.name );
1511
+ if (
1512
+ blockNames.some(
1513
+ ( blockName ) =>
1514
+ ! hasBlockSupport( blockName, 'multiple', true )
1515
+ )
1516
+ ) {
1517
+ return;
1518
+ }
1500
1519
 
1501
- const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
1502
- const lastSelectedIndex = select.getBlockIndex(
1503
- last( castArray( clientIds ) )
1504
- );
1505
- const clonedBlocks = blocks.map( ( block ) =>
1506
- __experimentalCloneSanitizedBlock( block )
1507
- );
1508
- dispatch.insertBlocks(
1509
- clonedBlocks,
1510
- lastSelectedIndex + 1,
1511
- rootClientId,
1512
- updateSelection
1513
- );
1514
- if ( clonedBlocks.length > 1 && updateSelection ) {
1515
- dispatch.multiSelect(
1516
- first( clonedBlocks ).clientId,
1517
- last( clonedBlocks ).clientId
1520
+ const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
1521
+ const clientIdsArray = castArray( clientIds );
1522
+ const lastSelectedIndex = select.getBlockIndex(
1523
+ clientIdsArray[ clientIdsArray.length - 1 ]
1518
1524
  );
1519
- }
1520
- return clonedBlocks.map( ( block ) => block.clientId );
1521
- };
1525
+ const clonedBlocks = blocks.map( ( block ) =>
1526
+ __experimentalCloneSanitizedBlock( block )
1527
+ );
1528
+ dispatch.insertBlocks(
1529
+ clonedBlocks,
1530
+ lastSelectedIndex + 1,
1531
+ rootClientId,
1532
+ updateSelection
1533
+ );
1534
+ if ( clonedBlocks.length > 1 && updateSelection ) {
1535
+ dispatch.multiSelect(
1536
+ clonedBlocks[ 0 ].clientId,
1537
+ clonedBlocks[ clonedBlocks.length - 1 ].clientId
1538
+ );
1539
+ }
1540
+ return clonedBlocks.map( ( block ) => block.clientId );
1541
+ };
1522
1542
 
1523
1543
  /**
1524
1544
  * Action that inserts an empty block before a given block.
1525
1545
  *
1526
1546
  * @param {string} clientId
1527
1547
  */
1528
- export const insertBeforeBlock = ( clientId ) => ( { select, dispatch } ) => {
1529
- if ( ! clientId ) {
1530
- return;
1531
- }
1532
- const rootClientId = select.getBlockRootClientId( clientId );
1533
- const isLocked = select.getTemplateLock( rootClientId );
1534
- if ( isLocked ) {
1535
- return;
1536
- }
1548
+ export const insertBeforeBlock =
1549
+ ( clientId ) =>
1550
+ ( { select, dispatch } ) => {
1551
+ if ( ! clientId ) {
1552
+ return;
1553
+ }
1554
+ const rootClientId = select.getBlockRootClientId( clientId );
1555
+ const isLocked = select.getTemplateLock( rootClientId );
1556
+ if ( isLocked ) {
1557
+ return;
1558
+ }
1537
1559
 
1538
- const firstSelectedIndex = select.getBlockIndex( clientId );
1539
- return dispatch.insertDefaultBlock( {}, rootClientId, firstSelectedIndex );
1540
- };
1560
+ const firstSelectedIndex = select.getBlockIndex( clientId );
1561
+ return dispatch.insertDefaultBlock(
1562
+ {},
1563
+ rootClientId,
1564
+ firstSelectedIndex
1565
+ );
1566
+ };
1541
1567
 
1542
1568
  /**
1543
1569
  * Action that inserts an empty block after a given block.
1544
1570
  *
1545
1571
  * @param {string} clientId
1546
1572
  */
1547
- export const insertAfterBlock = ( clientId ) => ( { select, dispatch } ) => {
1548
- if ( ! clientId ) {
1549
- return;
1550
- }
1551
- const rootClientId = select.getBlockRootClientId( clientId );
1552
- const isLocked = select.getTemplateLock( rootClientId );
1553
- if ( isLocked ) {
1554
- return;
1555
- }
1573
+ export const insertAfterBlock =
1574
+ ( clientId ) =>
1575
+ ( { select, dispatch } ) => {
1576
+ if ( ! clientId ) {
1577
+ return;
1578
+ }
1579
+ const rootClientId = select.getBlockRootClientId( clientId );
1580
+ const isLocked = select.getTemplateLock( rootClientId );
1581
+ if ( isLocked ) {
1582
+ return;
1583
+ }
1556
1584
 
1557
- const firstSelectedIndex = select.getBlockIndex( clientId );
1558
- return dispatch.insertDefaultBlock(
1559
- {},
1560
- rootClientId,
1561
- firstSelectedIndex + 1
1562
- );
1563
- };
1585
+ const firstSelectedIndex = select.getBlockIndex( clientId );
1586
+ return dispatch.insertDefaultBlock(
1587
+ {},
1588
+ rootClientId,
1589
+ firstSelectedIndex + 1
1590
+ );
1591
+ };
1564
1592
 
1565
1593
  /**
1566
1594
  * Action that toggles the highlighted block state.
@@ -1581,11 +1609,13 @@ export function toggleBlockHighlight( clientId, isHighlighted ) {
1581
1609
  *
1582
1610
  * @param {string} clientId Target block client ID.
1583
1611
  */
1584
- export const flashBlock = ( clientId ) => async ( { dispatch } ) => {
1585
- dispatch( toggleBlockHighlight( clientId, true ) );
1586
- await new Promise( ( resolve ) => setTimeout( resolve, 150 ) );
1587
- dispatch( toggleBlockHighlight( clientId, false ) );
1588
- };
1612
+ export const flashBlock =
1613
+ ( clientId ) =>
1614
+ async ( { dispatch } ) => {
1615
+ dispatch( toggleBlockHighlight( clientId, true ) );
1616
+ await new Promise( ( resolve ) => setTimeout( resolve, 150 ) );
1617
+ dispatch( toggleBlockHighlight( clientId, false ) );
1618
+ };
1589
1619
 
1590
1620
  /**
1591
1621
  * Action that sets whether a block has controlled inner blocks.