@wordpress/block-editor 7.0.4 → 8.0.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 (347) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +31 -0
  3. package/build/components/alignment-control/ui.js +1 -2
  4. package/build/components/alignment-control/ui.js.map +1 -1
  5. package/build/components/block-icon/index.js +5 -1
  6. package/build/components/block-icon/index.js.map +1 -1
  7. package/build/components/block-inspector/index.js +4 -0
  8. package/build/components/block-inspector/index.js.map +1 -1
  9. package/build/components/block-list/index.native.js +1 -1
  10. package/build/components/block-list/index.native.js.map +1 -1
  11. package/build/components/block-list/use-block-props/use-multi-selection.js +21 -8
  12. package/build/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
  13. package/build/components/block-navigation/dropdown.js +0 -1
  14. package/build/components/block-navigation/dropdown.js.map +1 -1
  15. package/build/components/block-patterns-list/index.js +1 -8
  16. package/build/components/block-patterns-list/index.js.map +1 -1
  17. package/build/components/block-settings/container.native.js +5 -2
  18. package/build/components/block-settings/container.native.js.map +1 -1
  19. package/build/components/block-settings-menu/block-settings-dropdown.js +22 -2
  20. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  21. package/build/components/block-styles/preview.native.js +2 -2
  22. package/build/components/block-styles/preview.native.js.map +1 -1
  23. package/build/components/colors-gradients/control.js +8 -47
  24. package/build/components/colors-gradients/control.js.map +1 -1
  25. package/build/components/colors-gradients/panel-color-gradient-settings.js +81 -6
  26. package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  27. package/build/components/duotone-control/index.js +5 -2
  28. package/build/components/duotone-control/index.js.map +1 -1
  29. package/build/components/font-appearance-control/index.js +27 -15
  30. package/build/components/font-appearance-control/index.js.map +1 -1
  31. package/build/components/iframe/index.js +1 -1
  32. package/build/components/iframe/index.js.map +1 -1
  33. package/build/components/index.js +20 -2
  34. package/build/components/index.js.map +1 -1
  35. package/build/components/index.native.js +2 -2
  36. package/build/components/index.native.js.map +1 -1
  37. package/build/components/inner-blocks/index.js +5 -4
  38. package/build/components/inner-blocks/index.js.map +1 -1
  39. package/build/components/inner-blocks/index.native.js +4 -3
  40. package/build/components/inner-blocks/index.native.js.map +1 -1
  41. package/build/components/inserter/block-patterns-explorer/explorer.js +62 -0
  42. package/build/components/inserter/block-patterns-explorer/explorer.js.map +1 -0
  43. package/build/components/inserter/block-patterns-explorer/patterns-list.js +111 -0
  44. package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -0
  45. package/build/components/inserter/block-patterns-explorer/sidebar.js +78 -0
  46. package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -0
  47. package/build/components/inserter/block-patterns-tab.js +74 -45
  48. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  49. package/build/components/inserter/hooks/use-block-type-impressions.native.js +4 -7
  50. package/build/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
  51. package/build/components/inserter/pattern-panel.js +19 -10
  52. package/build/components/inserter/pattern-panel.js.map +1 -1
  53. package/build/components/inspector-controls/groups.js +3 -1
  54. package/build/components/inspector-controls/groups.js.map +1 -1
  55. package/build/components/letter-spacing-control/index.js +9 -6
  56. package/build/components/letter-spacing-control/index.js.map +1 -1
  57. package/build/components/link-control/index.js +88 -35
  58. package/build/components/link-control/index.js.map +1 -1
  59. package/build/components/link-control/link-preview.js +19 -6
  60. package/build/components/link-control/link-preview.js.map +1 -1
  61. package/build/components/link-control/search-input.js +12 -3
  62. package/build/components/link-control/search-input.js.map +1 -1
  63. package/build/components/list-view/block.js +49 -23
  64. package/build/components/list-view/block.js.map +1 -1
  65. package/build/components/list-view/branch.js +92 -73
  66. package/build/components/list-view/branch.js.map +1 -1
  67. package/build/components/list-view/index.js +39 -16
  68. package/build/components/list-view/index.js.map +1 -1
  69. package/build/components/list-view/leaf.js +1 -1
  70. package/build/components/list-view/leaf.js.map +1 -1
  71. package/build/components/list-view/use-list-view-client-ids.js +8 -58
  72. package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
  73. package/build/components/rich-text/embed-handler-picker.native.js +1 -0
  74. package/build/components/rich-text/embed-handler-picker.native.js.map +1 -1
  75. package/build/components/rich-text/format-edit.js +28 -2
  76. package/build/components/rich-text/format-edit.js.map +1 -1
  77. package/build/components/rich-text/format-toolbar/index.js +2 -1
  78. package/build/components/rich-text/format-toolbar/index.js.map +1 -1
  79. package/build/components/url-input/index.js +11 -4
  80. package/build/components/url-input/index.js.map +1 -1
  81. package/build/components/use-setting/index.js +48 -9
  82. package/build/components/use-setting/index.js.map +1 -1
  83. package/build/hooks/border.js +5 -5
  84. package/build/hooks/border.js.map +1 -1
  85. package/build/hooks/color-panel.js +2 -1
  86. package/build/hooks/color-panel.js.map +1 -1
  87. package/build/hooks/duotone.js +16 -5
  88. package/build/hooks/duotone.js.map +1 -1
  89. package/build/hooks/font-appearance.js +49 -6
  90. package/build/hooks/font-appearance.js.map +1 -1
  91. package/build/hooks/font-family.js +37 -16
  92. package/build/hooks/font-family.js.map +1 -1
  93. package/build/hooks/font-size.js +51 -9
  94. package/build/hooks/font-size.js.map +1 -1
  95. package/build/hooks/index.js +8 -0
  96. package/build/hooks/index.js.map +1 -1
  97. package/build/hooks/index.native.js +8 -0
  98. package/build/hooks/index.native.js.map +1 -1
  99. package/build/hooks/letter-spacing.js +44 -7
  100. package/build/hooks/letter-spacing.js.map +1 -1
  101. package/build/hooks/line-height.js +45 -8
  102. package/build/hooks/line-height.js.map +1 -1
  103. package/build/hooks/margin.js +1 -1
  104. package/build/hooks/margin.js.map +1 -1
  105. package/build/hooks/padding.js +1 -1
  106. package/build/hooks/padding.js.map +1 -1
  107. package/build/hooks/text-decoration.js +42 -6
  108. package/build/hooks/text-decoration.js.map +1 -1
  109. package/build/hooks/text-transform.js +42 -6
  110. package/build/hooks/text-transform.js.map +1 -1
  111. package/build/hooks/typography.js +108 -8
  112. package/build/hooks/typography.js.map +1 -1
  113. package/build/hooks/use-cached-truthy.js +29 -0
  114. package/build/hooks/use-cached-truthy.js.map +1 -0
  115. package/build/index.js +7 -0
  116. package/build/index.js.map +1 -1
  117. package/build/layouts/flex.js +120 -28
  118. package/build/layouts/flex.js.map +1 -1
  119. package/build/store/actions.js +303 -265
  120. package/build/store/actions.js.map +1 -1
  121. package/build/store/index.js +1 -3
  122. package/build/store/index.js.map +1 -1
  123. package/build/store/reducer.js +23 -22
  124. package/build/store/reducer.js.map +1 -1
  125. package/build/store/selectors.js +44 -35
  126. package/build/store/selectors.js.map +1 -1
  127. package/build-module/components/alignment-control/ui.js +1 -2
  128. package/build-module/components/alignment-control/ui.js.map +1 -1
  129. package/build-module/components/block-icon/index.js +5 -1
  130. package/build-module/components/block-icon/index.js.map +1 -1
  131. package/build-module/components/block-inspector/index.js +4 -0
  132. package/build-module/components/block-inspector/index.js.map +1 -1
  133. package/build-module/components/block-list/index.native.js +1 -1
  134. package/build-module/components/block-list/index.native.js.map +1 -1
  135. package/build-module/components/block-list/use-block-props/use-multi-selection.js +21 -8
  136. package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
  137. package/build-module/components/block-navigation/dropdown.js +0 -1
  138. package/build-module/components/block-navigation/dropdown.js.map +1 -1
  139. package/build-module/components/block-patterns-list/index.js +1 -6
  140. package/build-module/components/block-patterns-list/index.js.map +1 -1
  141. package/build-module/components/block-settings/container.native.js +6 -3
  142. package/build-module/components/block-settings/container.native.js.map +1 -1
  143. package/build-module/components/block-settings-menu/block-settings-dropdown.js +24 -4
  144. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  145. package/build-module/components/block-styles/preview.native.js +2 -2
  146. package/build-module/components/block-styles/preview.native.js.map +1 -1
  147. package/build-module/components/colors-gradients/control.js +12 -53
  148. package/build-module/components/colors-gradients/control.js.map +1 -1
  149. package/build-module/components/colors-gradients/panel-color-gradient-settings.js +82 -6
  150. package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  151. package/build-module/components/duotone-control/index.js +5 -2
  152. package/build-module/components/duotone-control/index.js.map +1 -1
  153. package/build-module/components/font-appearance-control/index.js +23 -15
  154. package/build-module/components/font-appearance-control/index.js.map +1 -1
  155. package/build-module/components/iframe/index.js +1 -1
  156. package/build-module/components/iframe/index.js.map +1 -1
  157. package/build-module/components/index.js +3 -1
  158. package/build-module/components/index.js.map +1 -1
  159. package/build-module/components/index.native.js +1 -1
  160. package/build-module/components/index.native.js.map +1 -1
  161. package/build-module/components/inner-blocks/index.js +6 -5
  162. package/build-module/components/inner-blocks/index.js.map +1 -1
  163. package/build-module/components/inner-blocks/index.native.js +5 -4
  164. package/build-module/components/inner-blocks/index.native.js.map +1 -1
  165. package/build-module/components/inserter/block-patterns-explorer/explorer.js +50 -0
  166. package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +1 -0
  167. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +92 -0
  168. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -0
  169. package/build-module/components/inserter/block-patterns-explorer/sidebar.js +69 -0
  170. package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -0
  171. package/build-module/components/inserter/block-patterns-tab.js +75 -46
  172. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  173. package/build-module/components/inserter/hooks/use-block-type-impressions.native.js +4 -7
  174. package/build-module/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
  175. package/build-module/components/inserter/pattern-panel.js +21 -13
  176. package/build-module/components/inserter/pattern-panel.js.map +1 -1
  177. package/build-module/components/inspector-controls/groups.js +3 -1
  178. package/build-module/components/inspector-controls/groups.js.map +1 -1
  179. package/build-module/components/letter-spacing-control/index.js +9 -6
  180. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  181. package/build-module/components/link-control/index.js +88 -36
  182. package/build-module/components/link-control/index.js.map +1 -1
  183. package/build-module/components/link-control/link-preview.js +19 -7
  184. package/build-module/components/link-control/link-preview.js.map +1 -1
  185. package/build-module/components/link-control/search-input.js +11 -3
  186. package/build-module/components/link-control/search-input.js.map +1 -1
  187. package/build-module/components/list-view/block.js +49 -24
  188. package/build-module/components/list-view/block.js.map +1 -1
  189. package/build-module/components/list-view/branch.js +92 -73
  190. package/build-module/components/list-view/branch.js.map +1 -1
  191. package/build-module/components/list-view/index.js +41 -18
  192. package/build-module/components/list-view/index.js.map +1 -1
  193. package/build-module/components/list-view/leaf.js +1 -1
  194. package/build-module/components/list-view/leaf.js.map +1 -1
  195. package/build-module/components/list-view/use-list-view-client-ids.js +8 -58
  196. package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
  197. package/build-module/components/rich-text/embed-handler-picker.native.js +1 -0
  198. package/build-module/components/rich-text/embed-handler-picker.native.js.map +1 -1
  199. package/build-module/components/rich-text/format-edit.js +28 -3
  200. package/build-module/components/rich-text/format-edit.js.map +1 -1
  201. package/build-module/components/rich-text/format-toolbar/index.js +2 -1
  202. package/build-module/components/rich-text/format-toolbar/index.js.map +1 -1
  203. package/build-module/components/url-input/index.js +11 -4
  204. package/build-module/components/url-input/index.js.map +1 -1
  205. package/build-module/components/use-setting/index.js +48 -9
  206. package/build-module/components/use-setting/index.js.map +1 -1
  207. package/build-module/hooks/border.js +5 -5
  208. package/build-module/hooks/border.js.map +1 -1
  209. package/build-module/hooks/color-panel.js +2 -1
  210. package/build-module/hooks/color-panel.js.map +1 -1
  211. package/build-module/hooks/duotone.js +16 -5
  212. package/build-module/hooks/duotone.js.map +1 -1
  213. package/build-module/hooks/font-appearance.js +45 -6
  214. package/build-module/hooks/font-appearance.js.map +1 -1
  215. package/build-module/hooks/font-family.js +33 -16
  216. package/build-module/hooks/font-family.js.map +1 -1
  217. package/build-module/hooks/font-size.js +47 -9
  218. package/build-module/hooks/font-size.js.map +1 -1
  219. package/build-module/hooks/index.js +1 -0
  220. package/build-module/hooks/index.js.map +1 -1
  221. package/build-module/hooks/index.native.js +1 -0
  222. package/build-module/hooks/index.native.js.map +1 -1
  223. package/build-module/hooks/letter-spacing.js +40 -7
  224. package/build-module/hooks/letter-spacing.js.map +1 -1
  225. package/build-module/hooks/line-height.js +41 -8
  226. package/build-module/hooks/line-height.js.map +1 -1
  227. package/build-module/hooks/margin.js +1 -1
  228. package/build-module/hooks/margin.js.map +1 -1
  229. package/build-module/hooks/padding.js +1 -1
  230. package/build-module/hooks/padding.js.map +1 -1
  231. package/build-module/hooks/text-decoration.js +38 -6
  232. package/build-module/hooks/text-decoration.js.map +1 -1
  233. package/build-module/hooks/text-transform.js +38 -6
  234. package/build-module/hooks/text-transform.js.map +1 -1
  235. package/build-module/hooks/typography.js +117 -17
  236. package/build-module/hooks/typography.js.map +1 -1
  237. package/build-module/hooks/use-cached-truthy.js +21 -0
  238. package/build-module/hooks/use-cached-truthy.js.map +1 -0
  239. package/build-module/index.js +1 -1
  240. package/build-module/index.js.map +1 -1
  241. package/build-module/layouts/flex.js +124 -32
  242. package/build-module/layouts/flex.js.map +1 -1
  243. package/build-module/store/actions.js +266 -241
  244. package/build-module/store/actions.js.map +1 -1
  245. package/build-module/store/index.js +1 -2
  246. package/build-module/store/index.js.map +1 -1
  247. package/build-module/store/reducer.js +23 -22
  248. package/build-module/store/reducer.js.map +1 -1
  249. package/build-module/store/selectors.js +42 -30
  250. package/build-module/store/selectors.js.map +1 -1
  251. package/build-style/style-rtl.css +160 -57
  252. package/build-style/style.css +160 -57
  253. package/package.json +13 -14
  254. package/src/components/alignment-control/test/__snapshots__/index.js.snap +0 -2
  255. package/src/components/alignment-control/ui.js +1 -4
  256. package/src/components/block-draggable/style.scss +19 -4
  257. package/src/components/block-icon/index.js +4 -1
  258. package/src/components/block-inspector/index.js +5 -0
  259. package/src/components/block-list/index.native.js +1 -1
  260. package/src/components/block-list/use-block-props/use-multi-selection.js +27 -7
  261. package/src/components/block-navigation/dropdown.js +0 -1
  262. package/src/components/block-patterns-list/index.js +1 -8
  263. package/src/components/block-patterns-list/style.scss +22 -12
  264. package/src/components/block-settings/container.native.js +7 -0
  265. package/src/components/block-settings-menu/block-settings-dropdown.js +19 -7
  266. package/src/components/block-styles/preview.native.js +2 -2
  267. package/src/components/block-switcher/test/__snapshots__/index.js.snap +1 -1
  268. package/src/components/color-palette/test/__snapshots__/control.js.snap +88 -63
  269. package/src/components/colors-gradients/control.js +19 -62
  270. package/src/components/colors-gradients/panel-color-gradient-settings.js +76 -6
  271. package/src/components/colors-gradients/style.scss +3 -14
  272. package/src/components/colors-gradients/test/control.js +0 -16
  273. package/src/components/duotone-control/index.js +6 -0
  274. package/src/components/duotone-control/style.scss +27 -12
  275. package/src/components/font-appearance-control/index.js +22 -14
  276. package/src/components/iframe/index.js +1 -1
  277. package/src/components/index.js +3 -4
  278. package/src/components/index.native.js +1 -4
  279. package/src/components/inner-blocks/index.js +4 -4
  280. package/src/components/inner-blocks/index.native.js +7 -4
  281. package/src/components/inserter/block-patterns-explorer/explorer.js +50 -0
  282. package/src/components/inserter/block-patterns-explorer/patterns-list.js +122 -0
  283. package/src/components/inserter/block-patterns-explorer/sidebar.js +73 -0
  284. package/src/components/inserter/block-patterns-tab.js +107 -80
  285. package/src/components/inserter/hooks/use-block-type-impressions.native.js +14 -21
  286. package/src/components/inserter/pattern-panel.js +33 -16
  287. package/src/components/inserter/style.scss +64 -1
  288. package/src/components/inserter/test/block-types-tab.native.js +1 -1
  289. package/src/components/inserter/test/fixtures/index.native.js +12 -0
  290. package/src/components/inspector-controls/groups.js +4 -0
  291. package/src/components/letter-spacing-control/index.js +12 -6
  292. package/src/components/link-control/README.md +7 -0
  293. package/src/components/link-control/index.js +99 -34
  294. package/src/components/link-control/link-preview.js +21 -9
  295. package/src/components/link-control/search-input.js +9 -3
  296. package/src/components/link-control/style.scss +32 -16
  297. package/src/components/link-control/test/index.js +179 -4
  298. package/src/components/list-view/block.js +67 -23
  299. package/src/components/list-view/branch.js +113 -91
  300. package/src/components/list-view/index.js +58 -19
  301. package/src/components/list-view/leaf.js +1 -1
  302. package/src/components/list-view/style.scss +14 -3
  303. package/src/components/list-view/use-list-view-client-ids.js +7 -66
  304. package/src/components/rich-text/embed-handler-picker.native.js +1 -0
  305. package/src/components/rich-text/format-edit.js +36 -2
  306. package/src/components/rich-text/format-toolbar/index.js +3 -0
  307. package/src/components/url-input/index.js +14 -4
  308. package/src/components/use-setting/index.js +49 -11
  309. package/src/hooks/border.js +8 -11
  310. package/src/hooks/color-panel.js +1 -0
  311. package/src/hooks/duotone.js +21 -7
  312. package/src/hooks/font-appearance.js +38 -7
  313. package/src/hooks/font-family.js +29 -13
  314. package/src/hooks/font-size.js +42 -6
  315. package/src/hooks/index.js +1 -0
  316. package/src/hooks/index.native.js +1 -0
  317. package/src/hooks/layout.scss +3 -1
  318. package/src/hooks/letter-spacing.js +35 -7
  319. package/src/hooks/line-height.js +37 -9
  320. package/src/hooks/margin.js +1 -1
  321. package/src/hooks/padding.js +1 -1
  322. package/src/hooks/text-decoration.js +34 -6
  323. package/src/hooks/text-transform.js +34 -6
  324. package/src/hooks/typography.js +165 -15
  325. package/src/hooks/typography.scss +16 -0
  326. package/src/hooks/use-cached-truthy.js +20 -0
  327. package/src/index.js +1 -0
  328. package/src/layouts/flex.js +137 -41
  329. package/src/store/actions.js +223 -391
  330. package/src/store/index.js +1 -2
  331. package/src/store/reducer.js +36 -18
  332. package/src/store/selectors.js +52 -47
  333. package/src/store/test/actions.js +395 -694
  334. package/src/store/test/selectors.js +79 -21
  335. package/src/style.scss +1 -1
  336. package/src/utils/test/parse-css-unit-to-px.js +127 -167
  337. package/build/components/text-decoration-and-transform/index.js +0 -39
  338. package/build/components/text-decoration-and-transform/index.js.map +0 -1
  339. package/build/store/controls.js +0 -44
  340. package/build/store/controls.js.map +0 -1
  341. package/build-module/components/text-decoration-and-transform/index.js +0 -30
  342. package/build-module/components/text-decoration-and-transform/index.js.map +0 -1
  343. package/build-module/store/controls.js +0 -32
  344. package/build-module/store/controls.js.map +0 -1
  345. package/src/components/text-decoration-and-transform/index.js +0 -36
  346. package/src/components/text-decoration-and-transform/style.scss +0 -3
  347. package/src/store/controls.js +0 -39
