@page-speed/forms 0.5.1 → 0.5.3

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 (72) hide show
  1. package/README.md +29 -0
  2. package/dist/chunk-232KNGJI.js +207 -0
  3. package/dist/chunk-232KNGJI.js.map +1 -0
  4. package/dist/chunk-24RPM43T.js +373 -0
  5. package/dist/chunk-24RPM43T.js.map +1 -0
  6. package/dist/chunk-27JUYRDE.cjs +173 -0
  7. package/dist/chunk-27JUYRDE.cjs.map +1 -0
  8. package/dist/chunk-5NT5T5XY.js +4136 -0
  9. package/dist/chunk-5NT5T5XY.js.map +1 -0
  10. package/dist/chunk-AVAKC6R7.cjs +236 -0
  11. package/dist/chunk-AVAKC6R7.cjs.map +1 -0
  12. package/dist/chunk-DKLLPKZN.cjs +238 -0
  13. package/dist/chunk-DKLLPKZN.cjs.map +1 -0
  14. package/dist/chunk-EX6CRLKG.cjs +397 -0
  15. package/dist/chunk-EX6CRLKG.cjs.map +1 -0
  16. package/dist/chunk-H6NNFV64.js +127 -0
  17. package/dist/chunk-H6NNFV64.js.map +1 -0
  18. package/dist/chunk-JBEWTBFH.js +217 -0
  19. package/dist/chunk-JBEWTBFH.js.map +1 -0
  20. package/dist/chunk-JBEZLX3H.cjs +138 -0
  21. package/dist/chunk-JBEZLX3H.cjs.map +1 -0
  22. package/dist/chunk-VLGZG2VP.js +150 -0
  23. package/dist/chunk-VLGZG2VP.js.map +1 -0
  24. package/dist/chunk-ZYFTT6DB.cjs +4169 -0
  25. package/dist/chunk-ZYFTT6DB.cjs.map +1 -0
  26. package/dist/core.cjs +23 -722
  27. package/dist/core.cjs.map +1 -1
  28. package/dist/core.d.cts +3 -3
  29. package/dist/core.d.ts +3 -3
  30. package/dist/core.js +3 -705
  31. package/dist/core.js.map +1 -1
  32. package/dist/index.cjs +43 -727
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +1 -1
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.js +3 -705
  37. package/dist/index.js.map +1 -1
  38. package/dist/inputs.cjs +44 -4359
  39. package/dist/inputs.cjs.map +1 -1
  40. package/dist/inputs.d.cts +1 -1
  41. package/dist/inputs.d.ts +1 -1
  42. package/dist/inputs.js +2 -4337
  43. package/dist/inputs.js.map +1 -1
  44. package/dist/integration.cjs +574 -9
  45. package/dist/integration.cjs.map +1 -1
  46. package/dist/integration.d.cts +298 -1
  47. package/dist/integration.d.ts +298 -1
  48. package/dist/integration.js +566 -9
  49. package/dist/integration.js.map +1 -1
  50. package/dist/{types-DuX3q6A4.d.cts → types-CnOCn7b3.d.cts} +51 -1
  51. package/dist/{types-DuX3q6A4.d.ts → types-CnOCn7b3.d.ts} +51 -1
  52. package/dist/validation-rules.cjs +75 -231
  53. package/dist/validation-rules.cjs.map +1 -1
  54. package/dist/validation-rules.d.cts +1 -1
  55. package/dist/validation-rules.d.ts +1 -1
  56. package/dist/validation-rules.js +1 -215
  57. package/dist/validation-rules.js.map +1 -1
  58. package/dist/validation-utils.cjs +43 -133
  59. package/dist/validation-utils.cjs.map +1 -1
  60. package/dist/validation-utils.d.cts +1 -1
  61. package/dist/validation-utils.d.ts +1 -1
  62. package/dist/validation-utils.js +1 -125
  63. package/dist/validation-utils.js.map +1 -1
  64. package/dist/validation-valibot.d.cts +1 -1
  65. package/dist/validation-valibot.d.ts +1 -1
  66. package/dist/validation.cjs +115 -364
  67. package/dist/validation.cjs.map +1 -1
  68. package/dist/validation.d.cts +1 -1
  69. package/dist/validation.d.ts +1 -1
  70. package/dist/validation.js +2 -339
  71. package/dist/validation.js.map +1 -1
  72. package/package.json +1 -1
