sculp-js 1.11.1-alpha.3 → 1.13.0

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.
Files changed (63) hide show
  1. package/lib/cjs/array.js +1 -1
  2. package/lib/cjs/async.js +32 -1
  3. package/lib/cjs/base64.js +1 -1
  4. package/lib/cjs/clipboard.js +5 -3
  5. package/lib/cjs/cloneDeep.js +1 -1
  6. package/lib/cjs/cookie.js +1 -1
  7. package/lib/cjs/date.js +1 -1
  8. package/lib/cjs/dom.js +1 -1
  9. package/lib/cjs/download.js +1 -1
  10. package/lib/cjs/easing.js +1 -1
  11. package/lib/cjs/file.js +1 -1
  12. package/lib/cjs/func.js +1 -1
  13. package/lib/cjs/index.js +2 -1
  14. package/lib/cjs/isEqual.js +1 -1
  15. package/lib/cjs/math.js +1 -1
  16. package/lib/cjs/number.js +1 -1
  17. package/lib/cjs/object.js +1 -1
  18. package/lib/cjs/path.js +1 -1
  19. package/lib/cjs/qs.js +1 -1
  20. package/lib/cjs/random.js +1 -1
  21. package/lib/cjs/string.js +1 -1
  22. package/lib/cjs/tooltip.js +1 -1
  23. package/lib/cjs/tree.js +126 -52
  24. package/lib/cjs/type.js +1 -1
  25. package/lib/cjs/unique.js +1 -1
  26. package/lib/cjs/url.js +1 -1
  27. package/lib/cjs/validator.js +1 -1
  28. package/lib/cjs/variable.js +1 -1
  29. package/lib/cjs/watermark.js +1 -1
  30. package/lib/cjs/we-decode.js +1 -1
  31. package/lib/es/array.js +1 -1
  32. package/lib/es/async.js +32 -2
  33. package/lib/es/base64.js +1 -1
  34. package/lib/es/clipboard.js +5 -3
  35. package/lib/es/cloneDeep.js +1 -1
  36. package/lib/es/cookie.js +1 -1
  37. package/lib/es/date.js +1 -1
  38. package/lib/es/dom.js +1 -1
  39. package/lib/es/download.js +1 -1
  40. package/lib/es/easing.js +1 -1
  41. package/lib/es/file.js +1 -1
  42. package/lib/es/func.js +1 -1
  43. package/lib/es/index.js +2 -2
  44. package/lib/es/isEqual.js +1 -1
  45. package/lib/es/math.js +1 -1
  46. package/lib/es/number.js +1 -1
  47. package/lib/es/object.js +1 -1
  48. package/lib/es/path.js +1 -1
  49. package/lib/es/qs.js +1 -1
  50. package/lib/es/random.js +1 -1
  51. package/lib/es/string.js +1 -1
  52. package/lib/es/tooltip.js +1 -1
  53. package/lib/es/tree.js +127 -53
  54. package/lib/es/type.js +1 -1
  55. package/lib/es/unique.js +1 -1
  56. package/lib/es/url.js +1 -1
  57. package/lib/es/validator.js +1 -1
  58. package/lib/es/variable.js +1 -1
  59. package/lib/es/watermark.js +1 -1
  60. package/lib/es/we-decode.js +1 -1
  61. package/lib/index.d.ts +72 -12
  62. package/lib/umd/index.js +2 -2
  63. package/package.json +3 -4
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -16,7 +16,7 @@ export { qsParse, qsStringify } from './qs.js';
16
16
  export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, parseQueryParams, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase } from './string.js';
17
17
  export { arrayLike, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, objectHas, typeIs } from './type.js';
18
18
  export { urlDelParams, urlParse, urlSetParams, urlStringify } from './url.js';
19
- export { asyncMap, wait } from './async.js';
19
+ export { asyncMap, safeAwait, wait } from './async.js';
20
20
  export { chooseLocalFile, compressImg, supportCanvas } from './file.js';
21
21
  export { genCanvasWM } from './watermark.js';
