Skip to main content

Class: BlockSvg

Defined in: packages/blockly/core/block_svg.ts:78

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

Extends

Implements

Properties index

PropertyDescription
onchangeAn optional callback method to use whenever the block's parent workspace changes. This is usually only called from the constructor, the block type initializer function, or an extension initializer function.
COLLAPSED_INPUT_NAMEThe language-neutral ID given to the collapsed input.
COLLAPSED_FIELD_NAMEThe language-neutral ID given to the collapsed field.
dataOptional text data that round-trips between blocks and XML. Has no effect. May be used by 3rd parties for meta information.
colour_Colour of the block in '#RRGGBB' format.
styleName_Name of the block style.
initAn optional method called during initialization.
destroyAn optional method called during disposal.
mutationToDomAn optional serialization method for defining how to serialize the mutation state to XML. This must be coupled with defining domToMutation.
domToMutationAn optional deserialization method for defining how to deserialize the mutation state from XML. This must be coupled with defining mutationToDom.
saveExtraStateAn optional serialization method for defining how to serialize the block's extra state (eg mutation state) to something JSON compatible. This must be coupled with defining loadExtraState.
loadExtraStateAn optional serialization method for defining how to deserialize the block's extra state (eg mutation state) from something JSON compatible. This must be coupled with defining saveExtraState.
suppressPrefixSuffixAn optional property for suppressing adding STATEMENT_PREFIX and STATEMENT_SUFFIX to generated code.
getDeveloperVariablesAn optional method for declaring developer variables, to be used by generators. Developer variables are never shown to the user, but are declared as global variables in the generated code.
composeAn optional method that reconfigures the block based on the contents of the mutator dialog.
id-
inputList-
inputsInline-
icons-
tooltip-
contextMenu-
parentBlock_-
childBlocks_-
collapsed_-
outputShape_-
disposingIs the current block currently in the process of being disposed?
xy-
isInFlyout-
isInMutator-
RTL-
isInsertionMarker_True if this block is an insertion marker.
hatName of the type of hat.
helpUrlString for block help, or function that returns a URL. Null for no help.
type-
inputsInlineDefault-
INLINEConstant for identifying rows that are to be rendered inline. Don't collide with Blockly.inputTypes.
COLLAPSED_WARNING_IDID to give the "collapsed warnings" warning. Allows us to remove the "collapsed warnings" warning without removing any warnings that belong to the block.
decomposeAn optional function that populates the mutator flyout with blocks representing this block's configuration.
saveConnectionsAn optional method which saves a record of blocks connected to this block so they can be later restored after this block is recoomposed (reconfigured). Typically records the connected blocks on properties on blocks in the mutator flyout, so that rearranging those component blocks will automatically rearrange the corresponding connected blocks on this block after this block is recomposed.
customContextMenu-
heightHeight of this block, not including any statement blocks above or below. Height is in workspace units.
widthWidth of this block, including any connected value blocks. Width is in workspace units.
mutatorBlock's mutator icon (if any).
style-
renderedIs this block a BlockSVG?
workspace-
outputConnection-
nextConnection-
previousConnection-

Methods index

