@wordpress/block-editor 8.4.0 → 8.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (369) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +56 -19
  3. package/build/components/alignment-control/index.js +13 -6
  4. package/build/components/alignment-control/index.js.map +1 -1
  5. package/build/components/block-alignment-control/index.js +13 -6
  6. package/build/components/block-alignment-control/index.js.map +1 -1
  7. package/build/components/block-draggable/index.js +2 -3
  8. package/build/components/block-draggable/index.js.map +1 -1
  9. package/build/components/block-icon/index.js +4 -0
  10. package/build/components/block-icon/index.js.map +1 -1
  11. package/build/components/block-inspector/index.js +6 -1
  12. package/build/components/block-inspector/index.js.map +1 -1
  13. package/build/components/block-list/use-block-props/index.js +1 -6
  14. package/build/components/block-list/use-block-props/index.js.map +1 -1
  15. package/build/components/block-list/use-block-props/use-focus-first-element.js +14 -17
  16. package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
  17. package/build/components/block-list/use-block-props/use-focus-handler.js +7 -1
  18. package/build/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
  19. package/build/components/block-list-appender/index.js +6 -1
  20. package/build/components/block-list-appender/index.js.map +1 -1
  21. package/build/components/block-lock/menu-item.js +9 -0
  22. package/build/components/block-lock/menu-item.js.map +1 -1
  23. package/build/components/block-lock/modal.js +4 -13
  24. package/build/components/block-lock/modal.js.map +1 -1
  25. package/build/components/block-lock/toolbar.js +11 -3
  26. package/build/components/block-lock/toolbar.js.map +1 -1
  27. package/build/components/block-mover/index.js +4 -0
  28. package/build/components/block-mover/index.js.map +1 -1
  29. package/build/components/block-settings-menu/block-settings-dropdown.js +50 -5
  30. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  31. package/build/components/block-switcher/index.js +1 -1
  32. package/build/components/block-switcher/index.js.map +1 -1
  33. package/build/components/block-title/index.js +2 -2
  34. package/build/components/block-title/index.js.map +1 -1
  35. package/build/components/block-title/use-block-display-title.js +1 -1
  36. package/build/components/block-title/use-block-display-title.js.map +1 -1
  37. package/build/components/block-toolbar/block-name-context.js +17 -0
  38. package/build/components/block-toolbar/block-name-context.js.map +1 -0
  39. package/build/components/block-toolbar/block-toolbar-last-item.js +20 -0
  40. package/build/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
  41. package/build/components/block-toolbar/index.js +20 -5
  42. package/build/components/block-toolbar/index.js.map +1 -1
  43. package/build/components/block-tools/index.js +0 -16
  44. package/build/components/block-tools/index.js.map +1 -1
  45. package/build/components/block-variation-transforms/index.js +92 -47
  46. package/build/components/block-variation-transforms/index.js.map +1 -1
  47. package/build/components/block-vertical-alignment-control/index.js +13 -6
  48. package/build/components/block-vertical-alignment-control/index.js.map +1 -1
  49. package/build/components/contrast-checker/index.js +4 -0
  50. package/build/components/contrast-checker/index.js.map +1 -1
  51. package/build/components/convert-to-group-buttons/index.js +8 -0
  52. package/build/components/convert-to-group-buttons/index.js.map +1 -1
  53. package/build/components/convert-to-group-buttons/toolbar.js +105 -0
  54. package/build/components/convert-to-group-buttons/toolbar.js.map +1 -0
  55. package/build/components/copy-handler/index.js +4 -0
  56. package/build/components/copy-handler/index.js.map +1 -1
  57. package/build/components/font-sizes/font-size-picker.js +4 -0
  58. package/build/components/font-sizes/font-size-picker.js.map +1 -1
  59. package/build/components/iframe/index.js +6 -9
  60. package/build/components/iframe/index.js.map +1 -1
  61. package/build/components/index.js +18 -0
  62. package/build/components/index.js.map +1 -1
  63. package/build/components/justify-content-control/index.js +13 -6
  64. package/build/components/justify-content-control/index.js.map +1 -1
  65. package/build/components/keyboard-shortcuts/index.js +1 -1
  66. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  67. package/build/components/line-height-control/index.js +10 -3
  68. package/build/components/line-height-control/index.js.map +1 -1
  69. package/build/components/list-view/block-select-button.js +25 -6
  70. package/build/components/list-view/block-select-button.js.map +1 -1
  71. package/build/components/list-view/block.js +5 -1
  72. package/build/components/list-view/block.js.map +1 -1
  73. package/build/components/list-view/branch.js +1 -1
  74. package/build/components/list-view/branch.js.map +1 -1
  75. package/build/components/media-replace-flow/index.js +4 -0
  76. package/build/components/media-replace-flow/index.js.map +1 -1
  77. package/build/components/multi-selection-inspector/index.js +1 -1
  78. package/build/components/multi-selection-inspector/index.js.map +1 -1
  79. package/build/components/rich-text/index.js +26 -4
  80. package/build/components/rich-text/index.js.map +1 -1
  81. package/build/components/rich-text/split-value.js +12 -2
  82. package/build/components/rich-text/split-value.js.map +1 -1
  83. package/build/components/rich-text/use-firefox-compat.js +49 -0
  84. package/build/components/rich-text/use-firefox-compat.js.map +1 -0
  85. package/build/components/rich-text/use-input-rules.js +34 -2
  86. package/build/components/rich-text/use-input-rules.js.map +1 -1
  87. package/build/components/skip-to-selected-block/index.js +4 -0
  88. package/build/components/skip-to-selected-block/index.js.map +1 -1
  89. package/build/components/writing-flow/index.js +9 -1
  90. package/build/components/writing-flow/index.js.map +1 -1
  91. package/build/components/writing-flow/use-arrow-nav.js +3 -44
  92. package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
  93. package/build/components/writing-flow/use-click-selection.js +68 -0
  94. package/build/components/writing-flow/use-click-selection.js.map +1 -0
  95. package/build/components/writing-flow/use-drag-selection.js +134 -0
  96. package/build/components/writing-flow/use-drag-selection.js.map +1 -0
  97. package/build/components/writing-flow/use-input.js +116 -0
  98. package/build/components/writing-flow/use-input.js.map +1 -0
  99. package/build/components/writing-flow/use-multi-selection.js +18 -38
  100. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  101. package/build/components/writing-flow/use-selection-observer.js +161 -0
  102. package/build/components/writing-flow/use-selection-observer.js.map +1 -0
  103. package/build/components/writing-flow/use-tab-nav.js +1 -8
  104. package/build/components/writing-flow/use-tab-nav.js.map +1 -1
  105. package/build/hooks/border-color.js +3 -3
  106. package/build/hooks/border-color.js.map +1 -1
  107. package/build/hooks/border.js +0 -14
  108. package/build/hooks/border.js.map +1 -1
  109. package/build/hooks/color.js +20 -17
  110. package/build/hooks/color.js.map +1 -1
  111. package/build/hooks/font-family.js +5 -1
  112. package/build/hooks/font-family.js.map +1 -1
  113. package/build/hooks/font-size.js +4 -2
  114. package/build/hooks/font-size.js.map +1 -1
  115. package/build/hooks/gap.js +23 -16
  116. package/build/hooks/gap.js.map +1 -1
  117. package/build/hooks/layout.js +7 -2
  118. package/build/hooks/layout.js.map +1 -1
  119. package/build/hooks/style.js +34 -3
  120. package/build/hooks/style.js.map +1 -1
  121. package/build/hooks/utils.js +29 -0
  122. package/build/hooks/utils.js.map +1 -1
  123. package/build/layouts/flex.js +76 -12
  124. package/build/layouts/flex.js.map +1 -1
  125. package/build/layouts/flow.js +9 -4
  126. package/build/layouts/flow.js.map +1 -1
  127. package/build/store/actions.js +297 -51
  128. package/build/store/actions.js.map +1 -1
  129. package/build/store/defaults.js +5 -2
  130. package/build/store/defaults.js.map +1 -1
  131. package/build/store/reducer.js +25 -13
  132. package/build/store/reducer.js.map +1 -1
  133. package/build/store/selectors.js +142 -18
  134. package/build/store/selectors.js.map +1 -1
  135. package/build/utils/dom.js +2 -1
  136. package/build/utils/dom.js.map +1 -1
  137. package/build-module/components/alignment-control/index.js +12 -4
  138. package/build-module/components/alignment-control/index.js.map +1 -1
  139. package/build-module/components/block-alignment-control/index.js +12 -4
  140. package/build-module/components/block-alignment-control/index.js.map +1 -1
  141. package/build-module/components/block-draggable/index.js +2 -3
  142. package/build-module/components/block-draggable/index.js.map +1 -1
  143. package/build-module/components/block-icon/index.js +4 -0
  144. package/build-module/components/block-icon/index.js.map +1 -1
  145. package/build-module/components/block-inspector/index.js +6 -1
  146. package/build-module/components/block-inspector/index.js.map +1 -1
  147. package/build-module/components/block-list/use-block-props/index.js +1 -4
  148. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  149. package/build-module/components/block-list/use-block-props/use-focus-first-element.js +15 -17
  150. package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
  151. package/build-module/components/block-list/use-block-props/use-focus-handler.js +7 -1
  152. package/build-module/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
  153. package/build-module/components/block-list-appender/index.js +6 -1
  154. package/build-module/components/block-list-appender/index.js.map +1 -1
  155. package/build-module/components/block-lock/menu-item.js +9 -0
  156. package/build-module/components/block-lock/menu-item.js.map +1 -1
  157. package/build-module/components/block-lock/modal.js +5 -14
  158. package/build-module/components/block-lock/modal.js.map +1 -1
  159. package/build-module/components/block-lock/toolbar.js +11 -3
  160. package/build-module/components/block-lock/toolbar.js.map +1 -1
  161. package/build-module/components/block-mover/index.js +4 -0
  162. package/build-module/components/block-mover/index.js.map +1 -1
  163. package/build-module/components/block-settings-menu/block-settings-dropdown.js +50 -7
  164. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  165. package/build-module/components/block-switcher/index.js +2 -2
  166. package/build-module/components/block-switcher/index.js.map +1 -1
  167. package/build-module/components/block-title/index.js +2 -2
  168. package/build-module/components/block-title/index.js.map +1 -1
  169. package/build-module/components/block-title/use-block-display-title.js +1 -1
  170. package/build-module/components/block-title/use-block-display-title.js.map +1 -1
  171. package/build-module/components/block-toolbar/block-name-context.js +9 -0
  172. package/build-module/components/block-toolbar/block-name-context.js.map +1 -0
  173. package/build-module/components/block-toolbar/block-toolbar-last-item.js +11 -0
  174. package/build-module/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
  175. package/build-module/components/block-toolbar/index.js +16 -4
  176. package/build-module/components/block-toolbar/index.js.map +1 -1
  177. package/build-module/components/block-tools/index.js +0 -16
  178. package/build-module/components/block-tools/index.js.map +1 -1
  179. package/build-module/components/block-variation-transforms/index.js +95 -49
  180. package/build-module/components/block-variation-transforms/index.js.map +1 -1
  181. package/build-module/components/block-vertical-alignment-control/index.js +12 -4
  182. package/build-module/components/block-vertical-alignment-control/index.js.map +1 -1
  183. package/build-module/components/contrast-checker/index.js +4 -0
  184. package/build-module/components/contrast-checker/index.js.map +1 -1
  185. package/build-module/components/convert-to-group-buttons/index.js +2 -1
  186. package/build-module/components/convert-to-group-buttons/index.js.map +1 -1
  187. package/build-module/components/convert-to-group-buttons/toolbar.js +90 -0
  188. package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -0
  189. package/build-module/components/copy-handler/index.js +4 -0
  190. package/build-module/components/copy-handler/index.js.map +1 -1
  191. package/build-module/components/font-sizes/font-size-picker.js +4 -0
  192. package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
  193. package/build-module/components/iframe/index.js +6 -9
  194. package/build-module/components/iframe/index.js.map +1 -1
  195. package/build-module/components/index.js +2 -0
  196. package/build-module/components/index.js.map +1 -1
  197. package/build-module/components/justify-content-control/index.js +12 -4
  198. package/build-module/components/justify-content-control/index.js.map +1 -1
  199. package/build-module/components/keyboard-shortcuts/index.js +1 -1
  200. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  201. package/build-module/components/line-height-control/index.js +9 -2
  202. package/build-module/components/line-height-control/index.js.map +1 -1
  203. package/build-module/components/list-view/block-select-button.js +22 -6
  204. package/build-module/components/list-view/block-select-button.js.map +1 -1
  205. package/build-module/components/list-view/block.js +5 -1
  206. package/build-module/components/list-view/block.js.map +1 -1
  207. package/build-module/components/list-view/branch.js +1 -1
  208. package/build-module/components/list-view/branch.js.map +1 -1
  209. package/build-module/components/media-replace-flow/index.js +4 -0
  210. package/build-module/components/media-replace-flow/index.js.map +1 -1
  211. package/build-module/components/multi-selection-inspector/index.js +2 -2
  212. package/build-module/components/multi-selection-inspector/index.js.map +1 -1
  213. package/build-module/components/rich-text/index.js +25 -4
  214. package/build-module/components/rich-text/index.js.map +1 -1
  215. package/build-module/components/rich-text/split-value.js +12 -2
  216. package/build-module/components/rich-text/split-value.js.map +1 -1
  217. package/build-module/components/rich-text/use-firefox-compat.js +39 -0
  218. package/build-module/components/rich-text/use-firefox-compat.js.map +1 -0
  219. package/build-module/components/rich-text/use-input-rules.js +35 -4
  220. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  221. package/build-module/components/skip-to-selected-block/index.js +4 -0
  222. package/build-module/components/skip-to-selected-block/index.js.map +1 -1
  223. package/build-module/components/writing-flow/index.js +5 -1
  224. package/build-module/components/writing-flow/index.js.map +1 -1
  225. package/build-module/components/writing-flow/use-arrow-nav.js +4 -45
  226. package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
  227. package/build-module/components/writing-flow/use-click-selection.js +57 -0
  228. package/build-module/components/writing-flow/use-click-selection.js.map +1 -0
  229. package/build-module/components/writing-flow/use-drag-selection.js +124 -0
  230. package/build-module/components/writing-flow/use-drag-selection.js.map +1 -0
  231. package/build-module/components/writing-flow/use-input.js +104 -0
  232. package/build-module/components/writing-flow/use-input.js.map +1 -0
  233. package/build-module/components/writing-flow/use-multi-selection.js +18 -37
  234. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  235. package/build-module/components/writing-flow/use-selection-observer.js +150 -0
  236. package/build-module/components/writing-flow/use-selection-observer.js.map +1 -0
  237. package/build-module/components/writing-flow/use-tab-nav.js +1 -9
  238. package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
  239. package/build-module/hooks/border-color.js +5 -5
  240. package/build-module/hooks/border-color.js.map +1 -1
  241. package/build-module/hooks/border.js +0 -12
  242. package/build-module/hooks/border.js.map +1 -1
  243. package/build-module/hooks/color.js +19 -18
  244. package/build-module/hooks/color.js.map +1 -1
  245. package/build-module/hooks/font-family.js +3 -1
  246. package/build-module/hooks/font-family.js.map +1 -1
  247. package/build-module/hooks/font-size.js +4 -3
  248. package/build-module/hooks/font-size.js.map +1 -1
  249. package/build-module/hooks/gap.js +22 -15
  250. package/build-module/hooks/gap.js.map +1 -1
  251. package/build-module/hooks/layout.js +7 -2
  252. package/build-module/hooks/layout.js.map +1 -1
  253. package/build-module/hooks/style.js +33 -3
  254. package/build-module/hooks/style.js.map +1 -1
  255. package/build-module/hooks/utils.js +26 -0
  256. package/build-module/hooks/utils.js.map +1 -1
  257. package/build-module/layouts/flex.js +76 -13
  258. package/build-module/layouts/flex.js.map +1 -1
  259. package/build-module/layouts/flow.js +9 -5
  260. package/build-module/layouts/flow.js.map +1 -1
  261. package/build-module/store/actions.js +286 -49
  262. package/build-module/store/actions.js.map +1 -1
  263. package/build-module/store/defaults.js +5 -2
  264. package/build-module/store/defaults.js.map +1 -1
  265. package/build-module/store/reducer.js +25 -13
  266. package/build-module/store/reducer.js.map +1 -1
  267. package/build-module/store/selectors.js +138 -19
  268. package/build-module/store/selectors.js.map +1 -1
  269. package/build-module/utils/dom.js +2 -1
  270. package/build-module/utils/dom.js.map +1 -1
  271. package/build-style/style-rtl.css +107 -74
  272. package/build-style/style.css +107 -74
  273. package/build-types/utils/dom.d.ts.map +1 -1
  274. package/package.json +28 -28
  275. package/src/components/alignment-control/index.js +9 -4
  276. package/src/components/block-alignment-control/index.js +9 -4
  277. package/src/components/block-draggable/index.js +2 -5
  278. package/src/components/block-icon/index.js +3 -0
  279. package/src/components/block-inspector/index.js +4 -0
  280. package/src/components/block-list/style.scss +4 -5
  281. package/src/components/block-list/use-block-props/index.js +0 -5
  282. package/src/components/block-list/use-block-props/use-focus-first-element.js +19 -26
  283. package/src/components/block-list/use-block-props/use-focus-handler.js +8 -0
  284. package/src/components/block-list-appender/index.js +5 -0
  285. package/src/components/block-lock/menu-item.js +8 -1
  286. package/src/components/block-lock/modal.js +18 -13
  287. package/src/components/block-lock/style.scss +6 -3
  288. package/src/components/block-lock/toolbar.js +12 -2
  289. package/src/components/block-mover/index.js +3 -0
  290. package/src/components/block-mover/style.scss +4 -0
  291. package/src/components/block-settings-menu/block-settings-dropdown.js +62 -4
  292. package/src/components/block-switcher/index.js +2 -2
  293. package/src/components/block-switcher/style.scss +8 -1
  294. package/src/components/block-switcher/test/index.js +2 -2
  295. package/src/components/block-title/index.js +2 -2
  296. package/src/components/block-title/use-block-display-title.js +1 -1
  297. package/src/components/block-toolbar/block-name-context.js +8 -0
  298. package/src/components/block-toolbar/block-toolbar-last-item.js +12 -0
  299. package/src/components/block-toolbar/index.js +18 -2
  300. package/src/components/block-toolbar/style.scss +6 -0
  301. package/src/components/block-tools/index.js +0 -19
  302. package/src/components/block-tools/style.scss +3 -5
  303. package/src/components/block-variation-transforms/index.js +105 -36
  304. package/src/components/block-variation-transforms/style.scss +1 -1
  305. package/src/components/block-vertical-alignment-control/index.js +9 -4
  306. package/src/components/button-block-appender/style.scss +5 -1
  307. package/src/components/contrast-checker/index.js +3 -0
  308. package/src/components/convert-to-group-buttons/index.js +6 -1
  309. package/src/components/convert-to-group-buttons/toolbar.js +87 -0
  310. package/src/components/copy-handler/index.js +3 -0
  311. package/src/components/font-sizes/font-size-picker.js +3 -0
  312. package/src/components/iframe/index.js +5 -7
  313. package/src/components/index.js +2 -0
  314. package/src/components/justify-content-control/index.js +9 -4
  315. package/src/components/keyboard-shortcuts/index.js +1 -1
  316. package/src/components/line-height-control/index.js +8 -3
  317. package/src/components/list-view/block-select-button.js +21 -3
  318. package/src/components/list-view/block.js +8 -1
  319. package/src/components/list-view/branch.js +1 -1
  320. package/src/components/list-view/style.scss +56 -14
  321. package/src/components/media-placeholder/README.md +8 -0
  322. package/src/components/media-replace-flow/index.js +3 -0
  323. package/src/components/multi-selection-inspector/index.js +2 -2
  324. package/src/components/rich-text/index.js +24 -1
  325. package/src/components/rich-text/split-value.js +5 -1
  326. package/src/components/rich-text/use-firefox-compat.js +39 -0
  327. package/src/components/rich-text/use-input-rules.js +40 -3
  328. package/src/components/skip-to-selected-block/index.js +3 -0
  329. package/src/components/url-input/style.scss +3 -2
  330. package/src/components/writing-flow/index.js +8 -0
  331. package/src/components/writing-flow/readme.md +28 -0
  332. package/src/components/writing-flow/use-arrow-nav.js +4 -53
  333. package/src/components/writing-flow/use-click-selection.js +65 -0
  334. package/src/components/writing-flow/use-drag-selection.js +126 -0
  335. package/src/components/writing-flow/use-input.js +112 -0
  336. package/src/components/writing-flow/use-multi-selection.js +13 -36
  337. package/src/components/writing-flow/use-selection-observer.js +153 -0
  338. package/src/components/writing-flow/use-tab-nav.js +1 -11
  339. package/src/hooks/border-color.js +5 -5
  340. package/src/hooks/border.js +0 -13
  341. package/src/hooks/color.js +51 -24
  342. package/src/hooks/font-family.js +5 -2
  343. package/src/hooks/font-size.js +10 -7
  344. package/src/hooks/gap.js +25 -17
  345. package/src/hooks/layout.js +11 -1
  346. package/src/hooks/style.js +40 -4
  347. package/src/hooks/test/gap.js +25 -1
  348. package/src/hooks/test/style.js +94 -0
  349. package/src/hooks/test/utils.js +1 -1
  350. package/src/hooks/utils.js +26 -0
  351. package/src/layouts/flex.js +89 -5
  352. package/src/layouts/flow.js +15 -4
  353. package/src/store/actions.js +349 -32
  354. package/src/store/defaults.js +7 -2
  355. package/src/store/reducer.js +25 -10
  356. package/src/store/selectors.js +181 -24
  357. package/src/store/test/selectors.js +242 -5
  358. package/src/utils/dom.js +2 -1
  359. package/tsconfig.tsbuildinfo +1 -1
  360. package/build/components/block-list/use-block-props/use-multi-selection.js +0 -205
  361. package/build/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
  362. package/build/components/block-list/use-block-props/use-scroll-into-view.js +0 -77
  363. package/build/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
  364. package/build-module/components/block-list/use-block-props/use-multi-selection.js +0 -192
  365. package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
  366. package/build-module/components/block-list/use-block-props/use-scroll-into-view.js +0 -63
  367. package/build-module/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
  368. package/src/components/block-list/use-block-props/use-multi-selection.js +0 -227
  369. package/src/components/block-list/use-block-props/use-scroll-into-view.js +0 -73
