@tmagic/editor 1.1.0-beta.5 → 1.1.0-beta.6

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/{tmagic-editor.es.js → tmagic-editor.mjs} +1383 -1199
  2. package/dist/tmagic-editor.mjs.map +1 -0
  3. package/dist/tmagic-editor.umd.js +1396 -1211
  4. package/dist/tmagic-editor.umd.js.map +1 -1
  5. package/package.json +21 -19
  6. package/src/Editor.vue +14 -12
  7. package/src/components/ContentMenu.vue +87 -99
  8. package/src/components/ScrollViewer.vue +1 -1
  9. package/src/components/ToolButton.vue +150 -167
  10. package/src/fields/UISelect.vue +50 -70
  11. package/src/index.ts +1 -0
  12. package/src/layouts/AddPageBox.vue +2 -2
  13. package/src/layouts/Framework.vue +1 -1
  14. package/src/layouts/NavMenu.vue +2 -2
  15. package/src/layouts/PropsPanel.vue +1 -1
  16. package/src/layouts/Resizer.vue +1 -1
  17. package/src/layouts/sidebar/ComponentListPanel.vue +2 -2
  18. package/src/layouts/sidebar/LayerMenu.vue +2 -2
  19. package/src/layouts/sidebar/LayerPanel.vue +3 -3
  20. package/src/layouts/sidebar/Sidebar.vue +1 -1
  21. package/src/layouts/sidebar/TabPane.vue +2 -2
  22. package/src/layouts/workspace/PageBar.vue +53 -64
  23. package/src/layouts/workspace/Stage.vue +195 -222
  24. package/src/layouts/workspace/ViewerMenu.vue +142 -146
  25. package/src/layouts/workspace/Workspace.vue +11 -11
  26. package/src/services/BaseService.ts +1 -1
  27. package/src/services/componentList.ts +3 -3
  28. package/src/services/editor.ts +114 -133
  29. package/src/services/events.ts +1 -1
  30. package/src/services/history.ts +1 -1
  31. package/src/services/props.ts +18 -5
  32. package/src/services/storage.ts +133 -0
  33. package/src/services/ui.ts +2 -2
  34. package/src/type.ts +22 -6
  35. package/src/utils/config.ts +1 -1
  36. package/src/utils/editor.ts +1 -1
  37. package/src/utils/operator.ts +210 -0
  38. package/src/utils/props.ts +2 -2
  39. package/src/utils/scroll-viewer.ts +1 -1
  40. package/tsconfig.build.json +13 -0
  41. package/{dist/types/src → types}/Editor.vue.d.ts +7 -8
  42. package/types/components/ContentMenu.vue.d.ts +116 -0
  43. package/types/components/Icon.vue.d.ts +13 -0
  44. package/types/components/ScrollViewer.vue.d.ts +22 -0
  45. package/types/components/ToolButton.vue.d.ts +109 -0
  46. package/types/fields/Code.vue.d.ts +23 -0
  47. package/{dist/types/src → types}/fields/CodeLink.vue.d.ts +4 -6
  48. package/types/fields/UISelect.vue.d.ts +87 -0
  49. package/{dist/types/src → types}/index.d.ts +4 -1
  50. package/types/layouts/AddPageBox.vue.d.ts +4 -0
  51. package/{dist/types/src → types}/layouts/CodeEditor.vue.d.ts +11 -13
  52. package/types/layouts/Framework.vue.d.ts +22 -0
  53. package/types/layouts/NavMenu.vue.d.ts +25 -0
  54. package/types/layouts/PropsPanel.vue.d.ts +245 -0
  55. package/types/layouts/Resizer.vue.d.ts +12 -0
  56. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +14 -0
  57. package/types/layouts/sidebar/LayerMenu.vue.d.ts +100 -0
  58. package/types/layouts/sidebar/LayerPanel.vue.d.ts +1099 -0
  59. package/{dist/types/src → types}/layouts/sidebar/Sidebar.vue.d.ts +3 -5
  60. package/types/layouts/sidebar/TabPane.vue.d.ts +14 -0
  61. package/types/layouts/workspace/PageBar.vue.d.ts +54 -0
  62. package/types/layouts/workspace/Stage.vue.d.ts +46 -0
  63. package/types/layouts/workspace/ViewerMenu.vue.d.ts +88 -0
  64. package/types/layouts/workspace/Workspace.vue.d.ts +6 -0
  65. package/{dist/types/src → types}/services/BaseService.d.ts +0 -0
  66. package/types/services/componentList.d.ts +14 -0
  67. package/{dist/types/src → types}/services/editor.d.ts +26 -11
  68. package/{dist/types/src → types}/services/events.d.ts +0 -0
  69. package/{dist/types/src → types}/services/history.d.ts +0 -0
  70. package/{dist/types/src → types}/services/props.d.ts +6 -0
  71. package/types/services/storage.d.ts +56 -0
  72. package/{dist/types/src → types}/services/ui.d.ts +1 -1
  73. package/{dist/types/src → types}/type.d.ts +15 -0
  74. package/{dist/types/src → types}/utils/compose.d.ts +1 -1
  75. package/{dist/types/src → types}/utils/config.d.ts +0 -0
  76. package/{dist/types/src → types}/utils/editor.d.ts +2 -2
  77. package/{dist/types/src → types}/utils/index.d.ts +0 -0
  78. package/{dist/types/src → types}/utils/logger.d.ts +0 -0
  79. package/types/utils/operator.d.ts +44 -0
  80. package/{dist/types/src → types}/utils/polyfills.d.ts +0 -0
  81. package/{dist/types/src → types}/utils/props.d.ts +2 -2
  82. package/{dist/types/src → types}/utils/scroll-viewer.d.ts +0 -0
  83. package/{dist/types/src → types}/utils/undo-redo.d.ts +0 -0
  84. package/dist/tmagic-editor.es.js.map +0 -1
  85. package/dist/types/src/components/Icon.vue.d.ts +0 -14
  86. package/dist/types/src/components/ScrollViewer.vue.d.ts +0 -24
  87. package/dist/types/src/fields/Code.vue.d.ts +0 -25
  88. package/dist/types/src/layouts/AddPageBox.vue.d.ts +0 -5
  89. package/dist/types/src/layouts/Framework.vue.d.ts +0 -24
  90. package/dist/types/src/layouts/NavMenu.vue.d.ts +0 -27
  91. package/dist/types/src/layouts/PropsPanel.vue.d.ts +0 -13
  92. package/dist/types/src/layouts/Resizer.vue.d.ts +0 -14
  93. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +0 -16
  94. package/dist/types/src/layouts/sidebar/TabPane.vue.d.ts +0 -16
  95. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +0 -8
  96. package/dist/types/src/shims-vue.d.ts +0 -6
  97. package/dist/types/src/vite-env.d.ts +0 -1
  98. package/src/vite-env.d.ts +0 -1
@@ -4,31 +4,31 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.Vue, global.serialize, global.iconsVue, global.lodashEs, global.monaco, global.StageCore, global.schema, global.utils, global.events, global.core, global.Gesto, global.ElementPlus, global.KeyController));
5
5
  })(this, (function (exports, vue, serialize, iconsVue, lodashEs, monaco, StageCore, schema, utils, events, core, Gesto, elementPlus, KeyController) { 'use strict';
6
6
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
+ const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
8
8
 
9
9
  function _interopNamespace(e) {
10
10
  if (e && e.__esModule) return e;
11
- var n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
11
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
12
12
  if (e) {
13
- Object.keys(e).forEach(function (k) {
13
+ for (const k in e) {
14
14
  if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
15
+ const d = Object.getOwnPropertyDescriptor(e, k);
16
16
  Object.defineProperty(n, k, d.get ? d : {
17
17
  enumerable: true,
18
- get: function () { return e[k]; }
18
+ get: () => e[k]
19
19
  });
20
20
  }
21
- });
21
+ }
22
22
  }
23
- n["default"] = e;
23
+ n.default = e;
24
24
  return Object.freeze(n);
25
25
  }
26
26
 
27
- var serialize__default = /*#__PURE__*/_interopDefaultLegacy(serialize);
28
- var monaco__namespace = /*#__PURE__*/_interopNamespace(monaco);
29
- var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
30
- var Gesto__default = /*#__PURE__*/_interopDefaultLegacy(Gesto);
31
- var KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
27
+ const serialize__default = /*#__PURE__*/_interopDefaultLegacy(serialize);
28
+ const monaco__namespace = /*#__PURE__*/_interopNamespace(monaco);
29
+ const StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
30
+ const Gesto__default = /*#__PURE__*/_interopDefaultLegacy(Gesto);
31
+ const KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
32
32
 
33
33
  if (typeof global === "undefined") {
34
34
  window.global = window;
@@ -37,14 +37,6 @@
37
37
  window.globalThis = window;
38
38
  }
39
39
 
40
- var _export_sfc = (sfc, props) => {
41
- const target = sfc.__vccOpts || sfc;
42
- for (const [key, val] of props) {
43
- target[key] = val;
44
- }
45
- return target;
46
- };
47
-
48
40
  const _sfc_main$m = vue.defineComponent({
49
41
  name: "m-fields-vs-code",
50
42
  props: ["model", "name", "config", "prop"],
@@ -62,7 +54,16 @@
62
54
  };
63
55
  }
64
56
  });
65
- function _sfc_render$m(_ctx, _cache, $props, $setup, $data, $options) {
57
+
58
+ const _export_sfc = (sfc, props) => {
59
+ const target = sfc.__vccOpts || sfc;
60
+ for (const [key, val] of props) {
61
+ target[key] = val;
62
+ }
63
+ return target;
64
+ };
65
+
66
+ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
66
67
  const _component_magic_code_editor = vue.resolveComponent("magic-code-editor");
67
68
  return vue.openBlock(), vue.createBlock(_component_magic_code_editor, {
68
69
  style: vue.normalizeStyle(`height: ${_ctx.height}`),
@@ -71,7 +72,7 @@
71
72
  onSave: _ctx.save
72
73
  }, null, 8, ["style", "init-values", "language", "onSave"]);
73
74
  }
74
- var Code = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$m]]);
75
+ const Code = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$g]]);
75
76
 
76
77
  const _sfc_main$l = vue.defineComponent({
77
78
  name: "m-fields-code-link",
@@ -97,7 +98,7 @@
97
98
  vue.watchEffect(() => {
98
99
  if (!props.model || !props.name)
99
100
  return;
100
- modelValue.value.form[props.name] = serialize__default["default"](props.model[props.name], {
101
+ modelValue.value.form[props.name] = serialize__default.default(props.model[props.name], {
101
102
  space: 2,
102
103
  unsafe: true
103
104
  }).replace(/"(\w+)":\s/g, "$1: ");
@@ -128,7 +129,8 @@
128
129
  };
129
130
  }
130
131
  });
131
- function _sfc_render$l(_ctx, _cache, $props, $setup, $data, $options) {
132
+
133
+ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
132
134
  const _component_m_fields_link = vue.resolveComponent("m-fields-link");
133
135
  return vue.openBlock(), vue.createBlock(_component_m_fields_link, {
134
136
  config: _ctx.formConfig,
@@ -137,26 +139,21 @@
137
139
  onChange: _ctx.changeHandler
138
140
  }, null, 8, ["config", "model", "onChange"]);
139
141
  }
140
- var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$l]]);
142
+ const CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$f]]);
141
143
 
142
- var UISelect_vue_vue_type_style_index_0_lang = /* #__PURE__ */ (() => ".m-fields-ui-select {\n cursor: pointer;\n}\n.m-fields-ui-select i {\n margin-right: 3px;\n}\n.m-fields-ui-select span {\n color: #2882e0;\n}")();
143
-
144
- const _sfc_main$k = vue.defineComponent({
145
- name: "m-fields-ui-select",
144
+ const _hoisted_1$d = /* @__PURE__ */ vue.createTextVNode("\u53D6\u6D88");
145
+ const _sfc_main$k = /* @__PURE__ */ vue.defineComponent({
146
+ __name: "UISelect",
146
147
  props: {
147
- labelWidth: String,
148
- config: Object,
149
- model: Object,
150
- prop: {
151
- type: String,
152
- default() {
153
- return "";
154
- }
155
- },
156
- name: String
148
+ labelWidth: null,
149
+ config: null,
150
+ model: null,
151
+ prop: null,
152
+ name: null
157
153
  },
158
154
  emits: ["change"],
159
- setup(props, { emit }) {
155
+ setup(__props, { emit }) {
156
+ const props = __props;
160
157
  const services = vue.inject("services");
161
158
  const mForm = vue.inject("mForm");
162
159
  const val = vue.computed(() => props.model[props.name]);
@@ -178,97 +175,89 @@
178
175
  cancelHandler();
179
176
  }
180
177
  };
181
- return {
182
- Delete: vue.markRaw(iconsVue.Delete),
183
- Pointer: vue.markRaw(iconsVue.Pointer),
184
- Close: vue.markRaw(iconsVue.Close),
185
- val,
186
- uiSelectMode,
187
- toName: vue.computed(() => {
188
- const config = services?.editorService.getNodeById(val.value);
189
- return config?.name || "";
190
- }),
191
- startSelect() {
192
- if (!services?.uiService)
193
- return;
194
- services.uiService.set("uiSelectMode", true);
195
- uiSelectMode.value = true;
196
- globalThis.document.addEventListener("ui-select", clickHandler);
197
- },
198
- cancelHandler,
199
- deleteHandler() {
200
- if (props.model) {
201
- props.model[props.name] = "";
202
- emit("change", "");
203
- mForm?.$emit("field-change", props.prop, "");
204
- }
178
+ const toName = vue.computed(() => {
179
+ const config = services?.editorService.getNodeById(val.value);
180
+ return config?.name || "";
181
+ });
182
+ const startSelect = () => {
183
+ if (!services?.uiService)
184
+ return;
185
+ services.uiService.set("uiSelectMode", true);
186
+ uiSelectMode.value = true;
187
+ globalThis.document.addEventListener("ui-select", clickHandler);
188
+ };
189
+ const deleteHandler = () => {
190
+ if (props.model) {
191
+ props.model[props.name] = "";
192
+ emit("change", "");
193
+ mForm?.$emit("field-change", props.prop, "");
205
194
  }
206
195
  };
207
- }
208
- });
209
- const _hoisted_1$d = /* @__PURE__ */ vue.createTextVNode("\u53D6\u6D88");
210
- function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
211
- const _component_el_button = vue.resolveComponent("el-button");
212
- const _component_el_tooltip = vue.resolveComponent("el-tooltip");
213
- return _ctx.uiSelectMode ? (vue.openBlock(), vue.createElementBlock("div", {
214
- key: 0,
215
- class: "m-fields-ui-select",
216
- onClick: _cache[0] || (_cache[0] = (...args) => _ctx.cancelHandler && _ctx.cancelHandler(...args))
217
- }, [
218
- vue.createVNode(_component_el_button, {
219
- type: "danger",
220
- icon: _ctx.Delete,
221
- text: "",
222
- style: { "padding": "0" }
223
- }, {
224
- default: vue.withCtx(() => [
225
- _hoisted_1$d
226
- ]),
227
- _: 1
228
- }, 8, ["icon"])
229
- ])) : (vue.openBlock(), vue.createElementBlock("div", {
230
- key: 1,
231
- class: "m-fields-ui-select",
232
- onClick: _cache[1] || (_cache[1] = (...args) => _ctx.startSelect && _ctx.startSelect(...args)),
233
- style: { "display": "flex" }
234
- }, [
235
- vue.createVNode(_component_el_tooltip, { content: "\u6E05\u9664" }, {
236
- default: vue.withCtx(() => [
237
- _ctx.val ? (vue.openBlock(), vue.createBlock(_component_el_button, {
238
- key: 0,
239
- style: { "padding": "0" },
240
- type: "danger",
241
- icon: _ctx.Close,
242
- text: "",
243
- onClick: vue.withModifiers(_ctx.deleteHandler, ["stop"])
244
- }, null, 8, ["icon", "onClick"])) : vue.createCommentVNode("", true)
245
- ]),
246
- _: 1
247
- }),
248
- vue.createVNode(_component_el_tooltip, {
249
- content: _ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"
250
- }, {
251
- default: vue.withCtx(() => [
196
+ return (_ctx, _cache) => {
197
+ const _component_el_button = vue.resolveComponent("el-button");
198
+ const _component_el_tooltip = vue.resolveComponent("el-tooltip");
199
+ return uiSelectMode.value ? (vue.openBlock(), vue.createElementBlock("div", {
200
+ key: 0,
201
+ class: "m-fields-ui-select",
202
+ onClick: cancelHandler
203
+ }, [
252
204
  vue.createVNode(_component_el_button, {
205
+ type: "danger",
206
+ icon: vue.unref(iconsVue.Delete),
253
207
  text: "",
254
- style: { "padding": "0", "margin": "0" }
208
+ style: { "padding": "0" }
255
209
  }, {
256
210
  default: vue.withCtx(() => [
257
- vue.createTextVNode(vue.toDisplayString(_ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1)
211
+ _hoisted_1$d
258
212
  ]),
259
213
  _: 1
260
- })
261
- ]),
262
- _: 1
263
- }, 8, ["content"])
264
- ]));
265
- }
266
- var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$k]]);
214
+ }, 8, ["icon"])
215
+ ])) : (vue.openBlock(), vue.createElementBlock("div", {
216
+ key: 1,
217
+ class: "m-fields-ui-select",
218
+ onClick: startSelect,
219
+ style: { "display": "flex" }
220
+ }, [
221
+ vue.createVNode(_component_el_tooltip, { content: "\u6E05\u9664" }, {
222
+ default: vue.withCtx(() => [
223
+ vue.unref(val) ? (vue.openBlock(), vue.createBlock(_component_el_button, {
224
+ key: 0,
225
+ style: { "padding": "0" },
226
+ type: "danger",
227
+ icon: vue.unref(iconsVue.Close),
228
+ text: "",
229
+ onClick: vue.withModifiers(deleteHandler, ["stop"])
230
+ }, null, 8, ["icon", "onClick"])) : vue.createCommentVNode("", true)
231
+ ]),
232
+ _: 1
233
+ }),
234
+ vue.createVNode(_component_el_tooltip, {
235
+ content: vue.unref(val) ? vue.unref(toName) + "_" + vue.unref(val) : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"
236
+ }, {
237
+ default: vue.withCtx(() => [
238
+ vue.createVNode(_component_el_button, {
239
+ text: "",
240
+ style: { "padding": "0", "margin": "0" }
241
+ }, {
242
+ default: vue.withCtx(() => [
243
+ vue.createTextVNode(vue.toDisplayString(vue.unref(val) ? vue.unref(toName) + "_" + vue.unref(val) : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1)
244
+ ]),
245
+ _: 1
246
+ })
247
+ ]),
248
+ _: 1
249
+ }, 8, ["content"])
250
+ ]));
251
+ };
252
+ }
253
+ });
254
+
255
+ const UISelect_vue_vue_type_style_index_0_lang = '';
267
256
 
268
257
  const toString = (v, language) => {
269
258
  let value = "";
270
259
  if (typeof v !== "string") {
271
- value = serialize__default["default"](v, {
260
+ value = serialize__default.default(v, {
272
261
  space: 2,
273
262
  unsafe: true
274
263
  }).replace(/"(\w+)":\s/g, "$1: ");
@@ -387,14 +376,15 @@
387
376
  };
388
377
  }
389
378
  });
379
+
390
380
  const _hoisted_1$c = {
391
381
  ref: "codeEditor",
392
382
  class: "magic-code-editor"
393
383
  };
394
- function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
384
+ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
395
385
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$c, null, 512);
396
386
  }
397
- var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
387
+ const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$e]]);
398
388
 
399
389
  let $TMAGIC_EDITOR = {};
