feat: update logic of copy group block
This commit is contained in:
@@ -414,16 +414,35 @@ export class Paste {
|
|||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _createBlocks(blocks: ClipBlockInfo[], parentId?: string) {
|
private _flatGroupBlocks(blocks: ClipBlockInfo[]) {
|
||||||
|
return blocks.reduce(
|
||||||
|
(blockList: ClipBlockInfo[], block: ClipBlockInfo) => {
|
||||||
|
if (block.type === 'group') {
|
||||||
|
block?.children?.forEach(childBlock => {
|
||||||
|
childBlock.children = this._flatGroupBlocks(
|
||||||
|
childBlock.children
|
||||||
|
);
|
||||||
|
});
|
||||||
|
block?.children?.length &&
|
||||||
|
blockList.push(...block.children);
|
||||||
|
} else {
|
||||||
|
blockList.push(block);
|
||||||
|
block.children = this._flatGroupBlocks(block.children);
|
||||||
|
}
|
||||||
|
return blockList;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
private async _createBlocks(blocks: ClipBlockInfo[]) {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
blocks.map(async clipBlockInfo => {
|
this._flatGroupBlocks(blocks).map(async clipBlockInfo => {
|
||||||
const block = await this._editor.createBlock(
|
const block = await this._editor.createBlock(
|
||||||
clipBlockInfo.type
|
clipBlockInfo.type
|
||||||
);
|
);
|
||||||
block?.setProperties(clipBlockInfo.properties);
|
block?.setProperties(clipBlockInfo.properties);
|
||||||
const children = await this._createBlocks(
|
const children = await this._createBlocks(
|
||||||
clipBlockInfo.children,
|
clipBlockInfo.children
|
||||||
block?.id
|
|
||||||
);
|
);
|
||||||
await Promise.all(children.map(child => block?.append(child)));
|
await Promise.all(children.map(child => block?.append(child)));
|
||||||
return block;
|
return block;
|
||||||
|
|||||||
Reference in New Issue
Block a user