Skip to main content

Class: ScrollBlockDragger

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:89

A block dragger that adds the functionality for a block to be moved while someone is dragging it.

Extends​

  • Dragger

Properties index​

PropertyDescription
activeAutoScroll_-
dragDelta_How much the block has been moved due to dragging.
draggable-
dragTarget-
revertShouldDelete-
scrollDelta_How much the block has been moved due to scrolling.
scrollDirections_Possible directions the workspace could be scrolled.
startLoc-
edgeScrollEnabledWhether the behavior to scroll the workspace when a block is dragged near the edge is enabled.
optionsConfiguration options for the scroll-options settings.
resetOptionsResets the options object to the default options.
updateOptionsUpdate the scroll options. Only the properties actually included in the options parameter will be set. Any unspecified options will use the previously set value (where the initial value is from defaultOptions). Therefore, do not pass in any options with explicit undefined or null values. The plugin will break. Just leave them out of the object if you don't want to change the default value.

Methods index​

MethodDescription
computeBlockCandidateScrolls_Gets the candidate scrolls based on the position of the block on the workspace. If the block is near/over the edge, a candidate scroll will be added based on the options provided.
computeMouseCandidateScrolls_Gets the candidate scrolls based on the position of the mouse cursor relative to the workspace. If the mouse is near/over the edge, a candidate scroll will be added based on the options provided.
getBlockBoundsOverflows_Gets the amount of overflow of a box relative to the workspace viewport.
getMouseOverflows_Gets the amount of overflow of the mouse coordinates relative to the viewport.
getOverallScrollVector_There could be multiple candidate scrolls for each direction, such as one for block position and one for mouse position. We should first find the fastest scroll in each direction. Then, we sum those to find the overall scroll vector.
moveBlockWhileDraggingUpdates the location of the block that is being dragged.
onDragPasses the total amount the block has moved (both from dragging and from scrolling) since it was picked up.
onDragEnd-
onDragRevertHandles a drag being reverted.
onDragStartHandles any drag startup.
pixelsToWorkspaceUnits-
scrollWorkspaceWhileDragging_May scroll the workspace as a block is dragged. If a block is dragged near the edge of the workspace, this method will cause the workspace to scroll in the direction the block is being dragged. The workspace will not resize as the block is dragged. The workspace should appear to move out from under the block, i.e., the block should stay under the user's mouse.
shouldReturnToStartReturns true if we should return the draggable to its original location at the end of the drag.
stopAutoScrollingCancel any AutoScroll. This must be called when there is no need to scroll further, e.g., when no longer dragging near the edge of the workspace, or when no longer dragging at all.
updateDragTargetUpdates the drag target under the pointer (if there is one).
wouldDeleteDraggableReturns true if we would delete the draggable if it was dropped at the current location.

Constructors​

Constructor​

new ScrollBlockDragger(draggable): ScrollBlockDragger;

Parameters​

ParameterType
draggableIDraggable

Returns​

ScrollBlockDragger

Inherited from​

Blockly.dragging.Dragger.constructor

Properties​

activeAutoScroll_​

activeAutoScroll_: AutoScroll | null = null;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:115


dragDelta_​

protected dragDelta_: Coordinate;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:93

How much the block has been moved due to dragging.


draggable​

protected draggable: IDraggable;

Inherited from​

Blockly.dragging.Dragger.draggable


dragTarget​

protected dragTarget: IDragTarget | null;

Inherited from​

Blockly.dragging.Dragger.dragTarget


revertShouldDelete​

protected revertShouldDelete: boolean;

Inherited from​

Blockly.dragging.Dragger.revertShouldDelete


scrollDelta_​

protected scrollDelta_: Coordinate;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:91

How much the block has been moved due to scrolling.


scrollDirections_​

protected scrollDirections_: ["top", "bottom", "left", "right"];

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:97

Possible directions the workspace could be scrolled.


startLoc​

protected startLoc: Coordinate;

Inherited from​

