@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
@@ -0,0 +1,124 @@
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
+ /**
12
+ * Sets the `contenteditable` wrapper element to `value`.
13
+ *
14
+ * @param {HTMLElement} node Block element.
15
+ * @param {boolean} value `contentEditable` value (true or false)
16
+ */
17
+
18
+ function setContentEditableWrapper(node, value) {
19
+ node.contentEditable = value; // Firefox doesn't automatically move focus.
20
+
21
+ if (value) node.focus();
22
+ }
23
+ /**
24
+ * Sets a multi-selection based on the native selection across blocks.
25
+ */
26
+
27
+
28
+ export default function useDragSelection() {
29
+ const {
30
+ startMultiSelect,
31
+ stopMultiSelect
32
+ } = useDispatch(blockEditorStore);
33
+ const {
34
+ isSelectionEnabled,
35
+ hasMultiSelection
36
+ } = useSelect(blockEditorStore);
37
+ return useRefEffect(node => {
38
+ const {
39
+ ownerDocument
40
+ } = node;
41
+ const {
42
+ defaultView
43
+ } = ownerDocument;
44
+ let anchorElement;
45
+ let rafId;
46
+
47
+ function onMouseUp() {
48
+ stopMultiSelect(); // Equivalent to attaching the listener once.
49
+
50
+ defaultView.removeEventListener('mouseup', onMouseUp); // The browser selection won't have updated yet at this point,
51
+ // so wait until the next animation frame to get the browser
52
+ // selection.
53
+
54
+ rafId = defaultView.requestAnimationFrame(() => {
55
+ if (hasMultiSelection()) {
56
+ return;
57
+ } // If the selection is complete (on mouse up), and no
58
+ // multiple blocks have been selected, set focus back to the
59
+ // anchor element. if the anchor element contains the
60
+ // selection. Additionally, the contentEditable wrapper can
61
+ // now be disabled again.
62
+
63
+
64
+ setContentEditableWrapper(node, false);
65
+ const selection = defaultView.getSelection();
66
+
67
+ if (selection.rangeCount) {
68
+ const {
69
+ commonAncestorContainer
70
+ } = selection.getRangeAt(0);
71
+
72
+ if (anchorElement.contains(commonAncestorContainer)) {
73
+ anchorElement.focus();
74
+ }
75
+ }
76
+ });
77
+ }
78
+
79
+ function onMouseLeave(_ref) {
80
+ let {
81
+ buttons,
82
+ target
83
+ } = _ref;
84
+
85
+ // The primary button must be pressed to initiate selection.
86
+ // See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
87
+ if (buttons !== 1) {
88
+ return;
89
+ } // Check the attribute, not the contentEditable attribute. All
90
+ // child elements of the content editable wrapper are editable
91
+ // and return true for this property. We only want to start
92
+ // multi selecting when the mouse leaves the wrapper.
93
+
94
+
95
+ if (!target.getAttribute('contenteditable')) {
96
+ return;
97
+ }
98
+
99
+ if (!isSelectionEnabled()) {
100
+ return;
101
+ }
102
+
103
+ anchorElement = ownerDocument.activeElement;
104
+ startMultiSelect(); // `onSelectionStart` is called after `mousedown` and
105
+ // `mouseleave` (from a block). The selection ends when
106
+ // `mouseup` happens anywhere in the window.
107
+
108
+ defaultView.addEventListener('mouseup', onMouseUp); // Allow cross contentEditable selection by temporarily making
109
+ // all content editable. We can't rely on using the store and
110
+ // React because re-rending happens too slowly. We need to be
111
+ // able to select across instances immediately.
112
+
113
+ setContentEditableWrapper(node, true);
114
+ }
115
+
116
+ node.addEventListener('mouseout', onMouseLeave);
117
+ return () => {
118
+ node.removeEventListener('mouseout', onMouseLeave);
119
+ defaultView.removeEventListener('mouseup', onMouseUp);
120
+ defaultView.cancelAnimationFrame(rafId);
121
+ };
122
+ }, [startMultiSelect, stopMultiSelect, isSelectionEnabled, hasMultiSelection]);
123
+ }
124
+ //# sourceMappingURL=use-drag-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-drag-selection.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","setContentEditableWrapper","node","value","contentEditable","focus","useDragSelection","startMultiSelect","stopMultiSelect","isSelectionEnabled","hasMultiSelection","ownerDocument","defaultView","anchorElement","rafId","onMouseUp","removeEventListener","requestAnimationFrame","selection","getSelection","rangeCount","commonAncestorContainer","getRangeAt","contains","onMouseLeave","buttons","target","getAttribute","activeElement","addEventListener","cancelAnimationFrame"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AAC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A0BA;;AAED,aAASmB,YAAT,OAA6C;AAAA,UAAtB;AAAEC,QAAAA,OAAF;AAAWC,QAAAA;AAAX,OAAsB;;AAC5C;AACA;AACA,UAAKD,OAAO,KAAK,CAAjB,EAAqB;AACpB;AACA,OAL2C,CAO5C;AACA;AACA;AACA;;;AACA,UAAK,CAAEC,MAAM,CAACC,YAAP,CAAqB,iBAArB,CAAP,EAAkD;AACjD;AACA;;AAED,UAAK,CAAElB,kBAAkB,EAAzB,EAA8B;AAC7B;AACA;;AAEDI,MAAAA,aAAa,GAAGF,aAAa,CAACiB,aAA9B;AACArB,MAAAA,gBAAgB,GApB4B,CAsB5C;AACA;AACA;;AACAK,MAAAA,WAAW,CAACiB,gBAAZ,CAA8B,SAA9B,EAAyCd,SAAzC,EAzB4C,CA2B5C;AACA;AACA;AACA;;AACAd,MAAAA,yBAAyB,CAAEC,IAAF,EAAQ,IAAR,CAAzB;AACA;;AAEDA,IAAAA,IAAI,CAAC2B,gBAAL,CAAuB,UAAvB,EAAmCL,YAAnC;AAEA,WAAO,MAAM;AACZtB,MAAAA,IAAI,CAACc,mBAAL,CAA0B,UAA1B,EAAsCQ,YAAtC;AACAZ,MAAAA,WAAW,CAACI,mBAAZ,CAAiC,SAAjC,EAA4CD,SAA5C;AACAH,MAAAA,WAAW,CAACkB,oBAAZ,CAAkChB,KAAlC;AACA,KAJD;AAKA,GApFiB,EAqFlB,CACCP,gBADD,EAECC,eAFD,EAGCC,kBAHD,EAICC,iBAJD,CArFkB,CAAnB;AA4FA","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';\n\n/**\n * Sets the `contenteditable` wrapper element to `value`.\n *\n * @param {HTMLElement} node Block element.\n * @param {boolean} value `contentEditable` value (true or false)\n */\nfunction setContentEditableWrapper( node, value ) {\n\tnode.contentEditable = value;\n\t// Firefox doesn't automatically move focus.\n\tif ( value ) node.focus();\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n */\nexport default function useDragSelection() {\n\tconst { startMultiSelect, stopMultiSelect } = useDispatch(\n\t\tblockEditorStore\n\t);\n\tconst { isSelectionEnabled, hasMultiSelection } = useSelect(\n\t\tblockEditorStore\n\t);\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tlet anchorElement;\n\t\t\tlet rafId;\n\n\t\t\tfunction onMouseUp() {\n\t\t\t\tstopMultiSelect();\n\t\t\t\t// Equivalent to attaching the listener once.\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onMouseUp );\n\t\t\t\t// The browser selection won't have updated yet at this point,\n\t\t\t\t// so wait until the next animation frame to get the browser\n\t\t\t\t// selection.\n\t\t\t\trafId = defaultView.requestAnimationFrame( () => {\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\t// If the selection is complete (on mouse up), and no\n\t\t\t\t\t// multiple blocks have been selected, set focus back to the\n\t\t\t\t\t// anchor element. if the anchor element contains the\n\t\t\t\t\t// selection. Additionally, the contentEditable wrapper can\n\t\t\t\t\t// now be disabled again.\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\n\t\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\t\tif ( selection.rangeCount ) {\n\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\tcommonAncestorContainer,\n\t\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tanchorElement.contains( commonAncestorContainer )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tanchorElement.focus();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfunction onMouseLeave( { buttons, target } ) {\n\t\t\t\t// The primary button must be pressed to initiate selection.\n\t\t\t\t// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\n\t\t\t\tif ( buttons !== 1 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Check the attribute, not the contentEditable attribute. All\n\t\t\t\t// child elements of the content editable wrapper are editable\n\t\t\t\t// and return true for this property. We only want to start\n\t\t\t\t// multi selecting when the mouse leaves the wrapper.\n\t\t\t\tif ( ! target.getAttribute( 'contenteditable' ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! isSelectionEnabled() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tanchorElement = ownerDocument.activeElement;\n\t\t\t\tstartMultiSelect();\n\n\t\t\t\t// `onSelectionStart` is called after `mousedown` and\n\t\t\t\t// `mouseleave` (from a block). The selection ends when\n\t\t\t\t// `mouseup` happens anywhere in the window.\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onMouseUp );\n\n\t\t\t\t// Allow cross contentEditable selection by temporarily making\n\t\t\t\t// all content editable. We can't rely on using the store and\n\t\t\t\t// React because re-rending happens too slowly. We need to be\n\t\t\t\t// able to select across instances immediately.\n\t\t\t\tsetContentEditableWrapper( node, true );\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mouseout', onMouseLeave );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mouseout', onMouseLeave );\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onMouseUp );\n\t\t\t\tdefaultView.cancelAnimationFrame( rafId );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tstartMultiSelect,\n\t\t\tstopMultiSelect,\n\t\t\tisSelectionEnabled,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"]}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect, useDispatch } from '@wordpress/data';
5
+ import { useRefEffect } from '@wordpress/compose';
6
+ import { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';
7
+ import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+
12
+ import { store as blockEditorStore } from '../../store';
13
+ /**
14
+ * Handles input for selections across blocks.
15
+ */
16
+
17
+ export default function useInput() {
18
+ const {
19
+ __unstableIsFullySelected,
20
+ getSelectedBlockClientIds,
21
+ __unstableIsSelectionMergeable,
22
+ hasMultiSelection
23
+ } = useSelect(blockEditorStore);
24
+ const {
25
+ replaceBlocks,
26
+ __unstableSplitSelection,
27
+ removeBlocks,
28
+ __unstableDeleteSelection,
29
+ __unstableExpandSelection
30
+ } = useDispatch(blockEditorStore);
31
+ return useRefEffect(node => {
32
+ function onKeyDown(event) {
33
+ if (event.defaultPrevented) {
34
+ return;
35
+ }
36
+
37
+ if (!hasMultiSelection()) {
38
+ return;
39
+ }
40
+
41
+ if (event.keyCode === ENTER) {
42
+ node.contentEditable = false;
43
+ event.preventDefault();
44
+
45
+ if (__unstableIsFullySelected()) {
46
+ replaceBlocks(getSelectedBlockClientIds(), createBlock(getDefaultBlockName()));
47
+ } else {
48
+ __unstableSplitSelection();
49
+ }
50
+ } else if (event.keyCode === BACKSPACE || event.keyCode === DELETE) {
51
+ node.contentEditable = false;
52
+ event.preventDefault();
53
+
54
+ if (__unstableIsFullySelected()) {
55
+ removeBlocks(getSelectedBlockClientIds());
56
+ } else if (__unstableIsSelectionMergeable()) {
57
+ __unstableDeleteSelection(event.keyCode === DELETE);
58
+ } else {
59
+ __unstableExpandSelection();
60
+ }
61
+ } else if ( // If key.length is longer than 1, it's a control key that doesn't
62
+ // input anything.
63
+ event.key.length === 1 && !(event.metaKey || event.ctrlKey)) {
64
+ node.contentEditable = false;
65
+
66
+ if (__unstableIsSelectionMergeable()) {
67
+ __unstableDeleteSelection(event.keyCode === DELETE);
68
+ } else {
69
+ event.preventDefault(); // Safari does not stop default behaviour with either
70
+ // event.preventDefault() or node.contentEditable = false, so
71
+ // remove the selection to stop browser manipulation.
72
+
73
+ node.ownerDocument.defaultView.getSelection().removeAllRanges();
74
+ }
75
+ }
76
+ }
77
+
78
+ function onCompositionStart(event) {
79
+ if (!hasMultiSelection()) {
80
+ return;
81
+ }
82
+
83
+ node.contentEditable = false;
84
+
85
+ if (__unstableIsSelectionMergeable()) {
86
+ __unstableDeleteSelection();
87
+ } else {
88
+ event.preventDefault(); // Safari does not stop default behaviour with either
89
+ // event.preventDefault() or node.contentEditable = false, so
90
+ // remove the selection to stop browser manipulation.
91
+
92
+ node.ownerDocument.defaultView.getSelection().removeAllRanges();
93
+ }
94
+ }
95
+
96
+ node.addEventListener('keydown', onKeyDown);
97
+ node.addEventListener('compositionstart', onCompositionStart);
98
+ return () => {
99
+ node.removeEventListener('keydown', onKeyDown);
100
+ node.removeEventListener('compositionstart', onCompositionStart);
101
+ };
102
+ }, []);
103
+ }
104
+ //# sourceMappingURL=use-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-input.js"],"names":["useSelect","useDispatch","useRefEffect","ENTER","BACKSPACE","DELETE","createBlock","getDefaultBlockName","store","blockEditorStore","useInput","__unstableIsFullySelected","getSelectedBlockClientIds","__unstableIsSelectionMergeable","hasMultiSelection","replaceBlocks","__unstableSplitSelection","removeBlocks","__unstableDeleteSelection","__unstableExpandSelection","node","onKeyDown","event","defaultPrevented","keyCode","contentEditable","preventDefault","key","length","metaKey","ctrlKey","ownerDocument","defaultView","getSelection","removeAllRanges","onCompositionStart","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,KAAT,EAAgBC,SAAhB,EAA2BC,MAA3B,QAAyC,qBAAzC;AACA,SAASC,WAAT,EAAsBC,mBAAtB,QAAiD,mBAAjD;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA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AyB;AACzB;AACD,OAbM,MAaA,KACN;AACA;AACAG,MAAAA,KAAK,CAACK,GAAN,CAAUC,MAAV,KAAqB,CAArB,IACA,EAAIN,KAAK,CAACO,OAAN,IAAiBP,KAAK,CAACQ,OAA3B,CAJM,EAKL;AACDV,QAAAA,IAAI,CAACK,eAAL,GAAuB,KAAvB;;AACA,YAAKZ,8BAA8B,EAAnC,EAAwC;AACvCK,UAAAA,yBAAyB,CAAEI,KAAK,CAACE,OAAN,KAAkBnB,MAApB,CAAzB;AACA,SAFD,MAEO;AACNiB,UAAAA,KAAK,CAACI,cAAN,GADM,CAEN;AACA;AACA;;AACAN,UAAAA,IAAI,CAACW,aAAL,CAAmBC,WAAnB,CACEC,YADF,GAEEC,eAFF;AAGA;AACD;AACD;;AAED,aAASC,kBAAT,CAA6Bb,KAA7B,EAAqC;AACpC,UAAK,CAAER,iBAAiB,EAAxB,EAA6B;AAC5B;AACA;;AAEDM,MAAAA,IAAI,CAACK,eAAL,GAAuB,KAAvB;;AAEA,UAAKZ,8BAA8B,EAAnC,EAAwC;AACvCK,QAAAA,yBAAyB;AACzB,OAFD,MAEO;AACNI,QAAAA,KAAK,CAACI,cAAN,GADM,CAEN;AACA;AACA;;AACAN,QAAAA,IAAI,CAACW,aAAL,CAAmBC,WAAnB,CAA+BC,YAA/B,GAA8CC,eAA9C;AACA;AACD;;AAEDd,IAAAA,IAAI,CAACgB,gBAAL,CAAuB,SAAvB,EAAkCf,SAAlC;AACAD,IAAAA,IAAI,CAACgB,gBAAL,CAAuB,kBAAvB,EAA2CD,kBAA3C;AACA,WAAO,MAAM;AACZf,MAAAA,IAAI,CAACiB,mBAAL,CAA0B,SAA1B,EAAqChB,SAArC;AACAD,MAAAA,IAAI,CAACiB,mBAAL,CAA0B,kBAA1B,EAA8CF,kBAA9C;AACA,KAHD;AAIA,GA/EkB,EA+EhB,EA/EgB,CAAnB;AAgFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Handles input for selections across blocks.\n */\nexport default function useInput() {\n\tconst {\n\t\t__unstableIsFullySelected,\n\t\tgetSelectedBlockClientIds,\n\t\t__unstableIsSelectionMergeable,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\treplaceBlocks,\n\t\t__unstableSplitSelection,\n\t\tremoveBlocks,\n\t\t__unstableDeleteSelection,\n\t\t__unstableExpandSelection,\n\t} = useDispatch( blockEditorStore );\n\n\treturn useRefEffect( ( node ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.keyCode === ENTER ) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( __unstableIsFullySelected() ) {\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\tgetSelectedBlockClientIds(),\n\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t__unstableSplitSelection();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tevent.keyCode === BACKSPACE ||\n\t\t\t\tevent.keyCode === DELETE\n\t\t\t) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( __unstableIsFullySelected() ) {\n\t\t\t\t\tremoveBlocks( getSelectedBlockClientIds() );\n\t\t\t\t} else if ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t\t__unstableDeleteSelection( event.keyCode === DELETE );\n\t\t\t\t} else {\n\t\t\t\t\t__unstableExpandSelection();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\t// If key.length is longer than 1, it's a control key that doesn't\n\t\t\t\t// input anything.\n\t\t\t\tevent.key.length === 1 &&\n\t\t\t\t! ( event.metaKey || event.ctrlKey )\n\t\t\t) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tif ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t\t__unstableDeleteSelection( event.keyCode === DELETE );\n\t\t\t\t} else {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t// Safari does not stop default behaviour with either\n\t\t\t\t\t// event.preventDefault() or node.contentEditable = false, so\n\t\t\t\t\t// remove the selection to stop browser manipulation.\n\t\t\t\t\tnode.ownerDocument.defaultView\n\t\t\t\t\t\t.getSelection()\n\t\t\t\t\t\t.removeAllRanges();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction onCompositionStart( event ) {\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tnode.contentEditable = false;\n\n\t\t\tif ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t__unstableDeleteSelection();\n\t\t\t} else {\n\t\t\t\tevent.preventDefault();\n\t\t\t\t// Safari does not stop default behaviour with either\n\t\t\t\t// event.preventDefault() or node.contentEditable = false, so\n\t\t\t\t// remove the selection to stop browser manipulation.\n\t\t\t\tnode.ownerDocument.defaultView.getSelection().removeAllRanges();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\tnode.addEventListener( 'compositionstart', onCompositionStart );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\tnode.removeEventListener( 'compositionstart', onCompositionStart );\n\t\t};\n\t}, [] );\n}\n"]}
@@ -14,28 +14,6 @@ import { useSelect } from '@wordpress/data';
14
14
 
15
15
  import { store as blockEditorStore } from '../../store';
16
16
  import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';
17
- /**
18
- * Returns for the deepest node at the start or end of a container node. Ignores
19
- * any text nodes that only contain HTML formatting whitespace.
20
- *
21
- * @param {Element} node Container to search.
22
- * @param {string} type 'start' or 'end'.
23
- */
24
-
25
- function getDeepestNode(node, type) {
26
- const child = type === 'start' ? 'firstChild' : 'lastChild';
27
- const sibling = type === 'start' ? 'nextSibling' : 'previousSibling';
28
-
29
- while (node[child]) {
30
- node = node[child];
31
-
32
- while (node.nodeType === node.TEXT_NODE && /^[ \t\n]*$/.test(node.data) && node[sibling]) {
33
- node = node[sibling];
34
- }
35
- }
36
-
37
- return node;
38
- }
39
17
 
40
18
  function selector(select) {
41
19
  const {
@@ -43,14 +21,16 @@ function selector(select) {
43
21
  getMultiSelectedBlockClientIds,
44
22
  hasMultiSelection,
45
23
  getSelectedBlockClientId,
46
- getSelectedBlocksInitialCaretPosition
24
+ getSelectedBlocksInitialCaretPosition,
25
+ __unstableIsFullySelected
47
26
  } = select(blockEditorStore);
48
27
  return {
49
28
  isMultiSelecting: isMultiSelecting(),
50
29
  multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),
51
30
  hasMultiSelection: hasMultiSelection(),
52
31
  selectedBlockClientId: getSelectedBlockClientId(),
53
- initialPosition: getSelectedBlocksInitialCaretPosition()
32
+ initialPosition: getSelectedBlocksInitialCaretPosition(),
33
+ isFullSelection: __unstableIsFullySelected()
54
34
  };
55
35
  }
56
36
 
@@ -60,7 +40,8 @@ export default function useMultiSelection() {
60
40
  isMultiSelecting,
61
41
  multiSelectedBlockClientIds,
62
42
  hasMultiSelection,
63
- selectedBlockClientId
43
+ selectedBlockClientId,
44
+ isFullSelection
64
45
  } = useSelect(selector, []);
65
46
  const selectedRef = useBlockRef(selectedBlockClientId); // These must be in the right DOM order.
66
47
 
@@ -113,11 +94,9 @@ export default function useMultiSelection() {
113
94
 
114
95
  if (length < 2) {
115
96
  return;
116
- } // The block refs might not be immediately available
117
- // when dragging blocks into another block.
118
-
97
+ }
119
98
 
120
- if (!startRef.current || !endRef.current) {
99
+ if (!isFullSelection) {
121
100
  return;
122
101
  } // Allow cross contentEditable selection by temporarily making
123
102
  // all content editable. We can't rely on using the store and
@@ -128,18 +107,20 @@ export default function useMultiSelection() {
128
107
  node.contentEditable = true; // For some browsers, like Safari, it is important that focus happens
129
108
  // BEFORE selection.
130
109
 
131
- node.focus();
110
+ node.focus(); // The block refs might not be immediately available
111
+ // when dragging blocks into another block.
112
+
113
+ if (!startRef.current || !endRef.current) {
114
+ return;
115
+ }
116
+
132
117
  const selection = defaultView.getSelection();
133
118
  const range = ownerDocument.createRange(); // These must be in the right DOM order.
134
- // The most stable way to select the whole block contents is to start
135
- // and end at the deepest points.
136
119
 
137
- const startNode = getDeepestNode(startRef.current, 'start');
138
- const endNode = getDeepestNode(endRef.current, 'end');
139
- range.setStartBefore(startNode);
140
- range.setEndAfter(endNode);
120
+ range.setStartBefore(startRef.current);
121
+ range.setEndAfter(endRef.current);
141
122
  selection.removeAllRanges();
142
123
  selection.addRange(range);
143
- }, [hasMultiSelection, isMultiSelecting, multiSelectedBlockClientIds, selectedBlockClientId, initialPosition]);
124
+ }, [hasMultiSelection, isMultiSelecting, multiSelectedBlockClientIds, selectedBlockClientId, initialPosition, isFullSelection]);
144
125
  }