MethodDescription
doInit_Calls the init() function and handles associated event firing, etc.
initModelCall 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).
unplugUnplug this block from its superior block. If this block is a statement, optionally reconnect the block underneath with the block on top.
getParentReturn the parent block or null if this block is at the top level. The parent block is either the block connected to the previous connection (for a statement block) or the block connected to the output connection (for a value block).
getInputWithBlockReturn the input that connects to the specified block.
getSurroundParentReturn 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.
getRootBlockReturn the top-most block in this block's tree. This will return itself if this block is at the top level.
getDescendantsFind 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.
isDeletableGet whether this block is deletable or not.
isOwnDeletableReturn whether this block's own deletable property is true or false.
isDuplicatableGet whether is block is duplicatable or not. If duplicating this block and descendants will put this block over the workspace's capacity this block is not duplicatable. If duplicating this block and descendants will put any type over their maxInstances this block is not duplicatable.
isShadowGet whether this block is a shadow block or not.
isInsertionMarkerGet whether this block is an insertion marker block or not.
isOwnEditableReturn whether this block's own editable property is true or false.
isDisposedReturns if this block has been disposed of / deleted.
setHelpUrlSet the URL of this block's help page.
setTooltipSets the tooltip for this block.
getTooltipReturns the tooltip text for this block.
getStyleNameGet the name of the block style.
getHueGet the HSV hue value of a block. Null if hue not set.
setOnChangeSets 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.
getFieldReturns the named field from a block.
getFieldsReturns a generator that provides every field on the block.
getVarModelsReturn all variables referenced by this block.
renameVarByIdNotification that a variable is renaming. If the ID matches one of this block's variables, rename it.
getFieldValueReturns the language-neutral value of the given field.
setFieldValueSets the value of the given field for this block.
getInputsInlineGet whether value inputs are arranged horizontally or vertically.
setOutputShapeSet the block's output shape.
getOutputShapeGet the block's output shape.
isEnabledGet whether this block is enabled or not. A block is considered enabled if there aren't any reasons why it would be disabled. A block may still be disabled for other reasons even if the user attempts to manually enable it, such as when the block is in an invalid location.
getInheritedDisabledGet whether the block is disabled or not due to parents. The block's own disabled property is not considered.
hasDisabledReasonGet whether the block is currently disabled for the provided reason.
getDisabledReasonsGet a set of reasons why the block is currently disabled, if any. If the block is enabled, this set will be empty.
isCollapsedGet whether the block is collapsed or not.
setAriaRoleDescriptionProviderSet a custom aria role description provider for this block. If not set, uses a default provider based on the block's properties (e.g. whether it has inputs, outputs, etc.).
getAriaRoleDescriptionReturns the string to use as the role description for this block. If a custom provider has been set, use that. Otherwise, return a default description based on the block's properties.
toStringCreate a human-readable text representation of this block and any children.
appendValueInputAppends a value input row.
appendStatementInputAppends a statement input row.
appendDummyInputAppends a dummy input row.
appendEndRowInputAppends an input that ends the row.
mixinAdd 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.
moveInputBeforeMove a named input to a different location on this block.
getInputFetches the named input object.
getInputTargetBlockFetches the block attached to the named input.
getCommentTextReturns the comment on this block (or null if there is no comment).
setCommentTextSet this block's comment text.
hasIconReturns true if an icon with the given type exists on the block, false otherwise.
getIconReturns the icon with the given type if it exists on the block, undefined otherwise.
getIconsReturns an array of the icons attached to this block.
getRelativeToSurfaceXYReturn the coordinates of the top-left corner of this block relative to the drawing surface's origin (0,0), in workspace units.
allInputsFilledRecursively checks whether all statement and value inputs are filled with blocks. Also checks all following statement blocks in this stack.
toDevStringThis method returns a string describing this Block in developer terms (type name and ID; English only).
initSvgCreate and initialize the SVG representation of the block. May be called more than once.
getColourSecondaryGet the secondary colour of a block.
getColourTertiaryGet the tertiary colour of a block.
selectSelects this block. Highlights the block visually.
unselectUnselects this block. Unhighlights the block visually.
moveByMove a block by a relative offset.
translateTransforms a block by setting the translation on the transform attribute of the block's SVG.
moveToMove a block to a position.
snapToGridSnap this block to the nearest grid point.
getBoundingRectangleReturns the coordinates of a bounding box describing the dimensions of this block and any blocks stacked below it. Coordinate system: workspace coordinates.
getBoundingRectangleWithoutChildrenReturns the coordinates of a bounding box describing the dimensions of this block alone. Coordinate system: workspace coordinates.
markDirtyNotify every input on this block to mark its fields as dirty. A dirty field is a field that needs to be re-rendered.
setCollapsedSet whether the block is collapsed or not.
generateContextMenuGenerate the context menu for this block.
calculateContextMenuLocationGets the location in which to show the context menu for this block. Use the location of a click if the block was clicked, or a location based on the block's fields otherwise.
addClassAdd a CSS class to the SVG group of this block.
removeClassRemove a CSS class from the SVG group of this block.
isDraggingReturns whether or not this block is currently being dragged.
setMovableSet whether this block is movable or not.
setEditableSet whether this block is editable or not.
getSvgRootReturn the root node of the SVG or null if none exists.
disposeDispose of this block.
disposeInternalDisposes of this block without doing things required by the top block. E.g. does trigger UI effects, remove nodes, etc.
checkAndDeleteDelete a block and hide chaff when doing so. The block will not be deleted if it's in a flyout. This is called from the context menu and keyboard shortcuts as the full delete action. If you are disposing of a block from the workspace and don't need to perform flyout checks, handle event grouping, or hide chaff, then use block.dispose() directly.
toCopyDataEncode a block for copying.
setWarningTextSet this block's warning text.
setMutatorGive this block a mutator dialog.
addIconAdds the given icon to the block.
removeIconRemoves the icon whose getType matches the given type iconType from the block.
setDisabledReasonAdd or remove a reason why the block might be disabled. If a block has any reasons to be disabled, then the block itself will be considered disabled. A block could be disabled for multiple independent reasons simultaneously, such as when the user manually disables it, or the block is invalid.
setDeletableAdd blocklyNotDeletable class when block is not deletable Or remove class when block is deletable
setHighlightedSet whether the block is highlighted or not. Block highlighting is often used to visually mark blocks currently being executed.
addSelectAdds the visual "select" effect to the block, but does not actually select it or fire an event.
removeSelectRemoves the visual "select" effect from the block, but does not actually unselect it or fire an event.
getColourGet the colour of a block.
setColourChange the colour of a block.
setStyleSet the style and colour values of a block.
getStyleReturns the BlockStyle object used to style this block.
bringToFrontMove 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. Use sparingly, this method is expensive because it reorders the DOM nodes.
setPreviousStatementSet whether this block can chain onto the bottom of another block.
setNextStatementSet whether another block can chain onto the bottom of this block.
setOutputSet whether this block returns a value.
setInputsInlineSet whether value inputs are arranged horizontally or vertically.
removeInputRemove an input from this block.
moveNumberedInputBeforeMove a numbered input to a different location on this block.
appendInputAppends the given input row.
getNextBlockReturn the next statement block directly connected to this block.
getPreviousBlockReturns the block connected to the previous connection.
bumpNeighboursBumps unconnected blocks out of alignment.
scheduleSnapAndBumpSnap to grid, and then bump neighbouring blocks away at the end of the next render.
getChildrenFind 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.
renderImmediately lays out and reflows a block based on its contents and settings.
setDragStrategySets the drag strategy for this block.
isCopyableReturns whether this block is copyable or not.
isMovableReturns whether this block is movable or not.
startDragStarts a drag on the block.
dragDrags the block to the given location.
endDragEnds the drag on the block.
revertDragMoves the block back to where it was at the start of a drag.
toFlyoutInfoReturns a representation of this block that can be displayed in a flyout.
jsonInitInitialize this block using a cross-platform, internationalization-friendly JSON description.
getFocusableElementSee IFocusableNode.getFocusableElement.
getFocusableTreeSee IFocusableNode.getFocusableTree.
onNodeFocusSee IFocusableNode.onNodeFocus.
onNodeBlurSee IFocusableNode.onNodeBlur.
canBeFocusedSee IFocusableNode.canBeFocused.
performActionHandles the user acting on this block via keyboard navigation. If this block is in the flyout, a new copy is spawned in move mode on the main workspace. If this block has a single full-block field, that field will be focused. Otherwise, this is a no-op.
getAriaLabelReturns a description of this block suitable for screenreaders or use in ARIA attributes.

Constructors

Constructor

new BlockSvg(
workspace,
prototypeName,
opt_id?
): BlockSvg;

Defined in: packages/blockly/core/block_svg.ts:192

Parameters

ParameterTypeDescription
workspaceWorkspaceSvgThe block's workspace.
prototypeNamestringName of the language object containing type-specific functions for this block.
opt_id?stringOptional ID. Use this ID if provided, otherwise create a new ID.

Returns

BlockSvg

Overrides

Block.constructor

Properties

onchange?

optional onchange?: ((p1) => void) | null;

Defined in: packages/blockly/core/block.ts:63

An optional callback method to use whenever the block's parent workspace changes. This is usually only called from the constructor, the block type initializer function, or an extension initializer function.

Inherited from

Block.onchange


COLLAPSED_INPUT_NAME

readonly static COLLAPSED_INPUT_NAME: string = constants.COLLAPSED_INPUT_NAME;

Defined in: packages/blockly/core/block.ts:66

The language-neutral ID given to the collapsed input.

Inherited from

Block.COLLAPSED_INPUT_NAME


COLLAPSED_FIELD_NAME

readonly static COLLAPSED_FIELD_NAME: string = constants.COLLAPSED_FIELD_NAME;

Defined in: packages/blockly/core/block.ts:69

The language-neutral ID given to the collapsed field.

Inherited from

Block.COLLAPSED_FIELD_NAME


data

data: string | null = null;

Defined in: packages/blockly/core/block.ts:75

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

Inherited from

Block.data


colour_

protected colour_: string = '#000000';

Defined in: packages/blockly/core/block.ts:91

Colour of the block in '#RRGGBB' format.

Inherited from

Block.colour_


styleName_

protected styleName_: string = '';

Defined in: packages/blockly/core/block.ts:94

Name of the block style.

Inherited from

Block.styleName_


init?

optional init?: () => void;

Defined in: packages/blockly/core/block.ts:97

An optional method called during initialization.

Returns

void

Inherited from

Block.init


destroy?

optional destroy?: () => void;

Defined in: packages/blockly/core/block.ts:100

An optional method called during disposal.

Returns

void

Inherited from

Block.destroy


mutationToDom?

optional mutationToDom?: (...p1) => Element;

Defined in: packages/blockly/core/block.ts:107

An optional serialization method for defining how to serialize the mutation state to XML. This must be coupled with defining domToMutation.

Parameters

ParameterType
...p1any[]

Returns

Element

Inherited from

Block.mutationToDom


domToMutation?

optional domToMutation?: (p1) => void;

Defined in: packages/blockly/core/block.ts:114