400
390
  const setConfig = (option) => {
@@ -403,6 +393,9 @@
403
393
  const getConfig = (key) => $TMAGIC_EDITOR[key];
404
394
 
405
395
  class UndoRedo {
396
+ elementList;
397
+ listCursor;
398
+ listMaxSize;
406
399
  constructor(listMaxSize = 200) {
407
400
  const minListMaxSize = 2;
408
401
  this.elementList = [];
@@ -498,12 +491,12 @@
498
491
  }
499
492
  };
500
493
  class BaseService extends events.EventEmitter {
494
+ pluginOptionsList = {};
495
+ middleware = {};
496
+ taskList = [];
497
+ doingTask = false;
501
498
  constructor(methods = [], serialMethods = []) {
502
499
  super();
503
- this.pluginOptionsList = {};
504
- this.middleware = {};
505
- this.taskList = [];
506
- this.doingTask = false;
507
500
  methods.forEach((propertyName) => {
508
501
  const scope = this;
509
502
  const sourceMethod = scope[propertyName];
@@ -560,14 +553,14 @@
560
553
  }
561
554
 
562
555
  class History extends BaseService {
556
+ state = vue.reactive({
557
+ pageSteps: {},
558
+ pageId: void 0,
559
+ canRedo: false,
560
+ canUndo: false
561
+ });
563
562
  constructor() {
564
563
  super([]);
565
- this.state = vue.reactive({
566
- pageSteps: {},
567
- pageId: void 0,
568
- canRedo: false,
569
- canUndo: false
570
- });
571
564
  this.on("change", this.setCanUndoRedo);
572
565
  }
573
566
  reset() {
@@ -636,117 +629,88 @@
636
629
  this.state.canUndo = undoRedo?.canUndo() || false;
637
630
  }
638
631
  }
639
- var historyService = new History();
632
+ const historyService = new History();
640
633
 
641
- class Props extends BaseService {
634
+ var Protocol = /* @__PURE__ */ ((Protocol2) => {
635
+ Protocol2["OBJECT"] = "object";
636
+ Protocol2["JSON"] = "json";
637
+ Protocol2["STRING"] = "string";
638
+ Protocol2["NUMBER"] = "number";
639
+ Protocol2["BOOLEAN"] = "boolean";
640
+ return Protocol2;
641
+ })(Protocol || {});
642
+ class WebStorage extends BaseService {
643
+ storage = globalThis.localStorage;
644
+ namespace = "tmagic";
642
645
  constructor() {
643
- super([
644
- "setPropsConfig",
645
- "getPropsConfig",
646
- "setPropsValue",
647
- "getPropsValue",
648
- "createId",
649
- "setNewItemId",
650
- "getDefaultPropsValue"
651
- ]);
652
- this.state = vue.reactive({
653
- propsConfigMap: {},
654
- propsValueMap: {}
655
- });
656
- }
657
- setPropsConfigs(configs) {
658
- Object.keys(configs).forEach((type) => {
659
- this.setPropsConfig(utils.toLine(type), configs[type]);
660
- });
661
- this.emit("props-configs-change");
662
- }
663
- setPropsConfig(type, config) {
664
- this.state.propsConfigMap[type] = fillConfig(Array.isArray(config) ? config : [config]);
646
+ super(["getStorage", "getNamespace", "clear", "getItem", "removeItem", "setItem"]);
665
647
  }
666
- async getPropsConfig(type) {
667
- if (type === "area") {
668
- return await this.getPropsConfig("button");
669
- }
670
- return lodashEs.cloneDeep(this.state.propsConfigMap[type] || DEFAULT_CONFIG);
648
+ async getStorage() {
649
+ return this.storage;
671
650
  }
672
- setPropsValues(values) {
673
- Object.keys(values).forEach((type) => {
674
- this.setPropsValue(utils.toLine(type), values[type]);
675
- });
651
+ async getNamespace() {
652
+ return this.namespace;
676
653
  }
677
- setPropsValue(type, value) {
678
- this.state.propsValueMap[type] = value;
654
+ async clear() {
655
+ const storage2 = await this.getStorage();
656
+ storage2.clear();
679
657
  }
680
- async getPropsValue(type, { inputEvent, ...defaultValue } = {}) {
681
- if (type === "area") {
682
- const value = await this.getPropsValue("button");
683
- value.className = "action-area";
684
- value.text = "";
685
- if (value.style) {
686
- value.style.backgroundColor = "rgba(255, 255, 255, 0)";
687
- }
688
- return value;
658
+ async getItem(key, options = {}) {
659
+ const [storage, namespace] = await Promise.all([this.getStorage(), this.getNamespace()]);
660
+ const { protocol = options.protocol, item } = this.getValueAndProtocol(storage.getItem(`${options.namespace || namespace}:${key}`));
661
+ if (item === null)
662
+ return null;
663
+ switch (protocol) {
664
+ case "object" /* OBJECT */:
665
+ return eval(`(${item})`);
666
+ case "json" /* JSON */:
667
+ return JSON.parse(item);
668
+ case "number" /* NUMBER */:
669
+ return Number(item);
670
+ case "boolean" /* BOOLEAN */:
671
+ return Boolean(item);
672
+ default:
673
+ return item;
689
674
  }
690
- const [id, defaultPropsValue, data] = await Promise.all([
691
- this.createId(type),
692
- this.getDefaultPropsValue(type),
693
- this.setNewItemId(lodashEs.cloneDeep({
694
- type,
695
- ...defaultValue
696
- }))
697
- ]);
698
- return {
699
- id,
700
- ...defaultPropsValue,
701
- ...lodashEs.mergeWith(lodashEs.cloneDeep(this.state.propsValueMap[type] || {}), data)
702
- };
703
675
  }
704
- async createId(type) {
705
- return `${type}_${lodashEs.random(1e4, false)}`;
676
+ async key(index) {
677
+ const storage2 = await this.getStorage();
678
+ return storage2.key(index);
706
679
  }
707
- async setNewItemId(config, parent) {
708
- const oldId = config.id;
709
- config.id = await this.createId(config.type || "component");
710
- if (utils.isPop(config) && parent?.type === schema.NodeType.PAGE) {
711
- updatePopId(oldId, config.id, parent);
680
+ async removeItem(key2, options2 = {}) {
681
+ const [storage2, namespace2] = await Promise.all([this.getStorage(), this.getNamespace()]);
682
+ storage2.removeItem(`${options2.namespace || namespace2}:${key2}`);
683
+ }
684
+ async setItem(key2, value, options2 = {}) {
685
+ const [storage2, namespace2] = await Promise.all([this.getStorage(), this.getNamespace()]);
686
+ let item2 = value;
687
+ const protocol2 = options2.protocol ? `${options2.protocol}:` : "";
688
+ if (typeof value === "string" /* STRING */ || typeof value === "number" /* NUMBER */) {
689
+ item2 = `${protocol2}${value}`;
690
+ } else {
691
+ item2 = `${protocol2}${serialize__default.default(value)}`;
712
692
  }
713
- if (config.items && Array.isArray(config.items)) {
714
- for (const item of config.items) {
715
- await this.setNewItemId(item, config);
716
- }
693
+ storage2.setItem(`${options2.namespace || namespace2}:${key2}`, item2);
694
+ }
695
+ getValueAndProtocol(value) {
696
+ let protocol2 = "";
697
+ if (value === null) {
698
+ return {
699
+ item: value,
700
+ protocol: protocol2
701
+ };
717
702
  }
718
- return config;
719
- }
720
- async getDefaultPropsValue(type) {
721
- return ["page", "container"].includes(type) ? {
722
- type,
723
- layout: "absolute",
724
- style: {},
725
- name: type,
726
- items: []
727
- } : {
728
- type,
729
- style: {},
730
- name: type
703
+ const item2 = value.replace(new RegExp(`^(${Object.values(Protocol).join("|")})(:)(.+)`), (_$0, $1, _$2, $3) => {
704
+ protocol2 = $1;
705
+ return $3;
706
+ });
707
+ return {
708
+ protocol: protocol2,
709
+ item: item2
731
710
  };
732
711
  }
733
712
  }
734
- const updatePopId = (oldId, popId, pageConfig) => {
735
- pageConfig.items?.forEach((config) => {
736
- if (config.pop === oldId) {
737
- config.pop = popId;
738
- return;
739
- }
740
- if (config.popId === oldId) {
741
- config.popId = popId;
742
- return;
743
- }
744
- if (Array.isArray(config.items)) {
745
- updatePopId(oldId, popId, config);
746
- }
747
- });
748
- };
749
- var propsService = new Props();
713
+ const storageService = new WebStorage();
750
714
 
751
715
  var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
752
716
  LayerOffset2["TOP"] = "top";
@@ -910,83 +874,334 @@
910
874
  return config.style.left;
911
875
  };
912
876
 
913
- class Editor$1 extends BaseService {
877
+ class Props extends BaseService {
878
+ state = vue.reactive({
879
+ propsConfigMap: {},
880
+ propsValueMap: {}
881
+ });
914
882
  constructor() {
915
883
  super([
916
- "getLayout",
917
- "select",
918
- "add",
919
- "remove",
920
- "update",
921
- "sort",
922
- "copy",
923
- "paste",
924
- "alignCenter",
925
- "moveLayer",
926
- "moveToContainer",
927
- "move",
928
- "undo",
929
- "redo",
930
- "highlight"
931
- ], ["select", "update", "moveLayer"]);
932
- this.isHistoryStateChange = false;
933
- this.state = vue.reactive({
934
- root: null,
935
- page: null,
936
- parent: null,
937
- node: null,
938
- stage: null,
939
- highlightNode: null,
940
- modifiedNodeIds: /* @__PURE__ */ new Map(),
941
- pageLength: 0
942
- });
884
+ "setPropsConfig",
885
+ "getPropsConfig",
886
+ "setPropsValue",
887
+ "getPropsValue",
888
+ "createId",
889
+ "setNewItemId",
890
+ "getDefaultPropsValue"
891
+ ]);
943
892
  }
944
- set(name, value) {
945
- this.state[name] = value;
946
- if (name === "root") {
947
- this.state.pageLength = value?.items?.length || 0;
948
- this.emit("root-change", value);
949
- }
893
+ setPropsConfigs(configs) {
894
+ Object.keys(configs).forEach((type) => {
895
+ this.setPropsConfig(utils.toLine(type), configs[type]);
896
+ });
897
+ this.emit("props-configs-change");
950
898
  }
951
- get(name) {
952
- return this.state[name];
899
+ setPropsConfig(type, config) {
900
+ this.state.propsConfigMap[type] = fillConfig(Array.isArray(config) ? config : [config]);
953
901
  }
954
- getNodeInfo(id, raw = true) {
955
- let root = this.get("root");
956
- if (raw) {
957
- root = vue.toRaw(root);
958
- }
959
- if (!root)
960
- return {};
961
- if (id === root.id) {
962
- return { node: root };
902
+ async getPropsConfig(type) {
903
+ if (type === "area") {
904
+ return await this.getPropsConfig("button");
963
905
  }
964
- const path = utils.getNodePath(id, root.items);
965
- if (!path.length)
966
- return {};
967
- path.unshift(root);
968
- const info = {};
969
- info.node = path[path.length - 1];
970
- info.parent = path[path.length - 2];
971
- path.forEach((item) => {
972
- if (item.type === schema.NodeType.PAGE) {
973
- info.page = item;
974
- return;
975
- }
976
- });
977
- return info;
906
+ return lodashEs.cloneDeep(this.state.propsConfigMap[type] || DEFAULT_CONFIG);
978
907
  }
979
- getNodeById(id, raw = true) {
980
- const { node } = this.getNodeInfo(id, raw);
981
- return node;
908
+ setPropsValues(values) {
909
+ Object.keys(values).forEach((type) => {
910
+ this.setPropsValue(utils.toLine(type), values[type]);
911
+ });
982
912
  }
983
- getParentById(id, raw = true) {
984
- if (!this.get("root"))
985
- return;
986
- const { parent } = this.getNodeInfo(id, raw);
987
- return parent;
913
+ setPropsValue(type, value) {
914
+ this.state.propsValueMap[type] = value;
988
915
  }
989
- async getLayout(parent, node) {
916
+ async getPropsValue(type, { inputEvent, ...defaultValue } = {}) {
917
+ if (type === "area") {
918
+ const value = await this.getPropsValue("button");
919
+ value.className = "action-area";
920
+ value.text = "";
921
+ if (value.style) {
922
+ value.style.backgroundColor = "rgba(255, 255, 255, 0)";
923
+ }
924
+ return value;
925
+ }
926
+ const [id, defaultPropsValue, data] = await Promise.all([
927
+ this.createId(type),
928
+ this.getDefaultPropsValue(type),
929
+ this.setNewItemId(lodashEs.cloneDeep({
930
+ type,
931
+ ...defaultValue
932
+ }))
933
+ ]);
934
+ return {
935
+ id,
936
+ ...defaultPropsValue,
937
+ ...lodashEs.mergeWith({}, lodashEs.cloneDeep(this.state.propsValueMap[type] || {}), data)
938
+ };
939
+ }
940
+ guid(digit = 8) {
941
+ return "x".repeat(digit).replace(/[xy]/g, (c) => {
942
+ const r = Math.random() * 16 | 0;
943
+ const v = c == "x" ? r : r & 3 | 8;
944
+ return v.toString(16);
945
+ });
946
+ }
947
+ async createId(type) {
948
+ return `${type}_${this.guid()}`;
949
+ }
950
+ async setNewItemId(config, parent) {
951
+ const oldId = config.id;
952
+ config.id = await this.createId(config.type || "component");
953
+ if (utils.isPop(config) && parent?.type === schema.NodeType.PAGE) {
954
+ updatePopId(oldId, config.id, parent);
955
+ }
956
+ if (config.items && Array.isArray(config.items)) {
957
+ for (const item of config.items) {
958
+ await this.setNewItemId(item, config);
959
+ }
960
+ }
961
+ return config;
962
+ }
963
+ async getDefaultPropsValue(type) {
964
+ return ["page", "container"].includes(type) ? {
965
+ type,
966
+ layout: "absolute",
967
+ style: {},
968
+ name: type,
969
+ items: []
970
+ } : {
971
+ type,
972
+ style: {},
973
+ name: type
974
+ };
975
+ }
976
+ }
977
+ const updatePopId = (oldId, popId, pageConfig) => {
978
+ pageConfig.items?.forEach((config) => {
979
+ if (config.pop === oldId) {
980
+ config.pop = popId;
981
+ return;
982
+ }
983
+ if (config.popId === oldId) {
984
+ config.popId = popId;
985
+ return;
986
+ }
987
+ if (Array.isArray(config.items)) {
988
+ updatePopId(oldId, popId, config);
989
+ }
990
+ });
991
+ };
992
+ const propsService = new Props();
993
+
994
+ const beforePaste = async (position, config) => {
995
+ if (!config[0]?.style)
996
+ return config;
997
+ const curNode = editorService.get("node");
998
+ const { left: referenceLeft, top: referenceTop } = config[0].style;
999
+ const pasteConfigs = await Promise.all(config.map(async (configItem) => {
1000
+ const { offsetX = 0, offsetY = 0, ...positionClone } = position;
1001
+ let pastePosition = positionClone;
1002
+ if (!lodashEs.isEmpty(pastePosition) && curNode.items) {
1003
+ pastePosition = getPositionInContainer(pastePosition, curNode.id);
1004
+ }
1005
+ if (pastePosition.left && configItem.style?.left) {
1006
+ pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
1007
+ }
1008
+ if (pastePosition.top && configItem.style?.top) {
1009
+ pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
1010
+ }
1011
+ const pasteConfig = await propsService.setNewItemId(configItem, editorService.get("root"));
1012
+ if (pasteConfig.style) {
1013
+ const { left, top } = pasteConfig.style;
1014
+ if (typeof left === "number" || !!left && !isNaN(Number(left))) {
1015
+ pasteConfig.style.left = Number(left) + offsetX;
1016
+ }
1017
+ if (typeof top === "number" || !!top && !isNaN(Number(top))) {
1018
+ pasteConfig.style.top = Number(top) + offsetY;
1019
+ }
1020
+ pasteConfig.style = {
1021
+ ...pasteConfig.style,
1022
+ ...pastePosition
1023
+ };
1024
+ }
1025
+ if (utils.isPage(pasteConfig)) {
1026
+ pasteConfig.name = generatePageNameByApp(editorService.get("root"));
1027
+ }
1028
+ return pasteConfig;
1029
+ }));
1030
+ return pasteConfigs;
1031
+ };
1032
+ const beforeAdd = async (addNode, parent) => {
1033
+ const { type, inputEvent, ...config } = addNode;
1034
+ const curNode = editorService.get("node");
1035
+ let parentNode;
1036
+ const isPage2 = type === schema.NodeType.PAGE;
1037
+ if (isPage2) {
1038
+ parentNode = editorService.get("root");
1039
+ } else if (parent && typeof parent !== "function") {
1040
+ parentNode = parent;
1041
+ } else if (curNode.items) {
1042
+ parentNode = curNode;
1043
+ } else {
1044
+ parentNode = editorService.getParentById(curNode.id, false);
1045
+ }
1046
+ if (!parentNode)
1047
+ throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
1048
+ const layout = await editorService.getLayout(vue.toRaw(parentNode), addNode);
1049
+ const newNode = { ...vue.toRaw(await propsService.getPropsValue(type, config)) };
1050
+ newNode.style = getInitPositionStyle(newNode.style, layout, parentNode, editorService.get("stage"));
1051
+ if ((parentNode?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && newNode.type !== schema.NodeType.PAGE) {
1052
+ throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
1053
+ }
1054
+ parentNode?.items?.push(newNode);
1055
+ return {
1056
+ parentNode,
1057
+ newNode,
1058
+ layout,
1059
+ isPage: isPage2
1060
+ };
1061
+ };
1062
+ const getPositionInContainer = (position = {}, id) => {
1063
+ let { left = 0, top = 0 } = position;
1064
+ const parentEl = editorService.get("stage")?.renderer?.contentWindow?.document.getElementById(`${id}`);
1065
+ const parentElRect = parentEl?.getBoundingClientRect();
1066
+ left = left - (parentElRect?.left || 0);
1067
+ top = top - (parentElRect?.top || 0);
1068
+ return {
1069
+ left,
1070
+ top
1071
+ };
1072
+ };
1073
+ const notifyAddToStage = async (parentNode, newNode, layout) => {
1074
+ const stage = editorService.get("stage");
1075
+ const root = editorService.get("root");
1076
+ await stage?.add({ config: lodashEs.cloneDeep(newNode), parent: lodashEs.cloneDeep(parentNode), root: lodashEs.cloneDeep(root) });
1077
+ if (layout === Layout.ABSOLUTE) {
1078
+ const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
1079
+ if (typeof fixedLeft !== "undefined" && newNode.style) {
1080
+ newNode.style.left = fixedLeft;
1081
+ await stage?.update({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(root) });
1082
+ }
1083
+ }
1084
+ };
1085
+ const beforeRemove = async (node) => {
1086
+ if (!node?.id)
1087
+ return;
1088
+ const stage = editorService.get("stage");
1089
+ const root = editorService.get("root");
1090
+ if (!root)
1091
+ throw new Error("\u6CA1\u6709root");
1092
+ const { parent, node: curNode } = editorService.getNodeInfo(node.id, false);
1093
+ if (!parent || !curNode)
1094
+ throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1095
+ const index = getNodeIndex(curNode, parent);
1096
+ if (typeof index !== "number" || index === -1)
1097
+ throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1098
+ parent.items?.splice(index, 1);
1099
+ stage?.remove({ id: node.id, root: lodashEs.cloneDeep(root) });
1100
+ if (node.type === schema.NodeType.PAGE) {
1101
+ editorService.state.pageLength -= 1;
1102
+ if (root.items[0]) {
1103
+ await editorService.select(root.items[0]);
1104
+ stage?.select(root.items[0].id);
1105
+ } else {
1106
+ editorService.set("node", null);
1107
+ editorService.set("nodes", []);
1108
+ editorService.set("parent", null);
1109
+ editorService.set("page", null);
1110
+ editorService.set("stage", null);
1111
+ editorService.set("highlightNode", null);
1112
+ editorService.resetModifiedNodeId();
1113
+ historyService.reset();
1114
+ editorService.emit("remove", node);
1115
+ return;
1116
+ }
1117
+ } else {
1118
+ await editorService.select(parent);
1119
+ stage?.select(parent.id);
1120
+ }
1121
+ return parent;
1122
+ };
1123
+
1124
+ class Editor$1 extends BaseService {
1125
+ state = vue.reactive({
1126
+ root: null,
1127
+ page: null,
1128
+ parent: null,
1129
+ node: null,
1130
+ nodes: [],
1131
+ stage: null,
1132
+ highlightNode: null,
1133
+ modifiedNodeIds: /* @__PURE__ */ new Map(),
1134
+ pageLength: 0
1135
+ });
1136
+ isHistoryStateChange = false;
1137
+ constructor() {
1138
+ super([
1139
+ "getLayout",
1140
+ "select",
1141
+ "add",
1142
+ "remove",
1143
+ "update",
1144
+ "sort",
1145
+ "copy",
1146
+ "paste",
1147
+ "alignCenter",
1148
+ "moveLayer",
1149
+ "moveToContainer",
1150
+ "move",
1151
+ "undo",
1152
+ "redo",
1153
+ "highlight"
1154
+ ], ["select", "update", "moveLayer"]);
1155
+ }
1156
+ set(name, value) {
1157
+ this.state[name] = value;
1158
+ if (name === "nodes") {
1159
+ this.set("node", value[0]);
1160
+ }
1161
+ if (name === "root") {
1162
+ this.state.pageLength = value?.items?.length || 0;
1163
+ this.emit("root-change", value);
1164
+ }
1165
+ }
1166
+ get(name) {
1167
+ return this.state[name];
1168
+ }
1169
+ getNodeInfo(id, raw = true) {
1170
+ let root = this.get("root");
1171
+ if (raw) {
1172
+ root = vue.toRaw(root);
1173
+ }
1174
+ if (!root)
1175
+ return {};
1176
+ if (id === root.id) {
1177
+ return { node: root };
1178
+ }
1179
+ const path = utils.getNodePath(id, root.items);
1180
+ if (!path.length)
1181
+ return {};
1182
+ path.unshift(root);
1183
+ const info = {};
1184
+ info.node = path[path.length - 1];
1185
+ info.parent = path[path.length - 2];
1186
+ path.forEach((item) => {
1187
+ if (item.type === schema.NodeType.PAGE) {
1188
+ info.page = item;
1189
+ return;
1190
+ }
1191
+ });
1192
+ return info;
1193
+ }
1194
+ getNodeById(id, raw = true) {
1195
+ const { node } = this.getNodeInfo(id, raw);
1196
+ return node;
1197
+ }
1198
+ getParentById(id, raw = true) {
1199
+ if (!this.get("root"))
1200
+ return;
1201
+ const { parent } = this.getNodeInfo(id, raw);
1202
+ return parent;
1203
+ }
1204
+ async getLayout(parent, node) {
990
1205
  if (node && typeof node !== "function" && isFixed(node))
991
1206
  return Layout.FIXED;
992
1207
  if (parent.layout) {
@@ -997,9 +1212,9 @@
997
1212
  }
998
1213
  return Layout.ABSOLUTE;
999
1214
  }
1000
- async select(config2) {
1001
- const { node, page, parent } = this.selectedConfigExceptionHandler(config2);
1002
- this.set("node", node);
1215
+ async select(config) {
1216
+ const { node, page, parent } = this.selectedConfigExceptionHandler(config);
1217
+ this.set("nodes", [node]);
1003
1218
  this.set("page", page || null);
1004
1219
  this.set("parent", parent || null);
1005
1220
  if (page) {
@@ -1039,46 +1254,42 @@
1039
1254
  this.get("stage")?.select(nextPage.id);
1040
1255
  return nextPage;
1041
1256
  }
1042
- highlight(config2) {
1043
- const { node } = this.selectedConfigExceptionHandler(config2);
1257
+ highlight(config) {
1258
+ const { node } = this.selectedConfigExceptionHandler(config);
1044
1259
  const currentHighlightNode = this.get("highlightNode");
1045
1260
  if (currentHighlightNode === node)
1046
1261
  return;
1047
1262
  this.set("highlightNode", node);
1048
1263
  }
1264
+ multiSelect(ids) {
1265
+ const nodes = [];
1266
+ const idsUnique = lodashEs.uniq(ids);
1267
+ idsUnique.forEach((id) => {
1268
+ const { node } = this.getNodeInfo(id);
1269
+ if (!node)
1270
+ return;
1271
+ nodes.push(node);
1272
+ });
1273
+ this.set("nodes", nodes);
1274
+ }
1275
+ async multiAdd(configs) {
1276
+ const stage = this.get("stage");
1277
+ const newNodes = await Promise.all(configs.map(async (configItem) => {
1278
+ const { parentNode, newNode, layout } = await beforeAdd(configItem);
1279
+ await notifyAddToStage(parentNode, newNode, layout);
1280
+ return newNode;
1281
+ }));
1282
+ const newNodeIds = newNodes.map((node) => node.id);
1283
+ this.addModifiedNodeId(newNodeIds.join("-"));
1284
+ this.pushHistoryState();
1285
+ stage?.multiSelect(newNodeIds);
1286
+ this.emit("multiAdd", newNodes);
1287
+ return newNodes;
1288
+ }
1049
1289
  async add(addNode, parent) {
1050
- const { type, inputEvent, ...config2 } = addNode;
1051
- const curNode = this.get("node");
1052
- let parentNode;
1053
- const isPage2 = type === schema.NodeType.PAGE;
1054
- if (isPage2) {
1055
- parentNode = this.get("root");
1056
- } else if (parent && typeof parent !== "function") {
1057
- parentNode = parent;
1058
- } else if (curNode.items) {
1059
- parentNode = curNode;
1060
- } else {
1061
- parentNode = this.getParentById(curNode.id, false);
1062
- }
1063
- if (!parentNode)
1064
- throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
1065
- const layout = await this.getLayout(vue.toRaw(parentNode), addNode);
1066
- const newNode = { ...vue.toRaw(await propsService.getPropsValue(type, config2)) };
1067
- newNode.style = getInitPositionStyle(newNode.style, layout, parentNode, this.get("stage"));
1068
- if ((parentNode?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && newNode.type !== schema.NodeType.PAGE) {
1069
- throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
1070
- }
1071
- parentNode?.items?.push(newNode);
1072
1290
  const stage = this.get("stage");
1073
- const root = this.get("root");
1074
- await stage?.add({ config: lodashEs.cloneDeep(newNode), parent: lodashEs.cloneDeep(parentNode), root: lodashEs.cloneDeep(root) });
1075
- if (layout === Layout.ABSOLUTE) {
1076
- const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
1077
- if (typeof fixedLeft !== "undefined") {
1078
- newNode.style.left = fixedLeft;
1079
- await stage?.update({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(root) });
1080
- }
1081
- }
1291
+ const { parentNode, newNode, layout, isPage: isPage2 } = await beforeAdd(addNode, parent);
1292
+ await notifyAddToStage(parentNode, newNode, layout);
1082
1293
  await this.select(newNode);
1083
1294
  this.addModifiedNodeId(newNode.id);
1084
1295
  if (!isPage2) {
@@ -1092,54 +1303,38 @@
1092
1303
  this.emit("add", newNode);
1093
1304
  return newNode;
1094
1305
  }
1095
- async remove(node) {
1096
- if (!node?.id)
1097
- return;
1098
- const root = this.get("root");
1099
- if (!root)
1100
- throw new Error("\u6CA1\u6709root");
1101
- const { parent, node: curNode } = this.getNodeInfo(node.id, false);
1102
- if (!parent || !curNode)
1103
- throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1104
- const index = getNodeIndex(curNode, parent);
1105
- if (typeof index !== "number" || index === -1)
1106
- throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1107
- parent.items?.splice(index, 1);
1108
- const stage = this.get("stage");
1109
- stage?.remove({ id: node.id, root: lodashEs.cloneDeep(this.get("root")) });
1110
- if (node.type === schema.NodeType.PAGE) {
1111
- this.state.pageLength -= 1;
1112
- if (root.items[0]) {
1113
- await this.select(root.items[0]);
1114
- stage?.select(root.items[0].id);
1115
- } else {
1116
- this.set("node", null);
1117
- this.set("parent", null);
1118
- this.set("page", null);
1119
- this.set("stage", null);
1120
- this.set("highlightNode", null);
1121
- this.resetModifiedNodeId();
1122
- historyService.reset();
1123
- this.emit("remove", node);
1124
- return node;
1125
- }
1126
- } else {
1127
- await this.select(parent);
1128
- stage?.select(parent.id);
1306
+ async remove(nodeOrNodeList) {
1307
+ if (Array.isArray(nodeOrNodeList)) {
1308
+ const nodes = nodeOrNodeList;
1309
+ return this.multiRemove(nodes);
1129
1310
  }
1130
- this.addModifiedNodeId(parent.id);
1311
+ const node = nodeOrNodeList;
1312
+ const removeParent = await beforeRemove(node);
1313
+ if (!removeParent)
1314
+ return node;
1315
+ this.addModifiedNodeId(removeParent.id);
1131
1316
  this.pushHistoryState();
1132
1317
  this.emit("remove", node);
1133
1318
  return node;
1134
1319
  }
1135
- async update(config2) {
1136
- if (!config2?.id)
1320
+ async multiRemove(nodes) {
1321
+ await Promise.all(nodes.map(async (removeNode) => {
1322
+ await beforeRemove(removeNode);
1323
+ }));
1324
+ const nodeIds = nodes.map((node) => node.id);
1325
+ this.addModifiedNodeId(nodeIds.join("-"));
1326
+ this.pushHistoryState();
1327
+ this.emit("multiRemove", nodes);
1328
+ return nodes;
1329
+ }
1330
+ async update(config) {
1331
+ if (!config?.id)
1137
1332
  throw new Error("\u6CA1\u6709\u914D\u7F6E\u6216\u8005\u914D\u7F6E\u7F3A\u5C11id\u503C");
1138
- const info = this.getNodeInfo(config2.id, false);
1333
+ const info = this.getNodeInfo(config.id, false);
1139
1334
  if (!info.node)
1140
- throw new Error(`\u83B7\u53D6\u4E0D\u5230id\u4E3A${config2.id}\u7684\u8282\u70B9`);
1335
+ throw new Error(`\u83B7\u53D6\u4E0D\u5230id\u4E3A${config.id}\u7684\u8282\u70B9`);
1141
1336
  const node = lodashEs.cloneDeep(vue.toRaw(info.node));
1142
- let newConfig = await this.toggleFixedPosition(vue.toRaw(config2), node, this.get("root"));
1337
+ let newConfig = await this.toggleFixedPosition(vue.toRaw(config), node, this.get("root"));
1143
1338
  newConfig = lodashEs.mergeWith(lodashEs.cloneDeep(node), newConfig, (objValue, srcValue) => {
1144
1339
  if (Array.isArray(srcValue)) {
1145
1340
  return srcValue;
@@ -1164,9 +1359,10 @@
1164
1359
  newConfig = setLayout(newConfig, newLayout);
1165
1360
  }
1166
1361
  parentNodeItems[index] = newConfig;
1167
- if (`${newConfig.id}` === `${this.get("node").id}`) {
1168
- this.set("node", newConfig);
1169
- }
1362
+ const nodes = this.get("nodes");
1363
+ const targetIndex = nodes.findIndex((nodeItem) => `${nodeItem.id}` === `${newConfig.id}`);
1364
+ nodes.splice(targetIndex, 1, newConfig);
1365
+ this.set("nodes", nodes);
1170
1366
  this.get("stage")?.update({ config: lodashEs.cloneDeep(newConfig), root: lodashEs.cloneDeep(this.get("root")) });
1171
1367
  if (newConfig.type === schema.NodeType.PAGE) {
1172
1368
  this.set("page", newConfig);
@@ -1190,34 +1386,19 @@
1190
1386
  this.addModifiedNodeId(parent.id);
1191
1387
  this.pushHistoryState();
1192
1388
  }
1193
- async copy(config2) {
1194
- globalThis.localStorage.setItem(COPY_STORAGE_KEY, serialize__default["default"](config2));
1389
+ async copy(config) {
1390
+ await storageService.setItem(COPY_STORAGE_KEY, Array.isArray(config) ? config : [config], {
1391
+ protocol: Protocol.OBJECT
1392
+ });
1195
1393
  }
1196
1394
  async paste(position = {}) {
1197
- const configStr = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
1198
- let config = {};
1199
- if (!configStr) {
1200
- return;
1201
- }
1202
- try {
1203
- eval(`config = ${configStr}`);
1204
- } catch (e) {
1205
- console.error(e);
1395
+ const config = await storageService.getItem(COPY_STORAGE_KEY);
1396
+ if (!config)
1206
1397
  return;
1207
- }
1208
- config = await propsService.setNewItemId(config, this.get("root"));
1209
- if (config.style) {
1210
- config.style = {
1211
- ...config.style,
1212
- ...position
1213
- };
1214
- }
1215
- if (utils.isPage(config)) {
1216
- config.name = generatePageNameByApp(this.get("root"));
1217
- }
1218
- return await this.add(config);
1398
+ const pasteConfigs = await beforePaste(position, config);
1399
+ return await this.multiAdd(pasteConfigs);
1219
1400
  }
1220
- async alignCenter(config2) {
1401
+ async alignCenter(config) {
1221
1402
  const parent = this.get("parent");
1222
1403
  const node = this.get("node");
1223
1404
  const layout = await this.getLayout(vue.toRaw(parent), vue.toRaw(node));
@@ -1242,9 +1423,9 @@
1242
1423
  config: lodashEs.cloneDeep(vue.toRaw(node)),
1243
1424
  root: lodashEs.cloneDeep(this.get("root"))
1244
1425
  });
1245
- this.addModifiedNodeId(config2.id);
1426
+ this.addModifiedNodeId(config.id);
1246
1427
  this.pushHistoryState();
1247
- return config2;
1428
+ return config;
1248
1429
  }
1249
1430
  async moveLayer(offset) {
1250
1431
  const parent = this.get("parent");
@@ -1263,8 +1444,8 @@
1263
1444
  root: lodashEs.cloneDeep(this.get("root"))
1264
1445
  });
1265
1446
  }
1266
- async moveToContainer(config2, targetId) {
1267
- const { node, parent } = this.getNodeInfo(config2.id, false);
1447
+ async moveToContainer(config, targetId) {
1448
+ const { node, parent } = this.getNodeInfo(config.id, false);
1268
1449
  const target = this.getNodeById(targetId, false);
1269
1450
  const stage = this.get("stage");
1270
1451
  if (node && parent && stage) {
@@ -1273,7 +1454,7 @@
1273
1454
  parent.items?.splice(index, 1);
1274
1455
  await stage.remove({ id: node.id, root });
1275
1456
  const layout = await this.getLayout(target);
1276
- const newConfig = lodashEs.mergeWith(lodashEs.cloneDeep(node), config2, (objValue, srcValue) => {
1457
+ const newConfig = lodashEs.mergeWith(lodashEs.cloneDeep(node), config, (objValue, srcValue) => {
1277
1458
  if (Array.isArray(srcValue)) {
1278
1459
  return srcValue;
1279
1460
  }
@@ -1324,6 +1505,7 @@
1324
1505
  this.removeAllListeners();
1325
1506
  this.set("root", null);
1326
1507
  this.set("node", null);
1508
+ this.set("nodes", []);
1327
1509
  this.set("page", null);
1328
1510
  this.set("parent", null);
1329
1511
  }
@@ -1370,12 +1552,12 @@
1370
1552
  }
1371
1553
  return newConfig;
1372
1554
  }
1373
- selectedConfigExceptionHandler(config2) {
1555
+ selectedConfigExceptionHandler(config) {
1374
1556
  let id;
1375
- if (typeof config2 === "string" || typeof config2 === "number") {
1376
- id = config2;
1557
+ if (typeof config === "string" || typeof config === "number") {
1558
+ id = config;
1377
1559
  } else {
1378
- id = config2.id;
1560
+ id = config.id;
1379
1561
  }
1380
1562
  if (!id) {
1381
1563
  throw new Error("\u6CA1\u6709ID\uFF0C\u65E0\u6CD5\u9009\u4E2D");
@@ -1393,7 +1575,7 @@
1393
1575
  };
1394
1576
  }
1395
1577
  }
1396
- var editorService = new Editor$1();
1578
+ const editorService = new Editor$1();
1397
1579
 
1398
1580
  const eventMap = vue.reactive({});
1399
1581
  const methodMap = vue.reactive({});
@@ -1437,7 +1619,7 @@
1437
1619
  return lodashEs.cloneDeep(methodMap[type] || core.DEFAULT_METHODS);
1438
1620
  }
1439
1621
  }
1440
- var eventsService = new Events();
1622
+ const eventsService = new Events();
1441
1623
 
1442
1624
  const fillConfig = (config = []) => [
1443
1625
  {
@@ -1645,14 +1827,29 @@
1645
1827
  const DEFAULT_CONFIG = fillConfig([]);
1646
1828
 
1647
1829
  const log = (...args) => {
1830
+ if (process.env.NODE_ENV === "development") {
1831
+ console.log("magic editor: ", ...args);
1832
+ }
1648
1833
  };
1649
1834
  const info = (...args) => {
1835
+ if (process.env.NODE_ENV === "development") {
1836
+ console.info("magic editor: ", ...args);
1837
+ }
1650
1838
  };
1651
1839
  const warn = (...args) => {
1840
+ if (process.env.NODE_ENV === "development") {
1841
+ console.warn("magic editor: ", ...args);
1842
+ }
1652
1843
  };
1653
1844
  const debug = (...args) => {
1845
+ if (process.env.NODE_ENV === "development") {
1846
+ console.debug("magic editor: ", ...args);
1847
+ }
1654
1848
  };
1655
1849
  const error = (...args) => {
1850
+ if (process.env.NODE_ENV === "development") {
1851
+ console.error("magic editor: ", ...args);
1852
+ }
1656
1853
  };
1657
1854
 
1658
1855
  const _sfc_main$i = vue.defineComponent({
@@ -1672,10 +1869,11 @@
1672
1869
  };
1673
1870
  }
1674
1871
  });
1872
+
1675
1873
  const _hoisted_1$b = { class: "m-editor-empty-panel" };
1676
1874
  const _hoisted_2$4 = { class: "m-editor-empty-content" };
1677
1875
  const _hoisted_3$2 = /* @__PURE__ */ vue.createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1678
- function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
1876
+ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
1679
1877
  const _component_plus = vue.resolveComponent("plus");
1680
1878
  const _component_el_icon = vue.resolveComponent("el-icon");
1681
1879
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$b, [
@@ -1697,7 +1895,7 @@
1697
1895
  ])
1698
1896
  ]);
1699
1897
  }
1700
- var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
1898
+ const AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$d]]);
1701
1899
 
1702
1900
  const _sfc_main$h = vue.defineComponent({
1703
1901
  name: "m-editor-resize",
@@ -1713,7 +1911,7 @@
1713
1911
  vue.onMounted(() => {
1714
1912
  if (!target.value)
1715
1913
  return;
1716
- getso = new Gesto__default["default"](target.value, {
1914
+ getso = new Gesto__default.default(target.value, {
1717
1915
  container: window,
1718
1916
  pinchOutside: true
1719
1917
  }).on("drag", (e) => {
@@ -1741,16 +1939,17 @@
1741
1939
  };
1742
1940
  }
1743
1941
  });
1942
+
1744
1943
  const _hoisted_1$a = {
1745
1944
  ref: "target",
1746
1945
  class: "m-editor-resizer"
1747
1946
  };
1748
- function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
1947
+ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
1749
1948
  return vue.openBlock(), vue.createElementBlock("span", _hoisted_1$a, [
1750
1949
  vue.renderSlot(_ctx.$slots, "default")
1751
1950
  ], 512);
1752
1951
  }
1753
- var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
1952
+ const Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$c]]);
1754
1953
 
1755
1954
  const _sfc_main$g = vue.defineComponent({
1756
1955
  components: {
@@ -1781,12 +1980,13 @@
1781
1980
  };
1782
1981
  }
1783
1982
  });
1983
+
1784
1984
  const _hoisted_1$9 = { class: "m-editor" };
1785
1985
  const _hoisted_2$3 = {
1786
1986
  key: 1,
1787
1987
  class: "m-editor-content"
1788
1988
  };
1789
- function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
1989
+ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
1790
1990
  const _component_magic_code_editor = vue.resolveComponent("magic-code-editor");
1791
1991
  const _component_resizer = vue.resolveComponent("resizer");
1792
1992
  const _component_el_scrollbar = vue.resolveComponent("el-scrollbar");
@@ -1832,7 +2032,7 @@
1832
2032
  ]))
1833
2033
  ]);
1834
2034
  }
1835
- var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
2035
+ const Framework = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$b]]);
1836
2036
 
1837
2037
  const _sfc_main$f = vue.defineComponent({
1838
2038
  name: "m-icon",
@@ -1848,8 +2048,9 @@
1848
2048
  };
1849
2049
  }
1850
2050
  });
2051
+
1851
2052
  const _hoisted_1$8 = ["src"];
1852
- function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2053
+ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
1853
2054
  const _component_edit = vue.resolveComponent("edit");
1854
2055
  const _component_el_icon = vue.resolveComponent("el-icon");
1855
2056
  return !_ctx.icon ? (vue.openBlock(), vue.createBlock(_component_el_icon, { key: 0 }, {
@@ -1870,10 +2071,19 @@
1870
2071
  _: 1
1871
2072
  }));
1872
2073
  }
1873
- var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
2074
+ const MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$a]]);
1874
2075
 
1875
- const _sfc_main$e = vue.defineComponent({
1876
- components: { MIcon, ArrowDown: iconsVue.ArrowDown },
2076
+ const _hoisted_1$7 = {
2077
+ key: 1,
2078
+ class: "menu-item-text"
2079
+ };
2080
+ const _hoisted_2$2 = {
2081
+ class: "menu-item-text",
2082
+ style: { "margin": "0 5px" }
2083
+ };
2084
+ const _hoisted_3$1 = { class: "el-dropdown-link menubar-menu-button" };
2085
+ const _sfc_main$e = /* @__PURE__ */ vue.defineComponent({
2086
+ __name: "ToolButton",
1877
2087
  props: {
1878
2088
  data: {
1879
2089
  type: [Object, String],
@@ -1888,7 +2098,8 @@
1888
2098
  default: "click"
1889
2099
  }
1890
2100
  },
1891
- setup(props) {
2101
+ setup(__props) {
2102
+ const props = __props;
1892
2103
  const services = vue.inject("services");
1893
2104
  const uiService = services?.uiService;
1894
2105
  const zoom = vue.computed(() => uiService?.get("zoom") ?? 1);
@@ -1985,176 +2196,155 @@
1985
2196
  item2.handler?.(services, event);
1986
2197
  }
1987
2198
  };
1988
- return {
1989
- ZoomIn: vue.markRaw(iconsVue.ZoomIn),
1990
- ZoomOut: vue.markRaw(iconsVue.ZoomOut),
1991
- item,
1992
- zoom,
1993
- disabled,
1994
- display: vue.computed(() => {
1995
- if (!item.value)
1996
- return false;
1997
- if (typeof item.value === "string")
1998
- return true;
1999
- if (typeof item.value.display === "function") {
2000
- return item.value.display(services);
2001
- }
2002
- return item.value.display ?? true;
2003
- }),
2004
- zoomInHandler,
2005
- zoomOutHandler,
2006
- dropdownHandler(command) {
2007
- if (command.item.handler) {
2008
- command.item.handler(services);
2009
- }
2010
- },
2011
- clickHandler(item2, event) {
2012
- if (props.eventType !== "click")
2013
- return;
2014
- if (item2.type === "button") {
2015
- buttonHandler(item2, event);
2016
- }
2017
- },
2018
- mousedownHandler(item2, event) {
2019
- if (props.eventType !== "mousedown")
2020
- return;
2021
- if (item2.type === "button") {
2022
- buttonHandler(item2, event);
2023
- }
2024
- },
2025
- mouseupHandler(item2, event) {
2026
- if (props.eventType !== "mouseup")
2027
- return;
2028
- if (item2.type === "button") {
2029
- buttonHandler(item2, event);
2030
- }
2199
+ const display = vue.computed(() => {
2200
+ if (!item.value)
2201
+ return false;
2202
+ if (typeof item.value === "string")
2203
+ return true;
2204
+ if (typeof item.value.display === "function") {
2205
+ return item.value.display(services);
2206
+ }
2207
+ return item.value.display ?? true;
2208
+ });
2209
+ const dropdownHandler = (command) => {
2210
+ if (command.item.handler) {
2211
+ command.item.handler(services);
2031
2212
  }
2032
2213
  };
2033
- }
2034
- });
2035
- const _hoisted_1$7 = {
2036
- key: 1,
2037
- class: "menu-item-text"
2038
- };
2039
- const _hoisted_2$2 = {
2040
- class: "menu-item-text",
2041
- style: { "margin": "0 5px" }
2042
- };
2043
- const _hoisted_3$1 = { class: "el-dropdown-link menubar-menu-button" };
2044
- function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2045
- const _component_el_divider = vue.resolveComponent("el-divider");
2046
- const _component_tool_button = vue.resolveComponent("tool-button", true);
2047
- const _component_m_icon = vue.resolveComponent("m-icon");
2048
- const _component_el_button = vue.resolveComponent("el-button");
2049
- const _component_el_tooltip = vue.resolveComponent("el-tooltip");
2050
- const _component_arrow_down = vue.resolveComponent("arrow-down");
2051
- const _component_el_icon = vue.resolveComponent("el-icon");
2052
- const _component_el_dropdown_item = vue.resolveComponent("el-dropdown-item");
2053
- const _component_el_dropdown_menu = vue.resolveComponent("el-dropdown-menu");
2054
- const _component_el_dropdown = vue.resolveComponent("el-dropdown");
2055
- return _ctx.display ? (vue.openBlock(), vue.createElementBlock("div", {
2056
- key: 0,
2057
- class: vue.normalizeClass(["menu-item", _ctx.item.type]),
2058
- onClick: _cache[0] || (_cache[0] = ($event) => _ctx.clickHandler(_ctx.item, $event)),
2059
- onMousedown: _cache[1] || (_cache[1] = ($event) => _ctx.mousedownHandler(_ctx.item, $event)),
2060
- onMouseup: _cache[2] || (_cache[2] = ($event) => _ctx.mouseupHandler(_ctx.item, $event))
2061
- }, [
2062
- _ctx.item.type === "divider" ? (vue.openBlock(), vue.createBlock(_component_el_divider, {
2063
- key: 0,
2064
- direction: _ctx.item.direction || "vertical"
2065
- }, null, 8, ["direction"])) : _ctx.item.type === "text" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$7, vue.toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
2066
- vue.createVNode(_component_tool_button, {
2067
- data: { type: "button", icon: _ctx.ZoomOut, handler: _ctx.zoomOutHandler, tooltip: "\u7F29\u5C0F" },
2068
- "event-type": _ctx.eventType
2069
- }, null, 8, ["data", "event-type"]),
2070
- vue.createElementVNode("span", _hoisted_2$2, vue.toDisplayString(parseInt(`${_ctx.zoom * 100}`, 10)) + "%", 1),
2071
- vue.createVNode(_component_tool_button, {
2072
- data: { type: "button", icon: _ctx.ZoomIn, handler: _ctx.zoomInHandler, tooltip: "\u653E\u5927" },
2073
- "event-type": _ctx.eventType
2074
- }, null, 8, ["data", "event-type"])
2075
- ], 64)) : _ctx.item.type === "button" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 3 }, [
2076
- _ctx.item.tooltip ? (vue.openBlock(), vue.createBlock(_component_el_tooltip, {
2214
+ const clickHandler = (item2, event) => {
2215
+ if (props.eventType !== "click")
2216
+ return;
2217
+ if (item2.type === "button") {
2218
+ buttonHandler(item2, event);
2219
+ }
2220
+ };
2221
+ const mousedownHandler = (item2, event) => {
2222
+ if (props.eventType !== "mousedown")
2223
+ return;
2224
+ if (item2.type === "button") {
2225
+ buttonHandler(item2, event);
2226
+ }
2227
+ };
2228
+ const mouseupHandler = (item2, event) => {
2229
+ if (props.eventType !== "mouseup")
2230
+ return;
2231
+ if (item2.type === "button") {
2232
+ buttonHandler(item2, event);
2233
+ }
2234
+ };
2235
+ return (_ctx, _cache) => {
2236
+ const _component_el_divider = vue.resolveComponent("el-divider");
2237
+ const _component_tool_button = vue.resolveComponent("tool-button", true);
2238
+ const _component_el_button = vue.resolveComponent("el-button");
2239
+ const _component_el_tooltip = vue.resolveComponent("el-tooltip");
2240
+ const _component_el_icon = vue.resolveComponent("el-icon");
2241
+ const _component_el_dropdown_item = vue.resolveComponent("el-dropdown-item");
2242
+ const _component_el_dropdown_menu = vue.resolveComponent("el-dropdown-menu");
2243
+ const _component_el_dropdown = vue.resolveComponent("el-dropdown");
2244
+ return vue.unref(display) ? (vue.openBlock(), vue.createElementBlock("div", {
2077
2245
  key: 0,
2078
- effect: "dark",
2079
- placement: "bottom-start",
2080
- content: _ctx.item.tooltip
2081
- }, {
2082
- default: vue.withCtx(() => [
2083
- vue.createVNode(_component_el_button, {
2246
+ class: vue.normalizeClass(["menu-item", vue.unref(item).type]),
2247
+ onClick: _cache[0] || (_cache[0] = ($event) => clickHandler(vue.unref(item), $event)),
2248
+ onMousedown: _cache[1] || (_cache[1] = ($event) => mousedownHandler(vue.unref(item), $event)),
2249
+ onMouseup: _cache[2] || (_cache[2] = ($event) => mouseupHandler(vue.unref(item), $event))
2250
+ }, [
2251
+ vue.unref(item).type === "divider" ? (vue.openBlock(), vue.createBlock(_component_el_divider, {
2252
+ key: 0,
2253
+ direction: vue.unref(item).direction || "vertical"
2254
+ }, null, 8, ["direction"])) : vue.unref(item).type === "text" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$7, vue.toDisplayString(vue.unref(item).text), 1)) : vue.unref(item).type === "zoom" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
2255
+ vue.createVNode(_component_tool_button, {
2256
+ data: { type: "button", icon: vue.unref(iconsVue.ZoomOut), handler: zoomOutHandler, tooltip: "\u7F29\u5C0F" },
2257
+ "event-type": __props.eventType
2258
+ }, null, 8, ["data", "event-type"]),
2259
+ vue.createElementVNode("span", _hoisted_2$2, vue.toDisplayString(parseInt(`${vue.unref(zoom) * 100}`, 10)) + "%", 1),
2260
+ vue.createVNode(_component_tool_button, {
2261
+ data: { type: "button", icon: vue.unref(iconsVue.ZoomIn), handler: zoomInHandler, tooltip: "\u653E\u5927" },
2262
+ "event-type": __props.eventType
2263
+ }, null, 8, ["data", "event-type"])
2264
+ ], 64)) : vue.unref(item).type === "button" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 3 }, [
2265
+ vue.unref(item).tooltip ? (vue.openBlock(), vue.createBlock(_component_el_tooltip, {
2266
+ key: 0,
2267
+ effect: "dark",
2268
+ placement: "bottom-start",
2269
+ content: vue.unref(item).tooltip
2270
+ }, {
2271
+ default: vue.withCtx(() => [
2272
+ vue.createVNode(_component_el_button, {
2273
+ size: "small",
2274
+ text: "",
2275
+ disabled: vue.unref(disabled)
2276
+ }, {
2277
+ default: vue.withCtx(() => [
2278
+ vue.unref(item).icon ? (vue.openBlock(), vue.createBlock(MIcon, {
2279
+ key: 0,
2280
+ icon: vue.unref(item).icon
2281
+ }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
2282
+ vue.createElementVNode("span", null, vue.toDisplayString(vue.unref(item).text), 1)
2283
+ ]),
2284
+ _: 1
2285
+ }, 8, ["disabled"])
2286
+ ]),
2287
+ _: 1
2288
+ }, 8, ["content"])) : (vue.openBlock(), vue.createBlock(_component_el_button, {
2289
+ key: 1,
2084
2290
  size: "small",
2085
2291
  text: "",
2086
- disabled: _ctx.disabled
2292
+ disabled: vue.unref(disabled)
2087
2293
  }, {
2088
2294
  default: vue.withCtx(() => [
2089
- _ctx.item.icon ? (vue.openBlock(), vue.createBlock(_component_m_icon, {
2295
+ vue.unref(item).icon ? (vue.openBlock(), vue.createBlock(MIcon, {
2090
2296
  key: 0,
2091
- icon: _ctx.item.icon
2297
+ icon: vue.unref(item).icon
2092
2298
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
2093
- vue.createElementVNode("span", null, vue.toDisplayString(_ctx.item.text), 1)
2299
+ vue.createElementVNode("span", null, vue.toDisplayString(vue.unref(item).text), 1)
2094
2300
  ]),
2095
2301
  _: 1
2096
- }, 8, ["disabled"])
2097
- ]),
2098
- _: 1
2099
- }, 8, ["content"])) : (vue.openBlock(), vue.createBlock(_component_el_button, {
2100
- key: 1,
2101
- size: "small",
2102
- text: "",
2103
- disabled: _ctx.disabled
2104
- }, {
2105
- default: vue.withCtx(() => [
2106
- _ctx.item.icon ? (vue.openBlock(), vue.createBlock(_component_m_icon, {
2107
- key: 0,
2108
- icon: _ctx.item.icon
2109
- }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
2110
- vue.createElementVNode("span", null, vue.toDisplayString(_ctx.item.text), 1)
2111
- ]),
2112
- _: 1
2113
- }, 8, ["disabled"]))
2114
- ], 64)) : _ctx.item.type === "dropdown" ? (vue.openBlock(), vue.createBlock(_component_el_dropdown, {
2115
- key: 4,
2116
- trigger: "click",
2117
- disabled: _ctx.disabled,
2118
- onCommand: _ctx.dropdownHandler
2119
- }, {
2120
- dropdown: vue.withCtx(() => [
2121
- _ctx.item.items && _ctx.item.items.length ? (vue.openBlock(), vue.createBlock(_component_el_dropdown_menu, { key: 0 }, {
2302
+ }, 8, ["disabled"]))
2303
+ ], 64)) : vue.unref(item).type === "dropdown" ? (vue.openBlock(), vue.createBlock(_component_el_dropdown, {
2304
+ key: 4,
2305
+ trigger: "click",
2306
+ disabled: vue.unref(disabled),
2307
+ onCommand: dropdownHandler
2308
+ }, {
2309
+ dropdown: vue.withCtx(() => [
2310
+ vue.unref(item).items && vue.unref(item).items.length ? (vue.openBlock(), vue.createBlock(_component_el_dropdown_menu, { key: 0 }, {
2311
+ default: vue.withCtx(() => [
2312
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(item).items, (subItem, index) => {
2313
+ return vue.openBlock(), vue.createBlock(_component_el_dropdown_item, {
2314
+ key: index,
2315
+ command: { item: vue.unref(item), subItem }
2316
+ }, {
2317
+ default: vue.withCtx(() => [
2318
+ vue.createTextVNode(vue.toDisplayString(subItem.text), 1)
2319
+ ]),
2320
+ _: 2
2321
+ }, 1032, ["command"]);
2322
+ }), 128))
2323
+ ]),
2324
+ _: 1
2325
+ })) : vue.createCommentVNode("", true)
2326
+ ]),
2122
2327
  default: vue.withCtx(() => [
2123
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.item.items, (subItem, index) => {
2124
- return vue.openBlock(), vue.createBlock(_component_el_dropdown_item, {
2125
- key: index,
2126
- command: { item: _ctx.item, subItem }
2127
- }, {
2328
+ vue.createElementVNode("span", _hoisted_3$1, [
2329
+ vue.createTextVNode(vue.toDisplayString(vue.unref(item).text), 1),
2330
+ vue.createVNode(_component_el_icon, { class: "el-icon--right" }, {
2128
2331
  default: vue.withCtx(() => [
2129
- vue.createTextVNode(vue.toDisplayString(subItem.text), 1)
2332
+ vue.createVNode(vue.unref(iconsVue.ArrowDown))
2130
2333
  ]),
2131
- _: 2
2132
- }, 1032, ["command"]);
2133
- }), 128))
2334
+ _: 1
2335
+ })
2336
+ ])
2134
2337
  ]),
2135
2338
  _: 1
2136
- })) : vue.createCommentVNode("", true)
2137
- ]),
2138
- default: vue.withCtx(() => [
2139
- vue.createElementVNode("span", _hoisted_3$1, [
2140
- vue.createTextVNode(vue.toDisplayString(_ctx.item.text), 1),
2141
- vue.createVNode(_component_el_icon, { class: "el-icon--right" }, {
2142
- default: vue.withCtx(() => [
2143
- vue.createVNode(_component_arrow_down)
2144
- ]),
2145
- _: 1
2146
- })
2147
- ])
2148
- ]),
2149
- _: 1
2150
- }, 8, ["disabled", "onCommand"])) : _ctx.item.type === "component" ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.item.component), vue.normalizeProps(vue.mergeProps({ key: 5 }, _ctx.item.props || {})), null, 16)) : vue.createCommentVNode("", true)
2151
- ], 34)) : vue.createCommentVNode("", true);
2152
- }
2153
- var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
2339
+ }, 8, ["disabled"])) : vue.unref(item).type === "component" ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(item).component), vue.normalizeProps(vue.mergeProps({ key: 5 }, vue.unref(item).props || {})), null, 16)) : vue.createCommentVNode("", true)
2340
+ ], 34)) : vue.createCommentVNode("", true);
2341
+ };
2342
+ }
2343
+ });
2154
2344
 
