@bonlineza/luxity-lib 2.36.1-beta.4 → 2.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/Accordion.js +116 -76
  2. package/AddInterest.js +777 -440
  3. package/AddProductInterest.js +644 -485
  4. package/BrandSelector.js +336 -176
  5. package/Checkbox.js +101 -68
  6. package/CheckboxButton.js +124 -79
  7. package/CommunicationPreferenceOptionsRenderer.js +169 -159
  8. package/CommunicationPreferenceSection.js +178 -166
  9. package/CommunicationPreferences.js +427 -549
  10. package/ConditionSelector.js +336 -174
  11. package/CountryCodeSelect.js +10 -7
  12. package/CurrencyInputFormatter.js +56 -29
  13. package/CurrencySelect.js +49 -23
  14. package/DropdownSelector.js +92 -68
  15. package/GALink.js +16 -6
  16. package/GenderSelector.js +142 -88
  17. package/GraphQLDropdownSelector.js +1511 -933
  18. package/GraphQLMultiSelector.js +274 -141
  19. package/IconHeader.js +25 -11
  20. package/IconWrapper.js +7 -3
  21. package/InterestCatSelector.js +74 -34
  22. package/InterestItem.js +187 -103
  23. package/Interests.js +1466 -917
  24. package/InterestsSubheading.js +10 -5
  25. package/InvertedTextButton.js +63 -27
  26. package/LuxityAppSideNav.js +22 -19
  27. package/LuxityDesktopHeader.js +663 -549
  28. package/LuxityFooter.js +325 -434
  29. package/LuxityGraphQLDropdownSelector.js +1543 -949
  30. package/LuxityGraphQLMultiselector.js +321 -167
  31. package/LuxityMobileHeader.js +807 -681
  32. package/LuxityPageReady.js +136 -74
  33. package/LuxityProductInterestItem.js +175 -97
  34. package/LuxitySideNav.js +310 -382
  35. package/MaterialSelector.js +1550 -955
  36. package/ModelSelector.js +1550 -955
  37. package/NotificationDropDown.js +221 -122
  38. package/Notify.js +1 -0
  39. package/OutlinePrimaryButton.js +58 -26
  40. package/PriceRangeSelector.js +281 -168
  41. package/PrimaryButton.js +58 -26
  42. package/RadioButtons.js +140 -114
  43. package/RangeSlider.js +242 -152
  44. package/RareStepFooter.js +41 -27
  45. package/RareStepHeader.js +190 -139
  46. package/ReactSelectWrapper.js +1 -0
  47. package/SecondaryButton.js +58 -26
  48. package/ShoeSizeRangeSelector.js +260 -162
  49. package/ShoeSizeSelector.js +263 -158
  50. package/SimpleErrorBoundary.js +106 -59
  51. package/StyleSelector.js +336 -176
  52. package/TextButton.js +58 -26
  53. package/Tooltip.js +39 -17
  54. package/Tracking.js +1 -0
  55. package/WrapperButton.js +43 -20
  56. package/build/bundle.css +1 -1
  57. package/build/bundle.js +2973 -2457
  58. package/package.json +2 -3
  59. package/svg/Accessories.js +13 -6
  60. package/svg/Account.js +13 -6
  61. package/svg/Add.js +13 -6
  62. package/svg/ArrowRight.js +13 -6
  63. package/svg/Bags.js +13 -6
  64. package/svg/BurgerMenu.js +13 -6
  65. package/svg/Calendar.js +13 -6
  66. package/svg/CalendarCircled.js +13 -6
  67. package/svg/CheckCircled.js +13 -6
  68. package/svg/Close.js +13 -6
  69. package/svg/Clothing.js +13 -6
  70. package/svg/Dot.js +13 -6
  71. package/svg/Edit.js +13 -6
  72. package/svg/Eye.js +13 -6
  73. package/svg/FileAttach.js +13 -6
  74. package/svg/FileAttachCircled.js +13 -6
  75. package/svg/LightBulb.js +13 -6
  76. package/svg/Logo.js +13 -6
  77. package/svg/LuxityMenu.js +13 -6
  78. package/svg/Minus.js +13 -6
  79. package/svg/MobileAvatar.js +13 -6
  80. package/svg/MyOrder.js +13 -6
  81. package/svg/MyPayment.js +13 -6
  82. package/svg/MyProfile.js +14 -8
  83. package/svg/MySale.js +13 -6
  84. package/svg/Notification.js +13 -6
  85. package/svg/PointerDown.js +13 -6
  86. package/svg/Search.js +13 -6
  87. package/svg/Shoes.js +13 -6
  88. package/svg/SvgWrapper.js +7 -3
  89. package/svg/Trash.js +13 -6
  90. package/svg/Watches.js +13 -6
@@ -9,132 +9,169 @@
9
9
  EllipsisLoader = EllipsisLoader && Object.prototype.hasOwnProperty.call(EllipsisLoader, 'default') ? EllipsisLoader['default'] : EllipsisLoader;
10
10
  var Notifications__default = 'default' in Notifications ? Notifications['default'] : Notifications;
11
11
 
12
- function _arrayLikeToArray(r, a) {
13
- (null == a || a > r.length) && (a = r.length);
14
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
15
- return n;
12
+ function ownKeys(object, enumerableOnly) {
13
+ var keys = Object.keys(object);
14
+
15
+ if (Object.getOwnPropertySymbols) {
16
+ var symbols = Object.getOwnPropertySymbols(object);
17
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
18
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
19
+ })), keys.push.apply(keys, symbols);
20
+ }
21
+
22
+ return keys;
16
23
  }
17
- function _arrayWithHoles(r) {
18
- if (Array.isArray(r)) return r;
24
+
25
+ function _objectSpread2(target) {
26
+ for (var i = 1; i < arguments.length; i++) {
27
+ var source = null != arguments[i] ? arguments[i] : {};
28
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
29
+ _defineProperty(target, key, source[key]);
30
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
31
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
32
+ });
33
+ }
34
+
35
+ return target;
19
36
  }
20
- function _defineProperty(e, r, t) {
21
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
22
- value: t,
23
- enumerable: !0,
24
- configurable: !0,
25
- writable: !0
26
- }) : e[r] = t, e;
37
+
38
+ function _defineProperty(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+
50
+ return obj;
27
51
  }
