@betterinternship/components 3.0.4 → 3.1.1

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 (114) hide show
  1. package/README.md +45 -45
  2. package/dist/components/accordion.js.map +1 -1
  3. package/dist/components/animated-count.js.map +1 -1
  4. package/dist/components/animated-shiny-text.js +12 -0
  5. package/dist/components/animated-shiny-text.js.map +1 -0
  6. package/dist/components/app-header.js.map +1 -1
  7. package/dist/components/autocomplete.js +335 -0
  8. package/dist/components/autocomplete.js.map +1 -0
  9. package/dist/components/avatar.js.map +1 -1
  10. package/dist/components/badge.js.map +1 -1
  11. package/dist/components/banner.js.map +1 -1
  12. package/dist/components/button.js.map +1 -1
  13. package/dist/components/calendar.js.map +1 -1
  14. package/dist/components/card.js.map +1 -1
  15. package/dist/components/carousel.js +126 -0
  16. package/dist/components/carousel.js.map +1 -0
  17. package/dist/components/checkbox.js.map +1 -1
  18. package/dist/components/chip-select.js +22 -0
  19. package/dist/components/chip-select.js.map +1 -0
  20. package/dist/components/collapsible.js +45 -0
  21. package/dist/components/collapsible.js.map +1 -0
  22. package/dist/components/context-menu.js +37 -0
  23. package/dist/components/context-menu.js.map +1 -0
  24. package/dist/components/dialog.js +10 -10
  25. package/dist/components/dialog.js.map +1 -1
  26. package/dist/components/divider.js.map +1 -1
  27. package/dist/components/dot-matrix.js +163 -0
  28. package/dist/components/dot-matrix.js.map +1 -0
  29. package/dist/components/dropdown-menu.js.map +1 -1
  30. package/dist/components/dropdown.js +262 -0
  31. package/dist/components/dropdown.js.map +1 -0
  32. package/dist/components/error.js +19 -0
  33. package/dist/components/error.js.map +1 -0
  34. package/dist/components/fab.js +9 -0
  35. package/dist/components/fab.js.map +1 -0
  36. package/dist/components/file-upload.js.map +1 -1
  37. package/dist/components/filter-chip.js.map +1 -1
  38. package/dist/components/form-checkbox-group.js.map +1 -1
  39. package/dist/components/form-checkbox.js.map +1 -1
  40. package/dist/components/form-date-picker.js.map +1 -1
  41. package/dist/components/form-field.js.map +1 -1
  42. package/dist/components/form-input.js.map +1 -1
  43. package/dist/components/form-month-picker.js.map +1 -1
  44. package/dist/components/form-radio.js.map +1 -1
  45. package/dist/components/form-textarea.js.map +1 -1
  46. package/dist/components/form.js +71 -0
  47. package/dist/components/form.js.map +1 -0
  48. package/dist/components/hover-card.js +13 -0
  49. package/dist/components/hover-card.js.map +1 -0
  50. package/dist/components/input-otp.js +24 -0
  51. package/dist/components/input-otp.js.map +1 -0
  52. package/dist/components/input.js.map +1 -1
  53. package/dist/components/label.js.map +1 -1
  54. package/dist/components/loader.js.map +1 -1
  55. package/dist/components/magnetic-button.js +32 -0
  56. package/dist/components/magnetic-button.js.map +1 -0
  57. package/dist/components/messages.js +9 -0
  58. package/dist/components/messages.js.map +1 -0
  59. package/dist/components/mobile-sheet-portal.js +17 -0
  60. package/dist/components/mobile-sheet-portal.js.map +1 -0
  61. package/dist/components/page-header.d.ts +7 -1
  62. package/dist/components/page-header.js +2 -2
  63. package/dist/components/page-header.js.map +1 -1
  64. package/dist/components/paginator.js +44 -0
  65. package/dist/components/paginator.js.map +1 -0
  66. package/dist/components/popover.js.map +1 -1
  67. package/dist/components/progress.js +11 -0
  68. package/dist/components/progress.js.map +1 -0
  69. package/dist/components/radio-group.js.map +1 -1
  70. package/dist/components/select.js.map +1 -1
  71. package/dist/components/sheet.d.ts +1 -1
  72. package/dist/components/sheet.js +40 -0
  73. package/dist/components/sheet.js.map +1 -0
  74. package/dist/components/skeleton.js.map +1 -1
  75. package/dist/components/slider.js +11 -0
  76. package/dist/components/slider.js.map +1 -0
  77. package/dist/components/sonner-toast.js +78 -0
  78. package/dist/components/sonner-toast.js.map +1 -0
  79. package/dist/components/stepper.js.map +1 -1
  80. package/dist/components/switch.js.map +1 -1
  81. package/dist/components/table.js.map +1 -1
  82. package/dist/components/tabs.js.map +1 -1
  83. package/dist/components/textarea.js.map +1 -1
  84. package/dist/components/time-input-native.js.map +1 -1
  85. package/dist/components/timeline.js +16 -0
  86. package/dist/components/timeline.js.map +1 -0
  87. package/dist/components/toggle.js +15 -0
  88. package/dist/components/toggle.js.map +1 -0
  89. package/dist/components/tooltip.js.map +1 -1
  90. package/dist/hooks/use-detect-click-outside.js +29 -0
  91. package/dist/hooks/use-detect-click-outside.js.map +1 -0
  92. package/dist/hooks/use-field-focus.js.map +1 -1
  93. package/dist/hooks/use-mobile-sheet-viewport.js.map +1 -1
  94. package/dist/hooks/use-mobile.js.map +1 -1
  95. package/dist/hooks/use-resource-table.js.map +1 -1
  96. package/dist/hooks/useMQJob.js.map +1 -1
  97. package/dist/index.d.ts +34 -3
  98. package/dist/index.js +30 -0
  99. package/dist/index.js.map +1 -1
  100. package/dist/lib/interaction-styles.js.map +1 -1
  101. package/dist/node_modules/embla-carousel/esm/embla-carousel.esm.js +1670 -0
  102. package/dist/node_modules/embla-carousel/esm/embla-carousel.esm.js.map +1 -0
  103. package/dist/node_modules/embla-carousel-react/esm/embla-carousel-react.esm.js +38 -0
  104. package/dist/node_modules/embla-carousel-react/esm/embla-carousel-react.esm.js.map +1 -0
  105. package/dist/node_modules/embla-carousel-reactive-utils/esm/embla-carousel-reactive-utils.esm.js +39 -0
  106. package/dist/node_modules/embla-carousel-reactive-utils/esm/embla-carousel-reactive-utils.esm.js.map +1 -0
  107. package/dist/node_modules/input-otp/dist/index.js +25 -0
  108. package/dist/node_modules/input-otp/dist/index.js.map +1 -0
  109. package/dist/node_modules/react-hook-form/dist/index.esm.js +706 -0
  110. package/dist/node_modules/react-hook-form/dist/index.esm.js.map +1 -0
  111. package/dist/utils.js.map +1 -1
  112. package/package.json +326 -291
  113. package/theme.css +360 -355
  114. package/theme.legacy.css +84 -84
