feat!: migrate bubble dragging to use new API (#7974)

This commit is contained in:
Beka Westberg
2024-03-29 18:02:47 +00:00
committed by GitHub
parent da8a83b925
commit 59f589c32a
7 changed files with 107 additions and 263 deletions

View File

@@ -0,0 +1,52 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {IDragStrategy} from '../interfaces/i_draggable.js';
import {Coordinate} from '../utils.js';
import * as eventUtils from '../events/utils.js';
import {IBubble, WorkspaceSvg} from '../blockly.js';
import * as layers from '../layers.js';
export class BubbleDragStrategy implements IDragStrategy {
private startLoc: Coordinate | null = null;
constructor(
private bubble: IBubble,
private workspace: WorkspaceSvg,
) {}
isMovable(): boolean {
return true;
}
startDrag(): void {
if (!eventUtils.getGroup()) {
eventUtils.setGroup(true);
}
this.startLoc = this.bubble.getRelativeToSurfaceXY();
this.workspace.setResizesEnabled(false);
this.workspace.getLayerManager()?.moveToDragLayer(this.bubble);
this.bubble.setDragging && this.bubble.setDragging(true);
}
drag(newLoc: Coordinate): void {
this.bubble.moveDuringDrag(newLoc);
}
endDrag(): void {
this.workspace.setResizesEnabled(true);
eventUtils.setGroup(false);
this.workspace
.getLayerManager()
?.moveOffDragLayer(this.bubble, layers.BLOCK);
this.bubble.setDragging(false);
}
revertDrag(): void {
if (this.startLoc) this.bubble.moveDuringDrag(this.startLoc);
}
}