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