Class: Connection
Defined in: packages/blockly/core/connection.ts:28
Class for a connection between blocks.
Extended by
Properties index
| Property | Description |
|---|---|
| CAN_CONNECT | Constants 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_ | - |
| targetConnection | Connection this connection connects to. Null if not connected. |
| id | The unique ID of this connection. |
| type | The type of the connection. |
Methods index
| Method | Description |
|---|---|
| connect_ | Connect two connections together. This is the connection on the superior block. |
| getSourceBlock | Get the source block for this connection. |
| isSuperior | Does the connection belong to a superior block (higher in the source stack)? |
| isConnected | Is the connection connected? |
| connect | Connect this connection to another connection. |
| disconnect | Disconnect this connection. |
| disconnectInternal | Disconnect two blocks that are connected by this connection. |
| getParentAndChildConnections | Returns 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. |
| reconnect | 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. |
| targetBlock | Returns the block that this connection connects to. |
| onCheckChanged_ | Function to be called when this connection's compatible types have changed. |
| setCheck | Change a connection's compatibility. |
| getCheck | Get a connection's compatibility. |
| setShadowDom | Changes the connection's shadow block. |
| getShadowDom | Returns the xml representation of the connection's shadow block. |
| setShadowState | Changes the connection's shadow block. |
| getShadowState | Returns the serialized object representation of the connection's shadow block. |
| toString | This method returns a string describing this Connection in developer terms (English only). Intended to on be used in console logs and errors. |
| getConnectionForOrphanedConnection | Returns 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
| Parameter | Type | Description |
|---|---|---|
source | Block | The block establishing this connection. |
type | number | The 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
| Parameter | Type | Description |
|---|---|---|
childConnection | Connection | Connection on inferior block. |
Returns
void
getSourceBlock()
getSourceBlock(): Block;
Defined in: packages/blockly/core/connection.ts:187
Get the source block for this connection.
Returns
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
| Parameter | Type | Description |
|---|---|---|
otherConnection | Connection | Connection 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
| Parameter | Type | Default value | Description |
|---|---|---|---|
setParent | boolean | true | Whether 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
| Parameter | Type | Description |
|---|---|---|
block | Block | The block to connect this connection to. |
inputName | string | The 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
| Parameter | Type | Description |
|---|---|---|
check | string | string[] | null | Compatible 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
| Parameter | Type | Description |
|---|---|---|
shadowDom | Element | null | DOM 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
| Parameter | Type | Description |
|---|---|---|
returnCurrent? | boolean | If 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
| Parameter | Type | Description |
|---|---|---|
shadowState | | State | null | An 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
| Parameter | Type | Description |
|---|---|---|
returnCurrent? | boolean | If 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
| Parameter | Type | Description |
|---|---|---|
startBlock | Block | The block on which to start the search. |
orphanConnection | Connection | The connection that is looking for a home. |
Returns
Connection | null
The suitable connection point on the chain of blocks, or null.