52
+
28
53
  function _extends() {
29
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
30
- for (var e = 1; e < arguments.length; e++) {
31
- var t = arguments[e];
32
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
33
- }
34
- return n;
35
- }, _extends.apply(null, arguments);
36
- }
37
- function _iterableToArrayLimit(r, l) {
38
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
39
- if (null != t) {
40
- var e,
41
- n,
42
- i,
43
- u,
44
- a = [],
45
- f = !0,
46
- o = !1;
47
- try {
48
- if (i = (t = t.call(r)).next, 0 === l) {
49
- if (Object(t) !== t) return;
50
- f = !1;
51
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
52
- } catch (r) {
53
- o = !0, n = r;
54
- } finally {
55
- try {
56
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
57
- } finally {
58
- if (o) throw n;
54
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
55
+ for (var i = 1; i < arguments.length; i++) {
56
+ var source = arguments[i];
57
+
58
+ for (var key in source) {
59
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
60
+ target[key] = source[key];
61
+ }
59
62
  }
60
63
  }
61
- return a;
62
- }
63
- }
64
- function _nonIterableRest() {
65
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
66
- }
67
- function ownKeys(e, r) {
68
- var t = Object.keys(e);
69
- if (Object.getOwnPropertySymbols) {
70
- var o = Object.getOwnPropertySymbols(e);
71
- r && (o = o.filter(function (r) {
72
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
73
- })), t.push.apply(t, o);
74
- }
75
- return t;
64
+
65
+ return target;
66
+ };
67
+ return _extends.apply(this, arguments);
76
68
  }
77
- function _objectSpread2(e) {
78
- for (var r = 1; r < arguments.length; r++) {
79
- var t = null != arguments[r] ? arguments[r] : {};
80
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
81
- _defineProperty(e, r, t[r]);
82
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
83
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
84
- });
69
+
70
+ function _objectWithoutPropertiesLoose(source, excluded) {
71
+ if (source == null) return {};
72
+ var target = {};
73
+ var sourceKeys = Object.keys(source);
74
+ var key, i;
75
+
76
+ for (i = 0; i < sourceKeys.length; i++) {
77
+ key = sourceKeys[i];
78
+ if (excluded.indexOf(key) >= 0) continue;
79
+ target[key] = source[key];
85
80
  }
86
- return e;
81
+
82
+ return target;
87
83
  }
88
- function _objectWithoutProperties(e, t) {
89
- if (null == e) return {};
90
- var o,
91
- r,
92
- i = _objectWithoutPropertiesLoose(e, t);
84
+
85
+ function _objectWithoutProperties(source, excluded) {
86
+ if (source == null) return {};
87
+
88
+ var target = _objectWithoutPropertiesLoose(source, excluded);
89
+
90
+ var key, i;
91
+
93
92
  if (Object.getOwnPropertySymbols) {
94
- var n = Object.getOwnPropertySymbols(e);
95
- for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
93
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
94
+
95
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
96
+ key = sourceSymbolKeys[i];
97
+ if (excluded.indexOf(key) >= 0) continue;
98
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
99
+ target[key] = source[key];
100
+ }
96
101
  }
97
- return i;
102
+
103
+ return target;
98
104
  }
99
- function _objectWithoutPropertiesLoose(r, e) {
100
- if (null == r) return {};
101
- var t = {};
102
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
103
- if (-1 !== e.indexOf(n)) continue;
104
- t[n] = r[n];
105
+
106
+ function _taggedTemplateLiteral(strings, raw) {
107
+ if (!raw) {
108
+ raw = strings.slice(0);
105
109
  }
106
- return t;
107
- }
108
- function _slicedToArray(r, e) {
109
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
110
- }
111
- function _taggedTemplateLiteral(e, t) {
112
- return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, {
110
+
111
+ return Object.freeze(Object.defineProperties(strings, {
113
112
  raw: {
114
- value: Object.freeze(t)
113
+ value: Object.freeze(raw)
115
114
  }
116
115
  }));
117
116
  }
118
- function _toPrimitive(t, r) {
119
- if ("object" != typeof t || !t) return t;
120
- var e = t[Symbol.toPrimitive];
121
- if (void 0 !== e) {
122
- var i = e.call(t, r || "default");
123
- if ("object" != typeof i) return i;
124
- throw new TypeError("@@toPrimitive must return a primitive value.");
125
- }
126
- return ("string" === r ? String : Number)(t);
117
+
118
+ function _slicedToArray(arr, i) {
119
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
127
120
  }
128
- function _toPropertyKey(t) {
129
- var i = _toPrimitive(t, "string");
130
- return "symbol" == typeof i ? i : i + "";
121
+
122
+ function _arrayWithHoles(arr) {
123
+ if (Array.isArray(arr)) return arr;
131
124
  }
132
- function _unsupportedIterableToArray(r, a) {
133
- if (r) {
134
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
135
- var t = {}.toString.call(r).slice(8, -1);
136
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
125
+
126
+ function _iterableToArrayLimit(arr, i) {
127
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
128
+
129
+ if (_i == null) return;
130
+ var _arr = [];
131
+ var _n = true;
132
+ var _d = false;
133
+
134
+ var _s, _e;
135
+
136
+ try {
137
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
138
+ _arr.push(_s.value);
139
+
140
+ if (i && _arr.length === i) break;
141
+ }
142
+ } catch (err) {
143
+ _d = true;
144
+ _e = err;
145
+ } finally {
146
+ try {
147
+ if (!_n && _i["return"] != null) _i["return"]();
148
+ } finally {
149
+ if (_d) throw _e;
150
+ }
137
151
  }
152
+
153
+ return _arr;
154
+ }
155
+
156
+ function _unsupportedIterableToArray(o, minLen) {
157
+ if (!o) return;
158
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
159
+ var n = Object.prototype.toString.call(o).slice(8, -1);
160
+ if (n === "Object" && o.constructor) n = o.constructor.name;
161
+ if (n === "Map" || n === "Set") return Array.from(o);
162
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
163
+ }
164
+
165
+ function _arrayLikeToArray(arr, len) {
166
+ if (len == null || len > arr.length) len = arr.length;
167
+
168
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
169
+
170
+ return arr2;
171
+ }
172
+
173
+ function _nonIterableRest() {
174
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
138
175
  }
139
176
 
140
177
  var isCheckBoxInput = (element) => element.type === 'checkbox';
@@ -171,14 +208,13 @@
171
208
  function cloneObject(data) {
172
209
  let copy;
173
210
  const isArray = Array.isArray(data);
174
- const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
175
211
  if (data instanceof Date) {
176
212
  copy = new Date(data);
177
213
  }
178
214
  else if (data instanceof Set) {
179
215
  copy = new Set(data);
180
216
  }
181
- else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
217
+ else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
182
218
  (isArray || isObject(data))) {
183
219
  copy = isArray ? [] : {};
184
220
  if (!isArray && !isPlainObject(data)) {
@@ -202,50 +238,18 @@
202
238
 
203
239
  var isUndefined = (val) => val === undefined;
204
240
 
205
- var get = (object, path, defaultValue) => {
206
- if (!path || !isObject(object)) {
241
+ var get = (obj, path, defaultValue) => {
242
+ if (!path || !isObject(obj)) {
207
243
  return defaultValue;
208
244
  }
209
- const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
210
- return isUndefined(result) || result === object
211
- ? isUndefined(object[path])
245
+ const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], obj);
246
+ return isUndefined(result) || result === obj
247
+ ? isUndefined(obj[path])
212
248
  ? defaultValue
213
- : object[path]
249
+ : obj[path]
214
250
  : result;
215
251
  };
216
252
 
217
- var isBoolean = (value) => typeof value === 'boolean';
218
-
219
- var isKey = (value) => /^\w*$/.test(value);
220
-
221
- var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
222
-
223
- var set = (object, path, value) => {
224
- let index = -1;
225
- const tempPath = isKey(path) ? [path] : stringToPath(path);
226
- const length = tempPath.length;
227
- const lastIndex = length - 1;
228
- while (++index < length) {
229
- const key = tempPath[index];
230
- let newValue = value;
231
- if (index !== lastIndex) {
232
- const objValue = object[key];
233
- newValue =
234
- isObject(objValue) || Array.isArray(objValue)
235
- ? objValue
236
- : !isNaN(+tempPath[index + 1])
237
- ? []
238
- : {};
239
- }
240
- if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
241
- return;
242
- }
243
- object[key] = newValue;
244
- object = object[key];
245
- }
246
- return object;
247
- };
248
-
249
253
  const EVENTS = {
250
254
  BLUR: 'blur',
251
255
  FOCUS_OUT: 'focusout',
@@ -333,13 +337,15 @@
333
337
 
334
338
  var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
335
339
 
336
- var shouldSubscribeByName = (name, signalName, exact) => !name ||
337
- !signalName ||
338
- name === signalName ||
339
- convertToArrayPayload(name).some((currentName) => currentName &&
340
- (exact
341
- ? currentName === signalName
342
- : currentName.startsWith(signalName) ||
340
+ var shouldSubscribeByName = (name, signalName, exact) => exact && signalName
341
+ ? name === signalName ||
342
+ (Array.isArray(name) &&
343
+ name.some((currentName) => currentName && exact && currentName === signalName))
344
+ : !name ||
345
+ !signalName ||
346
+ name === signalName ||
347
+ convertToArrayPayload(name).some((currentName) => currentName &&
348
+ (currentName.startsWith(signalName) ||
343
349
  signalName.startsWith(currentName)));
344
350
 
345
351
  function useSubscribe(props) {
@@ -397,7 +403,6 @@
397
403
  isLoading: false,
398
404
  dirtyFields: false,
399
405
  touchedFields: false,
400
- validatingFields: false,
401
406
  isValidating: false,
402
407
  isValid: false,
403
408
  errors: false,
@@ -422,7 +427,7 @@
422
427
  _mounted.current = false;
423
428
  };
424
429
  }, [control]);
425
- return React__default.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
430
+ return getProxyFormState(formState, control, _localProxyFormState.current, false);
426
431
  }
427
432
 
428
433
  var isString = (value) => typeof value === 'string';
@@ -448,7 +453,7 @@
448
453
  *
449
454
  * @example
450
455
  * ```tsx
451
- * const { control } = useForm();
456
+ * const { watch } = useForm();
452
457
  * const values = useWatch({
453
458
  * name: "fieldName"
454
459
  * control,
@@ -474,6 +479,33 @@
474
479
  return value;
475
480
  }
476
481
 
482
+ var isKey = (value) => /^\w*$/.test(value);
483
+
484
+ var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
485
+
486
+ function set(object, path, value) {
487
+ let index = -1;
488
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
489
+ const length = tempPath.length;
490
+ const lastIndex = length - 1;
491
+ while (++index < length) {
492
+ const key = tempPath[index];
493
+ let newValue = value;
494
+ if (index !== lastIndex) {
495
+ const objValue = object[key];
496
+ newValue =
497
+ isObject(objValue) || Array.isArray(objValue)
498
+ ? objValue
499
+ : !isNaN(+tempPath[index + 1])
500
+ ? []
501
+ : {};
502
+ }
503
+ object[key] = newValue;
504
+ object = object[key];
505
+ }
506
+ return object;
507
+ }
508
+
477
509
  /**
478
510
  * Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
479
511
  *
@@ -511,79 +543,17 @@
511
543
  const formState = useFormState({
512
544
  control,
513
545
  name,
514
- exact: true,
515
546
  });
516
547
  const _registerProps = React__default.useRef(control.register(name, {
517
548
  ...props.rules,
518
549
  value,
519
- ...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
520
550
  }));
521
- const fieldState = React__default.useMemo(() => Object.defineProperties({}, {
522
- invalid: {
523
- enumerable: true,
524
- get: () => !!get(formState.errors, name),
525
- },
526
- isDirty: {
527
- enumerable: true,
528
- get: () => !!get(formState.dirtyFields, name),
529
- },
530
- isTouched: {
531
- enumerable: true,
532
- get: () => !!get(formState.touchedFields, name),
533
- },
534
- isValidating: {
535
- enumerable: true,
536
- get: () => !!get(formState.validatingFields, name),
537
- },
538
- error: {
539
- enumerable: true,
540
- get: () => get(formState.errors, name),
541
- },
542
- }), [formState, name]);
543
- const field = React__default.useMemo(() => ({
544
- name,
545
- value,
546
- ...(isBoolean(disabled) || formState.disabled
547
- ? { disabled: formState.disabled || disabled }
548
- : {}),
549
- onChange: (event) => _registerProps.current.onChange({
550
- target: {
551
- value: getEventValue(event),
552
- name: name,
553
- },
554
- type: EVENTS.CHANGE,
555
- }),
556
- onBlur: () => _registerProps.current.onBlur({
557
- target: {
558
- value: get(control._formValues, name),
559
- name: name,
560
- },
561
- type: EVENTS.BLUR,
562
- }),
563
- ref: (elm) => {
564
- const field = get(control._fields, name);
565
- if (field && elm) {
566
- field._f.ref = {
567
- focus: () => elm.focus(),
568
- select: () => elm.select(),
569
- setCustomValidity: (message) => elm.setCustomValidity(message),
570
- reportValidity: () => elm.reportValidity(),
571
- };
572
- }
573
- },
574
- }), [
575
- name,
576
- control._formValues,
577
- disabled,
578
- formState.disabled,
579
- value,
580
- control._fields,
581
- ]);
551
+ _registerProps.current = control.register(name, props.rules);
582
552
  React__default.useEffect(() => {
583
553
  const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
584
554
  const updateMounted = (name, value) => {
585
555
  const field = get(control._fields, name);
586
- if (field && field._f) {
556
+ if (field) {
587
557
  field._f.mount = value;
588
558
  }
589
559
  };
@@ -595,7 +565,6 @@
595
565
  set(control._formValues, name, value);
596
566
  }
597
567
  }
598
- !isArrayField && control.register(name);
599
568
  return () => {
600
569
  (isArrayField
601
570
  ? _shouldUnregisterField && !control._state.action
@@ -611,11 +580,57 @@
611
580
  name,
612
581
  });
613
582
  }, [disabled, name, control]);
614
- return React__default.useMemo(() => ({
615
- field,
583
+ return {
584
+ field: {
585
+ name,
586
+ value,
587
+ disabled,
588
+ onChange: React__default.useCallback((event) => _registerProps.current.onChange({
589
+ target: {
590
+ value: getEventValue(event),
591
+ name: name,
592
+ },
593
+ type: EVENTS.CHANGE,
594
+ }), [name]),
595
+ onBlur: React__default.useCallback(() => _registerProps.current.onBlur({
596
+ target: {
597
+ value: get(control._formValues, name),
598
+ name: name,
599
+ },
600
+ type: EVENTS.BLUR,
601
+ }), [name, control]),
602
+ ref: (elm) => {
603
+ const field = get(control._fields, name);
604
+ if (field && elm) {
605
+ field._f.ref = {
606
+ focus: () => elm.focus(),
607
+ select: () => elm.select(),
608
+ setCustomValidity: (message) => elm.setCustomValidity(message),
609
+ reportValidity: () => elm.reportValidity(),
610
+ };
611
+ }
612
+ },
613
+ },
616
614
  formState,
617
- fieldState,
618
- }), [field, formState, fieldState]);
615
+ fieldState: Object.defineProperties({}, {
616
+ invalid: {
617
+ enumerable: true,
618
+ get: () => !!get(formState.errors, name),
619
+ },
620
+ isDirty: {
621
+ enumerable: true,
622
+ get: () => !!get(formState.dirtyFields, name),
623
+ },
624
+ isTouched: {
625
+ enumerable: true,
626
+ get: () => !!get(formState.touchedFields, name),
627
+ },
628
+ error: {
629
+ enumerable: true,
630
+ get: () => get(formState.errors, name),
631
+ },
632
+ }),
633
+ };
619
634
  }
620
635
 
621
636
  var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
@@ -628,6 +643,28 @@
628
643
  }
629
644
  : {};
630
645
 
646
+ const focusFieldBy = (fields, callback, fieldsNames) => {
647
+ for (const key of fieldsNames || Object.keys(fields)) {
648
+ const field = get(fields, key);
649
+ if (field) {
650
+ const { _f, ...currentField } = field;
651
+ if (_f && callback(_f.name)) {
652
+ if (_f.ref.focus) {
653
+ _f.ref.focus();
654
+ break;
655
+ }
656
+ else if (_f.refs && _f.refs[0].focus) {
657
+ _f.refs[0].focus();
658
+ break;
659
+ }
660
+ }
661
+ else if (isObject(currentField)) {
662
+ focusFieldBy(currentField, callback);
663
+ }
664
+ }
665
+ }
666
+ };
667
+
631
668
  var getValidationModes = (mode) => ({
632
669
  isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
633
670
  isOnBlur: mode === VALIDATION_MODE.onBlur,
@@ -642,41 +679,15 @@
642
679
  [..._names.watch].some((watchName) => name.startsWith(watchName) &&
643
680
  /^\.\w+/.test(name.slice(watchName.length))));
644
681
 
645
- const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
646
- for (const key of fieldsNames || Object.keys(fields)) {
647
- const field = get(fields, key);
648
- if (field) {
649
- const { _f, ...currentField } = field;
650
- if (_f) {
651
- if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
652
- return true;
653
- }
654
- else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
655
- return true;
656
- }
657
- else {
658
- if (iterateFieldsByAction(currentField, action)) {
659
- break;
660
- }
661
- }
662
- }
663
- else if (isObject(currentField)) {
664
- if (iterateFieldsByAction(currentField, action)) {
665
- break;
666
- }
667
- }
668
- }
669
- }
670
- return;
671
- };
672
-
673
682
  var updateFieldArrayRootError = (errors, error, name) => {
674
- const fieldArrayErrors = convertToArrayPayload(get(errors, name));
683
+ const fieldArrayErrors = compact(get(errors, name));
675
684
  set(fieldArrayErrors, 'root', error[name]);
676
685
  set(errors, name, fieldArrayErrors);
677
686
  return errors;
678
687
  };
679
688
 
689
+ var isBoolean = (value) => typeof value === 'boolean';
690
+
680
691
  var isFileInput = (element) => element.type === 'file';
681
692
 
682
693
  var isFunction = (value) => typeof value === 'function';
@@ -753,10 +764,10 @@
753
764
  message: '',
754
765
  };
755
766
 
756
- var validateField = async (field, disabledFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
757
- const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, } = field._f;
767
+ var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
768
+ const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled, } = field._f;
758
769
  const inputValue = get(formValues, name);
759
- if (!mount || disabledFieldNames.has(name)) {
770
+ if (!mount || disabled) {
760
771
  return {};
761
772
  }
762
773
  const inputRef = refs ? refs[0] : ref;
@@ -968,7 +979,7 @@
968
979
  return object;
969
980
  }
970
981
 
971
- var createSubject = () => {
982
+ function createSubject() {
972
983
  let _observers = [];
973
984
  const next = (value) => {
974
985
  for (const observer of _observers) {
@@ -994,7 +1005,7 @@
994
1005
  subscribe,
995
1006
  unsubscribe,
996
1007
  };
997
- };
1008
+ }
998
1009
 
999
1010
  var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
1000
1011
 
@@ -1101,6 +1112,9 @@
1101
1112
 
1102
1113
  function getFieldValue(_f) {
1103
1114
  const ref = _f.ref;
1115
+ if (_f.refs ? _f.refs.every((ref) => ref.disabled) : ref.disabled) {
1116
+ return;
1117
+ }
1104
1118
  if (isFileInput(ref)) {
1105
1119
  return ref.files;
1106
1120
  }
@@ -1140,14 +1154,6 @@
1140
1154
  : rule.value
1141
1155
  : rule;
1142
1156
 
1143
- const ASYNC_FUNCTION = 'AsyncFunction';
1144
- var hasPromiseValidation = (fieldReference) => !!fieldReference &&
1145
- !!fieldReference.validate &&
1146
- !!((isFunction(fieldReference.validate) &&
1147
- fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||
1148
- (isObject(fieldReference.validate) &&
1149
- Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION)));
1150
-
1151
1157
  var hasValidation = (options) => options.mount &&
1152
1158
  (options.required ||
1153
1159
  options.min ||
@@ -1209,7 +1215,7 @@
1209
1215
  reValidateMode: VALIDATION_MODE.onChange,
1210
1216
  shouldFocusError: true,
1211
1217
  };
1212
- function createFormControl(props = {}) {
1218
+ function createFormControl(props = {}, flushRootRender) {
1213
1219
  let _options = {
1214
1220
  ...defaultOptions,
1215
1221
  ...props,
@@ -1225,9 +1231,7 @@
1225
1231
  isValid: false,
1226
1232
  touchedFields: {},
1227
1233
  dirtyFields: {},
1228
- validatingFields: {},
1229
- errors: _options.errors || {},
1230
- disabled: _options.disabled || false,
1234
+ errors: {},
1231
1235
  };
1232
1236
  let _fields = {};
1233
1237
  let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
@@ -1243,7 +1247,6 @@
1243
1247
  };
1244
1248
  let _names = {
1245
1249
  mount: new Set(),
1246
- disabled: new Set(),
1247
1250
  unMount: new Set(),
1248
1251
  array: new Set(),
1249
1252
  watch: new Set(),
@@ -1253,7 +1256,6 @@
1253
1256
  const _proxyFormState = {
1254
1257
  isDirty: false,
1255
1258
  dirtyFields: false,
1256
- validatingFields: false,
1257
1259
  touchedFields: false,
1258
1260
  isValidating: false,
1259
1261
  isValid: false,
@@ -1264,6 +1266,7 @@
1264
1266
  array: createSubject(),
1265
1267
  state: createSubject(),
1266
1268
  };
1269
+ const shouldCaptureDirtyFields = props.resetOptions && props.resetOptions.keepDirtyValues;
1267
1270
  const validationModeBeforeSubmit = getValidationModes(_options.mode);
1268
1271
  const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
1269
1272
  const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
@@ -1272,7 +1275,7 @@
1272
1275
  timer = setTimeout(callback, wait);
1273
1276
  };
1274
1277
  const _updateValid = async (shouldUpdateValid) => {
1275
- if (!_options.disabled && (_proxyFormState.isValid || shouldUpdateValid)) {
1278
+ if (_proxyFormState.isValid || shouldUpdateValid) {
1276
1279
  const isValid = _options.resolver
1277
1280
  ? isEmptyObject((await _executeSchema()).errors)
1278
1281
  : await executeBuiltInValidation(_fields, true);
@@ -1283,24 +1286,12 @@
1283
1286
  }
1284
1287
  }
1285
1288
  };
1286
- const _updateIsValidating = (names, isValidating) => {
1287
- if (!_options.disabled &&
1288
- (_proxyFormState.isValidating || _proxyFormState.validatingFields)) {
1289
- (names || Array.from(_names.mount)).forEach((name) => {
1290
- if (name) {
1291
- isValidating
1292
- ? set(_formState.validatingFields, name, isValidating)
1293
- : unset(_formState.validatingFields, name);
1294
- }
1295
- });
1296
- _subjects.state.next({
1297
- validatingFields: _formState.validatingFields,
1298
- isValidating: !isEmptyObject(_formState.validatingFields),
1299
- });
1300
- }
1301
- };
1289
+ const _updateIsValidating = (value) => _proxyFormState.isValidating &&
1290
+ _subjects.state.next({
1291
+ isValidating: value,
1292
+ });
1302
1293
  const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1303
- if (args && method && !_options.disabled) {
1294
+ if (args && method) {
1304
1295
  _state.action = true;
1305
1296
  if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
1306
1297
  const fieldValues = method(get(_fields, name), args.argA, args.argB);
@@ -1339,13 +1330,6 @@
1339
1330
  errors: _formState.errors,
1340
1331
  });
1341
1332
  };
1342
- const _setErrors = (errors) => {
1343
- _formState.errors = errors;
1344
- _subjects.state.next({
1345
- errors: _formState.errors,
1346
- isValid: false,
1347
- });
1348
- };
1349
1333
  const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
1350
1334
  const field = get(_fields, name);
1351
1335
  if (field) {
@@ -1364,40 +1348,35 @@
1364
1348
  const output = {
1365
1349
  name,
1366
1350
  };
1367
- if (!_options.disabled) {
1368
- const disabledField = !!(get(_fields, name) &&
1369
- get(_fields, name)._f &&
1370
- get(_fields, name)._f.disabled);
1371
- if (!isBlurEvent || shouldDirty) {
1372
- if (_proxyFormState.isDirty) {
1373
- isPreviousDirty = _formState.isDirty;
1374
- _formState.isDirty = output.isDirty = _getDirty();
1375
- shouldUpdateField = isPreviousDirty !== output.isDirty;
1376
- }
1377
- const isCurrentFieldPristine = disabledField || deepEqual(get(_defaultValues, name), fieldValue);
1378
- isPreviousDirty = !!(!disabledField && get(_formState.dirtyFields, name));
1379
- isCurrentFieldPristine || disabledField
1380
- ? unset(_formState.dirtyFields, name)
1381
- : set(_formState.dirtyFields, name, true);
1382
- output.dirtyFields = _formState.dirtyFields;
1351
+ if (!isBlurEvent || shouldDirty) {
1352
+ if (_proxyFormState.isDirty) {
1353
+ isPreviousDirty = _formState.isDirty;
1354
+ _formState.isDirty = output.isDirty = _getDirty();
1355
+ shouldUpdateField = isPreviousDirty !== output.isDirty;
1356
+ }
1357
+ const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
1358
+ isPreviousDirty = get(_formState.dirtyFields, name);
1359
+ isCurrentFieldPristine
1360
+ ? unset(_formState.dirtyFields, name)
1361
+ : set(_formState.dirtyFields, name, true);
1362
+ output.dirtyFields = _formState.dirtyFields;
1363
+ shouldUpdateField =
1364
+ shouldUpdateField ||
1365
+ (_proxyFormState.dirtyFields &&
1366
+ isPreviousDirty !== !isCurrentFieldPristine);
1367
+ }
1368
+ if (isBlurEvent) {
1369
+ const isPreviousFieldTouched = get(_formState.touchedFields, name);
1370
+ if (!isPreviousFieldTouched) {
1371
+ set(_formState.touchedFields, name, isBlurEvent);
1372
+ output.touchedFields = _formState.touchedFields;
1383
1373
  shouldUpdateField =
1384
1374
  shouldUpdateField ||
1385
- (_proxyFormState.dirtyFields &&
1386
- isPreviousDirty !== !isCurrentFieldPristine);
1387
- }
1388
- if (isBlurEvent) {
1389
- const isPreviousFieldTouched = get(_formState.touchedFields, name);
1390
- if (!isPreviousFieldTouched) {
1391
- set(_formState.touchedFields, name, isBlurEvent);
1392
- output.touchedFields = _formState.touchedFields;
1393
- shouldUpdateField =
1394
- shouldUpdateField ||
1395
- (_proxyFormState.touchedFields &&
1396
- isPreviousFieldTouched !== isBlurEvent);
1397
- }
1375
+ (_proxyFormState.touchedFields &&
1376
+ isPreviousFieldTouched !== isBlurEvent);
1398
1377
  }
1399
- shouldUpdateField && shouldRender && _subjects.state.next(output);
1400
1378
  }
1379
+ shouldUpdateField && shouldRender && _subjects.state.next(output);
1401
1380
  return shouldUpdateField ? output : {};
1402
1381
  };
1403
1382
  const shouldRenderByError = (name, isValid, error, fieldState) => {
@@ -1405,9 +1384,9 @@
1405
1384
  const shouldUpdateValid = _proxyFormState.isValid &&
1406
1385
  isBoolean(isValid) &&
1407
1386
  _formState.isValid !== isValid;
1408
- if (_options.delayError && error) {
1387
+ if (props.delayError && error) {
1409
1388
  delayErrorCallback = debounce(() => updateErrors(name, error));
1410
- delayErrorCallback(_options.delayError);
1389
+ delayErrorCallback(props.delayError);
1411
1390
  }
1412
1391
  else {
1413
1392
  clearTimeout(timer);
@@ -1431,13 +1410,9 @@
1431
1410
  };
1432
1411
  _subjects.state.next(updatedFormState);
1433
1412
  }
1413
+ _updateIsValidating(false);
1434
1414
  };
1435
- const _executeSchema = async (name) => {
1436
- _updateIsValidating(name, true);
1437
- const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1438
- _updateIsValidating(name);
1439
- return result;
1440
- };
1415
+ const _executeSchema = async (name) => _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1441
1416
  const executeSchemaAndUpdateState = async (names) => {
1442
1417
  const { errors } = await _executeSchema(names);
1443
1418
  if (names) {
@@ -1462,14 +1437,7 @@
1462
1437
  const { _f, ...fieldValue } = field;
1463
1438
  if (_f) {
1464
1439
  const isFieldArrayRoot = _names.array.has(_f.name);
1465
- const isPromiseFunction = field._f && hasPromiseValidation(field._f);
1466
- if (isPromiseFunction && _proxyFormState.validatingFields) {
1467
- _updateIsValidating([name], true);
1468
- }
1469
- const fieldError = await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
1470
- if (isPromiseFunction && _proxyFormState.validatingFields) {
1471
- _updateIsValidating([name]);
1472
- }
1440
+ const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
1473
1441
  if (fieldError[_f.name]) {
1474
1442
  context.valid = false;
1475
1443
  if (shouldOnlyCheckValid) {
@@ -1483,7 +1451,7 @@
1483
1451
  : set(_formState.errors, _f.name, fieldError[_f.name])
1484
1452
  : unset(_formState.errors, _f.name));
1485
1453
  }
1486
- !isEmptyObject(fieldValue) &&
1454
+ fieldValue &&
1487
1455
  (await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context));
1488
1456
  }
1489
1457
  }
@@ -1500,9 +1468,8 @@
1500
1468
  }
1501
1469
  _names.unMount = new Set();
1502
1470
  };
1503
- const _getDirty = (name, data) => !_options.disabled &&
1504
- (name && data && set(_formValues, name, data),
1505
- !deepEqual(getValues(), _defaultValues));
1471
+ const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
1472
+ !deepEqual(getValues(), _defaultValues));
1506
1473
  const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
1507
1474
  ...(_state.mount
1508
1475
  ? _formValues
@@ -1512,7 +1479,7 @@
1512
1479
  ? { [names]: defaultValue }
1513
1480
  : defaultValue),
1514
1481
  }, isGlobal, defaultValue);
1515
- const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, _options.shouldUnregister ? get(_defaultValues, name, []) : []));
1482
+ const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
1516
1483
  const setFieldValue = (name, value, options = {}) => {
1517
1484
  const field = get(_fields, name);
1518
1485
  let fieldValue = value;
@@ -1566,7 +1533,7 @@
1566
1533
  const fieldName = `${name}.${fieldKey}`;
1567
1534
  const field = get(_fields, fieldName);
1568
1535
  (_names.array.has(name) ||
1569
- isObject(fieldValue) ||
1536
+ !isPrimitive(fieldValue) ||
1570
1537
  (field && !field._f)) &&
1571
1538
  !isDateObject(fieldValue)
1572
1539
  ? setValues(fieldName, fieldValue, options)
@@ -1599,23 +1566,17 @@
1599
1566
  }
1600
1567
  isWatched(name, _names) && _subjects.state.next({ ..._formState });
1601
1568
  _subjects.values.next({
1602
- name: _state.mount ? name : undefined,
1569
+ name,
1603
1570
  values: { ..._formValues },
1604
1571
  });
1572
+ !_state.mount && flushRootRender();
1605
1573
  };
1606
1574
  const onChange = async (event) => {
1607
- _state.mount = true;
1608
1575
  const target = event.target;
1609
1576
  let name = target.name;
1610
1577
  let isFieldValueUpdated = true;
1611
1578
  const field = get(_fields, name);
1612
1579
  const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
1613
- const _updateIsFieldValueUpdated = (fieldValue) => {
1614
- isFieldValueUpdated =
1615
- Number.isNaN(fieldValue) ||
1616
- (isDateObject(fieldValue) && isNaN(fieldValue.getTime())) ||
1617
- deepEqual(fieldValue, get(_formValues, name, fieldValue));
1618
- };
1619
1580
  if (field) {
1620
1581
  let error;
1621
1582
  let isValid;
@@ -1644,34 +1605,25 @@
1644
1605
  values: { ..._formValues },
1645
1606
  });
1646
1607
  if (shouldSkipValidation) {
1647
- if (_proxyFormState.isValid) {
1648
- if (_options.mode === 'onBlur' && isBlurEvent) {
1649
- _updateValid();
1650
- }
1651
- else if (!isBlurEvent) {
1652
- _updateValid();
1653
- }
1654
- }
1608
+ _proxyFormState.isValid && _updateValid();
1655
1609
  return (shouldRender &&
1656
1610
  _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1657
1611
  }
1658
1612
  !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1613
+ _updateIsValidating(true);
1659
1614
  if (_options.resolver) {
1660
1615
  const { errors } = await _executeSchema([name]);
1661
- _updateIsFieldValueUpdated(fieldValue);
1662
- if (isFieldValueUpdated) {
1663
- const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1664
- const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
1665
- error = errorLookupResult.error;
1666
- name = errorLookupResult.name;
1667
- isValid = isEmptyObject(errors);
1668
- }
1616
+ const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1617
+ const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
1618
+ error = errorLookupResult.error;
1619
+ name = errorLookupResult.name;
1620
+ isValid = isEmptyObject(errors);
1669
1621
  }
1670
1622
  else {
1671
- _updateIsValidating([name], true);
1672
- error = (await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1673
- _updateIsValidating([name]);
1674
- _updateIsFieldValueUpdated(fieldValue);
1623
+ error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1624
+ isFieldValueUpdated =
1625
+ isNaN(fieldValue) ||
1626
+ fieldValue === get(_formValues, name, fieldValue);
1675
1627
  if (isFieldValueUpdated) {
1676
1628
  if (error) {
1677
1629
  isValid = false;
@@ -1688,17 +1640,11 @@
1688
1640
  }
1689
1641
  }
1690
1642
  };
1691
- const _focusInput = (ref, key) => {
1692
- if (get(_formState.errors, key) && ref.focus) {
1693
- ref.focus();
1694
- return 1;
1695
- }
1696
- return;
1697
- };
1698
1643
  const trigger = async (name, options = {}) => {
1699
1644
  let isValid;
1700
1645
  let validationResult;
1701
1646
  const fieldNames = convertToArrayPayload(name);
1647
+ _updateIsValidating(true);
1702
1648
  if (_options.resolver) {
1703
1649
  const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
1704
1650
  isValid = isEmptyObject(errors);
@@ -1723,15 +1669,17 @@
1723
1669
  : { name }),
1724
1670
  ...(_options.resolver || !name ? { isValid } : {}),
1725
1671
  errors: _formState.errors,
1672
+ isValidating: false,
1726
1673
  });
1727
1674
  options.shouldFocus &&
1728
1675
  !validationResult &&
1729
- iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
1676
+ focusFieldBy(_fields, (key) => key && get(_formState.errors, key), name ? fieldNames : _names.mount);
1730
1677
  return validationResult;
1731
1678
  };
1732
1679
  const getValues = (fieldNames) => {
1733
1680
  const values = {
1734
- ...(_state.mount ? _formValues : _defaultValues),
1681
+ ..._defaultValues,
1682
+ ...(_state.mount ? _formValues : {}),
1735
1683
  };
1736
1684
  return isUndefined(fieldNames)
1737
1685
  ? values
@@ -1742,9 +1690,8 @@
1742
1690
  const getFieldState = (name, formState) => ({
1743
1691
  invalid: !!get((formState || _formState).errors, name),
1744
1692
  isDirty: !!get((formState || _formState).dirtyFields, name),
1745
- error: get((formState || _formState).errors, name),
1746
- isValidating: !!get(_formState.validatingFields, name),
1747
1693
  isTouched: !!get((formState || _formState).touchedFields, name),
1694
+ error: get((formState || _formState).errors, name),
1748
1695
  });
1749
1696
  const clearErrors = (name) => {
1750
1697
  name &&
@@ -1755,11 +1702,7 @@
1755
1702
  };
1756
1703
  const setError = (name, error, options) => {
1757
1704
  const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
1758
- const currentError = get(_formState.errors, name) || {};
1759
- // Don't override existing error messages elsewhere in the object tree.
1760
- const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
1761
1705
  set(_formState.errors, name, {
1762
- ...restOfErrorTree,
1763
1706
  ...error,
1764
1707
  ref,
1765
1708
  });
@@ -1786,8 +1729,6 @@
1786
1729
  !options.keepError && unset(_formState.errors, fieldName);
1787
1730
  !options.keepDirty && unset(_formState.dirtyFields, fieldName);
1788
1731
  !options.keepTouched && unset(_formState.touchedFields, fieldName);
1789
- !options.keepIsValidating &&
1790
- unset(_formState.validatingFields, fieldName);
1791
1732
  !_options.shouldUnregister &&
1792
1733
  !options.keepDefaultValue &&
1793
1734
  unset(_defaultValues, fieldName);
@@ -1802,16 +1743,17 @@
1802
1743
  !options.keepIsValid && _updateValid();
1803
1744
  };
1804
1745
  const _updateDisabledField = ({ disabled, name, field, fields, }) => {
1805
- if ((isBoolean(disabled) && _state.mount) ||
1806
- !!disabled ||
1807
- _names.disabled.has(name)) {
1808
- disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
1809
- updateTouchAndDirty(name, getFieldValue(field ? field._f : get(fields, name)._f), false, false, true);
1746
+ if (isBoolean(disabled)) {
1747
+ const value = disabled
1748
+ ? undefined
1749
+ : get(_formValues, name, getFieldValue(field ? field._f : get(fields, name)._f));
1750
+ set(_formValues, name, value);
1751
+ updateTouchAndDirty(name, value, false, false, true);
1810
1752
  }
1811
1753
  };
1812
1754
  const register = (name, options = {}) => {
1813
1755
  let field = get(_fields, name);
1814
- const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
1756
+ const disabledIsDefined = isBoolean(options.disabled);
1815
1757
  set(_fields, name, {
1816
1758
  ...(field || {}),
1817
1759
  _f: {
@@ -1825,9 +1767,7 @@
1825
1767
  if (field) {
1826
1768
  _updateDisabledField({
1827
1769
  field,
1828
- disabled: isBoolean(options.disabled)
1829
- ? options.disabled
1830
- : _options.disabled,
1770
+ disabled: options.disabled,
1831
1771
  name,
1832
1772
  });
1833
1773
  }
@@ -1835,9 +1775,7 @@
1835
1775
  updateValidAndValue(name, true, options.value);
1836
1776
  }
1837
1777
  return {
1838
- ...(disabledIsDefined
1839
- ? { disabled: options.disabled || _options.disabled }
1840
- : {}),
1778
+ ...(disabledIsDefined ? { disabled: options.disabled } : {}),
1841
1779
  ...(_options.progressive
1842
1780
  ? {
1843
1781
  required: !!options.required,
@@ -1897,35 +1835,13 @@
1897
1835
  };
1898
1836
  };
1899
1837
  const _focusError = () => _options.shouldFocusError &&
1900
- iterateFieldsByAction(_fields, _focusInput, _names.mount);
1901
- const _disableForm = (disabled) => {
1902
- if (isBoolean(disabled)) {
1903
- _subjects.state.next({ disabled });
1904
- iterateFieldsByAction(_fields, (ref, name) => {
1905
- const currentField = get(_fields, name);
1906
- if (currentField) {
1907
- ref.disabled = currentField._f.disabled || disabled;
1908
- if (Array.isArray(currentField._f.refs)) {
1909
- currentField._f.refs.forEach((inputRef) => {
1910
- inputRef.disabled = currentField._f.disabled || disabled;
1911
- });
1912
- }
1913
- }
1914
- }, 0, false);
1915
- }
1916
- };
1838
+ focusFieldBy(_fields, (key) => key && get(_formState.errors, key), _names.mount);
1917
1839
  const handleSubmit = (onValid, onInvalid) => async (e) => {
1918
- let onValidError = undefined;
1919
1840
  if (e) {
1920
1841
  e.preventDefault && e.preventDefault();
1921
1842
  e.persist && e.persist();
1922
1843
  }
1923
1844
  let fieldValues = cloneObject(_formValues);
1924
- if (_names.disabled.size) {
1925
- for (const name of _names.disabled) {
1926
- set(fieldValues, name, undefined);
1927
- }
1928
- }
1929
1845
  _subjects.state.next({
1930
1846
  isSubmitting: true,
1931
1847
  });
@@ -1942,12 +1858,7 @@
1942
1858
  _subjects.state.next({
1943
1859
  errors: {},
1944
1860
  });
1945
- try {
1946
- await onValid(fieldValues, e);
1947
- }
1948
- catch (error) {
1949
- onValidError = error;
1950
- }
1861
+ await onValid(fieldValues, e);
1951
1862
  }
1952
1863
  else {
1953
1864
  if (onInvalid) {
@@ -1959,22 +1870,19 @@
1959
1870
  _subjects.state.next({
1960
1871
  isSubmitted: true,
1961
1872
  isSubmitting: false,
1962
- isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
1873
+ isSubmitSuccessful: isEmptyObject(_formState.errors),
1963
1874
  submitCount: _formState.submitCount + 1,
1964
1875
  errors: _formState.errors,
1965
1876
  });
1966
- if (onValidError) {
1967
- throw onValidError;
1968
- }
1969
1877
  };
1970
1878
  const resetField = (name, options = {}) => {
1971
1879
  if (get(_fields, name)) {
1972
1880
  if (isUndefined(options.defaultValue)) {
1973
- setValue(name, cloneObject(get(_defaultValues, name)));
1881
+ setValue(name, get(_defaultValues, name));
1974
1882
  }
1975
1883
  else {
1976
1884
  setValue(name, options.defaultValue);
1977
- set(_defaultValues, name, cloneObject(options.defaultValue));
1885
+ set(_defaultValues, name, options.defaultValue);
1978
1886
  }
1979
1887
  if (!options.keepTouched) {
1980
1888
  unset(_formState.touchedFields, name);
@@ -1982,7 +1890,7 @@
1982
1890
  if (!options.keepDirty) {
1983
1891
  unset(_formState.dirtyFields, name);
1984
1892
  _formState.isDirty = options.defaultValue
1985
- ? _getDirty(name, cloneObject(get(_defaultValues, name)))
1893
+ ? _getDirty(name, get(_defaultValues, name))
1986
1894
  : _getDirty();
1987
1895
  }
1988
1896
  if (!options.keepError) {
@@ -1995,18 +1903,15 @@
1995
1903
  const _reset = (formValues, keepStateOptions = {}) => {
1996
1904
  const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
1997
1905
  const cloneUpdatedValues = cloneObject(updatedValues);
1998
- const isEmptyResetValues = isEmptyObject(formValues);
1999
- const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;
1906
+ const values = formValues && !isEmptyObject(formValues)
1907
+ ? cloneUpdatedValues
1908
+ : _defaultValues;
2000
1909
  if (!keepStateOptions.keepDefaultValues) {
2001
1910
  _defaultValues = updatedValues;
2002
1911
  }
2003
1912
  if (!keepStateOptions.keepValues) {
2004
- if (keepStateOptions.keepDirtyValues) {
2005
- const fieldsToCheck = new Set([
2006
- ..._names.mount,
2007
- ...Object.keys(getDirtyFields(_defaultValues, _formValues)),
2008
- ]);
2009
- for (const fieldName of Array.from(fieldsToCheck)) {
1913
+ if (keepStateOptions.keepDirtyValues || shouldCaptureDirtyFields) {
1914
+ for (const fieldName of _names.mount) {
2010
1915
  get(_formState.dirtyFields, fieldName)
2011
1916
  ? set(values, fieldName, get(_formValues, fieldName))
2012
1917
  : setValue(fieldName, get(values, fieldName));
@@ -2032,7 +1937,7 @@
2032
1937
  }
2033
1938
  _fields = {};
2034
1939
  }
2035
- _formValues = _options.shouldUnregister
1940
+ _formValues = props.shouldUnregister
2036
1941
  ? keepStateOptions.keepDefaultValues
2037
1942
  ? cloneObject(_defaultValues)
2038
1943
  : {}
@@ -2045,51 +1950,38 @@
2045
1950
  });
2046
1951
  }
2047
1952
  _names = {
2048
- mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
1953
+ mount: new Set(),
2049
1954
  unMount: new Set(),
2050
1955
  array: new Set(),
2051
- disabled: new Set(),
2052
1956
  watch: new Set(),
2053
1957
  watchAll: false,
2054
1958
  focus: '',
2055
1959
  };
2056
- _state.mount =
2057
- !_proxyFormState.isValid ||
2058
- !!keepStateOptions.keepIsValid ||
2059
- !!keepStateOptions.keepDirtyValues;
2060
- _state.watch = !!_options.shouldUnregister;
1960
+ !_state.mount && flushRootRender();
1961
+ _state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
1962
+ _state.watch = !!props.shouldUnregister;
2061
1963
  _subjects.state.next({
2062
1964
  submitCount: keepStateOptions.keepSubmitCount
2063
1965
  ? _formState.submitCount
2064
1966
  : 0,
2065
- isDirty: isEmptyResetValues
2066
- ? false
2067
- : keepStateOptions.keepDirty
2068
- ? _formState.isDirty
2069
- : !!(keepStateOptions.keepDefaultValues &&
2070
- !deepEqual(formValues, _defaultValues)),
1967
+ isDirty: keepStateOptions.keepDirty
1968
+ ? _formState.isDirty
1969
+ : !!(keepStateOptions.keepDefaultValues &&
1970
+ !deepEqual(formValues, _defaultValues)),
2071
1971
  isSubmitted: keepStateOptions.keepIsSubmitted
2072
1972
  ? _formState.isSubmitted
2073
1973
  : false,
2074
- dirtyFields: isEmptyResetValues
2075
- ? {}
2076
- : keepStateOptions.keepDirtyValues
2077
- ? keepStateOptions.keepDefaultValues && _formValues
2078
- ? getDirtyFields(_defaultValues, _formValues)
2079
- : _formState.dirtyFields
2080
- : keepStateOptions.keepDefaultValues && formValues
2081
- ? getDirtyFields(_defaultValues, formValues)
2082
- : keepStateOptions.keepDirty
2083
- ? _formState.dirtyFields
2084
- : {},
1974
+ dirtyFields: keepStateOptions.keepDirtyValues
1975
+ ? _formState.dirtyFields
1976
+ : keepStateOptions.keepDefaultValues && formValues
1977
+ ? getDirtyFields(_defaultValues, formValues)
1978
+ : {},
2085
1979
  touchedFields: keepStateOptions.keepTouched
2086
1980
  ? _formState.touchedFields
2087
1981
  : {},
2088
1982
  errors: keepStateOptions.keepErrors ? _formState.errors : {},
2089
- isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
2090
- ? _formState.isSubmitSuccessful
2091
- : false,
2092
1983
  isSubmitting: false,
1984
+ isSubmitSuccessful: false,
2093
1985
  });
2094
1986
  };
2095
1987
  const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
@@ -2104,9 +1996,7 @@
2104
1996
  : fieldReference.ref;
2105
1997
  if (fieldRef.focus) {
2106
1998
  fieldRef.focus();
2107
- options.shouldSelect &&
2108
- isFunction(fieldRef.select) &&
2109
- fieldRef.select();
1999
+ options.shouldSelect && fieldRef.select();
2110
2000
  }
2111
2001
  }
2112
2002
  };
@@ -2141,10 +2031,8 @@
2141
2031
  _reset,
2142
2032
  _resetDefaultValues,
2143
2033
  _updateFormState,
2144
- _disableForm,
2145
2034
  _subjects,
2146
2035
  _proxyFormState,
2147
- _setErrors,
2148
2036
  get _fields() {
2149
2037
  return _fields;
2150
2038
  },
@@ -2228,8 +2116,8 @@
2228
2116
  * ```
2229
2117
  */
2230
2118
  function useForm(props = {}) {
2231
- const _formControl = React__default.useRef(undefined);
2232
- const _values = React__default.useRef(undefined);
2119
+ const _formControl = React__default.useRef();
2120
+ const _values = React__default.useRef();
2233
2121
  const [formState, updateFormState] = React__default.useState({
2234
2122
  isDirty: false,
2235
2123
  isValidating: false,
@@ -2241,16 +2129,14 @@
2241
2129
  submitCount: 0,
2242
2130
  dirtyFields: {},
2243
2131
  touchedFields: {},
2244
- validatingFields: {},
2245
- errors: props.errors || {},
2246
- disabled: props.disabled || false,
2132
+ errors: {},
2247
2133
  defaultValues: isFunction(props.defaultValues)
2248
2134
  ? undefined
2249
2135
  : props.defaultValues,
2250
2136
  });
2251
2137
  if (!_formControl.current) {
2252
2138
  _formControl.current = {
2253
- ...createFormControl(props),
2139
+ ...createFormControl(props, () => updateFormState((formState) => ({ ...formState }))),
2254
2140
  formState,
2255
2141
  };
2256
2142
  }
@@ -2264,32 +2150,15 @@
2264
2150
  }
2265
2151
  },
2266
2152
  });
2267
- React__default.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
2268
- React__default.useEffect(() => {
2269
- if (control._proxyFormState.isDirty) {
2270
- const isDirty = control._getDirty();
2271
- if (isDirty !== formState.isDirty) {
2272
- control._subjects.state.next({
2273
- isDirty,
2274
- });
2275
- }
2276
- }
2277
- }, [control, formState.isDirty]);
2278
2153
  React__default.useEffect(() => {
2279
2154
  if (props.values && !deepEqual(props.values, _values.current)) {
2280
2155
  control._reset(props.values, control._options.resetOptions);
2281
2156
  _values.current = props.values;
2282
- updateFormState((state) => ({ ...state }));
2283
2157
  }
2284
2158
  else {
2285
2159
  control._resetDefaultValues();
2286
2160
  }
2287
2161
  }, [props.values, control]);
2288
- React__default.useEffect(() => {
2289
- if (props.errors) {
2290
- control._setErrors(props.errors);
2291
- }
2292
- }, [props.errors, control]);
2293
2162
  React__default.useEffect(() => {
2294
2163
  if (!control._state.mount) {
2295
2164
  control._updateValid();
@@ -2301,12 +2170,6 @@
2301
2170
  }
2302
2171
  control._removeUnmounted();
2303
2172
  });
2304
- React__default.useEffect(() => {
2305
- props.shouldUnregister &&
2306
- control._subjects.values.next({
2307
- values: control._getWatch(),
2308
- });
2309
- }, [props.shouldUnregister, control]);
2310
2173
  _formControl.current.formState = getProxyFormState(formState, control);
2311
2174
  return _formControl.current;
2312
2175
  }
@@ -2399,27 +2262,31 @@
2399
2262
  });
2400
2263
 
2401
2264
  var _excluded = ["ref"];
2265
+
2402
2266
  var _templateObject$5, _templateObject2;
2403
2267
  var OptionsRow = styled__default.div(_templateObject$5 || (_templateObject$5 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n"])));
2404
2268
  var Options = styled__default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n flex-basis: 60%;\n"])));
2269
+
2405
2270
  var CommunicationPreferenceOptionsRenderer = function CommunicationPreferenceOptionsRenderer(_ref) {
2406
2271
  var control = _ref.control,
2407
- name = _ref.name,
2408
- isDisabled = _ref.isDisabled,
2409
- options = _ref.options,
2410
- defaultValue = _ref.defaultValue,
2411
- setValue = _ref.setValue;
2272
+ name = _ref.name,
2273
+ isDisabled = _ref.isDisabled,
2274
+ options = _ref.options,
2275
+ defaultValue = _ref.defaultValue,
2276
+ setValue = _ref.setValue;
2277
+
2412
2278
  var _useController = useController({
2413
- name: name,
2414
- control: control,
2415
- defaultValue: defaultValue
2416
- }),
2417
- _useController$field = _useController.field,
2418
- ref = _useController$field.ref,
2419
- inputProps = _objectWithoutProperties(_useController$field, _excluded),
2420
- _useController$fieldS = _useController.fieldState,
2421
- invalid = _useController$fieldS.invalid,
2422
- error = _useController$fieldS.error;
2279
+ name: name,
2280
+ control: control,
2281
+ defaultValue: defaultValue
2282
+ }),
2283
+ _useController$field = _useController.field,
2284
+ ref = _useController$field.ref,
2285
+ inputProps = _objectWithoutProperties(_useController$field, _excluded),
2286
+ _useController$fieldS = _useController.fieldState,
2287
+ invalid = _useController$fieldS.invalid,
2288
+ error = _useController$fieldS.error;
2289
+
2423
2290
  React.useEffect(function () {
2424
2291
  if (defaultValue) {
2425
2292
  setValue(name, defaultValue);
@@ -2449,15 +2316,16 @@
2449
2316
  return props.theme.colors.primary;
2450
2317
  });
2451
2318
  var SectionHeading = styled__default.div(_templateObject2$1 || (_templateObject2$1 = _taggedTemplateLiteral(["\n padding: 5px 10px;\n"])));
2319
+
2452
2320
  var CommunicationPreferenceSection = function CommunicationPreferenceSection(_ref) {
2453
2321
  var section_heading = _ref.section_heading,
2454
- description = _ref.description,
2455
- control = _ref.control,
2456
- name = _ref.name,
2457
- isDisabled = _ref.isDisabled,
2458
- options = _ref.options,
2459
- defaultValue = _ref.defaultValue,
2460
- setValue = _ref.setValue;
2322
+ description = _ref.description,
2323
+ control = _ref.control,
2324
+ name = _ref.name,
2325
+ isDisabled = _ref.isDisabled,
2326
+ options = _ref.options,
2327
+ defaultValue = _ref.defaultValue,
2328
+ setValue = _ref.setValue;
2461
2329
  return /*#__PURE__*/React__default.createElement(SectionContainer, null, /*#__PURE__*/React__default.createElement(SectionHeading, null, section_heading), /*#__PURE__*/React__default.createElement(CommunicationPreferenceOptionsRenderer, {
2462
2330
  description: description,
2463
2331
  control: control,
@@ -2468,6 +2336,7 @@
2468
2336
  setValue: setValue
2469
2337
  }));
2470
2338
  };
2339
+
2471
2340
  var CommunicationPreferenceSection$1 = themed(CommunicationPreferenceSection);
2472
2341
 
2473
2342
  var defaultNotifyTime = 5000;
@@ -2513,25 +2382,30 @@
2513
2382
  success: false,
2514
2383
  failed: false
2515
2384
  };
2385
+
2516
2386
  var CommunicationPreferences = function CommunicationPreferences(_ref) {
2517
2387
  var header = _ref.header,
2518
- requestInstance = _ref.requestInstance,
2519
- updateNotificationsApi = _ref.updateNotificationsApi,
2520
- preferenceData = _ref.preferenceData,
2521
- btnClassName = _ref.btnClassName;
2388
+ requestInstance = _ref.requestInstance,
2389
+ updateNotificationsApi = _ref.updateNotificationsApi,
2390
+ preferenceData = _ref.preferenceData,
2391
+ btnClassName = _ref.btnClassName;
2392
+
2522
2393
  var _useForm = useForm(),
2523
- handleSubmit = _useForm.handleSubmit,
2524
- control = _useForm.control,
2525
- setValue = _useForm.setValue;
2394
+ handleSubmit = _useForm.handleSubmit,
2395
+ control = _useForm.control,
2396
+ setValue = _useForm.setValue;
2397
+
2526
2398
  var _useState = React.useState(_objectSpread2({}, BaseRequest)),
2527
- _useState2 = _slicedToArray(_useState, 2),
2528
- requestState = _useState2[0],
2529
- setRequestState = _useState2[1];
2399
+ _useState2 = _slicedToArray(_useState, 2),
2400
+ requestState = _useState2[0],
2401
+ setRequestState = _useState2[1];
2402
+
2530
2403
  var _useState3 = React.useState(false),
2531
- _useState4 = _slicedToArray(_useState3, 2),
2532
- isEditing = _useState4[0],
2533
- setIsEditing = _useState4[1];
2534
- //
2404
+ _useState4 = _slicedToArray(_useState3, 2),
2405
+ isEditing = _useState4[0],
2406
+ setIsEditing = _useState4[1]; //
2407
+
2408
+
2535
2409
  var communicationOptions = [{
2536
2410
  label: 'WhatsApp',
2537
2411
  value: 'WHATSAPP'
@@ -2539,9 +2413,11 @@
2539
2413
  label: 'Email',
2540
2414
  value: 'EMAIL'
2541
2415
  }];
2416
+
2542
2417
  var updateRequestState = function updateRequestState(obj) {
2543
2418
  setRequestState(_objectSpread2(_objectSpread2({}, BaseRequest), obj));
2544
2419
  };
2420
+
2545
2421
  var onSubmit = function onSubmit(form_data) {
2546
2422
  updateRequestState({
2547
2423
  loading: true
@@ -2570,6 +2446,7 @@
2570
2446
  }));
2571
2447
  });
2572
2448
  };
2449
+
2573
2450
  return /*#__PURE__*/React__default.createElement(React.Fragment, null, requestState.loading && /*#__PURE__*/React__default.createElement(EllipsisLoader, null), header, /*#__PURE__*/React__default.createElement(CommunicationPreferenceContainer, null, /*#__PURE__*/React__default.createElement("form", {
2574
2451
  onSubmit: handleSubmit(onSubmit)
2575
2452
  }, /*#__PURE__*/React__default.createElement(CommunicationPreferenceSection$1, {
@@ -2597,6 +2474,7 @@
2597
2474
  }
2598
2475
  }, "Edit")))));
2599
2476
  };
2477
+
2600
2478
  var index = themed(CommunicationPreferences);
2601
2479
 
2602
2480
  return index;