Skip to content

Commit 43be0ed

Browse files
authored
fix!: Fix types on BlockSvg connections (#9669)
1 parent 15a4d50 commit 43be0ed

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

packages/blockly/blocks/text.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,15 @@ const JOIN_MUTATOR_MIXIN = {
757757
'text_create_join_container',
758758
) as BlockSvg;
759759
containerBlock.initSvg();
760-
let connection = containerBlock.getInput('STACK')!.connection!;
760+
let connection = containerBlock.getInput('STACK')?.connection;
761761
for (let i = 0; i < this.itemCount_; i++) {
762762
const itemBlock = workspace.newBlock(
763763
'text_create_join_item',
764764
) as JoinItemBlock;
765765
itemBlock.initSvg();
766-
connection.connect(itemBlock.previousConnection);
766+
if (itemBlock.previousConnection) {
767+
connection?.connect(itemBlock.previousConnection);
768+
}
767769
connection = itemBlock.nextConnection;
768770
}
769771
return containerBlock;

packages/blockly/core/block_svg.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,9 @@ export class BlockSvg
160160
private visuallyDisabled = false;
161161

162162
override workspace: WorkspaceSvg;
163-
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
164-
override outputConnection!: RenderedConnection;
165-
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
166-
override nextConnection!: RenderedConnection;
167-
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
168-
override previousConnection!: RenderedConnection;
163+
override outputConnection: RenderedConnection | null = null;
164+
override nextConnection: RenderedConnection | null = null;
165+
override previousConnection: RenderedConnection | null = null;
169166

170167
private translation = '';
171168

packages/blockly/core/dragging/block_drag_strategy.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export class BlockDragStrategy implements IDragStrategy {
366366
};
367367
}
368368

369-
this.startChildConn = nextTargetConn;
369+
this.startChildConn = nextTargetConn ?? null;
370370
}
371371
}
372372
}
@@ -627,7 +627,7 @@ export class BlockDragStrategy implements IDragStrategy {
627627
draggingBlock.outputConnection,
628628
draggingBlock.previousConnection,
629629
draggingBlock.nextConnection,
630-
].filter(Boolean); // Removes falsy (null) values.
630+
].filter((c) => !!c); // Removes falsy (null) values.
631631
const inputConnections: RenderedConnection[] = [];
632632

633633
for (const conn of available) {
@@ -727,14 +727,20 @@ export class BlockDragStrategy implements IDragStrategy {
727727
this.connectionPreviewer?.hidePreview();
728728
this.connectionCandidate = null;
729729

730-
this.startChildConn?.connect(this.block.nextConnection);
730+
if (this.block.nextConnection) {
731+
this.startChildConn?.connect(this.block.nextConnection);
732+
}
731733
if (this.startParentConn) {
732734
switch (this.startParentConn.type) {
733735
case ConnectionType.INPUT_VALUE:
734-
this.startParentConn.connect(this.block.outputConnection);
736+
if (this.block.outputConnection) {
737+
this.startParentConn.connect(this.block.outputConnection);
738+
}
735739
break;
736740
case ConnectionType.NEXT_STATEMENT:
737-
this.startParentConn.connect(this.block.previousConnection);
741+
if (this.block.previousConnection) {
742+
this.startParentConn.connect(this.block.previousConnection);
743+
}
738744
}
739745
} else {
740746
this.block.moveTo(this.startLoc!, ['drag']);

packages/blockly/core/renderers/common/drawer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ export class Drawer {
422422
const x =
423423
this.info_.startX + this.info_.outputConnection.connectionOffsetX;
424424
const connX = this.info_.RTL ? -x : x;
425-
this.block_.outputConnection.setOffsetInBlock(
425+
this.block_.outputConnection?.setOffsetInBlock(
426426
connX,
427427
this.info_.outputConnection.connectionOffsetY,
428428
);

0 commit comments

Comments
 (0)