2155
2345
  const _sfc_main$d = vue.defineComponent({
2156
2346
  name: "nav-menu",
2157
- components: { ToolButton },
2347
+ components: { ToolButton: _sfc_main$e },
2158
2348
  props: {
2159
2349
  data: {
2160
2350
  type: Object,
@@ -2172,7 +2362,8 @@
2172
2362
  };
2173
2363
  }
2174
2364
  });
2175
- function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2365
+
2366
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
2176
2367
  const _component_tool_button = vue.resolveComponent("tool-button");
2177
2368
  return vue.openBlock(), vue.createElementBlock("div", {
2178
2369
  class: "m-editor-nav-menu",
@@ -2194,7 +2385,7 @@
2194
2385
  }), 128))
2195
2386
  ], 4);
2196
2387
  }
2197
- var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
2388
+ const NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$9]]);
2198
2389
 
2199
2390
  const _sfc_main$c = vue.defineComponent({
2200
2391
  name: "m-editor-props-panel",
@@ -2243,8 +2434,9 @@
2243
2434
  };
2244
2435
  }
2245
2436
  });
2437
+
2246
2438
  const _hoisted_1$6 = { class: "`m-editor-props-panel" };
2247
- function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2439
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
2248
2440
  const _component_m_form = vue.resolveComponent("m-form");
2249
2441
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$6, [
2250
2442
  vue.renderSlot(_ctx.$slots, "props-panel-header"),
@@ -2259,7 +2451,7 @@
2259
2451
  }, null, 8, ["class", "popper-class", "size", "init-values", "config", "onChange"])
2260
2452
  ]);
2261
2453
  }
2262
- var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
2454
+ const PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$8]]);
2263
2455
 
2264
2456
  const _sfc_main$b = vue.defineComponent({
2265
2457
  name: "ui-component-panel",
@@ -2291,7 +2483,7 @@
2291
2483
  dragstartHandler({ text, type, data = {} }, e) {
2292
2484
  if (e.dataTransfer) {
2293
2485
  e.dataTransfer.effectAllowed = "move";
2294
- e.dataTransfer.setData("data", serialize__default["default"]({
2486
+ e.dataTransfer.setData("data", serialize__default.default({
2295
2487
  name: text,
2296
2488
  type,
2297
2489
  ...data
@@ -2327,9 +2519,10 @@
2327
2519
  };
2328
2520
  }
2329
2521
  });
2522
+
2330
2523
  const _hoisted_1$5 = /* @__PURE__ */ vue.createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
2331
2524
  const _hoisted_2$1 = ["onClick", "onDragstart"];
2332
- function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2525
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2333
2526
  const _component_el_input = vue.resolveComponent("el-input");
2334
2527
  const _component_m_icon = vue.resolveComponent("m-icon");
2335
2528
  const _component_el_tooltip = vue.resolveComponent("el-tooltip");
@@ -2401,22 +2594,17 @@
2401
2594
  _: 3
2402
2595
  });
2403
2596
  }
2404
- var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
2597
+ const ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$7]]);
2405
2598
 
2406
- const _sfc_main$a = vue.defineComponent({
2407
- components: { ToolButton },
2599
+ const _sfc_main$a = /* @__PURE__ */ vue.defineComponent({
2600
+ __name: "ContentMenu",
2408
2601
  props: {
2409
- menuData: {
2410
- type: Array,
2411
- default: () => []
2412
- },
2413
- isSubMenu: {
2414
- type: Boolean,
2415
- default: false
2416
- }
2602
+ menuData: { default: () => [] },
2603
+ isSubMenu: { type: Boolean, default: false }
2417
2604
  },
2418
2605
  emits: ["hide", "show"],
2419
- setup(props, { emit }) {
2606
+ setup(__props, { expose, emit }) {
2607
+ const props = __props;
2420
2608
  const menu = vue.ref();
2421
2609
  const subMenu = vue.ref();
2422
2610
  const visible = vue.ref(false);
@@ -2442,6 +2630,36 @@
2442
2630
  }
2443
2631
  hide();
2444
2632
  };
2633
+ const show = (e) => {
2634
+ setTimeout(() => {
2635
+ visible.value = true;
2636
+ vue.nextTick(() => {
2637
+ const menuHeight = menu.value?.clientHeight || 0;
2638
+ let top = e.clientY;
2639
+ if (menuHeight + e.clientY > document.body.clientHeight) {
2640
+ top = document.body.clientHeight - menuHeight;
2641
+ }
2642
+ menuStyle.value = {
2643
+ top: `${top}px`,
2644
+ left: `${e.clientX}px`
2645
+ };
2646
+ emit("show");
2647
+ });
2648
+ }, 300);
2649
+ };
2650
+ const showSubMenu = (item) => {
2651
+ const menuItem = item;
2652
+ if (typeof item !== "object" || !menuItem.items?.length) {
2653
+ return;
2654
+ }
2655
+ subMenuData.value = menuItem.items;
2656
+ if (menu.value) {
2657
+ subMenu.value.show({
2658
+ clientX: menu.value.offsetLeft + menu.value.clientWidth,
2659
+ clientY: menu.value.offsetTop
2660
+ });
2661
+ }
2662
+ };
2445
2663
  vue.onMounted(() => {
2446
2664
  if (props.isSubMenu)
2447
2665
  return;
@@ -2452,81 +2670,47 @@
2452
2670
  return;
2453
2671
  globalThis.removeEventListener("mousedown", hideHandler, true);
2454
2672
  });
2455
- return {
2456
- menu,
2457
- subMenu,
2458
- visible,
2459
- menuStyle,
2460
- subMenuData,
2673
+ expose({
2461
2674
  hide,
2462
- show(e) {
2463
- setTimeout(() => {
2464
- visible.value = true;
2465
- vue.nextTick(() => {
2466
- const menuHeight = menu.value?.clientHeight || 0;
2467
- let top = e.clientY;
2468
- if (menuHeight + e.clientY > document.body.clientHeight) {
2469
- top = document.body.clientHeight - menuHeight;
2470
- }
2471
- menuStyle.value = {
2472
- top: `${top}px`,
2473
- left: `${e.clientX}px`
2474
- };
2475
- emit("show");
2476
- });
2477
- }, 300);
2478
- },
2479
- showSubMenu(item) {
2480
- const menuItem = item;
2481
- if (typeof item !== "object" || !menuItem.items?.length) {
2482
- return;
2483
- }
2484
- subMenuData.value = menuItem.items;
2485
- if (menu.value) {
2486
- subMenu.value.show({
2487
- clientX: menu.value.offsetLeft + menu.value.clientWidth,
2488
- clientY: menu.value.offsetTop
2489
- });
2490
- }
2491
- }
2675
+ show
2676
+ });
2677
+ return (_ctx, _cache) => {
2678
+ const _component_content_menu = vue.resolveComponent("content-menu", true);
2679
+ return __props.menuData.length && visible.value ? (vue.openBlock(), vue.createElementBlock("div", {
2680
+ key: 0,
2681
+ class: "magic-editor-content-menu",
2682
+ ref_key: "menu",
2683
+ ref: menu,
2684
+ style: vue.normalizeStyle(menuStyle.value)
2685
+ }, [
2686
+ vue.createElementVNode("div", null, [
2687
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.menuData, (item, index) => {
2688
+ return vue.openBlock(), vue.createBlock(_sfc_main$e, {
2689
+ "event-type": "mouseup",
2690
+ data: item,
2691
+ key: index,
2692
+ onMouseup: hide,
2693
+ onMouseenter: ($event) => showSubMenu(item)
2694
+ }, null, 8, ["data", "onMouseenter"]);
2695
+ }), 128))
2696
+ ]),
2697
+ (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
2698
+ vue.createVNode(_component_content_menu, {
2699
+ class: "sub-menu",
2700
+ ref_key: "subMenu",
2701
+ ref: subMenu,
2702
+ "menu-data": subMenuData.value,
2703
+ "is-sub-menu": true,
2704
+ onHide: hide
2705
+ }, null, 8, ["menu-data"])
2706
+ ]))
2707
+ ], 4)) : vue.createCommentVNode("", true);
2492
2708
  };
2493
2709
  }
2494
2710
  });
2495
- function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2496
- const _component_tool_button = vue.resolveComponent("tool-button");
2497
- const _component_content_menu = vue.resolveComponent("content-menu", true);
2498
- return _ctx.menuData.length && _ctx.visible ? (vue.openBlock(), vue.createElementBlock("div", {
2499
- key: 0,
2500
- class: "magic-editor-content-menu",
2501
- ref: "menu",
2502
- style: vue.normalizeStyle(_ctx.menuStyle)
2503
- }, [
2504
- vue.createElementVNode("div", null, [
2505
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.menuData, (item, index) => {
2506
- return vue.openBlock(), vue.createBlock(_component_tool_button, {
2507
- "event-type": "mouseup",
2508
- data: item,
2509
- key: index,
2510
- onMouseup: _ctx.hide,
2511
- onMouseenter: ($event) => _ctx.showSubMenu(item)
2512
- }, null, 8, ["data", "onMouseup", "onMouseenter"]);
2513
- }), 128))
2514
- ]),
2515
- (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
2516
- vue.createVNode(_component_content_menu, {
2517
- class: "sub-menu",
2518
- ref: "subMenu",
2519
- "menu-data": _ctx.subMenuData,
2520
- "is-sub-menu": true,
2521
- onHide: _ctx.hide
2522
- }, null, 8, ["menu-data", "onHide"])
2523
- ]))
2524
- ], 4)) : vue.createCommentVNode("", true);
2525
- }
2526
- var ContentMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
2527
2711
 
2528
2712
  const _sfc_main$9 = vue.defineComponent({
2529
- components: { ContentMenu },
2713
+ components: { ContentMenu: _sfc_main$a },
2530
2714
  setup() {
2531
2715
  const services = vue.inject("services");
2532
2716
  const menu = vue.ref();
@@ -2608,7 +2792,8 @@
2608
2792
  };
2609
2793
  }
2610
2794
  });
2611
- function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
2795
+
2796
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
2612
2797
  const _component_content_menu = vue.resolveComponent("content-menu");
2613
2798
  return vue.openBlock(), vue.createBlock(_component_content_menu, {
2614
2799
  "menu-data": _ctx.menuData,
@@ -2616,7 +2801,7 @@
2616
2801
  style: { "overflow": "initial" }
2617
2802
  }, null, 8, ["menu-data"]);
2618
2803
  }
2619
- var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
2804
+ const LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$6]]);
2620
2805
 
2621
2806
  const throttleTime = 150;
2622
2807
  const select = async (data, editorService) => {
@@ -2763,8 +2948,9 @@
2763
2948
  };
2764
2949
  }
2765
2950
  });
2951
+
2766
2952
  const _hoisted_1$4 = ["id", "onMouseenter"];
2767
- function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
2953
+ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2768
2954
  const _component_el_input = vue.resolveComponent("el-input");
2769
2955
  const _component_el_tree = vue.resolveComponent("el-tree");
2770
2956
  const _component_layer_menu = vue.resolveComponent("layer-menu");
@@ -2826,7 +3012,7 @@
2826
3012
  _: 3
2827
3013
  });
2828
3014
  }
2829
- var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3015
+ const LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$5]]);
2830
3016
 
2831
3017
  const _sfc_main$7 = vue.defineComponent({
2832
3018
  components: { MIcon },
@@ -2865,11 +3051,12 @@
2865
3051
  };
2866
3052
  }
2867
3053
  });
3054
+
2868
3055
  const _hoisted_1$3 = {
2869
3056
  key: 1,
2870
3057
  class: "magic-editor-tab-panel-title"
2871
3058
  };
2872
- function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3059
+ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
2873
3060
  const _component_m_icon = vue.resolveComponent("m-icon");
2874
3061
  const _component_el_tab_pane = vue.resolveComponent("el-tab-pane");
2875
3062
  return _ctx.config ? (vue.openBlock(), vue.createBlock(_component_el_tab_pane, {
@@ -2915,7 +3102,7 @@
2915
3102
  _: 3
2916
3103
  }, 8, ["name"])) : vue.createCommentVNode("", true);
2917
3104
  }
2918
- var TabPane = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
3105
+ const TabPane = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$4]]);
2919
3106
 
2920
3107
  const _sfc_main$6 = vue.defineComponent({
2921
3108
  components: { TabPane },
@@ -2936,7 +3123,8 @@
2936
3123
  };
2937
3124
  }
2938
3125
  });
2939
- function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3126
+
3127
+ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
2940
3128
  const _component_tab_pane = vue.resolveComponent("tab-pane");
2941
3129
  const _component_el_tabs = vue.resolveComponent("el-tabs");
2942
3130
  return _ctx.data.type === "tabs" && _ctx.data.items.length ? (vue.openBlock(), vue.createBlock(_component_el_tabs, {
@@ -2971,331 +3159,249 @@
2971
3159
  _: 3
2972
3160
  }, 8, ["modelValue"])) : vue.createCommentVNode("", true);
2973
3161
  }
2974
- var Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$6]]);
3162
+ const Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$3]]);
2975
3163
 
2976
- const useScroll = (root) => {
2977
- const pageBar = vue.ref();
2978
- const itemsContainer = vue.ref();
2979
- const pageBarWidth = vue.ref(0);
2980
- const canScroll = vue.ref(false);
2981
- const itemsContainerWidth = vue.computed(() => pageBarWidth.value - 105);
2982
- let translateLeft = 0;
2983
- const resizeObserver = new ResizeObserver((entries) => {
2984
- for (const { contentRect } of entries) {
2985
- const { width } = contentRect;
2986
- pageBarWidth.value = width || 0;
2987
- setCanScroll();
2988
- }
2989
- });
2990
- const setCanScroll = () => {
2991
- if (itemsContainer.value) {
2992
- canScroll.value = itemsContainer.value.scrollWidth > pageBarWidth.value - 105;
2993
- }
2994
- };
2995
- const scroll = (type) => {
2996
- if (!itemsContainer.value)
2997
- return;
2998
- const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
2999
- if (type === "left") {
3000
- translateLeft += 100;
3001
- if (translateLeft > 0) {
3002
- translateLeft = 0;
3003
- }
3004
- } else if (type === "right") {
3005
- translateLeft -= 100;
3006
- if (-translateLeft > maxScrollLeft) {
3007
- translateLeft = -maxScrollLeft;
3008
- }
3009
- } else if (type === "start") {
3010
- translateLeft = 0;
3011
- } else if (type === "end") {
3012
- translateLeft = -maxScrollLeft;
3013
- }
3014
- itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
3015
- };
3016
- vue.onMounted(() => {
3017
- pageBar.value && resizeObserver.observe(pageBar.value);
3018
- });
3019
- vue.onUnmounted(() => {
3020
- resizeObserver.disconnect();
3021
- });
3022
- vue.watch(() => root.value?.items.length, (length = 0, preLength = 0) => {
3023
- setTimeout(() => {
3024
- setCanScroll();
3025
- if (length < preLength) {
3026
- scroll("start");
3027
- } else {
3028
- scroll("end");
3029
- }
3030
- });
3031
- });
3032
- return {
3033
- pageBar,
3034
- itemsContainer,
3035
- canScroll,
3036
- itemsContainerWidth,
3037
- scroll
3038
- };
3039
- };
3040
- const _sfc_main$5 = vue.defineComponent({
3041
- components: { ArrowLeftBold: iconsVue.ArrowLeftBold, ArrowRightBold: iconsVue.ArrowRightBold, CaretBottom: iconsVue.CaretBottom, Plus: iconsVue.Plus, ToolButton },
3042
- setup() {
3043
- const services = vue.inject("services");
3044
- const editorService = services?.editorService;
3045
- const root = vue.computed(() => editorService?.get("root"));
3046
- return {
3047
- Delete: vue.markRaw(iconsVue.Delete),
3048
- DocumentCopy: vue.markRaw(iconsVue.DocumentCopy),
3049
- ...useScroll(root),
3050
- root,
3051
- page: vue.computed(() => editorService?.get("page")),
3052
- switchPage(page) {
3053
- editorService?.select(page);
3054
- },
3055
- addPage() {
3056
- if (!editorService)
3057
- return;
3058
- const pageConfig = {
3059
- type: schema.NodeType.PAGE,
3060
- name: generatePageNameByApp(vue.toRaw(editorService.get("root")))
3061
- };
3062
- editorService.add(pageConfig);
3063
- },
3064
- copy(node) {
3065
- node && editorService?.copy(node);
3066
- editorService?.paste({
3067
- left: 0,
3068
- top: 0
3069
- });
3070
- },
3071
- remove(node) {
3072
- editorService?.remove(node);
3073
- }
3074
- };
3075
- }
3076
- });
3077
3164
  const _hoisted_1$2 = {
3078
3165
  class: "m-editor-page-bar",
3079
3166
  ref: "pageBar"
3080
3167
  };
3081
3168
  const _hoisted_2 = ["onClick"];
3082
3169
  const _hoisted_3 = { class: "m-editor-page-bar-title" };