Blockly.dragging.Dragger.startLoc


edgeScrollEnabled​

static edgeScrollEnabled: boolean = true;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:121

Whether the behavior to scroll the workspace when a block is dragged near the edge is enabled.


options​

static options: EdgeScrollOptions = defaultOptions;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:123

Configuration options for the scroll-options settings.


resetOptions​

static resetOptions: () => void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:506

Resets the options object to the default options.

Returns​

void


updateOptions​

static updateOptions: (options) => void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:499

Update the scroll options. Only the properties actually included in the options parameter will be set. Any unspecified options will use the previously set value (where the initial value is from defaultOptions). Therefore, do not pass in any options with explicit undefined or null values. The plugin will break. Just leave them out of the object if you don't want to change the default value.

This method is safe to call multiple times. Subsequent calls will add onto previous calls, not completely overwrite them. That is, if you call this with:

updateOptions({fastMouseSpeed: 5}); updateOptions({slowMouseSpeed: 2});.

Then the final options used will include both fastMouseSpeed: 5 and slowMouseSpeed: 2 with all other options being the default values.

Parameters​

ParameterTypeDescription
optionsPartial<EdgeScrollOptions>Object containing any or all of the available options. Any properties not present will use the existing value.

Returns​

void

Methods​

computeBlockCandidateScrolls_()​

protected computeBlockCandidateScrolls_(
candidateScrolls,
viewMetrics,
mouse
): void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:302

Gets the candidate scrolls based on the position of the block on the workspace. If the block is near/over the edge, a candidate scroll will be added based on the options provided.

This method can be overridden to further customize behavior, e.g. To add a third speed option.

Parameters​

ParameterTypeDescription
candidateScrollsCandidateScrollsExisting list of candidate scrolls. Will be modified in place.
viewMetricsContainerRegionView metrics for the workspace.
mouseCoordinateMouse coordinates.

Returns​

void


computeMouseCandidateScrolls_()​

protected computeMouseCandidateScrolls_(
candidateScrolls,
viewMetrics,
mouse
): void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:336

Gets the candidate scrolls based on the position of the mouse cursor relative to the workspace. If the mouse is near/over the edge, a candidate scroll will be added based on the options provided.

This method can be overridden to further customize behavior, e.g. To add a third speed option.

Parameters​

ParameterTypeDescription
candidateScrollsCandidateScrollsExisting list of candidate scrolls. Will be modified in place.
viewMetricsContainerRegionView metrics for the workspace.
mouseCoordinateMouse coordinates.

Returns​

void


getBlockBoundsOverflows_()​

protected getBlockBoundsOverflows_(viewMetrics, mouse): object;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:375

Gets the amount of overflow of a box relative to the workspace viewport.

The value for each direction will be how far the given block edge is from the given edge of the viewport. If the block edge is outside the viewport, the value will be positive. If the block edge is inside the viewport, the value will be negative.

This method also checks for oversized blocks. If the block is very large relative to the viewport size, then we will actually use a small zone around the cursor, rather than the edge of the block, to calculate the overflow values. This calculation is done independently in both the horizontal and vertical directions. These values can be configured in the options for the plugin.

Parameters​

ParameterTypeDescription
viewMetricsContainerRegionView metrics for the workspace.
mouseCoordinateMouse coordinates.

Returns​

object


getMouseOverflows_()​

protected getMouseOverflows_(viewMetrics, mouse): object;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:450

Gets the amount of overflow of the mouse coordinates relative to the viewport.

The value for each direction will be how far the pointer is from the given edge of the viewport. If the pointer is outside the viewport, the value will be positive. If the pointer is inside the viewport, the value will be negative.

Parameters​

ParameterTypeDescription
viewMetricsContainerRegionView metrics for the workspace.
mouseCoordinateMouse coordinates.

Returns​

object

An object describing the amount of overflow in each direction.


getOverallScrollVector_()​

protected getOverallScrollVector_(candidateScrolls): Coordinate;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:264

