@ariakit/react 0.4.25 → 0.4.27

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 (319) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/cjs/__chunks/2HXQHKBC.cjs +59 -0
  3. package/cjs/__chunks/2MDC3Z3V.cjs +43 -0
  4. package/cjs/__chunks/334WKW6I.cjs +19 -0
  5. package/cjs/__chunks/34UJGLOZ.cjs +236 -0
  6. package/cjs/__chunks/3FIXGHZ2.cjs +59 -0
  7. package/cjs/__chunks/4RKQMGBK.cjs +1179 -0
  8. package/cjs/__chunks/5NTEPQ2U.cjs +148 -0
  9. package/cjs/__chunks/66G6K4UR.cjs +1 -0
  10. package/cjs/__chunks/6GNM57O7.cjs +1 -0
  11. package/cjs/__chunks/7M4GY5DS.cjs +255 -0
  12. package/cjs/__chunks/7MXJT4IN.cjs +17 -0
  13. package/cjs/__chunks/7POA4244.cjs +184 -0
  14. package/cjs/__chunks/ASOIXRUN.cjs +305 -0
  15. package/cjs/__chunks/C4NVIV6V.cjs +455 -0
  16. package/cjs/__chunks/CR6AS7WL.cjs +1 -0
  17. package/cjs/__chunks/D4HCGWOU.cjs +464 -0
  18. package/cjs/__chunks/DVWS2XPY.cjs +107 -0
  19. package/cjs/__chunks/DWSXHZYM.cjs +20 -0
  20. package/cjs/__chunks/E6EV2Q5P.cjs +1 -0
  21. package/cjs/__chunks/FELYQPO5.cjs +1025 -0
  22. package/cjs/__chunks/FHQ5DVYQ.cjs +34 -0
  23. package/cjs/__chunks/FIPBE5IX.cjs +23 -0
  24. package/cjs/__chunks/FVIS5BFZ.cjs +41 -0
  25. package/cjs/__chunks/GUB6WHB6.cjs +51 -0
  26. package/cjs/__chunks/GUY4MKX2.cjs +56 -0
  27. package/cjs/__chunks/IF5DZKAR.cjs +1 -0
  28. package/cjs/__chunks/IFZV5LA3.cjs +94 -0
  29. package/cjs/__chunks/IHVFJGGN.cjs +32 -0
  30. package/cjs/__chunks/L2IFVMDU.cjs +96 -0
  31. package/cjs/__chunks/LCX235VJ.cjs +53 -0
  32. package/cjs/__chunks/LMCBLO3G.cjs +42 -0
  33. package/cjs/__chunks/LS5VO6AA.cjs +44 -0
  34. package/cjs/__chunks/LVHC4DSB.cjs +117 -0
  35. package/cjs/__chunks/MN5TONXW.cjs +123 -0
  36. package/cjs/__chunks/N3DLR7OL.cjs +34 -0
  37. package/cjs/__chunks/NFZWL7LE.cjs +24 -0
  38. package/cjs/__chunks/NG34QRI6.cjs +264 -0
  39. package/cjs/__chunks/NIOJG7C4.cjs +1 -0
  40. package/cjs/__chunks/NMUCJYMR.cjs +496 -0
  41. package/cjs/__chunks/OOFUBC32.cjs +109 -0
  42. package/cjs/__chunks/OQRQJNBU.cjs +1 -0
  43. package/cjs/__chunks/PDPE2VAZ.cjs +1035 -0
  44. package/cjs/__chunks/PTE2IJM5.cjs +143 -0
  45. package/cjs/__chunks/PU63IQFD.cjs +447 -0
  46. package/cjs/__chunks/PZXRBFZF.cjs +38 -0
  47. package/cjs/__chunks/QAUJZR6Y.cjs +996 -0
  48. package/cjs/__chunks/QYDAT3QF.cjs +1 -0
  49. package/cjs/__chunks/QYLMYWKV.cjs +1 -0
  50. package/cjs/__chunks/RGH2H3WL.cjs +34 -0
  51. package/cjs/__chunks/RLKC7JVT.cjs +19 -0
  52. package/cjs/__chunks/RR46KI45.cjs +17 -0
  53. package/cjs/__chunks/RVXPEX7O.cjs +150 -0
  54. package/cjs/__chunks/RXZPZPJX.cjs +95 -0
  55. package/cjs/__chunks/SIF7IN4L.cjs +62 -0
  56. package/cjs/__chunks/SQ72MZ63.cjs +294 -0
  57. package/cjs/__chunks/SXAPGTJ4.cjs +23 -0
  58. package/cjs/__chunks/TLUFYZC7.cjs +37 -0
  59. package/cjs/__chunks/TSBEWPNT.cjs +1922 -0
  60. package/cjs/__chunks/U2UYQT45.cjs +1 -0
  61. package/cjs/__chunks/UUEFM3TG.cjs +75 -0
  62. package/cjs/__chunks/UV7CXZEM.cjs +36 -0
  63. package/cjs/__chunks/VXDLN5CP.cjs +234 -0
  64. package/cjs/__chunks/VXUZM542.cjs +789 -0
  65. package/cjs/__chunks/W27WRDUB.cjs +1 -0
  66. package/cjs/__chunks/X4U3XKYQ.cjs +7 -0
  67. package/cjs/__chunks/XH4GE3VE.cjs +29 -0
  68. package/cjs/__chunks/XPQIHUQ7.cjs +172 -0
  69. package/cjs/__chunks/YEXJT4IL.cjs +55 -0
  70. package/cjs/__chunks/Z5PDS46M.cjs +975 -0
  71. package/cjs/__chunks/ZNW2LLWJ.cjs +108 -0
  72. package/cjs/__chunks/ZYPARRXG.cjs +19 -0
  73. package/cjs/button.cjs +7 -3
  74. package/cjs/button.d.cts +2 -2
  75. package/cjs/button.d.ts +2 -2
  76. package/cjs/checkbox.cjs +11 -2
  77. package/cjs/checkbox.d.cts +9 -9
  78. package/cjs/checkbox.d.ts +9 -9
  79. package/cjs/collection.cjs +8 -2
  80. package/cjs/collection.d.cts +9 -9
  81. package/cjs/collection.d.ts +9 -9
  82. package/cjs/combobox.cjs +33 -2
  83. package/cjs/combobox.d.cts +33 -33
  84. package/cjs/combobox.d.ts +33 -33
  85. package/cjs/command.cjs +6 -3
  86. package/cjs/command.d.cts +2 -2
  87. package/cjs/command.d.ts +2 -2
  88. package/cjs/composite.cjs +24 -2
  89. package/cjs/composite.d.cts +21 -21
  90. package/cjs/composite.d.ts +21 -21
  91. package/cjs/dialog.cjs +24 -2
  92. package/cjs/dialog.d.cts +15 -15
  93. package/cjs/dialog.d.ts +15 -15
  94. package/cjs/disclosure.cjs +11 -2
  95. package/cjs/disclosure.d.cts +9 -9
  96. package/cjs/disclosure.d.ts +9 -9
  97. package/cjs/focus-trap.cjs +6 -2
  98. package/cjs/focus-trap.d.cts +4 -4
  99. package/cjs/focus-trap.d.ts +4 -4
  100. package/cjs/focusable.cjs +5 -3
  101. package/cjs/focusable.d.cts +2 -2
  102. package/cjs/focusable.d.ts +2 -2
  103. package/cjs/form.cjs +15 -2
  104. package/cjs/form.d.cts +37 -37
  105. package/cjs/form.d.ts +37 -37
  106. package/cjs/group.cjs +5 -3
  107. package/cjs/group.d.cts +4 -4
  108. package/cjs/group.d.ts +4 -4
  109. package/cjs/heading.cjs +7 -3
  110. package/cjs/heading.d.cts +4 -4
  111. package/cjs/heading.d.ts +4 -4
  112. package/cjs/hovercard.cjs +28 -2
  113. package/cjs/hovercard.d.cts +19 -19
  114. package/cjs/hovercard.d.ts +19 -19
  115. package/cjs/index.cjs +103 -28
  116. package/cjs/menu.cjs +44 -2
  117. package/cjs/menu.d.cts +41 -41
  118. package/cjs/menu.d.ts +41 -41
  119. package/cjs/menubar.cjs +10 -3
  120. package/cjs/menubar.d.cts +7 -7
  121. package/cjs/menubar.d.ts +7 -7
  122. package/cjs/popover.cjs +33 -2
  123. package/cjs/popover.d.cts +21 -21
  124. package/cjs/popover.d.ts +21 -21
  125. package/cjs/portal.cjs +7 -3
  126. package/cjs/portal.d.cts +3 -3
  127. package/cjs/portal.d.ts +3 -3
  128. package/cjs/radio.cjs +13 -2
  129. package/cjs/radio.d.cts +9 -9
  130. package/cjs/radio.d.ts +9 -9
  131. package/cjs/role.cjs +5 -3
  132. package/cjs/role.d.cts +2 -2
  133. package/cjs/role.d.ts +2 -2
  134. package/cjs/select.cjs +39 -2
  135. package/cjs/select.d.cts +33 -33
  136. package/cjs/select.d.ts +33 -33
  137. package/cjs/separator.cjs +5 -3
  138. package/cjs/separator.d.cts +2 -2
  139. package/cjs/separator.d.ts +2 -2
  140. package/cjs/store.cjs +5 -3
  141. package/cjs/store.d.cts +1 -1
  142. package/cjs/store.d.ts +1 -1
  143. package/cjs/tab.cjs +15 -2
  144. package/cjs/tab.d.cts +11 -11
  145. package/cjs/tab.d.ts +11 -11
  146. package/cjs/toolbar.cjs +13 -2
  147. package/cjs/toolbar.d.cts +15 -15
  148. package/cjs/toolbar.d.ts +15 -15
  149. package/cjs/tooltip.cjs +16 -2
  150. package/cjs/tooltip.d.cts +11 -11
  151. package/cjs/tooltip.d.ts +11 -11
  152. package/cjs/visually-hidden.cjs +5 -3
  153. package/cjs/visually-hidden.d.cts +2 -2
  154. package/cjs/visually-hidden.d.ts +2 -2
  155. package/esm/__chunks/2RKMXQTW.js +10 -0
  156. package/esm/__chunks/3Y4V2DTP.js +8 -0
  157. package/esm/__chunks/5FGJT4YF.js +10 -0
  158. package/esm/__chunks/ASWYYI35.js +26 -0
  159. package/esm/__chunks/BCX2X2B5.js +40 -0
  160. package/esm/__chunks/BLUBZ7NO.js +28 -0
  161. package/esm/__chunks/CKEWLSMJ.js +8 -0
  162. package/esm/__chunks/CSCX5ZBZ.js +40 -0
  163. package/esm/__chunks/CTJDBGJU.js +18 -0
  164. package/esm/__chunks/DAO5N24L.js +16 -0
  165. package/esm/__chunks/E3G6CWS6.js +16 -0
  166. package/esm/__chunks/IVVNCX6W.js +16 -0
  167. package/esm/__chunks/LQB76ROL.js +16 -0
  168. package/esm/__chunks/MALDUIAO.js +28 -0
  169. package/esm/__chunks/MP5ILXF3.js +14 -0
  170. package/esm/__chunks/O3FPWSHV.js +10 -0
  171. package/esm/__chunks/OKEWM6H4.js +10 -0
  172. package/esm/__chunks/QL3WKMBE.js +8 -0
  173. package/esm/__chunks/RD2DI27Y.js +44 -0
  174. package/esm/__chunks/SB7MN4B3.js +22 -0
  175. package/esm/__chunks/UA4GRLAL.js +52 -0
  176. package/esm/__chunks/UBB5N3OM.js +22 -0
  177. package/esm/__chunks/WC6KFHZH.js +8 -0
  178. package/esm/__chunks/WFREFNZD.js +8 -0
  179. package/esm/__chunks/WH35KJXV.js +8 -0
  180. package/esm/__chunks/WQKZESWL.js +18 -0
  181. package/esm/__chunks/YAS6EMRP.js +8 -0
  182. package/esm/button.d.ts +2 -2
  183. package/esm/button.js +1 -1
  184. package/esm/checkbox.d.ts +9 -9
  185. package/esm/checkbox.js +1 -1
  186. package/esm/collection.d.ts +9 -9
  187. package/esm/collection.js +1 -1
  188. package/esm/combobox.d.ts +33 -33
  189. package/esm/combobox.js +1 -1
  190. package/esm/command.d.ts +2 -2
  191. package/esm/command.js +1 -1
  192. package/esm/composite.d.ts +21 -21
  193. package/esm/composite.js +1 -1
  194. package/esm/dialog.d.ts +15 -15
  195. package/esm/dialog.js +1 -1
  196. package/esm/disclosure.d.ts +9 -9
  197. package/esm/disclosure.js +1 -1
  198. package/esm/focus-trap.d.ts +4 -4
  199. package/esm/focus-trap.js +1 -1
  200. package/esm/focusable.d.ts +2 -2
  201. package/esm/focusable.js +1 -1
  202. package/esm/form.d.ts +37 -37
  203. package/esm/form.js +1 -1
  204. package/esm/group.d.ts +4 -4
  205. package/esm/group.js +1 -1
  206. package/esm/heading.d.ts +4 -4
  207. package/esm/heading.js +1 -1
  208. package/esm/hovercard.d.ts +19 -19
  209. package/esm/hovercard.js +1 -1
  210. package/esm/index.js +27 -27
  211. package/esm/menu.d.ts +41 -41
  212. package/esm/menu.js +1 -1
  213. package/esm/menubar.d.ts +7 -7
  214. package/esm/menubar.js +1 -1
  215. package/esm/popover.d.ts +21 -21
  216. package/esm/popover.js +1 -1
  217. package/esm/portal.d.ts +3 -3
  218. package/esm/portal.js +1 -1
  219. package/esm/radio.d.ts +9 -9
  220. package/esm/radio.js +1 -1
  221. package/esm/role.d.ts +2 -2
  222. package/esm/role.js +1 -1
  223. package/esm/select.d.ts +33 -33
  224. package/esm/select.js +1 -1
  225. package/esm/separator.d.ts +2 -2
  226. package/esm/separator.js +1 -1
  227. package/esm/store.d.ts +1 -1
  228. package/esm/store.js +1 -1
  229. package/esm/tab.d.ts +11 -11
  230. package/esm/tab.js +1 -1
  231. package/esm/toolbar.d.ts +15 -15
  232. package/esm/toolbar.js +1 -1
  233. package/esm/tooltip.d.ts +11 -11
  234. package/esm/tooltip.js +1 -1
  235. package/esm/visually-hidden.d.ts +2 -2
  236. package/esm/visually-hidden.js +1 -1
  237. package/package.json +2 -2
  238. package/src/button.ts +5 -0
  239. package/src/checkbox.ts +19 -0
  240. package/src/collection.ts +19 -0
  241. package/src/combobox.ts +76 -0
  242. package/src/command.ts +5 -0
  243. package/src/composite.ts +49 -0
  244. package/src/dialog.ts +34 -0
  245. package/src/disclosure.ts +19 -0
  246. package/src/focus-trap.ts +11 -0
  247. package/src/focusable.ts +5 -0
  248. package/src/form.ts +90 -0
  249. package/src/group.ts +10 -0
  250. package/src/heading.ts +7 -0
  251. package/src/hovercard.ts +44 -0
  252. package/src/index.ts +27 -0
  253. package/src/menu.ts +100 -0
  254. package/src/menubar.ts +14 -0
  255. package/src/popover.ts +49 -0
  256. package/src/portal.ts +6 -0
  257. package/src/radio.ts +19 -0
  258. package/src/role.ts +5 -0
  259. package/src/select.ts +76 -0
  260. package/src/separator.ts +5 -0
  261. package/src/store.ts +1 -0
  262. package/src/tab.ts +21 -0
  263. package/src/toolbar.ts +34 -0
  264. package/src/tooltip.ts +24 -0
  265. package/src/visually-hidden.ts +5 -0
  266. package/cjs/__chunks/24MX6KII.cjs +0 -14
  267. package/cjs/__chunks/2IFRJ7YS.cjs +0 -6
  268. package/cjs/__chunks/32YVOHOP.cjs +0 -50
  269. package/cjs/__chunks/4BAIAF3U.cjs +0 -14
  270. package/cjs/__chunks/4J2CIZDN.cjs +0 -14
  271. package/cjs/__chunks/4TTUYQMJ.cjs +0 -20
  272. package/cjs/__chunks/6QAXTQNM.cjs +0 -16
  273. package/cjs/__chunks/6WNPYLAU.cjs +0 -6
  274. package/cjs/__chunks/A2CP2RQF.cjs +0 -24
  275. package/cjs/__chunks/AEV4Y6LH.cjs +0 -8
  276. package/cjs/__chunks/APHGV4DJ.cjs +0 -6
  277. package/cjs/__chunks/B34XK6WF.cjs +0 -8
  278. package/cjs/__chunks/BFD7ZBIV.cjs +0 -26
  279. package/cjs/__chunks/CZIDOP5N.cjs +0 -38
  280. package/cjs/__chunks/ETUDK33Z.cjs +0 -26
  281. package/cjs/__chunks/GJC4LCYO.cjs +0 -16
  282. package/cjs/__chunks/KGVA5X7R.cjs +0 -38
  283. package/cjs/__chunks/LAX4QA6C.cjs +0 -42
  284. package/cjs/__chunks/MDOKA7B5.cjs +0 -6
  285. package/cjs/__chunks/Q2GGGIV7.cjs +0 -6
  286. package/cjs/__chunks/QKCQWENM.cjs +0 -6
  287. package/cjs/__chunks/QPSUJCLN.cjs +0 -12
  288. package/cjs/__chunks/TDX6HS73.cjs +0 -8
  289. package/cjs/__chunks/UPMOBIQ3.cjs +0 -20
  290. package/cjs/__chunks/W6XMZ4GT.cjs +0 -14
  291. package/cjs/__chunks/WXEUE6MJ.cjs +0 -6
  292. package/cjs/__chunks/XTZIX6PF.cjs +0 -8
  293. package/esm/__chunks/3IMSX6M3.js +0 -8
  294. package/esm/__chunks/4H6IIOQF.js +0 -22
  295. package/esm/__chunks/5OF2JM6T.js +0 -16
  296. package/esm/__chunks/6FL2IFMJ.js +0 -16
  297. package/esm/__chunks/6N4GEF7O.js +0 -18
  298. package/esm/__chunks/6OHDLPN7.js +0 -8
  299. package/esm/__chunks/7FQAKYJR.js +0 -26
  300. package/esm/__chunks/AJMZU3YP.js +0 -28
  301. package/esm/__chunks/DZPSY7QT.js +0 -22
  302. package/esm/__chunks/H2GJECQG.js +0 -8
  303. package/esm/__chunks/JBAWBCWC.js +0 -8
  304. package/esm/__chunks/LI3X5M2M.js +0 -8
  305. package/esm/__chunks/NV5BVS3O.js +0 -8
  306. package/esm/__chunks/PGIWSRTG.js +0 -28
  307. package/esm/__chunks/PRYHFEBA.js +0 -10
  308. package/esm/__chunks/UTW5KHW6.js +0 -16
  309. package/esm/__chunks/VGHCPDMA.js +0 -8
  310. package/esm/__chunks/VHD2YK6B.js +0 -18
  311. package/esm/__chunks/WA3BE3AY.js +0 -10
  312. package/esm/__chunks/XHSNLTYJ.js +0 -10
  313. package/esm/__chunks/XIMRDTWX.js +0 -14
  314. package/esm/__chunks/YQF2RGHD.js +0 -44
  315. package/esm/__chunks/ZDPYYVJP.js +0 -40
  316. package/esm/__chunks/ZFJPKQV6.js +0 -52
  317. package/esm/__chunks/ZL4AJIDL.js +0 -10
  318. package/esm/__chunks/ZQSDMYJA.js +0 -16
  319. package/esm/__chunks/ZVIXWGHS.js +0 -40
