Constructor

BlockSvg

new BlockSvg(workspace, prototypeName, opt_id)

Class for a block's SVG representation. Not normally called directly, workspace.newBlock() is preferred.

Parameter

workspace

Blockly.Workspace

The block's workspace.

Value must not be null.

prototypeName

string

Name of the language object containing type-specific functions for this block.

Value may be null.

opt_id

Optional

string

Optional ID. Use this ID if provided, otherwise create a new ID.

Extends
Blockly.Block

Properties

CORNER_RADIUS

constant   static

Rounded corner radius.

DISTANCE_45_INSIDE

constant   static

Distance from shape edge to intersect with a curved corner at 45 degrees. Applies to highlighting on around the inside of a curve.

DISTANCE_45_OUTSIDE

constant   static

Distance from shape edge to intersect with a curved corner at 45 degrees. Applies to highlighting on around the outside of a curve.

INLINE

constant   static

Constant for identifying rows that are to be rendered inline. Don't collide with Blockly.INPUT_VALUE and friends.

INLINE_PADDING_Y

constant   static

Vertical padding around inline elements.

INNER_BOTTOM_LEFT_CORNER

constant   static

SVG path for drawing the bottom-left corner of a statement input. Includes the rounded inside corner.

INNER_BOTTOM_LEFT_CORNER_HIGHLIGHT_LTR

constant   static

SVG path for drawing highlight on the bottom-left corner of a statement input in LTR.

INNER_BOTTOM_LEFT_CORNER_HIGHLIGHT_RTL

constant   static

SVG path for drawing highlight on the bottom-left corner of a statement input in RTL.

INNER_TOP_LEFT_CORNER

constant   static

SVG path for drawing the top-left corner of a statement input. Includes the top notch, a horizontal space, and the rounded inside corner.

INNER_TOP_LEFT_CORNER_HIGHLIGHT_RTL

constant   static

SVG path for drawing highlight on the top-left corner of a statement input in RTL.

JAGGED_TEETH

constant   static

SVG path for drawing jagged teeth at the end of collapsed blocks.

JAGGED_TEETH_HEIGHT

constant   static

Height of SVG path for jagged teeth at the end of collapsed blocks.

JAGGED_TEETH_WIDTH

constant   static

Width of SVG path for jagged teeth at the end of collapsed blocks.

MIN_BLOCK_Y

constant   static

Minimum height of a block.

NOTCH_PATH_LEFT

constant   static

SVG path for drawing next/previous notch from left to right.

NOTCH_PATH_LEFT_HIGHLIGHT

constant   static

SVG path for drawing next/previous notch from left to right with highlighting.

NOTCH_PATH_RIGHT

constant   static

SVG path for drawing next/previous notch from right to left.

NOTCH_WIDTH

constant   static

Width of vertical tab (inc left margin).

SEP_SPACE_X

constant   static

Horizontal space between elements.

SEP_SPACE_Y

constant   static

Vertical space between elements.

START_HAT

constant   static

Do blocks with no previous or output connections have a 'hat' on top?

START_HAT_HEIGHT

constant   static

Height of the top hat.

START_HAT_HIGHLIGHT_LTR

constant   static

Path of the top hat's curve's highlight in LTR.

START_HAT_HIGHLIGHT_RTL

constant   static

Path of the top hat's curve's highlight in RTL.

START_HAT_PATH

constant   static

Path of the top hat's curve.

TAB_HEIGHT

constant   static

Height of horizontal puzzle tab.

TAB_PATH_DOWN

constant   static

SVG path for drawing a horizontal puzzle tab from top to bottom.

TAB_PATH_DOWN_HIGHLIGHT_RTL

constant   static

SVG path for drawing a horizontal puzzle tab from top to bottom with highlighting from the upper-right.

TAB_WIDTH

constant   static

Width of horizontal puzzle tab.

TOP_LEFT_CORNER

constant   static

SVG path for drawing the rounded top-left corner.

TOP_LEFT_CORNER_HIGHLIGHT

constant   static

SVG path for drawing the highlight on the rounded top-left corner.

