sculp-js 1.19.12 → 1.19.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/array.cjs +1 -1
- package/dist/cjs/async.cjs +1 -1
- package/dist/cjs/base64.cjs +7 -8
- package/dist/cjs/clipboard.cjs +1 -1
- package/dist/cjs/cloneDeep.cjs +1 -1
- package/dist/cjs/cookie.cjs +1 -1
- package/dist/cjs/date.cjs +1 -1
- package/dist/cjs/dom.cjs +1 -1
- package/dist/cjs/download.cjs +1 -1
- package/dist/cjs/file.cjs +1 -1
- package/dist/cjs/func.cjs +2 -29
- package/dist/cjs/index.cjs +1 -3
- package/dist/cjs/isEqual.cjs +1 -1
- package/dist/cjs/math.cjs +1 -1
- package/dist/cjs/number.cjs +3 -3
- package/dist/cjs/object.cjs +1 -1
- package/dist/cjs/path.cjs +1 -1
- package/dist/cjs/qs.cjs +1 -1
- package/dist/cjs/random.cjs +1 -1
- package/dist/cjs/string.cjs +1 -1
- package/dist/cjs/tooltip.cjs +1 -1
- package/dist/cjs/tree.cjs +29 -26
- package/dist/cjs/type.cjs +1 -1
- package/dist/cjs/unicodeToolkit.cjs +1 -1
- package/dist/cjs/unique.cjs +1 -1
- package/dist/cjs/url.cjs +1 -1
- package/dist/cjs/validator.cjs +1 -1
- package/dist/cjs/variable.cjs +1 -1
- package/dist/cjs/watermark.cjs +1 -1
- package/dist/esm/array.mjs +1 -1
- package/dist/esm/async.mjs +1 -1
- package/dist/esm/base64.mjs +7 -8
- package/dist/esm/clipboard.mjs +1 -1
- package/dist/esm/cloneDeep.mjs +1 -1
- package/dist/esm/cookie.mjs +1 -1
- package/dist/esm/date.mjs +1 -1
- package/dist/esm/dom.mjs +1 -1
- package/dist/esm/download.mjs +1 -1
- package/dist/esm/file.mjs +1 -1
- package/dist/esm/func.mjs +3 -28
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/isEqual.mjs +1 -1
- package/dist/esm/math.mjs +1 -1
- package/dist/esm/number.mjs +3 -3
- package/dist/esm/object.mjs +1 -1
- package/dist/esm/path.mjs +1 -1
- package/dist/esm/qs.mjs +1 -1
- package/dist/esm/random.mjs +1 -1
- package/dist/esm/string.mjs +1 -1
- package/dist/esm/tooltip.mjs +1 -1
- package/dist/esm/tree.mjs +29 -26
- package/dist/esm/type.mjs +1 -1
- package/dist/esm/unicodeToolkit.mjs +1 -1
- package/dist/esm/unique.mjs +1 -1
- package/dist/esm/url.mjs +1 -1
- package/dist/esm/validator.mjs +1 -1
- package/dist/esm/variable.mjs +1 -1
- package/dist/esm/watermark.mjs +1 -1
- package/dist/types/func.d.ts +0 -14
- package/dist/types/tree.d.ts +16 -13
- package/dist/umd/index.min.js +2 -2
- package/package.json +3 -3
package/dist/esm/func.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.19.
|
|
2
|
+
* sculp-js v1.19.14
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -86,35 +86,10 @@ const once = func => {
|
|
|
86
86
|
return result;
|
|
87
87
|
};
|
|
88
88
|
};
|
|
89
|
-
/**
|
|
90
|
-
* 设置全局变量
|
|
91
|
-
* @param {string | number | symbol} key
|
|
92
|
-
* @param val
|
|
93
|
-
*/
|
|
94
|
-
function setGlobal(key, val) {
|
|
95
|
-
if (typeof globalThis !== 'undefined') globalThis[key] = val;
|
|
96
|
-
else if (typeof window !== 'undefined') window[key] = val;
|
|
97
|
-
else if (typeof global !== 'undefined') global[key] = val;
|
|
98
|
-
else if (typeof self !== 'undefined') self[key] = val;
|
|
99
|
-
else throw new SyntaxError('当前环境下无法设置全局属性');
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 获取全局变量
|
|
103
|
-
* @param {string | number | symbol} key
|
|
104
|
-
* @param val
|
|
105
|
-
*/
|
|
106
|
-
function getGlobal(key) {
|
|
107
|
-
if (typeof globalThis !== 'undefined') return globalThis[key];
|
|
108
|
-
else if (typeof window !== 'undefined') return window[key];
|
|
109
|
-
else if (typeof global !== 'undefined') return global[key];
|
|
110
|
-
else if (typeof self !== 'undefined') return self[key];
|
|
111
|
-
}
|
|
112
89
|
var func = {
|
|
113
90
|
debounce,
|
|
114
91
|
throttle,
|
|
115
|
-
once
|
|
116
|
-
getGlobal,
|
|
117
|
-
setGlobal
|
|
92
|
+
once
|
|
118
93
|
};
|
|
119
94
|
|
|
120
|
-
export { debounce, func as default,
|
|
95
|
+
export { debounce, func as default, once, throttle };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.19.
|
|
2
|
+
* sculp-js v1.19.14
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -99,7 +99,7 @@ export { chooseLocalFile, compressImg, supportCanvas } from './file.mjs';
|
|
|
99
99
|
import * as watermark from './watermark.mjs';
|
|
100
100
|
export { genCanvasWM } from './watermark.mjs';
|
|
101
101
|
import * as func from './func.mjs';
|
|
102
|
-
export { debounce,
|
|
102
|
+
export { debounce, once, throttle } from './func.mjs';
|
|
103
103
|
import * as random from './random.mjs';
|
|
104
104
|
export { STRING_POOL, randomNumber, randomString, randomUuid } from './random.mjs';
|
|
105
105
|
import * as number from './number.mjs';
|
package/dist/esm/isEqual.mjs
CHANGED
package/dist/esm/math.mjs
CHANGED
package/dist/esm/number.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.19.
|
|
2
|
+
* sculp-js v1.19.14
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { getGlobal } from './func.mjs';
|
|
8
7
|
import { STRING_ARABIC_NUMERALS, STRING_UPPERCASE_ALPHA, STRING_LOWERCASE_ALPHA } from './string.mjs';
|
|
9
8
|
import { isNullOrUnDef } from './type.mjs';
|
|
10
9
|
|
|
11
10
|
const HEX_POOL = `${STRING_ARABIC_NUMERALS}${STRING_UPPERCASE_ALPHA}${STRING_LOWERCASE_ALPHA}`;
|
|
12
11
|
const supportBigInt = typeof BigInt !== 'undefined';
|
|
13
|
-
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
const jsbi = () => globalThis.JSBI;
|
|
14
14
|
const toBigInt = n => (supportBigInt ? BigInt(n) : jsbi().BigInt(n));
|
|
15
15
|
const divide = (x, y) => (supportBigInt ? x / y : jsbi().divide(x, y));
|
|
16
16
|
const remainder = (x, y) => (supportBigInt ? x % y : jsbi().remainder(x, y));
|
package/dist/esm/object.mjs
CHANGED
package/dist/esm/path.mjs
CHANGED
package/dist/esm/qs.mjs
CHANGED
package/dist/esm/random.mjs
CHANGED
package/dist/esm/string.mjs
CHANGED
package/dist/esm/tooltip.mjs
CHANGED
package/dist/esm/tree.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.19.
|
|
2
|
+
* sculp-js v1.19.14
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -17,13 +17,13 @@ const defaultSearchTreeOptions = {
|
|
|
17
17
|
function getChildNodes(item, childField, isDomNode) {
|
|
18
18
|
const child = item[childField];
|
|
19
19
|
if (!child) return null;
|
|
20
|
-
return isDomNode && isNodeList(child) ?
|
|
20
|
+
return isDomNode && isNodeList(child) ? child : Array.isArray(child) ? child : null;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Tree traversal function (default DFS, supports continue and break operations).
|
|
24
24
|
* Can be used to traverse Array and NodeList type data.
|
|
25
|
-
* @param {V
|
|
26
|
-
* @param {Function}
|
|
25
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
26
|
+
* @param {Function} iteratee - Iteratee function. Returns true to continue, false to break.
|
|
27
27
|
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
28
28
|
childField: 'children',
|
|
29
29
|
reverse: false,
|
|
@@ -34,7 +34,7 @@ function getChildNodes(item, childField, isDomNode) {
|
|
|
34
34
|
*/
|
|
35
35
|
function forEachDeep(
|
|
36
36
|
tree,
|
|
37
|
-
|
|
37
|
+
iteratee,
|
|
38
38
|
options = {
|
|
39
39
|
childField: 'children',
|
|
40
40
|
reverse: false,
|
|
@@ -51,12 +51,12 @@ function forEachDeep(
|
|
|
51
51
|
let isBreak = false;
|
|
52
52
|
const queue = [];
|
|
53
53
|
const processNode = (item, index, arr, parent, level) => {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
54
|
+
const result = iteratee(item, index, arr, tree, parent, level);
|
|
55
|
+
if (result === false) {
|
|
56
56
|
isBreak = true;
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
|
-
if (
|
|
59
|
+
if (result === true) return;
|
|
60
60
|
const childNodes = getChildNodes(item, childField, isDomNode);
|
|
61
61
|
if (childNodes) {
|
|
62
62
|
if (breadthFirst) {
|
|
@@ -100,7 +100,7 @@ function forEachDeep(
|
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Tree search function, can be used to search Array and NodeList type data.
|
|
103
|
-
* @param {V
|
|
103
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
104
104
|
* @param {Function} predicate - Predicate function
|
|
105
105
|
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
106
106
|
childField: 'children',
|
|
@@ -135,7 +135,7 @@ function findDeep(
|
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Tree filter function, can be used to filter Array and NodeList type data.
|
|
138
|
-
* @param {V
|
|
138
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
139
139
|
* @param {Function} predicate - Predicate function
|
|
140
140
|
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
141
141
|
childField: 'children',
|
|
@@ -172,8 +172,8 @@ function filterDeep(
|
|
|
172
172
|
* Can be used for inserting or removing tree items.
|
|
173
173
|
*
|
|
174
174
|
* Can traverse any array-like object with a length property and numeric keys.
|
|
175
|
-
* @param {V
|
|
176
|
-
* @param {Function}
|
|
175
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
176
|
+
* @param {Function} iteratee - Iteratee function. Returns true to continue, false to break.
|
|
177
177
|
* @param {object} options - Options to customize child element name, reverse traversal. Default: {
|
|
178
178
|
childField: 'children',
|
|
179
179
|
reverse: false,
|
|
@@ -182,7 +182,7 @@ function filterDeep(
|
|
|
182
182
|
*/
|
|
183
183
|
function mapDeep(
|
|
184
184
|
tree,
|
|
185
|
-
|
|
185
|
+
iteratee,
|
|
186
186
|
options = {
|
|
187
187
|
childField: 'children',
|
|
188
188
|
reverse: false
|
|
@@ -196,13 +196,13 @@ function mapDeep(
|
|
|
196
196
|
for (let i = arr.length - 1; i >= 0; i--) {
|
|
197
197
|
if (isBreak) break;
|
|
198
198
|
const item = arr[i];
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
199
|
+
const result = iteratee(item, i, arr, tree, parent, level);
|
|
200
|
+
if (result === false) {
|
|
201
201
|
isBreak = true;
|
|
202
202
|
break;
|
|
203
203
|
}
|
|
204
|
-
if (
|
|
205
|
-
const newItem = objectOmit(
|
|
204
|
+
if (result === true) continue;
|
|
205
|
+
const newItem = objectOmit(result, [childField]);
|
|
206
206
|
output.push(newItem);
|
|
207
207
|
const children = item[childField];
|
|
208
208
|
if (Array.isArray(children)) {
|
|
@@ -214,13 +214,13 @@ function mapDeep(
|
|
|
214
214
|
for (let i = 0; i < arr.length; i++) {
|
|
215
215
|
if (isBreak) break;
|
|
216
216
|
const item = arr[i];
|
|
217
|
-
const
|
|
218
|
-
if (
|
|
217
|
+
const result = iteratee(item, i, arr, tree, parent, level);
|
|
218
|
+
if (result === false) {
|
|
219
219
|
isBreak = true;
|
|
220
220
|
break;
|
|
221
221
|
}
|
|
222
|
-
if (
|
|
223
|
-
const newItem = objectOmit(
|
|
222
|
+
if (result === true) continue;
|
|
223
|
+
const newItem = objectOmit(result, [childField]);
|
|
224
224
|
output.push(newItem);
|
|
225
225
|
const children = item[childField];
|
|
226
226
|
if (Array.isArray(children)) {
|
|
@@ -238,14 +238,14 @@ function mapDeep(
|
|
|
238
238
|
/**
|
|
239
239
|
* Retrieves the path (ancestors + self) for a given node ID.
|
|
240
240
|
*
|
|
241
|
-
* @param {ArrayLike<
|
|
241
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
242
242
|
* @param {number | string} nodeId - Target node ID
|
|
243
243
|
* @param {ITreeConf} options - Configuration. Default: { childField = 'children', keyField = 'id' }
|
|
244
244
|
* @returns {[(number | string)[], V[]]} - Array of IDs and Array of Nodes from root to target
|
|
245
245
|
*/
|
|
246
246
|
function getPathById(tree, nodeId, options = { childField: 'children', keyField: 'id' }) {
|
|
247
247
|
const { childField = 'children', keyField = 'id' } = isObject(options) ? options : {};
|
|
248
|
-
const
|
|
248
|
+
const nodeMap = {};
|
|
249
249
|
// 扁平化 - 使用迭代而非递归,避免栈溢出
|
|
250
250
|
const stack = [];
|
|
251
251
|
const len = tree.length;
|
|
@@ -255,7 +255,7 @@ function getPathById(tree, nodeId, options = { childField: 'children', keyField:
|
|
|
255
255
|
while (stack.length > 0) {
|
|
256
256
|
const { node, parentId, parent } = stack.pop();
|
|
257
257
|
const id = node[keyField];
|
|
258
|
-
|
|
258
|
+
nodeMap[id] = { node, parentId, parent };
|
|
259
259
|
const children = node[childField];
|
|
260
260
|
if (Array.isArray(children)) {
|
|
261
261
|
const childLen = children.length;
|
|
@@ -267,13 +267,13 @@ function getPathById(tree, nodeId, options = { childField: 'children', keyField:
|
|
|
267
267
|
// 回溯路径
|
|
268
268
|
const ids = [];
|
|
269
269
|
const nodes = [];
|
|
270
|
-
let current =
|
|
270
|
+
let current = nodeMap[nodeId];
|
|
271
271
|
if (!current) return [[], []];
|
|
272
272
|
ids.push(nodeId);
|
|
273
273
|
nodes.push(current.node);
|
|
274
274
|
while (current && current.parentId !== undefined) {
|
|
275
275
|
ids.unshift(current.parentId);
|
|
276
|
-
const parent =
|
|
276
|
+
const parent = nodeMap[current.parentId];
|
|
277
277
|
if (!parent) break;
|
|
278
278
|
nodes.unshift(parent.node);
|
|
279
279
|
current = parent;
|
|
@@ -417,6 +417,9 @@ var tree = {
|
|
|
417
417
|
filterDeep,
|
|
418
418
|
mapDeep,
|
|
419
419
|
getPathById,
|
|
420
|
+
/**
|
|
421
|
+
* @deprecated 已废弃,请使用 getPathById
|
|
422
|
+
*/
|
|
420
423
|
searchTreeById: getPathById,
|
|
421
424
|
formatTree,
|
|
422
425
|
flatTree,
|
package/dist/esm/type.mjs
CHANGED
package/dist/esm/unique.mjs
CHANGED
package/dist/esm/url.mjs
CHANGED
package/dist/esm/validator.mjs
CHANGED
package/dist/esm/variable.mjs
CHANGED
package/dist/esm/watermark.mjs
CHANGED
package/dist/types/func.d.ts
CHANGED
|
@@ -35,23 +35,9 @@ export interface OnceFunc<F extends AnyFunc> {
|
|
|
35
35
|
* @returns {AnyFunc}
|
|
36
36
|
*/
|
|
37
37
|
export declare const once: <F extends AnyFunc = AnyFunc>(func: F) => OnceFunc<F>;
|
|
38
|
-
/**
|
|
39
|
-
* 设置全局变量
|
|
40
|
-
* @param {string | number | symbol} key
|
|
41
|
-
* @param val
|
|
42
|
-
*/
|
|
43
|
-
export declare function setGlobal(key: string | number | symbol, val?: any): void;
|
|
44
|
-
/**
|
|
45
|
-
* 获取全局变量
|
|
46
|
-
* @param {string | number | symbol} key
|
|
47
|
-
* @param val
|
|
48
|
-
*/
|
|
49
|
-
export declare function getGlobal<T>(key: string | number | symbol): T | void;
|
|
50
38
|
declare const _default: {
|
|
51
39
|
debounce: <F extends AnyFunc>(func: F, wait?: number) => DebounceFunc<F>;
|
|
52
40
|
throttle: <F_1 extends AnyFunc>(func: F_1, wait: number, immediate?: boolean) => ThrottleFunc<F_1>;
|
|
53
41
|
once: <F_2 extends AnyFunc = AnyFunc>(func: F_2) => OnceFunc<F_2>;
|
|
54
|
-
getGlobal: typeof getGlobal;
|
|
55
|
-
setGlobal: typeof setGlobal;
|
|
56
42
|
};
|
|
57
43
|
export default _default;
|
package/dist/types/tree.d.ts
CHANGED
|
@@ -11,13 +11,13 @@ export interface ISearchTreeOpts {
|
|
|
11
11
|
}
|
|
12
12
|
export interface IFilterCondition<V> {
|
|
13
13
|
keyword?: string;
|
|
14
|
-
filter?: (
|
|
14
|
+
filter?: (val: V) => boolean;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Tree traversal function (default DFS, supports continue and break operations).
|
|
18
18
|
* Can be used to traverse Array and NodeList type data.
|
|
19
|
-
* @param {V
|
|
20
|
-
* @param {Function}
|
|
19
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
20
|
+
* @param {Function} iteratee - Iteratee function. Returns true to continue, false to break.
|
|
21
21
|
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
22
22
|
childField: 'children',
|
|
23
23
|
reverse: false,
|
|
@@ -26,7 +26,7 @@ export interface IFilterCondition<V> {
|
|
|
26
26
|
}
|
|
27
27
|
* @returns {*}
|
|
28
28
|
*/
|
|
29
|
-
export declare function forEachDeep<V>(tree: V
|
|
29
|
+
export declare function forEachDeep<V>(tree: ArrayLike<V>, iteratee: (val: V, index: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => boolean | void, options?: {
|
|
30
30
|
childField?: string;
|
|
31
31
|
reverse?: boolean;
|
|
32
32
|
breadthFirst?: boolean;
|
|
@@ -34,7 +34,7 @@ export declare function forEachDeep<V>(tree: V[], iterator: (val: V, index: numb
|
|
|
34
34
|
}): void;
|
|
35
35
|
/**
|
|
36
36
|
* Tree search function, can be used to search Array and NodeList type data.
|
|
37
|
-
* @param {V
|
|
37
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
38
38
|
* @param {Function} predicate - Predicate function
|
|
39
39
|
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
40
40
|
childField: 'children',
|
|
@@ -44,7 +44,7 @@ export declare function forEachDeep<V>(tree: V[], iterator: (val: V, index: numb
|
|
|
44
44
|
}
|
|
45
45
|
* @returns {V|null}
|
|
46
46
|
*/
|
|
47
|
-
export declare function findDeep<V>(tree: V
|
|
47
|
+
export declare function findDeep<V>(tree: ArrayLike<V>, predicate: (val: V, index: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => boolean | void, options?: {
|
|
48
48
|
childField?: string;
|
|
49
49
|
reverse?: boolean;
|
|
50
50
|
breadthFirst?: boolean;
|
|
@@ -52,7 +52,7 @@ export declare function findDeep<V>(tree: V[], predicate: (val: V, index: number
|
|
|
52
52
|
}): V | null;
|
|
53
53
|
/**
|
|
54
54
|
* Tree filter function, can be used to filter Array and NodeList type data.
|
|
55
|
-
* @param {V
|
|
55
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
56
56
|
* @param {Function} predicate - Predicate function
|
|
57
57
|
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
58
58
|
childField: 'children',
|
|
@@ -62,7 +62,7 @@ export declare function findDeep<V>(tree: V[], predicate: (val: V, index: number
|
|
|
62
62
|
}
|
|
63
63
|
* @returns {V[]}
|
|
64
64
|
*/
|
|
65
|
-
export declare function filterDeep<V>(tree: V
|
|
65
|
+
export declare function filterDeep<V>(tree: ArrayLike<V>, predicate: (val: V, index: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => boolean | void, options?: {
|
|
66
66
|
childField?: string;
|
|
67
67
|
reverse?: boolean;
|
|
68
68
|
breadthFirst?: boolean;
|
|
@@ -73,15 +73,15 @@ export declare function filterDeep<V>(tree: V[], predicate: (val: V, index: numb
|
|
|
73
73
|
* Can be used for inserting or removing tree items.
|
|
74
74
|
*
|
|
75
75
|
* Can traverse any array-like object with a length property and numeric keys.
|
|
76
|
-
* @param {V
|
|
77
|
-
* @param {Function}
|
|
76
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
77
|
+
* @param {Function} iteratee - Iteratee function. Returns true to continue, false to break.
|
|
78
78
|
* @param {object} options - Options to customize child element name, reverse traversal. Default: {
|
|
79
79
|
childField: 'children',
|
|
80
80
|
reverse: false,
|
|
81
81
|
}
|
|
82
82
|
* @returns {any[]} A new tree structure
|
|
83
83
|
*/
|
|
84
|
-
export declare function mapDeep<
|
|
84
|
+
export declare function mapDeep<V>(tree: ArrayLike<V>, iteratee: (val: V, index: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => {
|
|
85
85
|
[k: string | number]: any;
|
|
86
86
|
} | boolean, options?: {
|
|
87
87
|
childField?: string;
|
|
@@ -92,12 +92,12 @@ export type ITreeConf = Omit<IFieldOptions, 'pidField'>;
|
|
|
92
92
|
/**
|
|
93
93
|
* Retrieves the path (ancestors + self) for a given node ID.
|
|
94
94
|
*
|
|
95
|
-
* @param {ArrayLike<
|
|
95
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
96
96
|
* @param {number | string} nodeId - Target node ID
|
|
97
97
|
* @param {ITreeConf} options - Configuration. Default: { childField = 'children', keyField = 'id' }
|
|
98
98
|
* @returns {[(number | string)[], V[]]} - Array of IDs and Array of Nodes from root to target
|
|
99
99
|
*/
|
|
100
|
-
export declare function getPathById<V>(tree: V
|
|
100
|
+
export declare function getPathById<V>(tree: ArrayLike<V>, nodeId: IdLike, options?: ITreeConf): [(number | string)[], any[]];
|
|
101
101
|
export { getPathById as searchTreeById };
|
|
102
102
|
/**
|
|
103
103
|
* Converts a flat array into a tree structure.
|
|
@@ -144,6 +144,9 @@ declare const _default: {
|
|
|
144
144
|
filterDeep: typeof filterDeep;
|
|
145
145
|
mapDeep: typeof mapDeep;
|
|
146
146
|
getPathById: typeof getPathById;
|
|
147
|
+
/**
|
|
148
|
+
* @deprecated 已废弃,请使用 getPathById
|
|
149
|
+
*/
|
|
147
150
|
searchTreeById: typeof getPathById;
|
|
148
151
|
formatTree: typeof formatTree;
|
|
149
152
|
flatTree: typeof flatTree;
|