mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
* chore(deps): Add pretter-plugin-organize-imports * chore: Remove insignificant blank lines in import sections Since prettier-plugin-organize-imports sorts imports within sections separated by blank lines, but preserves the section divisions, remove any blank lines that are not dividing imports into meaningful sections. Do not remove blank lines separating side-effect-only imports from main imports. * chore: Remove unneded eslint-disable directives * chore: Organise imports
98 lines
2.6 KiB
TypeScript
98 lines
2.6 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2024 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import {RenderedWorkspaceComment} from '../comments.js';
|
|
import {CommentMove} from '../events/events_comment_move.js';
|
|
import * as eventUtils from '../events/utils.js';
|
|
import {IDragStrategy} from '../interfaces/i_draggable.js';
|
|
import * as layers from '../layers.js';
|
|
import {Coordinate} from '../utils.js';
|
|
import {WorkspaceSvg} from '../workspace_svg.js';
|
|
|
|
export class CommentDragStrategy implements IDragStrategy {
|
|
private startLoc: Coordinate | null = null;
|
|
|
|
private workspace: WorkspaceSvg;
|
|
|
|
/** Was there already an event group in progress when the drag started? */
|
|
private inGroup: boolean = false;
|
|
|
|
constructor(private comment: RenderedWorkspaceComment) {
|
|
this.workspace = comment.workspace;
|
|
}
|
|
|
|
isMovable(): boolean {
|
|
return this.comment.isOwnMovable() && !this.workspace.options.readOnly;
|
|
}
|
|
|
|
startDrag(): void {
|
|
this.inGroup = !!eventUtils.getGroup();
|
|
if (!this.inGroup) {
|
|
eventUtils.setGroup(true);
|
|
}
|
|
this.fireDragStartEvent();
|
|
this.startLoc = this.comment.getRelativeToSurfaceXY();
|
|
this.workspace.setResizesEnabled(false);
|
|
this.workspace.getLayerManager()?.moveToDragLayer(this.comment);
|
|
this.comment.setDragging(true);
|
|
}
|
|
|
|
drag(newLoc: Coordinate): void {
|
|
this.comment.moveDuringDrag(newLoc);
|
|
}
|
|
|
|
endDrag(): void {
|
|
this.fireDragEndEvent();
|
|
this.fireMoveEvent();
|
|
|
|
this.workspace
|
|
.getLayerManager()
|
|
?.moveOffDragLayer(this.comment, layers.BLOCK);
|
|
this.comment.setDragging(false);
|
|
|
|
this.comment.snapToGrid();
|
|
|
|
this.workspace.setResizesEnabled(true);
|
|
if (!this.inGroup) {
|
|
eventUtils.setGroup(false);
|
|
}
|
|
}
|
|
|
|
/** Fire a UI event at the start of a comment drag. */
|
|
private fireDragStartEvent() {
|
|
const event = new (eventUtils.get(eventUtils.COMMENT_DRAG))(
|
|
this.comment,
|
|
true,
|
|
);
|
|
eventUtils.fire(event);
|
|
}
|
|
|
|
/** Fire a UI event at the end of a comment drag. */
|
|
private fireDragEndEvent() {
|
|
const event = new (eventUtils.get(eventUtils.COMMENT_DRAG))(
|
|
this.comment,
|
|
false,
|
|
);
|
|
eventUtils.fire(event);
|
|
}
|
|
|
|
/** Fire a move event at the end of a comment drag. */
|
|
private fireMoveEvent() {
|
|
if (this.comment.isDeadOrDying()) return;
|
|
const event = new (eventUtils.get(eventUtils.COMMENT_MOVE))(
|
|
this.comment,
|
|
) as CommentMove;
|
|
event.setReason(['drag']);
|
|
event.oldCoordinate_ = this.startLoc!;
|
|
event.recordNew();
|
|
eventUtils.fire(event);
|
|
}
|
|
|
|
revertDrag(): void {
|
|
if (this.startLoc) this.comment.moveDuringDrag(this.startLoc);
|
|
}
|
|
}
|