@page-speed/forms 0.5.2 → 0.5.4

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 (55) hide show
  1. package/dist/chunk-232KNGJI.js +207 -0
  2. package/dist/chunk-232KNGJI.js.map +1 -0
  3. package/dist/chunk-24RPM43T.js +373 -0
  4. package/dist/chunk-24RPM43T.js.map +1 -0
  5. package/dist/chunk-27JUYRDE.cjs +173 -0
  6. package/dist/chunk-27JUYRDE.cjs.map +1 -0
  7. package/dist/chunk-5NT5T5XY.js +4136 -0
  8. package/dist/chunk-5NT5T5XY.js.map +1 -0
  9. package/dist/chunk-AVAKC6R7.cjs +236 -0
  10. package/dist/chunk-AVAKC6R7.cjs.map +1 -0
  11. package/dist/chunk-DKLLPKZN.cjs +238 -0
  12. package/dist/chunk-DKLLPKZN.cjs.map +1 -0
  13. package/dist/chunk-EX6CRLKG.cjs +397 -0
  14. package/dist/chunk-EX6CRLKG.cjs.map +1 -0
  15. package/dist/chunk-H6NNFV64.js +127 -0
  16. package/dist/chunk-H6NNFV64.js.map +1 -0
  17. package/dist/chunk-JBEWTBFH.js +217 -0
  18. package/dist/chunk-JBEWTBFH.js.map +1 -0
  19. package/dist/chunk-JBEZLX3H.cjs +138 -0
  20. package/dist/chunk-JBEZLX3H.cjs.map +1 -0
  21. package/dist/chunk-VLGZG2VP.js +150 -0
  22. package/dist/chunk-VLGZG2VP.js.map +1 -0
  23. package/dist/chunk-ZYFTT6DB.cjs +4169 -0
  24. package/dist/chunk-ZYFTT6DB.cjs.map +1 -0
  25. package/dist/core.cjs +23 -733
  26. package/dist/core.cjs.map +1 -1
  27. package/dist/core.js +3 -716
  28. package/dist/core.js.map +1 -1
  29. package/dist/index.cjs +43 -738
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.js +3 -716
  32. package/dist/index.js.map +1 -1
  33. package/dist/inputs.cjs +44 -4359
  34. package/dist/inputs.cjs.map +1 -1
  35. package/dist/inputs.js +2 -4337
  36. package/dist/inputs.js.map +1 -1
  37. package/dist/integration.cjs +65 -4658
  38. package/dist/integration.cjs.map +1 -1
  39. package/dist/integration.d.cts +7 -1
  40. package/dist/integration.d.ts +7 -1
  41. package/dist/integration.js +42 -4635
  42. package/dist/integration.js.map +1 -1
  43. package/dist/validation-rules.cjs +75 -231
  44. package/dist/validation-rules.cjs.map +1 -1
  45. package/dist/validation-rules.js +1 -215
  46. package/dist/validation-rules.js.map +1 -1
  47. package/dist/validation-utils.cjs +43 -133
  48. package/dist/validation-utils.cjs.map +1 -1
  49. package/dist/validation-utils.js +1 -125
  50. package/dist/validation-utils.js.map +1 -1
  51. package/dist/validation.cjs +115 -364
  52. package/dist/validation.cjs.map +1 -1
  53. package/dist/validation.js +2 -339
  54. package/dist/validation.js.map +1 -1
  55. package/package.json +1 -1
