@wordpress/block-editor 10.2.0 → 10.4.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 (482) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +41 -0
  3. package/build/components/alignment-control/ui.js +1 -1
  4. package/build/components/alignment-control/ui.js.map +1 -1
  5. package/build/components/block-alignment-control/constants.js +1 -1
  6. package/build/components/block-alignment-control/constants.js.map +1 -1
  7. package/build/components/block-alignment-matrix-control/index.js +1 -1
  8. package/build/components/block-alignment-matrix-control/index.js.map +1 -1
  9. package/build/components/block-compare/index.js +1 -3
  10. package/build/components/block-compare/index.js.map +1 -1
  11. package/build/components/block-draggable/draggable-chip.js +4 -2
  12. package/build/components/block-draggable/draggable-chip.js.map +1 -1
  13. package/build/components/block-edit/index.js +4 -2
  14. package/build/components/block-edit/index.js.map +1 -1
  15. package/build/components/block-inspector/index.js +4 -4
  16. package/build/components/block-inspector/index.js.map +1 -1
  17. package/build/components/block-list/block-list-compact.native.js +1 -0
  18. package/build/components/block-list/block-list-compact.native.js.map +1 -1
  19. package/build/components/block-list/block.js +75 -15
  20. package/build/components/block-list/block.js.map +1 -1
  21. package/build/components/block-list/block.native.js +79 -12
  22. package/build/components/block-list/block.native.js.map +1 -1
  23. package/build/components/block-list/use-in-between-inserter.js +7 -23
  24. package/build/components/block-list/use-in-between-inserter.js.map +1 -1
  25. package/build/components/block-lock/modal.js +9 -6
  26. package/build/components/block-lock/modal.js.map +1 -1
  27. package/build/components/block-parent-selector/index.js +3 -3
  28. package/build/components/block-parent-selector/index.js.map +1 -1
  29. package/build/components/block-patterns-list/index.js +5 -4
  30. package/build/components/block-patterns-list/index.js.map +1 -1
  31. package/build/components/block-popover/drop-zone.js +85 -0
  32. package/build/components/block-popover/drop-zone.js.map +1 -0
  33. package/build/components/block-popover/inbetween.js +2 -1
  34. package/build/components/block-popover/inbetween.js.map +1 -1
  35. package/build/components/block-popover/index.js +4 -2
  36. package/build/components/block-popover/index.js.map +1 -1
  37. package/build/components/block-preview/auto.js +2 -2
  38. package/build/components/block-preview/auto.js.map +1 -1
  39. package/build/components/block-preview/index.js +8 -13
  40. package/build/components/block-preview/index.js.map +1 -1
  41. package/build/components/block-preview/live.js +3 -7
  42. package/build/components/block-preview/live.js.map +1 -1
  43. package/build/components/block-selection-clearer/index.js +9 -1
  44. package/build/components/block-selection-clearer/index.js.map +1 -1
  45. package/build/components/block-settings-menu/block-settings-dropdown.js +19 -19
  46. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  47. package/build/components/block-styles/index.js +18 -42
  48. package/build/components/block-styles/index.js.map +1 -1
  49. package/build/components/block-switcher/index.js +2 -8
  50. package/build/components/block-switcher/index.js.map +1 -1
  51. package/build/components/block-switcher/preview-block-popover.js +1 -1
  52. package/build/components/block-switcher/preview-block-popover.js.map +1 -1
  53. package/build/components/block-toolbar/index.js +4 -4
  54. package/build/components/block-toolbar/index.js.map +1 -1
  55. package/build/components/block-tools/back-compat.js +2 -1
  56. package/build/components/block-tools/back-compat.js.map +1 -1
  57. package/build/components/block-tools/insertion-point.js +56 -16
  58. package/build/components/block-tools/insertion-point.js.map +1 -1
  59. package/build/components/block-tools/selected-block-popover.js +15 -3
  60. package/build/components/block-tools/selected-block-popover.js.map +1 -1
  61. package/build/components/block-vertical-alignment-control/ui.js +1 -1
  62. package/build/components/block-vertical-alignment-control/ui.js.map +1 -1
  63. package/build/components/border-radius-control/all-input-control.js +2 -1
  64. package/build/components/border-radius-control/all-input-control.js.map +1 -1
  65. package/build/components/border-radius-control/index.js +2 -1
  66. package/build/components/border-radius-control/index.js.map +1 -1
  67. package/build/components/border-radius-control/input-controls.js +2 -1
  68. package/build/components/border-radius-control/input-controls.js.map +1 -1
  69. package/build/components/colors-gradients/control.js +1 -1
  70. package/build/components/colors-gradients/control.js.map +1 -1
  71. package/build/components/colors-gradients/panel-color-gradient-settings.js +2 -2
  72. package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  73. package/build/components/duotone-control/index.js +1 -1
  74. package/build/components/duotone-control/index.js.map +1 -1
  75. package/build/components/font-sizes/fluid-utils.js +256 -0
  76. package/build/components/font-sizes/fluid-utils.js.map +1 -0
  77. package/build/components/font-sizes/index.js +8 -0
  78. package/build/components/font-sizes/index.js.map +1 -1
  79. package/build/components/font-sizes/with-font-sizes.js +1 -1
  80. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  81. package/build/components/iframe/index.js +1 -1
  82. package/build/components/iframe/index.js.map +1 -1
  83. package/build/components/image-editor/constants.js +1 -1
  84. package/build/components/image-editor/constants.js.map +1 -1
  85. package/build/components/index.js +0 -9
  86. package/build/components/index.js.map +1 -1
  87. package/build/components/inner-blocks/index.js +6 -2
  88. package/build/components/inner-blocks/index.js.map +1 -1
  89. package/build/components/inner-blocks/use-inner-block-template-sync.js +3 -2
  90. package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
  91. package/build/components/inserter/block-patterns-tab.js +151 -78
  92. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  93. package/build/components/inserter/hooks/use-insertion-point.js +2 -7
  94. package/build/components/inserter/hooks/use-insertion-point.js.map +1 -1
  95. package/build/components/inserter/menu.js +14 -3
  96. package/build/components/inserter/menu.js.map +1 -1
  97. package/build/components/inserter/search-items.js +23 -2
  98. package/build/components/inserter/search-items.js.map +1 -1
  99. package/build/components/inserter-draggable-blocks/index.js +4 -2
  100. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  101. package/build/components/line-height-control/index.js +2 -1
  102. package/build/components/line-height-control/index.js.map +1 -1
  103. package/build/components/list-view/drop-indicator.js +2 -1
  104. package/build/components/list-view/drop-indicator.js.map +1 -1
  105. package/build/components/list-view/use-list-view-drop-zone.js +1 -14
  106. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  107. package/build/components/media-replace-flow/index.js +1 -1
  108. package/build/components/media-replace-flow/index.js.map +1 -1
  109. package/build/components/preview-options/index.js +2 -3
  110. package/build/components/preview-options/index.js.map +1 -1
  111. package/build/components/rich-text/format-toolbar/index.js +1 -1
  112. package/build/components/rich-text/format-toolbar/index.js.map +1 -1
  113. package/build/components/rich-text/format-toolbar-container.js +1 -1
  114. package/build/components/rich-text/format-toolbar-container.js.map +1 -1
  115. package/build/components/rich-text/use-paste-handler.js +1 -1
  116. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  117. package/build/components/spacing-sizes-control/all-input-control.js +6 -2
  118. package/build/components/spacing-sizes-control/all-input-control.js.map +1 -1
  119. package/build/components/spacing-sizes-control/axial-input-controls.js +6 -2
  120. package/build/components/spacing-sizes-control/axial-input-controls.js.map +1 -1
  121. package/build/components/spacing-sizes-control/index.js +6 -2
  122. package/build/components/spacing-sizes-control/index.js.map +1 -1
  123. package/build/components/spacing-sizes-control/input-controls.js +6 -2
  124. package/build/components/spacing-sizes-control/input-controls.js.map +1 -1
  125. package/build/components/spacing-sizes-control/spacing-input-control.js +45 -8
  126. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  127. package/build/components/url-input/index.js +1 -1
  128. package/build/components/url-input/index.js.map +1 -1
  129. package/build/components/use-block-drop-zone/index.js +98 -57
  130. package/build/components/use-block-drop-zone/index.js.map +1 -1
  131. package/build/components/use-on-block-drop/index.js +12 -12
  132. package/build/components/use-on-block-drop/index.js.map +1 -1
  133. package/build/components/use-on-block-drop/types.js +6 -0
  134. package/build/components/use-on-block-drop/types.js.map +1 -0
  135. package/build/hooks/align.js +1 -3
  136. package/build/hooks/align.js.map +1 -1
  137. package/build/hooks/align.native.js +1 -7
  138. package/build/hooks/align.native.js.map +1 -1
  139. package/build/hooks/border.js +1 -0
  140. package/build/hooks/border.js.map +1 -1
  141. package/build/hooks/dimensions.js +32 -4
  142. package/build/hooks/dimensions.js.map +1 -1
  143. package/build/hooks/font-size.js +61 -0
  144. package/build/hooks/font-size.js.map +1 -1
  145. package/build/hooks/layout.js +4 -3
  146. package/build/hooks/layout.js.map +1 -1
  147. package/build/hooks/margin.js +24 -17
  148. package/build/hooks/margin.js.map +1 -1
  149. package/build/hooks/padding.js +20 -12
  150. package/build/hooks/padding.js.map +1 -1
  151. package/build/hooks/style.js +126 -4
  152. package/build/hooks/style.js.map +1 -1
  153. package/build/hooks/use-typography-props.js +17 -3
  154. package/build/hooks/use-typography-props.js.map +1 -1
  155. package/build/hooks/utils.js +8 -7
  156. package/build/hooks/utils.js.map +1 -1
  157. package/build/layouts/constrained.js +0 -1
  158. package/build/layouts/constrained.js.map +1 -1
  159. package/build/layouts/flex.js +1 -1
  160. package/build/layouts/flex.js.map +1 -1
  161. package/build/store/actions.js +63 -45
  162. package/build/store/actions.js.map +1 -1
  163. package/build/store/array.js +1 -7
  164. package/build/store/array.js.map +1 -1
  165. package/build/store/defaults.js +3 -0
  166. package/build/store/defaults.js.map +1 -1
  167. package/build/store/reducer.js +31 -15
  168. package/build/store/reducer.js.map +1 -1
  169. package/build/store/selectors.js +46 -29
  170. package/build/store/selectors.js.map +1 -1
  171. package/build/utils/math.js +14 -0
  172. package/build/utils/math.js.map +1 -1
  173. package/build/utils/pre-parse-patterns.js +19 -2
  174. package/build/utils/pre-parse-patterns.js.map +1 -1
  175. package/build-module/components/alignment-control/ui.js +1 -1
  176. package/build-module/components/alignment-control/ui.js.map +1 -1
  177. package/build-module/components/block-alignment-control/constants.js +1 -1
  178. package/build-module/components/block-alignment-control/constants.js.map +1 -1
  179. package/build-module/components/block-alignment-matrix-control/index.js +1 -1
  180. package/build-module/components/block-alignment-matrix-control/index.js.map +1 -1
  181. package/build-module/components/block-compare/index.js +2 -3
  182. package/build-module/components/block-compare/index.js.map +1 -1
  183. package/build-module/components/block-draggable/draggable-chip.js +7 -3
  184. package/build-module/components/block-draggable/draggable-chip.js.map +1 -1
  185. package/build-module/components/block-edit/index.js +4 -2
  186. package/build-module/components/block-edit/index.js.map +1 -1
  187. package/build-module/components/block-inspector/index.js +4 -4
  188. package/build-module/components/block-inspector/index.js.map +1 -1
  189. package/build-module/components/block-list/block-list-compact.native.js +1 -0
  190. package/build-module/components/block-list/block-list-compact.native.js.map +1 -1
  191. package/build-module/components/block-list/block.js +75 -15
  192. package/build-module/components/block-list/block.js.map +1 -1
  193. package/build-module/components/block-list/block.native.js +80 -13
  194. package/build-module/components/block-list/block.native.js.map +1 -1
  195. package/build-module/components/block-list/use-in-between-inserter.js +8 -24
  196. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  197. package/build-module/components/block-lock/modal.js +10 -8
  198. package/build-module/components/block-lock/modal.js.map +1 -1
  199. package/build-module/components/block-parent-selector/index.js +3 -3
  200. package/build-module/components/block-parent-selector/index.js.map +1 -1
  201. package/build-module/components/block-patterns-list/index.js +5 -4
  202. package/build-module/components/block-patterns-list/index.js.map +1 -1
  203. package/build-module/components/block-popover/drop-zone.js +70 -0
  204. package/build-module/components/block-popover/drop-zone.js.map +1 -0
  205. package/build-module/components/block-popover/inbetween.js +2 -1
  206. package/build-module/components/block-popover/inbetween.js.map +1 -1
  207. package/build-module/components/block-popover/index.js +4 -2
  208. package/build-module/components/block-popover/index.js.map +1 -1
  209. package/build-module/components/block-preview/auto.js +1 -1
  210. package/build-module/components/block-preview/auto.js.map +1 -1
  211. package/build-module/components/block-preview/index.js +8 -12
  212. package/build-module/components/block-preview/index.js.map +1 -1
  213. package/build-module/components/block-preview/live.js +3 -6
  214. package/build-module/components/block-preview/live.js.map +1 -1
  215. package/build-module/components/block-selection-clearer/index.js +9 -1
  216. package/build-module/components/block-selection-clearer/index.js.map +1 -1
  217. package/build-module/components/block-settings-menu/block-settings-dropdown.js +20 -19
  218. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  219. package/build-module/components/block-styles/index.js +19 -44
  220. package/build-module/components/block-styles/index.js.map +1 -1
  221. package/build-module/components/block-switcher/index.js +2 -7
  222. package/build-module/components/block-switcher/index.js.map +1 -1
  223. package/build-module/components/block-switcher/preview-block-popover.js +1 -1
  224. package/build-module/components/block-switcher/preview-block-popover.js.map +1 -1
  225. package/build-module/components/block-toolbar/index.js +4 -4
  226. package/build-module/components/block-toolbar/index.js.map +1 -1
  227. package/build-module/components/block-tools/back-compat.js +2 -1
  228. package/build-module/components/block-tools/back-compat.js.map +1 -1
  229. package/build-module/components/block-tools/insertion-point.js +54 -16
  230. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  231. package/build-module/components/block-tools/selected-block-popover.js +15 -3
  232. package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
  233. package/build-module/components/block-vertical-alignment-control/ui.js +1 -1
  234. package/build-module/components/block-vertical-alignment-control/ui.js.map +1 -1
  235. package/build-module/components/border-radius-control/all-input-control.js +2 -1
  236. package/build-module/components/border-radius-control/all-input-control.js.map +1 -1
  237. package/build-module/components/border-radius-control/index.js +2 -1
  238. package/build-module/components/border-radius-control/index.js.map +1 -1
  239. package/build-module/components/border-radius-control/input-controls.js +2 -1
  240. package/build-module/components/border-radius-control/input-controls.js.map +1 -1
  241. package/build-module/components/colors-gradients/control.js +2 -2
  242. package/build-module/components/colors-gradients/control.js.map +1 -1
  243. package/build-module/components/colors-gradients/panel-color-gradient-settings.js +3 -3
  244. package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  245. package/build-module/components/duotone-control/index.js +1 -1
  246. package/build-module/components/duotone-control/index.js.map +1 -1
  247. package/build-module/components/font-sizes/fluid-utils.js +245 -0
  248. package/build-module/components/font-sizes/fluid-utils.js.map +1 -0
  249. package/build-module/components/font-sizes/index.js +1 -0
  250. package/build-module/components/font-sizes/index.js.map +1 -1
  251. package/build-module/components/font-sizes/with-font-sizes.js +2 -2
  252. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  253. package/build-module/components/iframe/index.js +1 -1
  254. package/build-module/components/iframe/index.js.map +1 -1
  255. package/build-module/components/image-editor/constants.js +1 -1
  256. package/build-module/components/image-editor/constants.js.map +1 -1
  257. package/build-module/components/index.js +0 -1
  258. package/build-module/components/index.js.map +1 -1
  259. package/build-module/components/inner-blocks/index.js +6 -2
  260. package/build-module/components/inner-blocks/index.js.map +1 -1
  261. package/build-module/components/inner-blocks/use-inner-block-template-sync.js +3 -2
  262. package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
  263. package/build-module/components/inserter/block-patterns-tab.js +148 -81
  264. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  265. package/build-module/components/inserter/hooks/use-insertion-point.js +2 -6
  266. package/build-module/components/inserter/hooks/use-insertion-point.js.map +1 -1
  267. package/build-module/components/inserter/menu.js +10 -3
  268. package/build-module/components/inserter/menu.js.map +1 -1
  269. package/build-module/components/inserter/search-items.js +23 -3
  270. package/build-module/components/inserter/search-items.js.map +1 -1
  271. package/build-module/components/inserter-draggable-blocks/index.js +4 -2
  272. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  273. package/build-module/components/line-height-control/index.js +2 -1
  274. package/build-module/components/line-height-control/index.js.map +1 -1
  275. package/build-module/components/list-view/drop-indicator.js +2 -1
  276. package/build-module/components/list-view/drop-indicator.js.map +1 -1
  277. package/build-module/components/list-view/use-list-view-drop-zone.js +1 -14
  278. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  279. package/build-module/components/media-replace-flow/index.js +1 -1
  280. package/build-module/components/media-replace-flow/index.js.map +1 -1
  281. package/build-module/components/preview-options/index.js +2 -3
  282. package/build-module/components/preview-options/index.js.map +1 -1
  283. package/build-module/components/rich-text/format-toolbar/index.js +1 -1
  284. package/build-module/components/rich-text/format-toolbar/index.js.map +1 -1
  285. package/build-module/components/rich-text/format-toolbar-container.js +1 -1
  286. package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
  287. package/build-module/components/rich-text/use-paste-handler.js +1 -1
  288. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  289. package/build-module/components/spacing-sizes-control/all-input-control.js +6 -2
  290. package/build-module/components/spacing-sizes-control/all-input-control.js.map +1 -1
  291. package/build-module/components/spacing-sizes-control/axial-input-controls.js +6 -2
  292. package/build-module/components/spacing-sizes-control/axial-input-controls.js.map +1 -1
  293. package/build-module/components/spacing-sizes-control/index.js +6 -2
  294. package/build-module/components/spacing-sizes-control/index.js.map +1 -1
  295. package/build-module/components/spacing-sizes-control/input-controls.js +6 -2
  296. package/build-module/components/spacing-sizes-control/input-controls.js.map +1 -1
  297. package/build-module/components/spacing-sizes-control/spacing-input-control.js +44 -8
  298. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  299. package/build-module/components/url-input/index.js +1 -1
  300. package/build-module/components/url-input/index.js.map +1 -1
  301. package/build-module/components/use-block-drop-zone/index.js +98 -58
  302. package/build-module/components/use-block-drop-zone/index.js.map +1 -1
  303. package/build-module/components/use-on-block-drop/index.js +12 -12
  304. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  305. package/build-module/components/use-on-block-drop/types.js +2 -0
  306. package/build-module/components/use-on-block-drop/types.js.map +1 -0
  307. package/build-module/hooks/align.js +1 -2
  308. package/build-module/hooks/align.js.map +1 -1
  309. package/build-module/hooks/align.native.js +1 -6
  310. package/build-module/hooks/align.native.js.map +1 -1
  311. package/build-module/hooks/border.js +1 -0
  312. package/build-module/hooks/border.js.map +1 -1
  313. package/build-module/hooks/dimensions.js +32 -4
  314. package/build-module/hooks/dimensions.js.map +1 -1
  315. package/build-module/hooks/font-size.js +60 -1
  316. package/build-module/hooks/font-size.js.map +1 -1
  317. package/build-module/hooks/layout.js +5 -4
  318. package/build-module/hooks/layout.js.map +1 -1
  319. package/build-module/hooks/margin.js +25 -18
  320. package/build-module/hooks/margin.js.map +1 -1
  321. package/build-module/hooks/padding.js +21 -13
  322. package/build-module/hooks/padding.js.map +1 -1
  323. package/build-module/hooks/style.js +124 -3
  324. package/build-module/hooks/style.js.map +1 -1
  325. package/build-module/hooks/use-typography-props.js +17 -4
  326. package/build-module/hooks/use-typography-props.js.map +1 -1
  327. package/build-module/hooks/utils.js +8 -8
  328. package/build-module/hooks/utils.js.map +1 -1
  329. package/build-module/layouts/constrained.js +0 -1
  330. package/build-module/layouts/constrained.js.map +1 -1
  331. package/build-module/layouts/flex.js +1 -1
  332. package/build-module/layouts/flex.js.map +1 -1
  333. package/build-module/store/actions.js +59 -42
  334. package/build-module/store/actions.js.map +1 -1
  335. package/build-module/store/array.js +1 -6
  336. package/build-module/store/array.js.map +1 -1
  337. package/build-module/store/defaults.js +3 -0
  338. package/build-module/store/defaults.js.map +1 -1
  339. package/build-module/store/reducer.js +32 -16
  340. package/build-module/store/reducer.js.map +1 -1
  341. package/build-module/store/selectors.js +47 -30
  342. package/build-module/store/selectors.js.map +1 -1
  343. package/build-module/utils/math.js +12 -0
  344. package/build-module/utils/math.js.map +1 -1
  345. package/build-module/utils/pre-parse-patterns.js +19 -2
  346. package/build-module/utils/pre-parse-patterns.js.map +1 -1
  347. package/build-style/style-rtl.css +292 -206
  348. package/build-style/style.css +288 -202
  349. package/package.json +29 -28
  350. package/src/components/alignment-control/ui.js +1 -1
  351. package/src/components/block-alignment-control/constants.js +1 -1
  352. package/src/components/block-alignment-matrix-control/index.js +1 -1
  353. package/src/components/block-breadcrumb/test/__snapshots__/index.js.snap +13 -11
  354. package/src/components/block-breadcrumb/test/index.js +2 -2
  355. package/src/components/block-compare/index.js +3 -2
  356. package/src/components/block-draggable/draggable-chip.js +4 -2
  357. package/src/components/block-edit/index.js +2 -1
  358. package/src/components/block-inspector/index.js +8 -7
  359. package/src/components/block-list/block-list-compact.native.js +1 -0
  360. package/src/components/block-list/block.js +113 -7
  361. package/src/components/block-list/block.native.js +123 -9
  362. package/src/components/block-list/style.scss +93 -126
  363. package/src/components/block-list/use-in-between-inserter.js +8 -19
  364. package/src/components/block-lock/modal.js +12 -7
  365. package/src/components/block-mover/stories/index.js +1 -1
  366. package/src/components/block-mover/style.scss +35 -1
  367. package/src/components/block-parent-selector/index.js +3 -3
  368. package/src/components/block-patterns-list/index.js +9 -5
  369. package/src/components/block-patterns-list/style.scss +7 -3
  370. package/src/components/block-popover/README.md +8 -0
  371. package/src/components/block-popover/drop-zone.js +63 -0
  372. package/src/components/block-popover/inbetween.js +1 -0
  373. package/src/components/block-popover/index.js +3 -1
  374. package/src/components/block-popover/style.scss +17 -5
  375. package/src/components/block-preview/auto.js +1 -1
  376. package/src/components/block-preview/index.js +15 -11
  377. package/src/components/block-preview/live.js +2 -7
  378. package/src/components/block-preview/test/index.js +1 -7
  379. package/src/components/block-selection-clearer/index.js +7 -2
  380. package/src/components/block-selection-clearer/test/index.js +118 -0
  381. package/src/components/block-settings-menu/block-settings-dropdown.js +29 -18
  382. package/src/components/block-settings-menu/test/block-mode-toggle.js +17 -17
  383. package/src/components/block-styles/index.js +26 -49
  384. package/src/components/block-switcher/index.js +2 -7
  385. package/src/components/block-switcher/preview-block-popover.js +1 -1
  386. package/src/components/block-switcher/test/index.js +2 -2
  387. package/src/components/block-toolbar/index.js +4 -6
  388. package/src/components/block-toolbar/style.scss +38 -14
  389. package/src/components/block-tools/back-compat.js +1 -0
  390. package/src/components/block-tools/insertion-point.js +49 -15
  391. package/src/components/block-tools/selected-block-popover.js +14 -1
  392. package/src/components/block-variation-picker/README.md +1 -1
  393. package/src/components/block-vertical-alignment-control/ui.js +1 -1
  394. package/src/components/border-radius-control/all-input-control.js +1 -0
  395. package/src/components/border-radius-control/index.js +1 -0
  396. package/src/components/border-radius-control/input-controls.js +1 -0
  397. package/src/components/border-radius-control/style.scss +15 -24
  398. package/src/components/button-block-appender/style.scss +4 -2
  399. package/src/components/color-palette/test/__snapshots__/control.js.snap +86 -104
  400. package/src/components/color-palette/test/control.js +11 -15
  401. package/src/components/colors-gradients/control.js +2 -2
  402. package/src/components/colors-gradients/panel-color-gradient-settings.js +3 -4
  403. package/src/components/colors-gradients/test/control.js +49 -77
  404. package/src/components/duotone-control/index.js +1 -1
  405. package/src/components/font-sizes/fluid-utils.js +296 -0
  406. package/src/components/font-sizes/index.js +1 -0
  407. package/src/components/font-sizes/test/fluid-utils.js +168 -0
  408. package/src/components/font-sizes/with-font-sizes.js +2 -3
  409. package/src/components/iframe/index.js +1 -1
  410. package/src/components/image-editor/constants.js +1 -1
  411. package/src/components/image-size-control/test/index.js +47 -60
  412. package/src/components/index.js +0 -1
  413. package/src/components/inner-blocks/index.js +5 -1
  414. package/src/components/inner-blocks/test/index.js +4 -0
  415. package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -2
  416. package/src/components/inserter/block-patterns-tab.js +232 -98
  417. package/src/components/inserter/hooks/use-insertion-point.js +3 -11
  418. package/src/components/inserter/menu.js +15 -2
  419. package/src/components/inserter/search-items.js +23 -3
  420. package/src/components/inserter/style.scss +94 -9
  421. package/src/components/inserter/test/reusable-blocks-tab.js +6 -6
  422. package/src/components/inserter/test/search-items.js +6 -0
  423. package/src/components/inserter-draggable-blocks/index.js +12 -2
  424. package/src/components/inserter-list-item/style.scss +22 -1
  425. package/src/components/letter-spacing-control/README.md +55 -0
  426. package/src/components/line-height-control/index.js +1 -0
  427. package/src/components/link-control/README.md +3 -3
  428. package/src/components/link-control/test/index.js +1 -1
  429. package/src/components/list-view/drop-indicator.js +1 -0
  430. package/src/components/list-view/style.scss +1 -36
  431. package/src/components/list-view/use-list-view-drop-zone.js +4 -18
  432. package/src/components/media-replace-flow/index.js +1 -1
  433. package/src/components/media-replace-flow/test/index.js +69 -51
  434. package/src/components/panel-color-settings/test/index.js +4 -4
  435. package/src/components/preview-options/index.js +2 -2
  436. package/src/components/preview-options/style.scss +1 -1
  437. package/src/components/provider/test/use-block-sync.js +131 -165
  438. package/src/components/responsive-block-control/test/index.js +4 -4
  439. package/src/components/rich-text/format-toolbar/index.js +1 -1
  440. package/src/components/rich-text/format-toolbar-container.js +1 -1
  441. package/src/components/rich-text/use-paste-handler.js +1 -1
  442. package/src/components/spacing-sizes-control/all-input-control.js +4 -0
  443. package/src/components/spacing-sizes-control/axial-input-controls.js +4 -0
  444. package/src/components/spacing-sizes-control/index.js +4 -0
  445. package/src/components/spacing-sizes-control/input-controls.js +4 -0
  446. package/src/components/spacing-sizes-control/spacing-input-control.js +26 -3
  447. package/src/components/spacing-sizes-control/style.scss +27 -19
  448. package/src/components/url-input/index.js +1 -1
  449. package/src/components/use-block-drop-zone/index.js +136 -79
  450. package/src/components/use-block-drop-zone/test/index.js +333 -81
  451. package/src/components/use-on-block-drop/index.js +11 -12
  452. package/src/components/use-on-block-drop/types.ts +1 -0
  453. package/src/hooks/align.js +3 -2
  454. package/src/hooks/align.native.js +5 -8
  455. package/src/hooks/border.js +1 -0
  456. package/src/hooks/dimensions.js +32 -5
  457. package/src/hooks/font-size.js +76 -0
  458. package/src/hooks/layout.js +7 -9
  459. package/src/hooks/margin.js +20 -14
  460. package/src/hooks/padding.js +20 -16
  461. package/src/hooks/style.js +122 -3
  462. package/src/hooks/test/align.js +96 -72
  463. package/src/hooks/test/style.js +206 -1
  464. package/src/hooks/test/use-typography-props.js +22 -0
  465. package/src/hooks/use-typography-props.js +18 -3
  466. package/src/hooks/utils.js +10 -7
  467. package/src/layouts/constrained.js +0 -1
  468. package/src/layouts/flex.js +1 -1
  469. package/src/store/actions.js +24 -12
  470. package/src/store/array.js +1 -6
  471. package/src/store/defaults.js +3 -0
  472. package/src/store/reducer.js +31 -24
  473. package/src/store/selectors.js +28 -21
  474. package/src/store/test/actions.js +0 -9
  475. package/src/store/test/selectors.js +1 -1
  476. package/src/utils/math.js +17 -0
  477. package/src/utils/pre-parse-patterns.js +12 -7
  478. package/build/components/inserter/pattern-panel.js +0 -87
  479. package/build/components/inserter/pattern-panel.js.map +0 -1
  480. package/build-module/components/inserter/pattern-panel.js +0 -74
  481. package/build-module/components/inserter/pattern-panel.js.map +0 -1
  482. package/src/components/inserter/pattern-panel.js +0 -93
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/url-input/index.js"],"names":["classnames","scrollIntoView","__","sprintf","_n","Component","createRef","UP","DOWN","ENTER","TAB","BaseControl","Button","Spinner","withSpokenMessages","Popover","compose","debounce","withInstanceId","withSafeTimeout","withSelect","isURL","store","blockEditorStore","isFunction","maybeFunc","URLInput","constructor","props","onChange","bind","onFocus","onKeyDown","selectLink","handleOnClick","bindSuggestionNode","autocompleteRef","inputRef","updateSuggestions","suggestionNodes","isUpdatingSuggestions","state","suggestions","showSuggestions","selectedSuggestion","suggestionsListboxId","suggestionOptionIdPrefix","componentDidUpdate","prevProps","value","__experimentalShowInitialSuggestions","scrollingIntoView","current","onlyScrollIfNeeded","setTimeout","disableSuggestions","length","componentDidMount","shouldShowInitialSuggestions","componentWillUnmount","suggestionsRequest","cancel","index","ref","__experimentalFetchLinkSuggestions","fetchLinkSuggestions","__experimentalHandleURLSuggestions","handleURLSuggestions","isInitialSuggestions","trim","setState","loading","request","then","debouncedSpeak","catch","event","inputValue","target","keyCode","selectionStart","preventDefault","setSelectionRange","onSubmit","suggestion","previousIndex","nextIndex","speak","url","focus","getDerivedStateFromProps","instanceId","shouldShowSuggestions","hasValue","render","renderControl","renderSuggestions","label","className","isFullWidth","placeholder","__experimentalRenderControl","inputId","controlProps","id","inputProps","required","type","role","undefined","__experimentalRenderSuggestions","suggestionsListProps","buildSuggestionItemProps","tabIndex","isLoading","handleSuggestionClick","map","title","select","getSettings"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA,OAAOC,cAAP,MAA2B,sBAA3B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,EAAsBC,EAAtB,QAAgC,iBAAhC;AACA,SAASC,SAAT,EAAoBC,SAApB,QAAqC,oBAArC;AACA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,KAAnB,EAA0BC,GAA1B,QAAqC,qBAArC;AACA,SACCC,WADD,EAECC,MAFD,EAGCC,OAHD,EAICC,kBAJD,EAKCC,OALD,QAMO,uBANP;AAOA,SACCC,OADD,EAECC,QAFD,EAGCC,cAHD,EAICC,eAJD,QAKO,oBALP;AAMA,SAASC,UAAT,QAA2B,iBAA3B;AACA,SAASC,KAAT,QAAsB,gBAAtB;AAEA;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;;;AACA,eAAerG,OAAO,CACrBG,eADqB,EAErBL,kBAFqB,EAGrBI,cAHqB,EAIrBE,UAAU,CAAE,CAAEkG,MAAF,EAAU1F,KAAV,KAAqB;AAChC;AACA;AACA,MAAKJ,UAAU,CAAEI,KAAK,CAACoC,kCAAR,CAAf,EAA8D;AAC7D;AACA;;AACD,QAAM;AAAEuD,IAAAA;AAAF,MAAkBD,MAAM,CAAE/F,gBAAF,CAA9B;AACA,SAAO;AACNyC,IAAAA,kCAAkC,EACjCuD,WAAW,GAAGvD;AAFT,GAAP;AAIA,CAXS,CAJW,CAAP,CAgBZtC,QAhBY,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport scrollIntoView from 'dom-scroll-into-view';\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\tSpinner,\n\twithSpokenMessages,\n\tPopover,\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';\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 = createRef();\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.isUpdatingSuggestions = false;\n\n\t\tthis.state = {\n\t\t\tsuggestions: [],\n\t\t\tshowSuggestions: false,\n\t\t\tselectedSuggestion: null,\n\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\t! this.scrollingIntoView\n\t\t) {\n\t\t\tthis.scrollingIntoView = true;\n\t\t\tscrollIntoView(\n\t\t\t\tthis.suggestionNodes[ selectedSuggestion ],\n\t\t\t\tthis.autocompleteRef.current,\n\t\t\t\t{\n\t\t\t\t\tonlyScrollIfNeeded: true,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tthis.props.setTimeout( () => {\n\t\t\t\tthis.scrollingIntoView = false;\n\t\t\t}, 100 );\n\t\t}\n\n\t\t// Update suggestions when the value changes.\n\t\tif (\n\t\t\tprevProps.value !== value &&\n\t\t\t! this.props.disableSuggestions &&\n\t\t\t! this.isUpdatingSuggestions\n\t\t) {\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\tdelete this.suggestionsRequest;\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 { suggestions } = this.state;\n\t\tconst { __experimentalShowInitialSuggestions = false, value } =\n\t\t\tthis.props;\n\t\treturn (\n\t\t\t! this.isUpdatingSuggestions &&\n\t\t\t__experimentalShowInitialSuggestions &&\n\t\t\t! ( value && value.length ) &&\n\t\t\t! ( suggestions && suggestions.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.setState( {\n\t\t\t\tshowSuggestions: false,\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.isUpdatingSuggestions = true;\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\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: %s: 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\tthis.isUpdatingSuggestions = false;\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tif ( this.suggestionsRequest === request ) {\n\t\t\t\t\tthis.setState( {\n\t\t\t\t\t\tloading: false,\n\t\t\t\t\t} );\n\t\t\t\t\tthis.isUpdatingSuggestions = false;\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( event ) {\n\t\tconst inputValue = event.target.value;\n\n\t\tthis.props.onChange( inputValue );\n\t\tif ( ! this.props.disableSuggestions ) {\n\t\t\tthis.updateSuggestions( inputValue );\n\t\t}\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\tif (\n\t\t\tvalue &&\n\t\t\t! disableSuggestions &&\n\t\t\t! this.isUpdatingSuggestions &&\n\t\t\t! ( suggestions && suggestions.length )\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\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\tevent.preventDefault();\n\t\t\t\t\tif ( this.props.onSubmit ) {\n\t\t\t\t\t\tthis.props.onSubmit( null, event );\n\t\t\t\t\t}\n\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} = 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: classnames( 'block-editor-url-input', className, {\n\t\t\t\t'is-full-width': isFullWidth,\n\t\t\t} ),\n\t\t};\n\n\t\tconst inputProps = {\n\t\t\tid: inputId,\n\t\t\tvalue,\n\t\t\trequired: true,\n\t\t\tclassName: 'block-editor-url-input__input',\n\t\t\ttype: 'text',\n\t\t\tonChange: this.onChange,\n\t\t\tonFocus: this.onFocus,\n\t\t\tplaceholder,\n\t\t\tonKeyDown: this.onKeyDown,\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-controls': 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};\n\n\t\tif ( renderControl ) {\n\t\t\treturn renderControl( controlProps, inputProps, loading );\n\t\t}\n\n\t\treturn (\n\t\t\t<BaseControl { ...controlProps }>\n\t\t\t\t<input { ...inputProps } />\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\tvalue = '',\n\t\t\t__experimentalShowInitialSuggestions = false,\n\t\t} = this.props;\n\n\t\tconst {\n\t\t\tshowSuggestions,\n\t\t\tsuggestions,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListboxId,\n\t\t\tsuggestionOptionIdPrefix,\n\t\t\tloading,\n\t\t} = this.state;\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': index === selectedSuggestion,\n\t\t\t};\n\t\t};\n\n\t\tif (\n\t\t\tisFunction( renderSuggestions ) &&\n\t\t\tshowSuggestions &&\n\t\t\t!! suggestions.length\n\t\t) {\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:\n\t\t\t\t\t__experimentalShowInitialSuggestions &&\n\t\t\t\t\t! ( value && value.length ),\n\t\t\t} );\n\t\t}\n\n\t\tif (\n\t\t\t! isFunction( renderSuggestions ) &&\n\t\t\tshowSuggestions &&\n\t\t\t!! suggestions.length\n\t\t) {\n\t\t\treturn (\n\t\t\t\t<Popover position=\"bottom\" focusOnMount={ false }>\n\t\t\t\t\t<div\n\t\t\t\t\t\t{ ...suggestionsListProps }\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'block-editor-url-input__suggestions',\n\t\t\t\t\t\t\t`${ className }__suggestions`\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ suggestions.map( ( suggestion, index ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t{ ...buildSuggestionItemProps(\n\t\t\t\t\t\t\t\t\tsuggestion,\n\t\t\t\t\t\t\t\t\tindex\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tkey={ suggestion.id }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\t'block-editor-url-input__suggestion',\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t'is-selected':\n\t\t\t\t\t\t\t\t\t\t\tindex === selectedSuggestion,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tthis.handleOnClick( suggestion )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ suggestion.title }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</div>\n\t\t\t\t</Popover>\n\t\t\t);\n\t\t}\n\t\treturn null;\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"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/url-input/index.js"],"names":["classnames","scrollIntoView","__","sprintf","_n","Component","createRef","UP","DOWN","ENTER","TAB","BaseControl","Button","Spinner","withSpokenMessages","Popover","compose","debounce","withInstanceId","withSafeTimeout","withSelect","isURL","store","blockEditorStore","isFunction","maybeFunc","URLInput","constructor","props","onChange","bind","onFocus","onKeyDown","selectLink","handleOnClick","bindSuggestionNode","autocompleteRef","inputRef","updateSuggestions","suggestionNodes","isUpdatingSuggestions","state","suggestions","showSuggestions","selectedSuggestion","suggestionsListboxId","suggestionOptionIdPrefix","componentDidUpdate","prevProps","value","__experimentalShowInitialSuggestions","scrollingIntoView","current","onlyScrollIfNeeded","setTimeout","disableSuggestions","length","componentDidMount","shouldShowInitialSuggestions","componentWillUnmount","suggestionsRequest","cancel","index","ref","__experimentalFetchLinkSuggestions","fetchLinkSuggestions","__experimentalHandleURLSuggestions","handleURLSuggestions","isInitialSuggestions","trim","setState","loading","request","then","debouncedSpeak","catch","event","inputValue","target","keyCode","selectionStart","preventDefault","setSelectionRange","onSubmit","suggestion","previousIndex","nextIndex","speak","url","focus","getDerivedStateFromProps","instanceId","shouldShowSuggestions","hasValue","render","renderControl","renderSuggestions","label","className","isFullWidth","placeholder","__experimentalRenderControl","inputId","controlProps","id","inputProps","required","type","role","undefined","__experimentalRenderSuggestions","suggestionsListProps","buildSuggestionItemProps","tabIndex","isLoading","handleSuggestionClick","map","title","select","getSettings"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA,OAAOC,cAAP,MAA2B,sBAA3B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,EAAsBC,EAAtB,QAAgC,iBAAhC;AACA,SAASC,SAAT,EAAoBC,SAApB,QAAqC,oBAArC;AACA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,KAAnB,EAA0BC,G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B,oCADqB,EAErB;AACC,yBACC8D,KAAK,KAAKlB;AAFZ,SAFqB,CANvB;AAaC,QAAA,OAAO,EAAG,MACT,KAAKV,aAAL,CAAoBkD,UAApB;AAdF,UAiBGA,UAAU,CAACiC,KAjBd,CADC,CAPH,CADD,CADD;AAiCA;;AACD,WAAO,IAAP;AACA;;AAxhB+B;AA2hBjC;AACA;AACA;;;AACA,eAAerG,OAAO,CACrBG,eADqB,EAErBL,kBAFqB,EAGrBI,cAHqB,EAIrBE,UAAU,CAAE,CAAEkG,MAAF,EAAU1F,KAAV,KAAqB;AAChC;AACA;AACA,MAAKJ,UAAU,CAAEI,KAAK,CAACoC,kCAAR,CAAf,EAA8D;AAC7D;AACA;;AACD,QAAM;AAAEuD,IAAAA;AAAF,MAAkBD,MAAM,CAAE/F,gBAAF,CAA9B;AACA,SAAO;AACNyC,IAAAA,kCAAkC,EACjCuD,WAAW,GAAGvD;AAFT,GAAP;AAIA,CAXS,CAJW,CAAP,CAgBZtC,QAhBY,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport scrollIntoView from 'dom-scroll-into-view';\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\tSpinner,\n\twithSpokenMessages,\n\tPopover,\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';\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 = createRef();\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.isUpdatingSuggestions = false;\n\n\t\tthis.state = {\n\t\t\tsuggestions: [],\n\t\t\tshowSuggestions: false,\n\t\t\tselectedSuggestion: null,\n\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\t! this.scrollingIntoView\n\t\t) {\n\t\t\tthis.scrollingIntoView = true;\n\t\t\tscrollIntoView(\n\t\t\t\tthis.suggestionNodes[ selectedSuggestion ],\n\t\t\t\tthis.autocompleteRef.current,\n\t\t\t\t{\n\t\t\t\t\tonlyScrollIfNeeded: true,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tthis.props.setTimeout( () => {\n\t\t\t\tthis.scrollingIntoView = false;\n\t\t\t}, 100 );\n\t\t}\n\n\t\t// Update suggestions when the value changes.\n\t\tif (\n\t\t\tprevProps.value !== value &&\n\t\t\t! this.props.disableSuggestions &&\n\t\t\t! this.isUpdatingSuggestions\n\t\t) {\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\tdelete this.suggestionsRequest;\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 { suggestions } = this.state;\n\t\tconst { __experimentalShowInitialSuggestions = false, value } =\n\t\t\tthis.props;\n\t\treturn (\n\t\t\t! this.isUpdatingSuggestions &&\n\t\t\t__experimentalShowInitialSuggestions &&\n\t\t\t! ( value && value.length ) &&\n\t\t\t! ( suggestions && suggestions.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.setState( {\n\t\t\t\tshowSuggestions: false,\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.isUpdatingSuggestions = true;\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\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: %s: 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\tthis.isUpdatingSuggestions = false;\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tif ( this.suggestionsRequest === request ) {\n\t\t\t\t\tthis.setState( {\n\t\t\t\t\t\tloading: false,\n\t\t\t\t\t} );\n\t\t\t\t\tthis.isUpdatingSuggestions = false;\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( event ) {\n\t\tconst inputValue = event.target.value;\n\n\t\tthis.props.onChange( inputValue );\n\t\tif ( ! this.props.disableSuggestions ) {\n\t\t\tthis.updateSuggestions( inputValue );\n\t\t}\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\tif (\n\t\t\tvalue &&\n\t\t\t! disableSuggestions &&\n\t\t\t! this.isUpdatingSuggestions &&\n\t\t\t! ( suggestions && suggestions.length )\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\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\tevent.preventDefault();\n\t\t\t\t\tif ( this.props.onSubmit ) {\n\t\t\t\t\t\tthis.props.onSubmit( null, event );\n\t\t\t\t\t}\n\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} = 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: classnames( 'block-editor-url-input', className, {\n\t\t\t\t'is-full-width': isFullWidth,\n\t\t\t} ),\n\t\t};\n\n\t\tconst inputProps = {\n\t\t\tid: inputId,\n\t\t\tvalue,\n\t\t\trequired: true,\n\t\t\tclassName: 'block-editor-url-input__input',\n\t\t\ttype: 'text',\n\t\t\tonChange: this.onChange,\n\t\t\tonFocus: this.onFocus,\n\t\t\tplaceholder,\n\t\t\tonKeyDown: this.onKeyDown,\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-controls': 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};\n\n\t\tif ( renderControl ) {\n\t\t\treturn renderControl( controlProps, inputProps, loading );\n\t\t}\n\n\t\treturn (\n\t\t\t<BaseControl { ...controlProps }>\n\t\t\t\t<input { ...inputProps } />\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\tvalue = '',\n\t\t\t__experimentalShowInitialSuggestions = false,\n\t\t} = this.props;\n\n\t\tconst {\n\t\t\tshowSuggestions,\n\t\t\tsuggestions,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListboxId,\n\t\t\tsuggestionOptionIdPrefix,\n\t\t\tloading,\n\t\t} = this.state;\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': index === selectedSuggestion,\n\t\t\t};\n\t\t};\n\n\t\tif (\n\t\t\tisFunction( renderSuggestions ) &&\n\t\t\tshowSuggestions &&\n\t\t\t!! suggestions.length\n\t\t) {\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:\n\t\t\t\t\t__experimentalShowInitialSuggestions &&\n\t\t\t\t\t! ( value && value.length ),\n\t\t\t} );\n\t\t}\n\n\t\tif (\n\t\t\t! isFunction( renderSuggestions ) &&\n\t\t\tshowSuggestions &&\n\t\t\t!! suggestions.length\n\t\t) {\n\t\t\treturn (\n\t\t\t\t<Popover placement=\"bottom\" focusOnMount={ false }>\n\t\t\t\t\t<div\n\t\t\t\t\t\t{ ...suggestionsListProps }\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'block-editor-url-input__suggestions',\n\t\t\t\t\t\t\t`${ className }__suggestions`\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ suggestions.map( ( suggestion, index ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t{ ...buildSuggestionItemProps(\n\t\t\t\t\t\t\t\t\tsuggestion,\n\t\t\t\t\t\t\t\t\tindex\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tkey={ suggestion.id }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\t'block-editor-url-input__suggestion',\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t'is-selected':\n\t\t\t\t\t\t\t\t\t\t\tindex === selectedSuggestion,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tthis.handleOnClick( suggestion )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ suggestion.title }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</div>\n\t\t\t\t</Popover>\n\t\t\t);\n\t\t}\n\t\treturn null;\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,15 +5,18 @@ import { useDispatch, useSelect } from '@wordpress/data';
5
5
  import { useCallback, useState } from '@wordpress/element';
