@tmagic/editor 1.0.0-beta.9 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +1 -0
  2. package/coverage/clover.xml +1560 -0
  3. package/coverage/coverage-final.json +36 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +87 -0
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +206 -0
  8. package/coverage/lcov-report/prettify.css +1 -0
  9. package/coverage/lcov-report/prettify.js +2 -0
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +196 -0
  12. package/coverage/lcov-report/src/Editor.vue.html +787 -0
  13. package/coverage/lcov-report/src/components/ContentMenu.vue.html +406 -0
  14. package/coverage/lcov-report/src/components/Icon.vue.html +172 -0
  15. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +283 -0
  16. package/coverage/lcov-report/src/components/ToolButton.vue.html +772 -0
  17. package/coverage/lcov-report/src/components/index.html +161 -0
  18. package/coverage/lcov-report/src/index.html +131 -0
  19. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +214 -0
  20. package/coverage/lcov-report/src/layouts/Framework.vue.html +304 -0
  21. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +208 -0
  22. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +319 -0
  23. package/coverage/lcov-report/src/layouts/Resizer.vue.html +268 -0
  24. package/coverage/lcov-report/src/layouts/index.html +176 -0
  25. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +358 -0
  26. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +421 -0
  27. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +775 -0
  28. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +226 -0
  29. package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +289 -0
  30. package/coverage/lcov-report/src/layouts/sidebar/index.html +176 -0
  31. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +718 -0
  32. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +757 -0
  33. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +532 -0
  34. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +586 -0
  35. package/coverage/lcov-report/src/layouts/workspace/index.html +161 -0
  36. package/coverage/lcov-report/src/services/BaseService.ts.html +643 -0
  37. package/coverage/lcov-report/src/services/componentList.ts.html +229 -0
  38. package/coverage/lcov-report/src/services/editor.ts.html +2077 -0
  39. package/coverage/lcov-report/src/services/events.ts.html +331 -0
  40. package/coverage/lcov-report/src/services/history.ts.html +478 -0
  41. package/coverage/lcov-report/src/services/index.html +206 -0
  42. package/coverage/lcov-report/src/services/props.ts.html +415 -0
  43. package/coverage/lcov-report/src/services/ui.ts.html +580 -0
  44. package/coverage/lcov-report/src/type.ts.html +850 -0
  45. package/coverage/lcov-report/src/utils/compose.ts.html +184 -0
  46. package/coverage/lcov-report/src/utils/config.ts.html +172 -0
  47. package/coverage/lcov-report/src/utils/editor.ts.html +838 -0
  48. package/coverage/lcov-report/src/utils/index.html +221 -0
  49. package/coverage/lcov-report/src/utils/index.ts.html +151 -0
  50. package/coverage/lcov-report/src/utils/logger.ts.html +226 -0
  51. package/coverage/lcov-report/src/utils/props.ts.html +796 -0
  52. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +733 -0
  53. package/coverage/lcov-report/src/utils/undo-redo.ts.html +313 -0
  54. package/coverage/lcov.info +3708 -0
  55. package/dist/style.css +65 -33
  56. package/dist/tmagic-editor.es.js +1379 -806
  57. package/dist/tmagic-editor.es.js.map +1 -1
  58. package/dist/tmagic-editor.umd.js +1381 -808
  59. package/dist/tmagic-editor.umd.js.map +1 -1
  60. package/dist/types/src/Editor.vue.d.ts +1 -1
  61. package/dist/types/src/components/ToolButton.vue.d.ts +12 -1
  62. package/dist/types/src/fields/UISelect.vue.d.ts +4 -1
  63. package/dist/types/src/index.d.ts +1 -0
  64. package/dist/types/src/layouts/CodeEditor.vue.d.ts +13 -4
  65. package/dist/types/src/layouts/PropsPanel.vue.d.ts +2 -1
  66. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +2 -1
  67. package/dist/types/src/layouts/sidebar/Sidebar.vue.d.ts +2 -3
  68. package/dist/types/src/layouts/sidebar/TabPane.vue.d.ts +14 -0
  69. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +10 -3
  70. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +4 -7
  71. package/dist/types/src/services/BaseService.d.ts +4 -1
  72. package/dist/types/src/services/editor.d.ts +5 -2
  73. package/dist/types/src/services/history.d.ts +1 -0
  74. package/dist/types/src/services/props.d.ts +2 -2
  75. package/dist/types/src/services/ui.d.ts +2 -0
  76. package/dist/types/src/type.d.ts +15 -9
  77. package/dist/types/src/utils/editor.d.ts +4 -3
  78. package/dist/types/src/utils/polyfills.d.ts +0 -0
  79. package/package.json +36 -12
  80. package/src/components/ContentMenu.vue +107 -0
  81. package/src/components/ScrollViewer.vue +1 -1
  82. package/src/components/ToolButton.vue +69 -30
  83. package/src/fields/UISelect.vue +14 -6
  84. package/src/index.ts +2 -0
  85. package/src/layouts/CodeEditor.vue +20 -10
  86. package/src/layouts/Framework.vue +6 -6
  87. package/src/layouts/PropsPanel.vue +4 -3
  88. package/src/layouts/sidebar/ComponentListPanel.vue +25 -3
  89. package/src/layouts/sidebar/LayerMenu.vue +91 -96
  90. package/src/layouts/sidebar/LayerPanel.vue +31 -54
  91. package/src/layouts/sidebar/Sidebar.vue +13 -52
  92. package/src/layouts/sidebar/TabPane.vue +68 -0
  93. package/src/layouts/workspace/PageBar.vue +136 -13
  94. package/src/layouts/workspace/Stage.vue +50 -75
  95. package/src/layouts/workspace/ViewerMenu.vue +104 -67
  96. package/src/layouts/workspace/Workspace.vue +106 -23
  97. package/src/services/BaseService.ts +70 -22
  98. package/src/services/editor.ts +148 -39
  99. package/src/services/history.ts +7 -0
  100. package/src/services/props.ts +3 -3
  101. package/src/services/ui.ts +35 -5
  102. package/src/theme/common/var.scss +1 -0
  103. package/src/theme/component-list-panel.scss +2 -0
  104. package/src/theme/content-menu.scss +33 -26
  105. package/src/theme/layer-panel.scss +2 -1
  106. package/src/theme/nav-menu.scss +6 -2
  107. package/src/theme/page-bar.scss +35 -3
  108. package/src/theme/props-panel.scss +13 -13
  109. package/src/type.ts +16 -9
  110. package/src/utils/editor.ts +31 -6
  111. package/{vite.config.ts → src/utils/polyfills.ts} +4 -12
  112. package/src/utils/props.ts +20 -1
  113. package/dist/types/src/layouts/sidebar/LayerMenu.vue.d.ts +0 -31
  114. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +0 -979
  115. package/dist/types/src/layouts/workspace/Stage.vue.d.ts +0 -193
  116. package/dist/types/src/layouts/workspace/ViewerMenu.vue.d.ts +0 -18
  117. package/tsconfig.json +0 -9
@@ -1,14 +1,14 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('monaco-editor'), require('@element-plus/icons'), require('@tmagic/schema'), require('lodash-es'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('element-plus'), require('@tmagic/stage')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', 'monaco-editor', '@element-plus/icons', '@tmagic/schema', 'lodash-es', '@tmagic/utils', 'events', '@tmagic/core', 'element-plus', '@tmagic/stage'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.vue, global.serialize, global.monaco, global.icons, global.schema, global.lodashEs, global.utils, global.events, global.core, global.elementPlus, global.StageCore));
5
- })(this, (function (exports, vue, serialize, monaco, icons, schema, lodashEs, utils, events, core, elementPlus, StageCore) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('@element-plus/icons'), require('lodash-es'), require('monaco-editor'), require('@tmagic/schema'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('element-plus'), require('keycon'), require('@tmagic/stage')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', '@element-plus/icons', 'lodash-es', 'monaco-editor', '@tmagic/schema', '@tmagic/utils', 'events', '@tmagic/core', 'element-plus', 'keycon', '@tmagic/stage'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.vue, global.serialize, global.icons, global.lodashEs, global.monaco, global.schema, global.utils, global.events, global.core, global.elementPlus, global.KeyController, global.StageCore));
5
+ })(this, (function (exports, vue, serialize, icons, lodashEs, monaco, schema, utils, events, core, elementPlus, KeyController, StageCore) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return 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 = {__proto__: null, [Symbol.toStringTag]: 'Module'};
11
+ var n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
12
12
  if (e) {
13
13
  Object.keys(e).forEach(function (k) {
14
14
  if (k !== 'default') {
@@ -26,8 +26,13 @@
26
26
 
27
27
  var serialize__default = /*#__PURE__*/_interopDefaultLegacy(serialize);
28
28
  var monaco__namespace = /*#__PURE__*/_interopNamespace(monaco);
29
+ var KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
29
30
  var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
30
31
 
32
+ if (typeof window.global === "undefined") {
33
+ window.global = window;
34
+ }
35
+
31
36
  var _export_sfc = (sfc, props) => {
32
37
  const target = sfc.__vccOpts || sfc;
33
38
  for (const [key, val] of props) {
@@ -36,7 +41,7 @@
36
41
  return target;
37
42
  };
38
43
 
39
- const _sfc_main$k = vue.defineComponent({
44
+ const _sfc_main$m = vue.defineComponent({
40
45
  name: "m-fields-vs-code",
41
46
  props: ["model", "name", "config", "prop"],
42
47
  emits: ["change"],
@@ -53,7 +58,7 @@
53
58
  };
54
59
  }
55
60
  });
56
- function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
61
+ function _sfc_render$m(_ctx, _cache, $props, $setup, $data, $options) {
57
62
  const _component_magic_code_editor = vue.resolveComponent("magic-code-editor");
58
63
  return vue.openBlock(), vue.createBlock(_component_magic_code_editor, {
59
64
  style: vue.normalizeStyle(`height: ${_ctx.height}`),
@@ -62,9 +67,9 @@
62
67
  onSave: _ctx.save
63
68
  }, null, 8, ["style", "init-values", "language", "onSave"]);
64
69
  }
65
- var Code = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$k]]);
70
+ var Code = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$m]]);
66
71
 
67
- const _sfc_main$j = vue.defineComponent({
72
+ const _sfc_main$l = vue.defineComponent({
68
73
  name: "m-fields-code-link",
69
74
  props: {
70
75
  config: {
@@ -119,7 +124,7 @@
119
124
  };
120
125
  }
121
126
  });
122
- function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
127
+ function _sfc_render$l(_ctx, _cache, $props, $setup, $data, $options) {
123
128
  const _component_m_fields_link = vue.resolveComponent("m-fields-link");
124
129
  return vue.openBlock(), vue.createBlock(_component_m_fields_link, {
125
130
  config: _ctx.formConfig,
@@ -128,11 +133,11 @@
128
133
  onChange: _ctx.changeHandler
129
134
  }, null, 8, ["config", "model", "onChange"]);
130
135
  }
131
- var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
136
+ var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$l]]);
132
137
 
133
138
  var UISelect_vue_vue_type_style_index_0_lang = '';
134
139
 
135
- const _sfc_main$i = vue.defineComponent({
140
+ const _sfc_main$k = vue.defineComponent({
136
141
  name: "m-fields-ui-select",
137
142
  props: {
138
143
  labelWidth: String,
@@ -170,6 +175,9 @@
170
175
  }
171
176
  };
172
177
  return {
178
+ Delete: vue.markRaw(icons.Delete),
179
+ Pointer: vue.markRaw(icons.Pointer),
180
+ Close: vue.markRaw(icons.Close),
173
181
  val,
174
182
  uiSelectMode,
175
183
  toName: vue.computed(() => {
@@ -194,34 +202,64 @@
194
202
  };
195
203
  }
196
204
  });
197
- const _hoisted_1$e = /* @__PURE__ */ vue.createElementVNode("i", {
198
- class: "el-icon-delete",
199
- style: { "color": "rgb(221, 75, 57)" }
200
- }, "\u53D6\u6D88", -1);
201
- const _hoisted_2$7 = [
202
- _hoisted_1$e
203
- ];
204
- const _hoisted_3$5 = /* @__PURE__ */ vue.createElementVNode("i", { class: "el-icon-thumb" }, null, -1);
205
- function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
205
+ const _hoisted_1$c = /* @__PURE__ */ vue.createTextVNode("\u53D6\u6D88");
206
+ function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
207
+ const _component_el_button = vue.resolveComponent("el-button");
208
+ const _component_el_tooltip = vue.resolveComponent("el-tooltip");
206
209
  return _ctx.uiSelectMode ? (vue.openBlock(), vue.createElementBlock("div", {
207
210
  key: 0,
208
211
  class: "m-fields-ui-select",
209
212
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.cancelHandler && _ctx.cancelHandler(...args))
210
- }, _hoisted_2$7)) : (vue.openBlock(), vue.createElementBlock("div", {
213
+ }, [
214
+ vue.createVNode(_component_el_button, {
215
+ type: "danger",
216
+ icon: _ctx.Delete,
217
+ text: "",
218
+ style: { "padding": "0" }
219
+ }, {
220
+ default: vue.withCtx(() => [
221
+ _hoisted_1$c
222
+ ]),
223
+ _: 1
224
+ }, 8, ["icon"])
225
+ ])) : (vue.openBlock(), vue.createElementBlock("div", {
211
226
  key: 1,
212
227
  class: "m-fields-ui-select",
213
- onClick: _cache[2] || (_cache[2] = (...args) => _ctx.startSelect && _ctx.startSelect(...args))
228
+ onClick: _cache[1] || (_cache[1] = (...args) => _ctx.startSelect && _ctx.startSelect(...args)),
229
+ style: { "display": "flex" }
214
230
  }, [
215
- _hoisted_3$5,
216
- vue.createElementVNode("span", null, vue.toDisplayString(_ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1),
217
- _ctx.val ? (vue.openBlock(), vue.createElementBlock("i", {
218
- key: 0,
219
- class: "el-icon-delete",
220
- onClick: _cache[1] || (_cache[1] = vue.withModifiers((...args) => _ctx.deleteHandler && _ctx.deleteHandler(...args), ["stop"]))
221
- })) : vue.createCommentVNode("", true)
231
+ vue.createVNode(_component_el_tooltip, { content: "\u6E05\u9664" }, {
232
+ default: vue.withCtx(() => [
233
+ _ctx.val ? (vue.openBlock(), vue.createBlock(_component_el_button, {
234
+ key: 0,
235
+ style: { "padding": "0" },
236
+ type: "danger",
237
+ icon: _ctx.Close,
238
+ text: "",
239
+ onClick: vue.withModifiers(_ctx.deleteHandler, ["stop"])
240
+ }, null, 8, ["icon", "onClick"])) : vue.createCommentVNode("", true)
241
+ ]),
242
+ _: 1
243
+ }),
244
+ vue.createVNode(_component_el_tooltip, {
245
+ content: _ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"
246
+ }, {
247
+ default: vue.withCtx(() => [
248
+ vue.createVNode(_component_el_button, {
249
+ text: "",
250
+ style: { "padding": "0", "margin": "0" }
251
+ }, {
252
+ default: vue.withCtx(() => [
253
+ vue.createTextVNode(vue.toDisplayString(_ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1)
254
+ ]),
255
+ _: 1
256
+ })
257
+ ]),
258
+ _: 1
259
+ }, 8, ["content"])
222
260
  ]));
223
261
  }
224
- var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
262
+ var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$k]]);
225
263
 
226
264
  const toString = (v, language) => {
227
265
  let value = "";
@@ -238,7 +276,7 @@
238
276
  }
239
277
  return value;
240
278
  };
241
- const _sfc_main$h = vue.defineComponent({
279
+ const _sfc_main$j = vue.defineComponent({
242
280
  name: "magic-code-editor",
243
281
  props: {
244
282
  initValues: {
@@ -248,12 +286,16 @@
248
286
  type: [String, Object]
249
287
  },
250
288
  type: {
251
- type: [String],
289
+ type: String,
252
290
  default: () => ""
253
291
  },
254
292
  language: {
255
- type: [String],
293
+ type: String,
256
294
  default: () => "javascript"
295
+ },
296
+ options: {
297
+ type: Object,
298
+ default: () => ({})
257
299
  }
258
300
  },
259
301
  emits: ["initd", "save"],
@@ -263,6 +305,10 @@
263
305
  const values = vue.ref("");
264
306
  const loading = vue.ref(false);
265
307
  const codeEditor = vue.ref();
308
+ const resizeObserver = new globalThis.ResizeObserver(lodashEs.throttle(() => {
309
+ vsEditor?.layout();
310
+ vsDiffEditor?.layout();
311
+ }, 300));
266
312
  const setEditorValue = (v, m) => {
267
313
  values.value = toString(v, props.language);
268
314
  if (props.type === "diff") {
@@ -275,10 +321,6 @@
275
321
  }
276
322
  return vsEditor?.setValue(values.value);
277
323
  };
278
- const resizeHandler = () => {
279
- vsEditor?.layout();
280
- vsDiffEditor?.layout();
281
- };
282
324
  const getEditorValue = () => props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
283
325
  const init = async () => {
284
326
  if (!codeEditor.value)
@@ -289,8 +331,9 @@
289
331
  tabSize: 2,
290
332
  theme: "vs-dark",
291
333
  fontFamily: 'dm, Menlo, Monaco, "Courier New", monospace',
292
- fontSize: 15,
293
- formatOnPaste: true
334
+ fontSize: 14,
335
+ formatOnPaste: true,
336
+ ...props.options
294
337
  };
295
338
  if (props.type === "diff") {
296
339
  vsDiffEditor = monaco__namespace.editor.createDiffEditor(codeEditor.value, options);
@@ -311,7 +354,7 @@
311
354
  emit("save", getEditorValue());
312
355
  });
313
356
  }
314
- globalThis.addEventListener("resize", resizeHandler);
357
+ resizeObserver.observe(codeEditor.value);
315
358
  };
316
359
  vue.watch(() => props.initValues, (v, preV) => {
317
360
  if (v !== preV) {
@@ -326,7 +369,7 @@
326
369
  init();
327
370
  });
328
371
  vue.onUnmounted(() => {
329
- globalThis.removeEventListener("resize", resizeHandler);
372
+ resizeObserver.disconnect();
330
373
  });
331
374
  return {
332
375
  values,
@@ -343,14 +386,14 @@
343
386
  };
344
387
  }
345
388
  });
