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
|
@@ -22,35 +22,31 @@
|
|
|
22
22
|
* @fileoverview Data Flyout components including variable and list blocks.
|
|
23
23
|
* @author marisaleung@google.com (Marisa Leung)
|
|
24
24
|
*/
|
|
25
|
-
"use strict";
|
|
26
25
|
|
|
27
|
-
/**
|
|
28
|
-
* @name Blockly.DataCategory
|
|
29
|
-
* @namespace
|
|
30
|
-
**/
|
|
31
26
|
import * as Blockly from "blockly/core";
|
|
32
|
-
import { createVariable } from "./variables
|
|
33
|
-
import { LIST_VARIABLE_TYPE, SCALAR_VARIABLE_TYPE } from "./constants
|
|
27
|
+
import { createVariable } from "./variables";
|
|
28
|
+
import { LIST_VARIABLE_TYPE, SCALAR_VARIABLE_TYPE } from "./constants";
|
|
34
29
|
|
|
35
30
|
/**
|
|
36
31
|
* Construct the blocks required by the flyout for the variable category.
|
|
37
|
-
*
|
|
38
|
-
* @
|
|
32
|
+
*
|
|
33
|
+
* @param workspace The workspace containing variables.
|
|
34
|
+
* @returns Array of XML block elements.
|
|
39
35
|
*/
|
|
40
|
-
export function getVariablesCategory(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
export function getVariablesCategory(
|
|
37
|
+
workspace: Blockly.WorkspaceSvg
|
|
38
|
+
): Element[] {
|
|
39
|
+
const scalarVariables = workspace.getVariablesOfType(SCALAR_VARIABLE_TYPE);
|
|
40
|
+
scalarVariables.sort(Blockly.Variables.compareByName);
|
|
41
|
+
const xmlList: Element[] = [];
|
|
44
42
|
|
|
45
43
|
addCreateButton(xmlList, workspace, "VARIABLE");
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
addDataVariable(xmlList, variableModelList[i]);
|
|
49
|
-
}
|
|
45
|
+
scalarVariables.forEach((variable) => addDataVariable(xmlList, variable));
|
|
50
46
|
|
|
51
|
-
if (
|
|
52
|
-
xmlList[xmlList.length - 1].setAttribute("gap", 24);
|
|
53
|
-
|
|
47
|
+
if (scalarVariables.length > 0) {
|
|
48
|
+
xmlList[xmlList.length - 1].setAttribute("gap", "24");
|
|
49
|
+
const firstVariable = scalarVariables[0];
|
|
54
50
|
|
|
55
51
|
addSetVariableTo(xmlList, firstVariable);
|
|
56
52
|
addChangeVariableBy(xmlList, firstVariable);
|
|
@@ -60,15 +56,13 @@ export function getVariablesCategory(workspace) {
|
|
|
60
56
|
|
|
61
57
|
// Now add list variables to the flyout
|
|
62
58
|
addCreateButton(xmlList, workspace, "LIST");
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
addDataList(xmlList, variableModelList[i]);
|
|
67
|
-
}
|
|
59
|
+
const listVariables = workspace.getVariablesOfType(LIST_VARIABLE_TYPE);
|
|
60
|
+
listVariables.sort(Blockly.Variables.compareByName);
|
|
61
|
+
listVariables.forEach((variable) => addDataList(xmlList, variable));
|
|
68
62
|
|
|
69
|
-
if (
|
|
70
|
-
xmlList[xmlList.length - 1].setAttribute("gap", 24);
|
|
71
|
-
|
|
63
|
+
if (listVariables.length > 0) {
|
|
64
|
+
xmlList[xmlList.length - 1].setAttribute("gap", "24");
|
|
65
|
+
const firstVariable = listVariables[0];
|
|
72
66
|
|
|
73
67
|
addAddToList(xmlList, firstVariable);
|
|
74
68
|
addSep(xmlList);
|
|
@@ -91,10 +85,14 @@ export function getVariablesCategory(workspace) {
|
|
|
91
85
|
|
|
92
86
|
/**
|
|
93
87
|
* Construct and add a data_variable block to xmlList.
|
|
94
|
-
*
|
|
95
|
-
* @param
|
|
88
|
+
*
|
|
89
|
+
* @param xmlList Array of XML block elements.
|
|
90
|
+
* @param variable Variable to select in the field.
|
|
96
91
|
*/
|
|
97
|
-
function addDataVariable(
|
|
92
|
+
function addDataVariable(
|
|
93
|
+
xmlList: Element[],
|
|
94
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
95
|
+
) {
|
|
98
96
|
// <block id="variableId" type="data_variable">
|
|
99
97
|
// <field name="VARIABLE">variablename</field>
|
|
100
98
|
// </block>
|
|
@@ -105,10 +103,14 @@ function addDataVariable(xmlList, variable) {
|
|
|
105
103
|
|
|
106
104
|
/**
|
|
107
105
|
* Construct and add a data_setvariableto block to xmlList.
|
|
108
|
-
*
|
|
109
|
-
* @param
|
|
106
|
+
*
|
|
107
|
+
* @param xmlList Array of XML block elements.
|
|
108
|
+
* @param variable Variable to select in the field.
|
|
110
109
|
*/
|
|
111
|
-
function addSetVariableTo(
|
|
110
|
+
function addSetVariableTo(
|
|
111
|
+
xmlList: Element[],
|
|
112
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
113
|
+
) {
|
|
112
114
|
// <block type="data_setvariableto" gap="20">
|
|
113
115
|
// <value name="VARIABLE">
|
|
114
116
|
// <shadow type="data_variablemenu"></shadow>
|
|
@@ -122,16 +124,20 @@ function addSetVariableTo(xmlList, variable) {
|
|
|
122
124
|
addBlock(xmlList, variable, "data_setvariableto", "VARIABLE", [
|
|
123
125
|
"VALUE",
|
|
124
126
|
"text",
|
|
125
|
-
0,
|
|
127
|
+
"0",
|
|
126
128
|
]);
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
/**
|
|
130
132
|
* Construct and add a data_changevariableby block to xmlList.
|
|
131
|
-
*
|
|
132
|
-
* @param
|
|
133
|
+
*
|
|
134
|
+
* @param xmlList Array of XML block elements.
|
|
135
|
+
* @param variable Variable to select in the field.
|
|
133
136
|
*/
|
|
134
|
-
function addChangeVariableBy(
|
|
137
|
+
function addChangeVariableBy(
|
|
138
|
+
xmlList: Element[],
|
|
139
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
140
|
+
) {
|
|
135
141
|
// <block type="data_changevariableby">
|
|
136
142
|
// <value name="VARIABLE">
|
|
137
143
|
// <shadow type="data_variablemenu"></shadow>
|
|
@@ -145,16 +151,20 @@ function addChangeVariableBy(xmlList, variable) {
|
|
|
145
151
|
addBlock(xmlList, variable, "data_changevariableby", "VARIABLE", [
|
|
146
152
|
"VALUE",
|
|
147
153
|
"math_number",
|
|
148
|
-
1,
|
|
154
|
+
"1",
|
|
149
155
|
]);
|
|
150
156
|
}
|
|
151
157
|
|
|
152
158
|
/**
|
|
153
159
|
* Construct and add a data_showVariable block to xmlList.
|
|
154
|
-
*
|
|
155
|
-
* @param
|
|
160
|
+
*
|
|
161
|
+
* @param xmlList Array of XML block elements.
|
|
162
|
+
* @param variable Variable to select in the field.
|
|
156
163
|
*/
|
|
157
|
-
function addShowVariable(
|
|
164
|
+
function addShowVariable(
|
|
165
|
+
xmlList: Element[],
|
|
166
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
167
|
+
) {
|
|
158
168
|
// <block type="data_showvariable">
|
|
159
169
|
// <value name="VARIABLE">
|
|
160
170
|
// <shadow type="data_variablemenu"></shadow>
|
|
@@ -165,10 +175,14 @@ function addShowVariable(xmlList, variable) {
|
|
|
165
175
|
|
|
166
176
|
/**
|
|
167
177
|
* Construct and add a data_hideVariable block to xmlList.
|
|
168
|
-
*
|
|
169
|
-
* @param
|
|
178
|
+
*
|
|
179
|
+
* @param xmlList Array of XML block elements.
|
|
180
|
+
* @param variable Variable to select in the field.
|
|
170
181
|
*/
|
|
171
|
-
function addHideVariable(
|
|
182
|
+
function addHideVariable(
|
|
183
|
+
xmlList: Element[],
|
|
184
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
185
|
+
) {
|
|
172
186
|
// <block type="data_hidevariable">
|
|
173
187
|
// <value name="VARIABLE">
|
|
174
188
|
// <shadow type="data_variablemenu"></shadow>
|
|
@@ -179,10 +193,14 @@ function addHideVariable(xmlList, variable) {
|
|
|
179
193
|
|
|
180
194
|
/**
|
|
181
195
|
* Construct and add a data_listcontents block to xmlList.
|
|
182
|
-
*
|
|
183
|
-
* @param
|
|
196
|
+
*
|
|
197
|
+
* @param xmlList Array of XML block elements.
|
|
198
|
+
* @param variable Variable to select in the field.
|
|
184
199
|
*/
|
|
185
|
-
function addDataList(
|
|
200
|
+
function addDataList(
|
|
201
|
+
xmlList: Element[],
|
|
202
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
203
|
+
) {
|
|
186
204
|
// <block id="variableId" type="data_listcontents">
|
|
187
205
|
// <field name="LIST">variablename</field>
|
|
188
206
|
// </block>
|
|
@@ -193,10 +211,14 @@ function addDataList(xmlList, variable) {
|
|
|
193
211
|
|
|
194
212
|
/**
|
|
195
213
|
* Construct and add a data_addtolist block to xmlList.
|
|
196
|
-
*
|
|
197
|
-
* @param
|
|
214
|
+
*
|
|
215
|
+
* @param xmlList Array of XML block elements.
|
|
216
|
+
* @param variable Variable to select in the field.
|
|
198
217
|
*/
|
|
199
|
-
function addAddToList(
|
|
218
|
+
function addAddToList(
|
|
219
|
+
xmlList: Element[],
|
|
220
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
221
|
+
) {
|
|
200
222
|
// <block type="data_addtolist">
|
|
201
223
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
202
224
|
// <value name="ITEM">
|
|
@@ -214,10 +236,14 @@ function addAddToList(xmlList, variable) {
|
|
|
214
236
|
|
|
215
237
|
/**
|
|
216
238
|
* Construct and add a data_deleteoflist block to xmlList.
|
|
217
|
-
*
|
|
218
|
-
* @param
|
|
239
|
+
*
|
|
240
|
+
* @param xmlList Array of XML block elements.
|
|
241
|
+
* @param variable Variable to select in the field.
|
|
219
242
|
*/
|
|
220
|
-
function addDeleteOfList(
|
|
243
|
+
function addDeleteOfList(
|
|
244
|
+
xmlList: Element[],
|
|
245
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
246
|
+
) {
|
|
221
247
|
// <block type="data_deleteoflist">
|
|
222
248
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
223
249
|
// <value name="INDEX">
|
|
@@ -229,16 +255,20 @@ function addDeleteOfList(xmlList, variable) {
|
|
|
229
255
|
addBlock(xmlList, variable, "data_deleteoflist", "LIST", [
|
|
230
256
|
"INDEX",
|
|
231
257
|
"math_integer",
|
|
232
|
-
1,
|
|
258
|
+
"1",
|
|
233
259
|
]);
|
|
234
260
|
}
|
|
235
261
|
|
|
236
262
|
/**
|
|
237
263
|
* Construct and add a data_deleteoflist block to xmlList.
|
|
238
|
-
*
|
|
239
|
-
* @param
|
|
264
|
+
*
|
|
265
|
+
* @param xmlList Array of XML block elements.
|
|
266
|
+
* @param variable Variable to select in the field.
|
|
240
267
|
*/
|
|
241
|
-
function addDeleteAllOfList(
|
|
268
|
+
function addDeleteAllOfList(
|
|
269
|
+
xmlList: Element[],
|
|
270
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
271
|
+
) {
|
|
242
272
|
// <block type="data_deletealloflist">
|
|
243
273
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
244
274
|
// </block>
|
|
@@ -247,10 +277,14 @@ function addDeleteAllOfList(xmlList, variable) {
|
|
|
247
277
|
|
|
248
278
|
/**
|
|
249
279
|
* Construct and add a data_insertatlist block to xmlList.
|
|
250
|
-
*
|
|
251
|
-
* @param
|
|
280
|
+
*
|
|
281
|
+
* @param xmlList Array of XML block elements.
|
|
282
|
+
* @param variable Variable to select in the field.
|
|
252
283
|
*/
|
|
253
|
-
function addInsertAtList(
|
|
284
|
+
function addInsertAtList(
|
|
285
|
+
xmlList: Element[],
|
|
286
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
287
|
+
) {
|
|
254
288
|
// <block type="data_insertatlist">
|
|
255
289
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
256
290
|
// <value name="INDEX">
|
|
@@ -269,17 +303,21 @@ function addInsertAtList(xmlList, variable) {
|
|
|
269
303
|
variable,
|
|
270
304
|
"data_insertatlist",
|
|
271
305
|
"LIST",
|
|
272
|
-
["INDEX", "math_integer", 1],
|
|
306
|
+
["INDEX", "math_integer", "1"],
|
|
273
307
|
["ITEM", "text", Blockly.Msg.DEFAULT_LIST_ITEM]
|
|
274
308
|
);
|
|
275
309
|
}
|
|
276
310
|
|
|
277
311
|
/**
|
|
278
312
|
* Construct and add a data_replaceitemoflist block to xmlList.
|
|
279
|
-
*
|
|
280
|
-
* @param
|
|
313
|
+
*
|
|
314
|
+
* @param xmlList Array of XML block elements.
|
|
315
|
+
* @param variable Variable to select in the field.
|
|
281
316
|
*/
|
|
282
|
-
function addReplaceItemOfList(
|
|
317
|
+
function addReplaceItemOfList(
|
|
318
|
+
xmlList: Element[],
|
|
319
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
320
|
+
) {
|
|
283
321
|
// <block type="data_replaceitemoflist">
|
|
284
322
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
285
323
|
// <value name="INDEX">
|
|
@@ -298,17 +336,21 @@ function addReplaceItemOfList(xmlList, variable) {
|
|
|
298
336
|
variable,
|
|
299
337
|
"data_replaceitemoflist",
|
|
300
338
|
"LIST",
|
|
301
|
-
["INDEX", "math_integer", 1],
|
|
339
|
+
["INDEX", "math_integer", "1"],
|
|
302
340
|
["ITEM", "text", Blockly.Msg.DEFAULT_LIST_ITEM]
|
|
303
341
|
);
|
|
304
342
|
}
|
|
305
343
|
|
|
306
344
|
/**
|
|
307
345
|
* Construct and add a data_itemoflist block to xmlList.
|
|
308
|
-
*
|
|
309
|
-
* @param
|
|
346
|
+
*
|
|
347
|
+
* @param xmlList Array of XML block elements.
|
|
348
|
+
* @param variable Variable to select in the field.
|
|
310
349
|
*/
|
|
311
|
-
function addItemOfList(
|
|
350
|
+
function addItemOfList(
|
|
351
|
+
xmlList: Element[],
|
|
352
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
353
|
+
) {
|
|
312
354
|
// <block type="data_itemoflist">
|
|
313
355
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
314
356
|
// <value name="INDEX">
|
|
@@ -320,15 +362,19 @@ function addItemOfList(xmlList, variable) {
|
|
|
320
362
|
addBlock(xmlList, variable, "data_itemoflist", "LIST", [
|
|
321
363
|
"INDEX",
|
|
322
364
|
"math_integer",
|
|
323
|
-
1,
|
|
365
|
+
"1",
|
|
324
366
|
]);
|
|
325
367
|
}
|
|
326
368
|
|
|
327
369
|
/** Construct and add a data_itemnumoflist block to xmlList.
|
|
328
|
-
*
|
|
329
|
-
* @param
|
|
370
|
+
*
|
|
371
|
+
* @param xmlList Array of XML block elements.
|
|
372
|
+
* @param variable Variable to select in the field.
|
|
330
373
|
*/
|
|
331
|
-
function addItemNumberOfList(
|
|
374
|
+
function addItemNumberOfList(
|
|
375
|
+
xmlList: Element[],
|
|
376
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
377
|
+
) {
|
|
332
378
|
// <block type="data_itemnumoflist">
|
|
333
379
|
// <value name="ITEM">
|
|
334
380
|
// <shadow type="text">
|
|
@@ -346,10 +392,14 @@ function addItemNumberOfList(xmlList, variable) {
|
|
|
346
392
|
|
|
347
393
|
/**
|
|
348
394
|
* Construct and add a data_lengthoflist block to xmlList.
|
|
349
|
-
*
|
|
350
|
-
* @param
|
|
395
|
+
*
|
|
396
|
+
* @param xmlList Array of XML block elements.
|
|
397
|
+
* @param variable Variable to select in the field.
|
|
351
398
|
*/
|
|
352
|
-
function addLengthOfList(
|
|
399
|
+
function addLengthOfList(
|
|
400
|
+
xmlList: Element[],
|
|
401
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
402
|
+
) {
|
|
353
403
|
// <block type="data_lengthoflist">
|
|
354
404
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
355
405
|
// </block>
|
|
@@ -358,10 +408,14 @@ function addLengthOfList(xmlList, variable) {
|
|
|
358
408
|
|
|
359
409
|
/**
|
|
360
410
|
* Construct and add a data_listcontainsitem block to xmlList.
|
|
361
|
-
*
|
|
362
|
-
* @param
|
|
411
|
+
*
|
|
412
|
+
* @param xmlList Array of XML block elements.
|
|
413
|
+
* @param variable Variable to select in the field.
|
|
363
414
|
*/
|
|
364
|
-
function addListContainsItem(
|
|
415
|
+
function addListContainsItem(
|
|
416
|
+
xmlList: Element[],
|
|
417
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
418
|
+
) {
|
|
365
419
|
// <block type="data_listcontainsitem">
|
|
366
420
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
367
421
|
// <value name="ITEM">
|
|
@@ -379,10 +433,14 @@ function addListContainsItem(xmlList, variable) {
|
|
|
379
433
|
|
|
380
434
|
/**
|
|
381
435
|
* Construct and add a data_showlist block to xmlList.
|
|
382
|
-
*
|
|
383
|
-
* @param
|
|
436
|
+
*
|
|
437
|
+
* @param xmlList Array of XML block elements.
|
|
438
|
+
* @param variable Variable to select in the field.
|
|
384
439
|
*/
|
|
385
|
-
function addShowList(
|
|
440
|
+
function addShowList(
|
|
441
|
+
xmlList: Element[],
|
|
442
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
443
|
+
) {
|
|
386
444
|
// <block type="data_showlist">
|
|
387
445
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
388
446
|
// </block>
|
|
@@ -391,10 +449,14 @@ function addShowList(xmlList, variable) {
|
|
|
391
449
|
|
|
392
450
|
/**
|
|
393
451
|
* Construct and add a data_hidelist block to xmlList.
|
|
394
|
-
*
|
|
395
|
-
* @param
|
|
452
|
+
*
|
|
453
|
+
* @param xmlList Array of XML block elements.
|
|
454
|
+
* @param variable Variable to select in the field.
|
|
396
455
|
*/
|
|
397
|
-
function addHideList(
|
|
456
|
+
function addHideList(
|
|
457
|
+
xmlList: Element[],
|
|
458
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>
|
|
459
|
+
) {
|
|
398
460
|
// <block type="data_hidelist">
|
|
399
461
|
// <field name="LIST" variabletype="list" id="">variablename</field>
|
|
400
462
|
// </block>
|
|
@@ -403,24 +465,29 @@ function addHideList(xmlList, variable) {
|
|
|
403
465
|
|
|
404
466
|
/**
|
|
405
467
|
* Construct a create variable button and push it to the xmlList.
|
|
406
|
-
*
|
|
407
|
-
* @param
|
|
408
|
-
* @param
|
|
468
|
+
*
|
|
469
|
+
* @param xmlList Array of XML block elements.
|
|
470
|
+
* @param workspace Workspace to register callback to.
|
|
471
|
+
* @param type Type of variable this is for. For example, 'LIST' or
|
|
409
472
|
* 'VARIABLE'.
|
|
410
473
|
*/
|
|
411
|
-
function addCreateButton(
|
|
412
|
-
|
|
474
|
+
function addCreateButton(
|
|
475
|
+
xmlList: Element[],
|
|
476
|
+
workspace: Blockly.WorkspaceSvg,
|
|
477
|
+
type: string
|
|
478
|
+
) {
|
|
479
|
+
const button = document.createElement("button");
|
|
413
480
|
// Set default msg, callbackKey, and callback values for type 'VARIABLE'
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
481
|
+
let msg = Blockly.Msg.NEW_VARIABLE;
|
|
482
|
+
let callbackKey = "CREATE_VARIABLE";
|
|
483
|
+
let callback = function (button: Blockly.FlyoutButton) {
|
|
417
484
|
createVariable(button.getTargetWorkspace(), null, SCALAR_VARIABLE_TYPE);
|
|
418
485
|
};
|
|
419
486
|
|
|
420
487
|
if (type === "LIST") {
|
|
421
488
|
msg = Blockly.Msg.NEW_LIST;
|
|
422
489
|
callbackKey = "CREATE_LIST";
|
|
423
|
-
callback = function (button) {
|
|
490
|
+
callback = function (button: Blockly.FlyoutButton) {
|
|
424
491
|
createVariable(button.getTargetWorkspace(), null, LIST_VARIABLE_TYPE);
|
|
425
492
|
};
|
|
426
493
|
}
|
|
@@ -442,28 +509,28 @@ function addCreateButton(xmlList, workspace, type) {
|
|
|
442
509
|
/**
|
|
443
510
|
* Construct a variable block with the given variable, blockType, and optional
|
|
444
511
|
* value tags. Add the variable block to the given xmlList.
|
|
445
|
-
*
|
|
446
|
-
* @param
|
|
447
|
-
* @param
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* @param
|
|
452
|
-
*
|
|
453
|
-
* @param
|
|
454
|
-
*
|
|
512
|
+
*
|
|
513
|
+
* @param xmlList Array of XML block elements.
|
|
514
|
+
* @param variable Variable to select in the field.
|
|
515
|
+
* @param blockType Type of block. For example, 'data_hidelist' or
|
|
516
|
+
* 'data_showlist'.
|
|
517
|
+
* @param fieldName Name of field in block. For example: 'VARIABLE' or 'LIST'.
|
|
518
|
+
* @param opt_value Optional array containing the value name and shadow type of
|
|
519
|
+
* value tags.
|
|
520
|
+
* @param opt_secondValue Optional array containing the value name and shadow
|
|
521
|
+
* type of a second pair of value tags.
|
|
455
522
|
*/
|
|
456
523
|
function addBlock(
|
|
457
|
-
xmlList,
|
|
458
|
-
variable
|
|
459
|
-
blockType,
|
|
460
|
-
fieldName,
|
|
461
|
-
opt_value,
|
|
462
|
-
opt_secondValue
|
|
524
|
+
xmlList: Element[],
|
|
525
|
+
variable: Blockly.IVariableModel<Blockly.IVariableState>,
|
|
526
|
+
blockType: string,
|
|
527
|
+
fieldName: string,
|
|
528
|
+
opt_value?: string[],
|
|
529
|
+
opt_secondValue?: string[]
|
|
463
530
|
) {
|
|
464
531
|
if (Blockly.Blocks[blockType]) {
|
|
465
|
-
|
|
466
|
-
|
|
532
|
+
let firstValueField;
|
|
533
|
+
let secondValueField;
|
|
467
534
|
if (opt_value) {
|
|
468
535
|
firstValueField = createValue(opt_value[0], opt_value[1], opt_value[2]);
|
|
469
536
|
}
|
|
@@ -476,24 +543,30 @@ function addBlock(
|
|
|
476
543
|
}
|
|
477
544
|
|
|
478
545
|
var gap = 8;
|
|
479
|
-
var blockText =
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
secondValueField +
|
|
489
|
-
"</block>" +
|
|
490
|
-
"</xml>";
|
|
491
|
-
var block = Blockly.utils.xml.textToDom(blockText).firstChild;
|
|
546
|
+
var blockText = `
|
|
547
|
+
<xml>
|
|
548
|
+
<block type="${blockType}" gap="${gap}">
|
|
549
|
+
${generateVariableFieldXml(variable, fieldName)}
|
|
550
|
+
${firstValueField}
|
|
551
|
+
${secondValueField}
|
|
552
|
+
</block>
|
|
553
|
+
</xml>`;
|
|
554
|
+
var block = Blockly.utils.xml.textToDom(blockText).firstElementChild;
|
|
492
555
|
xmlList.push(block);
|
|
493
556
|
}
|
|
494
557
|
}
|
|
495
558
|
|
|
496
|
-
|
|
559
|
+
/**
|
|
560
|
+
* Creates XML representing a variable field.
|
|
561
|
+
*
|
|
562
|
+
* @param variableModel The variable to represent in the field.
|
|
563
|
+
* @param opt_name A custom name for the field, if desired.
|
|
564
|
+
* @returns XML representation of a variable field.
|
|
565
|
+
*/
|
|
566
|
+
function generateVariableFieldXml(
|
|
567
|
+
variableModel: Blockly.IVariableModel<Blockly.IVariableState>,
|
|
568
|
+
opt_name?: string
|
|
569
|
+
): string {
|
|
497
570
|
const field = document.createElement("field");
|
|
498
571
|
field.setAttribute("name", opt_name || "VARIABLE");
|
|
499
572
|
field.setAttribute("id", variableModel.getId());
|
|
@@ -505,13 +578,14 @@ function generateVariableFieldXml(variableModel, opt_name) {
|
|
|
505
578
|
/**
|
|
506
579
|
* Create the text representation of a value dom element with a shadow of the
|
|
507
580
|
* indicated type inside.
|
|
508
|
-
*
|
|
509
|
-
* @param
|
|
510
|
-
* @param
|
|
511
|
-
* @
|
|
581
|
+
*
|
|
582
|
+
* @param valueName Name of the value tags.
|
|
583
|
+
* @param type The type of the shadow tags.
|
|
584
|
+
* @param value The default shadow value.
|
|
585
|
+
* @returns The generated dom element in text.
|
|
512
586
|
*/
|
|
513
|
-
function createValue(valueName, type, value) {
|
|
514
|
-
|
|
587
|
+
function createValue(valueName: string, type: string, value: string): string {
|
|
588
|
+
let fieldName;
|
|
515
589
|
switch (valueName) {
|
|
516
590
|
case "ITEM":
|
|
517
591
|
fieldName = "TEXT";
|
|
@@ -527,30 +601,22 @@ function createValue(valueName, type, value) {
|
|
|
527
601
|
}
|
|
528
602
|
break;
|
|
529
603
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
'">' +
|
|
537
|
-
'<field name="' +
|
|
538
|
-
fieldName +
|
|
539
|
-
'">' +
|
|
540
|
-
value +
|
|
541
|
-
"</field>" +
|
|
542
|
-
"</shadow>" +
|
|
543
|
-
"</value>";
|
|
604
|
+
const valueField = `
|
|
605
|
+
<value name="${valueName}">
|
|
606
|
+
<shadow type="${type}">
|
|
607
|
+
<field name="${fieldName}">${value}</field>
|
|
608
|
+
</shadow>
|
|
609
|
+
</value>`;
|
|
544
610
|
return valueField;
|
|
545
611
|
}
|
|
546
612
|
|
|
547
613
|
/**
|
|
548
614
|
* Construct a block separator. Add the separator to the given xmlList.
|
|
549
|
-
*
|
|
615
|
+
*
|
|
616
|
+
* @param xmlList Array of XML block elements.
|
|
550
617
|
*/
|
|
551
|
-
function addSep(xmlList) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
var sep = Blockly.utils.xml.textToDom(sepText).firstChild;
|
|
618
|
+
function addSep(xmlList: Element[]) {
|
|
619
|
+
const sepText = `<xml><sep gap="36"/></xml>`;
|
|
620
|
+
const sep = Blockly.utils.xml.textToDom(sepText).firstElementChild;
|
|
555
621
|
xmlList.push(sep);
|
|
556
622
|
}
|
|
@@ -5,9 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as Blockly from "blockly/core";
|
|
8
|
+
import type { ScratchCommentBubble } from "../scratch_comment_bubble";
|
|
8
9
|
|
|
9
10
|
export class BlockCommentBase extends Blockly.Events.Abstract {
|
|
10
|
-
|
|
11
|
+
isBlank = true;
|
|
12
|
+
commentId: string;
|
|
13
|
+
blockId: string;
|
|
14
|
+
workspaceId: string;
|
|
15
|
+
|
|
16
|
+
constructor(opt_blockComment?: ScratchCommentBubble) {
|
|
11
17
|
super();
|
|
12
18
|
this.isBlank = !opt_blockComment;
|
|
13
19
|
|
|
@@ -18,7 +24,7 @@ export class BlockCommentBase extends Blockly.Events.Abstract {
|
|
|
18
24
|
this.workspaceId = opt_blockComment.getSourceBlock()?.workspace.id;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
toJson() {
|
|
27
|
+
toJson(): BlockCommentBaseJson {
|
|
22
28
|
return {
|
|
23
29
|
...super.toJson(),
|
|
24
30
|
commentId: this.commentId,
|
|
@@ -26,10 +32,23 @@ export class BlockCommentBase extends Blockly.Events.Abstract {
|
|
|
26
32
|
};
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
static fromJson(
|
|
30
|
-
|
|
35
|
+
static fromJson(
|
|
36
|
+
json: BlockCommentBaseJson,
|
|
37
|
+
workspace: Blockly.Workspace,
|
|
38
|
+
event?: any
|
|
39
|
+
): BlockCommentBase {
|
|
40
|
+
const newEvent = super.fromJson(
|
|
41
|
+
json,
|
|
42
|
+
workspace,
|
|
43
|
+
event ?? new BlockCommentBase()
|
|
44
|
+
) as BlockCommentBase;
|
|
31
45
|
newEvent.commentId = json["commentId"];
|
|
32
46
|
newEvent.blockId = json["blockId"];
|
|
33
47
|
return newEvent;
|
|
34
48
|
}
|
|
35
49
|
}
|
|
50
|
+
|
|
51
|
+
export interface BlockCommentBaseJson extends Blockly.Events.AbstractEventJson {
|
|
52
|
+
commentId: string;
|
|
53
|
+
blockId: string;
|
|
54
|
+
}
|