Class: Toolbox

Constructor

Toolbox

new Toolbox(workspace)

Class for a Toolbox. Creates the toolbox's DOM.

Parameter

workspace

Blockly.WorkspaceSvg

The workspace in which to create new blocks.

Value must not be null.

Implements
Blockly.IBlocklyActionable
Blockly.IDeleteArea
Blockly.IStyleable
Blockly.IToolbox

Properties

boundEvents_

protected

non-null Array of non-null Blockly.EventData

Array holding info needed to unbind event handlers. Used for disposing. Ex: [[node, name, func], [node, name, func]].

contentMap_

protected

non-null Object with Blockly.IToolboxItem properties

A map from toolbox item IDs to toolbox items.

contents_

protected

non-null Array of non-null Blockly.IToolboxItem

The list of items in the toolbox.

contentsDiv_

non-null Element

contentsDiv_

non-null Element

contentsDiv_

protected

nullable Element

The html container for the contents of a toolbox.

height_

protected

number

The height of the toolbox.

HtmlDiv

non-null Element

HtmlDiv

nullable Element

The html container for the toolbox.

HtmlDiv

non-null Element

previouslySelectedItem_

protected

nullable Blockly.ISelectableToolboxItem

The previously selected item.

RTL

boolean

Is RTL vs LTR.

selectedItem_

non-null Blockly.ICollapsibleToolboxItem

selectedItem_

protected

nullable Blockly.ISelectableToolboxItem

The currently selected item.

selectedItem_

non-null Blockly.ICollapsibleToolboxItem

selectedItem_

Blockly.ICollapsibleToolboxItem

toolboxDef_

protected

non-null Blockly.utils.toolbox.ToolboxInfo

The JSON describing the contents of this toolbox.

toolboxPosition

non-null Blockly.utils.toolbox.Position

Position of the toolbox and flyout relative to the workspace.

width_

protected

number

The width of the toolbox.

workspace_

protected

non-null Blockly.WorkspaceSvg

The workspace this toolbox is on.

Methods

addStyle

package

addStyle(style)

Adds a style on the toolbox. Usually used to change the cursor.

Parameter

style

string

The name of the class to add.

Implements
Blockly.IStyleable#addStyle

addToolboxItem_

protected

addToolboxItem_(toolboxItem)

Adds an item to the toolbox.

Parameter

toolboxItem

Blockly.IToolboxItem

The item in the toolbox.

Value must not be null.

attachEvents_

protected

attachEvents_(container, contentsContainer)

Adds event listeners to the toolbox container div.

Parameter

container

Element

The html container for the toolbox.

Value must not be null.

contentsContainer

Element

The html container for the contents of the toolbox.

Value must not be null.

clearSelection

public

clearSelection()

Unhighlights any previously selected item.

Implements
Blockly.IToolbox#clearSelection

createContainer_

protected

createContainer_() returns Element

Creates the container div for the toolbox.

Returns

non-null Element The html container for the toolbox.

createContentsContainer_

protected

createContentsContainer_() returns Element

Creates the container for all the contents in the toolbox.

Returns

non-null Element The html container for the toolbox contents.

createDom_

protected

createDom_(workspace) returns Element

Creates the dom for the toolbox.

Parameter

workspace

Blockly.WorkspaceSvg

The workspace this toolbox is on.

Value must not be null.

Returns

non-null Element The html container for the toolbox.

createFlyout_

protected

createFlyout_() returns Blockly.IFlyout

Creates the flyout based on the toolbox layout.

Throws

Error If missing a require for Blockly.HorizontalFlyout, Blockly.VerticalFlyout, and no flyout plugin is specified.

Returns

non-null Blockly.IFlyout The flyout for the toolbox.

deselectItem_

protected

deselectItem_(item)

Deselects the given item, marks it as unselected, and updates aria state.

Parameter

item

Blockly.ISelectableToolboxItem

The previously selected toolbox item which should be deselected.

Value must not be null.

dispose

public

dispose()

Disposes of this toolbox.

Implements
Blockly.IToolbox#dispose

getClientRect

public

getClientRect() returns Blockly.utils.Rect

Return the deletion rectangle for this toolbox.

Implements
Blockly.IDeleteArea#getClientRect
Returns

nullable Blockly.utils.Rect Rectangle in which to delete.

getFlyout

public

getFlyout() returns Blockly.IFlyout

Gets the toolbox flyout.

Implements
Blockly.IToolbox#getFlyout
Returns

nullable Blockly.IFlyout The toolbox flyout.

getHeight

public

getHeight() returns number

Gets the height of the toolbox.

Implements
Blockly.IToolbox#getHeight
Returns

number The width of the toolbox.

getPreviouslySelectedItem

public

getPreviouslySelectedItem() returns Blockly.ISelectableToolboxItem

Gets the previously selected item.

Returns

nullable Blockly.ISelectableToolboxItem The previously selected item, or null if no item was previously selected.

getSelectedItem

public

getSelectedItem() returns Blockly.ISelectableToolboxItem

Gets the selected item.

Implements
Blockly.IToolbox#getSelectedItem
Returns

nullable Blockly.ISelectableToolboxItem The selected item, or null if no item is currently selected.

getToolboxItemById

public

getToolboxItemById(id) returns Blockly.IToolboxItem

Gets the toolbox item with the given id.

Parameter

id

string

The id of the toolbox item.

