@tmagic/utils 1.5.0-beta.8 → 1.5.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/dist/tmagic-utils.js +56 -6
- package/dist/tmagic-utils.umd.cjs +59 -5
- package/package.json +4 -3
- package/src/index.ts +102 -2
- package/types/index.d.ts +21 -6
package/dist/tmagic-utils.js
CHANGED
|
@@ -115,6 +115,8 @@ const getIdFromEl = () => dslDomRelateConfig.getIdFromEl;
|
|
|
115
115
|
const getElById = () => dslDomRelateConfig.getElById;
|
|
116
116
|
const setIdToEl = () => dslDomRelateConfig.setIdToEl;
|
|
117
117
|
|
|
118
|
+
let _globalThis;
|
|
119
|
+
const getGlobalThis = () => _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {});
|
|
118
120
|
const sleep = (ms) => new Promise((resolve) => {
|
|
119
121
|
const timer = setTimeout(() => {
|
|
120
122
|
clearTimeout(timer);
|
|
@@ -122,7 +124,7 @@ const sleep = (ms) => new Promise((resolve) => {
|
|
|
122
124
|
}, ms);
|
|
123
125
|
});
|
|
124
126
|
const toLine = (name = "") => name.replace(/\B([A-Z])/g, "-$1").toLowerCase();
|
|
125
|
-
const toHump = (name = "") => name.replace(/-(\w)/g, (
|
|
127
|
+
const toHump = (name = "") => name.replace(/-(\w)/g, (_all, letter) => letter.toUpperCase());
|
|
126
128
|
const emptyFn = () => void 0;
|
|
127
129
|
const getNodePath = (id, data = []) => {
|
|
128
130
|
const path = [];
|
|
@@ -149,6 +151,30 @@ const getNodePath = (id, data = []) => {
|
|
|
149
151
|
get(id, data);
|
|
150
152
|
return path;
|
|
151
153
|
};
|
|
154
|
+
const getNodeInfo = (id, root) => {
|
|
155
|
+
const info = {
|
|
156
|
+
node: null,
|
|
157
|
+
parent: null,
|
|
158
|
+
page: null
|
|
159
|
+
};
|
|
160
|
+
if (!root) return info;
|
|
161
|
+
if (id === root.id) {
|
|
162
|
+
info.node = root;
|
|
163
|
+
return info;
|
|
164
|
+
}
|
|
165
|
+
const path = getNodePath(id, root.items);
|
|
166
|
+
if (!path.length) return info;
|
|
167
|
+
path.unshift(root);
|
|
168
|
+
info.node = path[path.length - 1];
|
|
169
|
+
info.parent = path[path.length - 2];
|
|
170
|
+
path.forEach((item) => {
|
|
171
|
+
if (isPage(item) || isPageFragment(item)) {
|
|
172
|
+
info.page = item;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return info;
|
|
177
|
+
};
|
|
152
178
|
const filterXSS = (str) => str.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
153
179
|
const getUrlParam = (param, url) => {
|
|
154
180
|
const u = url || location.href;
|
|
@@ -384,20 +410,44 @@ const convertToNumber = (value, parentValue = 0) => {
|
|
|
384
410
|
}
|
|
385
411
|
return parseFloat(value);
|
|
386
412
|
};
|
|
387
|
-
const addParamToUrl = (obj,
|
|
388
|
-
const url = new URL(
|
|
413
|
+
const addParamToUrl = (obj, global2 = globalThis, needReload = true) => {
|
|
414
|
+
const url = new URL(global2.location.href);
|
|
389
415
|
const { searchParams } = url;
|
|
390
416
|
for (const [k, v] of Object.entries(obj)) {
|
|
391
417
|
searchParams.set(k, v);
|
|
392
418
|
}
|
|
393
419
|
const newUrl = url.toString();
|
|
394
420
|
if (needReload) {
|
|
395
|
-
|
|
421
|
+
global2.location.href = newUrl;
|
|
396
422
|
} else {
|
|
397
|
-
|
|
423
|
+
global2.history.pushState({}, "", url);
|
|
398
424
|
}
|
|
399
425
|
};
|
|
400
426
|
const dataSourceTemplateRegExp = /\$\{([\s\S]+?)\}/g;
|
|
401
427
|
const isDslNode = (config) => typeof config[IS_DSL_NODE_KEY] === "undefined" || config[IS_DSL_NODE_KEY] === true;
|
|
428
|
+
const traverseNode = (node, cb, parents = []) => {
|
|
429
|
+
cb(node, parents);
|
|
430
|
+
if (Array.isArray(node.items) && node.items.length) {
|
|
431
|
+
parents.push(node);
|
|
432
|
+
node.items.forEach((item) => {
|
|
433
|
+
traverseNode(item, cb, [...parents]);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
const isValueIncludeDataSource = (value) => {
|
|
438
|
+
if (typeof value === "string" && /\$\{([\s\S]+?)\}/.test(value)) {
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
if (Array.isArray(value) && `${value[0]}`.startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)) {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
if (value?.isBindDataSource && value.dataSourceId) {
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
if (value?.isBindDataSourceField && value.dataSourceId) {
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
return false;
|
|
451
|
+
};
|
|
402
452
|
|
|
403
|
-
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 };
|
|
453
|
+
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, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
|
|
@@ -2724,6 +2724,8 @@
|
|
|
2724
2724
|
const getElById = () => dslDomRelateConfig.getElById;
|
|
2725
2725
|
const setIdToEl = () => dslDomRelateConfig.setIdToEl;
|
|
2726
2726
|
|
|
2727
|
+
let _globalThis;
|
|
2728
|
+
const getGlobalThis = () => _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {});
|
|
2727
2729
|
const sleep = (ms) => new Promise((resolve) => {
|
|
2728
2730
|
const timer = setTimeout(() => {
|
|
2729
2731
|
clearTimeout(timer);
|
|
@@ -2731,7 +2733,7 @@
|
|
|
2731
2733
|
}, ms);
|
|
2732
2734
|
});
|
|
2733
2735
|
const toLine = (name = "") => name.replace(/\B([A-Z])/g, "-$1").toLowerCase();
|
|
2734
|
-
const toHump = (name = "") => name.replace(/-(\w)/g, (
|
|
2736
|
+
const toHump = (name = "") => name.replace(/-(\w)/g, (_all, letter) => letter.toUpperCase());
|
|
2735
2737
|
const emptyFn = () => void 0;
|
|
2736
2738
|
const getNodePath = (id, data = []) => {
|
|
2737
2739
|
const path = [];
|
|
@@ -2758,6 +2760,30 @@
|
|
|
2758
2760
|
get(id, data);
|
|
2759
2761
|
return path;
|
|
2760
2762
|
};
|
|
2763
|
+
const getNodeInfo = (id, root) => {
|
|
2764
|
+
const info = {
|
|
2765
|
+
node: null,
|
|
2766
|
+
parent: null,
|
|
2767
|
+
page: null
|
|
2768
|
+
};
|
|
2769
|
+
if (!root) return info;
|
|
2770
|
+
if (id === root.id) {
|
|
2771
|
+
info.node = root;
|
|
2772
|
+
return info;
|
|
2773
|
+
}
|
|
2774
|
+
const path = getNodePath(id, root.items);
|
|
2775
|
+
if (!path.length) return info;
|
|
2776
|
+
path.unshift(root);
|
|
2777
|
+
info.node = path[path.length - 1];
|
|
2778
|
+
info.parent = path[path.length - 2];
|
|
2779
|
+
path.forEach((item) => {
|
|
2780
|
+
if (isPage(item) || isPageFragment(item)) {
|
|
2781
|
+
info.page = item;
|
|
2782
|
+
return;
|
|
2783
|
+
}
|
|
2784
|
+
});
|
|
2785
|
+
return info;
|
|
2786
|
+
};
|
|
2761
2787
|
const filterXSS = (str) => str.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2762
2788
|
const getUrlParam = (param, url) => {
|
|
2763
2789
|
const u = url || location.href;
|
|
@@ -2993,21 +3019,45 @@
|
|
|
2993
3019
|
}
|
|
2994
3020
|
return parseFloat(value);
|
|
2995
3021
|
};
|
|
2996
|
-
const addParamToUrl = (obj,
|
|
2997
|
-
const url = new URL(
|
|
3022
|
+
const addParamToUrl = (obj, global2 = globalThis, needReload = true) => {
|
|
3023
|
+
const url = new URL(global2.location.href);
|
|
2998
3024
|
const { searchParams } = url;
|
|
2999
3025
|
for (const [k, v] of Object.entries(obj)) {
|
|
3000
3026
|
searchParams.set(k, v);
|
|
3001
3027
|
}
|
|
3002
3028
|
const newUrl = url.toString();
|
|
3003
3029
|
if (needReload) {
|
|
3004
|
-
|
|
3030
|
+
global2.location.href = newUrl;
|
|
3005
3031
|
} else {
|
|
3006
|
-
|
|
3032
|
+
global2.history.pushState({}, "", url);
|
|
3007
3033
|
}
|
|
3008
3034
|
};
|
|
3009
3035
|
const dataSourceTemplateRegExp = /\$\{([\s\S]+?)\}/g;
|
|
3010
3036
|
const isDslNode = (config) => typeof config[IS_DSL_NODE_KEY] === "undefined" || config[IS_DSL_NODE_KEY] === true;
|
|
3037
|
+
const traverseNode = (node, cb, parents = []) => {
|
|
3038
|
+
cb(node, parents);
|
|
3039
|
+
if (Array.isArray(node.items) && node.items.length) {
|
|
3040
|
+
parents.push(node);
|
|
3041
|
+
node.items.forEach((item) => {
|
|
3042
|
+
traverseNode(item, cb, [...parents]);
|
|
3043
|
+
});
|
|
3044
|
+
}
|
|
3045
|
+
};
|
|
3046
|
+
const isValueIncludeDataSource = (value) => {
|
|
3047
|
+
if (typeof value === "string" && /\$\{([\s\S]+?)\}/.test(value)) {
|
|
3048
|
+
return true;
|
|
3049
|
+
}
|
|
3050
|
+
if (Array.isArray(value) && `${value[0]}`.startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)) {
|
|
3051
|
+
return true;
|
|
3052
|
+
}
|
|
3053
|
+
if (value?.isBindDataSource && value.dataSourceId) {
|
|
3054
|
+
return true;
|
|
3055
|
+
}
|
|
3056
|
+
if (value?.isBindDataSourceField && value.dataSourceId) {
|
|
3057
|
+
return true;
|
|
3058
|
+
}
|
|
3059
|
+
return false;
|
|
3060
|
+
};
|
|
3011
3061
|
|
|
3012
3062
|
exports.DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX = DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX;
|
|
3013
3063
|
exports.DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX = DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX;
|
|
@@ -3031,10 +3081,12 @@
|
|
|
3031
3081
|
exports.getDepNodeIds = getDepNodeIds;
|
|
3032
3082
|
exports.getDocument = getDocument;
|
|
3033
3083
|
exports.getElById = getElById;
|
|
3084
|
+
exports.getGlobalThis = getGlobalThis;
|
|
3034
3085
|
exports.getHost = getHost;
|
|
3035
3086
|
exports.getIdFromEl = getIdFromEl;
|
|
3036
3087
|
exports.getKeys = getKeys;
|
|
3037
3088
|
exports.getKeysArray = getKeysArray;
|
|
3089
|
+
exports.getNodeInfo = getNodeInfo;
|
|
3038
3090
|
exports.getNodePath = getNodePath;
|
|
3039
3091
|
exports.getNodes = getNodes;
|
|
3040
3092
|
exports.getUrlParam = getUrlParam;
|
|
@@ -3049,6 +3101,7 @@
|
|
|
3049
3101
|
exports.isPercentage = isPercentage;
|
|
3050
3102
|
exports.isPop = isPop;
|
|
3051
3103
|
exports.isSameDomain = isSameDomain;
|
|
3104
|
+
exports.isValueIncludeDataSource = isValueIncludeDataSource;
|
|
3052
3105
|
exports.removeClassName = removeClassName;
|
|
3053
3106
|
exports.removeClassNameByClassName = removeClassNameByClassName;
|
|
3054
3107
|
exports.replaceChildNode = replaceChildNode;
|
|
@@ -3058,6 +3111,7 @@
|
|
|
3058
3111
|
exports.sleep = sleep;
|
|
3059
3112
|
exports.toHump = toHump;
|
|
3060
3113
|
exports.toLine = toLine;
|
|
3114
|
+
exports.traverseNode = traverseNode;
|
|
3061
3115
|
|
|
3062
3116
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
3063
3117
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.5.0
|
|
2
|
+
"version": "1.5.0",
|
|
3
3
|
"name": "@tmagic/utils",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/tmagic-utils.umd.cjs",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"node": ">=18"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
|
+
"directory": "packages/utils",
|
|
25
26
|
"type": "git",
|
|
26
27
|
"url": "https://github.com/Tencent/tmagic-editor.git"
|
|
27
28
|
},
|
|
@@ -32,11 +33,11 @@
|
|
|
32
33
|
"@types/lodash-es": "^4.17.4",
|
|
33
34
|
"@types/node": "^18.19.0",
|
|
34
35
|
"rimraf": "^3.0.2",
|
|
35
|
-
"vite": "^5.4.
|
|
36
|
+
"vite": "^5.4.10"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"typescript": "*",
|
|
39
|
-
"@tmagic/schema": "1.5.0
|
|
40
|
+
"@tmagic/schema": "1.5.0"
|
|
40
41
|
},
|
|
41
42
|
"peerDependenciesMeta": {
|
|
42
43
|
"typescript": {
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-nested-ternary */
|
|
1
2
|
/*
|
|
2
3
|
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
4
|
*
|
|
@@ -18,11 +19,41 @@
|
|
|
18
19
|
|
|
19
20
|
import { cloneDeep, set as objectSet } from 'lodash-es';
|
|
20
21
|
|
|
21
|
-
import type {
|
|
22
|
+
import type {
|
|
23
|
+
DataSchema,
|
|
24
|
+
DataSourceDeps,
|
|
25
|
+
Id,
|
|
26
|
+
MApp,
|
|
27
|
+
MComponent,
|
|
28
|
+
MContainer,
|
|
29
|
+
MNode,
|
|
30
|
+
MNodeInstance,
|
|
31
|
+
MPage,
|
|
32
|
+
MPageFragment,
|
|
33
|
+
} from '@tmagic/schema';
|
|
22
34
|
import { NodeType } from '@tmagic/schema';
|
|
23
35
|
|
|
36
|
+
import type { EditorNodeInfo } from '@editor/type';
|
|
37
|
+
|
|
24
38
|
export * from './dom';
|
|
25
39
|
|
|
40
|
+
// for typeof global checks without @types/node
|
|
41
|
+
declare let global: {};
|
|
42
|
+
|
|
43
|
+
let _globalThis: any;
|
|
44
|
+
export const getGlobalThis = (): any =>
|
|
45
|
+
_globalThis ||
|
|
46
|
+
(_globalThis =
|
|
47
|
+
typeof globalThis !== 'undefined'
|
|
48
|
+
? globalThis
|
|
49
|
+
: typeof self !== 'undefined'
|
|
50
|
+
? self
|
|
51
|
+
: typeof window !== 'undefined'
|
|
52
|
+
? window
|
|
53
|
+
: typeof global !== 'undefined'
|
|
54
|
+
? global
|
|
55
|
+
: {});
|
|
56
|
+
|
|
26
57
|
export const sleep = (ms: number): Promise<void> =>
|
|
27
58
|
new Promise((resolve) => {
|
|
28
59
|
const timer = setTimeout(() => {
|
|
@@ -34,7 +65,7 @@ export const sleep = (ms: number): Promise<void> =>
|
|
|
34
65
|
// 驼峰转换横线
|
|
35
66
|
export const toLine = (name = '') => name.replace(/\B([A-Z])/g, '-$1').toLowerCase();
|
|
36
67
|
|
|
37
|
-
export const toHump = (name = ''): string => name.replace(/-(\w)/g, (
|
|
68
|
+
export const toHump = (name = ''): string => name.replace(/-(\w)/g, (_all, letter) => letter.toUpperCase());
|
|
38
69
|
|
|
39
70
|
export const emptyFn = (): any => undefined;
|
|
40
71
|
|
|
@@ -78,6 +109,39 @@ export const getNodePath = (id: Id, data: MNode[] = []): MNode[] => {
|
|
|
78
109
|
return path;
|
|
79
110
|
};
|
|
80
111
|
|
|
112
|
+
export const getNodeInfo = (id: Id, root: Pick<MApp, 'id' | 'items'> | null) => {
|
|
113
|
+
const info: EditorNodeInfo = {
|
|
114
|
+
node: null,
|
|
115
|
+
parent: null,
|
|
116
|
+
page: null,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (!root) return info;
|
|
120
|
+
|
|
121
|
+
if (id === root.id) {
|
|
122
|
+
info.node = root;
|
|
123
|
+
return info;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const path = getNodePath(id, root.items);
|
|
127
|
+
|
|
128
|
+
if (!path.length) return info;
|
|
129
|
+
|
|
130
|
+
path.unshift(root);
|
|
131
|
+
|
|
132
|
+
info.node = path[path.length - 1] as MComponent;
|
|
133
|
+
info.parent = path[path.length - 2] as MContainer;
|
|
134
|
+
|
|
135
|
+
path.forEach((item) => {
|
|
136
|
+
if (isPage(item) || isPageFragment(item)) {
|
|
137
|
+
info.page = item as MPage | MPageFragment;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return info;
|
|
143
|
+
};
|
|
144
|
+
|
|
81
145
|
export const filterXSS = (str: string) =>
|
|
82
146
|
str.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
83
147
|
|
|
@@ -425,3 +489,39 @@ export const dataSourceTemplateRegExp = /\$\{([\s\S]+?)\}/g;
|
|
|
425
489
|
|
|
426
490
|
export const isDslNode = (config: MNodeInstance) =>
|
|
427
491
|
typeof config[IS_DSL_NODE_KEY] === 'undefined' || config[IS_DSL_NODE_KEY] === true;
|
|
492
|
+
|
|
493
|
+
export interface NodeItem {
|
|
494
|
+
items?: NodeItem[];
|
|
495
|
+
[key: string]: any;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export const traverseNode = <T extends NodeItem = NodeItem>(
|
|
499
|
+
node: T,
|
|
500
|
+
cb: (node: T, parents: T[]) => void,
|
|
501
|
+
parents: T[] = [],
|
|
502
|
+
) => {
|
|
503
|
+
cb(node, parents);
|
|
504
|
+
|
|
505
|
+
if (Array.isArray(node.items) && node.items.length) {
|
|
506
|
+
parents.push(node);
|
|
507
|
+
node.items.forEach((item) => {
|
|
508
|
+
traverseNode(item as T, cb, [...parents]);
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
export const isValueIncludeDataSource = (value: any) => {
|
|
514
|
+
if (typeof value === 'string' && /\$\{([\s\S]+?)\}/.test(value)) {
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
if (Array.isArray(value) && `${value[0]}`.startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)) {
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
if (value?.isBindDataSource && value.dataSourceId) {
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
if (value?.isBindDataSourceField && value.dataSourceId) {
|
|
524
|
+
return true;
|
|
525
|
+
}
|
|
526
|
+
return false;
|
|
527
|
+
};
|
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;
|
|
@@ -22,6 +29,7 @@ declare const getIdFromEl: () => (el?: HTMLElement | SVGElement | null) => strin
|
|
|
22
29
|
declare const getElById: () => (doc?: Document, id?: string | number) => HTMLElement;
|
|
23
30
|
declare const setIdToEl: () => (el: HTMLElement | SVGElement, id: string | number) => void;
|
|
24
31
|
|
|
32
|
+
declare const getGlobalThis: () => any;
|
|
25
33
|
declare const sleep: (ms: number) => Promise<void>;
|
|
26
34
|
declare const toLine: (name?: string) => string;
|
|
27
35
|
declare const toHump: (name?: string) => string;
|
|
@@ -32,7 +40,8 @@ declare const emptyFn: () => any;
|
|
|
32
40
|
* @param {Array} data 要查找的根容器节点
|
|
33
41
|
* @return {Array} 组件在data中的子孙路径
|
|
34
42
|
*/
|
|
35
|
-
declare const getNodePath: (id: Id, data?: MNode[]) => MNode[];
|
|
43
|
+
declare const getNodePath: (id: Id, data?: MNode$1[]) => MNode$1[];
|
|
44
|
+
declare const getNodeInfo: (id: Id, root: Pick<MApp, "id" | "items"> | null) => EditorNodeInfo;
|
|
36
45
|
declare const filterXSS: (str: string) => string;
|
|
37
46
|
declare const getUrlParam: (param: string, url?: string) => string;
|
|
38
47
|
declare const isObject: (obj: any) => boolean;
|
|
@@ -51,7 +60,7 @@ declare const guid: (digit?: number) => string;
|
|
|
51
60
|
declare const getKeysArray: (keys: string | number) => string[];
|
|
52
61
|
declare const getValueByKeyPath: (keys?: number | string | string[], data?: Record<string | number, any>) => any;
|
|
53
62
|
declare const setValueByKeyPath: (keys: string | number, value: any, data?: Record<string | number, any>) => any;
|
|
54
|
-
declare const getNodes: (ids: Id[], data?: MNode[]) => MNode[];
|
|
63
|
+
declare const getNodes: (ids: Id[], data?: MNode$1[]) => MNode$1[];
|
|
55
64
|
declare const getDepKeys: (dataSourceDeps: DataSourceDeps | undefined, nodeId: Id) => Id[];
|
|
56
65
|
declare const getDepNodeIds: (dataSourceDeps?: DataSourceDeps) => string[];
|
|
57
66
|
/**
|
|
@@ -60,10 +69,10 @@ declare const getDepNodeIds: (dataSourceDeps?: DataSourceDeps) => string[];
|
|
|
60
69
|
* @param data 需要修改的数据
|
|
61
70
|
* @param parentId 父节点 id
|
|
62
71
|
*/
|
|
63
|
-
declare const replaceChildNode: (newNode: MNode, data?: MNode[], parentId?: Id) => void;
|
|
72
|
+
declare const replaceChildNode: (newNode: MNode$1, data?: MNode$1[], parentId?: Id) => void;
|
|
64
73
|
declare const DSL_NODE_KEY_COPY_PREFIX = "__tmagic__";
|
|
65
74
|
declare const IS_DSL_NODE_KEY = "__tmagic__dslNode";
|
|
66
|
-
declare const compiledNode: (compile: (value: any) => any, node: MNode, dataSourceDeps?: DataSourceDeps, sourceId?: Id) => MNode;
|
|
75
|
+
declare const compiledNode: (compile: (value: any) => any, node: MNode$1, dataSourceDeps?: DataSourceDeps, sourceId?: Id) => MNode$1;
|
|
67
76
|
declare const compiledCond: (op: string, fieldValue: any, inputValue: any, range?: number[]) => boolean;
|
|
68
77
|
declare const getDefaultValueFromFields: (fields: DataSchema[]) => Record<string, any>;
|
|
69
78
|
declare const DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX = "ds-field::";
|
|
@@ -81,5 +90,11 @@ declare const convertToNumber: (value: number | string, parentValue?: number) =>
|
|
|
81
90
|
declare const addParamToUrl: (obj: Record<string, any>, global?: typeof globalThis, needReload?: boolean) => void;
|
|
82
91
|
declare const dataSourceTemplateRegExp: RegExp;
|
|
83
92
|
declare const isDslNode: (config: MNodeInstance) => boolean;
|
|
93
|
+
interface NodeItem {
|
|
94
|
+
items?: NodeItem[];
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
}
|
|
97
|
+
declare const traverseNode: <T extends NodeItem = NodeItem>(node: T, cb: (node: T, parents: T[]) => void, parents?: T[]) => void;
|
|
98
|
+
declare const isValueIncludeDataSource: (value: any) => boolean;
|
|
84
99
|
|
|
85
|
-
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 };
|
|
100
|
+
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, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
|