@@ -100,6 +100,15 @@ export const validateBlocksToTemplate = blocks => _ref3 => {
100
100
  * text value. See `wp.richText.create`.
101
101
  */
102
102
 
103
+ /**
104
+ * A selection object.
105
+ *
106
+ * @typedef {Object} WPSelection
107
+ *
108
+ * @property {WPBlockSelection} start The selection start.
109
+ * @property {WPBlockSelection} end The selection end.
110
+ */
111
+
103
112
  /* eslint-disable jsdoc/valid-types */
104
113
 
105
114
  /**
@@ -595,7 +604,7 @@ export const insertBlocks = function (blocks, index, rootClientId) {
595
604
  * @param {?string} rootClientId Optional root client ID of block list on
596
605
  * which to insert.
597
606
  * @param {?number} index Index at which block should be inserted.
598
- * @param {Object} __unstableOptions Wether or not to show an inserter button.
607
+ * @param {Object} __unstableOptions Whether or not to show an inserter button.
599
608
  *
600
609
  * @return {Object} Action object.
601
610
  */
@@ -657,6 +666,243 @@ export const synchronizeTemplate = () => _ref11 => {
657
666
  const updatedBlockList = synchronizeBlocksWithTemplate(blocks, template);
658
667
  dispatch.resetBlocks(updatedBlockList);
659
668
  };
669
+
670
+ function mapRichTextSettings(attributeDefinition) {
671
+ const {
672
+ multiline: multilineTag,
673
+ __unstableMultilineWrapperTags: multilineWrapperTags,
674
+ __unstablePreserveWhiteSpace: preserveWhiteSpace
675
+ } = attributeDefinition;
676
+ return {
677
+ multilineTag,
678
+ multilineWrapperTags,
679
+ preserveWhiteSpace
680
+ };
681
+ }
682
+ /**
683
+ * Delete the current selection.
684
+ *
685
+ * @param {boolean} isForward
686
+ */
687
+
688
+
689
+ export const __unstableDeleteSelection = isForward => _ref12 => {
690
+ let {
691
+ registry,
692
+ select,
693
+ dispatch
694
+ } = _ref12;
695
+ const selectionAnchor = select.getSelectionStart();
696
+ const selectionFocus = select.getSelectionEnd();
697
+ if (selectionAnchor.clientId === selectionFocus.clientId) return; // It's not mergeable if there's no rich text selection.
698
+
699
+ if (!selectionAnchor.attributeKey || !selectionFocus.attributeKey || typeof selectionAnchor.offset === 'undefined' || typeof selectionFocus.offset === 'undefined') return false;
700
+ const anchorRootClientId = select.getBlockRootClientId(selectionAnchor.clientId);
701
+ const focusRootClientId = select.getBlockRootClientId(selectionFocus.clientId); // It's not mergeable if the selection doesn't start and end in the same
702
+ // block list. Maybe in the future it should be allowed.
703
+
704
+ if (anchorRootClientId !== focusRootClientId) {
705
+ return;
706
+ }
707
+
708
+ const blockOrder = select.getBlockOrder(anchorRootClientId);
709
+ const anchorIndex = blockOrder.indexOf(selectionAnchor.clientId);
710
+ const focusIndex = blockOrder.indexOf(selectionFocus.clientId); // Reassign selection start and end based on order.
711
+
712
+ let selectionStart, selectionEnd;
713
+
714
+ if (anchorIndex > focusIndex) {
715
+ selectionStart = selectionFocus;
716
+ selectionEnd = selectionAnchor;
717
+ } else {
718
+ selectionStart = selectionAnchor;
719
+ selectionEnd = selectionFocus;
720
+ }
721
+
722
+ const targetSelection = isForward ? selectionEnd : selectionStart;
723
+ const targetBlock = select.getBlock(targetSelection.clientId);
724
+ const targetBlockType = getBlockType(targetBlock.name);
725
+
726
+ if (!targetBlockType.merge) {
727
+ return;
728
+ }
729
+
730
+ const selectionA = selectionStart;
731
+ const selectionB = selectionEnd;
732
+ const blockA = select.getBlock(selectionA.clientId);
733
+ const blockAType = getBlockType(blockA.name);
734
+ const blockB = select.getBlock(selectionB.clientId);
735
+ const blockBType = getBlockType(blockB.name);
736
+ const htmlA = blockA.attributes[selectionA.attributeKey];
737
+ const htmlB = blockB.attributes[selectionB.attributeKey];
738
+ const attributeDefinitionA = blockAType.attributes[selectionA.attributeKey];
739
+ const attributeDefinitionB = blockBType.attributes[selectionB.attributeKey];
740
+ let valueA = create({
741
+ html: htmlA,
742
+ ...mapRichTextSettings(attributeDefinitionA)
743
+ });
744
+ let valueB = create({
745
+ html: htmlB,
746
+ ...mapRichTextSettings(attributeDefinitionB)
747
+ }); // A robust way to retain selection position through various transforms
748
+ // is to insert a special character at the position and then recover it.
749
+
750
+ const START_OF_SELECTED_AREA = '\u0086';
751
+ valueA = remove(valueA, selectionA.offset, valueA.text.length);
752
+ valueB = insert(valueB, START_OF_SELECTED_AREA, 0, selectionB.offset); // Clone the blocks so we don't manipulate the original.
753
+
754
+ const cloneA = cloneBlock(blockA, {
755
+ [selectionA.attributeKey]: toHTMLString({
756
+ value: valueA,
757
+ ...mapRichTextSettings(attributeDefinitionA)
758
+ })
759
+ });
760
+ const cloneB = cloneBlock(blockB, {
761
+ [selectionB.attributeKey]: toHTMLString({
762
+ value: valueB,
763
+ ...mapRichTextSettings(attributeDefinitionB)
764
+ })
765
+ });
766
+ const followingBlock = isForward ? cloneA : cloneB; // We can only merge blocks with similar types
767
+ // thus, we transform the block to merge first
768
+
769
+ const blocksWithTheSameType = blockA.name === blockB.name ? [followingBlock] : switchToBlockType(followingBlock, targetBlockType.name); // If the block types can not match, do nothing
770
+
771
+ if (!blocksWithTheSameType || !blocksWithTheSameType.length) {
772
+ return;
773
+ }
774
+
775
+ let updatedAttributes;
776
+
777
+ if (isForward) {
778
+ const blockToMerge = blocksWithTheSameType.pop();
779
+ updatedAttributes = targetBlockType.merge(blockToMerge.attributes, cloneB.attributes);
780
+ } else {
781
+ const blockToMerge = blocksWithTheSameType.shift();
782
+ updatedAttributes = targetBlockType.merge(cloneA.attributes, blockToMerge.attributes);
783
+ }
784
+
785
+ const newAttributeKey = findKey(updatedAttributes, v => typeof v === 'string' && v.indexOf(START_OF_SELECTED_AREA) !== -1);
786
+ const convertedHtml = updatedAttributes[newAttributeKey];
787
+ const convertedValue = create({
788
+ html: convertedHtml,
789
+ ...mapRichTextSettings(targetBlockType.attributes[newAttributeKey])
790
+ });
791
+ const newOffset = convertedValue.text.indexOf(START_OF_SELECTED_AREA);
792
+ const newValue = remove(convertedValue, newOffset, newOffset + 1);
793
+ const newHtml = toHTMLString({
794
+ value: newValue,
795
+ ...mapRichTextSettings(targetBlockType.attributes[newAttributeKey])
796
+ });
797
+ updatedAttributes[newAttributeKey] = newHtml;
798
+ const selectedBlockClientIds = select.getSelectedBlockClientIds();
799
+ const replacement = [...(isForward ? blocksWithTheSameType : []), { // Preserve the original client ID.
800
+ ...targetBlock,
801
+ attributes: { ...targetBlock.attributes,
802
+ ...updatedAttributes
803
+ }
804
+ }, ...(isForward ? [] : blocksWithTheSameType)];
805
+ registry.batch(() => {
806
+ dispatch.selectionChange(targetBlock.clientId, newAttributeKey, newOffset, newOffset);
807
+ dispatch.replaceBlocks(selectedBlockClientIds, replacement, 0, // If we don't pass the `indexToSelect` it will default to the last block.
808
+ select.getSelectedBlocksInitialCaretPosition());
809
+ });
810
+ };
811
+ /**
812
+ * Split the current selection.
813
+ */
814
+
815
+ export const __unstableSplitSelection = () => _ref13 => {
816
+ let {
817
+ select,
818
+ dispatch
819
+ } = _ref13;
820
+ const selectionAnchor = select.getSelectionStart();
821
+ const selectionFocus = select.getSelectionEnd();
822
+ if (selectionAnchor.clientId === selectionFocus.clientId) return; // Can't split if the selection is not set.
823
+
824
+ if (!selectionAnchor.attributeKey || !selectionFocus.attributeKey || typeof selectionAnchor.offset === 'undefined' || typeof selectionFocus.offset === 'undefined') return;
825
+ const anchorRootClientId = select.getBlockRootClientId(selectionAnchor.clientId);
826
+ const focusRootClientId = select.getBlockRootClientId(selectionFocus.clientId); // It's not splittable if the selection doesn't start and end in the same
827
+ // block list. Maybe in the future it should be allowed.
828
+
829
+ if (anchorRootClientId !== focusRootClientId) {
830
+ return;
831
+ }
832
+
833
+ const blockOrder = select.getBlockOrder(anchorRootClientId);
834
+ const anchorIndex = blockOrder.indexOf(selectionAnchor.clientId);
835
+ const focusIndex = blockOrder.indexOf(selectionFocus.clientId); // Reassign selection start and end based on order.
836
+
837
+ let selectionStart, selectionEnd;
838
+
839
+ if (anchorIndex > focusIndex) {
840
+ selectionStart = selectionFocus;
841
+ selectionEnd = selectionAnchor;
842
+ } else {
843
+ selectionStart = selectionAnchor;
844
+ selectionEnd = selectionFocus;
845
+ }
846
+
847
+ const selectionA = selectionStart;
848
+ const selectionB = selectionEnd;
849
+ const blockA = select.getBlock(selectionA.clientId);
850
+ const blockAType = getBlockType(blockA.name);
851
+ const blockB = select.getBlock(selectionB.clientId);
852
+ const blockBType = getBlockType(blockB.name);
853
+ const htmlA = blockA.attributes[selectionA.attributeKey];
854
+ const htmlB = blockB.attributes[selectionB.attributeKey];
855
+ const attributeDefinitionA = blockAType.attributes[selectionA.attributeKey];
856
+ const attributeDefinitionB = blockBType.attributes[selectionB.attributeKey];
857
+ let valueA = create({
858
+ html: htmlA,
859
+ ...mapRichTextSettings(attributeDefinitionA)
860
+ });
861
+ let valueB = create({
862
+ html: htmlB,
863
+ ...mapRichTextSettings(attributeDefinitionB)
864
+ });
865
+ valueA = remove(valueA, selectionA.offset, valueA.text.length);
866
+ valueB = remove(valueB, 0, selectionB.offset);
867
+ dispatch.replaceBlocks(select.getSelectedBlockClientIds(), [{ // Preserve the original client ID.
868
+ ...blockA,
869
+ attributes: { ...blockA.attributes,
870
+ [selectionA.attributeKey]: toHTMLString({
871
+ value: valueA,
872
+ ...mapRichTextSettings(attributeDefinitionA)
873
+ })
874
+ }
875
+ }, createBlock(getDefaultBlockName()), { // Preserve the original client ID.
876
+ ...blockB,
877
+ attributes: { ...blockB.attributes,
878
+ [selectionB.attributeKey]: toHTMLString({
879
+ value: valueB,
880
+ ...mapRichTextSettings(attributeDefinitionB)
881
+ })
882
+ }
883
+ }], 1, // If we don't pass the `indexToSelect` it will default to the last block.
884
+ select.getSelectedBlocksInitialCaretPosition());
885
+ };
886
+ /**
887
+ * Expand the selection to cover the entire blocks, removing partial selection.
888
+ */
889
+
890
+ export const __unstableExpandSelection = () => _ref14 => {
891
+ let {
892
+ select,
893
+ dispatch
894
+ } = _ref14;
895
+ const selectionAnchor = select.getSelectionStart();
896
+ const selectionFocus = select.getSelectionEnd();
897
+ dispatch.selectionChange({
898
+ start: {
899
+ clientId: selectionAnchor.clientId
900
+ },
901
+ end: {
902
+ clientId: selectionFocus.clientId
903
+ }
904
+ });
905
+ };
660
906
  /**
661
907
  * Action that merges two blocks.
662
908
  *
@@ -664,11 +910,11 @@ export const synchronizeTemplate = () => _ref11 => {
664
910
  * @param {string} secondBlockClientId Client ID of the second block to merge.
665
911
  */
666
912
 
667
- export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => _ref12 => {
913
+ export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => _ref15 => {
668
914
  let {
669
915
  select,
670
916
  dispatch
671
- } = _ref12;
917
+ } = _ref15;
672
918
  const blocks = [firstBlockClientId, secondBlockClientId];
673
919
  dispatch({
674
920
  type: 'MERGE_BLOCKS',
@@ -716,21 +962,13 @@ export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => _ref12 =
716
962
  if (canRestoreTextSelection) {
717
963
  const selectedBlock = clientId === clientIdA ? cloneA : cloneB;
718
964
  const html = selectedBlock.attributes[attributeKey];
719
- const {
720
- multiline: multilineTag,
721
- __unstableMultilineWrapperTags: multilineWrapperTags,
722
- __unstablePreserveWhiteSpace: preserveWhiteSpace
723
- } = attributeDefinition;
724
965
  const value = insert(create({
725
966
  html,
726
- multilineTag,
727
- multilineWrapperTags,
728
- preserveWhiteSpace
967
+ ...mapRichTextSettings(attributeDefinition)
729
968
  }), START_OF_SELECTED_AREA, offset, offset);
730
969
  selectedBlock.attributes[attributeKey] = toHTMLString({
731
970
  value,
732
- multilineTag,
733
- preserveWhiteSpace
971
+ ...mapRichTextSettings(attributeDefinition)
734
972
  });
735
973
  } // We can only merge blocks with similar types
736
974
  // thus, we transform the block to merge first.
@@ -748,23 +986,15 @@ export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => _ref12 =
748
986
  if (canRestoreTextSelection) {
749
987
  const newAttributeKey = findKey(updatedAttributes, v => typeof v === 'string' && v.indexOf(START_OF_SELECTED_AREA) !== -1);
750
988
  const convertedHtml = updatedAttributes[newAttributeKey];
751
- const {
752
- multiline: multilineTag,
753
- __unstableMultilineWrapperTags: multilineWrapperTags,
754
- __unstablePreserveWhiteSpace: preserveWhiteSpace
755
- } = blockAType.attributes[newAttributeKey];
756
989
  const convertedValue = create({
757
990
  html: convertedHtml,
758
- multilineTag,
759
- multilineWrapperTags,
760
- preserveWhiteSpace
991
+ ...mapRichTextSettings(blockAType.attributes[newAttributeKey])
761
992
  });
762
993
  const newOffset = convertedValue.text.indexOf(START_OF_SELECTED_AREA);
763
994
  const newValue = remove(convertedValue, newOffset, newOffset + 1);
764
995
  const newHtml = toHTMLString({
765
996
  value: newValue,
766
- multilineTag,
767
- preserveWhiteSpace
997
+ ...mapRichTextSettings(blockAType.attributes[newAttributeKey])
768
998
  });
769
999
  updatedAttributes[newAttributeKey] = newHtml;
770
1000
  dispatch.selectionChange(blockA.clientId, newAttributeKey, newOffset, newOffset);
@@ -788,11 +1018,11 @@ export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => _ref12 =
788
1018
 
789
1019
  export const removeBlocks = function (clientIds) {
790
1020
  let selectPrevious = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
791
- return _ref13 => {
1021
+ return _ref16 => {
792
1022
  let {
793
1023
  select,
794
1024
  dispatch
795
- } = _ref13;
1025
+ } = _ref16;
796
1026
 
797
1027
  if (!clientIds || !clientIds.length) {
798
1028
  return;
@@ -948,21 +1178,28 @@ export function exitFormattedText() {
948
1178
  /**
949
1179
  * Action that changes the position of the user caret.
950
1180
  *
951
- * @param {string} clientId The selected block client ID.
952
- * @param {string} attributeKey The selected block attribute key.
953
- * @param {number} startOffset The start offset.
954
- * @param {number} endOffset The end offset.
1181
+ * @param {string|WPSelection} clientId The selected block client ID.
1182
+ * @param {string} attributeKey The selected block attribute key.
1183
+ * @param {number} startOffset The start offset.
1184
+ * @param {number} endOffset The end offset.
955
1185
  *
956
1186
  * @return {Object} Action object.
957
1187
  */
958
1188
 
959
1189
  export function selectionChange(clientId, attributeKey, startOffset, endOffset) {
1190
+ if (typeof clientId === 'string') {
1191
+ return {
1192
+ type: 'SELECTION_CHANGE',
1193
+ clientId,
1194
+ attributeKey,
1195
+ startOffset,
1196
+ endOffset
1197
+ };
1198
+ }
1199
+
960
1200
  return {
961
1201
  type: 'SELECTION_CHANGE',
962
- clientId,
963
- attributeKey,
964
- startOffset,
965
- endOffset
1202
+ ...clientId
966
1203
  };
967
1204
  }
968
1205
  /**
@@ -974,10 +1211,10 @@ export function selectionChange(clientId, attributeKey, startOffset, endOffset)
974
1211
  * @param {?number} index Optional index where to insert the default block.
975
1212
  */
976
1213
 
977
- export const insertDefaultBlock = (attributes, rootClientId, index) => _ref14 => {
1214
+ export const insertDefaultBlock = (attributes, rootClientId, index) => _ref17 => {
978
1215
  let {
979
1216
  dispatch
980
- } = _ref14;
1217
+ } = _ref17;
981
1218
  // Abort if there is no default block type (if it has been unregistered).
982
1219
  const defaultBlockName = getDefaultBlockName();
983
1220
 
@@ -1066,10 +1303,10 @@ export function __unstableMarkNextChangeAsNotPersistent() {
1066
1303
  * selection changes have been recorded.
1067
1304
  */
1068
1305
 
1069
- export const __unstableMarkAutomaticChange = () => _ref15 => {
1306
+ export const __unstableMarkAutomaticChange = () => _ref18 => {
1070
1307
  let {
1071
1308
  dispatch
1072
- } = _ref15;
1309
+ } = _ref18;
1073
1310
  dispatch({
1074
1311
  type: 'MARK_AUTOMATIC_CHANGE'
1075
1312
  });
@@ -1090,10 +1327,10 @@ export const __unstableMarkAutomaticChange = () => _ref15 => {
1090
1327
 
1091
1328
  export const setNavigationMode = function () {
1092
1329
  let isNavigationMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1093
- return _ref16 => {
1330
+ return _ref19 => {
1094
1331
  let {
1095
1332
  dispatch
1096
- } = _ref16;
1333
+ } = _ref19;
1097
1334
  dispatch({
1098
1335
  type: 'SET_NAVIGATION_MODE',
1099
1336
  isNavigationMode
@@ -1114,10 +1351,10 @@ export const setNavigationMode = function () {
1114
1351
 
1115
1352
  export const setBlockMovingClientId = function () {
1116
1353
  let hasBlockMovingClientId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1117
- return _ref17 => {
1354
+ return _ref20 => {
1118
1355
  let {
1119
1356
  dispatch
1120
- } = _ref17;
1357
+ } = _ref20;
1121
1358
  dispatch({
1122
1359
  type: 'SET_BLOCK_MOVING_MODE',
1123
1360
  hasBlockMovingClientId
@@ -1137,11 +1374,11 @@ export const setBlockMovingClientId = function () {
1137
1374
 
1138
1375
  export const duplicateBlocks = function (clientIds) {
1139
1376
  let updateSelection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1140
- return _ref18 => {
1377
+ return _ref21 => {
1141
1378
  let {
1142
1379
  select,
1143
1380
  dispatch
1144
- } = _ref18;
1381
+ } = _ref21;
1145
1382
 
1146
1383
  if (!clientIds || !clientIds.length) {
1147
1384
  return;
@@ -1179,11 +1416,11 @@ export const duplicateBlocks = function (clientIds) {
1179
1416
  * @param {string} clientId
1180
1417
  */
1181
1418
 
1182
- export const insertBeforeBlock = clientId => _ref19 => {
1419
+ export const insertBeforeBlock = clientId => _ref22 => {
1183
1420
  let {
1184
1421
  select,
1185
1422
  dispatch
1186
- } = _ref19;
1423
+ } = _ref22;
1187
1424
 
1188
1425
  if (!clientId) {
1189
1426
  return;
@@ -1205,11 +1442,11 @@ export const insertBeforeBlock = clientId => _ref19 => {
1205
1442
  * @param {string} clientId
1206
1443
  */
1207
1444
 
1208
- export const insertAfterBlock = clientId => _ref20 => {
1445
+ export const insertAfterBlock = clientId => _ref23 => {
1209
1446
  let {
1210
1447
  select,
1211
1448
  dispatch
1212
- } = _ref20;
1449
+ } = _ref23;
1213
1450
 
1214
1451
  if (!clientId) {
1215
1452
  return;
@@ -1245,10 +1482,10 @@ export function toggleBlockHighlight(clientId, isHighlighted) {
1245
1482
  * @param {string} clientId Target block client ID.
1246
1483
  */
1247
1484
 
1248
- export const flashBlock = clientId => async _ref21 => {
1485
+ export const flashBlock = clientId => async _ref24 => {
1249
1486
  let {
1250
1487
  dispatch
1251
- } = _ref21;
1488
+ } = _ref24;
1252
1489
  dispatch(toggleBlockHighlight(clientId, true));
1253
1490
  await new Promise(resolve => setTimeout(resolve, 150));
1254
1491
  dispatch(toggleBlockHighlight(clientId, false));