@tmagic/editor 1.0.0-beta.1 → 1.0.0-beta.4

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.
@@ -1,12 +1,31 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('@tmagic/utils'), require('@element-plus/icons'), require('lodash-es'), require('events'), require('@tmagic/core'), require('element-plus'), require('@tmagic/stage')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', '@tmagic/utils', '@element-plus/icons', 'lodash-es', 'events', '@tmagic/core', 'element-plus', '@tmagic/stage'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.vue, global.serialize, global.utils, global.icons, global.lodashEs, global.events, global.core, global.elementPlus, global.StageCore));
5
- })(this, (function (exports, vue, serialize, utils, icons, lodashEs, events, core, elementPlus, StageCore) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('monaco-editor'), require('@element-plus/icons'), require('lodash-es'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('element-plus'), require('@tmagic/stage')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', 'monaco-editor', '@element-plus/icons', 'lodash-es', '@tmagic/utils', 'events', '@tmagic/core', 'element-plus', '@tmagic/stage'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.vue, global.serialize, global.monaco, global.icons, global.lodashEs, global.utils, global.events, global.core, global.elementPlus, global.StageCore));
5
+ })(this, (function (exports, vue, serialize, monaco, icons, lodashEs, utils, events, core, elementPlus, StageCore) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = {__proto__: null, [Symbol.toStringTag]: 'Module'};
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
9
27
  var serialize__default = /*#__PURE__*/_interopDefaultLegacy(serialize);
28
+ var monaco__namespace = /*#__PURE__*/_interopNamespace(monaco);
10
29
  var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
11
30
 
12
31
  var _export_sfc = (sfc, props) => {
@@ -17,7 +36,7 @@
17
36
  return target;
18
37
  };
19
38
 
20
- const _sfc_main$j = vue.defineComponent({
39
+ const _sfc_main$k = vue.defineComponent({
21
40
  name: "m-fields-vs-code",
22
41
  props: ["model", "name", "config", "prop"],
23
42
  emits: ["change"],
@@ -34,7 +53,7 @@
34
53
  };
35
54
  }
36
55
  });
37
- function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
56
+ function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
38
57
  const _component_magic_code_editor = vue.resolveComponent("magic-code-editor");
39
58
  return vue.openBlock(), vue.createBlock(_component_magic_code_editor, {
40
59
  style: vue.normalizeStyle(`height: ${_ctx.height}`),
@@ -43,9 +62,9 @@
43
62
  onSave: _ctx.save
44
63
  }, null, 8, ["style", "init-values", "language", "onSave"]);
45
64
  }
46
- var Code = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
65
+ var Code = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$k]]);
47
66
 