346
- const _hoisted_1$d = {
389
+ const _hoisted_1$b = {
347
390
  ref: "codeEditor",
348
391
  class: "magic-code-editor"
349
392
  };
350
- function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
351
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$d, null, 512);
393
+ function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
394
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$b, null, 512);
352
395
  }
353
- var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
396
+ var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
354
397
 
355
398
  let $TMAGIC_EDITOR = {};
356
399
  const setConfig = (option) => {
@@ -359,9 +402,6 @@
359
402
  const getConfig = (key) => $TMAGIC_EDITOR[key];
360
403
 
361
404
  class UndoRedo {
362
- elementList;
363
- listCursor;
364
- listMaxSize;
365
405
  constructor(listMaxSize = 200) {
366
406
  const minListMaxSize = 2;
367
407
  this.elementList = [];
@@ -434,11 +474,40 @@
434
474
 
435
475
  const methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
436
476
  const isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
477
+ const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethodName, fn) => {
478
+ try {
479
+ let beforeArgs = args;
480
+ for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
481
+ let beforeReturnValue = await beforeMethod(...beforeArgs) || [];
482
+ if (isError(beforeReturnValue))
483
+ throw beforeReturnValue;
484
+ if (!Array.isArray(beforeReturnValue)) {
485
+ beforeReturnValue = [beforeReturnValue];
486
+ }
487
+ beforeArgs = beforeArgs.map((v, index) => {
488
+ if (typeof beforeReturnValue[index] === "undefined")
489
+ return v;
490
+ return beforeReturnValue[index];
491
+ });
492
+ }
493
+ let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
494
+ for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
495
+ returnValue = await afterMethod(returnValue, ...beforeArgs);
496
+ if (isError(returnValue))
497
+ throw returnValue;
498
+ }
499
+ return returnValue;
500
+ } catch (error) {
501
+ throw error;
502
+ }
503
+ };
437
504
  class BaseService extends events.EventEmitter {
438
- pluginOptionsList = {};
439
- middleware = {};
440
- constructor(methods) {
505
+ constructor(methods = [], serialMethods = []) {
441
506
  super();
507
+ this.pluginOptionsList = {};
508
+ this.middleware = {};
509
+ this.taskList = [];
510
+ this.doingTask = false;
442
511
  methods.forEach((propertyName) => {
443
512
  const scope = this;
444
513
  const sourceMethod = scope[propertyName];
@@ -450,27 +519,23 @@
450
519
  const fn = compose(this.middleware[propertyName]);
451
520
  Object.defineProperty(scope, propertyName, {
452
521
  value: async (...args) => {
453
- let beforeArgs = args;
454
- for (const beforeMethod of this.pluginOptionsList[beforeMethodName]) {
455
- let beforeReturnValue = await beforeMethod(...beforeArgs) || [];
456
- if (isError(beforeReturnValue))
457
- throw beforeReturnValue;
458
- if (!Array.isArray(beforeReturnValue)) {
459
- beforeReturnValue = [beforeReturnValue];
460
- }
461
- beforeArgs = beforeArgs.map((v, index) => {
462
- if (typeof beforeReturnValue[index] === "undefined")
463
- return v;
464
- return beforeReturnValue[index];
465
- });
522
+ if (!serialMethods.includes(propertyName)) {
523
+ return doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
466
524
  }
467
- let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
468
- for (const afterMethod of this.pluginOptionsList[afterMethodName]) {
469
- returnValue = await afterMethod(...beforeArgs, returnValue);
470
- if (isError(returnValue))
471
- throw returnValue;
525
+ const promise = new Promise((resolve, reject) => {
526
+ this.taskList.push(async () => {
527
+ try {
528
+ const value = await doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
529
+ resolve(value);
530
+ } catch (e) {
531
+ reject(e);
532
+ }
533
+ });
534
+ });
535
+ if (!this.doingTask) {
536
+ this.doTask();
472
537
  }
473
- return returnValue;
538
+ return promise;
474
539
  }
475
540
  });
476
541
  });
@@ -487,19 +552,34 @@
487
552
  this.pluginOptionsList[methodName2].push(method);
488
553
  });
489
554
  }
555
+ async doTask() {
556
+ this.doingTask = true;
557
+ let task = this.taskList.shift();
558
+ while (task) {
559
+ await task();
560
+ task = this.taskList.shift();
561
+ }
562
+ this.doingTask = false;
563
+ }
490
564
  }
491
565
 
492
566
  class History extends BaseService {
493
- state = vue.reactive({
494
- pageSteps: {},
495
- pageId: void 0,
496
- canRedo: false,
497
- canUndo: false
498
- });
499
567
  constructor() {
500
568
  super([]);
569
+ this.state = vue.reactive({
570
+ pageSteps: {},
571
+ pageId: void 0,
572
+ canRedo: false,
573
+ canUndo: false
574
+ });
501
575
  this.on("change", this.setCanUndoRedo);
502
576
  }
577
+ reset() {
578
+ this.state.pageSteps = {};
579
+ this.state.pageId = void 0;
580
+ this.state.canRedo = false;
581
+ this.state.canUndo = false;
582
+ }
503
583
  changePage(page) {
504
584
  if (!page)
505
585
  return;
@@ -563,12 +643,12 @@
563
643
  var historyService = new History();
564
644
 
565
645
  class Props extends BaseService {
566
- state = vue.reactive({
567
- propsConfigMap: {},
568
- propsValueMap: {}
569
- });
570
646
  constructor() {
571
647
  super(["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue"]);
648
+ this.state = vue.reactive({
649
+ propsConfigMap: {},
650
+ propsValueMap: {}
651
+ });
572
652
  }
573
653
  setPropsConfigs(configs) {
574
654
  Object.keys(configs).forEach((type) => {
@@ -593,7 +673,7 @@
593
673
  setPropsValue(type, value) {
594
674
  this.state.propsValueMap[type] = value;
595
675
  }
596
- async getPropsValue(type) {
676
+ async getPropsValue(type, defaultValue = {}) {
597
677
  if (type === "area") {
598
678
  const value = await this.getPropsValue("button");
599
679
  value.className = "action-area";
@@ -605,7 +685,7 @@
605
685
  }
606
686
  return lodashEs.cloneDeep({
607
687
  ...getDefaultPropsValue(type),
608
- ...this.state.propsValueMap[type] || {}
688
+ ...lodashEs.mergeWith(this.state.propsValueMap[type] || {}, defaultValue)
609
689
  });
610
690
  }
611
691
  }
@@ -666,7 +746,7 @@
666
746
  };
667
747
  const setNewItemId = (config, parent) => {
668
748
  const oldId = config.id;
669
- config.id = generateId(config.type);
749
+ config.id = generateId(config.type || "component");
670
750
  config.name = `${config.name?.replace(/_(\d+)$/, "")}_${config.id}`;
671
751
  if (utils.isPop(config) && parent?.type === schema.NodeType.PAGE) {
672
752
  updatePopId(oldId, config.id, parent);
@@ -689,11 +769,25 @@
689
769
  };
690
770
  return node;
691
771
  };
692
- const initPosition = (node, layout) => {
772
+ const setTop2Middle = (node, parentNode, stage) => {
773
+ const style = node.style || {};
774
+ const height = style.height || 0;
775
+ if (!stage || typeof style.top !== "undefined" || !parentNode.style || !utils.isNumber(height))
776
+ return style;
777
+ const { height: parentHeight } = parentNode.style;
778
+ if (utils.isPage(parentNode)) {
779
+ const { scrollTop = 0, wrapperHeight } = stage.mask;
780
+ style.top = (wrapperHeight - height) / 2 + scrollTop;
781
+ } else {
782
+ style.top = (parentHeight - height) / 2;
783
+ }
784
+ return style;
785
+ };
786
+ const initPosition = (node, layout, parentNode, stage) => {
693
787
  if (layout === Layout.ABSOLUTE) {
694
788
  node.style = {
695
789
  position: "absolute",
696
- ...node.style || {}
790
+ ...setTop2Middle(node, parentNode, stage)
697
791
  };
698
792
  return node;
699
793
  }
@@ -740,7 +834,9 @@
740
834
  const cur = path.pop();
741
835
  const offset = {
742
836
  left: cur?.style?.left || 0,
743
- top: cur?.style?.top || 0
837
+ top: cur?.style?.top || 0,
838
+ right: "",
839
+ bottom: ""
744
840
  };
745
841
  path.forEach((value) => {
746
842
  offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
@@ -774,16 +870,6 @@
774
870
  };
775
871
 
776
872
  class Editor$1 extends BaseService {
777
- isHistoryStateChange = false;
778
- state = vue.reactive({
779
- root: null,
780
- page: null,
781
- parent: null,
782
- node: null,
783
- stage: null,
784
- highlightNode: null,
785
- modifiedNodeIds: /* @__PURE__ */ new Map()
786
- });
787
873
  constructor() {
788
874
  super([
789
875
  "getLayout",
@@ -796,14 +882,27 @@
796
882
  "paste",
797
883
  "alignCenter",
798
884
  "moveLayer",
885
+ "move",
799
886
  "undo",
800
887
  "redo",
801
888
  "highlight"
802
- ]);
889
+ ], ["select", "update", "moveLayer"]);
890
+ this.isHistoryStateChange = false;
891
+ this.state = vue.reactive({
892
+ root: null,
893
+ page: null,
894
+ parent: null,
895
+ node: null,
896
+ stage: null,
897
+ highlightNode: null,
898
+ modifiedNodeIds: /* @__PURE__ */ new Map(),
899
+ pageLength: 0
900
+ });
803
901
  }
804
902
  set(name, value) {
805
903
  this.state[name] = value;
806
904
  if (name === "root") {
905
+ this.state.pageLength = value?.items?.length || 0;
807
906
  this.emit("root-change", value);
808
907
  }
809
908
  }
@@ -811,7 +910,7 @@
811
910
  return this.state[name];
812
911
  }
813
912
  getNodeInfo(id) {
814
- const root = this.get("root");
913
+ const root = vue.toRaw(this.get("root"));
815
914
  if (!root)
816
915
  return {};
817
916
  if (id === root.id) {
@@ -842,11 +941,13 @@
842
941
  const { parent } = this.getNodeInfo(id);
843
942
  return parent;
844
943
  }
845
- async getLayout(node) {
846
- if (node.layout) {
847
- return node.layout;
944
+ async getLayout(parent, node) {
945
+ if (node && typeof node !== "function" && isFixed(node))
946
+ return Layout.FIXED;
947
+ if (parent.layout) {
948
+ return parent.layout;
848
949
  }
849
- if (!node.style?.position) {
950
+ if (!parent.style?.position) {
850
951
  return Layout.RELATIVE;
851
952
  }
852
953
  return Layout.ABSOLUTE;
@@ -861,19 +962,44 @@
861
962
  } else {
862
963
  historyService.empty();
863
964
  }
965
+ this.emit("select", node);
864
966
  return node;
865
967
  }
968
+ async selectNextNode() {
969
+ const node = vue.toRaw(this.get("node"));
970
+ if (!node || utils.isPage(node) || node.type === schema.NodeType.ROOT)
971
+ return node;
972
+ const parent = vue.toRaw(this.getParentById(node.id));
973
+ if (!parent)
974
+ return node;
975
+ const index = getNodeIndex(node, parent);
976
+ const nextNode = parent.items[index + 1] || parent.items[0];
977
+ await this.select(nextNode);
978
+ this.get("stage")?.select(nextNode.id);
979
+ return nextNode;
980
+ }
981
+ async selectNextPage() {
982
+ const root = vue.toRaw(this.get("root"));
983
+ const page = vue.toRaw(this.get("page"));
984
+ const index = getNodeIndex(page, root);
985
+ const nextPage = root.items[index + 1] || root.items[0];
986
+ await this.select(nextPage);
987
+ this.get("stage")?.select(nextPage.id);
988
+ return nextPage;
989
+ }
866
990
  highlight(config2) {
867
991
  const { node } = this.selectedConfigExceptionHandler(config2);
868
- const currentHighligtNode = this.get("highlightNode");
869
- if (currentHighligtNode === node)
992
+ const currentHighlightNode = this.get("highlightNode");
993
+ if (currentHighlightNode === node)
870
994
  return;
871
995
  this.set("highlightNode", node);
872
996
  }
873
- async add({ type, ...config2 }, parent) {
997
+ async add(addNode, parent) {
998
+ const { type, ...config2 } = addNode;
874
999
  const curNode = this.get("node");
875
1000
  let parentNode;
876
- if (type === schema.NodeType.PAGE) {
1001
+ const isPage2 = type === schema.NodeType.PAGE;
1002
+ if (isPage2) {
877
1003
  parentNode = this.get("root");
878
1004
  } else if (parent && typeof parent !== "function") {
879
1005
  parentNode = parent;
@@ -884,18 +1010,24 @@
884
1010
  }
885
1011
  if (!parentNode)
886
1012
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
887
- const layout = await this.getLayout(parentNode);
888
- const newNode = initPosition({ ...vue.toRaw(await propsService.getPropsValue(type)), ...config2 }, layout);
1013
+ const layout = await this.getLayout(vue.toRaw(parentNode), addNode);
1014
+ const newNode = initPosition({ ...vue.toRaw(await propsService.getPropsValue(type, config2)) }, layout, parentNode, this.get("stage"));
889
1015
  if ((parentNode?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && newNode.type !== schema.NodeType.PAGE) {
890
1016
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
891
1017
  }
892
1018
  parentNode?.items?.push(newNode);
893
- await this.get("stage")?.add({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(this.get("root")) });
1019
+ const stage = this.get("stage");
1020
+ await stage?.add({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(this.get("root")) });
894
1021
  await this.select(newNode);
895
1022
  this.addModifiedNodeId(newNode.id);
896
- if (type !== schema.NodeType.PAGE) {
1023
+ if (!isPage2) {
897
1024
  this.pushHistoryState();
898
1025
  }
1026
+ stage?.select(newNode.id);
1027
+ if (isPage2) {
1028
+ this.state.pageLength += 1;
1029
+ }
1030
+ this.emit("add", newNode);
899
1031
  return newNode;
900
1032
  }
901
1033
  async remove(node) {
@@ -911,14 +1043,31 @@
911
1043
  if (typeof index !== "number" || index === -1)
912
1044
  throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
913
1045
  parent.items?.splice(index, 1);
914
- this.get("stage")?.remove({ id: node.id, root: this.get("root") });
1046
+ const stage = this.get("stage");
1047
+ stage?.remove({ id: node.id, root: this.get("root") });
915
1048
  if (node.type === schema.NodeType.PAGE) {
916
- await this.select(root.items[0] || root);
1049
+ this.state.pageLength -= 1;
1050
+ if (root.items[0]) {
1051
+ await this.select(root.items[0]);
1052
+ stage?.select(root.items[0].id);
1053
+ } else {
1054
+ this.set("node", null);
1055
+ this.set("parent", null);
1056
+ this.set("page", null);
1057
+ this.set("stage", null);
1058
+ this.set("highlightNode", null);
1059
+ this.resetModifiedNodeId();
1060
+ historyService.reset();
1061
+ this.emit("remove", node);
1062
+ return node;
1063
+ }
917
1064
  } else {
918
1065
  await this.select(parent);
1066
+ stage?.select(parent.id);
919
1067
  }
920
1068
  this.addModifiedNodeId(parent.id);
921
1069
  this.pushHistoryState();
1070
+ this.emit("remove", node);
922
1071
  return node;
923
1072
  }
924
1073
  async update(config2) {
@@ -953,7 +1102,7 @@
953
1102
  newConfig = setLayout(newConfig, newLayout);
954
1103
  }
955
1104
  parentNodeItems[index] = newConfig;
956
- if (newConfig.id === this.get("node").id) {
1105
+ if (`${newConfig.id}` === `${this.get("node").id}`) {
957
1106
  this.set("node", newConfig);
958
1107
  }
959
1108
  this.get("stage")?.update({ config: lodashEs.cloneDeep(newConfig), root: this.get("root") });
@@ -962,6 +1111,7 @@
962
1111
  }
963
1112
  this.addModifiedNodeId(newConfig.id);
964
1113
  this.pushHistoryState();
1114
+ this.emit("update", newConfig);
965
1115
  return newConfig;
966
1116
  }
967
1117
  async sort(id1, id2) {
@@ -1005,7 +1155,7 @@
1005
1155
  async alignCenter(config2) {
1006
1156
  const parent = this.get("parent");
1007
1157
  const node = this.get("node");
1008
- const layout = await this.getLayout(parent);
1158
+ const layout = await this.getLayout(vue.toRaw(parent), vue.toRaw(node));
1009
1159
  if (layout === Layout.RELATIVE) {
1010
1160
  return;
1011
1161
  }
@@ -1042,6 +1192,26 @@
1042
1192
  await this.changeHistoryState(value);
1043
1193
  return value;
1044
1194
  }
1195
+ async move(left, top) {
1196
+ const node = vue.toRaw(this.get("node"));
1197
+ if (!node || utils.isPage(node))
1198
+ return;
1199
+ const { style, id } = node;
1200
+ if (!style || style.position !== "absolute")
1201
+ return;
1202
+ if (top && !utils.isNumber(style.top))
1203
+ return;
1204
+ if (left && !utils.isNumber(style.left))
1205
+ return;
1206
+ this.update({
1207
+ id,
1208
+ style: {
1209
+ ...style,
1210
+ left: Number(style.left) + left,
1211
+ top: Number(style.top) + top
1212
+ }
1213
+ });
1214
+ }
1045
1215
  destroy() {
1046
1216
  this.removeAllListeners();
1047
1217
  this.set("root", null);
@@ -1074,7 +1244,12 @@
1074
1244
  this.isHistoryStateChange = true;
1075
1245
  await this.update(value.data);
1076
1246
  this.set("modifiedNodeIds", value.modifiedNodeIds);
1077
- setTimeout(() => value.nodeId && this.select(value.nodeId), 0);
1247
+ setTimeout(async () => {
1248
+ if (!value.nodeId)
1249
+ return;
1250
+ await this.select(value.nodeId);
1251
+ this.get("stage")?.select(value.nodeId);
1252
+ }, 0);
1078
1253
  }
1079
1254
  async toggleFixedPosition(dist, src, root) {
1080
1255
  let newConfig = lodashEs.cloneDeep(dist);
@@ -1266,6 +1441,25 @@
1266
1441
  defaultValue: "100% 100%"
1267
1442
  }
1268
1443
  ]
1444
+ },
1445
+ {
1446
+ type: "fieldset",
1447
+ legend: "\u5B57\u4F53",
1448
+ items: [
1449
+ {
1450
+ name: "color",
1451
+ text: "\u989C\u8272",
1452
+ type: "colorPicker"
1453
+ },
1454
+ {
1455
+ name: "fontSize",
1456
+ text: "\u5927\u5C0F"
1457
+ },
1458
+ {
1459
+ name: "fontWeight",
1460
+ text: "\u7C97\u7EC6"
1461
+ }
1462
+ ]
1269
1463
  }
1270
1464
  ]
1271
1465
  }
@@ -1298,7 +1492,7 @@
1298
1492
  type: "select",
1299
1493
  options: (mForm, { model }) => {
1300
1494
  const node = editorService.getNodeById(model.to);
1301
- if (!node)
1495
+ if (!node?.type)
1302
1496
  return [];
1303
1497
  return eventsService.getMethod(node.type).map((option) => ({
1304
1498
  text: option.label,
@@ -1333,7 +1527,7 @@
1333
1527
  name: type
1334
1528
  });
1335
1529
 
1336
- const _sfc_main$g = vue.defineComponent({
1530
+ const _sfc_main$i = vue.defineComponent({
1337
1531
  components: { Plus: icons.Plus },
1338
1532
  setup() {
1339
1533
  const services = vue.inject("services");
@@ -1350,14 +1544,14 @@
1350
1544
  };
1351
1545
  }
1352
1546
  });
1353
- const _hoisted_1$c = { class: "m-editor-empty-panel" };
1354
- const _hoisted_2$6 = { class: "m-editor-empty-content" };
1355
- const _hoisted_3$4 = /* @__PURE__ */ vue.createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1356
- function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
1547
+ const _hoisted_1$a = { class: "m-editor-empty-panel" };
1548
+ const _hoisted_2$4 = { class: "m-editor-empty-content" };
1549
+ const _hoisted_3$2 = /* @__PURE__ */ vue.createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1550
+ function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
1357
1551
  const _component_plus = vue.resolveComponent("plus");
1358
1552
  const _component_el_icon = vue.resolveComponent("el-icon");
1359
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$c, [
1360
- vue.createElementVNode("div", _hoisted_2$6, [
1553
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$a, [
1554
+ vue.createElementVNode("div", _hoisted_2$4, [
1361
1555
  vue.createElementVNode("div", {
1362
1556
  class: "m-editor-empty-button",
1363
1557
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
@@ -1370,12 +1564,12 @@
1370
1564
  _: 1
1371
1565
  })
1372
1566
  ]),
1373
- _hoisted_3$4
1567
+ _hoisted_3$2
1374
1568
  ])
1375
1569
  ])
1376
1570
  ]);
1377
1571
  }
1378
- var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
1572
+ var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
1379
1573
 
1380
1574
  /*
1381
1575
  Copyright (c) 2018 Daybrush
@@ -1779,8 +1973,8 @@
1779
1973
  name: gesto
1780
1974
  license: MIT
1781
1975
  author: Daybrush
1782
- repository: git+https://github.com/daybrush/gesture.git
1783
- version: 1.5.0
1976
+ repository: git+https://github.com/daybrush/gesto.git
1977
+ version: 1.7.0
1784
1978
  */
1785
1979
 
1786
1980
  /*! *****************************************************************************
@@ -1949,19 +2143,6 @@
1949
2143
 
1950
2144
  var __proto = ClientStore.prototype;
1951
2145
 
1952
- __proto.addClients = function (clients) {
1953
- if (clients === void 0) {
1954
- clients = this.prevClients;
1955
- }
1956
-
1957
- var position = this.getPosition(clients);
1958
- var deltaX = position.deltaX,
1959
- deltaY = position.deltaY;
1960
- this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
1961
- this.prevClients = clients;
1962
- return position;
1963
- };
1964
-
1965
2146
  __proto.getAngle = function (clients) {
1966
2147
  if (clients === void 0) {
1967
2148
  clients = this.prevClients;
@@ -1978,8 +2159,17 @@
1978
2159
  return getRotatiion(clients) - getRotatiion(this.startClients);
1979
2160
  };
1980
2161
 
1981
- __proto.getPosition = function (clients) {
1982
- return getPosition(clients || this.prevClients, this.prevClients, this.startClients);
2162
+ __proto.getPosition = function (clients, isAdd) {
2163
+ if (clients === void 0) {
2164
+ clients = this.prevClients;
2165
+ }
2166
+
2167
+ var position = getPosition(clients || this.prevClients, this.prevClients, this.startClients);
2168
+ var deltaX = position.deltaX,
2169
+ deltaY = position.deltaY;
2170
+ this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
2171
+ this.prevClients = clients;
2172
+ return position;
1983
2173
  };
1984
2174
 
1985
2175
  __proto.getPositions = function (clients) {
@@ -2028,10 +2218,6 @@
2028
2218
  client.clientX -= deltaX;
2029
2219
  client.clientY -= deltaY;
2030
2220
  });
2031
- this.prevClients.forEach(function (client) {
2032
- client.clientX -= deltaX;
2033
- client.clientY -= deltaY;
2034
- });
2035
2221
  };
2036
2222
 
2037
2223
  return ClientStore;
@@ -2070,6 +2256,7 @@
2070
2256
  _this.targets = [];
2071
2257
  _this.prevTime = 0;
2072
2258
  _this.doubleFlag = false;
2259
+ _this._dragFlag = false;
2073
2260
 
2074
2261
  _this.onDragStart = function (e, isTrusted) {
2075
2262
  if (isTrusted === void 0) {
@@ -2100,7 +2287,8 @@
2100
2287
  if (checkInput || activeElement === target) {
2101
2288
  // force false or already focused.
2102
2289
  return false;
2103
- }
2290
+ } // no focus
2291
+
2104
2292
 
2105
2293
  if (activeElement && hasContentEditable && activeElement.isContentEditable && activeElement.contains(target)) {
2106
2294
  return false;
@@ -2116,6 +2304,7 @@
2116
2304
  _this.clientStores = [new ClientStore(getEventClients(e))];
2117
2305
  _this.flag = true;
2118
2306
  _this.isDrag = false;
2307
+ _this._dragFlag = true;
2119
2308
  _this.datas = {};
2120
2309
 
2121
2310
  if (preventRightClick && (e.which === 3 || e.button === 2)) {
@@ -2131,7 +2320,14 @@
2131
2320
  inputEvent: e,
2132
2321
  isTrusted: isTrusted,
2133
2322
  isDouble: _this.doubleFlag
2134
- }, _this.getCurrentStore().getPosition()));
2323
+ }, _this.getCurrentStore().getPosition(), {
2324
+ preventDefault: function () {
2325
+ e.preventDefault();
2326
+ },
2327
+ preventDrag: function () {
2328
+ _this._dragFlag = false;
2329
+ }
2330
+ }));
2135
2331
 
2136
2332
  if (result === false) {
2137
2333
  _this.initDrag();
@@ -2180,24 +2376,26 @@
2180
2376
 
2181
2377
  var result = _this.moveClients(clients, e, false);
2182
2378
 
2183
- if (_this.pinchFlag || result.deltaX || result.deltaY) {
2184
- var dragResult = _this.emit("drag", __assign({}, result, {
2185
- isScroll: !!isScroll,
2186
- inputEvent: e
2187
- }));
2379
+ if (_this._dragFlag) {
2380
+ if (_this.pinchFlag || result.deltaX || result.deltaY) {
2381
+ var dragResult = _this.emit("drag", __assign({}, result, {
2382
+ isScroll: !!isScroll,
2383
+ inputEvent: e
2384
+ }));
2188
2385
 
2189
- if (dragResult === false) {
2190
- _this.stop();
2386
+ if (dragResult === false) {
2387
+ _this.stop();
2191
2388
 
2192
- return;
2389
+ return;
2390
+ }
2193
2391
  }
2194
- }
2195
2392
 
2196
- if (_this.pinchFlag) {
2197
- _this.onPinch(e, clients);
2393
+ if (_this.pinchFlag) {
2394
+ _this.onPinch(e, clients);
2395
+ }
2198
2396
  }
2199
2397
 
2200
- _this.getCurrentStore().addClients(clients);
2398
+ _this.getCurrentStore().getPosition(clients, true);
2201
2399
  };
2202
2400
 
2203
2401
  _this.onDragEnd = function (e) {
@@ -2215,7 +2413,7 @@
2215
2413
 
2216
2414
  _this.flag = false;
2217
2415
 
2218
- var position = _this.getCurrentStore().getPosition();
2416
+ var position = _this._getPosition();
2219
2417
 
2220
2418
  var currentTime = now();
2221
2419
  var isDouble = !_this.isDrag && _this.doubleFlag;
@@ -2409,7 +2607,23 @@
2409
2607
  return this;
2410
2608
  };
2411
2609
  /**
2412
- * Set the event data while dragging.
2610
+ * Get the current event state while dragging.
2611
+ */
2612
+
2613
+
2614
+ __proto.getCurrentEvent = function (inputEvent) {
2615
+ return __assign({
2616
+ datas: this.datas
2617
+ }, this._getPosition(), {
2618
+ movement: this.getMovement(),
2619
+ isDrag: this.isDrag,
2620
+ isPinch: this.isPinch,
2621
+ isScroll: false,
2622
+ inputEvent: inputEvent
2623
+ });
2624
+ };
2625
+ /**
2626
+ * Get & Set the event data while dragging.
2413
2627
  */
2414
2628
 
2415
2629
 
@@ -2525,9 +2739,12 @@
2525
2739
  };
2526
2740
 
2527
2741
  __proto.moveClients = function (clients, inputEvent, isAdd) {
2528
- var store = this.getCurrentStore();
2529
- var position = store[isAdd ? "addClients" : "getPosition"](clients);
2530
- this.isDrag = true;
2742
+ var position = this._getPosition(clients, isAdd);
2743
+
2744
+ if (position.deltaX || position.deltaY) {
2745
+ this.isDrag = true;
2746
+ }
2747
+
2531
2748
  return __assign({
2532
2749
  datas: this.datas
2533
2750
  }, position, {
@@ -2539,12 +2756,31 @@
2539
2756
  });
2540
2757
  };
2541
2758
 
2759
+ __proto._getPosition = function (clients, isAdd) {
2760
+ var store = this.getCurrentStore();
2761
+ var position = store.getPosition(clients, isAdd);
2762
+
2763
+ var _a = this.clientStores.slice(1).reduce(function (prev, cur) {
2764
+ var storePosition = cur.getPosition();
2765
+ prev.distX += storePosition.distX;
2766
+ prev.distY += storePosition.distY;
2767
+ return prev;
2768
+ }, position),
2769
+ distX = _a.distX,
2770
+ distY = _a.distY;
2771
+
2772
+ return __assign({}, position, {
2773
+ distX: distX,
2774
+ distY: distY
2775
+ });
2776
+ };
2777
+
2542
2778
  return Gesto;
2543
2779
  }(EventEmitter$1);
2544
2780
 
2545
2781
  var Gesto$1 = Gesto;
2546
2782
 
2547
- const _sfc_main$f = vue.defineComponent({
2783
+ const _sfc_main$h = vue.defineComponent({
2548
2784
  name: "m-editor-resize",
2549
2785
  props: {
2550
2786
  type: {
@@ -2586,33 +2822,33 @@
2586
2822
  };
2587
2823
  }
2588
2824
  });
2589
- const _hoisted_1$b = {
2825
+ const _hoisted_1$9 = {
2590
2826
  ref: "target",
2591
2827
  class: "m-editor-resizer"
2592
2828
  };
2593
- function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2594
- return vue.openBlock(), vue.createElementBlock("span", _hoisted_1$b, [
2829
+ function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
2830
+ return vue.openBlock(), vue.createElementBlock("span", _hoisted_1$9, [
2595
2831
  vue.renderSlot(_ctx.$slots, "default")
2596
2832
  ], 512);
2597
2833
  }
2598
- var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
2834
+ var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
2599
2835
 
2600
- const _sfc_main$e = vue.defineComponent({
2836
+ const _sfc_main$g = vue.defineComponent({
2601
2837
  components: {
2602
2838
  AddPageBox,
2603
2839
  Resizer
2604
2840
  },
2605
2841
  setup() {
2606
- const services = vue.inject("services");
2607
- const root = vue.computed(() => services?.editorService.get("root"));
2842
+ const { editorService, uiService } = vue.inject("services") || {};
2843
+ const root = vue.computed(() => editorService?.get("root"));
2608
2844
  return {
2609
2845
  root,
2610
- pageLength: vue.computed(() => root.value?.items?.length || 0),
2611
- showSrc: vue.computed(() => services?.uiService.get("showSrc")),
2612
- columnWidth: vue.computed(() => services?.uiService.get("columnWidth")),
2846
+ pageLength: vue.computed(() => editorService?.get("pageLength") || 0),
2847
+ showSrc: vue.computed(() => uiService?.get("showSrc")),
2848
+ columnWidth: vue.computed(() => uiService?.get("columnWidth")),
2613
2849
  saveCode(value) {
2614
2850
  try {
2615
- services?.editorService.set("root", eval(value));
2851
+ editorService?.set("root", eval(value));
2616
2852
  } catch (e) {
2617
2853
  console.error(e);
2618
2854
  }
@@ -2620,24 +2856,24 @@
2620
2856
  };
2621
2857
  }
2622
2858
  });
2623
- const _hoisted_1$a = { class: "m-editor" };
2624
- const _hoisted_2$5 = {
2859
+ const _hoisted_1$8 = { class: "m-editor" };
2860
+ const _hoisted_2$3 = {
2625
2861
  key: 1,
2626
2862
  class: "m-editor-content"
2627
2863
  };
2628
- function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2864
+ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
2629
2865
  const _component_magic_code_editor = vue.resolveComponent("magic-code-editor");
2630
2866
  const _component_resizer = vue.resolveComponent("resizer");
2631
2867
  const _component_el_scrollbar = vue.resolveComponent("el-scrollbar");
2632
2868
  const _component_add_page_box = vue.resolveComponent("add-page-box");
2633
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$a, [
2869
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$8, [
2634
2870
  vue.renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2635
2871
  _ctx.showSrc ? (vue.openBlock(), vue.createBlock(_component_magic_code_editor, {
2636
2872
  key: 0,
2637
2873
  class: "m-editor-content",
2638
2874
  "init-values": _ctx.root,
2639
2875
  onSave: _ctx.saveCode
2640
- }, null, 8, ["init-values", "onSave"])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$5, [
2876
+ }, null, 8, ["init-values", "onSave"])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$3, [
2641
2877
  vue.createElementVNode("div", {
2642
2878
  class: "m-editor-framework-left",
2643
2879
  style: vue.normalizeStyle(`width: ${_ctx.columnWidth?.left}px`)
@@ -2670,9 +2906,9 @@
2670
2906
  ]))
2671
2907
  ]);
2672
2908
  }
2673
- var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
2909
+ var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
2674
2910
 
2675
- const _sfc_main$d = vue.defineComponent({
2911
+ const _sfc_main$f = vue.defineComponent({
2676
2912
  name: "m-icon",
2677
2913
  components: { Edit: icons.Edit },
2678
2914
  props: {
@@ -2686,8 +2922,8 @@
2686
2922
  };
2687
2923
  }
2688
2924
  });
2689
- const _hoisted_1$9 = ["src"];
2690
- function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2925
+ const _hoisted_1$7 = ["src"];
2926
+ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2691
2927
  const _component_edit = vue.resolveComponent("edit");
2692
2928
  const _component_el_icon = vue.resolveComponent("el-icon");
2693
2929
  return !_ctx.icon ? (vue.openBlock(), vue.createBlock(_component_el_icon, { key: 0 }, {
@@ -2698,7 +2934,7 @@
2698
2934
  })) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (vue.openBlock(), vue.createElementBlock("img", {
2699
2935
  key: 1,
2700
2936
  src: _ctx.icon
2701
- }, null, 8, _hoisted_1$9)) : typeof _ctx.icon === "string" ? (vue.openBlock(), vue.createElementBlock("i", {
2937
+ }, null, 8, _hoisted_1$7)) : typeof _ctx.icon === "string" ? (vue.openBlock(), vue.createElementBlock("i", {
2702
2938
  key: 2,
2703
2939
  class: vue.normalizeClass(_ctx.icon)
2704
2940
  }, null, 2)) : (vue.openBlock(), vue.createBlock(_component_el_icon, { key: 3 }, {
@@ -2708,9 +2944,9 @@
2708
2944
  _: 1
2709
2945
  }));
2710
2946
  }
2711
- var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
2947
+ var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
2712
2948
 
2713
- const _sfc_main$c = vue.defineComponent({
2949
+ const _sfc_main$e = vue.defineComponent({
2714
2950
  components: { MIcon, ArrowDown: icons.ArrowDown },
2715
2951
  props: {
2716
2952
  data: {
@@ -2720,16 +2956,20 @@
2720
2956
  type: "text",
2721
2957
  display: false
2722
2958
  })
2959
+ },
2960
+ eventType: {
2961
+ type: String,
2962
+ default: "click"
2723
2963
  }
2724
2964
  },
2725
2965
  setup(props) {
2726
2966
  const services = vue.inject("services");
2727
2967
  const uiService = services?.uiService;
2728
- const zoomInHandler = () => uiService?.set("zoom", zoom.value + 0.1);
2729
- const zoomOutHandler = () => uiService?.set("zoom", zoom.value - 0.1);
2730
2968
  const zoom = vue.computed(() => uiService?.get("zoom") ?? 1);
2731
2969
  const showGuides = vue.computed(() => uiService?.get("showGuides") ?? true);
2732
2970
  const showRule = vue.computed(() => uiService?.get("showRule") ?? true);
2971
+ const zoomInHandler = () => uiService?.zoom(0.1);
2972
+ const zoomOutHandler = () => uiService?.zoom(-0.1);
2733
2973
  const item = vue.computed(() => {
2734
2974
  if (typeof props.data !== "string") {
2735
2975
  return props.data;
@@ -2746,7 +2986,7 @@
2746
2986
  case "delete":
2747
2987
  return {
2748
2988
  type: "button",
2749
- icon: icons.Delete,
2989
+ icon: vue.markRaw(icons.Delete),
2750
2990
  tooltip: "\u522A\u9664",
2751
2991
  disabled: () => services?.editorService.get("node")?.type === schema.NodeType.PAGE,
2752
2992
  handler: () => services?.editorService.remove(services?.editorService.get("node"))
@@ -2754,7 +2994,7 @@
2754
2994
  case "undo":
2755
2995
  return {
2756
2996
  type: "button",
2757
- icon: icons.Back,
2997
+ icon: vue.markRaw(icons.Back),
2758
2998
  tooltip: "\u540E\u9000",
2759
2999
  disabled: () => !services?.historyService.state.canUndo,
2760
3000
  handler: () => services?.editorService.undo()
@@ -2762,7 +3002,7 @@
2762
3002
  case "redo":
2763
3003
  return {
2764
3004
  type: "button",
2765
- icon: icons.Right,
3005
+ icon: vue.markRaw(icons.Right),
2766
3006
  tooltip: "\u524D\u8FDB",
2767
3007
  disabled: () => !services?.historyService.state.canRedo,
2768
3008
  handler: () => services?.editorService.redo()
@@ -2770,28 +3010,28 @@
2770
3010
  case "zoom-in":
2771
3011
  return {
2772
3012
  type: "button",
2773
- icon: icons.ZoomIn,
3013
+ icon: vue.markRaw(icons.ZoomIn),
2774
3014
  tooltip: "\u653E\u5927",
2775
3015
  handler: zoomInHandler
2776
3016
  };
2777
3017
  case "zoom-out":
2778
3018
  return {
2779
3019
  type: "button",
2780
- icon: icons.ZoomOut,
3020
+ icon: vue.markRaw(icons.ZoomOut),
2781
3021
  tooltip: "\u7E2E\u5C0F",
2782
3022
  handler: zoomOutHandler
2783
3023
  };
2784
3024
  case "rule":
2785
3025
  return {
2786
3026
  type: "button",
2787
- icon: icons.ScaleToOriginal,
3027
+ icon: vue.markRaw(icons.ScaleToOriginal),
2788
3028
  tooltip: showRule.value ? "\u9690\u85CF\u6807\u5C3A" : "\u663E\u793A\u6807\u5C3A",
2789
3029
  handler: () => uiService?.set("showRule", !showRule.value)
2790
3030
  };
2791
3031
  case "guides":
2792
3032
  return {
2793
3033
  type: "button",
2794
- icon: icons.Grid,
3034
+ icon: vue.markRaw(icons.Grid),
2795
3035
  tooltip: showGuides.value ? "\u9690\u85CF\u53C2\u8003\u7EBF" : "\u663E\u793A\u53C2\u8003\u7EBF",
2796
3036
  handler: () => uiService?.set("showGuides", !showGuides.value)
2797
3037
  };
@@ -2812,9 +3052,16 @@
2812
3052
  }
2813
3053
  return item.value.disabled;
2814
3054
  });
3055
+ const buttonHandler = (item2, event) => {
3056
+ if (disabled.value)
3057
+ return;
3058
+ if (typeof item2.handler === "function" && services) {
3059
+ item2.handler?.(services, event);
3060
+ }
3061
+ };
2815
3062
  return {
2816
- ZoomIn: icons.ZoomIn,
2817
- ZoomOut: icons.ZoomOut,
3063
+ ZoomIn: vue.markRaw(icons.ZoomIn),
3064
+ ZoomOut: vue.markRaw(icons.ZoomOut),
2818
3065
  item,
2819
3066
  zoom,
2820
3067
  disabled,
@@ -2835,31 +3082,42 @@
2835
3082
  command.item.handler(services);
2836
3083
  }
2837
3084
  },
2838
- buttonHandler(item2) {
2839
- if (disabled.value)
3085
+ clickHandler(item2, event) {
3086
+ if (props.eventType !== "click")
3087
+ return;
3088
+ if (item2.type === "button") {
3089
+ buttonHandler(item2, event);
3090
+ }
3091
+ },
3092
+ mousedownHandler(item2, event) {
3093
+ if (props.eventType !== "mousedown")
3094
+ return;
3095
+ if (item2.type === "button") {
3096
+ buttonHandler(item2, event);
3097
+ }
3098
+ },
3099
+ mouseupHandler(item2, event) {
3100
+ if (props.eventType !== "mouseup")
2840
3101
  return;
2841
- if (typeof item2.handler === "function") {
2842
- item2.handler?.(services);
3102
+ if (item2.type === "button") {
3103
+ buttonHandler(item2, event);
2843
3104
  }
2844
3105
  }
2845
3106
  };
2846
3107
  }
2847
3108
  });
2848
- const _hoisted_1$8 = {
2849
- key: 0,
2850
- class: "menu-item"
2851
- };
2852
- const _hoisted_2$4 = {
3109
+ const _hoisted_1$6 = {
2853
3110
  key: 1,
2854
3111
  class: "menu-item-text"
2855
3112
  };
2856
- const _hoisted_3$3 = {
3113
+ const _hoisted_2$2 = {
2857
3114
  class: "menu-item-text",
2858
3115
  style: { "margin": "0 5px" }
2859
3116
  };
2860
- const _hoisted_4$3 = { class: "el-dropdown-link menubar-menu-button" };
2861
- function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
3117
+ const _hoisted_3$1 = { class: "el-dropdown-link menubar-menu-button" };
3118
+ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2862
3119
  const _component_el_divider = vue.resolveComponent("el-divider");
3120
+ const _component_tool_button = vue.resolveComponent("tool-button", true);
2863
3121
  const _component_m_icon = vue.resolveComponent("m-icon");
2864
3122
  const _component_el_button = vue.resolveComponent("el-button");
2865
3123
  const _component_el_tooltip = vue.resolveComponent("el-tooltip");
@@ -2868,44 +3126,66 @@
2868
3126
  const _component_el_dropdown_item = vue.resolveComponent("el-dropdown-item");
2869
3127
  const _component_el_dropdown_menu = vue.resolveComponent("el-dropdown-menu");
2870
3128
  const _component_el_dropdown = vue.resolveComponent("el-dropdown");
2871
- return _ctx.display ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$8, [
3129
+ return _ctx.display ? (vue.openBlock(), vue.createElementBlock("div", {
3130
+ key: 0,
3131
+ class: vue.normalizeClass(["menu-item", _ctx.item.type]),
3132
+ onClick: _cache[0] || (_cache[0] = ($event) => _ctx.clickHandler(_ctx.item, $event)),
3133
+ onMousedown: _cache[1] || (_cache[1] = ($event) => _ctx.mousedownHandler(_ctx.item, $event)),
3134
+ onMouseup: _cache[2] || (_cache[2] = ($event) => _ctx.mouseupHandler(_ctx.item, $event))
3135
+ }, [
2872
3136
  _ctx.item.type === "divider" ? (vue.openBlock(), vue.createBlock(_component_el_divider, {
2873
3137
  key: 0,
2874
- direction: "vertical"
2875
- })) : _ctx.item.type === "text" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$4, vue.toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
2876
- vue.createVNode(_component_m_icon, {
2877
- icon: _ctx.ZoomIn,
2878
- onClick: _ctx.zoomInHandler
2879
- }, null, 8, ["icon", "onClick"]),
2880
- vue.createElementVNode("span", _hoisted_3$3, vue.toDisplayString(parseInt(`${_ctx.zoom * 100}`, 10)) + "%", 1),
2881
- vue.createVNode(_component_m_icon, {
2882
- icon: _ctx.ZoomOut,
2883
- onClick: _ctx.zoomOutHandler
2884
- }, null, 8, ["icon", "onClick"])
2885
- ], 64)) : _ctx.item.type === "button" ? (vue.openBlock(), vue.createBlock(_component_el_tooltip, {
2886
- key: 3,
2887
- effect: "dark",
2888
- placement: "bottom-start",
2889
- content: _ctx.item.tooltip || _ctx.item.text
2890
- }, {
2891
- default: vue.withCtx(() => [
2892
- vue.createVNode(_component_el_button, {
2893
- size: "small",
2894
- type: "text",
2895
- disabled: _ctx.disabled,
2896
- onClick: _cache[0] || (_cache[0] = ($event) => _ctx.buttonHandler(_ctx.item))
2897
- }, {
2898
- default: vue.withCtx(() => [
2899
- vue.createVNode(_component_m_icon, {
2900
- icon: _ctx.item.icon
2901
- }, null, 8, ["icon"]),
2902
- vue.createElementVNode("span", null, vue.toDisplayString(_ctx.item.text), 1)
2903
- ]),
2904
- _: 1
2905
- }, 8, ["disabled"])
2906
- ]),
2907
- _: 1
2908
- }, 8, ["content"])) : _ctx.item.type === "dropdown" ? (vue.openBlock(), vue.createBlock(_component_el_dropdown, {
3138
+ direction: _ctx.item.direction || "vertical"
3139
+ }, null, 8, ["direction"])) : _ctx.item.type === "text" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$6, vue.toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
3140
+ vue.createVNode(_component_tool_button, {
3141
+ data: { type: "button", icon: _ctx.ZoomOut, handler: _ctx.zoomOutHandler, tooltip: "\u7F29\u5C0F" },
3142
+ "event-type": _ctx.eventType
3143
+ }, null, 8, ["data", "event-type"]),
3144
+ vue.createElementVNode("span", _hoisted_2$2, vue.toDisplayString(parseInt(`${_ctx.zoom * 100}`, 10)) + "%", 1),
3145
+ vue.createVNode(_component_tool_button, {
3146
+ data: { type: "button", icon: _ctx.ZoomIn, handler: _ctx.zoomInHandler, tooltip: "\u653E\u5927" },
3147
+ "event-type": _ctx.eventType
3148
+ }, null, 8, ["data", "event-type"])
3149
+ ], 64)) : _ctx.item.type === "button" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 3 }, [
3150
+ _ctx.item.tooltip ? (vue.openBlock(), vue.createBlock(_component_el_tooltip, {
3151
+ key: 0,
3152
+ effect: "dark",
3153
+ placement: "bottom-start",
3154
+ content: _ctx.item.tooltip
3155
+ }, {
3156
+ default: vue.withCtx(() => [
3157
+ vue.createVNode(_component_el_button, {
3158
+ size: "small",
3159
+ text: "",
3160
+ disabled: _ctx.disabled
3161
+ }, {
3162
+ default: vue.withCtx(() => [
3163
+ _ctx.item.icon ? (vue.openBlock(), vue.createBlock(_component_m_icon, {
3164
+ key: 0,
3165
+ icon: _ctx.item.icon
3166
+ }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
3167
+ vue.createElementVNode("span", null, vue.toDisplayString(_ctx.item.text), 1)
3168
+ ]),
3169
+ _: 1
3170
+ }, 8, ["disabled"])
3171
+ ]),
3172
+ _: 1
3173
+ }, 8, ["content"])) : (vue.openBlock(), vue.createBlock(_component_el_button, {
3174
+ key: 1,
3175
+ size: "small",
3176
+ text: "",
3177
+ disabled: _ctx.disabled
3178
+ }, {
3179
+ default: vue.withCtx(() => [
3180
+ _ctx.item.icon ? (vue.openBlock(), vue.createBlock(_component_m_icon, {
3181
+ key: 0,
3182
+ icon: _ctx.item.icon
3183
+ }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
3184
+ vue.createElementVNode("span", null, vue.toDisplayString(_ctx.item.text), 1)
3185
+ ]),
3186
+ _: 1
3187
+ }, 8, ["disabled"]))
3188
+ ], 64)) : _ctx.item.type === "dropdown" ? (vue.openBlock(), vue.createBlock(_component_el_dropdown, {
2909
3189
  key: 4,
2910
3190
  trigger: "click",
2911
3191
  disabled: _ctx.disabled,
@@ -2930,7 +3210,7 @@
2930
3210
  })) : vue.createCommentVNode("", true)
2931
3211
  ]),
2932
3212
  default: vue.withCtx(() => [
2933
- vue.createElementVNode("span", _hoisted_4$3, [
3213
+ vue.createElementVNode("span", _hoisted_3$1, [
2934
3214
  vue.createTextVNode(vue.toDisplayString(_ctx.item.text), 1),
2935
3215
  vue.createVNode(_component_el_icon, { class: "el-icon--right" }, {
2936
3216
  default: vue.withCtx(() => [
@@ -2942,11 +3222,11 @@
2942
3222
  ]),
2943
3223
  _: 1
2944
3224
  }, 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)
2945
- ])) : vue.createCommentVNode("", true);
3225
+ ], 34)) : vue.createCommentVNode("", true);
2946
3226
  }
2947
- var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
3227
+ var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
2948
3228
 
2949
- const _sfc_main$b = vue.defineComponent({
3229
+ const _sfc_main$d = vue.defineComponent({
2950
3230
  name: "nav-menu",
2951
3231
  components: { ToolButton },
2952
3232
  props: {
@@ -2966,7 +3246,7 @@
2966
3246
  };
2967
3247
  }
2968
3248
  });
2969
- function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
3249
+ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2970
3250
  const _component_tool_button = vue.resolveComponent("tool-button");
2971
3251
  return vue.openBlock(), vue.createElementBlock("div", {
2972
3252
  class: "m-editor-nav-menu",
@@ -2988,9 +3268,9 @@
2988
3268
  }), 128))
2989
3269
  ], 4);
2990
3270
  }
2991
- var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
3271
+ var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
2992
3272
 
2993
- const _sfc_main$a = vue.defineComponent({
3273
+ const _sfc_main$c = vue.defineComponent({
2994
3274
  name: "m-editor-props-panel",
2995
3275
  emits: ["mounted"],
2996
3276
  setup(props, { emit }) {
@@ -3005,9 +3285,9 @@
3005
3285
  curFormConfig.value = [];
3006
3286
  return;
3007
3287
  }
3008
- values.value = node.value;
3009
3288
  const type = node.value.type || (node.value.items ? "container" : "text");
3010
3289
  curFormConfig.value = await services?.propsService.getPropsConfig(type) || [];
3290
+ values.value = node.value;
3011
3291
  };
3012
3292
  vue.watchEffect(init);
3013
3293
  services?.propsService.on("props-configs-change", init);
@@ -3018,6 +3298,7 @@
3018
3298
  values,
3019
3299
  configForm,
3020
3300
  curFormConfig,
3301
+ propsPanelSize: vue.computed(() => services?.uiService.get("propsPanelSize") || "small"),
3021
3302
  async submit() {
3022
3303
  try {
3023
3304
  const values2 = await configForm.value?.submitForm();
@@ -3036,21 +3317,21 @@
3036
3317
  };
3037
3318
  }
3038
3319
  });
3039
- function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
3320
+ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
3040
3321
  const _component_m_form = vue.resolveComponent("m-form");
3041
3322
  return vue.openBlock(), vue.createBlock(_component_m_form, {
3042
- class: "m-editor-props-panel",
3323
+ class: vue.normalizeClass(`m-editor-props-panel ${_ctx.propsPanelSize}`),
3043
3324
  "popper-class": "m-editor-props-panel-popper",
3044
3325
  ref: "configForm",
3045
- size: "small",
3326
+ size: _ctx.propsPanelSize,
3046
3327
  "init-values": _ctx.values,
3047
3328
  config: _ctx.curFormConfig,
3048
3329
  onChange: _ctx.submit
3049
- }, null, 8, ["init-values", "config", "onChange"]);
3330
+ }, null, 8, ["class", "size", "init-values", "config", "onChange"]);
3050
3331
  }
3051
- var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
3332
+ var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
3052
3333
 
3053
- const _sfc_main$9 = vue.defineComponent({
3334
+ const _sfc_main$b = vue.defineComponent({
3054
3335
  name: "ui-component-panel",
3055
3336
  components: { MIcon },
3056
3337
  setup() {
@@ -3065,19 +3346,29 @@
3065
3346
  searchText,
3066
3347
  collapseValue,
3067
3348
  list,
3068
- appendComponent({ text, type, ...config }) {
3349
+ appendComponent({ text, type, data = {} }) {
3069
3350
  services?.editorService.add({
3070
3351
  name: text,
3071
3352
  type,
3072
- ...config
3353
+ ...data
3073
3354
  });
3355
+ },
3356
+ dragstartHandler({ text, type, data = {} }, e) {
3357
+ if (e.dataTransfer) {
3358
+ e.dataTransfer.effectAllowed = "move";
3359
+ e.dataTransfer.setData("data", serialize__default["default"]({
3360
+ name: text,
3361
+ type,
3362
+ ...data
3363
+ }).replace(/"(\w+)":\s/g, "$1: "));
3364
+ }
3074
3365
  }
3075
3366
  };
3076
3367
  }
3077
3368
  });
3078
- const _hoisted_1$7 = /* @__PURE__ */ vue.createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
3079
- const _hoisted_2$3 = ["onClick"];
3080
- function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3369
+ const _hoisted_1$5 = /* @__PURE__ */ vue.createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
3370
+ const _hoisted_2$1 = ["onClick", "onDragstart"];
3371
+ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
3081
3372
  const _component_el_input = vue.resolveComponent("el-input");
3082
3373
  const _component_m_icon = vue.resolveComponent("m-icon");
3083
3374
  const _component_el_tooltip = vue.resolveComponent("el-tooltip");
@@ -3107,15 +3398,17 @@
3107
3398
  name: index
3108
3399
  }, {
3109
3400
  title: vue.withCtx(() => [
3110
- _hoisted_1$7,
3401
+ _hoisted_1$5,
3111
3402
  vue.createTextVNode(vue.toDisplayString(group.title), 1)
3112
3403
  ]),
3113
3404
  default: vue.withCtx(() => [
3114
3405
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(group.items, (item) => {
3115
3406
  return vue.openBlock(), vue.createElementBlock("div", {
3116
3407
  class: "component-item",
3408
+ draggable: "true",
3117
3409
  key: item.type,
3118
- onClick: ($event) => _ctx.appendComponent(item)
3410
+ onClick: ($event) => _ctx.appendComponent(item),
3411
+ onDragstart: ($event) => _ctx.dragstartHandler(item, $event)
3119
3412
  }, [
3120
3413
  vue.createVNode(_component_m_icon, {
3121
3414
  icon: item.icon
@@ -3130,7 +3423,7 @@
3130
3423
  ]),
3131
3424
  _: 2
3132
3425
  }, 1032, ["content"])
3133
- ], 8, _hoisted_2$3);
3426
+ ], 40, _hoisted_2$1);
3134
3427
  }), 128))
3135
3428
  ]),
3136
3429
  _: 2
@@ -3144,133 +3437,211 @@
3144
3437
  _: 1
3145
3438
  });
3146
3439
  }
3147
- var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
3440
+ var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
3148
3441
 
3149
- const _sfc_main$8 = vue.defineComponent({
3150
- name: "magic-editor-content-menu",
3442
+ const _sfc_main$a = vue.defineComponent({
3443
+ components: { ToolButton },
3151
3444
  props: {
3152
- componentGroupList: {
3445
+ menuData: {
3153
3446
  type: Array,
3154
3447
  default: () => []
3155
3448
  }
3156
3449
  },
3157
- setup(props) {
3158
- const services = vue.inject("services");
3159
- const subVisible = vue.ref(false);
3160
- const node = vue.computed(() => services?.editorService.get("node"));
3161
- return {
3162
- subVisible,
3163
- node,
3164
- menu: vue.computed(() => ({
3165
- app: [
3166
- {
3167
- type: "page",
3168
- text: "\u9875\u9762"
3169
- }
3170
- ],
3171
- component: props.componentGroupList
3172
- })),
3173
- append(config) {
3174
- services?.editorService.add({
3175
- name: config.text,
3176
- type: config.type
3450
+ setup() {
3451
+ const menu = vue.ref();
3452
+ const subMenu = vue.ref();
3453
+ const visible = vue.ref(false);
3454
+ const subMenuData = vue.ref([]);
3455
+ const menuStyle = vue.ref({
3456
+ left: "0",
3457
+ top: "0"
3458
+ });
3459
+ const hide = () => {
3460
+ visible.value = false;
3461
+ };
3462
+ vue.onMounted(() => {
3463
+ globalThis.addEventListener("mousedown", (e) => {
3464
+ if (!visible.value || e.target && menu.value?.contains(e.target)) {
3465
+ return;
3466
+ }
3467
+ hide();
3468
+ }, true);
3469
+ });
3470
+ return {
3471
+ menu,
3472
+ subMenu,
3473
+ visible,
3474
+ menuStyle,
3475
+ subMenuData,
3476
+ hide,
3477
+ show(e) {
3478
+ visible.value = true;
3479
+ vue.nextTick(() => {
3480
+ const menuHeight = menu.value?.clientHeight || 0;
3481
+ let top = e.clientY;
3482
+ if (menuHeight + e.clientY > document.body.clientHeight) {
3483
+ top = document.body.clientHeight - menuHeight;
3484
+ }
3485
+ menuStyle.value = {
3486
+ top: `${top}px`,
3487
+ left: `${e.clientX}px`
3488
+ };
3177
3489
  });
3178
3490
  },
3179
- remove() {
3180
- node.value && services?.editorService.remove(node.value);
3181
- },
3182
- copy(node2) {
3183
- services?.editorService.copy(node2);
3184
- },
3185
- setSubVisiable(v) {
3186
- subVisible.value = v;
3491
+ showSubMenu(item) {
3492
+ const menuItem = item;
3493
+ if (typeof item !== "object" || !menuItem.items?.length) {
3494
+ return;
3495
+ }
3496
+ subMenuData.value = menuItem.items;
3497
+ if (menu.value) {
3498
+ subMenu.value.show({
3499
+ clientX: menu.value.offsetLeft + menu.value.clientWidth,
3500
+ clientY: menu.value.offsetTop
3501
+ });
3502
+ }
3187
3503
  }
3188
3504
  };
3189
3505
  }
3190
3506
  });
3191
- const _hoisted_1$6 = {
3192
- key: 0,
3193
- class: "magic-editor-content-menu"
3194
- };
3195
- const _hoisted_2$2 = ["onClick"];
3196
- const _hoisted_3$2 = ["onClick"];
3197
- const _hoisted_4$2 = /* @__PURE__ */ vue.createElementVNode("div", { class: "separation" }, null, -1);
3198
- function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3199
- const _component_el_scrollbar = vue.resolveComponent("el-scrollbar");
3200
- return _ctx.node ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$6, [
3201
- _ctx.node.items ? (vue.openBlock(), vue.createElementBlock("div", {
3202
- key: 0,
3203
- class: "magic-editor-content-menu-item",
3204
- onMouseenter: _cache[0] || (_cache[0] = ($event) => _ctx.setSubVisiable(true)),
3205
- onMouseleave: _cache[1] || (_cache[1] = ($event) => _ctx.setSubVisiable(false))
3206
- }, " \u65B0\u589E ", 32)) : vue.createCommentVNode("", true),
3207
- _ctx.node.type !== "app" ? (vue.openBlock(), vue.createElementBlock("div", {
3208
- key: 1,
3209
- class: "magic-editor-content-menu-item",
3210
- onClick: _cache[2] || (_cache[2] = () => _ctx.copy(_ctx.node))
3211
- }, "\u590D\u5236")) : vue.createCommentVNode("", true),
3212
- _ctx.node.type !== "app" && _ctx.node.type !== "page" ? (vue.openBlock(), vue.createElementBlock("div", {
3213
- key: 2,
3214
- class: "magic-editor-content-menu-item",
3215
- onClick: _cache[3] || (_cache[3] = () => _ctx.remove())
3216
- }, " \u5220\u9664 ")) : vue.createCommentVNode("", true),
3217
- vue.withDirectives(vue.createElementVNode("div", {
3218
- class: "subMenu",
3219
- onMouseenter: _cache[5] || (_cache[5] = ($event) => _ctx.setSubVisiable(true)),
3220
- onMouseleave: _cache[6] || (_cache[6] = ($event) => _ctx.setSubVisiable(false))
3221
- }, [
3222
- vue.createVNode(_component_el_scrollbar, null, {
3223
- default: vue.withCtx(() => [
3224
- _ctx.node.type === "tabs" ? (vue.openBlock(), vue.createElementBlock("div", {
3225
- key: 0,
3226
- class: "magic-editor-content-menu-item",
3227
- onClick: _cache[4] || (_cache[4] = () => _ctx.append({
3228
- type: "tab-pane"
3229
- }))
3230
- }, " \u6807\u7B7E ")) : _ctx.node.type === "app" ? (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 1 }, vue.renderList(_ctx.menu.app, (item) => {
3231
- return vue.openBlock(), vue.createElementBlock("div", {
3232
- class: "magic-editor-content-menu-item",
3233
- key: item.type,
3234
- onClick: () => _ctx.append(item)
3235
- }, vue.toDisplayString(item.text), 9, _hoisted_2$2);
3236
- }), 128)) : _ctx.node.items ? (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 2 }, vue.renderList(_ctx.menu.component, (list) => {
3237
- return vue.openBlock(), vue.createElementBlock("div", {
3238
- key: list.title
3239
- }, [
3240
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(list.items, (item) => {
3241
- return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
3242
- item ? (vue.openBlock(), vue.createElementBlock("div", {
3243
- class: "magic-editor-content-menu-item",
3244
- key: item.type,
3245
- onClick: () => _ctx.append(item)
3246
- }, vue.toDisplayString(item.text), 9, _hoisted_3$2)) : vue.createCommentVNode("", true)
3247
- ], 64);
3248
- }), 256)),
3249
- _hoisted_4$2
3250
- ]);
3251
- }), 128)) : vue.createCommentVNode("", true)
3252
- ]),
3253
- _: 1
3254
- })
3255
- ], 544), [
3256
- [vue.vShow, _ctx.subVisible]
3257
- ])
3258
- ])) : vue.createCommentVNode("", true);
3507
+ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
3508
+ const _component_tool_button = vue.resolveComponent("tool-button");
3509
+ const _component_content_menu = vue.resolveComponent("content-menu", true);
3510
+ return _ctx.menuData.length ? vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", {
3511
+ key: 0,
3512
+ class: "magic-editor-content-menu",
3513
+ ref: "menu",
3514
+ style: vue.normalizeStyle(_ctx.menuStyle)
3515
+ }, [
3516
+ vue.createElementVNode("div", null, [
3517
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.menuData, (item, index) => {
3518
+ return vue.openBlock(), vue.createBlock(_component_tool_button, {
3519
+ "event-type": "mouseup",
3520
+ data: item,
3521
+ key: index,
3522
+ onMouseup: _ctx.hide,
3523
+ onMouseenter: ($event) => _ctx.showSubMenu(item)
3524
+ }, null, 8, ["data", "onMouseup", "onMouseenter"]);
3525
+ }), 128))
3526
+ ]),
3527
+ (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
3528
+ vue.createVNode(_component_content_menu, {
3529
+ class: "sub-menu",
3530
+ ref: "subMenu",
3531
+ "menu-data": _ctx.subMenuData
3532
+ }, null, 8, ["menu-data"])
3533
+ ]))
3534
+ ], 4)), [
3535
+ [vue.vShow, _ctx.visible]
3536
+ ]) : vue.createCommentVNode("", true);
3537
+ }
3538
+ var ContentMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
3539
+
3540
+ const _sfc_main$9 = vue.defineComponent({
3541
+ components: { ContentMenu },
3542
+ setup() {
3543
+ const services = vue.inject("services");
3544
+ const menu = vue.ref();
3545
+ const node = vue.computed(() => services?.editorService.get("node"));
3546
+ const isRoot = vue.computed(() => node.value?.type === schema.NodeType.ROOT);
3547
+ const isPage = vue.computed(() => node.value?.type === schema.NodeType.PAGE);
3548
+ const componentList = vue.computed(() => services?.componentListService.getList() || []);
3549
+ const createMenuItems = (group) => group.items.map((component) => ({
3550
+ text: component.text,
3551
+ type: "button",
3552
+ icon: component.icon,
3553
+ handler: () => {
3554
+ services?.editorService.add({
3555
+ name: component.text,
3556
+ type: component.type,
3557
+ ...component.data || {}
3558
+ });
3559
+ }
3560
+ }));
3561
+ const getSubMenuData = vue.computed(() => {
3562
+ if (node.value?.type === "tabs") {
3563
+ return [
3564
+ {
3565
+ text: "\u6807\u7B7E\u9875",
3566
+ type: "button",
3567
+ icon: icons.Files,
3568
+ handler: () => {
3569
+ services?.editorService.add({
3570
+ type: "tab-pane"
3571
+ });
3572
+ }
3573
+ }
3574
+ ];
3575
+ }
3576
+ if (node.value?.items) {
3577
+ return componentList.value.reduce((subMenuData, group, index) => subMenuData.concat(createMenuItems(group), index < componentList.value.length - 1 ? [
3578
+ {
3579
+ type: "divider",
3580
+ direction: "horizontal"
3581
+ }
3582
+ ] : []), []) || [];
3583
+ }
3584
+ return [];
3585
+ });
3586
+ return {
3587
+ menu,
3588
+ menuData: vue.computed(() => [
3589
+ {
3590
+ type: "button",
3591
+ text: "\u65B0\u589E",
3592
+ icon: vue.markRaw(icons.Plus),
3593
+ display: () => node.value?.items,
3594
+ items: getSubMenuData.value
3595
+ },
3596
+ {
3597
+ type: "button",
3598
+ text: "\u590D\u5236",
3599
+ icon: vue.markRaw(icons.DocumentCopy),
3600
+ display: () => !isRoot.value,
3601
+ handler: () => {
3602
+ node.value && services?.editorService.copy(node.value);
3603
+ }
3604
+ },
3605
+ {
3606
+ type: "button",
3607
+ text: "\u5220\u9664",
3608
+ icon: vue.markRaw(icons.Delete),
3609
+ display: () => !isRoot.value && !isPage.value,
3610
+ handler: () => {
3611
+ node.value && services?.editorService.remove(node.value);
3612
+ }
3613
+ }
3614
+ ]),
3615
+ show(e) {
3616
+ menu.value?.show(e);
3617
+ }
3618
+ };
3619
+ }
3620
+ });
3621
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3622
+ const _component_content_menu = vue.resolveComponent("content-menu");
3623
+ return vue.openBlock(), vue.createBlock(_component_content_menu, {
3624
+ "menu-data": _ctx.menuData,
3625
+ ref: "menu",
3626
+ style: { "overflow": "initial" }
3627
+ }, null, 8, ["menu-data"]);
3259
3628
  }
3260
- var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3629
+ var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
3261
3630
 
3262
3631
  const throttleTime = 150;
3263
- const select = (data, editorService) => {
3632
+ const select = async (data, editorService) => {
3264
3633
  if (!data.id) {
3265
3634
  throw new Error("\u6CA1\u6709id");
3266
3635
  }
3267
- editorService?.select(data);
3636
+ await editorService?.select(data);
3637
+ editorService?.get("stage")?.select(data.id);
3268
3638
  };
3269
3639
  const highlight = (data, editorService) => {
3270
3640
  if (!data?.id) {
3271
3641
  throw new Error("\u6CA1\u6709id");
3272
3642
  }
3273
3643
  editorService?.highlight(data);
3644
+ editorService?.get("stage")?.highlight(data.id);
3274
3645
  };
3275
3646
  const useDrop = (tree, editorService) => ({
3276
3647
  allowDrop: (draggingNode, dropNode, type) => {
@@ -3325,7 +3696,8 @@
3325
3696
  resolve([]);
3326
3697
  },
3327
3698
  highlightNode,
3328
- clickNode: node
3699
+ clickNode: node,
3700
+ expandedKeys: vue.computed(() => node.value ? [node.value.id] : [])
3329
3701
  };
3330
3702
  };
3331
3703
  const useFilter = (tree) => ({
@@ -3337,67 +3709,46 @@
3337
3709
  let name = "";
3338
3710
  if (data.name) {
3339
3711
  name = data.name;
3340
- } else if (data.type) {
3341
- name = data.type;
3342
3712
  } else if (data.items) {
3343
3713
  name = "container";
3344
3714
  }
3345
- return name.indexOf(value) !== -1;
3715
+ return `${data.id}${name}${data.type}`.indexOf(value) !== -1;
3346
3716
  },
3347
3717
  filterTextChangeHandler(val) {
3348
3718
  tree.value?.filter(val);
3349
3719
  }
3350
3720
  });
3351
- const useContentMenu = (editorService) => {
3352
- const menuStyle = vue.ref({
3353
- position: "absolute",
3354
- left: "0",
3355
- top: "0",
3356
- display: "none"
3357
- });
3358
- vue.onMounted(() => {
3359
- document.addEventListener("click", () => {
3360
- menuStyle.value.display = "none";
3361
- }, true);
3362
- });
3363
- return {
3364
- menuStyle,
3365
- contextmenu(event, data) {
3366
- const bodyHeight = globalThis.document.body.clientHeight;
3367
- const left = `${event.clientX + 20}px`;
3368
- let top = `${event.clientY - 10}px`;
3369
- if (event.clientY + 300 > bodyHeight) {
3370
- top = `${bodyHeight - 300}px`;
3371
- }
3372
- menuStyle.value.left = left;
3373
- menuStyle.value.top = top;
3374
- menuStyle.value.display = "";
3375
- select(data, editorService);
3376
- }
3377
- };
3378
- };
3379
- const _sfc_main$7 = vue.defineComponent({
3721
+ const _sfc_main$8 = vue.defineComponent({
3380
3722
  name: "magic-editor-layer-panel",
3381
3723
  components: { LayerMenu },
3382
3724
  setup() {
3383
3725
  const services = vue.inject("services");
3384
3726
  const tree = vue.ref();
3727
+ const menu = vue.ref();
3385
3728
  const clicked = vue.ref(false);
3386
3729
  const editorService = services?.editorService;
3387
3730
  const highlightHandler = lodashEs.throttle((data) => {
3388
3731
  highlight(data, editorService);
3389
3732
  }, throttleTime);
3390
- const toogleClickFlag = () => {
3733
+ const toggleClickFlag = () => {
3391
3734
  clicked.value = !clicked.value;
3392
3735
  };
3393
3736
  const statusData = useStatus(tree, editorService);
3394
3737
  const canHighlight = vue.computed(() => statusData.highlightNode.value?.id !== statusData.clickNode.value?.id && !clicked.value);
3738
+ editorService?.on("remove", () => {
3739
+ setTimeout(() => {
3740
+ tree.value?.getNode(editorService.get("node").id)?.updateChildren();
3741
+ }, 0);
3742
+ });
3395
3743
  return {
3396
3744
  tree,
3745
+ menu,
3397
3746
  ...statusData,
3398
3747
  ...useDrop(tree, editorService),
3399
3748
  ...useFilter(tree),
3400
- ...useContentMenu(editorService),
3749
+ highlightHandler,
3750
+ toggleClickFlag,
3751
+ canHighlight,
3401
3752
  clickHandler(data) {
3402
3753
  if (services?.uiService.get("uiSelectMode")) {
3403
3754
  document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
@@ -3406,14 +3757,16 @@
3406
3757
  tree.value?.setCurrentKey(data.id);
3407
3758
  select(data, editorService);
3408
3759
  },
3409
- highlightHandler,
3410
- toogleClickFlag,
3411
- canHighlight
3760
+ async contextmenu(event, data) {
3761
+ event.preventDefault();
3762
+ await select(data, editorService);
3763
+ menu.value?.show(event);
3764
+ }
3412
3765
  };
3413
3766
  }
3414
3767
  });
3415
- const _hoisted_1$5 = ["id", "onMouseenter"];
3416
- function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3768
+ const _hoisted_1$4 = ["id", "onMouseenter"];
3769
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3417
3770
  const _component_el_input = vue.resolveComponent("el-input");
3418
3771
  const _component_el_tree = vue.resolveComponent("el-tree");
3419
3772
  const _component_layer_menu = vue.resolveComponent("layer-menu");
@@ -3434,6 +3787,7 @@
3434
3787
  ref: "tree",
3435
3788
  "node-key": "id",
3436
3789
  draggable: "",
3790
+ "default-expanded-keys": _ctx.expandedKeys,
3437
3791
  load: _ctx.loadItems,
3438
3792
  data: _ctx.values,
3439
3793
  "expand-on-click-node": false,
@@ -3452,8 +3806,8 @@
3452
3806
  vue.createElementVNode("div", {
3453
3807
  id: data.id,
3454
3808
  class: vue.normalizeClass(["cus-tree-node", { "cus-tree-node-hover": _ctx.canHighlight && data.id === _ctx.highlightNode?.id }]),
3455
- onMousedown: _cache[1] || (_cache[1] = (...args) => _ctx.toogleClickFlag && _ctx.toogleClickFlag(...args)),
3456
- onMouseup: _cache[2] || (_cache[2] = (...args) => _ctx.toogleClickFlag && _ctx.toogleClickFlag(...args)),
3809
+ onMousedown: _cache[1] || (_cache[1] = (...args) => _ctx.toggleClickFlag && _ctx.toggleClickFlag(...args)),
3810
+ onMouseup: _cache[2] || (_cache[2] = (...args) => _ctx.toggleClickFlag && _ctx.toggleClickFlag(...args)),
3457
3811
  onMouseenter: ($event) => _ctx.highlightHandler(data)
3458
3812
  }, [
3459
3813
  vue.renderSlot(_ctx.$slots, "layer-node-content", {
@@ -3462,42 +3816,33 @@
3462
3816
  }, () => [
3463
3817
  vue.createElementVNode("span", null, vue.toDisplayString(`${data.name} (${data.id})`), 1)
3464
3818
  ])
3465
- ], 42, _hoisted_1$5)
3819
+ ], 42, _hoisted_1$4)
3466
3820
  ]),
3467
3821
  _: 3
3468
- }, 8, ["load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd"])) : vue.createCommentVNode("", true),
3822
+ }, 8, ["default-expanded-keys", "load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd"])) : vue.createCommentVNode("", true),
3469
3823
  (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
3470
- vue.createVNode(_component_layer_menu, {
3471
- style: vue.normalizeStyle(_ctx.menuStyle)
3472
- }, null, 8, ["style"])
3824
+ vue.createVNode(_component_layer_menu, { ref: "menu" }, null, 512)
3473
3825
  ]))
3474
3826
  ]),
3475
3827
  _: 3
3476
3828
  });
3477
3829
  }
3478
- var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
3830
+ var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3479
3831
 
3480
- const _sfc_main$6 = vue.defineComponent({
3481
- name: "m-sidebar",
3832
+ const _sfc_main$7 = vue.defineComponent({
3482
3833
  components: { MIcon },
3483
3834
  props: {
3484
3835
  data: {
3485
- type: Object,
3486
- default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
3836
+ type: Object
3487
3837
  }
3488
3838
  },
3489
3839
  setup(props) {
3490
- const activeTabName = vue.ref(props.data?.status);
3491
- vue.watch(() => props.data?.status, (status) => {
3492
- activeTabName.value = status || "0";
3493
- });
3494
3840
  return {
3495
- activeTabName,
3496
- items: vue.computed(() => props.data?.items.map((item) => {
3497
- if (typeof item !== "string") {
3498
- return item;
3841
+ config: vue.computed(() => {
3842
+ if (typeof props.data !== "string") {
3843
+ return props.data;
3499
3844
  }
3500
- switch (item) {
3845
+ switch (props.data) {
3501
3846
  case "component-list":
3502
3847
  return {
3503
3848
  type: "component",
@@ -3515,21 +3860,75 @@
3515
3860
  slots: {}
3516
3861
  };
3517
3862
  default:
3518
- return {};
3863
+ return void 0;
3519
3864
  }
3520
- }))
3865
+ })
3521
3866
  };
3522
3867
  }
3523
3868
  });
3524
- const _hoisted_1$4 = {
3869
+ const _hoisted_1$3 = {
3525
3870
  key: 1,
3526
3871
  class: "magic-editor-tab-panel-title"
3527
3872
  };
3528
- function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3873
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3529
3874
  const _component_m_icon = vue.resolveComponent("m-icon");
3530
3875
  const _component_el_tab_pane = vue.resolveComponent("el-tab-pane");
3876
+ return _ctx.config ? (vue.openBlock(), vue.createBlock(_component_el_tab_pane, {
3877
+ key: 0,
3878
+ name: _ctx.config.text
3879
+ }, {
3880
+ label: vue.withCtx(() => [
3881
+ (vue.openBlock(), vue.createElementBlock("div", {
3882
+ key: _ctx.config.text
3883
+ }, [
3884
+ _ctx.config.icon ? (vue.openBlock(), vue.createBlock(_component_m_icon, {
3885
+ key: 0,
3886
+ icon: _ctx.config.icon
3887
+ }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
3888
+ _ctx.config.text ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$3, vue.toDisplayString(_ctx.config.text), 1)) : vue.createCommentVNode("", true)
3889
+ ]))
3890
+ ]),
3891
+ default: vue.withCtx(() => [
3892
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.config.component), vue.mergeProps(_ctx.config.props || {}, vue.toHandlers(_ctx.config?.listeners || {})), vue.createSlots({ _: 2 }, [
3893
+ _ctx.config.slots?.layerNodeContent ? {
3894
+ name: "layer-node-content",
3895
+ fn: vue.withCtx(({ data, node }) => [
3896
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.config.slots?.layerNodeContent), {
3897
+ data,
3898
+ node
3899
+ }, null, 8, ["data", "node"]))
3900
+ ])
3901
+ } : void 0
3902
+ ]), 1040))
3903
+ ]),
3904
+ _: 1
3905
+ }, 8, ["name"])) : vue.createCommentVNode("", true);
3906
+ }
3907
+ var TabPane = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
3908
+
3909
+ const _sfc_main$6 = vue.defineComponent({
3910
+ components: { TabPane },
3911
+ name: "m-sidebar",
3912
+ props: {
3913
+ data: {
3914
+ type: Object,
3915
+ default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
3916
+ }
3917
+ },
3918
+ setup(props) {
3919
+ const activeTabName = vue.ref(props.data?.status);
3920
+ vue.watch(() => props.data?.status, (status) => {
3921
+ activeTabName.value = status || "0";
3922
+ });
3923
+ return {
3924
+ activeTabName
3925
+ };
3926
+ }
3927
+ });
3928
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3929
+ const _component_tab_pane = vue.resolveComponent("tab-pane");
3531
3930
  const _component_el_tabs = vue.resolveComponent("el-tabs");
