Skip to main content

Class: Connection

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

Class for a connection between blocks.

Extended by

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-
sourceBlock_-
targetConnectionConnection this connection connects to. Null if not connected.
idThe unique ID of this connection.
typeThe type of the connection.

Methods index

MethodDescription
connect_Connect two connections together. This is the connection on the superior block.
getSourceBlockGet the source block for this connection.
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.
disconnectInternalDisconnect two blocks that are connected by this connection.
getParentAndChildConnectionsReturns the parent connection (superior) and child connection (inferior) given this connection and the connection it is connected to.
respawnShadow_Respawn the shadow block if there was one connected to the this connection.
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.
targetBlockReturns the block that this connection connects to.
onCheckChanged_Function to be called when this connection's compatible types have changed.
setCheckChange a connection's compatibility.
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.

Constructors

Constructor

new Connection(source, type): Connection;

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

Parameters

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

Returns

Connection

Properties

CAN_CONNECT

static CAN_CONNECT: number = 0;

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

Constants for checking whether two connections are compatible.


REASON_SELF_CONNECTION

static REASON_SELF_CONNECTION: number = 1;

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


REASON_WRONG_TYPE

static REASON_WRONG_TYPE: number = 2;

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


REASON_TARGET_NULL

static REASON_TARGET_NULL: number = 3;

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


REASON_CHECKS_FAILED

static REASON_CHECKS_FAILED: number = 4;

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


REASON_DIFFERENT_WORKSPACES

static REASON_DIFFERENT_WORKSPACES: number = 5;

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


REASON_SHADOW_PARENT

static REASON_SHADOW_PARENT: number = 6;

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


REASON_DRAG_CHECKS_FAILED

static REASON_DRAG_CHECKS_FAILED: number = 7;

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


REASON_PREVIOUS_AND_OUTPUT

static REASON_PREVIOUS_AND_OUTPUT: number = 8;

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


sourceBlock_

protected sourceBlock_: Block;

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


targetConnection

targetConnection: Connection | null = null;

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

Connection this connection connects to. Null if not connected.


id

id: string;

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

The unique ID of this connection.


type

type: number;

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

The type of the connection.

Methods

connect_()

protected connect_(childConnection): void;

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

Connect two connections together. This is the connection on the superior block.

Parameters

ParameterTypeDescription
childConnectionConnectionConnection on inferior block.

Returns

void


getSourceBlock()

getSourceBlock(): Block;

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

Get the source block for this connection.

Returns

Block

The source block.


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.


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.


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.


disconnect()

disconnect(): void;

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

Disconnect this connection.

Returns

void


disconnectInternal()

protected disconnectInternal(setParent?): void;

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

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


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;

respawnShadow_()

protected respawnShadow_(): void;

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

Respawn the shadow block if there was one connected to the this connection.

Returns

void


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.


targetBlock()

targetBlock(): Block | null;

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

Returns the block that this connection connects to.

Returns

Block | null

The connected block or null if none is connected.


onCheckChanged_()

protected onCheckChanged_(): void;

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

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

Returns

void


setCheck()

setCheck(check): Connection;

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

Change a connection's compatibility.

Parameters

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

Returns

Connection

The connection being modified (to allow chaining).


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.


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


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.


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


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.


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.


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.