@tmagic/editor 1.2.0-beta.19 → 1.2.0-beta.20

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.
@@ -1640,6 +1640,13 @@
1640
1640
  }
1641
1641
  return parentNode;
1642
1642
  };
1643
+ const getDefaultConfig = async (addNode, parentNode) => {
1644
+ const { type, inputEvent, ...config } = addNode;
1645
+ const layout = await editorService.getLayout(vue.toRaw(parentNode), addNode);
1646
+ const newNode = { ...vue.toRaw(await propsService.getPropsValue(type, config)) };
1647
+ newNode.style = getInitPositionStyle(newNode.style, layout);
1648
+ return newNode;
1649
+ };
1643
1650
 
1644
1651
  class Editor$1 extends BaseService {
1645
1652
  state = vue.reactive({
@@ -1848,6 +1855,9 @@
1848
1855
  }
1849
1856
  const newNodes = await Promise.all(
1850
1857
  addNodes.map((node) => {
1858
+ if (utils.isPage(node)) {
1859
+ return this.doAdd(node, this.get("root"));
1860
+ }
1851
1861
  const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(node);
1852
1862
  if (!parentNode)
1853
1863
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
@@ -2001,7 +2011,7 @@
2001
2011
  if (!Array.isArray(config))
2002
2012
  return;
2003
2013
  const pasteConfigs = await this.doPaste(config, position);
2004
- return this.add(pasteConfigs);
2014
+ return this.add(pasteConfigs, this.get("parent"));
2005
2015
  }
2006
2016
  async doPaste(config, position = {}) {
2007
2017
  const pasteConfigs = await beforePaste(position, lodashEs.cloneDeep(config));
@@ -5460,7 +5470,7 @@
5460
5470
  const zoom = vue.computed(() => services?.uiService.get("zoom") || 1);
5461
5471
  const node = vue.computed(() => services?.editorService.get("node"));
5462
5472
  vue.watchEffect(() => {
5463
- if (stage)
5473
+ if (stage || !page.value)
5464
5474
  return;
5465
5475
  if (!stageContainer.value)
5466
5476
  return;
@@ -5850,14 +5860,23 @@
5850
5860
  emits: ["props-panel-mounted", "update:modelValue"],
5851
5861
  setup(props, { emit }) {
5852
5862
  editorService.on("root-change", (value) => {
5853
- const node = editorService.get("node");
5854
- const nodeId = node?.id || props.defaultSelected;
5855
- if (nodeId && node !== value) {
5856
- editorService.select(nodeId);
5857
- } else {
5863
+ const nodeId = editorService.get("node")?.id || props.defaultSelected;
5864
+ let node;
5865
+ if (nodeId) {
5866
+ node = editorService.getNodeById(nodeId);
5867
+ }
5868
+ if (node && node !== value) {
5869
+ editorService.select(node.id);
5870
+ } else if (value?.items?.length) {
5871
+ editorService.select(value.items[0]);
5872
+ } else if (value?.id) {
5858
5873
  editorService.set("nodes", [value]);
5874
+ editorService.set("parent", null);
5875
+ editorService.set("page", null);
5876
+ }
5877
+ if (vue.toRaw(value) !== vue.toRaw(editorService.get("root"))) {
5878
+ emit("update:modelValue", value);
5859
5879
  }
5860
- emit("update:modelValue", vue.toRaw(editorService.get("root")));
5861
5880
  });
5862
5881
  vue.watch(
5863
5882
  () => props.modelValue,
@@ -6094,6 +6113,7 @@
6094
6113
  exports.TMagicEditor = Editor;
6095
6114
  exports.ToolButton = _sfc_main$k;
6096
6115
  exports.V_GUIDE_LINE_STORAGE_KEY = V_GUIDE_LINE_STORAGE_KEY;
6116
+ exports.beforePaste = beforePaste;
6097
6117
  exports.change2Fixed = change2Fixed;
6098
6118
  exports.codeBlockService = codeBlockService;
6099
6119
  exports.debug = debug;
@@ -6106,12 +6126,15 @@
6106
6126
  exports.fixNodePosition = fixNodePosition;
6107
6127
  exports.generatePageName = generatePageName;
6108
6128
  exports.generatePageNameByApp = generatePageNameByApp;
6129
+ exports.getAddParent = getAddParent;
6109
6130
  exports.getConfig = getConfig;
6131
+ exports.getDefaultConfig = getDefaultConfig;
6110
6132
  exports.getGuideLineFromCache = getGuideLineFromCache;
6111
6133
  exports.getInitPositionStyle = getInitPositionStyle;
6112
6134
  exports.getNodeIndex = getNodeIndex;
6113
6135
  exports.getPageList = getPageList;
6114
6136
  exports.getPageNameList = getPageNameList;
6137
+ exports.getPositionInContainer = getPositionInContainer;
6115
6138
  exports.getRelativeStyle = getRelativeStyle;
6116
6139
  exports.historyService = historyService;
6117
6140
  exports.info = info;