Skip to main content

Home > blockly > Toolbox

Toolbox class

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

Signature:

export declare class Toolbox extends DeleteArea implements IAutoHideable, IKeyboardAccessible, IStyleable, IToolbox, IFocusableNode 

Extends: DeleteArea

Implements: IAutoHideable, IKeyboardAccessible, IStyleable, IToolbox, IFocusableNode

Constructors

ConstructorModifiersDescription
(constructor)(workspace)Constructs a new instance of the Toolbox class

Properties

PropertyModifiersTypeDescription
boundEvents_protectedbrowserEvents.Data[]Array holding info needed to unbind event handlers. Used for disposing. Ex: [[node, name, func], [node, name, func]].
contentsprotectedMap<string, IToolboxItem>Map from ID to the corresponding toolbox item.
contentsDiv_protectedHTMLDivElement | nullThe HTML container for the contents of a toolbox.
height_protectednumberThe height of the toolbox.
HtmlDivHTMLDivElement | nullThe HTML container for the toolbox.
idstringThe unique ID for this component that is used to register with the ComponentManager.
isVisible_protectedbooleanWhether the Toolbox is visible.
previouslySelectedItem_protectedISelectableToolboxItem | nullThe previously selected item.
RTLboolean
selectedItem_protectedISelectableToolboxItem | nullThe currently selected item.
toolboxDef_protectedtoolbox.ToolboxInfo
toolboxPositiontoolbox.Position
width_protectednumberThe width of the toolbox.
workspace_protected readonlyWorkspaceSvgThe workspace this toolbox is on.

Methods

MethodModifiersDescription
addToolboxItem_(toolboxItem)protectedAdds an item to the toolbox.
attachEvents_(container, contentsContainer)protectedAdds event listeners to the toolbox container div.
autoHide(onlyClosePopups)Hides the component. Called in WorkspaceSvg.hideChaff.
canBeFocused()See IFocusableNode.canBeFocused.
clearSelection()Unhighlights any previously selected item.
createContainer_()protectedCreates the container div for the toolbox.
createContentsContainer_()protectedCreates the container for all the contents in the toolbox.
createDom_(workspace)protectedCreates the DOM for the toolbox.
createFlyout_()protectedCreates the flyout based on the toolbox layout.
deselectItem_(item)protectedDeselects the given item, marks it as unselected, and updates aria state.
dispose()Disposes of this toolbox.
getClientRect()Returns the bounding rectangle of the drag target area in pixel units relative to viewport.
getFlyout()Gets the toolbox flyout.
getFocusableElement()See IFocusableNode.getFocusableElement.
getFocusableTree()See IFocusableNode.getFocusableTree.
getHeight()Gets the height of the toolbox.
getNestedTrees()See IFocusableTree.getNestedTrees.
getPreviouslySelectedItem()Gets the previously selected item.
getRestoredFocusableNode(previousNode)See IFocusableTree.getRestoredFocusableNode.
getRootFocusableNode()See IFocusableTree.getRootFocusableNode.
getSelectedItem()Gets the selected item.
getToolboxItemById(id)Gets the toolbox item with the given ID.
getToolboxItems()Gets the items in the toolbox.
getWidth()Gets the width of the toolbox.
getWorkspace()Gets the workspace for the toolbox.
init()Initializes the toolbox
isHorizontal()Gets whether or not the toolbox is horizontal.
lookUpFocusableNode(id)See IFocusableTree.lookUpFocusableNode.
onClick_(e)protectedHandles on click events for when the toolbox or toolbox items are clicked.
onDragEnter(_dragElement)Handles when a cursor with a block or bubble enters this drag target.
onDragExit(_dragElement)Handles when a cursor with a block or bubble exits this drag target.
onDrop(_dragElement)Handles when a block or bubble is dropped on this component. Should not handle delete here.
onKeyDown_(e)protectedHandles key down events for the toolbox.
onNodeBlur()See IFocusableNode.onNodeBlur.
onNodeFocus()See IFocusableNode.onNodeFocus.
onShortcut(_shortcut)Handles the given keyboard shortcut.
onTreeBlur(nextTree)See IFocusableTree.onTreeBlur.
onTreeFocus(node, _previousTree)See IFocusableTree.onTreeFocus.
position()Positions the toolbox based on whether it is a horizontal toolbox and whether the workspace is in rtl.
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.
renderContents_(toolboxDef)protectedAdds all the toolbox items to the toolbox.
selectItem_(oldItem, newItem)protectedSelects the given item, marks it selected, and updates aria state.
selectItemByPosition(position)Selects the toolbox item by its position in the list of toolbox items.
setSelectedItem(newItem)Sets the given item as selected. No-op if the item is not selectable.
setVisible(isVisible)Shows or hides the toolbox.
shouldDeselectItem_(oldItem, newItem)protectedDecides whether the old item should be deselected.
shouldSelectItem_(oldItem, newItem)protectedDecides whether the new item should be selected.
updateCursorDeleteStyle_(addStyle)protectedAdds or removes the CSS style of the cursor over the toolbox based whether the block or bubble over it is expected to be deleted if dropped (using the internal this.wouldDelete_ property).
updateFlyout_(oldItem, newItem)protectedDecides whether to hide or show the flyout depending on the selected item.
updateWouldDelete_(wouldDelete)protectedUpdates the internal wouldDelete_ state.
wouldDelete(element)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.