145
126
  //# sourceMappingURL=use-multi-selection.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-multi-selection.js"],"names":["first","last","useRefEffect","useSelect","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","getDeepestNode","node","type","child","sibling","nodeType","TEXT_NODE","test","data","selector","select","isMultiSelecting","getMultiSelectedBlockClientIds","hasMultiSelection","getSelectedBlockClientId","getSelectedBlocksInitialCaretPosition","multiSelectedBlockClientIds","selectedBlockClientId","initialPosition","useMultiSelection","selectedRef","startRef","endRef","ownerDocument","defaultView","undefined","selection","getSelection","rangeCount","isCollapsed","blockNode","current","startContainer","endContainer","getRangeAt","contains","removeAllRanges","length","contentEditable","focus","range","createRange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,QAAV,CAAoBF,YAApB,CAFH,CADD,EAIE;AACDP,UAAAA,SAAS,CAACU,eAAV;AACA;AACD;;AAED;AACA;;AAED,UAAM;AAAEC,MAAAA;AAAF,QAAarB,2BAAnB;;AAEA,QAAKqB,MAAM,GAAG,CAAd,EAAkB;AACjB;AACA,KAzCU,CA2CX;AACA;;;AACA,QAAK,CAAEhB,QAAQ,CAACU,OAAX,IAAsB,CAAET,MAAM,CAACS,OAApC,EAA8C;AAC7C;AACA,KA/CU,CAiDX;AACA;AACA;AACA;;;AACA9B,IAAAA,IAAI,CAACqC,eAAL,GAAuB,IAAvB,CArDW,CAuDX;AACA;;AACArC,IAAAA,IAAI,CAACsC,KAAL;AAEA,UAAMb,SAAS,GAAGF,WAAW,CAACG,YAAZ,EAAlB;AACA,UAAMa,KAAK,GAAGjB,aAAa,CAACkB,WAAd,EAAd,CA5DW,CA8DX;AACA;AACA;;AACA,UAAMC,SAAS,GAAG1C,cAAc,CAAEqB,QAAQ,CAACU,OAAX,EAAoB,OAApB,CAAhC;AACA,UAAMY,OAAO,GAAG3C,cAAc,CAAEsB,MAAM,CAACS,OAAT,EAAkB,KAAlB,CAA9B;AAEAS,IAAAA,KAAK,CAACI,cAAN,CAAsBF,SAAtB;AACAF,IAAAA,KAAK,CAACK,WAAN,CAAmBF,OAAnB;AAEAjB,IAAAA,SAAS,CAACU,eAAV;AACAV,IAAAA,SAAS,CAACoB,QAAV,CAAoBN,KAApB;AACA,GA1EiB,EA2ElB,CACC3B,iBADD,EAECF,gBAFD,EAGCK,2BAHD,EAICC,qBAJD,EAKCC,eALD,CA3EkB,CAAnB;AAmFA","sourcesContent":["/**\n * External dependencies\n */\nimport { first, last } from 'lodash';\n\n/**\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';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\n/**\n * Returns for the deepest node at the start or end of a container node. Ignores\n * any text nodes that only contain HTML formatting whitespace.\n *\n * @param {Element} node Container to search.\n * @param {string} type 'start' or 'end'.\n */\nfunction getDeepestNode( node, type ) {\n\tconst child = type === 'start' ? 'firstChild' : 'lastChild';\n\tconst sibling = type === 'start' ? 'nextSibling' : 'previousSibling';\n\n\twhile ( node[ child ] ) {\n\t\tnode = node[ child ];\n\n\t\twhile (\n\t\t\tnode.nodeType === node.TEXT_NODE &&\n\t\t\t/^[ \\t\\n]*$/.test( node.data ) &&\n\t\t\tnode[ sibling ]\n\t\t) {\n\t\t\tnode = node[ sibling ];\n\t\t}\n\t}\n\n\treturn node;\n}\n\nfunction selector( select ) {\n\tconst {\n\t\tisMultiSelecting,\n\t\tgetMultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSelectedBlockClientId,\n\t\tgetSelectedBlocksInitialCaretPosition,\n\t} = select( blockEditorStore );\n\n\treturn {\n\t\tisMultiSelecting: isMultiSelecting(),\n\t\tmultiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),\n\t\thasMultiSelection: hasMultiSelection(),\n\t\tselectedBlockClientId: getSelectedBlockClientId(),\n\t\tinitialPosition: getSelectedBlocksInitialCaretPosition(),\n\t};\n}\n\nexport default function useMultiSelection() {\n\tconst {\n\t\tinitialPosition,\n\t\tisMultiSelecting,\n\t\tmultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tselectedBlockClientId,\n\t} = useSelect( selector, [] );\n\tconst selectedRef = useBlockRef( selectedBlockClientId );\n\t// These must be in the right DOM order.\n\tconst startRef = useBlockRef( first( multiSelectedBlockClientIds ) );\n\tconst endRef = useBlockRef( last( multiSelectedBlockClientIds ) );\n\n\t/**\n\t * When the component updates, and there is multi selection, we need to\n\t * select the entire block contents.\n\t */\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t// Allow initialPosition to bypass focus behavior. This is useful\n\t\t\t// for the list view or other areas where we don't want to transfer\n\t\t\t// focus to the editor canvas.\n\t\t\tif ( initialPosition === undefined || initialPosition === null ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! hasMultiSelection || isMultiSelecting ) {\n\t\t\t\tif ( ! selectedBlockClientId || isMultiSelecting ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\tif ( selection.rangeCount && ! selection.isCollapsed ) {\n\t\t\t\t\tconst blockNode = selectedRef.current;\n\t\t\t\t\tconst {\n\t\t\t\t\t\tstartContainer,\n\t\t\t\t\t\tendContainer,\n\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t!! blockNode &&\n\t\t\t\t\t\t( ! blockNode.contains( startContainer ) ||\n\t\t\t\t\t\t\t! blockNode.contains( endContainer ) )\n\t\t\t\t\t) {\n\t\t\t\t\t\tselection.removeAllRanges();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { length } = multiSelectedBlockClientIds;\n\n\t\t\tif ( length < 2 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// The block refs might not be immediately available\n\t\t\t// when dragging blocks into another block.\n\t\t\tif ( ! startRef.current || ! endRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Allow cross contentEditable selection by temporarily making\n\t\t\t// all content editable. We can't rely on using the store and\n\t\t\t// React because re-rending happens too slowly. We need to be\n\t\t\t// able to select across instances immediately.\n\t\t\tnode.contentEditable = true;\n\n\t\t\t// For some browsers, like Safari, it is important that focus happens\n\t\t\t// BEFORE selection.\n\t\t\tnode.focus();\n\n\t\t\tconst selection = defaultView.getSelection();\n\t\t\tconst range = ownerDocument.createRange();\n\n\t\t\t// These must be in the right DOM order.\n\t\t\t// The most stable way to select the whole block contents is to start\n\t\t\t// and end at the deepest points.\n\t\t\tconst startNode = getDeepestNode( startRef.current, 'start' );\n\t\t\tconst endNode = getDeepestNode( endRef.current, 'end' );\n\n\t\t\trange.setStartBefore( startNode );\n\t\t\trange.setEndAfter( endNode );\n\n\t\t\tselection.removeAllRanges();\n\t\t\tselection.addRange( range );\n\t\t},\n\t\t[\n\t\t\thasMultiSelection,\n\t\t\tisMultiSelecting,\n\t\t\tmultiSelectedBlockClientIds,\n\t\t\tselectedBlockClientId,\n\t\t\tinitialPosition,\n\t\t]\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-multi-selection.js"],"names":["first","last","useRefEffect","useSelect","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","selector","select","isMultiSelecting","getMultiSelectedBlockClientIds","hasMultiSelection","getSelectedBlockClientId","getSelectedBlocksInitialCaretPosition","__unstableIsFullySelected","multiSelectedBlockClientIds","selectedBlockClientId","initialPosition","isFullSelection","useMultiSelection","selectedRef","startRef","endRef","node","ownerDocument","defaultView","undefined","selection","getSelection","rangeCount","isCollapsed","blockNode","current","startContainer","endContainer","getRangeAt","contains","removeAllRanges","length","contentEditable","focus","range","createRange","setStartBefore","setEndAfter","addRange"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,IAAhB,QAA4B,QAA5B;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,8CAArD;;AAEA,SAASC,QAAT,CAAmBC,MAAnB,EAA4B;AAC3B,QAAM;AACLC,IAAAA,gBADK;AAELC,IAAAA,8BAFK;AAGLC,IAAAA,iBAHK;AAILC,IAAAA,wBAJK;AAKLC,IAAAA,qCALK;AAMLC,IAAAA;AANK,MAOFN,MAAM,CAAEJ,gBAAF,CAPV;AASA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GAAGX,WAAW,CAACY,OAA9B;AACA,cAAM;AACLC,UAAAA,cADK;AAELC,UAAAA;AAFK,YAGFP,SAAS,CAACQ,UAAV,CAAsB,CAAtB,CAHJ;;AAKA,YACC,CAAC,CAAEJ,SAAH,KACE,CAAEA,SAAS,CAACK,QAAV,CAAoBH,cAApB,CAAF,IACD,CAAEF,SAAS,CAACK,QAAV,CAAoBF,YAApB,CAFH,CADD,EAIE;AACDP,UAAAA,SAAS,CAACU,eAAV;AACA;AACD;;AAED;AACA;;AAED,UAAM;AAAEC,MAAAA;AAAF,QAAavB,2BAAnB;;AAEA,QAAKuB,MAAM,GAAG,CAAd,EAAkB;AACjB;AACA;;AAED,QAAK,CAAEpB,eAAP,EAAyB;AACxB;AACA,KA7CU,CA+CX;AACA;AACA;AACA;;;AACAK,IAAAA,IAAI,CAACgB,eAAL,GAAuB,IAAvB,CAnDW,CAqDX;AACA;;AACAhB,IAAAA,IAAI,CAACiB,KAAL,GAvDW,CAyDX;AACA;;AACA,QAAK,CAAEnB,QAAQ,CAACW,OAAX,IAAsB,CAAEV,MAAM,CAACU,OAApC,EAA8C;AAC7C;AACA;;AAED,UAAML,SAAS,GAAGF,WAAW,CAACG,YAAZ,EAAlB;AACA,UAAMa,KAAK,GAAGjB,aAAa,CAACkB,WAAd,EAAd,CAhEW,CAkEX;;AACAD,IAAAA,KAAK,CAACE,cAAN,CAAsBtB,QAAQ,CAACW,OAA/B;AACAS,IAAAA,KAAK,CAACG,WAAN,CAAmBtB,MAAM,CAACU,OAA1B;AAEAL,IAAAA,SAAS,CAACU,eAAV;AACAV,IAAAA,SAAS,CAACkB,QAAV,CAAoBJ,KAApB;AACA,GAzEiB,EA0ElB,CACC9B,iBADD,EAECF,gBAFD,EAGCM,2BAHD,EAICC,qBAJD,EAKCC,eALD,EAMCC,eAND,CA1EkB,CAAnB;AAmFA","sourcesContent":["/**\n * External dependencies\n */\nimport { first, last } from 'lodash';\n\n/**\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';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nfunction selector( select ) {\n\tconst {\n\t\tisMultiSelecting,\n\t\tgetMultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSelectedBlockClientId,\n\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t__unstableIsFullySelected,\n\t} = select( blockEditorStore );\n\n\treturn {\n\t\tisMultiSelecting: isMultiSelecting(),\n\t\tmultiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),\n\t\thasMultiSelection: hasMultiSelection(),\n\t\tselectedBlockClientId: getSelectedBlockClientId(),\n\t\tinitialPosition: getSelectedBlocksInitialCaretPosition(),\n\t\tisFullSelection: __unstableIsFullySelected(),\n\t};\n}\n\nexport default function useMultiSelection() {\n\tconst {\n\t\tinitialPosition,\n\t\tisMultiSelecting,\n\t\tmultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tselectedBlockClientId,\n\t\tisFullSelection,\n\t} = useSelect( selector, [] );\n\tconst selectedRef = useBlockRef( selectedBlockClientId );\n\t// These must be in the right DOM order.\n\tconst startRef = useBlockRef( first( multiSelectedBlockClientIds ) );\n\tconst endRef = useBlockRef( last( multiSelectedBlockClientIds ) );\n\n\t/**\n\t * When the component updates, and there is multi selection, we need to\n\t * select the entire block contents.\n\t */\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t// Allow initialPosition to bypass focus behavior. This is useful\n\t\t\t// for the list view or other areas where we don't want to transfer\n\t\t\t// focus to the editor canvas.\n\t\t\tif ( initialPosition === undefined || initialPosition === null ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! hasMultiSelection || isMultiSelecting ) {\n\t\t\t\tif ( ! selectedBlockClientId || isMultiSelecting ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\tif ( selection.rangeCount && ! selection.isCollapsed ) {\n\t\t\t\t\tconst blockNode = selectedRef.current;\n\t\t\t\t\tconst {\n\t\t\t\t\t\tstartContainer,\n\t\t\t\t\t\tendContainer,\n\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t!! blockNode &&\n\t\t\t\t\t\t( ! blockNode.contains( startContainer ) ||\n\t\t\t\t\t\t\t! blockNode.contains( endContainer ) )\n\t\t\t\t\t) {\n\t\t\t\t\t\tselection.removeAllRanges();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { length } = multiSelectedBlockClientIds;\n\n\t\t\tif ( length < 2 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isFullSelection ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Allow cross contentEditable selection by temporarily making\n\t\t\t// all content editable. We can't rely on using the store and\n\t\t\t// React because re-rending happens too slowly. We need to be\n\t\t\t// able to select across instances immediately.\n\t\t\tnode.contentEditable = true;\n\n\t\t\t// For some browsers, like Safari, it is important that focus happens\n\t\t\t// BEFORE selection.\n\t\t\tnode.focus();\n\n\t\t\t// The block refs might not be immediately available\n\t\t\t// when dragging blocks into another block.\n\t\t\tif ( ! startRef.current || ! endRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst selection = defaultView.getSelection();\n\t\t\tconst range = ownerDocument.createRange();\n\n\t\t\t// These must be in the right DOM order.\n\t\t\trange.setStartBefore( startRef.current );\n\t\t\trange.setEndAfter( endRef.current );\n\n\t\t\tselection.removeAllRanges();\n\t\t\tselection.addRange( range );\n\t\t},\n\t\t[\n\t\t\thasMultiSelection,\n\t\t\tisMultiSelecting,\n\t\t\tmultiSelectedBlockClientIds,\n\t\t\tselectedBlockClientId,\n\t\t\tinitialPosition,\n\t\t\tisFullSelection,\n\t\t]\n\t);\n}\n"]}
