@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
@@ -20,10 +20,20 @@ export function splitValue(_ref) {
20
20
 
21
21
  if (!onReplace || !onSplit) {
22
22
  return;
23
- }
23
+ } // Ensure the value has a selection. This might happen when trying to split
24
+ // an empty value before there was a `selectionchange` event.
25
+
24
26
 
27
+ const {
28
+ start = 0,
29
+ end = 0
30
+ } = value;
31
+ const valueWithEnsuredSelection = { ...value,
32
+ start,
33
+ end
34
+ };
25
35
  const blocks = [];
26
- const [before, after] = split(value);
36
+ const [before, after] = split(valueWithEnsuredSelection);
27
37
  const hasPastedBlocks = pastedBlocks.length > 0;
28
38
  let lastPastedBlockIndex = -1; // Consider the after value to be the original it is not empty and the
29
39
  // before value *is* empty.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/split-value.js"],"names":["isEmpty","split","toHTMLString","splitValue","value","pastedBlocks","onReplace","onSplit","onSplitMiddle","multilineTag","blocks","before","after","hasPastedBlocks","length","lastPastedBlockIndex","isAfterOriginal","push","indexToSelect","initialPosition"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,KAAlB,EAAyBC,YAAzB,QAA6C,sBAA7C;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,OAOH;AAAA,MAPwB;AAC3BC,IAAAA,KAD2B;AAE3BC,IAAAA,YAAY,GAAG,EAFY;AAG3BC,IAAAA,SAH2B;AAI3BC,IAAAA,OAJ2B;AAK3BC,IAAAA,aAL2B;AAM3BC,IAAAA;AAN2B,GAOxB;;AACH,MAAK,CAAEH,SAAF,IAAe,CAAEC,OAAtB,EAAgC;AAC/B;AACA;;AAED,QAAMG,MAAM,GAAG,EAAf;AACA,QAAM,CAAEC,MAAF,EAAUC,KAAV,IAAoBX,KAAK,CAAEG,KAAF,CAA/B;AACA,QAAMS,eAAe,GAAGR,YAAY,CAACS,MAAb,GAAsB,CAA9C;AACA,MAAIC,oBAAoB,GAAG,CAAC,CAA5B,CARG,CAUH;AACA;;AACA,QAAMC,eAAe,GAAGhB,OAAO,CAAEW,MAAF,CAAP,IAAqB,CAAEX,OAAO,CAAEY,KAAF,CAAtD,CAZG,CAcH;AACA;AACA;AACA;;AACA,MAAK,CAAEC,eAAF,IAAqB,CAAEb,OAAO,CAAEW,MAAF,CAAnC,EAAgD;AAC/CD,IAAAA,MAAM,CAACO,IAAP,CACCV,OAAO,CACNL,YAAY,CAAE;AACbE,MAAAA,KAAK,EAAEO,MADM;AAEbF,MAAAA;AAFa,KAAF,CADN,EAKN,CAAEO,eALI,CADR;AASAD,IAAAA,oBAAoB,IAAI,CAAxB;AACA;;AAED,MAAKF,eAAL,EAAuB;AACtBH,IAAAA,MAAM,CAACO,IAAP,CAAa,GAAGZ,YAAhB;AACAU,IAAAA,oBAAoB,IAAIV,YAAY,CAACS,MAArC;AACA,GAHD,MAGO,IAAKN,aAAL,EAAqB;AAC3BE,IAAAA,MAAM,CAACO,IAAP,CAAaT,aAAa,EAA1B;AACA,GApCE,CAsCH;AACA;AACA;AACA;;;AACA,MACCK,eAAe,GACZ,CAAEb,OAAO,CAAEY,KAAF,CADG,GAEZ,CAAEJ,aAAF,IAAmB,CAAER,OAAO,CAAEY,KAAF,CAHhC,EAIE;AACDF,IAAAA,MAAM,CAACO,IAAP,CACCV,OAAO,CACNL,YAAY,CAAE;AACbE,MAAAA,KAAK,EAAEQ,KADM;AAEbH,MAAAA;AAFa,KAAF,CADN,EAKNO,eALM,CADR;AASA,GAxDE,CA0DH;AACA;;;AACA,QAAME,aAAa,GAAGL,eAAe,GAAGE,oBAAH,GAA0B,CAA/D,CA5DG,CA8DH;AACA;;AACA,QAAMI,eAAe,GAAGN,eAAe,GAAG,CAAC,CAAJ,GAAQ,CAA/C;AAEAP,EAAAA,SAAS,CAAEI,MAAF,EAAUQ,aAAV,EAAyBC,eAAzB,CAAT;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { isEmpty, split, toHTMLString } from '@wordpress/rich-text';\n\n/*\n * Signals to the RichText owner that the block can be replaced with two blocks\n * as a result of splitting the block by pressing enter, or with blocks as a\n * result of splitting the block by pasting block content in the instance.\n */\nexport function splitValue( {\n\tvalue,\n\tpastedBlocks = [],\n\tonReplace,\n\tonSplit,\n\tonSplitMiddle,\n\tmultilineTag,\n} ) {\n\tif ( ! onReplace || ! onSplit ) {\n\t\treturn;\n\t}\n\n\tconst blocks = [];\n\tconst [ before, after ] = split( value );\n\tconst hasPastedBlocks = pastedBlocks.length > 0;\n\tlet lastPastedBlockIndex = -1;\n\n\t// Consider the after value to be the original it is not empty and the\n\t// before value *is* empty.\n\tconst isAfterOriginal = isEmpty( before ) && ! isEmpty( after );\n\n\t// Create a block with the content before the caret if there's no pasted\n\t// blocks, or if there are pasted blocks and the value is not empty. We do\n\t// not want a leading empty block on paste, but we do if split with e.g. the\n\t// enter key.\n\tif ( ! hasPastedBlocks || ! isEmpty( before ) ) {\n\t\tblocks.push(\n\t\t\tonSplit(\n\t\t\t\ttoHTMLString( {\n\t\t\t\t\tvalue: before,\n\t\t\t\t\tmultilineTag,\n\t\t\t\t} ),\n\t\t\t\t! isAfterOriginal\n\t\t\t)\n\t\t);\n\t\tlastPastedBlockIndex += 1;\n\t}\n\n\tif ( hasPastedBlocks ) {\n\t\tblocks.push( ...pastedBlocks );\n\t\tlastPastedBlockIndex += pastedBlocks.length;\n\t} else if ( onSplitMiddle ) {\n\t\tblocks.push( onSplitMiddle() );\n\t}\n\n\t// If there's pasted blocks, append a block with non empty content / after\n\t// the caret. Otherwise, do append an empty block if there is no\n\t// `onSplitMiddle` prop, but if there is and the content is empty, the\n\t// middle block is enough to set focus in.\n\tif (\n\t\thasPastedBlocks\n\t\t\t? ! isEmpty( after )\n\t\t\t: ! onSplitMiddle || ! isEmpty( after )\n\t) {\n\t\tblocks.push(\n\t\t\tonSplit(\n\t\t\t\ttoHTMLString( {\n\t\t\t\t\tvalue: after,\n\t\t\t\t\tmultilineTag,\n\t\t\t\t} ),\n\t\t\t\tisAfterOriginal\n\t\t\t)\n\t\t);\n\t}\n\n\t// If there are pasted blocks, set the selection to the last one. Otherwise,\n\t// set the selection to the second block.\n\tconst indexToSelect = hasPastedBlocks ? lastPastedBlockIndex : 1;\n\n\t// If there are pasted blocks, move the caret to the end of the selected\n\t// block Otherwise, retain the default value.\n\tconst initialPosition = hasPastedBlocks ? -1 : 0;\n\n\tonReplace( blocks, indexToSelect, initialPosition );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/split-value.js"],"names":["isEmpty","split","toHTMLString","splitValue","value","pastedBlocks","onReplace","onSplit","onSplitMiddle","multilineTag","start","end","valueWithEnsuredSelection","blocks","before","after","hasPastedBlocks","length","lastPastedBlockIndex","isAfterOriginal","push","indexToSelect","initialPosition"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,KAAlB,EAAyBC,YAAzB,QAA6C,sBAA7C;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,OAOH;AAAA,MAPwB;AAC3BC,IAAAA,KAD2B;AAE3BC,IAAAA,YAAY,GAAG,EAFY;AAG3BC,IAAAA,SAH2B;AAI3BC,IAAAA,OAJ2B;AAK3BC,IAAAA,aAL2B;AAM3BC,IAAAA;AAN2B,GAOxB;;AACH,MAAK,CAAEH,SAAF,IAAe,CAAEC,OAAtB,EAAgC;AAC/B;AACA,GAHE,CAKH;AACA;;;AACA,QAAM;AAAEG,IAAAA,KAAK,GAAG,CAAV;AAAaC,IAAAA,GAAG,GAAG;AAAnB,MAAyBP,KAA/B;AACA,QAAMQ,yBAAyB,GAAG,EAAE,GAAGR,KAAL;AAAYM,IAAAA,KAAZ;AAAmBC,IAAAA;AAAnB,GAAlC;AACA,QAAME,MAAM,GAAG,EAAf;AACA,QAAM,CAAEC,MAAF,EAAUC,KAAV,IAAoBd,KAAK,CAAEW,yBAAF,CAA/B;AACA,QAAMI,eAAe,GAAGX,YAAY,CAACY,MAAb,GAAsB,CAA9C;AACA,MAAIC,oBAAoB,GAAG,CAAC,CAA5B,CAZG,CAcH;AACA;;AACA,QAAMC,eAAe,GAAGnB,OAAO,CAAEc,MAAF,CAAP,IAAqB,CAAEd,OAAO,CAAEe,KAAF,CAAtD,CAhBG,CAkBH;AACA;AACA;AACA;;AACA,MAAK,CAAEC,eAAF,IAAqB,CAAEhB,OAAO,CAAEc,MAAF,CAAnC,EAAgD;AAC/CD,IAAAA,MAAM,CAACO,IAAP,CACCb,OAAO,CACNL,YAAY,CAAE;AACbE,MAAAA,KAAK,EAAEU,MADM;AAEbL,MAAAA;AAFa,KAAF,CADN,EAKN,CAAEU,eALI,CADR;AASAD,IAAAA,oBAAoB,IAAI,CAAxB;AACA;;AAED,MAAKF,eAAL,EAAuB;AACtBH,IAAAA,MAAM,CAACO,IAAP,CAAa,GAAGf,YAAhB;AACAa,IAAAA,oBAAoB,IAAIb,YAAY,CAACY,MAArC;AACA,GAHD,MAGO,IAAKT,aAAL,EAAqB;AAC3BK,IAAAA,MAAM,CAACO,IAAP,CAAaZ,aAAa,EAA1B;AACA,GAxCE,CA0CH;AACA;AACA;AACA;;;AACA,MACCQ,eAAe,GACZ,CAAEhB,OAAO,CAAEe,KAAF,CADG,GAEZ,CAAEP,aAAF,IAAmB,CAAER,OAAO,CAAEe,KAAF,CAHhC,EAIE;AACDF,IAAAA,MAAM,CAACO,IAAP,CACCb,OAAO,CACNL,YAAY,CAAE;AACbE,MAAAA,KAAK,EAAEW,KADM;AAEbN,MAAAA;AAFa,KAAF,CADN,EAKNU,eALM,CADR;AASA,GA5DE,CA8DH;AACA;;;AACA,QAAME,aAAa,GAAGL,eAAe,GAAGE,oBAAH,GAA0B,CAA/D,CAhEG,CAkEH;AACA;;AACA,QAAMI,eAAe,GAAGN,eAAe,GAAG,CAAC,CAAJ,GAAQ,CAA/C;AAEAV,EAAAA,SAAS,CAAEO,MAAF,EAAUQ,aAAV,EAAyBC,eAAzB,CAAT;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { isEmpty, split, toHTMLString } from '@wordpress/rich-text';\n\n/*\n * Signals to the RichText owner that the block can be replaced with two blocks\n * as a result of splitting the block by pressing enter, or with blocks as a\n * result of splitting the block by pasting block content in the instance.\n */\nexport function splitValue( {\n\tvalue,\n\tpastedBlocks = [],\n\tonReplace,\n\tonSplit,\n\tonSplitMiddle,\n\tmultilineTag,\n} ) {\n\tif ( ! onReplace || ! onSplit ) {\n\t\treturn;\n\t}\n\n\t// Ensure the value has a selection. This might happen when trying to split\n\t// an empty value before there was a `selectionchange` event.\n\tconst { start = 0, end = 0 } = value;\n\tconst valueWithEnsuredSelection = { ...value, start, end };\n\tconst blocks = [];\n\tconst [ before, after ] = split( valueWithEnsuredSelection );\n\tconst hasPastedBlocks = pastedBlocks.length > 0;\n\tlet lastPastedBlockIndex = -1;\n\n\t// Consider the after value to be the original it is not empty and the\n\t// before value *is* empty.\n\tconst isAfterOriginal = isEmpty( before ) && ! isEmpty( after );\n\n\t// Create a block with the content before the caret if there's no pasted\n\t// blocks, or if there are pasted blocks and the value is not empty. We do\n\t// not want a leading empty block on paste, but we do if split with e.g. the\n\t// enter key.\n\tif ( ! hasPastedBlocks || ! isEmpty( before ) ) {\n\t\tblocks.push(\n\t\t\tonSplit(\n\t\t\t\ttoHTMLString( {\n\t\t\t\t\tvalue: before,\n\t\t\t\t\tmultilineTag,\n\t\t\t\t} ),\n\t\t\t\t! isAfterOriginal\n\t\t\t)\n\t\t);\n\t\tlastPastedBlockIndex += 1;\n\t}\n\n\tif ( hasPastedBlocks ) {\n\t\tblocks.push( ...pastedBlocks );\n\t\tlastPastedBlockIndex += pastedBlocks.length;\n\t} else if ( onSplitMiddle ) {\n\t\tblocks.push( onSplitMiddle() );\n\t}\n\n\t// If there's pasted blocks, append a block with non empty content / after\n\t// the caret. Otherwise, do append an empty block if there is no\n\t// `onSplitMiddle` prop, but if there is and the content is empty, the\n\t// middle block is enough to set focus in.\n\tif (\n\t\thasPastedBlocks\n\t\t\t? ! isEmpty( after )\n\t\t\t: ! onSplitMiddle || ! isEmpty( after )\n\t) {\n\t\tblocks.push(\n\t\t\tonSplit(\n\t\t\t\ttoHTMLString( {\n\t\t\t\t\tvalue: after,\n\t\t\t\t\tmultilineTag,\n\t\t\t\t} ),\n\t\t\t\tisAfterOriginal\n\t\t\t)\n\t\t);\n\t}\n\n\t// If there are pasted blocks, set the selection to the last one. Otherwise,\n\t// set the selection to the second block.\n\tconst indexToSelect = hasPastedBlocks ? lastPastedBlockIndex : 1;\n\n\t// If there are pasted blocks, move the caret to the end of the selected\n\t// block Otherwise, retain the default value.\n\tconst initialPosition = hasPastedBlocks ? -1 : 0;\n\n\tonReplace( blocks, indexToSelect, initialPosition );\n}\n"]}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useRefEffect } from '@wordpress/compose';
