Skip to main content

Class: RenderedConnection

Defined in: packages/blockly/core/rendered_connection.ts:42

Class for a connection between blocks that may be rendered on screen.

Extends

Implements

Properties index

PropertyDescription
CAN_CONNECTConstants for checking whether two connections are compatible.
REASON_SELF_CONNECTION-
REASON_WRONG_TYPE-
REASON_TARGET_NULL-
REASON_CHECKS_FAILED-
REASON_DIFFERENT_WORKSPACES-
REASON_SHADOW_PARENT-
REASON_DRAG_CHECKS_FAILED-
REASON_PREVIOUS_AND_OUTPUT-
idThe unique ID of this connection.
typeThe type of the connection.
sourceBlock_-
targetConnectionConnection this connection connects to. Null if not connected.

Methods index

MethodDescription
isSuperiorDoes the connection belong to a superior block (higher in the source stack)?
isConnectedIs the connection connected?
connectConnect this connection to another connection.
disconnectDisconnect this connection.
getParentAndChildConnectionsReturns the parent connection (superior) and child connection (inferior) given this connection and the connection it is connected to.
reconnectReconnects this connection to the input with the given name on the given block. If there is already a connection connected to that input, that connection is disconnected.
getCheckGet a connection's compatibility.
setShadowDomChanges the connection's shadow block.
getShadowDomReturns the xml representation of the connection's shadow block.
setShadowStateChanges the connection's shadow block.
getShadowStateReturns the serialized object representation of the connection's shadow block.
toStringThis method returns a string describing this Connection in developer terms (English only). Intended to on be used in console logs and errors.
getConnectionForOrphanedConnectionReturns the connection (starting at the startBlock) which will accept the given connection. This includes compatible connection types and connection checks.
getSourceBlockGet the source block for this connection.
targetBlockReturns the block that this connection connects to.
distanceFromReturns the distance between this connection and another connection in workspace units.
moveToChange the connection's coordinates.
moveByChange the connection's coordinates.
moveToOffsetMove this connection to the location given by its offset within the block and the location of the block's top left corner.
setOffsetInBlockSet the offset of this connection relative to the top left of its block.
getOffsetInBlockGet the offset of this connection relative to the top left of its block.
closestFind the closest compatible connection to this connection. All parameters are in workspace units.
setAriaRoleSets the aria role and role description for this connection.
highlightAdd highlighting around this connection.
unhighlightRemove the highlighting around this connection.
isHighlightedReturns true if this connection is highlighted, false otherwise.
startTrackingAllStart tracking this connection, as well as all down-stream connections on any block attached to this connection. This happens when a block is expanded.
disconnectInternalDisconnect two blocks that are connected by this connection.
respawnShadow_Respawn the shadow block if there was one connected to the this connection. Render/rerender blocks as needed.
connect_Connect two connections together. This is the connection on the superior block. Rerender blocks as needed.
onCheckChanged_Function to be called when this connection's compatible types have changed.
setCheckChange a connection's compatibility. Rerender blocks as needed.
showContextMenuHandles showing the context menu when it is opened on a connection. Note that typically the context menu can't be opened with the mouse on a connection, because you can't select a connection. But keyboard users may open the context menu with a keyboard shortcut.
getFocusableElementSee IFocusableNode.getFocusableElement.
getFocusableTreeSee IFocusableNode.getFocusableTree.
onNodeFocusSee IFocusableNode.onNodeFocus.
onNodeBlurSee IFocusableNode.onNodeBlur.
canBeFocusedSee IFocusableNode.canBeFocused.

Constructors

Constructor

new RenderedConnection(source, type): RenderedConnection;

Defined in: packages/blockly/core/rendered_connection.ts:62

Parameters

ParameterTypeDescription
sourceBlockSvgThe block establishing this connection.
typenumberThe type of the connection.

Returns

RenderedConnection

Overrides

Connection.constructor

Properties

CAN_CONNECT

static CAN_CONNECT: number = 0;

Defined in: packages/blockly/core/connection.ts:30

Constants for checking whether two connections are compatible.

Inherited from

Connection.CAN_CONNECT


REASON_SELF_CONNECTION

static REASON_SELF_CONNECTION: number = 1;

Defined in: packages/blockly/core/connection.ts:31

Inherited from

Connection.REASON_SELF_CONNECTION


REASON_WRONG_TYPE

static REASON_WRONG_TYPE: number = 2;

Defined in: packages/blockly/core/connection.ts:32

Inherited from

Connection.REASON_WRONG_TYPE


REASON_TARGET_NULL

static REASON_TARGET_NULL: number = 3;

