@wordpress/block-editor 16.0.0 → 16.1.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 (368) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +8 -0
  3. package/build/components/alignment-control/ui.cjs +2 -4
  4. package/build/components/alignment-control/ui.cjs.map +2 -2
  5. package/build/components/background-image-control/index.cjs +40 -10
  6. package/build/components/background-image-control/index.cjs.map +2 -2
  7. package/build/components/block-alignment-control/ui.cjs +5 -3
  8. package/build/components/block-alignment-control/ui.cjs.map +2 -2
  9. package/build/components/block-inspector/index.cjs +73 -46
  10. package/build/components/block-inspector/index.cjs.map +2 -2
  11. package/build/components/block-list/block-html.cjs +4 -1
  12. package/build/components/block-list/block-html.cjs.map +2 -2
  13. package/build/components/block-list/use-block-props/index.cjs +5 -2
  14. package/build/components/block-list/use-block-props/index.cjs.map +2 -2
  15. package/build/components/block-list/use-block-props/use-focus-handler.cjs +2 -3
  16. package/build/components/block-list/use-block-props/use-focus-handler.cjs.map +2 -2
  17. package/build/components/block-list/use-block-props/use-register-block-event-handlers.cjs +48 -0
  18. package/build/components/block-list/use-block-props/use-register-block-event-handlers.cjs.map +7 -0
  19. package/build/components/block-parent-selector/index.cjs +2 -2
  20. package/build/components/block-parent-selector/index.cjs.map +2 -2
  21. package/build/components/block-toolbar/switch-section-style.cjs +4 -2
  22. package/build/components/block-toolbar/switch-section-style.cjs.map +3 -3
  23. package/build/components/block-tools/empty-block-inserter.cjs +2 -7
  24. package/build/components/block-tools/empty-block-inserter.cjs.map +2 -2
  25. package/build/components/block-vertical-alignment-control/ui.cjs +3 -5
  26. package/build/components/block-vertical-alignment-control/ui.cjs.map +2 -2
  27. package/build/components/border-radius-control/utils.cjs +8 -58
  28. package/build/components/border-radius-control/utils.cjs.map +2 -2
  29. package/build/components/colors-gradients/control.cjs +5 -3
  30. package/build/components/colors-gradients/control.cjs.map +2 -2
  31. package/build/components/dimension-control/index.cjs +30 -20
  32. package/build/components/dimension-control/index.cjs.map +3 -3
  33. package/build/components/dimensions-tool/aspect-ratio-tool.cjs +9 -2
  34. package/build/components/dimensions-tool/aspect-ratio-tool.cjs.map +3 -3
  35. package/build/components/editor-styles/index.cjs +9 -1
  36. package/build/components/editor-styles/index.cjs.map +2 -2
  37. package/build/components/global-styles/background-panel.cjs +66 -25
  38. package/build/components/global-styles/background-panel.cjs.map +3 -3
  39. package/build/components/global-styles/border-panel.cjs +153 -55
  40. package/build/components/global-styles/border-panel.cjs.map +3 -3
  41. package/build/components/global-styles/color-gradient-dropdown-item.cjs +46 -14
  42. package/build/components/global-styles/color-gradient-dropdown-item.cjs.map +3 -3
  43. package/build/components/global-styles/color-panel.cjs +63 -17
  44. package/build/components/global-styles/color-panel.cjs.map +2 -2
  45. package/build/components/global-styles/dimensions-panel.cjs +242 -64
  46. package/build/components/global-styles/dimensions-panel.cjs.map +3 -3
  47. package/build/components/global-styles/filters-panel.cjs +59 -20
  48. package/build/components/global-styles/filters-panel.cjs.map +3 -3
  49. package/build/components/global-styles/hooks.cjs +4 -1
  50. package/build/components/global-styles/hooks.cjs.map +2 -2
  51. package/build/components/global-styles/inheritance/index.cjs +142 -0
  52. package/build/components/global-styles/inheritance/index.cjs.map +7 -0
  53. package/build/components/global-styles/inherited-value-context.cjs +173 -0
  54. package/build/components/global-styles/inherited-value-context.cjs.map +7 -0
  55. package/build/components/global-styles/shadow-panel-components.cjs +38 -20
  56. package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
  57. package/build/components/global-styles/state-control.cjs +1 -1
  58. package/build/components/global-styles/state-control.cjs.map +2 -2
  59. package/build/components/global-styles/typography-panel.cjs +271 -78
  60. package/build/components/global-styles/typography-panel.cjs.map +3 -3
  61. package/build/components/inspector-controls-tabs/styles-tab.cjs +10 -1
  62. package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
  63. package/build/components/line-height-control/index.cjs +1 -1
  64. package/build/components/line-height-control/index.cjs.map +2 -2
  65. package/build/components/link-control/index.cjs +3 -1
  66. package/build/components/link-control/index.cjs.map +2 -2
  67. package/build/components/preset-input-control/index.cjs +2 -1
  68. package/build/components/preset-input-control/index.cjs.map +2 -2
  69. package/build/components/provider/block-refs-provider.cjs +8 -2
  70. package/build/components/provider/block-refs-provider.cjs.map +2 -2
  71. package/build/components/provider/index.cjs +1 -1
  72. package/build/components/provider/index.cjs.map +2 -2
  73. package/build/components/provider/use-block-sync.cjs +18 -6
  74. package/build/components/provider/use-block-sync.cjs.map +2 -2
  75. package/build/components/provider/use-media-upload-settings.cjs +3 -1
  76. package/build/components/provider/use-media-upload-settings.cjs.map +2 -2
  77. package/build/components/rich-text/index.cjs +23 -13
  78. package/build/components/rich-text/index.cjs.map +2 -2
  79. package/build/components/spacing-sizes-control/utils.cjs +6 -19
  80. package/build/components/spacing-sizes-control/utils.cjs.map +2 -2
  81. package/build/components/text-indent-control/index.cjs +8 -2
  82. package/build/components/text-indent-control/index.cjs.map +2 -2
  83. package/build/components/url-input/index.cjs +303 -344
  84. package/build/components/url-input/index.cjs.map +3 -3
  85. package/build/components/writing-flow/index.cjs +2 -0
  86. package/build/components/writing-flow/index.cjs.map +3 -3
  87. package/build/components/writing-flow/use-arrow-nav.cjs +24 -1
  88. package/build/components/writing-flow/use-arrow-nav.cjs.map +2 -2
  89. package/build/components/writing-flow/use-click-selection.cjs +28 -2
  90. package/build/components/writing-flow/use-click-selection.cjs.map +2 -2
  91. package/build/components/writing-flow/use-editable-root-event-handlers.cjs +179 -0
  92. package/build/components/writing-flow/use-editable-root-event-handlers.cjs.map +7 -0
  93. package/build/components/writing-flow/use-editable-root.cjs +5 -42
  94. package/build/components/writing-flow/use-editable-root.cjs.map +2 -2
  95. package/build/components/writing-flow/use-home-end.cjs +1 -1
  96. package/build/components/writing-flow/use-home-end.cjs.map +2 -2
  97. package/build/components/writing-flow/use-selection-observer.cjs +17 -13
  98. package/build/components/writing-flow/use-selection-observer.cjs.map +2 -2
  99. package/build/components/writing-flow/utils.cjs +3 -14
  100. package/build/components/writing-flow/utils.cjs.map +2 -2
  101. package/build/hooks/background.cjs +13 -10
  102. package/build/hooks/background.cjs.map +2 -2
  103. package/build/hooks/block-style-variation.cjs +4 -45
  104. package/build/hooks/block-style-variation.cjs.map +3 -3
  105. package/build/hooks/border.cjs +19 -4
  106. package/build/hooks/border.cjs.map +2 -2
  107. package/build/hooks/custom-css.cjs +6 -2
  108. package/build/hooks/custom-css.cjs.map +2 -2
  109. package/build/hooks/dimensions.cjs +15 -4
  110. package/build/hooks/dimensions.cjs.map +2 -2
  111. package/build/hooks/duotone.cjs +26 -14
  112. package/build/hooks/duotone.cjs.map +3 -3
  113. package/build/hooks/elements.cjs +14 -4
  114. package/build/hooks/elements.cjs.map +2 -2
  115. package/build/hooks/line-height.cjs +1 -2
  116. package/build/hooks/line-height.cjs.map +2 -2
  117. package/build/hooks/typography.cjs +13 -4
  118. package/build/hooks/typography.cjs.map +2 -2
  119. package/build/private-apis.cjs +9 -5
  120. package/build/private-apis.cjs.map +3 -3
  121. package/build/store/actions.cjs +9 -4
  122. package/build/store/actions.cjs.map +2 -2
  123. package/build/store/private-selectors.cjs +28 -1
  124. package/build/store/private-selectors.cjs.map +2 -2
  125. package/build/store/reducer.cjs +6 -6
  126. package/build/store/reducer.cjs.map +2 -2
  127. package/build/store/selectors.cjs +23 -0
  128. package/build/store/selectors.cjs.map +2 -2
  129. package/build/utils/native-undo.cjs +55 -0
  130. package/build/utils/native-undo.cjs.map +7 -0
  131. package/build-module/components/alignment-control/ui.mjs +2 -4
  132. package/build-module/components/alignment-control/ui.mjs.map +2 -2
  133. package/build-module/components/background-image-control/index.mjs +43 -10
  134. package/build-module/components/background-image-control/index.mjs.map +2 -2
  135. package/build-module/components/block-alignment-control/ui.mjs +5 -3
  136. package/build-module/components/block-alignment-control/ui.mjs.map +2 -2
  137. package/build-module/components/block-inspector/index.mjs +74 -46
  138. package/build-module/components/block-inspector/index.mjs.map +2 -2
  139. package/build-module/components/block-list/block-html.mjs +4 -1
  140. package/build-module/components/block-list/block-html.mjs.map +2 -2
  141. package/build-module/components/block-list/use-block-props/index.mjs +5 -2
  142. package/build-module/components/block-list/use-block-props/index.mjs.map +2 -2
  143. package/build-module/components/block-list/use-block-props/use-focus-handler.mjs +2 -3
  144. package/build-module/components/block-list/use-block-props/use-focus-handler.mjs.map +2 -2
  145. package/build-module/components/block-list/use-block-props/use-register-block-event-handlers.mjs +28 -0
  146. package/build-module/components/block-list/use-block-props/use-register-block-event-handlers.mjs.map +7 -0
  147. package/build-module/components/block-parent-selector/index.mjs +2 -2
  148. package/build-module/components/block-parent-selector/index.mjs.map +2 -2
  149. package/build-module/components/block-toolbar/switch-section-style.mjs +4 -2
  150. package/build-module/components/block-toolbar/switch-section-style.mjs.map +2 -2
  151. package/build-module/components/block-tools/empty-block-inserter.mjs +2 -7
  152. package/build-module/components/block-tools/empty-block-inserter.mjs.map +2 -2
  153. package/build-module/components/block-vertical-alignment-control/ui.mjs +4 -6
  154. package/build-module/components/block-vertical-alignment-control/ui.mjs.map +2 -2
  155. package/build-module/components/border-radius-control/utils.mjs +11 -53
  156. package/build-module/components/border-radius-control/utils.mjs.map +2 -2
  157. package/build-module/components/colors-gradients/control.mjs +5 -3
  158. package/build-module/components/colors-gradients/control.mjs.map +2 -2
  159. package/build-module/components/dimension-control/index.mjs +30 -20
  160. package/build-module/components/dimension-control/index.mjs.map +2 -2
  161. package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs +10 -6
  162. package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs.map +2 -2
  163. package/build-module/components/editor-styles/index.mjs +9 -1
  164. package/build-module/components/editor-styles/index.mjs.map +2 -2
  165. package/build-module/components/global-styles/background-panel.mjs +71 -29
  166. package/build-module/components/global-styles/background-panel.mjs.map +2 -2
  167. package/build-module/components/global-styles/border-panel.mjs +157 -56
  168. package/build-module/components/global-styles/border-panel.mjs.map +2 -2
  169. package/build-module/components/global-styles/color-gradient-dropdown-item.mjs +51 -15
  170. package/build-module/components/global-styles/color-gradient-dropdown-item.mjs.map +2 -2
  171. package/build-module/components/global-styles/color-panel.mjs +63 -17
  172. package/build-module/components/global-styles/color-panel.mjs.map +2 -2
  173. package/build-module/components/global-styles/dimensions-panel.mjs +248 -66
  174. package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
  175. package/build-module/components/global-styles/filters-panel.mjs +64 -21
  176. package/build-module/components/global-styles/filters-panel.mjs.map +2 -2
  177. package/build-module/components/global-styles/hooks.mjs +4 -1
  178. package/build-module/components/global-styles/hooks.mjs.map +2 -2
  179. package/build-module/components/global-styles/inheritance/index.mjs +108 -0
  180. package/build-module/components/global-styles/inheritance/index.mjs.map +7 -0
  181. package/build-module/components/global-styles/inherited-value-context.mjs +141 -0
  182. package/build-module/components/global-styles/inherited-value-context.mjs.map +7 -0
  183. package/build-module/components/global-styles/shadow-panel-components.mjs +38 -20
  184. package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
  185. package/build-module/components/global-styles/state-control.mjs +1 -1
  186. package/build-module/components/global-styles/state-control.mjs.map +2 -2
  187. package/build-module/components/global-styles/typography-panel.mjs +276 -79
  188. package/build-module/components/global-styles/typography-panel.mjs.map +2 -2
  189. package/build-module/components/inspector-controls-tabs/styles-tab.mjs +6 -1
  190. package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
  191. package/build-module/components/line-height-control/index.mjs +1 -1
  192. package/build-module/components/line-height-control/index.mjs.map +2 -2
  193. package/build-module/components/link-control/index.mjs +4 -2
  194. package/build-module/components/link-control/index.mjs.map +2 -2
  195. package/build-module/components/preset-input-control/index.mjs +2 -1
  196. package/build-module/components/preset-input-control/index.mjs.map +2 -2
  197. package/build-module/components/provider/block-refs-provider.mjs +8 -2
  198. package/build-module/components/provider/block-refs-provider.mjs.map +2 -2
  199. package/build-module/components/provider/index.mjs +1 -1
  200. package/build-module/components/provider/index.mjs.map +2 -2
  201. package/build-module/components/provider/use-block-sync.mjs +18 -6
  202. package/build-module/components/provider/use-block-sync.mjs.map +2 -2
  203. package/build-module/components/provider/use-media-upload-settings.mjs +3 -1
  204. package/build-module/components/provider/use-media-upload-settings.mjs.map +2 -2
  205. package/build-module/components/rich-text/index.mjs +28 -14
  206. package/build-module/components/rich-text/index.mjs.map +2 -2
  207. package/build-module/components/spacing-sizes-control/utils.mjs +6 -18
  208. package/build-module/components/spacing-sizes-control/utils.mjs.map +2 -2
  209. package/build-module/components/text-indent-control/index.mjs +8 -2
  210. package/build-module/components/text-indent-control/index.mjs.map +2 -2
  211. package/build-module/components/url-input/index.mjs +306 -353
  212. package/build-module/components/url-input/index.mjs.map +2 -2
  213. package/build-module/components/writing-flow/index.mjs +2 -0
  214. package/build-module/components/writing-flow/index.mjs.map +2 -2
  215. package/build-module/components/writing-flow/use-arrow-nav.mjs +24 -1
  216. package/build-module/components/writing-flow/use-arrow-nav.mjs.map +2 -2
  217. package/build-module/components/writing-flow/use-click-selection.mjs +28 -2
  218. package/build-module/components/writing-flow/use-click-selection.mjs.map +2 -2
  219. package/build-module/components/writing-flow/use-editable-root-event-handlers.mjs +154 -0
  220. package/build-module/components/writing-flow/use-editable-root-event-handlers.mjs.map +7 -0
  221. package/build-module/components/writing-flow/use-editable-root.mjs +5 -37
  222. package/build-module/components/writing-flow/use-editable-root.mjs.map +2 -2
  223. package/build-module/components/writing-flow/use-home-end.mjs +1 -1
  224. package/build-module/components/writing-flow/use-home-end.mjs.map +2 -2
  225. package/build-module/components/writing-flow/use-selection-observer.mjs +18 -14
  226. package/build-module/components/writing-flow/use-selection-observer.mjs.map +2 -2
  227. package/build-module/components/writing-flow/utils.mjs +2 -11
  228. package/build-module/components/writing-flow/utils.mjs.map +2 -2
  229. package/build-module/hooks/background.mjs +13 -10
  230. package/build-module/hooks/background.mjs.map +2 -2
  231. package/build-module/hooks/block-style-variation.mjs +8 -44
  232. package/build-module/hooks/block-style-variation.mjs.map +2 -2
  233. package/build-module/hooks/border.mjs +19 -4
  234. package/build-module/hooks/border.mjs.map +2 -2
  235. package/build-module/hooks/custom-css.mjs +7 -3
  236. package/build-module/hooks/custom-css.mjs.map +2 -2
  237. package/build-module/hooks/dimensions.mjs +15 -4
  238. package/build-module/hooks/dimensions.mjs.map +2 -2
  239. package/build-module/hooks/duotone.mjs +20 -9
  240. package/build-module/hooks/duotone.mjs.map +2 -2
  241. package/build-module/hooks/elements.mjs +14 -4
  242. package/build-module/hooks/elements.mjs.map +2 -2
  243. package/build-module/hooks/line-height.mjs +1 -2
  244. package/build-module/hooks/line-height.mjs.map +2 -2
  245. package/build-module/hooks/typography.mjs +13 -4
  246. package/build-module/hooks/typography.mjs.map +2 -2
  247. package/build-module/private-apis.mjs +7 -3
  248. package/build-module/private-apis.mjs.map +2 -2
  249. package/build-module/store/actions.mjs +9 -4
  250. package/build-module/store/actions.mjs.map +2 -2
  251. package/build-module/store/private-selectors.mjs +29 -1
  252. package/build-module/store/private-selectors.mjs.map +2 -2
  253. package/build-module/store/reducer.mjs +6 -6
  254. package/build-module/store/reducer.mjs.map +2 -2
  255. package/build-module/store/selectors.mjs +23 -0
  256. package/build-module/store/selectors.mjs.map +2 -2
  257. package/build-module/utils/native-undo.mjs +29 -0
  258. package/build-module/utils/native-undo.mjs.map +7 -0
  259. package/build-style/content-rtl.css +10 -18
  260. package/build-style/content.css +10 -18
  261. package/build-style/style-rtl.css +150 -7
  262. package/build-style/style.css +150 -7
  263. package/package.json +40 -41
  264. package/src/components/alignment-control/test/__snapshots__/index.js.snap +1 -1
  265. package/src/components/alignment-control/ui.js +2 -4
  266. package/src/components/background-image-control/index.js +74 -37
  267. package/src/components/background-image-control/style.scss +13 -4
  268. package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +3 -3
  269. package/src/components/block-alignment-control/test/index.js +1 -1
  270. package/src/components/block-alignment-control/ui.js +4 -2
  271. package/src/components/block-breadcrumb/test/__snapshots__/index.js.snap +1 -1
  272. package/src/components/block-compare/test/__snapshots__/block-view.js.snap +1 -1
  273. package/src/components/block-icon/test/__snapshots__/index.js.snap +1 -1
  274. package/src/components/block-inspector/index.js +60 -31
  275. package/src/components/block-list/block-html.js +5 -0
  276. package/src/components/block-list/content.scss +1 -11
  277. package/src/components/block-list/use-block-props/index.js +5 -1
  278. package/src/components/block-list/use-block-props/use-focus-handler.js +9 -8
  279. package/src/components/block-list/use-block-props/use-register-block-event-handlers.js +45 -0
  280. package/src/components/block-parent-selector/index.js +5 -2
  281. package/src/components/block-toolbar/switch-section-style.js +5 -2
  282. package/src/components/block-tools/empty-block-inserter.js +3 -7
  283. package/src/components/block-vertical-alignment-control/test/__snapshots__/index.js.snap +3 -3
  284. package/src/components/block-vertical-alignment-control/test/index.js +18 -2
  285. package/src/components/block-vertical-alignment-control/ui.js +3 -5
  286. package/src/components/border-radius-control/test/utils.js +0 -41
  287. package/src/components/border-radius-control/utils.js +16 -107
  288. package/src/components/button-block-appender/content.scss +6 -2
  289. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
  290. package/src/components/colors-gradients/control.js +6 -3
  291. package/src/components/default-block-appender/test/__snapshots__/index.js.snap +1 -1
  292. package/src/components/dimension-control/index.js +13 -1
  293. package/src/components/dimensions-tool/aspect-ratio-tool.js +13 -6
  294. package/src/components/editor-styles/index.js +16 -1
  295. package/src/components/global-styles/background-panel.js +107 -34
  296. package/src/components/global-styles/border-panel.js +219 -48
  297. package/src/components/global-styles/color-gradient-dropdown-item.js +93 -28
  298. package/src/components/global-styles/color-panel.js +92 -11
  299. package/src/components/global-styles/dimensions-panel.js +422 -71
  300. package/src/components/global-styles/filters-panel.js +88 -28
  301. package/src/components/global-styles/hooks.js +8 -1
  302. package/src/components/global-styles/inheritance/index.js +204 -0
  303. package/src/components/global-styles/inheritance/style.scss +184 -0
  304. package/src/components/global-styles/inheritance/test/index.js +281 -0
  305. package/src/components/global-styles/inherited-value-context.js +271 -0
  306. package/src/components/global-styles/shadow-panel-components.js +48 -26
  307. package/src/components/global-styles/state-control.js +2 -2
  308. package/src/components/global-styles/test/background-panel.js +338 -1
  309. package/src/components/global-styles/test/border-panel.js +441 -0
  310. package/src/components/global-styles/test/color-panel.js +182 -2
  311. package/src/components/global-styles/test/dimensions-panel.js +753 -0
  312. package/src/components/global-styles/test/filters-panel.js +194 -0
  313. package/src/components/global-styles/test/inherited-value-context-core.js +98 -0
  314. package/src/components/global-styles/test/inherited-value-context.js +454 -0
  315. package/src/components/global-styles/test/typography-panel-core.js +185 -0
  316. package/src/components/global-styles/test/typography-panel.js +849 -12
  317. package/src/components/global-styles/typography-panel.js +449 -100
  318. package/src/components/image-editor/style.scss +33 -0
  319. package/src/components/inner-blocks/test/__snapshots__/index.js.snap +1 -1
  320. package/src/components/inspector-controls-tabs/styles-tab.js +5 -1
  321. package/src/components/line-height-control/index.js +1 -1
  322. package/src/components/link-control/index.js +7 -2
  323. package/src/components/preset-input-control/index.js +4 -1
  324. package/src/components/provider/block-refs-provider.js +12 -2
  325. package/src/components/provider/index.js +2 -2
  326. package/src/components/provider/use-block-sync.js +18 -6
  327. package/src/components/provider/use-media-upload-settings.js +2 -0
  328. package/src/components/rich-text/index.js +37 -16
  329. package/src/components/spacing-sizes-control/test/utils.js +16 -5
  330. package/src/components/spacing-sizes-control/utils.js +11 -28
  331. package/src/components/text-indent-control/index.js +8 -0
  332. package/src/components/url-input/index.js +363 -431
  333. package/src/components/url-input/test/index.js +592 -0
  334. package/src/components/warning/test/__snapshots__/index.js.snap +1 -1
  335. package/src/components/writing-flow/index.js +2 -0
  336. package/src/components/writing-flow/use-arrow-nav.js +51 -1
  337. package/src/components/writing-flow/use-click-selection.js +54 -3
  338. package/src/components/writing-flow/use-editable-root-event-handlers.js +266 -0
  339. package/src/components/writing-flow/use-editable-root.js +7 -77
  340. package/src/components/writing-flow/use-home-end.js +17 -9
  341. package/src/components/writing-flow/use-selection-observer.js +32 -15
  342. package/src/components/writing-flow/utils.js +3 -24
  343. package/src/hooks/background.js +26 -21
  344. package/src/hooks/block-fields/rich-text/styles.scss +1 -1
  345. package/src/hooks/block-style-variation.js +8 -74
  346. package/src/hooks/border.js +19 -4
  347. package/src/hooks/custom-css.js +15 -6
  348. package/src/hooks/dimensions.js +17 -4
  349. package/src/hooks/duotone.js +26 -8
  350. package/src/hooks/elements.js +14 -3
  351. package/src/hooks/line-height.js +0 -1
  352. package/src/hooks/test/inherited-value-wiring.js +411 -0
  353. package/src/hooks/test/preset-round-trip.js +456 -0
  354. package/src/hooks/typography.js +35 -23
  355. package/src/private-apis.js +11 -2
  356. package/src/store/actions.js +10 -4
  357. package/src/store/private-selectors.js +57 -1
  358. package/src/store/reducer.js +9 -9
  359. package/src/store/selectors.js +56 -8
  360. package/src/store/test/private-selectors.js +160 -1
  361. package/src/style.scss +2 -0
  362. package/src/utils/native-undo.js +56 -0
  363. package/build/components/duotone/utils.cjs +0 -87
  364. package/build/components/duotone/utils.cjs.map +0 -7
  365. package/build-module/components/duotone/utils.mjs +0 -59
  366. package/build-module/components/duotone/utils.mjs.map +0 -7
  367. package/src/components/duotone/utils.js +0 -90
  368. package/src/hooks/test/get-variation-styles-with-ref-values.js +0 -91
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/url-input/index.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf, _n } from '@wordpress/i18n';\nimport { Component, createRef } from '@wordpress/element';\nimport { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';\nimport {\n\tBaseControl,\n\tButton,\n\t__experimentalInputControl as InputControl,\n\tSpinner,\n\twithSpokenMessages,\n\tPopover,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport {\n\tcompose,\n\tdebounce,\n\twithInstanceId,\n\twithSafeTimeout,\n} from '@wordpress/compose';\nimport { withSelect } from '@wordpress/data';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { ValidatedInputControl } = unlock( componentsPrivateApis );\n\n/**\n * Whether the argument is a function.\n *\n * @param {*} maybeFunc The argument to check.\n * @return {boolean} True if the argument is a function, false otherwise.\n */\nfunction isFunction( maybeFunc ) {\n\treturn typeof maybeFunc === 'function';\n}\n\nclass URLInput extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\n\t\tthis.onChange = this.onChange.bind( this );\n\t\tthis.onFocus = this.onFocus.bind( this );\n\t\tthis.onKeyDown = this.onKeyDown.bind( this );\n\t\tthis.selectLink = this.selectLink.bind( this );\n\t\tthis.handleOnClick = this.handleOnClick.bind( this );\n\t\tthis.bindSuggestionNode = this.bindSuggestionNode.bind( this );\n\t\tthis.autocompleteRef = props.autocompleteRef || createRef();\n\t\tthis.inputRef = props.inputRef || createRef();\n\t\tthis.hasRenderedValidation = { current: false };\n\t\tthis.updateSuggestions = debounce(\n\t\t\tthis.updateSuggestions.bind( this ),\n\t\t\t200\n\t\t);\n\n\t\tthis.suggestionNodes = [];\n\n\t\tthis.suggestionsRequest = null;\n\n\t\tthis.state = {\n\t\t\tsuggestions: [],\n\t\t\tshowSuggestions: false,\n\t\t\tsuggestionsValue: null,\n\t\t\tselectedSuggestion: null,\n\t\t\tsuggestionsListboxId: '',\n\t\t\tsuggestionOptionIdPrefix: '',\n\t\t};\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tconst { showSuggestions, selectedSuggestion } = this.state;\n\t\tconst { value, __experimentalShowInitialSuggestions = false } =\n\t\t\tthis.props;\n\n\t\t// Only have to worry about scrolling selected suggestion into view\n\t\t// when already expanded.\n\t\tif (\n\t\t\tshowSuggestions &&\n\t\t\tselectedSuggestion !== null &&\n\t\t\tthis.suggestionNodes[ selectedSuggestion ]\n\t\t) {\n\t\t\tthis.suggestionNodes[ selectedSuggestion ].scrollIntoView( {\n\t\t\t\tbehavior: 'instant',\n\t\t\t\tblock: 'nearest',\n\t\t\t\tinline: 'nearest',\n\t\t\t} );\n\t\t}\n\n\t\t// Update suggestions when the value changes.\n\t\tif ( prevProps.value !== value && ! this.props.disableSuggestions ) {\n\t\t\tif ( value?.length ) {\n\t\t\t\t// If the new value is not empty we need to update with suggestions for it.\n\t\t\t\tthis.updateSuggestions( value );\n\t\t\t} else if ( __experimentalShowInitialSuggestions ) {\n\t\t\t\t// If the new value is empty and we can show initial suggestions, then show initial suggestions.\n\t\t\t\tthis.updateSuggestions();\n\t\t\t}\n\t\t}\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( this.shouldShowInitialSuggestions() ) {\n\t\t\tthis.updateSuggestions();\n\t\t}\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.suggestionsRequest?.cancel?.();\n\t\tthis.suggestionsRequest = null;\n\t}\n\n\tbindSuggestionNode( index ) {\n\t\treturn ( ref ) => {\n\t\t\tthis.suggestionNodes[ index ] = ref;\n\t\t};\n\t}\n\n\tshouldShowInitialSuggestions() {\n\t\tconst { __experimentalShowInitialSuggestions = false, value } =\n\t\t\tthis.props;\n\t\treturn (\n\t\t\t__experimentalShowInitialSuggestions && ! ( value && value.length )\n\t\t);\n\t}\n\n\tupdateSuggestions( value = '' ) {\n\t\tconst {\n\t\t\t__experimentalFetchLinkSuggestions: fetchLinkSuggestions,\n\t\t\t__experimentalHandleURLSuggestions: handleURLSuggestions,\n\t\t} = this.props;\n\n\t\tif ( ! fetchLinkSuggestions ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Initial suggestions may only show if there is no value\n\t\t// (note: this includes whitespace).\n\t\tconst isInitialSuggestions = ! value?.length;\n\n\t\t// Trim only now we've determined whether or not it originally had a \"length\"\n\t\t// (even if that value was all whitespace).\n\t\tvalue = value.trim();\n\n\t\t// Allow a suggestions request if:\n\t\t// - there are at least 2 characters in the search input (except manual searches where\n\t\t// search input length is not required to trigger a fetch)\n\t\t// - this is a direct entry (eg: a URL)\n\t\tif (\n\t\t\t! isInitialSuggestions &&\n\t\t\t( value.length < 2 || ( ! handleURLSuggestions && isURL( value ) ) )\n\t\t) {\n\t\t\tthis.suggestionsRequest?.cancel?.();\n\t\t\tthis.suggestionsRequest = null;\n\n\t\t\tthis.setState( {\n\t\t\t\tsuggestions: [],\n\t\t\t\tshowSuggestions: false,\n\t\t\t\tsuggestionsValue: value,\n\t\t\t\tselectedSuggestion: null,\n\t\t\t\tloading: false,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t}\n\n\t\tthis.setState( {\n\t\t\tselectedSuggestion: null,\n\t\t\tloading: true,\n\t\t} );\n\n\t\tconst request = fetchLinkSuggestions( value, {\n\t\t\tisInitialSuggestions,\n\t\t} );\n\n\t\trequest\n\t\t\t.then( ( suggestions ) => {\n\t\t\t\t// A fetch Promise doesn't have an abort option. It's mimicked by\n\t\t\t\t// comparing the request reference in on the instance, which is\n\t\t\t\t// reset or deleted on subsequent requests or unmounting.\n\t\t\t\tif ( this.suggestionsRequest !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setState( {\n\t\t\t\t\tsuggestions,\n\t\t\t\t\tsuggestionsValue: value,\n\t\t\t\t\tloading: false,\n\t\t\t\t\tshowSuggestions: !! suggestions.length,\n\t\t\t\t} );\n\n\t\t\t\tif ( !! suggestions.length ) {\n\t\t\t\t\tthis.props.debouncedSpeak(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %d: number of results. */\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'%d result found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\t'%d results found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\tsuggestions.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tsuggestions.length\n\t\t\t\t\t\t),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.props.debouncedSpeak(\n\t\t\t\t\t\t__( 'No results.' ),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tif ( this.suggestionsRequest !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setState( {\n\t\t\t\t\tloading: false,\n\t\t\t\t} );\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\t// If this is the current promise then reset the reference\n\t\t\t\t// to allow for checking if a new request is made.\n\t\t\t\tif ( this.suggestionsRequest === request ) {\n\t\t\t\t\tthis.suggestionsRequest = null;\n\t\t\t\t}\n\t\t\t} );\n\n\t\t// Note that this assignment is handled *before* the async search request\n\t\t// as a Promise always resolves on the next tick of the event loop.\n\t\tthis.suggestionsRequest = request;\n\t}\n\n\tonChange( newValue ) {\n\t\tthis.props.onChange( newValue );\n\t}\n\n\tonFocus() {\n\t\tconst { suggestions } = this.state;\n\t\tconst { disableSuggestions, value } = this.props;\n\n\t\t// When opening the link editor, if there's a value present, we want to load the suggestions pane with the results for this input search value\n\t\t// Don't re-run the suggestions on focus if there are already suggestions present (prevents searching again when tabbing between the input and buttons)\n\t\t// or there is already a request in progress.\n\t\tif (\n\t\t\tvalue &&\n\t\t\t! disableSuggestions &&\n\t\t\t! ( suggestions && suggestions.length ) &&\n\t\t\tthis.suggestionsRequest === null\n\t\t) {\n\t\t\t// Ensure the suggestions are updated with the current input value.\n\t\t\tthis.updateSuggestions( value );\n\t\t}\n\t}\n\n\tonKeyDown( event ) {\n\t\tthis.props.onKeyDown?.( event );\n\t\tconst { showSuggestions, selectedSuggestion, suggestions, loading } =\n\t\t\tthis.state;\n\n\t\t// If the suggestions are not shown or loading, we shouldn't handle the arrow keys\n\t\t// We shouldn't preventDefault to allow block arrow keys navigation.\n\t\tif ( ! showSuggestions || ! suggestions.length || loading ) {\n\t\t\t// In the Windows version of Firefox the up and down arrows don't move the caret\n\t\t\t// within an input field like they do for Mac Firefox/Chrome/Safari. This causes\n\t\t\t// a form of focus trapping that is disruptive to the user experience. This disruption\n\t\t\t// only happens if the caret is not in the first or last position in the text input.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/5693#issuecomment-436684747\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\t// When UP is pressed, if the caret is at the start of the text, move it to the 0\n\t\t\t\t// position.\n\t\t\t\tcase UP: {\n\t\t\t\t\tif ( 0 !== event.target.selectionStart ) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Set the input caret to position 0.\n\t\t\t\t\t\tevent.target.setSelectionRange( 0, 0 );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// When DOWN is pressed, if the caret is not at the end of the text, move it to the\n\t\t\t\t// last position.\n\t\t\t\tcase DOWN: {\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.props.value.length !== event.target.selectionStart\n\t\t\t\t\t) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Set the input caret to the last position.\n\t\t\t\t\t\tevent.target.setSelectionRange(\n\t\t\t\t\t\t\tthis.props.value.length,\n\t\t\t\t\t\t\tthis.props.value.length\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\t// Submitting while loading should trigger onSubmit.\n\t\t\t\tcase ENTER: {\n\t\t\t\t\tif ( this.props.onSubmit ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tthis.props.onSubmit( null, event );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst suggestion =\n\t\t\tthis.state.suggestions[ this.state.selectedSuggestion ];\n\n\t\tswitch ( event.keyCode ) {\n\t\t\tcase UP: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst previousIndex = ! selectedSuggestion\n\t\t\t\t\t? suggestions.length - 1\n\t\t\t\t\t: selectedSuggestion - 1;\n\t\t\t\tthis.setState( {\n\t\t\t\t\tselectedSuggestion: previousIndex,\n\t\t\t\t} );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase DOWN: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst nextIndex =\n\t\t\t\t\tselectedSuggestion === null ||\n\t\t\t\t\tselectedSuggestion === suggestions.length - 1\n\t\t\t\t\t\t? 0\n\t\t\t\t\t\t: selectedSuggestion + 1;\n\t\t\t\tthis.setState( {\n\t\t\t\t\tselectedSuggestion: nextIndex,\n\t\t\t\t} );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TAB: {\n\t\t\t\tif ( this.state.selectedSuggestion !== null ) {\n\t\t\t\t\tthis.selectLink( suggestion );\n\t\t\t\t\t// Announce a link has been selected when tabbing away from the input field.\n\t\t\t\t\tthis.props.speak( __( 'Link selected.' ) );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ENTER: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( this.state.selectedSuggestion !== null ) {\n\t\t\t\t\tthis.selectLink( suggestion );\n\n\t\t\t\t\tif ( this.props.onSubmit ) {\n\t\t\t\t\t\tthis.props.onSubmit( suggestion, event );\n\t\t\t\t\t}\n\t\t\t\t} else if ( this.props.onSubmit ) {\n\t\t\t\t\tthis.props.onSubmit( null, event );\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tselectLink( suggestion ) {\n\t\tthis.props.onChange( suggestion.url, suggestion );\n\t\tthis.setState( {\n\t\t\tselectedSuggestion: null,\n\t\t\tshowSuggestions: false,\n\t\t} );\n\t}\n\n\thandleOnClick( suggestion ) {\n\t\tthis.selectLink( suggestion );\n\t\t// Move focus to the input field when a link suggestion is clicked.\n\t\tthis.inputRef.current.focus();\n\t}\n\n\tstatic getDerivedStateFromProps(\n\t\t{\n\t\t\tvalue,\n\t\t\tinstanceId,\n\t\t\tdisableSuggestions,\n\t\t\t__experimentalShowInitialSuggestions = false,\n\t\t},\n\t\t{ showSuggestions }\n\t) {\n\t\tlet shouldShowSuggestions = showSuggestions;\n\n\t\tconst hasValue = value && value.length;\n\n\t\tif ( ! __experimentalShowInitialSuggestions && ! hasValue ) {\n\t\t\tshouldShowSuggestions = false;\n\t\t}\n\n\t\tif ( disableSuggestions === true ) {\n\t\t\tshouldShowSuggestions = false;\n\t\t}\n\n\t\treturn {\n\t\t\tshowSuggestions: shouldShowSuggestions,\n\t\t\tsuggestionsListboxId: `block-editor-url-input-suggestions-${ instanceId }`,\n\t\t\tsuggestionOptionIdPrefix: `block-editor-url-input-suggestion-${ instanceId }`,\n\t\t};\n\t}\n\n\trender() {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ this.renderControl() }\n\t\t\t\t{ this.renderSuggestions() }\n\t\t\t</>\n\t\t);\n\t}\n\n\trenderControl() {\n\t\tconst {\n\t\t\tlabel = null,\n\t\t\tclassName,\n\t\t\tisFullWidth,\n\t\t\tinstanceId,\n\t\t\tplaceholder = __( 'Paste URL or type to search' ),\n\t\t\t__experimentalRenderControl: renderControl,\n\t\t\tvalue = '',\n\t\t\thideLabelFromVision = false,\n\t\t\thelp = null,\n\t\t\tdisabled = false,\n\t\t\tcustomValidity,\n\t\t\tmarkWhenOptional,\n\t\t} = this.props;\n\n\t\tconst {\n\t\t\tloading,\n\t\t\tshowSuggestions,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListboxId,\n\t\t\tsuggestionOptionIdPrefix,\n\t\t} = this.state;\n\n\t\tconst inputId = `url-input-control-${ instanceId }`;\n\n\t\tconst controlProps = {\n\t\t\tid: inputId, // Passes attribute to label for the for attribute\n\t\t\tlabel,\n\t\t\tclassName: clsx( 'block-editor-url-input', className, {\n\t\t\t\t'is-full-width': isFullWidth,\n\t\t\t} ),\n\t\t\thideLabelFromVision,\n\t\t};\n\n\t\tconst inputProps = {\n\t\t\tid: inputId,\n\t\t\tvalue,\n\t\t\trequired: this.props.required ?? true,\n\t\t\ttype: 'text',\n\t\t\tname: inputId,\n\t\t\tautoComplete: 'off',\n\t\t\tonChange: disabled ? () => {} : this.onChange, // Disable onChange when disabled\n\t\t\tonFocus: disabled ? () => {} : this.onFocus, // Disable onFocus when disabled\n\t\t\tplaceholder,\n\t\t\tonKeyDown: disabled ? () => {} : this.onKeyDown, // Disable onKeyDown when disabled\n\t\t\trole: 'combobox',\n\t\t\t'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label\n\t\t\t'aria-expanded': showSuggestions,\n\t\t\t'aria-autocomplete': 'list',\n\t\t\t'aria-owns': suggestionsListboxId,\n\t\t\t'aria-activedescendant':\n\t\t\t\tselectedSuggestion !== null\n\t\t\t\t\t? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`\n\t\t\t\t\t: undefined,\n\t\t\tref: this.inputRef,\n\t\t\tdisabled,\n\t\t\tsuffix: this.props.suffix,\n\t\t\thelp,\n\t\t};\n\n\t\tconst validationProps = {\n\t\t\tcustomValidity,\n\t\t\t// Suppress the \"(Required)\" indicator in the label.\n\t\t\t// The field is still required for validation, but the indicator\n\t\t\t// can be hidden when markWhenOptional is set to true.\n\t\t\t...( markWhenOptional !== undefined && {\n\t\t\t\tmarkWhenOptional,\n\t\t\t} ),\n\t\t};\n\n\t\tif ( renderControl ) {\n\t\t\treturn renderControl( controlProps, inputProps, loading );\n\t\t}\n\n\t\t// Use ValidatedInputControl if customValidity has ever had a non-undefined value.\n\t\tif ( customValidity !== undefined ) {\n\t\t\tthis.hasRenderedValidation.current = true;\n\t\t}\n\n\t\tconst MaybeValidatedInputControl = this.hasRenderedValidation.current\n\t\t\t? ValidatedInputControl\n\t\t\t: InputControl;\n\n\t\treturn (\n\t\t\t<BaseControl { ...controlProps }>\n\t\t\t\t<MaybeValidatedInputControl\n\t\t\t\t\t{ ...inputProps }\n\t\t\t\t\t{ ...( this.hasRenderedValidation.current\n\t\t\t\t\t\t? validationProps\n\t\t\t\t\t\t: {} ) }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t/>\n\t\t\t\t{ loading && <Spinner /> }\n\t\t\t</BaseControl>\n\t\t);\n\t}\n\n\trenderSuggestions() {\n\t\tconst {\n\t\t\tclassName,\n\t\t\t__experimentalRenderSuggestions: renderSuggestions,\n\t\t} = this.props;\n\n\t\tconst {\n\t\t\tshowSuggestions,\n\t\t\tsuggestions,\n\t\t\tsuggestionsValue,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListboxId,\n\t\t\tsuggestionOptionIdPrefix,\n\t\t\tloading,\n\t\t} = this.state;\n\n\t\tif ( ! showSuggestions || suggestions.length === 0 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst suggestionsListProps = {\n\t\t\tid: suggestionsListboxId,\n\t\t\tref: this.autocompleteRef,\n\t\t\trole: 'listbox',\n\t\t};\n\n\t\tconst buildSuggestionItemProps = ( suggestion, index ) => {\n\t\t\treturn {\n\t\t\t\trole: 'option',\n\t\t\t\ttabIndex: '-1',\n\t\t\t\tid: `${ suggestionOptionIdPrefix }-${ index }`,\n\t\t\t\tref: this.bindSuggestionNode( index ),\n\t\t\t\t'aria-selected':\n\t\t\t\t\tindex === selectedSuggestion ? true : undefined,\n\t\t\t};\n\t\t};\n\n\t\tif ( isFunction( renderSuggestions ) ) {\n\t\t\treturn renderSuggestions( {\n\t\t\t\tsuggestions,\n\t\t\t\tselectedSuggestion,\n\t\t\t\tsuggestionsListProps,\n\t\t\t\tbuildSuggestionItemProps,\n\t\t\t\tisLoading: loading,\n\t\t\t\thandleSuggestionClick: this.handleOnClick,\n\t\t\t\tisInitialSuggestions: ! suggestionsValue?.length,\n\t\t\t\tcurrentInputValue: suggestionsValue,\n\t\t\t} );\n\t\t}\n\n\t\treturn (\n\t\t\t<Popover placement=\"bottom\" focusOnMount={ false }>\n\t\t\t\t<div\n\t\t\t\t\t{ ...suggestionsListProps }\n\t\t\t\t\tclassName={ clsx( 'block-editor-url-input__suggestions', {\n\t\t\t\t\t\t[ `${ className }__suggestions` ]: className,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion, index ) => (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t{ ...buildSuggestionItemProps( suggestion, index ) }\n\t\t\t\t\t\t\tkey={ suggestion.id }\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'block-editor-url-input__suggestion',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'is-selected': index === selectedSuggestion,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonClick={ () => this.handleOnClick( suggestion ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ suggestion.title }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t</Popover>\n\t\t);\n\t}\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-input/README.md\n */\nexport default compose(\n\twithSafeTimeout,\n\twithSpokenMessages,\n\twithInstanceId,\n\twithSelect( ( select, props ) => {\n\t\t// If a link suggestions handler is already provided then\n\t\t// bail.\n\t\tif ( isFunction( props.__experimentalFetchLinkSuggestions ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn {\n\t\t\t__experimentalFetchLinkSuggestions:\n\t\t\t\tgetSettings().__experimentalFetchLinkSuggestions,\n\t\t};\n\t} )\n)( URLInput );\n"],
5
- "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,IAAI,SAAS,UAAU;AAChC,SAAS,WAAW,iBAAiB;AACrC,SAAS,IAAI,MAAM,OAAO,WAAW;AACrC;AAAA,EACC;AAAA,EACA;AAAA,EACA,8BAA8B;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,OACT;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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E;AAAA,QAEA,sBAAY,IAAK,CAAE,YAAY,UAChC;AAAA,UAAC;AAAA;AAAA,YACA,uBAAqB;AAAA,YACnB,GAAG,yBAA0B,YAAY,KAAM;AAAA,YACjD,KAAM,WAAW;AAAA,YACjB,WAAY;AAAA,cACX;AAAA,cACA;AAAA,gBACC,eAAe,UAAU;AAAA,cAC1B;AAAA,YACD;AAAA,YACA,SAAU,MAAM,KAAK,cAAe,UAAW;AAAA;AAAA,UAE7C,WAAW;AAAA,QACd,CACC;AAAA;AAAA,IACH,GACD;AAAA,EAEF;AACD;AAKA,IAAO,oBAAQ;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAY,CAAE,QAAQ,UAAW;AAGhC,QAAK,WAAY,MAAM,kCAAmC,GAAI;AAC7D;AAAA,IACD;AACA,UAAM,EAAE,YAAY,IAAI,OAAQ,gBAAiB;AACjD,WAAO;AAAA,MACN,oCACC,YAAY,EAAE;AAAA,IAChB;AAAA,EACD,CAAE;AACH,EAAG,QAAS;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { speak } from '@wordpress/a11y';\nimport { __, sprintf, _n } from '@wordpress/i18n';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';\nimport {\n\tBaseControl,\n\tButton,\n\t__experimentalInputControl as InputControl,\n\tSpinner,\n\tPopover,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useDebounce, useEvent, useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { ValidatedInputControl } = unlock( componentsPrivateApis );\n\nconst noop = () => {};\n\n/**\n * Whether the argument is a function.\n *\n * @param {*} maybeFunc The argument to check.\n * @return {boolean} True if the argument is a function, false otherwise.\n */\nfunction isFunction( maybeFunc ) {\n\treturn typeof maybeFunc === 'function';\n}\n\n/**\n * Text field for entering a URL, with an autocomplete list of matching posts,\n * pages and other link suggestions.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-input/README.md\n *\n * @param {Object} props Component props.\n */\nexport default function URLInput( props ) {\n\tconst {\n\t\t__experimentalFetchLinkSuggestions: fetchLinkSuggestionsProp,\n\t\t__experimentalHandleURLSuggestions: handleURLSuggestions,\n\t\t__experimentalRenderControl: renderControl,\n\t\t__experimentalRenderSuggestions: renderSuggestions,\n\t\t__experimentalShowInitialSuggestions: showInitialSuggestions = false,\n\t\tautocompleteRef,\n\t\tclassName,\n\t\tcustomValidity,\n\t\tdisableSuggestions,\n\t\tdisabled = false,\n\t\thelp = null,\n\t\thideLabelFromVision = false,\n\t\tinputRef,\n\t\tisFullWidth,\n\t\tlabel = null,\n\t\tmarkWhenOptional,\n\t\tonChange,\n\t\tonKeyDown,\n\t\tonSubmit,\n\t\tplaceholder = __( 'Paste URL or type to search' ),\n\t\trequired = true,\n\t\tsuffix,\n\t\tvalue = '',\n\t} = props;\n\n\tconst instanceId = useInstanceId( URLInput );\n\tconst { getSettings } = useSelect( blockEditorStore );\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\n\tconst [ suggestions, setSuggestions ] = useState( [] );\n\tconst [ suggestionsValue, setSuggestionsValue ] = useState( null );\n\tconst [ selectedSuggestion, setSelectedSuggestion ] = useState( null );\n\tconst [ isSuggestionsListOpen, setIsSuggestionsListOpen ] =\n\t\tuseState( false );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\n\tconst fallbackInputRef = useRef();\n\tconst suggestionNodesRef = useRef( [] );\n\t// A fetch Promise can't be aborted. It's mimicked by holding on to the\n\t// pending request so that responses of superseded requests can be ignored.\n\tconst suggestionsRequestRef = useRef( null );\n\n\tconst controlInputRef = inputRef ?? fallbackInputRef;\n\n\tconst inputId = `url-input-control-${ instanceId }`;\n\tconst suggestionsListboxId = `block-editor-url-input-suggestions-${ instanceId }`;\n\tconst suggestionOptionIdPrefix = `block-editor-url-input-suggestion-${ instanceId }`;\n\n\t// The suggestions are hidden rather than discarded, so that returning focus\n\t// to a field that already has results doesn't trigger a new search.\n\tconst showSuggestions =\n\t\tisSuggestionsListOpen &&\n\t\tdisableSuggestions !== true &&\n\t\t( showInitialSuggestions || !! value.length );\n\n\tconst updateSuggestions = useEvent( ( searchValue = '' ) => {\n\t\tconst fetchLinkSuggestions = isFunction( fetchLinkSuggestionsProp )\n\t\t\t? fetchLinkSuggestionsProp\n\t\t\t: getSettings().__experimentalFetchLinkSuggestions;\n\n\t\tif ( ! fetchLinkSuggestions ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Initial suggestions may only show if there is no value\n\t\t// (note: this includes whitespace).\n\t\tconst isInitialSuggestions = ! searchValue?.length;\n\n\t\t// Trim only now we've determined whether or not it originally had a \"length\"\n\t\t// (even if that value was all whitespace).\n\t\tconst search = searchValue.trim();\n\n\t\t// Allow a suggestions request if:\n\t\t// - there are at least 2 characters in the search input (except manual searches where\n\t\t// search input length is not required to trigger a fetch)\n\t\t// - this is a direct entry (eg: a URL)\n\t\tif (\n\t\t\t! isInitialSuggestions &&\n\t\t\t( search.length < 2 ||\n\t\t\t\t( ! handleURLSuggestions && isURL( search ) ) )\n\t\t) {\n\t\t\tsuggestionsRequestRef.current?.cancel?.();\n\t\t\tsuggestionsRequestRef.current = null;\n\n\t\t\tsetSuggestions( [] );\n\t\t\tsetIsSuggestionsListOpen( false );\n\t\t\tsetSuggestionsValue( search );\n\t\t\tsetSelectedSuggestion( null );\n\t\t\tsetIsLoading( false );\n\n\t\t\treturn;\n\t\t}\n\n\t\tsetSelectedSuggestion( null );\n\t\tsetIsLoading( true );\n\n\t\tconst request = fetchLinkSuggestions( search, {\n\t\t\tisInitialSuggestions,\n\t\t} );\n\t\tsuggestionsRequestRef.current = request;\n\n\t\trequest\n\t\t\t.then( ( nextSuggestions ) => {\n\t\t\t\tif ( suggestionsRequestRef.current !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetSuggestions( nextSuggestions );\n\t\t\t\tsetSuggestionsValue( search );\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tsetIsSuggestionsListOpen( !! nextSuggestions.length );\n\n\t\t\t\tif ( nextSuggestions.length ) {\n\t\t\t\t\tdebouncedSpeak(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %d: number of results. */\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'%d result found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\t'%d results found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\tnextSuggestions.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tnextSuggestions.length\n\t\t\t\t\t\t),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tdebouncedSpeak( __( 'No results.' ), 'assertive' );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tif ( suggestionsRequestRef.current !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif ( suggestionsRequestRef.current === request ) {\n\t\t\t\t\tsuggestionsRequestRef.current = null;\n\t\t\t\t}\n\t\t\t} );\n\t} );\n\n\tconst debouncedUpdateSuggestions = useDebounce( updateSuggestions, 200 );\n\n\t// Keep the suggestions in sync with the value being searched for. An empty\n\t// value requests the initial suggestions, when those are enabled.\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! disableSuggestions &&\n\t\t\t( value.length || showInitialSuggestions )\n\t\t) {\n\t\t\tdebouncedUpdateSuggestions( value );\n\t\t}\n\t}, [\n\t\tvalue,\n\t\tdisableSuggestions,\n\t\tshowInitialSuggestions,\n\t\tdebouncedUpdateSuggestions,\n\t] );\n\n\t// Persist the hidden state, so that the list can't reappear with stale\n\t// results once the value or the props allow suggestions again.\n\tuseEffect( () => {\n\t\tif ( ! showSuggestions ) {\n\t\t\tsetIsSuggestionsListOpen( false );\n\t\t}\n\t}, [ showSuggestions ] );\n\n\tuseEffect( () => {\n\t\tif ( showSuggestions && selectedSuggestion !== null ) {\n\t\t\tsuggestionNodesRef.current[ selectedSuggestion ]?.scrollIntoView( {\n\t\t\t\tbehavior: 'instant',\n\t\t\t\tblock: 'nearest',\n\t\t\t\tinline: 'nearest',\n\t\t\t} );\n\t\t}\n\t}, [ showSuggestions, selectedSuggestion ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tsuggestionsRequestRef.current?.cancel?.();\n\t\t\tsuggestionsRequestRef.current = null;\n\t\t};\n\t}, [] );\n\n\tfunction selectLink( suggestion ) {\n\t\tonChange( suggestion.url, suggestion );\n\t\tsetSelectedSuggestion( null );\n\t\tsetIsSuggestionsListOpen( false );\n\t}\n\n\tfunction handleSuggestionClick( suggestion ) {\n\t\tselectLink( suggestion );\n\t\t// Move focus to the input field when a link suggestion is clicked.\n\t\tcontrolInputRef.current.focus();\n\t}\n\n\tfunction handleChange( newValue ) {\n\t\t// `InputControl` passes an `{ event }` object as its second argument,\n\t\t// which callers would mistake for a selected suggestion.\n\t\tonChange( newValue );\n\t}\n\n\tfunction handleFocus() {\n\t\t// When opening the link editor, if there's a value present, we want to load the suggestions pane with the results for this input search value\n\t\t// Don't re-run the suggestions on focus if there are already suggestions present (prevents searching again when tabbing between the input and buttons)\n\t\t// or there is already a request in progress.\n\t\tif (\n\t\t\tvalue &&\n\t\t\t! disableSuggestions &&\n\t\t\t! suggestions.length &&\n\t\t\tsuggestionsRequestRef.current === null\n\t\t) {\n\t\t\tdebouncedUpdateSuggestions( value );\n\t\t}\n\t}\n\n\tfunction handleKeyDown( event ) {\n\t\tonKeyDown?.( event );\n\n\t\t// If the suggestions are not shown or loading, we shouldn't handle the arrow keys\n\t\t// We shouldn't preventDefault to allow block arrow keys navigation.\n\t\tif ( ! showSuggestions || ! suggestions.length || isLoading ) {\n\t\t\t// In the Windows version of Firefox the up and down arrows don't move the caret\n\t\t\t// within an input field like they do for Mac Firefox/Chrome/Safari. This causes\n\t\t\t// a form of focus trapping that is disruptive to the user experience. This disruption\n\t\t\t// only happens if the caret is not in the first or last position in the text input.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/5693#issuecomment-436684747\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\t// When UP is pressed, if the caret is at the start of the text, move it to the 0\n\t\t\t\t// position.\n\t\t\t\tcase UP: {\n\t\t\t\t\tif ( 0 !== event.target.selectionStart ) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Set the input caret to position 0.\n\t\t\t\t\t\tevent.target.setSelectionRange( 0, 0 );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// When DOWN is pressed, if the caret is not at the end of the text, move it to the\n\t\t\t\t// last position.\n\t\t\t\tcase DOWN: {\n\t\t\t\t\tif ( value.length !== event.target.selectionStart ) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Set the input caret to the last position.\n\t\t\t\t\t\tevent.target.setSelectionRange(\n\t\t\t\t\t\t\tvalue.length,\n\t\t\t\t\t\t\tvalue.length\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\t// Submitting while loading should trigger onSubmit.\n\t\t\t\tcase ENTER: {\n\t\t\t\t\tif ( onSubmit ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tonSubmit( null, event );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst suggestion = suggestions[ selectedSuggestion ];\n\n\t\tswitch ( event.keyCode ) {\n\t\t\tcase UP: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tsetSelectedSuggestion(\n\t\t\t\t\t! selectedSuggestion\n\t\t\t\t\t\t? suggestions.length - 1\n\t\t\t\t\t\t: selectedSuggestion - 1\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase DOWN: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tsetSelectedSuggestion(\n\t\t\t\t\tselectedSuggestion === null ||\n\t\t\t\t\t\tselectedSuggestion === suggestions.length - 1\n\t\t\t\t\t\t? 0\n\t\t\t\t\t\t: selectedSuggestion + 1\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TAB: {\n\t\t\t\tif ( selectedSuggestion !== null ) {\n\t\t\t\t\tselectLink( suggestion );\n\t\t\t\t\t// Announce a link has been selected when tabbing away from the input field.\n\t\t\t\t\tspeak( __( 'Link selected.' ) );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ENTER: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( selectedSuggestion !== null ) {\n\t\t\t\t\tselectLink( suggestion );\n\n\t\t\t\t\tif ( onSubmit ) {\n\t\t\t\t\t\tonSubmit( suggestion, event );\n\t\t\t\t\t}\n\t\t\t\t} else if ( onSubmit ) {\n\t\t\t\t\tonSubmit( null, event );\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst controlProps = {\n\t\tid: inputId, // Passes attribute to label for the for attribute\n\t\tlabel,\n\t\tclassName: clsx( 'block-editor-url-input', className, {\n\t\t\t'is-full-width': isFullWidth,\n\t\t} ),\n\t\thideLabelFromVision,\n\t};\n\n\tconst inputProps = {\n\t\tid: inputId,\n\t\tvalue,\n\t\trequired,\n\t\ttype: 'text',\n\t\tname: inputId,\n\t\tautoComplete: 'off',\n\t\tonChange: disabled ? noop : handleChange,\n\t\tonFocus: disabled ? noop : handleFocus,\n\t\tonKeyDown: disabled ? noop : handleKeyDown,\n\t\tplaceholder,\n\t\trole: 'combobox',\n\t\t'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label\n\t\t'aria-expanded': showSuggestions,\n\t\t'aria-autocomplete': 'list',\n\t\t'aria-owns': suggestionsListboxId,\n\t\t'aria-activedescendant':\n\t\t\tselectedSuggestion !== null\n\t\t\t\t? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`\n\t\t\t\t: undefined,\n\t\tref: controlInputRef,\n\t\tdisabled,\n\t\tsuffix,\n\t\thelp,\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<Control\n\t\t\t\tcontrolProps={ controlProps }\n\t\t\t\tinputProps={ inputProps }\n\t\t\t\tisLoading={ isLoading }\n\t\t\t\tcustomValidity={ customValidity }\n\t\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\t\trenderControl={ renderControl }\n\t\t\t/>\n\t\t\t{ showSuggestions && suggestions.length > 0 && (\n\t\t\t\t<Suggestions\n\t\t\t\t\tautocompleteRef={ autocompleteRef }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t\thandleSuggestionClick={ handleSuggestionClick }\n\t\t\t\t\tisLoading={ isLoading }\n\t\t\t\t\trenderSuggestions={ renderSuggestions }\n\t\t\t\t\tselectedSuggestion={ selectedSuggestion }\n\t\t\t\t\tsuggestionNodesRef={ suggestionNodesRef }\n\t\t\t\t\tsuggestionOptionIdPrefix={ suggestionOptionIdPrefix }\n\t\t\t\t\tsuggestions={ suggestions }\n\t\t\t\t\tsuggestionsListboxId={ suggestionsListboxId }\n\t\t\t\t\tsuggestionsValue={ suggestionsValue }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction Control( {\n\tcontrolProps,\n\tinputProps,\n\tisLoading,\n\tcustomValidity,\n\tmarkWhenOptional,\n\trenderControl,\n} ) {\n\t// Once a validity has been reported, keep using the validated control, so\n\t// that clearing the validity doesn't remount (and blur) the input.\n\tconst [ isValidated, setIsValidated ] = useState(\n\t\tcustomValidity !== undefined\n\t);\n\n\tif ( customValidity !== undefined && ! isValidated ) {\n\t\tsetIsValidated( true );\n\t}\n\n\tif ( renderControl ) {\n\t\treturn renderControl( controlProps, inputProps, isLoading );\n\t}\n\n\tconst MaybeValidatedInputControl = isValidated\n\t\t? ValidatedInputControl\n\t\t: InputControl;\n\n\treturn (\n\t\t<BaseControl { ...controlProps }>\n\t\t\t<MaybeValidatedInputControl\n\t\t\t\t{ ...inputProps }\n\t\t\t\t{ ...( isValidated && {\n\t\t\t\t\tcustomValidity,\n\t\t\t\t\t// Suppress the \"(Required)\" indicator in the label.\n\t\t\t\t\t// The field is still required for validation, but the indicator\n\t\t\t\t\t// can be hidden when markWhenOptional is set to true.\n\t\t\t\t\t...( markWhenOptional !== undefined && {\n\t\t\t\t\t\tmarkWhenOptional,\n\t\t\t\t\t} ),\n\t\t\t\t} ) }\n\t\t\t/>\n\t\t\t{ isLoading && <Spinner /> }\n\t\t</BaseControl>\n\t);\n}\n\nfunction Suggestions( {\n\tautocompleteRef,\n\tclassName,\n\thandleSuggestionClick,\n\tisLoading,\n\trenderSuggestions,\n\tselectedSuggestion,\n\tsuggestionNodesRef,\n\tsuggestionOptionIdPrefix,\n\tsuggestions,\n\tsuggestionsListboxId,\n\tsuggestionsValue,\n} ) {\n\tconst suggestionsListProps = {\n\t\tid: suggestionsListboxId,\n\t\tref: autocompleteRef,\n\t\trole: 'listbox',\n\t};\n\n\tconst buildSuggestionItemProps = ( suggestion, index ) => {\n\t\treturn {\n\t\t\trole: 'option',\n\t\t\ttabIndex: '-1',\n\t\t\tid: `${ suggestionOptionIdPrefix }-${ index }`,\n\t\t\tref: ( node ) => {\n\t\t\t\tsuggestionNodesRef.current[ index ] = node;\n\t\t\t},\n\t\t\t'aria-selected': index === selectedSuggestion ? true : undefined,\n\t\t};\n\t};\n\n\tif ( isFunction( renderSuggestions ) ) {\n\t\treturn renderSuggestions( {\n\t\t\tsuggestions,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListProps,\n\t\t\tbuildSuggestionItemProps,\n\t\t\tisLoading,\n\t\t\thandleSuggestionClick,\n\t\t\tisInitialSuggestions: ! suggestionsValue?.length,\n\t\t\tcurrentInputValue: suggestionsValue,\n\t\t} );\n\t}\n\n\treturn (\n\t\t<Popover placement=\"bottom\" focusOnMount={ false }>\n\t\t\t<div\n\t\t\t\t{ ...suggestionsListProps }\n\t\t\t\tclassName={ clsx( 'block-editor-url-input__suggestions', {\n\t\t\t\t\t[ `${ className }__suggestions` ]: className,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ suggestions.map( ( suggestion, index ) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t{ ...buildSuggestionItemProps( suggestion, index ) }\n\t\t\t\t\t\tkey={ suggestion.id }\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t'block-editor-url-input__suggestion',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t'is-selected': index === selectedSuggestion,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tonClick={ () => handleSuggestionClick( suggestion ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ suggestion.title }\n\t\t\t\t\t</Button>\n\t\t\t\t) ) }\n\t\t\t</div>\n\t\t</Popover>\n\t);\n}\n"],
5
+ "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,aAAa;AACtB,SAAS,IAAI,SAAS,UAAU;AAChC,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,IAAI,MAAM,OAAO,WAAW;AACrC;AAAA,EACC;AAAA,EACA;AAAA,EACA,8BAA8B;AAAA,EAC9B;AAAA,EACA;AAAA,EACA,eAAe;AAAA,OACT;AACP,SAAS,aAAa,UAAU,qBAAqB;AACrD,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAKtB,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AA0XrB,mBACC,KADD;AA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B,YAAY,KAAM;AAAA,UACjD,KAAM,WAAW;AAAA,UACjB,WAAY;AAAA,YACX;AAAA,YACA;AAAA,cACC,eAAe,UAAU;AAAA,YAC1B;AAAA,UACD;AAAA,UACA,SAAU,MAAM,sBAAuB,UAAW;AAAA;AAAA,QAEhD,WAAW;AAAA,MACd,CACC;AAAA;AAAA,EACH,GACD;AAEF;",
6
6
  "names": []
