@wordpress/block-editor 16.0.0 → 16.1.0

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