Register for the online Blockly Developer Summit April 28-29, 2021!

Namespace: Blockly

Classes

Interfaces

Namespaces

Enumerations

connectionTypes

static

number

Enum for the type of a connection or input.

Value

INPUT_VALUE

OUTPUT_VALUE

NEXT_STATEMENT

PREVIOUS_STATEMENT

inputTypes

static

number

Enum for the type of a connection or input.

Value

VALUE

STATEMENT

DUMMY

Properties

ALIGN_CENTRE

static

See also
Blockly.constants.ALIGN.CENTRE

ALIGN_LEFT

static

See also
Blockly.constants.ALIGN.LEFT

ALIGN_RIGHT

static

See also
Blockly.constants.ALIGN.RIGHT

bindEvent_

static

See also
Blockly.browserEvents.bind

bindEventWithChecks_

static

See also
Blockly.browserEvents.conditionalBind

Blocks

static

A mapping of block type names to block prototype objects.

Blocks

static

non-null Object with Object properties

A mapping of block type names to block prototype objects.

BUMP_DELAY

static

Delay in ms between trigger and bumping unconnected block out of alignment.

BUMP_RANDOMNESS

static

Maximum randomness in workspace units for bumping a block.

COLLAPSE_CHARS

static

Number of characters to truncate a collapsed block to.

CONNECTING_SNAP_RADIUS

static

Maximum misalignment between connections for them to snap together, when a connection is already highlighted.

connectionTypes

static

number

Enum for the type of a connection or input.

Value

INPUT_VALUE

OUTPUT_VALUE

NEXT_STATEMENT

PREVIOUS_STATEMENT

CURRENT_CONNECTION_PREFERENCE

static

How much to prefer staying connected to the current connection over moving to a new connection. The current previewed connection is considered to be this much closer to the matching connection on the block than it actually is.

DELETE_AREA_NONE

constant   static

ENUM representing that an event is not in any delete areas. Null for backwards compatibility reasons.

DELETE_AREA_TOOLBOX

constant   static

ENUM representing that an event is in the delete area of the toolbox or flyout.

DELETE_AREA_TRASH

constant   static

ENUM representing that an event is in the delete area of the trash can.

DELETE_VARIABLE_ID

constant   static

string

String for use in the dropdown created in field_variable. This string indicates that this option in the dropdown is 'Delete the "%1" variable' and if selected, should trigger the prompt to delete a variable.

DRAG_BEGIN

constant   static

ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between clicks and drags.

DRAG_FREE

constant   static

ENUM for freely draggable (outside the DRAG_RADIUS, if one applies).

DRAG_NONE

constant   static

ENUM for no drag operation.

DRAG_RADIUS

static

Number of pixels the mouse must move before a drag starts.

DRAG_STACK

static

When dragging a block out of a stack, split the stack in two (true), or drag out the block healing the stack (false).

DRAG_STICKY

constant   static

ENUM for inside the sticky DRAG_RADIUS.

draggingConnections

package   static

non-null Array of non-null Blockly.Connection

All of the connections on blocks that are currently being dragged.

DUMMY_INPUT

static

See also
Blockly.inputTypes.DUMMY_INPUT

FLYOUT_DRAG_RADIUS

static

Number of pixels the mouse must move before a drag/scroll starts from the flyout. Because the drag-intention is determined when this is reached, it is larger than Blockly.DRAG_RADIUS so that the drag-direction is clearer.

HSV_SATURATION

static

The richness of block colours, regardless of the hue. Must be in the range of 0 (inclusive) to 1 (exclusive).

HSV_VALUE

static

The intensity of block colours, regardless of the hue. Must be in the range of 0 (inclusive) to 1 (exclusive).

INPUT_VALUE

static

See also
Blockly.connectionTypes.INPUT_VALUE

inputTypes

static

number

Enum for the type of a connection or input.

Value

VALUE

STATEMENT

