@wordpress/block-editor 16.0.0 → 16.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +8 -0
  3. package/build/components/alignment-control/ui.cjs +2 -4
  4. package/build/components/alignment-control/ui.cjs.map +2 -2
  5. package/build/components/background-image-control/index.cjs +40 -10
  6. package/build/components/background-image-control/index.cjs.map +2 -2
  7. package/build/components/block-alignment-control/ui.cjs +5 -3
  8. package/build/components/block-alignment-control/ui.cjs.map +2 -2
  9. package/build/components/block-inspector/index.cjs +73 -46
  10. package/build/components/block-inspector/index.cjs.map +2 -2
  11. package/build/components/block-list/block-html.cjs +4 -1
  12. package/build/components/block-list/block-html.cjs.map +2 -2
  13. package/build/components/block-list/use-block-props/index.cjs +5 -2
  14. package/build/components/block-list/use-block-props/index.cjs.map +2 -2
  15. package/build/components/block-list/use-block-props/use-focus-handler.cjs +2 -3
  16. package/build/components/block-list/use-block-props/use-focus-handler.cjs.map +2 -2
  17. package/build/components/block-list/use-block-props/use-register-block-event-handlers.cjs +48 -0
  18. package/build/components/block-list/use-block-props/use-register-block-event-handlers.cjs.map +7 -0
  19. package/build/components/block-parent-selector/index.cjs +2 -2
  20. package/build/components/block-parent-selector/index.cjs.map +2 -2
  21. package/build/components/block-toolbar/switch-section-style.cjs +4 -2
  22. package/build/components/block-toolbar/switch-section-style.cjs.map +3 -3
  23. package/build/components/block-tools/empty-block-inserter.cjs +2 -7
  24. package/build/components/block-tools/empty-block-inserter.cjs.map +2 -2
  25. package/build/components/block-vertical-alignment-control/ui.cjs +3 -5
  26. package/build/components/block-vertical-alignment-control/ui.cjs.map +2 -2
  27. package/build/components/border-radius-control/utils.cjs +8 -58
  28. package/build/components/border-radius-control/utils.cjs.map +2 -2
  29. package/build/components/colors-gradients/control.cjs +5 -3
  30. package/build/components/colors-gradients/control.cjs.map +2 -2
  31. package/build/components/dimension-control/index.cjs +30 -20
  32. package/build/components/dimension-control/index.cjs.map +3 -3
  33. package/build/components/dimensions-tool/aspect-ratio-tool.cjs +9 -2
  34. package/build/components/dimensions-tool/aspect-ratio-tool.cjs.map +3 -3
  35. package/build/components/editor-styles/index.cjs +9 -1
  36. package/build/components/editor-styles/index.cjs.map +2 -2
  37. package/build/components/global-styles/background-panel.cjs +66 -25
  38. package/build/components/global-styles/background-panel.cjs.map +3 -3
  39. package/build/components/global-styles/border-panel.cjs +153 -55
  40. package/build/components/global-styles/border-panel.cjs.map +3 -3
  41. package/build/components/global-styles/color-gradient-dropdown-item.cjs +46 -14
  42. package/build/components/global-styles/color-gradient-dropdown-item.cjs.map +3 -3
  43. package/build/components/global-styles/color-panel.cjs +63 -17
  44. package/build/components/global-styles/color-panel.cjs.map +2 -2
  45. package/build/components/global-styles/dimensions-panel.cjs +242 -64
  46. package/build/components/global-styles/dimensions-panel.cjs.map +3 -3
  47. package/build/components/global-styles/filters-panel.cjs +59 -20
  48. package/build/components/global-styles/filters-panel.cjs.map +3 -3
  49. package/build/components/global-styles/hooks.cjs +4 -1
  50. package/build/components/global-styles/hooks.cjs.map +2 -2
  51. package/build/components/global-styles/inheritance/index.cjs +142 -0
  52. package/build/components/global-styles/inheritance/index.cjs.map +7 -0
  53. package/build/components/global-styles/inherited-value-context.cjs +173 -0
  54. package/build/components/global-styles/inherited-value-context.cjs.map +7 -0
  55. package/build/components/global-styles/shadow-panel-components.cjs +38 -20
  56. package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
  57. package/build/components/global-styles/state-control.cjs +1 -1
  58. package/build/components/global-styles/state-control.cjs.map +2 -2
  59. package/build/components/global-styles/typography-panel.cjs +271 -78
  60. package/build/components/global-styles/typography-panel.cjs.map +3 -3
  61. package/build/components/inspector-controls-tabs/styles-tab.cjs +10 -1
  62. package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
  63. package/build/components/line-height-control/index.cjs +1 -1
  64. package/build/components/line-height-control/index.cjs.map +2 -2
  65. package/build/components/link-control/index.cjs +3 -1
  66. package/build/components/link-control/index.cjs.map +2 -2
  67. package/build/components/preset-input-control/index.cjs +2 -1
  68. package/build/components/preset-input-control/index.cjs.map +2 -2
  69. package/build/components/provider/block-refs-provider.cjs +8 -2
  70. package/build/components/provider/block-refs-provider.cjs.map +2 -2
  71. package/build/components/provider/index.cjs +1 -1
  72. package/build/components/provider/index.cjs.map +2 -2
  73. package/build/components/provider/use-block-sync.cjs +18 -6
  74. package/build/components/provider/use-block-sync.cjs.map +2 -2
  75. package/build/components/provider/use-media-upload-settings.cjs +3 -1
  76. package/build/components/provider/use-media-upload-settings.cjs.map +2 -2
  77. package/build/components/rich-text/index.cjs +23 -13
  78. package/build/components/rich-text/index.cjs.map +2 -2
  79. package/build/components/spacing-sizes-control/utils.cjs +6 -19
  80. package/build/components/spacing-sizes-control/utils.cjs.map +2 -2
  81. package/build/components/text-indent-control/index.cjs +8 -2
  82. package/build/components/text-indent-control/index.cjs.map +2 -2
  83. package/build/components/url-input/index.cjs +303 -344
  84. package/build/components/url-input/index.cjs.map +3 -3
  85. package/build/components/writing-flow/index.cjs +2 -0
  86. package/build/components/writing-flow/index.cjs.map +3 -3
  87. package/build/components/writing-flow/use-arrow-nav.cjs +24 -1
  88. package/build/components/writing-flow/use-arrow-nav.cjs.map +2 -2
  89. package/build/components/writing-flow/use-click-selection.cjs +28 -2
  90. package/build/components/writing-flow/use-click-selection.cjs.map +2 -2
  91. package/build/components/writing-flow/use-editable-root-event-handlers.cjs +179 -0
  92. package/build/components/writing-flow/use-editable-root-event-handlers.cjs.map +7 -0
  93. package/build/components/writing-flow/use-editable-root.cjs +5 -42
  94. package/build/components/writing-flow/use-editable-root.cjs.map +2 -2
  95. package/build/components/writing-flow/use-home-end.cjs +1 -1
  96. package/build/components/writing-flow/use-home-end.cjs.map +2 -2
  97. package/build/components/writing-flow/use-selection-observer.cjs +17 -13
  98. package/build/components/writing-flow/use-selection-observer.cjs.map +2 -2
  99. package/build/components/writing-flow/utils.cjs +3 -14
  100. package/build/components/writing-flow/utils.cjs.map +2 -2
  101. package/build/hooks/background.cjs +13 -10
  102. package/build/hooks/background.cjs.map +2 -2
  103. package/build/hooks/block-style-variation.cjs +4 -45
  104. package/build/hooks/block-style-variation.cjs.map +3 -3
  105. package/build/hooks/border.cjs +19 -4
  106. package/build/hooks/border.cjs.map +2 -2
  107. package/build/hooks/custom-css.cjs +6 -2
  108. package/build/hooks/custom-css.cjs.map +2 -2
  109. package/build/hooks/dimensions.cjs +15 -4
  110. package/build/hooks/dimensions.cjs.map +2 -2
  111. package/build/hooks/duotone.cjs +26 -14
  112. package/build/hooks/duotone.cjs.map +3 -3
  113. package/build/hooks/elements.cjs +14 -4
  114. package/build/hooks/elements.cjs.map +2 -2
  115. package/build/hooks/line-height.cjs +1 -2
  116. package/build/hooks/line-height.cjs.map +2 -2
  117. package/build/hooks/typography.cjs +13 -4
  118. package/build/hooks/typography.cjs.map +2 -2
  119. package/build/private-apis.cjs +9 -5
  120. package/build/private-apis.cjs.map +3 -3
  121. package/build/store/actions.cjs +9 -4
  122. package/build/store/actions.cjs.map +2 -2
  123. package/build/store/private-selectors.cjs +28 -1
  124. package/build/store/private-selectors.cjs.map +2 -2
  125. package/build/store/reducer.cjs +6 -6
  126. package/build/store/reducer.cjs.map +2 -2
  127. package/build/store/selectors.cjs +23 -0
  128. package/build/store/selectors.cjs.map +2 -2
  129. package/build/utils/native-undo.cjs +55 -0
  130. package/build/utils/native-undo.cjs.map +7 -0
  131. package/build-module/components/alignment-control/ui.mjs +2 -4
  132. package/build-module/components/alignment-control/ui.mjs.map +2 -2
  133. package/build-module/components/background-image-control/index.mjs +43 -10
  134. package/build-module/components/background-image-control/index.mjs.map +2 -2
  135. package/build-module/components/block-alignment-control/ui.mjs +5 -3
  136. package/build-module/components/block-alignment-control/ui.mjs.map +2 -2
  137. package/build-module/components/block-inspector/index.mjs +74 -46
  138. package/build-module/components/block-inspector/index.mjs.map +2 -2
  139. package/build-module/components/block-list/block-html.mjs +4 -1
  140. package/build-module/components/block-list/block-html.mjs.map +2 -2
  141. package/build-module/components/block-list/use-block-props/index.mjs +5 -2
  142. package/build-module/components/block-list/use-block-props/index.mjs.map +2 -2
  143. package/build-module/components/block-list/use-block-props/use-focus-handler.mjs +2 -3
  144. package/build-module/components/block-list/use-block-props/use-focus-handler.mjs.map +2 -2
  145. package/build-module/components/block-list/use-block-props/use-register-block-event-handlers.mjs +28 -0
  146. package/build-module/components/block-list/use-block-props/use-register-block-event-handlers.mjs.map +7 -0
  147. package/build-module/components/block-parent-selector/index.mjs +2 -2
  148. package/build-module/components/block-parent-selector/index.mjs.map +2 -2
  149. package/build-module/components/block-toolbar/switch-section-style.mjs +4 -2
  150. package/build-module/components/block-toolbar/switch-section-style.mjs.map +2 -2
  151. package/build-module/components/block-tools/empty-block-inserter.mjs +2 -7
  152. package/build-module/components/block-tools/empty-block-inserter.mjs.map +2 -2
  153. package/build-module/components/block-vertical-alignment-control/ui.mjs +4 -6
  154. package/build-module/components/block-vertical-alignment-control/ui.mjs.map +2 -2
  155. package/build-module/components/border-radius-control/utils.mjs +11 -53
  156. package/build-module/components/border-radius-control/utils.mjs.map +2 -2
  157. package/build-module/components/colors-gradients/control.mjs +5 -3
  158. package/build-module/components/colors-gradients/control.mjs.map +2 -2
  159. package/build-module/components/dimension-control/index.mjs +30 -20
  160. package/build-module/components/dimension-control/index.mjs.map +2 -2
  161. package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs +10 -6
  162. package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs.map +2 -2
  163. package/build-module/components/editor-styles/index.mjs +9 -1
  164. package/build-module/components/editor-styles/index.mjs.map +2 -2
  165. package/build-module/components/global-styles/background-panel.mjs +71 -29
  166. package/build-module/components/global-styles/background-panel.mjs.map +2 -2
  167. package/build-module/components/global-styles/border-panel.mjs +157 -56
  168. package/build-module/components/global-styles/border-panel.mjs.map +2 -2
  169. package/build-module/components/global-styles/color-gradient-dropdown-item.mjs +51 -15
  170. package/build-module/components/global-styles/color-gradient-dropdown-item.mjs.map +2 -2
  171. package/build-module/components/global-styles/color-panel.mjs +63 -17
  172. package/build-module/components/global-styles/color-panel.mjs.map +2 -2
  173. package/build-module/components/global-styles/dimensions-panel.mjs +248 -66
  174. package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
  175. package/build-module/components/global-styles/filters-panel.mjs +64 -21
  176. package/build-module/components/global-styles/filters-panel.mjs.map +2 -2
  177. package/build-module/components/global-styles/hooks.mjs +4 -1
  178. package/build-module/components/global-styles/hooks.mjs.map +2 -2
  179. package/build-module/components/global-styles/inheritance/index.mjs +108 -0
  180. package/build-module/components/global-styles/inheritance/index.mjs.map +7 -0
  181. package/build-module/components/global-styles/inherited-value-context.mjs +141 -0
  182. package/build-module/components/global-styles/inherited-value-context.mjs.map +7 -0
  183. package/build-module/components/global-styles/shadow-panel-components.mjs +38 -20
  184. package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
  185. package/build-module/components/global-styles/state-control.mjs +1 -1
  186. package/build-module/components/global-styles/state-control.mjs.map +2 -2
  187. package/build-module/components/global-styles/typography-panel.mjs +276 -79
  188. package/build-module/components/global-styles/typography-panel.mjs.map +2 -2
  189. package/build-module/components/inspector-controls-tabs/styles-tab.mjs +6 -1
  190. package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
  191. package/build-module/components/line-height-control/index.mjs +1 -1
  192. package/build-module/components/line-height-control/index.mjs.map +2 -2
  193. package/build-module/components/link-control/index.mjs +4 -2
  194. package/build-module/components/link-control/index.mjs.map +2 -2
  195. package/build-module/components/preset-input-control/index.mjs +2 -1
  196. package/build-module/components/preset-input-control/index.mjs.map +2 -2
  197. package/build-module/components/provider/block-refs-provider.mjs +8 -2
  198. package/build-module/components/provider/block-refs-provider.mjs.map +2 -2
  199. package/build-module/components/provider/index.mjs +1 -1
  200. package/build-module/components/provider/index.mjs.map +2 -2
  201. package/build-module/components/provider/use-block-sync.mjs +18 -6
  202. package/build-module/components/provider/use-block-sync.mjs.map +2 -2
  203. package/build-module/components/provider/use-media-upload-settings.mjs +3 -1
  204. package/build-module/components/provider/use-media-upload-settings.mjs.map +2 -2
  205. package/build-module/components/rich-text/index.mjs +28 -14
  206. package/build-module/components/rich-text/index.mjs.map +2 -2
  207. package/build-module/components/spacing-sizes-control/utils.mjs +6 -18
  208. package/build-module/components/spacing-sizes-control/utils.mjs.map +2 -2
  209. package/build-module/components/text-indent-control/index.mjs +8 -2
  210. package/build-module/components/text-indent-control/index.mjs.map +2 -2
  211. package/build-module/components/url-input/index.mjs +306 -353
  212. package/build-module/components/url-input/index.mjs.map +2 -2
  213. package/build-module/components/writing-flow/index.mjs +2 -0
  214. package/build-module/components/writing-flow/index.mjs.map +2 -2
  215. package/build-module/components/writing-flow/use-arrow-nav.mjs +24 -1
  216. package/build-module/components/writing-flow/use-arrow-nav.mjs.map +2 -2
  217. package/build-module/components/writing-flow/use-click-selection.mjs +28 -2
  218. package/build-module/components/writing-flow/use-click-selection.mjs.map +2 -2
  219. package/build-module/components/writing-flow/use-editable-root-event-handlers.mjs +154 -0
  220. package/build-module/components/writing-flow/use-editable-root-event-handlers.mjs.map +7 -0
  221. package/build-module/components/writing-flow/use-editable-root.mjs +5 -37
  222. package/build-module/components/writing-flow/use-editable-root.mjs.map +2 -2
  223. package/build-module/components/writing-flow/use-home-end.mjs +1 -1
  224. package/build-module/components/writing-flow/use-home-end.mjs.map +2 -2
  225. package/build-module/components/writing-flow/use-selection-observer.mjs +18 -14
  226. package/build-module/components/writing-flow/use-selection-observer.mjs.map +2 -2
  227. package/build-module/components/writing-flow/utils.mjs +2 -11
  228. package/build-module/components/writing-flow/utils.mjs.map +2 -2
  229. package/build-module/hooks/background.mjs +13 -10
  230. package/build-module/hooks/background.mjs.map +2 -2
  231. package/build-module/hooks/block-style-variation.mjs +8 -44
  232. package/build-module/hooks/block-style-variation.mjs.map +2 -2
  233. package/build-module/hooks/border.mjs +19 -4
  234. package/build-module/hooks/border.mjs.map +2 -2
  235. package/build-module/hooks/custom-css.mjs +7 -3
  236. package/build-module/hooks/custom-css.mjs.map +2 -2
  237. package/build-module/hooks/dimensions.mjs +15 -4
  238. package/build-module/hooks/dimensions.mjs.map +2 -2
  239. package/build-module/hooks/duotone.mjs +20 -9
  240. package/build-module/hooks/duotone.mjs.map +2 -2
  241. package/build-module/hooks/elements.mjs +14 -4
  242. package/build-module/hooks/elements.mjs.map +2 -2
  243. package/build-module/hooks/line-height.mjs +1 -2
  244. package/build-module/hooks/line-height.mjs.map +2 -2
  245. package/build-module/hooks/typography.mjs +13 -4
  246. package/build-module/hooks/typography.mjs.map +2 -2
  247. package/build-module/private-apis.mjs +7 -3
  248. package/build-module/private-apis.mjs.map +2 -2
  249. package/build-module/store/actions.mjs +9 -4
  250. package/build-module/store/actions.mjs.map +2 -2
  251. package/build-module/store/private-selectors.mjs +29 -1
  252. package/build-module/store/private-selectors.mjs.map +2 -2
  253. package/build-module/store/reducer.mjs +6 -6
  254. package/build-module/store/reducer.mjs.map +2 -2
  255. package/build-module/store/selectors.mjs +23 -0
  256. package/build-module/store/selectors.mjs.map +2 -2
  257. package/build-module/utils/native-undo.mjs +29 -0
  258. package/build-module/utils/native-undo.mjs.map +7 -0
  259. package/build-style/content-rtl.css +10 -18
  260. package/build-style/content.css +10 -18
  261. package/build-style/style-rtl.css +150 -7
  262. package/build-style/style.css +150 -7
  263. package/package.json +40 -41
  264. package/src/components/alignment-control/test/__snapshots__/index.js.snap +1 -1
  265. package/src/components/alignment-control/ui.js +2 -4
  266. package/src/components/background-image-control/index.js +74 -37
  267. package/src/components/background-image-control/style.scss +13 -4
  268. package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +3 -3
  269. package/src/components/block-alignment-control/test/index.js +1 -1
  270. package/src/components/block-alignment-control/ui.js +4 -2
  271. package/src/components/block-breadcrumb/test/__snapshots__/index.js.snap +1 -1
  272. package/src/components/block-compare/test/__snapshots__/block-view.js.snap +1 -1
  273. package/src/components/block-icon/test/__snapshots__/index.js.snap +1 -1
  274. package/src/components/block-inspector/index.js +60 -31
  275. package/src/components/block-list/block-html.js +5 -0
  276. package/src/components/block-list/content.scss +1 -11
  277. package/src/components/block-list/use-block-props/index.js +5 -1
  278. package/src/components/block-list/use-block-props/use-focus-handler.js +9 -8
  279. package/src/components/block-list/use-block-props/use-register-block-event-handlers.js +45 -0
  280. package/src/components/block-parent-selector/index.js +5 -2
  281. package/src/components/block-toolbar/switch-section-style.js +5 -2
  282. package/src/components/block-tools/empty-block-inserter.js +3 -7
  283. package/src/components/block-vertical-alignment-control/test/__snapshots__/index.js.snap +3 -3
  284. package/src/components/block-vertical-alignment-control/test/index.js +18 -2
  285. package/src/components/block-vertical-alignment-control/ui.js +3 -5
  286. package/src/components/border-radius-control/test/utils.js +0 -41
  287. package/src/components/border-radius-control/utils.js +16 -107
  288. package/src/components/button-block-appender/content.scss +6 -2
  289. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
  290. package/src/components/colors-gradients/control.js +6 -3
  291. package/src/components/default-block-appender/test/__snapshots__/index.js.snap +1 -1
  292. package/src/components/dimension-control/index.js +13 -1
  293. package/src/components/dimensions-tool/aspect-ratio-tool.js +13 -6
  294. package/src/components/editor-styles/index.js +16 -1
  295. package/src/components/global-styles/background-panel.js +107 -34
  296. package/src/components/global-styles/border-panel.js +219 -48
  297. package/src/components/global-styles/color-gradient-dropdown-item.js +93 -28
  298. package/src/components/global-styles/color-panel.js +92 -11
  299. package/src/components/global-styles/dimensions-panel.js +422 -71
  300. package/src/components/global-styles/filters-panel.js +88 -28
  301. package/src/components/global-styles/hooks.js +8 -1
  302. package/src/components/global-styles/inheritance/index.js +204 -0
  303. package/src/components/global-styles/inheritance/style.scss +184 -0
  304. package/src/components/global-styles/inheritance/test/index.js +281 -0
  305. package/src/components/global-styles/inherited-value-context.js +271 -0
  306. package/src/components/global-styles/shadow-panel-components.js +48 -26
  307. package/src/components/global-styles/state-control.js +2 -2
  308. package/src/components/global-styles/test/background-panel.js +338 -1
  309. package/src/components/global-styles/test/border-panel.js +441 -0
  310. package/src/components/global-styles/test/color-panel.js +182 -2
  311. package/src/components/global-styles/test/dimensions-panel.js +753 -0
  312. package/src/components/global-styles/test/filters-panel.js +194 -0
  313. package/src/components/global-styles/test/inherited-value-context-core.js +98 -0
  314. package/src/components/global-styles/test/inherited-value-context.js +454 -0
  315. package/src/components/global-styles/test/typography-panel-core.js +185 -0
  316. package/src/components/global-styles/test/typography-panel.js +849 -12
  317. package/src/components/global-styles/typography-panel.js +449 -100
  318. package/src/components/image-editor/style.scss +33 -0
  319. package/src/components/inner-blocks/test/__snapshots__/index.js.snap +1 -1
  320. package/src/components/inspector-controls-tabs/styles-tab.js +5 -1
  321. package/src/components/line-height-control/index.js +1 -1
  322. package/src/components/link-control/index.js +7 -2
  323. package/src/components/preset-input-control/index.js +4 -1
  324. package/src/components/provider/block-refs-provider.js +12 -2
  325. package/src/components/provider/index.js +2 -2
  326. package/src/components/provider/use-block-sync.js +18 -6
  327. package/src/components/provider/use-media-upload-settings.js +2 -0
  328. package/src/components/rich-text/index.js +37 -16
  329. package/src/components/spacing-sizes-control/test/utils.js +16 -5
  330. package/src/components/spacing-sizes-control/utils.js +11 -28
  331. package/src/components/text-indent-control/index.js +8 -0
  332. package/src/components/url-input/index.js +363 -431
  333. package/src/components/url-input/test/index.js +592 -0
  334. package/src/components/warning/test/__snapshots__/index.js.snap +1 -1
  335. package/src/components/writing-flow/index.js +2 -0
  336. package/src/components/writing-flow/use-arrow-nav.js +51 -1
  337. package/src/components/writing-flow/use-click-selection.js +54 -3
  338. package/src/components/writing-flow/use-editable-root-event-handlers.js +266 -0
  339. package/src/components/writing-flow/use-editable-root.js +7 -77
  340. package/src/components/writing-flow/use-home-end.js +17 -9
  341. package/src/components/writing-flow/use-selection-observer.js +32 -15
  342. package/src/components/writing-flow/utils.js +3 -24
  343. package/src/hooks/background.js +26 -21
  344. package/src/hooks/block-fields/rich-text/styles.scss +1 -1
  345. package/src/hooks/block-style-variation.js +8 -74
  346. package/src/hooks/border.js +19 -4
  347. package/src/hooks/custom-css.js +15 -6
  348. package/src/hooks/dimensions.js +17 -4
  349. package/src/hooks/duotone.js +26 -8
  350. package/src/hooks/elements.js +14 -3
  351. package/src/hooks/line-height.js +0 -1
  352. package/src/hooks/test/inherited-value-wiring.js +411 -0
  353. package/src/hooks/test/preset-round-trip.js +456 -0
  354. package/src/hooks/typography.js +35 -23
  355. package/src/private-apis.js +11 -2
  356. package/src/store/actions.js +10 -4
  357. package/src/store/private-selectors.js +57 -1
  358. package/src/store/reducer.js +9 -9
  359. package/src/store/selectors.js +56 -8
  360. package/src/store/test/private-selectors.js +160 -1
  361. package/src/style.scss +2 -0
  362. package/src/utils/native-undo.js +56 -0
  363. package/build/components/duotone/utils.cjs +0 -87
  364. package/build/components/duotone/utils.cjs.map +0 -7
  365. package/build-module/components/duotone/utils.mjs +0 -59
  366. package/build-module/components/duotone/utils.mjs.map +0 -7
  367. package/src/components/duotone/utils.js +0 -90
  368. package/src/hooks/test/get-variation-styles-with-ref-values.js +0 -91
