mirror of
https://github.com/google/blockly.git
synced 2026-01-10 10:27:08 +01:00
feat: have block use drag strategy (#7971)
This commit is contained in:
@@ -36,7 +36,7 @@ import type {Input} from './inputs/input.js';
|
||||
import type {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js';
|
||||
import type {IBoundedElement} from './interfaces/i_bounded_element.js';
|
||||
import type {ICopyable} from './interfaces/i_copyable.js';
|
||||
import type {IDraggable} from './interfaces/i_draggable.old.js';
|
||||
import type {IDragStrategy, IDraggable} from './interfaces/i_draggable.js';
|
||||
import {IIcon} from './interfaces/i_icon.js';
|
||||
import * as internalConstants from './internal_constants.js';
|
||||
import {ASTNode} from './keyboard_nav/ast_node.js';
|
||||
@@ -60,6 +60,7 @@ import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
import * as renderManagement from './render_management.js';
|
||||
import {IconType} from './icons/icon_types.js';
|
||||
import {BlockCopyData, BlockPaster} from './clipboard/block_paster.js';
|
||||
import {BlockDragStrategy} from './dragging/block_drag_strategy.js';
|
||||
|
||||
/**
|
||||
* Class for a block's SVG representation.
|
||||
@@ -154,6 +155,8 @@ export class BlockSvg
|
||||
*/
|
||||
relativeCoords = new Coordinate(0, 0);
|
||||
|
||||
private dragStrategy: IDragStrategy = new BlockDragStrategy(this);
|
||||
|
||||
/**
|
||||
* @param workspace The block's workspace.
|
||||
* @param prototypeName Name of the language object containing type-specific
|
||||
@@ -1622,4 +1625,34 @@ export class BlockSvg
|
||||
add,
|
||||
);
|
||||
}
|
||||
|
||||
/** Sets the drag strategy for this block. */
|
||||
setDragStrategy(dragStrategy: IDragStrategy) {
|
||||
this.dragStrategy = dragStrategy;
|
||||
}
|
||||
|
||||
/** Returns whether this block is movable or not. */
|
||||
override isMovable(): boolean {
|
||||
return this.dragStrategy.isMovable();
|
||||
}
|
||||
|
||||
/** Starts a drag on the block. */
|
||||
startDrag(e?: PointerEvent): void {
|
||||
this.dragStrategy.startDrag(e);
|
||||
}
|
||||
|
||||
/** Drags the block to the given location. */
|
||||
drag(newLoc: Coordinate, e?: PointerEvent): void {
|
||||
this.dragStrategy.drag(newLoc, e);
|
||||
}
|
||||
|
||||
/** Ends the drag on the block. */
|
||||
endDrag(e?: PointerEvent): void {
|
||||
this.dragStrategy.endDrag(e);
|
||||
}
|
||||
|
||||
/** Moves the block back to where it was at the start of a drag. */
|
||||
revertDrag(): void {
|
||||
this.dragStrategy.revertDrag();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,6 +390,9 @@ export class BlockDragStrategy implements IDragStrategy {
|
||||
);
|
||||
}
|
||||
|
||||
this.startChildConn = null;
|
||||
this.startParentConn = null;
|
||||
|
||||
this.connectionPreviewer!.hidePreview();
|
||||
this.connectionCandidate = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user