@tmagic/editor 1.0.0-beta.13 → 1.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/coverage/clover.xml +703 -601
  2. package/coverage/coverage-final.json +35 -33
  3. package/coverage/lcov-report/index.html +56 -56
  4. package/coverage/lcov-report/src/Editor.vue.html +1 -1
  5. package/coverage/lcov-report/{layouts/sidebar/LayerMenu.vue.html → src/components/ContentMenu.vue.html} +137 -95
  6. package/coverage/lcov-report/src/components/Icon.vue.html +5 -5
  7. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +1 -1
  8. package/coverage/lcov-report/src/components/ToolButton.vue.html +180 -63
  9. package/coverage/lcov-report/src/components/index.html +34 -19
  10. package/coverage/lcov-report/src/index.html +1 -1
  11. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +1 -1
  12. package/coverage/lcov-report/src/layouts/Framework.vue.html +13 -13
  13. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +1 -1
  14. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +1 -1
  15. package/coverage/lcov-report/src/layouts/Resizer.vue.html +1 -1
  16. package/coverage/lcov-report/src/layouts/index.html +15 -15
  17. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +78 -12
  18. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +149 -92
  19. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +43 -121
  20. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +23 -140
  21. package/coverage/lcov-report/{utils/undo-redo.ts.html → src/layouts/sidebar/TabPane.vue.html} +94 -118
  22. package/coverage/lcov-report/src/layouts/sidebar/index.html +64 -49
  23. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +99 -12
  24. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +86 -95
  25. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +208 -97
  26. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +3 -3
  27. package/coverage/lcov-report/src/layouts/workspace/index.html +35 -35
  28. package/coverage/lcov-report/src/services/BaseService.ts.html +11 -11
  29. package/coverage/lcov-report/src/services/componentList.ts.html +1 -1
  30. package/coverage/lcov-report/src/services/editor.ts.html +103 -10
  31. package/coverage/lcov-report/src/services/events.ts.html +1 -1
  32. package/coverage/lcov-report/src/services/history.ts.html +29 -8
  33. package/coverage/lcov-report/src/services/index.html +25 -25
  34. package/coverage/lcov-report/src/services/props.ts.html +4 -7
  35. package/coverage/lcov-report/src/services/ui.ts.html +1 -1
  36. package/coverage/lcov-report/src/type.ts.html +8 -14
  37. package/coverage/lcov-report/src/utils/compose.ts.html +4 -4
  38. package/coverage/lcov-report/src/utils/config.ts.html +1 -1
  39. package/coverage/lcov-report/src/utils/editor.ts.html +2 -2
  40. package/coverage/lcov-report/src/utils/index.html +1 -1
  41. package/coverage/lcov-report/src/utils/index.ts.html +1 -1
  42. package/coverage/lcov-report/src/utils/logger.ts.html +1 -1
  43. package/coverage/lcov-report/src/utils/props.ts.html +59 -2
  44. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +1 -1
  45. package/coverage/lcov-report/src/utils/undo-redo.ts.html +1 -1
  46. package/coverage/lcov.info +1679 -1402
  47. package/dist/style.css +47 -20
  48. package/dist/tmagic-editor.es.js +732 -485
  49. package/dist/tmagic-editor.es.js.map +1 -1
  50. package/dist/tmagic-editor.umd.js +733 -485
  51. package/dist/tmagic-editor.umd.js.map +1 -1
  52. package/dist/types/src/Editor.vue.d.ts +1 -1
  53. package/dist/types/src/components/ToolButton.vue.d.ts +12 -1
  54. package/dist/types/src/fields/UISelect.vue.d.ts +4 -1
  55. package/dist/types/src/index.d.ts +1 -0
  56. package/dist/types/src/layouts/CodeEditor.vue.d.ts +13 -4
  57. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +1 -0
  58. package/dist/types/src/layouts/sidebar/Sidebar.vue.d.ts +2 -3
  59. package/dist/types/src/layouts/sidebar/TabPane.vue.d.ts +14 -0
  60. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +2 -0
  61. package/dist/types/src/services/history.d.ts +1 -0
  62. package/dist/types/src/services/props.d.ts +2 -2
  63. package/dist/types/src/type.d.ts +6 -8
  64. package/dist/types/src/utils/polyfills.d.ts +0 -0
  65. package/package.json +15 -10
  66. package/src/components/ContentMenu.vue +107 -0
  67. package/src/components/ToolButton.vue +66 -27
  68. package/src/fields/UISelect.vue +14 -6
  69. package/src/index.ts +2 -0
  70. package/src/layouts/CodeEditor.vue +20 -10
  71. package/src/layouts/Framework.vue +6 -6
  72. package/src/layouts/sidebar/ComponentListPanel.vue +23 -1
  73. package/src/layouts/sidebar/LayerMenu.vue +91 -72
  74. package/src/layouts/sidebar/LayerPanel.vue +23 -49
  75. package/src/layouts/sidebar/Sidebar.vue +13 -52
  76. package/src/layouts/sidebar/TabPane.vue +68 -0
  77. package/src/layouts/workspace/PageBar.vue +35 -6
  78. package/src/layouts/workspace/Stage.vue +41 -44
  79. package/src/layouts/workspace/ViewerMenu.vue +104 -67
  80. package/src/layouts/workspace/Workspace.vue +2 -2
  81. package/src/services/editor.ts +33 -2
  82. package/src/services/history.ts +7 -0
  83. package/src/services/props.ts +2 -3
  84. package/src/theme/common/var.scss +1 -0
  85. package/src/theme/component-list-panel.scss +2 -0
  86. package/src/theme/content-menu.scss +33 -26
  87. package/src/theme/layer-panel.scss +1 -1
  88. package/src/theme/nav-menu.scss +6 -2
  89. package/src/theme/page-bar.scss +22 -1
  90. package/src/theme/props-panel.scss +4 -0
  91. package/src/type.ts +6 -8
  92. package/src/utils/editor.ts +1 -1
  93. package/src/utils/polyfills.ts +22 -0
  94. package/src/utils/props.ts +19 -0
  95. package/coverage/lcov-report/Icon.vue.html +0 -172
  96. package/coverage/lcov-report/ToolButton.vue.html +0 -655
  97. package/coverage/lcov-report/layouts/sidebar/index.html +0 -116
  98. package/coverage/lcov-report/utils/index.html +0 -116
  99. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +0 -980
  100. package/dist/types/src/layouts/workspace/Stage.vue.d.ts +0 -188
  101. package/dist/types/src/layouts/workspace/ViewerMenu.vue.d.ts +0 -18
@@ -1,9 +1,9 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, createElementBlock, createElementVNode, toDisplayString, withModifiers, createCommentVNode, watch, onMounted, onUnmounted, reactive, toRaw, createVNode, withCtx, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, createTextVNode, normalizeProps, mergeProps, getCurrentInstance, withDirectives, vShow, Teleport, toHandlers, createSlots, markRaw, provide } from 'vue';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, markRaw, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, normalizeProps, mergeProps, getCurrentInstance, nextTick, withDirectives, Teleport, vShow, toHandlers, createSlots, provide } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
+ import { Delete, Pointer, Close, Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons';
4
+ import { throttle, cloneDeep, mergeWith, random } from 'lodash-es';
3
5
  import * as monaco from 'monaco-editor';
4
- import { Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Delete, Files, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom } from '@element-plus/icons';
5
6
  import { NodeType } from '@tmagic/schema';
6
- import { cloneDeep, random, mergeWith, throttle } from 'lodash-es';
7
7
  import { toLine, isPop, getNodePath, isNumber, isPage } from '@tmagic/utils';
8
8
  import { EventEmitter as EventEmitter$2 } from 'events';
9
9
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
@@ -11,6 +11,10 @@ import { ElMessage } from 'element-plus';
11
11
  import KeyController from 'keycon';
12
12
  import StageCore from '@tmagic/stage';
13
13
 
14
+ if (typeof window.global === "undefined") {
15
+ window.global = window;
16
+ }
17
+
14
18
  var _export_sfc = (sfc, props) => {
15
19
  const target = sfc.__vccOpts || sfc;
16
20
  for (const [key, val] of props) {
@@ -19,7 +23,7 @@ var _export_sfc = (sfc, props) => {
19
23
  return target;
20
24
  };
21
25
 
22
- const _sfc_main$k = defineComponent({
26
+ const _sfc_main$m = defineComponent({
23
27
  name: "m-fields-vs-code",
24
28
  props: ["model", "name", "config", "prop"],
25
29
  emits: ["change"],
@@ -36,7 +40,7 @@ const _sfc_main$k = defineComponent({
36
40
  };
37
41
  }
38
42
  });
39
- function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
43
+ function _sfc_render$m(_ctx, _cache, $props, $setup, $data, $options) {
40
44
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
41
45
  return openBlock(), createBlock(_component_magic_code_editor, {
42
46
  style: normalizeStyle(`height: ${_ctx.height}`),
@@ -45,9 +49,9 @@ function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
45
49
  onSave: _ctx.save
46
50
  }, null, 8, ["style", "init-values", "language", "onSave"]);
47
51
  }
48
- var Code = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$k]]);
52
+ var Code = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$m]]);
49
53
 
50
- const _sfc_main$j = defineComponent({
54
+ const _sfc_main$l = defineComponent({
51
55
  name: "m-fields-code-link",
52
56
  props: {
53
57
  config: {
@@ -102,7 +106,7 @@ const _sfc_main$j = defineComponent({
102
106
  };
103
107
  }
104
108
  });
105
- function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
109
+ function _sfc_render$l(_ctx, _cache, $props, $setup, $data, $options) {
106
110
  const _component_m_fields_link = resolveComponent("m-fields-link");
107
111
  return openBlock(), createBlock(_component_m_fields_link, {
108
112
  config: _ctx.formConfig,
@@ -111,11 +115,11 @@ function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
111
115
  onChange: _ctx.changeHandler
112
116
  }, null, 8, ["config", "model", "onChange"]);
113
117
  }
114
- var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
118
+ var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$l]]);
115
119
 
116
120
  var UISelect_vue_vue_type_style_index_0_lang = '';
117
121
 
118
- const _sfc_main$i = defineComponent({
122
+ const _sfc_main$k = defineComponent({
119
123
  name: "m-fields-ui-select",
120
124
  props: {
121
125
  labelWidth: String,
@@ -153,6 +157,9 @@ const _sfc_main$i = defineComponent({
153
157
  }
154
158
  };
155
159
  return {
160
+ Delete: markRaw(Delete),
161
+ Pointer: markRaw(Pointer),
162
+ Close: markRaw(Close),
156
163
  val,
157
164
  uiSelectMode,
158
165
  toName: computed(() => {
@@ -177,34 +184,64 @@ const _sfc_main$i = defineComponent({
177
184
  };
178
185
  }
179
186
  });
180
- const _hoisted_1$e = /* @__PURE__ */ createElementVNode("i", {
181
- class: "el-icon-delete",
182
- style: { "color": "rgb(221, 75, 57)" }
183
- }, "\u53D6\u6D88", -1);
184
- const _hoisted_2$7 = [
185
- _hoisted_1$e
186
- ];
187
- const _hoisted_3$5 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-thumb" }, null, -1);
188
- function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
187
+ const _hoisted_1$c = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
188
+ function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
189
+ const _component_el_button = resolveComponent("el-button");
190
+ const _component_el_tooltip = resolveComponent("el-tooltip");
189
191
  return _ctx.uiSelectMode ? (openBlock(), createElementBlock("div", {
190
192
  key: 0,
191
193
  class: "m-fields-ui-select",
192
194
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.cancelHandler && _ctx.cancelHandler(...args))
193
- }, _hoisted_2$7)) : (openBlock(), createElementBlock("div", {
195
+ }, [
196
+ createVNode(_component_el_button, {
197
+ type: "danger",
198
+ icon: _ctx.Delete,
199
+ text: "",
200
+ style: { "padding": "0" }
201
+ }, {
202
+ default: withCtx(() => [
203
+ _hoisted_1$c
204
+ ]),
205
+ _: 1
206
+ }, 8, ["icon"])
207
+ ])) : (openBlock(), createElementBlock("div", {
194
208
  key: 1,
195
209
  class: "m-fields-ui-select",
196
- onClick: _cache[2] || (_cache[2] = (...args) => _ctx.startSelect && _ctx.startSelect(...args))
210
+ onClick: _cache[1] || (_cache[1] = (...args) => _ctx.startSelect && _ctx.startSelect(...args)),
211
+ style: { "display": "flex" }
197
212
  }, [
198
- _hoisted_3$5,
199
- createElementVNode("span", null, toDisplayString(_ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1),
200
- _ctx.val ? (openBlock(), createElementBlock("i", {
201
- key: 0,
202
- class: "el-icon-delete",
203
- onClick: _cache[1] || (_cache[1] = withModifiers((...args) => _ctx.deleteHandler && _ctx.deleteHandler(...args), ["stop"]))
204
- })) : createCommentVNode("", true)
213
+ createVNode(_component_el_tooltip, { content: "\u6E05\u9664" }, {
214
+ default: withCtx(() => [
215
+ _ctx.val ? (openBlock(), createBlock(_component_el_button, {
216
+ key: 0,
217
+ style: { "padding": "0" },
218
+ type: "danger",
219
+ icon: _ctx.Close,
220
+ text: "",
221
+ onClick: withModifiers(_ctx.deleteHandler, ["stop"])
222
+ }, null, 8, ["icon", "onClick"])) : createCommentVNode("", true)
223
+ ]),
224
+ _: 1
225
+ }),
226
+ createVNode(_component_el_tooltip, {
227
+ content: _ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"
228
+ }, {
229
+ default: withCtx(() => [
230
+ createVNode(_component_el_button, {
231
+ text: "",
232
+ style: { "padding": "0", "margin": "0" }
233
+ }, {
234
+ default: withCtx(() => [
235
+ createTextVNode(toDisplayString(_ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1)
236
+ ]),
237
+ _: 1
238
+ })
239
+ ]),
240
+ _: 1
241
+ }, 8, ["content"])
205
242
  ]));
206
243
  }
207
- var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
244
+ var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$k]]);
208
245
 
209
246
  const toString = (v, language) => {
210
247
  let value = "";
@@ -221,7 +258,7 @@ const toString = (v, language) => {
221
258
  }
222
259
  return value;
223
260
  };
224
- const _sfc_main$h = defineComponent({
261
+ const _sfc_main$j = defineComponent({
225
262
  name: "magic-code-editor",
226
263
  props: {
227
264
  initValues: {
@@ -231,12 +268,16 @@ const _sfc_main$h = defineComponent({
231
268
  type: [String, Object]
232
269
  },
233
270
  type: {
234
- type: [String],
271
+ type: String,
235
272
  default: () => ""
236
273
  },
237
274
  language: {
238
- type: [String],
275
+ type: String,
239
276
  default: () => "javascript"
277
+ },
278
+ options: {
279
+ type: Object,
280
+ default: () => ({})
240
281
  }
241
282
  },
242
283
  emits: ["initd", "save"],
@@ -246,6 +287,10 @@ const _sfc_main$h = defineComponent({
246
287
  const values = ref("");
247
288
  const loading = ref(false);
248
289
  const codeEditor = ref();
290
+ const resizeObserver = new globalThis.ResizeObserver(throttle(() => {
291
+ vsEditor?.layout();
292
+ vsDiffEditor?.layout();
293
+ }, 300));
249
294
  const setEditorValue = (v, m) => {
250
295
  values.value = toString(v, props.language);
251
296
  if (props.type === "diff") {
@@ -258,10 +303,6 @@ const _sfc_main$h = defineComponent({
258
303
  }
259
304
  return vsEditor?.setValue(values.value);
260
305
  };
261
- const resizeHandler = () => {
262
- vsEditor?.layout();
263
- vsDiffEditor?.layout();
264
- };
265
306
  const getEditorValue = () => props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
266
307
  const init = async () => {
267
308
  if (!codeEditor.value)
@@ -272,8 +313,9 @@ const _sfc_main$h = defineComponent({
272
313
  tabSize: 2,
273
314
  theme: "vs-dark",
274
315
  fontFamily: 'dm, Menlo, Monaco, "Courier New", monospace',
275
- fontSize: 15,
276
- formatOnPaste: true
316
+ fontSize: 14,
317
+ formatOnPaste: true,
318
+ ...props.options
277
319
  };
278
320
  if (props.type === "diff") {
279
321
  vsDiffEditor = monaco.editor.createDiffEditor(codeEditor.value, options);
@@ -294,7 +336,7 @@ const _sfc_main$h = defineComponent({
294
336
  emit("save", getEditorValue());
295
337
  });
296
338
  }
297
- globalThis.addEventListener("resize", resizeHandler);
339
+ resizeObserver.observe(codeEditor.value);
298
340
  };
299
341
  watch(() => props.initValues, (v, preV) => {
300
342
  if (v !== preV) {
@@ -309,7 +351,7 @@ const _sfc_main$h = defineComponent({
309
351
  init();
310
352
  });
311
353
  onUnmounted(() => {
312
- globalThis.removeEventListener("resize", resizeHandler);
354
+ resizeObserver.disconnect();
313
355
  });
314
356
  return {
315
357
  values,
@@ -326,14 +368,14 @@ const _sfc_main$h = defineComponent({
326
368
  };
327
369
  }
328
370
  });
329
- const _hoisted_1$d = {
371
+ const _hoisted_1$b = {
330
372
  ref: "codeEditor",
331
373
  class: "magic-code-editor"
332
374
  };
333
- function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
334
- return openBlock(), createElementBlock("div", _hoisted_1$d, null, 512);
375
+ function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
376
+ return openBlock(), createElementBlock("div", _hoisted_1$b, null, 512);
335
377
  }
336
- var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
378
+ var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
337
379
 
338
380
  let $TMAGIC_EDITOR = {};
339
381
  const setConfig = (option) => {
@@ -514,6 +556,12 @@ class History extends BaseService {
514
556
  });
515
557
  this.on("change", this.setCanUndoRedo);
516
558
  }
559
+ reset() {
560
+ this.state.pageSteps = {};
561
+ this.state.pageId = void 0;
562
+ this.state.canRedo = false;
563
+ this.state.canUndo = false;
564
+ }
517
565
  changePage(page) {
518
566
  if (!page)
519
567
  return;
@@ -619,8 +667,7 @@ class Props extends BaseService {
619
667
  }
620
668
  return cloneDeep({
621
669
  ...getDefaultPropsValue(type),
622
- ...defaultValue,
623
- ...this.state.propsValueMap[type] || {}
670
+ ...mergeWith(this.state.propsValueMap[type] || {}, defaultValue)
624
671
  });
625
672
  }
626
673
  }
@@ -707,7 +754,7 @@ const toRelative = (node) => {
707
754
  const setTop2Middle = (node, parentNode, stage) => {
708
755
  const style = node.style || {};
709
756
  const height = style.height || 0;
710
- if (!stage || style.top || !parentNode.style || !isNumber(height))
757
+ if (!stage || typeof style.top !== "undefined" || !parentNode.style || !isNumber(height))
711
758
  return style;
712
759
  const { height: parentHeight } = parentNode.style;
713
760
  if (isPage(parentNode)) {
@@ -817,6 +864,7 @@ class Editor$1 extends BaseService {
817
864
  "paste",
818
865
  "alignCenter",
819
866
  "moveLayer",
867
+ "move",
820
868
  "undo",
821
869
  "redo",
822
870
  "highlight"
@@ -829,12 +877,14 @@ class Editor$1 extends BaseService {
829
877
  node: null,
830
878
  stage: null,
831
879
  highlightNode: null,
832
- modifiedNodeIds: /* @__PURE__ */ new Map()
880
+ modifiedNodeIds: /* @__PURE__ */ new Map(),
881
+ pageLength: 0
833
882
  });
834
883
  }
835
884
  set(name, value) {
836
885
  this.state[name] = value;
837
886
  if (name === "root") {
887
+ this.state.pageLength = value?.items?.length || 0;
838
888
  this.emit("root-change", value);
839
889
  }
840
890
  }
@@ -894,6 +944,7 @@ class Editor$1 extends BaseService {
894
944
  } else {
895
945
  historyService.empty();
896
946
  }
947
+ this.emit("select", node);
897
948
  return node;
898
949
  }
899
950
  async selectNextNode() {
@@ -929,7 +980,8 @@ class Editor$1 extends BaseService {
929
980
  const { type, ...config2 } = addNode;
930
981
  const curNode = this.get("node");
931
982
  let parentNode;
932
- if (type === NodeType.PAGE) {
983
+ const isPage2 = type === NodeType.PAGE;
984
+ if (isPage2) {
933
985
  parentNode = this.get("root");
934
986
  } else if (parent && typeof parent !== "function") {
935
987
  parentNode = parent;
@@ -950,10 +1002,14 @@ class Editor$1 extends BaseService {
950
1002
  await stage?.add({ config: cloneDeep(newNode), root: cloneDeep(this.get("root")) });
951
1003
  await this.select(newNode);
952
1004
  this.addModifiedNodeId(newNode.id);
953
- if (type !== NodeType.PAGE) {
1005
+ if (!isPage2) {
954
1006
  this.pushHistoryState();
955
1007
  }
956
1008
  stage?.select(newNode.id);
1009
+ if (isPage2) {
1010
+ this.state.pageLength += 1;
1011
+ }
1012
+ this.emit("add", newNode);
957
1013
  return newNode;
958
1014
  }
959
1015
  async remove(node) {
@@ -972,9 +1028,20 @@ class Editor$1 extends BaseService {
972
1028
  const stage = this.get("stage");
973
1029
  stage?.remove({ id: node.id, root: this.get("root") });
974
1030
  if (node.type === NodeType.PAGE) {
1031
+ this.state.pageLength -= 1;
975
1032
  if (root.items[0]) {
976
1033
  await this.select(root.items[0]);
977
1034
  stage?.select(root.items[0].id);
1035
+ } else {
1036
+ this.set("node", null);
1037
+ this.set("parent", null);
1038
+ this.set("page", null);
1039
+ this.set("stage", null);
1040
+ this.set("highlightNode", null);
1041
+ this.resetModifiedNodeId();
1042
+ historyService.reset();
1043
+ this.emit("remove", node);
1044
+ return node;
978
1045
  }
979
1046
  } else {
980
1047
  await this.select(parent);
@@ -982,6 +1049,7 @@ class Editor$1 extends BaseService {
982
1049
  }
983
1050
  this.addModifiedNodeId(parent.id);
984
1051
  this.pushHistoryState();
1052
+ this.emit("remove", node);
985
1053
  return node;
986
1054
  }
987
1055
  async update(config2) {
@@ -1025,6 +1093,7 @@ class Editor$1 extends BaseService {
1025
1093
  }
1026
1094
  this.addModifiedNodeId(newConfig.id);
1027
1095
  this.pushHistoryState();
1096
+ this.emit("update", newConfig);
1028
1097
  return newConfig;
1029
1098
  }
1030
1099
  async sort(id1, id2) {
@@ -1354,6 +1423,25 @@ const fillConfig = (config = []) => [
1354
1423
  defaultValue: "100% 100%"
1355
1424
  }
1356
1425
  ]
1426
+ },
1427
+ {
1428
+ type: "fieldset",
1429
+ legend: "\u5B57\u4F53",
1430
+ items: [
1431
+ {
1432
+ name: "color",
1433
+ text: "\u989C\u8272",
1434
+ type: "colorPicker"
1435
+ },
1436
+ {
1437
+ name: "fontSize",
1438
+ text: "\u5927\u5C0F"
1439
+ },
1440
+ {
1441
+ name: "fontWeight",
1442
+ text: "\u7C97\u7EC6"
1443
+ }
1444
+ ]
1357
1445
  }
1358
1446
  ]
1359
1447
  }
@@ -1421,7 +1509,7 @@ const getDefaultPropsValue = (type) => ({
1421
1509
  name: type
1422
1510
  });
1423
1511
 
1424
- const _sfc_main$g = defineComponent({
1512
+ const _sfc_main$i = defineComponent({
1425
1513
  components: { Plus },
1426
1514
  setup() {
1427
1515
  const services = inject("services");
@@ -1438,14 +1526,14 @@ const _sfc_main$g = defineComponent({
1438
1526
  };
1439
1527
  }
1440
1528
  });
1441
- const _hoisted_1$c = { class: "m-editor-empty-panel" };
1442
- const _hoisted_2$6 = { class: "m-editor-empty-content" };
1443
- const _hoisted_3$4 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1444
- function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
1529
+ const _hoisted_1$a = { class: "m-editor-empty-panel" };
1530
+ const _hoisted_2$4 = { class: "m-editor-empty-content" };
1531
+ const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1532
+ function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
1445
1533
  const _component_plus = resolveComponent("plus");
1446
1534
  const _component_el_icon = resolveComponent("el-icon");
1447
- return openBlock(), createElementBlock("div", _hoisted_1$c, [
1448
- createElementVNode("div", _hoisted_2$6, [
1535
+ return openBlock(), createElementBlock("div", _hoisted_1$a, [
1536
+ createElementVNode("div", _hoisted_2$4, [
1449
1537
  createElementVNode("div", {
1450
1538
  class: "m-editor-empty-button",
1451
1539
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
@@ -1458,12 +1546,12 @@ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
1458
1546
  _: 1
1459
1547
  })
1460
1548
  ]),
1461
- _hoisted_3$4
1549
+ _hoisted_3$2
1462
1550
  ])
1463
1551
  ])
1464
1552
  ]);
1465
1553
  }
1466
- var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
1554
+ var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
1467
1555
 
1468
1556
  /*
1469
1557
  Copyright (c) 2018 Daybrush
@@ -2674,7 +2762,7 @@ function (_super) {
2674
2762
 
2675
2763
  var Gesto$1 = Gesto;
2676
2764
 
2677
- const _sfc_main$f = defineComponent({
2765
+ const _sfc_main$h = defineComponent({
2678
2766
  name: "m-editor-resize",
2679
2767
  props: {
2680
2768
  type: {
@@ -2716,33 +2804,33 @@ const _sfc_main$f = defineComponent({
2716
2804
  };
2717
2805
  }
2718
2806
  });
2719
- const _hoisted_1$b = {
2807
+ const _hoisted_1$9 = {
2720
2808
  ref: "target",
2721
2809
  class: "m-editor-resizer"
2722
2810
  };
2723
- function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2724
- return openBlock(), createElementBlock("span", _hoisted_1$b, [
2811
+ function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
2812
+ return openBlock(), createElementBlock("span", _hoisted_1$9, [
2725
2813
  renderSlot(_ctx.$slots, "default")
2726
2814
  ], 512);
2727
2815
  }
2728
- var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
2816
+ var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
2729
2817
 
2730
- const _sfc_main$e = defineComponent({
2818
+ const _sfc_main$g = defineComponent({
2731
2819
  components: {
2732
2820
  AddPageBox,
2733
2821
  Resizer
2734
2822
  },
2735
2823
  setup() {
2736
- const services = inject("services");
2737
- const root = computed(() => services?.editorService.get("root"));
2824
+ const { editorService, uiService } = inject("services") || {};
2825
+ const root = computed(() => editorService?.get("root"));
2738
2826
  return {
2739
2827
  root,
2740
- pageLength: computed(() => root.value?.items?.length || 0),
2741
- showSrc: computed(() => services?.uiService.get("showSrc")),
2742
- columnWidth: computed(() => services?.uiService.get("columnWidth")),
2828
+ pageLength: computed(() => editorService?.get("pageLength") || 0),
2829
+ showSrc: computed(() => uiService?.get("showSrc")),
2830
+ columnWidth: computed(() => uiService?.get("columnWidth")),
2743
2831
  saveCode(value) {
2744
2832
  try {
2745
- services?.editorService.set("root", eval(value));
2833
+ editorService?.set("root", eval(value));
2746
2834
  } catch (e) {
2747
2835
  console.error(e);
2748
2836
  }
@@ -2750,24 +2838,24 @@ const _sfc_main$e = defineComponent({
2750
2838
  };
2751
2839
  }
2752
2840
  });
2753
- const _hoisted_1$a = { class: "m-editor" };
2754
- const _hoisted_2$5 = {
2841
+ const _hoisted_1$8 = { class: "m-editor" };
2842
+ const _hoisted_2$3 = {
2755
2843
  key: 1,
2756
2844
  class: "m-editor-content"
2757
2845
  };
2758
- function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2846
+ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
2759
2847
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
2760
2848
  const _component_resizer = resolveComponent("resizer");
2761
2849
  const _component_el_scrollbar = resolveComponent("el-scrollbar");
2762
2850
  const _component_add_page_box = resolveComponent("add-page-box");
2763
- return openBlock(), createElementBlock("div", _hoisted_1$a, [
2851
+ return openBlock(), createElementBlock("div", _hoisted_1$8, [
2764
2852
  renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2765
2853
  _ctx.showSrc ? (openBlock(), createBlock(_component_magic_code_editor, {
2766
2854
  key: 0,
2767
2855
  class: "m-editor-content",
2768
2856
  "init-values": _ctx.root,
2769
2857
  onSave: _ctx.saveCode
2770
- }, null, 8, ["init-values", "onSave"])) : (openBlock(), createElementBlock("div", _hoisted_2$5, [
2858
+ }, null, 8, ["init-values", "onSave"])) : (openBlock(), createElementBlock("div", _hoisted_2$3, [
2771
2859
  createElementVNode("div", {
2772
2860
  class: "m-editor-framework-left",
2773
2861
  style: normalizeStyle(`width: ${_ctx.columnWidth?.left}px`)
@@ -2800,9 +2888,9 @@ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2800
2888
  ]))
2801
2889
  ]);
2802
2890
  }
2803
- var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
2891
+ var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
2804
2892
 
2805
- const _sfc_main$d = defineComponent({
2893
+ const _sfc_main$f = defineComponent({
2806
2894
  name: "m-icon",
2807
2895
  components: { Edit },
2808
2896
  props: {
@@ -2816,8 +2904,8 @@ const _sfc_main$d = defineComponent({
2816
2904
  };
2817
2905
  }
2818
2906
  });
2819
- const _hoisted_1$9 = ["src"];
2820
- function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2907
+ const _hoisted_1$7 = ["src"];
2908
+ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2821
2909
  const _component_edit = resolveComponent("edit");
2822
2910
  const _component_el_icon = resolveComponent("el-icon");
2823
2911
  return !_ctx.icon ? (openBlock(), createBlock(_component_el_icon, { key: 0 }, {
@@ -2828,7 +2916,7 @@ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2828
2916
  })) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (openBlock(), createElementBlock("img", {
2829
2917
  key: 1,
2830
2918
  src: _ctx.icon
2831
- }, null, 8, _hoisted_1$9)) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
2919
+ }, null, 8, _hoisted_1$7)) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
2832
2920
  key: 2,
2833
2921
  class: normalizeClass(_ctx.icon)
2834
2922
  }, null, 2)) : (openBlock(), createBlock(_component_el_icon, { key: 3 }, {
@@ -2838,9 +2926,9 @@ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2838
2926
  _: 1
2839
2927
  }));
2840
2928
  }
2841
- var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
2929
+ var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
2842
2930
 
2843
- const _sfc_main$c = defineComponent({
2931
+ const _sfc_main$e = defineComponent({
2844
2932
  components: { MIcon, ArrowDown },
2845
2933
  props: {
2846
2934
  data: {
@@ -2850,6 +2938,10 @@ const _sfc_main$c = defineComponent({
2850
2938
  type: "text",
2851
2939
  display: false
2852
2940
  })
2941
+ },
2942
+ eventType: {
2943
+ type: String,
2944
+ default: "click"
2853
2945
  }
2854
2946
  },
2855
2947
  setup(props) {
@@ -2876,7 +2968,7 @@ const _sfc_main$c = defineComponent({
2876
2968
  case "delete":
2877
2969
  return {
2878
2970
  type: "button",
2879
- icon: Delete,
2971
+ icon: markRaw(Delete),
2880
2972
  tooltip: "\u522A\u9664",
2881
2973
  disabled: () => services?.editorService.get("node")?.type === NodeType.PAGE,
2882
2974
  handler: () => services?.editorService.remove(services?.editorService.get("node"))
@@ -2884,7 +2976,7 @@ const _sfc_main$c = defineComponent({
2884
2976
  case "undo":
2885
2977
  return {
2886
2978
  type: "button",
2887
- icon: Back,
2979
+ icon: markRaw(Back),
2888
2980
  tooltip: "\u540E\u9000",
2889
2981
  disabled: () => !services?.historyService.state.canUndo,
2890
2982
  handler: () => services?.editorService.undo()
@@ -2892,7 +2984,7 @@ const _sfc_main$c = defineComponent({
2892
2984
  case "redo":
2893
2985
  return {
2894
2986
  type: "button",
2895
- icon: Right,
2987
+ icon: markRaw(Right),
2896
2988
  tooltip: "\u524D\u8FDB",
2897
2989
  disabled: () => !services?.historyService.state.canRedo,
2898
2990
  handler: () => services?.editorService.redo()
@@ -2900,28 +2992,28 @@ const _sfc_main$c = defineComponent({
2900
2992
  case "zoom-in":
2901
2993
  return {
2902
2994
  type: "button",
2903
- icon: ZoomIn,
2995
+ icon: markRaw(ZoomIn),
2904
2996
  tooltip: "\u653E\u5927",
2905
2997
  handler: zoomInHandler
2906
2998
  };
2907
2999
  case "zoom-out":
2908
3000
  return {
2909
3001
  type: "button",
2910
- icon: ZoomOut,
3002
+ icon: markRaw(ZoomOut),
2911
3003
  tooltip: "\u7E2E\u5C0F",
2912
3004
  handler: zoomOutHandler
2913
3005
  };
2914
3006
  case "rule":
2915
3007
  return {
2916
3008
  type: "button",
2917
- icon: ScaleToOriginal,
3009
+ icon: markRaw(ScaleToOriginal),
2918
3010
  tooltip: showRule.value ? "\u9690\u85CF\u6807\u5C3A" : "\u663E\u793A\u6807\u5C3A",
2919
3011
  handler: () => uiService?.set("showRule", !showRule.value)
2920
3012
  };
2921
3013
  case "guides":
2922
3014
  return {
2923
3015
  type: "button",
2924
- icon: Grid,
3016
+ icon: markRaw(Grid),
2925
3017
  tooltip: showGuides.value ? "\u9690\u85CF\u53C2\u8003\u7EBF" : "\u663E\u793A\u53C2\u8003\u7EBF",
2926
3018
  handler: () => uiService?.set("showGuides", !showGuides.value)
2927
3019
  };
@@ -2942,9 +3034,16 @@ const _sfc_main$c = defineComponent({
2942
3034
  }
2943
3035
  return item.value.disabled;
2944
3036
  });
3037
+ const buttonHandler = (item2, event) => {
3038
+ if (disabled.value)
3039
+ return;
3040
+ if (typeof item2.handler === "function" && services) {
3041
+ item2.handler?.(services, event);
3042
+ }
3043
+ };
2945
3044
  return {
2946
- ZoomIn,
2947
- ZoomOut,
3045
+ ZoomIn: markRaw(ZoomIn),
3046
+ ZoomOut: markRaw(ZoomOut),
2948
3047
  item,
2949
3048
  zoom,
2950
3049
  disabled,
@@ -2965,31 +3064,42 @@ const _sfc_main$c = defineComponent({
2965
3064
  command.item.handler(services);
2966
3065
  }
2967
3066
  },
2968
- buttonHandler(item2) {
2969
- if (disabled.value)
3067
+ clickHandler(item2, event) {
3068
+ if (props.eventType !== "click")
3069
+ return;
3070
+ if (item2.type === "button") {
3071
+ buttonHandler(item2, event);
3072
+ }
3073
+ },
3074
+ mousedownHandler(item2, event) {
3075
+ if (props.eventType !== "mousedown")
3076
+ return;
3077
+ if (item2.type === "button") {
3078
+ buttonHandler(item2, event);
3079
+ }
3080
+ },
3081
+ mouseupHandler(item2, event) {
3082
+ if (props.eventType !== "mouseup")
2970
3083
  return;
2971
- if (typeof item2.handler === "function") {
2972
- item2.handler?.(services);
3084
+ if (item2.type === "button") {
3085
+ buttonHandler(item2, event);
2973
3086
  }
2974
3087
  }
2975
3088
  };
2976
3089
  }
2977
3090
  });
2978
- const _hoisted_1$8 = {
2979
- key: 0,
2980
- class: "menu-item"
2981
- };
2982
- const _hoisted_2$4 = {
3091
+ const _hoisted_1$6 = {
2983
3092
  key: 1,
2984
3093
  class: "menu-item-text"
2985
3094
  };
2986
- const _hoisted_3$3 = {
3095
+ const _hoisted_2$2 = {
2987
3096
  class: "menu-item-text",
2988
3097
  style: { "margin": "0 5px" }
2989
3098
  };
2990
- const _hoisted_4$2 = { class: "el-dropdown-link menubar-menu-button" };
2991
- function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
3099
+ const _hoisted_3$1 = { class: "el-dropdown-link menubar-menu-button" };
3100
+ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2992
3101
  const _component_el_divider = resolveComponent("el-divider");
3102
+ const _component_tool_button = resolveComponent("tool-button", true);
2993
3103
  const _component_m_icon = resolveComponent("m-icon");
2994
3104
  const _component_el_button = resolveComponent("el-button");
2995
3105
  const _component_el_tooltip = resolveComponent("el-tooltip");
@@ -2998,60 +3108,66 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2998
3108
  const _component_el_dropdown_item = resolveComponent("el-dropdown-item");
2999
3109
  const _component_el_dropdown_menu = resolveComponent("el-dropdown-menu");
3000
3110
  const _component_el_dropdown = resolveComponent("el-dropdown");
3001
- return _ctx.display ? (openBlock(), createElementBlock("div", _hoisted_1$8, [
3111
+ return _ctx.display ? (openBlock(), createElementBlock("div", {
3112
+ key: 0,
3113
+ class: normalizeClass(["menu-item", _ctx.item.type]),
3114
+ onClick: _cache[0] || (_cache[0] = ($event) => _ctx.clickHandler(_ctx.item, $event)),
3115
+ onMousedown: _cache[1] || (_cache[1] = ($event) => _ctx.mousedownHandler(_ctx.item, $event)),
3116
+ onMouseup: _cache[2] || (_cache[2] = ($event) => _ctx.mouseupHandler(_ctx.item, $event))
3117
+ }, [
3002
3118
  _ctx.item.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
3003
3119
  key: 0,
3004
- direction: "vertical"
3005
- })) : _ctx.item.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_2$4, toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
3006
- createVNode(_component_el_button, {
3007
- size: "small",
3008
- type: "text"
3120
+ direction: _ctx.item.direction || "vertical"
3121
+ }, null, 8, ["direction"])) : _ctx.item.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$6, toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
3122
+ createVNode(_component_tool_button, {
3123
+ data: { type: "button", icon: _ctx.ZoomOut, handler: _ctx.zoomOutHandler, tooltip: "\u7F29\u5C0F" },
3124
+ "event-type": _ctx.eventType
3125
+ }, null, 8, ["data", "event-type"]),
3126
+ createElementVNode("span", _hoisted_2$2, toDisplayString(parseInt(`${_ctx.zoom * 100}`, 10)) + "%", 1),
3127
+ createVNode(_component_tool_button, {
3128
+ data: { type: "button", icon: _ctx.ZoomIn, handler: _ctx.zoomInHandler, tooltip: "\u653E\u5927" },
3129
+ "event-type": _ctx.eventType
3130
+ }, null, 8, ["data", "event-type"])
3131
+ ], 64)) : _ctx.item.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
3132
+ _ctx.item.tooltip ? (openBlock(), createBlock(_component_el_tooltip, {
3133
+ key: 0,
3134
+ effect: "dark",
3135
+ placement: "bottom-start",
3136
+ content: _ctx.item.tooltip
3009
3137
  }, {
3010
3138
  default: withCtx(() => [
3011
- createVNode(_component_m_icon, {
3012
- icon: _ctx.ZoomIn,
3013
- onClick: _ctx.zoomInHandler
3014
- }, null, 8, ["icon", "onClick"])
3139
+ createVNode(_component_el_button, {
3140
+ size: "small",
3141
+ text: "",
3142
+ disabled: _ctx.disabled
3143
+ }, {
3144
+ default: withCtx(() => [
3145
+ _ctx.item.icon ? (openBlock(), createBlock(_component_m_icon, {
3146
+ key: 0,
3147
+ icon: _ctx.item.icon
3148
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
3149
+ createElementVNode("span", null, toDisplayString(_ctx.item.text), 1)
3150
+ ]),
3151
+ _: 1
3152
+ }, 8, ["disabled"])
3015
3153
  ]),
3016
3154
  _: 1
3017
- }),
3018
- createElementVNode("span", _hoisted_3$3, toDisplayString(parseInt(`${_ctx.zoom * 100}`, 10)) + "%", 1),
3019
- createVNode(_component_el_button, {
3155
+ }, 8, ["content"])) : (openBlock(), createBlock(_component_el_button, {
3156
+ key: 1,
3020
3157
  size: "small",
3021
- type: "text"
3158
+ text: "",
3159
+ disabled: _ctx.disabled
3022
3160
  }, {
3023
3161
  default: withCtx(() => [
3024
- createVNode(_component_m_icon, {
3025
- icon: _ctx.ZoomOut,
3026
- onClick: _ctx.zoomOutHandler
3027
- }, null, 8, ["icon", "onClick"])
3162
+ _ctx.item.icon ? (openBlock(), createBlock(_component_m_icon, {
3163
+ key: 0,
3164
+ icon: _ctx.item.icon
3165
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
3166
+ createElementVNode("span", null, toDisplayString(_ctx.item.text), 1)
3028
3167
  ]),
3029
3168
  _: 1
3030
- })
3031
- ], 64)) : _ctx.item.type === "button" ? (openBlock(), createBlock(_component_el_tooltip, {
3032
- key: 3,
3033
- effect: "dark",
3034
- placement: "bottom-start",
3035
- content: _ctx.item.tooltip || _ctx.item.text
3036
- }, {
3037
- default: withCtx(() => [
3038
- createVNode(_component_el_button, {
3039
- size: "small",
3040
- type: "text",
3041
- disabled: _ctx.disabled,
3042
- onClick: _cache[0] || (_cache[0] = ($event) => _ctx.buttonHandler(_ctx.item))
3043
- }, {
3044
- default: withCtx(() => [
3045
- createVNode(_component_m_icon, {
3046
- icon: _ctx.item.icon
3047
- }, null, 8, ["icon"]),
3048
- createElementVNode("span", null, toDisplayString(_ctx.item.text), 1)
3049
- ]),
3050
- _: 1
3051
- }, 8, ["disabled"])
3052
- ]),
3053
- _: 1
3054
- }, 8, ["content"])) : _ctx.item.type === "dropdown" ? (openBlock(), createBlock(_component_el_dropdown, {
3169
+ }, 8, ["disabled"]))
3170
+ ], 64)) : _ctx.item.type === "dropdown" ? (openBlock(), createBlock(_component_el_dropdown, {
3055
3171
  key: 4,
3056
3172
  trigger: "click",
3057
3173
  disabled: _ctx.disabled,
@@ -3076,7 +3192,7 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
3076
3192
  })) : createCommentVNode("", true)
3077
3193
  ]),
3078
3194
  default: withCtx(() => [
3079
- createElementVNode("span", _hoisted_4$2, [
3195
+ createElementVNode("span", _hoisted_3$1, [
3080
3196
  createTextVNode(toDisplayString(_ctx.item.text), 1),
3081
3197
  createVNode(_component_el_icon, { class: "el-icon--right" }, {
3082
3198
  default: withCtx(() => [
@@ -3088,11 +3204,11 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
3088
3204
  ]),
3089
3205
  _: 1
3090
3206
  }, 8, ["disabled", "onCommand"])) : _ctx.item.type === "component" ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.item.component), normalizeProps(mergeProps({ key: 5 }, _ctx.item.props || {})), null, 16)) : createCommentVNode("", true)
3091
- ])) : createCommentVNode("", true);
3207
+ ], 34)) : createCommentVNode("", true);
3092
3208
  }
3093
- var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
3209
+ var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
3094
3210
 
3095
- const _sfc_main$b = defineComponent({
3211
+ const _sfc_main$d = defineComponent({
3096
3212
  name: "nav-menu",
3097
3213
  components: { ToolButton },
3098
3214
  props: {
@@ -3112,7 +3228,7 @@ const _sfc_main$b = defineComponent({
3112
3228
  };
3113
3229
  }
3114
3230
  });
3115
- function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
3231
+ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
3116
3232
  const _component_tool_button = resolveComponent("tool-button");
3117
3233
  return openBlock(), createElementBlock("div", {
3118
3234
  class: "m-editor-nav-menu",
@@ -3134,9 +3250,9 @@ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
3134
3250
  }), 128))
3135
3251
  ], 4);
3136
3252
  }
3137
- var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
3253
+ var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
3138
3254
 
3139
- const _sfc_main$a = defineComponent({
3255
+ const _sfc_main$c = defineComponent({
3140
3256
  name: "m-editor-props-panel",
3141
3257
  emits: ["mounted"],
3142
3258
  setup(props, { emit }) {
@@ -3182,7 +3298,7 @@ const _sfc_main$a = defineComponent({
3182
3298
  };
3183
3299
  }
3184
3300
  });
3185
- function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
3301
+ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
3186
3302
  const _component_m_form = resolveComponent("m-form");
3187
3303
  return openBlock(), createBlock(_component_m_form, {
3188
3304
  class: "m-editor-props-panel",
@@ -3194,9 +3310,9 @@ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
3194
3310
  onChange: _ctx.submit
3195
3311
  }, null, 8, ["init-values", "config", "onChange"]);
3196
3312
  }
3197
- var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
3313
+ var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
3198
3314
 
3199
- const _sfc_main$9 = defineComponent({
3315
+ const _sfc_main$b = defineComponent({
3200
3316
  name: "ui-component-panel",
3201
3317
  components: { MIcon },
3202
3318
  setup() {
@@ -3217,13 +3333,23 @@ const _sfc_main$9 = defineComponent({
3217
3333
  type,
3218
3334
  ...data
3219
3335
  });
3336
+ },
3337
+ dragstartHandler({ text, type, data = {} }, e) {
3338
+ if (e.dataTransfer) {
3339
+ e.dataTransfer.effectAllowed = "move";
3340
+ e.dataTransfer.setData("data", serialize({
3341
+ name: text,
3342
+ type,
3343
+ ...data
3344
+ }).replace(/"(\w+)":\s/g, "$1: "));
3345
+ }
3220
3346
  }
3221
3347
  };
3222
3348
  }
3223
3349
  });
3224
- const _hoisted_1$7 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
3225
- const _hoisted_2$3 = ["onClick"];
3226
- function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3350
+ const _hoisted_1$5 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
3351
+ const _hoisted_2$1 = ["onClick", "onDragstart"];
3352
+ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
3227
3353
  const _component_el_input = resolveComponent("el-input");
3228
3354
  const _component_m_icon = resolveComponent("m-icon");
3229
3355
  const _component_el_tooltip = resolveComponent("el-tooltip");
@@ -3253,15 +3379,17 @@ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3253
3379
  name: index
3254
3380
  }, {
3255
3381
  title: withCtx(() => [
3256
- _hoisted_1$7,
3382
+ _hoisted_1$5,
3257
3383
  createTextVNode(toDisplayString(group.title), 1)
3258
3384
  ]),
3259
3385
  default: withCtx(() => [
3260
3386
  (openBlock(true), createElementBlock(Fragment, null, renderList(group.items, (item) => {
3261
3387
  return openBlock(), createElementBlock("div", {
3262
3388
  class: "component-item",
3389
+ draggable: "true",
3263
3390
  key: item.type,
3264
- onClick: ($event) => _ctx.appendComponent(item)
3391
+ onClick: ($event) => _ctx.appendComponent(item),
3392
+ onDragstart: ($event) => _ctx.dragstartHandler(item, $event)
3265
3393
  }, [
3266
3394
  createVNode(_component_m_icon, {
3267
3395
  icon: item.icon
@@ -3276,7 +3404,7 @@ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3276
3404
  ]),
3277
3405
  _: 2
3278
3406
  }, 1032, ["content"])
3279
- ], 8, _hoisted_2$3);
3407
+ ], 40, _hoisted_2$1);
3280
3408
  }), 128))
3281
3409
  ]),
3282
3410
  _: 2
@@ -3290,100 +3418,196 @@ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3290
3418
  _: 1
3291
3419
  });
3292
3420
  }
3293
- var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
3421
+ var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
3294
3422
 
3295
- const _sfc_main$8 = defineComponent({
3296
- name: "magic-editor-content-menu",
3423
+ const _sfc_main$a = defineComponent({
3424
+ components: { ToolButton },
3425
+ props: {
3426
+ menuData: {
3427
+ type: Array,
3428
+ default: () => []
3429
+ }
3430
+ },
3431
+ setup() {
3432
+ const menu = ref();
3433
+ const subMenu = ref();
3434
+ const visible = ref(false);
3435
+ const subMenuData = ref([]);
3436
+ const menuStyle = ref({
3437
+ left: "0",
3438
+ top: "0"
3439
+ });
3440
+ const hide = () => {
3441
+ visible.value = false;
3442
+ };
3443
+ onMounted(() => {
3444
+ globalThis.addEventListener("mousedown", (e) => {
3445
+ if (!visible.value || e.target && menu.value?.contains(e.target)) {
3446
+ return;
3447
+ }
3448
+ hide();
3449
+ }, true);
3450
+ });
3451
+ return {
3452
+ menu,
3453
+ subMenu,
3454
+ visible,
3455
+ menuStyle,
3456
+ subMenuData,
3457
+ hide,
3458
+ show(e) {
3459
+ visible.value = true;
3460
+ nextTick(() => {
3461
+ const menuHeight = menu.value?.clientHeight || 0;
3462
+ let top = e.clientY;
3463
+ if (menuHeight + e.clientY > document.body.clientHeight) {
3464
+ top = document.body.clientHeight - menuHeight;
3465
+ }
3466
+ menuStyle.value = {
3467
+ top: `${top}px`,
3468
+ left: `${e.clientX}px`
3469
+ };
3470
+ });
3471
+ },
3472
+ showSubMenu(item) {
3473
+ const menuItem = item;
3474
+ if (typeof item !== "object" || !menuItem.items?.length) {
3475
+ return;
3476
+ }
3477
+ subMenuData.value = menuItem.items;
3478
+ if (menu.value) {
3479
+ subMenu.value.show({
3480
+ clientX: menu.value.offsetLeft + menu.value.clientWidth,
3481
+ clientY: menu.value.offsetTop
3482
+ });
3483
+ }
3484
+ }
3485
+ };
3486
+ }
3487
+ });
3488
+ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
3489
+ const _component_tool_button = resolveComponent("tool-button");
3490
+ const _component_content_menu = resolveComponent("content-menu", true);
3491
+ return _ctx.menuData.length ? withDirectives((openBlock(), createElementBlock("div", {
3492
+ key: 0,
3493
+ class: "magic-editor-content-menu",
3494
+ ref: "menu",
3495
+ style: normalizeStyle(_ctx.menuStyle)
3496
+ }, [
3497
+ createElementVNode("div", null, [
3498
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.menuData, (item, index) => {
3499
+ return openBlock(), createBlock(_component_tool_button, {
3500
+ "event-type": "mouseup",
3501
+ data: item,
3502
+ key: index,
3503
+ onMouseup: _ctx.hide,
3504
+ onMouseenter: ($event) => _ctx.showSubMenu(item)
3505
+ }, null, 8, ["data", "onMouseup", "onMouseenter"]);
3506
+ }), 128))
3507
+ ]),
3508
+ (openBlock(), createBlock(Teleport, { to: "body" }, [
3509
+ createVNode(_component_content_menu, {
3510
+ class: "sub-menu",
3511
+ ref: "subMenu",
3512
+ "menu-data": _ctx.subMenuData
3513
+ }, null, 8, ["menu-data"])
3514
+ ]))
3515
+ ], 4)), [
3516
+ [vShow, _ctx.visible]
3517
+ ]) : createCommentVNode("", true);
3518
+ }
3519
+ var ContentMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
3520
+
3521
+ const _sfc_main$9 = defineComponent({
3522
+ components: { ContentMenu },
3297
3523
  setup() {
3298
3524
  const services = inject("services");
3299
- const subVisible = ref(false);
3525
+ const menu = ref();
3300
3526
  const node = computed(() => services?.editorService.get("node"));
3301
- return {
3302
- subVisible,
3303
- node,
3304
- componentGroupList: computed(() => services?.componentListService.getList()),
3305
- append(config) {
3527
+ const isRoot = computed(() => node.value?.type === NodeType.ROOT);
3528
+ const isPage = computed(() => node.value?.type === NodeType.PAGE);
3529
+ const componentList = computed(() => services?.componentListService.getList() || []);
3530
+ const createMenuItems = (group) => group.items.map((component) => ({
3531
+ text: component.text,
3532
+ type: "button",
3533
+ icon: component.icon,
3534
+ handler: () => {
3306
3535
  services?.editorService.add({
3307
- name: config.text,
3308
- type: config.type,
3309
- ...config.data || {}
3536
+ name: component.text,
3537
+ type: component.type,
3538
+ ...component.data || {}
3310
3539
  });
3311
- },
3312
- remove() {
3313
- node.value && services?.editorService.remove(node.value);
3314
- },
3315
- copy(node2) {
3316
- node2 && services?.editorService.copy(node2);
3317
- },
3318
- setSubVisitable(v) {
3319
- subVisible.value = v;
3540
+ }
3541
+ }));
3542
+ const getSubMenuData = computed(() => {
3543
+ if (node.value?.type === "tabs") {
3544
+ return [
3545
+ {
3546
+ text: "\u6807\u7B7E\u9875",
3547
+ type: "button",
3548
+ icon: Files,
3549
+ handler: () => {
3550
+ services?.editorService.add({
3551
+ type: "tab-pane"
3552
+ });
3553
+ }
3554
+ }
3555
+ ];
3556
+ }
3557
+ if (node.value?.items) {
3558
+ return componentList.value.reduce((subMenuData, group, index) => subMenuData.concat(createMenuItems(group), index < componentList.value.length - 1 ? [
3559
+ {
3560
+ type: "divider",
3561
+ direction: "horizontal"
3562
+ }
3563
+ ] : []), []) || [];
3564
+ }
3565
+ return [];
3566
+ });
3567
+ return {
3568
+ menu,
3569
+ menuData: computed(() => [
3570
+ {
3571
+ type: "button",
3572
+ text: "\u65B0\u589E",
3573
+ icon: markRaw(Plus),
3574
+ display: () => node.value?.items,
3575
+ items: getSubMenuData.value
3576
+ },
3577
+ {
3578
+ type: "button",
3579
+ text: "\u590D\u5236",
3580
+ icon: markRaw(DocumentCopy),
3581
+ display: () => !isRoot.value,
3582
+ handler: () => {
3583
+ node.value && services?.editorService.copy(node.value);
3584
+ }
3585
+ },
3586
+ {
3587
+ type: "button",
3588
+ text: "\u5220\u9664",
3589
+ icon: markRaw(Delete),
3590
+ display: () => !isRoot.value && !isPage.value,
3591
+ handler: () => {
3592
+ node.value && services?.editorService.remove(node.value);
3593
+ }
3594
+ }
3595
+ ]),
3596
+ show(e) {
3597
+ menu.value?.show(e);
3320
3598
  }
3321
3599
  };
3322
3600
  }
3323
3601
  });
3324
- const _hoisted_1$6 = {
3325
- key: 0,
3326
- class: "magic-editor-content-menu"
3327
- };
3328
- const _hoisted_2$2 = ["onClick"];
3329
- const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3330
- function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3331
- const _component_el_scrollbar = resolveComponent("el-scrollbar");
3332
- return _ctx.node ? (openBlock(), createElementBlock("div", _hoisted_1$6, [
3333
- _ctx.node.items ? (openBlock(), createElementBlock("div", {
3334
- key: 0,
3335
- class: "magic-editor-content-menu-item",
3336
- onMouseenter: _cache[0] || (_cache[0] = ($event) => _ctx.setSubVisitable(true)),
3337
- onMouseleave: _cache[1] || (_cache[1] = ($event) => _ctx.setSubVisitable(false))
3338
- }, " \u65B0\u589E ", 32)) : createCommentVNode("", true),
3339
- _ctx.node.type !== "app" ? (openBlock(), createElementBlock("div", {
3340
- key: 1,
3341
- class: "magic-editor-content-menu-item",
3342
- onClick: _cache[2] || (_cache[2] = () => _ctx.copy(_ctx.node))
3343
- }, "\u590D\u5236")) : createCommentVNode("", true),
3344
- _ctx.node.type !== "app" && _ctx.node.type !== "page" ? (openBlock(), createElementBlock("div", {
3345
- key: 2,
3346
- class: "magic-editor-content-menu-item",
3347
- onClick: _cache[3] || (_cache[3] = () => _ctx.remove())
3348
- }, " \u5220\u9664 ")) : createCommentVNode("", true),
3349
- withDirectives(createElementVNode("div", {
3350
- class: "subMenu",
3351
- onMouseenter: _cache[5] || (_cache[5] = ($event) => _ctx.setSubVisitable(true)),
3352
- onMouseleave: _cache[6] || (_cache[6] = ($event) => _ctx.setSubVisitable(false))
3353
- }, [
3354
- createVNode(_component_el_scrollbar, null, {
3355
- default: withCtx(() => [
3356
- _ctx.node.type === "tabs" ? (openBlock(), createElementBlock("div", {
3357
- key: 0,
3358
- class: "magic-editor-content-menu-item",
3359
- onClick: _cache[4] || (_cache[4] = () => _ctx.append({
3360
- type: "tab-pane"
3361
- }))
3362
- }, " \u6807\u7B7E ")) : _ctx.node.items ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.componentGroupList, (list) => {
3363
- return openBlock(), createElementBlock("div", {
3364
- key: list.title
3365
- }, [
3366
- (openBlock(true), createElementBlock(Fragment, null, renderList(list.items, (item) => {
3367
- return openBlock(), createElementBlock(Fragment, null, [
3368
- item ? (openBlock(), createElementBlock("div", {
3369
- class: "magic-editor-content-menu-item",
3370
- key: item.type,
3371
- onClick: () => _ctx.append(item)
3372
- }, toDisplayString(item.text), 9, _hoisted_2$2)) : createCommentVNode("", true)
3373
- ], 64);
3374
- }), 256)),
3375
- _hoisted_3$2
3376
- ]);
3377
- }), 128)) : createCommentVNode("", true)
3378
- ]),
3379
- _: 1
3380
- })
3381
- ], 544), [
3382
- [vShow, _ctx.subVisible]
3383
- ])
3384
- ])) : createCommentVNode("", true);
3602
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3603
+ const _component_content_menu = resolveComponent("content-menu");
3604
+ return openBlock(), createBlock(_component_content_menu, {
3605
+ "menu-data": _ctx.menuData,
3606
+ ref: "menu",
3607
+ style: { "overflow": "initial" }
3608
+ }, null, 8, ["menu-data"]);
3385
3609
  }
3386
- var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3610
+ var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
3387
3611
 
3388
3612
  const throttleTime = 150;
3389
3613
  const select = async (data, editorService) => {
@@ -3475,56 +3699,37 @@ const useFilter = (tree) => ({
3475
3699
  tree.value?.filter(val);
3476
3700
  }
3477
3701
  });
3478
- const useContentMenu = (editorService) => {
3479
- const menuStyle = ref({
3480
- position: "absolute",
3481
- left: "0",
3482
- top: "0",
3483
- display: "none"
3484
- });
3485
- onMounted(() => {
3486
- document.addEventListener("click", () => {
3487
- menuStyle.value.display = "none";
3488
- }, true);
3489
- });
3490
- return {
3491
- menuStyle,
3492
- contextmenu(event, data) {
3493
- const bodyHeight = globalThis.document.body.clientHeight;
3494
- const left = `${event.clientX + 20}px`;
3495
- let top = `${event.clientY - 10}px`;
3496
- if (event.clientY + 300 > bodyHeight) {
3497
- top = `${bodyHeight - 300}px`;
3498
- }
3499
- menuStyle.value.left = left;
3500
- menuStyle.value.top = top;
3501
- menuStyle.value.display = "";
3502
- select(data, editorService);
3503
- }
3504
- };
3505
- };
3506
- const _sfc_main$7 = defineComponent({
3702
+ const _sfc_main$8 = defineComponent({
3507
3703
  name: "magic-editor-layer-panel",
3508
3704
  components: { LayerMenu },
3509
3705
  setup() {
3510
3706
  const services = inject("services");
3511
3707
  const tree = ref();
3708
+ const menu = ref();
3512
3709
  const clicked = ref(false);
3513
3710
  const editorService = services?.editorService;
3514
3711
  const highlightHandler = throttle((data) => {
3515
3712
  highlight(data, editorService);
3516
3713
  }, throttleTime);
3517
- const toogleClickFlag = () => {
3714
+ const toggleClickFlag = () => {
3518
3715
  clicked.value = !clicked.value;
3519
3716
  };
3520
3717
  const statusData = useStatus(tree, editorService);
3521
3718
  const canHighlight = computed(() => statusData.highlightNode.value?.id !== statusData.clickNode.value?.id && !clicked.value);
3719
+ editorService?.on("remove", () => {
3720
+ setTimeout(() => {
3721
+ tree.value?.getNode(editorService.get("node").id)?.updateChildren();
3722
+ }, 0);
3723
+ });
3522
3724
  return {
3523
3725
  tree,
3726
+ menu,
3524
3727
  ...statusData,
3525
3728
  ...useDrop(tree, editorService),
3526
3729
  ...useFilter(tree),
3527
- ...useContentMenu(editorService),
3730
+ highlightHandler,
3731
+ toggleClickFlag,
3732
+ canHighlight,
3528
3733
  clickHandler(data) {
3529
3734
  if (services?.uiService.get("uiSelectMode")) {
3530
3735
  document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
@@ -3533,14 +3738,16 @@ const _sfc_main$7 = defineComponent({
3533
3738
  tree.value?.setCurrentKey(data.id);
3534
3739
  select(data, editorService);
3535
3740
  },
3536
- highlightHandler,
3537
- toogleClickFlag,
3538
- canHighlight
3741
+ async contextmenu(event, data) {
3742
+ event.preventDefault();
3743
+ await select(data, editorService);
3744
+ menu.value?.show(event);
3745
+ }
3539
3746
  };
3540
3747
  }
3541
3748
  });
3542
- const _hoisted_1$5 = ["id", "onMouseenter"];
3543
- function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3749
+ const _hoisted_1$4 = ["id", "onMouseenter"];
3750
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3544
3751
  const _component_el_input = resolveComponent("el-input");
3545
3752
  const _component_el_tree = resolveComponent("el-tree");
3546
3753
  const _component_layer_menu = resolveComponent("layer-menu");
@@ -3580,8 +3787,8 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3580
3787
  createElementVNode("div", {
3581
3788
  id: data.id,
3582
3789
  class: normalizeClass(["cus-tree-node", { "cus-tree-node-hover": _ctx.canHighlight && data.id === _ctx.highlightNode?.id }]),
3583
- onMousedown: _cache[1] || (_cache[1] = (...args) => _ctx.toogleClickFlag && _ctx.toogleClickFlag(...args)),
3584
- onMouseup: _cache[2] || (_cache[2] = (...args) => _ctx.toogleClickFlag && _ctx.toogleClickFlag(...args)),
3790
+ onMousedown: _cache[1] || (_cache[1] = (...args) => _ctx.toggleClickFlag && _ctx.toggleClickFlag(...args)),
3791
+ onMouseup: _cache[2] || (_cache[2] = (...args) => _ctx.toggleClickFlag && _ctx.toggleClickFlag(...args)),
3585
3792
  onMouseenter: ($event) => _ctx.highlightHandler(data)
3586
3793
  }, [
3587
3794
  renderSlot(_ctx.$slots, "layer-node-content", {
@@ -3590,42 +3797,33 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3590
3797
  }, () => [
3591
3798
  createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
3592
3799
  ])
3593
- ], 42, _hoisted_1$5)
3800
+ ], 42, _hoisted_1$4)
3594
3801
  ]),
3595
3802
  _: 3
3596
3803
  }, 8, ["default-expanded-keys", "load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd"])) : createCommentVNode("", true),
3597
3804
  (openBlock(), createBlock(Teleport, { to: "body" }, [
3598
- createVNode(_component_layer_menu, {
3599
- style: normalizeStyle(_ctx.menuStyle)
3600
- }, null, 8, ["style"])
3805
+ createVNode(_component_layer_menu, { ref: "menu" }, null, 512)
3601
3806
  ]))
3602
3807
  ]),
3603
3808
  _: 3
3604
3809
  });
3605
3810
  }
3606
- var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
3811
+ var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3607
3812
 
3608
- const _sfc_main$6 = defineComponent({
3609
- name: "m-sidebar",
3813
+ const _sfc_main$7 = defineComponent({
3610
3814
  components: { MIcon },
3611
3815
  props: {
3612
3816
  data: {
3613
- type: Object,
3614
- default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
3817
+ type: Object
3615
3818
  }
3616
3819
  },
3617
3820
  setup(props) {
3618
- const activeTabName = ref(props.data?.status);
3619
- watch(() => props.data?.status, (status) => {
3620
- activeTabName.value = status || "0";
3621
- });
3622
3821
  return {
3623
- activeTabName,
3624
- items: computed(() => props.data?.items.map((item) => {
3625
- if (typeof item !== "string") {
3626
- return item;
3822
+ config: computed(() => {
3823
+ if (typeof props.data !== "string") {
3824
+ return props.data;
3627
3825
  }
3628
- switch (item) {
3826
+ switch (props.data) {
3629
3827
  case "component-list":
3630
3828
  return {
3631
3829
  type: "component",
@@ -3643,21 +3841,75 @@ const _sfc_main$6 = defineComponent({
3643
3841
  slots: {}
3644
3842
  };
3645
3843
  default:
3646
- return {};
3844
+ return void 0;
3647
3845
  }
3648
- }))
3846
+ })
3649
3847
  };
3650
3848
  }
3651
3849
  });
3652
- const _hoisted_1$4 = {
3850
+ const _hoisted_1$3 = {
3653
3851
  key: 1,
3654
3852
  class: "magic-editor-tab-panel-title"
3655
3853
  };
3656
- function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3854
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3657
3855
  const _component_m_icon = resolveComponent("m-icon");
3658
3856
  const _component_el_tab_pane = resolveComponent("el-tab-pane");
3857
+ return _ctx.config ? (openBlock(), createBlock(_component_el_tab_pane, {
3858
+ key: 0,
3859
+ name: _ctx.config.text
3860
+ }, {
3861
+ label: withCtx(() => [
3862
+ (openBlock(), createElementBlock("div", {
3863
+ key: _ctx.config.text
3864
+ }, [
3865
+ _ctx.config.icon ? (openBlock(), createBlock(_component_m_icon, {
3866
+ key: 0,
3867
+ icon: _ctx.config.icon
3868
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
3869
+ _ctx.config.text ? (openBlock(), createElementBlock("div", _hoisted_1$3, toDisplayString(_ctx.config.text), 1)) : createCommentVNode("", true)
3870
+ ]))
3871
+ ]),
3872
+ default: withCtx(() => [
3873
+ (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.component), mergeProps(_ctx.config.props || {}, toHandlers(_ctx.config?.listeners || {})), createSlots({ _: 2 }, [
3874
+ _ctx.config.slots?.layerNodeContent ? {
3875
+ name: "layer-node-content",
3876
+ fn: withCtx(({ data, node }) => [
3877
+ (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots?.layerNodeContent), {
3878
+ data,
3879
+ node
3880
+ }, null, 8, ["data", "node"]))
3881
+ ])
3882
+ } : void 0
3883
+ ]), 1040))
3884
+ ]),
3885
+ _: 1
3886
+ }, 8, ["name"])) : createCommentVNode("", true);
3887
+ }
3888
+ var TabPane = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
3889
+
3890
+ const _sfc_main$6 = defineComponent({
3891
+ components: { TabPane },
3892
+ name: "m-sidebar",
3893
+ props: {
3894
+ data: {
3895
+ type: Object,
3896
+ default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
3897
+ }
3898
+ },
3899
+ setup(props) {
3900
+ const activeTabName = ref(props.data?.status);
3901
+ watch(() => props.data?.status, (status) => {
3902
+ activeTabName.value = status || "0";
3903
+ });
3904
+ return {
3905
+ activeTabName
3906
+ };
3907
+ }
3908
+ });
3909
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3910
+ const _component_tab_pane = resolveComponent("tab-pane");
3659
3911
  const _component_el_tabs = resolveComponent("el-tabs");
3660
- return _ctx.data.type === "tabs" ? (openBlock(), createBlock(_component_el_tabs, {
3912
+ return _ctx.data.type === "tabs" && _ctx.data.items.length ? (openBlock(), createBlock(_component_el_tabs, {
3661
3913
  key: 0,
3662
3914
  class: "m-editor-sidebar",
3663
3915
  modelValue: _ctx.activeTabName,
@@ -3666,35 +3918,11 @@ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3666
3918
  "tab-position": "left"
3667
3919
  }, {
3668
3920
  default: withCtx(() => [
3669
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.items, (item) => {
3670
- return openBlock(), createBlock(_component_el_tab_pane, {
3671
- key: item.text,
3672
- name: item.text
3673
- }, {
3674
- label: withCtx(() => [
3675
- createElementVNode("span", null, [
3676
- item.icon ? (openBlock(), createBlock(_component_m_icon, {
3677
- key: 0,
3678
- icon: item.icon
3679
- }, null, 8, ["icon"])) : createCommentVNode("", true),
3680
- item.text ? (openBlock(), createElementBlock("div", _hoisted_1$4, toDisplayString(item.text), 1)) : createCommentVNode("", true)
3681
- ])
3682
- ]),
3683
- default: withCtx(() => [
3684
- (openBlock(), createBlock(resolveDynamicComponent(item.component), mergeProps(item.props || {}, toHandlers(item.listeners || {})), createSlots({ _: 2 }, [
3685
- item.slots?.layerNodeContent ? {
3686
- name: "layer-node-content",
3687
- fn: withCtx(({ data, node }) => [
3688
- (openBlock(), createBlock(resolveDynamicComponent(item.slots.layerNodeContent), {
3689
- data,
3690
- node
3691
- }, null, 8, ["data", "node"]))
3692
- ])
3693
- } : void 0
3694
- ]), 1040))
3695
- ]),
3696
- _: 2
3697
- }, 1032, ["name"]);
3921
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.data.items, (item, index) => {
3922
+ return openBlock(), createBlock(_component_tab_pane, {
3923
+ key: index,
3924
+ data: item
3925
+ }, null, 8, ["data"]);
3698
3926
  }), 128))
3699
3927
  ]),
3700
3928
  _: 1
@@ -3767,12 +3995,14 @@ const useScroll = (root) => {
3767
3995
  };
3768
3996
  };
3769
3997
  const _sfc_main$5 = defineComponent({
3770
- components: { ArrowLeftBold, ArrowRightBold, CaretBottom, Plus },
3998
+ components: { ArrowLeftBold, ArrowRightBold, CaretBottom, Plus, ToolButton },
3771
3999
  setup() {
3772
4000
  const services = inject("services");
3773
4001
  const editorService = services?.editorService;
3774
4002
  const root = computed(() => editorService?.get("root"));
3775
4003
  return {
4004
+ Delete: markRaw(Delete),
4005
+ DocumentCopy: markRaw(DocumentCopy),
3776
4006
  ...useScroll(root),
3777
4007
  root,
3778
4008
  page: computed(() => editorService?.get("page")),
@@ -3801,23 +4031,22 @@ const _sfc_main$5 = defineComponent({
3801
4031
  };
3802
4032
  }
3803
4033
  });
3804
- const _hoisted_1$3 = {
4034
+ const _hoisted_1$2 = {
3805
4035
  class: "m-editor-page-bar",
3806
4036
  ref: "pageBar"
3807
4037
  };
3808
- const _hoisted_2$1 = ["onClick"];
3809
- const _hoisted_3$1 = { class: "m-editor-page-bar-title" };
3810
- const _hoisted_4$1 = ["onClick"];
3811
- const _hoisted_5 = ["onClick"];
4038
+ const _hoisted_2 = ["onClick"];
4039
+ const _hoisted_3 = { class: "m-editor-page-bar-title" };
3812
4040
  function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3813
4041
  const _component_plus = resolveComponent("plus");
3814
4042
  const _component_el_icon = resolveComponent("el-icon");
3815
4043
  const _component_arrow_left_bold = resolveComponent("arrow-left-bold");
3816
4044
  const _component_el_tooltip = resolveComponent("el-tooltip");
4045
+ const _component_tool_button = resolveComponent("tool-button");
3817
4046
  const _component_caret_bottom = resolveComponent("caret-bottom");
3818
4047
  const _component_el_popover = resolveComponent("el-popover");
3819
4048
  const _component_arrow_right_bold = resolveComponent("arrow-right-bold");
3820
- return openBlock(), createElementBlock("div", _hoisted_1$3, [
4049
+ return openBlock(), createElementBlock("div", _hoisted_1$2, [
3821
4050
  createElementVNode("div", {
3822
4051
  id: "m-editor-page-bar-add-icon",
3823
4052
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
@@ -3854,7 +4083,7 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3854
4083
  class: normalizeClass(["m-editor-page-bar-item", { active: _ctx.page?.id === item.id }]),
3855
4084
  onClick: ($event) => _ctx.switchPage(item)
3856
4085
  }, [
3857
- createElementVNode("div", _hoisted_3$1, [
4086
+ createElementVNode("div", _hoisted_3, [
3858
4087
  renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
3859
4088
  createVNode(_component_el_tooltip, {
3860
4089
  effect: "dark",
@@ -3869,6 +4098,7 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3869
4098
  ])
3870
4099
  ]),
3871
4100
  createVNode(_component_el_popover, {
4101
+ "popper-class": "page-bar-popover",
3872
4102
  placement: "top",
3873
4103
  width: 160,
3874
4104
  trigger: "hover"
@@ -3884,20 +4114,28 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3884
4114
  default: withCtx(() => [
3885
4115
  createElementVNode("div", null, [
3886
4116
  renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3887
- createElementVNode("div", {
3888
- class: "magic-editor-content-menu-item",
3889
- onClick: () => _ctx.copy(item)
3890
- }, "\u590D\u5236", 8, _hoisted_4$1),
3891
- createElementVNode("div", {
3892
- class: "magic-editor-content-menu-item",
3893
- onClick: () => _ctx.remove(item)
3894
- }, "\u5220\u9664", 8, _hoisted_5)
4117
+ createVNode(_component_tool_button, {
4118
+ data: {
4119
+ type: "button",
4120
+ text: "\u590D\u5236",
4121
+ icon: _ctx.DocumentCopy,
4122
+ handler: () => _ctx.copy(item)
4123
+ }
4124
+ }, null, 8, ["data"]),
4125
+ createVNode(_component_tool_button, {
4126
+ data: {
4127
+ type: "button",
4128
+ text: "\u5220\u9664",
4129
+ icon: _ctx.Delete,
4130
+ handler: () => _ctx.remove(item)
4131
+ }
4132
+ }, null, 8, ["data"])
3895
4133
  ])
3896
4134
  ])
3897
4135
  ]),
3898
4136
  _: 2
3899
4137
  }, 1024)
3900
- ], 10, _hoisted_2$1);
4138
+ ], 10, _hoisted_2);
3901
4139
  }), 128))
3902
4140
  ], 4)) : createCommentVNode("", true),
3903
4141
  _ctx.canScroll ? (openBlock(), createElementBlock("div", {
@@ -4117,12 +4355,12 @@ const _sfc_main$4 = defineComponent({
4117
4355
  };
4118
4356
  }
4119
4357
  });
4120
- const _hoisted_1$2 = {
4358
+ const _hoisted_1$1 = {
4121
4359
  class: "m-editor-scroll-viewer-container",
4122
4360
  ref: "container"
4123
4361
  };
4124
4362
  function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
4125
- return openBlock(), createElementBlock("div", _hoisted_1$2, [
4363
+ return openBlock(), createElementBlock("div", _hoisted_1$1, [
4126
4364
  createElementVNode("div", {
4127
4365
  ref: "el",
4128
4366
  style: normalizeStyle(_ctx.style)
@@ -4134,7 +4372,7 @@ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
4134
4372
  var ScrollViewer = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$4]]);
4135
4373
 
4136
4374
  const _sfc_main$3 = defineComponent({
4137
- name: "magic-editor-ui-viewer-menu",
4375
+ components: { ContentMenu },
4138
4376
  setup() {
4139
4377
  const services = inject("services");
4140
4378
  const editorService = services?.editorService;
@@ -4143,6 +4381,7 @@ const _sfc_main$3 = defineComponent({
4143
4381
  const canCenter = ref(false);
4144
4382
  const node = computed(() => editorService?.get("node"));
4145
4383
  const parent = computed(() => editorService?.get("parent"));
4384
+ const isPage = computed(() => node.value?.type === NodeType.PAGE);
4146
4385
  onMounted(() => {
4147
4386
  const data = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
4148
4387
  canPaste.value = data !== "undefined" && !!data;
@@ -4155,133 +4394,114 @@ const _sfc_main$3 = defineComponent({
4155
4394
  }, { immediate: true });
4156
4395
  return {
4157
4396
  menu,
4158
- canPaste,
4159
- canDelete: computed(() => node.value?.type !== NodeType.PAGE),
4160
- canMoveZPos: computed(() => node.value?.type !== NodeType.PAGE),
4161
- canCenter,
4162
- center() {
4163
- node.value && editorService?.alignCenter(node.value);
4164
- },
4165
- copy() {
4166
- node.value && editorService?.copy(node.value);
4167
- canPaste.value = true;
4168
- },
4169
- paste() {
4170
- const top = menu.value?.offsetTop || 0;
4171
- const left = menu.value?.offsetLeft || 0;
4172
- editorService?.paste({ left, top });
4173
- },
4174
- remove() {
4175
- node.value && editorService?.remove(node.value);
4176
- },
4177
- top() {
4178
- editorService?.moveLayer(LayerOffset.TOP);
4179
- },
4180
- bottom() {
4181
- editorService?.moveLayer(LayerOffset.BOTTOM);
4182
- },
4183
- topItem() {
4184
- editorService?.moveLayer(1);
4185
- },
4186
- bottomItem() {
4187
- editorService?.moveLayer(-1);
4188
- },
4189
- clearGuides() {
4190
- editorService?.get("stage").clearGuides();
4397
+ menuData: reactive([
4398
+ {
4399
+ type: "button",
4400
+ text: "\u6C34\u5E73\u5C45\u4E2D",
4401
+ display: () => canCenter.value,
4402
+ handler: () => {
4403
+ node.value && editorService?.alignCenter(node.value);
4404
+ }
4405
+ },
4406
+ {
4407
+ type: "button",
4408
+ text: "\u590D\u5236",
4409
+ icon: markRaw(DocumentCopy),
4410
+ handler: () => {
4411
+ node.value && editorService?.copy(node.value);
4412
+ canPaste.value = true;
4413
+ }
4414
+ },
4415
+ {
4416
+ type: "button",
4417
+ text: "\u7C98\u8D34",
4418
+ display: () => canPaste.value,
4419
+ handler: () => {
4420
+ const top = menu.value?.$el.offsetTop || 0;
4421
+ const left = menu.value?.$el.offsetLeft || 0;
4422
+ editorService?.paste({ left, top });
4423
+ }
4424
+ },
4425
+ {
4426
+ type: "divider",
4427
+ direction: "horizontal",
4428
+ display: () => !isPage.value
4429
+ },
4430
+ {
4431
+ type: "button",
4432
+ text: "\u4E0A\u79FB\u4E00\u5C42",
4433
+ icon: markRaw(Top),
4434
+ display: () => !isPage.value,
4435
+ handler: () => {
4436
+ editorService?.moveLayer(1);
4437
+ }
4438
+ },
4439
+ {
4440
+ type: "button",
4441
+ text: "\u4E0B\u79FB\u4E00\u5C42",
4442
+ icon: markRaw(Bottom),
4443
+ display: () => !isPage.value,
4444
+ handler: () => {
4445
+ editorService?.moveLayer(-1);
4446
+ }
4447
+ },
4448
+ {
4449
+ type: "button",
4450
+ text: "\u7F6E\u9876",
4451
+ display: () => !isPage.value,
4452
+ handler: () => {
4453
+ editorService?.moveLayer(LayerOffset.TOP);
4454
+ }
4455
+ },
4456
+ {
4457
+ type: "button",
4458
+ text: "\u7F6E\u5E95",
4459
+ display: () => !isPage.value,
4460
+ handler: () => {
4461
+ editorService?.moveLayer(LayerOffset.BOTTOM);
4462
+ }
4463
+ },
4464
+ {
4465
+ type: "divider",
4466
+ direction: "horizontal",
4467
+ display: () => !isPage.value
4468
+ },
4469
+ {
4470
+ type: "button",
4471
+ text: "\u5220\u9664",
4472
+ icon: Delete,
4473
+ display: () => !isPage.value,
4474
+ handler: () => {
4475
+ node.value && editorService?.remove(node.value);
4476
+ }
4477
+ },
4478
+ {
4479
+ type: "divider",
4480
+ direction: "horizontal"
4481
+ },
4482
+ {
4483
+ type: "button",
4484
+ text: "\u6E05\u7A7A\u53C2\u8003\u7EBF",
4485
+ handler: () => {
4486
+ editorService?.get("stage").clearGuides();
4487
+ }
4488
+ }
4489
+ ]),
4490
+ show(e) {
4491
+ menu.value?.show(e);
4191
4492
  }
4192
4493
  };
4193
4494
  }
4194
4495
  });
4195
- const _hoisted_1$1 = {
4196
- class: "magic-editor-content-menu",
4197
- ref: "menu"
4198
- };
4199
- const _hoisted_2 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
4200
- const _hoisted_3 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
4201
- const _hoisted_4 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
4202
4496
  function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
4203
- return openBlock(), createElementBlock("div", _hoisted_1$1, [
4204
- createElementVNode("div", null, [
4205
- _ctx.canCenter ? (openBlock(), createElementBlock("div", {
4206
- key: 0,
4207
- class: "magic-editor-content-menu-item",
4208
- onClick: _cache[0] || (_cache[0] = () => _ctx.center())
4209
- }, "\u6C34\u5E73\u5C45\u4E2D")) : createCommentVNode("", true),
4210
- createElementVNode("div", {
4211
- class: "magic-editor-content-menu-item",
4212
- onClick: _cache[1] || (_cache[1] = () => _ctx.copy())
4213
- }, "\u590D\u5236"),
4214
- _ctx.canPaste ? (openBlock(), createElementBlock("div", {
4215
- key: 1,
4216
- class: "magic-editor-content-menu-item",
4217
- onClick: _cache[2] || (_cache[2] = (...args) => _ctx.paste && _ctx.paste(...args))
4218
- }, "\u7C98\u8D34")) : createCommentVNode("", true),
4219
- _ctx.canMoveZPos ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
4220
- _hoisted_2,
4221
- createElementVNode("div", {
4222
- class: "magic-editor-content-menu-item",
4223
- onClick: _cache[3] || (_cache[3] = (...args) => _ctx.topItem && _ctx.topItem(...args))
4224
- }, "\u4E0A\u79FB\u4E00\u5C42"),
4225
- createElementVNode("div", {
4226
- class: "magic-editor-content-menu-item",
4227
- onClick: _cache[4] || (_cache[4] = (...args) => _ctx.bottomItem && _ctx.bottomItem(...args))
4228
- }, "\u4E0B\u79FB\u4E00\u5C42"),
4229
- createElementVNode("div", {
4230
- class: "magic-editor-content-menu-item",
4231
- onClick: _cache[5] || (_cache[5] = (...args) => _ctx.top && _ctx.top(...args))
4232
- }, "\u7F6E\u9876"),
4233
- createElementVNode("div", {
4234
- class: "magic-editor-content-menu-item",
4235
- onClick: _cache[6] || (_cache[6] = (...args) => _ctx.bottom && _ctx.bottom(...args))
4236
- }, "\u7F6E\u5E95")
4237
- ], 64)) : createCommentVNode("", true),
4238
- _ctx.canDelete ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
4239
- _hoisted_3,
4240
- createElementVNode("div", {
4241
- class: "magic-editor-content-menu-item",
4242
- onClick: _cache[7] || (_cache[7] = () => _ctx.remove())
4243
- }, "\u5220\u9664")
4244
- ], 64)) : createCommentVNode("", true),
4245
- _hoisted_4,
4246
- createElementVNode("div", {
4247
- class: "magic-editor-content-menu-item",
4248
- onClick: _cache[8] || (_cache[8] = (...args) => _ctx.clearGuides && _ctx.clearGuides(...args))
4249
- }, "\u6E05\u7A7A\u53C2\u8003\u7EBF")
4250
- ])
4251
- ], 512);
4497
+ const _component_content_menu = resolveComponent("content-menu");
4498
+ return openBlock(), createBlock(_component_content_menu, {
4499
+ "menu-data": _ctx.menuData,
4500
+ ref: "menu"
4501
+ }, null, 8, ["menu-data"]);
4252
4502
  }
4253
4503
  var ViewerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
4254
4504
 
4255
- const useMenu = () => {
4256
- const menu = ref();
4257
- const menuStyle = ref({
4258
- display: "none",
4259
- left: "0",
4260
- top: "0"
4261
- });
4262
- onMounted(() => {
4263
- document.addEventListener("click", () => {
4264
- menuStyle.value.display = "none";
4265
- }, true);
4266
- });
4267
- return {
4268
- menu,
4269
- menuStyle,
4270
- contextmenuHandler(e) {
4271
- e.preventDefault();
4272
- const menuHeight = menu.value?.$el.clientHeight;
4273
- let top = e.clientY;
4274
- if (menuHeight + e.clientY > document.body.clientHeight) {
4275
- top = document.body.clientHeight - menuHeight;
4276
- }
4277
- menuStyle.value = {
4278
- display: "block",
4279
- top: `${top}px`,
4280
- left: `${e.clientX}px`
4281
- };
4282
- }
4283
- };
4284
- };
4285
4505
  const _sfc_main$2 = defineComponent({
4286
4506
  name: "magic-stage",
4287
4507
  components: {
@@ -4308,11 +4528,12 @@ const _sfc_main$2 = defineComponent({
4308
4528
  const services = inject("services");
4309
4529
  const stageWrap = ref();
4310
4530
  const stageContainer = ref();
4531
+ const menu = ref();
4311
4532
  const stageRect = computed(() => services?.uiService.get("stageRect"));
4312
4533
  const uiSelectMode = computed(() => services?.uiService.get("uiSelectMode"));
4313
4534
  const root = computed(() => services?.editorService.get("root"));
4314
4535
  const page = computed(() => services?.editorService.get("page"));
4315
- const zoom = computed(() => services?.uiService.get("zoom"));
4536
+ const zoom = computed(() => services?.uiService.get("zoom") || 1);
4316
4537
  const node = computed(() => services?.editorService.get("node"));
4317
4538
  let stage = null;
4318
4539
  let runtime = null;
@@ -4394,9 +4615,36 @@ const _sfc_main$2 = defineComponent({
4394
4615
  return {
4395
4616
  stageWrap,
4396
4617
  stageContainer,
4618
+ menu,
4397
4619
  stageRect,
4398
4620
  zoom,
4399
- ...useMenu()
4621
+ contextmenuHandler(e2) {
4622
+ e2.preventDefault();
4623
+ menu.value?.show(e2);
4624
+ },
4625
+ dragoverHandler(e2) {
4626
+ e2.preventDefault();
4627
+ if (e2.dataTransfer) {
4628
+ e2.dataTransfer.dropEffect = "move";
4629
+ }
4630
+ },
4631
+ async dropHandler(e) {
4632
+ e.preventDefault();
4633
+ if (e.dataTransfer && page.value && stageContainer.value && stage) {
4634
+ const config = eval(`(${e.dataTransfer.getData("data")})`);
4635
+ const layout = await services?.editorService.getLayout(page.value);
4636
+ const containerRect = stageContainer.value.getBoundingClientRect();
4637
+ const { scrollTop, scrollLeft } = stage.mask;
4638
+ if (layout === Layout.ABSOLUTE) {
4639
+ config.style = {
4640
+ position: "absolute",
4641
+ top: e.clientY - containerRect.top + scrollTop,
4642
+ left: e.clientX - containerRect.left + scrollLeft
4643
+ };
4644
+ }
4645
+ services?.editorService.add(config, page.value);
4646
+ }
4647
+ }
4400
4648
  };
4401
4649
  }
4402
4650
  });
@@ -4414,14 +4662,13 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
4414
4662
  createElementVNode("div", {
4415
4663
  class: "m-editor-stage-container",
4416
4664
  ref: "stageContainer",
4665
+ style: normalizeStyle(`transform: scale(${_ctx.zoom})`),
4417
4666
  onContextmenu: _cache[0] || (_cache[0] = (...args) => _ctx.contextmenuHandler && _ctx.contextmenuHandler(...args)),
4418
- style: normalizeStyle(`transform: scale(${_ctx.zoom})`)
4667
+ onDrop: _cache[1] || (_cache[1] = (...args) => _ctx.dropHandler && _ctx.dropHandler(...args)),
4668
+ onDragover: _cache[2] || (_cache[2] = (...args) => _ctx.dragoverHandler && _ctx.dragoverHandler(...args))
4419
4669
  }, null, 36),
4420
4670
  (openBlock(), createBlock(Teleport, { to: "body" }, [
4421
- createVNode(_component_viewer_menu, {
4422
- ref: "menu",
4423
- style: normalizeStyle(_ctx.menuStyle)
4424
- }, null, 8, ["style"])
4671
+ createVNode(_component_viewer_menu, { ref: "menu" }, null, 512)
4425
4672
  ]))
4426
4673
  ]),
4427
4674
  _: 1
@@ -4468,10 +4715,10 @@ const _sfc_main$1 = defineComponent({
4468
4715
  }).keydown([ctrl, "c"], (e) => {
4469
4716
  e.inputEvent.preventDefault();
4470
4717
  node.value && services?.editorService.copy(node.value);
4471
- }).keyup([ctrl, "v"], (e) => {
4718
+ }).keydown([ctrl, "v"], (e) => {
4472
4719
  e.inputEvent.preventDefault();
4473
4720
  node.value && services?.editorService.paste();
4474
- }).keyup([ctrl, "x"], (e) => {
4721
+ }).keydown([ctrl, "x"], (e) => {
4475
4722
  e.inputEvent.preventDefault();
4476
4723
  if (!node.value || isPage(node.value))
4477
4724
  return;
@@ -4850,5 +5097,5 @@ var index = {
4850
5097
  }
4851
5098
  };
4852
5099
 
4853
- export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, generateId, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getNodeIndex, getPageList, getPageNameList, historyService, info, initPosition, isFixed, log, propsService, setConfig, setLayout, setNewItemId, toRelative, uiService, warn };
5100
+ export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, ToolButton, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, generateId, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getNodeIndex, getPageList, getPageNameList, historyService, info, initPosition, isFixed, log, propsService, setConfig, setLayout, setNewItemId, toRelative, uiService, warn };
4854
5101
  //# sourceMappingURL=tmagic-editor.es.js.map