@tmagic/editor 1.1.0-beta.4 → 1.1.0-beta.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.
@@ -622,7 +622,15 @@ var historyService = new History();
622
622
 
623
623
  class Props extends BaseService {
624
624
  constructor() {
625
- super(["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue", "createId", "setNewItemId"]);
625
+ super([
626
+ "setPropsConfig",
627
+ "getPropsConfig",
628
+ "setPropsValue",
629
+ "getPropsValue",
630
+ "createId",
631
+ "setNewItemId",
632
+ "getDefaultPropsValue"
633
+ ]);
626
634
  this.state = reactive({
627
635
  propsConfigMap: {},
628
636
  propsValueMap: {}
@@ -661,10 +669,17 @@ class Props extends BaseService {
661
669
  }
662
670
  return value;
663
671
  }
664
- const data = cloneDeep(defaultValue);
665
- await this.setNewItemId(data);
672
+ const [id, defaultPropsValue, data] = await Promise.all([
673
+ this.createId(type),
674
+ this.getDefaultPropsValue(type),
675
+ this.setNewItemId(cloneDeep({
676
+ type,
677
+ ...defaultValue
678
+ }))
679
+ ]);
666
680
  return {
667
- ...getDefaultPropsValue(type, await this.createId(type)),
681
+ id,
682
+ ...defaultPropsValue,
668
683
  ...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), data)
669
684
  };
670
685
  }
@@ -682,6 +697,20 @@ class Props extends BaseService {
682
697
  await this.setNewItemId(item, config);
683
698
  }
684
699
  }
700
+ return config;
701
+ }
702
+ async getDefaultPropsValue(type) {
703
+ return ["page", "container"].includes(type) ? {
704
+ type,
705
+ layout: "absolute",
706
+ style: {},
707
+ name: type,
708
+ items: []
709
+ } : {
710
+ type,
711
+ style: {},
712
+ name: type
713
+ };
685
714
  }
686
715
  }
687
716
  const updatePopId = (oldId, popId, pageConfig) => {
@@ -1037,9 +1066,10 @@ class Editor$1 extends BaseService {
1037
1066
  if (!isPage2) {
1038
1067
  this.pushHistoryState();
1039
1068
  }
1040
- stage?.select(newNode.id);
1041
1069
  if (isPage2) {
1042
1070
  this.state.pageLength += 1;
1071
+ } else {
1072
+ stage?.select(newNode.id);
1043
1073
  }
1044
1074
  this.emit("add", newNode);
1045
1075
  return newNode;
@@ -1157,7 +1187,7 @@ class Editor$1 extends BaseService {
1157
1187
  console.error(e);
1158
1188
  return;
1159
1189
  }
1160
- await propsService.setNewItemId(config, this.get("root"));
1190
+ config = await propsService.setNewItemId(config, this.get("root"));
1161
1191
  if (config.style) {
1162
1192
  config.style = {
1163
1193
  ...config.style,
@@ -1595,19 +1625,6 @@ const fillConfig = (config = []) => [
1595
1625
  }
1596
1626
  ];
1597
1627
  const DEFAULT_CONFIG = fillConfig([]);
1598
- const getDefaultPropsValue = (type, id) => ["page", "container"].includes(type) ? {
1599
- type,
1600
- id,
1601
- layout: "absolute",
1602
- style: {},
1603
- name: type,
1604
- items: []
1605
- } : {
1606
- type,
1607
- id,
1608
- style: {},
1609
- name: type
1610
- };
1611
1628
 
1612
1629
  const log = (...args) => {
1613
1630
  };
@@ -2615,9 +2632,17 @@ const useDrop = (tree, editorService) => ({
2615
2632
  return true;
2616
2633
  return false;
2617
2634
  },
2618
- handleDragEnd() {
2635
+ async handleDragEnd(e) {
2619
2636
  if (!tree.value)
2620
2637
  return;
2638
+ const { data: node } = e;
2639
+ const parent = editorService?.getParentById(node.id, false);
2640
+ const layout = await editorService?.getLayout(parent);
2641
+ node.style.position = layout;
2642
+ if (layout === Layout.RELATIVE) {
2643
+ node.style.top = 0;
2644
+ node.style.left = 0;
2645
+ }
2621
2646
  const { data } = tree.value;
2622
2647
  const [page] = data;
2623
2648
  editorService?.update(page);
@@ -4207,5 +4232,5 @@ var index = {
4207
4232
  }
4208
4233
  };
4209
4234
 
4210
- export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, uiService, warn };
4235
+ export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, 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, uiService, warn };
4211
4236
  //# sourceMappingURL=tmagic-editor.es.js.map