jenosize-ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +100 -0
  3. package/THIRD-PARTY-NOTICES.md +163 -0
  4. package/dist/Button-Bt7pzM4R.d.ts +82 -0
  5. package/dist/PaymentInput-CKPIPNWH.d.ts +141 -0
  6. package/dist/Select-CVbEQ2Ep.d.ts +118 -0
  7. package/dist/TagInput-CTJYOB4J.d.ts +90 -0
  8. package/dist/avatar.d.ts +161 -0
  9. package/dist/avatar.js +11 -0
  10. package/dist/badge.d.ts +109 -0
  11. package/dist/badge.js +10 -0
  12. package/dist/breadcrumb.d.ts +58 -0
  13. package/dist/breadcrumb.js +7 -0
  14. package/dist/button.d.ts +54 -0
  15. package/dist/button.js +14 -0
  16. package/dist/calendar.d.ts +368 -0
  17. package/dist/calendar.js +21 -0
  18. package/dist/callout.d.ts +70 -0
  19. package/dist/callout.js +16 -0
  20. package/dist/card-nWicloNi.d.ts +80 -0
  21. package/dist/card.d.ts +2 -0
  22. package/dist/card.js +7 -0
  23. package/dist/checkbox.d.ts +133 -0
  24. package/dist/checkbox.js +11 -0
  25. package/dist/chunk-24TO7E32.js +42 -0
  26. package/dist/chunk-3Y5X7B5C.js +146 -0
  27. package/dist/chunk-4OLULPQG.js +202 -0
  28. package/dist/chunk-4P2NBLBW.js +103 -0
  29. package/dist/chunk-52IFGFTL.js +11 -0
  30. package/dist/chunk-5FATN5YD.js +115 -0
  31. package/dist/chunk-5NOBSXJN.js +297 -0
  32. package/dist/chunk-5RAPA22E.js +106 -0
  33. package/dist/chunk-7EUAMHMU.js +16 -0
  34. package/dist/chunk-7EWQKTNQ.js +1336 -0
  35. package/dist/chunk-7HOIZ3UO.js +110 -0
  36. package/dist/chunk-7IU5TMFL.js +452 -0
  37. package/dist/chunk-7JBNLEJ7.js +29 -0
  38. package/dist/chunk-7S2TBALK.js +23 -0
  39. package/dist/chunk-BJUZVYQC.js +188 -0
  40. package/dist/chunk-BVJWBYIG.js +66 -0
  41. package/dist/chunk-CME4DIML.js +65 -0
  42. package/dist/chunk-CYPPEUX5.js +73 -0
  43. package/dist/chunk-D5BTFSL7.js +71 -0
  44. package/dist/chunk-D6TPWNRK.js +387 -0
  45. package/dist/chunk-DJSXIAFH.js +66 -0
  46. package/dist/chunk-DRZCJCBO.js +46 -0
  47. package/dist/chunk-DWKILXHE.js +17 -0
  48. package/dist/chunk-E7ZSWBAK.js +70 -0
  49. package/dist/chunk-EDSK6FEH.js +8 -0
  50. package/dist/chunk-F2K7VJUV.js +114 -0
  51. package/dist/chunk-F6NLE6XJ.js +40 -0
  52. package/dist/chunk-FHHAPGCR.js +32 -0
  53. package/dist/chunk-FXIBGTS5.js +14 -0
  54. package/dist/chunk-GCVA3OIV.js +72 -0
  55. package/dist/chunk-GFOAJVW5.js +336 -0
  56. package/dist/chunk-GRLSUQQE.js +136 -0
  57. package/dist/chunk-GTHJWR3Q.js +77 -0
  58. package/dist/chunk-HMUZE6EK.js +67 -0
  59. package/dist/chunk-I7WU4GTY.js +503 -0
  60. package/dist/chunk-J2BCKBHC.js +151 -0
  61. package/dist/chunk-J36M3KRX.js +1315 -0
  62. package/dist/chunk-J7ZQQFPT.js +113 -0
  63. package/dist/chunk-JP26LPCY.js +234 -0
  64. package/dist/chunk-JTNFJLIY.js +1046 -0
  65. package/dist/chunk-JVJRHBTD.js +50 -0
  66. package/dist/chunk-JYGR44ZC.js +133 -0
  67. package/dist/chunk-KDLPXXD2.js +173 -0
  68. package/dist/chunk-KMSYEE23.js +224 -0
  69. package/dist/chunk-KNYKWUYX.js +52 -0
  70. package/dist/chunk-LME57Z6J.js +138 -0
  71. package/dist/chunk-MFJP5FA7.js +20 -0
  72. package/dist/chunk-MKC5HNA7.js +1692 -0
  73. package/dist/chunk-MQGD2OUF.js +39 -0
  74. package/dist/chunk-MUFHLP4S.js +566 -0
  75. package/dist/chunk-O2LG3PNI.js +74 -0
  76. package/dist/chunk-O4GRKO3I.js +66 -0
  77. package/dist/chunk-OHUFNYGN.js +791 -0
  78. package/dist/chunk-PWKWNDBS.js +243 -0
  79. package/dist/chunk-QA74ITR4.js +103 -0
  80. package/dist/chunk-R6RGJF4L.js +170 -0
  81. package/dist/chunk-S7NNXWIN.js +7 -0
  82. package/dist/chunk-SV56BSUQ.js +162 -0
  83. package/dist/chunk-T7FCG7XV.js +435 -0
  84. package/dist/chunk-THC2ISYP.js +57 -0
  85. package/dist/chunk-VWC72TR3.js +115 -0
  86. package/dist/chunk-W46K56XU.js +216 -0
  87. package/dist/chunk-W5GGOUUI.js +75 -0
  88. package/dist/chunk-WEUJYDCV.js +269 -0
  89. package/dist/chunk-WFY7DKQD.js +279 -0
  90. package/dist/chunk-WZQFC7ZN.js +448 -0
  91. package/dist/chunk-Z3ETJN5G.js +136 -0
  92. package/dist/chunk-ZOOX3TUB.js +192 -0
  93. package/dist/chunk-ZSNJ6UA3.js +42 -0
  94. package/dist/chunk-ZZA2LUTL.js +130 -0
  95. package/dist/chunk-ZZT2E5VT.js +24 -0
  96. package/dist/color-CtSxc1Rh.d.ts +6 -0
  97. package/dist/combobox.d.ts +184 -0
  98. package/dist/combobox.js +21 -0
  99. package/dist/date-input.d.ts +83 -0
  100. package/dist/date-input.js +16 -0
  101. package/dist/date-picker.d.ts +249 -0
  102. package/dist/date-picker.js +29 -0
  103. package/dist/date-utils-7hTFTXNK.d.ts +34 -0
  104. package/dist/date-vMJBKAFK.d.ts +22 -0
  105. package/dist/dialog.d.ts +86 -0
  106. package/dist/dialog.js +15 -0
  107. package/dist/drawer.d.ts +77 -0
  108. package/dist/drawer.js +14 -0
  109. package/dist/dropdown-menu.d.ts +218 -0
  110. package/dist/dropdown-menu.js +10 -0
  111. package/dist/file-trigger.d.ts +42 -0
  112. package/dist/file-trigger.js +3 -0
  113. package/dist/form.d.ts +487 -0
  114. package/dist/form.js +1179 -0
  115. package/dist/header-navigation.d.ts +74 -0
  116. package/dist/header-navigation.js +23 -0
  117. package/dist/icons/app.d.ts +48 -0
  118. package/dist/icons/app.js +282 -0
  119. package/dist/icons/flag.d.ts +817 -0
  120. package/dist/icons/flag.js +58336 -0
  121. package/dist/icons/integration.d.ts +36 -0
  122. package/dist/icons/integration.js +531 -0
  123. package/dist/icons/payment.d.ts +116 -0
  124. package/dist/icons/payment.js +2418 -0
  125. package/dist/icons.d.ts +2013 -0
  126. package/dist/icons.js +2012 -0
  127. package/dist/illustration.d.ts +48 -0
  128. package/dist/illustration.js +4 -0
  129. package/dist/index.d.ts +68 -0
  130. package/dist/index.js +73 -0
  131. package/dist/indicator.d.ts +51 -0
  132. package/dist/indicator.js +7 -0
  133. package/dist/input.d.ts +66 -0
  134. package/dist/input.js +15 -0
  135. package/dist/multi-value-CJb_tnvi.d.ts +8 -0
  136. package/dist/nav-Bla0o_-1.d.ts +98 -0
  137. package/dist/number-input.d.ts +80 -0
  138. package/dist/number-input.js +15 -0
  139. package/dist/options-CPEIgjtd.d.ts +68 -0
  140. package/dist/overflow-Df0h42Oi.d.ts +29 -0
  141. package/dist/pagination.d.ts +77 -0
  142. package/dist/pagination.js +17 -0
  143. package/dist/payment-input.d.ts +7 -0
  144. package/dist/payment-input.js +15 -0
  145. package/dist/popover.d.ts +60 -0
  146. package/dist/popover.js +14 -0
  147. package/dist/progress.d.ts +87 -0
  148. package/dist/progress.js +5 -0
  149. package/dist/radio.d.ts +77 -0
  150. package/dist/radio.js +12 -0
  151. package/dist/select.d.ts +68 -0
  152. package/dist/select.js +24 -0
  153. package/dist/shared-BNXAdgh2.d.ts +9 -0
  154. package/dist/shared-BYXJPnsN.d.ts +11 -0
  155. package/dist/shared-Dc-GgA16.d.ts +42 -0
  156. package/dist/sidebar-navigation.d.ts +129 -0
  157. package/dist/sidebar-navigation.js +15 -0
  158. package/dist/styles.css +2 -0
  159. package/dist/switch.d.ts +23 -0
  160. package/dist/switch.js +7 -0
  161. package/dist/table.d.ts +692 -0
  162. package/dist/table.js +44 -0
  163. package/dist/tabs.d.ts +111 -0
  164. package/dist/tabs.js +8 -0
  165. package/dist/tag-input.d.ts +12 -0
  166. package/dist/tag-input.js +19 -0
  167. package/dist/tag.d.ts +98 -0
  168. package/dist/tag.js +9 -0
  169. package/dist/textarea.d.ts +40 -0
  170. package/dist/textarea.js +12 -0
  171. package/dist/theme-script.d.ts +29 -0
  172. package/dist/theme-script.js +15 -0
  173. package/dist/theme.css +929 -0
  174. package/dist/theme.d.ts +71 -0
  175. package/dist/theme.js +15 -0
  176. package/dist/toast.d.ts +242 -0
  177. package/dist/toast.js +15 -0
  178. package/dist/tooltip.d.ts +70 -0
  179. package/dist/tooltip.js +6 -0
  180. package/dist/tree.d.ts +308 -0
  181. package/dist/tree.js +11 -0
  182. package/package.json +352 -0
