Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blockly/block-dynamic-connection

Package Overview
Dependencies
Maintainers
2
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blockly/block-dynamic-connection - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

18

package.json
{
"name": "@blockly/block-dynamic-connection",
"version": "0.5.0",
"version": "0.5.1",
"description": "A group of blocks that add connections dynamically.",

@@ -9,3 +9,3 @@ "scripts": {

"clean": "blockly-scripts clean",
"lint": "blockly-scripts lint",
"lint": "eslint .",
"prepublishOnly": "npm run clean && npm run build",

@@ -17,3 +17,3 @@ "predeploy": "npm run build && blockly-scripts predeploy",

"main": "./dist/index.js",
"module": "./src/index.js",
"types": "./dist/index.d.ts",
"unpkg": "./dist/index.js",

@@ -45,7 +45,8 @@ "author": "",

"devDependencies": {
"@blockly/dev-scripts": "^2.0.1",
"@blockly/dev-tools": "^7.1.0",
"@blockly/dev-scripts": "^2.0.2",
"@blockly/dev-tools": "^7.1.1",
"blockly": "^10.2.0",
"chai": "^4.2.0",
"mocha": "^10.2.0"
"mocha": "^10.2.0",
"typescript": "^5.2.2"
},

@@ -59,9 +60,6 @@ "peerDependencies": {

},
"eslintConfig": {
"extends": "@blockly/eslint-config"
},
"engines": {
"node": ">=8.17.0"
},
"gitHead": "90bef04779f022f2650508a2e565274fdc1fb99c"
"gitHead": "defd5f8e3621403beb8e2ade3279b26268ae013c"
}

@@ -7,2 +7,3 @@ # @blockly/block-dynamic-connection [![Built on Blockly](https://tinyurl.com/built-on-blockly)](https://github.com/google/blockly)

## Installation
```

@@ -20,2 +21,3 @@ npm install @blockly/block-dynamic-connection --save

## API
- `overrideOldBlockDefinitions`: Replaces the Blockly default blocks with the

@@ -25,10 +27,10 @@ dynamic connection blocks. This enables projects to use the dynamic block

## Blocks
* `dynamic_text_join` replaces `text_join`
* `dynamic_list_create` replaces `lists_create_with`
* `dynamic_if` replaces `controls_if`
- `dynamic_text_join` replaces `text_join`
- `dynamic_list_create` replaces `lists_create_with`
- `dynamic_if` replaces `controls_if`
## License
Apache 2.0

@@ -69,3 +69,3 @@ /**

*/
mutationToDom(this: DynamicIfBlock): Element|null {
mutationToDom(this: DynamicIfBlock): Element | null {
// If we call finalizeConnections here without disabling events, we get into

@@ -118,13 +118,15 @@ // an event loop.

this.appendValueInput('IF' + first)
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_IF'], 'if');
this.appendStatementInput('DO' + first)
.appendField(Blockly.Msg['CONTROLS_IF_MSG_THEN']);
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_IF'], 'if');
this.appendStatementInput('DO' + first).appendField(
Blockly.Msg['CONTROLS_IF_MSG_THEN'],
);
for (let i = 1; i < inputNumbers.length; i++) {
this.appendValueInput('IF' + inputNumbers[i])
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF'], 'elseif');
this.appendStatementInput('DO' + inputNumbers[i])
.appendField(Blockly.Msg['CONTROLS_IF_MSG_THEN']);
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF'], 'elseif');
this.appendStatementInput('DO' + inputNumbers[i]).appendField(
Blockly.Msg['CONTROLS_IF_MSG_THEN'],
);
}

@@ -143,4 +145,4 @@ }

deserializeCounts(this: DynamicIfBlock, xmlElement: Element): void {
this.elseifCount = parseInt(
xmlElement.getAttribute('elseif') ?? '0', 10) || 0;
this.elseifCount =
parseInt(xmlElement.getAttribute('elseif') ?? '0', 10) || 0;
this.elseCount = parseInt(xmlElement.getAttribute('else') ?? '0', 10) || 0;

@@ -159,3 +161,3 @@ for (let i = 1; i <= this.elseifCount; i++) {

*/
saveExtraState: function(this: DynamicIfBlock): IfExtraState | null {
saveExtraState: function (this: DynamicIfBlock): IfExtraState | null {
// If we call finalizeConnections here without disabling events, we get into

@@ -186,3 +188,6 @@ // an event loop.

*/
loadExtraState: function(this: DynamicIfBlock, state: IfExtraState | string) {
loadExtraState: function (
this: DynamicIfBlock,
state: IfExtraState | string,
) {
if (typeof state === 'string') {

@@ -210,3 +215,5 @@ this.domToMutation(Blockly.utils.xml.textToDom(state));

findInputIndexForConnection(
this: DynamicIfBlock, connection: Blockly.Connection): number | null {
this: DynamicIfBlock,
connection: Blockly.Connection,
): number | null {
for (let i = 0; i < this.inputList.length; i++) {

@@ -229,9 +236,12 @@ const input = this.inputList[i];

insertElseIf(
this: DynamicIfBlock, index: number, id: string | number
this: DynamicIfBlock,
index: number,
id: string | number,
): CaseInputPair {
const ifInput = this.appendValueInput('IF' + id)
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF'], 'elseif');
const doInput = this.appendStatementInput('DO' + id)
.appendField(Blockly.Msg['CONTROLS_IF_MSG_THEN']);
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF'], 'elseif');
const doInput = this.appendStatementInput('DO' + id).appendField(
Blockly.Msg['CONTROLS_IF_MSG_THEN'],
);
this.moveInputBefore('IF' + id, this.inputList[index].name);

@@ -249,3 +259,5 @@ this.moveInputBefore('DO' + id, this.inputList[index + 1].name);

onPendingConnection(
this: DynamicIfBlock, connection: Blockly.Connection): void {
this: DynamicIfBlock,
connection: Blockly.Connection,
): void {
if (connection.type === Blockly.NEXT_STATEMENT && !this.getInput('ELSE')) {

@@ -265,5 +277,5 @@ this.addElseInput();

const nextIfConnection =
nextIfInput &&
nextIfInput.connection &&
nextIfInput.connection.targetConnection;
nextIfInput &&
nextIfInput.connection &&
nextIfInput.connection.targetConnection;
if (

@@ -309,6 +321,4 @@ nextIfConnection &&

for (let i = 0; i < this.inputList.length - 1; i += 2) {
const ifTarget =
this.inputList[i].connection?.targetConnection;
const doTarget =
this.inputList[i + 1].connection?.targetConnection;
const ifTarget = this.inputList[i].connection?.targetConnection;
const doTarget = this.inputList[i + 1].connection?.targetConnection;
if (!ifTarget && !doTarget) continue;

@@ -354,4 +364,5 @@ targetConns.push({ifTarget, doTarget});

addElseInput(this: DynamicIfBlock): Blockly.Input {
return this.appendStatementInput('ELSE')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSE']);
return this.appendStatementInput('ELSE').appendField(
Blockly.Msg['CONTROLS_IF_MSG_ELSE'],
);
},

@@ -365,6 +376,7 @@

this.appendValueInput('IF0')
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_IF'], 'if');
this.appendStatementInput('DO0')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_THEN']);
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_IF'], 'if');
this.appendStatementInput('DO0').appendField(
Blockly.Msg['CONTROLS_IF_MSG_THEN'],
);
},

@@ -371,0 +383,0 @@ };

@@ -84,4 +84,5 @@ /**

inputNames.forEach((name) => this.appendValueInput(name));
this.inputList[0]
.appendField(Blockly.Msg['LISTS_CREATE_WITH_INPUT_WITH']);
this.inputList[0].appendField(
Blockly.Msg['LISTS_CREATE_WITH_INPUT_WITH'],
);
}

@@ -96,3 +97,5 @@ },

this.itemCount = Math.max(
parseInt(xmlElement.getAttribute('items') ?? '0', 10), this.minInputs);
parseInt(xmlElement.getAttribute('items') ?? '0', 10),
this.minInputs,
);
// minInputs are added automatically.

@@ -108,3 +111,3 @@ for (let i = this.minInputs; i < this.itemCount; i++) {

*/
saveExtraState: function(this: DynamicListCreateBlock): {itemCount: number} {
saveExtraState: function (this: DynamicListCreateBlock): {itemCount: number} {
// If we call finalizeConnections here without disabling events, we get into

@@ -126,4 +129,6 @@ // an event loop.

*/
loadExtraState: function(
this: DynamicListCreateBlock, state: ({[x: string]: any} | string)) {
loadExtraState: function (
this: DynamicListCreateBlock,
state: {[x: string]: any} | string,
) {
if (typeof state === 'string') {

@@ -148,4 +153,5 @@ this.domToMutation(Blockly.utils.xml.textToDom(state));

findInputIndexForConnection(
this: DynamicListCreateBlock,
connection: Blockly.Connection): number | null {
this: DynamicListCreateBlock,
connection: Blockly.Connection,
): number | null {
if (!connection.targetConnection) {

@@ -171,4 +177,6 @@ // this connection is available

const nextConnection = nextInput?.connection?.targetConnection;
if (nextConnection &&
!nextConnection.getSourceBlock().isInsertionMarker()) {
if (
nextConnection &&
!nextConnection.getSourceBlock().isInsertionMarker()
) {
return connectionIndex + 1;

@@ -188,3 +196,5 @@ }

onPendingConnection(
this: DynamicListCreateBlock, connection: Blockly.Connection): void {
this: DynamicListCreateBlock,
connection: Blockly.Connection,
): void {
const insertIndex = this.findInputIndexForConnection(connection);

@@ -203,5 +213,5 @@ if (insertIndex == null) {

finalizeConnections(this: DynamicListCreateBlock): void {
const targetConns =
this.removeUnnecessaryEmptyConns(
this.inputList.map((i) => i.connection?.targetConnection));
const targetConns = this.removeUnnecessaryEmptyConns(
this.inputList.map((i) => i.connection?.targetConnection),
);
this.tearDownBlock();

@@ -228,3 +238,3 @@ this.addItemInputs(targetConns);

removeUnnecessaryEmptyConns(
targetConns: Array<Blockly.Connection | undefined | null>
targetConns: Array<Blockly.Connection | undefined | null>,
): Array<Blockly.Connection | undefined | null> {

@@ -248,4 +258,4 @@ const filteredConns = [...targetConns];

addItemInputs(
this: DynamicListCreateBlock,
targetConns: Array<Blockly.Connection | undefined | null>,
this: DynamicListCreateBlock,
targetConns: Array<Blockly.Connection | undefined | null>,
): void {

@@ -269,4 +279,5 @@ const input = this.addFirstInput();

addFirstInput(this: DynamicListCreateBlock): Blockly.Input {
return this.appendValueInput('ADD0')
.appendField(Blockly.Msg['LISTS_CREATE_WITH_INPUT_WITH']);
return this.appendValueInput('ADD0').appendField(
Blockly.Msg['LISTS_CREATE_WITH_INPUT_WITH'],
);
},

@@ -273,0 +284,0 @@ };

@@ -82,4 +82,3 @@ /**

inputNames.forEach((name) => this.appendValueInput(name));
this.inputList[0]
.appendField(Blockly.Msg['TEXT_JOIN_TITLE_CREATEWITH']);
this.inputList[0].appendField(Blockly.Msg['TEXT_JOIN_TITLE_CREATEWITH']);
}

@@ -94,3 +93,5 @@ },

this.itemCount = Math.max(
parseInt(xmlElement.getAttribute('items') ?? '0', 10), this.minInputs);
parseInt(xmlElement.getAttribute('items') ?? '0', 10),
this.minInputs,
);
// minInputs are added automatically.

@@ -106,3 +107,3 @@ for (let i = this.minInputs; i < this.itemCount; i++) {

*/
saveExtraState: function(this: DynamicTextJoinBlock): {itemCount: number} {
saveExtraState: function (this: DynamicTextJoinBlock): {itemCount: number} {
// If we call finalizeConnections here without disabling events, we get into

@@ -124,4 +125,6 @@ // an event loop.

*/
loadExtraState: function(
this: DynamicTextJoinBlock, state: ({[x: string]: any} | string)) {
loadExtraState: function (
this: DynamicTextJoinBlock,
state: {[x: string]: any} | string,
) {
if (typeof state === 'string') {

@@ -146,4 +149,5 @@ this.domToMutation(Blockly.utils.xml.textToDom(state));

findInputIndexForConnection(
this: DynamicTextJoinBlock,
connection: Blockly.Connection): number | null {
this: DynamicTextJoinBlock,
connection: Blockly.Connection,
): number | null {
if (!connection.targetConnection) {

@@ -168,6 +172,7 @@ // this connection is available

const nextInput = this.inputList[connectionIndex + 1];
const nextConnection =
nextInput?.connection?.targetConnection;
if (nextConnection &&
!nextConnection.getSourceBlock().isInsertionMarker()) {
const nextConnection = nextInput?.connection?.targetConnection;
if (
nextConnection &&
!nextConnection.getSourceBlock().isInsertionMarker()
) {
return connectionIndex + 1;

@@ -187,3 +192,5 @@ }

onPendingConnection(
this: DynamicTextJoinBlock, connection: Blockly.Connection): void {
this: DynamicTextJoinBlock,
connection: Blockly.Connection,
): void {
const insertIndex = this.findInputIndexForConnection(connection);

@@ -202,5 +209,5 @@ if (insertIndex == null) {

finalizeConnections(this: DynamicTextJoinBlock): void {
const targetConns =
this.removeUnnecessaryEmptyConns(
this.inputList.map((i) => i.connection?.targetConnection));
const targetConns = this.removeUnnecessaryEmptyConns(
this.inputList.map((i) => i.connection?.targetConnection),
);
this.tearDownBlock();

@@ -227,4 +234,4 @@ this.addItemInputs(targetConns);

removeUnnecessaryEmptyConns(
this: DynamicTextJoinBlock,
targetConns: Array<Blockly.Connection | undefined | null>
this: DynamicTextJoinBlock,
targetConns: Array<Blockly.Connection | undefined | null>,
): Array<Blockly.Connection | undefined | null> {

@@ -248,4 +255,4 @@ const filteredConns = [...targetConns];

addItemInputs(
this: DynamicTextJoinBlock,
targetConns: Array<Blockly.Connection | undefined | null>,
this: DynamicTextJoinBlock,
targetConns: Array<Blockly.Connection | undefined | null>,
): void {

@@ -269,4 +276,5 @@ const input = this.addFirstInput();

addFirstInput(this: DynamicTextJoinBlock): Blockly.Input {
return this.appendValueInput('ADD0')
.appendField(Blockly.Msg['TEXT_JOIN_TITLE_CREATEWITH']);
return this.appendValueInput('ADD0').appendField(
Blockly.Msg['TEXT_JOIN_TITLE_CREATEWITH'],
);
},

@@ -273,0 +281,0 @@ };

@@ -18,3 +18,3 @@ /**

export const overrideOldBlockDefinitions = function(): void {
export const overrideOldBlockDefinitions = function (): void {
Blockly.Blocks['lists_create_with'] = Blockly.Blocks['dynamic_list_create'];

@@ -21,0 +21,0 @@ Blockly.Blocks['text_join'] = Blockly.Blocks['dynamic_text_join'];

@@ -19,3 +19,3 @@ /**

interface MonkeyPatchedInsertionMarkerManager
extends Blockly.InsertionMarkerManager {
extends Blockly.InsertionMarkerManager {
pendingBlocks: Set<Blockly.Block>;

@@ -35,44 +35,46 @@ }

// type information in the d.ts files and are considered to return any here.
Blockly.InsertionMarkerManager.prototype.update =
function(
this: MonkeyPatchedInsertionMarkerManager,
dxy: Blockly.utils.Coordinate,
dragTarget: Blockly.IDragTarget | null): void {
const newCandidate = this['getCandidate'](dxy);
Blockly.InsertionMarkerManager.prototype.update = function (
this: MonkeyPatchedInsertionMarkerManager,
dxy: Blockly.utils.Coordinate,
dragTarget: Blockly.IDragTarget | null,
): void {
const newCandidate = this['getCandidate'](dxy);
this.wouldDeleteBlock = this['shouldDelete'](!!newCandidate, dragTarget);
this.wouldDeleteBlock = this['shouldDelete'](!!newCandidate, dragTarget);
const shouldUpdate: boolean = this.wouldDeleteBlock ||
this['shouldUpdatePreviews'](newCandidate, dxy);
const shouldUpdate: boolean =
this.wouldDeleteBlock || this['shouldUpdatePreviews'](newCandidate, dxy);
if (shouldUpdate) {
// Begin monkey patch
if (newCandidate?.closest?.sourceBlock_.onPendingConnection) {
newCandidate.closest.sourceBlock_
.onPendingConnection(newCandidate.closest);
if (!this.pendingBlocks) {
this.pendingBlocks = new Set();
}
this.pendingBlocks.add(newCandidate.closest.sourceBlock_);
}
// End monkey patch
// Don't fire events for insertion marker creation or movement.
Blockly.Events.disable();
this['maybeHidePreview'](newCandidate);
this['maybeShowPreview'](newCandidate);
Blockly.Events.enable();
if (shouldUpdate) {
// Begin monkey patch
if (newCandidate?.closest?.sourceBlock_.onPendingConnection) {
newCandidate.closest.sourceBlock_.onPendingConnection(
newCandidate.closest,
);
if (!this.pendingBlocks) {
this.pendingBlocks = new Set();
}
};
this.pendingBlocks.add(newCandidate.closest.sourceBlock_);
}
// End monkey patch
// Don't fire events for insertion marker creation or movement.
Blockly.Events.disable();
this['maybeHidePreview'](newCandidate);
this['maybeShowPreview'](newCandidate);
Blockly.Events.enable();
}
};
const oldDispose = Blockly.InsertionMarkerManager.prototype.dispose;
Blockly.InsertionMarkerManager.prototype.dispose =
function(this: MonkeyPatchedInsertionMarkerManager) {
if (this.pendingBlocks) {
this.pendingBlocks.forEach((block) => {
if ((block as DynamicBlock).finalizeConnections) {
(block as DynamicBlock).finalizeConnections();
}
});
Blockly.InsertionMarkerManager.prototype.dispose = function (
this: MonkeyPatchedInsertionMarkerManager,
) {
if (this.pendingBlocks) {
this.pendingBlocks.forEach((block) => {
if ((block as DynamicBlock).finalizeConnections) {
(block as DynamicBlock).finalizeConnections();
}
oldDispose.call(this);
};
});
}
oldDispose.call(this);
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc