@tmagic/editor 1.0.0-beta.8 → 1.0.0-rc.2

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 (121) hide show
  1. package/README.md +1 -0
  2. package/coverage/clover.xml +1556 -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 +802 -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 +343 -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 +760 -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 +598 -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 +3747 -0
  55. package/dist/style.css +91 -45
  56. package/dist/tmagic-editor.es.js +1462 -2003
  57. package/dist/tmagic-editor.es.js.map +1 -1
  58. package/dist/tmagic-editor.umd.js +1461 -2003
  59. package/dist/tmagic-editor.umd.js.map +1 -1
  60. package/dist/types/src/Editor.vue.d.ts +10 -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/Framework.vue.d.ts +15 -3
  66. package/dist/types/src/layouts/PropsPanel.vue.d.ts +2 -1
  67. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +2 -1
  68. package/dist/types/src/layouts/sidebar/Sidebar.vue.d.ts +2 -3
  69. package/dist/types/src/layouts/sidebar/TabPane.vue.d.ts +14 -0
  70. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +10 -3
  71. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +4 -6
  72. package/dist/types/src/services/BaseService.d.ts +4 -1
  73. package/dist/types/src/services/editor.d.ts +16 -6
  74. package/dist/types/src/services/history.d.ts +1 -0
  75. package/dist/types/src/services/props.d.ts +2 -2
  76. package/dist/types/src/services/ui.d.ts +2 -0
  77. package/dist/types/src/type.d.ts +16 -9
  78. package/dist/types/src/utils/editor.d.ts +5 -4
  79. package/dist/types/src/utils/polyfills.d.ts +0 -0
  80. package/package.json +44 -12
  81. package/src/Editor.vue +6 -1
  82. package/src/components/ContentMenu.vue +107 -0
  83. package/src/components/ScrollViewer.vue +1 -1
  84. package/src/components/ToolButton.vue +72 -31
  85. package/src/fields/UISelect.vue +14 -6
  86. package/src/index.ts +2 -0
  87. package/src/layouts/AddPageBox.vue +3 -1
  88. package/src/layouts/CodeEditor.vue +20 -13
  89. package/src/layouts/Framework.vue +20 -7
  90. package/src/layouts/PropsPanel.vue +5 -4
  91. package/src/layouts/sidebar/ComponentListPanel.vue +25 -3
  92. package/src/layouts/sidebar/LayerMenu.vue +91 -96
  93. package/src/layouts/sidebar/LayerPanel.vue +80 -59
  94. package/src/layouts/sidebar/Sidebar.vue +13 -52
  95. package/src/layouts/sidebar/TabPane.vue +68 -0
  96. package/src/layouts/workspace/PageBar.vue +145 -17
  97. package/src/layouts/workspace/Stage.vue +56 -64
  98. package/src/layouts/workspace/ViewerMenu.vue +107 -68
  99. package/src/layouts/workspace/Workspace.vue +110 -18
  100. package/src/services/BaseService.ts +70 -22
  101. package/src/services/editor.ts +197 -64
  102. package/src/services/history.ts +7 -0
  103. package/src/services/props.ts +3 -3
  104. package/src/services/ui.ts +35 -5
  105. package/src/theme/common/var.scss +3 -2
  106. package/src/theme/component-list-panel.scss +2 -0
  107. package/src/theme/content-menu.scss +33 -26
  108. package/src/theme/layer-panel.scss +10 -0
  109. package/src/theme/nav-menu.scss +6 -2
  110. package/src/theme/page-bar.scss +42 -2
  111. package/src/theme/props-panel.scss +19 -17
  112. package/src/type.ts +17 -9
  113. package/src/utils/editor.ts +35 -9
  114. package/src/utils/polyfills.ts +8 -0
  115. package/src/utils/props.ts +20 -1
  116. package/dist/types/src/layouts/sidebar/LayerMenu.vue.d.ts +0 -31
  117. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +0 -973
  118. package/dist/types/src/layouts/workspace/Stage.vue.d.ts +0 -192
  119. package/dist/types/src/layouts/workspace/ViewerMenu.vue.d.ts +0 -18
  120. package/tsconfig.json +0 -9
  121. package/vite.config.ts +0 -30
@@ -1,14 +1,24 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, createElementBlock, createElementVNode, toDisplayString, withModifiers, createCommentVNode, watch, onMounted, onUnmounted, reactive, toRaw, createVNode, withCtx, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, createTextVNode, normalizeProps, mergeProps, getCurrentInstance, withDirectives, vShow, Teleport, toHandlers, createSlots, nextTick, provide } from 'vue';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, markRaw, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, normalizeProps, mergeProps, getCurrentInstance, nextTick, withDirectives, Teleport, vShow, toHandlers, createSlots, provide } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
+ import { Delete, Pointer, Close, Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons';
4
+ import { throttle, cloneDeep, mergeWith, random } from 'lodash-es';
3
5
  import * as monaco from 'monaco-editor';
4
- import { Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Delete, Files, Coin, CaretBottom } from '@element-plus/icons';
5
- import { cloneDeep, random, mergeWith } from 'lodash-es';
6
- import { toLine, isPop, getNodePath } from '@tmagic/utils';
7
- import { EventEmitter as EventEmitter$2 } from 'events';
6
+ import { NodeType } from '@tmagic/schema';
7
+ import { toLine, isPop, getNodePath, isNumber, isPage } from '@tmagic/utils';
8
+ import { EventEmitter } from 'events';
8
9
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
10
+ import Gesto from 'gesto';
9
11
  import { ElMessage } from 'element-plus';
12
+ import KeyController from 'keycon';
10
13
  import StageCore from '@tmagic/stage';
11
14
 
15
+ if (typeof global === "undefined") {
16
+ window.global = window;
17
+ }
18
+ if (typeof globalThis === "undefined") {
19
+ window.globalThis = window;
20
+ }
21
+
12
22
  var _export_sfc = (sfc, props) => {
13
23
  const target = sfc.__vccOpts || sfc;
14
24
  for (const [key, val] of props) {
@@ -17,7 +27,7 @@ var _export_sfc = (sfc, props) => {
17
27
  return target;
18
28
  };
19
29
 
20
- const _sfc_main$k = defineComponent({
30
+ const _sfc_main$m = defineComponent({
21
31
  name: "m-fields-vs-code",
22
32
  props: ["model", "name", "config", "prop"],
23
33
  emits: ["change"],
@@ -34,7 +44,7 @@ const _sfc_main$k = defineComponent({
34
44
  };
35
45
  }
36
46
  });
37
- function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
47
+ function _sfc_render$m(_ctx, _cache, $props, $setup, $data, $options) {
38
48
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
39
49
  return openBlock(), createBlock(_component_magic_code_editor, {
40
50
  style: normalizeStyle(`height: ${_ctx.height}`),
@@ -43,9 +53,9 @@ function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
43
53
  onSave: _ctx.save
44
54
  }, null, 8, ["style", "init-values", "language", "onSave"]);
45
55
  }
46
- var Code = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$k]]);
56
+ var Code = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$m]]);
47
57
 