22
22
  export { debounce, getGlobal, once, setGlobal, throttle } from './func.js';
package/lib/es/isEqual.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/math.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/string.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/tooltip.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/tree.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- import { arrayEach } from './array.js';
8
7
  import { objectOmit } from './object.js';
9
- import { objectHas, isEmpty } from './type.js';
8
+ import { isObject, objectHas, isEmpty } from './type.js';
10
9
 
11
10
  const defaultFieldOptions = { keyField: 'key', childField: 'children', pidField: 'pid' };
12
11
  const defaultSearchTreeOptions = {
@@ -16,58 +15,126 @@ const defaultSearchTreeOptions = {
16
15
  ignoreCase: true
17
16
  };
18
17
  /**
19
- * 深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
18
+ * 树遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
20
19
  * @param {ArrayLike<V>} tree 树形数据
21
20
  * @param {Function} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
22
- * @param {string} children 定制子元素的key
23
- * @param {boolean} isReverse 是否反向遍历
21
+ * @param {options} options 支持定制子元素名称、反向遍历、广度优先遍历,默认{
22
+ childField: 'children',
23
+ reverse: false,
24
+ breadthFirst: false
25
+ }
24
26
  * @returns {*}
25
27
  */
26
- function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
28
+ function forEachDeep(tree, iterator, options = {
29
+ childField: 'children',
30
+ reverse: false,
31
+ breadthFirst: false
32
+ }) {
33
+ const { childField = 'children', reverse = false, breadthFirst = false } = isObject(options) ? options : {};
27
34
  let isBreak = false;
35
+ const queue = [];
28
36
  const walk = (arr, parent, level = 0) => {
29
- if (isReverse) {
30
- for (let i = arr.length - 1; i >= 0; i--) {
37
+ if (reverse) {
38
+ for (let index = arr.length - 1; index >= 0; index--) {
31
39
  if (isBreak) {
32
40
  break;
33
41
  }
34
- const re = iterator(arr[i], i, arr, tree, parent, level);
35
- if (re === false) {
36
- isBreak = true;
37
- break;
42
+ const item = arr[index];
43
+ // 广度优先
44
+ if (breadthFirst) {
45
+ queue.push({ item, index, array: arr, tree, parent, level });
38
46
  }
39
- else if (re === true) {
40
- continue;
47
+ else {
48
+ const re = iterator(item, index, arr, tree, parent, level);
49
+ if (re === false) {
50
+ isBreak = true;
51
+ break;
52
+ }
53
+ else if (re === true) {
54
+ continue;
55
+ }
56
+ // @ts-ignore
57
+ if (item && Array.isArray(item[childField])) {
58
+ // @ts-ignore
59
+ walk(item[childField], item, level + 1);
60
+ }
41
61
  }
42
- // @ts-ignore
43
- if (arr[i] && Array.isArray(arr[i][children])) {
62
+ }
63
+ if (breadthFirst) {
64
+ // Process queue
65
+ while (!isBreak) {
66
+ const current = queue.shift();
67
+ // iterate(info);
68
+ // @ts-ignore
69
+ const { item, index, array, tree, parent, level } = current;
70
+ const re = iterator(item, index, array, tree, parent, level);
71
+ if (re === false) {
72
+ isBreak = true;
73
+ break;
74
+ }
75
+ else if (re === true) {
76
+ continue;
77
+ }
44
78
  // @ts-ignore
45
- walk(arr[i][children], arr[i], level + 1);
79
+ if (item && Array.isArray(item[childField])) {
80
+ // @ts-ignore
81
+ walk(item[childField], item, level + 1);
82
+ }
46
83
  }
47
84
  }
48
85
  }
49
86
  else {
50
- for (let i = 0, len = arr.length; i < len; i++) {
87
+ for (let index = 0, len = arr.length; index < len; index++) {
51
88
  if (isBreak) {
52
89
  break;
53
90
  }
54
- const re = iterator(arr[i], i, arr, tree, parent, level);
55
- if (re === false) {
56
- isBreak = true;
57
- break;
91
+ const item = arr[index];
92
+ if (breadthFirst) {
93
+ // 广度优先
94
+ queue.push({ item, index: index, array: arr, tree, parent, level });
58
95
  }
59
- else if (re === true) {
60
- continue;
96
+ else {
97
+ // 深度优先
98
+ const re = iterator(item, index, arr, tree, parent, level);
99
+ if (re === false) {
100
+ isBreak = true;
101
+ break;
102
+ }
103
+ else if (re === true) {
104
+ continue;
105
+ }
106
+ // @ts-ignore
107
+ if (item && Array.isArray(item[childField])) {
108
+ // @ts-ignore
109
+ walk(item[childField], item, level + 1);
110
+ }
61
111
  }
62
- // @ts-ignore
63
- if (arr[i] && Array.isArray(arr[i][children])) {
112
+ }
113
+ if (breadthFirst) {
114
+ while (!isBreak) {
115
+ const current = queue.shift();
116
+ if (!current)
117
+ break;
118
+ // @ts-ignore
119
+ const { item, index, array, tree, parent, level } = current;
120
+ const re = iterator(item, index, array, tree, parent, level);
121
+ if (re === false) {
122
+ isBreak = true;
123
+ break;
124
+ }
125
+ else if (re === true) {
126
+ continue;
127
+ }
64
128
  // @ts-ignore
65
- walk(arr[i][children], arr[i], level + 1);
129
+ if (item && Array.isArray(item[childField])) {
130
+ // @ts-ignore
131
+ walk(item[childField], item, level + 1);
132
+ }
66
133
  }
67
134
  }
68
135
  }
69
136
  };
70
- walk(tree, null);
137
+ walk(tree, null, 0);
71
138
  // @ts-ignore
72
139
  tree = null;
73
140
  }
@@ -179,17 +246,20 @@ function searchTreeById(tree, nodeId, config) {
179
246
  /**
180
247
  * 扁平化数组转换成树
181
248
  * @param {any[]} list
182
- * @param {IFieldOptions} options
249
+ * @param {IFieldOptions} options 定制id字段名,子元素字段名,父元素字段名,默认
250
+ * { keyField: 'key', childField: 'children', pidField: 'pid' }
183
251
  * @returns {any[]}
184
252
  */
185
253
  function formatTree(list, options = defaultFieldOptions) {
186
- const { keyField, childField, pidField } = options;
254
+ const { keyField = 'key', childField = 'children', pidField = 'pid' } = isObject(options) ? options : {};
187
255
  const treeArr = [];
188
256
  const sourceMap = {};
189
- arrayEach(list, item => {
257
+ for (let i = 0, len = list.length; i < len; i++) {
258
+ const item = list[i];
190
259
  sourceMap[item[keyField]] = item;
191
- });
192
- arrayEach(list, item => {
260
+ }
261
+ for (let i = 0, len = list.length; i < len; i++) {
262
+ const item = list[i];
193
263
  const parent = sourceMap[item[pidField]];
194
264
  if (parent) {
195
265
  (parent[childField] || (parent[childField] = [])).push(item);
@@ -197,21 +267,23 @@ function formatTree(list, options = defaultFieldOptions) {
197
267
  else {
198
268
  treeArr.push(item);
199
269
  }
200
- });
270
+ }
201
271
  // @ts-ignore
202
272
  list = null;
203
273
  return treeArr;
204
274
  }
205
275
  /**
206
276
  * 树形结构转扁平化
207
- * @param {any} treeList
208
- * @param {IFieldOptions} options
209
- * @returns {*}
277
+ * @param {any[]} treeList
278
+ * @param {IFieldOptions} options 定制id字段名,子元素字段名,父元素字段名,默认
279
+ * { keyField: 'key', childField: 'children', pidField: 'pid' }
280
+ * @returns {any[]}
210
281
  */
211
282
  function flatTree(treeList, options = defaultFieldOptions) {
212
- const { childField, keyField, pidField } = options;
283
+ const { keyField = 'key', childField = 'children', pidField = 'pid' } = isObject(options) ? options : {};
213
284
  let res = [];
214
- arrayEach(treeList, node => {
285
+ for (let i = 0, len = treeList.length; i < len; i++) {
286
+ const node = treeList[i];
215
287
  const item = {
216
288
  ...node,
217
289
  [childField]: [] // 清空子级
@@ -225,7 +297,7 @@ function flatTree(treeList, options = defaultFieldOptions) {
225
297
  }));
226
298
  res = res.concat(flatTree(children, options));
227
299
  }
228
- });
300
+ }
229
301
  return res;
230
302
  }
231
303
  /**
@@ -239,7 +311,12 @@ function flatTree(treeList, options = defaultFieldOptions) {
239
311
  * 2. 若无任何过滤条件或keyword模式匹配且keyword为空串,返回原对象;其他情况返回新数组
240
312
  * @param {V[]} nodes
241
313
  * @param {IFilterCondition} filterCondition
242
- * @param {ISearchTreeOpts} options
314
+ * @param {ISearchTreeOpts} options 默认配置项 {
315
+ childField: 'children',
316
+ nameField: 'name',
317
+ removeEmptyChild: false,
318
+ ignoreCase: true
319
+ }
243
320
  * @returns {V[]}
244
321
  */
245
322
  function fuzzySearchTree(nodes, filterCondition, options = defaultSearchTreeOptions) {
@@ -248,7 +325,8 @@ function fuzzySearchTree(nodes, filterCondition, options = defaultSearchTreeOpti
248
325
  return nodes;
249
326
  }
250
327
  const result = [];
251
- arrayEach(nodes, node => {
328
+ for (let i = 0, len = nodes.length; i < len; i++) {
329
+ const node = nodes[i];
252
330
  // 递归检查子节点是否匹配
253
331
  const matchedChildren = node[options.childField] && node[options.childField].length > 0
254
332
  ? fuzzySearchTree(node[options.childField] || [], filterCondition, options)
@@ -269,26 +347,22 @@ function fuzzySearchTree(nodes, filterCondition, options = defaultSearchTreeOpti
269
347
  });
270
348
  }
271
349
  else if (options.removeEmptyChild) {
272
- node[options.childField] && delete node[options.childField];
273
- result.push({
274
- ...node
275
- });
350
+ const { [options.childField]: _, ...other } = node;
351
+ result.push(other);
276
352
  }
277
353
  else {
278
354
  result.push({
279
355
  ...node,
280
- ...{ [options.childField]: [] }
356
+ [options.childField]: []
281
357
  });
282
358
  }
283
359
  }
284
360
  else {
285
- node[options.childField] && delete node[options.childField];
286
- result.push({
287
- ...node
288
- });
361
+ const { [options.childField]: _, ...other } = node;
362
+ result.push(other);
289
363
  }
290
364
  }
291
- });
365
+ }
292
366
  return result;
293
367
  }
294
368
 
package/lib/es/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.11.1-alpha.3
2
+ * sculp-js v1.13.0
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/index.d.ts CHANGED
@@ -11,6 +11,30 @@ type AsyncCallback = {
11
11
  successCallback?: Function;
12
12
  failCallback?: Function;
13
13
  };
14
+ interface Fn<T = any, R = T> {
15
+ (...arg: T[]): R;
16
+ }
17
+ interface PromiseFn<T = any, R = T> {
18
+ (...arg: T[]): Promise<R>;
19
+ }
20
+ /**
21
+ * 将除指定属性外的所有属性变为必填
22
+ *
23
+ * Change all properties except the specified properties to required
24
+ */
25
+ type ChangeRequiredExcept<T, K extends keyof T> = Required<Omit<T, K>> & Partial<Pick<T, K>>;
26
+ /**
27
+ * 将指定属性变为可选
28
+ *
29
+ * Change the specified properties to optional
30
+ */
31
+ type ChangeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
32
+ /**
33
+ * 将指定属性变为必填
34
+ *
35
+ * Change the specified properties to required
36
+ */
37
+ type ChangeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
14
38
  type PartialDeep<T> = {
15
39
  [P in keyof T]?: PartialDeep<T[P]>;
16
40
  };
@@ -150,9 +174,11 @@ type CopyTextOptions = AsyncCallback & {
150
174
  container?: HTMLElement;
151
175
  };
152
176
  /**
153
- * 复制文本,优先使用navigator.clipboard,若不支持则回退使用execCommand方式
177
+ * 复制文本,优先使用navigator.clipboard,仅在安全上下文(HTTPS/localhost)下生效,若不支持则回退使用execCommand方式
154
178
  * @param {string} text
155
- * @param {AsyncCallback} options 可选参数:成功回调、失败回调、容器元素
179
+ * @param {CopyTextOptions} options 可选参数:成功回调successCallback、失败回调failCallback、容器元素container
180
+ * (默认document.body, 当不支持clipboard时必须传复制按钮元素,包裹模拟选择操作的临时元素,
181
+ * 解决脱离文档流的元素无法复制的问题,如Modal内复制操作)
156
182
  */
157
183
  declare function copyText(text: string, options?: CopyTextOptions): void;
158
184
  /**
@@ -604,6 +630,26 @@ declare function wait(timeout?: number): Promise<void>;
604
630
  * @returns {Promise<R[]>}
605
631
  */
606
632
  declare function asyncMap<T, R>(list: Array<T>, mapper: (val: T, idx: number, list: Array<T>) => Promise<R>, concurrency?: number): Promise<R[]>;
633
+ /**
634
+ * Execute a promise safely
635
+ *
636
+ * @param { Promise } promise
637
+ * @param { Object= } errorExt - Additional Information you can pass safeAwait the err object
638
+ * @return { Promise }
639
+ * @example
640
+ * async function asyncTaskWithCb(cb) {
641
+ let err, user, savedTask, notification;
642
+
643
+ [ err, user ] = await safeAwait(UserModel.findById(1));
644
+ if(!user) return cb('No user found');
645
+
646
+ [ err, savedTask ] = await safeAwait(TaskModel({userId: user.id, name: 'Demo Task'}));
647
+ if(err) return cb('Error occurred while saving task')
648
+
649
+ cb(null, savedTask);
650
+ }
651
+ */
652
+ declare function safeAwait<T, U = Error>(promise: Promise<T>, errorExt?: object): Promise<[U, undefined] | [null, T]>;
607
653
 
608
654
  /**
609
655
  * 判断是否支持canvas
@@ -863,14 +909,21 @@ interface IFilterCondition<V> {
863
909
  filter?: (args: V) => boolean;
864
910
  }
865
911
  /**
866
- * 深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
912
+ * 树遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
867
913
  * @param {ArrayLike<V>} tree 树形数据
868
914
  * @param {Function} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
869
- * @param {string} children 定制子元素的key
870
- * @param {boolean} isReverse 是否反向遍历
915
+ * @param {options} options 支持定制子元素名称、反向遍历、广度优先遍历,默认{
916
+ childField: 'children',
917
+ reverse: false,
918
+ breadthFirst: false
919
+ }
871
920
  * @returns {*}
872
921
  */
873
- declare function forEachDeep<V>(tree: ArrayLike<V>, iterator: (val: V, i: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => boolean | void, children?: string, isReverse?: boolean): void;
922
+ declare function forEachDeep<V>(tree: ArrayLike<V>, iterator: (val: V, index: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => boolean | void, options?: {
923
+ childField?: string;
924
+ reverse?: boolean;
925
+ breadthFirst?: boolean;
926
+ }): void;
874
927
  /**
875
928
  * 创建一个新数组, 深度优先遍历的Map函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
876
929
  *
@@ -901,15 +954,17 @@ declare function searchTreeById<V>(tree: ArrayLike<V>, nodeId: IdLike, config?:
901
954
  /**
902
955
  * 扁平化数组转换成树
903
956
  * @param {any[]} list
904
- * @param {IFieldOptions} options
957
+ * @param {IFieldOptions} options 定制id字段名,子元素字段名,父元素字段名,默认
958
+ * { keyField: 'key', childField: 'children', pidField: 'pid' }
905
959
  * @returns {any[]}
906
960
  */
907
961
  declare function formatTree(list: any[], options?: IFieldOptions): any[];
908
962
  /**
909
963
  * 树形结构转扁平化
910
- * @param {any} treeList
911
- * @param {IFieldOptions} options
912
- * @returns {*}
964
+ * @param {any[]} treeList
965
+ * @param {IFieldOptions} options 定制id字段名,子元素字段名,父元素字段名,默认
966
+ * { keyField: 'key', childField: 'children', pidField: 'pid' }
967
+ * @returns {any[]}
913
968
  */
914
969
  declare function flatTree(treeList: any[], options?: IFieldOptions): any[];
915
970
  /**
@@ -923,7 +978,12 @@ declare function flatTree(treeList: any[], options?: IFieldOptions): any[];
923
978
  * 2. 若无任何过滤条件或keyword模式匹配且keyword为空串,返回原对象;其他情况返回新数组
924
979
  * @param {V[]} nodes
925
980
  * @param {IFilterCondition} filterCondition
926
- * @param {ISearchTreeOpts} options
981
+ * @param {ISearchTreeOpts} options 默认配置项 {
982
+ childField: 'children',
983
+ nameField: 'name',
984
+ removeEmptyChild: false,
985
+ ignoreCase: true
986
+ }
927
987
  * @returns {V[]}
928
988
  */
929
989
  declare function fuzzySearchTree<V>(nodes: V[], filterCondition: IFilterCondition<V>, options?: ISearchTreeOpts): V[];
@@ -1148,4 +1208,4 @@ type Comparable = null | undefined | boolean | number | string | Date | RegExp |
1148
1208
  */
1149
1209
  declare function isEqual(a: Comparable, b: Comparable): boolean;
1150
1210
 
1151
- export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type AsyncCallback, type Comparable, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressImgResult, type ICompressOptions, type IFieldOptions, type IFilterCondition, IPV4_REGEX, IPV6_REGEX, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, PHONE_REGEX, type Params, type PartialDeep, type RandomString, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, URL_REGEX, type UniqueString, type Url, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, decodeFromBase64, divide, downloadBlob, downloadData, downloadHref, downloadURL, encodeToBase64, escapeRegExp, executeInScope, fallbackCopyText, flatTree, forEachDeep, formatDate, formatNumber as formatMoney, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, humanFileSize, isArray, isBigInt, isBoolean, isDate, isDigit, isEmail, isEmpty, isEqual, isError, isFloat, isFunction, isIdNo, isInteger, isIpV4, isIpV6, isJsonString, isNaN, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isNumerical, isObject, isPhone, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isUrl, isValidDate, mapDeep, multiply, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, once, parseQueryParams, parseVarFromString, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, replaceVarFromString, searchTreeById, select, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, strip, subtract, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, uniqueSymbol, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };
1211
+ export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type AsyncCallback, type ChangeOptional, type ChangeRequired, type ChangeRequiredExcept, type Comparable, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, type Fn, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressImgResult, type ICompressOptions, type IFieldOptions, type IFilterCondition, IPV4_REGEX, IPV6_REGEX, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, PHONE_REGEX, type Params, type PartialDeep, type PromiseFn, type RandomString, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, URL_REGEX, type UniqueString, type Url, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, decodeFromBase64, divide, downloadBlob, downloadData, downloadHref, downloadURL, encodeToBase64, escapeRegExp, executeInScope, fallbackCopyText, flatTree, forEachDeep, formatDate, formatNumber as formatMoney, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, humanFileSize, isArray, isBigInt, isBoolean, isDate, isDigit, isEmail, isEmpty, isEqual, isError, isFloat, isFunction, isIdNo, isInteger, isIpV4, isIpV6, isJsonString, isNaN, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isNumerical, isObject, isPhone, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isUrl, isValidDate, mapDeep, multiply, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, once, parseQueryParams, parseVarFromString, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, replaceVarFromString, safeAwait, searchTreeById, select, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, strip, subtract, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, uniqueSymbol, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };