@letar/forms 1.0.3 → 1.2.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 (56) hide show
  1. package/CHANGELOG.md +331 -0
  2. package/README.md +9 -9
  3. package/README.ru.md +389 -0
  4. package/analytics.js +3 -0
  5. package/analytics.js.map +1 -0
  6. package/chunk-2PSXYC3I.js +1782 -0
  7. package/chunk-2PSXYC3I.js.map +1 -0
  8. package/chunk-5D6S6EGF.js +206 -0
  9. package/chunk-5D6S6EGF.js.map +1 -0
  10. package/chunk-6E7VJAJT.js +78 -0
  11. package/chunk-6E7VJAJT.js.map +1 -0
  12. package/chunk-CGXKRCSM.js +117 -0
  13. package/chunk-CGXKRCSM.js.map +1 -0
  14. package/chunk-DQUVUMCX.js +982 -0
  15. package/chunk-DQUVUMCX.js.map +1 -0
  16. package/chunk-K3J4L26K.js +345 -0
  17. package/chunk-K3J4L26K.js.map +1 -0
  18. package/chunk-MAYUFA5K.js +822 -0
  19. package/chunk-MAYUFA5K.js.map +1 -0
  20. package/{chunk-4V6WBJ76.js → chunk-MVGXZNHP.js} +2 -2
  21. package/{chunk-4V6WBJ76.js.map → chunk-MVGXZNHP.js.map} +1 -1
  22. package/chunk-MZDTJSF7.js +299 -0
  23. package/chunk-MZDTJSF7.js.map +1 -0
  24. package/chunk-Q5EOF36Y.js +709 -0
  25. package/chunk-Q5EOF36Y.js.map +1 -0
  26. package/{chunk-7FEQFDJ7.js → chunk-R2RTCKXY.js} +2 -2
  27. package/{chunk-7FEQFDJ7.js.map → chunk-R2RTCKXY.js.map} +1 -1
  28. package/chunk-XFWLD5EO.js +1045 -0
  29. package/chunk-XFWLD5EO.js.map +1 -0
  30. package/fields/boolean.js +5 -0
  31. package/fields/boolean.js.map +1 -0
  32. package/fields/datetime.js +5 -0
  33. package/fields/datetime.js.map +1 -0
  34. package/fields/number.js +5 -0
  35. package/fields/number.js.map +1 -0
  36. package/fields/selection.js +5 -0
  37. package/fields/selection.js.map +1 -0
  38. package/fields/specialized.js +5 -0
  39. package/fields/specialized.js.map +1 -0
  40. package/fields/text.js +5 -0
  41. package/fields/text.js.map +1 -0
  42. package/hcaptcha-U4XIT3HS.js +64 -0
  43. package/hcaptcha-U4XIT3HS.js.map +1 -0
  44. package/i18n.js +1 -1
  45. package/index.js +3736 -4962
  46. package/index.js.map +1 -1
  47. package/offline.js +1 -1
  48. package/package.json +59 -4
  49. package/recaptcha-PKAUAY2S.js +56 -0
  50. package/recaptcha-PKAUAY2S.js.map +1 -0
  51. package/server-errors.js +3 -0
  52. package/server-errors.js.map +1 -0
  53. package/turnstile-7FXTBSLW.js +36 -0
  54. package/turnstile-7FXTBSLW.js.map +1 -0
  55. package/validators/ru.js +73 -0
  56. package/validators/ru.js.map +1 -0