TOP_LEFT_CORNER_START

constant   static

SVG start point for drawing the top-left corner.

TOP_LEFT_CORNER_START_HIGHLIGHT_LTR

constant   static

SVG start point for drawing the top-left corner's highlight in LTR.

TOP_LEFT_CORNER_START_HIGHLIGHT_RTL

constant   static

SVG start point for drawing the top-left corner's highlight in RTL.

childBlocks_

protected

unknown

Inherited from
Blockly.Block#childBlocks_

collapsed_

protected

unknown

Inherited from
Blockly.Block#collapsed_

comment

Blockly.Comment

Block's comment icon (if any).

contextMenu

unknown

Inherited from
Blockly.Block#contextMenu

data

unknown

Optional text data that round-trips beween blocks and XML. Has no effect. May be used by 3rd parties for meta information.

Inherited from
Blockly.Block#data

disabled

unknown

Inherited from
Blockly.Block#disabled

height

Height of this block, not including any statement blocks above or below. Height is in workspace units.

id

unknown

Inherited from
Blockly.Block#id

inputList

unknown

Inherited from
Blockly.Block#inputList

inputsInline

unknown

Inherited from
Blockly.Block#inputsInline

inputsInlineDefault

unknown

Inherited from
Blockly.Block#inputsInlineDefault

isInFlyout

unknown

Inherited from
Blockly.Block#isInFlyout

isInMutator

unknown

Inherited from
Blockly.Block#isInMutator

mutator

Blockly.Mutator

Block's mutator icon (if any).

nextConnection

unknown

Inherited from
Blockly.Block#nextConnection

outputConnection

unknown

Inherited from
Blockly.Block#outputConnection

parentBlock_

protected

unknown

Inherited from
Blockly.Block#parentBlock_

previousConnection

unknown

Inherited from
Blockly.Block#previousConnection

rendered

boolean

RTL

unknown

Inherited from
Blockly.Block#RTL

tooltip

unknown

Inherited from
Blockly.Block#tooltip

type

unknown

Inherited from
Blockly.Block#type

warning

Blockly.Warning

Block's warning icon (if any).

width

Width of this block, including any connected value blocks. Width is in workspace units.

workspace

unknown

Inherited from
Blockly.Block#workspace

Methods

addSelect

addSelect()

Select this block. Highlight it visually.

allInputsFilled

allInputsFilled(opt_shadowBlocksAreFilled) returns boolean

Recursively checks whether all statement and value inputs are filled with blocks. Also checks all following statement blocks in this stack.

Parameter

opt_shadowBlocksAreFilled

Optional

An optional argument controlling whether shadow blocks are counted as filled. Defaults to true.

Inherited from
Blockly.Block#allInputsFilled
Returns

True if all inputs are filled, false otherwise.

appendDummyInput

appendDummyInput(opt_name) returns Blockly.Input

Shortcut for appending a dummy input row.

Parameter

opt_name

Optional

Language-neutral identifier which may used to find this input again. Should be unique to this block.

Inherited from
Blockly.Block#appendDummyInput
Returns

The input object created.

appendStatementInput

appendStatementInput(name) returns Blockly.Input

Shortcut for appending a statement input row.

Parameter

name

Language-neutral identifier which may used to find this input again. Should be unique to this block.

Inherited from
Blockly.Block#appendStatementInput
Returns

The input object created.

appendValueInput

appendValueInput(name) returns Blockly.Input

Shortcut for appending a value input row.

Parameter

name

Language-neutral identifier which may used to find this input again. Should be unique to this block.

Inherited from
Blockly.Block#appendValueInput
Returns

The input object created.

bringToFront

bringToFront()

Move this block to the front of the visible workspace.

tags do not respect z-index so SVG renders them in the order that they are in the DOM. By placing this block first within the block group's , it will render on top of any other blocks.

dispose

dispose(healStack, animate)

Dispose of this block.

Parameter

healStack

boolean

If true, then try to heal any gap by connecting the next statement with the previous statement. Otherwise, dispose of all children of this block.

animate

boolean

If true, show a disposal animation and sound.

getBoundingRectangle

