tp-react-elements-dev 0.2.0 → 0.3.0

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.js CHANGED
@@ -4955,6 +4955,41 @@ if (process.env.NODE_ENV !== 'production') {
4955
4955
  ThemeContext$1.displayName = 'EmotionThemeContext';
4956
4956
  }
4957
4957
 
4958
+ var getTheme = function getTheme(outerTheme, theme) {
4959
+ if (typeof theme === 'function') {
4960
+ var mergedTheme = theme(outerTheme);
4961
+
4962
+ if (process.env.NODE_ENV !== 'production' && (mergedTheme == null || typeof mergedTheme !== 'object' || Array.isArray(mergedTheme))) {
4963
+ throw new Error('[ThemeProvider] Please return an object from your theme function, i.e. theme={() => ({})}!');
4964
+ }
4965
+
4966
+ return mergedTheme;
4967
+ }
4968
+
4969
+ if (process.env.NODE_ENV !== 'production' && (theme == null || typeof theme !== 'object' || Array.isArray(theme))) {
4970
+ throw new Error('[ThemeProvider] Please make your theme prop a plain object');
4971
+ }
4972
+
4973
+ return _extends$1({}, outerTheme, theme);
4974
+ };
4975
+
4976
+ var createCacheWithTheme = /* #__PURE__ */weakMemoize(function (outerTheme) {
4977
+ return weakMemoize(function (theme) {
4978
+ return getTheme(outerTheme, theme);
4979
+ });
4980
+ });
4981
+ var ThemeProvider = function ThemeProvider(props) {
4982
+ var theme = React__namespace.useContext(ThemeContext$1);
4983
+
4984
+ if (props.theme !== theme) {
4985
+ theme = createCacheWithTheme(theme)(props.theme);
4986
+ }
4987
+
4988
+ return /*#__PURE__*/React__namespace.createElement(ThemeContext$1.Provider, {
4989
+ value: theme
4990
+ }, props.children);
4991
+ };
4992
+
4958
4993
  var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
4959
4994
  var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
4960
4995
 
@@ -10782,7 +10817,7 @@ function isElement(node) {
10782
10817
  return node instanceof OwnElement || node instanceof Element;
10783
10818
  }
10784
10819
 
