js-tree-list
Advanced tools
Comparing version 1.1.8 to 1.1.13
@@ -414,7 +414,3 @@ (function (global, factory) { | ||
var tmp = val.splice(n, 1); // 从该元素位置删除元素并将已删除的元素放置于新数组(tmp) | ||
for (var i in val) { | ||
if (val[i][key_id] === findID) { | ||
val.splice(i + 1, 0, tmp[0]); // 在指定ID元素后面添加被删除的元素 | ||
} | ||
} | ||
val.splice(n + 1, 0, tmp[0]); // 在指定ID元素后面添加被删除的元素 | ||
} | ||
@@ -421,0 +417,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n["js-tree-list"]=e()}(this,function(){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},e=function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")},t=function(){function n(n,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}(),r=function(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n},i=function(){function n(t){e(this,n),this.content=t,this.children=[],this.length=0}return t(n,[{key:"get",value:function(n){if(void 0!==this.content[n])return this.content[n]}},{key:"set",value:function(n,e){return!!(this.content[n]=e)}},{key:"add",value:function(e){var t=e instanceof n?e:new n(e);return t.parent=this,this.length++,this.children.push(t),t}},{key:"remove",value:function(n){var e=this.children.findIndex(n);if(e>-1){var t=this.children.splice(e,1);return this.length--,t}return[]}},{key:"sort",value:function(n){return this.children.sort(n)}},{key:"traversal",value:function(n,e){n=n||function(){return!0},this.children.filter(n).forEach(e)}}]),n}(),o=function n(e,t,r,i){var o=t||e.rootNode;if(r(o))return o;for(var u=o.children,l=null,c=0;c<u.length;c++){if(l=n(e,u[c],r))return l}},u=function(){function u(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;e(this,u),this.rootNode=null,n&&(this.rootNode=new i(n))}return t(u,[{key:"get",value:function(n){return this.rootNode.get(n)}},{key:"set",value:function(n,e){this.rootNode.set(n,e)}},{key:"add",value:function(e,t){var r=void 0===e?"undefined":n(e);if("string"===r&&"root"===e)return this.rootNode=new i(t),this;if("function"===r){var u=o(this,null,e);if(u&&u.add(t))return this;console.log("Warning",t)}}},{key:"contains",value:function(n){return o(this,null,n)}},{key:"remove",value:function(n){var e=this.contains(n);return!!e&&!!e.parent.remove(n)}},{key:"move",value:function(n,e){var t=this.contains(n);return!(!t||!this.remove(n))&&!!this.contains(e).add(t)}},{key:"traversal",value:function(n,e){!function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments[2],i=arguments[3],o=t||e.rootNode;t||("function"==typeof r&&r(o)?i(o):null===r&&i(o)),o.traversal(r,i),o.children.forEach(function(t){n(e,t,r,i)})}(this,null,n,e)}},{key:"sort",value:function(n){this.traversal(null,function(e){e.sort(n)})}},{key:"toJson",value:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=arguments[3],u=o.key_children;if(!(t=t||e.rootNode))return null;var l=i.push(Object.assign(r({},u,[]),t.content));return t.children.forEach(function(t){n(e,t,i[l-1][u],o)}),i}(this,null,[],n=Object.assign({key_children:"children",empty_children:!0},n));return n.empty_children||function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments[2],i=r.key_children;0===(t=t||e[0])[i].length?delete t[i]:t[i].forEach(function(t){n(e,t,r)})}(e,null,n),e&&e.length>0?e[0]:[]}}]),u}(),l={key_id:"id",key_parent:"parent",key_child:"child",key_last:null,uuid:!1,empty_children:!1};return{ListToTree:function(){function n(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,n);var o=t.map(function(n){return n});i=Object.assign({},l,i),this.options=i;var c,a,s=i,f=s.key_id,h=s.key_parent;!1===s.uuid&&(c=h,a=f,o.sort(function(n,e){return n[a]<e[a]?n[c]>e[c]?1:-1:n[c]<e[c]?-1:1}));var d=new u(r({},f,0));o.forEach(function(n,e){d.add(function(e){return e.get(f)===n[h]},n)}),this.tree=d}return t(n,[{key:"sort",value:function(n){this.tree.sort(n)}},{key:"last",value:function(n,e,t,r){for(var i in n)if(n[i][r]&&n[i][r].length&&this.last(n[i][r],e,t,r),0!==n[i][t]&&(i-1>=0&&n[i-1][e]!==n[i][t]||i-1<0)){var o=n[i][t],u=n.splice(i,1);for(var l in n)n[l][e]===o&&n.splice(l+1,0,u[0])}}},{key:"GetTree",value:function(){var n=this.options,e=n.key_id,t=n.key_child,r=(n.empty_children,n.key_last),i=this.tree.toJson({key_children:t,empty_children:!1})[t];return r&&this.last(i,e,r,t),i}}]),n}(),Tree:u,Node:i}}); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n["js-tree-list"]=e()}(this,function(){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},e=function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")},t=function(){function n(n,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}(),r=function(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n},i=function(){function n(t){e(this,n),this.content=t,this.children=[],this.length=0}return t(n,[{key:"get",value:function(n){if(void 0!==this.content[n])return this.content[n]}},{key:"set",value:function(n,e){return!!(this.content[n]=e)}},{key:"add",value:function(e){var t=e instanceof n?e:new n(e);return t.parent=this,this.length++,this.children.push(t),t}},{key:"remove",value:function(n){var e=this.children.findIndex(n);if(e>-1){var t=this.children.splice(e,1);return this.length--,t}return[]}},{key:"sort",value:function(n){return this.children.sort(n)}},{key:"traversal",value:function(n,e){n=n||function(){return!0},this.children.filter(n).forEach(e)}}]),n}(),o=function n(e,t,r,i){var o=t||e.rootNode;if(r(o))return o;for(var u=o.children,l=null,c=0;c<u.length;c++){if(l=n(e,u[c],r))return l}},u=function(){function u(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;e(this,u),this.rootNode=null,n&&(this.rootNode=new i(n))}return t(u,[{key:"get",value:function(n){return this.rootNode.get(n)}},{key:"set",value:function(n,e){this.rootNode.set(n,e)}},{key:"add",value:function(e,t){var r=void 0===e?"undefined":n(e);if("string"===r&&"root"===e)return this.rootNode=new i(t),this;if("function"===r){var u=o(this,null,e);if(u&&u.add(t))return this;console.log("Warning",t)}}},{key:"contains",value:function(n){return o(this,null,n)}},{key:"remove",value:function(n){var e=this.contains(n);return!!e&&!!e.parent.remove(n)}},{key:"move",value:function(n,e){var t=this.contains(n);return!(!t||!this.remove(n))&&!!this.contains(e).add(t)}},{key:"traversal",value:function(n,e){!function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments[2],i=arguments[3],o=t||e.rootNode;t||("function"==typeof r&&r(o)?i(o):null===r&&i(o)),o.traversal(r,i),o.children.forEach(function(t){n(e,t,r,i)})}(this,null,n,e)}},{key:"sort",value:function(n){this.traversal(null,function(e){e.sort(n)})}},{key:"toJson",value:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=arguments[3],u=o.key_children;if(!(t=t||e.rootNode))return null;var l=i.push(Object.assign(r({},u,[]),t.content));return t.children.forEach(function(t){n(e,t,i[l-1][u],o)}),i}(this,null,[],n=Object.assign({key_children:"children",empty_children:!0},n));return n.empty_children||function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments[2],i=r.key_children;0===(t=t||e[0])[i].length?delete t[i]:t[i].forEach(function(t){n(e,t,r)})}(e,null,n),e&&e.length>0?e[0]:[]}}]),u}(),l={key_id:"id",key_parent:"parent",key_child:"child",key_last:null,uuid:!1,empty_children:!1};return{ListToTree:function(){function n(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,n);var o=t.map(function(n){return n});i=Object.assign({},l,i),this.options=i;var c,a,s=i,f=s.key_id,h=s.key_parent;!1===s.uuid&&(c=h,a=f,o.sort(function(n,e){return n[a]<e[a]?n[c]>e[c]?1:-1:n[c]<e[c]?-1:1}));var d=new u(r({},f,0));o.forEach(function(n,e){d.add(function(e){return e.get(f)===n[h]},n)}),this.tree=d}return t(n,[{key:"sort",value:function(n){this.tree.sort(n)}},{key:"last",value:function(n,e,t,r){for(var i in n)if(n[i][r]&&n[i][r].length&&this.last(n[i][r],e,t,r),0!==n[i][t]&&(i-1>=0&&n[i-1][e]!==n[i][t]||i-1<0)){n[i][t];var o=n.splice(i,1);n.splice(i+1,0,o[0])}}},{key:"GetTree",value:function(){var n=this.options,e=n.key_id,t=n.key_child,r=(n.empty_children,n.key_last),i=this.tree.toJson({key_children:t,empty_children:!1})[t];return r&&this.last(i,e,r,t),i}}]),n}(),Tree:u,Node:i}}); |
{ | ||
"name": "js-tree-list", | ||
"version": "1.1.8", | ||
"version": "1.1.13", | ||
"description": "Convert list to tree, managing a tree and its nodes.", | ||
@@ -26,3 +26,2 @@ "main": "bin/js-tree-list.min.js", | ||
], | ||
"author": "yi-ge <a@wyr.me>", | ||
"license": "MIT", | ||
@@ -29,0 +28,0 @@ "bugs": { |
@@ -65,7 +65,3 @@ import LTT from './tree' | ||
const tmp = val.splice(n, 1) // 从该元素位置删除元素并将已删除的元素放置于新数组(tmp) | ||
for (let i in val) { | ||
if (val[i][key_id] === findID) { | ||
val.splice(i + 1, 0, tmp[0]) // 在指定ID元素后面添加被删除的元素 | ||
} | ||
} | ||
val.splice(n + 1, 0, tmp[0]) // 在指定ID元素后面添加被删除的元素 | ||
} | ||
@@ -72,0 +68,0 @@ } |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
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
175390
13
751
2