getBoundingRectangle() returns Object

Returns the coordinates of a bounding box describing the dimensions of this block and any blocks stacked below it. Coordinate system: workspace coordinates.

Returns

non-null {topLeft: goog.math.Coordinate, bottomRight: goog.math.Coordinate} Object with top left and bottom right coordinates of the bounding box.

getChildren

getChildren(ordered) returns Array of non-null Blockly.Block

Find all the blocks that are directly nested inside this one. Includes value and statement inputs, as well as any following statement. Excludes any connection on an output tab or any preceding statement. Blocks are optionally sorted by position; top to bottom.

Parameter

ordered

Sort the list if true.

Inherited from
Blockly.Block#getChildren
Returns

Array of blocks.

getColour

getColour() returns string

Get the colour of a block.

Inherited from
Blockly.Block#getColour
Returns

#RRGGBB string.

getCommentText

getCommentText() returns string

Returns the comment on this block (or '' if none).

Returns

string Block's comment.

getConnections_

getConnections_(all) returns Array of non-null Blockly.Connection

Returns connections originating from this block.

Parameter

all

boolean

If true, return all connections even hidden ones. Otherwise, for a non-rendered block return an empty list, and for a collapsed block don't return inputs connections.

Returns

non-null Array of non-null Blockly.Connection Array of connections.

getDescendants

getDescendants(ordered) returns Array of non-null Blockly.Block

Find all the blocks that are directly or indirectly nested inside this one. Includes this block in the list. Includes value and statement inputs, as well as any following statements. Excludes any connection on an output tab or any preceding statements. Blocks are optionally sorted by position; top to bottom.

Parameter

ordered

Sort the list if true.

Inherited from
Blockly.Block#getDescendants
Returns

Flattened array of blocks.

getField

getField(name) returns Blockly.Field

Returns the named field from a block.

Parameter

name

The name of the field.

Inherited from
Blockly.Block#getField
Returns

Named field, or null if field does not exist.

getFieldValue

getFieldValue(name) returns string

Returns the language-neutral value from the field of a block.

Parameter

name

The name of the field.

Inherited from
Blockly.Block#getFieldValue
Returns

Value from the field or null if field does not exist.

getHeightWidth

getHeightWidth() returns Object

Returns a bounding box describing the dimensions of this block and any blocks stacked below it.

Returns

non-null {height: number, width: number} Object with height and width properties in workspace units.

getHue

getHue() returns number

Get the HSV hue value of a block. Null if hue not set.

Inherited from
Blockly.Block#getHue
Returns

Hue value (0-360)

getIcons

getIcons() returns Array

Returns a list of mutator, comment, and warning icons.

Returns

non-null Array List of icons.

getInheritedDisabled

getInheritedDisabled() returns boolean

Get whether the block is disabled or not due to parents. The block's own disabled property is not considered.

Inherited from
Blockly.Block#getInheritedDisabled
Returns

True if disabled.

getInput

getInput(name) returns Blockly.Input

Fetches the named input object.

Parameter

name

The name of the input.

Inherited from
Blockly.Block#getInput
Returns

The input object, or null if input does not exist.

getInputsInline

getInputsInline() returns boolean

Get whether value inputs are arranged horizontally or vertically.

Inherited from
Blockly.Block#getInputsInline
Returns

True if inputs are horizontal.

getInputTargetBlock

getInputTargetBlock(name) returns Blockly.Block

Fetches the block attached to the named input.

Parameter

name

The name of the input.

Inherited from
Blockly.Block#getInputTargetBlock
Returns

The attached value block, or null if the input is either disconnected or if the input does not exist.

getInputWithBlock

getInputWithBlock(block) returns Blockly.Input

Return the input that connects to the specified block.

Parameter

block

A block connected to an input on this block.

Value must not be null.

Inherited from
Blockly.Block#getInputWithBlock
Returns

The input that connects to the specified block.

getNextBlock

getNextBlock() returns Blockly.Block

Return the next statement block directly connected to this block.

Inherited from
Blockly.Block#getNextBlock
Returns

The next statement block or null.

getParent

