@thecb/components 3.5.11 → 3.5.12-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +638 -398
- package/package.json +1 -1
- package/src/components/atoms/alert/Alert.js +18 -12
- package/.tool-versions +0 -1
package/dist/index.cjs.js
CHANGED
|
@@ -215,6 +215,63 @@ function _nonIterableRest() {
|
|
|
215
215
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
219
|
+
var it;
|
|
220
|
+
|
|
221
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
|
222
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
223
|
+
if (it) o = it;
|
|
224
|
+
var i = 0;
|
|
225
|
+
|
|
226
|
+
var F = function () {};
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
s: F,
|
|
230
|
+
n: function () {
|
|
231
|
+
if (i >= o.length) return {
|
|
232
|
+
done: true
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
done: false,
|
|
236
|
+
value: o[i++]
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
e: function (e) {
|
|
240
|
+
throw e;
|
|
241
|
+
},
|
|
242
|
+
f: F
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
var normalCompletion = true,
|
|
250
|
+
didErr = false,
|
|
251
|
+
err;
|
|
252
|
+
return {
|
|
253
|
+
s: function () {
|
|
254
|
+
it = o[Symbol.iterator]();
|
|
255
|
+
},
|
|
256
|
+
n: function () {
|
|
257
|
+
var step = it.next();
|
|
258
|
+
normalCompletion = step.done;
|
|
259
|
+
return step;
|
|
260
|
+
},
|
|
261
|
+
e: function (e) {
|
|
262
|
+
didErr = true;
|
|
263
|
+
err = e;
|
|
264
|
+
},
|
|
265
|
+
f: function () {
|
|
266
|
+
try {
|
|
267
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
268
|
+
} finally {
|
|
269
|
+
if (didErr) throw err;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
218
275
|
/*! *****************************************************************************
|
|
219
276
|
Copyright (c) Microsoft Corporation.
|
|
220
277
|
|
|
@@ -10038,11 +10095,9 @@ function usePanGesture(_a, ref) {
|
|
|
10038
10095
|
onPanEnd && onPanEnd(event, info);
|
|
10039
10096
|
},
|
|
10040
10097
|
};
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
}
|
|
10045
|
-
});
|
|
10098
|
+
if (panSession.current !== null) {
|
|
10099
|
+
panSession.current.updateHandlers(handlers);
|
|
10100
|
+
}
|
|
10046
10101
|
function onPointerDown(event) {
|
|
10047
10102
|
panSession.current = new PanSession(event, handlers, {
|
|
10048
10103
|
transformPagePoint: transformPagePoint,
|
|
@@ -14239,18 +14294,21 @@ var fallbackValues$4 = {
|
|
|
14239
14294
|
var Alert = function Alert(_ref) {
|
|
14240
14295
|
var heading = _ref.heading,
|
|
14241
14296
|
text = _ref.text,
|
|
14297
|
+
textOverride = _ref.textOverride,
|
|
14242
14298
|
variant = _ref.variant,
|
|
14243
14299
|
children = _ref.children,
|
|
14244
14300
|
height = _ref.height,
|
|
14245
14301
|
onLinkClick = _ref.onLinkClick,
|
|
14302
|
+
_ref$padding = _ref.padding,
|
|
14303
|
+
padding = _ref$padding === void 0 ? "0.5rem" : _ref$padding,
|
|
14246
14304
|
_ref$showQuitLink = _ref.showQuitLink,
|
|
14247
14305
|
showQuitLink = _ref$showQuitLink === void 0 ? true : _ref$showQuitLink,
|
|
14248
14306
|
themeValues = _ref.themeValues;
|
|
14249
14307
|
var Icon = AlertIcons[variant];
|
|
14250
14308
|
return /*#__PURE__*/React__default.createElement(Box, {
|
|
14251
|
-
padding:
|
|
14309
|
+
padding: padding,
|
|
14252
14310
|
width: "100%",
|
|
14253
|
-
minHeight: "100px",
|
|
14311
|
+
minHeight: height && parseInt(height) < 100 ? height : "100px",
|
|
14254
14312
|
height: height ? height : "auto",
|
|
14255
14313
|
background: themeValues.background,
|
|
14256
14314
|
borderRadius: "4px",
|
|
@@ -14276,11 +14334,11 @@ var Alert = function Alert(_ref) {
|
|
|
14276
14334
|
width: "24px",
|
|
14277
14335
|
childGap: "0rem"
|
|
14278
14336
|
}, /*#__PURE__*/React__default.createElement(Box, {
|
|
14279
|
-
padding: "1rem"
|
|
14337
|
+
padding: "".concat(padding, " 1rem")
|
|
14280
14338
|
}, /*#__PURE__*/React__default.createElement(Cluster, {
|
|
14281
14339
|
justify: "flex-start",
|
|
14282
14340
|
align: "center"
|
|
14283
|
-
}, /*#__PURE__*/React__default.createElement(Stack, {
|
|
14341
|
+
}, textOverride ? textOverride : /*#__PURE__*/React__default.createElement(Stack, {
|
|
14284
14342
|
fullHeight: true,
|
|
14285
14343
|
childGap: "0.25rem"
|
|
14286
14344
|
}, /*#__PURE__*/React__default.createElement(Text$1, {
|
|
@@ -15345,7 +15403,7 @@ _curry2(function nth(offset, list) {
|
|
|
15345
15403
|
*
|
|
15346
15404
|
* @func
|
|
15347
15405
|
* @memberOf R
|
|
15348
|
-
* @since v0.27.
|
|
15406
|
+
* @since v0.27.0
|
|
15349
15407
|
* @category Object
|
|
15350
15408
|
* @typedefn Idx = [String | Int]
|
|
15351
15409
|
* @sig [Idx] -> {a} -> [a | Undefined]
|
|
@@ -30518,378 +30576,401 @@ var ToggleSwitch = function ToggleSwitch(_ref6) {
|
|
|
30518
30576
|
|
|
30519
30577
|
var ToggleSwitch$1 = themeComponent(ToggleSwitch, "ToggleSwitch", fallbackValues$o);
|
|
30520
30578
|
|
|
30521
|
-
|
|
30522
|
-
value
|
|
30523
|
-
|
|
30524
|
-
|
|
30579
|
+
var validatorToPredicate = function validatorToPredicate(validatorFn, emptyCase) {
|
|
30580
|
+
return function (value) {
|
|
30581
|
+
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
30582
|
+
rest[_key - 1] = arguments[_key];
|
|
30583
|
+
}
|
|
30525
30584
|
|
|
30585
|
+
return value === "" ? emptyCase : validatorFn.apply(void 0, [value].concat(rest));
|
|
30586
|
+
};
|
|
30587
|
+
};
|
|
30526
30588
|
/* eslint-disable no-unused-vars */
|
|
30527
30589
|
|
|
30528
|
-
|
|
30529
|
-
|
|
30590
|
+
|
|
30591
|
+
var createValidator = function createValidator(type, error) {
|
|
30592
|
+
var validator = function validator() {
|
|
30593
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
30594
|
+
args[_key2] = arguments[_key2];
|
|
30595
|
+
}
|
|
30596
|
+
|
|
30597
|
+
return {
|
|
30598
|
+
type: type,
|
|
30599
|
+
args: args,
|
|
30600
|
+
error: error
|
|
30601
|
+
};
|
|
30602
|
+
};
|
|
30603
|
+
|
|
30530
30604
|
validator.error = error;
|
|
30531
30605
|
return validator;
|
|
30532
30606
|
};
|
|
30533
30607
|
|
|
30534
|
-
|
|
30608
|
+
var validatorFns = {};
|
|
30609
|
+
var REQUIRED = "validator/REQUIRED";
|
|
30610
|
+
var REQUIRED_ERROR = "error/REQUIRED";
|
|
30611
|
+
var required = createValidator(REQUIRED, REQUIRED_ERROR);
|
|
30535
30612
|
|
|
30536
|
-
|
|
30537
|
-
|
|
30538
|
-
|
|
30539
|
-
validatorFns[REQUIRED] = (value, args, form) => value !== "";
|
|
30613
|
+
validatorFns[REQUIRED] = function (value, args, form) {
|
|
30614
|
+
return value !== "";
|
|
30615
|
+
};
|
|
30540
30616
|
|
|
30541
|
-
|
|
30542
|
-
|
|
30543
|
-
|
|
30544
|
-
validatorFns[ONLY_INTEGERS] = (value, args, form) => /^(-?\d+)?$/.test(value);
|
|
30617
|
+
var ONLY_INTEGERS = "validator/ONLY_INTEGERS";
|
|
30618
|
+
var ONLY_INTEGERS_ERROR = "error/ONLY_INTEGERS";
|
|
30619
|
+
var onlyIntegers = createValidator(ONLY_INTEGERS, ONLY_INTEGERS_ERROR);
|
|
30545
30620
|
|
|
30546
|
-
|
|
30547
|
-
|
|
30548
|
-
|
|
30549
|
-
validatorFns[ONLY_NATURALS] = (value, args, form) => /^(\d+)?$/.test(value);
|
|
30621
|
+
validatorFns[ONLY_INTEGERS] = function (value, args, form) {
|
|
30622
|
+
return /^(-?\d+)?$/.test(value);
|
|
30623
|
+
};
|
|
30550
30624
|
|
|
30551
|
-
|
|
30552
|
-
|
|
30553
|
-
|
|
30554
|
-
|
|
30555
|
-
|
|
30556
|
-
);
|
|
30557
|
-
|
|
30625
|
+
var ONLY_NATURALS = "validator/ONLY_NATURALS";
|
|
30626
|
+
var ONLY_NATURALS_ERROR = "error/ONLY_NATURALS";
|
|
30627
|
+
var onlyNaturals = createValidator(ONLY_NATURALS, ONLY_NATURALS_ERROR);
|
|
30628
|
+
|
|
30629
|
+
validatorFns[ONLY_NATURALS] = function (value, args, form) {
|
|
30630
|
+
return /^(\d+)?$/.test(value);
|
|
30631
|
+
};
|
|
30632
|
+
|
|
30633
|
+
var NUMBER_LESS_THAN = "validator/NUMBER_LESS_THAN";
|
|
30634
|
+
var NUMBER_LESS_THAN_ERROR = "error/NUMBER_LESS_THAN";
|
|
30635
|
+
var numberLessThan = createValidator(NUMBER_LESS_THAN, NUMBER_LESS_THAN_ERROR);
|
|
30636
|
+
|
|
30637
|
+
validatorFns[NUMBER_LESS_THAN] = function (value, args, form) {
|
|
30558
30638
|
if (value === "") {
|
|
30559
30639
|
return true;
|
|
30560
30640
|
}
|
|
30641
|
+
|
|
30561
30642
|
return Number(value) < args[0];
|
|
30562
30643
|
};
|
|
30563
30644
|
|
|
30564
|
-
|
|
30565
|
-
|
|
30566
|
-
|
|
30567
|
-
|
|
30568
|
-
|
|
30569
|
-
NUMBER_LESS_THAN_OR_EQUAL_TO,
|
|
30570
|
-
NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR
|
|
30571
|
-
);
|
|
30572
|
-
validatorFns[NUMBER_LESS_THAN_OR_EQUAL_TO] = (value, args, form) => {
|
|
30645
|
+
var NUMBER_LESS_THAN_OR_EQUAL_TO = "validator/NUMBER_LESS_THAN_OR_EQUAL_TO";
|
|
30646
|
+
var NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR = "error/NUMBER_LESS_THAN_OR_EQUAL_TO";
|
|
30647
|
+
var numberLessThanOrEqualTo = createValidator(NUMBER_LESS_THAN_OR_EQUAL_TO, NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR);
|
|
30648
|
+
|
|
30649
|
+
validatorFns[NUMBER_LESS_THAN_OR_EQUAL_TO] = function (value, args, form) {
|
|
30573
30650
|
if (value === "") {
|
|
30574
30651
|
return true;
|
|
30575
30652
|
}
|
|
30653
|
+
|
|
30576
30654
|
return Number(value) <= args[0];
|
|
30577
30655
|
};
|
|
30578
30656
|
|
|
30579
|
-
|
|
30580
|
-
|
|
30581
|
-
|
|
30582
|
-
|
|
30583
|
-
|
|
30584
|
-
);
|
|
30585
|
-
validatorFns[NUMBER_GREATER_THAN] = (value, args, form) => {
|
|
30657
|
+
var NUMBER_GREATER_THAN = "validator/NUMBER_GREATER_THAN";
|
|
30658
|
+
var NUMBER_GREATER_THAN_ERROR = "error/NUMBER_GREATER_THAN";
|
|
30659
|
+
var numberGreaterThan = createValidator(NUMBER_GREATER_THAN, NUMBER_GREATER_THAN_ERROR);
|
|
30660
|
+
|
|
30661
|
+
validatorFns[NUMBER_GREATER_THAN] = function (value, args, form) {
|
|
30586
30662
|
if (value === "") {
|
|
30587
30663
|
return true;
|
|
30588
30664
|
}
|
|
30665
|
+
|
|
30589
30666
|
return Number(value) > args[0];
|
|
30590
30667
|
};
|
|
30591
30668
|
|
|
30592
|
-
|
|
30593
|
-
|
|
30594
|
-
|
|
30595
|
-
|
|
30596
|
-
|
|
30597
|
-
NUMBER_GREATER_THAN_OR_EQUAL_TO,
|
|
30598
|
-
NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR
|
|
30599
|
-
);
|
|
30600
|
-
validatorFns[NUMBER_GREATER_THAN_OR_EQUAL_TO] = (value, args, form) => {
|
|
30669
|
+
var NUMBER_GREATER_THAN_OR_EQUAL_TO = "validator/NUMBER_GREATER_THAN_OR_EQUAL_TO";
|
|
30670
|
+
var NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR = "error/NUMBER_GREATER_THAN_OR_EQUAL_TO";
|
|
30671
|
+
var numberGreaterThanOrEqualTo = createValidator(NUMBER_GREATER_THAN_OR_EQUAL_TO, NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR);
|
|
30672
|
+
|
|
30673
|
+
validatorFns[NUMBER_GREATER_THAN_OR_EQUAL_TO] = function (value, args, form) {
|
|
30601
30674
|
if (value === "") {
|
|
30602
30675
|
return true;
|
|
30603
30676
|
}
|
|
30677
|
+
|
|
30604
30678
|
return Number(value) >= args[0];
|
|
30605
30679
|
};
|
|
30606
30680
|
|
|
30607
|
-
|
|
30608
|
-
|
|
30609
|
-
|
|
30610
|
-
|
|
30681
|
+
var MATCHES_FIELD = "validator/MATCHES_FIELD";
|
|
30682
|
+
var MATCHES_FIELD_ERROR$1 = "error/MATCHES_FIELD";
|
|
30683
|
+
var matchesField = createValidator(MATCHES_FIELD, MATCHES_FIELD_ERROR$1);
|
|
30684
|
+
|
|
30685
|
+
validatorFns[MATCHES_FIELD] = function (value, args, form) {
|
|
30611
30686
|
if (value === "") {
|
|
30612
30687
|
return true;
|
|
30613
30688
|
}
|
|
30689
|
+
|
|
30614
30690
|
if (form[args[0]] === undefined) {
|
|
30615
|
-
throw new Error(
|
|
30616
|
-
`${args[0]} was passed to matchesField, but that field does not exist in the form`
|
|
30617
|
-
);
|
|
30691
|
+
throw new Error("".concat(args[0], " was passed to matchesField, but that field does not exist in the form"));
|
|
30618
30692
|
}
|
|
30693
|
+
|
|
30619
30694
|
return value === form[args[0]].rawValue;
|
|
30620
30695
|
};
|
|
30621
30696
|
|
|
30622
|
-
|
|
30623
|
-
|
|
30624
|
-
|
|
30625
|
-
|
|
30626
|
-
|
|
30627
|
-
|
|
30628
|
-
|
|
30629
|
-
|
|
30630
|
-
|
|
30631
|
-
|
|
30632
|
-
|
|
30633
|
-
|
|
30634
|
-
|
|
30635
|
-
|
|
30636
|
-
|
|
30637
|
-
type: VALIDATE_WHEN,
|
|
30638
|
-
args: [dependentValidator, primaryValidator, optionalFieldName],
|
|
30639
|
-
error: dependentValidator.error
|
|
30640
|
-
});
|
|
30697
|
+
var validateWhenErrorMessage = function validateWhenErrorMessage(type) {
|
|
30698
|
+
return "".concat(type, " was passed to validateWhen, but that validator type does not exist.\n Please check that you are only calling validator creator functions exported from\n redux-freeform in your form config and that you didn't forget to\n invoke the validator creator (you cannot pass the functions themselves to\n createFormState). Also make sure you aren't passing validateWhen() to validateWhen\n as the primary validator.");
|
|
30699
|
+
};
|
|
30700
|
+
|
|
30701
|
+
var VALIDATE_WHEN = "validator/VALIDATE_WHEN";
|
|
30702
|
+
var VALIDATE_WHEN_ERROR = "error/VALIDATE_WHEN";
|
|
30703
|
+
|
|
30704
|
+
var validateWhen = function validateWhen(dependentValidator, primaryValidator, optionalFieldName) {
|
|
30705
|
+
return {
|
|
30706
|
+
type: VALIDATE_WHEN,
|
|
30707
|
+
args: [dependentValidator, primaryValidator, optionalFieldName],
|
|
30708
|
+
error: dependentValidator.error
|
|
30709
|
+
};
|
|
30710
|
+
};
|
|
30711
|
+
|
|
30641
30712
|
validateWhen.error = VALIDATE_WHEN_ERROR;
|
|
30642
|
-
validatorFns[VALIDATE_WHEN] = (value, args, form) => {
|
|
30643
|
-
const [dependentValidator, primaryValidator, optionalFieldName] = args;
|
|
30644
|
-
const dependsOnOtherField = typeof optionalFieldName === "string";
|
|
30645
30713
|
|
|
30646
|
-
|
|
30647
|
-
|
|
30648
|
-
|
|
30649
|
-
|
|
30714
|
+
validatorFns[VALIDATE_WHEN] = function (value, args, form) {
|
|
30715
|
+
var _args = _slicedToArray(args, 3),
|
|
30716
|
+
dependentValidator = _args[0],
|
|
30717
|
+
primaryValidator = _args[1],
|
|
30718
|
+
optionalFieldName = _args[2];
|
|
30719
|
+
|
|
30720
|
+
var dependsOnOtherField = typeof optionalFieldName === "string";
|
|
30721
|
+
|
|
30722
|
+
if (primaryValidator.type === undefined || typeof validatorFns[primaryValidator.type] !== "function") {
|
|
30650
30723
|
throw new Error(validateWhenErrorMessage(primaryValidator.type));
|
|
30651
30724
|
}
|
|
30725
|
+
|
|
30652
30726
|
if (dependsOnOtherField && form[optionalFieldName] === undefined) {
|
|
30653
|
-
throw new Error(
|
|
30654
|
-
`${args[2]} was passed to matchesField, but that field does not exist in the form`
|
|
30655
|
-
);
|
|
30727
|
+
throw new Error("".concat(args[2], " was passed to matchesField, but that field does not exist in the form"));
|
|
30656
30728
|
}
|
|
30657
30729
|
|
|
30658
|
-
|
|
30659
|
-
|
|
30660
|
-
|
|
30661
|
-
);
|
|
30662
|
-
|
|
30663
|
-
|
|
30664
|
-
|
|
30665
|
-
|
|
30666
|
-
|
|
30667
|
-
|
|
30668
|
-
|
|
30669
|
-
|
|
30730
|
+
var primaryPredicate = validatorToPredicate(validatorFns[primaryValidator.type], false);
|
|
30731
|
+
var primaryValue = dependsOnOtherField ? form[optionalFieldName].rawValue : value;
|
|
30732
|
+
var primaryPredicatePassed = primaryPredicate(primaryValue, primaryValidator.args, form);
|
|
30733
|
+
return primaryPredicatePassed ? validatorFns[dependentValidator.type](value, dependentValidator.args, form) : true;
|
|
30734
|
+
};
|
|
30735
|
+
|
|
30736
|
+
var validateSumErrorMessage = function validateSumErrorMessage(type) {
|
|
30737
|
+
return "".concat(type, " was passed to validateSum, but that validator type does not exist.\n Please check that you are only calling validator creator functions exported from\n redux-freeform in your form config and that you didn't forget to\n invoke the validator creator (you cannot pass the functions themselves to\n createFormState).");
|
|
30738
|
+
};
|
|
30739
|
+
|
|
30740
|
+
var VALIDATE_SUM = "validator/VALIDATE_SUM";
|
|
30741
|
+
var VALIDATE_SUM_ERROR = "error/VALIDATE_SUM";
|
|
30742
|
+
|
|
30743
|
+
var validateSum = function validateSum(validator, fieldNamesArray) {
|
|
30744
|
+
return {
|
|
30745
|
+
type: VALIDATE_SUM,
|
|
30746
|
+
args: [validator, fieldNamesArray],
|
|
30747
|
+
error: validator.error
|
|
30748
|
+
};
|
|
30749
|
+
};
|
|
30670
30750
|
|
|
30671
|
-
return primaryPredicatePassed
|
|
30672
|
-
? validatorFns[dependentValidator.type](
|
|
30673
|
-
value,
|
|
30674
|
-
dependentValidator.args,
|
|
30675
|
-
form
|
|
30676
|
-
)
|
|
30677
|
-
: true;
|
|
30678
|
-
};
|
|
30679
|
-
|
|
30680
|
-
const validateSumErrorMessage = type =>
|
|
30681
|
-
`${type} was passed to validateSum, but that validator type does not exist.
|
|
30682
|
-
Please check that you are only calling validator creator functions exported from
|
|
30683
|
-
redux-freeform in your form config and that you didn't forget to
|
|
30684
|
-
invoke the validator creator (you cannot pass the functions themselves to
|
|
30685
|
-
createFormState).`;
|
|
30686
|
-
const VALIDATE_SUM = "validator/VALIDATE_SUM";
|
|
30687
|
-
const VALIDATE_SUM_ERROR = "error/VALIDATE_SUM";
|
|
30688
|
-
const validateSum = (validator, fieldNamesArray) => ({
|
|
30689
|
-
type: VALIDATE_SUM,
|
|
30690
|
-
args: [validator, fieldNamesArray],
|
|
30691
|
-
error: validator.error
|
|
30692
|
-
});
|
|
30693
30751
|
validateSum.error = VALIDATE_SUM_ERROR;
|
|
30694
|
-
validatorFns[VALIDATE_SUM] = (value, args, form) => {
|
|
30695
|
-
const [validator, fieldNamesArray] = args;
|
|
30696
30752
|
|
|
30697
|
-
|
|
30698
|
-
|
|
30699
|
-
|
|
30700
|
-
|
|
30753
|
+
validatorFns[VALIDATE_SUM] = function (value, args, form) {
|
|
30754
|
+
var _args2 = _slicedToArray(args, 2),
|
|
30755
|
+
validator = _args2[0],
|
|
30756
|
+
fieldNamesArray = _args2[1];
|
|
30757
|
+
|
|
30758
|
+
if (validator.type === undefined || typeof validatorFns[validator.type] !== "function") {
|
|
30701
30759
|
throw new Error(validateSumErrorMessage(validator.type));
|
|
30702
30760
|
}
|
|
30703
30761
|
|
|
30704
|
-
|
|
30705
|
-
|
|
30706
|
-
|
|
30707
|
-
|
|
30708
|
-
|
|
30762
|
+
var _iterator = _createForOfIteratorHelper(fieldNamesArray),
|
|
30763
|
+
_step;
|
|
30764
|
+
|
|
30765
|
+
try {
|
|
30766
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
30767
|
+
var fieldName = _step.value;
|
|
30768
|
+
|
|
30769
|
+
if (form[fieldName] === undefined) {
|
|
30770
|
+
throw new Error("".concat(fieldName, " was passed to matchesField, but that field does not exist in the form"));
|
|
30771
|
+
}
|
|
30709
30772
|
}
|
|
30773
|
+
} catch (err) {
|
|
30774
|
+
_iterator.e(err);
|
|
30775
|
+
} finally {
|
|
30776
|
+
_iterator.f();
|
|
30710
30777
|
}
|
|
30711
30778
|
|
|
30712
|
-
|
|
30713
|
-
|
|
30714
|
-
|
|
30715
|
-
);
|
|
30716
|
-
|
|
30779
|
+
var sum = fieldNamesArray.reduce(function (acc, curr) {
|
|
30780
|
+
return acc + Number(form[curr].rawValue);
|
|
30781
|
+
}, Number(value));
|
|
30717
30782
|
return validatorFns[validator.type](sum, validator.args, form);
|
|
30718
30783
|
};
|
|
30719
30784
|
|
|
30720
|
-
|
|
30721
|
-
|
|
30722
|
-
|
|
30723
|
-
|
|
30785
|
+
var HAS_LENGTH = "validator/HAS_LENGTH";
|
|
30786
|
+
var HAS_LENGTH_ERROR = "error/HAS_LENGTH";
|
|
30787
|
+
var hasLength = createValidator(HAS_LENGTH, HAS_LENGTH_ERROR);
|
|
30788
|
+
|
|
30789
|
+
validatorFns[HAS_LENGTH] = function (value, args, form) {
|
|
30724
30790
|
if (value === "") {
|
|
30725
30791
|
return true;
|
|
30726
30792
|
}
|
|
30727
|
-
|
|
30728
|
-
|
|
30793
|
+
|
|
30794
|
+
var min = args[0];
|
|
30795
|
+
var max = args[1];
|
|
30796
|
+
|
|
30729
30797
|
if (max == undefined || min == undefined) {
|
|
30730
|
-
throw new Error(
|
|
30731
|
-
"Max and min need to be defined for hasLength, both or one of them is undefined"
|
|
30732
|
-
);
|
|
30798
|
+
throw new Error("Max and min need to be defined for hasLength, both or one of them is undefined");
|
|
30733
30799
|
}
|
|
30800
|
+
|
|
30734
30801
|
if (max < min) {
|
|
30735
|
-
throw new Error(
|
|
30736
|
-
"hasLength validator was passed a min greater than the max"
|
|
30737
|
-
);
|
|
30802
|
+
throw new Error("hasLength validator was passed a min greater than the max");
|
|
30738
30803
|
}
|
|
30739
|
-
|
|
30804
|
+
|
|
30805
|
+
var valueLength = value.length;
|
|
30740
30806
|
return max >= valueLength && valueLength >= min;
|
|
30741
30807
|
};
|
|
30742
30808
|
|
|
30743
|
-
|
|
30744
|
-
|
|
30745
|
-
|
|
30746
|
-
|
|
30809
|
+
var MATCHES_REGEX = "validator/MATCHES_REGEX";
|
|
30810
|
+
var MATCHES_REGEX_ERROR = "error/MATCHES_REGEX";
|
|
30811
|
+
var matchesRegex = createValidator(MATCHES_REGEX, MATCHES_REGEX_ERROR);
|
|
30812
|
+
|
|
30813
|
+
validatorFns[MATCHES_REGEX] = function (value, args, form) {
|
|
30747
30814
|
if (value === "") {
|
|
30748
30815
|
return true;
|
|
30749
30816
|
}
|
|
30817
|
+
|
|
30750
30818
|
return new RegExp(args[0]).test(value); // new RexExp never throws an error, no matter the input
|
|
30751
|
-
};
|
|
30819
|
+
}; // based on http://www.brainjar.com/js/validation/
|
|
30752
30820
|
|
|
30753
|
-
|
|
30754
|
-
|
|
30755
|
-
|
|
30756
|
-
|
|
30757
|
-
|
|
30758
|
-
|
|
30759
|
-
);
|
|
30760
|
-
validatorFns[IS_ROUTING_NUMBER] = (value, args, form) => {
|
|
30821
|
+
|
|
30822
|
+
var IS_ROUTING_NUMBER = "validator/IS_ROUTING_NUMBER";
|
|
30823
|
+
var IS_ROUTING_NUMBER_ERROR = "error/IS_ROUTING_NUMBER";
|
|
30824
|
+
var isRoutingNumber = createValidator(IS_ROUTING_NUMBER, IS_ROUTING_NUMBER_ERROR);
|
|
30825
|
+
|
|
30826
|
+
validatorFns[IS_ROUTING_NUMBER] = function (value, args, form) {
|
|
30761
30827
|
if (value === "") {
|
|
30762
30828
|
return true;
|
|
30763
30829
|
}
|
|
30830
|
+
|
|
30764
30831
|
if (value.length != 9) {
|
|
30765
30832
|
return false;
|
|
30766
30833
|
}
|
|
30767
|
-
|
|
30768
|
-
|
|
30769
|
-
|
|
30770
|
-
|
|
30771
|
-
|
|
30772
|
-
|
|
30773
|
-
|
|
30774
|
-
|
|
30775
|
-
|
|
30776
|
-
|
|
30777
|
-
|
|
30778
|
-
|
|
30779
|
-
|
|
30834
|
+
|
|
30835
|
+
var sum = value.split("").map(function (ch) {
|
|
30836
|
+
return parseInt(ch);
|
|
30837
|
+
}).reduce(function (acc, cur, idx) {
|
|
30838
|
+
switch (idx % 3) {
|
|
30839
|
+
case 0:
|
|
30840
|
+
return acc + 3 * cur;
|
|
30841
|
+
|
|
30842
|
+
case 1:
|
|
30843
|
+
return acc + 7 * cur;
|
|
30844
|
+
|
|
30845
|
+
case 2:
|
|
30846
|
+
return acc + 1 * cur;
|
|
30847
|
+
}
|
|
30848
|
+
}, 0);
|
|
30780
30849
|
return sum != 0 && sum % 10 == 0;
|
|
30781
30850
|
};
|
|
30782
30851
|
|
|
30783
|
-
|
|
30784
|
-
|
|
30785
|
-
|
|
30786
|
-
|
|
30852
|
+
var HAS_NUMBER = "validator/HAS_NUMBER";
|
|
30853
|
+
var HAS_NUMBER_ERROR$1 = "error/HAS_NUMBER";
|
|
30854
|
+
var hasNumber = createValidator(HAS_NUMBER, HAS_NUMBER_ERROR$1);
|
|
30855
|
+
|
|
30856
|
+
validatorFns[HAS_NUMBER] = function (value, args, form) {
|
|
30787
30857
|
if (value === "") {
|
|
30788
30858
|
return true;
|
|
30789
30859
|
}
|
|
30860
|
+
|
|
30790
30861
|
return new RegExp(/[0-9]/).test(value);
|
|
30791
30862
|
};
|
|
30792
30863
|
|
|
30793
|
-
|
|
30794
|
-
|
|
30795
|
-
|
|
30796
|
-
|
|
30797
|
-
|
|
30798
|
-
);
|
|
30799
|
-
validatorFns[HAS_LOWERCASE_LETTER] = (value, args, form) => {
|
|
30864
|
+
var HAS_LOWERCASE_LETTER = "validator/HAS_LOWERCASE_LETTER";
|
|
30865
|
+
var HAS_LOWERCASE_LETTER_ERROR$1 = "error/HAS_LOWERCASE_LETTER";
|
|
30866
|
+
var hasLowercaseLetter = createValidator(HAS_LOWERCASE_LETTER, HAS_LOWERCASE_LETTER_ERROR$1);
|
|
30867
|
+
|
|
30868
|
+
validatorFns[HAS_LOWERCASE_LETTER] = function (value, args, form) {
|
|
30800
30869
|
if (value === "") {
|
|
30801
30870
|
return true;
|
|
30802
30871
|
}
|
|
30872
|
+
|
|
30803
30873
|
return new RegExp(/[a-z]/).test(value);
|
|
30804
30874
|
};
|
|
30805
30875
|
|
|
30806
|
-
|
|
30807
|
-
|
|
30808
|
-
|
|
30809
|
-
|
|
30810
|
-
|
|
30811
|
-
);
|
|
30812
|
-
validatorFns[HAS_UPPERCASE_LETTER] = (value, args, form) => {
|
|
30876
|
+
var HAS_UPPERCASE_LETTER = "validator/HAS_UPPERCASE_LETTER";
|
|
30877
|
+
var HAS_UPPERCASE_LETTER_ERROR$1 = "error/HAS_UPPERCASE_LETTER";
|
|
30878
|
+
var hasUppercaseLetter = createValidator(HAS_UPPERCASE_LETTER, HAS_UPPERCASE_LETTER_ERROR$1);
|
|
30879
|
+
|
|
30880
|
+
validatorFns[HAS_UPPERCASE_LETTER] = function (value, args, form) {
|
|
30813
30881
|
if (value === "") {
|
|
30814
30882
|
return true;
|
|
30815
30883
|
}
|
|
30884
|
+
|
|
30816
30885
|
return new RegExp(/[A-Z]/).test(value);
|
|
30817
30886
|
};
|
|
30818
30887
|
|
|
30819
|
-
|
|
30820
|
-
|
|
30821
|
-
|
|
30822
|
-
|
|
30823
|
-
|
|
30824
|
-
);
|
|
30825
|
-
validatorFns[HAS_SPECIAL_CHARACTER] = (value, args, form) => {
|
|
30888
|
+
var HAS_SPECIAL_CHARACTER = "validator/HAS_SPECIAL_CHARACTER";
|
|
30889
|
+
var HAS_SPECIAL_CHARACTER_ERROR$1 = "error/HAS_SPECIAL_CHARACTER";
|
|
30890
|
+
var hasSpecialCharacter = createValidator(HAS_SPECIAL_CHARACTER, HAS_SPECIAL_CHARACTER_ERROR$1);
|
|
30891
|
+
|
|
30892
|
+
validatorFns[HAS_SPECIAL_CHARACTER] = function (value, args, form) {
|
|
30826
30893
|
if (value === "") {
|
|
30827
30894
|
return true;
|
|
30828
30895
|
}
|
|
30896
|
+
|
|
30829
30897
|
return new RegExp(/[!@#$%^&*.?]/).test(value);
|
|
30830
30898
|
};
|
|
30831
30899
|
|
|
30832
|
-
|
|
30833
|
-
|
|
30834
|
-
|
|
30835
|
-
|
|
30836
|
-
|
|
30837
|
-
);
|
|
30838
|
-
validatorFns[IS_PROBABLY_EMAIL] = (value, args, form) => {
|
|
30900
|
+
var IS_PROBABLY_EMAIL = "validator/IS_PROBABLY_EMAIL";
|
|
30901
|
+
var IS_PROBABLY_EMAIL_ERROR = "error/IS_PROBABLY_EMAIL";
|
|
30902
|
+
var isProbablyEmail = createValidator(IS_PROBABLY_EMAIL, IS_PROBABLY_EMAIL_ERROR);
|
|
30903
|
+
|
|
30904
|
+
validatorFns[IS_PROBABLY_EMAIL] = function (value, args, form) {
|
|
30839
30905
|
if (value === "") {
|
|
30840
30906
|
return true;
|
|
30841
30907
|
}
|
|
30908
|
+
|
|
30842
30909
|
return new RegExp(/^\S+@\S+\.\S+$/).test(value);
|
|
30843
30910
|
};
|
|
30844
30911
|
|
|
30845
|
-
|
|
30846
|
-
|
|
30847
|
-
|
|
30848
|
-
|
|
30849
|
-
|
|
30850
|
-
|
|
30912
|
+
var runValidatorErrorMessage = function runValidatorErrorMessage(type) {
|
|
30913
|
+
return "".concat(type, " was passed to runValidator, but that validator type does not exist. \n Please check that you are only calling validator creator functions exported from \n redux-freeform in your form config and that you didn't forget to \n invoke the validator creator (you cannot pass the functions themselves to \n createFormState)");
|
|
30914
|
+
};
|
|
30915
|
+
|
|
30916
|
+
var runValidator = function runValidator(validator, value, form) {
|
|
30917
|
+
var validatorFn = validatorFns[validator.type];
|
|
30851
30918
|
|
|
30852
|
-
const runValidator = (validator, value, form) => {
|
|
30853
|
-
const validatorFn = validatorFns[validator.type];
|
|
30854
30919
|
if (validatorFn === undefined) {
|
|
30855
30920
|
throw new Error(runValidatorErrorMessage(validator.type));
|
|
30856
30921
|
}
|
|
30922
|
+
|
|
30857
30923
|
return validatorFn(value, validator.args, form) ? null : validator.error;
|
|
30858
30924
|
};
|
|
30859
30925
|
|
|
30860
|
-
|
|
30861
|
-
return validators
|
|
30862
|
-
|
|
30863
|
-
|
|
30926
|
+
var _computeErrors = function _computeErrors(fieldName, form, validators) {
|
|
30927
|
+
return validators.map(function (v) {
|
|
30928
|
+
return runValidator(v, form[fieldName].rawValue, form);
|
|
30929
|
+
}).filter(function (x) {
|
|
30930
|
+
return x !== null;
|
|
30931
|
+
});
|
|
30864
30932
|
};
|
|
30865
30933
|
|
|
30866
|
-
|
|
30867
|
-
|
|
30934
|
+
var computeConstraints = function computeConstraints(fieldName, form) {
|
|
30935
|
+
var constraints = form[fieldName].constraints;
|
|
30868
30936
|
return _computeErrors(fieldName, form, constraints);
|
|
30869
30937
|
};
|
|
30870
30938
|
|
|
30871
|
-
|
|
30872
|
-
|
|
30939
|
+
var computeErrors = function computeErrors(fieldName, form) {
|
|
30940
|
+
var validators = form[fieldName].validators;
|
|
30873
30941
|
return _computeErrors(fieldName, form, validators);
|
|
30874
30942
|
};
|
|
30875
30943
|
|
|
30876
30944
|
var obj;
|
|
30877
|
-
var NOTHING = typeof Symbol !== "undefined" ? Symbol("immer-nothing") : (
|
|
30878
|
-
var DRAFTABLE = typeof Symbol !== "undefined" && Symbol
|
|
30879
|
-
var DRAFT_STATE = typeof Symbol !== "undefined" && Symbol
|
|
30945
|
+
var NOTHING = typeof Symbol !== "undefined" ? Symbol("immer-nothing") : (obj = {}, obj["immer-nothing"] = true, obj);
|
|
30946
|
+
var DRAFTABLE = typeof Symbol !== "undefined" && Symbol["for"] ? Symbol["for"]("immer-draftable") : "__$immer_draftable";
|
|
30947
|
+
var DRAFT_STATE = typeof Symbol !== "undefined" && Symbol["for"] ? Symbol["for"]("immer-state") : "__$immer_state";
|
|
30948
|
+
|
|
30880
30949
|
function isDraft(value) {
|
|
30881
30950
|
return !!value && !!value[DRAFT_STATE];
|
|
30882
30951
|
}
|
|
30952
|
+
|
|
30883
30953
|
function isDraftable(value) {
|
|
30884
|
-
if (!value) {
|
|
30954
|
+
if (!value) {
|
|
30955
|
+
return false;
|
|
30956
|
+
}
|
|
30957
|
+
|
|
30885
30958
|
return isPlainObject(value) || !!value[DRAFTABLE] || !!value.constructor[DRAFTABLE];
|
|
30886
30959
|
}
|
|
30960
|
+
|
|
30887
30961
|
function isPlainObject(value) {
|
|
30888
|
-
if (!value ||
|
|
30889
|
-
|
|
30962
|
+
if (!value || _typeof(value) !== "object") {
|
|
30963
|
+
return false;
|
|
30964
|
+
}
|
|
30965
|
+
|
|
30966
|
+
if (Array.isArray(value)) {
|
|
30967
|
+
return true;
|
|
30968
|
+
}
|
|
30969
|
+
|
|
30890
30970
|
var proto = Object.getPrototypeOf(value);
|
|
30891
30971
|
return !proto || proto === Object.prototype;
|
|
30892
30972
|
}
|
|
30973
|
+
|
|
30893
30974
|
var assign = Object.assign || function assign(target, value) {
|
|
30894
30975
|
for (var key in value) {
|
|
30895
30976
|
if (has(value, key)) {
|
|
@@ -30899,11 +30980,18 @@ var assign = Object.assign || function assign(target, value) {
|
|
|
30899
30980
|
|
|
30900
30981
|
return target;
|
|
30901
30982
|
};
|
|
30902
|
-
|
|
30983
|
+
|
|
30984
|
+
var ownKeys$1 = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) {
|
|
30985
|
+
return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj));
|
|
30986
|
+
} : Object.getOwnPropertyNames;
|
|
30987
|
+
|
|
30903
30988
|
function shallowCopy(base, invokeGetters) {
|
|
30904
|
-
if (
|
|
30989
|
+
if (invokeGetters === void 0) invokeGetters = false;
|
|
30990
|
+
|
|
30991
|
+
if (Array.isArray(base)) {
|
|
30992
|
+
return base.slice();
|
|
30993
|
+
}
|
|
30905
30994
|
|
|
30906
|
-
if (Array.isArray(base)) { return base.slice(); }
|
|
30907
30995
|
var clone = Object.create(Object.getPrototypeOf(base));
|
|
30908
30996
|
ownKeys$1(base).forEach(function (key) {
|
|
30909
30997
|
if (key === DRAFT_STATE) {
|
|
@@ -30933,20 +31021,28 @@ function shallowCopy(base, invokeGetters) {
|
|
|
30933
31021
|
});
|
|
30934
31022
|
return clone;
|
|
30935
31023
|
}
|
|
31024
|
+
|
|
30936
31025
|
function each(value, cb) {
|
|
30937
31026
|
if (Array.isArray(value)) {
|
|
30938
|
-
for (var i = 0; i < value.length; i++) {
|
|
31027
|
+
for (var i = 0; i < value.length; i++) {
|
|
31028
|
+
cb(i, value[i], value);
|
|
31029
|
+
}
|
|
30939
31030
|
} else {
|
|
30940
|
-
ownKeys$1(value).forEach(function (key) {
|
|
31031
|
+
ownKeys$1(value).forEach(function (key) {
|
|
31032
|
+
return cb(key, value[key], value);
|
|
31033
|
+
});
|
|
30941
31034
|
}
|
|
30942
31035
|
}
|
|
31036
|
+
|
|
30943
31037
|
function isEnumerable(base, prop) {
|
|
30944
31038
|
var desc = Object.getOwnPropertyDescriptor(base, prop);
|
|
30945
31039
|
return !!desc && desc.enumerable;
|
|
30946
31040
|
}
|
|
31041
|
+
|
|
30947
31042
|
function has(thing, prop) {
|
|
30948
31043
|
return Object.prototype.hasOwnProperty.call(thing, prop);
|
|
30949
31044
|
}
|
|
31045
|
+
|
|
30950
31046
|
function is(x, y) {
|
|
30951
31047
|
// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
|
|
30952
31048
|
if (x === y) {
|
|
@@ -30955,18 +31051,27 @@ function is(x, y) {
|
|
|
30955
31051
|
return x !== x && y !== y;
|
|
30956
31052
|
}
|
|
30957
31053
|
}
|
|
31054
|
+
|
|
30958
31055
|
function clone(obj) {
|
|
30959
|
-
if (!isDraftable(obj)) {
|
|
30960
|
-
|
|
31056
|
+
if (!isDraftable(obj)) {
|
|
31057
|
+
return obj;
|
|
31058
|
+
}
|
|
31059
|
+
|
|
31060
|
+
if (Array.isArray(obj)) {
|
|
31061
|
+
return obj.map(clone);
|
|
31062
|
+
}
|
|
31063
|
+
|
|
30961
31064
|
var cloned = Object.create(Object.getPrototypeOf(obj));
|
|
30962
31065
|
|
|
30963
|
-
for (var key in obj) {
|
|
31066
|
+
for (var key in obj) {
|
|
31067
|
+
cloned[key] = clone(obj[key]);
|
|
31068
|
+
}
|
|
30964
31069
|
|
|
30965
31070
|
return cloned;
|
|
30966
31071
|
}
|
|
30967
|
-
|
|
30968
31072
|
/** Each scope represents a `produce` call. */
|
|
30969
31073
|
|
|
31074
|
+
|
|
30970
31075
|
var ImmerScope = function ImmerScope(parent) {
|
|
30971
31076
|
this.drafts = [];
|
|
30972
31077
|
this.parent = parent; // Whenever the modified draft contains a draft from another scope, we
|
|
@@ -30977,7 +31082,7 @@ var ImmerScope = function ImmerScope(parent) {
|
|
|
30977
31082
|
this.patches = null;
|
|
30978
31083
|
};
|
|
30979
31084
|
|
|
30980
|
-
ImmerScope.prototype.usePatches = function usePatches
|
|
31085
|
+
ImmerScope.prototype.usePatches = function usePatches(patchListener) {
|
|
30981
31086
|
if (patchListener) {
|
|
30982
31087
|
this.patches = [];
|
|
30983
31088
|
this.inversePatches = [];
|
|
@@ -30985,17 +31090,18 @@ ImmerScope.prototype.usePatches = function usePatches (patchListener) {
|
|
|
30985
31090
|
}
|
|
30986
31091
|
};
|
|
30987
31092
|
|
|
30988
|
-
ImmerScope.prototype.revoke = function revoke$1
|
|
31093
|
+
ImmerScope.prototype.revoke = function revoke$1() {
|
|
30989
31094
|
this.leave();
|
|
30990
31095
|
this.drafts.forEach(revoke);
|
|
30991
31096
|
this.drafts = null; // Make draft-related methods throw.
|
|
30992
31097
|
};
|
|
30993
31098
|
|
|
30994
|
-
ImmerScope.prototype.leave = function leave
|
|
31099
|
+
ImmerScope.prototype.leave = function leave() {
|
|
30995
31100
|
if (this === ImmerScope.current) {
|
|
30996
31101
|
ImmerScope.current = this.parent;
|
|
30997
31102
|
}
|
|
30998
31103
|
};
|
|
31104
|
+
|
|
30999
31105
|
ImmerScope.current = null;
|
|
31000
31106
|
|
|
31001
31107
|
ImmerScope.enter = function () {
|
|
@@ -31004,11 +31110,11 @@ ImmerScope.enter = function () {
|
|
|
31004
31110
|
|
|
31005
31111
|
function revoke(draft) {
|
|
31006
31112
|
draft[DRAFT_STATE].revoke();
|
|
31007
|
-
}
|
|
31113
|
+
} // but share them all instead
|
|
31008
31114
|
|
|
31009
|
-
// but share them all instead
|
|
31010
31115
|
|
|
31011
31116
|
var descriptors = {};
|
|
31117
|
+
|
|
31012
31118
|
function willFinalize(scope, result, isReplaced) {
|
|
31013
31119
|
scope.drafts.forEach(function (draft) {
|
|
31014
31120
|
draft[DRAFT_STATE].finalizing = true;
|
|
@@ -31026,6 +31132,7 @@ function willFinalize(scope, result, isReplaced) {
|
|
|
31026
31132
|
markChangesSweep(scope.drafts);
|
|
31027
31133
|
}
|
|
31028
31134
|
}
|
|
31135
|
+
|
|
31029
31136
|
function createProxy(base, parent) {
|
|
31030
31137
|
var isArray = Array.isArray(base);
|
|
31031
31138
|
var draft = clonePotentialDraft(base);
|
|
@@ -31079,7 +31186,11 @@ function peek(draft, prop) {
|
|
|
31079
31186
|
function get(state, prop) {
|
|
31080
31187
|
assertUnrevoked(state);
|
|
31081
31188
|
var value = peek(source(state), prop);
|
|
31082
|
-
|
|
31189
|
+
|
|
31190
|
+
if (state.finalizing) {
|
|
31191
|
+
return value;
|
|
31192
|
+
} // Create a draft if the value is unmodified.
|
|
31193
|
+
|
|
31083
31194
|
|
|
31084
31195
|
if (value === peek(state.base, prop) && isDraftable(value)) {
|
|
31085
31196
|
prepareCopy(state);
|
|
@@ -31094,7 +31205,10 @@ function set(state, prop, value) {
|
|
|
31094
31205
|
state.assigned[prop] = true;
|
|
31095
31206
|
|
|
31096
31207
|
if (!state.modified) {
|
|
31097
|
-
if (is(value, peek(source(state), prop))) {
|
|
31208
|
+
if (is(value, peek(source(state), prop))) {
|
|
31209
|
+
return;
|
|
31210
|
+
}
|
|
31211
|
+
|
|
31098
31212
|
markChanged(state);
|
|
31099
31213
|
prepareCopy(state);
|
|
31100
31214
|
}
|
|
@@ -31105,12 +31219,17 @@ function set(state, prop, value) {
|
|
|
31105
31219
|
function markChanged(state) {
|
|
31106
31220
|
if (!state.modified) {
|
|
31107
31221
|
state.modified = true;
|
|
31108
|
-
|
|
31222
|
+
|
|
31223
|
+
if (state.parent) {
|
|
31224
|
+
markChanged(state.parent);
|
|
31225
|
+
}
|
|
31109
31226
|
}
|
|
31110
31227
|
}
|
|
31111
31228
|
|
|
31112
31229
|
function prepareCopy(state) {
|
|
31113
|
-
if (!state.copy) {
|
|
31230
|
+
if (!state.copy) {
|
|
31231
|
+
state.copy = clonePotentialDraft(state.base);
|
|
31232
|
+
}
|
|
31114
31233
|
}
|
|
31115
31234
|
|
|
31116
31235
|
function clonePotentialDraft(base) {
|
|
@@ -31135,15 +31254,12 @@ function proxyProperty(draft, prop, enumerable) {
|
|
|
31135
31254
|
descriptors[prop] = desc = {
|
|
31136
31255
|
configurable: true,
|
|
31137
31256
|
enumerable: enumerable,
|
|
31138
|
-
|
|
31139
31257
|
get: function get$1() {
|
|
31140
31258
|
return get(this[DRAFT_STATE], prop);
|
|
31141
31259
|
},
|
|
31142
|
-
|
|
31143
31260
|
set: function set$1(value) {
|
|
31144
31261
|
set(this[DRAFT_STATE], prop, value);
|
|
31145
31262
|
}
|
|
31146
|
-
|
|
31147
31263
|
};
|
|
31148
31264
|
}
|
|
31149
31265
|
|
|
@@ -31151,7 +31267,9 @@ function proxyProperty(draft, prop, enumerable) {
|
|
|
31151
31267
|
}
|
|
31152
31268
|
|
|
31153
31269
|
function assertUnrevoked(state) {
|
|
31154
|
-
if (state.revoked === true) {
|
|
31270
|
+
if (state.revoked === true) {
|
|
31271
|
+
throw new Error("Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + JSON.stringify(source(state)));
|
|
31272
|
+
}
|
|
31155
31273
|
} // This looks expensive, but only proxies are visited, and only objects without known changes are scanned.
|
|
31156
31274
|
|
|
31157
31275
|
|
|
@@ -31165,16 +31283,27 @@ function markChangesSweep(drafts) {
|
|
|
31165
31283
|
|
|
31166
31284
|
if (!state.modified) {
|
|
31167
31285
|
if (Array.isArray(state.base)) {
|
|
31168
|
-
if (hasArrayChanges(state)) {
|
|
31169
|
-
|
|
31286
|
+
if (hasArrayChanges(state)) {
|
|
31287
|
+
markChanged(state);
|
|
31288
|
+
}
|
|
31289
|
+
} else if (hasObjectChanges(state)) {
|
|
31290
|
+
markChanged(state);
|
|
31291
|
+
}
|
|
31170
31292
|
}
|
|
31171
31293
|
}
|
|
31172
31294
|
}
|
|
31173
31295
|
|
|
31174
31296
|
function markChangesRecursively(object) {
|
|
31175
|
-
if (!object ||
|
|
31297
|
+
if (!object || _typeof(object) !== "object") {
|
|
31298
|
+
return;
|
|
31299
|
+
}
|
|
31300
|
+
|
|
31176
31301
|
var state = object[DRAFT_STATE];
|
|
31177
|
-
|
|
31302
|
+
|
|
31303
|
+
if (!state) {
|
|
31304
|
+
return;
|
|
31305
|
+
}
|
|
31306
|
+
|
|
31178
31307
|
var base = state.base;
|
|
31179
31308
|
var draft = state.draft;
|
|
31180
31309
|
var assigned = state.assigned;
|
|
@@ -31204,14 +31333,20 @@ function markChangesRecursively(object) {
|
|
|
31204
31333
|
assigned.length = true;
|
|
31205
31334
|
|
|
31206
31335
|
if (draft.length < base.length) {
|
|
31207
|
-
for (var i = draft.length; i < base.length; i++) {
|
|
31336
|
+
for (var i = draft.length; i < base.length; i++) {
|
|
31337
|
+
assigned[i] = false;
|
|
31338
|
+
}
|
|
31208
31339
|
} else {
|
|
31209
|
-
for (var i$1 = base.length; i$1 < draft.length; i$1++) {
|
|
31340
|
+
for (var i$1 = base.length; i$1 < draft.length; i$1++) {
|
|
31341
|
+
assigned[i$1] = true;
|
|
31342
|
+
}
|
|
31210
31343
|
}
|
|
31211
31344
|
|
|
31212
31345
|
for (var i$2 = 0; i$2 < draft.length; i$2++) {
|
|
31213
31346
|
// Only untouched indices trigger recursion.
|
|
31214
|
-
if (assigned[i$2] === undefined) {
|
|
31347
|
+
if (assigned[i$2] === undefined) {
|
|
31348
|
+
markChangesRecursively(draft[i$2]);
|
|
31349
|
+
}
|
|
31215
31350
|
}
|
|
31216
31351
|
}
|
|
31217
31352
|
}
|
|
@@ -31248,7 +31383,10 @@ function hasObjectChanges(state) {
|
|
|
31248
31383
|
|
|
31249
31384
|
function hasArrayChanges(state) {
|
|
31250
31385
|
var draft = state.draft;
|
|
31251
|
-
|
|
31386
|
+
|
|
31387
|
+
if (draft.length !== state.base.length) {
|
|
31388
|
+
return true;
|
|
31389
|
+
} // See #116
|
|
31252
31390
|
// If we first shorten the length, our array interceptors will be removed.
|
|
31253
31391
|
// If after that new items are added, result in the same original length,
|
|
31254
31392
|
// those last items will have no intercepting property.
|
|
@@ -31256,9 +31394,13 @@ function hasArrayChanges(state) {
|
|
|
31256
31394
|
// N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check
|
|
31257
31395
|
// the last one
|
|
31258
31396
|
|
|
31397
|
+
|
|
31259
31398
|
var descriptor = Object.getOwnPropertyDescriptor(draft, draft.length - 1); // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)
|
|
31260
31399
|
|
|
31261
|
-
if (descriptor && !descriptor.get) {
|
|
31400
|
+
if (descriptor && !descriptor.get) {
|
|
31401
|
+
return true;
|
|
31402
|
+
} // For all other cases, we don't have to compare, as they would have been picked up by the index setters
|
|
31403
|
+
|
|
31262
31404
|
|
|
31263
31405
|
return false;
|
|
31264
31406
|
}
|
|
@@ -31272,11 +31414,12 @@ function createHiddenProperty(target, prop, value) {
|
|
|
31272
31414
|
}
|
|
31273
31415
|
|
|
31274
31416
|
var legacyProxy = /*#__PURE__*/Object.freeze({
|
|
31275
|
-
|
|
31276
|
-
|
|
31417
|
+
willFinalize: willFinalize,
|
|
31418
|
+
createProxy: createProxy
|
|
31277
31419
|
});
|
|
31278
31420
|
|
|
31279
31421
|
function willFinalize$1() {}
|
|
31422
|
+
|
|
31280
31423
|
function createProxy$1(base, parent) {
|
|
31281
31424
|
var scope = parent ? parent.scope : ImmerScope.current;
|
|
31282
31425
|
var state = {
|
|
@@ -31311,33 +31454,27 @@ function createProxy$1(base, parent) {
|
|
|
31311
31454
|
scope.drafts.push(proxy);
|
|
31312
31455
|
return proxy;
|
|
31313
31456
|
}
|
|
31457
|
+
|
|
31314
31458
|
var objectTraps = {
|
|
31315
31459
|
get: get$1,
|
|
31316
|
-
|
|
31317
31460
|
has: function has(target, prop) {
|
|
31318
31461
|
return prop in source$1(target);
|
|
31319
31462
|
},
|
|
31320
|
-
|
|
31321
31463
|
ownKeys: function ownKeys(target) {
|
|
31322
31464
|
return Reflect.ownKeys(source$1(target));
|
|
31323
31465
|
},
|
|
31324
|
-
|
|
31325
31466
|
set: set$1,
|
|
31326
31467
|
deleteProperty: deleteProperty,
|
|
31327
31468
|
getOwnPropertyDescriptor: getOwnPropertyDescriptor,
|
|
31328
|
-
|
|
31329
31469
|
defineProperty: function defineProperty() {
|
|
31330
31470
|
throw new Error("Object.defineProperty() cannot be used on an Immer draft"); // prettier-ignore
|
|
31331
31471
|
},
|
|
31332
|
-
|
|
31333
31472
|
getPrototypeOf: function getPrototypeOf(target) {
|
|
31334
31473
|
return Object.getPrototypeOf(target.base);
|
|
31335
31474
|
},
|
|
31336
|
-
|
|
31337
31475
|
setPrototypeOf: function setPrototypeOf() {
|
|
31338
31476
|
throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft"); // prettier-ignore
|
|
31339
31477
|
}
|
|
31340
|
-
|
|
31341
31478
|
};
|
|
31342
31479
|
var arrayTraps = {};
|
|
31343
31480
|
each(objectTraps, function (key, fn) {
|
|
@@ -31376,7 +31513,10 @@ function peek$1(draft, prop) {
|
|
|
31376
31513
|
}
|
|
31377
31514
|
|
|
31378
31515
|
function get$1(state, prop) {
|
|
31379
|
-
if (prop === DRAFT_STATE) {
|
|
31516
|
+
if (prop === DRAFT_STATE) {
|
|
31517
|
+
return state;
|
|
31518
|
+
}
|
|
31519
|
+
|
|
31380
31520
|
var drafts = state.drafts; // Check for existing draft in unmodified state.
|
|
31381
31521
|
|
|
31382
31522
|
if (!state.modified && has(drafts, prop)) {
|
|
@@ -31392,7 +31532,10 @@ function get$1(state, prop) {
|
|
|
31392
31532
|
|
|
31393
31533
|
if (state.modified) {
|
|
31394
31534
|
// Assigned values are never drafted. This catches any drafts we created, too.
|
|
31395
|
-
if (value !== peek$1(state.base, prop)) {
|
|
31535
|
+
if (value !== peek$1(state.base, prop)) {
|
|
31536
|
+
return value;
|
|
31537
|
+
} // Store drafts on the copy (when one exists).
|
|
31538
|
+
|
|
31396
31539
|
|
|
31397
31540
|
drafts = state.copy;
|
|
31398
31541
|
}
|
|
@@ -31407,7 +31550,11 @@ function set$1(state, prop, value) {
|
|
|
31407
31550
|
// values may be drafts, but falsy values are never drafts.
|
|
31408
31551
|
|
|
31409
31552
|
var isUnchanged = value ? is(baseValue, value) || value === state.drafts[prop] : is(baseValue, value) && prop in state.base;
|
|
31410
|
-
|
|
31553
|
+
|
|
31554
|
+
if (isUnchanged) {
|
|
31555
|
+
return true;
|
|
31556
|
+
}
|
|
31557
|
+
|
|
31411
31558
|
markChanged$1(state);
|
|
31412
31559
|
}
|
|
31413
31560
|
|
|
@@ -31426,7 +31573,10 @@ function deleteProperty(state, prop) {
|
|
|
31426
31573
|
delete state.assigned[prop];
|
|
31427
31574
|
}
|
|
31428
31575
|
|
|
31429
|
-
if (state.copy) {
|
|
31576
|
+
if (state.copy) {
|
|
31577
|
+
delete state.copy[prop];
|
|
31578
|
+
}
|
|
31579
|
+
|
|
31430
31580
|
return true;
|
|
31431
31581
|
} // Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
31432
31582
|
// the same guarantee in ES5 mode.
|
|
@@ -31449,13 +31599,16 @@ function markChanged$1(state) {
|
|
|
31449
31599
|
state.modified = true;
|
|
31450
31600
|
state.copy = assign(shallowCopy(state.base), state.drafts);
|
|
31451
31601
|
state.drafts = null;
|
|
31452
|
-
|
|
31602
|
+
|
|
31603
|
+
if (state.parent) {
|
|
31604
|
+
markChanged$1(state.parent);
|
|
31605
|
+
}
|
|
31453
31606
|
}
|
|
31454
31607
|
}
|
|
31455
31608
|
|
|
31456
31609
|
var modernProxy = /*#__PURE__*/Object.freeze({
|
|
31457
|
-
|
|
31458
|
-
|
|
31610
|
+
willFinalize: willFinalize$1,
|
|
31611
|
+
createProxy: createProxy$1
|
|
31459
31612
|
});
|
|
31460
31613
|
|
|
31461
31614
|
function generatePatches(state, basePath, patches, inversePatches) {
|
|
@@ -31464,14 +31617,13 @@ function generatePatches(state, basePath, patches, inversePatches) {
|
|
|
31464
31617
|
|
|
31465
31618
|
function generateArrayPatches(state, basePath, patches, inversePatches) {
|
|
31466
31619
|
var assign, assign$1;
|
|
31467
|
-
|
|
31468
31620
|
var base = state.base;
|
|
31469
31621
|
var copy = state.copy;
|
|
31470
31622
|
var assigned = state.assigned; // Reduce complexity by ensuring `base` is never longer.
|
|
31471
31623
|
|
|
31472
31624
|
if (copy.length < base.length) {
|
|
31473
|
-
|
|
31474
|
-
|
|
31625
|
+
assign = [copy, base], base = assign[0], copy = assign[1];
|
|
31626
|
+
assign$1 = [inversePatches, patches], patches = assign$1[0], inversePatches = assign$1[1];
|
|
31475
31627
|
}
|
|
31476
31628
|
|
|
31477
31629
|
var delta = copy.length - base.length; // Find the first replaced index.
|
|
@@ -31529,7 +31681,11 @@ function generateObjectPatches(state, basePath, patches, inversePatches) {
|
|
|
31529
31681
|
var origValue = base[key];
|
|
31530
31682
|
var value = copy[key];
|
|
31531
31683
|
var op = !assignedValue ? "remove" : key in base ? "replace" : "add";
|
|
31532
|
-
|
|
31684
|
+
|
|
31685
|
+
if (origValue === value && op === "replace") {
|
|
31686
|
+
return;
|
|
31687
|
+
}
|
|
31688
|
+
|
|
31533
31689
|
var path = basePath.concat(key);
|
|
31534
31690
|
patches.push(op === "remove" ? {
|
|
31535
31691
|
op: op,
|
|
@@ -31554,20 +31710,26 @@ function generateObjectPatches(state, basePath, patches, inversePatches) {
|
|
|
31554
31710
|
});
|
|
31555
31711
|
}
|
|
31556
31712
|
|
|
31557
|
-
var applyPatches = function (draft, patches) {
|
|
31713
|
+
var applyPatches = function applyPatches(draft, patches) {
|
|
31558
31714
|
for (var i$1 = 0, list = patches; i$1 < list.length; i$1 += 1) {
|
|
31559
31715
|
var patch = list[i$1];
|
|
31560
|
-
|
|
31561
31716
|
var path = patch.path;
|
|
31562
31717
|
var op = patch.op;
|
|
31563
31718
|
var value = clone(patch.value); // used to clone patch to ensure original patch is not modified, see #411
|
|
31564
31719
|
|
|
31565
|
-
if (!path.length) {
|
|
31720
|
+
if (!path.length) {
|
|
31721
|
+
throw new Error("Illegal state");
|
|
31722
|
+
}
|
|
31723
|
+
|
|
31566
31724
|
var base = draft;
|
|
31567
31725
|
|
|
31568
31726
|
for (var i = 0; i < path.length - 1; i++) {
|
|
31569
31727
|
base = base[path[i]];
|
|
31570
|
-
|
|
31728
|
+
|
|
31729
|
+
if (!base || _typeof(base) !== "object") {
|
|
31730
|
+
throw new Error("Cannot apply patch, path doesn't resolve: " + path.join("/"));
|
|
31731
|
+
} // prettier-ignore
|
|
31732
|
+
|
|
31571
31733
|
}
|
|
31572
31734
|
|
|
31573
31735
|
var key = path[path.length - 1];
|
|
@@ -31616,27 +31778,33 @@ var configDefaults = {
|
|
|
31616
31778
|
onDelete: null,
|
|
31617
31779
|
onCopy: null
|
|
31618
31780
|
};
|
|
31781
|
+
|
|
31619
31782
|
var Immer = function Immer(config) {
|
|
31620
31783
|
assign(this, configDefaults, config);
|
|
31621
31784
|
this.setUseProxies(this.useProxies);
|
|
31622
31785
|
this.produce = this.produce.bind(this);
|
|
31623
31786
|
};
|
|
31624
31787
|
|
|
31625
|
-
Immer.prototype.produce = function produce
|
|
31626
|
-
|
|
31788
|
+
Immer.prototype.produce = function produce(base, recipe, patchListener) {
|
|
31789
|
+
var this$1 = this; // curried invocation
|
|
31627
31790
|
|
|
31628
|
-
// curried invocation
|
|
31629
31791
|
if (typeof base === "function" && typeof recipe !== "function") {
|
|
31630
31792
|
var defaultBase = recipe;
|
|
31631
31793
|
recipe = base;
|
|
31632
31794
|
var self = this;
|
|
31633
31795
|
return function curriedProduce(base) {
|
|
31634
|
-
|
|
31635
|
-
|
|
31636
|
-
|
|
31637
|
-
|
|
31796
|
+
var this$1 = this;
|
|
31797
|
+
if (base === void 0) base = defaultBase;
|
|
31798
|
+
var args = [],
|
|
31799
|
+
len = arguments.length - 1;
|
|
31800
|
+
|
|
31801
|
+
while (len-- > 0) {
|
|
31802
|
+
args[len] = arguments[len + 1];
|
|
31803
|
+
}
|
|
31638
31804
|
|
|
31639
|
-
return self.produce(base, function (draft) {
|
|
31805
|
+
return self.produce(base, function (draft) {
|
|
31806
|
+
return recipe.call.apply(recipe, [this$1, draft].concat(args));
|
|
31807
|
+
}); // prettier-ignore
|
|
31640
31808
|
};
|
|
31641
31809
|
} // prettier-ignore
|
|
31642
31810
|
|
|
@@ -31662,7 +31830,11 @@ Immer.prototype.produce = function produce (base, recipe, patchListener) {
|
|
|
31662
31830
|
hasError = false;
|
|
31663
31831
|
} finally {
|
|
31664
31832
|
// finally instead of catch + rethrow better preserves original stack
|
|
31665
|
-
if (hasError) {
|
|
31833
|
+
if (hasError) {
|
|
31834
|
+
scope.revoke();
|
|
31835
|
+
} else {
|
|
31836
|
+
scope.leave();
|
|
31837
|
+
}
|
|
31666
31838
|
}
|
|
31667
31839
|
|
|
31668
31840
|
if (result instanceof Promise) {
|
|
@@ -31679,25 +31851,38 @@ Immer.prototype.produce = function produce (base, recipe, patchListener) {
|
|
|
31679
31851
|
return this.processResult(result, scope);
|
|
31680
31852
|
} else {
|
|
31681
31853
|
result = recipe(base);
|
|
31682
|
-
|
|
31854
|
+
|
|
31855
|
+
if (result === undefined) {
|
|
31856
|
+
return base;
|
|
31857
|
+
}
|
|
31858
|
+
|
|
31683
31859
|
return result !== NOTHING ? result : undefined;
|
|
31684
31860
|
}
|
|
31685
31861
|
};
|
|
31686
31862
|
|
|
31687
|
-
Immer.prototype.produceWithPatches = function produceWithPatches
|
|
31688
|
-
|
|
31863
|
+
Immer.prototype.produceWithPatches = function produceWithPatches(arg1, arg2, arg3) {
|
|
31864
|
+
var this$1 = this;
|
|
31689
31865
|
|
|
31690
31866
|
if (typeof arg1 === "function") {
|
|
31691
31867
|
return function (state) {
|
|
31692
|
-
|
|
31693
|
-
|
|
31868
|
+
var args = [],
|
|
31869
|
+
len = arguments.length - 1;
|
|
31694
31870
|
|
|
31695
|
-
|
|
31696
|
-
|
|
31871
|
+
while (len-- > 0) {
|
|
31872
|
+
args[len] = arguments[len + 1];
|
|
31873
|
+
}
|
|
31874
|
+
|
|
31875
|
+
return this$1.produceWithPatches(state, function (draft) {
|
|
31876
|
+
return arg1.apply(void 0, [draft].concat(args));
|
|
31877
|
+
});
|
|
31878
|
+
};
|
|
31697
31879
|
} // non-curried form
|
|
31698
31880
|
|
|
31699
31881
|
|
|
31700
|
-
if (arg3) {
|
|
31882
|
+
if (arg3) {
|
|
31883
|
+
throw new Error("A patch listener cannot be passed to produceWithPatches");
|
|
31884
|
+
}
|
|
31885
|
+
|
|
31701
31886
|
var patches, inversePatches;
|
|
31702
31887
|
var nextState = this.produce(arg1, arg2, function (p, ip) {
|
|
31703
31888
|
patches = p;
|
|
@@ -31706,7 +31891,7 @@ Immer.prototype.produceWithPatches = function produceWithPatches (arg1, arg2, ar
|
|
|
31706
31891
|
return [nextState, patches, inversePatches];
|
|
31707
31892
|
};
|
|
31708
31893
|
|
|
31709
|
-
Immer.prototype.createDraft = function createDraft
|
|
31894
|
+
Immer.prototype.createDraft = function createDraft(base) {
|
|
31710
31895
|
if (!isDraftable(base)) {
|
|
31711
31896
|
throw new Error("First argument to `createDraft` must be a plain object, an array, or an immerable object"); // prettier-ignore
|
|
31712
31897
|
}
|
|
@@ -31718,7 +31903,7 @@ Immer.prototype.createDraft = function createDraft (base) {
|
|
|
31718
31903
|
return proxy;
|
|
31719
31904
|
};
|
|
31720
31905
|
|
|
31721
|
-
Immer.prototype.finishDraft = function finishDraft
|
|
31906
|
+
Immer.prototype.finishDraft = function finishDraft(draft, patchListener) {
|
|
31722
31907
|
var state = draft && draft[DRAFT_STATE];
|
|
31723
31908
|
|
|
31724
31909
|
if (!state || !state.isManual) {
|
|
@@ -31734,16 +31919,16 @@ Immer.prototype.finishDraft = function finishDraft (draft, patchListener) {
|
|
|
31734
31919
|
return this.processResult(undefined, scope);
|
|
31735
31920
|
};
|
|
31736
31921
|
|
|
31737
|
-
Immer.prototype.setAutoFreeze = function setAutoFreeze
|
|
31922
|
+
Immer.prototype.setAutoFreeze = function setAutoFreeze(value) {
|
|
31738
31923
|
this.autoFreeze = value;
|
|
31739
31924
|
};
|
|
31740
31925
|
|
|
31741
|
-
Immer.prototype.setUseProxies = function setUseProxies
|
|
31926
|
+
Immer.prototype.setUseProxies = function setUseProxies(value) {
|
|
31742
31927
|
this.useProxies = value;
|
|
31743
31928
|
assign(this, value ? modernProxy : legacyProxy);
|
|
31744
31929
|
};
|
|
31745
31930
|
|
|
31746
|
-
Immer.prototype.applyPatches = function applyPatches$1
|
|
31931
|
+
Immer.prototype.applyPatches = function applyPatches$1(base, patches) {
|
|
31747
31932
|
// If a patch replaces the entire state, take that replacement as base
|
|
31748
31933
|
// before applying patches
|
|
31749
31934
|
var i;
|
|
@@ -31763,12 +31948,14 @@ Immer.prototype.applyPatches = function applyPatches$1 (base, patches) {
|
|
|
31763
31948
|
} // Otherwise, produce a copy of the base state.
|
|
31764
31949
|
|
|
31765
31950
|
|
|
31766
|
-
return this.produce(base, function (draft) {
|
|
31951
|
+
return this.produce(base, function (draft) {
|
|
31952
|
+
return applyPatches(draft, patches.slice(i + 1));
|
|
31953
|
+
});
|
|
31767
31954
|
};
|
|
31768
31955
|
/** @internal */
|
|
31769
31956
|
|
|
31770
31957
|
|
|
31771
|
-
Immer.prototype.processResult = function processResult
|
|
31958
|
+
Immer.prototype.processResult = function processResult(result, scope) {
|
|
31772
31959
|
var baseDraft = scope.drafts[0];
|
|
31773
31960
|
var isReplaced = result !== undefined && result !== baseDraft;
|
|
31774
31961
|
this.willFinalize(scope, result, isReplaced);
|
|
@@ -31816,13 +32003,15 @@ Immer.prototype.processResult = function processResult (result, scope) {
|
|
|
31816
32003
|
*/
|
|
31817
32004
|
|
|
31818
32005
|
|
|
31819
|
-
Immer.prototype.finalize = function finalize
|
|
31820
|
-
|
|
31821
|
-
|
|
32006
|
+
Immer.prototype.finalize = function finalize(draft, path, scope) {
|
|
32007
|
+
var this$1 = this;
|
|
31822
32008
|
var state = draft[DRAFT_STATE];
|
|
31823
32009
|
|
|
31824
32010
|
if (!state) {
|
|
31825
|
-
if (Object.isFrozen(draft)) {
|
|
32011
|
+
if (Object.isFrozen(draft)) {
|
|
32012
|
+
return draft;
|
|
32013
|
+
}
|
|
32014
|
+
|
|
31826
32015
|
return this.finalizeTree(draft, null, scope);
|
|
31827
32016
|
} // Never finalize drafts owned by another scope.
|
|
31828
32017
|
|
|
@@ -31845,13 +32034,17 @@ Immer.prototype.finalize = function finalize (draft, path, scope) {
|
|
|
31845
32034
|
var assigned = state.assigned;
|
|
31846
32035
|
|
|
31847
32036
|
for (var prop in assigned) {
|
|
31848
|
-
if (!assigned[prop]) {
|
|
32037
|
+
if (!assigned[prop]) {
|
|
32038
|
+
this.onDelete(state, prop);
|
|
32039
|
+
}
|
|
31849
32040
|
}
|
|
31850
32041
|
} else {
|
|
31851
32042
|
var base = state.base;
|
|
31852
|
-
|
|
32043
|
+
var copy = state.copy;
|
|
31853
32044
|
each(base, function (prop) {
|
|
31854
|
-
if (!has(copy, prop)) {
|
|
32045
|
+
if (!has(copy, prop)) {
|
|
32046
|
+
this$1.onDelete(state, prop);
|
|
32047
|
+
}
|
|
31855
32048
|
});
|
|
31856
32049
|
}
|
|
31857
32050
|
}
|
|
@@ -31879,9 +32072,8 @@ Immer.prototype.finalize = function finalize (draft, path, scope) {
|
|
|
31879
32072
|
*/
|
|
31880
32073
|
|
|
31881
32074
|
|
|
31882
|
-
Immer.prototype.finalizeTree = function finalizeTree
|
|
31883
|
-
|
|
31884
|
-
|
|
32075
|
+
Immer.prototype.finalizeTree = function finalizeTree(root, rootPath, scope) {
|
|
32076
|
+
var this$1 = this;
|
|
31885
32077
|
var state = root[DRAFT_STATE];
|
|
31886
32078
|
|
|
31887
32079
|
if (state) {
|
|
@@ -31895,7 +32087,7 @@ Immer.prototype.finalizeTree = function finalizeTree (root, rootPath, scope) {
|
|
|
31895
32087
|
|
|
31896
32088
|
var needPatches = !!rootPath && !!scope.patches;
|
|
31897
32089
|
|
|
31898
|
-
var finalizeProperty = function (prop, value, parent) {
|
|
32090
|
+
var finalizeProperty = function finalizeProperty(prop, value, parent) {
|
|
31899
32091
|
if (value === parent) {
|
|
31900
32092
|
throw Error("Immer forbids circular references");
|
|
31901
32093
|
} // In the `finalizeTree` method, only the `root` object may be a draft.
|
|
@@ -31922,7 +32114,9 @@ Immer.prototype.finalizeTree = function finalizeTree (root, rootPath, scope) {
|
|
|
31922
32114
|
} // Unchanged drafts are never passed to the `onAssign` hook.
|
|
31923
32115
|
|
|
31924
32116
|
|
|
31925
|
-
if (isDraftProp && value === state.base[prop]) {
|
|
32117
|
+
if (isDraftProp && value === state.base[prop]) {
|
|
32118
|
+
return;
|
|
32119
|
+
}
|
|
31926
32120
|
} // Unchanged draft properties are ignored.
|
|
31927
32121
|
else if (isDraftProp && is(value, state.base[prop])) {
|
|
31928
32122
|
return;
|
|
@@ -32007,103 +32201,149 @@ var createDraft = immer.createDraft.bind(immer);
|
|
|
32007
32201
|
|
|
32008
32202
|
var finishDraft = immer.finishDraft.bind(immer);
|
|
32009
32203
|
|
|
32010
|
-
|
|
32011
|
-
|
|
32012
|
-
|
|
32013
|
-
|
|
32204
|
+
var createInitialState = function createInitialState(formConfig) {
|
|
32205
|
+
var initialForm = {};
|
|
32206
|
+
var formConfigKeys = Object.keys(formConfig);
|
|
32207
|
+
|
|
32208
|
+
for (var _i = 0, _formConfigKeys = formConfigKeys; _i < _formConfigKeys.length; _i++) {
|
|
32209
|
+
var formKey = _formConfigKeys[_i];
|
|
32014
32210
|
initialForm[formKey] = {
|
|
32015
32211
|
dirty: false,
|
|
32016
32212
|
rawValue: formConfig[formKey].defaultValue || "",
|
|
32017
32213
|
validators: formConfig[formKey].validators || [],
|
|
32018
32214
|
constraints: formConfig[formKey].constraints || []
|
|
32019
32215
|
};
|
|
32020
|
-
}
|
|
32021
|
-
// Because validators require the entire form we have to do a
|
|
32216
|
+
} // Because validators require the entire form we have to do a
|
|
32022
32217
|
// second pass to add errors once the initial form has been
|
|
32023
32218
|
// constructed
|
|
32024
|
-
|
|
32025
|
-
|
|
32026
|
-
|
|
32027
|
-
|
|
32219
|
+
|
|
32220
|
+
|
|
32221
|
+
for (var _i2 = 0, _formConfigKeys2 = formConfigKeys; _i2 < _formConfigKeys2.length; _i2++) {
|
|
32222
|
+
var _formKey = _formConfigKeys2[_i2];
|
|
32223
|
+
var errors = computeErrors(_formKey, initialForm);
|
|
32224
|
+
initialForm[_formKey].errors = errors;
|
|
32225
|
+
initialForm[_formKey].hasErrors = errors.length > 0;
|
|
32028
32226
|
}
|
|
32227
|
+
|
|
32029
32228
|
return initialForm;
|
|
32030
32229
|
};
|
|
32031
32230
|
|
|
32032
|
-
|
|
32033
|
-
const set$2 = fieldName => value => ({
|
|
32034
|
-
type: SET,
|
|
32035
|
-
payload: { fieldName, value }
|
|
32036
|
-
});
|
|
32231
|
+
var SET = "field/SET";
|
|
32037
32232
|
|
|
32038
|
-
|
|
32039
|
-
|
|
32040
|
-
|
|
32041
|
-
|
|
32042
|
-
|
|
32043
|
-
|
|
32044
|
-
|
|
32045
|
-
|
|
32046
|
-
|
|
32047
|
-
|
|
32048
|
-
|
|
32049
|
-
|
|
32050
|
-
return produce(state, draftState => {
|
|
32051
|
-
let originalValue = draftState[changedFieldName].rawValue;
|
|
32052
|
-
draftState[changedFieldName].rawValue = newRawValue;
|
|
32053
|
-
if (computeConstraints(changedFieldName, draftState).length > 0) {
|
|
32054
|
-
// If the change violates constraints, revert the change
|
|
32055
|
-
draftState[changedFieldName].rawValue = originalValue;
|
|
32056
|
-
return draftState;
|
|
32057
|
-
}
|
|
32233
|
+
var set$2 = function set$2(fieldName) {
|
|
32234
|
+
return function (value) {
|
|
32235
|
+
return {
|
|
32236
|
+
type: SET,
|
|
32237
|
+
payload: {
|
|
32238
|
+
fieldName: fieldName,
|
|
32239
|
+
value: value
|
|
32240
|
+
}
|
|
32241
|
+
};
|
|
32242
|
+
};
|
|
32243
|
+
};
|
|
32058
32244
|
|
|
32059
|
-
|
|
32060
|
-
|
|
32061
|
-
|
|
32062
|
-
|
|
32063
|
-
|
|
32064
|
-
|
|
32065
|
-
draftState[fieldName].errors = errors;
|
|
32066
|
-
draftState[fieldName].dirty = dirty;
|
|
32067
|
-
draftState[fieldName].hasErrors = errors.length > 0;
|
|
32068
|
-
}
|
|
32069
|
-
});
|
|
32070
|
-
case CLEAR:
|
|
32071
|
-
return createInitialState(formConfig);
|
|
32072
|
-
default:
|
|
32073
|
-
return state;
|
|
32074
|
-
}
|
|
32245
|
+
var CLEAR = "form/CLEAR";
|
|
32246
|
+
|
|
32247
|
+
var _clear = function clear() {
|
|
32248
|
+
return {
|
|
32249
|
+
type: CLEAR
|
|
32250
|
+
};
|
|
32075
32251
|
};
|
|
32076
32252
|
|
|
32077
|
-
|
|
32253
|
+
var createFormReducer = function createFormReducer(formConfig) {
|
|
32254
|
+
return function () {
|
|
32255
|
+
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : createInitialState(formConfig);
|
|
32256
|
+
var action = arguments.length > 1 ? arguments[1] : undefined;
|
|
32257
|
+
|
|
32258
|
+
switch (action.type) {
|
|
32259
|
+
case SET:
|
|
32260
|
+
var changedFieldName = action.payload.fieldName;
|
|
32261
|
+
var newRawValue = action.payload.value;
|
|
32262
|
+
return produce(state, function (draftState) {
|
|
32263
|
+
var originalValue = draftState[changedFieldName].rawValue;
|
|
32264
|
+
draftState[changedFieldName].rawValue = newRawValue;
|
|
32265
|
+
|
|
32266
|
+
if (computeConstraints(changedFieldName, draftState).length > 0) {
|
|
32267
|
+
// If the change violates constraints, revert the change
|
|
32268
|
+
draftState[changedFieldName].rawValue = originalValue;
|
|
32269
|
+
return draftState;
|
|
32270
|
+
}
|
|
32271
|
+
|
|
32272
|
+
var fields = Object.entries(draftState);
|
|
32273
|
+
|
|
32274
|
+
for (var _i3 = 0, _fields = fields; _i3 < _fields.length; _i3++) {
|
|
32275
|
+
var entry = _fields[_i3];
|
|
32276
|
+
var fieldName = entry[0];
|
|
32277
|
+
var field = entry[1];
|
|
32278
|
+
var errors = computeErrors(fieldName, draftState);
|
|
32279
|
+
var dirty = fieldName === changedFieldName ? true : field.dirty;
|
|
32280
|
+
draftState[fieldName].errors = errors;
|
|
32281
|
+
draftState[fieldName].dirty = dirty;
|
|
32282
|
+
draftState[fieldName].hasErrors = errors.length > 0;
|
|
32283
|
+
}
|
|
32284
|
+
});
|
|
32285
|
+
|
|
32286
|
+
case CLEAR:
|
|
32287
|
+
return createInitialState(formConfig);
|
|
32288
|
+
|
|
32289
|
+
default:
|
|
32290
|
+
return state;
|
|
32291
|
+
}
|
|
32292
|
+
};
|
|
32293
|
+
};
|
|
32294
|
+
|
|
32295
|
+
var createMapDispatchToProps = function createMapDispatchToProps(formConfig) {
|
|
32078
32296
|
// Do memo-ization
|
|
32079
|
-
|
|
32080
|
-
|
|
32081
|
-
return dispatch
|
|
32297
|
+
var cachedDispatch;
|
|
32298
|
+
var cacheValue;
|
|
32299
|
+
return function (dispatch) {
|
|
32082
32300
|
if (dispatch == cachedDispatch) {
|
|
32083
32301
|
return cacheValue;
|
|
32084
32302
|
}
|
|
32085
|
-
|
|
32303
|
+
|
|
32304
|
+
var dispatchObj = {};
|
|
32086
32305
|
dispatchObj.fields = {};
|
|
32087
|
-
|
|
32088
|
-
|
|
32306
|
+
var keys = Object.keys(formConfig);
|
|
32307
|
+
|
|
32308
|
+
var _loop = function _loop() {
|
|
32309
|
+
var fieldName = _keys[_i4];
|
|
32089
32310
|
dispatchObj.fields[fieldName] = {
|
|
32090
|
-
set:
|
|
32311
|
+
set: function set(value) {
|
|
32312
|
+
return dispatch(set$2(fieldName)(value));
|
|
32313
|
+
}
|
|
32091
32314
|
};
|
|
32315
|
+
};
|
|
32316
|
+
|
|
32317
|
+
for (var _i4 = 0, _keys = keys; _i4 < _keys.length; _i4++) {
|
|
32318
|
+
_loop();
|
|
32092
32319
|
}
|
|
32093
|
-
|
|
32320
|
+
|
|
32321
|
+
dispatchObj.form = {
|
|
32322
|
+
clear: function clear() {
|
|
32323
|
+
return dispatch(_clear());
|
|
32324
|
+
}
|
|
32325
|
+
};
|
|
32094
32326
|
cachedDispatch = dispatch;
|
|
32095
|
-
cacheValue = {
|
|
32327
|
+
cacheValue = {
|
|
32328
|
+
actions: dispatchObj
|
|
32329
|
+
};
|
|
32096
32330
|
return cacheValue;
|
|
32097
32331
|
};
|
|
32098
32332
|
};
|
|
32099
32333
|
|
|
32100
|
-
|
|
32334
|
+
var mapStateToProps = function mapStateToProps(state) {
|
|
32335
|
+
return {
|
|
32336
|
+
fields: state
|
|
32337
|
+
};
|
|
32338
|
+
};
|
|
32101
32339
|
|
|
32102
|
-
|
|
32103
|
-
|
|
32104
|
-
|
|
32105
|
-
|
|
32106
|
-
|
|
32340
|
+
var createFormState = function createFormState(formConfig) {
|
|
32341
|
+
return {
|
|
32342
|
+
reducer: createFormReducer(formConfig),
|
|
32343
|
+
mapDispatchToProps: createMapDispatchToProps(formConfig),
|
|
32344
|
+
mapStateToProps: mapStateToProps
|
|
32345
|
+
};
|
|
32346
|
+
};
|
|
32107
32347
|
|
|
32108
32348
|
var formatDelimiter = "_";
|
|
32109
32349
|
var phoneFormats = ["", "_", "__", "(___) ", "(___) _", "(___) __", "(___) ___-", "(___) ___-_", "(___) ___-__", "(___) ___-___", "(___) ___-____"];
|