Defined in: packages/blockly/core/connection.ts:33

Inherited from

Connection.REASON_TARGET_NULL


REASON_CHECKS_FAILED

static REASON_CHECKS_FAILED: number = 4;

Defined in: packages/blockly/core/connection.ts:34

Inherited from

Connection.REASON_CHECKS_FAILED


REASON_DIFFERENT_WORKSPACES

static REASON_DIFFERENT_WORKSPACES: number = 5;

Defined in: packages/blockly/core/connection.ts:35

Inherited from

Connection.REASON_DIFFERENT_WORKSPACES


REASON_SHADOW_PARENT

static REASON_SHADOW_PARENT: number = 6;

Defined in: packages/blockly/core/connection.ts:36

Inherited from

Connection.REASON_SHADOW_PARENT


REASON_DRAG_CHECKS_FAILED

static REASON_DRAG_CHECKS_FAILED: number = 7;

Defined in: packages/blockly/core/connection.ts:37

Inherited from

Connection.REASON_DRAG_CHECKS_FAILED


REASON_PREVIOUS_AND_OUTPUT

static REASON_PREVIOUS_AND_OUTPUT: number = 8;

Defined in: packages/blockly/core/connection.ts:38

Inherited from

Connection.REASON_PREVIOUS_AND_OUTPUT


id

id: string;

Defined in: packages/blockly/core/connection.ts:59

The unique ID of this connection.

Inherited from

Connection.id


type

type: number;

Defined in: packages/blockly/core/connection.ts:83

The type of the connection.

Inherited from

Connection.type


sourceBlock_

sourceBlock_: BlockSvg;

Defined in: packages/blockly/core/rendered_connection.ts:47

Overrides

Connection.sourceBlock_


targetConnection

targetConnection: RenderedConnection | null = null;

Defined in: packages/blockly/core/rendered_connection.ts:56

Connection this connection connects to. Null if not connected.

Overrides

Connection.targetConnection

Methods

isSuperior()

isSuperior(): boolean;

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

Does the connection belong to a superior block (higher in the source stack)?

Returns

boolean

True if connection faces down or right.

Inherited from

Connection.isSuperior


isConnected()

isConnected(): boolean;

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

Is the connection connected?

Returns

boolean

True if connection is connected to another connection.

Inherited from

Connection.isConnected


connect()

connect(otherConnection): boolean;

Defined in: packages/blockly/core/connection.ts:240

Connect this connection to another connection.

Parameters

ParameterTypeDescription
otherConnectionConnectionConnection to connect to.

Returns

boolean

Whether the blocks are now connected or not.

Inherited from

Connection.connect


disconnect()

disconnect(): void;

Defined in: packages/blockly/core/connection.ts:269

Disconnect this connection.

Returns

void

Inherited from

Connection.disconnect


getParentAndChildConnections()

protected getParentAndChildConnections(): object;

Defined in: packages/blockly/core/connection.ts:326

Returns the parent connection (superior) and child connection (inferior) given this connection and the connection it is connected to.

Returns

object

The parent connection and child connection, given this connection and the connection it is connected to.

parentConnection?
optional parentConnection?: Connection;
childConnection?
optional childConnection?: Connection;

Inherited from

Connection.getParentAndChildConnections


reconnect()

reconnect(block, inputName): boolean;

Defined in: packages/blockly/core/connection.ts:360

Reconnects this connection to the input with the given name on the given block. If there is already a connection connected to that input, that connection is disconnected.

Parameters

ParameterTypeDescription
blockBlockThe block to connect this connection to.
inputNamestringThe name of the input to connect this connection to.

Returns

boolean

True if this connection was able to connect, false otherwise.

Inherited from

Connection.reconnect


getCheck()

getCheck(): string[] | null;

Defined in: packages/blockly/core/connection.ts:438

Get a connection's compatibility.

Returns

string[] | null

List of compatible value types. Null if all types are compatible.

Inherited from

Connection.getCheck


setShadowDom()

setShadowDom(shadowDom): void;

Defined in: packages/blockly/core/connection.ts:447

Changes the connection's shadow block.

Parameters

ParameterTypeDescription
shadowDomElement | nullDOM representation of a block or null.

Returns

void

Inherited from

Connection.setShadowDom


getShadowDom()

getShadowDom(returnCurrent?): Element | null;

Defined in: packages/blockly/core/connection.ts:460

Returns the xml representation of the connection's shadow block.

Parameters

ParameterTypeDescription
returnCurrent?booleanIf true, and the shadow block is currently attached to this connection, this serializes the state of that block and returns it (so that field values are correct). Otherwise the saved shadowDom is just returned.

