@tmagic/editor 1.2.0-beta.2 → 1.2.0-beta.21

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 (101) hide show
  1. package/dist/style.css +41 -28
  2. package/dist/{tmagic-editor.mjs → tmagic-editor.js} +1693 -1272
  3. package/dist/tmagic-editor.js.map +1 -0
  4. package/dist/{tmagic-editor.umd.js → tmagic-editor.umd.cjs} +1700 -1274
  5. package/dist/tmagic-editor.umd.cjs.map +1 -0
  6. package/package.json +16 -14
  7. package/src/Editor.vue +54 -37
  8. package/src/components/CodeDraftEditor.vue +145 -0
  9. package/src/components/ContentMenu.vue +4 -4
  10. package/src/components/FunctionEditor.vue +145 -0
  11. package/src/components/Icon.vue +7 -5
  12. package/src/components/Layout.vue +149 -0
  13. package/src/components/ScrollBar.vue +1 -1
  14. package/src/components/ScrollViewer.vue +10 -1
  15. package/src/components/ToolButton.vue +30 -15
  16. package/src/fields/Code.vue +1 -1
  17. package/src/fields/CodeLink.vue +1 -1
  18. package/src/fields/CodeSelect.vue +89 -110
  19. package/src/fields/UISelect.vue +9 -8
  20. package/src/index.ts +1 -0
  21. package/src/layouts/AddPageBox.vue +3 -2
  22. package/src/layouts/CodeEditor.vue +2 -3
  23. package/src/layouts/Framework.vue +62 -40
  24. package/src/layouts/NavMenu.vue +1 -1
  25. package/src/layouts/PropsPanel.vue +11 -13
  26. package/src/layouts/Resizer.vue +1 -1
  27. package/src/layouts/sidebar/ComponentListPanel.vue +15 -13
  28. package/src/layouts/sidebar/LayerMenu.vue +9 -7
  29. package/src/layouts/sidebar/LayerPanel.vue +277 -177
  30. package/src/layouts/sidebar/Sidebar.vue +113 -27
  31. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +34 -85
  32. package/src/layouts/sidebar/code-block/CodeBlockList.vue +55 -89
  33. package/src/layouts/workspace/Breadcrumb.vue +32 -0
  34. package/src/layouts/workspace/PageBar.vue +12 -11
  35. package/src/layouts/workspace/PageBarScrollContainer.vue +1 -1
  36. package/src/layouts/workspace/Stage.vue +26 -9
  37. package/src/layouts/workspace/ViewerMenu.vue +11 -9
  38. package/src/layouts/workspace/Workspace.vue +10 -3
  39. package/src/services/BaseService.ts +6 -1
  40. package/src/services/codeBlock.ts +124 -125
  41. package/src/services/componentList.ts +6 -1
  42. package/src/services/editor.ts +43 -19
  43. package/src/services/events.ts +6 -1
  44. package/src/services/history.ts +7 -16
  45. package/src/services/props.ts +7 -2
  46. package/src/services/storage.ts +1 -0
  47. package/src/services/ui.ts +12 -0
  48. package/src/theme/breadcrumb.scss +6 -0
  49. package/src/theme/code-block.scss +30 -21
  50. package/src/theme/component-list-panel.scss +3 -7
  51. package/src/theme/layer-panel.scss +7 -2
  52. package/src/theme/theme.scss +1 -0
  53. package/src/type.ts +76 -50
  54. package/src/utils/editor.ts +9 -1
  55. package/src/utils/index.ts +1 -0
  56. package/src/utils/props.ts +2 -2
  57. package/src/utils/scroll-viewer.ts +18 -2
  58. package/src/utils/stage.ts +9 -2
  59. package/types/Editor.vue.d.ts +42 -29
  60. package/types/components/CodeDraftEditor.vue.d.ts +148 -0
  61. package/types/components/ContentMenu.vue.d.ts +1 -3
  62. package/types/components/FunctionEditor.vue.d.ts +120 -0
  63. package/types/components/Icon.vue.d.ts +1 -3
  64. package/types/{layouts → components}/Layout.vue.d.ts +12 -1
  65. package/types/components/ScrollBar.vue.d.ts +1 -3
  66. package/types/components/ScrollViewer.vue.d.ts +45 -1
  67. package/types/components/ToolButton.vue.d.ts +1 -3
  68. package/types/fields/Code.vue.d.ts +1 -3
  69. package/types/fields/CodeLink.vue.d.ts +1 -3
  70. package/types/fields/CodeSelect.vue.d.ts +10 -12
  71. package/types/fields/UISelect.vue.d.ts +1 -3
  72. package/types/index.d.ts +1 -0
  73. package/types/layouts/AddPageBox.vue.d.ts +1 -3
  74. package/types/layouts/CodeEditor.vue.d.ts +6 -15
  75. package/types/layouts/NavMenu.vue.d.ts +1 -3
  76. package/types/layouts/sidebar/LayerMenu.vue.d.ts +25 -9
  77. package/types/layouts/sidebar/LayerPanel.vue.d.ts +38 -886
  78. package/types/layouts/sidebar/Sidebar.vue.d.ts +10 -5
  79. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +1 -1
  80. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +6 -5
  81. package/types/layouts/{sidebar/TabPane.vue.d.ts → workspace/Breadcrumb.vue.d.ts} +5 -43
  82. package/types/layouts/workspace/Stage.vue.d.ts +25 -8
  83. package/types/layouts/workspace/ViewerMenu.vue.d.ts +6 -3
  84. package/types/layouts/workspace/Workspace.vue.d.ts +23 -5
  85. package/types/services/BaseService.d.ts +2 -1
  86. package/types/services/codeBlock.d.ts +57 -36
  87. package/types/services/componentList.d.ts +1 -0
  88. package/types/services/editor.d.ts +5 -6
  89. package/types/services/events.d.ts +1 -0
  90. package/types/services/history.d.ts +5 -15
  91. package/types/services/props.d.ts +3 -2
  92. package/types/services/ui.d.ts +2 -1
  93. package/types/type.d.ts +64 -48
  94. package/types/utils/editor.d.ts +1 -0
  95. package/types/utils/index.d.ts +1 -0
  96. package/types/utils/props.d.ts +1 -1
  97. package/types/utils/scroll-viewer.d.ts +5 -0
  98. package/dist/tmagic-editor.mjs.map +0 -1
  99. package/dist/tmagic-editor.umd.js.map +0 -1
  100. package/src/layouts/Layout.vue +0 -100
  101. package/src/layouts/sidebar/TabPane.vue +0 -116
