@tmagic/editor 1.1.0-beta.7 → 1.1.0

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 (63) hide show
  1. package/dist/style.css +50 -0
  2. package/dist/tmagic-editor.mjs +1198 -1027
  3. package/dist/tmagic-editor.mjs.map +1 -1
  4. package/dist/tmagic-editor.umd.js +1201 -1026
  5. package/dist/tmagic-editor.umd.js.map +1 -1
  6. package/package.json +10 -10
  7. package/src/Editor.vue +22 -6
  8. package/src/components/ContentMenu.vue +4 -4
  9. package/src/components/Icon.vue +7 -21
  10. package/src/components/ScrollBar.vue +147 -0
  11. package/src/components/ScrollViewer.vue +89 -44
  12. package/src/components/ToolButton.vue +40 -138
  13. package/src/fields/UISelect.vue +2 -2
  14. package/src/index.ts +2 -0
  15. package/src/layouts/NavMenu.vue +156 -23
  16. package/src/layouts/PropsPanel.vue +49 -51
  17. package/src/layouts/sidebar/LayerMenu.vue +3 -3
  18. package/src/layouts/sidebar/LayerPanel.vue +39 -8
  19. package/src/layouts/workspace/PageBar.vue +1 -1
  20. package/src/layouts/workspace/Stage.vue +8 -86
  21. package/src/layouts/workspace/ViewerMenu.vue +10 -13
  22. package/src/layouts/workspace/Workspace.vue +133 -138
  23. package/src/services/componentList.ts +5 -0
  24. package/src/services/editor.ts +201 -112
  25. package/src/services/events.ts +8 -2
  26. package/src/services/props.ts +31 -52
  27. package/src/services/storage.ts +4 -0
  28. package/src/services/ui.ts +32 -30
  29. package/src/theme/component-list-panel.scss +5 -0
  30. package/src/theme/nav-menu.scss +6 -0
  31. package/src/type.ts +28 -11
  32. package/src/utils/editor.ts +17 -10
  33. package/src/utils/index.ts +1 -0
  34. package/src/utils/operator.ts +22 -123
  35. package/src/utils/props.ts +0 -3
  36. package/src/utils/scroll-viewer.ts +90 -158
  37. package/src/utils/stage.ts +91 -0
  38. package/types/Editor.vue.d.ts +17 -8
  39. package/types/components/ContentMenu.vue.d.ts +8 -8
  40. package/types/components/Icon.vue.d.ts +62 -12
  41. package/types/components/ScrollBar.vue.d.ts +83 -0
  42. package/types/components/ScrollViewer.vue.d.ts +131 -19
  43. package/types/components/ToolButton.vue.d.ts +56 -59
  44. package/types/index.d.ts +2 -0
  45. package/types/layouts/NavMenu.vue.d.ts +92 -23
  46. package/types/layouts/PropsPanel.vue.d.ts +25 -208
  47. package/types/layouts/sidebar/LayerMenu.vue.d.ts +7 -7
  48. package/types/layouts/sidebar/LayerPanel.vue.d.ts +17 -15
  49. package/types/layouts/workspace/ViewerMenu.vue.d.ts +3 -3
  50. package/types/layouts/workspace/Workspace.vue.d.ts +54 -4
  51. package/types/services/componentList.d.ts +1 -0
  52. package/types/services/editor.d.ts +10 -17
  53. package/types/services/events.d.ts +1 -0
  54. package/types/services/props.d.ts +41 -9
  55. package/types/services/storage.d.ts +1 -0
  56. package/types/services/ui.d.ts +3 -1
  57. package/types/type.d.ts +25 -11
  58. package/types/utils/editor.d.ts +4 -1
  59. package/types/utils/index.d.ts +1 -0
  60. package/types/utils/operator.d.ts +3 -26
  61. package/types/utils/props.d.ts +0 -1
  62. package/types/utils/scroll-viewer.d.ts +16 -18
  63. package/types/utils/stage.d.ts +3 -0
@@ -1,9 +1,9 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, createElementBlock, createVNode, unref, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, markRaw, renderList, normalizeProps, mergeProps, getCurrentInstance, Teleport, nextTick, toHandlers, createSlots, provide } from 'vue';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, createElementBlock, createVNode, unref, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, Teleport, nextTick, toHandlers, createSlots, provide } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
- import { Delete, Close, Plus, Edit, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, ArrowDown, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
3
+ import { Delete, Close, Plus, Edit, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
4
4
  import { throttle, cloneDeep, mergeWith, isEmpty, uniq } from 'lodash-es';
5
5
  import * as monaco from 'monaco-editor';
6
- import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS } from '@tmagic/stage';
6
+ import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType } from '@tmagic/stage';
7
7
  import { NodeType } from '@tmagic/schema';
8
8
  import { isPop, getNodePath, isNumber, isPage, toLine, removeClassNameByClassName } from '@tmagic/utils';
9
9
  import { EventEmitter } from 'events';
@@ -19,7 +19,7 @@ if (typeof globalThis === "undefined") {
19
19
  window.globalThis = window;
20
20
  }
21
21
 