getParent() returns Blockly.Block

Return the parent block or null if this block is at the top level.

Inherited from
Blockly.Block#getParent
Returns

The block that holds the current block.

getRelativeToSurfaceXY

getRelativeToSurfaceXY() returns goog.math.Coordinate

Return the coordinates of the top-left corner of this block relative to the drawing surface's origin (0,0), in workspace units. If the block is on the workspace, (0, 0) is the origin of the workspace coordinate system. This does not change with workspace scale.

Returns

non-null goog.math.Coordinate Object with .x and .y properties in workspace coordinates.

getRootBlock

getRootBlock() returns Blockly.Block

Return the top-most block in this block's tree. This will return itself if this block is at the top level.

Inherited from
Blockly.Block#getRootBlock
Returns

The root block.

getSurroundParent

getSurroundParent() returns Blockly.Block

Return the parent block that surrounds the current block, or null if this block has no surrounding block. A parent block might just be the previous statement, whereas the surrounding block is an if statement, while loop, etc.

Inherited from
Blockly.Block#getSurroundParent
Returns

The block that surrounds the current block.

getSvgRoot

getSvgRoot() returns Element

Return the root node of the SVG or null if none exists.

Returns

Element The root SVG node (probably a group).

getVarModels

getVarModels() returns Array of non-null Blockly.VariableModel

Return all variables referenced by this block.

Inherited from
Blockly.Block#getVarModels
Returns

List of variable models.

getVars

getVars() returns Array of string

Return all variables referenced by this block.

Inherited from
Blockly.Block#getVars
Returns

List of variable names.

initModel

public

initModel()

Call initModel on all fields on the block. May be called more than once. Either initModel or initSvg must be called after creating a block and before the first interaction with it. Interactions include UI actions (e.g. clicking and dragging) and firing events (e.g. create, delete, and change).

Inherited from
Blockly.Block#initModel

initSvg

initSvg()

Create and initialize the SVG representation of the block. May be called more than once.

isCollapsed

isCollapsed() returns boolean

Get whether the block is collapsed or not.

Inherited from
Blockly.Block#isCollapsed
Returns

True if collapsed.

isDeletable

isDeletable() returns boolean

Get whether this block is deletable or not.

Inherited from
Blockly.Block#isDeletable
Returns

True if deletable.

isEditable

isEditable() returns boolean

Get whether this block is editable or not.

Inherited from
Blockly.Block#isEditable
Returns

True if editable.

isMovable

isMovable() returns boolean

Get whether this block is movable or not.

Inherited from
Blockly.Block#isMovable
Returns

True if movable.

isShadow

isShadow() returns boolean

Get whether this block is a shadow block or not.

Inherited from
Blockly.Block#isShadow
Returns

True if a shadow.

jsonInit

jsonInit(json)

Initialize this block using a cross-platform, internationalization-friendly JSON description.

Parameter

json

Structured data describing the block.

Value must not be null.

Inherited from
Blockly.Block#jsonInit

lastConnectionInStack

lastConnectionInStack() returns Blockly.Connection

Walks down a stack of blocks and finds the last next connection on the stack.

Inherited from
Blockly.Block#lastConnectionInStack
Returns

The last next connection on the stack, or null.

mixin

mixin(mixinObj, opt_disableCheck)

Add key/values from mixinObj to this block object. By default, this method will check that the keys in mixinObj will not overwrite existing values in the block, including prototype values. This provides some insurance against mixin / extension incompatibilities with future block features. This check can be disabled by passing true as the second argument.

Parameter

mixinObj

The key/values pairs to add to this block object.

Value must not be null.

opt_disableCheck

Optional

Option flag to disable overwrite checks.

Inherited from
Blockly.Block#mixin

moveBy

moveBy(dx, dy)

Move a block by a relative offset.

Parameter

dx

number

Horizontal offset in workspace units.

dy

number

Vertical offset in workspace units.

moveDuringDrag

moveDuringDrag(newLoc)

Move this block during a drag, taking into account whether we are using a drag surface to translate blocks. This block must be a top-level block.

Parameter

newLoc

