@wordpress/block-editor 8.3.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 (443) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +56 -18
  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/block-html.js +4 -1
  14. package/build/components/block-list/block-html.js.map +1 -1
  15. package/build/components/block-list/block.js +4 -1
  16. package/build/components/block-list/block.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 +22 -6
  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 +32 -0
  26. package/build/components/block-lock/index.js.map +1 -0
  27. package/build/components/block-lock/menu-item.js +67 -0
  28. package/build/components/block-lock/menu-item.js.map +1 -0
  29. package/build/components/block-lock/modal.js +134 -0
  30. package/build/components/block-lock/modal.js.map +1 -0
  31. package/build/components/block-lock/toolbar.js +78 -0
  32. package/build/components/block-lock/toolbar.js.map +1 -0
  33. package/build/components/block-mover/index.js +4 -0
  34. package/build/components/block-mover/index.js.map +1 -1
  35. package/build/components/block-settings-menu/block-settings-dropdown.js +75 -10
  36. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  37. package/build/components/block-settings-menu-controls/index.js +19 -9
  38. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  39. package/build/components/block-switcher/index.js +1 -1
  40. package/build/components/block-switcher/index.js.map +1 -1
  41. package/build/components/block-title/index.js +2 -2
  42. package/build/components/block-title/index.js.map +1 -1
  43. package/build/components/block-title/use-block-display-title.js +8 -6
  44. package/build/components/block-title/use-block-display-title.js.map +1 -1
  45. package/build/components/block-toolbar/block-name-context.js +17 -0
  46. package/build/components/block-toolbar/block-name-context.js.map +1 -0
  47. package/build/components/block-toolbar/block-toolbar-last-item.js +20 -0
  48. package/build/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
  49. package/build/components/block-toolbar/index.js +24 -5
  50. package/build/components/block-toolbar/index.js.map +1 -1
  51. package/build/components/block-tools/index.js +0 -16
  52. package/build/components/block-tools/index.js.map +1 -1
  53. package/build/components/block-variation-transforms/index.js +92 -47
  54. package/build/components/block-variation-transforms/index.js.map +1 -1
  55. package/build/components/block-vertical-alignment-control/index.js +13 -6
  56. package/build/components/block-vertical-alignment-control/index.js.map +1 -1
  57. package/build/components/border-radius-control/index.js +0 -1
  58. package/build/components/border-radius-control/index.js.map +1 -1
  59. package/build/components/border-radius-control/utils.js +1 -1
  60. package/build/components/border-radius-control/utils.js.map +1 -1
  61. package/build/components/colors-gradients/control.js +3 -1
  62. package/build/components/colors-gradients/control.js.map +1 -1
  63. package/build/components/contrast-checker/index.js +4 -0
  64. package/build/components/contrast-checker/index.js.map +1 -1
  65. package/build/components/convert-to-group-buttons/index.js +8 -0
  66. package/build/components/convert-to-group-buttons/index.js.map +1 -1
  67. package/build/components/convert-to-group-buttons/toolbar.js +105 -0
  68. package/build/components/convert-to-group-buttons/toolbar.js.map +1 -0
  69. package/build/components/copy-handler/index.js +4 -0
  70. package/build/components/copy-handler/index.js.map +1 -1
  71. package/build/components/date-format-picker/index.js +132 -0
  72. package/build/components/date-format-picker/index.js.map +1 -0
  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 +27 -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 +15 -6
  84. package/build/components/line-height-control/index.js.map +1 -1
  85. package/build/components/list-view/block-select-button.js +24 -23
  86. package/build/components/list-view/block-select-button.js.map +1 -1
  87. package/build/components/list-view/block.js +38 -13
  88. package/build/components/list-view/block.js.map +1 -1
  89. package/build/components/list-view/branch.js +16 -13
  90. package/build/components/list-view/branch.js.map +1 -1
  91. package/build/components/list-view/index.js +7 -1
  92. package/build/components/list-view/index.js.map +1 -1
  93. package/build/components/list-view/use-block-selection.js +9 -2
  94. package/build/components/list-view/use-block-selection.js.map +1 -1
  95. package/build/components/media-replace-flow/index.js +4 -0
  96. package/build/components/media-replace-flow/index.js.map +1 -1
  97. package/build/components/multi-selection-inspector/index.js +1 -1
  98. package/build/components/multi-selection-inspector/index.js.map +1 -1
  99. package/build/components/rich-text/index.js +27 -5
  100. package/build/components/rich-text/index.js.map +1 -1
  101. package/build/components/rich-text/index.native.js +13 -9
  102. package/build/components/rich-text/index.native.js.map +1 -1
  103. package/build/components/rich-text/split-value.js +12 -2
  104. package/build/components/rich-text/split-value.js.map +1 -1
  105. package/build/components/rich-text/use-firefox-compat.js +49 -0
  106. package/build/components/rich-text/use-firefox-compat.js.map +1 -0
  107. package/build/components/rich-text/use-input-rules.js +34 -2
  108. package/build/components/rich-text/use-input-rules.js.map +1 -1
  109. package/build/components/skip-to-selected-block/index.js +4 -0
  110. package/build/components/skip-to-selected-block/index.js.map +1 -1
  111. package/build/components/url-popover/image-url-input-ui.js +11 -27
  112. package/build/components/url-popover/image-url-input-ui.js.map +1 -1
  113. package/build/components/writing-flow/index.js +9 -1
  114. package/build/components/writing-flow/index.js.map +1 -1
  115. package/build/components/writing-flow/use-arrow-nav.js +3 -44
  116. package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
  117. package/build/components/writing-flow/use-click-selection.js +68 -0
  118. package/build/components/writing-flow/use-click-selection.js.map +1 -0
  119. package/build/components/writing-flow/use-drag-selection.js +134 -0
  120. package/build/components/writing-flow/use-drag-selection.js.map +1 -0
  121. package/build/components/writing-flow/use-input.js +116 -0
  122. package/build/components/writing-flow/use-input.js.map +1 -0
  123. package/build/components/writing-flow/use-multi-selection.js +18 -38
  124. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  125. package/build/components/writing-flow/use-selection-observer.js +161 -0
  126. package/build/components/writing-flow/use-selection-observer.js.map +1 -0
  127. package/build/components/writing-flow/use-tab-nav.js +1 -8
  128. package/build/components/writing-flow/use-tab-nav.js.map +1 -1
  129. package/build/hooks/anchor.js +7 -6
  130. package/build/hooks/anchor.js.map +1 -1
  131. package/build/hooks/border-color.js +3 -3
  132. package/build/hooks/border-color.js.map +1 -1
  133. package/build/hooks/border.js +0 -14
  134. package/build/hooks/border.js.map +1 -1
  135. package/build/hooks/color.js +20 -17
  136. package/build/hooks/color.js.map +1 -1
  137. package/build/hooks/font-family.js +5 -1
  138. package/build/hooks/font-family.js.map +1 -1
  139. package/build/hooks/font-size.js +4 -2
  140. package/build/hooks/font-size.js.map +1 -1
  141. package/build/hooks/gap.js +77 -5
  142. package/build/hooks/gap.js.map +1 -1
  143. package/build/hooks/layout.js +7 -2
  144. package/build/hooks/layout.js.map +1 -1
  145. package/build/hooks/style.js +34 -3
  146. package/build/hooks/style.js.map +1 -1
  147. package/build/hooks/utils.js +29 -0
  148. package/build/hooks/utils.js.map +1 -1
  149. package/build/layouts/flex.js +82 -15
  150. package/build/layouts/flex.js.map +1 -1
  151. package/build/layouts/flow.js +22 -13
  152. package/build/layouts/flow.js.map +1 -1
  153. package/build/store/actions.js +297 -51
  154. package/build/store/actions.js.map +1 -1
  155. package/build/store/defaults.js +5 -1
  156. package/build/store/defaults.js.map +1 -1
  157. package/build/store/reducer.js +25 -13
  158. package/build/store/reducer.js.map +1 -1
  159. package/build/store/selectors.js +171 -21
  160. package/build/store/selectors.js.map +1 -1
  161. package/build/utils/dom.js +2 -1
  162. package/build/utils/dom.js.map +1 -1
  163. package/build-module/components/alignment-control/index.js +12 -4
  164. package/build-module/components/alignment-control/index.js.map +1 -1
  165. package/build-module/components/block-alignment-control/index.js +12 -4
  166. package/build-module/components/block-alignment-control/index.js.map +1 -1
  167. package/build-module/components/block-draggable/index.js +2 -3
  168. package/build-module/components/block-draggable/index.js.map +1 -1
  169. package/build-module/components/block-icon/index.js +4 -0
  170. package/build-module/components/block-icon/index.js.map +1 -1
  171. package/build-module/components/block-inspector/index.js +6 -1
  172. package/build-module/components/block-inspector/index.js.map +1 -1
  173. package/build-module/components/block-list/block-html.js +5 -2
  174. package/build-module/components/block-list/block-html.js.map +1 -1
  175. package/build-module/components/block-list/block.js +5 -2
  176. package/build-module/components/block-list/block.js.map +1 -1
  177. package/build-module/components/block-list/use-block-props/index.js +1 -4
  178. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  179. package/build-module/components/block-list/use-block-props/use-focus-first-element.js +22 -6
  180. package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
  181. package/build-module/components/block-list/use-block-props/use-focus-handler.js +7 -1
  182. package/build-module/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
  183. package/build-module/components/block-list-appender/index.js +6 -1
  184. package/build-module/components/block-list-appender/index.js.map +1 -1
  185. package/build-module/components/block-lock/index.js +4 -0
  186. package/build-module/components/block-lock/index.js.map +1 -0
  187. package/build-module/components/block-lock/menu-item.js +53 -0
  188. package/build-module/components/block-lock/menu-item.js.map +1 -0
  189. package/build-module/components/block-lock/modal.js +119 -0
  190. package/build-module/components/block-lock/modal.js.map +1 -0
  191. package/build-module/components/block-lock/toolbar.js +63 -0
  192. package/build-module/components/block-lock/toolbar.js.map +1 -0
  193. package/build-module/components/block-mover/index.js +4 -0
  194. package/build-module/components/block-mover/index.js.map +1 -1
  195. package/build-module/components/block-settings-menu/block-settings-dropdown.js +75 -12
  196. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  197. package/build-module/components/block-settings-menu-controls/index.js +18 -9
  198. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  199. package/build-module/components/block-switcher/index.js +2 -2
  200. package/build-module/components/block-switcher/index.js.map +1 -1
  201. package/build-module/components/block-title/index.js +2 -2
  202. package/build-module/components/block-title/index.js.map +1 -1
  203. package/build-module/components/block-title/use-block-display-title.js +8 -6
  204. package/build-module/components/block-title/use-block-display-title.js.map +1 -1
  205. package/build-module/components/block-toolbar/block-name-context.js +9 -0
  206. package/build-module/components/block-toolbar/block-name-context.js.map +1 -0
  207. package/build-module/components/block-toolbar/block-toolbar-last-item.js +11 -0
  208. package/build-module/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
  209. package/build-module/components/block-toolbar/index.js +19 -4
  210. package/build-module/components/block-toolbar/index.js.map +1 -1
  211. package/build-module/components/block-tools/index.js +0 -16
  212. package/build-module/components/block-tools/index.js.map +1 -1
  213. package/build-module/components/block-variation-transforms/index.js +95 -49
  214. package/build-module/components/block-variation-transforms/index.js.map +1 -1
  215. package/build-module/components/block-vertical-alignment-control/index.js +12 -4
  216. package/build-module/components/block-vertical-alignment-control/index.js.map +1 -1
  217. package/build-module/components/border-radius-control/index.js +0 -1
  218. package/build-module/components/border-radius-control/index.js.map +1 -1
  219. package/build-module/components/border-radius-control/utils.js +1 -1
  220. package/build-module/components/border-radius-control/utils.js.map +1 -1
  221. package/build-module/components/colors-gradients/control.js +3 -1
  222. package/build-module/components/colors-gradients/control.js.map +1 -1
  223. package/build-module/components/contrast-checker/index.js +4 -0
  224. package/build-module/components/contrast-checker/index.js.map +1 -1
  225. package/build-module/components/convert-to-group-buttons/index.js +2 -1
  226. package/build-module/components/convert-to-group-buttons/index.js.map +1 -1
  227. package/build-module/components/convert-to-group-buttons/toolbar.js +90 -0
  228. package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -0
  229. package/build-module/components/copy-handler/index.js +4 -0
  230. package/build-module/components/copy-handler/index.js.map +1 -1
  231. package/build-module/components/date-format-picker/index.js +122 -0
  232. package/build-module/components/date-format-picker/index.js.map +1 -0
  233. package/build-module/components/font-sizes/font-size-picker.js +4 -0
  234. package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
  235. package/build-module/components/iframe/index.js +6 -9
  236. package/build-module/components/iframe/index.js.map +1 -1
  237. package/build-module/components/index.js +3 -0
  238. package/build-module/components/index.js.map +1 -1
  239. package/build-module/components/justify-content-control/index.js +12 -4
  240. package/build-module/components/justify-content-control/index.js.map +1 -1
  241. package/build-module/components/keyboard-shortcuts/index.js +1 -1
  242. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  243. package/build-module/components/line-height-control/index.js +14 -5
  244. package/build-module/components/line-height-control/index.js.map +1 -1
  245. package/build-module/components/list-view/block-select-button.js +24 -23
  246. package/build-module/components/list-view/block-select-button.js.map +1 -1
  247. package/build-module/components/list-view/block.js +36 -13
  248. package/build-module/components/list-view/block.js.map +1 -1
  249. package/build-module/components/list-view/branch.js +16 -13
  250. package/build-module/components/list-view/branch.js.map +1 -1
  251. package/build-module/components/list-view/index.js +7 -1
  252. package/build-module/components/list-view/index.js.map +1 -1
  253. package/build-module/components/list-view/use-block-selection.js +10 -3
  254. package/build-module/components/list-view/use-block-selection.js.map +1 -1
  255. package/build-module/components/media-replace-flow/index.js +4 -0
  256. package/build-module/components/media-replace-flow/index.js.map +1 -1
  257. package/build-module/components/multi-selection-inspector/index.js +2 -2
  258. package/build-module/components/multi-selection-inspector/index.js.map +1 -1
  259. package/build-module/components/rich-text/index.js +26 -5
  260. package/build-module/components/rich-text/index.js.map +1 -1
  261. package/build-module/components/rich-text/index.native.js +13 -9
  262. package/build-module/components/rich-text/index.native.js.map +1 -1
  263. package/build-module/components/rich-text/split-value.js +12 -2
  264. package/build-module/components/rich-text/split-value.js.map +1 -1
  265. package/build-module/components/rich-text/use-firefox-compat.js +39 -0
  266. package/build-module/components/rich-text/use-firefox-compat.js.map +1 -0
  267. package/build-module/components/rich-text/use-input-rules.js +35 -4
  268. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  269. package/build-module/components/skip-to-selected-block/index.js +4 -0
  270. package/build-module/components/skip-to-selected-block/index.js.map +1 -1
  271. package/build-module/components/url-popover/image-url-input-ui.js +12 -28
  272. package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
  273. package/build-module/components/writing-flow/index.js +5 -1
  274. package/build-module/components/writing-flow/index.js.map +1 -1
  275. package/build-module/components/writing-flow/use-arrow-nav.js +4 -45
  276. package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
  277. package/build-module/components/writing-flow/use-click-selection.js +57 -0
  278. package/build-module/components/writing-flow/use-click-selection.js.map +1 -0
  279. package/build-module/components/writing-flow/use-drag-selection.js +124 -0
  280. package/build-module/components/writing-flow/use-drag-selection.js.map +1 -0
  281. package/build-module/components/writing-flow/use-input.js +104 -0
  282. package/build-module/components/writing-flow/use-input.js.map +1 -0
  283. package/build-module/components/writing-flow/use-multi-selection.js +18 -37
  284. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  285. package/build-module/components/writing-flow/use-selection-observer.js +150 -0
  286. package/build-module/components/writing-flow/use-selection-observer.js.map +1 -0
  287. package/build-module/components/writing-flow/use-tab-nav.js +1 -9
  288. package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
  289. package/build-module/hooks/anchor.js +7 -6
  290. package/build-module/hooks/anchor.js.map +1 -1
  291. package/build-module/hooks/border-color.js +5 -5
  292. package/build-module/hooks/border-color.js.map +1 -1
  293. package/build-module/hooks/border.js +0 -12
  294. package/build-module/hooks/border.js.map +1 -1
  295. package/build-module/hooks/color.js +19 -18
  296. package/build-module/hooks/color.js.map +1 -1
  297. package/build-module/hooks/font-family.js +3 -1
  298. package/build-module/hooks/font-family.js.map +1 -1
  299. package/build-module/hooks/font-size.js +4 -3
  300. package/build-module/hooks/font-size.js.map +1 -1
  301. package/build-module/hooks/gap.js +75 -7
  302. package/build-module/hooks/gap.js.map +1 -1
  303. package/build-module/hooks/layout.js +7 -2
  304. package/build-module/hooks/layout.js.map +1 -1
  305. package/build-module/hooks/style.js +33 -3
  306. package/build-module/hooks/style.js.map +1 -1
  307. package/build-module/hooks/utils.js +26 -0
  308. package/build-module/hooks/utils.js.map +1 -1
  309. package/build-module/layouts/flex.js +81 -16
  310. package/build-module/layouts/flex.js.map +1 -1
  311. package/build-module/layouts/flow.js +20 -13
  312. package/build-module/layouts/flow.js.map +1 -1
  313. package/build-module/store/actions.js +286 -49
  314. package/build-module/store/actions.js.map +1 -1
  315. package/build-module/store/defaults.js +5 -1
  316. package/build-module/store/defaults.js.map +1 -1
  317. package/build-module/store/reducer.js +25 -13
  318. package/build-module/store/reducer.js.map +1 -1
  319. package/build-module/store/selectors.js +162 -20
  320. package/build-module/store/selectors.js.map +1 -1
  321. package/build-module/utils/dom.js +2 -1
  322. package/build-module/utils/dom.js.map +1 -1
  323. package/build-style/style-rtl.css +214 -24
  324. package/build-style/style.css +214 -24
  325. package/build-types/utils/dom.d.ts.map +1 -1
  326. package/package.json +28 -27
  327. package/src/components/alignment-control/index.js +9 -4
  328. package/src/components/block-alignment-control/index.js +9 -4
  329. package/src/components/block-draggable/index.js +2 -5
  330. package/src/components/block-icon/index.js +3 -0
  331. package/src/components/block-inspector/index.js +4 -0
  332. package/src/components/block-list/block-html.js +8 -4
  333. package/src/components/block-list/block.js +5 -1
  334. package/src/components/block-list/style.scss +4 -5
  335. package/src/components/block-list/use-block-props/index.js +0 -5
  336. package/src/components/block-list/use-block-props/use-focus-first-element.js +27 -6
  337. package/src/components/block-list/use-block-props/use-focus-handler.js +8 -0
  338. package/src/components/block-list-appender/index.js +5 -0
  339. package/src/components/block-lock/index.js +3 -0
  340. package/src/components/block-lock/menu-item.js +59 -0
  341. package/src/components/block-lock/modal.js +170 -0
  342. package/src/components/block-lock/style.scss +70 -0
  343. package/src/components/block-lock/toolbar.js +68 -0
  344. package/src/components/block-mover/index.js +3 -0
  345. package/src/components/block-mover/style.scss +4 -0
  346. package/src/components/block-settings-menu/block-settings-dropdown.js +109 -9
  347. package/src/components/block-settings-menu-controls/index.js +33 -12
  348. package/src/components/block-switcher/index.js +2 -2
  349. package/src/components/block-switcher/style.scss +8 -1
  350. package/src/components/block-switcher/test/index.js +2 -2
  351. package/src/components/block-title/README.md +6 -1
  352. package/src/components/block-title/index.js +2 -2
  353. package/src/components/block-title/test/index.js +43 -1
  354. package/src/components/block-title/use-block-display-title.js +10 -7
  355. package/src/components/block-toolbar/block-name-context.js +8 -0
  356. package/src/components/block-toolbar/block-toolbar-last-item.js +12 -0
  357. package/src/components/block-toolbar/index.js +24 -2
  358. package/src/components/block-toolbar/style.scss +10 -0
  359. package/src/components/block-tools/index.js +0 -19
  360. package/src/components/block-tools/style.scss +27 -0
  361. package/src/components/block-variation-transforms/index.js +105 -36
  362. package/src/components/block-variation-transforms/style.scss +1 -1
  363. package/src/components/block-vertical-alignment-control/index.js +9 -4
  364. package/src/components/border-radius-control/index.js +0 -1
  365. package/src/components/border-radius-control/test/utils.js +4 -0
  366. package/src/components/border-radius-control/utils.js +2 -1
  367. package/src/components/button-block-appender/style.scss +5 -1
  368. package/src/components/color-palette/test/__snapshots__/control.js.snap +70 -4
  369. package/src/components/colors-gradients/control.js +1 -1
  370. package/src/components/colors-gradients/style.scss +6 -0
  371. package/src/components/contrast-checker/index.js +3 -0
  372. package/src/components/convert-to-group-buttons/index.js +6 -1
  373. package/src/components/convert-to-group-buttons/toolbar.js +87 -0
  374. package/src/components/copy-handler/index.js +3 -0
  375. package/src/components/date-format-picker/README.md +58 -0
  376. package/src/components/date-format-picker/index.js +161 -0
  377. package/src/components/date-format-picker/style.scss +31 -0
  378. package/src/components/font-sizes/font-size-picker.js +3 -0
  379. package/src/components/iframe/index.js +5 -7
  380. package/src/components/index.js +3 -0
  381. package/src/components/justify-content-control/index.js +9 -4
  382. package/src/components/keyboard-shortcuts/index.js +1 -1
  383. package/src/components/line-height-control/index.js +11 -6
  384. package/src/components/link-control/README.md +1 -1
  385. package/src/components/list-view/block-select-button.js +21 -30
  386. package/src/components/list-view/block.js +55 -13
  387. package/src/components/list-view/branch.js +37 -15
  388. package/src/components/list-view/index.js +6 -0
  389. package/src/components/list-view/style.scss +56 -14
  390. package/src/components/list-view/use-block-selection.js +15 -2
  391. package/src/components/media-placeholder/README.md +8 -0
  392. package/src/components/media-replace-flow/index.js +3 -0
  393. package/src/components/multi-selection-inspector/index.js +2 -2
  394. package/src/components/rich-text/index.js +25 -2
  395. package/src/components/rich-text/index.native.js +24 -8
  396. package/src/components/rich-text/split-value.js +5 -1
  397. package/src/components/rich-text/use-firefox-compat.js +39 -0
  398. package/src/components/rich-text/use-input-rules.js +40 -3
  399. package/src/components/skip-to-selected-block/index.js +3 -0
  400. package/src/components/url-input/style.scss +3 -2
  401. package/src/components/url-popover/image-url-input-ui.js +16 -29
  402. package/src/components/writing-flow/index.js +8 -0
  403. package/src/components/writing-flow/readme.md +28 -0
  404. package/src/components/writing-flow/use-arrow-nav.js +4 -53
  405. package/src/components/writing-flow/use-click-selection.js +65 -0
  406. package/src/components/writing-flow/use-drag-selection.js +126 -0
  407. package/src/components/writing-flow/use-input.js +112 -0
  408. package/src/components/writing-flow/use-multi-selection.js +13 -36
  409. package/src/components/writing-flow/use-selection-observer.js +153 -0
  410. package/src/components/writing-flow/use-tab-nav.js +1 -11
  411. package/src/hooks/anchor.js +8 -6
  412. package/src/hooks/border-color.js +5 -5
  413. package/src/hooks/border.js +0 -13
  414. package/src/hooks/color.js +51 -24
  415. package/src/hooks/font-family.js +5 -2
  416. package/src/hooks/font-size.js +10 -7
  417. package/src/hooks/gap.js +91 -12
  418. package/src/hooks/layout.js +11 -1
  419. package/src/hooks/style.js +40 -4
  420. package/src/hooks/test/gap.js +66 -0
  421. package/src/hooks/test/style.js +94 -0
  422. package/src/hooks/test/utils.js +1 -1
  423. package/src/hooks/utils.js +26 -0
  424. package/src/layouts/flex.js +93 -6
  425. package/src/layouts/flow.js +28 -12
  426. package/src/store/actions.js +349 -32
  427. package/src/store/defaults.js +7 -1
  428. package/src/store/reducer.js +25 -10
  429. package/src/store/selectors.js +207 -25
  430. package/src/store/test/selectors.js +305 -5
  431. package/src/style.scss +2 -0
  432. package/src/utils/dom.js +2 -1
  433. package/tsconfig.tsbuildinfo +1 -1
  434. package/build/components/block-list/use-block-props/use-multi-selection.js +0 -205
  435. package/build/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
  436. package/build/components/block-list/use-block-props/use-scroll-into-view.js +0 -77
  437. package/build/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
  438. package/build-module/components/block-list/use-block-props/use-multi-selection.js +0 -192
  439. package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
  440. package/build-module/components/block-list/use-block-props/use-scroll-into-view.js +0 -63
  441. package/build-module/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
  442. package/src/components/block-list/use-block-props/use-multi-selection.js +0 -227
  443. package/src/components/block-list/use-block-props/use-scroll-into-view.js +0 -73
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","blockEditorStore","propsRef","current","element","inputRule","value","onReplace","start","text","characterBefore","slice","trimmedTextBefore","trim","prefixTransforms","filter","type","transformation","prefix","content","length","block","transform","onInput","event","inputType","onChange","__unstableAllowPrefixTransformations","formatTypes","transformed","reduce","accumlator","__unstableInputRule","activeFormats","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AA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A6B,OAA7B,EAAsCZ,OAAtC;AACAnB,MAAAA,OAAO,CAAC+B,mBAAR,CAA6B,gBAA7B,EAA+CZ,OAA/C;AACA,KAHD;AAIA,GArFM,EAqFJ,EArFI,CAAP;AAsFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { slice, toHTMLString } from '@wordpress/rich-text';\nimport { getBlockTransforms, findTransform } from '@wordpress/blocks';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { preventEventDiscovery } from './prevent-event-discovery';\n\nexport function useInputRules( props ) {\n\tconst {\n\t\t__unstableMarkLastChangeAsPersistent,\n\t\t__unstableMarkAutomaticChange,\n\t} = useDispatch( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction inputRule() {\n\t\t\tconst { value, onReplace } = propsRef.current;\n\n\t\t\tif ( ! onReplace ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { start, text } = value;\n\t\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t\t// The character right before the caret must be a plain space.\n\t\t\tif ( characterBefore !== ' ' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst trimmedTextBefore = text.slice( 0, start ).trim();\n\t\t\tconst prefixTransforms = getBlockTransforms( 'from' ).filter(\n\t\t\t\t( { type } ) => type === 'prefix'\n\t\t\t);\n\t\t\tconst transformation = findTransform(\n\t\t\t\tprefixTransforms,\n\t\t\t\t( { prefix } ) => {\n\t\t\t\t\treturn trimmedTextBefore === prefix;\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( ! transformation ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst content = toHTMLString( {\n\t\t\t\tvalue: slice( value, start, text.length ),\n\t\t\t} );\n\t\t\tconst block = transformation.transform( content );\n\n\t\t\tonReplace( [ block ] );\n\t\t\t__unstableMarkAutomaticChange();\n\t\t}\n\n\t\tfunction onInput( event ) {\n\t\t\tconst { inputType, type } = event;\n\t\t\tconst {\n\t\t\t\tvalue,\n\t\t\t\tonChange,\n\t\t\t\t__unstableAllowPrefixTransformations,\n\t\t\t\tformatTypes,\n\t\t\t} = propsRef.current;\n\n\t\t\t// Only run input rules when inserting text.\n\t\t\tif ( inputType !== 'insertText' && type !== 'compositionend' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( __unstableAllowPrefixTransformations && inputRule ) {\n\t\t\t\tinputRule();\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstableInputRule } ) => {\n\t\t\t\t\tif ( __unstableInputRule ) {\n\t\t\t\t\t\taccumlator = __unstableInputRule( accumlator );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tpreventEventDiscovery( value )\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\t\tonChange( {\n\t\t\t\t\t...transformed,\n\t\t\t\t\tactiveFormats: value.activeFormats,\n\t\t\t\t} );\n\t\t\t\t__unstableMarkAutomaticChange();\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'input', onInput );\n\t\telement.addEventListener( 'compositionend', onInput );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'input', onInput );\n\t\t\telement.removeEventListener( 'compositionend', onInput );\n\t\t};\n\t}, [] );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["START_OF_SELECTED_AREA","findSelection","blocks","i","length","attributeKey","attributes","v","indexOf","replace","clientId","nestedSelection","innerBlocks","useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","blockEditorStore","propsRef","current","element","inputRule","value","onReplace","selectionChange","start","text","characterBefore","slice","trimmedTextBefore","trim","prefixTransforms","filter","type","transformation","prefix","content","block","transform","onInput","event","inputType","onChange","__unstableAllowPrefixTransformations","formatTypes","transformed","reduce","accumlator","__unstableInputRule","activeFormats","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AAIA;AACA;AACA;AACA,MAAMA,sBAAsB,GAAG,QAA/B;;AAEA,SAASC,aAAT,CAAwBC,MAAxB,EAAiC;AAChC,MAAIC,CAAC,GAAGD,MAAM,CAACE,MAAf;;AAEA,SAAQD,CAAC,EAAT,EAAc;AACb,UAAME,YAAY,GAAG,qBACpBH,MAAM,CAAEC,CAAF,CAAN,CAAYG,UADQ,EAElBC,CAAF,IACC,OAAOA,CAAP,KAAa,QAAb,IACAA,CAAC,CAACC,OAAF,CAAWR,sBAAX,MAAwC,CAAC,CAJtB,CAArB;;AAOA,QAAKK,YAAL,EAAoB;AACnBH,MAAAA,MAAM,CAAEC,CAAF,CAAN,CAAYG,UAAZ,CAAwBD,YAAxB,IAAyCH,MAAM,CAAEC,CAAF,CAAN,CAAYG,UAAZ,CACxCD,YADwC,EAEvCI,OAFuC,CAE9BT,sBAF8B,EAEN,EAFM,CAAzC;AAGA,aAAOE,MAAM,CAAEC,CAAF,CAAN,CAAYO,QAAnB;AACA;;AAED,UAAMC,eAAe,GAAGV,aAAa,CAAEC,MAAM,CAAEC,CAAF,CAAN,CAAYS,WAAd,CAArC;;AAEA,QAAKD,eAAL,EAAuB;AACtB,aAAOA,eAAP;AACA;AACD;AACD;;AAEM,SAASE,aAAT,CAAwBC,KAAxB,EAAgC;AACtC,QAAM;AACLC,IAAAA,oCADK;AAELC,IAAAA;AAFK,MAGF,uBAAaC,YAAb,CAHJ;AAIA,QAAMC,QAAQ,GAAG,qBAAQJ,KAAR,CAAjB;AACAI,EAAAA,QAAQ,CAACC,OAAT,GAAmBL,KAAnB;A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n * External dependencies\n */\nimport { findKey } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { insert, toHTMLString } from '@wordpress/rich-text';\nimport { getBlockTransforms, findTransform } from '@wordpress/blocks';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { preventEventDiscovery } from './prevent-event-discovery';\n\n// A robust way to retain selection position through various\n// transforms is to insert a special character at the position and\n// then recover it.\nconst START_OF_SELECTED_AREA = '\\u0086';\n\nfunction findSelection( blocks ) {\n\tlet i = blocks.length;\n\n\twhile ( i-- ) {\n\t\tconst attributeKey = findKey(\n\t\t\tblocks[ i ].attributes,\n\t\t\t( v ) =>\n\t\t\t\ttypeof v === 'string' &&\n\t\t\t\tv.indexOf( START_OF_SELECTED_AREA ) !== -1\n\t\t);\n\n\t\tif ( attributeKey ) {\n\t\t\tblocks[ i ].attributes[ attributeKey ] = blocks[ i ].attributes[\n\t\t\t\tattributeKey\n\t\t\t].replace( START_OF_SELECTED_AREA, '' );\n\t\t\treturn blocks[ i ].clientId;\n\t\t}\n\n\t\tconst nestedSelection = findSelection( blocks[ i ].innerBlocks );\n\n\t\tif ( nestedSelection ) {\n\t\t\treturn nestedSelection;\n\t\t}\n\t}\n}\n\nexport function useInputRules( props ) {\n\tconst {\n\t\t__unstableMarkLastChangeAsPersistent,\n\t\t__unstableMarkAutomaticChange,\n\t} = useDispatch( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction inputRule() {\n\t\t\tconst { value, onReplace, selectionChange } = propsRef.current;\n\n\t\t\tif ( ! onReplace ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { start, text } = value;\n\t\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t\t// The character right before the caret must be a plain space.\n\t\t\tif ( characterBefore !== ' ' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst trimmedTextBefore = text.slice( 0, start ).trim();\n\t\t\tconst prefixTransforms = getBlockTransforms( 'from' ).filter(\n\t\t\t\t( { type } ) => type === 'prefix'\n\t\t\t);\n\t\t\tconst transformation = findTransform(\n\t\t\t\tprefixTransforms,\n\t\t\t\t( { prefix } ) => {\n\t\t\t\t\treturn trimmedTextBefore === prefix;\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( ! transformation ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst content = toHTMLString( {\n\t\t\t\tvalue: insert( value, START_OF_SELECTED_AREA, 0, start ),\n\t\t\t} );\n\t\t\tconst block = transformation.transform( content );\n\n\t\t\tselectionChange( findSelection( [ block ] ) );\n\t\t\tonReplace( [ block ] );\n\t\t\t__unstableMarkAutomaticChange();\n\t\t}\n\n\t\tfunction onInput( event ) {\n\t\t\tconst { inputType, type } = event;\n\t\t\tconst {\n\t\t\t\tvalue,\n\t\t\t\tonChange,\n\t\t\t\t__unstableAllowPrefixTransformations,\n\t\t\t\tformatTypes,\n\t\t\t} = propsRef.current;\n\n\t\t\t// Only run input rules when inserting text.\n\t\t\tif ( inputType !== 'insertText' && type !== 'compositionend' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( __unstableAllowPrefixTransformations && inputRule ) {\n\t\t\t\tinputRule();\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstableInputRule } ) => {\n\t\t\t\t\tif ( __unstableInputRule ) {\n\t\t\t\t\t\taccumlator = __unstableInputRule( accumlator );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tpreventEventDiscovery( value )\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\t\tonChange( {\n\t\t\t\t\t...transformed,\n\t\t\t\t\tactiveFormats: value.activeFormats,\n\t\t\t\t} );\n\t\t\t\t__unstableMarkAutomaticChange();\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'input', onInput );\n\t\telement.addEventListener( 'compositionend', onInput );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'input', onInput );\n\t\t\telement.removeEventListener( 'compositionend', onInput );\n\t\t};\n\t}, [] );\n}\n"]}
@@ -40,6 +40,10 @@ const SkipToSelectedBlock = _ref => {
40
40
  onClick: onClick
41
41
  }, (0, _i18n.__)('Skip to the selected block')) : null;
42
42
  };
43
+ /**
44
+ * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md
45
+ */
46
+
43
47
 
44
48
  var _default = (0, _data.withSelect)(select => {
45
49
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/skip-to-selected-block/index.js"],"names":["SkipToSelectedBlock","selectedBlockClientId","ref","onClick","current","focus","select","blockEditorStore","getBlockSelectionStart"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAG,QAAiC;AAAA,MAA/B;AAAEC,IAAAA;AAAF,GAA+B;AAC5D,QAAMC,GAAG,GAAG,yCAAaD,qBAAb,CAAZ;;AACA,QAAME,OAAO,GAAG,MAAM;AACrBD,IAAAA,GAAG,CAACE,OAAJ,CAAYC,KAAZ;AACA,GAFD;;AAIA,SAAOJ,qBAAqB,GAC3B,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,SAAS,EAAC,qCAFX;AAGC,IAAA,OAAO,EAAGE;AAHX,KAKG,cAAI,4BAAJ,CALH,CAD2B,GAQxB,IARJ;AASA,CAfD;;eAiBe,sBAAcG,MAAF,IAAc;AACxC,SAAO;AACNL,IAAAA,qBAAqB,EAAEK,MAAM,CAC5BC,YAD4B,CAAN,CAErBC,sBAFqB;AADjB,GAAP;AAKA,CANc,EAMVR,mBANU,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { withSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nconst SkipToSelectedBlock = ( { selectedBlockClientId } ) => {\n\tconst ref = useBlockRef( selectedBlockClientId );\n\tconst onClick = () => {\n\t\tref.current.focus();\n\t};\n\n\treturn selectedBlockClientId ? (\n\t\t<Button\n\t\t\tvariant=\"secondary\"\n\t\t\tclassName=\"block-editor-skip-to-selected-block\"\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ __( 'Skip to the selected block' ) }\n\t\t</Button>\n\t) : null;\n};\n\nexport default withSelect( ( select ) => {\n\treturn {\n\t\tselectedBlockClientId: select(\n\t\t\tblockEditorStore\n\t\t).getBlockSelectionStart(),\n\t};\n} )( SkipToSelectedBlock );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/skip-to-selected-block/index.js"],"names":["SkipToSelectedBlock","selectedBlockClientId","ref","onClick","current","focus","select","blockEditorStore","getBlockSelectionStart"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAG,QAAiC;AAAA,MAA/B;AAAEC,IAAAA;AAAF,GAA+B;AAC5D,QAAMC,GAAG,GAAG,yCAAaD,qBAAb,CAAZ;;AACA,QAAME,OAAO,GAAG,MAAM;AACrBD,IAAAA,GAAG,CAACE,OAAJ,CAAYC,KAAZ;AACA,GAFD;;AAIA,SAAOJ,qBAAqB,GAC3B,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,SAAS,EAAC,qCAFX;AAGC,IAAA,OAAO,EAAGE;AAHX,KAKG,cAAI,4BAAJ,CALH,CAD2B,GAQxB,IARJ;AASA,CAfD;AAiBA;AACA;AACA;;;eACe,sBAAcG,MAAF,IAAc;AACxC,SAAO;AACNL,IAAAA,qBAAqB,EAAEK,MAAM,CAC5BC,YAD4B,CAAN,CAErBC,sBAFqB;AADjB,GAAP;AAKA,CANc,EAMVR,mBANU,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { withSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nconst SkipToSelectedBlock = ( { selectedBlockClientId } ) => {\n\tconst ref = useBlockRef( selectedBlockClientId );\n\tconst onClick = () => {\n\t\tref.current.focus();\n\t};\n\n\treturn selectedBlockClientId ? (\n\t\t<Button\n\t\t\tvariant=\"secondary\"\n\t\t\tclassName=\"block-editor-skip-to-selected-block\"\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ __( 'Skip to the selected block' ) }\n\t\t</Button>\n\t) : null;\n};\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md\n */\nexport default withSelect( ( select ) => {\n\treturn {\n\t\tselectedBlockClientId: select(\n\t\t\tblockEditorStore\n\t\t).getBlockSelectionStart(),\n\t};\n} )( SkipToSelectedBlock );\n"]}
@@ -82,37 +82,21 @@ const ImageURLInputUI = _ref => {
82
82
  setIsOpen(false);
83
83
  });
84
84
 
85
- const removeNewTabRel = currentRel => {
86
- let newRel = currentRel;
87
-
88
- if (currentRel !== undefined && !(0, _lodash.isEmpty)(newRel)) {
89
- if (!(0, _lodash.isEmpty)(newRel)) {
90
- (0, _lodash.each)(NEW_TAB_REL, relVal => {
91
- const regExp = new RegExp('\\b' + relVal + '\\b', 'gi');
92
- newRel = newRel.replace(regExp, '');
93
- }); // Only trim if NEW_TAB_REL values was replaced.
94
-
95
- if (newRel !== currentRel) {
96
- newRel = newRel.trim();
97
- }
98
-
99
- if ((0, _lodash.isEmpty)(newRel)) {
100
- newRel = undefined;
101
- }
102
- }
103
- }
104
-
105
- return newRel;
106
- };
107
-
108
85
  const getUpdatedLinkTargetSettings = value => {
109
86
  const newLinkTarget = value ? '_blank' : undefined;
110
87
  let updatedRel;
111
88
 
112
- if (!newLinkTarget && !rel) {
113
- updatedRel = undefined;
89
+ if (newLinkTarget) {
90
+ const rels = (rel !== null && rel !== void 0 ? rel : '').split(' ');
91
+ NEW_TAB_REL.forEach(relVal => {
92
+ if (!rels.includes(relVal)) {
93
+ rels.push(relVal);
94
+ }
95
+ });
96
+ updatedRel = rels.join(' ');
114
97
  } else {
115
- updatedRel = removeNewTabRel(rel);
98
+ const rels = (rel !== null && rel !== void 0 ? rel : '').split(' ').filter(relVal => NEW_TAB_REL.includes(relVal) === false);
99
+ updatedRel = rels.length ? rels.join(' ') : undefined;
116
100
  }
117
101
 
118
102
  return {
@@ -235,7 +219,7 @@ const ImageURLInputUI = _ref => {
235
219
  checked: linkTarget === '_blank'
236
220
  }), (0, _element.createElement)(_components.TextControl, {
237
221
  label: (0, _i18n.__)('Link Rel'),
238
- value: removeNewTabRel(rel) || '',
222
+ value: rel !== null && rel !== void 0 ? rel : '',
239
223
  onChange: onSetLinkRel
240
224
  }), (0, _element.createElement)(_components.TextControl, {
241
225
  label: (0, _i18n.__)('Link CSS Class'),
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/url-popover/image-url-input-ui.js"],"names":["LINK_DESTINATION_NONE","LINK_DESTINATION_CUSTOM","LINK_DESTINATION_MEDIA","LINK_DESTINATION_ATTACHMENT","NEW_TAB_REL","icon","ImageURLInputUI","linkDestination","onChangeUrl","url","mediaType","mediaUrl","mediaLink","linkTarget","linkClass","rel","isOpen","setIsOpen","openLinkUI","isEditingLink","setIsEditingLink","urlInput","setUrlInput","autocompleteRef","startEditLink","stopEditLink","closeLinkUI","removeNewTabRel","currentRel","newRel","undefined","relVal","regExp","RegExp","replace","trim","getUpdatedLinkTargetSettings","value","newLinkTarget","updatedRel","onFocusOutside","event","autocompleteElement","current","contains","target","onSubmitLinkChange","selectedDestination","getLinkDestinations","find","destination","href","preventDefault","onLinkRemove","linkDestinations","title","push","onSetHref","linkDestinationInput","onSetNewTab","updatedLinkTarget","onSetLinkRel","onSetLinkClass","advancedOptions","linkEditorValue","urlLabel","linkIcon","link","close"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AAUA;;AAKA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAeA;AACA;AACA;AAGA,MAAMA,qBAAqB,GAAG,MAA9B;AACA,MAAMC,uBAAuB,GAAG,QAAhC;AACA,MAAMC,sBAAsB,GAAG,OAA/B;AACA,MAAMC,2BAA2B,GAAG,YAApC;AACA,MAAMC,WAAW,GAAG,CAAE,YAAF,EAAgB,UAAhB,CAApB;AAEA,MAAMC,IAAI,GACT,4BAAC,eAAD;AAAK,EAAA,OAAO,EAAC,WAAb;AAAyB,EAAA,KAAK,EAAC;AAA/B,GACC,4BAAC,gBAAD;AAAM,EAAA,CAAC,EAAC,iBAAR;AAA0B,EAAA,IAAI,EAAC;AAA/B,EADD,EAEC,4BAAC,gBAAD;AAAM,EAAA,CAAC,EAAC;AAAR,EAFD,EAGC,4BAAC,gBAAD;AAAM,EAAA,CAAC,EAAC;AAAR,EAHD,CADD;;AAQA,MAAMC,eAAe,GAAG,QAUjB;AAAA,MAVmB;AACzBC,IAAAA,eADyB;AAEzBC,IAAAA,WAFyB;AAGzBC,IAAAA,GAHyB;AAIzBC,IAAAA,SAAS,GAAG,OAJa;AAKzBC,IAAAA,QALyB;AAMzBC,IAAAA,SANyB;AAOzBC,IAAAA,UAPyB;AAQzBC,IAAAA,SARyB;AASzBC,IAAAA;AATyB,GAUnB;AACN,QAAM,CAAEC,MAAF,EAAUC,SAAV,IAAwB,uBAAU,KAAV,CAA9B;AACA,QAAMC,UAAU,GAAG,0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FT;AAGC,IAAA,kBAAkB,EAAG1C,WAHtB;AAIC,IAAA,QAAQ,EAAGwB,kBAAkB,EAJ9B;AAKC,IAAA,eAAe,EAAGvB;AALnB,IAzBF,EAiCGd,GAAG,IAAI,CAAEU,aAAT,IACD,qDACC,4BAAC,cAAD,CAAY,UAAZ;AACC,IAAA,SAAS,EAAC,qDADX;AAEC,IAAA,GAAG,EAAGV,GAFP;AAGC,IAAA,eAAe,EAAGe,aAHnB;AAIC,IAAA,QAAQ,EAAGyC;AAJZ,IADD,EAOC,4BAAC,kBAAD;AACC,IAAA,IAAI,EAAGG,YADR;AAEC,IAAA,KAAK,EAAG,cAAI,aAAJ,CAFT;AAGC,IAAA,OAAO,EAAGf;AAHX,IAPD,CAlCF,CATF,CADD;AA8DA,CAjRD","sourcesContent":["/**\n * External dependencies\n */\nimport { find, isEmpty, each, map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useState, useCallback } from '@wordpress/element';\nimport {\n\tToolbarButton,\n\tButton,\n\tNavigableMenu,\n\tMenuItem,\n\tToggleControl,\n\tTextControl,\n\tSVG,\n\tPath,\n} from '@wordpress/components';\nimport { link as linkIcon, close } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport URLPopover from './index';\n\nconst LINK_DESTINATION_NONE = 'none';\nconst LINK_DESTINATION_CUSTOM = 'custom';\nconst LINK_DESTINATION_MEDIA = 'media';\nconst LINK_DESTINATION_ATTACHMENT = 'attachment';\nconst NEW_TAB_REL = [ 'noreferrer', 'noopener' ];\n\nconst icon = (\n\t<SVG viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t<Path d=\"M0,0h24v24H0V0z\" fill=\"none\" />\n\t\t<Path d=\"m19 5v14h-14v-14h14m0-2h-14c-1.1 0-2 0.9-2 2v14c0 1.1 0.9 2 2 2h14c1.1 0 2-0.9 2-2v-14c0-1.1-0.9-2-2-2z\" />\n\t\t<Path d=\"m14.14 11.86l-3 3.87-2.14-2.59-3 3.86h12l-3.86-5.14z\" />\n\t</SVG>\n);\n\nconst ImageURLInputUI = ( {\n\tlinkDestination,\n\tonChangeUrl,\n\turl,\n\tmediaType = 'image',\n\tmediaUrl,\n\tmediaLink,\n\tlinkTarget,\n\tlinkClass,\n\trel,\n} ) => {\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\tconst openLinkUI = useCallback( () => {\n\t\tsetIsOpen( true );\n\t} );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState( false );\n\tconst [ urlInput, setUrlInput ] = useState( null );\n\n\tconst autocompleteRef = useRef( null );\n\n\tconst startEditLink = useCallback( () => {\n\t\tif (\n\t\t\tlinkDestination === LINK_DESTINATION_MEDIA ||\n\t\t\tlinkDestination === LINK_DESTINATION_ATTACHMENT\n\t\t) {\n\t\t\tsetUrlInput( '' );\n\t\t}\n\t\tsetIsEditingLink( true );\n\t} );\n\n\tconst stopEditLink = useCallback( () => {\n\t\tsetIsEditingLink( false );\n\t} );\n\n\tconst closeLinkUI = useCallback( () => {\n\t\tsetUrlInput( null );\n\t\tstopEditLink();\n\t\tsetIsOpen( false );\n\t} );\n\n\tconst removeNewTabRel = ( currentRel ) => {\n\t\tlet newRel = currentRel;\n\n\t\tif ( currentRel !== undefined && ! isEmpty( newRel ) ) {\n\t\t\tif ( ! isEmpty( newRel ) ) {\n\t\t\t\teach( NEW_TAB_REL, ( relVal ) => {\n\t\t\t\t\tconst regExp = new RegExp( '\\\\b' + relVal + '\\\\b', 'gi' );\n\t\t\t\t\tnewRel = newRel.replace( regExp, '' );\n\t\t\t\t} );\n\n\t\t\t\t// Only trim if NEW_TAB_REL values was replaced.\n\t\t\t\tif ( newRel !== currentRel ) {\n\t\t\t\t\tnewRel = newRel.trim();\n\t\t\t\t}\n\n\t\t\t\tif ( isEmpty( newRel ) ) {\n\t\t\t\t\tnewRel = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn newRel;\n\t};\n\n\tconst getUpdatedLinkTargetSettings = ( value ) => {\n\t\tconst newLinkTarget = value ? '_blank' : undefined;\n\n\t\tlet updatedRel;\n\t\tif ( ! newLinkTarget && ! rel ) {\n\t\t\tupdatedRel = undefined;\n\t\t} else {\n\t\t\tupdatedRel = removeNewTabRel( rel );\n\t\t}\n\n\t\treturn {\n\t\t\tlinkTarget: newLinkTarget,\n\t\t\trel: updatedRel,\n\t\t};\n\t};\n\n\tconst onFocusOutside = useCallback( () => {\n\t\treturn ( event ) => {\n\t\t\t// The autocomplete suggestions list renders in a separate popover (in a portal),\n\t\t\t// so onFocusOutside fails to detect that a click on a suggestion occurred in the\n\t\t\t// LinkContainer. Detect clicks on autocomplete suggestions using a ref here, and\n\t\t\t// return to avoid the popover being closed.\n\t\t\tconst autocompleteElement = autocompleteRef.current;\n\t\t\tif (\n\t\t\t\tautocompleteElement &&\n\t\t\t\tautocompleteElement.contains( event.target )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetIsOpen( false );\n\t\t\tsetUrlInput( null );\n\t\t\tstopEditLink();\n\t\t};\n\t} );\n\n\tconst onSubmitLinkChange = useCallback( () => {\n\t\treturn ( event ) => {\n\t\t\tif ( urlInput ) {\n\t\t\t\t// It is possible the entered URL actually matches a named link destination.\n\t\t\t\t// This check will ensure our link destination is correct.\n\t\t\t\tconst selectedDestination =\n\t\t\t\t\tgetLinkDestinations().find(\n\t\t\t\t\t\t( destination ) => destination.url === urlInput\n\t\t\t\t\t)?.linkDestination || LINK_DESTINATION_CUSTOM;\n\n\t\t\t\tonChangeUrl( {\n\t\t\t\t\thref: urlInput,\n\t\t\t\t\tlinkDestination: selectedDestination,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tstopEditLink();\n\t\t\tsetUrlInput( null );\n\t\t\tevent.preventDefault();\n\t\t};\n\t} );\n\n\tconst onLinkRemove = useCallback( () => {\n\t\tonChangeUrl( {\n\t\t\tlinkDestination: LINK_DESTINATION_NONE,\n\t\t\thref: '',\n\t\t} );\n\t} );\n\n\tconst getLinkDestinations = () => {\n\t\tconst linkDestinations = [\n\t\t\t{\n\t\t\t\tlinkDestination: LINK_DESTINATION_MEDIA,\n\t\t\t\ttitle: __( 'Media File' ),\n\t\t\t\turl: mediaType === 'image' ? mediaUrl : undefined,\n\t\t\t\ticon,\n\t\t\t},\n\t\t];\n\t\tif ( mediaType === 'image' && mediaLink ) {\n\t\t\tlinkDestinations.push( {\n\t\t\t\tlinkDestination: LINK_DESTINATION_ATTACHMENT,\n\t\t\t\ttitle: __( 'Attachment Page' ),\n\t\t\t\turl: mediaType === 'image' ? mediaLink : undefined,\n\t\t\t\ticon: (\n\t\t\t\t\t<SVG viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t\t\t\t\t<Path d=\"M0 0h24v24H0V0z\" fill=\"none\" />\n\t\t\t\t\t\t<Path d=\"M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z\" />\n\t\t\t\t\t</SVG>\n\t\t\t\t),\n\t\t\t} );\n\t\t}\n\t\treturn linkDestinations;\n\t};\n\n\tconst onSetHref = ( value ) => {\n\t\tconst linkDestinations = getLinkDestinations();\n\t\tlet linkDestinationInput;\n\t\tif ( ! value ) {\n\t\t\tlinkDestinationInput = LINK_DESTINATION_NONE;\n\t\t} else {\n\t\t\tlinkDestinationInput = (\n\t\t\t\tfind( linkDestinations, ( destination ) => {\n\t\t\t\t\treturn destination.url === value;\n\t\t\t\t} ) || { linkDestination: LINK_DESTINATION_CUSTOM }\n\t\t\t).linkDestination;\n\t\t}\n\t\tonChangeUrl( {\n\t\t\tlinkDestination: linkDestinationInput,\n\t\t\thref: value,\n\t\t} );\n\t};\n\n\tconst onSetNewTab = ( value ) => {\n\t\tconst updatedLinkTarget = getUpdatedLinkTargetSettings( value );\n\t\tonChangeUrl( updatedLinkTarget );\n\t};\n\n\tconst onSetLinkRel = ( value ) => {\n\t\tonChangeUrl( { rel: value } );\n\t};\n\n\tconst onSetLinkClass = ( value ) => {\n\t\tonChangeUrl( { linkClass: value } );\n\t};\n\n\tconst advancedOptions = (\n\t\t<>\n\t\t\t<ToggleControl\n\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\tonChange={ onSetNewTab }\n\t\t\t\tchecked={ linkTarget === '_blank' }\n\t\t\t/>\n\t\t\t<TextControl\n\t\t\t\tlabel={ __( 'Link Rel' ) }\n\t\t\t\tvalue={ removeNewTabRel( rel ) || '' }\n\t\t\t\tonChange={ onSetLinkRel }\n\t\t\t/>\n\t\t\t<TextControl\n\t\t\t\tlabel={ __( 'Link CSS Class' ) }\n\t\t\t\tvalue={ linkClass || '' }\n\t\t\t\tonChange={ onSetLinkClass }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst linkEditorValue = urlInput !== null ? urlInput : url;\n\n\tconst urlLabel = (\n\t\tfind( getLinkDestinations(), [ 'linkDestination', linkDestination ] ) ||\n\t\t{}\n\t).title;\n\n\treturn (\n\t\t<>\n\t\t\t<ToolbarButton\n\t\t\t\ticon={ linkIcon }\n\t\t\t\tclassName=\"components-toolbar__control\"\n\t\t\t\tlabel={ url ? __( 'Edit link' ) : __( 'Insert link' ) }\n\t\t\t\taria-expanded={ isOpen }\n\t\t\t\tonClick={ openLinkUI }\n\t\t\t/>\n\t\t\t{ isOpen && (\n\t\t\t\t<URLPopover\n\t\t\t\t\tonFocusOutside={ onFocusOutside() }\n\t\t\t\t\tonClose={ closeLinkUI }\n\t\t\t\t\trenderSettings={ () => advancedOptions }\n\t\t\t\t\tadditionalControls={\n\t\t\t\t\t\t! linkEditorValue && (\n\t\t\t\t\t\t\t<NavigableMenu>\n\t\t\t\t\t\t\t\t{ map( getLinkDestinations(), ( link ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\tkey={ link.linkDestination }\n\t\t\t\t\t\t\t\t\t\ticon={ link.icon }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tsetUrlInput( null );\n\t\t\t\t\t\t\t\t\t\t\tonSetHref( link.url );\n\t\t\t\t\t\t\t\t\t\t\tstopEditLink();\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ link.title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ ( ! url || isEditingLink ) && (\n\t\t\t\t\t\t<URLPopover.LinkEditor\n\t\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__link-container-content\"\n\t\t\t\t\t\t\tvalue={ linkEditorValue }\n\t\t\t\t\t\t\tonChangeInputValue={ setUrlInput }\n\t\t\t\t\t\t\tonSubmit={ onSubmitLinkChange() }\n\t\t\t\t\t\t\tautocompleteRef={ autocompleteRef }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ url && ! isEditingLink && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<URLPopover.LinkViewer\n\t\t\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__link-container-content\"\n\t\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\t\tonEditLinkClick={ startEditLink }\n\t\t\t\t\t\t\t\turlLabel={ urlLabel }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ close }\n\t\t\t\t\t\t\t\tlabel={ __( 'Remove link' ) }\n\t\t\t\t\t\t\t\tonClick={ onLinkRemove }\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</URLPopover>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nexport { ImageURLInputUI as __experimentalImageURLInputUI };\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/url-popover/image-url-input-ui.js"],"names":["LINK_DESTINATION_NONE","LINK_DESTINATION_CUSTOM","LINK_DESTINATION_MEDIA","LINK_DESTINATION_ATTACHMENT","NEW_TAB_REL","icon","ImageURLInputUI","linkDestination","onChangeUrl","url","mediaType","mediaUrl","mediaLink","linkTarget","linkClass","rel","isOpen","setIsOpen","openLinkUI","isEditingLink","setIsEditingLink","urlInput","setUrlInput","autocompleteRef","startEditLink","stopEditLink","closeLinkUI","getUpdatedLinkTargetSettings","value","newLinkTarget","undefined","updatedRel","rels","split","forEach","relVal","includes","push","join","filter","length","onFocusOutside","event","autocompleteElement","current","contains","target","onSubmitLinkChange","selectedDestination","getLinkDestinations","find","destination","href","preventDefault","onLinkRemove","linkDestinations","title","onSetHref","linkDestinationInput","onSetNewTab","updatedLinkTarget","onSetLinkRel","onSetLinkClass","advancedOptions","linkEditorValue","urlLabel","linkIcon","link","close"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AAUA;;AAKA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAeA;AACA;AACA;AAGA,MAAMA,qBAAqB,GAAG,MAA9B;AACA,MAAMC,uBAAuB,GAAG,QAAhC;AACA,MAAMC,sBAAsB,GAAG,OAA/B;AACA,MAAMC,2BAA2B,GAAG,YAApC;AACA,MAAMC,WAAW,GAAG,CAAE,YAAF,EAAgB,UAAhB,CAApB;AAEA,MAAMC,IAAI,GACT,4BAAC,eAAD;AAAK,EAAA,OAAO,EAAC,WAAb;AAAyB,EAAA,KAAK,EAAC;AAA/B,GACC,4BAAC,gBAAD;AAAM,EAAA,CAAC,EAAC,iBAAR;AAA0B,EAAA,IAAI,EAAC;AAA/B,EADD,EAEC,4BAAC,gBAAD;AAAM,EAAA,CAAC,EAAC;AAAR,EAFD,EAGC,4BAAC,gBAAD;AAAM,EAAA,CAAC,EAAC;AAAR,EAHD,CADD;;AAQA,MAAM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I,CAAC1D,GAAP,CAAT;AACAgB,QAAAA,YAAY;AACZ;AAPF,OASG0C,IAAI,CAACX,KATR,CADC,CADH;AANH,KAwBG,CAAE,CAAE/C,GAAF,IAASU,aAAX,KACD,4BAAC,cAAD,CAAY,UAAZ;AACC,IAAA,SAAS,EAAC,qDADX;AAEC,IAAA,KAAK,EAAG6C,eAFT;AAGC,IAAA,kBAAkB,EAAG1C,WAHtB;AAIC,IAAA,QAAQ,EAAGyB,kBAAkB,EAJ9B;AAKC,IAAA,eAAe,EAAGxB;AALnB,IAzBF,EAiCGd,GAAG,IAAI,CAAEU,aAAT,IACD,qDACC,4BAAC,cAAD,CAAY,UAAZ;AACC,IAAA,SAAS,EAAC,qDADX;AAEC,IAAA,GAAG,EAAGV,GAFP;AAGC,IAAA,eAAe,EAAGe,aAHnB;AAIC,IAAA,QAAQ,EAAGyC;AAJZ,IADD,EAOC,4BAAC,kBAAD;AACC,IAAA,IAAI,EAAGG,YADR;AAEC,IAAA,KAAK,EAAG,cAAI,aAAJ,CAFT;AAGC,IAAA,OAAO,EAAGd;AAHX,IAPD,CAlCF,CATF,CADD;AA8DA,CApQD","sourcesContent":["/**\n * External dependencies\n */\nimport { find, map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useState, useCallback } from '@wordpress/element';\nimport {\n\tToolbarButton,\n\tButton,\n\tNavigableMenu,\n\tMenuItem,\n\tToggleControl,\n\tTextControl,\n\tSVG,\n\tPath,\n} from '@wordpress/components';\nimport { link as linkIcon, close } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport URLPopover from './index';\n\nconst LINK_DESTINATION_NONE = 'none';\nconst LINK_DESTINATION_CUSTOM = 'custom';\nconst LINK_DESTINATION_MEDIA = 'media';\nconst LINK_DESTINATION_ATTACHMENT = 'attachment';\nconst NEW_TAB_REL = [ 'noreferrer', 'noopener' ];\n\nconst icon = (\n\t<SVG viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t<Path d=\"M0,0h24v24H0V0z\" fill=\"none\" />\n\t\t<Path d=\"m19 5v14h-14v-14h14m0-2h-14c-1.1 0-2 0.9-2 2v14c0 1.1 0.9 2 2 2h14c1.1 0 2-0.9 2-2v-14c0-1.1-0.9-2-2-2z\" />\n\t\t<Path d=\"m14.14 11.86l-3 3.87-2.14-2.59-3 3.86h12l-3.86-5.14z\" />\n\t</SVG>\n);\n\nconst ImageURLInputUI = ( {\n\tlinkDestination,\n\tonChangeUrl,\n\turl,\n\tmediaType = 'image',\n\tmediaUrl,\n\tmediaLink,\n\tlinkTarget,\n\tlinkClass,\n\trel,\n} ) => {\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\tconst openLinkUI = useCallback( () => {\n\t\tsetIsOpen( true );\n\t} );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState( false );\n\tconst [ urlInput, setUrlInput ] = useState( null );\n\n\tconst autocompleteRef = useRef( null );\n\n\tconst startEditLink = useCallback( () => {\n\t\tif (\n\t\t\tlinkDestination === LINK_DESTINATION_MEDIA ||\n\t\t\tlinkDestination === LINK_DESTINATION_ATTACHMENT\n\t\t) {\n\t\t\tsetUrlInput( '' );\n\t\t}\n\t\tsetIsEditingLink( true );\n\t} );\n\n\tconst stopEditLink = useCallback( () => {\n\t\tsetIsEditingLink( false );\n\t} );\n\n\tconst closeLinkUI = useCallback( () => {\n\t\tsetUrlInput( null );\n\t\tstopEditLink();\n\t\tsetIsOpen( false );\n\t} );\n\n\tconst getUpdatedLinkTargetSettings = ( value ) => {\n\t\tconst newLinkTarget = value ? '_blank' : undefined;\n\n\t\tlet updatedRel;\n\t\tif ( newLinkTarget ) {\n\t\t\tconst rels = ( rel ?? '' ).split( ' ' );\n\t\t\tNEW_TAB_REL.forEach( ( relVal ) => {\n\t\t\t\tif ( ! rels.includes( relVal ) ) {\n\t\t\t\t\trels.push( relVal );\n\t\t\t\t}\n\t\t\t} );\n\t\t\tupdatedRel = rels.join( ' ' );\n\t\t} else {\n\t\t\tconst rels = ( rel ?? '' )\n\t\t\t\t.split( ' ' )\n\t\t\t\t.filter(\n\t\t\t\t\t( relVal ) => NEW_TAB_REL.includes( relVal ) === false\n\t\t\t\t);\n\t\t\tupdatedRel = rels.length ? rels.join( ' ' ) : undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tlinkTarget: newLinkTarget,\n\t\t\trel: updatedRel,\n\t\t};\n\t};\n\n\tconst onFocusOutside = useCallback( () => {\n\t\treturn ( event ) => {\n\t\t\t// The autocomplete suggestions list renders in a separate popover (in a portal),\n\t\t\t// so onFocusOutside fails to detect that a click on a suggestion occurred in the\n\t\t\t// LinkContainer. Detect clicks on autocomplete suggestions using a ref here, and\n\t\t\t// return to avoid the popover being closed.\n\t\t\tconst autocompleteElement = autocompleteRef.current;\n\t\t\tif (\n\t\t\t\tautocompleteElement &&\n\t\t\t\tautocompleteElement.contains( event.target )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetIsOpen( false );\n\t\t\tsetUrlInput( null );\n\t\t\tstopEditLink();\n\t\t};\n\t} );\n\n\tconst onSubmitLinkChange = useCallback( () => {\n\t\treturn ( event ) => {\n\t\t\tif ( urlInput ) {\n\t\t\t\t// It is possible the entered URL actually matches a named link destination.\n\t\t\t\t// This check will ensure our link destination is correct.\n\t\t\t\tconst selectedDestination =\n\t\t\t\t\tgetLinkDestinations().find(\n\t\t\t\t\t\t( destination ) => destination.url === urlInput\n\t\t\t\t\t)?.linkDestination || LINK_DESTINATION_CUSTOM;\n\n\t\t\t\tonChangeUrl( {\n\t\t\t\t\thref: urlInput,\n\t\t\t\t\tlinkDestination: selectedDestination,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tstopEditLink();\n\t\t\tsetUrlInput( null );\n\t\t\tevent.preventDefault();\n\t\t};\n\t} );\n\n\tconst onLinkRemove = useCallback( () => {\n\t\tonChangeUrl( {\n\t\t\tlinkDestination: LINK_DESTINATION_NONE,\n\t\t\thref: '',\n\t\t} );\n\t} );\n\n\tconst getLinkDestinations = () => {\n\t\tconst linkDestinations = [\n\t\t\t{\n\t\t\t\tlinkDestination: LINK_DESTINATION_MEDIA,\n\t\t\t\ttitle: __( 'Media File' ),\n\t\t\t\turl: mediaType === 'image' ? mediaUrl : undefined,\n\t\t\t\ticon,\n\t\t\t},\n\t\t];\n\t\tif ( mediaType === 'image' && mediaLink ) {\n\t\t\tlinkDestinations.push( {\n\t\t\t\tlinkDestination: LINK_DESTINATION_ATTACHMENT,\n\t\t\t\ttitle: __( 'Attachment Page' ),\n\t\t\t\turl: mediaType === 'image' ? mediaLink : undefined,\n\t\t\t\ticon: (\n\t\t\t\t\t<SVG viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t\t\t\t\t<Path d=\"M0 0h24v24H0V0z\" fill=\"none\" />\n\t\t\t\t\t\t<Path d=\"M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z\" />\n\t\t\t\t\t</SVG>\n\t\t\t\t),\n\t\t\t} );\n\t\t}\n\t\treturn linkDestinations;\n\t};\n\n\tconst onSetHref = ( value ) => {\n\t\tconst linkDestinations = getLinkDestinations();\n\t\tlet linkDestinationInput;\n\t\tif ( ! value ) {\n\t\t\tlinkDestinationInput = LINK_DESTINATION_NONE;\n\t\t} else {\n\t\t\tlinkDestinationInput = (\n\t\t\t\tfind( linkDestinations, ( destination ) => {\n\t\t\t\t\treturn destination.url === value;\n\t\t\t\t} ) || { linkDestination: LINK_DESTINATION_CUSTOM }\n\t\t\t).linkDestination;\n\t\t}\n\t\tonChangeUrl( {\n\t\t\tlinkDestination: linkDestinationInput,\n\t\t\thref: value,\n\t\t} );\n\t};\n\n\tconst onSetNewTab = ( value ) => {\n\t\tconst updatedLinkTarget = getUpdatedLinkTargetSettings( value );\n\t\tonChangeUrl( updatedLinkTarget );\n\t};\n\n\tconst onSetLinkRel = ( value ) => {\n\t\tonChangeUrl( { rel: value } );\n\t};\n\n\tconst onSetLinkClass = ( value ) => {\n\t\tonChangeUrl( { linkClass: value } );\n\t};\n\n\tconst advancedOptions = (\n\t\t<>\n\t\t\t<ToggleControl\n\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\tonChange={ onSetNewTab }\n\t\t\t\tchecked={ linkTarget === '_blank' }\n\t\t\t/>\n\t\t\t<TextControl\n\t\t\t\tlabel={ __( 'Link Rel' ) }\n\t\t\t\tvalue={ rel ?? '' }\n\t\t\t\tonChange={ onSetLinkRel }\n\t\t\t/>\n\t\t\t<TextControl\n\t\t\t\tlabel={ __( 'Link CSS Class' ) }\n\t\t\t\tvalue={ linkClass || '' }\n\t\t\t\tonChange={ onSetLinkClass }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst linkEditorValue = urlInput !== null ? urlInput : url;\n\n\tconst urlLabel = (\n\t\tfind( getLinkDestinations(), [ 'linkDestination', linkDestination ] ) ||\n\t\t{}\n\t).title;\n\n\treturn (\n\t\t<>\n\t\t\t<ToolbarButton\n\t\t\t\ticon={ linkIcon }\n\t\t\t\tclassName=\"components-toolbar__control\"\n\t\t\t\tlabel={ url ? __( 'Edit link' ) : __( 'Insert link' ) }\n\t\t\t\taria-expanded={ isOpen }\n\t\t\t\tonClick={ openLinkUI }\n\t\t\t/>\n\t\t\t{ isOpen && (\n\t\t\t\t<URLPopover\n\t\t\t\t\tonFocusOutside={ onFocusOutside() }\n\t\t\t\t\tonClose={ closeLinkUI }\n\t\t\t\t\trenderSettings={ () => advancedOptions }\n\t\t\t\t\tadditionalControls={\n\t\t\t\t\t\t! linkEditorValue && (\n\t\t\t\t\t\t\t<NavigableMenu>\n\t\t\t\t\t\t\t\t{ map( getLinkDestinations(), ( link ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\tkey={ link.linkDestination }\n\t\t\t\t\t\t\t\t\t\ticon={ link.icon }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tsetUrlInput( null );\n\t\t\t\t\t\t\t\t\t\t\tonSetHref( link.url );\n\t\t\t\t\t\t\t\t\t\t\tstopEditLink();\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ link.title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ ( ! url || isEditingLink ) && (\n\t\t\t\t\t\t<URLPopover.LinkEditor\n\t\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__link-container-content\"\n\t\t\t\t\t\t\tvalue={ linkEditorValue }\n\t\t\t\t\t\t\tonChangeInputValue={ setUrlInput }\n\t\t\t\t\t\t\tonSubmit={ onSubmitLinkChange() }\n\t\t\t\t\t\t\tautocompleteRef={ autocompleteRef }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ url && ! isEditingLink && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<URLPopover.LinkViewer\n\t\t\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__link-container-content\"\n\t\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\t\tonEditLinkClick={ startEditLink }\n\t\t\t\t\t\t\t\turlLabel={ urlLabel }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ close }\n\t\t\t\t\t\t\t\tlabel={ __( 'Remove link' ) }\n\t\t\t\t\t\t\t\tonClick={ onLinkRemove }\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</URLPopover>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nexport { ImageURLInputUI as __experimentalImageURLInputUI };\n"]}
@@ -28,6 +28,14 @@ var _useArrowNav = _interopRequireDefault(require("./use-arrow-nav"));
28
28
 
29
29
  var _useSelectAll = _interopRequireDefault(require("./use-select-all"));
30
30
 
31
+ var _useDragSelection = _interopRequireDefault(require("./use-drag-selection"));
32
+
33
+ var _useSelectionObserver = _interopRequireDefault(require("./use-selection-observer"));
34
+
35
+ var _useClickSelection = _interopRequireDefault(require("./use-click-selection"));
36
+
37
+ var _useInput = _interopRequireDefault(require("./use-input"));
38
+
31
39
  var _store = require("../../store");
32
40
 
33
41
  /**
@@ -44,7 +52,7 @@ var _store = require("../../store");
44
52
  function useWritingFlow() {
45
53
  const [before, ref, after] = (0, _useTabNav.default)();
46
54
  const hasMultiSelection = (0, _data.useSelect)(select => select(_store.store).hasMultiSelection(), []);
47
- return [before, (0, _compose.useMergeRefs)([ref, (0, _useMultiSelection.default)(), (0, _useSelectAll.default)(), (0, _useArrowNav.default)(), (0, _compose.useRefEffect)(node => {
55
+ return [before, (0, _compose.useMergeRefs)([ref, (0, _useInput.default)(), (0, _useDragSelection.default)(), (0, _useSelectionObserver.default)(), (0, _useClickSelection.default)(), (0, _useMultiSelection.default)(), (0, _useSelectAll.default)(), (0, _useArrowNav.default)(), (0, _compose.useRefEffect)(node => {
48
56
  node.tabIndex = -1;
49
57
  node.contentEditable = hasMultiSelection;
50
58
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["useWritingFlow","before","ref","after","hasMultiSelection","select","blockEditorStore","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAOO,SAASA,cAAT,GAA0B;AAChC,QAAM,CAAEC,MAAF,EAAUC,GAAV,EAAeC,KAAf,IAAyB,yBAA/B;AACA,QAAMC,iBAAiB,GAAG,qBACvBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAA2BF,iBAA3B,EADW,EAEzB,EAFyB,CAA1B;AAKA,SAAO,CACNH,MADM,EAEN,2BAAc,CACbC,GADa,EAEb,iCAFa,EAGb,4BAHa,EAIb,2BAJa,EAKb,2BACGK,IAAF,IAAY;AACXA,IAAAA,IAAI,CAACC,QAAL,GAAgB,CAAC,CAAjB;AACAD,IAAAA,IAAI,CAACE,eAAL,GAAuBL,iBAAvB;;AAEA,QAAK,CAAEA,iBAAP,EAA2B;AAC1B;AACA;;AAEDG,IAAAA,IAAI,CAACG,YAAL,CACC,YADD,EAEC,cAAI,0BAAJ,CAFD;AAKA,WAAO,MAAM;AACZH,MAAAA,IAAI,CAACI,eAAL,CAAsB,YAAtB;AACA,KAFD;AAGA,GAjBF,EAkBC,CAAEP,iBAAF,CAlBD,CALa,CAAd,CAFM,EA4BND,KA5BM,CAAP;AA8BA;;AAED,SAASS,WAAT,OAA8CC,YAA9C,EAA6D;AAAA,MAAvC;AAAEC,IAAAA,QAAF;AAAY,OAAGC;AAAf,GAAuC;AAC5D,QAAM,CAAEd,MAAF,EAAUC,GAAV,EAAeC,KAAf,IAAyBH,cAAc,EAA7C;AACA,SACC,qDACGC,MADH,EAEC,8DACMc,KADN;AAEC,IAAA,GAAG,EAAG,2BAAc,CAAEb,GAAF,EAAOW,YAAP,CAAd,CAFP;AAGC,IAAA,SAAS,EAAG,yBACXE,KAAK,CAACC,SADK,EAEX,2BAFW;AAHb,MAQGF,QARH,CAFD,EAYGX,KAZH,CADD;AAgBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;eACe,yBAAYS,WAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classNames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMultiSelection from './use-multi-selection';\nimport useTabNav from './use-tab-nav';\nimport useArrowNav from './use-arrow-nav';\nimport useSelectAll from './use-select-all';\nimport { store as blockEditorStore } from '../../store';\n\nexport function useWritingFlow() {\n\tconst [ before, ref, after ] = useTabNav();\n\tconst hasMultiSelection = useSelect(\n\t\t( select ) => select( blockEditorStore ).hasMultiSelection(),\n\t\t[]\n\t);\n\n\treturn [\n\t\tbefore,\n\t\tuseMergeRefs( [\n\t\t\tref,\n\t\t\tuseMultiSelection(),\n\t\t\tuseSelectAll(),\n\t\t\tuseArrowNav(),\n\t\t\tuseRefEffect(\n\t\t\t\t( node ) => {\n\t\t\t\t\tnode.tabIndex = -1;\n\t\t\t\t\tnode.contentEditable = hasMultiSelection;\n\n\t\t\t\t\tif ( ! hasMultiSelection ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tnode.setAttribute(\n\t\t\t\t\t\t'aria-label',\n\t\t\t\t\t\t__( 'Multiple selected blocks' )\n\t\t\t\t\t);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tnode.removeAttribute( 'aria-label' );\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ hasMultiSelection ]\n\t\t\t),\n\t\t] ),\n\t\tafter,\n\t];\n}\n\nfunction WritingFlow( { children, ...props }, forwardedRef ) {\n\tconst [ before, ref, after ] = useWritingFlow();\n\treturn (\n\t\t<>\n\t\t\t{ before }\n\t\t\t<div\n\t\t\t\t{ ...props }\n\t\t\t\tref={ useMergeRefs( [ ref, forwardedRef ] ) }\n\t\t\t\tclassName={ classNames(\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'block-editor-writing-flow'\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t\t{ after }\n\t\t</>\n\t);\n}\n\n/**\n * Handles selection and navigation across blocks. This component should be\n * wrapped around BlockList.\n *\n * @param {Object} props Component properties.\n * @param {WPElement} props.children Children to be rendered.\n */\nexport default forwardRef( WritingFlow );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["useWritingFlow","before","ref","after","hasMultiSelection","select","blockEditorStore","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAxBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAWO,SAASA,cAAT,GAA0B;AAChC,QAAM,CAAEC,MAAF,EAAUC,GAAV,EAAeC,KAAf,IAAyB,yBAA/B;AACA,QAAMC,iBAAiB,GAAG,qBACvBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAA2BF,iBAA3B,EADW,EAEzB,EAFyB,CAA1B;AAKA,SAAO,CACNH,MADM,EAEN,2BAAc,CACbC,GADa,EAEb,wBAFa,EAGb,gCAHa,EAIb,oCAJa,EAKb,iCALa,EAMb,iCANa,EAOb,4BAPa,EAQb,2BARa,EASb,2BACGK,IAAF,IAAY;AACXA,IAAAA,IAAI,CAACC,QAAL,GAAgB,CAAC,CAAjB;AACAD,IAAAA,IAAI,CAACE,eAAL,GAAuBL,iBAAvB;;AAEA,QAAK,CAAEA,iBAAP,EAA2B;AAC1B;AACA;;AAEDG,IAAAA,IAAI,CAACG,YAAL,CACC,YADD,EAEC,cAAI,0BAAJ,CAFD;AAKA,WAAO,MAAM;AACZH,MAAAA,IAAI,CAACI,eAAL,CAAsB,YAAtB;AACA,KAFD;AAGA,GAjBF,EAkBC,CAAEP,iBAAF,CAlBD,CATa,CAAd,CAFM,EAgCND,KAhCM,CAAP;AAkCA;;AAED,SAASS,WAAT,OAA8CC,YAA9C,EAA6D;AAAA,MAAvC;AAAEC,IAAAA,QAAF;AAAY,OAAGC;AAAf,GAAuC;AAC5D,QAAM,CAAEd,MAAF,EAAUC,GAAV,EAAeC,KAAf,IAAyBH,cAAc,EAA7C;AACA,SACC,qDACGC,MADH,EAEC,8DACMc,KADN;AAEC,IAAA,GAAG,EAAG,2BAAc,CAAEb,GAAF,EAAOW,YAAP,CAAd,CAFP;AAGC,IAAA,SAAS,EAAG,yBACXE,KAAK,CAACC,SADK,EAEX,2BAFW;AAHb,MAQGF,QARH,CAFD,EAYGX,KAZH,CADD;AAgBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;eACe,yBAAYS,WAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classNames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMultiSelection from './use-multi-selection';\nimport useTabNav from './use-tab-nav';\nimport useArrowNav from './use-arrow-nav';\nimport useSelectAll from './use-select-all';\nimport useDragSelection from './use-drag-selection';\nimport useSelectionObserver from './use-selection-observer';\nimport useClickSelection from './use-click-selection';\nimport useInput from './use-input';\nimport { store as blockEditorStore } from '../../store';\n\nexport function useWritingFlow() {\n\tconst [ before, ref, after ] = useTabNav();\n\tconst hasMultiSelection = useSelect(\n\t\t( select ) => select( blockEditorStore ).hasMultiSelection(),\n\t\t[]\n\t);\n\n\treturn [\n\t\tbefore,\n\t\tuseMergeRefs( [\n\t\t\tref,\n\t\t\tuseInput(),\n\t\t\tuseDragSelection(),\n\t\t\tuseSelectionObserver(),\n\t\t\tuseClickSelection(),\n\t\t\tuseMultiSelection(),\n\t\t\tuseSelectAll(),\n\t\t\tuseArrowNav(),\n\t\t\tuseRefEffect(\n\t\t\t\t( node ) => {\n\t\t\t\t\tnode.tabIndex = -1;\n\t\t\t\t\tnode.contentEditable = hasMultiSelection;\n\n\t\t\t\t\tif ( ! hasMultiSelection ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tnode.setAttribute(\n\t\t\t\t\t\t'aria-label',\n\t\t\t\t\t\t__( 'Multiple selected blocks' )\n\t\t\t\t\t);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tnode.removeAttribute( 'aria-label' );\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ hasMultiSelection ]\n\t\t\t),\n\t\t] ),\n\t\tafter,\n\t];\n}\n\nfunction WritingFlow( { children, ...props }, forwardedRef ) {\n\tconst [ before, ref, after ] = useWritingFlow();\n\treturn (\n\t\t<>\n\t\t\t{ before }\n\t\t\t<div\n\t\t\t\t{ ...props }\n\t\t\t\tref={ useMergeRefs( [ ref, forwardedRef ] ) }\n\t\t\t\tclassName={ classNames(\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'block-editor-writing-flow'\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t\t{ after }\n\t\t</>\n\t);\n}\n\n/**\n * Handles selection and navigation across blocks. This component should be\n * wrapped around BlockList.\n *\n * @param {Object} props Component properties.\n * @param {WPElement} props.children Children to be rendered.\n */\nexport default forwardRef( WritingFlow );\n"]}
@@ -119,19 +119,12 @@ function getClosestTabbable(target, isReverse, containerElement, onlyVertical) {
119
119
  function useArrowNav() {
120
120
  const {
121
121
  getSelectedBlockClientId,
122
- getMultiSelectedBlocksStartClientId,
123
122
  getMultiSelectedBlocksEndClientId,
124
123
  getPreviousBlockClientId,
125
124
  getNextBlockClientId,
126
- getFirstMultiSelectedBlockClientId,
127
- getLastMultiSelectedBlockClientId,
128
125
  getSettings,
129
126
  hasMultiSelection
130
127
  } = (0, _data.useSelect)(_store.store);
131
- const {
132
- multiSelect,
133
- selectBlock
134
- } = (0, _data.useDispatch)(_store.store);
135
128
  return (0, _compose.useRefEffect)(node => {
136
129
  // Here a DOMRect is stored while moving the caret vertically so
137
130
  // vertical position of the start position can be restored. This is to
@@ -141,33 +134,6 @@ function useArrowNav() {
141
134
  function onMouseDown() {
142
135
  verticalRect = null;
143
136
  }
144
-
145
- function expandSelection(isReverse) {
146
- const selectedBlockClientId = getSelectedBlockClientId();
147
- const selectionStartClientId = getMultiSelectedBlocksStartClientId();
148
- const selectionEndClientId = getMultiSelectedBlocksEndClientId();
149
- const selectionBeforeEndClientId = getPreviousBlockClientId(selectionEndClientId || selectedBlockClientId);
150
- const selectionAfterEndClientId = getNextBlockClientId(selectionEndClientId || selectedBlockClientId);
151
- const nextSelectionEndClientId = isReverse ? selectionBeforeEndClientId : selectionAfterEndClientId;
152
-
153
- if (nextSelectionEndClientId) {
154
- if (selectionStartClientId === nextSelectionEndClientId) {
155
- selectBlock(nextSelectionEndClientId);
156
- } else {
157
- multiSelect(selectionStartClientId || selectedBlockClientId, nextSelectionEndClientId);
158
- }
159
- }
160
- }
161
-
162
- function moveSelection(isReverse) {
163
- const selectedFirstClientId = getFirstMultiSelectedBlockClientId();
164
- const selectedLastClientId = getLastMultiSelectedBlockClientId();
165
- const focusedBlockClientId = isReverse ? selectedFirstClientId : selectedLastClientId;
166
-
167
- if (focusedBlockClientId) {
168
- selectBlock(focusedBlockClientId);
169
- }
170
- }
171
137
  /**
172
138
  * Returns true if the given target field is the last in its block which
173
139
  * can be considered for tab transition. For example, in a block with
@@ -210,12 +176,6 @@ function useArrowNav() {
210
176
  } = ownerDocument;
211
177
 
212
178
  if (hasMultiSelection()) {
213
- if (isNav) {
214
- const action = isShift ? expandSelection : moveSelection;
215
- action(isReverse);
216
- event.preventDefault();
217
- }
218
-
219
179
  return;
220
180
  } // When presing any key other than up or down, the initial vertical
221
181
  // position must ALWAYS be reset. The vertical position is saved so
@@ -263,10 +223,9 @@ function useArrowNav() {
263
223
 
264
224
  if ( // Ensure that there is a target block.
265
225
  (isReverse && selectionBeforeEndClientId || !isReverse && selectionAfterEndClientId) && isTabbableEdge(target, isReverse) && isNavEdge(target, isReverse)) {
266
- // Shift key is down, and there is multi selection or we're
267
- // at the end of the current block.
268
- expandSelection(isReverse);
269
- event.preventDefault();
226
+ node.contentEditable = true; // Firefox doesn't automatically move focus.
227
+
228
+ node.focus();
270
229
  }
271
230
  } else if (isVertical && (0, _dom.isVerticalEdge)(target, isReverse) && !keepCaretInsideBlock) {
272
231
  const closestTabbable = getClosestTabbable(target, isReverse, node, true);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["isNavigationCandidate","element","keyCode","hasModifier","isVertical","UP","DOWN","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focus","focusable","find","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getFirstMultiSelectedBlockClientId","getLastMultiSelectedBlockClientId","getSettings","hasMultiSelection","blockEditorStore","multiSelect","selectBlock","verticalRect","onMouseDown","expandSelection","selectedBlockClientId","selectionStartClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","nextSelectionEndClientId","moveSelection","selectedFirstClientId","selectedLastClientId","focusedBlockClientId","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","LEFT","isRight","RIGHT","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","isVerticalEdge","isHorizontalEdge","ownerDocument","defaultView","action","preventDefault","defaultPrevented","isReverseDir","keepCaretInsideBlock","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AAKA;;AASA;;AACA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WA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HD;AAIA,GAnMM,EAmMJ,EAnMI,CAAP;AAoMA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, reverse } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally.\n\tconst { tagName } = element;\n\treturn tagName !== 'INPUT' && tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes = reverse( focusableNodes );\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn find( focusableNodes, isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetFirstMultiSelectedBlockClientId,\n\t\tgetLastMultiSelectedBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\tfunction expandSelection( isReverse ) {\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst selectionStartClientId = getMultiSelectedBlocksStartClientId();\n\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t);\n\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t);\n\t\t\tconst nextSelectionEndClientId = isReverse\n\t\t\t\t? selectionBeforeEndClientId\n\t\t\t\t: selectionAfterEndClientId;\n\n\t\t\tif ( nextSelectionEndClientId ) {\n\t\t\t\tif ( selectionStartClientId === nextSelectionEndClientId ) {\n\t\t\t\t\tselectBlock( nextSelectionEndClientId );\n\t\t\t\t} else {\n\t\t\t\t\tmultiSelect(\n\t\t\t\t\t\tselectionStartClientId || selectedBlockClientId,\n\t\t\t\t\t\tnextSelectionEndClientId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction moveSelection( isReverse ) {\n\t\t\tconst selectedFirstClientId = getFirstMultiSelectedBlockClientId();\n\t\t\tconst selectedLastClientId = getLastMultiSelectedBlockClientId();\n\t\t\tconst focusedBlockClientId = isReverse\n\t\t\t\t? selectedFirstClientId\n\t\t\t\t: selectedLastClientId;\n\n\t\t\tif ( focusedBlockClientId ) {\n\t\t\t\tselectBlock( focusedBlockClientId );\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\tif ( isNav ) {\n\t\t\t\t\tconst action = isShift ? expandSelection : moveSelection;\n\t\t\t\t\taction( isReverse );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\t// Shift key is down, and there is multi selection or we're\n\t\t\t\t\t// at the end of the current block.\n\t\t\t\t\texpandSelection( isReverse );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["isNavigationCandidate","element","keyCode","hasModifier","isVertical","UP","DOWN","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focus","focusable","find","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getSettings","hasMultiSelection","blockEditorStore","verticalRect","onMouseDown","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","LEFT","isRight","RIGHT","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","isVerticalEdge","isHorizontalEdge","ownerDocument","defaultView","defaultPrevented","isReverseDir","keepCaretInsideBlock","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","preventDefault","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AAKA;;AASA;;AACA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WAAlD,EAAgE;AACtE,QAAMC,UAAU,GAAGF,OAAO,KAAKG,YAAZ,IAAkBH,OAAO,KAAKI,cAAjD,CADsE,CAGtE;;AACA,MAAKF,UAAU,IAAI,CAAED,WAArB,EAAmC;AAClC,WAAO,IAAP;AACA,GANqE,CAQtE;;;AACA,QAAM;AAAEI,IAAAA;AAAF,MAAcN,OAApB;AACA,SAAOM,OAAO,KAAK,OAAZ,IAAuBA,OAAO,KAAK,UAA1C;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,kBAAT,CACNC,MADM,EAENC,SAFM,EAGNC,gBAHM,EAINC,YAJM,EAKL;AACD;AACA;AACA,MAAIC,cAAc,GAAGC,WAAMC,SAAN,CAAgBC,IAAhB,CAAsBL,gBAAtB,CAArB;;AAEA,MAAKD,SAAL,EAAiB;AAChBG,IAAAA,cAAc,GAAG,qBAASA,cAAT,CAAjB;AACA,GAPA,CASD;AACA;AACA;;;AACAA,EAAAA,cAAc,GAAGA,cAAc,CAACI,KAAf,CAChBJ,cAAc,CAACK,OAAf,CAAwBT,MAAxB,IAAmC,CADnB,CAAjB;AAIA,MAAIU,UAAJ;;AAEA,MAAKP,YAAL,EAAoB;AACnBO,IAAAA,UAAU,GAAGV,MAAM,CAACW,qBAAP,EAAb;AACA;;AAED,WAASC,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AEzCsD,YAFyC,EAGzCzC,IAHyC,CAA1C;AAKA,6CAA4BmB,eAA5B,EAA6C/B,SAA7C;AACAiC,QAAAA,KAAK,CAAC0B,cAAN;AACA;AACD;;AAED/C,IAAAA,IAAI,CAACkD,gBAAL,CAAuB,WAAvB,EAAoCjC,WAApC;AACAjB,IAAAA,IAAI,CAACkD,gBAAL,CAAuB,SAAvB,EAAkC9B,SAAlC;AACA,WAAO,MAAM;AACZpB,MAAAA,IAAI,CAACmD,mBAAL,CAA0B,WAA1B,EAAuClC,WAAvC;AACAjB,MAAAA,IAAI,CAACmD,mBAAL,CAA0B,SAA1B,EAAqC/B,SAArC;AACA,KAHD;AAIA,GAtJM,EAsJJ,EAtJI,CAAP;AAuJA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, reverse } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally.\n\tconst { tagName } = element;\n\treturn tagName !== 'INPUT' && tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes = reverse( focusableNodes );\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn find( focusableNodes, isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useClickSelection;
7
+
8
+ var _data = require("@wordpress/data");
9
+
10
+ var _compose = require("@wordpress/compose");
11
+
12
+ var _store = require("../../store");
13
+
14
+ var _dom = require("../../utils/dom");
15
+
16
+ /**
17
+ * WordPress dependencies
18
+ */
19
+
20
+ /**
21
+ * Internal dependencies
22
+ */
23
+ function useClickSelection() {
24
+ const {
25
+ multiSelect,
26
+ selectBlock
27
+ } = (0, _data.useDispatch)(_store.store);
28
+ const {
29
+ isSelectionEnabled,
30
+ getBlockParents,
31
+ getBlockSelectionStart,
32
+ hasMultiSelection
33
+ } = (0, _data.useSelect)(_store.store);
34
+ return (0, _compose.useRefEffect)(node => {
35
+ function onMouseDown(event) {
36
+ // The main button.
37
+ // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
38
+ if (!isSelectionEnabled() || event.button !== 0) {
39
+ return;
40
+ }
41
+
42
+ const startClientId = getBlockSelectionStart();
43
+ const clickedClientId = (0, _dom.getBlockClientId)(event.target);
44
+
45
+ if (event.shiftKey) {
46
+ if (startClientId !== clickedClientId) {
47
+ node.contentEditable = true; // Firefox doesn't automatically move focus.
48
+
49
+ node.focus();
50
+ }
51
+ } else if (hasMultiSelection()) {
52
+ // Allow user to escape out of a multi-selection to a
53
+ // singular selection of a block via click. This is handled
54
+ // here since focus handling excludes blocks when there is
55
+ // multiselection, as focus can be incurred by starting a
56
+ // multiselection (focus moved to first block's multi-
57
+ // controls).
58
+ selectBlock(clickedClientId);
59
+ }
60
+ }
61
+
62
+ node.addEventListener('mousedown', onMouseDown);
63
+ return () => {
64
+ node.removeEventListener('mousedown', onMouseDown);
65
+ };
66
+ }, [multiSelect, selectBlock, isSelectionEnabled, getBlockParents, getBlockSelectionStart, hasMultiSelection]);
67
+ }
68
+ //# sourceMappingURL=use-click-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-click-selection.js"],"names":["useClickSelection","multiSelect","selectBlock","blockEditorStore","isSelectionEnabled","getBlockParents","getBlockSelectionStart","hasMultiSelection","node","onMouseDown","event","button","startClientId","clickedClientId","target","shiftKey","contentEditable","focus","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAIe,SAASA,iBAAT,GAA6B;AAC3C,QAAM;AAAEC,IAAAA,WAAF;AAAeC,IAAAA;AAAf,MAA+B,uBAAaC,YAAb,CAArC;AACA,QAAM;AACLC,IAAAA,kBADK;AAELC,IAAAA,eAFK;AAGLC,IAAAA,sBAHK;AAILC,IAAAA;AAJK,MAKF,qBAAWJ,YAAX,CALJ;AAMA,SAAO,2BACJK,IAAF,IAAY;AACX,aAASC,WAAT,CAAsBC,KAAtB,EAA8B;AAC7B;AACA;AACA,UAAK,CAAEN,kBAAkB,EAApB,IAA0BM,KAAK,CAACC,MAAN,KAAiB,CAAhD,EAAoD;AACnD;AACA;;AAED,YAAMC,aAAa,GAAGN,sBAAsB,EAA5C;AACA,YAAMO,eAAe,GAAG,2BAAkBH,KAAK,CAACI,MAAxB,CAAxB;;AAEA,UAAKJ,KAAK,CAACK,QAAX,EAAsB;AACrB,YAAKH,aAAa,KAAKC,eAAvB,EAAyC;AACxCL,UAAAA,IAAI,CAACQ,eAAL,GAAuB,IAAvB,CADwC,CAExC;;AACAR,UAAAA,IAAI,CAACS,KAAL;AACA;AACD,OAND,MAMO,IAAKV,iBAAiB,EAAtB,EAA2B;AACjC;AACA;AACA;AACA;AACA;AACA;AACAL,QAAAA,WAAW,CAAEW,eAAF,CAAX;AACA;AACD;;AAEDL,IAAAA,IAAI,CAACU,gBAAL,CAAuB,WAAvB,EAAoCT,WAApC;AAEA,WAAO,MAAM;AACZD,MAAAA,IAAI,CAACW,mBAAL,CAA0B,WAA1B,EAAuCV,WAAvC;AACA,KAFD;AAGA,GAlCK,EAmCN,CACCR,WADD,EAECC,WAFD,EAGCE,kBAHD,EAICC,eAJD,EAKCC,sBALD,EAMCC,iBAND,CAnCM,CAAP;AA4CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId } from '../../utils/dom';\n\nexport default function useClickSelection() {\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\tconst {\n\t\tisSelectionEnabled,\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tfunction onMouseDown( event ) {\n\t\t\t\t// The main button.\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button\n\t\t\t\tif ( ! isSelectionEnabled() || event.button !== 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst startClientId = getBlockSelectionStart();\n\t\t\t\tconst clickedClientId = getBlockClientId( event.target );\n\n\t\t\t\tif ( event.shiftKey ) {\n\t\t\t\t\tif ( startClientId !== clickedClientId ) {\n\t\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\t\tnode.focus();\n\t\t\t\t\t}\n\t\t\t\t} else if ( hasMultiSelection() ) {\n\t\t\t\t\t// Allow user to escape out of a multi-selection to a\n\t\t\t\t\t// singular selection of a block via click. This is handled\n\t\t\t\t\t// here since focus handling excludes blocks when there is\n\t\t\t\t\t// multiselection, as focus can be incurred by starting a\n\t\t\t\t\t// multiselection (focus moved to first block's multi-\n\t\t\t\t\t// controls).\n\t\t\t\t\tselectBlock( clickedClientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tmultiSelect,\n\t\t\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tgetBlockParents,\n\t\t\tgetBlockSelectionStart,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"]}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useDragSelection;
7
+
8
+ var _data = require("@wordpress/data");
9
+
10
+ var _compose = require("@wordpress/compose");
11
+
12
+ var _store = require("../../store");
13
+
14
+ /**
15
+ * WordPress dependencies
16
+ */
17
+
18
+ /**
19
+ * Internal dependencies
20
+ */
21
+
22
+ /**
23
+ * Sets the `contenteditable` wrapper element to `value`.
24
+ *
25
+ * @param {HTMLElement} node Block element.
26
+ * @param {boolean} value `contentEditable` value (true or false)
27
+ */
28
+ function setContentEditableWrapper(node, value) {
29
+ node.contentEditable = value; // Firefox doesn't automatically move focus.
30
+
31
+ if (value) node.focus();
32
+ }
33
+ /**
34
+ * Sets a multi-selection based on the native selection across blocks.
35
+ */
36
+
37
+
38
+ function useDragSelection() {
39
+ const {
40
+ startMultiSelect,
41
+ stopMultiSelect
42
+ } = (0, _data.useDispatch)(_store.store);
43
+ const {
44
+ isSelectionEnabled,
45
+ hasMultiSelection
46
+ } = (0, _data.useSelect)(_store.store);
47
+ return (0, _compose.useRefEffect)(node => {
48
+ const {
49
+ ownerDocument
50
+ } = node;
51
+ const {
52
+ defaultView
53
+ } = ownerDocument;
54
+ let anchorElement;
55
+ let rafId;
56
+
57
+ function onMouseUp() {
58
+ stopMultiSelect(); // Equivalent to attaching the listener once.
59
+
60
+ defaultView.removeEventListener('mouseup', onMouseUp); // The browser selection won't have updated yet at this point,
61
+ // so wait until the next animation frame to get the browser
62
+ // selection.
63
+
64
+ rafId = defaultView.requestAnimationFrame(() => {
65
+ if (hasMultiSelection()) {
66
+ return;
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
+
73
+
74
+ setContentEditableWrapper(node, false);
75
+ const selection = defaultView.getSelection();
76
+
77
+ if (selection.rangeCount) {
78
+ const {
79
+ commonAncestorContainer
80
+ } = selection.getRangeAt(0);
81
+
82
+ if (anchorElement.contains(commonAncestorContainer)) {
83
+ anchorElement.focus();
84
+ }
85
+ }
86
+ });
87
+ }
88
+
89
+ function onMouseLeave(_ref) {
90
+ let {
91
+ buttons,
92
+ target
93
+ } = _ref;
94
+
95
+ // The primary button must be pressed to initiate selection.
96
+ // See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
97
+ if (buttons !== 1) {
98
+ return;
99
+ } // Check the attribute, not the contentEditable attribute. All
100
+ // child elements of the content editable wrapper are editable
101
+ // and return true for this property. We only want to start
102
+ // multi selecting when the mouse leaves the wrapper.
103
+
104
+
105
+ if (!target.getAttribute('contenteditable')) {
106
+ return;
107
+ }
108
+
109
+ if (!isSelectionEnabled()) {
110
+ return;
111
+ }
112
+
113
+ anchorElement = ownerDocument.activeElement;
114
+ startMultiSelect(); // `onSelectionStart` is called after `mousedown` and
115
+ // `mouseleave` (from a block). The selection ends when
116
+ // `mouseup` happens anywhere in the window.
117
+
118
+ defaultView.addEventListener('mouseup', onMouseUp); // Allow cross contentEditable selection by temporarily making
119
+ // all content editable. We can't rely on using the store and
120
+ // React because re-rending happens too slowly. We need to be
121
+ // able to select across instances immediately.
122
+
123
+ setContentEditableWrapper(node, true);
124
+ }
125
+
126
+ node.addEventListener('mouseout', onMouseLeave);
127
+ return () => {
128
+ node.removeEventListener('mouseout', onMouseLeave);
129
+ defaultView.removeEventListener('mouseup', onMouseUp);
130
+ defaultView.cancelAnimationFrame(rafId);
131
+ };
132
+ }, [startMultiSelect, stopMultiSelect, isSelectionEnabled, hasMultiSelection]);
133
+ }
134
+ //# sourceMappingURL=use-drag-selection.js.map