6
6
  import { useThrottle, __experimentalUseDropZone as useDropZone } from '@wordpress/compose';
7
7
  import { isRTL } from '@wordpress/i18n';
8
+ import { isUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock } from '@wordpress/blocks';
8
9
  /**
9
10
  * Internal dependencies
10
11
  */
11
12
 
12
13
  import useOnBlockDrop from '../use-on-block-drop';
13
- import { getDistanceToNearestEdge } from '../../utils/math';
14
+ import { getDistanceToNearestEdge, isPointContainedByRect } from '../../utils/math';
14
15
  import { store as blockEditorStore } from '../../store';
15
16
  /** @typedef {import('../../utils/math').WPPoint} WPPoint */
16
17
 
18
+ /** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */
19
+
17
20
  /**
18
21
  * The orientation of a block list.
19
22
  *
@@ -21,48 +24,70 @@ import { store as blockEditorStore } from '../../store';
21
24
  */
22
25
 
23
26
  /**
24
- * Given a list of block DOM elements finds the index that a block should be dropped
25
- * at.
27
+ * The insert position when dropping a block.
26
28
  *
27
- * @param {Element[]} elements Array of DOM elements that represent each block in a block list.
28
- * @param {WPPoint} position The position of the item being dragged.
29
- * @param {WPBlockListOrientation} orientation The orientation of a block list.
29
+ * @typedef {'before'|'after'} WPInsertPosition
30
+ */
31
+
32
+ /**
33
+ * @typedef {Object} WPBlockData
34
+ * @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.
35
+ * @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.
36
+ * @property {number} blockIndex The index of the block.
37
+ */
38
+
39
+ /**
40
+ * Get the drop target position from a given drop point and the orientation.
30
41
  *
31
- * @return {number|undefined} The block index that's closest to the drag position.
42
+ * @param {WPBlockData[]} blocksData The block data list.
43
+ * @param {WPPoint} position The position of the item being dragged.
44
+ * @param {WPBlockListOrientation} orientation The orientation of the block list.
45
+ * @return {[number, WPDropOperation]} The drop target position.
32
46
  */