10785
- function isHTMLElement$2(node) {
10820
+ function isHTMLElement$1(node) {
10786
10821
  var OwnElement = getWindow(node).HTMLElement;
10787
10822
  return node instanceof OwnElement || node instanceof HTMLElement;
10788
10823
  }
@@ -10806,7 +10841,7 @@ function applyStyles(_ref) {
10806
10841
  var attributes = state.attributes[name] || {};
10807
10842
  var element = state.elements[name]; // arrow is optional + virtual elements
10808
10843
 
10809
- if (!isHTMLElement$2(element) || !getNodeName(element)) {
10844
+ if (!isHTMLElement$1(element) || !getNodeName(element)) {
10810
10845
  return;
10811
10846
  } // Flow doesn't support to extend this property, but it's the most
10812
10847
  // effective way to apply styles to an HTMLElement
@@ -10858,7 +10893,7 @@ function effect$2(_ref2) {
10858
10893
  return style;
10859
10894
  }, {}); // arrow is optional + virtual elements
10860
10895
 
10861
- if (!isHTMLElement$2(element) || !getNodeName(element)) {
10896
+ if (!isHTMLElement$1(element) || !getNodeName(element)) {
10862
10897
  return;
10863
10898
  }
10864
10899
 
@@ -10917,7 +10952,7 @@ function getBoundingClientRect(element, includeScale, isFixedStrategy) {
10917
10952
  var scaleX = 1;
10918
10953
  var scaleY = 1;
10919
10954
 
10920
- if (includeScale && isHTMLElement$2(element)) {
10955
+ if (includeScale && isHTMLElement$1(element)) {
10921
10956
  scaleX = element.offsetWidth > 0 ? round$1(clientRect.width) / element.offsetWidth || 1 : 1;
10922
10957
  scaleY = element.offsetHeight > 0 ? round$1(clientRect.height) / element.offsetHeight || 1 : 1;
10923
10958
  }
@@ -11022,7 +11057,7 @@ function getParentNode(element) {
11022
11057
  }
11023
11058
 
11024
11059
  function getTrueOffsetParent(element) {
11025
- if (!isHTMLElement$2(element) || // https://github.com/popperjs/popper-core/issues/837
11060
+ if (!isHTMLElement$1(element) || // https://github.com/popperjs/popper-core/issues/837
11026
11061
  getComputedStyle(element).position === 'fixed') {
11027
11062
  return null;
11028
11063
  }
@@ -11036,7 +11071,7 @@ function getContainingBlock(element) {
11036
11071
  var isFirefox = /firefox/i.test(getUAString());
11037
11072
  var isIE = /Trident/i.test(getUAString());
11038
11073
 
11039
- if (isIE && isHTMLElement$2(element)) {
11074
+ if (isIE && isHTMLElement$1(element)) {
11040
11075
  // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
11041
11076
  var elementCss = getComputedStyle(element);
11042
11077
 
@@ -11051,7 +11086,7 @@ function getContainingBlock(element) {
11051
11086
  currentNode = currentNode.host;
11052
11087
  }
11053
11088
 
11054
- while (isHTMLElement$2(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
11089
+ while (isHTMLElement$1(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
11055
11090
  var css = getComputedStyle(currentNode); // This is non-exhaustive but covers the most common CSS properties that
11056
11091
  // create a containing block.
11057
11092
  // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
@@ -11521,7 +11556,7 @@ function getScrollParent(node) {
11521
11556
  return node.ownerDocument.body;
11522
11557
  }
11523
11558
 
11524
- if (isHTMLElement$2(node) && isScrollParent(node)) {
11559
+ if (isHTMLElement$1(node) && isScrollParent(node)) {
11525
11560
  return node;
11526
11561
  }
11527
11562
 
@@ -11583,7 +11618,7 @@ function getClientRectFromMixedType(element, clippingParent, strategy) {
11583
11618
  function getClippingParents(element) {
11584
11619
  var clippingParents = listScrollParents(getParentNode(element));
11585
11620
  var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle(element).position) >= 0;
11586
- var clipperElement = canEscapeClipping && isHTMLElement$2(element) ? getOffsetParent(element) : element;
11621
+ var clipperElement = canEscapeClipping && isHTMLElement$1(element) ? getOffsetParent(element) : element;
11587
11622
 
11588
11623
  if (!isElement(clipperElement)) {
11589
11624
  return [];
@@ -12195,7 +12230,7 @@ function getHTMLElementScroll(element) {
12195
12230
  }
12196
12231
 
12197
12232
  function getNodeScroll(node) {
12198
- if (node === getWindow(node) || !isHTMLElement$2(node)) {
12233
+ if (node === getWindow(node) || !isHTMLElement$1(node)) {
12199
12234
  return getWindowScroll(node);
12200
12235
  } else {
12201
12236
  return getHTMLElementScroll(node);
@@ -12216,8 +12251,8 @@ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
12216
12251
  isFixed = false;
12217
12252
  }
12218
12253
 
12219
- var isOffsetParentAnElement = isHTMLElement$2(offsetParent);
12220
- var offsetParentIsScaled = isHTMLElement$2(offsetParent) && isElementScaled(offsetParent);
12254
+ var isOffsetParentAnElement = isHTMLElement$1(offsetParent);
12255
+ var offsetParentIsScaled = isHTMLElement$1(offsetParent) && isElementScaled(offsetParent);
12221
12256
  var documentElement = getDocumentElement(offsetParent);
12222
12257
  var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled, isFixed);
12223
12258
  var scroll = {
@@ -12235,7 +12270,7 @@ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
12235
12270
  scroll = getNodeScroll(offsetParent);
12236
12271
  }
12237
12272
 
12238
- if (isHTMLElement$2(offsetParent)) {
12273
+ if (isHTMLElement$1(offsetParent)) {
12239
12274
  offsets = getBoundingClientRect(offsetParent, true);
12240
12275
  offsets.x += offsetParent.clientLeft;
12241
12276
  offsets.y += offsetParent.clientTop;
@@ -12547,11 +12582,11 @@ function flipPlacement(placement, direction) {
12547
12582
  function resolveAnchorEl$1(anchorEl) {
12548
12583
  return typeof anchorEl === 'function' ? anchorEl() : anchorEl;
12549
12584
  }
12550
- function isHTMLElement$1(element) {
12585
+ function isHTMLElement(element) {
12551
12586
  return element.nodeType !== undefined;
12552
12587
  }
12553
12588
  function isVirtualElement(element) {
12554
- return !isHTMLElement$1(element);
12589
+ return !isHTMLElement(element);
12555
12590
  }
12556
12591
  const useUtilityClasses$U = () => {
12557
12592
  const slots = {
@@ -12613,7 +12648,7 @@ const PopperTooltip = /*#__PURE__*/React__namespace.forwardRef(function PopperTo
12613
12648
  setPlacement(data.placement);
12614
12649
  };
12615
12650
  if (process.env.NODE_ENV !== 'production') {
12616
- if (resolvedAnchorElement && isHTMLElement$1(resolvedAnchorElement) && resolvedAnchorElement.nodeType === 1) {
12651
+ if (resolvedAnchorElement && isHTMLElement(resolvedAnchorElement) && resolvedAnchorElement.nodeType === 1) {
12617
12652
  const box = resolvedAnchorElement.getBoundingClientRect();
12618
12653
  if (process.env.NODE_ENV !== 'test' && box.top === 0 && box.left === 0 && box.right === 0 && box.bottom === 0) {
12619
12654
  console.warn(['MUI: The `anchorEl` prop provided to the component is invalid.', 'The anchor element should be part of the document layout.', "Make sure the element is present in the document or that it's not display none."].join('\n'));
@@ -12730,7 +12765,7 @@ const Popper$1 = /*#__PURE__*/React__namespace.forwardRef(function Popper(props,
12730
12765
  container = containerProp;
12731
12766
  } else if (anchorEl) {
12732
12767
  const resolvedAnchorEl = resolveAnchorEl$1(anchorEl);
12733
- container = resolvedAnchorEl && isHTMLElement$1(resolvedAnchorEl) ? ownerDocument(resolvedAnchorEl).body : ownerDocument(null).body;
12768
+ container = resolvedAnchorEl && isHTMLElement(resolvedAnchorEl) ? ownerDocument(resolvedAnchorEl).body : ownerDocument(null).body;
12734
12769
  }
12735
12770
  const display = !open && keepMounted && (!transition || exited) ? 'none' : undefined;
12736
12771
  const transitionProps = transition ? {
@@ -12781,7 +12816,7 @@ process.env.NODE_ENV !== "production" ? Popper$1.propTypes /* remove-proptypes *
12781
12816
  anchorEl: chainPropTypes(PropTypes.oneOfType([HTMLElementType, PropTypes.object, PropTypes.func]), props => {
12782
12817
  if (props.open) {
12783
12818
  const resolvedAnchorEl = resolveAnchorEl$1(props.anchorEl);
12784
- if (resolvedAnchorEl && isHTMLElement$1(resolvedAnchorEl) && resolvedAnchorEl.nodeType === 1) {
12819
+ if (resolvedAnchorEl && isHTMLElement(resolvedAnchorEl) && resolvedAnchorEl.nodeType === 1) {
12785
12820
  const box = resolvedAnchorEl.getBoundingClientRect();
12786
12821
  if (process.env.NODE_ENV !== 'test' && box.top === 0 && box.left === 0 && box.right === 0 && box.bottom === 0) {
12787
12822
  return new Error(['MUI: The `anchorEl` prop provided to the component is invalid.', 'The anchor element should be part of the document layout.', "Make sure the element is present in the document or that it's not display none."].join('\n'));
@@ -13139,7 +13174,7 @@ function createFilterOptions(config = {}) {
13139
13174
  }
13140
13175
 
13141
13176
  // To replace with .findIndex() once we stop IE11 support.
13142
- function findIndex$2(array, comp) {
13177
+ function findIndex$1(array, comp) {
13143
13178
  for (let i = 0; i < array.length; i += 1) {
13144
13179
  if (comp(array[i])) {
13145
13180
  return i;
@@ -13487,7 +13522,7 @@ function useAutocomplete(props) {
13487
13522
  if (highlightedIndexRef.current !== -1 && previousProps.filteredOptions && previousProps.filteredOptions.length !== filteredOptions.length && previousProps.inputValue === inputValue && (multiple ? value.length === previousProps.value.length && previousProps.value.every((val, i) => getOptionLabel(value[i]) === getOptionLabel(val)) : isSameValue(previousProps.value, value))) {
13488
13523
  const previousHighlightedOption = previousProps.filteredOptions[highlightedIndexRef.current];
13489
13524
  if (previousHighlightedOption) {
13490
- return findIndex$2(filteredOptions, option => {
13525
+ return findIndex$1(filteredOptions, option => {
13491
13526
  return getOptionLabel(option) === getOptionLabel(previousHighlightedOption);
13492
13527
  });
13493
13528
  }
@@ -13524,10 +13559,10 @@ function useAutocomplete(props) {
13524
13559
  const currentOption = filteredOptions[highlightedIndexRef.current];
13525
13560
 
13526
13561
  // Keep the current highlighted index if possible
13527
- if (multiple && currentOption && findIndex$2(value, val => isOptionEqualToValue(currentOption, val)) !== -1) {
13562
+ if (multiple && currentOption && findIndex$1(value, val => isOptionEqualToValue(currentOption, val)) !== -1) {
13528
13563
  return;
13529
13564
  }
13530
- const itemIndex = findIndex$2(filteredOptions, optionItem => isOptionEqualToValue(optionItem, valueItem));
13565
+ const itemIndex = findIndex$1(filteredOptions, optionItem => isOptionEqualToValue(optionItem, valueItem));
13531
13566
  if (itemIndex === -1) {
13532
13567
  changeHighlightedIndex({
13533
13568
  diff: 'reset'
@@ -13626,7 +13661,7 @@ function useAutocomplete(props) {
13626
13661
  console.error([`MUI: The \`isOptionEqualToValue\` method of ${componentName} does not handle the arguments correctly.`, `The component expects a single value to match a given option but found ${matches.length} matches.`].join('\n'));
13627
13662
  }
13628
13663
  }
13629
- const itemIndex = findIndex$2(newValue, valueItem => isOptionEqualToValue(option, valueItem));
13664
+ const itemIndex = findIndex$1(newValue, valueItem => isOptionEqualToValue(option, valueItem));
13630
13665
  if (itemIndex === -1) {
13631
13666
  newValue.push(option);
13632
13667
  } else if (origin !== 'freeSolo') {
@@ -23345,12 +23380,12 @@ var isDateObject = (value) => value instanceof Date;
23345
23380
  var isNullOrUndefined = (value) => value == null;
23346
23381
 
23347
23382
  const isObjectType = (value) => typeof value === 'object';
23348
- var isObject$1 = (value) => !isNullOrUndefined(value) &&
23383
+ var isObject = (value) => !isNullOrUndefined(value) &&
23349
23384
  !Array.isArray(value) &&
23350
23385
  isObjectType(value) &&
23351
23386
  !isDateObject(value);
23352
23387
 
23353
- var getEventValue = (event) => isObject$1(event) && event.target
23388
+ var getEventValue = (event) => isObject(event) && event.target
23354
23389
  ? isCheckBoxInput(event.target)
23355
23390
  ? event.target.checked
23356
23391
  : event.target.value
@@ -23362,7 +23397,7 @@ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
23362
23397
 
23363
23398
  var isPlainObject = (tempObject) => {
23364
23399
  const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
23365
- return (isObject$1(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
23400
+ return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
23366
23401
  };
23367
23402
 
23368
23403
  var isWeb = typeof window !== 'undefined' &&
@@ -23379,7 +23414,7 @@ function cloneObject(data) {
23379
23414
  copy = new Set(data);
23380
23415
  }
23381
23416
  else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
23382
- (isArray || isObject$1(data))) {
23417
+ (isArray || isObject(data))) {
23383
23418
  copy = isArray ? [] : {};
23384
23419
  if (!isArray && !isPlainObject(data)) {
23385
23420
  copy = data;
@@ -23403,7 +23438,7 @@ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
23403
23438
  var isUndefined = (val) => val === undefined;
23404
23439
 
23405
23440
  var get = (object, path, defaultValue) => {
23406
- if (!path || !isObject$1(object)) {
23441
+ if (!path || !isObject(object)) {
23407
23442
  return defaultValue;
23408
23443
  }
23409
23444
  const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
@@ -23431,7 +23466,7 @@ var set = (object, path, value) => {
23431
23466
  if (index !== lastIndex) {
23432
23467
  const objValue = object[key];
23433
23468
  newValue =
23434
- isObject$1(objValue) || Array.isArray(objValue)
23469
+ isObject(objValue) || Array.isArray(objValue)
23435
23470
  ? objValue
23436
23471
  : !isNaN(+tempPath[index + 1])
23437
23472
  ? []
@@ -23458,15 +23493,6 @@ const VALIDATION_MODE = {
23458
23493
  onTouched: 'onTouched',
23459
23494
  all: 'all',
23460
23495
  };
23461
- const INPUT_VALIDATION_RULES = {
23462
- max: 'max',
23463
- min: 'min',
23464
- maxLength: 'maxLength',
23465
- minLength: 'minLength',
23466
- pattern: 'pattern',
23467
- required: 'required',
23468
- validate: 'validate',
23469
- };
23470
23496
 
23471
23497
  const HookFormContext = React$1.createContext(null);
23472
23498
  /**
@@ -23520,7 +23546,7 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
23520
23546
  return result;
23521
23547
  };
23522
23548
 
23523
- var isEmptyObject = (value) => isObject$1(value) && !Object.keys(value).length;
23549
+ var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
23524
23550
 
23525
23551
  var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
23526
23552
  updateFormState(formStateData);
@@ -23528,7 +23554,7 @@ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, is
23528
23554
  return (isEmptyObject(formState) ||
23529
23555
  Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
23530
23556
  Object.keys(formState).find((key) => _proxyFormState[key] ===
23531
- (!isRoot || VALIDATION_MODE.all)));
23557
+ (!isRoot )));
23532
23558
  };
23533
23559
 
23534
23560
  var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
@@ -23629,13 +23655,11 @@ var isString = (value) => typeof value === 'string';
23629
23655
 
23630
23656
  var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
23631
23657
  if (isString(names)) {
23632
- isGlobal && _names.watch.add(names);
23633
23658
  return get(formValues, names, defaultValue);
23634
23659
  }
23635
23660
  if (Array.isArray(names)) {
23636
- return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
23661
+ return names.map((fieldName) => (get(formValues, fieldName)));
23637
23662
  }
23638
- isGlobal && (_names.watchAll = true);
23639
23663
  return formValues;
23640
23664
  };
23641
23665
 
@@ -23854,1656 +23878,7 @@ function useController(props) {
23854
23878
  */
23855
23879
  const Controller = (props) => props.render(useController(props));
23856
23880
 
23857
- var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
23858
- ? {
23859
- ...errors[name],
23860
- types: {
23861
- ...(errors[name] && errors[name].types ? errors[name].types : {}),
23862
- [type]: message || true,
23863
- },
23864
- }
23865
- : {};
23866
-
23867
- var getValidationModes = (mode) => ({
23868
- isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
23869
- isOnBlur: mode === VALIDATION_MODE.onBlur,
23870
- isOnChange: mode === VALIDATION_MODE.onChange,
23871
- isOnAll: mode === VALIDATION_MODE.all,
23872
- isOnTouch: mode === VALIDATION_MODE.onTouched,
23873
- });
23874
-
23875
- var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
23876
- (_names.watchAll ||
23877
- _names.watch.has(name) ||
23878
- [..._names.watch].some((watchName) => name.startsWith(watchName) &&
23879
- /^\.\w+/.test(name.slice(watchName.length))));
23880
-
23881
- const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
23882
- for (const key of fieldsNames || Object.keys(fields)) {
23883
- const field = get(fields, key);
23884
- if (field) {
23885
- const { _f, ...currentField } = field;
23886
- if (_f) {
23887
- if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
23888
- break;
23889
- }
23890
- else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
23891
- break;
23892
- }
23893
- else {
23894
- iterateFieldsByAction(currentField, action);
23895
- }
23896
- }
23897
- else if (isObject$1(currentField)) {
23898
- iterateFieldsByAction(currentField, action);
23899
- }
23900
- }
23901
- }
23902
- };
23903
-
23904
- var updateFieldArrayRootError = (errors, error, name) => {
23905
- const fieldArrayErrors = compact(get(errors, name));
23906
- set(fieldArrayErrors, 'root', error[name]);
23907
- set(errors, name, fieldArrayErrors);
23908
- return errors;
23909
- };
23910
-
23911
- var isFileInput = (element) => element.type === 'file';
23912
-
23913
- var isFunction = (value) => typeof value === 'function';
23914
-
23915
- var isHTMLElement = (value) => {
23916
- if (!isWeb) {
23917
- return false;
23918
- }
23919
- const owner = value ? value.ownerDocument : 0;
23920
- return (value instanceof
23921
- (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
23922
- };
23923
-
23924
- var isMessage = (value) => isString(value);
23925
-
23926
- var isRadioInput = (element) => element.type === 'radio';
23927
-
23928
- var isRegex = (value) => value instanceof RegExp;
23929
-
23930
- const defaultResult = {
23931
- value: false,
23932
- isValid: false,
23933
- };
23934
- const validResult = { value: true, isValid: true };
23935
- var getCheckboxValue = (options) => {
23936
- if (Array.isArray(options)) {
23937
- if (options.length > 1) {
23938
- const values = options
23939
- .filter((option) => option && option.checked && !option.disabled)
23940
- .map((option) => option.value);
23941
- return { value: values, isValid: !!values.length };
23942
- }
23943
- return options[0].checked && !options[0].disabled
23944
- ? // @ts-expect-error expected to work in the browser
23945
- options[0].attributes && !isUndefined(options[0].attributes.value)
23946
- ? isUndefined(options[0].value) || options[0].value === ''
23947
- ? validResult
23948
- : { value: options[0].value, isValid: true }
23949
- : validResult
23950
- : defaultResult;
23951
- }
23952
- return defaultResult;
23953
- };
23954
-
23955
- const defaultReturn = {
23956
- isValid: false,
23957
- value: null,
23958
- };
23959
- var getRadioValue = (options) => Array.isArray(options)
23960
- ? options.reduce((previous, option) => option && option.checked && !option.disabled
23961
- ? {
23962
- isValid: true,
23963
- value: option.value,
23964
- }
23965
- : previous, defaultReturn)
23966
- : defaultReturn;
23967
-
23968
- function getValidateError(result, ref, type = 'validate') {
23969
- if (isMessage(result) ||
23970
- (Array.isArray(result) && result.every(isMessage)) ||
23971
- (isBoolean(result) && !result)) {
23972
- return {
23973
- type,
23974
- message: isMessage(result) ? result : '',
23975
- ref,
23976
- };
23977
- }
23978
- }
23979
-
23980
- var getValueAndMessage = (validationData) => isObject$1(validationData) && !isRegex(validationData)
23981
- ? validationData
23982
- : {
23983
- value: validationData,
23984
- message: '',
23985
- };
23986
-
23987
- var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
23988
- const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled, } = field._f;
23989
- const inputValue = get(formValues, name);
23990
- if (!mount || disabled) {
23991
- return {};
23992
- }
23993
- const inputRef = refs ? refs[0] : ref;
23994
- const setCustomValidity = (message) => {
23995
- if (shouldUseNativeValidation && inputRef.reportValidity) {
23996
- inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
23997
- inputRef.reportValidity();
23998
- }
23999
- };
24000
- const error = {};
24001
- const isRadio = isRadioInput(ref);
24002
- const isCheckBox = isCheckBoxInput(ref);
24003
- const isRadioOrCheckbox = isRadio || isCheckBox;
24004
- const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
24005
- isUndefined(ref.value) &&
24006
- isUndefined(inputValue)) ||
24007
- (isHTMLElement(ref) && ref.value === '') ||
24008
- inputValue === '' ||
24009
- (Array.isArray(inputValue) && !inputValue.length);
24010
- const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
24011
- const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
24012
- const message = exceedMax ? maxLengthMessage : minLengthMessage;
24013
- error[name] = {
24014
- type: exceedMax ? maxType : minType,
24015
- message,
24016
- ref,
24017
- ...appendErrorsCurry(exceedMax ? maxType : minType, message),
24018
- };
24019
- };
24020
- if (isFieldArray
24021
- ? !Array.isArray(inputValue) || !inputValue.length
24022
- : required &&
24023
- ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
24024
- (isBoolean(inputValue) && !inputValue) ||
24025
- (isCheckBox && !getCheckboxValue(refs).isValid) ||
24026
- (isRadio && !getRadioValue(refs).isValid))) {
24027
- const { value, message } = isMessage(required)
24028
- ? { value: !!required, message: required }
24029
- : getValueAndMessage(required);
24030
- if (value) {
24031
- error[name] = {
24032
- type: INPUT_VALIDATION_RULES.required,
24033
- message,
24034
- ref: inputRef,
24035
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
24036
- };
24037
- if (!validateAllFieldCriteria) {
24038
- setCustomValidity(message);
24039
- return error;
24040
- }
24041
- }
24042
- }
24043
- if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
24044
- let exceedMax;
24045
- let exceedMin;
24046
- const maxOutput = getValueAndMessage(max);
24047
- const minOutput = getValueAndMessage(min);
24048
- if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
24049
- const valueNumber = ref.valueAsNumber ||
24050
- (inputValue ? +inputValue : inputValue);
24051
- if (!isNullOrUndefined(maxOutput.value)) {
24052
- exceedMax = valueNumber > maxOutput.value;
24053
- }
24054
- if (!isNullOrUndefined(minOutput.value)) {
24055
- exceedMin = valueNumber < minOutput.value;
24056
- }
24057
- }
24058
- else {
24059
- const valueDate = ref.valueAsDate || new Date(inputValue);
24060
- const convertTimeToDate = (time) => new Date(new Date().toDateString() + ' ' + time);
24061
- const isTime = ref.type == 'time';
24062
- const isWeek = ref.type == 'week';
24063
- if (isString(maxOutput.value) && inputValue) {
24064
- exceedMax = isTime
24065
- ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value)
24066
- : isWeek
24067
- ? inputValue > maxOutput.value
24068
- : valueDate > new Date(maxOutput.value);
24069
- }
24070
- if (isString(minOutput.value) && inputValue) {
24071
- exceedMin = isTime
24072
- ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value)
24073
- : isWeek
24074
- ? inputValue < minOutput.value
24075
- : valueDate < new Date(minOutput.value);
24076
- }
24077
- }
24078
- if (exceedMax || exceedMin) {
24079
- getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
24080
- if (!validateAllFieldCriteria) {
24081
- setCustomValidity(error[name].message);
24082
- return error;
24083
- }
24084
- }
24085
- }
24086
- if ((maxLength || minLength) &&
24087
- !isEmpty &&
24088
- (isString(inputValue) || (isFieldArray && Array.isArray(inputValue)))) {
24089
- const maxLengthOutput = getValueAndMessage(maxLength);
24090
- const minLengthOutput = getValueAndMessage(minLength);
24091
- const exceedMax = !isNullOrUndefined(maxLengthOutput.value) &&
24092
- inputValue.length > +maxLengthOutput.value;
24093
- const exceedMin = !isNullOrUndefined(minLengthOutput.value) &&
24094
- inputValue.length < +minLengthOutput.value;
24095
- if (exceedMax || exceedMin) {
24096
- getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
24097
- if (!validateAllFieldCriteria) {
24098
- setCustomValidity(error[name].message);
24099
- return error;
24100
- }
24101
- }
24102
- }
24103
- if (pattern && !isEmpty && isString(inputValue)) {
24104
- const { value: patternValue, message } = getValueAndMessage(pattern);
24105
- if (isRegex(patternValue) && !inputValue.match(patternValue)) {
24106
- error[name] = {
24107
- type: INPUT_VALIDATION_RULES.pattern,
24108
- message,
24109
- ref,
24110
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
24111
- };
24112
- if (!validateAllFieldCriteria) {
24113
- setCustomValidity(message);
24114
- return error;
24115
- }
24116
- }
24117
- }
24118
- if (validate) {
24119
- if (isFunction(validate)) {
24120
- const result = await validate(inputValue, formValues);
24121
- const validateError = getValidateError(result, inputRef);
24122
- if (validateError) {
24123
- error[name] = {
24124
- ...validateError,
24125
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
24126
- };
24127
- if (!validateAllFieldCriteria) {
24128
- setCustomValidity(validateError.message);
24129
- return error;
24130
- }
24131
- }
24132
- }
24133
- else if (isObject$1(validate)) {
24134
- let validationResult = {};
24135
- for (const key in validate) {
24136
- if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
24137
- break;
24138
- }
24139
- const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
24140
- if (validateError) {
24141
- validationResult = {
24142
- ...validateError,
24143
- ...appendErrorsCurry(key, validateError.message),
24144
- };
24145
- setCustomValidity(validateError.message);
24146
- if (validateAllFieldCriteria) {
24147
- error[name] = validationResult;
24148
- }
24149
- }
24150
- }
24151
- if (!isEmptyObject(validationResult)) {
24152
- error[name] = {
24153
- ref: inputRef,
24154
- ...validationResult,
24155
- };
24156
- if (!validateAllFieldCriteria) {
24157
- return error;
24158
- }
24159
- }
24160
- }
24161
- }
24162
- setCustomValidity(true);
24163
- return error;
24164
- };
24165
-
24166
- function baseGet(object, updatePath) {
24167
- const length = updatePath.slice(0, -1).length;
24168
- let index = 0;
24169
- while (index < length) {
24170
- object = isUndefined(object) ? index++ : object[updatePath[index++]];
24171
- }
24172
- return object;
24173
- }
24174
- function isEmptyArray(obj) {
24175
- for (const key in obj) {
24176
- if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
24177
- return false;
24178
- }
24179
- }
24180
- return true;
24181
- }
24182
- function unset(object, path) {
24183
- const paths = Array.isArray(path)
24184
- ? path
24185
- : isKey(path)
24186
- ? [path]
24187
- : stringToPath(path);
24188
- const childObject = paths.length === 1 ? object : baseGet(object, paths);
24189
- const index = paths.length - 1;
24190
- const key = paths[index];
24191
- if (childObject) {
24192
- delete childObject[key];
24193
- }
24194
- if (index !== 0 &&
24195
- ((isObject$1(childObject) && isEmptyObject(childObject)) ||
24196
- (Array.isArray(childObject) && isEmptyArray(childObject)))) {
24197
- unset(object, paths.slice(0, -1));
24198
- }
24199
- return object;
24200
- }
24201
-
24202
- var createSubject = () => {
24203
- let _observers = [];
24204
- const next = (value) => {
24205
- for (const observer of _observers) {
24206
- observer.next && observer.next(value);
24207
- }
24208
- };
24209
- const subscribe = (observer) => {
24210
- _observers.push(observer);
24211
- return {
24212
- unsubscribe: () => {
24213
- _observers = _observers.filter((o) => o !== observer);
24214
- },
24215
- };
24216
- };
24217
- const unsubscribe = () => {
24218
- _observers = [];
24219
- };
24220
- return {
24221
- get observers() {
24222
- return _observers;
24223
- },
24224
- next,
24225
- subscribe,
24226
- unsubscribe,
24227
- };
24228
- };
24229
-
24230
- var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
24231
-
24232
- function deepEqual(object1, object2) {
24233
- if (isPrimitive(object1) || isPrimitive(object2)) {
24234
- return object1 === object2;
24235
- }
24236
- if (isDateObject(object1) && isDateObject(object2)) {
24237
- return object1.getTime() === object2.getTime();
24238
- }
24239
- const keys1 = Object.keys(object1);
24240
- const keys2 = Object.keys(object2);
24241
- if (keys1.length !== keys2.length) {
24242
- return false;
24243
- }
24244
- for (const key of keys1) {
24245
- const val1 = object1[key];
24246
- if (!keys2.includes(key)) {
24247
- return false;
24248
- }
24249
- if (key !== 'ref') {
24250
- const val2 = object2[key];
24251
- if ((isDateObject(val1) && isDateObject(val2)) ||
24252
- (isObject$1(val1) && isObject$1(val2)) ||
24253
- (Array.isArray(val1) && Array.isArray(val2))
24254
- ? !deepEqual(val1, val2)
24255
- : val1 !== val2) {
24256
- return false;
24257
- }
24258
- }
24259
- }
24260
- return true;
24261
- }
24262
-
24263
- var isMultipleSelect = (element) => element.type === `select-multiple`;
24264
-
24265
- var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
24266
-
24267
- var live = (ref) => isHTMLElement(ref) && ref.isConnected;
24268
-
24269
- var objectHasFunction = (data) => {
24270
- for (const key in data) {
24271
- if (isFunction(data[key])) {
24272
- return true;
24273
- }
24274
- }
24275
- return false;
24276
- };
24277
-
24278
- function markFieldsDirty(data, fields = {}) {
24279
- const isParentNodeArray = Array.isArray(data);
24280
- if (isObject$1(data) || isParentNodeArray) {
24281
- for (const key in data) {
24282
- if (Array.isArray(data[key]) ||
24283
- (isObject$1(data[key]) && !objectHasFunction(data[key]))) {
24284
- fields[key] = Array.isArray(data[key]) ? [] : {};
24285
- markFieldsDirty(data[key], fields[key]);
24286
- }
24287
- else if (!isNullOrUndefined(data[key])) {
24288
- fields[key] = true;
24289
- }
24290
- }
24291
- }
24292
- return fields;
24293
- }
24294
- function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
24295
- const isParentNodeArray = Array.isArray(data);
24296
- if (isObject$1(data) || isParentNodeArray) {
24297
- for (const key in data) {
24298
- if (Array.isArray(data[key]) ||
24299
- (isObject$1(data[key]) && !objectHasFunction(data[key]))) {
24300
- if (isUndefined(formValues) ||
24301
- isPrimitive(dirtyFieldsFromValues[key])) {
24302
- dirtyFieldsFromValues[key] = Array.isArray(data[key])
24303
- ? markFieldsDirty(data[key], [])
24304
- : { ...markFieldsDirty(data[key]) };
24305
- }
24306
- else {
24307
- getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
24308
- }
24309
- }
24310
- else {
24311
- dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
24312
- }
24313
- }
24314
- }
24315
- return dirtyFieldsFromValues;
24316
- }
24317
- var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
24318
-
24319
- var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
24320
- ? value
24321
- : valueAsNumber
24322
- ? value === ''
24323
- ? NaN
24324
- : value
24325
- ? +value
24326
- : value
24327
- : valueAsDate && isString(value)
24328
- ? new Date(value)
24329
- : setValueAs
24330
- ? setValueAs(value)
24331
- : value;
24332
-
24333
- function getFieldValue(_f) {
24334
- const ref = _f.ref;
24335
- if (_f.refs ? _f.refs.every((ref) => ref.disabled) : ref.disabled) {
24336
- return;
24337
- }
24338
- if (isFileInput(ref)) {
24339
- return ref.files;
24340
- }
24341
- if (isRadioInput(ref)) {
24342
- return getRadioValue(_f.refs).value;
24343
- }
24344
- if (isMultipleSelect(ref)) {
24345
- return [...ref.selectedOptions].map(({ value }) => value);
24346
- }
24347
- if (isCheckBoxInput(ref)) {
24348
- return getCheckboxValue(_f.refs).value;
24349
- }
24350
- return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
24351
- }
24352
-
24353
- var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
24354
- const fields = {};
24355
- for (const name of fieldsNames) {
24356
- const field = get(_fields, name);
24357
- field && set(fields, name, field._f);
24358
- }
24359
- return {
24360
- criteriaMode,
24361
- names: [...fieldsNames],
24362
- fields,
24363
- shouldUseNativeValidation,
24364
- };
24365
- };
24366
-
24367
- var getRuleValue = (rule) => isUndefined(rule)
24368
- ? rule
24369
- : isRegex(rule)
24370
- ? rule.source
24371
- : isObject$1(rule)
24372
- ? isRegex(rule.value)
24373
- ? rule.value.source
24374
- : rule.value
24375
- : rule;
24376
-
24377
- var hasValidation = (options) => options.mount &&
24378
- (options.required ||
24379
- options.min ||
24380
- options.max ||
24381
- options.maxLength ||
24382
- options.minLength ||
24383
- options.pattern ||
24384
- options.validate);
24385
-
24386
- function schemaErrorLookup(errors, _fields, name) {
24387
- const error = get(errors, name);
24388
- if (error || isKey(name)) {
24389
- return {
24390
- error,
24391
- name,
24392
- };
24393
- }
24394
- const names = name.split('.');
24395
- while (names.length) {
24396
- const fieldName = names.join('.');
24397
- const field = get(_fields, fieldName);
24398
- const foundError = get(errors, fieldName);
24399
- if (field && !Array.isArray(field) && name !== fieldName) {
24400
- return { name };
24401
- }
24402
- if (foundError && foundError.type) {
24403
- return {
24404
- name: fieldName,
24405
- error: foundError,
24406
- };
24407
- }
24408
- names.pop();
24409
- }
24410
- return {
24411
- name,
24412
- };
24413
- }
24414
-
24415
- var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
24416
- if (mode.isOnAll) {
24417
- return false;
24418
- }
24419
- else if (!isSubmitted && mode.isOnTouch) {
24420
- return !(isTouched || isBlurEvent);
24421
- }
24422
- else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
24423
- return !isBlurEvent;
24424
- }
24425
- else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
24426
- return isBlurEvent;
24427
- }
24428
- return true;
24429
- };
24430
-
24431
- var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
24432
-
24433
- const defaultOptions$2 = {
24434
- mode: VALIDATION_MODE.onSubmit,
24435
- reValidateMode: VALIDATION_MODE.onChange,
24436
- shouldFocusError: true,
24437
- };
24438
- function createFormControl(props = {}) {
24439
- let _options = {
24440
- ...defaultOptions$2,
24441
- ...props,
24442
- };
24443
- let _formState = {
24444
- submitCount: 0,
24445
- isDirty: false,
24446
- isLoading: isFunction(_options.defaultValues),
24447
- isValidating: false,
24448
- isSubmitted: false,
24449
- isSubmitting: false,
24450
- isSubmitSuccessful: false,
24451
- isValid: false,
24452
- touchedFields: {},
24453
- dirtyFields: {},
24454
- validatingFields: {},
24455
- errors: _options.errors || {},
24456
- disabled: _options.disabled || false,
24457
- };
24458
- let _fields = {};
24459
- let _defaultValues = isObject$1(_options.defaultValues) || isObject$1(_options.values)
24460
- ? cloneObject(_options.defaultValues || _options.values) || {}
24461
- : {};
24462
- let _formValues = _options.shouldUnregister
24463
- ? {}
24464
- : cloneObject(_defaultValues);
24465
- let _state = {
24466
- action: false,
24467
- mount: false,
24468
- watch: false,
24469
- };
24470
- let _names = {
24471
- mount: new Set(),
24472
- unMount: new Set(),
24473
- array: new Set(),
24474
- watch: new Set(),
24475
- };
24476
- let delayErrorCallback;
24477
- let timer = 0;
24478
- const _proxyFormState = {
24479
- isDirty: false,
24480
- dirtyFields: false,
24481
- validatingFields: false,
24482
- touchedFields: false,
24483
- isValidating: false,
24484
- isValid: false,
24485
- errors: false,
24486
- };
24487
- const _subjects = {
24488
- values: createSubject(),
24489
- array: createSubject(),
24490
- state: createSubject(),
24491
- };
24492
- const validationModeBeforeSubmit = getValidationModes(_options.mode);
24493
- const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
24494
- const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
24495
- const debounce = (callback) => (wait) => {
24496
- clearTimeout(timer);
24497
- timer = setTimeout(callback, wait);
24498
- };
24499
- const _updateValid = async (shouldUpdateValid) => {
24500
- if (_proxyFormState.isValid || shouldUpdateValid) {
24501
- const isValid = _options.resolver
24502
- ? isEmptyObject((await _executeSchema()).errors)
24503
- : await executeBuiltInValidation(_fields, true);
24504
- if (isValid !== _formState.isValid) {
24505
- _subjects.state.next({
24506
- isValid,
24507
- });
24508
- }
24509
- }
24510
- };
24511
- const _updateIsValidating = (names, isValidating) => {
24512
- if (_proxyFormState.isValidating || _proxyFormState.validatingFields) {
24513
- (names || Array.from(_names.mount)).forEach((name) => {
24514
- if (name) {
24515
- isValidating
24516
- ? set(_formState.validatingFields, name, isValidating)
24517
- : unset(_formState.validatingFields, name);
24518
- }
24519
- });
24520
- _subjects.state.next({
24521
- validatingFields: _formState.validatingFields,
24522
- isValidating: !isEmptyObject(_formState.validatingFields),
24523
- });
24524
- }
24525
- };
24526
- const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
24527
- if (args && method) {
24528
- _state.action = true;
24529
- if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
24530
- const fieldValues = method(get(_fields, name), args.argA, args.argB);
24531
- shouldSetValues && set(_fields, name, fieldValues);
24532
- }
24533
- if (shouldUpdateFieldsAndState &&
24534
- Array.isArray(get(_formState.errors, name))) {
24535
- const errors = method(get(_formState.errors, name), args.argA, args.argB);
24536
- shouldSetValues && set(_formState.errors, name, errors);
24537
- unsetEmptyArray(_formState.errors, name);
24538
- }
24539
- if (_proxyFormState.touchedFields &&
24540
- shouldUpdateFieldsAndState &&
24541
- Array.isArray(get(_formState.touchedFields, name))) {
24542
- const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
24543
- shouldSetValues && set(_formState.touchedFields, name, touchedFields);
24544
- }
24545
- if (_proxyFormState.dirtyFields) {
24546
- _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
24547
- }
24548
- _subjects.state.next({
24549
- name,
24550
- isDirty: _getDirty(name, values),
24551
- dirtyFields: _formState.dirtyFields,
24552
- errors: _formState.errors,
24553
- isValid: _formState.isValid,
24554
- });
24555
- }
24556
- else {
24557
- set(_formValues, name, values);
24558
- }
24559
- };
24560
- const updateErrors = (name, error) => {
24561
- set(_formState.errors, name, error);
24562
- _subjects.state.next({
24563
- errors: _formState.errors,
24564
- });
24565
- };
24566
- const _setErrors = (errors) => {
24567
- _formState.errors = errors;
24568
- _subjects.state.next({
24569
- errors: _formState.errors,
24570
- isValid: false,
24571
- });
24572
- };
24573
- const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
24574
- const field = get(_fields, name);
24575
- if (field) {
24576
- const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
24577
- isUndefined(defaultValue) ||
24578
- (ref && ref.defaultChecked) ||
24579
- shouldSkipSetValueAs
24580
- ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
24581
- : setFieldValue(name, defaultValue);
24582
- _state.mount && _updateValid();
24583
- }
24584
- };
24585
- const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
24586
- let shouldUpdateField = false;
24587
- let isPreviousDirty = false;
24588
- const output = {
24589
- name,
24590
- };
24591
- const disabledField = !!(get(_fields, name) && get(_fields, name)._f.disabled);
24592
- if (!isBlurEvent || shouldDirty) {
24593
- if (_proxyFormState.isDirty) {
24594
- isPreviousDirty = _formState.isDirty;
24595
- _formState.isDirty = output.isDirty = _getDirty();
24596
- shouldUpdateField = isPreviousDirty !== output.isDirty;
24597
- }
24598
- const isCurrentFieldPristine = disabledField || deepEqual(get(_defaultValues, name), fieldValue);
24599
- isPreviousDirty = !!(!disabledField && get(_formState.dirtyFields, name));
24600
- isCurrentFieldPristine || disabledField
24601
- ? unset(_formState.dirtyFields, name)
24602
- : set(_formState.dirtyFields, name, true);
24603
- output.dirtyFields = _formState.dirtyFields;
24604
- shouldUpdateField =
24605
- shouldUpdateField ||
24606
- (_proxyFormState.dirtyFields &&
24607
- isPreviousDirty !== !isCurrentFieldPristine);
24608
- }
24609
- if (isBlurEvent) {
24610
- const isPreviousFieldTouched = get(_formState.touchedFields, name);
24611
- if (!isPreviousFieldTouched) {
24612
- set(_formState.touchedFields, name, isBlurEvent);
24613
- output.touchedFields = _formState.touchedFields;
24614
- shouldUpdateField =
24615
- shouldUpdateField ||
24616
- (_proxyFormState.touchedFields &&
24617
- isPreviousFieldTouched !== isBlurEvent);
24618
- }
24619
- }
24620
- shouldUpdateField && shouldRender && _subjects.state.next(output);
24621
- return shouldUpdateField ? output : {};
24622
- };
24623
- const shouldRenderByError = (name, isValid, error, fieldState) => {
24624
- const previousFieldError = get(_formState.errors, name);
24625
- const shouldUpdateValid = _proxyFormState.isValid &&
24626
- isBoolean(isValid) &&
24627
- _formState.isValid !== isValid;
24628
- if (props.delayError && error) {
24629
- delayErrorCallback = debounce(() => updateErrors(name, error));
24630
- delayErrorCallback(props.delayError);
24631
- }
24632
- else {
24633
- clearTimeout(timer);
24634
- delayErrorCallback = null;
24635
- error
24636
- ? set(_formState.errors, name, error)
24637
- : unset(_formState.errors, name);
24638
- }
24639
- if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
24640
- !isEmptyObject(fieldState) ||
24641
- shouldUpdateValid) {
24642
- const updatedFormState = {
24643
- ...fieldState,
24644
- ...(shouldUpdateValid && isBoolean(isValid) ? { isValid } : {}),
24645
- errors: _formState.errors,
24646
- name,
24647
- };
24648
- _formState = {
24649
- ..._formState,
24650
- ...updatedFormState,
24651
- };
24652
- _subjects.state.next(updatedFormState);
24653
- }
24654
- };
24655
- const _executeSchema = async (name) => {
24656
- _updateIsValidating(name, true);
24657
- const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
24658
- _updateIsValidating(name);
24659
- return result;
24660
- };
24661
- const executeSchemaAndUpdateState = async (names) => {
24662
- const { errors } = await _executeSchema(names);
24663
- if (names) {
24664
- for (const name of names) {
24665
- const error = get(errors, name);
24666
- error
24667
- ? set(_formState.errors, name, error)
24668
- : unset(_formState.errors, name);
24669
- }
24670
- }
24671
- else {
24672
- _formState.errors = errors;
24673
- }
24674
- return errors;
24675
- };
24676
- const executeBuiltInValidation = async (fields, shouldOnlyCheckValid, context = {
24677
- valid: true,
24678
- }) => {
24679
- for (const name in fields) {
24680
- const field = fields[name];
24681
- if (field) {
24682
- const { _f, ...fieldValue } = field;
24683
- if (_f) {
24684
- const isFieldArrayRoot = _names.array.has(_f.name);
24685
- _updateIsValidating([name], true);
24686
- const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
24687
- _updateIsValidating([name]);
24688
- if (fieldError[_f.name]) {
24689
- context.valid = false;
24690
- if (shouldOnlyCheckValid) {
24691
- break;
24692
- }
24693
- }
24694
- !shouldOnlyCheckValid &&
24695
- (get(fieldError, _f.name)
24696
- ? isFieldArrayRoot
24697
- ? updateFieldArrayRootError(_formState.errors, fieldError, _f.name)
24698
- : set(_formState.errors, _f.name, fieldError[_f.name])
24699
- : unset(_formState.errors, _f.name));
24700
- }
24701
- fieldValue &&
24702
- (await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context));
24703
- }
24704
- }
24705
- return context.valid;
24706
- };
24707
- const _removeUnmounted = () => {
24708
- for (const name of _names.unMount) {
24709
- const field = get(_fields, name);
24710
- field &&
24711
- (field._f.refs
24712
- ? field._f.refs.every((ref) => !live(ref))
24713
- : !live(field._f.ref)) &&
24714
- unregister(name);
24715
- }
24716
- _names.unMount = new Set();
24717
- };
24718
- const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
24719
- !deepEqual(getValues(), _defaultValues));
24720
- const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
24721
- ...(_state.mount
24722
- ? _formValues
24723
- : isUndefined(defaultValue)
24724
- ? _defaultValues
24725
- : isString(names)
24726
- ? { [names]: defaultValue }
24727
- : defaultValue),
24728
- }, isGlobal, defaultValue);
24729
- const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
24730
- const setFieldValue = (name, value, options = {}) => {
24731
- const field = get(_fields, name);
24732
- let fieldValue = value;
24733
- if (field) {
24734
- const fieldReference = field._f;
24735
- if (fieldReference) {
24736
- !fieldReference.disabled &&
24737
- set(_formValues, name, getFieldValueAs(value, fieldReference));
24738
- fieldValue =
24739
- isHTMLElement(fieldReference.ref) && isNullOrUndefined(value)
24740
- ? ''
24741
- : value;
24742
- if (isMultipleSelect(fieldReference.ref)) {
24743
- [...fieldReference.ref.options].forEach((optionRef) => (optionRef.selected = fieldValue.includes(optionRef.value)));
24744
- }
24745
- else if (fieldReference.refs) {
24746
- if (isCheckBoxInput(fieldReference.ref)) {
24747
- fieldReference.refs.length > 1
24748
- ? fieldReference.refs.forEach((checkboxRef) => (!checkboxRef.defaultChecked || !checkboxRef.disabled) &&
24749
- (checkboxRef.checked = Array.isArray(fieldValue)
24750
- ? !!fieldValue.find((data) => data === checkboxRef.value)
24751
- : fieldValue === checkboxRef.value))
24752
- : fieldReference.refs[0] &&
24753
- (fieldReference.refs[0].checked = !!fieldValue);
24754
- }
24755
- else {
24756
- fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
24757
- }
24758
- }
24759
- else if (isFileInput(fieldReference.ref)) {
24760
- fieldReference.ref.value = '';
24761
- }
24762
- else {
24763
- fieldReference.ref.value = fieldValue;
24764
- if (!fieldReference.ref.type) {
24765
- _subjects.values.next({
24766
- name,
24767
- values: { ..._formValues },
24768
- });
24769
- }
24770
- }
24771
- }
24772
- }
24773
- (options.shouldDirty || options.shouldTouch) &&
24774
- updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
24775
- options.shouldValidate && trigger(name);
24776
- };
24777
- const setValues = (name, value, options) => {
24778
- for (const fieldKey in value) {
24779
- const fieldValue = value[fieldKey];
24780
- const fieldName = `${name}.${fieldKey}`;
24781
- const field = get(_fields, fieldName);
24782
- (_names.array.has(name) ||
24783
- !isPrimitive(fieldValue) ||
24784
- (field && !field._f)) &&
24785
- !isDateObject(fieldValue)
24786
- ? setValues(fieldName, fieldValue, options)
24787
- : setFieldValue(fieldName, fieldValue, options);
24788
- }
24789
- };
24790
- const setValue = (name, value, options = {}) => {
24791
- const field = get(_fields, name);
24792
- const isFieldArray = _names.array.has(name);
24793
- const cloneValue = cloneObject(value);
24794
- set(_formValues, name, cloneValue);
24795
- if (isFieldArray) {
24796
- _subjects.array.next({
24797
- name,
24798
- values: { ..._formValues },
24799
- });
24800
- if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
24801
- options.shouldDirty) {
24802
- _subjects.state.next({
24803
- name,
24804
- dirtyFields: getDirtyFields(_defaultValues, _formValues),
24805
- isDirty: _getDirty(name, cloneValue),
24806
- });
24807
- }
24808
- }
24809
- else {
24810
- field && !field._f && !isNullOrUndefined(cloneValue)
24811
- ? setValues(name, cloneValue, options)
24812
- : setFieldValue(name, cloneValue, options);
24813
- }
24814
- isWatched(name, _names) && _subjects.state.next({ ..._formState });
24815
- _subjects.values.next({
24816
- name: _state.mount ? name : undefined,
24817
- values: { ..._formValues },
24818
- });
24819
- };
24820
- const onChange = async (event) => {
24821
- _state.mount = true;
24822
- const target = event.target;
24823
- let name = target.name;
24824
- let isFieldValueUpdated = true;
24825
- const field = get(_fields, name);
24826
- const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
24827
- const _updateIsFieldValueUpdated = (fieldValue) => {
24828
- isFieldValueUpdated =
24829
- Number.isNaN(fieldValue) ||
24830
- fieldValue === get(_formValues, name, fieldValue);
24831
- };
24832
- if (field) {
24833
- let error;
24834
- let isValid;
24835
- const fieldValue = getCurrentFieldValue();
24836
- const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
24837
- const shouldSkipValidation = (!hasValidation(field._f) &&
24838
- !_options.resolver &&
24839
- !get(_formState.errors, name) &&
24840
- !field._f.deps) ||
24841
- skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
24842
- const watched = isWatched(name, _names, isBlurEvent);
24843
- set(_formValues, name, fieldValue);
24844
- if (isBlurEvent) {
24845
- field._f.onBlur && field._f.onBlur(event);
24846
- delayErrorCallback && delayErrorCallback(0);
24847
- }
24848
- else if (field._f.onChange) {
24849
- field._f.onChange(event);
24850
- }
24851
- const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
24852
- const shouldRender = !isEmptyObject(fieldState) || watched;
24853
- !isBlurEvent &&
24854
- _subjects.values.next({
24855
- name,
24856
- type: event.type,
24857
- values: { ..._formValues },
24858
- });
24859
- if (shouldSkipValidation) {
24860
- _proxyFormState.isValid && _updateValid();
24861
- return (shouldRender &&
24862
- _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
24863
- }
24864
- !isBlurEvent && watched && _subjects.state.next({ ..._formState });
24865
- if (_options.resolver) {
24866
- const { errors } = await _executeSchema([name]);
24867
- _updateIsFieldValueUpdated(fieldValue);
24868
- if (isFieldValueUpdated) {
24869
- const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
24870
- const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
24871
- error = errorLookupResult.error;
24872
- name = errorLookupResult.name;
24873
- isValid = isEmptyObject(errors);
24874
- }
24875
- }
24876
- else {
24877
- _updateIsValidating([name], true);
24878
- error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
24879
- _updateIsValidating([name]);
24880
- _updateIsFieldValueUpdated(fieldValue);
24881
- if (isFieldValueUpdated) {
24882
- if (error) {
24883
- isValid = false;
24884
- }
24885
- else if (_proxyFormState.isValid) {
24886
- isValid = await executeBuiltInValidation(_fields, true);
24887
- }
24888
- }
24889
- }
24890
- if (isFieldValueUpdated) {
24891
- field._f.deps &&
24892
- trigger(field._f.deps);
24893
- shouldRenderByError(name, isValid, error, fieldState);
24894
- }
24895
- }
24896
- };
24897
- const _focusInput = (ref, key) => {
24898
- if (get(_formState.errors, key) && ref.focus) {
24899
- ref.focus();
24900
- return 1;
24901
- }
24902
- return;
24903
- };
24904
- const trigger = async (name, options = {}) => {
24905
- let isValid;
24906
- let validationResult;
24907
- const fieldNames = convertToArrayPayload(name);
24908
- if (_options.resolver) {
24909
- const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
24910
- isValid = isEmptyObject(errors);
24911
- validationResult = name
24912
- ? !fieldNames.some((name) => get(errors, name))
24913
- : isValid;
24914
- }
24915
- else if (name) {
24916
- validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
24917
- const field = get(_fields, fieldName);
24918
- return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
24919
- }))).every(Boolean);
24920
- !(!validationResult && !_formState.isValid) && _updateValid();
24921
- }
24922
- else {
24923
- validationResult = isValid = await executeBuiltInValidation(_fields);
24924
- }
24925
- _subjects.state.next({
24926
- ...(!isString(name) ||
24927
- (_proxyFormState.isValid && isValid !== _formState.isValid)
24928
- ? {}
24929
- : { name }),
24930
- ...(_options.resolver || !name ? { isValid } : {}),
24931
- errors: _formState.errors,
24932
- });
24933
- options.shouldFocus &&
24934
- !validationResult &&
24935
- iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
24936
- return validationResult;
24937
- };
24938
- const getValues = (fieldNames) => {
24939
- const values = {
24940
- ...(_state.mount ? _formValues : _defaultValues),
24941
- };
24942
- return isUndefined(fieldNames)
24943
- ? values
24944
- : isString(fieldNames)
24945
- ? get(values, fieldNames)
24946
- : fieldNames.map((name) => get(values, name));
24947
- };
24948
- const getFieldState = (name, formState) => ({
24949
- invalid: !!get((formState || _formState).errors, name),
24950
- isDirty: !!get((formState || _formState).dirtyFields, name),
24951
- isTouched: !!get((formState || _formState).touchedFields, name),
24952
- isValidating: !!get((formState || _formState).validatingFields, name),
24953
- error: get((formState || _formState).errors, name),
24954
- });
24955
- const clearErrors = (name) => {
24956
- name &&
24957
- convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
24958
- _subjects.state.next({
24959
- errors: name ? _formState.errors : {},
24960
- });
24961
- };
24962
- const setError = (name, error, options) => {
24963
- const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
24964
- const currentError = get(_formState.errors, name) || {};
24965
- // Don't override existing error messages elsewhere in the object tree.
24966
- const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
24967
- set(_formState.errors, name, {
24968
- ...restOfErrorTree,
24969
- ...error,
24970
- ref,
24971
- });
24972
- _subjects.state.next({
24973
- name,
24974
- errors: _formState.errors,
24975
- isValid: false,
24976
- });
24977
- options && options.shouldFocus && ref && ref.focus && ref.focus();
24978
- };
24979
- const watch = (name, defaultValue) => isFunction(name)
24980
- ? _subjects.values.subscribe({
24981
- next: (payload) => name(_getWatch(undefined, defaultValue), payload),
24982
- })
24983
- : _getWatch(name, defaultValue, true);
24984
- const unregister = (name, options = {}) => {
24985
- for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
24986
- _names.mount.delete(fieldName);
24987
- _names.array.delete(fieldName);
24988
- if (!options.keepValue) {
24989
- unset(_fields, fieldName);
24990
- unset(_formValues, fieldName);
24991
- }
24992
- !options.keepError && unset(_formState.errors, fieldName);
24993
- !options.keepDirty && unset(_formState.dirtyFields, fieldName);
24994
- !options.keepTouched && unset(_formState.touchedFields, fieldName);
24995
- !options.keepIsValidating &&
24996
- unset(_formState.validatingFields, fieldName);
24997
- !_options.shouldUnregister &&
24998
- !options.keepDefaultValue &&
24999
- unset(_defaultValues, fieldName);
25000
- }
25001
- _subjects.values.next({
25002
- values: { ..._formValues },
25003
- });
25004
- _subjects.state.next({
25005
- ..._formState,
25006
- ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
25007
- });
25008
- !options.keepIsValid && _updateValid();
25009
- };
25010
- const _updateDisabledField = ({ disabled, name, field, fields, value, }) => {
25011
- if ((isBoolean(disabled) && _state.mount) || !!disabled) {
25012
- const inputValue = disabled
25013
- ? undefined
25014
- : isUndefined(value)
25015
- ? getFieldValue(field ? field._f : get(fields, name)._f)
25016
- : value;
25017
- set(_formValues, name, inputValue);
25018
- updateTouchAndDirty(name, inputValue, false, false, true);
25019
- }
25020
- };
25021
- const register = (name, options = {}) => {
25022
- let field = get(_fields, name);
25023
- const disabledIsDefined = isBoolean(options.disabled);
25024
- set(_fields, name, {
25025
- ...(field || {}),
25026
- _f: {
25027
- ...(field && field._f ? field._f : { ref: { name } }),
25028
- name,
25029
- mount: true,
25030
- ...options,
25031
- },
25032
- });
25033
- _names.mount.add(name);
25034
- if (field) {
25035
- _updateDisabledField({
25036
- field,
25037
- disabled: options.disabled,
25038
- name,
25039
- value: options.value,
25040
- });
25041
- }
25042
- else {
25043
- updateValidAndValue(name, true, options.value);
25044
- }
25045
- return {
25046
- ...(disabledIsDefined ? { disabled: options.disabled } : {}),
25047
- ...(_options.progressive
25048
- ? {
25049
- required: !!options.required,
25050
- min: getRuleValue(options.min),
25051
- max: getRuleValue(options.max),
25052
- minLength: getRuleValue(options.minLength),
25053
- maxLength: getRuleValue(options.maxLength),
25054
- pattern: getRuleValue(options.pattern),
25055
- }
25056
- : {}),
25057
- name,
25058
- onChange,
25059
- onBlur: onChange,
25060
- ref: (ref) => {
25061
- if (ref) {
25062
- register(name, options);
25063
- field = get(_fields, name);
25064
- const fieldRef = isUndefined(ref.value)
25065
- ? ref.querySelectorAll
25066
- ? ref.querySelectorAll('input,select,textarea')[0] || ref
25067
- : ref
25068
- : ref;
25069
- const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
25070
- const refs = field._f.refs || [];
25071
- if (radioOrCheckbox
25072
- ? refs.find((option) => option === fieldRef)
25073
- : fieldRef === field._f.ref) {
25074
- return;
25075
- }
25076
- set(_fields, name, {
25077
- _f: {
25078
- ...field._f,
25079
- ...(radioOrCheckbox
25080
- ? {
25081
- refs: [
25082
- ...refs.filter(live),
25083
- fieldRef,
25084
- ...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
25085
- ],
25086
- ref: { type: fieldRef.type, name },
25087
- }
25088
- : { ref: fieldRef }),
25089
- },
25090
- });
25091
- updateValidAndValue(name, false, undefined, fieldRef);
25092
- }
25093
- else {
25094
- field = get(_fields, name, {});
25095
- if (field._f) {
25096
- field._f.mount = false;
25097
- }
25098
- (_options.shouldUnregister || options.shouldUnregister) &&
25099
- !(isNameInFieldArray(_names.array, name) && _state.action) &&
25100
- _names.unMount.add(name);
25101
- }
25102
- },
25103
- };
25104
- };
25105
- const _focusError = () => _options.shouldFocusError &&
25106
- iterateFieldsByAction(_fields, _focusInput, _names.mount);
25107
- const _disableForm = (disabled) => {
25108
- if (isBoolean(disabled)) {
25109
- _subjects.state.next({ disabled });
25110
- iterateFieldsByAction(_fields, (ref, name) => {
25111
- const currentField = get(_fields, name);
25112
- if (currentField) {
25113
- ref.disabled = currentField._f.disabled || disabled;
25114
- if (Array.isArray(currentField._f.refs)) {
25115
- currentField._f.refs.forEach((inputRef) => {
25116
- inputRef.disabled = currentField._f.disabled || disabled;
25117
- });
25118
- }
25119
- }
25120
- }, 0, false);
25121
- }
25122
- };
25123
- const handleSubmit = (onValid, onInvalid) => async (e) => {
25124
- let onValidError = undefined;
25125
- if (e) {
25126
- e.preventDefault && e.preventDefault();
25127
- e.persist && e.persist();
25128
- }
25129
- let fieldValues = cloneObject(_formValues);
25130
- _subjects.state.next({
25131
- isSubmitting: true,
25132
- });
25133
- if (_options.resolver) {
25134
- const { errors, values } = await _executeSchema();
25135
- _formState.errors = errors;
25136
- fieldValues = values;
25137
- }
25138
- else {
25139
- await executeBuiltInValidation(_fields);
25140
- }
25141
- unset(_formState.errors, 'root');
25142
- if (isEmptyObject(_formState.errors)) {
25143
- _subjects.state.next({
25144
- errors: {},
25145
- });
25146
- try {
25147
- await onValid(fieldValues, e);
25148
- }
25149
- catch (error) {
25150
- onValidError = error;
25151
- }
25152
- }
25153
- else {
25154
- if (onInvalid) {
25155
- await onInvalid({ ..._formState.errors }, e);
25156
- }
25157
- _focusError();
25158
- setTimeout(_focusError);
25159
- }
25160
- _subjects.state.next({
25161
- isSubmitted: true,
25162
- isSubmitting: false,
25163
- isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
25164
- submitCount: _formState.submitCount + 1,
25165
- errors: _formState.errors,
25166
- });
25167
- if (onValidError) {
25168
- throw onValidError;
25169
- }
25170
- };
25171
- const resetField = (name, options = {}) => {
25172
- if (get(_fields, name)) {
25173
- if (isUndefined(options.defaultValue)) {
25174
- setValue(name, cloneObject(get(_defaultValues, name)));
25175
- }
25176
- else {
25177
- setValue(name, options.defaultValue);
25178
- set(_defaultValues, name, cloneObject(options.defaultValue));
25179
- }
25180
- if (!options.keepTouched) {
25181
- unset(_formState.touchedFields, name);
25182
- }
25183
- if (!options.keepDirty) {
25184
- unset(_formState.dirtyFields, name);
25185
- _formState.isDirty = options.defaultValue
25186
- ? _getDirty(name, cloneObject(get(_defaultValues, name)))
25187
- : _getDirty();
25188
- }
25189
- if (!options.keepError) {
25190
- unset(_formState.errors, name);
25191
- _proxyFormState.isValid && _updateValid();
25192
- }
25193
- _subjects.state.next({ ..._formState });
25194
- }
25195
- };
25196
- const _reset = (formValues, keepStateOptions = {}) => {
25197
- const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
25198
- const cloneUpdatedValues = cloneObject(updatedValues);
25199
- const isEmptyResetValues = isEmptyObject(formValues);
25200
- const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;
25201
- if (!keepStateOptions.keepDefaultValues) {
25202
- _defaultValues = updatedValues;
25203
- }
25204
- if (!keepStateOptions.keepValues) {
25205
- if (keepStateOptions.keepDirtyValues) {
25206
- for (const fieldName of _names.mount) {
25207
- get(_formState.dirtyFields, fieldName)
25208
- ? set(values, fieldName, get(_formValues, fieldName))
25209
- : setValue(fieldName, get(values, fieldName));
25210
- }
25211
- }
25212
- else {
25213
- if (isWeb && isUndefined(formValues)) {
25214
- for (const name of _names.mount) {
25215
- const field = get(_fields, name);
25216
- if (field && field._f) {
25217
- const fieldReference = Array.isArray(field._f.refs)
25218
- ? field._f.refs[0]
25219
- : field._f.ref;
25220
- if (isHTMLElement(fieldReference)) {
25221
- const form = fieldReference.closest('form');
25222
- if (form) {
25223
- form.reset();
25224
- break;
25225
- }
25226
- }
25227
- }
25228
- }
25229
- }
25230
- _fields = {};
25231
- }
25232
- _formValues = props.shouldUnregister
25233
- ? keepStateOptions.keepDefaultValues
25234
- ? cloneObject(_defaultValues)
25235
- : {}
25236
- : cloneObject(values);
25237
- _subjects.array.next({
25238
- values: { ...values },
25239
- });
25240
- _subjects.values.next({
25241
- values: { ...values },
25242
- });
25243
- }
25244
- _names = {
25245
- mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
25246
- unMount: new Set(),
25247
- array: new Set(),
25248
- watch: new Set(),
25249
- watchAll: false,
25250
- focus: '',
25251
- };
25252
- _state.mount =
25253
- !_proxyFormState.isValid ||
25254
- !!keepStateOptions.keepIsValid ||
25255
- !!keepStateOptions.keepDirtyValues;
25256
- _state.watch = !!props.shouldUnregister;
25257
- _subjects.state.next({
25258
- submitCount: keepStateOptions.keepSubmitCount
25259
- ? _formState.submitCount
25260
- : 0,
25261
- isDirty: isEmptyResetValues
25262
- ? false
25263
- : keepStateOptions.keepDirty
25264
- ? _formState.isDirty
25265
- : !!(keepStateOptions.keepDefaultValues &&
25266
- !deepEqual(formValues, _defaultValues)),
25267
- isSubmitted: keepStateOptions.keepIsSubmitted
25268
- ? _formState.isSubmitted
25269
- : false,
25270
- dirtyFields: isEmptyResetValues
25271
- ? []
25272
- : keepStateOptions.keepDirtyValues
25273
- ? keepStateOptions.keepDefaultValues && _formValues
25274
- ? getDirtyFields(_defaultValues, _formValues)
25275
- : _formState.dirtyFields
25276
- : keepStateOptions.keepDefaultValues && formValues
25277
- ? getDirtyFields(_defaultValues, formValues)
25278
- : {},
25279
- touchedFields: keepStateOptions.keepTouched
25280
- ? _formState.touchedFields
25281
- : {},
25282
- errors: keepStateOptions.keepErrors ? _formState.errors : {},
25283
- isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
25284
- ? _formState.isSubmitSuccessful
25285
- : false,
25286
- isSubmitting: false,
25287
- });
25288
- };
25289
- const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
25290
- ? formValues(_formValues)
25291
- : formValues, keepStateOptions);
25292
- const setFocus = (name, options = {}) => {
25293
- const field = get(_fields, name);
25294
- const fieldReference = field && field._f;
25295
- if (fieldReference) {
25296
- const fieldRef = fieldReference.refs
25297
- ? fieldReference.refs[0]
25298
- : fieldReference.ref;
25299
- if (fieldRef.focus) {
25300
- fieldRef.focus();
25301
- options.shouldSelect && fieldRef.select();
25302
- }
25303
- }
25304
- };
25305
- const _updateFormState = (updatedFormState) => {
25306
- _formState = {
25307
- ..._formState,
25308
- ...updatedFormState,
25309
- };
25310
- };
25311
- const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
25312
- _options.defaultValues().then((values) => {
25313
- reset(values, _options.resetOptions);
25314
- _subjects.state.next({
25315
- isLoading: false,
25316
- });
25317
- });
25318
- return {
25319
- control: {
25320
- register,
25321
- unregister,
25322
- getFieldState,
25323
- handleSubmit,
25324
- setError,
25325
- _executeSchema,
25326
- _getWatch,
25327
- _getDirty,
25328
- _updateValid,
25329
- _removeUnmounted,
25330
- _updateFieldArray,
25331
- _updateDisabledField,
25332
- _getFieldArray,
25333
- _reset,
25334
- _resetDefaultValues,
25335
- _updateFormState,
25336
- _disableForm,
25337
- _subjects,
25338
- _proxyFormState,
25339
- _setErrors,
25340
- get _fields() {
25341
- return _fields;
25342
- },
25343
- get _formValues() {
25344
- return _formValues;
25345
- },
25346
- get _state() {
25347
- return _state;
25348
- },
25349
- set _state(value) {
25350
- _state = value;
25351
- },
25352
- get _defaultValues() {
25353
- return _defaultValues;
25354
- },
25355
- get _names() {
25356
- return _names;
25357
- },
25358
- set _names(value) {
25359
- _names = value;
25360
- },
25361
- get _formState() {
25362
- return _formState;
25363
- },
25364
- set _formState(value) {
25365
- _formState = value;
25366
- },
25367
- get _options() {
25368
- return _options;
25369
- },
25370
- set _options(value) {
25371
- _options = {
25372
- ..._options,
25373
- ...value,
25374
- };
25375
- },
25376
- },
25377
- trigger,
25378
- register,
25379
- handleSubmit,
25380
- watch,
25381
- setValue,
25382
- getValues,
25383
- reset,
25384
- resetField,
25385
- clearErrors,
25386
- unregister,
25387
- setError,
25388
- setFocus,
25389
- getFieldState,
25390
- };
25391
- }
25392
-
25393
- /**
25394
- * Custom hook to manage the entire form.
25395
- *
25396
- * @remarks
25397
- * [API](https://react-hook-form.com/docs/useform) • [Demo](https://codesandbox.io/s/react-hook-form-get-started-ts-5ksmm) • [Video](https://www.youtube.com/watch?v=RkXv4AXXC_4)
25398
- *
25399
- * @param props - form configuration and validation parameters.
25400
- *
25401
- * @returns methods - individual functions to manage the form state. {@link UseFormReturn}
25402
- *
25403
- * @example
25404
- * ```tsx
25405
- * function App() {
25406
- * const { register, handleSubmit, watch, formState: { errors } } = useForm();
25407
- * const onSubmit = data => console.log(data);
25408
- *
25409
- * console.log(watch("example"));
25410
- *
25411
- * return (
25412
- * <form onSubmit={handleSubmit(onSubmit)}>
25413
- * <input defaultValue="test" {...register("example")} />
25414
- * <input {...register("exampleRequired", { required: true })} />
25415
- * {errors.exampleRequired && <span>This field is required</span>}
25416
- * <button>Submit</button>
25417
- * </form>
25418
- * );
25419
- * }
25420
- * ```
25421
- */
25422
- function useForm(props = {}) {
25423
- const _formControl = React$1.useRef();
25424
- const _values = React$1.useRef();
25425
- const [formState, updateFormState] = React$1.useState({
25426
- isDirty: false,
25427
- isValidating: false,
25428
- isLoading: isFunction(props.defaultValues),
25429
- isSubmitted: false,
25430
- isSubmitting: false,
25431
- isSubmitSuccessful: false,
25432
- isValid: false,
25433
- submitCount: 0,
25434
- dirtyFields: {},
25435
- touchedFields: {},
25436
- validatingFields: {},
25437
- errors: props.errors || {},
25438
- disabled: props.disabled || false,
25439
- defaultValues: isFunction(props.defaultValues)
25440
- ? undefined
25441
- : props.defaultValues,
25442
- });
25443
- if (!_formControl.current) {
25444
- _formControl.current = {
25445
- ...createFormControl(props),
25446
- formState,
25447
- };
25448
- }
25449
- const control = _formControl.current.control;
25450
- control._options = props;
25451
- useSubscribe({
25452
- subject: control._subjects.state,
25453
- next: (value) => {
25454
- if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
25455
- updateFormState({ ...control._formState });
25456
- }
25457
- },
25458
- });
25459
- React$1.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
25460
- React$1.useEffect(() => {
25461
- if (control._proxyFormState.isDirty) {
25462
- const isDirty = control._getDirty();
25463
- if (isDirty !== formState.isDirty) {
25464
- control._subjects.state.next({
25465
- isDirty,
25466
- });
25467
- }
25468
- }
25469
- }, [control, formState.isDirty]);
25470
- React$1.useEffect(() => {
25471
- if (props.values && !deepEqual(props.values, _values.current)) {
25472
- control._reset(props.values, control._options.resetOptions);
25473
- _values.current = props.values;
25474
- updateFormState((state) => ({ ...state }));
25475
- }
25476
- else {
25477
- control._resetDefaultValues();
25478
- }
25479
- }, [props.values, control]);
25480
- React$1.useEffect(() => {
25481
- if (props.errors) {
25482
- control._setErrors(props.errors);
25483
- }
25484
- }, [props.errors, control]);
25485
- React$1.useEffect(() => {
25486
- if (!control._state.mount) {
25487
- control._updateValid();
25488
- control._state.mount = true;
25489
- }
25490
- if (control._state.watch) {
25491
- control._state.watch = false;
25492
- control._subjects.state.next({ ...control._formState });
25493
- }
25494
- control._removeUnmounted();
25495
- });
25496
- React$1.useEffect(() => {
25497
- props.shouldUnregister &&
25498
- control._subjects.values.next({
25499
- values: control._getWatch(),
25500
- });
25501
- }, [props.shouldUnregister, control]);
25502
- _formControl.current.formState = getProxyFormState(formState, control);
25503
- return _formControl.current;
25504
- }
25505
-
25506
- var s$1=function(s){var t=s.as,a=s.errors,m=s.name,o=s.message,i=s.render,l=function(e,r){if(null==e)return {};var n,s,t={},a=Object.keys(e);for(s=0;s<a.length;s++)r.indexOf(n=a[s])>=0||(t[n]=e[n]);return t}(s,["as","errors","name","message","render"]),f=useFormContext(),c=get(a||f.formState.errors,m);if(!c)return null;var g=c.message,u=c.types,d=Object.assign({},l,{children:g||o});return React__namespace.isValidElement(t)?React__namespace.cloneElement(t,d):i?i({message:g||o,messages:u}):React__namespace.createElement(t||React__namespace.Fragment,d)};
23881
+ var s=function(s){var t=s.as,a=s.errors,m=s.name,o=s.message,i=s.render,l=function(e,r){if(null==e)return {};var n,s,t={},a=Object.keys(e);for(s=0;s<a.length;s++)r.indexOf(n=a[s])>=0||(t[n]=e[n]);return t}(s,["as","errors","name","message","render"]),f=useFormContext(),c=get(a||f.formState.errors,m);if(!c)return null;var g=c.message,u=c.types,d=Object.assign({},l,{children:g||o});return React__namespace.isValidElement(t)?React__namespace.cloneElement(t,d):i?i({message:g||o,messages:u}):React__namespace.createElement(t||React__namespace.Fragment,d)};
25507
23882
 