Returns

nullable Blockly.IToolboxItem The toolbox item with the given id, or null if no item exists.

getToolboxItems

public

getToolboxItems() returns Array of non-null Blockly.IToolboxItem

Gets the items in the toolbox.

Returns

non-null Array of non-null Blockly.IToolboxItem The list of items in the toolbox.

getWidth

public

getWidth() returns number

Gets the width of the toolbox.

Implements
Blockly.IToolbox#getWidth
Returns

number The width of the toolbox.

getWorkspace

public

getWorkspace() returns Blockly.WorkspaceSvg

Gets the workspace for the toolbox.

Implements
Blockly.IToolbox#getWorkspace
Returns

non-null Blockly.WorkspaceSvg The parent workspace for the toolbox.

handleToolboxItemResize

package

handleToolboxItemResize()

Handles resizing the toolbox when a toolbox item resizes.

Implements
Blockly.IToolbox#handleToolboxItemResize

init

public

init()

Initializes the toolbox

Implements
Blockly.IToolbox#init

isHorizontal

public

isHorizontal() returns boolean

Gets whether or not the toolbox is horizontal.

Implements
Blockly.IToolbox#isHorizontal
Returns

boolean True if the toolbox is horizontal, false if the toolbox is vertical.

onBlocklyAction

package

onBlocklyAction(action) returns boolean

Handles the given Blockly action on a toolbox. This is only triggered when keyboard accessibility mode is enabled.

Parameter

action

Blockly.Action

The action to be handled.

Value must not be null.

Implements
Blockly.IBlocklyActionable#onBlocklyAction
Returns

boolean True if the field handled the action, false otherwise.

onClick_

protected

onClick_(e)

Handles on click events for when the toolbox or toolbox items are clicked.

Parameter

e

Event

Click event to handle.

Value must not be null.

onKeyDown_

protected

onKeyDown_(e)

Handles key down events for the toolbox.

Parameter

e

KeyboardEvent

The key down event.

Value must not be null.

position

public

position()

Positions the toolbox based on whether it is a horizontal toolbox and whether the workspace is in rtl.

Implements
Blockly.IToolbox#position

refreshSelection

public

refreshSelection()

Updates the flyout's content without closing it. Should be used in response to a change in one of the dynamic categories, such as variables or procedures.

Implements
Blockly.IToolbox#refreshSelection

refreshTheme

package

refreshTheme()

Updates the category colours and background colour of selected categories.

Implements
Blockly.IToolbox#refreshTheme

removeStyle

package

removeStyle(style)

Removes a style from the toolbox. Usually used to change the cursor.

Parameter

style

string

The name of the class to remove.

Implements
Blockly.IStyleable#removeStyle

render

package

render(toolboxDef)

Fills the toolbox with new toolbox items and removes any old contents.

Parameter

toolboxDef

Blockly.utils.toolbox.ToolboxInfo

Object holding information for creating a toolbox.

Value must not be null.

Implements
Blockly.IToolbox#render

renderContents_

protected

renderContents_(toolboxDef)

Adds all the toolbox items to the toolbox.

Parameter

toolboxDef

Array of non-null Blockly.utils.toolbox.ToolboxItemInfo

Array holding objects containing information on the contents of the toolbox.

Value must not be null.

selectItem_

protected

selectItem_(oldItem, newItem)

Selects the given item, marks it selected, and updates aria state.

Parameter

oldItem

Blockly.ISelectableToolboxItem

The previously selected toolbox item.

Value may be null.

newItem

Blockly.ISelectableToolboxItem

The newly selected toolbox item.

Value must not be null.

selectItemByPosition

public

selectItemByPosition(position)

Selects the toolbox item by its position in the list of toolbox items.

Parameter

position

number

The position of the item to select.

Implements
Blockly.IToolbox#selectItemByPosition

setSelectedItem

public

setSelectedItem(newItem)

Sets the given item as selected. No-op if the item is not selectable.

Parameter

newItem

Blockly.IToolboxItem

The toolbox item to select.

Value may be null.

setVisible

public

setVisible(isVisible)

Shows or hides the toolbox.

Parameter

isVisible

boolean

True if toolbox should be visible.

Implements
Blockly.IToolbox#setVisible

shouldDeselectItem_

protected

shouldDeselectItem_(oldItem, newItem) returns boolean

Decides whether the old item should be deselected.

Parameter

oldItem

Blockly.ISelectableToolboxItem

The previously selected toolbox item.

Value may be null.

newItem

Blockly.ISelectableToolboxItem

The newly selected toolbox item.

Value may be null.

Returns

boolean True if the old item should be deselected, false otherwise.

shouldSelectItem_

protected

shouldSelectItem_(oldItem, newItem) returns boolean

Decides whether the new item should be selected.

Parameter

oldItem

Blockly.ISelectableToolboxItem

The previously selected toolbox item.

Value may be null.

newItem

Blockly.ISelectableToolboxItem

The newly selected toolbox item.

Value may be null.

Returns

boolean True if the new item should be selected, false otherwise.

updateFlyout_

protected

updateFlyout_(oldItem, newItem)

Decides whether to hide or show the flyout depending on the selected item.

Parameter

oldItem

Blockly.ISelectableToolboxItem

The previously selected toolbox item.

Value may be null.

newItem

Blockly.ISelectableToolboxItem

The newly selected toolbox item.

Value may be null.