pds-dev-kit-web-test 2.4.7 → 2.4.9

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.
package/dist/index.esm.js CHANGED
@@ -1,15 +1,122 @@
1
- import { __assign as __assign$a, __makeTemplateObject, __rest as __rest$5, __spreadArray as __spreadArray$2, __awaiter, __generator, __extends } from 'tslib';
2
1
  import styled, { css as css$1, keyframes, useTheme, ThemeProvider } from 'styled-components';
3
2
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
3
  import Lottie from 'lottie-react';
5
4
  import * as React from 'react';
6
5
  import React__default, { useState, useRef, useEffect, useContext, useMemo, forwardRef as forwardRef$2, createContext, useCallback, useLayoutEffect, useReducer, Fragment as Fragment$1, createElement, Component, useImperativeHandle } from 'react';
6
+ import { useFormContext, useWatch, useForm, FormProvider } from 'react-hook-form';
7
7
  import ReactDOM, { createPortal } from 'react-dom';
8
8
  import { Router, __RouterContext, matchPath, useHistory, useLocation } from 'react-router';
9
9
  import NukaCarousel from 'nuka-carousel';
10
10
  import PropTypes from 'prop-types';
11
11
  import smoothscroll from 'smoothscroll-polyfill';
12
12
 
13
+ /*! *****************************************************************************
14
+ Copyright (c) Microsoft Corporation.
15
+
16
+ Permission to use, copy, modify, and/or distribute this software for any
17
+ purpose with or without fee is hereby granted.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
+ PERFORMANCE OF THIS SOFTWARE.
26
+ ***************************************************************************** */
27
+ /* global Reflect, Promise */
28
+
29
+ var extendStatics = function(d, b) {
30
+ extendStatics = Object.setPrototypeOf ||
31
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
32
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
33
+ return extendStatics(d, b);
34
+ };
35
+
36
+ function __extends(d, b) {
37
+ if (typeof b !== "function" && b !== null)
38
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
39
+ extendStatics(d, b);
40
+ function __() { this.constructor = d; }
41
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
42
+ }
43
+
44
+ var __assign$a = function() {
45
+ __assign$a = Object.assign || function __assign(t) {
46
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
47
+ s = arguments[i];
48
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
49
+ }
50
+ return t;
51
+ };
52
+ return __assign$a.apply(this, arguments);
53
+ };
54
+
55
+ function __rest$5(s, e) {
56
+ var t = {};
57
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
58
+ t[p] = s[p];
59
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
60
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
61
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
62
+ t[p[i]] = s[p[i]];
63
+ }
64
+ return t;
65
+ }
66
+
67
+ function __awaiter(thisArg, _arguments, P, generator) {
68
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
69
+ return new (P || (P = Promise))(function (resolve, reject) {
70
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
71
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
72
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
73
+ step((generator = generator.apply(thisArg, [])).next());
74
+ });
75
+ }
76
+
77
+ function __generator(thisArg, body) {
78
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
79
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
80
+ function verb(n) { return function (v) { return step([n, v]); }; }
81
+ function step(op) {
82
+ if (f) throw new TypeError("Generator is already executing.");
83
+ while (_) try {
84
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
85
+ if (y = 0, t) op = [op[0] & 2, t.value];
86
+ switch (op[0]) {
87
+ case 0: case 1: t = op; break;
88
+ case 4: _.label++; return { value: op[1], done: false };
89
+ case 5: _.label++; y = op[1]; op = [0]; continue;
90
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
91
+ default:
92
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
93
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
94
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
95
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
96
+ if (t[2]) _.ops.pop();
97
+ _.trys.pop(); continue;
98
+ }
99
+ op = body.call(thisArg, _);
100
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
101
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
102
+ }
103
+ }
104
+
105
+ function __spreadArray$2(to, from, pack) {
106
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
107
+ if (ar || !(i in from)) {
108
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
109
+ ar[i] = from[i];
110
+ }
111
+ }
112
+ return to.concat(ar || Array.prototype.slice.call(from));
113
+ }
114
+
115
+ function __makeTemplateObject(cooked, raw) {
116
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
117
+ return cooked;
118
+ }
119
+
13
120
  var blue500$1 = "#455EEF";
14
121
  var blue700$1 = "#0040bb";
15
122
  var blue300$1 = "#838bff";
@@ -35256,1674 +35363,6 @@ var S_BottomWrapper$7 = styled.div.withConfig({
35256
35363
  });
35257
35364
  var templateObject_1$4u, templateObject_2$3m, templateObject_3$2S, templateObject_4$2r;
35258
35365
 
