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 IBoundedElement, IContextMenu, ICopyable<BlockCopyData>, IDraggable, IDeletable, IFocusableNode
Extends: Block
Implements: IBoundedElement, IContextMenu, ICopyable<BlockCopyData>, IDraggable, IDeletable, IFocusableNode
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 |
|
(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 |
|
(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? | (rootBlock: BlockSvg) => void | (Optional) An optional method which saves a record of blocks connected to this block so they can be later restored after this block is recoomposed (reconfigured). Typically records the connected blocks on properties on blocks in the mutator flyout, so that rearranging those component blocks will automatically rearrange the corresponding connected blocks on this block after this block is recomposed. To keep the saved connection information up-to-date, MutatorIcon arranges for an event listener to call this method any time the mutator flyout is open and a change occurs on this block's workspace. |
|
style | BlockStyle | ||
width | number | Width of this block, including any connected value blocks. Width is in workspace units. | |
workspace | WorkspaceSvg |
Methods
Method | Modifiers | Description |
---|---|---|
addClass(className) | Add a CSS class to the SVG group of this block. | |
addIcon(icon) | ||
addSelect() | Adds the visual "select" effect to the block, but does not actually select it or fire an event. | |
appendInput(input) | ||
bringToFront(blockOnly) | Move this block to the front of the visible workspace. |
|
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. |
|
calculateContextMenuLocation(e) | protected |
Gets the location in which to show the context menu for this block. Use the location of a click if the block was clicked, or a location based on the block's fields otherwise. |
canBeFocused() | See IFocusableNode.canBeFocused. | |
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(e) | 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. | |
getBoundingRectangleWithoutChildren() | Returns the coordinates of a bounding box describing the dimensions of this block alone. 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. | |
getFocusableElement() | See IFocusableNode.getFocusableElement. | |
getFocusableTree() | See IFocusableNode.getFocusableTree. | |
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. | |
getStyle() | Returns the BlockStyle object used to style this block. | |
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. | |
jsonInit(json) | ||
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. | |
onNodeBlur() | See IFocusableNode.onNodeBlur. | |
onNodeFocus() | See IFocusableNode.onNodeFocus. | |
removeClass(className) | Remove a CSS class from the SVG group of this block. | |
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. | |
setDeletable(deletable) | Add blocklyNotDeletable class when block is not deletable Or remove class when block is deletable | |
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. | |
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. | |
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 block visually. |