goog.math.Coordinate

The location to translate to, in workspace coordinates.

Value must not be null.

moveInputBefore

moveInputBefore(name, refName)

Move a named input to a different location on this block.

Parameter

name

The name of the input to move.

refName

Name of input that should be after the moved input, or null to be the input at the end.

Value may be null.

Inherited from
Blockly.Block#moveInputBefore

moveNumberedInputBefore

moveNumberedInputBefore(inputIndex, refIndex)

Move a numbered input to a different location on this block.

Parameter

inputIndex

number

Index of the input to move.

refIndex

number

Index of input that should be after the moved input.

removeInput

removeInput(name, opt_quiet)

Remove an input from this block.

Parameter

name

string

The name of the input.

opt_quiet

Optional

boolean

True to prevent error if input is not present.

Throws

goog.asserts.AssertionError if the input is not present and opt_quiet is not true.

removeSelect

removeSelect()

Unselect this block. Remove its highlighting.

renameVarById

renameVarById(oldId, newId)

Notification that a variable is renaming. If the ID matches one of this block's variables, rename it.

Parameter

oldId

ID of variable to rename.

newId

ID of new variable. May be the same as oldId, but with an updated name.

Inherited from
Blockly.Block#renameVarById

render

render(opt_bubble)

Render the block. Lays out and reflows a block based on its contents and settings.

Parameter

opt_bubble

Optional

boolean

If false, just render this block. If true, also render block's parent, grandparent, etc. Defaults to true.

scheduleSnapAndBump

scheduleSnapAndBump()

Schedule snapping to grid and bumping neighbours to occur after a brief delay.

select

select()

Select this block. Highlight it visually.

setCollapsed

setCollapsed(collapsed)

Set whether the block is collapsed or not.

Parameter

collapsed

boolean

True if collapsed.

setColour

setColour(colour)

Change the colour of a block.

Parameter

colour

(number or string)

HSV hue value, or #RRGGBB string.

setCommentText

setCommentText(text)

Set this block's comment text.

Parameter

text

string

The text, or null to delete.

Value may be null.

setConnectionsHidden

setConnectionsHidden(hidden)

Set whether the connections are hidden (not tracked in a database) or not. Recursively walk down all child blocks (except collapsed blocks).

Parameter

hidden

True if connections are hidden.

Inherited from
Blockly.Block#setConnectionsHidden

setDeletable

setDeletable(deletable)

Set whether this block is deletable or not.

Parameter

deletable

True if deletable.

Inherited from
Blockly.Block#setDeletable

setDeleteStyle

setDeleteStyle(enable)

Update the cursor over this block by adding or removing a class.

Parameter

enable

boolean

True if the delete cursor should be shown, false otherwise.

setDisabled

setDisabled(disabled)

Set whether the block is disabled or not.

Parameter

disabled

boolean

True if disabled.

setDragging

setDragging(adding)

Recursively adds or removes the dragging class to this node and its children.

Parameter

adding

boolean

True if adding, false if removing.

setEditable

setEditable(editable)

Set whether this block is editable or not.

Parameter

editable

boolean

True if editable.

setFieldValue

setFieldValue(newValue, name)

Change the field value for a block (e.g. 'CHOOSE' or 'REMOVE').

Parameter

newValue

Value to be the new field.

name

The name of the field.

Inherited from
Blockly.Block#setFieldValue

setHelpUrl

setHelpUrl(url)

Set the URL of this block's help page.

Parameter

url

URL string for block help, or function that returns a URL. Null for no help.

Inherited from
Blockly.Block#setHelpUrl

setHighlighted

setHighlighted(highlighted)

Set whether the block is highlighted or not. Block highlighting is often used to visually mark blocks currently being executed.

Parameter

highlighted

boolean

True if highlighted.

setInputsInline

setInputsInline(newBoolean)

Set whether value inputs are arranged horizontally or vertically.

Parameter

newBoolean

boolean

True if inputs are horizontal.

setMovable

setMovable(movable)

Set whether this block is movable or not.

Parameter

movable

boolean

True if movable.

setMutator

setMutator(mutator)