5
+ import { useSelect } from '@wordpress/data';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ import { store as blockEditorStore } from '../../store';
11
+ export function useFirefoxCompat() {
12
+ const {
13
+ isMultiSelecting
14
+ } = useSelect(blockEditorStore);
15
+ return useRefEffect(element => {
16
+ function onFocus() {
17
+ if (!isMultiSelecting()) {
18
+ return;
19
+ } // This is a little hack to work around focus issues with nested
20
+ // editable elements in Firefox. For some reason the editable child
21
+ // element sometimes regains focus, while it should not be focusable
22
+ // and focus should remain on the editable parent element.
23
+ // To do: try to find the cause of the shifting focus.
24
+
25
+
26
+ const parentEditable = element.parentElement.closest('[contenteditable="true"]');
27
+
28
+ if (parentEditable) {
29
+ parentEditable.focus();
30
+ }
31
+ }
32
+
33
+ element.addEventListener('focus', onFocus);
34
+ return () => {
35
+ element.removeEventListener('focus', onFocus);
36
+ };
37
+ }, []);
38
+ }
39
+ //# sourceMappingURL=use-firefox-compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-firefox-compat.js"],"names":["useRefEffect","useSelect","store","blockEditorStore","useFirefoxCompat","isMultiSelecting","element","onFocus","parentEditable","parentElement","closest","focus","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,oBAA7B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,OAAO,SAASC,gBAAT,GAA4B;AAClC,QAAM;AAAEC,IAAAA;AAAF,MAAuBJ,SAAS,CAAEE,gBAAF,CAAtC;AACA,SAAOH,YAAY,CAAIM,OAAF,IAAe;AACnC,aAASC,OAAT,GAAmB;AAClB,UAAK,CAAEF,gBAAgB,EAAvB,EAA4B;AAC3B;AACA,OAHiB,CAKlB;AACA;AACA;AACA;AACA;;;AACA,YAAMG,cAAc,GAAGF,OAAO,CAACG,aAAR,CAAsBC,OAAtB,CACtB,0BADsB,CAAvB;;AAIA,UAAKF,cAAL,EAAsB;AACrBA,QAAAA,cAAc,CAACG,KAAf;AACA;AACD;;AAEDL,IAAAA,OAAO,CAACM,gBAAR,CAA0B,OAA1B,EAAmCL,OAAnC;AACA,WAAO,MAAM;AACZD,MAAAA,OAAO,CAACO,mBAAR,CAA6B,OAA7B,EAAsCN,OAAtC;AACA,KAFD;AAGA,GAxBkB,EAwBhB,EAxBgB,CAAnB;AAyBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nexport function useFirefoxCompat() {\n\tconst { isMultiSelecting } = useSelect( blockEditorStore );\n\treturn useRefEffect( ( element ) => {\n\t\tfunction onFocus() {\n\t\t\tif ( ! isMultiSelecting() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// This is a little hack to work around focus issues with nested\n\t\t\t// editable elements in Firefox. For some reason the editable child\n\t\t\t// element sometimes regains focus, while it should not be focusable\n\t\t\t// and focus should remain on the editable parent element.\n\t\t\t// To do: try to find the cause of the shifting focus.\n\t\t\tconst parentEditable = element.parentElement.closest(\n\t\t\t\t'[contenteditable=\"true\"]'\n\t\t\t);\n\n\t\t\tif ( parentEditable ) {\n\t\t\t\tparentEditable.focus();\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'focus', onFocus );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'focus', onFocus );\n\t\t};\n\t}, [] );\n}\n"]}
@@ -1,9 +1,14 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { findKey } from 'lodash';
1
5
  /**
2
6
  * WordPress dependencies
3
7
  */
