scratch-blocks 2.0.0-spork.1 → 2.0.0-spork.3
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/package.json +2 -3
- 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.js +2 -2
- package/src/{checkbox_bubble.js → checkbox_bubble.ts} +36 -53
- 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/{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 +59 -60
- package/src/procedures.ts +462 -0
- package/src/{recyclable_block_flyout_inflater.js → recyclable_block_flyout_inflater.ts} +35 -35
- 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.js → scratch_continuous_toolbox.ts} +20 -18
- 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} +9 -7
- package/src/{variables.js → variables.ts} +153 -123
- package/tsconfig.json +4 -2
- package/src/categories.js +0 -15
- 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/renderer/renderer.js +0 -74
- package/src/scratch_blocks_utils.js +0 -148
- package/src/scratch_connection_checker.js +0 -29
- package/src/scratch_variable_model.js +0 -24
- /package/src/{css.js → css.ts} +0 -0
- /package/{continuous-toolbox.d.ts → types/continuous-toolbox.d.ts} +0 -0
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import * as Blockly from "blockly/core";
|
|
22
|
-
import
|
|
23
|
-
import * as
|
|
24
|
-
import
|
|
25
|
-
import {
|
|
22
|
+
import * as Constants from "../constants";
|
|
23
|
+
import * as scratchBlocksUtils from "../scratch_blocks_utils";
|
|
24
|
+
import { renameVariable } from "../variables";
|
|
25
|
+
import type { ScratchFieldVariable } from "../fields/scratch_field_variable";
|
|
26
|
+
import type { ScratchVariableModel } from "../scratch_variable_model";
|
|
26
27
|
|
|
27
28
|
Blockly.Blocks["data_variable"] = {
|
|
28
29
|
/**
|
|
29
30
|
* Block of Variables
|
|
30
|
-
* @this Blockly.Block
|
|
31
31
|
*/
|
|
32
|
-
init: function () {
|
|
32
|
+
init: function (this: Blockly.Block) {
|
|
33
33
|
this.jsonInit({
|
|
34
34
|
message0: "%1",
|
|
35
35
|
lastDummyAlign0: "CENTRE",
|
|
@@ -40,7 +40,6 @@ Blockly.Blocks["data_variable"] = {
|
|
|
40
40
|
allowedVariableType: Constants.SCALAR_VARIABLE_TYPE,
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
|
-
category: Categories.data,
|
|
44
43
|
extensions: [
|
|
45
44
|
"contextMenu_getVariableBlock",
|
|
46
45
|
"colours_data",
|
|
@@ -54,9 +53,8 @@ Blockly.Blocks["data_variable"] = {
|
|
|
54
53
|
Blockly.Blocks["data_setvariableto"] = {
|
|
55
54
|
/**
|
|
56
55
|
* Block to set variable to a certain value
|
|
57
|
-
* @this Blockly.Block
|
|
58
56
|
*/
|
|
59
|
-
init: function () {
|
|
57
|
+
init: function (this: Blockly.Block) {
|
|
60
58
|
this.jsonInit({
|
|
61
59
|
message0: Blockly.Msg.DATA_SETVARIABLETO,
|
|
62
60
|
args0: [
|
|
@@ -71,7 +69,6 @@ Blockly.Blocks["data_setvariableto"] = {
|
|
|
71
69
|
name: "VALUE",
|
|
72
70
|
},
|
|
73
71
|
],
|
|
74
|
-
category: Categories.data,
|
|
75
72
|
extensions: ["colours_data", "shape_statement"],
|
|
76
73
|
});
|
|
77
74
|
},
|
|
@@ -80,9 +77,8 @@ Blockly.Blocks["data_setvariableto"] = {
|
|
|
80
77
|
Blockly.Blocks["data_changevariableby"] = {
|
|
81
78
|
/**
|
|
82
79
|
* Block to change variable by a certain value
|
|
83
|
-
* @this Blockly.Block
|
|
84
80
|
*/
|
|
85
|
-
init: function () {
|
|
81
|
+
init: function (this: Blockly.Block) {
|
|
86
82
|
this.jsonInit({
|
|
87
83
|
message0: Blockly.Msg.DATA_CHANGEVARIABLEBY,
|
|
88
84
|
args0: [
|
|
@@ -97,7 +93,6 @@ Blockly.Blocks["data_changevariableby"] = {
|
|
|
97
93
|
name: "VALUE",
|
|
98
94
|
},
|
|
99
95
|
],
|
|
100
|
-
category: Categories.data,
|
|
101
96
|
extensions: ["colours_data", "shape_statement"],
|
|
102
97
|
});
|
|
103
98
|
},
|
|
@@ -106,9 +101,8 @@ Blockly.Blocks["data_changevariableby"] = {
|
|
|
106
101
|
Blockly.Blocks["data_showvariable"] = {
|
|
107
102
|
/**
|
|
108
103
|
* Block to show a variable
|
|
109
|
-
* @this Blockly.Block
|
|
110
104
|
*/
|
|
111
|
-
init: function () {
|
|
105
|
+
init: function (this: Blockly.Block) {
|
|
112
106
|
this.jsonInit({
|
|
113
107
|
message0: Blockly.Msg.DATA_SHOWVARIABLE,
|
|
114
108
|
args0: [
|
|
@@ -121,7 +115,6 @@ Blockly.Blocks["data_showvariable"] = {
|
|
|
121
115
|
],
|
|
122
116
|
previousStatement: null,
|
|
123
117
|
nextStatement: null,
|
|
124
|
-
category: Categories.data,
|
|
125
118
|
extensions: ["colours_data"],
|
|
126
119
|
});
|
|
127
120
|
},
|
|
@@ -130,9 +123,8 @@ Blockly.Blocks["data_showvariable"] = {
|
|
|
130
123
|
Blockly.Blocks["data_hidevariable"] = {
|
|
131
124
|
/**
|
|
132
125
|
* Block to hide a variable
|
|
133
|
-
* @this Blockly.Block
|
|
134
126
|
*/
|
|
135
|
-
init: function () {
|
|
127
|
+
init: function (this: Blockly.Block) {
|
|
136
128
|
this.jsonInit({
|
|
137
129
|
message0: Blockly.Msg.DATA_HIDEVARIABLE,
|
|
138
130
|
args0: [
|
|
@@ -145,7 +137,6 @@ Blockly.Blocks["data_hidevariable"] = {
|
|
|
145
137
|
],
|
|
146
138
|
previousStatement: null,
|
|
147
139
|
nextStatement: null,
|
|
148
|
-
category: Categories.data,
|
|
149
140
|
extensions: ["colours_data"],
|
|
150
141
|
});
|
|
151
142
|
},
|
|
@@ -154,9 +145,8 @@ Blockly.Blocks["data_hidevariable"] = {
|
|
|
154
145
|
Blockly.Blocks["data_listcontents"] = {
|
|
155
146
|
/**
|
|
156
147
|
* List reporter.
|
|
157
|
-
* @this Blockly.Block
|
|
158
148
|
*/
|
|
159
|
-
init: function () {
|
|
149
|
+
init: function (this: Blockly.Block) {
|
|
160
150
|
this.jsonInit({
|
|
161
151
|
message0: "%1",
|
|
162
152
|
args0: [
|
|
@@ -166,7 +156,6 @@ Blockly.Blocks["data_listcontents"] = {
|
|
|
166
156
|
allowedVariableType: Constants.LIST_VARIABLE_TYPE,
|
|
167
157
|
},
|
|
168
158
|
],
|
|
169
|
-
category: Categories.dataLists,
|
|
170
159
|
extensions: [
|
|
171
160
|
"contextMenu_getListBlock",
|
|
172
161
|
"colours_data_lists",
|
|
@@ -180,9 +169,8 @@ Blockly.Blocks["data_listcontents"] = {
|
|
|
180
169
|
Blockly.Blocks["data_listindexall"] = {
|
|
181
170
|
/**
|
|
182
171
|
* List index menu, with all option.
|
|
183
|
-
* @this Blockly.Block
|
|
184
172
|
*/
|
|
185
|
-
init: function () {
|
|
173
|
+
init: function (this: Blockly.Block) {
|
|
186
174
|
this.jsonInit({
|
|
187
175
|
message0: "%1",
|
|
188
176
|
args0: [
|
|
@@ -199,7 +187,6 @@ Blockly.Blocks["data_listindexall"] = {
|
|
|
199
187
|
],
|
|
200
188
|
},
|
|
201
189
|
],
|
|
202
|
-
category: Categories.data,
|
|
203
190
|
extensions: ["colours_textfield", "output_string"],
|
|
204
191
|
});
|
|
205
192
|
},
|
|
@@ -208,9 +195,8 @@ Blockly.Blocks["data_listindexall"] = {
|
|
|
208
195
|
Blockly.Blocks["data_listindexrandom"] = {
|
|
209
196
|
/**
|
|
210
197
|
* List index menu, with random option.
|
|
211
|
-
* @this Blockly.Block
|
|
212
198
|
*/
|
|
213
|
-
init: function () {
|
|
199
|
+
init: function (this: Blockly.Block) {
|
|
214
200
|
this.jsonInit({
|
|
215
201
|
message0: "%1",
|
|
216
202
|
args0: [
|
|
@@ -227,7 +213,6 @@ Blockly.Blocks["data_listindexrandom"] = {
|
|
|
227
213
|
],
|
|
228
214
|
},
|
|
229
215
|
],
|
|
230
|
-
category: Categories.data,
|
|
231
216
|
extensions: ["colours_textfield", "output_string"],
|
|
232
217
|
});
|
|
233
218
|
},
|
|
@@ -236,9 +221,8 @@ Blockly.Blocks["data_listindexrandom"] = {
|
|
|
236
221
|
Blockly.Blocks["data_addtolist"] = {
|
|
237
222
|
/**
|
|
238
223
|
* Block to add item to list.
|
|
239
|
-
* @this Blockly.Block
|
|
240
224
|
*/
|
|
241
|
-
init: function () {
|
|
225
|
+
init: function (this: Blockly.Block) {
|
|
242
226
|
this.jsonInit({
|
|
243
227
|
message0: Blockly.Msg.DATA_ADDTOLIST,
|
|
244
228
|
args0: [
|
|
@@ -253,7 +237,6 @@ Blockly.Blocks["data_addtolist"] = {
|
|
|
253
237
|
defaultType: Constants.LIST_VARIABLE_TYPE,
|
|
254
238
|
},
|
|
255
239
|
],
|
|
256
|
-
category: Categories.dataLists,
|
|
257
240
|
extensions: ["colours_data_lists", "shape_statement"],
|
|
258
241
|
});
|
|
259
242
|
},
|
|
@@ -262,9 +245,8 @@ Blockly.Blocks["data_addtolist"] = {
|
|
|
262
245
|
Blockly.Blocks["data_deleteoflist"] = {
|
|
263
246
|
/**
|
|
264
247
|
* Block to delete item from list.
|
|
265
|
-
* @this Blockly.Block
|
|
266
248
|
*/
|
|
267
|
-
init: function () {
|
|
249
|
+
init: function (this: Blockly.Block) {
|
|
268
250
|
this.jsonInit({
|
|
269
251
|
message0: Blockly.Msg.DATA_DELETEOFLIST,
|
|
270
252
|
args0: [
|
|
@@ -279,7 +261,6 @@ Blockly.Blocks["data_deleteoflist"] = {
|
|
|
279
261
|
defaultType: Constants.LIST_VARIABLE_TYPE,
|
|
280
262
|
},
|
|
281
263
|
],
|
|
282
|
-
category: Categories.dataLists,
|
|
283
264
|
extensions: ["colours_data_lists", "shape_statement"],
|
|
284
265
|
});
|
|
285
266
|
},
|
|
@@ -288,9 +269,8 @@ Blockly.Blocks["data_deleteoflist"] = {
|
|
|
288
269
|
Blockly.Blocks["data_deletealloflist"] = {
|
|
289
270
|
/**
|
|
290
271
|
* Block to delete all items from list.
|
|
291
|
-
* @this Blockly.Block
|
|
292
272
|
*/
|
|
293
|
-
init: function () {
|
|
273
|
+
init: function (this: Blockly.Block) {
|
|
294
274
|
this.jsonInit({
|
|
295
275
|
message0: Blockly.Msg.DATA_DELETEALLOFLIST,
|
|
296
276
|
args0: [
|
|
@@ -301,7 +281,6 @@ Blockly.Blocks["data_deletealloflist"] = {
|
|
|
301
281
|
defaultType: Constants.LIST_VARIABLE_TYPE,
|
|
302
282
|
},
|
|
303
283
|
],
|
|
304
|
-
category: Categories.dataLists,
|
|
305
284
|
extensions: ["colours_data_lists", "shape_statement"],
|
|
306
285
|
});
|
|
307
286
|
},
|
|
@@ -310,9 +289,8 @@ Blockly.Blocks["data_deletealloflist"] = {
|
|
|
310
289
|
Blockly.Blocks["data_insertatlist"] = {
|
|
311
290
|
/**
|
|
312
291
|
* Block to insert item to list.
|
|
313
|
-
* @this Blockly.Block
|
|
314
292
|
*/
|
|
315
|
-
init: function () {
|
|
293
|
+
init: function (this: Blockly.Block) {
|
|
316
294
|
this.jsonInit({
|
|
317
295
|
message0: Blockly.Msg.DATA_INSERTATLIST,
|
|
318
296
|
args0: [
|
|
@@ -331,7 +309,6 @@ Blockly.Blocks["data_insertatlist"] = {
|
|
|
331
309
|
defaultType: Constants.LIST_VARIABLE_TYPE,
|
|
332
310
|
},
|
|
333
311
|
],
|
|
334
|
-
category: Categories.dataLists,
|
|
335
312
|
extensions: ["colours_data_lists", "shape_statement"],
|
|
336
313
|
});
|
|
337
314
|
},
|
|
@@ -340,9 +317,8 @@ Blockly.Blocks["data_insertatlist"] = {
|
|
|
340
317
|
Blockly.Blocks["data_replaceitemoflist"] = {
|
|
341
318
|
/**
|
|
342
319
|
* Block to insert item to list.
|
|
343
|
-
* @this Blockly.Block
|
|
344
320
|
*/
|
|
345
|
-
init: function () {
|
|
321
|
+
init: function (this: Blockly.Block) {
|
|
346
322
|
this.jsonInit({
|
|
347
323
|
message0: Blockly.Msg.DATA_REPLACEITEMOFLIST,
|
|
348
324
|
args0: [
|
|
@@ -361,7 +337,6 @@ Blockly.Blocks["data_replaceitemoflist"] = {
|
|
|
361
337
|
name: "ITEM",
|
|
362
338
|
},
|
|
363
339
|
],
|
|
364
|
-
category: Categories.dataLists,
|
|
365
340
|
extensions: ["colours_data_lists", "shape_statement"],
|
|
366
341
|
});
|
|
367
342
|
},
|
|
@@ -370,9 +345,8 @@ Blockly.Blocks["data_replaceitemoflist"] = {
|
|
|
370
345
|
Blockly.Blocks["data_itemoflist"] = {
|
|
371
346
|
/**
|
|
372
347
|
* Block for reporting item of list.
|
|
373
|
-
* @this Blockly.Block
|
|
374
348
|
*/
|
|
375
|
-
init: function () {
|
|
349
|
+
init: function (this: Blockly.Block) {
|
|
376
350
|
this.jsonInit({
|
|
377
351
|
message0: Blockly.Msg.DATA_ITEMOFLIST,
|
|
378
352
|
args0: [
|
|
@@ -388,7 +362,6 @@ Blockly.Blocks["data_itemoflist"] = {
|
|
|
388
362
|
},
|
|
389
363
|
],
|
|
390
364
|
output: null,
|
|
391
|
-
category: Categories.dataLists,
|
|
392
365
|
extensions: ["colours_data_lists"],
|
|
393
366
|
outputShape: Constants.OUTPUT_SHAPE_ROUND,
|
|
394
367
|
});
|
|
@@ -398,9 +371,8 @@ Blockly.Blocks["data_itemoflist"] = {
|
|
|
398
371
|
Blockly.Blocks["data_itemnumoflist"] = {
|
|
399
372
|
/**
|
|
400
373
|
* Block for reporting the item # of a string in a list.
|
|
401
|
-
* @this Blockly.Block
|
|
402
374
|
*/
|
|
403
|
-
init: function () {
|
|
375
|
+
init: function (this: Blockly.Block) {
|
|
404
376
|
this.jsonInit({
|
|
405
377
|
message0: Blockly.Msg.DATA_ITEMNUMOFLIST,
|
|
406
378
|
args0: [
|
|
@@ -416,7 +388,6 @@ Blockly.Blocks["data_itemnumoflist"] = {
|
|
|
416
388
|
},
|
|
417
389
|
],
|
|
418
390
|
output: null,
|
|
419
|
-
category: Categories.dataLists,
|
|
420
391
|
extensions: ["colours_data_lists"],
|
|
421
392
|
outputShape: Constants.OUTPUT_SHAPE_ROUND,
|
|
422
393
|
});
|
|
@@ -426,9 +397,8 @@ Blockly.Blocks["data_itemnumoflist"] = {
|
|
|
426
397
|
Blockly.Blocks["data_lengthoflist"] = {
|
|
427
398
|
/**
|
|
428
399
|
* Block for reporting length of list.
|
|
429
|
-
* @this Blockly.Block
|
|
430
400
|
*/
|
|
431
|
-
init: function () {
|
|
401
|
+
init: function (this: Blockly.Block) {
|
|
432
402
|
this.jsonInit({
|
|
433
403
|
message0: Blockly.Msg.DATA_LENGTHOFLIST,
|
|
434
404
|
args0: [
|
|
@@ -439,7 +409,6 @@ Blockly.Blocks["data_lengthoflist"] = {
|
|
|
439
409
|
defaultType: Constants.LIST_VARIABLE_TYPE,
|
|
440
410
|
},
|
|
441
411
|
],
|
|
442
|
-
category: Categories.dataLists,
|
|
443
412
|
extensions: ["colours_data_lists", "output_number"],
|
|
444
413
|
});
|
|
445
414
|
},
|
|
@@ -448,9 +417,8 @@ Blockly.Blocks["data_lengthoflist"] = {
|
|
|
448
417
|
Blockly.Blocks["data_listcontainsitem"] = {
|
|
449
418
|
/**
|
|
450
419
|
* Block to report whether list contains item.
|
|
451
|
-
* @this Blockly.Block
|
|
452
420
|
*/
|
|
453
|
-
init: function () {
|
|
421
|
+
init: function (this: Blockly.Block) {
|
|
454
422
|
this.jsonInit({
|
|
455
423
|
message0: Blockly.Msg.DATA_LISTCONTAINSITEM,
|
|
456
424
|
args0: [
|
|
@@ -465,7 +433,6 @@ Blockly.Blocks["data_listcontainsitem"] = {
|
|
|
465
433
|
name: "ITEM",
|
|
466
434
|
},
|
|
467
435
|
],
|
|
468
|
-
category: Categories.dataLists,
|
|
469
436
|
extensions: ["colours_data_lists", "output_boolean"],
|
|
470
437
|
});
|
|
471
438
|
},
|
|
@@ -474,9 +441,8 @@ Blockly.Blocks["data_listcontainsitem"] = {
|
|
|
474
441
|
Blockly.Blocks["data_showlist"] = {
|
|
475
442
|
/**
|
|
476
443
|
* Block to show a list.
|
|
477
|
-
* @this Blockly.Block
|
|
478
444
|
*/
|
|
479
|
-
init: function () {
|
|
445
|
+
init: function (this: Blockly.Block) {
|
|
480
446
|
this.jsonInit({
|
|
481
447
|
message0: Blockly.Msg.DATA_SHOWLIST,
|
|
482
448
|
args0: [
|
|
@@ -487,7 +453,6 @@ Blockly.Blocks["data_showlist"] = {
|
|
|
487
453
|
defaultType: Constants.LIST_VARIABLE_TYPE,
|
|
488
454
|
},
|
|
489
455
|
],
|
|
490
|
-
category: Categories.dataLists,
|
|
491
456
|
extensions: ["colours_data_lists", "shape_statement"],
|
|
492
457
|
});
|
|
493
458
|
},
|
|
@@ -496,9 +461,8 @@ Blockly.Blocks["data_showlist"] = {
|
|
|
496
461
|
Blockly.Blocks["data_hidelist"] = {
|
|
497
462
|
/**
|
|
498
463
|
* Block to hide a list.
|
|
499
|
-
* @this Blockly.Block
|
|
500
464
|
*/
|
|
501
|
-
init: function () {
|
|
465
|
+
init: function (this: Blockly.Block) {
|
|
502
466
|
this.jsonInit({
|
|
503
467
|
message0: Blockly.Msg.DATA_HIDELIST,
|
|
504
468
|
args0: [
|
|
@@ -509,7 +473,6 @@ Blockly.Blocks["data_hidelist"] = {
|
|
|
509
473
|
defaultType: Constants.LIST_VARIABLE_TYPE,
|
|
510
474
|
},
|
|
511
475
|
],
|
|
512
|
-
category: Categories.dataLists,
|
|
513
476
|
extensions: ["colours_data_lists", "shape_statement"],
|
|
514
477
|
});
|
|
515
478
|
},
|
|
@@ -518,51 +481,57 @@ Blockly.Blocks["data_hidelist"] = {
|
|
|
518
481
|
/**
|
|
519
482
|
* Mixin to add a context menu for a data_variable block. It adds one item for
|
|
520
483
|
* each variable defined on the workspace.
|
|
521
|
-
* @mixin
|
|
522
|
-
* @augments Blockly.Block
|
|
523
|
-
* @package
|
|
524
|
-
* @readonly
|
|
525
484
|
*/
|
|
526
485
|
const CUSTOM_CONTEXT_MENU_GET_VARIABLE_MIXIN = {
|
|
527
486
|
/**
|
|
528
487
|
* Add context menu option to change the selected variable.
|
|
529
|
-
*
|
|
530
|
-
* @
|
|
488
|
+
*
|
|
489
|
+
* @param options List of menu options to add to.
|
|
531
490
|
*/
|
|
532
|
-
customContextMenu: function (
|
|
533
|
-
|
|
491
|
+
customContextMenu: function (
|
|
492
|
+
this: Blockly.Block,
|
|
493
|
+
options: Array<
|
|
494
|
+
| Blockly.ContextMenuRegistry.ContextMenuOption
|
|
495
|
+
| Blockly.ContextMenuRegistry.LegacyContextMenuOption
|
|
496
|
+
>
|
|
497
|
+
) {
|
|
498
|
+
const fieldName = "VARIABLE";
|
|
534
499
|
if (this.isCollapsed()) {
|
|
535
500
|
return;
|
|
536
501
|
}
|
|
537
|
-
|
|
502
|
+
const currentVarName = (this.getField(fieldName) as ScratchFieldVariable)
|
|
503
|
+
.getVariable()
|
|
504
|
+
.getName();
|
|
538
505
|
if (!this.isInFlyout) {
|
|
539
|
-
|
|
540
|
-
Constants.SCALAR_VARIABLE_TYPE
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
506
|
+
this.workspace
|
|
507
|
+
.getVariablesOfType(Constants.SCALAR_VARIABLE_TYPE)
|
|
508
|
+
.sort(function (
|
|
509
|
+
a: Blockly.IVariableModel<Blockly.IVariableState>,
|
|
510
|
+
b: Blockly.IVariableModel<Blockly.IVariableState>
|
|
511
|
+
) {
|
|
512
|
+
return scratchBlocksUtils.compareStrings(a.getName(), b.getName());
|
|
513
|
+
})
|
|
514
|
+
.forEach((variable: Blockly.IVariableModel<Blockly.IVariableState>) => {
|
|
515
|
+
const varName = variable.getName();
|
|
516
|
+
if (varName === currentVarName) return;
|
|
548
517
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
518
|
+
options.push({
|
|
519
|
+
enabled: true,
|
|
520
|
+
text: varName,
|
|
521
|
+
callback: VARIABLE_OPTION_CALLBACK_FACTORY(
|
|
522
|
+
this,
|
|
523
|
+
variable.getId(),
|
|
524
|
+
fieldName
|
|
525
|
+
),
|
|
526
|
+
});
|
|
527
|
+
});
|
|
559
528
|
} else {
|
|
560
|
-
|
|
529
|
+
const renameOption = {
|
|
561
530
|
text: Blockly.Msg.RENAME_VARIABLE,
|
|
562
531
|
enabled: true,
|
|
563
532
|
callback: RENAME_OPTION_CALLBACK_FACTORY(this, fieldName),
|
|
564
533
|
};
|
|
565
|
-
|
|
534
|
+
const deleteOption = {
|
|
566
535
|
text: Blockly.Msg.DELETE_VARIABLE.replace("%1", currentVarName),
|
|
567
536
|
enabled: true,
|
|
568
537
|
callback: DELETE_OPTION_CALLBACK_FACTORY(this, fieldName),
|
|
@@ -581,51 +550,57 @@ Blockly.Extensions.registerMixin(
|
|
|
581
550
|
/**
|
|
582
551
|
* Mixin to add a context menu for a data_listcontents block. It adds one item for
|
|
583
552
|
* each list defined on the workspace.
|
|
584
|
-
* @mixin
|
|
585
|
-
* @augments Blockly.Block
|
|
586
|
-
* @package
|
|
587
|
-
* @readonly
|
|
588
553
|
*/
|
|
589
554
|
const CUSTOM_CONTEXT_MENU_GET_LIST_MIXIN = {
|
|
590
555
|
/**
|
|
591
556
|
* Add context menu option to change the selected list.
|
|
592
|
-
*
|
|
593
|
-
* @
|
|
557
|
+
*
|
|
558
|
+
* @param options List of menu options to add to.
|
|
594
559
|
*/
|
|
595
|
-
customContextMenu: function (
|
|
596
|
-
|
|
560
|
+
customContextMenu: function (
|
|
561
|
+
this: Blockly.Block,
|
|
562
|
+
options: Array<
|
|
563
|
+
| Blockly.ContextMenuRegistry.ContextMenuOption
|
|
564
|
+
| Blockly.ContextMenuRegistry.LegacyContextMenuOption
|
|
565
|
+
>
|
|
566
|
+
) {
|
|
567
|
+
const fieldName = "LIST";
|
|
597
568
|
if (this.isCollapsed()) {
|
|
598
569
|
return;
|
|
599
570
|
}
|
|
600
|
-
|
|
571
|
+
const currentVarName = (this.getField(fieldName) as ScratchFieldVariable)
|
|
572
|
+
.getVariable()
|
|
573
|
+
.getName();
|
|
601
574
|
if (!this.isInFlyout) {
|
|
602
|
-
|
|
603
|
-
Constants.LIST_VARIABLE_TYPE
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
option.text = varName;
|
|
575
|
+
this.workspace
|
|
576
|
+
.getVariablesOfType(Constants.LIST_VARIABLE_TYPE)
|
|
577
|
+
.sort(function (
|
|
578
|
+
a: Blockly.IVariableModel<Blockly.IVariableState>,
|
|
579
|
+
b: Blockly.IVariableModel<Blockly.IVariableState>
|
|
580
|
+
) {
|
|
581
|
+
return scratchBlocksUtils.compareStrings(a.getName(), b.getName());
|
|
582
|
+
})
|
|
583
|
+
.forEach((variable: Blockly.IVariableModel<Blockly.IVariableState>) => {
|
|
584
|
+
const varName = variable.getName();
|
|
585
|
+
if (varName === currentVarName) return;
|
|
614
586
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
587
|
+
options.push({
|
|
588
|
+
enabled: true,
|
|
589
|
+
text: varName,
|
|
590
|
+
callback: VARIABLE_OPTION_CALLBACK_FACTORY(
|
|
591
|
+
this,
|
|
592
|
+
variable.getId(),
|
|
593
|
+
fieldName
|
|
594
|
+
),
|
|
595
|
+
});
|
|
596
|
+
});
|
|
622
597
|
} else {
|
|
623
|
-
|
|
598
|
+
const renameOption = {
|
|
624
599
|
text: Blockly.Msg.RENAME_LIST,
|
|
625
600
|
enabled: true,
|
|
626
601
|
callback: RENAME_OPTION_CALLBACK_FACTORY(this, fieldName),
|
|
627
602
|
};
|
|
628
|
-
|
|
603
|
+
const deleteOption = {
|
|
629
604
|
text: Blockly.Msg.DELETE_LIST.replace("%1", currentVarName),
|
|
630
605
|
enabled: true,
|
|
631
606
|
callback: DELETE_OPTION_CALLBACK_FACTORY(this, fieldName),
|
|
@@ -645,14 +620,19 @@ Blockly.Extensions.registerMixin(
|
|
|
645
620
|
* block. Each variable on the workspace gets its own item in the dropdown
|
|
646
621
|
* menu, and clicking on that item changes the text of the field on the source
|
|
647
622
|
* block.
|
|
648
|
-
*
|
|
649
|
-
* @param
|
|
650
|
-
* @param
|
|
651
|
-
* @
|
|
623
|
+
*
|
|
624
|
+
* @param block The block to update.
|
|
625
|
+
* @param id The id of the variable to set on this block.
|
|
626
|
+
* @param fieldName The name of the field to update on the block.
|
|
627
|
+
* @returns A function that updates the block with the new name.
|
|
652
628
|
*/
|
|
653
|
-
const VARIABLE_OPTION_CALLBACK_FACTORY = function (
|
|
654
|
-
|
|
655
|
-
|
|
629
|
+
const VARIABLE_OPTION_CALLBACK_FACTORY = function (
|
|
630
|
+
block: Blockly.Block,
|
|
631
|
+
id: string,
|
|
632
|
+
fieldName: string
|
|
633
|
+
): () => void {
|
|
634
|
+
return () => {
|
|
635
|
+
const variableField = block.getField(fieldName);
|
|
656
636
|
if (!variableField) {
|
|
657
637
|
console.log("Tried to get a variable field on the wrong type of block.");
|
|
658
638
|
}
|
|
@@ -663,28 +643,40 @@ const VARIABLE_OPTION_CALLBACK_FACTORY = function (block, id, fieldName) {
|
|
|
663
643
|
/**
|
|
664
644
|
* Callback for rename variable dropdown menu option associated with a
|
|
665
645
|
* variable getter block.
|
|
666
|
-
*
|
|
667
|
-
* @param
|
|
668
|
-
* @
|
|
646
|
+
*
|
|
647
|
+
* @param block The block with the variable to rename.
|
|
648
|
+
* @param fieldName The name of the field to inspect on the block.
|
|
649
|
+
* @returns A function that renames the variable.
|
|
669
650
|
*/
|
|
670
|
-
const RENAME_OPTION_CALLBACK_FACTORY = function (
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
651
|
+
const RENAME_OPTION_CALLBACK_FACTORY = function (
|
|
652
|
+
block: Blockly.Block,
|
|
653
|
+
fieldName: string
|
|
654
|
+
): () => void {
|
|
655
|
+
return () => {
|
|
656
|
+
const workspace = block.workspace;
|
|
657
|
+
const variable = (
|
|
658
|
+
block.getField(fieldName) as ScratchFieldVariable
|
|
659
|
+
).getVariable() as ScratchVariableModel;
|
|
660
|
+
renameVariable(workspace as Blockly.WorkspaceSvg, variable);
|
|
675
661
|
};
|
|
676
662
|
};
|
|
677
663
|
|
|
678
664
|
/**
|
|
679
665
|
* Callback for delete variable dropdown menu option associated with a
|
|
680
666
|
* variable getter block.
|
|
681
|
-
*
|
|
682
|
-
* @param
|
|
683
|
-
* @
|
|
667
|
+
*
|
|
668
|
+
* @param block The block with the variable to delete.
|
|
669
|
+
* @param fieldName The name of the field to inspect on the block.
|
|
670
|
+
* @return A function that deletes the variable.
|
|
684
671
|
*/
|
|
685
|
-
const DELETE_OPTION_CALLBACK_FACTORY = function (
|
|
686
|
-
|
|
687
|
-
|
|
672
|
+
const DELETE_OPTION_CALLBACK_FACTORY = function (
|
|
673
|
+
block: Blockly.Block,
|
|
674
|
+
fieldName: string
|
|
675
|
+
): () => void {
|
|
676
|
+
return () => {
|
|
677
|
+
const variable = (
|
|
678
|
+
block.getField(fieldName) as ScratchFieldVariable
|
|
679
|
+
).getVariable();
|
|
688
680
|
Blockly.Variables.deleteVariable(variable.getWorkspace(), variable, block);
|
|
689
681
|
};
|
|
690
682
|
};
|