@@ -9,56 +9,57 @@ import { castArray, findKey, first, isObject, last, some } from 'lodash';
9
9
  import { cloneBlock, __experimentalCloneSanitizedBlock, createBlock, doBlocksMatchTemplate, getBlockType, getDefaultBlockName, hasBlockSupport, switchToBlockType, synchronizeBlocksWithTemplate } from '@wordpress/blocks';
10
10
  import { speak } from '@wordpress/a11y';
11
11
  import { __, _n, sprintf } from '@wordpress/i18n';
12
- import { controls } from '@wordpress/data';
13
12
  import { create, insert, remove, toHTMLString } from '@wordpress/rich-text';
14
13
  import deprecated from '@wordpress/deprecated';
15
14
  /**
16
- * Internal dependencies
17
- */
18
-
19
- import { __unstableMarkAutomaticChangeFinalControl } from '../store/controls';
20
- import { STORE_NAME as blockEditorStoreName } from './constants';
21
- /**
22
- * Generator which will yield a default block insert action if there
23
- * are no other blocks at the root of the editor. This generator should be used
15
+ * Action which will insert a default block insert action if there
16
+ * are no other blocks at the root of the editor. This action should be used
24
17
  * in actions which may result in no blocks remaining in the editor (removal,
25
18
  * replacement, etc).
26
19
  */