DUMMY

LINE_MODE_MULTIPLIER

static

number

The multiplier for scroll wheel deltas using the line delta mode.

LONGPRESS

static

Length in ms for a touch to become a long press.

mainWorkspace

static

Blockly.Workspace

The main workspace most recently used. Set by Blockly.WorkspaceSvg.prototype.markFocused

mainWorkspace

static

non-null Blockly.Workspace

NEXT_STATEMENT

static

See also
Blockly.connectionTypes.NEXT_STATEMENT

OPPOSITE_TYPE

constant   static

Lookup table for determining the opposite type of a connection.

OUTPUT_VALUE

static

See also
Blockly.connectionTypes.OUTPUT_VALUE

PAGE_MODE_MULTIPLIER

static

number

The multiplier for scroll wheel deltas using the page delta mode.

parentContainer

package   static

nullable Element

Container element to render the WidgetDiv, DropDownDiv and Tooltip.

PREVIOUS_STATEMENT

static

See also
Blockly.connectionTypes.PREVIOUS_STATEMENT

PROCEDURE_CATEGORY_NAME

constant   static

string

String for use in the "custom" attribute of a category in toolbox XML. This string indicates that the category should be dynamically populated with procedure blocks.

RENAME_VARIABLE_ID

constant   static

string

String for use in the dropdown created in field_variable. This string indicates that this option in the dropdown is 'Rename variable...' and if selected, should trigger the prompt to rename a variable.

selected

static

nullable Blockly.ICopyable

Currently selected block.

selected

static

non-null Blockly.BlockSvg

selected

static

non-null Blockly.ICopyable

selected

static

non-null Blockly.ICopyable

selected

static

non-null Blockly.BlockSvg

SNAP_RADIUS

static

Maximum misalignment between connections for them to snap together.

SOUND_LIMIT

static

Prevent a sound from playing if another sound preceded it within this many milliseconds.

SPRITE

static

Sprited icons and images.

TOOLBOX_AT_BOTTOM

static

See also
Blockly.utils.toolbox.Position.BOTTOM

TOOLBOX_AT_LEFT

static

See also
Blockly.utils.toolbox.Position.LEFT

TOOLBOX_AT_RIGHT

static

See also
Blockly.utils.toolbox.Position.RIGHT

TOOLBOX_AT_TOP

static

See also
Blockly.utils.toolbox.Position.TOP

unbindEvent_

static

See also
Blockly.browserEvents.unbind

VARIABLE_CATEGORY_NAME

constant   static

string

String for use in the "custom" attribute of a category in toolbox XML. This string indicates that the category should be dynamically populated with variable blocks.

VARIABLE_DYNAMIC_CATEGORY_NAME

constant   static

string

String for use in the "custom" attribute of a category in toolbox XML. This string indicates that the category should be dynamically populated with variable blocks.

VERSION

constant   static

string

Blockly core version. This constant is overridden by the build script (build.py) to the value of the version in package.json. This is done during the gen_core build step. For local builds, you can pass --define='Blockly.VERSION=X.Y.Z' to the compiler to override this constant.

Methods

alert

static

alert(message, opt_callback)

Wrapper to window.alert() that app developers may override to provide alternatives to the modal browser window.

Parameter

message

string

The message to display to the user.

opt_callback

Optional

function()

The callback when the alert is dismissed.

checkBlockColourConstants

package   static

checkBlockColourConstants()

Checks old colour constants are not overwritten by the host application. If a constant is overwritten, it prints a console warning directing the developer to use the equivalent Msg constant.

confirm

static

confirm(message, callback)

Wrapper to window.confirm() that app developers may override to provide alternatives to the modal browser window.

Parameter

message

string

The message to display to the user.

callback

function(boolean)

The callback for handling user response.

Value must not be null.

copy

package   static

copy(toCopy)

Copy a block or workspace comment onto the local clipboard.

Parameter

toCopy

