Skip to main content

Class: Trashcan

Defined in: packages/blockly/core/trashcan.ts:50

Class for a trash can.

Extends

Implements

Properties index

PropertyDescription
wouldDelete_Whether the last block or bubble dragged over this delete area would be deleted if dropped on this component. This property is not updated after the block or bubble is deleted.
idThe id for this component that is used to register with the ComponentManager.
isLidOpenCurrent open/close state of the lid.

Methods index

MethodDescription
wouldDeleteReturns whether the provided block or bubble would be deleted if dropped on this area. This method should check if the element is deletable and is always called before onDragEnter/onDragOver/onDragExit.
updateWouldDelete_Updates the internal wouldDelete_ state.
onDragEnterHandles when a cursor with a block or bubble enters this drag target.
shouldPreventMoveReturns whether the provided block or bubble should not be moved after being dropped on this component. If true, the element will return to where it was when the drag started.
createDomCreate the trash can elements.
initInitializes the trash can.
disposeDispose of this trash can. Unlink from all DOM elements to prevent memory leaks.
contentsIsOpenReturns true if the trashcan contents-flyout is currently open.
openFlyoutOpens the trashcan flyout.
closeFlyoutCloses the trashcan flyout.
autoHideHides the component. Called in WorkspaceSvg.hideChaff.
emptyContentsEmpties the trashcan's contents. If the contents-flyout is currently open it will be closed.
positionPositions the trashcan. It is positioned in the opposite corner to the corner the categories/toolbox starts at.
getBoundingRectangleReturns the bounding rectangle of the UI element in pixel units relative to the Blockly injection div.
getClientRectReturns the bounding rectangle of the drag target area in pixel units relative to viewport.
onDragOverHandles when a cursor with a block or bubble is dragged over this drag target.
onDragExitHandles when a cursor with a block or bubble exits this drag target.
onDropHandles when a block or bubble is dropped on this component. Should not handle delete here.
closeLidFlip the lid shut. Called externally after a drag.
clickInspect the contents of the trash.

Constructors

Constructor

new Trashcan(workspace): Trashcan;

Defined in: packages/blockly/core/trashcan.ts:96

Parameters

ParameterTypeDescription
workspaceWorkspaceSvgThe workspace to sit in.

Returns

Trashcan

Overrides

DeleteArea.constructor

Properties

wouldDelete_

protected wouldDelete_: boolean = false;

Defined in: packages/blockly/core/delete_area.ts:32

Whether the last block or bubble dragged over this delete area would be deleted if dropped on this component. This property is not updated after the block or bubble is deleted.

Inherited from

DeleteArea.wouldDelete_


id

id: string = 'trashcan';

Defined in: packages/blockly/core/trashcan.ts:58

The id for this component that is used to register with the ComponentManager.

Implementation of

IComponent.id

Overrides

DeleteArea.id


isLidOpen

isLidOpen: boolean = false;

Defined in: packages/blockly/core/trashcan.ts:81

Current open/close state of the lid.

Methods

wouldDelete()

wouldDelete(element): boolean;

Defined in: packages/blockly/core/delete_area.ts:59

Returns whether the provided block or bubble would be deleted if dropped on this area. This method should check if the element is deletable and is always called before onDragEnter/onDragOver/onDragExit.

Parameters

ParameterTypeDescription
elementIDraggableThe block or bubble currently being dragged.

Returns

boolean

Whether the element provided would be deleted if dropped on this area.

Inherited from

DeleteArea.wouldDelete


updateWouldDelete_()

protected updateWouldDelete_(wouldDelete): void;

Defined in: packages/blockly/core/delete_area.ts:78

Updates the internal wouldDelete_ state.

Parameters

ParameterTypeDescription
wouldDeletebooleanThe new value for the wouldDelete state.

Returns

void

Inherited from

DeleteArea.updateWouldDelete_


onDragEnter()

onDragEnter(_dragElement): void;

Defined in: packages/blockly/core/drag_target.ts:42

Handles when a cursor with a block or bubble enters this drag target.

Parameters

ParameterTypeDescription
_dragElementIDraggableThe block or bubble currently being dragged.

Returns

void

Inherited from

DeleteArea.onDragEnter


shouldPreventMove()

shouldPreventMove(_dragElement): boolean;

Defined in: packages/blockly/core/drag_target.ts:94

