Class: Trashcan
Defined in: packages/blockly/core/trashcan.ts:50
Class for a trash can.
Extends
Implements
Properties index
| Property | Description |
|---|---|
| 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. |
| id | The id for this component that is used to register with the ComponentManager. |
| isLidOpen | Current open/close state of the lid. |
Methods index
| Method | Description |
|---|---|
| wouldDelete | 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. |
| updateWouldDelete_ | Updates the internal wouldDelete_ state. |
| onDragEnter | Handles when a cursor with a block or bubble enters this drag target. |
| shouldPreventMove | 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. |
| createDom | Create the trash can elements. |
| init | Initializes the trash can. |
| dispose | Dispose of this trash can. Unlink from all DOM elements to prevent memory leaks. |
| contentsIsOpen | Returns true if the trashcan contents-flyout is currently open. |
| openFlyout | Opens the trashcan flyout. |
| closeFlyout | Closes the trashcan flyout. |
| autoHide | Hides the component. Called in WorkspaceSvg.hideChaff. |
| emptyContents | Empties the trashcan's contents. If the contents-flyout is currently open it will be closed. |
| position | Positions the trashcan. It is positioned in the opposite corner to the corner the categories/toolbox starts at. |
| getBoundingRectangle | Returns the bounding rectangle of the UI element in pixel units relative to the Blockly injection div. |
| getClientRect | Returns the bounding rectangle of the drag target area in pixel units relative to viewport. |
| onDragOver | Handles when a cursor with a block or bubble is dragged over this drag target. |
| onDragExit | Handles when a cursor with a block or bubble exits this drag target. |
| onDrop | Handles when a block or bubble is dropped on this component. Should not handle delete here. |
| closeLid | Flip the lid shut. Called externally after a drag. |
| click | Inspect the contents of the trash. |
Constructors
Constructor
new Trashcan(workspace): Trashcan;
Defined in: packages/blockly/core/trashcan.ts:96
Parameters
| Parameter | Type | Description |
|---|---|---|
workspace | WorkspaceSvg | The workspace to sit in. |
Returns
Trashcan
Overrides
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
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
Overrides
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
| Parameter | Type | Description |
|---|---|---|
element | IDraggable | The block or bubble currently being dragged. |
Returns
boolean
Whether the element provided would be deleted if dropped on this area.
Inherited from
updateWouldDelete_()
protected updateWouldDelete_(wouldDelete): void;
Defined in: packages/blockly/core/delete_area.ts:78
Updates the internal wouldDelete_ state.
Parameters
| Parameter | Type | Description |
|---|---|---|
wouldDelete | boolean | The new value for the wouldDelete state. |
Returns
void
Inherited from
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
| Parameter | Type | Description |
|---|---|---|
_dragElement | IDraggable | The block or bubble currently being dragged. |
Returns
void
Inherited from
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
| Parameter | Type | Description |
|---|---|---|
_dragElement | IDraggable | The block or bubble currently being dragged. |
Returns
boolean
Whether the block or bubble provided should be returned to drag start.
Inherited from
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
| Parameter | Type | Description |
|---|---|---|
onlyClosePopups | boolean | Whether only popups should be closed. Flyouts should not be closed if this is true. |
Returns
void
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
metrics | UiMetrics | The workspace metrics. |
savedPositions | Rect[] | List of rectangles that are already on the workspace. |
Returns
void
Implementation of
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
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
| Parameter | Type | Description |
|---|---|---|
_dragElement | IDraggable | The block or bubble currently being dragged. |
Returns
void
Overrides
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
| Parameter | Type | Description |
|---|---|---|
_dragElement | IDraggable | The block or bubble currently being dragged. |
Returns
void
Overrides
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
| Parameter | Type | Description |
|---|---|---|
_dragElement | IDraggable | The block or bubble currently being dragged. |
Returns
void
Overrides
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