scratch-blocks 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +140 -0
- package/dist/main.mjs +1 -1
- package/dist/types/src/blocks/procedures.d.ts +1 -1
- package/dist/types/src/blocks/procedures.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
- package/dist/types/src/fields/field_colour_slider.d.ts +4 -4
- package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
- package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
- package/dist/types/src/fields/field_note.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_variable.d.ts +1 -1
- package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
- package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
- package/dist/types/src/procedures.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/drawer.d.ts +1 -1
- package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/render_info.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/renderer.d.ts +1 -1
- package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
- package/dist/types/src/renderer/constants.d.ts +41 -0
- package/dist/types/src/renderer/constants.d.ts.map +1 -0
- package/dist/types/src/renderer/drawer.d.ts +2 -2
- package/dist/types/src/renderer/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/render_info.d.ts.map +1 -1
- package/dist/types/src/renderer/renderer.d.ts +1 -1
- package/dist/types/src/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_bubble.d.ts +2 -2
- package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_icon.d.ts +1 -1
- package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
- package/dist/types/src/scratch_dragger.d.ts +1 -1
- package/dist/types/src/scratch_variable_model.d.ts +1 -1
- package/dist/types/src/scratch_variable_model.d.ts.map +1 -1
- package/dist/types/tests/jsunit/connection_db_test.d.ts +3 -3
- package/package.json +9 -9
- package/src/block_reporting.ts +2 -2
- package/src/blocks/control.ts +9 -2
- package/src/blocks/data.ts +34 -6
- package/src/blocks/procedures.ts +49 -31
- package/src/context_menu_items.ts +7 -7
- package/src/data_category.ts +4 -4
- package/src/events/events_block_comment_base.ts +8 -5
- package/src/events/events_block_comment_change.ts +4 -4
- package/src/events/events_block_comment_collapse.ts +14 -2
- package/src/events/events_block_comment_create.ts +4 -1
- package/src/events/events_block_comment_delete.ts +4 -2
- package/src/events/events_block_comment_move.ts +4 -4
- package/src/events/events_block_comment_resize.ts +4 -4
- package/src/events/events_block_drag_end.ts +4 -4
- package/src/events/events_block_drag_outside.ts +2 -2
- package/src/events/events_scratch_variable_create.ts +20 -2
- package/src/fields/field_colour_slider.ts +53 -28
- package/src/fields/field_matrix.ts +9 -8
- package/src/fields/field_note.ts +34 -27
- package/src/fields/field_textinput_removable.ts +2 -2
- package/src/fields/field_variable_getter.ts +5 -5
- package/src/fields/field_vertical_separator.ts +1 -1
- package/src/fields/scratch_field_angle.ts +14 -14
- package/src/fields/scratch_field_dropdown.ts +2 -2
- package/src/fields/scratch_field_number.ts +13 -12
- package/src/fields/scratch_field_variable.ts +8 -5
- package/src/flyout_checkbox_icon.ts +1 -1
- package/src/glows.ts +2 -2
- package/src/procedures.ts +25 -17
- package/src/renderer/cat/cat_face.ts +1 -1
- package/src/renderer/cat/drawer.ts +3 -3
- package/src/renderer/cat/render_info.ts +2 -2
- package/src/renderer/cat/renderer.ts +2 -2
- package/src/renderer/constants.ts +8 -8
- package/src/renderer/drawer.ts +2 -2
- package/src/renderer/render_info.ts +7 -4
- package/src/renderer/renderer.ts +2 -2
- package/src/scratch_block_paster.ts +1 -1
- package/src/scratch_comment_bubble.ts +16 -14
- package/src/scratch_comment_icon.ts +1 -1
- package/src/scratch_dragger.ts +2 -2
- package/src/scratch_variable_model.ts +2 -2
- package/src/status_indicator_label.ts +3 -3
- package/src/status_indicator_label_flyout_inflater.ts +1 -1
- package/src/variables.ts +7 -7
- package/src/xml.ts +3 -3
- package/tsconfig.json +1 -1
|
@@ -12,8 +12,8 @@ import { type RenderInfo } from "./render_info";
|
|
|
12
12
|
import { CatFace } from "./cat_face";
|
|
13
13
|
|
|
14
14
|
export class Drawer extends ClassicDrawer {
|
|
15
|
-
constants_: ConstantProvider;
|
|
16
|
-
info_: RenderInfo;
|
|
15
|
+
declare constants_: ConstantProvider;
|
|
16
|
+
declare info_: RenderInfo;
|
|
17
17
|
|
|
18
18
|
override draw() {
|
|
19
19
|
// Make sure the face exists if we need it.
|
|
@@ -57,7 +57,7 @@ export class Drawer extends ClassicDrawer {
|
|
|
57
57
|
const pathObject = this.block_.pathObject as PathObject;
|
|
58
58
|
return this.constants_.makeCatPath(
|
|
59
59
|
this.info_.width,
|
|
60
|
-
pathObject.catFace
|
|
60
|
+
pathObject.catFace!.pathEarState
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -10,6 +10,6 @@ import { ConstantProvider } from "./constants";
|
|
|
10
10
|
import { CatScratchRenderer } from "./renderer";
|
|
11
11
|
|
|
12
12
|
export class RenderInfo extends ClassicRenderInfo {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
declare constants_: ConstantProvider;
|
|
14
|
+
declare renderer_: CatScratchRenderer;
|
|
15
15
|
}
|
|
@@ -18,8 +18,8 @@ export class CatScratchRenderer extends ScratchRenderer {
|
|
|
18
18
|
return new ConstantProvider();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
override makeDrawer_(block: Blockly.BlockSvg, info: RenderInfo) {
|
|
22
|
-
return new Drawer(block, info);
|
|
21
|
+
override makeDrawer_(block: Blockly.BlockSvg, info: Blockly.blockRendering.RenderInfo) {
|
|
22
|
+
return new Drawer(block, info as RenderInfo);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
override makeRenderInfo_(block: Blockly.BlockSvg): RenderInfo {
|
|
@@ -64,7 +64,7 @@ export class ConstantProvider extends Blockly.zelos.ConstantProvider {
|
|
|
64
64
|
* drawn with the rounded shape that matches what they accept, not the
|
|
65
65
|
* hexagonal shape of their parent block's output.
|
|
66
66
|
*/
|
|
67
|
-
override shapeFor(connection: Blockly.RenderedConnection) {
|
|
67
|
+
override shapeFor(connection: Blockly.RenderedConnection): ReturnType<Blockly.zelos.ConstantProvider["shapeFor"]> {
|
|
68
68
|
let checks = connection.getCheck();
|
|
69
69
|
if (!checks && connection.targetConnection) {
|
|
70
70
|
checks = connection.targetConnection.getCheck();
|
|
@@ -75,19 +75,19 @@ export class ConstantProvider extends Blockly.zelos.ConstantProvider {
|
|
|
75
75
|
if (outputShape !== null) {
|
|
76
76
|
switch (outputShape) {
|
|
77
77
|
case this.SHAPES.HEXAGONAL:
|
|
78
|
-
return this.HEXAGONAL
|
|
78
|
+
return this.HEXAGONAL!;
|
|
79
79
|
case this.SHAPES.ROUND:
|
|
80
|
-
return this.ROUNDED
|
|
80
|
+
return this.ROUNDED!;
|
|
81
81
|
case this.SHAPES.SQUARE:
|
|
82
|
-
return this.SQUARED
|
|
82
|
+
return this.SQUARED!;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// For INPUT_VALUE (and OUTPUT_VALUE fallthrough), use connection checks.
|
|
88
|
-
if (checks?.includes("Boolean")) return this.HEXAGONAL
|
|
89
|
-
if (checks?.includes("Number")) return this.ROUNDED
|
|
90
|
-
if (checks?.includes("String")) return this.ROUNDED
|
|
88
|
+
if (checks?.includes("Boolean")) return this.HEXAGONAL!;
|
|
89
|
+
if (checks?.includes("Number")) return this.ROUNDED!;
|
|
90
|
+
if (checks?.includes("String")) return this.ROUNDED!;
|
|
91
91
|
// For INPUT_VALUE or OUTPUT_VALUE with unrecognized checks, default to
|
|
92
92
|
// ROUNDED. Don't call super.shapeFor() here: the base implementation
|
|
93
93
|
// uses getSourceBlock().getOutputShape(), which would incorrectly return
|
|
@@ -96,7 +96,7 @@ export class ConstantProvider extends Blockly.zelos.ConstantProvider {
|
|
|
96
96
|
connection.type === Blockly.ConnectionType.INPUT_VALUE ||
|
|
97
97
|
connection.type === Blockly.ConnectionType.OUTPUT_VALUE
|
|
98
98
|
) {
|
|
99
|
-
return this.ROUNDED
|
|
99
|
+
return this.ROUNDED!;
|
|
100
100
|
}
|
|
101
101
|
return super.shapeFor(connection);
|
|
102
102
|
}
|
package/src/renderer/drawer.ts
CHANGED
|
@@ -9,8 +9,8 @@ import type { RenderInfo } from "./render_info";
|
|
|
9
9
|
import { ConstantProvider } from "./constants";
|
|
10
10
|
|
|
11
11
|
export class Drawer extends Blockly.zelos.Drawer {
|
|
12
|
-
constants_: ConstantProvider;
|
|
13
|
-
info_: RenderInfo;
|
|
12
|
+
declare constants_: ConstantProvider;
|
|
13
|
+
declare info_: RenderInfo;
|
|
14
14
|
|
|
15
15
|
override drawStatementInput_(row: Blockly.blockRendering.Row) {
|
|
16
16
|
if (this.info_.isBowlerHatBlock()) {
|
|
@@ -10,7 +10,7 @@ import { BowlerHat } from "./bowler_hat";
|
|
|
10
10
|
import { ConstantProvider } from "./constants";
|
|
11
11
|
|
|
12
12
|
export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
13
|
-
constants_: ConstantProvider;
|
|
13
|
+
declare constants_: ConstantProvider;
|
|
14
14
|
|
|
15
15
|
override populateTopRow_() {
|
|
16
16
|
if (this.isBowlerHatBlock()) {
|
|
@@ -41,19 +41,22 @@ export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
|
41
41
|
if (this.isBowlerHatBlock()) {
|
|
42
42
|
// Resize the render info to the same width as the widest part of a
|
|
43
43
|
// bowler hat block.
|
|
44
|
-
|
|
44
|
+
// Bowler hat blocks always have exactly one statement row and one input
|
|
45
|
+
// element, so these find() calls are guaranteed to succeed.
|
|
46
|
+
const statementRow = this.rows.find((r) => r.hasStatement)!;
|
|
45
47
|
this.width =
|
|
46
48
|
statementRow.widthWithConnectedBlocks -
|
|
47
49
|
statementRow.elements.find((e) =>
|
|
48
50
|
Blockly.blockRendering.Types.isInput(e)
|
|
49
|
-
)
|
|
51
|
+
)!.width +
|
|
50
52
|
this.constants_.MEDIUM_PADDING;
|
|
51
53
|
|
|
52
54
|
// The bowler hat's width is the same as the block's width, so it can't
|
|
53
55
|
// be derived from the constants like a normal hat and has to be set here.
|
|
56
|
+
// populateTopRow_ always adds a hat element for bowler hat blocks.
|
|
54
57
|
const hat = this.topRow.elements.find((e) =>
|
|
55
58
|
Blockly.blockRendering.Types.isHat(e)
|
|
56
|
-
)
|
|
59
|
+
)!;
|
|
57
60
|
hat.width = this.width;
|
|
58
61
|
this.topRow.measure();
|
|
59
62
|
}
|
package/src/renderer/renderer.ts
CHANGED
|
@@ -32,8 +32,8 @@ export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
|
32
32
|
* block.
|
|
33
33
|
* @returns The drawer.
|
|
34
34
|
*/
|
|
35
|
-
override makeDrawer_(block: Blockly.BlockSvg, info: RenderInfo): Drawer {
|
|
36
|
-
return new Drawer(block, info);
|
|
35
|
+
override makeDrawer_(block: Blockly.BlockSvg, info: Blockly.blockRendering.RenderInfo): Drawer {
|
|
36
|
+
return new Drawer(block, info as RenderInfo);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -36,7 +36,7 @@ class ScratchBlockPaster extends Blockly.clipboard.BlockPaster {
|
|
|
36
36
|
// fired for blocks with comments, the VM will never receive it, causing its
|
|
37
37
|
// state to get out of sync. Manually fire it here (after suppression has
|
|
38
38
|
// been turned off) if needed.
|
|
39
|
-
const commentIcon = block
|
|
39
|
+
const commentIcon = block?.getIcon(Blockly.icons.IconType.COMMENT);
|
|
40
40
|
if (commentIcon) {
|
|
41
41
|
(commentIcon as ScratchCommentIcon).fireCreateEvent();
|
|
42
42
|
}
|
|
@@ -16,7 +16,7 @@ export class ScratchCommentBubble
|
|
|
16
16
|
implements Blockly.IBubble, Blockly.ISelectable
|
|
17
17
|
{
|
|
18
18
|
id: string;
|
|
19
|
-
private sourceBlock: Blockly.BlockSvg;
|
|
19
|
+
private sourceBlock: Blockly.BlockSvg | null;
|
|
20
20
|
private anchor?: Blockly.utils.Coordinate;
|
|
21
21
|
private anchorChain?: SVGLineElement;
|
|
22
22
|
private dragStartLocation?: Blockly.utils.Coordinate;
|
|
@@ -71,7 +71,7 @@ export class ScratchCommentBubble
|
|
|
71
71
|
const destination =
|
|
72
72
|
xOrCoordinate instanceof Blockly.utils.Coordinate
|
|
73
73
|
? xOrCoordinate
|
|
74
|
-
: new Blockly.utils.Coordinate(xOrCoordinate, y);
|
|
74
|
+
: new Blockly.utils.Coordinate(xOrCoordinate, y!);
|
|
75
75
|
super.moveTo(destination);
|
|
76
76
|
this.redrawAnchorChain();
|
|
77
77
|
}
|
|
@@ -79,7 +79,9 @@ export class ScratchCommentBubble
|
|
|
79
79
|
startGesture(e: PointerEvent) {
|
|
80
80
|
const gesture = this.workspace.getGesture(e);
|
|
81
81
|
if (gesture) {
|
|
82
|
-
|
|
82
|
+
// ScratchCommentBubble implements IBubble structurally but TypeScript
|
|
83
|
+
// cannot verify it because IBubble.drag has a different signature here.
|
|
84
|
+
gesture.handleBubbleStart(e, this as unknown as Blockly.IBubble);
|
|
83
85
|
Blockly.common.setSelected(this);
|
|
84
86
|
}
|
|
85
87
|
}
|
|
@@ -91,7 +93,7 @@ export class ScratchCommentBubble
|
|
|
91
93
|
Blockly.utils.dom.addClass(this.getSvgRoot(), "blocklyDragging");
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
drag(newLocation: Blockly.utils.Coordinate, event
|
|
96
|
+
drag(newLocation: Blockly.utils.Coordinate, event?: PointerEvent) {
|
|
95
97
|
this.moveTo(newLocation);
|
|
96
98
|
}
|
|
97
99
|
|
|
@@ -111,7 +113,7 @@ export class ScratchCommentBubble
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
revertDrag() {
|
|
114
|
-
this.moveTo(this.dragStartLocation);
|
|
116
|
+
this.moveTo(this.dragStartLocation!);
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
setAnchorLocation(newAnchor: Blockly.utils.Coordinate) {
|
|
@@ -122,7 +124,7 @@ export class ScratchCommentBubble
|
|
|
122
124
|
this.dropAnchor();
|
|
123
125
|
} else {
|
|
124
126
|
const oldLocation = this.getRelativeToSurfaceXY();
|
|
125
|
-
const delta = Blockly.utils.Coordinate.difference(this.anchor, oldAnchor);
|
|
127
|
+
const delta = Blockly.utils.Coordinate.difference(this.anchor, oldAnchor!);
|
|
126
128
|
const newLocation = Blockly.utils.Coordinate.sum(oldLocation, delta);
|
|
127
129
|
this.moveTo(newLocation);
|
|
128
130
|
}
|
|
@@ -131,18 +133,18 @@ export class ScratchCommentBubble
|
|
|
131
133
|
dropAnchor() {
|
|
132
134
|
const verticalOffset = 16;
|
|
133
135
|
this.moveTo(
|
|
134
|
-
this.anchor
|
|
135
|
-
this.anchor
|
|
136
|
+
this.anchor!.x + 40 * (this.workspace.RTL ? -1 : 1),
|
|
137
|
+
this.anchor!.y - verticalOffset
|
|
136
138
|
);
|
|
137
139
|
const location = this.getRelativeToSurfaceXY();
|
|
138
140
|
this.anchorChain = Blockly.utils.dom.createSvgElement(
|
|
139
141
|
Blockly.utils.Svg.LINE,
|
|
140
142
|
{
|
|
141
|
-
x1: this.anchor
|
|
142
|
-
y1: this.anchor
|
|
143
|
+
x1: this.anchor!.x - location.x,
|
|
144
|
+
y1: this.anchor!.y - location.y,
|
|
143
145
|
x2: (this.getSize().width / 2) * (this.workspace.RTL ? -1 : 1),
|
|
144
146
|
y2: verticalOffset,
|
|
145
|
-
style: `stroke: ${this.sourceBlock
|
|
147
|
+
style: `stroke: ${this.sourceBlock!.getColourTertiary()}; stroke-width: 1`,
|
|
146
148
|
},
|
|
147
149
|
this.getSvgRoot()
|
|
148
150
|
);
|
|
@@ -156,8 +158,8 @@ export class ScratchCommentBubble
|
|
|
156
158
|
if (!this.anchorChain) return;
|
|
157
159
|
|
|
158
160
|
const location = this.getRelativeToSurfaceXY();
|
|
159
|
-
this.anchorChain
|
|
160
|
-
this.anchorChain
|
|
161
|
+
this.anchorChain!.setAttribute("x1", `${this.anchor!.x - location.x}`);
|
|
162
|
+
this.anchorChain!.setAttribute("y1", `${this.anchor!.y - location.y}`);
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
getId() {
|
|
@@ -170,7 +172,7 @@ export class ScratchCommentBubble
|
|
|
170
172
|
|
|
171
173
|
dispose() {
|
|
172
174
|
this.disposing = true;
|
|
173
|
-
Blockly.utils.dom.removeNode(this.anchorChain);
|
|
175
|
+
Blockly.utils.dom.removeNode(this.anchorChain ?? null);
|
|
174
176
|
if (this.sourceBlock) {
|
|
175
177
|
Blockly.Events.fire(
|
|
176
178
|
new (Blockly.Events.get("block_comment_delete"))(this, this.sourceBlock)
|
package/src/scratch_dragger.ts
CHANGED
|
@@ -104,8 +104,8 @@ export class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
104
104
|
this.wouldDeleteDraggable(event, this.draggable.getRootBlock())
|
|
105
105
|
) {
|
|
106
106
|
const prototype = this.draggable
|
|
107
|
-
.getInput("custom_block")
|
|
108
|
-
.connection
|
|
107
|
+
.getInput("custom_block")!
|
|
108
|
+
.connection!.targetBlock();
|
|
109
109
|
const hasCaller =
|
|
110
110
|
prototype instanceof Blockly.BlockSvg &&
|
|
111
111
|
isProcedureBlock(prototype) &&
|
|
@@ -13,8 +13,8 @@ export class ScratchVariableModel extends Blockly.VariableModel {
|
|
|
13
13
|
constructor(
|
|
14
14
|
workspace: Blockly.Workspace,
|
|
15
15
|
name: string,
|
|
16
|
-
type
|
|
17
|
-
id
|
|
16
|
+
type?: string,
|
|
17
|
+
id?: string,
|
|
18
18
|
public isLocal = false,
|
|
19
19
|
public isCloud = false
|
|
20
20
|
) {
|
|
@@ -64,11 +64,11 @@ export class StatusIndicatorLabel extends Blockly.FlyoutButton {
|
|
|
64
64
|
json: Blockly.utils.toolbox.LabelInfo
|
|
65
65
|
) {
|
|
66
66
|
super(workspace, targetWorkspace, json, true);
|
|
67
|
-
this.extensionId = json["id"]
|
|
67
|
+
this.extensionId = json["id"]!;
|
|
68
68
|
|
|
69
69
|
const heightDelta = 40 - this.height;
|
|
70
70
|
this.height = 40;
|
|
71
|
-
const text = this.getSvgRoot().querySelector("text")
|
|
71
|
+
const text = this.getSvgRoot().querySelector("text")!;
|
|
72
72
|
const previousY = Number(text.getAttribute("y"));
|
|
73
73
|
|
|
74
74
|
text.setAttribute("y", `${previousY + heightDelta / 2}`);
|
|
@@ -77,7 +77,7 @@ export class StatusIndicatorLabel extends Blockly.FlyoutButton {
|
|
|
77
77
|
const marginX = 20;
|
|
78
78
|
const marginY = 5;
|
|
79
79
|
const touchPadding = 16;
|
|
80
|
-
const flyoutWidth = targetWorkspace.getFlyout()
|
|
80
|
+
const flyoutWidth = targetWorkspace.getFlyout()!.getWidth();
|
|
81
81
|
|
|
82
82
|
const statusButtonX = workspace.RTL
|
|
83
83
|
? marginX - flyoutWidth + statusButtonWidth
|
|
@@ -26,7 +26,7 @@ class StatusIndicatorLabelFlyoutInflater extends Blockly.LabelFlyoutInflater {
|
|
|
26
26
|
): Blockly.FlyoutItem {
|
|
27
27
|
const label = new StatusIndicatorLabel(
|
|
28
28
|
flyout.getWorkspace(),
|
|
29
|
-
flyout.targetWorkspace
|
|
29
|
+
flyout.targetWorkspace!,
|
|
30
30
|
state
|
|
31
31
|
);
|
|
32
32
|
label.show();
|
package/src/variables.ts
CHANGED
|
@@ -98,7 +98,7 @@ export function createVariable(
|
|
|
98
98
|
const validate = nameValidator.bind(null, opt_type);
|
|
99
99
|
|
|
100
100
|
// Prompt the user to enter a name for the variable
|
|
101
|
-
prompt(
|
|
101
|
+
prompt!(
|
|
102
102
|
newMsg,
|
|
103
103
|
"",
|
|
104
104
|
function (
|
|
@@ -127,7 +127,7 @@ export function createVariable(
|
|
|
127
127
|
workspace,
|
|
128
128
|
validatedText,
|
|
129
129
|
opt_type,
|
|
130
|
-
|
|
130
|
+
undefined,
|
|
131
131
|
isLocal,
|
|
132
132
|
isCloud
|
|
133
133
|
);
|
|
@@ -137,7 +137,7 @@ export function createVariable(
|
|
|
137
137
|
);
|
|
138
138
|
|
|
139
139
|
const toolbox = workspace.getToolbox();
|
|
140
|
-
const flyout = toolbox
|
|
140
|
+
const flyout = toolbox?.getFlyout();
|
|
141
141
|
const variableBlockId = variable.getId();
|
|
142
142
|
if (
|
|
143
143
|
toolbox instanceof ScratchContinuousToolbox &&
|
|
@@ -154,7 +154,7 @@ export function createVariable(
|
|
|
154
154
|
} else {
|
|
155
155
|
// User canceled prompt without a value.
|
|
156
156
|
if (opt_callback) {
|
|
157
|
-
opt_callback(
|
|
157
|
+
opt_callback(undefined);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
},
|
|
@@ -193,7 +193,7 @@ function nameValidator(
|
|
|
193
193
|
additionalVars: string[],
|
|
194
194
|
isCloud: boolean,
|
|
195
195
|
opt_callback?: (id?: string) => void
|
|
196
|
-
): string {
|
|
196
|
+
): string | null {
|
|
197
197
|
// The validators for the different variable types require slightly different
|
|
198
198
|
// arguments. For broadcast messages, if a broadcast message of the provided
|
|
199
199
|
// name already exists, the validator needs to call a function that updates
|
|
@@ -345,7 +345,7 @@ export function renameVariable(
|
|
|
345
345
|
promptDefaultText = promptDefaultText.substring(CLOUD_PREFIX.length);
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
prompt(
|
|
348
|
+
prompt!(
|
|
349
349
|
promptText,
|
|
350
350
|
promptDefaultText,
|
|
351
351
|
(newName: string, additionalVars: string[]) => {
|
|
@@ -373,7 +373,7 @@ export function renameVariable(
|
|
|
373
373
|
} else {
|
|
374
374
|
// User canceled prompt without a value.
|
|
375
375
|
if (opt_callback) {
|
|
376
|
-
opt_callback(
|
|
376
|
+
opt_callback(undefined);
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
},
|
package/src/xml.ts
CHANGED
|
@@ -26,8 +26,8 @@ export function clearWorkspaceAndLoadFromXml(
|
|
|
26
26
|
for (const variable of xml.querySelectorAll("variables variable")) {
|
|
27
27
|
const id = variable.getAttribute("id");
|
|
28
28
|
if (!id) continue;
|
|
29
|
-
const type = variable.getAttribute("type");
|
|
30
|
-
const name = variable.textContent;
|
|
29
|
+
const type = variable.getAttribute("type") ?? "";
|
|
30
|
+
const name = variable.textContent ?? "";
|
|
31
31
|
const isLocal = variable.getAttribute("islocal") === "true";
|
|
32
32
|
const isCloud = variable.getAttribute("iscloud") === "true";
|
|
33
33
|
|
|
@@ -47,7 +47,7 @@ export function clearWorkspaceAndLoadFromXml(
|
|
|
47
47
|
|
|
48
48
|
// Remove the `variables` element from the XML to prevent Blockly from
|
|
49
49
|
// throwing or stomping on the variables we created.
|
|
50
|
-
xml.querySelector("variables")
|
|
50
|
+
xml.querySelector("variables")?.remove();
|
|
51
51
|
|
|
52
52
|
// Defer to core for the rest of the deserialization.
|
|
53
53
|
const blockIds = Blockly.Xml.domToWorkspace(xml, workspace);
|