@wordpress/block-editor 8.4.0 → 8.5.2

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 (421) 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-alignment-control/ui.js +1 -1
  8. package/build/components/block-alignment-control/ui.js.map +1 -1
  9. package/build/components/block-content-overlay/index.js +13 -4
  10. package/build/components/block-content-overlay/index.js.map +1 -1
  11. package/build/components/block-draggable/index.js +2 -3
  12. package/build/components/block-draggable/index.js.map +1 -1
  13. package/build/components/block-icon/index.js +4 -0
  14. package/build/components/block-icon/index.js.map +1 -1
  15. package/build/components/block-inspector/index.js +6 -1
  16. package/build/components/block-inspector/index.js.map +1 -1
  17. package/build/components/block-list/use-block-props/index.js +1 -6
  18. package/build/components/block-list/use-block-props/index.js.map +1 -1
  19. package/build/components/block-list/use-block-props/use-focus-first-element.js +14 -17
  20. package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
  21. package/build/components/block-list/use-block-props/use-focus-handler.js +7 -1
  22. package/build/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
  23. package/build/components/block-list-appender/index.js +6 -1
  24. package/build/components/block-list-appender/index.js.map +1 -1
  25. package/build/components/block-lock/index.js +8 -0
  26. package/build/components/block-lock/index.js.map +1 -1
  27. package/build/components/block-lock/menu-item.js +9 -15
  28. package/build/components/block-lock/menu-item.js.map +1 -1
  29. package/build/components/block-lock/modal.js +35 -23
  30. package/build/components/block-lock/modal.js.map +1 -1
  31. package/build/components/block-lock/toolbar.js +11 -16
  32. package/build/components/block-lock/toolbar.js.map +1 -1
  33. package/build/components/block-lock/use-block-lock.js +50 -0
  34. package/build/components/block-lock/use-block-lock.js.map +1 -0
  35. package/build/components/block-mover/index.js +4 -0
  36. package/build/components/block-mover/index.js.map +1 -1
  37. package/build/components/block-pattern-setup/index.js +37 -22
  38. package/build/components/block-pattern-setup/index.js.map +1 -1
  39. package/build/components/block-pattern-setup/setup-toolbar.js +1 -1
  40. package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
  41. package/build/components/block-preview/auto.js +6 -3
  42. package/build/components/block-preview/auto.js.map +1 -1
  43. package/build/components/block-preview/index.js +4 -2
  44. package/build/components/block-preview/index.js.map +1 -1
  45. package/build/components/block-settings-menu/block-settings-dropdown.js +50 -5
  46. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  47. package/build/components/block-switcher/index.js +8 -3
  48. package/build/components/block-switcher/index.js.map +1 -1
  49. package/build/components/block-title/index.js +2 -2
  50. package/build/components/block-title/index.js.map +1 -1
  51. package/build/components/block-title/use-block-display-title.js +1 -1
  52. package/build/components/block-title/use-block-display-title.js.map +1 -1
  53. package/build/components/block-toolbar/block-name-context.js +17 -0
  54. package/build/components/block-toolbar/block-name-context.js.map +1 -0
  55. package/build/components/block-toolbar/block-toolbar-last-item.js +20 -0
  56. package/build/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
  57. package/build/components/block-toolbar/index.js +20 -5
  58. package/build/components/block-toolbar/index.js.map +1 -1
  59. package/build/components/block-tools/index.js +0 -16
  60. package/build/components/block-tools/index.js.map +1 -1
  61. package/build/components/block-variation-transforms/index.js +92 -47
  62. package/build/components/block-variation-transforms/index.js.map +1 -1
  63. package/build/components/block-vertical-alignment-control/index.js +13 -6
  64. package/build/components/block-vertical-alignment-control/index.js.map +1 -1
  65. package/build/components/contrast-checker/index.js +4 -0
  66. package/build/components/contrast-checker/index.js.map +1 -1
  67. package/build/components/convert-to-group-buttons/index.js +8 -0
  68. package/build/components/convert-to-group-buttons/index.js.map +1 -1
  69. package/build/components/convert-to-group-buttons/toolbar.js +105 -0
  70. package/build/components/convert-to-group-buttons/toolbar.js.map +1 -0
  71. package/build/components/copy-handler/index.js +48 -9
  72. package/build/components/copy-handler/index.js.map +1 -1
  73. package/build/components/font-sizes/font-size-picker.js +4 -0
  74. package/build/components/font-sizes/font-size-picker.js.map +1 -1
  75. package/build/components/iframe/index.js +6 -9
  76. package/build/components/iframe/index.js.map +1 -1
  77. package/build/components/index.js +18 -0
  78. package/build/components/index.js.map +1 -1
  79. package/build/components/justify-content-control/index.js +13 -6
  80. package/build/components/justify-content-control/index.js.map +1 -1
  81. package/build/components/keyboard-shortcuts/index.js +1 -1
  82. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  83. package/build/components/line-height-control/index.js +10 -3
  84. package/build/components/line-height-control/index.js.map +1 -1
  85. package/build/components/link-control/index.js +6 -7
  86. package/build/components/link-control/index.js.map +1 -1
  87. package/build/components/list-view/block-select-button.js +19 -6
  88. package/build/components/list-view/block-select-button.js.map +1 -1
  89. package/build/components/list-view/block.js +18 -3
  90. package/build/components/list-view/block.js.map +1 -1
  91. package/build/components/list-view/branch.js +1 -1
  92. package/build/components/list-view/branch.js.map +1 -1
  93. package/build/components/media-replace-flow/index.js +4 -0
  94. package/build/components/media-replace-flow/index.js.map +1 -1
  95. package/build/components/multi-selection-inspector/index.js +1 -1
  96. package/build/components/multi-selection-inspector/index.js.map +1 -1
  97. package/build/components/rich-text/index.js +26 -4
  98. package/build/components/rich-text/index.js.map +1 -1
  99. package/build/components/rich-text/split-value.js +12 -2
  100. package/build/components/rich-text/split-value.js.map +1 -1
  101. package/build/components/rich-text/use-firefox-compat.js +49 -0
  102. package/build/components/rich-text/use-firefox-compat.js.map +1 -0
  103. package/build/components/rich-text/use-input-rules.js +34 -2
  104. package/build/components/rich-text/use-input-rules.js.map +1 -1
  105. package/build/components/skip-to-selected-block/index.js +4 -0
  106. package/build/components/skip-to-selected-block/index.js.map +1 -1
  107. package/build/components/writing-flow/index.js +9 -1
  108. package/build/components/writing-flow/index.js.map +1 -1
  109. package/build/components/writing-flow/use-arrow-nav.js +3 -44
  110. package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
  111. package/build/components/writing-flow/use-click-selection.js +68 -0
  112. package/build/components/writing-flow/use-click-selection.js.map +1 -0
  113. package/build/components/writing-flow/use-drag-selection.js +134 -0
  114. package/build/components/writing-flow/use-drag-selection.js.map +1 -0
  115. package/build/components/writing-flow/use-input.js +116 -0
  116. package/build/components/writing-flow/use-input.js.map +1 -0
  117. package/build/components/writing-flow/use-multi-selection.js +18 -38
  118. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  119. package/build/components/writing-flow/use-selection-observer.js +161 -0
  120. package/build/components/writing-flow/use-selection-observer.js.map +1 -0
  121. package/build/components/writing-flow/use-tab-nav.js +1 -8
  122. package/build/components/writing-flow/use-tab-nav.js.map +1 -1
  123. package/build/hooks/border-color.js +3 -3
  124. package/build/hooks/border-color.js.map +1 -1
  125. package/build/hooks/border.js +0 -14
  126. package/build/hooks/border.js.map +1 -1
  127. package/build/hooks/color.js +20 -17
  128. package/build/hooks/color.js.map +1 -1
  129. package/build/hooks/font-family.js +5 -1
  130. package/build/hooks/font-family.js.map +1 -1
  131. package/build/hooks/font-size.js +4 -2
  132. package/build/hooks/font-size.js.map +1 -1
  133. package/build/hooks/gap.js +23 -16
  134. package/build/hooks/gap.js.map +1 -1
  135. package/build/hooks/layout.js +7 -2
  136. package/build/hooks/layout.js.map +1 -1
  137. package/build/hooks/style.js +34 -3
  138. package/build/hooks/style.js.map +1 -1
  139. package/build/hooks/utils.js +29 -0
  140. package/build/hooks/utils.js.map +1 -1
  141. package/build/layouts/flex.js +76 -12
  142. package/build/layouts/flex.js.map +1 -1
  143. package/build/layouts/flow.js +9 -4
  144. package/build/layouts/flow.js.map +1 -1
  145. package/build/store/actions.js +290 -51
  146. package/build/store/actions.js.map +1 -1
  147. package/build/store/defaults.js +5 -2
  148. package/build/store/defaults.js.map +1 -1
  149. package/build/store/reducer.js +25 -13
  150. package/build/store/reducer.js.map +1 -1
  151. package/build/store/selectors.js +264 -21
  152. package/build/store/selectors.js.map +1 -1
  153. package/build/store/utils.js +27 -0
  154. package/build/store/utils.js.map +1 -0
  155. package/build/utils/dom.js +2 -1
  156. package/build/utils/dom.js.map +1 -1
  157. package/build-module/components/alignment-control/index.js +12 -4
  158. package/build-module/components/alignment-control/index.js.map +1 -1
  159. package/build-module/components/block-alignment-control/index.js +12 -4
  160. package/build-module/components/block-alignment-control/index.js.map +1 -1
  161. package/build-module/components/block-alignment-control/ui.js +2 -2
  162. package/build-module/components/block-alignment-control/ui.js.map +1 -1
  163. package/build-module/components/block-content-overlay/index.js +13 -4
  164. package/build-module/components/block-content-overlay/index.js.map +1 -1
  165. package/build-module/components/block-draggable/index.js +2 -3
  166. package/build-module/components/block-draggable/index.js.map +1 -1
  167. package/build-module/components/block-icon/index.js +4 -0
  168. package/build-module/components/block-icon/index.js.map +1 -1
  169. package/build-module/components/block-inspector/index.js +6 -1
  170. package/build-module/components/block-inspector/index.js.map +1 -1
  171. package/build-module/components/block-list/use-block-props/index.js +1 -4
  172. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  173. package/build-module/components/block-list/use-block-props/use-focus-first-element.js +15 -17
  174. package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
  175. package/build-module/components/block-list/use-block-props/use-focus-handler.js +7 -1
  176. package/build-module/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
  177. package/build-module/components/block-list-appender/index.js +6 -1
  178. package/build-module/components/block-list-appender/index.js.map +1 -1
  179. package/build-module/components/block-lock/index.js +1 -0
  180. package/build-module/components/block-lock/index.js.map +1 -1
  181. package/build-module/components/block-lock/menu-item.js +8 -13
  182. package/build-module/components/block-lock/menu-item.js.map +1 -1
  183. package/build-module/components/block-lock/modal.js +34 -24
  184. package/build-module/components/block-lock/modal.js.map +1 -1
  185. package/build-module/components/block-lock/toolbar.js +10 -14
  186. package/build-module/components/block-lock/toolbar.js.map +1 -1
  187. package/build-module/components/block-lock/use-block-lock.js +41 -0
  188. package/build-module/components/block-lock/use-block-lock.js.map +1 -0
  189. package/build-module/components/block-mover/index.js +4 -0
  190. package/build-module/components/block-mover/index.js.map +1 -1
  191. package/build-module/components/block-pattern-setup/index.js +39 -24
  192. package/build-module/components/block-pattern-setup/index.js.map +1 -1
  193. package/build-module/components/block-pattern-setup/setup-toolbar.js +1 -1
  194. package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
  195. package/build-module/components/block-preview/auto.js +6 -3
  196. package/build-module/components/block-preview/auto.js.map +1 -1
  197. package/build-module/components/block-preview/index.js +4 -2
  198. package/build-module/components/block-preview/index.js.map +1 -1
  199. package/build-module/components/block-settings-menu/block-settings-dropdown.js +50 -7
  200. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  201. package/build-module/components/block-switcher/index.js +9 -4
  202. package/build-module/components/block-switcher/index.js.map +1 -1
  203. package/build-module/components/block-title/index.js +2 -2
  204. package/build-module/components/block-title/index.js.map +1 -1
  205. package/build-module/components/block-title/use-block-display-title.js +1 -1
  206. package/build-module/components/block-title/use-block-display-title.js.map +1 -1
  207. package/build-module/components/block-toolbar/block-name-context.js +9 -0
  208. package/build-module/components/block-toolbar/block-name-context.js.map +1 -0
  209. package/build-module/components/block-toolbar/block-toolbar-last-item.js +11 -0
  210. package/build-module/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
  211. package/build-module/components/block-toolbar/index.js +16 -4
  212. package/build-module/components/block-toolbar/index.js.map +1 -1
  213. package/build-module/components/block-tools/index.js +0 -16
  214. package/build-module/components/block-tools/index.js.map +1 -1
  215. package/build-module/components/block-variation-transforms/index.js +95 -49
  216. package/build-module/components/block-variation-transforms/index.js.map +1 -1
  217. package/build-module/components/block-vertical-alignment-control/index.js +12 -4
  218. package/build-module/components/block-vertical-alignment-control/index.js.map +1 -1
  219. package/build-module/components/contrast-checker/index.js +4 -0
  220. package/build-module/components/contrast-checker/index.js.map +1 -1
  221. package/build-module/components/convert-to-group-buttons/index.js +2 -1
  222. package/build-module/components/convert-to-group-buttons/index.js.map +1 -1
  223. package/build-module/components/convert-to-group-buttons/toolbar.js +90 -0
  224. package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -0
  225. package/build-module/components/copy-handler/index.js +48 -9
  226. package/build-module/components/copy-handler/index.js.map +1 -1
  227. package/build-module/components/font-sizes/font-size-picker.js +4 -0
  228. package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
  229. package/build-module/components/iframe/index.js +6 -9
  230. package/build-module/components/iframe/index.js.map +1 -1
  231. package/build-module/components/index.js +2 -0
  232. package/build-module/components/index.js.map +1 -1
  233. package/build-module/components/justify-content-control/index.js +12 -4
  234. package/build-module/components/justify-content-control/index.js.map +1 -1
  235. package/build-module/components/keyboard-shortcuts/index.js +1 -1
  236. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  237. package/build-module/components/line-height-control/index.js +9 -2
  238. package/build-module/components/line-height-control/index.js.map +1 -1
  239. package/build-module/components/link-control/index.js +6 -7
  240. package/build-module/components/link-control/index.js.map +1 -1
  241. package/build-module/components/list-view/block-select-button.js +17 -6
  242. package/build-module/components/list-view/block-select-button.js.map +1 -1
  243. package/build-module/components/list-view/block.js +18 -3
  244. package/build-module/components/list-view/block.js.map +1 -1
  245. package/build-module/components/list-view/branch.js +1 -1
  246. package/build-module/components/list-view/branch.js.map +1 -1
  247. package/build-module/components/media-replace-flow/index.js +4 -0
  248. package/build-module/components/media-replace-flow/index.js.map +1 -1
  249. package/build-module/components/multi-selection-inspector/index.js +2 -2
  250. package/build-module/components/multi-selection-inspector/index.js.map +1 -1
  251. package/build-module/components/rich-text/index.js +25 -4
  252. package/build-module/components/rich-text/index.js.map +1 -1
  253. package/build-module/components/rich-text/split-value.js +12 -2
  254. package/build-module/components/rich-text/split-value.js.map +1 -1
  255. package/build-module/components/rich-text/use-firefox-compat.js +39 -0
  256. package/build-module/components/rich-text/use-firefox-compat.js.map +1 -0
  257. package/build-module/components/rich-text/use-input-rules.js +35 -4
  258. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  259. package/build-module/components/skip-to-selected-block/index.js +4 -0
  260. package/build-module/components/skip-to-selected-block/index.js.map +1 -1
  261. package/build-module/components/writing-flow/index.js +5 -1
  262. package/build-module/components/writing-flow/index.js.map +1 -1
  263. package/build-module/components/writing-flow/use-arrow-nav.js +4 -45
  264. package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
  265. package/build-module/components/writing-flow/use-click-selection.js +57 -0
  266. package/build-module/components/writing-flow/use-click-selection.js.map +1 -0
  267. package/build-module/components/writing-flow/use-drag-selection.js +124 -0
  268. package/build-module/components/writing-flow/use-drag-selection.js.map +1 -0
  269. package/build-module/components/writing-flow/use-input.js +104 -0
  270. package/build-module/components/writing-flow/use-input.js.map +1 -0
  271. package/build-module/components/writing-flow/use-multi-selection.js +18 -37
  272. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  273. package/build-module/components/writing-flow/use-selection-observer.js +150 -0
  274. package/build-module/components/writing-flow/use-selection-observer.js.map +1 -0
  275. package/build-module/components/writing-flow/use-tab-nav.js +1 -9
  276. package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
  277. package/build-module/hooks/border-color.js +5 -5
  278. package/build-module/hooks/border-color.js.map +1 -1
  279. package/build-module/hooks/border.js +0 -12
  280. package/build-module/hooks/border.js.map +1 -1
  281. package/build-module/hooks/color.js +19 -18
  282. package/build-module/hooks/color.js.map +1 -1
  283. package/build-module/hooks/font-family.js +3 -1
  284. package/build-module/hooks/font-family.js.map +1 -1
  285. package/build-module/hooks/font-size.js +4 -3
  286. package/build-module/hooks/font-size.js.map +1 -1
  287. package/build-module/hooks/gap.js +22 -15
  288. package/build-module/hooks/gap.js.map +1 -1
  289. package/build-module/hooks/layout.js +7 -2
  290. package/build-module/hooks/layout.js.map +1 -1
  291. package/build-module/hooks/style.js +33 -3
  292. package/build-module/hooks/style.js.map +1 -1
  293. package/build-module/hooks/utils.js +26 -0
  294. package/build-module/hooks/utils.js.map +1 -1
  295. package/build-module/layouts/flex.js +76 -13
  296. package/build-module/layouts/flex.js.map +1 -1
  297. package/build-module/layouts/flow.js +9 -5
  298. package/build-module/layouts/flow.js.map +1 -1
  299. package/build-module/store/actions.js +277 -49
  300. package/build-module/store/actions.js.map +1 -1
  301. package/build-module/store/defaults.js +5 -2
  302. package/build-module/store/defaults.js.map +1 -1
  303. package/build-module/store/reducer.js +25 -13
  304. package/build-module/store/reducer.js.map +1 -1
  305. package/build-module/store/selectors.js +250 -21
  306. package/build-module/store/selectors.js.map +1 -1
  307. package/build-module/store/utils.js +20 -0
  308. package/build-module/store/utils.js.map +1 -0
  309. package/build-module/utils/dom.js +2 -1
  310. package/build-module/utils/dom.js.map +1 -1
  311. package/build-style/style-rtl.css +142 -101
  312. package/build-style/style.css +142 -101
  313. package/build-types/utils/dom.d.ts.map +1 -1
  314. package/package.json +28 -28
  315. package/src/components/alignment-control/index.js +9 -4
  316. package/src/components/block-alignment-control/index.js +9 -4
  317. package/src/components/block-alignment-control/ui.js +2 -2
  318. package/src/components/block-content-overlay/index.js +19 -2
  319. package/src/components/block-draggable/index.js +2 -5
  320. package/src/components/block-icon/index.js +3 -0
  321. package/src/components/block-inspector/index.js +4 -0
  322. package/src/components/block-list/style.scss +4 -5
  323. package/src/components/block-list/use-block-props/index.js +0 -5
  324. package/src/components/block-list/use-block-props/use-focus-first-element.js +19 -26
  325. package/src/components/block-list/use-block-props/use-focus-handler.js +8 -0
  326. package/src/components/block-list-appender/index.js +5 -0
  327. package/src/components/block-lock/index.js +1 -0
  328. package/src/components/block-lock/menu-item.js +6 -19
  329. package/src/components/block-lock/modal.js +52 -23
  330. package/src/components/block-lock/style.scss +7 -5
  331. package/src/components/block-lock/toolbar.js +7 -14
  332. package/src/components/block-lock/use-block-lock.js +45 -0
  333. package/src/components/block-mover/index.js +3 -0
  334. package/src/components/block-mover/style.scss +4 -0
  335. package/src/components/block-pattern-setup/index.js +84 -59
  336. package/src/components/block-pattern-setup/setup-toolbar.js +3 -1
  337. package/src/components/block-pattern-setup/style.scss +32 -26
  338. package/src/components/block-preview/auto.js +10 -1
  339. package/src/components/block-preview/index.js +2 -0
  340. package/src/components/block-settings-menu/block-settings-dropdown.js +62 -4
  341. package/src/components/block-switcher/index.js +15 -3
  342. package/src/components/block-switcher/style.scss +15 -4
  343. package/src/components/block-switcher/test/__snapshots__/index.js.snap +15 -13
  344. package/src/components/block-switcher/test/index.js +2 -2
  345. package/src/components/block-title/index.js +2 -2
  346. package/src/components/block-title/use-block-display-title.js +1 -1
  347. package/src/components/block-toolbar/block-name-context.js +8 -0
  348. package/src/components/block-toolbar/block-toolbar-last-item.js +12 -0
  349. package/src/components/block-toolbar/index.js +18 -2
  350. package/src/components/block-toolbar/style.scss +6 -0
  351. package/src/components/block-tools/index.js +0 -19
  352. package/src/components/block-tools/style.scss +3 -5
  353. package/src/components/block-variation-transforms/index.js +105 -36
  354. package/src/components/block-variation-transforms/style.scss +1 -1
  355. package/src/components/block-vertical-alignment-control/index.js +9 -4
  356. package/src/components/button-block-appender/style.scss +5 -1
  357. package/src/components/contrast-checker/index.js +3 -0
  358. package/src/components/convert-to-group-buttons/index.js +6 -1
  359. package/src/components/convert-to-group-buttons/toolbar.js +87 -0
  360. package/src/components/copy-handler/index.js +55 -10
  361. package/src/components/font-sizes/font-size-picker.js +3 -0
  362. package/src/components/iframe/index.js +5 -7
  363. package/src/components/index.js +2 -0
  364. package/src/components/justify-content-control/index.js +9 -4
  365. package/src/components/keyboard-shortcuts/index.js +1 -1
  366. package/src/components/line-height-control/index.js +8 -3
  367. package/src/components/link-control/index.js +5 -5
  368. package/src/components/list-view/block-select-button.js +13 -3
  369. package/src/components/list-view/block.js +24 -8
  370. package/src/components/list-view/branch.js +1 -1
  371. package/src/components/list-view/style.scss +56 -14
  372. package/src/components/media-placeholder/README.md +8 -0
  373. package/src/components/media-replace-flow/index.js +3 -0
  374. package/src/components/multi-selection-inspector/index.js +2 -2
  375. package/src/components/rich-text/index.js +24 -1
  376. package/src/components/rich-text/split-value.js +5 -1
  377. package/src/components/rich-text/use-firefox-compat.js +39 -0
  378. package/src/components/rich-text/use-input-rules.js +40 -3
  379. package/src/components/skip-to-selected-block/index.js +3 -0
  380. package/src/components/url-input/style.scss +3 -2
  381. package/src/components/writing-flow/index.js +8 -0
  382. package/src/components/writing-flow/readme.md +28 -0
  383. package/src/components/writing-flow/use-arrow-nav.js +4 -53
  384. package/src/components/writing-flow/use-click-selection.js +65 -0
  385. package/src/components/writing-flow/use-drag-selection.js +126 -0
  386. package/src/components/writing-flow/use-input.js +112 -0
  387. package/src/components/writing-flow/use-multi-selection.js +13 -36
  388. package/src/components/writing-flow/use-selection-observer.js +153 -0
  389. package/src/components/writing-flow/use-tab-nav.js +1 -11
  390. package/src/hooks/border-color.js +5 -5
  391. package/src/hooks/border.js +0 -13
  392. package/src/hooks/color.js +51 -24
  393. package/src/hooks/font-family.js +5 -2
  394. package/src/hooks/font-size.js +10 -7
  395. package/src/hooks/gap.js +25 -17
  396. package/src/hooks/layout.js +11 -1
  397. package/src/hooks/style.js +40 -4
  398. package/src/hooks/test/gap.js +25 -1
  399. package/src/hooks/test/style.js +94 -0
  400. package/src/hooks/test/utils.js +1 -1
  401. package/src/hooks/utils.js +26 -0
  402. package/src/layouts/flex.js +89 -5
  403. package/src/layouts/flow.js +15 -4
  404. package/src/store/actions.js +341 -32
  405. package/src/store/defaults.js +7 -2
  406. package/src/store/reducer.js +25 -10
  407. package/src/store/selectors.js +329 -26
  408. package/src/store/test/selectors.js +242 -5
  409. package/src/store/utils.js +19 -0
  410. package/src/utils/dom.js +2 -1
  411. package/tsconfig.tsbuildinfo +1 -1
  412. package/build/components/block-list/use-block-props/use-multi-selection.js +0 -205
  413. package/build/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
  414. package/build/components/block-list/use-block-props/use-scroll-into-view.js +0 -77
  415. package/build/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
  416. package/build-module/components/block-list/use-block-props/use-multi-selection.js +0 -192
  417. package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
  418. package/build-module/components/block-list/use-block-props/use-scroll-into-view.js +0 -63
  419. package/build-module/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
  420. package/src/components/block-list/use-block-props/use-multi-selection.js +0 -227
  421. package/src/components/block-list/use-block-props/use-scroll-into-view.js +0 -73
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.useScrollIntoView = useScrollIntoView;
9
-
10
- var _domScrollIntoView = _interopRequireDefault(require("dom-scroll-into-view"));
11
-
12
- var _element = require("@wordpress/element");
13
-
14
- var _data = require("@wordpress/data");
15
-
16
- var _dom = require("@wordpress/dom");
17
-
18
- var _store = require("../../../store");
19
-
20
- /**
21
- * External dependencies
22
- */
23
-
24
- /**
25
- * WordPress dependencies
26
- */
27
-
28
- /**
29
- * WordPress dependencies
30
- */
31
-
32
- /**
33
- * Internal dependencies
34
- */
35
- function useScrollIntoView(clientId) {
36
- const ref = (0, _element.useRef)();
37
- const isSelectionEnd = (0, _data.useSelect)(select => {
38
- const {
39
- isBlockSelected,
40
- getBlockSelectionEnd
41
- } = select(_store.store);
42
- return isBlockSelected(clientId) || getBlockSelectionEnd() === clientId;
43
- }, [clientId]); // Note that we can't use `useRefEffect` here, since an element change does
44
- // not mean we can scroll. `isSelectionEnd` should be the sole dependency,
45
- // while with `useRefEffect`, the element is a dependency as well.
46
-
47
- (0, _element.useEffect)(() => {
48
- if (!isSelectionEnd) {
49
- return;
50
- }
51
-
52
- const extentNode = ref.current;
53
-
54
- if (!extentNode) {
55
- return;
56
- } // If the block is focused, the browser will already have scrolled into
57
- // view if necessary.
58
-
59
-
60
- if (extentNode.contains(extentNode.ownerDocument.activeElement)) {
61
- return;
62
- }
63
-
64
- const scrollContainer = (0, _dom.getScrollContainer)(extentNode) || extentNode.ownerDocument.defaultView; // If there's no scroll container, it follows that there's no scrollbar
65
- // and thus there's no need to try to scroll into view.
66
-
67
- if (!scrollContainer) {
68
- return;
69
- }
70
-
71
- (0, _domScrollIntoView.default)(extentNode, scrollContainer, {
72
- onlyScrollIfNeeded: true
73
- });
74
- }, [isSelectionEnd]);
75
- return ref;
76
- }
77
- //# sourceMappingURL=use-scroll-into-view.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js"],"names":["useScrollIntoView","clientId","ref","isSelectionEnd","select","isBlockSelected","getBlockSelectionEnd","blockEditorStore","extentNode","current","contains","ownerDocument","activeElement","scrollContainer","defaultView","onlyScrollIfNeeded"],"mappings":";;;;;;;;;AAGA;;AAQA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AACA;AACA;AACA;;AAKA;AACA;AACA;AAGO,SAASA,iBAAT,CAA4BC,QAA5B,EAAuC;AAC7C,QAAMC,GAAG,GAAG,sBAAZ;AACA,QAAMC,cAAc,GAAG,qBACpBC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAA4CF,MAAM,CACvDG,YADuD,CAAxD;AAIA,WACCF,eAAe,CAAEJ,QAAF,CAAf,IACAK,oBAAoB,OAAOL,QAF5B;AAIA,GAVqB,EAWtB,CAAEA,QAAF,CAXsB,CAAvB,CAF6C,CAgB7C;AACA;AACA;;AACA,0BAAW,MAAM;AAChB,QAAK,CAAEE,cAAP,EAAwB;AACvB;AACA;;AAED,UAAMK,UAAU,GAAGN,GAAG,CAACO,OAAvB;;AAEA,QAAK,CAAED,UAAP,EAAoB;AACnB;AACA,KATe,CAWhB;AACA;;;AACA,QAAKA,UAAU,CAACE,QAAX,CAAqBF,UAAU,CAACG,aAAX,CAAyBC,aAA9C,CAAL,EAAqE;AACpE;AACA;;AAED,UAAMC,eAAe,GACpB,6BAAoBL,UAApB,KACAA,UAAU,CAACG,aAAX,CAAyBG,WAF1B,CAjBgB,CAqBhB;AACA;;AACA,QAAK,CAAED,eAAP,EAAyB;AACxB;AACA;;AAED,oCAAgBL,UAAhB,EAA4BK,eAA5B,EAA6C;AAC5CE,MAAAA,kBAAkB,EAAE;AADwB,KAA7C;AAGA,GA9BD,EA8BG,CAAEZ,cAAF,CA9BH;AAgCA,SAAOD,GAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport scrollIntoView from 'dom-scroll-into-view';\n\n/**\n * WordPress dependencies\n */\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { getScrollContainer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\n\nexport function useScrollIntoView( clientId ) {\n\tconst ref = useRef();\n\tconst isSelectionEnd = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isBlockSelected, getBlockSelectionEnd } = select(\n\t\t\t\tblockEditorStore\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\tisBlockSelected( clientId ) ||\n\t\t\t\tgetBlockSelectionEnd() === clientId\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Note that we can't use `useRefEffect` here, since an element change does\n\t// not mean we can scroll. `isSelectionEnd` should be the sole dependency,\n\t// while with `useRefEffect`, the element is a dependency as well.\n\tuseEffect( () => {\n\t\tif ( ! isSelectionEnd ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst extentNode = ref.current;\n\n\t\tif ( ! extentNode ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the block is focused, the browser will already have scrolled into\n\t\t// view if necessary.\n\t\tif ( extentNode.contains( extentNode.ownerDocument.activeElement ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst scrollContainer =\n\t\t\tgetScrollContainer( extentNode ) ||\n\t\t\textentNode.ownerDocument.defaultView;\n\n\t\t// If there's no scroll container, it follows that there's no scrollbar\n\t\t// and thus there's no need to try to scroll into view.\n\t\tif ( ! scrollContainer ) {\n\t\t\treturn;\n\t\t}\n\n\t\tscrollIntoView( extentNode, scrollContainer, {\n\t\t\tonlyScrollIfNeeded: true,\n\t\t} );\n\t}, [ isSelectionEnd ] );\n\n\treturn ref;\n}\n"]}
@@ -1,192 +0,0 @@
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
- * Sets the `contenteditable` wrapper element to `value`.
14
- *
15
- * @param {HTMLElement} node Block element.
16
- * @param {boolean} value `contentEditable` value (true or false)
17
- */
18
-
19
- export function setContentEditableWrapper(node, value) {
20
- // Since `closest` considers `node` as a candidate, use `parentElement`.
21
- node.parentElement.closest('[contenteditable]').contentEditable = value;
22
- }
23
- /**
24
- * Sets a multi-selection based on the native selection across blocks.
25
- *
26
- * @param {string} clientId Block client ID.
27
- */
28
-
29
- export function useMultiSelection(clientId) {
30
- const {
31
- startMultiSelect,
32
- stopMultiSelect,
33
- multiSelect,
34
- selectBlock
35
- } = useDispatch(blockEditorStore);
36
- const {
37
- isSelectionEnabled,
38
- isBlockSelected,
39
- getBlockParents,
40
- getBlockSelectionStart,
41
- hasMultiSelection
42
- } = useSelect(blockEditorStore);
43
- return useRefEffect(node => {
44
- const {
45
- ownerDocument
46
- } = node;
47
- const {
48
- defaultView
49
- } = ownerDocument;
50
- let anchorElement;
51
- let rafId;
52
-
53
- function onSelectionChange(_ref) {
54
- let {
55
- isSelectionEnd
56
- } = _ref;
57
- const selection = defaultView.getSelection(); // If no selection is found, end multi selection and disable the
58
- // contentEditable wrapper.
59
-
60
- if (!selection.rangeCount || selection.isCollapsed) {
61
- setContentEditableWrapper(node, false);
62
- return;
63
- }
64
-
65
- const endClientId = getBlockClientId(selection.focusNode);
66
- const isSingularSelection = clientId === endClientId;
67
-
68
- if (isSingularSelection) {
69
- selectBlock(clientId); // If the selection is complete (on mouse up), and no
70
- // multiple blocks have been selected, set focus back to the
71
- // anchor element. if the anchor element contains the
72
- // selection. Additionally, the contentEditable wrapper can
73
- // now be disabled again.
74
-
75
- if (isSelectionEnd) {
76
- setContentEditableWrapper(node, false);
77
-
78
- if (selection.rangeCount) {
79
- const {
80
- commonAncestorContainer
81
- } = selection.getRangeAt(0);
82
-
83
- if (anchorElement.contains(commonAncestorContainer)) {
84
- anchorElement.focus();
85
- }
86
- }
87
- }
88
- } else {
89
- const startPath = [...getBlockParents(clientId), clientId];
90
- const endPath = [...getBlockParents(endClientId), endClientId];
91
- const depth = Math.min(startPath.length, endPath.length) - 1;
92
- multiSelect(startPath[depth], endPath[depth]);
93
- }
94
- }
95
-
96
- function onSelectionEnd() {
97
- ownerDocument.removeEventListener('selectionchange', onSelectionChange); // Equivalent to attaching the listener once.
98
-
99
- defaultView.removeEventListener('mouseup', onSelectionEnd); // The browser selection won't have updated yet at this point,
100
- // so wait until the next animation frame to get the browser
101
- // selection.
102
-
103
- rafId = defaultView.requestAnimationFrame(() => {
104
- onSelectionChange({
105
- isSelectionEnd: true
106
- });
107
- stopMultiSelect();
108
- });
109
- }
110
-
111
- function onMouseLeave(_ref2) {
112
- let {
113
- buttons
114
- } = _ref2;
115
-
116
- // The primary button must be pressed to initiate selection.
117
- // See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
118
- if (buttons !== 1) {
119
- return;
120
- }
121
-
122
- if (!isSelectionEnabled() || !isBlockSelected(clientId)) {
123
- return;
124
- }
125
-
126
- anchorElement = ownerDocument.activeElement;
127
- startMultiSelect(); // `onSelectionStart` is called after `mousedown` and
128
- // `mouseleave` (from a block). The selection ends when
129
- // `mouseup` happens anywhere in the window.
130
-
131
- ownerDocument.addEventListener('selectionchange', onSelectionChange);
132
- defaultView.addEventListener('mouseup', onSelectionEnd); // Allow cross contentEditable selection by temporarily making
133
- // all content editable. We can't rely on using the store and
134
- // React because re-rending happens too slowly. We need to be
135
- // able to select across instances immediately.
136
-
137
- setContentEditableWrapper(node, true);
138
- }
139
-
140
- function onMouseDown(event) {
141
- // The main button.
142
- // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
143
- if (!isSelectionEnabled() || event.button !== 0) {
144
- return;
145
- }
146
-
147
- if (event.shiftKey) {
148
- const blockSelectionStart = getBlockSelectionStart(); // By checking `blockSelectionStart` to be set, we handle the
149
- // case where we select a single block. We also have to check
150
- // the selectionEnd (clientId) not to be included in the
151
- // `blockSelectionStart`'s parents because the click event is
152
- // propagated.
153
-
154
- const startParents = getBlockParents(blockSelectionStart);
155
-
156
- if (blockSelectionStart && blockSelectionStart !== clientId && !(startParents !== null && startParents !== void 0 && startParents.includes(clientId))) {
157
- const startPath = [...startParents, blockSelectionStart];
158
- const endPath = [...getBlockParents(clientId), clientId];
159
- const depth = Math.min(startPath.length, endPath.length) - 1;
160
- const start = startPath[depth];
161
- const end = endPath[depth]; // Handle the case of having selected a parent block and
162
- // then shift+click on a child.
163
-
164
- if (start !== end) {
165
- setContentEditableWrapper(node, true);
166
- multiSelect(start, end);
167
- event.preventDefault();
168
- }
169
- }
170
- } else if (hasMultiSelection()) {
171
- // Allow user to escape out of a multi-selection to a
172
- // singular selection of a block via click. This is handled
173
- // here since focus handling excludes blocks when there is
174
- // multiselection, as focus can be incurred by starting a
175
- // multiselection (focus moved to first block's multi-
176
- // controls).
177
- selectBlock(clientId);
178
- }
179
- }
180
-
181
- node.addEventListener('mousedown', onMouseDown);
182
- node.addEventListener('mouseleave', onMouseLeave);
183
- return () => {
184
- node.removeEventListener('mousedown', onMouseDown);
185
- node.removeEventListener('mouseleave', onMouseLeave);
186
- ownerDocument.removeEventListener('selectionchange', onSelectionChange);
187
- defaultView.removeEventListener('mouseup', onSelectionEnd);
188
- defaultView.cancelAnimationFrame(rafId);
189
- };
190
- }, [clientId, startMultiSelect, stopMultiSelect, multiSelect, selectBlock, isSelectionEnabled, isBlockSelected, getBlockParents]);
191
- }
192
- //# sourceMappingURL=use-multi-selection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-block-props/use-multi-selection.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","setContentEditableWrapper","node","value","parentElement","closest","contentEditable","useMultiSelection","clientId","startMultiSelect","stopMultiSelect","multiSelect","selectBlock","isSelectionEnabled","isBlockSelected","getBlockParents","getBlockSelectionStart","hasMultiSelection","ownerDocument","defaultView","anchorElement","rafId","onSelectionChange","isSelectionEnd","selection","getSelection","rangeCount","isCollapsed","endClientId","focusNode","isSingularSelection","commonAncestorContainer","getRangeAt","contains","focus","startPath","endPath","depth","Math","min","length","onSelectionEnd","removeEventListener","requestAnimationFrame","onMouseLeave","buttons","activeElement","addEventListener","onMouseDown","event","button","shiftKey","blockSelectionStart","startParents","includes","start","end","preventDefault","cancelAnimationFrame"],"mappings":"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","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\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 */\nexport function setContentEditableWrapper( node, value ) {\n\t// Since `closest` considers `node` as a candidate, use `parentElement`.\n\tnode.parentElement.closest( '[contenteditable]' ).contentEditable = value;\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n *\n * @param {string} clientId Block client ID.\n */\nexport function useMultiSelection( clientId ) {\n\tconst {\n\t\tstartMultiSelect,\n\t\tstopMultiSelect,\n\t\tmultiSelect,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tisSelectionEnabled,\n\t\tisBlockSelected,\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\thasMultiSelection,\n\t} = 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\tlet anchorElement;\n\t\t\tlet rafId;\n\n\t\t\tfunction onSelectionChange( { isSelectionEnd } ) {\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 endClientId = getBlockClientId( selection.focusNode );\n\t\t\t\tconst isSingularSelection = clientId === endClientId;\n\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tselectBlock( clientId );\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\tif ( isSelectionEnd ) {\n\t\t\t\t\t\tsetContentEditableWrapper( node, false );\n\n\t\t\t\t\t\tif ( selection.rangeCount ) {\n\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\tcommonAncestorContainer,\n\t\t\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tanchorElement.contains(\n\t\t\t\t\t\t\t\t\tcommonAncestorContainer\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tanchorElement.focus();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\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 =\n\t\t\t\t\t\tMath.min( startPath.length, endPath.length ) - 1;\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 onSelectionEnd() {\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\t// Equivalent to attaching the listener once.\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionEnd );\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\tonSelectionChange( { isSelectionEnd: true } );\n\t\t\t\t\tstopMultiSelect();\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfunction onMouseLeave( { buttons } ) {\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\tif ( ! isSelectionEnabled() || ! isBlockSelected( clientId ) ) {\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\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', onSelectionEnd );\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\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\tif ( event.shiftKey ) {\n\t\t\t\t\tconst blockSelectionStart = getBlockSelectionStart();\n\t\t\t\t\t// By checking `blockSelectionStart` to be set, we handle the\n\t\t\t\t\t// case where we select a single block. We also have to check\n\t\t\t\t\t// the selectionEnd (clientId) not to be included in the\n\t\t\t\t\t// `blockSelectionStart`'s parents because the click event is\n\t\t\t\t\t// propagated.\n\t\t\t\t\tconst startParents = getBlockParents( blockSelectionStart );\n\t\t\t\t\tif (\n\t\t\t\t\t\tblockSelectionStart &&\n\t\t\t\t\t\tblockSelectionStart !== clientId &&\n\t\t\t\t\t\t! startParents?.includes( clientId )\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t\t...startParents,\n\t\t\t\t\t\t\tblockSelectionStart,\n\t\t\t\t\t\t];\n\t\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t\t...getBlockParents( clientId ),\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t];\n\t\t\t\t\t\tconst depth =\n\t\t\t\t\t\t\tMath.min( startPath.length, endPath.length ) - 1;\n\t\t\t\t\t\tconst start = startPath[ depth ];\n\t\t\t\t\t\tconst end = endPath[ depth ];\n\t\t\t\t\t\t// Handle the case of having selected a parent block and\n\t\t\t\t\t\t// then shift+click on a child.\n\t\t\t\t\t\tif ( start !== end ) {\n\t\t\t\t\t\t\tsetContentEditableWrapper( node, true );\n\t\t\t\t\t\t\tmultiSelect( start, end );\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\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( clientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.addEventListener( 'mouseleave', onMouseLeave );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\t\tnode.removeEventListener( 'mouseleave', onMouseLeave );\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', onSelectionEnd );\n\t\t\t\tdefaultView.cancelAnimationFrame( rafId );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclientId,\n\t\t\tstartMultiSelect,\n\t\t\tstopMultiSelect,\n\t\t\tmultiSelect,\n\t\t\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tisBlockSelected,\n\t\t\tgetBlockParents,\n\t\t]\n\t);\n}\n"]}
@@ -1,63 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import scrollIntoView from 'dom-scroll-into-view';
5
- /**
6
- * WordPress dependencies
7
- */
8
-
9
- /**
10
- * WordPress dependencies
11
- */
12
-
13
- import { useEffect, useRef } from '@wordpress/element';
14
- import { useSelect } from '@wordpress/data';
15
- import { getScrollContainer } from '@wordpress/dom';
16
- /**
17
- * Internal dependencies
18
- */
19
-
20
- import { store as blockEditorStore } from '../../../store';
21
- export function useScrollIntoView(clientId) {
22
- const ref = useRef();
23
- const isSelectionEnd = useSelect(select => {
24
- const {
25
- isBlockSelected,
26
- getBlockSelectionEnd
27
- } = select(blockEditorStore);
28
- return isBlockSelected(clientId) || getBlockSelectionEnd() === clientId;
29
- }, [clientId]); // Note that we can't use `useRefEffect` here, since an element change does
30
- // not mean we can scroll. `isSelectionEnd` should be the sole dependency,
31
- // while with `useRefEffect`, the element is a dependency as well.
32
-
33
- useEffect(() => {
34
- if (!isSelectionEnd) {
35
- return;
36
- }
37
-
38
- const extentNode = ref.current;
39
-
40
- if (!extentNode) {
41
- return;
42
- } // If the block is focused, the browser will already have scrolled into
43
- // view if necessary.
44
-
45
-
46
- if (extentNode.contains(extentNode.ownerDocument.activeElement)) {
47
- return;
48
- }
49
-
50
- const scrollContainer = getScrollContainer(extentNode) || extentNode.ownerDocument.defaultView; // If there's no scroll container, it follows that there's no scrollbar
51
- // and thus there's no need to try to scroll into view.
52
-
53
- if (!scrollContainer) {
54
- return;
55
- }
56
-
57
- scrollIntoView(extentNode, scrollContainer, {
58
- onlyScrollIfNeeded: true
59
- });
60
- }, [isSelectionEnd]);
61
- return ref;
62
- }
63
- //# sourceMappingURL=use-scroll-into-view.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js"],"names":["scrollIntoView","useEffect","useRef","useSelect","getScrollContainer","store","blockEditorStore","useScrollIntoView","clientId","ref","isSelectionEnd","select","isBlockSelected","getBlockSelectionEnd","extentNode","current","contains","ownerDocument","activeElement","scrollContainer","defaultView","onlyScrollIfNeeded"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,sBAA3B;AAEA;AACA;AACA;;AACA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,MAApB,QAAkC,oBAAlC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,kBAAT,QAAmC,gBAAnC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,gBAA1C;AAEA,OAAO,SAASC,iBAAT,CAA4BC,QAA5B,EAAuC;AAC7C,QAAMC,GAAG,GAAGP,MAAM,EAAlB;AACA,QAAMQ,cAAc,GAAGP,SAAS,CAC7BQ,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAA4CF,MAAM,CACvDL,gBADuD,CAAxD;AAIA,WACCM,eAAe,CAAEJ,QAAF,CAAf,IACAK,oBAAoB,OAAOL,QAF5B;AAIA,GAV8B,EAW/B,CAAEA,QAAF,CAX+B,CAAhC,CAF6C,CAgB7C;AACA;AACA;;AACAP,EAAAA,SAAS,CAAE,MAAM;AAChB,QAAK,CAAES,cAAP,EAAwB;AACvB;AACA;;AAED,UAAMI,UAAU,GAAGL,GAAG,CAACM,OAAvB;;AAEA,QAAK,CAAED,UAAP,EAAoB;AACnB;AACA,KATe,CAWhB;AACA;;;AACA,QAAKA,UAAU,CAACE,QAAX,CAAqBF,UAAU,CAACG,aAAX,CAAyBC,aAA9C,CAAL,EAAqE;AACpE;AACA;;AAED,UAAMC,eAAe,GACpBf,kBAAkB,CAAEU,UAAF,CAAlB,IACAA,UAAU,CAACG,aAAX,CAAyBG,WAF1B,CAjBgB,CAqBhB;AACA;;AACA,QAAK,CAAED,eAAP,EAAyB;AACxB;AACA;;AAEDnB,IAAAA,cAAc,CAAEc,UAAF,EAAcK,eAAd,EAA+B;AAC5CE,MAAAA,kBAAkB,EAAE;AADwB,KAA/B,CAAd;AAGA,GA9BQ,EA8BN,CAAEX,cAAF,CA9BM,CAAT;AAgCA,SAAOD,GAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport scrollIntoView from 'dom-scroll-into-view';\n\n/**\n * WordPress dependencies\n */\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { getScrollContainer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\n\nexport function useScrollIntoView( clientId ) {\n\tconst ref = useRef();\n\tconst isSelectionEnd = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isBlockSelected, getBlockSelectionEnd } = select(\n\t\t\t\tblockEditorStore\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\tisBlockSelected( clientId ) ||\n\t\t\t\tgetBlockSelectionEnd() === clientId\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Note that we can't use `useRefEffect` here, since an element change does\n\t// not mean we can scroll. `isSelectionEnd` should be the sole dependency,\n\t// while with `useRefEffect`, the element is a dependency as well.\n\tuseEffect( () => {\n\t\tif ( ! isSelectionEnd ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst extentNode = ref.current;\n\n\t\tif ( ! extentNode ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the block is focused, the browser will already have scrolled into\n\t\t// view if necessary.\n\t\tif ( extentNode.contains( extentNode.ownerDocument.activeElement ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst scrollContainer =\n\t\t\tgetScrollContainer( extentNode ) ||\n\t\t\textentNode.ownerDocument.defaultView;\n\n\t\t// If there's no scroll container, it follows that there's no scrollbar\n\t\t// and thus there's no need to try to scroll into view.\n\t\tif ( ! scrollContainer ) {\n\t\t\treturn;\n\t\t}\n\n\t\tscrollIntoView( extentNode, scrollContainer, {\n\t\t\tonlyScrollIfNeeded: true,\n\t\t} );\n\t}, [ isSelectionEnd ] );\n\n\treturn ref;\n}\n"]}
@@ -1,227 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useSelect, useDispatch } from '@wordpress/data';
5
- import { useRefEffect } from '@wordpress/compose';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import { store as blockEditorStore } from '../../../store';
11
- import { getBlockClientId } from '../../../utils/dom';
12
-
13
- /**
14
- * Sets the `contenteditable` wrapper element to `value`.
15
- *
16
- * @param {HTMLElement} node Block element.
17
- * @param {boolean} value `contentEditable` value (true or false)
18
- */
19
- export function setContentEditableWrapper( node, value ) {
20
- // Since `closest` considers `node` as a candidate, use `parentElement`.
21
- node.parentElement.closest( '[contenteditable]' ).contentEditable = value;
22
- }
23
-
24
- /**
25
- * Sets a multi-selection based on the native selection across blocks.
26
- *
27
- * @param {string} clientId Block client ID.
28
- */
29
- export function useMultiSelection( clientId ) {
30
- const {
31
- startMultiSelect,
32
- stopMultiSelect,
33
- multiSelect,
34
- selectBlock,
35
- } = useDispatch( blockEditorStore );
36
- const {
37
- isSelectionEnabled,
38
- isBlockSelected,
39
- getBlockParents,
40
- getBlockSelectionStart,
41
- hasMultiSelection,
42
- } = useSelect( blockEditorStore );
43
- return useRefEffect(
44
- ( node ) => {
45
- const { ownerDocument } = node;
46
- const { defaultView } = ownerDocument;
47
-
48
- let anchorElement;
49
- let rafId;
50
-
51
- function onSelectionChange( { isSelectionEnd } ) {
52
- const selection = defaultView.getSelection();
53
-
54
- // If no selection is found, end multi selection and disable the
55
- // contentEditable wrapper.
56
- if ( ! selection.rangeCount || selection.isCollapsed ) {
57
- setContentEditableWrapper( node, false );
58
- return;
59
- }
60
-
61
- const endClientId = getBlockClientId( selection.focusNode );
62
- const isSingularSelection = clientId === endClientId;
63
-
64
- if ( isSingularSelection ) {
65
- selectBlock( clientId );
66
-
67
- // If the selection is complete (on mouse up), and no
68
- // multiple blocks have been selected, set focus back to the
69
- // anchor element. if the anchor element contains the
70
- // selection. Additionally, the contentEditable wrapper can
71
- // now be disabled again.
72
- if ( isSelectionEnd ) {
73
- setContentEditableWrapper( node, false );
74
-
75
- if ( selection.rangeCount ) {
76
- const {
77
- commonAncestorContainer,
78
- } = selection.getRangeAt( 0 );
79
-
80
- if (
81
- anchorElement.contains(
82
- commonAncestorContainer
83
- )
84
- ) {
85
- anchorElement.focus();
86
- }
87
- }
88
- }
89
- } else {
90
- const startPath = [
91
- ...getBlockParents( clientId ),
92
- clientId,
93
- ];
94
- const endPath = [
95
- ...getBlockParents( endClientId ),
96
- endClientId,
97
- ];
98
- const depth =
99
- Math.min( startPath.length, endPath.length ) - 1;
100
-
101
- multiSelect( startPath[ depth ], endPath[ depth ] );
102
- }
103
- }
104
-
105
- function onSelectionEnd() {
106
- ownerDocument.removeEventListener(
107
- 'selectionchange',
108
- onSelectionChange
109
- );
110
- // Equivalent to attaching the listener once.
111
- defaultView.removeEventListener( 'mouseup', onSelectionEnd );
112
- // The browser selection won't have updated yet at this point,
113
- // so wait until the next animation frame to get the browser
114
- // selection.
115
- rafId = defaultView.requestAnimationFrame( () => {
116
- onSelectionChange( { isSelectionEnd: true } );
117
- stopMultiSelect();
118
- } );
119
- }
120
-
121
- function onMouseLeave( { buttons } ) {
122
- // The primary button must be pressed to initiate selection.
123
- // See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
124
- if ( buttons !== 1 ) {
125
- return;
126
- }
127
-
128
- if ( ! isSelectionEnabled() || ! isBlockSelected( clientId ) ) {
129
- return;
130
- }
131
-
132
- anchorElement = ownerDocument.activeElement;
133
- startMultiSelect();
134
-
135
- // `onSelectionStart` is called after `mousedown` and
136
- // `mouseleave` (from a block). The selection ends when
137
- // `mouseup` happens anywhere in the window.
138
- ownerDocument.addEventListener(
139
- 'selectionchange',
140
- onSelectionChange
141
- );
142
- defaultView.addEventListener( 'mouseup', onSelectionEnd );
143
-
144
- // Allow cross contentEditable selection by temporarily making
145
- // all content editable. We can't rely on using the store and
146
- // React because re-rending happens too slowly. We need to be
147
- // able to select across instances immediately.
148
- setContentEditableWrapper( node, true );
149
- }
150
-
151
- function onMouseDown( event ) {
152
- // The main button.
153
- // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
154
- if ( ! isSelectionEnabled() || event.button !== 0 ) {
155
- return;
156
- }
157
-
158
- if ( event.shiftKey ) {
159
- const blockSelectionStart = getBlockSelectionStart();
160
- // By checking `blockSelectionStart` to be set, we handle the
161
- // case where we select a single block. We also have to check
162
- // the selectionEnd (clientId) not to be included in the
163
- // `blockSelectionStart`'s parents because the click event is
164
- // propagated.
165
- const startParents = getBlockParents( blockSelectionStart );
166
- if (
167
- blockSelectionStart &&
168
- blockSelectionStart !== clientId &&
169
- ! startParents?.includes( clientId )
170
- ) {
171
- const startPath = [
172
- ...startParents,
173
- blockSelectionStart,
174
- ];
175
- const endPath = [
176
- ...getBlockParents( clientId ),
177
- clientId,
178
- ];
179
- const depth =
180
- Math.min( startPath.length, endPath.length ) - 1;
181
- const start = startPath[ depth ];
182
- const end = endPath[ depth ];
183
- // Handle the case of having selected a parent block and
184
- // then shift+click on a child.
185
- if ( start !== end ) {
186
- setContentEditableWrapper( node, true );
187
- multiSelect( start, end );
188
- event.preventDefault();
189
- }
190
- }
191
- } else if ( hasMultiSelection() ) {
192
- // Allow user to escape out of a multi-selection to a
193
- // singular selection of a block via click. This is handled
194
- // here since focus handling excludes blocks when there is
195
- // multiselection, as focus can be incurred by starting a
196
- // multiselection (focus moved to first block's multi-
197
- // controls).
198
- selectBlock( clientId );
199
- }
200
- }
201
-
202
- node.addEventListener( 'mousedown', onMouseDown );
203
- node.addEventListener( 'mouseleave', onMouseLeave );
204
-
205
- return () => {
206
- node.removeEventListener( 'mousedown', onMouseDown );
207
- node.removeEventListener( 'mouseleave', onMouseLeave );
208
- ownerDocument.removeEventListener(
209
- 'selectionchange',
210
- onSelectionChange
211
- );
212
- defaultView.removeEventListener( 'mouseup', onSelectionEnd );
213
- defaultView.cancelAnimationFrame( rafId );
214
- };
215
- },
216
- [
217
- clientId,
218
- startMultiSelect,
219
- stopMultiSelect,
220
- multiSelect,
221
- selectBlock,
222
- isSelectionEnabled,
223
- isBlockSelected,
224
- getBlockParents,
225
- ]
226
- );
227
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import scrollIntoView from 'dom-scroll-into-view';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- /**
10
- * WordPress dependencies
11
- */
12
- import { useEffect, useRef } from '@wordpress/element';
13
- import { useSelect } from '@wordpress/data';
14
- import { getScrollContainer } from '@wordpress/dom';
15
-
16
- /**
17
- * Internal dependencies
18
- */
19
- import { store as blockEditorStore } from '../../../store';
20
-
21
- export function useScrollIntoView( clientId ) {
22
- const ref = useRef();
23
- const isSelectionEnd = useSelect(
24
- ( select ) => {
25
- const { isBlockSelected, getBlockSelectionEnd } = select(
26
- blockEditorStore
27
- );
28
-
29
- return (
30
- isBlockSelected( clientId ) ||
31
- getBlockSelectionEnd() === clientId
32
- );
33
- },
34
- [ clientId ]
35
- );
36
-
37
- // Note that we can't use `useRefEffect` here, since an element change does
38
- // not mean we can scroll. `isSelectionEnd` should be the sole dependency,
39
- // while with `useRefEffect`, the element is a dependency as well.
40
- useEffect( () => {
41
- if ( ! isSelectionEnd ) {
42
- return;
43
- }
44
-
45
- const extentNode = ref.current;
46
-
47
- if ( ! extentNode ) {
48
- return;
49
- }
50
-
51
- // If the block is focused, the browser will already have scrolled into
52
- // view if necessary.
53
- if ( extentNode.contains( extentNode.ownerDocument.activeElement ) ) {
54
- return;
55
- }
56
-
57
- const scrollContainer =
58
- getScrollContainer( extentNode ) ||
59
- extentNode.ownerDocument.defaultView;
60
-
61
- // If there's no scroll container, it follows that there's no scrollbar
62
- // and thus there's no need to try to scroll into view.
63
- if ( ! scrollContainer ) {
64
- return;
65
- }
66
-
67
- scrollIntoView( extentNode, scrollContainer, {
68
- onlyScrollIfNeeded: true,
69
- } );
70
- }, [ isSelectionEnd ] );
71
-
72
- return ref;
73
- }