package/dist/form.js ADDED
@@ -0,0 +1,1179 @@
1
+ "use client";import { Combobox } from './chunk-MUFHLP4S.js';
2
+ import './chunk-F6NLE6XJ.js';
3
+ import { CheckboxGroup, Checkbox } from './chunk-ZOOX3TUB.js';
4
+ import { RadioGroup } from './chunk-SV56BSUQ.js';
5
+ import { Switch } from './chunk-HMUZE6EK.js';
6
+ import './chunk-GTHJWR3Q.js';
7
+ import './chunk-MFJP5FA7.js';
8
+ import { FileTrigger } from './chunk-DJSXIAFH.js';
9
+ import { PaymentInput } from './chunk-D6TPWNRK.js';
10
+ import { DateInput } from './chunk-5NOBSXJN.js';
11
+ import './chunk-GFOAJVW5.js';
12
+ import { TagInput } from './chunk-WEUJYDCV.js';
13
+ import { Button } from './chunk-W46K56XU.js';
14
+ import './chunk-CME4DIML.js';
15
+ import './chunk-MQGD2OUF.js';
16
+ import './chunk-JVJRHBTD.js';
17
+ import { Input } from './chunk-7HOIZ3UO.js';
18
+ import { NumberInput } from './chunk-JYGR44ZC.js';
19
+ import { Textarea } from './chunk-KDLPXXD2.js';
20
+ import './chunk-7EUAMHMU.js';
21
+ import { Select } from './chunk-T7FCG7XV.js';
22
+ import './chunk-7S2TBALK.js';
23
+ import './chunk-LME57Z6J.js';
24
+ import './chunk-S7NNXWIN.js';
25
+ import './chunk-ZZT2E5VT.js';
26
+ import './chunk-FHHAPGCR.js';
27
+ import './chunk-7JBNLEJ7.js';
28
+ import './chunk-R6RGJF4L.js';
29
+ import './chunk-W5GGOUUI.js';
30
+ import './chunk-4P2NBLBW.js';
31
+ import './chunk-DWKILXHE.js';
32
+ import './chunk-QA74ITR4.js';
33
+ import './chunk-KNYKWUYX.js';
34
+ import './chunk-52IFGFTL.js';
35
+ import './chunk-O2LG3PNI.js';
36
+ import './chunk-EDSK6FEH.js';
37
+ import { FIELD_LABEL_CLASS } from './chunk-J2BCKBHC.js';
38
+ import { CircleAlertIcon } from './chunk-24TO7E32.js';
39
+ import './chunk-ZZA2LUTL.js';
40
+ import './chunk-O4GRKO3I.js';
41
+ import { devWarn } from './chunk-GCVA3OIV.js';
42
+ import { cn } from './chunk-ZSNJ6UA3.js';
43
+ import * as React8 from 'react';
44
+ import { useForm as useForm$1, useFormContext, Controller, useFormState, FormProvider, useWatch, useFieldArray } from 'react-hook-form';
45
+ export { useWatch } from 'react-hook-form';
46
+ import { jsx, jsxs } from 'react/jsx-runtime';
47
+
48
+ var RegistryContext = React8.createContext(null);
49
+ var RegistryProvider = RegistryContext.Provider;
50
+ var ArrayPrefixContext = React8.createContext("");
51
+ function ArrayPrefixProvider({ prefix, children }) {
52
+ const parent = React8.useContext(ArrayPrefixContext);
53
+ const value = React8.useMemo(() => `${parent}${prefix}`, [parent, prefix]);
54
+ return /* @__PURE__ */ jsx(ArrayPrefixContext.Provider, { value, children });
55
+ }
56
+ function useFieldName(name) {
57
+ const prefix = React8.useContext(ArrayPrefixContext);
58
+ return prefix ? `${prefix}${name}` : name;
59
+ }
60
+ function useArrayPrefix() {
61
+ return React8.useContext(ArrayPrefixContext);
62
+ }
63
+ function useRegisterField(args) {
64
+ const registry = React8.useContext(RegistryContext);
65
+ const { name, kind, validate, label, messages, optionValues, disabled, errorPath } = args;
66
+ const entryRef = React8.useRef({ name, kind });
67
+ entryRef.current = {
68
+ name,
69
+ kind,
70
+ ...validate && { validate },
71
+ ...typeof label === "string" && { label },
72
+ ...messages && { messages },
73
+ ...optionValues && { optionValues },
74
+ ...disabled !== void 0 && { disabled },
75
+ ...errorPath && { errorPath }
76
+ };
77
+ const context = useFormContext();
78
+ React8.useEffect(() => {
79
+ if (!registry) return;
80
+ registry.set(name, entryRef);
81
+ return () => {
82
+ if (registry.get(name) !== entryRef) return;
83
+ registry.delete(name);
84
+ queueMicrotask(() => {
85
+ if (registry.has(name)) return;
86
+ context?.clearErrors(name);
87
+ });
88
+ };
89
+ }, [registry, name]);
90
+ }
91
+ function optionValuesOf(options) {
92
+ if (!Array.isArray(options)) return void 0;
93
+ const values = [];
94
+ for (const entry of options) {
95
+ if (!entry || typeof entry !== "object") continue;
96
+ const record = entry;
97
+ if (Array.isArray(record.options)) {
98
+ for (const child of record.options) {
99
+ const value = child?.value;
100
+ if (typeof value === "string") values.push(value);
101
+ }
102
+ } else if (typeof record.value === "string") {
103
+ values.push(record.value);
104
+ }
105
+ }
106
+ return values.length > 0 ? values : void 0;
107
+ }
108
+ function ownsPopupWithFocus(root, active) {
109
+ for (const owner of root.querySelectorAll("[aria-controls],[aria-owns]")) {
110
+ for (const attribute of ["aria-controls", "aria-owns"]) {
111
+ const id = owner.getAttribute(attribute);
112
+ const popup = id ? root.ownerDocument.querySelector(`#${CSS.escape(id)}`) : null;
113
+ if (popup && (popup.contains(active) || active.contains(popup))) return true;
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+ function stillFocused(root) {
119
+ const active = root.ownerDocument.activeElement;
120
+ if (!active || active === root.ownerDocument.body) return false;
121
+ return root.contains(active) || ownsPopupWithFocus(root, active);
122
+ }
123
+ function BlurScope({ onBlur, children }) {
124
+ const ref = React8.useRef(null);
125
+ const onBlurRef = React8.useRef(onBlur);
126
+ onBlurRef.current = onBlur;
127
+ const pending = React8.useRef(null);
128
+ React8.useEffect(
129
+ () => () => {
130
+ if (pending.current !== null) clearTimeout(pending.current);
131
+ },
132
+ []
133
+ );
134
+ const handleBlur = () => {
135
+ if (pending.current !== null) clearTimeout(pending.current);
136
+ pending.current = setTimeout(() => {
137
+ pending.current = null;
138
+ const root = ref.current;
139
+ if (root && !stillFocused(root)) onBlurRef.current();
140
+ }, 0);
141
+ };
142
+ return /* @__PURE__ */ jsx("span", { ref, onBlur: handleBlur, style: { display: "contents" }, children });
143
+ }
144
+ function FormField(props) {
145
+ const { name, control, absolute = false, render } = props;
146
+ const ctx = useFormContext();
147
+ const prefixed = useFieldName(name);
148
+ const resolvedName = absolute ? name : prefixed;
149
+ const resolvedControl = control ?? ctx.control;
150
+ return /* @__PURE__ */ jsx(
151
+ Controller,
152
+ {
153
+ name: resolvedName,
154
+ control: resolvedControl,
155
+ render: ({ field, fieldState }) => /* @__PURE__ */ jsx(BlurScope, { onBlur: field.onBlur, children: render({ field, fieldState, invalid: fieldState.invalid, error: fieldState.error?.message }) })
156
+ }
157
+ );
158
+ }
159
+ function useBound(args) {
160
+ const path = useFieldName(args.name);
161
+ useRegisterField({
162
+ name: path,
163
+ kind: args.kind,
164
+ validate: args.validate,
165
+ label: args.label,
166
+ messages: args.messages,
167
+ optionValues: args.partialOptions ? void 0 : optionValuesOf(args.options),
168
+ disabled: args.disabled
169
+ });
170
+ const conditional = typeof args.validate?.required === "function";
171
+ const context = useFormContext();
172
+ const control = args.control ?? context?.control;
173
+ const values = useWatch({ control, disabled: !conditional });
174
+ const declared = args.validate?.required;
175
+ const required = conditional ? Boolean(declared(values ?? {})) : declared === true;
176
+ return { path, required };
177
+ }
178
+ function trimOnBlur(field) {
179
+ return () => {
180
+ if (typeof field.value === "string" && field.value !== field.value.trim()) field.onChange(field.value.trim());
181
+ };
182
+ }
183
+ function FormInput({
184
+ name,
185
+ control,
186
+ validate,
187
+ messages,
188
+ ...rest
189
+ }) {
190
+ const { path, required } = useBound({ name, kind: "string", validate, label: rest.label, messages, disabled: rest.disabled, control });
191
+ return /* @__PURE__ */ jsx(
192
+ FormField,
193
+ {
194
+ name: path,
195
+ control,
196
+ absolute: true,
197
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
198
+ Input,
199
+ {
200
+ ...rest,
201
+ required,
202
+ name: field.name,
203
+ value: field.value ?? "",
204
+ onChange: field.onChange,
205
+ onBlur: trimOnBlur(field),
206
+ invalid,
207
+ error
208
+ }
209
+ )
210
+ }
211
+ );
212
+ }
213
+ function FormTextarea({
214
+ name,
215
+ control,
216
+ validate,
217
+ messages,
218
+ ...rest
219
+ }) {
220
+ const { path, required } = useBound({ name, kind: "string", validate, label: rest.label, messages, disabled: rest.disabled, control });
221
+ return /* @__PURE__ */ jsx(
222
+ FormField,
223
+ {
224
+ name: path,
225
+ control,
226
+ absolute: true,
227
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
228
+ Textarea,
229
+ {
230
+ ...rest,
231
+ required,
232
+ name: field.name,
233
+ value: field.value ?? "",
234
+ onChange: field.onChange,
235
+ onBlur: trimOnBlur(field),
236
+ invalid,
237
+ error
238
+ }
239
+ )
240
+ }
241
+ );
242
+ }
243
+ function FormSelect({
244
+ name,
245
+ control,
246
+ validate,
247
+ messages,
248
+ ...rest
249
+ }) {
250
+ const multiple = rest.multiple === true;
251
+ const { path, required } = useBound({
252
+ name,
253
+ kind: multiple ? "array" : "enum",
254
+ validate,
255
+ label: rest.label,
256
+ messages,
257
+ options: rest.options,
258
+ disabled: rest.disabled,
259
+ control
260
+ });
261
+ return /* @__PURE__ */ jsx(
262
+ FormField,
263
+ {
264
+ name: path,
265
+ control,
266
+ absolute: true,
267
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
268
+ Select,
269
+ {
270
+ ...rest,
271
+ required,
272
+ name: field.name,
273
+ value: field.value ?? (multiple ? [] : null),
274
+ onValueChange: (value) => field.onChange(value),
275
+ invalid,
276
+ error
277
+ }
278
+ )
279
+ }
280
+ );
281
+ }
282
+ function FormCombobox({ name, control, validate, messages, ...rest }) {
283
+ const multiple = rest.multiple === true;
284
+ const partialOptions = rest.filter === null || rest.creatable === true;
285
+ const { path, required } = useBound({
286
+ name,
287
+ kind: multiple ? "array" : "enum",
288
+ validate,
289
+ label: rest.label,
290
+ messages,
291
+ options: rest.options,
292
+ partialOptions,
293
+ disabled: rest.disabled,
294
+ control
295
+ });
296
+ return /* @__PURE__ */ jsx(
297
+ FormField,
298
+ {
299
+ name: path,
300
+ control,
301
+ absolute: true,
302
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
303
+ Combobox,
304
+ {
305
+ ...rest,
306
+ required,
307
+ name: field.name,
308
+ value: field.value ?? (multiple ? [] : null),
309
+ onValueChange: (value) => field.onChange(value),
310
+ invalid,
311
+ error
312
+ }
313
+ )
314
+ }
315
+ );
316
+ }
317
+ function FormCheckbox({
318
+ name,
319
+ control,
320
+ validate,
321
+ messages,
322
+ ...rest
323
+ }) {
324
+ const { path, required } = useBound({ name, kind: "boolean", validate, label: rest.label, messages, disabled: rest.disabled, control });
325
+ return /* @__PURE__ */ jsx(
326
+ FormField,
327
+ {
328
+ name: path,
329
+ control,
330
+ absolute: true,
331
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
332
+ Checkbox,
333
+ {
334
+ ...rest,
335
+ required,
336
+ name: field.name,
337
+ checked: !!field.value,
338
+ onCheckedChange: (checked) => field.onChange(checked),
339
+ invalid,
340
+ error
341
+ }
342
+ )
343
+ }
344
+ );
345
+ }
346
+ function FormCheckboxGroup({
347
+ name,
348
+ control,
349
+ validate,
350
+ messages,
351
+ ...rest
352
+ }) {
353
+ const { path, required } = useBound({
354
+ name,
355
+ kind: "array",
356
+ validate,
357
+ label: rest.label,
358
+ messages,
359
+ options: rest.options,
360
+ disabled: rest.disabled,
361
+ control
362
+ });
363
+ return /* @__PURE__ */ jsx(
364
+ FormField,
365
+ {
366
+ name: path,
367
+ control,
368
+ absolute: true,
369
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
370
+ CheckboxGroup,
371
+ {
372
+ ...rest,
373
+ required,
374
+ value: field.value ?? [],
375
+ onValueChange: (value) => field.onChange(value),
376
+ invalid,
377
+ error
378
+ }
379
+ )
380
+ }
381
+ );
382
+ }
383
+ function FormRadioGroup({
384
+ name,
385
+ control,
386
+ validate,
387
+ messages,
388
+ ...rest
389
+ }) {
390
+ const { path, required } = useBound({
391
+ name,
392
+ kind: "enum",
393
+ validate,
394
+ label: rest.label,
395
+ messages,
396
+ options: rest.options,
397
+ disabled: rest.disabled,
398
+ control
399
+ });
400
+ return /* @__PURE__ */ jsx(
401
+ FormField,
402
+ {
403
+ name: path,
404
+ control,
405
+ absolute: true,
406
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
407
+ RadioGroup,
408
+ {
409
+ ...rest,
410
+ required,
411
+ name: field.name,
412
+ value: field.value ?? "",
413
+ onValueChange: (value) => field.onChange(value),
414
+ invalid,
415
+ error
416
+ }
417
+ )
418
+ }
419
+ );
420
+ }
421
+ function FormSwitch({
422
+ name,
423
+ control,
424
+ ...rest
425
+ }) {
426
+ const path = useFieldName(name);
427
+ return /* @__PURE__ */ jsx(
428
+ FormField,
429
+ {
430
+ name: path,
431
+ control,
432
+ absolute: true,
433
+ render: ({ field }) => /* @__PURE__ */ jsx(Switch, { ...rest, name: field.name, checked: !!field.value, onCheckedChange: (checked) => field.onChange(checked) })
434
+ }
435
+ );
436
+ }
437
+ function FormNumberInput({
438
+ name,
439
+ control,
440
+ validate,
441
+ messages,
442
+ ...rest
443
+ }) {
444
+ const { path, required } = useBound({ name, kind: "number", validate, label: rest.label, messages, disabled: rest.disabled, control });
445
+ return /* @__PURE__ */ jsx(
446
+ FormField,
447
+ {
448
+ name: path,
449
+ control,
450
+ absolute: true,
451
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
452
+ NumberInput,
453
+ {
454
+ ...rest,
455
+ required,
456
+ name: field.name,
457
+ value: field.value ?? null,
458
+ onValueChange: (value) => field.onChange(value),
459
+ invalid,
460
+ error
461
+ }
462
+ )
463
+ }
464
+ );
465
+ }
466
+ function FormDateInput({
467
+ name,
468
+ control,
469
+ validate,
470
+ messages,
471
+ ...rest
472
+ }) {
473
+ const { path, required } = useBound({ name, kind: "date", validate, label: rest.label, messages, disabled: rest.disabled, control });
474
+ return /* @__PURE__ */ jsx(
475
+ FormField,
476
+ {
477
+ name: path,
478
+ control,
479
+ absolute: true,
480
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
481
+ DateInput,
482
+ {
483
+ ...rest,
484
+ required,
485
+ name: field.name,
486
+ value: field.value ?? null,
487
+ onValueChange: (iso) => field.onChange(iso),
488
+ invalid,
489
+ error
490
+ }
491
+ )
492
+ }
493
+ );
494
+ }
495
+ function FormTagInput({
496
+ name,
497
+ control,
498
+ validate,
499
+ messages,
500
+ ...rest
501
+ }) {
502
+ const { path, required } = useBound({ name, kind: "array", validate, label: rest.label, messages, disabled: rest.disabled, control });
503
+ return /* @__PURE__ */ jsx(
504
+ FormField,
505
+ {
506
+ name: path,
507
+ control,
508
+ absolute: true,
509
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
510
+ TagInput,
511
+ {
512
+ ...rest,
513
+ required,
514
+ name: field.name,
515
+ value: field.value ?? [],
516
+ onValueChange: (tags) => field.onChange(tags),
517
+ invalid,
518
+ error
519
+ }
520
+ )
521
+ }
522
+ );
523
+ }
524
+ function FormPaymentInput({
525
+ name,
526
+ control,
527
+ validate,
528
+ messages,
529
+ ...rest
530
+ }) {
531
+ const { path, required } = useBound({ name, kind: "string", validate, label: rest.label, messages, disabled: rest.disabled, control });
532
+ return /* @__PURE__ */ jsx(
533
+ FormField,
534
+ {
535
+ name: path,
536
+ control,
537
+ absolute: true,
538
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(
539
+ PaymentInput,
540
+ {
541
+ ...rest,
542
+ required,
543
+ name: field.name,
544
+ value: field.value ?? "",
545
+ onValueChange: (value) => field.onChange(value),
546
+ invalid,
547
+ error
548
+ }
549
+ )
550
+ }
551
+ );
552
+ }
553
+ function fileDisplayValue(files) {
554
+ if (!files || files.length === 0) return "";
555
+ return files.length === 1 ? files[0]?.name ?? "" : `${files.length} files selected`;
556
+ }
557
+ function FormFileInput({
558
+ name,
559
+ control,
560
+ validate,
561
+ messages,
562
+ accept,
563
+ multiple = false,
564
+ buttonLabel = "Upload",
565
+ placeholder = "Choose a file",
566
+ ...rest
567
+ }) {
568
+ const { path, required } = useBound({ name, kind: "file", validate, label: rest.label, messages, disabled: rest.disabled, control });
569
+ return /* @__PURE__ */ jsx(
570
+ FormField,
571
+ {
572
+ name: path,
573
+ control,
574
+ absolute: true,
575
+ render: ({ field, invalid, error }) => /* @__PURE__ */ jsx(FileTrigger, { accept, multiple, onFilesChange: (files) => field.onChange(files), children: ({ open }) => /* @__PURE__ */ jsx(
576
+ Input,
577
+ {
578
+ ...rest,
579
+ readOnly: true,
580
+ required,
581
+ name: field.name,
582
+ value: fileDisplayValue(field.value),
583
+ placeholder,
584
+ onClick: rest.disabled ? void 0 : open,
585
+ invalid,
586
+ error,
587
+ trailingAddon: /* @__PURE__ */ jsx(Button, { variant: "secondary", seamless: true, disabled: rest.disabled, onClick: open, children: buttonLabel })
588
+ }
589
+ ) })
590
+ }
591
+ );
592
+ }
593
+ function FormSubmit({ children, form, ...rest }) {
594
+ const { isSubmitting } = useFormState(form ? { control: form.control } : void 0);
595
+ return /* @__PURE__ */ jsx(Button, { type: "submit", loading: isSubmitting, ...form && { form: form.__jz.formId }, ...rest, children });
596
+ }
597
+ var BOUND_FIELDS = {
598
+ Input: FormInput,
599
+ Textarea: FormTextarea,
600
+ Select: FormSelect,
601
+ Combobox: FormCombobox,
602
+ Checkbox: FormCheckbox,
603
+ CheckboxGroup: FormCheckboxGroup,
604
+ RadioGroup: FormRadioGroup,
605
+ Switch: FormSwitch,
606
+ NumberInput: FormNumberInput,
607
+ DateInput: FormDateInput,
608
+ TagInput: FormTagInput,
609
+ PaymentInput: FormPaymentInput,
610
+ FileInput: FormFileInput
611
+ };
612
+ var labelled = (ctx, suffix) => ctx.label ? `${ctx.label} ${suffix}` : `This field ${suffix}`;
613
+ var DEFAULT_MESSAGES = {
614
+ required: (ctx) => labelled(ctx, "is required"),
615
+ check: "Invalid value",
616
+ minLength: (ctx) => `Must be at least ${ctx.min} characters`,
617
+ maxLength: (ctx) => `Must be at most ${ctx.max} characters`,
618
+ pattern: "Invalid format",
619
+ email: "Enter a valid email address",
620
+ url: "Enter a valid URL",
621
+ equals: "Values do not match",
622
+ min: (ctx) => `Must be at least ${ctx.min}`,
623
+ max: (ctx) => `Must be at most ${ctx.max}`,
624
+ integer: "Must be a whole number",
625
+ positive: "Must be greater than 0",
626
+ negative: "Must be less than 0",
627
+ nonNegative: "Must be 0 or greater",
628
+ multipleOf: (ctx) => `Must be a multiple of ${ctx.min}`,
629
+ after: (ctx) => ctx.min ? `Must be after ${ctx.min}` : "Must be a later date",
630
+ before: (ctx) => ctx.max ? `Must be before ${ctx.max}` : "Must be an earlier date",
631
+ minItems: (ctx) => `Add at least ${ctx.min}`,
632
+ maxItems: (ctx) => `Add at most ${ctx.max}`,
633
+ unique: "Duplicates are not allowed",
634
+ minFiles: (ctx) => `Attach at least ${ctx.min} file(s)`,
635
+ maxFiles: (ctx) => `Attach at most ${ctx.max} file(s)`,
636
+ maxSize: (ctx) => `Each file must be ${ctx.max} or smaller`,
637
+ accept: "Unsupported file type",
638
+ oneOf: "Pick one of the available options"
639
+ };
640
+ var MessagesContext = React8.createContext(null);
641
+ function FormMessages({ value, children }) {
642
+ const parent = React8.useContext(MessagesContext);
643
+ const merged = React8.useMemo(() => parent ? { ...parent, ...value } : value, [parent, value]);
644
+ return /* @__PURE__ */ jsx(MessagesContext.Provider, { value: merged, children });
645
+ }
646
+ function useFormMessages() {
647
+ return React8.useContext(MessagesContext);
648
+ }
649
+ function resolveMessage(rule, ctx, field, app) {
650
+ const entry = field?.[rule] ?? app?.[rule] ?? DEFAULT_MESSAGES[rule];
651
+ return typeof entry === "function" ? entry(ctx) : entry;
652
+ }
653
+
654
+ // src/form/rules.ts
655
+ var FieldRegistry = class extends Map {
656
+ constructor() {
657
+ super(...arguments);
658
+ this.listeners = /* @__PURE__ */ new Set();
659
+ /** Bumped on every membership change — the snapshot `useSyncExternalStore` reads. */
660
+ this.version = 0;
661
+ this.subscribe = (listener) => {
662
+ this.listeners.add(listener);
663
+ return () => this.listeners.delete(listener);
664
+ };
665
+ /** The current membership version (identity-stable function, for React). */
666
+ this.getVersion = () => this.version;
667
+ }
668
+ changed() {
669
+ this.version += 1;
670
+ for (const listener of this.listeners) listener();
671
+ }
672
+ set(name, entry) {
673
+ const isNew = !this.has(name);
674
+ super.set(name, entry);
675
+ if (isNew) this.changed();
676
+ return this;
677
+ }
678
+ delete(name) {
679
+ const existed = super.delete(name);
680
+ if (existed) this.changed();
681
+ return existed;
682
+ }
683
+ };
684
+ var segments = (path) => path.split(/[.[\]]+/).filter(Boolean);
685
+ function getPath(target, path) {
686
+ let node = target;
687
+ for (const key of segments(path)) {
688
+ if (node == null || typeof node !== "object") return void 0;
689
+ node = node[key];
690
+ }
691
+ return node;
692
+ }
693
+ function setPath(target, path, value) {
694
+ const keys = segments(path);
695
+ let node = target;
696
+ for (const [index, key] of keys.entries()) {
697
+ if (index === keys.length - 1) {
698
+ node[key] = value;
699
+ break;
700
+ }
701
+ const next = node[key];
702
+ if (next == null || typeof next !== "object") {
703
+ const nextKey = keys[index + 1];
704
+ node[key] = nextKey !== void 0 && /^\d+$/.test(nextKey) ? [] : {};
705
+ }
706
+ node = node[key];
707
+ }
708
+ }
709
+ function trimValues(values) {
710
+ if (typeof values === "string") return values.trim();
711
+ if (Array.isArray(values)) return values.map((item) => trimValues(item));
712
+ if (values && typeof values === "object" && Object.getPrototypeOf(values) === Object.prototype) {
713
+ const out = {};
714
+ for (const [key, value] of Object.entries(values)) out[key] = trimValues(value);
715
+ return out;
716
+ }
717
+ return values;
718
+ }
719
+ var call = (source, values) => typeof source === "function" ? source(values) : source;
720
+ var isEmpty = (kind, value) => {
721
+ switch (kind) {
722
+ case "string": {
723
+ return typeof value !== "string" || value.trim() === "";
724
+ }
725
+ case "enum":
726
+ case "date": {
727
+ return value == null || value === "";
728
+ }
729
+ case "number": {
730
+ return value == null || Number.isNaN(value);
731
+ }
732
+ case "boolean": {
733
+ return value !== true;
734
+ }
735
+ case "array":
736
+ case "file": {
737
+ return !Array.isArray(value) || value.length === 0;
738
+ }
739
+ }
740
+ };
741
+ var EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
742
+ var isUrl = (value) => {
743
+ try {
744
+ const url = new URL(value);
745
+ return url.protocol === "http:" || url.protocol === "https:";
746
+ } catch {
747
+ return false;
748
+ }
749
+ };
750
+ var TIME_ONLY_DAY = "1970-01-01T";
751
+ var toTime = (value) => {
752
+ if (typeof value !== "string" || value === "") return null;
753
+ const iso = /^\d{2}:\d{2}(:\d{2})?$/.test(value) ? TIME_ONLY_DAY + value : value;
754
+ const time = new Date(iso).getTime();
755
+ return Number.isNaN(time) ? null : time;
756
+ };
757
+ var todayIso = () => {
758
+ const now = /* @__PURE__ */ new Date();
759
+ const month = String(now.getMonth() + 1).padStart(2, "0");
760
+ const day = String(now.getDate()).padStart(2, "0");
761
+ return `${now.getFullYear()}-${month}-${day}`;
762
+ };
763
+ var resolveDateBound = (bound, values) => {
764
+ const raw = call(bound, values);
765
+ return toTime(raw === "today" ? todayIso() : raw);
766
+ };
767
+ var isAcceptEntry = (entry) => entry.startsWith(".") || entry.includes("/");
768
+ var matchesAccept = (file, accept) => {
769
+ const entries = accept.split(",").map((entry) => entry.trim().toLowerCase()).filter(Boolean);
770
+ const bogus = entries.filter((entry) => !isAcceptEntry(entry));
771
+ if (bogus.length > 0) {
772
+ devWarn(
773
+ `\`accept\` entr${bogus.length === 1 ? "y" : "ies"} ${bogus.map((e) => `"${e}"`).join(", ")} match nothing \u2014 use an extension (".pdf"), a MIME glob ("image/*"), or a full MIME type ("application/pdf").`
774
+ );
775
+ }
776
+ return entries.some((entry) => {
777
+ if (entry.startsWith(".")) return file.name.toLowerCase().endsWith(entry);
778
+ if (entry.endsWith("/*")) return file.type.toLowerCase().startsWith(entry.slice(0, -1));
779
+ return file.type.toLowerCase() === entry;
780
+ });
781
+ };
782
+ async function evaluateField(entry, value, values, makeMessage) {
783
+ if (entry.disabled) return void 0;
784
+ const v = entry.validate;
785
+ const emit = (rule, extra) => ({ rule, message: makeMessage(rule, extra) });
786
+ const empty = isEmpty(entry.kind, value);
787
+ const required = call(v?.required, values) === true;
788
+ if (required && empty) return emit("required");
789
+ if (empty && entry.kind !== "boolean") {
790
+ if (entry.kind === "array" && v?.minItems !== void 0 && v.minItems > 0) return emit("minItems", { min: v.minItems });
791
+ if (entry.kind === "file" && v?.minFiles !== void 0 && v.minFiles > 0) return emit("minFiles", { min: v.minFiles });
792
+ if (v?.equals && (v.equals(values) ?? "") !== "") return emit("equals");
793
+ return void 0;
794
+ }
795
+ if (entry.optionValues && v?.oneOf !== false) {
796
+ const allowed = new Set(entry.optionValues);
797
+ const picked = Array.isArray(value) ? value : [value];
798
+ if (picked.some((item) => typeof item === "string" && item !== "" && !allowed.has(item))) return emit("oneOf");
799
+ }
800
+ switch (entry.kind) {
801
+ case "string": {
802
+ const text = String(value).trim();
803
+ if (v?.email && !EMAIL.test(text)) return emit("email");
804
+ if (v?.url && !isUrl(text)) return emit("url");
805
+ if (v?.pattern) {
806
+ v.pattern.lastIndex = 0;
807
+ if (!v.pattern.test(text)) return emit("pattern");
808
+ }
809
+ if (v?.minLength !== void 0 && text.length < v.minLength) return emit("minLength", { min: v.minLength });
810
+ if (v?.maxLength !== void 0 && text.length > v.maxLength) return emit("maxLength", { max: v.maxLength });
811
+ if (v?.equals) {
812
+ const other = v.equals(values);
813
+ if ((other ?? "") !== text) return emit("equals");
814
+ }
815
+ break;
816
+ }
817
+ case "number": {
818
+ const num = value;
819
+ if (v?.integer && !Number.isSafeInteger(num)) return emit("integer");
820
+ if (v?.positive && num <= 0) return emit("positive");
821
+ if (v?.negative && num >= 0) return emit("negative");
822
+ if (v?.nonNegative && num < 0) return emit("nonNegative");
823
+ if (v?.multipleOf !== void 0) {
824
+ const ratio = num / v.multipleOf;
825
+ if (!Number.isFinite(ratio) || Math.abs(ratio - Math.round(ratio)) > 1e-9) return emit("multipleOf", { min: v.multipleOf });
826
+ }
827
+ const min = call(v?.min, values);
828
+ if (min != null && num < min) return emit("min", { min });
829
+ const max = call(v?.max, values);
830
+ if (max != null && num > max) return emit("max", { max });
831
+ break;
832
+ }
833
+ case "date": {
834
+ const time = toTime(value);
835
+ if (time === null) break;
836
+ const min = resolveDateBound(v?.min, values);
837
+ const max = resolveDateBound(v?.max, values);
838
+ const after = resolveDateBound(v?.after, values);
839
+ const before = resolveDateBound(v?.before, values);
840
+ if (min !== null && time < min) return emit("min", { min: String(call(v?.min, values) ?? "") });
841
+ if (max !== null && time > max) return emit("max", { max: String(call(v?.max, values) ?? "") });
842
+ if (after !== null && time <= after) return emit("after", { min: String(call(v?.after, values) ?? "") });
843
+ if (before !== null && time >= before) return emit("before", { max: String(call(v?.before, values) ?? "") });
844
+ break;
845
+ }
846
+ case "array": {
847
+ const items = value;
848
+ if (v?.minItems !== void 0 && items.length < v.minItems) return emit("minItems", { min: v.minItems });
849
+ if (v?.maxItems !== void 0 && items.length > v.maxItems) return emit("maxItems", { max: v.maxItems });
850
+ if (v?.unique && new Set(items.map((item) => String(item).toLowerCase())).size !== items.length) return emit("unique");
851
+ break;
852
+ }
853
+ case "file": {
854
+ const files = value;
855
+ const { minFiles, maxFiles, maxSize, accept } = v ?? {};
856
+ if (minFiles !== void 0 && files.length < minFiles) return emit("minFiles", { min: minFiles });
857
+ if (maxFiles !== void 0 && files.length > maxFiles) return emit("maxFiles", { max: maxFiles });
858
+ if (maxSize !== void 0 && files.some((file) => file.size > maxSize)) return emit("maxSize", { max: maxSize });
859
+ if (accept && files.some((file) => !matchesAccept(file, accept))) return emit("accept");
860
+ break;
861
+ }
862
+ }
863
+ if (v?.check) {
864
+ const outcome = await v.check(value, values);
865
+ if (typeof outcome === "string" && outcome !== "") return { rule: "check", message: outcome };
866
+ }
867
+ return void 0;
868
+ }
869
+ var RowContext = React8.createContext(null);
870
+ function FormArrayRemove({ children, ...rest }) {
871
+ const row = React8.useContext(RowContext);
872
+ if (!row) return null;
873
+ return /* @__PURE__ */ jsx(
874
+ Button,
875
+ {
876
+ type: "button",
877
+ variant: "tertiary",
878
+ iconOnly: !children,
879
+ "aria-label": children ? void 0 : "Remove row",
880
+ ...rest,
881
+ disabled: !row.canRemove || rest.disabled,
882
+ onClick: row.remove,
883
+ children
884
+ }
885
+ );
886
+ }
887
+ FormArrayRemove.displayName = "Form.Array.Remove";
888
+ function FormArray({ form, name, label, hint, min, max, unique, empty, addLabel = "Add", messages, className, children }) {
889
+ const prefix = useArrayPrefix();
890
+ const path = `${prefix}${name}`;
891
+ const context = useFormContext();
892
+ const resolvedControl = form?.control ?? context.control;
893
+ const appMessages = useFormMessages();
894
+ const { fields, append, remove } = useFieldArray({ control: resolvedControl, name: path });
895
+ const addRef = React8.useRef(null);
896
+ const { errors, isSubmitted } = useFormState({ control: resolvedControl, name: path });
897
+ const revalidate = React8.useCallback(() => {
898
+ if (isSubmitted) void context.trigger();
899
+ }, [isSubmitted, context]);
900
+ const removeRow = React8.useCallback(
901
+ (index) => {
902
+ remove(index);
903
+ revalidate();
904
+ requestAnimationFrame(() => addRef.current?.focus());
905
+ },
906
+ [remove, revalidate]
907
+ );
908
+ const addRow = React8.useCallback(() => {
909
+ append(empty);
910
+ revalidate();
911
+ }, [append, empty, revalidate]);
912
+ const uniqueMessage = resolveMessage(
913
+ "unique",
914
+ { name: path, label: typeof label === "string" ? label : void 0, value: void 0, values: {} },
915
+ messages,
916
+ appMessages
917
+ );
918
+ useRegisterField({
919
+ name: path,
920
+ kind: "array",
921
+ label: typeof label === "string" ? label : void 0,
922
+ messages,
923
+ errorPath: `${path}.root`,
924
+ validate: {
925
+ ...min !== void 0 && { minItems: min },
926
+ ...max !== void 0 && { maxItems: max },
927
+ ...unique && {
928
+ check: (rows) => {
929
+ const keys = rows.map(
930
+ (row) => String(row?.[unique] ?? "").trim().toLowerCase()
931
+ ).filter(Boolean);
932
+ return new Set(keys).size !== keys.length ? uniqueMessage : false;
933
+ }
934
+ }
935
+ }
936
+ });
937
+ const rootError = getPath(errors, `${path}.root`)?.message;
938
+ const baseId = React8.useId();
939
+ const labelId = `${baseId}-label`;
940
+ const hintId = `${baseId}-hint`;
941
+ const errorId = `${baseId}-error`;
942
+ const describedBy = rootError ? errorId : hint ? hintId : void 0;
943
+ const rowFields = ROW_NAMESPACE;
944
+ const count = fields.length;
945
+ const canRemove = count > (min ?? 0);
946
+ const canAdd = max === void 0 || count < max;
947
+ return (
948
+ // A labelled `role="group"`, the same shape `FieldGroupFrame` uses for the
949
+ // other many-control fields (AGENTS §6): a plain element named via
950
+ // `aria-labelledby` — never a <label>, which would activate one control —
951
+ // plus the hint/array-level error wired through `aria-describedby` so a
952
+ // screen reader announces "Invite teammates, Add at least 1" instead of
953
+ // stranding that message next to nothing.
954
+ /* @__PURE__ */ jsxs(
955
+ "div",
956
+ {
957
+ ...label ? { role: "group", "aria-labelledby": labelId } : {},
958
+ ...describedBy ? { "aria-describedby": describedBy } : {},
959
+ className: cn("flex flex-col gap-3", className),
960
+ children: [
961
+ label ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
962
+ /* @__PURE__ */ jsx("span", { id: labelId, className: FIELD_LABEL_CLASS, children: label }),
963
+ hint && !rootError ? /* @__PURE__ */ jsx("span", { id: hintId, className: "text-sm text-tertiary", children: hint }) : null
964
+ ] }) : null,
965
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3", children: fields.map((field, index) => /* @__PURE__ */ jsx(ArrayRow, { prefix: `${name}.${index}.`, index, remove: () => removeRow(index), canRemove, children: children({
966
+ ...rowFields,
967
+ index,
968
+ first: index === 0,
969
+ last: index === count - 1,
970
+ count,
971
+ remove: () => removeRow(index),
972
+ Remove: FormArrayRemove
973
+ }) }, field.id)) }),
974
+ rootError ? /* @__PURE__ */ jsx("span", { id: errorId, className: "text-sm text-error-primary", children: rootError }) : null,
975
+ addLabel === null ? null : /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, { ref: addRef, type: "button", variant: "secondary", size: "sm", disabled: !canAdd, onClick: addRow, children: addLabel }) })
976
+ ]
977
+ }
978
+ )
979
+ );
980
+ }
981
+ FormArray.displayName = "Form.Array";
982
+ function ArrayRow({
983
+ prefix,
984
+ index,
985
+ remove,
986
+ canRemove,
987
+ children
988
+ }) {
989
+ const row = React8.useMemo(() => ({ index, remove, canRemove }), [index, remove, canRemove]);
990
+ return /* @__PURE__ */ jsx(RowContext.Provider, { value: row, children: /* @__PURE__ */ jsx(ArrayPrefixProvider, { prefix, children }) });
991
+ }
992
+ var ROW_NAMESPACE = { ...BOUND_FIELDS, Array: FormArray };
993
+ var BANNER = "flex items-start gap-2 rounded-[10px] border border-utility-red-200 bg-utility-red-50 px-3.5 py-3 text-sm text-utility-red-700";
994
+ function RootError({ messages }) {
995
+ return /* @__PURE__ */ jsxs("div", { role: "alert", className: BANNER, children: [
996
+ /* @__PURE__ */ jsx(CircleAlertIcon, { className: "mt-0.5 size-4 shrink-0" }),
997
+ messages.length === 1 ? /* @__PURE__ */ jsx("span", { children: messages[0] }) : /* @__PURE__ */ jsx("ul", { className: "flex list-disc flex-col gap-1 pl-4", children: messages.map((message) => /* @__PURE__ */ jsx("li", { children: message }, message)) })
998
+ ] });
999
+ }
1000
+ var ERROR_META_KEYS = /* @__PURE__ */ new Set(["ref", "type", "types"]);
1001
+ function errorLeaves(node, prefix = "", out = []) {
1002
+ if (!node || typeof node !== "object") return out;
1003
+ const record = node;
1004
+ if (typeof record.message === "string" && record.message !== "") {
1005
+ out.push([prefix, record.message]);
1006
+ return out;
1007
+ }
1008
+ for (const [key, child] of Object.entries(record)) {
1009
+ if (ERROR_META_KEYS.has(key)) continue;
1010
+ errorLeaves(child, prefix ? `${prefix}.${key}` : key, out);
1011
+ }
1012
+ return out;
1013
+ }
1014
+ function FormRoot({ form, errorSummary = true, className, children }) {
1015
+ const { rhf, registry, formId, formRef, onSubmit, mounted } = form.__jz;
1016
+ React8.useEffect(() => {
1017
+ mounted.count += 1;
1018
+ if (mounted.count > 1) devWarn("Two <Form> elements share one useForm() instance \u2014 the form id is duplicated in the DOM.");
1019
+ return () => {
1020
+ mounted.count -= 1;
1021
+ };
1022
+ }, [mounted]);
1023
+ const { errors } = useFormState({ control: form.control });
1024
+ React8.useSyncExternalStore(registry.subscribe, registry.getVersion, registry.getVersion);
1025
+ const registered = new Set(registry.keys());
1026
+ const messages = [];
1027
+ for (const [path, message] of errorLeaves(errors)) {
1028
+ const isFormLevel = path === "root";
1029
+ const isOwned = registered.has(path) || path.endsWith(".root") && registered.has(path.slice(0, -".root".length));
1030
+ if (isFormLevel || !isOwned) messages.push(message);
1031
+ }
1032
+ const bannerMessages = [...new Set(messages)];
1033
+ return /* @__PURE__ */ jsx(FormProvider, { ...rhf, children: /* @__PURE__ */ jsx(RegistryProvider, { value: registry, children: /* @__PURE__ */ jsxs("form", { id: formId, ref: formRef, noValidate: true, onSubmit, className: cn("flex flex-col gap-6", className), children: [
1034
+ errorSummary && bannerMessages.length > 0 ? /* @__PURE__ */ jsx(RootError, { messages: bannerMessages }) : null,
1035
+ children
1036
+ ] }) }) });
1037
+ }
1038
+ function createBoundForm(getForm) {
1039
+ const root = (props) => /* @__PURE__ */ jsx(FormRoot, { ...props, form: getForm() });
1040
+ root.displayName = "Form";
1041
+ const submit = (props) => /* @__PURE__ */ jsx(FormSubmit, { ...props, form: getForm() });
1042
+ submit.displayName = "Form.Submit";
1043
+ const array = (props) => /* @__PURE__ */ jsx(FormArray, { ...props, form: getForm() });
1044
+ array.displayName = "Form.Array";
1045
+ return Object.assign(root, {
1046
+ ...BOUND_FIELDS,
1047
+ Field: FormField,
1048
+ Array: Object.assign(array, { Remove: FormArrayRemove }),
1049
+ Submit: submit
1050
+ });
1051
+ }
1052
+
1053
+ // src/form/useForm.ts
1054
+ function focusFirstInvalid(root) {
1055
+ if (!root) return;
1056
+ requestAnimationFrame(
1057
+ () => requestAnimationFrame(() => {
1058
+ for (const node of root.querySelectorAll('[aria-invalid="true"]')) {
1059
+ const focusable = node.matches("input,textarea,select,button,[tabindex]") ? node : node.querySelector('input,textarea,select,button,[tabindex]:not([tabindex="-1"])');
1060
+ if (focusable && !focusable.disabled && focusable.tabIndex !== -1) {
1061
+ focusable.focus();
1062
+ return;
1063
+ }
1064
+ }
1065
+ })
1066
+ );
1067
+ }
1068
+ function pickDirty(dirty, values) {
1069
+ if (dirty === true) return values;
1070
+ if (Array.isArray(dirty)) return values;
1071
+ if (dirty && typeof dirty === "object") {
1072
+ const out = {};
1073
+ for (const [key, flag] of Object.entries(dirty)) {
1074
+ const picked = pickDirty(flag, values?.[key]);
1075
+ if (picked !== void 0) out[key] = picked;
1076
+ }
1077
+ return Object.keys(out).length > 0 ? out : void 0;
1078
+ }
1079
+ return void 0;
1080
+ }
1081
+ function readDirtyFields(rhf) {
1082
+ const live = rhf.control._formState;
1083
+ if (live && typeof live === "object" && "dirtyFields" in live) return live.dirtyFields;
1084
+ devWarn(
1085
+ "react-hook-form changed its internals \u2014 `control._formState` is gone, so `form.dirtyValues()` fell back to the render-time `formState` proxy and may under-report changed fields. Install a version matching the `react-hook-form` peer range (>=7.71 <8)."
1086
+ );
1087
+ return rhf.formState.dirtyFields;
1088
+ }
1089
+ function cacheKey(value) {
1090
+ try {
1091
+ return JSON.stringify(value, (_key, item) => item instanceof File ? `${item.name}:${item.size}` : item) ?? "undefined";
1092
+ } catch {
1093
+ return String(value);
1094
+ }
1095
+ }
1096
+ function useForm(options) {
1097
+ const { defaultValues, values, onSubmit: _onSubmit, onInvalid: _onInvalid, ...rhfOptions } = options;
1098
+ const optionsRef = React8.useRef(options);
1099
+ optionsRef.current = options;
1100
+ const appMessages = useFormMessages();
1101
+ const messagesRef = React8.useRef(appMessages);
1102
+ messagesRef.current = appMessages;
1103
+ const registry = React8.useRef(new FieldRegistry()).current;
1104
+ const formRef = React8.useRef(null);
1105
+ const formId = React8.useId();
1106
+ const checkCache = React8.useRef(/* @__PURE__ */ new Map()).current;
1107
+ const resolver = React8.useCallback(
1108
+ async (rawValues) => {
1109
+ const values2 = trimValues(rawValues);
1110
+ const errors = {};
1111
+ const errorBag = errors;
1112
+ for (const [name, entryRef] of registry) {
1113
+ const entry = entryRef.current;
1114
+ const value = getPath(values2, name);
1115
+ const makeMessage = (rule, extra) => resolveMessage(rule, { name, label: entry.label, value, values: values2, ...extra }, entry.messages, messagesRef.current);
1116
+ let target = entry;
1117
+ const check = entry.validate?.check;
1118
+ if (check) {
1119
+ const key = `${cacheKey(value)}|${cacheKey(values2)}`;
1120
+ const memo = async (checkValue, checkValues) => {
1121
+ const cached = checkCache.get(name);
1122
+ if (cached && cached.key === key) return cached.failure?.message ?? false;
1123
+ const outcome = await check(checkValue, checkValues);
1124
+ const failure2 = typeof outcome === "string" && outcome !== "" ? { rule: "check", message: outcome } : void 0;
1125
+ checkCache.set(name, { key, failure: failure2 });
1126
+ return outcome;
1127
+ };
1128
+ target = { ...entry, validate: { ...entry.validate, check: memo } };
1129
+ }
1130
+ const failure = await evaluateField(target, value, values2, makeMessage);
1131
+ if (!registry.has(name)) continue;
1132
+ const errorAt = entry.errorPath ?? name;
1133
+ if (failure && getPath(errors, errorAt) === void 0) {
1134
+ setPath(errorBag, errorAt, { type: failure.rule, message: failure.message });
1135
+ }
1136
+ }
1137
+ return Object.keys(errors).length > 0 ? { values: {}, errors } : { values: values2, errors: {} };
1138
+ },
1139
+ [registry, checkCache]
1140
+ );
1141
+ const rhf = useForm$1({
1142
+ ...rhfOptions,
1143
+ defaultValues,
1144
+ ...values !== void 0 && { values },
1145
+ resolver,
1146
+ // Our own pass (below) handles focus — RHF's needs a registered `field.ref`.
1147
+ shouldFocusError: false
1148
+ });
1149
+ const formRefObject = React8.useRef(null);
1150
+ const form = React8.useMemo(() => {
1151
+ const api = Object.create(rhf);
1152
+ api.setError = (name, error) => {
1153
+ rhf.setError(name, typeof error === "string" ? { type: "server", message: error } : error);
1154
+ };
1155
+ api.setFormError = (message) => rhf.setError("root", { type: "server", message });
1156
+ api.dirtyValues = () => pickDirty(readDirtyFields(rhf), rhf.getValues()) ?? {};
1157
+ api.validate = (names) => rhf.trigger(names);
1158
+ api.submit = () => void handleSubmit();
1159
+ const handleSubmit = rhf.handleSubmit(
1160
+ async (submitted) => {
1161
+ checkCache.clear();
1162
+ await optionsRef.current.onSubmit?.(submitted, formRefObject.current);
1163
+ },
1164
+ (errors) => {
1165
+ focusFirstInvalid(formRef.current);
1166
+ optionsRef.current.onInvalid?.(errors, formRefObject.current);
1167
+ }
1168
+ );
1169
+ api.__jz = { rhf, registry, formId, formRef, onSubmit: handleSubmit, mounted: { count: 0 } };
1170
+ return api;
1171
+ }, [rhf, registry, formId, checkCache]);
1172
+ formRefObject.current = form;
1173
+ const boundForm = React8.useMemo(() => createBoundForm(() => formRefObject.current), []);
1174
+ return [form, boundForm];
1175
+ }
1176
+
1177
+ export { DEFAULT_MESSAGES, FormMessages, useForm, useFormMessages };
1178
+ //# sourceMappingURL=form.js.map
1179
+ //# sourceMappingURL=form.js.map