@tmagic/utils 1.8.0-beta.1 → 1.8.0-beta.10
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/es/index.js +16 -15
- package/dist/tmagic-utils.umd.cjs +1148 -1147
- package/package.json +2 -2
- package/src/index.ts +16 -12
- package/types/index.d.ts +7 -3
package/dist/es/index.js
CHANGED
|
@@ -20,47 +20,48 @@ var emptyFn = () => void 0;
|
|
|
20
20
|
* @param {Array} data 要查找的根容器节点
|
|
21
21
|
* @return {Array} 组件在data中的子孙路径
|
|
22
22
|
*/
|
|
23
|
-
var getNodePath = (id, data = []) => {
|
|
23
|
+
var getNodePath = (id, data = [], skip) => {
|
|
24
24
|
const path = [];
|
|
25
|
-
const
|
|
25
|
+
const targetId = `${id}`;
|
|
26
|
+
const get = function(data) {
|
|
26
27
|
if (!Array.isArray(data)) return null;
|
|
27
28
|
for (let i = 0, l = data.length; i < l; i++) {
|
|
28
29
|
const item = data[i];
|
|
29
30
|
path.push(item);
|
|
30
|
-
if (`${item.id}` ===
|
|
31
|
-
if (item.items) {
|
|
32
|
-
const node = get(
|
|
31
|
+
if (`${item.id}` === targetId) return item;
|
|
32
|
+
if (item.items && item !== skip) {
|
|
33
|
+
const node = get(item.items);
|
|
33
34
|
if (node) return node;
|
|
34
35
|
}
|
|
35
36
|
path.pop();
|
|
36
37
|
}
|
|
37
38
|
return null;
|
|
38
39
|
};
|
|
39
|
-
get(
|
|
40
|
+
get(data);
|
|
40
41
|
return path;
|
|
41
42
|
};
|
|
42
|
-
var getNodeInfo = (id, root) => {
|
|
43
|
+
var getNodeInfo = (id, root, skip) => {
|
|
43
44
|
const info = {
|
|
44
45
|
node: null,
|
|
45
46
|
parent: null,
|
|
46
|
-
page: null
|
|
47
|
+
page: null,
|
|
48
|
+
path: []
|
|
47
49
|
};
|
|
48
50
|
if (!root) return info;
|
|
49
51
|
if (id === root.id) {
|
|
50
52
|
info.node = root;
|
|
51
53
|
return info;
|
|
52
54
|
}
|
|
53
|
-
const path = getNodePath(id, root.items);
|
|
55
|
+
const path = getNodePath(id, root.items, skip);
|
|
56
|
+
info.path = path;
|
|
54
57
|
if (!path.length) return info;
|
|
55
58
|
path.unshift(root);
|
|
56
59
|
info.node = path[path.length - 1];
|
|
57
60
|
info.parent = path[path.length - 2];
|
|
58
|
-
path
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
});
|
|
61
|
+
for (const item of path) if (isPage(item) || isPageFragment(item)) {
|
|
62
|
+
info.page = item;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
64
65
|
return info;
|
|
65
66
|
};
|
|
66
67
|
var filterXSS = (str) => str.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|