22
- const _sfc_main$n = defineComponent({
22
+ const _sfc_main$o = defineComponent({
23
23
  name: "m-fields-vs-code",
24
24
  props: ["model", "name", "config", "prop"],
25
25
  emits: ["change"],
@@ -45,7 +45,7 @@ const _export_sfc = (sfc, props) => {
45
45
  return target;
46
46
  };
47
47
 
48
- function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
48
+ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
49
49
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
50
50
  return openBlock(), createBlock(_component_magic_code_editor, {
51
51
  style: normalizeStyle(`height: ${_ctx.height}`),
@@ -54,9 +54,9 @@ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
54
54
  onSave: _ctx.save
55
55
  }, null, 8, ["style", "init-values", "language", "onSave"]);
56
56
  }
57
- const Code = /* @__PURE__ */ _export_sfc(_sfc_main$n, [["render", _sfc_render$g]]);
57
+ const Code = /* @__PURE__ */ _export_sfc(_sfc_main$o, [["render", _sfc_render$b]]);
58
58
 
59
- const _sfc_main$m = defineComponent({
59
+ const _sfc_main$n = defineComponent({
60
60
  name: "m-fields-code-link",
61
61
  props: {
62
62
  config: {
@@ -112,7 +112,7 @@ const _sfc_main$m = defineComponent({
112
112
  }
113
113
  });
114
114
 
115
- function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
115
+ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
116
116
  const _component_m_fields_link = resolveComponent("m-fields-link");
117
117
  return openBlock(), createBlock(_component_m_fields_link, {
118
118
  config: _ctx.formConfig,
@@ -121,10 +121,10 @@ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
121
121
  onChange: _ctx.changeHandler
122
122
  }, null, 8, ["config", "model", "onChange"]);
123
123
  }
124
- const CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$f]]);
124
+ const CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$n, [["render", _sfc_render$a]]);
125
125
 
126
- const _hoisted_1$d = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
127
- const _sfc_main$l = /* @__PURE__ */ defineComponent({
126
+ const _hoisted_1$b = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
127
+ const _sfc_main$m = /* @__PURE__ */ defineComponent({
128
128
  __name: "UISelect",
129
129
  props: {
130
130
  config: null,
@@ -189,7 +189,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
189
189
  style: { "padding": "0" }
190
190
  }, {
191
191
  default: withCtx(() => [
192
- _hoisted_1$d
192
+ _hoisted_1$b
193
193
  ]),
194
194
  _: 1
195
195
  }, 8, ["icon"])
@@ -199,19 +199,21 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
199
199
  onClick: startSelect,
200
200
  style: { "display": "flex" }
201
201
  }, [
202
- createVNode(_component_el_tooltip, { content: "\u6E05\u9664" }, {
202
+ unref(val) ? (openBlock(), createBlock(_component_el_tooltip, {
203
+ key: 0,
204
+ content: "\u6E05\u9664"
205
+ }, {
203
206
  default: withCtx(() => [
204
- unref(val) ? (openBlock(), createBlock(_component_el_button, {
205
- key: 0,
207
+ createVNode(_component_el_button, {
206
208
  style: { "padding": "0" },
207
209
  type: "danger",
208
210
  icon: unref(Close),
209
211
  text: "",
210
212
  onClick: withModifiers(deleteHandler, ["stop"])
211
- }, null, 8, ["icon", "onClick"])) : createCommentVNode("", true)
213
+ }, null, 8, ["icon", "onClick"])
212
214
  ]),
213
215
  _: 1
214
- }),
216
+ })) : createCommentVNode("", true),
215
217
  createVNode(_component_el_tooltip, {
216
218
  content: unref(val) ? unref(toName) + "_" + unref(val) : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"
217
219
  }, {
@@ -250,7 +252,7 @@ const toString = (v, language) => {
250
252
  }
251
253
  return value;
252
254
  };
253
- const _sfc_main$k = defineComponent({
255
+ const _sfc_main$l = defineComponent({
254
256
  name: "magic-code-editor",
255
257
  props: {
256
258
  initValues: {
@@ -358,14 +360,14 @@ const _sfc_main$k = defineComponent({
358
360
  }
359
361
  });
360
362
 
361
- const _hoisted_1$c = {
363
+ const _hoisted_1$a = {
362
364
  ref: "codeEditor",
363
365
  class: "magic-code-editor"
364
366
  };
365
- function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
366
- return openBlock(), createElementBlock("div", _hoisted_1$c, null, 512);
367
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
368
+ return openBlock(), createElementBlock("div", _hoisted_1$a, null, 512);
367
369
  }
368
- const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$e]]);
370
+ const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$9]]);
369
371
 
370
372
  let $TMAGIC_EDITOR = {};
371
373
  const setConfig = (option) => {
@@ -673,6 +675,9 @@ class WebStorage extends BaseService {
673
675
  }
674
676
  storage2.setItem(`${options2.namespace || namespace2}:${key2}`, item2);
675
677
  }
678
+ destroy() {
679
+ this.removeAllListeners();
680
+ }
676
681
  getValueAndProtocol(value) {
677
682
  let protocol2 = "";
678
683
  if (value === null) {
@@ -693,6 +698,12 @@ class WebStorage extends BaseService {
693
698
  }
694
699
  const storageService = new WebStorage();
695
700
 
701
+ var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
702
+ ColumnLayout2["LEFT"] = "left";
703
+ ColumnLayout2["CENTER"] = "center";
704
+ ColumnLayout2["RIGHT"] = "right";
705
+ return ColumnLayout2;
706
+ })(ColumnLayout || {});
696
707
  var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
697
708
  LayerOffset2["TOP"] = "top";
698
709
  LayerOffset2["BOTTOM"] = "bottom";
@@ -743,10 +754,10 @@ const getRelativeStyle = (style = {}) => ({
743
754
  top: 0,
744
755
  left: 0
745
756
  });
746
- const getMiddleTop = (style = {}, parentNode, stage) => {
747
- let height = style.height || 0;
748
- if (!stage || typeof style.top !== "undefined" || !parentNode.style)
749
- return style.top;
757
+ const getMiddleTop = (node, parentNode, stage) => {
758
+ let height = node.style?.height || 0;
759
+ if (!stage || typeof node.style?.top !== "undefined" || !parentNode.style)
760
+ return node.style?.top;
750
761
  if (!isNumber(height)) {
751
762
  height = 0;
752
763
  }
@@ -757,12 +768,11 @@ const getMiddleTop = (style = {}, parentNode, stage) => {
757
768
  }
758
769
  return (parentHeight - height) / 2;
759
770
  };
760
- const getInitPositionStyle = (style = {}, layout, parentNode, stage) => {
771
+ const getInitPositionStyle = (style = {}, layout) => {
761
772
  if (layout === Layout.ABSOLUTE) {
762
773
  return {
763
774
  ...style,
764
- position: "absolute",
765
- top: getMiddleTop(style, parentNode, stage)
775
+ position: "absolute"
766
776
  };
767
777
  }
768
778
  if (layout === Layout.RELATIVE) {
@@ -854,6 +864,16 @@ const fixNodeLeft = (config, parent, doc) => {
854
864
  }
855
865
  return config.style.left;
856
866
  };
867
+ const fixNodePosition = (config, parent, stage) => {
868
+ if (config.style?.position !== "absolute") {
869
+ return config.style;
870
+ }
871
+ return {
872
+ ...config.style || {},
873
+ top: getMiddleTop(config, parent, stage),
874
+ left: fixNodeLeft(config, parent, stage?.renderer.contentWindow?.document)
875
+ };
876
+ };
857
877
 
858
878
  class Props extends BaseService {
859
879
  state = reactive({
@@ -868,6 +888,7 @@ class Props extends BaseService {
868
888
  "getPropsValue",
869
889
  "createId",
870
890
  "setNewItemId",
891
+ "fillConfig",
871
892
  "getDefaultPropsValue"
872
893
  ]);
873
894
  }
@@ -877,14 +898,17 @@ class Props extends BaseService {
877
898
  });
878
899
  this.emit("props-configs-change");
879
900
  }
880
- setPropsConfig(type, config) {
881
- this.state.propsConfigMap[type] = fillConfig(Array.isArray(config) ? config : [config]);
901
+ async fillConfig(config) {
902
+ return fillConfig(config);
903
+ }
904
+ async setPropsConfig(type, config) {
905
+ this.state.propsConfigMap[type] = await this.fillConfig(Array.isArray(config) ? config : [config]);
882
906
  }
883
907
  async getPropsConfig(type) {
884
908
  if (type === "area") {
885
909
  return await this.getPropsConfig("button");
886
910
  }
887
- return cloneDeep(this.state.propsConfigMap[type] || DEFAULT_CONFIG);
911
+ return cloneDeep(this.state.propsConfigMap[type] || await this.fillConfig([]));
888
912
  }
889
913
  setPropsValues(values) {
890
914
  Object.keys(values).forEach((type) => {
@@ -918,25 +942,14 @@ class Props extends BaseService {
918
942
  ...mergeWith({}, cloneDeep(this.state.propsValueMap[type] || {}), data)
919
943
  };
920
944
  }
921
- guid(digit = 8) {
922
- return "x".repeat(digit).replace(/[xy]/g, (c) => {
923
- const r = Math.random() * 16 | 0;
924
- const v = c == "x" ? r : r & 3 | 8;
925
- return v.toString(16);
926
- });
927
- }
928
945
  async createId(type) {
929
946
  return `${type}_${this.guid()}`;
930
947
  }
931
- async setNewItemId(config, parent) {
932
- const oldId = config.id;
948
+ async setNewItemId(config) {
933
949
  config.id = await this.createId(config.type || "component");
934
- if (isPop(config) && parent?.type === NodeType.PAGE) {
935
- updatePopId(oldId, config.id, parent);
936
- }
937
950
  if (config.items && Array.isArray(config.items)) {
938
951
  for (const item of config.items) {
939
- await this.setNewItemId(item, config);
952
+ await this.setNewItemId(item);
940
953
  }
941
954
  }
942
955
  return config;
@@ -954,22 +967,19 @@ class Props extends BaseService {
954
967
  name: type
955
968
  };
956
969
  }
970
+ destroy() {
971
+ this.state.propsConfigMap = {};
972
+ this.state.propsValueMap = {};
973
+ this.removeAllListeners();
974
+ }
975
+ guid(digit = 8) {
976
+ return "x".repeat(digit).replace(/[xy]/g, (c) => {
977
+ const r = Math.random() * 16 | 0;
978
+ const v = c === "x" ? r : r & 3 | 8;
979
+ return v.toString(16);
980
+ });
981
+ }
957
982
  }
958
- const updatePopId = (oldId, popId, pageConfig) => {
959
- pageConfig.items?.forEach((config) => {
960
- if (config.pop === oldId) {
961
- config.pop = popId;
962
- return;
963
- }
964
- if (config.popId === oldId) {
965
- config.popId = popId;
966
- return;
967
- }
968
- if (Array.isArray(config.items)) {
969
- updatePopId(oldId, popId, config);
970
- }
971
- });
972
- };
973
983
  const propsService = new Props();
974
984
 
975
985
  const beforePaste = async (position, config) => {
@@ -989,7 +999,7 @@ const beforePaste = async (position, config) => {
989
999
  if (pastePosition.top && configItem.style?.top) {
990
1000
  pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
991
1001
  }
992
- const pasteConfig = await propsService.setNewItemId(configItem, editorService.get("root"));
1002
+ const pasteConfig = await propsService.setNewItemId(configItem);
993
1003
  if (pasteConfig.style) {
994
1004
  const { left, top } = pasteConfig.style;
995
1005
  if (typeof left === "number" || !!left && !isNaN(Number(left))) {
@@ -1010,36 +1020,6 @@ const beforePaste = async (position, config) => {
1010
1020
  }));
1011
1021
  return pasteConfigs;
1012
1022
  };
1013
- const beforeAdd = async (addNode, parent) => {
1014
- const { type, inputEvent, ...config } = addNode;
1015
- const curNode = editorService.get("node");
1016
- let parentNode;
1017
- const isPage2 = type === NodeType.PAGE;
1018
- if (isPage2) {
1019
- parentNode = editorService.get("root");
1020
- } else if (parent && typeof parent !== "function") {
1021
- parentNode = parent;
1022
- } else if (curNode.items) {
1023
- parentNode = curNode;
1024
- } else {
1025
- parentNode = editorService.getParentById(curNode.id, false);
1026
- }
1027
- if (!parentNode)
1028
- throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
1029
- const layout = await editorService.getLayout(toRaw(parentNode), addNode);
1030
- const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
1031
- newNode.style = getInitPositionStyle(newNode.style, layout, parentNode, editorService.get("stage"));
1032
- if ((parentNode?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && newNode.type !== NodeType.PAGE) {
1033
- throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
1034
- }
1035
- parentNode?.items?.push(newNode);
1036
- return {
1037
- parentNode,
1038
- newNode,
1039
- layout,
1040
- isPage: isPage2
1041
- };
1042
- };
1043
1023
  const getPositionInContainer = (position = {}, id) => {
1044
1024
  let { left = 0, top = 0 } = position;
1045
1025
  const parentEl = editorService.get("stage")?.renderer?.contentWindow?.document.getElementById(`${id}`);
@@ -1051,55 +1031,17 @@ const getPositionInContainer = (position = {}, id) => {
1051
1031
  top
1052
1032
  };
1053
1033
  };
1054
- const notifyAddToStage = async (parentNode, newNode, layout) => {
1055
- const stage = editorService.get("stage");
1056
- const root = editorService.get("root");
1057
- await stage?.add({ config: cloneDeep(newNode), parent: cloneDeep(parentNode), root: cloneDeep(root) });
1058
- if (layout === Layout.ABSOLUTE) {
1059
- const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
1060
- if (typeof fixedLeft !== "undefined" && newNode.style) {
1061
- newNode.style.left = fixedLeft;
1062
- await stage?.update({ config: cloneDeep(newNode), root: cloneDeep(root) });
1063
- }
1064
- }
1065
- };
1066
- const beforeRemove = async (node) => {
1067
- if (!node?.id)
1068
- return;
1069
- const stage = editorService.get("stage");
1070
- const root = editorService.get("root");
1071
- if (!root)
1072
- throw new Error("\u6CA1\u6709root");
1073
- const { parent, node: curNode } = editorService.getNodeInfo(node.id, false);
1074
- if (!parent || !curNode)
1075
- throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1076
- const index = getNodeIndex(curNode, parent);
1077
- if (typeof index !== "number" || index === -1)
1078
- throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1079
- parent.items?.splice(index, 1);
1080
- stage?.remove({ id: node.id, root: cloneDeep(root) });
1081
- if (node.type === NodeType.PAGE) {
1082
- editorService.state.pageLength -= 1;
1083
- if (root.items[0]) {
1084
- await editorService.select(root.items[0]);
1085
- stage?.select(root.items[0].id);
1086
- } else {
1087
- editorService.set("node", null);
1088
- editorService.set("nodes", []);
1089
- editorService.set("parent", null);
1090
- editorService.set("page", null);
1091
- editorService.set("stage", null);
1092
- editorService.set("highlightNode", null);
1093
- editorService.resetModifiedNodeId();
1094
- historyService.reset();
1095
- editorService.emit("remove", node);
1096
- return;
1097
- }
1034
+ const getAddParent = (node) => {
1035
+ const curNode = editorService.get("node");
1036
+ let parentNode;
1037
+ if (isPage(node)) {
1038
+ parentNode = editorService.get("root");
1039
+ } else if (curNode.items) {
1040
+ parentNode = curNode;
1098
1041
  } else {
1099
- await editorService.select(parent);
1100
- stage?.select(parent.id);
1042
+ parentNode = editorService.getParentById(curNode.id, false);
1101
1043
  }
1102
- return parent;
1044
+ return parentNode;
1103
1045
  };
1104
1046
 
1105
1047
  class Editor$1 extends BaseService {
@@ -1119,12 +1061,17 @@ class Editor$1 extends BaseService {
1119
1061
  super([
1120
1062
  "getLayout",
1121
1063
  "select",
1064
+ "doAdd",
1122
1065
  "add",
1066
+ "doRemove",
1123
1067
  "remove",
1068
+ "doUpdate",
1124
1069
  "update",
1125
1070
  "sort",
1126
1071
  "copy",
1127
1072
  "paste",
1073
+ "doPaste",
1074
+ "duAlignCenter",
1128
1075
  "alignCenter",
1129
1076
  "moveLayer",
1130
1077
  "moveToContainer",
@@ -1253,62 +1200,106 @@ class Editor$1 extends BaseService {
1253
1200
  });
1254
1201
  this.set("nodes", nodes);
1255
1202
  }
1256
- async multiAdd(configs) {
1203
+ async doAdd(node, parent) {
1204
+ const root = this.get("root");
1205
+ const curNode = this.get("node");
1257
1206
  const stage = this.get("stage");
1258
- const newNodes = await Promise.all(configs.map(async (configItem) => {
1259
- const { parentNode, newNode, layout } = await beforeAdd(configItem);
1260
- await notifyAddToStage(parentNode, newNode, layout);
1261
- return newNode;
1262
- }));
1263
- const newNodeIds = newNodes.map((node) => node.id);
1264
- this.addModifiedNodeId(newNodeIds.join("-"));
1265
- this.pushHistoryState();
1266
- stage?.multiSelect(newNodeIds);
1267
- this.emit("multiAdd", newNodes);
1268
- return newNodes;
1207
+ if ((parent?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && node.type !== NodeType.PAGE) {
1208
+ throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
1209
+ }
1210
+ if (parent.id !== curNode.id) {
1211
+ const index = parent.items.indexOf(curNode);
1212
+ parent?.items?.splice(index + 1, 0, node);
1213
+ } else {
1214
+ parent?.items?.push(node);
1215
+ }
1216
+ const layout = await this.getLayout(toRaw(parent), node);
1217
+ node.style = getInitPositionStyle(node.style, layout);
1218
+ await stage?.add({
1219
+ config: cloneDeep(node),
1220
+ parent: cloneDeep(parent),
1221
+ parentId: parent.id,
1222
+ root: cloneDeep(root)
1223
+ });
1224
+ node.style = fixNodePosition(node, parent, stage);
1225
+ await stage?.update({ config: cloneDeep(node), parentId: parent.id, root: cloneDeep(root) });
1226
+ this.addModifiedNodeId(node.id);
1227
+ return node;
1269
1228
  }
1270
1229
  async add(addNode, parent) {
1271
1230
  const stage = this.get("stage");
1272
- const { parentNode, newNode, layout, isPage: isPage2 } = await beforeAdd(addNode, parent);
1273
- await notifyAddToStage(parentNode, newNode, layout);
1274
- await this.select(newNode);
1275
- this.addModifiedNodeId(newNode.id);
1276
- if (!isPage2) {
1277
- this.pushHistoryState();
1231
+ const addNodes = [];
1232
+ if (!Array.isArray(addNode)) {
1233
+ const { type, inputEvent, ...config } = addNode;
1234
+ if (!type)
1235
+ throw new Error("\u7EC4\u4EF6\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A");
1236
+ addNodes.push({ ...toRaw(await propsService.getPropsValue(type, config)) });
1237
+ } else {
1238
+ addNodes.push(...addNode);
1278
1239
  }
1279
- if (isPage2) {
1280
- this.state.pageLength += 1;
1240
+ const newNodes = await Promise.all(addNodes.map((node) => {
1241
+ const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(node);
1242
+ if (!parentNode)
1243
+ throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
1244
+ return this.doAdd(node, parentNode);
1245
+ }));
1246
+ if (newNodes.length > 1) {
1247
+ const newNodeIds = newNodes.map((node) => node.id);
1248
+ stage?.multiSelect(newNodeIds);
1249
+ await this.multiSelect(newNodeIds);
1281
1250
  } else {
1282
- stage?.select(newNode.id);
1251
+ await this.select(newNodes[0]);
1252
+ if (isPage(newNodes[0])) {
1253
+ this.state.pageLength += 1;
1254
+ } else {
1255
+ stage?.select(newNodes[0].id);
1256
+ }
1283
1257
  }
1284
- this.emit("add", newNode);
1285
- return newNode;
1258
+ this.pushHistoryState();
1259
+ this.emit("add", newNodes);
1260
+ return Array.isArray(addNode) ? newNodes : newNodes[0];
1286
1261
  }
1287
- async remove(nodeOrNodeList) {
1288
- if (Array.isArray(nodeOrNodeList)) {
1289
- const nodes = nodeOrNodeList;
1290
- return this.multiRemove(nodes);
1262
+ async doRemove(node) {
1263
+ const root = this.get("root");
1264
+ if (!root)
1265
+ throw new Error("\u6CA1\u6709root");
1266
+ const { parent, node: curNode } = this.getNodeInfo(node.id);
1267
+ if (!parent || !curNode)
1268
+ throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1269
+ const index = getNodeIndex(curNode, parent);
1270
+ if (typeof index !== "number" || index === -1)
1271
+ throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1272
+ parent.items?.splice(index, 1);
1273
+ const stage = this.get("stage");
1274
+ stage?.remove({ id: node.id, parentId: parent.id, root: cloneDeep(root) });
1275
+ if (node.type === NodeType.PAGE) {
1276
+ this.state.pageLength -= 1;
1277
+ if (root.items[0]) {
1278
+ await this.select(root.items[0]);
1279
+ stage?.select(root.items[0].id);
1280
+ } else {
1281
+ this.set("node", null);
1282
+ this.set("parent", null);
1283
+ this.set("page", null);
1284
+ this.set("stage", null);
1285
+ this.set("highlightNode", null);
1286
+ this.resetModifiedNodeId();
1287
+ historyService.reset();
1288
+ return;
1289
+ }
1290
+ } else {
1291
+ await this.select(parent);
1292
+ stage?.select(parent.id);
1291
1293
  }
1292
- const node = nodeOrNodeList;
1293
- const removeParent = await beforeRemove(node);
1294
- if (!removeParent)
1295
- return node;
1296
- this.addModifiedNodeId(removeParent.id);
1297
- this.pushHistoryState();
1298
- this.emit("remove", node);
1299
- return node;
1294
+ this.addModifiedNodeId(parent.id);
1300
1295
  }
1301
- async multiRemove(nodes) {
1302
- await Promise.all(nodes.map(async (removeNode) => {
1303
- await beforeRemove(removeNode);
1304
- }));
1305
- const nodeIds = nodes.map((node) => node.id);
1306
- this.addModifiedNodeId(nodeIds.join("-"));
1296
+ async remove(nodeOrNodeList) {
1297
+ const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
1298
+ await Promise.all(nodes.map((node) => this.doRemove(node)));
1307
1299
  this.pushHistoryState();
1308
- this.emit("multiRemove", nodes);
1309
- return nodes;
1300
+ this.emit("remove", nodes);
1310
1301
  }
1311
- async update(config) {
1302
+ async doUpdate(config) {
1312
1303
  if (!config?.id)
1313
1304
  throw new Error("\u6CA1\u6709\u914D\u7F6E\u6216\u8005\u914D\u7F6E\u7F3A\u5C11id\u503C");
1314
1305
  const info = this.getNodeInfo(config.id, false);
@@ -1344,15 +1335,24 @@ class Editor$1 extends BaseService {
1344
1335
  const targetIndex = nodes.findIndex((nodeItem) => `${nodeItem.id}` === `${newConfig.id}`);
1345
1336
  nodes.splice(targetIndex, 1, newConfig);
1346
1337
  this.set("nodes", nodes);
1347
- this.get("stage")?.update({ config: cloneDeep(newConfig), root: cloneDeep(this.get("root")) });
1338
+ this.get("stage")?.update({
1339
+ config: cloneDeep(newConfig),
1340
+ parentId: parent.id,
1341
+ root: cloneDeep(this.get("root"))
1342
+ });
1348
1343
  if (newConfig.type === NodeType.PAGE) {
1349
1344
  this.set("page", newConfig);
1350
1345
  }
1351
1346
  this.addModifiedNodeId(newConfig.id);
1352
- this.pushHistoryState();
1353
- this.emit("update", newConfig);
1354
1347
  return newConfig;
1355
1348
  }
1349
+ async update(config) {
1350
+ const nodes = Array.isArray(config) ? config : [config];
1351
+ const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
1352
+ this.pushHistoryState();
1353
+ this.emit("update", newNodes);
1354
+ return Array.isArray(config) ? newNodes : newNodes[0];
1355
+ }
1356
1356
  async sort(id1, id2) {
1357
1357
  const node = this.get("node");
1358
1358
  const parent = cloneDeep(toRaw(this.get("parent")));
@@ -1363,7 +1363,11 @@ class Editor$1 extends BaseService {
1363
1363
  parent.items.splice(index2, 0, ...parent.items.splice(index1, 1));
1364
1364
  await this.update(parent);
1365
1365
  await this.select(node);
1366
- this.get("stage")?.update({ config: cloneDeep(node), root: cloneDeep(this.get("root")) });
1366
+ this.get("stage")?.update({
1367
+ config: cloneDeep(node),
1368
+ parentId: parent.id,
1369
+ root: cloneDeep(this.get("root"))
1370
+ });
1367
1371
  this.addModifiedNodeId(parent.id);
1368
1372
  this.pushHistoryState();
1369
1373
  }
@@ -1374,20 +1378,26 @@ class Editor$1 extends BaseService {
1374
1378
  }
1375
1379
  async paste(position = {}) {
1376
1380
  const config = await storageService.getItem(COPY_STORAGE_KEY);
1377
- if (!config)
1381
+ if (!Array.isArray(config))
1378
1382
  return;
1379
- const pasteConfigs = await beforePaste(position, config);
1380
- return await this.multiAdd(pasteConfigs);
1383
+ const pasteConfigs = await this.doPaste(config, position);
1384
+ return this.add(pasteConfigs);
1381
1385
  }
1382
- async alignCenter(config) {
1383
- const parent = this.get("parent");
1384
- const node = this.get("node");
1385
- const layout = await this.getLayout(toRaw(parent), toRaw(node));
1386
+ async doPaste(config, position = {}) {
1387
+ const pasteConfigs = await beforePaste(position, cloneDeep(config));
1388
+ return pasteConfigs;
1389
+ }
1390
+ async doAlignCenter(config) {
1391
+ const parent = this.getParentById(config.id);
1392
+ if (!parent)
1393
+ throw new Error("\u627E\u4E0D\u5230\u7236\u8282\u70B9");
1394
+ const node = cloneDeep(toRaw(config));
1395
+ const layout = await this.getLayout(parent, node);
1386
1396
  if (layout === Layout.RELATIVE) {
1387
- return;
1397
+ return config;
1388
1398
  }
1389
1399
  if (!node.style)
1390
- return;
1400
+ return config;
1391
1401
  const stage = this.get("stage");
1392
1402
  const doc = stage?.renderer.contentWindow?.document;
1393
1403
  if (doc) {
@@ -1399,14 +1409,15 @@ class Editor$1 extends BaseService {
1399
1409
  } else if (parent.style && isNumber(parent.style?.width) && isNumber(node.style?.width)) {
1400
1410
  node.style.left = (parent.style.width - node.style.width) / 2;
1401
1411
  }
1402
- await this.update(node);
1403
- this.get("stage")?.update({
1404
- config: cloneDeep(toRaw(node)),
1405
- root: cloneDeep(this.get("root"))
1406
- });
1407
- this.addModifiedNodeId(config.id);
1408
- this.pushHistoryState();
1409
- return config;
1412
+ return node;
1413
+ }
1414
+ async alignCenter(config) {
1415
+ const nodes = Array.isArray(config) ? config : [config];
1416
+ const stage = this.get("stage");
1417
+ const newNodes = await Promise.all(nodes.map((node) => this.doAlignCenter(node)));
1418
+ const newNode = await this.update(newNodes);
1419
+ await stage?.multiSelect(newNodes.map((node) => node.id));
1420
+ return newNode;
1410
1421
  }
1411
1422
  async moveLayer(offset) {
1412
1423
  const parent = this.get("parent");
@@ -1420,10 +1431,14 @@ class Editor$1 extends BaseService {
1420
1431
  } else {
1421
1432
  brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
1422
1433
  }
1434
+ const grandparent = this.getParentById(parent.id);
1423
1435
  this.get("stage")?.update({
1424
1436
  config: cloneDeep(toRaw(parent)),
1437
+ parentId: grandparent?.id,
1425
1438
  root: cloneDeep(this.get("root"))
1426
1439
  });
1440
+ this.addModifiedNodeId(parent.id);
1441
+ this.pushHistoryState();
1427
1442
  }
1428
1443
  async moveToContainer(config, targetId) {
1429
1444
  const { node, parent } = this.getNodeInfo(config.id, false);
@@ -1433,17 +1448,18 @@ class Editor$1 extends BaseService {
1433
1448
  const root = cloneDeep(this.get("root"));
1434
1449
  const index = getNodeIndex(node, parent);
1435
1450
  parent.items?.splice(index, 1);
1436
- await stage.remove({ id: node.id, root });
1451
+ await stage.remove({ id: node.id, parentId: parent.id, root });
1437
1452
  const layout = await this.getLayout(target);
1438
1453
  const newConfig = mergeWith(cloneDeep(node), config, (objValue, srcValue) => {
1439
1454
  if (Array.isArray(srcValue)) {
1440
1455
  return srcValue;
1441
1456
  }
1442
1457
  });
1443
- newConfig.style = getInitPositionStyle(newConfig.style, layout, target, stage);
1458
+ newConfig.style = getInitPositionStyle(newConfig.style, layout);
1444
1459
  target.items.push(newConfig);
1445
1460
  await stage.select(targetId);
1446
- await stage.update({ config: cloneDeep(target), root });
1461
+ const targetParent = this.getParentById(target.id);
1462
+ await stage.update({ config: cloneDeep(target), parentId: targetParent?.id, root });
1447
1463
  await this.select(newConfig);
1448
1464
  stage.select(newConfig.id);
1449
1465
  this.addModifiedNodeId(target.id);
@@ -1466,7 +1482,7 @@ class Editor$1 extends BaseService {
1466
1482
  const node = toRaw(this.get("node"));
1467
1483
  if (!node || isPage(node))
1468
1484
  return;
1469
- const { style, id } = node;
1485
+ const { style, id, type } = node;
1470
1486
  if (!style || style.position !== "absolute")
1471
1487
  return;
1472
1488
  if (top && !isNumber(style.top))
@@ -1475,6 +1491,7 @@ class Editor$1 extends BaseService {
1475
1491
  return;
1476
1492
  this.update({
1477
1493
  id,
1494
+ type,
1478
1495
  style: {
1479
1496
  ...style,
1480
1497
  left: Number(style.left) + left,
@@ -1489,6 +1506,10 @@ class Editor$1 extends BaseService {
1489
1506
  this.set("nodes", []);
1490
1507
  this.set("page", null);
1491
1508
  this.set("parent", null);
1509
+ this.set("stage", null);
1510
+ this.set("highlightNode", null);
1511
+ this.set("modifiedNodeIds", /* @__PURE__ */ new Map());
1512
+ this.set("pageLength", /* @__PURE__ */ new Map());
1492
1513
  }
1493
1514
  resetModifiedNodeId() {
1494
1515
  this.get("modifiedNodeIds").clear();
@@ -1558,8 +1579,8 @@ class Editor$1 extends BaseService {
1558
1579
  }
1559
1580
  const editorService = new Editor$1();
1560
1581
 
1561
- const eventMap = reactive({});
1562
- const methodMap = reactive({});
1582
+ let eventMap = reactive({});
1583
+ let methodMap = reactive({});
1563
1584
  class Events extends BaseService {
1564
1585
  constructor() {
1565
1586
  super([]);
@@ -1599,6 +1620,11 @@ class Events extends BaseService {
1599
1620
  getMethod(type) {
1600
1621
  return cloneDeep(methodMap[type] || DEFAULT_METHODS);
1601
1622
  }
1623
+ destroy() {
1624
+ eventMap = reactive({});
1625
+ methodMap = reactive({});
1626
+ this.removeAllListeners();
1627
+ }
1602
1628
  }
1603
1629
  const eventsService = new Events();
1604
1630
 
@@ -1805,7 +1831,6 @@ const fillConfig = (config = []) => [
1805
1831
  ]
1806
1832
  }
1807
1833
  ];
1808
- const DEFAULT_CONFIG = fillConfig([]);
1809
1834
 
1810
1835
  const log = (...args) => {
1811
1836
  if (process.env.NODE_ENV === "development") {
@@ -1833,116 +1858,303 @@ const error = (...args) => {
1833
1858
  }
1834
1859
  };
1835
1860
 
1836
- const _sfc_main$j = defineComponent({
1837
- components: { Plus },
1838
- setup() {
1839
- const services = inject("services");
1840
- return {
1841
- clickHandler() {
1842
- const { editorService } = services || {};
1843
- if (!editorService)
1844
- return;
1845
- editorService.add({
1846
- type: NodeType.PAGE,
1847
- name: generatePageNameByApp(toRaw(editorService.get("root")))
1848
- });
1849
- }
1850
- };
1851
- }
1852
- });
1853
-
1854
- const _hoisted_1$b = { class: "m-editor-empty-panel" };
1855
- const _hoisted_2$4 = { class: "m-editor-empty-content" };
1856
- const _hoisted_3$1 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1857
- function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
1858
- const _component_plus = resolveComponent("plus");
1859
- const _component_el_icon = resolveComponent("el-icon");
1860
- return openBlock(), createElementBlock("div", _hoisted_1$b, [
1861
- createElementVNode("div", _hoisted_2$4, [
1862
- createElementVNode("div", {
1863
- class: "m-editor-empty-button",
1864
- onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
1865
- }, [
1866
- createElementVNode("div", null, [
1867
- createVNode(_component_el_icon, null, {
1868
- default: withCtx(() => [
1869
- createVNode(_component_plus)
1870
- ]),
1871
- _: 1
1872
- })
1873
- ]),
1874
- _hoisted_3$1
1875
- ])
1876
- ])
1877
- ]);
1878
- }
1879
- const AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$d]]);
1880
-
1881
- const _sfc_main$i = defineComponent({
1882
- name: "m-editor-resize",
1883
- props: {
1884
- type: {
1885
- type: String
1886
- }
1861
+ const DEFAULT_LEFT_COLUMN_WIDTH = 310;
1862
+ const MIN_LEFT_COLUMN_WIDTH = 45;
1863
+ const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
1864
+ const MIN_RIGHT_COLUMN_WIDTH = 1;
1865
+ const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
1866
+ const defaultColumnWidth = {
1867
+ left: DEFAULT_LEFT_COLUMN_WIDTH,
1868
+ center: globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH,
1869
+ right: DEFAULT_RIGHT_COLUMN_WIDTH
1870
+ };
1871
+ const state = reactive({
1872
+ uiSelectMode: false,
1873
+ showSrc: false,
1874
+ zoom: 1,
1875
+ stageContainerRect: {
1876
+ width: 0,
1877
+ height: 0
1887
1878
  },
1888
- setup(props) {
1889
- const services = inject("services");
1890
- const target = ref();
1891
- let getso;
1892
- onMounted(() => {
1893
- if (!target.value)
1894
- return;
1895
- getso = new Gesto(target.value, {
1896
- container: window,
1897
- pinchOutside: true
1898
- }).on("drag", (e) => {
1899
- if (!target.value || !services)
1900
- return;
1901
- let { left, right } = {
1902
- ...toRaw(services.uiService.get("columnWidth"))
1903
- };
1904
- if (props.type === "left") {
1905
- left += e.deltaX;
1906
- } else if (props.type === "right") {
1907
- right -= e.deltaX;
1908
- }
1909
- services.uiService.set("columnWidth", {
1910
- left,
1911
- right
1912
- });
1879
+ stageRect: {
1880
+ width: 375,
1881
+ height: 817
1882
+ },
1883
+ columnWidth: defaultColumnWidth,
1884
+ showGuides: true,
1885
+ showRule: true,
1886
+ propsPanelSize: "small"
1887
+ });
1888
+ class Ui extends BaseService {
1889
+ constructor() {
1890
+ super([]);
1891
+ globalThis.addEventListener("resize", () => {
1892
+ this.setColumnWidth({
1893
+ center: "auto"
1913
1894
  });
1914
1895
  });
1915
- onUnmounted(() => {
1916
- getso?.unset();
1917
- });
1918
- return {
1919
- target
1920
- };
1921
1896
  }
1922
- });
1923
-
1924
- const _hoisted_1$a = {
1925
- ref: "target",
1926
- class: "m-editor-resizer"
1927
- };
1928
- function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
1929
- return openBlock(), createElementBlock("span", _hoisted_1$a, [
1930
- renderSlot(_ctx.$slots, "default")
1931
- ], 512);
1932
- }
1933
- const Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$c]]);
1934
-
1935
- const _sfc_main$h = defineComponent({
1936
- components: {
1937
- AddPageBox,
1938
- Resizer
1939
- },
1940
- props: {
1941
- codeOptions: {
1942
- type: Object,
1943
- default: () => ({})
1944
- }
1945
- },
1897
+ set(name, value) {
1898
+ const mask = editorService.get("stage")?.mask;
1899
+ if (name === "columnWidth") {
1900
+ this.setColumnWidth(value);
1901
+ return;
1902
+ }
1903
+ if (name === "stageRect") {
1904
+ this.setStageRect(value);
1905
+ return;
1906
+ }
1907
+ if (name === "showGuides") {
1908
+ mask?.showGuides(value);
1909
+ }
1910
+ if (name === "showRule") {
1911
+ mask?.showRule(value);
1912
+ }
1913
+ state[name] = value;
1914
+ }
1915
+ get(name) {
1916
+ return state[name];
1917
+ }
1918
+ initColumnWidth() {
1919
+ const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
1920
+ if (columnWidthCacheData) {
1921
+ try {
1922
+ const columnWidthCache = JSON.parse(columnWidthCacheData);
1923
+ this.setColumnWidth(columnWidthCache);
1924
+ } catch (e) {
1925
+ console.error(e);
1926
+ }
1927
+ }
1928
+ }
1929
+ zoom(zoom) {
1930
+ this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
1931
+ if (this.get("zoom") < 0.1)
1932
+ this.set("zoom", 0.1);
1933
+ }
1934
+ calcZoom() {
1935
+ const { stageRect, stageContainerRect } = state;
1936
+ const { height, width } = stageContainerRect;
1937
+ if (!width || !height)
1938
+ return 1;
1939
+ const stageWidth = stageRect.width + 30;
1940
+ const stageHeight = stageRect.height + 30;
1941
+ if (width > stageWidth && height > stageHeight) {
1942
+ return 1;
1943
+ }
1944
+ return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
1945
+ }
1946
+ destroy() {
1947
+ this.removeAllListeners();
1948
+ }
1949
+ setColumnWidth({ left, center, right }) {
1950
+ const columnWidth = {
1951
+ ...toRaw(this.get("columnWidth"))
1952
+ };
1953
+ if (left) {
1954
+ columnWidth.left = Math.max(left, MIN_LEFT_COLUMN_WIDTH);
1955
+ }
1956
+ if (right) {
1957
+ columnWidth.right = Math.max(right, MIN_RIGHT_COLUMN_WIDTH);
1958
+ }
1959
+ if (!center || center === "auto") {
1960
+ const bodyWidth = globalThis.document.body.clientWidth;
1961
+ columnWidth.center = bodyWidth - (columnWidth?.left || 0) - (columnWidth?.right || 0);
1962
+ if (columnWidth.center <= 0) {
1963
+ columnWidth.left = defaultColumnWidth.left;
1964
+ columnWidth.center = defaultColumnWidth.center;
1965
+ columnWidth.right = defaultColumnWidth.right;
1966
+ }
1967
+ } else {
1968
+ columnWidth.center = center;
1969
+ }
1970
+ globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
1971
+ state.columnWidth = columnWidth;
1972
+ }
1973
+ setStageRect(value) {
1974
+ state.stageRect = {
1975
+ ...state.stageRect,
1976
+ ...value
1977
+ };
1978
+ state.zoom = this.calcZoom();
1979
+ }
1980
+ }
1981
+ const uiService = new Ui();
1982
+
1983
+ const root = computed(() => editorService.get("root"));
1984
+ const page = computed(() => editorService.get("page"));
1985
+ const zoom = computed(() => uiService.get("zoom") || 1);
1986
+ const uiSelectMode = computed(() => uiService.get("uiSelectMode"));
1987
+ const getGuideLineKey = (key) => `${key}_${root.value?.id}_${page.value?.id}`;
1988
+ const useStage = (stageOptions) => {
1989
+ const stage = new StageCore({
1990
+ render: stageOptions.render,
1991
+ runtimeUrl: stageOptions.runtimeUrl,
1992
+ zoom: zoom.value,
1993
+ autoScrollIntoView: stageOptions.autoScrollIntoView,
1994
+ isContainer: stageOptions.isContainer,
1995
+ containerHighlightClassName: stageOptions.containerHighlightClassName,
1996
+ containerHighlightDuration: stageOptions.containerHighlightDuration,
1997
+ containerHighlightType: stageOptions.containerHighlightType,
1998
+ canSelect: (el, event, stop) => {
1999
+ const elCanSelect = stageOptions.canSelect(el);
2000
+ if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
2001
+ document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
2002
+ return stop();
2003
+ }
2004
+ return elCanSelect;
2005
+ },
2006
+ moveableOptions: stageOptions.moveableOptions,
2007
+ updateDragEl: stageOptions.updateDragEl
2008
+ });
2009
+ stage.mask.setGuides([
2010
+ getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
2011
+ getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
2012
+ ]);
2013
+ stage.on("select", (el) => {
2014
+ editorService.select(el.id);
2015
+ });
2016
+ stage.on("highlight", (el) => {
2017
+ editorService.highlight(el.id);
2018
+ });
2019
+ stage.on("multiSelect", (els) => {
2020
+ editorService.multiSelect(els.map((el) => el.id));
2021
+ });
2022
+ stage.on("update", (ev) => {
2023
+ if (ev.parentEl) {
2024
+ for (const data of ev.data) {
2025
+ editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
2026
+ }
2027
+ return;
2028
+ }
2029
+ editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
2030
+ });
2031
+ stage.on("sort", (ev) => {
2032
+ editorService.sort(ev.src, ev.dist);
2033
+ });
2034
+ stage.on("changeGuides", (e) => {
2035
+ uiService.set("showGuides", true);
2036
+ if (!root.value || !page.value)
2037
+ return;
2038
+ const storageKey = getGuideLineKey(e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY);
2039
+ if (e.guides.length) {
2040
+ globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
2041
+ } else {
2042
+ globalThis.localStorage.removeItem(storageKey);
2043
+ }
2044
+ });
2045
+ return stage;
2046
+ };
2047
+
2048
+ const _sfc_main$k = defineComponent({
2049
+ components: { Plus },
2050
+ setup() {
2051
+ const services = inject("services");
2052
+ return {
2053
+ clickHandler() {
2054
+ const { editorService } = services || {};
2055
+ if (!editorService)
2056
+ return;
2057
+ editorService.add({
2058
+ type: NodeType.PAGE,
2059
+ name: generatePageNameByApp(toRaw(editorService.get("root")))
2060
+ });
2061
+ }
2062
+ };
2063
+ }
2064
+ });
2065
+
2066
+ const _hoisted_1$9 = { class: "m-editor-empty-panel" };
2067
+ const _hoisted_2$4 = { class: "m-editor-empty-content" };
2068
+ const _hoisted_3 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2069
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
2070
+ const _component_plus = resolveComponent("plus");
2071
+ const _component_el_icon = resolveComponent("el-icon");
2072
+ return openBlock(), createElementBlock("div", _hoisted_1$9, [
2073
+ createElementVNode("div", _hoisted_2$4, [
2074
+ createElementVNode("div", {
2075
+ class: "m-editor-empty-button",
2076
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
2077
+ }, [
2078
+ createElementVNode("div", null, [
2079
+ createVNode(_component_el_icon, null, {
2080
+ default: withCtx(() => [
2081
+ createVNode(_component_plus)
2082
+ ]),
2083
+ _: 1
2084
+ })
2085
+ ]),
2086
+ _hoisted_3
2087
+ ])
2088
+ ])
2089
+ ]);
2090
+ }
2091
+ const AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$8]]);
2092
+
2093
+ const _sfc_main$j = defineComponent({
2094
+ name: "m-editor-resize",
2095
+ props: {
2096
+ type: {
2097
+ type: String
2098
+ }
2099
+ },
2100
+ setup(props) {
2101
+ const services = inject("services");
2102
+ const target = ref();
2103
+ let getso;
2104
+ onMounted(() => {
2105
+ if (!target.value)
2106
+ return;
2107
+ getso = new Gesto(target.value, {
2108
+ container: window,
2109
+ pinchOutside: true
2110
+ }).on("drag", (e) => {
2111
+ if (!target.value || !services)
2112
+ return;
2113
+ let { left, right } = {
2114
+ ...toRaw(services.uiService.get("columnWidth"))
2115
+ };
2116
+ if (props.type === "left") {
2117
+ left += e.deltaX;
2118
+ } else if (props.type === "right") {
2119
+ right -= e.deltaX;
2120
+ }
2121
+ services.uiService.set("columnWidth", {
2122
+ left,
2123
+ right
2124
+ });
2125
+ });
2126
+ });
2127
+ onUnmounted(() => {
2128
+ getso?.unset();
2129
+ });
2130
+ return {
2131
+ target
2132
+ };
2133
+ }
2134
+ });
2135
+
2136
+ const _hoisted_1$8 = {
2137
+ ref: "target",
2138
+ class: "m-editor-resizer"
2139
+ };
2140
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2141
+ return openBlock(), createElementBlock("span", _hoisted_1$8, [
2142
+ renderSlot(_ctx.$slots, "default")
2143
+ ], 512);
2144
+ }
2145
+ const Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$7]]);
2146
+
2147
+ const _sfc_main$i = defineComponent({
2148
+ components: {
2149
+ AddPageBox,
2150
+ Resizer
2151
+ },
2152
+ props: {
2153
+ codeOptions: {
2154
+ type: Object,
2155
+ default: () => ({})
2156
+ }
2157
+ },
1946
2158
  setup() {
1947
2159
  const { editorService, uiService } = inject("services") || {};
1948
2160
  const root = computed(() => editorService?.get("root"));
@@ -1962,17 +2174,17 @@ const _sfc_main$h = defineComponent({
1962
2174
  }
1963
2175
  });
1964
2176
 
1965
- const _hoisted_1$9 = { class: "m-editor" };
2177
+ const _hoisted_1$7 = { class: "m-editor" };
1966
2178
  const _hoisted_2$3 = {
1967
2179
  key: 1,
1968
2180
  class: "m-editor-content"
1969
2181
  };
1970
- function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2182
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
1971
2183
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
1972
2184
  const _component_resizer = resolveComponent("resizer");
1973
2185
  const _component_el_scrollbar = resolveComponent("el-scrollbar");
1974
2186
  const _component_add_page_box = resolveComponent("add-page-box");
1975
- return openBlock(), createElementBlock("div", _hoisted_1$9, [
2187
+ return openBlock(), createElementBlock("div", _hoisted_1$7, [
1976
2188
  renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
1977
2189
  _ctx.showSrc ? (openBlock(), createBlock(_component_magic_code_editor, {
1978
2190
  key: 0,
@@ -2013,209 +2225,112 @@ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2013
2225
  ]))
2014
2226
  ]);
2015
2227
  }
2016
- const Framework = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$b]]);
2228
+ const Framework = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$6]]);
2017
2229
 
2018
- const _sfc_main$g = defineComponent({
2019
- name: "m-icon",
2020
- components: { Edit },
2230
+ const _hoisted_1$6 = ["src"];
2231
+ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2232
+ __name: "Icon",
2021
2233
  props: {
2022
- icon: {
2023
- type: [String, Object]
2024
- }
2234
+ icon: null
2025
2235
  },
2026
- setup() {
2027
- return {
2028
- toRaw
2236
+ setup(__props) {
2237
+ return (_ctx, _cache) => {
2238
+ const _component_el_icon = resolveComponent("el-icon");
2239
+ return !__props.icon ? (openBlock(), createBlock(_component_el_icon, { key: 0 }, {
2240
+ default: withCtx(() => [
2241
+ createVNode(unref(Edit))
2242
+ ]),
2243
+ _: 1
2244
+ })) : typeof __props.icon === "string" && __props.icon.startsWith("http") ? (openBlock(), createBlock(_component_el_icon, { key: 1 }, {
2245
+ default: withCtx(() => [
2246
+ createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$6)
2247
+ ]),
2248
+ _: 1
2249
+ })) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
2250
+ key: 2,
2251
+ class: normalizeClass(__props.icon)
2252
+ }, null, 2)) : (openBlock(), createBlock(_component_el_icon, { key: 3 }, {
2253
+ default: withCtx(() => [
2254
+ (openBlock(), createBlock(resolveDynamicComponent(toRaw(__props.icon))))
2255
+ ]),
2256
+ _: 1
2257
+ }));
2029
2258
  };
2030
2259
  }
2031
2260
  });
2032
2261
 
2033
- const _hoisted_1$8 = ["src"];
2034
- function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2035
- const _component_edit = resolveComponent("edit");
2036
- const _component_el_icon = resolveComponent("el-icon");
2037
- return !_ctx.icon ? (openBlock(), createBlock(_component_el_icon, { key: 0 }, {
2038
- default: withCtx(() => [
2039
- createVNode(_component_edit)
2040
- ]),
2041
- _: 1
2042
- })) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (openBlock(), createElementBlock("img", {
2043
- key: 1,
2044
- src: _ctx.icon
2045
- }, null, 8, _hoisted_1$8)) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
2046
- key: 2,
2047
- class: normalizeClass(_ctx.icon)
2048
- }, null, 2)) : (openBlock(), createBlock(_component_el_icon, { key: 3 }, {
2049
- default: withCtx(() => [
2050
- (openBlock(), createBlock(resolveDynamicComponent(_ctx.toRaw(_ctx.icon))))
2051
- ]),
2052
- _: 1
2053
- }));
2054
- }
2055
- const MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$a]]);
2056
-
2057
- const _hoisted_1$7 = {
2262
+ const _hoisted_1$5 = {
2058
2263
  key: 1,
2059
2264
  class: "menu-item-text"
2060
2265
  };
2061
- const _hoisted_2$2 = {
2062
- class: "menu-item-text",
2063
- style: { "margin": "0 5px" }
2064
- };
2065
- const _hoisted_3 = { class: "el-dropdown-link menubar-menu-button" };
2066
- const _sfc_main$f = /* @__PURE__ */ defineComponent({
2266
+ const _hoisted_2$2 = { class: "el-dropdown-link menubar-menu-button" };
2267
+ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2067
2268
  __name: "ToolButton",
2068
2269
  props: {
2069
- data: {
2070
- type: [Object, String],
2071
- require: true,
2072
- default: () => ({
2073
- type: "text",
2074
- display: false
2075
- })
2076
- },
2077
- eventType: {
2078
- type: String,
2079
- default: "click"
2080
- }
2270
+ data: { default: () => ({
2271
+ type: "text",
2272
+ display: false
2273
+ }) },
2274
+ eventType: { default: "click" }
2081
2275
  },
2082
2276
  setup(__props) {
2083
2277
  const props = __props;
2084
2278
  const services = inject("services");
2085
- const uiService = services?.uiService;
2086
- const zoom = computed(() => uiService?.get("zoom") ?? 1);
2087
- const showGuides = computed(() => uiService?.get("showGuides") ?? true);
2088
- const showRule = computed(() => uiService?.get("showRule") ?? true);
2089
- const zoomInHandler = () => uiService?.zoom(0.1);
2090
- const zoomOutHandler = () => uiService?.zoom(-0.1);
2091
- const item = computed(() => {
2092
- if (typeof props.data !== "string") {
2093
- return props.data;
2094
- }
2095
- switch (props.data) {
2096
- case "/":
2097
- return {
2098
- type: "divider"
2099
- };
2100
- case "zoom":
2101
- return {
2102
- type: "zoom"
2103
- };
2104
- case "delete":
2105
- return {
2106
- type: "button",
2107
- icon: markRaw(Delete),
2108
- tooltip: "\u522A\u9664",
2109
- disabled: () => services?.editorService.get("node")?.type === NodeType.PAGE,
2110
- handler: () => services?.editorService.remove(services?.editorService.get("node"))
2111
- };
2112
- case "undo":
2113
- return {
2114
- type: "button",
2115
- icon: markRaw(Back),
2116
- tooltip: "\u540E\u9000",
2117
- disabled: () => !services?.historyService.state.canUndo,
2118
- handler: () => services?.editorService.undo()
2119
- };
2120
- case "redo":
2121
- return {
2122
- type: "button",
2123
- icon: markRaw(Right),
2124
- tooltip: "\u524D\u8FDB",
2125
- disabled: () => !services?.historyService.state.canRedo,
2126
- handler: () => services?.editorService.redo()
2127
- };
2128
- case "zoom-in":
2129
- return {
2130
- type: "button",
2131
- icon: markRaw(ZoomIn),
2132
- tooltip: "\u653E\u5927",
2133
- handler: zoomInHandler
2134
- };
2135
- case "zoom-out":
2136
- return {
2137
- type: "button",
2138
- icon: markRaw(ZoomOut),
2139
- tooltip: "\u7E2E\u5C0F",
2140
- handler: zoomOutHandler
2141
- };
2142
- case "rule":
2143
- return {
2144
- type: "button",
2145
- icon: markRaw(ScaleToOriginal),
2146
- tooltip: showRule.value ? "\u9690\u85CF\u6807\u5C3A" : "\u663E\u793A\u6807\u5C3A",
2147
- handler: () => uiService?.set("showRule", !showRule.value)
2148
- };
2149
- case "guides":
2150
- return {
2151
- type: "button",
2152
- icon: markRaw(Grid),
2153
- tooltip: showGuides.value ? "\u9690\u85CF\u53C2\u8003\u7EBF" : "\u663E\u793A\u53C2\u8003\u7EBF",
2154
- handler: () => uiService?.set("showGuides", !showGuides.value)
2155
- };
2156
- default:
2157
- return {
2158
- type: "text",
2159
- text: props.data
2160
- };
2161
- }
2162
- });
2163
2279
  const disabled = computed(() => {
2164
- if (typeof item.value === "string")
2280
+ if (typeof props.data === "string")
2165
2281
  return false;
2166
- if (item.value.type === "component")
2282
+ if (props.data.type === "component")
2167
2283
  return false;
2168
- if (typeof item.value.disabled === "function") {
2169
- return item.value.disabled(services);
2284
+ if (typeof props.data.disabled === "function") {
2285
+ return props.data.disabled(services);
2170
2286
  }
2171
- return item.value.disabled;
2287
+ return props.data.disabled;
2172
2288
  });
2173
- const buttonHandler = (item2, event) => {
2174
- if (disabled.value)
2175
- return;
2176
- if (typeof item2.handler === "function" && services) {
2177
- item2.handler?.(services, event);
2178
- }
2179
- };
2180
2289
  const display = computed(() => {
2181
- if (!item.value)
2290
+ if (!props.data)
2182
2291
  return false;
2183
- if (typeof item.value === "string")
2292
+ if (typeof props.data === "string")
2184
2293
  return true;
2185
- if (typeof item.value.display === "function") {
2186
- return item.value.display(services);
2294
+ if (typeof props.data.display === "function") {
2295
+ return props.data.display(services);
2187
2296
  }
2188
- return item.value.display ?? true;
2297
+ return props.data.display ?? true;
2189
2298
  });
2299
+ const buttonHandler = (item, event) => {
2300
+ if (disabled.value)
2301
+ return;
2302
+ if (typeof item.handler === "function" && services) {
2303
+ item.handler?.(services, event);
2304
+ }
2305
+ };
2190
2306
  const dropdownHandler = (command) => {
2191
2307
  if (command.item.handler) {
2192
2308
  command.item.handler(services);
2193
2309
  }
2194
2310
  };
2195
- const clickHandler = (item2, event) => {
2311
+ const clickHandler = (item, event) => {
2196
2312
  if (props.eventType !== "click")
2197
2313
  return;
2198
- if (item2.type === "button") {
2199
- buttonHandler(item2, event);
2314
+ if (item.type === "button") {
2315
+ buttonHandler(item, event);
2200
2316
  }
2201
2317
  };
2202
- const mousedownHandler = (item2, event) => {
2318
+ const mousedownHandler = (item, event) => {
2203
2319
  if (props.eventType !== "mousedown")
2204
2320
  return;
2205
- if (item2.type === "button") {
2206
- buttonHandler(item2, event);
2321
+ if (item.type === "button") {
2322
+ buttonHandler(item, event);
2207
2323
  }
2208
2324
  };
2209
- const mouseupHandler = (item2, event) => {
2325
+ const mouseupHandler = (item, event) => {
2210
2326
  if (props.eventType !== "mouseup")
2211
2327
  return;
2212
- if (item2.type === "button") {
2213
- buttonHandler(item2, event);
2328
+ if (item.type === "button") {
2329
+ buttonHandler(item, event);
2214
2330
  }
2215
2331
  };
2216
2332
  return (_ctx, _cache) => {
2217
2333
  const _component_el_divider = resolveComponent("el-divider");
2218
- const _component_tool_button = resolveComponent("tool-button", true);
2219
2334
  const _component_el_button = resolveComponent("el-button");
2220
2335
  const _component_el_tooltip = resolveComponent("el-tooltip");
2221
2336
  const _component_el_icon = resolveComponent("el-icon");
@@ -2224,30 +2339,20 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2224
2339
  const _component_el_dropdown = resolveComponent("el-dropdown");
2225
2340
  return unref(display) ? (openBlock(), createElementBlock("div", {
2226
2341
  key: 0,
2227
- class: normalizeClass(["menu-item", unref(item).type]),
2228
- onClick: _cache[0] || (_cache[0] = ($event) => clickHandler(unref(item), $event)),
2229
- onMousedown: _cache[1] || (_cache[1] = ($event) => mousedownHandler(unref(item), $event)),
2230
- onMouseup: _cache[2] || (_cache[2] = ($event) => mouseupHandler(unref(item), $event))
2342
+ class: normalizeClass(["menu-item", `${__props.data.type} ${__props.data.className || ""}`]),
2343
+ onClick: _cache[0] || (_cache[0] = ($event) => clickHandler(__props.data, $event)),
2344
+ onMousedown: _cache[1] || (_cache[1] = ($event) => mousedownHandler(__props.data, $event)),
2345
+ onMouseup: _cache[2] || (_cache[2] = ($event) => mouseupHandler(__props.data, $event))
2231
2346
  }, [
2232
- unref(item).type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
2347
+ __props.data.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
2233
2348
  key: 0,
2234
- direction: unref(item).direction || "vertical"
2235
- }, null, 8, ["direction"])) : unref(item).type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$7, toDisplayString(unref(item).text), 1)) : unref(item).type === "zoom" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2236
- createVNode(_component_tool_button, {
2237
- data: { type: "button", icon: unref(ZoomOut), handler: zoomOutHandler, tooltip: "\u7F29\u5C0F" },
2238
- "event-type": __props.eventType
2239
- }, null, 8, ["data", "event-type"]),
2240
- createElementVNode("span", _hoisted_2$2, toDisplayString(parseInt(`${unref(zoom) * 100}`, 10)) + "%", 1),
2241
- createVNode(_component_tool_button, {
2242
- data: { type: "button", icon: unref(ZoomIn), handler: zoomInHandler, tooltip: "\u653E\u5927" },
2243
- "event-type": __props.eventType
2244
- }, null, 8, ["data", "event-type"])
2245
- ], 64)) : unref(item).type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
2246
- unref(item).tooltip ? (openBlock(), createBlock(_component_el_tooltip, {
2349
+ direction: __props.data.direction || "vertical"
2350
+ }, null, 8, ["direction"])) : __props.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$5, toDisplayString(__props.data.text), 1)) : __props.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2351
+ __props.data.tooltip ? (openBlock(), createBlock(_component_el_tooltip, {
2247
2352
  key: 0,
2248
2353
  effect: "dark",
2249
2354
  placement: "bottom-start",
2250
- content: unref(item).tooltip
2355
+ content: __props.data.tooltip
2251
2356
  }, {
2252
2357
  default: withCtx(() => [
2253
2358
  createVNode(_component_el_button, {
@@ -2256,11 +2361,11 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2256
2361
  disabled: unref(disabled)
2257
2362
  }, {
2258
2363
  default: withCtx(() => [
2259
- unref(item).icon ? (openBlock(), createBlock(MIcon, {
2364
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$h, {
2260
2365
  key: 0,
2261
- icon: unref(item).icon
2366
+ icon: __props.data.icon
2262
2367
  }, null, 8, ["icon"])) : createCommentVNode("", true),
2263
- createElementVNode("span", null, toDisplayString(unref(item).text), 1)
2368
+ createElementVNode("span", null, toDisplayString(__props.data.text), 1)
2264
2369
  ]),
2265
2370
  _: 1
2266
2371
  }, 8, ["disabled"])
@@ -2273,27 +2378,27 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2273
2378
  disabled: unref(disabled)
2274
2379
  }, {
2275
2380
  default: withCtx(() => [
2276
- unref(item).icon ? (openBlock(), createBlock(MIcon, {
2381
+ __props.data.icon ? (openBlock(), createBlock(_sfc_main$h, {
2277
2382
  key: 0,
2278
- icon: unref(item).icon
2383
+ icon: __props.data.icon
2279
2384
  }, null, 8, ["icon"])) : createCommentVNode("", true),
2280
- createElementVNode("span", null, toDisplayString(unref(item).text), 1)
2385
+ createElementVNode("span", null, toDisplayString(__props.data.text), 1)
2281
2386
  ]),
2282
2387
  _: 1
2283
2388
  }, 8, ["disabled"]))
2284
- ], 64)) : unref(item).type === "dropdown" ? (openBlock(), createBlock(_component_el_dropdown, {
2285
- key: 4,
2389
+ ], 64)) : __props.data.type === "dropdown" ? (openBlock(), createBlock(_component_el_dropdown, {
2390
+ key: 3,
2286
2391
  trigger: "click",
2287
2392
  disabled: unref(disabled),
2288
2393
  onCommand: dropdownHandler
2289
2394
  }, {
2290
2395
  dropdown: withCtx(() => [
2291
- unref(item).items && unref(item).items.length ? (openBlock(), createBlock(_component_el_dropdown_menu, { key: 0 }, {
2396
+ __props.data.items && __props.data.items.length ? (openBlock(), createBlock(_component_el_dropdown_menu, { key: 0 }, {
2292
2397
  default: withCtx(() => [
2293
- (openBlock(true), createElementBlock(Fragment, null, renderList(unref(item).items, (subItem, index) => {
2398
+ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.data.items, (subItem, index) => {
2294
2399
  return openBlock(), createBlock(_component_el_dropdown_item, {
2295
2400
  key: index,
2296
- command: { item: unref(item), subItem }
2401
+ command: { data: __props.data, subItem }
2297
2402
  }, {
2298
2403
  default: withCtx(() => [
2299
2404
  createTextVNode(toDisplayString(subItem.text), 1)
@@ -2306,8 +2411,8 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2306
2411
  })) : createCommentVNode("", true)
2307
2412
  ]),
2308
2413
  default: withCtx(() => [
2309
- createElementVNode("span", _hoisted_3, [
2310
- createTextVNode(toDisplayString(unref(item).text), 1),
2414
+ createElementVNode("span", _hoisted_2$2, [
2415
+ createTextVNode(toDisplayString(__props.data.text), 1),
2311
2416
  createVNode(_component_el_icon, { class: "el-icon--right" }, {
2312
2417
  default: withCtx(() => [
2313
2418
  createVNode(unref(ArrowDown))
@@ -2317,67 +2422,187 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2317
2422
  ])
2318
2423
  ]),
2319
2424
  _: 1
2320
- }, 8, ["disabled"])) : unref(item).type === "component" ? (openBlock(), createBlock(resolveDynamicComponent(unref(item).component), normalizeProps(mergeProps({ key: 5 }, unref(item).props || {})), null, 16)) : createCommentVNode("", true)
2425
+ }, 8, ["disabled"])) : __props.data.type === "component" ? (openBlock(), createBlock(resolveDynamicComponent(__props.data.component), normalizeProps(mergeProps({ key: 4 }, __props.data.props || {})), null, 16)) : createCommentVNode("", true)
2321
2426
  ], 34)) : createCommentVNode("", true);
2322
2427
  };
2323
2428
  }
2324
2429
  });
2325
2430
 
2326
- const _sfc_main$e = defineComponent({
2327
- name: "nav-menu",
2328
- components: { ToolButton: _sfc_main$f },
2431
+ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2432
+ __name: "NavMenu",
2329
2433
  props: {
2330
- data: {
2331
- type: Object,
2332
- default: () => ({})
2333
- },
2334
- height: {
2335
- type: Number
2336
- }
2434
+ data: { default: () => ({}) },
2435
+ height: { default: 35 }
2337
2436
  },
2338
- setup(props) {
2437
+ setup(__props) {
2438
+ const props = __props;
2339
2439
  const services = inject("services");
2340
- return {
2341
- keys: computed(() => Object.keys(props.data)),
2342
- columnWidth: computed(() => services?.uiService.get("columnWidth"))
2440
+ const uiService = services?.uiService;
2441
+ const columnWidth = computed(() => services?.uiService.get("columnWidth"));
2442
+ const keys = Object.values(ColumnLayout);
2443
+ const showGuides = computed(() => uiService?.get("showGuides") ?? true);
2444
+ const showRule = computed(() => uiService?.get("showRule") ?? true);
2445
+ const zoom = computed(() => uiService?.get("zoom") ?? 1);
2446
+ const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
2447
+ const ctrl = isMac ? "Command" : "Ctrl";
2448
+ const getConfig = (item) => {
2449
+ if (typeof item !== "string") {
2450
+ return [item];
2451
+ }
2452
+ const config = [];
2453
+ switch (item) {
2454
+ case "/":
2455
+ config.push({
2456
+ type: "divider",
2457
+ className: "divider"
2458
+ });
2459
+ break;
2460
+ case "zoom":
2461
+ config.push(...getConfig("zoom-out"), ...getConfig(`${parseInt(`${zoom.value * 100}`, 10)}%`), ...getConfig("zoom-in"), ...getConfig("scale-to-original"), ...getConfig("scale-to-fit"));
2462
+ break;
2463
+ case "delete":
2464
+ config.push({
2465
+ type: "button",
2466
+ className: "delete",
2467
+ icon: markRaw(Delete),
2468
+ tooltip: `\u522A\u9664(Delete)`,
2469
+ disabled: () => services?.editorService.get("node")?.type === NodeType.PAGE,
2470
+ handler: () => services?.editorService.remove(services?.editorService.get("node"))
2471
+ });
2472
+ break;
2473
+ case "undo":
2474
+ config.push({
2475
+ type: "button",
2476
+ className: "undo",
2477
+ icon: markRaw(Back),
2478
+ tooltip: `\u540E\u9000(${ctrl}+z)`,
2479
+ disabled: () => !services?.historyService.state.canUndo,
2480
+ handler: () => services?.editorService.undo()
2481
+ });
2482
+ break;
2483
+ case "redo":
2484
+ config.push({
2485
+ type: "button",
2486
+ className: "redo",
2487
+ icon: markRaw(Right),
2488
+ tooltip: `\u524D\u8FDB(${ctrl}+Shift+z)`,
2489
+ disabled: () => !services?.historyService.state.canRedo,
2490
+ handler: () => services?.editorService.redo()
2491
+ });
2492
+ break;
2493
+ case "zoom-in":
2494
+ config.push({
2495
+ type: "button",
2496
+ className: "zoom-in",
2497
+ icon: markRaw(ZoomIn),
2498
+ tooltip: `\u653E\u5927(${ctrl}+=)`,
2499
+ handler: () => uiService?.zoom(0.1)
2500
+ });
2501
+ break;
2502
+ case "zoom-out":
2503
+ config.push({
2504
+ type: "button",
2505
+ className: "zoom-out",
2506
+ icon: markRaw(ZoomOut),
2507
+ tooltip: `\u7E2E\u5C0F(${ctrl}+-)`,
2508
+ handler: () => uiService?.zoom(-0.1)
2509
+ });
2510
+ break;
2511
+ case "scale-to-original":
2512
+ config.push({
2513
+ type: "button",
2514
+ className: "scale-to-original",
2515
+ icon: markRaw(ScaleToOriginal),
2516
+ tooltip: `\u7F29\u653E\u5230\u5B9E\u9645\u5927\u5C0F(${ctrl}+1)`,
2517
+ handler: () => uiService?.set("zoom", 1)
2518
+ });
2519
+ break;
2520
+ case "scale-to-fit":
2521
+ config.push({
2522
+ type: "button",
2523
+ className: "scale-to-fit",
2524
+ icon: markRaw(FullScreen),
2525
+ tooltip: `\u7F29\u653E\u4EE5\u9002\u5E94(${ctrl}+0)`,
2526
+ handler: () => uiService?.set("zoom", uiService.calcZoom())
2527
+ });
2528
+ break;
2529
+ case "rule":
2530
+ config.push({
2531
+ type: "button",
2532
+ className: "rule",
2533
+ icon: markRaw(Memo),
2534
+ tooltip: showRule.value ? "\u9690\u85CF\u6807\u5C3A" : "\u663E\u793A\u6807\u5C3A",
2535
+ handler: () => uiService?.set("showRule", !showRule.value)
2536
+ });
2537
+ break;
2538
+ case "guides":
2539
+ config.push({
2540
+ type: "button",
2541
+ className: "guides",
2542
+ icon: markRaw(Grid),
2543
+ tooltip: showGuides.value ? "\u9690\u85CF\u53C2\u8003\u7EBF" : "\u663E\u793A\u53C2\u8003\u7EBF",
2544
+ handler: () => uiService?.set("showGuides", !showGuides.value)
2545
+ });
2546
+ break;
2547
+ default:
2548
+ config.push({
2549
+ type: "text",
2550
+ text: item
2551
+ });
2552
+ }
2553
+ return config;
2343
2554
  };
2344
- }
2345
- });
2346
-
2347
- function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
2348
- const _component_tool_button = resolveComponent("tool-button");
2349
- return openBlock(), createElementBlock("div", {
2350
- class: "m-editor-nav-menu",
2351
- style: normalizeStyle({ height: `${_ctx.height}px` })
2352
- }, [
2353
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.keys, (key) => {
2555
+ const buttons = computed(() => {
2556
+ const data = {
2557
+ [ColumnLayout.LEFT]: [],
2558
+ [ColumnLayout.CENTER]: [],
2559
+ [ColumnLayout.RIGHT]: []
2560
+ };
2561
+ keys.forEach((key) => {
2562
+ const items = props.data[key] || [];
2563
+ items.forEach((item) => {
2564
+ data[key].push(...getConfig(item));
2565
+ });
2566
+ });
2567
+ return data;
2568
+ });
2569
+ return (_ctx, _cache) => {
2354
2570
  return openBlock(), createElementBlock("div", {
2355
- class: normalizeClass(`menu-${key}`),
2356
- key,
2357
- style: normalizeStyle(`width: ${_ctx.columnWidth?.[key]}px`)
2571
+ class: "m-editor-nav-menu",
2572
+ style: normalizeStyle({ height: `${__props.height}px` })
2358
2573
  }, [
2359
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.data[key], (item, index) => {
2360
- return openBlock(), createBlock(_component_tool_button, {
2361
- data: item,
2362
- key: index
2363
- }, null, 8, ["data"]);
2574
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(keys), (key) => {
2575
+ return openBlock(), createElementBlock("div", {
2576
+ class: normalizeClass(`menu-${key}`),
2577
+ key,
2578
+ style: normalizeStyle(`width: ${unref(columnWidth)?.[key]}px`)
2579
+ }, [
2580
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(buttons)[key], (item, index) => {
2581
+ return openBlock(), createBlock(_sfc_main$g, {
2582
+ data: item,
2583
+ key: index
2584
+ }, null, 8, ["data"]);
2585
+ }), 128))
2586
+ ], 6);
2364
2587
  }), 128))
2365
- ], 6);
2366
- }), 128))
2367
- ], 4);
2368
- }
2369
- const NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$9]]);
2588
+ ], 4);
2589
+ };
2590
+ }
2591
+ });
2370
2592
 
2371
- const _sfc_main$d = defineComponent({
2372
- name: "m-editor-props-panel",
2593
+ const _hoisted_1$4 = { class: "`m-editor-props-panel" };
2594
+ const _sfc_main$e = /* @__PURE__ */ defineComponent({
2595
+ __name: "PropsPanel",
2373
2596
  emits: ["mounted"],
2374
- setup(props, { emit }) {
2597
+ setup(__props, { expose, emit }) {
2375
2598
  const internalInstance = getCurrentInstance();
2376
2599
  const values = ref({});
2377
2600
  const configForm = ref();
2378
2601
  const curFormConfig = ref([]);
2379
2602
  const services = inject("services");
2380
2603
  const node = computed(() => services?.editorService.get("node"));
2604
+ const propsPanelSize = computed(() => services?.uiService.get("propsPanelSize") || "small");
2605
+ const stage = computed(() => services?.editorService.get("stage"));
2381
2606
  const init = async () => {
2382
2607
  if (!node.value) {
2383
2608
  curFormConfig.value = [];
@@ -2392,51 +2617,49 @@ const _sfc_main$d = defineComponent({
2392
2617
  onMounted(() => {
2393
2618
  emit("mounted", internalInstance);
2394
2619
  });
2395
- return {
2396
- values,
2397
- configForm,
2398
- curFormConfig,
2399
- propsPanelSize: computed(() => services?.uiService.get("propsPanelSize") || "small"),
2400
- async submit() {
2401
- try {
2402
- const values2 = await configForm.value?.submitForm();
2403
- services?.editorService.update(values2);
2404
- } catch (e) {
2405
- console.error(e);
2406
- ElMessage.closeAll();
2407
- ElMessage.error({
2408
- duration: 1e4,
2409
- showClose: true,
2410
- message: e.message,
2411
- dangerouslyUseHTMLString: true
2412
- });
2413
- }
2620
+ watchEffect(() => {
2621
+ if (configForm.value && stage.value) {
2622
+ configForm.value.formState.stage = stage.value;
2414
2623
  }
2624
+ });
2625
+ const submit = async () => {
2626
+ try {
2627
+ const values2 = await configForm.value?.submitForm();
2628
+ services?.editorService.update(values2);
2629
+ } catch (e) {
2630
+ console.error(e);
2631
+ ElMessage.closeAll();
2632
+ ElMessage.error({
2633
+ duration: 1e4,
2634
+ showClose: true,
2635
+ message: e.message,
2636
+ dangerouslyUseHTMLString: true
2637
+ });
2638
+ }
2639
+ };
2640
+ expose({ submit });
2641
+ return (_ctx, _cache) => {
2642
+ const _component_m_form = resolveComponent("m-form");
2643
+ return openBlock(), createElementBlock("div", _hoisted_1$4, [
2644
+ renderSlot(_ctx.$slots, "props-panel-header"),
2645
+ createVNode(_component_m_form, {
2646
+ ref_key: "configForm",
2647
+ ref: configForm,
2648
+ class: normalizeClass(`m-editor-props-panel ${unref(propsPanelSize)}`),
2649
+ "popper-class": `m-editor-props-panel-popper ${unref(propsPanelSize)}`,
2650
+ size: unref(propsPanelSize),
2651
+ "init-values": values.value,
2652
+ config: curFormConfig.value,
2653
+ onChange: submit
2654
+ }, null, 8, ["class", "popper-class", "size", "init-values", "config"])
2655
+ ]);
2415
2656
  };
2416
2657
  }
2417
2658
  });
2418
2659
 
2419
- const _hoisted_1$6 = { class: "`m-editor-props-panel" };
2420
- function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
2421
- const _component_m_form = resolveComponent("m-form");
2422
- return openBlock(), createElementBlock("div", _hoisted_1$6, [
2423
- renderSlot(_ctx.$slots, "props-panel-header"),
2424
- createVNode(_component_m_form, {
2425
- class: normalizeClass(`m-editor-props-panel ${_ctx.propsPanelSize}`),
2426
- "popper-class": `m-editor-props-panel-popper ${_ctx.propsPanelSize}`,
2427
- ref: "configForm",
2428
- size: _ctx.propsPanelSize,
2429
- "init-values": _ctx.values,
2430
- config: _ctx.curFormConfig,
2431
- onChange: _ctx.submit
2432
- }, null, 8, ["class", "popper-class", "size", "init-values", "config", "onChange"])
2433
- ]);
2434
- }
2435
- const PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$8]]);
2436
-
2437
- const _sfc_main$c = defineComponent({
2660
+ const _sfc_main$d = defineComponent({
2438
2661
  name: "ui-component-panel",
2439
- components: { MIcon },
2662
+ components: { MIcon: _sfc_main$h },
2440
2663
  setup() {
2441
2664
  const searchText = ref("");
2442
2665
  const services = inject("services");
@@ -2501,9 +2724,9 @@ const _sfc_main$c = defineComponent({
2501
2724
  }
2502
2725
  });
2503
2726
 
2504
- const _hoisted_1$5 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
2727
+ const _hoisted_1$3 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
2505
2728
  const _hoisted_2$1 = ["onClick", "onDragstart"];
2506
- function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2729
+ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2507
2730
  const _component_el_input = resolveComponent("el-input");
2508
2731
  const _component_m_icon = resolveComponent("m-icon");
2509
2732
  const _component_el_tooltip = resolveComponent("el-tooltip");
@@ -2534,7 +2757,7 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2534
2757
  name: index
2535
2758
  }, {
2536
2759
  title: withCtx(() => [
2537
- _hoisted_1$5,
2760
+ _hoisted_1$3,
2538
2761
  createTextVNode(toDisplayString(group.title), 1)
2539
2762
  ]),
2540
2763
  default: withCtx(() => [
@@ -2575,9 +2798,9 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2575
2798
  _: 3
2576
2799
  });
2577
2800
  }
2578
- const ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$7]]);
2801
+ const ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$5]]);
2579
2802
 
2580
- const _sfc_main$b = /* @__PURE__ */ defineComponent({
2803
+ const _sfc_main$c = /* @__PURE__ */ defineComponent({
2581
2804
  __name: "ContentMenu",
2582
2805
  props: {
2583
2806
  menuData: { default: () => [] },
@@ -2666,7 +2889,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
2666
2889
  }, [
2667
2890
  createElementVNode("div", null, [
2668
2891
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.menuData, (item, index) => {
2669
- return openBlock(), createBlock(_sfc_main$f, {
2892
+ return openBlock(), createBlock(_sfc_main$g, {
2670
2893
  "event-type": "mouseup",
2671
2894
  data: item,
2672
2895
  key: index,
@@ -2690,8 +2913,8 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
2690
2913
  }
2691
2914
  });
2692
2915
 
2693
- const _sfc_main$a = defineComponent({
2694
- components: { ContentMenu: _sfc_main$b },
2916
+ const _sfc_main$b = defineComponent({
2917
+ components: { ContentMenu: _sfc_main$c },
2695
2918
  setup() {
2696
2919
  const services = inject("services");
2697
2920
  const menu = ref();
@@ -2774,7 +2997,7 @@ const _sfc_main$a = defineComponent({
2774
2997
  }
2775
2998
  });
2776
2999
 
2777
- function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3000
+ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
2778
3001
  const _component_content_menu = resolveComponent("content-menu");
2779
3002
  return openBlock(), createBlock(_component_content_menu, {
2780
3003
  "menu-data": _ctx.menuData,
@@ -2782,7 +3005,7 @@ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
2782
3005
  style: { "overflow": "initial" }
2783
3006
  }, null, 8, ["menu-data"]);
2784
3007
  }
2785
- const LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$6]]);
3008
+ const LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$4]]);
2786
3009
 
2787
3010
  const throttleTime = 150;
2788
3011
  const select = async (data, editorService) => {
@@ -2833,20 +3056,38 @@ const useDrop = (tree, editorService) => ({
2833
3056
  }
2834
3057
  });
2835
3058
  const useStatus = (tree, editorService) => {
2836
- const highlightNode = ref();
2837
3059
  const node = ref();
2838
3060
  const page = computed(() => editorService?.get("page"));
3061
+ const expandedKeys = /* @__PURE__ */ new Map();
3062
+ const expandNodes = () => {
3063
+ expandedKeys.forEach((key) => {
3064
+ if (!tree.value)
3065
+ return;
3066
+ tree.value.getNode(key)?.expand();
3067
+ });
3068
+ };
2839
3069
  watchEffect(() => {
2840
3070
  if (!tree.value)
2841
3071
  return;
2842
- node.value = editorService?.get("node");
2843
- node.value && tree.value.setCurrentKey(node.value.id, true);
2844
- const parent = editorService?.get("parent");
3072
+ if (!editorService)
3073
+ return;
3074
+ node.value = editorService.get("node");
3075
+ if (!node.value)
3076
+ return;
3077
+ tree.value.setCurrentKey(node.value.id, true);
3078
+ const parent = editorService.get("parent");
2845
3079
  if (!parent?.id)
2846
3080
  return;
2847
3081
  const treeNode = tree.value.getNode(parent.id);
2848
3082
  treeNode?.updateChildren();
2849
- highlightNode.value = editorService?.get("highlightNode");
3083
+ setTimeout(() => {
3084
+ tree.value && Object.entries(tree.value.store.nodesMap).forEach(([id, node2]) => {
3085
+ if (node2.expanded && node2.data.items) {
3086
+ expandedKeys.set(id, id);
3087
+ }
3088
+ });
3089
+ expandNodes();
3090
+ });
2850
3091
  });
2851
3092
  return {
2852
3093
  values: computed(() => page.value ? [page.value] : []),
@@ -2859,9 +3100,18 @@ const useStatus = (tree, editorService) => {
2859
3100
  }
2860
3101
  resolve([]);
2861
3102
  },
2862
- highlightNode,
3103
+ highlightNode: computed(() => editorService?.get("highlightNode")),
2863
3104
  clickNode: node,
2864
- expandedKeys: computed(() => node.value ? [node.value.id] : [])
3105
+ expandedKeys: computed(() => node.value ? [node.value.id] : []),
3106
+ handleCollapse: (data) => {
3107
+ expandedKeys.delete(data.id);
3108
+ },
3109
+ handleExpand: (data) => {
3110
+ const parent = editorService?.getParentById(data.id);
3111
+ if (!parent?.id)
3112
+ return;
3113
+ expandedKeys.set(parent.id, parent.id);
3114
+ }
2865
3115
  };
2866
3116
  };
2867
3117
  const useFilter = (tree) => ({
@@ -2882,7 +3132,7 @@ const useFilter = (tree) => ({
2882
3132
  tree.value?.filter(val);
2883
3133
  }
2884
3134
  });
2885
- const _sfc_main$9 = defineComponent({
3135
+ const _sfc_main$a = defineComponent({
2886
3136
  name: "magic-editor-layer-panel",
2887
3137
  components: { LayerMenu },
2888
3138
  setup() {
@@ -2930,8 +3180,8 @@ const _sfc_main$9 = defineComponent({
2930
3180
  }
2931
3181
  });
2932
3182
 
2933
- const _hoisted_1$4 = ["id", "onMouseenter"];
2934
- function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3183
+ const _hoisted_1$2 = ["id", "onMouseenter"];
3184
+ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
2935
3185
  const _component_el_input = resolveComponent("el-input");
2936
3186
  const _component_el_tree = resolveComponent("el-tree");
2937
3187
  const _component_layer_menu = resolveComponent("layer-menu");
@@ -2952,6 +3202,7 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2952
3202
  key: 0,
2953
3203
  ref: "tree",
2954
3204
  "node-key": "id",
3205
+ "empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684",
2955
3206
  draggable: "",
2956
3207
  "default-expanded-keys": _ctx.expandedKeys,
2957
3208
  load: _ctx.loadItems,
@@ -2966,7 +3217,8 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2966
3217
  onNodeClick: _ctx.clickHandler,
2967
3218
  onNodeContextmenu: _ctx.contextmenu,
2968
3219
  onNodeDragEnd: _ctx.handleDragEnd,
2969
- "empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684"
3220
+ onNodeCollapse: _ctx.handleCollapse,
3221
+ onNodeExpand: _ctx.handleExpand
2970
3222
  }, {
2971
3223
  default: withCtx(({ node, data }) => [
2972
3224
  createElementVNode("div", {
@@ -2982,10 +3234,10 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2982
3234
  }, () => [
2983
3235
  createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
2984
3236
  ])
2985
- ], 42, _hoisted_1$4)
3237
+ ], 42, _hoisted_1$2)
2986
3238
  ]),
2987
3239
  _: 3
2988
- }, 8, ["default-expanded-keys", "load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd"])) : createCommentVNode("", true),
3240
+ }, 8, ["default-expanded-keys", "load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd", "onNodeCollapse", "onNodeExpand"])) : createCommentVNode("", true),
2989
3241
  (openBlock(), createBlock(Teleport, { to: "body" }, [
2990
3242
  createVNode(_component_layer_menu, { ref: "menu" }, null, 512)
2991
3243
  ]))
@@ -2993,10 +3245,10 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2993
3245
  _: 3
2994
3246
  });
2995
3247
  }
2996
- const LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$5]]);
3248
+ const LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$3]]);
2997
3249
 
2998
- const _sfc_main$8 = defineComponent({
2999
- components: { MIcon },
3250
+ const _sfc_main$9 = defineComponent({
3251
+ components: { MIcon: _sfc_main$h },
3000
3252
  props: {
3001
3253
  data: {
3002
3254
  type: [Object, String]
@@ -3033,11 +3285,11 @@ const _sfc_main$8 = defineComponent({
3033
3285
  }
3034
3286
  });
3035
3287
 
3036
- const _hoisted_1$3 = {
3288
+ const _hoisted_1$1 = {
3037
3289
  key: 1,
3038
3290
  class: "magic-editor-tab-panel-title"
3039
3291
  };
3040
- function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3292
+ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3041
3293
  const _component_m_icon = resolveComponent("m-icon");
3042
3294
  const _component_el_tab_pane = resolveComponent("el-tab-pane");
3043
3295
  return _ctx.config ? (openBlock(), createBlock(_component_el_tab_pane, {
@@ -3052,7 +3304,7 @@ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3052
3304
  key: 0,
3053
3305
  icon: _ctx.config.icon
3054
3306
  }, null, 8, ["icon"])) : createCommentVNode("", true),
3055
- _ctx.config.text ? (openBlock(), createElementBlock("div", _hoisted_1$3, toDisplayString(_ctx.config.text), 1)) : createCommentVNode("", true)
3307
+ _ctx.config.text ? (openBlock(), createElementBlock("div", _hoisted_1$1, toDisplayString(_ctx.config.text), 1)) : createCommentVNode("", true)
3056
3308
  ]))
3057
3309
  ]),
3058
3310
  default: withCtx(() => [
@@ -3083,9 +3335,9 @@ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3083
3335
  _: 3
3084
3336
  }, 8, ["name"])) : createCommentVNode("", true);
3085
3337
  }
3086
- const TabPane = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$4]]);
3338
+ const TabPane = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$2]]);
3087
3339
 
3088
- const _sfc_main$7 = defineComponent({
3340
+ const _sfc_main$8 = defineComponent({
3089
3341
  components: { TabPane },
3090
3342
  name: "m-sidebar",
3091
3343
  props: {
@@ -3105,7 +3357,7 @@ const _sfc_main$7 = defineComponent({
3105
3357
  }
3106
3358
  });
3107
3359
 
3108
- function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3360
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
3109
3361
  const _component_tab_pane = resolveComponent("tab-pane");
3110
3362
  const _component_el_tabs = resolveComponent("el-tabs");
3111
3363
  return _ctx.data.type === "tabs" && _ctx.data.items.length ? (openBlock(), createBlock(_component_el_tabs, {
@@ -3140,9 +3392,9 @@ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3140
3392
  _: 3
3141
3393
  }, 8, ["modelValue"])) : createCommentVNode("", true);
3142
3394
  }
3143
- const Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$3]]);
3395
+ const Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$1]]);
3144
3396
 
3145
- const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3397
+ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3146
3398
  __name: "PageBarScrollContainer",
3147
3399
  setup(__props) {
3148
3400
  const services = inject("services");
@@ -3269,9 +3521,9 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3269
3521
  }
3270
3522
  });
3271
3523
 
3272
- const _hoisted_1$2 = ["onClick"];
3524
+ const _hoisted_1 = ["onClick"];
3273
3525
  const _hoisted_2 = { class: "m-editor-page-bar-title" };
3274
- const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3526
+ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3275
3527
  __name: "PageBar",
3276
3528
  setup(__props) {
3277
3529
  const services = inject("services");
@@ -3295,7 +3547,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3295
3547
  const _component_el_tooltip = resolveComponent("el-tooltip");
3296
3548
  const _component_el_icon = resolveComponent("el-icon");
3297
3549
  const _component_el_popover = resolveComponent("el-popover");
3298
- return openBlock(), createBlock(_sfc_main$6, null, {
3550
+ return openBlock(), createBlock(_sfc_main$7, null, {
3299
3551
  default: withCtx(() => [
3300
3552
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(root) && unref(root).items || [], (item) => {
3301
3553
  return openBlock(), createElementBlock("div", {
@@ -3311,7 +3563,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3311
3563
  content: item.name
3312
3564
  }, {
3313
3565
  default: withCtx(() => [
3314
- createElementVNode("span", null, toDisplayString(item.name), 1)
3566
+ createElementVNode("span", null, toDisplayString(item.name || item.id), 1)
3315
3567
  ]),
3316
3568
  _: 2
3317
3569
  }, 1032, ["content"])
@@ -3334,7 +3586,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3334
3586
  default: withCtx(() => [
3335
3587
  createElementVNode("div", null, [
3336
3588
  renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3337
- createVNode(_sfc_main$f, {
3589
+ createVNode(_sfc_main$g, {
3338
3590
  data: {
3339
3591
  type: "button",
3340
3592
  text: "\u590D\u5236",
@@ -3342,7 +3594,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3342
3594
  handler: () => copy(item)
3343
3595
  }
3344
3596
  }, null, 8, ["data"]),
3345
- createVNode(_sfc_main$f, {
3597
+ createVNode(_sfc_main$g, {
3346
3598
  data: {
3347
3599
  type: "button",
3348
3600
  text: "\u5220\u9664",
@@ -3355,7 +3607,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3355
3607
  ]),
3356
3608
  _: 2
3357
3609
  }, 1024)
3358
- ], 10, _hoisted_1$2);
3610
+ ], 10, _hoisted_1);
3359
3611
  }), 128))
3360
3612
  ]),
3361
3613
  _: 3
@@ -3364,190 +3616,245 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3364
3616
  }
3365
3617
  });
3366
3618
 
3367
- class ScrollViewer$1 {
3368
- enter = false;
3369
- targetEnter = false;
3370
- keydown = false;
3619
+ class ScrollViewer extends EventEmitter {
3371
3620
  container;
3372
3621
  target;
3373
3622
  zoom = 1;
3374
3623
  scrollLeft = 0;
3375
3624
  scrollTop = 0;
3376
- x = 0;
3377
- y = 0;
3378
- resizeObserver = new ResizeObserver((entries) => {
3379
- for (const { contentRect } of entries) {
3380
- const { width, height } = contentRect;
3381
- const targetRect = this.target.getBoundingClientRect();
3382
- const targetWidth = targetRect.width * this.zoom;
3383
- const targetMarginTop = Number(this.target.style.marginTop) || 0;
3384
- const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3385
- if (targetWidth < width) {
3386
- this.target._left = 0;
3387
- }
3388
- if (targetHeight < height) {
3389
- this.target._top = 0;
3390
- }
3391
- this.scroll();
3392
- }
3625
+ scrollHeight = 0;
3626
+ scrollWidth = 0;
3627
+ width = 0;
3628
+ height = 0;
3629
+ translateXCorrectionValue = 0;
3630
+ translateYCorrectionValue = 0;
3631
+ resizeObserver = new ResizeObserver(() => {
3632
+ this.setSize();
3633
+ this.setScrollSize();
3393
3634
  });
3394
3635
  constructor(options) {
3636
+ super();
3395
3637
  this.container = options.container;
3396
3638
  this.target = options.target;
3397
3639
  this.zoom = options.zoom;
3398
- globalThis.addEventListener("keydown", this.keydownHandler);
3399
- globalThis.addEventListener("keyup", this.keyupHandler);
3400
- this.container.addEventListener("mouseenter", this.mouseEnterHandler);
3401
- this.container.addEventListener("mouseleave", this.mouseLeaveHandler);
3402
- this.target.addEventListener("mouseenter", this.targetMouseEnterHandler);
3403
- this.target.addEventListener("mouseleave", this.targetMouseLeaveHandler);
3404
- this.container.addEventListener("wheel", this.wheelHandler);
3640
+ this.container.addEventListener("wheel", this.wheelHandler, false);
3641
+ this.setSize();
3642
+ this.setScrollSize();
3405
3643
  this.resizeObserver.observe(this.container);
3406
3644
  }
3407
3645
  destroy() {
3408
3646
  this.resizeObserver.disconnect();
3409
- this.container.removeEventListener("mouseenter", this.mouseEnterHandler);
3410
- this.container.removeEventListener("mouseleave", this.mouseLeaveHandler);
3411
- this.target.removeEventListener("mouseenter", this.targetMouseEnterHandler);
3412
- this.target.removeEventListener("mouseleave", this.targetMouseLeaveHandler);
3413
- globalThis.removeEventListener("keydown", this.keydownHandler);
3414
- globalThis.removeEventListener("keyup", this.keyupHandler);
3647
+ this.container.removeEventListener("wheel", this.wheelHandler, false);
3648
+ this.removeAllListeners();
3415
3649
  }
3416
3650
  setZoom(zoom) {
3417
3651
  this.zoom = zoom;
3652
+ this.setScrollSize();
3418
3653
  }
3419
- scroll() {
3420
- const scrollLeft = this.target._left;
3421
- const scrollTop = this.target._top;
3422
- this.target.style.transform = `translate(${scrollLeft}px, ${scrollTop}px)`;
3423
- }
3424
- removeHandler() {
3425
- this.target.style.cursor = "";
3426
- this.target.removeEventListener("mousedown", this.mousedownHandler);
3427
- document.removeEventListener("mousemove", this.mousemoveHandler);
3428
- document.removeEventListener("mouseup", this.mouseupHandler);
3654
+ scrollTo({ left, top }) {
3655
+ if (typeof left !== "undefined") {
3656
+ this.scrollLeft = left;
3657
+ }
3658
+ if (typeof top !== "undefined") {
3659
+ this.scrollTop = top;
3660
+ }
3661
+ const translateX = -this.scrollLeft + this.translateXCorrectionValue;
3662
+ const translateY = -this.scrollTop + this.translateYCorrectionValue;
3663
+ this.target.style.transform = `translate(${translateX}px, ${translateY}px)`;
3429
3664
  }
3430
3665
  wheelHandler = (event) => {
3431
- if (this.targetEnter)
3432
- return;
3433
3666
  const { deltaX, deltaY, currentTarget } = event;
3434
3667
  if (currentTarget !== this.container)
3435
3668
  return;
3436
- this.setScrollOffset(deltaX, deltaY);
3437
- this.scroll();
3438
- this.scrollLeft = this.target._left;
3439
- this.scrollTop = this.target._top;
3440
- };
3441
- mouseEnterHandler = () => {
3442
- this.enter = true;
3443
- };
3444
- mouseLeaveHandler = () => {
3445
- this.enter = false;
3446
- };
3447
- targetMouseEnterHandler = () => {
3448
- this.targetEnter = true;
3449
- };
3450
- targetMouseLeaveHandler = () => {
3451
- this.targetEnter = false;
3452
- };
3453
- mousedownHandler = (event) => {
3454
- if (!this.keydown)
3455
- return;
3456
- event.stopImmediatePropagation();
3457
- event.stopPropagation();
3458
- this.target.style.cursor = "grabbing";
3459
- this.x = event.clientX;
3460
- this.y = event.clientY;
3461
- document.addEventListener("mousemove", this.mousemoveHandler);
3462
- document.addEventListener("mouseup", this.mouseupHandler);
3463
- };
3464
- mouseupHandler = () => {
3465
- this.x = 0;
3466
- this.y = 0;
3467
- this.scrollLeft = this.target._left;
3468
- this.scrollTop = this.target._top;
3469
- this.removeHandler();
3470
- };
3471
- mousemoveHandler = (event) => {
3472
- event.stopImmediatePropagation();
3473
- event.stopPropagation();
3474
- const deltaX = event.clientX - this.x;
3475
- const deltaY = event.clientY - this.y;
3476
- this.setScrollOffset(deltaX, deltaY);
3477
- this.scroll();
3669
+ let top;
3670
+ if (this.scrollHeight > this.height) {
3671
+ top = this.scrollTop + this.getPos(deltaY, this.scrollTop, this.scrollHeight, this.height);
3672
+ }
3673
+ let left;
3674
+ if (this.scrollWidth > this.width) {
3675
+ left = this.scrollLeft + this.getPos(deltaX, this.scrollLeft, this.scrollWidth, this.width);
3676
+ }
3677
+ this.scrollTo({ left, top });
3678
+ this.emit("scroll", {
3679
+ scrollLeft: this.scrollLeft,
3680
+ scrollTop: this.scrollTop,
3681
+ scrollHeight: this.scrollHeight,
3682
+ scrollWidth: this.scrollWidth
3683
+ });
3478
3684
  };
3479
- keydownHandler = (event) => {
3480
- if (event.code === Keys.ESCAPE && this.enter) {
3481
- event.preventDefault();
3482
- event.stopImmediatePropagation();
3483
- event.stopPropagation();
3685
+ getPos(delta, scrollPos, scrollSize, size) {
3686
+ let pos = 0;
3687
+ if (delta < 0) {
3688
+ if (scrollPos > 0) {
3689
+ pos = Math.max(delta, -scrollPos);
3690
+ }
3691
+ } else {
3692
+ const leftPos = scrollSize - size - scrollPos;
3693
+ if (leftPos > 0) {
3694
+ pos = Math.min(delta, leftPos);
3695
+ }
3484
3696
  }
3485
- if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3486
- return;
3697
+ return pos;
3698
+ }
3699
+ setScrollSize = () => {
3700
+ const targetRect = this.target.getBoundingClientRect();
3701
+ this.scrollWidth = targetRect.width * this.zoom + 100;
3702
+ const targetMarginTop = Number(this.target.style.marginTop) || 0;
3703
+ this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + 100;
3704
+ let left;
3705
+ let top;
3706
+ if (this.scrollWidth < this.width) {
3707
+ left = 0;
3708
+ this.translateXCorrectionValue = 0;
3709
+ } else {
3710
+ this.translateXCorrectionValue = (this.scrollWidth - this.width) / 2;
3487
3711
  }
3488
- this.keydown = true;
3489
- this.target.style.cursor = "grab";
3490
- this.container.addEventListener("mousedown", this.mousedownHandler);
3491
- };
3492
- keyupHandler = (event) => {
3493
- if (event.code !== Keys.ESCAPE || !this.keydown) {
3494
- return;
3712
+ if (this.scrollHeight < this.height) {
3713
+ top = 0;
3714
+ this.translateYCorrectionValue = 0;
3715
+ } else {
3716
+ this.translateYCorrectionValue = (this.scrollHeight - this.height) / 2;
3495
3717
  }
3496
- event.preventDefault();
3497
- event.stopImmediatePropagation();
3498
- event.stopPropagation();
3499
- this.keydown = false;
3500
- event.preventDefault();
3501
- this.removeHandler();
3718
+ this.scrollTo({
3719
+ left,
3720
+ top
3721
+ });
3722
+ this.emit("scroll", {
3723
+ scrollLeft: this.scrollLeft,
3724
+ scrollTop: this.scrollTop,
3725
+ scrollHeight: this.scrollHeight,
3726
+ scrollWidth: this.scrollWidth
3727
+ });
3502
3728
  };
3503
- setScrollOffset(deltaX, deltaY) {
3729
+ setSize = () => {
3504
3730
  const { width, height } = this.container.getBoundingClientRect();
3505
- const targetRect = this.target.getBoundingClientRect();
3506
- const targetWidth = targetRect.width * this.zoom;
3507
- const targetHeight = targetRect.height * this.zoom;
3508
- let y = 0;
3509
- if (targetHeight > height) {
3510
- if (deltaY > 0) {
3511
- y = this.scrollTop + Math.min(targetHeight - height - this.scrollTop, deltaY);
3512
- } else {
3513
- y = this.scrollTop + Math.max(-(targetHeight - height + this.scrollTop), deltaY);
3731
+ this.width = width;
3732
+ this.height = height;
3733
+ };
3734
+ }
3735
+
3736
+ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3737
+ __name: "ScrollBar",
3738
+ props: {
3739
+ size: null,
3740
+ scrollSize: null,
3741
+ isHorizontal: { type: Boolean },
3742
+ pos: null
3743
+ },
3744
+ emits: ["scroll"],
3745
+ setup(__props, { emit }) {
3746
+ const props = __props;
3747
+ const bar = ref();
3748
+ const thumb = ref();
3749
+ const thumbSize = computed(() => props.size * (props.size / props.scrollSize));
3750
+ const thumbPos = computed(() => props.pos / props.scrollSize * props.size);
3751
+ const thumbStyle = computed(() => ({
3752
+ [props.isHorizontal ? "width" : "height"]: `${thumbSize.value}px`,
3753
+ transform: `translate${props.isHorizontal ? "X" : "Y"}(${thumbPos.value}px)`
3754
+ }));
3755
+ let gesto;
3756
+ onMounted(() => {
3757
+ if (!thumb.value)
3758
+ return;
3759
+ const thumbEl = thumb.value;
3760
+ gesto = new Gesto(thumbEl, {
3761
+ container: window
3762
+ });
3763
+ gesto.on("dragStart", (e) => {
3764
+ e.inputEvent.stopPropagation();
3765
+ e.inputEvent.preventDefault();
3766
+ }).on("drag", (e) => {
3767
+ scrollBy(getDelta(e));
3768
+ });
3769
+ bar.value?.addEventListener("wheel", wheelHandler, false);
3770
+ });
3771
+ onUnmounted(() => {
3772
+ if (gesto)
3773
+ gesto.off();
3774
+ bar.value?.removeEventListener("wheel", wheelHandler, false);
3775
+ });
3776
+ const wheelHandler = (e) => {
3777
+ const delta = props.isHorizontal ? e.deltaX : e.deltaY;
3778
+ if (delta) {
3779
+ e.preventDefault();
3514
3780
  }
3515
- }
3516
- let x = 0;
3517
- if (targetWidth > width) {
3518
- if (deltaX > 0) {
3519
- x = this.scrollLeft + Math.min(targetWidth - width - this.scrollLeft, deltaX);
3781
+ scrollBy(delta);
3782
+ };
3783
+ const getDelta = (e) => {
3784
+ const ratio = (props.isHorizontal ? e.deltaX : e.deltaY) / props.size;
3785
+ return props.scrollSize * ratio;
3786
+ };
3787
+ const scrollBy = (delta) => {
3788
+ if (delta < 0) {
3789
+ if (props.pos <= 0) {
3790
+ emit("scroll", 0);
3791
+ } else {
3792
+ emit("scroll", -Math.min(-delta, props.pos));
3793
+ }
3520
3794
  } else {
3521
- x = this.scrollLeft + Math.max(-(targetWidth - width + this.scrollLeft), deltaX);
3795
+ const leftPos = props.size - (thumbSize.value + thumbPos.value);
3796
+ if (leftPos <= 0) {
3797
+ emit("scroll", 0);
3798
+ } else {
3799
+ emit("scroll", Math.min(delta, leftPos));
3800
+ }
3522
3801
  }
3523
- }
3524
- this.target._left = x;
3525
- this.target._top = y;
3802
+ };
3803
+ return (_ctx, _cache) => {
3804
+ return openBlock(), createElementBlock("div", {
3805
+ ref_key: "bar",
3806
+ ref: bar,
3807
+ class: normalizeClass(["m-editor-scroll-bar", __props.isHorizontal ? "horizontal" : "vertical"])
3808
+ }, [
3809
+ createElementVNode("div", {
3810
+ ref_key: "thumb",
3811
+ ref: thumb,
3812
+ class: "m-editor-scroll-bar-thumb",
3813
+ style: normalizeStyle(unref(thumbStyle))
3814
+ }, null, 4)
3815
+ ], 2);
3816
+ };
3526
3817
  }
3527
- }
3818
+ });
3528
3819
 
3529
- const _sfc_main$4 = defineComponent({
3530
- name: "m-editor-scroll-viewer",
3820
+ const ScrollBar_vue_vue_type_style_index_0_lang = '';
3821
+
3822
+ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
3823
+ __name: "ScrollViewer",
3531
3824
  props: {
3532
- width: Number,
3533
- height: Number,
3534
- zoom: {
3535
- type: Number,
3536
- default: 1
3537
- }
3825
+ width: { default: 0 },
3826
+ height: { default: 0 },
3827
+ wrapWidth: { default: 0 },
3828
+ wrapHeight: { default: 0 },
3829
+ zoom: { default: 1 }
3538
3830
  },
3539
- setup(props) {
3831
+ setup(__props, { expose }) {
3832
+ const props = __props;
3540
3833
  const container = ref();
3541
3834
  const el = ref();
3835
+ const style = computed(() => `
3836
+ width: ${props.width}px;
3837
+ height: ${props.height}px;
3838
+ position: absolute;
3839
+ margin-top: 30px;
3840
+ `);
3841
+ const scrollWidth = ref(0);
3842
+ const scrollHeight = ref(0);
3542
3843
  let scrollViewer;
3543
3844
  onMounted(() => {
3544
3845
  if (!container.value || !el.value)
3545
3846
  return;
3546
- scrollViewer = new ScrollViewer$1({
3847
+ scrollViewer = new ScrollViewer({
3547
3848
  container: container.value,
3548
3849
  target: el.value,
3549
3850
  zoom: props.zoom
3550
3851
  });
3852
+ scrollViewer.on("scroll", (data) => {
3853
+ hOffset.value = data.scrollLeft;
3854
+ vOffset.value = data.scrollTop;
3855
+ scrollWidth.value = data.scrollWidth;
3856
+ scrollHeight.value = data.scrollHeight;
3857
+ });
3551
3858
  });
3552
3859
  onUnmounted(() => {
3553
3860
  scrollViewer.destroy();
@@ -3555,35 +3862,56 @@ const _sfc_main$4 = defineComponent({
3555
3862
  watch(() => props.zoom, () => {
3556
3863
  scrollViewer.setZoom(props.zoom);
3557
3864
  });
3558
- return {
3559
- container,
3560
- el,
3561
- style: computed(() => `
3562
- width: ${props.width}px;
3563
- height: ${props.height}px;
3564
- position: absolute;
3565
- margin-top: 30px;
3566
- `)
3865
+ const vOffset = ref(0);
3866
+ const vScrollHandler = (delta) => {
3867
+ vOffset.value += delta;
3868
+ scrollViewer.scrollTo({
3869
+ top: vOffset.value
3870
+ });
3871
+ };
3872
+ const hOffset = ref(0);
3873
+ const hScrollHandler = (delta) => {
3874
+ hOffset.value += delta;
3875
+ scrollViewer.scrollTo({
3876
+ left: hOffset.value
3877
+ });
3878
+ };
3879
+ expose({
3880
+ container
3881
+ });
3882
+ return (_ctx, _cache) => {
3883
+ return openBlock(), createElementBlock("div", {
3884
+ class: "m-editor-scroll-viewer-container",
3885
+ ref_key: "container",
3886
+ ref: container
3887
+ }, [
3888
+ createElementVNode("div", {
3889
+ ref_key: "el",
3890
+ ref: el,
3891
+ style: normalizeStyle(unref(style))
3892
+ }, [
3893
+ renderSlot(_ctx.$slots, "default")
3894
+ ], 4),
3895
+ scrollHeight.value > __props.wrapHeight ? (openBlock(), createBlock(_sfc_main$5, {
3896
+ key: 0,
3897
+ "scroll-size": scrollHeight.value,
3898
+ size: __props.wrapHeight,
3899
+ pos: vOffset.value,
3900
+ onScroll: vScrollHandler
3901
+ }, null, 8, ["scroll-size", "size", "pos"])) : createCommentVNode("", true),
3902
+ scrollWidth.value > __props.wrapWidth ? (openBlock(), createBlock(_sfc_main$5, {
3903
+ key: 1,
3904
+ "is-horizontal": true,
3905
+ "scroll-size": scrollWidth.value,
3906
+ pos: hOffset.value,
3907
+ size: __props.wrapWidth,
3908
+ onScroll: hScrollHandler
3909
+ }, null, 8, ["scroll-size", "pos", "size"])) : createCommentVNode("", true)
3910
+ ], 512);
3567
3911
  };
3568
3912
  }
3569
3913
  });
3570
3914
 
3571
- const _hoisted_1$1 = {
3572
- class: "m-editor-scroll-viewer-container",
3573
- ref: "container"
3574
- };
3575
- function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3576
- return openBlock(), createElementBlock("div", _hoisted_1$1, [
3577
- createElementVNode("div", {
3578
- ref: "el",
3579
- style: normalizeStyle(_ctx.style)
3580
- }, [
3581
- renderSlot(_ctx.$slots, "default")
3582
- ], 4)
3583
- ], 512);
3584
- }
3585
- const ScrollViewer = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$2]]);
3586
-
3587
3915
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
3588
3916
  __name: "ViewerMenu",
3589
3917
  props: {
@@ -3605,11 +3933,11 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
3605
3933
  {
3606
3934
  type: "button",
3607
3935
  text: "\u6C34\u5E73\u5C45\u4E2D",
3608
- display: () => canCenter.value && !props.isMultiSelect,
3936
+ display: () => canCenter.value,
3609
3937
  handler: () => {
3610
- if (!node.value)
3938
+ if (!nodes.value)
3611
3939
  return;
3612
- editorService?.alignCenter(node.value);
3940
+ editorService?.alignCenter(nodes.value);
3613
3941
  }
3614
3942
  },
3615
3943
  {
@@ -3705,10 +4033,6 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
3705
4033
  },
3706
4034
  ...stageContentMenu
3707
4035
  ]);
3708
- onMounted(async () => {
3709
- const data = await storageService.getItem(COPY_STORAGE_KEY);
3710
- canPaste.value = data !== "undefined" && !!data;
3711
- });
3712
4036
  watch(parent, async () => {
3713
4037
  if (!parent.value || !editorService)
3714
4038
  return canCenter.value = false;
@@ -3717,12 +4041,14 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
3717
4041
  const isTypeConform = nodes.value?.every((selectedNode) => ![NodeType.ROOT, NodeType.PAGE, "pop"].includes(`${selectedNode?.type}`));
3718
4042
  canCenter.value = isLayoutConform && !!isTypeConform;
3719
4043
  }, { immediate: true });
3720
- const show = (e) => {
4044
+ const show = async (e) => {
3721
4045
  menu.value?.show(e);
4046
+ const data = await storageService.getItem(COPY_STORAGE_KEY);
4047
+ canPaste.value = data !== "undefined" && !!data;
3722
4048
  };
3723
4049
  expose({ show });
3724
4050
  return (_ctx, _cache) => {
3725
- return openBlock(), createBlock(_sfc_main$b, {
4051
+ return openBlock(), createBlock(_sfc_main$c, {
3726
4052
  "menu-data": menuData,
3727
4053
  ref_key: "menu",
3728
4054
  ref: menu
@@ -3743,12 +4069,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3743
4069
  const menu = ref();
3744
4070
  const isMultiSelect = computed(() => services?.editorService.get("nodes")?.length > 1);
3745
4071
  const stageRect = computed(() => services?.uiService.get("stageRect"));
3746
- const uiSelectMode = computed(() => services?.uiService.get("uiSelectMode"));
4072
+ const stageContainerRect = computed(() => services?.uiService.get("stageContainerRect"));
3747
4073
  const root = computed(() => services?.editorService.get("root"));
3748
4074
  const page = computed(() => services?.editorService.get("page"));
3749
4075
  const zoom = computed(() => services?.uiService.get("zoom") || 1);
3750
4076
  const node = computed(() => services?.editorService.get("node"));
3751
- const getGuideLineKey = (key) => `${key}_${root.value?.id}_${page.value?.id}`;
3752
4077
  watchEffect(() => {
3753
4078
  if (stage)
3754
4079
  return;
@@ -3756,61 +4081,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3756
4081
  return;
3757
4082
  if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value)
3758
4083
  return;
3759
- stage = new StageCore({
3760
- render: stageOptions.render,
3761
- runtimeUrl: stageOptions.runtimeUrl,
3762
- zoom: zoom.value,
3763
- autoScrollIntoView: stageOptions.autoScrollIntoView,
3764
- isContainer: stageOptions.isContainer,
3765
- containerHighlightClassName: stageOptions.containerHighlightClassName,
3766
- containerHighlightDuration: stageOptions.containerHighlightDuration,
3767
- canSelect: (el, event, stop) => {
3768
- const elCanSelect = stageOptions.canSelect(el);
3769
- if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
3770
- document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
3771
- return stop();
3772
- }
3773
- return elCanSelect;
3774
- },
3775
- moveableOptions: stageOptions.moveableOptions,
3776
- updateDragEl: stageOptions.updateDragEl
3777
- });
4084
+ stage = useStage(stageOptions);
3778
4085
  services?.editorService.set("stage", markRaw(stage));
3779
4086
  stage?.mount(stageContainer.value);
3780
- stage.mask.setGuides([
3781
- getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
3782
- getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
3783
- ]);
3784
- stage?.on("select", (el) => {
3785
- services?.editorService.select(el.id);
3786
- });
3787
- stage?.on("highlight", (el) => {
3788
- services?.editorService.highlight(el.id);
3789
- });
3790
- stage?.on("multiSelect", (els) => {
3791
- services?.editorService.multiSelect(els.map((el) => el.id));
3792
- });
3793
- stage?.on("update", (ev) => {
3794
- if (ev.parentEl) {
3795
- services?.editorService.moveToContainer({ id: ev.el.id, style: ev.style }, ev.parentEl.id);
3796
- return;
3797
- }
3798
- services?.editorService.update({ id: ev.el.id, style: ev.style });
3799
- });
3800
- stage?.on("sort", (ev) => {
3801
- services?.editorService.sort(ev.src, ev.dist);
3802
- });
3803
- stage?.on("changeGuides", (e2) => {
3804
- services?.uiService.set("showGuides", true);
3805
- if (!root.value || !page.value)
3806
- return;
3807
- const storageKey = getGuideLineKey(e2.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY);
3808
- if (e2.guides.length) {
3809
- globalThis.localStorage.setItem(storageKey, JSON.stringify(e2.guides));
3810
- } else {
3811
- globalThis.localStorage.removeItem(storageKey);
3812
- }
3813
- });
3814
4087
  if (!node.value?.id)
3815
4088
  return;
3816
4089
  stage?.on("runtime-ready", (rt) => {
@@ -3896,12 +4169,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3896
4169
  }
3897
4170
  };
3898
4171
  return (_ctx, _cache) => {
3899
- return openBlock(), createBlock(ScrollViewer, {
4172
+ return openBlock(), createBlock(_sfc_main$4, {
3900
4173
  class: "m-editor-stage",
3901
4174
  ref_key: "stageWrap",
3902
4175
  ref: stageWrap,
3903
4176
  width: unref(stageRect)?.width,
3904
4177
  height: unref(stageRect)?.height,
4178
+ "wrap-width": unref(stageContainerRect)?.width,
4179
+ "wrap-height": unref(stageContainerRect)?.height,
3905
4180
  zoom: unref(zoom)
3906
4181
  }, {
3907
4182
  default: withCtx(() => [
@@ -3909,7 +4184,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3909
4184
  class: "m-editor-stage-container",
3910
4185
  ref_key: "stageContainer",
3911
4186
  ref: stageContainer,
3912
- style: normalizeStyle(`transform: scale(${unref(zoom)})`),
4187
+ style: normalizeStyle(`transform: scale(${unref(zoom)});`),
3913
4188
  onContextmenu: contextmenuHandler,
3914
4189
  onDrop: dropHandler,
3915
4190
  onDragover: dragoverHandler
@@ -3923,28 +4198,25 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3923
4198
  ]))
3924
4199
  ]),
3925
4200
  _: 1
3926
- }, 8, ["width", "height", "zoom"]);
4201
+ }, 8, ["width", "height", "wrap-width", "wrap-height", "zoom"]);
3927
4202
  };
3928
4203
  }
3929
4204
  });
3930
4205
 
3931
- const _sfc_main$1 = defineComponent({
3932
- name: "m-editor-workspace",
3933
- components: {
3934
- PageBar: _sfc_main$5,
3935
- MagicStage: _sfc_main$2
3936
- },
3937
- setup() {
4206
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4207
+ __name: "Workspace",
4208
+ setup(__props) {
3938
4209
  const services = inject("services");
3939
4210
  const workspace = ref();
3940
4211
  const nodes = computed(() => services?.editorService.get("nodes"));
3941
- let keycon;
4212
+ const page = computed(() => services?.editorService.get("page"));
3942
4213
  const mouseenterHandler = () => {
3943
4214
  workspace.value?.focus();
3944
4215
  };
3945
4216
  const mouseleaveHandler = () => {
3946
4217
  workspace.value?.blur();
3947
4218
  };
4219
+ let keycon;
3948
4220
  onMounted(() => {
3949
4221
  workspace.value?.addEventListener("mouseenter", mouseenterHandler);
3950
4222
  workspace.value?.addEventListener("mouseleave", mouseleaveHandler);
@@ -3966,7 +4238,7 @@ const _sfc_main$1 = defineComponent({
3966
4238
  nodes.value && services?.editorService.copy(nodes.value);
3967
4239
  }).keydown([ctrl, "v"], (e) => {
3968
4240
  e.inputEvent.preventDefault();
3969
- nodes.value && services?.editorService.paste();
4241
+ nodes.value && services?.editorService.paste({ offsetX: 10, offsetY: 10 });
3970
4242
  }).keydown([ctrl, "x"], (e) => {
3971
4243
  e.inputEvent.preventDefault();
3972
4244
  if (!nodes.value || isPage(nodes.value[0]))
@@ -4021,6 +4293,12 @@ const _sfc_main$1 = defineComponent({
4021
4293
  }).keydown([ctrl, "numpad-"], (e) => {
4022
4294
  e.inputEvent.preventDefault();
4023
4295
  services?.uiService.zoom(-0.1);
4296
+ }).keydown([ctrl, "0"], (e) => {
4297
+ e.inputEvent.preventDefault();
4298
+ services?.uiService.set("zoom", services.uiService.calcZoom());
4299
+ }).keydown([ctrl, "1"], (e) => {
4300
+ e.inputEvent.preventDefault();
4301
+ services?.uiService.set("zoom", 1);
4024
4302
  });
4025
4303
  });
4026
4304
  onUnmounted(() => {
@@ -4028,39 +4306,33 @@ const _sfc_main$1 = defineComponent({
4028
4306
  workspace.value?.removeEventListener("mouseleave", mouseleaveHandler);
4029
4307
  keycon.destroy();
4030
4308
  });
4031
- return {
4032
- workspace,
4033
- page: computed(() => services?.editorService.get("page"))
4309
+ return (_ctx, _cache) => {
4310
+ return openBlock(), createElementBlock("div", {
4311
+ class: "m-editor-workspace",
4312
+ tabindex: "1",
4313
+ ref_key: "workspace",
4314
+ ref: workspace
4315
+ }, [
4316
+ renderSlot(_ctx.$slots, "stage", {}, () => [
4317
+ (openBlock(), createBlock(_sfc_main$2, {
4318
+ key: unref(page)?.id
4319
+ }))
4320
+ ]),
4321
+ renderSlot(_ctx.$slots, "workspace-content"),
4322
+ createVNode(_sfc_main$6, null, {
4323
+ "page-bar-title": withCtx(({ page: page2 }) => [
4324
+ renderSlot(_ctx.$slots, "page-bar-title", { page: page2 })
4325
+ ]),
4326
+ "page-bar-popover": withCtx(({ page: page2 }) => [
4327
+ renderSlot(_ctx.$slots, "page-bar-popover", { page: page2 })
4328
+ ]),
4329
+ _: 3
4330
+ })
4331
+ ], 512);
4034
4332
  };
4035
4333
  }
4036
4334
  });
4037
4335
 
4038
- const _hoisted_1 = {
4039
- class: "m-editor-workspace",
4040
- tabindex: "1",
4041
- ref: "workspace"
4042
- };
4043
- function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4044
- const _component_magic_stage = resolveComponent("magic-stage");
4045
- const _component_page_bar = resolveComponent("page-bar");
4046
- return openBlock(), createElementBlock("div", _hoisted_1, [
4047
- (openBlock(), createBlock(_component_magic_stage, {
4048
- key: _ctx.page?.id
4049
- })),
4050
- renderSlot(_ctx.$slots, "workspace-content"),
4051
- createVNode(_component_page_bar, null, {
4052
- "page-bar-title": withCtx(({ page }) => [
4053
- renderSlot(_ctx.$slots, "page-bar-title", { page })
4054
- ]),
4055
- "page-bar-popover": withCtx(({ page }) => [
4056
- renderSlot(_ctx.$slots, "page-bar-popover", { page })
4057
- ]),
4058
- _: 3
4059
- })
4060
- ], 512);
4061
- }
4062
- const Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
4063
-
4064
4336
  class ComponentList extends BaseService {
4065
4337
  state = reactive({
4066
4338
  list: []
@@ -4074,136 +4346,20 @@ class ComponentList extends BaseService {
4074
4346
  getList() {
4075
4347
  return this.state.list;
4076
4348
  }
4077
- }
4078
- const componentListService = new ComponentList();
4079
-
4080
- const DEFAULT_LEFT_COLUMN_WIDTH = 310;
4081
- const MIN_LEFT_COLUMN_WIDTH = 45;
4082
- const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
4083
- const MIN_RIGHT_COLUMN_WIDTH = 1;
4084
- const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
4085
- const defaultColumnWidth = {
4086
- left: DEFAULT_LEFT_COLUMN_WIDTH,
4087
- center: globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH,
4088
- right: DEFAULT_RIGHT_COLUMN_WIDTH
4089
- };
4090
- const state = reactive({
4091
- uiSelectMode: false,
4092
- showSrc: false,
4093
- zoom: 1,
4094
- stageContainerRect: {
4095
- width: 0,
4096
- height: 0
4097
- },
4098
- stageRect: {
4099
- width: 375,
4100
- height: 817
4101
- },
4102
- columnWidth: defaultColumnWidth,
4103
- showGuides: true,
4104
- showRule: true,
4105
- propsPanelSize: "small"
4106
- });
4107
- class Ui extends BaseService {
4108
- constructor() {
4109
- super([]);
4110
- globalThis.addEventListener("resize", () => {
4111
- this.setColumnWidth({
4112
- center: "auto"
4113
- });
4114
- });
4115
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
4116
- if (columnWidthCacheData) {
4117
- try {
4118
- const columnWidthCache = JSON.parse(columnWidthCacheData);
4119
- this.setColumnWidth(columnWidthCache);
4120
- } catch (e) {
4121
- console.error(e);
4122
- }
4123
- }
4124
- }
4125
- set(name, value) {
4126
- const mask = editorService.get("stage")?.mask;
4127
- if (name === "columnWidth") {
4128
- this.setColumnWidth(value);
4129
- return;
4130
- }
4131
- if (name === "stageRect") {
4132
- this.setStageRect(value);
4133
- return;
4134
- }
4135
- if (name === "showGuides") {
4136
- mask?.showGuides(value);
4137
- }
4138
- if (name === "showRule") {
4139
- mask?.showRule(value);
4140
- }
4141
- state[name] = value;
4142
- if (name === "stageContainerRect") {
4143
- state.zoom = this.calcZoom();
4144
- }
4145
- }
4146
- get(name) {
4147
- return state[name];
4148
- }
4149
- zoom(zoom) {
4150
- this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
4151
- if (this.get("zoom") < 0.1)
4152
- this.set("zoom", 0.1);
4153
- }
4154
- setColumnWidth({ left, center, right }) {
4155
- const columnWidth = {
4156
- ...toRaw(this.get("columnWidth"))
4157
- };
4158
- if (left) {
4159
- columnWidth.left = Math.max(left, MIN_LEFT_COLUMN_WIDTH);
4160
- }
4161
- if (right) {
4162
- columnWidth.right = Math.max(right, MIN_RIGHT_COLUMN_WIDTH);
4163
- }
4164
- if (!center || center === "auto") {
4165
- const bodyWidth = globalThis.document.body.clientWidth;
4166
- columnWidth.center = bodyWidth - (columnWidth?.left || 0) - (columnWidth?.right || 0);
4167
- if (columnWidth.center <= 0) {
4168
- columnWidth.left = defaultColumnWidth.left;
4169
- columnWidth.center = defaultColumnWidth.center;
4170
- columnWidth.right = defaultColumnWidth.right;
4171
- }
4172
- } else {
4173
- columnWidth.center = center;
4174
- }
4175
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
4176
- state.columnWidth = columnWidth;
4177
- }
4178
- setStageRect(value) {
4179
- state.stageRect = {
4180
- ...state.stageRect,
4181
- ...value
4182
- };
4183
- state.zoom = this.calcZoom();
4184
- }
4185
- calcZoom() {
4186
- const { stageRect, stageContainerRect } = state;
4187
- const { height, width } = stageContainerRect;
4188
- if (!width || !height)
4189
- return 1;
4190
- const stageWidth = stageRect.width + 30;
4191
- const stageHeight = stageRect.height + 30;
4192
- if (width > stageWidth && height > stageHeight) {
4193
- return 1;
4194
- }
4195
- return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
4349
+ destroy() {
4350
+ this.state.list = [];
4351
+ this.removeAllListeners();
4196
4352
  }
4197
4353
  }
4198
- const uiService = new Ui();
4354
+ const componentListService = new ComponentList();
4199
4355
 
4200
4356
  const _sfc_main = defineComponent({
4201
4357
  name: "m-editor",
4202
4358
  components: {
4203
- NavMenu,
4359
+ NavMenu: _sfc_main$f,
4204
4360
  Sidebar,
4205
- Workspace,
4206
- PropsPanel,
4361
+ Workspace: _sfc_main$1,
4362
+ PropsPanel: _sfc_main$e,
4207
4363
  Framework
4208
4364
  },
4209
4365
  props: {
@@ -4270,6 +4426,10 @@ const _sfc_main = defineComponent({
4270
4426
  type: Number,
4271
4427
  default: 800
4272
4428
  },
4429
+ containerHighlightType: {
4430
+ type: String,
4431
+ default: ContainerHighlightType.DEFAULT
4432
+ },
4273
4433
  stageRect: {
4274
4434
  type: [String, Object]
4275
4435
  },
@@ -4318,7 +4478,15 @@ const _sfc_main = defineComponent({
4318
4478
  watch(() => props.stageRect, (stageRect) => stageRect && uiService.set("stageRect", stageRect), {
4319
4479
  immediate: true
4320
4480
  });
4321
- onUnmounted(() => editorService.destroy());
4481
+ uiService.initColumnWidth();
4482
+ onUnmounted(() => {
4483
+ editorService.destroy();
4484
+ historyService.destroy();
4485
+ propsService.destroy();
4486
+ uiService.destroy();
4487
+ componentListService.destroy();
4488
+ storageService.destroy();
4489
+ });
4322
4490
  const services = {
4323
4491
  componentListService,
4324
4492
  eventsService,
@@ -4340,7 +4508,8 @@ const _sfc_main = defineComponent({
4340
4508
  updateDragEl: props.updateDragEl,
4341
4509
  isContainer: props.isContainer,
4342
4510
  containerHighlightClassName: props.containerHighlightClassName,
4343
- containerHighlightDuration: props.containerHighlightDuration
4511
+ containerHighlightDuration: props.containerHighlightDuration,
4512
+ containerHighlightType: props.containerHighlightType
4344
4513
  }));
4345
4514
  return services;
4346
4515
  }
@@ -4374,6 +4543,9 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4374
4543
  workspace: withCtx(() => [
4375
4544
  renderSlot(_ctx.$slots, "workspace", { editorService: _ctx.editorService }, () => [
4376
4545
  createVNode(_component_workspace, null, {
4546
+ stage: withCtx(() => [
4547
+ renderSlot(_ctx.$slots, "stage")
4548
+ ]),
4377
4549
  "workspace-content": withCtx(() => [
4378
4550
  renderSlot(_ctx.$slots, "workspace-content", { editorService: _ctx.editorService })
4379
4551
  ]),
@@ -4390,14 +4562,13 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4390
4562
  "props-panel": withCtx(() => [
4391
4563
  renderSlot(_ctx.$slots, "props-panel", {}, () => [
4392
4564
  createVNode(_component_props_panel, {
4393
- ref: "propsPanel",
4394
4565
  onMounted: _cache[0] || (_cache[0] = (instance) => _ctx.$emit("props-panel-mounted", instance))
4395
4566
  }, {
4396
4567
  "props-panel-header": withCtx(() => [
4397
4568
  renderSlot(_ctx.$slots, "props-panel-header")
4398
4569
  ]),
4399
4570
  _: 3
4400
- }, 512)
4571
+ })
4401
4572
  ])
4402
4573
  ]),
4403
4574
  empty: withCtx(() => [
@@ -4417,12 +4588,12 @@ const index = {
4417
4588
  app.config.globalProperties.$TMAGIC_EDITOR = option;
4418
4589
  setConfig(option);
4419
4590
  app.component(Editor.name, Editor);
4420
- app.component("m-fields-ui-select", _sfc_main$l);
4591
+ app.component("m-fields-ui-select", _sfc_main$m);
4421
4592
  app.component(CodeLink.name, CodeLink);
4422
4593
  app.component(Code.name, Code);
4423
4594
  app.component(CodeEditor.name, CodeEditor);
4424
4595
  }
4425
4596
  };
4426
4597
 
4427
- export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$f as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, warn };
4598
+ export { COPY_STORAGE_KEY, ColumnLayout, ComponentListPanel, _sfc_main$c as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$h as Icon, Keys, LayerOffset, LayerPanel, Layout, _sfc_main$e as PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$g as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, useStage, warn };
4428
4599
  //# sourceMappingURL=tmagic-editor.mjs.map