Returns whether the provided block or bubble should not be moved after being dropped on this component. If true, the element will return to where it was when the drag started.

Parameters

ParameterTypeDescription
_dragElementIDraggableThe block or bubble currently being dragged.

Returns

boolean

Whether the block or bubble provided should be returned to drag start.

Inherited from

DeleteArea.shouldPreventMove


createDom()

createDom(): SVGElement;

Defined in: packages/blockly/core/trashcan.ts:137

Create the trash can elements.

Returns

SVGElement

The trash can's SVG group.


init()

init(): void;

Defined in: packages/blockly/core/trashcan.ts:263

Initializes the trash can.

Returns

void


dispose()

dispose(): void;

Defined in: packages/blockly/core/trashcan.ts:288

Dispose of this trash can. Unlink from all DOM elements to prevent memory leaks.

Returns

void


contentsIsOpen()

contentsIsOpen(): boolean;

Defined in: packages/blockly/core/trashcan.ts:311

Returns true if the trashcan contents-flyout is currently open.

Returns

boolean

True if the trashcan contents-flyout is currently open.


openFlyout()

openFlyout(): void;

Defined in: packages/blockly/core/trashcan.ts:316

Opens the trashcan flyout.

Returns

void


closeFlyout()

closeFlyout(): void;

Defined in: packages/blockly/core/trashcan.ts:342

Closes the trashcan flyout.

Returns

void


autoHide()

autoHide(onlyClosePopups): void;

Defined in: packages/blockly/core/trashcan.ts:358

Hides the component. Called in WorkspaceSvg.hideChaff.

Parameters

ParameterTypeDescription
onlyClosePopupsbooleanWhether only popups should be closed. Flyouts should not be closed if this is true.

Returns

void

Implementation of

IAutoHideable.autoHide


emptyContents()

emptyContents(): void;

Defined in: packages/blockly/core/trashcan.ts:370

Empties the trashcan's contents. If the contents-flyout is currently open it will be closed.

Returns

void


position()

position(metrics, savedPositions): void;

Defined in: packages/blockly/core/trashcan.ts:393

Positions the trashcan. It is positioned in the opposite corner to the corner the categories/toolbox starts at.

Parameters

ParameterTypeDescription
metricsUiMetricsThe workspace metrics.
savedPositionsRect[]List of rectangles that are already on the workspace.

Returns

void

Implementation of

IPositionable.position


getBoundingRectangle()

getBoundingRectangle(): Rect | null;

Defined in: packages/blockly/core/trashcan.ts:443

Returns the bounding rectangle of the UI element in pixel units relative to the Blockly injection div.

Returns

Rect | null

The UI elements's bounding box. Null if bounding box should be ignored by other UI elements.

Implementation of

IPositionable.getBoundingRectangle


getClientRect()

getClientRect(): Rect | null;

Defined in: packages/blockly/core/trashcan.ts:456

Returns the bounding rectangle of the drag target area in pixel units relative to viewport.

Returns

Rect | null

The component's bounding box. Null if drag target area should be ignored.

Overrides

DeleteArea.getClientRect


onDragOver()

onDragOver(_dragElement): void;

Defined in: packages/blockly/core/trashcan.ts:475

Handles when a cursor with a block or bubble is dragged over this drag target.

Parameters

ParameterTypeDescription
_dragElementIDraggableThe block or bubble currently being dragged.

Returns

void

Overrides

DeleteArea.onDragOver


onDragExit()

onDragExit(_dragElement): void;

Defined in: packages/blockly/core/trashcan.ts:486

Handles when a cursor with a block or bubble exits this drag target.

Parameters

ParameterTypeDescription
_dragElementIDraggableThe block or bubble currently being dragged.

Returns

void

Overrides

DeleteArea.onDragExit


onDrop()

onDrop(_dragElement): void;

Defined in: packages/blockly/core/trashcan.ts:498

Handles when a block or bubble is dropped on this component. Should not handle delete here.

Parameters

ParameterTypeDescription
_dragElementIDraggableThe block or bubble currently being dragged.

Returns

void

Overrides

DeleteArea.onDrop


closeLid()

closeLid(): void;

Defined in: packages/blockly/core/trashcan.ts:522

Flip the lid shut. Called externally after a drag.

Returns

void


click()

click(): void;

Defined in: packages/blockly/core/trashcan.ts:527

Inspect the contents of the trash.

Returns

void