@vritti/quantum-ui 0.1.10 → 0.1.12

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 (60) hide show
  1. package/dist/AuthProvider.d.ts +25 -2
  2. package/dist/Button.js +3 -43
  3. package/dist/Button.js.map +1 -1
  4. package/dist/Checkbox.d.ts +10 -1
  5. package/dist/Checkbox.js +35 -7
  6. package/dist/Checkbox.js.map +1 -1
  7. package/dist/Form.d.ts +21 -0
  8. package/dist/Form.js +662 -0
  9. package/dist/Form.js.map +1 -0
  10. package/dist/OTPField.d.ts +3 -3
  11. package/dist/OTPField.js +135 -0
  12. package/dist/OTPField.js.map +1 -0
  13. package/dist/OnboardingProvider.js +91 -0
  14. package/dist/OnboardingProvider.js.map +1 -0
  15. package/dist/PasswordField.d.ts +3 -3
  16. package/dist/PasswordField.js +63 -57
  17. package/dist/PasswordField.js.map +1 -1
  18. package/dist/PhoneField.d.ts +3 -3
  19. package/dist/PhoneField.js +55 -58
  20. package/dist/PhoneField.js.map +1 -1
  21. package/dist/TextArea.d.ts +11 -0
  22. package/dist/TextArea.js +54 -0
  23. package/dist/TextArea.js.map +1 -0
  24. package/dist/TextField.d.ts +3 -3
  25. package/dist/TextField.js +26 -39
  26. package/dist/TextField.js.map +1 -1
  27. package/dist/assets/quantum-ui.css +126 -1
  28. package/dist/components/Form.d.ts +2 -0
  29. package/dist/components/Form.js +2 -0
  30. package/dist/components/Form.js.map +1 -0
  31. package/dist/components/OTPField.js +1 -134
  32. package/dist/components/OTPField.js.map +1 -1
  33. package/dist/components/Progress.js +2 -2
  34. package/dist/components/TextArea.d.ts +2 -0
  35. package/dist/components/TextArea.js +2 -0
  36. package/dist/components/TextArea.js.map +1 -0
  37. package/dist/context/AuthProvider.d.ts +2 -7
  38. package/dist/context/AuthProvider.js +1 -1
  39. package/dist/field.js +431 -0
  40. package/dist/field.js.map +1 -0
  41. package/dist/index.d.ts +320 -27
  42. package/dist/index.js +5 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/index2.js +116 -54
  45. package/dist/index2.js.map +1 -1
  46. package/dist/index3.js +42 -38
  47. package/dist/index3.js.map +1 -1
  48. package/dist/index4.js +54 -116
  49. package/dist/index4.js.map +1 -1
  50. package/dist/index5.js +41 -0
  51. package/dist/index5.js.map +1 -0
  52. package/dist/shadcn/shadcnField.d.ts +1 -0
  53. package/dist/shadcn/shadcnField.js +2 -0
  54. package/dist/shadcn/shadcnField.js.map +1 -0
  55. package/dist/shadcnField.d.ts +1 -0
  56. package/package.json +21 -4
  57. package/dist/AuthProvider.js +0 -137
  58. package/dist/AuthProvider.js.map +0 -1
  59. package/dist/Label.js +0 -40
  60. package/dist/Label.js.map +0 -1