27
20
 
28
- function* ensureDefaultBlock() {
29
- const count = yield controls.select(blockEditorStoreName, 'getBlockCount'); // To avoid a focus loss when removing the last block, assure there is
21
+ const ensureDefaultBlock = () => ({
22
+ select,
23
+ dispatch
24
+ }) => {
25
+ // To avoid a focus loss when removing the last block, assure there is
30
26
  // always a default block if the last of the blocks have been removed.
27
+ const count = select.getBlockCount();
31
28
 
32
- if (count === 0) {
33
- const {
34
- __unstableHasCustomAppender
35
- } = yield controls.select(blockEditorStoreName, 'getSettings'); // If there's an custom appender, don't insert default block.
36
- // We have to remember to manually move the focus elsewhere to
37
- // prevent it from being lost though.
29
+ if (count > 0) {
30
+ return;
31
+ } // If there's an custom appender, don't insert default block.
32
+ // We have to remember to manually move the focus elsewhere to
33
+ // prevent it from being lost though.
38
34
 
39
- if (__unstableHasCustomAppender) {
40
- return;
41
- }
42
35
 
43
- return yield insertDefaultBlock();
36
+ const {
37
+ __unstableHasCustomAppender
38
+ } = select.getSettings();
39
+
40
+ if (__unstableHasCustomAppender) {
41
+ return;
44
42
  }
45
- }
43
+
44
+ dispatch.insertDefaultBlock();
45
+ };
46
46
  /**
47
- * Returns an action object used in signalling that blocks state should be
48
- * reset to the specified array of blocks, taking precedence over any other
49
- * content reflected as an edit in state.
47
+ * Action that resets blocks state to the specified array of blocks, taking precedence
48
+ * over any other content reflected as an edit in state.
50
49
  *
51
50
  * @param {Array} blocks Array of blocks.
52
51
  */
53
52
 
54
53
 
55
- export function* resetBlocks(blocks) {
56
- yield {
54
+ export const resetBlocks = blocks => ({
55
+ dispatch
56
+ }) => {
57
+ dispatch({
57
58
  type: 'RESET_BLOCKS',
58
59
  blocks
59
- };
60
- return yield* validateBlocksToTemplate(blocks);
61
- }
60
+ });
61
+ dispatch(validateBlocksToTemplate(blocks));
62
+ };
62
63
  /**
63
64
  * Block validity is a function of blocks state (at the point of a
64
65
  * reset) and the template setting. As a compromise to its placement
@@ -68,20 +69,23 @@ export function* resetBlocks(blocks) {
68
69
  * @param {Array} blocks Array of blocks.
69
70
  */
70
71
 
71
- export function* validateBlocksToTemplate(blocks) {
72
- const template = yield controls.select(blockEditorStoreName, 'getTemplate');
73
- const templateLock = yield controls.select(blockEditorStoreName, 'getTemplateLock'); // Unlocked templates are considered always valid because they act
72
+ export const validateBlocksToTemplate = blocks => ({
73
+ select,
74
+ dispatch
75
+ }) => {
76
+ const template = select.getTemplate();
77
+ const templateLock = select.getTemplateLock(); // Unlocked templates are considered always valid because they act
74
78
  // as default values only.
75
79
 
76
80
  const isBlocksValidToTemplate = !template || templateLock !== 'all' || doBlocksMatchTemplate(blocks, template); // Update if validity has changed.
77
81
 
78
- const isValidTemplate = yield controls.select(blockEditorStoreName, 'isValidTemplate');
82
+ const isValidTemplate = select.isValidTemplate();
79
83
 
80
84
  if (isBlocksValidToTemplate !== isValidTemplate) {
81
- yield setTemplateValidity(isBlocksValidToTemplate);
85
+ dispatch.setTemplateValidity(isBlocksValidToTemplate);
82
86
  return isBlocksValidToTemplate;
83
87
  }
84
- }
88
+ };
85
89
  /**
86
90
  * A block selection object.
87
91
  *
@@ -138,8 +142,7 @@ export function receiveBlocks(blocks) {
138
142
  };
139
143
  }
140
144
  /**
141
- * Returns an action object used in signalling that the multiple blocks'
142
- * attributes with the specified client IDs have been updated.
145
+ * Action that updates attributes of multiple blocks with the specified client IDs.
143
146
  *
144
147
  * @param {string|string[]} clientIds Block client IDs.
145
148
  * @param {Object} attributes Block attributes to be merged. Should be keyed by clientIds if
@@ -157,8 +160,7 @@ export function updateBlockAttributes(clientIds, attributes, uniqueByBlock = fal
157
160
  };
158
161
  }
159
162
  /**
160
- * Returns an action object used in signalling that the block with the
161
- * specified client ID has been updated.
163
+ * Action that updates the block with the specified client ID.
162
164
  *
163
165
  * @param {string} clientId Block client ID.
164
166
  * @param {Object} updates Block attributes to be merged.
@@ -203,14 +205,16 @@ export function selectBlock(clientId, initialPosition = 0) {
203
205
  * @param {string} clientId Block client ID.
204
206
  */
205
207
 
206
- export function* selectPreviousBlock(clientId) {
207
- const previousBlockClientId = yield controls.select(blockEditorStoreName, 'getPreviousBlockClientId', clientId);
208
+ export const selectPreviousBlock = clientId => ({
209
+ select,
210
+ dispatch
211
+ }) => {
212
+ const previousBlockClientId = select.getPreviousBlockClientId(clientId);
208
213
 
209
214
  if (previousBlockClientId) {
210
- yield selectBlock(previousBlockClientId, -1);
211
- return [previousBlockClientId];
215
+ dispatch.selectBlock(previousBlockClientId, -1);
212
216
  }
213
- }
217
+ };
214
218
  /**
215
219
  * Yields action objects used in signalling that the block following the given
216
220
  * clientId should be selected.
@@ -218,16 +222,18 @@ export function* selectPreviousBlock(clientId) {
218
222
  * @param {string} clientId Block client ID.
219
223
  */
220
224
 
221
- export function* selectNextBlock(clientId) {
222
- const nextBlockClientId = yield controls.select(blockEditorStoreName, 'getNextBlockClientId', clientId);
225
+ export const selectNextBlock = clientId => ({
226
+ select,
227
+ dispatch
228
+ }) => {
229
+ const nextBlockClientId = select.getNextBlockClientId(clientId);
223
230
 
224
231
  if (nextBlockClientId) {
225
- yield selectBlock(nextBlockClientId);
226
- return [nextBlockClientId];
232
+ dispatch.selectBlock(nextBlockClientId);
227
233
  }
228
- }
234
+ };
229
235
  /**
230
- * Returns an action object used in signalling that a block multi-selection has started.
236
+ * Action that starts block multi-selection.
231
237
  *
232
238
  * @return {Object} Action object.
233
239
  */
@@ -238,7 +244,7 @@ export function startMultiSelect() {
238
244
  };
239
245
  }
