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