33
47
 
34
- export function getNearestBlockIndex(elements, position, orientation) {
48
+ export function getDropTargetPosition(blocksData, position) {
49
+ var _blocksData$nearestIn, _blocksData$adjacentI;
50
+
51
+ let orientation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'vertical';
35
52
  const allowedEdges = orientation === 'horizontal' ? ['left', 'right'] : ['top', 'bottom'];
36
53
  const isRightToLeft = isRTL();
37
- let candidateIndex;
38
- let candidateDistance;
39
- elements.forEach((element, index) => {
40
- const rect = element.getBoundingClientRect();
41
- const [distance, edge] = getDistanceToNearestEdge(position, rect, allowedEdges);
42
-
43
- if (candidateDistance === undefined || distance < candidateDistance) {
44
- // If the user is dropping to the trailing edge of the block
45
- // add 1 to the index to represent dragging after.
46
- // Take RTL languages into account where the left edge is
47
- // the trailing edge.
48
- const isTrailingEdge = edge === 'bottom' || !isRightToLeft && edge === 'right' || isRightToLeft && edge === 'left';
49
- const offset = isTrailingEdge ? 1 : 0; // Update the currently known best candidate.
50
-
51
- candidateDistance = distance;
52
- candidateIndex = index + offset;
54
+ let nearestIndex = 0;
55
+ let insertPosition = 'before';
56
+ let minDistance = Infinity;
57
+ blocksData.forEach(_ref => {
58
+ let {
59
+ isUnmodifiedDefaultBlock,
60
+ getBoundingClientRect,
61
+ blockIndex
62
+ } = _ref;
63
+ const rect = getBoundingClientRect();
64
+ let [distance, edge] = getDistanceToNearestEdge(position, rect, allowedEdges); // Prioritize the element if the point is inside of an unmodified default block.
65
+
66
+ if (isUnmodifiedDefaultBlock && isPointContainedByRect(position, rect)) {
67
+ distance = 0;
68
+ }
69
+
70
+ if (distance < minDistance) {
71
+ // Where the dropped block will be inserted on the nearest block.
72
+ insertPosition = edge === 'bottom' || !isRightToLeft && edge === 'right' || isRightToLeft && edge === 'left' ? 'after' : 'before'; // Update the currently known best candidate.
73
+
74
+ minDistance = distance;
75
+ nearestIndex = blockIndex;
53
76
  }
54
77
  });
55
- return candidateIndex;
56
- }
57
- /**
58
- * Determine if the element is an empty paragraph block.
59
- *
60
- * @param {?HTMLElement} element The element being tested.
61
- * @return {boolean} True or False.
62
- */
78
+ const adjacentIndex = nearestIndex + (insertPosition === 'after' ? 1 : -1);
79
+ const isNearestBlockUnmodifiedDefaultBlock = !!((_blocksData$nearestIn = blocksData[nearestIndex]) !== null && _blocksData$nearestIn !== void 0 && _blocksData$nearestIn.isUnmodifiedDefaultBlock);
80
+ const isAdjacentBlockUnmodifiedDefaultBlock = !!((_blocksData$adjacentI = blocksData[adjacentIndex]) !== null && _blocksData$adjacentI !== void 0 && _blocksData$adjacentI.isUnmodifiedDefaultBlock); // If both blocks are not unmodified default blocks then just insert between them.
81
+
82
+ if (!isNearestBlockUnmodifiedDefaultBlock && !isAdjacentBlockUnmodifiedDefaultBlock) {
83
+ // If the user is dropping to the trailing edge of the block
84
+ // add 1 to the index to represent dragging after.
85
+ const insertionIndex = insertPosition === 'after' ? nearestIndex + 1 : nearestIndex;
86
+ return [insertionIndex, 'insert'];
87
+ } // Otherwise, replace the nearest unmodified default block.
88
+
63
89
 
64
- function isEmptyParagraph(element) {
65
- return !!element && element.dataset.type === 'core/paragraph' && element.dataset.empty === 'true';
90
+ return [isNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex, 'replace'];
66
91
  }
67
92
  /**
68
93
  * @typedef {Object} WPBlockDropZoneConfig
@@ -75,7 +100,6 @@ function isEmptyParagraph(element) {
75
100
  * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.
76
101
  */
77
102
 
78
-
79
103
  export default function useBlockDropZone() {
80
104
  let {
81
105
  // An undefined value represents a top-level block. Default to an empty
@@ -84,7 +108,10 @@ export default function useBlockDropZone() {
84
108
  // an empty string to represent top-level blocks.
85
109
  rootClientId: targetRootClientId = ''
86
110
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
87
- const [targetBlockIndex, setTargetBlockIndex] = useState(null);
111
+ const [dropTarget, setDropTarget] = useState({
112
+ index: null,
113
+ operation: 'insert'
114
+ });
88
115
  const isDisabled = useSelect(select => {
89
116
  const {
90
117
  getTemplateLock,
@@ -95,35 +122,50 @@ export default function useBlockDropZone() {
95
122
  return ['all', 'contentOnly'].some(lock => lock === templateLock) || __unstableHasActiveBlockOverlayActive(targetRootClientId) || __unstableIsWithinBlockOverlay(targetRootClientId);
96
123
  }, [targetRootClientId]);
97
124
  const {
98
- getBlockListSettings
125
+ getBlockListSettings,
126
+ getBlocks,
127
+ getBlockIndex
99
128
  } = useSelect(blockEditorStore);
100
129
  const {
101
130
  showInsertionPoint,
102
131
  hideInsertionPoint
103
132
  } = useDispatch(blockEditorStore);
104
- const onBlockDrop = useOnBlockDrop(targetRootClientId, targetBlockIndex);
105
- const throttled = useThrottle(useCallback((event, currentTarget) => {
133
+ const onBlockDrop = useOnBlockDrop(targetRootClientId, dropTarget.index, {
134
+ operation: dropTarget.operation
135
+ });
136
+ const throttled = useThrottle(useCallback((event, ownerDocument) => {
106
137
  var _getBlockListSettings;
107
138
 
108
- const blockElements = Array.from(currentTarget.children).filter( // Ensure the element is a block. It should have the `wp-block` class.
109
- element => element.classList.contains('wp-block'));
110
- const targetIndex = getNearestBlockIndex(blockElements, {
139
+ const blocks = getBlocks(targetRootClientId); // The block list is empty, don't show the insertion point but still allow dropping.
140
+
141
+ if (blocks.length === 0) {
142
+ setDropTarget({
143
+ index: 0,
144
+ operation: 'insert'
145
+ });
146
+ return;
147
+ }
148
+
149
+ const blocksData = blocks.map(block => {
150
+ const clientId = block.clientId;
151
+ return {
152
+ isUnmodifiedDefaultBlock: getIsUnmodifiedDefaultBlock(block),
153
+ getBoundingClientRect: () => ownerDocument.getElementById(`block-${clientId}`).getBoundingClientRect(),
154
+ blockIndex: getBlockIndex(clientId)
155
+ };
156
+ });
157
+ const [targetIndex, operation] = getDropTargetPosition(blocksData, {
111
158
  x: event.clientX,
112
159
  y: event.clientY
113
160
  }, (_getBlockListSettings = getBlockListSettings(targetRootClientId)) === null || _getBlockListSettings === void 0 ? void 0 : _getBlockListSettings.orientation);
114
- setTargetBlockIndex(targetIndex === undefined ? 0 : targetIndex);
115
-
116
- if (targetIndex !== undefined) {
117
- const nextBlock = blockElements[targetIndex];
118
- const previousBlock = blockElements[targetIndex - 1]; // Don't show the insertion point when it's near an empty paragraph block.
119
-
120
- if (isEmptyParagraph(nextBlock) || isEmptyParagraph(previousBlock)) {
121
- return;
122
- }
123
-
124
- showInsertionPoint(targetRootClientId, targetIndex);
125
- }
126
- }, []), 200);
161
+ setDropTarget({
162
+ index: targetIndex,
163
+ operation
164
+ });
165
+ showInsertionPoint(targetRootClientId, targetIndex, {
166
+ operation
167
+ });
168
+ }, [targetRootClientId]), 200);
127
169
  return useDropZone({
128
170
  isDisabled,
129
171
  onDrop: onBlockDrop,
@@ -132,19 +174,17 @@ export default function useBlockDropZone() {
132
174
  // `currentTarget` is only available while the event is being
133
175
  // handled, so get it now and pass it to the thottled function.
134
176
  // https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
135
- throttled(event, event.currentTarget);
177
+ throttled(event, event.currentTarget.ownerDocument);
136
178
  },
137
179
 
138
180
  onDragLeave() {
139
181
  throttled.cancel();
140
182
  hideInsertionPoint();
141
- setTargetBlockIndex(null);
142
183
  },
143
184
 
144
185
  onDragEnd() {
145
186
  throttled.cancel();
146
187
  hideInsertionPoint();
147
- setTargetBlockIndex(null);
148
188
  }
149
189
 
150
190
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.js"],"names":["useDispatch","useSelect","useCallback","useState","useThrottle","__experimentalUseDropZone","useDropZone","isRTL","useOnBlockDrop","getDistanceToNearestEdge","store","blockEditorStore","getNearestBlockIndex","elements","position","orientation","allowedEdges","isRightToLeft","candidateIndex","candidateDistance","forEach","element","index","rect","getBoundingClientRect","distance","edge","undefined","isTrailingEdge","offset","isEmptyParagraph","dataset","type","empty","useBlockDropZone","rootClientId","targetRootClientId","targetBlockIndex","setTargetBlockIndex","isDisabled","select","getTemplateLock","__unstableIsWithinBlockOverlay","__unstableHasActiveBlockOverlayActive","templateLock","some","lock","getBlockListSettings","showInsertionPoint","hideInsertionPoint","onBlockDrop","throttled","event","currentTarget","blockElements","Array","from","children","filter","classList","contains","targetIndex","x","clientX","y","clientY","nextBlock","previousBlock","onDrop","onDragOver","onDragLeave","cancel","onDragEnd"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,WAAT,EAAsBC,QAAtB,QAAsC,oBAAtC;AACA,SACCC,WADD,EAECC,yBAAyB,IAAIC,WAF9B,QAGO,oBAHP;AAIA,SAASC,KAAT,QAAsB,iBAAtB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,sBAA3B;AACA,SAASC,wBAAT,QAAyC,kBAAzC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,CAA+BC,QAA/B,EAAyCC,QAAzC,EAAmDC,WAAnD,EAAiE;AACvE,QAAMC,YAAY,GACjBD,WAAW,KAAK,YAAhB,GACG,CAAE,MAAF,EAAU,OAAV,CADH,GAEG,CAAE,KAAF,EAAS,QAAT,CAHJ;AAKA,QAAME,aAAa,GAAGV,KAAK,EAA3B;AAEA,MAAIW,cAAJ;AACA,MAAIC,iBAAJ;AAEAN,EAAAA,QAAQ,CAACO,OAAT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aAAa,GAAGb,aAAa,CAAEO,WAAW,GAAG,CAAhB,CAAnC,CAFgC,CAIhC;;AACA,UACC/B,gBAAgB,CAAEoC,SAAF,CAAhB,IACApC,gBAAgB,CAAEqC,aAAF,CAFjB,EAGE;AACD;AACA;;AAEDnB,MAAAA,kBAAkB,CAAEZ,kBAAF,EAAsByB,WAAtB,CAAlB;AACA;AACD,GA3BU,EA2BR,EA3BQ,CADiB,EA6B5B,GA7B4B,CAA7B;AAgCA,SAAOvD,WAAW,CAAE;AACnBiC,IAAAA,UADmB;AAEnB6B,IAAAA,MAAM,EAAElB,WAFW;;AAGnBmB,IAAAA,UAAU,CAAEjB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KARkB;;AASnBiB,IAAAA,WAAW,GAAG;AACbnB,MAAAA,SAAS,CAACoB,MAAV;AACAtB,MAAAA,kBAAkB;AAClBX,MAAAA,mBAAmB,CAAE,IAAF,CAAnB;AACA,KAbkB;;AAcnBkC,IAAAA,SAAS,GAAG;AACXrB,MAAAA,SAAS,CAACoB,MAAV;AACAtB,MAAAA,kBAAkB;AAClBX,MAAAA,mBAAmB,CAAE,IAAF,CAAnB;AACA;;AAlBkB,GAAF,CAAlB;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { getDistanceToNearestEdge } from '../../utils/math';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * Given a list of block DOM elements finds the index that a block should be dropped\n * at.\n *\n * @param {Element[]} elements Array of DOM elements that represent each block in a block list.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of a block list.\n *\n * @return {number|undefined} The block index that's closest to the drag position.\n */\nexport function getNearestBlockIndex( elements, position, orientation ) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tconst isRightToLeft = isRTL();\n\n\tlet candidateIndex;\n\tlet candidateDistance;\n\n\telements.forEach( ( element, index ) => {\n\t\tconst rect = element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tallowedEdges\n\t\t);\n\n\t\tif ( candidateDistance === undefined || distance < candidateDistance ) {\n\t\t\t// If the user is dropping to the trailing edge of the block\n\t\t\t// add 1 to the index to represent dragging after.\n\t\t\t// Take RTL languages into account where the left edge is\n\t\t\t// the trailing edge.\n\t\t\tconst isTrailingEdge =\n\t\t\t\tedge === 'bottom' ||\n\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t( isRightToLeft && edge === 'left' );\n\t\t\tconst offset = isTrailingEdge ? 1 : 0;\n\n\t\t\t// Update the currently known best candidate.\n\t\t\tcandidateDistance = distance;\n\t\t\tcandidateIndex = index + offset;\n\t\t}\n\t} );\n\n\treturn candidateIndex;\n}\n\n/**\n * Determine if the element is an empty paragraph block.\n *\n * @param {?HTMLElement} element The element being tested.\n * @return {boolean} True or False.\n */\nfunction isEmptyParagraph( element ) {\n\treturn (\n\t\t!! element &&\n\t\telement.dataset.type === 'core/paragraph' &&\n\t\telement.dataset.empty === 'true'\n\t);\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n */\nexport default function useBlockDropZone( {\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n} = {} ) {\n\tconst [ targetBlockIndex, setTargetBlockIndex ] = useState( null );\n\n\tconst isDisabled = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetTemplateLock,\n\t\t\t\t__unstableIsWithinBlockOverlay,\n\t\t\t\t__unstableHasActiveBlockOverlayActive,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst templateLock = getTemplateLock( targetRootClientId );\n\t\t\treturn (\n\t\t\t\t[ 'all', 'contentOnly' ].some(\n\t\t\t\t\t( lock ) => lock === templateLock\n\t\t\t\t) ||\n\t\t\t\t__unstableHasActiveBlockOverlayActive( targetRootClientId ) ||\n\t\t\t\t__unstableIsWithinBlockOverlay( targetRootClientId )\n\t\t\t);\n\t\t},\n\t\t[ targetRootClientId ]\n\t);\n\n\tconst { getBlockListSettings } = useSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\tconst throttled = useThrottle(\n\t\tuseCallback( ( event, currentTarget ) => {\n\t\t\tconst blockElements = Array.from( currentTarget.children ).filter(\n\t\t\t\t// Ensure the element is a block. It should have the `wp-block` class.\n\t\t\t\t( element ) => element.classList.contains( 'wp-block' )\n\t\t\t);\n\t\t\tconst targetIndex = getNearestBlockIndex(\n\t\t\t\tblockElements,\n\t\t\t\t{ x: event.clientX, y: event.clientY },\n\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation\n\t\t\t);\n\n\t\t\tsetTargetBlockIndex( targetIndex === undefined ? 0 : targetIndex );\n\n\t\t\tif ( targetIndex !== undefined ) {\n\t\t\t\tconst nextBlock = blockElements[ targetIndex ];\n\t\t\t\tconst previousBlock = blockElements[ targetIndex - 1 ];\n\n\t\t\t\t// Don't show the insertion point when it's near an empty paragraph block.\n\t\t\t\tif (\n\t\t\t\t\tisEmptyParagraph( nextBlock ) ||\n\t\t\t\t\tisEmptyParagraph( previousBlock )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tshowInsertionPoint( targetRootClientId, targetIndex );\n\t\t\t}\n\t\t}, [] ),\n\t\t200\n\t);\n\n\treturn useDropZone( {\n\t\tisDisabled,\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t\tsetTargetBlockIndex( null );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t\tsetTargetBlockIndex( null );\n\t\t},\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.js"],"names":["useDispatch","useSelect","useCallback","useState","useThrottle","__experimentalUseDropZone","useDropZone","isRTL","isUnmodifiedDefaultBlock","getIsUnmodifiedDefaultBlock","useOnBlockDrop","getDistanceToNearestEdge","isPointContainedByRect","store","blockEditorStore","getDropTargetPosition","blocksData","position","orientation","allowedEdges","isRightToLeft","nearestIndex","insertPosition","minDistance","Infinity","forEach","getBoundingClientRect","blockIndex","rect","distance","edge","adjacentIndex","isNearestBlockUnmodifiedDefaultBlock","isAdjacentBlockUnmodifiedDefaultBlock","insertionIndex","useBlockDropZone","rootClientId","targetRootClientId","dropTarget","setDropTarget","index","operation","isDisabled","select","getTemplateLock","__unstableIsWithinBlockOverlay","__unstableHasActiveBlockOverlayActive","templateLock","some","lock","getBlockListSettings","getBlocks","getBlockIndex","showInsertionPoint","hideInsertionPoint","onBlockDrop","throttled","event","ownerDocument","blocks","length","map","block","clientId","getElementById","targetIndex","x","clientX","y","clientY","onDrop","onDragOver","currentTarget","onDragLeave","cancel","onDragEnd"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,WAAT,EAAsBC,QAAtB,QAAsC,oBAAtC;AACA,SACCC,WADD,EAECC,yBAAyB,IAAIC,WAF9B,QAGO,oBAHP;AAIA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,wBAAwB,IAAIC,2BAArC,QAAwE,mBAAxE;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,sBAA3B;AACA,SACCC,wBADD,EAECC,sBAFD,QAGO,kBAHP;AAIA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CACNC,UADM,EAENC,QAFM,EAIL;AAAA;;AAAA,MADDC,WACC,uEADa,UACb;AACD,QAAMC,YAAY,GACjBD,WAAW,KAAK,YAAhB,GACG,CAAE,MAAF,EAAU,OAAV,CADH,GAEG,CAAE,KAAF,EAAS,QAAT,CAHJ;AAKA,QAAME,aAAa,GAAGb,KAAK,EAA3B;AAEA,MAAIc,YAAY,GAAG,CAAnB;AACA,MAAIC,cAAc,GAAG,QAArB;AACA,MAAIC,WAAW,GAAGC,QAAlB;AAEAR,EAAAA,UAAU,CAACS,OAAX,CACC,QAAuE;AAAA,QAArE;AAAEjB,MAAAA,wBAAF;AAA4BkB,MAAAA,qBAA5B;AAAmDC,MAAAA;AAAnD,KAAqE;AACtE,UAAMC,IAAI,GAAGF,qBAAqB,EAAlC;AAEA,QAAI,C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WAAW,GAAG;AACbjB,MAAAA,SAAS,CAACkB,MAAV;AACApB,MAAAA,kBAAkB;AAClB,KAZkB;;AAanBqB,IAAAA,SAAS,GAAG;AACXnB,MAAAA,SAAS,CAACkB,MAAV;AACApB,MAAAA,kBAAkB;AAClB;;AAhBkB,GAAF,CAAlB;AAkBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\nimport { isUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport useOnBlockDrop from '../use-on-block-drop';\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * The insert position when dropping a block.\n *\n * @typedef {'before'|'after'} WPInsertPosition\n */\n\n/**\n * @typedef {Object} WPBlockData\n * @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.\n * @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.\n * @property {number} blockIndex The index of the block.\n */\n\n/**\n * Get the drop target position from a given drop point and the orientation.\n *\n * @param {WPBlockData[]} blocksData The block data list.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of the block list.\n * @return {[number, WPDropOperation]} The drop target position.\n */\nexport function getDropTargetPosition(\n\tblocksData,\n\tposition,\n\torientation = 'vertical'\n) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tconst isRightToLeft = isRTL();\n\n\tlet nearestIndex = 0;\n\tlet insertPosition = 'before';\n\tlet minDistance = Infinity;\n\n\tblocksData.forEach(\n\t\t( { isUnmodifiedDefaultBlock, getBoundingClientRect, blockIndex } ) => {\n\t\t\tconst rect = getBoundingClientRect();\n\n\t\t\tlet [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\t\tposition,\n\t\t\t\trect,\n\t\t\t\tallowedEdges\n\t\t\t);\n\t\t\t// Prioritize the element if the point is inside of an unmodified default block.\n\t\t\tif (\n\t\t\t\tisUnmodifiedDefaultBlock &&\n\t\t\t\tisPointContainedByRect( position, rect )\n\t\t\t) {\n\t\t\t\tdistance = 0;\n\t\t\t}\n\n\t\t\tif ( distance < minDistance ) {\n\t\t\t\t// Where the dropped block will be inserted on the nearest block.\n\t\t\t\tinsertPosition =\n\t\t\t\t\tedge === 'bottom' ||\n\t\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t\t( isRightToLeft && edge === 'left' )\n\t\t\t\t\t\t? 'after'\n\t\t\t\t\t\t: 'before';\n\n\t\t\t\t// Update the currently known best candidate.\n\t\t\t\tminDistance = distance;\n\t\t\t\tnearestIndex = blockIndex;\n\t\t\t}\n\t\t}\n\t);\n\n\tconst adjacentIndex =\n\t\tnearestIndex + ( insertPosition === 'after' ? 1 : -1 );\n\tconst isNearestBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ nearestIndex ]?.isUnmodifiedDefaultBlock;\n\tconst isAdjacentBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ adjacentIndex ]?.isUnmodifiedDefaultBlock;\n\n\t// If both blocks are not unmodified default blocks then just insert between them.\n\tif (\n\t\t! isNearestBlockUnmodifiedDefaultBlock &&\n\t\t! isAdjacentBlockUnmodifiedDefaultBlock\n\t) {\n\t\t// If the user is dropping to the trailing edge of the block\n\t\t// add 1 to the index to represent dragging after.\n\t\tconst insertionIndex =\n\t\t\tinsertPosition === 'after' ? nearestIndex + 1 : nearestIndex;\n\t\treturn [ insertionIndex, 'insert' ];\n\t}\n\n\t// Otherwise, replace the nearest unmodified default block.\n\treturn [\n\t\tisNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex,\n\t\t'replace',\n\t];\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n */\nexport default function useBlockDropZone( {\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n} = {} ) {\n\tconst [ dropTarget, setDropTarget ] = useState( {\n\t\tindex: null,\n\t\toperation: 'insert',\n\t} );\n\n\tconst isDisabled = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetTemplateLock,\n\t\t\t\t__unstableIsWithinBlockOverlay,\n\t\t\t\t__unstableHasActiveBlockOverlayActive,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst templateLock = getTemplateLock( targetRootClientId );\n\t\t\treturn (\n\t\t\t\t[ 'all', 'contentOnly' ].some(\n\t\t\t\t\t( lock ) => lock === templateLock\n\t\t\t\t) ||\n\t\t\t\t__unstableHasActiveBlockOverlayActive( targetRootClientId ) ||\n\t\t\t\t__unstableIsWithinBlockOverlay( targetRootClientId )\n\t\t\t);\n\t\t},\n\t\t[ targetRootClientId ]\n\t);\n\n\tconst { getBlockListSettings, getBlocks, getBlockIndex } =\n\t\tuseSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, dropTarget.index, {\n\t\toperation: dropTarget.operation,\n\t} );\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, ownerDocument ) => {\n\t\t\t\tconst blocks = getBlocks( targetRootClientId );\n\n\t\t\t\t// The block list is empty, don't show the insertion point but still allow dropping.\n\t\t\t\tif ( blocks.length === 0 ) {\n\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocksData = blocks.map( ( block ) => {\n\t\t\t\t\tconst clientId = block.clientId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tisUnmodifiedDefaultBlock:\n\t\t\t\t\t\t\tgetIsUnmodifiedDefaultBlock( block ),\n\t\t\t\t\t\tgetBoundingClientRect: () =>\n\t\t\t\t\t\t\townerDocument\n\t\t\t\t\t\t\t\t.getElementById( `block-${ clientId }` )\n\t\t\t\t\t\t\t\t.getBoundingClientRect(),\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst [ targetIndex, operation ] = getDropTargetPosition(\n\t\t\t\t\tblocksData,\n\t\t\t\t\t{ x: event.clientX, y: event.clientY },\n\t\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation\n\t\t\t\t);\n\n\t\t\t\tsetDropTarget( {\n\t\t\t\t\tindex: targetIndex,\n\t\t\t\t\toperation,\n\t\t\t\t} );\n\t\t\t\tshowInsertionPoint( targetRootClientId, targetIndex, {\n\t\t\t\t\toperation,\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[ targetRootClientId ]\n\t\t),\n\t\t200\n\t);\n\n\treturn useDropZone( {\n\t\tisDisabled,\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget.ownerDocument );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t} );\n}\n"]}
@@ -12,6 +12,8 @@ import { getFilesFromDataTransfer } from '@wordpress/dom';
12
12
  import { store as blockEditorStore } from '../../store';
13
13
  /** @typedef {import('@wordpress/element').WPSyntheticEvent} WPSyntheticEvent */
14
14
 
15
+ /** @typedef {import('./types').WPDropOperation} WPDropOperation */
16
+
15
17
  /**
16
18
  * Retrieve the data for a block drop event.
17
19
  *
@@ -146,20 +148,18 @@ export function onHTMLDrop(targetRootClientId, targetBlockIndex, insertOrReplace
146
148
  /**
147
149
  * A React hook for handling block drop events.
148
150
  *
149
- * @typedef {'insert'|'replace'} DropAction The type of action to perform on drop.
150
- *
151
- * @param {string} targetRootClientId The root client id where the block(s) will be inserted.
152
- * @param {number} targetBlockIndex The index where the block(s) will be inserted.
153
- * @param {Object} options The optional options.
154
- * @param {DropAction} options.action The type of action to perform on drop. Could be `insert` or `replace` for now.
151
+ * @param {string} targetRootClientId The root client id where the block(s) will be inserted.
152
+ * @param {number} targetBlockIndex The index where the block(s) will be inserted.
153
+ * @param {Object} options The optional options.
154
+ * @param {WPDropOperation} [options.operation] The type of operation to perform on drop. Could be `insert` or `replace` for now.
155
155
  *
156
- * @return {Object} An object that contains the event handlers `onDrop`, `onFilesDrop` and `onHTMLDrop`.
156
+ * @return {Function} A function to be passed to the onDrop handler.
157
157
  */
158
158
 
159
159
  export default function useOnBlockDrop(targetRootClientId, targetBlockIndex) {
160
160
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
161
161
  const {
162
- action = 'insert'
162
+ operation = 'insert'
163
163
  } = options;
164
164
  const hasUploadPermissions = useSelect(select => select(blockEditorStore).getSettings().mediaUpload, []);
165
165
  const {
@@ -182,16 +182,16 @@ export default function useOnBlockDrop(targetRootClientId, targetBlockIndex) {
182
182
  let updateSelection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
183
183
  let initialPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
184
184
 
185
- if (action === 'replace') {
185
+ if (operation === 'replace') {
186
186
  const clientIds = getBlockOrder(targetRootClientId);
187
187
  const clientId = clientIds[targetBlockIndex];
188
188
  replaceBlocks(clientId, blocks, undefined, initialPosition);
189
189
  } else {
190
190
  insertBlocks(blocks, targetBlockIndex, targetRootClientId, updateSelection, initialPosition);
191
191
  }
192
- }, [action, getBlockOrder, insertBlocks, replaceBlocks, targetBlockIndex, targetRootClientId]);
192
+ }, [operation, getBlockOrder, insertBlocks, replaceBlocks, targetBlockIndex, targetRootClientId]);
193
193
  const moveBlocks = useCallback((sourceClientIds, sourceRootClientId, insertIndex) => {
194
- if (action === 'replace') {
194
+ if (operation === 'replace') {
195
195
  const sourceBlocks = getBlocksByClientId(sourceClientIds);
196
196
  const targetBlockClientIds = getBlockOrder(targetRootClientId);
197
197
  const targetBlockClientId = targetBlockClientIds[targetBlockIndex];
@@ -204,7 +204,7 @@ export default function useOnBlockDrop(targetRootClientId, targetBlockIndex) {
204
204
  } else {
205
205
  moveBlocksToPosition(sourceClientIds, sourceRootClientId, targetRootClientId, insertIndex);
206
206
  }
207
- }, [action, getBlockOrder, getBlocksByClientId, insertBlocks, moveBlocksToPosition, removeBlocks, targetBlockIndex, targetRootClientId]);
207
+ }, [operation, getBlockOrder, getBlocksByClientId, insertBlocks, moveBlocksToPosition, removeBlocks, targetBlockIndex, targetRootClientId]);
208
208
 
209
209
  const _onDrop = onBlockDrop(targetRootClientId, targetBlockIndex, getBlockIndex, getClientIdsOfDescendants, moveBlocks, insertOrReplaceBlocks, clearSelectedBlock);
210
210
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/use-on-block-drop/index.js"],"names":["useCallback","cloneBlock","findTransform","getBlockTransforms","pasteHandler","useDispatch","useSelect","useRegistry","getFilesFromDataTransfer","store","blockEditorStore","parseDropEvent","event","result","srcRootClientId","srcClientIds","srcIndex","type","blocks","dataTransfer","Object","assign","JSON","parse","getData","err","onBlockDrop","targetRootClientId","targetBlockIndex","getBlockIndex","getClientIdsOfDescendants","moveBlocks","insertOrReplaceBlocks","clearSelectedBlock","sourceRootClientId","sourceClientIds","dropType","blocksToInsert","map","block","sourceBlockIndex","includes","some","id","isAtSameLevel","draggedBlockCount","length","insertIndex","onFilesDrop","hasUploadPermissions","updateBlockAttributes","canInsertBlockType","files","transformation","transform","blockName","isMatch","onHTMLDrop","HTML","mode","useOnBlockDrop","options","action","select","getSettings","mediaUpload","getBlockOrder","getBlocksByClientId","insertBlocks","moveBlocksToPosition","replaceBlocks","removeBlocks","registry","updateSelection","initialPosition","clientIds","clientId","undefined","sourceBlocks","targetBlockClientIds","targetBlockClientId","batch","_onDrop","_onFilesDrop","_onHTMLDrop","html"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,oBAA5B;AACA,SACCC,UADD,EAECC,aAFD,EAGCC,kBAHD,EAICC,YAJD,QAKO,mBALP;AAMA,SAASC,WAAT,EAAsBC,SAAtB,EAAiCC,WAAjC,QAAoD,iBAApD;AACA,SAASC,wBAAT,QAAyC,gBAAzC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,cAAT,CAAyBC,KAAzB,EAAiC;AACvC,MAAIC,MAAM,GAAG;AACZC,IAAAA,eAAe,EAAE,IADL;AAEZC,IAAAA,YAAY,EAAE,IAFF;AAGZC,IAAAA,QAAQ,EAAE,IAHE;AAIZC,IAAAA,IAAI,EAAE,IAJM;AAKZC,IAAAA,MAAM,EAAE;AALI,GAAb;;AAQA,MAAK,CAAEN,KAAK,CAACO,YAAb,EAA4B;AAC3B,WAAON,MAAP;AACA;;AAED,MAAI;AACHA,IAAAA,MAAM,GAA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E/BC,gBAF+B,EAG/BqB,oBAH+B,EAI/BC,qBAJ+B,EAK/BC,kBAL+B,EAM/BnB,qBAN+B,CAAhC;;AAQA,QAAMoD,WAAW,GAAG3B,UAAU,CAC7B9B,kBAD6B,EAE7BC,gBAF6B,EAG7BI,qBAH6B,CAA9B;;AAMA,SAASpB,KAAF,IAAa;AACnB,UAAMwC,KAAK,GAAG5C,wBAAwB,CAAEI,KAAK,CAACO,YAAR,CAAtC;AACA,UAAMkE,IAAI,GAAGzE,KAAK,CAACO,YAAN,CAAmBK,OAAnB,CAA4B,WAA5B,CAAb;AAEA;AACF;AACA;AACA;;AACE,QAAK6D,IAAL,EAAY;AACXD,MAAAA,WAAW,CAAEC,IAAF,CAAX;AACA,KAFD,MAEO,IAAKjC,KAAK,CAACN,MAAX,EAAoB;AAC1BqC,MAAAA,YAAY,CAAE/B,KAAF,CAAZ;AACA,KAFM,MAEA;AACN8B,MAAAA,OAAO,CAAEtE,KAAF,CAAP;AACA;AACD,GAfD;AAgBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport {\n\tcloneBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n\tpasteHandler,\n} from '@wordpress/blocks';\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('@wordpress/element').WPSyntheticEvent} WPSyntheticEvent */\n\n/**\n * Retrieve the data for a block drop event.\n *\n * @param {WPSyntheticEvent} event The drop event.\n *\n * @return {Object} An object with block drag and drop data.\n */\nexport function parseDropEvent( event ) {\n\tlet result = {\n\t\tsrcRootClientId: null,\n\t\tsrcClientIds: null,\n\t\tsrcIndex: null,\n\t\ttype: null,\n\t\tblocks: null,\n\t};\n\n\tif ( ! event.dataTransfer ) {\n\t\treturn result;\n\t}\n\n\ttry {\n\t\tresult = Object.assign(\n\t\t\tresult,\n\t\t\tJSON.parse( event.dataTransfer.getData( 'wp-blocks' ) )\n\t\t);\n\t} catch ( err ) {\n\t\treturn result;\n\t}\n\n\treturn result;\n}\n\n/**\n * A function that returns an event handler function for block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} getBlockIndex A function that gets the index of a block.\n * @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.\n * @param {Function} moveBlocks A function that moves blocks.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n * @param {Function} clearSelectedBlock A function that clears block selection.\n * @return {Function} The event handler for a block drop event.\n */\nexport function onBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tgetBlockIndex,\n\tgetClientIdsOfDescendants,\n\tmoveBlocks,\n\tinsertOrReplaceBlocks,\n\tclearSelectedBlock\n) {\n\treturn ( event ) => {\n\t\tconst {\n\t\t\tsrcRootClientId: sourceRootClientId,\n\t\t\tsrcClientIds: sourceClientIds,\n\t\t\ttype: dropType,\n\t\t\tblocks,\n\t\t} = parseDropEvent( event );\n\n\t\t// If the user is inserting a block.\n\t\tif ( dropType === 'inserter' ) {\n\t\t\tclearSelectedBlock();\n\t\t\tconst blocksToInsert = blocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tinsertOrReplaceBlocks( blocksToInsert, true, null );\n\t\t}\n\n\t\t// If the user is moving a block.\n\t\tif ( dropType === 'block' ) {\n\t\t\tconst sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );\n\n\t\t\t// If the user is dropping to the same position, return early.\n\t\t\tif (\n\t\t\t\tsourceRootClientId === targetRootClientId &&\n\t\t\t\tsourceBlockIndex === targetBlockIndex\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is attempting to drop a block within its own\n\t\t\t// nested blocks, return early as this would create infinite\n\t\t\t// recursion.\n\t\t\tif (\n\t\t\t\tsourceClientIds.includes( targetRootClientId ) ||\n\t\t\t\tgetClientIdsOfDescendants( sourceClientIds ).some(\n\t\t\t\t\t( id ) => id === targetRootClientId\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isAtSameLevel = sourceRootClientId === targetRootClientId;\n\t\t\tconst draggedBlockCount = sourceClientIds.length;\n\n\t\t\t// If the block is kept at the same level and moved downwards,\n\t\t\t// subtract to take into account that the blocks being dragged\n\t\t\t// were removed from the block list above the insertion point.\n\t\t\tconst insertIndex =\n\t\t\t\tisAtSameLevel && sourceBlockIndex < targetBlockIndex\n\t\t\t\t\t? targetBlockIndex - draggedBlockCount\n\t\t\t\t\t: targetBlockIndex;\n\n\t\t\tmoveBlocks( sourceClientIds, sourceRootClientId, insertIndex );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related file drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {boolean} hasUploadPermissions Whether the user has upload permissions.\n * @param {Function} updateBlockAttributes A function that updates a block's attributes.\n * @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n *\n * @return {Function} The event handler for a block-related file drop event.\n */\nexport function onFilesDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\thasUploadPermissions,\n\tupdateBlockAttributes,\n\tcanInsertBlockType,\n\tinsertOrReplaceBlocks\n) {\n\treturn ( files ) => {\n\t\tif ( ! hasUploadPermissions ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformation = findTransform(\n\t\t\tgetBlockTransforms( 'from' ),\n\t\t\t( transform ) =>\n\t\t\t\ttransform.type === 'files' &&\n\t\t\t\tcanInsertBlockType( transform.blockName, targetRootClientId ) &&\n\t\t\t\ttransform.isMatch( files )\n\t\t);\n\n\t\tif ( transformation ) {\n\t\t\tconst blocks = transformation.transform(\n\t\t\t\tfiles,\n\t\t\t\tupdateBlockAttributes\n\t\t\t);\n\t\t\tinsertOrReplaceBlocks( blocks );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related HTML drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n *\n * @return {Function} The event handler for a block-related HTML drop event.\n */\nexport function onHTMLDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tinsertOrReplaceBlocks\n) {\n\treturn ( HTML ) => {\n\t\tconst blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );\n\n\t\tif ( blocks.length ) {\n\t\t\tinsertOrReplaceBlocks( blocks );\n\t\t}\n\t};\n}\n\n/**\n * A React hook for handling block drop events.\n *\n * @typedef {'insert'|'replace'} DropAction The type of action to perform on drop.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Object} options The optional options.\n * @param {DropAction} options.action The type of action to perform on drop. Could be `insert` or `replace` for now.\n *\n * @return {Object} An object that contains the event handlers `onDrop`, `onFilesDrop` and `onHTMLDrop`.\n */\nexport default function useOnBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\toptions = {}\n) {\n\tconst { action = 'insert' } = options;\n\tconst hasUploadPermissions = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tgetBlockOrder,\n\t\tgetBlocksByClientId,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tinsertBlocks,\n\t\tmoveBlocksToPosition,\n\t\tupdateBlockAttributes,\n\t\tclearSelectedBlock,\n\t\treplaceBlocks,\n\t\tremoveBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst registry = useRegistry();\n\n\tconst insertOrReplaceBlocks = useCallback(\n\t\t( blocks, updateSelection = true, initialPosition = 0 ) => {\n\t\t\tif ( action === 'replace' ) {\n\t\t\t\tconst clientIds = getBlockOrder( targetRootClientId );\n\t\t\t\tconst clientId = clientIds[ targetBlockIndex ];\n\n\t\t\t\treplaceBlocks( clientId, blocks, undefined, initialPosition );\n\t\t\t} else {\n\t\t\t\tinsertBlocks(\n\t\t\t\t\tblocks,\n\t\t\t\t\ttargetBlockIndex,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\tupdateSelection,\n\t\t\t\t\tinitialPosition\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\taction,\n\t\t\tgetBlockOrder,\n\t\t\tinsertBlocks,\n\t\t\treplaceBlocks,\n\t\t\ttargetBlockIndex,\n\t\t\ttargetRootClientId,\n\t\t]\n\t);\n\n\tconst moveBlocks = useCallback(\n\t\t( sourceClientIds, sourceRootClientId, insertIndex ) => {\n\t\t\tif ( action === 'replace' ) {\n\t\t\t\tconst sourceBlocks = getBlocksByClientId( sourceClientIds );\n\t\t\t\tconst targetBlockClientIds =\n\t\t\t\t\tgetBlockOrder( targetRootClientId );\n\t\t\t\tconst targetBlockClientId =\n\t\t\t\t\ttargetBlockClientIds[ targetBlockIndex ];\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t// Remove the source blocks.\n\t\t\t\t\tremoveBlocks( sourceClientIds, false );\n\t\t\t\t\t// Replace the target block with the source blocks.\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\ttargetBlockClientId,\n\t\t\t\t\t\tsourceBlocks,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t0\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\tsourceClientIds,\n\t\t\t\t\tsourceRootClientId,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\tinsertIndex\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\taction,\n\t\t\tgetBlockOrder,\n\t\t\tgetBlocksByClientId,\n\t\t\tinsertBlocks,\n\t\t\tmoveBlocksToPosition,\n\t\t\tremoveBlocks,\n\t\t\ttargetBlockIndex,\n\t\t\ttargetRootClientId,\n\t\t]\n\t);\n\n\tconst _onDrop = onBlockDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tmoveBlocks,\n\t\tinsertOrReplaceBlocks,\n\t\tclearSelectedBlock\n\t);\n\tconst _onFilesDrop = onFilesDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\thasUploadPermissions,\n\t\tupdateBlockAttributes,\n\t\tcanInsertBlockType,\n\t\tinsertOrReplaceBlocks\n\t);\n\tconst _onHTMLDrop = onHTMLDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tinsertOrReplaceBlocks\n\t);\n\n\treturn ( event ) => {\n\t\tconst files = getFilesFromDataTransfer( event.dataTransfer );\n\t\tconst html = event.dataTransfer.getData( 'text/html' );\n\n\t\t/**\n\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t * The order of the checks is important to recognise the HTML drop.\n\t\t */\n\t\tif ( html ) {\n\t\t\t_onHTMLDrop( html );\n\t\t} else if ( files.length ) {\n\t\t\t_onFilesDrop( files );\n\t\t} else {\n\t\t\t_onDrop( event );\n\t\t}\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/use-on-block-drop/index.js"],"names":["useCallback","cloneBlock","findTransform","getBlockTransforms","pasteHandler","useDispatch","useSelect","useRegistry","getFilesFromDataTransfer","store","blockEditorStore","parseDropEvent","event","result","srcRootClientId","srcClientIds","srcIndex","type","blocks","dataTransfer","Object","assign","JSON","parse","getData","err","onBlockDrop","targetRootClientId","targetBlockIndex","getBlockIndex","getClientIdsOfDescendants","moveBlocks","insertOrReplaceBlocks","clearSelectedBlock","sourceRootClientId","sourceClientIds","dropType","blocksToInsert","map","block","sourceBlockIndex","includes","some","id","isAtSameLevel","draggedBlockCount","length","insertIndex","onFilesDrop","hasUploadPermissions","updateBlockAttributes","canInsertBlockType","files","transformation","transform","blockName","isMatch","onHTMLDrop","HTML","mode","useOnBlockDrop","options","operation","select","getSettings","mediaUpload","getBlockOrder","getBlocksByClientId","insertBlocks","moveBlocksToPosition","replaceBlocks","removeBlocks","registry","updateSelection","initialPosition","clientIds","clientId","undefined","sourceBlocks","targetBlockClientIds","targetBlockClientId","batch","_onDrop","_onFilesDrop","_onHTMLDrop","html"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,oBAA5B;AACA,SACCC,UADD,EAECC,aAFD,EAGCC,kBAHD,EAICC,YAJD,QAKO,mBALP;AAMA,SAASC,WAAT,EAAsBC,SAAtB,EAAiCC,WAAjC,QAAoD,iBAApD;AACA,SAASC,wBAAT,QAAyC,gBAAzC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,cAAT,CAAyBC,KAAzB,EAAiC;AACvC,MAAIC,MAAM,GAAG;AACZC,IAAAA,eAAe,EAAE,IADL;AAEZC,IAAAA,YAAY,EAAE,IAFF;AAGZC,IAAAA,QAAQ,EAAE,IAHE;AAIZC,IAAAA,IAAI,EAAE,IAJM;AAKZC,IAAAA,MAAM,EAAE;AALI,GAAb;;AAQA,MAAK,CAAEN,KAAK,CAACO,YAAb,EAA4B;AAC3B,WAAON,MAAP;AACA;;AAED,MAAI;AACHA,IAAAA,MAAM,GAAGO,MAAM,CAACC,MAAP,CACRR,MADQ,EAERS,IAAI,CAACC,KAAL,CAAYX,KAAK,CAACO,YAAN,CAAmBK,OAAnB,CAA4B,WAA5B,CAAZ,CAFQ,CAAT;AAIA,GALD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C,gBAF6B,EAG7BI,qBAH6B,CAA9B;;AAMA,SAASpB,KAAF,IAAa;AACnB,UAAMwC,KAAK,GAAG5C,wBAAwB,CAAEI,KAAK,CAACO,YAAR,CAAtC;AACA,UAAMkE,IAAI,GAAGzE,KAAK,CAACO,YAAN,CAAmBK,OAAnB,CAA4B,WAA5B,CAAb;AAEA;AACF;AACA;AACA;;AACE,QAAK6D,IAAL,EAAY;AACXD,MAAAA,WAAW,CAAEC,IAAF,CAAX;AACA,KAFD,MAEO,IAAKjC,KAAK,CAACN,MAAX,EAAoB;AAC1BqC,MAAAA,YAAY,CAAE/B,KAAF,CAAZ;AACA,KAFM,MAEA;AACN8B,MAAAA,OAAO,CAAEtE,KAAF,CAAP;AACA;AACD,GAfD;AAgBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport {\n\tcloneBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n\tpasteHandler,\n} from '@wordpress/blocks';\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('@wordpress/element').WPSyntheticEvent} WPSyntheticEvent */\n/** @typedef {import('./types').WPDropOperation} WPDropOperation */\n\n/**\n * Retrieve the data for a block drop event.\n *\n * @param {WPSyntheticEvent} event The drop event.\n *\n * @return {Object} An object with block drag and drop data.\n */\nexport function parseDropEvent( event ) {\n\tlet result = {\n\t\tsrcRootClientId: null,\n\t\tsrcClientIds: null,\n\t\tsrcIndex: null,\n\t\ttype: null,\n\t\tblocks: null,\n\t};\n\n\tif ( ! event.dataTransfer ) {\n\t\treturn result;\n\t}\n\n\ttry {\n\t\tresult = Object.assign(\n\t\t\tresult,\n\t\t\tJSON.parse( event.dataTransfer.getData( 'wp-blocks' ) )\n\t\t);\n\t} catch ( err ) {\n\t\treturn result;\n\t}\n\n\treturn result;\n}\n\n/**\n * A function that returns an event handler function for block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} getBlockIndex A function that gets the index of a block.\n * @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.\n * @param {Function} moveBlocks A function that moves blocks.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n * @param {Function} clearSelectedBlock A function that clears block selection.\n * @return {Function} The event handler for a block drop event.\n */\nexport function onBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tgetBlockIndex,\n\tgetClientIdsOfDescendants,\n\tmoveBlocks,\n\tinsertOrReplaceBlocks,\n\tclearSelectedBlock\n) {\n\treturn ( event ) => {\n\t\tconst {\n\t\t\tsrcRootClientId: sourceRootClientId,\n\t\t\tsrcClientIds: sourceClientIds,\n\t\t\ttype: dropType,\n\t\t\tblocks,\n\t\t} = parseDropEvent( event );\n\n\t\t// If the user is inserting a block.\n\t\tif ( dropType === 'inserter' ) {\n\t\t\tclearSelectedBlock();\n\t\t\tconst blocksToInsert = blocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tinsertOrReplaceBlocks( blocksToInsert, true, null );\n\t\t}\n\n\t\t// If the user is moving a block.\n\t\tif ( dropType === 'block' ) {\n\t\t\tconst sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );\n\n\t\t\t// If the user is dropping to the same position, return early.\n\t\t\tif (\n\t\t\t\tsourceRootClientId === targetRootClientId &&\n\t\t\t\tsourceBlockIndex === targetBlockIndex\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is attempting to drop a block within its own\n\t\t\t// nested blocks, return early as this would create infinite\n\t\t\t// recursion.\n\t\t\tif (\n\t\t\t\tsourceClientIds.includes( targetRootClientId ) ||\n\t\t\t\tgetClientIdsOfDescendants( sourceClientIds ).some(\n\t\t\t\t\t( id ) => id === targetRootClientId\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isAtSameLevel = sourceRootClientId === targetRootClientId;\n\t\t\tconst draggedBlockCount = sourceClientIds.length;\n\n\t\t\t// If the block is kept at the same level and moved downwards,\n\t\t\t// subtract to take into account that the blocks being dragged\n\t\t\t// were removed from the block list above the insertion point.\n\t\t\tconst insertIndex =\n\t\t\t\tisAtSameLevel && sourceBlockIndex < targetBlockIndex\n\t\t\t\t\t? targetBlockIndex - draggedBlockCount\n\t\t\t\t\t: targetBlockIndex;\n\n\t\t\tmoveBlocks( sourceClientIds, sourceRootClientId, insertIndex );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related file drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {boolean} hasUploadPermissions Whether the user has upload permissions.\n * @param {Function} updateBlockAttributes A function that updates a block's attributes.\n * @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n *\n * @return {Function} The event handler for a block-related file drop event.\n */\nexport function onFilesDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\thasUploadPermissions,\n\tupdateBlockAttributes,\n\tcanInsertBlockType,\n\tinsertOrReplaceBlocks\n) {\n\treturn ( files ) => {\n\t\tif ( ! hasUploadPermissions ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformation = findTransform(\n\t\t\tgetBlockTransforms( 'from' ),\n\t\t\t( transform ) =>\n\t\t\t\ttransform.type === 'files' &&\n\t\t\t\tcanInsertBlockType( transform.blockName, targetRootClientId ) &&\n\t\t\t\ttransform.isMatch( files )\n\t\t);\n\n\t\tif ( transformation ) {\n\t\t\tconst blocks = transformation.transform(\n\t\t\t\tfiles,\n\t\t\t\tupdateBlockAttributes\n\t\t\t);\n\t\t\tinsertOrReplaceBlocks( blocks );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related HTML drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n *\n * @return {Function} The event handler for a block-related HTML drop event.\n */\nexport function onHTMLDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tinsertOrReplaceBlocks\n) {\n\treturn ( HTML ) => {\n\t\tconst blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );\n\n\t\tif ( blocks.length ) {\n\t\t\tinsertOrReplaceBlocks( blocks );\n\t\t}\n\t};\n}\n\n/**\n * A React hook for handling block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Object} options The optional options.\n * @param {WPDropOperation} [options.operation] The type of operation to perform on drop. Could be `insert` or `replace` for now.\n *\n * @return {Function} A function to be passed to the onDrop handler.\n */\nexport default function useOnBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\toptions = {}\n) {\n\tconst { operation = 'insert' } = options;\n\tconst hasUploadPermissions = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tgetBlockOrder,\n\t\tgetBlocksByClientId,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tinsertBlocks,\n\t\tmoveBlocksToPosition,\n\t\tupdateBlockAttributes,\n\t\tclearSelectedBlock,\n\t\treplaceBlocks,\n\t\tremoveBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst registry = useRegistry();\n\n\tconst insertOrReplaceBlocks = useCallback(\n\t\t( blocks, updateSelection = true, initialPosition = 0 ) => {\n\t\t\tif ( operation === 'replace' ) {\n\t\t\t\tconst clientIds = getBlockOrder( targetRootClientId );\n\t\t\t\tconst clientId = clientIds[ targetBlockIndex ];\n\n\t\t\t\treplaceBlocks( clientId, blocks, undefined, initialPosition );\n\t\t\t} else {\n\t\t\t\tinsertBlocks(\n\t\t\t\t\tblocks,\n\t\t\t\t\ttargetBlockIndex,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\tupdateSelection,\n\t\t\t\t\tinitialPosition\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\toperation,\n\t\t\tgetBlockOrder,\n\t\t\tinsertBlocks,\n\t\t\treplaceBlocks,\n\t\t\ttargetBlockIndex,\n\t\t\ttargetRootClientId,\n\t\t]\n\t);\n\n\tconst moveBlocks = useCallback(\n\t\t( sourceClientIds, sourceRootClientId, insertIndex ) => {\n\t\t\tif ( operation === 'replace' ) {\n\t\t\t\tconst sourceBlocks = getBlocksByClientId( sourceClientIds );\n\t\t\t\tconst targetBlockClientIds =\n\t\t\t\t\tgetBlockOrder( targetRootClientId );\n\t\t\t\tconst targetBlockClientId =\n\t\t\t\t\ttargetBlockClientIds[ targetBlockIndex ];\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t// Remove the source blocks.\n\t\t\t\t\tremoveBlocks( sourceClientIds, false );\n\t\t\t\t\t// Replace the target block with the source blocks.\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\ttargetBlockClientId,\n\t\t\t\t\t\tsourceBlocks,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t0\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\tsourceClientIds,\n\t\t\t\t\tsourceRootClientId,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\tinsertIndex\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\toperation,\n\t\t\tgetBlockOrder,\n\t\t\tgetBlocksByClientId,\n\t\t\tinsertBlocks,\n\t\t\tmoveBlocksToPosition,\n\t\t\tremoveBlocks,\n\t\t\ttargetBlockIndex,\n\t\t\ttargetRootClientId,\n\t\t]\n\t);\n\n\tconst _onDrop = onBlockDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tmoveBlocks,\n\t\tinsertOrReplaceBlocks,\n\t\tclearSelectedBlock\n\t);\n\tconst _onFilesDrop = onFilesDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\thasUploadPermissions,\n\t\tupdateBlockAttributes,\n\t\tcanInsertBlockType,\n\t\tinsertOrReplaceBlocks\n\t);\n\tconst _onHTMLDrop = onHTMLDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tinsertOrReplaceBlocks\n\t);\n\n\treturn ( event ) => {\n\t\tconst files = getFilesFromDataTransfer( event.dataTransfer );\n\t\tconst html = event.dataTransfer.getData( 'text/html' );\n\n\t\t/**\n\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t * The order of the checks is important to recognise the HTML drop.\n\t\t */\n\t\tif ( html ) {\n\t\t\t_onHTMLDrop( html );\n\t\t} else if ( files.length ) {\n\t\t\t_onFilesDrop( files );\n\t\t} else {\n\t\t\t_onDrop( event );\n\t\t}\n\t};\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}