sculp-js 1.0.0 → 1.1.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.
- package/README.md +106 -9
- package/lib/cjs/array.js +116 -16
- package/lib/cjs/async.js +1 -1
- package/lib/cjs/clipboard.js +1 -1
- package/lib/cjs/cookie.js +1 -1
- package/lib/cjs/date.js +1 -1
- package/lib/cjs/dom.js +1 -1
- package/lib/cjs/download.js +1 -1
- package/lib/cjs/easing.js +1 -1
- package/lib/cjs/file.js +1 -1
- package/lib/cjs/func.js +1 -1
- package/lib/cjs/index.js +6 -3
- package/lib/cjs/number.js +1 -1
- package/lib/cjs/object.js +1 -1
- package/lib/cjs/path.js +1 -1
- package/lib/cjs/qs.js +1 -1
- package/lib/cjs/random.js +1 -1
- package/lib/cjs/string.js +1 -1
- package/lib/cjs/tooltip.js +118 -0
- package/lib/cjs/type.js +1 -1
- package/lib/cjs/unique.js +1 -1
- package/lib/cjs/url.js +1 -1
- package/lib/cjs/watermark.js +1 -1
- package/lib/es/array.js +114 -15
- package/lib/es/async.js +1 -1
- package/lib/es/clipboard.js +1 -1
- package/lib/es/cookie.js +1 -1
- package/lib/es/date.js +1 -1
- package/lib/es/dom.js +1 -1
- package/lib/es/download.js +1 -1
- package/lib/es/easing.js +1 -1
- package/lib/es/file.js +1 -1
- package/lib/es/func.js +1 -1
- package/lib/es/index.js +3 -2
- package/lib/es/number.js +1 -1
- package/lib/es/object.js +1 -1
- package/lib/es/path.js +1 -1
- package/lib/es/qs.js +1 -1
- package/lib/es/random.js +1 -1
- package/lib/es/string.js +1 -1
- package/lib/es/tooltip.js +116 -0
- package/lib/es/type.js +1 -1
- package/lib/es/unique.js +1 -1
- package/lib/es/url.js +1 -1
- package/lib/es/watermark.js +1 -1
- package/lib/index.d.ts +77 -8
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/umd/index.js +224 -16
- package/package.json +7 -6
package/lib/es/array.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.0.
|
|
2
|
+
* sculp-js v1.0.1
|
|
3
3
|
* (c) 2023-2023 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -23,26 +23,32 @@ function arrayLike(any) {
|
|
|
23
23
|
return objectHas(any, 'length');
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* 遍历数组,返回 false 中断遍历
|
|
26
|
+
* 遍历数组,返回 false 中断遍历(支持continue和break操作)
|
|
27
27
|
*
|
|
28
28
|
* @param {ArrayLike<V>} array
|
|
29
|
-
* @param {(val: V, idx: number) => any} iterator
|
|
30
|
-
* @param
|
|
29
|
+
* @param {(val: V, idx: number) => any} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
|
|
30
|
+
* @param {boolean} reverse 是否倒序
|
|
31
31
|
* @returns {*}
|
|
32
32
|
*/
|
|
33
33
|
function arrayEach(array, iterator, reverse = false) {
|
|
34
34
|
if (reverse) {
|
|
35
35
|
for (let idx = array.length - 1; idx >= 0; idx--) {
|
|
36
36
|
const val = array[idx];
|
|
37
|
-
|
|
37
|
+
const re = iterator(val, idx, array);
|
|
38
|
+
if (re === false)
|
|
38
39
|
break;
|
|
40
|
+
else if (re === true)
|
|
41
|
+
continue;
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
else {
|
|
42
45
|
for (let idx = 0; idx < array.length; idx++) {
|
|
43
46
|
const val = array[idx];
|
|
44
|
-
|
|
47
|
+
const re = iterator(val, idx, array);
|
|
48
|
+
if (re === false)
|
|
45
49
|
break;
|
|
50
|
+
else if (re === true)
|
|
51
|
+
continue;
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
}
|
|
@@ -104,21 +110,25 @@ function arrayRemove(array, expect) {
|
|
|
104
110
|
/**
|
|
105
111
|
* 自定义深度优先遍历函数(支持continue和break操作)
|
|
106
112
|
* @param {ArrayLike<V>} tree 树形数据
|
|
107
|
-
* @param {Function} iterator
|
|
113
|
+
* @param {Function} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
|
|
108
114
|
* @param {string} children 定制子元素的key
|
|
109
115
|
* @param {boolean} isReverse 是否反向遍历
|
|
110
116
|
* @returns {*}
|
|
111
117
|
*/
|
|
112
|
-
function
|
|
113
|
-
let level = 0;
|
|
118
|
+
function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
119
|
+
let level = 0, isBreak = false;
|
|
114
120
|
const walk = (arr, parent) => {
|
|
115
121
|
if (isReverse) {
|
|
116
122
|
for (let i = arr.length - 1; i >= 0; i--) {
|
|
123
|
+
if (isBreak) {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
117
126
|
const re = iterator(arr[i], i, tree, parent, level);
|
|
118
|
-
if (re ===
|
|
127
|
+
if (re === false) {
|
|
128
|
+
isBreak = true;
|
|
119
129
|
break;
|
|
120
130
|
}
|
|
121
|
-
else if (re ===
|
|
131
|
+
else if (re === true) {
|
|
122
132
|
continue;
|
|
123
133
|
}
|
|
124
134
|
// @ts-ignore
|
|
@@ -131,11 +141,15 @@ function deepTraversal(tree, iterator, children = 'children', isReverse = false)
|
|
|
131
141
|
}
|
|
132
142
|
else {
|
|
133
143
|
for (let i = 0; i < arr.length; i++) {
|
|
144
|
+
if (isBreak) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
134
147
|
const re = iterator(arr[i], i, tree, parent, level);
|
|
135
|
-
if (re ===
|
|
148
|
+
if (re === false) {
|
|
149
|
+
isBreak = true;
|
|
136
150
|
break;
|
|
137
151
|
}
|
|
138
|
-
else if (re ===
|
|
152
|
+
else if (re === true) {
|
|
139
153
|
continue;
|
|
140
154
|
}
|
|
141
155
|
// @ts-ignore
|
|
@@ -157,7 +171,7 @@ function deepTraversal(tree, iterator, children = 'children', isReverse = false)
|
|
|
157
171
|
* @param {ITreeConf} config - 迭代配置项
|
|
158
172
|
* @returns {[IdLike[], ITreeItem<V>[]]} - 由parentId...childId, parentObject-childObject组成的二维数组
|
|
159
173
|
*/
|
|
160
|
-
function
|
|
174
|
+
function searchTreeById(tree, nodeId, config) {
|
|
161
175
|
const { children = 'children', id = 'id' } = config || {};
|
|
162
176
|
const toFlatArray = (tree, parentId, parent) => {
|
|
163
177
|
return tree.reduce((t, _) => {
|
|
@@ -182,5 +196,90 @@ function getTreeIds(tree, nodeId, config) {
|
|
|
182
196
|
};
|
|
183
197
|
return getIds(toFlatArray(tree));
|
|
184
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* 使用迭代函数转换数组
|
|
201
|
+
* @param {T} array
|
|
202
|
+
* @param {Function} callback 迭代函数
|
|
203
|
+
* @return {Array}
|
|
204
|
+
*/
|
|
205
|
+
function flatMap(array, callback) {
|
|
206
|
+
const result = [];
|
|
207
|
+
array.forEach((value, index) => {
|
|
208
|
+
result.push(...callback(value, index, array));
|
|
209
|
+
});
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* 根据 idProp 与 parentIdProp 从对象数组中构建对应的树
|
|
214
|
+
* 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。
|
|
215
|
+
* 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
|
|
216
|
+
* @param {string} idProp 元素ID
|
|
217
|
+
* @param {string} parentIdProp 父元素ID
|
|
218
|
+
* @param {object[]} items 一维数组
|
|
219
|
+
* @returns {WithChildren<T>[]} 树
|
|
220
|
+
* @example
|
|
221
|
+
* const array = [
|
|
222
|
+
* { id: 'node-1', parent: 'root' },
|
|
223
|
+
* { id: 'node-2', parent: 'root' },
|
|
224
|
+
* { id: 'node-3', parent: 'node-2' },
|
|
225
|
+
* { id: 'node-4', parent: 'node-2' },
|
|
226
|
+
* { id: 'node-5', parent: 'node-4' },
|
|
227
|
+
* ]
|
|
228
|
+
* const tree = buildTree('id', 'parent', array)
|
|
229
|
+
* expect(tree).toEqual([
|
|
230
|
+
* { id: 'node-1', parent: 'root' },
|
|
231
|
+
* {
|
|
232
|
+
* id: 'node-2',
|
|
233
|
+
* parent: 'root',
|
|
234
|
+
* children: [
|
|
235
|
+
* { id: 'node-3', parent: 'node-2' },
|
|
236
|
+
* {
|
|
237
|
+
* id: 'node-4',
|
|
238
|
+
* parent: 'node-2',
|
|
239
|
+
* children: [{ id: 'node-5', parent: 'node-4' }],
|
|
240
|
+
* },
|
|
241
|
+
* ],
|
|
242
|
+
* },
|
|
243
|
+
* ])
|
|
244
|
+
*/
|
|
245
|
+
function buildTree(idProp, parentIdProp, items) {
|
|
246
|
+
const wrapperMap = new Map();
|
|
247
|
+
const ensure = (id) => {
|
|
248
|
+
if (wrapperMap.has(id)) {
|
|
249
|
+
return wrapperMap.get(id);
|
|
250
|
+
}
|
|
251
|
+
//@ts-ignore
|
|
252
|
+
const wrapper = { id, parent: null, item: null, children: [] };
|
|
253
|
+
wrapperMap.set(id, wrapper);
|
|
254
|
+
return wrapper;
|
|
255
|
+
};
|
|
256
|
+
for (const item of items) {
|
|
257
|
+
const parentWrapper = ensure(item[parentIdProp]);
|
|
258
|
+
const itemWrapper = ensure(item[idProp]);
|
|
259
|
+
//@ts-ignore
|
|
260
|
+
itemWrapper.parent = parentWrapper;
|
|
261
|
+
//@ts-ignore
|
|
262
|
+
parentWrapper.children.push(itemWrapper);
|
|
263
|
+
//@ts-ignore
|
|
264
|
+
itemWrapper.item = item;
|
|
265
|
+
}
|
|
266
|
+
const topLevelWrappers = flatMap(Array.from(wrapperMap.values()).filter(wrapper => wrapper.parent === null), wrapper => wrapper.children);
|
|
267
|
+
return unwrapRecursively(topLevelWrappers);
|
|
268
|
+
function unwrapRecursively(wrapperArray) {
|
|
269
|
+
const result = [];
|
|
270
|
+
for (const wrapper of wrapperArray) {
|
|
271
|
+
if (wrapper.children.length === 0) {
|
|
272
|
+
result.push(wrapper.item);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
result.push({
|
|
276
|
+
...wrapper.item,
|
|
277
|
+
children: unwrapRecursively(wrapper.children)
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
185
284
|
|
|
186
|
-
export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove,
|
|
285
|
+
export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, buildTree, forEachDeep, searchTreeById };
|
package/lib/es/async.js
CHANGED
package/lib/es/clipboard.js
CHANGED
package/lib/es/cookie.js
CHANGED
package/lib/es/date.js
CHANGED
package/lib/es/dom.js
CHANGED
package/lib/es/download.js
CHANGED
package/lib/es/easing.js
CHANGED
package/lib/es/file.js
CHANGED
package/lib/es/func.js
CHANGED
package/lib/es/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.0.
|
|
2
|
+
* sculp-js v1.0.1
|
|
3
3
|
* (c) 2023-2023 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove,
|
|
7
|
+
export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, buildTree, forEachDeep, searchTreeById } from './array.js';
|
|
8
8
|
export { copyText } from './clipboard.js';
|
|
9
9
|
export { cookieDel, cookieGet, cookieSet } from './cookie.js';
|
|
10
10
|
export { calculateDate, calculateDateTime, dateParse, dateToEnd, dateToStart, formatDate, isValidDate } from './date.js';
|
|
@@ -23,3 +23,4 @@ export { debounce, getGlobal, once, setGlobal, throttle } from './func.js';
|
|
|
23
23
|
export { STRING_POOL, randomNumber, randomString, randomUuid } from './random.js';
|
|
24
24
|
export { HEX_POOL, formatNumber, numberAbbr, numberToHex } from './number.js';
|
|
25
25
|
export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.js';
|
|
26
|
+
export { tooltipEvent } from './tooltip.js';
|
package/lib/es/number.js
CHANGED
package/lib/es/object.js
CHANGED
package/lib/es/path.js
CHANGED
package/lib/es/qs.js
CHANGED
package/lib/es/random.js
CHANGED
package/lib/es/string.js
CHANGED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* sculp-js v1.0.1
|
|
3
|
+
* (c) 2023-2023 chandq
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getStrWidthPx } from './string.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @title tooltip
|
|
11
|
+
* @Desc 自定义的tooltip方法, 支持拖动悬浮提示
|
|
12
|
+
* Created by chendeqiao on 2017/5/8.
|
|
13
|
+
* @example
|
|
14
|
+
* <span onmouseleave="handleMouseLeave('#root')" onmousemove="handleMouseEnter({rootElId: '#root', title: 'title content', event: event})"
|
|
15
|
+
* onmouseenter="handleMouseEnter({'#root', title: 'title content', event: event})">title content </span>
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* 自定义title提示功能的mouseenter事件句柄
|
|
19
|
+
* @param {ITooltipParams} param1
|
|
20
|
+
* @returns {*}
|
|
21
|
+
*/
|
|
22
|
+
function handleMouseEnter({ rootElId = '#root', title, event }) {
|
|
23
|
+
try {
|
|
24
|
+
const $rootEl = document.querySelector(rootElId);
|
|
25
|
+
console.assert($rootEl !== null, `未找到id为 ${rootElId} 的dom元素`);
|
|
26
|
+
let $customTitle = null;
|
|
27
|
+
// 动态创建class样式,并加入到head中
|
|
28
|
+
if (!document.querySelector('.tooltip-inner1494304949567')) {
|
|
29
|
+
const tooltipWrapperClass = document.createElement('style');
|
|
30
|
+
tooltipWrapperClass.type = 'text/css';
|
|
31
|
+
tooltipWrapperClass.innerHTML = `
|
|
32
|
+
.tooltip-inner1494304949567 {
|
|
33
|
+
max-width: 250px;
|
|
34
|
+
padding: 3px 8px;
|
|
35
|
+
color: #fff;
|
|
36
|
+
text-decoration: none;
|
|
37
|
+
border-radius: 4px;
|
|
38
|
+
text-align: left;
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
document.querySelector('head').appendChild(tooltipWrapperClass);
|
|
42
|
+
}
|
|
43
|
+
if (document.querySelector('#customTitle1494304949567')) {
|
|
44
|
+
$customTitle = document.querySelector('#customTitle1494304949567');
|
|
45
|
+
mouseenter($customTitle, title, event);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const $contentContainer = document.createElement('div');
|
|
49
|
+
$contentContainer.className = 'customTitle';
|
|
50
|
+
$contentContainer.id = 'customTitle1494304949567';
|
|
51
|
+
$contentContainer.className = 'tooltip';
|
|
52
|
+
$contentContainer.style.cssText = 'z-index: 99999999; visibility: hidden;';
|
|
53
|
+
$contentContainer.innerHTML =
|
|
54
|
+
'<div class="tooltip-inner1494304949567" style="word-wrap: break-word; max-width: 44px;">皮肤</div>';
|
|
55
|
+
$rootEl.appendChild($contentContainer);
|
|
56
|
+
$customTitle = document.querySelector('#customTitle1494304949567');
|
|
57
|
+
if (title) {
|
|
58
|
+
//判断div显示的内容是否为空
|
|
59
|
+
mouseenter($customTitle, title, event);
|
|
60
|
+
$customTitle.style.visibility = 'visible';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error(e.message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 提示文案dom渲染的处理函数
|
|
70
|
+
* @param {HTMLDivElement} customTitle
|
|
71
|
+
* @param {string} title 提示的字符串
|
|
72
|
+
* @param {PointerEvent} e 事件对象
|
|
73
|
+
* @returns {*}
|
|
74
|
+
*/
|
|
75
|
+
function mouseenter($customTitle, title, e) {
|
|
76
|
+
let diffValueX = 200 + 50; //默认设置弹出div的宽度为250px
|
|
77
|
+
let x = 13;
|
|
78
|
+
const y = 23;
|
|
79
|
+
const $contentEle = $customTitle.children[0];
|
|
80
|
+
if (getStrWidthPx(title, 12) < 180 + 50) {
|
|
81
|
+
//【弹出div自适应字符串宽度】若显示的字符串占用宽度小于180,则设置弹出div的宽度为“符串占用宽度”+20
|
|
82
|
+
$contentEle.style.maxWidth = getStrWidthPx(title, 12) + 20 + 50 + 'px';
|
|
83
|
+
diffValueX = e.clientX + (getStrWidthPx(title, 12) + 50) - document.body.offsetWidth;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
$contentEle.style.maxWidth = '250px';
|
|
87
|
+
diffValueX = e.clientX + 230 - document.body.offsetWidth; //计算div水平方向显示的内容超出屏幕多少宽度
|
|
88
|
+
}
|
|
89
|
+
$contentEle.innerHTML = title; //html方法可解析内容中换行标签,text方法不能
|
|
90
|
+
if (diffValueX > 0) {
|
|
91
|
+
//水平方向超出可见区域时
|
|
92
|
+
x -= diffValueX;
|
|
93
|
+
}
|
|
94
|
+
$customTitle.style.top = e.clientY + y + 'px';
|
|
95
|
+
$customTitle.style.left = e.clientX + x + 'px';
|
|
96
|
+
$customTitle.style.maxWidth = '250px';
|
|
97
|
+
const diffValueY = $customTitle.getBoundingClientRect().top + $contentEle.offsetHeight - document.body.offsetHeight;
|
|
98
|
+
if (diffValueY > 0) {
|
|
99
|
+
//垂直方向超出可见区域时
|
|
100
|
+
$customTitle.style.top = e.clientY - diffValueY + 'px';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 移除提示文案dom的事件句柄
|
|
105
|
+
* @param {string} rootElId
|
|
106
|
+
* @returns {*}
|
|
107
|
+
*/
|
|
108
|
+
function handleMouseLeave(rootElId = '#root') {
|
|
109
|
+
const rootEl = document.querySelector(rootElId), titleEl = document.querySelector('#customTitle1494304949567');
|
|
110
|
+
if (rootEl && titleEl) {
|
|
111
|
+
rootEl.removeChild(titleEl);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const tooltipEvent = { handleMouseEnter, handleMouseLeave };
|
|
115
|
+
|
|
116
|
+
export { tooltipEvent };
|
package/lib/es/type.js
CHANGED
package/lib/es/unique.js
CHANGED
package/lib/es/url.js
CHANGED
package/lib/es/watermark.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -44,14 +44,14 @@ declare const isRegExp: (any: unknown) => any is RegExp;
|
|
|
44
44
|
*/
|
|
45
45
|
declare function arrayLike(any: unknown): boolean;
|
|
46
46
|
/**
|
|
47
|
-
* 遍历数组,返回 false 中断遍历
|
|
47
|
+
* 遍历数组,返回 false 中断遍历(支持continue和break操作)
|
|
48
48
|
*
|
|
49
49
|
* @param {ArrayLike<V>} array
|
|
50
|
-
* @param {(val: V, idx: number) => any} iterator
|
|
51
|
-
* @param
|
|
50
|
+
* @param {(val: V, idx: number) => any} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
|
|
51
|
+
* @param {boolean} reverse 是否倒序
|
|
52
52
|
* @returns {*}
|
|
53
53
|
*/
|
|
54
|
-
declare function arrayEach<V>(array: ArrayLike<V>, iterator: (val: V, idx: number, arr: ArrayLike<V>) =>
|
|
54
|
+
declare function arrayEach<V>(array: ArrayLike<V>, iterator: (val: V, idx: number, arr: ArrayLike<V>) => boolean | void, reverse?: boolean): void;
|
|
55
55
|
/**
|
|
56
56
|
* 异步遍历数组,返回 false 中断遍历
|
|
57
57
|
* @param {ArrayLike<V>} array 数组
|
|
@@ -77,12 +77,12 @@ declare function arrayRemove<V>(array: V[], expect: (val: V, idx: number) => boo
|
|
|
77
77
|
/**
|
|
78
78
|
* 自定义深度优先遍历函数(支持continue和break操作)
|
|
79
79
|
* @param {ArrayLike<V>} tree 树形数据
|
|
80
|
-
* @param {Function} iterator
|
|
80
|
+
* @param {Function} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
|
|
81
81
|
* @param {string} children 定制子元素的key
|
|
82
82
|
* @param {boolean} isReverse 是否反向遍历
|
|
83
83
|
* @returns {*}
|
|
84
84
|
*/
|
|
85
|
-
declare function
|
|
85
|
+
declare function forEachDeep<V>(tree: ArrayLike<V>, iterator: (val: V, i: number, arr: ArrayLike<V>, parent: V | null, level: number) => boolean | void, children?: string, isReverse?: boolean): void;
|
|
86
86
|
type IdLike = number | string;
|
|
87
87
|
interface ITreeConf {
|
|
88
88
|
id: string | number;
|
|
@@ -96,7 +96,46 @@ interface ITreeConf {
|
|
|
96
96
|
* @param {ITreeConf} config - 迭代配置项
|
|
97
97
|
* @returns {[IdLike[], ITreeItem<V>[]]} - 由parentId...childId, parentObject-childObject组成的二维数组
|
|
98
98
|
*/
|
|
99
|
-
declare function
|
|
99
|
+
declare function searchTreeById<V>(tree: ArrayLike<V>, nodeId: IdLike, config?: ITreeConf): [IdLike[], ArrayLike<V>[]];
|
|
100
|
+
type WithChildren<T> = T & {
|
|
101
|
+
children?: WithChildren<T>[];
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* 根据 idProp 与 parentIdProp 从对象数组中构建对应的树
|
|
105
|
+
* 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。
|
|
106
|
+
* 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
|
|
107
|
+
* @param {string} idProp 元素ID
|
|
108
|
+
* @param {string} parentIdProp 父元素ID
|
|
109
|
+
* @param {object[]} items 一维数组
|
|
110
|
+
* @returns {WithChildren<T>[]} 树
|
|
111
|
+
* @example
|
|
112
|
+
* const array = [
|
|
113
|
+
* { id: 'node-1', parent: 'root' },
|
|
114
|
+
* { id: 'node-2', parent: 'root' },
|
|
115
|
+
* { id: 'node-3', parent: 'node-2' },
|
|
116
|
+
* { id: 'node-4', parent: 'node-2' },
|
|
117
|
+
* { id: 'node-5', parent: 'node-4' },
|
|
118
|
+
* ]
|
|
119
|
+
* const tree = buildTree('id', 'parent', array)
|
|
120
|
+
* expect(tree).toEqual([
|
|
121
|
+
* { id: 'node-1', parent: 'root' },
|
|
122
|
+
* {
|
|
123
|
+
* id: 'node-2',
|
|
124
|
+
* parent: 'root',
|
|
125
|
+
* children: [
|
|
126
|
+
* { id: 'node-3', parent: 'node-2' },
|
|
127
|
+
* {
|
|
128
|
+
* id: 'node-4',
|
|
129
|
+
* parent: 'node-2',
|
|
130
|
+
* children: [{ id: 'node-5', parent: 'node-4' }],
|
|
131
|
+
* },
|
|
132
|
+
* ],
|
|
133
|
+
* },
|
|
134
|
+
* ])
|
|
135
|
+
*/
|
|
136
|
+
declare function buildTree<ID extends string, PID extends string, T extends {
|
|
137
|
+
[key in ID | PID]: string;
|
|
138
|
+
}>(idProp: ID, parentIdProp: PID, items: T[]): WithChildren<T>[];
|
|
100
139
|
|
|
101
140
|
/**
|
|
102
141
|
* 复制文本
|
|
@@ -676,4 +715,34 @@ interface UniqueString {
|
|
|
676
715
|
*/
|
|
677
716
|
declare const uniqueString: UniqueString;
|
|
678
717
|
|
|
679
|
-
|
|
718
|
+
/**
|
|
719
|
+
* @title tooltip
|
|
720
|
+
* @Desc 自定义的tooltip方法, 支持拖动悬浮提示
|
|
721
|
+
* Created by chendeqiao on 2017/5/8.
|
|
722
|
+
* @example
|
|
723
|
+
* <span onmouseleave="handleMouseLeave('#root')" onmousemove="handleMouseEnter({rootElId: '#root', title: 'title content', event: event})"
|
|
724
|
+
* onmouseenter="handleMouseEnter({'#root', title: 'title content', event: event})">title content </span>
|
|
725
|
+
*/
|
|
726
|
+
interface ITooltipParams {
|
|
727
|
+
rootElId: string;
|
|
728
|
+
title: string;
|
|
729
|
+
event: PointerEvent;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* 自定义title提示功能的mouseenter事件句柄
|
|
733
|
+
* @param {ITooltipParams} param1
|
|
734
|
+
* @returns {*}
|
|
735
|
+
*/
|
|
736
|
+
declare function handleMouseEnter({ rootElId, title, event }: ITooltipParams): void;
|
|
737
|
+
/**
|
|
738
|
+
* 移除提示文案dom的事件句柄
|
|
739
|
+
* @param {string} rootElId
|
|
740
|
+
* @returns {*}
|
|
741
|
+
*/
|
|
742
|
+
declare function handleMouseLeave(rootElId?: string): void;
|
|
743
|
+
declare const tooltipEvent: {
|
|
744
|
+
handleMouseEnter: typeof handleMouseEnter;
|
|
745
|
+
handleMouseLeave: typeof handleMouseLeave;
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, type FileType, HEX_POOL, type ICanvasWM, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, type Params, type PartialDeep, type RandomString, type ReadyCallback, 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, type UniqueString, type Url, type WithChildren, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, cookieDel, cookieGet, cookieSet, copyText, dateParse, dateToEnd, dateToStart, debounce, downloadBlob, downloadData, downloadHref, downloadURL, forEachDeep, formatDate, formatNumber, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDomReady, isError, isFunction, isNaN, isNull, isNumber, isObject, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isValidDate, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, urlDelParams, urlParse, urlSetParams, urlStringify, wait };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.38.3"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|