@wordpress/components 29.13.1-next.719a03cbe.0 → 30.1.1-next.46f643fa0.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 (280) hide show
  1. package/CHANGELOG.md +34 -3
  2. package/build/autocomplete/index.js +4 -0
  3. package/build/autocomplete/index.js.map +1 -1
  4. package/build/calendar/date-calendar/index.js +13 -4
  5. package/build/calendar/date-calendar/index.js.map +1 -1
  6. package/build/calendar/date-range-calendar/index.js +8 -4
  7. package/build/calendar/date-range-calendar/index.js.map +1 -1
  8. package/build/calendar/types.js.map +1 -1
  9. package/build/color-picker/styles.js +7 -7
  10. package/build/color-picker/styles.js.map +1 -1
  11. package/build/icon/index.js +2 -0
  12. package/build/icon/index.js.map +1 -1
  13. package/build/index.js +0 -19
  14. package/build/index.js.map +1 -1
  15. package/build/palette-edit/index.js +1 -1
  16. package/build/palette-edit/index.js.map +1 -1
  17. package/build/private-apis.js +9 -1
  18. package/build/private-apis.js.map +1 -1
  19. package/build/range-control/index.js +1 -1
  20. package/build/range-control/index.js.map +1 -1
  21. package/build/range-control/styles/range-control-styles.js +35 -35
  22. package/build/range-control/styles/range-control-styles.js.map +1 -1
  23. package/build/range-control/tooltip.js +15 -15
  24. package/build/range-control/tooltip.js.map +1 -1
  25. package/build/range-control/types.js.map +1 -1
  26. package/build/select-control/index.js +1 -1
  27. package/build/select-control/index.js.map +1 -1
  28. package/build/textarea-control/index.js +7 -1
  29. package/build/textarea-control/index.js.map +1 -1
  30. package/build/toggle-group-control/toggle-group-control/as-button-group.js.map +1 -1
  31. package/build/utils/hooks/use-controlled-value.js +8 -4
  32. package/build/utils/hooks/use-controlled-value.js.map +1 -1
  33. package/build/validated-form-controls/components/checkbox-control.js +52 -0
  34. package/build/validated-form-controls/components/checkbox-control.js.map +1 -0
  35. package/build/validated-form-controls/components/combobox-control.js +64 -0
  36. package/build/validated-form-controls/components/combobox-control.js.map +1 -0
  37. package/build/validated-form-controls/components/custom-select-control.js +71 -0
  38. package/build/validated-form-controls/components/custom-select-control.js.map +1 -0
  39. package/build/validated-form-controls/components/index.js +138 -0
  40. package/build/validated-form-controls/components/index.js.map +1 -0
  41. package/build/validated-form-controls/components/input-control.js +50 -0
  42. package/build/validated-form-controls/components/input-control.js.map +1 -0
  43. package/build/validated-form-controls/components/number-control.js +53 -0
  44. package/build/validated-form-controls/components/number-control.js.map +1 -0
  45. package/build/validated-form-controls/components/radio-control.js +51 -0
  46. package/build/validated-form-controls/components/radio-control.js.map +1 -0
  47. package/build/validated-form-controls/components/range-control.js +51 -0
  48. package/build/validated-form-controls/components/range-control.js.map +1 -0
  49. package/build/validated-form-controls/components/select-control.js +53 -0
  50. package/build/validated-form-controls/components/select-control.js.map +1 -0
  51. package/build/validated-form-controls/components/text-control.js +51 -0
  52. package/build/validated-form-controls/components/text-control.js.map +1 -0
  53. package/build/validated-form-controls/components/textarea-control.js +50 -0
  54. package/build/validated-form-controls/components/textarea-control.js.map +1 -0
  55. package/build/validated-form-controls/components/toggle-control.js +60 -0
  56. package/build/validated-form-controls/components/toggle-control.js.map +1 -0
  57. package/build/validated-form-controls/components/toggle-group-control.js +69 -0
  58. package/build/validated-form-controls/components/toggle-group-control.js.map +1 -0
  59. package/build/validated-form-controls/components/types.js +6 -0
  60. package/build/validated-form-controls/components/types.js.map +1 -0
  61. package/build/validated-form-controls/control-with-error.js +137 -0
  62. package/build/validated-form-controls/control-with-error.js.map +1 -0
  63. package/build/validated-form-controls/index.js +28 -0
  64. package/build/validated-form-controls/index.js.map +1 -0
  65. package/build-module/autocomplete/index.js +4 -0
  66. package/build-module/autocomplete/index.js.map +1 -1
  67. package/build-module/calendar/date-calendar/index.js +11 -3
  68. package/build-module/calendar/date-calendar/index.js.map +1 -1
  69. package/build-module/calendar/date-range-calendar/index.js +8 -4
  70. package/build-module/calendar/date-range-calendar/index.js.map +1 -1
  71. package/build-module/calendar/types.js.map +1 -1
  72. package/build-module/color-picker/styles.js +7 -7
  73. package/build-module/color-picker/styles.js.map +1 -1
  74. package/build-module/icon/index.js +2 -0
  75. package/build-module/icon/index.js.map +1 -1
  76. package/build-module/index.js +0 -1
  77. package/build-module/index.js.map +1 -1
  78. package/build-module/palette-edit/index.js +2 -2
  79. package/build-module/palette-edit/index.js.map +1 -1
  80. package/build-module/private-apis.js +9 -1
  81. package/build-module/private-apis.js.map +1 -1
  82. package/build-module/range-control/index.js +1 -1
  83. package/build-module/range-control/index.js.map +1 -1
  84. package/build-module/range-control/styles/range-control-styles.js +35 -35
  85. package/build-module/range-control/styles/range-control-styles.js.map +1 -1
  86. package/build-module/range-control/tooltip.js +15 -15
  87. package/build-module/range-control/tooltip.js.map +1 -1
  88. package/build-module/range-control/types.js.map +1 -1
  89. package/build-module/select-control/index.js +1 -1
  90. package/build-module/select-control/index.js.map +1 -1
  91. package/build-module/textarea-control/index.js +7 -1
  92. package/build-module/textarea-control/index.js.map +1 -1
  93. package/build-module/toggle-group-control/toggle-group-control/as-button-group.js.map +1 -1
  94. package/build-module/utils/hooks/use-controlled-value.js +9 -5
  95. package/build-module/utils/hooks/use-controlled-value.js.map +1 -1
  96. package/build-module/validated-form-controls/components/checkbox-control.js +44 -0
  97. package/build-module/validated-form-controls/components/checkbox-control.js.map +1 -0
  98. package/build-module/validated-form-controls/components/combobox-control.js +56 -0
  99. package/build-module/validated-form-controls/components/combobox-control.js.map +1 -0
  100. package/build-module/validated-form-controls/components/custom-select-control.js +63 -0
  101. package/build-module/validated-form-controls/components/custom-select-control.js.map +1 -0
  102. package/build-module/validated-form-controls/components/index.js +13 -0
  103. package/build-module/validated-form-controls/components/index.js.map +1 -0
  104. package/build-module/validated-form-controls/components/input-control.js +42 -0
  105. package/build-module/validated-form-controls/components/input-control.js.map +1 -0
  106. package/build-module/validated-form-controls/components/number-control.js +45 -0
  107. package/build-module/validated-form-controls/components/number-control.js.map +1 -0
  108. package/build-module/validated-form-controls/components/radio-control.js +43 -0
  109. package/build-module/validated-form-controls/components/radio-control.js.map +1 -0
  110. package/build-module/validated-form-controls/components/range-control.js +43 -0
  111. package/build-module/validated-form-controls/components/range-control.js.map +1 -0
  112. package/build-module/validated-form-controls/components/select-control.js +45 -0
  113. package/build-module/validated-form-controls/components/select-control.js.map +1 -0
  114. package/build-module/validated-form-controls/components/text-control.js +43 -0
  115. package/build-module/validated-form-controls/components/text-control.js.map +1 -0
  116. package/build-module/validated-form-controls/components/textarea-control.js +42 -0
  117. package/build-module/validated-form-controls/components/textarea-control.js.map +1 -0
  118. package/build-module/validated-form-controls/components/toggle-control.js +52 -0
  119. package/build-module/validated-form-controls/components/toggle-control.js.map +1 -0
  120. package/build-module/validated-form-controls/components/toggle-group-control.js +62 -0
  121. package/build-module/validated-form-controls/components/toggle-group-control.js.map +1 -0
  122. package/build-module/validated-form-controls/components/types.js +2 -0
  123. package/build-module/validated-form-controls/components/types.js.map +1 -0
  124. package/build-module/validated-form-controls/control-with-error.js +129 -0
  125. package/build-module/validated-form-controls/control-with-error.js.map +1 -0
  126. package/build-module/validated-form-controls/index.js +3 -0
  127. package/build-module/validated-form-controls/index.js.map +1 -0
  128. package/build-style/style-rtl.css +79 -67
  129. package/build-style/style.css +79 -67
  130. package/build-types/autocomplete/index.d.ts.map +1 -1
  131. package/build-types/box-control/utils.d.ts +7 -7
  132. package/build-types/calendar/date-calendar/index.d.ts.map +1 -1
  133. package/build-types/calendar/date-range-calendar/index.d.ts.map +1 -1
  134. package/build-types/calendar/types.d.ts +2 -2
  135. package/build-types/calendar/types.d.ts.map +1 -1
  136. package/build-types/calendar/utils/use-localization-props.d.ts +3 -3
  137. package/build-types/color-picker/styles.d.ts.map +1 -1
  138. package/build-types/custom-gradient-picker/constants.d.ts +2 -2
  139. package/build-types/dimension-control/sizes.d.ts +5 -5
  140. package/build-types/font-size-picker/constants.d.ts +2 -2
  141. package/build-types/font-size-picker/constants.d.ts.map +1 -1
  142. package/build-types/icon/index.d.ts.map +1 -1
  143. package/build-types/index.d.ts +0 -1
  144. package/build-types/index.d.ts.map +1 -1
  145. package/build-types/private-apis.d.ts.map +1 -1
  146. package/build-types/range-control/types.d.ts +2 -2
  147. package/build-types/range-control/types.d.ts.map +1 -1
  148. package/build-types/select-control/stories/index.story.d.ts.map +1 -1
  149. package/build-types/text-control/stories/index.story.d.ts.map +1 -1
  150. package/build-types/textarea-control/index.d.ts.map +1 -1
  151. package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts.map +1 -1
  152. package/build-types/utils/hooks/use-controlled-value.d.ts +2 -2
  153. package/build-types/utils/hooks/use-controlled-value.d.ts.map +1 -1
  154. package/build-types/validated-form-controls/components/checkbox-control.d.ts +9 -0
  155. package/build-types/validated-form-controls/components/checkbox-control.d.ts.map +1 -0
  156. package/build-types/validated-form-controls/components/combobox-control.d.ts +21 -0
  157. package/build-types/validated-form-controls/components/combobox-control.d.ts.map +1 -0
  158. package/build-types/validated-form-controls/components/custom-select-control.d.ts +4 -0
  159. package/build-types/validated-form-controls/components/custom-select-control.d.ts.map +1 -0
  160. package/build-types/validated-form-controls/components/index.d.ts +13 -0
  161. package/build-types/validated-form-controls/components/index.d.ts.map +1 -0
  162. package/build-types/validated-form-controls/components/input-control.d.ts +4 -0
  163. package/build-types/validated-form-controls/components/input-control.d.ts.map +1 -0
  164. package/build-types/validated-form-controls/components/number-control.d.ts +17 -0
  165. package/build-types/validated-form-controls/components/number-control.d.ts.map +1 -0
  166. package/build-types/validated-form-controls/components/radio-control.d.ts +11 -0
  167. package/build-types/validated-form-controls/components/radio-control.d.ts.map +1 -0
  168. package/build-types/validated-form-controls/components/range-control.d.ts +36 -0
  169. package/build-types/validated-form-controls/components/range-control.d.ts.map +1 -0
  170. package/build-types/validated-form-controls/components/select-control.d.ts +9 -0
  171. package/build-types/validated-form-controls/components/select-control.d.ts.map +1 -0
  172. package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts +12 -0
  173. package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts.map +1 -0
  174. package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts +12 -0
  175. package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts.map +1 -0
  176. package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts +12 -0
  177. package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts.map +1 -0
  178. package/build-types/validated-form-controls/components/stories/input-control.story.d.ts +18 -0
  179. package/build-types/validated-form-controls/components/stories/input-control.story.d.ts.map +1 -0
  180. package/build-types/validated-form-controls/components/stories/number-control.story.d.ts +12 -0
  181. package/build-types/validated-form-controls/components/stories/number-control.story.d.ts.map +1 -0
  182. package/build-types/validated-form-controls/components/stories/overview.story.d.ts +19 -0
  183. package/build-types/validated-form-controls/components/stories/overview.story.d.ts.map +1 -0
  184. package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts +12 -0
  185. package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts.map +1 -0
  186. package/build-types/validated-form-controls/components/stories/range-control.story.d.ts +9 -0
  187. package/build-types/validated-form-controls/components/stories/range-control.story.d.ts.map +1 -0
  188. package/build-types/validated-form-controls/components/stories/select-control.story.d.ts +12 -0
  189. package/build-types/validated-form-controls/components/stories/select-control.story.d.ts.map +1 -0
  190. package/build-types/validated-form-controls/components/stories/story-utils.d.ts +9 -0
  191. package/build-types/validated-form-controls/components/stories/story-utils.d.ts.map +1 -0
  192. package/build-types/validated-form-controls/components/stories/text-control.story.d.ts +9 -0
  193. package/build-types/validated-form-controls/components/stories/text-control.story.d.ts.map +1 -0
  194. package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts +9 -0
  195. package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts.map +1 -0
  196. package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts +9 -0
  197. package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts.map +1 -0
  198. package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts +9 -0
  199. package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts.map +1 -0
  200. package/build-types/validated-form-controls/components/text-control.d.ts +8 -0
  201. package/build-types/validated-form-controls/components/text-control.d.ts.map +1 -0
  202. package/build-types/validated-form-controls/components/textarea-control.d.ts +7 -0
  203. package/build-types/validated-form-controls/components/textarea-control.d.ts.map +1 -0
  204. package/build-types/validated-form-controls/components/toggle-control.d.ts +7 -0
  205. package/build-types/validated-form-controls/components/toggle-control.d.ts.map +1 -0
  206. package/build-types/validated-form-controls/components/toggle-group-control.d.ts +15 -0
  207. package/build-types/validated-form-controls/components/toggle-group-control.d.ts.map +1 -0
  208. package/build-types/validated-form-controls/components/types.d.ts +27 -0
  209. package/build-types/validated-form-controls/components/types.d.ts.map +1 -0
  210. package/build-types/validated-form-controls/control-with-error.d.ts +36 -0
  211. package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -0
  212. package/build-types/validated-form-controls/index.d.ts +3 -0
  213. package/build-types/validated-form-controls/index.d.ts.map +1 -0
  214. package/package.json +19 -19
  215. package/src/autocomplete/index.tsx +4 -0
  216. package/src/calendar/date-calendar/README.md +57 -46
  217. package/src/calendar/date-calendar/index.tsx +22 -8
  218. package/src/calendar/date-range-calendar/README.md +63 -52
  219. package/src/calendar/date-range-calendar/index.tsx +23 -11
  220. package/src/calendar/types.ts +2 -2
  221. package/src/color-picker/styles.ts +10 -0
  222. package/src/dimension-control/test/__snapshots__/index.test.js.snap +8 -8
  223. package/src/icon/index.tsx +2 -0
  224. package/src/index.ts +0 -1
  225. package/src/modal/style.scss +2 -2
  226. package/src/palette-edit/index.tsx +3 -3
  227. package/src/private-apis.ts +13 -0
  228. package/src/range-control/index.tsx +1 -1
  229. package/src/range-control/styles/range-control-styles.ts +3 -3
  230. package/src/range-control/tooltip.tsx +13 -13
  231. package/src/range-control/types.ts +2 -2
  232. package/src/select-control/index.tsx +1 -1
  233. package/src/style.scss +2 -2
  234. package/src/text-control/stories/index.story.tsx +1 -0
  235. package/src/text-control/style.scss +6 -1
  236. package/src/textarea-control/index.tsx +8 -1
  237. package/src/toggle-group-control/toggle-group-control/as-button-group.tsx +3 -1
  238. package/src/utils/hooks/use-controlled-value.ts +16 -8
  239. package/src/utils/theme-variables.scss +3 -0
  240. package/src/validated-form-controls/components/checkbox-control.tsx +64 -0
  241. package/src/validated-form-controls/components/combobox-control.tsx +77 -0
  242. package/src/validated-form-controls/components/custom-select-control.tsx +86 -0
  243. package/src/validated-form-controls/components/index.ts +12 -0
  244. package/src/validated-form-controls/components/input-control.tsx +59 -0
  245. package/src/validated-form-controls/components/number-control.tsx +61 -0
  246. package/src/validated-form-controls/components/radio-control.tsx +60 -0
  247. package/src/validated-form-controls/components/range-control.tsx +60 -0
  248. package/src/validated-form-controls/components/select-control.tsx +75 -0
  249. package/src/validated-form-controls/components/stories/checkbox-control.story.tsx +57 -0
  250. package/src/validated-form-controls/components/stories/combobox-control.story.tsx +64 -0
  251. package/src/validated-form-controls/components/stories/custom-select-control.story.tsx +64 -0
  252. package/src/validated-form-controls/components/stories/input-control.story.tsx +132 -0
  253. package/src/validated-form-controls/components/stories/number-control.story.tsx +62 -0
  254. package/src/validated-form-controls/components/stories/overview.mdx +52 -0
  255. package/src/validated-form-controls/components/stories/overview.story.tsx +100 -0
  256. package/src/validated-form-controls/components/stories/radio-control.story.tsx +64 -0
  257. package/src/validated-form-controls/components/stories/range-control.story.tsx +60 -0
  258. package/src/validated-form-controls/components/stories/select-control.story.tsx +60 -0
  259. package/src/validated-form-controls/components/stories/story-utils.tsx +46 -0
  260. package/src/validated-form-controls/components/stories/text-control.story.tsx +55 -0
  261. package/src/validated-form-controls/components/stories/textarea-control.story.tsx +52 -0
  262. package/src/validated-form-controls/components/stories/toggle-control.story.tsx +55 -0
  263. package/src/validated-form-controls/components/stories/toggle-group-control.story.tsx +66 -0
  264. package/src/validated-form-controls/components/text-control.tsx +60 -0
  265. package/src/validated-form-controls/components/textarea-control.tsx +59 -0
  266. package/src/validated-form-controls/components/toggle-control.tsx +69 -0
  267. package/src/validated-form-controls/components/toggle-group-control.tsx +82 -0
  268. package/src/validated-form-controls/components/types.ts +28 -0
  269. package/src/validated-form-controls/control-with-error.tsx +198 -0
  270. package/src/validated-form-controls/index.ts +2 -0
  271. package/src/validated-form-controls/style.scss +75 -0
  272. package/tsconfig.tsbuildinfo +1 -1
  273. package/build/calendar/utils/use-controlled-value.js +0 -58
  274. package/build/calendar/utils/use-controlled-value.js.map +0 -1
  275. package/build-module/calendar/utils/use-controlled-value.js +0 -51
  276. package/build-module/calendar/utils/use-controlled-value.js.map +0 -1
  277. package/build-types/calendar/utils/use-controlled-value.d.ts +0 -27
  278. package/build-types/calendar/utils/use-controlled-value.d.ts.map +0 -1
  279. package/src/calendar/utils/use-controlled-value.ts +0 -61
  280. package/src/dimension-control/style.scss +0 -22
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ValidatedTextareaControl = void 0;
8
+ var _element = require("@wordpress/element");
9
+ var _compose = require("@wordpress/compose");
10
+ var _controlWithError = require("../control-with-error");
11
+ var _textareaControl = _interopRequireDefault(require("../../textarea-control"));
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ /**
14
+ * WordPress dependencies
15
+ */
16
+
17
+ /**
18
+ * Internal dependencies
19
+ */
20
+
21
+ const UnforwardedValidatedTextareaControl = ({
22
+ required,
23
+ customValidator,
24
+ onChange,
25
+ markWhenOptional,
26
+ ...restProps
27
+ }, forwardedRef) => {
28
+ const validityTargetRef = (0, _element.useRef)(null);
29
+ const mergedRefs = (0, _compose.useMergeRefs)([forwardedRef, validityTargetRef]);
30
+ const valueRef = (0, _element.useRef)(restProps.value);
31
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_controlWithError.ControlWithError, {
32
+ required: required,
33
+ markWhenOptional: markWhenOptional,
34
+ customValidator: () => {
35
+ return customValidator?.(valueRef.current);
36
+ },
37
+ getValidityTarget: () => validityTargetRef.current,
38
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_textareaControl.default, {
39
+ __nextHasNoMarginBottom: true,
40
+ ref: mergedRefs,
41
+ onChange: value => {
42
+ valueRef.current = value;
43
+ onChange?.(value);
44
+ },
45
+ ...restProps
46
+ })
47
+ });
48
+ };
49
+ const ValidatedTextareaControl = exports.ValidatedTextareaControl = (0, _element.forwardRef)(UnforwardedValidatedTextareaControl);
50
+ //# sourceMappingURL=textarea-control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_element","require","_compose","_controlWithError","_textareaControl","_interopRequireDefault","_jsxRuntime","UnforwardedValidatedTextareaControl","required","customValidator","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","useRef","mergedRefs","useMergeRefs","valueRef","value","jsx","ControlWithError","current","getValidityTarget","children","default","__nextHasNoMarginBottom","ref","ValidatedTextareaControl","exports","forwardRef"],"sources":["@wordpress/components/src/validated-form-controls/components/textarea-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport TextareaControl from '../../textarea-control';\nimport type { TextareaControlProps } from '../../textarea-control/types';\n\ntype Value = TextareaControlProps[ 'value' ];\n\nconst UnforwardedValidatedTextareaControl = (\n\t{\n\t\trequired,\n\t\tcustomValidator,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof TextareaControl >,\n\t\t'__nextHasNoMarginBottom'\n\t> &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLTextAreaElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLTextAreaElement >( null );\n\tconst mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );\n\tconst valueRef = useRef< Value >( restProps.value );\n\n\treturn (\n\t\t<ControlWithError\n\t\t\trequired={ required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tcustomValidator={ () => {\n\t\t\t\treturn customValidator?.( valueRef.current );\n\t\t\t} }\n\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t>\n\t\t\t<TextareaControl\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tref={ mergedRefs }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\tonChange?.( value );\n\t\t\t\t} }\n\t\t\t\t{ ...restProps }\n\t\t\t/>\n\t\t</ControlWithError>\n\t);\n};\n\nexport const ValidatedTextareaControl = forwardRef(\n\tUnforwardedValidatedTextareaControl\n);\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,iBAAA,GAAAF,OAAA;AAEA,IAAAG,gBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAAqD,IAAAK,WAAA,GAAAL,OAAA;AAXrD;AACA;AACA;;AAIA;AACA;AACA;;AAQA,MAAMM,mCAAmC,GAAGA,CAC3C;EACCC,QAAQ;EACRC,eAAe;EACfC,QAAQ;EACRC,gBAAgB;EAChB,GAAGC;AAK0B,CAAC,EAC/BC,YAAuD,KACnD;EACJ,MAAMC,iBAAiB,GAAG,IAAAC,eAAM,EAAyB,IAAK,CAAC;EAC/D,MAAMC,UAAU,GAAG,IAAAC,qBAAY,EAAE,CAAEJ,YAAY,EAAEC,iBAAiB,CAAG,CAAC;EACtE,MAAMI,QAAQ,GAAG,IAAAH,eAAM,EAAWH,SAAS,CAACO,KAAM,CAAC;EAEnD,oBACC,IAAAb,WAAA,CAAAc,GAAA,EAACjB,iBAAA,CAAAkB,gBAAgB;IAChBb,QAAQ,EAAGA,QAAU;IACrBG,gBAAgB,EAAGA,gBAAkB;IACrCF,eAAe,EAAGA,CAAA,KAAM;MACvB,OAAOA,eAAe,GAAIS,QAAQ,CAACI,OAAQ,CAAC;IAC7C,CAAG;IACHC,iBAAiB,EAAGA,CAAA,KAAMT,iBAAiB,CAACQ,OAAS;IAAAE,QAAA,eAErD,IAAAlB,WAAA,CAAAc,GAAA,EAAChB,gBAAA,CAAAqB,OAAe;MACfC,uBAAuB;MACvBC,GAAG,EAAGX,UAAY;MAClBN,QAAQ,EAAKS,KAAK,IAAM;QACvBD,QAAQ,CAACI,OAAO,GAAGH,KAAK;QACxBT,QAAQ,GAAIS,KAAM,CAAC;MACpB,CAAG;MAAA,GACEP;IAAS,CACd;EAAC,CACe,CAAC;AAErB,CAAC;AAEM,MAAMgB,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,GAAG,IAAAE,mBAAU,EACjDvB,mCACD,CAAC","ignoreList":[]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ValidatedToggleControl = void 0;
8
+ var _element = require("@wordpress/element");
9
+ var _compose = require("@wordpress/compose");
10
+ var _controlWithError = require("../control-with-error");
11
+ var _toggleControl = _interopRequireDefault(require("../../toggle-control"));
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ /**
14
+ * WordPress dependencies
15
+ */
16
+
17
+ /**
18
+ * Internal dependencies
19
+ */
20
+
21
+ // TODO: Should we customize the default `missingValue` message? It says to "check this box".
22
+
23
+ const UnforwardedValidatedToggleControl = ({
24
+ required,
25
+ customValidator,
26
+ onChange,
27
+ markWhenOptional,
28
+ ...restProps
29
+ }, forwardedRef) => {
30
+ const validityTargetRef = (0, _element.useRef)(null);
31
+ const mergedRefs = (0, _compose.useMergeRefs)([forwardedRef, validityTargetRef]);
32
+ const valueRef = (0, _element.useRef)(restProps.checked);
33
+
34
+ // TODO: Upstream limitation - The `required` attribute is not passed down to the input,
35
+ // so we need to set it manually.
36
+ (0, _element.useEffect)(() => {
37
+ if (validityTargetRef.current) {
38
+ validityTargetRef.current.required = required !== null && required !== void 0 ? required : false;
39
+ }
40
+ }, [required]);
41
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_controlWithError.ControlWithError, {
42
+ required: required,
43
+ markWhenOptional: markWhenOptional,
44
+ customValidator: () => {
45
+ return customValidator?.(valueRef.current);
46
+ },
47
+ getValidityTarget: () => validityTargetRef.current,
48
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_toggleControl.default, {
49
+ __nextHasNoMarginBottom: true,
50
+ ref: mergedRefs,
51
+ onChange: value => {
52
+ valueRef.current = value;
53
+ onChange?.(value);
54
+ },
55
+ ...restProps
56
+ })
57
+ });
58
+ };
59
+ const ValidatedToggleControl = exports.ValidatedToggleControl = (0, _element.forwardRef)(UnforwardedValidatedToggleControl);
60
+ //# sourceMappingURL=toggle-control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_element","require","_compose","_controlWithError","_toggleControl","_interopRequireDefault","_jsxRuntime","UnforwardedValidatedToggleControl","required","customValidator","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","useRef","mergedRefs","useMergeRefs","valueRef","checked","useEffect","current","jsx","ControlWithError","getValidityTarget","children","default","__nextHasNoMarginBottom","ref","value","ValidatedToggleControl","exports","forwardRef"],"sources":["@wordpress/components/src/validated-form-controls/components/toggle-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef, useEffect } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport ToggleControl from '../../toggle-control';\nimport type { ToggleControlProps } from '../../toggle-control/types';\n\ntype Value = ToggleControlProps[ 'checked' ];\n\n// TODO: Should we customize the default `missingValue` message? It says to \"check this box\".\n\nconst UnforwardedValidatedToggleControl = (\n\t{\n\t\trequired,\n\t\tcustomValidator,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof ToggleControl >,\n\t\t'__nextHasNoMarginBottom'\n\t> &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLInputElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLInputElement >( null );\n\tconst mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );\n\tconst valueRef = useRef< Value >( restProps.checked );\n\n\t// TODO: Upstream limitation - The `required` attribute is not passed down to the input,\n\t// so we need to set it manually.\n\tuseEffect( () => {\n\t\tif ( validityTargetRef.current ) {\n\t\t\tvalidityTargetRef.current.required = required ?? false;\n\t\t}\n\t}, [ required ] );\n\n\treturn (\n\t\t<ControlWithError\n\t\t\trequired={ required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tcustomValidator={ () => {\n\t\t\t\treturn customValidator?.( valueRef.current );\n\t\t\t} }\n\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t>\n\t\t\t<ToggleControl\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tref={ mergedRefs }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\tonChange?.( value );\n\t\t\t\t} }\n\t\t\t\t{ ...restProps }\n\t\t\t/>\n\t\t</ControlWithError>\n\t);\n};\n\nexport const ValidatedToggleControl = forwardRef(\n\tUnforwardedValidatedToggleControl\n);\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,iBAAA,GAAAF,OAAA;AAEA,IAAAG,cAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAAiD,IAAAK,WAAA,GAAAL,OAAA;AAXjD;AACA;AACA;;AAIA;AACA;AACA;;AAQA;;AAEA,MAAMM,iCAAiC,GAAGA,CACzC;EACCC,QAAQ;EACRC,eAAe;EACfC,QAAQ;EACRC,gBAAgB;EAChB,GAAGC;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
+ value: true
5
+ });
6
+ exports.ValidatedToggleGroupControl = void 0;
7
+ var _element = require("@wordpress/element");
8
+ var _controlWithError = require("../control-with-error");
9
+ var _toggleGroupControl = require("../../toggle-group-control");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * WordPress dependencies
13
+ */
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+
19
+ const UnforwardedValidatedToggleGroupControl = ({
20
+ required,
21
+ customValidator,
22
+ onChange,
23
+ markWhenOptional,
24
+ ...restProps
25
+ }, forwardedRef) => {
26
+ const validityTargetRef = (0, _element.useRef)(null);
27
+ const valueRef = (0, _element.useRef)(restProps.value);
28
+ const nameAttr = (0, _element.useId)();
29
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
30
+ className: "components-validated-control__wrapper-with-error-delegate",
31
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_controlWithError.ControlWithError, {
32
+ required: required,
33
+ markWhenOptional: markWhenOptional,
34
+ customValidator: () => {
35
+ return customValidator?.(valueRef.current);
36
+ },
37
+ getValidityTarget: () => validityTargetRef.current,
38
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_toggleGroupControl.ToggleGroupControl, {
39
+ __nextHasNoMarginBottom: true,
40
+ __next40pxDefaultSize: true,
41
+ ref: forwardedRef
42
+ // TODO: Upstream limitation - In uncontrolled mode, starting from an undefined value then
43
+ // setting a value has a visual bug.
44
+ ,
45
+ onChange: value => {
46
+ valueRef.current = value;
47
+ onChange?.(value);
48
+ },
49
+ ...restProps
50
+ })
51
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
52
+ className: "components-validated-control__error-delegate",
53
+ type: "radio",
54
+ ref: validityTargetRef,
55
+ required: required,
56
+ checked: restProps.value !== null,
57
+ tabIndex: -1
58
+ // A name attribute is needed for the `required` behavior to work.
59
+ ,
60
+ name: nameAttr,
61
+ onChange: () => {},
62
+ onFocus: e => {
63
+ e.target.previousElementSibling?.querySelector('[data-active-item="true"]')?.focus();
64
+ }
65
+ })]
66
+ });
67
+ };
68
+ const ValidatedToggleGroupControl = exports.ValidatedToggleGroupControl = (0, _element.forwardRef)(UnforwardedValidatedToggleGroupControl);
69
+ //# sourceMappingURL=toggle-group-control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_element","require","_controlWithError","_toggleGroupControl","_jsxRuntime","UnforwardedValidatedToggleGroupControl","required","customValidator","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","useRef","valueRef","value","nameAttr","useId","jsxs","className","children","jsx","ControlWithError","current","getValidityTarget","ToggleGroupControl","__nextHasNoMarginBottom","__next40pxDefaultSize","ref","type","checked","tabIndex","name","onFocus","e","target","previousElementSibling","querySelector","focus","ValidatedToggleGroupControl","exports","forwardRef"],"sources":["@wordpress/components/src/validated-form-controls/components/toggle-group-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef, useId, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport { ToggleGroupControl } from '../../toggle-group-control';\nimport type { ToggleGroupControlProps } from '../../toggle-group-control/types';\n\ntype Value = ToggleGroupControlProps[ 'value' ];\n\nconst UnforwardedValidatedToggleGroupControl = (\n\t{\n\t\trequired,\n\t\tcustomValidator,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof ToggleGroupControl >,\n\t\t'__next40pxDefaultSize' | '__nextHasNoMarginBottom'\n\t> &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLInputElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLInputElement >( null );\n\tconst valueRef = useRef< Value >( restProps.value );\n\n\tconst nameAttr = useId();\n\n\treturn (\n\t\t<div className=\"components-validated-control__wrapper-with-error-delegate\">\n\t\t\t<ControlWithError\n\t\t\t\trequired={ required }\n\t\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\t\tcustomValidator={ () => {\n\t\t\t\t\treturn customValidator?.( valueRef.current );\n\t\t\t\t} }\n\t\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t\t>\n\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ forwardedRef }\n\t\t\t\t\t// TODO: Upstream limitation - In uncontrolled mode, starting from an undefined value then\n\t\t\t\t\t// setting a value has a visual bug.\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\t\tonChange?.( value );\n\t\t\t\t\t} }\n\t\t\t\t\t{ ...restProps }\n\t\t\t\t/>\n\t\t\t</ControlWithError>\n\t\t\t<input\n\t\t\t\tclassName=\"components-validated-control__error-delegate\"\n\t\t\t\ttype=\"radio\"\n\t\t\t\tref={ validityTargetRef }\n\t\t\t\trequired={ required }\n\t\t\t\tchecked={ restProps.value !== null }\n\t\t\t\ttabIndex={ -1 }\n\t\t\t\t// A name attribute is needed for the `required` behavior to work.\n\t\t\t\tname={ nameAttr }\n\t\t\t\tonChange={ () => {} }\n\t\t\t\tonFocus={ ( e ) => {\n\t\t\t\t\te.target.previousElementSibling\n\t\t\t\t\t\t?.querySelector< HTMLButtonElement | HTMLInputElement >(\n\t\t\t\t\t\t\t'[data-active-item=\"true\"]'\n\t\t\t\t\t\t)\n\t\t\t\t\t\t?.focus();\n\t\t\t\t} }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const ValidatedToggleGroupControl = forwardRef(\n\tUnforwardedValidatedToggleGroupControl\n);\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,iBAAA,GAAAD,OAAA;AAEA,IAAAE,mBAAA,GAAAF,OAAA;AAAgE,IAAAG,WAAA,GAAAH,OAAA;AAVhE;AACA;AACA;;AAGA;AACA;AACA;;AAQA,MAAMI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,QAAU;MACjBR,QAAQ,EAAGA,CAAA,KAAM,CAAC,CAAG;MACrByB,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,MAAM,CAACC,sBAAsB,EAC5BC,aAAa,CACd,2BACD,CAAC,EACCC,KAAK,CAAC,CAAC;MACX;IAAG,CACH,CAAC;EAAA,CACE,CAAC;AAER,CAAC;AAEM,MAAMC,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,IAAAE,mBAAU,EACpDpC,sCACD,CAAC","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["@wordpress/components/src/validated-form-controls/components/types.ts"],"sourcesContent":["export type ValidatedControlProps< V > = {\n\t/**\n\t * Whether the control is required.\n\t * @default false\n\t */\n\trequired?: boolean;\n\t/**\n\t * Label the control as \"optional\" when _not_ `required`, instead of the inverse.\n\t * @default false\n\t */\n\tmarkWhenOptional?: boolean;\n\t/**\n\t * A function that returns a custom validity message when applicable. This error message will be applied to the\n\t * underlying element using the native [`setCustomValidity()` method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/setCustomValidity).\n\t * This means the custom validator will be run _in addition_ to any other HTML attribute-based validation, and\n\t * will be prioritized over any existing validity messages dictated by the HTML attributes.\n\t * An empty string or `undefined` return value will clear any existing custom validity message.\n\t *\n\t * Make sure you don't programatically pass a value (such as an initial value) to the control component\n\t * that fails this validator, because the validator will only run for user-initiated changes.\n\t *\n\t * Always prefer using standard HTML attributes like `required` and `min`/`max` over custom validators\n\t * when possible, as they are simpler and have localized error messages built in.\n\t */\n\t// TODO: Technically, we could add an optional `customValidity` string prop so the consumer can set\n\t// an error message at any point in time. We should wait until we have a use case though.\n\tcustomValidator?: ( currentValue: V ) => string | void;\n};\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ControlWithError = void 0;
8
+ var _i18n = require("@wordpress/i18n");
9
+ var _icons = require("@wordpress/icons");
10
+ var _element = require("@wordpress/element");
11
+ var _withIgnoreImeEvents = require("../utils/with-ignore-ime-events");
12
+ var _icon = _interopRequireDefault(require("../icon"));
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ /**
15
+ * WordPress dependencies
16
+ */
17
+
18
+ /**
19
+ * External dependencies
20
+ */
21
+
22
+ /**
23
+ * Internal dependencies
24
+ */
25
+
26
+ function appendRequiredIndicator(label, required, markWhenOptional) {
27
+ if (required && !markWhenOptional) {
28
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
29
+ children: [label, " ", `(${(0, _i18n.__)('Required')})`]
30
+ });
31
+ }
32
+ if (!required && markWhenOptional) {
33
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
34
+ children: [label, " ", `(${(0, _i18n.__)('Optional')})`]
35
+ });
36
+ }
37
+ return label;
38
+ }
39
+
40
+ /**
41
+ * HTML elements that support the Constraint Validation API.
42
+ *
43
+ * Here, we exclude HTMLButtonElement because although it does technically support the API,
44
+ * normal buttons are actually exempted from any validation.
45
+ * @see https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation
46
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/willValidate
47
+ */
48
+
49
+ function UnforwardedControlWithError({
50
+ required,
51
+ markWhenOptional,
52
+ customValidator,
53
+ getValidityTarget,
54
+ children
55
+ }, forwardedRef) {
56
+ const [errorMessage, setErrorMessage] = (0, _element.useState)();
57
+ const [isTouched, setIsTouched] = (0, _element.useState)(false);
58
+
59
+ // Ensure that error messages are visible after user attemps to submit a form
60
+ // with multiple invalid fields.
61
+ (0, _element.useEffect)(() => {
62
+ const validityTarget = getValidityTarget();
63
+ const showValidationMessage = () => setErrorMessage(validityTarget?.validationMessage);
64
+ validityTarget?.addEventListener('invalid', showValidationMessage);
65
+ return () => {
66
+ validityTarget?.removeEventListener('invalid', showValidationMessage);
67
+ };
68
+ });
69
+ const validate = () => {
70
+ const message = customValidator?.();
71
+ const validityTarget = getValidityTarget();
72
+ validityTarget?.setCustomValidity(message !== null && message !== void 0 ? message : '');
73
+ setErrorMessage(validityTarget?.validationMessage);
74
+ };
75
+ const onBlur = event => {
76
+ // Only consider "blurred from the component" if focus has fully left the wrapping div.
77
+ // This prevents unnecessary blurs from components with multiple focusable elements.
78
+ if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
79
+ setIsTouched(true);
80
+ const validityTarget = getValidityTarget();
81
+
82
+ // Prevents a double flash of the native error tooltip when the control is already showing one.
83
+ if (!validityTarget?.validity.valid) {
84
+ if (!errorMessage) {
85
+ setErrorMessage(validityTarget?.validationMessage);
86
+ }
87
+ return;
88
+ }
89
+ validate();
90
+ }
91
+ };
92
+ const onChange = (...args) => {
93
+ children.props.onChange?.(...args);
94
+
95
+ // Only validate incrementally if the field has blurred at least once,
96
+ // or currently has an error message.
97
+ if (isTouched || errorMessage) {
98
+ validate();
99
+ }
100
+ };
101
+ const onKeyDown = event => {
102
+ // Ensures that custom validators are triggered when the user submits by pressing Enter,
103
+ // without ever blurring the control.
104
+ if (event.key === 'Enter') {
105
+ validate();
106
+ }
107
+ };
108
+ return (
109
+ /*#__PURE__*/
110
+ // Disable reason: Just listening to a bubbled event, not for interaction.
111
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions
112
+ (0, _jsxRuntime.jsxs)("div", {
113
+ className: "components-validated-control",
114
+ ref: forwardedRef,
115
+ onBlur: onBlur,
116
+ onKeyDown: (0, _withIgnoreImeEvents.withIgnoreIMEEvents)(onKeyDown),
117
+ children: [(0, _element.cloneElement)(children, {
118
+ label: appendRequiredIndicator(children.props.label, required, markWhenOptional),
119
+ onChange,
120
+ required
121
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
122
+ "aria-live": "polite",
123
+ children: errorMessage && /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
124
+ className: "components-validated-control__error",
125
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.default, {
126
+ className: "components-validated-control__error-icon",
127
+ icon: _icons.error,
128
+ size: 16,
129
+ fill: "currentColor"
130
+ }), errorMessage]
131
+ })
132
+ })]
133
+ })
134
+ );
135
+ }
136
+ const ControlWithError = exports.ControlWithError = (0, _element.forwardRef)(UnforwardedControlWithError);
137
+ //# sourceMappingURL=control-with-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_i18n","require","_icons","_element","_withIgnoreImeEvents","_icon","_interopRequireDefault","_jsxRuntime","appendRequiredIndicator","label","required","markWhenOptional","jsxs","Fragment","children","__","UnforwardedControlWithError","customValidator","getValidityTarget","forwardedRef","errorMessage","setErrorMessage","useState","isTouched","setIsTouched","useEffect","validityTarget","showValidationMessage","validationMessage","addEventListener","removeEventListener","validate","message","setCustomValidity","onBlur","event","relatedTarget","currentTarget","contains","validity","valid","onChange","args","props","onKeyDown","key","className","ref","withIgnoreIMEEvents","cloneElement","jsx","default","icon","error","size","fill","ControlWithError","exports","forwardRef"],"sources":["@wordpress/components/src/validated-form-controls/control-with-error.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { error } from '@wordpress/icons';\n\n/**\n * External dependencies\n */\nimport {\n\tcloneElement,\n\tforwardRef,\n\tuseEffect,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\n\nimport Icon from '../icon';\n\nfunction appendRequiredIndicator(\n\tlabel: React.ReactNode,\n\trequired: boolean | undefined,\n\tmarkWhenOptional: boolean | undefined\n) {\n\tif ( required && ! markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Required' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\tif ( ! required && markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Optional' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\treturn label;\n}\n\n/**\n * HTML elements that support the Constraint Validation API.\n *\n * Here, we exclude HTMLButtonElement because although it does technically support the API,\n * normal buttons are actually exempted from any validation.\n * @see https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/willValidate\n */\ntype ValidityTarget =\n\t| HTMLFieldSetElement\n\t| HTMLInputElement\n\t| HTMLSelectElement\n\t| HTMLTextAreaElement;\n\nfunction UnforwardedControlWithError< C extends React.ReactElement >(\n\t{\n\t\trequired,\n\t\tmarkWhenOptional,\n\t\tcustomValidator,\n\t\tgetValidityTarget,\n\t\tchildren,\n\t}: {\n\t\t/**\n\t\t * Whether the control is required.\n\t\t */\n\t\trequired?: boolean;\n\t\t/**\n\t\t * Label the control as \"optional\" when _not_ `required`, instead of the inverse.\n\t\t */\n\t\tmarkWhenOptional?: boolean;\n\t\t/**\n\t\t * A function that returns a custom validity message when applicable.\n\t\t *\n\t\t * This message will be applied to the element returned by `getValidityTarget`.\n\t\t * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/setCustomValidity\n\t\t */\n\t\tcustomValidator?: () => string | void;\n\t\t/**\n\t\t * A function that returns the actual element on which the validity data should be applied.\n\t\t */\n\t\tgetValidityTarget: () => ValidityTarget | null | undefined;\n\t\t/**\n\t\t * The control component to apply validation to.\n\t\t */\n\t\tchildren: C;\n\t},\n\tforwardedRef: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst [ errorMessage, setErrorMessage ] = useState< string | undefined >();\n\tconst [ isTouched, setIsTouched ] = useState( false );\n\n\t// Ensure that error messages are visible after user attemps to submit a form\n\t// with multiple invalid fields.\n\tuseEffect( () => {\n\t\tconst validityTarget = getValidityTarget();\n\t\tconst showValidationMessage = () =>\n\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\tvalidityTarget?.addEventListener( 'invalid', showValidationMessage );\n\n\t\treturn () => {\n\t\t\tvalidityTarget?.removeEventListener(\n\t\t\t\t'invalid',\n\t\t\t\tshowValidationMessage\n\t\t\t);\n\t\t};\n\t} );\n\n\tconst validate = () => {\n\t\tconst message = customValidator?.();\n\t\tconst validityTarget = getValidityTarget();\n\n\t\tvalidityTarget?.setCustomValidity( message ?? '' );\n\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t};\n\n\tconst onBlur = ( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t// Only consider \"blurred from the component\" if focus has fully left the wrapping div.\n\t\t// This prevents unnecessary blurs from components with multiple focusable elements.\n\t\tif (\n\t\t\t! event.relatedTarget ||\n\t\t\t! event.currentTarget.contains( event.relatedTarget )\n\t\t) {\n\t\t\tsetIsTouched( true );\n\n\t\t\tconst validityTarget = getValidityTarget();\n\n\t\t\t// Prevents a double flash of the native error tooltip when the control is already showing one.\n\t\t\tif ( ! validityTarget?.validity.valid ) {\n\t\t\t\tif ( ! errorMessage ) {\n\t\t\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\tconst onChange = ( ...args: unknown[] ) => {\n\t\tchildren.props.onChange?.( ...args );\n\n\t\t// Only validate incrementally if the field has blurred at least once,\n\t\t// or currently has an error message.\n\t\tif ( isTouched || errorMessage ) {\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\tconst onKeyDown = ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t// Ensures that custom validators are triggered when the user submits by pressing Enter,\n\t\t// without ever blurring the control.\n\t\tif ( event.key === 'Enter' ) {\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\treturn (\n\t\t// Disable reason: Just listening to a bubbled event, not for interaction.\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName=\"components-validated-control\"\n\t\t\tref={ forwardedRef }\n\t\t\tonBlur={ onBlur }\n\t\t\tonKeyDown={ withIgnoreIMEEvents( onKeyDown ) }\n\t\t>\n\t\t\t{ cloneElement( children, {\n\t\t\t\tlabel: appendRequiredIndicator(\n\t\t\t\t\tchildren.props.label,\n\t\t\t\t\trequired,\n\t\t\t\t\tmarkWhenOptional\n\t\t\t\t),\n\t\t\t\tonChange,\n\t\t\t\trequired,\n\t\t\t} ) }\n\t\t\t<div aria-live=\"polite\">\n\t\t\t\t{ errorMessage && (\n\t\t\t\t\t<p className=\"components-validated-control__error\">\n\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\tclassName=\"components-validated-control__error-icon\"\n\t\t\t\t\t\t\ticon={ error }\n\t\t\t\t\t\t\tsize={ 16 }\n\t\t\t\t\t\t\tfill=\"currentColor\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport const ControlWithError = forwardRef( UnforwardedControlWithError );\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAKA,IAAAE,QAAA,GAAAF,OAAA;AAUA,IAAAG,oBAAA,GAAAH,OAAA;AAEA,IAAAI,KAAA,GAAAC,sBAAA,CAAAL,OAAA;AAA2B,IAAAM,WAAA,GAAAN,OAAA;AArB3B;AACA;AACA;;AAIA;AACA;AACA;;AAQA;AACA;AACA;;AAKA,SAASO,uBAAuBA,CAC/BC,KAAsB,EACtBC,QAA6B,EAC7BC,gBAAqC,EACpC;EACD,IAAKD,QAAQ,IAAI,CAAEC,gBAAgB,EAAG;IACrC,oBACC,IAAAJ,WAAA,CAAAK,IAAA,EAAAL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AAQ,EACRC,gBACD,CAAC;QACD8B,QAAQ;QACR/B;MACD,CAAE,CAAC,eACH,IAAAH,WAAA,CAAA2C,GAAA;QAAK,aAAU,QAAQ;QAAApC,QAAA,EACpBM,YAAY,iBACb,IAAAb,WAAA,CAAAK,IAAA;UAAGkC,SAAS,EAAC,qCAAqC;UAAAhC,QAAA,gBACjD,IAAAP,WAAA,CAAA2C,GAAA,EAAC7C,KAAA,CAAA8C,OAAI;YACJL,SAAS,EAAC,0CAA0C;YACpDM,IAAI,EAAGC,YAAO;YACdC,IAAI,EAAG,EAAI;YACXC,IAAI,EAAC;UAAc,CACnB,CAAC,EACAnC,YAAY;QAAA,CACZ;MACH,CACG,CAAC;IAAA,CACF;EAAC;AAER;AAEO,MAAMoC,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,IAAAE,mBAAU,EAAE1C,2BAA4B,CAAC","ignoreList":[]}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _components = require("./components");
7
+ Object.keys(_components).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _components[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _components[key];
14
+ }
15
+ });
16
+ });
17
+ var _controlWithError = require("./control-with-error");
18
+ Object.keys(_controlWithError).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _controlWithError[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _controlWithError[key];
25
+ }
26
+ });
27
+ });
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_components","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_controlWithError"],"sources":["@wordpress/components/src/validated-form-controls/index.ts"],"sourcesContent":["export * from './components';\nexport * from './control-with-error';\n"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,iBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,iBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,iBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,iBAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -78,6 +78,10 @@ export function useAutocomplete({
78
78
  // Reset autocomplete state after insertion rather than before
