Skip to main content

Class: Block

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

Class for one block. Not normally called directly, workspace.newBlock() is preferred.

Extended by

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.
decomposeAn optional function that populates the mutator flyout with blocks representing this block's configuration.
id-
outputConnection-
nextConnection-
previousConnection-
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.
renderedIs this block a BlockSVG?
helpUrlString for block help, or function that returns a URL. Null for no help.
type-
inputsInlineDefault-
workspace-

Methods index

MethodDescription
doInit_Calls the init() function and handles associated event firing, etc.
disposeDispose of this block.
disposeInternalDisposes of this block without doing things required by the top block. E.g. does not fire events, unplug the block, 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.
bumpNeighboursBump unconnected blocks out of alignment. Two blocks which aren't actually connected should not coincidentally line up on screen.
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.
getNextBlockReturn the next statement block directly connected to this block.
getPreviousBlockReturns the block connected to the previous connection.
getRootBlockReturn the top-most block in this block's tree. This will return itself if this block is at the top level.
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.
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.
setDeletableSet whether this block is deletable or not.
setMovableSet whether this block is movable or not.
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.
setEditableSet whether this block is editable or not.
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.
getColourGet the colour of a block.
getStyleNameGet the name of the block style.
getHueGet the HSV hue value of a block. Null if hue not set.
setColourChange the colour of a block.
setStyleSet the style and colour values of a block.
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.
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.
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.
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.
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.
setCollapsedSet 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.
appendInputAppends the given input row.
jsonInitInitialize this block using a cross-platform, internationalization-friendly JSON description.
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.
moveNumberedInputBeforeMove a numbered input to a different location on this block.
removeInputRemove an input from 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.
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.
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.
moveByMove a block by a relative offset.
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).

Constructors

Constructor

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

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

Parameters

ParameterTypeDescription
workspaceWorkspaceThe 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

Block

Throws

When the prototypeName is not valid or not allowed.

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.


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.


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.


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.


colour_

protected colour_: string = '#000000';

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

Colour of the block in '#RRGGBB' format.


styleName_

protected styleName_: string = '';

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

Name of the block style.


init?

optional init?: () => void;

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

An optional method called during initialization.

Returns

void


destroy?

optional destroy?: () => void;

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

An optional method called during disposal.

Returns

void


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


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


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


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


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.


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.


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


decompose?

optional decompose?: (workspace) => Block;

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

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

Parameters

ParameterTypeDescription
workspaceWorkspaceThe mutator flyout's workspace.

Returns

Block

The root block created in the flyout's workspace.


id

id: string;

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


outputConnection

outputConnection: Connection | null = null;

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


nextConnection

nextConnection: Connection | null = null;

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


previousConnection

previousConnection: Connection | null = null;

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


inputList

inputList: Input[] = [];

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


inputsInline?

optional inputsInline?: boolean;

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


icons

icons: IIcon[] = [];

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


tooltip

tooltip: TipInfo = '';

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


contextMenu

contextMenu: boolean = true;

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


parentBlock_

protected parentBlock_: Block | null = null;

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


childBlocks_

protected childBlocks_: Block[] = [];

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


collapsed_

protected collapsed_: boolean = false;

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


outputShape_

protected outputShape_: number | null = null;

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


disposing

protected disposing: boolean = false;

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

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


xy

protected readonly xy: Coordinate;

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


isInFlyout

isInFlyout: boolean;

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


isInMutator

isInMutator: boolean;

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


RTL

RTL: boolean;

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


isInsertionMarker_

protected isInsertionMarker_: boolean = false;

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

True if this block is an insertion marker.


hat?

optional hat?: string;

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

Name of the type of hat.


rendered

readonly rendered: boolean = false;

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

Is this block a BlockSVG?


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.


type

type: string;

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


inputsInlineDefault?

optional inputsInlineDefault?: boolean;

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


workspace

workspace: Workspace;

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

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


dispose()

dispose(healStack?): void;

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

Dispose of this block.

Parameters

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

Returns

void


disposeInternal()

protected disposeInternal(): void;

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

Disposes of this block without doing things required by the top block. E.g. does not fire events, unplug the block, etc.

Returns

void


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


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


bumpNeighbours()

bumpNeighbours(): void;

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

Bump unconnected blocks out of alignment. Two blocks which aren't actually connected should not coincidentally line up on screen.

Returns

void


getParent()

getParent(): Block | 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

Block | null

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


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.


getSurroundParent()

getSurroundParent(): Block | 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