An optional deserialization method for defining how to deserialize the mutation state from XML. This must be coupled with defining mutationToDom.

Parameters

ParameterType
p1Element

Returns

void

Inherited from

Block.domToMutation


saveExtraState?

optional saveExtraState?: (doFullSerialization?) => any;

Defined in: packages/blockly/core/block.ts:127

An optional serialization method for defining how to serialize the block's extra state (eg mutation state) to something JSON compatible. This must be coupled with defining loadExtraState.

Parameters

ParameterTypeDescription
doFullSerialization?booleanWhether or not to serialize the full state of the extra state (rather than possibly saving a reference to some state). This is used during copy-paste. See the block serialization docs for more information.

Returns

any

Inherited from

Block.saveExtraState


loadExtraState?

optional loadExtraState?: (p1) => void;

Defined in: packages/blockly/core/block.ts:134

An optional serialization method for defining how to deserialize the block's extra state (eg mutation state) from something JSON compatible. This must be coupled with defining saveExtraState.

Parameters

ParameterType
p1any

Returns

void

Inherited from

Block.loadExtraState


suppressPrefixSuffix

suppressPrefixSuffix: boolean | null = false;

Defined in: packages/blockly/core/block.ts:140

An optional property for suppressing adding STATEMENT_PREFIX and STATEMENT_SUFFIX to generated code.

Inherited from

Block.suppressPrefixSuffix


getDeveloperVariables?

optional getDeveloperVariables?: () => string[];

Defined in: packages/blockly/core/block.ts:149

An optional method for declaring developer variables, to be used by generators. Developer variables are never shown to the user, but are declared as global variables in the generated code.

Returns

string[]

a list of developer variable names.

Inherited from

Block.getDeveloperVariables


compose?

optional compose?: (rootBlock) => void;

Defined in: packages/blockly/core/block.ts:157

An optional method that reconfigures the block based on the contents of the mutator dialog.

Parameters

ParameterTypeDescription
rootBlockBlockThe root block in the mutator flyout.

Returns

void

Inherited from

Block.compose


id

id: string;

Defined in: packages/blockly/core/block.ts:168

Implementation of

IDraggable.id

Inherited from

Block.id


inputList

inputList: Input[] = [];

Defined in: packages/blockly/core/block.ts:172

Inherited from

Block.inputList


inputsInline?

optional inputsInline?: boolean;

Defined in: packages/blockly/core/block.ts:173

Inherited from

Block.inputsInline


icons

icons: IIcon[] = [];

Defined in: packages/blockly/core/block.ts:174

Inherited from

Block.icons


tooltip

tooltip: TipInfo = '';

Defined in: packages/blockly/core/block.ts:176

Inherited from

Block.tooltip


contextMenu

contextMenu: boolean = true;

Defined in: packages/blockly/core/block.ts:177

Inherited from

Block.contextMenu


parentBlock_

protected parentBlock_: BlockSvg | null = null;

Defined in: packages/blockly/core/block.ts:179

Inherited from

Block.parentBlock_


childBlocks_

protected childBlocks_: BlockSvg[] = [];

Defined in: packages/blockly/core/block.ts:181

Inherited from

Block.childBlocks_


collapsed_

protected collapsed_: boolean = false;

Defined in: packages/blockly/core/block.ts:191

Inherited from

Block.collapsed_


outputShape_

protected outputShape_: number | null = null;

Defined in: packages/blockly/core/block.ts:192

Inherited from

Block.outputShape_


disposing

protected disposing: boolean = false;

Defined in: packages/blockly/core/block.ts:197

Is the current block currently in the process of being disposed?

Inherited from

Block.disposing


xy

protected readonly xy: Coordinate;

Defined in: packages/blockly/core/block.ts:206

Inherited from

Block.xy


isInFlyout

isInFlyout: boolean;

Defined in: packages/blockly/core/block.ts:207

Inherited from

Block.isInFlyout


isInMutator

isInMutator: boolean;

Defined in: packages/blockly/core/block.ts:208

Inherited from

Block.isInMutator


RTL

RTL: boolean;

Defined in: packages/blockly/core/block.ts:209

Inherited from

Block.RTL


isInsertionMarker_

protected isInsertionMarker_: boolean = false;

Defined in: packages/blockly/core/block.ts:212

True if this block is an insertion marker.

Inherited from

Block.isInsertionMarker_


hat?

optional hat?: string;

Defined in: packages/blockly/core/block.ts:215

Name of the type of hat.

Inherited from

Block.hat


helpUrl

helpUrl: string | (() => string) | null = null;

Defined in: packages/blockly/core/block.ts:223

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

Inherited from

Block.helpUrl


type

type: string;

Defined in: packages/blockly/core/block.ts:235

Inherited from

Block.type


inputsInlineDefault?

optional inputsInlineDefault?: boolean;

Defined in: packages/blockly/core/block.ts:237

Inherited from

Block.inputsInlineDefault


INLINE

readonly static INLINE: -1 = -1;

Defined in: packages/blockly/core/block_svg.ts:92

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


COLLAPSED_WARNING_ID

readonly static COLLAPSED_WARNING_ID: "TEMP_COLLAPSED_WARNING_" = 'TEMP_COLLAPSED_WARNING_';

Defined in: packages/blockly/core/block_svg.ts:99

ID to give the "collapsed warnings" warning. Allows us to remove the "collapsed warnings" warning without removing any warnings that belong to the block.


decompose?

optional decompose?: (p1) => BlockSvg;

Defined in: packages/blockly/core/block_svg.ts:100

An optional function that populates the mutator flyout with blocks representing this block's configuration.

Parameters

ParameterType
p1Workspace

Returns

BlockSvg

The root block created in the flyout's workspace.

Overrides

Block.decompose


saveConnections?

optional saveConnections?: (rootBlock) => void;

Defined in: packages/blockly/core/block_svg.ts:119

An optional method which saves a record of blocks connected to this block so they can be later restored after this block is recoomposed (reconfigured). Typically records the connected blocks on properties on blocks in the mutator flyout, so that rearranging those component blocks will automatically rearrange the corresponding connected blocks on this block after this block is recomposed.

To keep the saved connection information up-to-date, MutatorIcon arranges for an event listener to call this method any time the mutator flyout is open and a change occurs on this block's workspace.

Parameters

ParameterTypeDescription
rootBlockBlockSvgThe root block in the mutator flyout.

Returns

void


customContextMenu?

optional customContextMenu?: (p1) => void;

Defined in: packages/blockly/core/block_svg.ts:121

Parameters

ParameterType
p1( | ContextMenuOption | LegacyContextMenuOption)[]

Returns

void


height

height: number = 0;

Defined in: packages/blockly/core/block_svg.ts:129

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


width

width: number = 0;

Defined in: packages/blockly/core/block_svg.ts:135

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


mutator

mutator: MutatorIcon | null = null;

Defined in: packages/blockly/core/block_svg.ts:152

Block's mutator icon (if any).


style

style: BlockStyle;

Defined in: packages/blockly/core/block_svg.ts:155


rendered

readonly rendered: true = true;

Defined in: packages/blockly/core/block_svg.ts:160

