operation-tree-node
Advanced tools
Comparing version 1.0.5 to 1.0.6
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";function r(r){return!(!Array.isArray(r)||!r.length)}function e(e,n){var t,c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"};!function e(i,o){i.forEach((function(i,u,l){t=i[c.children],!1!==n(i,u,l,o)&&r(t)&&e(t,i)}))}(e,null)}function n(e,n){var t,c=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function e(i,o){return i.map((function(i,u,l){var f=n(i,u,l,o);return r(t=f[c])&&(f[c]=e(t,f)),f}))}(e)}function t(r,e,n){return e in r?Object.defineProperty(r,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[e]=n,r}function c(r,e){var n=Object.keys(r);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(r);e&&(t=t.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.push.apply(n,t)}return n}function i(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?c(n,!0).forEach((function(e){t(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):c(n).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}function o(r){return function(r){if(Array.isArray(r)){for(var e=0,n=new Array(r.length);e<r.length;e++)n[e]=r[e];return n}}(r)||function(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function u(r,e){var n,t=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{parent:"parent"}).parent;r.forEach((function(r){!function r(c){n=c[t];n&&!1!==e(n)&&r(n)}(r)}))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.treeCheck=function(t,c){var o,l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{id:"id",children:"children",parent:"parent"},f=l.children,a=l.id,h=[],d=[],p=function(r){d.push(r[a]),r._checked=!0};return e(n(t,(function(r,e,n,t){return i({},r,{_checked:!1,parent:t})}),l),(function(n){if(n._checked)return!1;c.includes(n[a])&&(p(n),h.push(n),r(o=n[f])&&e(o,(function(r){p(r)}),l))}),l),u(h,(function(r){if(r._checked)return!1;var e=r[f].length;if(1===e)p(r);else{var n=r._checkedCount||0;r._checkedCount=n+1,r._checkedCount===e&&p(r)}}),l),d},exports.treeEach=e,exports.treeEachParent=u,exports.treeFilter=function(e,n){var t,c=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function e(o,u){var l,f,a,h=[];return o.forEach((function(o,d,p){a=!1,l=i({},o),r(t=o[c])&&(f=e(t,l),(a=r(f))?l[c]=f:delete l[c]),(n(o,d,p,u)||a)&&h.push(l)})),h}(e)},exports.treeFind=function(e,n){var t,c,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"},o=null;return function e(u,l){var f,a=u.length;for(f=0;f<a;f++){if(c=u[f],n(c,f,u,l)){o=c;break}if(r(t=c[i.children])&&(c=e(t,c))){o=c;break}}return o}(e,null)},exports.treeMap=n,exports.treeMerge=function(e,n){var t,c,u,l=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function e(f){var a=[];return f.forEach((function(f){var h=a.find((function(r){return n(r,f)}));t=f[l],h?(c=h[l],r(t)&&(r(c)?h[l]=e([].concat(o(c),o(t))):h[l]=e(t))):(u=i({},f),r(t)&&(u[l]=o(t)),a.push(u))})),a}(e)},exports.treeSort=function(e,t){var c,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"},l=u.children;return n(e=o(e).sort(t),(function(e){return c=e[l],e=i({},e),r(c)&&(e[l]=o(e[l]).sort(t)),e}),u)},exports.treeToFlatArray=function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(r){return r},t=arguments.length>2?arguments[2]:void 0,c=[];return e(r,(function(){c.push(n.apply(void 0,arguments))}),t),c}; | ||
"use strict";function r(r){return!(!Array.isArray(r)||!r.length)}function e(e,n){var t,c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"};!function e(i,o){i.forEach((function(i,u,a){t=i[c.children],!1!==n(i,u,a,o)&&r(t)&&e(t,i)}))}(e,null)}function n(e,n){var t,c=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function e(i,o){return i.map((function(i,u,a){var l=n(i,u,a,o);return r(t=l[c])&&(l[c]=e(t,l)),l}))}(e)}function t(r,e,n){return e in r?Object.defineProperty(r,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[e]=n,r}function c(r,e){var n=Object.keys(r);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(r);e&&(t=t.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.push.apply(n,t)}return n}function i(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?c(n,!0).forEach((function(e){t(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):c(n).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}function o(r){return function(r){if(Array.isArray(r)){for(var e=0,n=new Array(r.length);e<r.length;e++)n[e]=r[e];return n}}(r)||function(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function u(r,e){var n,t=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{parent:"parent"}).parent;r.forEach((function(r){!function r(c){n=c[t];n&&!1!==e(n)&&r(n)}(r)}))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.treeCheck=function(t,c){var o,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{id:"id",children:"children",parent:"parent"},l=a.children,f=a.id,h=[],d=[],p=function(r){d.push(r[f]),r._checked=!0};return e(n(t,(function(r,e,n,t){return i({},r,{_checked:!1,parent:t})}),a),(function(n){if(n._checked)return!1;c.includes(n[f])&&(p(n),h.push(n),r(o=n[l])&&e(o,(function(r){p(r)}),a))}),a),u(h,(function(r){if(r._checked)return!1;var e=r[l].length;if(1===e)p(r);else{var n=r._checkedCount||0;r._checkedCount=n+1,r._checkedCount===e&&p(r)}}),a),d},exports.treeEach=e,exports.treeEachParent=u,exports.treeFilter=function(e,n){var t,c=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function e(u,a){var l,f,h,d=[];return u.forEach((function(u,p,s){var v;h=!1,l=(v=u)instanceof Object?i({},v):Array.isArray(v)?o(v):v,r(t=u[c])&&(f=e(t,l),(h=r(f))?l[c]=f:delete l[c]),(n(u,p,s,a)||h)&&d.push(l)})),d}(e)},exports.treeFind=function(e,n){var t,c,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"},o=null;return function e(u,a){var l,f=u.length;for(l=0;l<f;l++){if(c=u[l],n(c,l,u,a)){o=c;break}if(r(t=c[i.children])&&(c=e(t,c))){o=c;break}}return o}(e,null)},exports.treeMap=n,exports.treeMerge=function(e,n){var t,c,u,a=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function e(l){var f=[];return l.forEach((function(l){var h=f.find((function(r){return n(r,l)}));t=l[a],h?(c=h[a],r(t)&&(r(c)?h[a]=e([].concat(o(c),o(t))):h[a]=e(t))):(u=i({},l),r(t)&&(u[a]=o(t)),f.push(u))})),f}(e)},exports.treeSort=function(e,t){var c,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"},a=u.children;return n(e=o(e).sort(t),(function(e){return c=e[a],e=i({},e),r(c)&&(e[a]=o(e[a]).sort(t)),e}),u)},exports.treeToFlatArray=function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(r){return r},t=arguments.length>2?arguments[2]:void 0,c=[];return e(r,(function(){c.push(n.apply(void 0,arguments))}),t),c}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -226,3 +226,3 @@ */ | ||
hasChildren = false; | ||
newItem = _objectSpread2({}, node); | ||
newItem = copy(node); | ||
children = node[propsChildren]; | ||
@@ -248,2 +248,8 @@ | ||
function copy(val) { | ||
return val instanceof Object ? _objectSpread2({}, val) : Array.isArray(val) ? // eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore | ||
_toConsumableArray(val) : val; | ||
} | ||
/** | ||
@@ -250,0 +256,0 @@ * tree to flat array |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";function e(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function n(e,n){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n&&(t=t.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),r.push.apply(r,t)}return r}function r(e){return!(!Array.isArray(e)||!e.length)}function t(e,n){var t,c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"};!function e(i,o){i.forEach((function(i,u,f){t=i[c.children],!1!==n(i,u,f,o)&&r(t)&&e(t,i)}))}(e,null)}function c(e,n){var r,t=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{parent:"parent"}).parent;e.forEach((function(e){!function e(c){r=c[t];r&&!1!==n(r)&&e(r)}(e)}))}module.exports=function(i,o){var u,f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{id:"id",children:"children",parent:"parent"},l=f.children,a=f.id,h=[],d=[],p=function(e){d.push(e[a]),e._checked=!0};return t(function(e,n){var t,c=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function e(i,o){return i.map((function(i,u,f){var l=n(i,u,f,o);return r(t=l[c])&&(l[c]=e(t,l)),l}))}(e)}(i,(function(r,t,c,i){return function(r){for(var t=1;t<arguments.length;t++){var c=null!=arguments[t]?arguments[t]:{};t%2?n(c,!0).forEach((function(n){e(r,n,c[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(c)):n(c).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(c,e))}))}return r}({},r,{_checked:!1,parent:i})}),f),(function(e){if(e._checked)return!1;o.includes(e[a])&&(p(e),h.push(e),r(u=e[l])&&t(u,(function(e){p(e)}),f))}),f),c(h,(function(e){if(e._checked)return!1;var n=e[l].length;if(1===n)p(e);else{var r=e._checkedCount||0;e._checkedCount=r+1,e._checkedCount===n&&p(e)}}),f),d}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";module.exports=function(n,r){var i,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"};!function n(c,e){c.forEach((function(c,l,o){i=c[t.children],!1!==r(c,l,o,e)&&function(n){return!(!Array.isArray(n)||!n.length)}(i)&&n(i,c)}))}(n,null)}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";module.exports=function(n,t){var e,o=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{parent:"parent"}).parent;n.forEach((function(n){!function n(r){e=r[o];e&&!1!==t(e)&&n(e)}(n)}))}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";function e(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function r(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function t(e){return!(!Array.isArray(e)||!e.length)}module.exports=function(n,o){var c,i=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function n(u,f){var l,p,a,b=[];return u.forEach((function(u,s,O){a=!1,l=function(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?r(o,!0).forEach((function(r){e(t,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):r(o).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}({},u),t(c=u[i])&&(p=n(c,l),(a=t(p))?l[i]=p:delete l[i]),(o(u,s,O,f)||a)&&b.push(l)})),b}(n)}; | ||
"use strict";function r(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function e(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.push.apply(t,n)}return t}function t(r){return function(r){if(Array.isArray(r)){for(var e=0,t=new Array(r.length);e<r.length;e++)t[e]=r[e];return t}}(r)||function(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function n(r){return!(!Array.isArray(r)||!r.length)}module.exports=function(o,i){var c,u=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function o(a,f){var l,p,y,b=[];return a.forEach((function(a,s,O){var g;y=!1,l=(g=a)instanceof Object?function(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(o,!0).forEach((function(e){r(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(o).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(o,r))}))}return t}({},g):Array.isArray(g)?t(g):g,n(c=a[u])&&(p=o(c,l),(y=n(p))?l[u]=p:delete l[u]),(i(a,s,O,f)||y)&&b.push(l)})),b}(o)}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -55,2 +55,22 @@ */ | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -88,3 +108,3 @@ function checkValidArray(data) { | ||
hasChildren = false; | ||
newItem = _objectSpread2({}, node); | ||
newItem = copy(node); | ||
children = node[propsChildren]; | ||
@@ -110,2 +130,8 @@ | ||
function copy(val) { | ||
return val instanceof Object ? _objectSpread2({}, val) : Array.isArray(val) ? // eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore | ||
_toConsumableArray(val) : val; | ||
} | ||
export default treeFilter; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";function r(r){return!(!Array.isArray(r)||!r.length)}module.exports=function(n,e){var t,i,l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"},u=null;return function n(c,o){var a,f=c.length;for(a=0;a<f;a++){if(i=c[a],e(i,a,c,o)){u=i;break}if(r(t=i[l.children])&&(i=n(t,i))){u=i;break}}return u}(n,null)}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";module.exports=function(r,n){var t,e=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function r(i,u){return i.map((function(i,c,o){var l=n(i,c,o,u);return function(r){return!(!Array.isArray(r)||!r.length)}(t=l[e])&&(l[e]=r(t,l)),l}))}(r)}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";function r(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function e(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.push.apply(t,n)}return t}function t(r){return function(r){if(Array.isArray(r)){for(var e=0,t=new Array(r.length);e<r.length;e++)t[e]=r[e];return t}}(r)||function(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function n(r){return!(!Array.isArray(r)||!r.length)}module.exports=function(o,c){var i,u,a,f=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function o(l){var p=[];return l.forEach((function(l){var b=p.find((function(r){return c(r,l)}));i=l[f],b?(u=b[f],n(i)&&(n(u)?b[f]=o([].concat(t(u),t(i))):b[f]=o(i))):(a=function(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(o,!0).forEach((function(e){r(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(o).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(o,r))}))}return t}({},l),n(i)&&(a[f]=t(i)),p.push(a))})),p}(o)}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";function r(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function e(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.push.apply(t,n)}return t}function t(r){return function(r){if(Array.isArray(r)){for(var e=0,t=new Array(r.length);e<r.length;e++)t[e]=r[e];return t}}(r)||function(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function n(r){return!(!Array.isArray(r)||!r.length)}module.exports=function(o,i){var c,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"},a=u.children;return function(r,e){var t,o=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"}).children;return function r(i,c){return i.map((function(i,u,a){var f=e(i,u,a,c);return n(t=f[o])&&(f[o]=r(t,f)),f}))}(r)}(o=t(o).sort(i),(function(o){return c=o[a],o=function(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(o,!0).forEach((function(e){r(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(o).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(o,r))}))}return t}({},o),n(c)&&(o[a]=t(o[a]).sort(i)),o}),u)}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
*/ | ||
"use strict";function n(n,r){var t,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:"children"};!function n(o,u){o.forEach((function(o,e,c){t=o[i.children],!1!==r(o,e,c,u)&&function(n){return!(!Array.isArray(n)||!n.length)}(t)&&n(t,o)}))}(n,null)}module.exports=function(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(n){return n},i=arguments.length>2?arguments[2]:void 0,o=[];return n(r,(function(){o.push(t.apply(void 0,arguments))}),i),o}; |
/*! | ||
* operation-tree-node v1.0.5 | ||
* (c) 2019-2019 yujinpan | ||
* operation-tree-node v1.0.6 | ||
* (c) 2019-2020 yujinpan | ||
* Released under the MIT License. | ||
@@ -5,0 +5,0 @@ */ |
{ | ||
"name": "operation-tree-node", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"author": "yujinpan", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.common.js", |
@@ -34,3 +34,3 @@ import { checkValidArray } from './utils/checkValidArray'; | ||
hasChildren = false; | ||
newItem = { ...node }; | ||
newItem = copy(node); | ||
children = node[propsChildren]; | ||
@@ -52,1 +52,11 @@ if (checkValidArray(children)) { | ||
} | ||
function copy<T>(val: T): T { | ||
return val instanceof Object | ||
? { ...val } | ||
: Array.isArray(val) | ||
? // eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore | ||
([...val] as T) | ||
: val; | ||
} |
79945
2036