Returns

Element | null

Shadow DOM representation of a block or null.

Inherited from

Connection.getShadowDom


setShadowState()

setShadowState(shadowState): void;

Defined in: packages/blockly/core/connection.ts:471

Changes the connection's shadow block.

Parameters

ParameterTypeDescription
shadowState| State | nullAn state represetation of the block or null.

Returns

void

Inherited from

Connection.setShadowState


getShadowState()

getShadowState(returnCurrent?):
| State
| null;

Defined in: packages/blockly/core/connection.ts:485

Returns the serialized object representation of the connection's shadow block.

Parameters

ParameterTypeDescription
returnCurrent?booleanIf true, and the shadow block is currently attached to this connection, this serializes the state of that block and returns it (so that field values are correct). Otherwise the saved state is just returned.

Returns

| State | null

Serialized object representation of the block, or null.

Inherited from

Connection.getShadowState


toString()

toString(): string;

Defined in: packages/blockly/core/connection.ts:534

This method returns a string describing this Connection in developer terms (English only). Intended to on be used in console logs and errors.

Returns

string

The description.

Inherited from

Connection.toString


getConnectionForOrphanedConnection()

static getConnectionForOrphanedConnection(startBlock, orphanConnection): Connection | null;

Defined in: packages/blockly/core/connection.ts:717

Returns the connection (starting at the startBlock) which will accept the given connection. This includes compatible connection types and connection checks.

Parameters

ParameterTypeDescription
startBlockBlockThe block on which to start the search.
orphanConnectionConnectionThe connection that is looking for a home.

Returns

Connection | null

The suitable connection point on the chain of blocks, or null.

Inherited from

Connection.getConnectionForOrphanedConnection


getSourceBlock()

getSourceBlock(): BlockSvg;

Defined in: packages/blockly/core/rendered_connection.ts:104

Get the source block for this connection.

Returns

BlockSvg

The source block.

Overrides

Connection.getSourceBlock


targetBlock()

targetBlock(): BlockSvg | null;

Defined in: packages/blockly/core/rendered_connection.ts:113

Returns the block that this connection connects to.

Returns

BlockSvg | null

The connected block or null if none is connected.

Overrides

Connection.targetBlock


distanceFrom()

distanceFrom(otherConnection): number;

Defined in: packages/blockly/core/rendered_connection.ts:124

Returns the distance between this connection and another connection in workspace units.

Parameters

ParameterTypeDescription
otherConnectionConnectionThe other connection to measure the distance to.

Returns

number

The distance between connections, in workspace units.


moveTo()

moveTo(x, y): boolean;

Defined in: packages/blockly/core/rendered_connection.ts:220

Change the connection's coordinates.

Parameters

ParameterTypeDescription
xnumberNew absolute x coordinate, in workspace coordinates.
ynumberNew absolute y coordinate, in workspace coordinates.

Returns

boolean

True if the position of the connection in the connection db was updated.


moveBy()

moveBy(dx, dy): boolean;

Defined in: packages/blockly/core/rendered_connection.ts:250

Change the connection's coordinates.

Parameters

ParameterTypeDescription
dxnumberChange to x coordinate, in workspace units.
dynumberChange to y coordinate, in workspace units.

Returns

boolean

True if the position of the connection in the connection db was updated.


moveToOffset()

moveToOffset(blockTL): boolean;

Defined in: packages/blockly/core/rendered_connection.ts:263

Move this connection to the location given by its offset within the block and the location of the block's top left corner.

Parameters

ParameterTypeDescription
blockTLCoordinateThe location of the top left corner of the block, in workspace coordinates.

Returns

boolean

True if the position of the connection in the connection db was updated.


setOffsetInBlock()

setOffsetInBlock(x, y): void;

Defined in: packages/blockly/core/rendered_connection.ts:276

Set the offset of this connection relative to the top left of its block.

Parameters

ParameterTypeDescription
xnumberThe new relative x, in workspace units.
ynumberThe new relative y, in workspace units.

Returns

void


getOffsetInBlock()

getOffsetInBlock(): Coordinate;

Defined in: packages/blockly/core/rendered_connection.ts:286

Get the offset of this connection relative to the top left of its block.

Returns

Coordinate

The offset of the connection.


closest()

closest(maxLimit, dxy): object;

Defined in: packages/blockly/core/rendered_connection.ts:326

Find the closest compatible connection to this connection. All parameters are in workspace units.

Parameters

ParameterTypeDescription
maxLimitnumberThe maximum radius to another connection.
dxyCoordinateOffset between this connection's location in the database and the current location (as a result of dragging).

Returns

object

