@bonlineza/luxity-lib 2.34.2 → 2.34.4
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 +116 -76
- package/AddInterest.js +768 -434
- package/BrandSelector.js +336 -176
- package/Checkbox.js +101 -68
- package/CheckboxButton.js +124 -79
- package/CommunicationPreferenceOptionsRenderer.js +125 -107
- package/CommunicationPreferenceSection.js +134 -114
- package/CommunicationPreferences.js +339 -443
- package/CountryCodeSelect.js +10 -7
- package/CurrencyInputFormatter.js +56 -29
- package/CurrencySelect.js +49 -23
- package/GALink.js +16 -6
- package/GenderSelector.js +142 -88
- package/GraphQLDropdownSelector.js +937 -503
- package/GraphQLMultiSelector.js +274 -141
- package/IconHeader.js +25 -11
- package/IconWrapper.js +7 -3
- package/InterestCatSelector.js +74 -34
- package/InterestItem.js +187 -103
- package/Interests.js +890 -485
- package/InterestsSubheading.js +10 -5
- package/InvertedTextButton.js +63 -27
- package/LuxityAppSideNav.js +21 -18
- package/LuxityDesktopHeader.js +246 -189
- package/LuxityFooter.js +276 -374
- package/LuxityGraphQLDropdownSelector.js +969 -519
- package/LuxityGraphQLMultiselector.js +321 -167
- package/LuxityMobileHeader.js +534 -219
- package/LuxityPageReady.js +136 -74
- package/LuxitySideNav.js +402 -137
- package/MaterialSelector.js +976 -525
- package/ModelSelector.js +976 -525
- package/NotificationDropDown.js +209 -111
- package/Notify.js +1 -0
- package/OutlinePrimaryButton.js +58 -26
- package/PriceRangeSelector.js +281 -168
- package/PrimaryButton.js +58 -26
- package/RadioButtons.js +140 -114
- package/RangeSlider.js +242 -152
- package/RareStepFooter.js +41 -27
- package/RareStepHeader.js +190 -139
- package/ReactSelectWrapper.js +1 -0
- package/SecondaryButton.js +58 -26
- package/ShoeSizeRangeSelector.js +260 -162
- package/ShoeSizeSelector.js +263 -158
- package/SimpleErrorBoundary.js +106 -59
- package/StyleSelector.js +336 -176
- package/TextButton.js +58 -26
- package/Tooltip.js +39 -17
- package/Tracking.js +1 -0
- package/WrapperButton.js +43 -20
- package/build/bundle.css +1 -1
- package/build/bundle.js +1701 -1254
- package/package.json +1 -1
- package/svg/Accessories.js +13 -6
- package/svg/Account.js +13 -6
- package/svg/Add.js +13 -6
- package/svg/ArrowRight.js +13 -6
- package/svg/Bags.js +13 -6
- package/svg/BurgerMenu.js +13 -6
- package/svg/Calendar.js +13 -6
- package/svg/CalendarCircled.js +13 -6
- package/svg/CheckCircled.js +13 -6
- package/svg/Close.js +13 -6
- package/svg/Clothing.js +13 -6
- package/svg/Dot.js +13 -6
- package/svg/Edit.js +13 -6
- package/svg/Eye.js +13 -6
- package/svg/FileAttach.js +13 -6
- package/svg/FileAttachCircled.js +13 -6
- package/svg/LightBulb.js +13 -6
- package/svg/Logo.js +13 -6
- package/svg/LuxityMenu.js +13 -6
- package/svg/Minus.js +13 -6
- package/svg/MobileAvatar.js +13 -6
- package/svg/MyOrder.js +13 -6
- package/svg/MyPayment.js +13 -6
- package/svg/MyProfile.js +14 -8
- package/svg/MySale.js +13 -6
- package/svg/Notification.js +13 -6
- package/svg/PointerDown.js +13 -6
- package/svg/Search.js +13 -6
- package/svg/Shoes.js +13 -6
- package/svg/SvgWrapper.js +7 -3
- package/svg/Trash.js +13 -6
- 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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
for (var
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
81
|
+
|
|
82
|
+
return target;
|
|
87
83
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
95
|
-
|
|
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
|
-
|
|
102
|
+
|
|
103
|
+
return target;
|
|
98
104
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (e.includes(n)) continue;
|
|
104
|
-
t[n] = r[n];
|
|
105
|
+
|
|
106
|
+
function _taggedTemplateLiteral(strings, raw) {
|
|
107
|
+
if (!raw) {
|
|
108
|
+
raw = strings.slice(0);
|
|
105
109
|
}
|
|
106
|
-
|
|
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(
|
|
113
|
+
value: Object.freeze(raw)
|
|
115
114
|
}
|
|
116
115
|
}));
|
|
117
116
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
|
|
122
|
+
function _arrayWithHoles(arr) {
|
|
123
|
+
if (Array.isArray(arr)) return arr;
|
|
131
124
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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';
|
|
@@ -201,50 +238,18 @@
|
|
|
201
238
|
|
|
202
239
|
var isUndefined = (val) => val === undefined;
|
|
203
240
|
|
|
204
|
-
var get = (
|
|
205
|
-
if (!path || !isObject(
|
|
241
|
+
var get = (obj, path, defaultValue) => {
|
|
242
|
+
if (!path || !isObject(obj)) {
|
|
206
243
|
return defaultValue;
|
|
207
244
|
}
|
|
208
|
-
const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key],
|
|
209
|
-
return isUndefined(result) || result ===
|
|
210
|
-
? isUndefined(
|
|
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])
|
|
211
248
|
? defaultValue
|
|
212
|
-
:
|
|
249
|
+
: obj[path]
|
|
213
250
|
: result;
|
|
214
251
|
};
|
|
215
252
|
|
|
216
|
-
var isBoolean = (value) => typeof value === 'boolean';
|
|
217
|
-
|
|
218
|
-
var isKey = (value) => /^\w*$/.test(value);
|
|
219
|
-
|
|
220
|
-
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
|
221
|
-
|
|
222
|
-
var set = (object, path, value) => {
|
|
223
|
-
let index = -1;
|
|
224
|
-
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
225
|
-
const length = tempPath.length;
|
|
226
|
-
const lastIndex = length - 1;
|
|
227
|
-
while (++index < length) {
|
|
228
|
-
const key = tempPath[index];
|
|
229
|
-
let newValue = value;
|
|
230
|
-
if (index !== lastIndex) {
|
|
231
|
-
const objValue = object[key];
|
|
232
|
-
newValue =
|
|
233
|
-
isObject(objValue) || Array.isArray(objValue)
|
|
234
|
-
? objValue
|
|
235
|
-
: !isNaN(+tempPath[index + 1])
|
|
236
|
-
? []
|
|
237
|
-
: {};
|
|
238
|
-
}
|
|
239
|
-
if (key === '__proto__') {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
object[key] = newValue;
|
|
243
|
-
object = object[key];
|
|
244
|
-
}
|
|
245
|
-
return object;
|
|
246
|
-
};
|
|
247
|
-
|
|
248
253
|
const EVENTS = {
|
|
249
254
|
BLUR: 'blur',
|
|
250
255
|
FOCUS_OUT: 'focusout',
|
|
@@ -332,13 +337,15 @@
|
|
|
332
337
|
|
|
333
338
|
var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
|
|
334
339
|
|
|
335
|
-
var shouldSubscribeByName = (name, signalName, exact) =>
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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) ||
|
|
342
349
|
signalName.startsWith(currentName)));
|
|
343
350
|
|
|
344
351
|
function useSubscribe(props) {
|
|
@@ -396,7 +403,6 @@
|
|
|
396
403
|
isLoading: false,
|
|
397
404
|
dirtyFields: false,
|
|
398
405
|
touchedFields: false,
|
|
399
|
-
validatingFields: false,
|
|
400
406
|
isValidating: false,
|
|
401
407
|
isValid: false,
|
|
402
408
|
errors: false,
|
|
@@ -447,7 +453,7 @@
|
|
|
447
453
|
*
|
|
448
454
|
* @example
|
|
449
455
|
* ```tsx
|
|
450
|
-
* const {
|
|
456
|
+
* const { watch } = useForm();
|
|
451
457
|
* const values = useWatch({
|
|
452
458
|
* name: "fieldName"
|
|
453
459
|
* control,
|
|
@@ -473,6 +479,33 @@
|
|
|
473
479
|
return value;
|
|
474
480
|
}
|
|
475
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
|
+
|
|
476
509
|
/**
|
|
477
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.
|
|
478
511
|
*
|
|
@@ -510,18 +543,17 @@
|
|
|
510
543
|
const formState = useFormState({
|
|
511
544
|
control,
|
|
512
545
|
name,
|
|
513
|
-
exact: true,
|
|
514
546
|
});
|
|
515
547
|
const _registerProps = React__default.useRef(control.register(name, {
|
|
516
548
|
...props.rules,
|
|
517
549
|
value,
|
|
518
|
-
...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
|
|
519
550
|
}));
|
|
551
|
+
_registerProps.current = control.register(name, props.rules);
|
|
520
552
|
React__default.useEffect(() => {
|
|
521
553
|
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
522
554
|
const updateMounted = (name, value) => {
|
|
523
555
|
const field = get(control._fields, name);
|
|
524
|
-
if (field
|
|
556
|
+
if (field) {
|
|
525
557
|
field._f.mount = value;
|
|
526
558
|
}
|
|
527
559
|
};
|
|
@@ -542,22 +574,17 @@
|
|
|
542
574
|
};
|
|
543
575
|
}, [name, control, isArrayField, shouldUnregister]);
|
|
544
576
|
React__default.useEffect(() => {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
value: get(control._fields, name)._f.value,
|
|
551
|
-
});
|
|
552
|
-
}
|
|
577
|
+
control._updateDisabledField({
|
|
578
|
+
disabled,
|
|
579
|
+
fields: control._fields,
|
|
580
|
+
name,
|
|
581
|
+
});
|
|
553
582
|
}, [disabled, name, control]);
|
|
554
583
|
return {
|
|
555
584
|
field: {
|
|
556
585
|
name,
|
|
557
586
|
value,
|
|
558
|
-
|
|
559
|
-
? { disabled: formState.disabled || disabled }
|
|
560
|
-
: {}),
|
|
587
|
+
disabled,
|
|
561
588
|
onChange: React__default.useCallback((event) => _registerProps.current.onChange({
|
|
562
589
|
target: {
|
|
563
590
|
value: getEventValue(event),
|
|
@@ -572,7 +599,7 @@
|
|
|
572
599
|
},
|
|
573
600
|
type: EVENTS.BLUR,
|
|
574
601
|
}), [name, control]),
|
|
575
|
-
ref:
|
|
602
|
+
ref: (elm) => {
|
|
576
603
|
const field = get(control._fields, name);
|
|
577
604
|
if (field && elm) {
|
|
578
605
|
field._f.ref = {
|
|
@@ -582,7 +609,7 @@
|
|
|
582
609
|
reportValidity: () => elm.reportValidity(),
|
|
583
610
|
};
|
|
584
611
|
}
|
|
585
|
-
},
|
|
612
|
+
},
|
|
586
613
|
},
|
|
587
614
|
formState,
|
|
588
615
|
fieldState: Object.defineProperties({}, {
|
|
@@ -598,10 +625,6 @@
|
|
|
598
625
|
enumerable: true,
|
|
599
626
|
get: () => !!get(formState.touchedFields, name),
|
|
600
627
|
},
|
|
601
|
-
isValidating: {
|
|
602
|
-
enumerable: true,
|
|
603
|
-
get: () => !!get(formState.validatingFields, name),
|
|
604
|
-
},
|
|
605
628
|
error: {
|
|
606
629
|
enumerable: true,
|
|
607
630
|
get: () => get(formState.errors, name),
|
|
@@ -620,6 +643,28 @@
|
|
|
620
643
|
}
|
|
621
644
|
: {};
|
|
622
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
|
+
|
|
623
668
|
var getValidationModes = (mode) => ({
|
|
624
669
|
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
|
|
625
670
|
isOnBlur: mode === VALIDATION_MODE.onBlur,
|
|
@@ -634,41 +679,15 @@
|
|
|
634
679
|
[..._names.watch].some((watchName) => name.startsWith(watchName) &&
|
|
635
680
|
/^\.\w+/.test(name.slice(watchName.length))));
|
|
636
681
|
|
|
637
|
-
const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
|
638
|
-
for (const key of fieldsNames || Object.keys(fields)) {
|
|
639
|
-
const field = get(fields, key);
|
|
640
|
-
if (field) {
|
|
641
|
-
const { _f, ...currentField } = field;
|
|
642
|
-
if (_f) {
|
|
643
|
-
if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
|
|
644
|
-
return true;
|
|
645
|
-
}
|
|
646
|
-
else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
|
|
647
|
-
return true;
|
|
648
|
-
}
|
|
649
|
-
else {
|
|
650
|
-
if (iterateFieldsByAction(currentField, action)) {
|
|
651
|
-
break;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
else if (isObject(currentField)) {
|
|
656
|
-
if (iterateFieldsByAction(currentField, action)) {
|
|
657
|
-
break;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
return;
|
|
663
|
-
};
|
|
664
|
-
|
|
665
682
|
var updateFieldArrayRootError = (errors, error, name) => {
|
|
666
|
-
const fieldArrayErrors =
|
|
683
|
+
const fieldArrayErrors = compact(get(errors, name));
|
|
667
684
|
set(fieldArrayErrors, 'root', error[name]);
|
|
668
685
|
set(errors, name, fieldArrayErrors);
|
|
669
686
|
return errors;
|
|
670
687
|
};
|
|
671
688
|
|
|
689
|
+
var isBoolean = (value) => typeof value === 'boolean';
|
|
690
|
+
|
|
672
691
|
var isFileInput = (element) => element.type === 'file';
|
|
673
692
|
|
|
674
693
|
var isFunction = (value) => typeof value === 'function';
|
|
@@ -960,7 +979,7 @@
|
|
|
960
979
|
return object;
|
|
961
980
|
}
|
|
962
981
|
|
|
963
|
-
|
|
982
|
+
function createSubject() {
|
|
964
983
|
let _observers = [];
|
|
965
984
|
const next = (value) => {
|
|
966
985
|
for (const observer of _observers) {
|
|
@@ -986,7 +1005,7 @@
|
|
|
986
1005
|
subscribe,
|
|
987
1006
|
unsubscribe,
|
|
988
1007
|
};
|
|
989
|
-
}
|
|
1008
|
+
}
|
|
990
1009
|
|
|
991
1010
|
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
992
1011
|
|
|
@@ -1135,13 +1154,6 @@
|
|
|
1135
1154
|
: rule.value
|
|
1136
1155
|
: rule;
|
|
1137
1156
|
|
|
1138
|
-
const ASYNC_FUNCTION = 'AsyncFunction';
|
|
1139
|
-
var hasPromiseValidation = (fieldReference) => (!fieldReference || !fieldReference.validate) &&
|
|
1140
|
-
!!((isFunction(fieldReference.validate) &&
|
|
1141
|
-
fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||
|
|
1142
|
-
(isObject(fieldReference.validate) &&
|
|
1143
|
-
Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION)));
|
|
1144
|
-
|
|
1145
1157
|
var hasValidation = (options) => options.mount &&
|
|
1146
1158
|
(options.required ||
|
|
1147
1159
|
options.min ||
|
|
@@ -1203,7 +1215,7 @@
|
|
|
1203
1215
|
reValidateMode: VALIDATION_MODE.onChange,
|
|
1204
1216
|
shouldFocusError: true,
|
|
1205
1217
|
};
|
|
1206
|
-
function createFormControl(props = {}) {
|
|
1218
|
+
function createFormControl(props = {}, flushRootRender) {
|
|
1207
1219
|
let _options = {
|
|
1208
1220
|
...defaultOptions,
|
|
1209
1221
|
...props,
|
|
@@ -1219,9 +1231,7 @@
|
|
|
1219
1231
|
isValid: false,
|
|
1220
1232
|
touchedFields: {},
|
|
1221
1233
|
dirtyFields: {},
|
|
1222
|
-
|
|
1223
|
-
errors: _options.errors || {},
|
|
1224
|
-
disabled: _options.disabled || false,
|
|
1234
|
+
errors: {},
|
|
1225
1235
|
};
|
|
1226
1236
|
let _fields = {};
|
|
1227
1237
|
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
|
|
@@ -1246,7 +1256,6 @@
|
|
|
1246
1256
|
const _proxyFormState = {
|
|
1247
1257
|
isDirty: false,
|
|
1248
1258
|
dirtyFields: false,
|
|
1249
|
-
validatingFields: false,
|
|
1250
1259
|
touchedFields: false,
|
|
1251
1260
|
isValidating: false,
|
|
1252
1261
|
isValid: false,
|
|
@@ -1257,6 +1266,7 @@
|
|
|
1257
1266
|
array: createSubject(),
|
|
1258
1267
|
state: createSubject(),
|
|
1259
1268
|
};
|
|
1269
|
+
const shouldCaptureDirtyFields = props.resetOptions && props.resetOptions.keepDirtyValues;
|
|
1260
1270
|
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
|
1261
1271
|
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
|
1262
1272
|
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
|
@@ -1276,21 +1286,10 @@
|
|
|
1276
1286
|
}
|
|
1277
1287
|
}
|
|
1278
1288
|
};
|
|
1279
|
-
const _updateIsValidating = (
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
isValidating
|
|
1284
|
-
? set(_formState.validatingFields, name, isValidating)
|
|
1285
|
-
: unset(_formState.validatingFields, name);
|
|
1286
|
-
}
|
|
1287
|
-
});
|
|
1288
|
-
_subjects.state.next({
|
|
1289
|
-
validatingFields: _formState.validatingFields,
|
|
1290
|
-
isValidating: !isEmptyObject(_formState.validatingFields),
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1289
|
+
const _updateIsValidating = (value) => _proxyFormState.isValidating &&
|
|
1290
|
+
_subjects.state.next({
|
|
1291
|
+
isValidating: value,
|
|
1292
|
+
});
|
|
1294
1293
|
const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
|
|
1295
1294
|
if (args && method) {
|
|
1296
1295
|
_state.action = true;
|
|
@@ -1331,13 +1330,6 @@
|
|
|
1331
1330
|
errors: _formState.errors,
|
|
1332
1331
|
});
|
|
1333
1332
|
};
|
|
1334
|
-
const _setErrors = (errors) => {
|
|
1335
|
-
_formState.errors = errors;
|
|
1336
|
-
_subjects.state.next({
|
|
1337
|
-
errors: _formState.errors,
|
|
1338
|
-
isValid: false,
|
|
1339
|
-
});
|
|
1340
|
-
};
|
|
1341
1333
|
const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
|
|
1342
1334
|
const field = get(_fields, name);
|
|
1343
1335
|
if (field) {
|
|
@@ -1356,18 +1348,15 @@
|
|
|
1356
1348
|
const output = {
|
|
1357
1349
|
name,
|
|
1358
1350
|
};
|
|
1359
|
-
const disabledField = !!(get(_fields, name) &&
|
|
1360
|
-
get(_fields, name)._f &&
|
|
1361
|
-
get(_fields, name)._f.disabled);
|
|
1362
1351
|
if (!isBlurEvent || shouldDirty) {
|
|
1363
1352
|
if (_proxyFormState.isDirty) {
|
|
1364
1353
|
isPreviousDirty = _formState.isDirty;
|
|
1365
1354
|
_formState.isDirty = output.isDirty = _getDirty();
|
|
1366
1355
|
shouldUpdateField = isPreviousDirty !== output.isDirty;
|
|
1367
1356
|
}
|
|
1368
|
-
const isCurrentFieldPristine =
|
|
1369
|
-
isPreviousDirty =
|
|
1370
|
-
isCurrentFieldPristine
|
|
1357
|
+
const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
|
|
1358
|
+
isPreviousDirty = get(_formState.dirtyFields, name);
|
|
1359
|
+
isCurrentFieldPristine
|
|
1371
1360
|
? unset(_formState.dirtyFields, name)
|
|
1372
1361
|
: set(_formState.dirtyFields, name, true);
|
|
1373
1362
|
output.dirtyFields = _formState.dirtyFields;
|
|
@@ -1421,13 +1410,9 @@
|
|
|
1421
1410
|
};
|
|
1422
1411
|
_subjects.state.next(updatedFormState);
|
|
1423
1412
|
}
|
|
1413
|
+
_updateIsValidating(false);
|
|
1424
1414
|
};
|
|
1425
|
-
const _executeSchema = async (name) =>
|
|
1426
|
-
_updateIsValidating(name, true);
|
|
1427
|
-
const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
1428
|
-
_updateIsValidating(name);
|
|
1429
|
-
return result;
|
|
1430
|
-
};
|
|
1415
|
+
const _executeSchema = async (name) => _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
1431
1416
|
const executeSchemaAndUpdateState = async (names) => {
|
|
1432
1417
|
const { errors } = await _executeSchema(names);
|
|
1433
1418
|
if (names) {
|
|
@@ -1452,14 +1437,7 @@
|
|
|
1452
1437
|
const { _f, ...fieldValue } = field;
|
|
1453
1438
|
if (_f) {
|
|
1454
1439
|
const isFieldArrayRoot = _names.array.has(_f.name);
|
|
1455
|
-
const isPromiseFunction = field._f && hasPromiseValidation(field._f);
|
|
1456
|
-
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
|
1457
|
-
_updateIsValidating([name], true);
|
|
1458
|
-
}
|
|
1459
1440
|
const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
|
1460
|
-
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
|
1461
|
-
_updateIsValidating([name]);
|
|
1462
|
-
}
|
|
1463
1441
|
if (fieldError[_f.name]) {
|
|
1464
1442
|
context.valid = false;
|
|
1465
1443
|
if (shouldOnlyCheckValid) {
|
|
@@ -1473,7 +1451,7 @@
|
|
|
1473
1451
|
: set(_formState.errors, _f.name, fieldError[_f.name])
|
|
1474
1452
|
: unset(_formState.errors, _f.name));
|
|
1475
1453
|
}
|
|
1476
|
-
|
|
1454
|
+
fieldValue &&
|
|
1477
1455
|
(await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context));
|
|
1478
1456
|
}
|
|
1479
1457
|
}
|
|
@@ -1588,22 +1566,17 @@
|
|
|
1588
1566
|
}
|
|
1589
1567
|
isWatched(name, _names) && _subjects.state.next({ ..._formState });
|
|
1590
1568
|
_subjects.values.next({
|
|
1591
|
-
name
|
|
1569
|
+
name,
|
|
1592
1570
|
values: { ..._formValues },
|
|
1593
1571
|
});
|
|
1572
|
+
!_state.mount && flushRootRender();
|
|
1594
1573
|
};
|
|
1595
1574
|
const onChange = async (event) => {
|
|
1596
|
-
_state.mount = true;
|
|
1597
1575
|
const target = event.target;
|
|
1598
1576
|
let name = target.name;
|
|
1599
1577
|
let isFieldValueUpdated = true;
|
|
1600
1578
|
const field = get(_fields, name);
|
|
1601
1579
|
const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
|
|
1602
|
-
const _updateIsFieldValueUpdated = (fieldValue) => {
|
|
1603
|
-
isFieldValueUpdated =
|
|
1604
|
-
Number.isNaN(fieldValue) ||
|
|
1605
|
-
deepEqual(fieldValue, get(_formValues, name, fieldValue));
|
|
1606
|
-
};
|
|
1607
1580
|
if (field) {
|
|
1608
1581
|
let error;
|
|
1609
1582
|
let isValid;
|
|
@@ -1632,36 +1605,25 @@
|
|
|
1632
1605
|
values: { ..._formValues },
|
|
1633
1606
|
});
|
|
1634
1607
|
if (shouldSkipValidation) {
|
|
1635
|
-
|
|
1636
|
-
if (props.mode === 'onBlur') {
|
|
1637
|
-
if (isBlurEvent) {
|
|
1638
|
-
_updateValid();
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
else {
|
|
1642
|
-
_updateValid();
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1608
|
+
_proxyFormState.isValid && _updateValid();
|
|
1645
1609
|
return (shouldRender &&
|
|
1646
1610
|
_subjects.state.next({ name, ...(watched ? {} : fieldState) }));
|
|
1647
1611
|
}
|
|
1648
1612
|
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
|
1613
|
+
_updateIsValidating(true);
|
|
1649
1614
|
if (_options.resolver) {
|
|
1650
1615
|
const { errors } = await _executeSchema([name]);
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
name = errorLookupResult.name;
|
|
1657
|
-
isValid = isEmptyObject(errors);
|
|
1658
|
-
}
|
|
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);
|
|
1659
1621
|
}
|
|
1660
1622
|
else {
|
|
1661
|
-
_updateIsValidating([name], true);
|
|
1662
1623
|
error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
|
1663
|
-
|
|
1664
|
-
|
|
1624
|
+
isFieldValueUpdated =
|
|
1625
|
+
isNaN(fieldValue) ||
|
|
1626
|
+
fieldValue === get(_formValues, name, fieldValue);
|
|
1665
1627
|
if (isFieldValueUpdated) {
|
|
1666
1628
|
if (error) {
|
|
1667
1629
|
isValid = false;
|
|
@@ -1678,17 +1640,11 @@
|
|
|
1678
1640
|
}
|
|
1679
1641
|
}
|
|
1680
1642
|
};
|
|
1681
|
-
const _focusInput = (ref, key) => {
|
|
1682
|
-
if (get(_formState.errors, key) && ref.focus) {
|
|
1683
|
-
ref.focus();
|
|
1684
|
-
return 1;
|
|
1685
|
-
}
|
|
1686
|
-
return;
|
|
1687
|
-
};
|
|
1688
1643
|
const trigger = async (name, options = {}) => {
|
|
1689
1644
|
let isValid;
|
|
1690
1645
|
let validationResult;
|
|
1691
1646
|
const fieldNames = convertToArrayPayload(name);
|
|
1647
|
+
_updateIsValidating(true);
|
|
1692
1648
|
if (_options.resolver) {
|
|
1693
1649
|
const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
|
|
1694
1650
|
isValid = isEmptyObject(errors);
|
|
@@ -1713,15 +1669,17 @@
|
|
|
1713
1669
|
: { name }),
|
|
1714
1670
|
...(_options.resolver || !name ? { isValid } : {}),
|
|
1715
1671
|
errors: _formState.errors,
|
|
1672
|
+
isValidating: false,
|
|
1716
1673
|
});
|
|
1717
1674
|
options.shouldFocus &&
|
|
1718
1675
|
!validationResult &&
|
|
1719
|
-
|
|
1676
|
+
focusFieldBy(_fields, (key) => key && get(_formState.errors, key), name ? fieldNames : _names.mount);
|
|
1720
1677
|
return validationResult;
|
|
1721
1678
|
};
|
|
1722
1679
|
const getValues = (fieldNames) => {
|
|
1723
1680
|
const values = {
|
|
1724
|
-
...
|
|
1681
|
+
..._defaultValues,
|
|
1682
|
+
...(_state.mount ? _formValues : {}),
|
|
1725
1683
|
};
|
|
1726
1684
|
return isUndefined(fieldNames)
|
|
1727
1685
|
? values
|
|
@@ -1732,9 +1690,8 @@
|
|
|
1732
1690
|
const getFieldState = (name, formState) => ({
|
|
1733
1691
|
invalid: !!get((formState || _formState).errors, name),
|
|
1734
1692
|
isDirty: !!get((formState || _formState).dirtyFields, name),
|
|
1735
|
-
error: get((formState || _formState).errors, name),
|
|
1736
|
-
isValidating: !!get(_formState.validatingFields, name),
|
|
1737
1693
|
isTouched: !!get((formState || _formState).touchedFields, name),
|
|
1694
|
+
error: get((formState || _formState).errors, name),
|
|
1738
1695
|
});
|
|
1739
1696
|
const clearErrors = (name) => {
|
|
1740
1697
|
name &&
|
|
@@ -1745,11 +1702,7 @@
|
|
|
1745
1702
|
};
|
|
1746
1703
|
const setError = (name, error, options) => {
|
|
1747
1704
|
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
|
1748
|
-
const currentError = get(_formState.errors, name) || {};
|
|
1749
|
-
// Don't override existing error messages elsewhere in the object tree.
|
|
1750
|
-
const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
|
|
1751
1705
|
set(_formState.errors, name, {
|
|
1752
|
-
...restOfErrorTree,
|
|
1753
1706
|
...error,
|
|
1754
1707
|
ref,
|
|
1755
1708
|
});
|
|
@@ -1776,8 +1729,6 @@
|
|
|
1776
1729
|
!options.keepError && unset(_formState.errors, fieldName);
|
|
1777
1730
|
!options.keepDirty && unset(_formState.dirtyFields, fieldName);
|
|
1778
1731
|
!options.keepTouched && unset(_formState.touchedFields, fieldName);
|
|
1779
|
-
!options.keepIsValidating &&
|
|
1780
|
-
unset(_formState.validatingFields, fieldName);
|
|
1781
1732
|
!_options.shouldUnregister &&
|
|
1782
1733
|
!options.keepDefaultValue &&
|
|
1783
1734
|
unset(_defaultValues, fieldName);
|
|
@@ -1791,20 +1742,18 @@
|
|
|
1791
1742
|
});
|
|
1792
1743
|
!options.keepIsValid && _updateValid();
|
|
1793
1744
|
};
|
|
1794
|
-
const _updateDisabledField = ({ disabled, name, field, fields,
|
|
1795
|
-
if (
|
|
1796
|
-
const
|
|
1745
|
+
const _updateDisabledField = ({ disabled, name, field, fields, }) => {
|
|
1746
|
+
if (isBoolean(disabled)) {
|
|
1747
|
+
const value = disabled
|
|
1797
1748
|
? undefined
|
|
1798
|
-
:
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
set(_formValues, name, inputValue);
|
|
1802
|
-
updateTouchAndDirty(name, inputValue, false, false, true);
|
|
1749
|
+
: get(_formValues, name, getFieldValue(field ? field._f : get(fields, name)._f));
|
|
1750
|
+
set(_formValues, name, value);
|
|
1751
|
+
updateTouchAndDirty(name, value, false, false, true);
|
|
1803
1752
|
}
|
|
1804
1753
|
};
|
|
1805
1754
|
const register = (name, options = {}) => {
|
|
1806
1755
|
let field = get(_fields, name);
|
|
1807
|
-
const disabledIsDefined = isBoolean(options.disabled)
|
|
1756
|
+
const disabledIsDefined = isBoolean(options.disabled);
|
|
1808
1757
|
set(_fields, name, {
|
|
1809
1758
|
...(field || {}),
|
|
1810
1759
|
_f: {
|
|
@@ -1818,20 +1767,15 @@
|
|
|
1818
1767
|
if (field) {
|
|
1819
1768
|
_updateDisabledField({
|
|
1820
1769
|
field,
|
|
1821
|
-
disabled:
|
|
1822
|
-
? options.disabled
|
|
1823
|
-
: props.disabled,
|
|
1770
|
+
disabled: options.disabled,
|
|
1824
1771
|
name,
|
|
1825
|
-
value: options.value,
|
|
1826
1772
|
});
|
|
1827
1773
|
}
|
|
1828
1774
|
else {
|
|
1829
1775
|
updateValidAndValue(name, true, options.value);
|
|
1830
1776
|
}
|
|
1831
1777
|
return {
|
|
1832
|
-
...(disabledIsDefined
|
|
1833
|
-
? { disabled: options.disabled || props.disabled }
|
|
1834
|
-
: {}),
|
|
1778
|
+
...(disabledIsDefined ? { disabled: options.disabled } : {}),
|
|
1835
1779
|
...(_options.progressive
|
|
1836
1780
|
? {
|
|
1837
1781
|
required: !!options.required,
|
|
@@ -1891,25 +1835,8 @@
|
|
|
1891
1835
|
};
|
|
1892
1836
|
};
|
|
1893
1837
|
const _focusError = () => _options.shouldFocusError &&
|
|
1894
|
-
|
|
1895
|
-
const _disableForm = (disabled) => {
|
|
1896
|
-
if (isBoolean(disabled)) {
|
|
1897
|
-
_subjects.state.next({ disabled });
|
|
1898
|
-
iterateFieldsByAction(_fields, (ref, name) => {
|
|
1899
|
-
const currentField = get(_fields, name);
|
|
1900
|
-
if (currentField) {
|
|
1901
|
-
ref.disabled = currentField._f.disabled || disabled;
|
|
1902
|
-
if (Array.isArray(currentField._f.refs)) {
|
|
1903
|
-
currentField._f.refs.forEach((inputRef) => {
|
|
1904
|
-
inputRef.disabled = currentField._f.disabled || disabled;
|
|
1905
|
-
});
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
}, 0, false);
|
|
1909
|
-
}
|
|
1910
|
-
};
|
|
1838
|
+
focusFieldBy(_fields, (key) => key && get(_formState.errors, key), _names.mount);
|
|
1911
1839
|
const handleSubmit = (onValid, onInvalid) => async (e) => {
|
|
1912
|
-
let onValidError = undefined;
|
|
1913
1840
|
if (e) {
|
|
1914
1841
|
e.preventDefault && e.preventDefault();
|
|
1915
1842
|
e.persist && e.persist();
|
|
@@ -1931,12 +1858,7 @@
|
|
|
1931
1858
|
_subjects.state.next({
|
|
1932
1859
|
errors: {},
|
|
1933
1860
|
});
|
|
1934
|
-
|
|
1935
|
-
await onValid(fieldValues, e);
|
|
1936
|
-
}
|
|
1937
|
-
catch (error) {
|
|
1938
|
-
onValidError = error;
|
|
1939
|
-
}
|
|
1861
|
+
await onValid(fieldValues, e);
|
|
1940
1862
|
}
|
|
1941
1863
|
else {
|
|
1942
1864
|
if (onInvalid) {
|
|
@@ -1948,22 +1870,19 @@
|
|
|
1948
1870
|
_subjects.state.next({
|
|
1949
1871
|
isSubmitted: true,
|
|
1950
1872
|
isSubmitting: false,
|
|
1951
|
-
isSubmitSuccessful: isEmptyObject(_formState.errors)
|
|
1873
|
+
isSubmitSuccessful: isEmptyObject(_formState.errors),
|
|
1952
1874
|
submitCount: _formState.submitCount + 1,
|
|
1953
1875
|
errors: _formState.errors,
|
|
1954
1876
|
});
|
|
1955
|
-
if (onValidError) {
|
|
1956
|
-
throw onValidError;
|
|
1957
|
-
}
|
|
1958
1877
|
};
|
|
1959
1878
|
const resetField = (name, options = {}) => {
|
|
1960
1879
|
if (get(_fields, name)) {
|
|
1961
1880
|
if (isUndefined(options.defaultValue)) {
|
|
1962
|
-
setValue(name,
|
|
1881
|
+
setValue(name, get(_defaultValues, name));
|
|
1963
1882
|
}
|
|
1964
1883
|
else {
|
|
1965
1884
|
setValue(name, options.defaultValue);
|
|
1966
|
-
set(_defaultValues, name,
|
|
1885
|
+
set(_defaultValues, name, options.defaultValue);
|
|
1967
1886
|
}
|
|
1968
1887
|
if (!options.keepTouched) {
|
|
1969
1888
|
unset(_formState.touchedFields, name);
|
|
@@ -1971,7 +1890,7 @@
|
|
|
1971
1890
|
if (!options.keepDirty) {
|
|
1972
1891
|
unset(_formState.dirtyFields, name);
|
|
1973
1892
|
_formState.isDirty = options.defaultValue
|
|
1974
|
-
? _getDirty(name,
|
|
1893
|
+
? _getDirty(name, get(_defaultValues, name))
|
|
1975
1894
|
: _getDirty();
|
|
1976
1895
|
}
|
|
1977
1896
|
if (!options.keepError) {
|
|
@@ -1984,13 +1903,14 @@
|
|
|
1984
1903
|
const _reset = (formValues, keepStateOptions = {}) => {
|
|
1985
1904
|
const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
|
|
1986
1905
|
const cloneUpdatedValues = cloneObject(updatedValues);
|
|
1987
|
-
const
|
|
1988
|
-
|
|
1906
|
+
const values = formValues && !isEmptyObject(formValues)
|
|
1907
|
+
? cloneUpdatedValues
|
|
1908
|
+
: _defaultValues;
|
|
1989
1909
|
if (!keepStateOptions.keepDefaultValues) {
|
|
1990
1910
|
_defaultValues = updatedValues;
|
|
1991
1911
|
}
|
|
1992
1912
|
if (!keepStateOptions.keepValues) {
|
|
1993
|
-
if (keepStateOptions.keepDirtyValues) {
|
|
1913
|
+
if (keepStateOptions.keepDirtyValues || shouldCaptureDirtyFields) {
|
|
1994
1914
|
for (const fieldName of _names.mount) {
|
|
1995
1915
|
get(_formState.dirtyFields, fieldName)
|
|
1996
1916
|
? set(values, fieldName, get(_formValues, fieldName))
|
|
@@ -2030,50 +1950,38 @@
|
|
|
2030
1950
|
});
|
|
2031
1951
|
}
|
|
2032
1952
|
_names = {
|
|
2033
|
-
mount:
|
|
1953
|
+
mount: new Set(),
|
|
2034
1954
|
unMount: new Set(),
|
|
2035
1955
|
array: new Set(),
|
|
2036
1956
|
watch: new Set(),
|
|
2037
1957
|
watchAll: false,
|
|
2038
1958
|
focus: '',
|
|
2039
1959
|
};
|
|
2040
|
-
_state.mount
|
|
2041
|
-
|
|
2042
|
-
!!keepStateOptions.keepIsValid ||
|
|
2043
|
-
!!keepStateOptions.keepDirtyValues;
|
|
1960
|
+
!_state.mount && flushRootRender();
|
|
1961
|
+
_state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
|
|
2044
1962
|
_state.watch = !!props.shouldUnregister;
|
|
2045
1963
|
_subjects.state.next({
|
|
2046
1964
|
submitCount: keepStateOptions.keepSubmitCount
|
|
2047
1965
|
? _formState.submitCount
|
|
2048
1966
|
: 0,
|
|
2049
|
-
isDirty:
|
|
2050
|
-
?
|
|
2051
|
-
: keepStateOptions.
|
|
2052
|
-
|
|
2053
|
-
: !!(keepStateOptions.keepDefaultValues &&
|
|
2054
|
-
!deepEqual(formValues, _defaultValues)),
|
|
1967
|
+
isDirty: keepStateOptions.keepDirty
|
|
1968
|
+
? _formState.isDirty
|
|
1969
|
+
: !!(keepStateOptions.keepDefaultValues &&
|
|
1970
|
+
!deepEqual(formValues, _defaultValues)),
|
|
2055
1971
|
isSubmitted: keepStateOptions.keepIsSubmitted
|
|
2056
1972
|
? _formState.isSubmitted
|
|
2057
1973
|
: false,
|
|
2058
|
-
dirtyFields:
|
|
2059
|
-
?
|
|
2060
|
-
: keepStateOptions.
|
|
2061
|
-
?
|
|
2062
|
-
|
|
2063
|
-
: _formState.dirtyFields
|
|
2064
|
-
: keepStateOptions.keepDefaultValues && formValues
|
|
2065
|
-
? getDirtyFields(_defaultValues, formValues)
|
|
2066
|
-
: keepStateOptions.keepDirty
|
|
2067
|
-
? _formState.dirtyFields
|
|
2068
|
-
: {},
|
|
1974
|
+
dirtyFields: keepStateOptions.keepDirtyValues
|
|
1975
|
+
? _formState.dirtyFields
|
|
1976
|
+
: keepStateOptions.keepDefaultValues && formValues
|
|
1977
|
+
? getDirtyFields(_defaultValues, formValues)
|
|
1978
|
+
: {},
|
|
2069
1979
|
touchedFields: keepStateOptions.keepTouched
|
|
2070
1980
|
? _formState.touchedFields
|
|
2071
1981
|
: {},
|
|
2072
1982
|
errors: keepStateOptions.keepErrors ? _formState.errors : {},
|
|
2073
|
-
isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
|
|
2074
|
-
? _formState.isSubmitSuccessful
|
|
2075
|
-
: false,
|
|
2076
1983
|
isSubmitting: false,
|
|
1984
|
+
isSubmitSuccessful: false,
|
|
2077
1985
|
});
|
|
2078
1986
|
};
|
|
2079
1987
|
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
|
|
@@ -2123,10 +2031,8 @@
|
|
|
2123
2031
|
_reset,
|
|
2124
2032
|
_resetDefaultValues,
|
|
2125
2033
|
_updateFormState,
|
|
2126
|
-
_disableForm,
|
|
2127
2034
|
_subjects,
|
|
2128
2035
|
_proxyFormState,
|
|
2129
|
-
_setErrors,
|
|
2130
2036
|
get _fields() {
|
|
2131
2037
|
return _fields;
|
|
2132
2038
|
},
|
|
@@ -2223,16 +2129,14 @@
|
|
|
2223
2129
|
submitCount: 0,
|
|
2224
2130
|
dirtyFields: {},
|
|
2225
2131
|
touchedFields: {},
|
|
2226
|
-
|
|
2227
|
-
errors: props.errors || {},
|
|
2228
|
-
disabled: props.disabled || false,
|
|
2132
|
+
errors: {},
|
|
2229
2133
|
defaultValues: isFunction(props.defaultValues)
|
|
2230
2134
|
? undefined
|
|
2231
2135
|
: props.defaultValues,
|
|
2232
2136
|
});
|
|
2233
2137
|
if (!_formControl.current) {
|
|
2234
2138
|
_formControl.current = {
|
|
2235
|
-
...createFormControl(props),
|
|
2139
|
+
...createFormControl(props, () => updateFormState((formState) => ({ ...formState }))),
|
|
2236
2140
|
formState,
|
|
2237
2141
|
};
|
|
2238
2142
|
}
|
|
@@ -2246,32 +2150,15 @@
|
|
|
2246
2150
|
}
|
|
2247
2151
|
},
|
|
2248
2152
|
});
|
|
2249
|
-
React__default.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
|
|
2250
|
-
React__default.useEffect(() => {
|
|
2251
|
-
if (control._proxyFormState.isDirty) {
|
|
2252
|
-
const isDirty = control._getDirty();
|
|
2253
|
-
if (isDirty !== formState.isDirty) {
|
|
2254
|
-
control._subjects.state.next({
|
|
2255
|
-
isDirty,
|
|
2256
|
-
});
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
}, [control, formState.isDirty]);
|
|
2260
2153
|
React__default.useEffect(() => {
|
|
2261
2154
|
if (props.values && !deepEqual(props.values, _values.current)) {
|
|
2262
2155
|
control._reset(props.values, control._options.resetOptions);
|
|
2263
2156
|
_values.current = props.values;
|
|
2264
|
-
updateFormState((state) => ({ ...state }));
|
|
2265
2157
|
}
|
|
2266
2158
|
else {
|
|
2267
2159
|
control._resetDefaultValues();
|
|
2268
2160
|
}
|
|
2269
2161
|
}, [props.values, control]);
|
|
2270
|
-
React__default.useEffect(() => {
|
|
2271
|
-
if (props.errors) {
|
|
2272
|
-
control._setErrors(props.errors);
|
|
2273
|
-
}
|
|
2274
|
-
}, [props.errors, control]);
|
|
2275
2162
|
React__default.useEffect(() => {
|
|
2276
2163
|
if (!control._state.mount) {
|
|
2277
2164
|
control._updateValid();
|
|
@@ -2283,12 +2170,6 @@
|
|
|
2283
2170
|
}
|
|
2284
2171
|
control._removeUnmounted();
|
|
2285
2172
|
});
|
|
2286
|
-
React__default.useEffect(() => {
|
|
2287
|
-
props.shouldUnregister &&
|
|
2288
|
-
control._subjects.values.next({
|
|
2289
|
-
values: control._getWatch(),
|
|
2290
|
-
});
|
|
2291
|
-
}, [props.shouldUnregister, control]);
|
|
2292
2173
|
_formControl.current.formState = getProxyFormState(formState, control);
|
|
2293
2174
|
return _formControl.current;
|
|
2294
2175
|
}
|
|
@@ -2381,27 +2262,31 @@
|
|
|
2381
2262
|
});
|
|
2382
2263
|
|
|
2383
2264
|
var _excluded = ["ref"];
|
|
2265
|
+
|
|
2384
2266
|
var _templateObject$5, _templateObject2;
|
|
2385
2267
|
var OptionsRow = styled__default.div(_templateObject$5 || (_templateObject$5 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n"])));
|
|
2386
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
|
+
|
|
2387
2270
|
var CommunicationPreferenceOptionsRenderer = function CommunicationPreferenceOptionsRenderer(_ref) {
|
|
2388
2271
|
var control = _ref.control,
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2272
|
+
name = _ref.name,
|
|
2273
|
+
isDisabled = _ref.isDisabled,
|
|
2274
|
+
options = _ref.options,
|
|
2275
|
+
defaultValue = _ref.defaultValue,
|
|
2276
|
+
setValue = _ref.setValue;
|
|
2277
|
+
|
|
2394
2278
|
var _useController = useController({
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
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
|
+
|
|
2405
2290
|
React.useEffect(function () {
|
|
2406
2291
|
if (defaultValue) {
|
|
2407
2292
|
setValue(name, defaultValue);
|
|
@@ -2431,15 +2316,16 @@
|
|
|
2431
2316
|
return props.theme.colors.primary;
|
|
2432
2317
|
});
|
|
2433
2318
|
var SectionHeading = styled__default.div(_templateObject2$1 || (_templateObject2$1 = _taggedTemplateLiteral(["\n padding: 5px 10px;\n"])));
|
|
2319
|
+
|
|
2434
2320
|
var CommunicationPreferenceSection = function CommunicationPreferenceSection(_ref) {
|
|
2435
2321
|
var section_heading = _ref.section_heading,
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
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;
|
|
2443
2329
|
return /*#__PURE__*/React__default.createElement(SectionContainer, null, /*#__PURE__*/React__default.createElement(SectionHeading, null, section_heading), /*#__PURE__*/React__default.createElement(CommunicationPreferenceOptionsRenderer, {
|
|
2444
2330
|
description: description,
|
|
2445
2331
|
control: control,
|
|
@@ -2450,6 +2336,7 @@
|
|
|
2450
2336
|
setValue: setValue
|
|
2451
2337
|
}));
|
|
2452
2338
|
};
|
|
2339
|
+
|
|
2453
2340
|
var CommunicationPreferenceSection$1 = themed(CommunicationPreferenceSection);
|
|
2454
2341
|
|
|
2455
2342
|
var defaultNotifyTime = 5000;
|
|
@@ -2495,25 +2382,30 @@
|
|
|
2495
2382
|
success: false,
|
|
2496
2383
|
failed: false
|
|
2497
2384
|
};
|
|
2385
|
+
|
|
2498
2386
|
var CommunicationPreferences = function CommunicationPreferences(_ref) {
|
|
2499
2387
|
var header = _ref.header,
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2388
|
+
requestInstance = _ref.requestInstance,
|
|
2389
|
+
updateNotificationsApi = _ref.updateNotificationsApi,
|
|
2390
|
+
preferenceData = _ref.preferenceData,
|
|
2391
|
+
btnClassName = _ref.btnClassName;
|
|
2392
|
+
|
|
2504
2393
|
var _useForm = useForm(),
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2394
|
+
handleSubmit = _useForm.handleSubmit,
|
|
2395
|
+
control = _useForm.control,
|
|
2396
|
+
setValue = _useForm.setValue;
|
|
2397
|
+
|
|
2508
2398
|
var _useState = React.useState(_objectSpread2({}, BaseRequest)),
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2399
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2400
|
+
requestState = _useState2[0],
|
|
2401
|
+
setRequestState = _useState2[1];
|
|
2402
|
+
|
|
2512
2403
|
var _useState3 = React.useState(false),
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2404
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
2405
|
+
isEditing = _useState4[0],
|
|
2406
|
+
setIsEditing = _useState4[1]; //
|
|
2407
|
+
|
|
2408
|
+
|
|
2517
2409
|
var communicationOptions = [{
|
|
2518
2410
|
label: 'WhatsApp',
|
|
2519
2411
|
value: 'WHATSAPP'
|
|
@@ -2521,9 +2413,11 @@
|
|
|
2521
2413
|
label: 'Email',
|
|
2522
2414
|
value: 'EMAIL'
|
|
2523
2415
|
}];
|
|
2416
|
+
|
|
2524
2417
|
var updateRequestState = function updateRequestState(obj) {
|
|
2525
2418
|
setRequestState(_objectSpread2(_objectSpread2({}, BaseRequest), obj));
|
|
2526
2419
|
};
|
|
2420
|
+
|
|
2527
2421
|
var onSubmit = function onSubmit(form_data) {
|
|
2528
2422
|
updateRequestState({
|
|
2529
2423
|
loading: true
|
|
@@ -2552,6 +2446,7 @@
|
|
|
2552
2446
|
}));
|
|
2553
2447
|
});
|
|
2554
2448
|
};
|
|
2449
|
+
|
|
2555
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", {
|
|
2556
2451
|
onSubmit: handleSubmit(onSubmit)
|
|
2557
2452
|
}, /*#__PURE__*/React__default.createElement(CommunicationPreferenceSection$1, {
|
|
@@ -2579,6 +2474,7 @@
|
|
|
2579
2474
|
}
|
|
2580
2475
|
}, "Edit")))));
|
|
2581
2476
|
};
|
|
2477
|
+
|
|
2582
2478
|
var index = themed(CommunicationPreferences);
|
|
2583
2479
|
|
|
2584
2480
|
return index;
|