tree-helper
Advanced tools
Comparing version 1.0.5 to 1.4.14
/*! | ||
* tree-helper v1.0.5 | ||
* phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* https://github.com/phphe/tree-helper.git | ||
* Released under the MIT License. | ||
*/ | ||
* tree-helper v1.4.14 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
import { isArray, arrayRemove } from 'helper-js'; | ||
import { arrayRemove, isArray } from 'helper-js'; | ||
import * as hp from 'helper-js'; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
return _typeof(obj); | ||
} | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
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"); | ||
} | ||
function clone(obj) { | ||
var childrenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'children'; | ||
var cloned; | ||
var cloned = void 0; | ||
if (isArray(obj)) { | ||
@@ -25,2 +52,3 @@ cloned = obj.map(function (item) { | ||
cloned = Object.assign({}, obj); | ||
if (cloned[childrenKey]) { | ||
@@ -30,7 +58,7 @@ cloned[childrenKey] = clone(cloned[childrenKey]); | ||
} | ||
return cloned; | ||
} | ||
} // 旧版深度优先遍历 | ||
// old Depth-First-Search | ||
// 旧版深度优先遍历 | ||
// old Depth-First-Search | ||
function forIn(obj, handler) { | ||
@@ -40,2 +68,3 @@ var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var rootChildren, rootParent, _func; | ||
if (isArray(obj)) { | ||
@@ -48,2 +77,3 @@ rootChildren = obj; | ||
} | ||
if (rootChildren) { | ||
@@ -53,5 +83,7 @@ _func = function func(children, parent) { | ||
var child = children[key]; | ||
if (handler(child, key, parent) === false) { | ||
return false; | ||
} | ||
if (child[childrenKey] != null) { | ||
@@ -63,18 +95,20 @@ if (_func(child[childrenKey], child) === false) { | ||
} | ||
return true; | ||
}; | ||
_func(rootChildren, rootParent); | ||
} | ||
return obj; | ||
} | ||
} // 深度优先遍历 | ||
// Depth-First-Search | ||
// 深度优先遍历 | ||
// Depth-First-Search | ||
function depthFirstSearch(obj, handler) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var reverse = arguments[3]; | ||
var reverse = arguments.length > 3 ? arguments[3] : undefined; | ||
var rootChildren = isArray(obj) ? obj : [obj]; // | ||
var rootChildren = isArray(obj) ? obj : [obj]; | ||
// | ||
var StopException = function StopException() {}; | ||
var func = function func(children, parent) { | ||
@@ -85,6 +119,9 @@ if (reverse) { | ||
} | ||
var len = children.length; | ||
for (var i = 0; i < len; i++) { | ||
var item = children[i]; | ||
var r = handler(item, i, parent); | ||
if (r === false) { | ||
@@ -98,2 +135,3 @@ // stop | ||
} | ||
if (item[childrenKey] != null) { | ||
@@ -104,24 +142,24 @@ func(item[childrenKey], item); | ||
}; | ||
try { | ||
func(rootChildren); | ||
} catch (e) { | ||
if (e instanceof StopException) { | ||
// stop | ||
} else { | ||
if (e instanceof StopException) ; else { | ||
throw e; | ||
} | ||
} | ||
} | ||
} // 广度优先遍历 | ||
// Breadth-First-Search | ||
// 广度优先遍历 | ||
// Breadth-First-Search | ||
function breadthFirstSearch(obj, handler) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var reverse = arguments[3]; | ||
var reverse = arguments.length > 3 ? arguments[3] : undefined; | ||
var rootChildren = isArray(obj) ? obj : [obj]; // | ||
var rootChildren = isArray(obj) ? obj : [obj]; | ||
// | ||
var stack = rootChildren.map(function (v, i) { | ||
return { item: v, index: i }; | ||
return { | ||
item: v, | ||
index: i | ||
}; | ||
}); | ||
if (reverse) { | ||
@@ -138,2 +176,3 @@ stack.reverse(); | ||
var r = handler(item, index, parent); | ||
if (r === false) { | ||
@@ -145,3 +184,3 @@ // stop | ||
} else if (r === 'skip children') { | ||
return 'continue'; | ||
return "continue"; | ||
} else if (r === 'skip siblings') { | ||
@@ -152,2 +191,3 @@ stack = stack.filter(function (v) { | ||
} | ||
if (item.children) { | ||
@@ -157,2 +197,3 @@ var _stack; | ||
var children = item.children; | ||
if (reverse) { | ||
@@ -162,5 +203,11 @@ children = children.slice(); | ||
} | ||
var pushStack = children.map(function (v, i) { | ||
return { item: v, index: i, parent: item }; | ||
return { | ||
item: v, | ||
index: i, | ||
parent: item | ||
}; | ||
}); | ||
(_stack = stack).push.apply(_stack, _toConsumableArray(pushStack)); | ||
@@ -174,7 +221,7 @@ } | ||
switch (_ret) { | ||
case 'continue': | ||
case "continue": | ||
continue; | ||
default: | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
if (_typeof(_ret) === "object") return _ret.v; | ||
} | ||
@@ -192,2 +239,3 @@ } | ||
} | ||
item[parentKey] = parent; | ||
@@ -213,4 +261,6 @@ } | ||
} | ||
var siblings = target[parentKey][childrenKey]; | ||
var index = siblings.indexOf(target); | ||
if (siblings[index - 1] !== item) { | ||
@@ -223,2 +273,3 @@ if (item[parentKey] === target[parentKey]) { | ||
} | ||
siblings.splice(index, 0, item); | ||
@@ -234,5 +285,7 @@ } | ||
} | ||
var targetParent = target[parentKey]; | ||
var siblings = targetParent[childrenKey]; | ||
var index = siblings.indexOf(target); | ||
if (siblings[index + 1] !== item) { | ||
@@ -245,2 +298,3 @@ if (item[parentKey] === target[parentKey]) { | ||
} | ||
siblings.splice(index + 1, 0, item); | ||
@@ -251,10 +305,12 @@ } | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
if (item === target) { | ||
throw 'can\'t prepend to self'; | ||
throw "can't prepend to self"; | ||
} | ||
var targetChildren = target[childrenKey]; | ||
if (targetChildren[0] !== item) { | ||
_changeParent(item, target); | ||
targetChildren.splice(0, 0, item); | ||
@@ -265,11 +321,13 @@ } | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
if (item === target) { | ||
throw 'can\'t append to self'; | ||
throw "can't append to self"; | ||
} | ||
var targetChildren = target[childrenKey]; | ||
var targetChildrenLast = targetChildren[targetChildren.length - 1]; | ||
if (targetChildrenLast !== item) { | ||
_changeParent(item, target); | ||
targetChildren.push(item); | ||
@@ -279,2 +337,2 @@ } | ||
export { clone, forIn, depthFirstSearch, breadthFirstSearch, getTreeDataFromFlat, insertBefore, insertAfter, prependTo, appendTo }; | ||
export { appendTo, breadthFirstSearch, clone, depthFirstSearch, forIn, getTreeDataFromFlat, insertAfter, insertBefore, prependTo }; |
/*! | ||
* tree-helper v1.0.5 | ||
* phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* https://github.com/phphe/tree-helper.git | ||
* Released under the MIT License. | ||
*/ | ||
* tree-helper v1.4.14 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.treeHelper = global.treeHelper || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('helper-js')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'helper-js'], factory) : | ||
(global = global || self, factory(global.treeHelper = {}, global.hp)); | ||
}(this, (function (exports, hp) { 'use strict'; | ||
var _typeof2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
/*! | ||
* helper-js v1.0.47 | ||
* (c) 2017-present phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
function _typeof$1(obj) { | ||
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") { | ||
_typeof$1 = function _typeof$1(obj) { | ||
return typeof obj === "undefined" ? "undefined" : _typeof2(obj); | ||
}; | ||
} else { | ||
_typeof$1 = function _typeof$1(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof2(obj); | ||
}; | ||
} | ||
return _typeof$1(obj); | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _get(object, property, receiver) { | ||
if (object === null) object = Function.prototype; | ||
var desc = Object.getOwnPropertyDescriptor(object, property); | ||
if (desc === undefined) { | ||
var parent = Object.getPrototypeOf(object); | ||
if (parent === null) { | ||
return undefined; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
return _get(parent, property, receiver); | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
} else if ("value" in desc) { | ||
return desc.value; | ||
} else { | ||
var getter = desc.get; | ||
if (getter === undefined) { | ||
return undefined; | ||
} | ||
return getter.call(receiver); | ||
return _typeof(obj); | ||
} | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
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; | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && ((typeof call === "undefined" ? "undefined" : _typeof2(call)) === "object" || typeof call === "function")) { | ||
return call; | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _toConsumableArray$1(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 _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function clone(obj) { | ||
var childrenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'children'; | ||
var cloned; | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
if (hp.isArray(obj)) { | ||
cloned = obj.map(function (item) { | ||
return clone(item); | ||
}); | ||
} else { | ||
cloned = Object.assign({}, obj); | ||
// resolve global | ||
var glb; | ||
if (cloned[childrenKey]) { | ||
cloned[childrenKey] = clone(cloned[childrenKey]); | ||
} | ||
} | ||
try { | ||
glb = global; | ||
} catch (e) { | ||
glb = window; | ||
} // local store | ||
return cloned; | ||
} // 旧版深度优先遍历 | ||
// old Depth-First-Search | ||
function forIn(obj, handler) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var store = {}; // is 各种判断 | ||
var rootChildren, rootParent, _func; | ||
function isset(v) { | ||
return typeof v !== 'undefined'; | ||
} | ||
function isArray(v) { | ||
return Object.prototype.toString.call(v) === '[object Array]'; | ||
} | ||
function isNumeric(v) { | ||
return isFinite(v); | ||
} | ||
function isObject(v) { | ||
return Object.prototype.toString.call(v) === '[object Object]'; | ||
} | ||
function isFunction(v) { | ||
return typeof v === 'function'; | ||
} | ||
function numRand(min, max) { | ||
if (arguments.length === 1) { | ||
max = min; | ||
min = 0; | ||
} | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
} | ||
function max(n, max) { | ||
return n < max ? n : max; | ||
} // str 字符 | ||
function studlyCase(str) { | ||
return str && str[0].toUpperCase() + str.substr(1); | ||
} | ||
function strRand() { | ||
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8; | ||
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
var r = ''; | ||
var seeds = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
for (var i = 0; i < len; i++) { | ||
r += seeds[numRand(seeds.length - 1)]; | ||
} | ||
return prefix + r; | ||
} | ||
function arrayRemove(arr, v) { | ||
var index; | ||
var count = 0; | ||
while ((index = arr.indexOf(v)) > -1) { | ||
arr.splice(index, 1); | ||
count++; | ||
} | ||
return count; | ||
} | ||
function arrayLast(arr) { | ||
return arr[arr.length - 1]; | ||
} | ||
function objectGet(obj, path) { | ||
var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var paths = path.split('.'); | ||
var current = obj; | ||
var parent = null; | ||
for (var i = 0; i < paths.length; i++) { | ||
if (current[paths[i]] == null) { | ||
return defaultValue; | ||
if (hp.isArray(obj)) { | ||
rootChildren = obj; | ||
rootParent = null; | ||
} else { | ||
parent = current; | ||
current = current[paths[i]]; | ||
rootChildren = [obj]; | ||
rootParent = null; | ||
} | ||
} | ||
var lastPath = arrayLast(paths); | ||
return parent.hasOwnProperty(lastPath) ? current : defaultValue; | ||
} | ||
function cloneObj(obj, exclude) { | ||
var type = _typeof$1(obj); | ||
if (rootChildren) { | ||
_func = function func(children, parent) { | ||
for (var key in children) { | ||
var child = children[key]; | ||
switch (type) { | ||
case 'undefined': | ||
case 'boolean': | ||
case 'nuber': | ||
case 'string': | ||
case 'function': | ||
return obj; | ||
break; | ||
if (handler(child, key, parent) === false) { | ||
return false; | ||
} | ||
case 'object': | ||
if (obj === null) { | ||
// null is object | ||
return obj; | ||
} | ||
var r; | ||
if (isArray(obj)) { | ||
r = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = obj[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var item = _step.value; | ||
r.push(cloneObj(item, exclude)); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
if (child[childrenKey] != null) { | ||
if (_func(child[childrenKey], child) === false) { | ||
return false; | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} else { | ||
r = {}; | ||
var _arr2 = Object.keys(obj); | ||
return true; | ||
}; | ||
for (var _i3 = 0; _i3 < _arr2.length; _i3++) { | ||
var key = _arr2[_i3]; | ||
_func(rootChildren, rootParent); | ||
} | ||
if (!exclude || isArray(exclude) && !exclude.includes(key) || !exclude(key, obj[key], obj)) { | ||
r[key] = cloneObj(obj[key], exclude); | ||
} | ||
} | ||
} | ||
return obj; | ||
} // 深度优先遍历 | ||
// Depth-First-Search | ||
return r; | ||
break; | ||
function depthFirstSearch(obj, handler) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var reverse = arguments.length > 3 ? arguments[3] : undefined; | ||
var rootChildren = hp.isArray(obj) ? obj : [obj]; // | ||
default: | ||
return obj; | ||
break; | ||
} | ||
} // return cloned obj | ||
/* eslint-enable */ | ||
// dom | ||
var StopException = function StopException() {}; | ||
function uniqueId() { | ||
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'id_'; | ||
var id = prefix + strRand(); | ||
if (!store.uniqueId) store.uniqueId = {}; | ||
var generatedIds = store.uniqueId; | ||
var func = function func(children, parent) { | ||
if (reverse) { | ||
children = children.slice(); | ||
children.reverse(); | ||
} | ||
if (document.getElementById(id) || generatedIds[id]) { | ||
return uniqueId(prefix); | ||
} else { | ||
generatedIds[id] = true; | ||
return id; | ||
} | ||
} | ||
function getOffsetWithoutScroll(el) { | ||
var elOffset = { | ||
x: el.offsetLeft, | ||
y: el.offsetTop | ||
}; | ||
var parentOffset = { | ||
x: 0, | ||
y: 0 | ||
}; | ||
if (el.offsetParent != null) parentOffset = getOffsetWithoutScroll(el.offsetParent); | ||
return { | ||
x: elOffset.x + parentOffset.x, | ||
y: elOffset.y + parentOffset.y | ||
}; | ||
} | ||
function hasClass(el, className) { | ||
if (el.classList) { | ||
return el.classList.contains(className); | ||
} else { | ||
return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className); | ||
} | ||
} // source: http://youmightnotneedjquery.com/ | ||
var len = children.length; | ||
function onDOM(el, name, handler) { | ||
if (el.addEventListener) { | ||
// 所有主流浏览器,除了 IE 8 及更早 IE版本 | ||
el.addEventListener(name, handler); | ||
} else if (el.attachEvent) { | ||
// IE 8 及更早 IE 版本 | ||
el.attachEvent("on".concat(name), handler); | ||
} | ||
} | ||
// binarySearch 二分查找 | ||
for (var i = 0; i < len; i++) { | ||
var item = children[i]; | ||
var r = handler(item, i, parent); | ||
function binarySearch(arr, callback, start, end, returnNearestIfNoHit) { | ||
var max = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1000; | ||
var midNum; | ||
var mid; | ||
if (r === false) { | ||
// stop | ||
throw new StopException(); | ||
} else if (r === 'skip children') { | ||
continue; | ||
} else if (r === 'skip siblings') { | ||
break; | ||
} | ||
if (start == null) { | ||
start = 0; | ||
end = arr.length - 1; | ||
} | ||
if (item[childrenKey] != null) { | ||
func(item[childrenKey], item); | ||
} | ||
} | ||
}; | ||
var i = 0; | ||
var r; | ||
while (start >= 0 && start <= end) { | ||
if (i >= max) { | ||
throw Error("binarySearch: loop times is over ".concat(max, ", you can increase the limit.")); | ||
try { | ||
func(rootChildren); | ||
} catch (e) { | ||
if (e instanceof StopException) ; else { | ||
throw e; | ||
} | ||
} | ||
} // 广度优先遍历 | ||
// Breadth-First-Search | ||
midNum = Math.floor((end - start) / 2 + start); | ||
mid = arr[midNum]; | ||
r = callback(mid, i); | ||
function breadthFirstSearch(obj, handler) { | ||
var reverse = arguments.length > 3 ? arguments[3] : undefined; | ||
var rootChildren = hp.isArray(obj) ? obj : [obj]; // | ||
if (r > 0) { | ||
end = midNum - 1; | ||
} else if (r < 0) { | ||
start = midNum + 1; | ||
} else { | ||
var stack = rootChildren.map(function (v, i) { | ||
return { | ||
index: midNum, | ||
value: mid, | ||
count: i + 1, | ||
hit: true | ||
item: v, | ||
index: i | ||
}; | ||
} | ||
i++; | ||
} | ||
return returnNearestIfNoHit ? { | ||
index: midNum, | ||
value: mid, | ||
count: i + 1, | ||
hit: false, | ||
bigger: r > 0 | ||
} : null; | ||
} // | ||
function retry(func) { | ||
var limitTimes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3; | ||
if (!store.retry) store.retry = {}; | ||
var counters = retry; | ||
var name = generateName(); | ||
counters[name] = 0; | ||
return doFunc; | ||
function doFunc(arg1, arg2, arg3) { | ||
return func(arg1, arg2, arg3).then(function (data) { | ||
delete counters[name]; | ||
return data; | ||
}).catch(function (e) { | ||
counters[name]++; | ||
if (counters[name] >= limitTimes) { | ||
delete counters[name]; | ||
return Promise.reject(e); | ||
} else { | ||
return doFunc(arg1, arg2, arg3); | ||
} | ||
}); | ||
} | ||
function generateName() { | ||
var name = Math.random() + ''; | ||
if (counters[name]) { | ||
return generateName(); | ||
} else { | ||
return name; | ||
if (reverse) { | ||
stack.reverse(); | ||
} | ||
} | ||
} // 复制文字到剪贴板 | ||
var URLHelper = | ||
/*#__PURE__*/ | ||
function () { | ||
// protocol, hostname, port, pastname | ||
function URLHelper(baseUrl) { | ||
var _this = this; | ||
var _loop = function _loop() { | ||
var _stack$shift = stack.shift(), | ||
item = _stack$shift.item, | ||
index = _stack$shift.index, | ||
parent = _stack$shift.parent; | ||
_classCallCheck(this, URLHelper); | ||
var r = handler(item, index, parent); | ||
Object.defineProperty(this, "baseUrl", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: '' | ||
}); | ||
Object.defineProperty(this, "search", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: {} | ||
}); | ||
var t = decodeURI(baseUrl).split('?'); | ||
this.baseUrl = t[0]; | ||
if (t[1]) { | ||
t[1].split('&').forEach(function (v) { | ||
var t2 = v.split('='); | ||
_this.search[t2[0]] = t2[1] == null ? '' : decodeURIComponent(t2[1]); | ||
}); | ||
} | ||
} | ||
_createClass(URLHelper, [{ | ||
key: "getHref", | ||
value: function getHref() { | ||
var _this2 = this; | ||
var t = [this.baseUrl]; | ||
var searchStr = Object.keys(this.search).map(function (k) { | ||
return "".concat(k, "=").concat(encodeURIComponent(_this2.search[k])); | ||
}).join('&'); | ||
if (searchStr) { | ||
t.push(searchStr); | ||
if (r === false) { | ||
// stop | ||
return { | ||
v: void 0 | ||
}; | ||
} else if (r === 'skip children') { | ||
return "continue"; | ||
} else if (r === 'skip siblings') { | ||
stack = stack.filter(function (v) { | ||
return v.parent !== parent; | ||
}); | ||
} | ||
return t.join('?'); | ||
} | ||
}]); | ||
if (item.children) { | ||
var _stack; | ||
return URLHelper; | ||
}(); // 解析函数参数, 帮助重载 | ||
var EventProcessor = | ||
/*#__PURE__*/ | ||
function () { | ||
function EventProcessor() { | ||
_classCallCheck(this, EventProcessor); | ||
var children = item.children; | ||
Object.defineProperty(this, "eventStore", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: [] | ||
}); | ||
} | ||
_createClass(EventProcessor, [{ | ||
key: "on", | ||
value: function on(name, handler) { | ||
this.eventStore.push({ | ||
name: name, | ||
handler: handler | ||
}); | ||
} | ||
}, { | ||
key: "once", | ||
value: function once(name, handler) { | ||
var _this3 = this; | ||
var off = function off() { | ||
_this3.off(name, wrappedHandler); | ||
}; | ||
var wrappedHandler = function wrappedHandler() { | ||
handler(); | ||
off(); | ||
}; | ||
this.on(name, wrappedHandler); | ||
return off; | ||
} | ||
}, { | ||
key: "off", | ||
value: function off(name, handler) { | ||
var indexes = []; // to remove indexes; reverse; 倒序的 | ||
var len = this.eventStore.length; | ||
for (var i = 0; i < len; i++) { | ||
var item = this.eventStore[i]; | ||
if (item.name === name && item.handler === handler) { | ||
indexes.unshift(i); | ||
if (reverse) { | ||
children = children.slice(); | ||
children.reverse(); | ||
} | ||
} | ||
for (var _i4 = 0; _i4 < indexes.length; _i4++) { | ||
var index = indexes[_i4]; | ||
this.eventStore.splice(index, 1); | ||
} | ||
} | ||
}, { | ||
key: "emit", | ||
value: function emit(name) { | ||
// 重要: 先找到要执行的项放在新数组里, 因为执行项会改变事件项存储数组 | ||
var items = []; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
var pushStack = children.map(function (v, i) { | ||
return { | ||
item: v, | ||
index: i, | ||
parent: item | ||
}; | ||
}); | ||
try { | ||
for (var _iterator2 = this.eventStore[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var item = _step2.value; | ||
if (item.name === name) { | ||
items.push(item); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
(_stack = stack).push.apply(_stack, _toConsumableArray(pushStack)); | ||
} | ||
}; | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
while (stack.length) { | ||
var _ret = _loop(); | ||
for (var _i5 = 0; _i5 < items.length; _i5++) { | ||
var _item = items[_i5]; | ||
switch (_ret) { | ||
case "continue": | ||
continue; | ||
_item.handler.apply(_item, args); | ||
default: | ||
if (_typeof(_ret) === "object") return _ret.v; | ||
} | ||
} | ||
}]); | ||
} | ||
return EventProcessor; | ||
}(); | ||
var CrossWindow = | ||
/*#__PURE__*/ | ||
function (_EventProcessor) { | ||
_inherits(CrossWindow, _EventProcessor); | ||
function _changeParent(item, parent) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
function CrossWindow() { | ||
var _this4; | ||
// remove item from original list | ||
if (item[parentKey]) { | ||
hp.arrayRemove(item[parentKey][childrenKey], item); | ||
} | ||
_classCallCheck(this, CrossWindow); | ||
item[parentKey] = parent; | ||
} | ||
_this4 = _possibleConstructorReturn(this, (CrossWindow.__proto__ || Object.getPrototypeOf(CrossWindow)).call(this)); | ||
Object.defineProperty(_assertThisInitialized(_this4), "storageName", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: '_crossWindow' | ||
function getTreeDataFromFlat(data, idKey, parentIdKey) { | ||
data.forEach(function (item) { | ||
return item.children = data.filter(function (v) { | ||
return v[parentIdKey] === item[idKey]; | ||
}); | ||
}); | ||
var cls = CrossWindow; | ||
return data.filter(function (item) { | ||
return item[parentIdKey] == null; | ||
}); | ||
} | ||
function insertBefore(item, target) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
if (!cls._listen) { | ||
cls._listen = true; | ||
onDOM(window, 'storage', function (ev) { | ||
if (ev.key === _this4.storageName) { | ||
var _get2; | ||
var event = JSON.parse(ev.newValue); | ||
(_get2 = _get(CrossWindow.prototype.__proto__ || Object.getPrototypeOf(CrossWindow.prototype), "emit", _assertThisInitialized(_this4))).call.apply(_get2, [_this4, event.name].concat(_toConsumableArray$1(event.args))); | ||
} | ||
}); | ||
if (item === target) { | ||
return; | ||
} | ||
return _this4; | ||
} | ||
var siblings = target[parentKey][childrenKey]; | ||
var index = siblings.indexOf(target); | ||
_createClass(CrossWindow, [{ | ||
key: "emit", | ||
value: function emit(name) { | ||
var _get3; | ||
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
if (siblings[index - 1] !== item) { | ||
if (item[parentKey] === target[parentKey]) { | ||
hp.arrayRemove(siblings, item); | ||
index = siblings.indexOf(target); | ||
} else { | ||
_changeParent(item, target[parentKey]); | ||
} | ||
(_get3 = _get(CrossWindow.prototype.__proto__ || Object.getPrototypeOf(CrossWindow.prototype), "emit", this)).call.apply(_get3, [this, name].concat(args)); | ||
glb.localStorage.setItem(this.storageName, JSON.stringify({ | ||
name: name, | ||
args: args, | ||
// use random make storage event triggered every time | ||
// 加入随机保证触发storage事件 | ||
random: Math.random() | ||
})); | ||
siblings.splice(index, 0, item); | ||
} | ||
}]); | ||
} | ||
function insertAfter(item, target) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
return CrossWindow; | ||
}(EventProcessor); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function clone(obj) { | ||
var childrenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'children'; | ||
var cloned = void 0; | ||
if (isArray(obj)) { | ||
cloned = obj.map(function (item) { | ||
return clone(item); | ||
}); | ||
} else { | ||
cloned = Object.assign({}, obj); | ||
if (cloned[childrenKey]) { | ||
cloned[childrenKey] = clone(cloned[childrenKey]); | ||
if (item === target) { | ||
return; | ||
} | ||
} | ||
return cloned; | ||
} | ||
// 旧版深度优先遍历 | ||
// old Depth-First-Search | ||
function forIn(obj, handler) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var targetParent = target[parentKey]; | ||
var siblings = targetParent[childrenKey]; | ||
var index = siblings.indexOf(target); | ||
var rootChildren, rootParent, _func; | ||
if (isArray(obj)) { | ||
rootChildren = obj; | ||
rootParent = null; | ||
} else { | ||
rootChildren = [obj]; | ||
rootParent = null; | ||
} | ||
if (rootChildren) { | ||
_func = function func(children, parent) { | ||
for (var key in children) { | ||
var child = children[key]; | ||
if (handler(child, key, parent) === false) { | ||
return false; | ||
} | ||
if (child[childrenKey] != null) { | ||
if (_func(child[childrenKey], child) === false) { | ||
return false; | ||
} | ||
} | ||
if (siblings[index + 1] !== item) { | ||
if (item[parentKey] === target[parentKey]) { | ||
hp.arrayRemove(siblings, item); | ||
index = siblings.indexOf(target); | ||
} else { | ||
_changeParent(item, target[parentKey]); | ||
} | ||
return true; | ||
}; | ||
_func(rootChildren, rootParent); | ||
} | ||
return obj; | ||
} | ||
// 深度优先遍历 | ||
// Depth-First-Search | ||
function depthFirstSearch(obj, handler) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var reverse = arguments[3]; | ||
var rootChildren = isArray(obj) ? obj : [obj]; | ||
// | ||
var StopException = function StopException() {}; | ||
var func = function func(children, parent) { | ||
if (reverse) { | ||
children = children.slice(); | ||
children.reverse(); | ||
siblings.splice(index + 1, 0, item); | ||
} | ||
var len = children.length; | ||
for (var i = 0; i < len; i++) { | ||
var item = children[i]; | ||
var r = handler(item, i, parent); | ||
if (r === false) { | ||
// stop | ||
throw new StopException(); | ||
} else if (r === 'skip children') { | ||
continue; | ||
} else if (r === 'skip siblings') { | ||
break; | ||
} | ||
if (item[childrenKey] != null) { | ||
func(item[childrenKey], item); | ||
} | ||
} | ||
}; | ||
try { | ||
func(rootChildren); | ||
} catch (e) { | ||
if (e instanceof StopException) { | ||
// stop | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
function prependTo(item, target) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
// 广度优先遍历 | ||
// Breadth-First-Search | ||
function breadthFirstSearch(obj, handler) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var reverse = arguments[3]; | ||
var rootChildren = isArray(obj) ? obj : [obj]; | ||
// | ||
var stack = rootChildren.map(function (v, i) { | ||
return { item: v, index: i }; | ||
}); | ||
if (reverse) { | ||
stack.reverse(); | ||
} | ||
var _loop = function _loop() { | ||
var _stack$shift = stack.shift(), | ||
item = _stack$shift.item, | ||
index = _stack$shift.index, | ||
parent = _stack$shift.parent; | ||
var r = handler(item, index, parent); | ||
if (r === false) { | ||
// stop | ||
return { | ||
v: void 0 | ||
}; | ||
} else if (r === 'skip children') { | ||
return 'continue'; | ||
} else if (r === 'skip siblings') { | ||
stack = stack.filter(function (v) { | ||
return v.parent !== parent; | ||
}); | ||
if (item === target) { | ||
throw "can't prepend to self"; | ||
} | ||
if (item.children) { | ||
var _stack; | ||
var children = item.children; | ||
if (reverse) { | ||
children = children.slice(); | ||
children.reverse(); | ||
} | ||
var pushStack = children.map(function (v, i) { | ||
return { item: v, index: i, parent: item }; | ||
}); | ||
(_stack = stack).push.apply(_stack, _toConsumableArray(pushStack)); | ||
} | ||
}; | ||
var targetChildren = target[childrenKey]; | ||
while (stack.length) { | ||
var _ret = _loop(); | ||
if (targetChildren[0] !== item) { | ||
_changeParent(item, target); | ||
switch (_ret) { | ||
case 'continue': | ||
continue; | ||
default: | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
targetChildren.splice(0, 0, item); | ||
} | ||
} | ||
} | ||
function appendTo(item, target) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
function _changeParent(item, parent) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
if (item === target) { | ||
throw "can't append to self"; | ||
} | ||
// remove item from original list | ||
if (item[parentKey]) { | ||
arrayRemove(item[parentKey][childrenKey], item); | ||
} | ||
item[parentKey] = parent; | ||
} | ||
var targetChildren = target[childrenKey]; | ||
var targetChildrenLast = targetChildren[targetChildren.length - 1]; | ||
function getTreeDataFromFlat(data, idKey, parentIdKey) { | ||
data.forEach(function (item) { | ||
return item.children = data.filter(function (v) { | ||
return v[parentIdKey] === item[idKey]; | ||
}); | ||
}); | ||
return data.filter(function (item) { | ||
return item[parentIdKey] == null; | ||
}); | ||
} | ||
function insertBefore(item, target) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
if (targetChildrenLast !== item) { | ||
_changeParent(item, target); | ||
if (item === target) { | ||
return; | ||
} | ||
var siblings = target[parentKey][childrenKey]; | ||
var index = siblings.indexOf(target); | ||
if (siblings[index - 1] !== item) { | ||
if (item[parentKey] === target[parentKey]) { | ||
arrayRemove(siblings, item); | ||
index = siblings.indexOf(target); | ||
} else { | ||
_changeParent(item, target[parentKey]); | ||
targetChildren.push(item); | ||
} | ||
siblings.splice(index, 0, item); | ||
} | ||
} | ||
function insertAfter(item, target) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
if (item === target) { | ||
return; | ||
} | ||
var targetParent = target[parentKey]; | ||
var siblings = targetParent[childrenKey]; | ||
var index = siblings.indexOf(target); | ||
if (siblings[index + 1] !== item) { | ||
if (item[parentKey] === target[parentKey]) { | ||
arrayRemove(siblings, item); | ||
index = siblings.indexOf(target); | ||
} else { | ||
_changeParent(item, target[parentKey]); | ||
} | ||
siblings.splice(index + 1, 0, item); | ||
} | ||
} | ||
function prependTo(item, target) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
exports.appendTo = appendTo; | ||
exports.breadthFirstSearch = breadthFirstSearch; | ||
exports.clone = clone; | ||
exports.depthFirstSearch = depthFirstSearch; | ||
exports.forIn = forIn; | ||
exports.getTreeDataFromFlat = getTreeDataFromFlat; | ||
exports.insertAfter = insertAfter; | ||
exports.insertBefore = insertBefore; | ||
exports.prependTo = prependTo; | ||
if (item === target) { | ||
throw 'can\'t prepend to self'; | ||
} | ||
var targetChildren = target[childrenKey]; | ||
if (targetChildren[0] !== item) { | ||
_changeParent(item, target); | ||
targetChildren.splice(0, 0, item); | ||
} | ||
} | ||
function appendTo(item, target) { | ||
var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parent'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
if (item === target) { | ||
throw 'can\'t append to self'; | ||
} | ||
var targetChildren = target[childrenKey]; | ||
var targetChildrenLast = targetChildren[targetChildren.length - 1]; | ||
if (targetChildrenLast !== item) { | ||
_changeParent(item, target); | ||
targetChildren.push(item); | ||
} | ||
} | ||
exports.clone = clone; | ||
exports.forIn = forIn; | ||
exports.depthFirstSearch = depthFirstSearch; | ||
exports.breadthFirstSearch = breadthFirstSearch; | ||
exports.getTreeDataFromFlat = getTreeDataFromFlat; | ||
exports.insertBefore = insertBefore; | ||
exports.insertAfter = insertAfter; | ||
exports.prependTo = prependTo; | ||
exports.appendTo = appendTo; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
/*! | ||
* tree-helper v1.0.5 | ||
* phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* https://github.com/phphe/tree-helper.git | ||
* Released under the MIT License. | ||
*/ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(n.treeHelper=n.treeHelper||{})}(this,function(n){"use strict";function e(n){return"[object Array]"===Object.prototype.toString.call(n)}function r(n,e){for(var r,t=0;(r=n.indexOf(e))>-1;)n.splice(r,1),t++;return t}function t(n){if(Array.isArray(n)){for(var e=0,r=Array(n.length);e<n.length;e++)r[e]=n[e];return r}return Array.from(n)}function i(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"children",t=void 0;return e(n)?t=n.map(function(n){return i(n)}):(t=Object.assign({},n),t[r]&&(t[r]=i(t[r]))),t}function o(n,r){var t,i,o,f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children";return e(n)?(t=n,i=null):(t=[n],i=null),t&&(o=function(n,e){for(var t in n){var i=n[t];if(!1===r(i,t,e))return!1;if(null!=i[f]&&!1===o(i[f],i))return!1}return!0})(t,i),n}function f(n,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",i=arguments[3],o=e(n)?n:[n],f=function(){};try{!function n(e,o){i&&(e=e.slice(),e.reverse());for(var c=e.length,l=0;l<c;l++){var u=e[l],a=r(u,l,o);if(!1===a)throw new f;if("skip children"!==a){if("skip siblings"===a)break;null!=u[t]&&n(u[t],u)}}}(o)}catch(n){if(!(n instanceof f))throw n}}function c(n,r){var i=(arguments.length>2&&void 0!==arguments[2]&&arguments[2],arguments[3]),o=e(n)?n:[n],f=o.map(function(n,e){return{item:n,index:e}});i&&f.reverse();for(;f.length;){var c=function(){var n=f.shift(),e=n.item,o=n.index,c=n.parent,l=r(e,o,c);if(!1===l)return{v:void 0};if("skip children"===l)return"continue";if("skip siblings"===l&&(f=f.filter(function(n){return n.parent!==c})),e.children){var u,a=e.children;i&&(a=a.slice(),a.reverse());var d=a.map(function(n,r){return{item:n,index:r,parent:e}});(u=f).push.apply(u,t(d))}}();switch(c){case"continue":continue;default:if("object"===(void 0===c?"undefined":v(c)))return c.v}}}function l(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent";n[i]&&r(n[i][t],n),n[i]=e}function u(n,e,r){return n.forEach(function(t){return t.children=n.filter(function(n){return n[r]===t[e]})}),n.filter(function(n){return null==n[r]})}function a(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent";if(n!==e){var o=e[i][t],f=o.indexOf(e);o[f-1]!==n&&(n[i]===e[i]?(r(o,n),f=o.indexOf(e)):l(n,e[i]),o.splice(f,0,n))}}function d(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent";if(n!==e){var o=e[i],f=o[t],c=f.indexOf(e);f[c+1]!==n&&(n[i]===e[i]?(r(f,n),c=f.indexOf(e)):l(n,e[i]),f.splice(c+1,0,n))}}function p(n,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children";arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(n===e)throw"can't prepend to self";var t=e[r];t[0]!==n&&(l(n,e),t.splice(0,0,n))}function h(n,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children";arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(n===e)throw"can't append to self";var t=e[r];t[t.length-1]!==n&&(l(n,e),t.push(n))}"function"==typeof Symbol&&Symbol.iterator;try{global}catch(n){window}var v="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};n.clone=i,n.forIn=o,n.depthFirstSearch=f,n.breadthFirstSearch=c,n.getTreeDataFromFlat=u,n.insertBefore=a,n.insertAfter=d,n.prependTo=p,n.appendTo=h,Object.defineProperty(n,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=tree-helper.min.js.map | ||
* tree-helper v1.4.14 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("helper-js")):"function"==typeof define&&define.amd?define(["exports","helper-js"],n):n((e=e||self).treeHelper={},e.hp)}(this,(function(e,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function t(e){return function(e){if(Array.isArray(e)){for(var n=0,r=new Array(e.length);n<e.length;n++)r[n]=e[n];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function i(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent";e[i]&&n.arrayRemove(e[i][t],e),e[i]=r}e.appendTo=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children";if(e===n)throw"can't append to self";var t=n[r];t[t.length-1]!==e&&(i(e,n),t.push(e))},e.breadthFirstSearch=function(e,i){var o=arguments.length>3?arguments[3]:void 0,f=(n.isArray(e)?e:[e]).map((function(e,n){return{item:e,index:n}}));o&&f.reverse();for(var c=function(){var e=f.shift(),n=e.item,r=e.index,c=e.parent,l=i(n,r,c);if(!1===l)return{v:void 0};if("skip children"===l)return"continue";if("skip siblings"===l&&(f=f.filter((function(e){return e.parent!==c}))),n.children){var a,u=n.children;o&&(u=u.slice()).reverse();var d=u.map((function(e,r){return{item:e,index:r,parent:n}}));(a=f).push.apply(a,t(d))}};f.length;){var l=c();switch(l){case"continue":continue;default:if("object"===r(l))return l.v}}},e.clone=function e(r){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"children";return n.isArray(r)?t=r.map((function(n){return e(n)})):(t=Object.assign({},r))[i]&&(t[i]=e(t[i])),t},e.depthFirstSearch=function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",i=arguments.length>3?arguments[3]:void 0,o=n.isArray(e)?e:[e],f=function(){};try{!function e(n,o){i&&(n=n.slice()).reverse();for(var c=n.length,l=0;l<c;l++){var a=n[l],u=r(a,l,o);if(!1===u)throw new f;if("skip children"!==u){if("skip siblings"===u)break;null!=a[t]&&e(a[t],a)}}}(o)}catch(e){if(!(e instanceof f))throw e}},e.forIn=function(e,r){var t,i,o,f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children";return n.isArray(e)?(t=e,i=null):(t=[e],i=null),t&&(o=function(e,n){for(var t in e){var i=e[t];if(!1===r(i,t,n))return!1;if(null!=i[f]&&!1===o(i[f],i))return!1}return!0})(t,i),e},e.getTreeDataFromFlat=function(e,n,r){return e.forEach((function(t){return t.children=e.filter((function(e){return e[r]===t[n]}))})),e.filter((function(e){return null==e[r]}))},e.insertAfter=function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent";if(e!==r){var f=r[o][t],c=f.indexOf(r);f[c+1]!==e&&(e[o]===r[o]?(n.arrayRemove(f,e),c=f.indexOf(r)):i(e,r[o]),f.splice(c+1,0,e))}},e.insertBefore=function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent";if(e!==r){var f=r[o][t],c=f.indexOf(r);f[c-1]!==e&&(e[o]===r[o]?(n.arrayRemove(f,e),c=f.indexOf(r)):i(e,r[o]),f.splice(c,0,e))}},e.prependTo=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children";if(e===n)throw"can't prepend to self";var t=n[r];t[0]!==e&&(i(e,n),t.splice(0,0,e))},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=tree-helper.min.js.map |
{ | ||
"name": "tree-helper", | ||
"version": "1.0.5", | ||
"version": "1.4.14", | ||
"description": "", | ||
"main": "dist/tree-helper.common.js", | ||
"main": "dist/tree-helper.cjs.js", | ||
"module": "dist/tree-helper.esm.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "node build/build.js" | ||
"build": "node scripts/build.js", | ||
"dev": "node scripts/build.js --watch", | ||
"build-test": "rollup -c" | ||
}, | ||
@@ -19,9 +24,7 @@ "author": "phphe <phphe@outlook.com> (https://github.com/phphe)", | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"rollup-helper": "^1.0.3" | ||
"rollup-helper": "^2.0.1" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"helper-js": "^1.0.47" | ||
} | ||
} | ||
"license": "MIT" | ||
} |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
0
39368
8
801
2
1
- Removedhelper-js@^1.0.47
- Removed@babel/runtime@7.26.0(transitive)
- Removedhelper-js@1.4.38(transitive)
- Removedregenerator-runtime@0.14.1(transitive)