48
- const _sfc_main$i = vue.defineComponent({
67
+ const _sfc_main$j = vue.defineComponent({
49
68
  name: "m-fields-code-link",
50
69
  props: {
51
70
  config: {
@@ -100,7 +119,7 @@
100
119
  };
101
120
  }
102
121
  });
103
- function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
122
+ function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
104
123
  const _component_m_fields_link = vue.resolveComponent("m-fields-link");
105
124
  return vue.openBlock(), vue.createBlock(_component_m_fields_link, {
106
125
  config: _ctx.formConfig,
@@ -109,11 +128,11 @@
109
128
  onChange: _ctx.changeHandler
110
129
  }, null, 8, ["config", "model", "onChange"]);
111
130
  }
112
- var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
131
+ var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
113
132
 
114
133
  var UISelect_vue_vue_type_style_index_0_lang = '';
115
134
 
116
- const _sfc_main$h = vue.defineComponent({
135
+ const _sfc_main$i = vue.defineComponent({
117
136
  name: "m-fields-ui-select",
118
137
  props: {
119
138
  labelWidth: String,
@@ -183,7 +202,7 @@
183
202
  _hoisted_1$d
184
203
  ];
185
204
  const _hoisted_3$5 = /* @__PURE__ */ vue.createElementVNode("i", { class: "el-icon-thumb" }, null, -1);
186
- function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
205
+ function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
187
206
  return _ctx.uiSelectMode ? (vue.openBlock(), vue.createElementBlock("div", {
188
207
  key: 0,
189
208
  class: "m-fields-ui-select",
@@ -202,23 +221,8 @@
202
221
  })) : vue.createCommentVNode("", true)
203
222
  ]));
204
223
  }
205
- var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
224
+ var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
206
225
 
207
- const initEditor = () => {
208
- if (globalThis.monaco) {
209
- Promise.resolve(globalThis.monaco);
210
- }
211
- return utils.asyncLoadJs(`https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.26.1/min/vs/loader.min.js`).then(() => {
212
- globalThis.require.config({
213
- paths: { vs: `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.26.1/min/vs` }
214
- });
215
- return new Promise((resolve) => {
216
- globalThis.require(["vs/editor/editor.main"], () => {
217
- resolve(globalThis.monaco);
218
- });
219
- });
220
- });
221
- };
222
226
  const toString = (v, language) => {
223
227
  let value = "";
224
228
  if (typeof v !== "string") {
@@ -234,7 +238,7 @@
234
238
  }
235
239
  return value;
236
240
  };
237
- const _sfc_main$g = vue.defineComponent({
241
+ const _sfc_main$h = vue.defineComponent({
238
242
  name: "magic-code-editor",
239
243
  props: {
240
244
  initValues: {
@@ -252,32 +256,34 @@
252
256
  default: () => "javascript"
253
257
  }
254
258
  },
255
- emits: ["inited", "save"],
259
+ emits: ["initd", "save"],
256
260
  setup(props, { emit }) {
257
261
  let vsEditor = null;
262
+ let vsDiffEditor = null;
258
263
  const values = vue.ref("");
259
264
  const loading = vue.ref(false);
260
265
  const codeEditor = vue.ref();
261
266
  const setEditorValue = (v, m) => {
262
267
  values.value = toString(v, props.language);
263
268
  if (props.type === "diff") {
264
- const originalModel = globalThis.monaco.editor.createModel(values.value, "text/javascript");
265
- const modifiedModel = globalThis.monaco.editor.createModel(toString(m, props.language), "text/javascript");
266
- return vsEditor.setModel({
269
+ const originalModel = monaco__namespace.editor.createModel(values.value, "text/javascript");
270
+ const modifiedModel = monaco__namespace.editor.createModel(toString(m, props.language), "text/javascript");
271
+ return vsDiffEditor?.setModel({
267
272
  original: originalModel,
268
273
  modified: modifiedModel
269
274
  });
270
275
  }
271
- return vsEditor.setValue?.(values.value);
276
+ return vsEditor?.setValue(values.value);
272
277
  };
273
278
  const resizeHandler = () => {
274
279
  vsEditor?.layout();
280
+ vsDiffEditor?.layout();
275
281
  };
276
- const getEditorValue = () => vsEditor.getValue?.() || "";
282
+ const getEditorValue = () => props.type === "diff" ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
277
283
  const init = async () => {
278
284
  if (!codeEditor.value)
279
285
  return;
280
- vsEditor = globalThis.monaco.editor[props.type === "diff" ? "createDiffEditor" : "create"](codeEditor.value, {
286
+ const options = {
281
287
  value: values.value,
282
288
  language: props.language,
283
289
  tabSize: 2,
@@ -285,10 +291,15 @@
285
291
  fontFamily: 'dm, Menlo, Monaco, "Courier New", monospace',
286
292
  fontSize: 15,
287
293
  formatOnPaste: true
288
- });
294
+ };
295
+ if (props.type === "diff") {
296
+ vsDiffEditor = monaco__namespace.editor.createDiffEditor(codeEditor.value, options);
297
+ } else {
298
+ vsEditor = monaco__namespace.editor.create(codeEditor.value, options);
299
+ }
289
300
  setEditorValue(props.initValues, props.modifiedValues);
290
301
  loading.value = false;
291
- emit("inited", vsEditor);
302
+ emit("initd", vsEditor);
292
303
  codeEditor.value.addEventListener("keydown", (e) => {
293
304
  if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
294
305
  e.preventDefault();
@@ -296,14 +307,14 @@
296
307
  }
297
308
  });
298
309
  if (props.type !== "diff") {
299
- vsEditor.onDidBlurEditorWidget(() => {
310
+ vsEditor?.onDidBlurEditorWidget(() => {
300
311
  emit("save", getEditorValue());
301
312
  });
302
313
  }
303
314
  globalThis.addEventListener("resize", resizeHandler);
304
315
  };
305
316
  vue.watch(() => props.initValues, (v, preV) => {
306
- if (vsEditor && v !== preV) {
317
+ if (v !== preV) {
307
318
  setEditorValue(props.initValues, props.modifiedValues);
308
319
  }
309
320
  }, {
@@ -312,17 +323,7 @@
312
323
  });
313
324
  vue.onMounted(async () => {
314
325
  loading.value = true;
315
- await initEditor();
316
- if (!globalThis.monaco) {
317
- const interval = setInterval(() => {
318
- if (globalThis.monaco) {
319
- clearInterval(interval);
320
- init();
321
- }
322
- }, 300);
323
- } else {
324
- init();
325
- }
326
+ init();
326
327
  });
327
328
  vue.onUnmounted(() => {
328
329
  globalThis.removeEventListener("resize", resizeHandler);
@@ -332,11 +333,12 @@
332
333
  loading,
333
334
  codeEditor,
334
335
  getEditor() {
335
- return vsEditor;
336
+ return vsEditor || vsDiffEditor;
336
337
  },
337
338
  setEditorValue,
338
339
  focus() {
339
- vsEditor.focus();
340
+ vsEditor?.focus();
341
+ vsDiffEditor?.focus();
340
342
  }
341
343
  };
342
344
  }
@@ -345,10 +347,10 @@
345
347
  ref: "codeEditor",
346
348
  class: "magic-code-editor"
347
349
  };
348
- function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
350
+ function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
349
351
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$c, null, 512);
350
352
  }
351
- var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
353
+ var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
352
354
 
353
355
  let $TMAGIC_EDITOR = {};
354
356
  const setConfig = (option) => {
@@ -621,6 +623,10 @@
621
623
  Layout2["ABSOLUTE"] = "absolute";
622
624
  return Layout2;
623
625
  })(Layout || {});
626
+ var Keys = /* @__PURE__ */ ((Keys2) => {
627
+ Keys2["ESCAPE"] = "Space";
628
+ return Keys2;
629
+ })(Keys || {});
624
630
 
625
631
  const COPY_STORAGE_KEY = "$MagicEditorCopyData";
626
632
  const generateId = (type) => `${type}_${lodashEs.random(1e4, false)}`;
@@ -938,9 +944,6 @@
938
944
  if (!info.node)
939
945
  throw new Error(`\u83B7\u53D6\u4E0D\u5230id\u4E3A${config2.id}\u7684\u8282\u70B9`);
940
946
  const node = lodashEs.cloneDeep(vue.toRaw(info.node));
941
- const { parent } = info;
942
- if (!parent)
943
- throw new Error("\u83B7\u53D6\u4E0D\u5230\u7236\u7EA7\u8282\u70B9");
944
947
  let newConfig = await this.toggleFixedPosition(vue.toRaw(config2), node, this.get("root"));
945
948
  defaults(newConfig, node);
946
949
  if (!newConfig.type)
@@ -949,6 +952,9 @@
949
952
  this.set("root", newConfig);
950
953
  return newConfig;
951
954
  }
955
+ const { parent } = info;
956
+ if (!parent)
957
+ throw new Error("\u83B7\u53D6\u4E0D\u5230\u7236\u7EA7\u8282\u70B9");
952
958
  const parentNodeItems = parent.items;
953
959
  const index = getNodeIndex(newConfig, parent);
954
960
  if (!parentNodeItems || typeof index === "undefined" || index === -1)
@@ -1316,7 +1322,7 @@
1316
1322
  name: type
1317
1323
  });
1318
1324
 
1319
- const _sfc_main$f = vue.defineComponent({
1325
+ const _sfc_main$g = vue.defineComponent({
1320
1326
  components: { Plus: icons.Plus },
1321
1327
  setup() {
1322
1328
  const services = vue.inject("services");
@@ -1336,7 +1342,7 @@
1336
1342
  const _hoisted_1$b = { class: "m-editor-empty-panel" };
1337
1343
  const _hoisted_2$6 = { class: "m-editor-empty-content" };
1338
1344
  const _hoisted_3$4 = /* @__PURE__ */ vue.createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1339
- function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
1345
+ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
1340
1346
  const _component_plus = vue.resolveComponent("plus");
1341
1347
  const _component_el_icon = vue.resolveComponent("el-icon");
1342
1348
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$b, [
@@ -1358,7 +1364,7 @@
1358
1364
  ])
1359
1365
  ]);
1360
1366
  }
1361
- var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
1367
+ var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
1362
1368
 
1363
1369
  /*
1364
1370
  Copyright (c) 2018 Daybrush
@@ -2527,7 +2533,7 @@
2527
2533
 
2528
2534
  var Gesto$1 = Gesto;
2529
2535
 
2530
- const _sfc_main$e = vue.defineComponent({
2536
+ const _sfc_main$f = vue.defineComponent({
2531
2537
  name: "m-editor-resize",
2532
2538
  props: {
2533
2539
  type: {
@@ -2573,14 +2579,14 @@
2573
2579
  ref: "target",
2574
2580
  class: "m-editor-resizer"
2575
2581
  };
2576
- function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2582
+ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2577
2583
  return vue.openBlock(), vue.createElementBlock("span", _hoisted_1$a, [
2578
2584
  vue.renderSlot(_ctx.$slots, "default")
2579
2585
  ], 512);
2580
2586
  }
2581
- var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
2587
+ var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
2582
2588
 
2583
- const _sfc_main$d = vue.defineComponent({
2589
+ const _sfc_main$e = vue.defineComponent({
2584
2590
  components: {
2585
2591
  AddPageBox,
2586
2592
  Resizer
@@ -2608,7 +2614,7 @@
2608
2614
  key: 1,
2609
2615
  class: "m-editor-content"
2610
2616
  };
2611
- function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2617
+ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2612
2618
  const _component_magic_code_editor = vue.resolveComponent("magic-code-editor");
2613
2619
  const _component_resizer = vue.resolveComponent("resizer");
2614
2620
  const _component_el_scrollbar = vue.resolveComponent("el-scrollbar");
@@ -2653,9 +2659,9 @@
2653
2659
  ]))
2654
2660
  ]);
2655
2661
  }
2656
- var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
2662
+ var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
2657
2663
 
2658
- const _sfc_main$c = vue.defineComponent({
2664
+ const _sfc_main$d = vue.defineComponent({
2659
2665
  name: "m-icon",
2660
2666
  components: { Edit: icons.Edit },
2661
2667
  props: {
@@ -2670,7 +2676,7 @@
2670
2676
  }
2671
2677
  });
2672
2678
  const _hoisted_1$8 = ["src"];
2673
- function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2679
+ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2674
2680
  const _component_edit = vue.resolveComponent("edit");
2675
2681
  const _component_el_icon = vue.resolveComponent("el-icon");
2676
2682
  return !_ctx.icon ? (vue.openBlock(), vue.createBlock(_component_el_icon, { key: 0 }, {
@@ -2691,9 +2697,9 @@
2691
2697
  _: 1
2692
2698
  }));
2693
2699
  }
2694
- var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
2700
+ var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
2695
2701
 
2696
- const _sfc_main$b = vue.defineComponent({
2702
+ const _sfc_main$c = vue.defineComponent({
2697
2703
  components: { MIcon, ArrowDown: icons.ArrowDown },
2698
2704
  props: {
2699
2705
  data: {
@@ -2841,7 +2847,7 @@
2841
2847
  style: { "margin": "0 5px" }
2842
2848
  };
2843
2849
  const _hoisted_4$3 = { class: "el-dropdown-link menubar-menu-button" };
2844
- function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2850
+ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2845
2851
  const _component_el_divider = vue.resolveComponent("el-divider");
2846
2852
  const _component_m_icon = vue.resolveComponent("m-icon");
2847
2853
  const _component_el_button = vue.resolveComponent("el-button");
@@ -2927,9 +2933,9 @@
2927
2933
  }, 8, ["disabled", "onCommand"])) : _ctx.item.type === "component" ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.item.component), vue.normalizeProps(vue.mergeProps({ key: 5 }, _ctx.item.props || {})), null, 16)) : vue.createCommentVNode("", true)
2928
2934
  ])) : vue.createCommentVNode("", true);
2929
2935
  }
2930
- var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
2936
+ var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
2931
2937
 
2932
- const _sfc_main$a = vue.defineComponent({
2938
+ const _sfc_main$b = vue.defineComponent({
2933
2939
  name: "nav-menu",
2934
2940
  components: { ToolButton },
2935
2941
  props: {
@@ -2947,7 +2953,7 @@
2947
2953
  };
2948
2954
  }
2949
2955
  });
2950
- function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2956
+ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2951
2957
  const _component_tool_button = vue.resolveComponent("tool-button");
2952
2958
  return vue.openBlock(), vue.createElementBlock("div", {
2953
2959
  class: "m-editor-nav-menu",
@@ -2968,9 +2974,9 @@
2968
2974
  }), 128))
2969
2975
  ], 4);
2970
2976
  }
2971
- var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
2977
+ var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
2972
2978
 
2973
- const _sfc_main$9 = vue.defineComponent({
2979
+ const _sfc_main$a = vue.defineComponent({
2974
2980
  name: "m-editor-props-panel",
2975
2981
  emits: ["mounted"],
2976
2982
  setup(props, { emit }) {
@@ -3019,7 +3025,7 @@
3019
3025
  };
3020
3026
  }
3021
3027
  });
3022
- function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3028
+ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
3023
3029
  const _component_m_form = vue.resolveComponent("m-form");
3024
3030
  return vue.openBlock(), vue.createBlock(_component_m_form, {
3025
3031
  class: "m-editor-props-panel",
@@ -3030,9 +3036,9 @@
3030
3036
  onChange: _ctx.submit
3031
3037
  }, null, 8, ["init-values", "config", "onChange"]);
3032
3038
  }
3033
- var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
3039
+ var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
3034
3040
 
3035
- const _sfc_main$8 = vue.defineComponent({
3041
+ const _sfc_main$9 = vue.defineComponent({
3036
3042
  name: "ui-component-panel",
3037
3043
  components: { MIcon },
3038
3044
  setup() {
@@ -3059,7 +3065,7 @@
3059
3065
  });
3060
3066
  const _hoisted_1$6 = /* @__PURE__ */ vue.createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
3061
3067
  const _hoisted_2$3 = ["onClick"];
3062
- function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3068
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3063
3069
  const _component_el_input = vue.resolveComponent("el-input");
3064
3070
  const _component_m_icon = vue.resolveComponent("m-icon");
3065
3071
  const _component_el_tooltip = vue.resolveComponent("el-tooltip");
@@ -3126,9 +3132,9 @@
3126
3132
  _: 1
3127
3133
  });
3128
3134
  }
3129
- var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3135
+ var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
3130
3136
 
3131
- const _sfc_main$7 = vue.defineComponent({
3137
+ const _sfc_main$8 = vue.defineComponent({
3132
3138
  name: "magic-editor-content-menu",
3133
3139
  props: {
3134
3140
  componentGroupList: {
@@ -3177,7 +3183,7 @@
3177
3183
  const _hoisted_2$2 = ["onClick"];
3178
3184
  const _hoisted_3$2 = ["onClick"];
3179
3185
  const _hoisted_4$2 = /* @__PURE__ */ vue.createElementVNode("div", { class: "separation" }, null, -1);
3180
- function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3186
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3181
3187
  const _component_el_scrollbar = vue.resolveComponent("el-scrollbar");
3182
3188
  return _ctx.node ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$5, [
3183
3189
  _ctx.node.items ? (vue.openBlock(), vue.createElementBlock("div", {
@@ -3239,7 +3245,7 @@
3239
3245
  ])
3240
3246
  ])) : vue.createCommentVNode("", true);
3241
3247
  }
3242
- var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
3248
+ var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3243
3249
 
3244
3250
  const select = (data, editorService) => {
3245
3251
  if (!data.id) {
@@ -3346,7 +3352,7 @@
3346
3352
  }
3347
3353
  };
3348
3354
  };
3349
- const _sfc_main$6 = vue.defineComponent({
3355
+ const _sfc_main$7 = vue.defineComponent({
3350
3356
  name: "magic-editor-layer-panel",
3351
3357
  components: { LayerMenu },
3352
3358
  setup() {
@@ -3369,7 +3375,7 @@
3369
3375
  };
3370
3376
  }
3371
3377
  });
3372
- function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3378
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3373
3379
  const _component_el_input = vue.resolveComponent("el-input");
3374
3380
  const _component_el_tree = vue.resolveComponent("el-tree");
3375
3381
  const _component_layer_menu = vue.resolveComponent("layer-menu");
@@ -3423,9 +3429,9 @@
3423
3429
  _: 3
3424
3430
  });
3425
3431
  }
3426
- var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$6]]);
3432
+ var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
3427
3433
 