Block | null

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


getNextBlock()

getNextBlock(): Block | null;

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

Return the next statement block directly connected to this block.

Returns

Block | null

The next statement block or null.


getPreviousBlock()

getPreviousBlock(): Block | null;

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

Returns the block connected to the previous connection.

Returns

Block | null

The previous statement block or null.


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.


getChildren()

getChildren(ordered): Block[];

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

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

Block[]

Array of blocks.


getDescendants()

getDescendants(ordered): Block[];

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

Block[]

Flattened array of blocks.


isDeletable()

isDeletable(): boolean;

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

Get whether this block is deletable or not.

Returns

boolean

True if deletable.


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.


setDeletable()

setDeletable(deletable): void;

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

Set whether this block is deletable or not.

Parameters

ParameterTypeDescription
deletablebooleanTrue if deletable.

Returns

void


setMovable()

setMovable(movable): void;

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

Set whether this block is movable or not.

Parameters

ParameterTypeDescription
movablebooleanTrue if movable.

Returns

void


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.


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.


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.


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.


setEditable()

setEditable(editable): void;

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

Set whether this block is editable or not.

Parameters

ParameterTypeDescription
editablebooleanTrue if editable.

Returns

void


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.


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


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


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.


getColour()

getColour(): string;

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

Get the colour of a block.

Returns

string

#RRGGBB string.


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.


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


setColour()

setColour(colour): void;

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

Change the colour of a block.

Parameters

ParameterTypeDescription
colourstring | numberHSV hue value (0 to 360), #RRGGBB string, or a message reference string pointing to one of those two values.

Returns

void


setStyle()

setStyle(blockStyleName): void;

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

Set the style and colour values of a block.

Parameters

ParameterTypeDescription
blockStyleNamestringName of the block style.

Returns

void


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.


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.


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.


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.


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


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.


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


setPreviousStatement()

setPreviousStatement(newBoolean, opt_check?): void;

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

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


setNextStatement()

setNextStatement(newBoolean, opt_check?): void;

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

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


setOutput()

setOutput(newBoolean, opt_check?): void;

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

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


setInputsInline()

setInputsInline(newBoolean): void;

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

Set whether value inputs are arranged horizontally or vertically.

Parameters

ParameterTypeDescription
newBooleanbooleanTrue if inputs are horizontal.

Returns

void


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.


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


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.


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.


setDisabledReason()

setDisabledReason(disabled, reason): void;

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

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


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.


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.


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.


isCollapsed()

isCollapsed(): boolean;

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

Get whether the block is collapsed or not.

Returns

boolean

True if collapsed.


setCollapsed()

setCollapsed(collapsed): void;

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

Set whether the block is collapsed or not.

Parameters

ParameterTypeDescription
collapsedbooleanTrue if collapsed.

Returns

void


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


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.


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.


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.


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.


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.


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.


appendInput()

appendInput(input): Input;

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

Appends the given input row.

Allows for custom inputs to be appended to the block.

Parameters

ParameterType
inputInput

Returns

Input


jsonInit()

jsonInit(json): void;

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

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

Parameters

ParameterTypeDescription
jsonanyStructured data describing the block.

Returns

void


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


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


moveNumberedInputBefore()

moveNumberedInputBefore(inputIndex, refIndex): void;

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

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


removeInput()

removeInput(name, opt_quiet?): boolean;

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

Remove an input from this block.

Parameters

ParameterTypeDescription
namestringThe name of the input.
opt_quiet?booleanTrue to prevent an 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.


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.


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.


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.


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


setWarningText()

setWarningText(_text, _opt_id?): void;

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

Set this block's warning text.

Parameters

ParameterTypeDescription
_textstring | nullThe text, or null to delete.
_opt_id?stringAn optional ID for the warning text to be able to maintain multiple warnings.

Returns

void


setMutator()

setMutator(_mutator): void;

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

Give this block a mutator dialog.

Parameters

ParameterTypeDescription
_mutatorMutatorIconA mutator dialog instance or null to remove.

Returns

void


addIcon()

addIcon<T>(icon): T;

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

Adds the given icon to the block.

Type Parameters

Type Parameter
T extends IIcon

Parameters

ParameterType
iconT

Returns

T


removeIcon()

removeIcon(type): boolean;

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

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.


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.


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.


getIcons()

getIcons(): IIcon[];

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

Returns

IIcon[]

An array of the icons attached to this block.


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.


moveBy()

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

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

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


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.


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.