25508
23883
  // TODO: remove this export once ClassNameGenerator is stable
25509
23884
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -42466,7 +40841,7 @@ function MultiSelectV1({ props }) {
42466
40841
  } }), jsxRuntimeExports.jsx(ListItemText, { primary: "Select All", sx: { fontSize: "5px" } })] })), (filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.length) !== 0 ? (filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.map((name) => {
42467
40842
  var _a;
42468
40843
  return (jsxRuntimeExports.jsxs(MenuItem, Object.assign({ value: name, sx: { zIndex: 0, fontSize: "5px !important" } }, { children: [jsxRuntimeExports.jsx(Checkbox, { checked: ((_a = extractValuesToArray(fieldValue)) === null || _a === void 0 ? void 0 : _a.indexOf(name)) > -1, size: "small" }), jsxRuntimeExports.jsx(ListItemText, { primary: name, sx: { fontSize: "5px" } })] }), name));
42469
- })) : (jsxRuntimeExports.jsx(MenuItem, Object.assign({ disabled: true, value: "NA" }, { children: "No data Found" }), "NA"))] })), jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name, render: ({ message }) => (jsxRuntimeExports.jsx(ErrorMessageComponent, { children: message })) })] })) }));
40844
+ })) : (jsxRuntimeExports.jsx(MenuItem, Object.assign({ disabled: true, value: "NA" }, { children: "No data Found" }), "NA"))] })), jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name, render: ({ message }) => (jsxRuntimeExports.jsx(ErrorMessageComponent, { children: message })) })] })) }));
42470
40845
  }