package/dist/core.js CHANGED
@@ -1,707 +1,5 @@
1
- import * as React4 from 'react';
2
- import { useRef, useCallback, useContext } from 'react';
3
- import { useObservable, useSelector } from '@legendapp/state/react';
4
- import { useMap } from '@opensite/hooks/useMap';
5
- import { clsx } from 'clsx';
6
- import { twMerge } from 'tailwind-merge';
7
- import { cva } from 'class-variance-authority';
8
- import { Label as Label$1, Slot } from 'radix-ui';
9
-
10
- // src/core/useForm.ts
11
- function useForm(options) {
12
- const {
13
- initialValues,
14
- validationSchema,
15
- validateOn = "onBlur",
16
- revalidateOn = "onChange",
17
- onSubmit,
18
- onError,
19
- debug = false
20
- } = options;
21
- const state$ = useObservable({
22
- values: initialValues,
23
- errors: {},
24
- touched: {},
25
- isSubmitting: false,
26
- status: "idle",
27
- initialValues: { ...initialValues },
28
- // Create a copy to prevent reference sharing
29
- hasValidated: {}
30
- });
31
- const validationInProgress = useRef(/* @__PURE__ */ new Set());
32
- const [, fieldMetadataActions] = useMap();
33
- const validateField = useCallback(
34
- async (field) => {
35
- const validators = validationSchema?.[field];
36
- if (!validators) return void 0;
37
- const fieldKey = String(field);
38
- validationInProgress.current.add(fieldKey);
39
- const currentMeta = fieldMetadataActions.get(fieldKey) || {
40
- validationCount: 0
41
- };
42
- fieldMetadataActions.set(fieldKey, {
43
- lastValidated: Date.now(),
44
- validationCount: currentMeta.validationCount + 1
45
- });
46
- try {
47
- const value = state$.values[field].get();
48
- const allValues = state$.values.get();
49
- const validatorArray = Array.isArray(validators) ? validators : [validators];
50
- for (const validator of validatorArray) {
51
- const error = await validator(value, allValues);
52
- if (error) {
53
- state$.errors[field].set(error);
54
- validationInProgress.current.delete(fieldKey);
55
- return error;
56
- }
57
- }
58
- state$.errors[field].set(void 0);
59
- validationInProgress.current.delete(fieldKey);
60
- return void 0;
61
- } catch (error) {
62
- validationInProgress.current.delete(fieldKey);
63
- const errorMessage = error instanceof Error ? error.message : "Validation error";
64
- state$.errors[field].set(errorMessage);
65
- return errorMessage;
66
- }
67
- },
68
- [validationSchema, state$, fieldMetadataActions]
69
- );
70
- const validateForm = useCallback(async () => {
71
- if (!validationSchema) return {};
72
- const fields = Object.keys(validationSchema);
73
- const errors2 = {};
74
- await Promise.all(
75
- fields.map(async (field) => {
76
- const error = await validateField(field);
77
- if (error) {
78
- errors2[field] = error;
79
- }
80
- })
81
- );
82
- state$.errors.set(errors2);
83
- return errors2;
84
- }, [validationSchema, validateField, state$]);
85
- const setFieldValue = useCallback(
86
- (field, value) => {
87
- state$.values[field].set(value);
88
- const shouldRevalidate = revalidateOn === "onChange" && state$.hasValidated[String(field)].get();
89
- if (shouldRevalidate && validationSchema?.[field]) {
90
- validateField(field);
91
- }
92
- if (debug) {
93
- console.log("[useForm] setFieldValue:", { field, value });
94
- }
95
- },
96
- [state$, revalidateOn, validationSchema, validateField, debug]
97
- );
98
- const setFieldTouched = useCallback(
99
- (field, touched2) => {
100
- state$.touched[field].set(touched2);
101
- if (touched2 && validateOn === "onBlur" && validationSchema?.[field]) {
102
- state$.hasValidated[String(field)].set(true);
103
- validateField(field);
104
- }
105
- if (debug) {
106
- console.log("[useForm] setFieldTouched:", { field, touched: touched2 });
107
- }
108
- },
109
- [state$, validateOn, validationSchema, validateField, debug]
110
- );
111
- const resetForm = useCallback(() => {
112
- state$.values.set(state$.initialValues.get());
113
- state$.errors.set({});
114
- state$.touched.set({});
115
- state$.isSubmitting.set(false);
116
- state$.status.set("idle");
117
- state$.hasValidated.set({});
118
- fieldMetadataActions.clear();
119
- if (debug) {
120
- console.log("[useForm] Form reset");
121
- }
122
- }, [state$, fieldMetadataActions, debug]);
123
- const handleSubmit = useCallback(
124
- async (e) => {
125
- e?.preventDefault();
126
- if (debug) {
127
- console.log("[useForm] handleSubmit started");
128
- }
129
- state$.isSubmitting.set(true);
130
- state$.status.set("submitting");
131
- try {
132
- const errors2 = await validateForm();
133
- const hasErrors = Object.keys(errors2).length > 0;
134
- if (hasErrors) {
135
- state$.status.set("error");
136
- onError?.(errors2);
137
- if (debug) {
138
- console.log("[useForm] Validation errors:", errors2);
139
- }
140
- return;
141
- }
142
- const helpers = {
143
- setValues: (values2) => {
144
- if (typeof values2 === "function") {
145
- state$.values.set(values2(state$.values.get()));
146
- } else {
147
- state$.values.set(values2);
148
- }
149
- },
150
- setFieldValue,
151
- setErrors: (errors3) => state$.errors.set(errors3),
152
- setFieldError: (field, error) => state$.errors[field].set(error),
153
- setTouched: (touched2) => state$.touched.set(touched2),
154
- setFieldTouched,
155
- setSubmitting: (submitting) => state$.isSubmitting.set(submitting),
156
- resetForm
157
- };
158
- await onSubmit(state$.values.get(), helpers);
159
- state$.status.set("success");
160
- if (debug) {
161
- console.log("[useForm] Submit successful");
162
- }
163
- } catch (error) {
164
- state$.status.set("error");
165
- if (debug) {
166
- console.error("[useForm] Submit error:", error);
167
- }
168
- throw error;
169
- } finally {
170
- state$.isSubmitting.set(false);
171
- }
172
- },
173
- [
174
- state$,
175
- validateForm,
176
- onSubmit,
177
- onError,
178
- setFieldValue,
179
- setFieldTouched,
180
- resetForm,
181
- debug
182
- ]
183
- );
184
- const getFieldProps = useCallback(
185
- (field) => {
186
- return {
187
- name: String(field),
188
- value: state$.values[field].get(),
189
- onChange: (value) => setFieldValue(field, value),
190
- onBlur: () => setFieldTouched(field, true)
191
- };
192
- },
193
- [state$, setFieldValue, setFieldTouched]
194
- );
195
- const getFieldMeta = useCallback(
196
- (field) => {
197
- const fieldKey = String(field);
198
- const metadata = fieldMetadataActions.get(fieldKey);
199
- return {
200
- error: state$.errors[field].get(),
201
- touched: state$.touched[field].get() ?? false,
202
- isDirty: state$.values[field].get() !== state$.initialValues[field].get(),
203
- isValidating: validationInProgress.current.has(fieldKey),
204
- // Additional metadata from @opensite/hooks
205
- validationCount: metadata?.validationCount,
206
- lastValidated: metadata?.lastValidated
207
- };
208
- },
209
- [state$, fieldMetadataActions]
210
- );
211
- const values = useSelector(() => state$.values.get());
212
- const errors = useSelector(() => state$.errors.get());
213
- const touched = useSelector(() => state$.touched.get());
214
- const isSubmitting = useSelector(() => state$.isSubmitting.get());
215
- const status = useSelector(() => state$.status.get());
216
- const isValid = useSelector(() => Object.keys(state$.errors.get()).length === 0);
217
- const isDirty = useSelector(() => {
218
- const currentValues = state$.values.get();
219
- const initialValues2 = state$.initialValues.get();
220
- return Object.keys(currentValues).some(
221
- (key) => currentValues[key] !== initialValues2[key]
222
- );
223
- });
224
- return {
225
- // State
226
- values,
227
- errors,
228
- touched,
229
- isSubmitting,
230
- isValid,
231
- isDirty,
232
- status,
233
- // Actions
234
- handleSubmit,
235
- setValues: (values2) => {
236
- if (typeof values2 === "function") {
237
- state$.values.set(values2(state$.values.get()));
238
- } else {
239
- state$.values.set(values2);
240
- }
241
- },
242
- setFieldValue,
243
- setErrors: (errors2) => state$.errors.set(errors2),
244
- setFieldError: (field, error) => state$.errors[field].set(error),
245
- setTouched: (touched2) => state$.touched.set(touched2),
246
- setFieldTouched,
247
- validateForm,
248
- validateField,
249
- resetForm,
250
- getFieldProps,
251
- getFieldMeta
252
- };
253
- }
254
- var FormContext = React4.createContext(null);
255
- FormContext.displayName = "FormContext";
256
-
257
- // src/core/useField.ts
258
- function useField(options) {
259
- const { name, validate, transform } = options;
260
- const form = useContext(FormContext);
261
- if (!form) {
262
- throw new Error(
263
- "useField must be used within a FormContext. Wrap your component with <Form> or use useForm's getFieldProps instead."
264
- );
265
- }
266
- const baseFieldProps = form.getFieldProps(name);
267
- const field = {
268
- ...baseFieldProps,
269
- value: baseFieldProps.value,
270
- onChange: (value) => {
271
- const transformedValue = transform ? transform(value) : value;
272
- baseFieldProps.onChange(transformedValue);
273
- if (validate) {
274
- const result = validate(transformedValue, form.values);
275
- if (result instanceof Promise) {
276
- result.then((error) => {
277
- if (error !== void 0) {
278
- form.setFieldError(name, error);
279
- }
280
- });
281
- } else if (result !== void 0) {
282
- form.setFieldError(name, result);
283
- }
284
- }
285
- }
286
- };
287
- const meta = form.getFieldMeta(name);
288
- const helpers = {
289
- setValue: useCallback(
290
- (value) => {
291
- const transformedValue = transform ? transform(value) : value;
292
- form.setFieldValue(name, transformedValue);
293
- },
294
- [name, transform, form]
295
- ),
296
- setTouched: useCallback(
297
- (touched) => {
298
- form.setFieldTouched(name, touched);
299
- },
300
- [name, form]
301
- ),
302
- setError: useCallback(
303
- (error) => {
304
- form.setFieldError(name, error);
305
- },
306
- [name, form]
307
- )
308
- };
309
- return {
310
- field,
311
- meta,
312
- helpers
313
- };
314
- }
315
- function cn(...inputs) {
316
- return twMerge(clsx(inputs));
317
- }
318
-
319
- // src/core/form-feedback.tsx
320
- function renderMessage(message, fallbackClassName, className) {
321
- if (typeof message === "string") {
322
- return /* @__PURE__ */ React4.createElement(
323
- "p",
324
- {
325
- className: cn(
326
- "text-sm font-medium text-center text-balance",
327
- className
328
- )
329
- },
330
- message
331
- );
332
- }
333
- return /* @__PURE__ */ React4.createElement("div", { className: cn(fallbackClassName, className) }, message);
334
- }
335
- function FormFeedback({
336
- successMessage,
337
- submissionError,
338
- successMessageClassName,
339
- errorMessageClassName
340
- }) {
341
- if (!successMessage && !submissionError) {
342
- return null;
343
- }
344
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, successMessage ? /* @__PURE__ */ React4.createElement(
345
- "div",
346
- {
347
- className: cn(
348
- "rounded-md border border-primary bg-primary px-4 py-3 shadow-sm",
349
- successMessageClassName
350
- ),
351
- role: "status",
352
- "aria-live": "polite"
353
- },
354
- renderMessage(
355
- successMessage,
356
- "text-primary-foreground",
357
- "text-primary-foreground"
358
- )
359
- ) : null, submissionError ? /* @__PURE__ */ React4.createElement(
360
- "div",
361
- {
362
- className: cn(
363
- "rounded-md border border-destructive bg-destructive px-4 py-3 shadow-sm",
364
- errorMessageClassName
365
- ),
366
- role: "alert",
367
- "aria-live": "assertive"
368
- },
369
- renderMessage(
370
- submissionError,
371
- "text-destructive-foreground",
372
- "text-destructive-foreground"
373
- )
374
- ) : null);
375
- }
376
- FormFeedback.displayName = "FormFeedback";
377
- var buttonVariants = cva(
378
- "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 aria-invalid:border-destructive",
379
- {
380
- variants: {
381
- variant: {
382
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
383
- destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20",
384
- outline: "border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground",
385
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
386
- ghost: "hover:bg-accent hover:text-accent-foreground",
387
- link: "text-primary underline-offset-4 hover:underline"
388
- },
389
- size: {
390
- default: "h-9 px-4 py-2 has-[>svg]:px-3",
391
- xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
392
- sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
393
- lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
394
- icon: "size-9",
395
- "icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
396
- "icon-sm": "size-8",
397
- "icon-lg": "size-10"
398
- }
399
- },
400
- defaultVariants: {
401
- variant: "default",
402
- size: "default"
403
- }
404
- }
405
- );
406
- function Button({
407
- className,
408
- variant = "default",
409
- size = "default",
410
- asChild = false,
411
- ...props
412
- }) {
413
- const Comp = asChild ? Slot.Root : "button";
414
- return /* @__PURE__ */ React4.createElement(
415
- Comp,
416
- {
417
- "data-slot": "button",
418
- "data-variant": variant,
419
- "data-size": size,
420
- className: cn(buttonVariants({ variant, size, className })),
421
- ...props
422
- }
423
- );
424
- }
425
-
426
- // src/core/Form.tsx
427
- function Form({
428
- form,
429
- children,
430
- className,
431
- action,
432
- method = "post",
433
- noValidate = true,
434
- submissionConfig,
435
- successMessage,
436
- submissionError,
437
- successMessageClassName,
438
- errorMessageClassName,
439
- onNewSubmission,
440
- ...props
441
- }) {
442
- const handleFormSubmit = React4.useCallback(
443
- async (e) => {
444
- try {
445
- await form.handleSubmit(e);
446
- } catch {
447
- }
448
- },
449
- [form]
450
- );
451
- const behavior = submissionConfig?.behavior || "showConfirmation";
452
- const shouldManageSubmissionUi = submissionConfig !== void 0 || successMessage !== void 0 || successMessageClassName !== void 0 || errorMessageClassName !== void 0 || submissionError != null || onNewSubmission !== void 0;
453
- const hasSubmissionError = Boolean(submissionError);
454
- const isSubmissionSuccessful = shouldManageSubmissionUi && form.status === "success" && !hasSubmissionError;
455
- const defaultSuccessMessage = behavior === "redirect" ? "Form submitted successfully. Redirecting..." : "Thank you. Your form has been submitted successfully.";
456
- const resolvedSuccessMessage = successMessage ?? defaultSuccessMessage;
457
- const shouldRenderCustomComponent = isSubmissionSuccessful && behavior === "renderCustomComponent" && Boolean(submissionConfig?.customComponent);
458
- const newSubmissionAction = submissionConfig?.newFormSubmissionAction;
459
- const showNewSubmissionAction = isSubmissionSuccessful && (typeof newSubmissionAction?.enable === "boolean" ? newSubmissionAction.enable : Boolean(newSubmissionAction?.label));
460
- const newSubmissionLabel = newSubmissionAction?.label ?? "Submit another response";
461
- const handleNewSubmission = React4.useCallback(() => {
462
- form.resetForm();
463
- onNewSubmission?.();
464
- }, [form, onNewSubmission]);
465
- return /* @__PURE__ */ React4.createElement(FormContext.Provider, { value: form }, /* @__PURE__ */ React4.createElement(
466
- "form",
467
- {
468
- onSubmit: handleFormSubmit,
469
- action,
470
- method,
471
- noValidate,
472
- className,
473
- ...props
474
- },
475
- isSubmissionSuccessful ? /* @__PURE__ */ React4.createElement("div", { className: "space-y-4" }, shouldRenderCustomComponent ? submissionConfig?.customComponent : /* @__PURE__ */ React4.createElement(
476
- FormFeedback,
477
- {
478
- successMessage: resolvedSuccessMessage,
479
- successMessageClassName
480
- }
481
- ), showNewSubmissionAction ? /* @__PURE__ */ React4.createElement(
482
- Button,
483
- {
484
- type: "button",
485
- variant: "outline",
486
- onClick: handleNewSubmission
487
- },
488
- newSubmissionLabel
489
- ) : null) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, children, submissionError ? /* @__PURE__ */ React4.createElement("div", { className: "mt-4" }, /* @__PURE__ */ React4.createElement(
490
- FormFeedback,
491
- {
492
- submissionError,
493
- errorMessageClassName
494
- }
495
- )) : null)
496
- ));
497
- }
498
- Form.displayName = "Form";
499
- function Label({
500
- className,
501
- ...props
502
- }) {
503
- return /* @__PURE__ */ React4.createElement(
504
- Label$1.Root,
505
- {
506
- "data-slot": "label",
507
- className: cn(
508
- "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
509
- className
510
- ),
511
- ...props
512
- }
513
- );
514
- }
515
-
516
- // src/components/ui/field.tsx
517
- var Field = React4.forwardRef(
518
- ({ className, orientation = "vertical", invalid = false, ...props }, ref) => {
519
- return /* @__PURE__ */ React4.createElement(
520
- "div",
521
- {
522
- ref,
523
- "data-slot": "field",
524
- "data-orientation": orientation,
525
- "data-invalid": invalid || void 0,
526
- className: cn(
527
- "flex",
528
- orientation === "horizontal" ? "items-center gap-2" : "flex-col gap-1.5",
529
- className
530
- ),
531
- ...props
532
- }
533
- );
534
- }
535
- );
536
- Field.displayName = "Field";
537
- var FieldGroup = React4.forwardRef(({ className, ...props }, ref) => {
538
- return /* @__PURE__ */ React4.createElement(
539
- "div",
540
- {
541
- ref,
542
- "data-slot": "field-group",
543
- className: cn("flex flex-col gap-4", className),
544
- ...props
545
- }
546
- );
547
- });
548
- FieldGroup.displayName = "FieldGroup";
549
- var FieldLabel = React4.forwardRef(({ className, required, children, ...props }, ref) => {
550
- return /* @__PURE__ */ React4.createElement(
551
- Label,
552
- {
553
- ref,
554
- "data-slot": "field-label",
555
- className: cn(
556
- "text-sm font-medium leading-none select-none",
557
- "peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
558
- className
559
- ),
560
- ...props
561
- },
562
- children,
563
- required && /* @__PURE__ */ React4.createElement("span", { className: "text-destructive ml-1" }, "*")
564
- );
565
- });
566
- FieldLabel.displayName = "FieldLabel";
567
- var FieldDescription = React4.forwardRef(({ className, ...props }, ref) => {
568
- return /* @__PURE__ */ React4.createElement(
569
- "p",
570
- {
571
- ref,
572
- "data-slot": "field-description",
573
- className: cn("text-sm opacity-70", className),
574
- ...props
575
- }
576
- );
577
- });
578
- FieldDescription.displayName = "FieldDescription";
579
- var FieldError = React4.forwardRef(({ className, ...props }, ref) => {
580
- return /* @__PURE__ */ React4.createElement(
581
- "p",
582
- {
583
- ref,
584
- "data-slot": "field-error",
585
- role: "alert",
586
- "aria-live": "polite",
587
- className: cn("text-sm text-destructive", className),
588
- ...props
589
- }
590
- );
591
- });
592
- FieldError.displayName = "FieldError";
593
-
594
- // src/core/field-feedback.tsx
595
- var FieldFeedback = ({
596
- errorId,
597
- errorClassName,
598
- error,
599
- shouldRenderError
600
- }) => {
601
- const errorText = Array.isArray(error) ? error.join(", ") : error;
602
- if (!errorText || !shouldRenderError) return null;
603
- return /* @__PURE__ */ React4.createElement(FieldError, { id: errorId, className: errorClassName }, errorText);
604
- };
605
- var LabelGroup = ({
606
- labelHtmlFor,
607
- required = false,
608
- variant = "label",
609
- secondaryId,
610
- secondary,
611
- primary,
612
- primaryClassName,
613
- secondaryClassName
614
- }) => {
615
- const primaryClasses = cn(
616
- "text-sm font-medium leading-snug",
617
- variant === "legend" ? "mb-1.5" : "mb-1 block",
618
- primaryClassName
619
- );
620
- const requiredIndicator = required && variant !== "label" ? /* @__PURE__ */ React4.createElement("span", { className: "text-destructive pl-0.5", "aria-label": "required" }, "*") : null;
621
- let primaryElement = null;
622
- if (primary) {
623
- if (variant === "label") {
624
- primaryElement = /* @__PURE__ */ React4.createElement(
625
- FieldLabel,
626
- {
627
- htmlFor: labelHtmlFor,
628
- required,
629
- className: primaryClasses
630
- },
631
- primary
632
- );
633
- } else if (variant === "legend") {
634
- primaryElement = /* @__PURE__ */ React4.createElement("legend", { "data-slot": "field-legend", className: primaryClasses }, primary, requiredIndicator);
635
- } else {
636
- primaryElement = /* @__PURE__ */ React4.createElement("div", { "data-slot": "field-label", className: primaryClasses }, primary, requiredIndicator);
637
- }
638
- }
639
- const secondaryElement = secondary ? /* @__PURE__ */ React4.createElement(
640
- FieldDescription,
641
- {
642
- id: secondaryId,
643
- className: cn("leading-normal font-normal", secondaryClassName)
644
- },
645
- secondary
646
- ) : null;
647
- if (!primaryElement && !secondaryElement) return null;
648
- if (variant === "legend") {
649
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, primaryElement, secondaryElement);
650
- }
651
- return /* @__PURE__ */ React4.createElement("div", { className: "flex flex-1 flex-col gap-0.5" }, primaryElement, secondaryElement);
652
- };
653
-
654
- // src/core/Field.tsx
655
- function Field2({
656
- name,
657
- label,
658
- description,
659
- children,
660
- showError = true,
661
- className,
662
- errorClassName,
663
- required = false,
664
- validate
665
- }) {
666
- const fieldState = useField({ name, validate });
667
- const { meta } = fieldState;
668
- const hasError = React4.useMemo(() => {
669
- return showError && meta.touched && meta.error ? true : false;
670
- }, [meta?.touched, meta?.error, showError]);
671
- const errorId = `${name}-error`;
672
- const descriptionId = `${name}-description`;
673
- return /* @__PURE__ */ React4.createElement(
674
- Field,
675
- {
676
- className,
677
- "data-field": name,
678
- invalid: hasError
679
- },
680
- /* @__PURE__ */ React4.createElement(
681
- LabelGroup,
682
- {
683
- labelHtmlFor: name,
684
- required,
685
- variant: "label",
686
- secondaryId: descriptionId,
687
- secondary: description,
688
- primary: label
689
- }
690
- ),
691
- /* @__PURE__ */ React4.createElement("div", { "data-slot": "field-control" }, typeof children === "function" ? children(fieldState) : children),
692
- /* @__PURE__ */ React4.createElement(
693
- FieldFeedback,
694
- {
695
- errorId,
696
- errorClassName,
697
- shouldRenderError: hasError,
698
- error: meta.error
699
- }
700
- )
701
- );
702
- }
703
- Field2.displayName = "Field";
704
-
705
- export { Field2 as Field, Form, FormContext, FormFeedback, useField, useForm };
1
+ export { Form, FormFeedback } from './chunk-VLGZG2VP.js';
2
+ export { Field, FormContext, useField, useForm } from './chunk-24RPM43T.js';
3
+ import './chunk-232KNGJI.js';
706
4
  //# sourceMappingURL=core.js.map
707
5
  //# sourceMappingURL=core.js.map