@@ -30,10 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // packages/block-editor/src/components/url-input/index.js
31
31
  var url_input_exports = {};
32
32
  __export(url_input_exports, {
33
- default: () => url_input_default
33
+ default: () => URLInput
34
34
  });
35
35
  module.exports = __toCommonJS(url_input_exports);
36
36
  var import_clsx = __toESM(require("clsx"));
37
+ var import_a11y = require("@wordpress/a11y");
37
38
  var import_i18n = require("@wordpress/i18n");
38
39
  var import_element = require("@wordpress/element");
39
40
  var import_keycodes = require("@wordpress/keycodes");
@@ -46,158 +47,162 @@ var import_lock_unlock = require("../../lock-unlock.cjs");
46
47
  var import_jsx_runtime = require("react/jsx-runtime");
47
48
  var import_react = require("react");
48
49
  var { ValidatedInputControl } = (0, import_lock_unlock.unlock)(import_components.privateApis);
50
+ var noop = () => {
51
+ };
49
52
  function isFunction(maybeFunc) {
50
53
  return typeof maybeFunc === "function";
51
54
  }
52
- var URLInput = class extends import_element.Component {
53
- constructor(props) {
54
- super(props);
55
- this.onChange = this.onChange.bind(this);
56
- this.onFocus = this.onFocus.bind(this);
57
- this.onKeyDown = this.onKeyDown.bind(this);
58
- this.selectLink = this.selectLink.bind(this);
59
- this.handleOnClick = this.handleOnClick.bind(this);
60
- this.bindSuggestionNode = this.bindSuggestionNode.bind(this);
61
- this.autocompleteRef = props.autocompleteRef || (0, import_element.createRef)();
62
- this.inputRef = props.inputRef || (0, import_element.createRef)();
63
- this.hasRenderedValidation = { current: false };
64
- this.updateSuggestions = (0, import_compose.debounce)(
65
- this.updateSuggestions.bind(this),
66
- 200
67
- );
68
- this.suggestionNodes = [];
69
- this.suggestionsRequest = null;
70
- this.state = {
71
- suggestions: [],
72
- showSuggestions: false,
73
- suggestionsValue: null,
74
- selectedSuggestion: null,
75
- suggestionsListboxId: "",
76
- suggestionOptionIdPrefix: ""
77
- };
78
- }
79
- componentDidUpdate(prevProps) {
80
- const { showSuggestions, selectedSuggestion } = this.state;
81
- const { value, __experimentalShowInitialSuggestions = false } = this.props;
82
- if (showSuggestions && selectedSuggestion !== null && this.suggestionNodes[selectedSuggestion]) {
83
- this.suggestionNodes[selectedSuggestion].scrollIntoView({
84
- behavior: "instant",
85
- block: "nearest",
86
- inline: "nearest"
87
- });
88
- }
89
- if (prevProps.value !== value && !this.props.disableSuggestions) {
90
- if (value?.length) {
91
- this.updateSuggestions(value);
92
- } else if (__experimentalShowInitialSuggestions) {
93
- this.updateSuggestions();
94
- }
95
- }
96
- }
97
- componentDidMount() {
98
- if (this.shouldShowInitialSuggestions()) {
99
- this.updateSuggestions();
100
- }
101
- }
102
- componentWillUnmount() {
103
- this.suggestionsRequest?.cancel?.();
104
- this.suggestionsRequest = null;
105
- }
106
- bindSuggestionNode(index) {
107
- return (ref) => {
108
- this.suggestionNodes[index] = ref;
109
- };
110
- }
111
- shouldShowInitialSuggestions() {
112
- const { __experimentalShowInitialSuggestions = false, value } = this.props;
113
- return __experimentalShowInitialSuggestions && !(value && value.length);
114
- }
115
- updateSuggestions(value = "") {
116
- const {
117
- __experimentalFetchLinkSuggestions: fetchLinkSuggestions,
118
- __experimentalHandleURLSuggestions: handleURLSuggestions
119
- } = this.props;
55
+ function URLInput(props) {
56
+ const {
57
+ __experimentalFetchLinkSuggestions: fetchLinkSuggestionsProp,
58
+ __experimentalHandleURLSuggestions: handleURLSuggestions,
59
+ __experimentalRenderControl: renderControl,
60
+ __experimentalRenderSuggestions: renderSuggestions,
61
+ __experimentalShowInitialSuggestions: showInitialSuggestions = false,
62
+ autocompleteRef,
63
+ className,
64
+ customValidity,
65
+ disableSuggestions,
66
+ disabled = false,
67
+ help = null,
68
+ hideLabelFromVision = false,
69
+ inputRef,
70
+ isFullWidth,
71
+ label = null,
72
+ markWhenOptional,
73
+ onChange,
74
+ onKeyDown,
75
+ onSubmit,
76
+ placeholder = (0, import_i18n.__)("Paste URL or type to search"),
77
+ required = true,
78
+ suffix,
79
+ value = ""
80
+ } = props;
81
+ const instanceId = (0, import_compose.useInstanceId)(URLInput);
82
+ const { getSettings } = (0, import_data.useSelect)(import_store.store);
83
+ const debouncedSpeak = (0, import_compose.useDebounce)(import_a11y.speak, 500);
84
+ const [suggestions, setSuggestions] = (0, import_element.useState)([]);
85
+ const [suggestionsValue, setSuggestionsValue] = (0, import_element.useState)(null);
86
+ const [selectedSuggestion, setSelectedSuggestion] = (0, import_element.useState)(null);
87
+ const [isSuggestionsListOpen, setIsSuggestionsListOpen] = (0, import_element.useState)(false);
88
+ const [isLoading, setIsLoading] = (0, import_element.useState)(false);
89
+ const fallbackInputRef = (0, import_element.useRef)();
90
+ const suggestionNodesRef = (0, import_element.useRef)([]);
91
+ const suggestionsRequestRef = (0, import_element.useRef)(null);
92
+ const controlInputRef = inputRef ?? fallbackInputRef;
93
+ const inputId = `url-input-control-${instanceId}`;
94
+ const suggestionsListboxId = `block-editor-url-input-suggestions-${instanceId}`;
95
+ const suggestionOptionIdPrefix = `block-editor-url-input-suggestion-${instanceId}`;
96
+ const showSuggestions = isSuggestionsListOpen && disableSuggestions !== true && (showInitialSuggestions || !!value.length);
97
+ const updateSuggestions = (0, import_compose.useEvent)((searchValue = "") => {
98
+ const fetchLinkSuggestions = isFunction(fetchLinkSuggestionsProp) ? fetchLinkSuggestionsProp : getSettings().__experimentalFetchLinkSuggestions;
120
99
  if (!fetchLinkSuggestions) {
121
100
  return;
122
101
  }
123
- const isInitialSuggestions = !value?.length;
124
- value = value.trim();
125
- if (!isInitialSuggestions && (value.length < 2 || !handleURLSuggestions && (0, import_url.isURL)(value))) {
126
- this.suggestionsRequest?.cancel?.();
127
- this.suggestionsRequest = null;
128
- this.setState({
129
- suggestions: [],
130
- showSuggestions: false,
131
- suggestionsValue: value,
132
- selectedSuggestion: null,
133
- loading: false
134
- });
102
+ const isInitialSuggestions = !searchValue?.length;
103
+ const search = searchValue.trim();
104
+ if (!isInitialSuggestions && (search.length < 2 || !handleURLSuggestions && (0, import_url.isURL)(search))) {
105
+ suggestionsRequestRef.current?.cancel?.();
106
+ suggestionsRequestRef.current = null;
107
+ setSuggestions([]);
108
+ setIsSuggestionsListOpen(false);
109
+ setSuggestionsValue(search);
110
+ setSelectedSuggestion(null);
111
+ setIsLoading(false);
135
112
  return;
136
113
  }
137
- this.setState({
138
- selectedSuggestion: null,
139
- loading: true
140
- });
141
- const request = fetchLinkSuggestions(value, {
114
+ setSelectedSuggestion(null);
115
+ setIsLoading(true);
116
+ const request = fetchLinkSuggestions(search, {
142
117
  isInitialSuggestions
143
118
  });
144
- request.then((suggestions) => {
145
- if (this.suggestionsRequest !== request) {
119
+ suggestionsRequestRef.current = request;
120
+ request.then((nextSuggestions) => {
121
+ if (suggestionsRequestRef.current !== request) {
146
122
  return;
147
123
  }
148
- this.setState({
149
- suggestions,
150
- suggestionsValue: value,
151
- loading: false,
152
- showSuggestions: !!suggestions.length
153
- });
154
- if (!!suggestions.length) {
155
- this.props.debouncedSpeak(
124
+ setSuggestions(nextSuggestions);
125
+ setSuggestionsValue(search);
126
+ setIsLoading(false);
127
+ setIsSuggestionsListOpen(!!nextSuggestions.length);
128
+ if (nextSuggestions.length) {
129
+ debouncedSpeak(
156
130
  (0, import_i18n.sprintf)(
157
131
  /* translators: %d: number of results. */
158
132
  (0, import_i18n._n)(
159
133
  "%d result found, use up and down arrow keys to navigate.",
160
134
  "%d results found, use up and down arrow keys to navigate.",
161
- suggestions.length
135
+ nextSuggestions.length
162
136
  ),
163
- suggestions.length
137
+ nextSuggestions.length
164
138
  ),
165
139
  "assertive"
166
140
  );
167
141
  } else {
168
- this.props.debouncedSpeak(
169
- (0, import_i18n.__)("No results."),
170
- "assertive"
171
- );
142
+ debouncedSpeak((0, import_i18n.__)("No results."), "assertive");
172
143
  }
173
144
  }).catch(() => {
174
- if (this.suggestionsRequest !== request) {
145
+ if (suggestionsRequestRef.current !== request) {
175
146
  return;
176
147
  }
177
- this.setState({
178
- loading: false
179
- });
148
+ setIsLoading(false);
180
149
  }).finally(() => {
181
- if (this.suggestionsRequest === request) {
182
- this.suggestionsRequest = null;
150
+ if (suggestionsRequestRef.current === request) {
151
+ suggestionsRequestRef.current = null;
183
152
  }
184
153
  });
185
- this.suggestionsRequest = request;
154
+ });
155
+ const debouncedUpdateSuggestions = (0, import_compose.useDebounce)(updateSuggestions, 200);
156
+ (0, import_element.useEffect)(() => {
157
+ if (!disableSuggestions && (value.length || showInitialSuggestions)) {
158
+ debouncedUpdateSuggestions(value);
159
+ }
160
+ }, [
161
+ value,
162
+ disableSuggestions,
163
+ showInitialSuggestions,
164
+ debouncedUpdateSuggestions
165
+ ]);
166
+ (0, import_element.useEffect)(() => {
167
+ if (!showSuggestions) {
168
+ setIsSuggestionsListOpen(false);
169
+ }
170
+ }, [showSuggestions]);
171
+ (0, import_element.useEffect)(() => {
172
+ if (showSuggestions && selectedSuggestion !== null) {
173
+ suggestionNodesRef.current[selectedSuggestion]?.scrollIntoView({
174
+ behavior: "instant",
175
+ block: "nearest",
176
+ inline: "nearest"
177
+ });
178
+ }
179
+ }, [showSuggestions, selectedSuggestion]);
180
+ (0, import_element.useEffect)(() => {
181
+ return () => {
182
+ suggestionsRequestRef.current?.cancel?.();
183
+ suggestionsRequestRef.current = null;
184
+ };
185
+ }, []);
186
+ function selectLink(suggestion) {
187
+ onChange(suggestion.url, suggestion);
188
+ setSelectedSuggestion(null);
189
+ setIsSuggestionsListOpen(false);
190
+ }
191
+ function handleSuggestionClick(suggestion) {
192
+ selectLink(suggestion);
193
+ controlInputRef.current.focus();
186
194
  }
187
- onChange(newValue) {
188
- this.props.onChange(newValue);
195
+ function handleChange(newValue) {
196
+ onChange(newValue);
189
197
  }
190
- onFocus() {
191
- const { suggestions } = this.state;
192
- const { disableSuggestions, value } = this.props;
193
- if (value && !disableSuggestions && !(suggestions && suggestions.length) && this.suggestionsRequest === null) {
194
- this.updateSuggestions(value);
198
+ function handleFocus() {
199
+ if (value && !disableSuggestions && !suggestions.length && suggestionsRequestRef.current === null) {
200
+ debouncedUpdateSuggestions(value);
195
201
  }
196
202
  }
197
- onKeyDown(event) {
198
- this.props.onKeyDown?.(event);
199
- const { showSuggestions, selectedSuggestion, suggestions, loading } = this.state;
200
- if (!showSuggestions || !suggestions.length || loading) {
203
+ function handleKeyDown(event) {
204
+ onKeyDown?.(event);
205
+ if (!showSuggestions || !suggestions.length || isLoading) {
201
206
  switch (event.keyCode) {
202
207
  // When UP is pressed, if the caret is at the start of the text, move it to the 0
203
208
  // position.
@@ -211,273 +216,227 @@ var URLInput = class extends import_element.Component {
211
216
  // When DOWN is pressed, if the caret is not at the end of the text, move it to the
212
217
  // last position.
213
218
  case import_keycodes.DOWN: {
214
- if (this.props.value.length !== event.target.selectionStart) {
219
+ if (value.length !== event.target.selectionStart) {
215
220
  event.preventDefault();
216
221
  event.target.setSelectionRange(
217
- this.props.value.length,
218
- this.props.value.length
222
+ value.length,
223
+ value.length
219
224
  );
220
225
  }
221
226
  break;
222
227
  }
223
228
  // Submitting while loading should trigger onSubmit.
224
229
  case import_keycodes.ENTER: {
225
- if (this.props.onSubmit) {
230
+ if (onSubmit) {
226
231
  event.preventDefault();
227
- this.props.onSubmit(null, event);
232
+ onSubmit(null, event);
228
233
  }
229
234
  break;
230
235
  }
231
236
  }
232
237
  return;
233
238
  }
234
- const suggestion = this.state.suggestions[this.state.selectedSuggestion];
239
+ const suggestion = suggestions[selectedSuggestion];
235
240
  switch (event.keyCode) {
236
241
  case import_keycodes.UP: {
237
242
  event.preventDefault();
238
- const previousIndex = !selectedSuggestion ? suggestions.length - 1 : selectedSuggestion - 1;
239
- this.setState({
240
- selectedSuggestion: previousIndex
241
- });
243
+ setSelectedSuggestion(
244
+ !selectedSuggestion ? suggestions.length - 1 : selectedSuggestion - 1
245
+ );
242
246
  break;
243
247
  }
244
248
  case import_keycodes.DOWN: {
245
249
  event.preventDefault();
246
- const nextIndex = selectedSuggestion === null || selectedSuggestion === suggestions.length - 1 ? 0 : selectedSuggestion + 1;
247
- this.setState({
248
- selectedSuggestion: nextIndex
249
- });
250
+ setSelectedSuggestion(
251
+ selectedSuggestion === null || selectedSuggestion === suggestions.length - 1 ? 0 : selectedSuggestion + 1
252
+ );
250
253
  break;
251
254
  }
252
255
  case import_keycodes.TAB: {
253
- if (this.state.selectedSuggestion !== null) {
254
- this.selectLink(suggestion);
255
- this.props.speak((0, import_i18n.__)("Link selected."));
256
+ if (selectedSuggestion !== null) {
257
+ selectLink(suggestion);
258
+ (0, import_a11y.speak)((0, import_i18n.__)("Link selected."));
256
259
  }
257
260
  break;
258
261
  }
259
262
  case import_keycodes.ENTER: {
260
263
  event.preventDefault();
261
- if (this.state.selectedSuggestion !== null) {
262
- this.selectLink(suggestion);
263
- if (this.props.onSubmit) {
264
- this.props.onSubmit(suggestion, event);
264
+ if (selectedSuggestion !== null) {
265
+ selectLink(suggestion);
266
+ if (onSubmit) {
267
+ onSubmit(suggestion, event);
265
268
  }
266
- } else if (this.props.onSubmit) {
267
- this.props.onSubmit(null, event);
269
+ } else if (onSubmit) {
270
+ onSubmit(null, event);
268
271
  }
269
272
  break;
270
273
  }
271
274
  }
272
275
  }
273
- selectLink(suggestion) {
274
- this.props.onChange(suggestion.url, suggestion);
275
- this.setState({
276
- selectedSuggestion: null,
277
- showSuggestions: false
278
- });
279
- }
280
- handleOnClick(suggestion) {
281
- this.selectLink(suggestion);
282
- this.inputRef.current.focus();
283
- }
284
- static getDerivedStateFromProps({
276
+ const controlProps = {
277
+ id: inputId,
278
+ // Passes attribute to label for the for attribute
279
+ label,
280
+ className: (0, import_clsx.default)("block-editor-url-input", className, {
281
+ "is-full-width": isFullWidth
282
+ }),
283
+ hideLabelFromVision
284
+ };
285
+ const inputProps = {
286
+ id: inputId,
285
287
  value,
286
- instanceId,
287
- disableSuggestions,
288
- __experimentalShowInitialSuggestions = false
289
- }, { showSuggestions }) {
290
- let shouldShowSuggestions = showSuggestions;
291
- const hasValue = value && value.length;
292
- if (!__experimentalShowInitialSuggestions && !hasValue) {
293
- shouldShowSuggestions = false;
294
- }
295
- if (disableSuggestions === true) {
296
- shouldShowSuggestions = false;
297
- }
298
- return {
299
- showSuggestions: shouldShowSuggestions,
300
- suggestionsListboxId: `block-editor-url-input-suggestions-${instanceId}`,
301
- suggestionOptionIdPrefix: `block-editor-url-input-suggestion-${instanceId}`
302
- };
288
+ required,
289
+ type: "text",
290
+ name: inputId,
291
+ autoComplete: "off",
292
+ onChange: disabled ? noop : handleChange,
293
+ onFocus: disabled ? noop : handleFocus,
294
+ onKeyDown: disabled ? noop : handleKeyDown,
295
+ placeholder,
296
+ role: "combobox",
297
+ "aria-label": label ? void 0 : (0, import_i18n.__)("URL"),
298
+ // Ensure input always has an accessible label
299
+ "aria-expanded": showSuggestions,
300
+ "aria-autocomplete": "list",
301
+ "aria-owns": suggestionsListboxId,
302
+ "aria-activedescendant": selectedSuggestion !== null ? `${suggestionOptionIdPrefix}-${selectedSuggestion}` : void 0,
303
+ ref: controlInputRef,
304
+ disabled,
305
+ suffix,
306
+ help
307
+ };
308
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
309
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
310
+ Control,
311
+ {
312
+ controlProps,
313
+ inputProps,
314
+ isLoading,
315
+ customValidity,
316
+ markWhenOptional,
317
+ renderControl
318
+ }
319
+ ),
320
+ showSuggestions && suggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
321
+ Suggestions,
322
+ {
323
+ autocompleteRef,
324
+ className,
325
+ handleSuggestionClick,
326
+ isLoading,
327
+ renderSuggestions,
328
+ selectedSuggestion,
329
+ suggestionNodesRef,
330
+ suggestionOptionIdPrefix,
331
+ suggestions,
332
+ suggestionsListboxId,
333
+ suggestionsValue
334
+ }
335
+ )
336
+ ] });
337
+ }
338
+ function Control({
339
+ controlProps,
340
+ inputProps,
341
+ isLoading,
342
+ customValidity,
343
+ markWhenOptional,
344
+ renderControl
345
+ }) {
346
+ const [isValidated, setIsValidated] = (0, import_element.useState)(
347
+ customValidity !== void 0
348
+ );
349
+ if (customValidity !== void 0 && !isValidated) {
350
+ setIsValidated(true);
303
351
  }
304
- render() {
305
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
306
- this.renderControl(),
307
- this.renderSuggestions()
308
- ] });
352
+ if (renderControl) {
353
+ return renderControl(controlProps, inputProps, isLoading);
309
354
  }
310
- renderControl() {
311
- const {
312
- label = null,
313
- className,
314
- isFullWidth,
315
- instanceId,
316
- placeholder = (0, import_i18n.__)("Paste URL or type to search"),
317
- __experimentalRenderControl: renderControl,
318
- value = "",
319
- hideLabelFromVision = false,
320
- help = null,
321
- disabled = false,
322
- customValidity,
323
- markWhenOptional
324
- } = this.props;
325
- const {
326
- loading,
327
- showSuggestions,
328
- selectedSuggestion,
329
- suggestionsListboxId,
330
- suggestionOptionIdPrefix
331
- } = this.state;
332
- const inputId = `url-input-control-${instanceId}`;
333
- const controlProps = {
334
- id: inputId,
335
- // Passes attribute to label for the for attribute
336
- label,
337
- className: (0, import_clsx.default)("block-editor-url-input", className, {
338
- "is-full-width": isFullWidth
339
- }),
340
- hideLabelFromVision
341
- };
342
- const inputProps = {
343
- id: inputId,
344
- value,
345
- required: this.props.required ?? true,
346
- type: "text",
347
- name: inputId,
348
- autoComplete: "off",
349
- onChange: disabled ? () => {
350
- } : this.onChange,
351
- // Disable onChange when disabled
352
- onFocus: disabled ? () => {
353
- } : this.onFocus,
354
- // Disable onFocus when disabled
355
- placeholder,
356
- onKeyDown: disabled ? () => {
357
- } : this.onKeyDown,
358
- // Disable onKeyDown when disabled
359
- role: "combobox",
360
- "aria-label": label ? void 0 : (0, import_i18n.__)("URL"),
361
- // Ensure input always has an accessible label
362
- "aria-expanded": showSuggestions,
363
- "aria-autocomplete": "list",
364
- "aria-owns": suggestionsListboxId,
365
- "aria-activedescendant": selectedSuggestion !== null ? `${suggestionOptionIdPrefix}-${selectedSuggestion}` : void 0,
366
- ref: this.inputRef,
367
- disabled,
368
- suffix: this.props.suffix,
369
- help
370
- };
371
- const validationProps = {
372
- customValidity,
373
- // Suppress the "(Required)" indicator in the label.
374
- // The field is still required for validation, but the indicator
375
- // can be hidden when markWhenOptional is set to true.
376
- ...markWhenOptional !== void 0 && {
377
- markWhenOptional
355
+ const MaybeValidatedInputControl = isValidated ? ValidatedInputControl : import_components.__experimentalInputControl;
356
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.BaseControl, { ...controlProps, children: [
357
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
358
+ MaybeValidatedInputControl,
359
+ {
360
+ ...inputProps,
361
+ ...isValidated && {
362
+ customValidity,
363
+ // Suppress the "(Required)" indicator in the label.
364
+ // The field is still required for validation, but the indicator
365
+ // can be hidden when markWhenOptional is set to true.
366
+ ...markWhenOptional !== void 0 && {
367
+ markWhenOptional
368
+ }
369
+ }
378
370
  }
371
+ ),
372
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {})
373
+ ] });
374
+ }
375
+ function Suggestions({
376
+ autocompleteRef,
377
+ className,
378
+ handleSuggestionClick,
379
+ isLoading,
380
+ renderSuggestions,
381
+ selectedSuggestion,
382
+ suggestionNodesRef,
383
+ suggestionOptionIdPrefix,
384
+ suggestions,
385
+ suggestionsListboxId,
386
+ suggestionsValue
387
+ }) {
388
+ const suggestionsListProps = {
389
+ id: suggestionsListboxId,
390
+ ref: autocompleteRef,
391
+ role: "listbox"
392
+ };
393
+ const buildSuggestionItemProps = (suggestion, index) => {
394
+ return {
395
+ role: "option",
396
+ tabIndex: "-1",
397
+ id: `${suggestionOptionIdPrefix}-${index}`,
398
+ ref: (node) => {
399
+ suggestionNodesRef.current[index] = node;
400
+ },
401
+ "aria-selected": index === selectedSuggestion ? true : void 0
379
402
  };
380
- if (renderControl) {
381
- return renderControl(controlProps, inputProps, loading);
382
- }
383
- if (customValidity !== void 0) {
384
- this.hasRenderedValidation.current = true;
385
- }
386
- const MaybeValidatedInputControl = this.hasRenderedValidation.current ? ValidatedInputControl : import_components.__experimentalInputControl;
387
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.BaseControl, { ...controlProps, children: [
388
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
389
- MaybeValidatedInputControl,
390
- {
391
- ...inputProps,
392
- ...this.hasRenderedValidation.current ? validationProps : {},
393
- __next40pxDefaultSize: true
394
- }
395
- ),
396
- loading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {})
397
- ] });
398
- }
399
- renderSuggestions() {
400
- const {
401
- className,
402
- __experimentalRenderSuggestions: renderSuggestions
403
- } = this.props;
404
- const {
405
- showSuggestions,
403
+ };
404
+ if (isFunction(renderSuggestions)) {
405
+ return renderSuggestions({
406
406
  suggestions,
407
- suggestionsValue,
408
407
  selectedSuggestion,
409
- suggestionsListboxId,
410
- suggestionOptionIdPrefix,
411
- loading
412
- } = this.state;
413
- if (!showSuggestions || suggestions.length === 0) {
414
- return null;
415
- }
416
- const suggestionsListProps = {
417
- id: suggestionsListboxId,
418
- ref: this.autocompleteRef,
419
- role: "listbox"
420
- };
421
- const buildSuggestionItemProps = (suggestion, index) => {
422
- return {
423
- role: "option",
424
- tabIndex: "-1",
425
- id: `${suggestionOptionIdPrefix}-${index}`,
426
- ref: this.bindSuggestionNode(index),
427
- "aria-selected": index === selectedSuggestion ? true : void 0
428
- };
429
- };
430
- if (isFunction(renderSuggestions)) {
431
- return renderSuggestions({
432
- suggestions,
433
- selectedSuggestion,
434
- suggestionsListProps,
435
- buildSuggestionItemProps,
436
- isLoading: loading,
437
- handleSuggestionClick: this.handleOnClick,
438
- isInitialSuggestions: !suggestionsValue?.length,
439
- currentInputValue: suggestionsValue
440
- });
441
- }
442
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Popover, { placement: "bottom", focusOnMount: false, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
443
- "div",
444
- {
445
- ...suggestionsListProps,
446
- className: (0, import_clsx.default)("block-editor-url-input__suggestions", {
447
- [`${className}__suggestions`]: className
448
- }),
449
- children: suggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_react.createElement)(
450
- import_components.Button,
451
- {
452
- __next40pxDefaultSize: true,
453
- ...buildSuggestionItemProps(suggestion, index),
454
- key: suggestion.id,
455
- className: (0, import_clsx.default)(
456
- "block-editor-url-input__suggestion",
457
- {
458
- "is-selected": index === selectedSuggestion
459
- }
460
- ),
461
- onClick: () => this.handleOnClick(suggestion)
462
- },
463
- suggestion.title
464
- ))
465
- }
466
- ) });
408
+ suggestionsListProps,
409
+ buildSuggestionItemProps,
410
+ isLoading,
411
+ handleSuggestionClick,
412
+ isInitialSuggestions: !suggestionsValue?.length,
413
+ currentInputValue: suggestionsValue
414
+ });
467
415
  }
468
- };
469
- var url_input_default = (0, import_compose.compose)(
470
- import_compose.withSafeTimeout,
471
- import_components.withSpokenMessages,
472
- import_compose.withInstanceId,
473
- (0, import_data.withSelect)((select, props) => {
474
- if (isFunction(props.__experimentalFetchLinkSuggestions)) {
475
- return;
416
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Popover, { placement: "bottom", focusOnMount: false, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
417
+ "div",
418
+ {
419
+ ...suggestionsListProps,
420
+ className: (0, import_clsx.default)("block-editor-url-input__suggestions", {
421
+ [`${className}__suggestions`]: className
422
+ }),
423
+ children: suggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_react.createElement)(
424
+ import_components.Button,
425
+ {
426
+ __next40pxDefaultSize: true,
427
+ ...buildSuggestionItemProps(suggestion, index),
428
+ key: suggestion.id,
429
+ className: (0, import_clsx.default)(
430
+ "block-editor-url-input__suggestion",
431
+ {
432
+ "is-selected": index === selectedSuggestion
433
+ }
434
+ ),
435
+ onClick: () => handleSuggestionClick(suggestion)
436
+ },
437
+ suggestion.title
438
+ ))
476
439
  }
477
- const { getSettings } = select(import_store.store);
478
- return {
479
- __experimentalFetchLinkSuggestions: getSettings().__experimentalFetchLinkSuggestions
480
- };
481
- })
482
- )(URLInput);
440
+ ) });
441
+ }
483
442
  //# sourceMappingURL=index.cjs.map