240
246
  /**
241
- * Returns an action object used in signalling that block multi-selection stopped.
247
+ * Action that stops block multi-selection.
242
248
  *
243
249
  * @return {Object} Action object.
244
250
  */
@@ -249,32 +255,35 @@ export function stopMultiSelect() {
249
255
  };
250
256
  }
251
257
  /**
252
- * Returns an action object used in signalling that block multi-selection changed.
258
+ * Action that changes block multi-selection.
253
259
  *
254
260
  * @param {string} start First block of the multi selection.
255
261
  * @param {string} end Last block of the multiselection.
256
262
  */
257
263
 
258
- export function* multiSelect(start, end) {
259
- const startBlockRootClientId = yield controls.select(blockEditorStoreName, 'getBlockRootClientId', start);
260
- const endBlockRootClientId = yield controls.select(blockEditorStoreName, 'getBlockRootClientId', end); // Only allow block multi-selections at the same level.
264
+ export const multiSelect = (start, end) => ({
265
+ select,
266
+ dispatch
267
+ }) => {
268
+ const startBlockRootClientId = select.getBlockRootClientId(start);
269
+ const endBlockRootClientId = select.getBlockRootClientId(end); // Only allow block multi-selections at the same level.
261
270
 
262
271
  if (startBlockRootClientId !== endBlockRootClientId) {
263
272
  return;
264
273
  }
265
274
 
266
- yield {
275
+ dispatch({
267
276
  type: 'MULTI_SELECT',
268
277
  start,
269
278
  end
270
- };
271
- const blockCount = yield controls.select(blockEditorStoreName, 'getSelectedBlockCount');
279
+ });
280
+ const blockCount = select.getSelectedBlockCount();
272
281
  speak(sprintf(
273
282
  /* translators: %s: number of selected blocks */
274
283
  _n('%s block selected.', '%s blocks selected.', blockCount), blockCount), 'assertive');
275
- }
284
+ };
276
285
  /**
277
- * Returns an action object used in signalling that the block selection is cleared.
286
+ * Action that clears the block selection.
278
287
  *
279
288
  * @return {Object} Action object.
280
289
  */
@@ -285,7 +294,7 @@ export function clearSelectedBlock() {
285
294
  };
286
295
  }
287
296
  /**
288
- * Returns an action object that enables or disables block selection.
297
+ * Action that enables or disables block selection.
289
298
  *
290
299
  * @param {boolean} [isSelectionEnabled=true] Whether block selection should
291
300
  * be enabled.
@@ -337,8 +346,7 @@ function getBlocksWithDefaultStylesApplied(blocks, blockEditorSettings) {
337
346
  /* eslint-disable jsdoc/valid-types */
338
347
 
339
348
  /**
340
- * Returns an action object signalling that a blocks should be replaced with
341
- * one or more replacement blocks.
349
+ * Action that replaces given blocks with one or more replacement blocks.
342
350
  *
343
351
  * @param {(string|string[])} clientIds Block client ID(s) to replace.
344
352
  * @param {(Object|Object[])} blocks Replacement block(s).
@@ -346,26 +354,29 @@ function getBlocksWithDefaultStylesApplied(blocks, blockEditorSettings) {
346
354
  * @param {0|-1|null} initialPosition Index of caret after in the selected block after the operation.
347
355
  * @param {?Object} meta Optional Meta values to be passed to the action object.
348
356
  *
349
- * @yield {Object} Action object.
357
+ * @return {Object} Action object.
350
358
  */