Give this block a mutator dialog.

Parameter

mutator

Blockly.Mutator

A mutator dialog instance or null to remove.

setNextStatement

setNextStatement(newBoolean, opt_check)

Set whether another block can chain onto the bottom of this block.

Parameter

newBoolean

boolean

True if there can be a next statement.

opt_check

Optional

(string, Array of string, or null)

Statement type or list of statement types. Null/undefined if any type could be connected.

setOnChange

setOnChange(onchangeFn)

Sets a callback function to use whenever the block's parent workspace changes, replacing any prior onchange handler. This is usually only called from the constructor, the block type initializer function, or an extension initializer function.

Parameter

onchangeFn

The callback to call when the block's workspace changes.

Inherited from
Blockly.Block#setOnChange
Throws

if onchangeFn is not falsey or a function.

setOutput

setOutput(newBoolean, opt_check)

Set whether this block returns a value.

Parameter

newBoolean

boolean

True if there is an output.

opt_check

Optional

(string, Array of string, or null)

Returned type or list of returned types. Null or undefined if any type could be returned (e.g. variable get).

setParent

setParent(newParent)

Set parent of this block to be a new block or null.

Parameter

newParent

Blockly.BlockSvg

New parent block.

setPreviousStatement

setPreviousStatement(newBoolean, opt_check)

Set whether this block can chain onto the bottom of another block.

Parameter

newBoolean

boolean

True if there can be a previous statement.

opt_check

Optional

(string, Array of string, or null)

Statement type or list of statement types. Null/undefined if any type could be connected.

setShadow

setShadow(shadow)

Set whether this block is a shadow block or not.

Parameter

shadow

boolean

True if a shadow.

setTooltip

setTooltip(newTip)

Change the tooltip text for a block.

Parameter

newTip

Text for tooltip or a parent element to link to for its tooltip. May be a function that returns a string.

Inherited from
Blockly.Block#setTooltip

setWarningText

setWarningText(text, opt_id)

Set this block's warning text.

Parameter

text

string

The text, or null to delete.

Value may be null.

opt_id

Optional

string

An optional ID for the warning text to be able to maintain multiple warnings.

snapToGrid

snapToGrid()

Snap this block to the nearest grid point.

tab

tab(start, forward)

Open the next (or previous) FieldTextInput.

Parameter

start

(Blockly.Field or Blockly.Block)

Current location.

forward

boolean

If true go forward, otherwise backward.

toDevString

toDevString() returns string

This method returns a string describing this Block in developer terms (type name and ID; English only).

Intended to on be used in console logs and errors. If you need a string that uses the user's native language (including block text, field values, and child blocks), use toString().

Inherited from
Blockly.Block#toDevString
Returns

The description.

toString

toString(opt_maxLength, opt_emptyToken) returns string

Create a human-readable text representation of this block and any children.

Parameter

opt_maxLength

Optional

Truncate the string to this length.

opt_emptyToken

Optional

The placeholder string used to denote an empty field. If not specified, '?' is used.

Inherited from
Blockly.Block#toString
Returns

Text of block.

translate

translate(x, y)

Transforms a block by setting the translation on the transform attribute of the block's SVG.

Parameter

x

number

The x coordinate of the translation in workspace units.

y

number

The y coordinate of the translation in workspace units.

unplug

unplug(opt_healStack)

Unplug this block from its superior block. If this block is a statement, optionally reconnect the block underneath with the block on top.

Parameter

opt_healStack

Optional

Disconnect child statement and reconnect stack. Defaults to false.

Inherited from
Blockly.Block#unplug

unselect

unselect()

Unselect this block. Remove its highlighting.

updateColour

updateColour()

Change the colour of a block.

updateDisabled

updateDisabled()

Enable or disable a block.

updateMovable

updateMovable()

Add or remove the UI indicating if this block is movable or not.

updateVarName

updateVarName(variable)

Notification that a variable is renaming but keeping the same ID. If the variable is in use on this block, rerender to show the new name.

Parameter

variable

The variable being renamed.

Value must not be null.

Inherited from
Blockly.Block#updateVarName