3083
- function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3084
- const _component_plus = vue.resolveComponent("plus");
3085
- const _component_el_icon = vue.resolveComponent("el-icon");
3086
- const _component_arrow_left_bold = vue.resolveComponent("arrow-left-bold");
3087
- const _component_el_tooltip = vue.resolveComponent("el-tooltip");
3088
- const _component_tool_button = vue.resolveComponent("tool-button");
3089
- const _component_caret_bottom = vue.resolveComponent("caret-bottom");
3090
- const _component_el_popover = vue.resolveComponent("el-popover");
3091
- const _component_arrow_right_bold = vue.resolveComponent("arrow-right-bold");
3092
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
3093
- vue.createElementVNode("div", {
3094
- id: "m-editor-page-bar-add-icon",
3095
- class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3096
- onClick: _cache[0] || (_cache[0] = (...args) => _ctx.addPage && _ctx.addPage(...args))
3097
- }, [
3098
- vue.createVNode(_component_el_icon, null, {
3099
- default: vue.withCtx(() => [
3100
- vue.createVNode(_component_plus)
3101
- ]),
3102
- _: 1
3103
- })
3104
- ]),
3105
- _ctx.canScroll ? (vue.openBlock(), vue.createElementBlock("div", {
3106
- key: 0,
3107
- class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3108
- onClick: _cache[1] || (_cache[1] = ($event) => _ctx.scroll("left"))
3109
- }, [
3110
- vue.createVNode(_component_el_icon, null, {
3111
- default: vue.withCtx(() => [
3112
- vue.createVNode(_component_arrow_left_bold)
3170
+ const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
3171
+ __name: "PageBar",
3172
+ setup(__props) {
3173
+ const useScroll = (root2) => {
3174
+ const pageBar = vue.ref();
3175
+ const itemsContainer = vue.ref();
3176
+ const pageBarWidth = vue.ref(0);
3177
+ const canScroll = vue.ref(false);
3178
+ const itemsContainerWidth = vue.computed(() => pageBarWidth.value - 105);
3179
+ let translateLeft = 0;
3180
+ const resizeObserver = new ResizeObserver((entries) => {
3181
+ for (const { contentRect } of entries) {
3182
+ const { width } = contentRect;
3183
+ pageBarWidth.value = width || 0;
3184
+ setCanScroll();
3185
+ }
3186
+ });
3187
+ const setCanScroll = () => {
3188
+ if (itemsContainer.value) {
3189
+ canScroll.value = itemsContainer.value.scrollWidth > pageBarWidth.value - 105;
3190
+ }
3191
+ };
3192
+ const scroll = (type) => {
3193
+ if (!itemsContainer.value)
3194
+ return;
3195
+ const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
3196
+ if (type === "left") {
3197
+ translateLeft += 100;
3198
+ if (translateLeft > 0) {
3199
+ translateLeft = 0;
3200
+ }
3201
+ } else if (type === "right") {
3202
+ translateLeft -= 100;
3203
+ if (-translateLeft > maxScrollLeft) {
3204
+ translateLeft = -maxScrollLeft;
3205
+ }
3206
+ } else if (type === "start") {
3207
+ translateLeft = 0;
3208
+ } else if (type === "end") {
3209
+ translateLeft = -maxScrollLeft;
3210
+ }
3211
+ itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
3212
+ };
3213
+ vue.onMounted(() => {
3214
+ pageBar.value && resizeObserver.observe(pageBar.value);
3215
+ });
3216
+ vue.onUnmounted(() => {
3217
+ resizeObserver.disconnect();
3218
+ });
3219
+ vue.watch(() => root2.value?.items.length, (length = 0, preLength = 0) => {
3220
+ setTimeout(() => {
3221
+ setCanScroll();
3222
+ if (length < preLength) {
3223
+ scroll("start");
3224
+ } else {
3225
+ scroll("end");
3226
+ }
3227
+ });
3228
+ });
3229
+ return {
3230
+ pageBar,
3231
+ itemsContainer,
3232
+ canScroll,
3233
+ itemsContainerWidth,
3234
+ scroll
3235
+ };
3236
+ };
3237
+ const services = vue.inject("services");
3238
+ const editorService = services?.editorService;
3239
+ const root = vue.computed(() => editorService?.get("root"));
3240
+ const scrollState = useScroll(root);
3241
+ const page = vue.computed(() => editorService?.get("page"));
3242
+ const switchPage = (page2) => {
3243
+ editorService?.select(page2);
3244
+ };
3245
+ const addPage = () => {
3246
+ if (!editorService)
3247
+ return;
3248
+ const pageConfig = {
3249
+ type: schema.NodeType.PAGE,
3250
+ name: generatePageNameByApp(vue.toRaw(editorService.get("root")))
3251
+ };
3252
+ editorService.add(pageConfig);
3253
+ };
3254
+ const copy = (node) => {
3255
+ node && editorService?.copy(node);
3256
+ editorService?.paste({
3257
+ left: 0,
3258
+ top: 0
3259
+ });
3260
+ };
3261
+ const remove = (node) => {
3262
+ editorService?.remove(node);
3263
+ };
3264
+ return (_ctx, _cache) => {
3265
+ const _component_el_icon = vue.resolveComponent("el-icon");
3266
+ const _component_el_tooltip = vue.resolveComponent("el-tooltip");
3267
+ const _component_el_popover = vue.resolveComponent("el-popover");
3268
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
3269
+ vue.createElementVNode("div", {
3270
+ id: "m-editor-page-bar-add-icon",
3271
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3272
+ onClick: addPage
3273
+ }, [
3274
+ vue.createVNode(_component_el_icon, null, {
3275
+ default: vue.withCtx(() => [
3276
+ vue.createVNode(vue.unref(iconsVue.Plus))
3277
+ ]),
3278
+ _: 1
3279
+ })
3113
3280
  ]),
3114
- _: 1
3115
- })
3116
- ])) : vue.createCommentVNode("", true),
3117
- _ctx.root ? (vue.openBlock(), vue.createElementBlock("div", {
3118
- key: 1,
3119
- class: "m-editor-page-bar-items",
3120
- ref: "itemsContainer",
3121
- style: vue.normalizeStyle(`width: ${_ctx.itemsContainerWidth}px`)
3122
- }, [
3123
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.root.items, (item) => {
3124
- return vue.openBlock(), vue.createElementBlock("div", {
3125
- key: item.key,
3126
- class: vue.normalizeClass(["m-editor-page-bar-item", { active: _ctx.page?.id === item.id }]),
3127
- onClick: ($event) => _ctx.switchPage(item)
3281
+ vue.unref(scrollState).canScroll ? (vue.openBlock(), vue.createElementBlock("div", {
3282
+ key: 0,
3283
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3284
+ onClick: _cache[0] || (_cache[0] = ($event) => vue.unref(scrollState).scroll("left"))
3285
+ }, [
3286
+ vue.createVNode(_component_el_icon, null, {
3287
+ default: vue.withCtx(() => [
3288
+ vue.createVNode(vue.unref(iconsVue.ArrowLeftBold))
3289
+ ]),
3290
+ _: 1
3291
+ })
3292
+ ])) : vue.createCommentVNode("", true),
3293
+ vue.unref(root) ? (vue.openBlock(), vue.createElementBlock("div", {
3294
+ key: 1,
3295
+ class: "m-editor-page-bar-items",
3296
+ ref: "itemsContainer",
3297
+ style: vue.normalizeStyle(`width: ${vue.unref(scrollState).itemsContainerWidth}px`)
3128
3298
  }, [
3129
- vue.createElementVNode("div", _hoisted_3, [
3130
- vue.renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
3131
- vue.createVNode(_component_el_tooltip, {
3132
- effect: "dark",
3133
- placement: "top-start",
3134
- content: item.name
3299
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(root).items, (item) => {
3300
+ return vue.openBlock(), vue.createElementBlock("div", {
3301
+ key: item.key,
3302
+ class: vue.normalizeClass(["m-editor-page-bar-item", { active: vue.unref(page)?.id === item.id }]),
3303
+ onClick: ($event) => switchPage(item)
3304
+ }, [
3305
+ vue.createElementVNode("div", _hoisted_3, [
3306
+ vue.renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
3307
+ vue.createVNode(_component_el_tooltip, {
3308
+ effect: "dark",
3309
+ placement: "top-start",
3310
+ content: item.name
3311
+ }, {
3312
+ default: vue.withCtx(() => [
3313
+ vue.createElementVNode("span", null, vue.toDisplayString(item.name), 1)
3314
+ ]),
3315
+ _: 2
3316
+ }, 1032, ["content"])
3317
+ ])
3318
+ ]),
3319
+ vue.createVNode(_component_el_popover, {
3320
+ "popper-class": "page-bar-popover",
3321
+ placement: "top",
3322
+ width: 160,
3323
+ trigger: "hover"
3135
3324
  }, {
3136
- default: vue.withCtx(() => [
3137
- vue.createElementVNode("span", null, vue.toDisplayString(item.name), 1)
3325
+ reference: vue.withCtx(() => [
3326
+ vue.createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-icon" }, {
3327
+ default: vue.withCtx(() => [
3328
+ vue.createVNode(vue.unref(iconsVue.CaretBottom))
3329
+ ]),
3330
+ _: 1
3331
+ })
3138
3332
  ]),
3139
- _: 2
3140
- }, 1032, ["content"])
3141
- ])
3142
- ]),
3143
- vue.createVNode(_component_el_popover, {
3144
- "popper-class": "page-bar-popover",
3145
- placement: "top",
3146
- width: 160,
3147
- trigger: "hover"
3148
- }, {
3149
- reference: vue.withCtx(() => [
3150
- vue.createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-icon" }, {
3151
3333
  default: vue.withCtx(() => [
3152
- vue.createVNode(_component_caret_bottom)
3334
+ vue.createElementVNode("div", null, [
3335
+ vue.renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3336
+ vue.createVNode(_sfc_main$e, {
3337
+ data: {
3338
+ type: "button",
3339
+ text: "\u590D\u5236",
3340
+ icon: vue.unref(iconsVue.DocumentCopy),
3341
+ handler: () => copy(item)
3342
+ }
3343
+ }, null, 8, ["data"]),
3344
+ vue.createVNode(_sfc_main$e, {
3345
+ data: {
3346
+ type: "button",
3347
+ text: "\u5220\u9664",
3348
+ icon: vue.unref(iconsVue.Delete),
3349
+ handler: () => remove(item)
3350
+ }
3351
+ }, null, 8, ["data"])
3352
+ ])
3353
+ ])
3153
3354
  ]),
3154
- _: 1
3155
- })
3156
- ]),
3355
+ _: 2
3356
+ }, 1024)
3357
+ ], 10, _hoisted_2);
3358
+ }), 128))
3359
+ ], 4)) : vue.createCommentVNode("", true),
3360
+ vue.unref(scrollState).canScroll ? (vue.openBlock(), vue.createElementBlock("div", {
3361
+ key: 2,
3362
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3363
+ onClick: _cache[1] || (_cache[1] = ($event) => vue.unref(scrollState).scroll("right"))
3364
+ }, [
3365
+ vue.createVNode(_component_el_icon, null, {
3157
3366
  default: vue.withCtx(() => [
3158
- vue.createElementVNode("div", null, [
3159
- vue.renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3160
- vue.createVNode(_component_tool_button, {
3161
- data: {
3162
- type: "button",
3163
- text: "\u590D\u5236",
3164
- icon: _ctx.DocumentCopy,
3165
- handler: () => _ctx.copy(item)
3166
- }
3167
- }, null, 8, ["data"]),
3168
- vue.createVNode(_component_tool_button, {
3169
- data: {
3170
- type: "button",
3171
- text: "\u5220\u9664",
3172
- icon: _ctx.Delete,
3173
- handler: () => _ctx.remove(item)
3174
- }
3175
- }, null, 8, ["data"])
3176
- ])
3177
- ])
3367
+ vue.createVNode(vue.unref(iconsVue.ArrowRightBold))
3178
3368
  ]),
3179
- _: 2
3180
- }, 1024)
3181
- ], 10, _hoisted_2);
3182
- }), 128))
3183
- ], 4)) : vue.createCommentVNode("", true),
3184
- _ctx.canScroll ? (vue.openBlock(), vue.createElementBlock("div", {
3185
- key: 2,
3186
- class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3187
- onClick: _cache[2] || (_cache[2] = ($event) => _ctx.scroll("right"))
3188
- }, [
3189
- vue.createVNode(_component_el_icon, null, {
3190
- default: vue.withCtx(() => [
3191
- vue.createVNode(_component_arrow_right_bold)
3192
- ]),
3193
- _: 1
3194
- })
3195
- ])) : vue.createCommentVNode("", true)
3196
- ], 512);
3197
- }
3198
- var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3369
+ _: 1
3370
+ })
3371
+ ])) : vue.createCommentVNode("", true)
3372
+ ], 512);
3373
+ };
3374
+ }
3375
+ });
3199
3376
 
3200
3377
  class ScrollViewer$1 {
3201
- constructor(options) {
3202
- this.enter = false;
3203
- this.targetEnter = false;
3204
- this.keydown = false;
3205
- this.zoom = 1;
3206
- this.scrollLeft = 0;
3207
- this.scrollTop = 0;
3208
- this.x = 0;
3209
- this.y = 0;
3210
- this.resizeObserver = new ResizeObserver((entries) => {
3211
- for (const { contentRect } of entries) {
3212
- const { width, height } = contentRect;
3213
- const targetRect = this.target.getBoundingClientRect();
3214
- const targetWidth = targetRect.width * this.zoom;
3215
- const targetMarginTop = Number(this.target.style.marginTop) || 0;
3216
- const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3217
- if (targetWidth < width) {
3218
- this.target._left = 0;
3219
- }
3220
- if (targetHeight < height) {
3221
- this.target._top = 0;
3222
- }
3223
- this.scroll();
3224
- }
3225
- });
3226
- this.wheelHandler = (event) => {
3227
- if (this.targetEnter)
3228
- return;
3229
- const { deltaX, deltaY, currentTarget } = event;
3230
- if (currentTarget !== this.container)
3231
- return;
3232
- this.setScrollOffset(deltaX, deltaY);
3233
- this.scroll();
3234
- this.scrollLeft = this.target._left;
3235
- this.scrollTop = this.target._top;
3236
- };
3237
- this.mouseEnterHandler = () => {
3238
- this.enter = true;
3239
- };
3240
- this.mouseLeaveHandler = () => {
3241
- this.enter = false;
3242
- };
3243
- this.targetMouseEnterHandler = () => {
3244
- this.targetEnter = true;
3245
- };
3246
- this.targetMouseLeaveHandler = () => {
3247
- this.targetEnter = false;
3248
- };
3249
- this.mousedownHandler = (event) => {
3250
- if (!this.keydown)
3251
- return;
3252
- event.stopImmediatePropagation();
3253
- event.stopPropagation();
3254
- this.target.style.cursor = "grabbing";
3255
- this.x = event.clientX;
3256
- this.y = event.clientY;
3257
- document.addEventListener("mousemove", this.mousemoveHandler);
3258
- document.addEventListener("mouseup", this.mouseupHandler);
3259
- };
3260
- this.mouseupHandler = () => {
3261
- this.x = 0;
3262
- this.y = 0;
3263
- this.scrollLeft = this.target._left;
3264
- this.scrollTop = this.target._top;
3265
- this.removeHandler();
3266
- };
3267
- this.mousemoveHandler = (event) => {
3268
- event.stopImmediatePropagation();
3269
- event.stopPropagation();
3270
- const deltaX = event.clientX - this.x;
3271
- const deltaY = event.clientY - this.y;
3272
- this.setScrollOffset(deltaX, deltaY);
3273
- this.scroll();
3274
- };
3275
- this.keydownHandler = (event) => {
3276
- if (event.code === Keys.ESCAPE && this.enter) {
3277
- event.preventDefault();
3278
- event.stopImmediatePropagation();
3279
- event.stopPropagation();
3378
+ enter = false;
3379
+ targetEnter = false;
3380
+ keydown = false;
3381
+ container;
3382
+ target;
3383
+ zoom = 1;
3384
+ scrollLeft = 0;
3385
+ scrollTop = 0;
3386
+ x = 0;
3387
+ y = 0;
3388
+ resizeObserver = new ResizeObserver((entries) => {
3389
+ for (const { contentRect } of entries) {
3390
+ const { width, height } = contentRect;
3391
+ const targetRect = this.target.getBoundingClientRect();
3392
+ const targetWidth = targetRect.width * this.zoom;
3393
+ const targetMarginTop = Number(this.target.style.marginTop) || 0;
3394
+ const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3395
+ if (targetWidth < width) {
3396
+ this.target._left = 0;
3280
3397
  }
3281
- if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3282
- return;
3398
+ if (targetHeight < height) {
3399
+ this.target._top = 0;
3283
3400
  }
3284
- this.keydown = true;
3285
- this.target.style.cursor = "grab";
3286
- this.container.addEventListener("mousedown", this.mousedownHandler);
3287
- };
3288
- this.keyupHandler = (event) => {
3289
- if (event.code !== Keys.ESCAPE || !this.keydown) {
3290
- return;
3291
- }
3292
- event.preventDefault();
3293
- event.stopImmediatePropagation();
3294
- event.stopPropagation();
3295
- this.keydown = false;
3296
- event.preventDefault();
3297
- this.removeHandler();
3298
- };
3401
+ this.scroll();
3402
+ }
3403
+ });
3404
+ constructor(options) {
3299
3405
  this.container = options.container;
3300
3406
  this.target = options.target;
3301
3407
  this.zoom = options.zoom;
@@ -3331,6 +3437,79 @@
3331
3437
  document.removeEventListener("mousemove", this.mousemoveHandler);
3332
3438
  document.removeEventListener("mouseup", this.mouseupHandler);
3333
3439
  }
3440
+ wheelHandler = (event) => {
3441
+ if (this.targetEnter)
3442
+ return;
3443
+ const { deltaX, deltaY, currentTarget } = event;
3444
+ if (currentTarget !== this.container)
3445
+ return;
3446
+ this.setScrollOffset(deltaX, deltaY);
3447
+ this.scroll();
3448
+ this.scrollLeft = this.target._left;
3449
+ this.scrollTop = this.target._top;
3450
+ };
3451
+ mouseEnterHandler = () => {
3452
+ this.enter = true;
3453
+ };
3454
+ mouseLeaveHandler = () => {
3455
+ this.enter = false;
3456
+ };
3457
+ targetMouseEnterHandler = () => {
3458
+ this.targetEnter = true;
3459
+ };
3460
+ targetMouseLeaveHandler = () => {
3461
+ this.targetEnter = false;
3462
+ };
3463
+ mousedownHandler = (event) => {
3464
+ if (!this.keydown)
3465
+ return;
3466
+ event.stopImmediatePropagation();
3467
+ event.stopPropagation();
3468
+ this.target.style.cursor = "grabbing";
3469
+ this.x = event.clientX;
3470
+ this.y = event.clientY;
3471
+ document.addEventListener("mousemove", this.mousemoveHandler);
3472
+ document.addEventListener("mouseup", this.mouseupHandler);
3473
+ };
3474
+ mouseupHandler = () => {
3475
+ this.x = 0;
3476
+ this.y = 0;
3477
+ this.scrollLeft = this.target._left;
3478
+ this.scrollTop = this.target._top;
3479
+ this.removeHandler();
3480
+ };
3481
+ mousemoveHandler = (event) => {
3482
+ event.stopImmediatePropagation();
3483
+ event.stopPropagation();
3484
+ const deltaX = event.clientX - this.x;
3485
+ const deltaY = event.clientY - this.y;
3486
+ this.setScrollOffset(deltaX, deltaY);
3487
+ this.scroll();
3488
+ };
3489
+ keydownHandler = (event) => {
3490
+ if (event.code === Keys.ESCAPE && this.enter) {
3491
+ event.preventDefault();
3492
+ event.stopImmediatePropagation();
3493
+ event.stopPropagation();
3494
+ }
3495
+ if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3496
+ return;
3497
+ }
3498
+ this.keydown = true;
3499
+ this.target.style.cursor = "grab";
3500
+ this.container.addEventListener("mousedown", this.mousedownHandler);
3501
+ };
3502
+ keyupHandler = (event) => {
3503
+ if (event.code !== Keys.ESCAPE || !this.keydown) {
3504
+ return;
3505
+ }
3506
+ event.preventDefault();
3507
+ event.stopImmediatePropagation();
3508
+ event.stopPropagation();
3509
+ this.keydown = false;
3510
+ event.preventDefault();
3511
+ this.removeHandler();
3512
+ };
3334
3513
  setScrollOffset(deltaX, deltaY) {
3335
3514
  const { width, height } = this.container.getBoundingClientRect();
3336
3515
  const targetRect = this.target.getBoundingClientRect();
@@ -3398,11 +3577,12 @@
3398
3577
  };
3399
3578
  }
3400
3579
  });
3580
+
3401
3581
  const _hoisted_1$1 = {
3402
3582
  class: "m-editor-scroll-viewer-container",
3403
3583
  ref: "container"
3404
3584
  };
3405
- function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3585
+ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3406
3586
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
3407
3587
  vue.createElementVNode("div", {
3408
3588
  ref: "el",
@@ -3412,170 +3592,172 @@
3412
3592
  ], 4)
3413
3593
  ], 512);
3414
3594
  }
3415
- var ScrollViewer = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$4]]);
3595
+ const ScrollViewer = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$2]]);
3416
3596
 