3428
- const _sfc_main$5 = vue.defineComponent({
3434
+ const _sfc_main$6 = vue.defineComponent({
3429
3435
  name: "m-sidebar",
3430
3436
  components: { MIcon },
3431
3437
  props: {
@@ -3473,7 +3479,7 @@
3473
3479
  key: 1,
3474
3480
  class: "magic-editor-tab-panel-title"
3475
3481
  };
3476
- function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3482
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3477
3483
  const _component_m_icon = vue.resolveComponent("m-icon");
3478
3484
  const _component_el_tab_pane = vue.resolveComponent("el-tab-pane");
3479
3485
  const _component_el_tabs = vue.resolveComponent("el-tabs");
@@ -3520,9 +3526,9 @@
3520
3526
  _: 1
3521
3527
  }, 8, ["modelValue"])) : vue.createCommentVNode("", true);
3522
3528
  }
3523
- var Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3529
+ var Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$6]]);
3524
3530
 
3525
- const _sfc_main$4 = vue.defineComponent({
3531
+ const _sfc_main$5 = vue.defineComponent({
3526
3532
  components: { CaretBottom: icons.CaretBottom, Plus: icons.Plus },
3527
3533
  setup() {
3528
3534
  const services = vue.inject("services");
@@ -3559,7 +3565,7 @@
3559
3565
  const _hoisted_2$1 = ["onClick"];
3560
3566
  const _hoisted_3$1 = ["onClick"];
3561
3567
  const _hoisted_4$1 = ["onClick"];
3562
- function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3568
+ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3563
3569
  const _component_plus = vue.resolveComponent("plus");
3564
3570
  const _component_el_icon = vue.resolveComponent("el-icon");
3565
3571
  const _component_caret_bottom = vue.resolveComponent("caret-bottom");
@@ -3618,7 +3624,223 @@
3618
3624
  }), 128)) : vue.createCommentVNode("", true)
3619
3625
  ]);