48
- const _sfc_main$j = defineComponent({
58
+ const _sfc_main$l = defineComponent({
49
59
  name: "m-fields-code-link",
50
60
  props: {
51
61
  config: {
@@ -100,7 +110,7 @@ const _sfc_main$j = defineComponent({
100
110
  };
101
111
  }
102
112
  });
103
- function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
113
+ function _sfc_render$l(_ctx, _cache, $props, $setup, $data, $options) {
104
114
  const _component_m_fields_link = resolveComponent("m-fields-link");
105
115
  return openBlock(), createBlock(_component_m_fields_link, {
106
116
  config: _ctx.formConfig,
@@ -109,11 +119,11 @@ function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
109
119
  onChange: _ctx.changeHandler
110
120
  }, null, 8, ["config", "model", "onChange"]);
111
121
  }
112
- var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
122
+ var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$l]]);
113
123
 
114
124
  var UISelect_vue_vue_type_style_index_0_lang = '';
115
125
 
116
- const _sfc_main$i = defineComponent({
126
+ const _sfc_main$k = defineComponent({
117
127
  name: "m-fields-ui-select",
118
128
  props: {
119
129
  labelWidth: String,
@@ -151,6 +161,9 @@ const _sfc_main$i = defineComponent({
151
161
  }
152
162
  };
153
163
  return {
164
+ Delete: markRaw(Delete),
165
+ Pointer: markRaw(Pointer),
166
+ Close: markRaw(Close),
154
167
  val,
155
168
  uiSelectMode,
156
169
  toName: computed(() => {
@@ -175,34 +188,64 @@ const _sfc_main$i = defineComponent({
175
188
  };
176
189
  }
177
190
  });
178
- const _hoisted_1$d = /* @__PURE__ */ createElementVNode("i", {
179
- class: "el-icon-delete",
180
- style: { "color": "rgb(221, 75, 57)" }
181
- }, "\u53D6\u6D88", -1);
182
- const _hoisted_2$7 = [
183
- _hoisted_1$d
184
- ];
185
- const _hoisted_3$5 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-thumb" }, null, -1);
186
- function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
191
+ const _hoisted_1$c = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
192
+ function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
193
+ const _component_el_button = resolveComponent("el-button");
194
+ const _component_el_tooltip = resolveComponent("el-tooltip");
187
195
  return _ctx.uiSelectMode ? (openBlock(), createElementBlock("div", {
188
196
  key: 0,
189
197
  class: "m-fields-ui-select",
190
198
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.cancelHandler && _ctx.cancelHandler(...args))
191
- }, _hoisted_2$7)) : (openBlock(), createElementBlock("div", {
199
+ }, [
200
+ createVNode(_component_el_button, {
201
+ type: "danger",
202
+ icon: _ctx.Delete,
203
+ text: "",
204
+ style: { "padding": "0" }
205
+ }, {
206
+ default: withCtx(() => [
207
+ _hoisted_1$c
208
+ ]),
209
+ _: 1
210
+ }, 8, ["icon"])
211
+ ])) : (openBlock(), createElementBlock("div", {
192
212
  key: 1,
193
213
  class: "m-fields-ui-select",
194
- onClick: _cache[2] || (_cache[2] = (...args) => _ctx.startSelect && _ctx.startSelect(...args))
214
+ onClick: _cache[1] || (_cache[1] = (...args) => _ctx.startSelect && _ctx.startSelect(...args)),
215
+ style: { "display": "flex" }
195
216
  }, [
196
- _hoisted_3$5,
197
- createElementVNode("span", null, toDisplayString(_ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1),
198
- _ctx.val ? (openBlock(), createElementBlock("i", {
199
- key: 0,
200
- class: "el-icon-delete",
201
- onClick: _cache[1] || (_cache[1] = withModifiers((...args) => _ctx.deleteHandler && _ctx.deleteHandler(...args), ["stop"]))
202
- })) : createCommentVNode("", true)
217
+ createVNode(_component_el_tooltip, { content: "\u6E05\u9664" }, {
218
+ default: withCtx(() => [
219
+ _ctx.val ? (openBlock(), createBlock(_component_el_button, {
220
+ key: 0,
221
+ style: { "padding": "0" },
222
+ type: "danger",
223
+ icon: _ctx.Close,
224
+ text: "",
225
+ onClick: withModifiers(_ctx.deleteHandler, ["stop"])
226
+ }, null, 8, ["icon", "onClick"])) : createCommentVNode("", true)
227
+ ]),
228
+ _: 1
229
+ }),
230
+ createVNode(_component_el_tooltip, {
231
+ content: _ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"
232
+ }, {
233
+ default: withCtx(() => [
234
+ createVNode(_component_el_button, {
235
+ text: "",
236
+ style: { "padding": "0", "margin": "0" }
237
+ }, {
238
+ default: withCtx(() => [
239
+ createTextVNode(toDisplayString(_ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1)
240
+ ]),
241
+ _: 1
242
+ })
243
+ ]),
244
+ _: 1
245
+ }, 8, ["content"])
203
246
  ]));
204
247
  }
205
- var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
248
+ var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$k]]);
206
249
 
207
250
  const toString = (v, language) => {
208
251
  let value = "";
@@ -219,7 +262,7 @@ const toString = (v, language) => {
219
262
  }
220
263
  return value;
221
264
  };
222
- const _sfc_main$h = defineComponent({
265
+ const _sfc_main$j = defineComponent({
223
266
  name: "magic-code-editor",
224
267
  props: {
225
268
  initValues: {
@@ -229,12 +272,16 @@ const _sfc_main$h = defineComponent({
229
272
  type: [String, Object]
230
273
  },
231
274
  type: {
232
- type: [String],
275
+ type: String,
233
276
  default: () => ""
234
277
  },
235
278
  language: {
236
- type: [String],
279
+ type: String,
237
280
  default: () => "javascript"
281
+ },
282
+ options: {
283
+ type: Object,
284
+ default: () => ({})
238
285
  }
239
286
  },
240
287
  emits: ["initd", "save"],
@@ -244,6 +291,10 @@ const _sfc_main$h = defineComponent({
244
291
  const values = ref("");
245
292
  const loading = ref(false);
246
293
  const codeEditor = ref();
294
+ const resizeObserver = new globalThis.ResizeObserver(throttle(() => {
295
+ vsEditor?.layout();
296
+ vsDiffEditor?.layout();
297
+ }, 300));
247
298
  const setEditorValue = (v, m) => {
248
299
  values.value = toString(v, props.language);
249
300
  if (props.type === "diff") {
@@ -256,10 +307,6 @@ const _sfc_main$h = defineComponent({
256
307
  }
257
308
  return vsEditor?.setValue(values.value);
258
309
  };
259
- const resizeHandler = () => {
260
- vsEditor?.layout();
261
- vsDiffEditor?.layout();
262
- };
263
310
  const getEditorValue = () => props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
264
311
  const init = async () => {
265
312
  if (!codeEditor.value)
@@ -267,11 +314,8 @@ const _sfc_main$h = defineComponent({
267
314
  const options = {
268
315
  value: values.value,
269
316
  language: props.language,
270
- tabSize: 2,
271
317
  theme: "vs-dark",
272
- fontFamily: 'dm, Menlo, Monaco, "Courier New", monospace',
273
- fontSize: 15,
274
- formatOnPaste: true
318
+ ...props.options
275
319
  };
276
320
  if (props.type === "diff") {
277
321
  vsDiffEditor = monaco.editor.createDiffEditor(codeEditor.value, options);
@@ -284,6 +328,7 @@ const _sfc_main$h = defineComponent({
284
328
  codeEditor.value.addEventListener("keydown", (e) => {
285
329
  if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
286
330
  e.preventDefault();
331
+ e.stopPropagation();
287
332
  emit("save", getEditorValue());
288
333
  }
289
334
  });
@@ -292,7 +337,7 @@ const _sfc_main$h = defineComponent({
292
337
  emit("save", getEditorValue());
293
338
  });
294
339
  }
295
- globalThis.addEventListener("resize", resizeHandler);
340
+ resizeObserver.observe(codeEditor.value);
296
341
  };
297
342
  watch(() => props.initValues, (v, preV) => {
298
343
  if (v !== preV) {
@@ -307,7 +352,7 @@ const _sfc_main$h = defineComponent({
307
352
  init();
308
353
  });
309
354
  onUnmounted(() => {
310
- globalThis.removeEventListener("resize", resizeHandler);
355
+ resizeObserver.disconnect();
311
356
  });
312
357
  return {
313
358
  values,
@@ -324,14 +369,14 @@ const _sfc_main$h = defineComponent({
324
369
  };
325
370
  }
326
371
  });
327
- const _hoisted_1$c = {
372
+ const _hoisted_1$b = {
328
373
  ref: "codeEditor",
329
374
  class: "magic-code-editor"
330
375
  };
331
- function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
332
- return openBlock(), createElementBlock("div", _hoisted_1$c, null, 512);
376
+ function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
377
+ return openBlock(), createElementBlock("div", _hoisted_1$b, null, 512);
333
378
  }
334
- var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
379
+ var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
335
380
 
336
381
  let $TMAGIC_EDITOR = {};
337
382
  const setConfig = (option) => {
@@ -340,9 +385,6 @@ const setConfig = (option) => {
340
385
  const getConfig = (key) => $TMAGIC_EDITOR[key];
341
386
 
342
387
  class UndoRedo {
343
- elementList;
344
- listCursor;
345
- listMaxSize;
346
388
  constructor(listMaxSize = 200) {
347
389
  const minListMaxSize = 2;
348
390
  this.elementList = [];
@@ -415,11 +457,40 @@ const compose = (middleware) => {
415
457
 
416
458
  const methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
417
459
  const isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
418
- class BaseService extends EventEmitter$2 {
419
- pluginOptionsList = {};
420
- middleware = {};
421
- constructor(methods) {
460
+ const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethodName, fn) => {
461
+ try {
462
+ let beforeArgs = args;
463
+ for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
464
+ let beforeReturnValue = await beforeMethod(...beforeArgs) || [];
465
+ if (isError(beforeReturnValue))
466
+ throw beforeReturnValue;
467
+ if (!Array.isArray(beforeReturnValue)) {
468
+ beforeReturnValue = [beforeReturnValue];
469
+ }
470
+ beforeArgs = beforeArgs.map((v, index) => {
471
+ if (typeof beforeReturnValue[index] === "undefined")
472
+ return v;
473
+ return beforeReturnValue[index];
474
+ });
475
+ }
476
+ let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
477
+ for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
478
+ returnValue = await afterMethod(returnValue, ...beforeArgs);
479
+ if (isError(returnValue))
480
+ throw returnValue;
481
+ }
482
+ return returnValue;
483
+ } catch (error) {
484
+ throw error;
485
+ }
486
+ };
487
+ class BaseService extends EventEmitter {
488
+ constructor(methods = [], serialMethods = []) {
422
489
  super();
490
+ this.pluginOptionsList = {};
491
+ this.middleware = {};
492
+ this.taskList = [];
493
+ this.doingTask = false;
423
494
  methods.forEach((propertyName) => {
424
495
  const scope = this;
425
496
  const sourceMethod = scope[propertyName];
@@ -431,27 +502,23 @@ class BaseService extends EventEmitter$2 {
431
502
  const fn = compose(this.middleware[propertyName]);
432
503
  Object.defineProperty(scope, propertyName, {
433
504
  value: async (...args) => {
434
- let beforeArgs = args;
435
- for (const beforeMethod of this.pluginOptionsList[beforeMethodName]) {
436
- let beforeReturnValue = await beforeMethod(...beforeArgs) || [];
437
- if (isError(beforeReturnValue))
438
- throw beforeReturnValue;
439
- if (!Array.isArray(beforeReturnValue)) {
440
- beforeReturnValue = [beforeReturnValue];
441
- }
442
- beforeArgs = beforeArgs.map((v, index) => {
443
- if (typeof beforeReturnValue[index] === "undefined")
444
- return v;
445
- return beforeReturnValue[index];
446
- });
505
+ if (!serialMethods.includes(propertyName)) {
506
+ return doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
447
507
  }
448
- let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
449
- for (const afterMethod of this.pluginOptionsList[afterMethodName]) {
450
- returnValue = await afterMethod(...beforeArgs, returnValue);
451
- if (isError(returnValue))
452
- throw returnValue;
508
+ const promise = new Promise((resolve, reject) => {
509
+ this.taskList.push(async () => {
510
+ try {
511
+ const value = await doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
512
+ resolve(value);
513
+ } catch (e) {
514
+ reject(e);
515
+ }
516
+ });
517
+ });
518
+ if (!this.doingTask) {
519
+ this.doTask();
453
520
  }
454
- return returnValue;
521
+ return promise;
455
522
  }
456
523
  });
457
524
  });
@@ -468,19 +535,34 @@ class BaseService extends EventEmitter$2 {
468
535
  this.pluginOptionsList[methodName2].push(method);
469
536
  });
470
537
  }
538
+ async doTask() {
539
+ this.doingTask = true;
540
+ let task = this.taskList.shift();
541
+ while (task) {
542
+ await task();
543
+ task = this.taskList.shift();
544
+ }
545
+ this.doingTask = false;
546
+ }
471
547
  }
472
548
 
473
549
  class History extends BaseService {
474
- state = reactive({
475
- pageSteps: {},
476
- pageId: void 0,
477
- canRedo: false,
478
- canUndo: false
479
- });
480
550
  constructor() {
481
551
  super([]);
552
+ this.state = reactive({
553
+ pageSteps: {},
554
+ pageId: void 0,
555
+ canRedo: false,
556
+ canUndo: false
557
+ });
482
558
  this.on("change", this.setCanUndoRedo);
483
559
  }
560
+ reset() {
561
+ this.state.pageSteps = {};
562
+ this.state.pageId = void 0;
563
+ this.state.canRedo = false;
564
+ this.state.canUndo = false;
565
+ }
484
566
  changePage(page) {
485
567
  if (!page)
486
568
  return;
@@ -544,12 +626,12 @@ class History extends BaseService {
544
626
  var historyService = new History();
545
627
 
546
628
  class Props extends BaseService {
547
- state = reactive({
548
- propsConfigMap: {},
549
- propsValueMap: {}
550
- });
551
629
  constructor() {
552
630
  super(["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue"]);
631
+ this.state = reactive({
632
+ propsConfigMap: {},
633
+ propsValueMap: {}
634
+ });
553
635
  }
554
636
  setPropsConfigs(configs) {
555
637
  Object.keys(configs).forEach((type) => {
@@ -574,7 +656,7 @@ class Props extends BaseService {
574
656
  setPropsValue(type, value) {
575
657
  this.state.propsValueMap[type] = value;
576
658
  }
577
- async getPropsValue(type) {
659
+ async getPropsValue(type, defaultValue = {}) {
578
660
  if (type === "area") {
579
661
  const value = await this.getPropsValue("button");
580
662
  value.className = "action-area";
@@ -586,7 +668,7 @@ class Props extends BaseService {
586
668
  }
587
669
  return cloneDeep({
588
670
  ...getDefaultPropsValue(type),
589
- ...this.state.propsValueMap[type] || {}
671
+ ...mergeWith(this.state.propsValueMap[type] || {}, defaultValue)
590
672
  });
591
673
  }
592
674
  }
@@ -613,7 +695,7 @@ const COPY_STORAGE_KEY = "$MagicEditorCopyData";
613
695
  const generateId = (type) => `${type}_${random(1e4, false)}`;
614
696
  const getPageList = (app) => {
615
697
  if (app.items && Array.isArray(app.items)) {
616
- return app.items.filter((item) => item.type === "page");
698
+ return app.items.filter((item) => item.type === NodeType.PAGE);
617
699
  }
618
700
  return [];
619
701
  };
@@ -647,9 +729,9 @@ const updatePopId = (oldId, popId, pageConfig) => {
647
729
  };
648
730
  const setNewItemId = (config, parent) => {
649
731
  const oldId = config.id;
650
- config.id = generateId(config.type);
732
+ config.id = generateId(config.type || "component");
651
733
  config.name = `${config.name?.replace(/_(\d+)$/, "")}_${config.id}`;
652
- if (isPop(config) && parent?.type === "page") {
734
+ if (isPop(config) && parent?.type === NodeType.PAGE) {
653
735
  updatePopId(oldId, config.id, parent);
654
736
  }
655
737
  if (config.items && Array.isArray(config.items)) {
@@ -670,11 +752,25 @@ const toRelative = (node) => {
670
752
  };
671
753
  return node;
672
754
  };
673
- const initPosition = (node, layout) => {
755
+ const setTop2Middle = (node, parentNode, stage) => {
756
+ const style = node.style || {};
757
+ const height = style.height || 0;
758
+ if (!stage || typeof style.top !== "undefined" || !parentNode.style || !isNumber(height))
759
+ return style;
760
+ const { height: parentHeight } = parentNode.style;
761
+ if (isPage(parentNode)) {
762
+ const { scrollTop = 0, wrapperHeight } = stage.mask;
763
+ style.top = (wrapperHeight - height) / 2 + scrollTop;
764
+ } else {
765
+ style.top = (parentHeight - height) / 2;
766
+ }
767
+ return style;
768
+ };
769
+ const initPosition = (node, layout, parentNode, stage) => {
674
770
  if (layout === Layout.ABSOLUTE) {
675
771
  node.style = {
676
772
  position: "absolute",
677
- ...node.style || {}
773
+ ...setTop2Middle(node, parentNode, stage)
678
774
  };
679
775
  return node;
680
776
  }
@@ -721,7 +817,9 @@ const Fixed2Other = async (node, root, getLayout) => {
721
817
  const cur = path.pop();
722
818
  const offset = {
723
819
  left: cur?.style?.left || 0,
724
- top: cur?.style?.top || 0
820
+ top: cur?.style?.top || 0,
821
+ right: "",
822
+ bottom: ""
725
823
  };
726
824
  path.forEach((value) => {
727
825
  offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
@@ -755,15 +853,6 @@ const error = (...args) => {
755
853
  };
756
854
 
757
855
  class Editor$1 extends BaseService {
758
- isHistoryStateChange = false;
759
- state = reactive({
760
- root: null,
761
- page: null,
762
- parent: null,
763
- node: null,
764
- stage: null,
765
- modifiedNodeIds: /* @__PURE__ */ new Map()
766
- });
767
856
  constructor() {
768
857
  super([
769
858
  "getLayout",
@@ -776,13 +865,27 @@ class Editor$1 extends BaseService {
776
865
  "paste",
777
866
  "alignCenter",
778
867
  "moveLayer",
868
+ "move",
779
869
  "undo",
780
- "redo"
781
- ]);
870
+ "redo",
871
+ "highlight"
872
+ ], ["select", "update", "moveLayer"]);
873
+ this.isHistoryStateChange = false;
874
+ this.state = reactive({
875
+ root: null,
876
+ page: null,
877
+ parent: null,
878
+ node: null,
879
+ stage: null,
880
+ highlightNode: null,
881
+ modifiedNodeIds: /* @__PURE__ */ new Map(),
882
+ pageLength: 0
883
+ });
782
884
  }
783
885
  set(name, value) {
784
886
  this.state[name] = value;
785
887
  if (name === "root") {
888
+ this.state.pageLength = value?.items?.length || 0;
786
889
  this.emit("root-change", value);
787
890
  }
788
891
  }
@@ -790,7 +893,7 @@ class Editor$1 extends BaseService {
790
893
  return this.state[name];
791
894
  }
792
895
  getNodeInfo(id) {
793
- const root = this.get("root");
896
+ const root = toRaw(this.get("root"));
794
897
  if (!root)
795
898
  return {};
796
899
  if (id === root.id) {
@@ -804,7 +907,7 @@ class Editor$1 extends BaseService {
804
907
  info.node = path[path.length - 1];
805
908
  info.parent = path[path.length - 2];
806
909
  path.forEach((item) => {
807
- if (item.type === "page") {
910
+ if (item.type === NodeType.PAGE) {
808
911
  info.page = item;
809
912
  return;
810
913
  }
@@ -821,31 +924,19 @@ class Editor$1 extends BaseService {
821
924
  const { parent } = this.getNodeInfo(id);
822
925
  return parent;
823
926
  }
824
- async getLayout(node) {
825
- if (node.layout) {
826
- return node.layout;
927
+ async getLayout(parent, node) {
928
+ if (node && typeof node !== "function" && isFixed(node))
929
+ return Layout.FIXED;
930
+ if (parent.layout) {
931
+ return parent.layout;
827
932
  }
828
- if (!node.style?.position) {
933
+ if (!parent.style?.position) {
829
934
  return Layout.RELATIVE;
830
935
  }
831
936
  return Layout.ABSOLUTE;
832
937
  }
833
938
  async select(config2) {
834
- let id;
835
- if (typeof config2 === "string" || typeof config2 === "number") {
836
- id = config2;
837
- } else {
838
- id = config2.id;
839
- }
840
- if (!id) {
841
- throw new Error("\u6CA1\u6709ID\uFF0C\u65E0\u6CD5\u9009\u4E2D");
842
- }
843
- const { node, parent, page } = this.getNodeInfo(id);
844
- if (!node)
845
- throw new Error("\u83B7\u53D6\u4E0D\u5230\u7EC4\u4EF6\u4FE1\u606F");
846
- if (node.id === this.state.root?.id) {
847
- throw new Error("\u4E0D\u80FD\u9009\u6839\u8282\u70B9");
848
- }
939
+ const { node, page, parent } = this.selectedConfigExceptionHandler(config2);
849
940
  this.set("node", node);
850
941
  this.set("page", page || null);
851
942
  this.set("parent", parent || null);
@@ -854,12 +945,44 @@ class Editor$1 extends BaseService {
854
945
  } else {
855
946
  historyService.empty();
856
947
  }
948
+ this.emit("select", node);
857
949
  return node;
858
950
  }
859
- async add({ type, ...config2 }, parent) {
951
+ async selectNextNode() {
952
+ const node = toRaw(this.get("node"));
953
+ if (!node || isPage(node) || node.type === NodeType.ROOT)
954
+ return node;
955
+ const parent = toRaw(this.getParentById(node.id));
956
+ if (!parent)
957
+ return node;
958
+ const index = getNodeIndex(node, parent);
959
+ const nextNode = parent.items[index + 1] || parent.items[0];
960
+ await this.select(nextNode);
961
+ this.get("stage")?.select(nextNode.id);
962
+ return nextNode;
963
+ }
964
+ async selectNextPage() {
965
+ const root = toRaw(this.get("root"));
966
+ const page = toRaw(this.get("page"));
967
+ const index = getNodeIndex(page, root);
968
+ const nextPage = root.items[index + 1] || root.items[0];
969
+ await this.select(nextPage);
970
+ this.get("stage")?.select(nextPage.id);
971
+ return nextPage;
972
+ }
973
+ highlight(config2) {
974
+ const { node } = this.selectedConfigExceptionHandler(config2);
975
+ const currentHighlightNode = this.get("highlightNode");
976
+ if (currentHighlightNode === node)
977
+ return;
978
+ this.set("highlightNode", node);
979
+ }
980
+ async add(addNode, parent) {
981
+ const { type, ...config2 } = addNode;
860
982
  const curNode = this.get("node");
861
983
  let parentNode;
862
- if (type === "page") {
984
+ const isPage2 = type === NodeType.PAGE;
985
+ if (isPage2) {
863
986
  parentNode = this.get("root");
864
987
  } else if (parent && typeof parent !== "function") {
865
988
  parentNode = parent;
@@ -870,16 +993,24 @@ class Editor$1 extends BaseService {
870
993
  }
871
994
  if (!parentNode)
872
995
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
873
- const layout = await this.getLayout(parentNode);
874
- const newNode = initPosition({ ...toRaw(await propsService.getPropsValue(type)), ...config2 }, layout);
875
- if ((parentNode?.type === "app" || curNode.type === "app") && newNode.type !== "page") {
996
+ const layout = await this.getLayout(toRaw(parentNode), addNode);
997
+ const newNode = initPosition({ ...toRaw(await propsService.getPropsValue(type, config2)) }, layout, parentNode, this.get("stage"));
998
+ if ((parentNode?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && newNode.type !== NodeType.PAGE) {
876
999
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
877
1000
  }
878
1001
  parentNode?.items?.push(newNode);
879
- await this.get("stage")?.add({ config: cloneDeep(newNode), root: cloneDeep(this.get("root")) });
1002
+ const stage = this.get("stage");
1003
+ await stage?.add({ config: cloneDeep(newNode), root: cloneDeep(this.get("root")) });
880
1004
  await this.select(newNode);
881
1005
  this.addModifiedNodeId(newNode.id);
882
- this.pushHistoryState();
1006
+ if (!isPage2) {
1007
+ this.pushHistoryState();
1008
+ }
1009
+ stage?.select(newNode.id);
1010
+ if (isPage2) {
1011
+ this.state.pageLength += 1;
1012
+ }
1013
+ this.emit("add", newNode);
883
1014
  return newNode;
884
1015
  }
885
1016
  async remove(node) {
@@ -895,14 +1026,31 @@ class Editor$1 extends BaseService {
895
1026
  if (typeof index !== "number" || index === -1)
896
1027
  throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
897
1028
  parent.items?.splice(index, 1);
898
- this.get("stage")?.remove({ id: node.id, root: this.get("root") });
899
- if (node.type === "page") {
900
- await this.select(root.items[0] || root);
1029
+ const stage = this.get("stage");
1030
+ stage?.remove({ id: node.id, root: this.get("root") });
1031
+ if (node.type === NodeType.PAGE) {
1032
+ this.state.pageLength -= 1;
1033
+ if (root.items[0]) {
1034
+ await this.select(root.items[0]);
1035
+ stage?.select(root.items[0].id);
1036
+ } else {
1037
+ this.set("node", null);
1038
+ this.set("parent", null);
1039
+ this.set("page", null);
1040
+ this.set("stage", null);
1041
+ this.set("highlightNode", null);
1042
+ this.resetModifiedNodeId();
1043
+ historyService.reset();
1044
+ this.emit("remove", node);
1045
+ return node;
1046
+ }
901
1047
  } else {
902
1048
  await this.select(parent);
1049
+ stage?.select(parent.id);
903
1050
  }
904
1051
  this.addModifiedNodeId(parent.id);
905
1052
  this.pushHistoryState();
1053
+ this.emit("remove", node);
906
1054
  return node;
907
1055
  }
908
1056
  async update(config2) {
@@ -920,7 +1068,7 @@ class Editor$1 extends BaseService {
920
1068
  });
921
1069
  if (!newConfig.type)
922
1070
  throw new Error("\u914D\u7F6E\u7F3A\u5C11type\u503C");
923
- if (newConfig.type === "app") {
1071
+ if (newConfig.type === NodeType.ROOT) {
924
1072
  this.set("root", newConfig);
925
1073
  return newConfig;
926
1074
  }
@@ -937,15 +1085,16 @@ class Editor$1 extends BaseService {
937
1085
  newConfig = setLayout(newConfig, newLayout);
938
1086
  }
939
1087
  parentNodeItems[index] = newConfig;
940
- if (newConfig.id === this.get("node").id) {
1088
+ if (`${newConfig.id}` === `${this.get("node").id}`) {
941
1089
  this.set("node", newConfig);
942
1090
  }
943
1091
  this.get("stage")?.update({ config: cloneDeep(newConfig), root: this.get("root") });
944
- if (newConfig.type === "page") {
1092
+ if (newConfig.type === NodeType.PAGE) {
945
1093
  this.set("page", newConfig);
946
1094
  }
947
1095
  this.addModifiedNodeId(newConfig.id);
948
1096
  this.pushHistoryState();
1097
+ this.emit("update", newConfig);
949
1098
  return newConfig;
950
1099
  }
951
1100
  async sort(id1, id2) {
@@ -989,7 +1138,7 @@ class Editor$1 extends BaseService {
989
1138
  async alignCenter(config2) {
990
1139
  const parent = this.get("parent");
991
1140
  const node = this.get("node");
992
- const layout = await this.getLayout(parent);
1141
+ const layout = await this.getLayout(toRaw(parent), toRaw(node));
993
1142
  if (layout === Layout.RELATIVE) {
994
1143
  return;
995
1144
  }
@@ -1026,6 +1175,26 @@ class Editor$1 extends BaseService {
1026
1175
  await this.changeHistoryState(value);
1027
1176
  return value;
1028
1177
  }
1178
+ async move(left, top) {
1179
+ const node = toRaw(this.get("node"));
1180
+ if (!node || isPage(node))
1181
+ return;
1182
+ const { style, id } = node;
1183
+ if (!style || style.position !== "absolute")
1184
+ return;
1185
+ if (top && !isNumber(style.top))
1186
+ return;
1187
+ if (left && !isNumber(style.left))
1188
+ return;
1189
+ this.update({
1190
+ id,
1191
+ style: {
1192
+ ...style,
1193
+ left: Number(style.left) + left,
1194
+ top: Number(style.top) + top
1195
+ }
1196
+ });
1197
+ }
1029
1198
  destroy() {
1030
1199
  this.removeAllListeners();
1031
1200
  this.set("root", null);
@@ -1058,7 +1227,12 @@ class Editor$1 extends BaseService {
1058
1227
  this.isHistoryStateChange = true;
1059
1228
  await this.update(value.data);
1060
1229
  this.set("modifiedNodeIds", value.modifiedNodeIds);
1061
- setTimeout(() => value.nodeId && this.select(value.nodeId), 0);
1230
+ setTimeout(async () => {
1231
+ if (!value.nodeId)
1232
+ return;
1233
+ await this.select(value.nodeId);
1234
+ this.get("stage")?.select(value.nodeId);
1235
+ }, 0);
1062
1236
  }
1063
1237
  async toggleFixedPosition(dist, src, root) {
1064
1238
  let newConfig = cloneDeep(dist);
@@ -1071,6 +1245,28 @@ class Editor$1 extends BaseService {
1071
1245
  }
1072
1246
  return newConfig;
1073
1247
  }
1248
+ selectedConfigExceptionHandler(config2) {
1249
+ let id;
1250
+ if (typeof config2 === "string" || typeof config2 === "number") {
1251
+ id = config2;
1252
+ } else {
1253
+ id = config2.id;
1254
+ }
1255
+ if (!id) {
1256
+ throw new Error("\u6CA1\u6709ID\uFF0C\u65E0\u6CD5\u9009\u4E2D");
1257
+ }
1258
+ const { node, parent, page } = this.getNodeInfo(id);
1259
+ if (!node)
1260
+ throw new Error("\u83B7\u53D6\u4E0D\u5230\u7EC4\u4EF6\u4FE1\u606F");
1261
+ if (node.id === this.state.root?.id) {
1262
+ throw new Error("\u4E0D\u80FD\u9009\u6839\u8282\u70B9");
1263
+ }
1264
+ return {
1265
+ node,
1266
+ parent,
1267
+ page
1268
+ };
1269
+ }
1074
1270
  }
1075
1271
  var editorService = new Editor$1();
1076
1272
 
@@ -1228,6 +1424,25 @@ const fillConfig = (config = []) => [
1228
1424
  defaultValue: "100% 100%"
1229
1425
  }
1230
1426
  ]
1427
+ },
1428
+ {
1429
+ type: "fieldset",
1430
+ legend: "\u5B57\u4F53",
1431
+ items: [
1432
+ {
1433
+ name: "color",
1434
+ text: "\u989C\u8272",
1435
+ type: "colorPicker"
1436
+ },
1437
+ {
1438
+ name: "fontSize",
1439
+ text: "\u5927\u5C0F"
1440
+ },
1441
+ {
1442
+ name: "fontWeight",
1443
+ text: "\u7C97\u7EC6"
1444
+ }
1445
+ ]
1231
1446
  }
1232
1447
  ]
1233
1448
  }
@@ -1260,7 +1475,7 @@ const fillConfig = (config = []) => [
1260
1475
  type: "select",
1261
1476
  options: (mForm, { model }) => {
1262
1477
  const node = editorService.getNodeById(model.to);
1263
- if (!node)
1478
+ if (!node?.type)
1264
1479
  return [];
1265
1480
  return eventsService.getMethod(node.type).map((option) => ({
1266
1481
  text: option.label,
@@ -1295,7 +1510,7 @@ const getDefaultPropsValue = (type) => ({
1295
1510
  name: type
1296
1511
  });
1297
1512
 
1298
- const _sfc_main$g = defineComponent({
1513
+ const _sfc_main$i = defineComponent({
1299
1514
  components: { Plus },
1300
1515
  setup() {
1301
1516
  const services = inject("services");
@@ -1305,21 +1520,21 @@ const _sfc_main$g = defineComponent({
1305
1520
  if (!editorService)
1306
1521
  return;
1307
1522
  editorService.add({
1308
- type: "page",
1523
+ type: NodeType.PAGE,
1309
1524
  name: generatePageNameByApp(toRaw(editorService.get("root")))
1310
1525
  });
1311
1526
  }
1312
1527
  };
1313
1528
  }
1314
1529
  });
1315
- const _hoisted_1$b = { class: "m-editor-empty-panel" };
1316
- const _hoisted_2$6 = { class: "m-editor-empty-content" };
1317
- const _hoisted_3$4 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1318
- function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
1530
+ const _hoisted_1$a = { class: "m-editor-empty-panel" };
1531
+ const _hoisted_2$4 = { class: "m-editor-empty-content" };
1532
+ const _hoisted_3$2 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1533
+ function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
1319
1534
  const _component_plus = resolveComponent("plus");
1320
1535
  const _component_el_icon = resolveComponent("el-icon");
1321
- return openBlock(), createElementBlock("div", _hoisted_1$b, [
1322
- createElementVNode("div", _hoisted_2$6, [
1536
+ return openBlock(), createElementBlock("div", _hoisted_1$a, [
1537
+ createElementVNode("div", _hoisted_2$4, [
1323
1538
  createElementVNode("div", {
1324
1539
  class: "m-editor-empty-button",
1325
1540
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
@@ -1332,1274 +1547,114 @@ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
1332
1547
  _: 1
1333
1548
  })
1334
1549
  ]),
1335
- _hoisted_3$4
1550
+ _hoisted_3$2
1336
1551
  ])
1337
1552
  ])
1338
1553
  ]);
1339
1554
  }
1340
- var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
1341
-
1342
- /*
1343
- Copyright (c) 2018 Daybrush
1344
- @name: @daybrush/utils
1345
- license: MIT
1346
- author: Daybrush
1347
- repository: https://github.com/daybrush/utils
1348
- @version 1.6.0
1349
- */
1350
- /**
1351
- * get string "object"
1352
- * @memberof Consts
1353
- * @example
1354
- import {OBJECT} from "@daybrush/utils";
1355
-
1356
- console.log(OBJECT); // "object"
1357
- */
1358
-
1359
- var OBJECT = "object";
1360
- /**
1361
- * Check the type that the value is object.
1362
- * @memberof Utils
1363
- * @param {string} value - Value to check the type
1364
- * @return {} true if the type is correct, false otherwise
1365
- * @example
1366
- import {isObject} from "@daybrush/utils";
1367
-
1368
- console.log(isObject({})); // true
1369
- console.log(isObject(undefined)); // false
1370
- console.log(isObject("")); // false
1371
- console.log(isObject(null)); // false
1372
- */
1373
-
1374
- function isObject(value) {
1375
- return value && typeof value === OBJECT;
1376
- }
1377
- /**
1378
- * Date.now() method
1379
- * @memberof CrossBrowser
1380
- * @return {number} milliseconds
1381
- * @example
1382
- import {now} from "@daybrush/utils";
1383
-
1384
- console.log(now()); // 12121324241(milliseconds)
1385
- */
1386
-
1387
- function now() {
1388
- return Date.now ? Date.now() : new Date().getTime();
1389
- }
1390
- /**
1391
- * Returns the index of the first element in the array that satisfies the provided testing function.
1392
- * @function
1393
- * @memberof CrossBrowser
1394
- * @param - The array `findIndex` was called upon.
1395
- * @param - A function to execute on each value in the array until the function returns true, indicating that the satisfying element was found.
1396
- * @param - Returns defaultIndex if not found by the function.
1397
- * @example
1398
- import { findIndex } from "@daybrush/utils";
1555
+ var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
1399
1556
 
1400
- findIndex([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // 1
1401
- */
1402
-
1403
- function findIndex(arr, callback, defaultIndex) {
1404
- if (defaultIndex === void 0) {
1405
- defaultIndex = -1;
1406
- }
1407
-
1408
- var length = arr.length;
1409
-
1410
- for (var i = 0; i < length; ++i) {
1411
- if (callback(arr[i], i, arr)) {
1412
- return i;
1557
+ const _sfc_main$h = defineComponent({
1558
+ name: "m-editor-resize",
1559
+ props: {
1560
+ type: {
1561
+ type: String
1413
1562
  }
1563
+ },
1564
+ setup(props) {
1565
+ const services = inject("services");
1566
+ const target = ref();
1567
+ let getso;
1568
+ onMounted(() => {
1569
+ if (!target.value)
1570
+ return;
1571
+ getso = new Gesto(target.value, {
1572
+ container: window,
1573
+ pinchOutside: true
1574
+ }).on("drag", (e) => {
1575
+ if (!target.value || !services)
1576
+ return;
1577
+ let { left, right } = {
1578
+ ...toRaw(services.uiService.get("columnWidth"))
1579
+ };
1580
+ if (props.type === "left") {
1581
+ left += e.deltaX;
1582
+ } else if (props.type === "right") {
1583
+ right -= e.deltaX;
1584
+ }
1585
+ services.uiService.set("columnWidth", {
1586
+ left,
1587
+ right
1588
+ });
1589
+ });
1590
+ });
1591
+ onUnmounted(() => {
1592
+ getso?.unset();
1593
+ });
1594
+ return {
1595
+ target
1596
+ };
1414
1597
  }
1415
-
1416
- return defaultIndex;
1417
- }
1418
- /**
1419
- * Sets up a function that will be called whenever the specified event is delivered to the target
1420
- * @memberof DOM
1421
- * @param - event target
1422
- * @param - A case-sensitive string representing the event type to listen for.
1423
- * @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs
1424
- * @param - An options object that specifies characteristics about the event listener.
1425
- * @example
1426
- import {addEvent} from "@daybrush/utils";
1427
-
1428
- addEvent(el, "click", e => {
1429
- console.log(e);
1430
1598
  });
1431
- */
1432
-
1433
- function addEvent(el, type, listener, options) {
1434
- el.addEventListener(type, listener, options);
1435
- }
1436
- /**
1437
- * removes from the EventTarget an event listener previously registered with EventTarget.addEventListener()
1438
- * @memberof DOM
1439
- * @param - event target
1440
- * @param - A case-sensitive string representing the event type to listen for.
1441
- * @param - The EventListener function of the event handler to remove from the event target.
1442
- * @param - An options object that specifies characteristics about the event listener.
1443
- * @example
1444
- import {addEvent, removeEvent} from "@daybrush/utils";
1445
- const listener = e => {
1446
- console.log(e);
1447
- };
1448
- addEvent(el, "click", listener);
1449
- removeEvent(el, "click", listener);
1450
- */
1451
-
1452
- function removeEvent(el, type, listener, options) {
1453
- el.removeEventListener(type, listener, options);
1454
- }
1455
-
1456
- /*
1457
- Copyright (c) 2019 Daybrush
1458
- name: @scena/event-emitter
1459
- license: MIT
1460
- author: Daybrush
1461
- repository: git+https://github.com/daybrush/gesture.git
1462
- version: 1.0.5
1463
- */
1464
-
1465
- /*! *****************************************************************************
1466
- Copyright (c) Microsoft Corporation.
1467
-
1468
- Permission to use, copy, modify, and/or distribute this software for any
1469
- purpose with or without fee is hereby granted.
1470
-
1471
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1472
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1473
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1474
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1475
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1476
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1477
- PERFORMANCE OF THIS SOFTWARE.
1478
- ***************************************************************************** */
1479
- var __assign$1 = function () {
1480
- __assign$1 = Object.assign || function __assign(t) {
1481
- for (var s, i = 1, n = arguments.length; i < n; i++) {
1482
- s = arguments[i];
1483
-
1484
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1485
- }
1486
-
1487
- return t;
1488
- };
1489
-
1490
- return __assign$1.apply(this, arguments);
1599
+ const _hoisted_1$9 = {
1600
+ ref: "target",
1601
+ class: "m-editor-resizer"
1491
1602
  };
1492
- function __spreadArrays() {
1493
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1494
-
1495
- for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
1496
-
1497
- return r;
1603
+ function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
1604
+ return openBlock(), createElementBlock("span", _hoisted_1$9, [
1605
+ renderSlot(_ctx.$slots, "default")
1606
+ ], 512);
1498
1607
  }
1608
+ var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
1499
1609
 
1500
- /**
1501
- * Implement EventEmitter on object or component.
1502
- */
1503
-
1504
- var EventEmitter =
1505
- /*#__PURE__*/
1506
- function () {
1507
- function EventEmitter() {
1508
- this._events = {};
1509
- }
1510
- /**
1511
- * Add a listener to the registered event.
1512
- * @param - Name of the event to be added
1513
- * @param - listener function of the event to be added
1514
- * @example
1515
- * import EventEmitter from "@scena/event-emitter";
1516
- * cosnt emitter = new EventEmitter();
1517
- *
1518
- * // Add listener in "a" event
1519
- * emitter.on("a", () => {
1520
- * });
1521
- * // Add listeners
1522
- * emitter.on({
1523
- * a: () => {},
1524
- * b: () => {},
1525
- * });
1526
- */
1527
-
1528
-
1529
- var __proto = EventEmitter.prototype;
1530
-
1531
- __proto.on = function (eventName, listener) {
1532
- if (isObject(eventName)) {
1533
- for (var name in eventName) {
1534
- this.on(name, eventName[name]);
1535
- }
1536
- } else {
1537
- this._addEvent(eventName, listener, {});
1610
+ const _sfc_main$g = defineComponent({
1611
+ components: {
1612
+ AddPageBox,
1613
+ Resizer
1614
+ },
1615
+ props: {
1616
+ codeOptions: {
1617
+ type: Object,
1618
+ default: () => ({})
1538
1619
  }
1539
-
1540
- return this;
1541
- };
1542
- /**
1543
- * Remove listeners registered in the event target.
1544
- * @param - Name of the event to be removed
1545
- * @param - listener function of the event to be removed
1546
- * @example
1547
- * import EventEmitter from "@scena/event-emitter";
1548
- * cosnt emitter = new EventEmitter();
1549
- *
1550
- * // Remove all listeners.
1551
- * emitter.off();
1552
- *
1553
- * // Remove all listeners in "A" event.
1554
- * emitter.off("a");
1555
- *
1556
- *
1557
- * // Remove "listener" listener in "a" event.
1558
- * emitter.off("a", listener);
1559
- */
1560
-
1561
-
1562
- __proto.off = function (eventName, listener) {
1563
- if (!eventName) {
1564
- this._events = {};
1565
- } else if (isObject(eventName)) {
1566
- for (var name in eventName) {
1567
- this.off(name);
1568
- }
1569
- } else if (!listener) {
1570
- this._events[eventName] = [];
1571
- } else {
1572
- var events = this._events[eventName];
1573
-
1574
- if (events) {
1575
- var index = findIndex(events, function (e) {
1576
- return e.listener === listener;
1577
- });
1578
-
1579
- if (index > -1) {
1580
- events.splice(index, 1);
1581
- }
1582
- }
1583
- }
1584
-
1585
- return this;
1586
- };
1587
- /**
1588
- * Add a disposable listener and Use promise to the registered event.
1589
- * @param - Name of the event to be added
1590
- * @param - disposable listener function of the event to be added
1591
- * @example
1592
- * import EventEmitter from "@scena/event-emitter";
1593
- * cosnt emitter = new EventEmitter();
1594
- *
1595
- * // Add a disposable listener in "a" event
1596
- * emitter.once("a", () => {
1597
- * });
1598
- *
1599
- * // Use Promise
1600
- * emitter.once("a").then(e => {
1601
- * });
1602
- */
1603
-
1604
-
1605
- __proto.once = function (eventName, listener) {
1606
- var _this = this;
1607
-
1608
- if (listener) {
1609
- this._addEvent(eventName, listener, {
1610
- once: true
1611
- });
1612
- }
1613
-
1614
- return new Promise(function (resolve) {
1615
- _this._addEvent(eventName, resolve, {
1616
- once: true
1617
- });
1618
- });
1619
- };
1620
- /**
1621
- * Fires an event to call listeners.
1622
- * @param - Event name
1623
- * @param - Event parameter
1624
- * @return If false, stop the event.
1625
- * @example
1626
- *
1627
- * import EventEmitter from "@scena/event-emitter";
1628
- *
1629
- *
1630
- * const emitter = new EventEmitter();
1631
- *
1632
- * emitter.on("a", e => {
1633
- * });
1634
- *
1635
- *
1636
- * emitter.emit("a", {
1637
- * a: 1,
1638
- * });
1639
- */
1640
-
1641
-
1642
- __proto.emit = function (eventName, param) {
1643
- var _this = this;
1644
-
1645
- if (param === void 0) {
1646
- param = {};
1647
- }
1648
-
1649
- var events = this._events[eventName];
1650
-
1651
- if (!eventName || !events) {
1652
- return true;
1653
- }
1654
-
1655
- var isStop = false;
1656
- param.eventType = eventName;
1657
-
1658
- param.stop = function () {
1659
- isStop = true;
1660
- };
1661
-
1662
- param.currentTarget = this;
1663
-
1664
- __spreadArrays(events).forEach(function (info) {
1665
- info.listener(param);
1666
-
1667
- if (info.once) {
1668
- _this.off(eventName, info.listener);
1669
- }
1670
- });
1671
-
1672
- return !isStop;
1673
- };
1674
- /**
1675
- * Fires an event to call listeners.
1676
- * @param - Event name
1677
- * @param - Event parameter
1678
- * @return If false, stop the event.
1679
- * @example
1680
- *
1681
- * import EventEmitter from "@scena/event-emitter";
1682
- *
1683
- *
1684
- * const emitter = new EventEmitter();
1685
- *
1686
- * emitter.on("a", e => {
1687
- * });
1688
- *
1689
- *
1690
- * emitter.emit("a", {
1691
- * a: 1,
1692
- * });
1693
- */
1694
-
1695
- /**
1696
- * Fires an event to call listeners.
1697
- * @param - Event name
1698
- * @param - Event parameter
1699
- * @return If false, stop the event.
1700
- * @example
1701
- *
1702
- * import EventEmitter from "@scena/event-emitter";
1703
- *
1704
- *
1705
- * const emitter = new EventEmitter();
1706
- *
1707
- * emitter.on("a", e => {
1708
- * });
1709
- *
1710
- * // emit
1711
- * emitter.trigger("a", {
1712
- * a: 1,
1713
- * });
1714
- */
1715
-
1716
-
1717
- __proto.trigger = function (eventName, param) {
1718
- if (param === void 0) {
1719
- param = {};
1720
- }
1721
-
1722
- return this.emit(eventName, param);
1723
- };
1724
-
1725
- __proto._addEvent = function (eventName, listener, options) {
1726
- var events = this._events;
1727
- events[eventName] = events[eventName] || [];
1728
- var listeners = events[eventName];
1729
- listeners.push(__assign$1({
1730
- listener: listener
1731
- }, options));
1732
- };
1733
-
1734
- return EventEmitter;
1735
- }();
1736
-
1737
- var EventEmitter$1 = EventEmitter;
1738
-
1739
- /*
1740
- Copyright (c) 2019 Daybrush
1741
- name: gesto
1742
- license: MIT
1743
- author: Daybrush
1744
- repository: git+https://github.com/daybrush/gesture.git
1745
- version: 1.5.0
1746
- */
1747
-
1748
- /*! *****************************************************************************
1749
- Copyright (c) Microsoft Corporation. All rights reserved.
1750
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
1751
- this file except in compliance with the License. You may obtain a copy of the
1752
- License at http://www.apache.org/licenses/LICENSE-2.0
1753
-
1754
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1755
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
1756
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
1757
- MERCHANTABLITY OR NON-INFRINGEMENT.
1758
-
1759
- See the Apache Version 2.0 License for specific language governing permissions
1760
- and limitations under the License.
1761
- ***************************************************************************** */
1762
-
1763
- /* global Reflect, Promise */
1764
- var extendStatics = function (d, b) {
1765
- extendStatics = Object.setPrototypeOf || {
1766
- __proto__: []
1767
- } instanceof Array && function (d, b) {
1768
- d.__proto__ = b;
1769
- } || function (d, b) {
1770
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1771
- };
1772
-
1773
- return extendStatics(d, b);
1774
- };
1775
-
1776
- function __extends(d, b) {
1777
- extendStatics(d, b);
1778
-
1779
- function __() {
1780
- this.constructor = d;
1781
- }
1782
-
1783
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1784
- }
1785
- var __assign = function () {
1786
- __assign = Object.assign || function __assign(t) {
1787
- for (var s, i = 1, n = arguments.length; i < n; i++) {
1788
- s = arguments[i];
1789
-
1790
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1791
- }
1792
-
1793
- return t;
1794
- };
1795
-
1796
- return __assign.apply(this, arguments);
1797
- };
1798
-
1799
- function getRad(pos1, pos2) {
1800
- var distX = pos2[0] - pos1[0];
1801
- var distY = pos2[1] - pos1[1];
1802
- var rad = Math.atan2(distY, distX);
1803
- return rad >= 0 ? rad : rad + Math.PI * 2;
1804
- }
1805
- function getRotatiion(touches) {
1806
- return getRad([touches[0].clientX, touches[0].clientY], [touches[1].clientX, touches[1].clientY]) / Math.PI * 180;
1807
- }
1808
- function isMultiTouch(e) {
1809
- return e.touches && e.touches.length >= 2;
1810
- }
1811
- function getEventClients(e) {
1812
- if (e.touches) {
1813
- return getClients(e.touches);
1814
- } else {
1815
- return [getClient(e)];
1816
- }
1817
- }
1818
- function getPosition(clients, prevClients, startClients) {
1819
- var length = startClients.length;
1820
-
1821
- var _a = getAverageClient(clients, length),
1822
- clientX = _a.clientX,
1823
- clientY = _a.clientY,
1824
- originalClientX = _a.originalClientX,
1825
- originalClientY = _a.originalClientY;
1826
-
1827
- var _b = getAverageClient(prevClients, length),
1828
- prevX = _b.clientX,
1829
- prevY = _b.clientY;
1830
-
1831
- var _c = getAverageClient(startClients, length),
1832
- startX = _c.clientX,
1833
- startY = _c.clientY;
1834
-
1835
- var deltaX = clientX - prevX;
1836
- var deltaY = clientY - prevY;
1837
- var distX = clientX - startX;
1838
- var distY = clientY - startY;
1839
- return {
1840
- clientX: originalClientX,
1841
- clientY: originalClientY,
1842
- deltaX: deltaX,
1843
- deltaY: deltaY,
1844
- distX: distX,
1845
- distY: distY
1846
- };
1847
- }
1848
- function getDist(clients) {
1849
- return Math.sqrt(Math.pow(clients[0].clientX - clients[1].clientX, 2) + Math.pow(clients[0].clientY - clients[1].clientY, 2));
1850
- }
1851
- function getClients(touches) {
1852
- var length = Math.min(touches.length, 2);
1853
- var clients = [];
1854
-
1855
- for (var i = 0; i < length; ++i) {
1856
- clients.push(getClient(touches[i]));
1857
- }
1858
-
1859
- return clients;
1860
- }
1861
- function getClient(e) {
1862
- return {
1863
- clientX: e.clientX,
1864
- clientY: e.clientY
1865
- };
1866
- }
1867
- function getAverageClient(clients, length) {
1868
- if (length === void 0) {
1869
- length = clients.length;
1870
- }
1871
-
1872
- var sumClient = {
1873
- clientX: 0,
1874
- clientY: 0,
1875
- originalClientX: 0,
1876
- originalClientY: 0
1877
- };
1878
-
1879
- for (var i = 0; i < length; ++i) {
1880
- var client = clients[i];
1881
- sumClient.originalClientX += "originalClientX" in client ? client.originalClientX : client.clientX;
1882
- sumClient.originalClientY += "originalClientY" in client ? client.originalClientY : client.clientY;
1883
- sumClient.clientX += client.clientX;
1884
- sumClient.clientY += client.clientY;
1885
- }
1886
-
1887
- if (!length) {
1888
- return sumClient;
1889
- }
1890
-
1891
- return {
1892
- clientX: sumClient.clientX / length,
1893
- clientY: sumClient.clientY / length,
1894
- originalClientX: sumClient.originalClientX / length,
1895
- originalClientY: sumClient.originalClientY / length
1896
- };
1897
- }
1898
-
1899
- var ClientStore =
1900
- /*#__PURE__*/
1901
- function () {
1902
- function ClientStore(clients) {
1903
- this.prevClients = [];
1904
- this.startClients = [];
1905
- this.movement = 0;
1906
- this.length = 0;
1907
- this.startClients = clients;
1908
- this.prevClients = clients;
1909
- this.length = clients.length;
1910
- }
1911
-
1912
- var __proto = ClientStore.prototype;
1913
-
1914
- __proto.addClients = function (clients) {
1915
- if (clients === void 0) {
1916
- clients = this.prevClients;
1917
- }
1918
-
1919
- var position = this.getPosition(clients);
1920
- var deltaX = position.deltaX,
1921
- deltaY = position.deltaY;
1922
- this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
1923
- this.prevClients = clients;
1924
- return position;
1925
- };
1926
-
1927
- __proto.getAngle = function (clients) {
1928
- if (clients === void 0) {
1929
- clients = this.prevClients;
1930
- }
1931
-
1932
- return getRotatiion(clients);
1933
- };
1934
-
1935
- __proto.getRotation = function (clients) {
1936
- if (clients === void 0) {
1937
- clients = this.prevClients;
1938
- }
1939
-
1940
- return getRotatiion(clients) - getRotatiion(this.startClients);
1941
- };
1942
-
1943
- __proto.getPosition = function (clients) {
1944
- return getPosition(clients || this.prevClients, this.prevClients, this.startClients);
1945
- };
1946
-
1947
- __proto.getPositions = function (clients) {
1948
- if (clients === void 0) {
1949
- clients = this.prevClients;
1950
- }
1951
-
1952
- var prevClients = this.prevClients;
1953
- return this.startClients.map(function (startClient, i) {
1954
- return getPosition([clients[i]], [prevClients[i]], [startClient]);
1955
- });
1956
- };
1957
-
1958
- __proto.getMovement = function (clients) {
1959
- var movement = this.movement;
1960
-
1961
- if (!clients) {
1962
- return movement;
1963
- }
1964
-
1965
- var currentClient = getAverageClient(clients, this.length);
1966
- var prevClient = getAverageClient(this.prevClients, this.length);
1967
- var deltaX = currentClient.clientX - prevClient.clientX;
1968
- var deltaY = currentClient.clientY - prevClient.clientY;
1969
- return Math.sqrt(deltaX * deltaX + deltaY * deltaY) + movement;
1970
- };
1971
-
1972
- __proto.getDistance = function (clients) {
1973
- if (clients === void 0) {
1974
- clients = this.prevClients;
1975
- }
1976
-
1977
- return getDist(clients);
1978
- };
1979
-
1980
- __proto.getScale = function (clients) {
1981
- if (clients === void 0) {
1982
- clients = this.prevClients;
1983
- }
1984
-
1985
- return getDist(clients) / getDist(this.startClients);
1986
- };
1987
-
1988
- __proto.move = function (deltaX, deltaY) {
1989
- this.startClients.forEach(function (client) {
1990
- client.clientX -= deltaX;
1991
- client.clientY -= deltaY;
1992
- });
1993
- this.prevClients.forEach(function (client) {
1994
- client.clientX -= deltaX;
1995
- client.clientY -= deltaY;
1996
- });
1997
- };
1998
-
1999
- return ClientStore;
2000
- }();
2001
-
2002
- var INPUT_TAGNAMES = ["textarea", "input"];
2003
- /**
2004
- * You can set up drag, pinch events in any browser.
2005
- */
2006
-
2007
- var Gesto =
2008
- /*#__PURE__*/
2009
- function (_super) {
2010
- __extends(Gesto, _super);
2011
- /**
2012
- *
2013
- */
2014
-
2015
-
2016
- function Gesto(targets, options) {
2017
- if (options === void 0) {
2018
- options = {};
2019
- }
2020
-
2021
- var _this = _super.call(this) || this;
2022
-
2023
- _this.options = {};
2024
- _this.flag = false;
2025
- _this.pinchFlag = false;
2026
- _this.datas = {};
2027
- _this.isDrag = false;
2028
- _this.isPinch = false;
2029
- _this.isMouse = false;
2030
- _this.isTouch = false;
2031
- _this.clientStores = [];
2032
- _this.targets = [];
2033
- _this.prevTime = 0;
2034
- _this.doubleFlag = false;
2035
-
2036
- _this.onDragStart = function (e, isTrusted) {
2037
- if (isTrusted === void 0) {
2038
- isTrusted = true;
2039
- }
2040
-
2041
- if (!_this.flag && e.cancelable === false) {
2042
- return;
2043
- }
2044
-
2045
- var _a = _this.options,
2046
- container = _a.container,
2047
- pinchOutside = _a.pinchOutside,
2048
- preventRightClick = _a.preventRightClick,
2049
- preventDefault = _a.preventDefault,
2050
- checkInput = _a.checkInput;
2051
- var isTouch = _this.isTouch;
2052
- var isDragStart = !_this.flag;
2053
-
2054
- if (isDragStart) {
2055
- var activeElement = document.activeElement;
2056
- var target = e.target;
2057
- var tagName = target.tagName.toLowerCase();
2058
- var hasInput = INPUT_TAGNAMES.indexOf(tagName) > -1;
2059
- var hasContentEditable = target.isContentEditable;
2060
-
2061
- if (hasInput || hasContentEditable) {
2062
- if (checkInput || activeElement === target) {
2063
- // force false or already focused.
2064
- return false;
2065
- }
2066
-
2067
- if (activeElement && hasContentEditable && activeElement.isContentEditable && activeElement.contains(target)) {
2068
- return false;
2069
- }
2070
- } else if ((preventDefault || e.type === "touchstart") && activeElement) {
2071
- var activeTagName = activeElement.tagName;
2072
-
2073
- if (activeElement.isContentEditable || INPUT_TAGNAMES.indexOf(activeTagName) > -1) {
2074
- activeElement.blur();
2075
- }
2076
- }
2077
-
2078
- _this.clientStores = [new ClientStore(getEventClients(e))];
2079
- _this.flag = true;
2080
- _this.isDrag = false;
2081
- _this.datas = {};
2082
-
2083
- if (preventRightClick && (e.which === 3 || e.button === 2)) {
2084
- _this.initDrag();
2085
-
2086
- return false;
2087
- }
2088
-
2089
- _this.doubleFlag = now() - _this.prevTime < 200;
2090
-
2091
- var result = _this.emit("dragStart", __assign({
2092
- datas: _this.datas,
2093
- inputEvent: e,
2094
- isTrusted: isTrusted,
2095
- isDouble: _this.doubleFlag
2096
- }, _this.getCurrentStore().getPosition()));
2097
-
2098
- if (result === false) {
2099
- _this.initDrag();
2100
- }
2101
-
2102
- _this.flag && preventDefault && e.preventDefault();
2103
- }
2104
-
2105
- if (!_this.flag) {
2106
- return false;
2107
- }
2108
-
2109
- var timer = 0;
2110
-
2111
- if (isDragStart && isTouch && pinchOutside) {
2112
- timer = setTimeout(function () {
2113
- addEvent(container, "touchstart", _this.onDragStart, {
2114
- passive: false
2115
- });
2116
- });
2117
- }
2118
-
2119
- if (!isDragStart && isTouch && pinchOutside) {
2120
- removeEvent(container, "touchstart", _this.onDragStart);
2121
- }
2122
-
2123
- if (_this.flag && isMultiTouch(e)) {
2124
- clearTimeout(timer);
2125
-
2126
- if (isDragStart && e.touches.length !== e.changedTouches.length) {
2127
- return;
2128
- }
2129
-
2130
- if (!_this.pinchFlag) {
2131
- _this.onPinchStart(e);
2132
- }
2133
- }
2134
- };
2135
-
2136
- _this.onDrag = function (e, isScroll) {
2137
- if (!_this.flag) {
2138
- return;
2139
- }
2140
-
2141
- var clients = getEventClients(e);
2142
-
2143
- var result = _this.moveClients(clients, e, false);
2144
-
2145
- if (_this.pinchFlag || result.deltaX || result.deltaY) {
2146
- var dragResult = _this.emit("drag", __assign({}, result, {
2147
- isScroll: !!isScroll,
2148
- inputEvent: e
2149
- }));
2150
-
2151
- if (dragResult === false) {
2152
- _this.stop();
2153
-
2154
- return;
2155
- }
2156
- }
2157
-
2158
- if (_this.pinchFlag) {
2159
- _this.onPinch(e, clients);
2160
- }
2161
-
2162
- _this.getCurrentStore().addClients(clients);
2163
- };
2164
-
2165
- _this.onDragEnd = function (e) {
2166
- if (!_this.flag) {
2167
- return;
2168
- }
2169
-
2170
- var _a = _this.options,
2171
- pinchOutside = _a.pinchOutside,
2172
- container = _a.container;
2173
-
2174
- if (_this.isTouch && pinchOutside) {
2175
- removeEvent(container, "touchstart", _this.onDragStart);
2176
- }
2177
-
2178
- _this.flag = false;
2179
-
2180
- var position = _this.getCurrentStore().getPosition();
2181
-
2182
- var currentTime = now();
2183
- var isDouble = !_this.isDrag && _this.doubleFlag;
2184
- _this.prevTime = _this.isDrag || isDouble ? 0 : currentTime;
2185
-
2186
- _this.emit("dragEnd", __assign({
2187
- datas: _this.datas,
2188
- isDouble: isDouble,
2189
- isDrag: _this.isDrag,
2190
- isClick: !_this.isDrag,
2191
- inputEvent: e
2192
- }, position));
2193
-
2194
- if (_this.pinchFlag) {
2195
- _this.onPinchEnd(e);
2196
- }
2197
-
2198
- _this.clientStores = [];
2199
- };
2200
-
2201
- _this.onBlur = function () {
2202
- _this.onDragEnd();
2203
- };
2204
-
2205
- var elements = [].concat(targets);
2206
- _this.options = __assign({
2207
- checkInput: false,
2208
- container: elements.length > 1 ? window : elements[0],
2209
- preventRightClick: true,
2210
- preventDefault: true,
2211
- checkWindowBlur: false,
2212
- pinchThreshold: 0,
2213
- events: ["touch", "mouse"]
2214
- }, options);
2215
- var _a = _this.options,
2216
- container = _a.container,
2217
- events = _a.events,
2218
- checkWindowBlur = _a.checkWindowBlur;
2219
- _this.isTouch = events.indexOf("touch") > -1;
2220
- _this.isMouse = events.indexOf("mouse") > -1;
2221
- _this.targets = elements;
2222
-
2223
- if (_this.isMouse) {
2224
- elements.forEach(function (el) {
2225
- addEvent(el, "mousedown", _this.onDragStart);
2226
- });
2227
- addEvent(container, "mousemove", _this.onDrag);
2228
- addEvent(container, "mouseup", _this.onDragEnd);
2229
- addEvent(container, "contextmenu", _this.onDragEnd);
2230
- }
2231
-
2232
- if (checkWindowBlur) {
2233
- addEvent(window, "blur", _this.onBlur);
2234
- }
2235
-
2236
- if (_this.isTouch) {
2237
- var passive_1 = {
2238
- passive: false
2239
- };
2240
- elements.forEach(function (el) {
2241
- addEvent(el, "touchstart", _this.onDragStart, passive_1);
2242
- });
2243
- addEvent(container, "touchmove", _this.onDrag, passive_1);
2244
- addEvent(container, "touchend", _this.onDragEnd, passive_1);
2245
- addEvent(container, "touchcancel", _this.onDragEnd, passive_1);
2246
- }
2247
-
2248
- return _this;
2249
- }
2250
- /**
2251
- * Stop Gesto's drag events.
2252
- */
2253
-
2254
-
2255
- var __proto = Gesto.prototype;
2256
-
2257
- __proto.stop = function () {
2258
- this.isDrag = false;
2259
- this.flag = false;
2260
- this.clientStores = [];
2261
- this.datas = {};
2262
- };
2263
- /**
2264
- * The total moved distance
2265
- */
2266
-
2267
-
2268
- __proto.getMovement = function (clients) {
2269
- return this.getCurrentStore().getMovement(clients) + this.clientStores.slice(1).reduce(function (prev, cur) {
2270
- return prev + cur.movement;
2271
- }, 0);
2272
- };
2273
- /**
2274
- * Whether to drag
2275
- */
2276
-
2277
-
2278
- __proto.isDragging = function () {
2279
- return this.isDrag;
2280
- };
2281
- /**
2282
- * Whether to start drag
2283
- */
2284
-
2285
-
2286
- __proto.isFlag = function () {
2287
- return this.flag;
2288
- };
2289
- /**
2290
- * Whether to start pinch
2291
- */
2292
-
2293
-
2294
- __proto.isPinchFlag = function () {
2295
- return this.pinchFlag;
2296
- };
2297
- /**
2298
- * Whether to start double click
2299
- */
2300
-
2301
-
2302
- __proto.isDoubleFlag = function () {
2303
- return this.doubleFlag;
2304
- };
2305
- /**
2306
- * Whether to pinch
2307
- */
2308
-
2309
-
2310
- __proto.isPinching = function () {
2311
- return this.isPinch;
2312
- };
2313
- /**
2314
- * If a scroll event occurs, it is corrected by the scroll distance.
2315
- */
2316
-
2317
-
2318
- __proto.scrollBy = function (deltaX, deltaY, e, isCallDrag) {
2319
- if (isCallDrag === void 0) {
2320
- isCallDrag = true;
2321
- }
2322
-
2323
- if (!this.flag) {
2324
- return;
2325
- }
2326
-
2327
- this.clientStores[0].move(deltaX, deltaY);
2328
- isCallDrag && this.onDrag(e, true);
2329
- };
2330
- /**
2331
- * Create a virtual drag event.
2332
- */
2333
-
2334
-
2335
- __proto.move = function (_a, inputEvent) {
2336
- var deltaX = _a[0],
2337
- deltaY = _a[1];
2338
- var store = this.getCurrentStore();
2339
- var nextClients = store.prevClients;
2340
- return this.moveClients(nextClients.map(function (_a) {
2341
- var clientX = _a.clientX,
2342
- clientY = _a.clientY;
2343
- return {
2344
- clientX: clientX + deltaX,
2345
- clientY: clientY + deltaY,
2346
- originalClientX: clientX,
2347
- originalClientY: clientY
2348
- };
2349
- }), inputEvent, true);
2350
- };
2351
- /**
2352
- * The dragStart event is triggered by an external event.
2353
- */
2354
-
2355
-
2356
- __proto.triggerDragStart = function (e) {
2357
- this.onDragStart(e, false);
2358
- };
2359
- /**
2360
- * Set the event data while dragging.
2361
- */
2362
-
2363
-
2364
- __proto.setEventDatas = function (datas) {
2365
- var currentDatas = this.datas;
2366
-
2367
- for (var name in datas) {
2368
- currentDatas[name] = datas[name];
2369
- }
2370
-
2371
- return this;
2372
- };
2373
- /**
2374
- * Set the event data while dragging.
2375
- */
2376
-
2377
-
2378
- __proto.getEventDatas = function () {
2379
- return this.datas;
2380
- };
2381
- /**
2382
- * Unset Gesto
2383
- */
2384
-
2385
-
2386
- __proto.unset = function () {
2387
- var _this = this;
2388
-
2389
- var targets = this.targets;
2390
- var container = this.options.container;
2391
- this.off();
2392
- removeEvent(window, "blur", this.onBlur);
2393
-
2394
- if (this.isMouse) {
2395
- targets.forEach(function (target) {
2396
- removeEvent(target, "mousedown", _this.onDragStart);
2397
- });
2398
- removeEvent(container, "mousemove", this.onDrag);
2399
- removeEvent(container, "mouseup", this.onDragEnd);
2400
- removeEvent(container, "contextmenu", this.onDragEnd);
2401
- }
2402
-
2403
- if (this.isTouch) {
2404
- targets.forEach(function (target) {
2405
- removeEvent(target, "touchstart", _this.onDragStart);
2406
- });
2407
- removeEvent(container, "touchstart", this.onDragStart);
2408
- removeEvent(container, "touchmove", this.onDrag);
2409
- removeEvent(container, "touchend", this.onDragEnd);
2410
- removeEvent(container, "touchcancel", this.onDragEnd);
2411
- }
2412
- };
2413
-
2414
- __proto.onPinchStart = function (e) {
2415
- var pinchThreshold = this.options.pinchThreshold;
2416
-
2417
- if (this.isDrag && this.getMovement() > pinchThreshold) {
2418
- return;
2419
- }
2420
-
2421
- var store = new ClientStore(getEventClients(e));
2422
- this.pinchFlag = true;
2423
- this.clientStores.splice(0, 0, store);
2424
- var result = this.emit("pinchStart", __assign({
2425
- datas: this.datas,
2426
- angle: store.getAngle(),
2427
- touches: this.getCurrentStore().getPositions()
2428
- }, store.getPosition(), {
2429
- inputEvent: e
2430
- }));
2431
-
2432
- if (result === false) {
2433
- this.pinchFlag = false;
2434
- }
2435
- };
2436
-
2437
- __proto.onPinch = function (e, clients) {
2438
- if (!this.flag || !this.pinchFlag || clients.length < 2) {
2439
- return;
2440
- }
2441
-
2442
- var store = this.getCurrentStore();
2443
- this.isPinch = true;
2444
- this.emit("pinch", __assign({
2445
- datas: this.datas,
2446
- movement: this.getMovement(clients),
2447
- angle: store.getAngle(clients),
2448
- rotation: store.getRotation(clients),
2449
- touches: store.getPositions(clients),
2450
- scale: store.getScale(clients),
2451
- distance: store.getDistance(clients)
2452
- }, store.getPosition(clients), {
2453
- inputEvent: e
2454
- }));
2455
- };
2456
-
2457
- __proto.onPinchEnd = function (e) {
2458
- if (!this.pinchFlag) {
2459
- return;
2460
- }
2461
-
2462
- var isPinch = this.isPinch;
2463
- this.isPinch = false;
2464
- this.pinchFlag = false;
2465
- var store = this.getCurrentStore();
2466
- this.emit("pinchEnd", __assign({
2467
- datas: this.datas,
2468
- isPinch: isPinch,
2469
- touches: store.getPositions()
2470
- }, store.getPosition(), {
2471
- inputEvent: e
2472
- }));
2473
- this.isPinch = false;
2474
- this.pinchFlag = false;
2475
- };
2476
-
2477
- __proto.initDrag = function () {
2478
- this.clientStores = [];
2479
- this.pinchFlag = false;
2480
- this.doubleFlag = false;
2481
- this.prevTime = 0;
2482
- this.flag = false;
2483
- };
2484
-
2485
- __proto.getCurrentStore = function () {
2486
- return this.clientStores[0];
2487
- };
2488
-
2489
- __proto.moveClients = function (clients, inputEvent, isAdd) {
2490
- var store = this.getCurrentStore();
2491
- var position = store[isAdd ? "addClients" : "getPosition"](clients);
2492
- this.isDrag = true;
2493
- return __assign({
2494
- datas: this.datas
2495
- }, position, {
2496
- movement: this.getMovement(clients),
2497
- isDrag: this.isDrag,
2498
- isPinch: this.isPinch,
2499
- isScroll: false,
2500
- inputEvent: inputEvent
2501
- });
2502
- };
2503
-
2504
- return Gesto;
2505
- }(EventEmitter$1);
2506
-
2507
- var Gesto$1 = Gesto;
2508
-
2509
- const _sfc_main$f = defineComponent({
2510
- name: "m-editor-resize",
2511
- props: {
2512
- type: {
2513
- type: String
2514
- }
2515
- },
2516
- setup(props) {
2517
- const services = inject("services");
2518
- const target = ref();
2519
- let getso;
2520
- onMounted(() => {
2521
- if (!target.value)
2522
- return;
2523
- getso = new Gesto$1(target.value, {
2524
- container: window,
2525
- pinchOutside: true
2526
- }).on("drag", (e) => {
2527
- if (!target.value || !services)
2528
- return;
2529
- let { left, right } = {
2530
- ...toRaw(services.uiService.get("columnWidth"))
2531
- };
2532
- if (props.type === "left") {
2533
- left += e.deltaX;
2534
- } else if (props.type === "right") {
2535
- right -= e.deltaX;
2536
- }
2537
- services.uiService.set("columnWidth", {
2538
- left,
2539
- right
2540
- });
2541
- });
2542
- });
2543
- onUnmounted(() => {
2544
- getso?.unset();
2545
- });
2546
- return {
2547
- target
2548
- };
2549
- }
2550
- });
2551
- const _hoisted_1$a = {
2552
- ref: "target",
2553
- class: "m-editor-resizer"
2554
- };
2555
- function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2556
- return openBlock(), createElementBlock("span", _hoisted_1$a, [
2557
- renderSlot(_ctx.$slots, "default")
2558
- ], 512);
2559
- }
2560
- var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
2561
-
2562
- const _sfc_main$e = defineComponent({
2563
- components: {
2564
- AddPageBox,
2565
- Resizer
2566
- },
2567
- setup() {
2568
- const services = inject("services");
2569
- const root = computed(() => services?.editorService.get("root"));
2570
- return {
2571
- root,
2572
- pageLength: computed(() => root.value?.items?.length || 0),
2573
- showSrc: computed(() => services?.uiService.get("showSrc")),
2574
- columnWidth: computed(() => services?.uiService.get("columnWidth")),
2575
- saveCode(value) {
2576
- try {
2577
- services?.editorService.set("root", eval(value));
2578
- } catch (e) {
2579
- console.error(e);
1620
+ },
1621
+ setup() {
1622
+ const { editorService, uiService } = inject("services") || {};
1623
+ const root = computed(() => editorService?.get("root"));
1624
+ return {
1625
+ root,
1626
+ pageLength: computed(() => editorService?.get("pageLength") || 0),
1627
+ showSrc: computed(() => uiService?.get("showSrc")),
1628
+ columnWidth: computed(() => uiService?.get("columnWidth")),
1629
+ saveCode(value) {
1630
+ try {
1631
+ editorService?.set("root", eval(value));
1632
+ } catch (e) {
1633
+ console.error(e);
2580
1634
  }
2581
1635
  }
2582
1636
  };
2583
1637
  }
2584
1638
  });
2585
- const _hoisted_1$9 = { class: "m-editor" };
2586
- const _hoisted_2$5 = {
1639
+ const _hoisted_1$8 = { class: "m-editor" };
1640
+ const _hoisted_2$3 = {
2587
1641
  key: 1,
2588
1642
  class: "m-editor-content"
2589
1643
  };
2590
- function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
1644
+ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
2591
1645
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
2592
1646
  const _component_resizer = resolveComponent("resizer");
2593
1647
  const _component_el_scrollbar = resolveComponent("el-scrollbar");
2594
1648
  const _component_add_page_box = resolveComponent("add-page-box");
2595
- return openBlock(), createElementBlock("div", _hoisted_1$9, [
1649
+ return openBlock(), createElementBlock("div", _hoisted_1$8, [
2596
1650
  renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2597
1651
  _ctx.showSrc ? (openBlock(), createBlock(_component_magic_code_editor, {
2598
1652
  key: 0,
2599
1653
  class: "m-editor-content",
2600
1654
  "init-values": _ctx.root,
1655
+ options: _ctx.codeOptions,
2601
1656
  onSave: _ctx.saveCode
2602
- }, null, 8, ["init-values", "onSave"])) : (openBlock(), createElementBlock("div", _hoisted_2$5, [
1657
+ }, null, 8, ["init-values", "options", "onSave"])) : (openBlock(), createElementBlock("div", _hoisted_2$3, [
2603
1658
  createElementVNode("div", {
2604
1659
  class: "m-editor-framework-left",
2605
1660
  style: normalizeStyle(`width: ${_ctx.columnWidth?.left}px`)
@@ -2632,9 +1687,9 @@ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2632
1687
  ]))
2633
1688
  ]);
2634
1689
  }
2635
- var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
1690
+ var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
2636
1691
 
2637
- const _sfc_main$d = defineComponent({
1692
+ const _sfc_main$f = defineComponent({
2638
1693
  name: "m-icon",
2639
1694
  components: { Edit },
2640
1695
  props: {
@@ -2648,8 +1703,8 @@ const _sfc_main$d = defineComponent({
2648
1703
  };
2649
1704
  }
2650
1705
  });
2651
- const _hoisted_1$8 = ["src"];
2652
- function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
1706
+ const _hoisted_1$7 = ["src"];
1707
+ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2653
1708
  const _component_edit = resolveComponent("edit");
2654
1709
  const _component_el_icon = resolveComponent("el-icon");
2655
1710
  return !_ctx.icon ? (openBlock(), createBlock(_component_el_icon, { key: 0 }, {
@@ -2660,7 +1715,7 @@ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2660
1715
  })) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (openBlock(), createElementBlock("img", {
2661
1716
  key: 1,
2662
1717
  src: _ctx.icon
2663
- }, null, 8, _hoisted_1$8)) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
1718
+ }, null, 8, _hoisted_1$7)) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
2664
1719
  key: 2,
2665
1720
  class: normalizeClass(_ctx.icon)
2666
1721
  }, null, 2)) : (openBlock(), createBlock(_component_el_icon, { key: 3 }, {
@@ -2670,9 +1725,9 @@ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2670
1725
  _: 1
2671
1726
  }));
2672
1727
  }
2673
- var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
1728
+ var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
2674
1729
 
2675
- const _sfc_main$c = defineComponent({
1730
+ const _sfc_main$e = defineComponent({
2676
1731
  components: { MIcon, ArrowDown },
2677
1732
  props: {
2678
1733
  data: {
@@ -2682,16 +1737,20 @@ const _sfc_main$c = defineComponent({
2682
1737
  type: "text",
2683
1738
  display: false
2684
1739
  })
1740
+ },
1741
+ eventType: {
1742
+ type: String,
1743
+ default: "click"
2685
1744
  }
2686
1745
  },
2687
1746
  setup(props) {
2688
1747
  const services = inject("services");
2689
1748
  const uiService = services?.uiService;
2690
- const zoomInHandler = () => uiService?.set("zoom", zoom.value + 0.1);
2691
- const zoomOutHandler = () => uiService?.set("zoom", zoom.value - 0.1);
2692
1749
  const zoom = computed(() => uiService?.get("zoom") ?? 1);
2693
1750
  const showGuides = computed(() => uiService?.get("showGuides") ?? true);
2694
1751
  const showRule = computed(() => uiService?.get("showRule") ?? true);
1752
+ const zoomInHandler = () => uiService?.zoom(0.1);
1753
+ const zoomOutHandler = () => uiService?.zoom(-0.1);
2695
1754
  const item = computed(() => {
2696
1755
  if (typeof props.data !== "string") {
2697
1756
  return props.data;
@@ -2708,15 +1767,15 @@ const _sfc_main$c = defineComponent({
2708
1767
  case "delete":
2709
1768
  return {
2710
1769
  type: "button",
2711
- icon: Delete,
1770
+ icon: markRaw(Delete),
2712
1771
  tooltip: "\u522A\u9664",
2713
- disabled: () => services?.editorService.get("node")?.type === "page",
1772
+ disabled: () => services?.editorService.get("node")?.type === NodeType.PAGE,
2714
1773
  handler: () => services?.editorService.remove(services?.editorService.get("node"))
2715
1774
  };
2716
1775
  case "undo":
2717
1776
  return {
2718
1777
  type: "button",
2719
- icon: Back,
1778
+ icon: markRaw(Back),
2720
1779
  tooltip: "\u540E\u9000",
2721
1780
  disabled: () => !services?.historyService.state.canUndo,
2722
1781
  handler: () => services?.editorService.undo()
@@ -2724,7 +1783,7 @@ const _sfc_main$c = defineComponent({
2724
1783
  case "redo":
2725
1784
  return {
2726
1785
  type: "button",
2727
- icon: Right,
1786
+ icon: markRaw(Right),
2728
1787
  tooltip: "\u524D\u8FDB",
2729
1788
  disabled: () => !services?.historyService.state.canRedo,
2730
1789
  handler: () => services?.editorService.redo()
@@ -2732,28 +1791,28 @@ const _sfc_main$c = defineComponent({
2732
1791
  case "zoom-in":
2733
1792
  return {
2734
1793
  type: "button",
2735
- icon: ZoomIn,
1794
+ icon: markRaw(ZoomIn),
2736
1795
  tooltip: "\u653E\u5927",
2737
1796
  handler: zoomInHandler
2738
1797
  };
2739
1798
  case "zoom-out":
2740
1799
  return {
2741
1800
  type: "button",
2742
- icon: ZoomOut,
1801
+ icon: markRaw(ZoomOut),
2743
1802
  tooltip: "\u7E2E\u5C0F",
2744
1803
  handler: zoomOutHandler
2745
1804
  };
2746
1805
  case "rule":
2747
1806
  return {
2748
1807
  type: "button",
2749
- icon: ScaleToOriginal,
1808
+ icon: markRaw(ScaleToOriginal),
2750
1809
  tooltip: showRule.value ? "\u9690\u85CF\u6807\u5C3A" : "\u663E\u793A\u6807\u5C3A",
2751
1810
  handler: () => uiService?.set("showRule", !showRule.value)
2752
1811
  };
2753
1812
  case "guides":
2754
1813
  return {
2755
1814
  type: "button",
2756
- icon: Grid,
1815
+ icon: markRaw(Grid),
2757
1816
  tooltip: showGuides.value ? "\u9690\u85CF\u53C2\u8003\u7EBF" : "\u663E\u793A\u53C2\u8003\u7EBF",
2758
1817
  handler: () => uiService?.set("showGuides", !showGuides.value)
2759
1818
  };
@@ -2774,9 +1833,16 @@ const _sfc_main$c = defineComponent({
2774
1833
  }
2775
1834
  return item.value.disabled;
2776
1835
  });
1836
+ const buttonHandler = (item2, event) => {
1837
+ if (disabled.value)
1838
+ return;
1839
+ if (typeof item2.handler === "function" && services) {
1840
+ item2.handler?.(services, event);
1841
+ }
1842
+ };
2777
1843
  return {
2778
- ZoomIn,
2779
- ZoomOut,
1844
+ ZoomIn: markRaw(ZoomIn),
1845
+ ZoomOut: markRaw(ZoomOut),
2780
1846
  item,
2781
1847
  zoom,
2782
1848
  disabled,
@@ -2797,31 +1863,42 @@ const _sfc_main$c = defineComponent({
2797
1863
  command.item.handler(services);
2798
1864
  }
2799
1865
  },
2800
- buttonHandler(item2) {
2801
- if (disabled.value)
1866
+ clickHandler(item2, event) {
1867
+ if (props.eventType !== "click")
1868
+ return;
1869
+ if (item2.type === "button") {
1870
+ buttonHandler(item2, event);
1871
+ }
1872
+ },
1873
+ mousedownHandler(item2, event) {
1874
+ if (props.eventType !== "mousedown")
1875
+ return;
1876
+ if (item2.type === "button") {
1877
+ buttonHandler(item2, event);
1878
+ }
1879
+ },
1880
+ mouseupHandler(item2, event) {
1881
+ if (props.eventType !== "mouseup")
2802
1882
  return;
2803
- if (typeof item2.handler === "function") {
2804
- item2.handler?.(services);
1883
+ if (item2.type === "button") {
1884
+ buttonHandler(item2, event);
2805
1885
  }
2806
1886
  }
2807
1887
  };
2808
1888
  }
2809
1889
  });
2810
- const _hoisted_1$7 = {
2811
- key: 0,
2812
- class: "menu-item"
2813
- };
2814
- const _hoisted_2$4 = {
1890
+ const _hoisted_1$6 = {
2815
1891
  key: 1,
2816
1892
  class: "menu-item-text"
2817
1893
  };
2818
- const _hoisted_3$3 = {
1894
+ const _hoisted_2$2 = {
2819
1895
  class: "menu-item-text",
2820
1896
  style: { "margin": "0 5px" }
2821
1897
  };
2822
- const _hoisted_4$3 = { class: "el-dropdown-link menubar-menu-button" };
2823
- function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
1898
+ const _hoisted_3$1 = { class: "el-dropdown-link menubar-menu-button" };
1899
+ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2824
1900
  const _component_el_divider = resolveComponent("el-divider");
1901
+ const _component_tool_button = resolveComponent("tool-button", true);
2825
1902
  const _component_m_icon = resolveComponent("m-icon");
2826
1903
  const _component_el_button = resolveComponent("el-button");
2827
1904
  const _component_el_tooltip = resolveComponent("el-tooltip");
@@ -2830,44 +1907,66 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2830
1907
  const _component_el_dropdown_item = resolveComponent("el-dropdown-item");
2831
1908
  const _component_el_dropdown_menu = resolveComponent("el-dropdown-menu");
2832
1909
  const _component_el_dropdown = resolveComponent("el-dropdown");
2833
- return _ctx.display ? (openBlock(), createElementBlock("div", _hoisted_1$7, [
1910
+ return _ctx.display ? (openBlock(), createElementBlock("div", {
1911
+ key: 0,
1912
+ class: normalizeClass(["menu-item", _ctx.item.type]),
1913
+ onClick: _cache[0] || (_cache[0] = ($event) => _ctx.clickHandler(_ctx.item, $event)),
1914
+ onMousedown: _cache[1] || (_cache[1] = ($event) => _ctx.mousedownHandler(_ctx.item, $event)),
1915
+ onMouseup: _cache[2] || (_cache[2] = ($event) => _ctx.mouseupHandler(_ctx.item, $event))
1916
+ }, [
2834
1917
  _ctx.item.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
2835
1918
  key: 0,
2836
- direction: "vertical"
2837
- })) : _ctx.item.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_2$4, toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2838
- createVNode(_component_m_icon, {
2839
- icon: _ctx.ZoomIn,
2840
- onClick: _ctx.zoomInHandler
2841
- }, null, 8, ["icon", "onClick"]),
2842
- createElementVNode("span", _hoisted_3$3, toDisplayString(parseInt(`${_ctx.zoom * 100}`, 10)) + "%", 1),
2843
- createVNode(_component_m_icon, {
2844
- icon: _ctx.ZoomOut,
2845
- onClick: _ctx.zoomOutHandler
2846
- }, null, 8, ["icon", "onClick"])
2847
- ], 64)) : _ctx.item.type === "button" ? (openBlock(), createBlock(_component_el_tooltip, {
2848
- key: 3,
2849
- effect: "dark",
2850
- placement: "bottom-start",
2851
- content: _ctx.item.tooltip || _ctx.item.text
2852
- }, {
2853
- default: withCtx(() => [
2854
- createVNode(_component_el_button, {
2855
- size: "small",
2856
- type: "text",
2857
- disabled: _ctx.disabled,
2858
- onClick: _cache[0] || (_cache[0] = ($event) => _ctx.buttonHandler(_ctx.item))
2859
- }, {
2860
- default: withCtx(() => [
2861
- createVNode(_component_m_icon, {
2862
- icon: _ctx.item.icon
2863
- }, null, 8, ["icon"]),
2864
- createElementVNode("span", null, toDisplayString(_ctx.item.text), 1)
2865
- ]),
2866
- _: 1
2867
- }, 8, ["disabled"])
2868
- ]),
2869
- _: 1
2870
- }, 8, ["content"])) : _ctx.item.type === "dropdown" ? (openBlock(), createBlock(_component_el_dropdown, {
1919
+ direction: _ctx.item.direction || "vertical"
1920
+ }, null, 8, ["direction"])) : _ctx.item.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$6, toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
1921
+ createVNode(_component_tool_button, {
1922
+ data: { type: "button", icon: _ctx.ZoomOut, handler: _ctx.zoomOutHandler, tooltip: "\u7F29\u5C0F" },
1923
+ "event-type": _ctx.eventType
1924
+ }, null, 8, ["data", "event-type"]),
1925
+ createElementVNode("span", _hoisted_2$2, toDisplayString(parseInt(`${_ctx.zoom * 100}`, 10)) + "%", 1),
1926
+ createVNode(_component_tool_button, {
1927
+ data: { type: "button", icon: _ctx.ZoomIn, handler: _ctx.zoomInHandler, tooltip: "\u653E\u5927" },
1928
+ "event-type": _ctx.eventType
1929
+ }, null, 8, ["data", "event-type"])
1930
+ ], 64)) : _ctx.item.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
1931
+ _ctx.item.tooltip ? (openBlock(), createBlock(_component_el_tooltip, {
1932
+ key: 0,
1933
+ effect: "dark",
1934
+ placement: "bottom-start",
1935
+ content: _ctx.item.tooltip
1936
+ }, {
1937
+ default: withCtx(() => [
1938
+ createVNode(_component_el_button, {
1939
+ size: "small",
1940
+ text: "",
1941
+ disabled: _ctx.disabled
1942
+ }, {
1943
+ default: withCtx(() => [
1944
+ _ctx.item.icon ? (openBlock(), createBlock(_component_m_icon, {
1945
+ key: 0,
1946
+ icon: _ctx.item.icon
1947
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
1948
+ createElementVNode("span", null, toDisplayString(_ctx.item.text), 1)
1949
+ ]),
1950
+ _: 1
1951
+ }, 8, ["disabled"])
1952
+ ]),
1953
+ _: 1
1954
+ }, 8, ["content"])) : (openBlock(), createBlock(_component_el_button, {
1955
+ key: 1,
1956
+ size: "small",
1957
+ text: "",
1958
+ disabled: _ctx.disabled
1959
+ }, {
1960
+ default: withCtx(() => [
1961
+ _ctx.item.icon ? (openBlock(), createBlock(_component_m_icon, {
1962
+ key: 0,
1963
+ icon: _ctx.item.icon
1964
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
1965
+ createElementVNode("span", null, toDisplayString(_ctx.item.text), 1)
1966
+ ]),
1967
+ _: 1
1968
+ }, 8, ["disabled"]))
1969
+ ], 64)) : _ctx.item.type === "dropdown" ? (openBlock(), createBlock(_component_el_dropdown, {
2871
1970
  key: 4,
2872
1971
  trigger: "click",
2873
1972
  disabled: _ctx.disabled,
@@ -2892,7 +1991,7 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2892
1991
  })) : createCommentVNode("", true)
2893
1992
  ]),
2894
1993
  default: withCtx(() => [
2895
- createElementVNode("span", _hoisted_4$3, [
1994
+ createElementVNode("span", _hoisted_3$1, [
2896
1995
  createTextVNode(toDisplayString(_ctx.item.text), 1),
2897
1996
  createVNode(_component_el_icon, { class: "el-icon--right" }, {
2898
1997
  default: withCtx(() => [
@@ -2904,11 +2003,11 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2904
2003
  ]),
2905
2004
  _: 1
2906
2005
  }, 8, ["disabled", "onCommand"])) : _ctx.item.type === "component" ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.item.component), normalizeProps(mergeProps({ key: 5 }, _ctx.item.props || {})), null, 16)) : createCommentVNode("", true)
2907
- ])) : createCommentVNode("", true);
2006
+ ], 34)) : createCommentVNode("", true);
2908
2007
  }
2909
- var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
2008
+ var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
2910
2009
 
2911
- const _sfc_main$b = defineComponent({
2010
+ const _sfc_main$d = defineComponent({
2912
2011
  name: "nav-menu",
2913
2012
  components: { ToolButton },
2914
2013
  props: {
@@ -2928,7 +2027,7 @@ const _sfc_main$b = defineComponent({
2928
2027
  };
2929
2028
  }
2930
2029
  });
2931
- function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2030
+ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2932
2031
  const _component_tool_button = resolveComponent("tool-button");
2933
2032
  return openBlock(), createElementBlock("div", {
2934
2033
  class: "m-editor-nav-menu",
@@ -2950,9 +2049,9 @@ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2950
2049
  }), 128))
2951
2050
  ], 4);
2952
2051
  }
2953
- var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
2052
+ var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
2954
2053
 
2955
- const _sfc_main$a = defineComponent({
2054
+ const _sfc_main$c = defineComponent({
2956
2055
  name: "m-editor-props-panel",
2957
2056
  emits: ["mounted"],
2958
2057
  setup(props, { emit }) {
@@ -2967,9 +2066,9 @@ const _sfc_main$a = defineComponent({
2967
2066
  curFormConfig.value = [];
2968
2067
  return;
2969
2068
  }
2970
- values.value = node.value;
2971
2069
  const type = node.value.type || (node.value.items ? "container" : "text");
2972
2070
  curFormConfig.value = await services?.propsService.getPropsConfig(type) || [];
2071
+ values.value = node.value;
2973
2072
  };
2974
2073
  watchEffect(init);
2975
2074
  services?.propsService.on("props-configs-change", init);
@@ -2980,6 +2079,7 @@ const _sfc_main$a = defineComponent({
2980
2079
  values,
2981
2080
  configForm,
2982
2081
  curFormConfig,
2082
+ propsPanelSize: computed(() => services?.uiService.get("propsPanelSize") || "small"),
2983
2083
  async submit() {
2984
2084
  try {
2985
2085
  const values2 = await configForm.value?.submitForm();
@@ -2998,21 +2098,21 @@ const _sfc_main$a = defineComponent({
2998
2098
  };
2999
2099
  }
3000
2100
  });
3001
- function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2101
+ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
3002
2102
  const _component_m_form = resolveComponent("m-form");
3003
2103
  return openBlock(), createBlock(_component_m_form, {
3004
- class: "m-editor-props-panel",
3005
- "popper-class": "m-editor-props-panel-popper",
2104
+ class: normalizeClass(`m-editor-props-panel ${_ctx.propsPanelSize}`),
2105
+ "popper-class": `m-editor-props-panel-popper ${_ctx.propsPanelSize}`,
3006
2106
  ref: "configForm",
3007
- size: "small",
2107
+ size: _ctx.propsPanelSize,
3008
2108
  "init-values": _ctx.values,
3009
2109
  config: _ctx.curFormConfig,
3010
2110
  onChange: _ctx.submit
3011
- }, null, 8, ["init-values", "config", "onChange"]);
2111
+ }, null, 8, ["class", "popper-class", "size", "init-values", "config", "onChange"]);
3012
2112
  }
3013
- var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
2113
+ var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
3014
2114
 
3015
- const _sfc_main$9 = defineComponent({
2115
+ const _sfc_main$b = defineComponent({
3016
2116
  name: "ui-component-panel",
3017
2117
  components: { MIcon },
3018
2118
  setup() {
@@ -3027,19 +2127,29 @@ const _sfc_main$9 = defineComponent({
3027
2127
  searchText,
3028
2128
  collapseValue,
3029
2129
  list,
3030
- appendComponent({ text, type, ...config }) {
2130
+ appendComponent({ text, type, data = {} }) {
3031
2131
  services?.editorService.add({
3032
2132
  name: text,
3033
2133
  type,
3034
- ...config
2134
+ ...data
3035
2135
  });
2136
+ },
2137
+ dragstartHandler({ text, type, data = {} }, e) {
2138
+ if (e.dataTransfer) {
2139
+ e.dataTransfer.effectAllowed = "move";
2140
+ e.dataTransfer.setData("data", serialize({
2141
+ name: text,
2142
+ type,
2143
+ ...data
2144
+ }).replace(/"(\w+)":\s/g, "$1: "));
2145
+ }
3036
2146
  }
3037
2147
  };
3038
2148
  }
3039
2149
  });
3040
- const _hoisted_1$6 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
3041
- const _hoisted_2$3 = ["onClick"];
3042
- function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
2150
+ const _hoisted_1$5 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
2151
+ const _hoisted_2$1 = ["onClick", "onDragstart"];
2152
+ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
3043
2153
  const _component_el_input = resolveComponent("el-input");
3044
2154
  const _component_m_icon = resolveComponent("m-icon");
3045
2155
  const _component_el_tooltip = resolveComponent("el-tooltip");
@@ -3069,15 +2179,17 @@ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3069
2179
  name: index
3070
2180
  }, {
3071
2181
  title: withCtx(() => [
3072
- _hoisted_1$6,
2182
+ _hoisted_1$5,
3073
2183
  createTextVNode(toDisplayString(group.title), 1)
3074
2184
  ]),
3075
2185
  default: withCtx(() => [
3076
2186
  (openBlock(true), createElementBlock(Fragment, null, renderList(group.items, (item) => {
3077
2187
  return openBlock(), createElementBlock("div", {
3078
2188
  class: "component-item",
2189
+ draggable: "true",
3079
2190
  key: item.type,
3080
- onClick: ($event) => _ctx.appendComponent(item)
2191
+ onClick: ($event) => _ctx.appendComponent(item),
2192
+ onDragstart: ($event) => _ctx.dragstartHandler(item, $event)
3081
2193
  }, [
3082
2194
  createVNode(_component_m_icon, {
3083
2195
  icon: item.icon
@@ -3092,7 +2204,7 @@ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3092
2204
  ]),
3093
2205
  _: 2
3094
2206
  }, 1032, ["content"])
3095
- ], 8, _hoisted_2$3);
2207
+ ], 40, _hoisted_2$1);
3096
2208
  }), 128))
3097
2209
  ]),
3098
2210
  _: 2
@@ -3106,135 +2218,220 @@ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3106
2218
  _: 1
3107
2219
  });
3108
2220
  }
3109
- var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
2221
+ var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
3110
2222
 
3111
- const _sfc_main$8 = defineComponent({
3112
- name: "magic-editor-content-menu",
2223
+ const _sfc_main$a = defineComponent({
2224
+ components: { ToolButton },
3113
2225
  props: {
3114
- componentGroupList: {
2226
+ menuData: {
3115
2227
  type: Array,
3116
2228
  default: () => []
3117
2229
  }
3118
2230
  },
3119
- setup(props) {
3120
- const services = inject("services");
3121
- const subVisible = ref(false);
3122
- const node = computed(() => services?.editorService.get("node"));
2231
+ setup() {
2232
+ const menu = ref();
2233
+ const subMenu = ref();
2234
+ const visible = ref(false);
2235
+ const subMenuData = ref([]);
2236
+ const menuStyle = ref({
2237
+ left: "0",
2238
+ top: "0"
2239
+ });
2240
+ const hide = () => {
2241
+ visible.value = false;
2242
+ };
2243
+ onMounted(() => {
2244
+ globalThis.addEventListener("mousedown", (e) => {
2245
+ if (!visible.value || e.target && menu.value?.contains(e.target)) {
2246
+ return;
2247
+ }
2248
+ hide();
2249
+ }, true);
2250
+ });
3123
2251
  return {
3124
- subVisible,
3125
- node,
3126
- menu: computed(() => ({
3127
- app: [
3128
- {
3129
- type: "page",
3130
- text: "\u9875\u9762"
2252
+ menu,
2253
+ subMenu,
2254
+ visible,
2255
+ menuStyle,
2256
+ subMenuData,
2257
+ hide,
2258
+ show(e) {
2259
+ visible.value = true;
2260
+ nextTick(() => {
2261
+ const menuHeight = menu.value?.clientHeight || 0;
2262
+ let top = e.clientY;
2263
+ if (menuHeight + e.clientY > document.body.clientHeight) {
2264
+ top = document.body.clientHeight - menuHeight;
3131
2265
  }
3132
- ],
3133
- component: props.componentGroupList
3134
- })),
3135
- append(config) {
3136
- services?.editorService.add({
3137
- name: config.text,
3138
- type: config.type
2266
+ menuStyle.value = {
2267
+ top: `${top}px`,
2268
+ left: `${e.clientX}px`
2269
+ };
3139
2270
  });
3140
2271
  },
3141
- remove() {
3142
- node.value && services?.editorService.remove(node.value);
3143
- },
3144
- copy(node2) {
3145
- services?.editorService.copy(node2);
3146
- },
3147
- setSubVisiable(v) {
3148
- subVisible.value = v;
2272
+ showSubMenu(item) {
2273
+ const menuItem = item;
2274
+ if (typeof item !== "object" || !menuItem.items?.length) {
2275
+ return;
2276
+ }
2277
+ subMenuData.value = menuItem.items;
2278
+ if (menu.value) {
2279
+ subMenu.value.show({
2280
+ clientX: menu.value.offsetLeft + menu.value.clientWidth,
2281
+ clientY: menu.value.offsetTop
2282
+ });
2283
+ }
3149
2284
  }
3150
2285
  };
3151
2286
  }
3152
2287
  });
3153
- const _hoisted_1$5 = {
3154
- key: 0,
3155
- class: "magic-editor-content-menu"
3156
- };
3157
- const _hoisted_2$2 = ["onClick"];
3158
- const _hoisted_3$2 = ["onClick"];
3159
- const _hoisted_4$2 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3160
- function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3161
- const _component_el_scrollbar = resolveComponent("el-scrollbar");
3162
- return _ctx.node ? (openBlock(), createElementBlock("div", _hoisted_1$5, [
3163
- _ctx.node.items ? (openBlock(), createElementBlock("div", {
3164
- key: 0,
3165
- class: "magic-editor-content-menu-item",
3166
- onMouseenter: _cache[0] || (_cache[0] = ($event) => _ctx.setSubVisiable(true)),
3167
- onMouseleave: _cache[1] || (_cache[1] = ($event) => _ctx.setSubVisiable(false))
3168
- }, " \u65B0\u589E ", 32)) : createCommentVNode("", true),
3169
- _ctx.node.type !== "app" ? (openBlock(), createElementBlock("div", {
3170
- key: 1,
3171
- class: "magic-editor-content-menu-item",
3172
- onClick: _cache[2] || (_cache[2] = () => _ctx.copy(_ctx.node))
3173
- }, "\u590D\u5236")) : createCommentVNode("", true),
3174
- _ctx.node.type !== "app" && _ctx.node.type !== "page" ? (openBlock(), createElementBlock("div", {
3175
- key: 2,
3176
- class: "magic-editor-content-menu-item",
3177
- onClick: _cache[3] || (_cache[3] = () => _ctx.remove())
3178
- }, " \u5220\u9664 ")) : createCommentVNode("", true),
3179
- withDirectives(createElementVNode("div", {
3180
- class: "subMenu",
3181
- onMouseenter: _cache[5] || (_cache[5] = ($event) => _ctx.setSubVisiable(true)),
3182
- onMouseleave: _cache[6] || (_cache[6] = ($event) => _ctx.setSubVisiable(false))
3183
- }, [
3184
- createVNode(_component_el_scrollbar, null, {
3185
- default: withCtx(() => [
3186
- _ctx.node.type === "tabs" ? (openBlock(), createElementBlock("div", {
3187
- key: 0,
3188
- class: "magic-editor-content-menu-item",
3189
- onClick: _cache[4] || (_cache[4] = () => _ctx.append({
3190
- type: "tab-pane"
3191
- }))
3192
- }, " \u6807\u7B7E ")) : _ctx.node.type === "app" ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.menu.app, (item) => {
3193
- return openBlock(), createElementBlock("div", {
3194
- class: "magic-editor-content-menu-item",
3195
- key: item.type,
3196
- onClick: () => _ctx.append(item)
3197
- }, toDisplayString(item.text), 9, _hoisted_2$2);
3198
- }), 128)) : _ctx.node.items ? (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(_ctx.menu.component, (list) => {
3199
- return openBlock(), createElementBlock("div", {
3200
- key: list.title
3201
- }, [
3202
- (openBlock(true), createElementBlock(Fragment, null, renderList(list.items, (item) => {
3203
- return openBlock(), createElementBlock(Fragment, null, [
3204
- item ? (openBlock(), createElementBlock("div", {
3205
- class: "magic-editor-content-menu-item",
3206
- key: item.type,
3207
- onClick: () => _ctx.append(item)
3208
- }, toDisplayString(item.text), 9, _hoisted_3$2)) : createCommentVNode("", true)
3209
- ], 64);
3210
- }), 256)),
3211
- _hoisted_4$2
3212
- ]);
3213
- }), 128)) : createCommentVNode("", true)
3214
- ]),
3215
- _: 1
3216
- })
3217
- ], 544), [
3218
- [vShow, _ctx.subVisible]
3219
- ])
3220
- ])) : createCommentVNode("", true);
2288
+ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2289
+ const _component_tool_button = resolveComponent("tool-button");
2290
+ const _component_content_menu = resolveComponent("content-menu", true);
2291
+ return _ctx.menuData.length ? withDirectives((openBlock(), createElementBlock("div", {
2292
+ key: 0,
2293
+ class: "magic-editor-content-menu",
2294
+ ref: "menu",
2295
+ style: normalizeStyle(_ctx.menuStyle)
2296
+ }, [
2297
+ createElementVNode("div", null, [
2298
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.menuData, (item, index) => {
2299
+ return openBlock(), createBlock(_component_tool_button, {
2300
+ "event-type": "mouseup",
2301
+ data: item,
2302
+ key: index,
2303
+ onMouseup: _ctx.hide,
2304
+ onMouseenter: ($event) => _ctx.showSubMenu(item)
2305
+ }, null, 8, ["data", "onMouseup", "onMouseenter"]);
2306
+ }), 128))
2307
+ ]),
2308
+ (openBlock(), createBlock(Teleport, { to: "body" }, [
2309
+ createVNode(_component_content_menu, {
2310
+ class: "sub-menu",
2311
+ ref: "subMenu",
2312
+ "menu-data": _ctx.subMenuData
2313
+ }, null, 8, ["menu-data"])
2314
+ ]))
2315
+ ], 4)), [
2316
+ [vShow, _ctx.visible]
2317
+ ]) : createCommentVNode("", true);
2318
+ }
2319
+ var ContentMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
2320
+
2321
+ const _sfc_main$9 = defineComponent({
2322
+ components: { ContentMenu },
2323
+ setup() {
2324
+ const services = inject("services");
2325
+ const menu = ref();
2326
+ const node = computed(() => services?.editorService.get("node"));
2327
+ const isRoot = computed(() => node.value?.type === NodeType.ROOT);
2328
+ const isPage = computed(() => node.value?.type === NodeType.PAGE);
2329
+ const componentList = computed(() => services?.componentListService.getList() || []);
2330
+ const createMenuItems = (group) => group.items.map((component) => ({
2331
+ text: component.text,
2332
+ type: "button",
2333
+ icon: component.icon,
2334
+ handler: () => {
2335
+ services?.editorService.add({
2336
+ name: component.text,
2337
+ type: component.type,
2338
+ ...component.data || {}
2339
+ });
2340
+ }
2341
+ }));
2342
+ const getSubMenuData = computed(() => {
2343
+ if (node.value?.type === "tabs") {
2344
+ return [
2345
+ {
2346
+ text: "\u6807\u7B7E\u9875",
2347
+ type: "button",
2348
+ icon: Files,
2349
+ handler: () => {
2350
+ services?.editorService.add({
2351
+ type: "tab-pane"
2352
+ });
2353
+ }
2354
+ }
2355
+ ];
2356
+ }
2357
+ if (node.value?.items) {
2358
+ return componentList.value.reduce((subMenuData, group, index) => subMenuData.concat(createMenuItems(group), index < componentList.value.length - 1 ? [
2359
+ {
2360
+ type: "divider",
2361
+ direction: "horizontal"
2362
+ }
2363
+ ] : []), []) || [];
2364
+ }
2365
+ return [];
2366
+ });
2367
+ return {
2368
+ menu,
2369
+ menuData: computed(() => [
2370
+ {
2371
+ type: "button",
2372
+ text: "\u65B0\u589E",
2373
+ icon: markRaw(Plus),
2374
+ display: () => node.value?.items,
2375
+ items: getSubMenuData.value
2376
+ },
2377
+ {
2378
+ type: "button",
2379
+ text: "\u590D\u5236",
2380
+ icon: markRaw(DocumentCopy),
2381
+ display: () => !isRoot.value,
2382
+ handler: () => {
2383
+ node.value && services?.editorService.copy(node.value);
2384
+ }
2385
+ },
2386
+ {
2387
+ type: "button",
2388
+ text: "\u5220\u9664",
2389
+ icon: markRaw(Delete),
2390
+ display: () => !isRoot.value && !isPage.value,
2391
+ handler: () => {
2392
+ node.value && services?.editorService.remove(node.value);
2393
+ }
2394
+ }
2395
+ ]),
2396
+ show(e) {
2397
+ menu.value?.show(e);
2398
+ }
2399
+ };
2400
+ }
2401
+ });
2402
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
2403
+ const _component_content_menu = resolveComponent("content-menu");
2404
+ return openBlock(), createBlock(_component_content_menu, {
2405
+ "menu-data": _ctx.menuData,
2406
+ ref: "menu",
2407
+ style: { "overflow": "initial" }
2408
+ }, null, 8, ["menu-data"]);
3221
2409
  }
3222
- var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
2410
+ var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
3223
2411
 
3224
- const select = (data, editorService) => {
2412
+ const throttleTime = 150;
2413
+ const select = async (data, editorService) => {
3225
2414
  if (!data.id) {
3226
2415
  throw new Error("\u6CA1\u6709id");
3227
2416
  }
3228
- editorService?.select(data);
2417
+ await editorService?.select(data);
2418
+ editorService?.get("stage")?.select(data.id);
2419
+ };
2420
+ const highlight = (data, editorService) => {
2421
+ if (!data?.id) {
2422
+ throw new Error("\u6CA1\u6709id");
2423
+ }
2424
+ editorService?.highlight(data);
2425
+ editorService?.get("stage")?.highlight(data.id);
3229
2426
  };
3230
2427
  const useDrop = (tree, editorService) => ({
3231
2428
  allowDrop: (draggingNode, dropNode, type) => {
3232
2429
  const { data } = dropNode || {};
3233
2430
  const { data: ingData } = draggingNode;
3234
2431
  const { type: ingType } = ingData;
3235
- if (ingType !== "page" && data.type === "page")
2432
+ if (ingType !== NodeType.PAGE && data.type === NodeType.PAGE)
3236
2433
  return false;
3237
- if (ingType === "page" && data.type !== "page")
2434
+ if (ingType === NodeType.PAGE && data.type !== NodeType.PAGE)
3238
2435
  return false;
3239
2436
  if (!data || !data.type)
3240
2437
  return false;
@@ -3253,29 +2450,35 @@ const useDrop = (tree, editorService) => ({
3253
2450
  }
3254
2451
  });
3255
2452
  const useStatus = (tree, editorService) => {
2453
+ const highlightNode = ref();
2454
+ const node = ref();
3256
2455
  const page = computed(() => editorService?.get("page"));
3257
2456
  watchEffect(() => {
3258
2457
  if (!tree.value)
3259
2458
  return;
3260
- const node = editorService?.get("node");
3261
- node && tree.value.setCurrentKey(node.id, true);
2459
+ node.value = editorService?.get("node");
2460
+ node.value && tree.value.setCurrentKey(node.value.id, true);
3262
2461
  const parent = editorService?.get("parent");
3263
2462
  if (!parent?.id)
3264
2463
  return;
3265
2464
  const treeNode = tree.value.getNode(parent.id);
3266
2465
  treeNode?.updateChildren();
2466
+ highlightNode.value = editorService?.get("highlightNode");
3267
2467
  });
3268
2468
  return {
3269
2469
  values: computed(() => page.value ? [page.value] : []),
3270
- loadItems: (node, resolve) => {
3271
- if (Array.isArray(node.data)) {
3272
- return resolve(node.data);
2470
+ loadItems: (node2, resolve) => {
2471
+ if (Array.isArray(node2.data)) {
2472
+ return resolve(node2.data);
3273
2473
  }
3274
- if (Array.isArray(node.data?.items)) {
3275
- return resolve(node.data?.items);
2474
+ if (Array.isArray(node2.data?.items)) {
2475
+ return resolve(node2.data?.items);
3276
2476
  }
3277
2477
  resolve([]);
3278
- }
2478
+ },
2479
+ highlightNode,
2480
+ clickNode: node,
2481
+ expandedKeys: computed(() => node.value ? [node.value.id] : [])
3279
2482
  };
3280
2483
  };
3281
2484
  const useFilter = (tree) => ({
@@ -3287,69 +2490,64 @@ const useFilter = (tree) => ({
3287
2490
  let name = "";
3288
2491
  if (data.name) {
3289
2492
  name = data.name;
3290
- } else if (data.type) {
3291
- name = data.type;
3292
2493
  } else if (data.items) {
3293
2494
  name = "container";
3294
2495
  }
3295
- return name.indexOf(value) !== -1;
2496
+ return `${data.id}${name}${data.type}`.indexOf(value) !== -1;
3296
2497
  },
3297
2498
  filterTextChangeHandler(val) {
3298
2499
  tree.value?.filter(val);
3299
2500
  }
3300
2501
  });
3301
- const useContentMenu = (editorService) => {
3302
- const menuStyle = ref({
3303
- position: "absolute",
3304
- left: "0",
3305
- top: "0",
3306
- display: "none"
3307
- });
3308
- onMounted(() => {
3309
- document.addEventListener("click", () => {
3310
- menuStyle.value.display = "none";
3311
- }, true);
3312
- });
3313
- return {
3314
- menuStyle,
3315
- contextmenu(event, data) {
3316
- const bodyHeight = globalThis.document.body.clientHeight;
3317
- const left = `${event.clientX + 20}px`;
3318
- let top = `${event.clientY - 10}px`;
3319
- if (event.clientY + 300 > bodyHeight) {
3320
- top = `${bodyHeight - 300}px`;
3321
- }
3322
- menuStyle.value.left = left;
3323
- menuStyle.value.top = top;
3324
- menuStyle.value.display = "";
3325
- select(data, editorService);
3326
- }
3327
- };
3328
- };
3329
- const _sfc_main$7 = defineComponent({
2502
+ const _sfc_main$8 = defineComponent({
3330
2503
  name: "magic-editor-layer-panel",
3331
2504
  components: { LayerMenu },
3332
2505
  setup() {
3333
2506
  const services = inject("services");
3334
2507
  const tree = ref();
2508
+ const menu = ref();
2509
+ const clicked = ref(false);
3335
2510
  const editorService = services?.editorService;
2511
+ const highlightHandler = throttle((data) => {
2512
+ highlight(data, editorService);
2513
+ }, throttleTime);
2514
+ const toggleClickFlag = () => {
2515
+ clicked.value = !clicked.value;
2516
+ };
2517
+ const statusData = useStatus(tree, editorService);
2518
+ const canHighlight = computed(() => statusData.highlightNode.value?.id !== statusData.clickNode.value?.id && !clicked.value);
2519
+ editorService?.on("remove", () => {
2520
+ setTimeout(() => {
2521
+ tree.value?.getNode(editorService.get("node").id)?.updateChildren();
2522
+ }, 0);
2523
+ });
3336
2524
  return {
3337
2525
  tree,
2526
+ menu,
2527
+ ...statusData,
3338
2528
  ...useDrop(tree, editorService),
3339
- ...useStatus(tree, editorService),
3340
2529
  ...useFilter(tree),
3341
- ...useContentMenu(editorService),
2530
+ highlightHandler,
2531
+ toggleClickFlag,
2532
+ canHighlight,
3342
2533
  clickHandler(data) {
3343
2534
  if (services?.uiService.get("uiSelectMode")) {
3344
2535
  document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
3345
2536
  return;
3346
2537
  }
2538
+ tree.value?.setCurrentKey(data.id);
3347
2539
  select(data, editorService);
2540
+ },
2541
+ async contextmenu(event, data) {
2542
+ event.preventDefault();
2543
+ await select(data, editorService);
2544
+ menu.value?.show(event);
3348
2545
  }
3349
2546
  };
3350
2547
  }
3351
2548
  });
3352
- function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2549
+ const _hoisted_1$4 = ["id", "onMouseenter"];
2550
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3353
2551
  const _component_el_input = resolveComponent("el-input");
3354
2552
  const _component_el_tree = resolveComponent("el-tree");
3355
2553
  const _component_layer_menu = resolveComponent("layer-menu");
@@ -3370,6 +2568,7 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3370
2568
  ref: "tree",
3371
2569
  "node-key": "id",
3372
2570
  draggable: "",
2571
+ "default-expanded-keys": _ctx.expandedKeys,
3373
2572
  load: _ctx.loadItems,
3374
2573
  data: _ctx.values,
3375
2574
  "expand-on-click-node": false,
@@ -3385,47 +2584,46 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3385
2584
  "empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684"
3386
2585
  }, {
3387
2586
  default: withCtx(({ node, data }) => [
3388
- renderSlot(_ctx.$slots, "layer-node-content", {
3389
- node,
3390
- data
3391
- }, () => [
3392
- createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
3393
- ])
2587
+ createElementVNode("div", {
2588
+ id: data.id,
2589
+ class: normalizeClass(["cus-tree-node", { "cus-tree-node-hover": _ctx.canHighlight && data.id === _ctx.highlightNode?.id }]),
2590
+ onMousedown: _cache[1] || (_cache[1] = (...args) => _ctx.toggleClickFlag && _ctx.toggleClickFlag(...args)),
2591
+ onMouseup: _cache[2] || (_cache[2] = (...args) => _ctx.toggleClickFlag && _ctx.toggleClickFlag(...args)),
2592
+ onMouseenter: ($event) => _ctx.highlightHandler(data)
2593
+ }, [
2594
+ renderSlot(_ctx.$slots, "layer-node-content", {
2595
+ node,
2596
+ data
2597
+ }, () => [
2598
+ createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
2599
+ ])
2600
+ ], 42, _hoisted_1$4)
3394
2601
  ]),
3395
2602
  _: 3
3396
- }, 8, ["load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd"])) : createCommentVNode("", true),
2603
+ }, 8, ["default-expanded-keys", "load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd"])) : createCommentVNode("", true),
3397
2604
  (openBlock(), createBlock(Teleport, { to: "body" }, [
3398
- createVNode(_component_layer_menu, {
3399
- style: normalizeStyle(_ctx.menuStyle)
3400
- }, null, 8, ["style"])
2605
+ createVNode(_component_layer_menu, { ref: "menu" }, null, 512)
3401
2606
  ]))
3402
2607
  ]),
3403
2608
  _: 3
3404
2609
  });
3405
2610
  }
3406
- var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
2611
+ var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3407
2612
 
3408
- const _sfc_main$6 = defineComponent({
3409
- name: "m-sidebar",
2613
+ const _sfc_main$7 = defineComponent({
3410
2614
  components: { MIcon },
3411
2615
  props: {
3412
2616
  data: {
3413
- type: Object,
3414
- default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
2617
+ type: Object
3415
2618
  }
3416
2619
  },
3417
2620
  setup(props) {
3418
- const activeTabName = ref(props.data?.status);
3419
- watch(() => props.data?.status, (status) => {
3420
- activeTabName.value = status || "0";
3421
- });
3422
2621
  return {
3423
- activeTabName,
3424
- items: computed(() => props.data?.items.map((item) => {
3425
- if (typeof item !== "string") {
3426
- return item;
2622
+ config: computed(() => {
2623
+ if (typeof props.data !== "string") {
2624
+ return props.data;
3427
2625
  }
3428
- switch (item) {
2626
+ switch (props.data) {
3429
2627
  case "component-list":
3430
2628
  return {
3431
2629
  type: "component",
@@ -3443,21 +2641,75 @@ const _sfc_main$6 = defineComponent({
3443
2641
  slots: {}
3444
2642
  };
3445
2643
  default:
3446
- return {};
2644
+ return void 0;
3447
2645
  }
3448
- }))
2646
+ })
2647
+ };
2648
+ }
2649
+ });
2650
+ const _hoisted_1$3 = {
2651
+ key: 1,
2652
+ class: "magic-editor-tab-panel-title"
2653
+ };
2654
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2655
+ const _component_m_icon = resolveComponent("m-icon");
2656
+ const _component_el_tab_pane = resolveComponent("el-tab-pane");
2657
+ return _ctx.config ? (openBlock(), createBlock(_component_el_tab_pane, {
2658
+ key: 0,
2659
+ name: _ctx.config.text
2660
+ }, {
2661
+ label: withCtx(() => [
2662
+ (openBlock(), createElementBlock("div", {
2663
+ key: _ctx.config.text
2664
+ }, [
2665
+ _ctx.config.icon ? (openBlock(), createBlock(_component_m_icon, {
2666
+ key: 0,
2667
+ icon: _ctx.config.icon
2668
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
2669
+ _ctx.config.text ? (openBlock(), createElementBlock("div", _hoisted_1$3, toDisplayString(_ctx.config.text), 1)) : createCommentVNode("", true)
2670
+ ]))
2671
+ ]),
2672
+ default: withCtx(() => [
2673
+ (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.component), mergeProps(_ctx.config.props || {}, toHandlers(_ctx.config?.listeners || {})), createSlots({ _: 2 }, [
2674
+ _ctx.config.slots?.layerNodeContent ? {
2675
+ name: "layer-node-content",
2676
+ fn: withCtx(({ data, node }) => [
2677
+ (openBlock(), createBlock(resolveDynamicComponent(_ctx.config.slots?.layerNodeContent), {
2678
+ data,
2679
+ node
2680
+ }, null, 8, ["data", "node"]))
2681
+ ])
2682
+ } : void 0
2683
+ ]), 1040))
2684
+ ]),
2685
+ _: 1
2686
+ }, 8, ["name"])) : createCommentVNode("", true);
2687
+ }
2688
+ var TabPane = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
2689
+
2690
+ const _sfc_main$6 = defineComponent({
2691
+ components: { TabPane },
2692
+ name: "m-sidebar",
2693
+ props: {
2694
+ data: {
2695
+ type: Object,
2696
+ default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
2697
+ }
2698
+ },
2699
+ setup(props) {
2700
+ const activeTabName = ref(props.data?.status);
2701
+ watch(() => props.data?.status, (status) => {
2702
+ activeTabName.value = status || "0";
2703
+ });
2704
+ return {
2705
+ activeTabName
3449
2706
  };
3450
2707
  }
3451
2708
  });
3452
- const _hoisted_1$4 = {
3453
- key: 1,
3454
- class: "magic-editor-tab-panel-title"
3455
- };
3456
2709
  function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3457
- const _component_m_icon = resolveComponent("m-icon");
3458
- const _component_el_tab_pane = resolveComponent("el-tab-pane");
2710
+ const _component_tab_pane = resolveComponent("tab-pane");
3459
2711
  const _component_el_tabs = resolveComponent("el-tabs");
3460
- return _ctx.data.type === "tabs" ? (openBlock(), createBlock(_component_el_tabs, {
2712
+ return _ctx.data.type === "tabs" && _ctx.data.items.length ? (openBlock(), createBlock(_component_el_tabs, {
3461
2713
  key: 0,
3462
2714
  class: "m-editor-sidebar",
3463
2715
  modelValue: _ctx.activeTabName,
@@ -3466,35 +2718,11 @@ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3466
2718
  "tab-position": "left"
3467
2719
  }, {
3468
2720
  default: withCtx(() => [
3469
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.items, (item) => {
3470
- return openBlock(), createBlock(_component_el_tab_pane, {
3471
- key: item.text,
3472
- name: item.text
3473
- }, {
3474
- label: withCtx(() => [
3475
- createElementVNode("span", null, [
3476
- item.icon ? (openBlock(), createBlock(_component_m_icon, {
3477
- key: 0,
3478
- icon: item.icon
3479
- }, null, 8, ["icon"])) : createCommentVNode("", true),
3480
- item.text ? (openBlock(), createElementBlock("div", _hoisted_1$4, toDisplayString(item.text), 1)) : createCommentVNode("", true)
3481
- ])
3482
- ]),
3483
- default: withCtx(() => [
3484
- (openBlock(), createBlock(resolveDynamicComponent(item.component), mergeProps(item.props || {}, toHandlers(item.listeners || {})), createSlots({ _: 2 }, [
3485
- item.slots?.layerNodeContent ? {
3486
- name: "layer-node-content",
3487
- fn: withCtx(({ data, node }) => [
3488
- (openBlock(), createBlock(resolveDynamicComponent(item.slots.layerNodeContent), {
3489
- data,
3490
- node
3491
- }, null, 8, ["data", "node"]))
3492
- ])
3493
- } : void 0
3494
- ]), 1040))
3495
- ]),
3496
- _: 2
3497
- }, 1032, ["name"]);
2721
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.data.items, (item, index) => {
2722
+ return openBlock(), createBlock(_component_tab_pane, {
2723
+ key: index,
2724
+ data: item
2725
+ }, null, 8, ["data"]);
3498
2726
  }), 128))
3499
2727
  ]),
3500
2728
  _: 1
@@ -3502,13 +2730,81 @@ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3502
2730
  }
3503
2731
  var Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$6]]);
3504
2732
 
2733
+ const useScroll = (root) => {
2734
+ const pageBar = ref();
2735
+ const itemsContainer = ref();
2736
+ const pageBarWidth = ref(0);
2737
+ const canScroll = ref(false);
2738
+ const itemsContainerWidth = computed(() => pageBarWidth.value - 105);
2739
+ let translateLeft = 0;
2740
+ const resizeObserver = new ResizeObserver((entries) => {
2741
+ for (const { contentRect } of entries) {
2742
+ const { width } = contentRect;
2743
+ pageBarWidth.value = width || 0;
2744
+ setCanScroll();
2745
+ }
2746
+ });
2747
+ const setCanScroll = () => {
2748
+ if (itemsContainer.value) {
2749
+ canScroll.value = itemsContainer.value.scrollWidth > pageBarWidth.value - 105;
2750
+ }
2751
+ };
2752
+ const scroll = (type) => {
2753
+ if (!itemsContainer.value)
2754
+ return;
2755
+ const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
2756
+ if (type === "left") {
2757
+ translateLeft += 100;
2758
+ if (translateLeft > 0) {
2759
+ translateLeft = 0;
2760
+ }
2761
+ } else if (type === "right") {
2762
+ translateLeft -= 100;
2763
+ if (-translateLeft > maxScrollLeft) {
2764
+ translateLeft = -maxScrollLeft;
2765
+ }
2766
+ } else if (type === "start") {
2767
+ translateLeft = 0;
2768
+ } else if (type === "end") {
2769
+ translateLeft = -maxScrollLeft;
2770
+ }
2771
+ itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
2772
+ };
2773
+ onMounted(() => {
2774
+ pageBar.value && resizeObserver.observe(pageBar.value);
2775
+ });
2776
+ onUnmounted(() => {
2777
+ resizeObserver.disconnect();
2778
+ });
2779
+ watch(() => root.value?.items.length, (length = 0, preLength = 0) => {
2780
+ setTimeout(() => {
2781
+ setCanScroll();
2782
+ if (length < preLength) {
2783
+ scroll("start");
2784
+ } else {
2785
+ scroll("end");
2786
+ }
2787
+ });
2788
+ });
2789
+ return {
2790
+ pageBar,
2791
+ itemsContainer,
2792
+ canScroll,
2793
+ itemsContainerWidth,
2794
+ scroll
2795
+ };
2796
+ };
3505
2797
  const _sfc_main$5 = defineComponent({
3506
- components: { CaretBottom, Plus },
2798
+ components: { ArrowLeftBold, ArrowRightBold, CaretBottom, Plus, ToolButton },
3507
2799
  setup() {
3508
2800
  const services = inject("services");
3509
2801
  const editorService = services?.editorService;
2802
+ const root = computed(() => editorService?.get("root"));
3510
2803
  return {
3511
- root: computed(() => editorService?.get("root")),
2804
+ Delete: markRaw(Delete),
2805
+ DocumentCopy: markRaw(DocumentCopy),
2806
+ ...useScroll(root),
2807
+ root,
3512
2808
  page: computed(() => editorService?.get("page")),
3513
2809
  switchPage(page) {
3514
2810
  editorService?.select(page);
@@ -3517,7 +2813,7 @@ const _sfc_main$5 = defineComponent({
3517
2813
  if (!editorService)
3518
2814
  return;
3519
2815
  const pageConfig = {
3520
- type: "page",
2816
+ type: NodeType.PAGE,
3521
2817
  name: generatePageNameByApp(toRaw(editorService.get("root")))
3522
2818
  };
3523
2819
  editorService.add(pageConfig);
@@ -3535,99 +2831,228 @@ const _sfc_main$5 = defineComponent({
3535
2831
  };
3536
2832
  }
3537
2833
  });
3538
- const _hoisted_1$3 = { class: "m-editor-page-bar" };
3539
- const _hoisted_2$1 = ["onClick"];
3540
- const _hoisted_3$1 = ["onClick"];
3541
- const _hoisted_4$1 = ["onClick"];
2834
+ const _hoisted_1$2 = {
2835
+ class: "m-editor-page-bar",
2836
+ ref: "pageBar"
2837
+ };
2838
+ const _hoisted_2 = ["onClick"];
2839
+ const _hoisted_3 = { class: "m-editor-page-bar-title" };
3542
2840
  function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3543
2841
  const _component_plus = resolveComponent("plus");
3544
2842
  const _component_el_icon = resolveComponent("el-icon");
2843
+ const _component_arrow_left_bold = resolveComponent("arrow-left-bold");
2844
+ const _component_el_tooltip = resolveComponent("el-tooltip");
2845
+ const _component_tool_button = resolveComponent("tool-button");
3545
2846
  const _component_caret_bottom = resolveComponent("caret-bottom");
3546
2847
  const _component_el_popover = resolveComponent("el-popover");
3547
- return openBlock(), createElementBlock("div", _hoisted_1$3, [
2848
+ const _component_arrow_right_bold = resolveComponent("arrow-right-bold");
2849
+ return openBlock(), createElementBlock("div", _hoisted_1$2, [
3548
2850
  createElementVNode("div", {
3549
- class: "m-editor-page-bar-item",
2851
+ id: "m-editor-page-bar-add-icon",
2852
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3550
2853
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.addPage && _ctx.addPage(...args))
3551
2854
  }, [
3552
- createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-add-icon" }, {
2855
+ createVNode(_component_el_icon, null, {
3553
2856
  default: withCtx(() => [
3554
2857
  createVNode(_component_plus)
3555
2858
  ]),
3556
2859
  _: 1
3557
2860
  })
3558
2861
  ]),
3559
- _ctx.root ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(_ctx.root.items, (item) => {
3560
- return openBlock(), createElementBlock("div", {
3561
- key: item.key,
3562
- class: normalizeClass(["m-editor-page-bar-item", { active: _ctx.page?.id === item.id }]),
3563
- onClick: ($event) => _ctx.switchPage(item)
3564
- }, [
3565
- renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
3566
- createElementVNode("span", null, toDisplayString(item.name), 1)
2862
+ _ctx.canScroll ? (openBlock(), createElementBlock("div", {
2863
+ key: 0,
2864
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
2865
+ onClick: _cache[1] || (_cache[1] = ($event) => _ctx.scroll("left"))
2866
+ }, [
2867
+ createVNode(_component_el_icon, null, {
2868
+ default: withCtx(() => [
2869
+ createVNode(_component_arrow_left_bold)
3567
2870
  ]),
3568
- createVNode(_component_el_popover, {
3569
- placement: "top",
3570
- width: 160,
3571
- trigger: "hover"
3572
- }, {
3573
- reference: withCtx(() => [
3574
- createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-icon" }, {
3575
- default: withCtx(() => [
3576
- createVNode(_component_caret_bottom)
3577
- ]),
3578
- _: 1
3579
- })
3580
- ]),
3581
- default: withCtx(() => [
3582
- createElementVNode("div", null, [
3583
- renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3584
- createElementVNode("div", {
3585
- class: "magic-editor-content-menu-item",
3586
- onClick: () => _ctx.copy(item)
3587
- }, "\u590D\u5236", 8, _hoisted_3$1),
3588
- createElementVNode("div", {
3589
- class: "magic-editor-content-menu-item",
3590
- onClick: () => _ctx.remove(item)
3591
- }, "\u5220\u9664", 8, _hoisted_4$1)
3592
- ])
2871
+ _: 1
2872
+ })
2873
+ ])) : createCommentVNode("", true),
2874
+ _ctx.root ? (openBlock(), createElementBlock("div", {
2875
+ key: 1,
2876
+ class: "m-editor-page-bar-items",
2877
+ ref: "itemsContainer",
2878
+ style: normalizeStyle(`width: ${_ctx.itemsContainerWidth}px`)
2879
+ }, [
2880
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.root.items, (item) => {
2881
+ return openBlock(), createElementBlock("div", {
2882
+ key: item.key,
2883
+ class: normalizeClass(["m-editor-page-bar-item", { active: _ctx.page?.id === item.id }]),
2884
+ onClick: ($event) => _ctx.switchPage(item)
2885
+ }, [
2886
+ createElementVNode("div", _hoisted_3, [
2887
+ renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
2888
+ createVNode(_component_el_tooltip, {
2889
+ effect: "dark",
2890
+ placement: "top-start",
2891
+ content: item.name
2892
+ }, {
2893
+ default: withCtx(() => [
2894
+ createElementVNode("span", null, toDisplayString(item.name), 1)
2895
+ ]),
2896
+ _: 2
2897
+ }, 1032, ["content"])
3593
2898
  ])
3594
2899
  ]),
3595
- _: 2
3596
- }, 1024)
3597
- ], 10, _hoisted_2$1);
3598
- }), 128)) : createCommentVNode("", true)
3599
- ]);
2900
+ createVNode(_component_el_popover, {
2901
+ "popper-class": "page-bar-popover",
2902
+ placement: "top",
2903
+ width: 160,
2904
+ trigger: "hover"
2905
+ }, {
2906
+ reference: withCtx(() => [
2907
+ createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-icon" }, {
2908
+ default: withCtx(() => [
2909
+ createVNode(_component_caret_bottom)
2910
+ ]),
2911
+ _: 1
2912
+ })
2913
+ ]),
2914
+ default: withCtx(() => [
2915
+ createElementVNode("div", null, [
2916
+ renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
2917
+ createVNode(_component_tool_button, {
2918
+ data: {
2919
+ type: "button",
2920
+ text: "\u590D\u5236",
2921
+ icon: _ctx.DocumentCopy,
2922
+ handler: () => _ctx.copy(item)
2923
+ }
2924
+ }, null, 8, ["data"]),
2925
+ createVNode(_component_tool_button, {
2926
+ data: {
2927
+ type: "button",
2928
+ text: "\u5220\u9664",
2929
+ icon: _ctx.Delete,
2930
+ handler: () => _ctx.remove(item)
2931
+ }
2932
+ }, null, 8, ["data"])
2933
+ ])
2934
+ ])
2935
+ ]),
2936
+ _: 2
2937
+ }, 1024)
2938
+ ], 10, _hoisted_2);
2939
+ }), 128))
2940
+ ], 4)) : createCommentVNode("", true),
2941
+ _ctx.canScroll ? (openBlock(), createElementBlock("div", {
2942
+ key: 2,
2943
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
2944
+ onClick: _cache[2] || (_cache[2] = ($event) => _ctx.scroll("right"))
2945
+ }, [
2946
+ createVNode(_component_el_icon, null, {
2947
+ default: withCtx(() => [
2948
+ createVNode(_component_arrow_right_bold)
2949
+ ]),
2950
+ _: 1
2951
+ })
2952
+ ])) : createCommentVNode("", true)
2953
+ ], 512);
3600
2954
  }
3601
2955
  var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3602
2956
 
3603
2957
  class ScrollViewer$1 {
3604
- enter = false;
3605
- targetEnter = false;
3606
- keydown = false;
3607
- container;
3608
- target;
3609
- zoom = 1;
3610
- scrollLeft = 0;
3611
- scrollTop = 0;
3612
- x = 0;
3613
- y = 0;
3614
- resizeObserver = new ResizeObserver((entries) => {
3615
- for (const { contentRect } of entries) {
3616
- const { width, height } = contentRect;
3617
- const targetRect = this.target.getBoundingClientRect();
3618
- const targetWidth = targetRect.width * this.zoom;
3619
- const targetMarginTop = Number(this.target.style.marginTop) || 0;
3620
- const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3621
- if (targetWidth < width) {
3622
- this.target._left = 0;
3623
- }
3624
- if (targetHeight < height) {
3625
- this.target._top = 0;
2958
+ constructor(options) {
2959
+ this.enter = false;
2960
+ this.targetEnter = false;
2961
+ this.keydown = false;
2962
+ this.zoom = 1;
2963
+ this.scrollLeft = 0;
2964
+ this.scrollTop = 0;
2965
+ this.x = 0;
2966
+ this.y = 0;
2967
+ this.resizeObserver = new ResizeObserver((entries) => {
2968
+ for (const { contentRect } of entries) {
2969
+ const { width, height } = contentRect;
2970
+ const targetRect = this.target.getBoundingClientRect();
2971
+ const targetWidth = targetRect.width * this.zoom;
2972
+ const targetMarginTop = Number(this.target.style.marginTop) || 0;
2973
+ const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
2974
+ if (targetWidth < width) {
2975
+ this.target._left = 0;
2976
+ }
2977
+ if (targetHeight < height) {
2978
+ this.target._top = 0;
2979
+ }
2980
+ this.scroll();
3626
2981
  }
2982
+ });
2983
+ this.wheelHandler = (event) => {
2984
+ if (this.targetEnter)
2985
+ return;
2986
+ const { deltaX, deltaY, currentTarget } = event;
2987
+ if (currentTarget !== this.container)
2988
+ return;
2989
+ this.setScrollOffset(deltaX, deltaY);
3627
2990
  this.scroll();
3628
- }
3629
- });
3630
- constructor(options) {
2991
+ this.scrollLeft = this.target._left;
2992
+ this.scrollTop = this.target._top;
2993
+ };
2994
+ this.mouseEnterHandler = () => {
2995
+ this.enter = true;
2996
+ };
2997
+ this.mouseLeaveHandler = () => {
2998
+ this.enter = false;
2999
+ };
3000
+ this.targetMouseEnterHandler = () => {
3001
+ this.targetEnter = true;
3002
+ };
3003
+ this.targetMouseLeaveHandler = () => {
3004
+ this.targetEnter = false;
3005
+ };
3006
+ this.mousedownHandler = (event) => {
3007
+ if (!this.keydown)
3008
+ return;
3009
+ event.stopImmediatePropagation();
3010
+ event.stopPropagation();
3011
+ this.target.style.cursor = "grabbing";
3012
+ this.x = event.clientX;
3013
+ this.y = event.clientY;
3014
+ document.addEventListener("mousemove", this.mousemoveHandler);
3015
+ document.addEventListener("mouseup", this.mouseupHandler);
3016
+ };
3017
+ this.mouseupHandler = () => {
3018
+ this.x = 0;
3019
+ this.y = 0;
3020
+ this.scrollLeft = this.target._left;
3021
+ this.scrollTop = this.target._top;
3022
+ this.removeHandler();
3023
+ };
3024
+ this.mousemoveHandler = (event) => {
3025
+ event.stopImmediatePropagation();
3026
+ event.stopPropagation();
3027
+ const deltaX = event.clientX - this.x;
3028
+ const deltaY = event.clientY - this.y;
3029
+ this.setScrollOffset(deltaX, deltaY);
3030
+ this.scroll();
3031
+ };
3032
+ this.keydownHandler = (event) => {
3033
+ if (event.code === Keys.ESCAPE && this.enter) {
3034
+ event.preventDefault();
3035
+ event.stopImmediatePropagation();
3036
+ event.stopPropagation();
3037
+ }
3038
+ if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3039
+ return;
3040
+ }
3041
+ this.keydown = true;
3042
+ this.target.style.cursor = "grab";
3043
+ this.container.addEventListener("mousedown", this.mousedownHandler);
3044
+ };
3045
+ this.keyupHandler = (event) => {
3046
+ if (event.code !== Keys.ESCAPE || !this.keydown) {
3047
+ return;
3048
+ }
3049
+ event.preventDefault();
3050
+ event.stopImmediatePropagation();
3051
+ event.stopPropagation();
3052
+ this.keydown = false;
3053
+ event.preventDefault();
3054
+ this.removeHandler();
3055
+ };
3631
3056
  this.container = options.container;
3632
3057
  this.target = options.target;
3633
3058
  this.zoom = options.zoom;
@@ -3663,79 +3088,6 @@ class ScrollViewer$1 {
3663
3088
  document.removeEventListener("mousemove", this.mousemoveHandler);
3664
3089
  document.removeEventListener("mouseup", this.mouseupHandler);
3665
3090
  }
3666
- wheelHandler = (event) => {
3667
- if (this.targetEnter)
3668
- return;
3669
- const { deltaX, deltaY, currentTarget } = event;
3670
- if (currentTarget !== this.container)
3671
- return;
3672
- this.setScrollOffset(deltaX, deltaY);
3673
- this.scroll();
3674
- this.scrollLeft = this.target._left;
3675
- this.scrollTop = this.target._top;
3676
- };
3677
- mouseEnterHandler = () => {
3678
- this.enter = true;
3679
- };
3680
- mouseLeaveHandler = () => {
3681
- this.enter = false;
3682
- };
3683
- targetMouseEnterHandler = () => {
3684
- this.targetEnter = true;
3685
- };
3686
- targetMouseLeaveHandler = () => {
3687
- this.targetEnter = false;
3688
- };
3689
- mousedownHandler = (event) => {
3690
- if (!this.keydown)
3691
- return;
3692
- event.stopImmediatePropagation();
3693
- event.stopPropagation();
3694
- this.target.style.cursor = "grabbing";
3695
- this.x = event.clientX;
3696
- this.y = event.clientY;
3697
- document.addEventListener("mousemove", this.mousemoveHandler);
3698
- document.addEventListener("mouseup", this.mouseupHandler);
3699
- };
3700
- mouseupHandler = () => {
3701
- this.x = 0;
3702
- this.y = 0;
3703
- this.scrollLeft = this.target._left;
3704
- this.scrollTop = this.target._top;
3705
- this.removeHandler();
3706
- };
3707
- mousemoveHandler = (event) => {
3708
- event.stopImmediatePropagation();
3709
- event.stopPropagation();
3710
- const deltaX = event.clientX - this.x;
3711
- const deltaY = event.clientY - this.y;
3712
- this.setScrollOffset(deltaX, deltaY);
3713
- this.scroll();
3714
- };
3715
- keydownHandler = (event) => {
3716
- if (event.code === Keys.ESCAPE && this.enter) {
3717
- event.preventDefault();
3718
- event.stopImmediatePropagation();
3719
- event.stopPropagation();
3720
- }
3721
- if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3722
- return;
3723
- }
3724
- this.keydown = true;
3725
- this.target.style.cursor = "grab";
3726
- this.container.addEventListener("mousedown", this.mousedownHandler);
3727
- };
3728
- keyupHandler = (event) => {
3729
- if (event.code !== Keys.ESCAPE || !this.keydown) {
3730
- return;
3731
- }
3732
- event.preventDefault();
3733
- event.stopImmediatePropagation();
3734
- event.stopPropagation();
3735
- this.keydown = false;
3736
- event.preventDefault();
3737
- this.removeHandler();
3738
- };
3739
3091
  setScrollOffset(deltaX, deltaY) {
3740
3092
  const { width, height } = this.container.getBoundingClientRect();
3741
3093
  const targetRect = this.target.getBoundingClientRect();
@@ -3796,19 +3148,19 @@ const _sfc_main$4 = defineComponent({
3796
3148
  el,
3797
3149
  style: computed(() => `
3798
3150
  width: ${props.width}px;
3799
- height: ${props.height}px;
3151
+ height: ${(props.height || 0) - 40}px;
3800
3152
  position: absolute;
3801
3153
  margin-top: 30px;
3802
3154
  `)
3803
3155
  };
3804
3156
  }
3805
3157
  });
3806
- const _hoisted_1$2 = {
3158
+ const _hoisted_1$1 = {
3807
3159
  class: "m-editor-scroll-viewer-container",
3808
3160
  ref: "container"
3809
3161
  };
3810
3162
  function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3811
- return openBlock(), createElementBlock("div", _hoisted_1$2, [
3163
+ return openBlock(), createElementBlock("div", _hoisted_1$1, [
3812
3164
  createElementVNode("div", {
3813
3165
  ref: "el",
3814
3166
  style: normalizeStyle(_ctx.style)
@@ -3820,7 +3172,7 @@ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3820
3172
  var ScrollViewer = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$4]]);
3821
3173
 
3822
3174
  const _sfc_main$3 = defineComponent({
3823
- name: "magic-editor-ui-viewer-menu",
3175
+ components: { ContentMenu },
3824
3176
  setup() {
3825
3177
  const services = inject("services");
3826
3178
  const editorService = services?.editorService;
@@ -3829,6 +3181,7 @@ const _sfc_main$3 = defineComponent({
3829
3181
  const canCenter = ref(false);
3830
3182
  const node = computed(() => editorService?.get("node"));
3831
3183
  const parent = computed(() => editorService?.get("parent"));
3184
+ const isPage = computed(() => node.value?.type === NodeType.PAGE);
3832
3185
  onMounted(() => {
3833
3186
  const data = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
3834
3187
  canPaste.value = data !== "undefined" && !!data;
@@ -3837,137 +3190,118 @@ const _sfc_main$3 = defineComponent({
3837
3190
  if (!parent.value || !editorService)
3838
3191
  return canCenter.value = false;
3839
3192
  const layout = await editorService.getLayout(parent.value);
3840
- canCenter.value = [Layout.ABSOLUTE, Layout.FIXED].includes(layout) && !["app", "page", "pop"].includes(`${node.value?.type}`);
3193
+ canCenter.value = [Layout.ABSOLUTE, Layout.FIXED].includes(layout) && ![NodeType.ROOT, NodeType.PAGE, "pop"].includes(`${node.value?.type}`);
3841
3194
  }, { immediate: true });
3842
3195
  return {
3843
3196
  menu,
3844
- canPaste,
3845
- canDelete: computed(() => node.value?.type !== "page"),
3846
- canMoveZPos: computed(() => node.value?.type !== "page"),
3847
- canCenter,
3848
- center() {
3849
- node.value && editorService?.alignCenter(node.value);
3850
- },
3851
- copy() {
3852
- node.value && editorService?.copy(node.value);
3853
- canPaste.value = true;
3854
- },
3855
- paste() {
3856
- const top = menu.value?.offsetTop || 0;
3857
- const left = menu.value?.offsetLeft || 0;
3858
- editorService?.paste({ left, top });
3859
- },
3860
- remove() {
3861
- node.value && editorService?.remove(node.value);
3862
- },
3863
- top() {
3864
- editorService?.moveLayer(LayerOffset.TOP);
3865
- },
3866
- bottom() {
3867
- editorService?.moveLayer(LayerOffset.BOTTOM);
3868
- },
3869
- topItem() {
3870
- editorService?.moveLayer(1);
3871
- },
3872
- bottomItem() {
3873
- editorService?.moveLayer(-1);
3874
- },
3875
- clearGuides() {
3876
- editorService?.get("stage").clearGuides();
3197
+ menuData: reactive([
3198
+ {
3199
+ type: "button",
3200
+ text: "\u6C34\u5E73\u5C45\u4E2D",
3201
+ display: () => canCenter.value,
3202
+ handler: () => {
3203
+ node.value && editorService?.alignCenter(node.value);
3204
+ }
3205
+ },
3206
+ {
3207
+ type: "button",
3208
+ text: "\u590D\u5236",
3209
+ icon: markRaw(DocumentCopy),
3210
+ handler: () => {
3211
+ node.value && editorService?.copy(node.value);
3212
+ canPaste.value = true;
3213
+ }
3214
+ },
3215
+ {
3216
+ type: "button",
3217
+ text: "\u7C98\u8D34",
3218
+ display: () => canPaste.value,
3219
+ handler: () => {
3220
+ const top = menu.value?.$el.offsetTop || 0;
3221
+ const left = menu.value?.$el.offsetLeft || 0;
3222
+ editorService?.paste({ left, top });
3223
+ }
3224
+ },
3225
+ {
3226
+ type: "divider",
3227
+ direction: "horizontal",
3228
+ display: () => !isPage.value
3229
+ },
3230
+ {
3231
+ type: "button",
3232
+ text: "\u4E0A\u79FB\u4E00\u5C42",
3233
+ icon: markRaw(Top),
3234
+ display: () => !isPage.value,
3235
+ handler: () => {
3236
+ editorService?.moveLayer(1);
3237
+ }
3238
+ },
3239
+ {
3240
+ type: "button",
3241
+ text: "\u4E0B\u79FB\u4E00\u5C42",
3242
+ icon: markRaw(Bottom),
3243
+ display: () => !isPage.value,
3244
+ handler: () => {
3245
+ editorService?.moveLayer(-1);
3246
+ }
3247
+ },
3248
+ {
3249
+ type: "button",
3250
+ text: "\u7F6E\u9876",
3251
+ display: () => !isPage.value,
3252
+ handler: () => {
3253
+ editorService?.moveLayer(LayerOffset.TOP);
3254
+ }
3255
+ },
3256
+ {
3257
+ type: "button",
3258
+ text: "\u7F6E\u5E95",
3259
+ display: () => !isPage.value,
3260
+ handler: () => {
3261
+ editorService?.moveLayer(LayerOffset.BOTTOM);
3262
+ }
3263
+ },
3264
+ {
3265
+ type: "divider",
3266
+ direction: "horizontal",
3267
+ display: () => !isPage.value
3268
+ },
3269
+ {
3270
+ type: "button",
3271
+ text: "\u5220\u9664",
3272
+ icon: Delete,
3273
+ display: () => !isPage.value,
3274
+ handler: () => {
3275
+ node.value && editorService?.remove(node.value);
3276
+ }
3277
+ },
3278
+ {
3279
+ type: "divider",
3280
+ direction: "horizontal"
3281
+ },
3282
+ {
3283
+ type: "button",
3284
+ text: "\u6E05\u7A7A\u53C2\u8003\u7EBF",
3285
+ handler: () => {
3286
+ editorService?.get("stage").clearGuides();
3287
+ }
3288
+ }
3289
+ ]),
3290
+ show(e) {
3291
+ menu.value?.show(e);
3877
3292
  }
3878
3293
  };
3879
3294
  }
3880
3295
  });
3881
- const _hoisted_1$1 = {
3882
- class: "magic-editor-content-menu",
3883
- ref: "menu"
3884
- };
3885
- const _hoisted_2 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3886
- const _hoisted_3 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3887
- const _hoisted_4 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3888
3296
  function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3889
- return openBlock(), createElementBlock("div", _hoisted_1$1, [
3890
- createElementVNode("div", null, [
3891
- _ctx.canCenter ? (openBlock(), createElementBlock("div", {
3892
- key: 0,
3893
- class: "magic-editor-content-menu-item",
3894
- onClick: _cache[0] || (_cache[0] = () => _ctx.center())
3895
- }, "\u6C34\u5E73\u5C45\u4E2D")) : createCommentVNode("", true),
3896
- createElementVNode("div", {
3897
- class: "magic-editor-content-menu-item",
3898
- onClick: _cache[1] || (_cache[1] = () => _ctx.copy())
3899
- }, "\u590D\u5236"),
3900
- _ctx.canPaste ? (openBlock(), createElementBlock("div", {
3901
- key: 1,
3902
- class: "magic-editor-content-menu-item",
3903
- onClick: _cache[2] || (_cache[2] = (...args) => _ctx.paste && _ctx.paste(...args))
3904
- }, "\u7C98\u8D34")) : createCommentVNode("", true),
3905
- _ctx.canMoveZPos ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
3906
- _hoisted_2,
3907
- createElementVNode("div", {
3908
- class: "magic-editor-content-menu-item",
3909
- onClick: _cache[3] || (_cache[3] = (...args) => _ctx.topItem && _ctx.topItem(...args))
3910
- }, "\u4E0A\u79FB\u4E00\u5C42"),
3911
- createElementVNode("div", {
3912
- class: "magic-editor-content-menu-item",
3913
- onClick: _cache[4] || (_cache[4] = (...args) => _ctx.bottomItem && _ctx.bottomItem(...args))
3914
- }, "\u4E0B\u79FB\u4E00\u5C42"),
3915
- createElementVNode("div", {
3916
- class: "magic-editor-content-menu-item",
3917
- onClick: _cache[5] || (_cache[5] = (...args) => _ctx.top && _ctx.top(...args))
3918
- }, "\u7F6E\u9876"),
3919
- createElementVNode("div", {
3920
- class: "magic-editor-content-menu-item",
3921
- onClick: _cache[6] || (_cache[6] = (...args) => _ctx.bottom && _ctx.bottom(...args))
3922
- }, "\u7F6E\u5E95")
3923
- ], 64)) : createCommentVNode("", true),
3924
- _ctx.canDelete ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
3925
- _hoisted_3,
3926
- createElementVNode("div", {
3927
- class: "magic-editor-content-menu-item",
3928
- onClick: _cache[7] || (_cache[7] = () => _ctx.remove())
3929
- }, "\u5220\u9664")
3930
- ], 64)) : createCommentVNode("", true),
3931
- _hoisted_4,
3932
- createElementVNode("div", {
3933
- class: "magic-editor-content-menu-item",
3934
- onClick: _cache[8] || (_cache[8] = (...args) => _ctx.clearGuides && _ctx.clearGuides(...args))
3935
- }, "\u6E05\u7A7A\u53C2\u8003\u7EBF")
3936
- ])
3937
- ], 512);
3297
+ const _component_content_menu = resolveComponent("content-menu");
3298
+ return openBlock(), createBlock(_component_content_menu, {
3299
+ "menu-data": _ctx.menuData,
3300
+ ref: "menu"
3301
+ }, null, 8, ["menu-data"]);
3938
3302
  }
3939
3303
  var ViewerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
3940
3304
 
3941
- const useMenu = () => {
3942
- const menu = ref();
3943
- const menuStyle = ref({
3944
- display: "none",
3945
- left: "0",
3946
- top: "0"
3947
- });
3948
- onMounted(() => {
3949
- document.addEventListener("click", () => {
3950
- menuStyle.value.display = "none";
3951
- }, true);
3952
- });
3953
- return {
3954
- menu,
3955
- menuStyle,
3956
- contextmenuHandler(e) {
3957
- e.preventDefault();
3958
- const menuHeight = menu.value?.$el.clientHeight;
3959
- let top = e.clientY;
3960
- if (menuHeight + e.clientY > document.body.clientHeight) {
3961
- top = document.body.clientHeight - menuHeight;
3962
- }
3963
- menuStyle.value = {
3964
- display: "block",
3965
- top: `${top}px`,
3966
- left: `${e.clientX}px`
3967
- };
3968
- }
3969
- };
3970
- };
3971
3305
  const _sfc_main$2 = defineComponent({
3972
3306
  name: "magic-stage",
3973
3307
  components: {
@@ -3990,16 +3324,16 @@ const _sfc_main$2 = defineComponent({
3990
3324
  })
3991
3325
  }
3992
3326
  },
3993
- emits: ["select", "update", "sort"],
3994
- setup(props, { emit }) {
3327
+ setup(props) {
3995
3328
  const services = inject("services");
3996
3329
  const stageWrap = ref();
3997
3330
  const stageContainer = ref();
3331
+ const menu = ref();
3998
3332
  const stageRect = computed(() => services?.uiService.get("stageRect"));
3999
3333
  const uiSelectMode = computed(() => services?.uiService.get("uiSelectMode"));
4000
3334
  const root = computed(() => services?.editorService.get("root"));
4001
3335
  const page = computed(() => services?.editorService.get("page"));
4002
- const zoom = computed(() => services?.uiService.get("zoom"));
3336
+ const zoom = computed(() => services?.uiService.get("zoom") || 1);
4003
3337
  const node = computed(() => services?.editorService.get("node"));
4004
3338
  let stage = null;
4005
3339
  let runtime = null;
@@ -4014,9 +3348,9 @@ const _sfc_main$2 = defineComponent({
4014
3348
  render: props.render,
4015
3349
  runtimeUrl: props.runtimeUrl,
4016
3350
  zoom: zoom.value,
4017
- canSelect: (el, stop) => {
3351
+ canSelect: (el, event, stop) => {
4018
3352
  const elCanSelect = props.canSelect(el);
4019
- if (uiSelectMode.value && elCanSelect) {
3353
+ if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
4020
3354
  document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
4021
3355
  return stop();
4022
3356
  }
@@ -4024,14 +3358,19 @@ const _sfc_main$2 = defineComponent({
4024
3358
  },
4025
3359
  moveableOptions: props.moveableOptions
4026
3360
  });
4027
- services?.editorService.set("stage", stage);
3361
+ services?.editorService.set("stage", markRaw(stage));
4028
3362
  stage?.mount(stageContainer.value);
4029
- stage?.on("select", (el) => emit("select", el));
3363
+ stage?.on("select", (el) => {
3364
+ services?.editorService.select(el.id);
3365
+ });
3366
+ stage?.on("highlight", (el) => {
3367
+ services?.editorService.highlight(el.id);
3368
+ });
4030
3369
  stage?.on("update", (ev) => {
4031
- emit("update", { id: ev.el.id, style: ev.style });
3370
+ services?.editorService.update({ id: ev.el.id, style: ev.style });
4032
3371
  });
4033
3372
  stage?.on("sort", (ev) => {
4034
- emit("sort", ev);
3373
+ services?.editorService.sort(ev.src, ev.dist);
4035
3374
  });
4036
3375
  stage?.on("changeGuides", () => {
4037
3376
  services?.uiService.set("showGuides", true);
@@ -4057,11 +3396,6 @@ const _sfc_main$2 = defineComponent({
4057
3396
  runtime.updateRootConfig(cloneDeep(toRaw(root2)));
4058
3397
  }
4059
3398
  });
4060
- watch(() => node.value?.id, (id) => {
4061
- nextTick(() => {
4062
- id && stage?.select(id);
4063
- });
4064
- });
4065
3399
  const resizeObserver = new ResizeObserver((entries) => {
4066
3400
  for (const { contentRect } of entries) {
4067
3401
  services?.uiService.set("stageContainerRect", {
@@ -4081,9 +3415,37 @@ const _sfc_main$2 = defineComponent({
4081
3415
  return {
4082
3416
  stageWrap,
4083
3417
  stageContainer,
3418
+ menu,
4084
3419
  stageRect,
4085
3420
  zoom,
4086
- ...useMenu()
3421
+ contextmenuHandler(e2) {
3422
+ e2.preventDefault();
3423
+ menu.value?.show(e2);
3424
+ },
3425
+ dragoverHandler(e2) {
3426
+ e2.preventDefault();
3427
+ if (e2.dataTransfer) {
3428
+ e2.dataTransfer.dropEffect = "move";
3429
+ }
3430
+ },
3431
+ async dropHandler(e) {
3432
+ e.preventDefault();
3433
+ if (e.dataTransfer && page.value && stageContainer.value && stage) {
3434
+ const config = eval(`(${e.dataTransfer.getData("data")})`);
3435
+ const layout = await services?.editorService.getLayout(page.value);
3436
+ const containerRect = stageContainer.value.getBoundingClientRect();
3437
+ const { scrollTop, scrollLeft } = stage.mask;
3438
+ if (layout === Layout.ABSOLUTE) {
3439
+ config.style = {
3440
+ ...config.style || {},
3441
+ position: "absolute",
3442
+ top: e.clientY - containerRect.top + scrollTop,
3443
+ left: e.clientX - containerRect.left + scrollLeft
3444
+ };
3445
+ }
3446
+ services?.editorService.add(config, page.value);
3447
+ }
3448
+ }
4087
3449
  };
4088
3450
  }
4089
3451
  });
@@ -4101,14 +3463,13 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
4101
3463
  createElementVNode("div", {
4102
3464
  class: "m-editor-stage-container",
4103
3465
  ref: "stageContainer",
3466
+ style: normalizeStyle(`transform: scale(${_ctx.zoom})`),
4104
3467
  onContextmenu: _cache[0] || (_cache[0] = (...args) => _ctx.contextmenuHandler && _ctx.contextmenuHandler(...args)),
4105
- style: normalizeStyle(`transform: scale(${_ctx.zoom})`)
3468
+ onDrop: _cache[1] || (_cache[1] = (...args) => _ctx.dropHandler && _ctx.dropHandler(...args)),
3469
+ onDragover: _cache[2] || (_cache[2] = (...args) => _ctx.dragoverHandler && _ctx.dragoverHandler(...args))
4106
3470
  }, null, 36),
4107
3471
  (openBlock(), createBlock(Teleport, { to: "body" }, [
4108
- createVNode(_component_viewer_menu, {
4109
- ref: "menu",
4110
- style: normalizeStyle(_ctx.menuStyle)
4111
- }, null, 8, ["style"])
3472
+ createVNode(_component_viewer_menu, { ref: "menu" }, null, 512)
4112
3473
  ]))
4113
3474
  ]),
4114
3475
  _: 1
@@ -4136,21 +3497,93 @@ const _sfc_main$1 = defineComponent({
4136
3497
  },
4137
3498
  setup() {
4138
3499
  const services = inject("services");
3500
+ const workspace = ref();
3501
+ const node = computed(() => services?.editorService.get("node"));
3502
+ let keycon;
3503
+ const mouseenterHandler = () => {
3504
+ workspace.value?.focus();
3505
+ };
3506
+ const mouseleaveHandler = () => {
3507
+ workspace.value?.blur();
3508
+ };
3509
+ onMounted(() => {
3510
+ workspace.value?.addEventListener("mouseenter", mouseenterHandler);
3511
+ workspace.value?.addEventListener("mouseleave", mouseleaveHandler);
3512
+ keycon = new KeyController(workspace.value);
3513
+ const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
3514
+ const ctrl = isMac ? "meta" : "ctrl";
3515
+ keycon.keydown((e) => {
3516
+ console.log(e);
3517
+ e.inputEvent.preventDefault();
3518
+ }).keyup("delete", (e) => {
3519
+ e.inputEvent.preventDefault();
3520
+ if (!node.value || isPage(node.value))
3521
+ return;
3522
+ services?.editorService.remove(node.value);
3523
+ }).keyup("backspace", (e) => {
3524
+ e.inputEvent.preventDefault();
3525
+ if (!node.value || isPage(node.value))
3526
+ return;
3527
+ services?.editorService.remove(node.value);
3528
+ }).keydown([ctrl, "c"], () => {
3529
+ node.value && services?.editorService.copy(node.value);
3530
+ }).keydown([ctrl, "v"], () => {
3531
+ node.value && services?.editorService.paste();
3532
+ }).keydown([ctrl, "x"], () => {
3533
+ if (!node.value || isPage(node.value))
3534
+ return;
3535
+ services?.editorService.copy(node.value);
3536
+ services?.editorService.remove(node.value);
3537
+ }).keydown([ctrl, "z"], () => {
3538
+ services?.editorService.undo();
3539
+ }).keydown([ctrl, "shift", "z"], () => {
3540
+ services?.editorService.redo();
3541
+ }).keydown("up", () => {
3542
+ services?.editorService.move(0, -1);
3543
+ }).keydown("down", () => {
3544
+ services?.editorService.move(0, 1);
3545
+ }).keydown("left", () => {
3546
+ services?.editorService.move(-1, 0);
3547
+ }).keydown("right", () => {
3548
+ services?.editorService.move(1, 0);
3549
+ }).keydown([ctrl, "up"], () => {
3550
+ services?.editorService.move(0, -10);
3551
+ }).keydown([ctrl, "down"], () => {
3552
+ services?.editorService.move(0, 10);
3553
+ }).keydown([ctrl, "left"], () => {
3554
+ services?.editorService.move(-10, 0);
3555
+ }).keydown([ctrl, "right"], () => {
3556
+ services?.editorService.move(10, 0);
3557
+ }).keydown("tab", () => {
3558
+ services?.editorService.selectNextNode();
3559
+ }).keydown([ctrl, "tab"], () => {
3560
+ services?.editorService.selectNextPage();
3561
+ }).keydown([ctrl, "="], () => {
3562
+ services?.uiService.zoom(0.1);
3563
+ }).keydown([ctrl, "numpadplus"], () => {
3564
+ services?.uiService.zoom(0.1);
3565
+ }).keydown([ctrl, "-"], () => {
3566
+ services?.uiService.zoom(-0.1);
3567
+ }).keydown([ctrl, "numpad-"], () => {
3568
+ services?.uiService.zoom(-0.1);
3569
+ });
3570
+ });
3571
+ onUnmounted(() => {
3572
+ workspace.value?.removeEventListener("mouseenter", mouseenterHandler);
3573
+ workspace.value?.removeEventListener("mouseleave", mouseleaveHandler);
3574
+ keycon.destroy();
3575
+ });
4139
3576
  return {
4140
- page: computed(() => services?.editorService.get("page")),
4141
- selectHandler(el) {
4142
- services?.editorService.select(el.id);
4143
- },
4144
- updateNodeHandler(node) {
4145
- services?.editorService.update(node);
4146
- },
4147
- sortNodeHandler(ev) {
4148
- services?.editorService.sort(ev.src, ev.dist);
4149
- }
3577
+ workspace,
3578
+ page: computed(() => services?.editorService.get("page"))
4150
3579
  };
4151
3580
  }
4152
3581
  });
4153
- const _hoisted_1 = { class: "m-editor-workspace" };
3582
+ const _hoisted_1 = {
3583
+ class: "m-editor-workspace",
3584
+ tabindex: "1",
3585
+ ref: "workspace"
3586
+ };
4154
3587
  function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4155
3588
  const _component_magic_stage = resolveComponent("magic-stage");
4156
3589
  const _component_page_bar = resolveComponent("page-bar");
@@ -4160,11 +3593,8 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4160
3593
  "runtime-url": _ctx.runtimeUrl,
4161
3594
  render: _ctx.render,
4162
3595
  "moveable-options": _ctx.moveableOptions,
4163
- "can-select": _ctx.canSelect,
4164
- onSelect: _ctx.selectHandler,
4165
- onUpdate: _ctx.updateNodeHandler,
4166
- onSort: _ctx.sortNodeHandler
4167
- }, null, 8, ["runtime-url", "render", "moveable-options", "can-select", "onSelect", "onUpdate", "onSort"])),
3596
+ "can-select": _ctx.canSelect
3597
+ }, null, 8, ["runtime-url", "render", "moveable-options", "can-select"])),
4168
3598
  renderSlot(_ctx.$slots, "workspace-content"),
4169
3599
  createVNode(_component_page_bar, null, {
4170
3600
  "page-bar-title": withCtx(({ page }) => [
@@ -4175,16 +3605,16 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4175
3605
  ]),
4176
3606
  _: 3
4177
3607
  })
4178
- ]);
3608
+ ], 512);
4179
3609
  }
4180
3610
  var Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
4181
3611
 
4182
3612
  class ComponentList extends BaseService {
4183
- state = reactive({
4184
- list: []
4185
- });
4186
3613
  constructor() {
4187
3614
  super([]);
3615
+ this.state = reactive({
3616
+ list: []
3617
+ });
4188
3618
  }
4189
3619
  setList(componentGroupList) {
4190
3620
  this.state.list = componentGroupList;
@@ -4195,6 +3625,14 @@ class ComponentList extends BaseService {
4195
3625
  }
4196
3626
  var componentListService = new ComponentList();
4197
3627
 
3628
+ const DEFAULT_LEFT_COLUMN_WIDTH = 310;
3629
+ const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
3630
+ const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
3631
+ const defaultColumnWidth = {
3632
+ left: DEFAULT_LEFT_COLUMN_WIDTH,
3633
+ center: globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH,
3634
+ right: DEFAULT_RIGHT_COLUMN_WIDTH
3635
+ };
4198
3636
  const state = reactive({
4199
3637
  uiSelectMode: false,
4200
3638
  showSrc: false,
@@ -4207,13 +3645,10 @@ const state = reactive({
4207
3645
  width: 375,
4208
3646
  height: 817
4209
3647
  },
4210
- columnWidth: {
4211
- left: 310,
4212
- center: globalThis.document.body.clientWidth - 310 - 400,
4213
- right: 400
4214
- },
3648
+ columnWidth: defaultColumnWidth,
4215
3649
  showGuides: true,
4216
- showRule: true
3650
+ showRule: true,
3651
+ propsPanelSize: "small"
4217
3652
  });
4218
3653
  class Ui extends BaseService {
4219
3654
  constructor() {
@@ -4223,6 +3658,15 @@ class Ui extends BaseService {
4223
3658
  center: "auto"
4224
3659
  });
4225
3660
  });
3661
+ const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
3662
+ if (columnWidthCacheData) {
3663
+ try {
3664
+ const columnWidthCache = JSON.parse(columnWidthCacheData);
3665
+ this.setColumnWidth(columnWidthCache);
3666
+ } catch (e) {
3667
+ console.error(e);
3668
+ }
3669
+ }
4226
3670
  }
4227
3671
  set(name, value) {
4228
3672
  const mask = editorService.get("stage")?.mask;
@@ -4248,6 +3692,11 @@ class Ui extends BaseService {
4248
3692
  get(name) {
4249
3693
  return state[name];
4250
3694
  }
3695
+ zoom(zoom) {
3696
+ this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
3697
+ if (this.get("zoom") < 0.1)
3698
+ this.set("zoom", 0.1);
3699
+ }
4251
3700
  setColumnWidth({ left, center, right }) {
4252
3701
  const columnWidth = {
4253
3702
  ...toRaw(this.get("columnWidth"))
@@ -4261,9 +3710,15 @@ class Ui extends BaseService {
4261
3710
  if (!center || center === "auto") {
4262
3711
  const bodyWidth = globalThis.document.body.clientWidth;
4263
3712
  columnWidth.center = bodyWidth - (columnWidth?.left || 0) - (columnWidth?.right || 0);
3713
+ if (columnWidth.center <= 0) {
3714
+ columnWidth.left = defaultColumnWidth.left;
3715
+ columnWidth.center = defaultColumnWidth.center;
3716
+ columnWidth.right = defaultColumnWidth.right;
3717
+ }
4264
3718
  } else {
4265
3719
  columnWidth.center = center;
4266
3720
  }
3721
+ globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
4267
3722
  state.columnWidth = columnWidth;
4268
3723
  }
4269
3724
  setStageRect(value) {
@@ -4339,6 +3794,10 @@ const _sfc_main = defineComponent({
4339
3794
  },
4340
3795
  stageRect: {
4341
3796
  type: [String, Object]
3797
+ },
3798
+ codeOptions: {
3799
+ type: Object,
3800
+ default: () => ({})
4342
3801
  }
4343
3802
  },
4344
3803
  emits: ["props-panel-mounted", "update:modelValue"],
@@ -4397,7 +3856,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4397
3856
  const _component_workspace = resolveComponent("workspace");
4398
3857
  const _component_props_panel = resolveComponent("props-panel");
4399
3858
  const _component_framework = resolveComponent("framework");
4400
- return openBlock(), createBlock(_component_framework, null, {
3859
+ return openBlock(), createBlock(_component_framework, { "code-options": _ctx.codeOptions }, {
4401
3860
  nav: withCtx(() => [
4402
3861
  renderSlot(_ctx.$slots, "nav", { editorService: _ctx.editorService }, () => [
4403
3862
  createVNode(_component_nav_menu, { data: _ctx.menu }, null, 8, ["data"])
@@ -4441,7 +3900,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4441
3900
  renderSlot(_ctx.$slots, "empty", { editorService: _ctx.editorService })
4442
3901
  ]),
4443
3902
  _: 3
4444
- });
3903
+ }, 8, ["code-options"]);
4445
3904
  }
4446
3905
  var Editor = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
4447
3906
 
@@ -4461,5 +3920,5 @@ var index = {
4461
3920
  }
4462
3921
  };
4463
3922
 
4464
- export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, generateId, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getNodeIndex, getPageList, getPageNameList, historyService, info, initPosition, isFixed, log, propsService, setConfig, setLayout, setNewItemId, toRelative, uiService, warn };
3923
+ export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, ToolButton, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, generateId, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getNodeIndex, getPageList, getPageNameList, historyService, info, initPosition, isFixed, log, propsService, setConfig, setLayout, setNewItemId, toRelative, uiService, warn };
4465
3924
  //# sourceMappingURL=tmagic-editor.es.js.map