Class: Trashcan

Constructor

Trashcan

new Trashcan(workspace)

Class for a trash can.

Parameter

workspace

Blockly.WorkspaceSvg

The workspace to sit in.

Value must not be null.

Extends
Blockly.DeleteArea
Implements
Blockly.IAutoHideable
Blockly.IPositionable

Properties

flyout

package

Blockly.IFlyout

The trashcan flyout.

id

string

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

isLidOpen

boolean

Current open/close state of the lid.

wouldDelete_

protected

unknown

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
Blockly.DeleteArea#wouldDelete_

Methods

autoHide

autoHide(onlyClosePopups)

Hides the component. Called in Blockly.hideChaff.

Parameter

onlyClosePopups

boolean

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

Implements
Blockly.IAutoHideable#autoHide

click

click()

Inspect the contents of the trash.

closeFlyout

closeFlyout()

Closes the trashcan flyout.

closeLid

closeLid()

Flip the lid shut. Called externally after a drag.

contentsIsOpen

contentsIsOpen() returns boolean

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

Returns

boolean True if the trashcan contents-flyout is currently open.

createDom

createDom() returns SVGElement

Create the trash can elements.

Returns

non-null SVGElement The trash can's SVG group.

dispose

dispose()

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

emptyContents

emptyContents()

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

getBoundingRectangle

getBoundingRectangle() returns Blockly.utils.Rect

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

Implements
Blockly.IPositionable#getBoundingRectangle
Returns

nullable Blockly.utils.Rect The UI elements’s bounding box. Null if bounding box should be ignored by other UI elements.

getClientRect

getClientRect() returns Blockly.utils.Rect

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

Returns

nullable Blockly.utils.Rect The component's bounding box. Null if drag target area should be ignored.

init

init()

Initializes the trash can.

onDragEnter

onDragEnter(_dragElement)

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

Parameter

_dragElement

The block or bubble currently being dragged.

Value must not be null.

Inherited from
Blockly.DragTarget#onDragEnter
Implements
Blockly.IDragTarget#onDragEnter

onDragExit

onDragExit(_dragElement)

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

Parameter

_dragElement

The block or bubble currently being dragged.

Value must not be null.

Inherited from
Blockly.DragTarget#onDragExit
Implements
Blockly.IDragTarget#onDragExit

onDragOver

onDragOver(_dragElement)

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

Parameter

_dragElement

The block or bubble currently being dragged.

Value must not be null.

Inherited from
Blockly.DragTarget#onDragOver
Implements
Blockly.IDragTarget#onDragOver

onDrop

onDrop(_dragElement)

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

Parameter

_dragElement

The block or bubble currently being dragged.

Value must not be null.

Inherited from
Blockly.DragTarget#onDrop
Implements
Blockly.IDragTarget#onDrop

openFlyout

openFlyout()

Opens the trashcan flyout.

position

position(metrics, savedPositions)

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

Parameter

metrics

Blockly.MetricsManager.UiMetrics

The workspace metrics.

Value must not be null.

savedPositions

Array of non-null Blockly.utils.Rect

List of rectangles that are already on the workspace.

Value must not be null.

Implements
Blockly.IPositionable#position

setLidOpen

package

setLidOpen(state)

Flip the lid open or shut.

Parameter

state

boolean

True if open.

shouldPreventMove

shouldPreventMove(_dragElement) returns boolean

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.

Parameter

_dragElement

The block or bubble currently being dragged.

Value must not be null.

Inherited from
Blockly.DragTarget#shouldPreventMove
Implements
Blockly.IDragTarget#shouldPreventMove
Returns

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

updateWouldDelete_

protected

updateWouldDelete_(wouldDelete)

Updates the internal wouldDelete_ state.

Parameter

wouldDelete

The new value for the wouldDelete state.

Inherited from
Blockly.DeleteArea#updateWouldDelete_

wouldDelete

wouldDelete(element, couldConnect) returns boolean

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.

Parameter

element

The block or bubble currently being dragged.

Value must not be null.

couldConnect

Whether the element could could connect to another.

Inherited from
Blockly.DeleteArea#wouldDelete
Implements
Blockly.IDeleteArea#wouldDelete
Returns

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