@tmagic/editor 1.7.13 → 1.7.14-beta.1
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/Editor.vue_vue_type_script_setup_true_lang.js +21 -3
- package/dist/es/components/ScrollViewer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/Tree.vue_vue_type_script_setup_true_lang.js +8 -4
- package/dist/es/components/TreeNode.vue_vue_type_script_setup_true_lang.js +19 -9
- package/dist/es/editorProps.js +1 -0
- package/dist/es/fields/StyleSetter/Index.vue_vue_type_script_setup_true_lang.js +2 -1
- package/dist/es/hooks/use-stage.js +5 -0
- package/dist/es/index.js +2 -2
- package/dist/es/initService.js +3 -0
- package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +12 -3
- package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +21 -5
- package/dist/es/layouts/sidebar/layer/use-click.js +22 -3
- package/dist/es/layouts/sidebar/layer/use-drag.js +28 -6
- package/dist/es/layouts/workspace/Breadcrumb.vue_vue_type_script_setup_true_lang.js +87 -12
- package/dist/es/layouts/workspace/Workspace.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/layouts/workspace/viewer/Stage.vue_vue_type_script_setup_true_lang.js +16 -4
- package/dist/es/services/editor.js +2 -1
- package/dist/es/services/props.js +14 -2
- package/dist/es/style.css +20 -0
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/tree.js +3 -1
- package/dist/style.css +20 -0
- package/dist/tmagic-editor.umd.cjs +266 -52
- package/package.json +7 -7
- package/src/Editor.vue +17 -0
- package/src/components/ScrollViewer.vue +4 -1
- package/src/components/Tree.vue +5 -1
- package/src/components/TreeNode.vue +14 -9
- package/src/editorProps.ts +23 -0
- package/src/fields/StyleSetter/Index.vue +5 -1
- package/src/hooks/use-stage.ts +9 -0
- package/src/initService.ts +10 -0
- package/src/layouts/props-panel/PropsPanel.vue +1 -1
- package/src/layouts/sidebar/Sidebar.vue +19 -0
- package/src/layouts/sidebar/layer/LayerPanel.vue +37 -3
- package/src/layouts/sidebar/layer/use-click.ts +36 -3
- package/src/layouts/sidebar/layer/use-drag.ts +62 -6
- package/src/layouts/workspace/Breadcrumb.vue +87 -6
- package/src/layouts/workspace/Workspace.vue +3 -1
- package/src/layouts/workspace/viewer/Stage.vue +31 -3
- package/src/services/editor.ts +1 -0
- package/src/services/props.ts +18 -2
- package/src/theme/breadcrumb.scss +24 -0
- package/src/type.ts +58 -1
- package/src/utils/tree.ts +5 -1
- package/types/index.d.ts +97 -8
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { useServices } from "../../hooks/use-services.js";
|
|
2
|
-
import { TMagicButton } from "@tmagic/design";
|
|
2
|
+
import { TMagicButton, TMagicTooltip } from "@tmagic/design";
|
|
3
3
|
import { getNodePath } from "@tmagic/utils";
|
|
4
|
-
import { Fragment, computed, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, openBlock, renderList, toDisplayString, unref, withCtx } from "vue";
|
|
4
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, nextTick, onBeforeUnmount, onMounted, openBlock, ref, renderList, toDisplayString, unref, watch, withCtx } from "vue";
|
|
5
5
|
//#region packages/editor/src/layouts/workspace/Breadcrumb.vue?vue&type=script&setup=true&lang.ts
|
|
6
6
|
var _hoisted_1 = {
|
|
7
7
|
key: 0,
|
|
8
|
-
class: "m-editor-breadcrumb"
|
|
8
|
+
class: "m-editor-breadcrumb-ellipsis"
|
|
9
9
|
};
|
|
10
|
-
var _hoisted_2 = {
|
|
10
|
+
var _hoisted_2 = {
|
|
11
|
+
key: 2,
|
|
12
|
+
class: "m-editor-breadcrumb-separator"
|
|
13
|
+
};
|
|
14
|
+
var COLLAPSE_RATIO = .8;
|
|
11
15
|
var Breadcrumb_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
12
16
|
name: "MEditorBreadcrumb",
|
|
13
17
|
__name: "Breadcrumb",
|
|
@@ -17,21 +21,92 @@ var Breadcrumb_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
17
21
|
const nodes = computed(() => editorService.get("nodes"));
|
|
18
22
|
const root = computed(() => editorService.get("root"));
|
|
19
23
|
const path = computed(() => getNodePath(node.value?.id || "", root.value?.items || []));
|
|
24
|
+
const containerRef = ref(null);
|
|
25
|
+
const collapsed = ref(false);
|
|
26
|
+
const displayPath = computed(() => {
|
|
27
|
+
const list = path.value;
|
|
28
|
+
if (!collapsed.value || list.length <= 3) return list;
|
|
29
|
+
return [
|
|
30
|
+
list[0],
|
|
31
|
+
{
|
|
32
|
+
isEllipsis: true,
|
|
33
|
+
id: "__ellipsis__",
|
|
34
|
+
name: "..."
|
|
35
|
+
},
|
|
36
|
+
list[list.length - 2],
|
|
37
|
+
list[list.length - 1]
|
|
38
|
+
];
|
|
39
|
+
});
|
|
40
|
+
const measureOverflow = async () => {
|
|
41
|
+
if (collapsed.value) {
|
|
42
|
+
collapsed.value = false;
|
|
43
|
+
await nextTick();
|
|
44
|
+
}
|
|
45
|
+
const el = containerRef.value;
|
|
46
|
+
const parent = el?.parentElement;
|
|
47
|
+
if (!el || !parent) return;
|
|
48
|
+
const contentWidth = el.scrollWidth;
|
|
49
|
+
const parentWidth = parent.clientWidth;
|
|
50
|
+
if (parentWidth <= 0) return;
|
|
51
|
+
collapsed.value = contentWidth > parentWidth * COLLAPSE_RATIO;
|
|
52
|
+
};
|
|
53
|
+
let resizeObserver = null;
|
|
54
|
+
const observe = () => {
|
|
55
|
+
resizeObserver?.disconnect();
|
|
56
|
+
const el = containerRef.value;
|
|
57
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
58
|
+
resizeObserver = new ResizeObserver(() => {
|
|
59
|
+
measureOverflow();
|
|
60
|
+
});
|
|
61
|
+
resizeObserver.observe(el);
|
|
62
|
+
if (el.parentElement) resizeObserver.observe(el.parentElement);
|
|
63
|
+
};
|
|
64
|
+
onMounted(() => {
|
|
65
|
+
observe();
|
|
66
|
+
measureOverflow();
|
|
67
|
+
});
|
|
68
|
+
onBeforeUnmount(() => {
|
|
69
|
+
resizeObserver?.disconnect();
|
|
70
|
+
resizeObserver = null;
|
|
71
|
+
});
|
|
72
|
+
watch(() => nodes.value.length, async () => {
|
|
73
|
+
await nextTick();
|
|
74
|
+
observe();
|
|
75
|
+
measureOverflow();
|
|
76
|
+
});
|
|
77
|
+
watch(path, async () => {
|
|
78
|
+
await nextTick();
|
|
79
|
+
measureOverflow();
|
|
80
|
+
});
|
|
20
81
|
const select = async (node) => {
|
|
21
82
|
await editorService.select(node);
|
|
22
83
|
editorService.get("stage")?.select(node.id);
|
|
23
84
|
};
|
|
24
85
|
return (_ctx, _cache) => {
|
|
25
|
-
return nodes.value.length === 1 ? (openBlock(), createElementBlock("div",
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
86
|
+
return nodes.value.length === 1 ? (openBlock(), createElementBlock("div", {
|
|
87
|
+
key: 0,
|
|
88
|
+
ref_key: "containerRef",
|
|
89
|
+
ref: containerRef,
|
|
90
|
+
class: "m-editor-breadcrumb"
|
|
91
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(displayPath.value, (item, index) => {
|
|
92
|
+
return openBlock(), createElementBlock(Fragment, { key: item.isEllipsis ? `ellipsis-${index}` : item.id }, [item.isEllipsis ? (openBlock(), createElementBlock("span", _hoisted_1, "...")) : (openBlock(), createBlock(unref(TMagicTooltip), {
|
|
93
|
+
key: 1,
|
|
94
|
+
content: item.name,
|
|
95
|
+
placement: "top",
|
|
96
|
+
"show-after": 500
|
|
30
97
|
}, {
|
|
31
|
-
default: withCtx(() => [
|
|
98
|
+
default: withCtx(() => [createVNode(unref(TMagicButton), {
|
|
99
|
+
class: "m-editor-breadcrumb-item",
|
|
100
|
+
link: "",
|
|
101
|
+
disabled: item.id === node.value?.id,
|
|
102
|
+
onClick: ($event) => select(item)
|
|
103
|
+
}, {
|
|
104
|
+
default: withCtx(() => [createTextVNode(toDisplayString(item.name), 1)]),
|
|
105
|
+
_: 2
|
|
106
|
+
}, 1032, ["disabled", "onClick"])]),
|
|
32
107
|
_: 2
|
|
33
|
-
}, 1032, ["
|
|
34
|
-
}), 128))])) : createCommentVNode("v-if", true);
|
|
108
|
+
}, 1032, ["content"])), index < displayPath.value.length - 1 ? (openBlock(), createElementBlock("span", _hoisted_2, "/")) : createCommentVNode("v-if", true)], 64);
|
|
109
|
+
}), 128))], 512)) : createCommentVNode("v-if", true);
|
|
35
110
|
};
|
|
36
111
|
}
|
|
37
112
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useServices } from "../../hooks/use-services.js";
|
|
2
2
|
import Stage_default from "./viewer/Stage.js";
|
|
3
3
|
import Breadcrumb_default from "./Breadcrumb.js";
|
|
4
|
-
import { computed, createBlock, createCommentVNode, createElementBlock, createVNode, defineComponent, inject, openBlock, renderSlot, unref } from "vue";
|
|
4
|
+
import { computed, createBlock, createCommentVNode, createElementBlock, createVNode, defineComponent, inject, openBlock, renderSlot, unref, withCtx } from "vue";
|
|
5
5
|
//#region packages/editor/src/layouts/workspace/Workspace.vue?vue&type=script&setup=true&lang.ts
|
|
6
6
|
var _hoisted_1 = { class: "m-editor-workspace" };
|
|
7
7
|
var Workspace_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
@@ -28,7 +28,10 @@ var Workspace_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
|
|
|
28
28
|
"disabled-stage-overlay": __props.disabledStageOverlay,
|
|
29
29
|
"stage-content-menu": __props.stageContentMenu,
|
|
30
30
|
"custom-content-menu": __props.customContentMenu
|
|
31
|
-
},
|
|
31
|
+
}, {
|
|
32
|
+
"stage-top": withCtx(() => [renderSlot(_ctx.$slots, "stage-top")]),
|
|
33
|
+
_: 3
|
|
34
|
+
}, 8, [
|
|
32
35
|
"stage-options",
|
|
33
36
|
"disabled-stage-overlay",
|
|
34
37
|
"stage-content-menu",
|
|
@@ -9,7 +9,7 @@ import StageOverlay_default from "./StageOverlay.js";
|
|
|
9
9
|
import ViewerMenu_default from "./ViewerMenu.js";
|
|
10
10
|
import { getOffset } from "@tmagic/stage";
|
|
11
11
|
import { calcValueByFontsize, getIdFromEl } from "@tmagic/utils";
|
|
12
|
-
import { Teleport, computed, createBlock, createCommentVNode, createElementVNode, createVNode, defineComponent, markRaw, nextTick, normalizeStyle, onBeforeUnmount, onMounted, openBlock, resolveDirective, useTemplateRef, watch, watchEffect, withCtx, withDirectives } from "vue";
|
|
12
|
+
import { Teleport, computed, createBlock, createCommentVNode, createElementVNode, createVNode, defineComponent, markRaw, nextTick, normalizeStyle, onBeforeUnmount, onMounted, openBlock, renderSlot, resolveDirective, useTemplateRef, watch, watchEffect, withCtx, withDirectives } from "vue";
|
|
13
13
|
//#region packages/editor/src/layouts/workspace/viewer/Stage.vue?vue&type=script&setup=true&lang.ts
|
|
14
14
|
var Stage_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
15
15
|
name: "MEditorStage",
|
|
@@ -184,9 +184,20 @@ var Stage_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
184
184
|
const doc = stage?.renderer?.contentWindow?.document;
|
|
185
185
|
const parentEl = doc?.querySelector(`.${props.stageOptions?.containerHighlightClassName}`);
|
|
186
186
|
let parent = page.value;
|
|
187
|
+
let resolvedParentEl = parentEl;
|
|
187
188
|
const parentId = getIdFromEl()(parentEl);
|
|
188
189
|
if (parentId) parent = editorService.getNodeById(parentId, false);
|
|
189
190
|
if (parent && stageContainerEl.value && stage) {
|
|
191
|
+
if (props.stageOptions.canDropIn) {
|
|
192
|
+
const result = props.stageOptions.canDropIn([], parent.id);
|
|
193
|
+
if (result === false) return;
|
|
194
|
+
if (typeof result === "string" || typeof result === "number") {
|
|
195
|
+
const redirectedNode = editorService.getNodeById(result, false);
|
|
196
|
+
if (!redirectedNode) return;
|
|
197
|
+
parent = redirectedNode;
|
|
198
|
+
resolvedParentEl = stage.renderer?.getTargetElement(result) ?? null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
190
201
|
const layout = await editorService.getLayout(parent);
|
|
191
202
|
const containerRect = stageContainerEl.value.getBoundingClientRect();
|
|
192
203
|
const { scrollTop, scrollLeft } = stage.mask;
|
|
@@ -202,8 +213,8 @@ var Stage_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
202
213
|
position = "absolute";
|
|
203
214
|
top = e.clientY - containerRect.top + scrollTop;
|
|
204
215
|
left = e.clientX - containerRect.left + scrollLeft;
|
|
205
|
-
if (
|
|
206
|
-
const { left: parentLeft, top: parentTop } = getOffset(
|
|
216
|
+
if (resolvedParentEl) {
|
|
217
|
+
const { left: parentLeft, top: parentTop } = getOffset(resolvedParentEl);
|
|
207
218
|
left = left - parentLeft * zoom.value;
|
|
208
219
|
top = top - parentTop * zoom.value;
|
|
209
220
|
}
|
|
@@ -236,6 +247,7 @@ var Stage_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
236
247
|
},
|
|
237
248
|
onClick: _cache[0] || (_cache[0] = ($event) => stageWrapRef.value?.container?.focus())
|
|
238
249
|
}, {
|
|
250
|
+
before: withCtx(() => [renderSlot(_ctx.$slots, "stage-top")]),
|
|
239
251
|
content: withCtx(() => [!__props.disabledStageOverlay ? (openBlock(), createBlock(StageOverlay_default, { key: 0 })) : createCommentVNode("v-if", true), (openBlock(), createBlock(Teleport, { to: "body" }, [createVNode(ViewerMenu_default, {
|
|
240
252
|
ref: "menu",
|
|
241
253
|
"is-multi-select": isMultiSelect.value,
|
|
@@ -254,7 +266,7 @@ var Stage_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
254
266
|
onDrop: dropHandler,
|
|
255
267
|
onDragover: dragoverHandler
|
|
256
268
|
}, null, 36), createVNode(NodeListMenu_default)]),
|
|
257
|
-
_:
|
|
269
|
+
_: 3
|
|
258
270
|
}, 8, [
|
|
259
271
|
"width",
|
|
260
272
|
"height",
|
|
@@ -25,7 +25,8 @@ var Editor = class extends BaseService_default {
|
|
|
25
25
|
modifiedNodeIds: /* @__PURE__ */ new Map(),
|
|
26
26
|
pageLength: 0,
|
|
27
27
|
pageFragmentLength: 0,
|
|
28
|
-
disabledMultiSelect: false
|
|
28
|
+
disabledMultiSelect: false,
|
|
29
|
+
alwaysMultiSelect: false
|
|
29
30
|
});
|
|
30
31
|
isHistoryStateChange = false;
|
|
31
32
|
selectionBeforeOp = null;
|
|
@@ -54,6 +54,9 @@ var Props = class extends BaseService_default {
|
|
|
54
54
|
});
|
|
55
55
|
this.emit("props-configs-change");
|
|
56
56
|
}
|
|
57
|
+
getPropsConfigs() {
|
|
58
|
+
return this.state.propsConfigMap;
|
|
59
|
+
}
|
|
57
60
|
async fillConfig(config, labelWidth) {
|
|
58
61
|
return fillConfig(config, {
|
|
59
62
|
labelWidth: typeof labelWidth !== "function" ? labelWidth : "80px",
|
|
@@ -72,15 +75,21 @@ var Props = class extends BaseService_default {
|
|
|
72
75
|
* @param type 组件类型
|
|
73
76
|
* @returns 组件属性表单配置
|
|
74
77
|
*/
|
|
75
|
-
async getPropsConfig(type) {
|
|
76
|
-
if (type === "area") return await this.getPropsConfig("button");
|
|
78
|
+
async getPropsConfig(type, data) {
|
|
79
|
+
if (type === "area") return await this.getPropsConfig("button", data);
|
|
77
80
|
return cloneDeep(this.state.propsConfigMap[toLine(type)] || await this.fillConfig([]));
|
|
78
81
|
}
|
|
82
|
+
hasPropsConfig(type) {
|
|
83
|
+
return !!this.state.propsConfigMap[toLine(type)];
|
|
84
|
+
}
|
|
79
85
|
setPropsValues(values) {
|
|
80
86
|
Object.keys(values).forEach((type) => {
|
|
81
87
|
this.setPropsValue(toLine(type), values[type]);
|
|
82
88
|
});
|
|
83
89
|
}
|
|
90
|
+
getPropsValues() {
|
|
91
|
+
return this.state.propsValueMap;
|
|
92
|
+
}
|
|
84
93
|
/**
|
|
85
94
|
* 为指点类型组件设置组件初始值
|
|
86
95
|
* @param type 组件类型
|
|
@@ -117,6 +126,9 @@ var Props = class extends BaseService_default {
|
|
|
117
126
|
...mergeWith({}, cloneDeep(this.state.propsValueMap[type] || {}), data)
|
|
118
127
|
};
|
|
119
128
|
}
|
|
129
|
+
hasPropsValue(type) {
|
|
130
|
+
return !!this.state.propsValueMap[toLine(type)];
|
|
131
|
+
}
|
|
120
132
|
createId(type) {
|
|
121
133
|
return `${type}_${guid()}`;
|
|
122
134
|
}
|
package/dist/es/style.css
CHANGED
|
@@ -1325,6 +1325,26 @@ fieldset.m-fieldset .m-form-tip {
|
|
|
1325
1325
|
left: 5px;
|
|
1326
1326
|
top: 5px;
|
|
1327
1327
|
z-index: 10;
|
|
1328
|
+
display: flex;
|
|
1329
|
+
align-items: center;
|
|
1330
|
+
white-space: nowrap;
|
|
1331
|
+
}
|
|
1332
|
+
.m-editor-breadcrumb .m-editor-breadcrumb-item {
|
|
1333
|
+
max-width: 100px;
|
|
1334
|
+
min-width: 0;
|
|
1335
|
+
overflow: hidden;
|
|
1336
|
+
}
|
|
1337
|
+
.m-editor-breadcrumb .m-editor-breadcrumb-item > span {
|
|
1338
|
+
display: block;
|
|
1339
|
+
max-width: 100%;
|
|
1340
|
+
overflow: hidden;
|
|
1341
|
+
text-overflow: ellipsis;
|
|
1342
|
+
white-space: nowrap;
|
|
1343
|
+
}
|
|
1344
|
+
.m-editor-breadcrumb .m-editor-breadcrumb-separator,
|
|
1345
|
+
.m-editor-breadcrumb .m-editor-breadcrumb-ellipsis {
|
|
1346
|
+
margin: 0 4px;
|
|
1347
|
+
flex-shrink: 0;
|
|
1328
1348
|
}
|
|
1329
1349
|
|
|
1330
1350
|
.data-source-list-panel .list-container .list-item .codeIcon {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region packages/editor/src/utils/dep/worker.ts?worker&inline
|
|
2
|
-
var jsContent = "(function() {\n //#region packages/schema/src/index.ts\n const NODE_CONDS_KEY = \"displayConds\";\n const NODE_DISABLE_DATA_SOURCE_KEY = \"_tmagic_node_disabled_data_source\";\n const NODE_DISABLE_CODE_BLOCK_KEY = \"_tmagic_node_disabled_code_block\";\n let HookType = /* @__PURE__ */ function(HookType) {\n /** 代码块钩子标识 */\n HookType[\"CODE\"] = \"code\";\n return HookType;\n }({});\n //#endregion\n //#region packages/utils/src/const.ts\n const DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX = \"ds-field::\";\n //#endregion\n //#region packages/utils/src/index.ts\n const isObject = (obj) => Object.prototype.toString.call(obj) === \"[object Object]\";\n const getKeysArray = (keys) => `${keys}`.replace(/\\[(\\d+)\\]/g, \".$1\").split(\".\");\n const dataSourceTemplateRegExp = /\\$\\{([\\s\\S]+?)\\}/g;\n //#endregion\n //#region packages/dep/src/types.ts\n /** 依赖收集的目标类型 */\n let DepTargetType = /* @__PURE__ */ function(DepTargetType) {\n DepTargetType[\"DEFAULT\"] = \"default\";\n /** 代码块 */\n DepTargetType[\"CODE_BLOCK\"] = \"code-block\";\n /** 数据源 */\n DepTargetType[\"DATA_SOURCE\"] = \"data-source\";\n /** 数据源方法 */\n DepTargetType[\"DATA_SOURCE_METHOD\"] = \"data-source-method\";\n /** 数据源条件 */\n DepTargetType[\"DATA_SOURCE_COND\"] = \"data-source-cond\";\n return DepTargetType;\n }({});\n //#endregion\n //#region packages/dep/src/Target.ts\n /**\n * 需要收集依赖的目标\n * 例如:一个代码块可以为一个目标\n */\n var Target = class {\n /**\n * 如何识别目标\n */\n isTarget;\n /**\n * 目标id,不可重复\n * 例如目标是代码块,则为代码块id\n */\n id;\n /**\n * 目标名称,用于显示在依赖列表中\n */\n name;\n /**\n * 不同的目标可以进行分类,例如代码块,数据源可以为两个不同的type\n */\n type = DepTargetType.DEFAULT;\n /**\n * 依赖详情\n * 实例:{ 'node_id': { name: 'node_name', keys: [ created, mounted ] } }\n */\n deps = {};\n /**\n * 是否默认收集,默认为true,当值为false时需要传入type参数给collect方法才会被收集\n */\n isCollectByDefault;\n constructor(options) {\n this.isTarget = options.isTarget;\n this.id = options.id;\n this.name = options.name;\n this.isCollectByDefault = options.isCollectByDefault ?? true;\n if (options.type) this.type = options.type;\n if (options.initialDeps) this.deps = options.initialDeps;\n }\n /**\n * 更新依赖\n * @param option 节点配置\n * @param key 哪个key配置了这个目标的id\n */\n updateDep({ id, name, key, data }) {\n const dep = this.deps[id] || {\n name,\n keys: []\n };\n dep.name = name;\n dep.data = data;\n this.deps[id] = dep;\n if (!dep.keys.includes(key)) dep.keys.push(key);\n }\n /**\n * 删除依赖\n * @param node 哪个节点的依赖需要移除,如果为空,则移除所有依赖\n * @param key 节点下哪个key需要移除,如果为空,则移除改节点下的所有依赖key\n * @returns void\n */\n removeDep(id, key) {\n if (typeof id === \"undefined\") {\n Object.keys(this.deps).forEach((depKey) => {\n delete this.deps[depKey];\n });\n return;\n }\n const dep = this.deps[id];\n if (!dep) return;\n if (key) {\n const index = dep.keys.indexOf(key);\n dep.keys.splice(index, 1);\n if (dep.keys.length === 0) delete this.deps[id];\n } else delete this.deps[id];\n }\n /**\n * 判断指定节点下的指定key是否存在在依赖列表中\n * @param node 哪个节点\n * @param key 哪个key\n * @returns boolean\n */\n hasDep(id, key) {\n return this.deps[id]?.keys.includes(key) ?? false;\n }\n destroy() {\n this.deps = {};\n }\n };\n //#endregion\n //#region packages/dep/src/utils.ts\n const INTEGER_REGEXP = /^\\d+$/;\n const createCodeBlockTarget = (id, codeBlock, initialDeps = {}) => new Target({\n type: DepTargetType.CODE_BLOCK,\n id,\n initialDeps,\n name: codeBlock.name,\n isTarget: (_key, value) => {\n if (id === value) return true;\n if (value?.hookType === HookType.CODE && Array.isArray(value.hookData)) return value.hookData.some((item) => item.codeId === id);\n return false;\n }\n });\n /**\n * ['array'] ['array', '0'] ['array', '0', 'a'] 这种返回false\n * ['array', 'a'] 这种返回true\n * @param keys\n * @param fields\n * @returns boolean\n */\n const isIncludeArrayField = (keys, fields) => {\n let f = fields;\n return keys.some((key, index) => {\n const field = f.find(({ name }) => name === key);\n f = field?.fields || [];\n return field?.type === \"array\" && index < keys.length - 1 && !INTEGER_REGEXP.test(keys[index + 1]);\n });\n };\n /**\n * 判断模板(value)是不是使用数据源Id(dsId),如:`xxx${dsId.field}xxx${dsId.field}`\n * @param value any\n * @param dsId string | number\n * @param hasArray boolean true: 一定要包含有需要迭代的模板; false: 一定要包含普通模板;\n * @returns boolean\n */\n const isDataSourceTemplate = (value, ds, hasArray = false) => {\n const templates = value.match(dataSourceTemplateRegExp) || [];\n if (templates.length <= 0) return false;\n for (const tpl of templates) {\n const keys = getKeysArray(tpl.substring(2, tpl.length - 1));\n const dsId = keys.shift();\n if (!dsId || dsId !== ds.id) continue;\n if (hasArray === isIncludeArrayField(keys, ds.fields)) return true;\n }\n return false;\n };\n /**\n * 指定数据源的字符串模板,如:{ isBindDataSourceField: true, dataSourceId: 'id', template: `xxx${field}xxx`}\n * @param value any\n * @param dsId string | number\n * @returns boolean\n */\n const isSpecificDataSourceTemplate = (value, dsId) => value?.isBindDataSourceField && value.dataSourceId && value.dataSourceId === dsId && typeof value.template === \"string\";\n /**\n * 关联数据源字段,格式为 [前缀+数据源ID, 字段名]\n * 使用data-source-field-select value: 'value' 可以配置出来\n * @param value any[]\n * @param id string | number\n * @returns boolean\n */\n const isUseDataSourceField = (value, id) => {\n if (!Array.isArray(value) || typeof value[0] !== \"string\") return false;\n const [prefixId] = value;\n const prefixIndex = prefixId.indexOf(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX);\n if (prefixIndex === -1) return false;\n return prefixId.substring(prefixIndex + DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX.length) === id;\n };\n const isDataSourceTarget = (ds, key, value, hasArray = false) => {\n if (!value) return false;\n const valueType = typeof value;\n if (valueType !== \"string\" && valueType !== \"object\") return false;\n if (`${key}`.startsWith(\"displayConds\")) return false;\n if (valueType === \"string\") return isDataSourceTemplate(value, ds, hasArray);\n if (isObject(value) && value.isBindDataSource && value.dataSourceId === ds.id) return true;\n if (isSpecificDataSourceTemplate(value, ds.id)) return true;\n if (isUseDataSourceField(value, ds.id)) {\n const [, ...keys] = value;\n const includeArray = isIncludeArrayField(keys, ds.fields);\n return hasArray ? includeArray : !includeArray;\n }\n return false;\n };\n const isDataSourceCondTarget = (ds, key, value, hasArray = false) => {\n if (!Array.isArray(value) || !ds) return false;\n const [dsId, ...keys] = value;\n if (dsId !== ds.id || !`${key}`.startsWith(\"displayConds\")) return false;\n if (ds.fields?.some((field) => field.name === keys[0])) {\n const includeArray = isIncludeArrayField(keys, ds.fields);\n return hasArray ? includeArray : !includeArray;\n }\n return false;\n };\n const createDataSourceTarget = (ds, initialDeps = {}) => new Target({\n type: DepTargetType.DATA_SOURCE,\n id: ds.id,\n initialDeps,\n isTarget: (key, value) => isDataSourceTarget(ds, key, value)\n });\n const createDataSourceCondTarget = (ds, initialDeps = {}) => new Target({\n type: DepTargetType.DATA_SOURCE_COND,\n id: ds.id,\n initialDeps,\n isTarget: (key, value) => isDataSourceCondTarget(ds, key, value)\n });\n const createDataSourceMethodTarget = (ds, initialDeps = {}) => new Target({\n type: DepTargetType.DATA_SOURCE_METHOD,\n id: ds.id,\n initialDeps,\n isTarget: (_key, value) => {\n if (!Array.isArray(value)) return false;\n const [dsId, methodName] = value;\n if (!methodName || dsId !== ds.id) return false;\n if (ds.methods?.some((method) => method.name === methodName)) return true;\n if (ds.fields?.some((field) => field.name === methodName)) return false;\n return true;\n }\n });\n const traverseTarget = (targetsList, cb, type) => {\n if (type) {\n const targets = targetsList[type];\n if (targets) for (const target of Object.values(targets)) cb(target);\n return;\n }\n for (const targets of Object.values(targetsList)) for (const target of Object.values(targets)) cb(target);\n };\n //#endregion\n //#region packages/dep/src/Watcher.ts\n const DATA_SOURCE_TARGET_TYPES = new Set([\n DepTargetType.DATA_SOURCE,\n DepTargetType.DATA_SOURCE_COND,\n DepTargetType.DATA_SOURCE_METHOD\n ]);\n var Watcher = class {\n targetsList = {};\n childrenProp = \"items\";\n idProp = \"id\";\n nameProp = \"name\";\n constructor(options) {\n if (options?.initialTargets) this.targetsList = options.initialTargets;\n if (options?.childrenProp) this.childrenProp = options.childrenProp;\n }\n getTargetsList() {\n return this.targetsList;\n }\n /**\n * 获取指定类型中的所有target\n * @param type 分类\n * @returns Target[]\n */\n getTargets(type = DepTargetType.DEFAULT) {\n return this.targetsList[type] || {};\n }\n /**\n * 添加新的目标\n * @param target Target\n */\n addTarget(target) {\n const targets = this.getTargets(target.type) || {};\n this.targetsList[target.type] = targets;\n targets[target.id] = target;\n }\n /**\n * 获取指定id的target\n * @param id target id\n * @returns Target\n */\n getTarget(id, type = DepTargetType.DEFAULT) {\n return this.getTargets(type)[id];\n }\n /**\n * 判断是否存在指定id的target\n * @param id target id\n * @returns boolean\n */\n hasTarget(id, type = DepTargetType.DEFAULT) {\n return Boolean(this.getTarget(id, type));\n }\n /**\n * 判断是否存在指定类型的target\n * @param type target type\n * @returns boolean\n */\n hasSpecifiedTypeTarget(type = DepTargetType.DEFAULT) {\n return Object.keys(this.getTargets(type)).length > 0;\n }\n /**\n * 删除指定id的target\n * @param id target id\n */\n removeTarget(id, type = DepTargetType.DEFAULT) {\n const targets = this.getTargets(type);\n if (targets[id]) {\n targets[id].destroy();\n delete targets[id];\n }\n }\n /**\n * 删除指定分类的所有target\n * @param type 分类\n * @returns void\n */\n removeTargets(type = DepTargetType.DEFAULT) {\n const targets = this.targetsList[type];\n if (!targets) return;\n for (const target of Object.values(targets)) target.destroy();\n delete this.targetsList[type];\n }\n /**\n * 删除所有target\n */\n clearTargets() {\n for (const key of Object.keys(this.targetsList)) delete this.targetsList[key];\n }\n /**\n * 收集依赖\n * @param nodes 需要收集的节点\n * @param deep 是否需要收集子节点\n * @param type 强制收集指定类型的依赖\n */\n collect(nodes, depExtendedData = {}, deep = false, type) {\n this.collectByCallback(nodes, type, ({ node, target }) => {\n this.removeTargetDep(target, node);\n this.collectItem(node, target, depExtendedData, deep);\n });\n }\n collectByCallback(nodes, type, cb) {\n traverseTarget(this.targetsList, (target) => {\n if (!type && !target.isCollectByDefault) return;\n for (const node of nodes) cb({\n node,\n target\n });\n }, type);\n }\n /**\n * 清除所有目标的依赖\n * @param nodes 需要清除依赖的节点\n */\n clear(nodes, type) {\n let { targetsList } = this;\n if (type) targetsList = { [type]: this.getTargets(type) };\n const clearedItemsNodeIds = /* @__PURE__ */ new Set();\n traverseTarget(targetsList, (target) => {\n if (nodes) for (const node of nodes) {\n target.removeDep(node[this.idProp]);\n if (Array.isArray(node[this.childrenProp]) && node[this.childrenProp].length && !clearedItemsNodeIds.has(node[this.idProp])) {\n clearedItemsNodeIds.add(node[this.idProp]);\n this.clear(node[this.childrenProp]);\n }\n }\n else target.removeDep();\n });\n }\n /**\n * 清除指定类型的依赖\n * @param type 类型\n * @param nodes 需要清除依赖的节点\n */\n clearByType(type, nodes) {\n this.clear(nodes, type);\n }\n collectItem(node, target, depExtendedData = {}, deep = false) {\n if (node[\"_tmagic_node_disabled_data_source\"] && DATA_SOURCE_TARGET_TYPES.has(target.type)) return;\n if (node[\"_tmagic_node_disabled_code_block\"] && target.type === DepTargetType.CODE_BLOCK) return;\n const collectTarget = (config, prop = \"\") => {\n const doCollect = (key, value) => {\n const keyIsItems = key === this.childrenProp;\n const fullKey = prop ? `${prop}.${key}` : key;\n if (target.isTarget(fullKey, value)) target.updateDep({\n id: node[this.idProp],\n name: `${node[this.nameProp] || node[this.idProp]}`,\n data: depExtendedData,\n key: fullKey\n });\n else if (!keyIsItems && Array.isArray(value)) for (let i = 0, l = value.length; i < l; i++) {\n const item = value[i];\n if (isObject(item)) collectTarget(item, `${fullKey}[${i}]`);\n }\n else if (isObject(value)) collectTarget(value, fullKey);\n if (keyIsItems && deep && Array.isArray(value)) for (const child of value) this.collectItem(child, target, depExtendedData, deep);\n };\n for (const [key, value] of Object.entries(config)) {\n if (typeof value === \"undefined\" || value === \"\") continue;\n doCollect(key, value);\n }\n };\n collectTarget(node);\n }\n removeTargetDep(target, node, key) {\n target.removeDep(node[this.idProp], key);\n if (typeof key === \"undefined\" && Array.isArray(node[this.childrenProp]) && node[this.childrenProp].length) for (const item of node[this.childrenProp]) this.removeTargetDep(target, item, key);\n }\n };\n //#endregion\n //#region packages/editor/src/utils/logger.ts\n const error = (...args) => {\n console.error(\"magic editor: \", ...args);\n };\n //#endregion\n //#region packages/editor/src/utils/dep/worker.ts\n onmessage = (e) => {\n const watcher = new Watcher({ initialTargets: {} });\n const { dsl } = e.data;\n try {\n const mApp = eval(`(${dsl})`);\n if (!mApp) postMessage({});\n watcher.clearTargets();\n if (mApp.codeBlocks) for (const [id, code] of Object.entries(mApp.codeBlocks)) watcher.addTarget(createCodeBlockTarget(id, code));\n if (mApp.dataSources) for (const ds of mApp.dataSources) {\n watcher.addTarget(createDataSourceTarget(ds, {}));\n watcher.addTarget(createDataSourceMethodTarget(ds, {}));\n watcher.addTarget(createDataSourceCondTarget(ds, {}));\n }\n watcher.collectByCallback(mApp.items, void 0, ({ node, target }) => {\n watcher.collectItem(node, target, { pageId: node.id }, true);\n });\n const data = {\n [DepTargetType.DATA_SOURCE]: {},\n [DepTargetType.DATA_SOURCE_METHOD]: {},\n [DepTargetType.DATA_SOURCE_COND]: {},\n [DepTargetType.CODE_BLOCK]: {}\n };\n traverseTarget(watcher.getTargetsList(), (target) => {\n data[target.type][target.id] = target.deps;\n });\n postMessage(data);\n } catch (e) {\n error(e);\n postMessage({});\n }\n };\n //#endregion\n})();\n";
|
|
2
|
+
var jsContent = "(function() {\n //#region packages/schema/src/index.ts\n const NODE_CONDS_KEY = \"displayConds\";\n const NODE_DISABLE_DATA_SOURCE_KEY = \"_tmagic_node_disabled_data_source\";\n const NODE_DISABLE_CODE_BLOCK_KEY = \"_tmagic_node_disabled_code_block\";\n let HookType = /* @__PURE__ */ function(HookType) {\n /** 代码块钩子标识 */\n HookType[\"CODE\"] = \"code\";\n return HookType;\n }({});\n //#endregion\n //#region packages/utils/src/const.ts\n const DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX = \"ds-field::\";\n //#endregion\n //#region packages/utils/src/index.ts\n const isObject = (obj) => Object.prototype.toString.call(obj) === \"[object Object]\";\n const getKeysArray = (keys) => `${keys}`.replace(/\\[(\\d+)\\]/g, \".$1\").split(\".\");\n const dataSourceTemplateRegExp = /\\$\\{([\\s\\S]+?)\\}/g;\n //#endregion\n //#region packages/dep/src/types.ts\n /** 依赖收集的目标类型 */\n let DepTargetType = /* @__PURE__ */ function(DepTargetType) {\n DepTargetType[\"DEFAULT\"] = \"default\";\n /** 代码块 */\n DepTargetType[\"CODE_BLOCK\"] = \"code-block\";\n /** 数据源 */\n DepTargetType[\"DATA_SOURCE\"] = \"data-source\";\n /** 数据源方法 */\n DepTargetType[\"DATA_SOURCE_METHOD\"] = \"data-source-method\";\n /** 数据源条件 */\n DepTargetType[\"DATA_SOURCE_COND\"] = \"data-source-cond\";\n return DepTargetType;\n }({});\n //#endregion\n //#region packages/dep/src/Target.ts\n /**\n * 需要收集依赖的目标\n * 例如:一个代码块可以为一个目标\n */\n var Target = class {\n /**\n * 如何识别目标\n */\n isTarget;\n /**\n * 目标id,不可重复\n * 例如目标是代码块,则为代码块id\n */\n id;\n /**\n * 目标名称,用于显示在依赖列表中\n */\n name;\n /**\n * 不同的目标可以进行分类,例如代码块,数据源可以为两个不同的type\n */\n type = DepTargetType.DEFAULT;\n /**\n * 依赖详情\n * 实例:{ 'node_id': { name: 'node_name', keys: [ created, mounted ] } }\n */\n deps = {};\n /**\n * 是否默认收集,默认为true,当值为false时需要传入type参数给collect方法才会被收集\n */\n isCollectByDefault;\n constructor(options) {\n this.isTarget = options.isTarget;\n this.id = options.id;\n this.name = options.name;\n this.isCollectByDefault = options.isCollectByDefault ?? true;\n if (options.type) this.type = options.type;\n if (options.initialDeps) this.deps = options.initialDeps;\n }\n /**\n * 更新依赖\n * @param option 节点配置\n * @param key 哪个key配置了这个目标的id\n */\n updateDep({ id, name, key, data }) {\n const dep = this.deps[id] || {\n name,\n keys: []\n };\n dep.name = name;\n dep.data = data;\n this.deps[id] = dep;\n if (!dep.keys.includes(key)) dep.keys.push(key);\n }\n /**\n * 删除依赖\n * @param node 哪个节点的依赖需要移除,如果为空,则移除所有依赖\n * @param key 节点下哪个key需要移除,如果为空,则移除改节点下的所有依赖key\n * @returns void\n */\n removeDep(id, key) {\n if (typeof id === \"undefined\") {\n Object.keys(this.deps).forEach((depKey) => {\n delete this.deps[depKey];\n });\n return;\n }\n const dep = this.deps[id];\n if (!dep) return;\n if (key) {\n const index = dep.keys.indexOf(key);\n dep.keys.splice(index, 1);\n if (dep.keys.length === 0) delete this.deps[id];\n } else delete this.deps[id];\n }\n /**\n * 判断指定节点下的指定key是否存在在依赖列表中\n * @param node 哪个节点\n * @param key 哪个key\n * @returns boolean\n */\n hasDep(id, key) {\n return this.deps[id]?.keys.includes(key) ?? false;\n }\n destroy() {\n this.deps = {};\n }\n };\n //#endregion\n //#region packages/dep/src/utils.ts\n const INTEGER_REGEXP = /^\\d+$/;\n const createCodeBlockTarget = (id, codeBlock, initialDeps = {}) => new Target({\n type: DepTargetType.CODE_BLOCK,\n id,\n initialDeps,\n name: codeBlock.name,\n isTarget: (_key, value) => {\n if (id === value) return true;\n if (value?.hookType === HookType.CODE && Array.isArray(value.hookData)) return value.hookData.some((item) => item.codeId === id);\n return false;\n }\n });\n /**\n * ['array'] ['array', '0'] ['array', '0', 'a'] 这种返回false\n * ['array', 'a'] 这种返回true\n * @param keys\n * @param fields\n * @returns boolean\n */\n const isIncludeArrayField = (keys, fields) => {\n let f = fields;\n return keys.some((key, index) => {\n const field = f.find(({ name }) => name === key);\n f = field?.fields || [];\n return field?.type === \"array\" && index < keys.length - 1 && !INTEGER_REGEXP.test(keys[index + 1]);\n });\n };\n /**\n * 判断模板(value)是不是使用数据源Id(dsId),如:`xxx${dsId.field}xxx${dsId.field}`\n * @param value any\n * @param dsId string | number\n * @param hasArray boolean true: 一定要包含有需要迭代的模板; false: 一定要包含普通模板;\n * @returns boolean\n */\n const isDataSourceTemplate = (value, ds, hasArray = false) => {\n const templates = value.match(dataSourceTemplateRegExp) || [];\n if (templates.length <= 0) return false;\n for (const tpl of templates) {\n const keys = getKeysArray(tpl.substring(2, tpl.length - 1));\n const dsId = keys.shift();\n if (!dsId || dsId !== ds.id) continue;\n if (hasArray === isIncludeArrayField(keys, ds.fields)) return true;\n }\n return false;\n };\n /**\n * 指定数据源的字符串模板,如:{ isBindDataSourceField: true, dataSourceId: 'id', template: `xxx${field}xxx`}\n * @param value any\n * @param dsId string | number\n * @returns boolean\n */\n const isSpecificDataSourceTemplate = (value, dsId) => value?.isBindDataSourceField && value.dataSourceId && value.dataSourceId === dsId && typeof value.template === \"string\";\n /**\n * 关联数据源字段,格式为 [前缀+数据源ID, 字段名]\n * 使用data-source-field-select value: 'value' 可以配置出来\n * @param value any[]\n * @param id string | number\n * @returns boolean\n */\n const isUseDataSourceField = (value, id) => {\n if (!Array.isArray(value) || typeof value[0] !== \"string\") return false;\n const [prefixId] = value;\n const prefixIndex = prefixId.indexOf(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX);\n if (prefixIndex === -1) return false;\n return prefixId.substring(prefixIndex + DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX.length) === id;\n };\n const isDataSourceTarget = (ds, key, value, hasArray = false) => {\n if (!value) return false;\n const valueType = typeof value;\n if (valueType !== \"string\" && valueType !== \"object\") return false;\n if (`${key}`.startsWith(\"displayConds\")) return false;\n if (valueType === \"string\") return isDataSourceTemplate(value, ds, hasArray);\n if (isObject(value) && value.isBindDataSource && value.dataSourceId === ds.id) return true;\n if (isSpecificDataSourceTemplate(value, ds.id)) return true;\n if (isUseDataSourceField(value, ds.id)) {\n const [, ...keys] = value;\n const includeArray = isIncludeArrayField(keys, ds.fields);\n return hasArray ? includeArray : !includeArray;\n }\n return false;\n };\n const isDataSourceCondTarget = (ds, key, value, hasArray = false) => {\n if (!Array.isArray(value) || !ds) return false;\n const [dsId, ...keys] = value;\n if (dsId !== ds.id || !`${key}`.startsWith(\"displayConds\")) return false;\n if (ds.fields?.some((field) => field.name === keys[0])) {\n const includeArray = isIncludeArrayField(keys, ds.fields);\n return hasArray ? includeArray : !includeArray;\n }\n return false;\n };\n const createDataSourceTarget = (ds, initialDeps = {}) => new Target({\n type: DepTargetType.DATA_SOURCE,\n id: ds.id,\n initialDeps,\n isTarget: (key, value) => isDataSourceTarget(ds, key, value)\n });\n const createDataSourceCondTarget = (ds, initialDeps = {}) => new Target({\n type: DepTargetType.DATA_SOURCE_COND,\n id: ds.id,\n initialDeps,\n isTarget: (key, value) => isDataSourceCondTarget(ds, key, value)\n });\n const createDataSourceMethodTarget = (ds, initialDeps = {}) => new Target({\n type: DepTargetType.DATA_SOURCE_METHOD,\n id: ds.id,\n initialDeps,\n isTarget: (_key, value) => {\n if (!Array.isArray(value)) return false;\n const [dsId, methodName] = value;\n if (!methodName || dsId !== ds.id) return false;\n if (ds.methods?.some((method) => method.name === methodName)) return true;\n if (ds.fields?.some((field) => field.name === methodName)) return false;\n return true;\n }\n });\n const traverseTarget = (targetsList, cb, type) => {\n if (type) {\n const targets = targetsList[type];\n if (targets) for (const target of Object.values(targets)) cb(target);\n return;\n }\n for (const targets of Object.values(targetsList)) for (const target of Object.values(targets)) cb(target);\n };\n //#endregion\n //#region packages/dep/src/Watcher.ts\n const DATA_SOURCE_TARGET_TYPES = new Set([\n DepTargetType.DATA_SOURCE,\n DepTargetType.DATA_SOURCE_COND,\n DepTargetType.DATA_SOURCE_METHOD\n ]);\n var Watcher = class {\n targetsList = {};\n childrenProp = \"items\";\n idProp = \"id\";\n nameProp = \"name\";\n constructor(options) {\n if (options?.initialTargets) this.targetsList = options.initialTargets;\n if (options?.childrenProp) this.childrenProp = options.childrenProp;\n }\n getTargetsList() {\n return this.targetsList;\n }\n /**\n * 获取指定类型中的所有target\n * @param type 分类\n * @returns Target[]\n */\n getTargets(type = DepTargetType.DEFAULT) {\n return this.targetsList[type] || {};\n }\n /**\n * 添加新的目标\n * @param target Target\n */\n addTarget(target) {\n const targets = this.getTargets(target.type) || {};\n this.targetsList[target.type] = targets;\n targets[target.id] = target;\n }\n /**\n * 获取指定id的target\n * @param id target id\n * @returns Target\n */\n getTarget(id, type = DepTargetType.DEFAULT) {\n return this.getTargets(type)[id];\n }\n /**\n * 判断是否存在指定id的target\n * @param id target id\n * @returns boolean\n */\n hasTarget(id, type = DepTargetType.DEFAULT) {\n return Boolean(this.getTarget(id, type));\n }\n /**\n * 判断是否存在指定类型的target\n * @param type target type\n * @returns boolean\n */\n hasSpecifiedTypeTarget(type = DepTargetType.DEFAULT) {\n return Object.keys(this.getTargets(type)).length > 0;\n }\n /**\n * 删除指定id的target\n * @param id target id\n */\n removeTarget(id, type = DepTargetType.DEFAULT) {\n const targets = this.getTargets(type);\n if (targets[id]) {\n targets[id].destroy();\n delete targets[id];\n }\n }\n /**\n * 删除指定分类的所有target\n * @param type 分类\n * @returns void\n */\n removeTargets(type = DepTargetType.DEFAULT) {\n const targets = this.targetsList[type];\n if (!targets) return;\n for (const target of Object.values(targets)) target.destroy();\n delete this.targetsList[type];\n }\n /**\n * 删除所有target\n */\n clearTargets() {\n for (const key of Object.keys(this.targetsList)) delete this.targetsList[key];\n }\n /**\n * 收集依赖\n * @param nodes 需要收集的节点\n * @param deep 是否需要收集子节点\n * @param type 强制收集指定类型的依赖\n */\n collect(nodes, depExtendedData = {}, deep = false, type) {\n this.collectByCallback(nodes, type, ({ node, target }) => {\n this.removeTargetDep(target, node);\n this.collectItem(node, target, depExtendedData, deep);\n });\n }\n collectByCallback(nodes, type, cb) {\n traverseTarget(this.targetsList, (target) => {\n if (!type && !target.isCollectByDefault) return;\n for (const node of nodes) cb({\n node,\n target\n });\n }, type);\n }\n /**\n * 清除所有目标的依赖\n * @param nodes 需要清除依赖的节点\n */\n clear(nodes, type) {\n let { targetsList } = this;\n if (type) targetsList = { [type]: this.getTargets(type) };\n const clearedItemsNodeIds = /* @__PURE__ */ new Set();\n traverseTarget(targetsList, (target) => {\n if (nodes) for (const node of nodes) {\n target.removeDep(node[this.idProp]);\n if (Array.isArray(node[this.childrenProp]) && node[this.childrenProp].length && !clearedItemsNodeIds.has(node[this.idProp])) {\n clearedItemsNodeIds.add(node[this.idProp]);\n this.clear(node[this.childrenProp]);\n }\n }\n else target.removeDep();\n });\n }\n /**\n * 清除指定类型的依赖\n * @param type 类型\n * @param nodes 需要清除依赖的节点\n */\n clearByType(type, nodes) {\n this.clear(nodes, type);\n }\n collectItem(node, target, depExtendedData = {}, deep = false) {\n if (node[\"_tmagic_node_disabled_data_source\"] && DATA_SOURCE_TARGET_TYPES.has(target.type)) return;\n if (node[\"_tmagic_node_disabled_code_block\"] && target.type === DepTargetType.CODE_BLOCK) return;\n const collectTarget = (config, prop = \"\") => {\n const doCollect = (key, value) => {\n const keyIsItems = key === this.childrenProp;\n const fullKey = prop ? `${prop}.${key}` : key;\n if (target.isTarget(fullKey, value)) target.updateDep({\n id: node[this.idProp],\n name: `${node[this.nameProp] || node[this.idProp]}`,\n data: depExtendedData,\n key: fullKey\n });\n else if (!keyIsItems && Array.isArray(value)) for (let i = 0, l = value.length; i < l; i++) {\n const item = value[i];\n if (isObject(item)) collectTarget(item, `${fullKey}[${i}]`);\n }\n else if (isObject(value)) collectTarget(value, fullKey);\n if (keyIsItems && deep && Array.isArray(value)) for (const child of value) this.collectItem(child, target, depExtendedData, deep);\n };\n for (const [key, value] of Object.entries(config)) {\n if (typeof value === \"undefined\" || value === \"\") continue;\n doCollect(key, value);\n }\n };\n collectTarget(node);\n }\n removeTargetDep(target, node, key) {\n target.removeDep(node[this.idProp], key);\n if (typeof key === \"undefined\" && Array.isArray(node[this.childrenProp]) && node[this.childrenProp].length) for (const item of node[this.childrenProp]) this.removeTargetDep(target, item, key);\n }\n };\n //#endregion\n //#region packages/editor/src/utils/logger.ts\n const error = (...args) => {\n if (process.env.NODE_ENV === \"development\") console.error(\"magic editor: \", ...args);\n };\n //#endregion\n //#region packages/editor/src/utils/dep/worker.ts\n onmessage = (e) => {\n const watcher = new Watcher({ initialTargets: {} });\n const { dsl } = e.data;\n try {\n const mApp = eval(`(${dsl})`);\n if (!mApp) postMessage({});\n watcher.clearTargets();\n if (mApp.codeBlocks) for (const [id, code] of Object.entries(mApp.codeBlocks)) watcher.addTarget(createCodeBlockTarget(id, code));\n if (mApp.dataSources) for (const ds of mApp.dataSources) {\n watcher.addTarget(createDataSourceTarget(ds, {}));\n watcher.addTarget(createDataSourceMethodTarget(ds, {}));\n watcher.addTarget(createDataSourceCondTarget(ds, {}));\n }\n watcher.collectByCallback(mApp.items, void 0, ({ node, target }) => {\n watcher.collectItem(node, target, { pageId: node.id }, true);\n });\n const data = {\n [DepTargetType.DATA_SOURCE]: {},\n [DepTargetType.DATA_SOURCE_METHOD]: {},\n [DepTargetType.DATA_SOURCE_COND]: {},\n [DepTargetType.CODE_BLOCK]: {}\n };\n traverseTarget(watcher.getTargetsList(), (target) => {\n data[target.type][target.id] = target.deps;\n });\n postMessage(data);\n } catch (e) {\n error(e);\n postMessage({});\n }\n };\n //#endregion\n})();\n";
|
|
3
3
|
var blob = typeof self !== "undefined" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", jsContent], { type: "text/javascript;charset=utf-8" });
|
|
4
4
|
function WorkerWrapper(options) {
|
|
5
5
|
let objURL;
|
package/dist/es/utils/tree.js
CHANGED
|
@@ -7,5 +7,7 @@ var updateStatus = (nodeStatusMap, id, status) => {
|
|
|
7
7
|
if (nodeStatus[key] !== void 0 && status[key] !== void 0) nodeStatus[key] = Boolean(status[key]);
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
/** 默认的组件树节点是否可展开的判断函数:当节点的子项中至少存在一个可见节点时认为可展开 */
|
|
11
|
+
var defaultIsExpandable = (data, nodeStatusMap) => Array.isArray(data.items) && data.items.some((item) => nodeStatusMap.get(item.id)?.visible);
|
|
10
12
|
//#endregion
|
|
11
|
-
export { updateStatus };
|
|
13
|
+
export { defaultIsExpandable, updateStatus };
|
package/dist/style.css
CHANGED
|
@@ -1325,6 +1325,26 @@ fieldset.m-fieldset .m-form-tip {
|
|
|
1325
1325
|
left: 5px;
|
|
1326
1326
|
top: 5px;
|
|
1327
1327
|
z-index: 10;
|
|
1328
|
+
display: flex;
|
|
1329
|
+
align-items: center;
|
|
1330
|
+
white-space: nowrap;
|
|
1331
|
+
}
|
|
1332
|
+
.m-editor-breadcrumb .m-editor-breadcrumb-item {
|
|
1333
|
+
max-width: 100px;
|
|
1334
|
+
min-width: 0;
|
|
1335
|
+
overflow: hidden;
|
|
1336
|
+
}
|
|
1337
|
+
.m-editor-breadcrumb .m-editor-breadcrumb-item > span {
|
|
1338
|
+
display: block;
|
|
1339
|
+
max-width: 100%;
|
|
1340
|
+
overflow: hidden;
|
|
1341
|
+
text-overflow: ellipsis;
|
|
1342
|
+
white-space: nowrap;
|
|
1343
|
+
}
|
|
1344
|
+
.m-editor-breadcrumb .m-editor-breadcrumb-separator,
|
|
1345
|
+
.m-editor-breadcrumb .m-editor-breadcrumb-ellipsis {
|
|
1346
|
+
margin: 0 4px;
|
|
1347
|
+
flex-shrink: 0;
|
|
1328
1348
|
}
|
|
1329
1349
|
|
|
1330
1350
|
.data-source-list-panel .list-container .list-item .codeIcon {
|