Skip to main content

Class: BlockDragStrategy

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:66

Implements

Properties index

PropertyDescription
workspace-
startLoc-
connectionPreviewer-
moveModeThe current movement mode.
BLOCK_CONNECTION_OFFSET-
WORKSPACE_MARGINHow far in from the edges of the workspace to position newly placed blocks.
block-

Methods index

MethodDescription
isMovableReturns true if the block is currently movable. False otherwise.
positionNewBlockPositions a cloned block on its new workspace.
getTargetBlockReturns the block to use for the current drag operation. This may create and return a newly instantiated block when e.g. dragging from a flyout.
startDragHandles any setup for starting the drag, including disconnecting the block from any parent blocks.
cacheAllConnectionPairsCaches a list of all valid connection pairs between the dragging block and any other blocks on the workspace. This is used to determine the closest valid connection during keyboard-driven moves and to determine the need to disambiguate between multiple compatible connections when announcing moves to assistive technologies.
shouldHealStackGet whether the drag should act on a single block or a block stack.
shouldDisconnectWhether or not we should disconnect the block when a drag is started.
dragMoves the block and updates any connection previews.
getSearchRadiusGet the radius to use when searching for a nearby valid connection.
endDragCleans up any state at the end of the drag. Applies any pending connections.
revertDragMoves the block back to where it was at the beginning of the drag, including reconnecting connections.
findTraversalCandidateGet the nearest valid candidate connection in traversal order.

Constructors

Constructor

new BlockDragStrategy(block): BlockDragStrategy;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:117

Parameters

ParameterType
blockBlockSvg

Returns

BlockDragStrategy

Properties

workspace

protected workspace: WorkspaceSvg;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:67


startLoc

protected startLoc: Coordinate | null = null;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:78


connectionPreviewer

protected connectionPreviewer:
| IConnectionPreviewer
| null = null;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:82


moveMode

protected moveMode: MoveMode = MoveMode.UNCONSTRAINED;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:90

The current movement mode.


BLOCK_CONNECTION_OFFSET

protected readonly BLOCK_CONNECTION_OFFSET: 10 = 10;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:110


WORKSPACE_MARGIN

protected readonly WORKSPACE_MARGIN: 10 = 10;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:115

How far in from the edges of the workspace to position newly placed blocks.


block

protected block: BlockSvg;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:117

Methods

isMovable()

isMovable(): boolean;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:122

Returns true if the block is currently movable. False otherwise.

Returns

boolean

Implementation of

IDragStrategy.isMovable


positionNewBlock()

protected positionNewBlock(oldBlock, newBlock): void;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:139

Positions a cloned block on its new workspace.

Parameters

ParameterTypeDescription
oldBlockBlockSvgThe flyout block that was cloned.
newBlockBlockSvgThe new block to position.

Returns

void


getTargetBlock()

protected getTargetBlock(): BlockSvg;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:242

Returns the block to use for the current drag operation. This may create and return a newly instantiated block when e.g. dragging from a flyout.

Returns

BlockSvg


startDrag()

startDrag(e?): IDraggable;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:344

Handles any setup for starting the drag, including disconnecting the block from any parent blocks.

Parameters

ParameterType
e?PointerEvent | KeyboardEvent

Returns

IDraggable

Implementation of

IDragStrategy.startDrag


cacheAllConnectionPairs()

cacheAllConnectionPairs(): void;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:431

Caches a list of all valid connection pairs between the dragging block and any other blocks on the workspace. This is used to determine the closest valid connection during keyboard-driven moves and to determine the need to disambiguate between multiple compatible connections when announcing moves to assistive technologies.

Returns

void


shouldHealStack()

protected shouldHealStack(e): boolean;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:486

Get whether the drag should act on a single block or a block stack.

Parameters

ParameterTypeDescription
ePointerEvent | KeyboardEvent | undefinedThe instigating pointer or keyboard event, if any.

Returns

boolean

True if just the initial block should be dragged out, false if all following blocks should also be dragged.


shouldDisconnect()

protected shouldDisconnect(healStack): boolean;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:506

Whether or not we should disconnect the block when a drag is started.

Parameters

ParameterTypeDescription
healStackbooleanWhether or not to heal the stack after disconnecting.

Returns

boolean

True to disconnect the block, false otherwise.


drag()

drag(newLoc, e?): void;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:607

Moves the block and updates any connection previews.

Parameters

ParameterType
newLocCoordinate
e?PointerEvent | KeyboardEvent

Returns

void

Implementation of

IDragStrategy.drag


getSearchRadius()

protected getSearchRadius(): number;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:876

Get the radius to use when searching for a nearby valid connection.

Returns

number


endDrag()

endDrag(_e, disposition): void;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:921

Cleans up any state at the end of the drag. Applies any pending connections.

Parameters

ParameterType
_ePointerEvent | KeyboardEvent | undefined
dispositionDragDisposition

Returns

void

Implementation of

IDragStrategy.endDrag


revertDrag()

revertDrag(): void;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:1015

Moves the block back to where it was at the beginning of the drag, including reconnecting connections.

Returns

void

Implementation of

IDragStrategy.revertDrag


findTraversalCandidate()

findTraversalCandidate(delta): ConnectionCandidate | null;

Defined in: packages/blockly/core/dragging/block_drag_strategy.ts:1070

Get the nearest valid candidate connection in traversal order.

Parameters

ParameterTypeDescription
deltaCoordinateThe distance the block has moved since this drag began.

Returns

ConnectionCandidate | null

A candidate connection and radius, or null if none was found.