See the 2022 Blockly Developer Summit site here.

Namespace: common

Methods

defineBlocks

static

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

static

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

static

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

static

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

Blockly.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

static

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

static

getParentContainer() returns Element

Get the container element in which to render the WidgetDiv, DropDownDiv and
Tooltip.

Returns

nullable Element The parent container.

getSelected

static

getSelected() returns Blockly.ICopyable

Returns the currently selected block.

Returns

nullable Blockly.ICopyable The currently selected block.

setMainWorkspace

static

setMainWorkspace(workspace)

Sets last used main workspace.

Parameter

workspace

Blockly.Workspace

The most recently used top level workspace.

Value must not be null.

setParentContainer

static

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

package   static

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

Blockly.ICopyable

The newly selected block.

Value may be null.

svgResize

static

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

Blockly.WorkspaceSvg

Any workspace in the SVG.

Value must not be null.