iglooform 3.1.5 → 3.2.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/.dumi/tmp/dumi/theme/ContextWrapper.tsx +1 -1
- package/es/config-provider.d.ts +13 -0
- package/es/config-provider.js +28 -0
- package/es/form/addable-section/index.js +18 -7
- package/es/form/element/index.d.ts +12 -0
- package/es/form/element/index.js +3 -2
- package/es/form/hsteps/index.js +4 -3
- package/es/form/steps/index.js +3 -2
- package/es/free-form/addable-section/index.js +33 -10
- package/es/free-form/element/index.js +4 -2
- package/es/free-form/step/index.js +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/es/input/amount.js +3 -1
- package/es/locale/locale-provider.d.ts +3 -0
- package/es/locale/locale-provider.js +6 -4
- package/es/media/file-icon.d.ts +9 -0
- package/es/media/preview.js +6 -2
- package/es/modal/index.js +5 -4
- package/es/select/attached-select.d.ts +17 -0
- package/es/types.d.ts +1 -0
- package/es/upload/index.js +16 -15
- package/es/upload-photo/index.js +6 -5
- package/es/upload-preview/media.js +8 -4
- package/es/utils/form-utils.d.ts +3 -2
- package/es/utils/form-utils.js +84 -16
- package/lib/config-provider.d.ts +13 -0
- package/lib/config-provider.js +37 -0
- package/lib/form/addable-section/index.js +18 -7
- package/lib/form/element/index.d.ts +12 -0
- package/lib/form/element/index.js +3 -2
- package/lib/form/hsteps/index.js +4 -3
- package/lib/form/steps/index.js +3 -2
- package/lib/free-form/addable-section/index.js +32 -9
- package/lib/free-form/element/index.js +4 -2
- package/lib/free-form/step/index.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -0
- package/lib/input/amount.js +3 -1
- package/lib/locale/locale-provider.d.ts +3 -0
- package/lib/locale/locale-provider.js +6 -4
- package/lib/media/file-icon.d.ts +9 -0
- package/lib/media/preview.js +6 -2
- package/lib/modal/index.js +5 -4
- package/lib/select/attached-select.d.ts +17 -0
- package/lib/types.d.ts +1 -0
- package/lib/upload/index.js +16 -15
- package/lib/upload-photo/index.js +6 -5
- package/lib/upload-preview/media.js +8 -4
- package/lib/utils/form-utils.d.ts +3 -2
- package/lib/utils/form-utils.js +86 -17
- package/package.json +1 -1
package/lib/utils/form-utils.js
CHANGED
|
@@ -4,14 +4,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.testAssert = exports.getRuleValidation = exports.calcShouldRender = exports.calcSelectValue = exports.calcNamePath = exports.calcFormItemProps = exports.calcDisabled = exports.calcCopyValue = void 0;
|
|
7
|
+
exports.testAssert = exports.getRuleValidation = exports.calcShouldRender = exports.calcSelectValue = exports.calcNamePath = exports.calcFormItemProps = exports.calcDisabled = exports.calcCopyValue = exports.calcAddableSectionAssertField = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
10
10
|
var _typography = _interopRequireDefault(require("../typography"));
|
|
11
11
|
var _formattedMessage = _interopRequireDefault(require("../locale/formatted-message"));
|
|
12
12
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
13
|
+
var _lodash = require("lodash");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
var _excluded = ["type", "name", "required", "requiredAsserts", "showOptional", "rules", "initialValue", "normalize", "mergeRules", "getValueFromEvent", "getValueProps", "extra", "help", "label", "previewLabel", "extraLabel", "copyValue", "selectValue", "span", "halfRow", "fullRow", "valuePropName", "dependencies", "asserts", "messageVariables", "requiredMessage", "previewFormater", "disabled", "ignore", "shouldRender", "valueFormater", "antdDependencies", "dateLimitationType", "absoluteRangeEnd", "absoluteRangeStart", "relativeRangeStart", "relativeRangeEnd", "validationCode", "shouldRenderCode"],
|
|
15
|
+
var _excluded = ["type", "name", "required", "requiredAsserts", "showOptional", "rules", "initialValue", "normalize", "mergeRules", "getValueFromEvent", "getValueProps", "extra", "help", "label", "previewLabel", "extraLabel", "copyValue", "selectValue", "span", "halfRow", "fullRow", "valuePropName", "dependencies", "asserts", "messageVariables", "requiredMessage", "previewFormater", "disabled", "ignore", "shouldRender", "valueFormater", "antdDependencies", "dateLimitationType", "absoluteRangeEnd", "absoluteRangeStart", "relativeRangeStart", "relativeRangeEnd", "validationCode", "shouldRenderCode", "disabledCode"],
|
|
15
16
|
_excluded2 = ["initialValue", "normalize", "rules", "extra", "help", "getValueFromEvent", "span", "valuePropName", "fullRow", "halfRow", "messageVariables", "requiredMessage", "previewFormater", "valueFormater", "required", "requiredMark", "className"];
|
|
16
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
18
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
@@ -179,6 +180,7 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
179
180
|
_config$validationCod = config.validationCode,
|
|
180
181
|
validationCode = _config$validationCod === void 0 ? [] : _config$validationCod,
|
|
181
182
|
shouldRenderCode = config.shouldRenderCode,
|
|
183
|
+
disabledCode = config.disabledCode,
|
|
182
184
|
rest = _objectWithoutProperties(config, _excluded);
|
|
183
185
|
(0, _invariant.default)(nameProp !== undefined || type === 'Divider' || type === 'Section' || type === 'Typography' || type === 'OCR' || !type, "name property is required for form item config (type: ".concat(type, ")"));
|
|
184
186
|
(0, _invariant.default)(!previewFormater || typeof previewFormater === 'function', 'previewFormater property should be a function');
|
|
@@ -230,7 +232,7 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
230
232
|
Object.keys(_objectSpread(_objectSpread({}, extraRest), rest)).forEach(function (key) {
|
|
231
233
|
elementProps[key.replace('element-', '')] = rest[key];
|
|
232
234
|
});
|
|
233
|
-
elementProps.disabled = calcDisabled(disabled, form) || copiedValue.disabled || selectedValue.disabled;
|
|
235
|
+
elementProps.disabled = calcDisabled(disabled, form, disabledCode, name, parentName) || copiedValue.disabled || selectedValue.disabled;
|
|
234
236
|
if (dateLimitationType) {
|
|
235
237
|
var rangeStart;
|
|
236
238
|
var rangeEnd;
|
|
@@ -311,8 +313,12 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
311
313
|
var fn = eval(code);
|
|
312
314
|
var formValues = form === null || form === void 0 ? void 0 : form.getFieldsValue(true);
|
|
313
315
|
var _result2 = fn(value, formValues, {
|
|
314
|
-
moment: _dayjs.default
|
|
315
|
-
|
|
316
|
+
moment: _dayjs.default,
|
|
317
|
+
get: _lodash.get
|
|
318
|
+
}, _objectSpread({
|
|
319
|
+
name: name,
|
|
320
|
+
parentName: parentName
|
|
321
|
+
}, validationCodeExtraParams));
|
|
316
322
|
return _result2 ? Promise.resolve() : Promise.reject(errorMessage);
|
|
317
323
|
} catch (_unused) {
|
|
318
324
|
return Promise.reject(errorMessage);
|
|
@@ -374,13 +380,32 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
374
380
|
dependencies: antdDependencies
|
|
375
381
|
},
|
|
376
382
|
elementProps: elementProps,
|
|
377
|
-
display: !ignore && calcShouldRender(name, dependencies, asserts, shouldRender, shouldRenderCode, form),
|
|
383
|
+
display: !ignore && calcShouldRender(name, parentName, dependencies, asserts, shouldRender, shouldRenderCode, form),
|
|
378
384
|
previewFormater: previewFormater || extraPreviewFormater
|
|
379
385
|
};
|
|
380
386
|
};
|
|
381
387
|
exports.calcFormItemProps = calcFormItemProps;
|
|
382
|
-
var calcDisabled = function calcDisabled(disabled, form) {
|
|
383
|
-
if (!form
|
|
388
|
+
var calcDisabled = function calcDisabled(disabled, form, disabledCode, name, parentName) {
|
|
389
|
+
if (!form) return false;
|
|
390
|
+
if (disabledCode) {
|
|
391
|
+
var fn = eval(disabledCode);
|
|
392
|
+
if (typeof fn === 'function') {
|
|
393
|
+
try {
|
|
394
|
+
var value = form.getFieldValue(name);
|
|
395
|
+
var values = form.getFieldsValue(true);
|
|
396
|
+
return fn(value, values, {
|
|
397
|
+
moment: _dayjs.default,
|
|
398
|
+
get: _lodash.get
|
|
399
|
+
}, {
|
|
400
|
+
name: name,
|
|
401
|
+
parentName: parentName
|
|
402
|
+
});
|
|
403
|
+
} catch (_unused2) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (!disabled) return false;
|
|
384
409
|
if (typeof disabled === 'boolean') return disabled;
|
|
385
410
|
if (Array.isArray(disabled)) {
|
|
386
411
|
var _iterator = _createForOfIteratorHelper(disabled),
|
|
@@ -455,12 +480,12 @@ var calcSelectValue = function calcSelectValue(selectValue, form) {
|
|
|
455
480
|
};
|
|
456
481
|
};
|
|
457
482
|
exports.calcSelectValue = calcSelectValue;
|
|
458
|
-
var calcShouldRender = function calcShouldRender(name) {
|
|
459
|
-
var dependencies = arguments.length >
|
|
460
|
-
var asserts = arguments.length >
|
|
461
|
-
var shouldRender = arguments.length >
|
|
462
|
-
var shouldRenderCode = arguments.length >
|
|
463
|
-
var form = arguments.length >
|
|
483
|
+
var calcShouldRender = function calcShouldRender(name, parentName) {
|
|
484
|
+
var dependencies = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
485
|
+
var asserts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
486
|
+
var shouldRender = arguments.length > 4 ? arguments[4] : undefined;
|
|
487
|
+
var shouldRenderCode = arguments.length > 5 ? arguments[5] : undefined;
|
|
488
|
+
var form = arguments.length > 6 ? arguments[6] : undefined;
|
|
464
489
|
if (!form) return true;
|
|
465
490
|
var _iterator3 = _createForOfIteratorHelper(dependencies),
|
|
466
491
|
_step3;
|
|
@@ -486,9 +511,13 @@ var calcShouldRender = function calcShouldRender(name) {
|
|
|
486
511
|
var value = form.getFieldValue(name);
|
|
487
512
|
var values = form.getFieldsValue(true);
|
|
488
513
|
return fn(value, values, {
|
|
489
|
-
moment: _dayjs.default
|
|
514
|
+
moment: _dayjs.default,
|
|
515
|
+
get: _lodash.get
|
|
516
|
+
}, {
|
|
517
|
+
name: name,
|
|
518
|
+
parentName: parentName
|
|
490
519
|
});
|
|
491
|
-
} catch (
|
|
520
|
+
} catch (_unused3) {
|
|
492
521
|
return false;
|
|
493
522
|
}
|
|
494
523
|
}
|
|
@@ -570,4 +599,44 @@ var getRuleValidation = /*#__PURE__*/function () {
|
|
|
570
599
|
return _ref3.apply(this, arguments);
|
|
571
600
|
};
|
|
572
601
|
}();
|
|
573
|
-
exports.getRuleValidation = getRuleValidation;
|
|
602
|
+
exports.getRuleValidation = getRuleValidation;
|
|
603
|
+
var isAddableSectionInnerField = function isAddableSectionInnerField(name, field, elements) {
|
|
604
|
+
var start = 0;
|
|
605
|
+
var hit = false;
|
|
606
|
+
while (start < name.length && start < field.length) {
|
|
607
|
+
if (name[start] === field[start]) {
|
|
608
|
+
hit = true;
|
|
609
|
+
start++;
|
|
610
|
+
} else {
|
|
611
|
+
if (hit) return false;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (start === name.length) return true;
|
|
616
|
+
var restField = field.slice(start);
|
|
617
|
+
var _elements = elements;
|
|
618
|
+
var index = 0;
|
|
619
|
+
var isReactElement = elements.some(_react.default.isValidElement);
|
|
620
|
+
while (index < restField.length) {
|
|
621
|
+
var found = _elements.find(function (item) {
|
|
622
|
+
return (isReactElement ? item.props.name : item.name).toString() === restField[index];
|
|
623
|
+
});
|
|
624
|
+
if (!found) return false;
|
|
625
|
+
index++;
|
|
626
|
+
_elements = (isReactElement ? found.props.children : found.elements) || [];
|
|
627
|
+
}
|
|
628
|
+
return true;
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
// 暂时不考虑AddableSection嵌套的场景
|
|
632
|
+
var calcAddableSectionAssertField = function calcAddableSectionAssertField(name, field, index, elements) {
|
|
633
|
+
var _field = typeof field === 'string' ? field.split('.') : field;
|
|
634
|
+
if (!isAddableSectionInnerField(name, _field, elements)) return field;
|
|
635
|
+
if (!_field.join().startsWith(name.join())) return [].concat(_toConsumableArray(name), [index], _toConsumableArray(_field));
|
|
636
|
+
var _index = _field.findIndex(function (item) {
|
|
637
|
+
return item === name[name.length - 1];
|
|
638
|
+
});
|
|
639
|
+
if (_index === -1) return field;
|
|
640
|
+
return [].concat(_toConsumableArray(name), [index], _toConsumableArray(_field.slice(_index + 1)));
|
|
641
|
+
};
|
|
642
|
+
exports.calcAddableSectionAssertField = calcAddableSectionAssertField;
|