package/dist/Form.js ADDED
@@ -0,0 +1,662 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import React__default from 'react';
3
+ import { C as Checkbox } from './Checkbox.js';
4
+
5
+ var isCheckBoxInput = (element) => element.type === 'checkbox';
6
+
7
+ var isDateObject = (value) => value instanceof Date;
8
+
9
+ var isNullOrUndefined = (value) => value == null;
10
+
11
+ const isObjectType = (value) => typeof value === 'object';
12
+ var isObject = (value) => !isNullOrUndefined(value) &&
13
+ !Array.isArray(value) &&
14
+ isObjectType(value) &&
15
+ !isDateObject(value);
16
+
17
+ var getEventValue = (event) => isObject(event) && event.target
18
+ ? isCheckBoxInput(event.target)
19
+ ? event.target.checked
20
+ : event.target.value
21
+ : event;
22
+
23
+ var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
24
+
25
+ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
26
+
27
+ var isPlainObject = (tempObject) => {
28
+ const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
29
+ return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
30
+ };
31
+
32
+ var isWeb = typeof window !== 'undefined' &&
33
+ typeof window.HTMLElement !== 'undefined' &&
34
+ typeof document !== 'undefined';
35
+
36
+ function cloneObject(data) {
37
+ let copy;
38
+ const isArray = Array.isArray(data);
39
+ const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
40
+ if (data instanceof Date) {
41
+ copy = new Date(data);
42
+ }
43
+ else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
44
+ (isArray || isObject(data))) {
45
+ copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
46
+ if (!isArray && !isPlainObject(data)) {
47
+ copy = data;
48
+ }
49
+ else {
50
+ for (const key in data) {
51
+ if (data.hasOwnProperty(key)) {
52
+ copy[key] = cloneObject(data[key]);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ else {
58
+ return data;
59
+ }
60
+ return copy;
61
+ }
62
+
63
+ var isKey = (value) => /^\w*$/.test(value);
64
+
65
+ var isUndefined = (val) => val === undefined;
66
+
67
+ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
68
+
69
+ var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
70
+
71
+ var get = (object, path, defaultValue) => {
72
+ if (!path || !isObject(object)) {
73
+ return defaultValue;
74
+ }
75
+ const result = (isKey(path) ? [path] : stringToPath(path)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
76
+ return isUndefined(result) || result === object
77
+ ? isUndefined(object[path])
78
+ ? defaultValue
79
+ : object[path]
80
+ : result;
81
+ };
82
+
83
+ var isBoolean = (value) => typeof value === 'boolean';
84
+
85
+ var set = (object, path, value) => {
86
+ let index = -1;
87
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
88
+ const length = tempPath.length;
89
+ const lastIndex = length - 1;
90
+ while (++index < length) {
91
+ const key = tempPath[index];
92
+ let newValue = value;
93
+ if (index !== lastIndex) {
94
+ const objValue = object[key];
95
+ newValue =
96
+ isObject(objValue) || Array.isArray(objValue)
97
+ ? objValue
98
+ : !isNaN(+tempPath[index + 1])
99
+ ? []
100
+ : {};
101
+ }
102
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
103
+ return;
104
+ }
105
+ object[key] = newValue;
106
+ object = object[key];
107
+ }
108
+ };
109
+
110
+ const EVENTS = {
111
+ BLUR: 'blur',
112
+ CHANGE: 'change',
113
+ };
114
+ const VALIDATION_MODE = {
115
+ all: 'all',
116
+ };
117
+
118
+ const HookFormContext = React__default.createContext(null);
119
+ HookFormContext.displayName = 'HookFormContext';
120
+ /**
121
+ * This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
122
+ *
123
+ * @remarks
124
+ * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
125
+ *
126
+ * @returns return all useForm methods
127
+ *
128
+ * @example
129
+ * ```tsx
130
+ * function App() {
131
+ * const methods = useForm();
132
+ * const onSubmit = data => console.log(data);
133
+ *
134
+ * return (
135
+ * <FormProvider {...methods} >
136
+ * <form onSubmit={methods.handleSubmit(onSubmit)}>
137
+ * <NestedInput />
138
+ * <input type="submit" />
139
+ * </form>
140
+ * </FormProvider>
141
+ * );
142
+ * }
143
+ *
144
+ * function NestedInput() {
145
+ * const { register } = useFormContext(); // retrieve all hook methods
146
+ * return <input {...register("test")} />;
147
+ * }
148
+ * ```
149
+ */
150
+ const useFormContext = () => React__default.useContext(HookFormContext);
151
+ /**
152
+ * A provider component that propagates the `useForm` methods to all children components via [React Context](https://react.dev/reference/react/useContext) API. To be used with {@link useFormContext}.
153
+ *
154
+ * @remarks
155
+ * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
156
+ *
157
+ * @param props - all useForm methods
158
+ *
159
+ * @example
160
+ * ```tsx
161
+ * function App() {
162
+ * const methods = useForm();
163
+ * const onSubmit = data => console.log(data);
164
+ *
165
+ * return (
166
+ * <FormProvider {...methods} >
167
+ * <form onSubmit={methods.handleSubmit(onSubmit)}>
168
+ * <NestedInput />
169
+ * <input type="submit" />
170
+ * </form>
171
+ * </FormProvider>
172
+ * );
173
+ * }
174
+ *
175
+ * function NestedInput() {
176
+ * const { register } = useFormContext(); // retrieve all hook methods
177
+ * return <input {...register("test")} />;
178
+ * }
179
+ * ```
180
+ */
181
+ const FormProvider = (props) => {
182
+ const { children, ...data } = props;
183
+ return (React__default.createElement(HookFormContext.Provider, { value: data }, children));
184
+ };
185
+
186
+ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
187
+ const result = {
188
+ defaultValues: control._defaultValues,
189
+ };
190
+ for (const key in formState) {
191
+ Object.defineProperty(result, key, {
192
+ get: () => {
193
+ const _key = key;
194
+ if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
195
+ control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
196
+ }
197
+ localProxyFormState && (localProxyFormState[_key] = true);
198
+ return formState[_key];
199
+ },
200
+ });
201
+ }
202
+ return result;
203
+ };
204
+
205
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__default.useLayoutEffect : React__default.useEffect;
206
+
207
+ /**
208
+ * This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
209
+ *
210
+ * @remarks
211
+ * [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
212
+ *
213
+ * @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
214
+ *
215
+ * @example
216
+ * ```tsx
217
+ * function App() {
218
+ * const { register, handleSubmit, control } = useForm({
219
+ * defaultValues: {
220
+ * firstName: "firstName"
221
+ * }});
222
+ * const { dirtyFields } = useFormState({
223
+ * control
224
+ * });
225
+ * const onSubmit = (data) => console.log(data);
226
+ *
227
+ * return (
228
+ * <form onSubmit={handleSubmit(onSubmit)}>
229
+ * <input {...register("firstName")} placeholder="First Name" />
230
+ * {dirtyFields.firstName && <p>Field is dirty.</p>}
231
+ * <input type="submit" />
232
+ * </form>
233
+ * );
234
+ * }
235
+ * ```
236
+ */
237
+ function useFormState(props) {
238
+ const methods = useFormContext();
239
+ const { control = methods.control, disabled, name, exact } = props || {};
240
+ const [formState, updateFormState] = React__default.useState(control._formState);
241
+ const _localProxyFormState = React__default.useRef({
242
+ isDirty: false,
243
+ isLoading: false,
244
+ dirtyFields: false,
245
+ touchedFields: false,
246
+ validatingFields: false,
247
+ isValidating: false,
248
+ isValid: false,
249
+ errors: false,
250
+ });
251
+ useIsomorphicLayoutEffect(() => control._subscribe({
252
+ name,
253
+ formState: _localProxyFormState.current,
254
+ exact,
255
+ callback: (formState) => {
256
+ !disabled &&
257
+ updateFormState({
258
+ ...control._formState,
259
+ ...formState,
260
+ });
261
+ },
262
+ }), [name, disabled, exact]);
263
+ React__default.useEffect(() => {
264
+ _localProxyFormState.current.isValid && control._setValid(true);
265
+ }, [control]);
266
+ return React__default.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
267
+ }
268
+
269
+ var isString = (value) => typeof value === 'string';
270
+
271
+ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
272
+ if (isString(names)) {
273
+ return get(formValues, names, defaultValue);
274
+ }
275
+ if (Array.isArray(names)) {
276
+ return names.map((fieldName) => (get(formValues, fieldName)));
277
+ }
278
+ return formValues;
279
+ };
280
+
281
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
282
+
283
+ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
284
+ if (isPrimitive(object1) || isPrimitive(object2)) {
285
+ return object1 === object2;
286
+ }
287
+ if (isDateObject(object1) && isDateObject(object2)) {
288
+ return object1.getTime() === object2.getTime();
289
+ }
290
+ const keys1 = Object.keys(object1);
291
+ const keys2 = Object.keys(object2);
292
+ if (keys1.length !== keys2.length) {
293
+ return false;
294
+ }
295
+ if (_internal_visited.has(object1) || _internal_visited.has(object2)) {
296
+ return true;
297
+ }
298
+ _internal_visited.add(object1);
299
+ _internal_visited.add(object2);
300
+ for (const key of keys1) {
301
+ const val1 = object1[key];
302
+ if (!keys2.includes(key)) {
303
+ return false;
304
+ }
305
+ if (key !== 'ref') {
306
+ const val2 = object2[key];
307
+ if ((isDateObject(val1) && isDateObject(val2)) ||
308
+ (isObject(val1) && isObject(val2)) ||
309
+ (Array.isArray(val1) && Array.isArray(val2))
310
+ ? !deepEqual(val1, val2, _internal_visited)
311
+ : val1 !== val2) {
312
+ return false;
313
+ }
314
+ }
315
+ }
316
+ return true;
317
+ }
318
+
319
+ /**
320
+ * Custom hook to subscribe to field change and isolate re-rendering at the component level.
321
+ *
322
+ * @remarks
323
+ *
324
+ * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
325
+ *
326
+ * @example
327
+ * ```tsx
328
+ * const { control } = useForm();
329
+ * const values = useWatch({
330
+ * name: "fieldName"
331
+ * control,
332
+ * })
333
+ * ```
334
+ */
335
+ function useWatch(props) {
336
+ const methods = useFormContext();
337
+ const { control = methods.control, name, defaultValue, disabled, exact, compute, } = props || {};
338
+ const _defaultValue = React__default.useRef(defaultValue);
339
+ const _compute = React__default.useRef(compute);
340
+ const _computeFormValues = React__default.useRef(undefined);
341
+ const _prevControl = React__default.useRef(control);
342
+ const _prevName = React__default.useRef(name);
343
+ _compute.current = compute;
344
+ const [value, updateValue] = React__default.useState(() => {
345
+ const defaultValue = control._getWatch(name, _defaultValue.current);
346
+ return _compute.current ? _compute.current(defaultValue) : defaultValue;
347
+ });
348
+ const getCurrentOutput = React__default.useCallback((values) => {
349
+ const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
350
+ return _compute.current ? _compute.current(formValues) : formValues;
351
+ }, [control._formValues, control._names, name]);
352
+ const refreshValue = React__default.useCallback((values) => {
353
+ if (!disabled) {
354
+ const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
355
+ if (_compute.current) {
356
+ const computedFormValues = _compute.current(formValues);
357
+ if (!deepEqual(computedFormValues, _computeFormValues.current)) {
358
+ updateValue(computedFormValues);
359
+ _computeFormValues.current = computedFormValues;
360
+ }
361
+ }
362
+ else {
363
+ updateValue(formValues);
364
+ }
365
+ }
366
+ }, [control._formValues, control._names, disabled, name]);
367
+ useIsomorphicLayoutEffect(() => {
368
+ if (_prevControl.current !== control ||
369
+ !deepEqual(_prevName.current, name)) {
370
+ _prevControl.current = control;
371
+ _prevName.current = name;
372
+ refreshValue();
373
+ }
374
+ return control._subscribe({
375
+ name,
376
+ formState: {
377
+ values: true,
378
+ },
379
+ exact,
380
+ callback: (formState) => {
381
+ refreshValue(formState.values);
382
+ },
383
+ });
384
+ }, [control, exact, name, refreshValue]);
385
+ React__default.useEffect(() => control._removeUnmounted());
386
+ // If name or control changed for this render, synchronously reflect the
387
+ // latest value so callers (like useController) see the correct value
388
+ // immediately on the same render.
389
+ // Optimize: Check control reference first before expensive deepEqual
390
+ const controlChanged = _prevControl.current !== control;
391
+ const prevName = _prevName.current;
392
+ // Cache the computed output to avoid duplicate calls within the same render
393
+ // We include shouldReturnImmediate in deps to ensure proper recomputation
394
+ const computedOutput = React__default.useMemo(() => {
395
+ if (disabled) {
396
+ return null;
397
+ }
398
+ const nameChanged = !controlChanged && !deepEqual(prevName, name);
399
+ const shouldReturnImmediate = controlChanged || nameChanged;
400
+ return shouldReturnImmediate ? getCurrentOutput() : null;
401
+ }, [disabled, controlChanged, name, prevName, getCurrentOutput]);
402
+ return computedOutput !== null ? computedOutput : value;
403
+ }
404
+
405
+ /**
406
+ * Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
407
+ *
408
+ * @remarks
409
+ * [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
410
+ *
411
+ * @param props - the path name to the form field value, and validation rules.
412
+ *
413
+ * @returns field properties, field and form state. {@link UseControllerReturn}
414
+ *
415
+ * @example
416
+ * ```tsx
417
+ * function Input(props) {
418
+ * const { field, fieldState, formState } = useController(props);
419
+ * return (
420
+ * <div>
421
+ * <input {...field} placeholder={props.name} />
422
+ * <p>{fieldState.isTouched && "Touched"}</p>
423
+ * <p>{formState.isSubmitted ? "submitted" : ""}</p>
424
+ * </div>
425
+ * );
426
+ * }
427
+ * ```
428
+ */
429
+ function useController(props) {
430
+ const methods = useFormContext();
431
+ const { name, disabled, control = methods.control, shouldUnregister, defaultValue, } = props;
432
+ const isArrayField = isNameInFieldArray(control._names.array, name);
433
+ const defaultValueMemo = React__default.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
434
+ const value = useWatch({
435
+ control,
436
+ name,
437
+ defaultValue: defaultValueMemo,
438
+ exact: true,
439
+ });
440
+ const formState = useFormState({
441
+ control,
442
+ name,
443
+ exact: true,
444
+ });
445
+ const _props = React__default.useRef(props);
446
+ const _previousNameRef = React__default.useRef(undefined);
447
+ const _registerProps = React__default.useRef(control.register(name, {
448
+ ...props.rules,
449
+ value,
450
+ ...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
451
+ }));
452
+ _props.current = props;
453
+ const fieldState = React__default.useMemo(() => Object.defineProperties({}, {
454
+ invalid: {
455
+ enumerable: true,
456
+ get: () => !!get(formState.errors, name),
457
+ },
458
+ isDirty: {
459
+ enumerable: true,
460
+ get: () => !!get(formState.dirtyFields, name),
461
+ },
462
+ isTouched: {
463
+ enumerable: true,
464
+ get: () => !!get(formState.touchedFields, name),
465
+ },
466
+ isValidating: {
467
+ enumerable: true,
468
+ get: () => !!get(formState.validatingFields, name),
469
+ },
470
+ error: {
471
+ enumerable: true,
472
+ get: () => get(formState.errors, name),
473
+ },
474
+ }), [formState, name]);
475
+ const onChange = React__default.useCallback((event) => _registerProps.current.onChange({
476
+ target: {
477
+ value: getEventValue(event),
478
+ name: name,
479
+ },
480
+ type: EVENTS.CHANGE,
481
+ }), [name]);
482
+ const onBlur = React__default.useCallback(() => _registerProps.current.onBlur({
483
+ target: {
484
+ value: get(control._formValues, name),
485
+ name: name,
486
+ },
487
+ type: EVENTS.BLUR,
488
+ }), [name, control._formValues]);
489
+ const ref = React__default.useCallback((elm) => {
490
+ const field = get(control._fields, name);
491
+ if (field && elm) {
492
+ field._f.ref = {
493
+ focus: () => elm.focus && elm.focus(),
494
+ select: () => elm.select && elm.select(),
495
+ setCustomValidity: (message) => elm.setCustomValidity(message),
496
+ reportValidity: () => elm.reportValidity(),
497
+ };
498
+ }
499
+ }, [control._fields, name]);
500
+ const field = React__default.useMemo(() => ({
501
+ name,
502
+ value,
503
+ ...(isBoolean(disabled) || formState.disabled
504
+ ? { disabled: formState.disabled || disabled }
505
+ : {}),
506
+ onChange,
507
+ onBlur,
508
+ ref,
509
+ }), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
510
+ React__default.useEffect(() => {
511
+ const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
512
+ const previousName = _previousNameRef.current;
513
+ if (previousName && previousName !== name && !isArrayField) {
514
+ control.unregister(previousName);
515
+ }
516
+ control.register(name, {
517
+ ..._props.current.rules,
518
+ ...(isBoolean(_props.current.disabled)
519
+ ? { disabled: _props.current.disabled }
520
+ : {}),
521
+ });
522
+ const updateMounted = (name, value) => {
523
+ const field = get(control._fields, name);
524
+ if (field && field._f) {
525
+ field._f.mount = value;
526
+ }
527
+ };
528
+ updateMounted(name, true);
529
+ if (_shouldUnregisterField) {
530
+ const value = cloneObject(get(control._options.defaultValues, name, _props.current.defaultValue));
531
+ set(control._defaultValues, name, value);
532
+ if (isUndefined(get(control._formValues, name))) {
533
+ set(control._formValues, name, value);
534
+ }
535
+ }
536
+ !isArrayField && control.register(name);
537
+ _previousNameRef.current = name;
538
+ return () => {
539
+ (isArrayField
540
+ ? _shouldUnregisterField && !control._state.action
541
+ : _shouldUnregisterField)
542
+ ? control.unregister(name)
543
+ : updateMounted(name, false);
544
+ };
545
+ }, [name, control, isArrayField, shouldUnregister]);
546
+ React__default.useEffect(() => {
547
+ control._setDisabledField({
548
+ disabled,
549
+ name,
550
+ });
551
+ }, [disabled, name, control]);
552
+ return React__default.useMemo(() => ({
553
+ field,
554
+ formState,
555
+ fieldState,
556
+ }), [field, formState, fieldState]);
557
+ }
558
+
559
+ /**
560
+ * Component based on `useController` hook to work with controlled component.
561
+ *
562
+ * @remarks
563
+ * [API](https://react-hook-form.com/docs/usecontroller/controller) • [Demo](https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw) • [Video](https://www.youtube.com/watch?v=N2UNk_UCVyA)
564
+ *
565
+ * @param props - the path name to the form field value, and validation rules.
566
+ *
567
+ * @returns provide field handler functions, field and form state.
568
+ *
569
+ * @example
570
+ * ```tsx
571
+ * function App() {
572
+ * const { control } = useForm<FormValues>({
573
+ * defaultValues: {
574
+ * test: ""
575
+ * }
576
+ * });
577
+ *
578
+ * return (
579
+ * <form>
580
+ * <Controller
581
+ * control={control}
582
+ * name="test"
583
+ * render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
584
+ * <>
585
+ * <input
586
+ * onChange={onChange} // send value to hook form
587
+ * onBlur={onBlur} // notify when input is touched
588
+ * value={value} // return updated value
589
+ * ref={ref} // set ref for focus management
590
+ * />
591
+ * <p>{formState.isSubmitted ? "submitted" : ""}</p>
592
+ * <p>{fieldState.isTouched ? "touched" : ""}</p>
593
+ * </>
594
+ * )}
595
+ * />
596
+ * </form>
597
+ * );
598
+ * }
599
+ * ```
600
+ */
601
+ const Controller = (props) => props.render(useController(props));
602
+
603
+ function processChildren(children, control) {
604
+ return React__default.Children.map(children, (child) => {
605
+ if (!React__default.isValidElement(child)) {
606
+ return child;
607
+ }
608
+ const childProps = child.props;
609
+ const isFragment = child.type === React__default.Fragment;
610
+ if (!isFragment && childProps.name && typeof childProps.name === "string") {
611
+ const name = childProps.name;
612
+ return /* @__PURE__ */ jsx(
613
+ Controller,
614
+ {
615
+ control,
616
+ name,
617
+ render: ({ field, fieldState }) => {
618
+ const isCheckbox = child.type === Checkbox;
619
+ const fieldProps = isCheckbox ? {
620
+ checked: field.value,
621
+ onCheckedChange: field.onChange,
622
+ onBlur: field.onBlur,
623
+ ref: field.ref
624
+ } : field;
625
+ return React__default.cloneElement(child, {
626
+ ...childProps,
627
+ ...fieldProps,
628
+ error: fieldState.error?.message || (fieldState.error ? "Invalid" : void 0),
629
+ name: void 0
630
+ // Remove name to avoid passing it to the underlying input
631
+ });
632
+ }
633
+ },
634
+ name
635
+ );
636
+ }
637
+ if (isFragment) {
638
+ return processChildren(childProps.children, control);
639
+ }
640
+ if (childProps.children != null) {
641
+ return React__default.cloneElement(child, {
642
+ ...childProps,
643
+ children: processChildren(childProps.children, control)
644
+ });
645
+ }
646
+ return child;
647
+ });
648
+ }
649
+ function Form({
650
+ form,
651
+ onSubmit,
652
+ children,
653
+ ...props
654
+ }) {
655
+ const handleSubmit = form.handleSubmit(onSubmit);
656
+ const processedChildren = processChildren(children, form.control);
657
+ return /* @__PURE__ */ jsx(FormProvider, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit: handleSubmit, ...props, children: processedChildren }) });
658
+ }
659
+ Form.displayName = "Form";
660
+
661
+ export { Controller as C, Form as F };
662
+ //# sourceMappingURL=Form.js.map