@tmagic/editor 1.2.0-beta.9 → 1.2.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.
Files changed (103) hide show
  1. package/dist/style.css +62 -34
  2. package/dist/{tmagic-editor.mjs → tmagic-editor.js} +1641 -1266
  3. package/dist/tmagic-editor.js.map +1 -0
  4. package/dist/{tmagic-editor.umd.js → tmagic-editor.umd.cjs} +1649 -1270
  5. package/dist/tmagic-editor.umd.cjs.map +1 -0
  6. package/package.json +16 -14
  7. package/src/Editor.vue +66 -40
  8. package/src/components/CodeDraftEditor.vue +137 -0
  9. package/src/components/ContentMenu.vue +1 -1
  10. package/src/components/FunctionEditor.vue +190 -0
  11. package/src/components/Icon.vue +1 -1
  12. package/src/{layouts → components}/Layout.vue +54 -15
  13. package/src/components/ScrollBar.vue +1 -1
  14. package/src/components/ScrollViewer.vue +10 -1
  15. package/src/components/ToolButton.vue +1 -1
  16. package/src/fields/Code.vue +1 -1
  17. package/src/fields/CodeLink.vue +1 -1
  18. package/src/fields/CodeSelect.vue +102 -99
  19. package/src/fields/UISelect.vue +3 -3
  20. package/src/index.ts +2 -1
  21. package/src/layouts/AddPageBox.vue +5 -2
  22. package/src/layouts/CodeEditor.vue +2 -3
  23. package/src/layouts/Framework.vue +12 -10
  24. package/src/layouts/NavMenu.vue +11 -8
  25. package/src/layouts/PropsPanel.vue +12 -9
  26. package/src/layouts/Resizer.vue +1 -1
  27. package/src/layouts/sidebar/ComponentListPanel.vue +2 -3
  28. package/src/layouts/sidebar/LayerMenu.vue +9 -7
  29. package/src/layouts/sidebar/LayerPanel.vue +130 -178
  30. package/src/layouts/sidebar/Sidebar.vue +110 -26
  31. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +33 -118
  32. package/src/layouts/sidebar/code-block/CodeBlockList.vue +93 -126
  33. package/src/layouts/workspace/Breadcrumb.vue +6 -7
  34. package/src/layouts/workspace/PageBar.vue +3 -3
  35. package/src/layouts/workspace/PageBarScrollContainer.vue +5 -3
  36. package/src/layouts/workspace/Stage.vue +36 -18
  37. package/src/layouts/workspace/ViewerMenu.vue +16 -15
  38. package/src/layouts/workspace/Workspace.vue +9 -6
  39. package/src/services/BaseService.ts +11 -2
  40. package/src/services/codeBlock.ts +136 -146
  41. package/src/services/componentList.ts +7 -2
  42. package/src/services/editor.ts +161 -85
  43. package/src/services/events.ts +7 -2
  44. package/src/services/history.ts +8 -17
  45. package/src/services/props.ts +8 -3
  46. package/src/services/storage.ts +1 -0
  47. package/src/services/ui.ts +20 -10
  48. package/src/theme/code-block.scss +46 -23
  49. package/src/theme/component-list-panel.scss +8 -5
  50. package/src/type.ts +84 -63
  51. package/src/utils/config.ts +1 -1
  52. package/src/utils/editor.ts +17 -3
  53. package/src/utils/index.ts +2 -1
  54. package/src/utils/logger.ts +1 -1
  55. package/src/utils/operator.ts +12 -12
  56. package/src/utils/props.ts +3 -3
  57. package/src/utils/scroll-viewer.ts +18 -2
  58. package/src/utils/stage.ts +10 -9
  59. package/src/utils/undo-redo.ts +1 -1
  60. package/types/Editor.vue.d.ts +48 -28
  61. package/types/components/CodeDraftEditor.vue.d.ts +55 -0
  62. package/types/components/ContentMenu.vue.d.ts +11 -87
  63. package/types/components/FunctionEditor.vue.d.ts +60 -0
  64. package/types/components/Icon.vue.d.ts +4 -50
  65. package/types/{layouts → components}/Layout.vue.d.ts +12 -1
  66. package/types/components/ScrollBar.vue.d.ts +7 -65
  67. package/types/components/ScrollViewer.vue.d.ts +45 -1
  68. package/types/components/ToolButton.vue.d.ts +12 -78
  69. package/types/fields/Code.vue.d.ts +11 -77
  70. package/types/fields/CodeLink.vue.d.ts +12 -82
  71. package/types/fields/CodeSelect.vue.d.ts +13 -77
  72. package/types/fields/UISelect.vue.d.ts +7 -65
  73. package/types/index.d.ts +1 -0
  74. package/types/layouts/AddPageBox.vue.d.ts +1 -43
  75. package/types/layouts/CodeEditor.vue.d.ts +22 -130
  76. package/types/layouts/NavMenu.vue.d.ts +9 -69
  77. package/types/layouts/sidebar/LayerMenu.vue.d.ts +16 -48
  78. package/types/layouts/sidebar/LayerPanel.vue.d.ts +24 -7
  79. package/types/layouts/sidebar/Sidebar.vue.d.ts +10 -5
  80. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +24 -6
  81. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +11 -5
  82. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -43
  83. package/types/layouts/workspace/Stage.vue.d.ts +15 -43
  84. package/types/layouts/workspace/ViewerMenu.vue.d.ts +11 -66
  85. package/types/layouts/workspace/Workspace.vue.d.ts +25 -8
  86. package/types/services/BaseService.d.ts +2 -1
  87. package/types/services/codeBlock.d.ts +56 -47
  88. package/types/services/componentList.d.ts +1 -0
  89. package/types/services/editor.d.ts +10 -11
  90. package/types/services/events.d.ts +1 -0
  91. package/types/services/history.d.ts +5 -15
  92. package/types/services/props.d.ts +3 -2
  93. package/types/services/ui.d.ts +24 -24
  94. package/types/type.d.ts +70 -59
  95. package/types/utils/editor.d.ts +1 -0
  96. package/types/utils/index.d.ts +1 -0
  97. package/types/utils/operator.d.ts +1 -1
  98. package/types/utils/props.d.ts +1 -1
  99. package/types/utils/scroll-viewer.d.ts +5 -0
  100. package/dist/tmagic-editor.mjs.map +0 -1
  101. package/dist/tmagic-editor.umd.js.map +0 -1
  102. package/src/layouts/sidebar/TabPane.vue +0 -118
  103. package/types/layouts/sidebar/TabPane.vue.d.ts +0 -82
@@ -1,19 +1,23 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, inject, ref, watchEffect, createElementBlock, createVNode, withCtx, createElementVNode, withModifiers, createCommentVNode, createTextVNode, toDisplayString, onMounted, onUnmounted, normalizeClass, resolveDynamicComponent, toRaw, renderSlot, Fragment, createSlots, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, isRef, withDirectives, Teleport, vShow, nextTick, toHandlers, provide } from 'vue';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, withCtx, createVNode, createElementVNode, createElementBlock, normalizeClass, resolveDynamicComponent, toRaw, inject, createCommentVNode, ref, withModifiers, createTextVNode, toDisplayString, onMounted, onUnmounted, renderSlot, Fragment, createSlots, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, watchEffect, provide, withDirectives, Teleport, vShow, nextTick, toHandlers } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
- import { map, xor, throttle, pick, cloneDeep, isEmpty, forIn, omit, keys, mergeWith, uniq } from 'lodash-es';
4
- import { TMagicCard, TMagicTooltip, tMagicMessage, TMagicButton, TMagicIcon, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, TMagicDialog, TMagicInput, TMagicTree, TMagicCollapse, TMagicCollapseItem, TMagicTabPane, TMagicTabs, TMagicPopover } from '@tmagic/design';
5
- import { Delete, Close, Edit, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, View, Link, Search, Files, DocumentCopy, EditPen, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
3
+ import { Edit, View, Delete, Close, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Link, Search, Files, CopyDocument, Coin, EditPen, ArrowLeftBold, ArrowRightBold, CaretBottom, DocumentCopy, Top, Bottom } from '@element-plus/icons-vue';
4
+ import { isEmpty, map, throttle, pick, omit, keys, cloneDeep, forIn, mergeWith, isObject, uniq, difference, union } from 'lodash-es';
5
+ import { createValues, MForm } from '@tmagic/form';
6
+ import { HookType, NodeType } from '@tmagic/schema';
7
+ import { TMagicIcon, TMagicButton, TMagicTooltip, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, tMagicMessage, tMagicMessageBox, TMagicCard, TMagicInput, TMagicDialog, TMagicTree, TMagicCollapse, TMagicCollapseItem, getConfig as getConfig$1, TMagicTabs, TMagicPopover } from '@tmagic/design';
6
8
  import * as monaco from 'monaco-editor';
7
- import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType } from '@tmagic/stage';
8
- import { NodeType } from '@tmagic/schema';
9
- import { isPop, getNodePath, isNumber, isPage, toLine, removeClassNameByClassName } from '@tmagic/utils';
9
+ import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType } from '@tmagic/stage';
10
+ import Gesto from 'gesto';
11
+ import { isPop, getNodePath, isNumber, isPage, toLine, datetimeFormatter, removeClassNameByClassName } from '@tmagic/utils';
10
12
  import { EventEmitter } from 'events';
11
13
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
12
- import Gesto from 'gesto';
13
14
  import KeyController from 'keycon';
14
15
 
15
- const _sfc_main$t = /* @__PURE__ */ defineComponent({
16
- __name: "Code",
16
+ const __default__$t = defineComponent({
17
+ name: "MEditorCode"
18
+ });
19
+ const _sfc_main$u = /* @__PURE__ */ defineComponent({
20
+ ...__default__$t,
17
21
  props: {
18
22
  model: null,
19
23
  name: null,
@@ -42,8 +46,11 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
42
46
  }
43
47
  });
44
48
 
45
- const _sfc_main$s = /* @__PURE__ */ defineComponent({
46
- __name: "CodeLink",
49
+ const __default__$s = defineComponent({
50
+ name: "MEditorCodeLink"
51
+ });
52
+ const _sfc_main$t = /* @__PURE__ */ defineComponent({
53
+ ...__default__$s,
47
54
  props: {
48
55
  config: null,
49
56
  model: null,
@@ -112,57 +119,55 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
112
119
  }
113
120
  });
114
121
 
115
- var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
116
- ColumnLayout2["LEFT"] = "left";
117
- ColumnLayout2["CENTER"] = "center";
118
- ColumnLayout2["RIGHT"] = "right";
119
- return ColumnLayout2;
120
- })(ColumnLayout || {});
121
- var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
122
- LayerOffset2["TOP"] = "top";
123
- LayerOffset2["BOTTOM"] = "bottom";
124
- return LayerOffset2;
125
- })(LayerOffset || {});
126
- var Layout = /* @__PURE__ */ ((Layout2) => {
127
- Layout2["FLEX"] = "flex";
128
- Layout2["FIXED"] = "fixed";
129
- Layout2["RELATIVE"] = "relative";
130
- Layout2["ABSOLUTE"] = "absolute";
131
- return Layout2;
132
- })(Layout || {});
133
- var Keys = /* @__PURE__ */ ((Keys2) => {
134
- Keys2["ESCAPE"] = "Space";
135
- return Keys2;
136
- })(Keys || {});
137
- const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
138
- const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
139
- var CodeEditorMode = /* @__PURE__ */ ((CodeEditorMode2) => {
140
- CodeEditorMode2["LIST"] = "list";
141
- CodeEditorMode2["EDITOR"] = "editor";
142
- return CodeEditorMode2;
143
- })(CodeEditorMode || {});
144
- var CodeDeleteErrorType = /* @__PURE__ */ ((CodeDeleteErrorType2) => {
145
- CodeDeleteErrorType2["UNDELETEABLE"] = "undeleteable";
146
- CodeDeleteErrorType2["BIND"] = "bind";
147
- return CodeDeleteErrorType2;
148
- })(CodeDeleteErrorType || {});
149
- var CodeSelectOp = /* @__PURE__ */ ((CodeSelectOp2) => {
150
- CodeSelectOp2["ADD"] = "add";
151
- CodeSelectOp2["DELETE"] = "delete";
152
- CodeSelectOp2["CHANGE"] = "change";
153
- return CodeSelectOp2;
154
- })(CodeSelectOp || {});
122
+ const _hoisted_1$g = ["src"];
123
+ const __default__$r = defineComponent({
124
+ name: "MEditorIcon"
125
+ });
126
+ const _sfc_main$s = /* @__PURE__ */ defineComponent({
127
+ ...__default__$r,
128
+ props: {
129
+ icon: null
130
+ },
131
+ setup(__props) {
132
+ return (_ctx, _cache) => {
133
+ return !__props.icon ? (openBlock(), createBlock(unref(TMagicIcon), {
134
+ key: 0,
135
+ class: "magic-editor-icon"
136
+ }, {
137
+ default: withCtx(() => [
138
+ createVNode(unref(Edit))
139
+ ]),
140
+ _: 1
141
+ })) : typeof __props.icon === "string" && __props.icon.startsWith("http") ? (openBlock(), createBlock(unref(TMagicIcon), {
142
+ key: 1,
143
+ class: "magic-editor-icon"
144
+ }, {
145
+ default: withCtx(() => [
146
+ createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$g)
147
+ ]),
148
+ _: 1
149
+ })) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
150
+ key: 2,
151
+ class: normalizeClass(["magic-editor-icon", __props.icon])
152
+ }, null, 2)) : (openBlock(), createBlock(unref(TMagicIcon), {
153
+ key: 3,
154
+ class: "magic-editor-icon"
155
+ }, {
156
+ default: withCtx(() => [
157
+ (openBlock(), createBlock(resolveDynamicComponent(toRaw(__props.icon))))
158
+ ]),
159
+ _: 1
160
+ }));
161
+ };
162
+ }
163
+ });
155
164
 
