mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 21:38:44 +08:00
21bf009553
### Changed - Add `onRequestElementsClone` action to allow extension to define how to clone gfx elements
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { getCommonBoundWithRotation } from '@blocksuite/global/gfx';
|
|
import { type GfxModel, InteractivityExtension } from '@blocksuite/std/gfx';
|
|
|
|
import { createElementsFromClipboardDataCommand } from '../clipboard/command.js';
|
|
import { prepareCloneData } from '../utils/clone-utils.js';
|
|
|
|
export class AltCloneExtension extends InteractivityExtension {
|
|
static override key = 'alt-clone';
|
|
|
|
override mounted(): void {
|
|
this.action.onRequestElementsClone(async context => {
|
|
const { elements: elementsToClone } = context;
|
|
const snapshot = prepareCloneData(elementsToClone, this.std);
|
|
|
|
const bound = getCommonBoundWithRotation(elementsToClone);
|
|
const [_, { createdElementsPromise }] = this.std.command.exec(
|
|
createElementsFromClipboardDataCommand,
|
|
{
|
|
elementsRawData: snapshot,
|
|
pasteCenter: bound.center,
|
|
}
|
|
);
|
|
|
|
if (!createdElementsPromise) return;
|
|
const { canvasElements, blockModels } = await createdElementsPromise;
|
|
|
|
return {
|
|
elements: [...canvasElements, ...blockModels] as GfxModel[],
|
|
};
|
|
});
|
|
}
|
|
}
|