Is this block a BlockSVG?

Overrides

Block.rendered


workspace

workspace: WorkspaceSvg;

Defined in: packages/blockly/core/block_svg.ts:164

Implementation of

IDraggable.workspace

Overrides

Block.workspace


outputConnection

outputConnection: RenderedConnection | null = null;

Defined in: packages/blockly/core/block_svg.ts:165

Overrides

Block.outputConnection


nextConnection

nextConnection: RenderedConnection | null = null;

Defined in: packages/blockly/core/block_svg.ts:166

Overrides

Block.nextConnection


previousConnection

previousConnection: RenderedConnection | null = null;

Defined in: packages/blockly/core/block_svg.ts:167

Overrides

Block.previousConnection

Methods

doInit_()

protected doInit_(): void;

Defined in: packages/blockly/core/block.ts:287

Calls the init() function and handles associated event firing, etc.

Returns

void

Inherited from

Block.doInit_


initModel()

initModel(): void;

Defined in: packages/blockly/core/block.ts:389

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

Returns

void

Inherited from

Block.initModel


unplug()

unplug(opt_healStack?): void;

Defined in: packages/blockly/core/block.ts:404

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

Parameters

ParameterTypeDescription
opt_healStack?booleanDisconnect child statement and reconnect stack. Defaults to false.

Returns

void

Inherited from

Block.unplug


getParent()

getParent(): BlockSvg | null;

Defined in: packages/blockly/core/block.ts:594

Return the parent block or null if this block is at the top level. The parent block is either the block connected to the previous connection (for a statement block) or the block connected to the output connection (for a value block).

Returns

BlockSvg | null

The block (if any) that holds the current block.

Inherited from

Block.getParent


getInputWithBlock()

getInputWithBlock(block): Input | null;

Defined in: packages/blockly/core/block.ts:604

Return the input that connects to the specified block.

Parameters

ParameterTypeDescription
blockBlockA block connected to an input on this block.

Returns

Input | null

The input (if any) that connects to the specified block.

Inherited from

Block.getInputWithBlock


getSurroundParent()

getSurroundParent(): BlockSvg | null;

Defined in: packages/blockly/core/block.ts:621

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.

Returns

BlockSvg | null

The block (if any) that surrounds the current block.

Inherited from

Block.getSurroundParent


getRootBlock()

getRootBlock(): this;

Defined in: packages/blockly/core/block.ts:661

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

Returns

this

The root block.

Inherited from

Block.getRootBlock


getDescendants()

getDescendants(ordered): BlockSvg[];

Defined in: packages/blockly/core/block.ts:784

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.

Parameters

ParameterTypeDescription
orderedbooleanSort the list if true.

Returns

BlockSvg[]

Flattened array of blocks.

Inherited from

Block.getDescendants


isDeletable()

isDeletable(): boolean;

Defined in: packages/blockly/core/block.ts:800

Get whether this block is deletable or not.

Returns

boolean

True if deletable.

Implementation of

IDeletable.isDeletable

Inherited from

Block.isDeletable


isOwnDeletable()

isOwnDeletable(): boolean;

Defined in: packages/blockly/core/block.ts:815

Return whether this block's own deletable property is true or false.

Returns

boolean

True if the block's deletable property is true, false otherwise.

Inherited from

Block.isOwnDeletable


isDuplicatable()

isDuplicatable(): boolean;

Defined in: packages/blockly/core/block.ts:871

Get whether is block is duplicatable or not. If duplicating this block and descendants will put this block over the workspace's capacity this block is not duplicatable. If duplicating this block and descendants will put any type over their maxInstances this block is not duplicatable.

Returns

boolean

True if duplicatable.

Inherited from

Block.isDuplicatable


isShadow()

isShadow(): boolean;

Defined in: packages/blockly/core/block.ts:885

Get whether this block is a shadow block or not.

Returns

boolean

True if a shadow.

Inherited from

Block.isShadow


isInsertionMarker()

isInsertionMarker(): boolean;

Defined in: packages/blockly/core/block.ts:906

Get whether this block is an insertion marker block or not.

Returns

boolean

True if an insertion marker.

Inherited from

Block.isInsertionMarker


isOwnEditable()

isOwnEditable(): boolean;

Defined in: packages/blockly/core/block.ts:938

Return whether this block's own editable property is true or false.

Returns

boolean

True if the block's editable property is true, false otherwise.

Inherited from

Block.isOwnEditable


isDisposed()

isDisposed(): boolean;

Defined in: packages/blockly/core/block.ts:959

Returns if this block has been disposed of / deleted.

Returns

boolean

True if this block has been disposed of / deleted.

Inherited from

Block.isDisposed


setHelpUrl()

setHelpUrl(url): void;

Defined in: packages/blockly/core/block.ts:1032

Set the URL of this block's help page.

Parameters

ParameterTypeDescription
urlstring | (() => string)URL string for block help, or function that returns a URL. Null for no help.

Returns

void

Inherited from

Block.setHelpUrl


setTooltip()

setTooltip(newTip): void;

Defined in: packages/blockly/core/block.ts:1043

Sets the tooltip for this block.

Parameters

ParameterTypeDescription
newTipTipInfoThe text for the tooltip, a function that returns the text for the tooltip, or a parent object whose tooltip will be used. To not display a tooltip pass the empty string.

Returns

void

Inherited from

Block.setTooltip


getTooltip()

getTooltip(): string;

Defined in: packages/blockly/core/block.ts:1052

Returns the tooltip text for this block.

Returns

string

The tooltip text for this block.

Inherited from

Block.getTooltip


getStyleName()

getStyleName(): string;

Defined in: packages/blockly/core/block.ts:1070

Get the name of the block style.

Returns

string

Name of the block style.

Inherited from

Block.getStyleName


getHue()

getHue(): number | null;

Defined in: packages/blockly/core/block.ts:1079

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

Returns

number | null

Hue value (0-360).

Inherited from

Block.getHue


setOnChange()

setOnChange(onchangeFn): void;

Defined in: packages/blockly/core/block.ts:1113

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.

Parameters

ParameterTypeDescription
onchangeFn(p1) => voidThe callback to call when the block's workspace changes.

Returns

void

Throws

if onchangeFn is not falsey and not a function.

Inherited from

Block.setOnChange


getField()

getField(name): Field<any> | null;

Defined in: packages/blockly/core/block.ts:1131

Returns the named field from a block.

Parameters

ParameterTypeDescription
namestringThe name of the field.

Returns

Field<any> | null

Named field, or null if field does not exist.

Inherited from

Block.getField


getFields()

getFields(): Generator<Field<any>, undefined, void>;

Defined in: packages/blockly/core/block.ts:1153

Returns a generator that provides every field on the block.

Returns

Generator<Field<any>, undefined, void>

A generator that can be used to iterate the fields on the block.

Inherited from

Block.getFields


getVarModels()

getVarModels(): IVariableModel<IVariableState>[];

Defined in: packages/blockly/core/block.ts:1166

Return all variables referenced by this block.

Returns

IVariableModel<IVariableState>[]

List of variable models.

Inherited from

Block.getVarModels


renameVarById()