3532
- return _ctx.data.type === "tabs" ? (vue.openBlock(), vue.createBlock(_component_el_tabs, {
3931
+ return _ctx.data.type === "tabs" && _ctx.data.items.length ? (vue.openBlock(), vue.createBlock(_component_el_tabs, {
3533
3932
  key: 0,
3534
3933
  class: "m-editor-sidebar",
3535
3934
  modelValue: _ctx.activeTabName,
@@ -3538,35 +3937,11 @@
3538
3937
  "tab-position": "left"
3539
3938
  }, {
3540
3939
  default: vue.withCtx(() => [
3541
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.items, (item) => {
3542
- return vue.openBlock(), vue.createBlock(_component_el_tab_pane, {
3543
- key: item.text,
3544
- name: item.text
3545
- }, {
3546
- label: vue.withCtx(() => [
3547
- vue.createElementVNode("span", null, [
3548
- item.icon ? (vue.openBlock(), vue.createBlock(_component_m_icon, {
3549
- key: 0,
3550
- icon: item.icon
3551
- }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
3552
- item.text ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$4, vue.toDisplayString(item.text), 1)) : vue.createCommentVNode("", true)
3553
- ])
3554
- ]),
3555
- default: vue.withCtx(() => [
3556
- (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(item.component), vue.mergeProps(item.props || {}, vue.toHandlers(item.listeners || {})), vue.createSlots({ _: 2 }, [
3557
- item.slots?.layerNodeContent ? {
3558
- name: "layer-node-content",
3559
- fn: vue.withCtx(({ data, node }) => [
3560
- (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(item.slots.layerNodeContent), {
3561
- data,
3562
- node
3563
- }, null, 8, ["data", "node"]))
3564
- ])
3565
- } : void 0
3566
- ]), 1040))
3567
- ]),
3568
- _: 2
3569
- }, 1032, ["name"]);
3940
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.data.items, (item, index) => {
3941
+ return vue.openBlock(), vue.createBlock(_component_tab_pane, {
3942
+ key: index,
3943
+ data: item
3944
+ }, null, 8, ["data"]);
3570
3945
  }), 128))
3571
3946
  ]),
3572
3947
  _: 1
@@ -3574,13 +3949,81 @@
3574
3949
  }
3575
3950
  var Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$6]]);
3576
3951
 
3952
+ const useScroll = (root) => {
3953
+ const pageBar = vue.ref();
3954
+ const itemsContainer = vue.ref();
3955
+ const pageBarWidth = vue.ref(0);
3956
+ const canScroll = vue.ref(false);
3957
+ const itemsContainerWidth = vue.computed(() => pageBarWidth.value - 105);
3958
+ let translateLeft = 0;
3959
+ const resizeObserver = new ResizeObserver((entries) => {
3960
+ for (const { contentRect } of entries) {
3961
+ const { width } = contentRect;
3962
+ pageBarWidth.value = width || 0;
3963
+ setCanScroll();
3964
+ }
3965
+ });
3966
+ const setCanScroll = () => {
3967
+ if (itemsContainer.value) {
3968
+ canScroll.value = itemsContainer.value.scrollWidth > pageBarWidth.value - 105;
3969
+ }
3970
+ };
3971
+ const scroll = (type) => {
3972
+ if (!itemsContainer.value)
3973
+ return;
3974
+ const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
3975
+ if (type === "left") {
3976
+ translateLeft += 100;
3977
+ if (translateLeft > 0) {
3978
+ translateLeft = 0;
3979
+ }
3980
+ } else if (type === "right") {
3981
+ translateLeft -= 100;
3982
+ if (-translateLeft > maxScrollLeft) {
3983
+ translateLeft = -maxScrollLeft;
3984
+ }
3985
+ } else if (type === "start") {
3986
+ translateLeft = 0;
3987
+ } else if (type === "end") {
3988
+ translateLeft = -maxScrollLeft;
3989
+ }
3990
+ itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
3991
+ };
3992
+ vue.onMounted(() => {
3993
+ pageBar.value && resizeObserver.observe(pageBar.value);
3994
+ });
3995
+ vue.onUnmounted(() => {
3996
+ resizeObserver.disconnect();
3997
+ });
3998
+ vue.watch(() => root.value?.items.length, (length = 0, preLength = 0) => {
3999
+ setTimeout(() => {
4000
+ setCanScroll();
4001
+ if (length < preLength) {
4002
+ scroll("start");
4003
+ } else {
4004
+ scroll("end");
4005
+ }
4006
+ });
4007
+ });
4008
+ return {
4009
+ pageBar,
4010
+ itemsContainer,
4011
+ canScroll,
4012
+ itemsContainerWidth,
4013
+ scroll
4014
+ };
4015
+ };
3577
4016
  const _sfc_main$5 = vue.defineComponent({
3578
- components: { CaretBottom: icons.CaretBottom, Plus: icons.Plus },
4017
+ components: { ArrowLeftBold: icons.ArrowLeftBold, ArrowRightBold: icons.ArrowRightBold, CaretBottom: icons.CaretBottom, Plus: icons.Plus, ToolButton },
3579
4018
  setup() {
3580
4019
  const services = vue.inject("services");
3581
4020
  const editorService = services?.editorService;
4021
+ const root = vue.computed(() => editorService?.get("root"));
3582
4022
  return {
3583
- root: vue.computed(() => editorService?.get("root")),
4023
+ Delete: vue.markRaw(icons.Delete),
4024
+ DocumentCopy: vue.markRaw(icons.DocumentCopy),
4025
+ ...useScroll(root),
4026
+ root,
3584
4027
  page: vue.computed(() => editorService?.get("page")),
3585
4028
  switchPage(page) {
3586
4029
  editorService?.select(page);
@@ -3607,112 +4050,228 @@
3607
4050
  };
3608
4051
  }
3609
4052
  });
3610
- const _hoisted_1$3 = { class: "m-editor-page-bar" };
3611
- const _hoisted_2$1 = ["onClick"];
3612
- const _hoisted_3$1 = { class: "m-editor-page-bar-title" };
3613
- const _hoisted_4$1 = ["onClick"];
3614
- const _hoisted_5 = ["onClick"];
4053
+ const _hoisted_1$2 = {
4054
+ class: "m-editor-page-bar",
4055
+ ref: "pageBar"
4056
+ };
4057
+ const _hoisted_2 = ["onClick"];
4058
+ const _hoisted_3 = { class: "m-editor-page-bar-title" };
3615
4059
  function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3616
4060
  const _component_plus = vue.resolveComponent("plus");
3617
4061
  const _component_el_icon = vue.resolveComponent("el-icon");
4062
+ const _component_arrow_left_bold = vue.resolveComponent("arrow-left-bold");
3618
4063
  const _component_el_tooltip = vue.resolveComponent("el-tooltip");
4064
+ const _component_tool_button = vue.resolveComponent("tool-button");
3619
4065
  const _component_caret_bottom = vue.resolveComponent("caret-bottom");
3620
4066
  const _component_el_popover = vue.resolveComponent("el-popover");
3621
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$3, [
4067
+ const _component_arrow_right_bold = vue.resolveComponent("arrow-right-bold");
4068
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
3622
4069
  vue.createElementVNode("div", {
3623
- class: "m-editor-page-bar-item",
4070
+ id: "m-editor-page-bar-add-icon",
4071
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3624
4072
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.addPage && _ctx.addPage(...args))
3625
4073
  }, [
3626
- vue.createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-add-icon" }, {
4074
+ vue.createVNode(_component_el_icon, null, {
3627
4075
  default: vue.withCtx(() => [
3628
4076
  vue.createVNode(_component_plus)
3629
4077
  ]),
3630
4078
  _: 1
3631
4079
  })
3632
4080
  ]),
3633
- _ctx.root ? (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 0 }, vue.renderList(_ctx.root.items, (item) => {
3634
- return vue.openBlock(), vue.createElementBlock("div", {
3635
- key: item.key,
3636
- class: vue.normalizeClass(["m-editor-page-bar-item", { active: _ctx.page?.id === item.id }]),
3637
- onClick: ($event) => _ctx.switchPage(item)
3638
- }, [
3639
- vue.createElementVNode("div", _hoisted_3$1, [
3640
- vue.renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
3641
- vue.createVNode(_component_el_tooltip, {
3642
- effect: "dark",
3643
- placement: "top-start",
3644
- content: item.name
3645
- }, {
3646
- default: vue.withCtx(() => [
3647
- vue.createElementVNode("span", null, vue.toDisplayString(item.name), 1)
3648
- ]),
3649
- _: 2
3650
- }, 1032, ["content"])
3651
- ])
4081
+ _ctx.canScroll ? (vue.openBlock(), vue.createElementBlock("div", {
4082
+ key: 0,
4083
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4084
+ onClick: _cache[1] || (_cache[1] = ($event) => _ctx.scroll("left"))
4085
+ }, [
4086
+ vue.createVNode(_component_el_icon, null, {
4087
+ default: vue.withCtx(() => [
4088
+ vue.createVNode(_component_arrow_left_bold)
3652
4089
  ]),
3653
- vue.createVNode(_component_el_popover, {
3654
- placement: "top",
3655
- width: 160,
3656
- trigger: "hover"
3657
- }, {
3658
- reference: vue.withCtx(() => [
3659
- vue.createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-icon" }, {
3660
- default: vue.withCtx(() => [
3661
- vue.createVNode(_component_caret_bottom)
3662
- ]),
3663
- _: 1
3664
- })
3665
- ]),
3666
- default: vue.withCtx(() => [
3667
- vue.createElementVNode("div", null, [
3668
- vue.renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3669
- vue.createElementVNode("div", {
3670
- class: "magic-editor-content-menu-item",
3671
- onClick: () => _ctx.copy(item)
3672
- }, "\u590D\u5236", 8, _hoisted_4$1),
3673
- vue.createElementVNode("div", {
3674
- class: "magic-editor-content-menu-item",
3675
- onClick: () => _ctx.remove(item)
3676
- }, "\u5220\u9664", 8, _hoisted_5)
3677
- ])
4090
+ _: 1
4091
+ })
4092
+ ])) : vue.createCommentVNode("", true),
4093
+ _ctx.root ? (vue.openBlock(), vue.createElementBlock("div", {
4094
+ key: 1,
4095
+ class: "m-editor-page-bar-items",
4096
+ ref: "itemsContainer",
4097
+ style: vue.normalizeStyle(`width: ${_ctx.itemsContainerWidth}px`)
4098
+ }, [
4099
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.root.items, (item) => {
4100
+ return vue.openBlock(), vue.createElementBlock("div", {
4101
+ key: item.key,
4102
+ class: vue.normalizeClass(["m-editor-page-bar-item", { active: _ctx.page?.id === item.id }]),
4103
+ onClick: ($event) => _ctx.switchPage(item)
4104
+ }, [
4105
+ vue.createElementVNode("div", _hoisted_3, [
4106
+ vue.renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
4107
+ vue.createVNode(_component_el_tooltip, {
4108
+ effect: "dark",
4109
+ placement: "top-start",
4110
+ content: item.name
4111
+ }, {
4112
+ default: vue.withCtx(() => [
4113
+ vue.createElementVNode("span", null, vue.toDisplayString(item.name), 1)
4114
+ ]),
4115
+ _: 2
4116
+ }, 1032, ["content"])
3678
4117
  ])
3679
4118
  ]),
3680
- _: 2
3681
- }, 1024)
3682
- ], 10, _hoisted_2$1);
3683
- }), 128)) : vue.createCommentVNode("", true)
3684
- ]);
4119
+ vue.createVNode(_component_el_popover, {
4120
+ "popper-class": "page-bar-popover",
4121
+ placement: "top",
4122
+ width: 160,
4123
+ trigger: "hover"
4124
+ }, {
4125
+ reference: vue.withCtx(() => [
4126
+ vue.createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-icon" }, {
4127
+ default: vue.withCtx(() => [
4128
+ vue.createVNode(_component_caret_bottom)
4129
+ ]),
4130
+ _: 1
4131
+ })
4132
+ ]),
4133
+ default: vue.withCtx(() => [
4134
+ vue.createElementVNode("div", null, [
4135
+ vue.renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
4136
+ vue.createVNode(_component_tool_button, {
4137
+ data: {
4138
+ type: "button",
4139
+ text: "\u590D\u5236",
4140
+ icon: _ctx.DocumentCopy,
4141
+ handler: () => _ctx.copy(item)
4142
+ }
4143
+ }, null, 8, ["data"]),
4144
+ vue.createVNode(_component_tool_button, {
4145
+ data: {
4146
+ type: "button",
4147
+ text: "\u5220\u9664",
4148
+ icon: _ctx.Delete,
4149
+ handler: () => _ctx.remove(item)
4150
+ }
4151
+ }, null, 8, ["data"])
4152
+ ])
4153
+ ])
4154
+ ]),
4155
+ _: 2
4156
+ }, 1024)
4157
+ ], 10, _hoisted_2);
4158
+ }), 128))
4159
+ ], 4)) : vue.createCommentVNode("", true),
4160
+ _ctx.canScroll ? (vue.openBlock(), vue.createElementBlock("div", {
4161
+ key: 2,
4162
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
4163
+ onClick: _cache[2] || (_cache[2] = ($event) => _ctx.scroll("right"))
4164
+ }, [
4165
+ vue.createVNode(_component_el_icon, null, {
4166
+ default: vue.withCtx(() => [
4167
+ vue.createVNode(_component_arrow_right_bold)
4168
+ ]),
4169
+ _: 1
4170
+ })
4171
+ ])) : vue.createCommentVNode("", true)
4172
+ ], 512);
3685
4173
  }