7
7
  }
@@ -13,6 +13,7 @@ import { usePreviewModeNav } from "./use-preview-mode-nav.mjs";
13
13
  import useSelectAll from "./use-select-all.mjs";
14
14
  import useDragSelection from "./use-drag-selection.mjs";
15
15
  import useSelectionObserver from "./use-selection-observer.mjs";
16
+ import useEditableRootEventHandlers from "./use-editable-root-event-handlers.mjs";
16
17
  import useClickSelection from "./use-click-selection.mjs";
17
18
  import useInput from "./use-input.mjs";
18
19
  import useClipboardHandler from "./use-clipboard-handler.mjs";
@@ -28,6 +29,7 @@ function useWritingFlow() {
28
29
  before,
29
30
  useMergeRefs([
30
31
  ref,
32
+ useEditableRootEventHandlers(),
31
33
  useClipboardHandler(),
32
34
  useInput(),
33
35
  useEditableRoot(),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/writing-flow/index.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\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 useEditableRoot from './use-editable-root';\nimport useHomeEnd from './use-home-end';\nimport useMultiSelection from './use-multi-selection';\nimport useTabNav from './use-tab-nav';\nimport useArrowNav from './use-arrow-nav';\nimport { usePreviewModeNav } from './use-preview-mode-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 useClipboardHandler from './use-clipboard-handler';\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\tuseClipboardHandler(),\n\t\t\tuseInput(),\n\t\t\tuseEditableRoot(),\n\t\t\tuseHomeEnd(),\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\tusePreviewModeNav(),\n\t\t\tuseRefEffect(\n\t\t\t\t( node ) => {\n\t\t\t\t\tnode.tabIndex = 0;\n\t\t\t\t\tnode.dataset.hasMultiSelection = hasMultiSelection;\n\n\t\t\t\t\tif ( ! hasMultiSelection ) {\n\t\t\t\t\t\treturn () => {\n\t\t\t\t\t\t\tdelete node.dataset.hasMultiSelection;\n\t\t\t\t\t\t};\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\tdelete node.dataset.hasMultiSelection;\n\t\t\t\t\t\t// The wrapper may remain the editing host (the\n\t\t\t\t\t\t// collapsed block supports `editableRoot`): keep it\n\t\t\t\t\t\t// named, as the textbox role requires.\n\t\t\t\t\t\tif ( node.contentEditable === 'true' ) {\n\t\t\t\t\t\t\tnode.setAttribute(\n\t\t\t\t\t\t\t\t'aria-label',\n\t\t\t\t\t\t\t\t__( 'Editor canvas' )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.removeAttribute( 'aria-label' );\n\t\t\t\t\t\t}\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={ clsx(\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 {Element} props.children Children to be rendered.\n */\nexport default forwardRef( WritingFlow );\n"],
5
- "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AACnB,SAAS,cAAc,oBAAoB;AAC3C,SAAS,kBAAkB;AAK3B,OAAO,qBAAqB;AAC5B,OAAO,gBAAgB;AACvB,OAAO,uBAAuB;AAC9B,OAAO,eAAe;AACtB,OAAO,iBAAiB;AACxB,SAAS,yBAAyB;AAClC,OAAO,kBAAkB;AACzB,OAAO,sBAAsB;AAC7B,OAAO,0BAA0B;AACjC,OAAO,uBAAuB;AAC9B,OAAO,cAAc;AACrB,OAAO,yBAAyB;AAChC,SAAS,SAAS,wBAAwB;AAiExC,mBAEC,KAFD;AA/DK,SAAS,iBAAiB;AAChC,QAAM,CAAE,QAAQ,KAAK,KAAM,IAAI,UAAU;AACzC,QAAM,oBAAoB;AAAA,IACzB,CAAE,WAAY,OAAQ,gBAAiB,EAAE,kBAAkB;AAAA,IAC3D,CAAC;AAAA,EACF;AAEA,SAAO;AAAA,IACN;AAAA,IACA,aAAc;AAAA,MACb;AAAA,MACA,oBAAoB;AAAA,MACpB,SAAS;AAAA,MACT,gBAAgB;AAAA,MAChB,WAAW;AAAA,MACX,iBAAiB;AAAA,MACjB,qBAAqB;AAAA,MACrB,kBAAkB;AAAA,MAClB,kBAAkB;AAAA,MAClB,aAAa;AAAA,MACb,YAAY;AAAA,MACZ,kBAAkB;AAAA,MAClB;AAAA,QACC,CAAE,SAAU;AACX,eAAK,WAAW;AAChB,eAAK,QAAQ,oBAAoB;AAEjC,cAAK,CAAE,mBAAoB;AAC1B,mBAAO,MAAM;AACZ,qBAAO,KAAK,QAAQ;AAAA,YACrB;AAAA,UACD;AAEA,eAAK;AAAA,YACJ;AAAA,YACA,GAAI,0BAA2B;AAAA,UAChC;AAEA,iBAAO,MAAM;AACZ,mBAAO,KAAK,QAAQ;AAIpB,gBAAK,KAAK,oBAAoB,QAAS;AACtC,mBAAK;AAAA,gBACJ;AAAA,gBACA,GAAI,eAAgB;AAAA,cACrB;AAAA,YACD,OAAO;AACN,mBAAK,gBAAiB,YAAa;AAAA,YACpC;AAAA,UACD;AAAA,QACD;AAAA,QACA,CAAE,iBAAkB;AAAA,MACrB;AAAA,IACD,CAAE;AAAA,IACF;AAAA,EACD;AACD;AAEA,SAAS,YAAa,EAAE,UAAU,GAAG,MAAM,GAAG,cAAe;AAC5D,QAAM,CAAE,QAAQ,KAAK,KAAM,IAAI,eAAe;AAC9C,SACC,iCACG;AAAA;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACL,KAAM,aAAc,CAAE,KAAK,YAAa,CAAE;AAAA,QAC1C,WAAY;AAAA,UACX,MAAM;AAAA,UACN;AAAA,QACD;AAAA,QAEE;AAAA;AAAA,IACH;AAAA,IACE;AAAA,KACH;AAEF;AASA,IAAO,uBAAQ,WAAY,WAAY;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\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 useEditableRoot from './use-editable-root';\nimport useHomeEnd from './use-home-end';\nimport useMultiSelection from './use-multi-selection';\nimport useTabNav from './use-tab-nav';\nimport useArrowNav from './use-arrow-nav';\nimport { usePreviewModeNav } from './use-preview-mode-nav';\nimport useSelectAll from './use-select-all';\nimport useDragSelection from './use-drag-selection';\nimport useSelectionObserver from './use-selection-observer';\nimport useEditableRootEventHandlers from './use-editable-root-event-handlers';\nimport useClickSelection from './use-click-selection';\nimport useInput from './use-input';\nimport useClipboardHandler from './use-clipboard-handler';\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\tuseEditableRootEventHandlers(),\n\t\t\tuseClipboardHandler(),\n\t\t\tuseInput(),\n\t\t\tuseEditableRoot(),\n\t\t\tuseHomeEnd(),\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\tusePreviewModeNav(),\n\t\t\tuseRefEffect(\n\t\t\t\t( node ) => {\n\t\t\t\t\tnode.tabIndex = 0;\n\t\t\t\t\tnode.dataset.hasMultiSelection = hasMultiSelection;\n\n\t\t\t\t\tif ( ! hasMultiSelection ) {\n\t\t\t\t\t\treturn () => {\n\t\t\t\t\t\t\tdelete node.dataset.hasMultiSelection;\n\t\t\t\t\t\t};\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\tdelete node.dataset.hasMultiSelection;\n\t\t\t\t\t\t// The wrapper may remain the editing host (the\n\t\t\t\t\t\t// collapsed block supports `editableRoot`): keep it\n\t\t\t\t\t\t// named, as the textbox role requires.\n\t\t\t\t\t\tif ( node.contentEditable === 'true' ) {\n\t\t\t\t\t\t\tnode.setAttribute(\n\t\t\t\t\t\t\t\t'aria-label',\n\t\t\t\t\t\t\t\t__( 'Editor canvas' )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.removeAttribute( 'aria-label' );\n\t\t\t\t\t\t}\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={ clsx(\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 {Element} props.children Children to be rendered.\n */\nexport default forwardRef( WritingFlow );\n"],
5
+ "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AACnB,SAAS,cAAc,oBAAoB;AAC3C,SAAS,kBAAkB;AAK3B,OAAO,qBAAqB;AAC5B,OAAO,gBAAgB;AACvB,OAAO,uBAAuB;AAC9B,OAAO,eAAe;AACtB,OAAO,iBAAiB;AACxB,SAAS,yBAAyB;AAClC,OAAO,kBAAkB;AACzB,OAAO,sBAAsB;AAC7B,OAAO,0BAA0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;AAC9C,SACC,iCACG;AAAA;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACL,KAAM,aAAc,CAAE,KAAK,YAAa,CAAE;AAAA,QAC1C,WAAY;AAAA,UACX,MAAM;AAAA,UACN;AAAA,QACD;AAAA,QAEE;AAAA;AAAA,IACH;AAAA,IACE;AAAA,KACH;AAEF;AASA,IAAO,uBAAQ,WAAY,WAAY;",
6
6
  "names": []
7
7
  }
@@ -86,11 +86,15 @@ function useArrowNav() {
86
86
  const {
87
87
  getMultiSelectedBlocksStartClientId,
88
88
  getMultiSelectedBlocksEndClientId,
89
+ getNextBlockClientId,
90
+ getPreviousBlockClientId,
91
+ getSelectedBlockClientId,
92
+ getSelectionStart,
89
93
  getSettings,
90
94
  hasMultiSelection,
91
95
  __unstableIsFullySelected
92
96
  } = useSelect(blockEditorStore);
93
- const { selectBlock } = useDispatch(blockEditorStore);
97
+ const { selectBlock, multiSelect } = useDispatch(blockEditorStore);
94
98
  return useRefEffect((node) => {
95
99
  let verticalRect;
96
100
  function onMouseDown() {
@@ -133,6 +137,16 @@ function useArrowNav() {
133
137
  }
134
138
  if (hasMultiSelection()) {
135
139
  if (shiftKey) {
140
+ const selection = defaultView.getSelection();
141
+ if (__unstableIsFullySelected() && (!selection.rangeCount || selection.isCollapsed)) {
142
+ const anchorClientId = getMultiSelectedBlocksStartClientId();
143
+ const focusClientId = getMultiSelectedBlocksEndClientId();
144
+ const nextClientId = isReverse ? getPreviousBlockClientId(focusClientId) : getNextBlockClientId(focusClientId);
145
+ if (nextClientId) {
146
+ multiSelect(anchorClientId, nextClientId);
147
+ event.preventDefault();
148
+ }
149
+ }
136
150
  return;
137
151
  }
138
152
  if (!__unstableIsFullySelected()) {
@@ -146,6 +160,15 @@ function useArrowNav() {
146
160
  }
147
161
  return;
148
162
  }
163
+ if (shiftKey && getSelectedBlockClientId() && !getSelectionStart().attributeKey) {
164
+ const selectedClientId = getSelectedBlockClientId();
165
+ const nextClientId = isReverse ? getPreviousBlockClientId(selectedClientId) : getNextBlockClientId(selectedClientId);
166
+ if (nextClientId) {
167
+ multiSelect(selectedClientId, nextClientId);
168
+ event.preventDefault();
169
+ }
170
+ return;
171
+ }
149
172
  if (!isNavigationCandidate(target, keyCode, hasModifier)) {
150
173
  return;
151
174
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/writing-flow/use-arrow-nav.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n\tisFormElement,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getBlockClientId, getSelectionEditableElement } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\nimport { setContentEditableWrapper } from './utils';\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\tconst { tagName } = element;\n\tconst elementType = element.getAttribute( 'type' );\n\n\t// Native inputs should not navigate vertically, unless they are simple types that don't need up/down arrow keys.\n\tif ( isVertical && ! hasModifier ) {\n\t\tif ( tagName === 'INPUT' ) {\n\t\t\tconst verticalInputTypes = [\n\t\t\t\t'date',\n\t\t\t\t'datetime-local',\n\t\t\t\t'month',\n\t\t\t\t'number',\n\t\t\t\t'range',\n\t\t\t\t'time',\n\t\t\t\t'week',\n\t\t\t];\n\t\t\treturn ! verticalInputTypes.includes( elementType );\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.\n\tif ( tagName === 'INPUT' ) {\n\t\tconst simpleInputTypes = [\n\t\t\t'button',\n\t\t\t'checkbox',\n\t\t\t'number',\n\t\t\t'color',\n\t\t\t'file',\n\t\t\t'image',\n\t\t\t'radio',\n\t\t\t'reset',\n\t\t\t'submit',\n\t\t];\n\t\treturn simpleInputTypes.includes( elementType );\n\t}\n\n\t// Native textareas should not navigate horizontally.\n\treturn 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();\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// If it's a block wrapper (not itself a contenteditable editing surface)\n\t\t// and there are nested focusable nodes, skip because there are better\n\t\t// candidates. We must not skip contenteditable nodes that happen to\n\t\t// contain links or other focusable inline elements, since those are the\n\t\t// correct navigation targets.\n\t\t//\n\t\t// See https://github.com/WordPress/gutenberg/pull/77474\n\t\t// TODO: Consider fixing focus.tabbable\n\t\tif (\n\t\t\tnode.contentEditable !== 'true' &&\n\t\t\tgetBlockClientId( node ) &&\n\t\t\tfocus.focusable\n\t\t\t\t.find( node )\n\t\t\t\t// Exclude form elements for now because primary+a cannot be\n\t\t\t\t// used to select the parent element.\n\t\t\t\t.filter( ( element ) => ! isFormElement( element ) ).length !==\n\t\t\t\t0\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\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\n\t\t// nodes: nodes whose closest editable host is an editable element\n\t\t// within a block. When an editable root (e.g. the canvas wrapper)\n\t\t// is the editing host, everything within it is content editable,\n\t\t// but focusables like block wrappers are not text content.\n\t\tif (\n\t\t\tnode.isContentEditable &&\n\t\t\tnode.contentEditable !== 'true' &&\n\t\t\tgetBlockClientId( node.closest( '[contenteditable=\"true\"]' ) )\n\t\t) {\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 focusableNodes.find( isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t\t__unstableIsFullySelected,\n\t} = useSelect( blockEditorStore );\n\tconst { 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 isClosestTabbableABlock( 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 closestTabbable && getBlockClientId( closestTabbable );\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\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\tconst { keyCode, shiftKey, ctrlKey, altKey, metaKey } = event;\n\t\t\t// When the wrapper is contentEditable and holds focus (the\n\t\t\t// selected block supports `editableRoot`), the event targets the\n\t\t\t// wrapper; resolve the editable element containing the selection.\n\t\t\tconst target =\n\t\t\t\t( event.target === node &&\n\t\t\t\t\tgetSelectionEditableElement(\n\t\t\t\t\t\tnode.ownerDocument.defaultView.getSelection(),\n\t\t\t\t\t\tnode\n\t\t\t\t\t) ) ||\n\t\t\t\tevent.target;\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 hasModifier = shiftKey || ctrlKey || altKey || 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 ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In preview mode, navigation is handled by useSelectableBlocksNav.\n\t\t\tif ( getSettings().isPreviewMode ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If there is a multi-selection, the arrow keys should collapse the\n\t\t\t// selection to the start or end of the selection.\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\tif ( shiftKey ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Only handle if we have a full selection (not a native partial\n\t\t\t\t// selection).\n\t\t\t\tif ( ! __unstableIsFullySelected() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tif ( isReverse ) {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksStartClientId() );\n\t\t\t\t} else {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksEndClientId(), -1 );\n\t\t\t\t}\n\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// 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// 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\n\t\t\tif ( shiftKey ) {\n\t\t\t\tif ( isNavEdge( target, isReverse ) ) {\n\t\t\t\t\tif ( isClosestTabbableABlock( target, isReverse ) ) {\n\t\t\t\t\t\tsetContentEditableWrapper( node, true );\n\t\t\t\t\t} else if ( node.contentEditable === 'true' ) {\n\t\t\t\t\t\t// There is no block to extend the selection into.\n\t\t\t\t\t\t// Within an editable wrapper the selection could\n\t\t\t\t\t\t// natively escape into surrounding editable elements\n\t\t\t\t\t\t// (e.g. the post title), so keep it inside the block\n\t\t\t\t\t\t// by extending it to the block's edge.\n\t\t\t\t\t\tconst selection = defaultView.getSelection();\n\t\t\t\t\t\tselection.extend(\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\tisReverse ? 0 : target.childNodes.length\n\t\t\t\t\t\t);\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t}\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// When Alt is pressed, only intercept if the caret is also at\n\t\t\t\t// the horizontal edge.\n\t\t\t\t( altKey ? isHorizontalEdge( target, isReverseDir ) : true ) &&\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\t// When Alt is pressed, place the caret at the furthest\n\t\t\t\t\t\t// horizontal edge and the furthest vertical edge.\n\t\t\t\t\t\taltKey ? ! isReverse : isReverse,\n\t\t\t\t\t\taltKey ? undefined : verticalRect\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"],
5
- "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,IAAI,MAAM,MAAM,aAAa;AACtC,SAAS,aAAa,iBAAiB;AACvC,SAAS,oBAAoB;AAK7B,SAAS,kBAAkB,mCAAmC;AAC9D,SAAS,SAAS,wBAAwB;AAC1C,SAAS,iCAAiC;AAYnC,SAAS,sBAAuB,SAAS,SAAS,aAAc;AACtE,QAAM,aAAa,YAAY,MAAM,YAAY;AACjD,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,cAAc,QAAQ,aAAc,MAAO;AAGjD,MAAK,cAAc,CAAE,aAAc;AAClC,QAAK,YAAY,SAAU;AAC1B,YAAM,qBAAqB;AAAA,QAC1B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,aAAO,CAAE,mBAAmB,SAAU,WAAY;AAAA,IACnD;AACA,WAAO;AAAA,EACR;AAGA,MAAK,YAAY,SAAU;AAC1B,UAAM,mBAAmB;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,WAAO,iBAAiB,SAAU,WAAY;AAAA,EAC/C;AAGA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,UAAW;AACf,YAAK,UAAW,QAAQ,SAAU,GAAI;AACrC,cAAK,wBAAyB,QAAQ,SAAU,GAAI;AACnD,sCAA2B,MAAM,IAAK;AAAA,UACvC,WAAY,KAAK,oBAAoB,QAAS;AAM7C,kBAAM,YAAY,YAAY,aAAa;AAC3C,sBAAU;AAAA,cACT;AAAA,cACA,YAAY,IAAI,OAAO,WAAW;AAAA,YACnC;AACA,kBAAM,eAAe;AAAA,UACtB;AAAA,QACD;AAAA,MACD,WACC,cACA,eAAgB,QAAQ,SAAU;AAAA;AAAA,OAGhC,SAAS,iBAAkB,QAAQ,YAAa,IAAI,SACtD,CAAE,sBACD;AACD,cAAM,kBAAkB;AAAA,UACvB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAEA,YAAK,iBAAkB;AACtB;AAAA,YACC;AAAA;AAAA;AAAA,YAGA,SAAS,CAAE,YAAY;AAAA,YACvB,SAAS,SAAY;AAAA,UACtB;AACA,gBAAM,eAAe;AAAA,QACtB;AAAA,MACD,WACC,gBACA,YAAY,aAAa,EAAE,eAC3B,iBAAkB,QAAQ,YAAa,KACvC,CAAE,sBACD;AACD,cAAM,kBAAkB;AAAA,UACvB;AAAA,UACA;AAAA,UACA;AAAA,QACD;AACA,mCAA4B,iBAAiB,SAAU;AACvD,cAAM,eAAe;AAAA,MACtB;AAAA,IACD;AAEA,SAAK,iBAAkB,aAAa,WAAY;AAChD,SAAK,iBAAkB,WAAW,SAAU;AAC5C,WAAO,MAAM;AACZ,WAAK,oBAAqB,aAAa,WAAY;AACnD,WAAK,oBAAqB,WAAW,SAAU;AAAA,IAChD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n\tisFormElement,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getBlockClientId, getSelectionEditableElement } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\nimport { setContentEditableWrapper } from './utils';\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\tconst { tagName } = element;\n\tconst elementType = element.getAttribute( 'type' );\n\n\t// Native inputs should not navigate vertically, unless they are simple types that don't need up/down arrow keys.\n\tif ( isVertical && ! hasModifier ) {\n\t\tif ( tagName === 'INPUT' ) {\n\t\t\tconst verticalInputTypes = [\n\t\t\t\t'date',\n\t\t\t\t'datetime-local',\n\t\t\t\t'month',\n\t\t\t\t'number',\n\t\t\t\t'range',\n\t\t\t\t'time',\n\t\t\t\t'week',\n\t\t\t];\n\t\t\treturn ! verticalInputTypes.includes( elementType );\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.\n\tif ( tagName === 'INPUT' ) {\n\t\tconst simpleInputTypes = [\n\t\t\t'button',\n\t\t\t'checkbox',\n\t\t\t'number',\n\t\t\t'color',\n\t\t\t'file',\n\t\t\t'image',\n\t\t\t'radio',\n\t\t\t'reset',\n\t\t\t'submit',\n\t\t];\n\t\treturn simpleInputTypes.includes( elementType );\n\t}\n\n\t// Native textareas should not navigate horizontally.\n\treturn 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();\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// If it's a block wrapper (not itself a contenteditable editing surface)\n\t\t// and there are nested focusable nodes, skip because there are better\n\t\t// candidates. We must not skip contenteditable nodes that happen to\n\t\t// contain links or other focusable inline elements, since those are the\n\t\t// correct navigation targets.\n\t\t//\n\t\t// See https://github.com/WordPress/gutenberg/pull/77474\n\t\t// TODO: Consider fixing focus.tabbable\n\t\tif (\n\t\t\tnode.contentEditable !== 'true' &&\n\t\t\tgetBlockClientId( node ) &&\n\t\t\tfocus.focusable\n\t\t\t\t.find( node )\n\t\t\t\t// Exclude form elements for now because primary+a cannot be\n\t\t\t\t// used to select the parent element.\n\t\t\t\t.filter( ( element ) => ! isFormElement( element ) ).length !==\n\t\t\t\t0\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\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\n\t\t// nodes: nodes whose closest editable host is an editable element\n\t\t// within a block. When an editable root (e.g. the canvas wrapper)\n\t\t// is the editing host, everything within it is content editable,\n\t\t// but focusables like block wrappers are not text content.\n\t\tif (\n\t\t\tnode.isContentEditable &&\n\t\t\tnode.contentEditable !== 'true' &&\n\t\t\tgetBlockClientId( node.closest( '[contenteditable=\"true\"]' ) )\n\t\t) {\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 focusableNodes.find( isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetNextBlockClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetSelectedBlockClientId,\n\t\tgetSelectionStart,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t\t__unstableIsFullySelected,\n\t} = useSelect( blockEditorStore );\n\tconst { selectBlock, multiSelect } = 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 isClosestTabbableABlock( 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 closestTabbable && getBlockClientId( closestTabbable );\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\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\tconst { keyCode, shiftKey, ctrlKey, altKey, metaKey } = event;\n\t\t\t// When the wrapper is contentEditable and holds focus (the\n\t\t\t// selected block supports `editableRoot`), the event targets the\n\t\t\t// wrapper; resolve the editable element containing the selection.\n\t\t\tconst target =\n\t\t\t\t( event.target === node &&\n\t\t\t\t\tgetSelectionEditableElement(\n\t\t\t\t\t\tnode.ownerDocument.defaultView.getSelection(),\n\t\t\t\t\t\tnode\n\t\t\t\t\t) ) ||\n\t\t\t\tevent.target;\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 hasModifier = shiftKey || ctrlKey || altKey || 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 ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In preview mode, navigation is handled by useSelectableBlocksNav.\n\t\t\tif ( getSettings().isPreviewMode ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If there is a multi-selection, the arrow keys should collapse the\n\t\t\t// selection to the start or end of the selection.\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\tif ( shiftKey ) {\n\t\t\t\t\t// A fully selected multi-selection has no native\n\t\t\t\t\t// selection to extend (use-multi-selection cleared it),\n\t\t\t\t\t// so grow or shrink it by one block at the focus end.\n\t\t\t\t\t// Only without a usable native selection: a selection\n\t\t\t\t\t// that is fully selected because it resolves to a\n\t\t\t\t\t// nesting ancestor keeps its native selection, which\n\t\t\t\t\t// the browser extends natively (and the observer\n\t\t\t\t\t// promotes to the common level).\n\t\t\t\t\tconst selection = defaultView.getSelection();\n\t\t\t\t\tif (\n\t\t\t\t\t\t__unstableIsFullySelected() &&\n\t\t\t\t\t\t( ! selection.rangeCount || selection.isCollapsed )\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst anchorClientId =\n\t\t\t\t\t\t\tgetMultiSelectedBlocksStartClientId();\n\t\t\t\t\t\tconst focusClientId =\n\t\t\t\t\t\t\tgetMultiSelectedBlocksEndClientId();\n\t\t\t\t\t\tconst nextClientId = isReverse\n\t\t\t\t\t\t\t? getPreviousBlockClientId( focusClientId )\n\t\t\t\t\t\t\t: getNextBlockClientId( focusClientId );\n\n\t\t\t\t\t\tif ( nextClientId ) {\n\t\t\t\t\t\t\tmultiSelect( anchorClientId, nextClientId );\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Only handle if we have a full selection (not a native partial\n\t\t\t\t// selection).\n\t\t\t\tif ( ! __unstableIsFullySelected() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tif ( isReverse ) {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksStartClientId() );\n\t\t\t\t} else {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksEndClientId(), -1 );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// A block selected without a text selection within it (e.g. an\n\t\t\t// image or spacer) has no native selection to extend: start a\n\t\t\t// block multi-selection with the adjacent block.\n\t\t\tif (\n\t\t\t\tshiftKey &&\n\t\t\t\tgetSelectedBlockClientId() &&\n\t\t\t\t! getSelectionStart().attributeKey\n\t\t\t) {\n\t\t\t\tconst selectedClientId = getSelectedBlockClientId();\n\t\t\t\tconst nextClientId = isReverse\n\t\t\t\t\t? getPreviousBlockClientId( selectedClientId )\n\t\t\t\t\t: getNextBlockClientId( selectedClientId );\n\n\t\t\t\tif ( nextClientId ) {\n\t\t\t\t\tmultiSelect( selectedClientId, nextClientId );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\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// 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// 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\n\t\t\tif ( shiftKey ) {\n\t\t\t\tif ( isNavEdge( target, isReverse ) ) {\n\t\t\t\t\tif ( isClosestTabbableABlock( target, isReverse ) ) {\n\t\t\t\t\t\tsetContentEditableWrapper( node, true );\n\t\t\t\t\t} else if ( node.contentEditable === 'true' ) {\n\t\t\t\t\t\t// There is no block to extend the selection into.\n\t\t\t\t\t\t// Within an editable wrapper the selection could\n\t\t\t\t\t\t// natively escape into surrounding editable elements\n\t\t\t\t\t\t// (e.g. the post title), so keep it inside the block\n\t\t\t\t\t\t// by extending it to the block's edge.\n\t\t\t\t\t\tconst selection = defaultView.getSelection();\n\t\t\t\t\t\tselection.extend(\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\tisReverse ? 0 : target.childNodes.length\n\t\t\t\t\t\t);\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t}\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// When Alt is pressed, only intercept if the caret is also at\n\t\t\t\t// the horizontal edge.\n\t\t\t\t( altKey ? isHorizontalEdge( target, isReverseDir ) : true ) &&\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\t// When Alt is pressed, place the caret at the furthest\n\t\t\t\t\t\t// horizontal edge and the furthest vertical edge.\n\t\t\t\t\t\taltKey ? ! isReverse : isReverse,\n\t\t\t\t\t\taltKey ? undefined : verticalRect\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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,IAChD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
6
6
  "names": []
7
7
  }
@@ -6,7 +6,12 @@ import { setContentEditableWrapper } from "./utils.mjs";
6
6
  import { getBlockClientId } from "../../utils/dom.mjs";
7
7
  function useClickSelection() {
8
8
  const { selectBlock } = useDispatch(blockEditorStore);
9
- const { isSelectionEnabled, getBlockSelectionStart, hasMultiSelection } = useSelect(blockEditorStore);
9
+ const {
10
+ isSelectionEnabled,
11
+ getBlockSelectionStart,
12
+ getSelectionStart,
13
+ hasMultiSelection
14
+ } = useSelect(blockEditorStore);
10
15
  return useRefEffect(
11
16
  (node) => {
12
17
  function onMouseDown(event) {
@@ -17,7 +22,27 @@ function useClickSelection() {
17
22
  const clickedClientId = getBlockClientId(event.target);
18
23
  if (event.shiftKey) {
19
24
  if (startClientId && startClientId !== clickedClientId) {
20
- setContentEditableWrapper(node, true);
25
+ const { clientId, attributeKey } = getSelectionStart();
26
+ setContentEditableWrapper(node, true, {
27
+ focus: !!attributeKey
28
+ });
29
+ const { ownerDocument } = node;
30
+ const selection = ownerDocument.defaultView.getSelection();
31
+ const blockElement = !attributeKey && ownerDocument.getElementById(
32
+ `block-${clientId}`
33
+ );
34
+ if (blockElement && !(selection.anchorNode && blockElement.contains(selection.anchorNode))) {
35
+ const isForward = (
36
+ // eslint-disable-next-line no-bitwise
37
+ blockElement.compareDocumentPosition(
38
+ event.target
39
+ ) & node.DOCUMENT_POSITION_FOLLOWING
40
+ );
41
+ selection.setPosition(
42
+ blockElement,
43
+ isForward ? 0 : blockElement.childNodes.length
44
+ );
45
+ }
21
46
  }
22
47
  } else if (hasMultiSelection()) {
23
48
  selectBlock(clickedClientId);
@@ -32,6 +57,7 @@ function useClickSelection() {
32
57
  selectBlock,
33
58
  isSelectionEnabled,
34
59
  getBlockSelectionStart,
60
+ getSelectionStart,
35
61
  hasMultiSelection
36
62
  ]
37
63
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/writing-flow/use-click-selection.js"],
4
- "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 { setContentEditableWrapper } from './utils';\nimport { getBlockClientId } from '../../utils/dom';\n\nexport default function useClickSelection() {\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst { isSelectionEnabled, getBlockSelectionStart, hasMultiSelection } =\n\t\tuseSelect( 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\t// When selecting a single block in a document by holding the shift key,\n\t\t\t\t\t// don't mark this action as multiselection.\n\t\t\t\t\tif ( startClientId && startClientId !== clickedClientId ) {\n\t\t\t\t\t\tsetContentEditableWrapper( node, true );\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\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tgetBlockSelectionStart,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,WAAW,mBAAmB;AACvC,SAAS,oBAAoB;AAK7B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;AAElB,SAAR,oBAAqC;AAC3C,QAAM,EAAE,YAAY,IAAI,YAAa,gBAAiB;AACtD,QAAM,EAAE,oBAAoB,wBAAwB,kBAAkB,IACrE,UAAW,gBAAiB;AAC7B,SAAO;AAAA,IACN,CAAE,SAAU;AACX,eAAS,YAAa,OAAQ;AAG7B,YAAK,CAAE,mBAAmB,KAAK,MAAM,WAAW,GAAI;AACnD;AAAA,QACD;AAEA,cAAM,gBAAgB,uBAAuB;AAC7C,cAAM,kBAAkB,iBAAkB,MAAM,MAAO;AAEvD,YAAK,MAAM,UAAW;AAGrB,cAAK,iBAAiB,kBAAkB,iBAAkB;AACzD,sCAA2B,MAAM,IAAK;AAAA,UACvC;AAAA,QACD,WAAY,kBAAkB,GAAI;AAOjC,sBAAa,eAAgB;AAAA,QAC9B;AAAA,MACD;AAEA,WAAK,iBAAkB,aAAa,WAAY;AAEhD,aAAO,MAAM;AACZ,aAAK,oBAAqB,aAAa,WAAY;AAAA,MACpD;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;",
4
+ "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 { setContentEditableWrapper } from './utils';\nimport { getBlockClientId } from '../../utils/dom';\n\nexport default function useClickSelection() {\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst {\n\t\tisSelectionEnabled,\n\t\tgetBlockSelectionStart,\n\t\tgetSelectionStart,\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\t// When selecting a single block in a document by holding the shift key,\n\t\t\t\t\t// don't mark this action as multiselection.\n\t\t\t\t\tif ( startClientId && startClientId !== clickedClientId ) {\n\t\t\t\t\t\t// When the selected block has no text selection\n\t\t\t\t\t\t// within it (e.g. an image or spacer), there is no\n\t\t\t\t\t\t// native selection for the wrapper to adopt when it\n\t\t\t\t\t\t// is focused, so Safari inserts a caret at the start\n\t\t\t\t\t\t// of the wrapper and asynchronously reveals it,\n\t\t\t\t\t\t// scrolling a scrolled-down viewport back up, which\n\t\t\t\t\t\t// `preventScroll` does not cover. Leave focus alone\n\t\t\t\t\t\t// in that case: the click moves it.\n\t\t\t\t\t\tconst { clientId, attributeKey } = getSelectionStart();\n\t\t\t\t\t\tsetContentEditableWrapper( node, true, {\n\t\t\t\t\t\t\tfocus: !! attributeKey,\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// The browser extends the selection from the native\n\t\t\t\t\t\t// anchor. When a block is selected without a text\n\t\t\t\t\t\t// selection within it, there is no native anchor,\n\t\t\t\t\t\t// and browsers synthesize one at the nearest text\n\t\t\t\t\t\t// instead, excluding the block itself. Give the\n\t\t\t\t\t\t// browser the right anchor before it acts on the\n\t\t\t\t\t\t// click: the near edge of the selected block, so the\n\t\t\t\t\t\t// whole block ends up within the extended selection.\n\t\t\t\t\t\tconst { ownerDocument } = node;\n\t\t\t\t\t\tconst selection =\n\t\t\t\t\t\t\townerDocument.defaultView.getSelection();\n\t\t\t\t\t\tconst blockElement =\n\t\t\t\t\t\t\t! attributeKey &&\n\t\t\t\t\t\t\townerDocument.getElementById(\n\t\t\t\t\t\t\t\t`block-${ clientId }`\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tblockElement &&\n\t\t\t\t\t\t\t! (\n\t\t\t\t\t\t\t\tselection.anchorNode &&\n\t\t\t\t\t\t\t\tblockElement.contains( selection.anchorNode )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tconst isForward =\n\t\t\t\t\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\t\t\t\t\tblockElement.compareDocumentPosition(\n\t\t\t\t\t\t\t\t\tevent.target\n\t\t\t\t\t\t\t\t) & node.DOCUMENT_POSITION_FOLLOWING;\n\t\t\t\t\t\t\tselection.setPosition(\n\t\t\t\t\t\t\t\tblockElement,\n\t\t\t\t\t\t\t\tisForward ? 0 : blockElement.childNodes.length\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else 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\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tgetBlockSelectionStart,\n\t\t\tgetSelectionStart,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"],
5
+ "mapp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ACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,154 @@
1
+ // packages/block-editor/src/components/writing-flow/use-editable-root-event-handlers.js
2
+ import { useSelect } from "@wordpress/data";
3
+ import { useRefEffect } from "@wordpress/compose";
4
+ import { useContext } from "@wordpress/element";
5
+ import { store as blockEditorStore } from "../../store/index.mjs";
6
+ import { getBlockClientId, getSelectionEditableElement } from "../../utils/dom.mjs";
7
+ import { BlockRefs } from "../provider/block-refs-provider.mjs";
8
+ var SUPPORTED_EVENTS = {
9
+ onKeyDown: "keydown",
10
+ onKeyUp: "keyup",
11
+ onBeforeInput: "beforeinput",
12
+ onInput: "input",
13
+ onCompositionStart: "compositionstart",
14
+ onCompositionUpdate: "compositionupdate",
15
+ onCompositionEnd: "compositionend"
16
+ };
17
+ var EVENT_TYPES = Object.values(SUPPORTED_EVENTS);
18
+ function getEventHandlers(props) {
19
+ let handlers;
20
+ for (const name in SUPPORTED_EVENTS) {
21
+ if (typeof props[name] === "function") {
22
+ handlers = handlers || {};
23
+ handlers[SUPPORTED_EVENTS[name]] = props[name];
24
+ }
25
+ }
26
+ return handlers;
27
+ }
28
+ var EVENT_INTERFACE = [
29
+ "eventPhase",
30
+ "bubbles",
31
+ "cancelable",
32
+ "timeStamp",
33
+ "defaultPrevented",
34
+ "isTrusted"
35
+ ];
36
+ var KEYBOARD_EVENT_INTERFACE = [
37
+ ...EVENT_INTERFACE,
38
+ "view",
39
+ "detail",
40
+ "key",
41
+ "code",
42
+ "location",
43
+ "ctrlKey",
44
+ "shiftKey",
45
+ "altKey",
46
+ "metaKey",
47
+ "repeat",
48
+ "locale",
49
+ "getModifierState",
50
+ "charCode",
51
+ "keyCode",
52
+ "which"
53
+ ];
54
+ var INPUT_EVENT_INTERFACE = [...EVENT_INTERFACE, "data"];
55
+ var EVENT_INTERFACES = {
56
+ keydown: KEYBOARD_EVENT_INTERFACE,
57
+ keyup: KEYBOARD_EVENT_INTERFACE,
58
+ beforeinput: INPUT_EVENT_INTERFACE,
59
+ input: INPUT_EVENT_INTERFACE,
60
+ compositionstart: INPUT_EVENT_INTERFACE,
61
+ compositionupdate: INPUT_EVENT_INTERFACE,
62
+ compositionend: INPUT_EVENT_INTERFACE
63
+ };
64
+ function createBlockSyntheticEvent(nativeEvent, target) {
65
+ let propagationStopped = false;
66
+ const syntheticEvent = {
67
+ nativeEvent,
68
+ type: nativeEvent.type,
69
+ target,
70
+ currentTarget: null,
71
+ preventDefault() {
72
+ nativeEvent.preventDefault();
73
+ syntheticEvent.defaultPrevented = true;
74
+ },
75
+ isDefaultPrevented() {
76
+ return syntheticEvent.defaultPrevented;
77
+ },
78
+ stopPropagation() {
79
+ nativeEvent.stopPropagation();
80
+ propagationStopped = true;
81
+ },
82
+ isPropagationStopped() {
83
+ return propagationStopped;
84
+ },
85
+ // The modern event system doesn't pool, so persistence is a no-op.
86
+ persist() {
87
+ },
88
+ isPersistent() {
89
+ return true;
90
+ }
91
+ };
92
+ for (const property of EVENT_INTERFACES[nativeEvent.type]) {
93
+ const value = nativeEvent[property];
94
+ syntheticEvent[property] = typeof value === "function" ? value.bind(nativeEvent) : value;
95
+ }
96
+ return syntheticEvent;
97
+ }
98
+ function useEditableRootEventHandlers() {
99
+ const { hasMultiSelection, getBlockParents } = useSelect(blockEditorStore);
100
+ const { refsMap, eventHandlers } = useContext(BlockRefs);
101
+ return useRefEffect(
102
+ (node) => {
103
+ function onEvent(event) {
104
+ if (!eventHandlers.size || event.target !== node || !event.isTrusted || node.contentEditable !== "true" || hasMultiSelection()) {
105
+ return;
106
+ }
107
+ const selection = node.ownerDocument.defaultView.getSelection();
108
+ if (!selection.rangeCount) {
109
+ return;
110
+ }
111
+ const editable = getSelectionEditableElement(selection, node);
112
+ const clientId = getBlockClientId(editable);
113
+ if (!clientId) {
114
+ return;
115
+ }
116
+ const clientIds = [
117
+ clientId,
118
+ ...getBlockParents(clientId, true)
119
+ ];
120
+ let syntheticEvent;
121
+ for (const ancestorClientId of clientIds) {
122
+ const handler = eventHandlers.get(ancestorClientId)?.current?.[event.type];
123
+ const element = handler && refsMap.get(ancestorClientId);
124
+ if (!element) {
125
+ continue;
126
+ }
127
+ if (!syntheticEvent) {
128
+ syntheticEvent = createBlockSyntheticEvent(
129
+ event,
130
+ editable
131
+ );
132
+ }
133
+ syntheticEvent.currentTarget = element;
134
+ handler(syntheticEvent);
135
+ if (syntheticEvent.isPropagationStopped()) {
136
+ break;
137
+ }
138
+ }
139
+ }
140
+ const root = node.ownerDocument.documentElement;
141
+ const unsubscribers = EVENT_TYPES.map((type) => {
142
+ root.addEventListener(type, onEvent);
143
+ return () => root.removeEventListener(type, onEvent);
144
+ });
145
+ return () => unsubscribers.forEach((unsubscribe) => unsubscribe());
146
+ },
147
+ [hasMultiSelection, getBlockParents, refsMap, eventHandlers]
148
+ );
149
+ }
150
+ export {
151
+ useEditableRootEventHandlers as default,
152
+ getEventHandlers
153
+ };
154
+ //# sourceMappingURL=use-editable-root-event-handlers.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/writing-flow/use-editable-root-event-handlers.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId, getSelectionEditableElement } from '../../utils/dom';\nimport { BlockRefs } from '../provider/block-refs-provider';\n\n// The React `on*` props the host bridges, mapped to their DOM event type. Only\n// editing events are redirected under `editableRoot` (the wrapper becomes the\n// editing host, so keyboard, input and composition events target it instead of\n// the block); pointer and other events still reach the block and need no\n// bridging. React prop names don't map to DOM types by lowercasing in general\n// (onChange is `input`, onDoubleClick is `dblclick`), so the mapping is\n// explicit, which also locks the bridged surface to events React actually fires.\nconst SUPPORTED_EVENTS = {\n\tonKeyDown: 'keydown',\n\tonKeyUp: 'keyup',\n\tonBeforeInput: 'beforeinput',\n\tonInput: 'input',\n\tonCompositionStart: 'compositionstart',\n\tonCompositionUpdate: 'compositionupdate',\n\tonCompositionEnd: 'compositionend',\n};\n\n// The DOM event types the host listens for. Fixed, so the host attaches these\n// listeners once rather than tracking which types are in use.\nconst EVENT_TYPES = Object.values( SUPPORTED_EVENTS );\n\n/**\n * Collects the supported `on*` event handlers from a set of props, e.g. a\n * block's merged `wrapperProps`, keyed by DOM event type. Used by the block to\n * register them (see `useRegisterBlockEventHandlers`).\n *\n * @param {Object} props Props to read handlers from.\n *\n * @return {Object|undefined} The handlers by event type, or undefined when\n * there are none.\n */\nexport function getEventHandlers( props ) {\n\tlet handlers;\n\n\tfor ( const name in SUPPORTED_EVENTS ) {\n\t\tif ( typeof props[ name ] === 'function' ) {\n\t\t\thandlers = handlers || {};\n\t\t\thandlers[ SUPPORTED_EVENTS[ name ] ] = props[ name ];\n\t\t}\n\t}\n\n\treturn handlers;\n}\n\n// The native properties React copies onto its SyntheticEvent for each event\n// type (the *EventInterface tables in react-dom), so the wrapper exposes exactly\n// what a React handler would see and nothing more. Values are copied straight\n// from the native event; React's normalizers only paper over browsers we don't\n// support, and anything omitted stays reachable through `nativeEvent`, as in\n// React (e.g. `getTargetRanges` on a `beforeinput`).\nconst EVENT_INTERFACE = [\n\t'eventPhase',\n\t'bubbles',\n\t'cancelable',\n\t'timeStamp',\n\t'defaultPrevented',\n\t'isTrusted',\n];\nconst KEYBOARD_EVENT_INTERFACE = [\n\t...EVENT_INTERFACE,\n\t'view',\n\t'detail',\n\t'key',\n\t'code',\n\t'location',\n\t'ctrlKey',\n\t'shiftKey',\n\t'altKey',\n\t'metaKey',\n\t'repeat',\n\t'locale',\n\t'getModifierState',\n\t'charCode',\n\t'keyCode',\n\t'which',\n];\nconst INPUT_EVENT_INTERFACE = [ ...EVENT_INTERFACE, 'data' ];\nconst EVENT_INTERFACES = {\n\tkeydown: KEYBOARD_EVENT_INTERFACE,\n\tkeyup: KEYBOARD_EVENT_INTERFACE,\n\tbeforeinput: INPUT_EVENT_INTERFACE,\n\tinput: INPUT_EVENT_INTERFACE,\n\tcompositionstart: INPUT_EVENT_INTERFACE,\n\tcompositionupdate: INPUT_EVENT_INTERFACE,\n\tcompositionend: INPUT_EVENT_INTERFACE,\n};\n\n/**\n * Builds a React `SyntheticEvent`-like object for an extension handler, which\n * expects one. It mirrors what react-dom does: a plain object wrapping the real\n * native event, eagerly copying the same interface properties React exposes for\n * the event type, so a handler sees exactly React's surface and nothing more.\n *\n * `preventDefault` and `stopPropagation` forward to the native event, so they\n * behave as through React; `stopPropagation` also flags the walk through block\n * ancestors to stop. `target` is the editable inside the block rather than the\n * real target (the editing host above it), and `currentTarget` is reassigned as\n * the event bubbles from block to block.\n *\n * @param {Event} nativeEvent The event to wrap.\n * @param {HTMLElement} target The element to report as the target.\n *\n * @return {Object} The synthetic event.\n */\nfunction createBlockSyntheticEvent( nativeEvent, target ) {\n\tlet propagationStopped = false;\n\n\tconst syntheticEvent = {\n\t\tnativeEvent,\n\t\ttype: nativeEvent.type,\n\t\ttarget,\n\t\tcurrentTarget: null,\n\t\tpreventDefault() {\n\t\t\tnativeEvent.preventDefault();\n\t\t\tsyntheticEvent.defaultPrevented = true;\n\t\t},\n\t\tisDefaultPrevented() {\n\t\t\treturn syntheticEvent.defaultPrevented;\n\t\t},\n\t\tstopPropagation() {\n\t\t\tnativeEvent.stopPropagation();\n\t\t\tpropagationStopped = true;\n\t\t},\n\t\tisPropagationStopped() {\n\t\t\treturn propagationStopped;\n\t\t},\n\t\t// The modern event system doesn't pool, so persistence is a no-op.\n\t\tpersist() {},\n\t\tisPersistent() {\n\t\t\treturn true;\n\t\t},\n\t};\n\n\tfor ( const property of EVENT_INTERFACES[ nativeEvent.type ] ) {\n\t\tconst value = nativeEvent[ property ];\n\t\tsyntheticEvent[ property ] =\n\t\t\ttypeof value === 'function' ? value.bind( nativeEvent ) : value;\n\t}\n\n\treturn syntheticEvent;\n}\n\n/**\n * Backwards compatibility for block event handlers under `editableRoot`.\n *\n * When a block supports `editableRoot`, the writing flow wrapper is the\n * contentEditable editing host, so keyboard, input and composition events\n * target the wrapper instead of the block. React `on*` handlers a third party\n * added to a block through `wrapperProps` (e.g. via an `editor.BlockListBlock`\n * filter) are on the block element, below the target, so they stop firing.\n *\n * The block registers those handlers (see `useBlockProps`), and this hook\n * calls them from the host: it resolves the block that owns the selection and\n * every block ancestor, and invokes each registered handler with a synthetic\n * event, innermost first, like a bubbling event. The listeners are attached\n * where React attaches its own (the portal container, the iframe's document\n * element), so a block's handler runs and its `preventDefault` /\n * `stopPropagation` behave as they would through React, without editableRoot.\n *\n * This does not cover handlers a filter puts on its own wrapping element rather\n * than the block's `wrapperProps`; the block element is the supported event\n * surface. It can be removed once input handling is lifted to the host.\n */\nexport default function useEditableRootEventHandlers() {\n\tconst { hasMultiSelection, getBlockParents } =\n\t\tuseSelect( blockEditorStore );\n\tconst { refsMap, eventHandlers } = useContext( BlockRefs );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tfunction onEvent( event ) {\n\t\t\t\t// Only act on real events targeting the host itself, while it\n\t\t\t\t// is the editing host for a single block and some block has a\n\t\t\t\t// handler to call.\n\t\t\t\tif (\n\t\t\t\t\t! eventHandlers.size ||\n\t\t\t\t\tevent.target !== node ||\n\t\t\t\t\t! event.isTrusted ||\n\t\t\t\t\tnode.contentEditable !== 'true' ||\n\t\t\t\t\thasMultiSelection()\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst selection = node.ownerDocument.defaultView.getSelection();\n\n\t\t\t\tif ( ! selection.rangeCount ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst editable = getSelectionEditableElement( selection, node );\n\t\t\t\tconst clientId = getBlockClientId( editable );\n\n\t\t\t\tif ( ! clientId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Call the handler on the block that owns the selection and each\n\t\t\t\t// of its block ancestors, innermost first, like a bubbling\n\t\t\t\t// event. The hierarchy comes from the store rather than the DOM,\n\t\t\t\t// and one synthetic event, wrapping the real event, is reused\n\t\t\t\t// for the whole chain, its currentTarget moved from block to\n\t\t\t\t// block. The element is only resolved for blocks with a handler.\n\t\t\t\tconst clientIds = [\n\t\t\t\t\tclientId,\n\t\t\t\t\t...getBlockParents( clientId, true ),\n\t\t\t\t];\n\n\t\t\t\tlet syntheticEvent;\n\t\t\t\tfor ( const ancestorClientId of clientIds ) {\n\t\t\t\t\tconst handler =\n\t\t\t\t\t\teventHandlers.get( ancestorClientId )?.current?.[\n\t\t\t\t\t\t\tevent.type\n\t\t\t\t\t\t];\n\t\t\t\t\tconst element = handler && refsMap.get( ancestorClientId );\n\n\t\t\t\t\tif ( ! element ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( ! syntheticEvent ) {\n\t\t\t\t\t\tsyntheticEvent = createBlockSyntheticEvent(\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\teditable\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tsyntheticEvent.currentTarget = element;\n\t\t\t\t\thandler( syntheticEvent );\n\n\t\t\t\t\tif ( syntheticEvent.isPropagationStopped() ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Attach where React attaches its own event system: the portal\n\t\t\t// container, which for the iframed canvas is the document element\n\t\t\t// (see `preparePortalMount` in react-dom). Listening at the same\n\t\t\t// node, non-capture, means a block's handler runs in the bubbling\n\t\t\t// phase after core, and its stopPropagation stops at the same point\n\t\t\t// React's would, as its `on*` handler would without editableRoot.\n\t\t\tconst root = node.ownerDocument.documentElement;\n\t\t\tconst unsubscribers = EVENT_TYPES.map( ( type ) => {\n\t\t\t\troot.addEventListener( type, onEvent );\n\t\t\t\treturn () => root.removeEventListener( type, onEvent );\n\t\t\t} );\n\t\t\treturn () =>\n\t\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe() );\n\t\t},\n\t\t[ hasMultiSelection, getBlockParents, refsMap, eventHandlers ]\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAK3B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,kBAAkB,mCAAmC;AAC9D,SAAS,iBAAiB;AAS1B,IAAM,mBAAmB;AAAA,EACxB,WAAW;AAAA,EACX,SAAS;AAAA,EACT,eAAe;AAAA,EACf,SAAS;AAAA,EACT,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EACrB,kBAAkB;AACnB;AAIA,IAAM,cAAc,OAAO,OAAQ,gBAAiB;AAY7C,SAAS,iBAAkB,OAAQ;AACzC,MAAI;AAEJ,aAAY,QAAQ,kBAAmB;AACtC,QAAK,OAAO,MAAO,IAAK,MAAM,YAAa;AAC1C,iBAAW,YAAY,CAAC;AACxB,eAAU,iBAAkB,IAAK,CAAE,IAAI,MAAO,IAAK;AAAA,IACpD;AAAA,EACD;AAEA,SAAO;AACR;AAQA,IAAM,kBAAkB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AACA,IAAM,2BAA2B;AAAA,EAChC,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AACA,IAAM,wBAAwB,CAAE,GAAG,iBAAiB,MAAO;AAC3D,IAAM,mBAAmB;AAAA,EACxB,SAAS;AAAA,EACT,OAAO;AAAA,EACP,aAAa;AAAA,EACb,OAAO;AAAA,EACP,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB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