blockly > BlockSvg

BlockSvg class

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

Signature:

export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBoundedElement, ICopyable<BlockCopyData>, IDraggable, IDeletable 

Extends: Block

Implements: IASTNodeLocationSvg, IBoundedElement, ICopyable<BlockCopyData>, IDraggable, IDeletable

Constructors

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

Properties

Property Modifiers Type Description
COLLAPSED_WARNING_ID

static

readonly

(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>) => void (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.
INLINE

static

readonly

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

Methods

Method Modifiers Description
addIcon(icon)
addSelect() Adds the visual "select" effect to the block, but does not actually select it or fire an event.
appendInput(input)
bumpNeighbours()

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.
disposeInternal() Disposes of this block without doing things required by the top block. E.g. does trigger UI effects, remove nodes, etc.
drag(newLoc, e) Drags the block to the given location.
endDrag(e) Ends the drag on the 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.
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.
isMovable() Returns whether this block is movable or not.
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, reason) Move a block by a relative offset.
moveNumberedInputBefore(inputIndex, refIndex) Move a numbered input to a different location on this block.
moveTo(xy, reason) Move a block to a position.
removeIcon(type)
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() Immediately lays out and reflows a block based on its contents and settings.
revertDrag() Moves the block back to where it was at the start of a drag.
scheduleSnapAndBump() Snap to grid, and then bump neighbouring blocks away at the end of the next render.
select() Selects this block. Highlights the block visually.
setCollapsed(collapsed) Set whether the block is collapsed or not.
setColour(colour) Change the colour of a block.
setDisabledReason(disabled, reason) 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.
setDragStrategy(dragStrategy) Sets the drag strategy for this block.
setEditable(editable) Set whether this block is editable or not.
setEnabled(enabled)
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, id) Set this block's warning text.
snapToGrid() Snap this block to the nearest grid point.
startDrag(e) Starts a drag on the block.
tab(start, forward) Open the next (or previous) FieldTextInput.
toCopyData() Encode a block for copying.
toFlyoutInfo() Returns a representation of this block that can be displayed in a flyout.
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 blockv visually.
updateMarkers_() protected Redraw any attached marker or cursor svgs if needed.