@tmagic/editor 1.0.6 → 1.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('@element-plus/icons'), require('lodash-es'), require('monaco-editor'), require('@tmagic/schema'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('gesto'), require('element-plus'), require('keycon'), require('@tmagic/stage')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', '@element-plus/icons', 'lodash-es', 'monaco-editor', '@tmagic/schema', '@tmagic/utils', 'events', '@tmagic/core', 'gesto', 'element-plus', 'keycon', '@tmagic/stage'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.Vue, global.serialize, global.icons, global.lodashEs, global.monaco, global.schema, global.utils, global.events, global.core, global.Gesto, global.ElementPlus, global.KeyController, global.StageCore));
5
- })(this, (function (exports, vue, serialize, icons, lodashEs, monaco, schema, utils, events, core, Gesto, elementPlus, KeyController, StageCore) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('@element-plus/icons-vue'), require('lodash-es'), require('monaco-editor'), require('@tmagic/stage'), require('@tmagic/schema'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('gesto'), require('element-plus'), require('keycon')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', '@element-plus/icons-vue', 'lodash-es', 'monaco-editor', '@tmagic/stage', '@tmagic/schema', '@tmagic/utils', 'events', '@tmagic/core', 'gesto', 'element-plus', 'keycon'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.Vue, global.serialize, global.iconsVue, global.lodashEs, global.monaco, global.StageCore, global.schema, global.utils, global.events, global.core, global.Gesto, global.ElementPlus, global.KeyController));
5
+ })(this, (function (exports, vue, serialize, iconsVue, lodashEs, monaco, StageCore, schema, utils, events, core, Gesto, elementPlus, KeyController) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -26,9 +26,9 @@
26
26
 
27
27
  var serialize__default = /*#__PURE__*/_interopDefaultLegacy(serialize);
28
28
  var monaco__namespace = /*#__PURE__*/_interopNamespace(monaco);
29
+ var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
29
30
  var Gesto__default = /*#__PURE__*/_interopDefaultLegacy(Gesto);
30
31
  var KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
31
- var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
32
32
 
33
33
  if (typeof global === "undefined") {
34
34
  window.global = window;
@@ -179,9 +179,9 @@
179
179
  }
180
180
  };
181
181
  return {
182
- Delete: vue.markRaw(icons.Delete),
183
- Pointer: vue.markRaw(icons.Pointer),
184
- Close: vue.markRaw(icons.Close),
182
+ Delete: vue.markRaw(iconsVue.Delete),
183
+ Pointer: vue.markRaw(iconsVue.Pointer),
184
+ Close: vue.markRaw(iconsVue.Close),
185
185
  val,
186
186
  uiSelectMode,
187
187
  toName: vue.computed(() => {
@@ -768,56 +768,50 @@
768
768
  const items = parent?.items || [];
769
769
  return items.findIndex((item) => `${item.id}` === `${node.id}`);
770
770
  };
771
- const toRelative = (node) => {
772
- node.style = {
773
- ...node.style || {},
774
- position: "relative",
775
- top: 0,
776
- left: 0
777
- };
778
- return node;
779
- };
780
- const setTop2Middle = (node, parentNode, stage) => {
781
- const style = node.style || {};
771
+ const getRelativeStyle = (style = {}) => ({
772
+ ...style,
773
+ position: "relative",
774
+ top: 0,
775
+ left: 0
776
+ });
777
+ const getMiddleTop = (style = {}, parentNode, stage) => {
782
778
  let height = style.height || 0;
783
779
  if (!stage || typeof style.top !== "undefined" || !parentNode.style)
784
- return style;
780
+ return style.top;
785
781
  if (!utils.isNumber(height)) {
786
782
  height = 0;
787
783
  }
788
784
  const { height: parentHeight } = parentNode.style;
789
785
  if (utils.isPage(parentNode)) {
790
786
  const { scrollTop = 0, wrapperHeight } = stage.mask;
791
- style.top = (wrapperHeight - height) / 2 + scrollTop;
792
- } else {
793
- style.top = (parentHeight - height) / 2;
787
+ return (wrapperHeight - height) / 2 + scrollTop;
794
788
  }
795
- return style;
789
+ return (parentHeight - height) / 2;
796
790
  };
797
- const initPosition = (node, layout, parentNode, stage) => {
791
+ const getInitPositionStyle = (style = {}, layout, parentNode, stage) => {
798
792
  if (layout === Layout.ABSOLUTE) {
799
- node.style = {
793
+ return {
794
+ ...style,
800
795
  position: "absolute",
801
- ...setTop2Middle(node, parentNode, stage)
796
+ top: getMiddleTop(style, parentNode, stage)
802
797
  };
803
- return node;
804
798
  }
805
799
  if (layout === Layout.RELATIVE) {
806
- return toRelative(node);
800
+ return getRelativeStyle(style);
807
801
  }
808
- return node;
802
+ return style;
809
803
  };
810
804
  const setLayout = (node, layout) => {
811
805
  node.items?.forEach((child) => {
812
806
  if (utils.isPop(child))
813
807
  return;
814
- child.style = child.style || {};
815
- if (child.style.position === "fixed")
808
+ const style = child.style || {};
809
+ if (style.position === "fixed")
816
810
  return;
817
811
  if (layout !== Layout.RELATIVE) {
818
- child.style.position = "absolute";
812
+ style.position = "absolute";
819
813
  } else {
820
- toRelative(child);
814
+ child.style = getRelativeStyle(style);
821
815
  child.style.right = "auto";
822
816
  child.style.bottom = "auto";
823
817
  }
@@ -834,11 +828,10 @@
834
828
  offset.left = offset.left + globalThis.parseFloat(value.style?.left || 0);
835
829
  offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
836
830
  });
837
- node.style = {
831
+ return {
838
832
  ...node.style || {},
839
833
  ...offset
840
834
  };
841
- return node;
842
835
  };
843
836
  const Fixed2Other = async (node, root, getLayout) => {
844
837
  const path = utils.getNodePath(node.id, root.items);
@@ -853,20 +846,20 @@
853
846
  offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
854
847
  offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
855
848
  });
849
+ const style = node.style || {};
856
850
  const parent = path.pop();
857
851
  if (!parent) {
858
- return toRelative(node);
852
+ return getRelativeStyle(style);
859
853
  }
860
854
  const layout = await getLayout(parent);
861
855
  if (layout !== Layout.RELATIVE) {
862
- node.style = {
863
- ...node.style || {},
856
+ return {
857
+ ...style,
864
858
  ...offset,
865
859
  position: "absolute"
866
860
  };
867
- return node;
868
861
  }
869
- return toRelative(node);
862
+ return getRelativeStyle(style);
870
863
  };
871
864
  const getGuideLineFromCache = (key) => {
872
865
  if (!key)
@@ -881,6 +874,16 @@
881
874
  }
882
875
  return [];
883
876
  };
877
+ const fixNodeLeft = (config, parent, doc) => {
878
+ if (!doc || !config.style || !utils.isNumber(config.style.left))
879
+ return config.style?.left;
880
+ const el = doc.getElementById(`${config.id}`);
881
+ const parentEl = doc.getElementById(`${parent.id}`);
882
+ if (el && parentEl && el.offsetWidth + config.style?.left > parentEl.offsetWidth) {
883
+ return parentEl.offsetWidth - el.offsetWidth;
884
+ }
885
+ return config.style.left;
886
+ };
884
887
 
885
888
  const log = (...args) => {
886
889
  };
@@ -906,6 +909,7 @@
906
909
  "paste",
907
910
  "alignCenter",
908
911
  "moveLayer",
912
+ "moveToContainer",
909
913
  "move",
910
914
  "undo",
911
915
  "redo",
@@ -1045,13 +1049,22 @@
1045
1049
  if (!parentNode)
1046
1050
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
1047
1051
  const layout = await this.getLayout(vue.toRaw(parentNode), addNode);
1048
- const newNode = initPosition({ ...vue.toRaw(await propsService.getPropsValue(type, config2)) }, layout, parentNode, this.get("stage"));
1052
+ const newNode = { ...vue.toRaw(await propsService.getPropsValue(type, config2)) };
1053
+ newNode.style = getInitPositionStyle(newNode.style, layout, parentNode, this.get("stage"));
1049
1054
  if ((parentNode?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && newNode.type !== schema.NodeType.PAGE) {
1050
1055
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
1051
1056
  }
1052
1057
  parentNode?.items?.push(newNode);
1053
1058
  const stage = this.get("stage");
1054
- await stage?.add({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(this.get("root")) });
1059
+ const root = this.get("root");
1060
+ await stage?.add({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(root) });
1061
+ if (layout === Layout.ABSOLUTE) {
1062
+ const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
1063
+ if (typeof fixedLeft !== "undefined") {
1064
+ newNode.style.left = fixedLeft;
1065
+ await stage?.update({ config: lodashEs.cloneDeep(newNode), root: lodashEs.cloneDeep(root) });
1066
+ }
1067
+ }
1055
1068
  await this.select(newNode);
1056
1069
  this.addModifiedNodeId(newNode.id);
1057
1070
  if (!isPage2) {
@@ -1078,7 +1091,7 @@
1078
1091
  throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
1079
1092
  parent.items?.splice(index, 1);
1080
1093
  const stage = this.get("stage");
1081
- stage?.remove({ id: node.id, root: this.get("root") });
1094
+ stage?.remove({ id: node.id, root: lodashEs.cloneDeep(this.get("root")) });
1082
1095
  if (node.type === schema.NodeType.PAGE) {
1083
1096
  this.state.pageLength -= 1;
1084
1097
  if (root.items[0]) {
@@ -1139,7 +1152,7 @@
1139
1152
  if (`${newConfig.id}` === `${this.get("node").id}`) {
1140
1153
  this.set("node", newConfig);
1141
1154
  }
1142
- this.get("stage")?.update({ config: lodashEs.cloneDeep(newConfig), root: this.get("root") });
1155
+ this.get("stage")?.update({ config: lodashEs.cloneDeep(newConfig), root: lodashEs.cloneDeep(this.get("root")) });
1143
1156
  if (newConfig.type === schema.NodeType.PAGE) {
1144
1157
  this.set("page", newConfig);
1145
1158
  }
@@ -1158,7 +1171,7 @@
1158
1171
  parent.items.splice(index2, 0, ...parent.items.splice(index1, 1));
1159
1172
  await this.update(parent);
1160
1173
  await this.select(node);
1161
- this.get("stage")?.update({ config: lodashEs.cloneDeep(node), root: this.get("root") });
1174
+ this.get("stage")?.update({ config: lodashEs.cloneDeep(node), root: lodashEs.cloneDeep(this.get("root")) });
1162
1175
  this.addModifiedNodeId(parent.id);
1163
1176
  this.pushHistoryState();
1164
1177
  }
@@ -1210,7 +1223,10 @@
1210
1223
  node.style.left = (parent.style.width - node.style.width) / 2;
1211
1224
  }
1212
1225
  await this.update(node);
1213
- this.get("stage")?.update({ config: lodashEs.cloneDeep(vue.toRaw(node)), root: this.get("root") });
1226
+ this.get("stage")?.update({
1227
+ config: lodashEs.cloneDeep(vue.toRaw(node)),
1228
+ root: lodashEs.cloneDeep(this.get("root"))
1229
+ });
1214
1230
  this.addModifiedNodeId(config2.id);
1215
1231
  this.pushHistoryState();
1216
1232
  return config2;
@@ -1227,7 +1243,37 @@
1227
1243
  } else {
1228
1244
  brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
1229
1245
  }
1230
- this.get("stage")?.update({ config: lodashEs.cloneDeep(vue.toRaw(parent)), root: this.get("root") });
1246
+ this.get("stage")?.update({
1247
+ config: lodashEs.cloneDeep(vue.toRaw(parent)),
1248
+ root: lodashEs.cloneDeep(this.get("root"))
1249
+ });
1250
+ }
1251
+ async moveToContainer(config2, targetId) {
1252
+ const { node, parent } = this.getNodeInfo(config2.id, false);
1253
+ const target = this.getNodeById(targetId, false);
1254
+ const stage = this.get("stage");
1255
+ if (node && parent && stage) {
1256
+ const root = lodashEs.cloneDeep(this.get("root"));
1257
+ const index = getNodeIndex(node, parent);
1258
+ parent.items?.splice(index, 1);
1259
+ await stage.remove({ id: node.id, root });
1260
+ const layout = await this.getLayout(target);
1261
+ const newConfig = lodashEs.mergeWith(lodashEs.cloneDeep(node), config2, (objValue, srcValue) => {
1262
+ if (Array.isArray(srcValue)) {
1263
+ return srcValue;
1264
+ }
1265
+ });
1266
+ newConfig.style = getInitPositionStyle(newConfig.style, layout, target, stage);
1267
+ target.items.push(newConfig);
1268
+ await stage.select(targetId);
1269
+ await stage.update({ config: lodashEs.cloneDeep(target), root });
1270
+ await this.select(newConfig);
1271
+ stage.select(newConfig.id);
1272
+ this.addModifiedNodeId(target.id);
1273
+ this.addModifiedNodeId(parent.id);
1274
+ this.pushHistoryState();
1275
+ return newConfig;
1276
+ }
1231
1277
  }
1232
1278
  async undo() {
1233
1279
  const value = historyService.undo();
@@ -1299,12 +1345,12 @@
1299
1345
  }, 0);
1300
1346
  }
1301
1347
  async toggleFixedPosition(dist, src, root) {
1302
- let newConfig = lodashEs.cloneDeep(dist);
1348
+ const newConfig = lodashEs.cloneDeep(dist);
1303
1349
  if (!utils.isPop(src) && newConfig.style?.position) {
1304
1350
  if (isFixed(newConfig) && !isFixed(src)) {
1305
- newConfig = change2Fixed(newConfig, root);
1351
+ newConfig.style = change2Fixed(newConfig, root);
1306
1352
  } else if (!isFixed(newConfig) && isFixed(src)) {
1307
- newConfig = await Fixed2Other(newConfig, root, this.getLayout);
1353
+ newConfig.style = await Fixed2Other(newConfig, root, this.getLayout);
1308
1354
  }
1309
1355
  }
1310
1356
  return newConfig;
@@ -1597,7 +1643,7 @@
1597
1643
  };
1598
1644
 
1599
1645
  const _sfc_main$i = vue.defineComponent({
1600
- components: { Plus: icons.Plus },
1646
+ components: { Plus: iconsVue.Plus },
1601
1647
  setup() {
1602
1648
  const services = vue.inject("services");
1603
1649
  return {
@@ -1777,7 +1823,7 @@
1777
1823
 
1778
1824
  const _sfc_main$f = vue.defineComponent({
1779
1825
  name: "m-icon",
1780
- components: { Edit: icons.Edit },
1826
+ components: { Edit: iconsVue.Edit },
1781
1827
  props: {
1782
1828
  icon: {
1783
1829
  type: [String, Object]
@@ -1814,7 +1860,7 @@
1814
1860
  var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
1815
1861
 
1816
1862
  const _sfc_main$e = vue.defineComponent({
1817
- components: { MIcon, ArrowDown: icons.ArrowDown },
1863
+ components: { MIcon, ArrowDown: iconsVue.ArrowDown },
1818
1864
  props: {
1819
1865
  data: {
1820
1866
  type: [Object, String],
@@ -1853,7 +1899,7 @@
1853
1899
  case "delete":
1854
1900
  return {
1855
1901
  type: "button",
1856
- icon: vue.markRaw(icons.Delete),
1902
+ icon: vue.markRaw(iconsVue.Delete),
1857
1903
  tooltip: "\u522A\u9664",
1858
1904
  disabled: () => services?.editorService.get("node")?.type === schema.NodeType.PAGE,
1859
1905
  handler: () => services?.editorService.remove(services?.editorService.get("node"))
@@ -1861,7 +1907,7 @@
1861
1907
  case "undo":
1862
1908
  return {
1863
1909
  type: "button",
1864
- icon: vue.markRaw(icons.Back),
1910
+ icon: vue.markRaw(iconsVue.Back),
1865
1911
  tooltip: "\u540E\u9000",
1866
1912
  disabled: () => !services?.historyService.state.canUndo,
1867
1913
  handler: () => services?.editorService.undo()
@@ -1869,7 +1915,7 @@
1869
1915
  case "redo":
1870
1916
  return {
1871
1917
  type: "button",
1872
- icon: vue.markRaw(icons.Right),
1918
+ icon: vue.markRaw(iconsVue.Right),
1873
1919
  tooltip: "\u524D\u8FDB",
1874
1920
  disabled: () => !services?.historyService.state.canRedo,
1875
1921
  handler: () => services?.editorService.redo()
@@ -1877,28 +1923,28 @@
1877
1923
  case "zoom-in":
1878
1924
  return {
1879
1925
  type: "button",
1880
- icon: vue.markRaw(icons.ZoomIn),
1926
+ icon: vue.markRaw(iconsVue.ZoomIn),
1881
1927
  tooltip: "\u653E\u5927",
1882
1928
  handler: zoomInHandler
1883
1929
  };
1884
1930
  case "zoom-out":
1885
1931
  return {
1886
1932
  type: "button",
1887
- icon: vue.markRaw(icons.ZoomOut),
1933
+ icon: vue.markRaw(iconsVue.ZoomOut),
1888
1934
  tooltip: "\u7E2E\u5C0F",
1889
1935
  handler: zoomOutHandler
1890
1936
  };
1891
1937
  case "rule":
1892
1938
  return {
1893
1939
  type: "button",
1894
- icon: vue.markRaw(icons.ScaleToOriginal),
1940
+ icon: vue.markRaw(iconsVue.ScaleToOriginal),
1895
1941
  tooltip: showRule.value ? "\u9690\u85CF\u6807\u5C3A" : "\u663E\u793A\u6807\u5C3A",
1896
1942
  handler: () => uiService?.set("showRule", !showRule.value)
1897
1943
  };
1898
1944
  case "guides":
1899
1945
  return {
1900
1946
  type: "button",
1901
- icon: vue.markRaw(icons.Grid),
1947
+ icon: vue.markRaw(iconsVue.Grid),
1902
1948
  tooltip: showGuides.value ? "\u9690\u85CF\u53C2\u8003\u7EBF" : "\u663E\u793A\u53C2\u8003\u7EBF",
1903
1949
  handler: () => uiService?.set("showGuides", !showGuides.value)
1904
1950
  };
@@ -1927,8 +1973,8 @@
1927
1973
  }
1928
1974
  };
1929
1975
  return {
1930
- ZoomIn: vue.markRaw(icons.ZoomIn),
1931
- ZoomOut: vue.markRaw(icons.ZoomOut),
1976
+ ZoomIn: vue.markRaw(iconsVue.ZoomIn),
1977
+ ZoomOut: vue.markRaw(iconsVue.ZoomOut),
1932
1978
  item,
1933
1979
  zoom,
1934
1980
  disabled,
@@ -2208,11 +2254,16 @@
2208
2254
  setup() {
2209
2255
  const searchText = vue.ref("");
2210
2256
  const services = vue.inject("services");
2257
+ const stageOptions = vue.inject("stageOptions");
2258
+ const stage = vue.computed(() => services?.editorService.get("stage"));
2211
2259
  const list = vue.computed(() => services?.componentListService.getList().map((group) => ({
2212
2260
  ...group,
2213
2261
  items: group.items.filter((item) => item.text.includes(searchText.value))
2214
2262
  })));
2215
2263
  const collapseValue = vue.computed(() => Array(list.value?.length).fill(1).map((x, i) => i));
2264
+ let timeout;
2265
+ let clientX;
2266
+ let clientY;
2216
2267
  return {
2217
2268
  searchText,
2218
2269
  collapseValue,
@@ -2233,6 +2284,43 @@
2233
2284
  ...data
2234
2285
  }).replace(/"(\w+)":\s/g, "$1: "));
2235
2286
  }
2287
+ },
2288
+ dragendHandler() {
2289
+ if (timeout) {
2290
+ globalThis.clearTimeout(timeout);
2291
+ timeout = void 0;
2292
+ }
2293
+ const doc = stage.value?.renderer.contentWindow?.document;
2294
+ if (doc && stageOptions) {
2295
+ utils.removeClassNameByClassName(doc, stageOptions.containerHighlightClassName);
2296
+ }
2297
+ clientX = 0;
2298
+ clientY = 0;
2299
+ },
2300
+ dragHandler(e) {
2301
+ if (e.clientX !== clientX || e.clientY !== clientY) {
2302
+ clientX = e.clientX;
2303
+ clientY = e.clientY;
2304
+ if (timeout) {
2305
+ globalThis.clearTimeout(timeout);
2306
+ timeout = void 0;
2307
+ }
2308
+ return;
2309
+ }
2310
+ if (timeout)
2311
+ return;
2312
+ timeout = globalThis.setTimeout(async () => {
2313
+ if (!stageOptions || !stage.value)
2314
+ return;
2315
+ const doc = stage.value.renderer.contentWindow?.document;
2316
+ const els = stage.value.getElementsFromPoint(e);
2317
+ for (const el of els) {
2318
+ if (doc && !el.id.startsWith(StageCore.GHOST_EL_ID_PREFIX) && await stageOptions.isContainer(el)) {
2319
+ utils.addClassName(el, doc, stageOptions?.containerHighlightClassName);
2320
+ break;
2321
+ }
2322
+ }
2323
+ }, stageOptions?.containerHighlightDuration);
2236
2324
  }
2237
2325
  };
2238
2326
  }
@@ -2280,7 +2368,9 @@
2280
2368
  draggable: "true",
2281
2369
  key: item.type,
2282
2370
  onClick: ($event) => _ctx.appendComponent(item),
2283
- onDragstart: ($event) => _ctx.dragstartHandler(item, $event)
2371
+ onDragstart: ($event) => _ctx.dragstartHandler(item, $event),
2372
+ onDragend: _cache[1] || (_cache[1] = (...args) => _ctx.dragendHandler && _ctx.dragendHandler(...args)),
2373
+ onDrag: _cache[2] || (_cache[2] = (...args) => _ctx.dragHandler && _ctx.dragHandler(...args))
2284
2374
  }, [
2285
2375
  vue.createVNode(_component_m_icon, {
2286
2376
  icon: item.icon
@@ -2461,7 +2551,7 @@
2461
2551
  {
2462
2552
  text: "\u6807\u7B7E\u9875",
2463
2553
  type: "button",
2464
- icon: icons.Files,
2554
+ icon: iconsVue.Files,
2465
2555
  handler: () => {
2466
2556
  services?.editorService.add({
2467
2557
  type: "tab-pane"
@@ -2486,14 +2576,14 @@
2486
2576
  {
2487
2577
  type: "button",
2488
2578
  text: "\u65B0\u589E",
2489
- icon: vue.markRaw(icons.Plus),
2579
+ icon: vue.markRaw(iconsVue.Plus),
2490
2580
  display: () => node.value?.items,
2491
2581
  items: getSubMenuData.value
2492
2582
  },
2493
2583
  {
2494
2584
  type: "button",
2495
2585
  text: "\u590D\u5236",
2496
- icon: vue.markRaw(icons.DocumentCopy),
2586
+ icon: vue.markRaw(iconsVue.DocumentCopy),
2497
2587
  display: () => !isRoot.value,
2498
2588
  handler: () => {
2499
2589
  node.value && services?.editorService.copy(node.value);
@@ -2502,7 +2592,7 @@
2502
2592
  {
2503
2593
  type: "button",
2504
2594
  text: "\u5220\u9664",
2505
- icon: vue.markRaw(icons.Delete),
2595
+ icon: vue.markRaw(iconsVue.Delete),
2506
2596
  display: () => !isRoot.value && !isPage.value,
2507
2597
  handler: () => {
2508
2598
  node.value && services?.editorService.remove(node.value);
@@ -2745,7 +2835,7 @@
2745
2835
  case "component-list":
2746
2836
  return {
2747
2837
  type: "component",
2748
- icon: icons.Coin,
2838
+ icon: iconsVue.Coin,
2749
2839
  text: "\u7EC4\u4EF6",
2750
2840
  component: ComponentListPanel,
2751
2841
  slots: {}
@@ -2753,7 +2843,7 @@
2753
2843
  case "layer":
2754
2844
  return {
2755
2845
  type: "component",
2756
- icon: icons.Files,
2846
+ icon: iconsVue.Files,
2757
2847
  text: "\u5DF2\u9009\u7EC4\u4EF6",
2758
2848
  component: LayerPanel,
2759
2849
  slots: {}
@@ -2938,14 +3028,14 @@
2938
3028
  };
2939
3029
  };
2940
3030
  const _sfc_main$5 = vue.defineComponent({
2941
- components: { ArrowLeftBold: icons.ArrowLeftBold, ArrowRightBold: icons.ArrowRightBold, CaretBottom: icons.CaretBottom, Plus: icons.Plus, ToolButton },
3031
+ components: { ArrowLeftBold: iconsVue.ArrowLeftBold, ArrowRightBold: iconsVue.ArrowRightBold, CaretBottom: iconsVue.CaretBottom, Plus: iconsVue.Plus, ToolButton },
2942
3032
  setup() {
2943
3033
  const services = vue.inject("services");
2944
3034
  const editorService = services?.editorService;
2945
3035
  const root = vue.computed(() => editorService?.get("root"));
2946
3036
  return {
2947
- Delete: vue.markRaw(icons.Delete),
2948
- DocumentCopy: vue.markRaw(icons.DocumentCopy),
3037
+ Delete: vue.markRaw(iconsVue.Delete),
3038
+ DocumentCopy: vue.markRaw(iconsVue.DocumentCopy),
2949
3039
  ...useScroll(root),
2950
3040
  root,
2951
3041
  page: vue.computed(() => editorService?.get("page")),
@@ -3350,7 +3440,7 @@
3350
3440
  {
3351
3441
  type: "button",
3352
3442
  text: "\u590D\u5236",
3353
- icon: vue.markRaw(icons.DocumentCopy),
3443
+ icon: vue.markRaw(iconsVue.DocumentCopy),
3354
3444
  handler: () => {
3355
3445
  node.value && editorService?.copy(node.value);
3356
3446
  canPaste.value = true;
@@ -3383,7 +3473,7 @@
3383
3473
  {
3384
3474
  type: "button",
3385
3475
  text: "\u4E0A\u79FB\u4E00\u5C42",
3386
- icon: vue.markRaw(icons.Top),
3476
+ icon: vue.markRaw(iconsVue.Top),
3387
3477
  display: () => !isPage.value,
3388
3478
  handler: () => {
3389
3479
  editorService?.moveLayer(1);
@@ -3392,7 +3482,7 @@
3392
3482
  {
3393
3483
  type: "button",
3394
3484
  text: "\u4E0B\u79FB\u4E00\u5C42",
3395
- icon: vue.markRaw(icons.Bottom),
3485
+ icon: vue.markRaw(iconsVue.Bottom),
3396
3486
  display: () => !isPage.value,
3397
3487
  handler: () => {
3398
3488
  editorService?.moveLayer(-1);
@@ -3422,7 +3512,7 @@
3422
3512
  {
3423
3513
  type: "button",
3424
3514
  text: "\u5220\u9664",
3425
- icon: icons.Delete,
3515
+ icon: iconsVue.Delete,
3426
3516
  display: () => !isPage.value,
3427
3517
  handler: () => {
3428
3518
  node.value && editorService?.remove(node.value);
@@ -3489,6 +3579,9 @@
3489
3579
  runtimeUrl: stageOptions.runtimeUrl,
3490
3580
  zoom: zoom.value,
3491
3581
  autoScrollIntoView: stageOptions.autoScrollIntoView,
3582
+ isContainer: stageOptions.isContainer,
3583
+ containerHighlightClassName: stageOptions.containerHighlightClassName,
3584
+ containerHighlightDuration: stageOptions.containerHighlightDuration,
3492
3585
  canSelect: (el, event, stop) => {
3493
3586
  const elCanSelect = stageOptions.canSelect(el);
3494
3587
  if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
@@ -3513,6 +3606,10 @@
3513
3606
  services?.editorService.highlight(el.id);
3514
3607
  });
3515
3608
  stage?.on("update", (ev) => {
3609
+ if (ev.parentEl) {
3610
+ services?.editorService.moveToContainer({ id: ev.el.id, style: ev.style }, ev.parentEl.id);
3611
+ return;
3612
+ }
3516
3613
  services?.editorService.update({ id: ev.el.id, style: ev.style });
3517
3614
  });
3518
3615
  stage?.on("sort", (ev) => {
@@ -3584,20 +3681,38 @@
3584
3681
  },
3585
3682
  async dropHandler(e) {
3586
3683
  e.preventDefault();
3587
- if (e.dataTransfer && page.value && stageContainer.value && stage) {
3684
+ const doc = stage?.renderer.contentWindow?.document;
3685
+ const parentEl = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
3686
+ let parent = page.value;
3687
+ if (parentEl) {
3688
+ parent = services?.editorService.getNodeById(parentEl.id, false);
3689
+ }
3690
+ if (e.dataTransfer && parent && stageContainer.value && stage) {
3588
3691
  const config = eval(`(${e.dataTransfer.getData("data")})`);
3589
- const layout = await services?.editorService.getLayout(page.value);
3692
+ const layout = await services?.editorService.getLayout(parent);
3590
3693
  const containerRect = stageContainer.value.getBoundingClientRect();
3591
3694
  const { scrollTop, scrollLeft } = stage.mask;
3695
+ const { style = {} } = config;
3696
+ let top = 0;
3697
+ let left = 0;
3698
+ let position = "relative";
3592
3699
  if (layout === Layout.ABSOLUTE) {
3593
- config.style = {
3594
- ...config.style || {},
3595
- position: "absolute",
3596
- top: e.clientY - containerRect.top + scrollTop,
3597
- left: e.clientX - containerRect.left + scrollLeft
3598
- };
3700
+ position = "absolute";
3701
+ top = e.clientY - containerRect.top + scrollTop;
3702
+ left = e.clientX - containerRect.left + scrollLeft;
3703
+ if (parentEl && doc) {
3704
+ const { left: parentLeft, top: parentTop } = StageCore.getOffset(parentEl);
3705
+ left = left - StageCore.calcValueByFontsize(doc, parentLeft);
3706
+ top = top - StageCore.calcValueByFontsize(doc, parentTop);
3707
+ }
3599
3708
  }
3600
- services?.editorService.add(config, page.value);
3709
+ config.style = {
3710
+ ...style,
3711
+ position,
3712
+ top,
3713
+ left
3714
+ };
3715
+ services?.editorService.add(config, parent);
3601
3716
  }
3602
3717
  }
3603
3718
  };
@@ -3958,6 +4073,18 @@
3958
4073
  type: Function,
3959
4074
  default: (el) => Boolean(el.id)
3960
4075
  },
4076
+ isContainer: {
4077
+ type: Function,
4078
+ default: (el) => el.classList.contains("magic-ui-container")
4079
+ },
4080
+ containerHighlightClassName: {
4081
+ type: String,
4082
+ default: StageCore.CONTAINER_HIGHLIGHT_CLASS
4083
+ },
4084
+ containerHighlightDuration: {
4085
+ type: Number,
4086
+ default: 800
4087
+ },
3961
4088
  stageRect: {
3962
4089
  type: [String, Object]
3963
4090
  },
@@ -4024,7 +4151,10 @@
4024
4151
  render: props.render,
4025
4152
  moveableOptions: props.moveableOptions,
4026
4153
  canSelect: props.canSelect,
4027
- updateDragEl: props.updateDragEl
4154
+ updateDragEl: props.updateDragEl,
4155
+ isContainer: props.isContainer,
4156
+ containerHighlightClassName: props.containerHighlightClassName,
4157
+ containerHighlightDuration: props.containerHighlightDuration
4028
4158
  }));
4029
4159
  return services;
4030
4160
  }
@@ -4128,23 +4258,24 @@
4128
4258
  exports.error = error;
4129
4259
  exports.eventsService = eventsService;
4130
4260
  exports.fillConfig = fillConfig;
4261
+ exports.fixNodeLeft = fixNodeLeft;
4131
4262
  exports.generatePageName = generatePageName;
4132
4263
  exports.generatePageNameByApp = generatePageNameByApp;
4133
4264
  exports.getConfig = getConfig;
4134
4265
  exports.getDefaultPropsValue = getDefaultPropsValue;
4135
4266
  exports.getGuideLineFromCache = getGuideLineFromCache;
4267
+ exports.getInitPositionStyle = getInitPositionStyle;
4136
4268
  exports.getNodeIndex = getNodeIndex;
4137
4269
  exports.getPageList = getPageList;
4138
4270
  exports.getPageNameList = getPageNameList;
4271
+ exports.getRelativeStyle = getRelativeStyle;
4139
4272
  exports.historyService = historyService;
4140
4273
  exports.info = info;
4141
- exports.initPosition = initPosition;
4142
4274
  exports.isFixed = isFixed;
4143
4275
  exports.log = log;
4144
4276
  exports.propsService = propsService;
4145
4277
  exports.setConfig = setConfig;
4146
4278
  exports.setLayout = setLayout;
4147
- exports.toRelative = toRelative;
4148
4279
  exports.uiService = uiService;
4149
4280
  exports.warn = warn;
4150
4281