8
+
4
9
  import { useRef } from '@wordpress/element';
5
10
  import { useRefEffect } from '@wordpress/compose';
6
- import { slice, toHTMLString } from '@wordpress/rich-text';
11
+ import { insert, toHTMLString } from '@wordpress/rich-text';
7
12
  import { getBlockTransforms, findTransform } from '@wordpress/blocks';
8
13
  import { useDispatch } from '@wordpress/data';
9
14
  /**
@@ -11,7 +16,31 @@ import { useDispatch } from '@wordpress/data';
11
16
  */
12
17
 
13
18
  import { store as blockEditorStore } from '../../store';
14
- import { preventEventDiscovery } from './prevent-event-discovery';
19
+ import { preventEventDiscovery } from './prevent-event-discovery'; // A robust way to retain selection position through various
20
+ // transforms is to insert a special character at the position and
21
+ // then recover it.
22
+
23
+ const START_OF_SELECTED_AREA = '\u0086';
24
+
25
+ function findSelection(blocks) {
26
+ let i = blocks.length;
27
+
28
+ while (i--) {
29
+ const attributeKey = findKey(blocks[i].attributes, v => typeof v === 'string' && v.indexOf(START_OF_SELECTED_AREA) !== -1);
30
+
31
+ if (attributeKey) {
32
+ blocks[i].attributes[attributeKey] = blocks[i].attributes[attributeKey].replace(START_OF_SELECTED_AREA, '');
33
+ return blocks[i].clientId;
34
+ }
35
+
36
+ const nestedSelection = findSelection(blocks[i].innerBlocks);
37
+
38
+ if (nestedSelection) {
39
+ return nestedSelection;
40
+ }
41
+ }
42
+ }
43
+
15
44
  export function useInputRules(props) {
16
45
  const {
17
46
  __unstableMarkLastChangeAsPersistent,
@@ -23,7 +52,8 @@ export function useInputRules(props) {
23
52
  function inputRule() {
24
53
  const {
25
54
  value,
26
- onReplace
55
+ onReplace,
56
+ selectionChange
27
57
  } = propsRef.current;
28
58
 
29
59
  if (!onReplace) {
@@ -59,9 +89,10 @@ export function useInputRules(props) {
59
89
  }
60
90
 
61
91
  const content = toHTMLString({
62
- value: slice(value, start, text.length)
92
+ value: insert(value, START_OF_SELECTED_AREA, 0, start)
63
93
  });
64
94
  const block = transformation.transform(content);
95
+ selectionChange(findSelection([block]));
65
96
  onReplace([block]);
66
97
 
67
98
  __unstableMarkAutomaticChange();
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["useRef","useRefEffect","slice","toHTMLString","getBlockTransforms","findTransform","useDispatch","store","blockEditorStore","preventEventDiscovery","useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","propsRef","current","element","inputRule","value","onReplace","start","text","characterBefore","trimmedTextBefore","trim","prefixTransforms","filter","type","transformation","prefix","content","length","block","transform","onInput","event","inputType","onChange","__unstableAllowPrefixTransformations","formatTypes","transformed","reduce","accumlator","__unstableInputRule","activeFormats","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,KAAT,EAAgBC,YAAhB,QAAoC,sBAApC;AACA,SAASC,kBAAT,EAA6BC,aAA7B,QAAkD,mBAAlD;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAT,QAAsC,2BAAtC;AAEA,OAAO,SAASC,aAAT,CAAwBC,KAAxB,EAAgC;AACtC,QAAM;AACLC,IAAAA,oCADK;AAELC,IAAAA;AAFK,MAGFP,WAAW,CAAEE,gBAAF,CAHf;AAIA,QAAMM,QAAQ,GAAGd,MAAM,CAAEW,KAAF,CAAvB;AACAG,EAAAA,QAAQ,CAACC,OAAT,GAAmBJ,KAAnB;AACA,SAAOV,YAAY,CAAIe,OAAF,IAAe;AACnC,aAASC,SAAT,GAAqB;AACpB,YAAM;AAAEC,QAAAA,KAAF;AAASC,QAAAA;AAAT,UAAuBL,QAAQ,CAACC,OAAtC;;AAEA,UAAK,CAAEI,SAAP,EAAmB;AACl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FyB,CASzB;;AACA,UAAKqB,SAAS,KAAK,YAAd,IAA8BT,IAAI,KAAK,gBAA5C,EAA+D;AAC9D;AACA;;AAED,UAAKW,oCAAoC,IAAIrB,SAA7C,EAAyD;AACxDA,QAAAA,SAAS;AACT;;AAED,YAAMuB,WAAW,GAAGD,WAAW,CAACE,MAAZ,CACnB,CAAEC,UAAF,YAA2C;AAAA,YAA7B;AAAEC,UAAAA;AAAF,SAA6B;;AAC1C,YAAKA,mBAAL,EAA2B;AAC1BD,UAAAA,UAAU,GAAGC,mBAAmB,CAAED,UAAF,CAAhC;AACA;;AAED,eAAOA,UAAP;AACA,OAPkB,EAQnBjC,qBAAqB,CAAES,KAAF,CARF,CAApB;;AAWA,UAAKsB,WAAW,KAAKtB,KAArB,EAA6B;AAC5BN,QAAAA,oCAAoC;;AACpCyB,QAAAA,QAAQ,CAAE,EACT,GAAGG,WADM;AAETI,UAAAA,aAAa,EAAE1B,KAAK,CAAC0B;AAFZ,SAAF,CAAR;;AAIA/B,QAAAA,6BAA6B;AAC7B;AACD;;AAEDG,IAAAA,OAAO,CAAC6B,gBAAR,CAA0B,OAA1B,EAAmCX,OAAnC;AACAlB,IAAAA,OAAO,CAAC6B,gBAAR,CAA0B,gBAA1B,EAA4CX,OAA5C;AACA,WAAO,MAAM;AACZlB,MAAAA,OAAO,CAAC8B,mBAAR,CAA6B,OAA7B,EAAsCZ,OAAtC;AACAlB,MAAAA,OAAO,CAAC8B,mBAAR,CAA6B,gBAA7B,EAA+CZ,OAA/C;AACA,KAHD;AAIA,GArFkB,EAqFhB,EArFgB,CAAnB;AAsFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { slice, toHTMLString } from '@wordpress/rich-text';\nimport { getBlockTransforms, findTransform } from '@wordpress/blocks';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { preventEventDiscovery } from './prevent-event-discovery';\n\nexport function useInputRules( props ) {\n\tconst {\n\t\t__unstableMarkLastChangeAsPersistent,\n\t\t__unstableMarkAutomaticChange,\n\t} = useDispatch( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction inputRule() {\n\t\t\tconst { value, onReplace } = propsRef.current;\n\n\t\t\tif ( ! onReplace ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { start, text } = value;\n\t\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t\t// The character right before the caret must be a plain space.\n\t\t\tif ( characterBefore !== ' ' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst trimmedTextBefore = text.slice( 0, start ).trim();\n\t\t\tconst prefixTransforms = getBlockTransforms( 'from' ).filter(\n\t\t\t\t( { type } ) => type === 'prefix'\n\t\t\t);\n\t\t\tconst transformation = findTransform(\n\t\t\t\tprefixTransforms,\n\t\t\t\t( { prefix } ) => {\n\t\t\t\t\treturn trimmedTextBefore === prefix;\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( ! transformation ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst content = toHTMLString( {\n\t\t\t\tvalue: slice( value, start, text.length ),\n\t\t\t} );\n\t\t\tconst block = transformation.transform( content );\n\n\t\t\tonReplace( [ block ] );\n\t\t\t__unstableMarkAutomaticChange();\n\t\t}\n\n\t\tfunction onInput( event ) {\n\t\t\tconst { inputType, type } = event;\n\t\t\tconst {\n\t\t\t\tvalue,\n\t\t\t\tonChange,\n\t\t\t\t__unstableAllowPrefixTransformations,\n\t\t\t\tformatTypes,\n\t\t\t} = propsRef.current;\n\n\t\t\t// Only run input rules when inserting text.\n\t\t\tif ( inputType !== 'insertText' && type !== 'compositionend' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( __unstableAllowPrefixTransformations && inputRule ) {\n\t\t\t\tinputRule();\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstableInputRule } ) => {\n\t\t\t\t\tif ( __unstableInputRule ) {\n\t\t\t\t\t\taccumlator = __unstableInputRule( accumlator );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tpreventEventDiscovery( value )\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\t\tonChange( {\n\t\t\t\t\t...transformed,\n\t\t\t\t\tactiveFormats: value.activeFormats,\n\t\t\t\t} );\n\t\t\t\t__unstableMarkAutomaticChange();\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'input', onInput );\n\t\telement.addEventListener( 'compositionend', onInput );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'input', onInput );\n\t\t\telement.removeEventListener( 'compositionend', onInput );\n\t\t};\n\t}, [] );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["findKey","useRef","useRefEffect","insert","toHTMLString","getBlockTransforms","findTransform","useDispatch","store","blockEditorStore","preventEventDiscovery","START_OF_SELECTED_AREA","findSelection","blocks","i","length","attributeKey","attributes","v","indexOf","replace","clientId","nestedSelection","innerBlocks","useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","propsRef","current","element","inputRule","value","onReplace","selectionChange","start","text","characterBefore","slice","trimmedTextBefore","trim","prefixTransforms","filter","type","transformation","prefix","content","block","transform","onInput","event","inputType","onChange","__unstableAllowPrefixTransformations","formatTypes","transformed","reduce","accumlator","__unstableInputRule","activeFormats","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,oBAAvB;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,MAAT,EAAiBC,YAAjB,QAAqC,sBAArC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uFA","sourcesContent":["/**\n * External dependencies\n */\nimport { findKey } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { insert, toHTMLString } from '@wordpress/rich-text';\nimport { getBlockTransforms, findTransform } from '@wordpress/blocks';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { preventEventDiscovery } from './prevent-event-discovery';\n\n// A robust way to retain selection position through various\n// transforms is to insert a special character at the position and\n// then recover it.\nconst START_OF_SELECTED_AREA = '\\u0086';\n\nfunction findSelection( blocks ) {\n\tlet i = blocks.length;\n\n\twhile ( i-- ) {\n\t\tconst attributeKey = findKey(\n\t\t\tblocks[ i ].attributes,\n\t\t\t( v ) =>\n\t\t\t\ttypeof v === 'string' &&\n\t\t\t\tv.indexOf( START_OF_SELECTED_AREA ) !== -1\n\t\t);\n\n\t\tif ( attributeKey ) {\n\t\t\tblocks[ i ].attributes[ attributeKey ] = blocks[ i ].attributes[\n\t\t\t\tattributeKey\n\t\t\t].replace( START_OF_SELECTED_AREA, '' );\n\t\t\treturn blocks[ i ].clientId;\n\t\t}\n\n\t\tconst nestedSelection = findSelection( blocks[ i ].innerBlocks );\n\n\t\tif ( nestedSelection ) {\n\t\t\treturn nestedSelection;\n\t\t}\n\t}\n}\n\nexport function useInputRules( props ) {\n\tconst {\n\t\t__unstableMarkLastChangeAsPersistent,\n\t\t__unstableMarkAutomaticChange,\n\t} = useDispatch( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction inputRule() {\n\t\t\tconst { value, onReplace, selectionChange } = propsRef.current;\n\n\t\t\tif ( ! onReplace ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { start, text } = value;\n\t\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t\t// The character right before the caret must be a plain space.\n\t\t\tif ( characterBefore !== ' ' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst trimmedTextBefore = text.slice( 0, start ).trim();\n\t\t\tconst prefixTransforms = getBlockTransforms( 'from' ).filter(\n\t\t\t\t( { type } ) => type === 'prefix'\n\t\t\t);\n\t\t\tconst transformation = findTransform(\n\t\t\t\tprefixTransforms,\n\t\t\t\t( { prefix } ) => {\n\t\t\t\t\treturn trimmedTextBefore === prefix;\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( ! transformation ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst content = toHTMLString( {\n\t\t\t\tvalue: insert( value, START_OF_SELECTED_AREA, 0, start ),\n\t\t\t} );\n\t\t\tconst block = transformation.transform( content );\n\n\t\t\tselectionChange( findSelection( [ block ] ) );\n\t\t\tonReplace( [ block ] );\n\t\t\t__unstableMarkAutomaticChange();\n\t\t}\n\n\t\tfunction onInput( event ) {\n\t\t\tconst { inputType, type } = event;\n\t\t\tconst {\n\t\t\t\tvalue,\n\t\t\t\tonChange,\n\t\t\t\t__unstableAllowPrefixTransformations,\n\t\t\t\tformatTypes,\n\t\t\t} = propsRef.current;\n\n\t\t\t// Only run input rules when inserting text.\n\t\t\tif ( inputType !== 'insertText' && type !== 'compositionend' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( __unstableAllowPrefixTransformations && inputRule ) {\n\t\t\t\tinputRule();\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstableInputRule } ) => {\n\t\t\t\t\tif ( __unstableInputRule ) {\n\t\t\t\t\t\taccumlator = __unstableInputRule( accumlator );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tpreventEventDiscovery( value )\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\t\tonChange( {\n\t\t\t\t\t...transformed,\n\t\t\t\t\tactiveFormats: value.activeFormats,\n\t\t\t\t} );\n\t\t\t\t__unstableMarkAutomaticChange();\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'input', onInput );\n\t\telement.addEventListener( 'compositionend', onInput );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'input', onInput );\n\t\t\telement.removeEventListener( 'compositionend', onInput );\n\t\t};\n\t}, [] );\n}\n"]}
@@ -29,6 +29,10 @@ const SkipToSelectedBlock = _ref => {
29
29
  onClick: onClick
30
30
  }, __('Skip to the selected block')) : null;
31
31
  };
32
+ /**
33
+ * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md
34
+ */
35
+
32
36
 
33
37
  export default withSelect(select => {
34
38
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/skip-to-selected-block/index.js"],"names":["withSelect","__","Button","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","SkipToSelectedBlock","selectedBlockClientId","ref","onClick","current","focus","select","getBlockSelectionStart"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,iBAA3B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,8CAArD;;AAEA,MAAMC,mBAAmB,GAAG,QAAiC;AAAA,MAA/B;AAAEC,IAAAA;AAAF,GAA+B;AAC5D,QAAMC,GAAG,GAAGH,WAAW,CAAEE,qBAAF,CAAvB;;AACA,QAAME,OAAO,GAAG,MAAM;AACrBD,IAAAA,GAAG,CAACE,OAAJ,CAAYC,KAAZ;AACA,GAFD;;AAIA,SAAOJ,qBAAqB,GAC3B,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,SAAS,EAAC,qCAFX;AAGC,IAAA,OAAO,EAAGE;AAHX,KAKGT,EAAE,CAAE,4BAAF,CALL,CAD2B,GAQxB,IARJ;AASA,CAfD;;AAiBA,eAAeD,UAAU,CAAIa,MAAF,IAAc;AACxC,SAAO;AACNL,IAAAA,qBAAqB,EAAEK,MAAM,CAC5BT,gBAD4B,CAAN,CAErBU,sBAFqB;AADjB,GAAP;AAKA,CANwB,CAAV,CAMVP,mBANU,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { withSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nconst SkipToSelectedBlock = ( { selectedBlockClientId } ) => {\n\tconst ref = useBlockRef( selectedBlockClientId );\n\tconst onClick = () => {\n\t\tref.current.focus();\n\t};\n\n\treturn selectedBlockClientId ? (\n\t\t<Button\n\t\t\tvariant=\"secondary\"\n\t\t\tclassName=\"block-editor-skip-to-selected-block\"\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ __( 'Skip to the selected block' ) }\n\t\t</Button>\n\t) : null;\n};\n\nexport default withSelect( ( select ) => {\n\treturn {\n\t\tselectedBlockClientId: select(\n\t\t\tblockEditorStore\n\t\t).getBlockSelectionStart(),\n\t};\n} )( SkipToSelectedBlock );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/skip-to-selected-block/index.js"],"names":["withSelect","__","Button","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","SkipToSelectedBlock","selectedBlockClientId","ref","onClick","current","focus","select","getBlockSelectionStart"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,iBAA3B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,8CAArD;;AAEA,MAAMC,mBAAmB,GAAG,QAAiC;AAAA,MAA/B;AAAEC,IAAAA;AAAF,GAA+B;AAC5D,QAAMC,GAAG,GAAGH,WAAW,CAAEE,qBAAF,CAAvB;;AACA,QAAME,OAAO,GAAG,MAAM;AACrBD,IAAAA,GAAG,CAACE,OAAJ,CAAYC,KAAZ;AACA,GAFD;;AAIA,SAAOJ,qBAAqB,GAC3B,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,SAAS,EAAC,qCAFX;AAGC,IAAA,OAAO,EAAGE;AAHX,KAKGT,EAAE,CAAE,4BAAF,CALL,CAD2B,GAQxB,IARJ;AASA,CAfD;AAiBA;AACA;AACA;;;AACA,eAAeD,UAAU,CAAIa,MAAF,IAAc;AACxC,SAAO;AACNL,IAAAA,qBAAqB,EAAEK,MAAM,CAC5BT,gBAD4B,CAAN,CAErBU,sBAFqB;AADjB,GAAP;AAKA,CANwB,CAAV,CAMVP,mBANU,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { withSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nconst SkipToSelectedBlock = ( { selectedBlockClientId } ) => {\n\tconst ref = useBlockRef( selectedBlockClientId );\n\tconst onClick = () => {\n\t\tref.current.focus();\n\t};\n\n\treturn selectedBlockClientId ? (\n\t\t<Button\n\t\t\tvariant=\"secondary\"\n\t\t\tclassName=\"block-editor-skip-to-selected-block\"\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ __( 'Skip to the selected block' ) }\n\t\t</Button>\n\t) : null;\n};\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md\n */\nexport default withSelect( ( select ) => {\n\treturn {\n\t\tselectedBlockClientId: select(\n\t\t\tblockEditorStore\n\t\t).getBlockSelectionStart(),\n\t};\n} )( SkipToSelectedBlock );\n"]}
@@ -21,11 +21,15 @@ import useMultiSelection from './use-multi-selection';
21
21
  import useTabNav from './use-tab-nav';
22
22
  import useArrowNav from './use-arrow-nav';
23
23
  import useSelectAll from './use-select-all';
24
+ import useDragSelection from './use-drag-selection';
25
+ import useSelectionObserver from './use-selection-observer';
26
+ import useClickSelection from './use-click-selection';
27
+ import useInput from './use-input';
24
28
  import { store as blockEditorStore } from '../../store';
25
29
  export function useWritingFlow() {
26
30
  const [before, ref, after] = useTabNav();
27
31
  const hasMultiSelection = useSelect(select => select(blockEditorStore).hasMultiSelection(), []);
28
- return [before, useMergeRefs([ref, useMultiSelection(), useSelectAll(), useArrowNav(), useRefEffect(node => {
32
+ return [before, useMergeRefs([ref, useInput(), useDragSelection(), useSelectionObserver(), useClickSelection(), useMultiSelection(), useSelectAll(), useArrowNav(), useRefEffect(node => {
29
33
  node.tabIndex = -1;
30
34
  node.contentEditable = hasMultiSelection;
31
35
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["classNames","useSelect","__","useMergeRefs","useRefEffect","forwardRef","useMultiSelection","useTabNav","useArrowNav","useSelectAll","store","blockEditorStore","useWritingFlow","before","ref","after","hasMultiSelection","select","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,YAAvB,QAA2C,oBAA3C;AACA,SAASC,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,SAAP,MAAsB,eAAtB;AACA,OAAOC,WAAP,MA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QGF,QARH,CAFD,EAYGV,KAZH,CADD;AAgBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeV,UAAU,CAAEkB,WAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport classNames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMultiSelection from './use-multi-selection';\nimport useTabNav from './use-tab-nav';\nimport useArrowNav from './use-arrow-nav';\nimport useSelectAll from './use-select-all';\nimport { store as blockEditorStore } from '../../store';\n\nexport function useWritingFlow() {\n\tconst [ before, ref, after ] = useTabNav();\n\tconst hasMultiSelection = useSelect(\n\t\t( select ) => select( blockEditorStore ).hasMultiSelection(),\n\t\t[]\n\t);\n\n\treturn [\n\t\tbefore,\n\t\tuseMergeRefs( [\n\t\t\tref,\n\t\t\tuseMultiSelection(),\n\t\t\tuseSelectAll(),\n\t\t\tuseArrowNav(),\n\t\t\tuseRefEffect(\n\t\t\t\t( node ) => {\n\t\t\t\t\tnode.tabIndex = -1;\n\t\t\t\t\tnode.contentEditable = hasMultiSelection;\n\n\t\t\t\t\tif ( ! hasMultiSelection ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tnode.setAttribute(\n\t\t\t\t\t\t'aria-label',\n\t\t\t\t\t\t__( 'Multiple selected blocks' )\n\t\t\t\t\t);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tnode.removeAttribute( 'aria-label' );\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ hasMultiSelection ]\n\t\t\t),\n\t\t] ),\n\t\tafter,\n\t];\n}\n\nfunction WritingFlow( { children, ...props }, forwardedRef ) {\n\tconst [ before, ref, after ] = useWritingFlow();\n\treturn (\n\t\t<>\n\t\t\t{ before }\n\t\t\t<div\n\t\t\t\t{ ...props }\n\t\t\t\tref={ useMergeRefs( [ ref, forwardedRef ] ) }\n\t\t\t\tclassName={ classNames(\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'block-editor-writing-flow'\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t\t{ after }\n\t\t</>\n\t);\n}\n\n/**\n * Handles selection and navigation across blocks. This component should be\n * wrapped around BlockList.\n *\n * @param {Object} props Component properties.\n * @param {WPElement} props.children Children to be rendered.\n */\nexport default forwardRef( WritingFlow );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["classNames","useSelect","__","useMergeRefs","useRefEffect","forwardRef","useMultiSelection","useTabNav","useArrowNav","useSelectAll","useDragSelection","useSelectionObserver","useClickSelection","useInput","store","blockEditorStore","useWritingFlow","before","ref","after","hasMultiSelection","select","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,YAAvB,QAA2C,oBAA3C;AACA,SAASC,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,SAAP,MAAsB,eAAtB;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;AACA,OAAOC,oBAAP,MAAiC,0BAAjC;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,QAAP,MAAqB,aAArB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,OAAO,SAASC,cAAT,GAA0B;AAChC,QAAM,CAAEC,MAAF,EAAUC,GAAV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ACA,eAAed,UAAU,CAAEsB,WAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport classNames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMultiSelection from './use-multi-selection';\nimport useTabNav from './use-tab-nav';\nimport useArrowNav from './use-arrow-nav';\nimport useSelectAll from './use-select-all';\nimport useDragSelection from './use-drag-selection';\nimport useSelectionObserver from './use-selection-observer';\nimport useClickSelection from './use-click-selection';\nimport useInput from './use-input';\nimport { store as blockEditorStore } from '../../store';\n\nexport function useWritingFlow() {\n\tconst [ before, ref, after ] = useTabNav();\n\tconst hasMultiSelection = useSelect(\n\t\t( select ) => select( blockEditorStore ).hasMultiSelection(),\n\t\t[]\n\t);\n\n\treturn [\n\t\tbefore,\n\t\tuseMergeRefs( [\n\t\t\tref,\n\t\t\tuseInput(),\n\t\t\tuseDragSelection(),\n\t\t\tuseSelectionObserver(),\n\t\t\tuseClickSelection(),\n\t\t\tuseMultiSelection(),\n\t\t\tuseSelectAll(),\n\t\t\tuseArrowNav(),\n\t\t\tuseRefEffect(\n\t\t\t\t( node ) => {\n\t\t\t\t\tnode.tabIndex = -1;\n\t\t\t\t\tnode.contentEditable = hasMultiSelection;\n\n\t\t\t\t\tif ( ! hasMultiSelection ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tnode.setAttribute(\n\t\t\t\t\t\t'aria-label',\n\t\t\t\t\t\t__( 'Multiple selected blocks' )\n\t\t\t\t\t);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tnode.removeAttribute( 'aria-label' );\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ hasMultiSelection ]\n\t\t\t),\n\t\t] ),\n\t\tafter,\n\t];\n}\n\nfunction WritingFlow( { children, ...props }, forwardedRef ) {\n\tconst [ before, ref, after ] = useWritingFlow();\n\treturn (\n\t\t<>\n\t\t\t{ before }\n\t\t\t<div\n\t\t\t\t{ ...props }\n\t\t\t\tref={ useMergeRefs( [ ref, forwardedRef ] ) }\n\t\t\t\tclassName={ classNames(\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'block-editor-writing-flow'\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t\t{ after }\n\t\t</>\n\t);\n}\n\n/**\n * Handles selection and navigation across blocks. This component should be\n * wrapped around BlockList.\n *\n * @param {Object} props Component properties.\n * @param {WPElement} props.children Children to be rendered.\n */\nexport default forwardRef( WritingFlow );\n"]}
@@ -8,7 +8,7 @@ import { find, reverse } from 'lodash';
8
8
 
9
9
  import { computeCaretRect, focus, isHorizontalEdge, isVerticalEdge, placeCaretAtHorizontalEdge, placeCaretAtVerticalEdge, isRTL } from '@wordpress/dom';
10
10
  import { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';
11
- import { useSelect, useDispatch } from '@wordpress/data';
11
+ import { useSelect } from '@wordpress/data';
12
12
  import { useRefEffect } from '@wordpress/compose';
13
13
  /**
14
14
  * Internal dependencies
@@ -101,19 +101,12 @@ export function getClosestTabbable(target, isReverse, containerElement, onlyVert
101
101
  export default function useArrowNav() {
102
102
  const {
103
103
  getSelectedBlockClientId,
104
- getMultiSelectedBlocksStartClientId,
105
104
  getMultiSelectedBlocksEndClientId,
106
105
  getPreviousBlockClientId,
107
106
  getNextBlockClientId,
108
- getFirstMultiSelectedBlockClientId,
109
- getLastMultiSelectedBlockClientId,
110
107
  getSettings,
111
108
  hasMultiSelection
112
109
  } = useSelect(blockEditorStore);
113
- const {
114
- multiSelect,
115
- selectBlock
116
- } = useDispatch(blockEditorStore);
117
110
  return useRefEffect(node => {
118
111
  // Here a DOMRect is stored while moving the caret vertically so
119
112
  // vertical position of the start position can be restored. This is to
@@ -123,33 +116,6 @@ export default function useArrowNav() {
123
116
  function onMouseDown() {
124
117
  verticalRect = null;
125
118
  }
126
-
127
- function expandSelection(isReverse) {
128
- const selectedBlockClientId = getSelectedBlockClientId();
129
- const selectionStartClientId = getMultiSelectedBlocksStartClientId();
130
- const selectionEndClientId = getMultiSelectedBlocksEndClientId();
131
- const selectionBeforeEndClientId = getPreviousBlockClientId(selectionEndClientId || selectedBlockClientId);
132
- const selectionAfterEndClientId = getNextBlockClientId(selectionEndClientId || selectedBlockClientId);
133
- const nextSelectionEndClientId = isReverse ? selectionBeforeEndClientId : selectionAfterEndClientId;
134
-
135
- if (nextSelectionEndClientId) {
136
- if (selectionStartClientId === nextSelectionEndClientId) {
137
- selectBlock(nextSelectionEndClientId);
138
- } else {
139
- multiSelect(selectionStartClientId || selectedBlockClientId, nextSelectionEndClientId);
140
- }
141
- }
142
- }
143
-
144
- function moveSelection(isReverse) {
145
- const selectedFirstClientId = getFirstMultiSelectedBlockClientId();
146
- const selectedLastClientId = getLastMultiSelectedBlockClientId();
147
- const focusedBlockClientId = isReverse ? selectedFirstClientId : selectedLastClientId;
148
-
149
- if (focusedBlockClientId) {
150
- selectBlock(focusedBlockClientId);
151
- }
152
- }
153
119
  /**
154
120
  * Returns true if the given target field is the last in its block which
155
121
  * can be considered for tab transition. For example, in a block with
@@ -192,12 +158,6 @@ export default function useArrowNav() {
192
158
  } = ownerDocument;
193
159
 
194
160
  if (hasMultiSelection()) {
195
- if (isNav) {
196
- const action = isShift ? expandSelection : moveSelection;
197
- action(isReverse);
198
- event.preventDefault();
199
- }
200
-
201
161
  return;
202
162
  } // When presing any key other than up or down, the initial vertical
203
163
  // position must ALWAYS be reset. The vertical position is saved so
@@ -245,10 +205,9 @@ export default function useArrowNav() {
245
205
 
246
206
  if ( // Ensure that there is a target block.
247
207
  (isReverse && selectionBeforeEndClientId || !isReverse && selectionAfterEndClientId) && isTabbableEdge(target, isReverse) && isNavEdge(target, isReverse)) {
248
- // Shift key is down, and there is multi selection or we're
249
- // at the end of the current block.
250
- expandSelection(isReverse);
251
- event.preventDefault();
208
+ node.contentEditable = true; // Firefox doesn't automatically move focus.
209
+
210
+ node.focus();
252
211
  }
253
212
  } else if (isVertical && isVerticalEdge(target, isReverse) && !keepCaretInsideBlock) {
254
213
  const closestTabbable = getClosestTabbable(target, isReverse, node, true);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["find","reverse","computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useSelect","useDispatch","useRefEffect","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getFirstMultiSelectedBlockClientId","getLastMultiSelectedBlockClientId","getSettings","hasMultiSelection","multiSelect","selectBlock","verticalRect","onMouseDown","expandSelection","selectedBlockClientId","selectionStartClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","nextSelectionEndClientId","moveSelection","selectedFirstClientId","selectedLastClientId","focusedBlockClientId","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","action","preventDefault","defaultPrevented","isReverseDir","keepCaretInsideBlock","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;;AACA,SACCC,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,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1F,gBAAgB,CAAEsB,MAAF,EAAUiE,YAAV,CAFhB,IAGA,CAAEC,oBAJI,EAKL;AACD,cAAMrB,eAAe,GAAG9C,kBAAkB,CACzCC,MADyC,EAEzCiE,YAFyC,EAGzCtD,IAHyC,CAA1C;AAKA/B,QAAAA,0BAA0B,CAAEiE,eAAF,EAAmB5C,SAAnB,CAA1B;AACA8C,QAAAA,KAAK,CAACgB,cAAN;AACA;AACD;;AAEDpD,IAAAA,IAAI,CAAC0D,gBAAL,CAAuB,WAAvB,EAAoCrC,WAApC;AACArB,IAAAA,IAAI,CAAC0D,gBAAL,CAAuB,SAAvB,EAAkCvB,SAAlC;AACA,WAAO,MAAM;AACZnC,MAAAA,IAAI,CAAC2D,mBAAL,CAA0B,WAA1B,EAAuCtC,WAAvC;AACArB,MAAAA,IAAI,CAAC2D,mBAAL,CAA0B,SAA1B,EAAqCxB,SAArC;AACA,KAHD;AAIA,GAnMkB,EAmMhB,EAnMgB,CAAnB;AAoMA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, reverse } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally.\n\tconst { tagName } = element;\n\treturn tagName !== 'INPUT' && tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes = reverse( focusableNodes );\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn find( focusableNodes, isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetFirstMultiSelectedBlockClientId,\n\t\tgetLastMultiSelectedBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\tfunction expandSelection( isReverse ) {\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst selectionStartClientId = getMultiSelectedBlocksStartClientId();\n\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t);\n\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t);\n\t\t\tconst nextSelectionEndClientId = isReverse\n\t\t\t\t? selectionBeforeEndClientId\n\t\t\t\t: selectionAfterEndClientId;\n\n\t\t\tif ( nextSelectionEndClientId ) {\n\t\t\t\tif ( selectionStartClientId === nextSelectionEndClientId ) {\n\t\t\t\t\tselectBlock( nextSelectionEndClientId );\n\t\t\t\t} else {\n\t\t\t\t\tmultiSelect(\n\t\t\t\t\t\tselectionStartClientId || selectedBlockClientId,\n\t\t\t\t\t\tnextSelectionEndClientId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction moveSelection( isReverse ) {\n\t\t\tconst selectedFirstClientId = getFirstMultiSelectedBlockClientId();\n\t\t\tconst selectedLastClientId = getLastMultiSelectedBlockClientId();\n\t\t\tconst focusedBlockClientId = isReverse\n\t\t\t\t? selectedFirstClientId\n\t\t\t\t: selectedLastClientId;\n\n\t\t\tif ( focusedBlockClientId ) {\n\t\t\t\tselectBlock( focusedBlockClientId );\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\tif ( isNav ) {\n\t\t\t\t\tconst action = isShift ? expandSelection : moveSelection;\n\t\t\t\t\taction( isReverse );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\t// Shift key is down, and there is multi selection or we're\n\t\t\t\t\t// at the end of the current block.\n\t\t\t\t\texpandSelection( isReverse );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["find","reverse","computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useSelect","useRefEffect","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getSettings","hasMultiSelection","verticalRect","onMouseDown","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","defaultPrevented","isReverseDir","keepCaretInsideBlock","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","preventDefault","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;;AACA,SACCC,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,0BALD,EAMCC,wBAND,EAOCC,KAPD,QAQO,gBARP;AASA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,IAAnB,EAAyBC,KAAzB,QAAsC,qBAAtC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,a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ACD;;AAED1C,IAAAA,IAAI,CAAC6C,gBAAL,CAAuB,WAAvB,EAAoC7B,WAApC;AACAhB,IAAAA,IAAI,CAAC6C,gBAAL,CAAuB,SAAvB,EAAkC1B,SAAlC;AACA,WAAO,MAAM;AACZnB,MAAAA,IAAI,CAAC8C,mBAAL,CAA0B,WAA1B,EAAuC9B,WAAvC;AACAhB,MAAAA,IAAI,CAAC8C,mBAAL,CAA0B,SAA1B,EAAqC3B,SAArC;AACA,KAHD;AAIA,GAtJkB,EAsJhB,EAtJgB,CAAnB;AAuJA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, reverse } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally.\n\tconst { tagName } = element;\n\treturn tagName !== 'INPUT' && tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes = reverse( focusableNodes );\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn find( focusableNodes, isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect, useDispatch } from '@wordpress/data';
5
+ import { useRefEffect } from '@wordpress/compose';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ import { store as blockEditorStore } from '../../store';
11
+ import { getBlockClientId } from '../../utils/dom';
12
+ export default function useClickSelection() {
13
+ const {
14
+ multiSelect,
15
+ selectBlock
16
+ } = useDispatch(blockEditorStore);
17
+ const {
18
+ isSelectionEnabled,
19
+ getBlockParents,
20
+ getBlockSelectionStart,
21
+ hasMultiSelection
22
+ } = useSelect(blockEditorStore);
23
+ return useRefEffect(node => {
24
+ function onMouseDown(event) {
25
+ // The main button.
26
+ // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
27
+ if (!isSelectionEnabled() || event.button !== 0) {
28
+ return;
29
+ }
30
+
31
+ const startClientId = getBlockSelectionStart();
32
+ const clickedClientId = getBlockClientId(event.target);
33
+
34
+ if (event.shiftKey) {
35
+ if (startClientId !== clickedClientId) {
36
+ node.contentEditable = true; // Firefox doesn't automatically move focus.
37
+
38
+ node.focus();
39
+ }
40
+ } else if (hasMultiSelection()) {
41
+ // Allow user to escape out of a multi-selection to a
42
+ // singular selection of a block via click. This is handled
43
+ // here since focus handling excludes blocks when there is
44
+ // multiselection, as focus can be incurred by starting a
45
+ // multiselection (focus moved to first block's multi-
46
+ // controls).
47
+ selectBlock(clickedClientId);
48
+ }
49
+ }
50
+
51
+ node.addEventListener('mousedown', onMouseDown);
52
+ return () => {
53
+ node.removeEventListener('mousedown', onMouseDown);
54
+ };
55
+ }, [multiSelect, selectBlock, isSelectionEnabled, getBlockParents, getBlockSelectionStart, hasMultiSelection]);
56
+ }
57
+ //# sourceMappingURL=use-click-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-click-selection.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","useClickSelection","multiSelect","selectBlock","isSelectionEnabled","getBlockParents","getBlockSelectionStart","hasMultiSelection","node","onMouseDown","event","button","startClientId","clickedClientId","target","shiftKey","contentEditable","focus","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SA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AA4CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId } from '../../utils/dom';\n\nexport default function useClickSelection() {\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\tconst {\n\t\tisSelectionEnabled,\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tfunction onMouseDown( event ) {\n\t\t\t\t// The main button.\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button\n\t\t\t\tif ( ! isSelectionEnabled() || event.button !== 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst startClientId = getBlockSelectionStart();\n\t\t\t\tconst clickedClientId = getBlockClientId( event.target );\n\n\t\t\t\tif ( event.shiftKey ) {\n\t\t\t\t\tif ( startClientId !== clickedClientId ) {\n\t\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\t\tnode.focus();\n\t\t\t\t\t}\n\t\t\t\t} else if ( hasMultiSelection() ) {\n\t\t\t\t\t// Allow user to escape out of a multi-selection to a\n\t\t\t\t\t// singular selection of a block via click. This is handled\n\t\t\t\t\t// here since focus handling excludes blocks when there is\n\t\t\t\t\t// multiselection, as focus can be incurred by starting a\n\t\t\t\t\t// multiselection (focus moved to first block's multi-\n\t\t\t\t\t// controls).\n\t\t\t\t\tselectBlock( clickedClientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tmultiSelect,\n\t\t\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tgetBlockParents,\n\t\t\tgetBlockSelectionStart,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"]}