mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 10:36:22 +08:00
refactor: migrate elements clone from default-tool to extension (#11703)
### Changed - Add `onRequestElementsClone` action to allow extension to define how to clone gfx elements
This commit is contained in:
@@ -5,7 +5,9 @@ import { Extension } from '@blocksuite/store';
|
||||
import type { PointerEventState } from '../../../event/index.js';
|
||||
import type { GfxController } from '../../controller.js';
|
||||
import { GfxControllerIdentifier } from '../../identifiers.js';
|
||||
import type { GfxModel } from '../../model/model.js';
|
||||
import type { SupportedEvents } from '../event.js';
|
||||
import type { ExtensionElementsCloneContext } from '../types/clone.js';
|
||||
import type {
|
||||
DragExtensionInitializeContext,
|
||||
ExtensionDragEndContext,
|
||||
@@ -105,11 +107,22 @@ type ActionContextMap = {
|
||||
clear?: () => void;
|
||||
};
|
||||
};
|
||||
elementsClone: {
|
||||
context: ExtensionElementsCloneContext;
|
||||
returnType: Promise<
|
||||
| {
|
||||
elements: GfxModel[];
|
||||
}
|
||||
| undefined
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
export class InteractivityActionAPI {
|
||||
private readonly _handlers: Partial<{
|
||||
dragInitialize: Parameters<InteractivityActionAPI['onDragInitialize']>[0];
|
||||
[K in keyof ActionContextMap]: (
|
||||
ctx: ActionContextMap[K]['context']
|
||||
) => ActionContextMap[K]['returnType'];
|
||||
}> = {};
|
||||
|
||||
onDragInitialize(
|
||||
@@ -124,6 +137,18 @@ export class InteractivityActionAPI {
|
||||
};
|
||||
}
|
||||
|
||||
onRequestElementsClone(
|
||||
handler: (
|
||||
ctx: ActionContextMap['elementsClone']['context']
|
||||
) => ActionContextMap['elementsClone']['returnType']
|
||||
) {
|
||||
this._handlers['elementsClone'] = handler;
|
||||
|
||||
return () => {
|
||||
return delete this._handlers['elementsClone'];
|
||||
};
|
||||
}
|
||||
|
||||
emit<K extends keyof ActionContextMap>(
|
||||
event: K,
|
||||
context: ActionContextMap[K]['context']
|
||||
|
||||
Reference in New Issue
Block a user