351
359
 
352
360
 
353
- export function* replaceBlocks(clientIds, blocks, indexToSelect, initialPosition = 0, meta) {
361
+ export const replaceBlocks = (clientIds, blocks, indexToSelect, initialPosition = 0, meta) => ({
362
+ select,
363
+ dispatch
364
+ }) => {
354
365
  /* eslint-enable jsdoc/valid-types */
355
366
  clientIds = castArray(clientIds);
356
- blocks = getBlocksWithDefaultStylesApplied(castArray(blocks), yield controls.select(blockEditorStoreName, 'getSettings'));
357
- const rootClientId = yield controls.select(blockEditorStoreName, 'getBlockRootClientId', first(clientIds)); // Replace is valid if the new blocks can be inserted in the root block.
367
+ blocks = getBlocksWithDefaultStylesApplied(castArray(blocks), select.getSettings());
368
+ const rootClientId = select.getBlockRootClientId(first(clientIds)); // Replace is valid if the new blocks can be inserted in the root block.
358
369
 
359
370
  for (let index = 0; index < blocks.length; index++) {
360
371
  const block = blocks[index];
361
- const canInsertBlock = yield controls.select(blockEditorStoreName, 'canInsertBlockType', block.name, rootClientId);
372
+ const canInsertBlock = select.canInsertBlockType(block.name, rootClientId);
362
373
 
363
374
  if (!canInsertBlock) {
364
375
  return;
365
376
  }
366
377
  }
367
378
 
368
- yield {
379
+ dispatch({
369
380
  type: 'REPLACE_BLOCKS',
370
381
  clientIds,
371
382
  blocks,
@@ -373,12 +384,11 @@ export function* replaceBlocks(clientIds, blocks, indexToSelect, initialPosition
373
384
  indexToSelect,
374
385
  initialPosition,
375
386
  meta
376
- };
377
- yield* ensureDefaultBlock();
378
- }
387
+ });
388
+ dispatch(ensureDefaultBlock());
389
+ };
379
390
  /**
380
- * Returns an action object signalling that a single block should be replaced
381
- * with one or more replacement blocks.
391
+ * Action that replaces a single block with one or more replacement blocks.
382
392
  *
383
393
  * @param {(string|string[])} clientId Block client ID to replace.
384
394
  * @param {(Object|Object[])} block Replacement block(s).
@@ -398,87 +408,83 @@ export function replaceBlock(clientId, block) {
398
408
  * @return {Function} Action creator.
399
409
  */
400
410
 
401
- function createOnMove(type) {
402
- return function* (clientIds, rootClientId) {
403
- const canMoveBlocks = yield controls.select(blockEditorStoreName, 'canMoveBlocks', clientIds, rootClientId); // If one of the blocks is locked or the parent is locked, we cannot move any block.
411
+ const createOnMove = type => (clientIds, rootClientId) => ({
412
+ select,
413
+ dispatch
414
+ }) => {
415
+ // If one of the blocks is locked or the parent is locked, we cannot move any block.
416
+ const canMoveBlocks = select.canMoveBlocks(clientIds, rootClientId);
404
417
 
405
- if (!canMoveBlocks) {
406
- return;
407
- }
418
+ if (!canMoveBlocks) {
419
+ return;
420
+ }
408
421
 
409
- yield {
410
- clientIds: castArray(clientIds),
411
- type,
412
- rootClientId
413
- };
414
- };
415
- }
422
+ dispatch({
423
+ type,
424
+ clientIds: castArray(clientIds),
425
+ rootClientId
426
+ });
427
+ };
416
428
 
417
429
  export const moveBlocksDown = createOnMove('MOVE_BLOCKS_DOWN');
418
430
  export const moveBlocksUp = createOnMove('MOVE_BLOCKS_UP');
419
431
  /**
420
- * Returns an action object signalling that the given blocks should be moved to
421
- * a new position.
432
+ * Action that moves given blocks to a new position.
422
433
  *
423
434
  * @param {?string} clientIds The client IDs of the blocks.
424
435
  * @param {?string} fromRootClientId Root client ID source.
425
436
  * @param {?string} toRootClientId Root client ID destination.
426
437
  * @param {number} index The index to move the blocks to.
427
- *
428
- * @yield {Object} Action object.
429
438
  */
430
439
 
431
- export function* moveBlocksToPosition(clientIds, fromRootClientId = '', toRootClientId = '', index) {
432
- const canMoveBlocks = yield controls.select(blockEditorStoreName, 'canMoveBlocks', clientIds, fromRootClientId);
433
- const canRemoveBlocks = yield controls.select(blockEditorStoreName, 'canRemoveBlocks', clientIds, fromRootClientId); // If one of the blocks is locked or the parent is locked, we cannot move any block.
440
+ export const moveBlocksToPosition = (clientIds, fromRootClientId = '', toRootClientId = '', index) => ({
441
+ select,
442
+ dispatch
443
+ }) => {
444
+ const canMoveBlocks = select.canMoveBlocks(clientIds, fromRootClientId); // If one of the blocks is locked or the parent is locked, we cannot move any block.
434
445
 
435
446
  if (!canMoveBlocks) {
436
447
  return;
448
+ } // If moving inside the same root block the move is always possible.
449
+
450
+
451
+ if (fromRootClientId !== toRootClientId) {
452
+ const canRemoveBlocks = select.canRemoveBlocks(clientIds, fromRootClientId); // If we're moving to another block, it means we're deleting blocks from
453
+ // the original block, so we need to check if removing is possible.
454
+
455
+ if (!canRemoveBlocks) {
456
+ return;
457
+ }
458
+
459
+ const canInsertBlocks = select.canInsertBlocks(clientIds, toRootClientId); // 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.
460
+
461
+ if (!canInsertBlocks) {
462
+ return;
463
+ }
437
464
  }
438
465
 
439
- const action = {
466
+ dispatch({
440
467
  type: 'MOVE_BLOCKS_TO_POSITION',
441
468
  fromRootClientId,
442
469
  toRootClientId,
443
470
  clientIds,
444
471
  index
445
- }; // If moving inside the same root block the move is always possible.
446
-
447
- if (fromRootClientId === toRootClientId) {
448
- yield action;
449
- return;
450
- } // If we're moving to another block, it means we're deleting blocks from
451
- // the original block, so we need to check if removing is possible.
452
-
453
-
454
- if (!canRemoveBlocks) {
455
- return;
456
- }
457
-
458
- const canInsertBlocks = yield controls.select(blockEditorStoreName, 'canInsertBlocks', clientIds, toRootClientId); // 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.
459
-
460
- if (canInsertBlocks) {
461
- yield action;
462
- }
463
- }
472
+ });
473
+ };
464
474
  /**
465
- * Returns an action object signalling that the given block should be moved to a
466
- * new position.
475
+ * Action that moves given block to a new position.
467
476
  *
468
477
  * @param {?string} clientId The client ID of the block.
469
478
  * @param {?string} fromRootClientId Root client ID source.
470
479
  * @param {?string} toRootClientId Root client ID destination.
471
480
  * @param {number} index The index to move the block to.
472
- *
473
- * @yield {Object} Action object.
474
481
  */
475
482
 
476
- export function* moveBlockToPosition(clientId, fromRootClientId = '', toRootClientId = '', index) {
477
- yield moveBlocksToPosition([clientId], fromRootClientId, toRootClientId, index);
483
+ export function moveBlockToPosition(clientId, fromRootClientId = '', toRootClientId = '', index) {
484
+ return moveBlocksToPosition([clientId], fromRootClientId, toRootClientId, index);
478
485
  }
479
486
  /**
480
- * Returns an action object used in signalling that a single block should be
481
- * inserted, optionally at a specific index respective a root block list.
487
+ * Action that inserts a single block, optionally at a specific index respective a root block list.
482
488
  *
483
489
  * @param {Object} block Block object to insert.
484
490
  * @param {?number} index Index at which block should be inserted.
@@ -489,14 +495,13 @@ export function* moveBlockToPosition(clientId, fromRootClientId = '', toRootClie
489
495
  * @return {Object} Action object.
490
496
  */
491
497
 
492
- export function insertBlock(block, index, rootClientId, updateSelection = true, meta) {
498
+ export function insertBlock(block, index, rootClientId, updateSelection, meta) {
493
499
  return insertBlocks([block], index, rootClientId, updateSelection, 0, meta);
494
500
  }
495
501
  /* eslint-disable jsdoc/valid-types */
496
502
 
497
503
  /**
498
- * Returns an action object used in signalling that an array of blocks should
499
- * be inserted, optionally at a specific index respective a root block list.
504
+ * Action that inserts an array of blocks, optionally at a specific index respective a root block list.
500
505
  *
501
506
  * @param {Object[]} blocks Block objects to insert.
502
507
  * @param {?number} index Index at which block should be inserted.
@@ -507,7 +512,10 @@ export function insertBlock(block, index, rootClientId, updateSelection = true,
507
512
  * @return {Object} Action object.
508
513
  */
509
514
 
510
- export function* insertBlocks(blocks, index, rootClientId, updateSelection = true, initialPosition = 0, meta) {
515
+ export const insertBlocks = (blocks, index, rootClientId, updateSelection = true, initialPosition = 0, meta) => ({
516
+ select,
517
+ dispatch
518
+ }) => {
511
519
  /* eslint-enable jsdoc/valid-types */
512
520
  if (isObject(initialPosition)) {
513
521
  meta = initialPosition;
@@ -519,11 +527,11 @@ export function* insertBlocks(blocks, index, rootClientId, updateSelection = tru
519
527
  });
520
528
  }
521
529
 
522
- blocks = getBlocksWithDefaultStylesApplied(castArray(blocks), yield controls.select(blockEditorStoreName, 'getSettings'));
530
+ blocks = getBlocksWithDefaultStylesApplied(castArray(blocks), select.getSettings());
523
531
  const allowedBlocks = [];
524
532
 
525
533
  for (const block of blocks) {
526
- const isValid = yield controls.select(blockEditorStoreName, 'canInsertBlockType', block.name, rootClientId);
534
+ const isValid = select.canInsertBlockType(block.name, rootClientId);
527
535
 
528
536
  if (isValid) {
529
537
  allowedBlocks.push(block);
@@ -531,7 +539,7 @@ export function* insertBlocks(blocks, index, rootClientId, updateSelection = tru
531
539
  }
532
540
 
533
541
  if (allowedBlocks.length) {
534
- return {
542
+ dispatch({
535
543
  type: 'INSERT_BLOCKS',
536
544
  blocks: allowedBlocks,
537
545
  index,
@@ -540,12 +548,11 @@ export function* insertBlocks(blocks, index, rootClientId, updateSelection = tru
540
548
  updateSelection,
541
549
  initialPosition: updateSelection ? initialPosition : null,
542
550
  meta
543
- };
551
+ });
544
552
  }
545
- }
553
+ };
546
554
  /**
547
- * Returns an action object used in signalling that the insertion point should
548
- * be shown.
555
+ * Action that shows the insertion point.
549
556
  *
550
557
  * @param {?string} rootClientId Optional root client ID of block list on
551
558
  * which to insert.
@@ -567,7 +574,7 @@ export function showInsertionPoint(rootClientId, index, __unstableOptions = {})
567
574
  };
568
575
  }
569
576
  /**
570
- * Returns an action object hiding the insertion point.
577
+ * Action that hides the insertion point.
571
578
  *
572
579
  * @return {Object} Action object.
573
580
  */
@@ -578,7 +585,7 @@ export function hideInsertionPoint() {
578
585
  };
579
586
  }
580
587
  /**
581
- * Returns an action object resetting the template validity.
588
+ * Action that resets the template validity.
582
589
  *
583
590
  * @param {boolean} isValid template validity flag.
584
591
  *
@@ -592,49 +599,55 @@ export function setTemplateValidity(isValid) {
592
599
  };
593
600
  }
594
601
  /**
595
- * Returns an action object synchronize the template with the list of blocks
602
+ * Action that synchronizes the template with the list of blocks.
596
603
  *
597
604
  * @return {Object} Action object.
598
605
  */
599
606
 
600
- export function* synchronizeTemplate() {
601
- yield {
607
+ export const synchronizeTemplate = () => ({
608
+ select,
609
+ dispatch
610
+ }) => {
611
+ dispatch({
602
612
  type: 'SYNCHRONIZE_TEMPLATE'
603
- };
604
- const blocks = yield controls.select(blockEditorStoreName, 'getBlocks');
605
- const template = yield controls.select(blockEditorStoreName, 'getTemplate');
613
+ });
614
+ const blocks = select.getBlocks();
615
+ const template = select.getTemplate();
606
616
  const updatedBlockList = synchronizeBlocksWithTemplate(blocks, template);
607
- return yield resetBlocks(updatedBlockList);
608
- }
617
+ dispatch.resetBlocks(updatedBlockList);
618
+ };
609
619
  /**
610
- * Returns an action object used in signalling that two blocks should be merged
620
+ * Action that merges two blocks.
611
621
  *
612
622
  * @param {string} firstBlockClientId Client ID of the first block to merge.
613
623
  * @param {string} secondBlockClientId Client ID of the second block to merge.
614
624
  */
615
625
 
616
- export function* mergeBlocks(firstBlockClientId, secondBlockClientId) {
626
+ export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => ({
627
+ select,
628
+ dispatch
629
+ }) => {
617
630
  const blocks = [firstBlockClientId, secondBlockClientId];
618
- yield {
631
+ dispatch({
619
632
  type: 'MERGE_BLOCKS',
620
633
  blocks
621
- };
634
+ });
622
635
  const [clientIdA, clientIdB] = blocks;
623
- const blockA = yield controls.select(blockEditorStoreName, 'getBlock', clientIdA);
636
+ const blockA = select.getBlock(clientIdA);
624
637
  const blockAType = getBlockType(blockA.name); // Only focus the previous block if it's not mergeable
625
638
 
626
639
  if (blockAType && !blockAType.merge) {
627
- yield selectBlock(blockA.clientId);
640
+ dispatch.selectBlock(blockA.clientId);
628
641
  return;
629
642
  }
630
643
 
631
- const blockB = yield controls.select(blockEditorStoreName, 'getBlock', clientIdB);
644
+ const blockB = select.getBlock(clientIdB);
632
645
  const blockBType = getBlockType(blockB.name);
633
646
  const {
634
647
  clientId,
635
648
  attributeKey,
636
649
  offset
637
- } = yield controls.select(blockEditorStoreName, 'getSelectionStart');
650
+ } = select.getSelectionStart();
638
651
  const selectedBlockType = clientId === clientIdA ? blockAType : blockBType;
639
652
  const attributeDefinition = selectedBlockType.attributes[attributeKey];
640
653
  const canRestoreTextSelection = (clientId === clientIdA || clientId === clientIdB) && attributeKey !== undefined && offset !== undefined && // We cannot restore text selection if the RichText identifier
@@ -712,16 +725,16 @@ export function* mergeBlocks(firstBlockClientId, secondBlockClientId) {
712
725
  preserveWhiteSpace
713
726
  });
714
727
  updatedAttributes[newAttributeKey] = newHtml;
715
- yield selectionChange(blockA.clientId, newAttributeKey, newOffset, newOffset);
728
+ dispatch.selectionChange(blockA.clientId, newAttributeKey, newOffset, newOffset);
716
729
  }
717
730
 
718
- yield* replaceBlocks([blockA.clientId, blockB.clientId], [{ ...blockA,
731
+ dispatch.replaceBlocks([blockA.clientId, blockB.clientId], [{ ...blockA,
719
732
  attributes: { ...blockA.attributes,
720
733
  ...updatedAttributes
721
734
  }
722
735
  }, ...blocksWithTheSameType.slice(1)], 0 // If we don't pass the `indexToSelect` it will default to the last block.
723
736
  );
724
- }
737
+ };
725
738
  /**
726
739
  * Yields action objects used in signalling that the blocks corresponding to
727
740
  * the set of specified client IDs are to be removed.
@@ -731,36 +744,34 @@ export function* mergeBlocks(firstBlockClientId, secondBlockClientId) {
731
744
  * selected when a block is removed.
732
745
  */
733
746
 
734
- export function* removeBlocks(clientIds, selectPrevious = true) {
747
+ export const removeBlocks = (clientIds, selectPrevious = true) => ({
748
+ select,
749
+ dispatch
750
+ }) => {
735
751
  if (!clientIds || !clientIds.length) {
736
752
  return;
737
753
  }
738
754
 
739
755
  clientIds = castArray(clientIds);
740
- const rootClientId = yield controls.select(blockEditorStoreName, 'getBlockRootClientId', clientIds[0]);
741
- const canRemoveBlocks = yield controls.select(blockEditorStoreName, 'canRemoveBlocks', clientIds, rootClientId);
756
+ const rootClientId = select.getBlockRootClientId(clientIds[0]);
757
+ const canRemoveBlocks = select.canRemoveBlocks(clientIds, rootClientId);
742
758
 
743
759
  if (!canRemoveBlocks) {
744
760
  return;
745
761
  }
746
762
 
747
- let previousBlockId;
748
-
749
763
  if (selectPrevious) {
750
- previousBlockId = yield selectPreviousBlock(clientIds[0]);
751
- } else {
752
- previousBlockId = yield controls.select(blockEditorStoreName, 'getPreviousBlockClientId', clientIds[0]);
764
+ dispatch.selectPreviousBlock(clientIds[0]);
753
765
  }
754
766
 
755
- yield {
767
+ dispatch({
756
768
  type: 'REMOVE_BLOCKS',
757
769
  clientIds
758
- }; // To avoid a focus loss when removing the last block, assure there is
770
+ }); // To avoid a focus loss when removing the last block, assure there is
759
771
  // always a default block if the last of the blocks have been removed.
760
772
 
761
- const defaultBlockId = yield* ensureDefaultBlock();
762
- return [previousBlockId || defaultBlockId];
763
- }
773
+ dispatch(ensureDefaultBlock());
774
+ };
764
775
  /**
765
776
  * Returns an action object used in signalling that the block with the
766
777
  * specified client ID is to be removed.
@@ -884,8 +895,7 @@ export function exitFormattedText() {
884
895
  };
885
896
  }
886
897
  /**
887
- * Returns an action object used in signalling that the user caret has changed
888
- * position.
898
+ * Action that changes the position of the user caret.
889
899
  *
890
900
  * @param {string} clientId The selected block client ID.
891
901
  * @param {string} attributeKey The selected block attribute key.
@@ -905,8 +915,7 @@ export function selectionChange(clientId, attributeKey, startOffset, endOffset)
905
915
  };
906
916
  }
907
917
  /**
908
- * Returns an action object used in signalling that a new block of the default
909
- * type should be added to the block list.
918
+ * Action that adds a new block of the default type to the block list.
910
919
  *
911
920
  * @param {?Object} attributes Optional attributes of the block to assign.
912
921
  * @param {?string} rootClientId Optional root client ID of block list on which
@@ -928,7 +937,7 @@ export function insertDefaultBlock(attributes, rootClientId, index) {
928
937
  return insertBlock(block, index, rootClientId);
929
938
  }
930
939
  /**
931
- * Returns an action object that changes the nested settings of a given block.
940
+ * Action that changes the nested settings of a given block.
932
941
  *
933
942
  * @param {string} clientId Client ID of the block whose nested setting are
934
943
  * being received.
@@ -945,7 +954,7 @@ export function updateBlockListSettings(clientId, settings) {
945
954
  };
946
955
  }
947
956
  /**
948
- * Returns an action object used in signalling that the block editor settings have been updated.
957
+ * Action that updates the block editor settings.
949
958
  *
950
959
  * @param {Object} settings Updated settings
951
960
  *
@@ -959,7 +968,7 @@ export function updateSettings(settings) {
959
968
  };
960
969
  }
961
970
  /**
962
- * Returns an action object used in signalling that a temporary reusable blocks have been saved
971
+ * Action that signals that a temporary reusable block has been saved
963
972
  * in order to switch its temporary id with the real id.
964
973
  *
965
974
  * @param {string} id Reusable block's id.
@@ -976,7 +985,7 @@ export function __unstableSaveReusableBlock(id, updatedId) {
976
985
  };
977
986
  }
978
987
  /**
979
- * Returns an action object used in signalling that the last block change should be marked explicitly as persistent.
988
+ * Action that marks the last block change explicitly as persistent.
980
989
  *
981
990
  * @return {Object} Action object.
982
991
  */
@@ -987,7 +996,7 @@ export function __unstableMarkLastChangeAsPersistent() {
987
996
  };
988
997
  }
989
998
  /**
990
- * Returns an action object used in signalling that the next block change should be marked explicitly as not persistent.
999
+ * Action that signals that the next block change should be marked explicitly as not persistent.
991
1000
  *
992
1001
  * @return {Object} Action object.
993
1002
  */
@@ -998,138 +1007,156 @@ export function __unstableMarkNextChangeAsNotPersistent() {
998
1007
  };
999
1008
  }
1000
1009
  /**
1001
- * Returns an action object used in signalling that the last block change is
1002
- * an automatic change, meaning it was not performed by the user, and can be
1003
- * undone using the `Escape` and `Backspace` keys. This action must be called
1004
- * after the change was made, and any actions that are a consequence of it, so
1005
- * it is recommended to be called at the next idle period to ensure all
1010
+ * Action that marks the last block change as an automatic change, meaning it was not
1011
+ * performed by the user, and can be undone using the `Escape` and `Backspace` keys.
1012
+ * This action must be called after the change was made, and any actions that are a
1013
+ * consequence of it, so it is recommended to be called at the next idle period to ensure all
1006
1014
  * selection changes have been recorded.
1007
1015
  */
1008
1016
 
1009
- export function* __unstableMarkAutomaticChange() {
1010
- yield {
1017
+ export const __unstableMarkAutomaticChange = () => ({
1018
+ dispatch
1019
+ }) => {
1020
+ dispatch({
1011
1021
  type: 'MARK_AUTOMATIC_CHANGE'
1012
- };
1013
- yield __unstableMarkAutomaticChangeFinalControl();
1014
- }
1015
- export function __unstableMarkAutomaticChangeFinal() {
1016
- return {
1017
- type: 'MARK_AUTOMATIC_CHANGE_FINAL'
1018
- };
1019
- }
1022
+ });
1023
+ const {
1024
+ requestIdleCallback = cb => setTimeout(cb, 100)
1025
+ } = window;
1026
+ requestIdleCallback(() => {
1027
+ dispatch({
1028
+ type: 'MARK_AUTOMATIC_CHANGE_FINAL'
1029
+ });
1030
+ });
1031
+ };
1020
1032
  /**
1021
- * Generators that triggers an action used to enable or disable the navigation mode.
1033
+ * Action that enables or disables the navigation mode.
1022
1034
  *
1023
1035
  * @param {string} isNavigationMode Enable/Disable navigation mode.
1024
1036
  */
1025
1037
 
1026
- export function* setNavigationMode(isNavigationMode = true) {
1027
- yield {
1038
+ export const setNavigationMode = (isNavigationMode = true) => ({
1039
+ dispatch
1040
+ }) => {
1041
+ dispatch({
1028
1042
  type: 'SET_NAVIGATION_MODE',
1029
1043
  isNavigationMode
1030
- };
1044
+ });
1031
1045
 
1032
1046
  if (isNavigationMode) {
1033
1047
  speak(__('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.'));
1034
1048
  } else {
1035
1049
  speak(__('You are currently in edit mode. To return to the navigation mode, press Escape.'));
1036
1050
  }
1037
- }
1051
+ };
1038
1052
  /**
1039
- * Generator that triggers an action used to enable or disable the block moving mode.
1053
+ * Action that enables or disables the block moving mode.
1040
1054
  *
1041
1055
  * @param {string|null} hasBlockMovingClientId Enable/Disable block moving mode.
1042
1056
  */
1043
1057
 
1044
- export function* setBlockMovingClientId(hasBlockMovingClientId = null) {
1045
- yield {
1058
+ export const setBlockMovingClientId = (hasBlockMovingClientId = null) => ({
1059
+ dispatch
1060
+ }) => {
1061
+ dispatch({
1046
1062
  type: 'SET_BLOCK_MOVING_MODE',
1047
1063
  hasBlockMovingClientId
1048
- };
1064
+ });
1049
1065
 
1050
1066
  if (hasBlockMovingClientId) {
1051
1067
  speak(__('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.'));
1052
1068
  }
1053
- }
1069
+ };
1054
1070
  /**
1055
- * Generator that triggers an action used to duplicate a list of blocks.
1071
+ * Action that duplicates a list of blocks.
1056
1072
  *
1057
1073
  * @param {string[]} clientIds
1058
1074
  * @param {boolean} updateSelection
1059
1075
  */
1060
1076
 
1061
- export function* duplicateBlocks(clientIds, updateSelection = true) {
1062
- if (!clientIds && !clientIds.length) {
1077
+ export const duplicateBlocks = (clientIds, updateSelection = true) => ({
1078
+ select,
1079
+ dispatch
1080
+ }) => {
1081
+ if (!clientIds || !clientIds.length) {
1063
1082
  return;
1064
- }
1083
+ } // Return early if blocks don't exist.
1084
+
1065
1085
 
1066
- const blocks = yield controls.select(blockEditorStoreName, 'getBlocksByClientId', clientIds);
1067
- const rootClientId = yield controls.select(blockEditorStoreName, 'getBlockRootClientId', clientIds[0]); // Return early if blocks don't exist.
1086
+ const blocks = select.getBlocksByClientId(clientIds);
1068
1087
 
1069
1088
  if (some(blocks, block => !block)) {
1070
1089
  return;
1071
- }
1090
+ } // Return early if blocks don't support multiple usage.
1072
1091
 
1073
- const blockNames = blocks.map(block => block.name); // Return early if blocks don't support multiple usage.
1074
1092
 
1075
- if (some(blockNames, blockName => !hasBlockSupport(blockName, 'multiple', true))) {
1093
+ const blockNames = blocks.map(block => block.name);
1094
+
1095
+ if (blockNames.some(blockName => !hasBlockSupport(blockName, 'multiple', true))) {
1076
1096
  return;
1077
1097
  }
1078
1098
 
1079
- const lastSelectedIndex = yield controls.select(blockEditorStoreName, 'getBlockIndex', last(castArray(clientIds)), rootClientId);
1099
+ const rootClientId = select.getBlockRootClientId(clientIds[0]);
1100
+ const lastSelectedIndex = select.getBlockIndex(last(castArray(clientIds)), rootClientId);
1080
1101
  const clonedBlocks = blocks.map(block => __experimentalCloneSanitizedBlock(block));
1081
- yield insertBlocks(clonedBlocks, lastSelectedIndex + 1, rootClientId, updateSelection);
1102
+ dispatch.insertBlocks(clonedBlocks, lastSelectedIndex + 1, rootClientId, updateSelection);
1082
1103
 
1083
1104
  if (clonedBlocks.length > 1 && updateSelection) {
1084
- yield multiSelect(first(clonedBlocks).clientId, last(clonedBlocks).clientId);
1105
+ dispatch.multiSelect(first(clonedBlocks).clientId, last(clonedBlocks).clientId);
1085
1106
  }
1086
1107
 
1087
1108
  return clonedBlocks.map(block => block.clientId);
1088
- }
1109
+ };
1089
1110
  /**
1090
- * Generator used to insert an empty block after a given block.
1111
+ * Action that inserts an empty block before a given block.
1091
1112
  *
1092
1113
  * @param {string} clientId
1093
1114
  */
1094
1115
 
1095
- export function* insertBeforeBlock(clientId) {
1116
+ export const insertBeforeBlock = clientId => ({
1117
+ select,
1118
+ dispatch
1119
+ }) => {
1096
1120
  if (!clientId) {
1097
1121
  return;
1098
1122
  }
1099
1123
 
1100
- const rootClientId = yield controls.select(blockEditorStoreName, 'getBlockRootClientId', clientId);
1101
- const isLocked = yield controls.select(blockEditorStoreName, 'getTemplateLock', rootClientId);
1124
+ const rootClientId = select.getBlockRootClientId(clientId);
1125
+ const isLocked = select.getTemplateLock(rootClientId);
1102
1126
 
1103
1127
  if (isLocked) {
1104
1128
  return;
1105
1129
  }
1106
1130
 
1107
- const firstSelectedIndex = yield controls.select(blockEditorStoreName, 'getBlockIndex', clientId, rootClientId);
1108
- return yield insertDefaultBlock({}, rootClientId, firstSelectedIndex);
1109
- }
1131
+ const firstSelectedIndex = select.getBlockIndex(clientId, rootClientId);
1132
+ return dispatch.insertDefaultBlock({}, rootClientId, firstSelectedIndex);
1133
+ };
1110
1134
  /**
1111
- * Generator used to insert an empty block before a given block.
1135
+ * Action that inserts an empty block after a given block.
1112
1136
  *
1113
1137
  * @param {string} clientId
1114
1138
  */
1115
1139
 
1116
- export function* insertAfterBlock(clientId) {
1140
+ export const insertAfterBlock = clientId => ({
1141
+ select,
1142
+ dispatch
1143
+ }) => {
1117
1144
  if (!clientId) {
1118
1145
  return;
1119
1146
  }
1120
1147
 
1121
- const rootClientId = yield controls.select(blockEditorStoreName, 'getBlockRootClientId', clientId);
1122
- const isLocked = yield controls.select(blockEditorStoreName, 'getTemplateLock', rootClientId);
1148
+ const rootClientId = select.getBlockRootClientId(clientId);
1149
+ const isLocked = select.getTemplateLock(rootClientId);
1123
1150
 
1124
1151
  if (isLocked) {
1125
1152
  return;
1126
1153
  }
1127
1154
 
1128
- const firstSelectedIndex = yield controls.select(blockEditorStoreName, 'getBlockIndex', clientId, rootClientId);
1129
- return yield insertDefaultBlock({}, rootClientId, firstSelectedIndex + 1);
1130
- }
1155
+ const firstSelectedIndex = select.getBlockIndex(clientId, rootClientId);
1156
+ return dispatch.insertDefaultBlock({}, rootClientId, firstSelectedIndex + 1);
1157
+ };
1131
1158
  /**
1132
- * Returns an action object that toggles the highlighted block state.
1159
+ * Action that toggles the highlighted block state.
1133
1160
  *
1134
1161
  * @param {string} clientId The block's clientId.
1135
1162
  * @param {boolean} isHighlighted The highlight state.
@@ -1143,22 +1170,20 @@ export function toggleBlockHighlight(clientId, isHighlighted) {
1143
1170
  };
1144
1171
  }
1145
1172
  /**
1146
- * Yields action objects used in signalling that the block corresponding to the
1147
- * given clientId should appear to "flash" by rhythmically highlighting it.
1173
+ * Action that "flashes" the block with a given `clientId` by rhythmically highlighting it.
1148
1174
  *
1149
1175
  * @param {string} clientId Target block client ID.
1150
1176
  */
1151
1177
 
1152
- export function* flashBlock(clientId) {
1153
- yield toggleBlockHighlight(clientId, true);
1154
- yield {
1155
- type: 'SLEEP',
1156
- duration: 150
1157
- };
1158
- yield toggleBlockHighlight(clientId, false);
1159
- }
1178
+ export const flashBlock = clientId => async ({
1179
+ dispatch
1180
+ }) => {
1181
+ dispatch(toggleBlockHighlight(clientId, true));
1182
+ await new Promise(resolve => setTimeout(resolve, 150));
1183
+ dispatch(toggleBlockHighlight(clientId, false));
1184
+ };
1160
1185
  /**
1161
- * Returns an action object that sets whether the block has controlled innerblocks.
1186
+ * Action that sets whether a block has controlled inner blocks.
1162
1187
  *
1163
1188
  * @param {string} clientId The block's clientId.
1164
1189
  * @param {boolean} hasControlledInnerBlocks True if the block's inner blocks are controlled.