79
79
  // so insertion events don't cause the completion menu to redisplay.
80
80
  reset();
81
+
82
+ // Make sure that the content remains focused after making a selection
83
+ // and that the text cursor position is not lost.
84
+ contentRef.current?.focus();
81
85
  }
82
86
  function reset() {
83
87
  setSelectedIndex(0);
@@ -1 +1 @@
1
- {"version":3,"names":["removeAccents","renderToString","useEffect","useState","useRef","useMemo","useInstanceId","useMergeRefs","useRefEffect","create","slice","insert","isCollapsed","getTextContent","speak","isAppleOS","getAutoCompleterUI","escapeRegExp","withIgnoreIMEEvents","getNodeText","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","EMPTY_FILTERED_OPTIONS","AUTOCOMPLETE_HOOK_REFERENCE","useAutocomplete","record","onChange","onReplace","completers","contentRef","instanceId","selectedIndex","setSelectedIndex","filteredOptions","setFilteredOptions","filterValue","setFilterValue","autocompleter","setAutocompleter","AutocompleterUI","setAutocompleterUI","backspacingRef","insertCompletion","replacement","end","start","triggerPrefix","length","toInsert","html","select","option","getOptionCompletion","isDisabled","completion","value","isCompletionObject","obj","action","undefined","completionObject","reset","onChangeOptions","options","handleKeyDown","event","current","key","defaultPrevented","newIndex","label","preventDefault","textContent","completer","reduce","lastTrigger","currentCompleter","triggerIndex","lastIndexOf","lastTriggerIndex","allowContext","textWithoutTrigger","tooDistantFromTrigger","mismatch","wordsFromTrigger","split","hasOneTriggerWord","matchingWhileBackspacing","textAfterSelection","test","safeTrigger","text","match","RegExp","query","selectedKey","className","isExpanded","listBoxId","activeId","hasSelection","showPopover","onKeyDown","popover","onSelect","useLastDifferentValue","history","Set","add","size","delete","Array","from","useAutocompleteProps","ref","onKeyDownRef","previousRecord","mergedRefs","element","_onKeyDown","addEventListener","removeEventListener","didUserInput","children","Autocomplete","isSelected","props"],"sources":["@wordpress/components/src/autocomplete/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport {\n\trenderToString,\n\tuseEffect,\n\tuseState,\n\tuseRef,\n\tuseMemo,\n} from '@wordpress/element';\nimport { useInstanceId, useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport {\n\tcreate,\n\tslice,\n\tinsert,\n\tisCollapsed,\n\tgetTextContent,\n} from '@wordpress/rich-text';\nimport { speak } from '@wordpress/a11y';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { getAutoCompleterUI } from './autocompleter-ui';\nimport { escapeRegExp } from '../utils/strings';\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\nimport type {\n\tAutocompleteProps,\n\tAutocompleterUIProps,\n\tInsertOption,\n\tKeyedOption,\n\tOptionCompletion,\n\tReplaceOption,\n\tUseAutocompleteProps,\n\tWPCompleter,\n} from './types';\nimport getNodeText from '../utils/get-node-text';\n\nconst EMPTY_FILTERED_OPTIONS: KeyedOption[] = [];\n\n// Used for generating the instance ID\nconst AUTOCOMPLETE_HOOK_REFERENCE = {};\n\nexport function useAutocomplete( {\n\trecord,\n\tonChange,\n\tonReplace,\n\tcompleters,\n\tcontentRef,\n}: UseAutocompleteProps ) {\n\tconst instanceId = useInstanceId( AUTOCOMPLETE_HOOK_REFERENCE );\n\tconst [ selectedIndex, setSelectedIndex ] = useState( 0 );\n\n\tconst [ filteredOptions, setFilteredOptions ] = useState<\n\t\tArray< KeyedOption >\n\t>( EMPTY_FILTERED_OPTIONS );\n\tconst [ filterValue, setFilterValue ] =\n\t\tuseState< AutocompleterUIProps[ 'filterValue' ] >( '' );\n\tconst [ autocompleter, setAutocompleter ] = useState< WPCompleter | null >(\n\t\tnull\n\t);\n\tconst [ AutocompleterUI, setAutocompleterUI ] = useState<\n\t\t( ( props: AutocompleterUIProps ) => JSX.Element | null ) | null\n\t>( null );\n\n\tconst backspacingRef = useRef( false );\n\n\tfunction insertCompletion( replacement: React.ReactNode ) {\n\t\tif ( autocompleter === null ) {\n\t\t\treturn;\n\t\t}\n\t\tconst end = record.start;\n\t\tconst start =\n\t\t\tend - autocompleter.triggerPrefix.length - filterValue.length;\n\t\tconst toInsert = create( { html: renderToString( replacement ) } );\n\n\t\tonChange( insert( record, toInsert, start, end ) );\n\t}\n\n\tfunction select( option: KeyedOption ) {\n\t\tconst { getOptionCompletion } = autocompleter || {};\n\n\t\tif ( option.isDisabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( getOptionCompletion ) {\n\t\t\tconst completion = getOptionCompletion( option.value, filterValue );\n\n\t\t\tconst isCompletionObject = (\n\t\t\t\tobj: OptionCompletion\n\t\t\t): obj is InsertOption | ReplaceOption => {\n\t\t\t\treturn (\n\t\t\t\t\tobj !== null &&\n\t\t\t\t\ttypeof obj === 'object' &&\n\t\t\t\t\t'action' in obj &&\n\t\t\t\t\tobj.action !== undefined &&\n\t\t\t\t\t'value' in obj &&\n\t\t\t\t\tobj.value !== undefined\n\t\t\t\t);\n\t\t\t};\n\n\t\t\tconst completionObject = isCompletionObject( completion )\n\t\t\t\t? completion\n\t\t\t\t: ( {\n\t\t\t\t\t\taction: 'insert-at-caret',\n\t\t\t\t\t\tvalue: completion,\n\t\t\t\t } as InsertOption );\n\n\t\t\tif ( 'replace' === completionObject.action ) {\n\t\t\t\tonReplace( [ completionObject.value ] );\n\t\t\t\t// When replacing, the component will unmount, so don't reset\n\t\t\t\t// state (below) on an unmounted component.\n\t\t\t\treturn;\n\t\t\t} else if ( 'insert-at-caret' === completionObject.action ) {\n\t\t\t\tinsertCompletion( completionObject.value );\n\t\t\t}\n\t\t}\n\n\t\t// Reset autocomplete state after insertion rather than before\n\t\t// so insertion events don't cause the completion menu to redisplay.\n\t\treset();\n\t}\n\n\tfunction reset() {\n\t\tsetSelectedIndex( 0 );\n\t\tsetFilteredOptions( EMPTY_FILTERED_OPTIONS );\n\t\tsetFilterValue( '' );\n\t\tsetAutocompleter( null );\n\t\tsetAutocompleterUI( null );\n\t}\n\n\t/**\n\t * Load options for an autocompleter.\n\t *\n\t * @param {Array} options\n\t */\n\tfunction onChangeOptions( options: Array< KeyedOption > ) {\n\t\tsetSelectedIndex(\n\t\t\toptions.length === filteredOptions.length ? selectedIndex : 0\n\t\t);\n\t\tsetFilteredOptions( options );\n\t}\n\n\tfunction handleKeyDown( event: KeyboardEvent ) {\n\t\tbackspacingRef.current = event.key === 'Backspace';\n\n\t\tif ( ! autocompleter ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( filteredOptions.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( event.defaultPrevented ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( event.key ) {\n\t\t\tcase 'ArrowUp': {\n\t\t\t\tconst newIndex =\n\t\t\t\t\t( selectedIndex === 0\n\t\t\t\t\t\t? filteredOptions.length\n\t\t\t\t\t\t: selectedIndex ) - 1;\n\t\t\t\tsetSelectedIndex( newIndex );\n\t\t\t\t// See the related PR as to why this is necessary: https://github.com/WordPress/gutenberg/pull/54902.\n\t\t\t\tif ( isAppleOS() ) {\n\t\t\t\t\tspeak(\n\t\t\t\t\t\tgetNodeText( filteredOptions[ newIndex ].label ),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tconst newIndex = ( selectedIndex + 1 ) % filteredOptions.length;\n\t\t\t\tsetSelectedIndex( newIndex );\n\t\t\t\tif ( isAppleOS() ) {\n\t\t\t\t\tspeak(\n\t\t\t\t\t\tgetNodeText( filteredOptions[ newIndex ].label ),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'Escape':\n\t\t\t\tsetAutocompleter( null );\n\t\t\t\tsetAutocompleterUI( null );\n\t\t\t\tevent.preventDefault();\n\t\t\t\tbreak;\n\n\t\t\tcase 'Enter':\n\t\t\t\tselect( filteredOptions[ selectedIndex ] );\n\t\t\t\tbreak;\n\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\t\treset();\n\t\t\t\treturn;\n\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\n\t\t// Any handled key should prevent original behavior. This relies on\n\t\t// the early return in the default case.\n\t\tevent.preventDefault();\n\t}\n\n\t// textContent is a primitive (string), memoizing is not strictly necessary\n\t// but this is a preemptive performance improvement, since the autocompleter\n\t// is a potential bottleneck for the editor type metric.\n\tconst textContent = useMemo( () => {\n\t\tif ( isCollapsed( record ) ) {\n\t\t\treturn getTextContent( slice( record, 0 ) );\n\t\t}\n\t\treturn '';\n\t}, [ record ] );\n\n\tuseEffect( () => {\n\t\tif ( ! textContent ) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Find the completer with the highest triggerPrefix index in the\n\t\t// textContent.\n\t\tconst completer = completers.reduce< WPCompleter | null >(\n\t\t\t( lastTrigger, currentCompleter ) => {\n\t\t\t\tconst triggerIndex = textContent.lastIndexOf(\n\t\t\t\t\tcurrentCompleter.triggerPrefix\n\t\t\t\t);\n\t\t\t\tconst lastTriggerIndex =\n\t\t\t\t\tlastTrigger !== null\n\t\t\t\t\t\t? textContent.lastIndexOf( lastTrigger.triggerPrefix )\n\t\t\t\t\t\t: -1;\n\n\t\t\t\treturn triggerIndex > lastTriggerIndex\n\t\t\t\t\t? currentCompleter\n\t\t\t\t\t: lastTrigger;\n\t\t\t},\n\t\t\tnull\n\t\t);\n\n\t\tif ( ! completer ) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst { allowContext, triggerPrefix } = completer;\n\t\tconst triggerIndex = textContent.lastIndexOf( triggerPrefix );\n\t\tconst textWithoutTrigger = textContent.slice(\n\t\t\ttriggerIndex + triggerPrefix.length\n\t\t);\n\n\t\tconst tooDistantFromTrigger = textWithoutTrigger.length > 50; // 50 chars seems to be a good limit.\n\t\t// This is a final barrier to prevent the effect from completing with\n\t\t// an extremely long string, which causes the editor to slow-down\n\t\t// significantly. This could happen, for example, if `matchingWhileBackspacing`\n\t\t// is true and one of the \"words\" end up being too long. If that's the case,\n\t\t// it will be caught by this guard.\n\t\tif ( tooDistantFromTrigger ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst mismatch = filteredOptions.length === 0;\n\t\tconst wordsFromTrigger = textWithoutTrigger.split( /\\s/ );\n\t\t// We need to allow the effect to run when not backspacing and if there\n\t\t// was a mismatch. i.e when typing a trigger + the match string or when\n\t\t// clicking in an existing trigger word on the page. We do that if we\n\t\t// detect that we have one word from trigger in the current textual context.\n\t\t//\n\t\t// Ex.: \"Some text @a\" <-- \"@a\" will be detected as the trigger word and\n\t\t// allow the effect to run. It will run until there's a mismatch.\n\t\tconst hasOneTriggerWord = wordsFromTrigger.length === 1;\n\t\t// This is used to allow the effect to run when backspacing and if\n\t\t// \"touching\" a word that \"belongs\" to a trigger. We consider a \"trigger\n\t\t// word\" any word up to the limit of 3 from the trigger character.\n\t\t// Anything beyond that is ignored if there's a mismatch. This allows\n\t\t// us to \"escape\" a mismatch when backspacing, but still imposing some\n\t\t// sane limits.\n\t\t//\n\t\t// Ex: \"Some text @marcelo sekkkk\" <--- \"kkkk\" caused a mismatch, but\n\t\t// if the user presses backspace here, it will show the completion popup again.\n\t\tconst matchingWhileBackspacing =\n\t\t\tbackspacingRef.current && wordsFromTrigger.length <= 3;\n\n\t\tif ( mismatch && ! ( matchingWhileBackspacing || hasOneTriggerWord ) ) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst textAfterSelection = getTextContent(\n\t\t\tslice( record, undefined, getTextContent( record ).length )\n\t\t);\n\n\t\tif (\n\t\t\tallowContext &&\n\t\t\t! allowContext(\n\t\t\t\ttextContent.slice( 0, triggerIndex ),\n\t\t\t\ttextAfterSelection\n\t\t\t)\n\t\t) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\t/^\\s/.test( textWithoutTrigger ) ||\n\t\t\t/\\s\\s+$/.test( textWithoutTrigger )\n\t\t) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! /[\\u0000-\\uFFFF]*$/.test( textWithoutTrigger ) ) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst safeTrigger = escapeRegExp( completer.triggerPrefix );\n\t\tconst text = removeAccents( textContent );\n\t\tconst match = text\n\t\t\t.slice( text.lastIndexOf( completer.triggerPrefix ) )\n\t\t\t.match( new RegExp( `${ safeTrigger }([\\u0000-\\uFFFF]*)$` ) );\n\t\tconst query = match && match[ 1 ];\n\n\t\tsetAutocompleter( completer );\n\t\tsetAutocompleterUI( () =>\n\t\t\tcompleter !== autocompleter\n\t\t\t\t? getAutoCompleterUI( completer )\n\t\t\t\t: AutocompleterUI\n\t\t);\n\t\tsetFilterValue( query === null ? '' : query );\n\t\t// We want to avoid introducing unexpected side effects.\n\t\t// See https://github.com/WordPress/gutenberg/pull/41820\n\t}, [ textContent ] );\n\n\tconst { key: selectedKey = '' } = filteredOptions[ selectedIndex ] || {};\n\tconst { className } = autocompleter || {};\n\tconst isExpanded = !! autocompleter && filteredOptions.length > 0;\n\tconst listBoxId = isExpanded\n\t\t? `components-autocomplete-listbox-${ instanceId }`\n\t\t: undefined;\n\tconst activeId = isExpanded\n\t\t? `components-autocomplete-item-${ instanceId }-${ selectedKey }`\n\t\t: null;\n\tconst hasSelection = record.start !== undefined;\n\tconst showPopover = !! textContent && hasSelection && !! AutocompleterUI;\n\n\treturn {\n\t\tlistBoxId,\n\t\tactiveId,\n\t\tonKeyDown: withIgnoreIMEEvents( handleKeyDown ),\n\t\tpopover: showPopover && (\n\t\t\t<AutocompleterUI\n\t\t\t\tclassName={ className }\n\t\t\t\tfilterValue={ filterValue }\n\t\t\t\tinstanceId={ instanceId }\n\t\t\t\tlistBoxId={ listBoxId }\n\t\t\t\tselectedIndex={ selectedIndex }\n\t\t\t\tonChangeOptions={ onChangeOptions }\n\t\t\t\tonSelect={ select }\n\t\t\t\tvalue={ record }\n\t\t\t\tcontentRef={ contentRef }\n\t\t\t\treset={ reset }\n\t\t\t/>\n\t\t),\n\t};\n}\n\nfunction useLastDifferentValue( value: UseAutocompleteProps[ 'record' ] ) {\n\tconst history = useRef< Set< typeof value > >( new Set() );\n\n\thistory.current.add( value );\n\n\t// Keep the history size to 2.\n\tif ( history.current.size > 2 ) {\n\t\thistory.current.delete( Array.from( history.current )[ 0 ] );\n\t}\n\n\treturn Array.from( history.current )[ 0 ];\n}\n\nexport function useAutocompleteProps( options: UseAutocompleteProps ) {\n\tconst ref = useRef< HTMLElement >( null );\n\tconst onKeyDownRef = useRef< ( event: KeyboardEvent ) => void >();\n\tconst { record } = options;\n\tconst previousRecord = useLastDifferentValue( record );\n\tconst { popover, listBoxId, activeId, onKeyDown } = useAutocomplete( {\n\t\t...options,\n\t\tcontentRef: ref,\n\t} );\n\tonKeyDownRef.current = onKeyDown;\n\n\tconst mergedRefs = useMergeRefs( [\n\t\tref,\n\t\tuseRefEffect( ( element: HTMLElement ) => {\n\t\t\tfunction _onKeyDown( event: KeyboardEvent ) {\n\t\t\t\tonKeyDownRef.current?.( event );\n\t\t\t}\n\t\t\telement.addEventListener( 'keydown', _onKeyDown );\n\t\t\treturn () => {\n\t\t\t\telement.removeEventListener( 'keydown', _onKeyDown );\n\t\t\t};\n\t\t}, [] ),\n\t] );\n\n\t// We only want to show the popover if the user has typed something.\n\tconst didUserInput = record.text !== previousRecord?.text;\n\n\tif ( ! didUserInput ) {\n\t\treturn { ref: mergedRefs };\n\t}\n\n\treturn {\n\t\tref: mergedRefs,\n\t\tchildren: popover,\n\t\t'aria-autocomplete': listBoxId ? 'list' : undefined,\n\t\t'aria-owns': listBoxId,\n\t\t'aria-activedescendant': activeId,\n\t};\n}\n\nexport default function Autocomplete( {\n\tchildren,\n\tisSelected,\n\t...options\n}: AutocompleteProps ) {\n\tconst { popover, ...props } = useAutocomplete( options );\n\treturn (\n\t\t<>\n\t\t\t{ children( props ) }\n\t\t\t{ isSelected && popover }\n\t\t</>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,gBAAgB;;AAE1C;AACA;AACA;AACA,SACCC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,MAAM,EACNC,OAAO,QACD,oBAAoB;AAC3B,SAASC,aAAa,EAAEC,YAAY,EAAEC,YAAY,QAAQ,o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EA,eAAe,SAASyB,YAAYA,CAAE;EACrCD,QAAQ;EACRE,UAAU;EACV,GAAG9D;AACe,CAAC,EAAG;EACtB,MAAM;IAAEwC,OAAO;IAAE,GAAGuB;EAAM,CAAC,GAAGtG,eAAe,CAAEuC,OAAQ,CAAC;EACxD,oBACC1C,KAAA,CAAAF,SAAA;IAAAwG,QAAA,GACGA,QAAQ,CAAEG,KAAM,CAAC,EACjBD,UAAU,IAAItB,OAAO;EAAA,CACtB,CAAC;AAEL","ignoreList":[]}
1
+ {"version":3,"names":["removeAccents","renderToString","useEffect","useState","useRef","useMemo","useInstanceId","useMergeRefs","useRefEffect","create","slice","insert","isCollapsed","getTextContent","speak","isAppleOS","getAutoCompleterUI","escapeRegExp","withIgnoreIMEEvents","getNodeText","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","EMPTY_FILTERED_OPTIONS","AUTOCOMPLETE_HOOK_REFERENCE","useAutocomplete","record","onChange","onReplace","completers","contentRef","instanceId","selectedIndex","setSelectedIndex","filteredOptions","setFilteredOptions","filterValue","setFilterValue","autocompleter","setAutocompleter","AutocompleterUI","setAutocompleterUI","backspacingRef","insertCompletion","replacement","end","start","triggerPrefix","length","toInsert","html","select","option","getOptionCompletion","isDisabled","completion","value","isCompletionObject","obj","action","undefined","completionObject","reset","current","focus","onChangeOptions","options","handleKeyDown","event","key","defaultPrevented","newIndex","label","preventDefault","textContent","completer","reduce","lastTrigger","currentCompleter","triggerIndex","lastIndexOf","lastTriggerIndex","allowContext","textWithoutTrigger","tooDistantFromTrigger","mismatch","wordsFromTrigger","split","hasOneTriggerWord","matchingWhileBackspacing","textAfterSelection","test","safeTrigger","text","match","RegExp","query","selectedKey","className","isExpanded","listBoxId","activeId","hasSelection","showPopover","onKeyDown","popover","onSelect","useLastDifferentValue","history","Set","add","size","delete","Array","from","useAutocompleteProps","ref","onKeyDownRef","previousRecord","mergedRefs","element","_onKeyDown","addEventListener","removeEventListener","didUserInput","children","Autocomplete","isSelected","props"],"sources":["@wordpress/components/src/autocomplete/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport {\n\trenderToString,\n\tuseEffect,\n\tuseState,\n\tuseRef,\n\tuseMemo,\n} from '@wordpress/element';\nimport { useInstanceId, useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport {\n\tcreate,\n\tslice,\n\tinsert,\n\tisCollapsed,\n\tgetTextContent,\n} from '@wordpress/rich-text';\nimport { speak } from '@wordpress/a11y';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { getAutoCompleterUI } from './autocompleter-ui';\nimport { escapeRegExp } from '../utils/strings';\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\nimport type {\n\tAutocompleteProps,\n\tAutocompleterUIProps,\n\tInsertOption,\n\tKeyedOption,\n\tOptionCompletion,\n\tReplaceOption,\n\tUseAutocompleteProps,\n\tWPCompleter,\n} from './types';\nimport getNodeText from '../utils/get-node-text';\n\nconst EMPTY_FILTERED_OPTIONS: KeyedOption[] = [];\n\n// Used for generating the instance ID\nconst AUTOCOMPLETE_HOOK_REFERENCE = {};\n\nexport function useAutocomplete( {\n\trecord,\n\tonChange,\n\tonReplace,\n\tcompleters,\n\tcontentRef,\n}: UseAutocompleteProps ) {\n\tconst instanceId = useInstanceId( AUTOCOMPLETE_HOOK_REFERENCE );\n\tconst [ selectedIndex, setSelectedIndex ] = useState( 0 );\n\n\tconst [ filteredOptions, setFilteredOptions ] = useState<\n\t\tArray< KeyedOption >\n\t>( EMPTY_FILTERED_OPTIONS );\n\tconst [ filterValue, setFilterValue ] =\n\t\tuseState< AutocompleterUIProps[ 'filterValue' ] >( '' );\n\tconst [ autocompleter, setAutocompleter ] = useState< WPCompleter | null >(\n\t\tnull\n\t);\n\tconst [ AutocompleterUI, setAutocompleterUI ] = useState<\n\t\t( ( props: AutocompleterUIProps ) => JSX.Element | null ) | null\n\t>( null );\n\n\tconst backspacingRef = useRef( false );\n\n\tfunction insertCompletion( replacement: React.ReactNode ) {\n\t\tif ( autocompleter === null ) {\n\t\t\treturn;\n\t\t}\n\t\tconst end = record.start;\n\t\tconst start =\n\t\t\tend - autocompleter.triggerPrefix.length - filterValue.length;\n\t\tconst toInsert = create( { html: renderToString( replacement ) } );\n\n\t\tonChange( insert( record, toInsert, start, end ) );\n\t}\n\n\tfunction select( option: KeyedOption ) {\n\t\tconst { getOptionCompletion } = autocompleter || {};\n\n\t\tif ( option.isDisabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( getOptionCompletion ) {\n\t\t\tconst completion = getOptionCompletion( option.value, filterValue );\n\n\t\t\tconst isCompletionObject = (\n\t\t\t\tobj: OptionCompletion\n\t\t\t): obj is InsertOption | ReplaceOption => {\n\t\t\t\treturn (\n\t\t\t\t\tobj !== null &&\n\t\t\t\t\ttypeof obj === 'object' &&\n\t\t\t\t\t'action' in obj &&\n\t\t\t\t\tobj.action !== undefined &&\n\t\t\t\t\t'value' in obj &&\n\t\t\t\t\tobj.value !== undefined\n\t\t\t\t);\n\t\t\t};\n\n\t\t\tconst completionObject = isCompletionObject( completion )\n\t\t\t\t? completion\n\t\t\t\t: ( {\n\t\t\t\t\t\taction: 'insert-at-caret',\n\t\t\t\t\t\tvalue: completion,\n\t\t\t\t } as InsertOption );\n\n\t\t\tif ( 'replace' === completionObject.action ) {\n\t\t\t\tonReplace( [ completionObject.value ] );\n\t\t\t\t// When replacing, the component will unmount, so don't reset\n\t\t\t\t// state (below) on an unmounted component.\n\t\t\t\treturn;\n\t\t\t} else if ( 'insert-at-caret' === completionObject.action ) {\n\t\t\t\tinsertCompletion( completionObject.value );\n\t\t\t}\n\t\t}\n\n\t\t// Reset autocomplete state after insertion rather than before\n\t\t// so insertion events don't cause the completion menu to redisplay.\n\t\treset();\n\n\t\t// Make sure that the content remains focused after making a selection\n\t\t// and that the text cursor position is not lost.\n\t\tcontentRef.current?.focus();\n\t}\n\n\tfunction reset() {\n\t\tsetSelectedIndex( 0 );\n\t\tsetFilteredOptions( EMPTY_FILTERED_OPTIONS );\n\t\tsetFilterValue( '' );\n\t\tsetAutocompleter( null );\n\t\tsetAutocompleterUI( null );\n\t}\n\n\t/**\n\t * Load options for an autocompleter.\n\t *\n\t * @param {Array} options\n\t */\n\tfunction onChangeOptions( options: Array< KeyedOption > ) {\n\t\tsetSelectedIndex(\n\t\t\toptions.length === filteredOptions.length ? selectedIndex : 0\n\t\t);\n\t\tsetFilteredOptions( options );\n\t}\n\n\tfunction handleKeyDown( event: KeyboardEvent ) {\n\t\tbackspacingRef.current = event.key === 'Backspace';\n\n\t\tif ( ! autocompleter ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( filteredOptions.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( event.defaultPrevented ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( event.key ) {\n\t\t\tcase 'ArrowUp': {\n\t\t\t\tconst newIndex =\n\t\t\t\t\t( selectedIndex === 0\n\t\t\t\t\t\t? filteredOptions.length\n\t\t\t\t\t\t: selectedIndex ) - 1;\n\t\t\t\tsetSelectedIndex( newIndex );\n\t\t\t\t// See the related PR as to why this is necessary: https://github.com/WordPress/gutenberg/pull/54902.\n\t\t\t\tif ( isAppleOS() ) {\n\t\t\t\t\tspeak(\n\t\t\t\t\t\tgetNodeText( filteredOptions[ newIndex ].label ),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tconst newIndex = ( selectedIndex + 1 ) % filteredOptions.length;\n\t\t\t\tsetSelectedIndex( newIndex );\n\t\t\t\tif ( isAppleOS() ) {\n\t\t\t\t\tspeak(\n\t\t\t\t\t\tgetNodeText( filteredOptions[ newIndex ].label ),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'Escape':\n\t\t\t\tsetAutocompleter( null );\n\t\t\t\tsetAutocompleterUI( null );\n\t\t\t\tevent.preventDefault();\n\t\t\t\tbreak;\n\n\t\t\tcase 'Enter':\n\t\t\t\tselect( filteredOptions[ selectedIndex ] );\n\t\t\t\tbreak;\n\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\t\treset();\n\t\t\t\treturn;\n\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\n\t\t// Any handled key should prevent original behavior. This relies on\n\t\t// the early return in the default case.\n\t\tevent.preventDefault();\n\t}\n\n\t// textContent is a primitive (string), memoizing is not strictly necessary\n\t// but this is a preemptive performance improvement, since the autocompleter\n\t// is a potential bottleneck for the editor type metric.\n\tconst textContent = useMemo( () => {\n\t\tif ( isCollapsed( record ) ) {\n\t\t\treturn getTextContent( slice( record, 0 ) );\n\t\t}\n\t\treturn '';\n\t}, [ record ] );\n\n\tuseEffect( () => {\n\t\tif ( ! textContent ) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Find the completer with the highest triggerPrefix index in the\n\t\t// textContent.\n\t\tconst completer = completers.reduce< WPCompleter | null >(\n\t\t\t( lastTrigger, currentCompleter ) => {\n\t\t\t\tconst triggerIndex = textContent.lastIndexOf(\n\t\t\t\t\tcurrentCompleter.triggerPrefix\n\t\t\t\t);\n\t\t\t\tconst lastTriggerIndex =\n\t\t\t\t\tlastTrigger !== null\n\t\t\t\t\t\t? textContent.lastIndexOf( lastTrigger.triggerPrefix )\n\t\t\t\t\t\t: -1;\n\n\t\t\t\treturn triggerIndex > lastTriggerIndex\n\t\t\t\t\t? currentCompleter\n\t\t\t\t\t: lastTrigger;\n\t\t\t},\n\t\t\tnull\n\t\t);\n\n\t\tif ( ! completer ) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst { allowContext, triggerPrefix } = completer;\n\t\tconst triggerIndex = textContent.lastIndexOf( triggerPrefix );\n\t\tconst textWithoutTrigger = textContent.slice(\n\t\t\ttriggerIndex + triggerPrefix.length\n\t\t);\n\n\t\tconst tooDistantFromTrigger = textWithoutTrigger.length > 50; // 50 chars seems to be a good limit.\n\t\t// This is a final barrier to prevent the effect from completing with\n\t\t// an extremely long string, which causes the editor to slow-down\n\t\t// significantly. This could happen, for example, if `matchingWhileBackspacing`\n\t\t// is true and one of the \"words\" end up being too long. If that's the case,\n\t\t// it will be caught by this guard.\n\t\tif ( tooDistantFromTrigger ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst mismatch = filteredOptions.length === 0;\n\t\tconst wordsFromTrigger = textWithoutTrigger.split( /\\s/ );\n\t\t// We need to allow the effect to run when not backspacing and if there\n\t\t// was a mismatch. i.e when typing a trigger + the match string or when\n\t\t// clicking in an existing trigger word on the page. We do that if we\n\t\t// detect that we have one word from trigger in the current textual context.\n\t\t//\n\t\t// Ex.: \"Some text @a\" <-- \"@a\" will be detected as the trigger word and\n\t\t// allow the effect to run. It will run until there's a mismatch.\n\t\tconst hasOneTriggerWord = wordsFromTrigger.length === 1;\n\t\t// This is used to allow the effect to run when backspacing and if\n\t\t// \"touching\" a word that \"belongs\" to a trigger. We consider a \"trigger\n\t\t// word\" any word up to the limit of 3 from the trigger character.\n\t\t// Anything beyond that is ignored if there's a mismatch. This allows\n\t\t// us to \"escape\" a mismatch when backspacing, but still imposing some\n\t\t// sane limits.\n\t\t//\n\t\t// Ex: \"Some text @marcelo sekkkk\" <--- \"kkkk\" caused a mismatch, but\n\t\t// if the user presses backspace here, it will show the completion popup again.\n\t\tconst matchingWhileBackspacing =\n\t\t\tbackspacingRef.current && wordsFromTrigger.length <= 3;\n\n\t\tif ( mismatch && ! ( matchingWhileBackspacing || hasOneTriggerWord ) ) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst textAfterSelection = getTextContent(\n\t\t\tslice( record, undefined, getTextContent( record ).length )\n\t\t);\n\n\t\tif (\n\t\t\tallowContext &&\n\t\t\t! allowContext(\n\t\t\t\ttextContent.slice( 0, triggerIndex ),\n\t\t\t\ttextAfterSelection\n\t\t\t)\n\t\t) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\t/^\\s/.test( textWithoutTrigger ) ||\n\t\t\t/\\s\\s+$/.test( textWithoutTrigger )\n\t\t) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! /[\\u0000-\\uFFFF]*$/.test( textWithoutTrigger ) ) {\n\t\t\tif ( autocompleter ) {\n\t\t\t\treset();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst safeTrigger = escapeRegExp( completer.triggerPrefix );\n\t\tconst text = removeAccents( textContent );\n\t\tconst match = text\n\t\t\t.slice( text.lastIndexOf( completer.triggerPrefix ) )\n\t\t\t.match( new RegExp( `${ safeTrigger }([\\u0000-\\uFFFF]*)$` ) );\n\t\tconst query = match && match[ 1 ];\n\n\t\tsetAutocompleter( completer );\n\t\tsetAutocompleterUI( () =>\n\t\t\tcompleter !== autocompleter\n\t\t\t\t? getAutoCompleterUI( completer )\n\t\t\t\t: AutocompleterUI\n\t\t);\n\t\tsetFilterValue( query === null ? '' : query );\n\t\t// We want to avoid introducing unexpected side effects.\n\t\t// See https://github.com/WordPress/gutenberg/pull/41820\n\t}, [ textContent ] );\n\n\tconst { key: selectedKey = '' } = filteredOptions[ selectedIndex ] || {};\n\tconst { className } = autocompleter || {};\n\tconst isExpanded = !! autocompleter && filteredOptions.length > 0;\n\tconst listBoxId = isExpanded\n\t\t? `components-autocomplete-listbox-${ instanceId }`\n\t\t: undefined;\n\tconst activeId = isExpanded\n\t\t? `components-autocomplete-item-${ instanceId }-${ selectedKey }`\n\t\t: null;\n\tconst hasSelection = record.start !== undefined;\n\tconst showPopover = !! textContent && hasSelection && !! AutocompleterUI;\n\n\treturn {\n\t\tlistBoxId,\n\t\tactiveId,\n\t\tonKeyDown: withIgnoreIMEEvents( handleKeyDown ),\n\t\tpopover: showPopover && (\n\t\t\t<AutocompleterUI\n\t\t\t\tclassName={ className }\n\t\t\t\tfilterValue={ filterValue }\n\t\t\t\tinstanceId={ instanceId }\n\t\t\t\tlistBoxId={ listBoxId }\n\t\t\t\tselectedIndex={ selectedIndex }\n\t\t\t\tonChangeOptions={ onChangeOptions }\n\t\t\t\tonSelect={ select }\n\t\t\t\tvalue={ record }\n\t\t\t\tcontentRef={ contentRef }\n\t\t\t\treset={ reset }\n\t\t\t/>\n\t\t),\n\t};\n}\n\nfunction useLastDifferentValue( value: UseAutocompleteProps[ 'record' ] ) {\n\tconst history = useRef< Set< typeof value > >( new Set() );\n\n\thistory.current.add( value );\n\n\t// Keep the history size to 2.\n\tif ( history.current.size > 2 ) {\n\t\thistory.current.delete( Array.from( history.current )[ 0 ] );\n\t}\n\n\treturn Array.from( history.current )[ 0 ];\n}\n\nexport function useAutocompleteProps( options: UseAutocompleteProps ) {\n\tconst ref = useRef< HTMLElement >( null );\n\tconst onKeyDownRef = useRef< ( event: KeyboardEvent ) => void >();\n\tconst { record } = options;\n\tconst previousRecord = useLastDifferentValue( record );\n\tconst { popover, listBoxId, activeId, onKeyDown } = useAutocomplete( {\n\t\t...options,\n\t\tcontentRef: ref,\n\t} );\n\tonKeyDownRef.current = onKeyDown;\n\n\tconst mergedRefs = useMergeRefs( [\n\t\tref,\n\t\tuseRefEffect( ( element: HTMLElement ) => {\n\t\t\tfunction _onKeyDown( event: KeyboardEvent ) {\n\t\t\t\tonKeyDownRef.current?.( event );\n\t\t\t}\n\t\t\telement.addEventListener( 'keydown', _onKeyDown );\n\t\t\treturn () => {\n\t\t\t\telement.removeEventListener( 'keydown', _onKeyDown );\n\t\t\t};\n\t\t}, [] ),\n\t] );\n\n\t// We only want to show the popover if the user has typed something.\n\tconst didUserInput = record.text !== previousRecord?.text;\n\n\tif ( ! didUserInput ) {\n\t\treturn { ref: mergedRefs };\n\t}\n\n\treturn {\n\t\tref: mergedRefs,\n\t\tchildren: popover,\n\t\t'aria-autocomplete': listBoxId ? 'list' : undefined,\n\t\t'aria-owns': listBoxId,\n\t\t'aria-activedescendant': activeId,\n\t};\n}\n\nexport default function Autocomplete( {\n\tchildren,\n\tisSelected,\n\t...options\n}: AutocompleteProps ) {\n\tconst { popover, ...props } = useAutocomplete( options );\n\treturn (\n\t\t<>\n\t\t\t{ children( props ) }\n\t\t\t{ isSelected && popover }\n\t\t</>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,gBAAgB;;AAE1C;AACA;AACA;AACA,SACCC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,MAAM,EACNC,OAAO,QACD,oBAAoB;AAC3B,SAASC,aAAa,EAAEC,YAAY,EAAEC,YAAY,QAAQ,oBAAoB;AAC9E,SACCC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,WAAW,EACXC,cAAc,QACR,sBAAsB;AAC7B,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,SAAS,QAAQ,qBAAqB;;AAE/C;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,mBAAmB,QAAQ,iCAAiC;AAWrE,OAAOC,WAAW,MAAM,wBAAwB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAEjD,MAAMC,sBAAqC,GAAG,EAAE;;AAEhD;AACA,MAAMC,2BAA2B,GAAG,CAAC,CAAC;AAEtC,OAAO,SAASC,eAAeA,CAAE;EAChCC,MAAM;EACNC,QAAQ;EACRC,SAAS;EACTC,UAAU;EACVC;AACqB,CA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AS;EAEhC,MAAMe,UAAU,GAAGnH,YAAY,CAAE,CAChCgH,GAAG,EACH/G,YAAY,CAAImH,OAAoB,IAAM;IACzC,SAASC,UAAUA,CAAErD,KAAoB,EAAG;MAC3CiD,YAAY,CAACtD,OAAO,GAAIK,KAAM,CAAC;IAChC;IACAoD,OAAO,CAACE,gBAAgB,CAAE,SAAS,EAAED,UAAW,CAAC;IACjD,OAAO,MAAM;MACZD,OAAO,CAACG,mBAAmB,CAAE,SAAS,EAAEF,UAAW,CAAC;IACrD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC,CACN,CAAC;;EAEH;EACA,MAAMG,YAAY,GAAGlG,MAAM,CAACmE,IAAI,KAAKyB,cAAc,EAAEzB,IAAI;EAEzD,IAAK,CAAE+B,YAAY,EAAG;IACrB,OAAO;MAAER,GAAG,EAAEG;IAAW,CAAC;EAC3B;EAEA,OAAO;IACNH,GAAG,EAAEG,UAAU;IACfM,QAAQ,EAAEpB,OAAO;IACjB,mBAAmB,EAAEL,SAAS,GAAG,MAAM,GAAGxC,SAAS;IACnD,WAAW,EAAEwC,SAAS;IACtB,uBAAuB,EAAEC;EAC1B,CAAC;AACF;AAEA,eAAe,SAASyB,YAAYA,CAAE;EACrCD,QAAQ;EACRE,UAAU;EACV,GAAG7D;AACe,CAAC,EAAG;EACtB,MAAM;IAAEuC,OAAO;IAAE,GAAGuB;EAAM,CAAC,GAAGvG,eAAe,CAAEyC,OAAQ,CAAC;EACxD,oBACC5C,KAAA,CAAAF,SAAA;IAAAyG,QAAA,GACGA,QAAQ,CAAEG,KAAM,CAAC,EACjBD,UAAU,IAAItB,OAAO;EAAA,CACtB,CAAC;AAEL","ignoreList":[]}
@@ -3,12 +3,16 @@
3
3
  */
4
4
  import { DayPicker } from 'react-day-picker';
5
5
  import { enUS } from 'react-day-picker/locale';
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { useCallback } from '@wordpress/element';
6
10
  /**
7
11
  * Internal dependencies
8
12
  */
9
13
  import { COMMON_PROPS } from '../utils/constants';
10
14
  import { clampNumberOfMonths } from '../utils/misc';
11
- import { useControlledValue } from '../utils/use-controlled-value';
15
+ import { useControlledValue } from '../../utils/hooks';
12
16
  import { useLocalizationProps } from '../utils/use-localization-props';
13
17
  import { jsx as _jsx } from "react/jsx-runtime";
14
18
  /**
@@ -33,10 +37,14 @@ export const DateCalendar = ({
33
37
  timeZone,
34
38
  mode: 'single'
35
39
  });
40
+ const onChange = useCallback((selected, triggerDate, modifiers, e) => {
41
+ // Convert internal `null` to `undefined` for the public event handler.
42
+ onSelect?.(selected !== null && selected !== void 0 ? selected : undefined, triggerDate, modifiers, e);
43
+ }, [onSelect]);
36
44
  const [selected, setSelected] = useControlledValue({
37
45
  defaultValue: defaultSelected,
38
46
  value: selectedProp,
39
- onChange: onSelect
47
+ onChange
40
48
  });
41
49
  return /*#__PURE__*/_jsx(DayPicker, {
42
50
  ...COMMON_PROPS,
@@ -44,7 +52,7 @@ export const DateCalendar = ({
44
52
  ...props,
45
53
  mode: "single",
46
54
  numberOfMonths: clampNumberOfMonths(numberOfMonths),
47
- selected: selected,
55
+ selected: selected !== null && selected !== void 0 ? selected : undefined,
48
56
  onSelect: setSelected
49
57
  });
50
58
  };
@@ -1 +1 @@
1
- {"version":3,"names":["DayPicker","enUS","COMMON_PROPS","clampNumberOfMonths","useControlledValue","useLocalizationProps","jsx","_jsx","DateCalendar","defaultSelected","selected","selectedProp","onSelect","numberOfMonths","locale","timeZone","props","localizationProps","mode","setSelected","defaultValue","value","onChange"],"sources":["@wordpress/components/src/calendar/date-calendar/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport { DayPicker } from 'react-day-picker';\nimport { enUS } from 'react-day-picker/locale';\n/**\n * Internal dependencies\n */\nimport { COMMON_PROPS } from '../utils/constants';\nimport { clampNumberOfMonths } from '../utils/misc';\nimport { useControlledValue } from '../utils/use-controlled-value';\nimport { useLocalizationProps } from '../utils/use-localization-props';\nimport type { DateCalendarProps } from '../types';\n\n/**\n * `DateCalendar` is a React component that provides a customizable calendar\n * interface for **single date** selection.\n *\n * The component is built with accessibility in mind and follows ARIA best\n * practices for calendar widgets. It provides keyboard navigation, screen reader\n * support, and customizable labels for internationalization.\n */\nexport const DateCalendar = ( {\n\tdefaultSelected,\n\tselected: selectedProp,\n\tonSelect,\n\tnumberOfMonths = 1,\n\tlocale = enUS,\n\ttimeZone,\n\t...props\n}: DateCalendarProps ) => {\n\tconst localizationProps = useLocalizationProps( {\n\t\tlocale,\n\t\ttimeZone,\n\t\tmode: 'single',\n\t} );\n\n\tconst [ selected, setSelected ] = useControlledValue< Date | undefined >( {\n\t\tdefaultValue: defaultSelected,\n\t\tvalue: selectedProp,\n\t\tonChange: onSelect,\n\t} );\n\n\treturn (\n\t\t<DayPicker\n\t\t\t{ ...COMMON_PROPS }\n\t\t\t{ ...localizationProps }\n\t\t\t{ ...props }\n\t\t\tmode=\"single\"\n\t\t\tnumberOfMonths={ clampNumberOfMonths( numberOfMonths ) }\n\t\t\tselected={ selected }\n\t\t\tonSelect={ setSelected }\n\t\t/>\n\t);\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,IAAI,QAAQ,yBAAyB;AAC9C;AACA;AACA;AACA,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,mBAAmB,QAAQ,eAAe;AACnD,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,oBAAoB,QAAQ,iCAAiC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAGA,CAAE;EAC7BC,eAAe;EACfC,QAAQ,EAAEC,YAAY;EACtBC,QAAQ;EACRC,cAAc,GAAG,CAAC;EAClBC,MAAM,GAAGb,IAAI;EACbc,QAAQ;EACR,GAAGC;AACe,CAAC,KAAM;EACzB,MAAMC,iBAAiB,GAAGZ,oBAAoB,CAAE;IAC/CS,MAAM;IACNC,QAAQ;IACRG,IAAI,EAAE;EACP,CAAE,CAAC;EAEH,MAAM,CAAER,QAAQ,EAAES,WAAW,CAAE,GAAGf,kBAAkB,CAAsB;IACzEgB,YAAY,EAAEX,eAAe;IAC7BY,KAAK,EAAEV,YAAY;IACnBW,QAAQ,EAAEV;EACX,CAAE,CAAC;EAEH,oBACCL,IAAA,CAACP,SAAS;IAAA,GACJE,YAAY;IAAA,GACZe,iBAAiB;IAAA,GACjBD,KAAK;IACVE,IAAI,EAAC,QAAQ;IACbL,cAAc,EAAGV,mBAAmB,CAAEU,cAAe,CAAG;IACxDH,QAAQ,EAAGA,QAAU;IACrBE,QAAQ,EAAGO;EAAa,CACxB,CAAC;AAEJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["DayPicker","enUS","useCallback","COMMON_PROPS","clampNumberOfMonths","useControlledValue","useLocalizationProps","jsx","_jsx","DateCalendar","defaultSelected","selected","selectedProp","onSelect","numberOfMonths","locale","timeZone","props","localizationProps","mode","onChange","triggerDate","modifiers","e","undefined","setSelected","defaultValue","value"],"sources":["@wordpress/components/src/calendar/date-calendar/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport { DayPicker } from 'react-day-picker';\nimport { enUS } from 'react-day-picker/locale';\n/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport { COMMON_PROPS } from '../utils/constants';\nimport { clampNumberOfMonths } from '../utils/misc';\nimport { useControlledValue } from '../../utils/hooks';\nimport { useLocalizationProps } from '../utils/use-localization-props';\nimport type { DateCalendarProps, OnSelectHandler } from '../types';\n\n/**\n * `DateCalendar` is a React component that provides a customizable calendar\n * interface for **single date** selection.\n *\n * The component is built with accessibility in mind and follows ARIA best\n * practices for calendar widgets. It provides keyboard navigation, screen reader\n * support, and customizable labels for internationalization.\n */\nexport const DateCalendar = ( {\n\tdefaultSelected,\n\tselected: selectedProp,\n\tonSelect,\n\tnumberOfMonths = 1,\n\tlocale = enUS,\n\ttimeZone,\n\t...props\n}: DateCalendarProps ) => {\n\tconst localizationProps = useLocalizationProps( {\n\t\tlocale,\n\t\ttimeZone,\n\t\tmode: 'single',\n\t} );\n\n\tconst onChange: OnSelectHandler< typeof selectedProp > = useCallback(\n\t\t( selected, triggerDate, modifiers, e ) => {\n\t\t\t// Convert internal `null` to `undefined` for the public event handler.\n\t\t\tonSelect?.( selected ?? undefined, triggerDate, modifiers, e );\n\t\t},\n\t\t[ onSelect ]\n\t);\n\n\tconst [ selected, setSelected ] = useControlledValue< typeof selectedProp >(\n\t\t{\n\t\t\tdefaultValue: defaultSelected,\n\t\t\tvalue: selectedProp,\n\t\t\tonChange,\n\t\t}\n\t);\n\n\treturn (\n\t\t<DayPicker\n\t\t\t{ ...COMMON_PROPS }\n\t\t\t{ ...localizationProps }\n\t\t\t{ ...props }\n\t\t\tmode=\"single\"\n\t\t\tnumberOfMonths={ clampNumberOfMonths( numberOfMonths ) }\n\t\t\tselected={ selected ?? undefined }\n\t\t\tonSelect={ setSelected }\n\t\t/>\n\t);\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,IAAI,QAAQ,yBAAyB;AAC9C;AACA;AACA;AACA,SAASC,WAAW,QAAQ,oBAAoB;AAChD;AACA;AACA;AACA,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,mBAAmB,QAAQ,eAAe;AACnD,SAASC,kBAAkB,QAAQ,mBAAmB;AACtD,SAASC,oBAAoB,QAAQ,iCAAiC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAGA,CAAE;EAC7BC,eAAe;EACfC,QAAQ,EAAEC,YAAY;EACtBC,QAAQ;EACRC,cAAc,GAAG,CAAC;EAClBC,MAAM,GAAGd,IAAI;EACbe,QAAQ;EACR,GAAGC;AACe,CAAC,KAAM;EACzB,MA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