refactor: moving connector label to connector view (#11738)

### Changed
Moved connector label moving logic from `default-tool` to connector view.

#### Other infrastructure changes:​​
- Gfx element view now can handles drag events
- Added `context.preventDefault()` support to bypass built-in interactions in extension
- Handle the pointer events in element view will bypass the built-in interactions automatically

> The built-in interactions include element dragging, click selection, drag-to-scale operations, etc.
This commit is contained in:
doouding
2025-04-22 08:18:24 +00:00
parent 21bf009553
commit e0e84d302d
12 changed files with 305 additions and 130 deletions
@@ -2,11 +2,10 @@ import { type Container, createIdentifier } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
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 { GfxInteractivityContext, SupportedEvents } from '../event.js';
import type { ExtensionElementsCloneContext } from '../types/clone.js';
import type {
DragExtensionInitializeContext,
@@ -64,10 +63,13 @@ export class InteractivityExtension extends Extension {
export class InteractivityEventAPI {
private readonly _handlersMap = new Map<
SupportedEvents,
((evt: PointerEventState) => void)[]
((evt: GfxInteractivityContext) => void)[]
>();
on(eventName: SupportedEvents, handler: (evt: PointerEventState) => void) {
on(
eventName: SupportedEvents,
handler: (evt: GfxInteractivityContext) => void
) {
const handlers = this._handlersMap.get(eventName) ?? [];
handlers.push(handler);
this._handlersMap.set(eventName, handlers);
@@ -81,7 +83,7 @@ export class InteractivityEventAPI {
};
}
emit(eventName: SupportedEvents, evt: PointerEventState) {
emit(eventName: SupportedEvents, evt: GfxInteractivityContext) {
const handlers = this._handlersMap.get(eventName);
if (!handlers) {
return;