@@ -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, toRaw, renderSlot, Fragment, normalizeClass, createSlots, resolveDynamicComponent, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, isRef, Teleport, nextTick, toHandlers, provide } from 'vue';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, inject, createElementBlock, createVNode, ref, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, onMounted, onUnmounted, renderSlot, Fragment, createElementVNode, normalizeClass, resolveDynamicComponent, toRaw, createSlots, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, watchEffect, provide, withDirectives, Teleport, vShow, nextTick, toHandlers } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
- import { ElMessage } from 'element-plus';
4
- import { cloneDeep, map, xor, throttle, pick, isEmpty, forIn, omit, keys, mergeWith, uniq } from 'lodash-es';
5
- import { Delete, Close, Plus, Edit, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, View, Link, Files, DocumentCopy, EditPen, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
3
+ import { isEmpty, map, throttle, pick, omit, keys, cloneDeep, forIn, mergeWith, uniq, isObject } from 'lodash-es';
4
+ import { createValues, MForm } from '@tmagic/form';
5
+ import { HookType, NodeType } from '@tmagic/schema';
6
+ import { Delete, Close, Edit, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, View, Link, Search, Files, CopyDocument, Coin, EditPen, ArrowLeftBold, ArrowRightBold, CaretBottom, DocumentCopy, Top, Bottom } from '@element-plus/icons-vue';
7
+ import { TMagicButton, TMagicTooltip, TMagicIcon, 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$s = /* @__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$s = /* @__PURE__ */ defineComponent({
42
46
  }
43
47
  });
44
48
 
45
- const _sfc_main$r = /* @__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,12 @@ const _sfc_main$r = /* @__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 || {});
155
-
156
- const _hoisted_1$d = { 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
- ];
164
- const _sfc_main$q = /* @__PURE__ */ defineComponent({
165
- __name: "CodeSelect",
122
+ const _hoisted_1$g = { class: "m-fields-code-select" };
123
+ const __default__$r = defineComponent({
124
+ name: "MEditorCodeSelect"
125
+ });
126
+ const _sfc_main$s = /* @__PURE__ */ defineComponent({
127
+ ...__default__$r,
166
128
  props: {
167
129
  config: null,
168
130
  model: null,
@@ -174,125 +136,107 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
174
136
  setup(__props, { emit }) {
175
137
  const props = __props;
176
138
  const services = inject("services");
177
- const selectConfig = computed(() => {
139
+ const mForm = inject("mForm");
140
+ const codeDsl = computed(() => services?.codeBlockService.getCodeDslSync());
141
+ const tableConfig = computed(() => {
178
142
  const defaultConfig = {
179
- multiple: true,
180
- options: async () => {
181
- const codeDsl = await services?.codeBlockService.getCodeDsl();
182
- if (codeDsl) {
183
- return map(codeDsl, (value, key) => ({
184
- text: `${value.name}\uFF08${key}\uFF09`,
185
- label: `${value.name}\uFF08${key}\uFF09`,
186
- value: key
187
- }));
143
+ dropSort: true,
144
+ enableFullscreen: false,
145
+ border: true,
146
+ items: [
147
+ {
148
+ type: "select",
149
+ label: "\u4EE3\u7801\u5757",
150
+ name: "codeId",
151
+ width: "200px",
152
+ options: () => {
153
+ if (codeDsl.value) {
154
+ return map(codeDsl.value, (value, key) => ({
155
+ text: `${value.name}\uFF08${key}\uFF09`,
156
+ label: `${value.name}\uFF08${key}\uFF09`,
157
+ value: key
158
+ }));
159
+ }
160
+ return [];
161
+ },
162
+ onChange: (formState, codeId, { model }) => {
163
+ model.params = {};
164
+ }
165
+ },
166
+ {
167
+ name: "params",
168
+ label: "\u53C2\u6570",
169
+ defaultValue: {},
170
+ itemsFunction: (row) => {
171
+ const paramsConfig = getParamsConfig(row.codeId);
172
+ if (!row.params)
173
+ row.params = {};
174
+ if (isEmpty(row.params)) {
175
+ createValues(mForm, paramsConfig, {}, row.params);
176
+ }
177
+ return paramsConfig;
178
+ }
188
179
  }
189
- return [];
190
- }
180
+ ]
191
181
  };
192
182
  return {
193
183
  ...defaultConfig,
194
- ...props.config.selectConfig
184
+ ...props.config.tableConfig
195
185
  };
196
186
  });
197
- const fieldKey = ref("");
198
- const multiple = ref(true);
199
- const combineIds = ref([]);
200
- let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
201
- watchEffect(async () => {
202
- const combineNames = await Promise.all(
203
- combineIds.value.map(async (id) => {
204
- const { name = "" } = await services?.codeBlockService.getCodeContentById(id) || {};
205
- return name;
206
- })
207
- );
208
- fieldKey.value = combineNames.join("-");
209
- });
210
- const changeHandler = async (value) => {
211
- let codeIds = value;
212
- if (typeof value === "string") {
213
- multiple.value = false;
214
- lastTagSnapshot = [lastTagSnapshot];
215
- codeIds = value ? [value] : [];
216
- }
217
- await setCombineRelation(codeIds);
218
- emit("change", value);
219
- };
220
- const setCombineRelation = async (codeIds) => {
221
- const { id = "" } = services?.editorService.get("node") || {};
222
- let opFlag = CodeSelectOp.CHANGE;
223
- let diffValues = codeIds;
224
- if (multiple.value) {
225
- opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
226
- diffValues = xor(codeIds, lastTagSnapshot);
187
+ watch(
188
+ () => props.model[props.name],
189
+ (value) => {
190
+ if (isEmpty(value)) {
191
+ props.model[props.name] = {
192
+ hookType: HookType.CODE,
193
+ hookData: []
194
+ };
195
+ }
196
+ },
197
+ {
198
+ immediate: true
227
199
  }
228
- await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
229
- lastTagSnapshot = codeIds;
230
- await setCombineIds(codeIds);
231
- };
232
- const setCombineIds = async (codeIds) => {
233
- combineIds.value = codeIds;
234
- await services?.codeBlockService.setCombineIds(codeIds);
200
+ );
201
+ const changeHandler = async () => {
202
+ emit("change", props.model[props.name]);
235
203
  };
236
- const viewHandler = async () => {
237
- if (props.model[props.name].length === 0) {
238
- ElMessage.error("\u8BF7\u5148\u7ED1\u5B9A\u4EE3\u7801\u5757");
239
- return;
240
- }
241
- await setCombineIds(props.model[props.name]);
242
- await services?.codeBlockService.setMode(CodeEditorMode.LIST);
243
- services?.codeBlockService.setCodeEditorContent(true, combineIds.value[0]);
204
+ const getParamsConfig = (codeId) => {
205
+ if (!codeDsl.value)
206
+ return [];
207
+ const paramStatements = codeDsl.value[codeId]?.params;
208
+ if (isEmpty(paramStatements))
209
+ return [];
210
+ return paramStatements.map((paramState) => ({
211
+ name: paramState.name,
212
+ text: paramState.name,
213
+ labelWidth: "100px",
214
+ type: "text"
215
+ }));
244
216
  };
245
217
  return (_ctx, _cache) => {
246
- const _component_m_fields_select = resolveComponent("m-fields-select");
247
- const _component_el_tooltip = resolveComponent("el-tooltip");
248
- const _component_el_card = resolveComponent("el-card");
249
- return openBlock(), createElementBlock("div", {
250
- class: "m-fields-code-select",
251
- key: fieldKey.value
252
- }, [
253
- createVNode(_component_el_card, { shadow: "never" }, {
254
- header: withCtx(() => [
255
- createVNode(_component_m_fields_select, {
256
- config: unref(selectConfig),
257
- model: __props.model,
258
- prop: __props.prop,
259
- name: __props.name,
260
- size: __props.size,
261
- onChange: changeHandler
262
- }, null, 8, ["config", "model", "prop", "name", "size"])
263
- ]),
264
- default: withCtx(() => [
265
- createElementVNode("div", _hoisted_1$d, [
266
- createVNode(_component_el_tooltip, {
267
- class: "tool-item",
268
- effect: "dark",
269
- content: "\u67E5\u770B\u4EE3\u7801\u5757",
270
- placement: "top"
271
- }, {
272
- default: withCtx(() => [
273
- (openBlock(), createElementBlock("svg", {
274
- onClick: viewHandler,
275
- preserveAspectRatio: "xMidYMid meet",
276
- viewBox: "0 0 24 24",
277
- width: "15px",
278
- height: "15px",
279
- "data-v-65a7fb6c": ""
280
- }, _hoisted_3$3))
281
- ]),
282
- _: 1
283
- })
284
- ])
285
- ]),
286
- _: 1
287
- })
218
+ const _component_m_form_table = resolveComponent("m-form-table");
219
+ return openBlock(), createElementBlock("div", _hoisted_1$g, [
220
+ createVNode(_component_m_form_table, {
221
+ config: unref(tableConfig),
222
+ model: __props.model[__props.name],
223
+ name: "hookData",
224
+ enableToggleMode: false,
225
+ prop: __props.prop,
226
+ size: __props.size,
227
+ onChange: changeHandler
228
+ }, null, 8, ["config", "model", "prop", "size"])
288
229
  ]);
289
230
  };
290
231
  }
291
232
  });
292
233
 
293
- const _hoisted_1$c = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
294
- const _sfc_main$p = /* @__PURE__ */ defineComponent({
295
- __name: "UISelect",
234
+ const _hoisted_1$f = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
235
+ const __default__$q = defineComponent({
236
+ name: "MEditorUISelect"
237
+ });
238
+ const _sfc_main$r = /* @__PURE__ */ defineComponent({
239
+ ...__default__$q,
296
240
  props: {
297
241
  config: null,
298
242
  model: null,
@@ -342,21 +286,19 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
342
286
  }
343
287
  };
344
288
  return (_ctx, _cache) => {
345
- const _component_el_button = resolveComponent("el-button");
346
- const _component_el_tooltip = resolveComponent("el-tooltip");
347
289
  return uiSelectMode.value ? (openBlock(), createElementBlock("div", {
348
290
  key: 0,
349
291
  class: "m-fields-ui-select",
350
292
  onClick: cancelHandler
351
293
  }, [
352
- createVNode(_component_el_button, {
294
+ createVNode(unref(TMagicButton), {
353
295
  type: "danger",
354
296
  icon: unref(Delete),
355
297
  text: "",
356
298
  style: { "padding": "0" }
357
299
  }, {
358
300
  default: withCtx(() => [
359
- _hoisted_1$c
301
+ _hoisted_1$f
360
302
  ]),
361
303
  _: 1
362
304
  }, 8, ["icon"])
@@ -366,12 +308,12 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
366
308
  onClick: startSelect,
367
309
  style: { "display": "flex" }
368
310
  }, [
369
- unref(val) ? (openBlock(), createBlock(_component_el_tooltip, {
311
+ unref(val) ? (openBlock(), createBlock(unref(TMagicTooltip), {
370
312
  key: 0,
371
313
  content: "\u6E05\u9664"
372
314
  }, {
373
315
  default: withCtx(() => [
374
- createVNode(_component_el_button, {
316
+ createVNode(unref(TMagicButton), {
375
317
  style: { "padding": "0" },
376
318
  type: "danger",
377
319
  icon: unref(Close),
@@ -381,11 +323,11 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
381
323
  ]),
382
324
  _: 1
383
325
  })) : createCommentVNode("", true),
384
- createVNode(_component_el_tooltip, {
326
+ createVNode(unref(TMagicTooltip), {
385
327
  content: unref(val) ? unref(toName) + "_" + unref(val) : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"
386
328
  }, {
387
329
  default: withCtx(() => [
388
- createVNode(_component_el_button, {
330
+ createVNode(unref(TMagicButton), {
389
331
  text: "",
390
332
  style: { "padding": "0", "margin": "0" }
391
333
  }, {
@@ -404,12 +346,15 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
404
346
 
405
347
  const UISelect_vue_vue_type_style_index_0_lang = '';
406
348
 
407
- const _sfc_main$o = /* @__PURE__ */ defineComponent({
408
- __name: "CodeEditor",
349
+ const __default__$p = defineComponent({
350
+ name: "MEditorCodeEditor"
351
+ });
352
+ const _sfc_main$q = /* @__PURE__ */ defineComponent({
353
+ ...__default__$p,
409
354
  props: {
410
355
  initValues: null,
411
356
  modifiedValues: null,
412
- type: { default: "" },
357
+ type: null,
413
358
  language: { default: "javascript" },
414
359
  options: { default: () => ({
415
360
  tabSize: 2
@@ -534,6 +479,255 @@ const setConfig = (option) => {
534
479
  };
535
480
  const getConfig = (key) => $TMAGIC_EDITOR[key];
536
481
 
482
+ const __default__$o = defineComponent({
483
+ name: "MEditorResizer"
484
+ });
485
+ const _sfc_main$p = /* @__PURE__ */ defineComponent({
486
+ ...__default__$o,
487
+ emits: ["change"],
488
+ setup(__props, { emit }) {
489
+ const target = ref();
490
+ let getso;
491
+ onMounted(() => {
492
+ if (!target.value)
493
+ return;
494
+ getso = new Gesto(target.value, {
495
+ container: window,
496
+ pinchOutside: true
497
+ }).on("drag", (e) => {
498
+ if (!target.value)
499
+ return;
500
+ emit("change", e.deltaX);
501
+ });
502
+ });
503
+ onUnmounted(() => {
504
+ getso?.unset();
505
+ });
506
+ return (_ctx, _cache) => {
507
+ return openBlock(), createElementBlock("span", {
508
+ ref_key: "target",
509
+ ref: target,
510
+ class: "m-editor-resizer"
511
+ }, [
512
+ renderSlot(_ctx.$slots, "default")
513
+ ], 512);
514
+ };
515
+ }
516
+ });
517
+
518
+ const __default__$n = defineComponent({
519
+ name: "MEditorLayout"
520
+ });
521
+ const _sfc_main$o = /* @__PURE__ */ defineComponent({
522
+ ...__default__$n,
523
+ props: {
524
+ left: null,
525
+ right: null,
526
+ minLeft: { default: 46 },
527
+ minRight: { default: 1 },
528
+ minCenter: { default: 1 },
529
+ leftClass: null,
530
+ rightClass: null,
531
+ centerClass: null
532
+ },
533
+ emits: ["update:left", "change", "update:right"],
534
+ setup(__props, { emit }) {
535
+ const props = __props;
536
+ const el = ref();
537
+ const hasLeft = computed(() => typeof props.left !== "undefined");
538
+ const hasRight = computed(() => typeof props.right !== "undefined");
539
+ const getCenterWidth = (clientWidth2, left, right) => {
540
+ let center2 = clientWidth2 - left - right;
541
+ if (center2 < props.minCenter) {
542
+ center2 = props.minCenter;
543
+ if (left < right) {
544
+ right = clientWidth2 - left - props.minCenter;
545
+ } else {
546
+ left = clientWidth2 - right - props.minCenter;
547
+ }
548
+ }
549
+ return {
550
+ center: center2,
551
+ left,
552
+ right
553
+ };
554
+ };
555
+ let clientWidth = 0;
556
+ const resizerObserver = new ResizeObserver((entries) => {
557
+ for (const { contentRect } of entries) {
558
+ clientWidth = contentRect.width;
559
+ let left = props.left || 0;
560
+ let right = props.right || 0;
561
+ if (left > clientWidth) {
562
+ left = clientWidth / 3;
563
+ }
564
+ if (right > clientWidth) {
565
+ right = clientWidth / 3;
566
+ }
567
+ const columnWidth = getCenterWidth(clientWidth, left, right);
568
+ center.value = columnWidth.center;
569
+ emit("change", {
570
+ left: columnWidth.left,
571
+ center: center.value,
572
+ right: columnWidth.right
573
+ });
574
+ }
575
+ });
576
+ onMounted(() => {
577
+ if (el.value) {
578
+ resizerObserver.observe(el.value);
579
+ }
580
+ });
581
+ onUnmounted(() => {
582
+ resizerObserver.disconnect();
583
+ });
584
+ const center = ref(0);
585
+ const changeLeft = (deltaX) => {
586
+ if (typeof props.left === "undefined")
587
+ return;
588
+ let left = Math.max(props.left + deltaX, props.minLeft) || 0;
589
+ emit("update:left", left);
590
+ if (clientWidth - left - (props.right || 0) <= 0) {
591
+ left = props.left;
592
+ }
593
+ const columnWidth = getCenterWidth(clientWidth, left, props.right || 0);
594
+ center.value = columnWidth.center;
595
+ emit("change", {
596
+ left: columnWidth.left,
597
+ center: center.value,
598
+ right: columnWidth.right
599
+ });
600
+ };
601
+ const changeRight = (deltaX) => {
602
+ if (typeof props.right === "undefined")
603
+ return;
604
+ let right = Math.max(props.right - deltaX, props.minRight) || 0;
605
+ emit("update:right", right);
606
+ if (clientWidth - (props.left || 0) - right <= 0) {
607
+ right = props.right;
608
+ }
609
+ const columnWidth = getCenterWidth(clientWidth, props.left || 0, right);
610
+ center.value = columnWidth.center;
611
+ emit("change", {
612
+ left: columnWidth.left,
613
+ center: center.value,
614
+ right: columnWidth.right
615
+ });
616
+ };
617
+ return (_ctx, _cache) => {
618
+ return openBlock(), createElementBlock("div", {
619
+ ref_key: "el",
620
+ ref: el,
621
+ class: "m-editor-layout"
622
+ }, [
623
+ unref(hasLeft) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
624
+ createElementVNode("div", {
625
+ class: normalizeClass(["m-editor-layout-left", __props.leftClass]),
626
+ style: normalizeStyle(`width: ${__props.left}px`)
627
+ }, [
628
+ renderSlot(_ctx.$slots, "left")
629
+ ], 6),
630
+ createVNode(_sfc_main$p, { onChange: changeLeft })
631
+ ], 64)) : createCommentVNode("", true),
632
+ createElementVNode("div", {
633
+ class: normalizeClass(["m-editor-layout-center", __props.centerClass]),
634
+ style: normalizeStyle(`width: ${center.value}px`)
635
+ }, [
636
+ renderSlot(_ctx.$slots, "center")
637
+ ], 6),
638
+ unref(hasRight) ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
639
+ createVNode(_sfc_main$p, { onChange: changeRight }),
640
+ createElementVNode("div", {
641
+ class: normalizeClass(["m-editor-layout-right", __props.rightClass]),
642
+ style: normalizeStyle(`width: ${__props.right}px`)
643
+ }, [
644
+ renderSlot(_ctx.$slots, "right")
645
+ ], 6)
646
+ ], 64)) : createCommentVNode("", true)
647
+ ], 512);
648
+ };
649
+ }
650
+ });
651
+
652
+ const _hoisted_1$e = ["src"];
653
+ const __default__$m = defineComponent({
654
+ name: "MEditorIcon"
655
+ });
656
+ const _sfc_main$n = /* @__PURE__ */ defineComponent({
657
+ ...__default__$m,
658
+ props: {
659
+ icon: null
660
+ },
661
+ setup(__props) {
662
+ return (_ctx, _cache) => {
663
+ return !__props.icon ? (openBlock(), createBlock(unref(TMagicIcon), {
664
+ key: 0,
665
+ class: "magic-editor-icon"
666
+ }, {
667
+ default: withCtx(() => [
668
+ createVNode(unref(Edit))
669
+ ]),
670
+ _: 1
671
+ })) : typeof __props.icon === "string" && __props.icon.startsWith("http") ? (openBlock(), createBlock(unref(TMagicIcon), {
672
+ key: 1,
673
+ class: "magic-editor-icon"
674
+ }, {
675
+ default: withCtx(() => [
676
+ createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$e)
677
+ ]),
678
+ _: 1
679
+ })) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
680
+ key: 2,
681
+ class: normalizeClass(["magic-editor-icon", __props.icon])
682
+ }, null, 2)) : (openBlock(), createBlock(unref(TMagicIcon), {
683
+ key: 3,
684
+ class: "magic-editor-icon"
685
+ }, {
686
+ default: withCtx(() => [
687
+ (openBlock(), createBlock(resolveDynamicComponent(toRaw(__props.icon))))
688
+ ]),
689
+ _: 1
690
+ }));
691
+ };
692
+ }
693
+ });
694
+
695
+ var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
696
+ ColumnLayout2["LEFT"] = "left";
697
+ ColumnLayout2["CENTER"] = "center";
698
+ ColumnLayout2["RIGHT"] = "right";
699
+ return ColumnLayout2;
700
+ })(ColumnLayout || {});
701
+ var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
702
+ LayerOffset2["TOP"] = "top";
703
+ LayerOffset2["BOTTOM"] = "bottom";
704
+ return LayerOffset2;
705
+ })(LayerOffset || {});
706
+ var Layout = /* @__PURE__ */ ((Layout2) => {
707
+ Layout2["FLEX"] = "flex";
708
+ Layout2["FIXED"] = "fixed";
709
+ Layout2["RELATIVE"] = "relative";
710
+ Layout2["ABSOLUTE"] = "absolute";
711
+ return Layout2;
712
+ })(Layout || {});
713
+ var Keys = /* @__PURE__ */ ((Keys2) => {
714
+ Keys2["ESCAPE"] = "Space";
715
+ return Keys2;
716
+ })(Keys || {});
717
+ const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
718
+ const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
719
+ var CodeEditorMode = /* @__PURE__ */ ((CodeEditorMode2) => {
720
+ CodeEditorMode2["LIST"] = "list";
721
+ CodeEditorMode2["EDITOR"] = "editor";
722
+ return CodeEditorMode2;
723
+ })(CodeEditorMode || {});
724
+ var CodeDeleteErrorType = /* @__PURE__ */ ((CodeDeleteErrorType2) => {
725
+ CodeDeleteErrorType2["UNDELETEABLE"] = "undeleteable";
726
+ CodeDeleteErrorType2["BIND"] = "bind";
727
+ return CodeDeleteErrorType2;
728
+ })(CodeDeleteErrorType || {});
729
+ const CODE_DRAFT_STORAGE_KEY = "magicCodeDraft";
730
+
537
731
  const log = (...args) => {
538
732
  if (process.env.NODE_ENV === "development") {
539
733
  console.log("magic editor: ", ...args);
@@ -663,6 +857,10 @@ class BaseService extends EventEmitter {
663
857
  this.pluginOptionsList[methodName2].push(method);
664
858
  });
665
859
  }
860
+ removeAllPlugins() {
861
+ this.pluginOptionsList = {};
862
+ this.middleware = {};
863
+ }
666
864
  async doTask() {
667
865
  this.doingTask = true;
668
866
  let task = this.taskList.shift();
@@ -682,7 +880,8 @@ class CodeBlock extends BaseService {
682
880
  editable: true,
683
881
  mode: CodeEditorMode.EDITOR,
684
882
  combineIds: [],
685
- undeletableList: []
883
+ undeletableList: [],
884
+ relations: {}
686
885
  });
687
886
  constructor() {
688
887
  super([
@@ -700,31 +899,40 @@ class CodeBlock extends BaseService {
700
899
  "deleteCodeDslByIds"
701
900
  ]);
702
901
  }
703
- async setCodeDsl(codeDsl) {
704
- this.state.codeDsl = codeDsl;
902
+ async setCodeDsl(codeDsl2) {
903
+ this.state.codeDsl = codeDsl2;
705
904
  await editorService.setCodeDsl(this.state.codeDsl);
706
905
  info("[code-block]:code-dsl-change", this.state.codeDsl);
707
906
  this.emit("code-dsl-change", this.state.codeDsl);
708
907
  }
709
908
  async getCodeDsl(forceRefresh = false) {
909
+ return this.getCodeDslSync(forceRefresh);
910
+ }
911
+ getCodeDslSync(forceRefresh = false) {
710
912
  if (!this.state.codeDsl || forceRefresh) {
711
- this.state.codeDsl = await editorService.getCodeDsl();
913
+ this.state.codeDsl = editorService.getCodeDslSync();
712
914
  }
713
915
  return this.state.codeDsl;
714
916
  }
715
- async getCodeContentById(id) {
716
- if (!id)
917
+ async getCodeContentById(id2) {
918
+ if (!id2)
717
919
  return null;
718
920
  const totalCodeDsl = await this.getCodeDsl();
719
921
  if (!totalCodeDsl)
720
922
  return null;
721
- return totalCodeDsl[id] ?? null;
923
+ return totalCodeDsl[id2] ?? null;
722
924
  }
723
925
  async setCodeDslById(id, codeConfig) {
724
926
  let codeDsl = await this.getCodeDsl();
927
+ const codeConfigProcessed = codeConfig;
928
+ if (codeConfig.content) {
929
+ codeConfigProcessed.content = eval(codeConfig.content);
930
+ }
725
931
  if (!codeDsl) {
726
932
  codeDsl = {
727
- [id]: codeConfig
933
+ [id]: {
934
+ ...codeConfigProcessed
935
+ }
728
936
  };
729
937
  } else {
730
938
  const existContent = codeDsl[id] || {};
@@ -732,15 +940,15 @@ class CodeBlock extends BaseService {
732
940
  ...codeDsl,
733
941
  [id]: {
734
942
  ...existContent,
735
- ...codeConfig
943
+ ...codeConfigProcessed
736
944
  }
737
945
  };
738
946
  }
739
947
  await this.setCodeDsl(codeDsl);
740
948
  }
741
949
  async getCodeDslByIds(ids) {
742
- const codeDsl = await this.getCodeDsl();
743
- return pick(codeDsl, ids);
950
+ const codeDsl2 = await this.getCodeDsl();
951
+ return pick(codeDsl2, ids);
744
952
  }
745
953
  async setCodeEditorShowStatus(status) {
746
954
  this.state.isShowCodeEditor = status;
@@ -748,10 +956,10 @@ class CodeBlock extends BaseService {
748
956
  getCodeEditorShowStatus() {
749
957
  return this.state.isShowCodeEditor;
750
958
  }
751
- setCodeEditorContent(status, id) {
752
- if (!id)
959
+ setCodeEditorContent(status, id2) {
960
+ if (!id2)
753
961
  return;
754
- this.setId(id);
962
+ this.setId(id2);
755
963
  this.state.isShowCodeEditor = status;
756
964
  }
757
965
  async getCurrentDsl() {
@@ -763,10 +971,10 @@ class CodeBlock extends BaseService {
763
971
  async setEditStatus(status) {
764
972
  this.state.editable = status;
765
973
  }
766
- setId(id) {
767
- if (!id)
974
+ setId(id2) {
975
+ if (!id2)
768
976
  return;
769
- this.state.id = id;
977
+ this.state.id = id2;
770
978
  }
771
979
  getId() {
772
980
  return this.state.id;
@@ -783,61 +991,17 @@ class CodeBlock extends BaseService {
783
991
  getCombineIds() {
784
992
  return this.state.combineIds;
785
993
  }
786
- async setCombineRelation(compId, diffCodeIds, opFlag, hook) {
787
- const codeDsl = cloneDeep(await this.getCodeDsl());
788
- if (!codeDsl)
789
- return;
790
- if (opFlag === CodeSelectOp.DELETE) {
791
- try {
792
- diffCodeIds.forEach((codeId) => {
793
- const compsContent = codeDsl[codeId].comps;
794
- const index = compsContent?.[compId].findIndex((item) => item === hook);
795
- if (typeof index !== "undefined" && index !== -1) {
796
- compsContent?.[compId].splice(index, 1);
797
- }
798
- });
799
- } catch (e) {
800
- error(e);
801
- throw new Error("\u89E3\u7ED1\u4EE3\u7801\u5757\u5931\u8D25");
802
- }
803
- } else if (opFlag === CodeSelectOp.ADD) {
804
- try {
805
- diffCodeIds.forEach((codeId) => {
806
- const compsContent = codeDsl[codeId].comps;
807
- const existHooks = compsContent?.[compId];
808
- if (isEmpty(existHooks)) {
809
- codeDsl[codeId].comps = {
810
- ...codeDsl[codeId].comps || {},
811
- [compId]: [hook]
812
- };
813
- } else {
814
- existHooks?.push(hook);
815
- }
816
- });
817
- } catch (e) {
818
- error(e);
819
- throw new Error("\u7ED1\u5B9A\u4EE3\u7801\u5757\u5931\u8D25");
820
- }
821
- } else if (opFlag === CodeSelectOp.CHANGE) {
822
- forIn(codeDsl, (codeBlockContent, codeId) => {
823
- if (codeId === diffCodeIds[0]) {
824
- codeBlockContent.comps = {
825
- ...codeBlockContent?.comps || {},
826
- [compId]: [hook]
827
- };
828
- } else if (isEmpty(diffCodeIds) || codeId !== diffCodeIds[0]) {
829
- const compHooks = codeBlockContent?.comps?.[compId];
830
- if (!compHooks)
831
- return true;
832
- const index = compHooks.findIndex((hookName) => hookName === hook);
833
- if (index !== -1) {
834
- compHooks.splice(index, 1);
835
- return false;
836
- }
837
- }
838
- });
839
- }
840
- this.setCodeDsl(codeDsl);
994
+ refreshCombineInfo() {
995
+ const root = editorService.get("root");
996
+ if (!root)
997
+ return null;
998
+ const relations = {};
999
+ this.recurseMNode(root, relations);
1000
+ this.state.relations = relations;
1001
+ return this.state.relations;
1002
+ }
1003
+ getCombineInfo() {
1004
+ return this.state.relations;
841
1005
  }
842
1006
  getUndeletableList() {
843
1007
  return this.state.undeletableList;
@@ -845,6 +1009,15 @@ class CodeBlock extends BaseService {
845
1009
  async setUndeleteableList(codeIds) {
846
1010
  this.state.undeletableList = codeIds;
847
1011
  }
1012
+ setCodeDraft(codeId, content) {
1013
+ globalThis.localStorage.setItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`, content);
1014
+ }
1015
+ getCodeDraft(codeId) {
1016
+ return globalThis.localStorage.getItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
1017
+ }
1018
+ removeCodeDraft(codeId) {
1019
+ globalThis.localStorage.removeItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
1020
+ }
848
1021
  async deleteCodeDslByIds(codeIds) {
849
1022
  const currentDsl = await this.getCodeDsl();
850
1023
  const newDsl = omit(currentDsl, codeIds);
@@ -860,13 +1033,13 @@ class CodeBlock extends BaseService {
860
1033
  return await this.getUniqueId();
861
1034
  }
862
1035
  async deleteCompsInRelation(node) {
863
- const codeDsl = cloneDeep(await this.getCodeDsl());
864
- if (!codeDsl)
1036
+ const codeDsl2 = cloneDeep(await this.getCodeDsl());
1037
+ if (!codeDsl2)
865
1038
  return;
866
- this.recurseNodes(node, codeDsl);
867
- this.setCodeDsl(codeDsl);
1039
+ this.refreshRelationDeep(node, codeDsl2);
1040
+ this.setCodeDsl(codeDsl2);
868
1041
  }
869
- destroy() {
1042
+ resetState() {
870
1043
  this.state.isShowCodeEditor = false;
871
1044
  this.state.codeDsl = null;
872
1045
  this.state.id = "";
@@ -875,16 +1048,44 @@ class CodeBlock extends BaseService {
875
1048
  this.state.combineIds = [];
876
1049
  this.state.undeletableList = [];
877
1050
  }
878
- recurseNodes(node, codeDsl) {
879
- if (!node.id)
880
- return;
881
- forIn(codeDsl, (codeBlockContent) => {
882
- const compsContent = codeBlockContent.comps || {};
883
- codeBlockContent.comps = omit(compsContent, node.id);
1051
+ destroy() {
1052
+ this.resetState();
1053
+ this.removeAllListeners();
1054
+ this.removeAllPlugins();
1055
+ }
1056
+ refreshRelationDeep(node, codeDsl2) {
1057
+ if (!node.id)
1058
+ return;
1059
+ forIn(codeDsl2, (codeBlockContent) => {
1060
+ const compsContent = codeBlockContent.comps || {};
1061
+ codeBlockContent.comps = omit(compsContent, node.id);
1062
+ });
1063
+ if (!isEmpty(node.items)) {
1064
+ node.items.forEach((item) => {
1065
+ this.refreshRelationDeep(item, codeDsl2);
1066
+ });
1067
+ }
1068
+ }
1069
+ recurseMNode(node, relations) {
1070
+ forIn(node, (value, key) => {
1071
+ if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
1072
+ value.hookData.forEach((relationItem) => {
1073
+ if (!relationItem.codeId)
1074
+ return;
1075
+ if (!relations[relationItem.codeId]) {
1076
+ relations[relationItem.codeId] = {};
1077
+ }
1078
+ const codeItem = relations[relationItem.codeId];
1079
+ if (isEmpty(codeItem[node.id])) {
1080
+ codeItem[node.id] = [];
1081
+ }
1082
+ codeItem[node.id].push(key);
1083
+ });
1084
+ }
884
1085
  });
885
1086
  if (!isEmpty(node.items)) {
886
1087
  node.items.forEach((item) => {
887
- this.recurseNodes(item, codeDsl);
1088
+ this.recurseMNode(item, relations);
888
1089
  });
889
1090
  }
890
1091
  }
@@ -968,8 +1169,9 @@ class History extends BaseService {
968
1169
  this.state.pageSteps[this.state.pageId] = undoRedo;
969
1170
  }
970
1171
  this.setCanUndoRedo();
1172
+ this.emit("page-change", this.state.pageSteps[this.state.pageId]);
971
1173
  }
972
- empty() {
1174
+ resetState() {
973
1175
  this.state.pageId = void 0;
974
1176
  this.state.pageSteps = {};
975
1177
  this.state.canRedo = false;
@@ -1000,8 +1202,9 @@ class History extends BaseService {
1000
1202
  return state;
1001
1203
  }
1002
1204
  destroy() {
1003
- this.empty();
1205
+ this.resetState();
1004
1206
  this.removeAllListeners();
1207
+ this.removeAllPlugins();
1005
1208
  }
1006
1209
  getUndoRedo() {
1007
1210
  if (!this.state.pageId)
@@ -1081,6 +1284,7 @@ class WebStorage extends BaseService {
1081
1284
  }
1082
1285
  destroy() {
1083
1286
  this.removeAllListeners();
1287
+ this.removeAllPlugins();
1084
1288
  }
1085
1289
  getValueAndProtocol(value) {
1086
1290
  let protocol2 = "";
@@ -1253,6 +1457,10 @@ const fixNodePosition = (config, parent, stage) => {
1253
1457
  left: fixNodeLeft(config, parent, stage?.renderer.contentWindow?.document)
1254
1458
  };
1255
1459
  };
1460
+ const serializeConfig = (config) => serialize(config, {
1461
+ space: 2,
1462
+ unsafe: true
1463
+ }).replace(/"(\w+)":\s/g, "$1: ");
1256
1464
 
1257
1465
  class Props extends BaseService {
1258
1466
  state = reactive({
@@ -1294,7 +1502,7 @@ class Props extends BaseService {
1294
1502
  this.setPropsValue(toLine(type), values[type]);
1295
1503
  });
1296
1504
  }
1297
- setPropsValue(type, value) {
1505
+ async setPropsValue(type, value) {
1298
1506
  this.state.propsValueMap[type] = value;
1299
1507
  }
1300
1508
  async getPropsValue(type, { inputEvent, ...defaultValue } = {}) {
@@ -1348,10 +1556,14 @@ class Props extends BaseService {
1348
1556
  name: type
1349
1557
  };
1350
1558
  }
1351
- destroy() {
1559
+ resetState() {
1352
1560
  this.state.propsConfigMap = {};
1353
1561
  this.state.propsValueMap = {};
1562
+ }
1563
+ destroy() {
1564
+ this.resetState();
1354
1565
  this.removeAllListeners();
1566
+ this.removeAllPlugins();
1355
1567
  }
1356
1568
  guid(digit = 8) {
1357
1569
  return "x".repeat(digit).replace(/[xy]/g, (c) => {
@@ -1426,6 +1638,13 @@ const getAddParent = (node) => {
1426
1638
  }
1427
1639
  return parentNode;
1428
1640
  };
1641
+ const getDefaultConfig = async (addNode, parentNode) => {
1642
+ const { type, inputEvent, ...config } = addNode;
1643
+ const layout = await editorService.getLayout(toRaw(parentNode), addNode);
1644
+ const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
1645
+ newNode.style = getInitPositionStyle(newNode.style, layout);
1646
+ return newNode;
1647
+ };
1429
1648
 
1430
1649
  class Editor$1 extends BaseService {
1431
1650
  state = reactive({
@@ -1455,7 +1674,7 @@ class Editor$1 extends BaseService {
1455
1674
  "copy",
1456
1675
  "paste",
1457
1676
  "doPaste",
1458
- "duAlignCenter",
1677
+ "doAlignCenter",
1459
1678
  "alignCenter",
1460
1679
  "moveLayer",
1461
1680
  "moveToContainer",
@@ -1536,7 +1755,7 @@ class Editor$1 extends BaseService {
1536
1755
  if (page) {
1537
1756
  historyService.changePage(toRaw(page));
1538
1757
  } else {
1539
- historyService.empty();
1758
+ historyService.resetState();
1540
1759
  }
1541
1760
  if (node?.id) {
1542
1761
  this.get("stage")?.renderer.runtime?.getApp?.()?.emit(
@@ -1634,6 +1853,9 @@ class Editor$1 extends BaseService {
1634
1853
  }
1635
1854
  const newNodes = await Promise.all(
1636
1855
  addNodes.map((node) => {
1856
+ if (isPage(node)) {
1857
+ return this.doAdd(node, this.get("root"));
1858
+ }
1637
1859
  const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(node);
1638
1860
  if (!parentNode)
1639
1861
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
@@ -1652,7 +1874,9 @@ class Editor$1 extends BaseService {
1652
1874
  stage?.select(newNodes[0].id);
1653
1875
  }
1654
1876
  }
1655
- this.pushHistoryState();
1877
+ if (!isPage(newNodes[0])) {
1878
+ this.pushHistoryState();
1879
+ }
1656
1880
  this.emit("add", newNodes);
1657
1881
  return Array.isArray(addNode) ? newNodes : newNodes[0];
1658
1882
  }
@@ -1694,7 +1918,9 @@ class Editor$1 extends BaseService {
1694
1918
  async remove(nodeOrNodeList) {
1695
1919
  const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
1696
1920
  await Promise.all(nodes.map((node) => this.doRemove(node)));
1697
- this.pushHistoryState();
1921
+ if (!isPage(nodes[0])) {
1922
+ this.pushHistoryState();
1923
+ }
1698
1924
  this.emit("remove", nodes);
1699
1925
  }
1700
1926
  async doUpdate(config) {
@@ -1706,6 +1932,9 @@ class Editor$1 extends BaseService {
1706
1932
  const node = cloneDeep(toRaw(info.node));
1707
1933
  let newConfig = await this.toggleFixedPosition(toRaw(config), node, this.get("root"));
1708
1934
  newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue) => {
1935
+ if (isObject(srcValue) && Array.isArray(objValue)) {
1936
+ return srcValue;
1937
+ }
1709
1938
  if (Array.isArray(srcValue)) {
1710
1939
  return srcValue;
1711
1940
  }
@@ -1729,10 +1958,10 @@ class Editor$1 extends BaseService {
1729
1958
  newConfig = setLayout(newConfig, newLayout);
1730
1959
  }
1731
1960
  parentNodeItems[index] = newConfig;
1732
- const nodes = this.get("nodes");
1961
+ const nodes = this.get("nodes") || [];
1733
1962
  const targetIndex = nodes.findIndex((nodeItem) => `${nodeItem.id}` === `${newConfig.id}`);
1734
1963
  nodes.splice(targetIndex, 1, newConfig);
1735
- this.set("nodes", nodes);
1964
+ this.set("nodes", [...nodes]);
1736
1965
  this.get("stage")?.update({
1737
1966
  config: cloneDeep(newConfig),
1738
1967
  parentId: parent.id,
@@ -1749,6 +1978,7 @@ class Editor$1 extends BaseService {
1749
1978
  const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
1750
1979
  this.pushHistoryState();
1751
1980
  this.emit("update", newNodes);
1981
+ codeBlockService.refreshCombineInfo();
1752
1982
  return Array.isArray(config) ? newNodes : newNodes[0];
1753
1983
  }
1754
1984
  async sort(id1, id2) {
@@ -1779,7 +2009,7 @@ class Editor$1 extends BaseService {
1779
2009
  if (!Array.isArray(config))
1780
2010
  return;
1781
2011
  const pasteConfigs = await this.doPaste(config, position);
1782
- return this.add(pasteConfigs);
2012
+ return this.add(pasteConfigs, this.get("parent"));
1783
2013
  }
1784
2014
  async doPaste(config, position = {}) {
1785
2015
  const pasteConfigs = await beforePaste(position, cloneDeep(config));
@@ -1814,7 +2044,11 @@ class Editor$1 extends BaseService {
1814
2044
  const stage = this.get("stage");
1815
2045
  const newNodes = await Promise.all(nodes.map((node) => this.doAlignCenter(node)));
1816
2046
  const newNode = await this.update(newNodes);
1817
- await stage?.multiSelect(newNodes.map((node) => node.id));
2047
+ if (newNodes.length > 1) {
2048
+ await stage?.multiSelect(newNodes.map((node) => node.id));
2049
+ } else {
2050
+ await stage?.select(newNodes[0].id);
2051
+ }
1818
2052
  return newNode;
1819
2053
  }
1820
2054
  async moveLayer(offset) {
@@ -1900,8 +2134,7 @@ class Editor$1 extends BaseService {
1900
2134
  }
1901
2135
  });
1902
2136
  }
1903
- destroy() {
1904
- this.removeAllListeners();
2137
+ resetState() {
1905
2138
  this.set("root", null);
1906
2139
  this.set("node", null);
1907
2140
  this.set("nodes", []);
@@ -1912,6 +2145,11 @@ class Editor$1 extends BaseService {
1912
2145
  this.set("modifiedNodeIds", /* @__PURE__ */ new Map());
1913
2146
  this.set("pageLength", /* @__PURE__ */ new Map());
1914
2147
  }
2148
+ destroy() {
2149
+ this.removeAllListeners();
2150
+ this.resetState();
2151
+ this.removeAllPlugins();
2152
+ }
1915
2153
  resetModifiedNodeId() {
1916
2154
  this.get("modifiedNodeIds").clear();
1917
2155
  }
@@ -1921,6 +2159,12 @@ class Editor$1 extends BaseService {
1921
2159
  return null;
1922
2160
  return root.codeBlocks || null;
1923
2161
  }
2162
+ getCodeDslSync() {
2163
+ const root = this.get("root");
2164
+ if (!root)
2165
+ return null;
2166
+ return root.codeBlocks || null;
2167
+ }
1924
2168
  async setCodeDsl(codeDsl) {
1925
2169
  if (!this.state.root)
1926
2170
  return;
@@ -2032,10 +2276,14 @@ class Events extends BaseService {
2032
2276
  getMethod(type) {
2033
2277
  return cloneDeep(methodMap[type] || DEFAULT_METHODS);
2034
2278
  }
2035
- destroy() {
2279
+ resetState() {
2036
2280
  eventMap = reactive({});
2037
2281
  methodMap = reactive({});
2282
+ }
2283
+ destroy() {
2284
+ this.resetState();
2038
2285
  this.removeAllListeners();
2286
+ this.removeAllPlugins();
2039
2287
  }
2040
2288
  }
2041
2289
  const eventsService = new Events();
@@ -2235,14 +2483,14 @@ const fillConfig = (config = []) => [
2235
2483
  {
2236
2484
  name: "created",
2237
2485
  text: "created",
2238
- type: "code-select",
2239
- labelWidth: "100px"
2486
+ labelWidth: "100px",
2487
+ type: "code-select"
2240
2488
  },
2241
2489
  {
2242
2490
  name: "mounted",
2243
2491
  text: "mounted",
2244
- type: "code-select",
2245
- labelWidth: "100px"
2492
+ labelWidth: "100px",
2493
+ type: "code-select"
2246
2494
  }
2247
2495
  ]
2248
2496
  }
@@ -2310,8 +2558,19 @@ class Ui extends BaseService {
2310
2558
  }
2311
2559
  return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
2312
2560
  }
2561
+ resetState() {
2562
+ this.set("showSrc", false);
2563
+ this.set("uiSelectMode", false);
2564
+ this.set("zoom", 1);
2565
+ this.set("stageContainerRect", {
2566
+ width: 0,
2567
+ height: 0
2568
+ });
2569
+ }
2313
2570
  destroy() {
2571
+ this.resetState();
2314
2572
  this.removeAllListeners();
2573
+ this.removeAllPlugins();
2315
2574
  }
2316
2575
  async setStageRect(value) {
2317
2576
  state.stageRect = {
@@ -2354,12 +2613,14 @@ const useStage = (stageOptions) => {
2354
2613
  getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
2355
2614
  ]);
2356
2615
  stage.on("select", (el) => {
2616
+ if (`${editorService.get("node")?.id}` === el.id && editorService.get("nodes").length === 1)
2617
+ return;
2357
2618
  editorService.select(el.id);
2358
2619
  });
2359
2620
  stage.on("highlight", (el) => {
2360
2621
  editorService.highlight(el.id);
2361
2622
  });
2362
- stage.on("multiSelect", (els) => {
2623
+ stage.on("multi-select", (els) => {
2363
2624
  editorService.multiSelect(els.map((el) => el.id));
2364
2625
  });
2365
2626
  stage.on("update", (ev) => {
@@ -2374,7 +2635,12 @@ const useStage = (stageOptions) => {
2374
2635
  stage.on("sort", (ev) => {
2375
2636
  editorService.sort(ev.src, ev.dist);
2376
2637
  });
2377
- stage.on("changeGuides", (e) => {
2638
+ stage.on("select-parent", () => {
2639
+ const parent = editorService.get("parent");
2640
+ editorService.select(parent);
2641
+ editorService.get("stage").select(parent.id);
2642
+ });
2643
+ stage.on("change-guides", (e) => {
2378
2644
  uiService.set("showGuides", true);
2379
2645
  if (!root.value || !page.value)
2380
2646
  return;
@@ -2390,11 +2656,14 @@ const useStage = (stageOptions) => {
2390
2656
  return stage;
2391
2657
  };
2392
2658
 
2393
- const _hoisted_1$b = { class: "m-editor-empty-panel" };
2394
- const _hoisted_2$5 = { class: "m-editor-empty-content" };
2395
- const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2396
- const _sfc_main$n = /* @__PURE__ */ defineComponent({
2397
- __name: "AddPageBox",
2659
+ const _hoisted_1$d = { class: "m-editor-empty-panel" };
2660
+ const _hoisted_2$7 = { class: "m-editor-empty-content" };
2661
+ const _hoisted_3$4 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2662
+ const __default__$l = defineComponent({
2663
+ name: "MEditorAddPageBox"
2664
+ });
2665
+ const _sfc_main$m = /* @__PURE__ */ defineComponent({
2666
+ ...__default__$l,
2398
2667
  setup(__props) {
2399
2668
  const services = inject("services");
2400
2669
  const clickHandler = () => {
@@ -2407,22 +2676,16 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
2407
2676
  });
2408
2677
  };
2409
2678
  return (_ctx, _cache) => {
2410
- const _component_el_icon = resolveComponent("el-icon");
2411
- return openBlock(), createElementBlock("div", _hoisted_1$b, [
2412
- createElementVNode("div", _hoisted_2$5, [
2679
+ return openBlock(), createElementBlock("div", _hoisted_1$d, [
2680
+ createElementVNode("div", _hoisted_2$7, [
2413
2681
  createElementVNode("div", {
2414
2682
  class: "m-editor-empty-button",
2415
2683
  onClick: clickHandler
2416
2684
  }, [
2417
2685
  createElementVNode("div", null, [
2418
- createVNode(_component_el_icon, null, {
2419
- default: withCtx(() => [
2420
- createVNode(unref(Plus))
2421
- ]),
2422
- _: 1
2423
- })
2686
+ createVNode(_sfc_main$n, { icon: unref(Plus) }, null, 8, ["icon"])
2424
2687
  ]),
2425
- _hoisted_3$2
2688
+ _hoisted_3$4
2426
2689
  ])
2427
2690
  ])
2428
2691
  ]);
@@ -2430,137 +2693,12 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
2430
2693
  }
2431
2694
  });
2432
2695
 
2433
- const _sfc_main$m = /* @__PURE__ */ defineComponent({
2434
- __name: "Resizer",
2435
- emits: ["change"],
2436
- setup(__props, { emit }) {
2437
- const target = ref();
2438
- let getso;
2439
- onMounted(() => {
2440
- if (!target.value)
2441
- return;
2442
- getso = new Gesto(target.value, {
2443
- container: window,
2444
- pinchOutside: true
2445
- }).on("drag", (e) => {
2446
- if (!target.value)
2447
- return;
2448
- emit("change", e.deltaX);
2449
- });
2450
- });
2451
- onUnmounted(() => {
2452
- getso?.unset();
2453
- });
2454
- return (_ctx, _cache) => {
2455
- return openBlock(), createElementBlock("span", {
2456
- ref_key: "target",
2457
- ref: target,
2458
- class: "m-editor-resizer"
2459
- }, [
2460
- renderSlot(_ctx.$slots, "default")
2461
- ], 512);
2462
- };
2463
- }
2696
+ const _hoisted_1$c = { class: "m-editor" };
2697
+ const __default__$k = defineComponent({
2698
+ name: "MEditorFramework"
2464
2699
  });
2465
-
2466
2700
  const _sfc_main$l = /* @__PURE__ */ defineComponent({
2467
- __name: "Layout",
2468
- props: {
2469
- left: null,
2470
- right: null,
2471
- minLeft: { default: 1 },
2472
- minRight: { default: 1 },
2473
- leftClass: null,
2474
- rightClass: null,
2475
- centerClass: null
2476
- },
2477
- emits: ["update:left", "change", "update:right"],
2478
- setup(__props, { emit }) {
2479
- const props = __props;
2480
- const el = ref();
2481
- let clientWidth = 0;
2482
- const resizerObserver = new ResizeObserver((entries) => {
2483
- for (const { contentRect } of entries) {
2484
- clientWidth = contentRect.width;
2485
- center.value = clientWidth - (props.left || 0) - (props.right || 0);
2486
- emit("change", {
2487
- left: props.left,
2488
- center: center.value,
2489
- right: props.right
2490
- });
2491
- }
2492
- });
2493
- onMounted(() => {
2494
- if (el.value) {
2495
- resizerObserver.observe(el.value);
2496
- }
2497
- });
2498
- onUnmounted(() => {
2499
- resizerObserver.disconnect();
2500
- });
2501
- const center = ref(0);
2502
- const changeLeft = (deltaX) => {
2503
- if (typeof props.left === "undefined")
2504
- return;
2505
- const left = Math.max(props.left + deltaX, props.minLeft) || 0;
2506
- emit("update:left", left);
2507
- center.value = clientWidth - left - (props.right || 0);
2508
- emit("change", {
2509
- left,
2510
- center: center.value,
2511
- right: props.right
2512
- });
2513
- };
2514
- const changeRight = (deltaX) => {
2515
- if (typeof props.right === "undefined")
2516
- return;
2517
- const right = Math.max(props.right - deltaX, props.minRight) || 0;
2518
- emit("update:right", right);
2519
- center.value = clientWidth - (props.left || 0) - right;
2520
- emit("change", {
2521
- left: props.left,
2522
- center: center.value,
2523
- right
2524
- });
2525
- };
2526
- return (_ctx, _cache) => {
2527
- return openBlock(), createElementBlock("div", {
2528
- ref_key: "el",
2529
- ref: el,
2530
- class: "m-editor-layout"
2531
- }, [
2532
- typeof props.left !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2533
- createElementVNode("div", {
2534
- class: normalizeClass(["m-editor-layout-left", __props.leftClass]),
2535
- style: normalizeStyle(`width: ${__props.left}px`)
2536
- }, [
2537
- renderSlot(_ctx.$slots, "left")
2538
- ], 6),
2539
- createVNode(_sfc_main$m, { onChange: changeLeft })
2540
- ], 64)) : createCommentVNode("", true),
2541
- createElementVNode("div", {
2542
- class: normalizeClass(["m-editor-layout-center", __props.centerClass]),
2543
- style: normalizeStyle(`width: ${center.value}px`)
2544
- }, [
2545
- renderSlot(_ctx.$slots, "center")
2546
- ], 6),
2547
- typeof props.right !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
2548
- createVNode(_sfc_main$m, { onChange: changeRight }),
2549
- createElementVNode("div", {
2550
- class: normalizeClass(["m-editor-layout-right", __props.rightClass]),
2551
- style: normalizeStyle(`width: ${__props.right}px`)
2552
- }, [
2553
- renderSlot(_ctx.$slots, "right")
2554
- ], 6)
2555
- ], 64)) : createCommentVNode("", true)
2556
- ], 512);
2557
- };
2558
- }
2559
- });
2560
-
2561
- const _hoisted_1$a = { class: "m-editor" };
2562
- const _sfc_main$k = /* @__PURE__ */ defineComponent({
2563
- __name: "Framework",
2701
+ ...__default__$k,
2564
2702
  props: {
2565
2703
  codeOptions: { default: () => ({}) }
2566
2704
  },
@@ -2569,48 +2707,64 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2569
2707
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
2570
2708
  const { editorService, uiService } = inject("services") || {};
2571
2709
  const root = computed(() => editorService?.get("root"));
2710
+ const nodes = computed(() => editorService?.get("nodes") || []);
2572
2711
  const pageLength = computed(() => editorService?.get("pageLength") || 0);
2573
2712
  const showSrc = computed(() => uiService?.get("showSrc"));
2713
+ const LEFT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorLeftColumnWidthData";
2714
+ const RIGHT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorRightColumnWidthData";
2715
+ const leftColumnWidthCacheData = Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY));
2716
+ const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY));
2574
2717
  const columnWidth = ref({
2575
- left: DEFAULT_LEFT_COLUMN_WIDTH,
2718
+ left: leftColumnWidthCacheData,
2576
2719
  center: 0,
2577
- right: 0
2720
+ right: RightColumnWidthCacheData
2578
2721
  });
2579
- uiService?.set("columnWidth", columnWidth.value);
2580
- watchEffect(() => {
2581
- if (pageLength.value <= 0) {
2582
- columnWidth.value.right = void 0;
2583
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH;
2584
- } else {
2585
- columnWidth.value.right = columnWidth.value.right || DEFAULT_RIGHT_COLUMN_WIDTH;
2586
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH;
2722
+ watch(
2723
+ pageLength,
2724
+ (length) => {
2725
+ const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
2726
+ columnWidth.value.left = left;
2727
+ if (length <= 0) {
2728
+ columnWidth.value.right = void 0;
2729
+ columnWidth.value.center = globalThis.document.body.clientWidth - left;
2730
+ } else {
2731
+ const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
2732
+ columnWidth.value.right = right;
2733
+ columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
2734
+ }
2735
+ uiService?.set("columnWidth", columnWidth);
2736
+ },
2737
+ {
2738
+ immediate: true
2587
2739
  }
2588
- });
2589
- const saveCode = (value) => {
2590
- try {
2591
- editorService?.set("root", eval(value));
2592
- } catch (e) {
2593
- console.error(e);
2740
+ );
2741
+ watch(
2742
+ () => columnWidth.value.right,
2743
+ (right) => {
2744
+ if (typeof right === "undefined")
2745
+ return;
2746
+ globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${right}`);
2594
2747
  }
2748
+ );
2749
+ watch(
2750
+ () => columnWidth.value.left,
2751
+ (left) => {
2752
+ globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
2753
+ }
2754
+ );
2755
+ const columnWidthChange = (columnWidth2) => {
2756
+ uiService?.set("columnWidth", columnWidth2);
2595
2757
  };
2596
- const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
2597
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
2598
- if (columnWidthCacheData) {
2758
+ const saveCode = (value) => {
2599
2759
  try {
2600
- const columnWidthCache = JSON.parse(columnWidthCacheData);
2601
- columnWidth.value = columnWidthCache;
2760
+ editorService?.set("root", eval(value));
2602
2761
  } catch (e) {
2603
2762
  console.error(e);
2604
2763
  }
2605
- }
2606
- const columnWidthChange = (columnWidth2) => {
2607
- uiService?.set("columnWidth", columnWidth2);
2608
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth2));
2609
2764
  };
2610
2765
  return (_ctx, _cache) => {
2611
2766
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
2612
- const _component_el_scrollbar = resolveComponent("el-scrollbar");
2613
- return openBlock(), createElementBlock("div", _hoisted_1$a, [
2767
+ return openBlock(), createElementBlock("div", _hoisted_1$c, [
2614
2768
  renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2615
2769
  unref(showSrc) ? (openBlock(), createBlock(_component_magic_code_editor, {
2616
2770
  key: 0,
@@ -2618,95 +2772,57 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2618
2772
  "init-values": unref(root),
2619
2773
  options: __props.codeOptions,
2620
2774
  onSave: saveCode
2621
- }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$l, {
2775
+ }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$o, {
2622
2776
  key: 1,
2623
2777
  class: "m-editor-content",
2624
2778
  "left-class": "m-editor-framework-left",
2625
- "center-class": "m-editor-framework-center",
2626
- "right-class": "m-editor-framework-right",
2627
- left: columnWidth.value.left,
2628
- "onUpdate:left": _cache[0] || (_cache[0] = ($event) => columnWidth.value.left = $event),
2629
- right: columnWidth.value.right,
2630
- "onUpdate:right": _cache[1] || (_cache[1] = ($event) => columnWidth.value.right = $event),
2631
- "min-left": 45,
2632
- "min-right": 1,
2633
- onChange: columnWidthChange
2634
- }, createSlots({
2635
- left: withCtx(() => [
2636
- renderSlot(_ctx.$slots, "sidebar")
2637
- ]),
2638
- center: withCtx(() => [
2639
- unref(pageLength) > 0 ? renderSlot(_ctx.$slots, "workspace", { key: 0 }) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
2640
- createVNode(_sfc_main$n)
2641
- ])
2642
- ]),
2643
- _: 2
2644
- }, [
2645
- unref(pageLength) > 0 ? {
2646
- name: "right",
2647
- fn: withCtx(() => [
2648
- createVNode(_component_el_scrollbar, null, {
2649
- default: withCtx(() => [
2650
- renderSlot(_ctx.$slots, "props-panel")
2651
- ]),
2652
- _: 3
2653
- })
2654
- ])
2655
- } : void 0
2656
- ]), 1032, ["left", "right"]))
2657
- ]);
2658
- };
2659
- }
2660
- });
2661
-
2662
- const _hoisted_1$9 = ["src"];
2663
- const _sfc_main$j = /* @__PURE__ */ defineComponent({
2664
- __name: "Icon",
2665
- props: {
2666
- icon: null
2667
- },
2668
- setup(__props) {
2669
- return (_ctx, _cache) => {
2670
- const _component_el_icon = resolveComponent("el-icon");
2671
- return !__props.icon ? (openBlock(), createBlock(_component_el_icon, {
2672
- key: 0,
2673
- class: "magic-editor-icon"
2674
- }, {
2675
- default: withCtx(() => [
2676
- createVNode(unref(Edit))
2677
- ]),
2678
- _: 1
2679
- })) : typeof __props.icon === "string" && __props.icon.startsWith("http") ? (openBlock(), createBlock(_component_el_icon, {
2680
- key: 1,
2681
- class: "magic-editor-icon"
2682
- }, {
2683
- default: withCtx(() => [
2684
- createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$9)
2685
- ]),
2686
- _: 1
2687
- })) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
2688
- key: 2,
2689
- class: normalizeClass(["magic-editor-icon", __props.icon])
2690
- }, null, 2)) : (openBlock(), createBlock(_component_el_icon, {
2691
- key: 3,
2692
- class: "magic-editor-icon"
2693
- }, {
2694
- default: withCtx(() => [
2695
- (openBlock(), createBlock(resolveDynamicComponent(toRaw(__props.icon))))
2696
- ]),
2697
- _: 1
2698
- }));
2779
+ "center-class": "m-editor-framework-center",
2780
+ "right-class": "m-editor-framework-right",
2781
+ left: columnWidth.value.left,
2782
+ "onUpdate:left": _cache[0] || (_cache[0] = ($event) => columnWidth.value.left = $event),
2783
+ right: columnWidth.value.right,
2784
+ "onUpdate:right": _cache[1] || (_cache[1] = ($event) => columnWidth.value.right = $event),
2785
+ "min-left": 45,
2786
+ "min-right": 1,
2787
+ onChange: columnWidthChange
2788
+ }, createSlots({
2789
+ left: withCtx(() => [
2790
+ renderSlot(_ctx.$slots, "sidebar")
2791
+ ]),
2792
+ center: withCtx(() => [
2793
+ unref(pageLength) > 0 ? renderSlot(_ctx.$slots, "workspace", { key: 0 }) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
2794
+ createVNode(_sfc_main$m)
2795
+ ])
2796
+ ]),
2797
+ _: 2
2798
+ }, [
2799
+ unref(pageLength) > 0 && unref(nodes).length === 1 ? {
2800
+ name: "right",
2801
+ fn: withCtx(() => [
2802
+ createVNode(unref(TMagicScrollbar), null, {
2803
+ default: withCtx(() => [
2804
+ renderSlot(_ctx.$slots, "props-panel")
2805
+ ]),
2806
+ _: 3
2807
+ })
2808
+ ])
2809
+ } : void 0
2810
+ ]), 1032, ["left", "right"]))
2811
+ ]);
2699
2812
  };
2700
2813
  }
2701
2814
  });
2702
2815
 
2703
- const _hoisted_1$8 = {
2816
+ const _hoisted_1$b = {
2704
2817
  key: 1,
2705
2818
  class: "menu-item-text"
2706
2819
  };
2707
- const _hoisted_2$4 = { class: "el-dropdown-link menubar-menu-button" };
2708
- const _sfc_main$i = /* @__PURE__ */ defineComponent({
2709
- __name: "ToolButton",
2820
+ const _hoisted_2$6 = { class: "el-dropdown-link menubar-menu-button" };
2821
+ const __default__$j = defineComponent({
2822
+ name: "MEditorToolButton"
2823
+ });
2824
+ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2825
+ ...__default__$j,
2710
2826
  props: {
2711
2827
  data: { default: () => ({
2712
2828
  type: "text",
@@ -2771,13 +2887,6 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2771
2887
  }
2772
2888
  };
2773
2889
  return (_ctx, _cache) => {
2774
- const _component_el_divider = resolveComponent("el-divider");
2775
- const _component_el_button = resolveComponent("el-button");
2776
- const _component_el_tooltip = resolveComponent("el-tooltip");
2777
- const _component_el_icon = resolveComponent("el-icon");
2778
- const _component_el_dropdown_item = resolveComponent("el-dropdown-item");
2779
- const _component_el_dropdown_menu = resolveComponent("el-dropdown-menu");
2780
- const _component_el_dropdown = resolveComponent("el-dropdown");
2781
2890
  return unref(display) ? (openBlock(), createElementBlock("div", {
2782
2891
  key: 0,
2783
2892
  class: normalizeClass(["menu-item", `${__props.data.type} ${__props.data.className || ""}`]),
@@ -2785,24 +2894,24 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2785
2894
  onMousedown: _cache[1] || (_cache[1] = ($event) => mousedownHandler(__props.data, $event)),
2786
2895
  onMouseup: _cache[2] || (_cache[2] = ($event) => mouseupHandler(__props.data, $event))
2787
2896
  }, [
2788
- __props.data.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
2897
+ __props.data.type === "divider" ? (openBlock(), createBlock(unref(TMagicDivider), {
2789
2898
  key: 0,
2790
2899
  direction: __props.data.direction || "vertical"
2791
- }, null, 8, ["direction"])) : __props.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$8, toDisplayString(__props.data.text), 1)) : __props.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2792
- __props.data.tooltip ? (openBlock(), createBlock(_component_el_tooltip, {
2900
+ }, 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 }, [
2901
+ __props.data.tooltip ? (openBlock(), createBlock(unref(TMagicTooltip), {
2793
2902
  key: 0,
2794
2903
  effect: "dark",
2795
2904
  placement: "bottom-start",
2796
2905
  content: __props.data.tooltip
2797
2906
  }, {
2798
2907
  default: withCtx(() => [
2799
- createVNode(_component_el_button, {
2908
+ createVNode(unref(TMagicButton), {
2800
2909
  size: "small",
2801
2910
  text: "",
2802
2911
  disabled: unref(disabled)
2803
2912
  }, {
2804
2913
  default: withCtx(() => [
2805
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$j, {
2914
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$n, {
2806
2915
  key: 0,
2807
2916
  icon: __props.data.icon
2808
2917
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2812,14 +2921,14 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2812
2921
  }, 8, ["disabled"])
2813
2922
  ]),
2814
2923
  _: 1
2815
- }, 8, ["content"])) : (openBlock(), createBlock(_component_el_button, {
2924
+ }, 8, ["content"])) : (openBlock(), createBlock(unref(TMagicButton), {
2816
2925
  key: 1,
2817
2926
  size: "small",
2818
2927
  text: "",
2819
2928
  disabled: unref(disabled)
2820
2929
  }, {
2821
2930
  default: withCtx(() => [
2822
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$j, {
2931
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$n, {
2823
2932
  key: 0,
2824
2933
  icon: __props.data.icon
2825
2934
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2827,17 +2936,17 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2827
2936
  ]),
2828
2937
  _: 1
2829
2938
  }, 8, ["disabled"]))
2830
- ], 64)) : __props.data.type === "dropdown" ? (openBlock(), createBlock(_component_el_dropdown, {
2939
+ ], 64)) : __props.data.type === "dropdown" ? (openBlock(), createBlock(unref(TMagicDropdown), {
2831
2940
  key: 3,
2832
2941
  trigger: "click",
2833
2942
  disabled: unref(disabled),
2834
2943
  onCommand: dropdownHandler
2835
2944
  }, {
2836
2945
  dropdown: withCtx(() => [
2837
- __props.data.items && __props.data.items.length ? (openBlock(), createBlock(_component_el_dropdown_menu, { key: 0 }, {
2946
+ __props.data.items && __props.data.items.length ? (openBlock(), createBlock(unref(TMagicDropdownMenu), { key: 0 }, {
2838
2947
  default: withCtx(() => [
2839
2948
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.data.items, (subItem, index) => {
2840
- return openBlock(), createBlock(_component_el_dropdown_item, {
2949
+ return openBlock(), createBlock(unref(TMagicDropdownItem), {
2841
2950
  key: index,
2842
2951
  command: { data: __props.data, subItem }
2843
2952
  }, {
@@ -2852,9 +2961,9 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2852
2961
  })) : createCommentVNode("", true)
2853
2962
  ]),
2854
2963
  default: withCtx(() => [
2855
- createElementVNode("span", _hoisted_2$4, [
2964
+ createElementVNode("span", _hoisted_2$6, [
2856
2965
  createTextVNode(toDisplayString(__props.data.text), 1),
2857
- createVNode(_component_el_icon, { class: "el-icon--right" }, {
2966
+ createVNode(unref(TMagicIcon), { class: "el-icon--right" }, {
2858
2967
  default: withCtx(() => [
2859
2968
  createVNode(unref(ArrowDown))
2860
2969
  ]),
@@ -2869,8 +2978,11 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2869
2978
  }
2870
2979
  });
2871
2980
 
2872
- const _sfc_main$h = /* @__PURE__ */ defineComponent({
2873
- __name: "NavMenu",
2981
+ const __default__$i = defineComponent({
2982
+ name: "MEditorNavMenu"
2983
+ });
2984
+ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2985
+ ...__default__$i,
2874
2986
  props: {
2875
2987
  data: { default: () => ({}) },
2876
2988
  height: { default: 35 }
@@ -3025,7 +3137,7 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3025
3137
  style: normalizeStyle(`width: ${unref(columnWidth)?.[key]}px`)
3026
3138
  }, [
3027
3139
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(buttons)[key], (item, index) => {
3028
- return openBlock(), createBlock(_sfc_main$i, {
3140
+ return openBlock(), createBlock(_sfc_main$k, {
3029
3141
  data: item,
3030
3142
  key: index
3031
3143
  }, null, 8, ["data"]);
@@ -3037,9 +3149,12 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3037
3149
  }
3038
3150
  });
3039
3151
 
3040
- const _hoisted_1$7 = { class: "m-editor-props-panel" };
3041
- const _sfc_main$g = /* @__PURE__ */ defineComponent({
3042
- __name: "PropsPanel",
3152
+ const _hoisted_1$a = { class: "m-editor-props-panel" };
3153
+ const __default__$h = defineComponent({
3154
+ name: "MEditorPropsPanel"
3155
+ });
3156
+ const _sfc_main$i = /* @__PURE__ */ defineComponent({
3157
+ ...__default__$h,
3043
3158
  emits: ["mounted"],
3044
3159
  setup(__props, { expose, emit }) {
3045
3160
  const internalInstance = getCurrentInstance();
@@ -3048,7 +3163,9 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
3048
3163
  const curFormConfig = ref([]);
3049
3164
  const services = inject("services");
3050
3165
  const node = computed(() => services?.editorService.get("node"));
3051
- const propsPanelSize = computed(() => services?.uiService.get("propsPanelSize") || "small");
3166
+ const propsPanelSize = computed(
3167
+ () => services?.uiService.get("propsPanelSize") || "small"
3168
+ );
3052
3169
  const stage = computed(() => services?.editorService.get("stage"));
3053
3170
  const init = async () => {
3054
3171
  if (!node.value) {
@@ -3075,21 +3192,15 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
3075
3192
  services?.editorService.update(values2);
3076
3193
  } catch (e) {
3077
3194
  console.error(e);
3078
- ElMessage.closeAll();
3079
- ElMessage.error({
3080
- duration: 1e4,
3081
- showClose: true,
3082
- message: e.message,
3083
- dangerouslyUseHTMLString: true
3084
- });
3195
+ tMagicMessage.closeAll();
3196
+ tMagicMessage.error(e.message);
3085
3197
  }
3086
3198
  };
3087
3199
  expose({ submit });
3088
3200
  return (_ctx, _cache) => {
3089
- const _component_m_form = resolveComponent("m-form");
3090
- return openBlock(), createElementBlock("div", _hoisted_1$7, [
3201
+ return openBlock(), createElementBlock("div", _hoisted_1$a, [
3091
3202
  renderSlot(_ctx.$slots, "props-panel-header"),
3092
- createVNode(_component_m_form, {
3203
+ createVNode(unref(MForm), {
3093
3204
  ref_key: "configForm",
3094
3205
  ref: configForm,
3095
3206
  class: normalizeClass(`m-editor-props-panel ${unref(propsPanelSize)}`),
@@ -3104,43 +3215,328 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
3104
3215
  }
3105
3216
  });
3106
3217
 
3107
- const _hoisted_1$6 = ["id"];
3108
- const _hoisted_2$3 = { class: "list-item" };
3109
- const _hoisted_3$1 = { class: "code-name" };
3110
- const _hoisted_4$1 = { class: "code-name-wrapper" };
3111
- const _hoisted_5$1 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u4EE3\u7801\u5757\u540D\u79F0", -1);
3112
- const _hoisted_6$1 = { class: "m-editor-wrapper" };
3113
- const _hoisted_7$1 = {
3114
- key: 1,
3218
+ const _hoisted_1$9 = {
3219
+ key: 0,
3115
3220
  class: "m-editor-content-bottom"
3116
3221
  };
3117
- const _hoisted_8$1 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
3118
- const _hoisted_9$1 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3119
- const _hoisted_10 = {
3120
- key: 2,
3222
+ const _hoisted_2$5 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
3223
+ const _hoisted_3$3 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3224
+ const _hoisted_4$2 = {
3225
+ key: 1,
3121
3226
  class: "m-editor-content-bottom"
3122
3227
  };
3123
- const _hoisted_11 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3228
+ const _hoisted_5$1 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3229
+ const __default__$g = defineComponent({
3230
+ name: "MEditorCodeDraftEditor"
3231
+ });
3232
+ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3233
+ ...__default__$g,
3234
+ props: {
3235
+ id: null,
3236
+ content: null,
3237
+ editable: { type: Boolean, default: true },
3238
+ autoSaveDraft: { type: Boolean, default: true },
3239
+ codeOptions: null,
3240
+ language: null
3241
+ },
3242
+ emits: ["save", "close", "saveAndClose"],
3243
+ setup(__props, { emit }) {
3244
+ const props = __props;
3245
+ const services = inject("services");
3246
+ const codeContent = ref("");
3247
+ const editorContent = ref("");
3248
+ const codeEditor = ref();
3249
+ const originCodeContent = ref("");
3250
+ const isFullScreen = ref(false);
3251
+ const codeOptions = computed(() => ({
3252
+ ...props.codeOptions,
3253
+ readOnly: !props.editable
3254
+ }));
3255
+ watchEffect(() => {
3256
+ codeContent.value = props.content;
3257
+ if (!originCodeContent.value) {
3258
+ originCodeContent.value = codeContent.value;
3259
+ }
3260
+ const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
3261
+ if (codeDraft) {
3262
+ codeContent.value = codeDraft;
3263
+ }
3264
+ });
3265
+ const saveCodeDraft = async (codeValue) => {
3266
+ if (!props.autoSaveDraft)
3267
+ return;
3268
+ if (originCodeContent.value === codeValue) {
3269
+ services?.codeBlockService.removeCodeDraft(props.id);
3270
+ return;
3271
+ }
3272
+ services?.codeBlockService.setCodeDraft(props.id, codeValue);
3273
+ tMagicMessage.success(`\u4EE3\u7801\u8349\u7A3F\u4FDD\u5B58\u6210\u529F ${datetimeFormatter(new Date())}`);
3274
+ };
3275
+ const saveCode = () => {
3276
+ if (!codeEditor.value || !props.editable)
3277
+ return;
3278
+ editorContent.value = codeEditor.value.getEditor()?.getValue();
3279
+ emit("save", editorContent.value);
3280
+ };
3281
+ const saveAndClose = () => {
3282
+ if (!codeEditor.value || !props.editable)
3283
+ return;
3284
+ editorContent.value = codeEditor.value.getEditor()?.getValue();
3285
+ emit("saveAndClose", editorContent.value);
3286
+ };
3287
+ const close = async () => {
3288
+ const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
3289
+ if (codeDraft) {
3290
+ tMagicMessageBox.confirm("\u60A8\u6709\u4EE3\u7801\u4FEE\u6539\u672A\u4FDD\u5B58\uFF0C\u662F\u5426\u4FDD\u5B58\u540E\u518D\u5173\u95ED\uFF1F", "\u63D0\u793A", {
3291
+ confirmButtonText: "\u786E\u8BA4",
3292
+ cancelButtonText: "\u53D6\u6D88",
3293
+ type: "warning"
3294
+ }).then(async () => {
3295
+ saveAndClose();
3296
+ }).catch(() => {
3297
+ services?.codeBlockService.removeCodeDraft(props.id);
3298
+ emit("close");
3299
+ });
3300
+ } else {
3301
+ emit("close");
3302
+ }
3303
+ };
3304
+ const toggleFullScreen = () => {
3305
+ isFullScreen.value = !isFullScreen.value;
3306
+ if (codeEditor.value) {
3307
+ codeEditor.value.focus();
3308
+ }
3309
+ };
3310
+ return (_ctx, _cache) => {
3311
+ return openBlock(), createElementBlock("div", {
3312
+ class: normalizeClass(["m-editor-wrapper", isFullScreen.value ? "fullScreen" : "normal"])
3313
+ }, [
3314
+ createVNode(_sfc_main$q, {
3315
+ ref_key: "codeEditor",
3316
+ ref: codeEditor,
3317
+ class: "m-editor-container",
3318
+ "init-values": `${codeContent.value}`,
3319
+ onSave: saveCodeDraft,
3320
+ language: __props.language,
3321
+ options: unref(codeOptions)
3322
+ }, null, 8, ["init-values", "language", "options"]),
3323
+ __props.editable ? (openBlock(), createElementBlock("div", _hoisted_1$9, [
3324
+ createVNode(unref(TMagicButton), {
3325
+ type: "primary",
3326
+ class: "button",
3327
+ onClick: toggleFullScreen
3328
+ }, {
3329
+ default: withCtx(() => [
3330
+ createTextVNode(toDisplayString(isFullScreen.value ? "\u9000\u51FA\u5168\u5C4F" : "\u5168\u5C4F"), 1)
3331
+ ]),
3332
+ _: 1
3333
+ }),
3334
+ createVNode(unref(TMagicButton), {
3335
+ type: "primary",
3336
+ class: "button",
3337
+ onClick: saveCode
3338
+ }, {
3339
+ default: withCtx(() => [
3340
+ _hoisted_2$5
3341
+ ]),
3342
+ _: 1
3343
+ }),
3344
+ createVNode(unref(TMagicButton), {
3345
+ type: "primary",
3346
+ class: "button",
3347
+ onClick: close
3348
+ }, {
3349
+ default: withCtx(() => [
3350
+ _hoisted_3$3
3351
+ ]),
3352
+ _: 1
3353
+ })
3354
+ ])) : (openBlock(), createElementBlock("div", _hoisted_4$2, [
3355
+ createVNode(unref(TMagicButton), {
3356
+ type: "primary",
3357
+ class: "button",
3358
+ onClick: toggleFullScreen
3359
+ }, {
3360
+ default: withCtx(() => [
3361
+ createTextVNode(toDisplayString(isFullScreen.value ? "\u9000\u51FA\u5168\u5C4F" : "\u5168\u5C4F"), 1)
3362
+ ]),
3363
+ _: 1
3364
+ }),
3365
+ createVNode(unref(TMagicButton), {
3366
+ type: "primary",
3367
+ class: "button",
3368
+ onClick: close
3369
+ }, {
3370
+ default: withCtx(() => [
3371
+ _hoisted_5$1
3372
+ ]),
3373
+ _: 1
3374
+ })
3375
+ ]))
3376
+ ], 2);
3377
+ };
3378
+ }
3379
+ });
3380
+
3381
+ const _hoisted_1$8 = { class: "code-name-wrapper" };
3382
+ const _hoisted_2$4 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u4EE3\u7801\u5757\u540D\u79F0", -1);
3383
+ const _hoisted_3$2 = { class: "code-name-wrapper" };
3384
+ const _hoisted_4$1 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u53C2\u6570\u5B9A\u4E49", -1);
3385
+ const __default__$f = defineComponent({
3386
+ name: "MEditorFunctionEditor"
3387
+ });
3388
+ const _sfc_main$g = /* @__PURE__ */ defineComponent({
3389
+ ...__default__$f,
3390
+ props: {
3391
+ id: null,
3392
+ name: null,
3393
+ content: null,
3394
+ editable: { type: Boolean, default: true },
3395
+ autoSaveDraft: { type: Boolean, default: true },
3396
+ codeOptions: null
3397
+ },
3398
+ emits: ["change", "field-input"],
3399
+ setup(__props, { emit }) {
3400
+ const props = __props;
3401
+ const tableConfig = {
3402
+ border: true,
3403
+ enableFullscreen: false,
3404
+ name: "params",
3405
+ maxHeight: "150px",
3406
+ items: [
3407
+ {
3408
+ type: "text",
3409
+ label: "\u53C2\u6570\u540D",
3410
+ name: "name"
3411
+ }
3412
+ ]
3413
+ };
3414
+ const services = inject("services");
3415
+ const codeName = ref("");
3416
+ const codeContent = ref("");
3417
+ const evalRes = ref(true);
3418
+ provide("mForm", {
3419
+ $emit: emit,
3420
+ setField: () => {
3421
+ }
3422
+ });
3423
+ const tableModel = ref();
3424
+ watchEffect(() => {
3425
+ codeName.value = props.name;
3426
+ codeContent.value = props.content;
3427
+ });
3428
+ const initTableModel = () => {
3429
+ const codeDsl = services?.codeBlockService.getCodeDslSync();
3430
+ if (!codeDsl)
3431
+ return;
3432
+ tableModel.value = {
3433
+ params: codeDsl[props.id]?.params || []
3434
+ };
3435
+ };
3436
+ initTableModel();
3437
+ const beforeSave = (codeValue) => {
3438
+ try {
3439
+ eval(codeValue);
3440
+ return true;
3441
+ } catch (e) {
3442
+ tMagicMessage.error(e.stack);
3443
+ return false;
3444
+ }
3445
+ };
3446
+ const saveCode = async (codeValue2) => {
3447
+ if (!props.editable)
3448
+ return;
3449
+ evalRes.value = beforeSave(codeValue2);
3450
+ if (evalRes.value) {
3451
+ await services?.codeBlockService.setCodeDslById(props.id, {
3452
+ name: codeName.value,
3453
+ content: codeValue2,
3454
+ params: tableModel.value?.params || []
3455
+ });
3456
+ tMagicMessage.success("\u4EE3\u7801\u4FDD\u5B58\u6210\u529F");
3457
+ services?.codeBlockService.removeCodeDraft(props.id);
3458
+ }
3459
+ };
3460
+ const saveAndClose = async (codeValue2) => {
3461
+ await saveCode(codeValue2);
3462
+ if (evalRes.value) {
3463
+ close();
3464
+ }
3465
+ };
3466
+ const close = () => {
3467
+ services?.codeBlockService.setCodeEditorShowStatus(false);
3468
+ };
3469
+ return (_ctx, _cache) => {
3470
+ const _component_m_form_table = resolveComponent("m-form-table");
3471
+ return openBlock(), createBlock(unref(TMagicCard), { shadow: "never" }, {
3472
+ header: withCtx(() => [
3473
+ createElementVNode("div", _hoisted_1$8, [
3474
+ _hoisted_2$4,
3475
+ createVNode(unref(TMagicInput), {
3476
+ class: "code-name-input",
3477
+ modelValue: codeName.value,
3478
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeName.value = $event),
3479
+ disabled: !__props.editable
3480
+ }, null, 8, ["modelValue", "disabled"])
3481
+ ]),
3482
+ createElementVNode("div", _hoisted_3$2, [
3483
+ _hoisted_4$1,
3484
+ createVNode(_component_m_form_table, {
3485
+ style: { "width": "320px" },
3486
+ config: tableConfig,
3487
+ model: tableModel.value,
3488
+ enableToggleMode: false,
3489
+ name: "params",
3490
+ prop: "params",
3491
+ size: "small"
3492
+ }, null, 8, ["model"])
3493
+ ])
3494
+ ]),
3495
+ default: withCtx(() => [
3496
+ createVNode(_sfc_main$h, {
3497
+ id: __props.id,
3498
+ content: codeContent.value,
3499
+ editable: __props.editable,
3500
+ autoSaveDraft: __props.autoSaveDraft,
3501
+ codeOptions: __props.codeOptions,
3502
+ language: "javascript",
3503
+ onSave: saveCode,
3504
+ onSaveAndClose: saveAndClose,
3505
+ onClose: close
3506
+ }, null, 8, ["id", "content", "editable", "autoSaveDraft", "codeOptions"])
3507
+ ]),
3508
+ _: 1
3509
+ });
3510
+ };
3511
+ }
3512
+ });
3513
+
3514
+ const _hoisted_1$7 = ["id"];
3515
+ const _hoisted_2$3 = { class: "list-item" };
3516
+ const _hoisted_3$1 = { class: "code-name" };
3517
+ const __default__$e = defineComponent({
3518
+ name: "MEditorCodeBlockEditor"
3519
+ });
3124
3520
  const _sfc_main$f = /* @__PURE__ */ defineComponent({
3125
- __name: "CodeBlockEditor",
3521
+ ...__default__$e,
3126
3522
  setup(__props) {
3127
3523
  const services = inject("services");
3128
- const codeEditor = ref();
3524
+ const codeOptions = inject("codeOptions", {});
3129
3525
  const left = ref(200);
3130
3526
  const currentTitle = ref("");
3131
3527
  const codeConfig = ref(null);
3132
3528
  const state = reactive({
3133
3529
  codeList: []
3134
3530
  });
3135
- const isShowCodeBlockEditor = computed(
3136
- () => codeConfig.value && services?.codeBlockService.getCodeEditorShowStatus() || false
3137
- );
3138
3531
  const mode = computed(() => services?.codeBlockService.getMode());
3139
3532
  const id = computed(() => services?.codeBlockService.getId() || "");
3140
3533
  const editable = computed(() => services?.codeBlockService.getEditStatus());
3141
3534
  const selectedIds = computed(() => services?.codeBlockService.getCombineIds() || []);
3142
3535
  watchEffect(async () => {
3143
- codeConfig.value = await services?.codeBlockService.getCodeContentById(id.value) || null;
3536
+ codeConfig.value = cloneDeep(await services?.codeBlockService.getCodeContentById(id.value)) || null;
3537
+ if (!codeConfig.value)
3538
+ return;
3539
+ codeConfig.value.content = serializeConfig(codeConfig.value.content);
3144
3540
  });
3145
3541
  watchEffect(async () => {
3146
3542
  const codeDsl = await services?.codeBlockService.getCodeDslByIds(selectedIds.value) || null;
@@ -3155,52 +3551,24 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3155
3551
  });
3156
3552
  currentTitle.value = state.codeList[0]?.name || "";
3157
3553
  });
3158
- const saveCode = async () => {
3159
- if (!codeEditor.value || !codeConfig.value || !editable.value)
3160
- return true;
3161
- try {
3162
- const codeContent = codeEditor.value.getEditor()?.getValue();
3163
- codeConfig.value.content = eval(codeContent);
3164
- } catch (e) {
3165
- ElMessage.error(e.stack);
3166
- return false;
3167
- }
3168
- await services?.codeBlockService.setCodeDslById(id.value, {
3169
- name: codeConfig.value.name,
3170
- content: codeConfig.value.content
3171
- });
3172
- ElMessage.success("\u4EE3\u7801\u4FDD\u5B58\u6210\u529F");
3173
- return true;
3174
- };
3175
- const saveAndClose = async () => {
3176
- const saveRes = await saveCode();
3177
- if (saveRes) {
3178
- await services?.codeBlockService.setCodeEditorShowStatus(false);
3179
- }
3180
- };
3181
3554
  const selectHandler = (data) => {
3182
3555
  services?.codeBlockService.setId(data.id);
3183
3556
  currentTitle.value = data.name;
3184
3557
  };
3185
3558
  return (_ctx, _cache) => {
3186
- const _component_el_tree = resolveComponent("el-tree");
3187
- const _component_el_input = resolveComponent("el-input");
3188
- const _component_el_button = resolveComponent("el-button");
3189
- const _component_el_card = resolveComponent("el-card");
3190
- const _component_el_dialog = resolveComponent("el-dialog");
3191
- return openBlock(), createBlock(_component_el_dialog, {
3192
- modelValue: unref(isShowCodeBlockEditor),
3193
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(isShowCodeBlockEditor) ? isShowCodeBlockEditor.value = $event : null),
3559
+ return openBlock(), createBlock(unref(TMagicDialog), {
3560
+ "model-value": true,
3194
3561
  class: "code-editor-dialog",
3195
3562
  title: currentTitle.value,
3196
3563
  fullscreen: true,
3197
- "before-close": saveAndClose,
3198
- "append-to-body": true
3564
+ "close-on-press-escape": false,
3565
+ "append-to-body": true,
3566
+ "show-close": false
3199
3567
  }, {
3200
3568
  default: withCtx(() => [
3201
- createVNode(_sfc_main$l, {
3569
+ createVNode(_sfc_main$o, {
3202
3570
  left: left.value,
3203
- "onUpdate:left": _cache[1] || (_cache[1] = ($event) => left.value = $event),
3571
+ "onUpdate:left": _cache[0] || (_cache[0] = ($event) => left.value = $event),
3204
3572
  "min-left": 45,
3205
3573
  class: "code-editor-layout"
3206
3574
  }, createSlots({
@@ -3212,72 +3580,15 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3212
3580
  ])
3213
3581
  }, [
3214
3582
  renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id: unref(id) }),
3215
- createVNode(_component_el_card, { shadow: "never" }, {
3216
- header: withCtx(() => [
3217
- createElementVNode("div", _hoisted_4$1, [
3218
- _hoisted_5$1,
3219
- codeConfig.value ? (openBlock(), createBlock(_component_el_input, {
3220
- key: 0,
3221
- class: "code-name-input",
3222
- modelValue: codeConfig.value.name,
3223
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeConfig.value.name = $event),
3224
- disabled: !unref(editable)
3225
- }, null, 8, ["modelValue", "disabled"])) : createCommentVNode("", true)
3226
- ])
3227
- ]),
3228
- default: withCtx(() => [
3229
- createElementVNode("div", _hoisted_6$1, [
3230
- codeConfig.value ? (openBlock(), createBlock(_sfc_main$o, {
3231
- key: 0,
3232
- ref_key: "codeEditor",
3233
- ref: codeEditor,
3234
- class: "m-editor-container",
3235
- "init-values": `${codeConfig.value.content}`,
3236
- onSave: saveCode,
3237
- options: {
3238
- tabSize: 2,
3239
- fontSize: 16,
3240
- formatOnPaste: true,
3241
- readOnly: !unref(editable)
3242
- }
3243
- }, null, 8, ["init-values", "options"])) : createCommentVNode("", true),
3244
- unref(editable) ? (openBlock(), createElementBlock("div", _hoisted_7$1, [
3245
- createVNode(_component_el_button, {
3246
- type: "primary",
3247
- class: "button",
3248
- onClick: saveCode
3249
- }, {
3250
- default: withCtx(() => [
3251
- _hoisted_8$1
3252
- ]),
3253
- _: 1
3254
- }),
3255
- createVNode(_component_el_button, {
3256
- type: "primary",
3257
- class: "button",
3258
- onClick: saveAndClose
3259
- }, {
3260
- default: withCtx(() => [
3261
- _hoisted_9$1
3262
- ]),
3263
- _: 1
3264
- })
3265
- ])) : (openBlock(), createElementBlock("div", _hoisted_10, [
3266
- createVNode(_component_el_button, {
3267
- type: "primary",
3268
- class: "button",
3269
- onClick: saveAndClose
3270
- }, {
3271
- default: withCtx(() => [
3272
- _hoisted_11
3273
- ]),
3274
- _: 1
3275
- })
3276
- ]))
3277
- ])
3278
- ]),
3279
- _: 1
3280
- })
3583
+ codeConfig.value ? (openBlock(), createBlock(_sfc_main$g, {
3584
+ key: 0,
3585
+ id: unref(id),
3586
+ name: codeConfig.value.name,
3587
+ content: codeConfig.value.content,
3588
+ editable: !!unref(editable),
3589
+ autoSaveDraft: unref(mode) === unref(CodeEditorMode).EDITOR,
3590
+ codeOptions: unref(codeOptions)
3591
+ }, null, 8, ["id", "name", "content", "editable", "autoSaveDraft", "codeOptions"])) : createCommentVNode("", true)
3281
3592
  ], 2)) : createCommentVNode("", true)
3282
3593
  ]),
3283
3594
  _: 2
@@ -3285,16 +3596,15 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3285
3596
  unref(mode) === unref(CodeEditorMode).LIST ? {
3286
3597
  name: "left",
3287
3598
  fn: withCtx(() => [
3288
- !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(_component_el_tree, {
3599
+ !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(unref(TMagicTree), {
3289
3600
  key: 0,
3290
- ref: "tree",
3601
+ class: "side-tree",
3291
3602
  "node-key": "id",
3292
3603
  "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3293
3604
  data: state.codeList,
3294
3605
  "highlight-current": true,
3295
- onNodeClick: selectHandler,
3296
3606
  "current-node-key": state.codeList[0].id,
3297
- class: "side-tree"
3607
+ onNodeClick: selectHandler
3298
3608
  }, {
3299
3609
  default: withCtx(({ data }) => [
3300
3610
  createElementVNode("div", {
@@ -3304,7 +3614,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3304
3614
  createElementVNode("div", _hoisted_2$3, [
3305
3615
  createElementVNode("div", _hoisted_3$1, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1)
3306
3616
  ])
3307
- ], 8, _hoisted_1$6)
3617
+ ], 8, _hoisted_1$7)
3308
3618
  ]),
3309
3619
  _: 1
3310
3620
  }, 8, ["data", "current-node-key"])) : createCommentVNode("", true)
@@ -3313,12 +3623,12 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3313
3623
  ]), 1032, ["left"])
3314
3624
  ]),
3315
3625
  _: 3
3316
- }, 8, ["modelValue", "title"]);
3626
+ }, 8, ["title"]);
3317
3627
  };
3318
3628
  }
3319
3629
  });
3320
3630
 
3321
- const _hoisted_1$5 = { class: "m-editor-code-block-list" };
3631
+ const _hoisted_1$6 = { class: "m-editor-code-block-list" };
3322
3632
  const _hoisted_2$2 = { class: "code-header-wrapper" };
3323
3633
  const _hoisted_3 = /* @__PURE__ */ createTextVNode("\u65B0\u589E");
3324
3634
  const _hoisted_4 = ["id"];
@@ -3340,8 +3650,11 @@ const _hoisted_9 = /* @__PURE__ */ createElementVNode("svg", {
3340
3650
  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"
3341
3651
  })
3342
3652
  ], -1);
3653
+ const __default__$d = defineComponent({
3654
+ name: "MEditorCodeBlockList"
3655
+ });
3343
3656
  const _sfc_main$e = /* @__PURE__ */ defineComponent({
3344
- __name: "CodeBlockList",
3657
+ ...__default__$d,
3345
3658
  props: {
3346
3659
  customError: null
3347
3660
  },
@@ -3349,41 +3662,38 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3349
3662
  const props = __props;
3350
3663
  const services = inject("services");
3351
3664
  const state = reactive({
3352
- codeList: [],
3353
- bindComps: {}
3665
+ codeList: []
3354
3666
  });
3355
3667
  const editable = computed(() => services?.codeBlockService.getEditStatus());
3356
- const getBindCompsByCodeId = (codeId, codeBlockContent) => {
3357
- if (isEmpty(codeBlockContent) || isEmpty(codeBlockContent.comps)) {
3358
- state.bindComps[codeId] = [];
3359
- return;
3360
- }
3361
- const compsField = codeBlockContent.comps;
3362
- const bindCompIds = Object.keys(compsField);
3363
- const bindCompsFiltered = bindCompIds.filter((compId) => !isEmpty(compsField[compId]));
3364
- const compsInfo = bindCompsFiltered.map((compId) => ({
3365
- id: compId,
3366
- name: getCompName(compId)
3668
+ const isShowCodeBlockEditor = computed(() => services?.codeBlockService.getCodeEditorShowStatus() || false);
3669
+ const codeCombineInfo = ref(null);
3670
+ const getBindCompsByCodeId = (codeId) => {
3671
+ if (!codeCombineInfo.value || !codeCombineInfo.value[codeId])
3672
+ return [];
3673
+ const bindCompsId = Object.keys(codeCombineInfo.value[codeId]);
3674
+ return bindCompsId.map((compId) => ({
3675
+ compId,
3676
+ compName: getCompName(compId)
3367
3677
  }));
3368
- state.bindComps[codeId] = compsInfo;
3369
3678
  };
3370
3679
  const initList = async () => {
3371
- const codeDsl = await services?.codeBlockService.getCodeDsl() || null;
3372
- if (!codeDsl)
3680
+ const codeDsl = cloneDeep(await services?.codeBlockService.getCodeDsl()) || null;
3681
+ codeCombineInfo.value = cloneDeep(services?.codeBlockService.getCombineInfo()) || null;
3682
+ if (!codeDsl || !codeCombineInfo.value)
3373
3683
  return;
3374
3684
  state.codeList = [];
3375
3685
  forIn(codeDsl, (value, codeId) => {
3376
- getBindCompsByCodeId(codeId, value);
3377
3686
  state.codeList.push({
3378
3687
  id: codeId,
3379
3688
  name: value.name,
3380
3689
  codeBlockContent: value,
3381
- showRelation: true
3690
+ showRelation: true,
3691
+ combineInfo: getBindCompsByCodeId(codeId)
3382
3692
  });
3383
3693
  });
3384
3694
  };
3385
3695
  watch(
3386
- () => services?.codeBlockService.getCodeDsl(),
3696
+ [() => services?.codeBlockService.getCodeDslSync(), () => services?.codeBlockService.refreshCombineInfo()],
3387
3697
  () => {
3388
3698
  initList();
3389
3699
  },
@@ -3392,31 +3702,18 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3392
3702
  deep: true
3393
3703
  }
3394
3704
  );
3395
- watch(
3396
- () => services?.editorService.get("node"),
3397
- (curNode) => {
3398
- if (!curNode?.id)
3399
- return;
3400
- forIn(state.bindComps, (bindCompInfo) => {
3401
- bindCompInfo.forEach((comp) => {
3402
- if (comp.id === curNode.id) {
3403
- comp.name = curNode.name;
3404
- }
3405
- });
3406
- });
3407
- }
3408
- );
3409
3705
  const createCodeBlock = async () => {
3410
3706
  const { codeBlockService } = services || {};
3411
3707
  if (!codeBlockService) {
3412
- ElMessage.error("\u65B0\u589E\u4EE3\u7801\u5757\u5931\u8D25");
3708
+ tMagicMessage.error("\u65B0\u589E\u4EE3\u7801\u5757\u5931\u8D25");
3413
3709
  return;
3414
3710
  }
3415
3711
  const codeConfig = {
3416
3712
  name: "\u4EE3\u7801\u5757",
3417
- content: `() => {
3713
+ content: `({app, params}) => {
3418
3714
  // place your code here
3419
- }`
3715
+ }`,
3716
+ params: []
3420
3717
  };
3421
3718
  await codeBlockService.setMode(CodeEditorMode.EDITOR);
3422
3719
  const id = await codeBlockService.getUniqueId();
@@ -3428,7 +3725,8 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3428
3725
  services?.codeBlockService.setCodeEditorContent(true, key);
3429
3726
  };
3430
3727
  const deleteCode = (key) => {
3431
- const existBinds = !!(state.bindComps[key]?.length > 0);
3728
+ const currentCode = state.codeList.find((codeItem) => codeItem.id === key);
3729
+ const existBinds = !isEmpty(currentCode?.combineInfo);
3432
3730
  const undeleteableList = services?.codeBlockService.getUndeletableList() || [];
3433
3731
  if (!existBinds && !undeleteableList.includes(key)) {
3434
3732
  services?.codeBlockService.deleteCodeDslByIds([key]);
@@ -3436,7 +3734,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3436
3734
  if (typeof props.customError === "function") {
3437
3735
  props.customError(key, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
3438
3736
  } else {
3439
- ElMessage.error("\u4EE3\u7801\u5757\u5220\u9664\u5931\u8D25");
3737
+ tMagicMessage.error("\u4EE3\u7801\u5757\u5220\u9664\u5931\u8D25");
3440
3738
  }
3441
3739
  }
3442
3740
  };
@@ -3468,14 +3766,10 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3468
3766
  stage?.select(compId);
3469
3767
  };
3470
3768
  return (_ctx, _cache) => {
3471
- const _component_el_input = resolveComponent("el-input");
3472
- const _component_el_button = resolveComponent("el-button");
3473
- const _component_el_tooltip = resolveComponent("el-tooltip");
3474
- const _component_el_tree = resolveComponent("el-tree");
3475
- return openBlock(), createElementBlock("div", _hoisted_1$5, [
3769
+ return openBlock(), createElementBlock("div", _hoisted_1$6, [
3476
3770
  renderSlot(_ctx.$slots, "code-block-panel-header", {}, () => [
3477
3771
  createElementVNode("div", _hoisted_2$2, [
3478
- createVNode(_component_el_input, {
3772
+ createVNode(unref(TMagicInput), {
3479
3773
  class: normalizeClass([unref(editable) ? "code-filter-input" : "code-filter-input-no-btn"]),
3480
3774
  size: "small",
3481
3775
  placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
@@ -3484,7 +3778,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3484
3778
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => filterText.value = $event),
3485
3779
  onInput: filterTextChangeHandler
3486
3780
  }, null, 8, ["class", "modelValue"]),
3487
- unref(editable) ? (openBlock(), createBlock(_component_el_button, {
3781
+ unref(editable) ? (openBlock(), createBlock(unref(TMagicButton), {
3488
3782
  key: 0,
3489
3783
  class: "create-code-button",
3490
3784
  type: "primary",
@@ -3498,7 +3792,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3498
3792
  })) : createCommentVNode("", true)
3499
3793
  ])
3500
3794
  ]),
3501
- !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(_component_el_tree, {
3795
+ !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(unref(TMagicTree), {
3502
3796
  key: 0,
3503
3797
  ref_key: "tree",
3504
3798
  ref: tree,
@@ -3515,15 +3809,15 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3515
3809
  class: "list-container"
3516
3810
  }, [
3517
3811
  createElementVNode("div", _hoisted_5, [
3518
- createElementVNode("div", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
3812
+ createElementVNode("span", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
3519
3813
  createElementVNode("div", _hoisted_7, [
3520
- createVNode(_component_el_tooltip, {
3814
+ createVNode(unref(TMagicTooltip), {
3521
3815
  effect: "dark",
3522
3816
  content: unref(editable) ? "\u7F16\u8F91" : "\u67E5\u770B",
3523
3817
  placement: "bottom"
3524
3818
  }, {
3525
3819
  default: withCtx(() => [
3526
- createVNode(_sfc_main$j, {
3820
+ createVNode(_sfc_main$n, {
3527
3821
  icon: unref(editable) ? unref(Edit) : unref(View),
3528
3822
  class: "edit-icon",
3529
3823
  onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
@@ -3531,14 +3825,14 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3531
3825
  ]),
3532
3826
  _: 2
3533
3827
  }, 1032, ["content"]),
3534
- state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createBlock(_component_el_tooltip, {
3828
+ data.combineInfo && data.combineInfo.length > 0 ? (openBlock(), createBlock(unref(TMagicTooltip), {
3535
3829
  key: 0,
3536
3830
  effect: "dark",
3537
3831
  content: "\u67E5\u770B\u7ED1\u5B9A\u5173\u7CFB",
3538
3832
  placement: "bottom"
3539
3833
  }, {
3540
3834
  default: withCtx(() => [
3541
- createVNode(_sfc_main$j, {
3835
+ createVNode(_sfc_main$n, {
3542
3836
  icon: unref(Link),
3543
3837
  class: "edit-icon",
3544
3838
  onClick: withModifiers(($event) => toggleCombineRelation(data), ["stop"])
@@ -3546,14 +3840,14 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3546
3840
  ]),
3547
3841
  _: 2
3548
3842
  }, 1024)) : createCommentVNode("", true),
3549
- unref(editable) ? (openBlock(), createBlock(_component_el_tooltip, {
3843
+ unref(editable) ? (openBlock(), createBlock(unref(TMagicTooltip), {
3550
3844
  key: 1,
3551
3845
  effect: "dark",
3552
3846
  content: "\u5220\u9664",
3553
3847
  placement: "bottom"
3554
3848
  }, {
3555
3849
  default: withCtx(() => [
3556
- createVNode(_sfc_main$j, {
3850
+ createVNode(_sfc_main$n, {
3557
3851
  icon: unref(Close),
3558
3852
  class: "edit-icon",
3559
3853
  onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
@@ -3567,18 +3861,18 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3567
3861
  })
3568
3862
  ])
3569
3863
  ]),
3570
- data.showRelation && state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
3864
+ data.showRelation && data.combineInfo && data.combineInfo.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
3571
3865
  _hoisted_9,
3572
- (openBlock(true), createElementBlock(Fragment, null, renderList(state.bindComps[data.id], (comp, index) => {
3573
- return openBlock(), createBlock(_component_el_button, {
3866
+ (openBlock(true), createElementBlock(Fragment, null, renderList(data.combineInfo, (comp, index) => {
3867
+ return openBlock(), createBlock(unref(TMagicButton), {
3574
3868
  key: index,
3575
3869
  class: "code-comp",
3576
3870
  size: "small",
3577
3871
  plain: true,
3578
- onClick: withModifiers(($event) => selectComp(comp.id), ["stop"])
3872
+ onClick: withModifiers(($event) => selectComp(comp.compId), ["stop"])
3579
3873
  }, {
3580
3874
  default: withCtx(() => [
3581
- createTextVNode(toDisplayString(comp.name), 1)
3875
+ createTextVNode(toDisplayString(comp.compName), 1)
3582
3876
  ]),
3583
3877
  _: 2
3584
3878
  }, 1032, ["onClick"]);
@@ -3588,21 +3882,23 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3588
3882
  ]),
3589
3883
  _: 3
3590
3884
  }, 8, ["data"])) : createCommentVNode("", true),
3591
- createVNode(_sfc_main$f, null, {
3885
+ unref(isShowCodeBlockEditor) ? (openBlock(), createBlock(_sfc_main$f, { key: 1 }, {
3592
3886
  "code-block-edit-panel-header": withCtx(({ id }) => [
3593
3887
  renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
3594
3888
  ]),
3595
3889
  _: 3
3596
- })
3890
+ })) : createCommentVNode("", true)
3597
3891
  ]);
3598
3892
  };
3599
3893
  }
3600
3894
  });
3601
3895
 
3602
- const _hoisted_1$4 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
3603
- const _hoisted_2$1 = ["onClick", "onDragstart"];
3896
+ const _hoisted_1$5 = ["onClick", "onDragstart"];
3897
+ const __default__$c = defineComponent({
3898
+ name: "MEditorComponentListPanel"
3899
+ });
3604
3900
  const _sfc_main$d = /* @__PURE__ */ defineComponent({
3605
- __name: "ComponentListPanel",
3901
+ ...__default__$c,
3606
3902
  setup(__props) {
3607
3903
  const searchText = ref("");
3608
3904
  const services = inject("services");
@@ -3615,7 +3911,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3615
3911
  }))
3616
3912
  );
3617
3913
  const collapseValue = computed(
3618
- () => Array(list.value?.length).fill(1).map((x, i) => i)
3914
+ () => Array(list.value?.length).fill(1).map((x, i) => `${i}`)
3619
3915
  );
3620
3916
  let timeout;
3621
3917
  let clientX;
@@ -3667,36 +3963,31 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3667
3963
  timeout = stage.value.getAddContainerHighlightClassNameTimeout(e);
3668
3964
  };
3669
3965
  return (_ctx, _cache) => {
3670
- const _component_el_input = resolveComponent("el-input");
3671
- const _component_el_tooltip = resolveComponent("el-tooltip");
3672
- const _component_el_collapse_item = resolveComponent("el-collapse-item");
3673
- const _component_el_collapse = resolveComponent("el-collapse");
3674
- const _component_el_scrollbar = resolveComponent("el-scrollbar");
3675
- return openBlock(), createBlock(_component_el_scrollbar, null, {
3966
+ return openBlock(), createBlock(unref(TMagicScrollbar), null, {
3676
3967
  default: withCtx(() => [
3677
3968
  renderSlot(_ctx.$slots, "component-list-panel-header"),
3678
- createVNode(_component_el_collapse, {
3969
+ createVNode(unref(TMagicCollapse), {
3679
3970
  class: "ui-component-panel",
3680
3971
  "model-value": unref(collapseValue)
3681
3972
  }, {
3682
3973
  default: withCtx(() => [
3683
- createVNode(_component_el_input, {
3684
- "prefix-icon": "el-icon-search",
3974
+ createVNode(unref(TMagicInput), {
3685
3975
  placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
3686
3976
  class: "search-input",
3687
3977
  size: "small",
3688
3978
  clearable: "",
3979
+ "prefix-icon": unref(Search),
3689
3980
  modelValue: searchText.value,
3690
3981
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchText.value = $event)
3691
- }, null, 8, ["modelValue"]),
3982
+ }, null, 8, ["prefix-icon", "modelValue"]),
3692
3983
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(list), (group, index) => {
3693
3984
  return openBlock(), createElementBlock(Fragment, null, [
3694
- group.items && group.items.length ? (openBlock(), createBlock(_component_el_collapse_item, {
3985
+ group.items && group.items.length ? (openBlock(), createBlock(unref(TMagicCollapseItem), {
3695
3986
  key: index,
3696
- name: index
3987
+ name: `${index}`
3697
3988
  }, {
3698
3989
  title: withCtx(() => [
3699
- _hoisted_1$4,
3990
+ createVNode(_sfc_main$n, { icon: unref(Grid) }, null, 8, ["icon"]),
3700
3991
  createTextVNode(toDisplayString(group.title), 1)
3701
3992
  ]),
3702
3993
  default: withCtx(() => [
@@ -3711,10 +4002,10 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3711
4002
  onDrag: dragHandler
3712
4003
  }, [
3713
4004
  renderSlot(_ctx.$slots, "component-list-item", { component: item }, () => [
3714
- createVNode(_sfc_main$j, {
4005
+ createVNode(_sfc_main$n, {
3715
4006
  icon: item.icon
3716
4007
  }, null, 8, ["icon"]),
3717
- createVNode(_component_el_tooltip, {
4008
+ createVNode(unref(TMagicTooltip), {
3718
4009
  effect: "dark",
3719
4010
  placement: "bottom",
3720
4011
  content: item.text
@@ -3725,7 +4016,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3725
4016
  _: 2
3726
4017
  }, 1032, ["content"])
3727
4018
  ])
3728
- ], 40, _hoisted_2$1);
4019
+ ], 40, _hoisted_1$5);
3729
4020
  }), 128))
3730
4021
  ]),
3731
4022
  _: 2
@@ -3742,8 +4033,11 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3742
4033
  }
3743
4034
  });
3744
4035
 
4036
+ const __default__$b = defineComponent({
4037
+ name: "MEditorContentMenu"
4038
+ });
3745
4039
  const _sfc_main$c = /* @__PURE__ */ defineComponent({
3746
- __name: "ContentMenu",
4040
+ ...__default__$b,
3747
4041
  props: {
3748
4042
  menuData: { default: () => [] },
3749
4043
  isSubMenu: { type: Boolean, default: false }
@@ -3822,7 +4116,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3822
4116
  });
3823
4117
  return (_ctx, _cache) => {
3824
4118
  const _component_content_menu = resolveComponent("content-menu", true);
3825
- return __props.menuData.length && visible.value ? (openBlock(), createElementBlock("div", {
4119
+ return __props.menuData.length ? withDirectives((openBlock(), createElementBlock("div", {
3826
4120
  key: 0,
3827
4121
  class: "magic-editor-content-menu",
3828
4122
  ref_key: "menu",
@@ -3831,7 +4125,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3831
4125
  }, [
3832
4126
  createElementVNode("div", null, [
3833
4127
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.menuData, (item, index) => {
3834
- return openBlock(), createBlock(_sfc_main$i, {
4128
+ return openBlock(), createBlock(_sfc_main$k, {
3835
4129
  "event-type": "mouseup",
3836
4130
  data: item,
3837
4131
  key: index,
@@ -3850,21 +4144,29 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3850
4144
  onHide: hide
3851
4145
  }, null, 8, ["menu-data"])
3852
4146
  ]))
3853
- ], 4)) : createCommentVNode("", true);
4147
+ ], 4)), [
4148
+ [vShow, visible.value]
4149
+ ]) : createCommentVNode("", true);
3854
4150
  };
3855
4151
  }
3856
4152
  });
3857
4153
 
4154
+ const __default__$a = defineComponent({
4155
+ name: "MEditorLayerMenu"
4156
+ });
3858
4157
  const _sfc_main$b = /* @__PURE__ */ defineComponent({
3859
- __name: "LayerMenu",
4158
+ ...__default__$a,
4159
+ props: {
4160
+ layerContentMenu: null
4161
+ },
3860
4162
  setup(__props, { expose }) {
4163
+ const props = __props;
3861
4164
  const services = inject("services");
3862
4165
  const menu = ref();
3863
4166
  const node = computed(() => services?.editorService.get("node"));
3864
4167
  const isRoot = computed(() => node.value?.type === NodeType.ROOT);
3865
4168
  const isPage = computed(() => node.value?.type === NodeType.PAGE);
3866
4169
  const componentList = computed(() => services?.componentListService.getList() || []);
3867
- const layerContentMenu = inject("layerContentMenu", []);
3868
4170
  const createMenuItems = (group) => group.items.map((component) => ({
3869
4171
  text: component.text,
3870
4172
  type: "button",
@@ -3919,7 +4221,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
3919
4221
  {
3920
4222
  type: "button",
3921
4223
  text: "\u590D\u5236",
3922
- icon: markRaw(DocumentCopy),
4224
+ icon: markRaw(CopyDocument),
3923
4225
  display: () => !isRoot.value,
3924
4226
  handler: () => {
3925
4227
  node.value && services?.editorService.copy(node.value);
@@ -3934,7 +4236,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
3934
4236
  node.value && services?.editorService.remove(node.value);
3935
4237
  }
3936
4238
  },
3937
- ...layerContentMenu
4239
+ ...props.layerContentMenu
3938
4240
  ]);
3939
4241
  const show = (e) => {
3940
4242
  menu.value?.show(e);
@@ -3953,398 +4255,365 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
3953
4255
  }
3954
4256
  });
3955
4257
 
3956
- const throttleTime = 150;
3957
- const select = async (data, editorService) => {
3958
- if (!data.id) {
3959
- throw new Error("\u6CA1\u6709id");
3960
- }
3961
- await editorService?.select(data);
3962
- editorService?.get("stage")?.select(data.id);
3963
- };
3964
- const highlight = (data, editorService) => {
3965
- if (!data?.id) {
3966
- throw new Error("\u6CA1\u6709id");
3967
- }
3968
- editorService?.highlight(data);
3969
- editorService?.get("stage")?.highlight(data.id);
3970
- };
3971
- const useDrop = (tree, editorService) => ({
3972
- allowDrop: (draggingNode, dropNode, type) => {
3973
- const { data } = dropNode || {};
3974
- const { data: ingData } = draggingNode;
3975
- const { type: ingType } = ingData;
3976
- if (ingType !== NodeType.PAGE && data.type === NodeType.PAGE)
3977
- return false;
3978
- if (ingType === NodeType.PAGE && data.type !== NodeType.PAGE)
3979
- return false;
3980
- if (!data || !data.type)
3981
- return false;
3982
- if (["prev", "next"].includes(type))
3983
- return true;
3984
- if (data.items || data.type === "container")
3985
- return true;
3986
- return false;
3987
- },
3988
- async handleDragEnd(e) {
3989
- if (!tree.value)
3990
- return;
3991
- const { data: node } = e;
3992
- const parent = editorService?.getParentById(node.id, false);
3993
- const layout = await editorService?.getLayout(parent);
3994
- node.style.position = layout;
3995
- if (layout === Layout.RELATIVE) {
3996
- node.style.top = 0;
3997
- node.style.left = 0;
3998
- }
3999
- const { data } = tree.value;
4000
- const [page] = data;
4001
- editorService?.update(page);
4002
- }
4258
+ const _hoisted_1$4 = ["id", "onMouseenter"];
4259
+ const __default__$9 = defineComponent({
4260
+ name: "MEditorLayerPanel"
4003
4261
  });
4004
- const useStatus = (tree, editorService) => {
4005
- const node = ref();
4006
- const page = computed(() => editorService?.get("page"));
4007
- const expandedKeys = /* @__PURE__ */ new Map();
4008
- const expandNodes = () => {
4009
- expandedKeys.forEach((key) => {
4262
+ const _sfc_main$a = /* @__PURE__ */ defineComponent({
4263
+ ...__default__$9,
4264
+ props: {
4265
+ layerContentMenu: null
4266
+ },
4267
+ setup(__props) {
4268
+ const throttleTime = 150;
4269
+ const services = inject("services");
4270
+ const tree = ref();
4271
+ const menu = ref();
4272
+ const editorService = services?.editorService;
4273
+ const page = computed(() => editorService?.get("page"));
4274
+ const values = computed(() => page.value ? [page.value] : []);
4275
+ const selectedNodes = ref([]);
4276
+ const selectedIds = computed(() => selectedNodes.value.map((node) => node.id));
4277
+ const isMultiSelectStatus = ref(false);
4278
+ const spliceNodeKey = ref();
4279
+ const filterText = ref("");
4280
+ const defaultExpandedKeys = computed(() => selectedIds.value.length > 0 ? selectedIds.value : []);
4281
+ editorService?.on("remove", () => {
4282
+ setTimeout(() => {
4283
+ tree.value?.getNode(editorService.get("node").id)?.updateChildren();
4284
+ }, 0);
4285
+ });
4286
+ const select = async (data) => {
4287
+ if (!data.id) {
4288
+ throw new Error("\u6CA1\u6709id");
4289
+ }
4290
+ await editorService?.select(data);
4291
+ editorService?.get("stage")?.select(data.id);
4292
+ };
4293
+ const multiSelect = async (data) => {
4294
+ await editorService?.multiSelect(data);
4295
+ editorService?.get("stage")?.multiSelect(data);
4296
+ };
4297
+ const highlight = (data) => {
4298
+ if (!data?.id) {
4299
+ throw new Error("\u6CA1\u6709id");
4300
+ }
4301
+ editorService?.highlight(data);
4302
+ editorService?.get("stage")?.highlight(data.id);
4303
+ };
4304
+ const expandedKeys = /* @__PURE__ */ new Map();
4305
+ const allowDrop = (draggingNode, dropNode, type) => {
4306
+ const { data } = dropNode || {};
4307
+ const { data: ingData } = draggingNode;
4308
+ const { type: ingType } = ingData;
4309
+ if (ingType !== NodeType.PAGE && data.type === NodeType.PAGE)
4310
+ return false;
4311
+ if (ingType === NodeType.PAGE && data.type !== NodeType.PAGE)
4312
+ return false;
4313
+ if (!data || !data.type)
4314
+ return false;
4315
+ if (["prev", "next"].includes(type))
4316
+ return true;
4317
+ if (data.items || data.type === "container")
4318
+ return true;
4319
+ return false;
4320
+ };
4321
+ const handleDragEnd = async (e) => {
4010
4322
  if (!tree.value)
4011
4323
  return;
4012
- tree.value.getNode(key)?.expand();
4013
- });
4014
- };
4015
- watchEffect(() => {
4016
- if (!tree.value)
4017
- return;
4018
- if (!editorService)
4019
- return;
4020
- node.value = editorService.get("node");
4021
- if (!node.value)
4022
- return;
4023
- tree.value.setCurrentKey(node.value.id, true);
4024
- const parent = editorService.get("parent");
4025
- if (!parent?.id)
4026
- return;
4027
- const treeNode = tree.value.getNode(parent.id);
4028
- treeNode?.updateChildren();
4029
- setTimeout(() => {
4030
- tree.value && Object.entries(tree.value.store.nodesMap).forEach(([id, node2]) => {
4031
- if (node2.expanded && node2.data.items) {
4324
+ const { data: node } = e;
4325
+ const parent = editorService?.getParentById(node.id, false);
4326
+ const layout = await editorService?.getLayout(parent);
4327
+ node.style.position = layout;
4328
+ if (layout === Layout.RELATIVE) {
4329
+ node.style.top = 0;
4330
+ node.style.left = 0;
4331
+ }
4332
+ const data = tree.value.getData();
4333
+ const [page2] = data;
4334
+ editorService?.update(page2);
4335
+ };
4336
+ const loadItems = (node, resolve) => {
4337
+ if (Array.isArray(node.data)) {
4338
+ return resolve(node.data);
4339
+ }
4340
+ if (Array.isArray(node.data?.items)) {
4341
+ return resolve(node.data?.items);
4342
+ }
4343
+ resolve([]);
4344
+ };
4345
+ const handleCollapse = (data) => {
4346
+ expandedKeys.delete(data.id);
4347
+ };
4348
+ const handleExpand = (data) => {
4349
+ const parent = editorService?.getParentById(data.id);
4350
+ if (!parent?.id)
4351
+ return;
4352
+ expandedKeys.set(parent.id, parent.id);
4353
+ };
4354
+ const filterNode = (value, data) => {
4355
+ if (!value) {
4356
+ return true;
4357
+ }
4358
+ let name = "";
4359
+ if (data.name) {
4360
+ name = data.name;
4361
+ } else if (data.items) {
4362
+ name = "container";
4363
+ }
4364
+ return `${data.id}${name}${data.type}`.indexOf(value) !== -1;
4365
+ };
4366
+ const filterTextChangeHandler = (val) => {
4367
+ tree.value?.filter(val);
4368
+ };
4369
+ const expandNodes = async () => {
4370
+ if (!tree.value)
4371
+ return;
4372
+ await nextTick();
4373
+ tree.value && Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]) => {
4374
+ if (node.expanded && node.data.items) {
4032
4375
  expandedKeys.set(id, id);
4033
4376
  }
4034
4377
  });
4035
- expandNodes();
4036
- });
4037
- });
4038
- return {
4039
- values: computed(() => page.value ? [page.value] : []),
4040
- loadItems: (node2, resolve) => {
4041
- if (Array.isArray(node2.data)) {
4042
- return resolve(node2.data);
4378
+ expandedKeys.forEach((key) => {
4379
+ if (!tree.value)
4380
+ return;
4381
+ tree.value.getNode(key)?.expand();
4382
+ });
4383
+ };
4384
+ watch(
4385
+ () => editorService?.get("nodes"),
4386
+ (nodes) => {
4387
+ selectedNodes.value = nodes ?? [];
4043
4388
  }
4044
- if (Array.isArray(node2.data?.items)) {
4045
- return resolve(node2.data?.items);
4389
+ );
4390
+ const setTreeKeyStatus = () => {
4391
+ if (!tree.value)
4392
+ return;
4393
+ if (selectedIds.value.length === 0) {
4394
+ tree.value.setCheckedKeys([]);
4395
+ tree.value.setCurrentKey();
4396
+ } else if (selectedIds.value.length === 1 && !isMultiSelectStatus.value) {
4397
+ tree.value.setCurrentKey(selectedIds.value[0], true);
4398
+ tree.value.setCheckedKeys([]);
4399
+ } else {
4400
+ tree.value.setCheckedKeys(selectedIds.value);
4401
+ tree.value.setCurrentKey();
4046
4402
  }
4047
- resolve([]);
4048
- },
4049
- highlightNode: computed(() => editorService?.get("highlightNode")),
4050
- clickNode: node,
4051
- expandedKeys: computed(() => node.value ? [node.value.id] : []),
4052
- handleCollapse: (data) => {
4053
- expandedKeys.delete(data.id);
4054
- },
4055
- handleExpand: (data) => {
4056
- const parent = editorService?.getParentById(data.id);
4403
+ };
4404
+ watch([selectedIds, tree], async () => {
4405
+ if (!tree.value || !editorService)
4406
+ return;
4407
+ const parent = editorService.get("parent");
4057
4408
  if (!parent?.id)
4058
4409
  return;
4059
- expandedKeys.set(parent.id, parent.id);
4060
- }
4061
- };
4062
- };
4063
- const useFilter = (tree) => ({
4064
- filterText: ref(""),
4065
- filterNode: (value, data) => {
4066
- if (!value) {
4067
- return true;
4068
- }
4069
- let name = "";
4070
- if (data.name) {
4071
- name = data.name;
4072
- } else if (data.items) {
4073
- name = "container";
4074
- }
4075
- return `${data.id}${name}${data.type}`.indexOf(value) !== -1;
4076
- },
4077
- filterTextChangeHandler(val) {
4078
- tree.value?.filter(val);
4079
- }
4080
- });
4081
- const _sfc_main$a = defineComponent({
4082
- name: "magic-editor-layer-panel",
4083
- components: { LayerMenu: _sfc_main$b },
4084
- setup() {
4085
- const services = inject("services");
4086
- const tree = ref();
4087
- const menu = ref();
4410
+ const treeNode = tree.value.getNode(parent.id);
4411
+ treeNode?.updateChildren();
4412
+ await expandNodes();
4413
+ setTreeKeyStatus();
4414
+ });
4415
+ const mouseenterHandler = () => {
4416
+ tree.value?.$el.focus();
4417
+ };
4418
+ const mouseleaveHandler = () => {
4419
+ tree.value?.$el.blur();
4420
+ isMultiSelectStatus.value = false;
4421
+ };
4422
+ let keycon;
4423
+ onMounted(() => {
4424
+ keycon = new KeyController(tree.value?.$el);
4425
+ const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
4426
+ const ctrl = isMac ? "meta" : "ctrl";
4427
+ keycon.keydown(ctrl, (e) => {
4428
+ e.inputEvent.preventDefault();
4429
+ isMultiSelectStatus.value = true;
4430
+ }).keyup(ctrl, (e) => {
4431
+ e.inputEvent.preventDefault();
4432
+ isMultiSelectStatus.value = false;
4433
+ });
4434
+ });
4435
+ onUnmounted(() => {
4436
+ keycon.destroy();
4437
+ });
4088
4438
  const clicked = ref(false);
4089
- const editorService = services?.editorService;
4439
+ const highlightNode = computed(() => editorService?.get("highlightNode"));
4090
4440
  const highlightHandler = throttle((data) => {
4091
- highlight(data, editorService);
4441
+ highlight(data);
4092
4442
  }, throttleTime);
4093
4443
  const toggleClickFlag = () => {
4094
4444
  clicked.value = !clicked.value;
4095
4445
  };
4096
- const statusData = useStatus(tree, editorService);
4097
- const canHighlight = computed(
4098
- () => statusData.highlightNode.value?.id !== statusData.clickNode.value?.id && !clicked.value
4099
- );
4100
- editorService?.on("remove", () => {
4101
- setTimeout(() => {
4102
- tree.value?.getNode(editorService.get("node").id)?.updateChildren();
4103
- }, 0);
4446
+ const canHighlight = (data) => {
4447
+ if (clicked.value)
4448
+ return false;
4449
+ return data.id === highlightNode?.value?.id && !selectedIds.value.includes(data.id) && spliceNodeKey.value !== data.id;
4450
+ };
4451
+ watch(isMultiSelectStatus, () => {
4452
+ if (isMultiSelectStatus.value && selectedNodes.value.length === 1 && selectedNodes.value[0].type === NodeType.PAGE) {
4453
+ selectedNodes.value = [];
4454
+ }
4104
4455
  });
4105
- return {
4106
- tree,
4107
- menu,
4108
- ...statusData,
4109
- ...useDrop(tree, editorService),
4110
- ...useFilter(tree),
4111
- highlightHandler,
4112
- toggleClickFlag,
4113
- canHighlight,
4114
- clickHandler(data) {
4456
+ const multiClickHandler = (data) => {
4457
+ if (!data?.id) {
4458
+ throw new Error("\u6CA1\u6709id");
4459
+ }
4460
+ if (data.type === NodeType.PAGE) {
4461
+ tree.value?.setCheckedKeys([]);
4462
+ return;
4463
+ }
4464
+ const index = selectedNodes.value.findIndex((node) => node.id === data.id);
4465
+ if (index !== -1) {
4466
+ selectedNodes.value.splice(index, 1);
4467
+ spliceNodeKey.value = data.id;
4468
+ } else {
4469
+ selectedNodes.value = [...selectedNodes.value, data];
4470
+ }
4471
+ tree.value?.setCheckedKeys(selectedIds.value);
4472
+ multiSelect(selectedIds.value);
4473
+ };
4474
+ const clickHandler = (data) => {
4475
+ if (!isMultiSelectStatus.value) {
4115
4476
  if (services?.uiService.get("uiSelectMode")) {
4116
4477
  document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
4117
4478
  return;
4118
4479
  }
4119
4480
  tree.value?.setCurrentKey(data.id);
4120
- select(data, editorService);
4121
- },
4122
- async contextmenu(event, data) {
4123
- event.preventDefault();
4124
- await select(data, editorService);
4125
- menu.value?.show(event);
4481
+ select(data);
4482
+ } else {
4483
+ multiClickHandler(data);
4126
4484
  }
4127
4485
  };
4128
- }
4129
- });
4130
-
4131
- const _export_sfc = (sfc, props) => {
4132
- const target = sfc.__vccOpts || sfc;
4133
- for (const [key, val] of props) {
4134
- target[key] = val;
4135
- }
4136
- return target;
4137
- };
4138
-
4139
- const _hoisted_1$3 = ["id", "onMouseenter"];
4140
- function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4141
- const _component_el_input = resolveComponent("el-input");
4142
- const _component_el_tree = resolveComponent("el-tree");
4143
- const _component_layer_menu = resolveComponent("layer-menu");
4144
- const _component_el_scrollbar = resolveComponent("el-scrollbar");
4145
- return openBlock(), createBlock(_component_el_scrollbar, { class: "magic-editor-layer-panel" }, {
4146
- default: withCtx(() => [
4147
- renderSlot(_ctx.$slots, "layer-panel-header"),
4148
- createVNode(_component_el_input, {
4149
- class: "filterInput",
4150
- size: "small",
4151
- placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
4152
- clearable: "",
4153
- modelValue: _ctx.filterText,
4154
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.filterText = $event),
4155
- onChange: _ctx.filterTextChangeHandler
4156
- }, null, 8, ["modelValue", "onChange"]),
4157
- _ctx.values.length ? (openBlock(), createBlock(_component_el_tree, {
4158
- key: 0,
4159
- ref: "tree",
4160
- "node-key": "id",
4161
- "empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684",
4162
- draggable: "",
4163
- "default-expanded-keys": _ctx.expandedKeys,
4164
- load: _ctx.loadItems,
4165
- data: _ctx.values,
4166
- "expand-on-click-node": false,
4167
- "highlight-current": true,
4168
- props: {
4169
- children: "items"
4170
- },
4171
- "filter-node-method": _ctx.filterNode,
4172
- "allow-drop": _ctx.allowDrop,
4173
- onNodeClick: _ctx.clickHandler,
4174
- onNodeContextmenu: _ctx.contextmenu,
4175
- onNodeDragEnd: _ctx.handleDragEnd,
4176
- onNodeCollapse: _ctx.handleCollapse,
4177
- onNodeExpand: _ctx.handleExpand
4178
- }, {
4179
- default: withCtx(({ node, data }) => [
4180
- createElementVNode("div", {
4181
- id: data.id,
4182
- class: normalizeClass(["cus-tree-node", { "cus-tree-node-hover": _ctx.canHighlight && data.id === _ctx.highlightNode?.id }]),
4183
- onMousedown: _cache[1] || (_cache[1] = (...args) => _ctx.toggleClickFlag && _ctx.toggleClickFlag(...args)),
4184
- onMouseup: _cache[2] || (_cache[2] = (...args) => _ctx.toggleClickFlag && _ctx.toggleClickFlag(...args)),
4185
- onMouseenter: ($event) => _ctx.highlightHandler(data)
4186
- }, [
4187
- renderSlot(_ctx.$slots, "layer-node-content", {
4188
- node,
4189
- data
4190
- }, () => [
4191
- createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
4192
- ])
4193
- ], 42, _hoisted_1$3)
4194
- ]),
4195
- _: 3
4196
- }, 8, ["default-expanded-keys", "load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd", "onNodeCollapse", "onNodeExpand"])) : createCommentVNode("", true),
4197
- (openBlock(), createBlock(Teleport, { to: "body" }, [
4198
- createVNode(_component_layer_menu, { ref: "menu" }, null, 512)
4199
- ]))
4200
- ]),
4201
- _: 3
4202
- });
4203
- }
4204
- const LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$1]]);
4205
-
4206
- const _hoisted_1$2 = {
4207
- key: 1,
4208
- class: "magic-editor-tab-panel-title"
4209
- };
4210
- const _sfc_main$9 = /* @__PURE__ */ defineComponent({
4211
- __name: "TabPane",
4212
- props: {
4213
- data: null
4214
- },
4215
- setup(__props) {
4216
- const props = __props;
4217
- const config = computed(() => {
4218
- if (typeof props.data !== "string") {
4219
- return props.data;
4220
- }
4221
- switch (props.data) {
4222
- case "component-list":
4223
- return {
4224
- type: "component",
4225
- icon: Coin,
4226
- text: "\u7EC4\u4EF6",
4227
- component: _sfc_main$d,
4228
- slots: {}
4229
- };
4230
- case "layer":
4231
- return {
4232
- type: "component",
4233
- icon: Files,
4234
- text: "\u5DF2\u9009\u7EC4\u4EF6",
4235
- component: LayerPanel,
4236
- slots: {}
4237
- };
4238
- case "code-block":
4239
- return {
4240
- type: "component",
4241
- icon: EditPen,
4242
- text: "\u4EE3\u7801\u7F16\u8F91",
4243
- component: _sfc_main$e,
4244
- slots: {}
4245
- };
4246
- default:
4247
- return void 0;
4248
- }
4249
- });
4486
+ const contextmenu = async (event, data) => {
4487
+ event.preventDefault();
4488
+ await select(data);
4489
+ menu.value?.show(event);
4490
+ };
4250
4491
  return (_ctx, _cache) => {
4251
- const _component_el_tab_pane = resolveComponent("el-tab-pane");
4252
- return unref(config) ? (openBlock(), createBlock(_component_el_tab_pane, {
4253
- key: 0,
4254
- name: unref(config).text
4255
- }, {
4256
- label: withCtx(() => [
4257
- (openBlock(), createElementBlock("div", {
4258
- key: unref(config).text
4259
- }, [
4260
- unref(config).icon ? (openBlock(), createBlock(_sfc_main$j, {
4261
- key: 0,
4262
- icon: unref(config).icon
4263
- }, null, 8, ["icon"])) : createCommentVNode("", true),
4264
- unref(config).text ? (openBlock(), createElementBlock("div", _hoisted_1$2, toDisplayString(unref(config).text), 1)) : createCommentVNode("", true)
4265
- ]))
4266
- ]),
4492
+ return openBlock(), createBlock(unref(TMagicScrollbar), { class: "magic-editor-layer-panel" }, {
4267
4493
  default: withCtx(() => [
4268
- (openBlock(), createBlock(resolveDynamicComponent(unref(config).component), mergeProps(unref(config).props || {}, toHandlers(unref(config)?.listeners || {})), createSlots({ _: 2 }, [
4269
- __props.data === "component-list" || unref(config).slots?.componentListPanelHeader ? {
4270
- name: "component-list-panel-header",
4271
- fn: withCtx(() => [
4272
- __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)
4273
- ])
4274
- } : void 0,
4275
- __props.data === "component-list" || unref(config).slots?.componentListItem ? {
4276
- name: "component-list-item",
4277
- fn: withCtx(({ component }) => [
4278
- __props.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
4279
- key: 0,
4280
- component
4281
- }) : unref(config).slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.componentListItem), {
4282
- key: 1,
4283
- component
4284
- }, null, 8, ["component"])) : createCommentVNode("", true)
4285
- ])
4286
- } : void 0,
4287
- __props.data === "layer" || unref(config).slots?.layerPanelHeader ? {
4288
- name: "layer-panel-header",
4289
- fn: withCtx(() => [
4290
- __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)
4291
- ])
4292
- } : void 0,
4293
- __props.data === "code-block" || unref(config).slots?.codeBlockPanelHeader ? {
4294
- name: "code-block-panel-header",
4295
- fn: withCtx(() => [
4296
- __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)
4297
- ])
4298
- } : void 0,
4299
- __props.data === "code-block" || unref(config).slots?.codeBlockPanelTool ? {
4300
- name: "code-block-panel-tool",
4301
- fn: withCtx(({ id, data }) => [
4302
- data === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
4303
- key: 0,
4304
- id,
4494
+ renderSlot(_ctx.$slots, "layer-panel-header"),
4495
+ createVNode(unref(TMagicInput), {
4496
+ modelValue: filterText.value,
4497
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => filterText.value = $event),
4498
+ class: "search-input",
4499
+ size: "small",
4500
+ placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
4501
+ clearable: "",
4502
+ "prefix-icon": unref(Search),
4503
+ onChange: filterTextChangeHandler
4504
+ }, null, 8, ["modelValue", "prefix-icon"]),
4505
+ unref(values).length ? (openBlock(), createBlock(unref(TMagicTree), {
4506
+ key: 0,
4507
+ tabindex: "-1",
4508
+ class: "magic-editor-layer-tree",
4509
+ ref_key: "tree",
4510
+ ref: tree,
4511
+ "node-key": "id",
4512
+ "empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684",
4513
+ draggable: "",
4514
+ "default-expanded-keys": unref(defaultExpandedKeys),
4515
+ load: loadItems,
4516
+ data: unref(values),
4517
+ "default-expand-all": true,
4518
+ "expand-on-click-node": false,
4519
+ "highlight-current": true,
4520
+ props: {
4521
+ children: "items"
4522
+ },
4523
+ "filter-node-method": filterNode,
4524
+ "allow-drop": allowDrop,
4525
+ "show-checkbox": isMultiSelectStatus.value || unref(selectedIds).length > 1,
4526
+ onNodeClick: clickHandler,
4527
+ onNodeContextmenu: contextmenu,
4528
+ onNodeDragEnd: handleDragEnd,
4529
+ onNodeCollapse: handleCollapse,
4530
+ onNodeExpand: handleExpand,
4531
+ onCheck: multiClickHandler,
4532
+ onMousedown: toggleClickFlag,
4533
+ onMouseup: toggleClickFlag,
4534
+ onMouseenter: mouseenterHandler,
4535
+ onMouseleave: mouseleaveHandler
4536
+ }, {
4537
+ default: withCtx(({ node, data }) => [
4538
+ createElementVNode("div", {
4539
+ id: data.id,
4540
+ class: normalizeClass(["cus-tree-node", { "cus-tree-node-hover": canHighlight(data) }]),
4541
+ onMouseenter: ($event) => unref(highlightHandler)(data)
4542
+ }, [
4543
+ renderSlot(_ctx.$slots, "layer-node-content", {
4544
+ node,
4305
4545
  data
4306
- }) : unref(config).slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
4307
- ])
4308
- } : void 0,
4309
- __props.data === "code-block" || unref(config).slots?.codeBlockEditPanelHeader ? {
4310
- name: "code-block-edit-panel-header",
4311
- fn: withCtx(({ id }) => [
4312
- __props.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
4313
- key: 0,
4314
- id
4315
- }) : unref(config).slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
4316
- ])
4317
- } : void 0,
4318
- __props.data === "layer" || unref(config).slots?.layerNodeContent ? {
4319
- name: "layer-node-content",
4320
- fn: withCtx(({ data: nodeData, node }) => [
4321
- __props.data === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
4322
- key: 0,
4323
- data: nodeData,
4324
- node
4325
- }) : unref(config).slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.layerNodeContent), {
4326
- key: 1,
4327
- data: nodeData,
4328
- node
4329
- }, null, 8, ["data", "node"])) : createCommentVNode("", true)
4330
- ])
4331
- } : void 0
4332
- ]), 1040))
4546
+ }, () => [
4547
+ createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
4548
+ ])
4549
+ ], 42, _hoisted_1$4)
4550
+ ]),
4551
+ _: 3
4552
+ }, 8, ["default-expanded-keys", "data", "show-checkbox"])) : createCommentVNode("", true),
4553
+ (openBlock(), createBlock(Teleport, { to: "body" }, [
4554
+ createVNode(_sfc_main$b, {
4555
+ ref_key: "menu",
4556
+ ref: menu,
4557
+ "layer-content-menu": __props.layerContentMenu
4558
+ }, null, 8, ["layer-content-menu"])
4559
+ ]))
4333
4560
  ]),
4334
4561
  _: 3
4335
- }, 8, ["name"])) : createCommentVNode("", true);
4562
+ });
4336
4563
  };
4337
4564
  }
4338
4565
  });
4339
4566
 
4340
- const _sfc_main$8 = /* @__PURE__ */ defineComponent({
4341
- __name: "Sidebar",
4567
+ const _hoisted_1$3 = {
4568
+ key: 1,
4569
+ class: "magic-editor-tab-panel-title"
4570
+ };
4571
+ const __default__$8 = defineComponent({
4572
+ name: "MEditorSidebar"
4573
+ });
4574
+ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
4575
+ ...__default__$8,
4342
4576
  props: {
4343
- data: { default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer", "code-block"] }) }
4577
+ data: { default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer", "code-block"] }) },
4578
+ layerContentMenu: null
4344
4579
  },
4345
4580
  setup(__props, { expose }) {
4346
4581
  const props = __props;
4582
+ const uiComponent = getConfig$1("components").tabPane;
4347
4583
  const activeTabName = ref(props.data?.status);
4584
+ const getItemConfig = (data) => {
4585
+ const map = {
4586
+ "component-list": {
4587
+ $key: "component-list",
4588
+ type: "component",
4589
+ icon: Coin,
4590
+ text: "\u7EC4\u4EF6",
4591
+ component: _sfc_main$d,
4592
+ slots: {}
4593
+ },
4594
+ layer: {
4595
+ $key: "layer",
4596
+ type: "component",
4597
+ icon: Files,
4598
+ text: "\u5DF2\u9009\u7EC4\u4EF6",
4599
+ props: {
4600
+ layerContentMenu: props.layerContentMenu
4601
+ },
4602
+ component: _sfc_main$a,
4603
+ slots: {}
4604
+ },
4605
+ "code-block": {
4606
+ $key: "code-block",
4607
+ type: "component",
4608
+ icon: EditPen,
4609
+ text: "\u4EE3\u7801\u7F16\u8F91",
4610
+ component: _sfc_main$e,
4611
+ slots: {}
4612
+ }
4613
+ };
4614
+ return typeof data === "string" ? map[data] : data;
4615
+ };
4616
+ const sideBarItems = computed(() => props.data.items.map((item) => getItemConfig(item)));
4348
4617
  watch(
4349
4618
  () => props.data.status,
4350
4619
  (status) => {
@@ -4355,8 +4624,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
4355
4624
  activeTabName
4356
4625
  });
4357
4626
  return (_ctx, _cache) => {
4358
- const _component_el_tabs = resolveComponent("el-tabs");
4359
- return __props.data.type === "tabs" && __props.data.items.length ? (openBlock(), createBlock(_component_el_tabs, {
4627
+ return __props.data.type === "tabs" && __props.data.items.length ? (openBlock(), createBlock(unref(TMagicTabs), {
4360
4628
  key: 0,
4361
4629
  class: "m-editor-sidebar",
4362
4630
  modelValue: activeTabName.value,
@@ -4365,60 +4633,91 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
4365
4633
  "tab-position": "left"
4366
4634
  }, {
4367
4635
  default: withCtx(() => [
4368
- (openBlock(true), createElementBlock(Fragment, null, renderList(__props.data.items, (item, index) => {
4369
- return openBlock(), createBlock(_sfc_main$9, {
4636
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(sideBarItems), (config, index) => {
4637
+ return openBlock(), createBlock(resolveDynamicComponent(unref(uiComponent).component), {
4370
4638
  key: index,
4371
- data: item
4372
- }, createSlots({ _: 2 }, [
4373
- item === "layer" ? {
4374
- name: "layer-panel-header",
4375
- fn: withCtx(() => [
4376
- renderSlot(_ctx.$slots, "layer-panel-header")
4377
- ])
4378
- } : void 0,
4379
- item === "layer" ? {
4380
- name: "layer-node-content",
4381
- fn: withCtx(({ node, data }) => [
4382
- renderSlot(_ctx.$slots, "layer-node-content", {
4383
- data,
4384
- node
4385
- })
4386
- ])
4387
- } : void 0,
4388
- item === "component-list" ? {
4389
- name: "component-list-panel-header",
4390
- fn: withCtx(() => [
4391
- renderSlot(_ctx.$slots, "component-list-panel-header")
4392
- ])
4393
- } : void 0,
4394
- item === "component-list" ? {
4395
- name: "component-list-item",
4396
- fn: withCtx(({ component }) => [
4397
- renderSlot(_ctx.$slots, "component-list-item", { component })
4398
- ])
4399
- } : void 0,
4400
- item === "code-block" ? {
4401
- name: "code-block-panel-header",
4402
- fn: withCtx(() => [
4403
- renderSlot(_ctx.$slots, "code-block-panel-header")
4404
- ])
4405
- } : void 0,
4406
- item === "code-block" ? {
4407
- name: "code-block-panel-tool",
4408
- fn: withCtx(({ id, data }) => [
4409
- renderSlot(_ctx.$slots, "code-block-panel-tool", {
4410
- id,
4411
- data
4412
- })
4413
- ])
4414
- } : void 0,
4415
- item === "code-block" ? {
4416
- name: "code-block-edit-panel-header",
4417
- fn: withCtx(({ id }) => [
4418
- renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
4419
- ])
4420
- } : void 0
4421
- ]), 1032, ["data"]);
4639
+ name: config.text
4640
+ }, {
4641
+ label: withCtx(() => [
4642
+ (openBlock(), createElementBlock("div", {
4643
+ key: config.text
4644
+ }, [
4645
+ config.icon ? (openBlock(), createBlock(_sfc_main$n, {
4646
+ key: 0,
4647
+ icon: config.icon
4648
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
4649
+ config.text ? (openBlock(), createElementBlock("div", _hoisted_1$3, toDisplayString(config.text), 1)) : createCommentVNode("", true)
4650
+ ]))
4651
+ ]),
4652
+ default: withCtx(() => [
4653
+ config ? (openBlock(), createBlock(resolveDynamicComponent(config.component), mergeProps({ key: 0 }, config.props || {}, toHandlers(config?.listeners || {})), createSlots({ _: 2 }, [
4654
+ config.$key === "component-list" || config.slots?.componentListPanelHeader ? {
4655
+ name: "component-list-panel-header",
4656
+ fn: withCtx(() => [
4657
+ 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)
4658
+ ])
4659
+ } : void 0,
4660
+ config.$key === "component-list" || config.slots?.componentListItem ? {
4661
+ name: "component-list-item",
4662
+ fn: withCtx(({ component }) => [
4663
+ config.$key === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
4664
+ key: 0,
4665
+ component
4666
+ }) : config.slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.componentListItem), {
4667
+ key: 1,
4668
+ component
4669
+ }, null, 8, ["component"])) : createCommentVNode("", true)
4670
+ ])
4671
+ } : void 0,
4672
+ config.$key === "layer" || config.slots?.layerPanelHeader ? {
4673
+ name: "layer-panel-header",
4674
+ fn: withCtx(() => [
4675
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : config.slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
4676
+ ])
4677
+ } : void 0,
4678
+ config.$key === "code-block" || config.slots?.codeBlockPanelHeader ? {
4679
+ name: "code-block-panel-header",
4680
+ fn: withCtx(() => [
4681
+ 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)
4682
+ ])
4683
+ } : void 0,
4684
+ config.$key === "code-block" || config.slots?.codeBlockPanelTool ? {
4685
+ name: "code-block-panel-tool",
4686
+ fn: withCtx(({ id, data }) => [
4687
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
4688
+ key: 0,
4689
+ id,
4690
+ data
4691
+ }) : config.slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
4692
+ ])
4693
+ } : void 0,
4694
+ config.$key === "code-block" || config.slots?.codeBlockEditPanelHeader ? {
4695
+ name: "code-block-edit-panel-header",
4696
+ fn: withCtx(({ id }) => [
4697
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
4698
+ key: 0,
4699
+ id
4700
+ }) : config.slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
4701
+ ])
4702
+ } : void 0,
4703
+ config.$key === "layer" || config.slots?.layerNodeContent ? {
4704
+ name: "layer-node-content",
4705
+ fn: withCtx(({ data: nodeData, node }) => [
4706
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
4707
+ key: 0,
4708
+ data: nodeData,
4709
+ node
4710
+ }) : config.slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerNodeContent), {
4711
+ key: 1,
4712
+ data: nodeData,
4713
+ node
4714
+ }, null, 8, ["data", "node"])) : createCommentVNode("", true)
4715
+ ])
4716
+ } : void 0
4717
+ ]), 1040)) : createCommentVNode("", true)
4718
+ ]),
4719
+ _: 2
4720
+ }, 1032, ["name"]);
4422
4721
  }), 128))
4423
4722
  ]),
4424
4723
  _: 3
@@ -4427,12 +4726,60 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
4427
4726
  }
4428
4727
  });
4429
4728
 
4729
+ const _hoisted_1$2 = {
4730
+ key: 0,
4731
+ class: "m-editor-breadcrumb"
4732
+ };
4733
+ const _hoisted_2$1 = { key: 0 };
4734
+ const __default__$7 = defineComponent({
4735
+ name: "MEditorBreadcrumb"
4736
+ });
4737
+ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
4738
+ ...__default__$7,
4739
+ setup(__props) {
4740
+ const services = inject("services");
4741
+ const editorService = services?.editorService;
4742
+ const node = computed(() => editorService?.get("node"));
4743
+ const nodes = computed(() => editorService?.get("nodes") || []);
4744
+ const root = computed(() => editorService?.get("root"));
4745
+ const path = computed(() => getNodePath(node.value?.id || "", root.value?.items || []));
4746
+ const select = async (node2) => {
4747
+ await editorService?.select(node2);
4748
+ editorService?.get("stage")?.select(node2.id);
4749
+ };
4750
+ return (_ctx, _cache) => {
4751
+ return unref(nodes).length === 1 ? (openBlock(), createElementBlock("div", _hoisted_1$2, [
4752
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(path), (item, index) => {
4753
+ return openBlock(), createElementBlock(Fragment, {
4754
+ key: item.id
4755
+ }, [
4756
+ createVNode(unref(TMagicButton), {
4757
+ text: "",
4758
+ disabled: item.id === unref(node)?.id,
4759
+ onClick: ($event) => select(item)
4760
+ }, {
4761
+ default: withCtx(() => [
4762
+ createTextVNode(toDisplayString(item.name), 1)
4763
+ ]),
4764
+ _: 2
4765
+ }, 1032, ["disabled", "onClick"]),
4766
+ index < unref(path).length - 1 ? (openBlock(), createElementBlock("span", _hoisted_2$1, "/")) : createCommentVNode("", true)
4767
+ ], 64);
4768
+ }), 128))
4769
+ ])) : createCommentVNode("", true);
4770
+ };
4771
+ }
4772
+ });
4773
+
4430
4774
  const _hoisted_1$1 = {
4431
4775
  key: 1,
4432
4776
  style: { "width": "21px" }
4433
4777
  };
4778
+ const __default__$6 = defineComponent({
4779
+ name: "MEditorPageBarScrollContainer"
4780
+ });
4434
4781
  const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4435
- __name: "PageBarScrollContainer",
4782
+ ...__default__$6,
4436
4783
  setup(__props) {
4437
4784
  const services = inject("services");
4438
4785
  const editorService = services?.editorService;
@@ -4513,14 +4860,14 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4513
4860
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4514
4861
  onClick: addPage
4515
4862
  }, [
4516
- createVNode(_sfc_main$j, { icon: unref(Plus) }, null, 8, ["icon"])
4863
+ createVNode(_sfc_main$n, { icon: unref(Plus) }, null, 8, ["icon"])
4517
4864
  ])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
4518
4865
  canScroll.value ? (openBlock(), createElementBlock("div", {
4519
4866
  key: 2,
4520
4867
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4521
4868
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
4522
4869
  }, [
4523
- createVNode(_sfc_main$j, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
4870
+ createVNode(_sfc_main$n, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
4524
4871
  ])) : createCommentVNode("", true),
4525
4872
  unref(pageLength) ? (openBlock(), createElementBlock("div", {
4526
4873
  key: 3,
@@ -4536,7 +4883,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4536
4883
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4537
4884
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
4538
4885
  }, [
4539
- createVNode(_sfc_main$j, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
4886
+ createVNode(_sfc_main$n, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
4540
4887
  ])) : createCommentVNode("", true)
4541
4888
  ], 512);
4542
4889
  };
@@ -4545,8 +4892,11 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4545
4892
 
4546
4893
  const _hoisted_1 = ["onClick"];
4547
4894
  const _hoisted_2 = { class: "m-editor-page-bar-title" };
4895
+ const __default__$5 = defineComponent({
4896
+ name: "MEditorPageBar"
4897
+ });
4548
4898
  const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4549
- __name: "PageBar",
4899
+ ...__default__$5,
4550
4900
  setup(__props) {
4551
4901
  const services = inject("services");
4552
4902
  const editorService = services?.editorService;
@@ -4566,9 +4916,6 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4566
4916
  editorService?.remove(node);
4567
4917
  };
4568
4918
  return (_ctx, _cache) => {
4569
- const _component_el_tooltip = resolveComponent("el-tooltip");
4570
- const _component_el_icon = resolveComponent("el-icon");
4571
- const _component_el_popover = resolveComponent("el-popover");
4572
4919
  return openBlock(), createBlock(_sfc_main$7, null, {
4573
4920
  default: withCtx(() => [
4574
4921
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(root) && unref(root).items || [], (item) => {
@@ -4579,7 +4926,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4579
4926
  }, [
4580
4927
  createElementVNode("div", _hoisted_2, [
4581
4928
  renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
4582
- createVNode(_component_el_tooltip, {
4929
+ createVNode(unref(TMagicTooltip), {
4583
4930
  effect: "dark",
4584
4931
  placement: "top-start",
4585
4932
  content: item.name
@@ -4591,14 +4938,14 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4591
4938
  }, 1032, ["content"])
4592
4939
  ])
4593
4940
  ]),
4594
- createVNode(_component_el_popover, {
4941
+ createVNode(unref(TMagicPopover), {
4595
4942
  "popper-class": "page-bar-popover",
4596
4943
  placement: "top",
4597
4944
  width: 160,
4598
4945
  trigger: "hover"
4599
4946
  }, {
4600
4947
  reference: withCtx(() => [
4601
- createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-icon" }, {
4948
+ createVNode(unref(TMagicIcon), { class: "m-editor-page-bar-menu-icon" }, {
4602
4949
  default: withCtx(() => [
4603
4950
  createVNode(unref(CaretBottom))
4604
4951
  ]),
@@ -4608,7 +4955,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4608
4955
  default: withCtx(() => [
4609
4956
  createElementVNode("div", null, [
4610
4957
  renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
4611
- createVNode(_sfc_main$i, {
4958
+ createVNode(_sfc_main$k, {
4612
4959
  data: {
4613
4960
  type: "button",
4614
4961
  text: "\u590D\u5236",
@@ -4616,7 +4963,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4616
4963
  handler: () => copy(item)
4617
4964
  }
4618
4965
  }, null, 8, ["data"]),
4619
- createVNode(_sfc_main$i, {
4966
+ createVNode(_sfc_main$k, {
4620
4967
  data: {
4621
4968
  type: "button",
4622
4969
  text: "\u5220\u9664",
@@ -4650,6 +4997,10 @@ class ScrollViewer extends EventEmitter {
4650
4997
  height = 0;
4651
4998
  translateXCorrectionValue = 0;
4652
4999
  translateYCorrectionValue = 0;
5000
+ correctionScrollSize = {
5001
+ width: 0,
5002
+ height: 0
5003
+ };
4653
5004
  resizeObserver = new ResizeObserver(() => {
4654
5005
  this.setSize();
4655
5006
  this.setScrollSize();
@@ -4659,6 +5010,12 @@ class ScrollViewer extends EventEmitter {
4659
5010
  this.container = options.container;
4660
5011
  this.target = options.target;
4661
5012
  this.zoom = options.zoom;
5013
+ if (this.correctionScrollSize) {
5014
+ this.correctionScrollSize = {
5015
+ ...this.correctionScrollSize,
5016
+ ...options.correctionScrollSize
5017
+ };
5018
+ }
4662
5019
  this.container.addEventListener("wheel", this.wheelHandler, false);
4663
5020
  this.setSize();
4664
5021
  this.setScrollSize();
@@ -4721,9 +5078,9 @@ class ScrollViewer extends EventEmitter {
4721
5078
  }
4722
5079
  setScrollSize = () => {
4723
5080
  const targetRect = this.target.getBoundingClientRect();
4724
- this.scrollWidth = targetRect.width * this.zoom + 100;
5081
+ this.scrollWidth = targetRect.width * this.zoom + this.correctionScrollSize.width;
4725
5082
  const targetMarginTop = Number(this.target.style.marginTop) || 0;
4726
- this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + 100;
5083
+ this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + this.correctionScrollSize.height;
4727
5084
  let left;
4728
5085
  let top;
4729
5086
  if (this.scrollWidth < this.width) {
@@ -4756,8 +5113,11 @@ class ScrollViewer extends EventEmitter {
4756
5113
  };
4757
5114
  }
4758
5115
 
5116
+ const __default__$4 = defineComponent({
5117
+ name: "MEditorScrollBar"
5118
+ });
4759
5119
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
4760
- __name: "ScrollBar",
5120
+ ...__default__$4,
4761
5121
  props: {
4762
5122
  size: null,
4763
5123
  scrollSize: null,
@@ -4842,14 +5202,21 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
4842
5202
 
4843
5203
  const ScrollBar_vue_vue_type_style_index_0_lang = '';
4844
5204
 
5205
+ const __default__$3 = defineComponent({
5206
+ name: "MEditorScrollViewer"
5207
+ });
4845
5208
  const _sfc_main$4 = /* @__PURE__ */ defineComponent({
4846
- __name: "ScrollViewer",
5209
+ ...__default__$3,
4847
5210
  props: {
4848
5211
  width: { default: 0 },
4849
5212
  height: { default: 0 },
4850
5213
  wrapWidth: { default: 0 },
4851
5214
  wrapHeight: { default: 0 },
4852
- zoom: { default: 1 }
5215
+ zoom: { default: 1 },
5216
+ correctionScrollSize: { default: () => ({
5217
+ width: 0,
5218
+ height: 0
5219
+ }) }
4853
5220
  },
4854
5221
  setup(__props, { expose }) {
4855
5222
  const props = __props;
@@ -4872,7 +5239,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
4872
5239
  scrollViewer = new ScrollViewer({
4873
5240
  container: container.value,
4874
5241
  target: el.value,
4875
- zoom: props.zoom
5242
+ zoom: props.zoom,
5243
+ correctionScrollSize: props.correctionScrollSize
4876
5244
  });
4877
5245
  scrollViewer.on("scroll", (data) => {
4878
5246
  hOffset.value = data.scrollLeft;
@@ -4940,10 +5308,14 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
4940
5308
  }
4941
5309
  });
4942
5310
 
5311
+ const __default__$2 = defineComponent({
5312
+ name: "MEditorViewerMenu"
5313
+ });
4943
5314
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
4944
- __name: "ViewerMenu",
5315
+ ...__default__$2,
4945
5316
  props: {
4946
- isMultiSelect: { type: Boolean, default: false }
5317
+ isMultiSelect: { type: Boolean, default: false },
5318
+ stageContentMenu: null
4947
5319
  },
4948
5320
  setup(__props, { expose }) {
4949
5321
  const props = __props;
@@ -4956,8 +5328,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
4956
5328
  const nodes = computed(() => editorService?.get("nodes"));
4957
5329
  const parent = computed(() => editorService?.get("parent"));
4958
5330
  const stage = computed(() => editorService?.get("stage"));
4959
- const stageContentMenu = inject("stageContentMenu", []);
4960
- const menuData = reactive([
5331
+ const menuData = computed(() => [
4961
5332
  {
4962
5333
  type: "button",
4963
5334
  text: "\u6C34\u5E73\u5C45\u4E2D",
@@ -4971,7 +5342,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
4971
5342
  {
4972
5343
  type: "button",
4973
5344
  text: "\u590D\u5236",
4974
- icon: markRaw(DocumentCopy),
5345
+ icon: markRaw(CopyDocument),
4975
5346
  handler: () => {
4976
5347
  nodes.value && editorService?.copy(nodes.value);
4977
5348
  canPaste.value = true;
@@ -4980,6 +5351,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
4980
5351
  {
4981
5352
  type: "button",
4982
5353
  text: "\u7C98\u8D34",
5354
+ icon: markRaw(DocumentCopy),
4983
5355
  display: () => canPaste.value,
4984
5356
  handler: () => {
4985
5357
  const rect = menu.value?.$el.getBoundingClientRect();
@@ -5059,7 +5431,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5059
5431
  editorService?.get("stage").clearGuides();
5060
5432
  }
5061
5433
  },
5062
- ...stageContentMenu
5434
+ ...props.stageContentMenu
5063
5435
  ]);
5064
5436
  watch(
5065
5437
  parent,
@@ -5083,7 +5455,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5083
5455
  expose({ show });
5084
5456
  return (_ctx, _cache) => {
5085
5457
  return openBlock(), createBlock(_sfc_main$c, {
5086
- "menu-data": menuData,
5458
+ "menu-data": unref(menuData),
5087
5459
  ref_key: "menu",
5088
5460
  ref: menu
5089
5461
  }, null, 8, ["menu-data"]);
@@ -5091,8 +5463,14 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5091
5463
  }
5092
5464
  });
5093
5465
 
5466
+ const __default__$1 = defineComponent({
5467
+ name: "MEditorStage"
5468
+ });
5094
5469
  const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5095
- __name: "Stage",
5470
+ ...__default__$1,
5471
+ props: {
5472
+ stageContentMenu: null
5473
+ },
5096
5474
  setup(__props) {
5097
5475
  let stage = null;
5098
5476
  let runtime = null;
@@ -5109,7 +5487,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5109
5487
  const zoom = computed(() => services?.uiService.get("zoom") || 1);
5110
5488
  const node = computed(() => services?.editorService.get("node"));
5111
5489
  watchEffect(() => {
5112
- if (stage)
5490
+ if (stage || !page.value)
5113
5491
  return;
5114
5492
  if (!stageContainer.value)
5115
5493
  return;
@@ -5139,6 +5517,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5139
5517
  runtime.updateRootConfig?.(cloneDeep(toRaw(root2)));
5140
5518
  }
5141
5519
  });
5520
+ watch(page, (page2) => {
5521
+ if (runtime && page2) {
5522
+ runtime.updatePageId?.(page2.id);
5523
+ nextTick(() => {
5524
+ stage?.select(page2.id);
5525
+ });
5526
+ }
5527
+ });
5142
5528
  const resizeObserver = new ResizeObserver((entries) => {
5143
5529
  for (const { contentRect } of entries) {
5144
5530
  services?.uiService.set("stageContainerRect", {
@@ -5211,7 +5597,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5211
5597
  height: unref(stageRect)?.height,
5212
5598
  "wrap-width": unref(stageContainerRect)?.width,
5213
5599
  "wrap-height": unref(stageContainerRect)?.height,
5214
- zoom: unref(zoom)
5600
+ zoom: unref(zoom),
5601
+ "correction-scroll-size": {
5602
+ width: 60,
5603
+ height: 50
5604
+ }
5215
5605
  }, {
5216
5606
  default: withCtx(() => [
5217
5607
  createElementVNode("div", {
@@ -5227,8 +5617,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5227
5617
  createVNode(_sfc_main$3, {
5228
5618
  ref_key: "menu",
5229
5619
  ref: menu,
5230
- "is-multi-select": unref(isMultiSelect)
5231
- }, null, 8, ["is-multi-select"])
5620
+ "is-multi-select": unref(isMultiSelect),
5621
+ "stage-content-menu": __props.stageContentMenu
5622
+ }, null, 8, ["is-multi-select", "stage-content-menu"])
5232
5623
  ]))
5233
5624
  ]),
5234
5625
  _: 1
@@ -5237,8 +5628,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5237
5628
  }
5238
5629
  });
5239
5630
 
5631
+ const __default__ = defineComponent({
5632
+ name: "MEditorWorkspace"
5633
+ });
5240
5634
  const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5241
- __name: "Workspace",
5635
+ ...__default__,
5636
+ props: {
5637
+ stageContentMenu: null
5638
+ },
5242
5639
  setup(__props) {
5243
5640
  const services = inject("services");
5244
5641
  const workspace = ref();
@@ -5347,10 +5744,12 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5347
5744
  ref_key: "workspace",
5348
5745
  ref: workspace
5349
5746
  }, [
5747
+ createVNode(_sfc_main$8),
5350
5748
  renderSlot(_ctx.$slots, "stage", {}, () => [
5351
- (openBlock(), createBlock(_sfc_main$2, {
5352
- key: unref(page)?.id
5353
- }))
5749
+ unref(page) ? (openBlock(), createBlock(_sfc_main$2, {
5750
+ key: 0,
5751
+ "stage-content-menu": __props.stageContentMenu
5752
+ }, null, 8, ["stage-content-menu"])) : createCommentVNode("", true)
5354
5753
  ]),
5355
5754
  renderSlot(_ctx.$slots, "workspace-content"),
5356
5755
  createVNode(_sfc_main$6, null, {
@@ -5380,9 +5779,13 @@ class ComponentList extends BaseService {
5380
5779
  getList() {
5381
5780
  return this.state.list;
5382
5781
  }
5383
- destroy() {
5782
+ resetState() {
5384
5783
  this.state.list = [];
5784
+ }
5785
+ destroy() {
5786
+ this.resetState();
5385
5787
  this.removeAllListeners();
5788
+ this.removeAllPlugins();
5386
5789
  }
5387
5790
  }
5388
5791
  const componentListService = new ComponentList();
@@ -5390,11 +5793,11 @@ const componentListService = new ComponentList();
5390
5793
  const _sfc_main = defineComponent({
5391
5794
  name: "m-editor",
5392
5795
  components: {
5393
- NavMenu: _sfc_main$h,
5394
- Sidebar: _sfc_main$8,
5796
+ NavMenu: _sfc_main$j,
5797
+ Sidebar: _sfc_main$9,
5395
5798
  Workspace: _sfc_main$1,
5396
- PropsPanel: _sfc_main$g,
5397
- Framework: _sfc_main$k
5799
+ PropsPanel: _sfc_main$i,
5800
+ Framework: _sfc_main$l
5398
5801
  },
5399
5802
  props: {
5400
5803
  modelValue: {
@@ -5409,6 +5812,10 @@ const _sfc_main = defineComponent({
5409
5812
  sidebar: {
5410
5813
  type: Object
5411
5814
  },
5815
+ menu: {
5816
+ type: Object,
5817
+ default: () => ({ left: [], right: [] })
5818
+ },
5412
5819
  layerContentMenu: {
5413
5820
  type: Array,
5414
5821
  default: () => []
@@ -5417,10 +5824,6 @@ const _sfc_main = defineComponent({
5417
5824
  type: Array,
5418
5825
  default: () => []
5419
5826
  },
5420
- menu: {
5421
- type: Object,
5422
- default: () => ({ left: [], right: [] })
5423
- },
5424
5827
  render: {
5425
5828
  type: Function
5426
5829
  },
@@ -5454,7 +5857,7 @@ const _sfc_main = defineComponent({
5454
5857
  },
5455
5858
  containerHighlightClassName: {
5456
5859
  type: String,
5457
- default: CONTAINER_HIGHLIGHT_CLASS
5860
+ default: CONTAINER_HIGHLIGHT_CLASS_NAME
5458
5861
  },
5459
5862
  containerHighlightDuration: {
5460
5863
  type: Number,
@@ -5478,14 +5881,23 @@ const _sfc_main = defineComponent({
5478
5881
  emits: ["props-panel-mounted", "update:modelValue"],
5479
5882
  setup(props, { emit }) {
5480
5883
  editorService.on("root-change", (value) => {
5481
- const node = editorService.get("node");
5482
- const nodeId = node?.id || props.defaultSelected;
5483
- if (nodeId && node !== value) {
5484
- editorService.select(nodeId);
5485
- } else {
5884
+ const nodeId = editorService.get("node")?.id || props.defaultSelected;
5885
+ let node;
5886
+ if (nodeId) {
5887
+ node = editorService.getNodeById(nodeId);
5888
+ }
5889
+ if (node && node !== value) {
5890
+ editorService.select(node.id);
5891
+ } else if (value?.items?.length) {
5892
+ editorService.select(value.items[0]);
5893
+ } else if (value?.id) {
5486
5894
  editorService.set("nodes", [value]);
5895
+ editorService.set("parent", null);
5896
+ editorService.set("page", null);
5897
+ }
5898
+ if (toRaw(value) !== toRaw(editorService.get("root"))) {
5899
+ emit("update:modelValue", value);
5487
5900
  }
5488
- emit("update:modelValue", toRaw(editorService.get("root")));
5489
5901
  });
5490
5902
  watch(
5491
5903
  () => props.modelValue,
@@ -5548,13 +5960,12 @@ const _sfc_main = defineComponent({
5548
5960
  }
5549
5961
  );
5550
5962
  onUnmounted(() => {
5551
- editorService.destroy();
5552
- historyService.destroy();
5553
- propsService.destroy();
5554
- uiService.destroy();
5555
- componentListService.destroy();
5556
- storageService.destroy();
5557
- codeBlockService.destroy();
5963
+ editorService.resetState();
5964
+ historyService.resetState();
5965
+ propsService.resetState();
5966
+ uiService.resetState();
5967
+ componentListService.resetState();
5968
+ codeBlockService.resetState();
5558
5969
  });
5559
5970
  const services = {
5560
5971
  componentListService,
@@ -5567,8 +5978,7 @@ const _sfc_main = defineComponent({
5567
5978
  codeBlockService
5568
5979
  };
5569
5980
  provide("services", services);
5570
- provide("layerContentMenu", props.layerContentMenu);
5571
- provide("stageContentMenu", props.stageContentMenu);
5981
+ provide("codeOptions", props.codeOptions);
5572
5982
  provide(
5573
5983
  "stageOptions",
5574
5984
  reactive({
@@ -5588,21 +5998,32 @@ const _sfc_main = defineComponent({
5588
5998
  }
5589
5999
  });
5590
6000
 
6001
+ const _export_sfc = (sfc, props) => {
6002
+ const target = sfc.__vccOpts || sfc;
6003
+ for (const [key, val] of props) {
6004
+ target[key] = val;
6005
+ }
6006
+ return target;
6007
+ };
6008
+
5591
6009
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5592
- const _component_nav_menu = resolveComponent("nav-menu");
5593
- const _component_sidebar = resolveComponent("sidebar");
5594
- const _component_workspace = resolveComponent("workspace");
5595
- const _component_props_panel = resolveComponent("props-panel");
5596
- const _component_framework = resolveComponent("framework");
5597
- return openBlock(), createBlock(_component_framework, { "code-options": _ctx.codeOptions }, {
6010
+ const _component_NavMenu = resolveComponent("NavMenu");
6011
+ const _component_Sidebar = resolveComponent("Sidebar");
6012
+ const _component_Workspace = resolveComponent("Workspace");
6013
+ const _component_PropsPanel = resolveComponent("PropsPanel");
6014
+ const _component_Framework = resolveComponent("Framework");
6015
+ return openBlock(), createBlock(_component_Framework, { "code-options": _ctx.codeOptions }, {
5598
6016
  nav: withCtx(() => [
5599
6017
  renderSlot(_ctx.$slots, "nav", { editorService: _ctx.editorService }, () => [
5600
- createVNode(_component_nav_menu, { data: _ctx.menu }, null, 8, ["data"])
6018
+ createVNode(_component_NavMenu, { data: _ctx.menu }, null, 8, ["data"])
5601
6019
  ])
5602
6020
  ]),
5603
6021
  sidebar: withCtx(() => [
5604
6022
  renderSlot(_ctx.$slots, "sidebar", { editorService: _ctx.editorService }, () => [
5605
- createVNode(_component_sidebar, { data: _ctx.sidebar }, {
6023
+ createVNode(_component_Sidebar, {
6024
+ data: _ctx.sidebar,
6025
+ "layer-content-menu": _ctx.layerContentMenu
6026
+ }, {
5606
6027
  "layer-panel-header": withCtx(() => [
5607
6028
  renderSlot(_ctx.$slots, "layer-panel-header")
5608
6029
  ]),
@@ -5631,12 +6052,12 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5631
6052
  renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
5632
6053
  ]),
5633
6054
  _: 3
5634
- }, 8, ["data"])
6055
+ }, 8, ["data", "layer-content-menu"])
5635
6056
  ])
5636
6057
  ]),
5637
6058
  workspace: withCtx(() => [
5638
6059
  renderSlot(_ctx.$slots, "workspace", { editorService: _ctx.editorService }, () => [
5639
- createVNode(_component_workspace, null, {
6060
+ createVNode(_component_Workspace, { "stage-content-menu": _ctx.stageContentMenu }, {
5640
6061
  stage: withCtx(() => [
5641
6062
  renderSlot(_ctx.$slots, "stage")
5642
6063
  ]),
@@ -5650,12 +6071,12 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5650
6071
  renderSlot(_ctx.$slots, "page-bar-popover", { page })
5651
6072
  ]),
5652
6073
  _: 3
5653
- })
6074
+ }, 8, ["stage-content-menu"])
5654
6075
  ])
5655
6076
  ]),
5656
6077
  "props-panel": withCtx(() => [
5657
6078
  renderSlot(_ctx.$slots, "props-panel", {}, () => [
5658
- createVNode(_component_props_panel, {
6079
+ createVNode(_component_PropsPanel, {
5659
6080
  onMounted: _cache[0] || (_cache[0] = (instance) => _ctx.$emit("props-panel-mounted", instance))
5660
6081
  }, {
5661
6082
  "props-panel-header": withCtx(() => [
@@ -5682,13 +6103,13 @@ const index = {
5682
6103
  app.config.globalProperties.$TMAGIC_EDITOR = option;
5683
6104
  setConfig(option);
5684
6105
  app.component(Editor.name, Editor);
5685
- app.component("m-fields-ui-select", _sfc_main$p);
5686
- app.component("m-fields-code-link", _sfc_main$r);
5687
- app.component("m-fields-vs-code", _sfc_main$s);
5688
- app.component("magic-code-editor", _sfc_main$o);
5689
- app.component("m-fields-code-select", _sfc_main$q);
6106
+ app.component("m-fields-ui-select", _sfc_main$r);
6107
+ app.component("m-fields-code-link", _sfc_main$t);
6108
+ app.component("m-fields-vs-code", _sfc_main$u);
6109
+ app.component("magic-code-editor", _sfc_main$q);
6110
+ app.component("m-fields-code-select", _sfc_main$s);
5690
6111
  }
5691
6112
  };
5692
6113
 
5693
- export { COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, CodeEditorMode, _sfc_main$q as CodeSelect, CodeSelectOp, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$j as Icon, Keys, LayerOffset, LayerPanel, Layout, _sfc_main$g as PropsPanel, _sfc_main$o as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$i 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 };
5694
- //# sourceMappingURL=tmagic-editor.mjs.map
6114
+ export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, CodeEditorMode, _sfc_main$s as CodeSelect, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$n as Icon, Keys, LayerOffset, _sfc_main$a as LayerPanel, Layout, _sfc_main$o as LayoutContainer, _sfc_main$i as PropsPanel, _sfc_main$q 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 };
6115
+ //# sourceMappingURL=tmagic-editor.js.map