3620
3626
  }
3621
- var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$4]]);
3627
+ var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3628
+
3629
+ class ScrollViewer$1 {
3630
+ enter = false;
3631
+ targetEnter = false;
3632
+ keydown = false;
3633
+ container;
3634
+ target;
3635
+ zoom = 1;
3636
+ scrollLeft = 0;
3637
+ scrollTop = 0;
3638
+ x = 0;
3639
+ y = 0;
3640
+ resizeObserver = new ResizeObserver((entries) => {
3641
+ for (const { contentRect } of entries) {
3642
+ const { width, height } = contentRect;
3643
+ const targetRect = this.target.getBoundingClientRect();
3644
+ const targetWidth = targetRect.width * this.zoom;
3645
+ const targetHeight = targetRect.height * this.zoom;
3646
+ if (targetWidth < width) {
3647
+ this.target._left = 0;
3648
+ }
3649
+ if (targetHeight < height) {
3650
+ this.target._top = 0;
3651
+ }
3652
+ this.scroll();
3653
+ }
3654
+ });
3655
+ constructor(options) {
3656
+ this.container = options.container;
3657
+ this.target = options.target;
3658
+ this.zoom = options.zoom;
3659
+ globalThis.addEventListener("keydown", this.keydownHandler);
3660
+ globalThis.addEventListener("keyup", this.keyupHandler);
3661
+ this.container.addEventListener("mouseenter", this.mouseEnterHandler);
3662
+ this.container.addEventListener("mouseleave", this.mouseLeaveHandler);
3663
+ this.target.addEventListener("mouseenter", this.targetMouseEnterHandler);
3664
+ this.target.addEventListener("mouseleave", this.targetMouseLeaveHandler);
3665
+ this.container.addEventListener("wheel", this.wheelHandler);
3666
+ this.resizeObserver.observe(this.container);
3667
+ }
3668
+ destroy() {
3669
+ this.resizeObserver.disconnect();
3670
+ this.container.removeEventListener("mouseenter", this.mouseEnterHandler);
3671
+ this.container.removeEventListener("mouseleave", this.mouseLeaveHandler);
3672
+ this.target.removeEventListener("mouseenter", this.targetMouseEnterHandler);
3673
+ this.target.removeEventListener("mouseleave", this.targetMouseLeaveHandler);
3674
+ globalThis.removeEventListener("keydown", this.keydownHandler);
3675
+ globalThis.removeEventListener("keyup", this.keyupHandler);
3676
+ }
3677
+ setZoom(zoom) {
3678
+ this.zoom = zoom;
3679
+ }
3680
+ scroll() {
3681
+ const scrollLeft = this.target._left;
3682
+ const scrollTop = this.target._top;
3683
+ this.target.style.transform = `translate(${scrollLeft}px, ${scrollTop}px)`;
3684
+ }
3685
+ removeHandler() {
3686
+ this.target.style.cursor = "";
3687
+ this.target.removeEventListener("mousedown", this.mousedownHandler);
3688
+ document.removeEventListener("mousemove", this.mousemoveHandler);
3689
+ document.removeEventListener("mouseup", this.mouseupHandler);
3690
+ }
3691
+ wheelHandler = (event) => {
3692
+ if (this.targetEnter)
3693
+ return;
3694
+ const { deltaX, deltaY, currentTarget } = event;
3695
+ if (currentTarget !== this.container)
3696
+ return;
3697
+ this.setScrollOffset(deltaX, deltaY);
3698
+ this.scroll();
3699
+ this.scrollLeft = this.target._left;
3700
+ this.scrollTop = this.target._top;
3701
+ };
3702
+ mouseEnterHandler = () => {
3703
+ this.enter = true;
3704
+ };
3705
+ mouseLeaveHandler = () => {
3706
+ this.enter = false;
3707
+ };
3708
+ targetMouseEnterHandler = () => {
3709
+ this.targetEnter = true;
3710
+ };
3711
+ targetMouseLeaveHandler = () => {
3712
+ this.targetEnter = false;
3713
+ };
3714
+ mousedownHandler = (event) => {
3715
+ if (!this.keydown)
3716
+ return;
3717
+ event.stopImmediatePropagation();
3718
+ event.stopPropagation();
3719
+ this.target.style.cursor = "grabbing";
3720
+ this.x = event.clientX;
3721
+ this.y = event.clientY;
3722
+ document.addEventListener("mousemove", this.mousemoveHandler);
3723
+ document.addEventListener("mouseup", this.mouseupHandler);
3724
+ };
3725
+ mouseupHandler = () => {
3726
+ this.x = 0;
3727
+ this.y = 0;
3728
+ this.scrollLeft = this.target._left;
3729
+ this.scrollTop = this.target._top;
3730
+ this.removeHandler();
3731
+ };
3732
+ mousemoveHandler = (event) => {
3733
+ event.stopImmediatePropagation();
3734
+ event.stopPropagation();
3735
+ const deltaX = event.clientX - this.x;
3736
+ const deltaY = event.clientY - this.y;
3737
+ this.setScrollOffset(deltaX, deltaY);
3738
+ this.scroll();
3739
+ };
3740
+ keydownHandler = (event) => {
3741
+ if (event.code === Keys.ESCAPE && this.enter) {
3742
+ event.preventDefault();
3743
+ event.stopImmediatePropagation();
3744
+ event.stopPropagation();
3745
+ } else if (this.keydown)
3746
+ return;
3747
+ this.keydown = true;
3748
+ event.preventDefault();
3749
+ this.target.style.cursor = "grab";
3750
+ this.container.addEventListener("mousedown", this.mousedownHandler);
3751
+ };
3752
+ keyupHandler = (event) => {
3753
+ if (event.code !== Keys.ESCAPE || !this.keydown) {
3754
+ return;
3755
+ }
3756
+ event.preventDefault();
3757
+ event.stopImmediatePropagation();
3758
+ event.stopPropagation();
3759
+ this.keydown = false;
3760
+ event.preventDefault();
3761
+ this.removeHandler();
3762
+ };
3763
+ setScrollOffset(deltaX, deltaY) {
3764
+ const { width, height } = this.container.getBoundingClientRect();
3765
+ const targetRect = this.target.getBoundingClientRect();
3766
+ const targetWidth = targetRect.width * this.zoom;
3767
+ const targetHeight = targetRect.height * this.zoom;
3768
+ let y = 0;
3769
+ if (targetHeight > height) {
3770
+ if (deltaY > 0) {
3771
+ y = this.scrollTop + Math.min(targetHeight - height - this.scrollTop, deltaY);
3772
+ } else {
3773
+ y = this.scrollTop + Math.max(-(targetHeight - height + this.scrollTop), deltaY);
3774
+ }
3775
+ }
3776
+ let x = 0;
3777
+ if (targetWidth > width) {
3778
+ if (deltaX > 0) {
3779
+ x = this.scrollLeft + Math.min(targetWidth - width - this.scrollLeft, deltaX);
3780
+ } else {
3781
+ x = this.scrollLeft + Math.max(-(targetWidth - width + this.scrollLeft), deltaX);
3782
+ }
3783
+ }
3784
+ this.target._left = x;
3785
+ this.target._top = y;
3786
+ }
3787
+ }
3788
+
3789
+ const _sfc_main$4 = vue.defineComponent({
3790
+ name: "m-editor-scroll-viewer",
3791
+ props: {
3792
+ width: Number,
3793
+ height: Number,
3794
+ zoom: {
3795
+ type: Number,
3796
+ default: 1
3797
+ }
3798
+ },
3799
+ setup(props) {
3800
+ const container = vue.ref();
3801
+ const el = vue.ref();
3802
+ let scrollViewer;
3803
+ vue.onMounted(() => {
3804
+ if (!container.value || !el.value)
3805
+ return;
3806
+ scrollViewer = new ScrollViewer$1({
3807
+ container: container.value,
3808
+ target: el.value,
3809
+ zoom: props.zoom
3810
+ });
3811
+ });
3812
+ vue.onUnmounted(() => {
3813
+ scrollViewer.destroy();
3814
+ });
3815
+ vue.watch(() => props.zoom, () => {
3816
+ scrollViewer.setZoom(props.zoom);
3817
+ });
3818
+ return {
3819
+ container,
3820
+ el,
3821
+ style: vue.computed(() => `
3822
+ width: ${props.width}px;
3823
+ height: ${props.height}px;
3824
+ position: absolute;
3825
+ `)
3826
+ };
3827
+ }
3828
+ });
3829
+ const _hoisted_1$2 = {
3830
+ class: "m-editor-scroll-viewer-container",
3831
+ ref: "container"
3832
+ };
3833
+ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3834
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
3835
+ vue.createElementVNode("div", {
3836
+ ref: "el",
3837
+ style: vue.normalizeStyle(_ctx.style)
3838
+ }, [
3839
+ vue.renderSlot(_ctx.$slots, "default")
3840
+ ], 4)
3841
+ ], 512);
3842
+ }
3843
+ var ScrollViewer = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$4]]);
3622
3844
 
