@tmagic/utils 1.5.0-beta.11 → 1.5.0-beta.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/dist/tmagic-utils.js +25 -1
- package/dist/tmagic-utils.umd.cjs +25 -0
- package/package.json +2 -2
- package/src/index.ts +47 -1
- package/types/index.d.ts +14 -6
package/dist/tmagic-utils.js
CHANGED
|
@@ -149,6 +149,30 @@ const getNodePath = (id, data = []) => {
|
|
|
149
149
|
get(id, data);
|
|
150
150
|
return path;
|
|
151
151
|
};
|
|
152
|
+
const getNodeInfo = (id, root) => {
|
|
153
|
+
const info = {
|
|
154
|
+
node: null,
|
|
155
|
+
parent: null,
|
|
156
|
+
page: null
|
|
157
|
+
};
|
|
158
|
+
if (!root) return info;
|
|
159
|
+
if (id === root.id) {
|
|
160
|
+
info.node = root;
|
|
161
|
+
return info;
|
|
162
|
+
}
|
|
163
|
+
const path = getNodePath(id, root.items);
|
|
164
|
+
if (!path.length) return info;
|
|
165
|
+
path.unshift(root);
|
|
166
|
+
info.node = path[path.length - 1];
|
|
167
|
+
info.parent = path[path.length - 2];
|
|
168
|
+
path.forEach((item) => {
|
|
169
|
+
if (isPage(item) || isPageFragment(item)) {
|
|
170
|
+
info.page = item;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return info;
|
|
175
|
+
};
|
|
152
176
|
const filterXSS = (str) => str.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
153
177
|
const getUrlParam = (param, url) => {
|
|
154
178
|
const u = url || location.href;
|
|
@@ -409,4 +433,4 @@ const traverseNode = (node, cb, parents = []) => {
|
|
|
409
433
|
}
|
|
410
434
|
};
|
|
411
435
|
|
|
412
|
-
export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getHost, getIdFromEl, getKeys, getKeysArray, getNodePath, getNodes, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
|
|
436
|
+
export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
|
|
@@ -2758,6 +2758,30 @@
|
|
|
2758
2758
|
get(id, data);
|
|
2759
2759
|
return path;
|
|
2760
2760
|
};
|
|
2761
|
+
const getNodeInfo = (id, root) => {
|
|
2762
|
+
const info = {
|
|
2763
|
+
node: null,
|
|
2764
|
+
parent: null,
|
|
2765
|
+
page: null
|
|
2766
|
+
};
|
|
2767
|
+
if (!root) return info;
|
|
2768
|
+
if (id === root.id) {
|
|
2769
|
+
info.node = root;
|
|
2770
|
+
return info;
|
|
2771
|
+
}
|
|
2772
|
+
const path = getNodePath(id, root.items);
|
|
2773
|
+
if (!path.length) return info;
|
|
2774
|
+
path.unshift(root);
|
|
2775
|
+
info.node = path[path.length - 1];
|
|
2776
|
+
info.parent = path[path.length - 2];
|
|
2777
|
+
path.forEach((item) => {
|
|
2778
|
+
if (isPage(item) || isPageFragment(item)) {
|
|
2779
|
+
info.page = item;
|
|
2780
|
+
return;
|
|
2781
|
+
}
|
|
2782
|
+
});
|
|
2783
|
+
return info;
|
|
2784
|
+
};
|
|
2761
2785
|
const filterXSS = (str) => str.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2762
2786
|
const getUrlParam = (param, url) => {
|
|
2763
2787
|
const u = url || location.href;
|
|
@@ -3044,6 +3068,7 @@
|
|
|
3044
3068
|
exports.getIdFromEl = getIdFromEl;
|
|
3045
3069
|
exports.getKeys = getKeys;
|
|
3046
3070
|
exports.getKeysArray = getKeysArray;
|
|
3071
|
+
exports.getNodeInfo = getNodeInfo;
|
|
3047
3072
|
exports.getNodePath = getNodePath;
|
|
3048
3073
|
exports.getNodes = getNodes;
|
|
3049
3074
|
exports.getUrlParam = getUrlParam;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.5.0-beta.
|
|
2
|
+
"version": "1.5.0-beta.13",
|
|
3
3
|
"name": "@tmagic/utils",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/tmagic-utils.umd.cjs",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"typescript": "*",
|
|
39
|
-
"@tmagic/schema": "1.5.0-beta.
|
|
39
|
+
"@tmagic/schema": "1.5.0-beta.13"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"typescript": {
|
package/src/index.ts
CHANGED
|
@@ -18,9 +18,22 @@
|
|
|
18
18
|
|
|
19
19
|
import { cloneDeep, set as objectSet } from 'lodash-es';
|
|
20
20
|
|
|
21
|
-
import type {
|
|
21
|
+
import type {
|
|
22
|
+
DataSchema,
|
|
23
|
+
DataSourceDeps,
|
|
24
|
+
Id,
|
|
25
|
+
MApp,
|
|
26
|
+
MComponent,
|
|
27
|
+
MContainer,
|
|
28
|
+
MNode,
|
|
29
|
+
MNodeInstance,
|
|
30
|
+
MPage,
|
|
31
|
+
MPageFragment,
|
|
32
|
+
} from '@tmagic/schema';
|
|
22
33
|
import { NodeType } from '@tmagic/schema';
|
|
23
34
|
|
|
35
|
+
import type { EditorNodeInfo } from '@editor/type';
|
|
36
|
+
|
|
24
37
|
export * from './dom';
|
|
25
38
|
|
|
26
39
|
export const sleep = (ms: number): Promise<void> =>
|
|
@@ -78,6 +91,39 @@ export const getNodePath = (id: Id, data: MNode[] = []): MNode[] => {
|
|
|
78
91
|
return path;
|
|
79
92
|
};
|
|
80
93
|
|
|
94
|
+
export const getNodeInfo = (id: Id, root: MApp | null) => {
|
|
95
|
+
const info: EditorNodeInfo = {
|
|
96
|
+
node: null,
|
|
97
|
+
parent: null,
|
|
98
|
+
page: null,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
if (!root) return info;
|
|
102
|
+
|
|
103
|
+
if (id === root.id) {
|
|
104
|
+
info.node = root;
|
|
105
|
+
return info;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const path = getNodePath(id, root.items);
|
|
109
|
+
|
|
110
|
+
if (!path.length) return info;
|
|
111
|
+
|
|
112
|
+
path.unshift(root);
|
|
113
|
+
|
|
114
|
+
info.node = path[path.length - 1] as MComponent;
|
|
115
|
+
info.parent = path[path.length - 2] as MContainer;
|
|
116
|
+
|
|
117
|
+
path.forEach((item) => {
|
|
118
|
+
if (isPage(item) || isPageFragment(item)) {
|
|
119
|
+
info.page = item as MPage | MPageFragment;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return info;
|
|
125
|
+
};
|
|
126
|
+
|
|
81
127
|
export const filterXSS = (str: string) =>
|
|
82
128
|
str.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
83
129
|
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { Id, MNode, MComponent, DataSourceDeps, DataSchema, MNodeInstance } from '@tmagic/schema';
|
|
1
|
+
import { Id, MNode as MNode$1, MApp, MComponent, DataSourceDeps, DataSchema, MNodeInstance } from '@tmagic/schema';
|
|
2
|
+
import { MNode, MContainer, MPage, MPageFragment } from '@tmagic/core';
|
|
3
|
+
|
|
4
|
+
interface EditorNodeInfo {
|
|
5
|
+
node: MNode | null;
|
|
6
|
+
parent: MContainer | null;
|
|
7
|
+
page: MPage | MPageFragment | null;
|
|
8
|
+
}
|
|
2
9
|
|
|
3
10
|
declare const asyncLoadJs: (url: string, crossOrigin?: string, document?: Document) => any;
|
|
4
11
|
declare const asyncLoadCss: (url: string, document?: Document) => any;
|
|
@@ -32,7 +39,8 @@ declare const emptyFn: () => any;
|
|
|
32
39
|
* @param {Array} data 要查找的根容器节点
|
|
33
40
|
* @return {Array} 组件在data中的子孙路径
|
|
34
41
|
*/
|
|
35
|
-
declare const getNodePath: (id: Id, data?: MNode[]) => MNode[];
|
|
42
|
+
declare const getNodePath: (id: Id, data?: MNode$1[]) => MNode$1[];
|
|
43
|
+
declare const getNodeInfo: (id: Id, root: MApp | null) => EditorNodeInfo;
|
|
36
44
|
declare const filterXSS: (str: string) => string;
|
|
37
45
|
declare const getUrlParam: (param: string, url?: string) => string;
|
|
38
46
|
declare const isObject: (obj: any) => boolean;
|
|
@@ -51,7 +59,7 @@ declare const guid: (digit?: number) => string;
|
|
|
51
59
|
declare const getKeysArray: (keys: string | number) => string[];
|
|
52
60
|
declare const getValueByKeyPath: (keys?: number | string | string[], data?: Record<string | number, any>) => any;
|
|
53
61
|
declare const setValueByKeyPath: (keys: string | number, value: any, data?: Record<string | number, any>) => any;
|
|
54
|
-
declare const getNodes: (ids: Id[], data?: MNode[]) => MNode[];
|
|
62
|
+
declare const getNodes: (ids: Id[], data?: MNode$1[]) => MNode$1[];
|
|
55
63
|
declare const getDepKeys: (dataSourceDeps: DataSourceDeps | undefined, nodeId: Id) => Id[];
|
|
56
64
|
declare const getDepNodeIds: (dataSourceDeps?: DataSourceDeps) => string[];
|
|
57
65
|
/**
|
|
@@ -60,10 +68,10 @@ declare const getDepNodeIds: (dataSourceDeps?: DataSourceDeps) => string[];
|
|
|
60
68
|
* @param data 需要修改的数据
|
|
61
69
|
* @param parentId 父节点 id
|
|
62
70
|
*/
|
|
63
|
-
declare const replaceChildNode: (newNode: MNode, data?: MNode[], parentId?: Id) => void;
|
|
71
|
+
declare const replaceChildNode: (newNode: MNode$1, data?: MNode$1[], parentId?: Id) => void;
|
|
64
72
|
declare const DSL_NODE_KEY_COPY_PREFIX = "__tmagic__";
|
|
65
73
|
declare const IS_DSL_NODE_KEY = "__tmagic__dslNode";
|
|
66
|
-
declare const compiledNode: (compile: (value: any) => any, node: MNode, dataSourceDeps?: DataSourceDeps, sourceId?: Id) => MNode;
|
|
74
|
+
declare const compiledNode: (compile: (value: any) => any, node: MNode$1, dataSourceDeps?: DataSourceDeps, sourceId?: Id) => MNode$1;
|
|
67
75
|
declare const compiledCond: (op: string, fieldValue: any, inputValue: any, range?: number[]) => boolean;
|
|
68
76
|
declare const getDefaultValueFromFields: (fields: DataSchema[]) => Record<string, any>;
|
|
69
77
|
declare const DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX = "ds-field::";
|
|
@@ -87,4 +95,4 @@ interface NodeItem {
|
|
|
87
95
|
}
|
|
88
96
|
declare const traverseNode: <T extends NodeItem = NodeItem>(node: T, cb: (node: T, parents: T[]) => void, parents?: T[]) => void;
|
|
89
97
|
|
|
90
|
-
export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, type NodeItem, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getHost, getIdFromEl, getKeys, getKeysArray, getNodePath, getNodes, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
|
|
98
|
+
export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, type NodeItem, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
|