Skip to content

Commit 5f0e421

Browse files
roymondchenjia000
authored andcommitted
fix(editor): 复制页面错误
1 parent c19afda commit 5f0e421

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

packages/editor/src/services/editor.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ class Editor extends BaseService {
327327
public async add(addNode: AddMNode | MNode[], parent?: MContainer | null): Promise<MNode | MNode[]> {
328328
const stage = this.get<StageCore | null>('stage');
329329

330-
const parentNode = parent && typeof parent !== 'function' ? parent : getAddParent(addNode);
331-
if (!parentNode) throw new Error('未找到父元素');
332-
333330
// 新增多个组件只存在于粘贴多个组件,粘贴的是一个完整的config,所以不再需要getPropsValue
334331
const addNodes = [];
335332
if (!Array.isArray(addNode)) {
@@ -342,7 +339,13 @@ class Editor extends BaseService {
342339
addNodes.push(...addNode);
343340
}
344341

345-
const newNodes = await Promise.all(addNodes.map((node) => this.doAdd(node, parentNode)));
342+
const newNodes = await Promise.all(
343+
addNodes.map((node) => {
344+
const parentNode = parent && typeof parent !== 'function' ? parent : getAddParent(node);
345+
if (!parentNode) throw new Error('未找到父元素');
346+
return this.doAdd(node, parentNode);
347+
}),
348+
);
346349

347350
if (newNodes.length > 1) {
348351
const newNodeIds = newNodes.map((node) => node.id);

packages/editor/src/utils/operator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ export const getPositionInContainer = (position: PastePosition = {}, id: Id) =>
8686
};
8787
};
8888

89-
export const getAddParent = (addNode: AddMNode | MNode[]) => {
89+
export const getAddParent = (node: MNode) => {
9090
const curNode = editorService.get<MContainer>('node');
9191

9292
let parentNode;
93-
if (!Array.isArray(addNode) && isPage(addNode as MNode)) {
93+
if (isPage(node)) {
9494
parentNode = editorService.get<MApp>('root');
9595
} else if (curNode.items) {
9696
parentNode = curNode;

0 commit comments

Comments
 (0)