Contains two properties: 'connection' which is either another connection or null, and 'radius' which is the distance.

connection
connection: RenderedConnection | null;
radius
radius: number;

setAriaRole()

setAriaRole(highlightSvg): void;

Defined in: packages/blockly/core/rendered_connection.ts:338

Sets the aria role and role description for this connection.

Parameters

ParameterTypeDescription
highlightSvgSVGElementThe focusable element for this connection.

Returns

void


highlight()

highlight(): void;

Defined in: packages/blockly/core/rendered_connection.ts:395

Add highlighting around this connection.

Returns

void


unhighlight()

unhighlight(): void;

Defined in: packages/blockly/core/rendered_connection.ts:419

Remove the highlighting around this connection.

Returns

void


isHighlighted()

isHighlighted(): boolean;

Defined in: packages/blockly/core/rendered_connection.ts:430

Returns true if this connection is highlighted, false otherwise.

Returns

boolean


startTrackingAll()

startTrackingAll(): BlockSvg[];

Defined in: packages/blockly/core/rendered_connection.ts:499

Start tracking this connection, as well as all down-stream connections on any block attached to this connection. This happens when a block is expanded.

Returns

BlockSvg[]

List of blocks to render.


disconnectInternal()

disconnectInternal(setParent?): void;

Defined in: packages/blockly/core/rendered_connection.ts:572

Disconnect two blocks that are connected by this connection.

Parameters

ParameterTypeDefault valueDescription
setParentbooleantrueWhether to set the parent of the disconnected block or not, defaults to true. If you do not set the parent, ensure that a subsequent action does, otherwise the view and model will be out of sync.

Returns

void

Overrides

Connection.disconnectInternal


respawnShadow_()

protected respawnShadow_(): void;

Defined in: packages/blockly/core/rendered_connection.ts:596

Respawn the shadow block if there was one connected to the this connection. Render/rerender blocks as needed.

Returns

void

Overrides

Connection.respawnShadow_


connect_()

protected connect_(childConnection): void;

Defined in: packages/blockly/core/rendered_connection.ts:625

Connect two connections together. This is the connection on the superior block. Rerender blocks as needed.

Parameters

ParameterTypeDescription
childConnectionConnectionConnection on inferior block.

Returns

void

Overrides

Connection.connect_


onCheckChanged_()

protected onCheckChanged_(): void;

Defined in: packages/blockly/core/rendered_connection.ts:648

Function to be called when this connection's compatible types have changed.

Returns

void

Overrides

Connection.onCheckChanged_


setCheck()

setCheck(check): RenderedConnection;

Defined in: packages/blockly/core/rendered_connection.ts:672

Change a connection's compatibility. Rerender blocks as needed.

Parameters

ParameterTypeDescription
checkstring | string[] | nullCompatible value type or list of value types. Null if all types are compatible.

Returns

RenderedConnection

The connection being modified (to allow chaining).

Overrides

Connection.setCheck


showContextMenu()

showContextMenu(e): void;

Defined in: packages/blockly/core/rendered_connection.ts:686

Handles showing the context menu when it is opened on a connection. Note that typically the context menu can't be opened with the mouse on a connection, because you can't select a connection. But keyboard users may open the context menu with a keyboard shortcut.

Parameters

ParameterTypeDescription
eEventEvent that triggered the opening of the context menu.

Returns

void

Implementation of

IContextMenu.showContextMenu


getFocusableElement()

getFocusableElement(): HTMLElement | SVGElement;

Defined in: packages/blockly/core/rendered_connection.ts:713

See IFocusableNode.getFocusableElement.

Returns

HTMLElement | SVGElement

Implementation of

IFocusableNode.getFocusableElement


getFocusableTree()

getFocusableTree(): IFocusableTree;

Defined in: packages/blockly/core/rendered_connection.ts:720

See IFocusableNode.getFocusableTree.

Returns

IFocusableTree

Implementation of

IFocusableNode.getFocusableTree


onNodeFocus()

onNodeFocus(): void;

Defined in: packages/blockly/core/rendered_connection.ts:725

See IFocusableNode.onNodeFocus.

Returns

void

Implementation of

IFocusableNode.onNodeFocus


onNodeBlur()

onNodeBlur(): void;

Defined in: packages/blockly/core/rendered_connection.ts:737

See IFocusableNode.onNodeBlur.

Returns

void

Implementation of

IFocusableNode.onNodeBlur


canBeFocused()

canBeFocused(): boolean;

Defined in: packages/blockly/core/rendered_connection.ts:742

See IFocusableNode.canBeFocused.

Returns

boolean

Implementation of

IFocusableNode.canBeFocused