3417
- const _sfc_main$3 = vue.defineComponent({
3418
- components: { ContentMenu },
3419
- setup() {
3597
+ const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
3598
+ __name: "ViewerMenu",
3599
+ props: {
3600
+ isMultiSelect: { type: Boolean, default: false }
3601
+ },
3602
+ setup(__props, { expose }) {
3603
+ const props = __props;
3420
3604
  const services = vue.inject("services");
3421
3605
  const editorService = services?.editorService;
3422
3606
  const menu = vue.ref();
3423
3607
  const canPaste = vue.ref(false);
3424
3608
  const canCenter = vue.ref(false);
3425
3609
  const node = vue.computed(() => editorService?.get("node"));
3610
+ const nodes = vue.computed(() => editorService?.get("nodes"));
3426
3611
  const parent = vue.computed(() => editorService?.get("parent"));
3427
- const isPage = vue.computed(() => node.value?.type === schema.NodeType.PAGE);
3612
+ const stage = vue.computed(() => editorService?.get("stage"));
3428
3613
  const stageContentMenu = vue.inject("stageContentMenu", []);
3429
- vue.onMounted(() => {
3430
- const data = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
3614
+ const menuData = vue.reactive([
3615
+ {
3616
+ type: "button",
3617
+ text: "\u6C34\u5E73\u5C45\u4E2D",
3618
+ display: () => canCenter.value && !props.isMultiSelect,
3619
+ handler: () => {
3620
+ if (!node.value)
3621
+ return;
3622
+ editorService?.alignCenter(node.value);
3623
+ }
3624
+ },
3625
+ {
3626
+ type: "button",
3627
+ text: "\u590D\u5236",
3628
+ icon: vue.markRaw(iconsVue.DocumentCopy),
3629
+ handler: () => {
3630
+ nodes.value && editorService?.copy(nodes.value);
3631
+ canPaste.value = true;
3632
+ }
3633
+ },
3634
+ {
3635
+ type: "button",
3636
+ text: "\u7C98\u8D34",
3637
+ display: () => canPaste.value,
3638
+ handler: () => {
3639
+ const rect = menu.value?.$el.getBoundingClientRect();
3640
+ const parentRect = stage.value?.container?.getBoundingClientRect();
3641
+ const initialLeft = (rect?.left || 0) - (parentRect?.left || 0);
3642
+ const initialTop = (rect?.top || 0) - (parentRect?.top || 0);
3643
+ if (!nodes.value || nodes.value.length === 0)
3644
+ return;
3645
+ editorService?.paste({ left: initialLeft, top: initialTop });
3646
+ }
3647
+ },
3648
+ {
3649
+ type: "divider",
3650
+ direction: "horizontal",
3651
+ display: () => {
3652
+ if (!node.value)
3653
+ return false;
3654
+ return !utils.isPage(node.value);
3655
+ }
3656
+ },
3657
+ {
3658
+ type: "button",
3659
+ text: "\u4E0A\u79FB\u4E00\u5C42",
3660
+ icon: vue.markRaw(iconsVue.Top),
3661
+ display: () => !utils.isPage(node.value) && !props.isMultiSelect,
3662
+ handler: () => {
3663
+ editorService?.moveLayer(1);
3664
+ }
3665
+ },
3666
+ {
3667
+ type: "button",
3668
+ text: "\u4E0B\u79FB\u4E00\u5C42",
3669
+ icon: vue.markRaw(iconsVue.Bottom),
3670
+ display: () => !utils.isPage(node.value) && !props.isMultiSelect,
3671
+ handler: () => {
3672
+ editorService?.moveLayer(-1);
3673
+ }
3674
+ },
3675
+ {
3676
+ type: "button",
3677
+ text: "\u7F6E\u9876",
3678
+ display: () => !utils.isPage(node.value) && !props.isMultiSelect,
3679
+ handler: () => {
3680
+ editorService?.moveLayer(LayerOffset.TOP);
3681
+ }
3682
+ },
3683
+ {
3684
+ type: "button",
3685
+ text: "\u7F6E\u5E95",
3686
+ display: () => !utils.isPage(node.value) && !props.isMultiSelect,
3687
+ handler: () => {
3688
+ editorService?.moveLayer(LayerOffset.BOTTOM);
3689
+ }
3690
+ },
3691
+ {
3692
+ type: "divider",
3693
+ direction: "horizontal",
3694
+ display: () => !utils.isPage(node.value) && !props.isMultiSelect
3695
+ },
3696
+ {
3697
+ type: "button",
3698
+ text: "\u5220\u9664",
3699
+ icon: iconsVue.Delete,
3700
+ display: () => !utils.isPage(node.value),
3701
+ handler: () => {
3702
+ nodes.value && editorService?.remove(nodes.value);
3703
+ }
3704
+ },
3705
+ {
3706
+ type: "divider",
3707
+ direction: "horizontal"
3708
+ },
3709
+ {
3710
+ type: "button",
3711
+ text: "\u6E05\u7A7A\u53C2\u8003\u7EBF",
3712
+ handler: () => {
3713
+ editorService?.get("stage").clearGuides();
3714
+ }
3715
+ },
3716
+ ...stageContentMenu
3717
+ ]);
3718
+ vue.onMounted(async () => {
3719
+ const data = await storageService.getItem(COPY_STORAGE_KEY);
3431
3720
  canPaste.value = data !== "undefined" && !!data;
3432
3721
  });
3433
3722
  vue.watch(parent, async () => {
3434
3723
  if (!parent.value || !editorService)
3435
3724
  return canCenter.value = false;
3436
3725
  const layout = await editorService.getLayout(parent.value);
3437
- canCenter.value = [Layout.ABSOLUTE, Layout.FIXED].includes(layout) && ![schema.NodeType.ROOT, schema.NodeType.PAGE, "pop"].includes(`${node.value?.type}`);
3726
+ const isLayoutConform = [Layout.ABSOLUTE, Layout.FIXED].includes(layout);
3727
+ const isTypeConform = nodes.value?.every((selectedNode) => ![schema.NodeType.ROOT, schema.NodeType.PAGE, "pop"].includes(`${selectedNode?.type}`));
3728
+ canCenter.value = isLayoutConform && !!isTypeConform;
3438
3729
  }, { immediate: true });
3439
- return {
3440
- menu,
3441
- menuData: vue.reactive([
3442
- {
3443
- type: "button",
3444
- text: "\u6C34\u5E73\u5C45\u4E2D",
3445
- display: () => canCenter.value,
3446
- handler: () => {
3447
- node.value && editorService?.alignCenter(node.value);
3448
- }
3449
- },
3450
- {
3451
- type: "button",
3452
- text: "\u590D\u5236",
3453
- icon: vue.markRaw(iconsVue.DocumentCopy),
3454
- handler: () => {
3455
- node.value && editorService?.copy(node.value);
3456
- canPaste.value = true;
3457
- }
3458
- },
3459
- {
3460
- type: "button",
3461
- text: "\u7C98\u8D34",
3462
- display: () => canPaste.value,
3463
- handler: () => {
3464
- const stage = editorService?.get("stage");
3465
- const rect = menu.value?.$el.getBoundingClientRect();
3466
- const parentRect = stage?.container?.getBoundingClientRect();
3467
- let left = (rect?.left || 0) - (parentRect?.left || 0);
3468
- let top = (rect?.top || 0) - (parentRect?.top || 0);
3469
- if (node.value?.items && stage) {
3470
- const parentEl = stage.renderer.contentWindow?.document.getElementById(`${node.value.id}`);
3471
- const parentElRect = parentEl?.getBoundingClientRect();
3472
- left = left - (parentElRect?.left || 0);
3473
- top = top - (parentElRect?.top || 0);
3474
- }
3475
- editorService?.paste({ left, top });
3476
- }
3477
- },
3478
- {
3479
- type: "divider",
3480
- direction: "horizontal",
3481
- display: () => !isPage.value
3482
- },
3483
- {
3484
- type: "button",
3485
- text: "\u4E0A\u79FB\u4E00\u5C42",
3486
- icon: vue.markRaw(iconsVue.Top),
3487
- display: () => !isPage.value,
3488
- handler: () => {
3489
- editorService?.moveLayer(1);
3490
- }
3491
- },
3492
- {
3493
- type: "button",
3494
- text: "\u4E0B\u79FB\u4E00\u5C42",
3495
- icon: vue.markRaw(iconsVue.Bottom),
3496
- display: () => !isPage.value,
3497
- handler: () => {
3498
- editorService?.moveLayer(-1);
3499
- }
3500
- },
3501
- {
3502
- type: "button",
3503
- text: "\u7F6E\u9876",
3504
- display: () => !isPage.value,
3505
- handler: () => {
3506
- editorService?.moveLayer(LayerOffset.TOP);
3507
- }
3508
- },
3509
- {
3510
- type: "button",
3511
- text: "\u7F6E\u5E95",
3512
- display: () => !isPage.value,
3513
- handler: () => {
3514
- editorService?.moveLayer(LayerOffset.BOTTOM);
3515
- }
3516
- },
3517
- {
3518
- type: "divider",
3519
- direction: "horizontal",
3520
- display: () => !isPage.value
3521
- },
3522
- {
3523
- type: "button",
3524
- text: "\u5220\u9664",
3525
- icon: iconsVue.Delete,
3526
- display: () => !isPage.value,
3527
- handler: () => {
3528
- node.value && editorService?.remove(node.value);
3529
- }
3530
- },
3531
- {
3532
- type: "divider",
3533
- direction: "horizontal"
3534
- },
3535
- {
3536
- type: "button",
3537
- text: "\u6E05\u7A7A\u53C2\u8003\u7EBF",
3538
- handler: () => {
3539
- editorService?.get("stage").clearGuides();
3540
- }
3541
- },
3542
- ...stageContentMenu
3543
- ]),
3544
- show(e) {
3545
- menu.value?.show(e);
3546
- }
3730
+ const show = (e) => {
3731
+ menu.value?.show(e);
3732
+ };
3733
+ expose({ show });
3734
+ return (_ctx, _cache) => {
3735
+ return vue.openBlock(), vue.createBlock(_sfc_main$a, {
3736
+ "menu-data": menuData,
3737
+ ref_key: "menu",
3738
+ ref: menu
3739
+ }, null, 8, ["menu-data"]);
3547
3740
  };
3548
3741
  }
3549
3742
  });
3550
- function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3551
- const _component_content_menu = vue.resolveComponent("content-menu");
3552
- return vue.openBlock(), vue.createBlock(_component_content_menu, {
3553
- "menu-data": _ctx.menuData,
3554
- ref: "menu"
3555
- }, null, 8, ["menu-data"]);
3556
- }
3557
- var ViewerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
3558
3743
 
3559
- const _sfc_main$2 = vue.defineComponent({
3560
- name: "magic-stage",
3561
- components: {
3562
- ViewerMenu,
3563
- ScrollViewer
3564
- },
3565
- setup() {
3744
+ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
3745
+ __name: "Stage",
3746
+ setup(__props) {
3747
+ let stage = null;
3748
+ let runtime = null;
3566
3749
  const services = vue.inject("services");
3567
3750
  const stageOptions = vue.inject("stageOptions");
3568
3751
  const stageWrap = vue.ref();
3569
3752
  const stageContainer = vue.ref();
3570
3753
  const menu = vue.ref();
3754
+ const isMultiSelect = vue.computed(() => services?.editorService.get("nodes")?.length > 1);
3571
3755
  const stageRect = vue.computed(() => services?.uiService.get("stageRect"));
3572
3756
  const uiSelectMode = vue.computed(() => services?.uiService.get("uiSelectMode"));
3573
3757
  const root = vue.computed(() => services?.editorService.get("root"));
3574
3758
  const page = vue.computed(() => services?.editorService.get("page"));
3575
3759
  const zoom = vue.computed(() => services?.uiService.get("zoom") || 1);
3576
3760
  const node = vue.computed(() => services?.editorService.get("node"));
3577
- let stage = null;
3578
- let runtime = null;
3579
3761
  const getGuideLineKey = (key) => `${key}_${root.value?.id}_${page.value?.id}`;
3580
3762
  vue.watchEffect(() => {
3581
3763
  if (stage)
@@ -3584,7 +3766,7 @@
3584
3766
  return;
3585
3767
  if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value)
3586
3768
  return;
3587
- stage = new StageCore__default["default"]({
3769
+ stage = new StageCore__default.default({
3588
3770
  render: stageOptions.render,
3589
3771
  runtimeUrl: stageOptions.runtimeUrl,
3590
3772
  zoom: zoom.value,
@@ -3615,6 +3797,9 @@
3615
3797
  stage?.on("highlight", (el) => {
3616
3798
  services?.editorService.highlight(el.id);
3617
3799
  });
3800
+ stage?.on("multiSelect", (els) => {
3801
+ services?.editorService.multiSelect(els.map((el) => el.id));
3802
+ });
3618
3803
  stage?.on("update", (ev) => {
3619
3804
  if (ev.parentEl) {
3620
3805
  services?.editorService.moveToContainer({ id: ev.el.id, style: ev.style }, ev.parentEl.id);
@@ -3673,100 +3858,96 @@
3673
3858
  resizeObserver.disconnect();
3674
3859
  services?.editorService.set("stage", null);
3675
3860
  });
3676
- return {
3677
- stageWrap,
3678
- stageContainer,
3679
- menu,
3680
- stageRect,
3681
- zoom,
3682
- contextmenuHandler(e2) {
3683
- e2.preventDefault();
3684
- menu.value?.show(e2);
3685
- },
3686
- dragoverHandler(e2) {
3687
- e2.preventDefault();
3688
- if (e2.dataTransfer) {
3689
- e2.dataTransfer.dropEffect = "move";
3690
- }
3691
- },
3692
- async dropHandler(e) {
3693
- e.preventDefault();
3694
- const doc = stage?.renderer.contentWindow?.document;
3695
- const parentEl = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
3696
- let parent = page.value;
3697
- if (parentEl) {
3698
- parent = services?.editorService.getNodeById(parentEl.id, false);
3699
- }
3700
- if (e.dataTransfer && parent && stageContainer.value && stage) {
3701
- const config = eval(`(${e.dataTransfer.getData("data")})`);
3702
- const layout = await services?.editorService.getLayout(parent);
3703
- const containerRect = stageContainer.value.getBoundingClientRect();
3704
- const { scrollTop, scrollLeft } = stage.mask;
3705
- const { style = {} } = config;
3706
- let top = 0;
3707
- let left = 0;
3708
- let position = "relative";
3709
- if (layout === Layout.ABSOLUTE) {
3710
- position = "absolute";
3711
- top = e.clientY - containerRect.top + scrollTop;
3712
- left = e.clientX - containerRect.left + scrollLeft;
3713
- if (parentEl && doc) {
3714
- const { left: parentLeft, top: parentTop } = StageCore.getOffset(parentEl);
3715
- left = left - StageCore.calcValueByFontsize(doc, parentLeft);
3716
- top = top - StageCore.calcValueByFontsize(doc, parentTop);
3717
- }
3861
+ const contextmenuHandler = (e2) => {
3862
+ e2.preventDefault();
3863
+ menu.value?.show(e2);
3864
+ };
3865
+ const dragoverHandler = (e2) => {
3866
+ e2.preventDefault();
3867
+ if (e2.dataTransfer) {
3868
+ e2.dataTransfer.dropEffect = "move";
3869
+ }
3870
+ };
3871
+ const dropHandler = async (e) => {
3872
+ e.preventDefault();
3873
+ const doc = stage?.renderer.contentWindow?.document;
3874
+ const parentEl = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
3875
+ let parent = page.value;
3876
+ if (parentEl) {
3877
+ parent = services?.editorService.getNodeById(parentEl.id, false);
3878
+ }
3879
+ if (e.dataTransfer && parent && stageContainer.value && stage) {
3880
+ const config = eval(`(${e.dataTransfer.getData("data")})`);
3881
+ const layout = await services?.editorService.getLayout(parent);
3882
+ const containerRect = stageContainer.value.getBoundingClientRect();
3883
+ const { scrollTop, scrollLeft } = stage.mask;
3884
+ const { style = {} } = config;
3885
+ let top = 0;
3886
+ let left = 0;
3887
+ let position = "relative";
3888
+ if (layout === Layout.ABSOLUTE) {
3889
+ position = "absolute";
3890
+ top = e.clientY - containerRect.top + scrollTop;
3891
+ left = e.clientX - containerRect.left + scrollLeft;
3892
+ if (parentEl && doc) {
3893
+ const { left: parentLeft, top: parentTop } = StageCore.getOffset(parentEl);
3894
+ left = left - StageCore.calcValueByFontsize(doc, parentLeft);
3895
+ top = top - StageCore.calcValueByFontsize(doc, parentTop);
3718
3896
  }
3719
- config.style = {
3720
- ...style,
3721
- position,
3722
- top,
3723
- left
3724
- };
3725
- config.inputEvent = e;
3726
- services?.editorService.add(config, parent);
3727
3897
  }
3898
+ config.style = {
3899
+ ...style,
3900
+ position,
3901
+ top,
3902
+ left
3903
+ };
3904
+ config.inputEvent = e;
3905
+ services?.editorService.add(config, parent);
3728
3906
  }
3729
3907
  };
3908
+ return (_ctx, _cache) => {
3909
+ return vue.openBlock(), vue.createBlock(ScrollViewer, {
3910
+ class: "m-editor-stage",
3911
+ ref_key: "stageWrap",
3912
+ ref: stageWrap,
3913
+ width: vue.unref(stageRect)?.width,
3914
+ height: vue.unref(stageRect)?.height,
3915
+ zoom: vue.unref(zoom)
3916
+ }, {
3917
+ default: vue.withCtx(() => [
3918
+ vue.createElementVNode("div", {
3919
+ class: "m-editor-stage-container",
3920
+ ref_key: "stageContainer",
3921
+ ref: stageContainer,
3922
+ style: vue.normalizeStyle(`transform: scale(${vue.unref(zoom)})`),
3923
+ onContextmenu: contextmenuHandler,
3924
+ onDrop: dropHandler,
3925
+ onDragover: dragoverHandler
3926
+ }, null, 36),
3927
+ (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
3928
+ vue.createVNode(_sfc_main$3, {
3929
+ ref_key: "menu",
3930
+ ref: menu,
3931
+ "is-multi-select": vue.unref(isMultiSelect)
3932
+ }, null, 8, ["is-multi-select"])
3933
+ ]))
3934
+ ]),
3935
+ _: 1
3936
+ }, 8, ["width", "height", "zoom"]);
3937
+ };
3730
3938
  }
3731
3939
  });
3732
- function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3733
- const _component_viewer_menu = vue.resolveComponent("viewer-menu");
3734
- const _component_scroll_viewer = vue.resolveComponent("scroll-viewer");
3735
- return vue.openBlock(), vue.createBlock(_component_scroll_viewer, {
3736
- class: "m-editor-stage",
3737
- ref: "stageWrap",
3738
- width: _ctx.stageRect?.width,
3739
- height: _ctx.stageRect?.height,
3740
- zoom: _ctx.zoom
3741
- }, {
3742
- default: vue.withCtx(() => [
3743
- vue.createElementVNode("div", {
3744
- class: "m-editor-stage-container",
3745
- ref: "stageContainer",
3746
- style: vue.normalizeStyle(`transform: scale(${_ctx.zoom})`),
3747
- onContextmenu: _cache[0] || (_cache[0] = (...args) => _ctx.contextmenuHandler && _ctx.contextmenuHandler(...args)),
3748
- onDrop: _cache[1] || (_cache[1] = (...args) => _ctx.dropHandler && _ctx.dropHandler(...args)),
3749
- onDragover: _cache[2] || (_cache[2] = (...args) => _ctx.dragoverHandler && _ctx.dragoverHandler(...args))
3750
- }, null, 36),
3751
- (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
3752
- vue.createVNode(_component_viewer_menu, { ref: "menu" }, null, 512)
3753
- ]))
3754
- ]),
3755
- _: 1
3756
- }, 8, ["width", "height", "zoom"]);
3757
- }
3758
- var MagicStage = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2]]);
3759
3940
 
3760
3941
  const _sfc_main$1 = vue.defineComponent({
3761
3942
  name: "m-editor-workspace",
3762
3943
  components: {
3763
- PageBar,
3764
- MagicStage
3944
+ PageBar: _sfc_main$5,
3945
+ MagicStage: _sfc_main$2
3765
3946
  },
3766
3947
  setup() {
3767
3948
  const services = vue.inject("services");
3768
3949
  const workspace = vue.ref();
3769
- const node = vue.computed(() => services?.editorService.get("node"));
3950
+ const nodes = vue.computed(() => services?.editorService.get("nodes"));
3770
3951
  let keycon;
3771
3952
  const mouseenterHandler = () => {
3772
3953
  workspace.value?.focus();
@@ -3777,31 +3958,31 @@
3777
3958
  vue.onMounted(() => {
3778
3959
  workspace.value?.addEventListener("mouseenter", mouseenterHandler);
3779
3960
  workspace.value?.addEventListener("mouseleave", mouseleaveHandler);
3780
- keycon = new KeyController__default["default"](workspace.value);
3961
+ keycon = new KeyController__default.default(workspace.value);
3781
3962
  const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
3782
3963
  const ctrl = isMac ? "meta" : "ctrl";
3783
3964
  keycon.keyup("delete", (e) => {
3784
3965
  e.inputEvent.preventDefault();
3785
- if (!node.value || utils.isPage(node.value))
3966
+ if (!nodes.value || utils.isPage(nodes.value[0]))
3786
3967
  return;
3787
- services?.editorService.remove(node.value);
3968
+ services?.editorService.remove(nodes.value);
3788
3969
  }).keyup("backspace", (e) => {
3789
3970
  e.inputEvent.preventDefault();
3790
- if (!node.value || utils.isPage(node.value))
3971
+ if (!nodes.value || utils.isPage(nodes.value[0]))
3791
3972
  return;
3792
- services?.editorService.remove(node.value);
3973
+ services?.editorService.remove(nodes.value);
3793
3974
  }).keydown([ctrl, "c"], (e) => {
3794
3975
  e.inputEvent.preventDefault();
3795
- node.value && services?.editorService.copy(node.value);
3976
+ nodes.value && services?.editorService.copy(nodes.value);
3796
3977
  }).keydown([ctrl, "v"], (e) => {
3797
3978
  e.inputEvent.preventDefault();
3798
- node.value && services?.editorService.paste();
3979
+ nodes.value && services?.editorService.paste();
3799
3980
  }).keydown([ctrl, "x"], (e) => {
3800
3981
  e.inputEvent.preventDefault();
3801
- if (!node.value || utils.isPage(node.value))
3982
+ if (!nodes.value || utils.isPage(nodes.value[0]))
3802
3983
  return;
3803
- services?.editorService.copy(node.value);
3804
- services?.editorService.remove(node.value);
3984
+ services?.editorService.copy(nodes.value);
3985
+ services?.editorService.remove(nodes.value);
3805
3986
  }).keydown([ctrl, "z"], (e) => {
3806
3987
  e.inputEvent.preventDefault();
3807
3988
  services?.editorService.undo();
@@ -3863,6 +4044,7 @@
3863
4044
  };
3864
4045
  }
3865
4046
  });
4047
+
3866
4048
  const _hoisted_1 = {
3867
4049
  class: "m-editor-workspace",
3868
4050
  tabindex: "1",
@@ -3887,14 +4069,14 @@
3887
4069
  })
3888
4070
  ], 512);
3889
4071
  }
3890
- var Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
4072
+ const Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
3891
4073
 
3892
4074
  class ComponentList extends BaseService {
4075
+ state = vue.reactive({
4076
+ list: []
4077
+ });
3893
4078
  constructor() {
3894
4079
  super([]);
3895
- this.state = vue.reactive({
3896
- list: []
3897
- });
3898
4080
  }
3899
4081
  setList(componentGroupList) {
3900
4082
  this.state.list = componentGroupList;
@@ -3903,7 +4085,7 @@
3903
4085
  return this.state.list;
3904
4086
  }
3905
4087
  }
3906
- var componentListService = new ComponentList();
4088
+ const componentListService = new ComponentList();
3907
4089
 
3908
4090
  const DEFAULT_LEFT_COLUMN_WIDTH = 310;
3909
4091
  const MIN_LEFT_COLUMN_WIDTH = 45;
@@ -4023,7 +4205,7 @@
4023
4205
  return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
4024
4206
  }
4025
4207
  }
4026
- var uiService = new Ui();
4208
+ const uiService = new Ui();
4027
4209
 
4028
4210
  const _sfc_main = vue.defineComponent({
4029
4211
  name: "m-editor",
@@ -4153,7 +4335,8 @@
4153
4335
  historyService,
4154
4336
  propsService,
4155
4337
  editorService,
4156
- uiService
4338
+ uiService,
4339
+ storageService
4157
4340
  };
4158
4341
  vue.provide("services", services);
4159
4342
  vue.provide("layerContentMenu", props.layerContentMenu);
@@ -4172,6 +4355,7 @@
4172
4355
  return services;
4173
4356
  }
4174
4357
  });
4358
+
4175
4359
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4176
4360
  const _component_nav_menu = vue.resolveComponent("nav-menu");
4177
4361
  const _component_sidebar = vue.resolveComponent("sidebar");
@@ -4232,18 +4416,18 @@
4232
4416
  _: 3
4233
4417
  }, 8, ["code-options"]);