renameVarById(oldId, newId): void;

Defined in: packages/blockly/core/block.ts:1209

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

Parameters

ParameterTypeDescription
oldIdstringID of variable to rename.
newIdstringID of new variable. May be the same as oldId, but with an updated name.

Returns

void

Inherited from

Block.renameVarById


getFieldValue()

getFieldValue(name): any;

Defined in: packages/blockly/core/block.ts:1223

Returns the language-neutral value of the given field.

Parameters

ParameterTypeDescription
namestringThe name of the field.

Returns

any

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

Inherited from

Block.getFieldValue


setFieldValue()

setFieldValue(newValue, name): void;

Defined in: packages/blockly/core/block.ts:1237

Sets the value of the given field for this block.

Parameters

ParameterTypeDescription
newValueanyThe value to set.
namestringThe name of the field to set the value of.

Returns

void

Inherited from

Block.setFieldValue


getInputsInline()

getInputsInline(): boolean;

Defined in: packages/blockly/core/block.ts:1367

Get whether value inputs are arranged horizontally or vertically.

Returns

boolean

True if inputs are horizontal.

Inherited from

Block.getInputsInline


setOutputShape()

setOutputShape(outputShape): void;

Defined in: packages/blockly/core/block.ts:1405

Set the block's output shape.

Parameters

ParameterTypeDescription
outputShapenumber | nullValue representing an output shape.

Returns

void

Inherited from

Block.setOutputShape


getOutputShape()

getOutputShape(): number | null;

Defined in: packages/blockly/core/block.ts:1414

Get the block's output shape.

Returns

number | null

Value representing output shape if one exists.

Inherited from

Block.getOutputShape


isEnabled()

isEnabled(): boolean;

Defined in: packages/blockly/core/block.ts:1426

Get whether this block is enabled or not. A block is considered enabled if there aren't any reasons why it would be disabled. A block may still be disabled for other reasons even if the user attempts to manually enable it, such as when the block is in an invalid location.

Returns

boolean

True if enabled.

Inherited from

Block.isEnabled


getInheritedDisabled()

getInheritedDisabled(): boolean;

Defined in: packages/blockly/core/block.ts:1488

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

Returns

boolean

True if disabled.

Inherited from

Block.getInheritedDisabled


hasDisabledReason()

hasDisabledReason(reason): boolean;

Defined in: packages/blockly/core/block.ts:1507

Get whether the block is currently disabled for the provided reason.

Parameters

ParameterTypeDescription
reasonstringA language-neutral identifier for a reason why the block could be disabled.

Returns

boolean

Whether the block is disabled for the provided reason.

Inherited from

Block.hasDisabledReason


getDisabledReasons()

getDisabledReasons(): ReadonlySet<string>;

Defined in: packages/blockly/core/block.ts:1517

Get a set of reasons why the block is currently disabled, if any. If the block is enabled, this set will be empty.

Returns

ReadonlySet<string>

The set of reasons why the block is disabled, if any.

Inherited from

Block.getDisabledReasons


isCollapsed()

isCollapsed(): boolean;

Defined in: packages/blockly/core/block.ts:1526

Get whether the block is collapsed or not.

Returns

boolean

True if collapsed.

Inherited from

Block.isCollapsed


setAriaRoleDescriptionProvider()

setAriaRoleDescriptionProvider(description): void;

Defined in: packages/blockly/core/block.ts:1560

Set a custom aria role description provider for this block. If not set, uses a default provider based on the block's properties (e.g. whether it has inputs, outputs, etc.).

Parameters

ParameterTypeDescription
descriptionstring | (() => string)The description or function to provide the description. If a string, we'll replace message references in the string, e.g. %{BKY_CUSTOM_MESSAGE} will be replaced with the value of Blockly.Msg['CUSTOM_MESSAGE'].}'

Returns

void

Inherited from

Block.setAriaRoleDescriptionProvider


getAriaRoleDescription()

getAriaRoleDescription(): string;

Defined in: packages/blockly/core/block.ts:1569

Returns

string

The string to use as the role description for this block. If a custom provider has been set, use that. Otherwise, return a default description based on the block's properties.

Inherited from

Block.getAriaRoleDescription


toString()

toString(opt_maxLength?, opt_emptyToken?): string;

Defined in: packages/blockly/core/block.ts:1596

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

Parameters

ParameterTypeDescription
opt_maxLength?numberTruncate the string to this length.
opt_emptyToken?stringThe placeholder string used to denote an empty input. If not specified, '?' is used.

Returns

string

Text of block.

Inherited from

Block.toString


appendValueInput()

appendValueInput(name): Input;

Defined in: packages/blockly/core/block.ts:1683

Appends a value input row.

Parameters

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

Returns

Input

The input object created.

Inherited from

Block.appendValueInput


appendStatementInput()

appendStatementInput(name): Input;

Defined in: packages/blockly/core/block.ts:1694

Appends a statement input row.

Parameters

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

Returns

Input

The input object created.

Inherited from

Block.appendStatementInput


appendDummyInput()

appendDummyInput(name?): Input;

Defined in: packages/blockly/core/block.ts:1706

Appends a dummy input row.

Parameters

ParameterTypeDefault valueDescription
namestring''Optional language-neutral identifier which may used to find this input again. Should be unique to this block.

Returns

Input

The input object created.

Inherited from

Block.appendDummyInput


appendEndRowInput()

appendEndRowInput(name?): Input;

Defined in: packages/blockly/core/block.ts:1717

Appends an input that ends the row.

Parameters

ParameterTypeDefault valueDescription
namestring''Optional language-neutral identifier which may used to find this input again. Should be unique to this block.

Returns

Input

The input object created.

Inherited from

Block.appendEndRowInput


mixin()

mixin(mixinObj, opt_disableCheck?): void;

Defined in: packages/blockly/core/block.ts:1917

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.

Parameters

ParameterTypeDescription
mixinObjanyThe key/values pairs to add to this block object.
opt_disableCheck?booleanOption flag to disable overwrite checks.

Returns

void

Inherited from

Block.mixin


moveInputBefore()

moveInputBefore(name, refName): void;

Defined in: packages/blockly/core/block.ts:2223

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

Parameters

ParameterTypeDescription
namestringThe name of the input to move.
refNamestring | nullName of input that should be after the moved input, or null to be the input at the end.

Returns

void

Inherited from

Block.moveInputBefore


getInput()

getInput(name): Input | null;

Defined in: packages/blockly/core/block.ts:2309

Fetches the named input object.

Parameters

ParameterTypeDescription
namestringThe name of the input.

Returns

Input | null

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

Inherited from

Block.getInput


getInputTargetBlock()

getInputTargetBlock(name): Block | null;

Defined in: packages/blockly/core/block.ts:2326

Fetches the block attached to the named input.

Parameters

ParameterTypeDescription
namestringThe name of the input.

Returns

Block | null

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

Inherited from

Block.getInputTargetBlock


getCommentText()

getCommentText(): string | null;

Defined in: packages/blockly/core/block.ts:2336

Returns the comment on this block (or null if there is no comment).

Returns

string | null

Block's comment.

Inherited from

Block.getCommentText


setCommentText()

