Latest updates from IceHrmPro
This commit is contained in:
20
web/node_modules/rc-field-form/lib/utils/NameMap.d.ts
generated
vendored
Normal file
20
web/node_modules/rc-field-form/lib/utils/NameMap.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { InternalNamePath } from '../interface';
|
||||
interface KV<T> {
|
||||
key: InternalNamePath;
|
||||
value: T;
|
||||
}
|
||||
/**
|
||||
* NameMap like a `Map` but accepts `string[]` as key.
|
||||
*/
|
||||
declare class NameMap<T> {
|
||||
private list;
|
||||
set(key: InternalNamePath, value: T): void;
|
||||
get(key: InternalNamePath): T;
|
||||
update(key: InternalNamePath, updater: (origin: T) => T | null): void;
|
||||
delete(key: InternalNamePath): void;
|
||||
map<U>(callback: (kv: KV<T>) => U): U[];
|
||||
toJSON(): {
|
||||
[name: string]: T;
|
||||
};
|
||||
}
|
||||
export default NameMap;
|
||||
90
web/node_modules/rc-field-form/lib/utils/NameMap.js
generated
vendored
Normal file
90
web/node_modules/rc-field-form/lib/utils/NameMap.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
||||
|
||||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
||||
|
||||
var _valueUtil = require("./valueUtil");
|
||||
|
||||
/**
|
||||
* NameMap like a `Map` but accepts `string[]` as key.
|
||||
*/
|
||||
var NameMap = /*#__PURE__*/function () {
|
||||
function NameMap() {
|
||||
(0, _classCallCheck2.default)(this, NameMap);
|
||||
this.list = [];
|
||||
}
|
||||
|
||||
(0, _createClass2.default)(NameMap, [{
|
||||
key: "set",
|
||||
value: function set(key, value) {
|
||||
var index = this.list.findIndex(function (item) {
|
||||
return (0, _valueUtil.matchNamePath)(item.key, key);
|
||||
});
|
||||
|
||||
if (index !== -1) {
|
||||
this.list[index].value = value;
|
||||
} else {
|
||||
this.list.push({
|
||||
key: key,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "get",
|
||||
value: function get(key) {
|
||||
var result = this.list.find(function (item) {
|
||||
return (0, _valueUtil.matchNamePath)(item.key, key);
|
||||
});
|
||||
return result && result.value;
|
||||
}
|
||||
}, {
|
||||
key: "update",
|
||||
value: function update(key, updater) {
|
||||
var origin = this.get(key);
|
||||
var next = updater(origin);
|
||||
|
||||
if (!next) {
|
||||
this.delete(key);
|
||||
} else {
|
||||
this.set(key, next);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "delete",
|
||||
value: function _delete(key) {
|
||||
this.list = this.list.filter(function (item) {
|
||||
return !(0, _valueUtil.matchNamePath)(item.key, key);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "map",
|
||||
value: function map(callback) {
|
||||
return this.list.map(callback);
|
||||
}
|
||||
}, {
|
||||
key: "toJSON",
|
||||
value: function toJSON() {
|
||||
var json = {};
|
||||
this.map(function (_ref) {
|
||||
var key = _ref.key,
|
||||
value = _ref.value;
|
||||
json[key.join('.')] = value;
|
||||
return null;
|
||||
});
|
||||
return json;
|
||||
}
|
||||
}]);
|
||||
return NameMap;
|
||||
}();
|
||||
|
||||
var _default = NameMap;
|
||||
exports.default = _default;
|
||||
2
web/node_modules/rc-field-form/lib/utils/asyncUtil.d.ts
generated
vendored
Normal file
2
web/node_modules/rc-field-form/lib/utils/asyncUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { FieldError } from '../interface';
|
||||
export declare function allPromiseFinish(promiseList: Promise<FieldError>[]): Promise<FieldError[]>;
|
||||
38
web/node_modules/rc-field-form/lib/utils/asyncUtil.js
generated
vendored
Normal file
38
web/node_modules/rc-field-form/lib/utils/asyncUtil.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.allPromiseFinish = allPromiseFinish;
|
||||
|
||||
function allPromiseFinish(promiseList) {
|
||||
var hasError = false;
|
||||
var count = promiseList.length;
|
||||
var results = [];
|
||||
|
||||
if (!promiseList.length) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
promiseList.forEach(function (promise, index) {
|
||||
promise.catch(function (e) {
|
||||
hasError = true;
|
||||
return e;
|
||||
}).then(function (result) {
|
||||
count -= 1;
|
||||
results[index] = result;
|
||||
|
||||
if (count > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
reject(results);
|
||||
}
|
||||
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
47
web/node_modules/rc-field-form/lib/utils/messages.d.ts
generated
vendored
Normal file
47
web/node_modules/rc-field-form/lib/utils/messages.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
export declare const defaultValidateMessages: {
|
||||
default: string;
|
||||
required: string;
|
||||
enum: string;
|
||||
whitespace: string;
|
||||
date: {
|
||||
format: string;
|
||||
parse: string;
|
||||
invalid: string;
|
||||
};
|
||||
types: {
|
||||
string: string;
|
||||
method: string;
|
||||
array: string;
|
||||
object: string;
|
||||
number: string;
|
||||
date: string;
|
||||
boolean: string;
|
||||
integer: string;
|
||||
float: string;
|
||||
regexp: string;
|
||||
email: string;
|
||||
url: string;
|
||||
hex: string;
|
||||
};
|
||||
string: {
|
||||
len: string;
|
||||
min: string;
|
||||
max: string;
|
||||
range: string;
|
||||
};
|
||||
number: {
|
||||
len: string;
|
||||
min: string;
|
||||
max: string;
|
||||
range: string;
|
||||
};
|
||||
array: {
|
||||
len: string;
|
||||
min: string;
|
||||
max: string;
|
||||
range: string;
|
||||
};
|
||||
pattern: {
|
||||
mismatch: string;
|
||||
};
|
||||
};
|
||||
55
web/node_modules/rc-field-form/lib/utils/messages.js
generated
vendored
Normal file
55
web/node_modules/rc-field-form/lib/utils/messages.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.defaultValidateMessages = void 0;
|
||||
var typeTemplate = "'${name}' is not a valid ${type}";
|
||||
var defaultValidateMessages = {
|
||||
default: "Validation error on field '${name}'",
|
||||
required: "'${name}' is required",
|
||||
enum: "'${name}' must be one of [${enum}]",
|
||||
whitespace: "'${name}' cannot be empty",
|
||||
date: {
|
||||
format: "'${name}' is invalid for format date",
|
||||
parse: "'${name}' could not be parsed as date",
|
||||
invalid: "'${name}' is invalid date"
|
||||
},
|
||||
types: {
|
||||
string: typeTemplate,
|
||||
method: typeTemplate,
|
||||
array: typeTemplate,
|
||||
object: typeTemplate,
|
||||
number: typeTemplate,
|
||||
date: typeTemplate,
|
||||
boolean: typeTemplate,
|
||||
integer: typeTemplate,
|
||||
float: typeTemplate,
|
||||
regexp: typeTemplate,
|
||||
email: typeTemplate,
|
||||
url: typeTemplate,
|
||||
hex: typeTemplate
|
||||
},
|
||||
string: {
|
||||
len: "'${name}' must be exactly ${len} characters",
|
||||
min: "'${name}' must be at least ${min} characters",
|
||||
max: "'${name}' cannot be longer than ${max} characters",
|
||||
range: "'${name}' must be between ${min} and ${max} characters"
|
||||
},
|
||||
number: {
|
||||
len: "'${name}' must equal ${len}",
|
||||
min: "'${name}' cannot be less than ${min}",
|
||||
max: "'${name}' cannot be greater than ${max}",
|
||||
range: "'${name}' must be between ${min} and ${max}"
|
||||
},
|
||||
array: {
|
||||
len: "'${name}' must be exactly ${len} in length",
|
||||
min: "'${name}' cannot be less than ${min} in length",
|
||||
max: "'${name}' cannot be greater than ${max} in length",
|
||||
range: "'${name}' must be between ${min} and ${max} in length"
|
||||
},
|
||||
pattern: {
|
||||
mismatch: "'${name}' does not match pattern ${pattern}"
|
||||
}
|
||||
};
|
||||
exports.defaultValidateMessages = defaultValidateMessages;
|
||||
1
web/node_modules/rc-field-form/lib/utils/typeUtil.d.ts
generated
vendored
Normal file
1
web/node_modules/rc-field-form/lib/utils/typeUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function toArray<T>(value?: T | T[] | null): T[];
|
||||
14
web/node_modules/rc-field-form/lib/utils/typeUtil.js
generated
vendored
Normal file
14
web/node_modules/rc-field-form/lib/utils/typeUtil.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.toArray = toArray;
|
||||
|
||||
function toArray(value) {
|
||||
if (value === undefined || value === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.isArray(value) ? value : [value];
|
||||
}
|
||||
6
web/node_modules/rc-field-form/lib/utils/validateUtil.d.ts
generated
vendored
Normal file
6
web/node_modules/rc-field-form/lib/utils/validateUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { InternalNamePath, ValidateOptions, RuleObject, StoreValue } from '../interface';
|
||||
/**
|
||||
* We use `async-validator` to validate the value.
|
||||
* But only check one value in a time to avoid namePath validate issue.
|
||||
*/
|
||||
export declare function validateRules(namePath: InternalNamePath, value: StoreValue, rules: RuleObject[], options: ValidateOptions, validateFirst: boolean, messageVariables?: Record<string, string>): Promise<string[]>;
|
||||
306
web/node_modules/rc-field-form/lib/utils/validateUtil.js
generated
vendored
Normal file
306
web/node_modules/rc-field-form/lib/utils/validateUtil.js
generated
vendored
Normal file
@@ -0,0 +1,306 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.validateRules = validateRules;
|
||||
|
||||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
||||
|
||||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
||||
|
||||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
||||
|
||||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
||||
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
|
||||
var _asyncValidator = _interopRequireDefault(require("async-validator"));
|
||||
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
|
||||
var _warning = _interopRequireDefault(require("warning"));
|
||||
|
||||
var _valueUtil = require("./valueUtil");
|
||||
|
||||
var _messages = require("./messages");
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
// Remove incorrect original ts define
|
||||
var AsyncValidator = _asyncValidator.default;
|
||||
/**
|
||||
* Replace with template.
|
||||
* `I'm ${name}` + { name: 'bamboo' } = I'm bamboo
|
||||
*/
|
||||
|
||||
function replaceMessage(template, kv) {
|
||||
return template.replace(/\$\{\w+\}/g, function (str) {
|
||||
var key = str.slice(2, -1);
|
||||
return kv[key];
|
||||
});
|
||||
}
|
||||
/**
|
||||
* We use `async-validator` to validate rules. So have to hot replace the message with validator.
|
||||
* { required: '${name} is required' } => { required: () => 'field is required' }
|
||||
*/
|
||||
|
||||
|
||||
function convertMessages(messages, name, rule, messageVariables) {
|
||||
var kv = _objectSpread({}, rule, {
|
||||
name: name,
|
||||
enum: (rule.enum || []).join(', ')
|
||||
});
|
||||
|
||||
var replaceFunc = function replaceFunc(template, additionalKV) {
|
||||
return function () {
|
||||
return replaceMessage(template, _objectSpread({}, kv, {}, additionalKV));
|
||||
};
|
||||
};
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
||||
|
||||
function fillTemplate(source) {
|
||||
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
Object.keys(source).forEach(function (ruleName) {
|
||||
var value = source[ruleName];
|
||||
|
||||
if (typeof value === 'string') {
|
||||
target[ruleName] = replaceFunc(value, messageVariables);
|
||||
} else if (value && (0, _typeof2.default)(value) === 'object') {
|
||||
target[ruleName] = {};
|
||||
fillTemplate(value, target[ruleName]);
|
||||
} else {
|
||||
target[ruleName] = value;
|
||||
}
|
||||
});
|
||||
return target;
|
||||
}
|
||||
/* eslint-enable */
|
||||
|
||||
|
||||
return fillTemplate((0, _valueUtil.setValues)({}, _messages.defaultValidateMessages, messages));
|
||||
}
|
||||
|
||||
function validateRule(_x, _x2, _x3, _x4, _x5) {
|
||||
return _validateRule.apply(this, arguments);
|
||||
}
|
||||
/**
|
||||
* We use `async-validator` to validate the value.
|
||||
* But only check one value in a time to avoid namePath validate issue.
|
||||
*/
|
||||
|
||||
|
||||
function _validateRule() {
|
||||
_validateRule = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(name, value, rule, options, messageVariables) {
|
||||
var cloneRule, subRuleField, validator, messages, result, subResults;
|
||||
return _regenerator.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
cloneRule = _objectSpread({}, rule); // We should special handle array validate
|
||||
|
||||
subRuleField = null;
|
||||
|
||||
if (cloneRule && cloneRule.type === 'array' && cloneRule.defaultField) {
|
||||
subRuleField = cloneRule.defaultField;
|
||||
delete cloneRule.defaultField;
|
||||
}
|
||||
|
||||
validator = new AsyncValidator((0, _defineProperty2.default)({}, name, [cloneRule]));
|
||||
messages = convertMessages(options.validateMessages, name, cloneRule, messageVariables);
|
||||
validator.messages(messages);
|
||||
result = [];
|
||||
_context.prev = 7;
|
||||
_context.next = 10;
|
||||
return Promise.resolve(validator.validate((0, _defineProperty2.default)({}, name, value), _objectSpread({}, options)));
|
||||
|
||||
case 10:
|
||||
_context.next = 15;
|
||||
break;
|
||||
|
||||
case 12:
|
||||
_context.prev = 12;
|
||||
_context.t0 = _context["catch"](7);
|
||||
|
||||
if (_context.t0.errors) {
|
||||
result = _context.t0.errors.map(function (_ref2, index) {
|
||||
var message = _ref2.message;
|
||||
return (// Wrap ReactNode with `key`
|
||||
React.isValidElement(message) ? React.cloneElement(message, {
|
||||
key: "error_".concat(index)
|
||||
}) : message
|
||||
);
|
||||
});
|
||||
} else {
|
||||
console.error(_context.t0);
|
||||
result = [messages.default()];
|
||||
}
|
||||
|
||||
case 15:
|
||||
if (!(!result.length && subRuleField)) {
|
||||
_context.next = 20;
|
||||
break;
|
||||
}
|
||||
|
||||
_context.next = 18;
|
||||
return Promise.all(value.map(function (subValue, i) {
|
||||
return validateRule("".concat(name, ".").concat(i), subValue, subRuleField, options, messageVariables);
|
||||
}));
|
||||
|
||||
case 18:
|
||||
subResults = _context.sent;
|
||||
return _context.abrupt("return", subResults.reduce(function (prev, errors) {
|
||||
return [].concat((0, _toConsumableArray2.default)(prev), (0, _toConsumableArray2.default)(errors));
|
||||
}, []));
|
||||
|
||||
case 20:
|
||||
return _context.abrupt("return", result);
|
||||
|
||||
case 21:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, null, [[7, 12]]);
|
||||
}));
|
||||
return _validateRule.apply(this, arguments);
|
||||
}
|
||||
|
||||
function validateRules(namePath, value, rules, options, validateFirst, messageVariables) {
|
||||
var name = namePath.join('.'); // Fill rule with context
|
||||
|
||||
var filledRules = rules.map(function (currentRule) {
|
||||
var originValidatorFunc = currentRule.validator;
|
||||
|
||||
if (!originValidatorFunc) {
|
||||
return currentRule;
|
||||
}
|
||||
|
||||
return _objectSpread({}, currentRule, {
|
||||
validator: function validator(rule, val, callback) {
|
||||
var hasPromise = false; // Wrap callback only accept when promise not provided
|
||||
|
||||
var wrappedCallback = function wrappedCallback() {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
// Wait a tick to make sure return type is a promise
|
||||
Promise.resolve().then(function () {
|
||||
(0, _warning.default)(!hasPromise, 'Your validator function has already return a promise. `callback` will be ignored.');
|
||||
|
||||
if (!hasPromise) {
|
||||
callback.apply(void 0, args);
|
||||
}
|
||||
});
|
||||
}; // Get promise
|
||||
|
||||
|
||||
var promise = originValidatorFunc(rule, val, wrappedCallback);
|
||||
hasPromise = promise && typeof promise.then === 'function' && typeof promise.catch === 'function';
|
||||
/**
|
||||
* 1. Use promise as the first priority.
|
||||
* 2. If promise not exist, use callback with warning instead
|
||||
*/
|
||||
|
||||
(0, _warning.default)(hasPromise, '`callback` is deprecated. Please return a promise instead.');
|
||||
|
||||
if (hasPromise) {
|
||||
promise.then(function () {
|
||||
callback();
|
||||
}).catch(function (err) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
var rulePromises = filledRules.map(function (rule) {
|
||||
return validateRule(name, value, rule, options, messageVariables);
|
||||
});
|
||||
var summaryPromise = (validateFirst ? finishOnFirstFailed(rulePromises) : finishOnAllFailed(rulePromises)).then(function (errors) {
|
||||
if (!errors.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Promise.reject(errors);
|
||||
}); // Internal catch error to avoid console error log.
|
||||
|
||||
summaryPromise.catch(function (e) {
|
||||
return e;
|
||||
});
|
||||
return summaryPromise;
|
||||
}
|
||||
|
||||
function finishOnAllFailed(_x6) {
|
||||
return _finishOnAllFailed.apply(this, arguments);
|
||||
}
|
||||
|
||||
function _finishOnAllFailed() {
|
||||
_finishOnAllFailed = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(rulePromises) {
|
||||
return _regenerator.default.wrap(function _callee2$(_context2) {
|
||||
while (1) {
|
||||
switch (_context2.prev = _context2.next) {
|
||||
case 0:
|
||||
return _context2.abrupt("return", Promise.all(rulePromises).then(function (errorsList) {
|
||||
var _ref3;
|
||||
|
||||
var errors = (_ref3 = []).concat.apply(_ref3, (0, _toConsumableArray2.default)(errorsList));
|
||||
|
||||
return errors;
|
||||
}));
|
||||
|
||||
case 1:
|
||||
case "end":
|
||||
return _context2.stop();
|
||||
}
|
||||
}
|
||||
}, _callee2);
|
||||
}));
|
||||
return _finishOnAllFailed.apply(this, arguments);
|
||||
}
|
||||
|
||||
function finishOnFirstFailed(_x7) {
|
||||
return _finishOnFirstFailed.apply(this, arguments);
|
||||
}
|
||||
|
||||
function _finishOnFirstFailed() {
|
||||
_finishOnFirstFailed = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(rulePromises) {
|
||||
var count;
|
||||
return _regenerator.default.wrap(function _callee3$(_context3) {
|
||||
while (1) {
|
||||
switch (_context3.prev = _context3.next) {
|
||||
case 0:
|
||||
count = 0;
|
||||
return _context3.abrupt("return", new Promise(function (resolve) {
|
||||
rulePromises.forEach(function (promise) {
|
||||
promise.then(function (errors) {
|
||||
if (errors.length) {
|
||||
resolve(errors);
|
||||
}
|
||||
|
||||
count += 1;
|
||||
|
||||
if (count === rulePromises.length) {
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
case 2:
|
||||
case "end":
|
||||
return _context3.stop();
|
||||
}
|
||||
}
|
||||
}, _callee3);
|
||||
}));
|
||||
return _finishOnFirstFailed.apply(this, arguments);
|
||||
}
|
||||
30
web/node_modules/rc-field-form/lib/utils/valueUtil.d.ts
generated
vendored
Normal file
30
web/node_modules/rc-field-form/lib/utils/valueUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { InternalNamePath, NamePath, Store, StoreValue, EventArgs } from '../interface';
|
||||
/**
|
||||
* Convert name to internal supported format.
|
||||
* This function should keep since we still thinking if need support like `a.b.c` format.
|
||||
* 'a' => ['a']
|
||||
* 123 => [123]
|
||||
* ['a', 123] => ['a', 123]
|
||||
*/
|
||||
export declare function getNamePath(path: NamePath | null): InternalNamePath;
|
||||
export declare function getValue(store: Store, namePath: InternalNamePath): any;
|
||||
export declare function setValue(store: Store, namePath: InternalNamePath, value: StoreValue): Store;
|
||||
export declare function cloneByNamePathList(store: Store, namePathList: InternalNamePath[]): Store;
|
||||
export declare function containsNamePath(namePathList: InternalNamePath[], namePath: InternalNamePath): boolean;
|
||||
export declare function setValues<T>(store: T, ...restValues: T[]): T;
|
||||
export declare function matchNamePath(namePath: InternalNamePath, changedNamePath: InternalNamePath | null): boolean;
|
||||
declare type SimilarObject = string | number | {};
|
||||
export declare function isSimilar(source: SimilarObject, target: SimilarObject): boolean;
|
||||
export declare function defaultGetValueFromEvent(valuePropName: string, ...args: EventArgs): any;
|
||||
/**
|
||||
* Moves an array item from one position in an array to another.
|
||||
*
|
||||
* Note: This is a pure function so a new array will be returned, instead
|
||||
* of altering the array argument.
|
||||
*
|
||||
* @param array Array in which to move an item. (required)
|
||||
* @param moveIndex The index of the item to move. (required)
|
||||
* @param toIndex The index to move item at moveIndex to. (required)
|
||||
*/
|
||||
export declare function move<T>(array: T[], moveIndex: number, toIndex: number): T[];
|
||||
export {};
|
||||
187
web/node_modules/rc-field-form/lib/utils/valueUtil.js
generated
vendored
Normal file
187
web/node_modules/rc-field-form/lib/utils/valueUtil.js
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getNamePath = getNamePath;
|
||||
exports.getValue = getValue;
|
||||
exports.setValue = setValue;
|
||||
exports.cloneByNamePathList = cloneByNamePathList;
|
||||
exports.containsNamePath = containsNamePath;
|
||||
exports.setValues = setValues;
|
||||
exports.matchNamePath = matchNamePath;
|
||||
exports.isSimilar = isSimilar;
|
||||
exports.defaultGetValueFromEvent = defaultGetValueFromEvent;
|
||||
exports.move = move;
|
||||
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
|
||||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
||||
|
||||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
||||
|
||||
var _get = _interopRequireDefault(require("rc-util/lib/utils/get"));
|
||||
|
||||
var _set = _interopRequireDefault(require("rc-util/lib/utils/set"));
|
||||
|
||||
var _typeUtil = require("./typeUtil");
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
/**
|
||||
* Convert name to internal supported format.
|
||||
* This function should keep since we still thinking if need support like `a.b.c` format.
|
||||
* 'a' => ['a']
|
||||
* 123 => [123]
|
||||
* ['a', 123] => ['a', 123]
|
||||
*/
|
||||
function getNamePath(path) {
|
||||
return (0, _typeUtil.toArray)(path);
|
||||
}
|
||||
|
||||
function getValue(store, namePath) {
|
||||
var value = (0, _get.default)(store, namePath);
|
||||
return value;
|
||||
}
|
||||
|
||||
function setValue(store, namePath, value) {
|
||||
var newStore = (0, _set.default)(store, namePath, value);
|
||||
return newStore;
|
||||
}
|
||||
|
||||
function cloneByNamePathList(store, namePathList) {
|
||||
var newStore = {};
|
||||
namePathList.forEach(function (namePath) {
|
||||
var value = getValue(store, namePath);
|
||||
newStore = setValue(newStore, namePath, value);
|
||||
});
|
||||
return newStore;
|
||||
}
|
||||
|
||||
function containsNamePath(namePathList, namePath) {
|
||||
return namePathList && namePathList.some(function (path) {
|
||||
return matchNamePath(path, namePath);
|
||||
});
|
||||
}
|
||||
|
||||
function isObject(obj) {
|
||||
return (0, _typeof2.default)(obj) === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
|
||||
}
|
||||
/**
|
||||
* Copy values into store and return a new values object
|
||||
* ({ a: 1, b: { c: 2 } }, { a: 4, b: { d: 5 } }) => { a: 4, b: { c: 2, d: 5 } }
|
||||
*/
|
||||
|
||||
|
||||
function internalSetValues(store, values) {
|
||||
var newStore = Array.isArray(store) ? (0, _toConsumableArray2.default)(store) : _objectSpread({}, store);
|
||||
|
||||
if (!values) {
|
||||
return newStore;
|
||||
}
|
||||
|
||||
Object.keys(values).forEach(function (key) {
|
||||
var prevValue = newStore[key];
|
||||
var value = values[key]; // If both are object (but target is not array), we use recursion to set deep value
|
||||
|
||||
var recursive = isObject(prevValue) && isObject(value);
|
||||
newStore[key] = recursive ? internalSetValues(prevValue, value || {}) : value;
|
||||
});
|
||||
return newStore;
|
||||
}
|
||||
|
||||
function setValues(store) {
|
||||
for (var _len = arguments.length, restValues = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
restValues[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
return restValues.reduce(function (current, newStore) {
|
||||
return internalSetValues(current, newStore);
|
||||
}, store);
|
||||
}
|
||||
|
||||
function matchNamePath(namePath, changedNamePath) {
|
||||
if (!namePath || !changedNamePath || namePath.length !== changedNamePath.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return namePath.every(function (nameUnit, i) {
|
||||
return changedNamePath[i] === nameUnit;
|
||||
});
|
||||
}
|
||||
|
||||
function isSimilar(source, target) {
|
||||
if (source === target) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!source && target || source && !target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!source || !target || (0, _typeof2.default)(source) !== 'object' || (0, _typeof2.default)(target) !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var sourceKeys = Object.keys(source);
|
||||
var targetKeys = Object.keys(target);
|
||||
var keys = new Set([].concat((0, _toConsumableArray2.default)(sourceKeys), (0, _toConsumableArray2.default)(targetKeys)));
|
||||
return (0, _toConsumableArray2.default)(keys).every(function (key) {
|
||||
var sourceValue = source[key];
|
||||
var targetValue = target[key];
|
||||
|
||||
if (typeof sourceValue === 'function' && typeof targetValue === 'function') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return sourceValue === targetValue;
|
||||
});
|
||||
}
|
||||
|
||||
function defaultGetValueFromEvent(valuePropName) {
|
||||
var event = arguments.length <= 1 ? undefined : arguments[1];
|
||||
|
||||
if (event && event.target && valuePropName in event.target) {
|
||||
return event.target[valuePropName];
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
/**
|
||||
* Moves an array item from one position in an array to another.
|
||||
*
|
||||
* Note: This is a pure function so a new array will be returned, instead
|
||||
* of altering the array argument.
|
||||
*
|
||||
* @param array Array in which to move an item. (required)
|
||||
* @param moveIndex The index of the item to move. (required)
|
||||
* @param toIndex The index to move item at moveIndex to. (required)
|
||||
*/
|
||||
|
||||
|
||||
function move(array, moveIndex, toIndex) {
|
||||
var length = array.length;
|
||||
|
||||
if (moveIndex < 0 || moveIndex >= length || toIndex < 0 || toIndex >= length) {
|
||||
return array;
|
||||
}
|
||||
|
||||
var item = array[moveIndex];
|
||||
var diff = moveIndex - toIndex;
|
||||
|
||||
if (diff > 0) {
|
||||
// move left
|
||||
return [].concat((0, _toConsumableArray2.default)(array.slice(0, toIndex)), [item], (0, _toConsumableArray2.default)(array.slice(toIndex, moveIndex)), (0, _toConsumableArray2.default)(array.slice(moveIndex + 1, length)));
|
||||
}
|
||||
|
||||
if (diff < 0) {
|
||||
// move right
|
||||
return [].concat((0, _toConsumableArray2.default)(array.slice(0, moveIndex)), (0, _toConsumableArray2.default)(array.slice(moveIndex + 1, toIndex + 1)), [item], (0, _toConsumableArray2.default)(array.slice(toIndex + 1, length)));
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
Reference in New Issue
Block a user