package/dist/core.js CHANGED
@@ -1,718 +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,
433
- noValidate = true,
434
- submissionConfig,
435
- successMessage,
436
- submissionError,
437
- successMessageClassName,
438
- errorMessageClassName,
439
- onNewSubmission,
440
- notificationConfig,
441
- styleConfig,
442
- formConfig,
443
- ...props
444
- }) {
445
- const handleFormSubmit = React4.useCallback(
446
- async (e) => {
447
- try {
448
- await form.handleSubmit(e);
449
- } catch {
450
- }
451
- },
452
- [form]
453
- );
454
- const resolvedClassName = className ?? styleConfig?.formClassName;
455
- const resolvedAction = action ?? formConfig?.endpoint;
456
- const resolvedMethod = method ?? formConfig?.method ?? "post";
457
- const resolvedSubmissionConfig = submissionConfig ?? formConfig?.submissionConfig;
458
- const resolvedSuccessMessage = successMessage ?? notificationConfig?.successMessage;
459
- const resolvedSubmissionError = submissionError ?? notificationConfig?.submissionError;
460
- const resolvedSuccessMessageClassName = successMessageClassName ?? styleConfig?.successMessageClassName;
461
- const resolvedErrorMessageClassName = errorMessageClassName ?? styleConfig?.errorMessageClassName;
462
- const behavior = resolvedSubmissionConfig?.behavior || "showConfirmation";
463
- const shouldManageSubmissionUi = resolvedSubmissionConfig !== void 0 || resolvedSuccessMessage !== void 0 || resolvedSuccessMessageClassName !== void 0 || resolvedErrorMessageClassName !== void 0 || resolvedSubmissionError != null || onNewSubmission !== void 0;
464
- const hasSubmissionError = Boolean(resolvedSubmissionError);
465
- const isSubmissionSuccessful = shouldManageSubmissionUi && form.status === "success" && !hasSubmissionError;
466
- const defaultSuccessMessage = behavior === "redirect" ? "Form submitted successfully. Redirecting..." : "Thank you. Your form has been submitted successfully.";
467
- const finalSuccessMessage = resolvedSuccessMessage ?? defaultSuccessMessage;
468
- const shouldRenderCustomComponent = isSubmissionSuccessful && behavior === "renderCustomComponent" && Boolean(resolvedSubmissionConfig?.customComponent);
469
- const newSubmissionAction = resolvedSubmissionConfig?.newFormSubmissionAction;
470
- const showNewSubmissionAction = isSubmissionSuccessful && (typeof newSubmissionAction?.enable === "boolean" ? newSubmissionAction.enable : Boolean(newSubmissionAction?.label));
471
- const newSubmissionLabel = newSubmissionAction?.label ?? "Submit another response";
472
- const handleNewSubmission = React4.useCallback(() => {
473
- form.resetForm();
474
- onNewSubmission?.();
475
- }, [form, onNewSubmission]);
476
- return /* @__PURE__ */ React4.createElement(FormContext.Provider, { value: form }, /* @__PURE__ */ React4.createElement(
477
- "form",
478
- {
479
- onSubmit: handleFormSubmit,
480
- action: resolvedAction,
481
- method: resolvedMethod,
482
- noValidate,
483
- className: resolvedClassName,
484
- ...props
485
- },
486
- isSubmissionSuccessful ? /* @__PURE__ */ React4.createElement("div", { className: "space-y-4" }, shouldRenderCustomComponent ? resolvedSubmissionConfig?.customComponent : /* @__PURE__ */ React4.createElement(
487
- FormFeedback,
488
- {
489
- successMessage: finalSuccessMessage,
490
- successMessageClassName: resolvedSuccessMessageClassName
491
- }
492
- ), showNewSubmissionAction ? /* @__PURE__ */ React4.createElement(
493
- Button,
494
- {
495
- type: "button",
496
- variant: "outline",
497
- onClick: handleNewSubmission
498
- },
499
- newSubmissionLabel
500
- ) : null) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, children, resolvedSubmissionError ? /* @__PURE__ */ React4.createElement("div", { className: "mt-4" }, /* @__PURE__ */ React4.createElement(
501
- FormFeedback,
502
- {
503
- submissionError: resolvedSubmissionError,
504
- errorMessageClassName: resolvedErrorMessageClassName
505
- }
506
- )) : null)
507
- ));
508
- }
509
- Form.displayName = "Form";
510
- function Label({
511
- className,
512
- ...props
513
- }) {
514
- return /* @__PURE__ */ React4.createElement(
515
- Label$1.Root,
516
- {
517
- "data-slot": "label",
518
- className: cn(
519
- "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",
520
- className
521
- ),
522
- ...props
523
- }
524
- );
525
- }
526
-
527
- // src/components/ui/field.tsx
528
- var Field = React4.forwardRef(
529
- ({ className, orientation = "vertical", invalid = false, ...props }, ref) => {
530
- return /* @__PURE__ */ React4.createElement(
531
- "div",
532
- {
533
- ref,
534
- "data-slot": "field",
535
- "data-orientation": orientation,
536
- "data-invalid": invalid || void 0,
537
- className: cn(
538
- "flex",
539
- orientation === "horizontal" ? "items-center gap-2" : "flex-col gap-1.5",
540
- className
541
- ),
542
- ...props
543
- }
544
- );
545
- }
546
- );
547
- Field.displayName = "Field";
548
- var FieldGroup = React4.forwardRef(({ className, ...props }, ref) => {
549
- return /* @__PURE__ */ React4.createElement(
550
- "div",
551
- {
552
- ref,
553
- "data-slot": "field-group",
554
- className: cn("flex flex-col gap-4", className),
555
- ...props
556
- }
557
- );
558
- });
559
- FieldGroup.displayName = "FieldGroup";
560
- var FieldLabel = React4.forwardRef(({ className, required, children, ...props }, ref) => {
561
- return /* @__PURE__ */ React4.createElement(
562
- Label,
563
- {
564
- ref,
565
- "data-slot": "field-label",
566
- className: cn(
567
- "text-sm font-medium leading-none select-none",
568
- "peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
569
- className
570
- ),
571
- ...props
572
- },
573
- children,
574
- required && /* @__PURE__ */ React4.createElement("span", { className: "text-destructive ml-1" }, "*")
575
- );
576
- });
577
- FieldLabel.displayName = "FieldLabel";
578
- var FieldDescription = React4.forwardRef(({ className, ...props }, ref) => {
579
- return /* @__PURE__ */ React4.createElement(
580
- "p",
581
- {
582
- ref,
583
- "data-slot": "field-description",
584
- className: cn("text-sm opacity-70", className),
585
- ...props
586
- }
587
- );
588
- });
589
- FieldDescription.displayName = "FieldDescription";
590
- var FieldError = React4.forwardRef(({ className, ...props }, ref) => {
591
- return /* @__PURE__ */ React4.createElement(
592
- "p",
593
- {
594
- ref,
595
- "data-slot": "field-error",
596
- role: "alert",
597
- "aria-live": "polite",
598
- className: cn("text-sm text-destructive", className),
599
- ...props
600
- }
601
- );
602
- });
603
- FieldError.displayName = "FieldError";
604
-
605
- // src/core/field-feedback.tsx
606
- var FieldFeedback = ({
607
- errorId,
608
- errorClassName,
609
- error,
610
- shouldRenderError
611
- }) => {
612
- const errorText = Array.isArray(error) ? error.join(", ") : error;
613
- if (!errorText || !shouldRenderError) return null;
614
- return /* @__PURE__ */ React4.createElement(FieldError, { id: errorId, className: errorClassName }, errorText);
615
- };
616
- var LabelGroup = ({
617
- labelHtmlFor,
618
- required = false,
619
- variant = "label",
620
- secondaryId,
621
- secondary,
622
- primary,
623
- primaryClassName,
624
- secondaryClassName
625
- }) => {
626
- const primaryClasses = cn(
627
- "text-sm font-medium leading-snug",
628
- variant === "legend" ? "mb-1.5" : "mb-1 block",
629
- primaryClassName
630
- );
631
- const requiredIndicator = required && variant !== "label" ? /* @__PURE__ */ React4.createElement("span", { className: "text-destructive pl-0.5", "aria-label": "required" }, "*") : null;
632
- let primaryElement = null;
633
- if (primary) {
634
- if (variant === "label") {
635
- primaryElement = /* @__PURE__ */ React4.createElement(
636
- FieldLabel,
637
- {
638
- htmlFor: labelHtmlFor,
639
- required,
640
- className: primaryClasses
641
- },
642
- primary
643
- );
644
- } else if (variant === "legend") {
645
- primaryElement = /* @__PURE__ */ React4.createElement("legend", { "data-slot": "field-legend", className: primaryClasses }, primary, requiredIndicator);
646
- } else {
647
- primaryElement = /* @__PURE__ */ React4.createElement("div", { "data-slot": "field-label", className: primaryClasses }, primary, requiredIndicator);
648
- }
649
- }
650
- const secondaryElement = secondary ? /* @__PURE__ */ React4.createElement(
651
- FieldDescription,
652
- {
653
- id: secondaryId,
654
- className: cn("leading-normal font-normal", secondaryClassName)
655
- },
656
- secondary
657
- ) : null;
658
- if (!primaryElement && !secondaryElement) return null;
659
- if (variant === "legend") {
660
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, primaryElement, secondaryElement);
661
- }
662
- return /* @__PURE__ */ React4.createElement("div", { className: "flex flex-1 flex-col gap-0.5" }, primaryElement, secondaryElement);
663
- };
664
-
665
- // src/core/Field.tsx
666
- function Field2({
667
- name,
668
- label,
669
- description,
670
- children,
671
- showError = true,
672
- className,
673
- errorClassName,
674
- required = false,
675
- validate
676
- }) {
677
- const fieldState = useField({ name, validate });
678
- const { meta } = fieldState;
679
- const hasError = React4.useMemo(() => {
680
- return showError && meta.touched && meta.error ? true : false;
681
- }, [meta?.touched, meta?.error, showError]);
682
- const errorId = `${name}-error`;
683
- const descriptionId = `${name}-description`;
684
- return /* @__PURE__ */ React4.createElement(
685
- Field,
686
- {
687
- className,
688
- "data-field": name,
689
- invalid: hasError
690
- },
691
- /* @__PURE__ */ React4.createElement(
692
- LabelGroup,
693
- {
694
- labelHtmlFor: name,
695
- required,
696
- variant: "label",
697
- secondaryId: descriptionId,
698
- secondary: description,
699
- primary: label
700
- }
701
- ),
702
- /* @__PURE__ */ React4.createElement("div", { "data-slot": "field-control" }, typeof children === "function" ? children(fieldState) : children),
703
- /* @__PURE__ */ React4.createElement(
704
- FieldFeedback,
705
- {
706
- errorId,
707
- errorClassName,
708
- shouldRenderError: hasError,
709
- error: meta.error
710
- }
711
- )
712
- );
713
- }
714
- Field2.displayName = "Field";
715
-
716
- 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';
717
4
  //# sourceMappingURL=core.js.map
718
5
  //# sourceMappingURL=core.js.map