@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.
@@ -640,7 +640,15 @@
640
640
 
641
641
  class Props extends BaseService {
642
642
  constructor() {
643
- super(["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue", "createId", "setNewItemId"]);
643
+ super([
644
+ "setPropsConfig",
645
+ "getPropsConfig",
646
+ "setPropsValue",
647
+ "getPropsValue",
648
+ "createId",
649
+ "setNewItemId",
650
+ "getDefaultPropsValue"
651
+ ]);
644
652
  this.state = vue.reactive({
645
653
  propsConfigMap: {},
646
654
  propsValueMap: {}
@@ -679,10 +687,17 @@
679
687
  }
680
688
  return value;
681
689
  }
682
- const data = lodashEs.cloneDeep(defaultValue);
683
- await this.setNewItemId(data);
690
+ const [id, defaultPropsValue, data] = await Promise.all([
691
+ this.createId(type),
692
+ this.getDefaultPropsValue(type),
693
+ this.setNewItemId(lodashEs.cloneDeep({
694
+ type,
695
+ ...defaultValue
696
+ }))
697
+ ]);
684
698
  return {
685
- ...getDefaultPropsValue(type, await this.createId(type)),
699
+ id,
700
+ ...defaultPropsValue,
686
701
  ...lodashEs.mergeWith(lodashEs.cloneDeep(this.state.propsValueMap[type] || {}), data)
687
702
  };
688
703
  }
@@ -700,6 +715,20 @@
700
715
  await this.setNewItemId(item, config);
701
716
  }
702
717
  }
718
+ return config;
719
+ }
720
+ async getDefaultPropsValue(type) {
721
+ return ["page", "container"].includes(type) ? {
722
+ type,
723
+ layout: "absolute",
724
+ style: {},
725
+ name: type,
726
+ items: []
727
+ } : {
728
+ type,
729
+ style: {},
730
+ name: type
731
+ };
703
732
  }
704
733
  }
705
734
  const updatePopId = (oldId, popId, pageConfig) => {
@@ -1055,9 +1084,10 @@
1055
1084
  if (!isPage2) {
1056
1085
  this.pushHistoryState();
1057
1086
  }
1058
- stage?.select(newNode.id);
1059
1087
  if (isPage2) {
1060
1088
  this.state.pageLength += 1;
1089
+ } else {
1090
+ stage?.select(newNode.id);
1061
1091
  }
1062
1092
  this.emit("add", newNode);
1063
1093
  return newNode;
@@ -1175,7 +1205,7 @@
1175
1205
  console.error(e);
1176
1206
  return;
1177
1207
  }
1178
- await propsService.setNewItemId(config, this.get("root"));
1208
+ config = await propsService.setNewItemId(config, this.get("root"));
1179
1209
  if (config.style) {
1180
1210
  config.style = {
1181
1211
  ...config.style,
@@ -1613,19 +1643,6 @@
1613
1643
  }
1614
1644
  ];
1615
1645
  const DEFAULT_CONFIG = fillConfig([]);
1616
- const getDefaultPropsValue = (type, id) => ["page", "container"].includes(type) ? {
1617
- type,
1618
- id,
1619
- layout: "absolute",
1620
- style: {},
1621
- name: type,
1622
- items: []
1623
- } : {
1624
- type,
1625
- id,
1626
- style: {},
1627
- name: type
1628
- };
1629
1646
 
1630
1647
  const log = (...args) => {
1631
1648
  };
@@ -2633,9 +2650,17 @@
2633
2650
  return true;
2634
2651
  return false;
2635
2652
  },
2636
- handleDragEnd() {
2653
+ async handleDragEnd(e) {
2637
2654
  if (!tree.value)
2638
2655
  return;
2656
+ const { data: node } = e;
2657
+ const parent = editorService?.getParentById(node.id, false);
2658
+ const layout = await editorService?.getLayout(parent);
2659
+ node.style.position = layout;
2660
+ if (layout === Layout.RELATIVE) {
2661
+ node.style.top = 0;
2662
+ node.style.left = 0;
2663
+ }
2639
2664
  const { data } = tree.value;
2640
2665
  const [page] = data;
2641
2666
  editorService?.update(page);
@@ -4250,7 +4275,6 @@
4250
4275
  exports.generatePageName = generatePageName;
4251
4276
  exports.generatePageNameByApp = generatePageNameByApp;
4252
4277
  exports.getConfig = getConfig;
4253
- exports.getDefaultPropsValue = getDefaultPropsValue;
4254
4278
  exports.getGuideLineFromCache = getGuideLineFromCache;
4255
4279
  exports.getInitPositionStyle = getInitPositionStyle;
4256
4280
  exports.getNodeIndex = getNodeIndex;