@@ -0,0 +1,975 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _5NTEPQ2Ucjs = require('./5NTEPQ2U.cjs');
4
+
5
+
6
+
7
+ var _7POA4244cjs = require('./7POA4244.cjs');
8
+
9
+
10
+ var _L2IFVMDUcjs = require('./L2IFVMDU.cjs');
11
+
12
+
13
+
14
+ var _SIF7IN4Lcjs = require('./SIF7IN4L.cjs');
15
+
16
+
17
+ var _GUB6WHB6cjs = require('./GUB6WHB6.cjs');
18
+
19
+
20
+
21
+
22
+
23
+ var _XPQIHUQ7cjs = require('./XPQIHUQ7.cjs');
24
+
25
+
26
+ var _LMCBLO3Gcjs = require('./LMCBLO3G.cjs');
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ var _D4HCGWOUcjs = require('./D4HCGWOU.cjs');
37
+
38
+
39
+ var _NG34QRI6cjs = require('./NG34QRI6.cjs');
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+ var _QAUJZR6Ycjs = require('./QAUJZR6Y.cjs');
64
+
65
+ // ../ariakit-react-components/dist/form/form-context.js
66
+ var ctx = _QAUJZR6Ycjs.createStoreContext.call(void 0, [_XPQIHUQ7cjs.CollectionContextProvider], [_XPQIHUQ7cjs.CollectionScopedContextProvider]);
67
+ var useFormContext = ctx.useContext;
68
+ var useFormScopedContext = ctx.useScopedContext;
69
+ var useFormProviderContext = ctx.useProviderContext;
70
+ var FormContextProvider = ctx.ContextProvider;
71
+ var FormScopedContextProvider = ctx.ScopedContextProvider;
72
+
73
+ // ../ariakit-react-components/dist/form/form.js
74
+ var _react = require('react');
75
+ var _jsxruntime = require('react/jsx-runtime');
76
+ var TagName = "form";
77
+ function isField(element, items) {
78
+ return items.some((item) => item.type === "field" && item.element === element);
79
+ }
80
+ function getFirstInvalidField(items) {
81
+ return items.find((item) => {
82
+ var _a;
83
+ return item.type === "field" && ((_a = item.element) == null ? void 0 : _a.getAttribute("aria-invalid")) === "true";
84
+ });
85
+ }
86
+ var useForm = _QAUJZR6Ycjs.createHook.call(void 0, function useForm2({ store, validateOnChange = true, validateOnBlur = true, resetOnUnmount = false, resetOnSubmit = true, autoFocusOnSubmit = true, ...props }) {
87
+ const context = useFormContext();
88
+ store = store || context;
89
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "Form must receive a `store` prop or be wrapped in a FormProvider component.");
90
+ const ref = _react.useRef.call(void 0, null);
91
+ const values = _D4HCGWOUcjs.useStoreState.call(void 0, store, "values");
92
+ const submitSucceed = _D4HCGWOUcjs.useStoreState.call(void 0, store, "submitSucceed");
93
+ const submitFailed = _D4HCGWOUcjs.useStoreState.call(void 0, store, "submitFailed");
94
+ const items = _D4HCGWOUcjs.useStoreState.call(void 0, store, "items");
95
+ const defaultValues = _QAUJZR6Ycjs.useInitialValue.call(void 0, values);
96
+ _react.useEffect.call(void 0, () => resetOnUnmount ? store == null ? void 0 : store.reset : void 0, [resetOnUnmount, store]);
97
+ _QAUJZR6Ycjs.useUpdateEffect.call(void 0, () => {
98
+ if (!validateOnChange) return;
99
+ if (values === defaultValues) return;
100
+ store == null ? void 0 : store.validate();
101
+ }, [
102
+ validateOnChange,
103
+ values,
104
+ defaultValues,
105
+ store
106
+ ]);
107
+ _react.useEffect.call(void 0, () => {
108
+ if (!resetOnSubmit) return;
109
+ if (!submitSucceed) return;
110
+ store == null ? void 0 : store.reset();
111
+ }, [
112
+ resetOnSubmit,
113
+ submitSucceed,
114
+ store
115
+ ]);
116
+ const [shouldFocusOnSubmit, setShouldFocusOnSubmit] = _react.useState.call(void 0, false);
117
+ _react.useEffect.call(void 0, () => {
118
+ var _a;
119
+ if (!shouldFocusOnSubmit) return;
120
+ if (!submitFailed) return;
121
+ const element = (_a = getFirstInvalidField(items)) == null ? void 0 : _a.element;
122
+ if (!element) return;
123
+ setShouldFocusOnSubmit(false);
124
+ element.focus();
125
+ if (_QAUJZR6Ycjs.isTextField.call(void 0, element)) element.select();
126
+ }, [
127
+ autoFocusOnSubmit,
128
+ submitFailed,
129
+ items
130
+ ]);
131
+ const onSubmitProp = props.onSubmit;
132
+ const onSubmit = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
133
+ onSubmitProp == null ? void 0 : onSubmitProp(event);
134
+ if (event.defaultPrevented) return;
135
+ event.preventDefault();
136
+ store == null ? void 0 : store.submit();
137
+ if (!autoFocusOnSubmit) return;
138
+ setShouldFocusOnSubmit(true);
139
+ });
140
+ const onBlurProp = props.onBlur;
141
+ const onBlur = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
142
+ onBlurProp == null ? void 0 : onBlurProp(event);
143
+ if (event.defaultPrevented) return;
144
+ if (!validateOnBlur) return;
145
+ if (!store) return;
146
+ if (!isField(event.target, store.getState().items)) return;
147
+ store.validate();
148
+ });
149
+ const onResetProp = props.onReset;
150
+ const onReset = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
151
+ onResetProp == null ? void 0 : onResetProp(event);
152
+ if (event.defaultPrevented) return;
153
+ event.preventDefault();
154
+ store == null ? void 0 : store.reset();
155
+ });
156
+ props = _QAUJZR6Ycjs.useWrapElement.call(void 0, props, (element) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FormScopedContextProvider, {
157
+ value: store,
158
+ children: element
159
+ }), [store]);
160
+ props = {
161
+ role: _QAUJZR6Ycjs.useTagName.call(void 0, ref, TagName) !== "form" ? "form" : void 0,
162
+ noValidate: true,
163
+ ...props,
164
+ ref: _QAUJZR6Ycjs.useMergeRefs.call(void 0, ref, props.ref),
165
+ onSubmit,
166
+ onBlur,
167
+ onReset
168
+ };
169
+ return props;
170
+ });
171
+ var Form = _QAUJZR6Ycjs.forwardRef.call(void 0, function Form2(props) {
172
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName, useForm(props));
173
+ });
174
+
175
+ // ../ariakit-react-components/dist/form/form-control.js
176
+
177
+ var TagName2 = "input";
178
+ function getNamedElement(ref, name) {
179
+ const element = ref.current;
180
+ if (!element) return null;
181
+ if (element.name === name) return element;
182
+ if (element.form) return element.form.elements.namedItem(name);
183
+ return _QAUJZR6Ycjs.getDocument.call(void 0, element).getElementsByName(name)[0];
184
+ }
185
+ function useItem(store, name, type) {
186
+ return _D4HCGWOUcjs.useStoreState.call(void 0, store, (state) => state.items.find((item) => item.type === type && item.name === name));
187
+ }
188
+ var useFormControl = _QAUJZR6Ycjs.createHook.call(void 0, function useFormControl2({ store, name: nameProp, getItem: getItemProp, touchOnBlur = true, ...props }) {
189
+ const context = useFormContext();
190
+ store = store || context;
191
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormControl must be wrapped in a Form component.");
192
+ const name = String(nameProp);
193
+ const id = _QAUJZR6Ycjs.useId.call(void 0, props.id);
194
+ const ref = _react.useRef.call(void 0, null);
195
+ store.useValidate(async () => {
196
+ const element = getNamedElement(ref, name);
197
+ if (!element) return;
198
+ await Promise.resolve();
199
+ if ("validity" in element && !element.validity.valid) store == null ? void 0 : store.setError(name, element.validationMessage);
200
+ });
201
+ const getItem = _react.useCallback.call(void 0, (item) => {
202
+ const nextItem = {
203
+ ...item,
204
+ id: id || item.id,
205
+ name,
206
+ type: "field"
207
+ };
208
+ if (getItemProp) return getItemProp(nextItem);
209
+ return nextItem;
210
+ }, [
211
+ id,
212
+ name,
213
+ getItemProp
214
+ ]);
215
+ const onBlurProp = props.onBlur;
216
+ const touchOnBlurProp = _QAUJZR6Ycjs.useBooleanEvent.call(void 0, touchOnBlur);
217
+ const onBlur = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
218
+ onBlurProp == null ? void 0 : onBlurProp(event);
219
+ if (event.defaultPrevented) return;
220
+ if (!touchOnBlurProp(event)) return;
221
+ store == null ? void 0 : store.setFieldTouched(name, true);
222
+ });
223
+ const label = useItem(store, name, "label");
224
+ const error = useItem(store, name, "error");
225
+ const description = useItem(store, name, "description");
226
+ const describedBy = _QAUJZR6Ycjs.cx.call(void 0, error == null ? void 0 : error.id, description == null ? void 0 : description.id, props["aria-describedby"]);
227
+ const invalid = _D4HCGWOUcjs.useStoreState.call(void 0, store, () => !!(store == null ? void 0 : store.getError(name)) && store.getFieldTouched(name));
228
+ props = {
229
+ "aria-labelledby": props["aria-label"] != null ? void 0 : label == null ? void 0 : label.id,
230
+ "aria-invalid": invalid,
231
+ ...props,
232
+ id,
233
+ "aria-describedby": describedBy || void 0,
234
+ ref: _QAUJZR6Ycjs.useMergeRefs.call(void 0, ref, props.ref),
235
+ onBlur
236
+ };
237
+ props = _GUB6WHB6cjs.useCollectionItem.call(void 0, {
238
+ store,
239
+ ...props,
240
+ name,
241
+ getItem
242
+ });
243
+ return props;
244
+ });
245
+ var FormControl = _QAUJZR6Ycjs.memo.call(void 0, _QAUJZR6Ycjs.forwardRef.call(void 0, function FormControl2(props) {
246
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName2, useFormControl(props));
247
+ }));
248
+
249
+ // ../ariakit-react-components/dist/form/form-checkbox.js
250
+ var TagName3 = "input";
251
+ var useFormCheckbox = _QAUJZR6Ycjs.createHook.call(void 0, function useFormCheckbox2({ store, name: nameProp, value, checked, defaultChecked, ...props }) {
252
+ const context = useFormContext();
253
+ store = store || context;
254
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormCheckbox must be wrapped in a Form component.");
255
+ const name = String(nameProp);
256
+ props = _7POA4244cjs.useCheckbox.call(void 0, {
257
+ store: _7POA4244cjs.useCheckboxStore.call(void 0, {
258
+ value: store.useValue(name),
259
+ setValue: (value2) => store == null ? void 0 : store.setValue(name, value2)
260
+ }),
261
+ value,
262
+ checked,
263
+ ...props
264
+ });
265
+ props = useFormControl({
266
+ store,
267
+ name,
268
+ "aria-labelledby": void 0,
269
+ ...props
270
+ });
271
+ return props;
272
+ });
273
+ var FormCheckbox = _QAUJZR6Ycjs.memo.call(void 0, _QAUJZR6Ycjs.forwardRef.call(void 0, function FormCheckbox2(props) {
274
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName3, useFormCheckbox(props));
275
+ }));
276
+
277
+ // ../ariakit-react-components/dist/form/form-description.js
278
+
279
+ var TagName4 = "div";
280
+ var useFormDescription = _QAUJZR6Ycjs.createHook.call(void 0, function useFormDescription2({ store, name: nameProp, getItem: getItemProp, ...props }) {
281
+ const context = useFormContext();
282
+ store = store || context;
283
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormDescription must be wrapped in a Form component.");
284
+ const id = _QAUJZR6Ycjs.useId.call(void 0, props.id);
285
+ const ref = _react.useRef.call(void 0, null);
286
+ const name = String(nameProp);
287
+ const getItem = _react.useCallback.call(void 0, (item) => {
288
+ const nextItem = {
289
+ ...item,
290
+ id: id || item.id,
291
+ name,
292
+ type: "description"
293
+ };
294
+ if (getItemProp) return getItemProp(nextItem);
295
+ return nextItem;
296
+ }, [
297
+ id,
298
+ name,
299
+ getItemProp
300
+ ]);
301
+ props = {
302
+ ...props,
303
+ id,
304
+ ref: _QAUJZR6Ycjs.useMergeRefs.call(void 0, ref, props.ref)
305
+ };
306
+ props = _GUB6WHB6cjs.useCollectionItem.call(void 0, {
307
+ store,
308
+ ...props,
309
+ getItem
310
+ });
311
+ return props;
312
+ });
313
+ var FormDescription = _QAUJZR6Ycjs.memo.call(void 0, _QAUJZR6Ycjs.forwardRef.call(void 0, function FormDescription2(props) {
314
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName4, useFormDescription(props));
315
+ }));
316
+
317
+ // ../ariakit-react-components/dist/form/form-error.js
318
+
319
+ var TagName5 = "div";
320
+ var useFormError = _QAUJZR6Ycjs.createHook.call(void 0, function useFormError2({ store, name: nameProp, getItem: getItemProp, ...props }) {
321
+ const context = useFormContext();
322
+ store = store || context;
323
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormError must be wrapped in a Form component.");
324
+ const id = _QAUJZR6Ycjs.useId.call(void 0, props.id);
325
+ const ref = _react.useRef.call(void 0, null);
326
+ const name = String(nameProp);
327
+ const getItem = _react.useCallback.call(void 0, (item) => {
328
+ const nextItem = {
329
+ ...item,
330
+ id: id || item.id,
331
+ name,
332
+ type: "error"
333
+ };
334
+ if (getItemProp) return getItemProp(nextItem);
335
+ return nextItem;
336
+ }, [
337
+ id,
338
+ name,
339
+ getItemProp
340
+ ]);
341
+ props = {
342
+ role: "alert",
343
+ children: _D4HCGWOUcjs.useStoreState.call(void 0, store, () => {
344
+ const error = store == null ? void 0 : store.getError(name);
345
+ if (error == null) return;
346
+ if (!(store == null ? void 0 : store.getFieldTouched(name))) return;
347
+ return error;
348
+ }),
349
+ ...props,
350
+ id,
351
+ ref: _QAUJZR6Ycjs.useMergeRefs.call(void 0, ref, props.ref)
352
+ };
353
+ props = _GUB6WHB6cjs.useCollectionItem.call(void 0, {
354
+ store,
355
+ ...props,
356
+ getItem
357
+ });
358
+ return props;
359
+ });
360
+ var FormError = _QAUJZR6Ycjs.memo.call(void 0, _QAUJZR6Ycjs.forwardRef.call(void 0, function FormError2(props) {
361
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName5, useFormError(props));
362
+ }));
363
+
364
+ // ../ariakit-react-components/dist/form/form-field.js
365
+ var TagName6 = "input";
366
+ var useFormField = _QAUJZR6Ycjs.createHook.call(void 0, function useFormField2(props) {
367
+ return useFormControl(props);
368
+ });
369
+ var FormField = _QAUJZR6Ycjs.memo.call(void 0, _QAUJZR6Ycjs.forwardRef.call(void 0, function FormField2(props) {
370
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName6, useFormField(props));
371
+ }));
372
+
373
+ // ../ariakit-react-components/dist/form/form-group.js
374
+ var TagName7 = "div";
375
+ var useFormGroup = _QAUJZR6Ycjs.createHook.call(void 0, function useFormGroup2({ store, ...props }) {
376
+ props = _SIF7IN4Lcjs.useGroup.call(void 0, props);
377
+ return props;
378
+ });
379
+ var FormGroup = _QAUJZR6Ycjs.forwardRef.call(void 0, function FormGroup2(props) {
380
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName7, useFormGroup(props));
381
+ });
382
+
383
+ // ../ariakit-react-components/dist/form/form-group-label.js
384
+ var TagName8 = "div";
385
+ var useFormGroupLabel = _QAUJZR6Ycjs.createHook.call(void 0, function useFormGroupLabel2({ store, ...props }) {
386
+ props = _SIF7IN4Lcjs.useGroupLabel.call(void 0, props);
387
+ return props;
388
+ });
389
+ var FormGroupLabel = _QAUJZR6Ycjs.forwardRef.call(void 0, function FormGroupLabel2(props) {
390
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName8, useFormGroupLabel(props));
391
+ });
392
+
393
+ // ../ariakit-react-components/dist/form/form-input.js
394
+ var TagName9 = "input";
395
+ var useFormInput = _QAUJZR6Ycjs.createHook.call(void 0, function useFormInput2({ store, name: nameProp, ...props }) {
396
+ const context = useFormContext();
397
+ store = store || context;
398
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormInput must be wrapped in a Form component.");
399
+ const name = String(nameProp);
400
+ const onChangeProp = props.onChange;
401
+ const onChange = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
402
+ onChangeProp == null ? void 0 : onChangeProp(event);
403
+ if (event.defaultPrevented) return;
404
+ store == null ? void 0 : store.setValue(name, event.target.value);
405
+ });
406
+ props = {
407
+ value: store.useValue(name),
408
+ ...props,
409
+ onChange
410
+ };
411
+ props = _NG34QRI6cjs.useFocusable.call(void 0, props);
412
+ props = useFormControl({
413
+ store,
414
+ name,
415
+ ...props
416
+ });
417
+ return props;
418
+ });
419
+ var FormInput = _QAUJZR6Ycjs.memo.call(void 0, _QAUJZR6Ycjs.forwardRef.call(void 0, function FormInput2(props) {
420
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName9, useFormInput(props));
421
+ }));
422
+
423
+ // ../ariakit-react-components/dist/form/form-label.js
424
+
425
+
426
+ var TagName10 = "label";
427
+ function supportsNativeLabel(tagName) {
428
+ return tagName === "input" || tagName === "textarea" || tagName === "select" || tagName === "meter" || tagName === "progress";
429
+ }
430
+ var useFormLabel = _QAUJZR6Ycjs.createHook.call(void 0, function useFormLabel2({ store, name: nameProp, getItem: getItemProp, ...props }) {
431
+ const context = useFormContext();
432
+ store = store || context;
433
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormLabel must be wrapped in a Form component.");
434
+ const id = _QAUJZR6Ycjs.useId.call(void 0, props.id);
435
+ const ref = _react.useRef.call(void 0, null);
436
+ const name = String(nameProp);
437
+ const getItem = _react.useCallback.call(void 0, (item) => {
438
+ const nextItem = {
439
+ ...item,
440
+ id: id || item.id,
441
+ name,
442
+ type: "label"
443
+ };
444
+ if (getItemProp) return getItemProp(nextItem);
445
+ return nextItem;
446
+ }, [
447
+ id,
448
+ name,
449
+ getItemProp
450
+ ]);
451
+ const field = _D4HCGWOUcjs.useStoreState.call(void 0, store, (state) => state.items.find((item) => item.type === "field" && item.name === name));
452
+ const isNativeLabel = supportsNativeLabel(_QAUJZR6Ycjs.useTagName.call(void 0, field == null ? void 0 : field.element, "input"));
453
+ const onClickProp = props.onClick;
454
+ const onClick = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
455
+ onClickProp == null ? void 0 : onClickProp(event);
456
+ if (event.defaultPrevented) return;
457
+ if (isNativeLabel) return;
458
+ const fieldElement = field == null ? void 0 : field.element;
459
+ if (!fieldElement) return;
460
+ queueMicrotask(() => {
461
+ const focusableElement = _QAUJZR6Ycjs.getFirstTabbableIn.call(void 0, fieldElement, true, true);
462
+ focusableElement == null ? void 0 : focusableElement.focus();
463
+ if ((focusableElement == null ? void 0 : focusableElement.getAttribute("role")) === "combobox") return;
464
+ focusableElement == null ? void 0 : focusableElement.click();
465
+ });
466
+ });
467
+ props = {
468
+ render: isNativeLabel ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "label", {}) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {}),
469
+ htmlFor: isNativeLabel ? field == null ? void 0 : field.id : void 0,
470
+ ...props,
471
+ id,
472
+ ref: _QAUJZR6Ycjs.useMergeRefs.call(void 0, ref, props.ref),
473
+ onClick
474
+ };
475
+ if (!isNativeLabel) props = {
476
+ ...props,
477
+ style: {
478
+ cursor: "default",
479
+ ...props.style
480
+ }
481
+ };
482
+ props = _GUB6WHB6cjs.useCollectionItem.call(void 0, {
483
+ store,
484
+ ...props,
485
+ getItem
486
+ });
487
+ return props;
488
+ });
489
+ var FormLabel = _QAUJZR6Ycjs.memo.call(void 0, _QAUJZR6Ycjs.forwardRef.call(void 0, function FormLabel2(props) {
490
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName10, useFormLabel(props));
491
+ }));
492
+
493
+ // ../ariakit-react-components/dist/form/form-store.js
494
+
495
+
496
+ // ../ariakit-components/dist/form/form-store.js
497
+ function nextFrame() {
498
+ return new Promise((resolve) => requestAnimationFrame(() => resolve()));
499
+ }
500
+ function hasMessages(object) {
501
+ return Object.keys(object).some((key) => {
502
+ if (_QAUJZR6Ycjs.isObject.call(void 0, object[key])) return hasMessages(object[key]);
503
+ return !!object[key];
504
+ });
505
+ }
506
+ function get(values, path, defaultValue2) {
507
+ var _a;
508
+ const [key, ...rest] = Array.isArray(path) ? path : String(path).split(".");
509
+ if (key == null || !values) return defaultValue2;
510
+ if (!rest.length) return (_a = values[key]) != null ? _a : defaultValue2;
511
+ return get(values[key], rest, defaultValue2);
512
+ }
513
+ function getOrCreateNested(nestedValues, nextKey) {
514
+ if (Array.isArray(nestedValues) || _QAUJZR6Ycjs.isObject.call(void 0, nestedValues)) return nestedValues;
515
+ return _QAUJZR6Ycjs.isInteger.call(void 0, nextKey) ? [] : {};
516
+ }
517
+ function set(values, path, value) {
518
+ const [k, ...rest] = Array.isArray(path) ? path : String(path).split(".");
519
+ if (k == null) return values;
520
+ const key = k;
521
+ const isIntegerKey = _QAUJZR6Ycjs.isInteger.call(void 0, key);
522
+ const nestedValues = (isIntegerKey ? values || [] : values || {})[key];
523
+ const nextKey = rest[0];
524
+ const result = rest.length && nextKey != null ? set(getOrCreateNested(nestedValues, nextKey), rest, value) : value;
525
+ if (isIntegerKey) {
526
+ const index = Number(key);
527
+ if (values && Array.isArray(values)) {
528
+ const copy = [...values];
529
+ copy[index] = result;
530
+ return copy;
531
+ }
532
+ const nextValues = [];
533
+ nextValues[index] = result;
534
+ return nextValues;
535
+ }
536
+ return Object.assign({}, values, { [key]: result });
537
+ }
538
+ function setAll(values, value) {
539
+ const result = {};
540
+ const keys = Object.keys(values);
541
+ for (const key of keys) {
542
+ const currentValue = values[key];
543
+ if (Array.isArray(currentValue)) result[key] = currentValue.map((v) => {
544
+ if (_QAUJZR6Ycjs.isObject.call(void 0, v)) return setAll(v, value);
545
+ return value;
546
+ });
547
+ else if (_QAUJZR6Ycjs.isObject.call(void 0, currentValue)) result[key] = setAll(currentValue, value);
548
+ else result[key] = value;
549
+ }
550
+ return result;
551
+ }
552
+ function getNameHandler(cache, prevKeys = []) {
553
+ return { get(target, key) {
554
+ if ([
555
+ "toString",
556
+ "valueOf",
557
+ Symbol.toPrimitive
558
+ ].includes(key)) return () => prevKeys.join(".");
559
+ const nextKeys = [...prevKeys, key];
560
+ const nextKey = nextKeys.join(".");
561
+ if (cache[nextKey]) return cache[nextKey];
562
+ const nextProxy = new Proxy(target, getNameHandler(cache, nextKeys));
563
+ cache[nextKey] = nextProxy;
564
+ return nextProxy;
565
+ } };
566
+ }
567
+ function getStoreCallbacks(store) {
568
+ return store == null ? void 0 : store.__unstableCallbacks;
569
+ }
570
+ function createNames() {
571
+ return new Proxy(/* @__PURE__ */ Object.create(null), getNameHandler(/* @__PURE__ */ Object.create(null)));
572
+ }
573
+ function createFormStore(props = {}) {
574
+ var _a;
575
+ _D4HCGWOUcjs.throwOnConflictingProps.call(void 0, props, props.store);
576
+ const syncState = (_a = props.store) == null ? void 0 : _a.getState();
577
+ const collection = _XPQIHUQ7cjs.createCollectionStore.call(void 0, props);
578
+ const values = _QAUJZR6Ycjs.defaultValue.call(void 0, props.values, syncState == null ? void 0 : syncState.values, props.defaultValues, {});
579
+ const errors = _QAUJZR6Ycjs.defaultValue.call(void 0, props.errors, syncState == null ? void 0 : syncState.errors, props.defaultErrors, {});
580
+ const touched = _QAUJZR6Ycjs.defaultValue.call(void 0, props.touched, syncState == null ? void 0 : syncState.touched, props.defaultTouched, {});
581
+ const form = _D4HCGWOUcjs.createStore.call(void 0, {
582
+ ...collection.getState(),
583
+ values,
584
+ errors,
585
+ touched,
586
+ validating: _QAUJZR6Ycjs.defaultValue.call(void 0, syncState == null ? void 0 : syncState.validating, false),
587
+ submitting: _QAUJZR6Ycjs.defaultValue.call(void 0, syncState == null ? void 0 : syncState.submitting, false),
588
+ submitSucceed: _QAUJZR6Ycjs.defaultValue.call(void 0, syncState == null ? void 0 : syncState.submitSucceed, 0),
589
+ submitFailed: _QAUJZR6Ycjs.defaultValue.call(void 0, syncState == null ? void 0 : syncState.submitFailed, 0),
590
+ valid: !hasMessages(errors)
591
+ }, collection, props.store);
592
+ const syncCallbacks = getStoreCallbacks(props.store);
593
+ const syncCallbacksState = syncCallbacks == null ? void 0 : syncCallbacks.getState();
594
+ const callbacks = _D4HCGWOUcjs.createStore.call(void 0, {
595
+ validate: (syncCallbacksState == null ? void 0 : syncCallbacksState.validate) || [],
596
+ submit: (syncCallbacksState == null ? void 0 : syncCallbacksState.submit) || []
597
+ }, syncCallbacks);
598
+ _D4HCGWOUcjs.setup.call(void 0, form, () => _D4HCGWOUcjs.init.call(void 0, callbacks));
599
+ _D4HCGWOUcjs.setup.call(void 0, form, () => _D4HCGWOUcjs.sync.call(void 0, form, ["validating", "errors"], (state) => {
600
+ if (state.validating) return;
601
+ form.setState("valid", !hasMessages(state.errors));
602
+ }));
603
+ const validate = async () => {
604
+ form.setState("validating", true);
605
+ form.setState("errors", {});
606
+ const validateCallbacks = callbacks.getState().validate;
607
+ try {
608
+ for (const callback of validateCallbacks) await callback(form.getState());
609
+ await nextFrame();
610
+ return !hasMessages(form.getState().errors);
611
+ } finally {
612
+ form.setState("validating", false);
613
+ }
614
+ };
615
+ return {
616
+ ...collection,
617
+ ...form,
618
+ names: createNames(),
619
+ setValues: (values2) => form.setState("values", values2),
620
+ getValue: (name) => get(form.getState().values, name),
621
+ setValue: (name, value) => form.setState("values", (values2) => {
622
+ const prevValue = get(values2, name);
623
+ const nextValue = _QAUJZR6Ycjs.applyState.call(void 0, value, prevValue);
624
+ if (nextValue === prevValue) return values2;
625
+ return set(values2, name, nextValue);
626
+ }),
627
+ pushValue: (name, value) => form.setState("values", (values2) => {
628
+ return set(values2, name, [...get(values2, name, []), value]);
629
+ }),
630
+ removeValue: (name, index) => form.setState("values", (values2) => {
631
+ const array = get(values2, name, []);
632
+ return set(values2, name, [
633
+ ...array.slice(0, index),
634
+ null,
635
+ ...array.slice(index + 1)
636
+ ]);
637
+ }),
638
+ setErrors: (errors2) => form.setState("errors", errors2),
639
+ getError: (name) => get(form.getState().errors, name),
640
+ setError: (name, error) => form.setState("errors", (errors2) => {
641
+ const prevError = get(errors2, name);
642
+ const nextError = _QAUJZR6Ycjs.applyState.call(void 0, error, prevError);
643
+ if (nextError === prevError) return errors2;
644
+ return set(errors2, name, nextError);
645
+ }),
646
+ setTouched: (touched2) => form.setState("touched", touched2),
647
+ getFieldTouched: (name) => !!get(form.getState().touched, name),
648
+ setFieldTouched: (name, value) => form.setState("touched", (touched2) => {
649
+ const prevValue = get(touched2, name);
650
+ const nextValue = _QAUJZR6Ycjs.applyState.call(void 0, value, prevValue);
651
+ if (nextValue === prevValue) return touched2;
652
+ return set(touched2, name, nextValue);
653
+ }),
654
+ onValidate: (callback) => {
655
+ callbacks.setState("validate", (callbacks2) => [...callbacks2, callback]);
656
+ return () => {
657
+ callbacks.setState("validate", (callbacks2) => callbacks2.filter((c) => c !== callback));
658
+ };
659
+ },
660
+ validate,
661
+ onSubmit: (callback) => {
662
+ callbacks.setState("submit", (callbacks2) => [...callbacks2, callback]);
663
+ return () => {
664
+ callbacks.setState("submit", (callbacks2) => callbacks2.filter((c) => c !== callback));
665
+ };
666
+ },
667
+ submit: async () => {
668
+ form.setState("submitting", true);
669
+ form.setState("touched", setAll(form.getState().values, true));
670
+ try {
671
+ if (await validate()) {
672
+ const submitCallbacks = callbacks.getState().submit;
673
+ for (const callback of submitCallbacks) await callback(form.getState());
674
+ await nextFrame();
675
+ if (!hasMessages(form.getState().errors)) {
676
+ form.setState("submitSucceed", (count) => count + 1);
677
+ return true;
678
+ }
679
+ }
680
+ form.setState("submitFailed", (count) => count + 1);
681
+ return false;
682
+ } catch (error) {
683
+ form.setState("submitFailed", (count) => count + 1);
684
+ throw error;
685
+ } finally {
686
+ form.setState("submitting", false);
687
+ }
688
+ },
689
+ reset: () => {
690
+ form.setState("values", values);
691
+ form.setState("errors", errors);
692
+ form.setState("touched", touched);
693
+ form.setState("validating", false);
694
+ form.setState("submitting", false);
695
+ form.setState("submitSucceed", 0);
696
+ form.setState("submitFailed", 0);
697
+ form.setState("valid", !hasMessages(errors));
698
+ },
699
+ __unstableCallbacks: callbacks
700
+ };
701
+ }
702
+
703
+ // ../ariakit-react-components/dist/form/form-store.js
704
+ function useFormStoreProps(store, update, props) {
705
+ store = _XPQIHUQ7cjs.useCollectionStoreProps.call(void 0, store, update, props);
706
+ _D4HCGWOUcjs.useStoreProps.call(void 0, store, props, "values", "setValues");
707
+ _D4HCGWOUcjs.useStoreProps.call(void 0, store, props, "errors", "setErrors");
708
+ _D4HCGWOUcjs.useStoreProps.call(void 0, store, props, "touched", "setTouched");
709
+ const useValue = _react.useCallback.call(void 0, (name) => _D4HCGWOUcjs.useStoreState.call(void 0, store, () => store.getValue(name)), [store]);
710
+ const useValidate = _react.useCallback.call(void 0, (callback) => {
711
+ callback = _QAUJZR6Ycjs.useEvent.call(void 0, callback);
712
+ _react.useEffect.call(void 0, () => store.onValidate(callback), [_D4HCGWOUcjs.useStoreState.call(void 0, store, "items"), callback]);
713
+ }, [store]);
714
+ const useSubmit = _react.useCallback.call(void 0, (callback) => {
715
+ callback = _QAUJZR6Ycjs.useEvent.call(void 0, callback);
716
+ _react.useEffect.call(void 0, () => store.onSubmit(callback), [_D4HCGWOUcjs.useStoreState.call(void 0, store, "items"), callback]);
717
+ }, [store]);
718
+ return _react.useMemo.call(void 0, () => ({
719
+ ...store,
720
+ useValue,
721
+ useValidate,
722
+ useSubmit
723
+ }), [
724
+ store,
725
+ useValue,
726
+ useValidate,
727
+ useSubmit
728
+ ]);
729
+ }
730
+ function useFormStore(props = {}) {
731
+ const [store, update] = _D4HCGWOUcjs.useStore.call(void 0, createFormStore, props);
732
+ return useFormStoreProps(store, update, props);
733
+ }
734
+
735
+ // ../ariakit-react-components/dist/form/form-provider.js
736
+
737
+ function FormProvider(props = {}) {
738
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FormContextProvider, {
739
+ value: useFormStore(props),
740
+ children: props.children
741
+ });
742
+ }
743
+
744
+ // ../ariakit-react-components/dist/form/form-push.js
745
+
746
+ var TagName11 = "button";
747
+ function getFirstFieldsByName(items, name) {
748
+ if (!items) return [];
749
+ const fields = [];
750
+ for (const item of items) {
751
+ if (item.type !== "field") continue;
752
+ if (!item.name.startsWith(name)) continue;
753
+ const nameWithIndex = item.name.replace(/(\.\d+)\..+$/, "$1");
754
+ const regex = new RegExp(`^${nameWithIndex}`);
755
+ if (!fields.some((i) => regex.test(i.name))) fields.push(item);
756
+ }
757
+ return fields;
758
+ }
759
+ var useFormPush = _QAUJZR6Ycjs.createHook.call(void 0, function useFormPush2({ store, value, name: nameProp, getItem: getItemProp, autoFocusOnClick = true, ...props }) {
760
+ const context = useFormContext();
761
+ store = store || context;
762
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormPush must be wrapped in a Form component.");
763
+ const name = String(nameProp);
764
+ const [shouldFocus, setShouldFocus] = _react.useState.call(void 0, false);
765
+ _react.useEffect.call(void 0, () => {
766
+ var _a;
767
+ if (!shouldFocus) return;
768
+ const items = getFirstFieldsByName(store == null ? void 0 : store.getState().items, name);
769
+ const element = (_a = items == null ? void 0 : items[items.length - 1]) == null ? void 0 : _a.element;
770
+ if (!element) return;
771
+ element.focus();
772
+ setShouldFocus(false);
773
+ }, [
774
+ store,
775
+ shouldFocus,
776
+ name
777
+ ]);
778
+ const getItem = _react.useCallback.call(void 0, (item) => {
779
+ const nextItem = {
780
+ ...item,
781
+ type: "button",
782
+ name
783
+ };
784
+ if (getItemProp) return getItemProp(nextItem);
785
+ return nextItem;
786
+ }, [name, getItemProp]);
787
+ const onClickProp = props.onClick;
788
+ const onClick = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
789
+ onClickProp == null ? void 0 : onClickProp(event);
790
+ if (event.defaultPrevented) return;
791
+ store == null ? void 0 : store.pushValue(name, value);
792
+ if (!autoFocusOnClick) return;
793
+ setShouldFocus(true);
794
+ });
795
+ props = {
796
+ ...props,
797
+ onClick
798
+ };
799
+ props = _LMCBLO3Gcjs.useButton.call(void 0, props);
800
+ props = _GUB6WHB6cjs.useCollectionItem.call(void 0, {
801
+ store,
802
+ ...props,
803
+ getItem
804
+ });
805
+ return props;
806
+ });
807
+ var FormPush = _QAUJZR6Ycjs.forwardRef.call(void 0, function FormPush2(props) {
808
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName11, useFormPush(props));
809
+ });
810
+
811
+ // ../ariakit-react-components/dist/form/form-radio.js
812
+ var TagName12 = "input";
813
+ var useFormRadio = _QAUJZR6Ycjs.createHook.call(void 0, function useFormRadio2({ store, name: nameProp, value, ...props }) {
814
+ const context = useFormContext();
815
+ store = store || context;
816
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormRadio must be wrapped in a Form component.");
817
+ const name = String(nameProp);
818
+ const onChangeProp = props.onChange;
819
+ const onChange = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
820
+ onChangeProp == null ? void 0 : onChangeProp(event);
821
+ if (event.defaultPrevented) return;
822
+ store == null ? void 0 : store.setValue(name, value);
823
+ });
824
+ const checkedProp = props.checked;
825
+ const checked = _D4HCGWOUcjs.useStoreState.call(void 0, store, () => checkedProp != null ? checkedProp : (store == null ? void 0 : store.getValue(name)) === value);
826
+ props = {
827
+ ...props,
828
+ checked,
829
+ onChange
830
+ };
831
+ props = _5NTEPQ2Ucjs.useRadio.call(void 0, {
832
+ name,
833
+ value,
834
+ ...props
835
+ });
836
+ props = useFormControl({
837
+ store,
838
+ name,
839
+ "aria-labelledby": void 0,
840
+ ...props
841
+ });
842
+ return props;
843
+ });
844
+ var FormRadio = _QAUJZR6Ycjs.memo.call(void 0, _QAUJZR6Ycjs.forwardRef.call(void 0, function FormRadio2(props) {
845
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName12, useFormRadio(props));
846
+ }));
847
+
848
+ // ../ariakit-react-components/dist/form/form-radio-group.js
849
+
850
+ var TagName13 = "div";
851
+ var useFormRadioGroup = _QAUJZR6Ycjs.createHook.call(void 0, function useFormRadioGroup2({ store, ...props }) {
852
+ props = _QAUJZR6Ycjs.useWrapElement.call(void 0, props, (element) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _L2IFVMDUcjs.CompositeScopedContextProvider, {
853
+ value: void 0,
854
+ children: element
855
+ }), []);
856
+ props = {
857
+ role: "radiogroup",
858
+ ...props
859
+ };
860
+ props = useFormGroup(props);
861
+ return props;
862
+ });
863
+ var FormRadioGroup = _QAUJZR6Ycjs.forwardRef.call(void 0, function FormRadioGroup2(props) {
864
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName13, useFormRadioGroup(props));
865
+ });
866
+
867
+ // ../ariakit-react-components/dist/form/form-remove.js
868
+ var TagName14 = "button";
869
+ function findNextOrPreviousField(items, name, index) {
870
+ const fields = items == null ? void 0 : items.filter((item) => item.type === "field" && item.name.startsWith(name));
871
+ const regex = new RegExp(`^${name}\\.(\\d+)`);
872
+ const nextField = fields == null ? void 0 : fields.find((field) => {
873
+ const fieldIndex = field.name.replace(regex, "$1");
874
+ return Number.parseInt(fieldIndex, 10) > index;
875
+ });
876
+ if (nextField) return nextField;
877
+ return fields == null ? void 0 : fields.reverse().find((field) => {
878
+ const fieldIndex = field.name.replace(regex, "$1");
879
+ return Number.parseInt(fieldIndex, 10) < index;
880
+ });
881
+ }
882
+ function findPushButton(items, name) {
883
+ return items == null ? void 0 : items.find((item) => item.type === "button" && item.name === name);
884
+ }
885
+ var useFormRemove = _QAUJZR6Ycjs.createHook.call(void 0, function useFormRemove2({ store, name: nameProp, index, autoFocusOnClick = true, ...props }) {
886
+ const context = useFormContext();
887
+ store = store || context;
888
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormRemove must be wrapped in a Form component.");
889
+ const name = String(nameProp);
890
+ const onClickProp = props.onClick;
891
+ const onClick = _QAUJZR6Ycjs.useEvent.call(void 0, (event) => {
892
+ var _a, _b, _c;
893
+ onClickProp == null ? void 0 : onClickProp(event);
894
+ if (event.defaultPrevented) return;
895
+ if (!store) return;
896
+ store.removeValue(name, index);
897
+ if (!autoFocusOnClick) return;
898
+ const { items } = store.getState();
899
+ const element = (_a = findNextOrPreviousField(items, name, index)) == null ? void 0 : _a.element;
900
+ if (element) {
901
+ element.focus();
902
+ if (_QAUJZR6Ycjs.isTextField.call(void 0, element)) element.select();
903
+ } else (_c = (_b = findPushButton(items, name)) == null ? void 0 : _b.element) == null ? void 0 : _c.focus();
904
+ });
905
+ props = {
906
+ ...props,
907
+ onClick
908
+ };
909
+ props = _LMCBLO3Gcjs.useButton.call(void 0, props);
910
+ return props;
911
+ });
912
+ var FormRemove = _QAUJZR6Ycjs.forwardRef.call(void 0, function FormRemove2(props) {
913
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName14, useFormRemove(props));
914
+ });
915
+
916
+ // ../ariakit-react-components/dist/form/form-reset.js
917
+ var TagName15 = "button";
918
+ var useFormReset = _QAUJZR6Ycjs.createHook.call(void 0, function useFormReset2({ store, ...props }) {
919
+ const context = useFormContext();
920
+ store = store || context;
921
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormReset must be wrapped in a Form component.");
922
+ props = {
923
+ type: "reset",
924
+ disabled: _D4HCGWOUcjs.useStoreState.call(void 0, store, "submitting"),
925
+ ...props
926
+ };
927
+ props = _LMCBLO3Gcjs.useButton.call(void 0, props);
928
+ return props;
929
+ });
930
+ var FormReset = _QAUJZR6Ycjs.forwardRef.call(void 0, function FormReset2(props) {
931
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName15, useFormReset(props));
932
+ });
933
+
934
+ // ../ariakit-react-components/dist/form/form-submit.js
935
+ var TagName16 = "button";
936
+ var useFormSubmit = _QAUJZR6Ycjs.createHook.call(void 0, function useFormSubmit2({ store, accessibleWhenDisabled = true, ...props }) {
937
+ const context = useFormContext();
938
+ store = store || context;
939
+ _QAUJZR6Ycjs.invariant.call(void 0, store, "FormSubmit must be wrapped in a Form component.");
940
+ props = {
941
+ type: "submit",
942
+ disabled: _D4HCGWOUcjs.useStoreState.call(void 0, store, "submitting"),
943
+ ...props
944
+ };
945
+ props = _LMCBLO3Gcjs.useButton.call(void 0, {
946
+ ...props,
947
+ accessibleWhenDisabled
948
+ });
949
+ return props;
950
+ });
951
+ var FormSubmit = _QAUJZR6Ycjs.forwardRef.call(void 0, function FormSubmit2(props) {
952
+ return _QAUJZR6Ycjs.createElement.call(void 0, TagName16, useFormSubmit(props));
953
+ });
954
+
955
+
956
+
957
+
958
+
959
+
960
+
961
+
962
+
963
+
964
+
965
+
966
+
967
+
968
+
969
+
970
+
971
+
972
+
973
+
974
+
975
+ exports.useFormContext = useFormContext; exports.Form = Form; exports.FormControl = FormControl; exports.FormCheckbox = FormCheckbox; exports.FormDescription = FormDescription; exports.FormError = FormError; exports.FormField = FormField; exports.FormGroup = FormGroup; exports.FormGroupLabel = FormGroupLabel; exports.FormInput = FormInput; exports.FormLabel = FormLabel; exports.useFormStore = useFormStore; exports.FormProvider = FormProvider; exports.FormPush = FormPush; exports.FormRadio = FormRadio; exports.FormRadioGroup = FormRadioGroup; exports.FormRemove = FormRemove; exports.FormReset = FormReset; exports.FormSubmit = FormSubmit;