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
| Property | Description |
|---|---|
| onchange | 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 | The language-neutral ID given to the collapsed input. |
| COLLAPSED_FIELD_NAME | The language-neutral ID given to the collapsed field. |
| data | Optional 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. |
| init | An optional method called during initialization. |
| destroy | An optional method called during disposal. |
| mutationToDom | An optional serialization method for defining how to serialize the mutation state to XML. This must be coupled with defining domToMutation. |
| domToMutation | An optional deserialization method for defining how to deserialize the mutation state from XML. This must be coupled with defining mutationToDom. |
| saveExtraState | 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. |
| loadExtraState | 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. |
| suppressPrefixSuffix | An optional property for suppressing adding STATEMENT_PREFIX and STATEMENT_SUFFIX to generated code. |
| getDeveloperVariables | 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. |
| compose | An optional method that reconfigures the block based on the contents of the mutator dialog. |
| decompose | An 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_ | - |
| disposing | Is the current block currently in the process of being disposed? |
| xy | - |
| isInFlyout | - |
| isInMutator | - |
| RTL | - |
| isInsertionMarker_ | True if this block is an insertion marker. |
| hat | Name of the type of hat. |
| rendered | Is this block a BlockSVG? |
| helpUrl | String for block help, or function that returns a URL. Null for no help. |
| type | - |
| inputsInlineDefault | - |
| workspace | - |
Methods index
| Method | Description |
|---|---|
| doInit_ | Calls the init() function and handles associated event firing, etc. |
| dispose | Dispose of this block. |
| disposeInternal | Disposes of this block without doing things required by the top block. E.g. does not fire events, unplug the block, etc. |
| initModel | Call initModel on all fields on the block. May be called more than once. Either initModel or initSvg must be called after creating a block and before the first interaction with it. Interactions include UI actions (e.g. clicking and dragging) and firing events (e.g. create, delete, and change). |
| unplug | Unplug this block from its superior block. If this block is a statement, optionally reconnect the block underneath with the block on top. |
| bumpNeighbours | Bump unconnected blocks out of alignment. Two blocks which aren't actually connected should not coincidentally line up on screen. |
| getParent | 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). |
| getInputWithBlock | Return the input that connects to the specified block. |
| getSurroundParent | 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. |
| getNextBlock | Return the next statement block directly connected to this block. |
| getPreviousBlock | Returns the block connected to the previous connection. |
| getRootBlock | Return the top-most block in this block's tree. This will return itself if this block is at the top level. |
| getChildren | 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. |
| getDescendants | 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. |
| isDeletable | Get whether this block is deletable or not. |
| isOwnDeletable | Return whether this block's own deletable property is true or false. |
| setDeletable | Set whether this block is deletable or not. |
| setMovable | Set whether this block is movable or not. |
| isDuplicatable | 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. |
| isShadow | Get whether this block is a shadow block or not. |
| isInsertionMarker | Get whether this block is an insertion marker block or not. |
| isOwnEditable | Return whether this block's own editable property is true or false. |
| setEditable | Set whether this block is editable or not. |
| isDisposed | Returns if this block has been disposed of / deleted. |
| setHelpUrl | Set the URL of this block's help page. |
| setTooltip | Sets the tooltip for this block. |
| getTooltip | Returns the tooltip text for this block. |
| getColour | Get the colour of a block. |
| getStyleName | Get the name of the block style. |
| getHue | Get the HSV hue value of a block. Null if hue not set. |
| setColour | Change the colour of a block. |
| setStyle | Set the style and colour values of a block. |
| setOnChange | 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. |
| getField | Returns the named field from a block. |
| getFields | Returns a generator that provides every field on the block. |
| getVarModels | Return all variables referenced by this block. |
| renameVarById | Notification that a variable is renaming. If the ID matches one of this block's variables, rename it. |
| getFieldValue | Returns the language-neutral value of the given field. |
| setFieldValue | Sets the value of the given field for this block. |
| setPreviousStatement | Set whether this block can chain onto the bottom of another block. |
| setNextStatement | Set whether another block can chain onto the bottom of this block. |
| setOutput | Set whether this block returns a value. |
| setInputsInline | Set whether value inputs are arranged horizontally or vertically. |
| getInputsInline | Get whether value inputs are arranged horizontally or vertically. |
| setOutputShape | Set the block's output shape. |
| getOutputShape | Get the block's output shape. |
| isEnabled | 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. |
| setDisabledReason | 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. |
| getInheritedDisabled | Get whether the block is disabled or not due to parents. The block's own disabled property is not considered. |
| hasDisabledReason | Get whether the block is currently disabled for the provided reason. |
| getDisabledReasons | Get a set of reasons why the block is currently disabled, if any. If the block is enabled, this set will be empty. |
| isCollapsed | Get whether the block is collapsed or not. |
| setCollapsed | Set whether the block is collapsed or not. |
| setAriaRoleDescriptionProvider | 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.). |
| getAriaRoleDescription | Returns 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 | Create a human-readable text representation of this block and any children. |
| appendValueInput | Appends a value input row. |
| appendStatementInput | Appends a statement input row. |
| appendDummyInput | Appends a dummy input row. |
| appendEndRowInput | Appends an input that ends the row. |
| appendInput | Appends the given input row. |
| jsonInit | Initialize this block using a cross-platform, internationalization-friendly JSON description. |
| mixin | 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. |
| moveInputBefore | Move a named input to a different location on this block. |
| moveNumberedInputBefore | Move a numbered input to a different location on this block. |
| removeInput | Remove an input from this block. |
| getInput | Fetches the named input object. |
| getInputTargetBlock | Fetches the block attached to the named input. |
| getCommentText | Returns the comment on this block (or null if there is no comment). |
| setCommentText | Set this block's comment text. |
| setWarningText | Set this block's warning text. |
| setMutator | Give this block a mutator dialog. |
| addIcon | Adds the given icon to the block. |
| removeIcon | Removes the icon whose getType matches the given type iconType from the block. |
| hasIcon | Returns true if an icon with the given type exists on the block, false otherwise. |
| getIcon | Returns the icon with the given type if it exists on the block, undefined otherwise. |
| getIcons | Returns an array of the icons attached to this block. |
| getRelativeToSurfaceXY | Return the coordinates of the top-left corner of this block relative to the drawing surface's origin (0,0), in workspace units. |
| moveBy | Move a block by a relative offset. |
| allInputsFilled | Recursively checks whether all statement and value inputs are filled with blocks. Also checks all following statement blocks in this stack. |
| toDevString | This 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
| Parameter | Type | Description |
|---|---|---|
workspace | Workspace | The block's workspace. |
prototypeName | string | Name of the language object containing type-specific functions for this block. |
opt_id? | string | Optional 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
| Parameter | Type |
|---|---|
...p1 | any[] |
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
| Parameter | Type |
|---|---|
p1 | Element |
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
| Parameter | Type | Description |
|---|---|---|
doFullSerialization? | boolean | Whether 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
| Parameter | Type |
|---|---|
p1 | any |
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
| Parameter | Type | Description |
|---|---|---|
rootBlock | Block | The 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
| Parameter | Type | Description |
|---|---|---|
workspace | Workspace | The 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
| Parameter | Type | Default value | Description |
|---|---|---|---|
healStack | boolean | false | If true, then try to heal any gap by connecting the next statement with the previous statement. Otherwise, dispose of all children of this block. |
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
| Parameter | Type | Description |
|---|---|---|
opt_healStack? | boolean | Disconnect 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
| Parameter | Type | Description |
|---|---|---|
block | Block | A 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
| Parameter | Type | Description |
|---|---|---|
ordered | boolean | Sort 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
| Parameter | Type | Description |
|---|---|---|
ordered | boolean | Sort 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
| Parameter | Type | Description |
|---|---|---|
deletable | boolean | True 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
| Parameter | Type | Description |
|---|---|---|
movable | boolean | True 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
| Parameter | Type | Description |
|---|---|---|
editable | boolean | True 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
| Parameter | Type | Description |
|---|---|---|
url | string | (() => 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
| Parameter | Type | Description |
|---|---|---|
newTip | TipInfo | The 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
| Parameter | Type | Description |
|---|---|---|
colour | string | number | HSV 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
| Parameter | Type | Description |
|---|---|---|
blockStyleName | string | Name 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
| Parameter | Type | Description |
|---|---|---|
onchangeFn | (p1) => void | The 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
| Parameter | Type | Description |
|---|---|---|
name | string | The 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
| Parameter | Type | Description |
|---|---|---|
oldId | string | ID of variable to rename. |
newId | string | ID 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
| Parameter | Type | Description |
|---|---|---|
name | string | The 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
| Parameter | Type | Description |
|---|---|---|
newValue | any | The value to set. |
name | string | The 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
| Parameter | Type | Description |
|---|---|---|
newBoolean | boolean | True if there can be a previous statement. |
opt_check? | string | string[] | null | Statement 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
| Parameter | Type | Description |
|---|---|---|
newBoolean | boolean | True if there can be a next statement. |
opt_check? | string | string[] | null | Statement 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
| Parameter | Type | Description |
|---|---|---|
newBoolean | boolean | True if there is an output. |
opt_check? | string | string[] | null | Returned 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
| Parameter | Type | Description |
|---|---|---|
newBoolean | boolean | True 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
| Parameter | Type | Description |
|---|---|---|
outputShape | number | null | Value 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
| Parameter | Type | Description |
|---|---|---|
disabled | boolean | If true, then the block should be considered disabled for at least the provided reason, otherwise the block is no longer disabled for that reason. |
reason | string | A 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
| Parameter | Type | Description |
|---|---|---|
reason | string | A 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
| Parameter | Type | Description |
|---|---|---|
collapsed | boolean | True 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
| Parameter | Type | Description |
|---|---|---|
description | string | (() => 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
| Parameter | Type | Description |
|---|---|---|
opt_maxLength? | number | Truncate the string to this length. |
opt_emptyToken? | string | The 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
| Parameter | Type | Description |
|---|---|---|
name | string | Language-neutral identifier which may used to find this input again. Should be unique to this block. |
Returns
The input object created.
appendStatementInput()
appendStatementInput(name): Input;
Defined in: packages/blockly/core/block.ts:1694
Appends a statement input row.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Language-neutral identifier which may used to find this input again. Should be unique to this block. |
Returns
The input object created.
appendDummyInput()
appendDummyInput(name?): Input;
Defined in: packages/blockly/core/block.ts:1706
Appends a dummy input row.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | '' | Optional language-neutral identifier which may used to find this input again. Should be unique to this block. |
Returns
The input object created.
appendEndRowInput()
appendEndRowInput(name?): Input;
Defined in: packages/blockly/core/block.ts:1717
Appends an input that ends the row.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | '' | Optional language-neutral identifier which may used to find this input again. Should be unique to this block. |
Returns
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
| Parameter | Type |
|---|---|
input | Input |
Returns
jsonInit()
jsonInit(json): void;
Defined in: packages/blockly/core/block.ts:1756
Initialize this block using a cross-platform, internationalization-friendly JSON description.
Parameters
| Parameter | Type | Description |
|---|---|---|
json | any | Structured 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
| Parameter | Type | Description |
|---|---|---|
mixinObj | any | The key/values pairs to add to this block object. |
opt_disableCheck? | boolean | Option 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
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the input to move. |
refName | string | null | Name 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
| Parameter | Type | Description |
|---|---|---|
inputIndex | number | Index of the input to move. |
refIndex | number | Index 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
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the input. |
opt_quiet? | boolean | True 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
| Parameter | Type | Description |
|---|---|---|
name | string | The 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
| Parameter | Type | Description |
|---|---|---|
name | string | The 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
| Parameter | Type | Description |
|---|---|---|
text | string | null | The 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
| Parameter | Type | Description |
|---|---|---|
_text | string | null | The text, or null to delete. |
_opt_id? | string | An 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
| Parameter | Type | Description |
|---|---|---|
_mutator | MutatorIcon | A 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
| Parameter | Type |
|---|---|
icon | T |
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
| Parameter | Type | Description |
|---|---|---|
type | IconType<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
| Parameter | Type |
|---|---|
type | IconType<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
| Parameter | Type | Description |
|---|---|---|
type | string | 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
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
| Parameter | Type | Description |
|---|---|---|
dx | number | Horizontal offset, in workspace units. |
dy | number | Vertical 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
| Parameter | Type | Description |
|---|---|---|
opt_shadowBlocksAreFilled? | boolean | An 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.