Blockly. Toolbox
Constructor
Toolbox
new Toolbox(workspace)
Class for a Toolbox. Creates the toolbox's DOM.
Parameter |
|
---|---|
workspace |
The workspace in which to create new blocks. Value must not be null. |
Properties
boundEvents_
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_
non-null Object with Blockly.IToolboxItem properties
A map from toolbox item IDs to toolbox items.
contents_
non-null Array of non-null Blockly.IToolboxItem
The list of items in the toolbox.
contentsDiv_
nullable Element
The html container for the contents of a toolbox.
contentsDiv_
non-null Element
contentsDiv_
non-null Element
height_
number
The height of the toolbox.
HtmlDiv
nullable Element
The html container for the toolbox.
HtmlDiv
non-null Element
HtmlDiv
non-null Element
previouslySelectedItem_
nullable Blockly.ISelectableToolboxItem
The previously selected item.
RTL
boolean
Is RTL vs LTR.
selectedItem_
nullable Blockly.ISelectableToolboxItem
The currently selected item.
selectedItem_
non-null Blockly.ICollapsibleToolboxItem
selectedItem_
non-null Blockly.ICollapsibleToolboxItem
selectedItem_
Blockly.ICollapsibleToolboxItem
toolboxDef_
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_
number
The width of the toolbox.
workspace_
non-null Blockly.WorkspaceSvg
The workspace this toolbox is on.
Methods
addStyle
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_
addToolboxItem_(toolboxItem)
Adds an item to the toolbox.
Parameter |
|
---|---|
toolboxItem |
The item in the toolbox. Value must not be null. |
attachEvents_
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
clearSelection()
Unhighlights any previously selected item.
- Implements
- Blockly.IToolbox#clearSelection
createContainer_
createContainer_() returns Element
Creates the container div for the toolbox.
- Returns
-
non-null Element
The html container for the toolbox.
createContentsContainer_
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_
createDom_(workspace) returns Element
Creates the dom for the toolbox.
Parameter |
|
---|---|
workspace |
The workspace this toolbox is on. Value must not be null. |
- Returns
-
non-null Element
The html container for the toolbox.
createFlyout_
createFlyout_() returns Blockly.IFlyout
Creates the flyout based on the toolbox layout.
- Throws
-
Error
If missing a require forBlockly.HorizontalFlyout
,Blockly.VerticalFlyout
, and no flyout plugin is specified. - Returns
-
non-null Blockly.IFlyout
The flyout for the toolbox.
deselectItem_
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
dispose()
Disposes of this toolbox.
- Implements
- Blockly.IToolbox#dispose
getClientRect
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
getFlyout() returns Blockly.IFlyout
Gets the toolbox flyout.
- Implements
- Blockly.IToolbox#getFlyout
- Returns
-
nullable Blockly.IFlyout
The toolbox flyout.
getHeight
getHeight() returns number
Gets the height of the toolbox.
- Implements
- Blockly.IToolbox#getHeight
- Returns
-
number
The width of the toolbox.
getPreviouslySelectedItem
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
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
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
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
getWidth() returns number
Gets the width of the toolbox.
- Implements
- Blockly.IToolbox#getWidth
- Returns
-
number
The width of the toolbox.
getWorkspace
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
handleToolboxItemResize()
Handles resizing the toolbox when a toolbox item resizes.
- Implements
- Blockly.IToolbox#handleToolboxItemResize
init
init()
Initializes the toolbox
- Implements
- Blockly.IToolbox#init
isHorizontal
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
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.ShortcutRegistry.KeyboardShortcut 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_
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_
onKeyDown_(e)
Handles key down events for the toolbox.
Parameter |
|
---|---|
e |
KeyboardEvent The key down event. Value must not be null. |
position
position()
Positions the toolbox based on whether it is a horizontal toolbox and whether the workspace is in rtl.
- Implements
- Blockly.IToolbox#position
refreshSelection
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
refreshTheme()
Updates the category colours and background colour of selected categories.
- Implements
- Blockly.IToolbox#refreshTheme
removeStyle
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
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_
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_
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
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
setSelectedItem(newItem)
Sets the given item as selected. No-op if the item is not selectable.
Parameter |
|
---|---|
newItem |
The toolbox item to select. Value may be null. |
setVisible
setVisible(isVisible)
Shows or hides the toolbox.
Parameter |
|
---|---|
isVisible |
boolean True if toolbox should be visible. |
- Implements
- Blockly.IToolbox#setVisible
shouldDeselectItem_
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_
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_
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. |