4234
4418
  }
4235
- var Editor = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
4419
+ const Editor = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
4236
4420
 
4237
- var index$1 = /* #__PURE__ */ (() => ".m-editor-nav-menu {\n display: flex;\n z-index: 5;\n -webkit-box-pack: justify;\n justify-content: space-between;\n -webkit-box-align: center;\n align-items: center;\n background-color: #ffffff;\n font-size: 19.2px;\n color: #070303;\n font-weight: 400;\n box-sizing: border-box;\n margin: 0px;\n flex: 0 0 35px;\n border-bottom: 1px solid #d8dee8;\n}\n.m-editor-nav-menu > div {\n display: flex;\n height: 100%;\n z-index: 1;\n align-items: center;\n}\n.m-editor-nav-menu .menu-center {\n justify-content: center;\n}\n.m-editor-nav-menu .menu-right {\n justify-content: flex-end;\n}\n.m-editor-nav-menu .menu-item {\n flex-direction: row;\n -webkit-box-align: center;\n align-items: center;\n vertical-align: middle;\n font-size: 14px;\n line-height: 1;\n height: 100%;\n color: rgba(255, 255, 255, 0.7);\n box-sizing: inherit;\n z-index: 1;\n display: flex !important;\n transition: all 0.3s ease 0s;\n border-bottom: 2px solid transparent;\n margin: 0;\n}\n.m-editor-nav-menu .menu-item .is-disabled {\n opacity: 0.5;\n}\n.m-editor-nav-menu .menu-item .is-text {\n padding: 5px;\n}\n.m-editor-nav-menu .menu-item .is-text,\n.m-editor-nav-menu .menu-item i {\n color: #070303;\n}\n.m-editor-nav-menu .menu-item .icon {\n display: flex;\n -webkit-box-align: center;\n align-items: center;\n height: 100%;\n padding: 0px 8px;\n}\n.m-editor-nav-menu .menu-item .menu-item-text {\n color: #070303;\n}\n.m-editor {\n display: flex;\n flex-direction: column;\n width: 100%;\n}\n.m-editor-content {\n width: 100%;\n height: calc(100% - 35px);\n display: flex;\n justify-self: space-between;\n}\n.m-editor-framework-center {\n position: relative;\n transform: translateZ(0);\n flex: 1;\n}\n.m-editor-framework-left {\n background-color: #ffffff;\n}\n.m-editor-framework-center .el-scrollbar__view {\n height: 100%;\n min-height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n}\n.m-editor-empty-panel {\n display: flex;\n flex: 1;\n justify-content: center;\n align-items: center;\n flex-direction: column;\n height: calc(100% - 32px);\n}\n.m-editor-empty-content {\n display: flex;\n justify-content: space-evenly;\n flex-direction: row;\n width: 100%;\n}\n.m-editor-empty-button {\n border: 3px solid rgba(0, 0, 0, 0.2);\n padding: 10px 40px;\n color: rgba(0, 0, 0, 0.6);\n cursor: pointer;\n}\n.m-editor-empty-button i {\n height: 180px;\n line-height: 180px;\n font-size: 100px;\n}\n.m-editor-empty-button p {\n text-align: center;\n font-size: 20px;\n margin-top: 5px;\n}\n.m-editor-empty-button:hover {\n border-color: #2882e0;\n color: #2882e0;\n}\n.m-editor-sidebar {\n height: 100%;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header {\n background: #2882e0;\n border: 0;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header.is-left {\n width: 40px;\n margin-right: 0;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .el-tabs__nav-wrap {\n margin: 0;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .el-tabs__nav {\n border: 0;\n border-radius: 0;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .tab-label {\n margin-left: 2px;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .el-tabs__item.is-left {\n line-height: 15px;\n border: 0;\n height: auto;\n padding: 8px;\n color: rgb(255, 255, 255);\n box-sizing: border-box;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .el-tabs__item.is-left.is-left.is-active {\n background: #ffffff;\n border: 0;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .el-tabs__item.is-left.is-left.is-active i {\n color: #353140;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .el-tabs__item.is-left.is-left.is-active .magic-editor-tab-panel-title {\n color: #353140;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .el-tabs__item.is-left.is-left:first-child {\n border-right: 0;\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header i {\n font-size: 25px;\n color: rgba(255, 255, 255, 0.6);\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header i:hover {\n color: rgb(255, 255, 255);\n}\n.m-editor-sidebar.el-tabs--left .el-tabs__header .magic-editor-tab-panel-title {\n font-size: 12px;\n white-space: normal;\n}\n.m-editor-sidebar .el-scrollbar {\n height: 100%;\n}\n.m-editor-sidebar .el-tree {\n min-height: 100%;\n}\n.m-editor-sidebar .fold-icon {\n position: absolute;\n bottom: 8px;\n left: 0px;\n width: 45px;\n padding-left: 8px;\n color: #fff;\n font-size: 32px;\n opacity: 0.8;\n cursor: pointer;\n}\n.m-editor-sidebar .fold-icon:hover {\n background: rgba(0, 0, 0, 0.2);\n}\n.m-editor-sidebar .el-tabs__content,\n.m-editor-sidebar .el-tab-pane {\n height: 100%;\n}\n.magic-editor-layer-panel {\n background: #ffffff;\n}\n.magic-editor-layer-panel .search-input {\n background: #ffffff;\n color: #bbbbbb;\n padding: 10px;\n position: absolute;\n top: 0;\n left: 0;\n z-index: 1;\n}\n.magic-editor-layer-panel .search-input .el-input__suffix {\n padding: 10px 5px;\n}\n.magic-editor-layer-panel .node-content {\n flex: 1;\n display: flex;\n width: 100%;\n}\n.magic-editor-layer-panel .node-content > div {\n width: 8px;\n}\n.magic-editor-layer-panel .node-content > span {\n width: calc(100% - 68px);\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.magic-editor-layer-panel .node-content > i {\n margin-right: 10px;\n font-size: 20px;\n}\n.magic-editor-layer-panel .node-content > i.lock {\n color: #bbb;\n}\n.magic-editor-layer-panel,\n.magic-editor-layer-panel .el-tree {\n background-color: #ffffff;\n color: #313a40;\n}\n.magic-editor-layer-panel .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {\n background-color: #2882e0;\n color: #fff;\n}\n.magic-editor-layer-panel .cus-tree-node {\n width: 100%;\n overflow: hidden;\n}\n.magic-editor-layer-panel .cus-tree-node-hover {\n background-color: #f3f5f9;\n width: 100%;\n}\n.magic-editor-layer-panel .el-tree-node:focus > .el-tree-node__content {\n background-color: #2882e0;\n color: #fff;\n}\n.ui-tree-tip {\n width: 100%;\n height: 25px;\n margin-left: 10px;\n background: #ffffff;\n font-style: italic;\n color: #555554;\n position: absolute;\n top: 40px;\n left: 0;\n z-index: 1;\n}\n.ui-component-panel {\n height: 100%;\n border-top: 0 !important;\n margin-top: 50px;\n background-color: #ffffff;\n}\n.ui-component-panel .search-input {\n background: #f8fbff;\n color: #bbbbbb;\n padding: 10px;\n position: absolute;\n top: 0;\n left: 0;\n box-sizing: border-box;\n z-index: 1;\n}\n.ui-component-panel .search-input .el-input__prefix {\n padding: 10px;\n}\n.ui-component-panel .search-input .el-input__suffix {\n padding: 10px 5px;\n}\n.ui-component-panel .el-collapse-item > div:first-of-type {\n border-bottom: 1px solid #d9dbdd;\n margin-bottom: 10px;\n}\n.ui-component-panel .el-collapse-item__header {\n background: #ffffff;\n color: #070303;\n height: 25px;\n line-height: 25px;\n padding-left: 10px;\n font-size: 12px;\n}\n.ui-component-panel .el-collapse-item__header i {\n margin-right: 5px;\n font-size: 14px;\n}\n.ui-component-panel .el-collapse-item__wrap {\n background: #ffffff;\n border-bottom: 0;\n}\n.ui-component-panel .el-collapse-item__wrap .el-collapse-item__content {\n padding: 10px;\n display: flex;\n flex-wrap: wrap;\n}\n.ui-component-panel .el-collapse-item__wrap .component-item {\n display: flex;\n overflow: hidden;\n text-overflow: ellipsis;\n margin: 5px 10px;\n box-sizing: border-box;\n color: #070303;\n flex-direction: column;\n width: 42px;\n cursor: pointer;\n}\n.ui-component-panel .el-collapse-item__wrap .component-item i {\n font-size: 20px;\n background: #fff;\n height: 40px;\n width: 40px;\n line-height: 40px;\n border-radius: 5px;\n color: #909090;\n border: 1px solid #d9dbdd;\n display: flex;\n justify-content: space-evenly;\n align-items: center;\n margin-bottom: 5px;\n}\n.ui-component-panel .el-collapse-item__wrap .component-item i:hover {\n background: #2882e0;\n color: #fff;\n border-color: #4e8be1;\n}\n.ui-component-panel .el-collapse-item__wrap .component-item span {\n font-size: 12px;\n text-align: center;\n}\n.ui-component-panel .el-collapse-item__wrap .component-item .el-tooltip {\n width: 50px;\n height: 30px;\n line-height: 15px;\n display: block;\n white-space: normal;\n margin: 0;\n}\n.m-editor-resizer {\n border-left: 1px solid transparent;\n border-right: 1px solid transparent;\n width: 8px;\n margin: 0 -5px;\n height: 100%;\n opacity: 0.9;\n background: padding-box #d8dee8;\n box-sizing: border-box;\n cursor: col-resize;\n z-index: 1;\n}\n.m-editor-resizer:hover {\n border-color: #d8dee8;\n}\n.m-editor-resizer .icon-container {\n visibility: hidden;\n opacity: 0;\n transition: opacity 0.4s;\n width: 20px;\n height: 120px;\n line-height: 120px;\n text-align: center;\n background: #d8dee8;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n cursor: pointer;\n}\n.m-editor-resizer .icon-container.position-left {\n transform: translate(calc(-100% - 4px), -50%);\n}\n.m-editor-resizer .icon-container.position-right {\n transform: translate(calc(100% + 4px), -50%);\n}\n.m-editor-resizer .icon {\n color: #fff;\n font-size: 18px;\n}\n.magic-editor-resizer:hover .icon-container {\n visibility: visible;\n opacity: 1;\n}\n.m-editor-workspace {\n height: 100%;\n width: 100%;\n user-select: none;\n}\n.m-editor-workspace:focus-visible {\n outline: 0;\n}\n.m-editor-page-bar {\n position: fixed;\n bottom: 0;\n left: 0;\n display: flex;\n width: 100%;\n height: 32px;\n line-height: 32px;\n color: #070303;\n background-color: #f3f3f3;\n border-top: 1px solid #d9dbdd;\n z-index: 2;\n overflow: hidden;\n}\n.m-editor-page-bar-items {\n display: flex;\n transition: transform 0.3s;\n}\n.m-editor-page-bar-item {\n padding: 0 10px;\n cursor: pointer;\n border-right: 1px solid #d9dbdd;\n display: flex;\n justify-items: center;\n align-items: center;\n background-color: #f3f3f3;\n white-space: nowrap;\n}\n.m-editor-page-bar-item.active {\n background-color: #fff;\n cursor: text;\n}\n.m-editor-page-bar-item.active .m-editor-page-bar-menu-icon {\n cursor: pointer;\n}\n.m-editor-page-bar-item-icon {\n position: relative;\n z-index: 1;\n}\n.m-editor-page-bar-item-title {\n max-width: 150px;\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n}\n.page-bar-popover.el-popper.el-popover {\n padding: 10px 0;\n}\n.page-bar-popover .menu-item {\n cursor: pointer;\n transition: all 0.2s ease 0s;\n padding: 5px 14px;\n}\n.page-bar-popover .menu-item .el-button--text,\n.page-bar-popover .menu-item i {\n color: #070303;\n}\n.page-bar-popover .menu-item:hover {\n background-color: #f3f5f9;\n}\n.m-editor-props-panel {\n padding: 0 10px;\n}\n.m-editor-props-panel.small .el-form-item__label {\n font-size: 12px;\n}\n.m-editor-props-panel.small .m-fieldset legend {\n font-size: 12px;\n}\n.m-editor-props-panel.small .el-tabs__item {\n font-size: 12px;\n}\n.m-editor-props-panel .el-input__wrapper {\n border-radius: 0;\n}\n.m-editor-props-panel-popper.small span,\n.m-editor-props-panel-popper.small a,\n.m-editor-props-panel-popper.small p {\n font-size: 12px;\n}\n.magic-editor-content-menu {\n position: fixed;\n font-size: 12px;\n background: #fff;\n box-shadow: 0 2px 8px 2px rgba(68, 73, 77, 0.16);\n z-index: 9999;\n transform-origin: 0% 0%;\n font-weight: 600;\n padding: 4px 0px;\n overflow: auto;\n max-height: 100%;\n}\n.magic-editor-content-menu .menu-item {\n color: #333;\n display: flex;\n -webkit-box-align: center;\n align-items: center;\n cursor: pointer;\n min-width: 140px;\n transition: all 0.2s ease 0s;\n padding: 5px 14px;\n border-left: 2px solid transparent;\n}\n.magic-editor-content-menu .menu-item .el-button {\n width: 100%;\n justify-content: flex-start;\n}\n.magic-editor-content-menu .menu-item .el-button--text,\n.magic-editor-content-menu .menu-item i {\n color: #070303;\n}\n.magic-editor-content-menu .menu-item.divider {\n padding: 0 14px;\n}\n.magic-editor-content-menu .menu-item.divider .el-divider {\n margin: 0;\n}\n.magic-editor-content-menu .menu-item:hover {\n background-color: #f3f5f9;\n}\n.m-editor-stage {\n position: relative;\n width: 100%;\n height: calc(100% - 32px);\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n}\n.m-editor-stage-container {\n width: 100%;\n height: 100%;\n z-index: 0;\n position: relative;\n transition: transform 0.3s;\n box-sizing: content-box;\n box-shadow: rgba(0, 0, 0, 0.04) 0px 3px 5px;\n}\n.m-editor-stage-container::-webkit-scrollbar {\n width: 0 !important;\n}\n.magic-code-editor {\n width: 100%;\n}\n.magic-code-editor .margin {\n margin: 0;\n}")();
4421
+ const index$1 = '';
4238
4422
 
4239
4423
  const defaultInstallOpt = {};
4240
- var index = {
4424
+ const index = {
4241
4425
  install: (app, opt) => {
4242
4426
  const option = Object.assign(defaultInstallOpt, opt || {});
4243
4427
  app.config.globalProperties.$TMAGIC_EDITOR = option;
4244
4428
  setConfig(option);
4245
4429
  app.component(Editor.name, Editor);
4246
- app.component(uiSelect.name, uiSelect);
4430
+ app.component(_sfc_main$k.name, _sfc_main$k);
4247
4431
  app.component(CodeLink.name, CodeLink);
4248
4432
  app.component(Code.name, Code);
4249
4433
  app.component(CodeEditor.name, CodeEditor);
@@ -4262,11 +4446,11 @@
4262
4446
  exports.PropsPanel = PropsPanel;
4263
4447
  exports.TMagicCodeEditor = CodeEditor;
4264
4448
  exports.TMagicEditor = Editor;
4265
- exports.ToolButton = ToolButton;
4449
+ exports.ToolButton = _sfc_main$e;
4266
4450
  exports.V_GUIDE_LINE_STORAGE_KEY = V_GUIDE_LINE_STORAGE_KEY;
4267
4451
  exports.change2Fixed = change2Fixed;
4268
4452
  exports.debug = debug;
4269
- exports["default"] = index;
4453
+ exports.default = index;
4270
4454
  exports.editorService = editorService;
4271
4455
  exports.error = error;
4272
4456
  exports.eventsService = eventsService;
@@ -4288,6 +4472,7 @@
4288
4472
  exports.propsService = propsService;
4289
4473
  exports.setConfig = setConfig;
4290
4474
  exports.setLayout = setLayout;
4475
+ exports.storageService = storageService;
4291
4476
  exports.uiService = uiService;
4292
4477
  exports.warn = warn;
4293
4478