sculp-js 1.19.6 → 1.19.13
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/README.md +2 -2
- package/dist/cjs/array.cjs +1 -1
- package/dist/cjs/async.cjs +1 -1
- package/dist/cjs/base64.cjs +1 -1
- 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 +1 -1
- package/dist/cjs/index.cjs +3 -2
- package/dist/cjs/isEqual.cjs +1 -1
- package/dist/cjs/math.cjs +1 -1
- package/dist/cjs/number.cjs +1 -1
- 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 +71 -64
- 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 +1 -1
- 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 +1 -1
- package/dist/esm/index.mjs +3 -2
- package/dist/esm/isEqual.mjs +1 -1
- package/dist/esm/math.mjs +1 -1
- package/dist/esm/number.mjs +1 -1
- 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 +71 -64
- 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/tree.d.ts +54 -48
- package/dist/umd/index.min.js +2 -2
- package/package.json +8 -5
- /package/{LICENSE.md → LICENSE} +0 -0
package/dist/esm/math.mjs
CHANGED
package/dist/esm/number.mjs
CHANGED
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.13
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -17,13 +17,14 @@ 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
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
23
|
+
* Tree traversal function (default DFS, supports continue and break operations).
|
|
24
|
+
* Can be used to traverse Array and NodeList type data.
|
|
25
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
26
|
+
* @param {Function} iteratee - Iteratee function. Returns true to continue, false to break.
|
|
27
|
+
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
27
28
|
childField: 'children',
|
|
28
29
|
reverse: false,
|
|
29
30
|
breadthFirst: false,
|
|
@@ -33,7 +34,7 @@ function getChildNodes(item, childField, isDomNode) {
|
|
|
33
34
|
*/
|
|
34
35
|
function forEachDeep(
|
|
35
36
|
tree,
|
|
36
|
-
|
|
37
|
+
iteratee,
|
|
37
38
|
options = {
|
|
38
39
|
childField: 'children',
|
|
39
40
|
reverse: false,
|
|
@@ -50,12 +51,12 @@ function forEachDeep(
|
|
|
50
51
|
let isBreak = false;
|
|
51
52
|
const queue = [];
|
|
52
53
|
const processNode = (item, index, arr, parent, level) => {
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
54
|
+
const result = iteratee(item, index, arr, tree, parent, level);
|
|
55
|
+
if (result === false) {
|
|
55
56
|
isBreak = true;
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
|
-
if (
|
|
59
|
+
if (result === true) return;
|
|
59
60
|
const childNodes = getChildNodes(item, childField, isDomNode);
|
|
60
61
|
if (childNodes) {
|
|
61
62
|
if (breadthFirst) {
|
|
@@ -98,10 +99,10 @@ function forEachDeep(
|
|
|
98
99
|
tree = null;
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {ArrayLike<V>} tree
|
|
103
|
-
* @param {Function} predicate
|
|
104
|
-
* @param {
|
|
102
|
+
* Tree search function, can be used to search Array and NodeList type data.
|
|
103
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
104
|
+
* @param {Function} predicate - Predicate function
|
|
105
|
+
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
105
106
|
childField: 'children',
|
|
106
107
|
reverse: false,
|
|
107
108
|
breadthFirst: false,
|
|
@@ -133,10 +134,10 @@ function findDeep(
|
|
|
133
134
|
return result;
|
|
134
135
|
}
|
|
135
136
|
/**
|
|
136
|
-
*
|
|
137
|
-
* @param {ArrayLike<V>} tree
|
|
138
|
-
* @param {Function} predicate
|
|
139
|
-
* @param {
|
|
137
|
+
* Tree filter function, can be used to filter Array and NodeList type data.
|
|
138
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
139
|
+
* @param {Function} predicate - Predicate function
|
|
140
|
+
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
140
141
|
childField: 'children',
|
|
141
142
|
reverse: false,
|
|
142
143
|
breadthFirst: false,
|
|
@@ -167,20 +168,21 @@ function filterDeep(
|
|
|
167
168
|
return result;
|
|
168
169
|
}
|
|
169
170
|
/**
|
|
170
|
-
*
|
|
171
|
+
* Creates a new array using a depth-first traversal Map function (supports continue and break operations).
|
|
172
|
+
* Can be used for inserting or removing tree items.
|
|
171
173
|
*
|
|
172
|
-
*
|
|
173
|
-
* @param {ArrayLike<V>} tree
|
|
174
|
-
* @param {Function}
|
|
175
|
-
* @param {
|
|
174
|
+
* Can traverse any array-like object with a length property and numeric keys.
|
|
175
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
176
|
+
* @param {Function} iteratee - Iteratee function. Returns true to continue, false to break.
|
|
177
|
+
* @param {object} options - Options to customize child element name, reverse traversal. Default: {
|
|
176
178
|
childField: 'children',
|
|
177
179
|
reverse: false,
|
|
178
180
|
}
|
|
179
|
-
* @returns {any[]}
|
|
181
|
+
* @returns {any[]} A new tree structure
|
|
180
182
|
*/
|
|
181
183
|
function mapDeep(
|
|
182
184
|
tree,
|
|
183
|
-
|
|
185
|
+
iteratee,
|
|
184
186
|
options = {
|
|
185
187
|
childField: 'children',
|
|
186
188
|
reverse: false
|
|
@@ -194,13 +196,13 @@ function mapDeep(
|
|
|
194
196
|
for (let i = arr.length - 1; i >= 0; i--) {
|
|
195
197
|
if (isBreak) break;
|
|
196
198
|
const item = arr[i];
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
+
const result = iteratee(item, i, arr, tree, parent, level);
|
|
200
|
+
if (result === false) {
|
|
199
201
|
isBreak = true;
|
|
200
202
|
break;
|
|
201
203
|
}
|
|
202
|
-
if (
|
|
203
|
-
const newItem = objectOmit(
|
|
204
|
+
if (result === true) continue;
|
|
205
|
+
const newItem = objectOmit(result, [childField]);
|
|
204
206
|
output.push(newItem);
|
|
205
207
|
const children = item[childField];
|
|
206
208
|
if (Array.isArray(children)) {
|
|
@@ -212,13 +214,13 @@ function mapDeep(
|
|
|
212
214
|
for (let i = 0; i < arr.length; i++) {
|
|
213
215
|
if (isBreak) break;
|
|
214
216
|
const item = arr[i];
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
+
const result = iteratee(item, i, arr, tree, parent, level);
|
|
218
|
+
if (result === false) {
|
|
217
219
|
isBreak = true;
|
|
218
220
|
break;
|
|
219
221
|
}
|
|
220
|
-
if (
|
|
221
|
-
const newItem = objectOmit(
|
|
222
|
+
if (result === true) continue;
|
|
223
|
+
const newItem = objectOmit(result, [childField]);
|
|
222
224
|
output.push(newItem);
|
|
223
225
|
const children = item[childField];
|
|
224
226
|
if (Array.isArray(children)) {
|
|
@@ -234,16 +236,16 @@ function mapDeep(
|
|
|
234
236
|
return newTree;
|
|
235
237
|
}
|
|
236
238
|
/**
|
|
237
|
-
*
|
|
239
|
+
* Retrieves the path (ancestors + self) for a given node ID.
|
|
238
240
|
*
|
|
239
|
-
* @param {ArrayLike<
|
|
240
|
-
* @param {number | string} nodeId -
|
|
241
|
-
* @param {ITreeConf} options -
|
|
242
|
-
* @returns {[(number | string)[], V[]]} -
|
|
241
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
242
|
+
* @param {number | string} nodeId - Target node ID
|
|
243
|
+
* @param {ITreeConf} options - Configuration. Default: { childField = 'children', keyField = 'id' }
|
|
244
|
+
* @returns {[(number | string)[], V[]]} - Array of IDs and Array of Nodes from root to target
|
|
243
245
|
*/
|
|
244
|
-
function
|
|
246
|
+
function getPathById(tree, nodeId, options = { childField: 'children', keyField: 'id' }) {
|
|
245
247
|
const { childField = 'children', keyField = 'id' } = isObject(options) ? options : {};
|
|
246
|
-
const
|
|
248
|
+
const nodeMap = {};
|
|
247
249
|
// 扁平化 - 使用迭代而非递归,避免栈溢出
|
|
248
250
|
const stack = [];
|
|
249
251
|
const len = tree.length;
|
|
@@ -253,7 +255,7 @@ function searchTreeById(tree, nodeId, options = { childField: 'children', keyFie
|
|
|
253
255
|
while (stack.length > 0) {
|
|
254
256
|
const { node, parentId, parent } = stack.pop();
|
|
255
257
|
const id = node[keyField];
|
|
256
|
-
|
|
258
|
+
nodeMap[id] = { node, parentId, parent };
|
|
257
259
|
const children = node[childField];
|
|
258
260
|
if (Array.isArray(children)) {
|
|
259
261
|
const childLen = children.length;
|
|
@@ -265,13 +267,13 @@ function searchTreeById(tree, nodeId, options = { childField: 'children', keyFie
|
|
|
265
267
|
// 回溯路径
|
|
266
268
|
const ids = [];
|
|
267
269
|
const nodes = [];
|
|
268
|
-
let current =
|
|
270
|
+
let current = nodeMap[nodeId];
|
|
269
271
|
if (!current) return [[], []];
|
|
270
272
|
ids.push(nodeId);
|
|
271
273
|
nodes.push(current.node);
|
|
272
274
|
while (current && current.parentId !== undefined) {
|
|
273
275
|
ids.unshift(current.parentId);
|
|
274
|
-
const parent =
|
|
276
|
+
const parent = nodeMap[current.parentId];
|
|
275
277
|
if (!parent) break;
|
|
276
278
|
nodes.unshift(parent.node);
|
|
277
279
|
current = parent;
|
|
@@ -279,11 +281,11 @@ function searchTreeById(tree, nodeId, options = { childField: 'children', keyFie
|
|
|
279
281
|
return [ids, nodes];
|
|
280
282
|
}
|
|
281
283
|
/**
|
|
282
|
-
*
|
|
283
|
-
* @param {any[]} list
|
|
284
|
-
* @param {IFieldOptions} options
|
|
284
|
+
* Converts a flat array into a tree structure.
|
|
285
|
+
* @param {any[]} list - Flat list of items
|
|
286
|
+
* @param {IFieldOptions} options - Customizes id field name, child element field name, parent element field name. Default:
|
|
285
287
|
* { keyField: 'key', childField: 'children', pidField: 'pid' }
|
|
286
|
-
* @returns {any[]}
|
|
288
|
+
* @returns {any[]} Tree structure array
|
|
287
289
|
*/
|
|
288
290
|
function formatTree(list, options = defaultFieldOptions) {
|
|
289
291
|
const { keyField = 'key', childField = 'children', pidField = 'pid' } = isObject(options) ? options : {};
|
|
@@ -309,11 +311,11 @@ function formatTree(list, options = defaultFieldOptions) {
|
|
|
309
311
|
return treeArr;
|
|
310
312
|
}
|
|
311
313
|
/**
|
|
312
|
-
*
|
|
313
|
-
* @param {any[]} treeList
|
|
314
|
-
* @param {IFieldOptions} options
|
|
314
|
+
* Converts a tree structure into a flat array.
|
|
315
|
+
* @param {any[]} treeList - Tree structure array
|
|
316
|
+
* @param {IFieldOptions} options - Customizes id field name, child element field name, parent element field name. Default:
|
|
315
317
|
* { keyField: 'key', childField: 'children', pidField: 'pid' }
|
|
316
|
-
* @returns {any[]}
|
|
318
|
+
* @returns {any[]} Flat array
|
|
317
319
|
*/
|
|
318
320
|
function flatTree(treeList, options = defaultFieldOptions) {
|
|
319
321
|
const { keyField = 'key', childField = 'children', pidField = 'pid' } = isObject(options) ? options : {};
|
|
@@ -340,23 +342,26 @@ function flatTree(treeList, options = defaultFieldOptions) {
|
|
|
340
342
|
return res;
|
|
341
343
|
}
|
|
342
344
|
/**
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
* 1. 过滤函数filter, 返回true/false
|
|
346
|
-
* 2. 匹配关键词,支持是否启用忽略大小写来判断
|
|
345
|
+
* Fuzzy search function that returns nodes containing the search character and their ancestor nodes.
|
|
346
|
+
* Suitable for character filtering in tree components.
|
|
347
347
|
*
|
|
348
|
-
*
|
|
349
|
-
* 1.
|
|
350
|
-
* 2.
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
348
|
+
* Two search conditions are available, processed in priority order:
|
|
349
|
+
* 1. Filter function `filter`, returning true/false.
|
|
350
|
+
* 2. Keyword matching, supporting case-insensitive check.
|
|
351
|
+
*
|
|
352
|
+
* Features:
|
|
353
|
+
* 1. Configurable `removeEmptyChild` field to decide whether to remove empty children fields in search results.
|
|
354
|
+
* 2. If no filter condition is provided, or keyword mode is used with an empty keyword, the original object is returned; otherwise, a new array is returned.
|
|
355
|
+
*
|
|
356
|
+
* @param {V[]} nodes - Tree nodes
|
|
357
|
+
* @param {IFilterCondition} filterCondition - Filter conditions
|
|
358
|
+
* @param {ISearchTreeOpts} options - Default configuration: {
|
|
354
359
|
childField: 'children',
|
|
355
360
|
nameField: 'name',
|
|
356
361
|
removeEmptyChild: false,
|
|
357
362
|
ignoreCase: true
|
|
358
363
|
}
|
|
359
|
-
* @returns {V[]}
|
|
364
|
+
* @returns {V[]} Filtered tree nodes
|
|
360
365
|
*/
|
|
361
366
|
function fuzzySearchTree(nodes, filterCondition, options = defaultSearchTreeOptions) {
|
|
362
367
|
if (!objectHas(filterCondition, 'filter') && !filterCondition.keyword) {
|
|
@@ -411,7 +416,8 @@ var tree = {
|
|
|
411
416
|
findDeep,
|
|
412
417
|
filterDeep,
|
|
413
418
|
mapDeep,
|
|
414
|
-
|
|
419
|
+
getPathById,
|
|
420
|
+
searchTreeById: getPathById,
|
|
415
421
|
formatTree,
|
|
416
422
|
flatTree,
|
|
417
423
|
fuzzySearchTree
|
|
@@ -425,6 +431,7 @@ export {
|
|
|
425
431
|
forEachDeep,
|
|
426
432
|
formatTree,
|
|
427
433
|
fuzzySearchTree,
|
|
434
|
+
getPathById,
|
|
428
435
|
mapDeep,
|
|
429
|
-
searchTreeById
|
|
436
|
+
getPathById as searchTreeById
|
|
430
437
|
};
|
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/tree.d.ts
CHANGED
|
@@ -11,13 +11,14 @@ 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
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {
|
|
17
|
+
* Tree traversal function (default DFS, supports continue and break operations).
|
|
18
|
+
* Can be used to traverse Array and NodeList type data.
|
|
19
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
20
|
+
* @param {Function} iteratee - Iteratee function. Returns true to continue, false to break.
|
|
21
|
+
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
21
22
|
childField: 'children',
|
|
22
23
|
reverse: false,
|
|
23
24
|
breadthFirst: false,
|
|
@@ -25,17 +26,17 @@ export interface IFilterCondition<V> {
|
|
|
25
26
|
}
|
|
26
27
|
* @returns {*}
|
|
27
28
|
*/
|
|
28
|
-
export declare function forEachDeep<V>(tree: ArrayLike<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?: {
|
|
29
30
|
childField?: string;
|
|
30
31
|
reverse?: boolean;
|
|
31
32
|
breadthFirst?: boolean;
|
|
32
33
|
isDomNode?: boolean;
|
|
33
34
|
}): void;
|
|
34
35
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param {ArrayLike<V>} tree
|
|
37
|
-
* @param {Function} predicate
|
|
38
|
-
* @param {
|
|
36
|
+
* Tree search function, can be used to search Array and NodeList type data.
|
|
37
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
38
|
+
* @param {Function} predicate - Predicate function
|
|
39
|
+
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
39
40
|
childField: 'children',
|
|
40
41
|
reverse: false,
|
|
41
42
|
breadthFirst: false,
|
|
@@ -50,10 +51,10 @@ export declare function findDeep<V>(tree: ArrayLike<V>, predicate: (val: V, inde
|
|
|
50
51
|
isDomNode?: boolean;
|
|
51
52
|
}): V | null;
|
|
52
53
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param {ArrayLike<V>} tree
|
|
55
|
-
* @param {Function} predicate
|
|
56
|
-
* @param {
|
|
54
|
+
* Tree filter function, can be used to filter Array and NodeList type data.
|
|
55
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
56
|
+
* @param {Function} predicate - Predicate function
|
|
57
|
+
* @param {object} options - Options to customize child element name, reverse traversal, breadth-first traversal. Default: {
|
|
57
58
|
childField: 'children',
|
|
58
59
|
reverse: false,
|
|
59
60
|
breadthFirst: false,
|
|
@@ -68,69 +69,73 @@ export declare function filterDeep<V>(tree: ArrayLike<V>, predicate: (val: V, in
|
|
|
68
69
|
isDomNode?: boolean;
|
|
69
70
|
}): V[];
|
|
70
71
|
/**
|
|
71
|
-
*
|
|
72
|
+
* Creates a new array using a depth-first traversal Map function (supports continue and break operations).
|
|
73
|
+
* Can be used for inserting or removing tree items.
|
|
72
74
|
*
|
|
73
|
-
*
|
|
74
|
-
* @param {ArrayLike<V>} tree
|
|
75
|
-
* @param {Function}
|
|
76
|
-
* @param {
|
|
75
|
+
* Can traverse any array-like object with a length property and numeric keys.
|
|
76
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
77
|
+
* @param {Function} iteratee - Iteratee function. Returns true to continue, false to break.
|
|
78
|
+
* @param {object} options - Options to customize child element name, reverse traversal. Default: {
|
|
77
79
|
childField: 'children',
|
|
78
80
|
reverse: false,
|
|
79
81
|
}
|
|
80
|
-
* @returns {any[]}
|
|
82
|
+
* @returns {any[]} A new tree structure
|
|
81
83
|
*/
|
|
82
|
-
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) => {
|
|
83
85
|
[k: string | number]: any;
|
|
84
86
|
} | boolean, options?: {
|
|
85
87
|
childField?: string;
|
|
86
88
|
reverse?: boolean;
|
|
87
|
-
breadthFirst?: boolean;
|
|
88
89
|
}): any[];
|
|
89
90
|
export type IdLike = number | string;
|
|
90
91
|
export type ITreeConf = Omit<IFieldOptions, 'pidField'>;
|
|
91
92
|
/**
|
|
92
|
-
*
|
|
93
|
+
* Retrieves the path (ancestors + self) for a given node ID.
|
|
93
94
|
*
|
|
94
|
-
* @param {ArrayLike<
|
|
95
|
-
* @param {number | string} nodeId -
|
|
96
|
-
* @param {ITreeConf} options -
|
|
97
|
-
* @returns {[(number | string)[], V[]]} -
|
|
95
|
+
* @param {ArrayLike<V>} tree - Tree data
|
|
96
|
+
* @param {number | string} nodeId - Target node ID
|
|
97
|
+
* @param {ITreeConf} options - Configuration. Default: { childField = 'children', keyField = 'id' }
|
|
98
|
+
* @returns {[(number | string)[], V[]]} - Array of IDs and Array of Nodes from root to target
|
|
98
99
|
*/
|
|
99
|
-
export declare function
|
|
100
|
+
export declare function getPathById<V>(tree: ArrayLike<V>, nodeId: IdLike, options?: ITreeConf): [(number | string)[], any[]];
|
|
101
|
+
export { getPathById as searchTreeById };
|
|
100
102
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {any[]} list
|
|
103
|
-
* @param {IFieldOptions} options
|
|
103
|
+
* Converts a flat array into a tree structure.
|
|
104
|
+
* @param {any[]} list - Flat list of items
|
|
105
|
+
* @param {IFieldOptions} options - Customizes id field name, child element field name, parent element field name. Default:
|
|
104
106
|
* { keyField: 'key', childField: 'children', pidField: 'pid' }
|
|
105
|
-
* @returns {any[]}
|
|
107
|
+
* @returns {any[]} Tree structure array
|
|
106
108
|
*/
|
|
107
109
|
export declare function formatTree(list: any[], options?: IFieldOptions): any[];
|
|
108
110
|
/**
|
|
109
|
-
*
|
|
110
|
-
* @param {any[]} treeList
|
|
111
|
-
* @param {IFieldOptions} options
|
|
111
|
+
* Converts a tree structure into a flat array.
|
|
112
|
+
* @param {any[]} treeList - Tree structure array
|
|
113
|
+
* @param {IFieldOptions} options - Customizes id field name, child element field name, parent element field name. Default:
|
|
112
114
|
* { keyField: 'key', childField: 'children', pidField: 'pid' }
|
|
113
|
-
* @returns {any[]}
|
|
115
|
+
* @returns {any[]} Flat array
|
|
114
116
|
*/
|
|
115
117
|
export declare function flatTree(treeList: any[], options?: IFieldOptions): any[];
|
|
116
118
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
119
|
+
* Fuzzy search function that returns nodes containing the search character and their ancestor nodes.
|
|
120
|
+
* Suitable for character filtering in tree components.
|
|
121
|
+
*
|
|
122
|
+
* Two search conditions are available, processed in priority order:
|
|
123
|
+
* 1. Filter function `filter`, returning true/false.
|
|
124
|
+
* 2. Keyword matching, supporting case-insensitive check.
|
|
121
125
|
*
|
|
122
|
-
*
|
|
123
|
-
* 1.
|
|
124
|
-
* 2.
|
|
125
|
-
*
|
|
126
|
-
* @param {
|
|
127
|
-
* @param {
|
|
126
|
+
* Features:
|
|
127
|
+
* 1. Configurable `removeEmptyChild` field to decide whether to remove empty children fields in search results.
|
|
128
|
+
* 2. If no filter condition is provided, or keyword mode is used with an empty keyword, the original object is returned; otherwise, a new array is returned.
|
|
129
|
+
*
|
|
130
|
+
* @param {V[]} nodes - Tree nodes
|
|
131
|
+
* @param {IFilterCondition} filterCondition - Filter conditions
|
|
132
|
+
* @param {ISearchTreeOpts} options - Default configuration: {
|
|
128
133
|
childField: 'children',
|
|
129
134
|
nameField: 'name',
|
|
130
135
|
removeEmptyChild: false,
|
|
131
136
|
ignoreCase: true
|
|
132
137
|
}
|
|
133
|
-
* @returns {V[]}
|
|
138
|
+
* @returns {V[]} Filtered tree nodes
|
|
134
139
|
*/
|
|
135
140
|
export declare function fuzzySearchTree<V>(nodes: V[], filterCondition: IFilterCondition<V>, options?: ISearchTreeOpts): V[];
|
|
136
141
|
declare const _default: {
|
|
@@ -138,7 +143,8 @@ declare const _default: {
|
|
|
138
143
|
findDeep: typeof findDeep;
|
|
139
144
|
filterDeep: typeof filterDeep;
|
|
140
145
|
mapDeep: typeof mapDeep;
|
|
141
|
-
|
|
146
|
+
getPathById: typeof getPathById;
|
|
147
|
+
searchTreeById: typeof getPathById;
|
|
142
148
|
formatTree: typeof formatTree;
|
|
143
149
|
flatTree: typeof flatTree;
|
|
144
150
|
fuzzySearchTree: typeof fuzzySearchTree;
|