42471
40846
 
42472
40847
  var dayjs_min = {exports: {}};
@@ -43826,7 +42201,7 @@ function isSameDay(dateLeft, dateRight) {
43826
42201
  * const result = isDate({})
43827
42202
  * //=> false
43828
42203
  */
43829
- function isDate$1(value) {
42204
+ function isDate(value) {
43830
42205
  return (
43831
42206
  value instanceof Date ||
43832
42207
  (typeof value === "object" &&
@@ -43868,7 +42243,7 @@ function isDate$1(value) {
43868
42243
  * //=> false
43869
42244
  */
43870
42245
  function isValid(date) {
43871
- if (!isDate$1(date) && typeof date !== "number") {
42246
+ if (!isDate(date) && typeof date !== "number") {
43872
42247
  return false;
43873
42248
  }
43874
42249
  const _date = toDate(date);
@@ -44498,7 +42873,7 @@ function buildMatchFn(args) {
44498
42873
  args.parsePatterns[args.defaultParseWidth];
44499
42874
 
44500
42875
  const key = Array.isArray(parsePatterns)
44501
- ? findIndex$1(parsePatterns, (pattern) => pattern.test(matchedString))
42876
+ ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
44502
42877
  : // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type
44503
42878
  findKey(parsePatterns, (pattern) => pattern.test(matchedString));
44504
42879
 
@@ -44528,7 +42903,7 @@ function findKey(object, predicate) {
44528
42903
  return undefined;
44529
42904
  }
44530
42905
 
44531
- function findIndex$1(array, predicate) {
42906
+ function findIndex(array, predicate) {
44532
42907
  for (let key = 0; key < array.length; key++) {
44533
42908
  if (predicate(array[key])) {
44534
42909
  return key;
@@ -47383,6 +45758,7 @@ const DateRangePickerComponent = ({ props }) => {
47383
45758
  setOpen(false);
47384
45759
  }
47385
45760
  }, [props.getValues('ToDate')]);
45761
+ console.log(props.getValues('ToDate'), 'props.getValues');
47386
45762
  console.log(props.getValues('FromDate'), props.getValues('FromDate'), 'from date range picker');
47387
45763
  const value = props.getValues('FromDate') && props.getValues('ToDate')
47388
45764
  ? `${props.getValues('FromDate')} - ${props.getValues('ToDate')}`
@@ -47393,7 +45769,7 @@ const DateRangePickerComponent = ({ props }) => {
47393
45769
  "& .css-1holvmy, .css-kichxs-MuiFormLabel-root-MuiInputLabel-root": {
47394
45770
  top: "-10px",
47395
45771
  },
47396
- } }, { children: [jsxRuntimeExports.jsx(TextField, { label: props.item.label, value: value, className: "read-only", inputRef: textRef, sx: { width: '100%', '& input': { cursor: 'pointer' } }, onClick: () => {
45772
+ } }, { children: [jsxRuntimeExports.jsx(TextField, { label: props.item.label, value: value || null, className: "read-only", inputRef: textRef, sx: { width: '100%', '& input': { cursor: 'pointer' } }, onClick: () => {
47397
45773
  setOpen(true);
47398
45774
  } }), open && (jsxRuntimeExports.jsx(Box, Object.assign({ sx: {
47399
45775
  position: "absolute",
@@ -47538,7 +45914,7 @@ function createRule(name, decl, options) {
47538
45914
  return null;
47539
45915
  }
47540
45916
 
47541
- var join$1 = function join(value, by) {
45917
+ var join = function join(value, by) {
47542
45918
  var result = '';
47543
45919
 
47544
45920
  for (var i = 0; i < value.length; i++) {
@@ -47568,9 +45944,9 @@ var toCssValue = function toCssValue(value) {
47568
45944
  for (var i = 0; i < value.length; i++) {
47569
45945
  if (value[i] === '!important') break;
47570
45946
  if (cssValue) cssValue += ', ';
47571
- cssValue += join$1(value[i], ' ');
45947
+ cssValue += join(value[i], ' ');
47572
45948
  }
47573
- } else cssValue = join$1(value, ', '); // Add !important, because it was ignored.
45949
+ } else cssValue = join(value, ', '); // Add !important, because it was ignored.
47574
45950
 
47575
45951
 
47576
45952
  if (value[value.length - 1] === '!important') {
@@ -50106,7 +48482,7 @@ function convertCase(style) {
50106
48482
  */
50107
48483
 
50108
48484
 
50109
- function camelCase$1() {
48485
+ function camelCase() {
50110
48486
  function onProcessStyle(style) {
50111
48487
  if (Array.isArray(style)) {
50112
48488
  // Handle rules like @font-face, which can have multiple styles in an array
@@ -51069,7 +49445,7 @@ function jssPropsSort() {
51069
49445
  // Subset of jss-preset-default with only the plugins the MUI components are using.
51070
49446
  function jssPreset() {
51071
49447
  return {
51072
- plugins: [functionPlugin(), jssGlobal(), jssNested(), camelCase$1(), defaultUnit(),
49448
+ plugins: [functionPlugin(), jssGlobal(), jssNested(), camelCase(), defaultUnit(),
51073
49449
  // Disable the vendor prefixer server-side, it does nothing.
51074
49450
  // This way, we can get a performance boost.
51075
49451
  // In the documentation, we are using `autoprefixer` to solve this problem.
@@ -51638,7 +50014,7 @@ const SingleSelect = ({ props }) => {
51638
50014
  },
51639
50015
  }, getOptionLabel: (option) => option.label, renderInput: (params) => {
51640
50016
  return (jsxRuntimeExports.jsx(Tooltip, Object.assign({ title: params.inputProps.value && params.inputProps.value }, { children: jsxRuntimeExports.jsx(TextField, Object.assign({}, params, { placeholder: props.item.Placeholder, label: props.item.label })) })));
51641
- }, isOptionEqualToValue: isOptionEqualToValue })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] }));
50017
+ }, isOptionEqualToValue: isOptionEqualToValue })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] }));
51642
50018
  } }));
51643
50019
  };
51644
50020
 
@@ -51655,7 +50031,7 @@ const PasswordField = ({ props }) => {
51655
50031
  const handleTogglePasswordVisibility = () => {
51656
50032
  setShowPassword((prevShowPassword) => !prevShowPassword);
51657
50033
  };
51658
- return (jsxRuntimeExports.jsxs(FormControl, Object.assign({ fullWidth: true }, { children: [" ", jsxRuntimeExports.jsx(Controller, { control: props.control, name: props.item.name, render: ({ field }) => (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs(Box, Object.assign({ sx: { position: 'relative' } }, { children: [" ", jsxRuntimeExports.jsx(TextField, Object.assign({ type: showPassword ? "text" : "password" }, field, { label: props.item.label, sx: {
50034
+ return (jsxRuntimeExports.jsxs(FormControl, Object.assign({ fullWidth: true }, { children: [" ", jsxRuntimeExports.jsx(Controller, { control: props.control, name: props.item.name, render: ({ field }) => (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs(Box, Object.assign({ sx: { position: "relative" } }, { children: [" ", jsxRuntimeExports.jsx(TextField, Object.assign({ size: "small", type: showPassword ? "text" : "password" }, field, { label: props.item.label, sx: {
51659
50035
  width: "100%",
51660
50036
  "& .css-kichxs-MuiFormLabel-root-MuiInputLabel-root,.css-1holvmy": {
51661
50037
  top: "-8px",
@@ -51665,7 +50041,17 @@ const PasswordField = ({ props }) => {
51665
50041
  right: "14px",
51666
50042
  top: "50%",
51667
50043
  transform: "translateY(-50%)",
51668
- }, "aria-label": "toggle password visibility", onClick: handleTogglePasswordVisibility, edge: "end" }, { children: showPassword ? (jsxRuntimeExports.jsx(Visibility, { sx: { fontSize: "12px", position: 'absolute', top: '22%', right: 10 } })) : (jsxRuntimeExports.jsx(VisibilityOff, { sx: { fontSize: "12px", position: 'absolute', top: '22%', right: 10 } })) }))] })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] })) })] })));
50044
+ }, "aria-label": "toggle password visibility", onClick: handleTogglePasswordVisibility, edge: "end" }, { children: showPassword ? (jsxRuntimeExports.jsx(Visibility, { sx: {
50045
+ fontSize: "12px",
50046
+ position: "absolute",
50047
+ top: "22%",
50048
+ right: 10,
50049
+ } })) : (jsxRuntimeExports.jsx(VisibilityOff, { sx: {
50050
+ fontSize: "12px",
50051
+ position: "absolute",
50052
+ top: "22%",
50053
+ right: 10,
50054
+ } })) }))] })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] })) })] })));
51669
50055
  };
51670
50056
 
51671
50057
  const Monthpickerrender = ({ props }) => {
@@ -51734,7 +50120,7 @@ const Monthpickerrender = ({ props }) => {
51734
50120
  fontFamily: "Roboto-Reg",
51735
50121
  fontSize: "11px",
51736
50122
  color: "#3651d3",
51737
- } }, { children: ["(", (_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.helperText, ")"] }))), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] }));
50123
+ } }, { children: ["(", (_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.helperText, ")"] }))), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] }));
51738
50124
  } }));
51739
50125
  };
51740
50126
 
@@ -51764,7 +50150,7 @@ const DatepickerWrapperV2 = ({ props }) => {
51764
50150
  // onFocus: () => inputTextRef.current?.blur(),
51765
50151
  },
51766
50152
  }, sx: {
51767
- "& .css-lqj8pz-MuiFormLabel-root-MuiInputLabel-root,.css-zy8vme,.css-1holvmy": {
50153
+ "& .css-lqj8pz-MuiFormLabel-root-MuiInputLabel-root,.css-zy8vme,.css-1holvmy,.css-kichxs-MuiFormLabel-root-MuiInputLabel-root": {
51768
50154
  top: "-10px !important",
51769
50155
  },
51770
50156
  "& input:hover": {
@@ -51774,7 +50160,7 @@ const DatepickerWrapperV2 = ({ props }) => {
51774
50160
  fontFamily: "Roboto-Reg",
51775
50161
  fontSize: "11px",
51776
50162
  color: "#3651d3",
51777
- } }, { children: ["(", (_d = props === null || props === void 0 ? void 0 : props.item) === null || _d === void 0 ? void 0 : _d.helperText, ")"] }))), !(props === null || props === void 0 ? void 0 : props.getValues(props.item.name)) && (jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) }))] }));
50163
+ } }, { children: ["(", (_d = props === null || props === void 0 ? void 0 : props.item) === null || _d === void 0 ? void 0 : _d.helperText, ")"] }))), !(props === null || props === void 0 ? void 0 : props.getValues(props.item.name)) && (jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) }))] }));
51778
50164
  } }));
51779
50165
  };
51780
50166
 
@@ -51795,7 +50181,7 @@ const FormRenderFileUpload = ({ props }) => {
51795
50181
  [props.item.name]: file,
51796
50182
  [props.item.name + "Name"]: fileName,
51797
50183
  });
51798
- }, sx: { width: "100%" } }) })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] }));
50184
+ }, sx: { width: "100%" } }) })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] }));
51799
50185
  };
51800
50186
 
51801
50187
  const useStyles = makeStyles((theme) => ({
@@ -51818,7 +50204,7 @@ const SingleSelectNonAutoComplete = ({ props }) => {
51818
50204
  fontSize: "11px",
51819
50205
  fontFamily: "Roboto-Reg",
51820
50206
  zIndex: 2000,
51821
- }, value: item.value }, { children: item.label })))) })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] })));
50207
+ }, value: item.value }, { children: item.label })))) })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] })));
51822
50208
  };
51823
50209
 
51824
50210
  function formatDateMonthAndYear(date) {
@@ -51865,11 +50251,11 @@ const RenderForm = (props) => {
51865
50251
  },
51866
50252
  },
51867
50253
  // classes={{ option: { color: "red !important" } }}
51868
- value: field.value || "", disabled: props.item.disable })), ((_a = props === null || props === void 0 ? void 0 : props.item) === null || _a === void 0 ? void 0 : _a.helperText) && (jsxRuntimeExports.jsxs("span", Object.assign({ style: {
50254
+ value: field.value || "", size: "small", disabled: props.item.disable })), ((_a = props === null || props === void 0 ? void 0 : props.item) === null || _a === void 0 ? void 0 : _a.helperText) && (jsxRuntimeExports.jsxs("span", Object.assign({ style: {
51869
50255
  fontFamily: "Roboto-Reg",
51870
50256
  fontSize: "11px",
51871
50257
  color: "#3651d3",
51872
- } }, { children: ["(", (_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.helperText, ")"] }))), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] }));
50258
+ } }, { children: ["(", (_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.helperText, ")"] }))), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] }));
51873
50259
  } }) }));
51874
50260
  case "register-number":
51875
50261
  return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: jsxRuntimeExports.jsx(Controller, { control: props.control, name: props.item.name, render: ({ field }) => {
@@ -51880,7 +50266,9 @@ const RenderForm = (props) => {
51880
50266
  border: "none",
51881
50267
  },
51882
50268
  }, onInput: (e) => {
51883
- e.target.value = e.target.value.replace(/\s/g, "").replace(/[^a-zA-Z0-9!@#$%^&*()_+{}\[\]:;<>,.?/~`|\\-]/g, '');
50269
+ e.target.value = e.target.value
50270
+ .replace(/\s/g, "")
50271
+ .replace(/[^a-zA-Z0-9!@#$%^&*()_+{}\[\]:;<>,.?/~`|\\-]/g, "");
51884
50272
  }, sx: {
51885
50273
  fontFamily: "Roboto-Reg",
51886
50274
  "& .css-1holvmy,.css-lqj8pz-MuiFormLabel-root-MuiInputLabel-root, .css-kichxs-MuiFormLabel-root-MuiInputLabel-root": {
@@ -51908,7 +50296,7 @@ const RenderForm = (props) => {
51908
50296
  fontFamily: "Roboto-Reg",
51909
50297
  fontSize: "11px",
51910
50298
  color: "#3651d3",
51911
- } }, { children: ["(", (_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.helperText, ")"] }))), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] }));
50299
+ } }, { children: ["(", (_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.helperText, ")"] }))), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] }));
51912
50300
  } }) }));