setCommentText(text): void;

Defined in: packages/blockly/core/block.ts:2346

Set this block's comment text.

Parameters

ParameterTypeDescription
textstring | nullThe text, or null to delete.

Returns

void

Inherited from

Block.setCommentText


hasIcon()

hasIcon(type): boolean;

Defined in: packages/blockly/core/block.ts:2436

Parameters

ParameterType
typeIconType<IIcon>

Returns

boolean

True if an icon with the given type exists on the block, false otherwise.

Inherited from

Block.hasIcon


getIcon()

getIcon<T>(type): T | undefined;

Defined in: packages/blockly/core/block.ts:2446

Type Parameters

Type Parameter
T extends IIcon

Parameters

ParameterTypeDescription
typestring | IconType<T>The type of the icon to retrieve. Prefer passing an IconType for proper type checking when using typescript.

Returns

T | undefined

The icon with the given type if it exists on the block, undefined otherwise.

Inherited from

Block.getIcon


getIcons()

getIcons(): IIcon[];

Defined in: packages/blockly/core/block.ts:2455

Returns

IIcon[]

An array of the icons attached to this block.

Inherited from

Block.getIcons


getRelativeToSurfaceXY()

getRelativeToSurfaceXY(): Coordinate;

Defined in: packages/blockly/core/block.ts:2465

Return the coordinates of the top-left corner of this block relative to the drawing surface's origin (0,0), in workspace units.

Returns

Coordinate

Object with .x and .y properties.

Implementation of

IDraggable.getRelativeToSurfaceXY

Inherited from

Block.getRelativeToSurfaceXY


allInputsFilled()

allInputsFilled(opt_shadowBlocksAreFilled?): boolean;

Defined in: packages/blockly/core/block.ts:2506

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

Parameters

ParameterTypeDescription
opt_shadowBlocksAreFilled?booleanAn optional argument controlling whether shadow blocks are counted as filled. Defaults to true.

Returns

boolean

True if all inputs are filled, false otherwise.

Inherited from

Block.allInputsFilled


toDevString()

toDevString(): string;

Defined in: packages/blockly/core/block.ts:2545

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 (Block:class).toString | toString().

Returns

string

The description.

Inherited from

Block.toDevString


initSvg()

initSvg(): void;

Defined in: packages/blockly/core/block_svg.ts:228

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

Returns

void


getColourSecondary()

getColourSecondary(): string;

Defined in: packages/blockly/core/block_svg.ts:256

Get the secondary colour of a block.

Returns

string

#RRGGBB string.


getColourTertiary()

getColourTertiary(): string;

Defined in: packages/blockly/core/block_svg.ts:265

Get the tertiary colour of a block.

Returns

string

#RRGGBB string.


select()

select(): void;

Defined in: packages/blockly/core/block_svg.ts:270

Selects this block. Highlights the block visually.

Returns

void

Implementation of

IDraggable.select


unselect()

unselect(): void;

Defined in: packages/blockly/core/block_svg.ts:276

Unselects this block. Unhighlights the block visually.

Returns

void

Implementation of

IDraggable.unselect


moveBy()

moveBy(
dx,
dy,
reason?
): void;

Defined in: packages/blockly/core/block_svg.ts:343

Move a block by a relative offset.

Parameters

ParameterTypeDescription
dxnumberHorizontal offset in workspace units.
dynumberVertical offset in workspace units.
reason?string[]Why is this move happening? 'drag', 'bump', 'snap', ...

Returns

void

Implementation of

IDraggable.moveBy

Overrides

Block.moveBy


translate()

translate(x, y): void;

Defined in: packages/blockly/core/block_svg.ts:376

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

Parameters

ParameterTypeDescription
xnumberThe x coordinate of the translation in workspace units.
ynumberThe y coordinate of the translation in workspace units.

Returns

void


moveTo()

moveTo(xy, reason?): void;

Defined in: packages/blockly/core/block_svg.ts:397

Move a block to a position.

Parameters

ParameterTypeDescription
xyCoordinateThe position to move to in workspace units.
reason?string[]Why is this move happening? 'drag', 'bump', 'snap', ...

Returns

void


snapToGrid()

snapToGrid(): void;

Defined in: packages/blockly/core/block_svg.ts:415

Snap this block to the nearest grid point.

Returns

void


getBoundingRectangle()

getBoundingRectangle(): Rect;

Defined in: packages/blockly/core/block_svg.ts:435

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

Returns

Rect

Object with coordinates of the bounding box.

Implementation of

IDraggable.getBoundingRectangle


getBoundingRectangleWithoutChildren()

getBoundingRectangleWithoutChildren(): Rect;

Defined in: packages/blockly/core/block_svg.ts:446

Returns the coordinates of a bounding box describing the dimensions of this block alone. Coordinate system: workspace coordinates.

Returns

Rect

Object with coordinates of the bounding box.


markDirty()

markDirty(): void;

Defined in: packages/blockly/core/block_svg.ts:474

Notify every input on this block to mark its fields as dirty. A dirty field is a field that needs to be re-rendered.

Returns

void


setCollapsed()

setCollapsed(collapsed): void;

Defined in: packages/blockly/core/block_svg.ts:486

Set whether the block is collapsed or not.

Parameters

ParameterTypeDescription
collapsedbooleanTrue if collapsed.

Returns

void

Overrides

Block.setCollapsed


generateContextMenu()

protected generateContextMenu(e):
| (
| ContextMenuOption
| LegacyContextMenuOption)[]
| null;

Defined in: packages/blockly/core/block_svg.ts:599

Generate the context menu for this block.

Parameters

ParameterType
eEvent

Returns

| ( | ContextMenuOption | LegacyContextMenuOption)[] | null

Context menu options or null if no menu.


calculateContextMenuLocation()

protected calculateContextMenuLocation(e): Coordinate;

Defined in: packages/blockly/core/block_svg.ts:623

Gets the location in which to show the context menu for this block. Use the location of a click if the block was clicked, or a location based on the block's fields otherwise.

Parameters

ParameterType
eEvent

Returns

Coordinate


addClass()

addClass(className): void;

Defined in: packages/blockly/core/block_svg.ts:732

Add a CSS class to the SVG group of this block.

Parameters

ParameterType
classNamestring

Returns

void


removeClass()

removeClass(className): void;

Defined in: packages/blockly/core/block_svg.ts:741

Remove a CSS class from the SVG group of this block.

Parameters

ParameterType
classNamestring

Returns

void


isDragging()

isDragging(): boolean;

Defined in: packages/blockly/core/block_svg.ts:774

Returns whether or not this block is currently being dragged.

Returns

boolean


setMovable()

setMovable(movable): void;

Defined in: packages/blockly/core/block_svg.ts:783

Set whether this block is movable or not.

Parameters

ParameterTypeDescription
movablebooleanTrue if movable.

Returns

void

Overrides

Block.setMovable


setEditable()

setEditable(editable): void;

Defined in: packages/blockly/core/block_svg.ts:793

Set whether this block is editable or not.

Parameters

ParameterTypeDescription
editablebooleanTrue if editable.

Returns

void

Overrides

Block.setEditable


getSvgRoot()

