fix(editor): 复制页面错误

This commit is contained in:
roymondchen 2022-08-17 15:20:01 +08:00 committed by jia000
parent c19afda58c
commit 5f0e421550
2 changed files with 9 additions and 6 deletions

View File

@ -327,9 +327,6 @@ class Editor extends BaseService {
public async add(addNode: AddMNode | MNode[], parent?: MContainer | null): Promise<MNode | MNode[]> {
const stage = this.get<StageCore | null>('stage');
const parentNode = parent && typeof parent !== 'function' ? parent : getAddParent(addNode);
if (!parentNode) throw new Error('未找到父元素');
// 新增多个组件只存在于粘贴多个组件,粘贴的是一个完整的config,所以不再需要getPropsValue
const addNodes = [];
if (!Array.isArray(addNode)) {
@ -342,7 +339,13 @@ class Editor extends BaseService {
addNodes.push(...addNode);
}
const newNodes = await Promise.all(addNodes.map((node) => this.doAdd(node, parentNode)));
const newNodes = await Promise.all(
addNodes.map((node) => {
const parentNode = parent && typeof parent !== 'function' ? parent : getAddParent(node);
if (!parentNode) throw new Error('未找到父元素');
return this.doAdd(node, parentNode);
}),
);
if (newNodes.length > 1) {
const newNodeIds = newNodes.map((node) => node.id);

View File

@ -86,11 +86,11 @@ export const getPositionInContainer = (position: PastePosition = {}, id: Id) =>
};
};
export const getAddParent = (addNode: AddMNode | MNode[]) => {
export const getAddParent = (node: MNode) => {
const curNode = editorService.get<MContainer>('node');
let parentNode;
if (!Array.isArray(addNode) && isPage(addNode as MNode)) {
if (isPage(node)) {
parentNode = editorService.get<MApp>('root');
} else if (curNode.items) {
parentNode = curNode;