@tmagic/editor 1.2.0-beta.8 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/style.css +59 -35
  2. package/dist/{tmagic-editor.mjs → tmagic-editor.js} +1473 -1161
  3. package/dist/tmagic-editor.js.map +1 -0
  4. package/dist/{tmagic-editor.umd.js → tmagic-editor.umd.cjs} +1483 -1166
  5. package/dist/tmagic-editor.umd.cjs.map +1 -0
  6. package/package.json +16 -14
  7. package/src/Editor.vue +66 -40
  8. package/src/components/CodeDraftEditor.vue +145 -0
  9. package/src/components/ContentMenu.vue +2 -2
  10. package/src/components/FunctionEditor.vue +145 -0
  11. package/src/components/Icon.vue +1 -1
  12. package/src/{layouts → components}/Layout.vue +54 -15
  13. package/src/components/ScrollBar.vue +1 -1
  14. package/src/components/ScrollViewer.vue +10 -1
  15. package/src/components/ToolButton.vue +1 -1
  16. package/src/fields/Code.vue +1 -1
  17. package/src/fields/CodeLink.vue +1 -1
  18. package/src/fields/CodeSelect.vue +84 -110
  19. package/src/fields/UISelect.vue +1 -1
  20. package/src/index.ts +1 -0
  21. package/src/layouts/AddPageBox.vue +1 -1
  22. package/src/layouts/CodeEditor.vue +2 -3
  23. package/src/layouts/Framework.vue +2 -2
  24. package/src/layouts/NavMenu.vue +2 -2
  25. package/src/layouts/PropsPanel.vue +13 -6
  26. package/src/layouts/Resizer.vue +1 -1
  27. package/src/layouts/sidebar/ComponentListPanel.vue +1 -1
  28. package/src/layouts/sidebar/LayerMenu.vue +9 -7
  29. package/src/layouts/sidebar/LayerPanel.vue +127 -174
  30. package/src/layouts/sidebar/Sidebar.vue +110 -26
  31. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +27 -83
  32. package/src/layouts/sidebar/code-block/CodeBlockList.vue +90 -122
  33. package/src/layouts/workspace/Breadcrumb.vue +1 -1
  34. package/src/layouts/workspace/PageBar.vue +1 -1
  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 +7 -3
  39. package/src/services/BaseService.ts +10 -1
  40. package/src/services/codeBlock.ts +124 -125
  41. package/src/services/componentList.ts +6 -1
  42. package/src/services/editor.ts +54 -18
  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/code-block.scss +43 -24
  49. package/src/theme/component-list-panel.scss +8 -5
  50. package/src/type.ts +77 -50
  51. package/src/utils/editor.ts +9 -1
  52. package/src/utils/index.ts +1 -0
  53. package/src/utils/props.ts +2 -2
  54. package/src/utils/scroll-viewer.ts +18 -2
  55. package/src/utils/stage.ts +4 -3
  56. package/types/Editor.vue.d.ts +47 -27
  57. package/types/components/CodeDraftEditor.vue.d.ts +56 -0
  58. package/types/components/ContentMenu.vue.d.ts +11 -87
  59. package/types/components/FunctionEditor.vue.d.ts +43 -0
  60. package/types/components/Icon.vue.d.ts +4 -50
  61. package/types/{layouts → components}/Layout.vue.d.ts +12 -1
  62. package/types/components/ScrollBar.vue.d.ts +7 -65
  63. package/types/components/ScrollViewer.vue.d.ts +45 -1
  64. package/types/components/ToolButton.vue.d.ts +12 -78
  65. package/types/fields/Code.vue.d.ts +11 -77
  66. package/types/fields/CodeLink.vue.d.ts +12 -82
  67. package/types/fields/CodeSelect.vue.d.ts +13 -77
  68. package/types/fields/UISelect.vue.d.ts +7 -65
  69. package/types/index.d.ts +1 -0
  70. package/types/layouts/AddPageBox.vue.d.ts +1 -43
  71. package/types/layouts/CodeEditor.vue.d.ts +22 -130
  72. package/types/layouts/NavMenu.vue.d.ts +9 -69
  73. package/types/layouts/sidebar/LayerMenu.vue.d.ts +16 -48
  74. package/types/layouts/sidebar/LayerPanel.vue.d.ts +24 -7
  75. package/types/layouts/sidebar/Sidebar.vue.d.ts +10 -5
  76. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +1 -1
  77. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +6 -5
  78. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -43
  79. package/types/layouts/workspace/Stage.vue.d.ts +15 -43
  80. package/types/layouts/workspace/ViewerMenu.vue.d.ts +11 -66
  81. package/types/layouts/workspace/Workspace.vue.d.ts +23 -5
  82. package/types/services/BaseService.d.ts +2 -1
  83. package/types/services/codeBlock.d.ts +57 -36
  84. package/types/services/componentList.d.ts +1 -0
  85. package/types/services/editor.d.ts +5 -6
  86. package/types/services/events.d.ts +1 -0
  87. package/types/services/history.d.ts +5 -15
  88. package/types/services/props.d.ts +3 -2
  89. package/types/services/ui.d.ts +2 -1
  90. package/types/type.d.ts +65 -48
  91. package/types/utils/editor.d.ts +1 -0
  92. package/types/utils/index.d.ts +1 -0
  93. package/types/utils/props.d.ts +1 -1
  94. package/types/utils/scroll-viewer.d.ts +5 -0
  95. package/dist/tmagic-editor.mjs.map +0 -1
  96. package/dist/tmagic-editor.umd.js.map +0 -1
  97. package/src/layouts/sidebar/TabPane.vue +0 -118
  98. package/types/layouts/sidebar/TabPane.vue.d.ts +0 -82