getSvgRoot(): SVGGElement;

Defined in: packages/blockly/core/block_svg.ts:847

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

Returns

SVGGElement

The root SVG node (probably a group).


dispose()

dispose(healStack?, animate?): void;

Defined in: packages/blockly/core/block_svg.ts:885

Dispose of this block.

Parameters

ParameterTypeDescription
healStack?booleanIf 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?booleanIf true, show a disposal animation and sound.

Returns

void

Implementation of

IDeletable.dispose

Overrides

Block.dispose


disposeInternal()

disposeInternal(): void;

Defined in: packages/blockly/core/block_svg.ts:951

Disposes of this block without doing things required by the top block. E.g. does trigger UI effects, remove nodes, etc.

Returns

void

Overrides

Block.disposeInternal


checkAndDelete()

checkAndDelete(): void;

Defined in: packages/blockly/core/block_svg.ts:972

Delete a block and hide chaff when doing so. The block will not be deleted if it's in a flyout. This is called from the context menu and keyboard shortcuts as the full delete action. If you are disposing of a block from the workspace and don't need to perform flyout checks, handle event grouping, or hide chaff, then use block.dispose() directly.

Returns

void


toCopyData()

toCopyData(addNextBlocks?):
| BlockCopyData
| null;

Defined in: packages/blockly/core/block_svg.ts:996

Encode a block for copying.

Parameters

ParameterTypeDefault valueDescription
addNextBlocksbooleanfalseIf true, copy subsequent blocks attached to this one as well.

Returns

| BlockCopyData | null

Copy metadata, or null if the block is an insertion marker.

Implementation of

ICopyable.toCopyData


setWarningText()

setWarningText(text, id?): void;

Defined in: packages/blockly/core/block_svg.ts:1058

Set this block's warning text.

Parameters

ParameterTypeDefault valueDescription
textstring | nullundefinedThe text, or null to delete.
idstring''An optional ID for the warning text to be able to maintain multiple warnings.

Returns

void

Overrides

Block.setWarningText


setMutator()

setMutator(mutator): void;

Defined in: packages/blockly/core/block_svg.ts:1130

Give this block a mutator dialog.

Parameters

ParameterTypeDescription
mutatorMutatorIcon | nullA mutator dialog instance or null to remove.

Returns

void

Overrides

Block.setMutator


addIcon()

addIcon<T>(icon): T;

Defined in: packages/blockly/core/block_svg.ts:1135

Adds the given icon to the block.

Type Parameters

Type Parameter
T extends IIcon

Parameters

ParameterType
iconT

Returns

T

Overrides

Block.addIcon


removeIcon()

removeIcon(type): boolean;

Defined in: packages/blockly/core/block_svg.ts:1164

Removes the icon whose getType matches the given type iconType from the block.

Parameters

ParameterTypeDescription
typeIconType<IIcon>The type of the icon to remove from the block.

Returns

boolean

True if an icon with the given type was found, false otherwise.

Overrides

Block.removeIcon


setDisabledReason()

setDisabledReason(disabled, reason): void;

Defined in: packages/blockly/core/block_svg.ts:1188

Add or remove a reason why the block might be disabled. If a block has any reasons to be disabled, then the block itself will be considered disabled. A block could be disabled for multiple independent reasons simultaneously, such as when the user manually disables it, or the block is invalid.

Parameters

ParameterTypeDescription
disabledbooleanIf true, then the block should be considered disabled for at least the provided reason, otherwise the block is no longer disabled for that reason.
reasonstringA language-neutral identifier for a reason why the block could be disabled. Call this method again with the same identifier to update whether the block is currently disabled for this reason.

Returns

void

Overrides

Block.setDisabledReason


setDeletable()

setDeletable(deletable): void;

Defined in: packages/blockly/core/block_svg.ts:1200

Add blocklyNotDeletable class when block is not deletable Or remove class when block is deletable

Parameters

ParameterType
deletableboolean

Returns

void

Overrides

Block.setDeletable


setHighlighted()

setHighlighted(highlighted): void;

Defined in: packages/blockly/core/block_svg.ts:1216

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

Parameters

ParameterTypeDescription
highlightedbooleanTrue if highlighted.

Returns

void


addSelect()

addSelect(): void;

Defined in: packages/blockly/core/block_svg.ts:1226

Adds the visual "select" effect to the block, but does not actually select it or fire an event.

Returns

void

See

BlockSvg#select


removeSelect()

removeSelect(): void;

Defined in: packages/blockly/core/block_svg.ts:1236

Removes the visual "select" effect from the block, but does not actually unselect it or fire an event.

Returns

void

See

BlockSvg#unselect


getColour()

getColour(): string;

Defined in: packages/blockly/core/block_svg.ts:1258

Get the colour of a block.

Returns

string

#RRGGBB string.

Overrides

Block.getColour


setColour()

setColour(colour): void;

Defined in: packages/blockly/core/block_svg.ts:1267

Change the colour of a block.

Parameters

ParameterTypeDescription
colourstring | numberHSV hue value, or #RRGGBB string.

Returns

void

Overrides

Block.setColour


setStyle()

setStyle(blockStyleName): void;

Defined in: packages/blockly/core/block_svg.ts:1287

Set the style and colour values of a block.

Parameters

ParameterTypeDescription
blockStyleNamestringName of the block style.

Returns

void

Throws

if the block style does not exist.

Overrides

Block.setStyle


getStyle()

getStyle(): BlockStyle;

Defined in: packages/blockly/core/block_svg.ts:1318

Returns the BlockStyle object used to style this block.

Returns

BlockStyle

This block's style object.


bringToFront()

bringToFront(blockOnly?): void;

Defined in: packages/blockly/core/block_svg.ts:1333

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. Use sparingly, this method is expensive because it reorders the DOM nodes.

Parameters

ParameterTypeDefault valueDescription
blockOnlybooleanfalseTrue to only move this block to the front without adjusting its parents.

Returns

void


setPreviousStatement()

setPreviousStatement(newBoolean, opt_check?): void;

Defined in: packages/blockly/core/block_svg.ts:1390

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

Parameters

ParameterTypeDescription
newBooleanbooleanTrue if there can be a previous statement.
opt_check?string | string[] | nullStatement type or list of statement types. Null/undefined if any type could be connected.

Returns

void

Overrides

Block.setPreviousStatement


setNextStatement()

setNextStatement(newBoolean, opt_check?): void;

Defined in: packages/blockly/core/block_svg.ts:1405

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

Parameters

ParameterTypeDescription
newBooleanbooleanTrue if there can be a next statement.
opt_check?string | string[] | nullStatement type or list of statement types. Null/undefined if any type could be connected.

Returns

void

Overrides

Block.setNextStatement


setOutput()

setOutput(newBoolean, opt_check?): void;

Defined in: packages/blockly/core/block_svg.ts:1420

Set whether this block returns a value.

Parameters

ParameterTypeDescription
newBooleanbooleanTrue if there is an output.
opt_check?string | string[] | nullReturned type or list of returned types. Null or undefined if any type could be returned (e.g. variable get).

Returns

void

Overrides

Block.setOutput


setInputsInline()

