mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-15 17:43:43 +08:00
fix(editor): 复制页面错误
This commit is contained in:
parent
c19afda58c
commit
5f0e421550
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user