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

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