35259
- var isCheckBoxInput = (element) => element.type === 'checkbox';
35260
-
35261
- var isDateObject = (value) => value instanceof Date;
35262
-
35263
- var isNullOrUndefined$1 = (value) => value == null;
35264
-
35265
- const isObjectType = (value) => typeof value === 'object';
35266
- var isObject$3 = (value) => !isNullOrUndefined$1(value) &&
35267
- !Array.isArray(value) &&
35268
- isObjectType(value) &&
35269
- !isDateObject(value);
35270
-
35271
- var getEventValue = (event) => isObject$3(event) && event.target
35272
- ? isCheckBoxInput(event.target)
35273
- ? event.target.checked
35274
- : event.target.value
35275
- : event;
35276
-
35277
- var getNodeParentName = (name) => name.substring(0, name.search(/.\d/)) || name;
35278
-
35279
- var isNameInFieldArray = (names, name) => [...names].some((current) => getNodeParentName(name) === current);
35280
-
35281
- var compact$1 = (value) => value.filter(Boolean);
35282
-
35283
- var isUndefined = (val) => val === undefined;
35284
-
35285
- var get = (obj, path, defaultValue) => {
35286
- if (!path || !isObject$3(obj)) {
35287
- return defaultValue;
35288
- }
35289
- const result = compact$1(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined$1(result) ? result : result[key], obj);
35290
- return isUndefined(result) || result === obj
35291
- ? isUndefined(obj[path])
35292
- ? defaultValue
35293
- : obj[path]
35294
- : result;
35295
- };
35296
-
35297
- const EVENTS$1 = {
35298
- BLUR: 'blur',
35299
- FOCUS_OUT: 'focusout',
35300
- CHANGE: 'change',
35301
- };
35302
- const VALIDATION_MODE = {
35303
- onBlur: 'onBlur',
35304
- onChange: 'onChange',
35305
- onSubmit: 'onSubmit',
35306
- onTouched: 'onTouched',
35307
- all: 'all',
35308
- };
35309
- const INPUT_VALIDATION_RULES = {
35310
- max: 'max',
35311
- min: 'min',
35312
- maxLength: 'maxLength',
35313
- minLength: 'minLength',
35314
- pattern: 'pattern',
35315
- required: 'required',
35316
- validate: 'validate',
35317
- };
35318
-
35319
- var omit = (source, key) => {
35320
- const copy = Object.assign({}, source);
35321
- delete copy[key];
35322
- return copy;
35323
- };
35324
-
35325
- const HookFormContext = React__default.createContext(null);
35326
- /**
35327
- * 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}.
35328
- *
35329
- * @remarks
35330
- * [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
35331
- *
35332
- * @returns return all useForm methods
35333
- *
35334
- * @example
35335
- * ```tsx
35336
- * function App() {
35337
- * const methods = useForm();
35338
- * const onSubmit = data => console.log(data);
35339
- *
35340
- * return (
35341
- * <FormProvider {...methods} >
35342
- * <form onSubmit={methods.handleSubmit(onSubmit)}>
35343
- * <NestedInput />
35344
- * <input type="submit" />
35345
- * </form>
35346
- * </FormProvider>
35347
- * );
35348
- * }
35349
- *
35350
- * function NestedInput() {
35351
- * const { register } = useFormContext(); // retrieve all hook methods
35352
- * return <input {...register("test")} />;
35353
- * }
35354
- * ```
35355
- */
35356
- const useFormContext = () => React__default.useContext(HookFormContext);
35357
- /**
35358
- * A provider component that propagates the `useForm` methods to all children components via [React Context](https://reactjs.org/docs/context.html) API. To be used with {@link useFormContext}.
35359
- *
35360
- * @remarks
35361
- * [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
35362
- *
35363
- * @param props - all useFrom methods
35364
- *
35365
- * @example
35366
- * ```tsx
35367
- * function App() {
35368
- * const methods = useForm();
35369
- * const onSubmit = data => console.log(data);
35370
- *
35371
- * return (
35372
- * <FormProvider {...methods} >
35373
- * <form onSubmit={methods.handleSubmit(onSubmit)}>
35374
- * <NestedInput />
35375
- * <input type="submit" />
35376
- * </form>
35377
- * </FormProvider>
35378
- * );
35379
- * }
35380
- *
35381
- * function NestedInput() {
35382
- * const { register } = useFormContext(); // retrieve all hook methods
35383
- * return <input {...register("test")} />;
35384
- * }
35385
- * ```
35386
- */
35387
- const FormProvider = (props) => (React__default.createElement(HookFormContext.Provider, { value: omit(props, 'children') }, props.children));
35388
-
35389
- var getProxyFormState = (formState, _proxyFormState, localProxyFormState, isRoot = true) => {
35390
- const result = {};
35391
- for (const key in formState) {
35392
- Object.defineProperty(result, key, {
35393
- get: () => {
35394
- const _key = key;
35395
- if (_proxyFormState[_key] !== VALIDATION_MODE.all) {
35396
- _proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
35397
- }
35398
- return formState[_key];
35399
- },
35400
- });
35401
- }
35402
- return result;
35403
- };
35404
-
35405
- var isEmptyObject = (value) => isObject$3(value) && !Object.keys(value).length;
35406
-
35407
- var shouldRenderFormState = (formStateData, _proxyFormState, isRoot) => {
35408
- const formState = omit(formStateData, 'name');
35409
- return (isEmptyObject(formState) ||
35410
- Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
35411
- Object.keys(formState).find((key) => _proxyFormState[key] ===
35412
- (VALIDATION_MODE.all)));
35413
- };
35414
-
35415
- var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
35416
-
35417
- var shouldSubscribeByName = (name, signalName, exact) => exact && signalName
35418
- ? name === signalName
35419
- : !name ||
35420
- !signalName ||
35421
- name === signalName ||
35422
- convertToArrayPayload(name).some((currentName) => currentName &&
35423
- (currentName.startsWith(signalName) ||
35424
- signalName.startsWith(currentName)));
35425
-
35426
- function useSubscribe(props) {
35427
- const _props = React__default.useRef(props);
35428
- _props.current = props;
35429
- React__default.useEffect(() => {
35430
- const tearDown = (subscription) => {
35431
- if (subscription) {
35432
- subscription.unsubscribe();
35433
- }
35434
- };
35435
- const subscription = !props.disabled &&
35436
- _props.current.subject.subscribe({
35437
- next: _props.current.callback,
35438
- });
35439
- return () => tearDown(subscription);
35440
- }, [props.disabled]);
35441
- }
35442
-
35443
- var isString = (value) => typeof value === 'string';
35444
-
35445
- var generateWatchOutput = (names, _names, formValues, isGlobal) => {
35446
- const isArray = Array.isArray(names);
35447
- if (isString(names)) {
35448
- isGlobal && _names.watch.add(names);
35449
- return get(formValues, names);
35450
- }
35451
- if (isArray) {
35452
- return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
35453
- get(formValues, fieldName)));
35454
- }
35455
- isGlobal && (_names.watchAll = true);
35456
- return formValues;
35457
- };
35458
-
35459
- var isFunction$1 = (value) => typeof value === 'function';
35460
-
35461
- var objectHasFunction = (data) => {
35462
- for (const key in data) {
35463
- if (isFunction$1(data[key])) {
35464
- return true;
35465
- }
35466
- }
35467
- return false;
35468
- };
35469
-
35470
- /**
35471
- * Custom hook to subscribe to field change and isolate re-rendering at the component level.
35472
- *
35473
- * @remarks
35474
- *
35475
- * [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
35476
- *
35477
- * @example
35478
- * ```tsx
35479
- * const { watch } = useForm();
35480
- * const values = useWatch({
35481
- * name: "fieldName"
35482
- * control,
35483
- * })
35484
- * ```
35485
- */
35486
- function useWatch(props) {
35487
- const methods = useFormContext();
35488
- const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
35489
- const _name = React__default.useRef(name);
35490
- _name.current = name;
35491
- const callback = React__default.useCallback((formState) => {
35492
- if (shouldSubscribeByName(_name.current, formState.name, exact)) {
35493
- const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
35494
- updateValue(isUndefined(_name.current) ||
35495
- (isObject$3(fieldValues) && !objectHasFunction(fieldValues))
35496
- ? Object.assign({}, fieldValues) : Array.isArray(fieldValues)
35497
- ? [...fieldValues]
35498
- : isUndefined(fieldValues)
35499
- ? defaultValue
35500
- : fieldValues);
35501
- }
35502
- }, [control, exact, defaultValue]);
35503
- useSubscribe({
35504
- disabled,
35505
- subject: control._subjects.watch,
35506
- callback,
35507
- });
35508
- const [value, updateValue] = React__default.useState(isUndefined(defaultValue)
35509
- ? control._getWatch(name)
35510
- : defaultValue);
35511
- React__default.useEffect(() => {
35512
- control._removeUnmounted();
35513
- });
35514
- return value;
35515
- }
35516
-
35517
- var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
35518
- ? Object.assign(Object.assign({}, errors[name]), { types: Object.assign(Object.assign({}, (errors[name] && errors[name].types ? errors[name].types : {})), { [type]: message || true }) }) : {};
35519
-
35520
- var isKey = (value) => /^\w*$/.test(value);
35521
-
35522
- var stringToPath = (input) => compact$1(input.replace(/["|']|\]/g, '').split(/\.|\[/));
35523
-
35524
- function set(object, path, value) {
35525
- let index = -1;
35526
- const tempPath = isKey(path) ? [path] : stringToPath(path);
35527
- const length = tempPath.length;
35528
- const lastIndex = length - 1;
35529
- while (++index < length) {
35530
- const key = tempPath[index];
35531
- let newValue = value;
35532
- if (index !== lastIndex) {
35533
- const objValue = object[key];
35534
- newValue =
35535
- isObject$3(objValue) || Array.isArray(objValue)
35536
- ? objValue
35537
- : !isNaN(+tempPath[index + 1])
35538
- ? []
35539
- : {};
35540
- }
35541
- object[key] = newValue;
35542
- object = object[key];
35543
- }
35544
- return object;
35545
- }
35546
-
35547
- const focusFieldBy = (fields, callback, fieldsNames) => {
35548
- for (const key of fieldsNames || Object.keys(fields)) {
35549
- const field = get(fields, key);
35550
- if (field) {
35551
- const _f = field._f;
35552
- const current = omit(field, '_f');
35553
- if (_f && callback(_f.name)) {
35554
- if (_f.ref.focus && isUndefined(_f.ref.focus())) {
35555
- break;
35556
- }
35557
- else if (_f.refs) {
35558
- _f.refs[0].focus();
35559
- break;
35560
- }
35561
- }
35562
- else if (isObject$3(current)) {
35563
- focusFieldBy(current, callback);
35564
- }
35565
- }
35566
- }
35567
- };
35568
-
35569
- var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
35570
- (_names.watchAll ||
35571
- _names.watch.has(name) ||
35572
- [..._names.watch].some((watchName) => name.startsWith(watchName) &&
35573
- /^\.\w+/.test(name.slice(watchName.length))));
35574
-
35575
- function cloneObject(data) {
35576
- let copy;
35577
- const isArray = Array.isArray(data);
35578
- if (data instanceof Date) {
35579
- copy = new Date(data);
35580
- }
35581
- else if (data instanceof Set) {
35582
- copy = new Set(data);
35583
- }
35584
- else if (isArray || isObject$3(data)) {
35585
- copy = isArray ? [] : {};
35586
- for (const key in data) {
35587
- if (isFunction$1(data[key])) {
35588
- copy = data;
35589
- break;
35590
- }
35591
- copy[key] = cloneObject(data[key]);
35592
- }
35593
- }
35594
- else {
35595
- return data;
35596
- }
35597
- return copy;
35598
- }
35599
-
35600
- function createSubject() {
35601
- let _observers = [];
35602
- const next = (value) => {
35603
- for (const observer of _observers) {
35604
- observer.next(value);
35605
- }
35606
- };
35607
- const subscribe = (observer) => {
35608
- _observers.push(observer);
35609
- return {
35610
- unsubscribe: () => {
35611
- _observers = _observers.filter((o) => o !== observer);
35612
- },
35613
- };
35614
- };
35615
- const unsubscribe = () => {
35616
- _observers = [];
35617
- };
35618
- return {
35619
- get observers() {
35620
- return _observers;
35621
- },
35622
- next,
35623
- subscribe,
35624
- unsubscribe,
35625
- };
35626
- }
35627
-
35628
- var isPrimitive = (value) => isNullOrUndefined$1(value) || !isObjectType(value);
35629
-
35630
- function deepEqual(object1, object2) {
35631
- if (isPrimitive(object1) || isPrimitive(object2)) {
35632
- return object1 === object2;
35633
- }
35634
- if (isDateObject(object1) && isDateObject(object2)) {
35635
- return object1.getTime() === object2.getTime();
35636
- }
35637
- const keys1 = Object.keys(object1);
35638
- const keys2 = Object.keys(object2);
35639
- if (keys1.length !== keys2.length) {
35640
- return false;
35641
- }
35642
- for (const key of keys1) {
35643
- const val1 = object1[key];
35644
- if (!keys2.includes(key)) {
35645
- return false;
35646
- }
35647
- if (key !== 'ref') {
35648
- const val2 = object2[key];
35649
- if ((isDateObject(val1) && isDateObject(val2)) ||
35650
- (isObject$3(val1) && isObject$3(val2)) ||
35651
- (Array.isArray(val1) && Array.isArray(val2))
35652
- ? !deepEqual(val1, val2)
35653
- : val1 !== val2) {
35654
- return false;
35655
- }
35656
- }
35657
- }
35658
- return true;
35659
- }
35660
-
35661
- var getValidationModes = (mode) => ({
35662
- isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
35663
- isOnBlur: mode === VALIDATION_MODE.onBlur,
35664
- isOnChange: mode === VALIDATION_MODE.onChange,
35665
- isOnAll: mode === VALIDATION_MODE.all,
35666
- isOnTouch: mode === VALIDATION_MODE.onTouched,
35667
- });
35668
-
35669
- var isBoolean = (value) => typeof value === 'boolean';
35670
-
35671
- var isFileInput = (element) => element.type === 'file';
35672
-
35673
- var isHTMLElement = (value) => value instanceof HTMLElement;
35674
-
35675
- var isMultipleSelect = (element) => element.type === `select-multiple`;
35676
-
35677
- var isRadioInput = (element) => element.type === 'radio';
35678
-
35679
- var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
35680
-
35681
- var isWeb = typeof window !== 'undefined' &&
35682
- typeof window.HTMLElement !== 'undefined' &&
35683
- typeof document !== 'undefined';
35684
-
35685
- var live = (ref) => isHTMLElement(ref) && ref.isConnected;
35686
-
35687
- function baseGet(object, updatePath) {
35688
- const length = updatePath.slice(0, -1).length;
35689
- let index = 0;
35690
- while (index < length) {
35691
- object = isUndefined(object) ? index++ : object[updatePath[index++]];
35692
- }
35693
- return object;
35694
- }
35695
- function unset(object, path) {
35696
- const updatePath = isKey(path) ? [path] : stringToPath(path);
35697
- const childObject = updatePath.length == 1 ? object : baseGet(object, updatePath);
35698
- const key = updatePath[updatePath.length - 1];
35699
- let previousObjRef;
35700
- if (childObject) {
35701
- delete childObject[key];
35702
- }
35703
- for (let k = 0; k < updatePath.slice(0, -1).length; k++) {
35704
- let index = -1;
35705
- let objectRef;
35706
- const currentPaths = updatePath.slice(0, -(k + 1));
35707
- const currentPathsLength = currentPaths.length - 1;
35708
- if (k > 0) {
35709
- previousObjRef = object;
35710
- }
35711
- while (++index < currentPaths.length) {
35712
- const item = currentPaths[index];
35713
- objectRef = objectRef ? objectRef[item] : object[item];
35714
- if (currentPathsLength === index &&
35715
- ((isObject$3(objectRef) && isEmptyObject(objectRef)) ||
35716
- (Array.isArray(objectRef) &&
35717
- !objectRef.filter((data) => !isUndefined(data)).length))) {
35718
- previousObjRef ? delete previousObjRef[item] : delete object[item];
35719
- }
35720
- previousObjRef = objectRef;
35721
- }
35722
- }
35723
- return object;
35724
- }
35725
-
35726
- function markFieldsDirty(data, fields = {}) {
35727
- const isParentNodeArray = Array.isArray(data);
35728
- if (isObject$3(data) || isParentNodeArray) {
35729
- for (const key in data) {
35730
- if (Array.isArray(data[key]) ||
35731
- (isObject$3(data[key]) && !objectHasFunction(data[key]))) {
35732
- fields[key] = Array.isArray(data[key]) ? [] : {};
35733
- markFieldsDirty(data[key], fields[key]);
35734
- }
35735
- else if (!isNullOrUndefined$1(data[key])) {
35736
- fields[key] = true;
35737
- }
35738
- }
35739
- }
35740
- return fields;
35741
- }
35742
- function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
35743
- const isParentNodeArray = Array.isArray(data);
35744
- if (isObject$3(data) || isParentNodeArray) {
35745
- for (const key in data) {
35746
- if (Array.isArray(data[key]) ||
35747
- (isObject$3(data[key]) && !objectHasFunction(data[key]))) {
35748
- if (isUndefined(formValues) ||
35749
- isPrimitive(dirtyFieldsFromValues[key])) {
35750
- dirtyFieldsFromValues[key] = Array.isArray(data[key])
35751
- ? markFieldsDirty(data[key], [])
35752
- : Object.assign({}, markFieldsDirty(data[key]));
35753
- }
35754
- else {
35755
- getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined$1(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
35756
- }
35757
- }
35758
- else {
35759
- dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
35760
- }
35761
- }
35762
- }
35763
- return dirtyFieldsFromValues;
35764
- }
35765
- var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
35766
-
35767
- const defaultResult = {
35768
- value: false,
35769
- isValid: false,
35770
- };
35771
- const validResult = { value: true, isValid: true };
35772
- var getCheckboxValue = (options) => {
35773
- if (Array.isArray(options)) {
35774
- if (options.length > 1) {
35775
- const values = options
35776
- .filter((option) => option && option.checked && !option.disabled)
35777
- .map((option) => option.value);
35778
- return { value: values, isValid: !!values.length };
35779
- }
35780
- return options[0].checked && !options[0].disabled
35781
- ? // @ts-expect-error expected to work in the browser
35782
- options[0].attributes && !isUndefined(options[0].attributes.value)
35783
- ? isUndefined(options[0].value) || options[0].value === ''
35784
- ? validResult
35785
- : { value: options[0].value, isValid: true }
35786
- : validResult
35787
- : defaultResult;
35788
- }
35789
- return defaultResult;
35790
- };
35791
-
35792
- var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
35793
- ? value
35794
- : valueAsNumber
35795
- ? value === ''
35796
- ? NaN
35797
- : +value
35798
- : valueAsDate && isString(value)
35799
- ? new Date(value)
35800
- : setValueAs
35801
- ? setValueAs(value)
35802
- : value;
35803
-
35804
- const defaultReturn = {
35805
- isValid: false,
35806
- value: null,
35807
- };
35808
- var getRadioValue = (options) => Array.isArray(options)
35809
- ? options.reduce((previous, option) => option && option.checked && !option.disabled
35810
- ? {
35811
- isValid: true,
35812
- value: option.value,
35813
- }
35814
- : previous, defaultReturn)
35815
- : defaultReturn;
35816
-
35817
- function getFieldValue(_f) {
35818
- const ref = _f.ref;
35819
- if (_f.refs ? _f.refs.every((ref) => ref.disabled) : ref.disabled) {
35820
- return;
35821
- }
35822
- if (isFileInput(ref)) {
35823
- return ref.files;
35824
- }
35825
- if (isRadioInput(ref)) {
35826
- return getRadioValue(_f.refs).value;
35827
- }
35828
- if (isMultipleSelect(ref)) {
35829
- return [...ref.selectedOptions].map(({ value }) => value);
35830
- }
35831
- if (isCheckBoxInput(ref)) {
35832
- return getCheckboxValue(_f.refs).value;
35833
- }
35834
- return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
35835
- }
35836
-
35837
- var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
35838
- const fields = {};
35839
- for (const name of fieldsNames) {
35840
- const field = get(_fields, name);
35841
- field && set(fields, name, field._f);
35842
- }
35843
- return {
35844
- criteriaMode,
35845
- names: [...fieldsNames],
35846
- fields,
35847
- shouldUseNativeValidation,
35848
- };
35849
- };
35850
-
35851
- var isRegex = (value) => value instanceof RegExp;
35852
-
35853
- var getRuleValue = (rule) => isUndefined(rule)
35854
- ? undefined
35855
- : isRegex(rule)
35856
- ? rule.source
35857
- : isObject$3(rule)
35858
- ? isRegex(rule.value)
35859
- ? rule.value.source
35860
- : rule.value
35861
- : rule;
35862
-
35863
- var hasValidation = (options) => options.mount &&
35864
- (options.required ||
35865
- options.min ||
35866
- options.max ||
35867
- options.maxLength ||
35868
- options.minLength ||
35869
- options.pattern ||
35870
- options.validate);
35871
-
35872
- function schemaErrorLookup(errors, _fields, name) {
35873
- const error = get(errors, name);
35874
- if (error || isKey(name)) {
35875
- return {
35876
- error,
35877
- name,
35878
- };
35879
- }
35880
- const names = name.split('.');
35881
- while (names.length) {
35882
- const fieldName = names.join('.');
35883
- const field = get(_fields, fieldName);
35884
- const foundError = get(errors, fieldName);
35885
- if (field && !Array.isArray(field) && name !== fieldName) {
35886
- return { name };
35887
- }
35888
- if (foundError && foundError.type) {
35889
- return {
35890
- name: fieldName,
35891
- error: foundError,
35892
- };
35893
- }
35894
- names.pop();
35895
- }
35896
- return {
35897
- name,
35898
- };
35899
- }
35900
-
35901
- var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
35902
- if (mode.isOnAll) {
35903
- return false;
35904
- }
35905
- else if (!isSubmitted && mode.isOnTouch) {
35906
- return !(isTouched || isBlurEvent);
35907
- }
35908
- else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
35909
- return !isBlurEvent;
35910
- }
35911
- else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
35912
- return isBlurEvent;
35913
- }
35914
- return true;
35915
- };
35916
-
35917
- var unsetEmptyArray = (ref, name) => !compact$1(get(ref, name)).length && unset(ref, name);
35918
-
35919
- var isMessage = (value) => isString(value) || React__default.isValidElement(value);
35920
-
35921
- function getValidateError(result, ref, type = 'validate') {
35922
- if (isMessage(result) ||
35923
- (Array.isArray(result) && result.every(isMessage)) ||
35924
- (isBoolean(result) && !result)) {
35925
- return {
35926
- type,
35927
- message: isMessage(result) ? result : '',
35928
- ref,
35929
- };
35930
- }
35931
- }
35932
-
35933
- var getValueAndMessage = (validationData) => isObject$3(validationData) && !isRegex(validationData)
35934
- ? validationData
35935
- : {
35936
- value: validationData,
35937
- message: '',
35938
- };
35939
-
35940
- var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUseNativeValidation) => {
35941
- const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled, } = field._f;
35942
- if (!mount || disabled) {
35943
- return {};
35944
- }
35945
- const inputRef = refs ? refs[0] : ref;
35946
- const setCustomValidity = (message) => {
35947
- if (shouldUseNativeValidation && inputRef.reportValidity) {
35948
- inputRef.setCustomValidity(isBoolean(message) ? '' : message || ' ');
35949
- inputRef.reportValidity();
35950
- }
35951
- };
35952
- const error = {};
35953
- const isRadio = isRadioInput(ref);
35954
- const isCheckBox = isCheckBoxInput(ref);
35955
- const isRadioOrCheckbox = isRadio || isCheckBox;
35956
- const isEmpty = ((valueAsNumber || isFileInput(ref)) && !ref.value) ||
35957
- inputValue === '' ||
35958
- (Array.isArray(inputValue) && !inputValue.length);
35959
- const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
35960
- const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
35961
- const message = exceedMax ? maxLengthMessage : minLengthMessage;
35962
- error[name] = Object.assign({ type: exceedMax ? maxType : minType, message,
35963
- ref }, appendErrorsCurry(exceedMax ? maxType : minType, message));
35964
- };
35965
- if (required &&
35966
- ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined$1(inputValue))) ||
35967
- (isBoolean(inputValue) && !inputValue) ||
35968
- (isCheckBox && !getCheckboxValue(refs).isValid) ||
35969
- (isRadio && !getRadioValue(refs).isValid))) {
35970
- const { value, message } = isMessage(required)
35971
- ? { value: !!required, message: required }
35972
- : getValueAndMessage(required);
35973
- if (value) {
35974
- error[name] = Object.assign({ type: INPUT_VALIDATION_RULES.required, message, ref: inputRef }, appendErrorsCurry(INPUT_VALIDATION_RULES.required, message));
35975
- if (!validateAllFieldCriteria) {
35976
- setCustomValidity(message);
35977
- return error;
35978
- }
35979
- }
35980
- }
35981
- if (!isEmpty && (!isNullOrUndefined$1(min) || !isNullOrUndefined$1(max))) {
35982
- let exceedMax;
35983
- let exceedMin;
35984
- const maxOutput = getValueAndMessage(max);
35985
- const minOutput = getValueAndMessage(min);
35986
- if (!isNaN(inputValue)) {
35987
- const valueNumber = ref.valueAsNumber || +inputValue;
35988
- if (!isNullOrUndefined$1(maxOutput.value)) {
35989
- exceedMax = valueNumber > maxOutput.value;
35990
- }
35991
- if (!isNullOrUndefined$1(minOutput.value)) {
35992
- exceedMin = valueNumber < minOutput.value;
35993
- }
35994
- }
35995
- else {
35996
- const valueDate = ref.valueAsDate || new Date(inputValue);
35997
- if (isString(maxOutput.value)) {
35998
- exceedMax = valueDate > new Date(maxOutput.value);
35999
- }
36000
- if (isString(minOutput.value)) {
36001
- exceedMin = valueDate < new Date(minOutput.value);
36002
- }
36003
- }
36004
- if (exceedMax || exceedMin) {
36005
- getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
36006
- if (!validateAllFieldCriteria) {
36007
- setCustomValidity(error[name].message);
36008
- return error;
36009
- }
36010
- }
36011
- }
36012
- if ((maxLength || minLength) && !isEmpty && isString(inputValue)) {
36013
- const maxLengthOutput = getValueAndMessage(maxLength);
36014
- const minLengthOutput = getValueAndMessage(minLength);
36015
- const exceedMax = !isNullOrUndefined$1(maxLengthOutput.value) &&
36016
- inputValue.length > maxLengthOutput.value;
36017
- const exceedMin = !isNullOrUndefined$1(minLengthOutput.value) &&
36018
- inputValue.length < minLengthOutput.value;
36019
- if (exceedMax || exceedMin) {
36020
- getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
36021
- if (!validateAllFieldCriteria) {
36022
- setCustomValidity(error[name].message);
36023
- return error;
36024
- }
36025
- }
36026
- }
36027
- if (pattern && !isEmpty && isString(inputValue)) {
36028
- const { value: patternValue, message } = getValueAndMessage(pattern);
36029
- if (isRegex(patternValue) && !inputValue.match(patternValue)) {
36030
- error[name] = Object.assign({ type: INPUT_VALIDATION_RULES.pattern, message,
36031
- ref }, appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message));
36032
- if (!validateAllFieldCriteria) {
36033
- setCustomValidity(message);
36034
- return error;
36035
- }
36036
- }
36037
- }
36038
- if (validate) {
36039
- if (isFunction$1(validate)) {
36040
- const result = await validate(inputValue);
36041
- const validateError = getValidateError(result, inputRef);
36042
- if (validateError) {
36043
- error[name] = Object.assign(Object.assign({}, validateError), appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message));
36044
- if (!validateAllFieldCriteria) {
36045
- setCustomValidity(validateError.message);
36046
- return error;
36047
- }
36048
- }
36049
- }
36050
- else if (isObject$3(validate)) {
36051
- let validationResult = {};
36052
- for (const key in validate) {
36053
- if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
36054
- break;
36055
- }
36056
- const validateError = getValidateError(await validate[key](inputValue), inputRef, key);
36057
- if (validateError) {
36058
- validationResult = Object.assign(Object.assign({}, validateError), appendErrorsCurry(key, validateError.message));
36059
- setCustomValidity(validateError.message);
36060
- if (validateAllFieldCriteria) {
36061
- error[name] = validationResult;
36062
- }
36063
- }
36064
- }
36065
- if (!isEmptyObject(validationResult)) {
36066
- error[name] = Object.assign({ ref: inputRef }, validationResult);
36067
- if (!validateAllFieldCriteria) {
36068
- return error;
36069
- }
36070
- }
36071
- }
36072
- }
36073
- setCustomValidity(true);
36074
- return error;
36075
- };
36076
-
36077
- const defaultOptions$1 = {
36078
- mode: VALIDATION_MODE.onSubmit,
36079
- reValidateMode: VALIDATION_MODE.onChange,
36080
- shouldFocusError: true,
36081
- };
36082
- function createFormControl(props = {}) {
36083
- let _options = Object.assign(Object.assign({}, defaultOptions$1), props);
36084
- let _formState = {
36085
- isDirty: false,
36086
- isValidating: false,
36087
- dirtyFields: {},
36088
- isSubmitted: false,
36089
- submitCount: 0,
36090
- touchedFields: {},
36091
- isSubmitting: false,
36092
- isSubmitSuccessful: false,
36093
- isValid: false,
36094
- errors: {},
36095
- };
36096
- let _fields = {};
36097
- let _defaultValues = _options.defaultValues || {};
36098
- let _formValues = _options.shouldUnregister
36099
- ? {}
36100
- : cloneObject(_defaultValues);
36101
- let _stateFlags = {
36102
- action: false,
36103
- mount: false,
36104
- watch: false,
36105
- };
36106
- let _names = {
36107
- mount: new Set(),
36108
- unMount: new Set(),
36109
- array: new Set(),
36110
- watch: new Set(),
36111
- };
36112
- let delayErrorCallback;
36113
- let timer = 0;
36114
- let validateFields = {};
36115
- const _proxyFormState = {
36116
- isDirty: false,
36117
- dirtyFields: false,
36118
- touchedFields: false,
36119
- isValidating: false,
36120
- isValid: false,
36121
- errors: false,
36122
- };
36123
- const _subjects = {
36124
- watch: createSubject(),
36125
- array: createSubject(),
36126
- state: createSubject(),
36127
- };
36128
- const validationModeBeforeSubmit = getValidationModes(_options.mode);
36129
- const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
36130
- const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
36131
- const debounce = (callback, wait) => (...args) => {
36132
- clearTimeout(timer);
36133
- timer = window.setTimeout(() => callback(...args), wait);
36134
- };
36135
- const _updateValid = async (shouldSkipRender) => {
36136
- let isValid = false;
36137
- if (_proxyFormState.isValid) {
36138
- isValid = _options.resolver
36139
- ? isEmptyObject((await _executeSchema()).errors)
36140
- : await executeBuildInValidation(_fields, true);
36141
- if (!shouldSkipRender && isValid !== _formState.isValid) {
36142
- _formState.isValid = isValid;
36143
- _subjects.state.next({
36144
- isValid,
36145
- });
36146
- }
36147
- }
36148
- return isValid;
36149
- };
36150
- const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
36151
- if (args && method) {
36152
- _stateFlags.action = true;
36153
- if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
36154
- const fieldValues = method(get(_fields, name), args.argA, args.argB);
36155
- shouldSetValues && set(_fields, name, fieldValues);
36156
- }
36157
- if (_proxyFormState.errors &&
36158
- shouldUpdateFieldsAndState &&
36159
- Array.isArray(get(_formState.errors, name))) {
36160
- const errors = method(get(_formState.errors, name), args.argA, args.argB);
36161
- shouldSetValues && set(_formState.errors, name, errors);
36162
- unsetEmptyArray(_formState.errors, name);
36163
- }
36164
- if (_proxyFormState.touchedFields &&
36165
- shouldUpdateFieldsAndState &&
36166
- Array.isArray(get(_formState.touchedFields, name))) {
36167
- const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
36168
- shouldSetValues && set(_formState.touchedFields, name, touchedFields);
36169
- }
36170
- if (_proxyFormState.dirtyFields) {
36171
- _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
36172
- }
36173
- _subjects.state.next({
36174
- isDirty: _getDirty(name, values),
36175
- dirtyFields: _formState.dirtyFields,
36176
- errors: _formState.errors,
36177
- isValid: _formState.isValid,
36178
- });
36179
- }
36180
- else {
36181
- set(_formValues, name, values);
36182
- }
36183
- };
36184
- const updateErrors = (name, error) => (set(_formState.errors, name, error),
36185
- _subjects.state.next({
36186
- errors: _formState.errors,
36187
- }));
36188
- const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
36189
- const field = get(_fields, name);
36190
- if (field) {
36191
- const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
36192
- isUndefined(defaultValue) ||
36193
- (ref && ref.defaultChecked) ||
36194
- shouldSkipSetValueAs
36195
- ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
36196
- : setFieldValue(name, defaultValue);
36197
- _stateFlags.mount && _updateValid();
36198
- }
36199
- };
36200
- const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
36201
- let isFieldDirty = false;
36202
- const output = {
36203
- name,
36204
- };
36205
- const isPreviousFieldTouched = get(_formState.touchedFields, name);
36206
- if (_proxyFormState.isDirty) {
36207
- const isPreviousFormDirty = _formState.isDirty;
36208
- _formState.isDirty = output.isDirty = _getDirty();
36209
- isFieldDirty = isPreviousFormDirty !== output.isDirty;
36210
- }
36211
- if (_proxyFormState.dirtyFields && (!isBlurEvent || shouldDirty)) {
36212
- const isPreviousFieldDirty = get(_formState.dirtyFields, name);
36213
- const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
36214
- isCurrentFieldPristine
36215
- ? unset(_formState.dirtyFields, name)
36216
- : set(_formState.dirtyFields, name, true);
36217
- output.dirtyFields = _formState.dirtyFields;
36218
- isFieldDirty =
36219
- isFieldDirty ||
36220
- isPreviousFieldDirty !== get(_formState.dirtyFields, name);
36221
- }
36222
- if (isBlurEvent && !isPreviousFieldTouched) {
36223
- set(_formState.touchedFields, name, isBlurEvent);
36224
- output.touchedFields = _formState.touchedFields;
36225
- isFieldDirty =
36226
- isFieldDirty ||
36227
- (_proxyFormState.touchedFields &&
36228
- isPreviousFieldTouched !== isBlurEvent);
36229
- }
36230
- isFieldDirty && shouldRender && _subjects.state.next(output);
36231
- return isFieldDirty ? output : {};
36232
- };
36233
- const shouldRenderByError = async (shouldSkipRender, name, isValid, error, fieldState) => {
36234
- const previousFieldError = get(_formState.errors, name);
36235
- const shouldUpdateValid = _proxyFormState.isValid && _formState.isValid !== isValid;
36236
- if (props.delayError && error) {
36237
- delayErrorCallback =
36238
- delayErrorCallback || debounce(updateErrors, props.delayError);
36239
- delayErrorCallback(name, error);
36240
- }
36241
- else {
36242
- clearTimeout(timer);
36243
- error
36244
- ? set(_formState.errors, name, error)
36245
- : unset(_formState.errors, name);
36246
- }
36247
- if (((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
36248
- !isEmptyObject(fieldState) ||
36249
- shouldUpdateValid) &&
36250
- !shouldSkipRender) {
36251
- const updatedFormState = Object.assign(Object.assign(Object.assign({}, fieldState), (shouldUpdateValid ? { isValid } : {})), { errors: _formState.errors, name });
36252
- _formState = Object.assign(Object.assign({}, _formState), updatedFormState);
36253
- _subjects.state.next(updatedFormState);
36254
- }
36255
- validateFields[name]--;
36256
- if (_proxyFormState.isValidating &&
36257
- !Object.values(validateFields).some((v) => v)) {
36258
- _subjects.state.next({
36259
- isValidating: false,
36260
- });
36261
- validateFields = {};
36262
- }
36263
- };
36264
- const _executeSchema = async (name) => _options.resolver
36265
- ? await _options.resolver(Object.assign({}, _formValues), _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
36266
- : {};
36267
- const executeSchemaAndUpdateState = async (names) => {
36268
- const { errors } = await _executeSchema();
36269
- if (names) {
36270
- for (const name of names) {
36271
- const error = get(errors, name);
36272
- error
36273
- ? set(_formState.errors, name, error)
36274
- : unset(_formState.errors, name);
36275
- }
36276
- }
36277
- else {
36278
- _formState.errors = errors;
36279
- }
36280
- return errors;
36281
- };
36282
- const executeBuildInValidation = async (fields, shouldOnlyCheckValid, context = {
36283
- valid: true,
36284
- }) => {
36285
- for (const name in fields) {
36286
- const field = fields[name];
36287
- if (field) {
36288
- const fieldReference = field._f;
36289
- const fieldValue = omit(field, '_f');
36290
- if (fieldReference) {
36291
- const fieldError = await validateField(field, get(_formValues, fieldReference.name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation);
36292
- if (fieldError[fieldReference.name]) {
36293
- context.valid = false;
36294
- if (shouldOnlyCheckValid) {
36295
- break;
36296
- }
36297
- }
36298
- if (!shouldOnlyCheckValid) {
36299
- fieldError[fieldReference.name]
36300
- ? set(_formState.errors, fieldReference.name, fieldError[fieldReference.name])
36301
- : unset(_formState.errors, fieldReference.name);
36302
- }
36303
- }
36304
- fieldValue &&
36305
- (await executeBuildInValidation(fieldValue, shouldOnlyCheckValid, context));
36306
- }
36307
- }
36308
- return context.valid;
36309
- };
36310
- const _removeUnmounted = () => {
36311
- for (const name of _names.unMount) {
36312
- const field = get(_fields, name);
36313
- field &&
36314
- (field._f.refs
36315
- ? field._f.refs.every((ref) => !live(ref))
36316
- : !live(field._f.ref)) &&
36317
- unregister(name);
36318
- }
36319
- _names.unMount = new Set();
36320
- };
36321
- const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
36322
- !deepEqual(getValues(), _defaultValues));
36323
- const _getWatch = (names, defaultValue, isGlobal) => {
36324
- const fieldValues = Object.assign({}, (_stateFlags.mount
36325
- ? _formValues
36326
- : isUndefined(defaultValue)
36327
- ? _defaultValues
36328
- : isString(names)
36329
- ? { [names]: defaultValue }
36330
- : defaultValue));
36331
- return generateWatchOutput(names, _names, fieldValues, isGlobal);
36332
- };
36333
- const _getFieldArray = (name) => compact$1(get(_stateFlags.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
36334
- const setFieldValue = (name, value, options = {}) => {
36335
- const field = get(_fields, name);
36336
- let fieldValue = value;
36337
- if (field) {
36338
- const fieldReference = field._f;
36339
- if (fieldReference) {
36340
- !fieldReference.disabled &&
36341
- set(_formValues, name, getFieldValueAs(value, fieldReference));
36342
- fieldValue =
36343
- isWeb && isHTMLElement(fieldReference.ref) && isNullOrUndefined$1(value)
36344
- ? ''
36345
- : value;
36346
- if (isMultipleSelect(fieldReference.ref)) {
36347
- [...fieldReference.ref.options].forEach((selectRef) => (selectRef.selected = fieldValue.includes(selectRef.value)));
36348
- }
36349
- else if (fieldReference.refs) {
36350
- if (isCheckBoxInput(fieldReference.ref)) {
36351
- fieldReference.refs.length > 1
36352
- ? fieldReference.refs.forEach((checkboxRef) => !checkboxRef.disabled &&
36353
- (checkboxRef.checked = Array.isArray(fieldValue)
36354
- ? !!fieldValue.find((data) => data === checkboxRef.value)
36355
- : fieldValue === checkboxRef.value))
36356
- : fieldReference.refs[0] &&
36357
- (fieldReference.refs[0].checked = !!fieldValue);
36358
- }
36359
- else {
36360
- fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
36361
- }
36362
- }
36363
- else if (isFileInput(fieldReference.ref)) {
36364
- fieldReference.ref.value = '';
36365
- }
36366
- else {
36367
- fieldReference.ref.value = fieldValue;
36368
- if (!fieldReference.ref.type) {
36369
- _subjects.watch.next({
36370
- name,
36371
- });
36372
- }
36373
- }
36374
- }
36375
- }
36376
- (options.shouldDirty || options.shouldTouch) &&
36377
- updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
36378
- options.shouldValidate && trigger(name);
36379
- };
36380
- const setValues = (name, value, options) => {
36381
- for (const fieldKey in value) {
36382
- const fieldValue = value[fieldKey];
36383
- const fieldName = `${name}.${fieldKey}`;
36384
- const field = get(_fields, fieldName);
36385
- (_names.array.has(name) ||
36386
- !isPrimitive(fieldValue) ||
36387
- (field && !field._f)) &&
36388
- !isDateObject(fieldValue)
36389
- ? setValues(fieldName, fieldValue, options)
36390
- : setFieldValue(fieldName, fieldValue, options);
36391
- }
36392
- };
36393
- const setValue = (name, value, options = {}) => {
36394
- const field = get(_fields, name);
36395
- const isFieldArray = _names.array.has(name);
36396
- const cloneValue = cloneObject(value);
36397
- set(_formValues, name, cloneValue);
36398
- if (isFieldArray) {
36399
- _subjects.array.next({
36400
- name,
36401
- values: _formValues,
36402
- });
36403
- if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
36404
- options.shouldDirty) {
36405
- _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
36406
- _subjects.state.next({
36407
- name,
36408
- dirtyFields: _formState.dirtyFields,
36409
- isDirty: _getDirty(name, cloneValue),
36410
- });
36411
- }
36412
- }
36413
- else {
36414
- field && !field._f && !isNullOrUndefined$1(cloneValue)
36415
- ? setValues(name, cloneValue, options)
36416
- : setFieldValue(name, cloneValue, options);
36417
- }
36418
- isWatched(name, _names) && _subjects.state.next({});
36419
- _subjects.watch.next({
36420
- name,
36421
- });
36422
- };
36423
- const onChange = async (event) => {
36424
- const target = event.target;
36425
- let name = target.name;
36426
- const field = get(_fields, name);
36427
- if (field) {
36428
- let error;
36429
- let isValid;
36430
- const fieldValue = target.type
36431
- ? getFieldValue(field._f)
36432
- : getEventValue(event);
36433
- const isBlurEvent = event.type === EVENTS$1.BLUR || event.type === EVENTS$1.FOCUS_OUT;
36434
- const shouldSkipValidation = (!hasValidation(field._f) &&
36435
- !_options.resolver &&
36436
- !get(_formState.errors, name) &&
36437
- !field._f.deps) ||
36438
- skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
36439
- const watched = isWatched(name, _names, isBlurEvent);
36440
- set(_formValues, name, fieldValue);
36441
- if (isBlurEvent) {
36442
- field._f.onBlur && field._f.onBlur(event);
36443
- }
36444
- else if (field._f.onChange) {
36445
- field._f.onChange(event);
36446
- }
36447
- const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
36448
- const shouldRender = !isEmptyObject(fieldState) || watched;
36449
- !isBlurEvent &&
36450
- _subjects.watch.next({
36451
- name,
36452
- type: event.type,
36453
- });
36454
- if (shouldSkipValidation) {
36455
- return (shouldRender &&
36456
- _subjects.state.next(Object.assign({ name }, (watched ? {} : fieldState))));
36457
- }
36458
- !isBlurEvent && watched && _subjects.state.next({});
36459
- validateFields[name] = validateFields[name] ? +1 : 1;
36460
- _subjects.state.next({
36461
- isValidating: true,
36462
- });
36463
- if (_options.resolver) {
36464
- const { errors } = await _executeSchema([name]);
36465
- const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
36466
- const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
36467
- error = errorLookupResult.error;
36468
- name = errorLookupResult.name;
36469
- isValid = isEmptyObject(errors);
36470
- }
36471
- else {
36472
- error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
36473
- isValid = await _updateValid(true);
36474
- }
36475
- field._f.deps &&
36476
- trigger(field._f.deps);
36477
- shouldRenderByError(false, name, isValid, error, fieldState);
36478
- }
36479
- };
36480
- const trigger = async (name, options = {}) => {
36481
- let isValid;
36482
- let validationResult;
36483
- const fieldNames = convertToArrayPayload(name);
36484
- _subjects.state.next({
36485
- isValidating: true,
36486
- });
36487
- if (_options.resolver) {
36488
- const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
36489
- isValid = isEmptyObject(errors);
36490
- validationResult = name
36491
- ? !fieldNames.some((name) => get(errors, name))
36492
- : isValid;
36493
- }
36494
- else if (name) {
36495
- validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
36496
- const field = get(_fields, fieldName);
36497
- return await executeBuildInValidation(field && field._f ? { [fieldName]: field } : field);
36498
- }))).every(Boolean);
36499
- !(!validationResult && !_formState.isValid) && _updateValid();
36500
- }
36501
- else {
36502
- validationResult = isValid = await executeBuildInValidation(_fields);
36503
- }
36504
- _subjects.state.next(Object.assign(Object.assign(Object.assign({}, (!isString(name) ||
36505
- (_proxyFormState.isValid && isValid !== _formState.isValid)
36506
- ? {}
36507
- : { name })), (_options.resolver ? { isValid } : {})), { errors: _formState.errors, isValidating: false }));
36508
- options.shouldFocus &&
36509
- !validationResult &&
36510
- focusFieldBy(_fields, (key) => get(_formState.errors, key), name ? fieldNames : _names.mount);
36511
- return validationResult;
36512
- };
36513
- const getValues = (fieldNames) => {
36514
- const values = Object.assign(Object.assign({}, _defaultValues), (_stateFlags.mount ? _formValues : {}));
36515
- return isUndefined(fieldNames)
36516
- ? values
36517
- : isString(fieldNames)
36518
- ? get(values, fieldNames)
36519
- : fieldNames.map((name) => get(values, name));
36520
- };
36521
- const getFieldState = (name, formState) => ({
36522
- invalid: !!get((formState || _formState).errors, name),
36523
- isDirty: !!get((formState || _formState).dirtyFields, name),
36524
- isTouched: !!get((formState || _formState).touchedFields, name),
36525
- error: get((formState || _formState).errors, name),
36526
- });
36527
- const clearErrors = (name) => {
36528
- name
36529
- ? convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName))
36530
- : (_formState.errors = {});
36531
- _subjects.state.next({
36532
- errors: _formState.errors,
36533
- });
36534
- };
36535
- const setError = (name, error, options) => {
36536
- const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
36537
- set(_formState.errors, name, Object.assign(Object.assign({}, error), { ref }));
36538
- _subjects.state.next({
36539
- name,
36540
- errors: _formState.errors,
36541
- isValid: false,
36542
- });
36543
- options && options.shouldFocus && ref && ref.focus && ref.focus();
36544
- };
36545
- const watch = (name, defaultValue) => isFunction$1(name)
36546
- ? _subjects.watch.subscribe({
36547
- next: (info) => name(_getWatch(undefined, defaultValue), info),
36548
- })
36549
- : _getWatch(name, defaultValue, true);
36550
- const unregister = (name, options = {}) => {
36551
- for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
36552
- _names.mount.delete(fieldName);
36553
- _names.array.delete(fieldName);
36554
- if (get(_fields, fieldName)) {
36555
- if (!options.keepValue) {
36556
- unset(_fields, fieldName);
36557
- unset(_formValues, fieldName);
36558
- }
36559
- !options.keepError && unset(_formState.errors, fieldName);
36560
- !options.keepDirty && unset(_formState.dirtyFields, fieldName);
36561
- !options.keepTouched && unset(_formState.touchedFields, fieldName);
36562
- !_options.shouldUnregister &&
36563
- !options.keepDefaultValue &&
36564
- unset(_defaultValues, fieldName);
36565
- }
36566
- }
36567
- _subjects.watch.next({});
36568
- _subjects.state.next(Object.assign(Object.assign({}, _formState), (!options.keepDirty ? {} : { isDirty: _getDirty() })));
36569
- !options.keepIsValid && _updateValid();
36570
- };
36571
- const register = (name, options = {}) => {
36572
- let field = get(_fields, name);
36573
- const disabledIsDefined = isBoolean(options.disabled);
36574
- set(_fields, name, {
36575
- _f: Object.assign(Object.assign(Object.assign({}, (field && field._f ? field._f : { ref: { name } })), { name, mount: true }), options),
36576
- });
36577
- _names.mount.add(name);
36578
- field
36579
- ? disabledIsDefined &&
36580
- set(_formValues, name, options.disabled
36581
- ? undefined
36582
- : get(_formValues, name, getFieldValue(field._f)))
36583
- : updateValidAndValue(name, true, options.value);
36584
- return Object.assign(Object.assign(Object.assign({}, (disabledIsDefined ? { disabled: options.disabled } : {})), (_options.shouldUseNativeValidation
36585
- ? {
36586
- required: !!options.required,
36587
- min: getRuleValue(options.min),
36588
- max: getRuleValue(options.max),
36589
- minLength: getRuleValue(options.minLength),
36590
- maxLength: getRuleValue(options.maxLength),
36591
- pattern: getRuleValue(options.pattern),
36592
- }
36593
- : {})), { name,
36594
- onChange, onBlur: onChange, ref: (ref) => {
36595
- if (ref) {
36596
- register(name, options);
36597
- field = get(_fields, name);
36598
- const fieldRef = isUndefined(ref.value)
36599
- ? ref.querySelectorAll
36600
- ? ref.querySelectorAll('input,select,textarea')[0] || ref
36601
- : ref
36602
- : ref;
36603
- const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
36604
- const refs = field._f.refs || [];
36605
- if (radioOrCheckbox
36606
- ? refs.find((option) => option === fieldRef)
36607
- : fieldRef === field._f.ref) {
36608
- return;
36609
- }
36610
- set(_fields, name, {
36611
- _f: Object.assign(Object.assign({}, field._f), (radioOrCheckbox
36612
- ? {
36613
- refs: [...refs.filter(live), fieldRef],
36614
- ref: { type: fieldRef.type, name },
36615
- }
36616
- : { ref: fieldRef })),
36617
- });
36618
- updateValidAndValue(name, false, undefined, fieldRef);
36619
- }
36620
- else {
36621
- field = get(_fields, name, {});
36622
- if (field._f) {
36623
- field._f.mount = false;
36624
- }
36625
- (_options.shouldUnregister || options.shouldUnregister) &&
36626
- !(isNameInFieldArray(_names.array, name) && _stateFlags.action) &&
36627
- _names.unMount.add(name);
36628
- }
36629
- } });
36630
- };
36631
- const handleSubmit = (onValid, onInvalid) => async (e) => {
36632
- if (e) {
36633
- e.preventDefault && e.preventDefault();
36634
- e.persist && e.persist();
36635
- }
36636
- let hasNoPromiseError = true;
36637
- let fieldValues = cloneObject(_formValues);
36638
- _subjects.state.next({
36639
- isSubmitting: true,
36640
- });
36641
- try {
36642
- if (_options.resolver) {
36643
- const { errors, values } = await _executeSchema();
36644
- _formState.errors = errors;
36645
- fieldValues = values;
36646
- }
36647
- else {
36648
- await executeBuildInValidation(_fields);
36649
- }
36650
- if (isEmptyObject(_formState.errors) &&
36651
- Object.keys(_formState.errors).every((name) => get(fieldValues, name))) {
36652
- _subjects.state.next({
36653
- errors: {},
36654
- isSubmitting: true,
36655
- });
36656
- await onValid(fieldValues, e);
36657
- }
36658
- else {
36659
- if (onInvalid) {
36660
- await onInvalid(Object.assign({}, _formState.errors), e);
36661
- }
36662
- _options.shouldFocusError &&
36663
- focusFieldBy(_fields, (key) => get(_formState.errors, key), _names.mount);
36664
- }
36665
- }
36666
- catch (err) {
36667
- hasNoPromiseError = false;
36668
- throw err;
36669
- }
36670
- finally {
36671
- _formState.isSubmitted = true;
36672
- _subjects.state.next({
36673
- isSubmitted: true,
36674
- isSubmitting: false,
36675
- isSubmitSuccessful: isEmptyObject(_formState.errors) && hasNoPromiseError,
36676
- submitCount: _formState.submitCount + 1,
36677
- errors: _formState.errors,
36678
- });
36679
- }
36680
- };
36681
- const resetField = (name, options = {}) => {
36682
- if (get(_fields, name)) {
36683
- if (isUndefined(options.defaultValue)) {
36684
- setValue(name, get(_defaultValues, name));
36685
- }
36686
- else {
36687
- setValue(name, options.defaultValue);
36688
- set(_defaultValues, name, options.defaultValue);
36689
- }
36690
- if (!options.keepTouched) {
36691
- unset(_formState.touchedFields, name);
36692
- }
36693
- if (!options.keepDirty) {
36694
- unset(_formState.dirtyFields, name);
36695
- _formState.isDirty = options.defaultValue
36696
- ? _getDirty(name, get(_defaultValues, name))
36697
- : _getDirty();
36698
- }
36699
- if (!options.keepError) {
36700
- unset(_formState.errors, name);
36701
- _proxyFormState.isValid && _updateValid();
36702
- }
36703
- _subjects.state.next(Object.assign({}, _formState));
36704
- }
36705
- };
36706
- const reset = (formValues, keepStateOptions = {}) => {
36707
- const updatedValues = formValues || _defaultValues;
36708
- const cloneUpdatedValues = cloneObject(updatedValues);
36709
- const values = formValues && !isEmptyObject(formValues)
36710
- ? cloneUpdatedValues
36711
- : _defaultValues;
36712
- if (!keepStateOptions.keepDefaultValues) {
36713
- _defaultValues = updatedValues;
36714
- }
36715
- if (!keepStateOptions.keepValues) {
36716
- if (isWeb && isUndefined(formValues)) {
36717
- for (const name of _names.mount) {
36718
- const field = get(_fields, name);
36719
- if (field && field._f) {
36720
- const fieldReference = Array.isArray(field._f.refs)
36721
- ? field._f.refs[0]
36722
- : field._f.ref;
36723
- try {
36724
- isHTMLElement(fieldReference) &&
36725
- fieldReference.closest('form').reset();
36726
- break;
36727
- }
36728
- catch (_a) { }
36729
- }
36730
- }
36731
- }
36732
- _formValues = props.shouldUnregister
36733
- ? keepStateOptions.keepDefaultValues
36734
- ? cloneObject(_defaultValues)
36735
- : {}
36736
- : cloneUpdatedValues;
36737
- _fields = {};
36738
- _subjects.array.next({
36739
- values,
36740
- });
36741
- _subjects.watch.next({
36742
- values,
36743
- });
36744
- }
36745
- _names = {
36746
- mount: new Set(),
36747
- unMount: new Set(),
36748
- array: new Set(),
36749
- watch: new Set(),
36750
- watchAll: false,
36751
- focus: '',
36752
- };
36753
- _stateFlags.mount =
36754
- !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
36755
- _stateFlags.watch = !!props.shouldUnregister;
36756
- _subjects.state.next({
36757
- submitCount: keepStateOptions.keepSubmitCount
36758
- ? _formState.submitCount
36759
- : 0,
36760
- isDirty: keepStateOptions.keepDirty
36761
- ? _formState.isDirty
36762
- : keepStateOptions.keepDefaultValues
36763
- ? !deepEqual(formValues, _defaultValues)
36764
- : false,
36765
- isSubmitted: keepStateOptions.keepIsSubmitted
36766
- ? _formState.isSubmitted
36767
- : false,
36768
- dirtyFields: keepStateOptions.keepDirty
36769
- ? _formState.dirtyFields
36770
- : (keepStateOptions.keepDefaultValues && formValues
36771
- ? Object.entries(formValues).reduce((previous, [key, value]) => (Object.assign(Object.assign({}, previous), { [key]: value !== get(_defaultValues, key) })), {})
36772
- : {}),
36773
- touchedFields: keepStateOptions.keepTouched
36774
- ? _formState.touchedFields
36775
- : {},
36776
- errors: keepStateOptions.keepErrors
36777
- ? _formState.errors
36778
- : {},
36779
- isSubmitting: false,
36780
- isSubmitSuccessful: false,
36781
- });
36782
- };
36783
- const setFocus = (name, options = {}) => {
36784
- const field = get(_fields, name)._f;
36785
- const fieldRef = field.refs ? field.refs[0] : field.ref;
36786
- options.shouldSelect ? fieldRef.select() : fieldRef.focus();
36787
- };
36788
- return {
36789
- control: {
36790
- register,
36791
- unregister,
36792
- getFieldState,
36793
- _executeSchema,
36794
- _getWatch,
36795
- _getDirty,
36796
- _updateValid,
36797
- _removeUnmounted,
36798
- _updateFieldArray,
36799
- _getFieldArray,
36800
- _subjects,
36801
- _proxyFormState,
36802
- get _fields() {
36803
- return _fields;
36804
- },
36805
- get _formValues() {
36806
- return _formValues;
36807
- },
36808
- get _stateFlags() {
36809
- return _stateFlags;
36810
- },
36811
- set _stateFlags(value) {
36812
- _stateFlags = value;
36813
- },
36814
- get _defaultValues() {
36815
- return _defaultValues;
36816
- },
36817
- get _names() {
36818
- return _names;
36819
- },
36820
- set _names(value) {
36821
- _names = value;
36822
- },
36823
- get _formState() {
36824
- return _formState;
36825
- },
36826
- set _formState(value) {
36827
- _formState = value;
36828
- },
36829
- get _options() {
36830
- return _options;
36831
- },
36832
- set _options(value) {
36833
- _options = Object.assign(Object.assign({}, _options), value);
36834
- },
36835
- },
36836
- trigger,
36837
- register,
36838
- handleSubmit,
36839
- watch,
36840
- setValue,
36841
- getValues,
36842
- reset,
36843
- resetField,
36844
- clearErrors,
36845
- unregister,
36846
- setError,
36847
- setFocus,
36848
- getFieldState,
36849
- };
36850
- }
36851
-
36852
- /**
36853
- * Custom hook to mange the entire form.
36854
- *
36855
- * @remarks
36856
- * [API](https://react-hook-form.com/api/useform) • [Demo](https://codesandbox.io/s/react-hook-form-get-started-ts-5ksmm) • [Video](https://www.youtube.com/watch?v=RkXv4AXXC_4)
36857
- *
36858
- * @param props - form configuration and validation parameters.
36859
- *
36860
- * @returns methods - individual functions to manage the form state. {@link UseFormReturn}
36861
- *
36862
- * @example
36863
- * ```tsx
36864
- * function App() {
36865
- * const { register, handleSubmit, watch, formState: { errors } } = useForm();
36866
- * const onSubmit = data => console.log(data);
36867
- *
36868
- * console.log(watch("example"));
36869
- *
36870
- * return (
36871
- * <form onSubmit={handleSubmit(onSubmit)}>
36872
- * <input defaultValue="test" {...register("example")} />
36873
- * <input {...register("exampleRequired", { required: true })} />
36874
- * {errors.exampleRequired && <span>This field is required</span>}
36875
- * <input type="submit" />
36876
- * </form>
36877
- * );
36878
- * }
36879
- * ```
36880
- */
36881
- function useForm(props = {}) {
36882
- const _formControl = React__default.useRef();
36883
- const [formState, updateFormState] = React__default.useState({
36884
- isDirty: false,
36885
- isValidating: false,
36886
- dirtyFields: {},
36887
- isSubmitted: false,
36888
- submitCount: 0,
36889
- touchedFields: {},
36890
- isSubmitting: false,
36891
- isSubmitSuccessful: false,
36892
- isValid: false,
36893
- errors: {},
36894
- });
36895
- if (_formControl.current) {
36896
- _formControl.current.control._options = props;
36897
- }
36898
- else {
36899
- _formControl.current = Object.assign(Object.assign({}, createFormControl(props)), { formState });
36900
- }
36901
- const control = _formControl.current.control;
36902
- const callback = React__default.useCallback((value) => {
36903
- if (shouldRenderFormState(value, control._proxyFormState)) {
36904
- control._formState = Object.assign(Object.assign({}, control._formState), value);
36905
- updateFormState(Object.assign({}, control._formState));
36906
- }
36907
- }, [control]);
36908
- useSubscribe({
36909
- subject: control._subjects.state,
36910
- callback,
36911
- });
36912
- React__default.useEffect(() => {
36913
- if (!control._stateFlags.mount) {
36914
- control._proxyFormState.isValid && control._updateValid();
36915
- control._stateFlags.mount = true;
36916
- }
36917
- if (control._stateFlags.watch) {
36918
- control._stateFlags.watch = false;
36919
- control._subjects.state.next({});
36920
- }
36921
- control._removeUnmounted();
36922
- });
36923
- _formControl.current.formState = getProxyFormState(formState, control._proxyFormState);
36924
- return _formControl.current;
36925
- }
36926
-
36927
35366
  var TooltipWrapperStyle = css$1(templateObject_1$4t || (templateObject_1$4t = __makeTemplateObject(["\n align-items: center;\n background-color: ", ";\n border-radius: ", ";\n box-sizing: border-box;\n color: ", ";\n display: flex;\n font-size: ", ";\n font-weight: ", ";\n justify-content: center;\n line-height: 1.2;\n max-width: 240px;\n overflow-wrap: break-word;\n padding: ", ";\n position: absolute;\n text-align: left;\n white-space: pre-wrap;\n width: max-content;\n word-break: keep-all;\n z-index: 400;\n"], ["\n align-items: center;\n background-color: ", ";\n border-radius: ", ";\n box-sizing: border-box;\n color: ", ";\n display: flex;\n font-size: ", ";\n font-weight: ", ";\n justify-content: center;\n line-height: 1.2;\n max-width: 240px;\n overflow-wrap: break-word;\n padding: ", ";\n position: absolute;\n text-align: left;\n white-space: pre-wrap;\n width: max-content;\n word-break: keep-all;\n z-index: 400;\n"])), function (_a) {
36928
35367
  var theme = _a.theme;
36929
35368
  return theme.ui_cpnt_button_tooltip_base;