@@ -0,0 +1,150 @@
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
+ /**
13
+ * Extract the selection start node from the selection. When the anchor node is
14
+ * not a text node, the selection offset is the index of a child node.
15
+ *
16
+ * @param {Selection} selection The selection.
17
+ *
18
+ * @return {Element} The selection start node.
19
+ */
20
+
21
+ function extractSelectionStartNode(selection) {
22
+ const {
23
+ anchorNode,
24
+ anchorOffset
25
+ } = selection;
26
+
27
+ if (anchorNode.nodeType === anchorNode.TEXT_NODE) {
28
+ return anchorNode;
29
+ }
30
+
31
+ return anchorNode.childNodes[anchorOffset];
32
+ }
33
+ /**
34
+ * Extract the selection end node from the selection. When the focus node is not
35
+ * a text node, the selection offset is the index of a child node. The selection
36
+ * reaches up to but excluding that child node.
37
+ *
38
+ * @param {Selection} selection The selection.
39
+ *
40
+ * @return {Element} The selection start node.
41
+ */
42
+
43
+
44
+ function extractSelectionEndNode(selection) {
45
+ const {
46
+ focusNode,
47
+ focusOffset
48
+ } = selection;
49
+
50
+ if (focusNode.nodeType === focusNode.TEXT_NODE) {
51
+ return focusNode;
52
+ }
53
+
54
+ return focusNode.childNodes[focusOffset - 1];
55
+ }
56
+
57
+ function findDepth(a, b) {
58
+ let depth = 0;
59
+
60
+ while (a[depth] === b[depth]) {
61
+ depth++;
62
+ }
63
+
64
+ return depth;
65
+ }
66
+ /**
67
+ * Sets the `contenteditable` wrapper element to `value`.
68
+ *
69
+ * @param {HTMLElement} node Block element.
70
+ * @param {boolean} value `contentEditable` value (true or false)
71
+ */
72
+
73
+
74
+ function setContentEditableWrapper(node, value) {
75
+ node.contentEditable = value; // Firefox doesn't automatically move focus.
76
+
77
+ if (value) node.focus();
78
+ }
79
+ /**
80
+ * Sets a multi-selection based on the native selection across blocks.
81
+ */
82
+
83
+
84
+ export default function useSelectionObserver() {
85
+ const {
86
+ multiSelect,
87
+ selectBlock,
88
+ selectionChange
89
+ } = useDispatch(blockEditorStore);
90
+ const {
91
+ getBlockParents
92
+ } = useSelect(blockEditorStore);
93
+ return useRefEffect(node => {
94
+ const {
95
+ ownerDocument
96
+ } = node;
97
+ const {
98
+ defaultView
99
+ } = ownerDocument;
100
+
101
+ function onSelectionChange() {
102
+ const selection = defaultView.getSelection(); // If no selection is found, end multi selection and disable the
103
+ // contentEditable wrapper.
104
+
105
+ if (!selection.rangeCount || selection.isCollapsed) {
106
+ setContentEditableWrapper(node, false);
107
+ return;
108
+ }
109
+
110
+ const clientId = getBlockClientId(extractSelectionStartNode(selection));
111
+ const endClientId = getBlockClientId(extractSelectionEndNode(selection));
112
+ const isSingularSelection = clientId === endClientId;
113
+
114
+ if (isSingularSelection) {
115
+ selectBlock(clientId);
116
+ } else {
117
+ const startPath = [...getBlockParents(clientId), clientId];
118
+ const endPath = [...getBlockParents(endClientId), endClientId];
119
+ const depth = findDepth(startPath, endPath);
120
+ multiSelect(startPath[depth], endPath[depth]);
121
+ }
122
+ }
123
+
124
+ function addListeners() {
125
+ ownerDocument.addEventListener('selectionchange', onSelectionChange);
126
+ defaultView.addEventListener('mouseup', onSelectionChange);
127
+ }
128
+
129
+ function removeListeners() {
130
+ ownerDocument.removeEventListener('selectionchange', onSelectionChange);
131
+ defaultView.removeEventListener('mouseup', onSelectionChange);
132
+ }
133
+
134
+ function resetListeners() {
135
+ removeListeners();
136
+ addListeners();
137
+ }
138
+
139
+ addListeners(); // We must allow rich text to set selection first. This ensures that
140
+ // our `selectionchange` listener is always reset to be called after
141
+ // the rich text one.
142
+
143
+ node.addEventListener('focusin', resetListeners);
144
+ return () => {
145
+ removeListeners();
146
+ node.removeEventListener('focusin', resetListeners);
147
+ };
148
+ }, [multiSelect, selectBlock, selectionChange, getBlockParents]);
149
+ }
150
+ //# sourceMappingURL=use-selection-observer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-selection-observer.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","focus","useSelectionObserver","multiSelect","selectBlock","selectionChange","getBlockParents","ownerDocument","defaultView","onSelectionChange","getSelection","rangeCount","isCollapsed","clientId","endClientId","isSingularSelection","startPath","endPath","addListeners","addEventListener","removeListeners","removeEventListener","resetListeners"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,iBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAoCC,SAApC,EAAgD;AAC/C,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA+BF,SAArC;;AAEA,MAAKC,UAAU,CAACE,QAAX,KAAwBF,UAAU,CAACG,SAAxC,EAAoD;AACnD,WAAOH,UAAP;AACA;;AAED,SAAOA,UAAU,CAACI,UAAX,CAAuBH,YAAvB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,uBAAT,CAAkCN,SAAlC,EAA8C;AAC7C,QAAM;AAAEO,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6BR,SAAnC;;AAEA,MAAKO,SAAS,CAACJ,QAAV,KAAuBI,SAAS,CAACH,SAAtC,EAAkD;AACjD,WAAOG,SAAP;AACA;;AAED,SAAOA,SAAS,CA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ispatch } 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\n/**\n * Extract the selection start node from the selection. When the anchor node is\n * not a text node, the selection offset is the index of a child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionStartNode( selection ) {\n\tconst { anchorNode, anchorOffset } = selection;\n\n\tif ( anchorNode.nodeType === anchorNode.TEXT_NODE ) {\n\t\treturn anchorNode;\n\t}\n\n\treturn anchorNode.childNodes[ anchorOffset ];\n}\n\n/**\n * Extract the selection end node from the selection. When the focus node is not\n * a text node, the selection offset is the index of a child node. The selection\n * reaches up to but excluding that child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionEndNode( selection ) {\n\tconst { focusNode, focusOffset } = selection;\n\n\tif ( focusNode.nodeType === focusNode.TEXT_NODE ) {\n\t\treturn focusNode;\n\t}\n\n\treturn focusNode.childNodes[ focusOffset - 1 ];\n}\n\nfunction findDepth( a, b ) {\n\tlet depth = 0;\n\n\twhile ( a[ depth ] === b[ depth ] ) {\n\t\tdepth++;\n\t}\n\n\treturn depth;\n}\n\n/**\n * Sets the `contenteditable` wrapper element to `value`.\n *\n * @param {HTMLElement} node Block element.\n * @param {boolean} value `contentEditable` value (true or false)\n */\nfunction setContentEditableWrapper( node, value ) {\n\tnode.contentEditable = value;\n\t// Firefox doesn't automatically move focus.\n\tif ( value ) node.focus();\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n */\nexport default function useSelectionObserver() {\n\tconst { multiSelect, selectBlock, selectionChange } = useDispatch(\n\t\tblockEditorStore\n\t);\n\tconst { getBlockParents } = useSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tfunction onSelectionChange() {\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\t// If no selection is found, end multi selection and disable the\n\t\t\t\t// contentEditable wrapper.\n\t\t\t\tif ( ! selection.rangeCount || selection.isCollapsed ) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst clientId = getBlockClientId(\n\t\t\t\t\textractSelectionStartNode( selection )\n\t\t\t\t);\n\t\t\t\tconst endClientId = getBlockClientId(\n\t\t\t\t\textractSelectionEndNode( selection )\n\t\t\t\t);\n\t\t\t\tconst isSingularSelection = clientId === endClientId;\n\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t} else {\n\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t...getBlockParents( clientId ),\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t...getBlockParents( endClientId ),\n\t\t\t\t\t\tendClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst depth = findDepth( startPath, endPath );\n\n\t\t\t\t\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction addListeners() {\n\t\t\t\townerDocument.addEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionChange );\n\t\t\t}\n\n\t\t\tfunction removeListeners() {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionChange );\n\t\t\t}\n\n\t\t\tfunction resetListeners() {\n\t\t\t\tremoveListeners();\n\t\t\t\taddListeners();\n\t\t\t}\n\n\t\t\taddListeners();\n\t\t\t// We must allow rich text to set selection first. This ensures that\n\t\t\t// our `selectionchange` listener is always reset to be called after\n\t\t\t// the rich text one.\n\t\t\tnode.addEventListener( 'focusin', resetListeners );\n\t\t\treturn () => {\n\t\t\t\tremoveListeners();\n\t\t\t\tnode.removeEventListener( 'focusin', resetListeners );\n\t\t\t};\n\t\t},\n\t\t[ multiSelect, selectBlock, selectionChange, getBlockParents ]\n\t);\n}\n"]}
@@ -3,7 +3,7 @@ import { createElement } from "@wordpress/element";
3
3
  /**
4
4
  * WordPress dependencies
5
5
  */
6
- import { focus } from '@wordpress/dom';
6
+ import { focus, isFormElement } from '@wordpress/dom';
7
7
  import { TAB, ESCAPE } from '@wordpress/keycodes';
8
8
  import { useSelect, useDispatch } from '@wordpress/data';
9
9
  import { useRefEffect, useMergeRefs } from '@wordpress/compose';
@@ -13,14 +13,6 @@ import { useRef } from '@wordpress/element';
13
13
  */
14
14
 
15
15
  import { store as blockEditorStore } from '../../store';
16
-
17
- function isFormElement(element) {
18
- const {
19
- tagName
20
- } = element;
21
- return tagName === 'INPUT' || tagName === 'BUTTON' || tagName === 'SELECT' || tagName === 'TEXTAREA';
22
- }
23
-
24
16
  export default function useTabNav() {
25
17
  const container = useRef();
26
18
  const focusCaptureBeforeRef = useRef();