@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.
@@ -1623,6 +1623,13 @@ const getAddParent = (node) => {
1623
1623
  }
1624
1624
  return parentNode;
1625
1625
  };
1626
+ const getDefaultConfig = async (addNode, parentNode) => {
1627
+ const { type, inputEvent, ...config } = addNode;
1628
+ const layout = await editorService.getLayout(toRaw(parentNode), addNode);
1629
+ const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
1630
+ newNode.style = getInitPositionStyle(newNode.style, layout);
1631
+ return newNode;
1632
+ };
1626
1633
 
1627
1634
  class Editor$1 extends BaseService {
1628
1635
  state = reactive({
@@ -1831,6 +1838,9 @@ class Editor$1 extends BaseService {
1831
1838
  }
1832
1839
  const newNodes = await Promise.all(
1833
1840
  addNodes.map((node) => {
1841
+ if (isPage(node)) {
1842
+ return this.doAdd(node, this.get("root"));
1843
+ }
1834
1844
  const parentNode = parent && typeof parent !== "function" ? parent : getAddParent(node);
1835
1845
  if (!parentNode)
1836
1846
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
@@ -1984,7 +1994,7 @@ class Editor$1 extends BaseService {
1984
1994
  if (!Array.isArray(config))
1985
1995
  return;
1986
1996
  const pasteConfigs = await this.doPaste(config, position);
1987
- return this.add(pasteConfigs);
1997
+ return this.add(pasteConfigs, this.get("parent"));
1988
1998
  }
1989
1999
  async doPaste(config, position = {}) {
1990
2000
  const pasteConfigs = await beforePaste(position, cloneDeep(config));
@@ -5443,7 +5453,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5443
5453
  const zoom = computed(() => services?.uiService.get("zoom") || 1);
5444
5454
  const node = computed(() => services?.editorService.get("node"));
5445
5455
  watchEffect(() => {
5446
- if (stage)
5456
+ if (stage || !page.value)
5447
5457
  return;
5448
5458
  if (!stageContainer.value)
5449
5459
  return;
@@ -5833,14 +5843,23 @@ const _sfc_main = defineComponent({
5833
5843
  emits: ["props-panel-mounted", "update:modelValue"],
5834
5844
  setup(props, { emit }) {
5835
5845
  editorService.on("root-change", (value) => {
5836
- const node = editorService.get("node");
5837
- const nodeId = node?.id || props.defaultSelected;
5838
- if (nodeId && node !== value) {
5839
- editorService.select(nodeId);
5840
- } else {
5846
+ const nodeId = editorService.get("node")?.id || props.defaultSelected;
5847
+ let node;
5848
+ if (nodeId) {
5849
+ node = editorService.getNodeById(nodeId);
5850
+ }
5851
+ if (node && node !== value) {
5852
+ editorService.select(node.id);
5853
+ } else if (value?.items?.length) {
5854
+ editorService.select(value.items[0]);
5855
+ } else if (value?.id) {
5841
5856
  editorService.set("nodes", [value]);
5857
+ editorService.set("parent", null);
5858
+ editorService.set("page", null);
5859
+ }
5860
+ if (toRaw(value) !== toRaw(editorService.get("root"))) {
5861
+ emit("update:modelValue", value);
5842
5862
  }
5843
- emit("update:modelValue", toRaw(editorService.get("root")));
5844
5863
  });
5845
5864
  watch(
5846
5865
  () => props.modelValue,
@@ -6055,5 +6074,5 @@ const index = {
6055
6074
  }
6056
6075
  };
6057
6076
 
6058
- export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, CodeEditorMode, _sfc_main$s as CodeSelect, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$n as Icon, Keys, LayerOffset, _sfc_main$a as LayerPanel, Layout, _sfc_main$o as LayoutContainer, _sfc_main$i as PropsPanel, _sfc_main$q as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$k as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, codeBlockService, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, uiService, useStage, warn };
6077
+ export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, CodeEditorMode, _sfc_main$s as CodeSelect, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$n as Icon, Keys, LayerOffset, _sfc_main$a as LayerPanel, Layout, _sfc_main$o as LayoutContainer, _sfc_main$i as PropsPanel, _sfc_main$q as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$k as ToolButton, V_GUIDE_LINE_STORAGE_KEY, beforePaste, change2Fixed, codeBlockService, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, uiService, useStage, warn };
6059
6078
  //# sourceMappingURL=tmagic-editor.mjs.map