3623
3845
  const _sfc_main$3 = vue.defineComponent({
3624
3846
  name: "magic-editor-ui-viewer-menu",
@@ -3679,7 +3901,7 @@
3679
3901
  };
3680
3902
  }
3681
3903
  });
3682
- const _hoisted_1$2 = {
3904
+ const _hoisted_1$1 = {
3683
3905
  class: "magic-editor-content-menu",
3684
3906
  ref: "menu"
3685
3907
  };
@@ -3687,7 +3909,7 @@
3687
3909
  const _hoisted_3 = /* @__PURE__ */ vue.createElementVNode("div", { class: "separation" }, null, -1);
3688
3910
  const _hoisted_4 = /* @__PURE__ */ vue.createElementVNode("div", { class: "separation" }, null, -1);
3689
3911
  function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3690
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
3912
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
3691
3913
  vue.createElementVNode("div", null, [
3692
3914
  _ctx.canCenter ? (vue.openBlock(), vue.createElementBlock("div", {
3693
3915
  key: 0,
@@ -3772,28 +3994,14 @@
3772
3994
  const _sfc_main$2 = vue.defineComponent({
3773
3995
  name: "magic-stage",
3774
3996
  components: {
3775
- ViewerMenu
3997
+ ViewerMenu,
3998
+ ScrollViewer
3776
3999
  },
3777
4000
  props: {
3778
4001
  render: {
3779
4002
  type: Function
3780
4003
  },
3781
4004
  runtimeUrl: String,
3782
- root: {
3783
- type: Object
3784
- },
3785
- page: {
3786
- type: Object
3787
- },
3788
- node: {
3789
- type: Object
3790
- },
3791
- uiSelectMode: {
3792
- type: Boolean
3793
- },
3794
- zoom: {
3795
- type: Number
3796
- },
3797
4005
  canSelect: {
3798
4006
  type: Function,
3799
4007
  default: (el) => Boolean(el.id)
@@ -3808,11 +4016,14 @@
3808
4016
  emits: ["select", "update", "sort"],
3809
4017
  setup(props, { emit }) {
3810
4018
  const services = vue.inject("services");
4019
+ const stageWrap = vue.ref();
3811
4020
  const stageContainer = vue.ref();
3812
- const stageStyle = vue.computed(() => ({
3813
- ...services?.uiService.get("stageStyle"),
3814
- transform: `scale(${props.zoom}) translate3d(0, -50%, 0)`
3815
- }));
4021
+ const stageRect = vue.computed(() => services?.uiService.get("stageRect"));
4022
+ const uiSelectMode = vue.computed(() => services?.uiService.get("uiSelectMode"));
4023
+ const root = vue.computed(() => services?.editorService.get("root"));
4024
+ const page = vue.computed(() => services?.editorService.get("page"));
4025
+ const zoom = vue.computed(() => services?.uiService.get("zoom"));
4026
+ const node = vue.computed(() => services?.editorService.get("node"));
3816
4027
  let stage = null;
3817
4028
  let runtime = null;
3818
4029
  vue.watchEffect(() => {
@@ -3820,15 +4031,15 @@
3820
4031
  return;
3821
4032
  if (!stageContainer.value)
3822
4033
  return;
3823
- if (!(props.runtimeUrl || props.render) || !props.root)
4034
+ if (!(props.runtimeUrl || props.render) || !root.value)
3824
4035
  return;
3825
4036
  stage = new StageCore__default["default"]({
3826
4037
  render: props.render,
3827
4038
  runtimeUrl: props.runtimeUrl,
3828
- zoom: props.zoom,
4039
+ zoom: zoom.value,
3829
4040
  canSelect: (el, stop) => {
3830
4041
  const elCanSelect = props.canSelect(el);
3831
- if (props.uiSelectMode && elCanSelect) {
4042
+ if (uiSelectMode.value && elCanSelect) {
3832
4043
  document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
3833
4044
  return stop();
3834
4045
  }
@@ -3848,55 +4059,83 @@
3848
4059
  stage?.on("changeGuides", () => {
3849
4060
  services?.uiService.set("showGuides", true);
3850
4061
  });
3851
- if (!props.node?.id)
4062
+ if (!node.value?.id)
3852
4063
  return;
3853
4064
  stage?.on("runtime-ready", (rt) => {
3854
4065
  runtime = rt;
3855
- props.root && runtime?.updateRootConfig(lodashEs.cloneDeep(vue.toRaw(props.root)));
3856
- props.page?.id && runtime?.updatePageId?.(props.page.id);
4066
+ root.value && runtime?.updateRootConfig(lodashEs.cloneDeep(vue.toRaw(root.value)));
4067
+ page.value?.id && runtime?.updatePageId?.(page.value.id);
3857
4068
  setTimeout(() => {
3858
- props.node && stage?.select(vue.toRaw(props.node.id));
4069
+ node.value && stage?.select(vue.toRaw(node.value.id));
3859
4070
  });
3860
4071
  });
3861
4072
  });
3862
- vue.watch(() => props.zoom, (zoom) => {
3863
- if (!stage || !zoom)
4073
+ vue.watch(zoom, (zoom2) => {
4074
+ if (!stage || !zoom2)
3864
4075
  return;
3865
- stage?.setZoom(zoom);
4076
+ stage.setZoom(zoom2);
4077
+ });
4078
+ vue.watch(root, (root2) => {
4079
+ if (runtime && root2) {
4080
+ runtime.updateRootConfig(lodashEs.cloneDeep(vue.toRaw(root2)));
4081
+ }
4082
+ });
4083
+ vue.watch(() => node.value?.id, (id) => {
4084
+ vue.nextTick(() => {
4085
+ id && stage?.select(id);
4086
+ });
3866
4087
  });
3867
- vue.watch(() => props.root, (root) => {
3868
- if (runtime && root) {
3869
- runtime.updateRootConfig(lodashEs.cloneDeep(vue.toRaw(root)));
4088
+ const resizeObserver = new ResizeObserver((entries) => {
4089
+ for (const { contentRect } of entries) {
4090
+ services?.uiService.set("stageContainerRect", {
4091
+ width: contentRect.width,
4092
+ height: contentRect.height
4093
+ });
3870
4094
  }
3871
4095
  });
4096
+ vue.onMounted(() => {
4097
+ stageWrap.value?.container && resizeObserver.observe(stageWrap.value.container);
4098
+ });
3872
4099
  vue.onUnmounted(() => {
3873
4100
  stage?.destroy();
4101
+ resizeObserver.disconnect();
3874
4102
  services?.editorService.set("stage", null);
3875
4103
  });
3876
4104
  return {
3877
- stageStyle,
3878
- ...useMenu(),
3879
- stageContainer
4105
+ stageWrap,
4106
+ stageContainer,
4107
+ stageRect,
4108
+ zoom,
4109
+ ...useMenu()
3880
4110
  };
3881
4111
  }
3882
4112
  });
3883
- const _hoisted_1$1 = { class: "m-editor-stage" };
3884
4113
  function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3885
4114
  const _component_viewer_menu = vue.resolveComponent("viewer-menu");
3886
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
3887
- vue.createElementVNode("div", {
3888
- class: "m-editor-stage-container",
3889
- ref: "stageContainer",
3890
- style: vue.normalizeStyle(_ctx.stageStyle),
3891
- onContextmenu: _cache[0] || (_cache[0] = (...args) => _ctx.contextmenuHandler && _ctx.contextmenuHandler(...args))
3892
- }, null, 36),
3893
- (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
3894
- vue.createVNode(_component_viewer_menu, {
3895
- ref: "menu",
3896
- style: vue.normalizeStyle(_ctx.menuStyle)
3897
- }, null, 8, ["style"])
3898
- ]))
3899
- ]);
4115
+ const _component_scroll_viewer = vue.resolveComponent("scroll-viewer");
4116
+ return vue.openBlock(), vue.createBlock(_component_scroll_viewer, {
4117
+ class: "m-editor-stage",
4118
+ ref: "stageWrap",
4119
+ width: _ctx.stageRect?.width,
4120
+ height: _ctx.stageRect?.height,
4121
+ zoom: _ctx.zoom
4122
+ }, {
4123
+ default: vue.withCtx(() => [
4124
+ vue.createElementVNode("div", {
4125
+ class: "m-editor-stage-container",
4126
+ ref: "stageContainer",
4127
+ onContextmenu: _cache[0] || (_cache[0] = (...args) => _ctx.contextmenuHandler && _ctx.contextmenuHandler(...args)),
4128
+ style: vue.normalizeStyle(`transform: scale(${_ctx.zoom})`)
4129
+ }, null, 36),
4130
+ (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
4131
+ vue.createVNode(_component_viewer_menu, {
4132
+ ref: "menu",
4133
+ style: vue.normalizeStyle(_ctx.menuStyle)
4134
+ }, null, 8, ["style"])
4135
+ ]))
4136
+ ]),
4137
+ _: 1
4138
+ }, 8, ["width", "height", "zoom"]);
3900
4139
  }
3901
4140
  var MagicStage = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2]]);
3902
4141
 
@@ -3920,24 +4159,13 @@
3920
4159
  },
3921
4160
  setup() {
3922
4161
  const services = vue.inject("services");
3923
- const node = vue.computed(() => services?.editorService.get("node"));
3924
- const stage = vue.computed(() => services?.editorService.get("stage"));
3925
- vue.watch([() => node.value?.id, stage], ([id, stage2]) => {
3926
- vue.nextTick(() => {
3927
- id && stage2?.select(id);
3928
- });
3929
- });
3930
4162
  return {
3931
- uiSelectMode: vue.computed(() => services?.uiService.get("uiSelectMode")),
3932
- root: vue.computed(() => services?.editorService.get("root")),
3933
4163
  page: vue.computed(() => services?.editorService.get("page")),
3934
- zoom: vue.computed(() => services?.uiService.get("zoom")),
3935
- node,
3936
4164
  selectHandler(el) {
3937
4165
  services?.editorService.select(el.id);
3938
4166
  },
3939
- updateNodeHandler(node2) {
3940
- services?.editorService.update(node2);
4167
+ updateNodeHandler(node) {
4168
+ services?.editorService.update(node);
3941
4169
  },
3942
4170
  sortNodeHandler(ev) {
3943
4171
  services?.editorService.sort(ev.src, ev.dist);
@@ -3954,17 +4182,12 @@
3954
4182
  key: _ctx.page?.id,
3955
4183
  "runtime-url": _ctx.runtimeUrl,
3956
4184
  render: _ctx.render,
3957
- "ui-select-mode": _ctx.uiSelectMode,
3958
- root: _ctx.root,
3959
- page: _ctx.page,
3960
- node: _ctx.node,
3961
- zoom: _ctx.zoom,
3962
4185
  "moveable-options": _ctx.moveableOptions,
3963
4186
  "can-select": _ctx.canSelect,
3964
4187
  onSelect: _ctx.selectHandler,
3965
4188
  onUpdate: _ctx.updateNodeHandler,
3966
4189
  onSort: _ctx.sortNodeHandler
3967
- }, null, 8, ["runtime-url", "render", "ui-select-mode", "root", "page", "node", "zoom", "moveable-options", "can-select", "onSelect", "onUpdate", "onSort"])),
4190
+ }, null, 8, ["runtime-url", "render", "moveable-options", "can-select", "onSelect", "onUpdate", "onSort"])),
3968
4191
  vue.renderSlot(_ctx.$slots, "workspace-content"),
3969
4192
  vue.createVNode(_component_page_bar, null, {
3970
4193
  "page-bar-title": vue.withCtx(({ page }) => [
@@ -3999,7 +4222,14 @@
3999
4222
  uiSelectMode: false,
4000
4223
  showSrc: false,
4001
4224
  zoom: 1,
4002
- stageStyle: {},
4225
+ stageContainerRect: {
4226
+ width: 0,
4227
+ height: 0
4228
+ },
4229
+ stageRect: {
4230
+ width: 375,
4231
+ height: 817
4232
+ },
4003
4233
  columnWidth: {
4004
4234
  left: 310,
4005
4235
  center: globalThis.document.body.clientWidth - 310 - 400,
@@ -4023,6 +4253,10 @@
4023
4253
  this.setColumnWidth(value);
4024
4254
  return;
4025
4255
  }
4256
+ if (name === "stageRect") {
4257
+ this.setStageRect(value);
4258
+ return;
4259
+ }
4026
4260
  if (name === "showGuides") {
4027
4261
  mask?.showGuides(value);
4028
4262
  }
@@ -4030,6 +4264,9 @@
4030
4264
  mask?.showRule(value);
4031
4265
  }
4032
4266
  state[name] = value;
4267
+ if (name === "stageContainerRect") {
4268
+ state.zoom = this.calcZoom();
4269
+ }
4033
4270
  }
4034
4271
  get(name) {
4035
4272
  return state[name];
@@ -4052,6 +4289,23 @@
4052
4289
  }
4053
4290
  state.columnWidth = columnWidth;
4054
4291
  }
4292
+ setStageRect(value) {
4293
+ state.stageRect = {
4294
+ ...state.stageRect,
4295
+ ...value
4296
+ };
4297
+ state.zoom = this.calcZoom();
4298
+ }
4299
+ calcZoom() {
4300
+ const { stageRect, stageContainerRect } = state;
4301
+ const { height, width } = stageContainerRect;
4302
+ if (!width || !height)
4303
+ return 1;
4304
+ if (width > stageRect.width && height > stageRect.height) {
4305
+ return 1;
4306
+ }
4307
+ return Math.min((width - 100) / stageRect.width || 1, (height - 100) / stageRect.height || 1);
4308
+ }
4055
4309
  }
4056
4310
  var uiService = new Ui();
4057
4311
 
@@ -4106,7 +4360,7 @@
4106
4360
  canSelect: {
4107
4361
  type: Function
4108
4362
  },
4109
- stageStyle: {
4363
+ stageRect: {
4110
4364
  type: [String, Object]
4111
4365
  }
4112
4366
  },
@@ -4144,7 +4398,7 @@
4144
4398
  vue.watch(() => props.defaultSelected, (defaultSelected) => defaultSelected && editorService.select(defaultSelected), {
4145
4399
  immediate: true
4146
4400
  });
4147
- vue.watch(() => props.stageStyle, (stageStyle) => uiService.set("stageStyle", stageStyle), {
4401
+ vue.watch(() => props.stageRect, (stageRect) => stageRect && uiService.set("stageRect", stageRect), {
4148
4402
  immediate: true
4149
4403
  });
4150
4404
  vue.onUnmounted(() => editorService.destroy());
@@ -4234,6 +4488,7 @@
4234
4488
  exports.ComponentListPanel = ComponentListPanel;
4235
4489
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
4236
4490
  exports.Fixed2Other = Fixed2Other;
4491
+ exports.Keys = Keys;
4237
4492
  exports.LayerOffset = LayerOffset;
4238
4493
  exports.LayerPanel = LayerPanel;
4239
4494
  exports.Layout = Layout;