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