@tmagic/editor 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
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';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, inject, ref, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, onMounted, onUnmounted, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, watchEffect, createSlots, resolveDynamicComponent, renderList, normalizeProps, mergeProps, markRaw, getCurrentInstance, Teleport, nextTick, toHandlers, provide } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
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';
@@ -12,112 +12,100 @@ import Gesto from 'gesto';
12
12
  import { ElMessage } from 'element-plus';
13
13
  import KeyController from 'keycon';
14
14
 
15
- const _sfc_main$o = defineComponent({
16
- name: "m-fields-vs-code",
17
- props: ["model", "name", "config", "prop"],
15
+ const _sfc_main$p = /* @__PURE__ */ defineComponent({
16
+ __name: "Code",
17
+ props: {
18
+ model: null,
19
+ name: null,
20
+ config: null,
21
+ prop: null
22
+ },
18
23
  emits: ["change"],
19
- setup(props, { emit }) {
24
+ setup(__props, { emit }) {
25
+ const props = __props;
20
26
  const language = computed(() => props.config.language || "javascript");
21
27
  const height = computed(() => `${document.body.clientHeight - 168}px`);
22
- return {
23
- height,
24
- language,
25
- save(v) {
26
- props.model[props.name] = v;
27
- emit("change", v);
28
- }
28
+ const save = (v) => {
29
+ props.model[props.name] = v;
30
+ emit("change", v);
31
+ };
32
+ return (_ctx, _cache) => {
33
+ const _component_magic_code_editor = resolveComponent("magic-code-editor");
34
+ return openBlock(), createBlock(_component_magic_code_editor, {
35
+ style: normalizeStyle(`height: ${unref(height)}`),
36
+ "init-values": __props.model[__props.name],
37
+ language: unref(language),
38
+ onSave: save
39
+ }, null, 8, ["style", "init-values", "language"]);
29
40
  };
30
41
  }
31
42
  });
32
43
 
33
- const _export_sfc = (sfc, props) => {
34
- const target = sfc.__vccOpts || sfc;
35
- for (const [key, val] of props) {
36
- target[key] = val;
37
- }
38
- return target;
39
- };
40
-
41
- function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
42
- const _component_magic_code_editor = resolveComponent("magic-code-editor");
43
- return openBlock(), createBlock(_component_magic_code_editor, {
44
- style: normalizeStyle(`height: ${_ctx.height}`),
45
- "init-values": _ctx.model[_ctx.name],
46
- language: _ctx.language,
47
- onSave: _ctx.save
48
- }, null, 8, ["style", "init-values", "language", "onSave"]);
49
- }
50
- const Code = /* @__PURE__ */ _export_sfc(_sfc_main$o, [["render", _sfc_render$a]]);
51
-
52
- const _sfc_main$n = defineComponent({
53
- name: "m-fields-code-link",
44
+ const _sfc_main$o = /* @__PURE__ */ defineComponent({
45
+ __name: "CodeLink",
54
46
  props: {
55
- config: {
56
- type: Object
57
- },
58
- model: {
59
- type: Object
60
- },
61
- name: {
62
- type: String
63
- },
64
- prop: {
65
- type: String
66
- }
47
+ config: null,
48
+ model: null,
49
+ name: null,
50
+ prop: null
67
51
  },
68
52
  emits: ["change"],
69
- setup(props, { emit }) {
70
- const modelValue = ref({
71
- form: {}
53
+ setup(__props, { emit }) {
54
+ const props = __props;
55
+ const formConfig = computed(() => ({
56
+ ...props.config,
57
+ text: "",
58
+ type: "link",
59
+ form: [
60
+ {
61
+ name: props.name,
62
+ type: "vs-code"
63
+ }
64
+ ]
65
+ }));
66
+ const modelValue = reactive({
67
+ form: {
68
+ [props.name]: ""
69
+ }
72
70
  });
73
- watchEffect(() => {
74
- if (!props.model || !props.name)
71
+ watch(
72
+ () => props.model[props.name],
73
+ (value) => {
74
+ modelValue.form = {
75
+ [props.name]: serialize(value, {
76
+ space: 2,
77
+ unsafe: true
78
+ }).replace(/"(\w+)":\s/g, "$1: ")
79
+ };
80
+ },
81
+ {
82
+ immediate: true
83
+ }
84
+ );
85
+ const changeHandler = (v) => {
86
+ if (!props.name || !props.model)
75
87
  return;
76
- modelValue.value.form[props.name] = serialize(props.model[props.name], {
77
- space: 2,
78
- unsafe: true
79
- }).replace(/"(\w+)":\s/g, "$1: ");
80
- });
81
- return {
82
- modelValue,
83
- formConfig: computed(() => ({
84
- ...props.config,
85
- text: "",
86
- type: "link",
87
- form: [
88
- {
89
- name: props.name,
90
- type: "vs-code"
91
- }
92
- ]
93
- })),
94
- changeHandler(v) {
95
- if (!props.name || !props.model)
96
- return;
97
- try {
98
- props.model[props.name] = eval(`${v[props.name]}`);
99
- emit("change", props.model[props.name]);
100
- } catch (e) {
101
- console.error(e);
102
- }
88
+ try {
89
+ props.model[props.name] = eval(`(${v[props.name]})`);
90
+ emit("change", props.model[props.name]);
91
+ } catch (e) {
92
+ console.error(e);
103
93
  }
104
94
  };
95
+ return (_ctx, _cache) => {
96
+ const _component_m_fields_link = resolveComponent("m-fields-link");
97
+ return openBlock(), createBlock(_component_m_fields_link, {
98
+ config: unref(formConfig),
99
+ model: modelValue,
100
+ name: "form",
101
+ onChange: changeHandler
102
+ }, null, 8, ["config", "model"]);
103
+ };
105
104
  }
106
105
  });
107
106
 
108
- function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
109
- const _component_m_fields_link = resolveComponent("m-fields-link");
110
- return openBlock(), createBlock(_component_m_fields_link, {
111
- config: _ctx.formConfig,
112
- model: _ctx.modelValue,
113
- name: "form",
114
- onChange: _ctx.changeHandler
115
- }, null, 8, ["config", "model", "onChange"]);
116
- }
117
- const CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$n, [["render", _sfc_render$9]]);
118
-
119
- const _hoisted_1$c = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
120
- const _sfc_main$m = /* @__PURE__ */ defineComponent({
107
+ const _hoisted_1$b = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
108
+ const _sfc_main$n = /* @__PURE__ */ defineComponent({
121
109
  __name: "UISelect",
122
110
  props: {
123
111
  config: null,
@@ -182,7 +170,7 @@ const _sfc_main$m = /* @__PURE__ */ defineComponent({
182
170
  style: { "padding": "0" }
183
171
  }, {
184
172
  default: withCtx(() => [
185
- _hoisted_1$c
173
+ _hoisted_1$b
186
174
  ]),
187
175
  _: 1
188
176
  }, 8, ["icon"])
@@ -245,7 +233,7 @@ const toString = (v, language) => {
245
233
  }
246
234
  return value;
247
235
  };
248
- const _sfc_main$l = defineComponent({
236
+ const _sfc_main$m = defineComponent({
249
237
  name: "magic-code-editor",
250
238
  props: {
251
239
  initValues: {
@@ -274,10 +262,12 @@ const _sfc_main$l = defineComponent({
274
262
  const values = ref("");
275
263
  const loading = ref(false);
276
264
  const codeEditor = ref();
277
- const resizeObserver = new globalThis.ResizeObserver(throttle(() => {
278
- vsEditor?.layout();
279
- vsDiffEditor?.layout();
280
- }, 300));
265
+ const resizeObserver = new globalThis.ResizeObserver(
266
+ throttle(() => {
267
+ vsEditor?.layout();
268
+ vsDiffEditor?.layout();
269
+ }, 300)
270
+ );
281
271
  const setEditorValue = (v, m) => {
282
272
  values.value = toString(v, props.language);
283
273
  if (props.type === "diff") {
@@ -322,14 +312,18 @@ const _sfc_main$l = defineComponent({
322
312
  }
323
313
  resizeObserver.observe(codeEditor.value);
324
314
  };
325
- watch(() => props.initValues, (v, preV) => {
326
- if (v !== preV) {
327
- setEditorValue(props.initValues, props.modifiedValues);
315
+ watch(
316
+ () => props.initValues,
317
+ (v, preV) => {
318
+ if (v !== preV) {
319
+ setEditorValue(props.initValues, props.modifiedValues);
320
+ }
321
+ },
322
+ {
323
+ deep: true,
324
+ immediate: true
328
325
  }
329
- }, {
330
- deep: true,
331
- immediate: true
332
- });
326
+ );
333
327
  onMounted(async () => {
334
328
  loading.value = true;
335
329
  init();
@@ -353,14 +347,22 @@ const _sfc_main$l = defineComponent({
353
347
  }
354
348
  });
355
349
 
356
- const _hoisted_1$b = {
350
+ const _export_sfc = (sfc, props) => {
351
+ const target = sfc.__vccOpts || sfc;
352
+ for (const [key, val] of props) {
353
+ target[key] = val;
354
+ }
355
+ return target;
356
+ };
357
+
358
+ const _hoisted_1$a = {
357
359
  ref: "codeEditor",
358
360
  class: "magic-code-editor"
359
361
  };
360
- function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
361
- return openBlock(), createElementBlock("div", _hoisted_1$b, null, 512);
362
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
363
+ return openBlock(), createElementBlock("div", _hoisted_1$a, null, 512);
362
364
  }
363
- const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$8]]);
365
+ const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$6]]);
364
366
 
365
367
  let $TMAGIC_EDITOR = {};
366
368
  const setConfig = (option) => {
@@ -633,7 +635,9 @@ class WebStorage extends BaseService {
633
635
  }
634
636
  async getItem(key, options = {}) {
635
637
  const [storage, namespace] = await Promise.all([this.getStorage(), this.getNamespace()]);
636
- const { protocol = options.protocol, item } = this.getValueAndProtocol(storage.getItem(`${options.namespace || namespace}:${key}`));
638
+ const { protocol = options.protocol, item } = this.getValueAndProtocol(
639
+ storage.getItem(`${options.namespace || namespace}:${key}`)
640
+ );
637
641
  if (item === null)
638
642
  return null;
639
643
  switch (protocol) {
@@ -924,10 +928,12 @@ class Props extends BaseService {
924
928
  const [id, defaultPropsValue, data] = await Promise.all([
925
929
  this.createId(type),
926
930
  this.getDefaultPropsValue(type),
927
- this.setNewItemId(cloneDeep({
928
- type,
929
- ...defaultValue
930
- }))
931
+ this.setNewItemId(
932
+ cloneDeep({
933
+ type,
934
+ ...defaultValue
935
+ })
936
+ )
931
937
  ]);
932
938
  return {
933
939
  id,
@@ -980,37 +986,39 @@ const beforePaste = async (position, config) => {
980
986
  return config;
981
987
  const curNode = editorService.get("node");
982
988
  const { left: referenceLeft, top: referenceTop } = config[0].style;
983
- const pasteConfigs = await Promise.all(config.map(async (configItem) => {
984
- const { offsetX = 0, offsetY = 0, ...positionClone } = position;
985
- let pastePosition = positionClone;
986
- if (!isEmpty(pastePosition) && curNode.items) {
987
- pastePosition = getPositionInContainer(pastePosition, curNode.id);
988
- }
989
- if (pastePosition.left && configItem.style?.left) {
990
- pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
991
- }
992
- if (pastePosition.top && configItem.style?.top) {
993
- pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
994
- }
995
- const pasteConfig = await propsService.setNewItemId(configItem);
996
- if (pasteConfig.style) {
997
- const { left, top } = pasteConfig.style;
998
- if (typeof left === "number" || !!left && !isNaN(Number(left))) {
999
- pasteConfig.style.left = Number(left) + offsetX;
989
+ const pasteConfigs = await Promise.all(
990
+ config.map(async (configItem) => {
991
+ const { offsetX = 0, offsetY = 0, ...positionClone } = position;
992
+ let pastePosition = positionClone;
993
+ if (!isEmpty(pastePosition) && curNode.items) {
994
+ pastePosition = getPositionInContainer(pastePosition, curNode.id);
1000
995
  }
1001
- if (typeof top === "number" || !!top && !isNaN(Number(top))) {
1002
- pasteConfig.style.top = Number(top) + offsetY;
996
+ if (pastePosition.left && configItem.style?.left) {
997
+ pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
1003
998
  }
1004
- pasteConfig.style = {
1005
- ...pasteConfig.style,
1006
- ...pastePosition
1007
- };
1008
- }
1009
- if (isPage(pasteConfig)) {
1010
- pasteConfig.name = generatePageNameByApp(editorService.get("root"));
1011
- }
1012
- return pasteConfig;
1013
- }));
999
+ if (pastePosition.top && configItem.style?.top) {
1000
+ pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
1001
+ }
1002
+ const pasteConfig = await propsService.setNewItemId(configItem);
1003
+ if (pasteConfig.style) {
1004
+ const { left, top } = pasteConfig.style;
1005
+ if (typeof left === "number" || !!left && !isNaN(Number(left))) {
1006
+ pasteConfig.style.left = Number(left) + offsetX;
1007
+ }
1008
+ if (typeof top === "number" || !!top && !isNaN(Number(top))) {
1009
+ pasteConfig.style.top = Number(top) + offsetY;
1010
+ }
1011
+ pasteConfig.style = {
1012
+ ...pasteConfig.style,
1013
+ ...pastePosition
1014
+ };
1015
+ }
1016
+ if (isPage(pasteConfig)) {
1017
+ pasteConfig.name = generatePageNameByApp(editorService.get("root"));
1018
+ }
1019
+ return pasteConfig;
1020
+ })
1021
+ );
1014
1022
  return pasteConfigs;
1015
1023
  };
1016
1024
  const getPositionInContainer = (position = {}, id) => {
@@ -1051,28 +1059,31 @@ class Editor$1 extends BaseService {
1051
1059
  });
1052
1060
  isHistoryStateChange = false;
1053
1061
  constructor() {
1054
- super([
1055
- "getLayout",
1056
- "select",
1057
- "doAdd",
1058
- "add",
1059
- "doRemove",
1060
- "remove",
1061
- "doUpdate",
1062
- "update",
1063
- "sort",
1064
- "copy",
1065
- "paste",
1066
- "doPaste",
1067
- "duAlignCenter",
1068
- "alignCenter",
1069
- "moveLayer",
1070
- "moveToContainer",
1071
- "move",
1072
- "undo",
1073
- "redo",
1074
- "highlight"
1075
- ], ["select", "update", "moveLayer"]);
1062
+ super(
1063
+ [
1064
+ "getLayout",
1065
+ "select",
1066
+ "doAdd",
1067
+ "add",
1068
+ "doRemove",
1069
+ "remove",
1070
+ "doUpdate",
1071
+ "update",
1072
+ "sort",
1073
+ "copy",
1074
+ "paste",
1075
+ "doPaste",
1076
+ "duAlignCenter",
1077
+ "alignCenter",
1078
+ "moveLayer",
1079
+ "moveToContainer",
1080
+ "move",
1081
+ "undo",
1082
+ "redo",
1083
+ "highlight"
1084
+ ],
1085
+ ["select", "update", "moveLayer"]
1086
+ );
1076
1087
  }
1077
1088
  set(name, value) {
1078
1089
  this.state[name] = value;
@@ -1144,11 +1155,15 @@ class Editor$1 extends BaseService {
1144
1155
  historyService.empty();
1145
1156
  }
1146
1157
  if (node?.id) {
1147
- this.get("stage")?.renderer.runtime?.getApp?.()?.emit("editor:select", {
1148
- node,
1149
- page,
1150
- parent
1151
- }, getNodePath(node.id, this.get("root").items));
1158
+ this.get("stage")?.renderer.runtime?.getApp?.()?.emit(
1159
+ "editor:select",
1160
+ {
1161
+ node,
1162
+ page,
1163
+ parent
1164
+ },
1165
+ getNodePath(node.id, this.get("root").items)
1166
+ );
1152
1167
  }
1153
1168
  this.emit("select", node);
1154
1169
  return node;
@@ -1200,7 +1215,7 @@ class Editor$1 extends BaseService {
1200
1215
  if ((parent?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && node.type !== NodeType.PAGE) {
1201
1216
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
1202
1217
  }
1203
- if (parent.id !== curNode.id) {
1218
+ if (parent.id !== curNode.id && node.type !== NodeType.PAGE) {
1204
1219
  const index = parent.items.indexOf(curNode);
1205
1220
  parent?.items?.splice(index + 1, 0, node);
1206
1221
  } else {
@@ -1214,8 +1229,11 @@ class Editor$1 extends BaseService {
1214
1229
  parentId: parent.id,
1215
1230
  root: cloneDeep(root)
1216
1231
  });
1217
- node.style = fixNodePosition(node, parent, stage);
1218
- await stage?.update({ config: cloneDeep(node), parentId: parent.id, root: cloneDeep(root) });
1232
+ const newStyle = fixNodePosition(node, parent, stage);
1233
+ if (newStyle && (newStyle.top !== node.style.top || newStyle.left !== node.style.left)) {
1234
+ node.style = newStyle;
1235
+ await stage?.update({ config: cloneDeep(node), parentId: parent.id, root: cloneDeep(root) });
1236
+ }
1219
1237
  this.addModifiedNodeId(node.id);
1220
1238
  return node;
1221
1239
  }
@@ -1230,12 +1248,14 @@ class Editor$1 extends BaseService {
1230
1248
  } else {
1231
1249
  addNodes.push(...addNode);
1232
1250
  }
1233
- const newNodes = await Promise.all(addNodes.map((node) => {
1234
- const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(node);
1235
- if (!parentNode)
1236
- throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
1237
- return this.doAdd(node, parentNode);
1238
- }));
1251
+ const newNodes = await Promise.all(
1252
+ addNodes.map((node) => {
1253
+ const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(node);
1254
+ if (!parentNode)
1255
+ throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
1256
+ return this.doAdd(node, parentNode);
1257
+ })
1258
+ );
1239
1259
  if (newNodes.length > 1) {
1240
1260
  const newNodeIds = newNodes.map((node) => node.id);
1241
1261
  stage?.multiSelect(newNodeIds);
@@ -1854,16 +1874,6 @@ const error = (...args) => {
1854
1874
  }
1855
1875
  };
1856
1876
 
1857
- const DEFAULT_LEFT_COLUMN_WIDTH = 310;
1858
- const MIN_LEFT_COLUMN_WIDTH = 45;
1859
- const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
1860
- const MIN_RIGHT_COLUMN_WIDTH = 1;
1861
- const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
1862
- const defaultColumnWidth = {
1863
- left: DEFAULT_LEFT_COLUMN_WIDTH,
1864
- center: globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH,
1865
- right: DEFAULT_RIGHT_COLUMN_WIDTH
1866
- };
1867
1877
  const state = reactive({
1868
1878
  uiSelectMode: false,
1869
1879
  showSrc: false,
@@ -1876,7 +1886,11 @@ const state = reactive({
1876
1886
  width: 375,
1877
1887
  height: 817
1878
1888
  },
1879
- columnWidth: defaultColumnWidth,
1889
+ columnWidth: {
1890
+ left: 0,
1891
+ right: 0,
1892
+ center: 0
1893
+ },
1880
1894
  showGuides: true,
1881
1895
  showRule: true,
1882
1896
  propsPanelSize: "small",
@@ -1884,19 +1898,10 @@ const state = reactive({
1884
1898
  });
1885
1899
  class Ui extends BaseService {
1886
1900
  constructor() {
1887
- super([]);
1888
- globalThis.addEventListener("resize", () => {
1889
- this.setColumnWidth({
1890
- center: "auto"
1891
- });
1892
- });
1901
+ super(["zoom", "calcZoom"]);
1893
1902
  }
1894
1903
  set(name, value) {
1895
1904
  const mask = editorService.get("stage")?.mask;
1896
- if (name === "columnWidth") {
1897
- this.setColumnWidth(value);
1898
- return;
1899
- }
1900
1905
  if (name === "stageRect") {
1901
1906
  this.setStageRect(value);
1902
1907
  return;
@@ -1912,23 +1917,12 @@ class Ui extends BaseService {
1912
1917
  get(name) {
1913
1918
  return state[name];
1914
1919
  }
1915
- initColumnWidth() {
1916
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
1917
- if (columnWidthCacheData) {
1918
- try {
1919
- const columnWidthCache = JSON.parse(columnWidthCacheData);
1920
- this.setColumnWidth(columnWidthCache);
1921
- } catch (e) {
1922
- console.error(e);
1923
- }
1924
- }
1925
- }
1926
- zoom(zoom) {
1920
+ async zoom(zoom) {
1927
1921
  this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
1928
1922
  if (this.get("zoom") < 0.1)
1929
1923
  this.set("zoom", 0.1);
1930
1924
  }
1931
- calcZoom() {
1925
+ async calcZoom() {
1932
1926
  const { stageRect, stageContainerRect } = state;
1933
1927
  const { height, width } = stageContainerRect;
1934
1928
  if (!width || !height)
@@ -1943,36 +1937,12 @@ class Ui extends BaseService {
1943
1937
  destroy() {
1944
1938
  this.removeAllListeners();
1945
1939
  }
1946
- setColumnWidth({ left, center, right }) {
1947
- const columnWidth = {
1948
- ...toRaw(this.get("columnWidth"))
1949
- };
1950
- if (left) {
1951
- columnWidth.left = Math.max(left, MIN_LEFT_COLUMN_WIDTH);
1952
- }
1953
- if (right) {
1954
- columnWidth.right = Math.max(right, MIN_RIGHT_COLUMN_WIDTH);
1955
- }
1956
- if (!center || center === "auto") {
1957
- const bodyWidth = globalThis.document.body.clientWidth;
1958
- columnWidth.center = bodyWidth - (columnWidth?.left || 0) - (columnWidth?.right || 0);
1959
- if (columnWidth.center <= 0) {
1960
- columnWidth.left = defaultColumnWidth.left;
1961
- columnWidth.center = defaultColumnWidth.center;
1962
- columnWidth.right = defaultColumnWidth.right;
1963
- }
1964
- } else {
1965
- columnWidth.center = center;
1966
- }
1967
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
1968
- state.columnWidth = columnWidth;
1969
- }
1970
- setStageRect(value) {
1940
+ async setStageRect(value) {
1971
1941
  state.stageRect = {
1972
1942
  ...state.stageRect,
1973
1943
  ...value
1974
1944
  };
1975
- state.zoom = this.calcZoom();
1945
+ state.zoom = await this.calcZoom();
1976
1946
  }
1977
1947
  }
1978
1948
  const uiService = new Ui();
@@ -2032,7 +2002,9 @@ const useStage = (stageOptions) => {
2032
2002
  uiService.set("showGuides", true);
2033
2003
  if (!root.value || !page.value)
2034
2004
  return;
2035
- const storageKey = getGuideLineKey(e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY);
2005
+ const storageKey = getGuideLineKey(
2006
+ e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY
2007
+ );
2036
2008
  if (e.guides.length) {
2037
2009
  globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
2038
2010
  } else {
@@ -2042,7 +2014,7 @@ const useStage = (stageOptions) => {
2042
2014
  return stage;
2043
2015
  };
2044
2016
 
2045
- const _sfc_main$k = defineComponent({
2017
+ const _sfc_main$l = defineComponent({
2046
2018
  components: { Plus },
2047
2019
  setup() {
2048
2020
  const services = inject("services");
@@ -2060,14 +2032,14 @@ const _sfc_main$k = defineComponent({
2060
2032
  }
2061
2033
  });
2062
2034
 
2063
- const _hoisted_1$a = { class: "m-editor-empty-panel" };
2064
- const _hoisted_2$4 = { class: "m-editor-empty-content" };
2035
+ const _hoisted_1$9 = { class: "m-editor-empty-panel" };
2036
+ const _hoisted_2$3 = { class: "m-editor-empty-content" };
2065
2037
  const _hoisted_3 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
2066
- function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2038
+ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2067
2039
  const _component_plus = resolveComponent("plus");
2068
2040
  const _component_el_icon = resolveComponent("el-icon");
2069
- return openBlock(), createElementBlock("div", _hoisted_1$a, [
2070
- createElementVNode("div", _hoisted_2$4, [
2041
+ return openBlock(), createElementBlock("div", _hoisted_1$9, [
2042
+ createElementVNode("div", _hoisted_2$3, [
2071
2043
  createElementVNode("div", {
2072
2044
  class: "m-editor-empty-button",
2073
2045
  onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
@@ -2085,17 +2057,12 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2085
2057
  ])
2086
2058
  ]);
2087
2059
  }
2088
- const AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$7]]);
2060
+ const AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$5]]);
2089
2061
 
2090
- const _sfc_main$j = defineComponent({
2091
- name: "m-editor-resize",
2092
- props: {
2093
- type: {
2094
- type: String
2095
- }
2096
- },
2097
- setup(props) {
2098
- const services = inject("services");
2062
+ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2063
+ __name: "Resizer",
2064
+ emits: ["change"],
2065
+ setup(__props, { emit }) {
2099
2066
  const target = ref();
2100
2067
  let getso;
2101
2068
  onMounted(() => {
@@ -2105,124 +2072,220 @@ const _sfc_main$j = defineComponent({
2105
2072
  container: window,
2106
2073
  pinchOutside: true
2107
2074
  }).on("drag", (e) => {
2108
- if (!target.value || !services)
2075
+ if (!target.value)
2109
2076
  return;
2110
- let { left, right } = {
2111
- ...toRaw(services.uiService.get("columnWidth"))
2112
- };
2113
- if (props.type === "left") {
2114
- left += e.deltaX;
2115
- } else if (props.type === "right") {
2116
- right -= e.deltaX;
2117
- }
2118
- services.uiService.set("columnWidth", {
2119
- left,
2120
- right
2121
- });
2077
+ emit("change", e.deltaX);
2122
2078
  });
2123
2079
  });
2124
2080
  onUnmounted(() => {
2125
2081
  getso?.unset();
2126
2082
  });
2127
- return {
2128
- target
2083
+ return (_ctx, _cache) => {
2084
+ return openBlock(), createElementBlock("span", {
2085
+ ref_key: "target",
2086
+ ref: target,
2087
+ class: "m-editor-resizer"
2088
+ }, [
2089
+ renderSlot(_ctx.$slots, "default")
2090
+ ], 512);
2129
2091
  };
2130
2092
  }
2131
2093
  });
2132
2094
 
2133
- const _hoisted_1$9 = {
2134
- ref: "target",
2135
- class: "m-editor-resizer"
2136
- };
2137
- function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
2138
- return openBlock(), createElementBlock("span", _hoisted_1$9, [
2139
- renderSlot(_ctx.$slots, "default")
2140
- ], 512);
2141
- }
2142
- const Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$6]]);
2143
-
2144
- const _sfc_main$i = defineComponent({
2145
- components: {
2146
- AddPageBox,
2147
- Resizer
2148
- },
2095
+ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2096
+ __name: "Layout",
2149
2097
  props: {
2150
- codeOptions: {
2151
- type: Object,
2152
- default: () => ({})
2153
- }
2098
+ left: null,
2099
+ right: null,
2100
+ minLeft: { default: 1 },
2101
+ minRight: { default: 1 },
2102
+ leftClass: null,
2103
+ rightClass: null,
2104
+ centerClass: null
2154
2105
  },
2155
- setup() {
2156
- const { editorService, uiService } = inject("services") || {};
2157
- const root = computed(() => editorService?.get("root"));
2158
- return {
2159
- root,
2160
- pageLength: computed(() => editorService?.get("pageLength") || 0),
2161
- showSrc: computed(() => uiService?.get("showSrc")),
2162
- columnWidth: computed(() => uiService?.get("columnWidth")),
2163
- saveCode(value) {
2164
- try {
2165
- editorService?.set("root", eval(value));
2166
- } catch (e) {
2167
- console.error(e);
2168
- }
2106
+ emits: ["update:left", "change", "update:right"],
2107
+ setup(__props, { emit }) {
2108
+ const props = __props;
2109
+ const el = ref();
2110
+ let clientWidth = 0;
2111
+ const resizerObserver = new ResizeObserver((entries) => {
2112
+ for (const { contentRect } of entries) {
2113
+ clientWidth = contentRect.width;
2114
+ center.value = clientWidth - (props.left || 0) - (props.right || 0);
2115
+ emit("change", {
2116
+ left: props.left,
2117
+ center: center.value,
2118
+ right: props.right
2119
+ });
2169
2120
  }
2121
+ });
2122
+ onMounted(() => {
2123
+ if (el.value) {
2124
+ resizerObserver.observe(el.value);
2125
+ }
2126
+ });
2127
+ onUnmounted(() => {
2128
+ resizerObserver.disconnect();
2129
+ });
2130
+ const center = ref(0);
2131
+ const changeLeft = (deltaX) => {
2132
+ if (typeof props.left === "undefined")
2133
+ return;
2134
+ const left = Math.max(props.left + deltaX, props.minLeft) || 0;
2135
+ emit("update:left", left);
2136
+ center.value = clientWidth - left - (props.right || 0);
2137
+ emit("change", {
2138
+ left,
2139
+ center: center.value,
2140
+ right: props.right
2141
+ });
2142
+ };
2143
+ const changeRight = (deltaX) => {
2144
+ if (typeof props.right === "undefined")
2145
+ return;
2146
+ const right = Math.max(props.right - deltaX, props.minRight) || 0;
2147
+ emit("update:right", right);
2148
+ center.value = clientWidth - (props.left || 0) - right;
2149
+ emit("change", {
2150
+ left: props.left,
2151
+ center: center.value,
2152
+ right
2153
+ });
2154
+ };
2155
+ return (_ctx, _cache) => {
2156
+ return openBlock(), createElementBlock("div", {
2157
+ ref_key: "el",
2158
+ ref: el
2159
+ }, [
2160
+ typeof props.left !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2161
+ createElementVNode("div", {
2162
+ class: normalizeClass(["m-editor-layout-left", __props.leftClass]),
2163
+ style: normalizeStyle(`width: ${__props.left}px`)
2164
+ }, [
2165
+ renderSlot(_ctx.$slots, "left")
2166
+ ], 6),
2167
+ createVNode(_sfc_main$k, { onChange: changeLeft })
2168
+ ], 64)) : createCommentVNode("", true),
2169
+ createElementVNode("div", {
2170
+ class: normalizeClass(["m-editor-layout-center", __props.centerClass]),
2171
+ style: normalizeStyle(`width: ${center.value}px`)
2172
+ }, [
2173
+ renderSlot(_ctx.$slots, "center")
2174
+ ], 6),
2175
+ typeof props.right !== "undefined" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
2176
+ createVNode(_sfc_main$k, { onChange: changeRight }),
2177
+ createElementVNode("div", {
2178
+ class: normalizeClass(["m-editor-layout-right", __props.rightClass]),
2179
+ style: normalizeStyle(`width: ${__props.right}px`)
2180
+ }, [
2181
+ renderSlot(_ctx.$slots, "right")
2182
+ ], 6)
2183
+ ], 64)) : createCommentVNode("", true)
2184
+ ], 512);
2170
2185
  };
2171
2186
  }
2172
2187
  });
2173
2188
 
2174
2189
  const _hoisted_1$8 = { class: "m-editor" };
2175
- const _hoisted_2$3 = {
2176
- key: 1,
2177
- class: "m-editor-content"
2178
- };
2179
- function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
2180
- const _component_magic_code_editor = resolveComponent("magic-code-editor");
2181
- const _component_resizer = resolveComponent("resizer");
2182
- const _component_el_scrollbar = resolveComponent("el-scrollbar");
2183
- const _component_add_page_box = resolveComponent("add-page-box");
2184
- return openBlock(), createElementBlock("div", _hoisted_1$8, [
2185
- renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2186
- _ctx.showSrc ? (openBlock(), createBlock(_component_magic_code_editor, {
2187
- key: 0,
2188
- class: "m-editor-content",
2189
- "init-values": _ctx.root,
2190
- options: _ctx.codeOptions,
2191
- onSave: _ctx.saveCode
2192
- }, null, 8, ["init-values", "options", "onSave"])) : (openBlock(), createElementBlock("div", _hoisted_2$3, [
2193
- createElementVNode("div", {
2194
- class: "m-editor-framework-left",
2195
- style: normalizeStyle(`width: ${_ctx.columnWidth?.left}px`)
2196
- }, [
2197
- renderSlot(_ctx.$slots, "sidebar")
2198
- ], 4),
2199
- createVNode(_component_resizer, { type: "left" }),
2200
- _ctx.pageLength > 0 ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2201
- createElementVNode("div", {
2202
- class: "m-editor-framework-center",
2203
- style: normalizeStyle(`width: ${_ctx.columnWidth?.center}px`)
2204
- }, [
2205
- renderSlot(_ctx.$slots, "workspace")
2206
- ], 4),
2207
- createVNode(_component_resizer, { type: "right" }),
2208
- createElementVNode("div", {
2209
- class: "m-editor-framework-right",
2210
- style: normalizeStyle(`width: ${_ctx.columnWidth?.right}px`)
2190
+ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2191
+ __name: "Framework",
2192
+ props: {
2193
+ codeOptions: { default: () => ({}) }
2194
+ },
2195
+ setup(__props) {
2196
+ const DEFAULT_LEFT_COLUMN_WIDTH = 310;
2197
+ const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
2198
+ const { editorService, uiService } = inject("services") || {};
2199
+ const root = computed(() => editorService?.get("root"));
2200
+ const pageLength = computed(() => editorService?.get("pageLength") || 0);
2201
+ const showSrc = computed(() => uiService?.get("showSrc"));
2202
+ const columnWidth = ref({
2203
+ left: DEFAULT_LEFT_COLUMN_WIDTH,
2204
+ center: 0,
2205
+ right: 0
2206
+ });
2207
+ uiService?.set("columnWidth", columnWidth.value);
2208
+ watchEffect(() => {
2209
+ if (pageLength.value <= 0) {
2210
+ columnWidth.value.right = void 0;
2211
+ columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH;
2212
+ } else {
2213
+ columnWidth.value.right = columnWidth.value.right || DEFAULT_RIGHT_COLUMN_WIDTH;
2214
+ columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH;
2215
+ }
2216
+ });
2217
+ const saveCode = (value) => {
2218
+ try {
2219
+ editorService?.set("root", eval(value));
2220
+ } catch (e) {
2221
+ console.error(e);
2222
+ }
2223
+ };
2224
+ const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
2225
+ const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
2226
+ if (columnWidthCacheData) {
2227
+ try {
2228
+ const columnWidthCache = JSON.parse(columnWidthCacheData);
2229
+ columnWidth.value = columnWidthCache;
2230
+ } catch (e) {
2231
+ console.error(e);
2232
+ }
2233
+ }
2234
+ const columnWidthChange = (columnWidth2) => {
2235
+ uiService?.set("columnWidth", columnWidth2);
2236
+ globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth2));
2237
+ };
2238
+ return (_ctx, _cache) => {
2239
+ const _component_magic_code_editor = resolveComponent("magic-code-editor");
2240
+ const _component_el_scrollbar = resolveComponent("el-scrollbar");
2241
+ return openBlock(), createElementBlock("div", _hoisted_1$8, [
2242
+ renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2243
+ unref(showSrc) ? (openBlock(), createBlock(_component_magic_code_editor, {
2244
+ key: 0,
2245
+ class: "m-editor-content",
2246
+ "init-values": unref(root),
2247
+ options: __props.codeOptions,
2248
+ onSave: saveCode
2249
+ }, null, 8, ["init-values", "options"])) : (openBlock(), createBlock(_sfc_main$j, {
2250
+ key: 1,
2251
+ class: "m-editor-content",
2252
+ "left-class": "m-editor-framework-left",
2253
+ "center-class": "m-editor-framework-center",
2254
+ "right-class": "m-editor-framework-right",
2255
+ left: columnWidth.value.left,
2256
+ "onUpdate:left": _cache[0] || (_cache[0] = ($event) => columnWidth.value.left = $event),
2257
+ right: columnWidth.value.right,
2258
+ "onUpdate:right": _cache[1] || (_cache[1] = ($event) => columnWidth.value.right = $event),
2259
+ "min-left": 45,
2260
+ "min-right": 1,
2261
+ onChange: columnWidthChange
2262
+ }, createSlots({
2263
+ left: withCtx(() => [
2264
+ renderSlot(_ctx.$slots, "sidebar")
2265
+ ]),
2266
+ center: withCtx(() => [
2267
+ unref(pageLength) > 0 ? renderSlot(_ctx.$slots, "workspace", { key: 0 }) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
2268
+ createVNode(AddPageBox)
2269
+ ])
2270
+ ]),
2271
+ _: 2
2211
2272
  }, [
2212
- createVNode(_component_el_scrollbar, null, {
2213
- default: withCtx(() => [
2214
- renderSlot(_ctx.$slots, "props-panel")
2215
- ]),
2216
- _: 3
2217
- })
2218
- ], 4)
2219
- ], 64)) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
2220
- createVNode(_component_add_page_box)
2221
- ])
2222
- ]))
2223
- ]);
2224
- }
2225
- const Framework = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$5]]);
2273
+ unref(pageLength) > 0 ? {
2274
+ name: "right",
2275
+ fn: withCtx(() => [
2276
+ createVNode(_component_el_scrollbar, null, {
2277
+ default: withCtx(() => [
2278
+ renderSlot(_ctx.$slots, "props-panel")
2279
+ ]),
2280
+ _: 3
2281
+ })
2282
+ ])
2283
+ } : void 0
2284
+ ]), 1032, ["left", "right"]))
2285
+ ]);
2286
+ };
2287
+ }
2288
+ });
2226
2289
 
2227
2290
  const _hoisted_1$7 = ["src"];
2228
2291
  const _sfc_main$h = /* @__PURE__ */ defineComponent({
@@ -2464,7 +2527,13 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2464
2527
  });
2465
2528
  break;
2466
2529
  case "zoom":
2467
- config.push(...getConfig("zoom-out"), ...getConfig(`${parseInt(`${zoom.value * 100}`, 10)}%`), ...getConfig("zoom-in"), ...getConfig("scale-to-original"), ...getConfig("scale-to-fit"));
2530
+ config.push(
2531
+ ...getConfig("zoom-out"),
2532
+ ...getConfig(`${parseInt(`${zoom.value * 100}`, 10)}%`),
2533
+ ...getConfig("zoom-in"),
2534
+ ...getConfig("scale-to-original"),
2535
+ ...getConfig("scale-to-fit")
2536
+ );
2468
2537
  break;
2469
2538
  case "delete":
2470
2539
  config.push({
@@ -2529,7 +2598,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2529
2598
  className: "scale-to-fit",
2530
2599
  icon: markRaw(FullScreen),
2531
2600
  tooltip: `\u7F29\u653E\u4EE5\u9002\u5E94(${ctrl}+0)`,
2532
- handler: () => uiService?.set("zoom", uiService.calcZoom())
2601
+ handler: async () => uiService?.set("zoom", await uiService.calcZoom())
2533
2602
  });
2534
2603
  break;
2535
2604
  case "rule":
@@ -2672,11 +2741,15 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2672
2741
  const services = inject("services");
2673
2742
  const stageOptions = inject("stageOptions");
2674
2743
  const stage = computed(() => services?.editorService.get("stage"));
2675
- const list = computed(() => services?.componentListService.getList().map((group) => ({
2676
- ...group,
2677
- items: group.items.filter((item) => item.text.includes(searchText.value))
2678
- })));
2679
- const collapseValue = computed(() => Array(list.value?.length).fill(1).map((x, i) => i));
2744
+ const list = computed(
2745
+ () => services?.componentListService.getList().map((group) => ({
2746
+ ...group,
2747
+ items: group.items.filter((item) => item.text.includes(searchText.value))
2748
+ }))
2749
+ );
2750
+ const collapseValue = computed(
2751
+ () => Array(list.value?.length).fill(1).map((x, i) => i)
2752
+ );
2680
2753
  let timeout;
2681
2754
  let clientX;
2682
2755
  let clientY;
@@ -2690,11 +2763,14 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2690
2763
  const dragstartHandler = ({ text, type, data = {} }, e) => {
2691
2764
  if (e.dataTransfer) {
2692
2765
  e.dataTransfer.effectAllowed = "move";
2693
- e.dataTransfer.setData("data", serialize({
2694
- name: text,
2695
- type,
2696
- ...data
2697
- }).replace(/"(\w+)":\s/g, "$1: "));
2766
+ e.dataTransfer.setData(
2767
+ "data",
2768
+ serialize({
2769
+ name: text,
2770
+ type,
2771
+ ...data
2772
+ }).replace(/"(\w+)":\s/g, "$1: ")
2773
+ );
2698
2774
  }
2699
2775
  };
2700
2776
  const dragendHandler = () => {
@@ -2950,12 +3026,18 @@ const _sfc_main$b = defineComponent({
2950
3026
  ];
2951
3027
  }
2952
3028
  if (node.value?.items) {
2953
- return componentList.value.reduce((subMenuData, group, index) => subMenuData.concat(createMenuItems(group), index < componentList.value.length - 1 ? [
2954
- {
2955
- type: "divider",
2956
- direction: "horizontal"
2957
- }
2958
- ] : []), []) || [];
3029
+ return componentList.value.reduce(
3030
+ (subMenuData, group, index) => subMenuData.concat(
3031
+ createMenuItems(group),
3032
+ index < componentList.value.length - 1 ? [
3033
+ {
3034
+ type: "divider",
3035
+ direction: "horizontal"
3036
+ }
3037
+ ] : []
3038
+ ),
3039
+ []
3040
+ ) || [];
2959
3041
  }
2960
3042
  return [];
2961
3043
  });
@@ -3147,7 +3229,9 @@ const _sfc_main$a = defineComponent({
3147
3229
  clicked.value = !clicked.value;
3148
3230
  };
3149
3231
  const statusData = useStatus(tree, editorService);
3150
- const canHighlight = computed(() => statusData.highlightNode.value?.id !== statusData.clickNode.value?.id && !clicked.value);
3232
+ const canHighlight = computed(
3233
+ () => statusData.highlightNode.value?.id !== statusData.clickNode.value?.id && !clicked.value
3234
+ );
3151
3235
  editorService?.on("remove", () => {
3152
3236
  setTimeout(() => {
3153
3237
  tree.value?.getNode(editorService.get("node").id)?.updateChildren();
@@ -3359,9 +3443,12 @@ const _sfc_main$8 = defineComponent({
3359
3443
  },
3360
3444
  setup(props) {
3361
3445
  const activeTabName = ref(props.data?.status);
3362
- watch(() => props.data?.status, (status) => {
3363
- activeTabName.value = status || "0";
3364
- });
3446
+ watch(
3447
+ () => props.data?.status,
3448
+ (status) => {
3449
+ activeTabName.value = status || "0";
3450
+ }
3451
+ );
3365
3452
  return {
3366
3453
  activeTabName
3367
3454
  };
@@ -3421,25 +3508,29 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3421
3508
  const services = inject("services");
3422
3509
  const editorService = services?.editorService;
3423
3510
  const uiService = services?.uiService;
3424
- const pageBar = ref();
3425
3511
  const itemsContainer = ref();
3426
- const pageBarWidth = ref(0);
3427
3512
  const canScroll = ref(false);
3428
3513
  const showAddPageButton = computed(() => uiService?.get("showAddPageButton"));
3429
- const itemsContainerWidth = computed(() => pageBarWidth.value - 35 * 2 - (showAddPageButton.value ? 35 : 21));
3430
- let translateLeft = 0;
3431
- const resizeObserver = new ResizeObserver((entries) => {
3432
- for (const { contentRect } of entries) {
3433
- const { width } = contentRect;
3434
- pageBarWidth.value = width || 0;
3435
- setCanScroll();
3436
- }
3437
- });
3514
+ const itemsContainerWidth = ref(0);
3438
3515
  const setCanScroll = () => {
3439
- if (itemsContainer.value) {
3440
- canScroll.value = itemsContainer.value.scrollWidth > itemsContainerWidth.value;
3441
- }
3516
+ itemsContainerWidth.value = (pageBar.value?.clientWidth || 0) - 37 * 2 - (showAddPageButton.value ? 37 : 21);
3517
+ nextTick(() => {
3518
+ if (itemsContainer.value) {
3519
+ canScroll.value = itemsContainer.value.scrollWidth - itemsContainerWidth.value > 1;
3520
+ }
3521
+ });
3442
3522
  };
3523
+ const resizeObserver = new ResizeObserver(() => {
3524
+ setCanScroll();
3525
+ });
3526
+ const pageBar = ref();
3527
+ onMounted(() => {
3528
+ pageBar.value && resizeObserver.observe(pageBar.value);
3529
+ });
3530
+ onUnmounted(() => {
3531
+ resizeObserver.disconnect();
3532
+ });
3533
+ let translateLeft = 0;
3443
3534
  const scroll = (type) => {
3444
3535
  if (!itemsContainer.value)
3445
3536
  return;
@@ -3461,14 +3552,8 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3461
3552
  }
3462
3553
  itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
3463
3554
  };
3464
- onMounted(() => {
3465
- pageBar.value && resizeObserver.observe(pageBar.value);
3466
- });
3467
- onUnmounted(() => {
3468
- resizeObserver.disconnect();
3469
- });
3470
- const root = computed(() => editorService?.get("root"));
3471
- watch(() => root.value?.items.length, (length = 0, preLength = 0) => {
3555
+ const pageLength = computed(() => editorService?.get("pageLength"));
3556
+ watch(pageLength, (length = 0, preLength = 0) => {
3472
3557
  setTimeout(() => {
3473
3558
  setCanScroll();
3474
3559
  if (length < preLength) {
@@ -3488,7 +3573,6 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3488
3573
  editorService.add(pageConfig);
3489
3574
  };
3490
3575
  return (_ctx, _cache) => {
3491
- const _component_el_icon = resolveComponent("el-icon");
3492
3576
  return openBlock(), createElementBlock("div", {
3493
3577
  class: "m-editor-page-bar",
3494
3578
  ref_key: "pageBar",
@@ -3500,31 +3584,21 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3500
3584
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3501
3585
  onClick: addPage
3502
3586
  }, [
3503
- createVNode(_component_el_icon, null, {
3504
- default: withCtx(() => [
3505
- createVNode(unref(Plus))
3506
- ]),
3507
- _: 1
3508
- })
3587
+ createVNode(_sfc_main$h, { icon: unref(Plus) }, null, 8, ["icon"])
3509
3588
  ])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
3510
3589
  canScroll.value ? (openBlock(), createElementBlock("div", {
3511
3590
  key: 2,
3512
3591
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3513
3592
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
3514
3593
  }, [
3515
- createVNode(_component_el_icon, null, {
3516
- default: withCtx(() => [
3517
- createVNode(unref(ArrowLeftBold))
3518
- ]),
3519
- _: 1
3520
- })
3594
+ createVNode(_sfc_main$h, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
3521
3595
  ])) : createCommentVNode("", true),
3522
- unref(root) ? (openBlock(), createElementBlock("div", {
3596
+ unref(pageLength) ? (openBlock(), createElementBlock("div", {
3523
3597
  key: 3,
3524
3598
  class: "m-editor-page-bar-items",
3525
3599
  ref_key: "itemsContainer",
3526
3600
  ref: itemsContainer,
3527
- style: normalizeStyle(`width: ${unref(itemsContainerWidth)}px`)
3601
+ style: normalizeStyle(`width: ${itemsContainerWidth.value}px`)
3528
3602
  }, [
3529
3603
  renderSlot(_ctx.$slots, "default")
3530
3604
  ], 4)) : createCommentVNode("", true),
@@ -3533,12 +3607,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3533
3607
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3534
3608
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
3535
3609
  }, [
3536
- createVNode(_component_el_icon, null, {
3537
- default: withCtx(() => [
3538
- createVNode(unref(ArrowRightBold))
3539
- ]),
3540
- _: 1
3541
- })
3610
+ createVNode(_sfc_main$h, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
3542
3611
  ])) : createCommentVNode("", true)
3543
3612
  ], 512);
3544
3613
  };
@@ -3665,6 +3734,7 @@ class ScrollViewer extends EventEmitter {
3665
3734
  this.setSize();
3666
3735
  this.setScrollSize();
3667
3736
  this.resizeObserver.observe(this.container);
3737
+ this.resizeObserver.observe(this.target);
3668
3738
  }
3669
3739
  destroy() {
3670
3740
  this.resizeObserver.disconnect();
@@ -3856,12 +3926,14 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
3856
3926
  const props = __props;
3857
3927
  const container = ref();
3858
3928
  const el = ref();
3859
- const style = computed(() => `
3929
+ const style = computed(
3930
+ () => `
3860
3931
  width: ${props.width}px;
3861
3932
  height: ${props.height}px;
3862
3933
  position: absolute;
3863
3934
  margin-top: 30px;
3864
- `);
3935
+ `
3936
+ );
3865
3937
  const scrollWidth = ref(0);
3866
3938
  const scrollHeight = ref(0);
3867
3939
  let scrollViewer;
@@ -3883,9 +3955,12 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
3883
3955
  onUnmounted(() => {
3884
3956
  scrollViewer.destroy();
3885
3957
  });
3886
- watch(() => props.zoom, () => {
3887
- scrollViewer.setZoom(props.zoom);
3888
- });
3958
+ watch(
3959
+ () => props.zoom,
3960
+ () => {
3961
+ scrollViewer.setZoom(props.zoom);
3962
+ }
3963
+ );
3889
3964
  const vOffset = ref(0);
3890
3965
  const vScrollHandler = (delta) => {
3891
3966
  vOffset.value += delta;
@@ -4057,14 +4132,20 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
4057
4132
  },
4058
4133
  ...stageContentMenu
4059
4134
  ]);
4060
- watch(parent, async () => {
4061
- if (!parent.value || !editorService)
4062
- return canCenter.value = false;
4063
- const layout = await editorService.getLayout(parent.value);
4064
- const isLayoutConform = [Layout.ABSOLUTE, Layout.FIXED].includes(layout);
4065
- const isTypeConform = nodes.value?.every((selectedNode) => ![NodeType.ROOT, NodeType.PAGE, "pop"].includes(`${selectedNode?.type}`));
4066
- canCenter.value = isLayoutConform && !!isTypeConform;
4067
- }, { immediate: true });
4135
+ watch(
4136
+ parent,
4137
+ async () => {
4138
+ if (!parent.value || !editorService)
4139
+ return canCenter.value = false;
4140
+ const layout = await editorService.getLayout(parent.value);
4141
+ const isLayoutConform = [Layout.ABSOLUTE, Layout.FIXED].includes(layout);
4142
+ const isTypeConform = nodes.value?.every(
4143
+ (selectedNode) => ![NodeType.ROOT, NodeType.PAGE, "pop"].includes(`${selectedNode?.type}`)
4144
+ );
4145
+ canCenter.value = isLayoutConform && !!isTypeConform;
4146
+ },
4147
+ { immediate: true }
4148
+ );
4068
4149
  const show = async (e) => {
4069
4150
  menu.value?.show(e);
4070
4151
  const data = await storageService.getItem(COPY_STORAGE_KEY);
@@ -4317,9 +4398,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4317
4398
  }).keydown([ctrl, "numpad-"], (e) => {
4318
4399
  e.inputEvent.preventDefault();
4319
4400
  services?.uiService.zoom(-0.1);
4320
- }).keydown([ctrl, "0"], (e) => {
4401
+ }).keydown([ctrl, "0"], async (e) => {
4321
4402
  e.inputEvent.preventDefault();
4322
- services?.uiService.set("zoom", services.uiService.calcZoom());
4403
+ services?.uiService.set("zoom", await services.uiService.calcZoom());
4323
4404
  }).keydown([ctrl, "1"], (e) => {
4324
4405
  e.inputEvent.preventDefault();
4325
4406
  services?.uiService.set("zoom", 1);
@@ -4333,7 +4414,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4333
4414
  return (_ctx, _cache) => {
4334
4415
  return openBlock(), createElementBlock("div", {
4335
4416
  class: "m-editor-workspace",
4336
- tabindex: "1",
4417
+ tabindex: "-1",
4337
4418
  ref_key: "workspace",
4338
4419
  ref: workspace
4339
4420
  }, [
@@ -4384,7 +4465,7 @@ const _sfc_main = defineComponent({
4384
4465
  Sidebar,
4385
4466
  Workspace: _sfc_main$1,
4386
4467
  PropsPanel: _sfc_main$e,
4387
- Framework
4468
+ Framework: _sfc_main$i
4388
4469
  },
4389
4470
  props: {
4390
4471
  modelValue: {
@@ -4477,37 +4558,64 @@ const _sfc_main = defineComponent({
4477
4558
  }
4478
4559
  emit("update:modelValue", toRaw(editorService.get("root")));
4479
4560
  });
4480
- watch(() => props.modelValue, (modelValue) => editorService.set("root", modelValue), {
4481
- immediate: true
4482
- });
4483
- watch(() => props.componentGroupList, (componentGroupList) => componentListService.setList(componentGroupList), {
4484
- immediate: true
4485
- });
4486
- watch(() => props.propsConfigs, (configs) => propsService.setPropsConfigs(configs), {
4487
- immediate: true
4488
- });
4489
- watch(() => props.propsValues, (values) => propsService.setPropsValues(values), {
4490
- immediate: true
4491
- });
4492
- watch(() => props.eventMethodList, (eventMethodList) => {
4493
- const eventsList = {};
4494
- const methodsList = {};
4495
- Object.keys(eventMethodList).forEach((type) => {
4496
- eventsList[type] = eventMethodList[type].events;
4497
- methodsList[type] = eventMethodList[type].methods;
4498
- });
4499
- eventsService.setEvents(eventsList);
4500
- eventsService.setMethods(methodsList);
4501
- }, {
4502
- immediate: true
4503
- });
4504
- watch(() => props.defaultSelected, (defaultSelected) => defaultSelected && editorService.select(defaultSelected), {
4505
- immediate: true
4506
- });
4507
- watch(() => props.stageRect, (stageRect) => stageRect && uiService.set("stageRect", stageRect), {
4508
- immediate: true
4509
- });
4510
- uiService.initColumnWidth();
4561
+ watch(
4562
+ () => props.modelValue,
4563
+ (modelValue) => editorService.set("root", modelValue),
4564
+ {
4565
+ immediate: true
4566
+ }
4567
+ );
4568
+ watch(
4569
+ () => props.componentGroupList,
4570
+ (componentGroupList) => componentListService.setList(componentGroupList),
4571
+ {
4572
+ immediate: true
4573
+ }
4574
+ );
4575
+ watch(
4576
+ () => props.propsConfigs,
4577
+ (configs) => propsService.setPropsConfigs(configs),
4578
+ {
4579
+ immediate: true
4580
+ }
4581
+ );
4582
+ watch(
4583
+ () => props.propsValues,
4584
+ (values) => propsService.setPropsValues(values),
4585
+ {
4586
+ immediate: true
4587
+ }
4588
+ );
4589
+ watch(
4590
+ () => props.eventMethodList,
4591
+ (eventMethodList) => {
4592
+ const eventsList = {};
4593
+ const methodsList = {};
4594
+ Object.keys(eventMethodList).forEach((type) => {
4595
+ eventsList[type] = eventMethodList[type].events;
4596
+ methodsList[type] = eventMethodList[type].methods;
4597
+ });
4598
+ eventsService.setEvents(eventsList);
4599
+ eventsService.setMethods(methodsList);
4600
+ },
4601
+ {
4602
+ immediate: true
4603
+ }
4604
+ );
4605
+ watch(
4606
+ () => props.defaultSelected,
4607
+ (defaultSelected) => defaultSelected && editorService.select(defaultSelected),
4608
+ {
4609
+ immediate: true
4610
+ }
4611
+ );
4612
+ watch(
4613
+ () => props.stageRect,
4614
+ (stageRect) => stageRect && uiService.set("stageRect", stageRect),
4615
+ {
4616
+ immediate: true
4617
+ }
4618
+ );
4511
4619
  onUnmounted(() => {
4512
4620
  editorService.destroy();
4513
4621
  historyService.destroy();
@@ -4528,18 +4636,21 @@ const _sfc_main = defineComponent({
4528
4636
  provide("services", services);
4529
4637
  provide("layerContentMenu", props.layerContentMenu);
4530
4638
  provide("stageContentMenu", props.stageContentMenu);
4531
- provide("stageOptions", reactive({
4532
- runtimeUrl: props.runtimeUrl,
4533
- autoScrollIntoView: props.autoScrollIntoView,
4534
- render: props.render,
4535
- moveableOptions: props.moveableOptions,
4536
- canSelect: props.canSelect,
4537
- updateDragEl: props.updateDragEl,
4538
- isContainer: props.isContainer,
4539
- containerHighlightClassName: props.containerHighlightClassName,
4540
- containerHighlightDuration: props.containerHighlightDuration,
4541
- containerHighlightType: props.containerHighlightType
4542
- }));
4639
+ provide(
4640
+ "stageOptions",
4641
+ reactive({
4642
+ runtimeUrl: props.runtimeUrl,
4643
+ autoScrollIntoView: props.autoScrollIntoView,
4644
+ render: props.render,
4645
+ moveableOptions: props.moveableOptions,
4646
+ canSelect: props.canSelect,
4647
+ updateDragEl: props.updateDragEl,
4648
+ isContainer: props.isContainer,
4649
+ containerHighlightClassName: props.containerHighlightClassName,
4650
+ containerHighlightDuration: props.containerHighlightDuration,
4651
+ containerHighlightType: props.containerHighlightType
4652
+ })
4653
+ );
4543
4654
  return services;
4544
4655
  }
4545
4656
  });
@@ -4620,9 +4731,9 @@ const index = {
4620
4731
  app.config.globalProperties.$TMAGIC_EDITOR = option;
4621
4732
  setConfig(option);
4622
4733
  app.component(Editor.name, Editor);
4623
- app.component("m-fields-ui-select", _sfc_main$m);
4624
- app.component(CodeLink.name, CodeLink);
4625
- app.component(Code.name, Code);
4734
+ app.component("m-fields-ui-select", _sfc_main$n);
4735
+ app.component("m-fields-code-link", _sfc_main$o);
4736
+ app.component("m-fields-vs-code", _sfc_main$p);
4626
4737
  app.component(CodeEditor.name, CodeEditor);
4627
4738
  }
4628
4739
  };