Stay organized with collections Save and categorize content based on your preferences.

blockly > BlockSvg

BlockSvg class

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


export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBoundedElement, ICopyable, IDraggable 

Extends: Block

Implements: IASTNodeLocationSvg, IBoundedElement, ICopyable, IDraggable


Constructor Modifiers Description
(constructor)(workspace, prototypeName, opt_id) Constructs a new instance of the BlockSvg class


Property Modifiers Type Description



(not declared) ID to give the "collapsed warnings" warning. Allows us to remove the "collapsed warnings" warning without removing any warnings that belong to the block.
customContextMenu? ((p1: Array<ContextMenuOption | LegacyContextMenuOption>) => any) | null (Optional)
decompose? ((p1: Workspace) => BlockSvg) (Optional)
height number Height of this block, not including any statement blocks above or below. Height is in workspace units.



(not declared) Constant for identifying rows that are to be rendered inline. Don't collide with Blockly.inputTypes.
mutator Mutator | null Block's mutator icon (if any).
nextConnection RenderedConnection
outputConnection RenderedConnection
previousConnection RenderedConnection
rendered boolean
saveConnections? ((p1: BlockSvg) => any) (Optional)
style BlockStyle
warning Warning | null Block's warning icon (if any).
width number Width of this block, including any connected value blocks. Width is in workspace units.
workspace WorkspaceSvg


Method Modifiers Description
addSelect() Adds the visual "select" effect to the block, but does not actually select it or fire an event.
appendInput_(type, name) protected Add a value input, statement input or local variable to this block.

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.

checkAndDelete() 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.
dispose(healStack, animate) Dispose of this block.
generateContextMenu() protected Generate the context menu for this block.
getBoundingRectangle() Returns the coordinates of a bounding box describing the dimensions of this block and any blocks stacked below it. Coordinate system: workspace coordinates.
getChildren(ordered) 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.
getColour() Get the colour of a block.
getColourSecondary() Get the secondary colour of a block.
getColourTertiary() Get the tertiary colour of a block.
getCommentIcon() Get the comment icon attached to this block, or null if the block has no comment.
getIcons() Returns a list of mutator, comment, and warning icons.
getNextBlock() Return the next statement block directly connected to this block.
getPreviousBlock() Returns the block connected to the previous connection.
getRelativeToSurfaceXY() Return the coordinates of the top-left corner of this block relative to the drawing surface's origin (0,0), in workspace units. If the block is on the workspace, (0, 0) is the origin of the workspace coordinate system. This does not change with workspace scale.
getSvgRoot() Return the root node of the SVG or null if none exists.
initSvg() Create and initialize the SVG representation of the block. May be called more than once.
makeConnection_(type) protected Create a connection of the specified type.
markDirty() Notify every input on this block to mark its fields as dirty. A dirty field is a field that needs to be re-rendered.
moveBy(dx, dy) Move a block by a relative offset.
moveNumberedInputBefore(inputIndex, refIndex) Move a numbered input to a different location on this block.
moveTo(xy) Move a block to a position.
removeInput(name, opt_quiet) Remove an input from this block.
removeSelect() Removes the visual "select" effect from the block, but does not actually unselect it or fire an event.
render(opt_bubble) Lays out and reflows a block based on its contents and settings.
select() Selects this block. Highlights the block visually and fires a select event if the block is not already selected.
setCollapsed(collapsed) Set whether the block is collapsed or not.
setColour(colour) Change the colour of a block.
setCommentText(text) Set this block's comment text.
setEditable(editable) Set whether this block is editable or not.
setEnabled(enabled) Set whether the block is enabled or not.
setHighlighted(highlighted) Set whether the block is highlighted or not. Block highlighting is often used to visually mark blocks currently being executed.
setInputsInline(newBoolean) Set whether value inputs are arranged horizontally or vertically.
setMovable(movable) Set whether this block is movable or not.
setMutator(mutator) Give this block a mutator dialog.
setNextStatement(newBoolean, opt_check) Set whether another block can chain onto the bottom of this block.
setOutput(newBoolean, opt_check) Set whether this block returns a value.
setPreviousStatement(newBoolean, opt_check) Set whether this block can chain onto the bottom of another block.
setStyle(blockStyleName) Set the style and colour values of a block.
setWarningText(text, opt_id) Set this block's warning text.
snapToGrid() Snap this block to the nearest grid point.
tab(start, forward) Open the next (or previous) FieldTextInput.
translate(x, y) Transforms a block by setting the translation on the transform attribute of the block's SVG.
unselect() Unselects this block. Unhighlights the block and fires a select (false) event if the block is currently selected.
updateMarkers_() protected Redraw any attached marker or cursor svgs if needed.