@alifd/field
Advanced tools
Comparing version 1.6.6 to 1.6.7
@@ -483,4 +483,6 @@ "use strict"; | ||
var fields = this.getNames(); | ||
// record all old field values | ||
var oldFieldValues = fields.map(function (name) { | ||
// record all old field values, exclude items overwritten by fieldsValue | ||
var oldFieldValues = fields.filter(function (name) { | ||
return !(0, _utils.isOverwritten)(fieldsValue, name); | ||
}).map(function (name) { | ||
return { | ||
@@ -487,0 +489,0 @@ name: name, |
@@ -14,2 +14,3 @@ "use strict"; | ||
exports.hasIn = hasIn; | ||
exports.isOverwritten = isOverwritten; | ||
exports.mapValidateRules = mapValidateRules; | ||
@@ -24,2 +25,5 @@ exports.setIn = setIn; | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
function splitNameToPath(name) { | ||
@@ -138,2 +142,49 @@ return typeof name === 'string' && name ? name.replace(/\[/, '.').replace(/\]/, '').split('.') : ''; | ||
/** | ||
* name是否被覆写 | ||
* e.g. { a: { b: 1 } } and 'a.b', should return true | ||
* e.g. { a: { b: 1 } } and 'a.b.c', should return true | ||
* e.g. { a: { b: 1 } } and 'a.b2', should return false | ||
* e.g. { a: { b: 1 } } and 'a2', should return false | ||
* e.g. { a: { b: [0, 1] } } and 'a.b[0]' return true | ||
* e.g. { a: { b: [0, 1] } } and 'a.b[5]' return true (miss index means overwritten in array) | ||
* @param {object} values 写入对象 | ||
* @param {string} name 字段key | ||
*/ | ||
function isOverwritten(values, name) { | ||
if (!values || (0, _typeof2.default)(values) !== 'object' || !name || typeof name !== 'string') { | ||
return false; | ||
} | ||
var paths = splitNameToPath(name); | ||
var obj = values; | ||
var _iterator = _createForOfIteratorHelper(paths), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var path = _step.value; | ||
if (path in obj) { | ||
var pathValue = obj[path]; | ||
// 任意一层path值不是对象了,则代表被覆盖 | ||
if (!pathValue || (0, _typeof2.default)(pathValue) !== 'object') { | ||
return true; | ||
} else { | ||
obj = pathValue; | ||
} | ||
} else { | ||
// 数组的index已经移除,则代表被覆写 | ||
if (Array.isArray(obj)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
// 代表 name in values,则返回 true | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return true; | ||
} | ||
/** | ||
* 从组件事件中获取数据 | ||
@@ -140,0 +191,0 @@ * @param e Event或者value |
{ | ||
"name": "@alifd/field", | ||
"version": "1.6.6", | ||
"version": "1.6.7", | ||
"description": "Fields can be used to manage data when it comes to form data manipulation and validation. After being associated with a component, the form data can be automatically written back, read, and verified.", | ||
@@ -88,3 +88,3 @@ "files": [ | ||
}, | ||
"homepage": "https://unpkg.com/@alifd/field@1.6.6/build/index.html", | ||
"homepage": "https://unpkg.com/@alifd/field@1.6.7/build/index.html", | ||
"bugs": "https://github.com/alibaba-fusion/field/issues", | ||
@@ -91,0 +91,0 @@ "publishConfig": { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1837211
5487