3686
4174
  var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3687
4175
 
3688
4176
  class ScrollViewer$1 {
3689
- enter = false;
3690
- targetEnter = false;
3691
- keydown = false;
3692
- container;
3693
- target;
3694
- zoom = 1;
3695
- scrollLeft = 0;
3696
- scrollTop = 0;
3697
- x = 0;
3698
- y = 0;
3699
- resizeObserver = new ResizeObserver((entries) => {
3700
- for (const { contentRect } of entries) {
3701
- const { width, height } = contentRect;
3702
- const targetRect = this.target.getBoundingClientRect();
3703
- const targetWidth = targetRect.width * this.zoom;
3704
- const targetMarginTop = Number(this.target.style.marginTop) || 0;
3705
- const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3706
- if (targetWidth < width) {
3707
- this.target._left = 0;
3708
- }
3709
- if (targetHeight < height) {
3710
- this.target._top = 0;
4177
+ constructor(options) {
4178
+ this.enter = false;
4179
+ this.targetEnter = false;
4180
+ this.keydown = false;
4181
+ this.zoom = 1;
4182
+ this.scrollLeft = 0;
4183
+ this.scrollTop = 0;
4184
+ this.x = 0;
4185
+ this.y = 0;
4186
+ this.resizeObserver = new ResizeObserver((entries) => {
4187
+ for (const { contentRect } of entries) {
4188
+ const { width, height } = contentRect;
4189
+ const targetRect = this.target.getBoundingClientRect();
4190
+ const targetWidth = targetRect.width * this.zoom;
4191
+ const targetMarginTop = Number(this.target.style.marginTop) || 0;
4192
+ const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
4193
+ if (targetWidth < width) {
4194
+ this.target._left = 0;
4195
+ }
4196
+ if (targetHeight < height) {
4197
+ this.target._top = 0;
4198
+ }
4199
+ this.scroll();
3711
4200
  }
4201
+ });
4202
+ this.wheelHandler = (event) => {
4203
+ if (this.targetEnter)
4204
+ return;
4205
+ const { deltaX, deltaY, currentTarget } = event;
4206
+ if (currentTarget !== this.container)
4207
+ return;
4208
+ this.setScrollOffset(deltaX, deltaY);
3712
4209
  this.scroll();
3713
- }
3714
- });
3715
- constructor(options) {
4210
+ this.scrollLeft = this.target._left;
4211
+ this.scrollTop = this.target._top;
4212
+ };
4213
+ this.mouseEnterHandler = () => {
4214
+ this.enter = true;
4215
+ };
4216
+ this.mouseLeaveHandler = () => {
4217
+ this.enter = false;
4218
+ };
4219
+ this.targetMouseEnterHandler = () => {
4220
+ this.targetEnter = true;
4221
+ };
4222
+ this.targetMouseLeaveHandler = () => {
4223
+ this.targetEnter = false;
4224
+ };
4225
+ this.mousedownHandler = (event) => {
4226
+ if (!this.keydown)
4227
+ return;
4228
+ event.stopImmediatePropagation();
4229
+ event.stopPropagation();
4230
+ this.target.style.cursor = "grabbing";
4231
+ this.x = event.clientX;
4232
+ this.y = event.clientY;
4233
+ document.addEventListener("mousemove", this.mousemoveHandler);
4234
+ document.addEventListener("mouseup", this.mouseupHandler);
4235
+ };
4236
+ this.mouseupHandler = () => {
4237
+ this.x = 0;
4238
+ this.y = 0;
4239
+ this.scrollLeft = this.target._left;
4240
+ this.scrollTop = this.target._top;
4241
+ this.removeHandler();
4242
+ };
4243
+ this.mousemoveHandler = (event) => {
4244
+ event.stopImmediatePropagation();
4245
+ event.stopPropagation();
4246
+ const deltaX = event.clientX - this.x;
4247
+ const deltaY = event.clientY - this.y;
4248
+ this.setScrollOffset(deltaX, deltaY);
4249
+ this.scroll();
4250
+ };
4251
+ this.keydownHandler = (event) => {
4252
+ if (event.code === Keys.ESCAPE && this.enter) {
4253
+ event.preventDefault();
4254
+ event.stopImmediatePropagation();
4255
+ event.stopPropagation();
4256
+ }
4257
+ if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
4258
+ return;
4259
+ }
4260
+ this.keydown = true;
4261
+ this.target.style.cursor = "grab";
4262
+ this.container.addEventListener("mousedown", this.mousedownHandler);
4263
+ };
4264
+ this.keyupHandler = (event) => {
4265
+ if (event.code !== Keys.ESCAPE || !this.keydown) {
4266
+ return;
4267
+ }
4268
+ event.preventDefault();
4269
+ event.stopImmediatePropagation();
4270
+ event.stopPropagation();
4271
+ this.keydown = false;
4272
+ event.preventDefault();
4273
+ this.removeHandler();
4274
+ };
3716
4275
  this.container = options.container;
3717
4276
  this.target = options.target;
3718
4277
  this.zoom = options.zoom;
@@ -3748,79 +4307,6 @@
3748
4307
  document.removeEventListener("mousemove", this.mousemoveHandler);
3749
4308
  document.removeEventListener("mouseup", this.mouseupHandler);
3750
4309
  }
3751
- wheelHandler = (event) => {
3752
- if (this.targetEnter)
3753
- return;
3754
- const { deltaX, deltaY, currentTarget } = event;
3755
- if (currentTarget !== this.container)
3756
- return;
3757
- this.setScrollOffset(deltaX, deltaY);
3758
- this.scroll();
3759
- this.scrollLeft = this.target._left;
3760
- this.scrollTop = this.target._top;
3761
- };
3762
- mouseEnterHandler = () => {
3763
- this.enter = true;
3764
- };
3765
- mouseLeaveHandler = () => {
3766
- this.enter = false;
3767
- };
3768
- targetMouseEnterHandler = () => {
3769
- this.targetEnter = true;
3770
- };
3771
- targetMouseLeaveHandler = () => {
3772
- this.targetEnter = false;
3773
- };
3774
- mousedownHandler = (event) => {
3775
- if (!this.keydown)
3776
- return;
3777
- event.stopImmediatePropagation();
3778
- event.stopPropagation();
3779
- this.target.style.cursor = "grabbing";
3780
- this.x = event.clientX;
3781
- this.y = event.clientY;
3782
- document.addEventListener("mousemove", this.mousemoveHandler);
3783
- document.addEventListener("mouseup", this.mouseupHandler);
3784
- };
3785
- mouseupHandler = () => {
3786
- this.x = 0;
3787
- this.y = 0;
3788
- this.scrollLeft = this.target._left;
3789
- this.scrollTop = this.target._top;
3790
- this.removeHandler();
3791
- };
3792
- mousemoveHandler = (event) => {
3793
- event.stopImmediatePropagation();
3794
- event.stopPropagation();
3795
- const deltaX = event.clientX - this.x;
3796
- const deltaY = event.clientY - this.y;
3797
- this.setScrollOffset(deltaX, deltaY);
3798
- this.scroll();
3799
- };
3800
- keydownHandler = (event) => {
3801
- if (event.code === Keys.ESCAPE && this.enter) {
3802
- event.preventDefault();
3803
- event.stopImmediatePropagation();
3804
- event.stopPropagation();
3805
- }
3806
- if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3807
- return;
3808
- }
3809
- this.keydown = true;
3810
- this.target.style.cursor = "grab";
3811
- this.container.addEventListener("mousedown", this.mousedownHandler);
3812
- };
3813
- keyupHandler = (event) => {
3814
- if (event.code !== Keys.ESCAPE || !this.keydown) {
3815
- return;
3816
- }
3817
- event.preventDefault();
3818
- event.stopImmediatePropagation();
3819
- event.stopPropagation();
3820
- this.keydown = false;
3821
- event.preventDefault();
3822
- this.removeHandler();
3823
- };
3824
4310
  setScrollOffset(deltaX, deltaY) {
3825
4311
  const { width, height } = this.container.getBoundingClientRect();
3826
4312
  const targetRect = this.target.getBoundingClientRect();
@@ -3881,19 +4367,19 @@
3881
4367
  el,
3882
4368
  style: vue.computed(() => `
3883
4369
  width: ${props.width}px;
3884
- height: ${props.height}px;
4370
+ height: ${(props.height || 0) - 40}px;
3885
4371
  position: absolute;
3886
4372
  margin-top: 30px;
3887
4373
  `)
3888
4374
  };
3889
4375
  }
3890
4376
  });
3891
- const _hoisted_1$2 = {
4377
+ const _hoisted_1$1 = {
3892
4378
  class: "m-editor-scroll-viewer-container",
3893
4379
  ref: "container"
3894
4380
  };
3895
4381
  function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3896
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
4382
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
3897
4383
  vue.createElementVNode("div", {
3898
4384
  ref: "el",
3899
4385
  style: vue.normalizeStyle(_ctx.style)
@@ -3905,7 +4391,7 @@
3905
4391
  var ScrollViewer = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$4]]);
3906
4392
 
3907
4393
  const _sfc_main$3 = vue.defineComponent({
3908
- name: "magic-editor-ui-viewer-menu",
4394
+ components: { ContentMenu },
3909
4395
  setup() {
3910
4396
  const services = vue.inject("services");
3911
4397
  const editorService = services?.editorService;
@@ -3914,6 +4400,7 @@
3914
4400
  const canCenter = vue.ref(false);
3915
4401
  const node = vue.computed(() => editorService?.get("node"));
3916
4402
  const parent = vue.computed(() => editorService?.get("parent"));
4403
+ const isPage = vue.computed(() => node.value?.type === schema.NodeType.PAGE);
3917
4404
  vue.onMounted(() => {
3918
4405
  const data = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
3919
4406
  canPaste.value = data !== "undefined" && !!data;
@@ -3926,133 +4413,114 @@
3926
4413
  }, { immediate: true });
3927
4414
  return {
3928
4415
  menu,
3929
- canPaste,
3930
- canDelete: vue.computed(() => node.value?.type !== schema.NodeType.PAGE),
3931
- canMoveZPos: vue.computed(() => node.value?.type !== schema.NodeType.PAGE),
3932
- canCenter,
3933
- center() {
3934
- node.value && editorService?.alignCenter(node.value);
3935
- },
3936
- copy() {
3937
- node.value && editorService?.copy(node.value);
3938
- canPaste.value = true;
3939
- },
3940
- paste() {
3941
- const top = menu.value?.offsetTop || 0;
3942
- const left = menu.value?.offsetLeft || 0;
3943
- editorService?.paste({ left, top });
3944
- },
3945
- remove() {
3946
- node.value && editorService?.remove(node.value);
3947
- },
3948
- top() {
3949
- editorService?.moveLayer(LayerOffset.TOP);
3950
- },
3951
- bottom() {
3952
- editorService?.moveLayer(LayerOffset.BOTTOM);
3953
- },
3954
- topItem() {
3955
- editorService?.moveLayer(1);
3956
- },
3957
- bottomItem() {
3958
- editorService?.moveLayer(-1);
3959
- },
3960
- clearGuides() {
3961
- editorService?.get("stage").clearGuides();
4416
+ menuData: vue.reactive([
4417
+ {
4418
+ type: "button",
4419
+ text: "\u6C34\u5E73\u5C45\u4E2D",
4420
+ display: () => canCenter.value,
4421
+ handler: () => {
4422
+ node.value && editorService?.alignCenter(node.value);
4423
+ }
4424
+ },
4425
+ {
4426
+ type: "button",
4427
+ text: "\u590D\u5236",
4428
+ icon: vue.markRaw(icons.DocumentCopy),
4429
+ handler: () => {
4430
+ node.value && editorService?.copy(node.value);
4431
+ canPaste.value = true;
4432
+ }
4433
+ },
4434
+ {
4435
+ type: "button",
4436
+ text: "\u7C98\u8D34",
4437
+ display: () => canPaste.value,
4438
+ handler: () => {
4439
+ const top = menu.value?.$el.offsetTop || 0;
4440
+ const left = menu.value?.$el.offsetLeft || 0;
4441
+ editorService?.paste({ left, top });
4442
+ }
4443
+ },
4444
+ {
4445
+ type: "divider",
4446
+ direction: "horizontal",
4447
+ display: () => !isPage.value
4448
+ },
4449
+ {
4450
+ type: "button",
4451
+ text: "\u4E0A\u79FB\u4E00\u5C42",
4452
+ icon: vue.markRaw(icons.Top),
4453
+ display: () => !isPage.value,
4454
+ handler: () => {
4455
+ editorService?.moveLayer(1);
4456
+ }
4457
+ },
4458
+ {
4459
+ type: "button",
4460
+ text: "\u4E0B\u79FB\u4E00\u5C42",
4461
+ icon: vue.markRaw(icons.Bottom),
4462
+ display: () => !isPage.value,
4463
+ handler: () => {
4464
+ editorService?.moveLayer(-1);
4465
+ }
4466
+ },
4467
+ {
4468
+ type: "button",
4469
+ text: "\u7F6E\u9876",
4470
+ display: () => !isPage.value,
4471
+ handler: () => {
4472
+ editorService?.moveLayer(LayerOffset.TOP);
4473
+ }
4474
+ },
4475
+ {
4476
+ type: "button",
4477
+ text: "\u7F6E\u5E95",
4478
+ display: () => !isPage.value,
4479
+ handler: () => {
4480
+ editorService?.moveLayer(LayerOffset.BOTTOM);
4481
+ }
4482
+ },
4483
+ {
4484
+ type: "divider",
4485
+ direction: "horizontal",
4486
+ display: () => !isPage.value
4487
+ },
4488
+ {
4489
+ type: "button",
4490
+ text: "\u5220\u9664",
4491
+ icon: icons.Delete,
4492
+ display: () => !isPage.value,
4493
+ handler: () => {
4494
+ node.value && editorService?.remove(node.value);
4495
+ }
4496
+ },
4497
+ {
4498
+ type: "divider",
4499
+ direction: "horizontal"
4500
+ },
4501
+ {
4502
+ type: "button",
4503
+ text: "\u6E05\u7A7A\u53C2\u8003\u7EBF",
4504
+ handler: () => {
4505
+ editorService?.get("stage").clearGuides();
4506
+ }
4507
+ }
4508
+ ]),
4509
+ show(e) {
4510
+ menu.value?.show(e);
3962
4511
  }
3963
4512
  };
3964
4513
  }
3965
4514
  });
3966
- const _hoisted_1$1 = {
3967
- class: "magic-editor-content-menu",
3968
- ref: "menu"
3969
- };
3970
- const _hoisted_2 = /* @__PURE__ */ vue.createElementVNode("div", { class: "separation" }, null, -1);
3971
- const _hoisted_3 = /* @__PURE__ */ vue.createElementVNode("div", { class: "separation" }, null, -1);
3972
- const _hoisted_4 = /* @__PURE__ */ vue.createElementVNode("div", { class: "separation" }, null, -1);
3973
4515
  function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3974
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
3975
- vue.createElementVNode("div", null, [
3976
- _ctx.canCenter ? (vue.openBlock(), vue.createElementBlock("div", {
3977
- key: 0,
3978
- class: "magic-editor-content-menu-item",
3979
- onClick: _cache[0] || (_cache[0] = () => _ctx.center())
3980
- }, "\u6C34\u5E73\u5C45\u4E2D")) : vue.createCommentVNode("", true),
3981
- vue.createElementVNode("div", {
3982
- class: "magic-editor-content-menu-item",
3983
- onClick: _cache[1] || (_cache[1] = () => _ctx.copy())
3984
- }, "\u590D\u5236"),
3985
- _ctx.canPaste ? (vue.openBlock(), vue.createElementBlock("div", {
3986
- key: 1,
3987
- class: "magic-editor-content-menu-item",
3988
- onClick: _cache[2] || (_cache[2] = (...args) => _ctx.paste && _ctx.paste(...args))
3989
- }, "\u7C98\u8D34")) : vue.createCommentVNode("", true),
3990
- _ctx.canMoveZPos ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
3991
- _hoisted_2,
3992
- vue.createElementVNode("div", {
3993
- class: "magic-editor-content-menu-item",
3994
- onClick: _cache[3] || (_cache[3] = (...args) => _ctx.topItem && _ctx.topItem(...args))
3995
- }, "\u4E0A\u79FB\u4E00\u5C42"),
3996
- vue.createElementVNode("div", {
3997
- class: "magic-editor-content-menu-item",
3998
- onClick: _cache[4] || (_cache[4] = (...args) => _ctx.bottomItem && _ctx.bottomItem(...args))
3999
- }, "\u4E0B\u79FB\u4E00\u5C42"),
4000
- vue.createElementVNode("div", {
4001
- class: "magic-editor-content-menu-item",
4002
- onClick: _cache[5] || (_cache[5] = (...args) => _ctx.top && _ctx.top(...args))
4003
- }, "\u7F6E\u9876"),
4004
- vue.createElementVNode("div", {
4005
- class: "magic-editor-content-menu-item",
4006
- onClick: _cache[6] || (_cache[6] = (...args) => _ctx.bottom && _ctx.bottom(...args))
4007
- }, "\u7F6E\u5E95")
4008
- ], 64)) : vue.createCommentVNode("", true),
4009
- _ctx.canDelete ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 3 }, [
4010
- _hoisted_3,
4011
- vue.createElementVNode("div", {
4012
- class: "magic-editor-content-menu-item",
4013
- onClick: _cache[7] || (_cache[7] = () => _ctx.remove())
4014
- }, "\u5220\u9664")
4015
- ], 64)) : vue.createCommentVNode("", true),
4016
- _hoisted_4,
4017
- vue.createElementVNode("div", {
4018
- class: "magic-editor-content-menu-item",
4019
- onClick: _cache[8] || (_cache[8] = (...args) => _ctx.clearGuides && _ctx.clearGuides(...args))
4020
- }, "\u6E05\u7A7A\u53C2\u8003\u7EBF")
4021
- ])
4022
- ], 512);
4516
+ const _component_content_menu = vue.resolveComponent("content-menu");
4517
+ return vue.openBlock(), vue.createBlock(_component_content_menu, {
4518
+ "menu-data": _ctx.menuData,
4519
+ ref: "menu"
4520
+ }, null, 8, ["menu-data"]);
4023
4521
  }
