Blockly. common
Common functions used both internally and externally, but which must not be at the top level to avoid circular dependencies.
Methods
defineBlocks
defineBlocks(blocks)
Add the specified block definitions to the block definitions dictionary (Blockly.Blocks).
Parameter |
|
---|---|
blocks |
Object with non-null Blockly.blocks properties A map of block type names to block definitions. Value must not be null. |
defineBlocksWithJsonArray
defineBlocksWithJsonArray(jsonArray)
Define blocks from an array of JSON block definitions, as might be generated by the Blockly Developer Tools.
Parameter |
|
---|---|
jsonArray |
Array of non-null Object An array of JSON block definitions. Value must not be null. |
defineBlocksWithJsonArray
defineBlocksWithJsonArray(jsonArray) returns Object with non-null Blockly.blocks properties
Define blocks from an array of JSON block definitions, as might be generated by the Blockly Developer Tools.
Parameter |
|
---|---|
jsonArray |
Array of non-null Object An array of JSON block definitions. Value must not be null. |
- Returns
-
non-null Object with non-null Blockly.blocks properties
A map of the block definitions created.
getBlockTypeCounts
getBlockTypeCounts(block, opt_stripFollowing) returns Object
Get a map of all the block's descendants mapping their type to the number of children with that type.
Parameter |
|
---|---|
block |
The block to map. Value must not be null. |
opt_stripFollowing |
Optional boolean Optionally ignore all following statements (blocks that are not inside a value or statement input of the block). |
- Returns
-
non-null Object
Map of types to type counts for descendants of the bock.
getMainWorkspace
getMainWorkspace() returns Blockly.Workspace
Returns the last used top level workspace (based on focus). Try not to use this function, particularly if there are multiple Blockly instances on a page.
- Returns
-
non-null Blockly.Workspace
The main workspace.
getParentContainer
getParentContainer() returns Element
Get the container element in which to render the WidgetDiv, DropDownDiv and
Tooltip.
- Returns
-
nullable Element
The parent container.
getSelected
getSelected() returns Blockly.ICopyable
Returns the currently selected block.
- Returns
-
nullable Blockly.ICopyable
The currently selected block.
setMainWorkspace
setMainWorkspace(workspace)
Sets last used main workspace.
Parameter |
|
---|---|
workspace |
The most recently used top level workspace. Value must not be null. |
setParentContainer
setParentContainer(newParent)
Set the parent container. This is the container element that the WidgetDiv,
DropDownDiv, and Tooltip are rendered into the first time Blockly.inject
is called.
This method is a NOP if called after the first Blockly.inject
.
Parameter |
|
---|---|
newParent |
Element The container element. Value must not be null. |
setSelected
setSelected(newSelection)
Sets the currently selected block. This function does not visually mark the
block as selected or fire the required events. If you wish to
programmatically select a block, use BlockSvg#select
.
Parameter |
|
---|---|
newSelection |
The newly selected block. Value may be null. |
svgResize
svgResize(workspace)
Size the SVG image to completely fill its container. Call this when the view actually changes sizes (e.g. on a window resize/device orientation change). See workspace.resizeContents to resize the workspace when the contents change (e.g. when a block is added or removed). Record the height/width of the SVG image.
Parameter |
|
---|---|
workspace |
Any workspace in the SVG. Value must not be null. |