setInputsInline(newBoolean): void;

Defined in: packages/blockly/core/block_svg.ts:1433

Set whether value inputs are arranged horizontally or vertically.

Parameters

ParameterTypeDescription
newBooleanbooleanTrue if inputs are horizontal.

Returns

void

Overrides

Block.setInputsInline


removeInput()

removeInput(name, opt_quiet?): boolean;

Defined in: packages/blockly/core/block_svg.ts:1447

Remove an input from this block.

Parameters

ParameterTypeDescription
namestringThe name of the input.
opt_quiet?booleanTrue to prevent error if input is not present.

Returns

boolean

True if operation succeeds, false if input is not present and opt_quiet is true

Throws

if the input is not present and opt_quiet is not true.

Overrides

Block.removeInput


moveNumberedInputBefore()

moveNumberedInputBefore(inputIndex, refIndex): void;

Defined in: packages/blockly/core/block_svg.ts:1459

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

Parameters

ParameterTypeDescription
inputIndexnumberIndex of the input to move.
refIndexnumberIndex of input that should be after the moved input.

Returns

void

Overrides

Block.moveNumberedInputBefore


appendInput()

appendInput(input): Input;

Defined in: packages/blockly/core/block_svg.ts:1464

Appends the given input row.

Allows for custom inputs to be appended to the block.

Parameters

ParameterType
inputInput

Returns

Input

Overrides

Block.appendInput


getNextBlock()

getNextBlock(): BlockSvg | null;

Defined in: packages/blockly/core/block_svg.ts:1594

Return the next statement block directly connected to this block.

Returns

BlockSvg | null

The next statement block or null.

Overrides

Block.getNextBlock


getPreviousBlock()

getPreviousBlock(): BlockSvg | null;

Defined in: packages/blockly/core/block_svg.ts:1603

Returns the block connected to the previous connection.

Returns

BlockSvg | null

The previous statement block or null.

Overrides

Block.getPreviousBlock


bumpNeighbours()

bumpNeighbours(): void;

Defined in: packages/blockly/core/block_svg.ts:1613

Bumps unconnected blocks out of alignment.

Two blocks which aren't actually connected should not coincidentally line up on screen, because that creates confusion for end-users.

Returns

void

Overrides

Block.bumpNeighbours


scheduleSnapAndBump()

scheduleSnapAndBump(): void;

Defined in: packages/blockly/core/block_svg.ts:1651

Snap to grid, and then bump neighbouring blocks away at the end of the next render.

Returns

void


getChildren()

getChildren(ordered): BlockSvg[];

Defined in: packages/blockly/core/block_svg.ts:1697

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.

Parameters

ParameterTypeDescription
orderedbooleanSort the list if true.

Returns

BlockSvg[]

Array of blocks.

Overrides

Block.getChildren


render()

render(): void;

Defined in: packages/blockly/core/block_svg.ts:1717

Immediately lays out and reflows a block based on its contents and settings.

Returns

void


setDragStrategy()

setDragStrategy(dragStrategy): void;

Defined in: packages/blockly/core/block_svg.ts:1808

Sets the drag strategy for this block.

Parameters

ParameterType
dragStrategyIDragStrategy

Returns

void


isCopyable()

isCopyable(): boolean;

Defined in: packages/blockly/core/block_svg.ts:1813

Returns whether this block is copyable or not.

Returns

boolean

Implementation of

ICopyable.isCopyable


isMovable()

isMovable(): boolean;

Defined in: packages/blockly/core/block_svg.ts:1818

Returns whether this block is movable or not.

Returns

boolean

Implementation of

IDraggable.isMovable

Overrides

Block.isMovable

startDrag()

startDrag(e?): IDraggable;

Defined in: packages/blockly/core/block_svg.ts:1823

Starts a drag on the block.

Parameters

ParameterType
e?PointerEvent | KeyboardEvent

Returns

IDraggable

Implementation of

IDraggable.startDrag


drag()

drag(newLoc, e?): void;

Defined in: packages/blockly/core/block_svg.ts:1828

Drags the block to the given location.

Parameters

ParameterType
newLocCoordinate
e?PointerEvent | KeyboardEvent

Returns

void

Implementation of

IDraggable.drag


endDrag()

endDrag(e, disposition): void;

Defined in: packages/blockly/core/block_svg.ts:1833

Ends the drag on the block.

Parameters

ParameterType
ePointerEvent | KeyboardEvent | undefined
dispositionDragDisposition

Returns

void

Implementation of

IDraggable.endDrag


revertDrag()

revertDrag(): void;

Defined in: packages/blockly/core/block_svg.ts:1841

Moves the block back to where it was at the start of a drag.

Returns

void

Implementation of

IDraggable.revertDrag


toFlyoutInfo()

toFlyoutInfo(): FlyoutItemInfo[];

Defined in: packages/blockly/core/block_svg.ts:1848

Returns a representation of this block that can be displayed in a flyout.

Returns

FlyoutItemInfo[]


jsonInit()

jsonInit(json): void;

Defined in: packages/blockly/core/block_svg.ts:1871

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

Parameters

ParameterTypeDescription
jsonanyStructured data describing the block.

Returns

void

Overrides

Block.jsonInit


getFocusableElement()

getFocusableElement(): HTMLElement | SVGElement;

Defined in: packages/blockly/core/block_svg.ts:1894

See IFocusableNode.getFocusableElement.

Returns

HTMLElement | SVGElement

Implementation of

IFocusableNode.getFocusableElement


getFocusableTree()

getFocusableTree(): IFocusableTree;

Defined in: packages/blockly/core/block_svg.ts:1904

See IFocusableNode.getFocusableTree.

Returns

IFocusableTree

Implementation of

IFocusableNode.getFocusableTree


onNodeFocus()

onNodeFocus(): void;

Defined in: packages/blockly/core/block_svg.ts:1909

See IFocusableNode.onNodeFocus.

Returns

void

Implementation of

IFocusableNode.onNodeFocus


onNodeBlur()

onNodeBlur(): void;

Defined in: packages/blockly/core/block_svg.ts:1926

See IFocusableNode.onNodeBlur.

Returns

void

Implementation of

IFocusableNode.onNodeBlur


canBeFocused()

canBeFocused(): boolean;

Defined in: packages/blockly/core/block_svg.ts:1931

See IFocusableNode.canBeFocused.

Returns

boolean

Implementation of

IFocusableNode.canBeFocused


performAction()

performAction(e?): void;

Defined in: packages/blockly/core/block_svg.ts:1941

Handles the user acting on this block via keyboard navigation. If this block is in the flyout, a new copy is spawned in move mode on the main workspace. If this block has a single full-block field, that field will be focused. Otherwise, this is a no-op.

Parameters

ParameterType
e?KeyboardEvent

Returns

void

Implementation of

IFocusableNode.performAction


getAriaLabel()

getAriaLabel(verbosity): string;

Defined in: packages/blockly/core/block_svg.ts:2046

Returns a description of this block suitable for screenreaders or use in ARIA attributes.

Parameters

ParameterTypeDescription
verbosityVerbosityHow much detail to include in the description.

Returns

string

An accessibility description of this block.