pds-dev-kit-web-test 2.4.8 → 2.4.10
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 +1 -1668
- package/package.json +2 -1
- package/release-note.md +2 -6
- package/rollup.config.mjs +2 -1
package/dist/index.esm.js
CHANGED
@@ -3,6 +3,7 @@ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import Lottie from 'lottie-react';
|
4
4
|
import * as React from 'react';
|
5
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';
|
6
7
|
import ReactDOM, { createPortal } from 'react-dom';
|
7
8
|
import { Router, __RouterContext, matchPath, useHistory, useLocation } from 'react-router';
|
8
9
|
import NukaCarousel from 'nuka-carousel';
|
@@ -35362,1674 +35363,6 @@ var S_BottomWrapper$7 = styled.div.withConfig({
|
|
35362
35363
|
});
|
35363
35364
|
var templateObject_1$4u, templateObject_2$3m, templateObject_3$2S, templateObject_4$2r;
|
35364
35365
|
|
35365
|
-
var isCheckBoxInput = (element) => element.type === 'checkbox';
|
35366
|
-
|
35367
|
-
var isDateObject = (value) => value instanceof Date;
|
35368
|
-
|
35369
|
-
var isNullOrUndefined$1 = (value) => value == null;
|
35370
|
-
|
35371
|
-
const isObjectType = (value) => typeof value === 'object';
|
35372
|
-
var isObject$3 = (value) => !isNullOrUndefined$1(value) &&
|
35373
|
-
!Array.isArray(value) &&
|
35374
|
-
isObjectType(value) &&
|
35375
|
-
!isDateObject(value);
|
35376
|
-
|
35377
|
-
var getEventValue = (event) => isObject$3(event) && event.target
|
35378
|
-
? isCheckBoxInput(event.target)
|
35379
|
-
? event.target.checked
|
35380
|
-
: event.target.value
|
35381
|
-
: event;
|
35382
|
-
|
35383
|
-
var getNodeParentName = (name) => name.substring(0, name.search(/.\d/)) || name;
|
35384
|
-
|
35385
|
-
var isNameInFieldArray = (names, name) => [...names].some((current) => getNodeParentName(name) === current);
|
35386
|
-
|
35387
|
-
var compact$1 = (value) => value.filter(Boolean);
|
35388
|
-
|
35389
|
-
var isUndefined = (val) => val === undefined;
|
35390
|
-
|
35391
|
-
var get = (obj, path, defaultValue) => {
|
35392
|
-
if (!path || !isObject$3(obj)) {
|
35393
|
-
return defaultValue;
|
35394
|
-
}
|
35395
|
-
const result = compact$1(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined$1(result) ? result : result[key], obj);
|
35396
|
-
return isUndefined(result) || result === obj
|
35397
|
-
? isUndefined(obj[path])
|
35398
|
-
? defaultValue
|
35399
|
-
: obj[path]
|
35400
|
-
: result;
|
35401
|
-
};
|
35402
|
-
|
35403
|
-
const EVENTS$1 = {
|
35404
|
-
BLUR: 'blur',
|
35405
|
-
FOCUS_OUT: 'focusout',
|
35406
|
-
CHANGE: 'change',
|
35407
|
-
};
|
35408
|
-
const VALIDATION_MODE = {
|
35409
|
-
onBlur: 'onBlur',
|
35410
|
-
onChange: 'onChange',
|
35411
|
-
onSubmit: 'onSubmit',
|
35412
|
-
onTouched: 'onTouched',
|
35413
|
-
all: 'all',
|
35414
|
-
};
|
35415
|
-
const INPUT_VALIDATION_RULES = {
|
35416
|
-
max: 'max',
|
35417
|
-
min: 'min',
|
35418
|
-
maxLength: 'maxLength',
|
35419
|
-
minLength: 'minLength',
|
35420
|
-
pattern: 'pattern',
|
35421
|
-
required: 'required',
|
35422
|
-
validate: 'validate',
|
35423
|
-
};
|
35424
|
-
|
35425
|
-
var omit = (source, key) => {
|
35426
|
-
const copy = Object.assign({}, source);
|
35427
|
-
delete copy[key];
|
35428
|
-
return copy;
|
35429
|
-
};
|
35430
|
-
|
35431
|
-
const HookFormContext = React__default.createContext(null);
|
35432
|
-
/**
|
35433
|
-
* 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}.
|
35434
|
-
*
|
35435
|
-
* @remarks
|
35436
|
-
* [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
35437
|
-
*
|
35438
|
-
* @returns return all useForm methods
|
35439
|
-
*
|
35440
|
-
* @example
|
35441
|
-
* ```tsx
|
35442
|
-
* function App() {
|
35443
|
-
* const methods = useForm();
|
35444
|
-
* const onSubmit = data => console.log(data);
|
35445
|
-
*
|
35446
|
-
* return (
|
35447
|
-
* <FormProvider {...methods} >
|
35448
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
35449
|
-
* <NestedInput />
|
35450
|
-
* <input type="submit" />
|
35451
|
-
* </form>
|
35452
|
-
* </FormProvider>
|
35453
|
-
* );
|
35454
|
-
* }
|
35455
|
-
*
|
35456
|
-
* function NestedInput() {
|
35457
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
35458
|
-
* return <input {...register("test")} />;
|
35459
|
-
* }
|
35460
|
-
* ```
|
35461
|
-
*/
|
35462
|
-
const useFormContext = () => React__default.useContext(HookFormContext);
|
35463
|
-
/**
|
35464
|
-
* 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}.
|
35465
|
-
*
|
35466
|
-
* @remarks
|
35467
|
-
* [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
35468
|
-
*
|
35469
|
-
* @param props - all useFrom methods
|
35470
|
-
*
|
35471
|
-
* @example
|
35472
|
-
* ```tsx
|
35473
|
-
* function App() {
|
35474
|
-
* const methods = useForm();
|
35475
|
-
* const onSubmit = data => console.log(data);
|
35476
|
-
*
|
35477
|
-
* return (
|
35478
|
-
* <FormProvider {...methods} >
|
35479
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
35480
|
-
* <NestedInput />
|
35481
|
-
* <input type="submit" />
|
35482
|
-
* </form>
|
35483
|
-
* </FormProvider>
|
35484
|
-
* );
|
35485
|
-
* }
|
35486
|
-
*
|
35487
|
-
* function NestedInput() {
|
35488
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
35489
|
-
* return <input {...register("test")} />;
|
35490
|
-
* }
|
35491
|
-
* ```
|
35492
|
-
*/
|
35493
|
-
const FormProvider = (props) => (React__default.createElement(HookFormContext.Provider, { value: omit(props, 'children') }, props.children));
|
35494
|
-
|
35495
|
-
var getProxyFormState = (formState, _proxyFormState, localProxyFormState, isRoot = true) => {
|
35496
|
-
const result = {};
|
35497
|
-
for (const key in formState) {
|
35498
|
-
Object.defineProperty(result, key, {
|
35499
|
-
get: () => {
|
35500
|
-
const _key = key;
|
35501
|
-
if (_proxyFormState[_key] !== VALIDATION_MODE.all) {
|
35502
|
-
_proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
|
35503
|
-
}
|
35504
|
-
return formState[_key];
|
35505
|
-
},
|
35506
|
-
});
|
35507
|
-
}
|
35508
|
-
return result;
|
35509
|
-
};
|
35510
|
-
|
35511
|
-
var isEmptyObject = (value) => isObject$3(value) && !Object.keys(value).length;
|
35512
|
-
|
35513
|
-
var shouldRenderFormState = (formStateData, _proxyFormState, isRoot) => {
|
35514
|
-
const formState = omit(formStateData, 'name');
|
35515
|
-
return (isEmptyObject(formState) ||
|
35516
|
-
Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
|
35517
|
-
Object.keys(formState).find((key) => _proxyFormState[key] ===
|
35518
|
-
(VALIDATION_MODE.all)));
|
35519
|
-
};
|
35520
|
-
|
35521
|
-
var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
|
35522
|
-
|
35523
|
-
var shouldSubscribeByName = (name, signalName, exact) => exact && signalName
|
35524
|
-
? name === signalName
|
35525
|
-
: !name ||
|
35526
|
-
!signalName ||
|
35527
|
-
name === signalName ||
|
35528
|
-
convertToArrayPayload(name).some((currentName) => currentName &&
|
35529
|
-
(currentName.startsWith(signalName) ||
|
35530
|
-
signalName.startsWith(currentName)));
|
35531
|
-
|
35532
|
-
function useSubscribe(props) {
|
35533
|
-
const _props = React__default.useRef(props);
|
35534
|
-
_props.current = props;
|
35535
|
-
React__default.useEffect(() => {
|
35536
|
-
const tearDown = (subscription) => {
|
35537
|
-
if (subscription) {
|
35538
|
-
subscription.unsubscribe();
|
35539
|
-
}
|
35540
|
-
};
|
35541
|
-
const subscription = !props.disabled &&
|
35542
|
-
_props.current.subject.subscribe({
|
35543
|
-
next: _props.current.callback,
|
35544
|
-
});
|
35545
|
-
return () => tearDown(subscription);
|
35546
|
-
}, [props.disabled]);
|
35547
|
-
}
|
35548
|
-
|
35549
|
-
var isString = (value) => typeof value === 'string';
|
35550
|
-
|
35551
|
-
var generateWatchOutput = (names, _names, formValues, isGlobal) => {
|
35552
|
-
const isArray = Array.isArray(names);
|
35553
|
-
if (isString(names)) {
|
35554
|
-
isGlobal && _names.watch.add(names);
|
35555
|
-
return get(formValues, names);
|
35556
|
-
}
|
35557
|
-
if (isArray) {
|
35558
|
-
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
|
35559
|
-
get(formValues, fieldName)));
|
35560
|
-
}
|
35561
|
-
isGlobal && (_names.watchAll = true);
|
35562
|
-
return formValues;
|
35563
|
-
};
|
35564
|
-
|
35565
|
-
var isFunction$1 = (value) => typeof value === 'function';
|
35566
|
-
|
35567
|
-
var objectHasFunction = (data) => {
|
35568
|
-
for (const key in data) {
|
35569
|
-
if (isFunction$1(data[key])) {
|
35570
|
-
return true;
|
35571
|
-
}
|
35572
|
-
}
|
35573
|
-
return false;
|
35574
|
-
};
|
35575
|
-
|
35576
|
-
/**
|
35577
|
-
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
|
35578
|
-
*
|
35579
|
-
* @remarks
|
35580
|
-
*
|
35581
|
-
* [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
|
35582
|
-
*
|
35583
|
-
* @example
|
35584
|
-
* ```tsx
|
35585
|
-
* const { watch } = useForm();
|
35586
|
-
* const values = useWatch({
|
35587
|
-
* name: "fieldName"
|
35588
|
-
* control,
|
35589
|
-
* })
|
35590
|
-
* ```
|
35591
|
-
*/
|
35592
|
-
function useWatch(props) {
|
35593
|
-
const methods = useFormContext();
|
35594
|
-
const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
|
35595
|
-
const _name = React__default.useRef(name);
|
35596
|
-
_name.current = name;
|
35597
|
-
const callback = React__default.useCallback((formState) => {
|
35598
|
-
if (shouldSubscribeByName(_name.current, formState.name, exact)) {
|
35599
|
-
const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
|
35600
|
-
updateValue(isUndefined(_name.current) ||
|
35601
|
-
(isObject$3(fieldValues) && !objectHasFunction(fieldValues))
|
35602
|
-
? Object.assign({}, fieldValues) : Array.isArray(fieldValues)
|
35603
|
-
? [...fieldValues]
|
35604
|
-
: isUndefined(fieldValues)
|
35605
|
-
? defaultValue
|
35606
|
-
: fieldValues);
|
35607
|
-
}
|
35608
|
-
}, [control, exact, defaultValue]);
|
35609
|
-
useSubscribe({
|
35610
|
-
disabled,
|
35611
|
-
subject: control._subjects.watch,
|
35612
|
-
callback,
|
35613
|
-
});
|
35614
|
-
const [value, updateValue] = React__default.useState(isUndefined(defaultValue)
|
35615
|
-
? control._getWatch(name)
|
35616
|
-
: defaultValue);
|
35617
|
-
React__default.useEffect(() => {
|
35618
|
-
control._removeUnmounted();
|
35619
|
-
});
|
35620
|
-
return value;
|
35621
|
-
}
|
35622
|
-
|
35623
|
-
var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
|
35624
|
-
? Object.assign(Object.assign({}, errors[name]), { types: Object.assign(Object.assign({}, (errors[name] && errors[name].types ? errors[name].types : {})), { [type]: message || true }) }) : {};
|
35625
|
-
|
35626
|
-
var isKey = (value) => /^\w*$/.test(value);
|
35627
|
-
|
35628
|
-
var stringToPath = (input) => compact$1(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
35629
|
-
|
35630
|
-
function set(object, path, value) {
|
35631
|
-
let index = -1;
|
35632
|
-
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
35633
|
-
const length = tempPath.length;
|
35634
|
-
const lastIndex = length - 1;
|
35635
|
-
while (++index < length) {
|
35636
|
-
const key = tempPath[index];
|
35637
|
-
let newValue = value;
|
35638
|
-
if (index !== lastIndex) {
|
35639
|
-
const objValue = object[key];
|
35640
|
-
newValue =
|
35641
|
-
isObject$3(objValue) || Array.isArray(objValue)
|
35642
|
-
? objValue
|
35643
|
-
: !isNaN(+tempPath[index + 1])
|
35644
|
-
? []
|
35645
|
-
: {};
|
35646
|
-
}
|
35647
|
-
object[key] = newValue;
|
35648
|
-
object = object[key];
|
35649
|
-
}
|
35650
|
-
return object;
|
35651
|
-
}
|
35652
|
-
|
35653
|
-
const focusFieldBy = (fields, callback, fieldsNames) => {
|
35654
|
-
for (const key of fieldsNames || Object.keys(fields)) {
|
35655
|
-
const field = get(fields, key);
|
35656
|
-
if (field) {
|
35657
|
-
const _f = field._f;
|
35658
|
-
const current = omit(field, '_f');
|
35659
|
-
if (_f && callback(_f.name)) {
|
35660
|
-
if (_f.ref.focus && isUndefined(_f.ref.focus())) {
|
35661
|
-
break;
|
35662
|
-
}
|
35663
|
-
else if (_f.refs) {
|
35664
|
-
_f.refs[0].focus();
|
35665
|
-
break;
|
35666
|
-
}
|
35667
|
-
}
|
35668
|
-
else if (isObject$3(current)) {
|
35669
|
-
focusFieldBy(current, callback);
|
35670
|
-
}
|
35671
|
-
}
|
35672
|
-
}
|
35673
|
-
};
|
35674
|
-
|
35675
|
-
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
|
35676
|
-
(_names.watchAll ||
|
35677
|
-
_names.watch.has(name) ||
|
35678
|
-
[..._names.watch].some((watchName) => name.startsWith(watchName) &&
|
35679
|
-
/^\.\w+/.test(name.slice(watchName.length))));
|
35680
|
-
|
35681
|
-
function cloneObject(data) {
|
35682
|
-
let copy;
|
35683
|
-
const isArray = Array.isArray(data);
|
35684
|
-
if (data instanceof Date) {
|
35685
|
-
copy = new Date(data);
|
35686
|
-
}
|
35687
|
-
else if (data instanceof Set) {
|
35688
|
-
copy = new Set(data);
|
35689
|
-
}
|
35690
|
-
else if (isArray || isObject$3(data)) {
|
35691
|
-
copy = isArray ? [] : {};
|
35692
|
-
for (const key in data) {
|
35693
|
-
if (isFunction$1(data[key])) {
|
35694
|
-
copy = data;
|
35695
|
-
break;
|
35696
|
-
}
|
35697
|
-
copy[key] = cloneObject(data[key]);
|
35698
|
-
}
|
35699
|
-
}
|
35700
|
-
else {
|
35701
|
-
return data;
|
35702
|
-
}
|
35703
|
-
return copy;
|
35704
|
-
}
|
35705
|
-
|
35706
|
-
function createSubject() {
|
35707
|
-
let _observers = [];
|
35708
|
-
const next = (value) => {
|
35709
|
-
for (const observer of _observers) {
|
35710
|
-
observer.next(value);
|
35711
|
-
}
|
35712
|
-
};
|
35713
|
-
const subscribe = (observer) => {
|
35714
|
-
_observers.push(observer);
|
35715
|
-
return {
|
35716
|
-
unsubscribe: () => {
|
35717
|
-
_observers = _observers.filter((o) => o !== observer);
|
35718
|
-
},
|
35719
|
-
};
|
35720
|
-
};
|
35721
|
-
const unsubscribe = () => {
|
35722
|
-
_observers = [];
|
35723
|
-
};
|
35724
|
-
return {
|
35725
|
-
get observers() {
|
35726
|
-
return _observers;
|
35727
|
-
},
|
35728
|
-
next,
|
35729
|
-
subscribe,
|
35730
|
-
unsubscribe,
|
35731
|
-
};
|
35732
|
-
}
|
35733
|
-
|
35734
|
-
var isPrimitive = (value) => isNullOrUndefined$1(value) || !isObjectType(value);
|
35735
|
-
|
35736
|
-
function deepEqual(object1, object2) {
|
35737
|
-
if (isPrimitive(object1) || isPrimitive(object2)) {
|
35738
|
-
return object1 === object2;
|
35739
|
-
}
|
35740
|
-
if (isDateObject(object1) && isDateObject(object2)) {
|
35741
|
-
return object1.getTime() === object2.getTime();
|
35742
|
-
}
|
35743
|
-
const keys1 = Object.keys(object1);
|
35744
|
-
const keys2 = Object.keys(object2);
|
35745
|
-
if (keys1.length !== keys2.length) {
|
35746
|
-
return false;
|
35747
|
-
}
|
35748
|
-
for (const key of keys1) {
|
35749
|
-
const val1 = object1[key];
|
35750
|
-
if (!keys2.includes(key)) {
|
35751
|
-
return false;
|
35752
|
-
}
|
35753
|
-
if (key !== 'ref') {
|
35754
|
-
const val2 = object2[key];
|
35755
|
-
if ((isDateObject(val1) && isDateObject(val2)) ||
|
35756
|
-
(isObject$3(val1) && isObject$3(val2)) ||
|
35757
|
-
(Array.isArray(val1) && Array.isArray(val2))
|
35758
|
-
? !deepEqual(val1, val2)
|
35759
|
-
: val1 !== val2) {
|
35760
|
-
return false;
|
35761
|
-
}
|
35762
|
-
}
|
35763
|
-
}
|
35764
|
-
return true;
|
35765
|
-
}
|
35766
|
-
|
35767
|
-
var getValidationModes = (mode) => ({
|
35768
|
-
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
|
35769
|
-
isOnBlur: mode === VALIDATION_MODE.onBlur,
|
35770
|
-
isOnChange: mode === VALIDATION_MODE.onChange,
|
35771
|
-
isOnAll: mode === VALIDATION_MODE.all,
|
35772
|
-
isOnTouch: mode === VALIDATION_MODE.onTouched,
|
35773
|
-
});
|
35774
|
-
|
35775
|
-
var isBoolean = (value) => typeof value === 'boolean';
|
35776
|
-
|
35777
|
-
var isFileInput = (element) => element.type === 'file';
|
35778
|
-
|
35779
|
-
var isHTMLElement = (value) => value instanceof HTMLElement;
|
35780
|
-
|
35781
|
-
var isMultipleSelect = (element) => element.type === `select-multiple`;
|
35782
|
-
|
35783
|
-
var isRadioInput = (element) => element.type === 'radio';
|
35784
|
-
|
35785
|
-
var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
|
35786
|
-
|
35787
|
-
var isWeb = typeof window !== 'undefined' &&
|
35788
|
-
typeof window.HTMLElement !== 'undefined' &&
|
35789
|
-
typeof document !== 'undefined';
|
35790
|
-
|
35791
|
-
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
|
35792
|
-
|
35793
|
-
function baseGet(object, updatePath) {
|
35794
|
-
const length = updatePath.slice(0, -1).length;
|
35795
|
-
let index = 0;
|
35796
|
-
while (index < length) {
|
35797
|
-
object = isUndefined(object) ? index++ : object[updatePath[index++]];
|
35798
|
-
}
|
35799
|
-
return object;
|
35800
|
-
}
|
35801
|
-
function unset(object, path) {
|
35802
|
-
const updatePath = isKey(path) ? [path] : stringToPath(path);
|
35803
|
-
const childObject = updatePath.length == 1 ? object : baseGet(object, updatePath);
|
35804
|
-
const key = updatePath[updatePath.length - 1];
|
35805
|
-
let previousObjRef;
|
35806
|
-
if (childObject) {
|
35807
|
-
delete childObject[key];
|
35808
|
-
}
|
35809
|
-
for (let k = 0; k < updatePath.slice(0, -1).length; k++) {
|
35810
|
-
let index = -1;
|
35811
|
-
let objectRef;
|
35812
|
-
const currentPaths = updatePath.slice(0, -(k + 1));
|
35813
|
-
const currentPathsLength = currentPaths.length - 1;
|
35814
|
-
if (k > 0) {
|
35815
|
-
previousObjRef = object;
|
35816
|
-
}
|
35817
|
-
while (++index < currentPaths.length) {
|
35818
|
-
const item = currentPaths[index];
|
35819
|
-
objectRef = objectRef ? objectRef[item] : object[item];
|
35820
|
-
if (currentPathsLength === index &&
|
35821
|
-
((isObject$3(objectRef) && isEmptyObject(objectRef)) ||
|
35822
|
-
(Array.isArray(objectRef) &&
|
35823
|
-
!objectRef.filter((data) => !isUndefined(data)).length))) {
|
35824
|
-
previousObjRef ? delete previousObjRef[item] : delete object[item];
|
35825
|
-
}
|
35826
|
-
previousObjRef = objectRef;
|
35827
|
-
}
|
35828
|
-
}
|
35829
|
-
return object;
|
35830
|
-
}
|
35831
|
-
|
35832
|
-
function markFieldsDirty(data, fields = {}) {
|
35833
|
-
const isParentNodeArray = Array.isArray(data);
|
35834
|
-
if (isObject$3(data) || isParentNodeArray) {
|
35835
|
-
for (const key in data) {
|
35836
|
-
if (Array.isArray(data[key]) ||
|
35837
|
-
(isObject$3(data[key]) && !objectHasFunction(data[key]))) {
|
35838
|
-
fields[key] = Array.isArray(data[key]) ? [] : {};
|
35839
|
-
markFieldsDirty(data[key], fields[key]);
|
35840
|
-
}
|
35841
|
-
else if (!isNullOrUndefined$1(data[key])) {
|
35842
|
-
fields[key] = true;
|
35843
|
-
}
|
35844
|
-
}
|
35845
|
-
}
|
35846
|
-
return fields;
|
35847
|
-
}
|
35848
|
-
function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
|
35849
|
-
const isParentNodeArray = Array.isArray(data);
|
35850
|
-
if (isObject$3(data) || isParentNodeArray) {
|
35851
|
-
for (const key in data) {
|
35852
|
-
if (Array.isArray(data[key]) ||
|
35853
|
-
(isObject$3(data[key]) && !objectHasFunction(data[key]))) {
|
35854
|
-
if (isUndefined(formValues) ||
|
35855
|
-
isPrimitive(dirtyFieldsFromValues[key])) {
|
35856
|
-
dirtyFieldsFromValues[key] = Array.isArray(data[key])
|
35857
|
-
? markFieldsDirty(data[key], [])
|
35858
|
-
: Object.assign({}, markFieldsDirty(data[key]));
|
35859
|
-
}
|
35860
|
-
else {
|
35861
|
-
getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined$1(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
35862
|
-
}
|
35863
|
-
}
|
35864
|
-
else {
|
35865
|
-
dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
|
35866
|
-
}
|
35867
|
-
}
|
35868
|
-
}
|
35869
|
-
return dirtyFieldsFromValues;
|
35870
|
-
}
|
35871
|
-
var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
|
35872
|
-
|
35873
|
-
const defaultResult = {
|
35874
|
-
value: false,
|
35875
|
-
isValid: false,
|
35876
|
-
};
|
35877
|
-
const validResult = { value: true, isValid: true };
|
35878
|
-
var getCheckboxValue = (options) => {
|
35879
|
-
if (Array.isArray(options)) {
|
35880
|
-
if (options.length > 1) {
|
35881
|
-
const values = options
|
35882
|
-
.filter((option) => option && option.checked && !option.disabled)
|
35883
|
-
.map((option) => option.value);
|
35884
|
-
return { value: values, isValid: !!values.length };
|
35885
|
-
}
|
35886
|
-
return options[0].checked && !options[0].disabled
|
35887
|
-
? // @ts-expect-error expected to work in the browser
|
35888
|
-
options[0].attributes && !isUndefined(options[0].attributes.value)
|
35889
|
-
? isUndefined(options[0].value) || options[0].value === ''
|
35890
|
-
? validResult
|
35891
|
-
: { value: options[0].value, isValid: true }
|
35892
|
-
: validResult
|
35893
|
-
: defaultResult;
|
35894
|
-
}
|
35895
|
-
return defaultResult;
|
35896
|
-
};
|
35897
|
-
|
35898
|
-
var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
|
35899
|
-
? value
|
35900
|
-
: valueAsNumber
|
35901
|
-
? value === ''
|
35902
|
-
? NaN
|
35903
|
-
: +value
|
35904
|
-
: valueAsDate && isString(value)
|
35905
|
-
? new Date(value)
|
35906
|
-
: setValueAs
|
35907
|
-
? setValueAs(value)
|
35908
|
-
: value;
|
35909
|
-
|
35910
|
-
const defaultReturn = {
|
35911
|
-
isValid: false,
|
35912
|
-
value: null,
|
35913
|
-
};
|
35914
|
-
var getRadioValue = (options) => Array.isArray(options)
|
35915
|
-
? options.reduce((previous, option) => option && option.checked && !option.disabled
|
35916
|
-
? {
|
35917
|
-
isValid: true,
|
35918
|
-
value: option.value,
|
35919
|
-
}
|
35920
|
-
: previous, defaultReturn)
|
35921
|
-
: defaultReturn;
|
35922
|
-
|
35923
|
-
function getFieldValue(_f) {
|
35924
|
-
const ref = _f.ref;
|
35925
|
-
if (_f.refs ? _f.refs.every((ref) => ref.disabled) : ref.disabled) {
|
35926
|
-
return;
|
35927
|
-
}
|
35928
|
-
if (isFileInput(ref)) {
|
35929
|
-
return ref.files;
|
35930
|
-
}
|
35931
|
-
if (isRadioInput(ref)) {
|
35932
|
-
return getRadioValue(_f.refs).value;
|
35933
|
-
}
|
35934
|
-
if (isMultipleSelect(ref)) {
|
35935
|
-
return [...ref.selectedOptions].map(({ value }) => value);
|
35936
|
-
}
|
35937
|
-
if (isCheckBoxInput(ref)) {
|
35938
|
-
return getCheckboxValue(_f.refs).value;
|
35939
|
-
}
|
35940
|
-
return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
|
35941
|
-
}
|
35942
|
-
|
35943
|
-
var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
|
35944
|
-
const fields = {};
|
35945
|
-
for (const name of fieldsNames) {
|
35946
|
-
const field = get(_fields, name);
|
35947
|
-
field && set(fields, name, field._f);
|
35948
|
-
}
|
35949
|
-
return {
|
35950
|
-
criteriaMode,
|
35951
|
-
names: [...fieldsNames],
|
35952
|
-
fields,
|
35953
|
-
shouldUseNativeValidation,
|
35954
|
-
};
|
35955
|
-
};
|
35956
|
-
|
35957
|
-
var isRegex = (value) => value instanceof RegExp;
|
35958
|
-
|
35959
|
-
var getRuleValue = (rule) => isUndefined(rule)
|
35960
|
-
? undefined
|
35961
|
-
: isRegex(rule)
|
35962
|
-
? rule.source
|
35963
|
-
: isObject$3(rule)
|
35964
|
-
? isRegex(rule.value)
|
35965
|
-
? rule.value.source
|
35966
|
-
: rule.value
|
35967
|
-
: rule;
|
35968
|
-
|
35969
|
-
var hasValidation = (options) => options.mount &&
|
35970
|
-
(options.required ||
|
35971
|
-
options.min ||
|
35972
|
-
options.max ||
|
35973
|
-
options.maxLength ||
|
35974
|
-
options.minLength ||
|
35975
|
-
options.pattern ||
|
35976
|
-
options.validate);
|
35977
|
-
|
35978
|
-
function schemaErrorLookup(errors, _fields, name) {
|
35979
|
-
const error = get(errors, name);
|
35980
|
-
if (error || isKey(name)) {
|
35981
|
-
return {
|
35982
|
-
error,
|
35983
|
-
name,
|
35984
|
-
};
|
35985
|
-
}
|
35986
|
-
const names = name.split('.');
|
35987
|
-
while (names.length) {
|
35988
|
-
const fieldName = names.join('.');
|
35989
|
-
const field = get(_fields, fieldName);
|
35990
|
-
const foundError = get(errors, fieldName);
|
35991
|
-
if (field && !Array.isArray(field) && name !== fieldName) {
|
35992
|
-
return { name };
|
35993
|
-
}
|
35994
|
-
if (foundError && foundError.type) {
|
35995
|
-
return {
|
35996
|
-
name: fieldName,
|
35997
|
-
error: foundError,
|
35998
|
-
};
|
35999
|
-
}
|
36000
|
-
names.pop();
|
36001
|
-
}
|
36002
|
-
return {
|
36003
|
-
name,
|
36004
|
-
};
|
36005
|
-
}
|
36006
|
-
|
36007
|
-
var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
|
36008
|
-
if (mode.isOnAll) {
|
36009
|
-
return false;
|
36010
|
-
}
|
36011
|
-
else if (!isSubmitted && mode.isOnTouch) {
|
36012
|
-
return !(isTouched || isBlurEvent);
|
36013
|
-
}
|
36014
|
-
else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
|
36015
|
-
return !isBlurEvent;
|
36016
|
-
}
|
36017
|
-
else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
|
36018
|
-
return isBlurEvent;
|
36019
|
-
}
|
36020
|
-
return true;
|
36021
|
-
};
|
36022
|
-
|
36023
|
-
var unsetEmptyArray = (ref, name) => !compact$1(get(ref, name)).length && unset(ref, name);
|
36024
|
-
|
36025
|
-
var isMessage = (value) => isString(value) || React__default.isValidElement(value);
|
36026
|
-
|
36027
|
-
function getValidateError(result, ref, type = 'validate') {
|
36028
|
-
if (isMessage(result) ||
|
36029
|
-
(Array.isArray(result) && result.every(isMessage)) ||
|
36030
|
-
(isBoolean(result) && !result)) {
|
36031
|
-
return {
|
36032
|
-
type,
|
36033
|
-
message: isMessage(result) ? result : '',
|
36034
|
-
ref,
|
36035
|
-
};
|
36036
|
-
}
|
36037
|
-
}
|
36038
|
-
|
36039
|
-
var getValueAndMessage = (validationData) => isObject$3(validationData) && !isRegex(validationData)
|
36040
|
-
? validationData
|
36041
|
-
: {
|
36042
|
-
value: validationData,
|
36043
|
-
message: '',
|
36044
|
-
};
|
36045
|
-
|
36046
|
-
var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUseNativeValidation) => {
|
36047
|
-
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled, } = field._f;
|
36048
|
-
if (!mount || disabled) {
|
36049
|
-
return {};
|
36050
|
-
}
|
36051
|
-
const inputRef = refs ? refs[0] : ref;
|
36052
|
-
const setCustomValidity = (message) => {
|
36053
|
-
if (shouldUseNativeValidation && inputRef.reportValidity) {
|
36054
|
-
inputRef.setCustomValidity(isBoolean(message) ? '' : message || ' ');
|
36055
|
-
inputRef.reportValidity();
|
36056
|
-
}
|
36057
|
-
};
|
36058
|
-
const error = {};
|
36059
|
-
const isRadio = isRadioInput(ref);
|
36060
|
-
const isCheckBox = isCheckBoxInput(ref);
|
36061
|
-
const isRadioOrCheckbox = isRadio || isCheckBox;
|
36062
|
-
const isEmpty = ((valueAsNumber || isFileInput(ref)) && !ref.value) ||
|
36063
|
-
inputValue === '' ||
|
36064
|
-
(Array.isArray(inputValue) && !inputValue.length);
|
36065
|
-
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
36066
|
-
const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
|
36067
|
-
const message = exceedMax ? maxLengthMessage : minLengthMessage;
|
36068
|
-
error[name] = Object.assign({ type: exceedMax ? maxType : minType, message,
|
36069
|
-
ref }, appendErrorsCurry(exceedMax ? maxType : minType, message));
|
36070
|
-
};
|
36071
|
-
if (required &&
|
36072
|
-
((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined$1(inputValue))) ||
|
36073
|
-
(isBoolean(inputValue) && !inputValue) ||
|
36074
|
-
(isCheckBox && !getCheckboxValue(refs).isValid) ||
|
36075
|
-
(isRadio && !getRadioValue(refs).isValid))) {
|
36076
|
-
const { value, message } = isMessage(required)
|
36077
|
-
? { value: !!required, message: required }
|
36078
|
-
: getValueAndMessage(required);
|
36079
|
-
if (value) {
|
36080
|
-
error[name] = Object.assign({ type: INPUT_VALIDATION_RULES.required, message, ref: inputRef }, appendErrorsCurry(INPUT_VALIDATION_RULES.required, message));
|
36081
|
-
if (!validateAllFieldCriteria) {
|
36082
|
-
setCustomValidity(message);
|
36083
|
-
return error;
|
36084
|
-
}
|
36085
|
-
}
|
36086
|
-
}
|
36087
|
-
if (!isEmpty && (!isNullOrUndefined$1(min) || !isNullOrUndefined$1(max))) {
|
36088
|
-
let exceedMax;
|
36089
|
-
let exceedMin;
|
36090
|
-
const maxOutput = getValueAndMessage(max);
|
36091
|
-
const minOutput = getValueAndMessage(min);
|
36092
|
-
if (!isNaN(inputValue)) {
|
36093
|
-
const valueNumber = ref.valueAsNumber || +inputValue;
|
36094
|
-
if (!isNullOrUndefined$1(maxOutput.value)) {
|
36095
|
-
exceedMax = valueNumber > maxOutput.value;
|
36096
|
-
}
|
36097
|
-
if (!isNullOrUndefined$1(minOutput.value)) {
|
36098
|
-
exceedMin = valueNumber < minOutput.value;
|
36099
|
-
}
|
36100
|
-
}
|
36101
|
-
else {
|
36102
|
-
const valueDate = ref.valueAsDate || new Date(inputValue);
|
36103
|
-
if (isString(maxOutput.value)) {
|
36104
|
-
exceedMax = valueDate > new Date(maxOutput.value);
|
36105
|
-
}
|
36106
|
-
if (isString(minOutput.value)) {
|
36107
|
-
exceedMin = valueDate < new Date(minOutput.value);
|
36108
|
-
}
|
36109
|
-
}
|
36110
|
-
if (exceedMax || exceedMin) {
|
36111
|
-
getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
|
36112
|
-
if (!validateAllFieldCriteria) {
|
36113
|
-
setCustomValidity(error[name].message);
|
36114
|
-
return error;
|
36115
|
-
}
|
36116
|
-
}
|
36117
|
-
}
|
36118
|
-
if ((maxLength || minLength) && !isEmpty && isString(inputValue)) {
|
36119
|
-
const maxLengthOutput = getValueAndMessage(maxLength);
|
36120
|
-
const minLengthOutput = getValueAndMessage(minLength);
|
36121
|
-
const exceedMax = !isNullOrUndefined$1(maxLengthOutput.value) &&
|
36122
|
-
inputValue.length > maxLengthOutput.value;
|
36123
|
-
const exceedMin = !isNullOrUndefined$1(minLengthOutput.value) &&
|
36124
|
-
inputValue.length < minLengthOutput.value;
|
36125
|
-
if (exceedMax || exceedMin) {
|
36126
|
-
getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
|
36127
|
-
if (!validateAllFieldCriteria) {
|
36128
|
-
setCustomValidity(error[name].message);
|
36129
|
-
return error;
|
36130
|
-
}
|
36131
|
-
}
|
36132
|
-
}
|
36133
|
-
if (pattern && !isEmpty && isString(inputValue)) {
|
36134
|
-
const { value: patternValue, message } = getValueAndMessage(pattern);
|
36135
|
-
if (isRegex(patternValue) && !inputValue.match(patternValue)) {
|
36136
|
-
error[name] = Object.assign({ type: INPUT_VALIDATION_RULES.pattern, message,
|
36137
|
-
ref }, appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message));
|
36138
|
-
if (!validateAllFieldCriteria) {
|
36139
|
-
setCustomValidity(message);
|
36140
|
-
return error;
|
36141
|
-
}
|
36142
|
-
}
|
36143
|
-
}
|
36144
|
-
if (validate) {
|
36145
|
-
if (isFunction$1(validate)) {
|
36146
|
-
const result = await validate(inputValue);
|
36147
|
-
const validateError = getValidateError(result, inputRef);
|
36148
|
-
if (validateError) {
|
36149
|
-
error[name] = Object.assign(Object.assign({}, validateError), appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message));
|
36150
|
-
if (!validateAllFieldCriteria) {
|
36151
|
-
setCustomValidity(validateError.message);
|
36152
|
-
return error;
|
36153
|
-
}
|
36154
|
-
}
|
36155
|
-
}
|
36156
|
-
else if (isObject$3(validate)) {
|
36157
|
-
let validationResult = {};
|
36158
|
-
for (const key in validate) {
|
36159
|
-
if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
|
36160
|
-
break;
|
36161
|
-
}
|
36162
|
-
const validateError = getValidateError(await validate[key](inputValue), inputRef, key);
|
36163
|
-
if (validateError) {
|
36164
|
-
validationResult = Object.assign(Object.assign({}, validateError), appendErrorsCurry(key, validateError.message));
|
36165
|
-
setCustomValidity(validateError.message);
|
36166
|
-
if (validateAllFieldCriteria) {
|
36167
|
-
error[name] = validationResult;
|
36168
|
-
}
|
36169
|
-
}
|
36170
|
-
}
|
36171
|
-
if (!isEmptyObject(validationResult)) {
|
36172
|
-
error[name] = Object.assign({ ref: inputRef }, validationResult);
|
36173
|
-
if (!validateAllFieldCriteria) {
|
36174
|
-
return error;
|
36175
|
-
}
|
36176
|
-
}
|
36177
|
-
}
|
36178
|
-
}
|
36179
|
-
setCustomValidity(true);
|
36180
|
-
return error;
|
36181
|
-
};
|
36182
|
-
|
36183
|
-
const defaultOptions$1 = {
|
36184
|
-
mode: VALIDATION_MODE.onSubmit,
|
36185
|
-
reValidateMode: VALIDATION_MODE.onChange,
|
36186
|
-
shouldFocusError: true,
|
36187
|
-
};
|
36188
|
-
function createFormControl(props = {}) {
|
36189
|
-
let _options = Object.assign(Object.assign({}, defaultOptions$1), props);
|
36190
|
-
let _formState = {
|
36191
|
-
isDirty: false,
|
36192
|
-
isValidating: false,
|
36193
|
-
dirtyFields: {},
|
36194
|
-
isSubmitted: false,
|
36195
|
-
submitCount: 0,
|
36196
|
-
touchedFields: {},
|
36197
|
-
isSubmitting: false,
|
36198
|
-
isSubmitSuccessful: false,
|
36199
|
-
isValid: false,
|
36200
|
-
errors: {},
|
36201
|
-
};
|
36202
|
-
let _fields = {};
|
36203
|
-
let _defaultValues = _options.defaultValues || {};
|
36204
|
-
let _formValues = _options.shouldUnregister
|
36205
|
-
? {}
|
36206
|
-
: cloneObject(_defaultValues);
|
36207
|
-
let _stateFlags = {
|
36208
|
-
action: false,
|
36209
|
-
mount: false,
|
36210
|
-
watch: false,
|
36211
|
-
};
|
36212
|
-
let _names = {
|
36213
|
-
mount: new Set(),
|
36214
|
-
unMount: new Set(),
|
36215
|
-
array: new Set(),
|
36216
|
-
watch: new Set(),
|
36217
|
-
};
|
36218
|
-
let delayErrorCallback;
|
36219
|
-
let timer = 0;
|
36220
|
-
let validateFields = {};
|
36221
|
-
const _proxyFormState = {
|
36222
|
-
isDirty: false,
|
36223
|
-
dirtyFields: false,
|
36224
|
-
touchedFields: false,
|
36225
|
-
isValidating: false,
|
36226
|
-
isValid: false,
|
36227
|
-
errors: false,
|
36228
|
-
};
|
36229
|
-
const _subjects = {
|
36230
|
-
watch: createSubject(),
|
36231
|
-
array: createSubject(),
|
36232
|
-
state: createSubject(),
|
36233
|
-
};
|
36234
|
-
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
36235
|
-
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
36236
|
-
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
36237
|
-
const debounce = (callback, wait) => (...args) => {
|
36238
|
-
clearTimeout(timer);
|
36239
|
-
timer = window.setTimeout(() => callback(...args), wait);
|
36240
|
-
};
|
36241
|
-
const _updateValid = async (shouldSkipRender) => {
|
36242
|
-
let isValid = false;
|
36243
|
-
if (_proxyFormState.isValid) {
|
36244
|
-
isValid = _options.resolver
|
36245
|
-
? isEmptyObject((await _executeSchema()).errors)
|
36246
|
-
: await executeBuildInValidation(_fields, true);
|
36247
|
-
if (!shouldSkipRender && isValid !== _formState.isValid) {
|
36248
|
-
_formState.isValid = isValid;
|
36249
|
-
_subjects.state.next({
|
36250
|
-
isValid,
|
36251
|
-
});
|
36252
|
-
}
|
36253
|
-
}
|
36254
|
-
return isValid;
|
36255
|
-
};
|
36256
|
-
const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
|
36257
|
-
if (args && method) {
|
36258
|
-
_stateFlags.action = true;
|
36259
|
-
if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
|
36260
|
-
const fieldValues = method(get(_fields, name), args.argA, args.argB);
|
36261
|
-
shouldSetValues && set(_fields, name, fieldValues);
|
36262
|
-
}
|
36263
|
-
if (_proxyFormState.errors &&
|
36264
|
-
shouldUpdateFieldsAndState &&
|
36265
|
-
Array.isArray(get(_formState.errors, name))) {
|
36266
|
-
const errors = method(get(_formState.errors, name), args.argA, args.argB);
|
36267
|
-
shouldSetValues && set(_formState.errors, name, errors);
|
36268
|
-
unsetEmptyArray(_formState.errors, name);
|
36269
|
-
}
|
36270
|
-
if (_proxyFormState.touchedFields &&
|
36271
|
-
shouldUpdateFieldsAndState &&
|
36272
|
-
Array.isArray(get(_formState.touchedFields, name))) {
|
36273
|
-
const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
|
36274
|
-
shouldSetValues && set(_formState.touchedFields, name, touchedFields);
|
36275
|
-
}
|
36276
|
-
if (_proxyFormState.dirtyFields) {
|
36277
|
-
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
36278
|
-
}
|
36279
|
-
_subjects.state.next({
|
36280
|
-
isDirty: _getDirty(name, values),
|
36281
|
-
dirtyFields: _formState.dirtyFields,
|
36282
|
-
errors: _formState.errors,
|
36283
|
-
isValid: _formState.isValid,
|
36284
|
-
});
|
36285
|
-
}
|
36286
|
-
else {
|
36287
|
-
set(_formValues, name, values);
|
36288
|
-
}
|
36289
|
-
};
|
36290
|
-
const updateErrors = (name, error) => (set(_formState.errors, name, error),
|
36291
|
-
_subjects.state.next({
|
36292
|
-
errors: _formState.errors,
|
36293
|
-
}));
|
36294
|
-
const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
|
36295
|
-
const field = get(_fields, name);
|
36296
|
-
if (field) {
|
36297
|
-
const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
|
36298
|
-
isUndefined(defaultValue) ||
|
36299
|
-
(ref && ref.defaultChecked) ||
|
36300
|
-
shouldSkipSetValueAs
|
36301
|
-
? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
|
36302
|
-
: setFieldValue(name, defaultValue);
|
36303
|
-
_stateFlags.mount && _updateValid();
|
36304
|
-
}
|
36305
|
-
};
|
36306
|
-
const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
|
36307
|
-
let isFieldDirty = false;
|
36308
|
-
const output = {
|
36309
|
-
name,
|
36310
|
-
};
|
36311
|
-
const isPreviousFieldTouched = get(_formState.touchedFields, name);
|
36312
|
-
if (_proxyFormState.isDirty) {
|
36313
|
-
const isPreviousFormDirty = _formState.isDirty;
|
36314
|
-
_formState.isDirty = output.isDirty = _getDirty();
|
36315
|
-
isFieldDirty = isPreviousFormDirty !== output.isDirty;
|
36316
|
-
}
|
36317
|
-
if (_proxyFormState.dirtyFields && (!isBlurEvent || shouldDirty)) {
|
36318
|
-
const isPreviousFieldDirty = get(_formState.dirtyFields, name);
|
36319
|
-
const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
|
36320
|
-
isCurrentFieldPristine
|
36321
|
-
? unset(_formState.dirtyFields, name)
|
36322
|
-
: set(_formState.dirtyFields, name, true);
|
36323
|
-
output.dirtyFields = _formState.dirtyFields;
|
36324
|
-
isFieldDirty =
|
36325
|
-
isFieldDirty ||
|
36326
|
-
isPreviousFieldDirty !== get(_formState.dirtyFields, name);
|
36327
|
-
}
|
36328
|
-
if (isBlurEvent && !isPreviousFieldTouched) {
|
36329
|
-
set(_formState.touchedFields, name, isBlurEvent);
|
36330
|
-
output.touchedFields = _formState.touchedFields;
|
36331
|
-
isFieldDirty =
|
36332
|
-
isFieldDirty ||
|
36333
|
-
(_proxyFormState.touchedFields &&
|
36334
|
-
isPreviousFieldTouched !== isBlurEvent);
|
36335
|
-
}
|
36336
|
-
isFieldDirty && shouldRender && _subjects.state.next(output);
|
36337
|
-
return isFieldDirty ? output : {};
|
36338
|
-
};
|
36339
|
-
const shouldRenderByError = async (shouldSkipRender, name, isValid, error, fieldState) => {
|
36340
|
-
const previousFieldError = get(_formState.errors, name);
|
36341
|
-
const shouldUpdateValid = _proxyFormState.isValid && _formState.isValid !== isValid;
|
36342
|
-
if (props.delayError && error) {
|
36343
|
-
delayErrorCallback =
|
36344
|
-
delayErrorCallback || debounce(updateErrors, props.delayError);
|
36345
|
-
delayErrorCallback(name, error);
|
36346
|
-
}
|
36347
|
-
else {
|
36348
|
-
clearTimeout(timer);
|
36349
|
-
error
|
36350
|
-
? set(_formState.errors, name, error)
|
36351
|
-
: unset(_formState.errors, name);
|
36352
|
-
}
|
36353
|
-
if (((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
|
36354
|
-
!isEmptyObject(fieldState) ||
|
36355
|
-
shouldUpdateValid) &&
|
36356
|
-
!shouldSkipRender) {
|
36357
|
-
const updatedFormState = Object.assign(Object.assign(Object.assign({}, fieldState), (shouldUpdateValid ? { isValid } : {})), { errors: _formState.errors, name });
|
36358
|
-
_formState = Object.assign(Object.assign({}, _formState), updatedFormState);
|
36359
|
-
_subjects.state.next(updatedFormState);
|
36360
|
-
}
|
36361
|
-
validateFields[name]--;
|
36362
|
-
if (_proxyFormState.isValidating &&
|
36363
|
-
!Object.values(validateFields).some((v) => v)) {
|
36364
|
-
_subjects.state.next({
|
36365
|
-
isValidating: false,
|
36366
|
-
});
|
36367
|
-
validateFields = {};
|
36368
|
-
}
|
36369
|
-
};
|
36370
|
-
const _executeSchema = async (name) => _options.resolver
|
36371
|
-
? await _options.resolver(Object.assign({}, _formValues), _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
|
36372
|
-
: {};
|
36373
|
-
const executeSchemaAndUpdateState = async (names) => {
|
36374
|
-
const { errors } = await _executeSchema();
|
36375
|
-
if (names) {
|
36376
|
-
for (const name of names) {
|
36377
|
-
const error = get(errors, name);
|
36378
|
-
error
|
36379
|
-
? set(_formState.errors, name, error)
|
36380
|
-
: unset(_formState.errors, name);
|
36381
|
-
}
|
36382
|
-
}
|
36383
|
-
else {
|
36384
|
-
_formState.errors = errors;
|
36385
|
-
}
|
36386
|
-
return errors;
|
36387
|
-
};
|
36388
|
-
const executeBuildInValidation = async (fields, shouldOnlyCheckValid, context = {
|
36389
|
-
valid: true,
|
36390
|
-
}) => {
|
36391
|
-
for (const name in fields) {
|
36392
|
-
const field = fields[name];
|
36393
|
-
if (field) {
|
36394
|
-
const fieldReference = field._f;
|
36395
|
-
const fieldValue = omit(field, '_f');
|
36396
|
-
if (fieldReference) {
|
36397
|
-
const fieldError = await validateField(field, get(_formValues, fieldReference.name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation);
|
36398
|
-
if (fieldError[fieldReference.name]) {
|
36399
|
-
context.valid = false;
|
36400
|
-
if (shouldOnlyCheckValid) {
|
36401
|
-
break;
|
36402
|
-
}
|
36403
|
-
}
|
36404
|
-
if (!shouldOnlyCheckValid) {
|
36405
|
-
fieldError[fieldReference.name]
|
36406
|
-
? set(_formState.errors, fieldReference.name, fieldError[fieldReference.name])
|
36407
|
-
: unset(_formState.errors, fieldReference.name);
|
36408
|
-
}
|
36409
|
-
}
|
36410
|
-
fieldValue &&
|
36411
|
-
(await executeBuildInValidation(fieldValue, shouldOnlyCheckValid, context));
|
36412
|
-
}
|
36413
|
-
}
|
36414
|
-
return context.valid;
|
36415
|
-
};
|
36416
|
-
const _removeUnmounted = () => {
|
36417
|
-
for (const name of _names.unMount) {
|
36418
|
-
const field = get(_fields, name);
|
36419
|
-
field &&
|
36420
|
-
(field._f.refs
|
36421
|
-
? field._f.refs.every((ref) => !live(ref))
|
36422
|
-
: !live(field._f.ref)) &&
|
36423
|
-
unregister(name);
|
36424
|
-
}
|
36425
|
-
_names.unMount = new Set();
|
36426
|
-
};
|
36427
|
-
const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
|
36428
|
-
!deepEqual(getValues(), _defaultValues));
|
36429
|
-
const _getWatch = (names, defaultValue, isGlobal) => {
|
36430
|
-
const fieldValues = Object.assign({}, (_stateFlags.mount
|
36431
|
-
? _formValues
|
36432
|
-
: isUndefined(defaultValue)
|
36433
|
-
? _defaultValues
|
36434
|
-
: isString(names)
|
36435
|
-
? { [names]: defaultValue }
|
36436
|
-
: defaultValue));
|
36437
|
-
return generateWatchOutput(names, _names, fieldValues, isGlobal);
|
36438
|
-
};
|
36439
|
-
const _getFieldArray = (name) => compact$1(get(_stateFlags.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
|
36440
|
-
const setFieldValue = (name, value, options = {}) => {
|
36441
|
-
const field = get(_fields, name);
|
36442
|
-
let fieldValue = value;
|
36443
|
-
if (field) {
|
36444
|
-
const fieldReference = field._f;
|
36445
|
-
if (fieldReference) {
|
36446
|
-
!fieldReference.disabled &&
|
36447
|
-
set(_formValues, name, getFieldValueAs(value, fieldReference));
|
36448
|
-
fieldValue =
|
36449
|
-
isWeb && isHTMLElement(fieldReference.ref) && isNullOrUndefined$1(value)
|
36450
|
-
? ''
|
36451
|
-
: value;
|
36452
|
-
if (isMultipleSelect(fieldReference.ref)) {
|
36453
|
-
[...fieldReference.ref.options].forEach((selectRef) => (selectRef.selected = fieldValue.includes(selectRef.value)));
|
36454
|
-
}
|
36455
|
-
else if (fieldReference.refs) {
|
36456
|
-
if (isCheckBoxInput(fieldReference.ref)) {
|
36457
|
-
fieldReference.refs.length > 1
|
36458
|
-
? fieldReference.refs.forEach((checkboxRef) => !checkboxRef.disabled &&
|
36459
|
-
(checkboxRef.checked = Array.isArray(fieldValue)
|
36460
|
-
? !!fieldValue.find((data) => data === checkboxRef.value)
|
36461
|
-
: fieldValue === checkboxRef.value))
|
36462
|
-
: fieldReference.refs[0] &&
|
36463
|
-
(fieldReference.refs[0].checked = !!fieldValue);
|
36464
|
-
}
|
36465
|
-
else {
|
36466
|
-
fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
|
36467
|
-
}
|
36468
|
-
}
|
36469
|
-
else if (isFileInput(fieldReference.ref)) {
|
36470
|
-
fieldReference.ref.value = '';
|
36471
|
-
}
|
36472
|
-
else {
|
36473
|
-
fieldReference.ref.value = fieldValue;
|
36474
|
-
if (!fieldReference.ref.type) {
|
36475
|
-
_subjects.watch.next({
|
36476
|
-
name,
|
36477
|
-
});
|
36478
|
-
}
|
36479
|
-
}
|
36480
|
-
}
|
36481
|
-
}
|
36482
|
-
(options.shouldDirty || options.shouldTouch) &&
|
36483
|
-
updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
|
36484
|
-
options.shouldValidate && trigger(name);
|
36485
|
-
};
|
36486
|
-
const setValues = (name, value, options) => {
|
36487
|
-
for (const fieldKey in value) {
|
36488
|
-
const fieldValue = value[fieldKey];
|
36489
|
-
const fieldName = `${name}.${fieldKey}`;
|
36490
|
-
const field = get(_fields, fieldName);
|
36491
|
-
(_names.array.has(name) ||
|
36492
|
-
!isPrimitive(fieldValue) ||
|
36493
|
-
(field && !field._f)) &&
|
36494
|
-
!isDateObject(fieldValue)
|
36495
|
-
? setValues(fieldName, fieldValue, options)
|
36496
|
-
: setFieldValue(fieldName, fieldValue, options);
|
36497
|
-
}
|
36498
|
-
};
|
36499
|
-
const setValue = (name, value, options = {}) => {
|
36500
|
-
const field = get(_fields, name);
|
36501
|
-
const isFieldArray = _names.array.has(name);
|
36502
|
-
const cloneValue = cloneObject(value);
|
36503
|
-
set(_formValues, name, cloneValue);
|
36504
|
-
if (isFieldArray) {
|
36505
|
-
_subjects.array.next({
|
36506
|
-
name,
|
36507
|
-
values: _formValues,
|
36508
|
-
});
|
36509
|
-
if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
|
36510
|
-
options.shouldDirty) {
|
36511
|
-
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
36512
|
-
_subjects.state.next({
|
36513
|
-
name,
|
36514
|
-
dirtyFields: _formState.dirtyFields,
|
36515
|
-
isDirty: _getDirty(name, cloneValue),
|
36516
|
-
});
|
36517
|
-
}
|
36518
|
-
}
|
36519
|
-
else {
|
36520
|
-
field && !field._f && !isNullOrUndefined$1(cloneValue)
|
36521
|
-
? setValues(name, cloneValue, options)
|
36522
|
-
: setFieldValue(name, cloneValue, options);
|
36523
|
-
}
|
36524
|
-
isWatched(name, _names) && _subjects.state.next({});
|
36525
|
-
_subjects.watch.next({
|
36526
|
-
name,
|
36527
|
-
});
|
36528
|
-
};
|
36529
|
-
const onChange = async (event) => {
|
36530
|
-
const target = event.target;
|
36531
|
-
let name = target.name;
|
36532
|
-
const field = get(_fields, name);
|
36533
|
-
if (field) {
|
36534
|
-
let error;
|
36535
|
-
let isValid;
|
36536
|
-
const fieldValue = target.type
|
36537
|
-
? getFieldValue(field._f)
|
36538
|
-
: getEventValue(event);
|
36539
|
-
const isBlurEvent = event.type === EVENTS$1.BLUR || event.type === EVENTS$1.FOCUS_OUT;
|
36540
|
-
const shouldSkipValidation = (!hasValidation(field._f) &&
|
36541
|
-
!_options.resolver &&
|
36542
|
-
!get(_formState.errors, name) &&
|
36543
|
-
!field._f.deps) ||
|
36544
|
-
skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
|
36545
|
-
const watched = isWatched(name, _names, isBlurEvent);
|
36546
|
-
set(_formValues, name, fieldValue);
|
36547
|
-
if (isBlurEvent) {
|
36548
|
-
field._f.onBlur && field._f.onBlur(event);
|
36549
|
-
}
|
36550
|
-
else if (field._f.onChange) {
|
36551
|
-
field._f.onChange(event);
|
36552
|
-
}
|
36553
|
-
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
|
36554
|
-
const shouldRender = !isEmptyObject(fieldState) || watched;
|
36555
|
-
!isBlurEvent &&
|
36556
|
-
_subjects.watch.next({
|
36557
|
-
name,
|
36558
|
-
type: event.type,
|
36559
|
-
});
|
36560
|
-
if (shouldSkipValidation) {
|
36561
|
-
return (shouldRender &&
|
36562
|
-
_subjects.state.next(Object.assign({ name }, (watched ? {} : fieldState))));
|
36563
|
-
}
|
36564
|
-
!isBlurEvent && watched && _subjects.state.next({});
|
36565
|
-
validateFields[name] = validateFields[name] ? +1 : 1;
|
36566
|
-
_subjects.state.next({
|
36567
|
-
isValidating: true,
|
36568
|
-
});
|
36569
|
-
if (_options.resolver) {
|
36570
|
-
const { errors } = await _executeSchema([name]);
|
36571
|
-
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
36572
|
-
const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
|
36573
|
-
error = errorLookupResult.error;
|
36574
|
-
name = errorLookupResult.name;
|
36575
|
-
isValid = isEmptyObject(errors);
|
36576
|
-
}
|
36577
|
-
else {
|
36578
|
-
error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
36579
|
-
isValid = await _updateValid(true);
|
36580
|
-
}
|
36581
|
-
field._f.deps &&
|
36582
|
-
trigger(field._f.deps);
|
36583
|
-
shouldRenderByError(false, name, isValid, error, fieldState);
|
36584
|
-
}
|
36585
|
-
};
|
36586
|
-
const trigger = async (name, options = {}) => {
|
36587
|
-
let isValid;
|
36588
|
-
let validationResult;
|
36589
|
-
const fieldNames = convertToArrayPayload(name);
|
36590
|
-
_subjects.state.next({
|
36591
|
-
isValidating: true,
|
36592
|
-
});
|
36593
|
-
if (_options.resolver) {
|
36594
|
-
const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
|
36595
|
-
isValid = isEmptyObject(errors);
|
36596
|
-
validationResult = name
|
36597
|
-
? !fieldNames.some((name) => get(errors, name))
|
36598
|
-
: isValid;
|
36599
|
-
}
|
36600
|
-
else if (name) {
|
36601
|
-
validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
|
36602
|
-
const field = get(_fields, fieldName);
|
36603
|
-
return await executeBuildInValidation(field && field._f ? { [fieldName]: field } : field);
|
36604
|
-
}))).every(Boolean);
|
36605
|
-
!(!validationResult && !_formState.isValid) && _updateValid();
|
36606
|
-
}
|
36607
|
-
else {
|
36608
|
-
validationResult = isValid = await executeBuildInValidation(_fields);
|
36609
|
-
}
|
36610
|
-
_subjects.state.next(Object.assign(Object.assign(Object.assign({}, (!isString(name) ||
|
36611
|
-
(_proxyFormState.isValid && isValid !== _formState.isValid)
|
36612
|
-
? {}
|
36613
|
-
: { name })), (_options.resolver ? { isValid } : {})), { errors: _formState.errors, isValidating: false }));
|
36614
|
-
options.shouldFocus &&
|
36615
|
-
!validationResult &&
|
36616
|
-
focusFieldBy(_fields, (key) => get(_formState.errors, key), name ? fieldNames : _names.mount);
|
36617
|
-
return validationResult;
|
36618
|
-
};
|
36619
|
-
const getValues = (fieldNames) => {
|
36620
|
-
const values = Object.assign(Object.assign({}, _defaultValues), (_stateFlags.mount ? _formValues : {}));
|
36621
|
-
return isUndefined(fieldNames)
|
36622
|
-
? values
|
36623
|
-
: isString(fieldNames)
|
36624
|
-
? get(values, fieldNames)
|
36625
|
-
: fieldNames.map((name) => get(values, name));
|
36626
|
-
};
|
36627
|
-
const getFieldState = (name, formState) => ({
|
36628
|
-
invalid: !!get((formState || _formState).errors, name),
|
36629
|
-
isDirty: !!get((formState || _formState).dirtyFields, name),
|
36630
|
-
isTouched: !!get((formState || _formState).touchedFields, name),
|
36631
|
-
error: get((formState || _formState).errors, name),
|
36632
|
-
});
|
36633
|
-
const clearErrors = (name) => {
|
36634
|
-
name
|
36635
|
-
? convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName))
|
36636
|
-
: (_formState.errors = {});
|
36637
|
-
_subjects.state.next({
|
36638
|
-
errors: _formState.errors,
|
36639
|
-
});
|
36640
|
-
};
|
36641
|
-
const setError = (name, error, options) => {
|
36642
|
-
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
36643
|
-
set(_formState.errors, name, Object.assign(Object.assign({}, error), { ref }));
|
36644
|
-
_subjects.state.next({
|
36645
|
-
name,
|
36646
|
-
errors: _formState.errors,
|
36647
|
-
isValid: false,
|
36648
|
-
});
|
36649
|
-
options && options.shouldFocus && ref && ref.focus && ref.focus();
|
36650
|
-
};
|
36651
|
-
const watch = (name, defaultValue) => isFunction$1(name)
|
36652
|
-
? _subjects.watch.subscribe({
|
36653
|
-
next: (info) => name(_getWatch(undefined, defaultValue), info),
|
36654
|
-
})
|
36655
|
-
: _getWatch(name, defaultValue, true);
|
36656
|
-
const unregister = (name, options = {}) => {
|
36657
|
-
for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
|
36658
|
-
_names.mount.delete(fieldName);
|
36659
|
-
_names.array.delete(fieldName);
|
36660
|
-
if (get(_fields, fieldName)) {
|
36661
|
-
if (!options.keepValue) {
|
36662
|
-
unset(_fields, fieldName);
|
36663
|
-
unset(_formValues, fieldName);
|
36664
|
-
}
|
36665
|
-
!options.keepError && unset(_formState.errors, fieldName);
|
36666
|
-
!options.keepDirty && unset(_formState.dirtyFields, fieldName);
|
36667
|
-
!options.keepTouched && unset(_formState.touchedFields, fieldName);
|
36668
|
-
!_options.shouldUnregister &&
|
36669
|
-
!options.keepDefaultValue &&
|
36670
|
-
unset(_defaultValues, fieldName);
|
36671
|
-
}
|
36672
|
-
}
|
36673
|
-
_subjects.watch.next({});
|
36674
|
-
_subjects.state.next(Object.assign(Object.assign({}, _formState), (!options.keepDirty ? {} : { isDirty: _getDirty() })));
|
36675
|
-
!options.keepIsValid && _updateValid();
|
36676
|
-
};
|
36677
|
-
const register = (name, options = {}) => {
|
36678
|
-
let field = get(_fields, name);
|
36679
|
-
const disabledIsDefined = isBoolean(options.disabled);
|
36680
|
-
set(_fields, name, {
|
36681
|
-
_f: Object.assign(Object.assign(Object.assign({}, (field && field._f ? field._f : { ref: { name } })), { name, mount: true }), options),
|
36682
|
-
});
|
36683
|
-
_names.mount.add(name);
|
36684
|
-
field
|
36685
|
-
? disabledIsDefined &&
|
36686
|
-
set(_formValues, name, options.disabled
|
36687
|
-
? undefined
|
36688
|
-
: get(_formValues, name, getFieldValue(field._f)))
|
36689
|
-
: updateValidAndValue(name, true, options.value);
|
36690
|
-
return Object.assign(Object.assign(Object.assign({}, (disabledIsDefined ? { disabled: options.disabled } : {})), (_options.shouldUseNativeValidation
|
36691
|
-
? {
|
36692
|
-
required: !!options.required,
|
36693
|
-
min: getRuleValue(options.min),
|
36694
|
-
max: getRuleValue(options.max),
|
36695
|
-
minLength: getRuleValue(options.minLength),
|
36696
|
-
maxLength: getRuleValue(options.maxLength),
|
36697
|
-
pattern: getRuleValue(options.pattern),
|
36698
|
-
}
|
36699
|
-
: {})), { name,
|
36700
|
-
onChange, onBlur: onChange, ref: (ref) => {
|
36701
|
-
if (ref) {
|
36702
|
-
register(name, options);
|
36703
|
-
field = get(_fields, name);
|
36704
|
-
const fieldRef = isUndefined(ref.value)
|
36705
|
-
? ref.querySelectorAll
|
36706
|
-
? ref.querySelectorAll('input,select,textarea')[0] || ref
|
36707
|
-
: ref
|
36708
|
-
: ref;
|
36709
|
-
const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
|
36710
|
-
const refs = field._f.refs || [];
|
36711
|
-
if (radioOrCheckbox
|
36712
|
-
? refs.find((option) => option === fieldRef)
|
36713
|
-
: fieldRef === field._f.ref) {
|
36714
|
-
return;
|
36715
|
-
}
|
36716
|
-
set(_fields, name, {
|
36717
|
-
_f: Object.assign(Object.assign({}, field._f), (radioOrCheckbox
|
36718
|
-
? {
|
36719
|
-
refs: [...refs.filter(live), fieldRef],
|
36720
|
-
ref: { type: fieldRef.type, name },
|
36721
|
-
}
|
36722
|
-
: { ref: fieldRef })),
|
36723
|
-
});
|
36724
|
-
updateValidAndValue(name, false, undefined, fieldRef);
|
36725
|
-
}
|
36726
|
-
else {
|
36727
|
-
field = get(_fields, name, {});
|
36728
|
-
if (field._f) {
|
36729
|
-
field._f.mount = false;
|
36730
|
-
}
|
36731
|
-
(_options.shouldUnregister || options.shouldUnregister) &&
|
36732
|
-
!(isNameInFieldArray(_names.array, name) && _stateFlags.action) &&
|
36733
|
-
_names.unMount.add(name);
|
36734
|
-
}
|
36735
|
-
} });
|
36736
|
-
};
|
36737
|
-
const handleSubmit = (onValid, onInvalid) => async (e) => {
|
36738
|
-
if (e) {
|
36739
|
-
e.preventDefault && e.preventDefault();
|
36740
|
-
e.persist && e.persist();
|
36741
|
-
}
|
36742
|
-
let hasNoPromiseError = true;
|
36743
|
-
let fieldValues = cloneObject(_formValues);
|
36744
|
-
_subjects.state.next({
|
36745
|
-
isSubmitting: true,
|
36746
|
-
});
|
36747
|
-
try {
|
36748
|
-
if (_options.resolver) {
|
36749
|
-
const { errors, values } = await _executeSchema();
|
36750
|
-
_formState.errors = errors;
|
36751
|
-
fieldValues = values;
|
36752
|
-
}
|
36753
|
-
else {
|
36754
|
-
await executeBuildInValidation(_fields);
|
36755
|
-
}
|
36756
|
-
if (isEmptyObject(_formState.errors) &&
|
36757
|
-
Object.keys(_formState.errors).every((name) => get(fieldValues, name))) {
|
36758
|
-
_subjects.state.next({
|
36759
|
-
errors: {},
|
36760
|
-
isSubmitting: true,
|
36761
|
-
});
|
36762
|
-
await onValid(fieldValues, e);
|
36763
|
-
}
|
36764
|
-
else {
|
36765
|
-
if (onInvalid) {
|
36766
|
-
await onInvalid(Object.assign({}, _formState.errors), e);
|
36767
|
-
}
|
36768
|
-
_options.shouldFocusError &&
|
36769
|
-
focusFieldBy(_fields, (key) => get(_formState.errors, key), _names.mount);
|
36770
|
-
}
|
36771
|
-
}
|
36772
|
-
catch (err) {
|
36773
|
-
hasNoPromiseError = false;
|
36774
|
-
throw err;
|
36775
|
-
}
|
36776
|
-
finally {
|
36777
|
-
_formState.isSubmitted = true;
|
36778
|
-
_subjects.state.next({
|
36779
|
-
isSubmitted: true,
|
36780
|
-
isSubmitting: false,
|
36781
|
-
isSubmitSuccessful: isEmptyObject(_formState.errors) && hasNoPromiseError,
|
36782
|
-
submitCount: _formState.submitCount + 1,
|
36783
|
-
errors: _formState.errors,
|
36784
|
-
});
|
36785
|
-
}
|
36786
|
-
};
|
36787
|
-
const resetField = (name, options = {}) => {
|
36788
|
-
if (get(_fields, name)) {
|
36789
|
-
if (isUndefined(options.defaultValue)) {
|
36790
|
-
setValue(name, get(_defaultValues, name));
|
36791
|
-
}
|
36792
|
-
else {
|
36793
|
-
setValue(name, options.defaultValue);
|
36794
|
-
set(_defaultValues, name, options.defaultValue);
|
36795
|
-
}
|
36796
|
-
if (!options.keepTouched) {
|
36797
|
-
unset(_formState.touchedFields, name);
|
36798
|
-
}
|
36799
|
-
if (!options.keepDirty) {
|
36800
|
-
unset(_formState.dirtyFields, name);
|
36801
|
-
_formState.isDirty = options.defaultValue
|
36802
|
-
? _getDirty(name, get(_defaultValues, name))
|
36803
|
-
: _getDirty();
|
36804
|
-
}
|
36805
|
-
if (!options.keepError) {
|
36806
|
-
unset(_formState.errors, name);
|
36807
|
-
_proxyFormState.isValid && _updateValid();
|
36808
|
-
}
|
36809
|
-
_subjects.state.next(Object.assign({}, _formState));
|
36810
|
-
}
|
36811
|
-
};
|
36812
|
-
const reset = (formValues, keepStateOptions = {}) => {
|
36813
|
-
const updatedValues = formValues || _defaultValues;
|
36814
|
-
const cloneUpdatedValues = cloneObject(updatedValues);
|
36815
|
-
const values = formValues && !isEmptyObject(formValues)
|
36816
|
-
? cloneUpdatedValues
|
36817
|
-
: _defaultValues;
|
36818
|
-
if (!keepStateOptions.keepDefaultValues) {
|
36819
|
-
_defaultValues = updatedValues;
|
36820
|
-
}
|
36821
|
-
if (!keepStateOptions.keepValues) {
|
36822
|
-
if (isWeb && isUndefined(formValues)) {
|
36823
|
-
for (const name of _names.mount) {
|
36824
|
-
const field = get(_fields, name);
|
36825
|
-
if (field && field._f) {
|
36826
|
-
const fieldReference = Array.isArray(field._f.refs)
|
36827
|
-
? field._f.refs[0]
|
36828
|
-
: field._f.ref;
|
36829
|
-
try {
|
36830
|
-
isHTMLElement(fieldReference) &&
|
36831
|
-
fieldReference.closest('form').reset();
|
36832
|
-
break;
|
36833
|
-
}
|
36834
|
-
catch (_a) { }
|
36835
|
-
}
|
36836
|
-
}
|
36837
|
-
}
|
36838
|
-
_formValues = props.shouldUnregister
|
36839
|
-
? keepStateOptions.keepDefaultValues
|
36840
|
-
? cloneObject(_defaultValues)
|
36841
|
-
: {}
|
36842
|
-
: cloneUpdatedValues;
|
36843
|
-
_fields = {};
|
36844
|
-
_subjects.array.next({
|
36845
|
-
values,
|
36846
|
-
});
|
36847
|
-
_subjects.watch.next({
|
36848
|
-
values,
|
36849
|
-
});
|
36850
|
-
}
|
36851
|
-
_names = {
|
36852
|
-
mount: new Set(),
|
36853
|
-
unMount: new Set(),
|
36854
|
-
array: new Set(),
|
36855
|
-
watch: new Set(),
|
36856
|
-
watchAll: false,
|
36857
|
-
focus: '',
|
36858
|
-
};
|
36859
|
-
_stateFlags.mount =
|
36860
|
-
!_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
|
36861
|
-
_stateFlags.watch = !!props.shouldUnregister;
|
36862
|
-
_subjects.state.next({
|
36863
|
-
submitCount: keepStateOptions.keepSubmitCount
|
36864
|
-
? _formState.submitCount
|
36865
|
-
: 0,
|
36866
|
-
isDirty: keepStateOptions.keepDirty
|
36867
|
-
? _formState.isDirty
|
36868
|
-
: keepStateOptions.keepDefaultValues
|
36869
|
-
? !deepEqual(formValues, _defaultValues)
|
36870
|
-
: false,
|
36871
|
-
isSubmitted: keepStateOptions.keepIsSubmitted
|
36872
|
-
? _formState.isSubmitted
|
36873
|
-
: false,
|
36874
|
-
dirtyFields: keepStateOptions.keepDirty
|
36875
|
-
? _formState.dirtyFields
|
36876
|
-
: (keepStateOptions.keepDefaultValues && formValues
|
36877
|
-
? Object.entries(formValues).reduce((previous, [key, value]) => (Object.assign(Object.assign({}, previous), { [key]: value !== get(_defaultValues, key) })), {})
|
36878
|
-
: {}),
|
36879
|
-
touchedFields: keepStateOptions.keepTouched
|
36880
|
-
? _formState.touchedFields
|
36881
|
-
: {},
|
36882
|
-
errors: keepStateOptions.keepErrors
|
36883
|
-
? _formState.errors
|
36884
|
-
: {},
|
36885
|
-
isSubmitting: false,
|
36886
|
-
isSubmitSuccessful: false,
|
36887
|
-
});
|
36888
|
-
};
|
36889
|
-
const setFocus = (name, options = {}) => {
|
36890
|
-
const field = get(_fields, name)._f;
|
36891
|
-
const fieldRef = field.refs ? field.refs[0] : field.ref;
|
36892
|
-
options.shouldSelect ? fieldRef.select() : fieldRef.focus();
|
36893
|
-
};
|
36894
|
-
return {
|
36895
|
-
control: {
|
36896
|
-
register,
|
36897
|
-
unregister,
|
36898
|
-
getFieldState,
|
36899
|
-
_executeSchema,
|
36900
|
-
_getWatch,
|
36901
|
-
_getDirty,
|
36902
|
-
_updateValid,
|
36903
|
-
_removeUnmounted,
|
36904
|
-
_updateFieldArray,
|
36905
|
-
_getFieldArray,
|
36906
|
-
_subjects,
|
36907
|
-
_proxyFormState,
|
36908
|
-
get _fields() {
|
36909
|
-
return _fields;
|
36910
|
-
},
|
36911
|
-
get _formValues() {
|
36912
|
-
return _formValues;
|
36913
|
-
},
|
36914
|
-
get _stateFlags() {
|
36915
|
-
return _stateFlags;
|
36916
|
-
},
|
36917
|
-
set _stateFlags(value) {
|
36918
|
-
_stateFlags = value;
|
36919
|
-
},
|
36920
|
-
get _defaultValues() {
|
36921
|
-
return _defaultValues;
|
36922
|
-
},
|
36923
|
-
get _names() {
|
36924
|
-
return _names;
|
36925
|
-
},
|
36926
|
-
set _names(value) {
|
36927
|
-
_names = value;
|
36928
|
-
},
|
36929
|
-
get _formState() {
|
36930
|
-
return _formState;
|
36931
|
-
},
|
36932
|
-
set _formState(value) {
|
36933
|
-
_formState = value;
|
36934
|
-
},
|
36935
|
-
get _options() {
|
36936
|
-
return _options;
|
36937
|
-
},
|
36938
|
-
set _options(value) {
|
36939
|
-
_options = Object.assign(Object.assign({}, _options), value);
|
36940
|
-
},
|
36941
|
-
},
|
36942
|
-
trigger,
|
36943
|
-
register,
|
36944
|
-
handleSubmit,
|
36945
|
-
watch,
|
36946
|
-
setValue,
|
36947
|
-
getValues,
|
36948
|
-
reset,
|
36949
|
-
resetField,
|
36950
|
-
clearErrors,
|
36951
|
-
unregister,
|
36952
|
-
setError,
|
36953
|
-
setFocus,
|
36954
|
-
getFieldState,
|
36955
|
-
};
|
36956
|
-
}
|
36957
|
-
|
36958
|
-
/**
|
36959
|
-
* Custom hook to mange the entire form.
|
36960
|
-
*
|
36961
|
-
* @remarks
|
36962
|
-
* [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)
|
36963
|
-
*
|
36964
|
-
* @param props - form configuration and validation parameters.
|
36965
|
-
*
|
36966
|
-
* @returns methods - individual functions to manage the form state. {@link UseFormReturn}
|
36967
|
-
*
|
36968
|
-
* @example
|
36969
|
-
* ```tsx
|
36970
|
-
* function App() {
|
36971
|
-
* const { register, handleSubmit, watch, formState: { errors } } = useForm();
|
36972
|
-
* const onSubmit = data => console.log(data);
|
36973
|
-
*
|
36974
|
-
* console.log(watch("example"));
|
36975
|
-
*
|
36976
|
-
* return (
|
36977
|
-
* <form onSubmit={handleSubmit(onSubmit)}>
|
36978
|
-
* <input defaultValue="test" {...register("example")} />
|
36979
|
-
* <input {...register("exampleRequired", { required: true })} />
|
36980
|
-
* {errors.exampleRequired && <span>This field is required</span>}
|
36981
|
-
* <input type="submit" />
|
36982
|
-
* </form>
|
36983
|
-
* );
|
36984
|
-
* }
|
36985
|
-
* ```
|
36986
|
-
*/
|
36987
|
-
function useForm(props = {}) {
|
36988
|
-
const _formControl = React__default.useRef();
|
36989
|
-
const [formState, updateFormState] = React__default.useState({
|
36990
|
-
isDirty: false,
|
36991
|
-
isValidating: false,
|
36992
|
-
dirtyFields: {},
|
36993
|
-
isSubmitted: false,
|
36994
|
-
submitCount: 0,
|
36995
|
-
touchedFields: {},
|
36996
|
-
isSubmitting: false,
|
36997
|
-
isSubmitSuccessful: false,
|
36998
|
-
isValid: false,
|
36999
|
-
errors: {},
|
37000
|
-
});
|
37001
|
-
if (_formControl.current) {
|
37002
|
-
_formControl.current.control._options = props;
|
37003
|
-
}
|
37004
|
-
else {
|
37005
|
-
_formControl.current = Object.assign(Object.assign({}, createFormControl(props)), { formState });
|
37006
|
-
}
|
37007
|
-
const control = _formControl.current.control;
|
37008
|
-
const callback = React__default.useCallback((value) => {
|
37009
|
-
if (shouldRenderFormState(value, control._proxyFormState)) {
|
37010
|
-
control._formState = Object.assign(Object.assign({}, control._formState), value);
|
37011
|
-
updateFormState(Object.assign({}, control._formState));
|
37012
|
-
}
|
37013
|
-
}, [control]);
|
37014
|
-
useSubscribe({
|
37015
|
-
subject: control._subjects.state,
|
37016
|
-
callback,
|
37017
|
-
});
|
37018
|
-
React__default.useEffect(() => {
|
37019
|
-
if (!control._stateFlags.mount) {
|
37020
|
-
control._proxyFormState.isValid && control._updateValid();
|
37021
|
-
control._stateFlags.mount = true;
|
37022
|
-
}
|
37023
|
-
if (control._stateFlags.watch) {
|
37024
|
-
control._stateFlags.watch = false;
|
37025
|
-
control._subjects.state.next({});
|
37026
|
-
}
|
37027
|
-
control._removeUnmounted();
|
37028
|
-
});
|
37029
|
-
_formControl.current.formState = getProxyFormState(formState, control._proxyFormState);
|
37030
|
-
return _formControl.current;
|
37031
|
-
}
|
37032
|
-
|
37033
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) {
|
37034
35367
|
var theme = _a.theme;
|
37035
35368
|
return theme.ui_cpnt_button_tooltip_base;
|