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
| Property | Description |
|---|---|
| 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 | - |
| edgeScrollEnabled | Whether the behavior to scroll the workspace when a block is dragged near the edge is enabled. |
| options | Configuration options for the scroll-options settings. |
| resetOptions | Resets the options object to the default options. |
| updateOptions | 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. |
Methods index
| Method | Description |
|---|---|
| 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. |
| moveBlockWhileDragging | Updates the location of the block that is being dragged. |
| onDrag | Passes the total amount the block has moved (both from dragging and from scrolling) since it was picked up. |
| onDragEnd | - |
| onDragRevert | Handles a drag being reverted. |
| onDragStart | Handles 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. |
| shouldReturnToStart | Returns true if we should return the draggable to its original location at the end of the drag. |
| stopAutoScrolling | 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. |
| updateDragTarget | Updates the drag target under the pointer (if there is one). |
| wouldDeleteDraggable | Returns true if we would delete the draggable if it was dropped at the current location. |
Constructors
Constructor
new ScrollBlockDragger(draggable): ScrollBlockDragger;
Parameters
| Parameter | Type |
|---|---|
draggable | IDraggable |
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
| Parameter | Type | Description |
|---|---|---|
options | Partial<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
| Parameter | Type | Description |
|---|---|---|
candidateScrolls | CandidateScrolls | Existing list of candidate scrolls. Will be modified in place. |
viewMetrics | ContainerRegion | View metrics for the workspace. |
mouse | Coordinate | Mouse 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
| Parameter | Type | Description |
|---|---|---|
candidateScrolls | CandidateScrolls | Existing list of candidate scrolls. Will be modified in place. |
viewMetrics | ContainerRegion | View metrics for the workspace. |
mouse | Coordinate | Mouse 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
| Parameter | Type | Description |
|---|---|---|
viewMetrics | ContainerRegion | View metrics for the workspace. |
mouse | Coordinate | Mouse 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
| Parameter | Type | Description |
|---|---|---|
viewMetrics | ContainerRegion | View metrics for the workspace. |
mouse | Coordinate | Mouse 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
| Parameter | Type | Description |
|---|---|---|
candidateScrolls | CandidateScrolls | Existing 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
| Parameter | Type | Description |
|---|---|---|
deltaX | number | Horizontal offset in pixel units. |
deltaY | number | Vertical 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
| Parameter | Type |
|---|---|
e | PointerEvent |
dragDelta | Coordinate |
Returns
void
Overrides
Blockly.dragging.Dragger.onDrag
onDragEnd()
onDragEnd(e): void;
Defined in: plugins/scroll-options/src/ScrollBlockDragger.ts:178
Parameters
| Parameter | Type |
|---|---|
e | PointerEvent |
Returns
void
Overrides
Blockly.dragging.Dragger.onDragEnd
onDragRevert()
onDragRevert(e?): void;
Handles a drag being reverted.
Parameters
| Parameter | Type |
|---|---|
e? | PointerEvent | KeyboardEvent |
Returns
void
Inherited from
Blockly.dragging.Dragger.onDragRevert
onDragStart()
onDragStart(e?): IDraggable;
Handles any drag startup.
Parameters
| Parameter | Type |
|---|---|
e? | PointerEvent | KeyboardEvent |
Returns
IDraggable
Inherited from
Blockly.dragging.Dragger.onDragStart
pixelsToWorkspaceUnits()
protected pixelsToWorkspaceUnits(pixelCoord): Coordinate;
Parameters
| Parameter | Type |
|---|---|
pixelCoord | Coordinate |
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
| Parameter | Type | Description |
|---|---|---|
e | PointerEvent | The 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
| Parameter | Type |
|---|---|
coordinate | Coordinate |
rootDraggable | IDraggable |
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
| Parameter | Type |
|---|---|
coordinate | Coordinate |
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
| Parameter | Type |
|---|---|
coordinate | Coordinate |
rootDraggable | IDraggable & IDeletable |
Returns
boolean
Inherited from
Blockly.dragging.Dragger.wouldDeleteDraggable