There could be multiple candidate scrolls for each direction, such as one for block position and one for mouse position. We should first find the fastest scroll in each direction. Then, we sum those to find the overall scroll vector.

For example, we may have a fast block scroll and a slow mouse scroll candidate in both the top and left directions. First, we reduce to only the fast block scroll. Then, we sum the vectors in each direction to get a resulting fast scroll in a diagonal direction to the top left.

Parameters​

ParameterTypeDescription
candidateScrollsCandidateScrollsExisting lists of candidate scrolls. Will be modified in place.

Returns​

Coordinate

Overall scroll vector.


moveBlockWhileDragging()​

moveBlockWhileDragging(deltaX, deltaY): void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:131

Updates the location of the block that is being dragged.

Parameters​

ParameterTypeDescription
deltaXnumberHorizontal offset in pixel units.
deltaYnumberVertical offset in pixel units.

Returns​

void


onDrag()​

onDrag(e, dragDelta): void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:157

Passes the total amount the block has moved (both from dragging and from scrolling) since it was picked up.

Parameters​

ParameterType
ePointerEvent
dragDeltaCoordinate

Returns​

void

Overrides​

Blockly.dragging.Dragger.onDrag


onDragEnd()​

onDragEnd(e): void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:178

Parameters​

ParameterType
ePointerEvent

Returns​

void

Overrides​

Blockly.dragging.Dragger.onDragEnd


onDragRevert()​

onDragRevert(e?): void;

Handles a drag being reverted.

Parameters​

ParameterType
e?PointerEvent | KeyboardEvent

Returns​

void

Inherited from​

Blockly.dragging.Dragger.onDragRevert


onDragStart()​

onDragStart(e?): IDraggable;

Handles any drag startup.

Parameters​

ParameterType
e?PointerEvent | KeyboardEvent

Returns​

IDraggable

Inherited from​

Blockly.dragging.Dragger.onDragStart


pixelsToWorkspaceUnits()​

protected pixelsToWorkspaceUnits(pixelCoord): Coordinate;

Parameters​

ParameterType
pixelCoordCoordinate

Returns​

Coordinate

Inherited from​

Blockly.dragging.Dragger.pixelsToWorkspaceUnits


scrollWorkspaceWhileDragging_()​

protected scrollWorkspaceWhileDragging_(e): void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:198

May scroll the workspace as a block is dragged. If a block is dragged near the edge of the workspace, this method will cause the workspace to scroll in the direction the block is being dragged. The workspace will not resize as the block is dragged. The workspace should appear to move out from under the block, i.e., the block should stay under the user's mouse.

Parameters​

ParameterTypeDescription
ePointerEventThe mouse/touch event for the drag.

Returns​

void


shouldReturnToStart()​

protected shouldReturnToStart(coordinate, rootDraggable): boolean;

Returns true if we should return the draggable to its original location at the end of the drag.

Parameters​

ParameterType
coordinateCoordinate
rootDraggableIDraggable

Returns​

boolean

Inherited from​

Blockly.dragging.Dragger.shouldReturnToStart


stopAutoScrolling()​

stopAutoScrolling(): void;

Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:470

Cancel any AutoScroll. This must be called when there is no need to scroll further, e.g., when no longer dragging near the edge of the workspace, or when no longer dragging at all.

Returns​

void


updateDragTarget()​

protected updateDragTarget(coordinate): void;

Updates the drag target under the pointer (if there is one).

Parameters​

ParameterType
coordinateCoordinate

Returns​

void

Inherited from​

Blockly.dragging.Dragger.updateDragTarget


wouldDeleteDraggable()​

protected wouldDeleteDraggable(coordinate, rootDraggable): boolean;

Returns true if we would delete the draggable if it was dropped at the current location.

Parameters​

ParameterType
coordinateCoordinate
rootDraggableIDraggable & IDeletable

Returns​

boolean

Inherited from​

Blockly.dragging.Dragger.wouldDeleteDraggable