156
- const _hoisted_1$e = { class: "tool-bar" };
157
- const _hoisted_2$6 = /* @__PURE__ */ createElementVNode("path", {
158
- fill: "currentColor",
159
- d: "m23 12l-7.071 7.071l-1.414-1.414L20.172 12l-5.657-5.657l1.414-1.414L23 12zM3.828 12l5.657 5.657l-1.414 1.414L1 12l7.071-7.071l1.414 1.414L3.828 12z"
160
- }, null, -1);
161
- const _hoisted_3$3 = [
162
- _hoisted_2$6
163
- ];
165
+ const _hoisted_1$f = { class: "m-fields-code-select" };
166
+ const __default__$q = defineComponent({
167
+ name: "MEditorCodeSelect"
168
+ });
164
169
  const _sfc_main$r = /* @__PURE__ */ defineComponent({
165
- __name: "CodeSelect",
170
+ ...__default__$q,
166
171
  props: {
167
172
  config: null,
168
173
  model: null,
@@ -174,119 +179,119 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
174
179
  setup(__props, { emit }) {
175
180
  const props = __props;
176
181
  const services = inject("services");
177
- const form = inject("mForm");
178
- const selectConfig = computed(() => {
182
+ const mForm = inject("mForm");
183
+ const codeDsl = computed(() => services?.codeBlockService.getCodeDslSync());
184
+ const tableConfig = computed(() => {
179
185
  const defaultConfig = {
180
- multiple: true,
181
- options: async () => {
182
- const codeDsl = await services?.codeBlockService.getCodeDsl();
183
- if (codeDsl) {
184
- return map(codeDsl, (value, key) => ({
185
- text: `${value.name}\uFF08${key}\uFF09`,
186
- label: `${value.name}\uFF08${key}\uFF09`,
187
- value: key
188
- }));
186
+ dropSort: false,
187
+ enableFullscreen: false,
188
+ border: true,
189
+ operateColWidth: 60,
190
+ items: [
191
+ {
192
+ type: "select",
193
+ label: "\u4EE3\u7801\u5757",
194
+ name: "codeId",
195
+ width: "200px",
196
+ options: () => {
197
+ if (codeDsl.value) {
198
+ return map(codeDsl.value, (value, key) => ({
199
+ text: `${value.name}\uFF08${key}\uFF09`,
200
+ label: `${value.name}\uFF08${key}\uFF09`,
201
+ value: key
202
+ }));
203
+ }
204
+ return [];
205
+ },
206
+ onChange: (formState, codeId, { model }) => {
207
+ model.params = {};
208
+ }
209
+ },
210
+ {
211
+ name: "params",
212
+ label: "\u53C2\u6570",
213
+ defaultValue: {},
214
+ itemsFunction: (row) => {
215
+ const paramsConfig = getParamsConfig(row.codeId);
216
+ if (isEmpty(row.params) || !row.params) {
217
+ createValues(mForm, paramsConfig, {}, row.params);
218
+ }
219
+ return paramsConfig;
220
+ }
189
221
  }
190
- return [];
191
- }
222
+ ]
192
223
  };
193
224
  return {
194
225
  ...defaultConfig,
195
- ...props.config.selectConfig
226
+ ...props.config.tableConfig
196
227
  };
197
228
  });
198
- const fieldKey = ref("");
199
- const multiple = ref(true);
200
- const lastTagSnapshot = ref([]);
201
- watchEffect(async () => {
202
- if (!props.model[props.name])
203
- return;
204
- const combineNames = await Promise.all(
205
- props.model[props.name].map(async (id) => {
206
- const { name = "" } = await services?.codeBlockService.getCodeContentById(id) || {};
207
- return name;
208
- })
209
- );
210
- fieldKey.value = combineNames.join("-");
211
- });
212
- const changeHandler = async (value) => {
213
- let codeIds = value;
214
- if (typeof value === "string") {
215
- multiple.value = false;
216
- codeIds = value ? [value] : [];
217
- }
218
- await setCombineRelation(codeIds);
219
- emit("change", value);
220
- };
221
- const setCombineRelation = async (codeIds) => {
222
- const { id = "" } = services?.editorService.get("node") || {};
223
- let opFlag = CodeSelectOp.CHANGE;
224
- let diffValues = codeIds;
225
- if (multiple.value) {
226
- lastTagSnapshot.value = form?.initValues[props.name] || [];
227
- opFlag = codeIds.length < lastTagSnapshot.value.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
228
- diffValues = xor(codeIds, lastTagSnapshot.value);
229
+ const editable = computed(() => services?.codeBlockService.getEditStatus());
230
+ watch(
231
+ () => props.model[props.name],
232
+ (value) => {
233
+ if (isEmpty(value)) {
234
+ props.model[props.name] = {
235
+ hookType: HookType.CODE,
236
+ hookData: []
237
+ };
238
+ }
239
+ },
240
+ {
241
+ immediate: true
229
242
  }
230
- await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
243
+ );
244
+ const changeHandler = async () => {
245
+ emit("change", props.model[props.name]);
231
246
  };
232
- const viewHandler = async () => {
233
- if (props.model[props.name].length === 0) {
234
- tMagicMessage.error("\u8BF7\u5148\u7ED1\u5B9A\u4EE3\u7801\u5757");
235
- return;
236
- }
237
- await services?.codeBlockService.setCombineIds(props.model[props.name]);
238
- await services?.codeBlockService.setMode(CodeEditorMode.LIST);
239
- services?.codeBlockService.setCodeEditorContent(true, props.model[props.name][0]);
247
+ const getParamsConfig = (codeId) => {
248
+ if (!codeDsl.value)
249
+ return [];
250
+ const paramStatements = codeDsl.value[codeId]?.params;
251
+ if (isEmpty(paramStatements))
252
+ return [];
253
+ return paramStatements.map((paramState) => ({
254
+ labelWidth: "100px",
255
+ text: paramState.name,
256
+ ...paramState
257
+ }));
258
+ };
259
+ const editCode = (codeId) => {
260
+ services?.codeBlockService.setCodeEditorContent(true, codeId);
240
261
  };
241
262
  return (_ctx, _cache) => {
242
- const _component_m_fields_select = resolveComponent("m-fields-select");
243
- return openBlock(), createElementBlock("div", {
244
- class: "m-fields-code-select",
245
- key: fieldKey.value
246
- }, [
247
- createVNode(unref(TMagicCard), { shadow: "never" }, {
248
- header: withCtx(() => [
249
- createVNode(_component_m_fields_select, {
250
- config: unref(selectConfig),
251
- model: __props.model,
252
- prop: __props.prop,
253
- name: __props.name,
254
- size: __props.size,
255
- onChange: changeHandler
256
- }, null, 8, ["config", "model", "prop", "name", "size"])
257
- ]),
258
- default: withCtx(() => [
259
- createElementVNode("div", _hoisted_1$e, [
260
- createVNode(unref(TMagicTooltip), {
261
- class: "tool-item",
262
- effect: "dark",
263
- content: "\u67E5\u770B\u4EE3\u7801\u5757",
264
- placement: "top"
265
- }, {
266
- default: withCtx(() => [
267
- (openBlock(), createElementBlock("svg", {
268
- onClick: viewHandler,
269
- preserveAspectRatio: "xMidYMid meet",
270
- viewBox: "0 0 24 24",
271
- width: "15px",
272
- height: "15px",
273
- "data-v-65a7fb6c": ""
274
- }, _hoisted_3$3))
275
- ]),
276
- _: 1
277
- })
278
- ])
263
+ const _component_m_form_table = resolveComponent("m-form-table");
264
+ return openBlock(), createElementBlock("div", _hoisted_1$f, [
265
+ createVNode(_component_m_form_table, {
266
+ config: unref(tableConfig),
267
+ model: __props.model[__props.name],
268
+ name: "hookData",
269
+ enableToggleMode: false,
270
+ prop: __props.prop,
271
+ size: __props.size,
272
+ onChange: changeHandler
273
+ }, {
274
+ operateCol: withCtx(({ scope }) => [
275
+ scope.row.codeId ? (openBlock(), createBlock(_sfc_main$s, {
276
+ key: 0,
277
+ icon: unref(editable) ? unref(Edit) : unref(View),
278
+ class: "edit-icon",
279
+ onClick: ($event) => editCode(scope.row.codeId)
280
+ }, null, 8, ["icon", "onClick"])) : createCommentVNode("", true)
279
281
  ]),
280
282
  _: 1
281
- })
283
+ }, 8, ["config", "model", "prop", "size"])
282
284
  ]);
283
285
  };
284
286
  }
285
287
  });
286
288
 
287
- const _hoisted_1$d = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
289
+ const _hoisted_1$e = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
290
+ const __default__$p = defineComponent({
291
+ name: "MEditorUISelect"
292
+ });
288
293
  const _sfc_main$q = /* @__PURE__ */ defineComponent({
289
- __name: "UISelect",
294
+ ...__default__$p,
290
295
  props: {
291
296
  config: null,
292
297
  model: null,
@@ -348,7 +353,7 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
348
353
  style: { "padding": "0" }
349
354
  }, {
350
355
  default: withCtx(() => [
351
- _hoisted_1$d
356
+ _hoisted_1$e
352
357
  ]),
353
358
  _: 1
354
359
  }, 8, ["icon"])
@@ -396,12 +401,15 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
396
401
 
397
402
  const UISelect_vue_vue_type_style_index_0_lang = '';
398
403
 
404
+ const __default__$o = defineComponent({
405
+ name: "MEditorCodeEditor"
406
+ });
399
407
  const _sfc_main$p = /* @__PURE__ */ defineComponent({
400
- __name: "CodeEditor",
408
+ ...__default__$o,
401
409
  props: {
402
410
  initValues: null,
403
411
  modifiedValues: null,
404
- type: { default: "" },
412
+ type: null,
405
413
  language: { default: "javascript" },
406
414
  options: { default: () => ({
407
415
  tabSize: 2
@@ -526,46 +534,207 @@ const setConfig = (option) => {
526
534
  };
527
535
  const getConfig = (key) => $TMAGIC_EDITOR[key];
528
536
 
529
- const _hoisted_1$c = ["src"];
537
+ const __default__$n = defineComponent({
538
+ name: "MEditorResizer"
539
+ });
530
540
  const _sfc_main$o = /* @__PURE__ */ defineComponent({
531
- __name: "Icon",
541
+ ...__default__$n,
542
+ emits: ["change"],
543
+ setup(__props, { emit }) {
544
+ const target = ref();
545
+ let getso;
546
+ onMounted(() => {
547
+ if (!target.value)
548
+ return;
549
+ getso = new Gesto(target.value, {
550
+ container: window,
551
+ pinchOutside: true
552
+ }).on("drag", (e) => {
553
+ if (!target.value)
554
+ return;
555
+ emit("change", e.deltaX);
556
+ });
557
+ });
558
+ onUnmounted(() => {
559
+ getso?.unset();
560
+ });
561
+ return (_ctx, _cache) => {
562
+ return openBlock(), createElementBlock("span", {
563
+ ref_key: "target",
564
+ ref: target,
565
+ class: "m-editor-resizer"
566
+ }, [
567
+ renderSlot(_ctx.$slots, "default")
568
+ ], 512);
569
+ };
570
+ }
571
+ });
572
+
573
+ const __default__$m = defineComponent({
574
+ name: "MEditorLayout"
575
+ });
576
+ const _sfc_main$n = /* @__PURE__ */ defineComponent({
577
+ ...__default__$m,
532
578
  props: {
533
- icon: null
579
+ left: null,
580
+ right: null,
581
+ minLeft: { default: 46 },
582
+ minRight: { default: 1 },
583
+ minCenter: { default: 5 },
584
+ leftClass: null,
585
+ rightClass: null,
586
+ centerClass: null
534
587
  },
535
- setup(__props) {
588
+ emits: ["update:left", "change", "update:right"],
589
+ setup(__props, { emit }) {
590
+ const props = __props;
591
+ const el = ref();
592
+ const hasLeft = computed(() => typeof props.left !== "undefined");
593
+ const hasRight = computed(() => typeof props.right !== "undefined");
594
+ const getCenterWidth = (clientWidth2, left, right) => {
595
+ let center2 = clientWidth2 - left - right;
596
+ if (center2 < props.minCenter) {
597
+ center2 = props.minCenter;
598
+ if (left < right) {
599
+ right = clientWidth2 - left - props.minCenter;
600
+ } else {
601
+ left = clientWidth2 - right - props.minCenter;
602
+ }
603
+ }
604
+ return {
605
+ center: center2,
606
+ left,
607
+ right
608
+ };
609
+ };
610
+ let clientWidth = 0;
611
+ const resizerObserver = new ResizeObserver((entries) => {
612
+ for (const { contentRect } of entries) {
613
+ clientWidth = contentRect.width;
614
+ let left = props.left || 0;
615
+ let right = props.right || 0;
616
+ if (left > clientWidth) {
617
+ left = clientWidth / 3;
618
+ }
619
+ if (right > clientWidth) {
620
+ right = clientWidth / 3;
621
+ }
622
+ const columnWidth = getCenterWidth(clientWidth, left, right);
623
+ center.value = columnWidth.center;
624
+ emit("change", {
625
+ left: columnWidth.left,
626
+ center: center.value,
627
+ right: columnWidth.right
628
+ });
629
+ }
630
+ });
631
+ onMounted(() => {
632
+ if (el.value) {
633
+ resizerObserver.observe(el.value);
634
+ }
635
+ });
636
+ onUnmounted(() => {
637
+ resizerObserver.disconnect();
638
+ });
639
+ const center = ref(0);
640
+ const changeLeft = (deltaX) => {
641
+ if (typeof props.left === "undefined")
642
+ return;
643
+ let left = Math.max(props.left + deltaX, props.minLeft) || 0;
644
+ emit("update:left", left);
645
+ if (clientWidth - left - (props.right || 0) <= 0) {
646
+ left = props.left;
647
+ }
648
+ const columnWidth = getCenterWidth(clientWidth, left, props.right || 0);
649
+ center.value = columnWidth.center;
650
+ emit("change", {
651
+ left: columnWidth.left,
652
+ center: center.value,
653
+ right: columnWidth.right
654
+ });
655
+ };
656
+ const changeRight = (deltaX) => {
657
+ if (typeof props.right === "undefined")
658
+ return;
659
+ let right = Math.max(props.right - deltaX, props.minRight) || 0;
660
+ emit("update:right", right);
661
+ if (clientWidth - (props.left || 0) - right <= 0) {
662
+ right = props.right;
663
+ }
664
+ const columnWidth = getCenterWidth(clientWidth, props.left || 0, right);
665
+ center.value = columnWidth.center;
666
+ emit("change", {
667
+ left: columnWidth.left,
668
+ center: center.value,
669
+ right: columnWidth.right
670
+ });
671
+ };
536
672
  return (_ctx, _cache) => {
537
- return !__props.icon ? (openBlock(), createBlock(unref(TMagicIcon), {
538
- key: 0,
539
- class: "magic-editor-icon"
540
- }, {
541
- default: withCtx(() => [
542
- createVNode(unref(Edit))
543
- ]),
544
- _: 1
545
- })) : typeof __props.icon === "string" && __props.icon.startsWith("http") ? (openBlock(), createBlock(unref(TMagicIcon), {
546
- key: 1,
547
- class: "magic-editor-icon"
548
- }, {
549
- default: withCtx(() => [
550
- createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$c)
551
- ]),
552
- _: 1
553
- })) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
554
- key: 2,
555
- class: normalizeClass(["magic-editor-icon", __props.icon])
556
- }, null, 2)) : (openBlock(), createBlock(unref(TMagicIcon), {
557
- key: 3,
558
- class: "magic-editor-icon"
559
- }, {
560
- default: withCtx(() => [
561
- (openBlock(), createBlock(resolveDynamicComponent(toRaw(__props.icon))))
562
- ]),
563
- _: 1
564
- }));
673
+ return openBlock(), createElementBlock("div", {
674
+ ref_key: "el",
675
+ ref: el,
676
+ class: "m-editor-layout"
677
+ }, [
678
+ unref(hasLeft) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
679
+ createElementVNode("div", {
680
+ class: normalizeClass(["m-editor-layout-left", __props.leftClass]),
681
+ style: normalizeStyle(`width: ${__props.left}px`)
682
+ }, [
683
+ renderSlot(_ctx.$slots, "left")
684
+ ], 6),
685
+ createVNode(_sfc_main$o, { onChange: changeLeft })
686
+ ], 64)) : createCommentVNode("", true),
687
+ createElementVNode("div", {
688
+ class: normalizeClass(["m-editor-layout-center", __props.centerClass]),
689
+ style: normalizeStyle(`width: ${center.value}px`)
690
+ }, [
691
+ renderSlot(_ctx.$slots, "center")
692
+ ], 6),
693
+ unref(hasRight) ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
694
+ createVNode(_sfc_main$o, { onChange: changeRight }),
695
+ createElementVNode("div", {
696
+ class: normalizeClass(["m-editor-layout-right", __props.rightClass]),
697
+ style: normalizeStyle(`width: ${__props.right}px`)
698
+ }, [
699
+ renderSlot(_ctx.$slots, "right")
700
+ ], 6)
701
+ ], 64)) : createCommentVNode("", true)
702
+ ], 512);
565
703
  };
566
704
  }
567
705
  });
568
706
 
707
+ var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
708
+ ColumnLayout2["LEFT"] = "left";
709
+ ColumnLayout2["CENTER"] = "center";
710
+ ColumnLayout2["RIGHT"] = "right";
711
+ return ColumnLayout2;
712
+ })(ColumnLayout || {});
713
+ var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
714
+ LayerOffset2["TOP"] = "top";
715
+ LayerOffset2["BOTTOM"] = "bottom";
716
+ return LayerOffset2;
717
+ })(LayerOffset || {});
718
+ var Layout = /* @__PURE__ */ ((Layout2) => {
719
+ Layout2["FLEX"] = "flex";
720
+ Layout2["FIXED"] = "fixed";
721
+ Layout2["RELATIVE"] = "relative";
722
+ Layout2["ABSOLUTE"] = "absolute";
723
+ return Layout2;
724
+ })(Layout || {});
725
+ var Keys = /* @__PURE__ */ ((Keys2) => {
726
+ Keys2["ESCAPE"] = "Space";
727
+ return Keys2;
728
+ })(Keys || {});
729
+ const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
730
+ const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
731
+ var CodeDeleteErrorType = /* @__PURE__ */ ((CodeDeleteErrorType2) => {
732
+ CodeDeleteErrorType2["UNDELETEABLE"] = "undeleteable";
733
+ CodeDeleteErrorType2["BIND"] = "bind";
734
+ return CodeDeleteErrorType2;
735
+ })(CodeDeleteErrorType || {});
736
+ const CODE_DRAFT_STORAGE_KEY = "magicCodeDraft";
737
+
569
738
  const log = (...args) => {
570
739
  if (process.env.NODE_ENV === "development") {
571
740
  console.log("magic editor: ", ...args);
@@ -695,6 +864,14 @@ class BaseService extends EventEmitter {
695
864
  this.pluginOptionsList[methodName2].push(method);
696
865
  });
697
866
  }
867
+ removeAllPlugins() {
868
+ Object.keys(this.pluginOptionsList).forEach((key) => {
869
+ this.pluginOptionsList[key] = [];
870
+ });
871
+ Object.keys(this.middleware).forEach((key) => {
872
+ this.middleware[key] = [];
873
+ });
874
+ }
698
875
  async doTask() {
699
876
  this.doingTask = true;
700
877
  let task = this.taskList.shift();
@@ -712,9 +889,9 @@ class CodeBlock extends BaseService {
712
889
  codeDsl: null,
713
890
  id: "",
714
891
  editable: true,
715
- mode: CodeEditorMode.EDITOR,
716
892
  combineIds: [],
717
- undeletableList: []
893
+ undeletableList: [],
894
+ relations: {}
718
895
  });
719
896
  constructor() {
720
897
  super([
@@ -726,37 +903,45 @@ class CodeBlock extends BaseService {
726
903
  "setCodeDslById",
727
904
  "setCodeEditorShowStatus",
728
905
  "setEditStatus",
729
- "setMode",
730
906
  "setCombineIds",
731
907
  "setUndeleteableList",
732
908
  "deleteCodeDslByIds"
733
909
  ]);
734
910
  }
735
- async setCodeDsl(codeDsl) {
736
- this.state.codeDsl = codeDsl;
911
+ async setCodeDsl(codeDsl2) {
912
+ this.state.codeDsl = codeDsl2;
737
913
  await editorService.setCodeDsl(this.state.codeDsl);
738
914
  info("[code-block]:code-dsl-change", this.state.codeDsl);
739
915
  this.emit("code-dsl-change", this.state.codeDsl);
740
916
  }
741
917
  async getCodeDsl(forceRefresh = false) {
918
+ return this.getCodeDslSync(forceRefresh);
919
+ }
920
+ getCodeDslSync(forceRefresh = false) {
742
921
  if (!this.state.codeDsl || forceRefresh) {
743
- this.state.codeDsl = await editorService.getCodeDsl();
922
+ this.state.codeDsl = editorService.getCodeDslSync();
744
923
  }
745
924
  return this.state.codeDsl;
746
925
  }
747
- async getCodeContentById(id) {
748
- if (!id)
926
+ async getCodeContentById(id2) {
927
+ if (!id2)
749
928
  return null;
750
929
  const totalCodeDsl = await this.getCodeDsl();
751
930
  if (!totalCodeDsl)
752
931
  return null;
753
- return totalCodeDsl[id] ?? null;
932
+ return totalCodeDsl[id2] ?? null;
754
933
  }
755
934
  async setCodeDslById(id, codeConfig) {
756
935
  let codeDsl = await this.getCodeDsl();
936
+ const codeConfigProcessed = codeConfig;
937
+ if (codeConfig.content) {
938
+ codeConfigProcessed.content = eval(codeConfig.content);
939
+ }
757
940
  if (!codeDsl) {
758
941
  codeDsl = {
759
- [id]: codeConfig
942
+ [id]: {
943
+ ...codeConfigProcessed
944
+ }
760
945
  };
761
946
  } else {
762
947
  const existContent = codeDsl[id] || {};
@@ -764,15 +949,15 @@ class CodeBlock extends BaseService {
764
949
  ...codeDsl,
765
950
  [id]: {
766
951
  ...existContent,
767
- ...codeConfig
952
+ ...codeConfigProcessed
768
953
  }
769
954
  };
770
955
  }
771
956
  await this.setCodeDsl(codeDsl);
772
957
  }
773
958
  async getCodeDslByIds(ids) {
774
- const codeDsl = await this.getCodeDsl();
775
- return pick(codeDsl, ids);
959
+ const codeDsl2 = await this.getCodeDsl();
960
+ return pick(codeDsl2, ids);
776
961
  }
777
962
  async setCodeEditorShowStatus(status) {
778
963
  this.state.isShowCodeEditor = status;
@@ -780,10 +965,10 @@ class CodeBlock extends BaseService {
780
965
  getCodeEditorShowStatus() {
781
966
  return this.state.isShowCodeEditor;
782
967
  }
783
- setCodeEditorContent(status, id) {
784
- if (!id)
968
+ setCodeEditorContent(status, id2) {
969
+ if (!id2)
785
970
  return;
786
- this.setId(id);
971
+ this.setId(id2);
787
972
  this.state.isShowCodeEditor = status;
788
973
  }
789
974
  async getCurrentDsl() {
@@ -795,81 +980,31 @@ class CodeBlock extends BaseService {
795
980
  async setEditStatus(status) {
796
981
  this.state.editable = status;
797
982
  }
798
- setId(id) {
799
- if (!id)
983
+ setId(id2) {
984
+ if (!id2)
800
985
  return;
801
- this.state.id = id;
986
+ this.state.id = id2;
802
987
  }
803
988
  getId() {
804
989
  return this.state.id;
805
990
  }
806
- getMode() {
807
- return this.state.mode;
808
- }
809
- async setMode(mode) {
810
- this.state.mode = mode;
811
- }
812
991
  async setCombineIds(ids) {
813
992
  this.state.combineIds = ids;
814
993
  }
815
994
  getCombineIds() {
816
995
  return this.state.combineIds;
817
996
  }
818
- async setCombineRelation(compId, diffCodeIds, opFlag, hook) {
819
- const codeDsl = cloneDeep(await this.getCodeDsl());
820
- if (!codeDsl)
821
- return;
822
- if (opFlag === CodeSelectOp.DELETE) {
823
- try {
824
- diffCodeIds.forEach((codeId) => {
825
- const compsContent = codeDsl[codeId].comps;
826
- const index = compsContent?.[compId].findIndex((item) => item === hook);
827
- if (typeof index !== "undefined" && index !== -1) {
828
- compsContent?.[compId].splice(index, 1);
829
- }
830
- });
831
- } catch (e) {
832
- error(e);
833
- throw new Error("\u89E3\u7ED1\u4EE3\u7801\u5757\u5931\u8D25");
834
- }
835
- } else if (opFlag === CodeSelectOp.ADD) {
836
- try {
837
- diffCodeIds.forEach((codeId) => {
838
- const compsContent = codeDsl[codeId].comps;
839
- const existHooks = compsContent?.[compId];
840
- if (isEmpty(existHooks)) {
841
- codeDsl[codeId].comps = {
842
- ...codeDsl[codeId].comps || {},
843
- [compId]: [hook]
844
- };
845
- } else {
846
- existHooks?.push(hook);
847
- }
848
- });
849
- } catch (e) {
850
- error(e);
851
- throw new Error("\u7ED1\u5B9A\u4EE3\u7801\u5757\u5931\u8D25");
852
- }
853
- } else if (opFlag === CodeSelectOp.CHANGE) {
854
- forIn(codeDsl, (codeBlockContent, codeId) => {
855
- if (codeId === diffCodeIds[0]) {
856
- codeBlockContent.comps = {
857
- ...codeBlockContent?.comps || {},
858
- [compId]: [hook]
859
- };
860
- } else if (isEmpty(diffCodeIds) || codeId !== diffCodeIds[0]) {
861
- const compHooks = codeBlockContent?.comps?.[compId];
862
- if (!compHooks)
863
- return true;
864
- const index = compHooks.findIndex((hookName) => hookName === hook);
865
- if (index !== -1) {
866
- compHooks.splice(index, 1);
867
- return false;
868
- }
869
- }
870
- });
871
- }
872
- this.setCodeDsl(codeDsl);
997
+ refreshCombineInfo() {
998
+ const root = editorService.get("root");
999
+ if (!root)
1000
+ return null;
1001
+ const relations = {};
1002
+ this.recurseMNode(root, relations);
1003
+ this.state.relations = relations;
1004
+ return this.state.relations;
1005
+ }
1006
+ getCombineInfo() {
1007
+ return this.state.relations;
873
1008
  }
874
1009
  getUndeletableList() {
875
1010
  return this.state.undeletableList;
@@ -877,6 +1012,15 @@ class CodeBlock extends BaseService {
877
1012
  async setUndeleteableList(codeIds) {
878
1013
  this.state.undeletableList = codeIds;
879
1014
  }
1015
+ setCodeDraft(codeId, content) {
1016
+ globalThis.localStorage.setItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`, content);
1017
+ }
1018
+ getCodeDraft(codeId) {
1019
+ return globalThis.localStorage.getItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
1020
+ }
1021
+ removeCodeDraft(codeId) {
1022
+ globalThis.localStorage.removeItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
1023
+ }
880
1024
  async deleteCodeDslByIds(codeIds) {
881
1025
  const currentDsl = await this.getCodeDsl();
882
1026
  const newDsl = omit(currentDsl, codeIds);
@@ -892,31 +1036,67 @@ class CodeBlock extends BaseService {
892
1036
  return await this.getUniqueId();
893
1037
  }
894
1038
  async deleteCompsInRelation(node) {
895
- const codeDsl = cloneDeep(await this.getCodeDsl());
896
- if (!codeDsl)
1039
+ const codeDsl2 = cloneDeep(await this.getCodeDsl());
1040
+ if (!codeDsl2)
897
1041
  return;
898
- this.recurseNodes(node, codeDsl);
899
- this.setCodeDsl(codeDsl);
1042
+ this.refreshRelationDeep(node, codeDsl2);
1043
+ this.setCodeDsl(codeDsl2);
900
1044
  }
901
- destroy() {
1045
+ resetState() {
902
1046
  this.state.isShowCodeEditor = false;
903
1047
  this.state.codeDsl = null;
904
1048
  this.state.id = "";
905
1049
  this.state.editable = true;
906
- this.state.mode = CodeEditorMode.EDITOR;
907
1050
  this.state.combineIds = [];
908
1051
  this.state.undeletableList = [];
909
1052
  }
910
- recurseNodes(node, codeDsl) {
1053
+ destroy() {
1054
+ this.resetState();
1055
+ this.removeAllListeners();
1056
+ this.removeAllPlugins();
1057
+ }
1058
+ refreshRelationDeep(node, codeDsl2) {
911
1059
  if (!node.id)
912
1060
  return;
913
- forIn(codeDsl, (codeBlockContent) => {
1061
+ forIn(codeDsl2, (codeBlockContent) => {
914
1062
  const compsContent = codeBlockContent.comps || {};
915
1063
  codeBlockContent.comps = omit(compsContent, node.id);
916
1064
  });
917
1065
  if (!isEmpty(node.items)) {
918
1066
  node.items.forEach((item) => {
919
- this.recurseNodes(item, codeDsl);
1067
+ this.refreshRelationDeep(item, codeDsl2);
1068
+ });
1069
+ }
1070
+ }
1071
+ recurseMNode(node, relations) {
1072
+ forIn(node, (value, key) => {
1073
+ let unConfirmedValue = { id: node.id };
1074
+ if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
1075
+ value.hookData.forEach((relationItem) => {
1076
+ if (!relationItem.codeId)
1077
+ return;
1078
+ if (!relations[relationItem.codeId]) {
1079
+ relations[relationItem.codeId] = {};
1080
+ }
1081
+ const codeItem = relations[relationItem.codeId];
1082
+ if (isEmpty(codeItem[node.id])) {
1083
+ codeItem[node.id] = [];
1084
+ }
1085
+ codeItem[node.id].push(key);
1086
+ });
1087
+ return;
1088
+ }
1089
+ if (typeof value === "object") {
1090
+ unConfirmedValue = {
1091
+ ...unConfirmedValue,
1092
+ ...value
1093
+ };
1094
+ this.recurseMNode(unConfirmedValue, relations);
1095
+ }
1096
+ });
1097
+ if (!isEmpty(node.items)) {
1098
+ node.items.forEach((item) => {
1099
+ this.recurseMNode(item, relations);
920
1100
  });
921
1101
  }
922
1102
  }
@@ -1000,8 +1180,9 @@ class History extends BaseService {
1000
1180
  this.state.pageSteps[this.state.pageId] = undoRedo;
1001
1181
  }
1002
1182
  this.setCanUndoRedo();
1183
+ this.emit("page-change", this.state.pageSteps[this.state.pageId]);
1003
1184
  }
1004
- empty() {
1185
+ resetState() {
1005
1186
  this.state.pageId = void 0;
1006
1187
  this.state.pageSteps = {};
1007
1188
  this.state.canRedo = false;
@@ -1032,8 +1213,9 @@ class History extends BaseService {
1032
1213
  return state;
1033
1214
  }
1034
1215
  destroy() {
1035
- this.empty();
1216
+ this.resetState();
1036
1217
  this.removeAllListeners();
1218
+ this.removeAllPlugins();
1037
1219
  }
1038
1220
  getUndoRedo() {
1039
1221
  if (!this.state.pageId)
@@ -1113,6 +1295,7 @@ class WebStorage extends BaseService {
1113
1295
  }
1114
1296
  destroy() {
1115
1297
  this.removeAllListeners();
1298
+ this.removeAllPlugins();
1116
1299
  }
1117
1300
  getValueAndProtocol(value) {
1118
1301
  let protocol2 = "";
@@ -1181,10 +1364,14 @@ const getMiddleTop = (node, parentNode, stage) => {
1181
1364
  };
1182
1365
  const getInitPositionStyle = (style = {}, layout) => {
1183
1366
  if (layout === Layout.ABSOLUTE) {
1184
- return {
1367
+ const newStyle = {
1185
1368
  ...style,
1186
1369
  position: "absolute"
1187
1370
  };
1371
+ if (typeof newStyle.left === "undefined" && typeof newStyle.right === "undefined") {
1372
+ newStyle.left = 0;
1373
+ }
1374
+ return newStyle;
1188
1375
  }
1189
1376
  if (layout === Layout.RELATIVE) {
1190
1377
  return getRelativeStyle(style);
@@ -1285,6 +1472,10 @@ const fixNodePosition = (config, parent, stage) => {
1285
1472
  left: fixNodeLeft(config, parent, stage?.renderer.contentWindow?.document)
1286
1473
  };
1287
1474
  };
1475
+ const serializeConfig = (config) => serialize(config, {
1476
+ space: 2,
1477
+ unsafe: true
1478
+ }).replace(/"(\w+)":\s/g, "$1: ");
1288
1479
 
1289
1480
  class Props extends BaseService {
1290
1481
  state = reactive({
@@ -1326,7 +1517,7 @@ class Props extends BaseService {
1326
1517
  this.setPropsValue(toLine(type), values[type]);
1327
1518
  });
1328
1519
  }
1329
- setPropsValue(type, value) {
1520
+ async setPropsValue(type, value) {
1330
1521
  this.state.propsValueMap[type] = value;
1331
1522
  }
1332
1523
  async getPropsValue(type, { inputEvent, ...defaultValue } = {}) {
@@ -1380,10 +1571,14 @@ class Props extends BaseService {
1380
1571
  name: type
1381
1572
  };
1382
1573
  }
1383
- destroy() {
1574
+ resetState() {
1384
1575
  this.state.propsConfigMap = {};
1385
1576
  this.state.propsValueMap = {};
1577
+ }
1578
+ destroy() {
1579
+ this.resetState();
1386
1580
  this.removeAllListeners();
1581
+ this.removeAllPlugins();
1387
1582
  }
1388
1583
  guid(digit = 8) {
1389
1584
  return "x".repeat(digit).replace(/[xy]/g, (c) => {
@@ -1404,7 +1599,7 @@ const beforePaste = async (position, config) => {
1404
1599
  config.map(async (configItem) => {
1405
1600
  const { offsetX = 0, offsetY = 0, ...positionClone } = position;
1406
1601
  let pastePosition = positionClone;
1407
- if (!isEmpty(pastePosition) && curNode.items) {
1602
+ if (!isEmpty(pastePosition) && curNode?.items) {
1408
1603
  pastePosition = getPositionInContainer(pastePosition, curNode.id);
1409
1604
  }
1410
1605
  if (pastePosition.left && configItem.style?.left) {
@@ -1427,8 +1622,9 @@ const beforePaste = async (position, config) => {
1427
1622
  ...pastePosition
1428
1623
  };
1429
1624
  }
1430
- if (isPage(pasteConfig)) {
1431
- pasteConfig.name = generatePageNameByApp(editorService.get("root"));
1625
+ const root = editorService.get("root");
1626
+ if (isPage(pasteConfig) && root) {
1627
+ pasteConfig.name = generatePageNameByApp(root);
1432
1628
  }
1433
1629
  return pasteConfig;
1434
1630
  })
@@ -1451,13 +1647,20 @@ const getAddParent = (node) => {
1451
1647
  let parentNode;
1452
1648
  if (isPage(node)) {
1453
1649
  parentNode = editorService.get("root");
1454
- } else if (curNode.items) {
1650
+ } else if (curNode?.items) {
1455
1651
  parentNode = curNode;
1456
- } else {
1652
+ } else if (curNode?.id) {
1457
1653
  parentNode = editorService.getParentById(curNode.id, false);
1458
1654
  }
1459
1655
  return parentNode;
1460
1656
  };
1657
+ const getDefaultConfig = async (addNode, parentNode) => {
1658
+ const { type, inputEvent, ...config } = addNode;
1659
+ const layout = await editorService.getLayout(toRaw(parentNode), addNode);
1660
+ const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
1661
+ newNode.style = getInitPositionStyle(newNode.style, layout);
1662
+ return newNode;
1663
+ };
1461
1664
 
1462
1665
  class Editor$1 extends BaseService {
1463
1666
  state = reactive({
@@ -1487,7 +1690,7 @@ class Editor$1 extends BaseService {
1487
1690
  "copy",
1488
1691
  "paste",
1489
1692
  "doPaste",
1490
- "duAlignCenter",
1693
+ "doAlignCenter",
1491
1694
  "alignCenter",
1492
1695
  "moveLayer",
1493
1696
  "moveToContainer",
@@ -1502,13 +1705,21 @@ class Editor$1 extends BaseService {
1502
1705
  );
1503
1706
  }
1504
1707
  set(name, value) {
1708
+ const preValue = this.state[name];
1505
1709
  this.state[name] = value;
1506
- if (name === "nodes") {
1710
+ if (name === "nodes" && Array.isArray(value)) {
1507
1711
  this.set("node", value[0]);
1508
1712
  }
1509
1713
  if (name === "root") {
1510
- this.state.pageLength = value?.items?.length || 0;
1511
- this.emit("root-change", value);
1714
+ if (Array.isArray(value)) {
1715
+ throw new Error("root \u4E0D\u80FD\u4E3A\u6570\u7EC4");
1716
+ }
1717
+ if (isObject(value) && !(value instanceof StageCore) && !(value instanceof Map)) {
1718
+ this.state.pageLength = value.items.length;
1719
+ } else {
1720
+ this.state.pageLength = 0;
1721
+ }
1722
+ this.emit("root-change", value, preValue);
1512
1723
  }
1513
1724
  }
1514
1725
  get(name) {
@@ -1519,16 +1730,21 @@ class Editor$1 extends BaseService {
1519
1730
  if (raw) {
1520
1731
  root = toRaw(root);
1521
1732
  }
1733
+ const info = {
1734
+ node: null,
1735
+ parent: null,
1736
+ page: null
1737
+ };
1522
1738
  if (!root)
1523
- return {};
1739
+ return info;
1524
1740
  if (id === root.id) {
1525
- return { node: root };
1741
+ info.node = root;
1742
+ return info;
1526
1743
  }
1527
1744
  const path = getNodePath(id, root.items);
1528
1745
  if (!path.length)
1529
- return {};
1746
+ return info;
1530
1747
  path.unshift(root);
1531
- const info = {};
1532
1748
  info.node = path[path.length - 1];
1533
1749
  info.parent = path[path.length - 2];
1534
1750
  path.forEach((item) => {
@@ -1544,8 +1760,6 @@ class Editor$1 extends BaseService {
1544
1760
  return node;
1545
1761
  }
1546
1762
  getParentById(id, raw = true) {
1547
- if (!this.get("root"))
1548
- return;
1549
1763
  const { parent } = this.getNodeInfo(id, raw);
1550
1764
  return parent;
1551
1765
  }
@@ -1562,13 +1776,13 @@ class Editor$1 extends BaseService {
1562
1776
  }
1563
1777
  async select(config) {
1564
1778
  const { node, page, parent } = this.selectedConfigExceptionHandler(config);
1565
- this.set("nodes", [node]);
1566
- this.set("page", page || null);
1567
- this.set("parent", parent || null);
1779
+ this.set("nodes", node ? [node] : []);
1780
+ this.set("page", page);
1781
+ this.set("parent", parent);
1568
1782
  if (page) {
1569
1783
  historyService.changePage(toRaw(page));
1570
1784
  } else {
1571
- historyService.empty();
1785
+ historyService.resetState();
1572
1786
  }
1573
1787
  if (node?.id) {
1574
1788
  this.get("stage")?.renderer.runtime?.getApp?.()?.emit(
@@ -1578,7 +1792,7 @@ class Editor$1 extends BaseService {
1578
1792
  page,
1579
1793
  parent
1580
1794
  },
1581
- getNodePath(node.id, this.get("root").items)
1795
+ getNodePath(node.id, this.get("root")?.items)
1582
1796
  );
1583
1797
  }
1584
1798
  this.emit("select", node);
@@ -1600,6 +1814,10 @@ class Editor$1 extends BaseService {
1600
1814
  async selectNextPage() {
1601
1815
  const root = toRaw(this.get("root"));
1602
1816
  const page = toRaw(this.get("page"));
1817
+ if (!page)
1818
+ throw new Error("page\u4E0D\u80FD\u4E3A\u7A7A");
1819
+ if (!root)
1820
+ throw new Error("root\u4E0D\u80FD\u4E3A\u7A7A");
1603
1821
  const index = getNodeIndex(page, root);
1604
1822
  const nextPage = root.items[index + 1] || root.items[0];
1605
1823
  await this.select(nextPage);
@@ -1626,16 +1844,20 @@ class Editor$1 extends BaseService {
1626
1844
  }
1627
1845
  async doAdd(node, parent) {
1628
1846
  const root = this.get("root");
1847
+ if (!root)
1848
+ throw new Error("root\u4E3A\u7A7A");
1629
1849
  const curNode = this.get("node");
1630
1850
  const stage = this.get("stage");
1631
- if ((parent?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && node.type !== NodeType.PAGE) {
1851
+ if (!curNode)
1852
+ throw new Error("\u5F53\u524D\u9009\u4E2D\u8282\u70B9\u4E3A\u7A7A");
1853
+ if ((parent.type === NodeType.ROOT || curNode?.type === NodeType.ROOT) && node.type !== NodeType.PAGE) {
1632
1854
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
1633
1855
  }
1634
1856
  if (parent.id !== curNode.id && node.type !== NodeType.PAGE) {
1635
1857
  const index = parent.items.indexOf(curNode);
1636
- parent?.items?.splice(index + 1, 0, node);
1858
+ parent.items?.splice(index + 1, 0, node);
1637
1859
  } else {
1638
- parent?.items?.push(node);
1860
+ parent.items?.push(node);
1639
1861
  }
1640
1862
  const layout = await this.getLayout(toRaw(parent), node);
1641
1863
  node.style = getInitPositionStyle(node.style, layout);
@@ -1666,6 +1888,10 @@ class Editor$1 extends BaseService {
1666
1888
  }
1667
1889
  const newNodes = await Promise.all(
1668
1890
  addNodes.map((node) => {
1891
+ const root = this.get("root");
1892
+ if (isPage(node) && root) {
1893
+ return this.doAdd(node, root);
1894
+ }
1669
1895
  const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(node);
1670
1896
  if (!parentNode)
1671
1897
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
@@ -1684,14 +1910,16 @@ class Editor$1 extends BaseService {
1684
1910
  stage?.select(newNodes[0].id);
1685
1911
  }
1686
1912
  }
1687
- this.pushHistoryState();
1913
+ if (!isPage(newNodes[0])) {
1914
+ this.pushHistoryState();
1915
+ }
1688
1916
  this.emit("add", newNodes);
1689
1917
  return Array.isArray(addNode) ? newNodes : newNodes[0];
1690
1918
  }
1691
1919
  async doRemove(node) {
1692
1920
  const root = this.get("root");
1693
1921
  if (!root)
1694
- throw new Error("\u6CA1\u6709root");
1922
+ throw new Error("root\u4E0D\u80FD\u4E3A\u7A7A");
1695
1923
  const { parent, node: curNode } = this.getNodeInfo(node.id);
1696
1924
  if (!parent || !curNode)
1697
1925
  throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
@@ -1726,18 +1954,26 @@ class Editor$1 extends BaseService {
1726
1954
  async remove(nodeOrNodeList) {
1727
1955
  const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
1728
1956
  await Promise.all(nodes.map((node) => this.doRemove(node)));
1729
- this.pushHistoryState();
1957
+ if (!isPage(nodes[0])) {
1958
+ this.pushHistoryState();
1959
+ }
1730
1960
  this.emit("remove", nodes);
1731
1961
  }
1732
1962
  async doUpdate(config) {
1963
+ const root = this.get("root");
1964
+ if (!root)
1965
+ throw new Error("root\u4E3A\u7A7A");
1733
1966
  if (!config?.id)
1734
1967
  throw new Error("\u6CA1\u6709\u914D\u7F6E\u6216\u8005\u914D\u7F6E\u7F3A\u5C11id\u503C");
1735
1968
  const info = this.getNodeInfo(config.id, false);
1736
1969
  if (!info.node)
1737
1970
  throw new Error(`\u83B7\u53D6\u4E0D\u5230id\u4E3A${config.id}\u7684\u8282\u70B9`);
1738
1971
  const node = cloneDeep(toRaw(info.node));
1739
- let newConfig = await this.toggleFixedPosition(toRaw(config), node, this.get("root"));
1972
+ let newConfig = await this.toggleFixedPosition(toRaw(config), node, root);
1740
1973
  newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue) => {
1974
+ if (isObject(srcValue) && Array.isArray(objValue)) {
1975
+ return srcValue;
1976
+ }
1741
1977
  if (Array.isArray(srcValue)) {
1742
1978
  return srcValue;
1743
1979
  }
@@ -1761,14 +1997,14 @@ class Editor$1 extends BaseService {
1761
1997
  newConfig = setLayout(newConfig, newLayout);
1762
1998
  }
1763
1999
  parentNodeItems[index] = newConfig;
1764
- const nodes = this.get("nodes") || [];
2000
+ const nodes = this.get("nodes");
1765
2001
  const targetIndex = nodes.findIndex((nodeItem) => `${nodeItem.id}` === `${newConfig.id}`);
1766
2002
  nodes.splice(targetIndex, 1, newConfig);
1767
2003
  this.set("nodes", [...nodes]);
1768
2004
  this.get("stage")?.update({
1769
2005
  config: cloneDeep(newConfig),
1770
2006
  parentId: parent.id,
1771
- root: cloneDeep(this.get("root"))
2007
+ root: cloneDeep(root)
1772
2008
  });
1773
2009
  if (newConfig.type === NodeType.PAGE) {
1774
2010
  this.set("page", newConfig);
@@ -1781,11 +2017,19 @@ class Editor$1 extends BaseService {
1781
2017
  const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
1782
2018
  this.pushHistoryState();
1783
2019
  this.emit("update", newNodes);
2020
+ codeBlockService.refreshCombineInfo();
1784
2021
  return Array.isArray(config) ? newNodes : newNodes[0];
1785
2022
  }
1786
2023
  async sort(id1, id2) {
2024
+ const root = this.get("root");
2025
+ if (!root)
2026
+ throw new Error("root\u4E3A\u7A7A");
1787
2027
  const node = this.get("node");
2028
+ if (!node)
2029
+ throw new Error("\u5F53\u524D\u8282\u70B9\u4E3A\u7A7A");
1788
2030
  const parent = cloneDeep(toRaw(this.get("parent")));
2031
+ if (!parent)
2032
+ throw new Error("\u7236\u8282\u70B9\u4E3A\u7A7A");
1789
2033
  const index2 = parent.items.findIndex((node2) => `${node2.id}` === `${id2}`);
1790
2034
  if (index2 < 0)
1791
2035
  return;
@@ -1796,7 +2040,7 @@ class Editor$1 extends BaseService {
1796
2040
  this.get("stage")?.update({
1797
2041
  config: cloneDeep(node),
1798
2042
  parentId: parent.id,
1799
- root: cloneDeep(this.get("root"))
2043
+ root: cloneDeep(root)
1800
2044
  });
1801
2045
  this.addModifiedNodeId(parent.id);
1802
2046
  this.pushHistoryState();
@@ -1810,8 +2054,16 @@ class Editor$1 extends BaseService {
1810
2054
  const config = await storageService.getItem(COPY_STORAGE_KEY);
1811
2055
  if (!Array.isArray(config))
1812
2056
  return;
2057
+ const node = this.get("node");
2058
+ let parent = null;
2059
+ if (config.length === 1 && config[0].id === node?.id) {
2060
+ parent = this.get("parent");
2061
+ if (parent?.type === NodeType.ROOT) {
2062
+ parent = this.get("page");
2063
+ }
2064
+ }
1813
2065
  const pasteConfigs = await this.doPaste(config, position);
1814
- return this.add(pasteConfigs);
2066
+ return this.add(pasteConfigs, parent);
1815
2067
  }
1816
2068
  async doPaste(config, position = {}) {
1817
2069
  const pasteConfigs = await beforePaste(position, cloneDeep(config));
@@ -1846,13 +2098,24 @@ class Editor$1 extends BaseService {
1846
2098
  const stage = this.get("stage");
1847
2099
  const newNodes = await Promise.all(nodes.map((node) => this.doAlignCenter(node)));
1848
2100
  const newNode = await this.update(newNodes);
1849
- await stage?.multiSelect(newNodes.map((node) => node.id));
2101
+ if (newNodes.length > 1) {
2102
+ await stage?.multiSelect(newNodes.map((node) => node.id));
2103
+ } else {
2104
+ await stage?.select(newNodes[0].id);
2105
+ }
1850
2106
  return newNode;
1851
2107
  }
1852
2108
  async moveLayer(offset) {
2109
+ const root = this.get("root");
2110
+ if (!root)
2111
+ throw new Error("root\u4E3A\u7A7A");
1853
2112
  const parent = this.get("parent");
2113
+ if (!parent)
2114
+ throw new Error("\u7236\u8282\u70B9\u4E3A\u7A7A");
1854
2115
  const node = this.get("node");
1855
- const brothers = parent?.items || [];
2116
+ if (!node)
2117
+ throw new Error("\u5F53\u524D\u8282\u70B9\u4E3A\u7A7A");
2118
+ const brothers = parent.items || [];
1856
2119
  const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
1857
2120
  const layout = await this.getLayout(parent, node);
1858
2121
  const isRelative = layout === Layout.RELATIVE;
@@ -1868,17 +2131,17 @@ class Editor$1 extends BaseService {
1868
2131
  this.get("stage")?.update({
1869
2132
  config: cloneDeep(toRaw(parent)),
1870
2133
  parentId: grandparent?.id,
1871
- root: cloneDeep(this.get("root"))
2134
+ root: cloneDeep(root)
1872
2135
  });
1873
2136
  this.addModifiedNodeId(parent.id);
1874
2137
  this.pushHistoryState();
1875
2138
  }
1876
2139
  async moveToContainer(config, targetId) {
2140
+ const root = cloneDeep(this.get("root"));
1877
2141
  const { node, parent } = this.getNodeInfo(config.id, false);
1878
2142
  const target = this.getNodeById(targetId, false);
1879
2143
  const stage = this.get("stage");
1880
- if (node && parent && stage) {
1881
- const root = cloneDeep(this.get("root"));
2144
+ if (root && node && parent && stage) {
1882
2145
  const index = getNodeIndex(node, parent);
1883
2146
  parent.items?.splice(index, 1);
1884
2147
  await stage.remove({ id: node.id, parentId: parent.id, root });
@@ -1932,8 +2195,7 @@ class Editor$1 extends BaseService {
1932
2195
  }
1933
2196
  });
1934
2197
  }
1935
- destroy() {
1936
- this.removeAllListeners();
2198
+ resetState() {
1937
2199
  this.set("root", null);
1938
2200
  this.set("node", null);
1939
2201
  this.set("nodes", []);
@@ -1942,16 +2204,23 @@ class Editor$1 extends BaseService {
1942
2204
  this.set("stage", null);
1943
2205
  this.set("highlightNode", null);
1944
2206
  this.set("modifiedNodeIds", /* @__PURE__ */ new Map());
1945
- this.set("pageLength", /* @__PURE__ */ new Map());
2207
+ this.set("pageLength", 0);
2208
+ }
2209
+ destroy() {
2210
+ this.removeAllListeners();
2211
+ this.resetState();
2212
+ this.removeAllPlugins();
1946
2213
  }
1947
2214
  resetModifiedNodeId() {
1948
2215
  this.get("modifiedNodeIds").clear();
1949
2216
  }
1950
2217
  async getCodeDsl() {
1951
2218
  const root = this.get("root");
1952
- if (!root)
1953
- return null;
1954
- return root.codeBlocks || null;
2219
+ return root?.codeBlocks || null;
2220
+ }
2221
+ getCodeDslSync() {
2222
+ const root = this.get("root");
2223
+ return root?.codeBlocks || null;
1955
2224
  }
1956
2225
  async setCodeDsl(codeDsl) {
1957
2226
  if (!this.state.root)
@@ -1965,9 +2234,10 @@ class Editor$1 extends BaseService {
1965
2234
  }
1966
2235
  pushHistoryState() {
1967
2236
  const curNode = cloneDeep(toRaw(this.get("node")));
1968
- if (!this.isHistoryStateChange) {
2237
+ const page = this.get("page");
2238
+ if (!this.isHistoryStateChange && curNode && page) {
1969
2239
  historyService.push({
1970
- data: cloneDeep(toRaw(this.get("page"))),
2240
+ data: cloneDeep(toRaw(page)),
1971
2241
  modifiedNodeIds: this.get("modifiedNodeIds"),
1972
2242
  nodeId: curNode.id
1973
2243
  });
@@ -2064,10 +2334,14 @@ class Events extends BaseService {
2064
2334
  getMethod(type) {
2065
2335
  return cloneDeep(methodMap[type] || DEFAULT_METHODS);
2066
2336
  }
2067
- destroy() {
2337
+ resetState() {
2068
2338
  eventMap = reactive({});
2069
2339
  methodMap = reactive({});
2340
+ }
2341
+ destroy() {
2342
+ this.resetState();
2070
2343
  this.removeAllListeners();
2344
+ this.removeAllPlugins();
2071
2345
  }
2072
2346
  }
2073
2347
  const eventsService = new Events();
@@ -2267,14 +2541,14 @@ const fillConfig = (config = []) => [
2267
2541
  {
2268
2542
  name: "created",
2269
2543
  text: "created",
2270
- type: "code-select",
2271
- labelWidth: "100px"
2544
+ labelWidth: "100px",
2545
+ type: "code-select"
2272
2546
  },
2273
2547
  {
2274
2548
  name: "mounted",
2275
2549
  text: "mounted",
2276
- type: "code-select",
2277
- labelWidth: "100px"
2550
+ labelWidth: "100px",
2551
+ type: "code-select"
2278
2552
  }
2279
2553
  ]
2280
2554
  }
@@ -2342,8 +2616,19 @@ class Ui extends BaseService {
2342
2616
  }
2343
2617
  return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
2344
2618
  }
2619
+ resetState() {
2620
+ this.set("showSrc", false);
2621
+ this.set("uiSelectMode", false);
2622
+ this.set("zoom", 1);
2623
+ this.set("stageContainerRect", {
2624
+ width: 0,
2625
+ height: 0
2626
+ });
2627
+ }
2345
2628
  destroy() {
2629
+ this.resetState();
2346
2630
  this.removeAllListeners();
2631
+ this.removeAllPlugins();
2347
2632
  }
2348
2633
  async setStageRect(value) {
2349
2634
  state.stageRect = {
@@ -2370,6 +2655,7 @@ const useStage = (stageOptions) => {
2370
2655
  containerHighlightClassName: stageOptions.containerHighlightClassName,
2371
2656
  containerHighlightDuration: stageOptions.containerHighlightDuration,
2372
2657
  containerHighlightType: stageOptions.containerHighlightType,
2658
+ disabledDragStart: stageOptions.disabledDragStart,
2373
2659
  canSelect: (el, event, stop) => {
2374
2660
  const elCanSelect = stageOptions.canSelect(el);
2375
2661
  if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
@@ -2386,220 +2672,97 @@ const useStage = (stageOptions) => {
2386
2672
  getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
2387
2673
  ]);
2388
2674
  stage.on("select", (el) => {
2389
- if (`${editorService.get("node")?.id}` === el.id)
2390
- return;
2391
- editorService.select(el.id);
2392
- });
2393
- stage.on("highlight", (el) => {
2394
- editorService.highlight(el.id);
2395
- });
2396
- stage.on("multiSelect", (els) => {
2397
- editorService.multiSelect(els.map((el) => el.id));
2398
- });
2399
- stage.on("update", (ev) => {
2400
- if (ev.parentEl) {
2401
- for (const data of ev.data) {
2402
- editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
2403
- }
2404
- return;
2405
- }
2406
- editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
2407
- });
2408
- stage.on("sort", (ev) => {
2409
- editorService.sort(ev.src, ev.dist);
2410
- });
2411
- stage.on("select-parent", () => {
2412
- const parent = editorService.get("parent");
2413
- editorService.select(parent);
2414
- editorService.get("stage").select(parent.id);
2415
- });
2416
- stage.on("changeGuides", (e) => {
2417
- uiService.set("showGuides", true);
2418
- if (!root.value || !page.value)
2675
+ if (`${editorService.get("node")?.id}` === el.id && editorService.get("nodes").length === 1)
2419
2676
  return;
2420
- const storageKey = getGuideLineKey(
2421
- e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY
2422
- );
2423
- if (e.guides.length) {
2424
- globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
2425
- } else {
2426
- globalThis.localStorage.removeItem(storageKey);
2427
- }
2428
- });
2429
- return stage;
2430
- };
2431
-
2432
- const _hoisted_1$b = { class: "m-editor-empty-panel" };
2433
- const _hoisted_2$5 = { class: "m-editor-empty-content" };
2434
- const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2435
- const _sfc_main$n = /* @__PURE__ */ defineComponent({
2436
- __name: "AddPageBox",
2437
- setup(__props) {
2438
- const services = inject("services");
2439
- const clickHandler = () => {
2440
- const { editorService } = services || {};
2441
- if (!editorService)
2442
- return;
2443
- editorService.add({
2444
- type: NodeType.PAGE,
2445
- name: generatePageNameByApp(toRaw(editorService.get("root")))
2446
- });
2447
- };
2448
- return (_ctx, _cache) => {
2449
- return openBlock(), createElementBlock("div", _hoisted_1$b, [
2450
- createElementVNode("div", _hoisted_2$5, [
2451
- createElementVNode("div", {
2452
- class: "m-editor-empty-button",
2453
- onClick: clickHandler
2454
- }, [
2455
- createElementVNode("div", null, [
2456
- createVNode(_sfc_main$o, { icon: unref(Plus) }, null, 8, ["icon"])
2457
- ]),
2458
- _hoisted_3$2
2459
- ])
2460
- ])
2461
- ]);
2462
- };
2463
- }
2464
- });
2465
-
2466
- const _sfc_main$m = /* @__PURE__ */ defineComponent({
2467
- __name: "Resizer",
2468
- emits: ["change"],
2469
- setup(__props, { emit }) {
2470
- const target = ref();
2471
- let getso;
2472
- onMounted(() => {
2473
- if (!target.value)
2474
- return;
2475
- getso = new Gesto(target.value, {
2476
- container: window,
2477
- pinchOutside: true
2478
- }).on("drag", (e) => {
2479
- if (!target.value)
2480
- return;
2481
- emit("change", e.deltaX);
2482
- });
2483
- });
2484
- onUnmounted(() => {
2485
- getso?.unset();
2486
- });
2487
- return (_ctx, _cache) => {
2488
- return openBlock(), createElementBlock("span", {
2489
- ref_key: "target",
2490
- ref: target,
2491
- class: "m-editor-resizer"
2492
- }, [
2493
- renderSlot(_ctx.$slots, "default")
2494
- ], 512);
2495
- };
2496
- }
2497
- });
2498
-
2499
- const _sfc_main$l = /* @__PURE__ */ defineComponent({
2500
- __name: "Layout",
2501
- props: {
2502
- left: null,
2503
- right: null,
2504
- minLeft: { default: 1 },
2505
- minRight: { default: 1 },
2506
- leftClass: null,
2507
- rightClass: null,
2508
- centerClass: null
2509
- },
2510
- emits: ["update:left", "change", "update:right"],
2511
- setup(__props, { emit }) {
2512
- const props = __props;
2513
- const el = ref();
2514
- let clientWidth = 0;
2515
- const resizerObserver = new ResizeObserver((entries) => {
2516
- for (const { contentRect } of entries) {
2517
- clientWidth = contentRect.width;
2518
- center.value = clientWidth - (props.left || 0) - (props.right || 0);
2519
- emit("change", {
2520
- left: props.left,
2521
- center: center.value,
2522
- right: props.right
2523
- });
2524
- }
2525
- });
2526
- onMounted(() => {
2527
- if (el.value) {
2528
- resizerObserver.observe(el.value);
2529
- }
2530
- });
2531
- onUnmounted(() => {
2532
- resizerObserver.disconnect();
2533
- });
2534
- const center = ref(0);
2535
- const changeLeft = (deltaX) => {
2536
- if (typeof props.left === "undefined")
2537
- return;
2538
- let left = Math.max(props.left + deltaX, props.minLeft) || 0;
2539
- emit("update:left", left);
2540
- if (clientWidth - left - (props.right || 0) <= 0) {
2541
- left = props.left;
2677
+ editorService.select(el.id);
2678
+ });
2679
+ stage.on("highlight", (el) => {
2680
+ editorService.highlight(el.id);
2681
+ });
2682
+ stage.on("multi-select", (els) => {
2683
+ editorService.multiSelect(els.map((el) => el.id));
2684
+ });
2685
+ stage.on("update", (ev) => {
2686
+ if (ev.parentEl) {
2687
+ for (const data of ev.data) {
2688
+ editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
2542
2689
  }
2543
- center.value = clientWidth - left - (props.right || 0);
2544
- emit("change", {
2545
- left,
2546
- center: center.value,
2547
- right: props.right
2548
- });
2549
- };
2550
- const changeRight = (deltaX) => {
2551
- if (typeof props.right === "undefined")
2690
+ return;
2691
+ }
2692
+ editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
2693
+ });
2694
+ stage.on("sort", (ev) => {
2695
+ editorService.sort(ev.src, ev.dist);
2696
+ });
2697
+ stage.on("select-parent", () => {
2698
+ const parent = editorService.get("parent");
2699
+ if (!parent)
2700
+ throw new Error("\u7236\u8282\u70B9\u4E3A\u7A7A");
2701
+ editorService.select(parent);
2702
+ editorService.get("stage")?.select(parent.id);
2703
+ });
2704
+ stage.on("change-guides", (e) => {
2705
+ uiService.set("showGuides", true);
2706
+ if (!root.value || !page.value)
2707
+ return;
2708
+ const storageKey = getGuideLineKey(
2709
+ e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY
2710
+ );
2711
+ if (e.guides.length) {
2712
+ globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
2713
+ } else {
2714
+ globalThis.localStorage.removeItem(storageKey);
2715
+ }
2716
+ });
2717
+ return stage;
2718
+ };
2719
+
2720
+ const _hoisted_1$d = { class: "m-editor-empty-panel" };
2721
+ const _hoisted_2$6 = { class: "m-editor-empty-content" };
2722
+ const _hoisted_3$3 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2723
+ const __default__$l = defineComponent({
2724
+ name: "MEditorAddPageBox"
2725
+ });
2726
+ const _sfc_main$m = /* @__PURE__ */ defineComponent({
2727
+ ...__default__$l,
2728
+ setup(__props) {
2729
+ const services = inject("services");
2730
+ const clickHandler = () => {
2731
+ const { editorService } = services || {};
2732
+ if (!editorService)
2552
2733
  return;
2553
- let right = Math.max(props.right - deltaX, props.minRight) || 0;
2554
- emit("update:right", right);
2555
- if (clientWidth - (props.left || 0) - right <= 0) {
2556
- right = props.right;
2557
- }
2558
- center.value = clientWidth - (props.left || 0) - right;
2559
- emit("change", {
2560
- left: props.left,
2561
- center: center.value,
2562
- right
2734
+ const root = toRaw(editorService.get("root"));
2735
+ if (!root)
2736
+ throw new Error("root \u4E0D\u80FD\u4E3A\u7A7A");
2737
+ editorService.add({
2738
+ type: NodeType.PAGE,
2739
+ name: generatePageNameByApp(root)
2563
2740
  });
2564
2741
  };
2565
2742
  return (_ctx, _cache) => {
2566
- return openBlock(), createElementBlock("div", {
2567
- ref_key: "el",
2568
- ref: el,
2569
- class: "m-editor-layout"
2570
- }, [
2571
- typeof props.left !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2572
- createElementVNode("div", {
2573
- class: normalizeClass(["m-editor-layout-left", __props.leftClass]),
2574
- style: normalizeStyle(`width: ${__props.left}px`)
2575
- }, [
2576
- renderSlot(_ctx.$slots, "left")
2577
- ], 6),
2578
- createVNode(_sfc_main$m, { onChange: changeLeft })
2579
- ], 64)) : createCommentVNode("", true),
2580
- createElementVNode("div", {
2581
- class: normalizeClass(["m-editor-layout-center", __props.centerClass]),
2582
- style: normalizeStyle(`width: ${center.value}px`)
2583
- }, [
2584
- renderSlot(_ctx.$slots, "center")
2585
- ], 6),
2586
- typeof props.right !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
2587
- createVNode(_sfc_main$m, { onChange: changeRight }),
2743
+ return openBlock(), createElementBlock("div", _hoisted_1$d, [
2744
+ createElementVNode("div", _hoisted_2$6, [
2588
2745
  createElementVNode("div", {
2589
- class: normalizeClass(["m-editor-layout-right", __props.rightClass]),
2590
- style: normalizeStyle(`width: ${__props.right}px`)
2746
+ class: "m-editor-empty-button",
2747
+ onClick: clickHandler
2591
2748
  }, [
2592
- renderSlot(_ctx.$slots, "right")
2593
- ], 6)
2594
- ], 64)) : createCommentVNode("", true)
2595
- ], 512);
2749
+ createElementVNode("div", null, [
2750
+ createVNode(_sfc_main$s, { icon: unref(Plus) }, null, 8, ["icon"])
2751
+ ]),
2752
+ _hoisted_3$3
2753
+ ])
2754
+ ])
2755
+ ]);
2596
2756
  };
2597
2757
  }
2598
2758
  });
2599
2759
 
2600
- const _hoisted_1$a = { class: "m-editor" };
2601
- const _sfc_main$k = /* @__PURE__ */ defineComponent({
2602
- __name: "Framework",
2760
+ const _hoisted_1$c = { class: "m-editor" };
2761
+ const __default__$k = defineComponent({
2762
+ name: "MEditorFramework"
2763
+ });
2764
+ const _sfc_main$l = /* @__PURE__ */ defineComponent({
2765
+ ...__default__$k,
2603
2766
  props: {
2604
2767
  codeOptions: { default: () => ({}) }
2605
2768
  },
@@ -2633,7 +2796,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2633
2796
  columnWidth.value.right = right;
2634
2797
  columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
2635
2798
  }
2636
- uiService?.set("columnWidth", columnWidth);
2799
+ uiService?.set("columnWidth", columnWidth.value);
2637
2800
  },
2638
2801
  {
2639
2802
  immediate: true
@@ -2653,8 +2816,11 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2653
2816
  globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
2654
2817
  }
2655
2818
  );
2656
- const columnWidthChange = (columnWidth2) => {
2657
- uiService?.set("columnWidth", columnWidth2);
2819
+ const columnWidthChange = (columnW) => {
2820
+ columnWidth.value.left = columnW.left;
2821
+ columnWidth.value.center = columnW.center;
2822
+ columnWidth.value.right = columnW.right;
2823
+ uiService?.set("columnWidth", columnW);
2658
2824
  };
2659
2825
  const saveCode = (value) => {
2660
2826
  try {
@@ -2665,7 +2831,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2665
2831
  };
2666
2832
  return (_ctx, _cache) => {
2667
2833
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
2668
- return openBlock(), createElementBlock("div", _hoisted_1$a, [
2834
+ return openBlock(), createElementBlock("div", _hoisted_1$c, [
2669
2835
  renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2670
2836
  unref(showSrc) ? (openBlock(), createBlock(_component_magic_code_editor, {
2671
2837
  key: 0,
@@ -2673,7 +2839,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2673
2839
  "init-values": unref(root),
2674
2840
  options: __props.codeOptions,
2675
2841
  onSave: saveCode
2676
- }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$l, {
2842
+ }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$n, {
2677
2843
  key: 1,
2678
2844
  class: "m-editor-content",
2679
2845
  "left-class": "m-editor-framework-left",
@@ -2692,7 +2858,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2692
2858
  ]),
2693
2859
  center: withCtx(() => [
2694
2860
  unref(pageLength) > 0 ? renderSlot(_ctx.$slots, "workspace", { key: 0 }) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
2695
- createVNode(_sfc_main$n)
2861
+ createVNode(_sfc_main$m)
2696
2862
  ])
2697
2863
  ]),
2698
2864
  _: 2
@@ -2714,13 +2880,16 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2714
2880
  }
2715
2881
  });
2716
2882
 
2717
- const _hoisted_1$9 = {
2883
+ const _hoisted_1$b = {
2718
2884
  key: 1,
2719
2885
  class: "menu-item-text"
2720
2886
  };
2721
- const _hoisted_2$4 = { class: "el-dropdown-link menubar-menu-button" };
2722
- const _sfc_main$j = /* @__PURE__ */ defineComponent({
2723
- __name: "ToolButton",
2887
+ const _hoisted_2$5 = { class: "el-dropdown-link menubar-menu-button" };
2888
+ const __default__$j = defineComponent({
2889
+ name: "MEditorToolButton"
2890
+ });
2891
+ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2892
+ ...__default__$j,
2724
2893
  props: {
2725
2894
  data: { default: () => ({
2726
2895
  type: "text",
@@ -2795,7 +2964,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2795
2964
  __props.data.type === "divider" ? (openBlock(), createBlock(unref(TMagicDivider), {
2796
2965
  key: 0,
2797
2966
  direction: __props.data.direction || "vertical"
2798
- }, null, 8, ["direction"])) : __props.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$9, toDisplayString(__props.data.text), 1)) : __props.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2967
+ }, null, 8, ["direction"])) : __props.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$b, toDisplayString(__props.data.text), 1)) : __props.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2799
2968
  __props.data.tooltip ? (openBlock(), createBlock(unref(TMagicTooltip), {
2800
2969
  key: 0,
2801
2970
  effect: "dark",
@@ -2809,7 +2978,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2809
2978
  disabled: unref(disabled)
2810
2979
  }, {
2811
2980
  default: withCtx(() => [
2812
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$o, {
2981
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$s, {
2813
2982
  key: 0,
2814
2983
  icon: __props.data.icon
2815
2984
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2826,7 +2995,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2826
2995
  disabled: unref(disabled)
2827
2996
  }, {
2828
2997
  default: withCtx(() => [
2829
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$o, {
2998
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$s, {
2830
2999
  key: 0,
2831
3000
  icon: __props.data.icon
2832
3001
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2859,7 +3028,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2859
3028
  })) : createCommentVNode("", true)
2860
3029
  ]),
2861
3030
  default: withCtx(() => [
2862
- createElementVNode("span", _hoisted_2$4, [
3031
+ createElementVNode("span", _hoisted_2$5, [
2863
3032
  createTextVNode(toDisplayString(__props.data.text), 1),
2864
3033
  createVNode(unref(TMagicIcon), { class: "el-icon--right" }, {
2865
3034
  default: withCtx(() => [
@@ -2876,8 +3045,11 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2876
3045
  }
2877
3046
  });
2878
3047
 
2879
- const _sfc_main$i = /* @__PURE__ */ defineComponent({
2880
- __name: "NavMenu",
3048
+ const __default__$i = defineComponent({
3049
+ name: "MEditorNavMenu"
3050
+ });
3051
+ const _sfc_main$j = /* @__PURE__ */ defineComponent({
3052
+ ...__default__$i,
2881
3053
  props: {
2882
3054
  data: { default: () => ({}) },
2883
3055
  height: { default: 35 }
@@ -2921,7 +3093,10 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2921
3093
  icon: markRaw(Delete),
2922
3094
  tooltip: `\u522A\u9664(Delete)`,
2923
3095
  disabled: () => services?.editorService.get("node")?.type === NodeType.PAGE,
2924
- handler: () => services?.editorService.remove(services?.editorService.get("node"))
3096
+ handler: () => {
3097
+ const node = services?.editorService.get("node");
3098
+ node && services?.editorService.remove(node);
3099
+ }
2925
3100
  });
2926
3101
  break;
2927
3102
  case "undo":
@@ -3032,7 +3207,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
3032
3207
  style: normalizeStyle(`width: ${unref(columnWidth)?.[key]}px`)
3033
3208
  }, [
3034
3209
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(buttons)[key], (item, index) => {
3035
- return openBlock(), createBlock(_sfc_main$j, {
3210
+ return openBlock(), createBlock(_sfc_main$k, {
3036
3211
  data: item,
3037
3212
  key: index
3038
3213
  }, null, 8, ["data"]);
@@ -3044,9 +3219,12 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
3044
3219
  }
3045
3220
  });
3046
3221
 
3047
- const _hoisted_1$8 = { class: "m-editor-props-panel" };
3048
- const _sfc_main$h = /* @__PURE__ */ defineComponent({
3049
- __name: "PropsPanel",
3222
+ const _hoisted_1$a = { class: "m-editor-props-panel" };
3223
+ const __default__$h = defineComponent({
3224
+ name: "MEditorPropsPanel"
3225
+ });
3226
+ const _sfc_main$i = /* @__PURE__ */ defineComponent({
3227
+ ...__default__$h,
3050
3228
  emits: ["mounted"],
3051
3229
  setup(__props, { expose, emit }) {
3052
3230
  const internalInstance = getCurrentInstance();
@@ -3071,6 +3249,9 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3071
3249
  onMounted(() => {
3072
3250
  emit("mounted", internalInstance);
3073
3251
  });
3252
+ onUnmounted(() => {
3253
+ services?.propsService.off("props-configs-change", init);
3254
+ });
3074
3255
  watchEffect(() => {
3075
3256
  if (configForm.value && stage.value) {
3076
3257
  configForm.value.formState.stage = stage.value;
@@ -3088,10 +3269,9 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3088
3269
  };
3089
3270
  expose({ submit });
3090
3271
  return (_ctx, _cache) => {
3091
- const _component_m_form = resolveComponent("m-form");
3092
- return openBlock(), createElementBlock("div", _hoisted_1$8, [
3272
+ return openBlock(), createElementBlock("div", _hoisted_1$a, [
3093
3273
  renderSlot(_ctx.$slots, "props-panel-header"),
3094
- createVNode(_component_m_form, {
3274
+ createVNode(unref(MForm), {
3095
3275
  ref_key: "configForm",
3096
3276
  ref: configForm,
3097
3277
  class: normalizeClass(`m-editor-props-panel ${unref(propsPanelSize)}`),
@@ -3106,43 +3286,360 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3106
3286
  }
3107
3287
  });
3108
3288
 
3109
- const _hoisted_1$7 = ["id"];
3110
- const _hoisted_2$3 = { class: "list-item" };
3111
- const _hoisted_3$1 = { class: "code-name" };
3112
- const _hoisted_4$1 = { class: "code-name-wrapper" };
3113
- const _hoisted_5$1 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u4EE3\u7801\u5757\u540D\u79F0", -1);
3114
- const _hoisted_6$1 = { class: "m-editor-wrapper" };
3115
- const _hoisted_7$1 = {
3116
- key: 1,
3289
+ const _hoisted_1$9 = {
3290
+ key: 0,
3117
3291
  class: "m-editor-content-bottom"
3118
3292
  };
3119
- const _hoisted_8$1 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
3120
- const _hoisted_9$1 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3121
- const _hoisted_10 = {
3122
- key: 2,
3293
+ const _hoisted_2$4 = /* @__PURE__ */ createTextVNode("\u786E\u8BA4");
3294
+ const _hoisted_3$2 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3295
+ const _hoisted_4$2 = {
3296
+ key: 1,
3123
3297
  class: "m-editor-content-bottom"
3124
3298
  };
3125
- const _hoisted_11 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3299
+ const _hoisted_5$1 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3300
+ const __default__$g = defineComponent({
3301
+ name: "MEditorCodeDraftEditor"
3302
+ });
3303
+ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3304
+ ...__default__$g,
3305
+ props: {
3306
+ id: null,
3307
+ content: null,
3308
+ editable: { type: Boolean, default: true },
3309
+ autoSaveDraft: { type: Boolean, default: true },
3310
+ codeOptions: null,
3311
+ language: null
3312
+ },
3313
+ emits: ["close", "saveAndClose"],
3314
+ setup(__props, { emit }) {
3315
+ const props = __props;
3316
+ const services = inject("services");
3317
+ const codeContent = ref("");
3318
+ const editorContent = ref("");
3319
+ const codeEditor = ref();
3320
+ const originCodeContent = ref("");
3321
+ const isFullScreen = ref(false);
3322
+ const codeOptions = computed(() => ({
3323
+ ...props.codeOptions,
3324
+ readOnly: !props.editable
3325
+ }));
3326
+ watchEffect(() => {
3327
+ codeContent.value = props.content;
3328
+ if (!originCodeContent.value) {
3329
+ originCodeContent.value = codeContent.value;
3330
+ }
3331
+ const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
3332
+ if (codeDraft) {
3333
+ codeContent.value = codeDraft;
3334
+ }
3335
+ });
3336
+ const saveCodeDraft = async (codeValue) => {
3337
+ if (!props.autoSaveDraft)
3338
+ return;
3339
+ if (originCodeContent.value === codeValue) {
3340
+ services?.codeBlockService.removeCodeDraft(props.id);
3341
+ return;
3342
+ }
3343
+ services?.codeBlockService.setCodeDraft(props.id, codeValue);
3344
+ tMagicMessage.success(`\u4EE3\u7801\u8349\u7A3F\u4FDD\u5B58\u6210\u529F ${datetimeFormatter(new Date())}`);
3345
+ };
3346
+ const saveAndClose = () => {
3347
+ if (!codeEditor.value || !props.editable)
3348
+ return;
3349
+ editorContent.value = codeEditor.value.getEditor()?.getValue();
3350
+ emit("saveAndClose", editorContent.value);
3351
+ };
3352
+ const close = async () => {
3353
+ const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
3354
+ if (codeDraft) {
3355
+ tMagicMessageBox.confirm("\u60A8\u6709\u4EE3\u7801\u4FEE\u6539\u672A\u4FDD\u5B58\uFF0C\u662F\u5426\u4FDD\u5B58\u540E\u518D\u5173\u95ED\uFF1F", "\u63D0\u793A", {
3356
+ confirmButtonText: "\u786E\u8BA4",
3357
+ cancelButtonText: "\u53D6\u6D88",
3358
+ type: "warning"
3359
+ }).then(async () => {
3360
+ saveAndClose();
3361
+ }).catch(() => {
3362
+ services?.codeBlockService.removeCodeDraft(props.id);
3363
+ emit("close");
3364
+ });
3365
+ } else {
3366
+ emit("close");
3367
+ }
3368
+ };
3369
+ const toggleFullScreen = () => {
3370
+ isFullScreen.value = !isFullScreen.value;
3371
+ if (codeEditor.value) {
3372
+ codeEditor.value.focus();
3373
+ }
3374
+ };
3375
+ return (_ctx, _cache) => {
3376
+ return openBlock(), createElementBlock("div", {
3377
+ class: normalizeClass(["m-editor-wrapper", isFullScreen.value ? "fullScreen" : "normal"])
3378
+ }, [
3379
+ createVNode(_sfc_main$p, {
3380
+ ref_key: "codeEditor",
3381
+ ref: codeEditor,
3382
+ class: "m-editor-container",
3383
+ "init-values": `${codeContent.value}`,
3384
+ onSave: saveCodeDraft,
3385
+ language: __props.language,
3386
+ options: unref(codeOptions)
3387
+ }, null, 8, ["init-values", "language", "options"]),
3388
+ __props.editable ? (openBlock(), createElementBlock("div", _hoisted_1$9, [
3389
+ createVNode(unref(TMagicButton), {
3390
+ type: "primary",
3391
+ class: "button",
3392
+ onClick: toggleFullScreen
3393
+ }, {
3394
+ default: withCtx(() => [
3395
+ createTextVNode(toDisplayString(isFullScreen.value ? "\u9000\u51FA\u5168\u5C4F" : "\u5168\u5C4F"), 1)
3396
+ ]),
3397
+ _: 1
3398
+ }),
3399
+ createVNode(unref(TMagicButton), {
3400
+ type: "primary",
3401
+ class: "button",
3402
+ onClick: saveAndClose
3403
+ }, {
3404
+ default: withCtx(() => [
3405
+ _hoisted_2$4
3406
+ ]),
3407
+ _: 1
3408
+ }),
3409
+ createVNode(unref(TMagicButton), {
3410
+ type: "primary",
3411
+ class: "button",
3412
+ onClick: close
3413
+ }, {
3414
+ default: withCtx(() => [
3415
+ _hoisted_3$2
3416
+ ]),
3417
+ _: 1
3418
+ })
3419
+ ])) : (openBlock(), createElementBlock("div", _hoisted_4$2, [
3420
+ createVNode(unref(TMagicButton), {
3421
+ type: "primary",
3422
+ class: "button",
3423
+ onClick: toggleFullScreen
3424
+ }, {
3425
+ default: withCtx(() => [
3426
+ createTextVNode(toDisplayString(isFullScreen.value ? "\u9000\u51FA\u5168\u5C4F" : "\u5168\u5C4F"), 1)
3427
+ ]),
3428
+ _: 1
3429
+ }),
3430
+ createVNode(unref(TMagicButton), {
3431
+ type: "primary",
3432
+ class: "button",
3433
+ onClick: close
3434
+ }, {
3435
+ default: withCtx(() => [
3436
+ _hoisted_5$1
3437
+ ]),
3438
+ _: 1
3439
+ })
3440
+ ]))
3441
+ ], 2);
3442
+ };
3443
+ }
3444
+ });
3445
+
3446
+ const _hoisted_1$8 = { class: "code-name-wrapper" };
3447
+ const _hoisted_2$3 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u4EE3\u7801\u5757\u540D\u79F0", -1);
3448
+ const _hoisted_3$1 = { class: "code-name-wrapper" };
3449
+ const _hoisted_4$1 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u53C2\u6570", -1);
3450
+ const __default__$f = defineComponent({
3451
+ name: "MEditorFunctionEditor"
3452
+ });
3126
3453
  const _sfc_main$g = /* @__PURE__ */ defineComponent({
3127
- __name: "CodeBlockEditor",
3454
+ ...__default__$f,
3455
+ props: {
3456
+ id: null,
3457
+ name: null,
3458
+ content: null,
3459
+ editable: { type: Boolean, default: true },
3460
+ autoSaveDraft: { type: Boolean, default: true },
3461
+ codeOptions: null,
3462
+ paramsColConfig: null
3463
+ },
3464
+ emits: ["change", "field-input"],
3465
+ setup(__props, { emit }) {
3466
+ const props = __props;
3467
+ const defaultParamColConfig = {
3468
+ type: "row",
3469
+ label: "\u53C2\u6570\u7C7B\u578B",
3470
+ items: [
3471
+ {
3472
+ text: "\u53C2\u6570\u7C7B\u578B",
3473
+ labelWidth: "70px",
3474
+ type: "select",
3475
+ name: "type",
3476
+ options: [
3477
+ {
3478
+ text: "\u6570\u5B57",
3479
+ label: "\u6570\u5B57",
3480
+ value: "number"
3481
+ },
3482
+ {
3483
+ text: "\u5B57\u7B26\u4E32",
3484
+ label: "\u5B57\u7B26\u4E32",
3485
+ value: "text"
3486
+ }
3487
+ ]
3488
+ }
3489
+ ]
3490
+ };
3491
+ const paramsColConfig = props.paramsColConfig || defaultParamColConfig;
3492
+ const tableConfig = {
3493
+ type: "table",
3494
+ border: true,
3495
+ enableFullscreen: false,
3496
+ name: "params",
3497
+ maxHeight: "300px",
3498
+ dropSort: false,
3499
+ items: [
3500
+ {
3501
+ type: "text",
3502
+ label: "\u53C2\u6570\u540D",
3503
+ name: "name",
3504
+ width: 200
3505
+ },
3506
+ {
3507
+ type: "text",
3508
+ label: "\u53C2\u6570\u6CE8\u91CA",
3509
+ name: "tip",
3510
+ width: 200
3511
+ },
3512
+ paramsColConfig
3513
+ ]
3514
+ };
3515
+ const services = inject("services");
3516
+ const codeName = ref("");
3517
+ const codeContent = ref("");
3518
+ const evalRes = ref(true);
3519
+ provide("mForm", {
3520
+ $emit: emit,
3521
+ setField: () => {
3522
+ }
3523
+ });
3524
+ const tableModel = ref();
3525
+ watchEffect(() => {
3526
+ codeName.value = props.name;
3527
+ codeContent.value = props.content;
3528
+ });
3529
+ const initTableModel = () => {
3530
+ const codeDsl = cloneDeep(services?.codeBlockService.getCodeDslSync());
3531
+ if (!codeDsl)
3532
+ return;
3533
+ tableModel.value = {
3534
+ params: codeDsl[props.id]?.params || []
3535
+ };
3536
+ };
3537
+ initTableModel();
3538
+ const beforeSave = (codeValue) => {
3539
+ try {
3540
+ eval(codeValue);
3541
+ return true;
3542
+ } catch (e) {
3543
+ tMagicMessage.error(e.stack);
3544
+ return false;
3545
+ }
3546
+ };
3547
+ const saveCode = async (codeValue2) => {
3548
+ if (!props.editable)
3549
+ return;
3550
+ evalRes.value = beforeSave(codeValue2);
3551
+ if (evalRes.value) {
3552
+ await services?.codeBlockService.setCodeDslById(props.id, {
3553
+ name: codeName.value,
3554
+ content: codeValue2,
3555
+ params: tableModel.value?.params || []
3556
+ });
3557
+ tMagicMessage.success("\u4EE3\u7801\u4FDD\u5B58\u6210\u529F");
3558
+ services?.codeBlockService.removeCodeDraft(props.id);
3559
+ }
3560
+ };
3561
+ const saveAndClose = async (codeValue2) => {
3562
+ await saveCode(codeValue2);
3563
+ if (evalRes.value) {
3564
+ close();
3565
+ }
3566
+ };
3567
+ const close = () => {
3568
+ services?.codeBlockService.setCodeEditorShowStatus(false);
3569
+ };
3570
+ return (_ctx, _cache) => {
3571
+ const _component_m_form_table = resolveComponent("m-form-table");
3572
+ return openBlock(), createBlock(unref(TMagicCard), { shadow: "never" }, {
3573
+ header: withCtx(() => [
3574
+ createElementVNode("div", _hoisted_1$8, [
3575
+ _hoisted_2$3,
3576
+ createVNode(unref(TMagicInput), {
3577
+ class: "code-name-input",
3578
+ modelValue: codeName.value,
3579
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeName.value = $event),
3580
+ disabled: !__props.editable
3581
+ }, null, 8, ["modelValue", "disabled"])
3582
+ ]),
3583
+ createElementVNode("div", _hoisted_3$1, [
3584
+ _hoisted_4$1,
3585
+ createVNode(_component_m_form_table, {
3586
+ style: { "width": "800px" },
3587
+ config: tableConfig,
3588
+ model: tableModel.value,
3589
+ enableToggleMode: false,
3590
+ name: "params",
3591
+ prop: "params",
3592
+ size: "small"
3593
+ }, null, 8, ["model"])
3594
+ ])
3595
+ ]),
3596
+ default: withCtx(() => [
3597
+ createVNode(_sfc_main$h, {
3598
+ id: __props.id,
3599
+ content: codeContent.value,
3600
+ editable: __props.editable,
3601
+ autoSaveDraft: __props.autoSaveDraft,
3602
+ codeOptions: __props.codeOptions,
3603
+ language: "javascript",
3604
+ onSaveAndClose: saveAndClose,
3605
+ onClose: close
3606
+ }, null, 8, ["id", "content", "editable", "autoSaveDraft", "codeOptions"])
3607
+ ]),
3608
+ _: 1
3609
+ });
3610
+ };
3611
+ }
3612
+ });
3613
+
3614
+ const _hoisted_1$7 = {
3615
+ key: 0,
3616
+ class: "m-editor-code-block-editor-panel"
3617
+ };
3618
+ const __default__$e = defineComponent({
3619
+ name: "MEditorCodeBlockEditor"
3620
+ });
3621
+ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3622
+ ...__default__$e,
3623
+ props: {
3624
+ paramsColConfig: null
3625
+ },
3128
3626
  setup(__props) {
3129
3627
  const services = inject("services");
3130
- const codeEditor = ref();
3628
+ const codeOptions = inject("codeOptions", {});
3131
3629
  const left = ref(200);
3132
3630
  const currentTitle = ref("");
3133
3631
  const codeConfig = ref(null);
3134
3632
  const state = reactive({
3135
3633
  codeList: []
3136
3634
  });
3137
- const isShowCodeBlockEditor = computed(
3138
- () => codeConfig.value && services?.codeBlockService.getCodeEditorShowStatus() || false
3139
- );
3140
- const mode = computed(() => services?.codeBlockService.getMode());
3141
3635
  const id = computed(() => services?.codeBlockService.getId() || "");
3142
3636
  const editable = computed(() => services?.codeBlockService.getEditStatus());
3143
3637
  const selectedIds = computed(() => services?.codeBlockService.getCombineIds() || []);
3144
3638
  watchEffect(async () => {
3145
- codeConfig.value = await services?.codeBlockService.getCodeContentById(id.value) || null;
3639
+ codeConfig.value = cloneDeep(await services?.codeBlockService.getCodeContentById(id.value)) || null;
3640
+ if (!codeConfig.value)
3641
+ return;
3642
+ codeConfig.value.content = serializeConfig(codeConfig.value.content);
3146
3643
  });
3147
3644
  watchEffect(async () => {
3148
3645
  const codeDsl = await services?.codeBlockService.getCodeDslByIds(selectedIds.value) || null;
@@ -3157,159 +3654,43 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
3157
3654
  });
3158
3655
  currentTitle.value = state.codeList[0]?.name || "";
3159
3656
  });
3160
- const saveCode = async () => {
3161
- if (!codeEditor.value || !codeConfig.value || !editable.value)
3162
- return true;
3163
- try {
3164
- const codeContent = codeEditor.value.getEditor()?.getValue();
3165
- codeConfig.value.content = eval(codeContent);
3166
- } catch (e) {
3167
- tMagicMessage.error(e.stack);
3168
- return false;
3169
- }
3170
- await services?.codeBlockService.setCodeDslById(id.value, {
3171
- name: codeConfig.value.name,
3172
- content: codeConfig.value.content
3173
- });
3174
- tMagicMessage.success("\u4EE3\u7801\u4FDD\u5B58\u6210\u529F");
3175
- return true;
3176
- };
3177
- const saveAndClose = async () => {
3178
- const saveRes = await saveCode();
3179
- if (saveRes) {
3180
- await services?.codeBlockService.setCodeEditorShowStatus(false);
3181
- }
3182
- };
3183
- const selectHandler = (data) => {
3184
- services?.codeBlockService.setId(data.id);
3185
- currentTitle.value = data.name;
3186
- };
3187
3657
  return (_ctx, _cache) => {
3188
3658
  return openBlock(), createBlock(unref(TMagicDialog), {
3189
- modelValue: unref(isShowCodeBlockEditor),
3190
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(isShowCodeBlockEditor) ? isShowCodeBlockEditor.value = $event : null),
3659
+ "model-value": true,
3191
3660
  class: "code-editor-dialog",
3192
3661
  title: currentTitle.value,
3193
3662
  fullscreen: true,
3194
- "before-close": saveAndClose,
3195
- "append-to-body": true
3663
+ "close-on-press-escape": false,
3664
+ "append-to-body": true,
3665
+ "show-close": false
3196
3666
  }, {
3197
3667
  default: withCtx(() => [
3198
- createVNode(_sfc_main$l, {
3668
+ createVNode(_sfc_main$n, {
3199
3669
  left: left.value,
3200
- "onUpdate:left": _cache[1] || (_cache[1] = ($event) => left.value = $event),
3670
+ "onUpdate:left": _cache[0] || (_cache[0] = ($event) => left.value = $event),
3201
3671
  "min-left": 45,
3202
3672
  class: "code-editor-layout"
3203
- }, createSlots({
3673
+ }, {
3204
3674
  center: withCtx(() => [
3205
- !unref(isEmpty)(codeConfig.value) ? (openBlock(), createElementBlock("div", {
3206
- key: 0,
3207
- class: normalizeClass([
3208
- unref(mode) === unref(CodeEditorMode).LIST ? "m-editor-code-block-editor-panel-list-mode" : "m-editor-code-block-editor-panel"
3209
- ])
3210
- }, [
3211
- renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id: unref(id) }),
3212
- createVNode(unref(TMagicCard), { shadow: "never" }, {
3213
- header: withCtx(() => [
3214
- createElementVNode("div", _hoisted_4$1, [
3215
- _hoisted_5$1,
3216
- codeConfig.value ? (openBlock(), createBlock(unref(TMagicInput), {
3217
- key: 0,
3218
- class: "code-name-input",
3219
- modelValue: codeConfig.value.name,
3220
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeConfig.value.name = $event),
3221
- disabled: !unref(editable)
3222
- }, null, 8, ["modelValue", "disabled"])) : createCommentVNode("", true)
3223
- ])
3224
- ]),
3225
- default: withCtx(() => [
3226
- createElementVNode("div", _hoisted_6$1, [
3227
- codeConfig.value ? (openBlock(), createBlock(_sfc_main$p, {
3228
- key: 0,
3229
- ref_key: "codeEditor",
3230
- ref: codeEditor,
3231
- class: "m-editor-container",
3232
- "init-values": `${codeConfig.value.content}`,
3233
- onSave: saveCode,
3234
- options: {
3235
- tabSize: 2,
3236
- fontSize: 16,
3237
- formatOnPaste: true,
3238
- readOnly: !unref(editable)
3239
- }
3240
- }, null, 8, ["init-values", "options"])) : createCommentVNode("", true),
3241
- unref(editable) ? (openBlock(), createElementBlock("div", _hoisted_7$1, [
3242
- createVNode(unref(TMagicButton), {
3243
- type: "primary",
3244
- class: "button",
3245
- onClick: saveCode
3246
- }, {
3247
- default: withCtx(() => [
3248
- _hoisted_8$1
3249
- ]),
3250
- _: 1
3251
- }),
3252
- createVNode(unref(TMagicButton), {
3253
- type: "primary",
3254
- class: "button",
3255
- onClick: saveAndClose
3256
- }, {
3257
- default: withCtx(() => [
3258
- _hoisted_9$1
3259
- ]),
3260
- _: 1
3261
- })
3262
- ])) : (openBlock(), createElementBlock("div", _hoisted_10, [
3263
- createVNode(unref(TMagicButton), {
3264
- type: "primary",
3265
- class: "button",
3266
- onClick: saveAndClose
3267
- }, {
3268
- default: withCtx(() => [
3269
- _hoisted_11
3270
- ]),
3271
- _: 1
3272
- })
3273
- ]))
3274
- ])
3275
- ]),
3276
- _: 1
3277
- })
3278
- ], 2)) : createCommentVNode("", true)
3279
- ]),
3280
- _: 2
3281
- }, [
3282
- unref(mode) === unref(CodeEditorMode).LIST ? {
3283
- name: "left",
3284
- fn: withCtx(() => [
3285
- !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(unref(TMagicTree), {
3675
+ !unref(isEmpty)(codeConfig.value) ? (openBlock(), createElementBlock("div", _hoisted_1$7, [
3676
+ renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id: unref(id) }),
3677
+ codeConfig.value ? (openBlock(), createBlock(_sfc_main$g, {
3286
3678
  key: 0,
3287
- class: "side-tree",
3288
- "node-key": "id",
3289
- "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3290
- data: state.codeList,
3291
- "highlight-current": true,
3292
- "current-node-key": state.codeList[0].id,
3293
- onNodeClick: selectHandler
3294
- }, {
3295
- default: withCtx(({ data }) => [
3296
- createElementVNode("div", {
3297
- id: data.id,
3298
- class: "list-container"
3299
- }, [
3300
- createElementVNode("div", _hoisted_2$3, [
3301
- createElementVNode("div", _hoisted_3$1, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1)
3302
- ])
3303
- ], 8, _hoisted_1$7)
3304
- ]),
3305
- _: 1
3306
- }, 8, ["data", "current-node-key"])) : createCommentVNode("", true)
3307
- ])
3308
- } : void 0
3309
- ]), 1032, ["left"])
3679
+ id: unref(id),
3680
+ name: codeConfig.value.name,
3681
+ content: codeConfig.value.content,
3682
+ paramsColConfig: __props.paramsColConfig,
3683
+ editable: !!unref(editable),
3684
+ autoSaveDraft: true,
3685
+ codeOptions: unref(codeOptions)
3686
+ }, null, 8, ["id", "name", "content", "paramsColConfig", "editable", "codeOptions"])) : createCommentVNode("", true)
3687
+ ])) : createCommentVNode("", true)
3688
+ ]),
3689
+ _: 3
3690
+ }, 8, ["left"])
3310
3691
  ]),
3311
3692
  _: 3
3312
- }, 8, ["modelValue", "title"]);
3693
+ }, 8, ["title"]);
3313
3694
  };
3314
3695
  }
3315
3696
  });
@@ -3336,50 +3717,51 @@ const _hoisted_9 = /* @__PURE__ */ createElementVNode("svg", {
3336
3717
  d: "M609.408 149.376 277.76 489.6a32 32 0 0 0 0 44.672l331.648 340.352a29.12 29.12 0 0 0 41.728 0 30.592 30.592 0 0 0 0-42.752L339.264 511.936l311.872-319.872a30.592 30.592 0 0 0 0-42.688 29.12 29.12 0 0 0-41.728 0z"
3337
3718
  })
3338
3719
  ], -1);
3339
- const _sfc_main$f = /* @__PURE__ */ defineComponent({
3340
- __name: "CodeBlockList",
3720
+ const __default__$d = defineComponent({
3721
+ name: "MEditorCodeBlockList"
3722
+ });
3723
+ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3724
+ ...__default__$d,
3341
3725
  props: {
3342
- customError: null
3726
+ customError: null,
3727
+ paramsColConfig: null
3343
3728
  },
3344
3729
  setup(__props) {
3345
3730
  const props = __props;
3346
3731
  const services = inject("services");
3347
3732
  const state = reactive({
3348
- codeList: [],
3349
- bindComps: {}
3733
+ codeList: []
3350
3734
  });
3351
3735
  const editable = computed(() => services?.codeBlockService.getEditStatus());
3352
- const getBindCompsByCodeId = (codeId, codeBlockContent) => {
3353
- if (isEmpty(codeBlockContent) || isEmpty(codeBlockContent.comps)) {
3354
- state.bindComps[codeId] = [];
3355
- return;
3356
- }
3357
- const compsField = codeBlockContent.comps;
3358
- const bindCompIds = Object.keys(compsField);
3359
- const bindCompsFiltered = bindCompIds.filter((compId) => !isEmpty(compsField[compId]));
3360
- const compsInfo = bindCompsFiltered.map((compId) => ({
3361
- id: compId,
3362
- name: getCompName(compId)
3736
+ const isShowCodeBlockEditor = computed(() => services?.codeBlockService.getCodeEditorShowStatus() || false);
3737
+ const codeCombineInfo = ref(null);
3738
+ const getBindCompsByCodeId = (codeId) => {
3739
+ if (!codeCombineInfo.value || !codeCombineInfo.value[codeId])
3740
+ return [];
3741
+ const bindCompsId = Object.keys(codeCombineInfo.value[codeId]);
3742
+ return bindCompsId.map((compId) => ({
3743
+ compId,
3744
+ compName: getCompName(compId)
3363
3745
  }));
3364
- state.bindComps[codeId] = compsInfo;
3365
3746
  };
3366
3747
  const initList = async () => {
3367
- const codeDsl = await services?.codeBlockService.getCodeDsl() || null;
3368
- if (!codeDsl)
3748
+ const codeDsl = cloneDeep(await services?.codeBlockService.getCodeDsl()) || null;
3749
+ codeCombineInfo.value = cloneDeep(services?.codeBlockService.getCombineInfo()) || null;
3750
+ if (!codeDsl || !codeCombineInfo.value)
3369
3751
  return;
3370
3752
  state.codeList = [];
3371
3753
  forIn(codeDsl, (value, codeId) => {
3372
- getBindCompsByCodeId(codeId, value);
3373
3754
  state.codeList.push({
3374
3755
  id: codeId,
3375
3756
  name: value.name,
3376
3757
  codeBlockContent: value,
3377
- showRelation: true
3758
+ showRelation: true,
3759
+ combineInfo: getBindCompsByCodeId(codeId)
3378
3760
  });
3379
3761
  });
3380
3762
  };
3381
3763
  watch(
3382
- () => services?.codeBlockService.getCodeDsl(),
3764
+ [() => services?.codeBlockService.getCodeDslSync(), () => services?.codeBlockService.refreshCombineInfo()],
3383
3765
  () => {
3384
3766
  initList();
3385
3767
  },
@@ -3388,20 +3770,6 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3388
3770
  deep: true
3389
3771
  }
3390
3772
  );
3391
- watch(
3392
- () => services?.editorService.get("node"),
3393
- (curNode) => {
3394
- if (!curNode?.id)
3395
- return;
3396
- forIn(state.bindComps, (bindCompInfo) => {
3397
- bindCompInfo.forEach((comp) => {
3398
- if (comp.id === curNode.id) {
3399
- comp.name = curNode.name;
3400
- }
3401
- });
3402
- });
3403
- }
3404
- );
3405
3773
  const createCodeBlock = async () => {
3406
3774
  const { codeBlockService } = services || {};
3407
3775
  if (!codeBlockService) {
@@ -3410,21 +3778,21 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3410
3778
  }
3411
3779
  const codeConfig = {
3412
3780
  name: "\u4EE3\u7801\u5757",
3413
- content: `() => {
3781
+ content: `({app, params}) => {
3414
3782
  // place your code here
3415
- }`
3783
+ }`,
3784
+ params: []
3416
3785
  };
3417
- await codeBlockService.setMode(CodeEditorMode.EDITOR);
3418
3786
  const id = await codeBlockService.getUniqueId();
3419
3787
  await codeBlockService.setCodeDslById(id, codeConfig);
3420
3788
  codeBlockService.setCodeEditorContent(true, id);
3421
3789
  };
3422
3790
  const editCode = async (key) => {
3423
- await services?.codeBlockService.setMode(CodeEditorMode.EDITOR);
3424
3791
  services?.codeBlockService.setCodeEditorContent(true, key);
3425
3792
  };
3426
3793
  const deleteCode = (key) => {
3427
- const existBinds = !!(state.bindComps[key]?.length > 0);
3794
+ const currentCode = state.codeList.find((codeItem) => codeItem.id === key);
3795
+ const existBinds = !isEmpty(currentCode?.combineInfo);
3428
3796
  const undeleteableList = services?.codeBlockService.getUndeletableList() || [];
3429
3797
  if (!existBinds && !undeleteableList.includes(key)) {
3430
3798
  services?.codeBlockService.deleteCodeDslByIds([key]);
@@ -3490,110 +3858,121 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3490
3858
  })) : createCommentVNode("", true)
3491
3859
  ])
3492
3860
  ]),
3493
- !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(unref(TMagicTree), {
3494
- key: 0,
3495
- ref_key: "tree",
3496
- ref: tree,
3497
- "node-key": "id",
3498
- "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3499
- data: state.codeList,
3500
- "highlight-current": true,
3501
- "filter-node-method": filterNode,
3502
- onNodeClick: toggleCombineRelation
3503
- }, {
3504
- default: withCtx(({ data }) => [
3505
- createElementVNode("div", {
3506
- id: data.id,
3507
- class: "list-container"
3508
- }, [
3509
- createElementVNode("div", _hoisted_5, [
3510
- createElementVNode("div", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
3511
- createElementVNode("div", _hoisted_7, [
3512
- createVNode(unref(TMagicTooltip), {
3513
- effect: "dark",
3514
- content: unref(editable) ? "\u7F16\u8F91" : "\u67E5\u770B",
3515
- placement: "bottom"
3516
- }, {
3517
- default: withCtx(() => [
3518
- createVNode(_sfc_main$o, {
3519
- icon: unref(editable) ? unref(Edit) : unref(View),
3520
- class: "edit-icon",
3521
- onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
3522
- }, null, 8, ["icon", "onClick"])
3523
- ]),
3524
- _: 2
3525
- }, 1032, ["content"]),
3526
- state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createBlock(unref(TMagicTooltip), {
3527
- key: 0,
3528
- effect: "dark",
3529
- content: "\u67E5\u770B\u7ED1\u5B9A\u5173\u7CFB",
3530
- placement: "bottom"
3531
- }, {
3532
- default: withCtx(() => [
3533
- createVNode(_sfc_main$o, {
3534
- icon: unref(Link),
3535
- class: "edit-icon",
3536
- onClick: withModifiers(($event) => toggleCombineRelation(data), ["stop"])
3537
- }, null, 8, ["icon", "onClick"])
3538
- ]),
3539
- _: 2
3540
- }, 1024)) : createCommentVNode("", true),
3541
- unref(editable) ? (openBlock(), createBlock(unref(TMagicTooltip), {
3542
- key: 1,
3543
- effect: "dark",
3544
- content: "\u5220\u9664",
3545
- placement: "bottom"
3546
- }, {
3547
- default: withCtx(() => [
3548
- createVNode(_sfc_main$o, {
3549
- icon: unref(Close),
3550
- class: "edit-icon",
3551
- onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
3552
- }, null, 8, ["icon", "onClick"])
3553
- ]),
3554
- _: 2
3555
- }, 1024)) : createCommentVNode("", true),
3556
- renderSlot(_ctx.$slots, "code-block-panel-tool", {
3557
- id: data.id,
3558
- data: data.codeBlockContent
3559
- })
3560
- ])
3861
+ createVNode(unref(TMagicScrollbar), null, {
3862
+ default: withCtx(() => [
3863
+ !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(unref(TMagicTree), {
3864
+ key: 0,
3865
+ ref_key: "tree",
3866
+ ref: tree,
3867
+ "node-key": "id",
3868
+ "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3869
+ data: state.codeList,
3870
+ "highlight-current": true,
3871
+ "filter-node-method": filterNode,
3872
+ onNodeClick: toggleCombineRelation
3873
+ }, {
3874
+ default: withCtx(({ data }) => [
3875
+ createElementVNode("div", {
3876
+ id: data.id,
3877
+ class: "list-container"
3878
+ }, [
3879
+ createElementVNode("div", _hoisted_5, [
3880
+ createElementVNode("span", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
3881
+ createElementVNode("div", _hoisted_7, [
3882
+ createVNode(unref(TMagicTooltip), {
3883
+ effect: "dark",
3884
+ content: unref(editable) ? "\u7F16\u8F91" : "\u67E5\u770B",
3885
+ placement: "bottom"
3886
+ }, {
3887
+ default: withCtx(() => [
3888
+ createVNode(_sfc_main$s, {
3889
+ icon: unref(editable) ? unref(Edit) : unref(View),
3890
+ class: "edit-icon",
3891
+ onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
3892
+ }, null, 8, ["icon", "onClick"])
3893
+ ]),
3894
+ _: 2
3895
+ }, 1032, ["content"]),
3896
+ data.combineInfo && data.combineInfo.length > 0 ? (openBlock(), createBlock(unref(TMagicTooltip), {
3897
+ key: 0,
3898
+ effect: "dark",
3899
+ content: "\u67E5\u770B\u7ED1\u5B9A\u5173\u7CFB",
3900
+ placement: "bottom"
3901
+ }, {
3902
+ default: withCtx(() => [
3903
+ createVNode(_sfc_main$s, {
3904
+ icon: unref(Link),
3905
+ class: "edit-icon",
3906
+ onClick: withModifiers(($event) => toggleCombineRelation(data), ["stop"])
3907
+ }, null, 8, ["icon", "onClick"])
3908
+ ]),
3909
+ _: 2
3910
+ }, 1024)) : createCommentVNode("", true),
3911
+ unref(editable) ? (openBlock(), createBlock(unref(TMagicTooltip), {
3912
+ key: 1,
3913
+ effect: "dark",
3914
+ content: "\u5220\u9664",
3915
+ placement: "bottom"
3916
+ }, {
3917
+ default: withCtx(() => [
3918
+ createVNode(_sfc_main$s, {
3919
+ icon: unref(Close),
3920
+ class: "edit-icon",
3921
+ onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
3922
+ }, null, 8, ["icon", "onClick"])
3923
+ ]),
3924
+ _: 2
3925
+ }, 1024)) : createCommentVNode("", true),
3926
+ renderSlot(_ctx.$slots, "code-block-panel-tool", {
3927
+ id: data.id,
3928
+ data: data.codeBlockContent
3929
+ })
3930
+ ])
3931
+ ]),
3932
+ data.showRelation && data.combineInfo && data.combineInfo.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
3933
+ _hoisted_9,
3934
+ (openBlock(true), createElementBlock(Fragment, null, renderList(data.combineInfo, (comp, index) => {
3935
+ return openBlock(), createBlock(unref(TMagicButton), {
3936
+ key: index,
3937
+ class: "code-comp",
3938
+ size: "small",
3939
+ plain: true,
3940
+ onClick: withModifiers(($event) => selectComp(comp.compId), ["stop"])
3941
+ }, {
3942
+ default: withCtx(() => [
3943
+ createTextVNode(toDisplayString(comp.compName), 1)
3944
+ ]),
3945
+ _: 2
3946
+ }, 1032, ["onClick"]);
3947
+ }), 128))
3948
+ ])) : createCommentVNode("", true)
3949
+ ], 8, _hoisted_4)
3561
3950
  ]),
3562
- data.showRelation && state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
3563
- _hoisted_9,
3564
- (openBlock(true), createElementBlock(Fragment, null, renderList(state.bindComps[data.id], (comp, index) => {
3565
- return openBlock(), createBlock(unref(TMagicButton), {
3566
- key: index,
3567
- class: "code-comp",
3568
- size: "small",
3569
- plain: true,
3570
- onClick: withModifiers(($event) => selectComp(comp.id), ["stop"])
3571
- }, {
3572
- default: withCtx(() => [
3573
- createTextVNode(toDisplayString(comp.name), 1)
3574
- ]),
3575
- _: 2
3576
- }, 1032, ["onClick"]);
3577
- }), 128))
3578
- ])) : createCommentVNode("", true)
3579
- ], 8, _hoisted_4)
3951
+ _: 3
3952
+ }, 8, ["data"])) : createCommentVNode("", true)
3580
3953
  ]),
3581
3954
  _: 3
3582
- }, 8, ["data"])) : createCommentVNode("", true),
3583
- createVNode(_sfc_main$g, null, {
3955
+ }),
3956
+ unref(isShowCodeBlockEditor) ? (openBlock(), createBlock(_sfc_main$f, {
3957
+ key: 0,
3958
+ paramsColConfig: __props.paramsColConfig
3959
+ }, {
3584
3960
  "code-block-edit-panel-header": withCtx(({ id }) => [
3585
3961
  renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
3586
3962
  ]),
3587
3963
  _: 3
3588
- })
3964
+ }, 8, ["paramsColConfig"])) : createCommentVNode("", true)
3589
3965
  ]);
3590
3966
  };
3591
3967
  }
3592
3968
  });
3593
3969
 
3594
3970
  const _hoisted_1$5 = ["onClick", "onDragstart"];
3595
- const _sfc_main$e = /* @__PURE__ */ defineComponent({
3596
- __name: "ComponentListPanel",
3971
+ const __default__$c = defineComponent({
3972
+ name: "MEditorComponentListPanel"
3973
+ });
3974
+ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3975
+ ...__default__$c,
3597
3976
  setup(__props) {
3598
3977
  const searchText = ref("");
3599
3978
  const services = inject("services");
@@ -3682,7 +4061,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3682
4061
  name: `${index}`
3683
4062
  }, {
3684
4063
  title: withCtx(() => [
3685
- createVNode(_sfc_main$o, { icon: unref(Grid) }, null, 8, ["icon"]),
4064
+ createVNode(_sfc_main$s, { icon: unref(Grid) }, null, 8, ["icon"]),
3686
4065
  createTextVNode(toDisplayString(group.title), 1)
3687
4066
  ]),
3688
4067
  default: withCtx(() => [
@@ -3697,7 +4076,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3697
4076
  onDrag: dragHandler
3698
4077
  }, [
3699
4078
  renderSlot(_ctx.$slots, "component-list-item", { component: item }, () => [
3700
- createVNode(_sfc_main$o, {
4079
+ createVNode(_sfc_main$s, {
3701
4080
  icon: item.icon
3702
4081
  }, null, 8, ["icon"]),
3703
4082
  createVNode(unref(TMagicTooltip), {
@@ -3728,8 +4107,11 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3728
4107
  }
3729
4108
  });
3730
4109
 
3731
- const _sfc_main$d = /* @__PURE__ */ defineComponent({
3732
- __name: "ContentMenu",
4110
+ const __default__$b = defineComponent({
4111
+ name: "MEditorContentMenu"
4112
+ });
4113
+ const _sfc_main$c = /* @__PURE__ */ defineComponent({
4114
+ ...__default__$b,
3733
4115
  props: {
3734
4116
  menuData: { default: () => [] },
3735
4117
  isSubMenu: { type: Boolean, default: false }
@@ -3817,7 +4199,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3817
4199
  }, [
3818
4200
  createElementVNode("div", null, [
3819
4201
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.menuData, (item, index) => {
3820
- return openBlock(), createBlock(_sfc_main$j, {
4202
+ return openBlock(), createBlock(_sfc_main$k, {
3821
4203
  "event-type": "mouseup",
3822
4204
  data: item,
3823
4205
  key: index,
@@ -3843,16 +4225,22 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3843
4225
  }
3844
4226
  });
3845
4227
 
3846
- const _sfc_main$c = /* @__PURE__ */ defineComponent({
3847
- __name: "LayerMenu",
4228
+ const __default__$a = defineComponent({
4229
+ name: "MEditorLayerMenu"
4230
+ });
4231
+ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4232
+ ...__default__$a,
4233
+ props: {
4234
+ layerContentMenu: null
4235
+ },
3848
4236
  setup(__props, { expose }) {
4237
+ const props = __props;
3849
4238
  const services = inject("services");
3850
4239
  const menu = ref();
3851
4240
  const node = computed(() => services?.editorService.get("node"));
3852
4241
  const isRoot = computed(() => node.value?.type === NodeType.ROOT);
3853
4242
  const isPage = computed(() => node.value?.type === NodeType.PAGE);
3854
4243
  const componentList = computed(() => services?.componentListService.getList() || []);
3855
- const layerContentMenu = inject("layerContentMenu", []);
3856
4244
  const createMenuItems = (group) => group.items.map((component) => ({
3857
4245
  text: component.text,
3858
4246
  type: "button",
@@ -3907,7 +4295,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3907
4295
  {
3908
4296
  type: "button",
3909
4297
  text: "\u590D\u5236",
3910
- icon: markRaw(DocumentCopy),
4298
+ icon: markRaw(CopyDocument),
3911
4299
  display: () => !isRoot.value,
3912
4300
  handler: () => {
3913
4301
  node.value && services?.editorService.copy(node.value);
@@ -3922,7 +4310,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3922
4310
  node.value && services?.editorService.remove(node.value);
3923
4311
  }
3924
4312
  },
3925
- ...layerContentMenu
4313
+ ...props.layerContentMenu
3926
4314
  ]);
3927
4315
  const show = (e) => {
3928
4316
  menu.value?.show(e);
@@ -3931,7 +4319,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3931
4319
  show
3932
4320
  });
3933
4321
  return (_ctx, _cache) => {
3934
- return openBlock(), createBlock(_sfc_main$d, {
4322
+ return openBlock(), createBlock(_sfc_main$c, {
3935
4323
  "menu-data": unref(menuData),
3936
4324
  ref_key: "menu",
3937
4325
  ref: menu,
@@ -3942,27 +4330,42 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3942
4330
  });
3943
4331
 
3944
4332
  const _hoisted_1$4 = ["id", "onMouseenter"];
3945
- const _sfc_main$b = /* @__PURE__ */ defineComponent({
3946
- __name: "LayerPanel",
4333
+ const __default__$9 = defineComponent({
4334
+ name: "MEditorLayerPanel"
4335
+ });
4336
+ const _sfc_main$a = /* @__PURE__ */ defineComponent({
4337
+ ...__default__$9,
4338
+ props: {
4339
+ layerContentMenu: null
4340
+ },
3947
4341
  setup(__props) {
3948
4342
  const throttleTime = 150;
3949
4343
  const services = inject("services");
4344
+ const editorService = services?.editorService;
3950
4345
  const tree = ref();
3951
4346
  const menu = ref();
3952
- const editorService = services?.editorService;
4347
+ const checkedKeys = ref([]);
4348
+ const isCtrlKeyDown = ref(false);
4349
+ const filterText = ref("");
4350
+ const expandedKeys = ref([]);
4351
+ const currentNodeKey = ref();
4352
+ const clicked = ref(false);
4353
+ const treeProps = {
4354
+ children: "items",
4355
+ disabled: (data) => Boolean(data.items?.length),
4356
+ class: (data) => {
4357
+ if (clicked.value || isPage(data))
4358
+ return "";
4359
+ if (data.id === highlightNode?.value?.id && !checkedKeys.value.includes(data.id)) {
4360
+ return "cus-tree-node-hover";
4361
+ }
4362
+ }
4363
+ };
4364
+ const isMultiSelect = computed(() => isCtrlKeyDown.value || checkedKeys.value.length > 1);
4365
+ const nodes = computed(() => editorService?.get("nodes") || []);
3953
4366
  const page = computed(() => editorService?.get("page"));
3954
4367
  const values = computed(() => page.value ? [page.value] : []);
3955
- const selectedNodes = ref([]);
3956
- const selectedIds = computed(() => selectedNodes.value.map((node) => node.id));
3957
- const isMultiSelectStatus = ref(false);
3958
- const spliceNodeKey = ref();
3959
- const filterText = ref("");
3960
- const defaultExpandedKeys = computed(() => selectedIds.value.length > 0 ? selectedIds.value : []);
3961
- editorService?.on("remove", () => {
3962
- setTimeout(() => {
3963
- tree.value?.getNode(editorService.get("node").id)?.updateChildren();
3964
- }, 0);
3965
- });
4368
+ const highlightNode = computed(() => editorService?.get("highlightNode"));
3966
4369
  const select = async (data) => {
3967
4370
  if (!data.id) {
3968
4371
  throw new Error("\u6CA1\u6709id");
@@ -3981,7 +4384,6 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
3981
4384
  editorService?.highlight(data);
3982
4385
  editorService?.get("stage")?.highlight(data.id);
3983
4386
  };
3984
- const expandedKeys = /* @__PURE__ */ new Map();
3985
4387
  const allowDrop = (draggingNode, dropNode, type) => {
3986
4388
  const { data } = dropNode || {};
3987
4389
  const { data: ingData } = draggingNode;
@@ -4013,23 +4415,18 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4013
4415
  const [page2] = data;
4014
4416
  editorService?.update(page2);
4015
4417
  };
4016
- const loadItems = (node, resolve) => {
4017
- if (Array.isArray(node.data)) {
4018
- return resolve(node.data);
4019
- }
4020
- if (Array.isArray(node.data?.items)) {
4021
- return resolve(node.data?.items);
4022
- }
4023
- resolve([]);
4024
- };
4025
4418
  const handleCollapse = (data) => {
4026
- expandedKeys.delete(data.id);
4419
+ expandedKeys.value = expandedKeys.value.filter((id) => id !== data.id);
4027
4420
  };
4028
4421
  const handleExpand = (data) => {
4029
- const parent = editorService?.getParentById(data.id);
4030
- if (!parent?.id)
4422
+ if (!page.value) {
4423
+ expandedKeys.value = [];
4031
4424
  return;
4032
- expandedKeys.set(parent.id, parent.id);
4425
+ }
4426
+ expandedKeys.value = union(
4427
+ expandedKeys.value,
4428
+ getNodePath(data.id, [page.value]).map((node) => node.id)
4429
+ );
4033
4430
  };
4034
4431
  const filterNode = (value, data) => {
4035
4432
  if (!value) {
@@ -4046,121 +4443,78 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4046
4443
  const filterTextChangeHandler = (val) => {
4047
4444
  tree.value?.filter(val);
4048
4445
  };
4049
- const expandNodes = async () => {
4050
- if (!tree.value)
4051
- return;
4052
- await nextTick();
4053
- tree.value && Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]) => {
4054
- if (node.expanded && node.data.items) {
4055
- expandedKeys.set(id, id);
4056
- }
4057
- });
4058
- expandedKeys.forEach((key) => {
4059
- if (!tree.value)
4060
- return;
4061
- tree.value.getNode(key)?.expand();
4062
- });
4063
- };
4064
- watch(
4065
- () => editorService?.get("nodes"),
4066
- (nodes) => {
4067
- selectedNodes.value = nodes ?? [];
4446
+ watch(nodes, (nodes2) => {
4447
+ const ids = nodes2?.map((node) => node.id) || [];
4448
+ const idsLength = ids.length;
4449
+ const checkedKeysLength = checkedKeys.value.length;
4450
+ if (difference(
4451
+ idsLength > checkedKeysLength ? ids : checkedKeys.value,
4452
+ idsLength > checkedKeysLength ? checkedKeys.value : ids
4453
+ ).length) {
4454
+ tree.value?.setCheckedKeys([], false);
4455
+ [currentNodeKey.value] = ids;
4456
+ checkedKeys.value = ids.filter((id) => id !== page.value?.id);
4457
+ expandedKeys.value = union(expandedKeys.value, ids);
4068
4458
  }
4069
- );
4070
- const setTreeKeyStatus = () => {
4071
- if (!tree.value)
4072
- return;
4073
- if (selectedIds.value.length === 0) {
4074
- tree.value.setCheckedKeys([]);
4075
- tree.value.setCurrentKey();
4076
- } else if (selectedIds.value.length === 1 && !isMultiSelectStatus.value) {
4077
- tree.value.setCurrentKey(selectedIds.value[0], true);
4078
- tree.value.setCheckedKeys([]);
4079
- } else {
4080
- tree.value.setCheckedKeys(selectedIds.value);
4081
- tree.value.setCurrentKey();
4459
+ });
4460
+ watch(isMultiSelect, (isMultiSelect2) => {
4461
+ if (!isMultiSelect2) {
4462
+ currentNodeKey.value = editorService?.get("node")?.id;
4463
+ tree.value?.setCurrentKey(currentNodeKey.value);
4082
4464
  }
4083
- };
4084
- watch([selectedIds, tree], async () => {
4085
- if (!tree.value || !editorService)
4086
- return;
4087
- const parent = editorService.get("parent");
4088
- if (!parent?.id)
4089
- return;
4090
- const treeNode = tree.value.getNode(parent.id);
4091
- treeNode?.updateChildren();
4092
- await expandNodes();
4093
- setTreeKeyStatus();
4094
4465
  });
4095
- const keycon = ref();
4096
- const addSelectModeListener = () => {
4466
+ const editorServiceRemoveHandler = () => {
4467
+ setTimeout(() => {
4468
+ tree.value?.getNode(editorService?.get("node")?.id)?.updateChildren();
4469
+ }, 0);
4470
+ };
4471
+ const windowBlurHandler = () => {
4472
+ isCtrlKeyDown.value = false;
4473
+ };
4474
+ let keycon;
4475
+ onMounted(() => {
4476
+ editorService?.on("remove", editorServiceRemoveHandler);
4477
+ keycon = new KeyController();
4097
4478
  const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
4098
4479
  const ctrl = isMac ? "meta" : "ctrl";
4099
- keycon.value = new KeyController();
4100
- keycon.value.keydown(ctrl, (e) => {
4101
- e.inputEvent.preventDefault();
4102
- isMultiSelectStatus.value = true;
4103
- });
4104
- keycon.value.on("blur", () => {
4105
- isMultiSelectStatus.value = false;
4106
- });
4107
- keycon.value.keyup(ctrl, (e) => {
4108
- e.inputEvent.preventDefault();
4109
- isMultiSelectStatus.value = false;
4480
+ keycon.keydown((e) => {
4481
+ if (e.key !== ctrl) {
4482
+ isCtrlKeyDown.value = false;
4483
+ }
4484
+ }).keydown(ctrl, () => {
4485
+ isCtrlKeyDown.value = true;
4486
+ }).keyup(ctrl, () => {
4487
+ isCtrlKeyDown.value = false;
4110
4488
  });
4111
- };
4112
- const removeSelectModeListener = () => {
4113
- keycon.value?.destroy();
4114
- if (selectedIds.value.length === 1)
4115
- isMultiSelectStatus.value = false;
4116
- };
4117
- const clicked = ref(false);
4118
- const highlightNode = computed(() => editorService?.get("highlightNode"));
4489
+ globalThis.addEventListener("blur", windowBlurHandler);
4490
+ });
4491
+ onUnmounted(() => {
4492
+ keycon.destroy();
4493
+ editorService?.off("remove", editorServiceRemoveHandler);
4494
+ globalThis.removeEventListener("blur", windowBlurHandler);
4495
+ });
4119
4496
  const highlightHandler = throttle((data) => {
4120
4497
  highlight(data);
4121
4498
  }, throttleTime);
4122
4499
  const toggleClickFlag = () => {
4123
4500
  clicked.value = !clicked.value;
4124
4501
  };
4125
- const canHighlight = (data) => {
4126
- if (clicked.value)
4127
- return false;
4128
- return data.id === highlightNode?.value?.id && !selectedIds.value.includes(data.id) && spliceNodeKey.value !== data.id;
4129
- };
4130
- watch(isMultiSelectStatus, () => {
4131
- if (isMultiSelectStatus.value && selectedNodes.value.length === 1 && selectedNodes.value[0].type === NodeType.PAGE) {
4132
- selectedNodes.value = [];
4133
- }
4134
- });
4135
- const multiClickHandler = (data) => {
4136
- if (!data?.id) {
4137
- throw new Error("\u6CA1\u6709id");
4138
- }
4139
- if (data.type === NodeType.PAGE) {
4140
- tree.value?.setCheckedKeys([]);
4141
- return;
4142
- }
4143
- const index = selectedNodes.value.findIndex((node) => node.id === data.id);
4144
- if (index !== -1) {
4145
- selectedNodes.value.splice(index, 1);
4146
- spliceNodeKey.value = data.id;
4502
+ const checkHandler = (data, { checkedNodes }) => {
4503
+ if (checkedNodes.length > 0) {
4504
+ multiSelect(checkedNodes.map((node) => node.id));
4147
4505
  } else {
4148
- selectedNodes.value = [...selectedNodes.value, data];
4506
+ multiSelect(nodes.value.map((node) => node.id));
4149
4507
  }
4150
- tree.value?.setCheckedKeys(selectedIds.value);
4151
- multiSelect(selectedIds.value);
4152
4508
  };
4153
4509
  const clickHandler = (data) => {
4154
- if (!isMultiSelectStatus.value) {
4155
- if (services?.uiService.get("uiSelectMode")) {
4156
- document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
4157
- return;
4158
- }
4159
- tree.value?.setCurrentKey(data.id);
4160
- select(data);
4161
- } else {
4162
- multiClickHandler(data);
4510
+ if (isCtrlKeyDown.value) {
4511
+ return;
4512
+ }
4513
+ if (services?.uiService.get("uiSelectMode")) {
4514
+ document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
4515
+ return;
4163
4516
  }
4517
+ select(data);
4164
4518
  };
4165
4519
  const contextmenu = async (event, data) => {
4166
4520
  event.preventDefault();
@@ -4168,11 +4522,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4168
4522
  menu.value?.show(event);
4169
4523
  };
4170
4524
  return (_ctx, _cache) => {
4171
- return openBlock(), createBlock(unref(TMagicScrollbar), {
4172
- class: "magic-editor-layer-panel",
4173
- onMouseenter: addSelectModeListener,
4174
- onMouseleave: removeSelectModeListener
4175
- }, {
4525
+ return openBlock(), createBlock(unref(TMagicScrollbar), { class: "magic-editor-layer-panel" }, {
4176
4526
  default: withCtx(() => [
4177
4527
  renderSlot(_ctx.$slots, "layer-panel-header"),
4178
4528
  createVNode(unref(TMagicInput), {
@@ -4193,30 +4543,30 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4193
4543
  "node-key": "id",
4194
4544
  "empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684",
4195
4545
  draggable: "",
4196
- "default-expanded-keys": unref(defaultExpandedKeys),
4197
- load: loadItems,
4546
+ "default-expanded-keys": expandedKeys.value,
4547
+ "default-checked-keys": checkedKeys.value,
4548
+ "current-node-key": currentNodeKey.value,
4198
4549
  data: unref(values),
4199
4550
  "expand-on-click-node": false,
4200
- "highlight-current": true,
4201
- props: {
4202
- children: "items"
4203
- },
4551
+ "highlight-current": !unref(isMultiSelect),
4552
+ "check-on-click-node": true,
4553
+ props: treeProps,
4204
4554
  "filter-node-method": filterNode,
4205
4555
  "allow-drop": allowDrop,
4206
- "show-checkbox": isMultiSelectStatus.value || unref(selectedIds).length > 1,
4556
+ "show-checkbox": unref(isMultiSelect),
4207
4557
  onNodeClick: clickHandler,
4208
4558
  onNodeContextmenu: contextmenu,
4209
4559
  onNodeDragEnd: handleDragEnd,
4210
4560
  onNodeCollapse: handleCollapse,
4211
4561
  onNodeExpand: handleExpand,
4212
- onCheck: multiClickHandler,
4562
+ onCheck: checkHandler,
4213
4563
  onMousedown: toggleClickFlag,
4214
4564
  onMouseup: toggleClickFlag
4215
4565
  }, {
4216
4566
  default: withCtx(({ node, data }) => [
4217
4567
  createElementVNode("div", {
4568
+ class: "cus-tree-node",
4218
4569
  id: data.id,
4219
- class: normalizeClass(["cus-tree-node", { "cus-tree-node-hover": canHighlight(data) }]),
4220
4570
  onMouseenter: ($event) => unref(highlightHandler)(data)
4221
4571
  }, [
4222
4572
  renderSlot(_ctx.$slots, "layer-node-content", {
@@ -4225,15 +4575,16 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4225
4575
  }, () => [
4226
4576
  createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
4227
4577
  ])
4228
- ], 42, _hoisted_1$4)
4578
+ ], 40, _hoisted_1$4)
4229
4579
  ]),
4230
4580
  _: 3
4231
- }, 8, ["default-expanded-keys", "data", "show-checkbox"])) : createCommentVNode("", true),
4581
+ }, 8, ["default-expanded-keys", "default-checked-keys", "current-node-key", "data", "highlight-current", "show-checkbox"])) : createCommentVNode("", true),
4232
4582
  (openBlock(), createBlock(Teleport, { to: "body" }, [
4233
- createVNode(_sfc_main$c, {
4583
+ createVNode(_sfc_main$b, {
4234
4584
  ref_key: "menu",
4235
- ref: menu
4236
- }, null, 512)
4585
+ ref: menu,
4586
+ "layer-content-menu": __props.layerContentMenu
4587
+ }, null, 8, ["layer-content-menu"])
4237
4588
  ]))
4238
4589
  ]),
4239
4590
  _: 3
@@ -4246,143 +4597,52 @@ const _hoisted_1$3 = {
4246
4597
  key: 1,
4247
4598
  class: "magic-editor-tab-panel-title"
4248
4599
  };
4249
- const _sfc_main$a = /* @__PURE__ */ defineComponent({
4250
- __name: "TabPane",
4251
- props: {
4252
- data: null
4253
- },
4254
- setup(__props) {
4255
- const props = __props;
4256
- const config = computed(() => {
4257
- if (typeof props.data !== "string") {
4258
- return props.data;
4259
- }
4260
- switch (props.data) {
4261
- case "component-list":
4262
- return {
4263
- type: "component",
4264
- icon: Coin,
4265
- text: "\u7EC4\u4EF6",
4266
- component: _sfc_main$e,
4267
- slots: {}
4268
- };
4269
- case "layer":
4270
- return {
4271
- type: "component",
4272
- icon: Files,
4273
- text: "\u5DF2\u9009\u7EC4\u4EF6",
4274
- component: _sfc_main$b,
4275
- slots: {}
4276
- };
4277
- case "code-block":
4278
- return {
4279
- type: "component",
4280
- icon: EditPen,
4281
- text: "\u4EE3\u7801\u7F16\u8F91",
4282
- component: _sfc_main$f,
4283
- slots: {}
4284
- };
4285
- default:
4286
- return void 0;
4287
- }
4288
- });
4289
- return (_ctx, _cache) => {
4290
- return unref(config) ? (openBlock(), createBlock(unref(TMagicTabPane), {
4291
- key: 0,
4292
- name: unref(config).text
4293
- }, {
4294
- label: withCtx(() => [
4295
- (openBlock(), createElementBlock("div", {
4296
- key: unref(config).text
4297
- }, [
4298
- unref(config).icon ? (openBlock(), createBlock(_sfc_main$o, {
4299
- key: 0,
4300
- icon: unref(config).icon
4301
- }, null, 8, ["icon"])) : createCommentVNode("", true),
4302
- unref(config).text ? (openBlock(), createElementBlock("div", _hoisted_1$3, toDisplayString(unref(config).text), 1)) : createCommentVNode("", true)
4303
- ]))
4304
- ]),
4305
- default: withCtx(() => [
4306
- (openBlock(), createBlock(resolveDynamicComponent(unref(config).component), mergeProps(unref(config).props || {}, toHandlers(unref(config)?.listeners || {})), createSlots({ _: 2 }, [
4307
- __props.data === "component-list" || unref(config).slots?.componentListPanelHeader ? {
4308
- name: "component-list-panel-header",
4309
- fn: withCtx(() => [
4310
- __props.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-panel-header", { key: 0 }) : unref(config).slots?.componentListPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.componentListPanelHeader), { key: 1 })) : createCommentVNode("", true)
4311
- ])
4312
- } : void 0,
4313
- __props.data === "component-list" || unref(config).slots?.componentListItem ? {
4314
- name: "component-list-item",
4315
- fn: withCtx(({ component }) => [
4316
- __props.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
4317
- key: 0,
4318
- component
4319
- }) : unref(config).slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.componentListItem), {
4320
- key: 1,
4321
- component
4322
- }, null, 8, ["component"])) : createCommentVNode("", true)
4323
- ])
4324
- } : void 0,
4325
- __props.data === "layer" || unref(config).slots?.layerPanelHeader ? {
4326
- name: "layer-panel-header",
4327
- fn: withCtx(() => [
4328
- __props.data === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : unref(config).slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
4329
- ])
4330
- } : void 0,
4331
- __props.data === "code-block" || unref(config).slots?.codeBlockPanelHeader ? {
4332
- name: "code-block-panel-header",
4333
- fn: withCtx(() => [
4334
- __props.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-header", { key: 0 }) : unref(config).slots?.codeBlockPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockPanelHeader), { key: 1 })) : createCommentVNode("", true)
4335
- ])
4336
- } : void 0,
4337
- __props.data === "code-block" || unref(config).slots?.codeBlockPanelTool ? {
4338
- name: "code-block-panel-tool",
4339
- fn: withCtx(({ id, data }) => [
4340
- data === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
4341
- key: 0,
4342
- id,
4343
- data
4344
- }) : unref(config).slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
4345
- ])
4346
- } : void 0,
4347
- __props.data === "code-block" || unref(config).slots?.codeBlockEditPanelHeader ? {
4348
- name: "code-block-edit-panel-header",
4349
- fn: withCtx(({ id }) => [
4350
- __props.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
4351
- key: 0,
4352
- id
4353
- }) : unref(config).slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
4354
- ])
4355
- } : void 0,
4356
- __props.data === "layer" || unref(config).slots?.layerNodeContent ? {
4357
- name: "layer-node-content",
4358
- fn: withCtx(({ data: nodeData, node }) => [
4359
- __props.data === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
4360
- key: 0,
4361
- data: nodeData,
4362
- node
4363
- }) : unref(config).slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.layerNodeContent), {
4364
- key: 1,
4365
- data: nodeData,
4366
- node
4367
- }, null, 8, ["data", "node"])) : createCommentVNode("", true)
4368
- ])
4369
- } : void 0
4370
- ]), 1040))
4371
- ]),
4372
- _: 3
4373
- }, 8, ["name"])) : createCommentVNode("", true);
4374
- };
4375
- }
4600
+ const __default__$8 = defineComponent({
4601
+ name: "MEditorSidebar"
4376
4602
  });
4377
-
4378
4603
  const _sfc_main$9 = /* @__PURE__ */ defineComponent({
4379
- __name: "Sidebar",
4604
+ ...__default__$8,
4380
4605
  props: {
4381
- data: { default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer", "code-block"] }) }
4606
+ data: { default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer", "code-block"] }) },
4607
+ layerContentMenu: null
4382
4608
  },
4383
4609
  setup(__props, { expose }) {
4384
4610
  const props = __props;
4611
+ const uiComponent = getConfig$1("components").tabPane;
4385
4612
  const activeTabName = ref(props.data?.status);
4613
+ const getItemConfig = (data) => {
4614
+ const map = {
4615
+ "component-list": {
4616
+ $key: "component-list",
4617
+ type: "component",
4618
+ icon: Coin,
4619
+ text: "\u7EC4\u4EF6",
4620
+ component: _sfc_main$d,
4621
+ slots: {}
4622
+ },
4623
+ layer: {
4624
+ $key: "layer",
4625
+ type: "component",
4626
+ icon: Files,
4627
+ text: "\u5DF2\u9009\u7EC4\u4EF6",
4628
+ props: {
4629
+ layerContentMenu: props.layerContentMenu
4630
+ },
4631
+ component: _sfc_main$a,
4632
+ slots: {}
4633
+ },
4634
+ "code-block": {
4635
+ $key: "code-block",
4636
+ type: "component",
4637
+ icon: EditPen,
4638
+ text: "\u4EE3\u7801\u7F16\u8F91",
4639
+ component: _sfc_main$e,
4640
+ slots: {}
4641
+ }
4642
+ };
4643
+ return typeof data === "string" ? map[data] : data;
4644
+ };
4645
+ const sideBarItems = computed(() => props.data.items.map((item) => getItemConfig(item)));
4386
4646
  watch(
4387
4647
  () => props.data.status,
4388
4648
  (status) => {
@@ -4402,60 +4662,91 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
4402
4662
  "tab-position": "left"
4403
4663
  }, {
4404
4664
  default: withCtx(() => [
4405
- (openBlock(true), createElementBlock(Fragment, null, renderList(__props.data.items, (item, index) => {
4406
- return openBlock(), createBlock(_sfc_main$a, {
4665
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(sideBarItems), (config, index) => {
4666
+ return openBlock(), createBlock(resolveDynamicComponent(unref(uiComponent).component), {
4407
4667
  key: index,
4408
- data: item
4409
- }, createSlots({ _: 2 }, [
4410
- item === "layer" ? {
4411
- name: "layer-panel-header",
4412
- fn: withCtx(() => [
4413
- renderSlot(_ctx.$slots, "layer-panel-header")
4414
- ])
4415
- } : void 0,
4416
- item === "layer" ? {
4417
- name: "layer-node-content",
4418
- fn: withCtx(({ node, data }) => [
4419
- renderSlot(_ctx.$slots, "layer-node-content", {
4420
- data,
4421
- node
4422
- })
4423
- ])
4424
- } : void 0,
4425
- item === "component-list" ? {
4426
- name: "component-list-panel-header",
4427
- fn: withCtx(() => [
4428
- renderSlot(_ctx.$slots, "component-list-panel-header")
4429
- ])
4430
- } : void 0,
4431
- item === "component-list" ? {
4432
- name: "component-list-item",
4433
- fn: withCtx(({ component }) => [
4434
- renderSlot(_ctx.$slots, "component-list-item", { component })
4435
- ])
4436
- } : void 0,
4437
- item === "code-block" ? {
4438
- name: "code-block-panel-header",
4439
- fn: withCtx(() => [
4440
- renderSlot(_ctx.$slots, "code-block-panel-header")
4441
- ])
4442
- } : void 0,
4443
- item === "code-block" ? {
4444
- name: "code-block-panel-tool",
4445
- fn: withCtx(({ id, data }) => [
4446
- renderSlot(_ctx.$slots, "code-block-panel-tool", {
4447
- id,
4448
- data
4449
- })
4450
- ])
4451
- } : void 0,
4452
- item === "code-block" ? {
4453
- name: "code-block-edit-panel-header",
4454
- fn: withCtx(({ id }) => [
4455
- renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
4456
- ])
4457
- } : void 0
4458
- ]), 1032, ["data"]);
4668
+ name: config.text
4669
+ }, {
4670
+ label: withCtx(() => [
4671
+ (openBlock(), createElementBlock("div", {
4672
+ key: config.text
4673
+ }, [
4674
+ config.icon ? (openBlock(), createBlock(_sfc_main$s, {
4675
+ key: 0,
4676
+ icon: config.icon
4677
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
4678
+ config.text ? (openBlock(), createElementBlock("div", _hoisted_1$3, toDisplayString(config.text), 1)) : createCommentVNode("", true)
4679
+ ]))
4680
+ ]),
4681
+ default: withCtx(() => [
4682
+ config ? (openBlock(), createBlock(resolveDynamicComponent(config.component), mergeProps({ key: 0 }, config.props || {}, toHandlers(config?.listeners || {})), createSlots({ _: 2 }, [
4683
+ config.$key === "component-list" || config.slots?.componentListPanelHeader ? {
4684
+ name: "component-list-panel-header",
4685
+ fn: withCtx(() => [
4686
+ config.$key === "component-list" ? renderSlot(_ctx.$slots, "component-list-panel-header", { key: 0 }) : config.slots?.componentListPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.componentListPanelHeader), { key: 1 })) : createCommentVNode("", true)
4687
+ ])
4688
+ } : void 0,
4689
+ config.$key === "component-list" || config.slots?.componentListItem ? {
4690
+ name: "component-list-item",
4691
+ fn: withCtx(({ component }) => [
4692
+ config.$key === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
4693
+ key: 0,
4694
+ component
4695
+ }) : config.slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.componentListItem), {
4696
+ key: 1,
4697
+ component
4698
+ }, null, 8, ["component"])) : createCommentVNode("", true)
4699
+ ])
4700
+ } : void 0,
4701
+ config.$key === "layer" || config.slots?.layerPanelHeader ? {
4702
+ name: "layer-panel-header",
4703
+ fn: withCtx(() => [
4704
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : config.slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
4705
+ ])
4706
+ } : void 0,
4707
+ config.$key === "code-block" || config.slots?.codeBlockPanelHeader ? {
4708
+ name: "code-block-panel-header",
4709
+ fn: withCtx(() => [
4710
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-header", { key: 0 }) : config.slots?.codeBlockPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockPanelHeader), { key: 1 })) : createCommentVNode("", true)
4711
+ ])
4712
+ } : void 0,
4713
+ config.$key === "code-block" || config.slots?.codeBlockPanelTool ? {
4714
+ name: "code-block-panel-tool",
4715
+ fn: withCtx(({ id, data }) => [
4716
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
4717
+ key: 0,
4718
+ id,
4719
+ data
4720
+ }) : config.slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
4721
+ ])
4722
+ } : void 0,
4723
+ config.$key === "code-block" || config.slots?.codeBlockEditPanelHeader ? {
4724
+ name: "code-block-edit-panel-header",
4725
+ fn: withCtx(({ id }) => [
4726
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
4727
+ key: 0,
4728
+ id
4729
+ }) : config.slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
4730
+ ])
4731
+ } : void 0,
4732
+ config.$key === "layer" || config.slots?.layerNodeContent ? {
4733
+ name: "layer-node-content",
4734
+ fn: withCtx(({ data: nodeData, node }) => [
4735
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
4736
+ key: 0,
4737
+ data: nodeData,
4738
+ node
4739
+ }) : config.slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerNodeContent), {
4740
+ key: 1,
4741
+ data: nodeData,
4742
+ node
4743
+ }, null, 8, ["data", "node"])) : createCommentVNode("", true)
4744
+ ])
4745
+ } : void 0
4746
+ ]), 1040)) : createCommentVNode("", true)
4747
+ ]),
4748
+ _: 2
4749
+ }, 1032, ["name"]);
4459
4750
  }), 128))
4460
4751
  ]),
4461
4752
  _: 3
@@ -4469,8 +4760,11 @@ const _hoisted_1$2 = {
4469
4760
  class: "m-editor-breadcrumb"
4470
4761
  };
4471
4762
  const _hoisted_2$1 = { key: 0 };
4763
+ const __default__$7 = defineComponent({
4764
+ name: "MEditorBreadcrumb"
4765
+ });
4472
4766
  const _sfc_main$8 = /* @__PURE__ */ defineComponent({
4473
- __name: "Breadcrumb",
4767
+ ...__default__$7,
4474
4768
  setup(__props) {
4475
4769
  const services = inject("services");
4476
4770
  const editorService = services?.editorService;
@@ -4510,8 +4804,11 @@ const _hoisted_1$1 = {
4510
4804
  key: 1,
4511
4805
  style: { "width": "21px" }
4512
4806
  };
4807
+ const __default__$6 = defineComponent({
4808
+ name: "MEditorPageBarScrollContainer"
4809
+ });
4513
4810
  const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4514
- __name: "PageBarScrollContainer",
4811
+ ...__default__$6,
4515
4812
  setup(__props) {
4516
4813
  const services = inject("services");
4517
4814
  const editorService = services?.editorService;
@@ -4574,9 +4871,12 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4574
4871
  const addPage = () => {
4575
4872
  if (!editorService)
4576
4873
  return;
4874
+ const root = toRaw(editorService.get("root"));
4875
+ if (!root)
4876
+ throw new Error("root \u4E0D\u80FD\u4E3A\u7A7A");
4577
4877
  const pageConfig = {
4578
4878
  type: NodeType.PAGE,
4579
- name: generatePageNameByApp(toRaw(editorService.get("root")))
4879
+ name: generatePageNameByApp(root)
4580
4880
  };
4581
4881
  editorService.add(pageConfig);
4582
4882
  };
@@ -4592,14 +4892,14 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4592
4892
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4593
4893
  onClick: addPage
4594
4894
  }, [
4595
- createVNode(_sfc_main$o, { icon: unref(Plus) }, null, 8, ["icon"])
4895
+ createVNode(_sfc_main$s, { icon: unref(Plus) }, null, 8, ["icon"])
4596
4896
  ])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
4597
4897
  canScroll.value ? (openBlock(), createElementBlock("div", {
4598
4898
  key: 2,
4599
4899
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4600
4900
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
4601
4901
  }, [
4602
- createVNode(_sfc_main$o, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
4902
+ createVNode(_sfc_main$s, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
4603
4903
  ])) : createCommentVNode("", true),
4604
4904
  unref(pageLength) ? (openBlock(), createElementBlock("div", {
4605
4905
  key: 3,
@@ -4615,7 +4915,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4615
4915
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4616
4916
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
4617
4917
  }, [
4618
- createVNode(_sfc_main$o, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
4918
+ createVNode(_sfc_main$s, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
4619
4919
  ])) : createCommentVNode("", true)
4620
4920
  ], 512);
4621
4921
  };
@@ -4624,8 +4924,11 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4624
4924
 
4625
4925
  const _hoisted_1 = ["onClick"];
4626
4926
  const _hoisted_2 = { class: "m-editor-page-bar-title" };
4927
+ const __default__$5 = defineComponent({
4928
+ name: "MEditorPageBar"
4929
+ });
4627
4930
  const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4628
- __name: "PageBar",
4931
+ ...__default__$5,
4629
4932
  setup(__props) {
4630
4933
  const services = inject("services");
4631
4934
  const editorService = services?.editorService;
@@ -4684,7 +4987,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4684
4987
  default: withCtx(() => [
4685
4988
  createElementVNode("div", null, [
4686
4989
  renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
4687
- createVNode(_sfc_main$j, {
4990
+ createVNode(_sfc_main$k, {
4688
4991
  data: {
4689
4992
  type: "button",
4690
4993
  text: "\u590D\u5236",
@@ -4692,7 +4995,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4692
4995
  handler: () => copy(item)
4693
4996
  }
4694
4997
  }, null, 8, ["data"]),
4695
- createVNode(_sfc_main$j, {
4998
+ createVNode(_sfc_main$k, {
4696
4999
  data: {
4697
5000
  type: "button",
4698
5001
  text: "\u5220\u9664",
@@ -4726,6 +5029,10 @@ class ScrollViewer extends EventEmitter {
4726
5029
  height = 0;
4727
5030
  translateXCorrectionValue = 0;
4728
5031
  translateYCorrectionValue = 0;
5032
+ correctionScrollSize = {
5033
+ width: 0,
5034
+ height: 0
5035
+ };
4729
5036
  resizeObserver = new ResizeObserver(() => {
4730
5037
  this.setSize();
4731
5038
  this.setScrollSize();
@@ -4735,6 +5042,12 @@ class ScrollViewer extends EventEmitter {
4735
5042
  this.container = options.container;
4736
5043
  this.target = options.target;
4737
5044
  this.zoom = options.zoom;
5045
+ if (this.correctionScrollSize) {
5046
+ this.correctionScrollSize = {
5047
+ ...this.correctionScrollSize,
5048
+ ...options.correctionScrollSize
5049
+ };
5050
+ }
4738
5051
  this.container.addEventListener("wheel", this.wheelHandler, false);
4739
5052
  this.setSize();
4740
5053
  this.setScrollSize();
@@ -4797,9 +5110,9 @@ class ScrollViewer extends EventEmitter {
4797
5110
  }
4798
5111
  setScrollSize = () => {
4799
5112
  const targetRect = this.target.getBoundingClientRect();
4800
- this.scrollWidth = targetRect.width * this.zoom + 100;
5113
+ this.scrollWidth = targetRect.width * this.zoom + this.correctionScrollSize.width;
4801
5114
  const targetMarginTop = Number(this.target.style.marginTop) || 0;
4802
- this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + 100;
5115
+ this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + this.correctionScrollSize.height;
4803
5116
  let left;
4804
5117
  let top;
4805
5118
  if (this.scrollWidth < this.width) {
@@ -4832,8 +5145,11 @@ class ScrollViewer extends EventEmitter {
4832
5145
  };
4833
5146
  }
4834
5147
 
5148
+ const __default__$4 = defineComponent({
5149
+ name: "MEditorScrollBar"
5150
+ });
4835
5151
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
4836
- __name: "ScrollBar",
5152
+ ...__default__$4,
4837
5153
  props: {
4838
5154
  size: null,
4839
5155
  scrollSize: null,
@@ -4918,14 +5234,21 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
4918
5234
 
4919
5235
  const ScrollBar_vue_vue_type_style_index_0_lang = '';
4920
5236
 
5237
+ const __default__$3 = defineComponent({
5238
+ name: "MEditorScrollViewer"
5239
+ });
4921
5240
  const _sfc_main$4 = /* @__PURE__ */ defineComponent({
4922
- __name: "ScrollViewer",
5241
+ ...__default__$3,
4923
5242
  props: {
4924
5243
  width: { default: 0 },
4925
5244
  height: { default: 0 },
4926
5245
  wrapWidth: { default: 0 },
4927
5246
  wrapHeight: { default: 0 },
4928
- zoom: { default: 1 }
5247
+ zoom: { default: 1 },
5248
+ correctionScrollSize: { default: () => ({
5249
+ width: 0,
5250
+ height: 0
5251
+ }) }
4929
5252
  },
4930
5253
  setup(__props, { expose }) {
4931
5254
  const props = __props;
@@ -4948,7 +5271,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
4948
5271
  scrollViewer = new ScrollViewer({
4949
5272
  container: container.value,
4950
5273
  target: el.value,
4951
- zoom: props.zoom
5274
+ zoom: props.zoom,
5275
+ correctionScrollSize: props.correctionScrollSize
4952
5276
  });
4953
5277
  scrollViewer.on("scroll", (data) => {
4954
5278
  hOffset.value = data.scrollLeft;
@@ -5016,10 +5340,14 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
5016
5340
  }
5017
5341
  });
5018
5342
 
5343
+ const __default__$2 = defineComponent({
5344
+ name: "MEditorViewerMenu"
5345
+ });
5019
5346
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5020
- __name: "ViewerMenu",
5347
+ ...__default__$2,
5021
5348
  props: {
5022
- isMultiSelect: { type: Boolean, default: false }
5349
+ isMultiSelect: { type: Boolean, default: false },
5350
+ stageContentMenu: null
5023
5351
  },
5024
5352
  setup(__props, { expose }) {
5025
5353
  const props = __props;
@@ -5032,8 +5360,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5032
5360
  const nodes = computed(() => editorService?.get("nodes"));
5033
5361
  const parent = computed(() => editorService?.get("parent"));
5034
5362
  const stage = computed(() => editorService?.get("stage"));
5035
- const stageContentMenu = inject("stageContentMenu", []);
5036
- const menuData = reactive([
5363
+ const menuData = computed(() => [
5037
5364
  {
5038
5365
  type: "button",
5039
5366
  text: "\u6C34\u5E73\u5C45\u4E2D",
@@ -5047,7 +5374,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5047
5374
  {
5048
5375
  type: "button",
5049
5376
  text: "\u590D\u5236",
5050
- icon: markRaw(DocumentCopy),
5377
+ icon: markRaw(CopyDocument),
5051
5378
  handler: () => {
5052
5379
  nodes.value && editorService?.copy(nodes.value);
5053
5380
  canPaste.value = true;
@@ -5056,6 +5383,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5056
5383
  {
5057
5384
  type: "button",
5058
5385
  text: "\u7C98\u8D34",
5386
+ icon: markRaw(DocumentCopy),
5059
5387
  display: () => canPaste.value,
5060
5388
  handler: () => {
5061
5389
  const rect = menu.value?.$el.getBoundingClientRect();
@@ -5132,10 +5460,10 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5132
5460
  type: "button",
5133
5461
  text: "\u6E05\u7A7A\u53C2\u8003\u7EBF",
5134
5462
  handler: () => {
5135
- editorService?.get("stage").clearGuides();
5463
+ editorService?.get("stage")?.clearGuides();
5136
5464
  }
5137
5465
  },
5138
- ...stageContentMenu
5466
+ ...props.stageContentMenu
5139
5467
  ]);
5140
5468
  watch(
5141
5469
  parent,
@@ -5158,8 +5486,8 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5158
5486
  };
5159
5487
  expose({ show });
5160
5488
  return (_ctx, _cache) => {
5161
- return openBlock(), createBlock(_sfc_main$d, {
5162
- "menu-data": menuData,
5489
+ return openBlock(), createBlock(_sfc_main$c, {
5490
+ "menu-data": unref(menuData),
5163
5491
  ref_key: "menu",
5164
5492
  ref: menu
5165
5493
  }, null, 8, ["menu-data"]);
@@ -5167,8 +5495,14 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5167
5495
  }
5168
5496
  });
5169
5497
 
5498
+ const __default__$1 = defineComponent({
5499
+ name: "MEditorStage"
5500
+ });
5170
5501
  const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5171
- __name: "Stage",
5502
+ ...__default__$1,
5503
+ props: {
5504
+ stageContentMenu: null
5505
+ },
5172
5506
  setup(__props) {
5173
5507
  let stage = null;
5174
5508
  let runtime = null;
@@ -5177,7 +5511,8 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5177
5511
  const stageWrap = ref();
5178
5512
  const stageContainer = ref();
5179
5513
  const menu = ref();
5180
- const isMultiSelect = computed(() => services?.editorService.get("nodes")?.length > 1);
5514
+ const nodes = computed(() => services?.editorService.get("nodes") || []);
5515
+ const isMultiSelect = computed(() => nodes.value.length > 1);
5181
5516
  const stageRect = computed(() => services?.uiService.get("stageRect"));
5182
5517
  const stageContainerRect = computed(() => services?.uiService.get("stageContainerRect"));
5183
5518
  const root = computed(() => services?.editorService.get("root"));
@@ -5185,7 +5520,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5185
5520
  const zoom = computed(() => services?.uiService.get("zoom") || 1);
5186
5521
  const node = computed(() => services?.editorService.get("node"));
5187
5522
  watchEffect(() => {
5188
- if (stage)
5523
+ if (stage || !page.value)
5189
5524
  return;
5190
5525
  if (!stageContainer.value)
5191
5526
  return;
@@ -5215,6 +5550,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5215
5550
  runtime.updateRootConfig?.(cloneDeep(toRaw(root2)));
5216
5551
  }
5217
5552
  });
5553
+ watch(page, (page2) => {
5554
+ if (runtime && page2) {
5555
+ runtime.updatePageId?.(page2.id);
5556
+ nextTick(() => {
5557
+ stage?.select(page2.id);
5558
+ });
5559
+ }
5560
+ });
5218
5561
  const resizeObserver = new ResizeObserver((entries) => {
5219
5562
  for (const { contentRect } of entries) {
5220
5563
  services?.uiService.set("stageContainerRect", {
@@ -5287,7 +5630,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5287
5630
  height: unref(stageRect)?.height,
5288
5631
  "wrap-width": unref(stageContainerRect)?.width,
5289
5632
  "wrap-height": unref(stageContainerRect)?.height,
5290
- zoom: unref(zoom)
5633
+ zoom: unref(zoom),
5634
+ "correction-scroll-size": {
5635
+ width: 60,
5636
+ height: 50
5637
+ }
5291
5638
  }, {
5292
5639
  default: withCtx(() => [
5293
5640
  createElementVNode("div", {
@@ -5303,8 +5650,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5303
5650
  createVNode(_sfc_main$3, {
5304
5651
  ref_key: "menu",
5305
5652
  ref: menu,
5306
- "is-multi-select": unref(isMultiSelect)
5307
- }, null, 8, ["is-multi-select"])
5653
+ "is-multi-select": unref(isMultiSelect),
5654
+ "stage-content-menu": __props.stageContentMenu
5655
+ }, null, 8, ["is-multi-select", "stage-content-menu"])
5308
5656
  ]))
5309
5657
  ]),
5310
5658
  _: 1
@@ -5313,8 +5661,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5313
5661
  }
5314
5662
  });
5315
5663
 
5664
+ const __default__ = defineComponent({
5665
+ name: "MEditorWorkspace"
5666
+ });
5316
5667
  const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5317
- __name: "Workspace",
5668
+ ...__default__,
5669
+ props: {
5670
+ stageContentMenu: null
5671
+ },
5318
5672
  setup(__props) {
5319
5673
  const services = inject("services");
5320
5674
  const workspace = ref();
@@ -5425,9 +5779,10 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5425
5779
  }, [
5426
5780
  createVNode(_sfc_main$8),
5427
5781
  renderSlot(_ctx.$slots, "stage", {}, () => [
5428
- (openBlock(), createBlock(_sfc_main$2, {
5429
- key: unref(page)?.id
5430
- }))
5782
+ unref(page) ? (openBlock(), createBlock(_sfc_main$2, {
5783
+ key: 0,
5784
+ "stage-content-menu": __props.stageContentMenu
5785
+ }, null, 8, ["stage-content-menu"])) : createCommentVNode("", true)
5431
5786
  ]),
5432
5787
  renderSlot(_ctx.$slots, "workspace-content"),
5433
5788
  createVNode(_sfc_main$6, null, {
@@ -5457,9 +5812,13 @@ class ComponentList extends BaseService {
5457
5812
  getList() {
5458
5813
  return this.state.list;
5459
5814
  }
5460
- destroy() {
5815
+ resetState() {
5461
5816
  this.state.list = [];
5817
+ }
5818
+ destroy() {
5819
+ this.resetState();
5462
5820
  this.removeAllListeners();
5821
+ this.removeAllPlugins();
5463
5822
  }
5464
5823
  }
5465
5824
  const componentListService = new ComponentList();
@@ -5467,11 +5826,11 @@ const componentListService = new ComponentList();
5467
5826
  const _sfc_main = defineComponent({
5468
5827
  name: "m-editor",
5469
5828
  components: {
5470
- NavMenu: _sfc_main$i,
5829
+ TMagicNavMenu: _sfc_main$j,
5471
5830
  Sidebar: _sfc_main$9,
5472
5831
  Workspace: _sfc_main$1,
5473
- PropsPanel: _sfc_main$h,
5474
- Framework: _sfc_main$k
5832
+ PropsPanel: _sfc_main$i,
5833
+ Framework: _sfc_main$l
5475
5834
  },
5476
5835
  props: {
5477
5836
  modelValue: {
@@ -5486,6 +5845,10 @@ const _sfc_main = defineComponent({
5486
5845
  sidebar: {
5487
5846
  type: Object
5488
5847
  },
5848
+ menu: {
5849
+ type: Object,
5850
+ default: () => ({ left: [], right: [] })
5851
+ },
5489
5852
  layerContentMenu: {
5490
5853
  type: Array,
5491
5854
  default: () => []
@@ -5494,10 +5857,6 @@ const _sfc_main = defineComponent({
5494
5857
  type: Array,
5495
5858
  default: () => []
5496
5859
  },
5497
- menu: {
5498
- type: Object,
5499
- default: () => ({ left: [], right: [] })
5500
- },
5501
5860
  render: {
5502
5861
  type: Function
5503
5862
  },
@@ -5531,7 +5890,7 @@ const _sfc_main = defineComponent({
5531
5890
  },
5532
5891
  containerHighlightClassName: {
5533
5892
  type: String,
5534
- default: CONTAINER_HIGHLIGHT_CLASS
5893
+ default: CONTAINER_HIGHLIGHT_CLASS_NAME
5535
5894
  },
5536
5895
  containerHighlightDuration: {
5537
5896
  type: Number,
@@ -5550,20 +5909,33 @@ const _sfc_main = defineComponent({
5550
5909
  },
5551
5910
  updateDragEl: {
5552
5911
  type: Function
5912
+ },
5913
+ disabledDragStart: {
5914
+ type: Boolean
5553
5915
  }
5554
5916
  },
5555
5917
  emits: ["props-panel-mounted", "update:modelValue"],
5556
5918
  setup(props, { emit }) {
5557
- editorService.on("root-change", (value) => {
5558
- const node = editorService.get("node");
5559
- const nodeId = node?.id || props.defaultSelected;
5560
- if (nodeId && node !== value) {
5561
- editorService.select(nodeId);
5562
- } else {
5919
+ const rootChangeHandler = (value, preValue) => {
5920
+ const nodeId = editorService.get("node")?.id || props.defaultSelected;
5921
+ let node;
5922
+ if (nodeId) {
5923
+ node = editorService.getNodeById(nodeId);
5924
+ }
5925
+ if (node && node !== value) {
5926
+ editorService.select(node.id);
5927
+ } else if (value?.items?.length) {
5928
+ editorService.select(value.items[0]);
5929
+ } else if (value?.id) {
5563
5930
  editorService.set("nodes", [value]);
5931
+ editorService.set("parent", null);
5932
+ editorService.set("page", null);
5564
5933
  }
5565
- emit("update:modelValue", toRaw(editorService.get("root")));
5566
- });
5934
+ if (toRaw(value) !== toRaw(preValue)) {
5935
+ emit("update:modelValue", value);
5936
+ }
5937
+ };
5938
+ editorService.on("root-change", rootChangeHandler);
5567
5939
  watch(
5568
5940
  () => props.modelValue,
5569
5941
  (modelValue) => {
@@ -5625,13 +5997,13 @@ const _sfc_main = defineComponent({
5625
5997
  }
5626
5998
  );
5627
5999
  onUnmounted(() => {
5628
- editorService.destroy();
5629
- historyService.destroy();
5630
- propsService.destroy();
5631
- uiService.destroy();
5632
- componentListService.destroy();
5633
- storageService.destroy();
5634
- codeBlockService.destroy();
6000
+ editorService.resetState();
6001
+ historyService.resetState();
6002
+ propsService.resetState();
6003
+ uiService.resetState();
6004
+ componentListService.resetState();
6005
+ codeBlockService.resetState();
6006
+ editorService.off("root-change", rootChangeHandler);
5635
6007
  });
5636
6008
  const services = {
5637
6009
  componentListService,
@@ -5644,8 +6016,7 @@ const _sfc_main = defineComponent({
5644
6016
  codeBlockService
5645
6017
  };
5646
6018
  provide("services", services);
5647
- provide("layerContentMenu", props.layerContentMenu);
5648
- provide("stageContentMenu", props.stageContentMenu);
6019
+ provide("codeOptions", props.codeOptions);
5649
6020
  provide(
5650
6021
  "stageOptions",
5651
6022
  reactive({
@@ -5658,7 +6029,8 @@ const _sfc_main = defineComponent({
5658
6029
  isContainer: props.isContainer,
5659
6030
  containerHighlightClassName: props.containerHighlightClassName,
5660
6031
  containerHighlightDuration: props.containerHighlightDuration,
5661
- containerHighlightType: props.containerHighlightType
6032
+ containerHighlightType: props.containerHighlightType,
6033
+ disabledDragStart: props.disabledDragStart
5662
6034
  })
5663
6035
  );
5664
6036
  return services;
@@ -5674,20 +6046,23 @@ const _export_sfc = (sfc, props) => {
5674
6046
  };
5675
6047
 
5676
6048
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5677
- const _component_nav_menu = resolveComponent("nav-menu");
5678
- const _component_sidebar = resolveComponent("sidebar");
5679
- const _component_workspace = resolveComponent("workspace");
5680
- const _component_props_panel = resolveComponent("props-panel");
5681
- const _component_framework = resolveComponent("framework");
5682
- return openBlock(), createBlock(_component_framework, { "code-options": _ctx.codeOptions }, {
6049
+ const _component_TMagicNavMenu = resolveComponent("TMagicNavMenu");
6050
+ const _component_Sidebar = resolveComponent("Sidebar");
6051
+ const _component_Workspace = resolveComponent("Workspace");
6052
+ const _component_PropsPanel = resolveComponent("PropsPanel");
6053
+ const _component_Framework = resolveComponent("Framework");
6054
+ return openBlock(), createBlock(_component_Framework, { "code-options": _ctx.codeOptions }, {
5683
6055
  nav: withCtx(() => [
5684
6056
  renderSlot(_ctx.$slots, "nav", { editorService: _ctx.editorService }, () => [
5685
- createVNode(_component_nav_menu, { data: _ctx.menu }, null, 8, ["data"])
6057
+ createVNode(_component_TMagicNavMenu, { data: _ctx.menu }, null, 8, ["data"])
5686
6058
  ])
5687
6059
  ]),
5688
6060
  sidebar: withCtx(() => [
5689
6061
  renderSlot(_ctx.$slots, "sidebar", { editorService: _ctx.editorService }, () => [
5690
- createVNode(_component_sidebar, { data: _ctx.sidebar }, {
6062
+ createVNode(_component_Sidebar, {
6063
+ data: _ctx.sidebar,
6064
+ "layer-content-menu": _ctx.layerContentMenu
6065
+ }, {
5691
6066
  "layer-panel-header": withCtx(() => [
5692
6067
  renderSlot(_ctx.$slots, "layer-panel-header")
5693
6068
  ]),
@@ -5716,12 +6091,12 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5716
6091
  renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
5717
6092
  ]),
5718
6093
  _: 3
5719
- }, 8, ["data"])
6094
+ }, 8, ["data", "layer-content-menu"])
5720
6095
  ])
5721
6096
  ]),
5722
6097
  workspace: withCtx(() => [
5723
6098
  renderSlot(_ctx.$slots, "workspace", { editorService: _ctx.editorService }, () => [
5724
- createVNode(_component_workspace, null, {
6099
+ createVNode(_component_Workspace, { "stage-content-menu": _ctx.stageContentMenu }, {
5725
6100
  stage: withCtx(() => [
5726
6101
  renderSlot(_ctx.$slots, "stage")
5727
6102
  ]),
@@ -5735,12 +6110,12 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5735
6110
  renderSlot(_ctx.$slots, "page-bar-popover", { page })
5736
6111
  ]),
5737
6112
  _: 3
5738
- })
6113
+ }, 8, ["stage-content-menu"])
5739
6114
  ])
5740
6115
  ]),
5741
6116
  "props-panel": withCtx(() => [
5742
6117
  renderSlot(_ctx.$slots, "props-panel", {}, () => [
5743
- createVNode(_component_props_panel, {
6118
+ createVNode(_component_PropsPanel, {
5744
6119
  onMounted: _cache[0] || (_cache[0] = (instance) => _ctx.$emit("props-panel-mounted", instance))
5745
6120
  }, {
5746
6121
  "props-panel-header": withCtx(() => [
@@ -5768,12 +6143,12 @@ const index = {
5768
6143
  setConfig(option);
5769
6144
  app.component(Editor.name, Editor);
5770
6145
  app.component("m-fields-ui-select", _sfc_main$q);
5771
- app.component("m-fields-code-link", _sfc_main$s);
5772
- app.component("m-fields-vs-code", _sfc_main$t);
6146
+ app.component("m-fields-code-link", _sfc_main$t);
6147
+ app.component("m-fields-vs-code", _sfc_main$u);
5773
6148
  app.component("magic-code-editor", _sfc_main$p);
5774
6149
  app.component("m-fields-code-select", _sfc_main$r);
5775
6150
  }
5776
6151
  };
5777
6152
 
5778
- export { COPY_STORAGE_KEY, _sfc_main$f as CodeBlockList, CodeDeleteErrorType, CodeEditorMode, _sfc_main$r as CodeSelect, CodeSelectOp, ColumnLayout, _sfc_main$e as ComponentListPanel, _sfc_main$d as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$o as Icon, Keys, LayerOffset, _sfc_main$b as LayerPanel, Layout, _sfc_main$h as PropsPanel, _sfc_main$p as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$j as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, codeBlockService, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, useStage, warn };
5779
- //# sourceMappingURL=tmagic-editor.mjs.map
6153
+ export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, _sfc_main$r as CodeSelect, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$s as Icon, Keys, LayerOffset, _sfc_main$a as LayerPanel, Layout, _sfc_main$n as LayoutContainer, _sfc_main$i as PropsPanel, _sfc_main$p as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$k as ToolButton, V_GUIDE_LINE_STORAGE_KEY, beforePaste, change2Fixed, codeBlockService, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, uiService, useStage, warn };
6154
+ //# sourceMappingURL=tmagic-editor.js.map