Class: Backpack
Defined in: plugins/workspace-backpack/src/backpack.ts:27
Class for backpack that can be used save blocks from the workspace for future use.
Extends
DragTarget
Implements
IComponentIContextMenuIAutoHideableIPositionableIFocusableNode
Properties index
| Property | Description |
|---|---|
| contents_ | A list of JSON (stored as strings) representing blocks in the backpack. |
| flyout_ | The backpack flyout. Initialized during init. |
| HEIGHT_ | Height of the backpack in pixels. Used for clip path. |
| HOTSPOT_MARGIN_ | Extent of hotspot on all sides beyond the size of the image in pixels. |
| id | The unique id for this component. |
| initialized_ | Whether or not the plugin has been initialized. |
| left_ | Left coordinate of the backpack in pixels. |
| MARGIN_HORIZONTAL_ | Distance between backpack and right/left edge of workspace in pixels. |
| MARGIN_VERTICAL_ | Distance between backpack and bottom/top edge of workspace in pixels. |
| svgGroup_ | The SVG group containing the backpack. |
| svgImg_ | The SVG image of the backpack. |
| top_ | Top coordinate of the backpack in pixels. |
| WIDTH_ | Width of the backpack in pixels. Used for clip path. |
| workspace_ | The target workspace that the backpack will be added to. |
Methods index
| Method | Description |
|---|---|
| addBackpackable | - |
| addBackpackables | - |
| addBlock | Adds the specified block to backpack. |
| addBlocks | Adds the provided blocks to backpack. |
| addItem | Adds item to backpack. |
| addItems | Adds multiple items to the backpack. |
| attachListeners | Attaches event listeners. |
| autoHide | Hides the component. Called in Blockly.hideChaff. |
| blockMouseDownWhenOpenable | Prevents a workspace scroll and click event if the backpack is openable. |
| canBeFocused | Indicates whether this node allows focus. If this returns false then none of the other IFocusableNode methods will be called. |
| close | Closes the backpack flyout. |
| containsBackpackable | Returns whether the backpack contains a duplicate of the provided backpackable. |
| containsBlock | Returns whether the backpack contains a duplicate of the provided Block. |
| createDom | Creates DOM for UI element. |
| dispose | Disposes of workspace search. Unlink from all DOM elements and remove all event listeners to prevent memory leaks. |
| empty | Empties the backpack's contents. If the contents-flyout is currently open it will be closed. |
| 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. |
| getContents | Returns backpack contents. |
| getCount | Returns the count of items in the backpack. |
| getFlyout | Returns the backpack flyout. |
| getFocusableElement | Returns the DOM element that can be explicitly requested to receive focus. |
| getFocusableTree | Returns the closest parent tree of this node (in cases where a tree has distinct trees underneath it), which represents the tree to which this node belongs. |
| init | Initializes the backpack. |
| initFlyout | Creates and initializes the flyout and inserts it into the dom. |
| isOpen | Returns whether the backpack is open. |
| isOpenable | Returns whether the backpack is open-able. |
| maybeRefreshFlyoutContents | Refreshes backpack flyout contents if the flyout is open. |
| onClick | Handle click event. |
| onContentChange | Handles content change. |
| onDragEnter | Handles when a cursor with a block or bubble enters this drag target. |
| onDragExit | Handles when a cursor with a block or bubble exits this drag target. |
| onDragOver | Handles when a cursor with a block or bubble is dragged over this drag target. |
| onDrop | Handles when a block or bubble is dropped on this component. Should not handle delete here. |
| onNodeBlur | Called when this node loses active focus. It may still have passive focus. |
| onNodeFocus | Called when this node receives active focus. |
| open | Opens the backpack flyout. |
| performAction | Optional method invoked when this node has focus and the user acts on it by pressing Enter or Space. Behavior should generally be similar to the node being clicked on. |
| position | Positions the backpack. It is positioned in the opposite corner to the corner the categories/toolbox starts at. |
| removeBackpackable | - |
| removeBlock | Removes the specified block from the backpack. |
| removeItem | Removes item from the backpack. |
| setContents | Sets backpack contents. |
| 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. |
| showContextMenu | Show the context menu for the backpack. |
| updateHoverStying | Adds or removes styling to darken the backpack to show it is interactable. |
Constructors
Constructor
new Backpack(workspace_, backpackOptions?): Backpack;
Defined in: plugins/workspace-backpack/src/backpack.ts:102
Constructor for a backpack.
Parameters
| Parameter | Type | Description |
|---|---|---|
workspace_ | WorkspaceSvg | The target workspace that the backpack will be added to. |
backpackOptions? | BackpackOptions | The backpack options to use. |
Returns
Backpack
Overrides
Blockly.DragTarget.constructor
Properties
contents_
protected contents_: string[] = [];
Defined in: plugins/workspace-backpack/src/backpack.ts:51
A list of JSON (stored as strings) representing blocks in the backpack.
flyout_
protected flyout_: IFlyout | null = null;
Defined in: plugins/workspace-backpack/src/backpack.ts:48
The backpack flyout. Initialized during init.
HEIGHT_
protected readonly HEIGHT_: 60 = 60;
Defined in: plugins/workspace-backpack/src/backpack.ts:66
Height of the backpack in pixels. Used for clip path.
HOTSPOT_MARGIN_
protected readonly HOTSPOT_MARGIN_: 10 = 10;
Defined in: plugins/workspace-backpack/src/backpack.ts:75
Extent of hotspot on all sides beyond the size of the image in pixels.
id
id: string = 'backpack';
Defined in: plugins/workspace-backpack/src/backpack.ts:38
The unique id for this component.
Implementation of
Blockly.IComponent.id
Overrides
Blockly.DragTarget.id
initialized_
protected initialized_: boolean = false;
Defined in: plugins/workspace-backpack/src/backpack.ts:93
Whether or not the plugin has been initialized.
left_
protected left_: number = 0;
Defined in: plugins/workspace-backpack/src/backpack.ts:57
Left coordinate of the backpack in pixels.
MARGIN_HORIZONTAL_
protected readonly MARGIN_HORIZONTAL_: 20 = 20;
Defined in: plugins/workspace-backpack/src/backpack.ts:72
Distance between backpack and right/left edge of workspace in pixels.
MARGIN_VERTICAL_
protected readonly MARGIN_VERTICAL_: 20 = 20;
Defined in: plugins/workspace-backpack/src/backpack.ts:69
Distance between backpack and bottom/top edge of workspace in pixels.
svgGroup_
protected svgGroup_: SVGElement | null = null;
Defined in: plugins/workspace-backpack/src/backpack.ts:78
The SVG group containing the backpack.
svgImg_
protected svgImg_: SVGImageElement | null = null;
Defined in: plugins/workspace-backpack/src/backpack.ts:81
The SVG image of the backpack.
top_
protected top_: number = 0;
Defined in: plugins/workspace-backpack/src/backpack.ts:60
Top coordinate of the backpack in pixels.
WIDTH_
protected readonly WIDTH_: 40 = 40;
Defined in: plugins/workspace-backpack/src/backpack.ts:63
Width of the backpack in pixels. Used for clip path.
workspace_
protected workspace_: WorkspaceSvg;
Defined in: plugins/workspace-backpack/src/backpack.ts:103
The target workspace that the backpack will be added to.
Methods
addBackpackable()
addBackpackable(backpackable): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:650
Parameters
| Parameter | Type | Description |
|---|---|---|
backpackable | Backpackable | The backpackable to add to the backpack. |
Returns
void
addBackpackables()
addBackpackables(backpackables): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:655
Parameters
| Parameter | Type | Description |
|---|---|---|
backpackables | Backpackable[] | The backpackables to add to the backpack. |
Returns
void
addBlock()
addBlock(block): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:598
Adds the specified block to backpack.
Parameters
| Parameter | Type | Description |
|---|---|---|
block | Block | The block to be added to the backpack. |
Returns
void
addBlocks()
addBlocks(blocks): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:612
Adds the provided blocks to backpack.
Parameters
| Parameter | Type | Description |
|---|---|---|
blocks | Block[] | The blocks to be added to the backpack. |
Returns
void
addItem()
addItem(item): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:680
Adds item to backpack.
Parameters
| Parameter | Type | Description |
|---|---|---|
item | string | Text representing the JSON of a block to add, cleaned of all unnecessary attributes. |
Returns
void
addItems()
addItems(items): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:689
Adds multiple items to the backpack.
Parameters
| Parameter | Type | Description |
|---|---|---|
items | string[] | The backpack contents to add. |
Returns
void
attachListeners()
protected attachListeners(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:301
Attaches event listeners.
Returns
void
autoHide()
autoHide(onlyClosePopups): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:861
Hides the component. Called in Blockly.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
Blockly.IAutoHideable.autoHide
blockMouseDownWhenOpenable()
protected blockMouseDownWhenOpenable(e): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:960
Prevents a workspace scroll and click event if the backpack is openable.
Parameters
| Parameter | Type | Description |
|---|---|---|
e | Event | A mouse down event. |
Returns
void
canBeFocused()
canBeFocused(): boolean;
Defined in: plugins/workspace-backpack/src/backpack.ts:990
Indicates whether this node allows focus. If this returns false then none of the other IFocusableNode methods will be called.
Note that special care must be taken if implementations of this function dynamically change their return value value over the lifetime of the node as certain environment conditions could affect the focusability of this node's DOM element (such as whether the element has a positive or zero tabindex). Also, changing from a true to a false value while the node holds focus will not immediately change the current focus of the node nor FocusManager's internal state, and thus may result in some of the node's functions being called later on when defocused (since it was previously considered focusable at the time of being focused).
Implementations should generally always return true here unless there are circumstances under which this node should be skipped for focus considerations. Examples may include being disabled, read-only, a purely visual decoration, or a node with no visual representation that must implement this interface (e.g. due to a parent interface extending it). Keep in mind accessibility best practices when determining whether a node should be focusable since even disabled and read-only elements are still often relevant to providing organizational context to users (particularly when using a screen reader).
Returns
boolean
Whether this node can be focused by FocusManager.
Implementation of
Blockly.IFocusableNode.canBeFocused
close()
close(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:840
Closes the backpack flyout.
Returns
void
containsBackpackable()
containsBackpackable(backpackable): boolean;
Defined in: plugins/workspace-backpack/src/backpack.ts:641
Parameters
| Parameter | Type | Description |
|---|---|---|
backpackable | Backpackable | The backpackable we want to check for existence within the backpack. |
Returns
boolean
whether the backpack contains a duplicate of the provided backpackable.
containsBlock()
containsBlock(block): boolean;
Defined in: plugins/workspace-backpack/src/backpack.ts:585
Returns whether the backpack contains a duplicate of the provided Block.
Parameters
| Parameter | Type | Description |
|---|---|---|
block | Block | The block to check. |
Returns
boolean
Whether the backpack contains a duplicate of the provided block.
createDom()
protected createDom(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:228
Creates DOM for UI element.
Returns
void
dispose()
dispose(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:161
Disposes of workspace search. Unlink from all DOM elements and remove all event listeners to prevent memory leaks.
Returns
void
empty()
empty(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:734
Empties the backpack's contents. If the contents-flyout is currently open it will be closed.
Returns
void
getBoundingRectangle()
getBoundingRectangle(): Rect;
Defined in: plugins/workspace-backpack/src/backpack.ts:367
Returns the bounding rectangle of the UI element in pixel units relative to the Blockly injection div.
Returns
Rect
The component’s bounding box.
Implementation of
Blockly.IPositionable.getBoundingRectangle
getClientRect()
getClientRect(): Rect | null;
Defined in: plugins/workspace-backpack/src/backpack.ts:348
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
Blockly.DragTarget.getClientRect
getContents()
getContents(): string[];
Defined in: plugins/workspace-backpack/src/backpack.ts:479
Returns backpack contents.
Returns
string[]
The backpack contents.
getCount()
getCount(): number;
Defined in: plugins/workspace-backpack/src/backpack.ts:470
Returns the count of items in the backpack.
Returns
number
The count of items.
getFlyout()
getFlyout(): IFlyout | null;
Defined in: plugins/workspace-backpack/src/backpack.ts:337
Returns the backpack flyout.
Returns
IFlyout | null
The backpack flyout.
getFocusableElement()
getFocusableElement(): SVGElement | HTMLElement;
Defined in: plugins/workspace-backpack/src/backpack.ts:974
Returns the DOM element that can be explicitly requested to receive focus.
IMPORTANT: Please note that this element is expected to have a visual presence on the page as it will both be explicitly focused and have its style changed depending on its current focus state (i.e. blurred, actively focused, and passively focused). The element will have one of two styles attached (where no style indicates blurred/not focused):
- blocklyActiveFocus
- blocklyPassiveFocus
The returned element must also have a valid ID specified, and this ID should be unique across the entire page. Failing to have a properly unique ID could result in trying to focus one node (such as via a mouse click) leading to another node with the same ID actually becoming focused by FocusManager.
The returned element must be visible if the node is ever focused via FocusManager.focusNode() or FocusManager.focusTree(). It's allowed for an element to be hidden until onNodeFocus() is called, or become hidden with a call to onNodeBlur().
It's expected the actual returned element will not change for the lifetime of the node (that is, its properties can change but a new element should never be returned). Also, the returned element will have its tabindex overwritten throughout the lifecycle of this node and FocusManager.
If a node requires the ability to be focused directly without first being focused via FocusManager then it must set its own tab index.
Returns
SVGElement | HTMLElement
The HTMLElement or SVGElement which can both receive focus and be visually represented as actively or passively focused for this node.
Implementation of
Blockly.IFocusableNode.getFocusableElement
getFocusableTree()
getFocusableTree(): IFocusableTree;
Defined in: plugins/workspace-backpack/src/backpack.ts:982
Returns the closest parent tree of this node (in cases where a tree has distinct trees underneath it), which represents the tree to which this node belongs.
Returns
IFocusableTree
The node's IFocusableTree.
Implementation of
Blockly.IFocusableNode.getFocusableTree
init()
init(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:135
Initializes the backpack.
Returns
void
initFlyout()
protected initFlyout(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:174
Creates and initializes the flyout and inserts it into the dom.
Returns
void
isOpen()
isOpen(): boolean;
Defined in: plugins/workspace-backpack/src/backpack.ts:797
Returns whether the backpack is open.
Returns
boolean
Whether the backpack is open.
isOpenable()
protected isOpenable(): boolean;
Defined in: plugins/workspace-backpack/src/backpack.ts:786
Returns whether the backpack is open-able.
Returns
boolean
Whether the backpack is open-able.
maybeRefreshFlyoutContents()
protected maybeRefreshFlyoutContents(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:829
Refreshes backpack flyout contents if the flyout is open.
Returns
void
onClick()
protected onClick(e?): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:874
Handle click event.
Parameters
| Parameter | Type | Description |
|---|---|---|
e? | Event | Mouse event. |
Returns
void
onContentChange()
protected onContentChange(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:748
Handles content change.
Returns
void
onDragEnter()
onDragEnter(dragElement): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:893
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
Overrides
Blockly.DragTarget.onDragEnter
onDragExit()
onDragExit(dragElement): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:905
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
Blockly.DragTarget.onDragExit
onDragOver()
onDragOver(_dragElement): void;
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
Inherited from
Blockly.DragTarget.onDragOver
onDrop()
onDrop(dragElement): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:491
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
Blockly.DragTarget.onDrop
onNodeBlur()
onNodeBlur(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:988
Called when this node loses active focus. It may still have passive focus.
This has the same implementation restrictions as onNodeFocus().
Returns
void
Implementation of
Blockly.IFocusableNode.onNodeBlur
onNodeFocus()
onNodeFocus(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:986
Called when this node receives active focus.
Note that it's fine for implementations to change visibility modifiers, but they should avoid the following:
- Creating or removing DOM elements (including via the renderer or drawer).
- Affecting focus via DOM focus() calls or the FocusManager.
Implementations may consider scrolling themselves into view here; that is not handled by the focus manager.
Returns
void
Implementation of
Blockly.IFocusableNode.onNodeFocus
open()
open(): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:804
Opens the backpack flyout.
Returns
void
performAction()
performAction(e?): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:994
Optional method invoked when this node has focus and the user acts on it by pressing Enter or Space. Behavior should generally be similar to the node being clicked on.
Parameters
| Parameter | Type | Description |
|---|---|---|
e? | Event | The event that triggered this action, if any. |
Returns
void
Implementation of
Blockly.IFocusableNode.performAction
position()
position(metrics, savedPositions): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:385
Positions the backpack. 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
Blockly.IPositionable.position
removeBackpackable()
removeBackpackable(backpackable): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:668
Parameters
| Parameter | Type | Description |
|---|---|---|
backpackable | Backpackable | The backpackable to remove from the backpack. |
Returns
void
removeBlock()
removeBlock(block): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:627
Removes the specified block from the backpack.
Parameters
| Parameter | Type | Description |
|---|---|---|
block | Block | The block to be removed from the backpack. |
Returns
void
removeItem()
removeItem(item): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:703
Removes item from the backpack.
Parameters
| Parameter | Type | Description |
|---|---|---|
item | string | Text representing the JSON of a block to remove, cleaned of all unnecessary attributes. |
Returns
void
setContents()
setContents(contents): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:716
Sets backpack contents.
Parameters
| Parameter | Type | Description |
|---|---|---|
contents | string[] | The new backpack contents. |
Returns
void
shouldPreventMove()
shouldPreventMove(dragElement): boolean;
Defined in: plugins/workspace-backpack/src/backpack.ts:951
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.
Overrides
Blockly.DragTarget.shouldPreventMove
showContextMenu()
showContextMenu(e): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:1003
Show the context menu for the backpack.
Parameters
| Parameter | Type | Description |
|---|---|---|
e | Event | Event that triggered the display of the context menu. |
Returns
void
Implementation of
Blockly.IContextMenu.showContextMenu
updateHoverStying()
protected updateHoverStying(addClass): void;
Defined in: plugins/workspace-backpack/src/backpack.ts:930
Adds or removes styling to darken the backpack to show it is interactable.
Parameters
| Parameter | Type | Description |
|---|---|---|
addClass | boolean | True to add styling, false to remove. |
Returns
void