scratch-blocks 2.0.0-spork.2 → 2.0.0-spork.4
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/CHANGELOG.md +14 -0
- package/dist/main.js +1 -1
- package/dist/main.js.LICENSE.txt +0 -12
- package/package.json +4 -4
- package/src/{block_reporting.js → block_reporting.ts} +7 -5
- package/src/blocks/{colour.js → colour.ts} +6 -6
- package/src/blocks/{control.js → control.ts} +21 -54
- package/src/blocks/{data.js → data.ts} +134 -142
- package/src/blocks/{event.js → event.ts} +12 -33
- package/src/blocks/{looks.js → looks.ts} +24 -73
- package/src/blocks/{math.js → math.ts} +6 -11
- package/src/blocks/{matrix.js → matrix.ts} +2 -3
- package/src/blocks/{motion.js → motion.ts} +23 -70
- package/src/blocks/{note.js → note.ts} +2 -3
- package/src/blocks/{operators.js → operators.ts} +18 -55
- package/src/blocks/{procedures.js → procedures.ts} +418 -269
- package/src/blocks/{sensing.js → sensing.ts} +21 -61
- package/src/blocks/{sound.js → sound.ts} +9 -28
- package/src/blocks/{text.js → text.ts} +1 -2
- package/src/blocks/{vertical_extensions.js → vertical_extensions.ts} +63 -100
- package/src/checkable_continuous_flyout.ts +112 -0
- package/src/{checkbox_bubble.js → checkbox_bubble.ts} +40 -58
- package/src/{colours.js → colours.ts} +11 -4
- package/src/{constants.js → constants.ts} +13 -0
- package/src/{context_menu_items.js → context_menu_items.ts} +18 -12
- package/src/{css.js → css.ts} +13 -7
- package/src/{data_category.js → data_category.ts} +216 -150
- package/src/events/{events_block_comment_base.js → events_block_comment_base.ts} +23 -4
- package/src/events/{events_block_comment_change.js → events_block_comment_change.ts} +29 -5
- package/src/events/{events_block_comment_collapse.js → events_block_comment_collapse.ts} +24 -6
- package/src/events/{events_block_comment_create.js → events_block_comment_create.ts} +36 -10
- package/src/events/{events_block_comment_delete.js → events_block_comment_delete.ts} +6 -2
- package/src/events/{events_block_comment_move.js → events_block_comment_move.ts} +36 -6
- package/src/events/events_block_comment_resize.ts +88 -0
- package/src/events/events_block_drag_end.ts +49 -0
- package/src/events/events_block_drag_outside.ts +44 -0
- package/src/events/{events_scratch_variable_create.js → events_scratch_variable_create.ts} +28 -15
- package/src/fields/{field_colour_slider.js → field_colour_slider.ts} +117 -106
- package/src/fields/{field_matrix.js → field_matrix.ts} +189 -215
- package/src/fields/{field_note.js → field_note.ts} +227 -286
- package/src/fields/{field_textinput_removable.js → field_textinput_removable.ts} +17 -20
- package/src/fields/{field_variable_getter.js → field_variable_getter.ts} +28 -17
- package/src/fields/{field_vertical_separator.js → field_vertical_separator.ts} +14 -30
- package/src/fields/{field_angle.js → scratch_field_angle.ts} +124 -80
- package/src/fields/{field_dropdown.js → scratch_field_dropdown.ts} +9 -7
- package/src/fields/{field_number.js → scratch_field_number.ts} +60 -55
- package/src/fields/{field_variable.js → scratch_field_variable.ts} +46 -27
- package/src/{flyout_checkbox_icon.js → flyout_checkbox_icon.ts} +15 -19
- package/src/{glows.js → glows.ts} +29 -18
- package/src/index.ts +62 -63
- package/src/procedures.ts +462 -0
- package/src/recyclable_block_flyout_inflater.ts +51 -0
- package/src/renderer/{bowler_hat.js → bowler_hat.ts} +1 -1
- package/src/renderer/{constants.js → constants.ts} +26 -12
- package/src/renderer/{drawer.js → drawer.ts} +8 -3
- package/src/renderer/{path_object.js → path_object.ts} +2 -2
- package/src/renderer/{render_info.js → render_info.ts} +19 -7
- package/src/renderer/renderer.ts +76 -0
- package/src/{scratch_block_paster.js → scratch_block_paster.ts} +9 -7
- package/src/scratch_blocks_utils.ts +39 -0
- package/src/{scratch_comment_icon.js → scratch_comment_icon.ts} +43 -26
- package/src/scratch_connection_checker.ts +44 -0
- package/src/{scratch_continuous_category.js → scratch_continuous_category.ts} +20 -13
- package/src/scratch_continuous_toolbox.ts +70 -0
- package/src/{scratch_dragger.js → scratch_dragger.ts} +97 -28
- package/src/{scratch_variable_map.js → scratch_variable_map.ts} +4 -1
- package/src/scratch_variable_model.ts +30 -0
- package/src/{shadows.js → shadows.ts} +8 -4
- package/src/{status_indicator_label.js → status_indicator_label.ts} +24 -36
- package/src/{status_indicator_label_flyout_inflater.js → status_indicator_label_flyout_inflater.ts} +13 -9
- package/src/{variables.js → variables.ts} +153 -123
- package/tsconfig.json +5 -0
- package/src/categories.js +0 -15
- package/src/checkable_continuous_flyout.js +0 -138
- package/src/events/events_block_comment_resize.js +0 -52
- package/src/events/events_block_drag_end.js +0 -33
- package/src/events/events_block_drag_outside.js +0 -30
- package/src/procedures.js +0 -425
- package/src/recyclable_block_flyout_inflater.js +0 -194
- package/src/renderer/renderer.js +0 -74
- package/src/scratch_blocks_utils.js +0 -148
- package/src/scratch_connection_checker.js +0 -29
- package/src/scratch_continuous_toolbox.js +0 -78
- package/src/scratch_variable_model.js +0 -24
- /package/{continuous-toolbox.d.ts → types/continuous-toolbox.d.ts} +0 -0
|
@@ -5,23 +5,44 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as Blockly from "blockly/core";
|
|
8
|
-
import { BlockDragOutside } from "./events/events_block_drag_outside
|
|
9
|
-
import { BlockDragEnd } from "./events/events_block_drag_end
|
|
8
|
+
import { BlockDragOutside } from "./events/events_block_drag_outside";
|
|
9
|
+
import { BlockDragEnd } from "./events/events_block_drag_end";
|
|
10
|
+
import { isProcedureBlock, getCallers } from "./procedures";
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* CSS class that allows the workspace to overflow its bounds when set.
|
|
14
|
+
*/
|
|
11
15
|
const BOUNDLESS_CLASS = "boundless";
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Class responsible for managing dragging items on the workspace.
|
|
19
|
+
*/
|
|
20
|
+
export class ScratchDragger extends Blockly.dragging.Dragger {
|
|
21
|
+
/**
|
|
22
|
+
* Whether or not the current drag location is outside of the main workspace.
|
|
23
|
+
*/
|
|
24
|
+
draggedOutOfBounds = false;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether or not the current drag started from the flyout.
|
|
28
|
+
*/
|
|
29
|
+
originatedFromFlyout = false;
|
|
19
30
|
|
|
20
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Sets the current item being dragged.
|
|
33
|
+
*
|
|
34
|
+
* @param draggable The item being dragged.
|
|
35
|
+
*/
|
|
36
|
+
setDraggable(draggable: Blockly.IDraggable) {
|
|
21
37
|
this.draggable = draggable;
|
|
22
38
|
}
|
|
23
39
|
|
|
24
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Handles the start of a drag operation.
|
|
42
|
+
*
|
|
43
|
+
* @param event The event that triggered the drag.
|
|
44
|
+
*/
|
|
45
|
+
onDragStart(event: PointerEvent) {
|
|
25
46
|
super.onDragStart(event);
|
|
26
47
|
if (this.draggable instanceof Blockly.BlockSvg) {
|
|
27
48
|
this.workspace.addClass(BOUNDLESS_CLASS);
|
|
@@ -41,17 +62,28 @@ class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
41
62
|
}
|
|
42
63
|
}
|
|
43
64
|
|
|
44
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Handles motion during an ongoing drag operation.
|
|
67
|
+
*
|
|
68
|
+
* @param event The event that triggered this call.
|
|
69
|
+
* @param totalDelta The change in pointer position since the last invocation.
|
|
70
|
+
*/
|
|
71
|
+
onDrag(event: PointerEvent, totalDelta: Blockly.utils.Coordinate) {
|
|
45
72
|
super.onDrag(event, totalDelta);
|
|
46
73
|
this.updateOutOfBoundsState(event);
|
|
47
74
|
}
|
|
48
75
|
|
|
49
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Records whether or not the current drag is out of the workspace's bounds.
|
|
78
|
+
*
|
|
79
|
+
* @param event The event that triggered this call.
|
|
80
|
+
*/
|
|
81
|
+
updateOutOfBoundsState(event: PointerEvent) {
|
|
50
82
|
if (this.draggable instanceof Blockly.BlockSvg) {
|
|
51
83
|
const outOfBounds = !this.isInsideWorkspace(event);
|
|
52
84
|
if (outOfBounds !== this.draggedOutOfBounds) {
|
|
53
85
|
const event = new BlockDragOutside(
|
|
54
|
-
this.getDragRoot(this.draggable),
|
|
86
|
+
this.getDragRoot(this.draggable) as Blockly.BlockSvg,
|
|
55
87
|
outOfBounds
|
|
56
88
|
);
|
|
57
89
|
Blockly.Events.fire(event);
|
|
@@ -60,18 +92,30 @@ class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
60
92
|
}
|
|
61
93
|
}
|
|
62
94
|
|
|
63
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Handles the end of a drag.
|
|
97
|
+
*
|
|
98
|
+
* @param event The event that ended the drag.
|
|
99
|
+
*/
|
|
100
|
+
onDragEnd(event: PointerEvent) {
|
|
64
101
|
if (
|
|
65
102
|
this.draggable instanceof Blockly.BlockSvg &&
|
|
66
103
|
this.draggable.type === "procedures_definition" &&
|
|
67
104
|
this.wouldDeleteDraggable(event, this.draggable.getRootBlock())
|
|
68
105
|
) {
|
|
69
|
-
const
|
|
70
|
-
.
|
|
71
|
-
.
|
|
72
|
-
const hasCaller =
|
|
73
|
-
.
|
|
74
|
-
|
|
106
|
+
const prototype = this.draggable
|
|
107
|
+
.getInput("custom_block")
|
|
108
|
+
.connection.targetBlock();
|
|
109
|
+
const hasCaller =
|
|
110
|
+
prototype instanceof Blockly.BlockSvg &&
|
|
111
|
+
isProcedureBlock(prototype) &&
|
|
112
|
+
getCallers(
|
|
113
|
+
prototype.getProcCode(),
|
|
114
|
+
this.draggable.workspace,
|
|
115
|
+
this.draggable.getRootBlock(),
|
|
116
|
+
false
|
|
117
|
+
).length > 0;
|
|
118
|
+
|
|
75
119
|
if (hasCaller) {
|
|
76
120
|
Blockly.dialog.alert(Blockly.Msg.PROCEDURE_USED);
|
|
77
121
|
this.draggable.revertDrag();
|
|
@@ -85,7 +129,7 @@ class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
85
129
|
this.updateOutOfBoundsState(event);
|
|
86
130
|
if (this.draggable instanceof Blockly.BlockSvg) {
|
|
87
131
|
const event = new BlockDragEnd(
|
|
88
|
-
this.getDragRoot(this.draggable),
|
|
132
|
+
this.getDragRoot(this.draggable) as Blockly.BlockSvg,
|
|
89
133
|
this.draggedOutOfBounds
|
|
90
134
|
);
|
|
91
135
|
Blockly.Events.fire(event);
|
|
@@ -95,14 +139,25 @@ class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
95
139
|
// deleted.
|
|
96
140
|
if (this.originatedFromFlyout && this.draggedOutOfBounds) {
|
|
97
141
|
Blockly.renderManagement.finishQueuedRenders().then(() => {
|
|
98
|
-
this.getDragRoot(this.draggable)
|
|
142
|
+
const rootBlock = this.getDragRoot(this.draggable);
|
|
143
|
+
if (rootBlock instanceof Blockly.BlockSvg) {
|
|
144
|
+
rootBlock.dispose();
|
|
145
|
+
}
|
|
99
146
|
});
|
|
100
147
|
}
|
|
101
148
|
}
|
|
102
149
|
this.workspace.removeClass(BOUNDLESS_CLASS);
|
|
103
150
|
}
|
|
104
151
|
|
|
105
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Returns whether or not the dragged item should return to its starting
|
|
154
|
+
* position.
|
|
155
|
+
*
|
|
156
|
+
* @param event The drag event that triggered this check.
|
|
157
|
+
* @param rootDraggable The topmost item being dragged.
|
|
158
|
+
* @returns True if the draggable should return to its starting position.
|
|
159
|
+
*/
|
|
160
|
+
shouldReturnToStart(event: PointerEvent, rootDraggable: Blockly.IDraggable) {
|
|
106
161
|
// If a block is dragged out of the workspace to be e.g. dropped on another
|
|
107
162
|
// sprite, it should remain in the same place on the workspace where it was,
|
|
108
163
|
// rather than being moved to an invisible part of the workspace.
|
|
@@ -111,18 +166,32 @@ class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
111
166
|
);
|
|
112
167
|
}
|
|
113
168
|
|
|
114
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Returns the root element being dragged. For shadow blocks, this is the
|
|
171
|
+
* parent block.
|
|
172
|
+
*
|
|
173
|
+
* @param draggable The element being dragged directly.
|
|
174
|
+
* @returns The element being dragged, or its parent.
|
|
175
|
+
*/
|
|
176
|
+
getDragRoot(draggable: Blockly.IDraggable) {
|
|
115
177
|
// We can't just use getRootBlock() here because, when blocks are detached
|
|
116
178
|
// from a stack via dragging, getRootBlock() still returns the root of that
|
|
117
179
|
// stack.
|
|
118
|
-
if (
|
|
119
|
-
return
|
|
180
|
+
if (draggable instanceof Blockly.BlockSvg && draggable.isShadow()) {
|
|
181
|
+
return draggable.getParent();
|
|
120
182
|
}
|
|
121
183
|
|
|
122
|
-
return
|
|
184
|
+
return draggable;
|
|
123
185
|
}
|
|
124
186
|
|
|
125
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Returns whether or not the given event occurred within the bounds of the
|
|
189
|
+
* workspace.
|
|
190
|
+
*
|
|
191
|
+
* @param event The event to check.
|
|
192
|
+
* @returns True if the event occurred inside the workspace.
|
|
193
|
+
*/
|
|
194
|
+
isInsideWorkspace(event: PointerEvent) {
|
|
126
195
|
const bounds = this.workspace.getParentSvg().getBoundingClientRect();
|
|
127
196
|
const workspaceRect = new Blockly.utils.Rect(
|
|
128
197
|
bounds.top,
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
import * as Blockly from "blockly/core";
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Class that provides storage for variables.
|
|
11
|
+
*/
|
|
9
12
|
class ScratchVariableMap extends Blockly.VariableMap {
|
|
10
|
-
getVariable(name, type) {
|
|
13
|
+
getVariable(name: string, type: string) {
|
|
11
14
|
// Variable names in Blockly are case-insensitive, but case sensitive in
|
|
12
15
|
// Scratch. Override the implementation to only return a variable whose name
|
|
13
16
|
// is identical to the one requested.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2024 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as Blockly from "blockly/core";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Class that represents a variable with extra fields for Scratch.
|
|
11
|
+
*/
|
|
12
|
+
export class ScratchVariableModel extends Blockly.VariableModel {
|
|
13
|
+
constructor(
|
|
14
|
+
workspace: Blockly.Workspace,
|
|
15
|
+
name: string,
|
|
16
|
+
type: string,
|
|
17
|
+
id: string,
|
|
18
|
+
public isLocal = false,
|
|
19
|
+
public isCloud = false
|
|
20
|
+
) {
|
|
21
|
+
super(workspace, name, type, id);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Blockly.registry.register(
|
|
26
|
+
Blockly.registry.Type.VARIABLE_MODEL,
|
|
27
|
+
Blockly.registry.DEFAULT,
|
|
28
|
+
ScratchVariableModel,
|
|
29
|
+
true
|
|
30
|
+
);
|
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as Blockly from "blockly/core";
|
|
8
|
-
import { Colours } from "./colours
|
|
8
|
+
import { Colours } from "./colours";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Creates an SVG filter to apply drop shadows to blocks being dragged and
|
|
12
|
+
* inserts it into the DOM.
|
|
13
|
+
*/
|
|
14
|
+
export function buildShadowFilter(workspace: Blockly.WorkspaceSvg) {
|
|
11
15
|
const svg = workspace.getParentSvg();
|
|
12
16
|
const defs = Blockly.utils.dom.createSvgElement(
|
|
13
17
|
Blockly.utils.Svg.DEFS,
|
|
@@ -15,7 +19,7 @@ export function buildShadowFilter(workspace) {
|
|
|
15
19
|
svg
|
|
16
20
|
);
|
|
17
21
|
// Adjust these width/height, x/y properties to stop the shadow from clipping
|
|
18
|
-
|
|
22
|
+
const dragShadowFilter = Blockly.utils.dom.createSvgElement(
|
|
19
23
|
"filter",
|
|
20
24
|
{
|
|
21
25
|
id: "blocklyDragShadowFilter",
|
|
@@ -34,7 +38,7 @@ export function buildShadowFilter(workspace) {
|
|
|
34
38
|
},
|
|
35
39
|
dragShadowFilter
|
|
36
40
|
);
|
|
37
|
-
|
|
41
|
+
const componentTransfer = Blockly.utils.dom.createSvgElement(
|
|
38
42
|
"feComponentTransfer",
|
|
39
43
|
{ result: "offsetBlur" },
|
|
40
44
|
dragShadowFilter
|
|
@@ -33,42 +33,37 @@ import * as Blockly from "blockly/core";
|
|
|
33
33
|
export class StatusIndicatorLabel extends Blockly.FlyoutButton {
|
|
34
34
|
/**
|
|
35
35
|
* The ID of the Scratch extension whose status is indicated by this label.
|
|
36
|
-
* @type {string}
|
|
37
36
|
*/
|
|
38
|
-
extensionId;
|
|
37
|
+
extensionId: string;
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* DOM element that displays the status indicator dot.
|
|
42
|
-
* @type {!SVGImageElement}
|
|
43
41
|
*/
|
|
44
|
-
imageElement;
|
|
42
|
+
imageElement: SVGImageElement;
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
45
|
* Opaque data for mouse up listener used to unbind it in dispose().
|
|
48
|
-
* @type {!Blockly.browserEvents.Data}
|
|
49
46
|
*/
|
|
50
|
-
|
|
47
|
+
mouseUpWrapper: Blockly.browserEvents.Data;
|
|
51
48
|
|
|
52
49
|
/**
|
|
53
50
|
* Function to be invoked when the status indicator is clicked.
|
|
54
|
-
* @type {?Function}
|
|
55
51
|
*/
|
|
56
|
-
static statusButtonCallback;
|
|
52
|
+
static statusButtonCallback: (extensionId: string) => void;
|
|
57
53
|
|
|
58
54
|
/**
|
|
59
55
|
* Creates a new StatusIndicatorLabel.
|
|
60
56
|
*
|
|
61
|
-
* @param
|
|
62
|
-
*
|
|
63
|
-
* @param
|
|
64
|
-
* workspace.
|
|
65
|
-
* @param {!Element} xml The XML specifying the header.
|
|
57
|
+
* @param workspace The workspace in which to place this header.
|
|
58
|
+
* @param targetWorkspace The flyout's target workspace.
|
|
59
|
+
* @param json The JSON specifying the header.
|
|
66
60
|
*/
|
|
67
|
-
constructor(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
constructor(
|
|
62
|
+
workspace: Blockly.WorkspaceSvg,
|
|
63
|
+
targetWorkspace: Blockly.WorkspaceSvg,
|
|
64
|
+
json: Blockly.utils.toolbox.LabelInfo
|
|
65
|
+
) {
|
|
66
|
+
super(workspace, targetWorkspace, json, true);
|
|
72
67
|
this.extensionId = json["id"];
|
|
73
68
|
|
|
74
69
|
const heightDelta = 40 - this.height;
|
|
@@ -76,7 +71,7 @@ export class StatusIndicatorLabel extends Blockly.FlyoutButton {
|
|
|
76
71
|
const text = this.getSvgRoot().querySelector("text");
|
|
77
72
|
const previousY = Number(text.getAttribute("y"));
|
|
78
73
|
|
|
79
|
-
text.setAttribute("y", previousY + heightDelta / 2);
|
|
74
|
+
text.setAttribute("y", `${previousY + heightDelta / 2}`);
|
|
80
75
|
|
|
81
76
|
const statusButtonWidth = 30;
|
|
82
77
|
const marginX = 20;
|
|
@@ -88,7 +83,6 @@ export class StatusIndicatorLabel extends Blockly.FlyoutButton {
|
|
|
88
83
|
? marginX - flyoutWidth + statusButtonWidth
|
|
89
84
|
: (flyoutWidth - statusButtonWidth - marginX) / workspace.scale;
|
|
90
85
|
|
|
91
|
-
/** @type {SVGElement} */
|
|
92
86
|
this.imageElement = Blockly.utils.dom.createSvgElement(
|
|
93
87
|
"image",
|
|
94
88
|
{
|
|
@@ -140,31 +134,25 @@ export class StatusIndicatorLabel extends Blockly.FlyoutButton {
|
|
|
140
134
|
|
|
141
135
|
/**
|
|
142
136
|
* Set the source URL of the image for the button.
|
|
143
|
-
* @param
|
|
137
|
+
* @param src New source.
|
|
144
138
|
* @package
|
|
145
139
|
*/
|
|
146
|
-
setImageSrc(src) {
|
|
147
|
-
if (src === null) {
|
|
148
|
-
// No change if null.
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
this.imageSrc = src;
|
|
140
|
+
setImageSrc(src: string) {
|
|
152
141
|
if (this.imageElement) {
|
|
153
142
|
this.imageElement.setAttributeNS(
|
|
154
143
|
"http://www.w3.org/1999/xlink",
|
|
155
144
|
"xlink:href",
|
|
156
|
-
|
|
145
|
+
src
|
|
157
146
|
);
|
|
158
147
|
}
|
|
159
148
|
}
|
|
160
149
|
|
|
161
150
|
/**
|
|
162
151
|
* Gets the extension state. Overridden externally.
|
|
163
|
-
* @param
|
|
164
|
-
* @return
|
|
165
|
-
* @public
|
|
152
|
+
* @param extensionId The ID of the extension in question.
|
|
153
|
+
* @return The state of the extension.
|
|
166
154
|
*/
|
|
167
|
-
getExtensionState(extensionId) {
|
|
155
|
+
getExtensionState(extensionId: string): StatusButtonState {
|
|
168
156
|
return StatusButtonState.NOT_READY;
|
|
169
157
|
}
|
|
170
158
|
|
|
@@ -180,7 +168,7 @@ export class StatusIndicatorLabel extends Blockly.FlyoutButton {
|
|
|
180
168
|
/**
|
|
181
169
|
* Set of available states for a status indicator.
|
|
182
170
|
*/
|
|
183
|
-
export
|
|
184
|
-
READY
|
|
185
|
-
NOT_READY
|
|
186
|
-
}
|
|
171
|
+
export enum StatusButtonState {
|
|
172
|
+
READY = "ready",
|
|
173
|
+
NOT_READY = "not ready",
|
|
174
|
+
}
|
package/src/{status_indicator_label_flyout_inflater.js → status_indicator_label_flyout_inflater.ts}
RENAMED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as Blockly from "blockly/core";
|
|
8
|
-
import { StatusIndicatorLabel } from "./status_indicator_label
|
|
8
|
+
import { StatusIndicatorLabel } from "./status_indicator_label";
|
|
9
|
+
|
|
10
|
+
export const STATUS_INDICATOR_LABEL_TYPE = "status_indicator_label";
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Flyout inflater responsible for creating status indicator labels.
|
|
@@ -13,20 +15,22 @@ import { StatusIndicatorLabel } from "./status_indicator_label.js";
|
|
|
13
15
|
class StatusIndicatorLabelFlyoutInflater extends Blockly.LabelFlyoutInflater {
|
|
14
16
|
/**
|
|
15
17
|
* Creates a status indicator label on the flyout from the given state.
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
+
* @param state JSON representation of a status indicator label.
|
|
19
|
+
* @param flyoutWorkspace The workspace to create the
|
|
18
20
|
* label on.
|
|
19
|
-
* @returns
|
|
21
|
+
* @returns The newly created status indicator label.
|
|
20
22
|
*/
|
|
21
|
-
load(
|
|
23
|
+
load(
|
|
24
|
+
state: Blockly.utils.toolbox.LabelInfo,
|
|
25
|
+
flyoutWorkspace: Blockly.WorkspaceSvg
|
|
26
|
+
): Blockly.FlyoutItem {
|
|
22
27
|
const label = new StatusIndicatorLabel(
|
|
23
28
|
flyoutWorkspace,
|
|
24
29
|
flyoutWorkspace.targetWorkspace,
|
|
25
|
-
state
|
|
26
|
-
true
|
|
30
|
+
state
|
|
27
31
|
);
|
|
28
32
|
label.show();
|
|
29
|
-
return label;
|
|
33
|
+
return new Blockly.FlyoutItem(label, STATUS_INDICATOR_LABEL_TYPE, true);
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -36,7 +40,7 @@ class StatusIndicatorLabelFlyoutInflater extends Blockly.LabelFlyoutInflater {
|
|
|
36
40
|
export function registerStatusIndicatorLabelFlyoutInflater() {
|
|
37
41
|
Blockly.registry.register(
|
|
38
42
|
Blockly.registry.Type.FLYOUT_INFLATER,
|
|
39
|
-
|
|
43
|
+
STATUS_INDICATOR_LABEL_TYPE,
|
|
40
44
|
StatusIndicatorLabelFlyoutInflater
|
|
41
45
|
);
|
|
42
46
|
}
|