@@ -0,0 +1,822 @@
1
+ import { createField, SelectionFieldLabel, FieldError, useAsyncSearch, FieldTooltip, getOptionLabel, useGroupedOptions, FieldWrapper, FieldLabel, useDeclarativeForm, useFormGroup, useResolvedFieldProps, getFieldErrors } from './chunk-XFWLD5EO.js';
2
+ import { Field, Combobox, Spinner, Portal, useFilter, createListCollection, Fieldset, CheckboxGroup, HStack, Flex, CheckboxCard, Listbox, NativeSelect, RadioCard, RadioGroup, SegmentGroup, Select, TagsInput } from '@chakra-ui/react';
3
+ import { useMemo, useCallback, useState, useRef, useEffect } from 'react';
4
+ import { jsxs, jsx } from 'react/jsx-runtime';
5
+
6
+ var FieldAutocomplete = createField({
7
+ displayName: "FieldAutocomplete",
8
+ useFieldState: (componentProps) => {
9
+ const {
10
+ inputValue,
11
+ setInputValue,
12
+ isLoading,
13
+ data: queryData
14
+ } = useAsyncSearch({
15
+ useQuery: componentProps.useQuery,
16
+ debounce: componentProps.debounce ?? 300,
17
+ minChars: componentProps.minChars ?? 1
18
+ });
19
+ const { contains } = useFilter({ sensitivity: "base" });
20
+ const suggestions = useMemo(() => {
21
+ if (componentProps.suggestions) {
22
+ const filtered = inputValue ? componentProps.suggestions.filter((s) => contains(s, inputValue)) : componentProps.suggestions.slice(0, 10);
23
+ return filtered.map((s) => ({ label: s, value: s }));
24
+ }
25
+ if (queryData && componentProps.getLabel) {
26
+ const getLabel = componentProps.getLabel;
27
+ return queryData.map((item) => {
28
+ const itemLabel = getLabel(item);
29
+ return { label: itemLabel, value: itemLabel };
30
+ });
31
+ }
32
+ return [];
33
+ }, [componentProps.suggestions, queryData, componentProps.getLabel, inputValue, contains]);
34
+ const collection = useMemo(() => {
35
+ return createListCollection({
36
+ items: suggestions,
37
+ itemToString: (item) => item.label,
38
+ itemToValue: (item) => item.value
39
+ });
40
+ }, [suggestions]);
41
+ return {
42
+ inputValue,
43
+ setInputValue,
44
+ isLoading,
45
+ suggestions,
46
+ collection
47
+ };
48
+ },
49
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps, fieldState }) => {
50
+ const currentValue = field.state.value ?? "";
51
+ const minChars = componentProps.minChars ?? 1;
52
+ return /* @__PURE__ */ jsxs(
53
+ Field.Root,
54
+ {
55
+ invalid: hasError,
56
+ required: resolved.required,
57
+ disabled: resolved.disabled,
58
+ readOnly: resolved.readOnly,
59
+ children: [
60
+ /* @__PURE__ */ jsxs(
61
+ Combobox.Root,
62
+ {
63
+ collection: fieldState.collection,
64
+ size: componentProps.size ?? "md",
65
+ variant: componentProps.variant ?? "outline",
66
+ value: currentValue ? [currentValue] : [],
67
+ inputValue: fieldState.inputValue,
68
+ onInputValueChange: (details) => {
69
+ fieldState.setInputValue(details.inputValue);
70
+ field.handleChange(details.inputValue);
71
+ },
72
+ onValueChange: (details) => {
73
+ const newValue = details.value[0] ?? "";
74
+ fieldState.setInputValue(newValue);
75
+ field.handleChange(newValue);
76
+ },
77
+ onInteractOutside: () => field.handleBlur(),
78
+ disabled: resolved.disabled,
79
+ allowCustomValue: true,
80
+ openOnClick: true,
81
+ "data-field-name": fullPath,
82
+ children: [
83
+ resolved.label && /* @__PURE__ */ jsx(Combobox.Label, { children: /* @__PURE__ */ jsx(SelectionFieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }) }),
84
+ /* @__PURE__ */ jsxs(Combobox.Control, { children: [
85
+ /* @__PURE__ */ jsx(Combobox.Input, { placeholder: resolved.placeholder ?? "Start typing..." }),
86
+ /* @__PURE__ */ jsxs(Combobox.IndicatorGroup, { children: [
87
+ fieldState.isLoading && /* @__PURE__ */ jsx(Spinner, { size: "xs" }),
88
+ /* @__PURE__ */ jsx(Combobox.Trigger, {})
89
+ ] })
90
+ ] }),
91
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Combobox.Positioner, { children: /* @__PURE__ */ jsxs(Combobox.Content, { children: [
92
+ fieldState.isLoading && fieldState.suggestions.length === 0 && /* @__PURE__ */ jsx(Combobox.Empty, { children: componentProps.loadingMessage ?? "Loading..." }),
93
+ !fieldState.isLoading && fieldState.suggestions.length === 0 && fieldState.inputValue.length >= minChars && /* @__PURE__ */ jsx(Combobox.Empty, { children: componentProps.emptyMessage ?? "No suggestions" }),
94
+ !fieldState.isLoading && fieldState.suggestions.length === 0 && fieldState.inputValue.length < minChars && fieldState.inputValue.length > 0 && /* @__PURE__ */ jsxs(Combobox.Empty, { children: [
95
+ "Enter at least ",
96
+ minChars,
97
+ " characters"
98
+ ] }),
99
+ fieldState.suggestions.map((item) => /* @__PURE__ */ jsxs(Combobox.Item, { item, children: [
100
+ /* @__PURE__ */ jsx(Combobox.ItemText, { children: item.label }),
101
+ /* @__PURE__ */ jsx(Combobox.ItemIndicator, {})
102
+ ] }, item.value))
103
+ ] }) }) })
104
+ ]
105
+ }
106
+ ),
107
+ /* @__PURE__ */ jsx(FieldError, { hasError, errorMessage, helperText: resolved.helperText })
108
+ ]
109
+ }
110
+ );
111
+ }
112
+ });
113
+ var FieldCheckboxCard = createField({
114
+ displayName: "FieldCheckboxCard",
115
+ render: ({ field, resolved, hasError, errorMessage, componentProps }) => {
116
+ const currentValue = field.state.value;
117
+ const valueArray = currentValue ?? [];
118
+ return /* @__PURE__ */ jsxs(Fieldset.Root, { invalid: hasError, disabled: resolved.disabled, children: [
119
+ /* @__PURE__ */ jsxs(
120
+ CheckboxGroup,
121
+ {
122
+ value: valueArray,
123
+ onValueChange: (value) => field.handleChange(value),
124
+ disabled: resolved.disabled,
125
+ invalid: hasError,
126
+ children: [
127
+ resolved.label && /* @__PURE__ */ jsxs(Fieldset.Legend, { mb: 2, children: [
128
+ resolved.tooltip ? /* @__PURE__ */ jsxs(HStack, { gap: 1, children: [
129
+ /* @__PURE__ */ jsx("span", { children: resolved.label }),
130
+ /* @__PURE__ */ jsx(FieldTooltip, { ...resolved.tooltip })
131
+ ] }) : resolved.label,
132
+ resolved.required && /* @__PURE__ */ jsx(
133
+ "span",
134
+ {
135
+ role: "presentation",
136
+ "aria-hidden": "true",
137
+ style: { color: "var(--chakra-colors-fg-error)", marginInlineStart: "1px" },
138
+ children: "*"
139
+ }
140
+ )
141
+ ] }),
142
+ /* @__PURE__ */ jsx(
143
+ Flex,
144
+ {
145
+ gap: componentProps.gap ?? 2,
146
+ direction: (componentProps.orientation ?? "horizontal") === "vertical" ? "column" : "row",
147
+ wrap: (componentProps.orientation ?? "horizontal") === "horizontal" ? "wrap" : void 0,
148
+ children: componentProps.options.map((opt) => /* @__PURE__ */ jsxs(
149
+ CheckboxCard.Root,
150
+ {
151
+ value: opt.value,
152
+ size: componentProps.size ?? "md",
153
+ variant: componentProps.variant ?? "outline",
154
+ colorPalette: componentProps.colorPalette,
155
+ align: componentProps.align ?? "start",
156
+ disabled: opt.disabled,
157
+ children: [
158
+ /* @__PURE__ */ jsx(CheckboxCard.HiddenInput, {}),
159
+ /* @__PURE__ */ jsxs(CheckboxCard.Control, { children: [
160
+ /* @__PURE__ */ jsxs(CheckboxCard.Content, { children: [
161
+ opt.icon,
162
+ /* @__PURE__ */ jsx(CheckboxCard.Label, { children: opt.label }),
163
+ opt.description && /* @__PURE__ */ jsx(CheckboxCard.Description, { children: opt.description })
164
+ ] }),
165
+ /* @__PURE__ */ jsx(CheckboxCard.Indicator, {})
166
+ ] })
167
+ ]
168
+ },
169
+ opt.value
170
+ ))
171
+ }
172
+ )
173
+ ]
174
+ }
175
+ ),
176
+ hasError ? /* @__PURE__ */ jsx(Fieldset.ErrorText, { children: errorMessage }) : resolved.helperText && /* @__PURE__ */ jsx(Fieldset.HelperText, { children: resolved.helperText })
177
+ ] });
178
+ }
179
+ });
180
+ var FieldCombobox = createField({
181
+ displayName: "FieldCombobox",
182
+ useFieldState: (componentProps, resolved) => {
183
+ const {
184
+ inputValue,
185
+ setInputValue,
186
+ isLoading,
187
+ data: queryData
188
+ } = useAsyncSearch({
189
+ useQuery: componentProps.useQuery,
190
+ debounce: componentProps.debounce ?? 300,
191
+ minChars: componentProps.minChars ?? 1
192
+ });
193
+ const { contains } = useFilter({ sensitivity: "base" });
194
+ const options = useMemo(() => {
195
+ if (componentProps.options) {
196
+ if (!inputValue) {
197
+ return componentProps.options;
198
+ }
199
+ return componentProps.options.filter((opt) => {
200
+ return contains(getOptionLabel(opt), inputValue);
201
+ });
202
+ }
203
+ if (queryData && componentProps.getLabel && componentProps.getValue) {
204
+ const getLabel = componentProps.getLabel;
205
+ const getValue = componentProps.getValue;
206
+ return queryData.map((item) => ({
207
+ label: getLabel(item),
208
+ value: getValue(item),
209
+ group: componentProps.getGroup?.(item),
210
+ disabled: componentProps.getDisabled?.(item)
211
+ }));
212
+ }
213
+ return [];
214
+ }, [
215
+ componentProps.options,
216
+ queryData,
217
+ componentProps.getLabel,
218
+ componentProps.getValue,
219
+ componentProps.getGroup,
220
+ componentProps.getDisabled,
221
+ inputValue,
222
+ contains
223
+ ]);
224
+ const { collection, groups } = useGroupedOptions(options);
225
+ const resolvedClearable = componentProps.clearable ?? !resolved.required;
226
+ return {
227
+ inputValue,
228
+ setInputValue,
229
+ isLoading,
230
+ options,
231
+ collection,
232
+ groups,
233
+ resolvedClearable
234
+ };
235
+ },
236
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps, fieldState }) => {
237
+ const currentValue = field.state.value;
238
+ const minChars = componentProps.minChars ?? 1;
239
+ return /* @__PURE__ */ jsxs(Field.Root, { invalid: hasError, required: resolved.required, disabled: resolved.disabled, children: [
240
+ /* @__PURE__ */ jsxs(
241
+ Combobox.Root,
242
+ {
243
+ collection: fieldState.collection,
244
+ size: componentProps.size ?? "md",
245
+ variant: componentProps.variant ?? "outline",
246
+ value: currentValue ? [currentValue] : [],
247
+ inputValue: fieldState.inputValue,
248
+ onInputValueChange: (details) => fieldState.setInputValue(details.inputValue),
249
+ onValueChange: (details) => {
250
+ const newValue = details.value[0];
251
+ field.handleChange(newValue ?? "");
252
+ },
253
+ onInteractOutside: () => field.handleBlur(),
254
+ disabled: resolved.disabled,
255
+ allowCustomValue: componentProps.allowCustomValue ?? false,
256
+ openOnClick: true,
257
+ "data-field-name": fullPath,
258
+ children: [
259
+ resolved.label && /* @__PURE__ */ jsx(Combobox.Label, { children: /* @__PURE__ */ jsx(SelectionFieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }) }),
260
+ /* @__PURE__ */ jsxs(Combobox.Control, { children: [
261
+ /* @__PURE__ */ jsx(Combobox.Input, { placeholder: resolved.placeholder ?? "Search..." }),
262
+ /* @__PURE__ */ jsxs(Combobox.IndicatorGroup, { children: [
263
+ fieldState.isLoading && /* @__PURE__ */ jsx(Spinner, { size: "xs" }),
264
+ fieldState.resolvedClearable && /* @__PURE__ */ jsx(Combobox.ClearTrigger, {}),
265
+ /* @__PURE__ */ jsx(Combobox.Trigger, {})
266
+ ] })
267
+ ] }),
268
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Combobox.Positioner, { children: /* @__PURE__ */ jsxs(Combobox.Content, { children: [
269
+ fieldState.isLoading && fieldState.options.length === 0 && /* @__PURE__ */ jsx(Combobox.Empty, { children: componentProps.loadingMessage ?? "Loading..." }),
270
+ !fieldState.isLoading && fieldState.options.length === 0 && fieldState.inputValue.length >= minChars && /* @__PURE__ */ jsx(Combobox.Empty, { children: componentProps.emptyMessage ?? "Nothing found" }),
271
+ !fieldState.isLoading && fieldState.options.length === 0 && fieldState.inputValue.length < minChars && fieldState.inputValue.length > 0 && /* @__PURE__ */ jsxs(Combobox.Empty, { children: [
272
+ "Enter at least ",
273
+ minChars,
274
+ " characters"
275
+ ] }),
276
+ fieldState.groups ? Array.from(fieldState.groups.entries()).map(([groupName, groupOptions]) => /* @__PURE__ */ jsxs(Combobox.ItemGroup, { children: [
277
+ groupName && /* @__PURE__ */ jsx(Combobox.ItemGroupLabel, { children: groupName }),
278
+ groupOptions.map((opt) => /* @__PURE__ */ jsxs(Combobox.Item, { item: opt, children: [
279
+ /* @__PURE__ */ jsx(Combobox.ItemText, { children: getOptionLabel(opt) }),
280
+ /* @__PURE__ */ jsx(Combobox.ItemIndicator, {})
281
+ ] }, opt.value))
282
+ ] }, groupName)) : (
283
+ /* Flat options */
284
+ fieldState.options.map((opt) => /* @__PURE__ */ jsxs(Combobox.Item, { item: opt, children: [
285
+ /* @__PURE__ */ jsx(Combobox.ItemText, { children: getOptionLabel(opt) }),
286
+ /* @__PURE__ */ jsx(Combobox.ItemIndicator, {})
287
+ ] }, opt.value))
288
+ )
289
+ ] }) }) })
290
+ ]
291
+ }
292
+ ),
293
+ /* @__PURE__ */ jsx(FieldError, { hasError, errorMessage, helperText: resolved.helperText })
294
+ ] });
295
+ }
296
+ });
297
+ var FieldListbox = createField({
298
+ displayName: "FieldListbox",
299
+ useFieldState: (componentProps) => {
300
+ return useGroupedOptions(componentProps.options);
301
+ },
302
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps, fieldState }) => {
303
+ const currentValue = field.state.value;
304
+ const valueArray = Array.isArray(currentValue) ? currentValue : currentValue ? [currentValue] : [];
305
+ const selectionMode = componentProps.selectionMode ?? "single";
306
+ return /* @__PURE__ */ jsxs(
307
+ Field.Root,
308
+ {
309
+ invalid: hasError,
310
+ required: resolved.required,
311
+ disabled: resolved.disabled,
312
+ readOnly: resolved.readOnly,
313
+ children: [
314
+ /* @__PURE__ */ jsxs(
315
+ Listbox.Root,
316
+ {
317
+ collection: fieldState.collection,
318
+ selectionMode,
319
+ orientation: componentProps.orientation ?? "vertical",
320
+ variant: componentProps.variant ?? "subtle",
321
+ colorPalette: componentProps.colorPalette,
322
+ value: valueArray,
323
+ onValueChange: (details) => {
324
+ if (selectionMode === "single") {
325
+ const newValue = details.value[0];
326
+ field.handleChange(newValue ?? "");
327
+ } else {
328
+ field.handleChange(details.value);
329
+ }
330
+ },
331
+ disabled: resolved.disabled,
332
+ "data-field-name": fullPath,
333
+ children: [
334
+ resolved.label && /* @__PURE__ */ jsx(Listbox.Label, { fontSize: componentProps.size ?? "md", children: /* @__PURE__ */ jsx(SelectionFieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }) }),
335
+ /* @__PURE__ */ jsx(Listbox.Content, { maxH: componentProps.maxHeight, children: fieldState.groups ? (
336
+ /* Grouped options */
337
+ Array.from(fieldState.groups.entries()).map(([groupName, groupOptions]) => /* @__PURE__ */ jsxs(Listbox.ItemGroup, { children: [
338
+ groupName && /* @__PURE__ */ jsx(Listbox.ItemGroupLabel, { children: groupName }),
339
+ groupOptions.map((opt) => /* @__PURE__ */ jsxs(Listbox.Item, { item: opt, children: [
340
+ /* @__PURE__ */ jsx(Listbox.ItemText, { children: getOptionLabel(opt) }),
341
+ /* @__PURE__ */ jsx(Listbox.ItemIndicator, {})
342
+ ] }, opt.value))
343
+ ] }, groupName))
344
+ ) : (
345
+ /* Flat options */
346
+ componentProps.options.map((opt) => /* @__PURE__ */ jsxs(Listbox.Item, { item: opt, children: [
347
+ /* @__PURE__ */ jsx(Listbox.ItemText, { children: getOptionLabel(opt) }),
348
+ /* @__PURE__ */ jsx(Listbox.ItemIndicator, {})
349
+ ] }, opt.value))
350
+ ) })
351
+ ]
352
+ }
353
+ ),
354
+ /* @__PURE__ */ jsx(FieldError, { hasError, errorMessage, helperText: resolved.helperText })
355
+ ]
356
+ }
357
+ );
358
+ }
359
+ });
360
+ var FieldNativeSelect = createField({
361
+ displayName: "FieldNativeSelect",
362
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps }) => /* @__PURE__ */ jsx(FieldWrapper, { resolved, hasError, errorMessage, fullPath, children: /* @__PURE__ */ jsxs(NativeSelect.Root, { children: [
363
+ /* @__PURE__ */ jsxs(
364
+ NativeSelect.Field,
365
+ {
366
+ value: field.state.value ?? "",
367
+ onChange: (e) => field.handleChange(e.target.value),
368
+ onBlur: field.handleBlur,
369
+ "data-field-name": fullPath,
370
+ children: [
371
+ resolved.placeholder && /* @__PURE__ */ jsx("option", { value: "", disabled: true, children: resolved.placeholder }),
372
+ componentProps.options.map((opt, idx) => /* @__PURE__ */ jsx("option", { value: opt.value, children: typeof opt.title === "string" ? opt.title : opt.value }, idx))
373
+ ]
374
+ }
375
+ ),
376
+ /* @__PURE__ */ jsx(NativeSelect.Indicator, {})
377
+ ] }) })
378
+ });
379
+ var FieldRadioCard = createField({
380
+ displayName: "FieldRadioCard",
381
+ useFieldState: (componentProps) => {
382
+ const enabledOptions = componentProps.options.filter((opt) => !opt.disabled);
383
+ const handleKeyDown = useCallback(
384
+ (e, currentValue, handleChange) => {
385
+ if (!componentProps.keyboardNavigation || enabledOptions.length === 0) {
386
+ return;
387
+ }
388
+ const isHorizontal = (componentProps.orientation ?? "horizontal") === "horizontal";
389
+ const prevKey = isHorizontal ? "ArrowLeft" : "ArrowUp";
390
+ const nextKey = isHorizontal ? "ArrowRight" : "ArrowDown";
391
+ if (e.key !== prevKey && e.key !== nextKey) {
392
+ return;
393
+ }
394
+ e.preventDefault();
395
+ const currentIndex = currentValue ? enabledOptions.findIndex((opt) => opt.value === currentValue) : -1;
396
+ let newIndex;
397
+ if (e.key === nextKey) {
398
+ newIndex = currentIndex === -1 ? 0 : (currentIndex + 1) % enabledOptions.length;
399
+ } else {
400
+ newIndex = currentIndex === -1 ? enabledOptions.length - 1 : (currentIndex - 1 + enabledOptions.length) % enabledOptions.length;
401
+ }
402
+ handleChange(enabledOptions[newIndex].value);
403
+ },
404
+ [componentProps.keyboardNavigation, enabledOptions, componentProps.orientation]
405
+ );
406
+ return { enabledOptions, handleKeyDown };
407
+ },
408
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps, fieldState }) => {
409
+ const currentValue = field.state.value;
410
+ return /* @__PURE__ */ jsxs(
411
+ Field.Root,
412
+ {
413
+ invalid: hasError,
414
+ required: resolved.required,
415
+ disabled: resolved.disabled,
416
+ readOnly: resolved.readOnly,
417
+ children: [
418
+ /* @__PURE__ */ jsxs(
419
+ RadioCard.Root,
420
+ {
421
+ value: currentValue ?? "",
422
+ onValueChange: (details) => field.handleChange(details.value),
423
+ onKeyDown: componentProps.keyboardNavigation ? (e) => fieldState.handleKeyDown(e, currentValue, field.handleChange) : void 0,
424
+ disabled: resolved.disabled,
425
+ name: fullPath,
426
+ size: componentProps.size ?? "md",
427
+ variant: componentProps.variant ?? "outline",
428
+ colorPalette: componentProps.colorPalette,
429
+ align: componentProps.align ?? "start",
430
+ orientation: componentProps.orientation ?? "horizontal",
431
+ gap: componentProps.gap ?? 2,
432
+ children: [
433
+ resolved.label && /* @__PURE__ */ jsx(RadioCard.Label, { children: /* @__PURE__ */ jsx(SelectionFieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }) }),
434
+ componentProps.options.map((opt) => /* @__PURE__ */ jsxs(RadioCard.Item, { value: opt.value, disabled: opt.disabled, children: [
435
+ /* @__PURE__ */ jsx(RadioCard.ItemHiddenInput, {}),
436
+ /* @__PURE__ */ jsxs(RadioCard.ItemControl, { children: [
437
+ /* @__PURE__ */ jsxs(RadioCard.ItemContent, { children: [
438
+ opt.icon,
439
+ /* @__PURE__ */ jsx(RadioCard.ItemText, { children: opt.label }),
440
+ opt.description && /* @__PURE__ */ jsx(RadioCard.ItemDescription, { children: opt.description })
441
+ ] }),
442
+ /* @__PURE__ */ jsx(RadioCard.ItemIndicator, {})
443
+ ] })
444
+ ] }, opt.value))
445
+ ]
446
+ }
447
+ ),
448
+ /* @__PURE__ */ jsx(FieldError, { hasError, errorMessage, helperText: resolved.helperText })
449
+ ]
450
+ }
451
+ );
452
+ }
453
+ });
454
+ var FieldRadioGroup = createField({
455
+ displayName: "FieldRadioGroup",
456
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps }) => /* @__PURE__ */ jsxs(
457
+ Field.Root,
458
+ {
459
+ invalid: hasError,
460
+ required: resolved.required,
461
+ disabled: resolved.disabled,
462
+ readOnly: resolved.readOnly,
463
+ children: [
464
+ /* @__PURE__ */ jsx(FieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }),
465
+ /* @__PURE__ */ jsx(
466
+ RadioGroup.Root,
467
+ {
468
+ value: field.state.value ?? void 0,
469
+ onValueChange: (details) => field.handleChange(details.value),
470
+ orientation: componentProps.orientation ?? "vertical",
471
+ size: componentProps.size ?? "md",
472
+ variant: componentProps.variant ?? "solid",
473
+ colorPalette: componentProps.colorPalette ?? "brand",
474
+ disabled: resolved.disabled,
475
+ readOnly: resolved.readOnly,
476
+ "data-field-name": fullPath,
477
+ display: "flex",
478
+ flexDirection: componentProps.orientation === "horizontal" ? "row" : "column",
479
+ gap: componentProps.orientation === "horizontal" ? 4 : 2,
480
+ flexWrap: "wrap",
481
+ children: componentProps.options.map((opt) => /* @__PURE__ */ jsxs(RadioGroup.Item, { value: opt.value, disabled: opt.disabled, children: [
482
+ /* @__PURE__ */ jsx(RadioGroup.ItemHiddenInput, { onBlur: field.handleBlur }),
483
+ /* @__PURE__ */ jsx(RadioGroup.ItemIndicator, {}),
484
+ /* @__PURE__ */ jsx(RadioGroup.ItemText, { children: getOptionLabel(opt) })
485
+ ] }, opt.value))
486
+ }
487
+ ),
488
+ /* @__PURE__ */ jsx(FieldError, { hasError, errorMessage, helperText: resolved.helperText })
489
+ ]
490
+ }
491
+ )
492
+ });
493
+ var FieldSegmentedGroup = createField({
494
+ displayName: "FieldSegmentedGroup",
495
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps }) => /* @__PURE__ */ jsxs(
496
+ Field.Root,
497
+ {
498
+ invalid: hasError,
499
+ required: resolved.required,
500
+ disabled: resolved.disabled,
501
+ readOnly: resolved.readOnly,
502
+ children: [
503
+ /* @__PURE__ */ jsx(FieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }),
504
+ /* @__PURE__ */ jsxs(
505
+ SegmentGroup.Root,
506
+ {
507
+ value: field.state.value ?? "",
508
+ onValueChange: (details) => field.handleChange(details.value),
509
+ disabled: resolved.disabled,
510
+ name: fullPath,
511
+ size: componentProps.size ?? "md",
512
+ orientation: componentProps.orientation ?? "horizontal",
513
+ colorPalette: componentProps.colorPalette,
514
+ children: [
515
+ /* @__PURE__ */ jsx(SegmentGroup.Indicator, {}),
516
+ componentProps.options.map((opt) => /* @__PURE__ */ jsxs(SegmentGroup.Item, { value: opt.value, disabled: opt.disabled, children: [
517
+ /* @__PURE__ */ jsx(SegmentGroup.ItemText, { children: opt.label }),
518
+ /* @__PURE__ */ jsx(SegmentGroup.ItemHiddenInput, {})
519
+ ] }, opt.value))
520
+ ]
521
+ }
522
+ ),
523
+ /* @__PURE__ */ jsx(FieldError, { hasError, errorMessage, helperText: resolved.helperText })
524
+ ]
525
+ }
526
+ )
527
+ });
528
+ var FieldSelect = createField({
529
+ displayName: "FieldSelect",
530
+ useFieldState: (componentProps, resolved) => {
531
+ const sourceOptions = componentProps.options ?? resolved.options ?? [];
532
+ const normalizedOptions = useMemo(
533
+ () => sourceOptions.map((opt) => ({
534
+ label: opt.label,
535
+ value: String(opt.value),
536
+ disabled: opt.disabled
537
+ })),
538
+ [sourceOptions]
539
+ );
540
+ const collection = useMemo(
541
+ () => createListCollection({
542
+ items: normalizedOptions,
543
+ itemToString: getOptionLabel,
544
+ itemToValue: (item) => item.value
545
+ }),
546
+ [normalizedOptions]
547
+ );
548
+ const resolvedClearable = componentProps.clearable ?? !resolved.required;
549
+ return { collection, normalizedOptions, resolvedClearable };
550
+ },
551
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps, fieldState }) => {
552
+ const currentValue = field.state.value;
553
+ const stringValue = currentValue !== null && currentValue !== void 0 ? String(currentValue) : void 0;
554
+ return /* @__PURE__ */ jsxs(Field.Root, { invalid: hasError, required: resolved.required, disabled: resolved.disabled, children: [
555
+ /* @__PURE__ */ jsxs(
556
+ Select.Root,
557
+ {
558
+ collection: fieldState.collection,
559
+ size: componentProps.size ?? "md",
560
+ variant: componentProps.variant ?? "outline",
561
+ value: stringValue ? [stringValue] : [],
562
+ onValueChange: (details) => {
563
+ const newStringValue = details.value[0];
564
+ if (componentProps.valueType === "number") {
565
+ field.handleChange(newStringValue ? Number(newStringValue) : 0);
566
+ } else {
567
+ field.handleChange(newStringValue ?? "");
568
+ }
569
+ },
570
+ onInteractOutside: () => field.handleBlur(),
571
+ disabled: resolved.disabled,
572
+ "data-field-name": fullPath,
573
+ children: [
574
+ /* @__PURE__ */ jsx(Select.HiddenSelect, {}),
575
+ resolved.label && /* @__PURE__ */ jsx(Select.Label, { children: /* @__PURE__ */ jsx(SelectionFieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }) }),
576
+ /* @__PURE__ */ jsxs(Select.Control, { children: [
577
+ /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.ValueText, { placeholder: resolved.placeholder }) }),
578
+ /* @__PURE__ */ jsxs(Select.IndicatorGroup, { children: [
579
+ fieldState.resolvedClearable && /* @__PURE__ */ jsx(Select.ClearTrigger, {}),
580
+ /* @__PURE__ */ jsx(Select.Indicator, {})
581
+ ] })
582
+ ] }),
583
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Select.Positioner, { children: /* @__PURE__ */ jsx(Select.Content, { children: fieldState.normalizedOptions.map((opt) => /* @__PURE__ */ jsxs(Select.Item, { item: opt, children: [
584
+ getOptionLabel(opt),
585
+ /* @__PURE__ */ jsx(Select.ItemIndicator, {})
586
+ ] }, opt.value)) }) }) })
587
+ ]
588
+ }
589
+ ),
590
+ /* @__PURE__ */ jsx(FieldError, { hasError, errorMessage, helperText: resolved.helperText })
591
+ ] });
592
+ }
593
+ });
594
+ var FieldTags = createField({
595
+ displayName: "FieldTags",
596
+ render: ({ field, fullPath, resolved, hasError, errorMessage, componentProps }) => {
597
+ const {
598
+ maxTags,
599
+ minTagLength = 1,
600
+ delimiter,
601
+ addOnBlur = false,
602
+ addOnPaste = true,
603
+ editable = false,
604
+ clearable = false,
605
+ size = "md",
606
+ variant = "outline",
607
+ colorPalette
608
+ } = componentProps;
609
+ const value = field.state.value ?? [];
610
+ const handleValueChange = (details) => {
611
+ field.handleChange(details.value);
612
+ };
613
+ const validateTag = (details) => {
614
+ return details.inputValue.length >= minTagLength;
615
+ };
616
+ return /* @__PURE__ */ jsxs(
617
+ Field.Root,
618
+ {
619
+ invalid: hasError,
620
+ required: resolved.required,
621
+ disabled: resolved.disabled,
622
+ readOnly: resolved.readOnly,
623
+ children: [
624
+ /* @__PURE__ */ jsxs(
625
+ TagsInput.Root,
626
+ {
627
+ value,
628
+ onValueChange: handleValueChange,
629
+ max: maxTags,
630
+ validate: validateTag,
631
+ delimiter,
632
+ blurBehavior: addOnBlur ? "add" : void 0,
633
+ addOnPaste,
634
+ editable,
635
+ disabled: resolved.disabled,
636
+ readOnly: resolved.readOnly,
637
+ size,
638
+ variant,
639
+ colorPalette,
640
+ "data-field-name": fullPath,
641
+ children: [
642
+ resolved.label && /* @__PURE__ */ jsx(TagsInput.Label, { children: /* @__PURE__ */ jsx(SelectionFieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }) }),
643
+ /* @__PURE__ */ jsxs(TagsInput.Control, { children: [
644
+ /* @__PURE__ */ jsx(TagsInput.Items, {}),
645
+ /* @__PURE__ */ jsx(TagsInput.Input, { placeholder: resolved.placeholder, onBlur: field.handleBlur }),
646
+ clearable && /* @__PURE__ */ jsx(TagsInput.ClearTrigger, {})
647
+ ] }),
648
+ /* @__PURE__ */ jsx(TagsInput.HiddenInput, {})
649
+ ]
650
+ }
651
+ ),
652
+ /* @__PURE__ */ jsx(FieldError, { hasError, errorMessage, helperText: resolved.helperText })
653
+ ]
654
+ }
655
+ );
656
+ }
657
+ });
658
+ function CascadingSelectContent({
659
+ parentValue,
660
+ form,
661
+ fullPath,
662
+ resolved,
663
+ loadOptions,
664
+ initialOptions,
665
+ clearOnParentChange,
666
+ disableWhenParentEmpty,
667
+ clearable,
668
+ size,
669
+ variant,
670
+ placeholderWhenDisabled
671
+ }) {
672
+ const [options, setOptions] = useState(initialOptions);
673
+ const [isLoading, setIsLoading] = useState(false);
674
+ const prevParentValueRef = useRef(parentValue);
675
+ const loadOptionsRef = useRef(loadOptions);
676
+ loadOptionsRef.current = loadOptions;
677
+ useEffect(() => {
678
+ const doLoad = async () => {
679
+ if (parentValue === void 0 || parentValue === null || parentValue === "") {
680
+ setOptions(initialOptions);
681
+ return;
682
+ }
683
+ setIsLoading(true);
684
+ try {
685
+ const result = await loadOptionsRef.current(parentValue);
686
+ const newOptions = Array.isArray(result) ? result : result.options;
687
+ setOptions(newOptions);
688
+ } catch (error) {
689
+ console.error("Error loading cascading select options:", error);
690
+ setOptions([]);
691
+ } finally {
692
+ setIsLoading(false);
693
+ }
694
+ };
695
+ void doLoad();
696
+ }, [parentValue, initialOptions]);
697
+ useEffect(() => {
698
+ if (clearOnParentChange && prevParentValueRef.current !== parentValue) {
699
+ if (prevParentValueRef.current !== void 0) {
700
+ form.setFieldValue(fullPath, "");
701
+ }
702
+ prevParentValueRef.current = parentValue;
703
+ }
704
+ }, [parentValue, clearOnParentChange, form, fullPath]);
705
+ const isParentEmpty = parentValue === void 0 || parentValue === null || parentValue === "";
706
+ const isDisabled = resolved.disabled || disableWhenParentEmpty && isParentEmpty;
707
+ const effectivePlaceholder = isParentEmpty && placeholderWhenDisabled ? placeholderWhenDisabled : resolved.placeholder;
708
+ const resolvedClearable = clearable ?? !resolved.required;
709
+ const collection = useMemo(
710
+ () => createListCollection({
711
+ items: options,
712
+ itemToString: getOptionLabel,
713
+ itemToValue: (item) => item.value
714
+ }),
715
+ [options]
716
+ );
717
+ return /* @__PURE__ */ jsx(form.Field, { name: fullPath, children: (field) => {
718
+ const { hasError, errorMessage } = getFieldErrors(field);
719
+ const currentValue = field.state.value;
720
+ return /* @__PURE__ */ jsxs(Field.Root, { invalid: hasError, required: resolved.required, disabled: isDisabled, children: [
721
+ /* @__PURE__ */ jsxs(
722
+ Select.Root,
723
+ {
724
+ collection,
725
+ size,
726
+ variant,
727
+ value: currentValue ? [currentValue] : [],
728
+ onValueChange: (details) => {
729
+ const newValue = details.value[0];
730
+ field.handleChange(newValue ?? "");
731
+ },
732
+ onInteractOutside: () => field.handleBlur(),
733
+ disabled: isDisabled,
734
+ "data-field-name": fullPath,
735
+ children: [
736
+ /* @__PURE__ */ jsx(Select.HiddenSelect, {}),
737
+ resolved.label && /* @__PURE__ */ jsx(Select.Label, { children: /* @__PURE__ */ jsx(SelectionFieldLabel, { label: resolved.label, tooltip: resolved.tooltip, required: resolved.required }) }),
738
+ /* @__PURE__ */ jsxs(Select.Control, { children: [
739
+ /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.ValueText, { placeholder: effectivePlaceholder }) }),
740
+ /* @__PURE__ */ jsxs(Select.IndicatorGroup, { children: [
741
+ isLoading && /* @__PURE__ */ jsx(Spinner, { size: "xs" }),
742
+ resolvedClearable && !isLoading && /* @__PURE__ */ jsx(Select.ClearTrigger, {}),
743
+ /* @__PURE__ */ jsx(Select.Indicator, {})
744
+ ] })
745
+ ] }),
746
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Select.Positioner, { children: /* @__PURE__ */ jsx(Select.Content, { children: options.map((opt) => /* @__PURE__ */ jsxs(Select.Item, { item: opt, children: [
747
+ getOptionLabel(opt),
748
+ /* @__PURE__ */ jsx(Select.ItemIndicator, {})
749
+ ] }, opt.value)) }) }) })
750
+ ]
751
+ }
752
+ ),
753
+ /* @__PURE__ */ jsx(FieldError, { hasError: !!hasError, errorMessage, helperText: resolved.helperText })
754
+ ] });
755
+ } });
756
+ }
757
+ function FieldCascadingSelect(props) {
758
+ const {
759
+ name,
760
+ dependsOn,
761
+ loadOptions,
762
+ initialOptions = [],
763
+ clearOnParentChange = true,
764
+ disableWhenParentEmpty = true,
765
+ clearable,
766
+ size = "md",
767
+ variant = "outline",
768
+ placeholderWhenDisabled,
769
+ ...baseProps
770
+ } = props;
771
+ const { form } = useDeclarativeForm();
772
+ const parentGroup = useFormGroup();
773
+ const { form: _formFromProps, fullPath, ...resolvedRest } = useResolvedFieldProps(name, baseProps);
774
+ const resolved = {
775
+ label: resolvedRest.label,
776
+ placeholder: resolvedRest.placeholder,
777
+ helperText: resolvedRest.helperText,
778
+ tooltip: resolvedRest.tooltip,
779
+ required: resolvedRest.required,
780
+ disabled: resolvedRest.disabled,
781
+ readOnly: resolvedRest.readOnly,
782
+ constraints: resolvedRest.constraints,
783
+ options: resolvedRest.options,
784
+ autocomplete: resolvedRest.autocomplete
785
+ };
786
+ const fullDependsOnPath = parentGroup ? `${parentGroup.name}.${dependsOn}` : dependsOn;
787
+ const parentSelector = (state) => {
788
+ const parts = fullDependsOnPath.split(".");
789
+ let value = state.values;
790
+ for (const part of parts) {
791
+ if (value && typeof value === "object") {
792
+ value = value[part];
793
+ } else {
794
+ value = void 0;
795
+ break;
796
+ }
797
+ }
798
+ return value;
799
+ };
800
+ return /* @__PURE__ */ jsx(form.Subscribe, { selector: parentSelector, children: (parentValue) => /* @__PURE__ */ jsx(
801
+ CascadingSelectContent,
802
+ {
803
+ parentValue,
804
+ form,
805
+ fullPath,
806
+ resolved,
807
+ loadOptions,
808
+ initialOptions,
809
+ clearOnParentChange,
810
+ disableWhenParentEmpty,
811
+ clearable,
812
+ size,
813
+ variant,
814
+ placeholderWhenDisabled
815
+ }
816
+ ) });
817
+ }
818
+ FieldCascadingSelect.displayName = "FieldCascadingSelect";
819
+
820
+ export { FieldAutocomplete, FieldCascadingSelect, FieldCheckboxCard, FieldCombobox, FieldListbox, FieldNativeSelect, FieldRadioCard, FieldRadioGroup, FieldSegmentedGroup, FieldSelect, FieldTags };
821
+ //# sourceMappingURL=chunk-MAYUFA5K.js.map
822
+ //# sourceMappingURL=chunk-MAYUFA5K.js.map