@@ -0,0 +1,706 @@
1
+ import React__default from 'react';
2
+
3
+ var isCheckBoxInput = (element) => element.type === 'checkbox';
4
+
5
+ var isFileInput = (element) => element.type === 'file';
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
+ : isFileInput(event.target)
21
+ ? event.target.files
22
+ : event.target.value
23
+ : event;
24
+
25
+ const FIELD_PATH_RE = /[.[\]'"]/;
26
+ var stringToPath = (input) => input.split(FIELD_PATH_RE).filter(Boolean);
27
+
28
+ function getNullAncestorValue(control, name) {
29
+ const segments = stringToPath(name);
30
+ let formValues = control._formValues;
31
+ let defaultValues = control._defaultValues;
32
+ for (let i = 0; i < segments.length - 1; i++) {
33
+ const key = segments[i];
34
+ formValues =
35
+ formValues == null
36
+ ? formValues
37
+ : formValues[key];
38
+ defaultValues =
39
+ defaultValues == null
40
+ ? defaultValues
41
+ : defaultValues[key];
42
+ if (formValues === null || defaultValues === null) {
43
+ return null;
44
+ }
45
+ }
46
+ return undefined;
47
+ }
48
+
49
+ var isNameInFieldArray = (names, name) => name
50
+ .split('.')
51
+ .some((part, index, arr) => !isNaN(Number(part)) && names.has(arr.slice(0, index).join('.')));
52
+
53
+ var isWeb = typeof window !== 'undefined' &&
54
+ typeof window.HTMLElement !== 'undefined' &&
55
+ typeof document !== 'undefined';
56
+
57
+ function cloneObject(data) {
58
+ if (data === null || typeof data !== 'object') {
59
+ return data;
60
+ }
61
+ if (data instanceof Date) {
62
+ return new Date(data);
63
+ }
64
+ const isBlobInstance = typeof Blob !== 'undefined' && data instanceof Blob;
65
+ const isFileListInstance = typeof FileList !== 'undefined' && data instanceof FileList;
66
+ if (isWeb && (isBlobInstance || isFileListInstance)) {
67
+ return data;
68
+ }
69
+ const isArray = Array.isArray(data);
70
+ const prototype = Object.getPrototypeOf(data);
71
+ if (!isArray && prototype && prototype.constructor !== Object) {
72
+ return data;
73
+ }
74
+ const copy = isArray ? new Array(data.length) : Object.create(prototype);
75
+ for (const key in data) {
76
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
77
+ copy[key] = cloneObject(data[key]);
78
+ }
79
+ }
80
+ return copy;
81
+ }
82
+
83
+ const EVENTS = {
84
+ BLUR: 'blur',
85
+ CHANGE: 'change'};
86
+ const VALIDATION_MODE = {
87
+ all: 'all',
88
+ };
89
+ const PROTOTYPE_KEYWORDS = ['__proto__', 'constructor', 'prototype'];
90
+
91
+ const IS_KEY_RE = /^\w*$/;
92
+ var isKey = (value) => IS_KEY_RE.test(value);
93
+
94
+ var isUndefined = (val) => val === undefined;
95
+
96
+ var get = (object, path, defaultValue) => {
97
+ if (!path || !isObject(object)) {
98
+ return defaultValue;
99
+ }
100
+ const paths = isKey(path) ? [path] : stringToPath(path);
101
+ if (paths.some((key) => PROTOTYPE_KEYWORDS.includes(key))) {
102
+ return defaultValue;
103
+ }
104
+ const result = paths.reduce((result, key) => {
105
+ return isNullOrUndefined(result)
106
+ ? undefined
107
+ : result[key];
108
+ }, object);
109
+ return (isUndefined(result) || result === object
110
+ ? isUndefined(object[path])
111
+ ? defaultValue
112
+ : object[path]
113
+ : result);
114
+ };
115
+
116
+ var isBoolean = (value) => typeof value === 'boolean';
117
+
118
+ var isFunction = (value) => typeof value === 'function';
119
+
120
+ var set = (object, path, value) => {
121
+ let index = -1;
122
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
123
+ const length = tempPath.length;
124
+ const lastIndex = length - 1;
125
+ while (++index < length) {
126
+ const key = tempPath[index];
127
+ let newValue = value;
128
+ if (index !== lastIndex) {
129
+ const objValue = object[key];
130
+ newValue =
131
+ isObject(objValue) || Array.isArray(objValue)
132
+ ? objValue
133
+ : !isNaN(+tempPath[index + 1])
134
+ ? []
135
+ : {};
136
+ }
137
+ if (PROTOTYPE_KEYWORDS.includes(key)) {
138
+ return;
139
+ }
140
+ object[key] = newValue;
141
+ object = object[key];
142
+ }
143
+ };
144
+
145
+ /**
146
+ * Separate context for `control` to prevent unnecessary rerenders.
147
+ * Internal hooks that only need control use this instead of full form context.
148
+ */
149
+ const HookFormControlContext = React__default.createContext(null);
150
+ HookFormControlContext.displayName = 'HookFormControlContext';
151
+ /**
152
+ * @internal Internal hook to access only control from context.
153
+ */
154
+ const useFormControlContext = () => React__default.useContext(HookFormControlContext);
155
+
156
+ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
157
+ const result = {};
158
+ for (const key in formState) {
159
+ Object.defineProperty(result, key, {
160
+ get: () => {
161
+ const _key = key;
162
+ if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
163
+ control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
164
+ }
165
+ localProxyFormState && (localProxyFormState[_key] = true);
166
+ return formState[_key];
167
+ },
168
+ });
169
+ }
170
+ return result;
171
+ };
172
+
173
+ const useIsomorphicLayoutEffect = isWeb
174
+ ? React__default.useLayoutEffect
175
+ : React__default.useEffect;
176
+
177
+ var isPlainObject = (tempObject) => {
178
+ const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
179
+ return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
180
+ };
181
+
182
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
183
+
184
+ const isEmptyObjectWithCustomPrototype = (object, keys) => keys.length === 0 &&
185
+ !Array.isArray(object) &&
186
+ Object.getPrototypeOf(object) !== null &&
187
+ !isPlainObject(object);
188
+ function deepEqual(object1, object2, isErrorObject = false, visited = new WeakMap()) {
189
+ if (object1 === object2) {
190
+ return true;
191
+ }
192
+ if (isPrimitive(object1) || isPrimitive(object2)) {
193
+ return Object.is(object1, object2);
194
+ }
195
+ if (isDateObject(object1) && isDateObject(object2)) {
196
+ return Object.is(object1.getTime(), object2.getTime());
197
+ }
198
+ if (Array.isArray(object1) &&
199
+ Array.isArray(object2) &&
200
+ object1.length !== object2.length) {
201
+ return false;
202
+ }
203
+ const keys1 = Object.keys(object1);
204
+ const keys2 = Object.keys(object2);
205
+ if (keys1.length !== keys2.length) {
206
+ return false;
207
+ }
208
+ if (isEmptyObjectWithCustomPrototype(object1, keys1) ||
209
+ isEmptyObjectWithCustomPrototype(object2, keys2)) {
210
+ return Object.is(object1, object2);
211
+ }
212
+ if (!keys1.length && Array.isArray(object1) !== Array.isArray(object2)) {
213
+ return false;
214
+ }
215
+ const visitedPairs = visited.get(object1);
216
+ if (visitedPairs && visitedPairs.has(object2)) {
217
+ return true;
218
+ }
219
+ if (visitedPairs) {
220
+ visitedPairs.add(object2);
221
+ }
222
+ else {
223
+ const ws = new WeakSet();
224
+ ws.add(object2);
225
+ visited.set(object1, ws);
226
+ }
227
+ for (const key of keys1) {
228
+ const val1 = object1[key];
229
+ if (!Object.prototype.hasOwnProperty.call(object2, key)) {
230
+ return false;
231
+ }
232
+ if (!isErrorObject || key !== 'ref') {
233
+ const val2 = object2[key];
234
+ if ((isDateObject(val1) && isDateObject(val2)) ||
235
+ ((isObject(val1) || Array.isArray(val1)) &&
236
+ (isObject(val2) || Array.isArray(val2)))
237
+ ? !deepEqual(val1, val2, isErrorObject, visited)
238
+ : !Object.is(val1, val2)) {
239
+ return false;
240
+ }
241
+ }
242
+ }
243
+ return true;
244
+ }
245
+
246
+ function useResyncOnReconnect(getInitialValue) {
247
+ const _connected = React__default.useRef(false);
248
+ const _initialized = React__default.useRef(false);
249
+ const _prevValue = React__default.useRef(undefined);
250
+ const _renderCount = React__default.useRef(0);
251
+ _renderCount.current++;
252
+ if (!_initialized.current && getInitialValue) {
253
+ _initialized.current = true;
254
+ _prevValue.current = cloneObject(getInitialValue());
255
+ }
256
+ const resyncIfNeeded = React__default.useCallback((enabled, getCurrentValue, setValue) => {
257
+ if (enabled &&
258
+ (_connected.current ||
259
+ (_initialized.current && _renderCount.current > 1))) {
260
+ const currentValue = getCurrentValue();
261
+ if (!deepEqual(_prevValue.current, currentValue)) {
262
+ setValue(currentValue);
263
+ }
264
+ }
265
+ _connected.current = true;
266
+ }, []);
267
+ const snapshot = React__default.useCallback((enabled, getCurrentValue) => {
268
+ if (enabled) {
269
+ _prevValue.current = cloneObject(getCurrentValue());
270
+ }
271
+ }, []);
272
+ return { resyncIfNeeded, snapshot };
273
+ }
274
+
275
+ /**
276
+ * Subscribes to form state with re-renders isolated to this hook.
277
+ * Optionally scope to specific field names to minimize re-render surface.
278
+ *
279
+ * @see [API](https://react-hook-form.com/docs/useformstate)
280
+ *
281
+ * @example
282
+ * ```tsx
283
+ * const { errors, isDirty } = useFormState({ control, name: "email" });
284
+ * ```
285
+ */
286
+ function useFormState(props) {
287
+ const formControl = useFormControlContext();
288
+ const { control = formControl, disabled, name, exact } = props || {};
289
+ const getCurrentFormState = () => ({
290
+ ...control._formState,
291
+ defaultValues: control._defaultValues,
292
+ });
293
+ const [formState, updateFormState] = React__default.useState(getCurrentFormState);
294
+ const _localProxyFormState = React__default.useRef({
295
+ isDirty: false,
296
+ isLoading: false,
297
+ dirtyFields: false,
298
+ touchedFields: false,
299
+ validatingFields: false,
300
+ isValidating: false,
301
+ isValid: false,
302
+ errors: false,
303
+ });
304
+ const { resyncIfNeeded, snapshot } = useResyncOnReconnect(getCurrentFormState);
305
+ useIsomorphicLayoutEffect(() => {
306
+ resyncIfNeeded(!disabled, getCurrentFormState, updateFormState);
307
+ const unsubscribe = control._subscribe({
308
+ name,
309
+ formState: _localProxyFormState.current,
310
+ exact,
311
+ callback: (formState) => {
312
+ !disabled &&
313
+ updateFormState({
314
+ ...control._formState,
315
+ ...formState,
316
+ defaultValues: control._defaultValues,
317
+ });
318
+ },
319
+ });
320
+ return () => {
321
+ unsubscribe();
322
+ snapshot(!disabled, getCurrentFormState);
323
+ };
324
+ }, [control, name, disabled, exact, resyncIfNeeded, snapshot]);
325
+ React__default.useEffect(() => {
326
+ _localProxyFormState.current.isValid && control._setValid(true);
327
+ }, [control]);
328
+ return React__default.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
329
+ }
330
+
331
+ var isString = (value) => typeof value === 'string';
332
+
333
+ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
334
+ if (isString(names)) {
335
+ return get(formValues, names, defaultValue);
336
+ }
337
+ if (Array.isArray(names)) {
338
+ return names.map((fieldName) => (get(formValues, fieldName, get(defaultValue, fieldName))));
339
+ }
340
+ return formValues;
341
+ };
342
+
343
+ /**
344
+ * Subscribes to field value changes and isolates re-renders to the hook level.
345
+ *
346
+ * @see [API](https://react-hook-form.com/docs/usewatch)
347
+ *
348
+ * @example
349
+ * ```tsx
350
+ * const email = useWatch({ control, name: "email" });
351
+ * const all = useWatch({ control });
352
+ * const adult = useWatch({ control, name: "age", compute: (v) => v >= 18 });
353
+ * ```
354
+ */
355
+ function useWatch(props) {
356
+ const formControl = useFormControlContext();
357
+ const { control = formControl, name, defaultValue, disabled, exact, compute, } = props || {};
358
+ const _defaultValue = React__default.useRef(defaultValue);
359
+ const _compute = React__default.useRef(compute);
360
+ const _prevControl = React__default.useRef(control);
361
+ const _prevName = React__default.useRef(name);
362
+ _compute.current = compute;
363
+ const getInitialOutput = () => {
364
+ const defaultValue = control._getWatch(name, _defaultValue.current);
365
+ return _compute.current ? _compute.current(defaultValue) : defaultValue;
366
+ };
367
+ const [value, updateValue] = React__default.useState(getInitialOutput);
368
+ const _computeFormValues = React__default.useRef(value);
369
+ const getCurrentOutput = React__default.useCallback((values) => {
370
+ const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
371
+ return _compute.current
372
+ ? _compute.current(formValues)
373
+ : formValues;
374
+ }, [control._formValues, control._names, name]);
375
+ const refreshValue = React__default.useCallback((values) => {
376
+ if (!disabled) {
377
+ const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
378
+ if (_compute.current) {
379
+ const computedFormValues = _compute.current(formValues);
380
+ if (!deepEqual(computedFormValues, _computeFormValues.current)) {
381
+ updateValue(computedFormValues);
382
+ _computeFormValues.current = computedFormValues;
383
+ }
384
+ }
385
+ else {
386
+ updateValue(formValues);
387
+ }
388
+ }
389
+ }, [control._formValues, control._names, disabled, name]);
390
+ const { resyncIfNeeded, snapshot } = useResyncOnReconnect(getInitialOutput);
391
+ const _refreshValue = React__default.useRef(refreshValue);
392
+ _refreshValue.current = refreshValue;
393
+ const _getCurrentOutput = React__default.useRef(getCurrentOutput);
394
+ _getCurrentOutput.current = getCurrentOutput;
395
+ useIsomorphicLayoutEffect(() => {
396
+ if (_prevControl.current !== control ||
397
+ !deepEqual(_prevName.current, name)) {
398
+ _prevControl.current = control;
399
+ _prevName.current = name;
400
+ _refreshValue.current();
401
+ }
402
+ else {
403
+ resyncIfNeeded(!disabled, () => _getCurrentOutput.current(), (currentValue) => {
404
+ const nextValue = cloneObject(currentValue);
405
+ updateValue(nextValue);
406
+ _computeFormValues.current = nextValue;
407
+ });
408
+ }
409
+ const unsubscribe = control._subscribe({
410
+ name,
411
+ formState: {
412
+ values: true,
413
+ },
414
+ exact,
415
+ callback: (formState) => {
416
+ _refreshValue.current(formState.values);
417
+ },
418
+ });
419
+ return () => {
420
+ unsubscribe();
421
+ snapshot(!disabled, () => _getCurrentOutput.current());
422
+ };
423
+ }, [control, exact, name, disabled, resyncIfNeeded, snapshot]);
424
+ React__default.useEffect(() => control._removeUnmounted());
425
+ // If name or control changed for this render, synchronously reflect the
426
+ // latest value so callers (like useController) see the correct value
427
+ // immediately on the same render.
428
+ // Optimize: Check control reference first before expensive deepEqual
429
+ const controlChanged = _prevControl.current !== control;
430
+ const prevName = _prevName.current;
431
+ const nameChanged = React__default.useMemo(() => !controlChanged && !deepEqual(prevName, name), [controlChanged, name, prevName]);
432
+ if (controlChanged || nameChanged) {
433
+ _defaultValue.current = defaultValue;
434
+ }
435
+ const shouldReturnImmediate = !disabled && (controlChanged || nameChanged);
436
+ return shouldReturnImmediate ? getCurrentOutput() : value;
437
+ }
438
+
439
+ /**
440
+ * Hook for controlled inputs. Returns `field`, `fieldState`, and `formState`.
441
+ * Re-renders are isolated to the hook level.
442
+ *
443
+ * @see [API](https://react-hook-form.com/docs/usecontroller)
444
+ *
445
+ * @example
446
+ * ```tsx
447
+ * const { field, fieldState } = useController({ control, name: "email" });
448
+ * return <input {...field} />;
449
+ * ```
450
+ */
451
+ function useController(props) {
452
+ const formControl = useFormControlContext();
453
+ const { name, disabled, control = formControl, shouldUnregister, defaultValue, exact = true, } = props;
454
+ const isArrayField = isNameInFieldArray(control._names.array, name);
455
+ const defaultValueMemo = React__default.useMemo(() => {
456
+ const resolved = get(control._formValues, name, get(control._defaultValues, name, defaultValue));
457
+ return (isUndefined(resolved) ? getNullAncestorValue(control, name) : resolved);
458
+ }, [control, name, defaultValue]);
459
+ const value = useWatch({
460
+ control,
461
+ name,
462
+ defaultValue: defaultValueMemo,
463
+ exact,
464
+ });
465
+ const formState = useFormState({
466
+ control,
467
+ name,
468
+ exact,
469
+ });
470
+ const _props = React__default.useRef(props);
471
+ const _proxyRef = React__default.useRef(null);
472
+ const _registerProps = React__default.useRef(control.register(name, {
473
+ ...props.rules,
474
+ value,
475
+ ...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
476
+ }));
477
+ _props.current = props;
478
+ const fieldState = React__default.useMemo(() => Object.defineProperties({}, {
479
+ invalid: {
480
+ enumerable: true,
481
+ get: () => !!get(formState.errors, name),
482
+ },
483
+ isDirty: {
484
+ enumerable: true,
485
+ get: () => !!get(formState.dirtyFields, name),
486
+ },
487
+ isTouched: {
488
+ enumerable: true,
489
+ get: () => !!get(formState.touchedFields, name),
490
+ },
491
+ isValidating: {
492
+ enumerable: true,
493
+ get: () => !!get(formState.validatingFields, name),
494
+ },
495
+ error: {
496
+ enumerable: true,
497
+ get: () => get(formState.errors, name),
498
+ },
499
+ }), [formState, name]);
500
+ const onChange = React__default.useCallback((event) => {
501
+ const value = getEventValue(event);
502
+ if (!get(control._fields, name)) {
503
+ _registerProps.current = control.register(name, {
504
+ ..._props.current.rules,
505
+ value,
506
+ });
507
+ }
508
+ return _registerProps.current.onChange({
509
+ target: {
510
+ value: getEventValue(event),
511
+ name,
512
+ },
513
+ type: EVENTS.CHANGE,
514
+ });
515
+ }, [name, control]);
516
+ const onBlur = React__default.useCallback(() => {
517
+ const value = get(control._formValues, name);
518
+ if (!get(control._fields, name)) {
519
+ _registerProps.current = control.register(name, {
520
+ ..._props.current.rules,
521
+ value,
522
+ });
523
+ }
524
+ return _registerProps.current.onBlur({
525
+ target: {
526
+ value,
527
+ name,
528
+ },
529
+ type: EVENTS.BLUR,
530
+ });
531
+ }, [name, control]);
532
+ const ref = React__default.useCallback((elm) => {
533
+ if (elm) {
534
+ _proxyRef.current = {
535
+ focus: () => isFunction(elm.focus) && elm.focus(),
536
+ select: () => isFunction(elm.select) && elm.select(),
537
+ setCustomValidity: (message) => isFunction(elm.setCustomValidity) && elm.setCustomValidity(message),
538
+ reportValidity: () => isFunction(elm.reportValidity) && elm.reportValidity(),
539
+ };
540
+ }
541
+ const field = get(control._fields, name);
542
+ if (field && field._f && elm) {
543
+ field._f.ref = _proxyRef.current;
544
+ field._f._c = true;
545
+ }
546
+ }, [control._fields, name]);
547
+ const field = React__default.useMemo(() => ({
548
+ name,
549
+ value,
550
+ ...(isBoolean(disabled) || formState.disabled
551
+ ? { disabled: formState.disabled || disabled }
552
+ : {}),
553
+ onChange,
554
+ onBlur,
555
+ ref,
556
+ }), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
557
+ React__default.useEffect(() => {
558
+ const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
559
+ _registerProps.current = control.register(name, {
560
+ ..._props.current.rules,
561
+ ...(isBoolean(_props.current.disabled)
562
+ ? { disabled: _props.current.disabled }
563
+ : {}),
564
+ });
565
+ const updateMounted = (name, value) => {
566
+ const field = get(control._fields, name);
567
+ if (field && field._f) {
568
+ field._f.mount = value;
569
+ field._f._c = value;
570
+ }
571
+ };
572
+ updateMounted(name, true);
573
+ if (_shouldUnregisterField) {
574
+ const value = cloneObject(get(shouldUnregister
575
+ ? control._defaultValues
576
+ : control._options.values || control._defaultValues, name, get(control._options.defaultValues, name, _props.current.defaultValue)));
577
+ set(control._defaultValues, name, value);
578
+ if (isUndefined(get(control._formValues, name))) {
579
+ set(control._formValues, name, value);
580
+ }
581
+ }
582
+ !isArrayField &&
583
+ control.register(name, {
584
+ ..._props.current.rules,
585
+ ...(isBoolean(_props.current.disabled)
586
+ ? { disabled: _props.current.disabled }
587
+ : {}),
588
+ });
589
+ if (_proxyRef.current) {
590
+ const field = get(control._fields, name);
591
+ if (field && field._f) {
592
+ field._f.ref = _proxyRef.current;
593
+ }
594
+ }
595
+ return () => {
596
+ (isArrayField
597
+ ? _shouldUnregisterField && !control._state.action
598
+ : _shouldUnregisterField)
599
+ ? control.unregister(name)
600
+ : updateMounted(name, false);
601
+ };
602
+ }, [name, control, isArrayField, shouldUnregister]);
603
+ React__default.useEffect(() => {
604
+ control._setDisabledField({
605
+ disabled,
606
+ name,
607
+ });
608
+ }, [disabled, name, control]);
609
+ return React__default.useMemo(() => ({
610
+ field,
611
+ formState,
612
+ fieldState,
613
+ }), [field, formState, fieldState]);
614
+ }
615
+
616
+ /**
617
+ * Component wrapper around `useController` for controlled inputs.
618
+ *
619
+ * @see [API](https://react-hook-form.com/docs/usecontroller/controller)
620
+ *
621
+ * @example
622
+ * ```tsx
623
+ * <Controller
624
+ * control={control}
625
+ * name="test"
626
+ * render={({ field, fieldState, formState }) => <input {...field} />}
627
+ * />
628
+ * ```
629
+ */
630
+ const Controller = (props) => props.render(useController(props));
631
+
632
+ const HookFormContext = React__default.createContext(null);
633
+ HookFormContext.displayName = 'HookFormContext';
634
+ /**
635
+ * Retrieves all `useForm` methods from the nearest `FormProvider`.
636
+ * Use in deeply nested components to avoid prop-drilling.
637
+ *
638
+ * @see [API](https://react-hook-form.com/docs/useformcontext)
639
+ *
640
+ * @example
641
+ * ```tsx
642
+ * const { register } = useFormContext<FormValues>();
643
+ * ```
644
+ */
645
+ const useFormContext = () => React__default.useContext(HookFormContext);
646
+ /**
647
+ * Provides all `useForm` methods to the component tree via React Context.
648
+ * Pair with `useFormContext` to consume them in any descendant.
649
+ *
650
+ * @see [API](https://react-hook-form.com/docs/useformcontext)
651
+ *
652
+ * @example
653
+ * ```tsx
654
+ * <FormProvider {...methods}>
655
+ * <form onSubmit={methods.handleSubmit(onSubmit)}>{children}</form>
656
+ * </FormProvider>
657
+ * ```
658
+ */
659
+ const FormProvider = ({ children, watch, getValues, getErrors, getFieldState, setError, clearErrors, setValue, setValues, trigger, formState, resetField, reset, resetDefaultValues, handleSubmit, unregister, control, register, setFocus, subscribe, }) => {
660
+ const memoizedValue = React__default.useMemo(() => ({
661
+ watch,
662
+ getValues,
663
+ getErrors,
664
+ getFieldState,
665
+ setError,
666
+ clearErrors,
667
+ setValue,
668
+ setValues,
669
+ trigger,
670
+ formState,
671
+ resetField,
672
+ reset,
673
+ resetDefaultValues,
674
+ handleSubmit,
675
+ unregister,
676
+ control,
677
+ register,
678
+ setFocus,
679
+ subscribe,
680
+ }), [
681
+ clearErrors,
682
+ control,
683
+ formState,
684
+ getErrors,
685
+ getFieldState,
686
+ getValues,
687
+ handleSubmit,
688
+ register,
689
+ reset,
690
+ resetDefaultValues,
691
+ resetField,
692
+ setError,
693
+ setFocus,
694
+ setValue,
695
+ setValues,
696
+ subscribe,
697
+ trigger,
698
+ unregister,
699
+ watch,
700
+ ]);
701
+ return (React__default.createElement(HookFormContext.Provider, { value: memoizedValue },
702
+ React__default.createElement(HookFormControlContext.Provider, { value: memoizedValue.control }, children)));
703
+ };
704
+
705
+ export { Controller, FormProvider, get, set, useController, useFormContext, useFormState, useWatch };
706
+ //# sourceMappingURL=index.esm.js.map