51913
50301
  case "password":
51914
50302
  return (jsxRuntimeExports.jsx(Box, Object.assign({ position: "relative" }, { children: jsxRuntimeExports.jsx(PasswordField, { props: props }) })));
@@ -51924,10 +50312,11 @@ const RenderForm = (props) => {
51924
50312
  // );
51925
50313
  case "number":
51926
50314
  return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: jsxRuntimeExports.jsx(Controller, { control: props.control, name: props.item.name, render: ({ field }) => {
51927
- return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(TextField, Object.assign({}, field, { label: props.item.label, value: props.getValues(props.item.name) || "", defaultValue: props.getValues(props.item.name) || null, onInput: (e) => {
50315
+ return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(TextField, Object.assign({}, field, { size: "small", label: props.item.label, value: props.getValues(props.item.name) || "", defaultValue: props.getValues(props.item.name) || null, onInput: (e) => {
51928
50316
  var _a, _b;
51929
50317
  e.target.value = e.target.value.replace(/[^0-9]/g, "");
51930
- ((_a = props === null || props === void 0 ? void 0 : props.item) === null || _a === void 0 ? void 0 : _a.onChangeFn) && ((_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.onChangeFn(e.target.value));
50318
+ ((_a = props === null || props === void 0 ? void 0 : props.item) === null || _a === void 0 ? void 0 : _a.onChangeFn) &&
50319
+ ((_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.onChangeFn(e.target.value));
51931
50320
  (props === null || props === void 0 ? void 0 : props.clearErrors) && (props === null || props === void 0 ? void 0 : props.clearErrors(props.item.name));
51932
50321
  }, sx: {
51933
50322
  "& .css-1holvmy,.css-lqj8pz-MuiFormLabel-root-MuiInputLabel-root,.css-kichxs-MuiFormLabel-root-MuiInputLabel-root": {
@@ -51936,7 +50325,7 @@ const RenderForm = (props) => {
51936
50325
  }, inputProps: {
51937
50326
  pattern: "[0-9]*",
51938
50327
  maxLength: props.item.maxLength || 20,
51939
- }, disabled: props.item.disable })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] }));
50328
+ }, disabled: props.item.disable })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] }));
51940
50329
  } }) }));
51941
50330
  case "decimal":
51942
50331
  return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: jsxRuntimeExports.jsx(Controller, { name: props.item.name, control: props.control, disabled: (_b = props.item) === null || _b === void 0 ? void 0 : _b.disable, render: ({ field }) => (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(TextField, Object.assign({ type: "text", size: "small", label: props.item.label }, field, { onChange: (e) => (props === null || props === void 0 ? void 0 : props.clearErrors) && (props === null || props === void 0 ? void 0 : props.clearErrors(props.item.name)), sx: {
@@ -51964,7 +50353,7 @@ const RenderForm = (props) => {
51964
50353
  pattern: "[1-9]",
51965
50354
  maxLength: 7,
51966
50355
  },
51967
- } })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] })) }) }));
50356
+ } })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] })) }) }));
51968
50357
  // case "alpha-numerical":
51969
50358
  // return (
51970
50359
  // <>
@@ -52173,12 +50562,12 @@ const RenderForm = (props) => {
52173
50562
  },
52174
50563
  }, label: props.item.label, views: ["year"], value: dayjs(field.value), onChange: (date) => field.onChange(date), slots: {
52175
50564
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
52176
- textField: (textFieldProps) => jsxRuntimeExports.jsx(TextField, Object.assign({}, textFieldProps, { fullWidth: true, disabled: props.item.disable || false, InputLabelProps: {
50565
+ textField: (textFieldProps) => (jsxRuntimeExports.jsx(TextField, Object.assign({}, textFieldProps, { fullWidth: true, disabled: props.item.disable || false, InputLabelProps: {
52177
50566
  shrink: true,
52178
50567
  }, error: props.errors, inputProps: {
52179
50568
  min: props.item.minDate,
52180
- } }))
52181
- } }) })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] })) }) }));
50569
+ } }))),
50570
+ } }) })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] })) }) }));
52182
50571
  case "dateRangePicker":
52183
50572
  return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: jsxRuntimeExports.jsx(DateRangePickerComponent, { props: props }) }));
52184
50573
  case "monthpicker":
@@ -52222,7 +50611,7 @@ const RenderForm = (props) => {
52222
50611
  },
52223
50612
  }, minRows: props.item.minRows || 1,
52224
50613
  // maxRows={2}
52225
- placeholder: props.item.placeholder || "Type Something..." }, field, { label: props.item.label, value: field.value || "", disabled: props.item.disable })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s$1, { errors: props.errors, name: props.item.name }) })] })) }) }));
50614
+ placeholder: props.item.placeholder || "Type Something..." }, field, { label: props.item.label, value: field.value || "", disabled: props.item.disable })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] })) }) }));
52226
50615
  // case "textarea-normal":
52227
50616
  // return (
52228
50617
  // <>
@@ -52296,2335 +50685,84 @@ const RenderForm = (props) => {
52296
50685
  // </ErrorMessageComponent>
52297
50686
  // </>
52298
50687
  // );
50688
+ default:
50689
+ return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
52299
50690
  }
52300
50691
  };
52301
50692
 
