@thecb/components 3.5.1 → 3.5.2
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 +629 -391
- package/package.json +1 -1
- package/src/components/atoms/dropdown/Dropdown.js +2 -3
- 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
|
|
|
@@ -17008,15 +17065,14 @@ var Dropdown = function Dropdown(_ref7) {
|
|
|
17008
17065
|
}, /*#__PURE__*/React__default.createElement(Box, {
|
|
17009
17066
|
as: "button",
|
|
17010
17067
|
background: isOpen ? themeValues.hoverColor : WHITE,
|
|
17011
|
-
minHeight: "52px",
|
|
17012
17068
|
width: "100%",
|
|
17013
|
-
padding: "
|
|
17069
|
+
padding: "12px",
|
|
17014
17070
|
hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
|
|
17015
17071
|
focusStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
|
|
17016
17072
|
borderSize: "1px",
|
|
17017
17073
|
borderColor: isError ? ERROR_COLOR : isOpen ? themeValues.selectedColor : GREY_CHATEAU,
|
|
17018
17074
|
borderRadius: "2px",
|
|
17019
|
-
extraStyles: "tabindex: 0;",
|
|
17075
|
+
extraStyles: "tabindex: 0; height: 48px;",
|
|
17020
17076
|
dataQa: placeholder
|
|
17021
17077
|
}, /*#__PURE__*/React__default.createElement(Stack, {
|
|
17022
17078
|
direction: "row",
|
|
@@ -30516,378 +30572,401 @@ var ToggleSwitch = function ToggleSwitch(_ref6) {
|
|
|
30516
30572
|
|
|
30517
30573
|
var ToggleSwitch$1 = themeComponent(ToggleSwitch, "ToggleSwitch", fallbackValues$o);
|
|
30518
30574
|
|
|
30519
|
-
|
|
30520
|
-
value
|
|
30521
|
-
|
|
30522
|
-
|
|
30575
|
+
var validatorToPredicate = function validatorToPredicate(validatorFn, emptyCase) {
|
|
30576
|
+
return function (value) {
|
|
30577
|
+
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
30578
|
+
rest[_key - 1] = arguments[_key];
|
|
30579
|
+
}
|
|
30523
30580
|
|
|
30581
|
+
return value === "" ? emptyCase : validatorFn.apply(void 0, [value].concat(rest));
|
|
30582
|
+
};
|
|
30583
|
+
};
|
|
30524
30584
|
/* eslint-disable no-unused-vars */
|
|
30525
30585
|
|
|
30526
|
-
|
|
30527
|
-
|
|
30586
|
+
|
|
30587
|
+
var createValidator = function createValidator(type, error) {
|
|
30588
|
+
var validator = function validator() {
|
|
30589
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
30590
|
+
args[_key2] = arguments[_key2];
|
|
30591
|
+
}
|
|
30592
|
+
|
|
30593
|
+
return {
|
|
30594
|
+
type: type,
|
|
30595
|
+
args: args,
|
|
30596
|
+
error: error
|
|
30597
|
+
};
|
|
30598
|
+
};
|
|
30599
|
+
|
|
30528
30600
|
validator.error = error;
|
|
30529
30601
|
return validator;
|
|
30530
30602
|
};
|
|
30531
30603
|
|
|
30532
|
-
|
|
30604
|
+
var validatorFns = {};
|
|
30605
|
+
var REQUIRED = "validator/REQUIRED";
|
|
30606
|
+
var REQUIRED_ERROR = "error/REQUIRED";
|
|
30607
|
+
var required = createValidator(REQUIRED, REQUIRED_ERROR);
|
|
30533
30608
|
|
|
30534
|
-
|
|
30535
|
-
|
|
30536
|
-
|
|
30537
|
-
validatorFns[REQUIRED] = (value, args, form) => value !== "";
|
|
30609
|
+
validatorFns[REQUIRED] = function (value, args, form) {
|
|
30610
|
+
return value !== "";
|
|
30611
|
+
};
|
|
30538
30612
|
|
|
30539
|
-
|
|
30540
|
-
|
|
30541
|
-
|
|
30542
|
-
validatorFns[ONLY_INTEGERS] = (value, args, form) => /^(-?\d+)?$/.test(value);
|
|
30613
|
+
var ONLY_INTEGERS = "validator/ONLY_INTEGERS";
|
|
30614
|
+
var ONLY_INTEGERS_ERROR = "error/ONLY_INTEGERS";
|
|
30615
|
+
var onlyIntegers = createValidator(ONLY_INTEGERS, ONLY_INTEGERS_ERROR);
|
|
30543
30616
|
|
|
30544
|
-
|
|
30545
|
-
|
|
30546
|
-
|
|
30547
|
-
validatorFns[ONLY_NATURALS] = (value, args, form) => /^(\d+)?$/.test(value);
|
|
30617
|
+
validatorFns[ONLY_INTEGERS] = function (value, args, form) {
|
|
30618
|
+
return /^(-?\d+)?$/.test(value);
|
|
30619
|
+
};
|
|
30548
30620
|
|
|
30549
|
-
|
|
30550
|
-
|
|
30551
|
-
|
|
30552
|
-
|
|
30553
|
-
|
|
30554
|
-
);
|
|
30555
|
-
|
|
30621
|
+
var ONLY_NATURALS = "validator/ONLY_NATURALS";
|
|
30622
|
+
var ONLY_NATURALS_ERROR = "error/ONLY_NATURALS";
|
|
30623
|
+
var onlyNaturals = createValidator(ONLY_NATURALS, ONLY_NATURALS_ERROR);
|
|
30624
|
+
|
|
30625
|
+
validatorFns[ONLY_NATURALS] = function (value, args, form) {
|
|
30626
|
+
return /^(\d+)?$/.test(value);
|
|
30627
|
+
};
|
|
30628
|
+
|
|
30629
|
+
var NUMBER_LESS_THAN = "validator/NUMBER_LESS_THAN";
|
|
30630
|
+
var NUMBER_LESS_THAN_ERROR = "error/NUMBER_LESS_THAN";
|
|
30631
|
+
var numberLessThan = createValidator(NUMBER_LESS_THAN, NUMBER_LESS_THAN_ERROR);
|
|
30632
|
+
|
|
30633
|
+
validatorFns[NUMBER_LESS_THAN] = function (value, args, form) {
|
|
30556
30634
|
if (value === "") {
|
|
30557
30635
|
return true;
|
|
30558
30636
|
}
|
|
30637
|
+
|
|
30559
30638
|
return Number(value) < args[0];
|
|
30560
30639
|
};
|
|
30561
30640
|
|
|
30562
|
-
|
|
30563
|
-
|
|
30564
|
-
|
|
30565
|
-
|
|
30566
|
-
|
|
30567
|
-
NUMBER_LESS_THAN_OR_EQUAL_TO,
|
|
30568
|
-
NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR
|
|
30569
|
-
);
|
|
30570
|
-
validatorFns[NUMBER_LESS_THAN_OR_EQUAL_TO] = (value, args, form) => {
|
|
30641
|
+
var NUMBER_LESS_THAN_OR_EQUAL_TO = "validator/NUMBER_LESS_THAN_OR_EQUAL_TO";
|
|
30642
|
+
var NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR = "error/NUMBER_LESS_THAN_OR_EQUAL_TO";
|
|
30643
|
+
var numberLessThanOrEqualTo = createValidator(NUMBER_LESS_THAN_OR_EQUAL_TO, NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR);
|
|
30644
|
+
|
|
30645
|
+
validatorFns[NUMBER_LESS_THAN_OR_EQUAL_TO] = function (value, args, form) {
|
|
30571
30646
|
if (value === "") {
|
|
30572
30647
|
return true;
|
|
30573
30648
|
}
|
|
30649
|
+
|
|
30574
30650
|
return Number(value) <= args[0];
|
|
30575
30651
|
};
|
|
30576
30652
|
|
|
30577
|
-
|
|
30578
|
-
|
|
30579
|
-
|
|
30580
|
-
|
|
30581
|
-
|
|
30582
|
-
);
|
|
30583
|
-
validatorFns[NUMBER_GREATER_THAN] = (value, args, form) => {
|
|
30653
|
+
var NUMBER_GREATER_THAN = "validator/NUMBER_GREATER_THAN";
|
|
30654
|
+
var NUMBER_GREATER_THAN_ERROR = "error/NUMBER_GREATER_THAN";
|
|
30655
|
+
var numberGreaterThan = createValidator(NUMBER_GREATER_THAN, NUMBER_GREATER_THAN_ERROR);
|
|
30656
|
+
|
|
30657
|
+
validatorFns[NUMBER_GREATER_THAN] = function (value, args, form) {
|
|
30584
30658
|
if (value === "") {
|
|
30585
30659
|
return true;
|
|
30586
30660
|
}
|
|
30661
|
+
|
|
30587
30662
|
return Number(value) > args[0];
|
|
30588
30663
|
};
|
|
30589
30664
|
|
|
30590
|
-
|
|
30591
|
-
|
|
30592
|
-
|
|
30593
|
-
|
|
30594
|
-
|
|
30595
|
-
NUMBER_GREATER_THAN_OR_EQUAL_TO,
|
|
30596
|
-
NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR
|
|
30597
|
-
);
|
|
30598
|
-
validatorFns[NUMBER_GREATER_THAN_OR_EQUAL_TO] = (value, args, form) => {
|
|
30665
|
+
var NUMBER_GREATER_THAN_OR_EQUAL_TO = "validator/NUMBER_GREATER_THAN_OR_EQUAL_TO";
|
|
30666
|
+
var NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR = "error/NUMBER_GREATER_THAN_OR_EQUAL_TO";
|
|
30667
|
+
var numberGreaterThanOrEqualTo = createValidator(NUMBER_GREATER_THAN_OR_EQUAL_TO, NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR);
|
|
30668
|
+
|
|
30669
|
+
validatorFns[NUMBER_GREATER_THAN_OR_EQUAL_TO] = function (value, args, form) {
|
|
30599
30670
|
if (value === "") {
|
|
30600
30671
|
return true;
|
|
30601
30672
|
}
|
|
30673
|
+
|
|
30602
30674
|
return Number(value) >= args[0];
|
|
30603
30675
|
};
|
|
30604
30676
|
|
|
30605
|
-
|
|
30606
|
-
|
|
30607
|
-
|
|
30608
|
-
|
|
30677
|
+
var MATCHES_FIELD = "validator/MATCHES_FIELD";
|
|
30678
|
+
var MATCHES_FIELD_ERROR$1 = "error/MATCHES_FIELD";
|
|
30679
|
+
var matchesField = createValidator(MATCHES_FIELD, MATCHES_FIELD_ERROR$1);
|
|
30680
|
+
|
|
30681
|
+
validatorFns[MATCHES_FIELD] = function (value, args, form) {
|
|
30609
30682
|
if (value === "") {
|
|
30610
30683
|
return true;
|
|
30611
30684
|
}
|
|
30685
|
+
|
|
30612
30686
|
if (form[args[0]] === undefined) {
|
|
30613
|
-
throw new Error(
|
|
30614
|
-
`${args[0]} was passed to matchesField, but that field does not exist in the form`
|
|
30615
|
-
);
|
|
30687
|
+
throw new Error("".concat(args[0], " was passed to matchesField, but that field does not exist in the form"));
|
|
30616
30688
|
}
|
|
30689
|
+
|
|
30617
30690
|
return value === form[args[0]].rawValue;
|
|
30618
30691
|
};
|
|
30619
30692
|
|
|
30620
|
-
|
|
30621
|
-
|
|
30622
|
-
|
|
30623
|
-
|
|
30624
|
-
|
|
30625
|
-
|
|
30626
|
-
|
|
30627
|
-
|
|
30628
|
-
|
|
30629
|
-
|
|
30630
|
-
|
|
30631
|
-
|
|
30632
|
-
|
|
30633
|
-
|
|
30634
|
-
|
|
30635
|
-
type: VALIDATE_WHEN,
|
|
30636
|
-
args: [dependentValidator, primaryValidator, optionalFieldName],
|
|
30637
|
-
error: dependentValidator.error
|
|
30638
|
-
});
|
|
30693
|
+
var validateWhenErrorMessage = function validateWhenErrorMessage(type) {
|
|
30694
|
+
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.");
|
|
30695
|
+
};
|
|
30696
|
+
|
|
30697
|
+
var VALIDATE_WHEN = "validator/VALIDATE_WHEN";
|
|
30698
|
+
var VALIDATE_WHEN_ERROR = "error/VALIDATE_WHEN";
|
|
30699
|
+
|
|
30700
|
+
var validateWhen = function validateWhen(dependentValidator, primaryValidator, optionalFieldName) {
|
|
30701
|
+
return {
|
|
30702
|
+
type: VALIDATE_WHEN,
|
|
30703
|
+
args: [dependentValidator, primaryValidator, optionalFieldName],
|
|
30704
|
+
error: dependentValidator.error
|
|
30705
|
+
};
|
|
30706
|
+
};
|
|
30707
|
+
|
|
30639
30708
|
validateWhen.error = VALIDATE_WHEN_ERROR;
|
|
30640
|
-
validatorFns[VALIDATE_WHEN] = (value, args, form) => {
|
|
30641
|
-
const [dependentValidator, primaryValidator, optionalFieldName] = args;
|
|
30642
|
-
const dependsOnOtherField = typeof optionalFieldName === "string";
|
|
30643
30709
|
|
|
30644
|
-
|
|
30645
|
-
|
|
30646
|
-
|
|
30647
|
-
|
|
30710
|
+
validatorFns[VALIDATE_WHEN] = function (value, args, form) {
|
|
30711
|
+
var _args = _slicedToArray(args, 3),
|
|
30712
|
+
dependentValidator = _args[0],
|
|
30713
|
+
primaryValidator = _args[1],
|
|
30714
|
+
optionalFieldName = _args[2];
|
|
30715
|
+
|
|
30716
|
+
var dependsOnOtherField = typeof optionalFieldName === "string";
|
|
30717
|
+
|
|
30718
|
+
if (primaryValidator.type === undefined || typeof validatorFns[primaryValidator.type] !== "function") {
|
|
30648
30719
|
throw new Error(validateWhenErrorMessage(primaryValidator.type));
|
|
30649
30720
|
}
|
|
30721
|
+
|
|
30650
30722
|
if (dependsOnOtherField && form[optionalFieldName] === undefined) {
|
|
30651
|
-
throw new Error(
|
|
30652
|
-
`${args[2]} was passed to matchesField, but that field does not exist in the form`
|
|
30653
|
-
);
|
|
30723
|
+
throw new Error("".concat(args[2], " was passed to matchesField, but that field does not exist in the form"));
|
|
30654
30724
|
}
|
|
30655
30725
|
|
|
30656
|
-
|
|
30657
|
-
|
|
30658
|
-
|
|
30659
|
-
);
|
|
30660
|
-
|
|
30661
|
-
|
|
30662
|
-
|
|
30663
|
-
|
|
30664
|
-
|
|
30665
|
-
|
|
30666
|
-
|
|
30667
|
-
|
|
30726
|
+
var primaryPredicate = validatorToPredicate(validatorFns[primaryValidator.type], false);
|
|
30727
|
+
var primaryValue = dependsOnOtherField ? form[optionalFieldName].rawValue : value;
|
|
30728
|
+
var primaryPredicatePassed = primaryPredicate(primaryValue, primaryValidator.args, form);
|
|
30729
|
+
return primaryPredicatePassed ? validatorFns[dependentValidator.type](value, dependentValidator.args, form) : true;
|
|
30730
|
+
};
|
|
30731
|
+
|
|
30732
|
+
var validateSumErrorMessage = function validateSumErrorMessage(type) {
|
|
30733
|
+
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).");
|
|
30734
|
+
};
|
|
30735
|
+
|
|
30736
|
+
var VALIDATE_SUM = "validator/VALIDATE_SUM";
|
|
30737
|
+
var VALIDATE_SUM_ERROR = "error/VALIDATE_SUM";
|
|
30738
|
+
|
|
30739
|
+
var validateSum = function validateSum(validator, fieldNamesArray) {
|
|
30740
|
+
return {
|
|
30741
|
+
type: VALIDATE_SUM,
|
|
30742
|
+
args: [validator, fieldNamesArray],
|
|
30743
|
+
error: validator.error
|
|
30744
|
+
};
|
|
30745
|
+
};
|
|
30668
30746
|
|
|
30669
|
-
return primaryPredicatePassed
|
|
30670
|
-
? validatorFns[dependentValidator.type](
|
|
30671
|
-
value,
|
|
30672
|
-
dependentValidator.args,
|
|
30673
|
-
form
|
|
30674
|
-
)
|
|
30675
|
-
: true;
|
|
30676
|
-
};
|
|
30677
|
-
|
|
30678
|
-
const validateSumErrorMessage = type =>
|
|
30679
|
-
`${type} was passed to validateSum, but that validator type does not exist.
|
|
30680
|
-
Please check that you are only calling validator creator functions exported from
|
|
30681
|
-
redux-freeform in your form config and that you didn't forget to
|
|
30682
|
-
invoke the validator creator (you cannot pass the functions themselves to
|
|
30683
|
-
createFormState).`;
|
|
30684
|
-
const VALIDATE_SUM = "validator/VALIDATE_SUM";
|
|
30685
|
-
const VALIDATE_SUM_ERROR = "error/VALIDATE_SUM";
|
|
30686
|
-
const validateSum = (validator, fieldNamesArray) => ({
|
|
30687
|
-
type: VALIDATE_SUM,
|
|
30688
|
-
args: [validator, fieldNamesArray],
|
|
30689
|
-
error: validator.error
|
|
30690
|
-
});
|
|
30691
30747
|
validateSum.error = VALIDATE_SUM_ERROR;
|
|
30692
|
-
validatorFns[VALIDATE_SUM] = (value, args, form) => {
|
|
30693
|
-
const [validator, fieldNamesArray] = args;
|
|
30694
30748
|
|
|
30695
|
-
|
|
30696
|
-
|
|
30697
|
-
|
|
30698
|
-
|
|
30749
|
+
validatorFns[VALIDATE_SUM] = function (value, args, form) {
|
|
30750
|
+
var _args2 = _slicedToArray(args, 2),
|
|
30751
|
+
validator = _args2[0],
|
|
30752
|
+
fieldNamesArray = _args2[1];
|
|
30753
|
+
|
|
30754
|
+
if (validator.type === undefined || typeof validatorFns[validator.type] !== "function") {
|
|
30699
30755
|
throw new Error(validateSumErrorMessage(validator.type));
|
|
30700
30756
|
}
|
|
30701
30757
|
|
|
30702
|
-
|
|
30703
|
-
|
|
30704
|
-
|
|
30705
|
-
|
|
30706
|
-
|
|
30758
|
+
var _iterator = _createForOfIteratorHelper(fieldNamesArray),
|
|
30759
|
+
_step;
|
|
30760
|
+
|
|
30761
|
+
try {
|
|
30762
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
30763
|
+
var fieldName = _step.value;
|
|
30764
|
+
|
|
30765
|
+
if (form[fieldName] === undefined) {
|
|
30766
|
+
throw new Error("".concat(fieldName, " was passed to matchesField, but that field does not exist in the form"));
|
|
30767
|
+
}
|
|
30707
30768
|
}
|
|
30769
|
+
} catch (err) {
|
|
30770
|
+
_iterator.e(err);
|
|
30771
|
+
} finally {
|
|
30772
|
+
_iterator.f();
|
|
30708
30773
|
}
|
|
30709
30774
|
|
|
30710
|
-
|
|
30711
|
-
|
|
30712
|
-
|
|
30713
|
-
);
|
|
30714
|
-
|
|
30775
|
+
var sum = fieldNamesArray.reduce(function (acc, curr) {
|
|
30776
|
+
return acc + Number(form[curr].rawValue);
|
|
30777
|
+
}, Number(value));
|
|
30715
30778
|
return validatorFns[validator.type](sum, validator.args, form);
|
|
30716
30779
|
};
|
|
30717
30780
|
|
|
30718
|
-
|
|
30719
|
-
|
|
30720
|
-
|
|
30721
|
-
|
|
30781
|
+
var HAS_LENGTH = "validator/HAS_LENGTH";
|
|
30782
|
+
var HAS_LENGTH_ERROR = "error/HAS_LENGTH";
|
|
30783
|
+
var hasLength = createValidator(HAS_LENGTH, HAS_LENGTH_ERROR);
|
|
30784
|
+
|
|
30785
|
+
validatorFns[HAS_LENGTH] = function (value, args, form) {
|
|
30722
30786
|
if (value === "") {
|
|
30723
30787
|
return true;
|
|
30724
30788
|
}
|
|
30725
|
-
|
|
30726
|
-
|
|
30789
|
+
|
|
30790
|
+
var min = args[0];
|
|
30791
|
+
var max = args[1];
|
|
30792
|
+
|
|
30727
30793
|
if (max == undefined || min == undefined) {
|
|
30728
|
-
throw new Error(
|
|
30729
|
-
"Max and min need to be defined for hasLength, both or one of them is undefined"
|
|
30730
|
-
);
|
|
30794
|
+
throw new Error("Max and min need to be defined for hasLength, both or one of them is undefined");
|
|
30731
30795
|
}
|
|
30796
|
+
|
|
30732
30797
|
if (max < min) {
|
|
30733
|
-
throw new Error(
|
|
30734
|
-
"hasLength validator was passed a min greater than the max"
|
|
30735
|
-
);
|
|
30798
|
+
throw new Error("hasLength validator was passed a min greater than the max");
|
|
30736
30799
|
}
|
|
30737
|
-
|
|
30800
|
+
|
|
30801
|
+
var valueLength = value.length;
|
|
30738
30802
|
return max >= valueLength && valueLength >= min;
|
|
30739
30803
|
};
|
|
30740
30804
|
|
|
30741
|
-
|
|
30742
|
-
|
|
30743
|
-
|
|
30744
|
-
|
|
30805
|
+
var MATCHES_REGEX = "validator/MATCHES_REGEX";
|
|
30806
|
+
var MATCHES_REGEX_ERROR = "error/MATCHES_REGEX";
|
|
30807
|
+
var matchesRegex = createValidator(MATCHES_REGEX, MATCHES_REGEX_ERROR);
|
|
30808
|
+
|
|
30809
|
+
validatorFns[MATCHES_REGEX] = function (value, args, form) {
|
|
30745
30810
|
if (value === "") {
|
|
30746
30811
|
return true;
|
|
30747
30812
|
}
|
|
30813
|
+
|
|
30748
30814
|
return new RegExp(args[0]).test(value); // new RexExp never throws an error, no matter the input
|
|
30749
|
-
};
|
|
30815
|
+
}; // based on http://www.brainjar.com/js/validation/
|
|
30750
30816
|
|
|
30751
|
-
|
|
30752
|
-
|
|
30753
|
-
|
|
30754
|
-
|
|
30755
|
-
|
|
30756
|
-
|
|
30757
|
-
);
|
|
30758
|
-
validatorFns[IS_ROUTING_NUMBER] = (value, args, form) => {
|
|
30817
|
+
|
|
30818
|
+
var IS_ROUTING_NUMBER = "validator/IS_ROUTING_NUMBER";
|
|
30819
|
+
var IS_ROUTING_NUMBER_ERROR = "error/IS_ROUTING_NUMBER";
|
|
30820
|
+
var isRoutingNumber = createValidator(IS_ROUTING_NUMBER, IS_ROUTING_NUMBER_ERROR);
|
|
30821
|
+
|
|
30822
|
+
validatorFns[IS_ROUTING_NUMBER] = function (value, args, form) {
|
|
30759
30823
|
if (value === "") {
|
|
30760
30824
|
return true;
|
|
30761
30825
|
}
|
|
30826
|
+
|
|
30762
30827
|
if (value.length != 9) {
|
|
30763
30828
|
return false;
|
|
30764
30829
|
}
|
|
30765
|
-
|
|
30766
|
-
|
|
30767
|
-
|
|
30768
|
-
|
|
30769
|
-
|
|
30770
|
-
|
|
30771
|
-
|
|
30772
|
-
|
|
30773
|
-
|
|
30774
|
-
|
|
30775
|
-
|
|
30776
|
-
|
|
30777
|
-
|
|
30830
|
+
|
|
30831
|
+
var sum = value.split("").map(function (ch) {
|
|
30832
|
+
return parseInt(ch);
|
|
30833
|
+
}).reduce(function (acc, cur, idx) {
|
|
30834
|
+
switch (idx % 3) {
|
|
30835
|
+
case 0:
|
|
30836
|
+
return acc + 3 * cur;
|
|
30837
|
+
|
|
30838
|
+
case 1:
|
|
30839
|
+
return acc + 7 * cur;
|
|
30840
|
+
|
|
30841
|
+
case 2:
|
|
30842
|
+
return acc + 1 * cur;
|
|
30843
|
+
}
|
|
30844
|
+
}, 0);
|
|
30778
30845
|
return sum != 0 && sum % 10 == 0;
|
|
30779
30846
|
};
|
|
30780
30847
|
|
|
30781
|
-
|
|
30782
|
-
|
|
30783
|
-
|
|
30784
|
-
|
|
30848
|
+
var HAS_NUMBER = "validator/HAS_NUMBER";
|
|
30849
|
+
var HAS_NUMBER_ERROR$1 = "error/HAS_NUMBER";
|
|
30850
|
+
var hasNumber = createValidator(HAS_NUMBER, HAS_NUMBER_ERROR$1);
|
|
30851
|
+
|
|
30852
|
+
validatorFns[HAS_NUMBER] = function (value, args, form) {
|
|
30785
30853
|
if (value === "") {
|
|
30786
30854
|
return true;
|
|
30787
30855
|
}
|
|
30856
|
+
|
|
30788
30857
|
return new RegExp(/[0-9]/).test(value);
|
|
30789
30858
|
};
|
|
30790
30859
|
|
|
30791
|
-
|
|
30792
|
-
|
|
30793
|
-
|
|
30794
|
-
|
|
30795
|
-
|
|
30796
|
-
);
|
|
30797
|
-
validatorFns[HAS_LOWERCASE_LETTER] = (value, args, form) => {
|
|
30860
|
+
var HAS_LOWERCASE_LETTER = "validator/HAS_LOWERCASE_LETTER";
|
|
30861
|
+
var HAS_LOWERCASE_LETTER_ERROR$1 = "error/HAS_LOWERCASE_LETTER";
|
|
30862
|
+
var hasLowercaseLetter = createValidator(HAS_LOWERCASE_LETTER, HAS_LOWERCASE_LETTER_ERROR$1);
|
|
30863
|
+
|
|
30864
|
+
validatorFns[HAS_LOWERCASE_LETTER] = function (value, args, form) {
|
|
30798
30865
|
if (value === "") {
|
|
30799
30866
|
return true;
|
|
30800
30867
|
}
|
|
30868
|
+
|
|
30801
30869
|
return new RegExp(/[a-z]/).test(value);
|
|
30802
30870
|
};
|
|
30803
30871
|
|
|
30804
|
-
|
|
30805
|
-
|
|
30806
|
-
|
|
30807
|
-
|
|
30808
|
-
|
|
30809
|
-
);
|
|
30810
|
-
validatorFns[HAS_UPPERCASE_LETTER] = (value, args, form) => {
|
|
30872
|
+
var HAS_UPPERCASE_LETTER = "validator/HAS_UPPERCASE_LETTER";
|
|
30873
|
+
var HAS_UPPERCASE_LETTER_ERROR$1 = "error/HAS_UPPERCASE_LETTER";
|
|
30874
|
+
var hasUppercaseLetter = createValidator(HAS_UPPERCASE_LETTER, HAS_UPPERCASE_LETTER_ERROR$1);
|
|
30875
|
+
|
|
30876
|
+
validatorFns[HAS_UPPERCASE_LETTER] = function (value, args, form) {
|
|
30811
30877
|
if (value === "") {
|
|
30812
30878
|
return true;
|
|
30813
30879
|
}
|
|
30880
|
+
|
|
30814
30881
|
return new RegExp(/[A-Z]/).test(value);
|
|
30815
30882
|
};
|
|
30816
30883
|
|
|
30817
|
-
|
|
30818
|
-
|
|
30819
|
-
|
|
30820
|
-
|
|
30821
|
-
|
|
30822
|
-
);
|
|
30823
|
-
validatorFns[HAS_SPECIAL_CHARACTER] = (value, args, form) => {
|
|
30884
|
+
var HAS_SPECIAL_CHARACTER = "validator/HAS_SPECIAL_CHARACTER";
|
|
30885
|
+
var HAS_SPECIAL_CHARACTER_ERROR$1 = "error/HAS_SPECIAL_CHARACTER";
|
|
30886
|
+
var hasSpecialCharacter = createValidator(HAS_SPECIAL_CHARACTER, HAS_SPECIAL_CHARACTER_ERROR$1);
|
|
30887
|
+
|
|
30888
|
+
validatorFns[HAS_SPECIAL_CHARACTER] = function (value, args, form) {
|
|
30824
30889
|
if (value === "") {
|
|
30825
30890
|
return true;
|
|
30826
30891
|
}
|
|
30892
|
+
|
|
30827
30893
|
return new RegExp(/[!@#$%^&*.?]/).test(value);
|
|
30828
30894
|
};
|
|
30829
30895
|
|
|
30830
|
-
|
|
30831
|
-
|
|
30832
|
-
|
|
30833
|
-
|
|
30834
|
-
|
|
30835
|
-
);
|
|
30836
|
-
validatorFns[IS_PROBABLY_EMAIL] = (value, args, form) => {
|
|
30896
|
+
var IS_PROBABLY_EMAIL = "validator/IS_PROBABLY_EMAIL";
|
|
30897
|
+
var IS_PROBABLY_EMAIL_ERROR = "error/IS_PROBABLY_EMAIL";
|
|
30898
|
+
var isProbablyEmail = createValidator(IS_PROBABLY_EMAIL, IS_PROBABLY_EMAIL_ERROR);
|
|
30899
|
+
|
|
30900
|
+
validatorFns[IS_PROBABLY_EMAIL] = function (value, args, form) {
|
|
30837
30901
|
if (value === "") {
|
|
30838
30902
|
return true;
|
|
30839
30903
|
}
|
|
30904
|
+
|
|
30840
30905
|
return new RegExp(/^\S+@\S+\.\S+$/).test(value);
|
|
30841
30906
|
};
|
|
30842
30907
|
|
|
30843
|
-
|
|
30844
|
-
|
|
30845
|
-
|
|
30846
|
-
|
|
30847
|
-
|
|
30848
|
-
|
|
30908
|
+
var runValidatorErrorMessage = function runValidatorErrorMessage(type) {
|
|
30909
|
+
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)");
|
|
30910
|
+
};
|
|
30911
|
+
|
|
30912
|
+
var runValidator = function runValidator(validator, value, form) {
|
|
30913
|
+
var validatorFn = validatorFns[validator.type];
|
|
30849
30914
|
|
|
30850
|
-
const runValidator = (validator, value, form) => {
|
|
30851
|
-
const validatorFn = validatorFns[validator.type];
|
|
30852
30915
|
if (validatorFn === undefined) {
|
|
30853
30916
|
throw new Error(runValidatorErrorMessage(validator.type));
|
|
30854
30917
|
}
|
|
30918
|
+
|
|
30855
30919
|
return validatorFn(value, validator.args, form) ? null : validator.error;
|
|
30856
30920
|
};
|
|
30857
30921
|
|
|
30858
|
-
|
|
30859
|
-
return validators
|
|
30860
|
-
|
|
30861
|
-
|
|
30922
|
+
var _computeErrors = function _computeErrors(fieldName, form, validators) {
|
|
30923
|
+
return validators.map(function (v) {
|
|
30924
|
+
return runValidator(v, form[fieldName].rawValue, form);
|
|
30925
|
+
}).filter(function (x) {
|
|
30926
|
+
return x !== null;
|
|
30927
|
+
});
|
|
30862
30928
|
};
|
|
30863
30929
|
|
|
30864
|
-
|
|
30865
|
-
|
|
30930
|
+
var computeConstraints = function computeConstraints(fieldName, form) {
|
|
30931
|
+
var constraints = form[fieldName].constraints;
|
|
30866
30932
|
return _computeErrors(fieldName, form, constraints);
|
|
30867
30933
|
};
|
|
30868
30934
|
|
|
30869
|
-
|
|
30870
|
-
|
|
30935
|
+
var computeErrors = function computeErrors(fieldName, form) {
|
|
30936
|
+
var validators = form[fieldName].validators;
|
|
30871
30937
|
return _computeErrors(fieldName, form, validators);
|
|
30872
30938
|
};
|
|
30873
30939
|
|
|
30874
30940
|
var obj;
|
|
30875
|
-
var NOTHING = typeof Symbol !== "undefined" ? Symbol("immer-nothing") : (
|
|
30876
|
-
var DRAFTABLE = typeof Symbol !== "undefined" && Symbol
|
|
30877
|
-
var DRAFT_STATE = typeof Symbol !== "undefined" && Symbol
|
|
30941
|
+
var NOTHING = typeof Symbol !== "undefined" ? Symbol("immer-nothing") : (obj = {}, obj["immer-nothing"] = true, obj);
|
|
30942
|
+
var DRAFTABLE = typeof Symbol !== "undefined" && Symbol["for"] ? Symbol["for"]("immer-draftable") : "__$immer_draftable";
|
|
30943
|
+
var DRAFT_STATE = typeof Symbol !== "undefined" && Symbol["for"] ? Symbol["for"]("immer-state") : "__$immer_state";
|
|
30944
|
+
|
|
30878
30945
|
function isDraft(value) {
|
|
30879
30946
|
return !!value && !!value[DRAFT_STATE];
|
|
30880
30947
|
}
|
|
30948
|
+
|
|
30881
30949
|
function isDraftable(value) {
|
|
30882
|
-
if (!value) {
|
|
30950
|
+
if (!value) {
|
|
30951
|
+
return false;
|
|
30952
|
+
}
|
|
30953
|
+
|
|
30883
30954
|
return isPlainObject(value) || !!value[DRAFTABLE] || !!value.constructor[DRAFTABLE];
|
|
30884
30955
|
}
|
|
30956
|
+
|
|
30885
30957
|
function isPlainObject(value) {
|
|
30886
|
-
if (!value ||
|
|
30887
|
-
|
|
30958
|
+
if (!value || _typeof(value) !== "object") {
|
|
30959
|
+
return false;
|
|
30960
|
+
}
|
|
30961
|
+
|
|
30962
|
+
if (Array.isArray(value)) {
|
|
30963
|
+
return true;
|
|
30964
|
+
}
|
|
30965
|
+
|
|
30888
30966
|
var proto = Object.getPrototypeOf(value);
|
|
30889
30967
|
return !proto || proto === Object.prototype;
|
|
30890
30968
|
}
|
|
30969
|
+
|
|
30891
30970
|
var assign = Object.assign || function assign(target, value) {
|
|
30892
30971
|
for (var key in value) {
|
|
30893
30972
|
if (has(value, key)) {
|
|
@@ -30897,11 +30976,18 @@ var assign = Object.assign || function assign(target, value) {
|
|
|
30897
30976
|
|
|
30898
30977
|
return target;
|
|
30899
30978
|
};
|
|
30900
|
-
|
|
30979
|
+
|
|
30980
|
+
var ownKeys$1 = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) {
|
|
30981
|
+
return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj));
|
|
30982
|
+
} : Object.getOwnPropertyNames;
|
|
30983
|
+
|
|
30901
30984
|
function shallowCopy(base, invokeGetters) {
|
|
30902
|
-
if (
|
|
30985
|
+
if (invokeGetters === void 0) invokeGetters = false;
|
|
30986
|
+
|
|
30987
|
+
if (Array.isArray(base)) {
|
|
30988
|
+
return base.slice();
|
|
30989
|
+
}
|
|
30903
30990
|
|
|
30904
|
-
if (Array.isArray(base)) { return base.slice(); }
|
|
30905
30991
|
var clone = Object.create(Object.getPrototypeOf(base));
|
|
30906
30992
|
ownKeys$1(base).forEach(function (key) {
|
|
30907
30993
|
if (key === DRAFT_STATE) {
|
|
@@ -30931,20 +31017,28 @@ function shallowCopy(base, invokeGetters) {
|
|
|
30931
31017
|
});
|
|
30932
31018
|
return clone;
|
|
30933
31019
|
}
|
|
31020
|
+
|
|
30934
31021
|
function each(value, cb) {
|
|
30935
31022
|
if (Array.isArray(value)) {
|
|
30936
|
-
for (var i = 0; i < value.length; i++) {
|
|
31023
|
+
for (var i = 0; i < value.length; i++) {
|
|
31024
|
+
cb(i, value[i], value);
|
|
31025
|
+
}
|
|
30937
31026
|
} else {
|
|
30938
|
-
ownKeys$1(value).forEach(function (key) {
|
|
31027
|
+
ownKeys$1(value).forEach(function (key) {
|
|
31028
|
+
return cb(key, value[key], value);
|
|
31029
|
+
});
|
|
30939
31030
|
}
|
|
30940
31031
|
}
|
|
31032
|
+
|
|
30941
31033
|
function isEnumerable(base, prop) {
|
|
30942
31034
|
var desc = Object.getOwnPropertyDescriptor(base, prop);
|
|
30943
31035
|
return !!desc && desc.enumerable;
|
|
30944
31036
|
}
|
|
31037
|
+
|
|
30945
31038
|
function has(thing, prop) {
|
|
30946
31039
|
return Object.prototype.hasOwnProperty.call(thing, prop);
|
|
30947
31040
|
}
|
|
31041
|
+
|
|
30948
31042
|
function is(x, y) {
|
|
30949
31043
|
// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
|
|
30950
31044
|
if (x === y) {
|
|
@@ -30953,18 +31047,27 @@ function is(x, y) {
|
|
|
30953
31047
|
return x !== x && y !== y;
|
|
30954
31048
|
}
|
|
30955
31049
|
}
|
|
31050
|
+
|
|
30956
31051
|
function clone(obj) {
|
|
30957
|
-
if (!isDraftable(obj)) {
|
|
30958
|
-
|
|
31052
|
+
if (!isDraftable(obj)) {
|
|
31053
|
+
return obj;
|
|
31054
|
+
}
|
|
31055
|
+
|
|
31056
|
+
if (Array.isArray(obj)) {
|
|
31057
|
+
return obj.map(clone);
|
|
31058
|
+
}
|
|
31059
|
+
|
|
30959
31060
|
var cloned = Object.create(Object.getPrototypeOf(obj));
|
|
30960
31061
|
|
|
30961
|
-
for (var key in obj) {
|
|
31062
|
+
for (var key in obj) {
|
|
31063
|
+
cloned[key] = clone(obj[key]);
|
|
31064
|
+
}
|
|
30962
31065
|
|
|
30963
31066
|
return cloned;
|
|
30964
31067
|
}
|
|
30965
|
-
|
|
30966
31068
|
/** Each scope represents a `produce` call. */
|
|
30967
31069
|
|
|
31070
|
+
|
|
30968
31071
|
var ImmerScope = function ImmerScope(parent) {
|
|
30969
31072
|
this.drafts = [];
|
|
30970
31073
|
this.parent = parent; // Whenever the modified draft contains a draft from another scope, we
|
|
@@ -30975,7 +31078,7 @@ var ImmerScope = function ImmerScope(parent) {
|
|
|
30975
31078
|
this.patches = null;
|
|
30976
31079
|
};
|
|
30977
31080
|
|
|
30978
|
-
ImmerScope.prototype.usePatches = function usePatches
|
|
31081
|
+
ImmerScope.prototype.usePatches = function usePatches(patchListener) {
|
|
30979
31082
|
if (patchListener) {
|
|
30980
31083
|
this.patches = [];
|
|
30981
31084
|
this.inversePatches = [];
|
|
@@ -30983,17 +31086,18 @@ ImmerScope.prototype.usePatches = function usePatches (patchListener) {
|
|
|
30983
31086
|
}
|
|
30984
31087
|
};
|
|
30985
31088
|
|
|
30986
|
-
ImmerScope.prototype.revoke = function revoke$1
|
|
31089
|
+
ImmerScope.prototype.revoke = function revoke$1() {
|
|
30987
31090
|
this.leave();
|
|
30988
31091
|
this.drafts.forEach(revoke);
|
|
30989
31092
|
this.drafts = null; // Make draft-related methods throw.
|
|
30990
31093
|
};
|
|
30991
31094
|
|
|
30992
|
-
ImmerScope.prototype.leave = function leave
|
|
31095
|
+
ImmerScope.prototype.leave = function leave() {
|
|
30993
31096
|
if (this === ImmerScope.current) {
|
|
30994
31097
|
ImmerScope.current = this.parent;
|
|
30995
31098
|
}
|
|
30996
31099
|
};
|
|
31100
|
+
|
|
30997
31101
|
ImmerScope.current = null;
|
|
30998
31102
|
|
|
30999
31103
|
ImmerScope.enter = function () {
|
|
@@ -31002,11 +31106,11 @@ ImmerScope.enter = function () {
|
|
|
31002
31106
|
|
|
31003
31107
|
function revoke(draft) {
|
|
31004
31108
|
draft[DRAFT_STATE].revoke();
|
|
31005
|
-
}
|
|
31109
|
+
} // but share them all instead
|
|
31006
31110
|
|
|
31007
|
-
// but share them all instead
|
|
31008
31111
|
|
|
31009
31112
|
var descriptors = {};
|
|
31113
|
+
|
|
31010
31114
|
function willFinalize(scope, result, isReplaced) {
|
|
31011
31115
|
scope.drafts.forEach(function (draft) {
|
|
31012
31116
|
draft[DRAFT_STATE].finalizing = true;
|
|
@@ -31024,6 +31128,7 @@ function willFinalize(scope, result, isReplaced) {
|
|
|
31024
31128
|
markChangesSweep(scope.drafts);
|
|
31025
31129
|
}
|
|
31026
31130
|
}
|
|
31131
|
+
|
|
31027
31132
|
function createProxy(base, parent) {
|
|
31028
31133
|
var isArray = Array.isArray(base);
|
|
31029
31134
|
var draft = clonePotentialDraft(base);
|
|
@@ -31077,7 +31182,11 @@ function peek(draft, prop) {
|
|
|
31077
31182
|
function get(state, prop) {
|
|
31078
31183
|
assertUnrevoked(state);
|
|
31079
31184
|
var value = peek(source(state), prop);
|
|
31080
|
-
|
|
31185
|
+
|
|
31186
|
+
if (state.finalizing) {
|
|
31187
|
+
return value;
|
|
31188
|
+
} // Create a draft if the value is unmodified.
|
|
31189
|
+
|
|
31081
31190
|
|
|
31082
31191
|
if (value === peek(state.base, prop) && isDraftable(value)) {
|
|
31083
31192
|
prepareCopy(state);
|
|
@@ -31092,7 +31201,10 @@ function set(state, prop, value) {
|
|
|
31092
31201
|
state.assigned[prop] = true;
|
|
31093
31202
|
|
|
31094
31203
|
if (!state.modified) {
|
|
31095
|
-
if (is(value, peek(source(state), prop))) {
|
|
31204
|
+
if (is(value, peek(source(state), prop))) {
|
|
31205
|
+
return;
|
|
31206
|
+
}
|
|
31207
|
+
|
|
31096
31208
|
markChanged(state);
|
|
31097
31209
|
prepareCopy(state);
|
|
31098
31210
|
}
|
|
@@ -31103,12 +31215,17 @@ function set(state, prop, value) {
|
|
|
31103
31215
|
function markChanged(state) {
|
|
31104
31216
|
if (!state.modified) {
|
|
31105
31217
|
state.modified = true;
|
|
31106
|
-
|
|
31218
|
+
|
|
31219
|
+
if (state.parent) {
|
|
31220
|
+
markChanged(state.parent);
|
|
31221
|
+
}
|
|
31107
31222
|
}
|
|
31108
31223
|
}
|
|
31109
31224
|
|
|
31110
31225
|
function prepareCopy(state) {
|
|
31111
|
-
if (!state.copy) {
|
|
31226
|
+
if (!state.copy) {
|
|
31227
|
+
state.copy = clonePotentialDraft(state.base);
|
|
31228
|
+
}
|
|
31112
31229
|
}
|
|
31113
31230
|
|
|
31114
31231
|
function clonePotentialDraft(base) {
|
|
@@ -31133,15 +31250,12 @@ function proxyProperty(draft, prop, enumerable) {
|
|
|
31133
31250
|
descriptors[prop] = desc = {
|
|
31134
31251
|
configurable: true,
|
|
31135
31252
|
enumerable: enumerable,
|
|
31136
|
-
|
|
31137
31253
|
get: function get$1() {
|
|
31138
31254
|
return get(this[DRAFT_STATE], prop);
|
|
31139
31255
|
},
|
|
31140
|
-
|
|
31141
31256
|
set: function set$1(value) {
|
|
31142
31257
|
set(this[DRAFT_STATE], prop, value);
|
|
31143
31258
|
}
|
|
31144
|
-
|
|
31145
31259
|
};
|
|
31146
31260
|
}
|
|
31147
31261
|
|
|
@@ -31149,7 +31263,9 @@ function proxyProperty(draft, prop, enumerable) {
|
|
|
31149
31263
|
}
|
|
31150
31264
|
|
|
31151
31265
|
function assertUnrevoked(state) {
|
|
31152
|
-
if (state.revoked === true) {
|
|
31266
|
+
if (state.revoked === true) {
|
|
31267
|
+
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)));
|
|
31268
|
+
}
|
|
31153
31269
|
} // This looks expensive, but only proxies are visited, and only objects without known changes are scanned.
|
|
31154
31270
|
|
|
31155
31271
|
|
|
@@ -31163,16 +31279,27 @@ function markChangesSweep(drafts) {
|
|
|
31163
31279
|
|
|
31164
31280
|
if (!state.modified) {
|
|
31165
31281
|
if (Array.isArray(state.base)) {
|
|
31166
|
-
if (hasArrayChanges(state)) {
|
|
31167
|
-
|
|
31282
|
+
if (hasArrayChanges(state)) {
|
|
31283
|
+
markChanged(state);
|
|
31284
|
+
}
|
|
31285
|
+
} else if (hasObjectChanges(state)) {
|
|
31286
|
+
markChanged(state);
|
|
31287
|
+
}
|
|
31168
31288
|
}
|
|
31169
31289
|
}
|
|
31170
31290
|
}
|
|
31171
31291
|
|
|
31172
31292
|
function markChangesRecursively(object) {
|
|
31173
|
-
if (!object ||
|
|
31293
|
+
if (!object || _typeof(object) !== "object") {
|
|
31294
|
+
return;
|
|
31295
|
+
}
|
|
31296
|
+
|
|
31174
31297
|
var state = object[DRAFT_STATE];
|
|
31175
|
-
|
|
31298
|
+
|
|
31299
|
+
if (!state) {
|
|
31300
|
+
return;
|
|
31301
|
+
}
|
|
31302
|
+
|
|
31176
31303
|
var base = state.base;
|
|
31177
31304
|
var draft = state.draft;
|
|
31178
31305
|
var assigned = state.assigned;
|
|
@@ -31202,14 +31329,20 @@ function markChangesRecursively(object) {
|
|
|
31202
31329
|
assigned.length = true;
|
|
31203
31330
|
|
|
31204
31331
|
if (draft.length < base.length) {
|
|
31205
|
-
for (var i = draft.length; i < base.length; i++) {
|
|
31332
|
+
for (var i = draft.length; i < base.length; i++) {
|
|
31333
|
+
assigned[i] = false;
|
|
31334
|
+
}
|
|
31206
31335
|
} else {
|
|
31207
|
-
for (var i$1 = base.length; i$1 < draft.length; i$1++) {
|
|
31336
|
+
for (var i$1 = base.length; i$1 < draft.length; i$1++) {
|
|
31337
|
+
assigned[i$1] = true;
|
|
31338
|
+
}
|
|
31208
31339
|
}
|
|
31209
31340
|
|
|
31210
31341
|
for (var i$2 = 0; i$2 < draft.length; i$2++) {
|
|
31211
31342
|
// Only untouched indices trigger recursion.
|
|
31212
|
-
if (assigned[i$2] === undefined) {
|
|
31343
|
+
if (assigned[i$2] === undefined) {
|
|
31344
|
+
markChangesRecursively(draft[i$2]);
|
|
31345
|
+
}
|
|
31213
31346
|
}
|
|
31214
31347
|
}
|
|
31215
31348
|
}
|
|
@@ -31246,7 +31379,10 @@ function hasObjectChanges(state) {
|
|
|
31246
31379
|
|
|
31247
31380
|
function hasArrayChanges(state) {
|
|
31248
31381
|
var draft = state.draft;
|
|
31249
|
-
|
|
31382
|
+
|
|
31383
|
+
if (draft.length !== state.base.length) {
|
|
31384
|
+
return true;
|
|
31385
|
+
} // See #116
|
|
31250
31386
|
// If we first shorten the length, our array interceptors will be removed.
|
|
31251
31387
|
// If after that new items are added, result in the same original length,
|
|
31252
31388
|
// those last items will have no intercepting property.
|
|
@@ -31254,9 +31390,13 @@ function hasArrayChanges(state) {
|
|
|
31254
31390
|
// N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check
|
|
31255
31391
|
// the last one
|
|
31256
31392
|
|
|
31393
|
+
|
|
31257
31394
|
var descriptor = Object.getOwnPropertyDescriptor(draft, draft.length - 1); // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)
|
|
31258
31395
|
|
|
31259
|
-
if (descriptor && !descriptor.get) {
|
|
31396
|
+
if (descriptor && !descriptor.get) {
|
|
31397
|
+
return true;
|
|
31398
|
+
} // For all other cases, we don't have to compare, as they would have been picked up by the index setters
|
|
31399
|
+
|
|
31260
31400
|
|
|
31261
31401
|
return false;
|
|
31262
31402
|
}
|
|
@@ -31270,11 +31410,12 @@ function createHiddenProperty(target, prop, value) {
|
|
|
31270
31410
|
}
|
|
31271
31411
|
|
|
31272
31412
|
var legacyProxy = /*#__PURE__*/Object.freeze({
|
|
31273
|
-
|
|
31274
|
-
|
|
31413
|
+
willFinalize: willFinalize,
|
|
31414
|
+
createProxy: createProxy
|
|
31275
31415
|
});
|
|
31276
31416
|
|
|
31277
31417
|
function willFinalize$1() {}
|
|
31418
|
+
|
|
31278
31419
|
function createProxy$1(base, parent) {
|
|
31279
31420
|
var scope = parent ? parent.scope : ImmerScope.current;
|
|
31280
31421
|
var state = {
|
|
@@ -31309,33 +31450,27 @@ function createProxy$1(base, parent) {
|
|
|
31309
31450
|
scope.drafts.push(proxy);
|
|
31310
31451
|
return proxy;
|
|
31311
31452
|
}
|
|
31453
|
+
|
|
31312
31454
|
var objectTraps = {
|
|
31313
31455
|
get: get$1,
|
|
31314
|
-
|
|
31315
31456
|
has: function has(target, prop) {
|
|
31316
31457
|
return prop in source$1(target);
|
|
31317
31458
|
},
|
|
31318
|
-
|
|
31319
31459
|
ownKeys: function ownKeys(target) {
|
|
31320
31460
|
return Reflect.ownKeys(source$1(target));
|
|
31321
31461
|
},
|
|
31322
|
-
|
|
31323
31462
|
set: set$1,
|
|
31324
31463
|
deleteProperty: deleteProperty,
|
|
31325
31464
|
getOwnPropertyDescriptor: getOwnPropertyDescriptor,
|
|
31326
|
-
|
|
31327
31465
|
defineProperty: function defineProperty() {
|
|
31328
31466
|
throw new Error("Object.defineProperty() cannot be used on an Immer draft"); // prettier-ignore
|
|
31329
31467
|
},
|
|
31330
|
-
|
|
31331
31468
|
getPrototypeOf: function getPrototypeOf(target) {
|
|
31332
31469
|
return Object.getPrototypeOf(target.base);
|
|
31333
31470
|
},
|
|
31334
|
-
|
|
31335
31471
|
setPrototypeOf: function setPrototypeOf() {
|
|
31336
31472
|
throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft"); // prettier-ignore
|
|
31337
31473
|
}
|
|
31338
|
-
|
|
31339
31474
|
};
|
|
31340
31475
|
var arrayTraps = {};
|
|
31341
31476
|
each(objectTraps, function (key, fn) {
|
|
@@ -31374,7 +31509,10 @@ function peek$1(draft, prop) {
|
|
|
31374
31509
|
}
|
|
31375
31510
|
|
|
31376
31511
|
function get$1(state, prop) {
|
|
31377
|
-
if (prop === DRAFT_STATE) {
|
|
31512
|
+
if (prop === DRAFT_STATE) {
|
|
31513
|
+
return state;
|
|
31514
|
+
}
|
|
31515
|
+
|
|
31378
31516
|
var drafts = state.drafts; // Check for existing draft in unmodified state.
|
|
31379
31517
|
|
|
31380
31518
|
if (!state.modified && has(drafts, prop)) {
|
|
@@ -31390,7 +31528,10 @@ function get$1(state, prop) {
|
|
|
31390
31528
|
|
|
31391
31529
|
if (state.modified) {
|
|
31392
31530
|
// Assigned values are never drafted. This catches any drafts we created, too.
|
|
31393
|
-
if (value !== peek$1(state.base, prop)) {
|
|
31531
|
+
if (value !== peek$1(state.base, prop)) {
|
|
31532
|
+
return value;
|
|
31533
|
+
} // Store drafts on the copy (when one exists).
|
|
31534
|
+
|
|
31394
31535
|
|
|
31395
31536
|
drafts = state.copy;
|
|
31396
31537
|
}
|
|
@@ -31405,7 +31546,11 @@ function set$1(state, prop, value) {
|
|
|
31405
31546
|
// values may be drafts, but falsy values are never drafts.
|
|
31406
31547
|
|
|
31407
31548
|
var isUnchanged = value ? is(baseValue, value) || value === state.drafts[prop] : is(baseValue, value) && prop in state.base;
|
|
31408
|
-
|
|
31549
|
+
|
|
31550
|
+
if (isUnchanged) {
|
|
31551
|
+
return true;
|
|
31552
|
+
}
|
|
31553
|
+
|
|
31409
31554
|
markChanged$1(state);
|
|
31410
31555
|
}
|
|
31411
31556
|
|
|
@@ -31424,7 +31569,10 @@ function deleteProperty(state, prop) {
|
|
|
31424
31569
|
delete state.assigned[prop];
|
|
31425
31570
|
}
|
|
31426
31571
|
|
|
31427
|
-
if (state.copy) {
|
|
31572
|
+
if (state.copy) {
|
|
31573
|
+
delete state.copy[prop];
|
|
31574
|
+
}
|
|
31575
|
+
|
|
31428
31576
|
return true;
|
|
31429
31577
|
} // Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
31430
31578
|
// the same guarantee in ES5 mode.
|
|
@@ -31447,13 +31595,16 @@ function markChanged$1(state) {
|
|
|
31447
31595
|
state.modified = true;
|
|
31448
31596
|
state.copy = assign(shallowCopy(state.base), state.drafts);
|
|
31449
31597
|
state.drafts = null;
|
|
31450
|
-
|
|
31598
|
+
|
|
31599
|
+
if (state.parent) {
|
|
31600
|
+
markChanged$1(state.parent);
|
|
31601
|
+
}
|
|
31451
31602
|
}
|
|
31452
31603
|
}
|
|
31453
31604
|
|
|
31454
31605
|
var modernProxy = /*#__PURE__*/Object.freeze({
|
|
31455
|
-
|
|
31456
|
-
|
|
31606
|
+
willFinalize: willFinalize$1,
|
|
31607
|
+
createProxy: createProxy$1
|
|
31457
31608
|
});
|
|
31458
31609
|
|
|
31459
31610
|
function generatePatches(state, basePath, patches, inversePatches) {
|
|
@@ -31462,14 +31613,13 @@ function generatePatches(state, basePath, patches, inversePatches) {
|
|
|
31462
31613
|
|
|
31463
31614
|
function generateArrayPatches(state, basePath, patches, inversePatches) {
|
|
31464
31615
|
var assign, assign$1;
|
|
31465
|
-
|
|
31466
31616
|
var base = state.base;
|
|
31467
31617
|
var copy = state.copy;
|
|
31468
31618
|
var assigned = state.assigned; // Reduce complexity by ensuring `base` is never longer.
|
|
31469
31619
|
|
|
31470
31620
|
if (copy.length < base.length) {
|
|
31471
|
-
|
|
31472
|
-
|
|
31621
|
+
assign = [copy, base], base = assign[0], copy = assign[1];
|
|
31622
|
+
assign$1 = [inversePatches, patches], patches = assign$1[0], inversePatches = assign$1[1];
|
|
31473
31623
|
}
|
|
31474
31624
|
|
|
31475
31625
|
var delta = copy.length - base.length; // Find the first replaced index.
|
|
@@ -31527,7 +31677,11 @@ function generateObjectPatches(state, basePath, patches, inversePatches) {
|
|
|
31527
31677
|
var origValue = base[key];
|
|
31528
31678
|
var value = copy[key];
|
|
31529
31679
|
var op = !assignedValue ? "remove" : key in base ? "replace" : "add";
|
|
31530
|
-
|
|
31680
|
+
|
|
31681
|
+
if (origValue === value && op === "replace") {
|
|
31682
|
+
return;
|
|
31683
|
+
}
|
|
31684
|
+
|
|
31531
31685
|
var path = basePath.concat(key);
|
|
31532
31686
|
patches.push(op === "remove" ? {
|
|
31533
31687
|
op: op,
|
|
@@ -31552,20 +31706,26 @@ function generateObjectPatches(state, basePath, patches, inversePatches) {
|
|
|
31552
31706
|
});
|
|
31553
31707
|
}
|
|
31554
31708
|
|
|
31555
|
-
var applyPatches = function (draft, patches) {
|
|
31709
|
+
var applyPatches = function applyPatches(draft, patches) {
|
|
31556
31710
|
for (var i$1 = 0, list = patches; i$1 < list.length; i$1 += 1) {
|
|
31557
31711
|
var patch = list[i$1];
|
|
31558
|
-
|
|
31559
31712
|
var path = patch.path;
|
|
31560
31713
|
var op = patch.op;
|
|
31561
31714
|
var value = clone(patch.value); // used to clone patch to ensure original patch is not modified, see #411
|
|
31562
31715
|
|
|
31563
|
-
if (!path.length) {
|
|
31716
|
+
if (!path.length) {
|
|
31717
|
+
throw new Error("Illegal state");
|
|
31718
|
+
}
|
|
31719
|
+
|
|
31564
31720
|
var base = draft;
|
|
31565
31721
|
|
|
31566
31722
|
for (var i = 0; i < path.length - 1; i++) {
|
|
31567
31723
|
base = base[path[i]];
|
|
31568
|
-
|
|
31724
|
+
|
|
31725
|
+
if (!base || _typeof(base) !== "object") {
|
|
31726
|
+
throw new Error("Cannot apply patch, path doesn't resolve: " + path.join("/"));
|
|
31727
|
+
} // prettier-ignore
|
|
31728
|
+
|
|
31569
31729
|
}
|
|
31570
31730
|
|
|
31571
31731
|
var key = path[path.length - 1];
|
|
@@ -31614,27 +31774,33 @@ var configDefaults = {
|
|
|
31614
31774
|
onDelete: null,
|
|
31615
31775
|
onCopy: null
|
|
31616
31776
|
};
|
|
31777
|
+
|
|
31617
31778
|
var Immer = function Immer(config) {
|
|
31618
31779
|
assign(this, configDefaults, config);
|
|
31619
31780
|
this.setUseProxies(this.useProxies);
|
|
31620
31781
|
this.produce = this.produce.bind(this);
|
|
31621
31782
|
};
|
|
31622
31783
|
|
|
31623
|
-
Immer.prototype.produce = function produce
|
|
31624
|
-
|
|
31784
|
+
Immer.prototype.produce = function produce(base, recipe, patchListener) {
|
|
31785
|
+
var this$1 = this; // curried invocation
|
|
31625
31786
|
|
|
31626
|
-
// curried invocation
|
|
31627
31787
|
if (typeof base === "function" && typeof recipe !== "function") {
|
|
31628
31788
|
var defaultBase = recipe;
|
|
31629
31789
|
recipe = base;
|
|
31630
31790
|
var self = this;
|
|
31631
31791
|
return function curriedProduce(base) {
|
|
31632
|
-
|
|
31633
|
-
|
|
31634
|
-
|
|
31635
|
-
|
|
31792
|
+
var this$1 = this;
|
|
31793
|
+
if (base === void 0) base = defaultBase;
|
|
31794
|
+
var args = [],
|
|
31795
|
+
len = arguments.length - 1;
|
|
31796
|
+
|
|
31797
|
+
while (len-- > 0) {
|
|
31798
|
+
args[len] = arguments[len + 1];
|
|
31799
|
+
}
|
|
31636
31800
|
|
|
31637
|
-
return self.produce(base, function (draft) {
|
|
31801
|
+
return self.produce(base, function (draft) {
|
|
31802
|
+
return recipe.call.apply(recipe, [this$1, draft].concat(args));
|
|
31803
|
+
}); // prettier-ignore
|
|
31638
31804
|
};
|
|
31639
31805
|
} // prettier-ignore
|
|
31640
31806
|
|
|
@@ -31660,7 +31826,11 @@ Immer.prototype.produce = function produce (base, recipe, patchListener) {
|
|
|
31660
31826
|
hasError = false;
|
|
31661
31827
|
} finally {
|
|
31662
31828
|
// finally instead of catch + rethrow better preserves original stack
|
|
31663
|
-
if (hasError) {
|
|
31829
|
+
if (hasError) {
|
|
31830
|
+
scope.revoke();
|
|
31831
|
+
} else {
|
|
31832
|
+
scope.leave();
|
|
31833
|
+
}
|
|
31664
31834
|
}
|
|
31665
31835
|
|
|
31666
31836
|
if (result instanceof Promise) {
|
|
@@ -31677,25 +31847,38 @@ Immer.prototype.produce = function produce (base, recipe, patchListener) {
|
|
|
31677
31847
|
return this.processResult(result, scope);
|
|
31678
31848
|
} else {
|
|
31679
31849
|
result = recipe(base);
|
|
31680
|
-
|
|
31850
|
+
|
|
31851
|
+
if (result === undefined) {
|
|
31852
|
+
return base;
|
|
31853
|
+
}
|
|
31854
|
+
|
|
31681
31855
|
return result !== NOTHING ? result : undefined;
|
|
31682
31856
|
}
|
|
31683
31857
|
};
|
|
31684
31858
|
|
|
31685
|
-
Immer.prototype.produceWithPatches = function produceWithPatches
|
|
31686
|
-
|
|
31859
|
+
Immer.prototype.produceWithPatches = function produceWithPatches(arg1, arg2, arg3) {
|
|
31860
|
+
var this$1 = this;
|
|
31687
31861
|
|
|
31688
31862
|
if (typeof arg1 === "function") {
|
|
31689
31863
|
return function (state) {
|
|
31690
|
-
|
|
31691
|
-
|
|
31864
|
+
var args = [],
|
|
31865
|
+
len = arguments.length - 1;
|
|
31692
31866
|
|
|
31693
|
-
|
|
31694
|
-
|
|
31867
|
+
while (len-- > 0) {
|
|
31868
|
+
args[len] = arguments[len + 1];
|
|
31869
|
+
}
|
|
31870
|
+
|
|
31871
|
+
return this$1.produceWithPatches(state, function (draft) {
|
|
31872
|
+
return arg1.apply(void 0, [draft].concat(args));
|
|
31873
|
+
});
|
|
31874
|
+
};
|
|
31695
31875
|
} // non-curried form
|
|
31696
31876
|
|
|
31697
31877
|
|
|
31698
|
-
if (arg3) {
|
|
31878
|
+
if (arg3) {
|
|
31879
|
+
throw new Error("A patch listener cannot be passed to produceWithPatches");
|
|
31880
|
+
}
|
|
31881
|
+
|
|
31699
31882
|
var patches, inversePatches;
|
|
31700
31883
|
var nextState = this.produce(arg1, arg2, function (p, ip) {
|
|
31701
31884
|
patches = p;
|
|
@@ -31704,7 +31887,7 @@ Immer.prototype.produceWithPatches = function produceWithPatches (arg1, arg2, ar
|
|
|
31704
31887
|
return [nextState, patches, inversePatches];
|
|
31705
31888
|
};
|
|
31706
31889
|
|
|
31707
|
-
Immer.prototype.createDraft = function createDraft
|
|
31890
|
+
Immer.prototype.createDraft = function createDraft(base) {
|
|
31708
31891
|
if (!isDraftable(base)) {
|
|
31709
31892
|
throw new Error("First argument to `createDraft` must be a plain object, an array, or an immerable object"); // prettier-ignore
|
|
31710
31893
|
}
|
|
@@ -31716,7 +31899,7 @@ Immer.prototype.createDraft = function createDraft (base) {
|
|
|
31716
31899
|
return proxy;
|
|
31717
31900
|
};
|
|
31718
31901
|
|
|
31719
|
-
Immer.prototype.finishDraft = function finishDraft
|
|
31902
|
+
Immer.prototype.finishDraft = function finishDraft(draft, patchListener) {
|
|
31720
31903
|
var state = draft && draft[DRAFT_STATE];
|
|
31721
31904
|
|
|
31722
31905
|
if (!state || !state.isManual) {
|
|
@@ -31732,16 +31915,16 @@ Immer.prototype.finishDraft = function finishDraft (draft, patchListener) {
|
|
|
31732
31915
|
return this.processResult(undefined, scope);
|
|
31733
31916
|
};
|
|
31734
31917
|
|
|
31735
|
-
Immer.prototype.setAutoFreeze = function setAutoFreeze
|
|
31918
|
+
Immer.prototype.setAutoFreeze = function setAutoFreeze(value) {
|
|
31736
31919
|
this.autoFreeze = value;
|
|
31737
31920
|
};
|
|
31738
31921
|
|
|
31739
|
-
Immer.prototype.setUseProxies = function setUseProxies
|
|
31922
|
+
Immer.prototype.setUseProxies = function setUseProxies(value) {
|
|
31740
31923
|
this.useProxies = value;
|
|
31741
31924
|
assign(this, value ? modernProxy : legacyProxy);
|
|
31742
31925
|
};
|
|
31743
31926
|
|
|
31744
|
-
Immer.prototype.applyPatches = function applyPatches$1
|
|
31927
|
+
Immer.prototype.applyPatches = function applyPatches$1(base, patches) {
|
|
31745
31928
|
// If a patch replaces the entire state, take that replacement as base
|
|
31746
31929
|
// before applying patches
|
|
31747
31930
|
var i;
|
|
@@ -31761,12 +31944,14 @@ Immer.prototype.applyPatches = function applyPatches$1 (base, patches) {
|
|
|
31761
31944
|
} // Otherwise, produce a copy of the base state.
|
|
31762
31945
|
|
|
31763
31946
|
|
|
31764
|
-
return this.produce(base, function (draft) {
|
|
31947
|
+
return this.produce(base, function (draft) {
|
|
31948
|
+
return applyPatches(draft, patches.slice(i + 1));
|
|
31949
|
+
});
|
|
31765
31950
|
};
|
|
31766
31951
|
/** @internal */
|
|
31767
31952
|
|
|
31768
31953
|
|
|
31769
|
-
Immer.prototype.processResult = function processResult
|
|
31954
|
+
Immer.prototype.processResult = function processResult(result, scope) {
|
|
31770
31955
|
var baseDraft = scope.drafts[0];
|
|
31771
31956
|
var isReplaced = result !== undefined && result !== baseDraft;
|
|
31772
31957
|
this.willFinalize(scope, result, isReplaced);
|
|
@@ -31814,13 +31999,15 @@ Immer.prototype.processResult = function processResult (result, scope) {
|
|
|
31814
31999
|
*/
|
|
31815
32000
|
|
|
31816
32001
|
|
|
31817
|
-
Immer.prototype.finalize = function finalize
|
|
31818
|
-
|
|
31819
|
-
|
|
32002
|
+
Immer.prototype.finalize = function finalize(draft, path, scope) {
|
|
32003
|
+
var this$1 = this;
|
|
31820
32004
|
var state = draft[DRAFT_STATE];
|
|
31821
32005
|
|
|
31822
32006
|
if (!state) {
|
|
31823
|
-
if (Object.isFrozen(draft)) {
|
|
32007
|
+
if (Object.isFrozen(draft)) {
|
|
32008
|
+
return draft;
|
|
32009
|
+
}
|
|
32010
|
+
|
|
31824
32011
|
return this.finalizeTree(draft, null, scope);
|
|
31825
32012
|
} // Never finalize drafts owned by another scope.
|
|
31826
32013
|
|
|
@@ -31843,13 +32030,17 @@ Immer.prototype.finalize = function finalize (draft, path, scope) {
|
|
|
31843
32030
|
var assigned = state.assigned;
|
|
31844
32031
|
|
|
31845
32032
|
for (var prop in assigned) {
|
|
31846
|
-
if (!assigned[prop]) {
|
|
32033
|
+
if (!assigned[prop]) {
|
|
32034
|
+
this.onDelete(state, prop);
|
|
32035
|
+
}
|
|
31847
32036
|
}
|
|
31848
32037
|
} else {
|
|
31849
32038
|
var base = state.base;
|
|
31850
|
-
|
|
32039
|
+
var copy = state.copy;
|
|
31851
32040
|
each(base, function (prop) {
|
|
31852
|
-
if (!has(copy, prop)) {
|
|
32041
|
+
if (!has(copy, prop)) {
|
|
32042
|
+
this$1.onDelete(state, prop);
|
|
32043
|
+
}
|
|
31853
32044
|
});
|
|
31854
32045
|
}
|
|
31855
32046
|
}
|
|
@@ -31877,9 +32068,8 @@ Immer.prototype.finalize = function finalize (draft, path, scope) {
|
|
|
31877
32068
|
*/
|
|
31878
32069
|
|
|
31879
32070
|
|
|
31880
|
-
Immer.prototype.finalizeTree = function finalizeTree
|
|
31881
|
-
|
|
31882
|
-
|
|
32071
|
+
Immer.prototype.finalizeTree = function finalizeTree(root, rootPath, scope) {
|
|
32072
|
+
var this$1 = this;
|
|
31883
32073
|
var state = root[DRAFT_STATE];
|
|
31884
32074
|
|
|
31885
32075
|
if (state) {
|
|
@@ -31893,7 +32083,7 @@ Immer.prototype.finalizeTree = function finalizeTree (root, rootPath, scope) {
|
|
|
31893
32083
|
|
|
31894
32084
|
var needPatches = !!rootPath && !!scope.patches;
|
|
31895
32085
|
|
|
31896
|
-
var finalizeProperty = function (prop, value, parent) {
|
|
32086
|
+
var finalizeProperty = function finalizeProperty(prop, value, parent) {
|
|
31897
32087
|
if (value === parent) {
|
|
31898
32088
|
throw Error("Immer forbids circular references");
|
|
31899
32089
|
} // In the `finalizeTree` method, only the `root` object may be a draft.
|
|
@@ -31920,7 +32110,9 @@ Immer.prototype.finalizeTree = function finalizeTree (root, rootPath, scope) {
|
|
|
31920
32110
|
} // Unchanged drafts are never passed to the `onAssign` hook.
|
|
31921
32111
|
|
|
31922
32112
|
|
|
31923
|
-
if (isDraftProp && value === state.base[prop]) {
|
|
32113
|
+
if (isDraftProp && value === state.base[prop]) {
|
|
32114
|
+
return;
|
|
32115
|
+
}
|
|
31924
32116
|
} // Unchanged draft properties are ignored.
|
|
31925
32117
|
else if (isDraftProp && is(value, state.base[prop])) {
|
|
31926
32118
|
return;
|
|
@@ -32005,103 +32197,149 @@ var createDraft = immer.createDraft.bind(immer);
|
|
|
32005
32197
|
|
|
32006
32198
|
var finishDraft = immer.finishDraft.bind(immer);
|
|
32007
32199
|
|
|
32008
|
-
|
|
32009
|
-
|
|
32010
|
-
|
|
32011
|
-
|
|
32200
|
+
var createInitialState = function createInitialState(formConfig) {
|
|
32201
|
+
var initialForm = {};
|
|
32202
|
+
var formConfigKeys = Object.keys(formConfig);
|
|
32203
|
+
|
|
32204
|
+
for (var _i = 0, _formConfigKeys = formConfigKeys; _i < _formConfigKeys.length; _i++) {
|
|
32205
|
+
var formKey = _formConfigKeys[_i];
|
|
32012
32206
|
initialForm[formKey] = {
|
|
32013
32207
|
dirty: false,
|
|
32014
32208
|
rawValue: formConfig[formKey].defaultValue || "",
|
|
32015
32209
|
validators: formConfig[formKey].validators || [],
|
|
32016
32210
|
constraints: formConfig[formKey].constraints || []
|
|
32017
32211
|
};
|
|
32018
|
-
}
|
|
32019
|
-
// Because validators require the entire form we have to do a
|
|
32212
|
+
} // Because validators require the entire form we have to do a
|
|
32020
32213
|
// second pass to add errors once the initial form has been
|
|
32021
32214
|
// constructed
|
|
32022
|
-
|
|
32023
|
-
|
|
32024
|
-
|
|
32025
|
-
|
|
32215
|
+
|
|
32216
|
+
|
|
32217
|
+
for (var _i2 = 0, _formConfigKeys2 = formConfigKeys; _i2 < _formConfigKeys2.length; _i2++) {
|
|
32218
|
+
var _formKey = _formConfigKeys2[_i2];
|
|
32219
|
+
var errors = computeErrors(_formKey, initialForm);
|
|
32220
|
+
initialForm[_formKey].errors = errors;
|
|
32221
|
+
initialForm[_formKey].hasErrors = errors.length > 0;
|
|
32026
32222
|
}
|
|
32223
|
+
|
|
32027
32224
|
return initialForm;
|
|
32028
32225
|
};
|
|
32029
32226
|
|
|
32030
|
-
|
|
32031
|
-
const set$2 = fieldName => value => ({
|
|
32032
|
-
type: SET,
|
|
32033
|
-
payload: { fieldName, value }
|
|
32034
|
-
});
|
|
32227
|
+
var SET = "field/SET";
|
|
32035
32228
|
|
|
32036
|
-
|
|
32037
|
-
|
|
32038
|
-
|
|
32039
|
-
|
|
32040
|
-
|
|
32041
|
-
|
|
32042
|
-
|
|
32043
|
-
|
|
32044
|
-
|
|
32045
|
-
|
|
32046
|
-
|
|
32047
|
-
|
|
32048
|
-
return produce(state, draftState => {
|
|
32049
|
-
let originalValue = draftState[changedFieldName].rawValue;
|
|
32050
|
-
draftState[changedFieldName].rawValue = newRawValue;
|
|
32051
|
-
if (computeConstraints(changedFieldName, draftState).length > 0) {
|
|
32052
|
-
// If the change violates constraints, revert the change
|
|
32053
|
-
draftState[changedFieldName].rawValue = originalValue;
|
|
32054
|
-
return draftState;
|
|
32055
|
-
}
|
|
32229
|
+
var set$2 = function set$2(fieldName) {
|
|
32230
|
+
return function (value) {
|
|
32231
|
+
return {
|
|
32232
|
+
type: SET,
|
|
32233
|
+
payload: {
|
|
32234
|
+
fieldName: fieldName,
|
|
32235
|
+
value: value
|
|
32236
|
+
}
|
|
32237
|
+
};
|
|
32238
|
+
};
|
|
32239
|
+
};
|
|
32056
32240
|
|
|
32057
|
-
|
|
32058
|
-
|
|
32059
|
-
|
|
32060
|
-
|
|
32061
|
-
|
|
32062
|
-
|
|
32063
|
-
|
|
32064
|
-
|
|
32065
|
-
|
|
32066
|
-
|
|
32067
|
-
|
|
32068
|
-
|
|
32069
|
-
|
|
32070
|
-
|
|
32071
|
-
|
|
32072
|
-
|
|
32241
|
+
var CLEAR = "form/CLEAR";
|
|
32242
|
+
|
|
32243
|
+
var _clear = function clear() {
|
|
32244
|
+
return {
|
|
32245
|
+
type: CLEAR
|
|
32246
|
+
};
|
|
32247
|
+
};
|
|
32248
|
+
|
|
32249
|
+
var createFormReducer = function createFormReducer(formConfig) {
|
|
32250
|
+
return function () {
|
|
32251
|
+
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : createInitialState(formConfig);
|
|
32252
|
+
var action = arguments.length > 1 ? arguments[1] : undefined;
|
|
32253
|
+
|
|
32254
|
+
switch (action.type) {
|
|
32255
|
+
case SET:
|
|
32256
|
+
var changedFieldName = action.payload.fieldName;
|
|
32257
|
+
var newRawValue = action.payload.value;
|
|
32258
|
+
return produce(state, function (draftState) {
|
|
32259
|
+
var originalValue = draftState[changedFieldName].rawValue;
|
|
32260
|
+
draftState[changedFieldName].rawValue = newRawValue;
|
|
32261
|
+
|
|
32262
|
+
if (computeConstraints(changedFieldName, draftState).length > 0) {
|
|
32263
|
+
// If the change violates constraints, revert the change
|
|
32264
|
+
draftState[changedFieldName].rawValue = originalValue;
|
|
32265
|
+
return draftState;
|
|
32266
|
+
}
|
|
32267
|
+
|
|
32268
|
+
var fields = Object.entries(draftState);
|
|
32269
|
+
|
|
32270
|
+
for (var _i3 = 0, _fields = fields; _i3 < _fields.length; _i3++) {
|
|
32271
|
+
var entry = _fields[_i3];
|
|
32272
|
+
var fieldName = entry[0];
|
|
32273
|
+
var field = entry[1];
|
|
32274
|
+
var errors = computeErrors(fieldName, draftState);
|
|
32275
|
+
var dirty = fieldName === changedFieldName ? true : field.dirty;
|
|
32276
|
+
draftState[fieldName].errors = errors;
|
|
32277
|
+
draftState[fieldName].dirty = dirty;
|
|
32278
|
+
draftState[fieldName].hasErrors = errors.length > 0;
|
|
32279
|
+
}
|
|
32280
|
+
});
|
|
32281
|
+
|
|
32282
|
+
case CLEAR:
|
|
32283
|
+
return createInitialState(formConfig);
|
|
32284
|
+
|
|
32285
|
+
default:
|
|
32286
|
+
return state;
|
|
32287
|
+
}
|
|
32288
|
+
};
|
|
32073
32289
|
};
|
|
32074
32290
|
|
|
32075
|
-
|
|
32291
|
+
var createMapDispatchToProps = function createMapDispatchToProps(formConfig) {
|
|
32076
32292
|
// Do memo-ization
|
|
32077
|
-
|
|
32078
|
-
|
|
32079
|
-
return dispatch
|
|
32293
|
+
var cachedDispatch;
|
|
32294
|
+
var cacheValue;
|
|
32295
|
+
return function (dispatch) {
|
|
32080
32296
|
if (dispatch == cachedDispatch) {
|
|
32081
32297
|
return cacheValue;
|
|
32082
32298
|
}
|
|
32083
|
-
|
|
32299
|
+
|
|
32300
|
+
var dispatchObj = {};
|
|
32084
32301
|
dispatchObj.fields = {};
|
|
32085
|
-
|
|
32086
|
-
|
|
32302
|
+
var keys = Object.keys(formConfig);
|
|
32303
|
+
|
|
32304
|
+
var _loop = function _loop() {
|
|
32305
|
+
var fieldName = _keys[_i4];
|
|
32087
32306
|
dispatchObj.fields[fieldName] = {
|
|
32088
|
-
set:
|
|
32307
|
+
set: function set(value) {
|
|
32308
|
+
return dispatch(set$2(fieldName)(value));
|
|
32309
|
+
}
|
|
32089
32310
|
};
|
|
32311
|
+
};
|
|
32312
|
+
|
|
32313
|
+
for (var _i4 = 0, _keys = keys; _i4 < _keys.length; _i4++) {
|
|
32314
|
+
_loop();
|
|
32090
32315
|
}
|
|
32091
|
-
|
|
32316
|
+
|
|
32317
|
+
dispatchObj.form = {
|
|
32318
|
+
clear: function clear() {
|
|
32319
|
+
return dispatch(_clear());
|
|
32320
|
+
}
|
|
32321
|
+
};
|
|
32092
32322
|
cachedDispatch = dispatch;
|
|
32093
|
-
cacheValue = {
|
|
32323
|
+
cacheValue = {
|
|
32324
|
+
actions: dispatchObj
|
|
32325
|
+
};
|
|
32094
32326
|
return cacheValue;
|
|
32095
32327
|
};
|
|
32096
32328
|
};
|
|
32097
32329
|
|
|
32098
|
-
|
|
32330
|
+
var mapStateToProps = function mapStateToProps(state) {
|
|
32331
|
+
return {
|
|
32332
|
+
fields: state
|
|
32333
|
+
};
|
|
32334
|
+
};
|
|
32099
32335
|
|
|
32100
|
-
|
|
32101
|
-
|
|
32102
|
-
|
|
32103
|
-
|
|
32104
|
-
|
|
32336
|
+
var createFormState = function createFormState(formConfig) {
|
|
32337
|
+
return {
|
|
32338
|
+
reducer: createFormReducer(formConfig),
|
|
32339
|
+
mapDispatchToProps: createMapDispatchToProps(formConfig),
|
|
32340
|
+
mapStateToProps: mapStateToProps
|
|
32341
|
+
};
|
|
32342
|
+
};
|
|
32105
32343
|
|
|
32106
32344
|
var formatDelimiter = "_";
|
|
32107
32345
|
var phoneFormats = ["", "_", "__", "(___) ", "(___) _", "(___) __", "(___) ___-", "(___) ___-_", "(___) ___-__", "(___) ___-___", "(___) ___-____"];
|