@@ -1,19 +1,23 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, inject, ref, watchEffect, createElementBlock, createVNode, withCtx, createElementVNode, withModifiers, createCommentVNode, createTextVNode, toDisplayString, onMounted, onUnmounted, normalizeClass, resolveDynamicComponent, toRaw, renderSlot, Fragment, createSlots, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, isRef, 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 { cloneDeep, map, xor, throttle, pick, isEmpty, forIn, omit, keys, mergeWith, uniq } from 'lodash-es';
4
- import { TMagicCard, TMagicTooltip, tMagicMessage, TMagicButton, TMagicIcon, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, TMagicDialog, TMagicInput, TMagicTree, TMagicCollapse, TMagicCollapseItem, TMagicTabPane, TMagicTabs, TMagicPopover } from '@tmagic/design';
5
- import { Delete, Close, Edit, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, View, Link, Search, Files, DocumentCopy, EditPen, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
3
+ import { isEmpty, map, throttle, pick, omit, keys, cloneDeep, forIn, mergeWith, uniq, isObject, difference, union } 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$t = /* @__PURE__ */ defineComponent({
16
- __name: "Code",
16
+ const __default__$t = defineComponent({
17
+ name: "MEditorCode"
18
+ });
19
+ const _sfc_main$u = /* @__PURE__ */ defineComponent({
20
+ ...__default__$t,
17
21
  props: {
18
22
  model: null,
19
23
  name: null,
@@ -42,8 +46,11 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
42
46
  }
43
47
  });
44
48
 
45
- const _sfc_main$s = /* @__PURE__ */ defineComponent({
46
- __name: "CodeLink",
49
+ const __default__$s = defineComponent({
50
+ name: "MEditorCodeLink"
51
+ });
52
+ const _sfc_main$t = /* @__PURE__ */ defineComponent({
53
+ ...__default__$s,
47
54
  props: {
48
55
  config: null,
49
56
  model: null,
@@ -112,57 +119,12 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
112
119
  }
113
120
  });
114
121
 
115
- var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
116
- ColumnLayout2["LEFT"] = "left";
117
- ColumnLayout2["CENTER"] = "center";
118
- ColumnLayout2["RIGHT"] = "right";
119
- return ColumnLayout2;
120
- })(ColumnLayout || {});
121
- var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
122
- LayerOffset2["TOP"] = "top";
123
- LayerOffset2["BOTTOM"] = "bottom";
124
- return LayerOffset2;
125
- })(LayerOffset || {});
126
- var Layout = /* @__PURE__ */ ((Layout2) => {
127
- Layout2["FLEX"] = "flex";
128
- Layout2["FIXED"] = "fixed";
129
- Layout2["RELATIVE"] = "relative";
130
- Layout2["ABSOLUTE"] = "absolute";
131
- return Layout2;
132
- })(Layout || {});
133
- var Keys = /* @__PURE__ */ ((Keys2) => {
134
- Keys2["ESCAPE"] = "Space";
135
- return Keys2;
136
- })(Keys || {});
137
- const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
138
- const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
139
- var CodeEditorMode = /* @__PURE__ */ ((CodeEditorMode2) => {
140
- CodeEditorMode2["LIST"] = "list";
141
- CodeEditorMode2["EDITOR"] = "editor";
142
- return CodeEditorMode2;
143
- })(CodeEditorMode || {});
144
- var CodeDeleteErrorType = /* @__PURE__ */ ((CodeDeleteErrorType2) => {
145
- CodeDeleteErrorType2["UNDELETEABLE"] = "undeleteable";
146
- CodeDeleteErrorType2["BIND"] = "bind";
147
- return CodeDeleteErrorType2;
148
- })(CodeDeleteErrorType || {});
149
- var CodeSelectOp = /* @__PURE__ */ ((CodeSelectOp2) => {
150
- CodeSelectOp2["ADD"] = "add";
151
- CodeSelectOp2["DELETE"] = "delete";
152
- CodeSelectOp2["CHANGE"] = "change";
153
- return CodeSelectOp2;
154
- })(CodeSelectOp || {});
155
-
156
- const _hoisted_1$e = { class: "tool-bar" };
157
- const _hoisted_2$6 = /* @__PURE__ */ createElementVNode("path", {
158
- fill: "currentColor",
159
- d: "m23 12l-7.071 7.071l-1.414-1.414L20.172 12l-5.657-5.657l1.414-1.414L23 12zM3.828 12l5.657 5.657l-1.414 1.414L1 12l7.071-7.071l1.414 1.414L3.828 12z"
160
- }, null, -1);
161
- const _hoisted_3$3 = [
162
- _hoisted_2$6
163
- ];
164
- const _sfc_main$r = /* @__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,128 +136,107 @@ const _sfc_main$r = /* @__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
- let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
200
- let shouldWatch = true;
201
187
  watch(
202
188
  () => props.model[props.name],
203
- (selectValue) => {
204
- if (shouldWatch) {
205
- lastTagSnapshot = cloneDeep(selectValue) || [];
189
+ (value) => {
190
+ if (isEmpty(value)) {
191
+ props.model[props.name] = {
192
+ hookType: HookType.CODE,
193
+ hookData: []
194
+ };
206
195
  }
196
+ },
197
+ {
198
+ immediate: true
207
199
  }
208
200
  );
209
- watchEffect(async () => {
210
- const combineNames = await Promise.all(
211
- props.model[props.name].map(async (id) => {
212
- const { name = "" } = await services?.codeBlockService.getCodeContentById(id) || {};
213
- return name;
214
- })
215
- );
216
- fieldKey.value = combineNames.join("-");
217
- });
218
- const changeHandler = async (value) => {
219
- shouldWatch = false;
220
- let codeIds = value;
221
- if (typeof value === "string") {
222
- multiple.value = false;
223
- lastTagSnapshot = [lastTagSnapshot];
224
- codeIds = value ? [value] : [];
225
- }
226
- await setCombineRelation(codeIds);
227
- emit("change", value);
228
- };
229
- const setCombineRelation = async (codeIds) => {
230
- const { id = "" } = services?.editorService.get("node") || {};
231
- let opFlag = CodeSelectOp.CHANGE;
232
- let diffValues = codeIds;
233
- if (multiple.value) {
234
- opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
235
- diffValues = xor(codeIds, lastTagSnapshot);
236
- }
237
- await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
238
- lastTagSnapshot = codeIds;
239
- shouldWatch = true;
201
+ const changeHandler = async () => {
202
+ emit("change", props.model[props.name]);
240
203
  };
241
- const viewHandler = async () => {
242
- if (props.model[props.name].length === 0) {
243
- tMagicMessage.error("\u8BF7\u5148\u7ED1\u5B9A\u4EE3\u7801\u5757");
244
- return;
245
- }
246
- await services?.codeBlockService.setCombineIds(props.model[props.name]);
247
- await services?.codeBlockService.setMode(CodeEditorMode.LIST);
248
- services?.codeBlockService.setCodeEditorContent(true, props.model[props.name][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
+ }));
249
216
  };
250
217
  return (_ctx, _cache) => {
251
- const _component_m_fields_select = resolveComponent("m-fields-select");
252
- return openBlock(), createElementBlock("div", {
253
- class: "m-fields-code-select",
254
- key: fieldKey.value
255
- }, [
256
- createVNode(unref(TMagicCard), { shadow: "never" }, {
257
- header: withCtx(() => [
258
- createVNode(_component_m_fields_select, {
259
- config: unref(selectConfig),
260
- model: __props.model,
261
- prop: __props.prop,
262
- name: __props.name,
263
- size: __props.size,
264
- onChange: changeHandler
265
- }, null, 8, ["config", "model", "prop", "name", "size"])
266
- ]),
267
- default: withCtx(() => [
268
- createElementVNode("div", _hoisted_1$e, [
269
- createVNode(unref(TMagicTooltip), {
270
- class: "tool-item",
271
- effect: "dark",
272
- content: "\u67E5\u770B\u4EE3\u7801\u5757",
273
- placement: "top"
274
- }, {
275
- default: withCtx(() => [
276
- (openBlock(), createElementBlock("svg", {
277
- onClick: viewHandler,
278
- preserveAspectRatio: "xMidYMid meet",
279
- viewBox: "0 0 24 24",
280
- width: "15px",
281
- height: "15px",
282
- "data-v-65a7fb6c": ""
283
- }, _hoisted_3$3))
284
- ]),
285
- _: 1
286
- })
287
- ])
288
- ]),
289
- _: 1
290
- })
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"])
291
229
  ]);
292
230
  };
293
231
  }
294
232
  });
295
233
 
296
- const _hoisted_1$d = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
297
- const _sfc_main$q = /* @__PURE__ */ defineComponent({
298
- __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,
299
240
  props: {
300
241
  config: null,
301
242
  model: null,
@@ -357,7 +298,7 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
357
298
  style: { "padding": "0" }
358
299
  }, {
359
300
  default: withCtx(() => [
360
- _hoisted_1$d
301
+ _hoisted_1$f
361
302
  ]),
362
303
  _: 1
363
304
  }, 8, ["icon"])
@@ -405,12 +346,15 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
405
346
 
406
347
  const UISelect_vue_vue_type_style_index_0_lang = '';
407
348
 
408
- const _sfc_main$p = /* @__PURE__ */ defineComponent({
409
- __name: "CodeEditor",
349
+ const __default__$p = defineComponent({
350
+ name: "MEditorCodeEditor"
351
+ });
352
+ const _sfc_main$q = /* @__PURE__ */ defineComponent({
353
+ ...__default__$p,
410
354
  props: {
411
355
  initValues: null,
412
356
  modifiedValues: null,
413
- type: { default: "" },
357
+ type: null,
414
358
  language: { default: "javascript" },
415
359
  options: { default: () => ({
416
360
  tabSize: 2
@@ -535,9 +479,182 @@ const setConfig = (option) => {
535
479
  };
536
480
  const getConfig = (key) => $TMAGIC_EDITOR[key];
537
481
 
538
- const _hoisted_1$c = ["src"];
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
+ });
539
521
  const _sfc_main$o = /* @__PURE__ */ defineComponent({
540
- __name: "Icon",
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,
541
658
  props: {
542
659
  icon: null
543
660
  },
@@ -556,7 +673,7 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
556
673
  class: "magic-editor-icon"
557
674
  }, {
558
675
  default: withCtx(() => [
559
- createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$c)
676
+ createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$e)
560
677
  ]),
561
678
  _: 1
562
679
  })) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
@@ -575,6 +692,42 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
575
692
  }
576
693
  });
577
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
+
578
731
  const log = (...args) => {
579
732
  if (process.env.NODE_ENV === "development") {
580
733
  console.log("magic editor: ", ...args);
@@ -704,6 +857,14 @@ class BaseService extends EventEmitter {
704
857
  this.pluginOptionsList[methodName2].push(method);
705
858
  });
706
859
  }
860
+ removeAllPlugins() {
861
+ Object.keys(this.pluginOptionsList).forEach((key) => {
862
+ this.pluginOptionsList[key] = [];
863
+ });
864
+ Object.keys(this.middleware).forEach((key) => {
865
+ this.middleware[key] = [];
866
+ });
867
+ }
707
868
  async doTask() {
708
869
  this.doingTask = true;
709
870
  let task = this.taskList.shift();
@@ -723,7 +884,8 @@ class CodeBlock extends BaseService {
723
884
  editable: true,
724
885
  mode: CodeEditorMode.EDITOR,
725
886
  combineIds: [],
726
- undeletableList: []
887
+ undeletableList: [],
888
+ relations: {}
727
889
  });
728
890
  constructor() {
729
891
  super([
@@ -741,31 +903,40 @@ class CodeBlock extends BaseService {
741
903
  "deleteCodeDslByIds"
742
904
  ]);
743
905
  }
744
- async setCodeDsl(codeDsl) {
745
- this.state.codeDsl = codeDsl;
906
+ async setCodeDsl(codeDsl2) {
907
+ this.state.codeDsl = codeDsl2;
746
908
  await editorService.setCodeDsl(this.state.codeDsl);
747
909
  info("[code-block]:code-dsl-change", this.state.codeDsl);
748
910
  this.emit("code-dsl-change", this.state.codeDsl);
749
911
  }
750
912
  async getCodeDsl(forceRefresh = false) {
913
+ return this.getCodeDslSync(forceRefresh);
914
+ }
915
+ getCodeDslSync(forceRefresh = false) {
751
916
  if (!this.state.codeDsl || forceRefresh) {
752
- this.state.codeDsl = await editorService.getCodeDsl();
917
+ this.state.codeDsl = editorService.getCodeDslSync();
753
918
  }
754
919
  return this.state.codeDsl;
755
920
  }
756
- async getCodeContentById(id) {
757
- if (!id)
921
+ async getCodeContentById(id2) {
922
+ if (!id2)
758
923
  return null;
759
924
  const totalCodeDsl = await this.getCodeDsl();
760
925
  if (!totalCodeDsl)
761
926
  return null;
762
- return totalCodeDsl[id] ?? null;
927
+ return totalCodeDsl[id2] ?? null;
763
928
  }
764
929
  async setCodeDslById(id, codeConfig) {
765
930
  let codeDsl = await this.getCodeDsl();
931
+ const codeConfigProcessed = codeConfig;
932
+ if (codeConfig.content) {
933
+ codeConfigProcessed.content = eval(codeConfig.content);
934
+ }
766
935
  if (!codeDsl) {
767
936
  codeDsl = {
768
- [id]: codeConfig
937
+ [id]: {
938
+ ...codeConfigProcessed
939
+ }
769
940
  };
770
941
  } else {
771
942
  const existContent = codeDsl[id] || {};
@@ -773,15 +944,15 @@ class CodeBlock extends BaseService {
773
944
  ...codeDsl,
774
945
  [id]: {
775
946
  ...existContent,
776
- ...codeConfig
947
+ ...codeConfigProcessed
777
948
  }
778
949
  };
779
950
  }
780
951
  await this.setCodeDsl(codeDsl);
781
952
  }
782
953
  async getCodeDslByIds(ids) {
783
- const codeDsl = await this.getCodeDsl();
784
- return pick(codeDsl, ids);
954
+ const codeDsl2 = await this.getCodeDsl();
955
+ return pick(codeDsl2, ids);
785
956
  }
786
957
  async setCodeEditorShowStatus(status) {
787
958
  this.state.isShowCodeEditor = status;
@@ -789,10 +960,10 @@ class CodeBlock extends BaseService {
789
960
  getCodeEditorShowStatus() {
790
961
  return this.state.isShowCodeEditor;
791
962
  }
792
- setCodeEditorContent(status, id) {
793
- if (!id)
963
+ setCodeEditorContent(status, id2) {
964
+ if (!id2)
794
965
  return;
795
- this.setId(id);
966
+ this.setId(id2);
796
967
  this.state.isShowCodeEditor = status;
797
968
  }
798
969
  async getCurrentDsl() {
@@ -804,10 +975,10 @@ class CodeBlock extends BaseService {
804
975
  async setEditStatus(status) {
805
976
  this.state.editable = status;
806
977
  }
807
- setId(id) {
808
- if (!id)
978
+ setId(id2) {
979
+ if (!id2)
809
980
  return;
810
- this.state.id = id;
981
+ this.state.id = id2;
811
982
  }
812
983
  getId() {
813
984
  return this.state.id;
@@ -824,61 +995,17 @@ class CodeBlock extends BaseService {
824
995
  getCombineIds() {
825
996
  return this.state.combineIds;
826
997
  }
827
- async setCombineRelation(compId, diffCodeIds, opFlag, hook) {
828
- const codeDsl = cloneDeep(await this.getCodeDsl());
829
- if (!codeDsl)
830
- return;
831
- if (opFlag === CodeSelectOp.DELETE) {
832
- try {
833
- diffCodeIds.forEach((codeId) => {
834
- const compsContent = codeDsl[codeId].comps;
835
- const index = compsContent?.[compId].findIndex((item) => item === hook);
836
- if (typeof index !== "undefined" && index !== -1) {
837
- compsContent?.[compId].splice(index, 1);
838
- }
839
- });
840
- } catch (e) {
841
- error(e);
842
- throw new Error("\u89E3\u7ED1\u4EE3\u7801\u5757\u5931\u8D25");
843
- }
844
- } else if (opFlag === CodeSelectOp.ADD) {
845
- try {
846
- diffCodeIds.forEach((codeId) => {
847
- const compsContent = codeDsl[codeId].comps;
848
- const existHooks = compsContent?.[compId];
849
- if (isEmpty(existHooks)) {
850
- codeDsl[codeId].comps = {
851
- ...codeDsl[codeId].comps || {},
852
- [compId]: [hook]
853
- };
854
- } else {
855
- existHooks?.push(hook);
856
- }
857
- });
858
- } catch (e) {
859
- error(e);
860
- throw new Error("\u7ED1\u5B9A\u4EE3\u7801\u5757\u5931\u8D25");
861
- }
862
- } else if (opFlag === CodeSelectOp.CHANGE) {
863
- forIn(codeDsl, (codeBlockContent, codeId) => {
864
- if (codeId === diffCodeIds[0]) {
865
- codeBlockContent.comps = {
866
- ...codeBlockContent?.comps || {},
867
- [compId]: [hook]
868
- };
869
- } else if (isEmpty(diffCodeIds) || codeId !== diffCodeIds[0]) {
870
- const compHooks = codeBlockContent?.comps?.[compId];
871
- if (!compHooks)
872
- return true;
873
- const index = compHooks.findIndex((hookName) => hookName === hook);
874
- if (index !== -1) {
875
- compHooks.splice(index, 1);
876
- return false;
877
- }
878
- }
879
- });
880
- }
881
- this.setCodeDsl(codeDsl);
998
+ refreshCombineInfo() {
999
+ const root = editorService.get("root");
1000
+ if (!root)
1001
+ return null;
1002
+ const relations = {};
1003
+ this.recurseMNode(root, relations);
1004
+ this.state.relations = relations;
1005
+ return this.state.relations;
1006
+ }
1007
+ getCombineInfo() {
1008
+ return this.state.relations;
882
1009
  }
883
1010
  getUndeletableList() {
884
1011
  return this.state.undeletableList;
@@ -886,6 +1013,15 @@ class CodeBlock extends BaseService {
886
1013
  async setUndeleteableList(codeIds) {
887
1014
  this.state.undeletableList = codeIds;
888
1015
  }
1016
+ setCodeDraft(codeId, content) {
1017
+ globalThis.localStorage.setItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`, content);
1018
+ }
1019
+ getCodeDraft(codeId) {
1020
+ return globalThis.localStorage.getItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
1021
+ }
1022
+ removeCodeDraft(codeId) {
1023
+ globalThis.localStorage.removeItem(`${CODE_DRAFT_STORAGE_KEY}_${codeId}`);
1024
+ }
889
1025
  async deleteCodeDslByIds(codeIds) {
890
1026
  const currentDsl = await this.getCodeDsl();
891
1027
  const newDsl = omit(currentDsl, codeIds);
@@ -901,13 +1037,13 @@ class CodeBlock extends BaseService {
901
1037
  return await this.getUniqueId();
902
1038
  }
903
1039
  async deleteCompsInRelation(node) {
904
- const codeDsl = cloneDeep(await this.getCodeDsl());
905
- if (!codeDsl)
1040
+ const codeDsl2 = cloneDeep(await this.getCodeDsl());
1041
+ if (!codeDsl2)
906
1042
  return;
907
- this.recurseNodes(node, codeDsl);
908
- this.setCodeDsl(codeDsl);
1043
+ this.refreshRelationDeep(node, codeDsl2);
1044
+ this.setCodeDsl(codeDsl2);
909
1045
  }
910
- destroy() {
1046
+ resetState() {
911
1047
  this.state.isShowCodeEditor = false;
912
1048
  this.state.codeDsl = null;
913
1049
  this.state.id = "";
@@ -916,16 +1052,44 @@ class CodeBlock extends BaseService {
916
1052
  this.state.combineIds = [];
917
1053
  this.state.undeletableList = [];
918
1054
  }
919
- recurseNodes(node, codeDsl) {
1055
+ destroy() {
1056
+ this.resetState();
1057
+ this.removeAllListeners();
1058
+ this.removeAllPlugins();
1059
+ }
1060
+ refreshRelationDeep(node, codeDsl2) {
920
1061
  if (!node.id)
921
1062
  return;
922
- forIn(codeDsl, (codeBlockContent) => {
1063
+ forIn(codeDsl2, (codeBlockContent) => {
923
1064
  const compsContent = codeBlockContent.comps || {};
924
1065
  codeBlockContent.comps = omit(compsContent, node.id);
925
1066
  });
926
1067
  if (!isEmpty(node.items)) {
927
1068
  node.items.forEach((item) => {
928
- this.recurseNodes(item, codeDsl);
1069
+ this.refreshRelationDeep(item, codeDsl2);
1070
+ });
1071
+ }
1072
+ }
1073
+ recurseMNode(node, relations) {
1074
+ forIn(node, (value, key) => {
1075
+ if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
1076
+ value.hookData.forEach((relationItem) => {
1077
+ if (!relationItem.codeId)
1078
+ return;
1079
+ if (!relations[relationItem.codeId]) {
1080
+ relations[relationItem.codeId] = {};
1081
+ }
1082
+ const codeItem = relations[relationItem.codeId];
1083
+ if (isEmpty(codeItem[node.id])) {
1084
+ codeItem[node.id] = [];
1085
+ }
1086
+ codeItem[node.id].push(key);
1087
+ });
1088
+ }
1089
+ });
1090
+ if (!isEmpty(node.items)) {
1091
+ node.items.forEach((item) => {
1092
+ this.recurseMNode(item, relations);
929
1093
  });
930
1094
  }
931
1095
  }
@@ -1009,8 +1173,9 @@ class History extends BaseService {
1009
1173
  this.state.pageSteps[this.state.pageId] = undoRedo;
1010
1174
  }
1011
1175
  this.setCanUndoRedo();
1176
+ this.emit("page-change", this.state.pageSteps[this.state.pageId]);
1012
1177
  }
1013
- empty() {
1178
+ resetState() {
1014
1179
  this.state.pageId = void 0;
1015
1180
  this.state.pageSteps = {};
1016
1181
  this.state.canRedo = false;
@@ -1041,8 +1206,9 @@ class History extends BaseService {
1041
1206
  return state;
1042
1207
  }
1043
1208
  destroy() {
1044
- this.empty();
1209
+ this.resetState();
1045
1210
  this.removeAllListeners();
1211
+ this.removeAllPlugins();
1046
1212
  }
1047
1213
  getUndoRedo() {
1048
1214
  if (!this.state.pageId)
@@ -1122,6 +1288,7 @@ class WebStorage extends BaseService {
1122
1288
  }
1123
1289
  destroy() {
1124
1290
  this.removeAllListeners();
1291
+ this.removeAllPlugins();
1125
1292
  }
1126
1293
  getValueAndProtocol(value) {
1127
1294
  let protocol2 = "";
@@ -1294,6 +1461,10 @@ const fixNodePosition = (config, parent, stage) => {
1294
1461
  left: fixNodeLeft(config, parent, stage?.renderer.contentWindow?.document)
1295
1462
  };
1296
1463
  };
1464
+ const serializeConfig = (config) => serialize(config, {
1465
+ space: 2,
1466
+ unsafe: true
1467
+ }).replace(/"(\w+)":\s/g, "$1: ");
1297
1468
 
1298
1469
  class Props extends BaseService {
1299
1470
  state = reactive({
@@ -1335,7 +1506,7 @@ class Props extends BaseService {
1335
1506
  this.setPropsValue(toLine(type), values[type]);
1336
1507
  });
1337
1508
  }
1338
- setPropsValue(type, value) {
1509
+ async setPropsValue(type, value) {
1339
1510
  this.state.propsValueMap[type] = value;
1340
1511
  }
1341
1512
  async getPropsValue(type, { inputEvent, ...defaultValue } = {}) {
@@ -1389,10 +1560,14 @@ class Props extends BaseService {
1389
1560
  name: type
1390
1561
  };
1391
1562
  }
1392
- destroy() {
1563
+ resetState() {
1393
1564
  this.state.propsConfigMap = {};
1394
1565
  this.state.propsValueMap = {};
1566
+ }
1567
+ destroy() {
1568
+ this.resetState();
1395
1569
  this.removeAllListeners();
1570
+ this.removeAllPlugins();
1396
1571
  }
1397
1572
  guid(digit = 8) {
1398
1573
  return "x".repeat(digit).replace(/[xy]/g, (c) => {
@@ -1467,6 +1642,13 @@ const getAddParent = (node) => {
1467
1642
  }
1468
1643
  return parentNode;
1469
1644
  };
1645
+ const getDefaultConfig = async (addNode, parentNode) => {
1646
+ const { type, inputEvent, ...config } = addNode;
1647
+ const layout = await editorService.getLayout(toRaw(parentNode), addNode);
1648
+ const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
1649
+ newNode.style = getInitPositionStyle(newNode.style, layout);
1650
+ return newNode;
1651
+ };
1470
1652
 
1471
1653
  class Editor$1 extends BaseService {
1472
1654
  state = reactive({
@@ -1496,7 +1678,7 @@ class Editor$1 extends BaseService {
1496
1678
  "copy",
1497
1679
  "paste",
1498
1680
  "doPaste",
1499
- "duAlignCenter",
1681
+ "doAlignCenter",
1500
1682
  "alignCenter",
1501
1683
  "moveLayer",
1502
1684
  "moveToContainer",
@@ -1511,13 +1693,14 @@ class Editor$1 extends BaseService {
1511
1693
  );
1512
1694
  }
1513
1695
  set(name, value) {
1696
+ const preValue = this.state[name];
1514
1697
  this.state[name] = value;
1515
1698
  if (name === "nodes") {
1516
1699
  this.set("node", value[0]);
1517
1700
  }
1518
1701
  if (name === "root") {
1519
1702
  this.state.pageLength = value?.items?.length || 0;
1520
- this.emit("root-change", value);
1703
+ this.emit("root-change", value, preValue);
1521
1704
  }
1522
1705
  }
1523
1706
  get(name) {
@@ -1577,7 +1760,7 @@ class Editor$1 extends BaseService {
1577
1760
  if (page) {
1578
1761
  historyService.changePage(toRaw(page));
1579
1762
  } else {
1580
- historyService.empty();
1763
+ historyService.resetState();
1581
1764
  }
1582
1765
  if (node?.id) {
1583
1766
  this.get("stage")?.renderer.runtime?.getApp?.()?.emit(
@@ -1675,6 +1858,9 @@ class Editor$1 extends BaseService {
1675
1858
  }
1676
1859
  const newNodes = await Promise.all(
1677
1860
  addNodes.map((node) => {
1861
+ if (isPage(node)) {
1862
+ return this.doAdd(node, this.get("root"));
1863
+ }
1678
1864
  const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(node);
1679
1865
  if (!parentNode)
1680
1866
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
@@ -1693,7 +1879,9 @@ class Editor$1 extends BaseService {
1693
1879
  stage?.select(newNodes[0].id);
1694
1880
  }
1695
1881
  }
1696
- this.pushHistoryState();
1882
+ if (!isPage(newNodes[0])) {
1883
+ this.pushHistoryState();
1884
+ }
1697
1885
  this.emit("add", newNodes);
1698
1886
  return Array.isArray(addNode) ? newNodes : newNodes[0];
1699
1887
  }
@@ -1735,7 +1923,9 @@ class Editor$1 extends BaseService {
1735
1923
  async remove(nodeOrNodeList) {
1736
1924
  const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
1737
1925
  await Promise.all(nodes.map((node) => this.doRemove(node)));
1738
- this.pushHistoryState();
1926
+ if (!isPage(nodes[0])) {
1927
+ this.pushHistoryState();
1928
+ }
1739
1929
  this.emit("remove", nodes);
1740
1930
  }
1741
1931
  async doUpdate(config) {
@@ -1747,6 +1937,9 @@ class Editor$1 extends BaseService {
1747
1937
  const node = cloneDeep(toRaw(info.node));
1748
1938
  let newConfig = await this.toggleFixedPosition(toRaw(config), node, this.get("root"));
1749
1939
  newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue) => {
1940
+ if (isObject(srcValue) && Array.isArray(objValue)) {
1941
+ return srcValue;
1942
+ }
1750
1943
  if (Array.isArray(srcValue)) {
1751
1944
  return srcValue;
1752
1945
  }
@@ -1790,6 +1983,7 @@ class Editor$1 extends BaseService {
1790
1983
  const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
1791
1984
  this.pushHistoryState();
1792
1985
  this.emit("update", newNodes);
1986
+ codeBlockService.refreshCombineInfo();
1793
1987
  return Array.isArray(config) ? newNodes : newNodes[0];
1794
1988
  }
1795
1989
  async sort(id1, id2) {
@@ -1819,8 +2013,16 @@ class Editor$1 extends BaseService {
1819
2013
  const config = await storageService.getItem(COPY_STORAGE_KEY);
1820
2014
  if (!Array.isArray(config))
1821
2015
  return;
2016
+ const node = this.get("node");
2017
+ let parent = void 0;
2018
+ if (config.length === 1 && config[0].id === node.id) {
2019
+ parent = this.get("parent");
2020
+ if (parent.type === NodeType.ROOT) {
2021
+ parent = this.get("page");
2022
+ }
2023
+ }
1822
2024
  const pasteConfigs = await this.doPaste(config, position);
1823
- return this.add(pasteConfigs);
2025
+ return this.add(pasteConfigs, parent);
1824
2026
  }
1825
2027
  async doPaste(config, position = {}) {
1826
2028
  const pasteConfigs = await beforePaste(position, cloneDeep(config));
@@ -1855,7 +2057,11 @@ class Editor$1 extends BaseService {
1855
2057
  const stage = this.get("stage");
1856
2058
  const newNodes = await Promise.all(nodes.map((node) => this.doAlignCenter(node)));
1857
2059
  const newNode = await this.update(newNodes);
1858
- await stage?.multiSelect(newNodes.map((node) => node.id));
2060
+ if (newNodes.length > 1) {
2061
+ await stage?.multiSelect(newNodes.map((node) => node.id));
2062
+ } else {
2063
+ await stage?.select(newNodes[0].id);
2064
+ }
1859
2065
  return newNode;
1860
2066
  }
1861
2067
  async moveLayer(offset) {
@@ -1941,8 +2147,7 @@ class Editor$1 extends BaseService {
1941
2147
  }
1942
2148
  });
1943
2149
  }
1944
- destroy() {
1945
- this.removeAllListeners();
2150
+ resetState() {
1946
2151
  this.set("root", null);
1947
2152
  this.set("node", null);
1948
2153
  this.set("nodes", []);
@@ -1953,6 +2158,11 @@ class Editor$1 extends BaseService {
1953
2158
  this.set("modifiedNodeIds", /* @__PURE__ */ new Map());
1954
2159
  this.set("pageLength", /* @__PURE__ */ new Map());
1955
2160
  }
2161
+ destroy() {
2162
+ this.removeAllListeners();
2163
+ this.resetState();
2164
+ this.removeAllPlugins();
2165
+ }
1956
2166
  resetModifiedNodeId() {
1957
2167
  this.get("modifiedNodeIds").clear();
1958
2168
  }
@@ -1962,6 +2172,12 @@ class Editor$1 extends BaseService {
1962
2172
  return null;
1963
2173
  return root.codeBlocks || null;
1964
2174
  }
2175
+ getCodeDslSync() {
2176
+ const root = this.get("root");
2177
+ if (!root)
2178
+ return null;
2179
+ return root.codeBlocks || null;
2180
+ }
1965
2181
  async setCodeDsl(codeDsl) {
1966
2182
  if (!this.state.root)
1967
2183
  return;
@@ -2073,10 +2289,14 @@ class Events extends BaseService {
2073
2289
  getMethod(type) {
2074
2290
  return cloneDeep(methodMap[type] || DEFAULT_METHODS);
2075
2291
  }
2076
- destroy() {
2292
+ resetState() {
2077
2293
  eventMap = reactive({});
2078
2294
  methodMap = reactive({});
2295
+ }
2296
+ destroy() {
2297
+ this.resetState();
2079
2298
  this.removeAllListeners();
2299
+ this.removeAllPlugins();
2080
2300
  }
2081
2301
  }
2082
2302
  const eventsService = new Events();
@@ -2276,14 +2496,14 @@ const fillConfig = (config = []) => [
2276
2496
  {
2277
2497
  name: "created",
2278
2498
  text: "created",
2279
- type: "code-select",
2280
- labelWidth: "100px"
2499
+ labelWidth: "100px",
2500
+ type: "code-select"
2281
2501
  },
2282
2502
  {
2283
2503
  name: "mounted",
2284
2504
  text: "mounted",
2285
- type: "code-select",
2286
- labelWidth: "100px"
2505
+ labelWidth: "100px",
2506
+ type: "code-select"
2287
2507
  }
2288
2508
  ]
2289
2509
  }
@@ -2351,8 +2571,19 @@ class Ui extends BaseService {
2351
2571
  }
2352
2572
  return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
2353
2573
  }
2574
+ resetState() {
2575
+ this.set("showSrc", false);
2576
+ this.set("uiSelectMode", false);
2577
+ this.set("zoom", 1);
2578
+ this.set("stageContainerRect", {
2579
+ width: 0,
2580
+ height: 0
2581
+ });
2582
+ }
2354
2583
  destroy() {
2584
+ this.resetState();
2355
2585
  this.removeAllListeners();
2586
+ this.removeAllPlugins();
2356
2587
  }
2357
2588
  async setStageRect(value) {
2358
2589
  state.stageRect = {
@@ -2379,6 +2610,7 @@ const useStage = (stageOptions) => {
2379
2610
  containerHighlightClassName: stageOptions.containerHighlightClassName,
2380
2611
  containerHighlightDuration: stageOptions.containerHighlightDuration,
2381
2612
  containerHighlightType: stageOptions.containerHighlightType,
2613
+ disabledDragStart: stageOptions.disabledDragStart,
2382
2614
  canSelect: (el, event, stop) => {
2383
2615
  const elCanSelect = stageOptions.canSelect(el);
2384
2616
  if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
@@ -2390,225 +2622,97 @@ const useStage = (stageOptions) => {
2390
2622
  moveableOptions: stageOptions.moveableOptions,
2391
2623
  updateDragEl: stageOptions.updateDragEl
2392
2624
  });
2393
- stage.mask.setGuides([
2394
- getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
2395
- getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
2396
- ]);
2397
- stage.on("select", (el) => {
2398
- if (`${editorService.get("node")?.id}` === el.id)
2399
- return;
2400
- editorService.select(el.id);
2401
- });
2402
- stage.on("highlight", (el) => {
2403
- editorService.highlight(el.id);
2404
- });
2405
- stage.on("multiSelect", (els) => {
2406
- editorService.multiSelect(els.map((el) => el.id));
2407
- });
2408
- stage.on("update", (ev) => {
2409
- if (ev.parentEl) {
2410
- for (const data of ev.data) {
2411
- editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
2412
- }
2413
- return;
2414
- }
2415
- editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
2416
- });
2417
- stage.on("sort", (ev) => {
2418
- editorService.sort(ev.src, ev.dist);
2419
- });
2420
- stage.on("select-parent", () => {
2421
- const parent = editorService.get("parent");
2422
- editorService.select(parent);
2423
- editorService.get("stage").select(parent.id);
2424
- });
2425
- stage.on("changeGuides", (e) => {
2426
- uiService.set("showGuides", true);
2427
- if (!root.value || !page.value)
2428
- return;
2429
- const storageKey = getGuideLineKey(
2430
- e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY
2431
- );
2432
- if (e.guides.length) {
2433
- globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
2434
- } else {
2435
- globalThis.localStorage.removeItem(storageKey);
2436
- }
2437
- });
2438
- return stage;
2439
- };
2440
-
2441
- const _hoisted_1$b = { class: "m-editor-empty-panel" };
2442
- const _hoisted_2$5 = { class: "m-editor-empty-content" };
2443
- const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2444
- const _sfc_main$n = /* @__PURE__ */ defineComponent({
2445
- __name: "AddPageBox",
2446
- setup(__props) {
2447
- const services = inject("services");
2448
- const clickHandler = () => {
2449
- const { editorService } = services || {};
2450
- if (!editorService)
2451
- return;
2452
- editorService.add({
2453
- type: NodeType.PAGE,
2454
- name: generatePageNameByApp(toRaw(editorService.get("root")))
2455
- });
2456
- };
2457
- return (_ctx, _cache) => {
2458
- return openBlock(), createElementBlock("div", _hoisted_1$b, [
2459
- createElementVNode("div", _hoisted_2$5, [
2460
- createElementVNode("div", {
2461
- class: "m-editor-empty-button",
2462
- onClick: clickHandler
2463
- }, [
2464
- createElementVNode("div", null, [
2465
- createVNode(_sfc_main$o, { icon: unref(Plus) }, null, 8, ["icon"])
2466
- ]),
2467
- _hoisted_3$2
2468
- ])
2469
- ])
2470
- ]);
2471
- };
2472
- }
2473
- });
2474
-
2475
- const _sfc_main$m = /* @__PURE__ */ defineComponent({
2476
- __name: "Resizer",
2477
- emits: ["change"],
2478
- setup(__props, { emit }) {
2479
- const target = ref();
2480
- let getso;
2481
- onMounted(() => {
2482
- if (!target.value)
2483
- return;
2484
- getso = new Gesto(target.value, {
2485
- container: window,
2486
- pinchOutside: true
2487
- }).on("drag", (e) => {
2488
- if (!target.value)
2489
- return;
2490
- emit("change", e.deltaX);
2491
- });
2492
- });
2493
- onUnmounted(() => {
2494
- getso?.unset();
2495
- });
2496
- return (_ctx, _cache) => {
2497
- return openBlock(), createElementBlock("span", {
2498
- ref_key: "target",
2499
- ref: target,
2500
- class: "m-editor-resizer"
2501
- }, [
2502
- renderSlot(_ctx.$slots, "default")
2503
- ], 512);
2504
- };
2505
- }
2506
- });
2507
-
2508
- const _sfc_main$l = /* @__PURE__ */ defineComponent({
2509
- __name: "Layout",
2510
- props: {
2511
- left: null,
2512
- right: null,
2513
- minLeft: { default: 1 },
2514
- minRight: { default: 1 },
2515
- leftClass: null,
2516
- rightClass: null,
2517
- centerClass: null
2518
- },
2519
- emits: ["update:left", "change", "update:right"],
2520
- setup(__props, { emit }) {
2521
- const props = __props;
2522
- const el = ref();
2523
- let clientWidth = 0;
2524
- const resizerObserver = new ResizeObserver((entries) => {
2525
- for (const { contentRect } of entries) {
2526
- clientWidth = contentRect.width;
2527
- center.value = clientWidth - (props.left || 0) - (props.right || 0);
2528
- emit("change", {
2529
- left: props.left,
2530
- center: center.value,
2531
- right: props.right
2532
- });
2533
- }
2534
- });
2535
- onMounted(() => {
2536
- if (el.value) {
2537
- resizerObserver.observe(el.value);
2538
- }
2539
- });
2540
- onUnmounted(() => {
2541
- resizerObserver.disconnect();
2542
- });
2543
- const center = ref(0);
2544
- const changeLeft = (deltaX) => {
2545
- if (typeof props.left === "undefined")
2546
- return;
2547
- let left = Math.max(props.left + deltaX, props.minLeft) || 0;
2548
- emit("update:left", left);
2549
- if (clientWidth - left - (props.right || 0) <= 0) {
2550
- left = props.left;
2625
+ stage.mask.setGuides([
2626
+ getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
2627
+ getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
2628
+ ]);
2629
+ stage.on("select", (el) => {
2630
+ if (`${editorService.get("node")?.id}` === el.id && editorService.get("nodes").length === 1)
2631
+ return;
2632
+ editorService.select(el.id);
2633
+ });
2634
+ stage.on("highlight", (el) => {
2635
+ editorService.highlight(el.id);
2636
+ });
2637
+ stage.on("multi-select", (els) => {
2638
+ editorService.multiSelect(els.map((el) => el.id));
2639
+ });
2640
+ stage.on("update", (ev) => {
2641
+ if (ev.parentEl) {
2642
+ for (const data of ev.data) {
2643
+ editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
2551
2644
  }
2552
- center.value = clientWidth - left - (props.right || 0);
2553
- emit("change", {
2554
- left,
2555
- center: center.value,
2556
- right: props.right
2557
- });
2558
- };
2559
- const changeRight = (deltaX) => {
2560
- if (typeof props.right === "undefined")
2645
+ return;
2646
+ }
2647
+ editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
2648
+ });
2649
+ stage.on("sort", (ev) => {
2650
+ editorService.sort(ev.src, ev.dist);
2651
+ });
2652
+ stage.on("select-parent", () => {
2653
+ const parent = editorService.get("parent");
2654
+ editorService.select(parent);
2655
+ editorService.get("stage").select(parent.id);
2656
+ });
2657
+ stage.on("change-guides", (e) => {
2658
+ uiService.set("showGuides", true);
2659
+ if (!root.value || !page.value)
2660
+ return;
2661
+ const storageKey = getGuideLineKey(
2662
+ e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY
2663
+ );
2664
+ if (e.guides.length) {
2665
+ globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
2666
+ } else {
2667
+ globalThis.localStorage.removeItem(storageKey);
2668
+ }
2669
+ });
2670
+ return stage;
2671
+ };
2672
+
2673
+ const _hoisted_1$d = { class: "m-editor-empty-panel" };
2674
+ const _hoisted_2$7 = { class: "m-editor-empty-content" };
2675
+ const _hoisted_3$4 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2676
+ const __default__$l = defineComponent({
2677
+ name: "MEditorAddPageBox"
2678
+ });
2679
+ const _sfc_main$m = /* @__PURE__ */ defineComponent({
2680
+ ...__default__$l,
2681
+ setup(__props) {
2682
+ const services = inject("services");
2683
+ const clickHandler = () => {
2684
+ const { editorService } = services || {};
2685
+ if (!editorService)
2561
2686
  return;
2562
- let right = Math.max(props.right - deltaX, props.minRight) || 0;
2563
- emit("update:right", right);
2564
- if (clientWidth - (props.left || 0) - right <= 0) {
2565
- right = props.right;
2566
- }
2567
- center.value = clientWidth - (props.left || 0) - right;
2568
- emit("change", {
2569
- left: props.left,
2570
- center: center.value,
2571
- right
2687
+ editorService.add({
2688
+ type: NodeType.PAGE,
2689
+ name: generatePageNameByApp(toRaw(editorService.get("root")))
2572
2690
  });
2573
2691
  };
2574
2692
  return (_ctx, _cache) => {
2575
- return openBlock(), createElementBlock("div", {
2576
- ref_key: "el",
2577
- ref: el,
2578
- class: "m-editor-layout"
2579
- }, [
2580
- typeof props.left !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2581
- createElementVNode("div", {
2582
- class: normalizeClass(["m-editor-layout-left", __props.leftClass]),
2583
- style: normalizeStyle(`width: ${__props.left}px`)
2584
- }, [
2585
- renderSlot(_ctx.$slots, "left")
2586
- ], 6),
2587
- createVNode(_sfc_main$m, { onChange: changeLeft })
2588
- ], 64)) : createCommentVNode("", true),
2589
- createElementVNode("div", {
2590
- class: normalizeClass(["m-editor-layout-center", __props.centerClass]),
2591
- style: normalizeStyle(`width: ${center.value}px`)
2592
- }, [
2593
- renderSlot(_ctx.$slots, "center")
2594
- ], 6),
2595
- typeof props.right !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
2596
- createVNode(_sfc_main$m, { onChange: changeRight }),
2693
+ return openBlock(), createElementBlock("div", _hoisted_1$d, [
2694
+ createElementVNode("div", _hoisted_2$7, [
2597
2695
  createElementVNode("div", {
2598
- class: normalizeClass(["m-editor-layout-right", __props.rightClass]),
2599
- style: normalizeStyle(`width: ${__props.right}px`)
2696
+ class: "m-editor-empty-button",
2697
+ onClick: clickHandler
2600
2698
  }, [
2601
- renderSlot(_ctx.$slots, "right")
2602
- ], 6)
2603
- ], 64)) : createCommentVNode("", true)
2604
- ], 512);
2699
+ createElementVNode("div", null, [
2700
+ createVNode(_sfc_main$n, { icon: unref(Plus) }, null, 8, ["icon"])
2701
+ ]),
2702
+ _hoisted_3$4
2703
+ ])
2704
+ ])
2705
+ ]);
2605
2706
  };
2606
2707
  }
2607
2708
  });
2608
2709
 
2609
- const _hoisted_1$a = { class: "m-editor" };
2610
- const _sfc_main$k = /* @__PURE__ */ defineComponent({
2611
- __name: "Framework",
2710
+ const _hoisted_1$c = { class: "m-editor" };
2711
+ const __default__$k = defineComponent({
2712
+ name: "MEditorFramework"
2713
+ });
2714
+ const _sfc_main$l = /* @__PURE__ */ defineComponent({
2715
+ ...__default__$k,
2612
2716
  props: {
2613
2717
  codeOptions: { default: () => ({}) }
2614
2718
  },
@@ -2674,7 +2778,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2674
2778
  };
2675
2779
  return (_ctx, _cache) => {
2676
2780
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
2677
- return openBlock(), createElementBlock("div", _hoisted_1$a, [
2781
+ return openBlock(), createElementBlock("div", _hoisted_1$c, [
2678
2782
  renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2679
2783
  unref(showSrc) ? (openBlock(), createBlock(_component_magic_code_editor, {
2680
2784
  key: 0,
@@ -2682,7 +2786,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2682
2786
  "init-values": unref(root),
2683
2787
  options: __props.codeOptions,
2684
2788
  onSave: saveCode
2685
- }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$l, {
2789
+ }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$o, {
2686
2790
  key: 1,
2687
2791
  class: "m-editor-content",
2688
2792
  "left-class": "m-editor-framework-left",
@@ -2701,7 +2805,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2701
2805
  ]),
2702
2806
  center: withCtx(() => [
2703
2807
  unref(pageLength) > 0 ? renderSlot(_ctx.$slots, "workspace", { key: 0 }) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
2704
- createVNode(_sfc_main$n)
2808
+ createVNode(_sfc_main$m)
2705
2809
  ])
2706
2810
  ]),
2707
2811
  _: 2
@@ -2723,13 +2827,16 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2723
2827
  }
2724
2828
  });
2725
2829
 
2726
- const _hoisted_1$9 = {
2830
+ const _hoisted_1$b = {
2727
2831
  key: 1,
2728
2832
  class: "menu-item-text"
2729
2833
  };
2730
- const _hoisted_2$4 = { class: "el-dropdown-link menubar-menu-button" };
2731
- const _sfc_main$j = /* @__PURE__ */ defineComponent({
2732
- __name: "ToolButton",
2834
+ const _hoisted_2$6 = { class: "el-dropdown-link menubar-menu-button" };
2835
+ const __default__$j = defineComponent({
2836
+ name: "MEditorToolButton"
2837
+ });
2838
+ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2839
+ ...__default__$j,
2733
2840
  props: {
2734
2841
  data: { default: () => ({
2735
2842
  type: "text",
@@ -2804,7 +2911,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2804
2911
  __props.data.type === "divider" ? (openBlock(), createBlock(unref(TMagicDivider), {
2805
2912
  key: 0,
2806
2913
  direction: __props.data.direction || "vertical"
2807
- }, null, 8, ["direction"])) : __props.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$9, toDisplayString(__props.data.text), 1)) : __props.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2914
+ }, 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 }, [
2808
2915
  __props.data.tooltip ? (openBlock(), createBlock(unref(TMagicTooltip), {
2809
2916
  key: 0,
2810
2917
  effect: "dark",
@@ -2818,7 +2925,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2818
2925
  disabled: unref(disabled)
2819
2926
  }, {
2820
2927
  default: withCtx(() => [
2821
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$o, {
2928
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$n, {
2822
2929
  key: 0,
2823
2930
  icon: __props.data.icon
2824
2931
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2835,7 +2942,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2835
2942
  disabled: unref(disabled)
2836
2943
  }, {
2837
2944
  default: withCtx(() => [
2838
- __props.data.icon ? (openBlock(), createBlock(_sfc_main$o, {
2945
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$n, {
2839
2946
  key: 0,
2840
2947
  icon: __props.data.icon
2841
2948
  }, null, 8, ["icon"])) : createCommentVNode("", true),
@@ -2868,7 +2975,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2868
2975
  })) : createCommentVNode("", true)
2869
2976
  ]),
2870
2977
  default: withCtx(() => [
2871
- createElementVNode("span", _hoisted_2$4, [
2978
+ createElementVNode("span", _hoisted_2$6, [
2872
2979
  createTextVNode(toDisplayString(__props.data.text), 1),
2873
2980
  createVNode(unref(TMagicIcon), { class: "el-icon--right" }, {
2874
2981
  default: withCtx(() => [
@@ -2885,8 +2992,11 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2885
2992
  }
2886
2993
  });
2887
2994
 
2888
- const _sfc_main$i = /* @__PURE__ */ defineComponent({
2889
- __name: "NavMenu",
2995
+ const __default__$i = defineComponent({
2996
+ name: "MEditorNavMenu"
2997
+ });
2998
+ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2999
+ ...__default__$i,
2890
3000
  props: {
2891
3001
  data: { default: () => ({}) },
2892
3002
  height: { default: 35 }
@@ -3041,7 +3151,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
3041
3151
  style: normalizeStyle(`width: ${unref(columnWidth)?.[key]}px`)
3042
3152
  }, [
3043
3153
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(buttons)[key], (item, index) => {
3044
- return openBlock(), createBlock(_sfc_main$j, {
3154
+ return openBlock(), createBlock(_sfc_main$k, {
3045
3155
  data: item,
3046
3156
  key: index
3047
3157
  }, null, 8, ["data"]);
@@ -3053,9 +3163,12 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
3053
3163
  }
3054
3164
  });
3055
3165
 
3056
- const _hoisted_1$8 = { class: "m-editor-props-panel" };
3057
- const _sfc_main$h = /* @__PURE__ */ defineComponent({
3058
- __name: "PropsPanel",
3166
+ const _hoisted_1$a = { class: "m-editor-props-panel" };
3167
+ const __default__$h = defineComponent({
3168
+ name: "MEditorPropsPanel"
3169
+ });
3170
+ const _sfc_main$i = /* @__PURE__ */ defineComponent({
3171
+ ...__default__$h,
3059
3172
  emits: ["mounted"],
3060
3173
  setup(__props, { expose, emit }) {
3061
3174
  const internalInstance = getCurrentInstance();
@@ -3064,7 +3177,9 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3064
3177
  const curFormConfig = ref([]);
3065
3178
  const services = inject("services");
3066
3179
  const node = computed(() => services?.editorService.get("node"));
3067
- const propsPanelSize = computed(() => services?.uiService.get("propsPanelSize") || "small");
3180
+ const propsPanelSize = computed(
3181
+ () => services?.uiService.get("propsPanelSize") || "small"
3182
+ );
3068
3183
  const stage = computed(() => services?.editorService.get("stage"));
3069
3184
  const init = async () => {
3070
3185
  if (!node.value) {
@@ -3080,6 +3195,9 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3080
3195
  onMounted(() => {
3081
3196
  emit("mounted", internalInstance);
3082
3197
  });
3198
+ onUnmounted(() => {
3199
+ services?.propsService.off("props-configs-change", init);
3200
+ });
3083
3201
  watchEffect(() => {
3084
3202
  if (configForm.value && stage.value) {
3085
3203
  configForm.value.formState.stage = stage.value;
@@ -3097,10 +3215,9 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3097
3215
  };
3098
3216
  expose({ submit });
3099
3217
  return (_ctx, _cache) => {
3100
- const _component_m_form = resolveComponent("m-form");
3101
- return openBlock(), createElementBlock("div", _hoisted_1$8, [
3218
+ return openBlock(), createElementBlock("div", _hoisted_1$a, [
3102
3219
  renderSlot(_ctx.$slots, "props-panel-header"),
3103
- createVNode(_component_m_form, {
3220
+ createVNode(unref(MForm), {
3104
3221
  ref_key: "configForm",
3105
3222
  ref: configForm,
3106
3223
  class: normalizeClass(`m-editor-props-panel ${unref(propsPanelSize)}`),
@@ -3115,43 +3232,328 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3115
3232
  }
3116
3233
  });
3117
3234
 
3118
- const _hoisted_1$7 = ["id"];
3119
- const _hoisted_2$3 = { class: "list-item" };
3120
- const _hoisted_3$1 = { class: "code-name" };
3121
- const _hoisted_4$1 = { class: "code-name-wrapper" };
3122
- const _hoisted_5$1 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u4EE3\u7801\u5757\u540D\u79F0", -1);
3123
- const _hoisted_6$1 = { class: "m-editor-wrapper" };
3124
- const _hoisted_7$1 = {
3125
- key: 1,
3235
+ const _hoisted_1$9 = {
3236
+ key: 0,
3126
3237
  class: "m-editor-content-bottom"
3127
3238
  };
3128
- const _hoisted_8$1 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
3129
- const _hoisted_9$1 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3130
- const _hoisted_10 = {
3131
- key: 2,
3239
+ const _hoisted_2$5 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
3240
+ const _hoisted_3$3 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3241
+ const _hoisted_4$2 = {
3242
+ key: 1,
3132
3243
  class: "m-editor-content-bottom"
3133
3244
  };
3134
- const _hoisted_11 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3245
+ const _hoisted_5$1 = /* @__PURE__ */ createTextVNode("\u5173\u95ED");
3246
+ const __default__$g = defineComponent({
3247
+ name: "MEditorCodeDraftEditor"
3248
+ });
3249
+ const _sfc_main$h = /* @__PURE__ */ defineComponent({
3250
+ ...__default__$g,
3251
+ props: {
3252
+ id: null,
3253
+ content: null,
3254
+ editable: { type: Boolean, default: true },
3255
+ autoSaveDraft: { type: Boolean, default: true },
3256
+ codeOptions: null,
3257
+ language: null
3258
+ },
3259
+ emits: ["save", "close", "saveAndClose"],
3260
+ setup(__props, { emit }) {
3261
+ const props = __props;
3262
+ const services = inject("services");
3263
+ const codeContent = ref("");
3264
+ const editorContent = ref("");
3265
+ const codeEditor = ref();
3266
+ const originCodeContent = ref("");
3267
+ const isFullScreen = ref(false);
3268
+ const codeOptions = computed(() => ({
3269
+ ...props.codeOptions,
3270
+ readOnly: !props.editable
3271
+ }));
3272
+ watchEffect(() => {
3273
+ codeContent.value = props.content;
3274
+ if (!originCodeContent.value) {
3275
+ originCodeContent.value = codeContent.value;
3276
+ }
3277
+ const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
3278
+ if (codeDraft) {
3279
+ codeContent.value = codeDraft;
3280
+ }
3281
+ });
3282
+ const saveCodeDraft = async (codeValue) => {
3283
+ if (!props.autoSaveDraft)
3284
+ return;
3285
+ if (originCodeContent.value === codeValue) {
3286
+ services?.codeBlockService.removeCodeDraft(props.id);
3287
+ return;
3288
+ }
3289
+ services?.codeBlockService.setCodeDraft(props.id, codeValue);
3290
+ tMagicMessage.success(`\u4EE3\u7801\u8349\u7A3F\u4FDD\u5B58\u6210\u529F ${datetimeFormatter(new Date())}`);
3291
+ };
3292
+ const saveCode = () => {
3293
+ if (!codeEditor.value || !props.editable)
3294
+ return;
3295
+ editorContent.value = codeEditor.value.getEditor()?.getValue();
3296
+ emit("save", editorContent.value);
3297
+ };
3298
+ const saveAndClose = () => {
3299
+ if (!codeEditor.value || !props.editable)
3300
+ return;
3301
+ editorContent.value = codeEditor.value.getEditor()?.getValue();
3302
+ emit("saveAndClose", editorContent.value);
3303
+ };
3304
+ const close = async () => {
3305
+ const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
3306
+ if (codeDraft) {
3307
+ tMagicMessageBox.confirm("\u60A8\u6709\u4EE3\u7801\u4FEE\u6539\u672A\u4FDD\u5B58\uFF0C\u662F\u5426\u4FDD\u5B58\u540E\u518D\u5173\u95ED\uFF1F", "\u63D0\u793A", {
3308
+ confirmButtonText: "\u786E\u8BA4",
3309
+ cancelButtonText: "\u53D6\u6D88",
3310
+ type: "warning"
3311
+ }).then(async () => {
3312
+ saveAndClose();
3313
+ }).catch(() => {
3314
+ services?.codeBlockService.removeCodeDraft(props.id);
3315
+ emit("close");
3316
+ });
3317
+ } else {
3318
+ emit("close");
3319
+ }
3320
+ };
3321
+ const toggleFullScreen = () => {
3322
+ isFullScreen.value = !isFullScreen.value;
3323
+ if (codeEditor.value) {
3324
+ codeEditor.value.focus();
3325
+ }
3326
+ };
3327
+ return (_ctx, _cache) => {
3328
+ return openBlock(), createElementBlock("div", {
3329
+ class: normalizeClass(["m-editor-wrapper", isFullScreen.value ? "fullScreen" : "normal"])
3330
+ }, [
3331
+ createVNode(_sfc_main$q, {
3332
+ ref_key: "codeEditor",
3333
+ ref: codeEditor,
3334
+ class: "m-editor-container",
3335
+ "init-values": `${codeContent.value}`,
3336
+ onSave: saveCodeDraft,
3337
+ language: __props.language,
3338
+ options: unref(codeOptions)
3339
+ }, null, 8, ["init-values", "language", "options"]),
3340
+ __props.editable ? (openBlock(), createElementBlock("div", _hoisted_1$9, [
3341
+ createVNode(unref(TMagicButton), {
3342
+ type: "primary",
3343
+ class: "button",
3344
+ onClick: toggleFullScreen
3345
+ }, {
3346
+ default: withCtx(() => [
3347
+ createTextVNode(toDisplayString(isFullScreen.value ? "\u9000\u51FA\u5168\u5C4F" : "\u5168\u5C4F"), 1)
3348
+ ]),
3349
+ _: 1
3350
+ }),
3351
+ createVNode(unref(TMagicButton), {
3352
+ type: "primary",
3353
+ class: "button",
3354
+ onClick: saveCode
3355
+ }, {
3356
+ default: withCtx(() => [
3357
+ _hoisted_2$5
3358
+ ]),
3359
+ _: 1
3360
+ }),
3361
+ createVNode(unref(TMagicButton), {
3362
+ type: "primary",
3363
+ class: "button",
3364
+ onClick: close
3365
+ }, {
3366
+ default: withCtx(() => [
3367
+ _hoisted_3$3
3368
+ ]),
3369
+ _: 1
3370
+ })
3371
+ ])) : (openBlock(), createElementBlock("div", _hoisted_4$2, [
3372
+ createVNode(unref(TMagicButton), {
3373
+ type: "primary",
3374
+ class: "button",
3375
+ onClick: toggleFullScreen
3376
+ }, {
3377
+ default: withCtx(() => [
3378
+ createTextVNode(toDisplayString(isFullScreen.value ? "\u9000\u51FA\u5168\u5C4F" : "\u5168\u5C4F"), 1)
3379
+ ]),
3380
+ _: 1
3381
+ }),
3382
+ createVNode(unref(TMagicButton), {
3383
+ type: "primary",
3384
+ class: "button",
3385
+ onClick: close
3386
+ }, {
3387
+ default: withCtx(() => [
3388
+ _hoisted_5$1
3389
+ ]),
3390
+ _: 1
3391
+ })
3392
+ ]))
3393
+ ], 2);
3394
+ };
3395
+ }
3396
+ });
3397
+
3398
+ const _hoisted_1$8 = { class: "code-name-wrapper" };
3399
+ const _hoisted_2$4 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u4EE3\u7801\u5757\u540D\u79F0", -1);
3400
+ const _hoisted_3$2 = { class: "code-name-wrapper" };
3401
+ const _hoisted_4$1 = /* @__PURE__ */ createElementVNode("div", { class: "code-name-label" }, "\u53C2\u6570\u5B9A\u4E49", -1);
3402
+ const __default__$f = defineComponent({
3403
+ name: "MEditorFunctionEditor"
3404
+ });
3135
3405
  const _sfc_main$g = /* @__PURE__ */ defineComponent({
3136
- __name: "CodeBlockEditor",
3406
+ ...__default__$f,
3407
+ props: {
3408
+ id: null,
3409
+ name: null,
3410
+ content: null,
3411
+ editable: { type: Boolean, default: true },
3412
+ autoSaveDraft: { type: Boolean, default: true },
3413
+ codeOptions: null
3414
+ },
3415
+ emits: ["change", "field-input"],
3416
+ setup(__props, { emit }) {
3417
+ const props = __props;
3418
+ const tableConfig = {
3419
+ border: true,
3420
+ enableFullscreen: false,
3421
+ name: "params",
3422
+ maxHeight: "150px",
3423
+ items: [
3424
+ {
3425
+ type: "text",
3426
+ label: "\u53C2\u6570\u540D",
3427
+ name: "name"
3428
+ }
3429
+ ]
3430
+ };
3431
+ const services = inject("services");
3432
+ const codeName = ref("");
3433
+ const codeContent = ref("");
3434
+ const evalRes = ref(true);
3435
+ provide("mForm", {
3436
+ $emit: emit,
3437
+ setField: () => {
3438
+ }
3439
+ });
3440
+ const tableModel = ref();
3441
+ watchEffect(() => {
3442
+ codeName.value = props.name;
3443
+ codeContent.value = props.content;
3444
+ });
3445
+ const initTableModel = () => {
3446
+ const codeDsl = services?.codeBlockService.getCodeDslSync();
3447
+ if (!codeDsl)
3448
+ return;
3449
+ tableModel.value = {
3450
+ params: codeDsl[props.id]?.params || []
3451
+ };
3452
+ };
3453
+ initTableModel();
3454
+ const beforeSave = (codeValue) => {
3455
+ try {
3456
+ eval(codeValue);
3457
+ return true;
3458
+ } catch (e) {
3459
+ tMagicMessage.error(e.stack);
3460
+ return false;
3461
+ }
3462
+ };
3463
+ const saveCode = async (codeValue2) => {
3464
+ if (!props.editable)
3465
+ return;
3466
+ evalRes.value = beforeSave(codeValue2);
3467
+ if (evalRes.value) {
3468
+ await services?.codeBlockService.setCodeDslById(props.id, {
3469
+ name: codeName.value,
3470
+ content: codeValue2,
3471
+ params: tableModel.value?.params || []
3472
+ });
3473
+ tMagicMessage.success("\u4EE3\u7801\u4FDD\u5B58\u6210\u529F");
3474
+ services?.codeBlockService.removeCodeDraft(props.id);
3475
+ }
3476
+ };
3477
+ const saveAndClose = async (codeValue2) => {
3478
+ await saveCode(codeValue2);
3479
+ if (evalRes.value) {
3480
+ close();
3481
+ }
3482
+ };
3483
+ const close = () => {
3484
+ services?.codeBlockService.setCodeEditorShowStatus(false);
3485
+ };
3486
+ return (_ctx, _cache) => {
3487
+ const _component_m_form_table = resolveComponent("m-form-table");
3488
+ return openBlock(), createBlock(unref(TMagicCard), { shadow: "never" }, {
3489
+ header: withCtx(() => [
3490
+ createElementVNode("div", _hoisted_1$8, [
3491
+ _hoisted_2$4,
3492
+ createVNode(unref(TMagicInput), {
3493
+ class: "code-name-input",
3494
+ modelValue: codeName.value,
3495
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeName.value = $event),
3496
+ disabled: !__props.editable
3497
+ }, null, 8, ["modelValue", "disabled"])
3498
+ ]),
3499
+ createElementVNode("div", _hoisted_3$2, [
3500
+ _hoisted_4$1,
3501
+ createVNode(_component_m_form_table, {
3502
+ style: { "width": "320px" },
3503
+ config: tableConfig,
3504
+ model: tableModel.value,
3505
+ enableToggleMode: false,
3506
+ name: "params",
3507
+ prop: "params",
3508
+ size: "small"
3509
+ }, null, 8, ["model"])
3510
+ ])
3511
+ ]),
3512
+ default: withCtx(() => [
3513
+ createVNode(_sfc_main$h, {
3514
+ id: __props.id,
3515
+ content: codeContent.value,
3516
+ editable: __props.editable,
3517
+ autoSaveDraft: __props.autoSaveDraft,
3518
+ codeOptions: __props.codeOptions,
3519
+ language: "javascript",
3520
+ onSave: saveCode,
3521
+ onSaveAndClose: saveAndClose,
3522
+ onClose: close
3523
+ }, null, 8, ["id", "content", "editable", "autoSaveDraft", "codeOptions"])
3524
+ ]),
3525
+ _: 1
3526
+ });
3527
+ };
3528
+ }
3529
+ });
3530
+
3531
+ const _hoisted_1$7 = ["id"];
3532
+ const _hoisted_2$3 = { class: "list-item" };
3533
+ const _hoisted_3$1 = { class: "code-name" };
3534
+ const __default__$e = defineComponent({
3535
+ name: "MEditorCodeBlockEditor"
3536
+ });
3537
+ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3538
+ ...__default__$e,
3137
3539
  setup(__props) {
3138
3540
  const services = inject("services");
3139
- const codeEditor = ref();
3541
+ const codeOptions = inject("codeOptions", {});
3140
3542
  const left = ref(200);
3141
3543
  const currentTitle = ref("");
3142
3544
  const codeConfig = ref(null);
3143
3545
  const state = reactive({
3144
3546
  codeList: []
3145
3547
  });
3146
- const isShowCodeBlockEditor = computed(
3147
- () => codeConfig.value && services?.codeBlockService.getCodeEditorShowStatus() || false
3148
- );
3149
3548
  const mode = computed(() => services?.codeBlockService.getMode());
3150
3549
  const id = computed(() => services?.codeBlockService.getId() || "");
3151
3550
  const editable = computed(() => services?.codeBlockService.getEditStatus());
3152
3551
  const selectedIds = computed(() => services?.codeBlockService.getCombineIds() || []);
3153
3552
  watchEffect(async () => {
3154
- codeConfig.value = await services?.codeBlockService.getCodeContentById(id.value) || null;
3553
+ codeConfig.value = cloneDeep(await services?.codeBlockService.getCodeContentById(id.value)) || null;
3554
+ if (!codeConfig.value)
3555
+ return;
3556
+ codeConfig.value.content = serializeConfig(codeConfig.value.content);
3155
3557
  });
3156
3558
  watchEffect(async () => {
3157
3559
  const codeDsl = await services?.codeBlockService.getCodeDslByIds(selectedIds.value) || null;
@@ -3166,47 +3568,24 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
3166
3568
  });
3167
3569
  currentTitle.value = state.codeList[0]?.name || "";
3168
3570
  });
3169
- const saveCode = async () => {
3170
- if (!codeEditor.value || !codeConfig.value || !editable.value)
3171
- return true;
3172
- try {
3173
- const codeContent = codeEditor.value.getEditor()?.getValue();
3174
- codeConfig.value.content = eval(codeContent);
3175
- } catch (e) {
3176
- tMagicMessage.error(e.stack);
3177
- return false;
3178
- }
3179
- await services?.codeBlockService.setCodeDslById(id.value, {
3180
- name: codeConfig.value.name,
3181
- content: codeConfig.value.content
3182
- });
3183
- tMagicMessage.success("\u4EE3\u7801\u4FDD\u5B58\u6210\u529F");
3184
- return true;
3185
- };
3186
- const saveAndClose = async () => {
3187
- const saveRes = await saveCode();
3188
- if (saveRes) {
3189
- await services?.codeBlockService.setCodeEditorShowStatus(false);
3190
- }
3191
- };
3192
3571
  const selectHandler = (data) => {
3193
3572
  services?.codeBlockService.setId(data.id);
3194
3573
  currentTitle.value = data.name;
3195
3574
  };
3196
3575
  return (_ctx, _cache) => {
3197
3576
  return openBlock(), createBlock(unref(TMagicDialog), {
3198
- modelValue: unref(isShowCodeBlockEditor),
3199
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(isShowCodeBlockEditor) ? isShowCodeBlockEditor.value = $event : null),
3577
+ "model-value": true,
3200
3578
  class: "code-editor-dialog",
3201
3579
  title: currentTitle.value,
3202
3580
  fullscreen: true,
3203
- "before-close": saveAndClose,
3204
- "append-to-body": true
3581
+ "close-on-press-escape": false,
3582
+ "append-to-body": true,
3583
+ "show-close": false
3205
3584
  }, {
3206
3585
  default: withCtx(() => [
3207
- createVNode(_sfc_main$l, {
3586
+ createVNode(_sfc_main$o, {
3208
3587
  left: left.value,
3209
- "onUpdate:left": _cache[1] || (_cache[1] = ($event) => left.value = $event),
3588
+ "onUpdate:left": _cache[0] || (_cache[0] = ($event) => left.value = $event),
3210
3589
  "min-left": 45,
3211
3590
  class: "code-editor-layout"
3212
3591
  }, createSlots({
@@ -3218,72 +3597,15 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
3218
3597
  ])
3219
3598
  }, [
3220
3599
  renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id: unref(id) }),
3221
- createVNode(unref(TMagicCard), { shadow: "never" }, {
3222
- header: withCtx(() => [
3223
- createElementVNode("div", _hoisted_4$1, [
3224
- _hoisted_5$1,
3225
- codeConfig.value ? (openBlock(), createBlock(unref(TMagicInput), {
3226
- key: 0,
3227
- class: "code-name-input",
3228
- modelValue: codeConfig.value.name,
3229
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => codeConfig.value.name = $event),
3230
- disabled: !unref(editable)
3231
- }, null, 8, ["modelValue", "disabled"])) : createCommentVNode("", true)
3232
- ])
3233
- ]),
3234
- default: withCtx(() => [
3235
- createElementVNode("div", _hoisted_6$1, [
3236
- codeConfig.value ? (openBlock(), createBlock(_sfc_main$p, {
3237
- key: 0,
3238
- ref_key: "codeEditor",
3239
- ref: codeEditor,
3240
- class: "m-editor-container",
3241
- "init-values": `${codeConfig.value.content}`,
3242
- onSave: saveCode,
3243
- options: {
3244
- tabSize: 2,
3245
- fontSize: 16,
3246
- formatOnPaste: true,
3247
- readOnly: !unref(editable)
3248
- }
3249
- }, null, 8, ["init-values", "options"])) : createCommentVNode("", true),
3250
- unref(editable) ? (openBlock(), createElementBlock("div", _hoisted_7$1, [
3251
- createVNode(unref(TMagicButton), {
3252
- type: "primary",
3253
- class: "button",
3254
- onClick: saveCode
3255
- }, {
3256
- default: withCtx(() => [
3257
- _hoisted_8$1
3258
- ]),
3259
- _: 1
3260
- }),
3261
- createVNode(unref(TMagicButton), {
3262
- type: "primary",
3263
- class: "button",
3264
- onClick: saveAndClose
3265
- }, {
3266
- default: withCtx(() => [
3267
- _hoisted_9$1
3268
- ]),
3269
- _: 1
3270
- })
3271
- ])) : (openBlock(), createElementBlock("div", _hoisted_10, [
3272
- createVNode(unref(TMagicButton), {
3273
- type: "primary",
3274
- class: "button",
3275
- onClick: saveAndClose
3276
- }, {
3277
- default: withCtx(() => [
3278
- _hoisted_11
3279
- ]),
3280
- _: 1
3281
- })
3282
- ]))
3283
- ])
3284
- ]),
3285
- _: 1
3286
- })
3600
+ codeConfig.value ? (openBlock(), createBlock(_sfc_main$g, {
3601
+ key: 0,
3602
+ id: unref(id),
3603
+ name: codeConfig.value.name,
3604
+ content: codeConfig.value.content,
3605
+ editable: !!unref(editable),
3606
+ autoSaveDraft: unref(mode) === unref(CodeEditorMode).EDITOR,
3607
+ codeOptions: unref(codeOptions)
3608
+ }, null, 8, ["id", "name", "content", "editable", "autoSaveDraft", "codeOptions"])) : createCommentVNode("", true)
3287
3609
  ], 2)) : createCommentVNode("", true)
3288
3610
  ]),
3289
3611
  _: 2
@@ -3318,7 +3640,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
3318
3640
  ]), 1032, ["left"])
3319
3641
  ]),
3320
3642
  _: 3
3321
- }, 8, ["modelValue", "title"]);
3643
+ }, 8, ["title"]);
3322
3644
  };
3323
3645
  }
3324
3646
  });
@@ -3345,8 +3667,11 @@ const _hoisted_9 = /* @__PURE__ */ createElementVNode("svg", {
3345
3667
  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"
3346
3668
  })
3347
3669
  ], -1);
3348
- const _sfc_main$f = /* @__PURE__ */ defineComponent({
3349
- __name: "CodeBlockList",
3670
+ const __default__$d = defineComponent({
3671
+ name: "MEditorCodeBlockList"
3672
+ });
3673
+ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3674
+ ...__default__$d,
3350
3675
  props: {
3351
3676
  customError: null
3352
3677
  },
@@ -3354,41 +3679,38 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3354
3679
  const props = __props;
3355
3680
  const services = inject("services");
3356
3681
  const state = reactive({
3357
- codeList: [],
3358
- bindComps: {}
3682
+ codeList: []
3359
3683
  });
3360
3684
  const editable = computed(() => services?.codeBlockService.getEditStatus());
3361
- const getBindCompsByCodeId = (codeId, codeBlockContent) => {
3362
- if (isEmpty(codeBlockContent) || isEmpty(codeBlockContent.comps)) {
3363
- state.bindComps[codeId] = [];
3364
- return;
3365
- }
3366
- const compsField = codeBlockContent.comps;
3367
- const bindCompIds = Object.keys(compsField);
3368
- const bindCompsFiltered = bindCompIds.filter((compId) => !isEmpty(compsField[compId]));
3369
- const compsInfo = bindCompsFiltered.map((compId) => ({
3370
- id: compId,
3371
- name: getCompName(compId)
3685
+ const isShowCodeBlockEditor = computed(() => services?.codeBlockService.getCodeEditorShowStatus() || false);
3686
+ const codeCombineInfo = ref(null);
3687
+ const getBindCompsByCodeId = (codeId) => {
3688
+ if (!codeCombineInfo.value || !codeCombineInfo.value[codeId])
3689
+ return [];
3690
+ const bindCompsId = Object.keys(codeCombineInfo.value[codeId]);
3691
+ return bindCompsId.map((compId) => ({
3692
+ compId,
3693
+ compName: getCompName(compId)
3372
3694
  }));
3373
- state.bindComps[codeId] = compsInfo;
3374
3695
  };
3375
3696
  const initList = async () => {
3376
- const codeDsl = await services?.codeBlockService.getCodeDsl() || null;
3377
- if (!codeDsl)
3697
+ const codeDsl = cloneDeep(await services?.codeBlockService.getCodeDsl()) || null;
3698
+ codeCombineInfo.value = cloneDeep(services?.codeBlockService.getCombineInfo()) || null;
3699
+ if (!codeDsl || !codeCombineInfo.value)
3378
3700
  return;
3379
3701
  state.codeList = [];
3380
3702
  forIn(codeDsl, (value, codeId) => {
3381
- getBindCompsByCodeId(codeId, value);
3382
3703
  state.codeList.push({
3383
3704
  id: codeId,
3384
3705
  name: value.name,
3385
3706
  codeBlockContent: value,
3386
- showRelation: true
3707
+ showRelation: true,
3708
+ combineInfo: getBindCompsByCodeId(codeId)
3387
3709
  });
3388
3710
  });
3389
3711
  };
3390
3712
  watch(
3391
- () => services?.codeBlockService.getCodeDsl(),
3713
+ [() => services?.codeBlockService.getCodeDslSync(), () => services?.codeBlockService.refreshCombineInfo()],
3392
3714
  () => {
3393
3715
  initList();
3394
3716
  },
@@ -3397,20 +3719,6 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3397
3719
  deep: true
3398
3720
  }
3399
3721
  );
3400
- watch(
3401
- () => services?.editorService.get("node"),
3402
- (curNode) => {
3403
- if (!curNode?.id)
3404
- return;
3405
- forIn(state.bindComps, (bindCompInfo) => {
3406
- bindCompInfo.forEach((comp) => {
3407
- if (comp.id === curNode.id) {
3408
- comp.name = curNode.name;
3409
- }
3410
- });
3411
- });
3412
- }
3413
- );
3414
3722
  const createCodeBlock = async () => {
3415
3723
  const { codeBlockService } = services || {};
3416
3724
  if (!codeBlockService) {
@@ -3419,9 +3727,10 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3419
3727
  }
3420
3728
  const codeConfig = {
3421
3729
  name: "\u4EE3\u7801\u5757",
3422
- content: `() => {
3730
+ content: `({app, params}) => {
3423
3731
  // place your code here
3424
- }`
3732
+ }`,
3733
+ params: []
3425
3734
  };
3426
3735
  await codeBlockService.setMode(CodeEditorMode.EDITOR);
3427
3736
  const id = await codeBlockService.getUniqueId();
@@ -3433,7 +3742,8 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3433
3742
  services?.codeBlockService.setCodeEditorContent(true, key);
3434
3743
  };
3435
3744
  const deleteCode = (key) => {
3436
- const existBinds = !!(state.bindComps[key]?.length > 0);
3745
+ const currentCode = state.codeList.find((codeItem) => codeItem.id === key);
3746
+ const existBinds = !isEmpty(currentCode?.combineInfo);
3437
3747
  const undeleteableList = services?.codeBlockService.getUndeletableList() || [];
3438
3748
  if (!existBinds && !undeleteableList.includes(key)) {
3439
3749
  services?.codeBlockService.deleteCodeDslByIds([key]);
@@ -3499,110 +3809,118 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3499
3809
  })) : createCommentVNode("", true)
3500
3810
  ])
3501
3811
  ]),
3502
- !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(unref(TMagicTree), {
3503
- key: 0,
3504
- ref_key: "tree",
3505
- ref: tree,
3506
- "node-key": "id",
3507
- "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3508
- data: state.codeList,
3509
- "highlight-current": true,
3510
- "filter-node-method": filterNode,
3511
- onNodeClick: toggleCombineRelation
3512
- }, {
3513
- default: withCtx(({ data }) => [
3514
- createElementVNode("div", {
3515
- id: data.id,
3516
- class: "list-container"
3517
- }, [
3518
- createElementVNode("div", _hoisted_5, [
3519
- createElementVNode("div", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
3520
- createElementVNode("div", _hoisted_7, [
3521
- createVNode(unref(TMagicTooltip), {
3522
- effect: "dark",
3523
- content: unref(editable) ? "\u7F16\u8F91" : "\u67E5\u770B",
3524
- placement: "bottom"
3525
- }, {
3526
- default: withCtx(() => [
3527
- createVNode(_sfc_main$o, {
3528
- icon: unref(editable) ? unref(Edit) : unref(View),
3529
- class: "edit-icon",
3530
- onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
3531
- }, null, 8, ["icon", "onClick"])
3532
- ]),
3533
- _: 2
3534
- }, 1032, ["content"]),
3535
- state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createBlock(unref(TMagicTooltip), {
3536
- key: 0,
3537
- effect: "dark",
3538
- content: "\u67E5\u770B\u7ED1\u5B9A\u5173\u7CFB",
3539
- placement: "bottom"
3540
- }, {
3541
- default: withCtx(() => [
3542
- createVNode(_sfc_main$o, {
3543
- icon: unref(Link),
3544
- class: "edit-icon",
3545
- onClick: withModifiers(($event) => toggleCombineRelation(data), ["stop"])
3546
- }, null, 8, ["icon", "onClick"])
3547
- ]),
3548
- _: 2
3549
- }, 1024)) : createCommentVNode("", true),
3550
- unref(editable) ? (openBlock(), createBlock(unref(TMagicTooltip), {
3551
- key: 1,
3552
- effect: "dark",
3553
- content: "\u5220\u9664",
3554
- placement: "bottom"
3555
- }, {
3556
- default: withCtx(() => [
3557
- createVNode(_sfc_main$o, {
3558
- icon: unref(Close),
3559
- class: "edit-icon",
3560
- onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
3561
- }, null, 8, ["icon", "onClick"])
3562
- ]),
3563
- _: 2
3564
- }, 1024)) : createCommentVNode("", true),
3565
- renderSlot(_ctx.$slots, "code-block-panel-tool", {
3566
- id: data.id,
3567
- data: data.codeBlockContent
3568
- })
3569
- ])
3812
+ createVNode(unref(TMagicScrollbar), null, {
3813
+ default: withCtx(() => [
3814
+ !unref(isEmpty)(state.codeList) ? (openBlock(), createBlock(unref(TMagicTree), {
3815
+ key: 0,
3816
+ ref_key: "tree",
3817
+ ref: tree,
3818
+ "node-key": "id",
3819
+ "empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
3820
+ data: state.codeList,
3821
+ "highlight-current": true,
3822
+ "filter-node-method": filterNode,
3823
+ onNodeClick: toggleCombineRelation
3824
+ }, {
3825
+ default: withCtx(({ data }) => [
3826
+ createElementVNode("div", {
3827
+ id: data.id,
3828
+ class: "list-container"
3829
+ }, [
3830
+ createElementVNode("div", _hoisted_5, [
3831
+ createElementVNode("span", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
3832
+ createElementVNode("div", _hoisted_7, [
3833
+ createVNode(unref(TMagicTooltip), {
3834
+ effect: "dark",
3835
+ content: unref(editable) ? "\u7F16\u8F91" : "\u67E5\u770B",
3836
+ placement: "bottom"
3837
+ }, {
3838
+ default: withCtx(() => [
3839
+ createVNode(_sfc_main$n, {
3840
+ icon: unref(editable) ? unref(Edit) : unref(View),
3841
+ class: "edit-icon",
3842
+ onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
3843
+ }, null, 8, ["icon", "onClick"])
3844
+ ]),
3845
+ _: 2
3846
+ }, 1032, ["content"]),
3847
+ data.combineInfo && data.combineInfo.length > 0 ? (openBlock(), createBlock(unref(TMagicTooltip), {
3848
+ key: 0,
3849
+ effect: "dark",
3850
+ content: "\u67E5\u770B\u7ED1\u5B9A\u5173\u7CFB",
3851
+ placement: "bottom"
3852
+ }, {
3853
+ default: withCtx(() => [
3854
+ createVNode(_sfc_main$n, {
3855
+ icon: unref(Link),
3856
+ class: "edit-icon",
3857
+ onClick: withModifiers(($event) => toggleCombineRelation(data), ["stop"])
3858
+ }, null, 8, ["icon", "onClick"])
3859
+ ]),
3860
+ _: 2
3861
+ }, 1024)) : createCommentVNode("", true),
3862
+ unref(editable) ? (openBlock(), createBlock(unref(TMagicTooltip), {
3863
+ key: 1,
3864
+ effect: "dark",
3865
+ content: "\u5220\u9664",
3866
+ placement: "bottom"
3867
+ }, {
3868
+ default: withCtx(() => [
3869
+ createVNode(_sfc_main$n, {
3870
+ icon: unref(Close),
3871
+ class: "edit-icon",
3872
+ onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
3873
+ }, null, 8, ["icon", "onClick"])
3874
+ ]),
3875
+ _: 2
3876
+ }, 1024)) : createCommentVNode("", true),
3877
+ renderSlot(_ctx.$slots, "code-block-panel-tool", {
3878
+ id: data.id,
3879
+ data: data.codeBlockContent
3880
+ })
3881
+ ])
3882
+ ]),
3883
+ data.showRelation && data.combineInfo && data.combineInfo.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
3884
+ _hoisted_9,
3885
+ (openBlock(true), createElementBlock(Fragment, null, renderList(data.combineInfo, (comp, index) => {
3886
+ return openBlock(), createBlock(unref(TMagicButton), {
3887
+ key: index,
3888
+ class: "code-comp",
3889
+ size: "small",
3890
+ plain: true,
3891
+ onClick: withModifiers(($event) => selectComp(comp.compId), ["stop"])
3892
+ }, {
3893
+ default: withCtx(() => [
3894
+ createTextVNode(toDisplayString(comp.compName), 1)
3895
+ ]),
3896
+ _: 2
3897
+ }, 1032, ["onClick"]);
3898
+ }), 128))
3899
+ ])) : createCommentVNode("", true)
3900
+ ], 8, _hoisted_4)
3570
3901
  ]),
3571
- data.showRelation && state.bindComps[data.id] && state.bindComps[data.id].length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
3572
- _hoisted_9,
3573
- (openBlock(true), createElementBlock(Fragment, null, renderList(state.bindComps[data.id], (comp, index) => {
3574
- return openBlock(), createBlock(unref(TMagicButton), {
3575
- key: index,
3576
- class: "code-comp",
3577
- size: "small",
3578
- plain: true,
3579
- onClick: withModifiers(($event) => selectComp(comp.id), ["stop"])
3580
- }, {
3581
- default: withCtx(() => [
3582
- createTextVNode(toDisplayString(comp.name), 1)
3583
- ]),
3584
- _: 2
3585
- }, 1032, ["onClick"]);
3586
- }), 128))
3587
- ])) : createCommentVNode("", true)
3588
- ], 8, _hoisted_4)
3902
+ _: 3
3903
+ }, 8, ["data"])) : createCommentVNode("", true)
3589
3904
  ]),
3590
3905
  _: 3
3591
- }, 8, ["data"])) : createCommentVNode("", true),
3592
- createVNode(_sfc_main$g, null, {
3906
+ }),
3907
+ unref(isShowCodeBlockEditor) ? (openBlock(), createBlock(_sfc_main$f, { key: 0 }, {
3593
3908
  "code-block-edit-panel-header": withCtx(({ id }) => [
3594
3909
  renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
3595
3910
  ]),
3596
3911
  _: 3
3597
- })
3912
+ })) : createCommentVNode("", true)
3598
3913
  ]);
3599
3914
  };
3600
3915
  }
3601
3916
  });
3602
3917
 
3603
3918
  const _hoisted_1$5 = ["onClick", "onDragstart"];
3604
- const _sfc_main$e = /* @__PURE__ */ defineComponent({
3605
- __name: "ComponentListPanel",
3919
+ const __default__$c = defineComponent({
3920
+ name: "MEditorComponentListPanel"
3921
+ });
3922
+ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3923
+ ...__default__$c,
3606
3924
  setup(__props) {
3607
3925
  const searchText = ref("");
3608
3926
  const services = inject("services");
@@ -3691,7 +4009,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3691
4009
  name: `${index}`
3692
4010
  }, {
3693
4011
  title: withCtx(() => [
3694
- createVNode(_sfc_main$o, { icon: unref(Grid) }, null, 8, ["icon"]),
4012
+ createVNode(_sfc_main$n, { icon: unref(Grid) }, null, 8, ["icon"]),
3695
4013
  createTextVNode(toDisplayString(group.title), 1)
3696
4014
  ]),
3697
4015
  default: withCtx(() => [
@@ -3706,7 +4024,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3706
4024
  onDrag: dragHandler
3707
4025
  }, [
3708
4026
  renderSlot(_ctx.$slots, "component-list-item", { component: item }, () => [
3709
- createVNode(_sfc_main$o, {
4027
+ createVNode(_sfc_main$n, {
3710
4028
  icon: item.icon
3711
4029
  }, null, 8, ["icon"]),
3712
4030
  createVNode(unref(TMagicTooltip), {
@@ -3737,8 +4055,11 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
3737
4055
  }
3738
4056
  });
3739
4057
 
3740
- const _sfc_main$d = /* @__PURE__ */ defineComponent({
3741
- __name: "ContentMenu",
4058
+ const __default__$b = defineComponent({
4059
+ name: "MEditorContentMenu"
4060
+ });
4061
+ const _sfc_main$c = /* @__PURE__ */ defineComponent({
4062
+ ...__default__$b,
3742
4063
  props: {
3743
4064
  menuData: { default: () => [] },
3744
4065
  isSubMenu: { type: Boolean, default: false }
@@ -3817,7 +4138,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3817
4138
  });
3818
4139
  return (_ctx, _cache) => {
3819
4140
  const _component_content_menu = resolveComponent("content-menu", true);
3820
- return __props.menuData.length && visible.value ? (openBlock(), createElementBlock("div", {
4141
+ return __props.menuData.length ? withDirectives((openBlock(), createElementBlock("div", {
3821
4142
  key: 0,
3822
4143
  class: "magic-editor-content-menu",
3823
4144
  ref_key: "menu",
@@ -3826,7 +4147,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3826
4147
  }, [
3827
4148
  createElementVNode("div", null, [
3828
4149
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.menuData, (item, index) => {
3829
- return openBlock(), createBlock(_sfc_main$j, {
4150
+ return openBlock(), createBlock(_sfc_main$k, {
3830
4151
  "event-type": "mouseup",
3831
4152
  data: item,
3832
4153
  key: index,
@@ -3845,21 +4166,29 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3845
4166
  onHide: hide
3846
4167
  }, null, 8, ["menu-data"])
3847
4168
  ]))
3848
- ], 4)) : createCommentVNode("", true);
4169
+ ], 4)), [
4170
+ [vShow, visible.value]
4171
+ ]) : createCommentVNode("", true);
3849
4172
  };
3850
4173
  }
3851
4174
  });
3852
4175
 
3853
- const _sfc_main$c = /* @__PURE__ */ defineComponent({
3854
- __name: "LayerMenu",
4176
+ const __default__$a = defineComponent({
4177
+ name: "MEditorLayerMenu"
4178
+ });
4179
+ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4180
+ ...__default__$a,
4181
+ props: {
4182
+ layerContentMenu: null
4183
+ },
3855
4184
  setup(__props, { expose }) {
4185
+ const props = __props;
3856
4186
  const services = inject("services");
3857
4187
  const menu = ref();
3858
4188
  const node = computed(() => services?.editorService.get("node"));
3859
4189
  const isRoot = computed(() => node.value?.type === NodeType.ROOT);
3860
4190
  const isPage = computed(() => node.value?.type === NodeType.PAGE);
3861
4191
  const componentList = computed(() => services?.componentListService.getList() || []);
3862
- const layerContentMenu = inject("layerContentMenu", []);
3863
4192
  const createMenuItems = (group) => group.items.map((component) => ({
3864
4193
  text: component.text,
3865
4194
  type: "button",
@@ -3914,7 +4243,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3914
4243
  {
3915
4244
  type: "button",
3916
4245
  text: "\u590D\u5236",
3917
- icon: markRaw(DocumentCopy),
4246
+ icon: markRaw(CopyDocument),
3918
4247
  display: () => !isRoot.value,
3919
4248
  handler: () => {
3920
4249
  node.value && services?.editorService.copy(node.value);
@@ -3929,7 +4258,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3929
4258
  node.value && services?.editorService.remove(node.value);
3930
4259
  }
3931
4260
  },
3932
- ...layerContentMenu
4261
+ ...props.layerContentMenu
3933
4262
  ]);
3934
4263
  const show = (e) => {
3935
4264
  menu.value?.show(e);
@@ -3938,7 +4267,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3938
4267
  show
3939
4268
  });
3940
4269
  return (_ctx, _cache) => {
3941
- return openBlock(), createBlock(_sfc_main$d, {
4270
+ return openBlock(), createBlock(_sfc_main$c, {
3942
4271
  "menu-data": unref(menuData),
3943
4272
  ref_key: "menu",
3944
4273
  ref: menu,
@@ -3949,27 +4278,42 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3949
4278
  });
3950
4279
 
3951
4280
  const _hoisted_1$4 = ["id", "onMouseenter"];
3952
- const _sfc_main$b = /* @__PURE__ */ defineComponent({
3953
- __name: "LayerPanel",
4281
+ const __default__$9 = defineComponent({
4282
+ name: "MEditorLayerPanel"
4283
+ });
4284
+ const _sfc_main$a = /* @__PURE__ */ defineComponent({
4285
+ ...__default__$9,
4286
+ props: {
4287
+ layerContentMenu: null
4288
+ },
3954
4289
  setup(__props) {
3955
4290
  const throttleTime = 150;
3956
4291
  const services = inject("services");
4292
+ const editorService = services?.editorService;
3957
4293
  const tree = ref();
3958
4294
  const menu = ref();
3959
- const editorService = services?.editorService;
4295
+ const checkedKeys = ref([]);
4296
+ const isCtrlKeyDown = ref(false);
4297
+ const filterText = ref("");
4298
+ const expandedKeys = ref([]);
4299
+ const currentNodeKey = ref();
4300
+ const clicked = ref(false);
4301
+ const treeProps = {
4302
+ children: "items",
4303
+ disabled: (data) => Boolean(data.items?.length),
4304
+ class: (data) => {
4305
+ if (clicked.value || isPage(data))
4306
+ return "";
4307
+ if (data.id === highlightNode?.value?.id && !checkedKeys.value.includes(data.id)) {
4308
+ return "cus-tree-node-hover";
4309
+ }
4310
+ }
4311
+ };
4312
+ const isMultiSelect = computed(() => isCtrlKeyDown.value || checkedKeys.value.length > 1);
4313
+ const nodes = computed(() => editorService?.get("nodes") || []);
3960
4314
  const page = computed(() => editorService?.get("page"));
3961
4315
  const values = computed(() => page.value ? [page.value] : []);
3962
- const selectedNodes = ref([]);
3963
- const selectedIds = computed(() => selectedNodes.value.map((node) => node.id));
3964
- const isMultiSelectStatus = ref(false);
3965
- const spliceNodeKey = ref();
3966
- const filterText = ref("");
3967
- const defaultExpandedKeys = computed(() => selectedIds.value.length > 0 ? selectedIds.value : []);
3968
- editorService?.on("remove", () => {
3969
- setTimeout(() => {
3970
- tree.value?.getNode(editorService.get("node").id)?.updateChildren();
3971
- }, 0);
3972
- });
4316
+ const highlightNode = computed(() => editorService?.get("highlightNode"));
3973
4317
  const select = async (data) => {
3974
4318
  if (!data.id) {
3975
4319
  throw new Error("\u6CA1\u6709id");
@@ -3988,7 +4332,6 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
3988
4332
  editorService?.highlight(data);
3989
4333
  editorService?.get("stage")?.highlight(data.id);
3990
4334
  };
3991
- const expandedKeys = /* @__PURE__ */ new Map();
3992
4335
  const allowDrop = (draggingNode, dropNode, type) => {
3993
4336
  const { data } = dropNode || {};
3994
4337
  const { data: ingData } = draggingNode;
@@ -4020,23 +4363,18 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4020
4363
  const [page2] = data;
4021
4364
  editorService?.update(page2);
4022
4365
  };
4023
- const loadItems = (node, resolve) => {
4024
- if (Array.isArray(node.data)) {
4025
- return resolve(node.data);
4026
- }
4027
- if (Array.isArray(node.data?.items)) {
4028
- return resolve(node.data?.items);
4029
- }
4030
- resolve([]);
4031
- };
4032
4366
  const handleCollapse = (data) => {
4033
- expandedKeys.delete(data.id);
4367
+ expandedKeys.value = expandedKeys.value.filter((id) => id !== data.id);
4034
4368
  };
4035
4369
  const handleExpand = (data) => {
4036
- const parent = editorService?.getParentById(data.id);
4037
- if (!parent?.id)
4370
+ if (!page.value) {
4371
+ expandedKeys.value = [];
4038
4372
  return;
4039
- expandedKeys.set(parent.id, parent.id);
4373
+ }
4374
+ expandedKeys.value = union(
4375
+ expandedKeys.value,
4376
+ getNodePath(data.id, [page.value]).map((node) => node.id)
4377
+ );
4040
4378
  };
4041
4379
  const filterNode = (value, data) => {
4042
4380
  if (!value) {
@@ -4053,121 +4391,78 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4053
4391
  const filterTextChangeHandler = (val) => {
4054
4392
  tree.value?.filter(val);
4055
4393
  };
4056
- const expandNodes = async () => {
4057
- if (!tree.value)
4058
- return;
4059
- await nextTick();
4060
- tree.value && Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]) => {
4061
- if (node.expanded && node.data.items) {
4062
- expandedKeys.set(id, id);
4063
- }
4064
- });
4065
- expandedKeys.forEach((key) => {
4066
- if (!tree.value)
4067
- return;
4068
- tree.value.getNode(key)?.expand();
4069
- });
4070
- };
4071
- watch(
4072
- () => editorService?.get("nodes"),
4073
- (nodes) => {
4074
- selectedNodes.value = nodes ?? [];
4394
+ watch(nodes, (nodes2) => {
4395
+ const ids = nodes2?.map((node) => node.id) || [];
4396
+ const idsLength = ids.length;
4397
+ const checkedKeysLength = checkedKeys.value.length;
4398
+ if (difference(
4399
+ idsLength > checkedKeysLength ? ids : checkedKeys.value,
4400
+ idsLength > checkedKeysLength ? checkedKeys.value : ids
4401
+ ).length) {
4402
+ tree.value?.setCheckedKeys([], false);
4403
+ [currentNodeKey.value] = ids;
4404
+ checkedKeys.value = ids.filter((id) => id !== page.value?.id);
4405
+ expandedKeys.value = union(expandedKeys.value, ids);
4075
4406
  }
4076
- );
4077
- const setTreeKeyStatus = () => {
4078
- if (!tree.value)
4079
- return;
4080
- if (selectedIds.value.length === 0) {
4081
- tree.value.setCheckedKeys([]);
4082
- tree.value.setCurrentKey();
4083
- } else if (selectedIds.value.length === 1 && !isMultiSelectStatus.value) {
4084
- tree.value.setCurrentKey(selectedIds.value[0], true);
4085
- tree.value.setCheckedKeys([]);
4086
- } else {
4087
- tree.value.setCheckedKeys(selectedIds.value);
4088
- tree.value.setCurrentKey();
4407
+ });
4408
+ watch(isMultiSelect, (isMultiSelect2) => {
4409
+ if (!isMultiSelect2) {
4410
+ currentNodeKey.value = editorService?.get("node").id;
4411
+ tree.value?.setCurrentKey(currentNodeKey.value);
4089
4412
  }
4090
- };
4091
- watch([selectedIds, tree], async () => {
4092
- if (!tree.value || !editorService)
4093
- return;
4094
- const parent = editorService.get("parent");
4095
- if (!parent?.id)
4096
- return;
4097
- const treeNode = tree.value.getNode(parent.id);
4098
- treeNode?.updateChildren();
4099
- await expandNodes();
4100
- setTreeKeyStatus();
4101
4413
  });
4102
- const keycon = ref();
4103
- const addSelectModeListener = () => {
4414
+ const editorServiceRemoveHandler = () => {
4415
+ setTimeout(() => {
4416
+ tree.value?.getNode(editorService?.get("node").id)?.updateChildren();
4417
+ }, 0);
4418
+ };
4419
+ const windowBlurHandler = () => {
4420
+ isCtrlKeyDown.value = false;
4421
+ };
4422
+ let keycon;
4423
+ onMounted(() => {
4424
+ editorService?.on("remove", editorServiceRemoveHandler);
4425
+ keycon = new KeyController();
4104
4426
  const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
4105
4427
  const ctrl = isMac ? "meta" : "ctrl";
4106
- keycon.value = new KeyController();
4107
- keycon.value.keydown(ctrl, (e) => {
4108
- e.inputEvent.preventDefault();
4109
- isMultiSelectStatus.value = true;
4110
- });
4111
- keycon.value.on("blur", () => {
4112
- isMultiSelectStatus.value = false;
4113
- });
4114
- keycon.value.keyup(ctrl, (e) => {
4115
- e.inputEvent.preventDefault();
4116
- isMultiSelectStatus.value = false;
4428
+ keycon.keydown((e) => {
4429
+ if (e.key !== ctrl) {
4430
+ isCtrlKeyDown.value = false;
4431
+ }
4432
+ }).keydown(ctrl, () => {
4433
+ isCtrlKeyDown.value = true;
4434
+ }).keyup(ctrl, () => {
4435
+ isCtrlKeyDown.value = false;
4117
4436
  });
4118
- };
4119
- const removeSelectModeListener = () => {
4120
- keycon.value?.destroy();
4121
- if (selectedIds.value.length === 1)
4122
- isMultiSelectStatus.value = false;
4123
- };
4124
- const clicked = ref(false);
4125
- const highlightNode = computed(() => editorService?.get("highlightNode"));
4437
+ globalThis.addEventListener("blur", windowBlurHandler);
4438
+ });
4439
+ onUnmounted(() => {
4440
+ keycon.destroy();
4441
+ editorService?.off("remove", editorServiceRemoveHandler);
4442
+ globalThis.removeEventListener("blur", windowBlurHandler);
4443
+ });
4126
4444
  const highlightHandler = throttle((data) => {
4127
4445
  highlight(data);
4128
4446
  }, throttleTime);
4129
4447
  const toggleClickFlag = () => {
4130
4448
  clicked.value = !clicked.value;
4131
4449
  };
4132
- const canHighlight = (data) => {
4133
- if (clicked.value)
4134
- return false;
4135
- return data.id === highlightNode?.value?.id && !selectedIds.value.includes(data.id) && spliceNodeKey.value !== data.id;
4136
- };
4137
- watch(isMultiSelectStatus, () => {
4138
- if (isMultiSelectStatus.value && selectedNodes.value.length === 1 && selectedNodes.value[0].type === NodeType.PAGE) {
4139
- selectedNodes.value = [];
4140
- }
4141
- });
4142
- const multiClickHandler = (data) => {
4143
- if (!data?.id) {
4144
- throw new Error("\u6CA1\u6709id");
4145
- }
4146
- if (data.type === NodeType.PAGE) {
4147
- tree.value?.setCheckedKeys([]);
4148
- return;
4149
- }
4150
- const index = selectedNodes.value.findIndex((node) => node.id === data.id);
4151
- if (index !== -1) {
4152
- selectedNodes.value.splice(index, 1);
4153
- spliceNodeKey.value = data.id;
4450
+ const checkHandler = (data, { checkedNodes }) => {
4451
+ if (checkedNodes.length > 0) {
4452
+ multiSelect(checkedNodes.map((node) => node.id));
4154
4453
  } else {
4155
- selectedNodes.value = [...selectedNodes.value, data];
4454
+ multiSelect(nodes.value.map((node) => node.id));
4156
4455
  }
4157
- tree.value?.setCheckedKeys(selectedIds.value);
4158
- multiSelect(selectedIds.value);
4159
4456
  };
4160
4457
  const clickHandler = (data) => {
4161
- if (!isMultiSelectStatus.value) {
4162
- if (services?.uiService.get("uiSelectMode")) {
4163
- document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
4164
- return;
4165
- }
4166
- tree.value?.setCurrentKey(data.id);
4167
- select(data);
4168
- } else {
4169
- multiClickHandler(data);
4458
+ if (isCtrlKeyDown.value) {
4459
+ return;
4460
+ }
4461
+ if (services?.uiService.get("uiSelectMode")) {
4462
+ document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
4463
+ return;
4170
4464
  }
4465
+ select(data);
4171
4466
  };
4172
4467
  const contextmenu = async (event, data) => {
4173
4468
  event.preventDefault();
@@ -4175,11 +4470,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4175
4470
  menu.value?.show(event);
4176
4471
  };
4177
4472
  return (_ctx, _cache) => {
4178
- return openBlock(), createBlock(unref(TMagicScrollbar), {
4179
- class: "magic-editor-layer-panel",
4180
- onMouseenter: addSelectModeListener,
4181
- onMouseleave: removeSelectModeListener
4182
- }, {
4473
+ return openBlock(), createBlock(unref(TMagicScrollbar), { class: "magic-editor-layer-panel" }, {
4183
4474
  default: withCtx(() => [
4184
4475
  renderSlot(_ctx.$slots, "layer-panel-header"),
4185
4476
  createVNode(unref(TMagicInput), {
@@ -4200,30 +4491,30 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4200
4491
  "node-key": "id",
4201
4492
  "empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684",
4202
4493
  draggable: "",
4203
- "default-expanded-keys": unref(defaultExpandedKeys),
4204
- load: loadItems,
4494
+ "default-expanded-keys": expandedKeys.value,
4495
+ "default-checked-keys": checkedKeys.value,
4496
+ "current-node-key": currentNodeKey.value,
4205
4497
  data: unref(values),
4206
4498
  "expand-on-click-node": false,
4207
- "highlight-current": true,
4208
- props: {
4209
- children: "items"
4210
- },
4499
+ "highlight-current": !unref(isMultiSelect),
4500
+ "check-on-click-node": true,
4501
+ props: treeProps,
4211
4502
  "filter-node-method": filterNode,
4212
4503
  "allow-drop": allowDrop,
4213
- "show-checkbox": isMultiSelectStatus.value || unref(selectedIds).length > 1,
4504
+ "show-checkbox": unref(isMultiSelect),
4214
4505
  onNodeClick: clickHandler,
4215
4506
  onNodeContextmenu: contextmenu,
4216
4507
  onNodeDragEnd: handleDragEnd,
4217
4508
  onNodeCollapse: handleCollapse,
4218
4509
  onNodeExpand: handleExpand,
4219
- onCheck: multiClickHandler,
4510
+ onCheck: checkHandler,
4220
4511
  onMousedown: toggleClickFlag,
4221
4512
  onMouseup: toggleClickFlag
4222
4513
  }, {
4223
4514
  default: withCtx(({ node, data }) => [
4224
4515
  createElementVNode("div", {
4516
+ class: "cus-tree-node",
4225
4517
  id: data.id,
4226
- class: normalizeClass(["cus-tree-node", { "cus-tree-node-hover": canHighlight(data) }]),
4227
4518
  onMouseenter: ($event) => unref(highlightHandler)(data)
4228
4519
  }, [
4229
4520
  renderSlot(_ctx.$slots, "layer-node-content", {
@@ -4232,15 +4523,16 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
4232
4523
  }, () => [
4233
4524
  createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
4234
4525
  ])
4235
- ], 42, _hoisted_1$4)
4526
+ ], 40, _hoisted_1$4)
4236
4527
  ]),
4237
4528
  _: 3
4238
- }, 8, ["default-expanded-keys", "data", "show-checkbox"])) : createCommentVNode("", true),
4529
+ }, 8, ["default-expanded-keys", "default-checked-keys", "current-node-key", "data", "highlight-current", "show-checkbox"])) : createCommentVNode("", true),
4239
4530
  (openBlock(), createBlock(Teleport, { to: "body" }, [
4240
- createVNode(_sfc_main$c, {
4531
+ createVNode(_sfc_main$b, {
4241
4532
  ref_key: "menu",
4242
- ref: menu
4243
- }, null, 512)
4533
+ ref: menu,
4534
+ "layer-content-menu": __props.layerContentMenu
4535
+ }, null, 8, ["layer-content-menu"])
4244
4536
  ]))
4245
4537
  ]),
4246
4538
  _: 3
@@ -4253,143 +4545,52 @@ const _hoisted_1$3 = {
4253
4545
  key: 1,
4254
4546
  class: "magic-editor-tab-panel-title"
4255
4547
  };
4256
- const _sfc_main$a = /* @__PURE__ */ defineComponent({
4257
- __name: "TabPane",
4258
- props: {
4259
- data: null
4260
- },
4261
- setup(__props) {
4262
- const props = __props;
4263
- const config = computed(() => {
4264
- if (typeof props.data !== "string") {
4265
- return props.data;
4266
- }
4267
- switch (props.data) {
4268
- case "component-list":
4269
- return {
4270
- type: "component",
4271
- icon: Coin,
4272
- text: "\u7EC4\u4EF6",
4273
- component: _sfc_main$e,
4274
- slots: {}
4275
- };
4276
- case "layer":
4277
- return {
4278
- type: "component",
4279
- icon: Files,
4280
- text: "\u5DF2\u9009\u7EC4\u4EF6",
4281
- component: _sfc_main$b,
4282
- slots: {}
4283
- };
4284
- case "code-block":
4285
- return {
4286
- type: "component",
4287
- icon: EditPen,
4288
- text: "\u4EE3\u7801\u7F16\u8F91",
4289
- component: _sfc_main$f,
4290
- slots: {}
4291
- };
4292
- default:
4293
- return void 0;
4294
- }
4295
- });
4296
- return (_ctx, _cache) => {
4297
- return unref(config) ? (openBlock(), createBlock(unref(TMagicTabPane), {
4298
- key: 0,
4299
- name: unref(config).text
4300
- }, {
4301
- label: withCtx(() => [
4302
- (openBlock(), createElementBlock("div", {
4303
- key: unref(config).text
4304
- }, [
4305
- unref(config).icon ? (openBlock(), createBlock(_sfc_main$o, {
4306
- key: 0,
4307
- icon: unref(config).icon
4308
- }, null, 8, ["icon"])) : createCommentVNode("", true),
4309
- unref(config).text ? (openBlock(), createElementBlock("div", _hoisted_1$3, toDisplayString(unref(config).text), 1)) : createCommentVNode("", true)
4310
- ]))
4311
- ]),
4312
- default: withCtx(() => [
4313
- (openBlock(), createBlock(resolveDynamicComponent(unref(config).component), mergeProps(unref(config).props || {}, toHandlers(unref(config)?.listeners || {})), createSlots({ _: 2 }, [
4314
- __props.data === "component-list" || unref(config).slots?.componentListPanelHeader ? {
4315
- name: "component-list-panel-header",
4316
- fn: withCtx(() => [
4317
- __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)
4318
- ])
4319
- } : void 0,
4320
- __props.data === "component-list" || unref(config).slots?.componentListItem ? {
4321
- name: "component-list-item",
4322
- fn: withCtx(({ component }) => [
4323
- __props.data === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
4324
- key: 0,
4325
- component
4326
- }) : unref(config).slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.componentListItem), {
4327
- key: 1,
4328
- component
4329
- }, null, 8, ["component"])) : createCommentVNode("", true)
4330
- ])
4331
- } : void 0,
4332
- __props.data === "layer" || unref(config).slots?.layerPanelHeader ? {
4333
- name: "layer-panel-header",
4334
- fn: withCtx(() => [
4335
- __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)
4336
- ])
4337
- } : void 0,
4338
- __props.data === "code-block" || unref(config).slots?.codeBlockPanelHeader ? {
4339
- name: "code-block-panel-header",
4340
- fn: withCtx(() => [
4341
- __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)
4342
- ])
4343
- } : void 0,
4344
- __props.data === "code-block" || unref(config).slots?.codeBlockPanelTool ? {
4345
- name: "code-block-panel-tool",
4346
- fn: withCtx(({ id, data }) => [
4347
- data === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
4348
- key: 0,
4349
- id,
4350
- data
4351
- }) : unref(config).slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
4352
- ])
4353
- } : void 0,
4354
- __props.data === "code-block" || unref(config).slots?.codeBlockEditPanelHeader ? {
4355
- name: "code-block-edit-panel-header",
4356
- fn: withCtx(({ id }) => [
4357
- __props.data === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
4358
- key: 0,
4359
- id
4360
- }) : unref(config).slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
4361
- ])
4362
- } : void 0,
4363
- __props.data === "layer" || unref(config).slots?.layerNodeContent ? {
4364
- name: "layer-node-content",
4365
- fn: withCtx(({ data: nodeData, node }) => [
4366
- __props.data === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
4367
- key: 0,
4368
- data: nodeData,
4369
- node
4370
- }) : unref(config).slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).slots.layerNodeContent), {
4371
- key: 1,
4372
- data: nodeData,
4373
- node
4374
- }, null, 8, ["data", "node"])) : createCommentVNode("", true)
4375
- ])
4376
- } : void 0
4377
- ]), 1040))
4378
- ]),
4379
- _: 3
4380
- }, 8, ["name"])) : createCommentVNode("", true);
4381
- };
4382
- }
4548
+ const __default__$8 = defineComponent({
4549
+ name: "MEditorSidebar"
4383
4550
  });
4384
-
4385
4551
  const _sfc_main$9 = /* @__PURE__ */ defineComponent({
4386
- __name: "Sidebar",
4552
+ ...__default__$8,
4387
4553
  props: {
4388
- data: { default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer", "code-block"] }) }
4554
+ data: { default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer", "code-block"] }) },
4555
+ layerContentMenu: null
4389
4556
  },
4390
4557
  setup(__props, { expose }) {
4391
4558
  const props = __props;
4559
+ const uiComponent = getConfig$1("components").tabPane;
4392
4560
  const activeTabName = ref(props.data?.status);
4561
+ const getItemConfig = (data) => {
4562
+ const map = {
4563
+ "component-list": {
4564
+ $key: "component-list",
4565
+ type: "component",
4566
+ icon: Coin,
4567
+ text: "\u7EC4\u4EF6",
4568
+ component: _sfc_main$d,
4569
+ slots: {}
4570
+ },
4571
+ layer: {
4572
+ $key: "layer",
4573
+ type: "component",
4574
+ icon: Files,
4575
+ text: "\u5DF2\u9009\u7EC4\u4EF6",
4576
+ props: {
4577
+ layerContentMenu: props.layerContentMenu
4578
+ },
4579
+ component: _sfc_main$a,
4580
+ slots: {}
4581
+ },
4582
+ "code-block": {
4583
+ $key: "code-block",
4584
+ type: "component",
4585
+ icon: EditPen,
4586
+ text: "\u4EE3\u7801\u7F16\u8F91",
4587
+ component: _sfc_main$e,
4588
+ slots: {}
4589
+ }
4590
+ };
4591
+ return typeof data === "string" ? map[data] : data;
4592
+ };
4593
+ const sideBarItems = computed(() => props.data.items.map((item) => getItemConfig(item)));
4393
4594
  watch(
4394
4595
  () => props.data.status,
4395
4596
  (status) => {
@@ -4409,60 +4610,91 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
4409
4610
  "tab-position": "left"
4410
4611
  }, {
4411
4612
  default: withCtx(() => [
4412
- (openBlock(true), createElementBlock(Fragment, null, renderList(__props.data.items, (item, index) => {
4413
- return openBlock(), createBlock(_sfc_main$a, {
4613
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(sideBarItems), (config, index) => {
4614
+ return openBlock(), createBlock(resolveDynamicComponent(unref(uiComponent).component), {
4414
4615
  key: index,
4415
- data: item
4416
- }, createSlots({ _: 2 }, [
4417
- item === "layer" ? {
4418
- name: "layer-panel-header",
4419
- fn: withCtx(() => [
4420
- renderSlot(_ctx.$slots, "layer-panel-header")
4421
- ])
4422
- } : void 0,
4423
- item === "layer" ? {
4424
- name: "layer-node-content",
4425
- fn: withCtx(({ node, data }) => [
4426
- renderSlot(_ctx.$slots, "layer-node-content", {
4427
- data,
4428
- node
4429
- })
4430
- ])
4431
- } : void 0,
4432
- item === "component-list" ? {
4433
- name: "component-list-panel-header",
4434
- fn: withCtx(() => [
4435
- renderSlot(_ctx.$slots, "component-list-panel-header")
4436
- ])
4437
- } : void 0,
4438
- item === "component-list" ? {
4439
- name: "component-list-item",
4440
- fn: withCtx(({ component }) => [
4441
- renderSlot(_ctx.$slots, "component-list-item", { component })
4442
- ])
4443
- } : void 0,
4444
- item === "code-block" ? {
4445
- name: "code-block-panel-header",
4446
- fn: withCtx(() => [
4447
- renderSlot(_ctx.$slots, "code-block-panel-header")
4448
- ])
4449
- } : void 0,
4450
- item === "code-block" ? {
4451
- name: "code-block-panel-tool",
4452
- fn: withCtx(({ id, data }) => [
4453
- renderSlot(_ctx.$slots, "code-block-panel-tool", {
4454
- id,
4455
- data
4456
- })
4457
- ])
4458
- } : void 0,
4459
- item === "code-block" ? {
4460
- name: "code-block-edit-panel-header",
4461
- fn: withCtx(({ id }) => [
4462
- renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
4463
- ])
4464
- } : void 0
4465
- ]), 1032, ["data"]);
4616
+ name: config.text
4617
+ }, {
4618
+ label: withCtx(() => [
4619
+ (openBlock(), createElementBlock("div", {
4620
+ key: config.text
4621
+ }, [
4622
+ config.icon ? (openBlock(), createBlock(_sfc_main$n, {
4623
+ key: 0,
4624
+ icon: config.icon
4625
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
4626
+ config.text ? (openBlock(), createElementBlock("div", _hoisted_1$3, toDisplayString(config.text), 1)) : createCommentVNode("", true)
4627
+ ]))
4628
+ ]),
4629
+ default: withCtx(() => [
4630
+ config ? (openBlock(), createBlock(resolveDynamicComponent(config.component), mergeProps({ key: 0 }, config.props || {}, toHandlers(config?.listeners || {})), createSlots({ _: 2 }, [
4631
+ config.$key === "component-list" || config.slots?.componentListPanelHeader ? {
4632
+ name: "component-list-panel-header",
4633
+ fn: withCtx(() => [
4634
+ 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)
4635
+ ])
4636
+ } : void 0,
4637
+ config.$key === "component-list" || config.slots?.componentListItem ? {
4638
+ name: "component-list-item",
4639
+ fn: withCtx(({ component }) => [
4640
+ config.$key === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
4641
+ key: 0,
4642
+ component
4643
+ }) : config.slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.componentListItem), {
4644
+ key: 1,
4645
+ component
4646
+ }, null, 8, ["component"])) : createCommentVNode("", true)
4647
+ ])
4648
+ } : void 0,
4649
+ config.$key === "layer" || config.slots?.layerPanelHeader ? {
4650
+ name: "layer-panel-header",
4651
+ fn: withCtx(() => [
4652
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : config.slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
4653
+ ])
4654
+ } : void 0,
4655
+ config.$key === "code-block" || config.slots?.codeBlockPanelHeader ? {
4656
+ name: "code-block-panel-header",
4657
+ fn: withCtx(() => [
4658
+ 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)
4659
+ ])
4660
+ } : void 0,
4661
+ config.$key === "code-block" || config.slots?.codeBlockPanelTool ? {
4662
+ name: "code-block-panel-tool",
4663
+ fn: withCtx(({ id, data }) => [
4664
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
4665
+ key: 0,
4666
+ id,
4667
+ data
4668
+ }) : config.slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
4669
+ ])
4670
+ } : void 0,
4671
+ config.$key === "code-block" || config.slots?.codeBlockEditPanelHeader ? {
4672
+ name: "code-block-edit-panel-header",
4673
+ fn: withCtx(({ id }) => [
4674
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-edit-panel-header", {
4675
+ key: 0,
4676
+ id
4677
+ }) : config.slots?.codeBlockEditPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockEditPanelHeader), { key: 1 })) : createCommentVNode("", true)
4678
+ ])
4679
+ } : void 0,
4680
+ config.$key === "layer" || config.slots?.layerNodeContent ? {
4681
+ name: "layer-node-content",
4682
+ fn: withCtx(({ data: nodeData, node }) => [
4683
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
4684
+ key: 0,
4685
+ data: nodeData,
4686
+ node
4687
+ }) : config.slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerNodeContent), {
4688
+ key: 1,
4689
+ data: nodeData,
4690
+ node
4691
+ }, null, 8, ["data", "node"])) : createCommentVNode("", true)
4692
+ ])
4693
+ } : void 0
4694
+ ]), 1040)) : createCommentVNode("", true)
4695
+ ]),
4696
+ _: 2
4697
+ }, 1032, ["name"]);
4466
4698
  }), 128))
4467
4699
  ]),
4468
4700
  _: 3
@@ -4476,8 +4708,11 @@ const _hoisted_1$2 = {
4476
4708
  class: "m-editor-breadcrumb"
4477
4709
  };
4478
4710
  const _hoisted_2$1 = { key: 0 };
4711
+ const __default__$7 = defineComponent({
4712
+ name: "MEditorBreadcrumb"
4713
+ });
4479
4714
  const _sfc_main$8 = /* @__PURE__ */ defineComponent({
4480
- __name: "Breadcrumb",
4715
+ ...__default__$7,
4481
4716
  setup(__props) {
4482
4717
  const services = inject("services");
4483
4718
  const editorService = services?.editorService;
@@ -4517,8 +4752,11 @@ const _hoisted_1$1 = {
4517
4752
  key: 1,
4518
4753
  style: { "width": "21px" }
4519
4754
  };
4755
+ const __default__$6 = defineComponent({
4756
+ name: "MEditorPageBarScrollContainer"
4757
+ });
4520
4758
  const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4521
- __name: "PageBarScrollContainer",
4759
+ ...__default__$6,
4522
4760
  setup(__props) {
4523
4761
  const services = inject("services");
4524
4762
  const editorService = services?.editorService;
@@ -4599,14 +4837,14 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4599
4837
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4600
4838
  onClick: addPage
4601
4839
  }, [
4602
- createVNode(_sfc_main$o, { icon: unref(Plus) }, null, 8, ["icon"])
4840
+ createVNode(_sfc_main$n, { icon: unref(Plus) }, null, 8, ["icon"])
4603
4841
  ])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
4604
4842
  canScroll.value ? (openBlock(), createElementBlock("div", {
4605
4843
  key: 2,
4606
4844
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4607
4845
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
4608
4846
  }, [
4609
- createVNode(_sfc_main$o, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
4847
+ createVNode(_sfc_main$n, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
4610
4848
  ])) : createCommentVNode("", true),
4611
4849
  unref(pageLength) ? (openBlock(), createElementBlock("div", {
4612
4850
  key: 3,
@@ -4622,7 +4860,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4622
4860
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4623
4861
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
4624
4862
  }, [
4625
- createVNode(_sfc_main$o, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
4863
+ createVNode(_sfc_main$n, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
4626
4864
  ])) : createCommentVNode("", true)
4627
4865
  ], 512);
4628
4866
  };
@@ -4631,8 +4869,11 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4631
4869
 
4632
4870
  const _hoisted_1 = ["onClick"];
4633
4871
  const _hoisted_2 = { class: "m-editor-page-bar-title" };
4872
+ const __default__$5 = defineComponent({
4873
+ name: "MEditorPageBar"
4874
+ });
4634
4875
  const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4635
- __name: "PageBar",
4876
+ ...__default__$5,
4636
4877
  setup(__props) {
4637
4878
  const services = inject("services");
4638
4879
  const editorService = services?.editorService;
@@ -4691,7 +4932,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4691
4932
  default: withCtx(() => [
4692
4933
  createElementVNode("div", null, [
4693
4934
  renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
4694
- createVNode(_sfc_main$j, {
4935
+ createVNode(_sfc_main$k, {
4695
4936
  data: {
4696
4937
  type: "button",
4697
4938
  text: "\u590D\u5236",
@@ -4699,7 +4940,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
4699
4940
  handler: () => copy(item)
4700
4941
  }
4701
4942
  }, null, 8, ["data"]),
4702
- createVNode(_sfc_main$j, {
4943
+ createVNode(_sfc_main$k, {
4703
4944
  data: {
4704
4945
  type: "button",
4705
4946
  text: "\u5220\u9664",
@@ -4733,6 +4974,10 @@ class ScrollViewer extends EventEmitter {
4733
4974
  height = 0;
4734
4975
  translateXCorrectionValue = 0;
4735
4976
  translateYCorrectionValue = 0;
4977
+ correctionScrollSize = {
4978
+ width: 0,
4979
+ height: 0
4980
+ };
4736
4981
  resizeObserver = new ResizeObserver(() => {
4737
4982
  this.setSize();
4738
4983
  this.setScrollSize();
@@ -4742,6 +4987,12 @@ class ScrollViewer extends EventEmitter {
4742
4987
  this.container = options.container;
4743
4988
  this.target = options.target;
4744
4989
  this.zoom = options.zoom;
4990
+ if (this.correctionScrollSize) {
4991
+ this.correctionScrollSize = {
4992
+ ...this.correctionScrollSize,
4993
+ ...options.correctionScrollSize
4994
+ };
4995
+ }
4745
4996
  this.container.addEventListener("wheel", this.wheelHandler, false);
4746
4997
  this.setSize();
4747
4998
  this.setScrollSize();
@@ -4804,9 +5055,9 @@ class ScrollViewer extends EventEmitter {
4804
5055
  }
4805
5056
  setScrollSize = () => {
4806
5057
  const targetRect = this.target.getBoundingClientRect();
4807
- this.scrollWidth = targetRect.width * this.zoom + 100;
5058
+ this.scrollWidth = targetRect.width * this.zoom + this.correctionScrollSize.width;
4808
5059
  const targetMarginTop = Number(this.target.style.marginTop) || 0;
4809
- this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + 100;
5060
+ this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + this.correctionScrollSize.height;
4810
5061
  let left;
4811
5062
  let top;
4812
5063
  if (this.scrollWidth < this.width) {
@@ -4839,8 +5090,11 @@ class ScrollViewer extends EventEmitter {
4839
5090
  };
4840
5091
  }
4841
5092
 
5093
+ const __default__$4 = defineComponent({
5094
+ name: "MEditorScrollBar"
5095
+ });
4842
5096
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
4843
- __name: "ScrollBar",
5097
+ ...__default__$4,
4844
5098
  props: {
4845
5099
  size: null,
4846
5100
  scrollSize: null,
@@ -4925,14 +5179,21 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
4925
5179
 
4926
5180
  const ScrollBar_vue_vue_type_style_index_0_lang = '';
4927
5181
 
5182
+ const __default__$3 = defineComponent({
5183
+ name: "MEditorScrollViewer"
5184
+ });
4928
5185
  const _sfc_main$4 = /* @__PURE__ */ defineComponent({
4929
- __name: "ScrollViewer",
5186
+ ...__default__$3,
4930
5187
  props: {
4931
5188
  width: { default: 0 },
4932
5189
  height: { default: 0 },
4933
5190
  wrapWidth: { default: 0 },
4934
5191
  wrapHeight: { default: 0 },
4935
- zoom: { default: 1 }
5192
+ zoom: { default: 1 },
5193
+ correctionScrollSize: { default: () => ({
5194
+ width: 0,
5195
+ height: 0
5196
+ }) }
4936
5197
  },
4937
5198
  setup(__props, { expose }) {
4938
5199
  const props = __props;
@@ -4955,7 +5216,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
4955
5216
  scrollViewer = new ScrollViewer({
4956
5217
  container: container.value,
4957
5218
  target: el.value,
4958
- zoom: props.zoom
5219
+ zoom: props.zoom,
5220
+ correctionScrollSize: props.correctionScrollSize
4959
5221
  });
4960
5222
  scrollViewer.on("scroll", (data) => {
4961
5223
  hOffset.value = data.scrollLeft;
@@ -5023,10 +5285,14 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
5023
5285
  }
5024
5286
  });
5025
5287
 
5288
+ const __default__$2 = defineComponent({
5289
+ name: "MEditorViewerMenu"
5290
+ });
5026
5291
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5027
- __name: "ViewerMenu",
5292
+ ...__default__$2,
5028
5293
  props: {
5029
- isMultiSelect: { type: Boolean, default: false }
5294
+ isMultiSelect: { type: Boolean, default: false },
5295
+ stageContentMenu: null
5030
5296
  },
5031
5297
  setup(__props, { expose }) {
5032
5298
  const props = __props;
@@ -5039,8 +5305,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5039
5305
  const nodes = computed(() => editorService?.get("nodes"));
5040
5306
  const parent = computed(() => editorService?.get("parent"));
5041
5307
  const stage = computed(() => editorService?.get("stage"));
5042
- const stageContentMenu = inject("stageContentMenu", []);
5043
- const menuData = reactive([
5308
+ const menuData = computed(() => [
5044
5309
  {
5045
5310
  type: "button",
5046
5311
  text: "\u6C34\u5E73\u5C45\u4E2D",
@@ -5054,7 +5319,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5054
5319
  {
5055
5320
  type: "button",
5056
5321
  text: "\u590D\u5236",
5057
- icon: markRaw(DocumentCopy),
5322
+ icon: markRaw(CopyDocument),
5058
5323
  handler: () => {
5059
5324
  nodes.value && editorService?.copy(nodes.value);
5060
5325
  canPaste.value = true;
@@ -5063,6 +5328,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5063
5328
  {
5064
5329
  type: "button",
5065
5330
  text: "\u7C98\u8D34",
5331
+ icon: markRaw(DocumentCopy),
5066
5332
  display: () => canPaste.value,
5067
5333
  handler: () => {
5068
5334
  const rect = menu.value?.$el.getBoundingClientRect();
@@ -5142,7 +5408,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5142
5408
  editorService?.get("stage").clearGuides();
5143
5409
  }
5144
5410
  },
5145
- ...stageContentMenu
5411
+ ...props.stageContentMenu
5146
5412
  ]);
5147
5413
  watch(
5148
5414
  parent,
@@ -5165,8 +5431,8 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5165
5431
  };
5166
5432
  expose({ show });
5167
5433
  return (_ctx, _cache) => {
5168
- return openBlock(), createBlock(_sfc_main$d, {
5169
- "menu-data": menuData,
5434
+ return openBlock(), createBlock(_sfc_main$c, {
5435
+ "menu-data": unref(menuData),
5170
5436
  ref_key: "menu",
5171
5437
  ref: menu
5172
5438
  }, null, 8, ["menu-data"]);
@@ -5174,8 +5440,14 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
5174
5440
  }
5175
5441
  });
5176
5442
 
5443
+ const __default__$1 = defineComponent({
5444
+ name: "MEditorStage"
5445
+ });
5177
5446
  const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5178
- __name: "Stage",
5447
+ ...__default__$1,
5448
+ props: {
5449
+ stageContentMenu: null
5450
+ },
5179
5451
  setup(__props) {
5180
5452
  let stage = null;
5181
5453
  let runtime = null;
@@ -5192,7 +5464,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5192
5464
  const zoom = computed(() => services?.uiService.get("zoom") || 1);
5193
5465
  const node = computed(() => services?.editorService.get("node"));
5194
5466
  watchEffect(() => {
5195
- if (stage)
5467
+ if (stage || !page.value)
5196
5468
  return;
5197
5469
  if (!stageContainer.value)
5198
5470
  return;
@@ -5222,6 +5494,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5222
5494
  runtime.updateRootConfig?.(cloneDeep(toRaw(root2)));
5223
5495
  }
5224
5496
  });
5497
+ watch(page, (page2) => {
5498
+ if (runtime && page2) {
5499
+ runtime.updatePageId?.(page2.id);
5500
+ nextTick(() => {
5501
+ stage?.select(page2.id);
5502
+ });
5503
+ }
5504
+ });
5225
5505
  const resizeObserver = new ResizeObserver((entries) => {
5226
5506
  for (const { contentRect } of entries) {
5227
5507
  services?.uiService.set("stageContainerRect", {
@@ -5294,7 +5574,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5294
5574
  height: unref(stageRect)?.height,
5295
5575
  "wrap-width": unref(stageContainerRect)?.width,
5296
5576
  "wrap-height": unref(stageContainerRect)?.height,
5297
- zoom: unref(zoom)
5577
+ zoom: unref(zoom),
5578
+ "correction-scroll-size": {
5579
+ width: 60,
5580
+ height: 50
5581
+ }
5298
5582
  }, {
5299
5583
  default: withCtx(() => [
5300
5584
  createElementVNode("div", {
@@ -5310,8 +5594,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5310
5594
  createVNode(_sfc_main$3, {
5311
5595
  ref_key: "menu",
5312
5596
  ref: menu,
5313
- "is-multi-select": unref(isMultiSelect)
5314
- }, null, 8, ["is-multi-select"])
5597
+ "is-multi-select": unref(isMultiSelect),
5598
+ "stage-content-menu": __props.stageContentMenu
5599
+ }, null, 8, ["is-multi-select", "stage-content-menu"])
5315
5600
  ]))
5316
5601
  ]),
5317
5602
  _: 1
@@ -5320,8 +5605,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5320
5605
  }
5321
5606
  });
5322
5607
 
5608
+ const __default__ = defineComponent({
5609
+ name: "MEditorWorkspace"
5610
+ });
5323
5611
  const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5324
- __name: "Workspace",
5612
+ ...__default__,
5613
+ props: {
5614
+ stageContentMenu: null
5615
+ },
5325
5616
  setup(__props) {
5326
5617
  const services = inject("services");
5327
5618
  const workspace = ref();
@@ -5432,9 +5723,10 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5432
5723
  }, [
5433
5724
  createVNode(_sfc_main$8),
5434
5725
  renderSlot(_ctx.$slots, "stage", {}, () => [
5435
- (openBlock(), createBlock(_sfc_main$2, {
5436
- key: unref(page)?.id
5437
- }))
5726
+ unref(page) ? (openBlock(), createBlock(_sfc_main$2, {
5727
+ key: 0,
5728
+ "stage-content-menu": __props.stageContentMenu
5729
+ }, null, 8, ["stage-content-menu"])) : createCommentVNode("", true)
5438
5730
  ]),
5439
5731
  renderSlot(_ctx.$slots, "workspace-content"),
5440
5732
  createVNode(_sfc_main$6, null, {
@@ -5464,9 +5756,13 @@ class ComponentList extends BaseService {
5464
5756
  getList() {
5465
5757
  return this.state.list;
5466
5758
  }
5467
- destroy() {
5759
+ resetState() {
5468
5760
  this.state.list = [];
5761
+ }
5762
+ destroy() {
5763
+ this.resetState();
5469
5764
  this.removeAllListeners();
5765
+ this.removeAllPlugins();
5470
5766
  }
5471
5767
  }
5472
5768
  const componentListService = new ComponentList();
@@ -5474,11 +5770,11 @@ const componentListService = new ComponentList();
5474
5770
  const _sfc_main = defineComponent({
5475
5771
  name: "m-editor",
5476
5772
  components: {
5477
- NavMenu: _sfc_main$i,
5773
+ TMagicNavMenu: _sfc_main$j,
5478
5774
  Sidebar: _sfc_main$9,
5479
5775
  Workspace: _sfc_main$1,
5480
- PropsPanel: _sfc_main$h,
5481
- Framework: _sfc_main$k
5776
+ PropsPanel: _sfc_main$i,
5777
+ Framework: _sfc_main$l
5482
5778
  },
5483
5779
  props: {
5484
5780
  modelValue: {
@@ -5493,6 +5789,10 @@ const _sfc_main = defineComponent({
5493
5789
  sidebar: {
5494
5790
  type: Object
5495
5791
  },
5792
+ menu: {
5793
+ type: Object,
5794
+ default: () => ({ left: [], right: [] })
5795
+ },
5496
5796
  layerContentMenu: {
5497
5797
  type: Array,
5498
5798
  default: () => []
@@ -5501,10 +5801,6 @@ const _sfc_main = defineComponent({
5501
5801
  type: Array,
5502
5802
  default: () => []
5503
5803
  },
5504
- menu: {
5505
- type: Object,
5506
- default: () => ({ left: [], right: [] })
5507
- },
5508
5804
  render: {
5509
5805
  type: Function
5510
5806
  },
@@ -5538,7 +5834,7 @@ const _sfc_main = defineComponent({
5538
5834
  },
5539
5835
  containerHighlightClassName: {
5540
5836
  type: String,
5541
- default: CONTAINER_HIGHLIGHT_CLASS
5837
+ default: CONTAINER_HIGHLIGHT_CLASS_NAME
5542
5838
  },
5543
5839
  containerHighlightDuration: {
5544
5840
  type: Number,
@@ -5557,20 +5853,33 @@ const _sfc_main = defineComponent({
5557
5853
  },
5558
5854
  updateDragEl: {
5559
5855
  type: Function
5856
+ },
5857
+ disabledDragStart: {
5858
+ type: Boolean
5560
5859
  }
5561
5860
  },
5562
5861
  emits: ["props-panel-mounted", "update:modelValue"],
5563
5862
  setup(props, { emit }) {
5564
- editorService.on("root-change", (value) => {
5565
- const node = editorService.get("node");
5566
- const nodeId = node?.id || props.defaultSelected;
5567
- if (nodeId && node !== value) {
5568
- editorService.select(nodeId);
5569
- } else {
5863
+ const rootChangeHandler = (value, preValue) => {
5864
+ const nodeId = editorService.get("node")?.id || props.defaultSelected;
5865
+ let node;
5866
+ if (nodeId) {
5867
+ node = editorService.getNodeById(nodeId);
5868
+ }
5869
+ if (node && node !== value) {
5870
+ editorService.select(node.id);
5871
+ } else if (value?.items?.length) {
5872
+ editorService.select(value.items[0]);
5873
+ } else if (value?.id) {
5570
5874
  editorService.set("nodes", [value]);
5875
+ editorService.set("parent", null);
5876
+ editorService.set("page", null);
5571
5877
  }
5572
- emit("update:modelValue", toRaw(editorService.get("root")));
5573
- });
5878
+ if (toRaw(value) !== toRaw(preValue)) {
5879
+ emit("update:modelValue", value);
5880
+ }
5881
+ };
5882
+ editorService.on("root-change", rootChangeHandler);
5574
5883
  watch(
5575
5884
  () => props.modelValue,
5576
5885
  (modelValue) => {
@@ -5632,13 +5941,13 @@ const _sfc_main = defineComponent({
5632
5941
  }
5633
5942
  );
5634
5943
  onUnmounted(() => {
5635
- editorService.destroy();
5636
- historyService.destroy();
5637
- propsService.destroy();
5638
- uiService.destroy();
5639
- componentListService.destroy();
5640
- storageService.destroy();
5641
- codeBlockService.destroy();
5944
+ editorService.resetState();
5945
+ historyService.resetState();
5946
+ propsService.resetState();
5947
+ uiService.resetState();
5948
+ componentListService.resetState();
5949
+ codeBlockService.resetState();
5950
+ editorService.off("root-change", rootChangeHandler);
5642
5951
  });
5643
5952
  const services = {
5644
5953
  componentListService,
@@ -5651,8 +5960,7 @@ const _sfc_main = defineComponent({
5651
5960
  codeBlockService
5652
5961
  };
5653
5962
  provide("services", services);
5654
- provide("layerContentMenu", props.layerContentMenu);
5655
- provide("stageContentMenu", props.stageContentMenu);
5963
+ provide("codeOptions", props.codeOptions);
5656
5964
  provide(
5657
5965
  "stageOptions",
5658
5966
  reactive({
@@ -5665,7 +5973,8 @@ const _sfc_main = defineComponent({
5665
5973
  isContainer: props.isContainer,
5666
5974
  containerHighlightClassName: props.containerHighlightClassName,
5667
5975
  containerHighlightDuration: props.containerHighlightDuration,
5668
- containerHighlightType: props.containerHighlightType
5976
+ containerHighlightType: props.containerHighlightType,
5977
+ disabledDragStart: props.disabledDragStart
5669
5978
  })
5670
5979
  );
5671
5980
  return services;
@@ -5681,20 +5990,23 @@ const _export_sfc = (sfc, props) => {
5681
5990
  };
5682
5991
 
5683
5992
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5684
- const _component_nav_menu = resolveComponent("nav-menu");
5685
- const _component_sidebar = resolveComponent("sidebar");
5686
- const _component_workspace = resolveComponent("workspace");
5687
- const _component_props_panel = resolveComponent("props-panel");
5688
- const _component_framework = resolveComponent("framework");
5689
- return openBlock(), createBlock(_component_framework, { "code-options": _ctx.codeOptions }, {
5993
+ const _component_TMagicNavMenu = resolveComponent("TMagicNavMenu");
5994
+ const _component_Sidebar = resolveComponent("Sidebar");
5995
+ const _component_Workspace = resolveComponent("Workspace");
5996
+ const _component_PropsPanel = resolveComponent("PropsPanel");
5997
+ const _component_Framework = resolveComponent("Framework");
5998
+ return openBlock(), createBlock(_component_Framework, { "code-options": _ctx.codeOptions }, {
5690
5999
  nav: withCtx(() => [
5691
6000
  renderSlot(_ctx.$slots, "nav", { editorService: _ctx.editorService }, () => [
5692
- createVNode(_component_nav_menu, { data: _ctx.menu }, null, 8, ["data"])
6001
+ createVNode(_component_TMagicNavMenu, { data: _ctx.menu }, null, 8, ["data"])
5693
6002
  ])
5694
6003
  ]),
5695
6004
  sidebar: withCtx(() => [
5696
6005
  renderSlot(_ctx.$slots, "sidebar", { editorService: _ctx.editorService }, () => [
5697
- createVNode(_component_sidebar, { data: _ctx.sidebar }, {
6006
+ createVNode(_component_Sidebar, {
6007
+ data: _ctx.sidebar,
6008
+ "layer-content-menu": _ctx.layerContentMenu
6009
+ }, {
5698
6010
  "layer-panel-header": withCtx(() => [
5699
6011
  renderSlot(_ctx.$slots, "layer-panel-header")
5700
6012
  ]),
@@ -5723,12 +6035,12 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5723
6035
  renderSlot(_ctx.$slots, "code-block-edit-panel-header", { id })
5724
6036
  ]),
5725
6037
  _: 3
5726
- }, 8, ["data"])
6038
+ }, 8, ["data", "layer-content-menu"])
5727
6039
  ])
5728
6040
  ]),
5729
6041
  workspace: withCtx(() => [
5730
6042
  renderSlot(_ctx.$slots, "workspace", { editorService: _ctx.editorService }, () => [
5731
- createVNode(_component_workspace, null, {
6043
+ createVNode(_component_Workspace, { "stage-content-menu": _ctx.stageContentMenu }, {
5732
6044
  stage: withCtx(() => [
5733
6045
  renderSlot(_ctx.$slots, "stage")
5734
6046
  ]),
@@ -5742,12 +6054,12 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5742
6054
  renderSlot(_ctx.$slots, "page-bar-popover", { page })
5743
6055
  ]),
5744
6056
  _: 3
5745
- })
6057
+ }, 8, ["stage-content-menu"])
5746
6058
  ])
5747
6059
  ]),
5748
6060
  "props-panel": withCtx(() => [
5749
6061
  renderSlot(_ctx.$slots, "props-panel", {}, () => [
5750
- createVNode(_component_props_panel, {
6062
+ createVNode(_component_PropsPanel, {
5751
6063
  onMounted: _cache[0] || (_cache[0] = (instance) => _ctx.$emit("props-panel-mounted", instance))
5752
6064
  }, {
5753
6065
  "props-panel-header": withCtx(() => [
@@ -5774,13 +6086,13 @@ const index = {
5774
6086
  app.config.globalProperties.$TMAGIC_EDITOR = option;
5775
6087
  setConfig(option);
5776
6088
  app.component(Editor.name, Editor);
5777
- app.component("m-fields-ui-select", _sfc_main$q);
5778
- app.component("m-fields-code-link", _sfc_main$s);
5779
- app.component("m-fields-vs-code", _sfc_main$t);
5780
- app.component("magic-code-editor", _sfc_main$p);
5781
- app.component("m-fields-code-select", _sfc_main$r);
6089
+ app.component("m-fields-ui-select", _sfc_main$r);
6090
+ app.component("m-fields-code-link", _sfc_main$t);
6091
+ app.component("m-fields-vs-code", _sfc_main$u);
6092
+ app.component("magic-code-editor", _sfc_main$q);
6093
+ app.component("m-fields-code-select", _sfc_main$s);
5782
6094
  }
5783
6095
  };
5784
6096
 
5785
- export { COPY_STORAGE_KEY, _sfc_main$f as CodeBlockList, CodeDeleteErrorType, CodeEditorMode, _sfc_main$r as CodeSelect, CodeSelectOp, ColumnLayout, _sfc_main$e as ComponentListPanel, _sfc_main$d as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$o as Icon, Keys, LayerOffset, _sfc_main$b as LayerPanel, Layout, _sfc_main$h as PropsPanel, _sfc_main$p as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$j as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, codeBlockService, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, useStage, warn };
5786
- //# sourceMappingURL=tmagic-editor.mjs.map
6097
+ 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 };
6098
+ //# sourceMappingURL=tmagic-editor.js.map