52302
- /**
52303
- * Based on Kendo UI Core expression code <https://github.com/telerik/kendo-ui-core#license-information>
52304
- */
52305
-
52306
- function Cache(maxSize) {
52307
- this._maxSize = maxSize;
52308
- this.clear();
52309
- }
52310
- Cache.prototype.clear = function () {
52311
- this._size = 0;
52312
- this._values = Object.create(null);
52313
- };
52314
- Cache.prototype.get = function (key) {
52315
- return this._values[key]
52316
- };
52317
- Cache.prototype.set = function (key, value) {
52318
- this._size >= this._maxSize && this.clear();
52319
- if (!(key in this._values)) this._size++;
52320
-
52321
- return (this._values[key] = value)
52322
- };
52323
-
52324
- var SPLIT_REGEX = /[^.^\]^[]+|(?=\[\]|\.\.)/g,
52325
- DIGIT_REGEX = /^\d+$/,
52326
- LEAD_DIGIT_REGEX = /^\d/,
52327
- SPEC_CHAR_REGEX = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g,
52328
- CLEAN_QUOTES_REGEX = /^\s*(['"]?)(.*?)(\1)\s*$/,
52329
- MAX_CACHE_SIZE = 512;
52330
-
52331
- var pathCache = new Cache(MAX_CACHE_SIZE),
52332
- setCache = new Cache(MAX_CACHE_SIZE),
52333
- getCache = new Cache(MAX_CACHE_SIZE);
52334
-
52335
- var propertyExpr = {
52336
- Cache: Cache,
52337
-
52338
- split: split,
52339
-
52340
- normalizePath: normalizePath,
52341
-
52342
- setter: function (path) {
52343
- var parts = normalizePath(path);
52344
-
52345
- return (
52346
- setCache.get(path) ||
52347
- setCache.set(path, function setter(obj, value) {
52348
- var index = 0;
52349
- var len = parts.length;
52350
- var data = obj;
52351
-
52352
- while (index < len - 1) {
52353
- var part = parts[index];
52354
- if (
52355
- part === '__proto__' ||
52356
- part === 'constructor' ||
52357
- part === 'prototype'
52358
- ) {
52359
- return obj
52360
- }
52361
-
52362
- data = data[parts[index++]];
52363
- }
52364
- data[parts[index]] = value;
52365
- })
52366
- )
52367
- },
52368
-
52369
- getter: function (path, safe) {
52370
- var parts = normalizePath(path);
52371
- return (
52372
- getCache.get(path) ||
52373
- getCache.set(path, function getter(data) {
52374
- var index = 0,
52375
- len = parts.length;
52376
- while (index < len) {
52377
- if (data != null || !safe) data = data[parts[index++]];
52378
- else return
52379
- }
52380
- return data
52381
- })
52382
- )
52383
- },
52384
-
52385
- join: function (segments) {
52386
- return segments.reduce(function (path, part) {
52387
- return (
52388
- path +
52389
- (isQuoted(part) || DIGIT_REGEX.test(part)
52390
- ? '[' + part + ']'
52391
- : (path ? '.' : '') + part)
52392
- )
52393
- }, '')
52394
- },
52395
-
52396
- forEach: function (path, cb, thisArg) {
52397
- forEach(Array.isArray(path) ? path : split(path), cb, thisArg);
52398
- },
52399
- };
52400
-
52401
- function normalizePath(path) {
52402
- return (
52403
- pathCache.get(path) ||
52404
- pathCache.set(
52405
- path,
52406
- split(path).map(function (part) {
52407
- return part.replace(CLEAN_QUOTES_REGEX, '$2')
52408
- })
52409
- )
52410
- )
52411
- }
52412
-
52413
- function split(path) {
52414
- return path.match(SPLIT_REGEX) || ['']
52415
- }
52416
-
52417
- function forEach(parts, iter, thisArg) {
52418
- var len = parts.length,
52419
- part,
52420
- idx,
52421
- isArray,
52422
- isBracket;
52423
-
52424
- for (idx = 0; idx < len; idx++) {
52425
- part = parts[idx];
52426
-
52427
- if (part) {
52428
- if (shouldBeQuoted(part)) {
52429
- part = '"' + part + '"';
52430
- }
52431
-
52432
- isBracket = isQuoted(part);
52433
- isArray = !isBracket && /^\d+$/.test(part);
52434
-
52435
- iter.call(thisArg, part, isBracket, isArray, idx, parts);
52436
- }
52437
- }
52438
- }
52439
-
52440
- function isQuoted(str) {
52441
- return (
52442
- typeof str === 'string' && str && ["'", '"'].indexOf(str.charAt(0)) !== -1
52443
- )
52444
- }
52445
-
52446
- function hasLeadingNumber(part) {
52447
- return part.match(LEAD_DIGIT_REGEX) && !part.match(DIGIT_REGEX)
52448
- }
52449
-
52450
- function hasSpecialChars(part) {
52451
- return SPEC_CHAR_REGEX.test(part)
52452
- }
52453
-
52454
- function shouldBeQuoted(part) {
52455
- return !isQuoted(part) && (hasLeadingNumber(part) || hasSpecialChars(part))
52456
- }
52457
-
52458
- const reWords = /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
52459
-
52460
- const words = (str) => str.match(reWords) || [];
52461
-
52462
- const upperFirst = (str) => str[0].toUpperCase() + str.slice(1);
52463
-
52464
- const join = (str, d) => words(str).join(d).toLowerCase();
52465
-
52466
- const camelCase = (str) =>
52467
- words(str).reduce(
52468
- (acc, next) =>
52469
- `${acc}${
52470
- !acc
52471
- ? next.toLowerCase()
52472
- : next[0].toUpperCase() + next.slice(1).toLowerCase()
52473
- }`,
52474
- '',
52475
- );
52476
-
52477
- const pascalCase = (str) => upperFirst(camelCase(str));
52478
-
52479
- const snakeCase = (str) => join(str, '_');
52480
-
52481
- const kebabCase = (str) => join(str, '-');
52482
-
52483
- const sentenceCase = (str) => upperFirst(join(str, ' '));
52484
-
52485
- const titleCase = (str) => words(str).map(upperFirst).join(' ');
52486
-
52487
- var tinyCase = {
52488
- words,
52489
- upperFirst,
52490
- camelCase,
52491
- pascalCase,
52492
- snakeCase,
52493
- kebabCase,
52494
- sentenceCase,
52495
- titleCase,
52496
- };
52497
-
52498
- var toposort$2 = {exports: {}};
52499
-
52500
- /**
52501
- * Topological sorting function
52502
- *
52503
- * @param {Array} edges
52504
- * @returns {Array}
52505
- */
52506
-
52507
- toposort$2.exports = function(edges) {
52508
- return toposort(uniqueNodes(edges), edges)
52509
- };
52510
-
52511
- toposort$2.exports.array = toposort;
52512
-
52513
- function toposort(nodes, edges) {
52514
- var cursor = nodes.length
52515
- , sorted = new Array(cursor)
52516
- , visited = {}
52517
- , i = cursor
52518
- // Better data structures make algorithm much faster.
52519
- , outgoingEdges = makeOutgoingEdges(edges)
52520
- , nodesHash = makeNodesHash(nodes);
52521
-
52522
- // check for unknown nodes
52523
- edges.forEach(function(edge) {
52524
- if (!nodesHash.has(edge[0]) || !nodesHash.has(edge[1])) {
52525
- throw new Error('Unknown node. There is an unknown node in the supplied edges.')
52526
- }
52527
- });
52528
-
52529
- while (i--) {
52530
- if (!visited[i]) visit(nodes[i], i, new Set());
52531
- }
52532
-
52533
- return sorted
52534
-
52535
- function visit(node, i, predecessors) {
52536
- if(predecessors.has(node)) {
52537
- var nodeRep;
52538
- try {
52539
- nodeRep = ", node was:" + JSON.stringify(node);
52540
- } catch(e) {
52541
- nodeRep = "";
52542
- }
52543
- throw new Error('Cyclic dependency' + nodeRep)
52544
- }
52545
-
52546
- if (!nodesHash.has(node)) {
52547
- throw new Error('Found unknown node. Make sure to provided all involved nodes. Unknown node: '+JSON.stringify(node))
52548
- }
52549
-
52550
- if (visited[i]) return;
52551
- visited[i] = true;
52552
-
52553
- var outgoing = outgoingEdges.get(node) || new Set();
52554
- outgoing = Array.from(outgoing);
52555
-
52556
- if (i = outgoing.length) {
52557
- predecessors.add(node);
52558
- do {
52559
- var child = outgoing[--i];
52560
- visit(child, nodesHash.get(child), predecessors);
52561
- } while (i)
52562
- predecessors.delete(node);
52563
- }
52564
-
52565
- sorted[--cursor] = node;
52566
- }
52567
- }
52568
-
52569
- function uniqueNodes(arr){
52570
- var res = new Set();
52571
- for (var i = 0, len = arr.length; i < len; i++) {
52572
- var edge = arr[i];
52573
- res.add(edge[0]);
52574
- res.add(edge[1]);
52575
- }
52576
- return Array.from(res)
52577
- }
52578
-
52579
- function makeOutgoingEdges(arr){
52580
- var edges = new Map();
52581
- for (var i = 0, len = arr.length; i < len; i++) {
52582
- var edge = arr[i];
52583
- if (!edges.has(edge[0])) edges.set(edge[0], new Set());
52584
- if (!edges.has(edge[1])) edges.set(edge[1], new Set());
52585
- edges.get(edge[0]).add(edge[1]);
52586
- }
52587
- return edges
52588
- }
52589
-
52590
- function makeNodesHash(arr){
52591
- var res = new Map();
52592
- for (var i = 0, len = arr.length; i < len; i++) {
52593
- res.set(arr[i], i);
52594
- }
52595
- return res
52596
- }
52597
-
52598
- var toposortExports = toposort$2.exports;
52599
- var toposort$1 = /*@__PURE__*/getDefaultExportFromCjs(toposortExports);
52600
-
52601
- const toString = Object.prototype.toString;
52602
- const errorToString = Error.prototype.toString;
52603
- const regExpToString = RegExp.prototype.toString;
52604
- const symbolToString = typeof Symbol !== 'undefined' ? Symbol.prototype.toString : () => '';
52605
- const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
52606
- function printNumber(val) {
52607
- if (val != +val) return 'NaN';
52608
- const isNegativeZero = val === 0 && 1 / val < 0;
52609
- return isNegativeZero ? '-0' : '' + val;
52610
- }
52611
- function printSimpleValue(val, quoteStrings = false) {
52612
- if (val == null || val === true || val === false) return '' + val;
52613
- const typeOf = typeof val;
52614
- if (typeOf === 'number') return printNumber(val);
52615
- if (typeOf === 'string') return quoteStrings ? `"${val}"` : val;
52616
- if (typeOf === 'function') return '[Function ' + (val.name || 'anonymous') + ']';
52617
- if (typeOf === 'symbol') return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
52618
- const tag = toString.call(val).slice(8, -1);
52619
- if (tag === 'Date') return isNaN(val.getTime()) ? '' + val : val.toISOString(val);
52620
- if (tag === 'Error' || val instanceof Error) return '[' + errorToString.call(val) + ']';
52621
- if (tag === 'RegExp') return regExpToString.call(val);
52622
- return null;
52623
- }
52624
- function printValue(value, quoteStrings) {
52625
- let result = printSimpleValue(value, quoteStrings);
52626
- if (result !== null) return result;
52627
- return JSON.stringify(value, function (key, value) {
52628
- let result = printSimpleValue(this[key], quoteStrings);
52629
- if (result !== null) return result;
52630
- return value;
52631
- }, 2);
52632
- }
52633
-
52634
- function toArray(value) {
52635
- return value == null ? [] : [].concat(value);
52636
- }
52637
-
52638
- let _Symbol$toStringTag, _Symbol$hasInstance, _Symbol$toStringTag2;
52639
- let strReg = /\$\{\s*(\w+)\s*\}/g;
52640
- _Symbol$toStringTag = Symbol.toStringTag;
52641
- class ValidationErrorNoStack {
52642
- constructor(errorOrErrors, value, field, type) {
52643
- this.name = void 0;
52644
- this.message = void 0;
52645
- this.value = void 0;
52646
- this.path = void 0;
52647
- this.type = void 0;
52648
- this.params = void 0;
52649
- this.errors = void 0;
52650
- this.inner = void 0;
52651
- this[_Symbol$toStringTag] = 'Error';
52652
- this.name = 'ValidationError';
52653
- this.value = value;
52654
- this.path = field;
52655
- this.type = type;
52656
- this.errors = [];
52657
- this.inner = [];
52658
- toArray(errorOrErrors).forEach(err => {
52659
- if (ValidationError.isError(err)) {
52660
- this.errors.push(...err.errors);
52661
- const innerErrors = err.inner.length ? err.inner : [err];
52662
- this.inner.push(...innerErrors);
52663
- } else {
52664
- this.errors.push(err);
52665
- }
52666
- });
52667
- this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
52668
- }
52669
- }
52670
- _Symbol$hasInstance = Symbol.hasInstance;
52671
- _Symbol$toStringTag2 = Symbol.toStringTag;
52672
- class ValidationError extends Error {
52673
- static formatError(message, params) {
52674
- const path = params.label || params.path || 'this';
52675
- if (path !== params.path) params = Object.assign({}, params, {
52676
- path
52677
- });
52678
- if (typeof message === 'string') return message.replace(strReg, (_, key) => printValue(params[key]));
52679
- if (typeof message === 'function') return message(params);
52680
- return message;
52681
- }
52682
- static isError(err) {
52683
- return err && err.name === 'ValidationError';
52684
- }
52685
- constructor(errorOrErrors, value, field, type, disableStack) {
52686
- const errorNoStack = new ValidationErrorNoStack(errorOrErrors, value, field, type);
52687
- if (disableStack) {
52688
- return errorNoStack;
52689
- }
52690
- super();
52691
- this.value = void 0;
52692
- this.path = void 0;
52693
- this.type = void 0;
52694
- this.params = void 0;
52695
- this.errors = [];
52696
- this.inner = [];
52697
- this[_Symbol$toStringTag2] = 'Error';
52698
- this.name = errorNoStack.name;
52699
- this.message = errorNoStack.message;
52700
- this.type = errorNoStack.type;
52701
- this.value = errorNoStack.value;
52702
- this.path = errorNoStack.path;
52703
- this.errors = errorNoStack.errors;
52704
- this.inner = errorNoStack.inner;
52705
- if (Error.captureStackTrace) {
52706
- Error.captureStackTrace(this, ValidationError);
52707
- }
52708
- }
52709
- static [_Symbol$hasInstance](inst) {
52710
- return ValidationErrorNoStack[Symbol.hasInstance](inst) || super[Symbol.hasInstance](inst);
52711
- }
52712
- }
52713
-
52714
- let mixed = {
52715
- default: '${path} is invalid',
52716
- required: '${path} is a required field',
52717
- defined: '${path} must be defined',
52718
- notNull: '${path} cannot be null',
52719
- oneOf: '${path} must be one of the following values: ${values}',
52720
- notOneOf: '${path} must not be one of the following values: ${values}',
52721
- notType: ({
52722
- path,
52723
- type,
52724
- value,
52725
- originalValue
52726
- }) => {
52727
- const castMsg = originalValue != null && originalValue !== value ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.';
52728
- return type !== 'mixed' ? `${path} must be a \`${type}\` type, ` + `but the final value was: \`${printValue(value, true)}\`` + castMsg : `${path} must match the configured type. ` + `The validated value was: \`${printValue(value, true)}\`` + castMsg;
52729
- }
52730
- };
52731
- let string = {
52732
- length: '${path} must be exactly ${length} characters',
52733
- min: '${path} must be at least ${min} characters',
52734
- max: '${path} must be at most ${max} characters',
52735
- matches: '${path} must match the following: "${regex}"',
52736
- email: '${path} must be a valid email',
52737
- url: '${path} must be a valid URL',
52738
- uuid: '${path} must be a valid UUID',
52739
- datetime: '${path} must be a valid ISO date-time',
52740
- datetime_precision: '${path} must be a valid ISO date-time with a sub-second precision of exactly ${precision} digits',
52741
- datetime_offset: '${path} must be a valid ISO date-time with UTC "Z" timezone',
52742
- trim: '${path} must be a trimmed string',
52743
- lowercase: '${path} must be a lowercase string',
52744
- uppercase: '${path} must be a upper case string'
52745
- };
52746
- let number = {
52747
- min: '${path} must be greater than or equal to ${min}',
52748
- max: '${path} must be less than or equal to ${max}',
52749
- lessThan: '${path} must be less than ${less}',
52750
- moreThan: '${path} must be greater than ${more}',
52751
- positive: '${path} must be a positive number',
52752
- negative: '${path} must be a negative number',
52753
- integer: '${path} must be an integer'
52754
- };
52755
- let date = {
52756
- min: '${path} field must be later than ${min}',
52757
- max: '${path} field must be at earlier than ${max}'
52758
- };
52759
- let boolean = {
52760
- isValue: '${path} field must be ${value}'
52761
- };
52762
- let object = {
52763
- noUnknown: '${path} field has unspecified keys: ${unknown}'
52764
- };
52765
- let array = {
52766
- min: '${path} field must have at least ${min} items',
52767
- max: '${path} field must have less than or equal to ${max} items',
52768
- length: '${path} must have ${length} items'
52769
- };
52770
- let tuple = {
52771
- notType: params => {
52772
- const {
52773
- path,
52774
- value,
52775
- spec
52776
- } = params;
52777
- const typeLen = spec.types.length;
52778
- if (Array.isArray(value)) {
52779
- if (value.length < typeLen) return `${path} tuple value has too few items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
52780
- if (value.length > typeLen) return `${path} tuple value has too many items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
52781
- }
52782
- return ValidationError.formatError(mixed.notType, params);
52783
- }
52784
- };
52785
- Object.assign(Object.create(null), {
52786
- mixed,
52787
- string,
52788
- number,
52789
- date,
52790
- object,
52791
- array,
52792
- boolean,
52793
- tuple
52794
- });
52795
-
52796
- const isSchema = obj => obj && obj.__isYupSchema__;
52797
-
52798
- class Condition {
52799
- static fromOptions(refs, config) {
52800
- if (!config.then && !config.otherwise) throw new TypeError('either `then:` or `otherwise:` is required for `when()` conditions');
52801
- let {
52802
- is,
52803
- then,
52804
- otherwise
52805
- } = config;
52806
- let check = typeof is === 'function' ? is : (...values) => values.every(value => value === is);
52807
- return new Condition(refs, (values, schema) => {
52808
- var _branch;
52809
- let branch = check(...values) ? then : otherwise;
52810
- return (_branch = branch == null ? void 0 : branch(schema)) != null ? _branch : schema;
52811
- });
52812
- }
52813
- constructor(refs, builder) {
52814
- this.fn = void 0;
52815
- this.refs = refs;
52816
- this.refs = refs;
52817
- this.fn = builder;
52818
- }
52819
- resolve(base, options) {
52820
- let values = this.refs.map(ref =>
52821
- // TODO: ? operator here?
52822
- ref.getValue(options == null ? void 0 : options.value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context));
52823
- let schema = this.fn(values, base, options);
52824
- if (schema === undefined ||
52825
- // @ts-ignore this can be base
52826
- schema === base) {
52827
- return base;
52828
- }
52829
- if (!isSchema(schema)) throw new TypeError('conditions must return a schema object');
52830
- return schema.resolve(options);
52831
- }
52832
- }
52833
-
52834
- const prefixes = {
52835
- context: '$',
52836
- value: '.'
52837
- };
52838
- class Reference {
52839
- constructor(key, options = {}) {
52840
- this.key = void 0;
52841
- this.isContext = void 0;
52842
- this.isValue = void 0;
52843
- this.isSibling = void 0;
52844
- this.path = void 0;
52845
- this.getter = void 0;
52846
- this.map = void 0;
52847
- if (typeof key !== 'string') throw new TypeError('ref must be a string, got: ' + key);
52848
- this.key = key.trim();
52849
- if (key === '') throw new TypeError('ref must be a non-empty string');
52850
- this.isContext = this.key[0] === prefixes.context;
52851
- this.isValue = this.key[0] === prefixes.value;
52852
- this.isSibling = !this.isContext && !this.isValue;
52853
- let prefix = this.isContext ? prefixes.context : this.isValue ? prefixes.value : '';
52854
- this.path = this.key.slice(prefix.length);
52855
- this.getter = this.path && propertyExpr.getter(this.path, true);
52856
- this.map = options.map;
52857
- }
52858
- getValue(value, parent, context) {
52859
- let result = this.isContext ? context : this.isValue ? value : parent;
52860
- if (this.getter) result = this.getter(result || {});
52861
- if (this.map) result = this.map(result);
52862
- return result;
52863
- }
52864
-
52865
- /**
52866
- *
52867
- * @param {*} value
52868
- * @param {Object} options
52869
- * @param {Object=} options.context
52870
- * @param {Object=} options.parent
52871
- */
52872
- cast(value, options) {
52873
- return this.getValue(value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context);
52874
- }
52875
- resolve() {
52876
- return this;
52877
- }
52878
- describe() {
52879
- return {
52880
- type: 'ref',
52881
- key: this.key
52882
- };
52883
- }
52884
- toString() {
52885
- return `Ref(${this.key})`;
52886
- }
52887
- static isRef(value) {
52888
- return value && value.__isYupRef;
52889
- }
52890
- }
52891
-
52892
- // @ts-ignore
52893
- Reference.prototype.__isYupRef = true;
52894
-
52895
- const isAbsent = value => value == null;
52896
-
52897
- function createValidation(config) {
52898
- function validate({
52899
- value,
52900
- path = '',
52901
- options,
52902
- originalValue,
52903
- schema
52904
- }, panic, next) {
52905
- const {
52906
- name,
52907
- test,
52908
- params,
52909
- message,
52910
- skipAbsent
52911
- } = config;
52912
- let {
52913
- parent,
52914
- context,
52915
- abortEarly = schema.spec.abortEarly,
52916
- disableStackTrace = schema.spec.disableStackTrace
52917
- } = options;
52918
- function resolve(item) {
52919
- return Reference.isRef(item) ? item.getValue(value, parent, context) : item;
52920
- }
52921
- function createError(overrides = {}) {
52922
- const nextParams = Object.assign({
52923
- value,
52924
- originalValue,
52925
- label: schema.spec.label,
52926
- path: overrides.path || path,
52927
- spec: schema.spec,
52928
- disableStackTrace: overrides.disableStackTrace || disableStackTrace
52929
- }, params, overrides.params);
52930
- for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
52931
- const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
52932
- error.params = nextParams;
52933
- return error;
52934
- }
52935
- const invalid = abortEarly ? panic : next;
52936
- let ctx = {
52937
- path,
52938
- parent,
52939
- type: name,
52940
- from: options.from,
52941
- createError,
52942
- resolve,
52943
- options,
52944
- originalValue,
52945
- schema
52946
- };
52947
- const handleResult = validOrError => {
52948
- if (ValidationError.isError(validOrError)) invalid(validOrError);else if (!validOrError) invalid(createError());else next(null);
52949
- };
52950
- const handleError = err => {
52951
- if (ValidationError.isError(err)) invalid(err);else panic(err);
52952
- };
52953
- const shouldSkip = skipAbsent && isAbsent(value);
52954
- if (shouldSkip) {
52955
- return handleResult(true);
52956
- }
52957
- let result;
52958
- try {
52959
- var _result;
52960
- result = test.call(ctx, value, ctx);
52961
- if (typeof ((_result = result) == null ? void 0 : _result.then) === 'function') {
52962
- if (options.sync) {
52963
- throw new Error(`Validation test of type: "${ctx.type}" returned a Promise during a synchronous validate. ` + `This test will finish after the validate call has returned`);
52964
- }
52965
- return Promise.resolve(result).then(handleResult, handleError);
52966
- }
52967
- } catch (err) {
52968
- handleError(err);
52969
- return;
52970
- }
52971
- handleResult(result);
52972
- }
52973
- validate.OPTIONS = config;
52974
- return validate;
52975
- }
52976
-
52977
- function getIn(schema, path, value, context = value) {
52978
- let parent, lastPart, lastPartDebug;
52979
-
52980
- // root path: ''
52981
- if (!path) return {
52982
- parent,
52983
- parentPath: path,
52984
- schema
52985
- };
52986
- propertyExpr.forEach(path, (_part, isBracket, isArray) => {
52987
- let part = isBracket ? _part.slice(1, _part.length - 1) : _part;
52988
- schema = schema.resolve({
52989
- context,
52990
- parent,
52991
- value
52992
- });
52993
- let isTuple = schema.type === 'tuple';
52994
- let idx = isArray ? parseInt(part, 10) : 0;
52995
- if (schema.innerType || isTuple) {
52996
- if (isTuple && !isArray) throw new Error(`Yup.reach cannot implicitly index into a tuple type. the path part "${lastPartDebug}" must contain an index to the tuple element, e.g. "${lastPartDebug}[0]"`);
52997
- if (value && idx >= value.length) {
52998
- throw new Error(`Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` + `because there is no value at that index. `);
52999
- }
53000
- parent = value;
53001
- value = value && value[idx];
53002
- schema = isTuple ? schema.spec.types[idx] : schema.innerType;
53003
- }
53004
-
53005
- // sometimes the array index part of a path doesn't exist: "nested.arr.child"
53006
- // in these cases the current part is the next schema and should be processed
53007
- // in this iteration. For cases where the index signature is included this
53008
- // check will fail and we'll handle the `child` part on the next iteration like normal
53009
- if (!isArray) {
53010
- if (!schema.fields || !schema.fields[part]) throw new Error(`The schema does not contain the path: ${path}. ` + `(failed at: ${lastPartDebug} which is a type: "${schema.type}")`);
53011
- parent = value;
53012
- value = value && value[part];
53013
- schema = schema.fields[part];
53014
- }
53015
- lastPart = part;
53016
- lastPartDebug = isBracket ? '[' + _part + ']' : '.' + _part;
53017
- });
53018
- return {
53019
- schema,
53020
- parent,
53021
- parentPath: lastPart
53022
- };
53023
- }
53024
-
53025
- class ReferenceSet extends Set {
53026
- describe() {
53027
- const description = [];
53028
- for (const item of this.values()) {
53029
- description.push(Reference.isRef(item) ? item.describe() : item);
53030
- }
53031
- return description;
53032
- }
53033
- resolveAll(resolve) {
53034
- let result = [];
53035
- for (const item of this.values()) {
53036
- result.push(resolve(item));
53037
- }
53038
- return result;
53039
- }
53040
- clone() {
53041
- return new ReferenceSet(this.values());
53042
- }
53043
- merge(newItems, removeItems) {
53044
- const next = this.clone();
53045
- newItems.forEach(value => next.add(value));
53046
- removeItems.forEach(value => next.delete(value));
53047
- return next;
53048
- }
53049
- }
53050
-
53051
- // tweaked from https://github.com/Kelin2025/nanoclone/blob/0abeb7635bda9b68ef2277093f76dbe3bf3948e1/src/index.js
53052
- function clone(src, seen = new Map()) {
53053
- if (isSchema(src) || !src || typeof src !== 'object') return src;
53054
- if (seen.has(src)) return seen.get(src);
53055
- let copy;
53056
- if (src instanceof Date) {
53057
- // Date
53058
- copy = new Date(src.getTime());
53059
- seen.set(src, copy);
53060
- } else if (src instanceof RegExp) {
53061
- // RegExp
53062
- copy = new RegExp(src);
53063
- seen.set(src, copy);
53064
- } else if (Array.isArray(src)) {
53065
- // Array
53066
- copy = new Array(src.length);
53067
- seen.set(src, copy);
53068
- for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen);
53069
- } else if (src instanceof Map) {
53070
- // Map
53071
- copy = new Map();
53072
- seen.set(src, copy);
53073
- for (const [k, v] of src.entries()) copy.set(k, clone(v, seen));
53074
- } else if (src instanceof Set) {
53075
- // Set
53076
- copy = new Set();
53077
- seen.set(src, copy);
53078
- for (const v of src) copy.add(clone(v, seen));
53079
- } else if (src instanceof Object) {
53080
- // Object
53081
- copy = {};
53082
- seen.set(src, copy);
53083
- for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen);
53084
- } else {
53085
- throw Error(`Unable to clone ${src}`);
53086
- }
53087
- return copy;
53088
- }
53089
-
53090
- // If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
53091
- // loose Record definition allowing free form usage.
53092
- class Schema {
53093
- constructor(options) {
53094
- this.type = void 0;
53095
- this.deps = [];
53096
- this.tests = void 0;
53097
- this.transforms = void 0;
53098
- this.conditions = [];
53099
- this._mutate = void 0;
53100
- this.internalTests = {};
53101
- this._whitelist = new ReferenceSet();
53102
- this._blacklist = new ReferenceSet();
53103
- this.exclusiveTests = Object.create(null);
53104
- this._typeCheck = void 0;
53105
- this.spec = void 0;
53106
- this.tests = [];
53107
- this.transforms = [];
53108
- this.withMutation(() => {
53109
- this.typeError(mixed.notType);
53110
- });
53111
- this.type = options.type;
53112
- this._typeCheck = options.check;
53113
- this.spec = Object.assign({
53114
- strip: false,
53115
- strict: false,
53116
- abortEarly: true,
53117
- recursive: true,
53118
- disableStackTrace: false,
53119
- nullable: false,
53120
- optional: true,
53121
- coerce: true
53122
- }, options == null ? void 0 : options.spec);
53123
- this.withMutation(s => {
53124
- s.nonNullable();
53125
- });
53126
- }
53127
-
53128
- // TODO: remove
53129
- get _type() {
53130
- return this.type;
53131
- }
53132
- clone(spec) {
53133
- if (this._mutate) {
53134
- if (spec) Object.assign(this.spec, spec);
53135
- return this;
53136
- }
53137
-
53138
- // if the nested value is a schema we can skip cloning, since
53139
- // they are already immutable
53140
- const next = Object.create(Object.getPrototypeOf(this));
53141
-
53142
- // @ts-expect-error this is readonly
53143
- next.type = this.type;
53144
- next._typeCheck = this._typeCheck;
53145
- next._whitelist = this._whitelist.clone();
53146
- next._blacklist = this._blacklist.clone();
53147
- next.internalTests = Object.assign({}, this.internalTests);
53148
- next.exclusiveTests = Object.assign({}, this.exclusiveTests);
53149
-
53150
- // @ts-expect-error this is readonly
53151
- next.deps = [...this.deps];
53152
- next.conditions = [...this.conditions];
53153
- next.tests = [...this.tests];
53154
- next.transforms = [...this.transforms];
53155
- next.spec = clone(Object.assign({}, this.spec, spec));
53156
- return next;
53157
- }
53158
- label(label) {
53159
- let next = this.clone();
53160
- next.spec.label = label;
53161
- return next;
53162
- }
53163
- meta(...args) {
53164
- if (args.length === 0) return this.spec.meta;
53165
- let next = this.clone();
53166
- next.spec.meta = Object.assign(next.spec.meta || {}, args[0]);
53167
- return next;
53168
- }
53169
- withMutation(fn) {
53170
- let before = this._mutate;
53171
- this._mutate = true;
53172
- let result = fn(this);
53173
- this._mutate = before;
53174
- return result;
53175
- }
53176
- concat(schema) {
53177
- if (!schema || schema === this) return this;
53178
- if (schema.type !== this.type && this.type !== 'mixed') throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
53179
- let base = this;
53180
- let combined = schema.clone();
53181
- const mergedSpec = Object.assign({}, base.spec, combined.spec);
53182
- combined.spec = mergedSpec;
53183
- combined.internalTests = Object.assign({}, base.internalTests, combined.internalTests);
53184
-
53185
- // manually merge the blacklist/whitelist (the other `schema` takes
53186
- // precedence in case of conflicts)
53187
- combined._whitelist = base._whitelist.merge(schema._whitelist, schema._blacklist);
53188
- combined._blacklist = base._blacklist.merge(schema._blacklist, schema._whitelist);
53189
-
53190
- // start with the current tests
53191
- combined.tests = base.tests;
53192
- combined.exclusiveTests = base.exclusiveTests;
53193
-
53194
- // manually add the new tests to ensure
53195
- // the deduping logic is consistent
53196
- combined.withMutation(next => {
53197
- schema.tests.forEach(fn => {
53198
- next.test(fn.OPTIONS);
53199
- });
53200
- });
53201
- combined.transforms = [...base.transforms, ...combined.transforms];
53202
- return combined;
53203
- }
53204
- isType(v) {
53205
- if (v == null) {
53206
- if (this.spec.nullable && v === null) return true;
53207
- if (this.spec.optional && v === undefined) return true;
53208
- return false;
53209
- }
53210
- return this._typeCheck(v);
53211
- }
53212
- resolve(options) {
53213
- let schema = this;
53214
- if (schema.conditions.length) {
53215
- let conditions = schema.conditions;
53216
- schema = schema.clone();
53217
- schema.conditions = [];
53218
- schema = conditions.reduce((prevSchema, condition) => condition.resolve(prevSchema, options), schema);
53219
- schema = schema.resolve(options);
53220
- }
53221
- return schema;
53222
- }
53223
- resolveOptions(options) {
53224
- var _options$strict, _options$abortEarly, _options$recursive, _options$disableStack;
53225
- return Object.assign({}, options, {
53226
- from: options.from || [],
53227
- strict: (_options$strict = options.strict) != null ? _options$strict : this.spec.strict,
53228
- abortEarly: (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly,
53229
- recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive,
53230
- disableStackTrace: (_options$disableStack = options.disableStackTrace) != null ? _options$disableStack : this.spec.disableStackTrace
53231
- });
53232
- }
53233
-
53234
- /**
53235
- * Run the configured transform pipeline over an input value.
53236
- */
53237
-
53238
- cast(value, options = {}) {
53239
- let resolvedSchema = this.resolve(Object.assign({
53240
- value
53241
- }, options));
53242
- let allowOptionality = options.assert === 'ignore-optionality';
53243
- let result = resolvedSchema._cast(value, options);
53244
- if (options.assert !== false && !resolvedSchema.isType(result)) {
53245
- if (allowOptionality && isAbsent(result)) {
53246
- return result;
53247
- }
53248
- let formattedValue = printValue(value);
53249
- let formattedResult = printValue(result);
53250
- throw new TypeError(`The value of ${options.path || 'field'} could not be cast to a value ` + `that satisfies the schema type: "${resolvedSchema.type}". \n\n` + `attempted value: ${formattedValue} \n` + (formattedResult !== formattedValue ? `result of cast: ${formattedResult}` : ''));
53251
- }
53252
- return result;
53253
- }
53254
- _cast(rawValue, options) {
53255
- let value = rawValue === undefined ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this), rawValue);
53256
- if (value === undefined) {
53257
- value = this.getDefault(options);
53258
- }
53259
- return value;
53260
- }
53261
- _validate(_value, options = {}, panic, next) {
53262
- let {
53263
- path,
53264
- originalValue = _value,
53265
- strict = this.spec.strict
53266
- } = options;
53267
- let value = _value;
53268
- if (!strict) {
53269
- value = this._cast(value, Object.assign({
53270
- assert: false
53271
- }, options));
53272
- }
53273
- let initialTests = [];
53274
- for (let test of Object.values(this.internalTests)) {
53275
- if (test) initialTests.push(test);
53276
- }
53277
- this.runTests({
53278
- path,
53279
- value,
53280
- originalValue,
53281
- options,
53282
- tests: initialTests
53283
- }, panic, initialErrors => {
53284
- // even if we aren't ending early we can't proceed further if the types aren't correct
53285
- if (initialErrors.length) {
53286
- return next(initialErrors, value);
53287
- }
53288
- this.runTests({
53289
- path,
53290
- value,
53291
- originalValue,
53292
- options,
53293
- tests: this.tests
53294
- }, panic, next);
53295
- });
53296
- }
53297
-
53298
- /**
53299
- * Executes a set of validations, either schema, produced Tests or a nested
53300
- * schema validate result.
53301
- */
53302
- runTests(runOptions, panic, next) {
53303
- let fired = false;
53304
- let {
53305
- tests,
53306
- value,
53307
- originalValue,
53308
- path,
53309
- options
53310
- } = runOptions;
53311
- let panicOnce = arg => {
53312
- if (fired) return;
53313
- fired = true;
53314
- panic(arg, value);
53315
- };
53316
- let nextOnce = arg => {
53317
- if (fired) return;
53318
- fired = true;
53319
- next(arg, value);
53320
- };
53321
- let count = tests.length;
53322
- let nestedErrors = [];
53323
- if (!count) return nextOnce([]);
53324
- let args = {
53325
- value,
53326
- originalValue,
53327
- path,
53328
- options,
53329
- schema: this
53330
- };
53331
- for (let i = 0; i < tests.length; i++) {
53332
- const test = tests[i];
53333
- test(args, panicOnce, function finishTestRun(err) {
53334
- if (err) {
53335
- Array.isArray(err) ? nestedErrors.push(...err) : nestedErrors.push(err);
53336
- }
53337
- if (--count <= 0) {
53338
- nextOnce(nestedErrors);
53339
- }
53340
- });
53341
- }
53342
- }
53343
- asNestedTest({
53344
- key,
53345
- index,
53346
- parent,
53347
- parentPath,
53348
- originalParent,
53349
- options
53350
- }) {
53351
- const k = key != null ? key : index;
53352
- if (k == null) {
53353
- throw TypeError('Must include `key` or `index` for nested validations');
53354
- }
53355
- const isIndex = typeof k === 'number';
53356
- let value = parent[k];
53357
- const testOptions = Object.assign({}, options, {
53358
- // Nested validations fields are always strict:
53359
- // 1. parent isn't strict so the casting will also have cast inner values
53360
- // 2. parent is strict in which case the nested values weren't cast either
53361
- strict: true,
53362
- parent,
53363
- value,
53364
- originalValue: originalParent[k],
53365
- // FIXME: tests depend on `index` being passed around deeply,
53366
- // we should not let the options.key/index bleed through
53367
- key: undefined,
53368
- // index: undefined,
53369
- [isIndex ? 'index' : 'key']: k,
53370
- path: isIndex || k.includes('.') ? `${parentPath || ''}[${isIndex ? k : `"${k}"`}]` : (parentPath ? `${parentPath}.` : '') + key
53371
- });
53372
- return (_, panic, next) => this.resolve(testOptions)._validate(value, testOptions, panic, next);
53373
- }
53374
- validate(value, options) {
53375
- var _options$disableStack2;
53376
- let schema = this.resolve(Object.assign({}, options, {
53377
- value
53378
- }));
53379
- let disableStackTrace = (_options$disableStack2 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack2 : schema.spec.disableStackTrace;
53380
- return new Promise((resolve, reject) => schema._validate(value, options, (error, parsed) => {
53381
- if (ValidationError.isError(error)) error.value = parsed;
53382
- reject(error);
53383
- }, (errors, validated) => {
53384
- if (errors.length) reject(new ValidationError(errors, validated, undefined, undefined, disableStackTrace));else resolve(validated);
53385
- }));
53386
- }
53387
- validateSync(value, options) {
53388
- var _options$disableStack3;
53389
- let schema = this.resolve(Object.assign({}, options, {
53390
- value
53391
- }));
53392
- let result;
53393
- let disableStackTrace = (_options$disableStack3 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack3 : schema.spec.disableStackTrace;
53394
- schema._validate(value, Object.assign({}, options, {
53395
- sync: true
53396
- }), (error, parsed) => {
53397
- if (ValidationError.isError(error)) error.value = parsed;
53398
- throw error;
53399
- }, (errors, validated) => {
53400
- if (errors.length) throw new ValidationError(errors, value, undefined, undefined, disableStackTrace);
53401
- result = validated;
53402
- });
53403
- return result;
53404
- }
53405
- isValid(value, options) {
53406
- return this.validate(value, options).then(() => true, err => {
53407
- if (ValidationError.isError(err)) return false;
53408
- throw err;
53409
- });
53410
- }
53411
- isValidSync(value, options) {
53412
- try {
53413
- this.validateSync(value, options);
53414
- return true;
53415
- } catch (err) {
53416
- if (ValidationError.isError(err)) return false;
53417
- throw err;
53418
- }
53419
- }
53420
- _getDefault(options) {
53421
- let defaultValue = this.spec.default;
53422
- if (defaultValue == null) {
53423
- return defaultValue;
53424
- }
53425
- return typeof defaultValue === 'function' ? defaultValue.call(this, options) : clone(defaultValue);
53426
- }
53427
- getDefault(options
53428
- // If schema is defaulted we know it's at least not undefined
53429
- ) {
53430
- let schema = this.resolve(options || {});
53431
- return schema._getDefault(options);
53432
- }
53433
- default(def) {
53434
- if (arguments.length === 0) {
53435
- return this._getDefault();
53436
- }
53437
- let next = this.clone({
53438
- default: def
53439
- });
53440
- return next;
53441
- }
53442
- strict(isStrict = true) {
53443
- return this.clone({
53444
- strict: isStrict
53445
- });
53446
- }
53447
- nullability(nullable, message) {
53448
- const next = this.clone({
53449
- nullable
53450
- });
53451
- next.internalTests.nullable = createValidation({
53452
- message,
53453
- name: 'nullable',
53454
- test(value) {
53455
- return value === null ? this.schema.spec.nullable : true;
53456
- }
53457
- });
53458
- return next;
53459
- }
53460
- optionality(optional, message) {
53461
- const next = this.clone({
53462
- optional
53463
- });
53464
- next.internalTests.optionality = createValidation({
53465
- message,
53466
- name: 'optionality',
53467
- test(value) {
53468
- return value === undefined ? this.schema.spec.optional : true;
53469
- }
53470
- });
53471
- return next;
53472
- }
53473
- optional() {
53474
- return this.optionality(true);
53475
- }
53476
- defined(message = mixed.defined) {
53477
- return this.optionality(false, message);
53478
- }
53479
- nullable() {
53480
- return this.nullability(true);
53481
- }
53482
- nonNullable(message = mixed.notNull) {
53483
- return this.nullability(false, message);
53484
- }
53485
- required(message = mixed.required) {
53486
- return this.clone().withMutation(next => next.nonNullable(message).defined(message));
53487
- }
53488
- notRequired() {
53489
- return this.clone().withMutation(next => next.nullable().optional());
53490
- }
53491
- transform(fn) {
53492
- let next = this.clone();
53493
- next.transforms.push(fn);
53494
- return next;
53495
- }
53496
-
53497
- /**
53498
- * Adds a test function to the schema's queue of tests.
53499
- * tests can be exclusive or non-exclusive.
53500
- *
53501
- * - exclusive tests, will replace any existing tests of the same name.
53502
- * - non-exclusive: can be stacked
53503
- *
53504
- * If a non-exclusive test is added to a schema with an exclusive test of the same name
53505
- * the exclusive test is removed and further tests of the same name will be stacked.
53506
- *
53507
- * If an exclusive test is added to a schema with non-exclusive tests of the same name
53508
- * the previous tests are removed and further tests of the same name will replace each other.
53509
- */
53510
-
53511
- test(...args) {
53512
- let opts;
53513
- if (args.length === 1) {
53514
- if (typeof args[0] === 'function') {
53515
- opts = {
53516
- test: args[0]
53517
- };
53518
- } else {
53519
- opts = args[0];
53520
- }
53521
- } else if (args.length === 2) {
53522
- opts = {
53523
- name: args[0],
53524
- test: args[1]
53525
- };
53526
- } else {
53527
- opts = {
53528
- name: args[0],
53529
- message: args[1],
53530
- test: args[2]
53531
- };
53532
- }
53533
- if (opts.message === undefined) opts.message = mixed.default;
53534
- if (typeof opts.test !== 'function') throw new TypeError('`test` is a required parameters');
53535
- let next = this.clone();
53536
- let validate = createValidation(opts);
53537
- let isExclusive = opts.exclusive || opts.name && next.exclusiveTests[opts.name] === true;
53538
- if (opts.exclusive) {
53539
- if (!opts.name) throw new TypeError('Exclusive tests must provide a unique `name` identifying the test');
53540
- }
53541
- if (opts.name) next.exclusiveTests[opts.name] = !!opts.exclusive;
53542
- next.tests = next.tests.filter(fn => {
53543
- if (fn.OPTIONS.name === opts.name) {
53544
- if (isExclusive) return false;
53545
- if (fn.OPTIONS.test === validate.OPTIONS.test) return false;
53546
- }
53547
- return true;
53548
- });
53549
- next.tests.push(validate);
53550
- return next;
53551
- }
53552
- when(keys, options) {
53553
- if (!Array.isArray(keys) && typeof keys !== 'string') {
53554
- options = keys;
53555
- keys = '.';
53556
- }
53557
- let next = this.clone();
53558
- let deps = toArray(keys).map(key => new Reference(key));
53559
- deps.forEach(dep => {
53560
- // @ts-ignore readonly array
53561
- if (dep.isSibling) next.deps.push(dep.key);
53562
- });
53563
- next.conditions.push(typeof options === 'function' ? new Condition(deps, options) : Condition.fromOptions(deps, options));
53564
- return next;
53565
- }
53566
- typeError(message) {
53567
- let next = this.clone();
53568
- next.internalTests.typeError = createValidation({
53569
- message,
53570
- name: 'typeError',
53571
- skipAbsent: true,
53572
- test(value) {
53573
- if (!this.schema._typeCheck(value)) return this.createError({
53574
- params: {
53575
- type: this.schema.type
53576
- }
53577
- });
53578
- return true;
53579
- }
53580
- });
53581
- return next;
53582
- }
53583
- oneOf(enums, message = mixed.oneOf) {
53584
- let next = this.clone();
53585
- enums.forEach(val => {
53586
- next._whitelist.add(val);
53587
- next._blacklist.delete(val);
53588
- });
53589
- next.internalTests.whiteList = createValidation({
53590
- message,
53591
- name: 'oneOf',
53592
- skipAbsent: true,
53593
- test(value) {
53594
- let valids = this.schema._whitelist;
53595
- let resolved = valids.resolveAll(this.resolve);
53596
- return resolved.includes(value) ? true : this.createError({
53597
- params: {
53598
- values: Array.from(valids).join(', '),
53599
- resolved
53600
- }
53601
- });
53602
- }
53603
- });
53604
- return next;
53605
- }
53606
- notOneOf(enums, message = mixed.notOneOf) {
53607
- let next = this.clone();
53608
- enums.forEach(val => {
53609
- next._blacklist.add(val);
53610
- next._whitelist.delete(val);
53611
- });
53612
- next.internalTests.blacklist = createValidation({
53613
- message,
53614
- name: 'notOneOf',
53615
- test(value) {
53616
- let invalids = this.schema._blacklist;
53617
- let resolved = invalids.resolveAll(this.resolve);
53618
- if (resolved.includes(value)) return this.createError({
53619
- params: {
53620
- values: Array.from(invalids).join(', '),
53621
- resolved
53622
- }
53623
- });
53624
- return true;
53625
- }
53626
- });
53627
- return next;
53628
- }
53629
- strip(strip = true) {
53630
- let next = this.clone();
53631
- next.spec.strip = strip;
53632
- return next;
53633
- }
53634
-
53635
- /**
53636
- * Return a serialized description of the schema including validations, flags, types etc.
53637
- *
53638
- * @param options Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
53639
- */
53640
- describe(options) {
53641
- const next = (options ? this.resolve(options) : this).clone();
53642
- const {
53643
- label,
53644
- meta,
53645
- optional,
53646
- nullable
53647
- } = next.spec;
53648
- const description = {
53649
- meta,
53650
- label,
53651
- optional,
53652
- nullable,
53653
- default: next.getDefault(options),
53654
- type: next.type,
53655
- oneOf: next._whitelist.describe(),
53656
- notOneOf: next._blacklist.describe(),
53657
- tests: next.tests.map(fn => ({
53658
- name: fn.OPTIONS.name,
53659
- params: fn.OPTIONS.params
53660
- })).filter((n, idx, list) => list.findIndex(c => c.name === n.name) === idx)
53661
- };
53662
- return description;
53663
- }
53664
- }
53665
- // @ts-expect-error
53666
- Schema.prototype.__isYupSchema__ = true;
53667
- for (const method of ['validate', 'validateSync']) Schema.prototype[`${method}At`] = function (path, value, options = {}) {
53668
- const {
53669
- parent,
53670
- parentPath,
53671
- schema
53672
- } = getIn(this, path, value, options.context);
53673
- return schema[method](parent && parent[parentPath], Object.assign({}, options, {
53674
- parent,
53675
- path
53676
- }));
53677
- };
53678
- for (const alias of ['equals', 'is']) Schema.prototype[alias] = Schema.prototype.oneOf;
53679
- for (const alias of ['not', 'nope']) Schema.prototype[alias] = Schema.prototype.notOneOf;
53680
-
53681
- const returnsTrue = () => true;
53682
- function create$8(spec) {
53683
- return new MixedSchema(spec);
53684
- }
53685
- class MixedSchema extends Schema {
53686
- constructor(spec) {
53687
- super(typeof spec === 'function' ? {
53688
- type: 'mixed',
53689
- check: spec
53690
- } : Object.assign({
53691
- type: 'mixed',
53692
- check: returnsTrue
53693
- }, spec));
53694
- }
53695
- }
53696
- create$8.prototype = MixedSchema.prototype;
53697
-
53698
- /**
53699
- * This file is a modified version of the file from the following repository:
53700
- * Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
53701
- * NON-CONFORMANT EDITION.
53702
- * © 2011 Colin Snover <http://zetafleet.com>
53703
- * Released under MIT license.
53704
- */
53705
-
53706
- // prettier-ignore
53707
- // 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
53708
- const isoReg = /^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;
53709
- function parseIsoDate(date) {
53710
- const struct = parseDateStruct(date);
53711
- if (!struct) return Date.parse ? Date.parse(date) : Number.NaN;
53712
-
53713
- // timestamps without timezone identifiers should be considered local time
53714
- if (struct.z === undefined && struct.plusMinus === undefined) {
53715
- return new Date(struct.year, struct.month, struct.day, struct.hour, struct.minute, struct.second, struct.millisecond).valueOf();
53716
- }
53717
- let totalMinutesOffset = 0;
53718
- if (struct.z !== 'Z' && struct.plusMinus !== undefined) {
53719
- totalMinutesOffset = struct.hourOffset * 60 + struct.minuteOffset;
53720
- if (struct.plusMinus === '+') totalMinutesOffset = 0 - totalMinutesOffset;
53721
- }
53722
- return Date.UTC(struct.year, struct.month, struct.day, struct.hour, struct.minute + totalMinutesOffset, struct.second, struct.millisecond);
53723
- }
53724
- function parseDateStruct(date) {
53725
- var _regexResult$7$length, _regexResult$;
53726
- const regexResult = isoReg.exec(date);
53727
- if (!regexResult) return null;
53728
-
53729
- // use of toNumber() avoids NaN timestamps caused by “undefined”
53730
- // values being passed to Date constructor
53731
- return {
53732
- year: toNumber(regexResult[1]),
53733
- month: toNumber(regexResult[2], 1) - 1,
53734
- day: toNumber(regexResult[3], 1),
53735
- hour: toNumber(regexResult[4]),
53736
- minute: toNumber(regexResult[5]),
53737
- second: toNumber(regexResult[6]),
53738
- millisecond: regexResult[7] ?
53739
- // allow arbitrary sub-second precision beyond milliseconds
53740
- toNumber(regexResult[7].substring(0, 3)) : 0,
53741
- precision: (_regexResult$7$length = (_regexResult$ = regexResult[7]) == null ? void 0 : _regexResult$.length) != null ? _regexResult$7$length : undefined,
53742
- z: regexResult[8] || undefined,
53743
- plusMinus: regexResult[9] || undefined,
53744
- hourOffset: toNumber(regexResult[10]),
53745
- minuteOffset: toNumber(regexResult[11])
53746
- };
53747
- }
53748
- function toNumber(str, defaultValue = 0) {
53749
- return Number(str) || defaultValue;
53750
- }
53751
-
53752
- // Taken from HTML spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
53753
- let rEmail =
53754
- // eslint-disable-next-line
53755
- /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
53756
- let rUrl =
53757
- // eslint-disable-next-line
53758
- /^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
53759
-
53760
- // eslint-disable-next-line
53761
- let rUUID = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
53762
- let yearMonthDay = '^\\d{4}-\\d{2}-\\d{2}';
53763
- let hourMinuteSecond = '\\d{2}:\\d{2}:\\d{2}';
53764
- let zOrOffset = '(([+-]\\d{2}(:?\\d{2})?)|Z)';
53765
- let rIsoDateTime = new RegExp(`${yearMonthDay}T${hourMinuteSecond}(\\.\\d+)?${zOrOffset}$`);
53766
- let isTrimmed = value => isAbsent(value) || value === value.trim();
53767
- let objStringTag = {}.toString();
53768
- function create$6() {
53769
- return new StringSchema();
53770
- }
53771
- class StringSchema extends Schema {
53772
- constructor() {
53773
- super({
53774
- type: 'string',
53775
- check(value) {
53776
- if (value instanceof String) value = value.valueOf();
53777
- return typeof value === 'string';
53778
- }
53779
- });
53780
- this.withMutation(() => {
53781
- this.transform((value, _raw, ctx) => {
53782
- if (!ctx.spec.coerce || ctx.isType(value)) return value;
53783
-
53784
- // don't ever convert arrays
53785
- if (Array.isArray(value)) return value;
53786
- const strValue = value != null && value.toString ? value.toString() : value;
53787
-
53788
- // no one wants plain objects converted to [Object object]
53789
- if (strValue === objStringTag) return value;
53790
- return strValue;
53791
- });
53792
- });
53793
- }
53794
- required(message) {
53795
- return super.required(message).withMutation(schema => schema.test({
53796
- message: message || mixed.required,
53797
- name: 'required',
53798
- skipAbsent: true,
53799
- test: value => !!value.length
53800
- }));
53801
- }
53802
- notRequired() {
53803
- return super.notRequired().withMutation(schema => {
53804
- schema.tests = schema.tests.filter(t => t.OPTIONS.name !== 'required');
53805
- return schema;
53806
- });
53807
- }
53808
- length(length, message = string.length) {
53809
- return this.test({
53810
- message,
53811
- name: 'length',
53812
- exclusive: true,
53813
- params: {
53814
- length
53815
- },
53816
- skipAbsent: true,
53817
- test(value) {
53818
- return value.length === this.resolve(length);
53819
- }
53820
- });
53821
- }
53822
- min(min, message = string.min) {
53823
- return this.test({
53824
- message,
53825
- name: 'min',
53826
- exclusive: true,
53827
- params: {
53828
- min
53829
- },
53830
- skipAbsent: true,
53831
- test(value) {
53832
- return value.length >= this.resolve(min);
53833
- }
53834
- });
53835
- }
53836
- max(max, message = string.max) {
53837
- return this.test({
53838
- name: 'max',
53839
- exclusive: true,
53840
- message,
53841
- params: {
53842
- max
53843
- },
53844
- skipAbsent: true,
53845
- test(value) {
53846
- return value.length <= this.resolve(max);
53847
- }
53848
- });
53849
- }
53850
- matches(regex, options) {
53851
- let excludeEmptyString = false;
53852
- let message;
53853
- let name;
53854
- if (options) {
53855
- if (typeof options === 'object') {
53856
- ({
53857
- excludeEmptyString = false,
53858
- message,
53859
- name
53860
- } = options);
53861
- } else {
53862
- message = options;
53863
- }
53864
- }
53865
- return this.test({
53866
- name: name || 'matches',
53867
- message: message || string.matches,
53868
- params: {
53869
- regex
53870
- },
53871
- skipAbsent: true,
53872
- test: value => value === '' && excludeEmptyString || value.search(regex) !== -1
53873
- });
53874
- }
53875
- email(message = string.email) {
53876
- return this.matches(rEmail, {
53877
- name: 'email',
53878
- message,
53879
- excludeEmptyString: true
53880
- });
53881
- }
53882
- url(message = string.url) {
53883
- return this.matches(rUrl, {
53884
- name: 'url',
53885
- message,
53886
- excludeEmptyString: true
53887
- });
53888
- }
53889
- uuid(message = string.uuid) {
53890
- return this.matches(rUUID, {
53891
- name: 'uuid',
53892
- message,
53893
- excludeEmptyString: false
53894
- });
53895
- }
53896
- datetime(options) {
53897
- let message = '';
53898
- let allowOffset;
53899
- let precision;
53900
- if (options) {
53901
- if (typeof options === 'object') {
53902
- ({
53903
- message = '',
53904
- allowOffset = false,
53905
- precision = undefined
53906
- } = options);
53907
- } else {
53908
- message = options;
53909
- }
53910
- }
53911
- return this.matches(rIsoDateTime, {
53912
- name: 'datetime',
53913
- message: message || string.datetime,
53914
- excludeEmptyString: true
53915
- }).test({
53916
- name: 'datetime_offset',
53917
- message: message || string.datetime_offset,
53918
- params: {
53919
- allowOffset
53920
- },
53921
- skipAbsent: true,
53922
- test: value => {
53923
- if (!value || allowOffset) return true;
53924
- const struct = parseDateStruct(value);
53925
- if (!struct) return false;
53926
- return !!struct.z;
53927
- }
53928
- }).test({
53929
- name: 'datetime_precision',
53930
- message: message || string.datetime_precision,
53931
- params: {
53932
- precision
53933
- },
53934
- skipAbsent: true,
53935
- test: value => {
53936
- if (!value || precision == undefined) return true;
53937
- const struct = parseDateStruct(value);
53938
- if (!struct) return false;
53939
- return struct.precision === precision;
53940
- }
53941
- });
53942
- }
53943
-
53944
- //-- transforms --
53945
- ensure() {
53946
- return this.default('').transform(val => val === null ? '' : val);
53947
- }
53948
- trim(message = string.trim) {
53949
- return this.transform(val => val != null ? val.trim() : val).test({
53950
- message,
53951
- name: 'trim',
53952
- test: isTrimmed
53953
- });
53954
- }
53955
- lowercase(message = string.lowercase) {
53956
- return this.transform(value => !isAbsent(value) ? value.toLowerCase() : value).test({
53957
- message,
53958
- name: 'string_case',
53959
- exclusive: true,
53960
- skipAbsent: true,
53961
- test: value => isAbsent(value) || value === value.toLowerCase()
53962
- });
53963
- }
53964
- uppercase(message = string.uppercase) {
53965
- return this.transform(value => !isAbsent(value) ? value.toUpperCase() : value).test({
53966
- message,
53967
- name: 'string_case',
53968
- exclusive: true,
53969
- skipAbsent: true,
53970
- test: value => isAbsent(value) || value === value.toUpperCase()
53971
- });
53972
- }
53973
- }
53974
- create$6.prototype = StringSchema.prototype;
53975
-
53976
- //
53977
- // String Interfaces
53978
- //
53979
-
53980
- let isNaN$1 = value => value != +value;
53981
- function create$5() {
53982
- return new NumberSchema();
53983
- }
53984
- class NumberSchema extends Schema {
53985
- constructor() {
53986
- super({
53987
- type: 'number',
53988
- check(value) {
53989
- if (value instanceof Number) value = value.valueOf();
53990
- return typeof value === 'number' && !isNaN$1(value);
53991
- }
53992
- });
53993
- this.withMutation(() => {
53994
- this.transform((value, _raw, ctx) => {
53995
- if (!ctx.spec.coerce) return value;
53996
- let parsed = value;
53997
- if (typeof parsed === 'string') {
53998
- parsed = parsed.replace(/\s/g, '');
53999
- if (parsed === '') return NaN;
54000
- // don't use parseFloat to avoid positives on alpha-numeric strings
54001
- parsed = +parsed;
54002
- }
54003
-
54004
- // null -> NaN isn't useful; treat all nulls as null and let it fail on
54005
- // nullability check vs TypeErrors
54006
- if (ctx.isType(parsed) || parsed === null) return parsed;
54007
- return parseFloat(parsed);
54008
- });
54009
- });
54010
- }
54011
- min(min, message = number.min) {
54012
- return this.test({
54013
- message,
54014
- name: 'min',
54015
- exclusive: true,
54016
- params: {
54017
- min
54018
- },
54019
- skipAbsent: true,
54020
- test(value) {
54021
- return value >= this.resolve(min);
54022
- }
54023
- });
54024
- }
54025
- max(max, message = number.max) {
54026
- return this.test({
54027
- message,
54028
- name: 'max',
54029
- exclusive: true,
54030
- params: {
54031
- max
54032
- },
54033
- skipAbsent: true,
54034
- test(value) {
54035
- return value <= this.resolve(max);
54036
- }
54037
- });
54038
- }
54039
- lessThan(less, message = number.lessThan) {
54040
- return this.test({
54041
- message,
54042
- name: 'max',
54043
- exclusive: true,
54044
- params: {
54045
- less
54046
- },
54047
- skipAbsent: true,
54048
- test(value) {
54049
- return value < this.resolve(less);
54050
- }
54051
- });
54052
- }
54053
- moreThan(more, message = number.moreThan) {
54054
- return this.test({
54055
- message,
54056
- name: 'min',
54057
- exclusive: true,
54058
- params: {
54059
- more
54060
- },
54061
- skipAbsent: true,
54062
- test(value) {
54063
- return value > this.resolve(more);
54064
- }
54065
- });
54066
- }
54067
- positive(msg = number.positive) {
54068
- return this.moreThan(0, msg);
54069
- }
54070
- negative(msg = number.negative) {
54071
- return this.lessThan(0, msg);
54072
- }
54073
- integer(message = number.integer) {
54074
- return this.test({
54075
- name: 'integer',
54076
- message,
54077
- skipAbsent: true,
54078
- test: val => Number.isInteger(val)
54079
- });
54080
- }
54081
- truncate() {
54082
- return this.transform(value => !isAbsent(value) ? value | 0 : value);
54083
- }
54084
- round(method) {
54085
- var _method;
54086
- let avail = ['ceil', 'floor', 'round', 'trunc'];
54087
- method = ((_method = method) == null ? void 0 : _method.toLowerCase()) || 'round';
54088
-
54089
- // this exists for symemtry with the new Math.trunc
54090
- if (method === 'trunc') return this.truncate();
54091
- if (avail.indexOf(method.toLowerCase()) === -1) throw new TypeError('Only valid options for round() are: ' + avail.join(', '));
54092
- return this.transform(value => !isAbsent(value) ? Math[method](value) : value);
54093
- }
54094
- }
54095
- create$5.prototype = NumberSchema.prototype;
54096
-
54097
- //
54098
- // Number Interfaces
54099
- //
54100
-
54101
- let invalidDate = new Date('');
54102
- let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
54103
- class DateSchema extends Schema {
54104
- constructor() {
54105
- super({
54106
- type: 'date',
54107
- check(v) {
54108
- return isDate(v) && !isNaN(v.getTime());
54109
- }
54110
- });
54111
- this.withMutation(() => {
54112
- this.transform((value, _raw, ctx) => {
54113
- // null -> InvalidDate isn't useful; treat all nulls as null and let it fail on
54114
- // nullability check vs TypeErrors
54115
- if (!ctx.spec.coerce || ctx.isType(value) || value === null) return value;
54116
- value = parseIsoDate(value);
54117
-
54118
- // 0 is a valid timestamp equivalent to 1970-01-01T00:00:00Z(unix epoch) or before.
54119
- return !isNaN(value) ? new Date(value) : DateSchema.INVALID_DATE;
54120
- });
54121
- });
54122
- }
54123
- prepareParam(ref, name) {
54124
- let param;
54125
- if (!Reference.isRef(ref)) {
54126
- let cast = this.cast(ref);
54127
- if (!this._typeCheck(cast)) throw new TypeError(`\`${name}\` must be a Date or a value that can be \`cast()\` to a Date`);
54128
- param = cast;
54129
- } else {
54130
- param = ref;
54131
- }
54132
- return param;
54133
- }
54134
- min(min, message = date.min) {
54135
- let limit = this.prepareParam(min, 'min');
54136
- return this.test({
54137
- message,
54138
- name: 'min',
54139
- exclusive: true,
54140
- params: {
54141
- min
54142
- },
54143
- skipAbsent: true,
54144
- test(value) {
54145
- return value >= this.resolve(limit);
54146
- }
54147
- });
54148
- }
54149
- max(max, message = date.max) {
54150
- let limit = this.prepareParam(max, 'max');
54151
- return this.test({
54152
- message,
54153
- name: 'max',
54154
- exclusive: true,
54155
- params: {
54156
- max
54157
- },
54158
- skipAbsent: true,
54159
- test(value) {
54160
- return value <= this.resolve(limit);
54161
- }
54162
- });
54163
- }
54164
- }
54165
- DateSchema.INVALID_DATE = invalidDate;
54166
- DateSchema.prototype;
54167
-
54168
- // @ts-expect-error
54169
- function sortFields(fields, excludedEdges = []) {
54170
- let edges = [];
54171
- let nodes = new Set();
54172
- let excludes = new Set(excludedEdges.map(([a, b]) => `${a}-${b}`));
54173
- function addNode(depPath, key) {
54174
- let node = propertyExpr.split(depPath)[0];
54175
- nodes.add(node);
54176
- if (!excludes.has(`${key}-${node}`)) edges.push([key, node]);
54177
- }
54178
- for (const key of Object.keys(fields)) {
54179
- let value = fields[key];
54180
- nodes.add(key);
54181
- if (Reference.isRef(value) && value.isSibling) addNode(value.path, key);else if (isSchema(value) && 'deps' in value) value.deps.forEach(path => addNode(path, key));
54182
- }
54183
- return toposort$1.array(Array.from(nodes), edges).reverse();
54184
- }
54185
-
54186
- function findIndex(arr, err) {
54187
- let idx = Infinity;
54188
- arr.some((key, ii) => {
54189
- var _err$path;
54190
- if ((_err$path = err.path) != null && _err$path.includes(key)) {
54191
- idx = ii;
54192
- return true;
54193
- }
54194
- });
54195
- return idx;
54196
- }
54197
- function sortByKeyOrder(keys) {
54198
- return (a, b) => {
54199
- return findIndex(keys, a) - findIndex(keys, b);
54200
- };
54201
- }
54202
-
54203
- const parseJson = (value, _, ctx) => {
54204
- if (typeof value !== 'string') {
54205
- return value;
54206
- }
54207
- let parsed = value;
54208
- try {
54209
- parsed = JSON.parse(value);
54210
- } catch (err) {
54211
- /* */
54212
- }
54213
- return ctx.isType(parsed) ? parsed : value;
54214
- };
54215
-
54216
- // @ts-ignore
54217
- function deepPartial(schema) {
54218
- if ('fields' in schema) {
54219
- const partial = {};
54220
- for (const [key, fieldSchema] of Object.entries(schema.fields)) {
54221
- partial[key] = deepPartial(fieldSchema);
54222
- }
54223
- return schema.setFields(partial);
54224
- }
54225
- if (schema.type === 'array') {
54226
- const nextArray = schema.optional();
54227
- if (nextArray.innerType) nextArray.innerType = deepPartial(nextArray.innerType);
54228
- return nextArray;
54229
- }
54230
- if (schema.type === 'tuple') {
54231
- return schema.optional().clone({
54232
- types: schema.spec.types.map(deepPartial)
54233
- });
54234
- }
54235
- if ('optional' in schema) {
54236
- return schema.optional();
54237
- }
54238
- return schema;
54239
- }
54240
- const deepHas = (obj, p) => {
54241
- const path = [...propertyExpr.normalizePath(p)];
54242
- if (path.length === 1) return path[0] in obj;
54243
- let last = path.pop();
54244
- let parent = propertyExpr.getter(propertyExpr.join(path), true)(obj);
54245
- return !!(parent && last in parent);
54246
- };
54247
- let isObject = obj => Object.prototype.toString.call(obj) === '[object Object]';
54248
- function unknown(ctx, value) {
54249
- let known = Object.keys(ctx.fields);
54250
- return Object.keys(value).filter(key => known.indexOf(key) === -1);
54251
- }
54252
- const defaultSort = sortByKeyOrder([]);
54253
- function create$3(spec) {
54254
- return new ObjectSchema(spec);
54255
- }
54256
- class ObjectSchema extends Schema {
54257
- constructor(spec) {
54258
- super({
54259
- type: 'object',
54260
- check(value) {
54261
- return isObject(value) || typeof value === 'function';
54262
- }
54263
- });
54264
- this.fields = Object.create(null);
54265
- this._sortErrors = defaultSort;
54266
- this._nodes = [];
54267
- this._excludedEdges = [];
54268
- this.withMutation(() => {
54269
- if (spec) {
54270
- this.shape(spec);
54271
- }
54272
- });
54273
- }
54274
- _cast(_value, options = {}) {
54275
- var _options$stripUnknown;
54276
- let value = super._cast(_value, options);
54277
-
54278
- //should ignore nulls here
54279
- if (value === undefined) return this.getDefault(options);
54280
- if (!this._typeCheck(value)) return value;
54281
- let fields = this.fields;
54282
- let strip = (_options$stripUnknown = options.stripUnknown) != null ? _options$stripUnknown : this.spec.noUnknown;
54283
- let props = [].concat(this._nodes, Object.keys(value).filter(v => !this._nodes.includes(v)));
54284
- let intermediateValue = {}; // is filled during the transform below
54285
- let innerOptions = Object.assign({}, options, {
54286
- parent: intermediateValue,
54287
- __validating: options.__validating || false
54288
- });
54289
- let isChanged = false;
54290
- for (const prop of props) {
54291
- let field = fields[prop];
54292
- let exists = (prop in value);
54293
- if (field) {
54294
- let fieldValue;
54295
- let inputValue = value[prop];
54296
-
54297
- // safe to mutate since this is fired in sequence
54298
- innerOptions.path = (options.path ? `${options.path}.` : '') + prop;
54299
- field = field.resolve({
54300
- value: inputValue,
54301
- context: options.context,
54302
- parent: intermediateValue
54303
- });
54304
- let fieldSpec = field instanceof Schema ? field.spec : undefined;
54305
- let strict = fieldSpec == null ? void 0 : fieldSpec.strict;
54306
- if (fieldSpec != null && fieldSpec.strip) {
54307
- isChanged = isChanged || prop in value;
54308
- continue;
54309
- }
54310
- fieldValue = !options.__validating || !strict ?
54311
- // TODO: use _cast, this is double resolving
54312
- field.cast(value[prop], innerOptions) : value[prop];
54313
- if (fieldValue !== undefined) {
54314
- intermediateValue[prop] = fieldValue;
54315
- }
54316
- } else if (exists && !strip) {
54317
- intermediateValue[prop] = value[prop];
54318
- }
54319
- if (exists !== prop in intermediateValue || intermediateValue[prop] !== value[prop]) {
54320
- isChanged = true;
54321
- }
54322
- }
54323
- return isChanged ? intermediateValue : value;
54324
- }
54325
- _validate(_value, options = {}, panic, next) {
54326
- let {
54327
- from = [],
54328
- originalValue = _value,
54329
- recursive = this.spec.recursive
54330
- } = options;
54331
- options.from = [{
54332
- schema: this,
54333
- value: originalValue
54334
- }, ...from];
54335
- // this flag is needed for handling `strict` correctly in the context of
54336
- // validation vs just casting. e.g strict() on a field is only used when validating
54337
- options.__validating = true;
54338
- options.originalValue = originalValue;
54339
- super._validate(_value, options, panic, (objectErrors, value) => {
54340
- if (!recursive || !isObject(value)) {
54341
- next(objectErrors, value);
54342
- return;
54343
- }
54344
- originalValue = originalValue || value;
54345
- let tests = [];
54346
- for (let key of this._nodes) {
54347
- let field = this.fields[key];
54348
- if (!field || Reference.isRef(field)) {
54349
- continue;
54350
- }
54351
- tests.push(field.asNestedTest({
54352
- options,
54353
- key,
54354
- parent: value,
54355
- parentPath: options.path,
54356
- originalParent: originalValue
54357
- }));
54358
- }
54359
- this.runTests({
54360
- tests,
54361
- value,
54362
- originalValue,
54363
- options
54364
- }, panic, fieldErrors => {
54365
- next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value);
54366
- });
54367
- });
54368
- }
54369
- clone(spec) {
54370
- const next = super.clone(spec);
54371
- next.fields = Object.assign({}, this.fields);
54372
- next._nodes = this._nodes;
54373
- next._excludedEdges = this._excludedEdges;
54374
- next._sortErrors = this._sortErrors;
54375
- return next;
54376
- }
54377
- concat(schema) {
54378
- let next = super.concat(schema);
54379
- let nextFields = next.fields;
54380
- for (let [field, schemaOrRef] of Object.entries(this.fields)) {
54381
- const target = nextFields[field];
54382
- nextFields[field] = target === undefined ? schemaOrRef : target;
54383
- }
54384
- return next.withMutation(s =>
54385
- // XXX: excludes here is wrong
54386
- s.setFields(nextFields, [...this._excludedEdges, ...schema._excludedEdges]));
54387
- }
54388
- _getDefault(options) {
54389
- if ('default' in this.spec) {
54390
- return super._getDefault(options);
54391
- }
54392
-
54393
- // if there is no default set invent one
54394
- if (!this._nodes.length) {
54395
- return undefined;
54396
- }
54397
- let dft = {};
54398
- this._nodes.forEach(key => {
54399
- var _innerOptions;
54400
- const field = this.fields[key];
54401
- let innerOptions = options;
54402
- if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
54403
- innerOptions = Object.assign({}, innerOptions, {
54404
- parent: innerOptions.value,
54405
- value: innerOptions.value[key]
54406
- });
54407
- }
54408
- dft[key] = field && 'getDefault' in field ? field.getDefault(innerOptions) : undefined;
54409
- });
54410
- return dft;
54411
- }
54412
- setFields(shape, excludedEdges) {
54413
- let next = this.clone();
54414
- next.fields = shape;
54415
- next._nodes = sortFields(shape, excludedEdges);
54416
- next._sortErrors = sortByKeyOrder(Object.keys(shape));
54417
- // XXX: this carries over edges which may not be what you want
54418
- if (excludedEdges) next._excludedEdges = excludedEdges;
54419
- return next;
54420
- }
54421
- shape(additions, excludes = []) {
54422
- return this.clone().withMutation(next => {
54423
- let edges = next._excludedEdges;
54424
- if (excludes.length) {
54425
- if (!Array.isArray(excludes[0])) excludes = [excludes];
54426
- edges = [...next._excludedEdges, ...excludes];
54427
- }
54428
-
54429
- // XXX: excludes here is wrong
54430
- return next.setFields(Object.assign(next.fields, additions), edges);
54431
- });
54432
- }
54433
- partial() {
54434
- const partial = {};
54435
- for (const [key, schema] of Object.entries(this.fields)) {
54436
- partial[key] = 'optional' in schema && schema.optional instanceof Function ? schema.optional() : schema;
54437
- }
54438
- return this.setFields(partial);
54439
- }
54440
- deepPartial() {
54441
- const next = deepPartial(this);
54442
- return next;
54443
- }
54444
- pick(keys) {
54445
- const picked = {};
54446
- for (const key of keys) {
54447
- if (this.fields[key]) picked[key] = this.fields[key];
54448
- }
54449
- return this.setFields(picked, this._excludedEdges.filter(([a, b]) => keys.includes(a) && keys.includes(b)));
54450
- }
54451
- omit(keys) {
54452
- const remaining = [];
54453
- for (const key of Object.keys(this.fields)) {
54454
- if (keys.includes(key)) continue;
54455
- remaining.push(key);
54456
- }
54457
- return this.pick(remaining);
54458
- }
54459
- from(from, to, alias) {
54460
- let fromGetter = propertyExpr.getter(from, true);
54461
- return this.transform(obj => {
54462
- if (!obj) return obj;
54463
- let newObj = obj;
54464
- if (deepHas(obj, from)) {
54465
- newObj = Object.assign({}, obj);
54466
- if (!alias) delete newObj[from];
54467
- newObj[to] = fromGetter(obj);
54468
- }
54469
- return newObj;
54470
- });
54471
- }
54472
-
54473
- /** Parse an input JSON string to an object */
54474
- json() {
54475
- return this.transform(parseJson);
54476
- }
54477
- noUnknown(noAllow = true, message = object.noUnknown) {
54478
- if (typeof noAllow !== 'boolean') {
54479
- message = noAllow;
54480
- noAllow = true;
54481
- }
54482
- let next = this.test({
54483
- name: 'noUnknown',
54484
- exclusive: true,
54485
- message: message,
54486
- test(value) {
54487
- if (value == null) return true;
54488
- const unknownKeys = unknown(this.schema, value);
54489
- return !noAllow || unknownKeys.length === 0 || this.createError({
54490
- params: {
54491
- unknown: unknownKeys.join(', ')
54492
- }
54493
- });
54494
- }
54495
- });
54496
- next.spec.noUnknown = noAllow;
54497
- return next;
54498
- }
54499
- unknown(allow = true, message = object.noUnknown) {
54500
- return this.noUnknown(!allow, message);
54501
- }
54502
- transformKeys(fn) {
54503
- return this.transform(obj => {
54504
- if (!obj) return obj;
54505
- const result = {};
54506
- for (const key of Object.keys(obj)) result[fn(key)] = obj[key];
54507
- return result;
54508
- });
54509
- }
54510
- camelCase() {
54511
- return this.transformKeys(tinyCase.camelCase);
54512
- }
54513
- snakeCase() {
54514
- return this.transformKeys(tinyCase.snakeCase);
54515
- }
54516
- constantCase() {
54517
- return this.transformKeys(key => tinyCase.snakeCase(key).toUpperCase());
54518
- }
54519
- describe(options) {
54520
- const next = (options ? this.resolve(options) : this).clone();
54521
- const base = super.describe(options);
54522
- base.fields = {};
54523
- for (const [key, value] of Object.entries(next.fields)) {
54524
- var _innerOptions2;
54525
- let innerOptions = options;
54526
- if ((_innerOptions2 = innerOptions) != null && _innerOptions2.value) {
54527
- innerOptions = Object.assign({}, innerOptions, {
54528
- parent: innerOptions.value,
54529
- value: innerOptions.value[key]
54530
- });
54531
- }
54532
- base.fields[key] = value.describe(innerOptions);
54533
- }
54534
- return base;
54535
- }
54536
- }
54537
- create$3.prototype = ObjectSchema.prototype;
54538
-
54539
- var t=function(t,n,e){if(t&&"reportValidity"in t){var i=get(e,n);t.setCustomValidity(i&&i.message||""),t.reportValidity();}},n=function(r,n){var e=function(e){var i=n.fields[e];i&&i.ref&&"reportValidity"in i.ref?t(i.ref,e,r):i.refs&&i.refs.forEach(function(n){return t(n,e,r)});};for(var i in n.fields)e(i);},e=function(r){return r instanceof Date},i=function(r){return null==r},a=function(r){return "object"==typeof r},o$1=function(r){return !i(r)&&!Array.isArray(r)&&a(r)&&!e(r)},f=function(r){return /^\w*$/.test(r)},s=function(r,t,n){for(var e=-1,i=f(t)?[t]:function(r){return t=r.replace(/["|']|\]/g,"").split(/\.|\[/),Array.isArray(t)?t.filter(Boolean):[];var t;}(t),a=i.length,s=a-1;++e<a;){var u=i[e],c=n;if(e!==s){var l=r[u];c=o$1(l)||Array.isArray(l)?l:isNaN(+i[e+1])?{}:[];}r[u]=c,r=r[u];}return r},u=function(t,e){e.shouldUseNativeValidation&&n(t,e);var i={};for(var a in t){var o=get(e.fields,a),f=Object.assign(t[a]||{},{ref:o&&o.ref});if(c(e.names||Object.keys(t),a)){var u=Object.assign({},get(i,a));s(u,"root",f),s(i,a,u);}else s(i,a,f);}return i},c=function(r,t){return r.some(function(r){return r.startsWith(t+".")})};
54540
-
54541
- function o(o,n$1,a){return void 0===n$1&&(n$1={}),void 0===a&&(a={}),function(s,i,c){try{return Promise.resolve(function(t,r){try{var u=(n$1.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(o["sync"===a.mode?"validateSync":"validate"](s,Object.assign({abortEarly:!1},n$1,{context:i}))).then(function(t){return c.shouldUseNativeValidation&&n({},c),{values:a.raw?s:t,errors:{}}}));}catch(e){return r(e)}return u&&u.then?u.then(void 0,r):u}(0,function(e){if(!e.inner)throw e;return {values:{},errors:u((o=e,n=!c.shouldUseNativeValidation&&"all"===c.criteriaMode,(o.inner||[]).reduce(function(e,t){if(e[t.path]||(e[t.path]={message:t.message,type:t.type}),n){var o=e[t.path].types,a=o&&o[t.type];e[t.path]=appendErrors(t.path,n,e,t.type,a?[].concat(a,t.message):t.message);}return e},{})),c)};var o,n;}))}catch(e){return Promise.reject(e)}}}
54542
-
54543
- const FormRenderWrapper = ({ formArray, name, setFormFunctions, numberOfColumns = 3 }) => {
54544
- const initialValues = {};
54545
- const validationShape = {};
54546
- formArray.forEach((field) => {
54547
- switch (field.inputType) {
54548
- case "text":
54549
- initialValues[field.name] = "";
54550
- if (field.required) {
54551
- validationShape[field.name] = create$6()
54552
- .typeError(`Select ${field.label}`)
54553
- .required(field.errorMessage);
54554
- }
54555
- break;
54556
- case "number":
54557
- initialValues[field.name] = null;
54558
- if (field.required) {
54559
- validationShape[field.name] = create$5()
54560
- .nullable()
54561
- .typeError(`Enters ${field.label}`)
54562
- .required(field.errorMessage);
54563
- }
54564
- break;
54565
- case "password":
54566
- initialValues[field.name] = '';
54567
- if (field.required) {
54568
- validationShape[field.name] = create$5()
54569
- .nullable()
54570
- .typeError(`Enters ${field.label}`)
54571
- .required(field.errorMessage);
50693
+ const customTheme = createTheme({
50694
+ breakpoints: {
50695
+ values: {
50696
+ xs: 0,
50697
+ sm: 600,
50698
+ md: 900,
50699
+ lg: 1200,
50700
+ xl: 1536,
50701
+ },
50702
+ },
50703
+ typography: {
50704
+ fontFamily: 'Roboto-Reg'
50705
+ },
50706
+ palette: {
50707
+ // primary: {
50708
+ // // main: 'linear-gradient(135deg, #6379c3 0%, #546ee5 60%)',
50709
+ // },
50710
+ // secondary: {
50711
+ // main: 'linear-gradient(135deg, #6379c3 0%, #546ee5 60%)',
50712
+ // },
50713
+ },
50714
+ components: {
50715
+ MuiInputLabel: {
50716
+ styleOverrides: {
50717
+ root: {
50718
+ fontSize: '12px',
50719
+ },
50720
+ },
50721
+ },
50722
+ MuiInputBase: {
50723
+ styleOverrides: {
50724
+ root: {
50725
+ fontSize: '12px',
50726
+ input: {
50727
+ padding: '6.38px 14px',
50728
+ }
54572
50729
  }
54573
- break;
54574
- case "select":
54575
- initialValues[field.name] = "";
54576
- if (field.required) {
54577
- validationShape[field.name] = create$6()
54578
- .typeError(`Select ${field.label}`)
54579
- .required(field.errorMessage);
50730
+ }
50731
+ },
50732
+ MuiRadio: {
50733
+ styleOverrides: {
50734
+ root: {
50735
+ padding: '4px 4px 0 8px'
54580
50736
  }
54581
- break;
54582
- case "multiselect":
54583
- initialValues[field.name] = null;
54584
- if (field.required) {
54585
- validationShape[field.name] = validationShape[field.name] = create$6()
54586
- .typeError(`Select atleast one ${field.label}`)
54587
- .required(field.errorMessage);
50737
+ }
50738
+ },
50739
+ MuiSelect: {
50740
+ styleOverrides: {
50741
+ select: {
50742
+ padding: '6.38px 32px 6.38px 14px'
54588
50743
  }
54589
- break;
54590
- default:
54591
- initialValues[field.name] = null; // default value if inputType is not recognized
54592
- if (field.required) {
54593
- validationShape[field.name] = create$8().required(field.errorMessage);
50744
+ }
50745
+ },
50746
+ MuiButton: {
50747
+ styleOverrides: {
50748
+ root: {
50749
+ fontFamily: 'Roboto-Reg',
50750
+ textTransform: 'none'
54594
50751
  }
54595
- break;
50752
+ }
54596
50753
  }
54597
- });
54598
- const validationSchema = create$3().shape(validationShape);
54599
- const { register, handleSubmit, setValue, clearErrors, watch, control, getValues, reset, formState: { errors }, } = useForm({
54600
- defaultValues: initialValues,
54601
- resolver: o(validationSchema),
54602
- });
54603
- React$1.useEffect(() => {
54604
- setFormFunctions({
54605
- handleSubmit,
54606
- setValue,
54607
- clearErrors,
54608
- watch,
54609
- control,
54610
- getValues,
54611
- reset,
54612
- });
54613
- }, [
54614
- handleSubmit,
54615
- setFormFunctions,
54616
- setValue,
54617
- watch,
54618
- register,
54619
- control,
54620
- errors,
54621
- getValues,
54622
- reset,
54623
- clearErrors,
54624
- ]);
54625
- return jsxRuntimeExports.jsx(FormComponent, Object.assign({ container: true, margin: "auto" }, { children: formArray.map((item, i) => {
54626
- return (jsxRuntimeExports.jsx(Formitem, Object.assign({ container: true, sx: item.CustomProps, noOfColumn: item.numberOfColumns || numberOfColumns }, { children: jsxRuntimeExports.jsx(RenderForm, { item: item, register: register, control: control, errors: errors, getValues: getValues, clearErrors: clearErrors, setValue: setValue }) }), i));
54627
- }) }));
50754
+ }
50755
+ });
50756
+
50757
+ const FormRenderWrapper = ({ formArray, name, numberOfColumns = 3, form, }) => {
50758
+ // const formContext=useFormControl({
50759
+ // })
50760
+ // useEffect(() => {
50761
+ // // form.reset(initialValues, { resolver: yupResolver(validationSchema) });
50762
+ // }, [formArray, validationSchema, initialValues]);
50763
+ return (jsxRuntimeExports.jsx(ThemeProvider, Object.assign({ theme: customTheme }, { children: jsxRuntimeExports.jsx(FormComponent, Object.assign({ container: true, margin: "auto" }, { children: formArray.map((item, i) => {
50764
+ return (jsxRuntimeExports.jsx(Formitem, Object.assign({ container: true, sx: item.CustomProps, noOfColumn: item.numberOfColumns || numberOfColumns }, { children: jsxRuntimeExports.jsx(RenderForm, { item: item, register: form.register, control: form.control, errors: form.formState.errors, getValues: form.getValues, clearErrors: form.clearErrors, setValue: form.setValue }) }), i));
50765
+ }) })) })));
54628
50766
  };
54629
50767
 
54630
50768
  exports.Button = Button$1;