Blockly.ICopyable

Block or Workspace Comment to be copied.

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.

deleteBlock

package   static

deleteBlock(selected)

Delete the given block.

Parameter

selected

Blockly.BlockSvg

The block to delete.

Value must not be null.

duplicate

package   static

duplicate(toDuplicate)

Duplicate this block and its children, or a workspace comment.

Parameter

toDuplicate

Blockly.ICopyable

Block or Workspace Comment to be copied.

Value must not be null.

getMainWorkspace

static

getMainWorkspace() returns Blockly.Workspace

Returns the main workspace. Returns the last used main 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.

hideChaff

static

hideChaff(opt_allowToolbox)

Close tooltips, context menus, dropdown selections, etc.

Parameter

opt_allowToolbox

Optional

boolean

If true, don't close the toolbox.

hueToHex

static

hueToHex(hue) returns string

Convert a hue (HSV model) into an RGB hex triplet.

Parameter

hue

number

Hue on a colour wheel (0-360).

Returns

string RGB code, e.g. '#5ba65b'.

inject

static

inject(container, opt_options) returns Blockly.WorkspaceSvg

Inject a Blockly editor into the specified container element (usually a div).

Parameter

container

(Element or string)

Containing element, or its ID, or a CSS selector.

opt_options

Optional

Blockly.BlocklyOptions

Optional dictionary of options.

Returns

non-null Blockly.WorkspaceSvg Newly created main workspace.

isNumber

static

isNumber(str) returns boolean

Is the given string a number (includes negative and decimals).

Parameter

str

string

Input string.

Returns

boolean True if number, false otherwise.

longStart

package   static

longStart(e, gesture)

Context menus on touch devices are activated using a long-press. Unfortunately the contextmenu touch event is currently (2015) only supported by Chrome. This function is fired on any touchstart event, queues a task, which after about a second opens the context menu. The tasks is killed if the touch event terminates early.

Parameter

e

Event

Touch start event.

Value must not be null.

gesture

Blockly.Gesture

The gesture that triggered this longStart.

longStop_

package   static

longStop_()

Nope, that's not a long-press. Either touchend or touchcancel was fired, or a drag hath begun. Kill the queued long-press task.

onKeyDown

package   static

onKeyDown(e)

Handle a key-down on SVG drawing surface. Does nothing if the main workspace is not visible.

Parameter

e

KeyboardEvent

Key down event.

Value must not be null.

paste

package   static

paste() returns boolean

Paste a block or workspace comment on to the main workspace.

Returns

boolean True if the paste was successful, false otherwise.

prompt

static

prompt(message, defaultValue, callback)

Wrapper to window.prompt() that app developers may override to provide alternatives to the modal browser window. Built-in browser prompts are often used for better text input experience on mobile device. We strongly recommend testing mobile when overriding this.

Parameter

message

string

The message to display to the user.

defaultValue

string

The value to initialize the prompt with.

callback

function(nullable string)

The callback for handling user response.

Value must not be null.

resizeSvgContents

static

resizeSvgContents(workspace)

Size the workspace when the contents change. This also updates scrollbars accordingly.

Parameter

workspace

Blockly.WorkspaceSvg

The workspace to resize.

Value must not be null.

setParentContainer

static

setParentContainer(container)

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

container

Element

The container element.

Value must not 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 Blockly.resizeSvgContents 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.

svgSize

static

svgSize(svg) returns Blockly.utils.Size

Returns the dimensions of the specified SVG image.

Parameter

svg

SVGElement

SVG image.

Value must not be null.

Deprecated
Use workspace.setCachedParentSvgSize. (2021 March 5)
Returns

non-null Blockly.utils.Size Contains width and height properties.

Abstract type

IRegistrableField

static

{fromJson:Blockly.IRegistrableField.fromJson}

A registrable field. Note: We are not using an interface here as we are interested in defining the static methods of a field rather than the instance methods.