4024
4522
  var ViewerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
4025
4523
 
4026
- const useMenu = () => {
4027
- const menu = vue.ref();
4028
- const menuStyle = vue.ref({
4029
- display: "none",
4030
- left: "0",
4031
- top: "0"
4032
- });
4033
- vue.onMounted(() => {
4034
- document.addEventListener("click", () => {
4035
- menuStyle.value.display = "none";
4036
- }, true);
4037
- });
4038
- return {
4039
- menu,
4040
- menuStyle,
4041
- contextmenuHandler(e) {
4042
- e.preventDefault();
4043
- const menuHeight = menu.value?.$el.clientHeight;
4044
- let top = e.clientY;
4045
- if (menuHeight + e.clientY > document.body.clientHeight) {
4046
- top = document.body.clientHeight - menuHeight;
4047
- }
4048
- menuStyle.value = {
4049
- display: "block",
4050
- top: `${top}px`,
4051
- left: `${e.clientX}px`
4052
- };
4053
- }
4054
- };
4055
- };
4056
4524
  const _sfc_main$2 = vue.defineComponent({
4057
4525
  name: "magic-stage",
4058
4526
  components: {
@@ -4075,18 +4543,17 @@
4075
4543
  })
4076
4544
  }
4077
4545
  },
4078
- emits: ["select", "update", "sort", "highlight"],
4079
- setup(props, { emit }) {
4546
+ setup(props) {
4080
4547
  const services = vue.inject("services");
4081
4548
  const stageWrap = vue.ref();
4082
4549
  const stageContainer = vue.ref();
4550
+ const menu = vue.ref();
4083
4551
  const stageRect = vue.computed(() => services?.uiService.get("stageRect"));
4084
4552
  const uiSelectMode = vue.computed(() => services?.uiService.get("uiSelectMode"));
4085
4553
  const root = vue.computed(() => services?.editorService.get("root"));
4086
4554
  const page = vue.computed(() => services?.editorService.get("page"));
4087
- const zoom = vue.computed(() => services?.uiService.get("zoom"));
4555
+ const zoom = vue.computed(() => services?.uiService.get("zoom") || 1);
4088
4556
  const node = vue.computed(() => services?.editorService.get("node"));
4089
- const highlightNode = vue.computed(() => services?.editorService.get("highlightNode"));
4090
4557
  let stage = null;
4091
4558
  let runtime = null;
4092
4559
  vue.watchEffect(() => {
@@ -4100,9 +4567,9 @@
4100
4567
  render: props.render,
4101
4568
  runtimeUrl: props.runtimeUrl,
4102
4569
  zoom: zoom.value,
4103
- canSelect: (el, stop) => {
4570
+ canSelect: (el, event, stop) => {
4104
4571
  const elCanSelect = props.canSelect(el);
4105
- if (uiSelectMode.value && elCanSelect) {
4572
+ if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
4106
4573
  document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
4107
4574
  return stop();
4108
4575
  }
@@ -4110,19 +4577,19 @@
4110
4577
  },
4111
4578
  moveableOptions: props.moveableOptions
4112
4579
  });
4113
- services?.editorService.set("stage", stage);
4580
+ services?.editorService.set("stage", vue.markRaw(stage));
4114
4581
  stage?.mount(stageContainer.value);
4115
4582
  stage?.on("select", (el) => {
4116
- emit("select", el);
4583
+ services?.editorService.select(el.id);
4117
4584
  });
4118
4585
  stage?.on("highlight", (el) => {
4119
- emit("highlight", el);
4586
+ services?.editorService.highlight(el.id);
4120
4587
  });
4121
4588
  stage?.on("update", (ev) => {
4122
- emit("update", { id: ev.el.id, style: ev.style });
4589
+ services?.editorService.update({ id: ev.el.id, style: ev.style });
4123
4590
  });
4124
4591
  stage?.on("sort", (ev) => {
4125
- emit("sort", ev);
4592
+ services?.editorService.sort(ev.src, ev.dist);
4126
4593
  });
4127
4594
  stage?.on("changeGuides", () => {
4128
4595
  services?.uiService.set("showGuides", true);
@@ -4148,16 +4615,6 @@
4148
4615
  runtime.updateRootConfig(lodashEs.cloneDeep(vue.toRaw(root2)));
4149
4616
  }
4150
4617
  });
4151
- vue.watch(() => node.value?.id, (id) => {
4152
- vue.nextTick(() => {
4153
- id && stage?.select(id);
4154
- });
4155
- });
4156
- vue.watch(() => highlightNode.value?.id, (id) => {
4157
- vue.nextTick(() => {
4158
- id && stage?.highlight(id);
4159
- });
4160
- });
4161
4618
  const resizeObserver = new ResizeObserver((entries) => {
4162
4619
  for (const { contentRect } of entries) {
4163
4620
  services?.uiService.set("stageContainerRect", {
@@ -4177,9 +4634,36 @@
4177
4634
  return {
4178
4635
  stageWrap,
4179
4636
  stageContainer,
4637
+ menu,
4180
4638
  stageRect,
4181
4639
  zoom,
4182
- ...useMenu()
4640
+ contextmenuHandler(e2) {
4641
+ e2.preventDefault();
4642
+ menu.value?.show(e2);
4643
+ },
4644
+ dragoverHandler(e2) {
4645
+ e2.preventDefault();
4646
+ if (e2.dataTransfer) {
4647
+ e2.dataTransfer.dropEffect = "move";
4648
+ }
4649
+ },
4650
+ async dropHandler(e) {
4651
+ e.preventDefault();
4652
+ if (e.dataTransfer && page.value && stageContainer.value && stage) {
4653
+ const config = eval(`(${e.dataTransfer.getData("data")})`);
4654
+ const layout = await services?.editorService.getLayout(page.value);
4655
+ const containerRect = stageContainer.value.getBoundingClientRect();
4656
+ const { scrollTop, scrollLeft } = stage.mask;
4657
+ if (layout === Layout.ABSOLUTE) {
4658
+ config.style = {
4659
+ position: "absolute",
4660
+ top: e.clientY - containerRect.top + scrollTop,
4661
+ left: e.clientX - containerRect.left + scrollLeft
4662
+ };
4663
+ }
4664
+ services?.editorService.add(config, page.value);
4665
+ }
4666
+ }
4183
4667
  };
4184
4668
  }
4185
4669
  });
@@ -4197,14 +4681,13 @@
4197
4681
  vue.createElementVNode("div", {
4198
4682
  class: "m-editor-stage-container",
4199
4683
  ref: "stageContainer",
4684
+ style: vue.normalizeStyle(`transform: scale(${_ctx.zoom})`),
4200
4685
  onContextmenu: _cache[0] || (_cache[0] = (...args) => _ctx.contextmenuHandler && _ctx.contextmenuHandler(...args)),
4201
- style: vue.normalizeStyle(`transform: scale(${_ctx.zoom})`)
4686
+ onDrop: _cache[1] || (_cache[1] = (...args) => _ctx.dropHandler && _ctx.dropHandler(...args)),
4687
+ onDragover: _cache[2] || (_cache[2] = (...args) => _ctx.dragoverHandler && _ctx.dragoverHandler(...args))
4202
4688
  }, null, 36),
4203
4689
  (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
4204
- vue.createVNode(_component_viewer_menu, {
4205
- ref: "menu",
4206
- style: vue.normalizeStyle(_ctx.menuStyle)
4207
- }, null, 8, ["style"])
4690
+ vue.createVNode(_component_viewer_menu, { ref: "menu" }, null, 512)
4208
4691
  ]))
4209
4692
  ]),
4210
4693
  _: 1
@@ -4232,24 +4715,93 @@
4232
4715
  },
4233
4716
  setup() {
4234
4717
  const services = vue.inject("services");
4718
+ const workspace = vue.ref();
4719
+ const node = vue.computed(() => services?.editorService.get("node"));
4720
+ let keycon;
4721
+ const mouseenterHandler = () => {
4722
+ workspace.value?.focus();
4723
+ };
4724
+ vue.onMounted(() => {
4725
+ workspace.value?.addEventListener("mouseenter", mouseenterHandler);
4726
+ keycon = new KeyController__default["default"](workspace.value);
4727
+ const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
4728
+ const ctrl = isMac ? "meta" : "ctrl";
4729
+ keycon.keyup("delete", (e) => {
4730
+ e.inputEvent.preventDefault();
4731
+ if (!node.value || utils.isPage(node.value))
4732
+ return;
4733
+ services?.editorService.remove(node.value);
4734
+ }).keydown([ctrl, "c"], (e) => {
4735
+ e.inputEvent.preventDefault();
4736
+ node.value && services?.editorService.copy(node.value);
4737
+ }).keydown([ctrl, "v"], (e) => {
4738
+ e.inputEvent.preventDefault();
4739
+ node.value && services?.editorService.paste();
4740
+ }).keydown([ctrl, "x"], (e) => {
4741
+ e.inputEvent.preventDefault();
4742
+ if (!node.value || utils.isPage(node.value))
4743
+ return;
4744
+ services?.editorService.copy(node.value);
4745
+ services?.editorService.remove(node.value);
4746
+ }).keydown([ctrl, "z"], (e) => {
4747
+ e.inputEvent.preventDefault();
4748
+ services?.editorService.undo();
4749
+ }).keydown([ctrl, "shift", "z"], (e) => {
4750
+ e.inputEvent.preventDefault();
4751
+ services?.editorService.redo();
4752
+ }).keydown("up", (e) => {
4753
+ e.inputEvent.preventDefault();
4754
+ services?.editorService.move(0, -1);
4755
+ }).keydown("down", (e) => {
4756
+ e.inputEvent.preventDefault();
4757
+ services?.editorService.move(0, 1);
4758
+ }).keydown("left", (e) => {
4759
+ e.inputEvent.preventDefault();
4760
+ services?.editorService.move(-1, 0);
4761
+ }).keydown("right", (e) => {
4762
+ e.inputEvent.preventDefault();
4763
+ services?.editorService.move(1, 0);
4764
+ }).keydown([ctrl, "up"], (e) => {
4765
+ e.inputEvent.preventDefault();
4766
+ services?.editorService.move(0, -10);
4767
+ }).keydown([ctrl, "down"], (e) => {
4768
+ e.inputEvent.preventDefault();
4769
+ services?.editorService.move(0, 10);
4770
+ }).keydown([ctrl, "left"], (e) => {
4771
+ e.inputEvent.preventDefault();
4772
+ services?.editorService.move(-10, 0);
4773
+ }).keydown([ctrl, "right"], (e) => {
4774
+ e.inputEvent.preventDefault();
4775
+ services?.editorService.move(10, 0);
4776
+ }).keydown("tab", (e) => {
4777
+ e.inputEvent.preventDefault();
4778
+ services?.editorService.selectNextNode();
4779
+ }).keydown([ctrl, "tab"], (e) => {
4780
+ e.inputEvent.preventDefault();
4781
+ services?.editorService.selectNextPage();
4782
+ }).keydown([ctrl, "="], (e) => {
4783
+ e.inputEvent.preventDefault();
4784
+ services?.uiService.zoom(0.1);
4785
+ }).keydown([ctrl, "-"], (e) => {
4786
+ e.inputEvent.preventDefault();
4787
+ services?.uiService.zoom(-0.1);
4788
+ });
4789
+ });
4790
+ vue.onUnmounted(() => {
4791
+ workspace.value?.removeEventListener("mouseenter", mouseenterHandler);
4792
+ keycon.destroy();
4793
+ });
4235
4794
  return {
4236
- page: vue.computed(() => services?.editorService.get("page")),
4237
- selectHandler(el) {
4238
- services?.editorService.select(el.id);
4239
- },
4240
- updateNodeHandler(node) {
4241
- services?.editorService.update(node);
4242
- },
4243
- sortNodeHandler(ev) {
4244
- services?.editorService.sort(ev.src, ev.dist);
4245
- },
4246
- highlightHandler(el) {
4247
- services?.editorService.highlight(el.id);
4248
- }
4795
+ workspace,
4796
+ page: vue.computed(() => services?.editorService.get("page"))
4249
4797
  };
4250
4798
  }
4251
4799
  });
4252
- const _hoisted_1 = { class: "m-editor-workspace" };
4800
+ const _hoisted_1 = {
4801
+ class: "m-editor-workspace",
4802
+ tabindex: "1",
4803
+ ref: "workspace"
4804
+ };
4253
4805
  function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4254
4806
  const _component_magic_stage = vue.resolveComponent("magic-stage");
4255
4807
  const _component_page_bar = vue.resolveComponent("page-bar");
@@ -4259,12 +4811,8 @@
4259
4811
  "runtime-url": _ctx.runtimeUrl,
4260
4812
  render: _ctx.render,
4261
4813
  "moveable-options": _ctx.moveableOptions,
4262
- "can-select": _ctx.canSelect,
4263
- onSelect: _ctx.selectHandler,
4264
- onHighlight: _ctx.highlightHandler,
4265
- onUpdate: _ctx.updateNodeHandler,
4266
- onSort: _ctx.sortNodeHandler
4267
- }, null, 8, ["runtime-url", "render", "moveable-options", "can-select", "onSelect", "onHighlight", "onUpdate", "onSort"])),
4814
+ "can-select": _ctx.canSelect
4815
+ }, null, 8, ["runtime-url", "render", "moveable-options", "can-select"])),
4268
4816
  vue.renderSlot(_ctx.$slots, "workspace-content"),
4269
4817
  vue.createVNode(_component_page_bar, null, {
4270
4818
  "page-bar-title": vue.withCtx(({ page }) => [
@@ -4275,16 +4823,16 @@
4275
4823
  ]),
4276
4824
  _: 3
4277
4825
  })
4278
- ]);
4826
+ ], 512);
4279
4827
  }
4280
4828
  var Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
4281
4829
 
4282
4830
  class ComponentList extends BaseService {
4283
- state = vue.reactive({
4284
- list: []
4285
- });
4286
4831
  constructor() {
4287
4832
  super([]);
4833
+ this.state = vue.reactive({
4834
+ list: []
4835
+ });
4288
4836
  }
4289
4837
  setList(componentGroupList) {
4290
4838
  this.state.list = componentGroupList;
@@ -4295,6 +4843,14 @@
4295
4843
  }
4296
4844
  var componentListService = new ComponentList();
4297
4845
 
4846
+ const DEFAULT_LEFT_COLUMN_WIDTH = 310;
4847
+ const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
4848
+ const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
4849
+ const defaultColumnWidth = {
4850
+ left: DEFAULT_LEFT_COLUMN_WIDTH,
4851
+ center: globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH,
4852
+ right: DEFAULT_RIGHT_COLUMN_WIDTH
4853
+ };
4298
4854
  const state = vue.reactive({
4299
4855
  uiSelectMode: false,
4300
4856
  showSrc: false,
@@ -4307,13 +4863,10 @@
4307
4863
  width: 375,
4308
4864
  height: 817
4309
4865
  },
4310
- columnWidth: {
4311
- left: 310,
4312
- center: globalThis.document.body.clientWidth - 310 - 400,
4313
- right: 400
4314
- },
4866
+ columnWidth: defaultColumnWidth,
4315
4867
  showGuides: true,
4316
- showRule: true
4868
+ showRule: true,
4869
+ propsPanelSize: "small"
4317
4870
  });
4318
4871
  class Ui extends BaseService {
4319
4872
  constructor() {
@@ -4323,6 +4876,15 @@
4323
4876
  center: "auto"
4324
4877
  });
4325
4878
  });
4879
+ const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
4880
+ if (columnWidthCacheData) {
4881
+ try {
4882
+ const columnWidthCache = JSON.parse(columnWidthCacheData);
4883
+ this.setColumnWidth(columnWidthCache);
4884
+ } catch (e) {
4885
+ console.error(e);
4886
+ }
4887
+ }
4326
4888
  }
4327
4889
  set(name, value) {
4328
4890
  const mask = editorService.get("stage")?.mask;
@@ -4348,6 +4910,11 @@
4348
4910
  get(name) {
4349
4911
  return state[name];
4350
4912
  }
4913
+ zoom(zoom) {
4914
+ this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
4915
+ if (this.get("zoom") < 0.1)
4916
+ this.set("zoom", 0.1);
4917
+ }
4351
4918
  setColumnWidth({ left, center, right }) {
4352
4919
  const columnWidth = {
4353
4920
  ...vue.toRaw(this.get("columnWidth"))
@@ -4361,9 +4928,15 @@
4361
4928
  if (!center || center === "auto") {
4362
4929
  const bodyWidth = globalThis.document.body.clientWidth;
4363
4930
  columnWidth.center = bodyWidth - (columnWidth?.left || 0) - (columnWidth?.right || 0);
4931
+ if (columnWidth.center <= 0) {
4932
+ columnWidth.left = defaultColumnWidth.left;
4933
+ columnWidth.center = defaultColumnWidth.center;
4934
+ columnWidth.right = defaultColumnWidth.right;
4935
+ }
4364
4936
  } else {
4365
4937
  columnWidth.center = center;
4366
4938
  }
4939
+ globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
4367
4940
  state.columnWidth = columnWidth;
4368
4941
  }
4369
4942
  setStageRect(value) {
@@ -4572,6 +5145,7 @@
4572
5145
  exports.PropsPanel = PropsPanel;
4573
5146
  exports.TMagicCodeEditor = CodeEditor;
4574
5147
  exports.TMagicEditor = Editor;
5148
+ exports.ToolButton = ToolButton;
4575
5149
  exports.change2Fixed = change2Fixed;
4576
5150
  exports.debug = debug;
4577
5151
  exports["default"] = index;
@@ -4600,8 +5174,7 @@
4600
5174
  exports.uiService = uiService;
4601
5175
  exports.warn = warn;
4602
5176
 
4603
- Object.defineProperty(exports, '__esModule', { value: true });
4604
- exports[Symbol.toStringTag] = 'Module';
5177
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4605
5178
 
4606
5179
  }));
4607
5180
  //# sourceMappingURL=tmagic-editor.umd.js.map