scratch-blocks 0.1.0-prerelease.20211005172512

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.
Files changed (243) hide show
  1. package/LICENSE +177 -0
  2. package/README.md +23 -0
  3. package/TRADEMARK +1 -0
  4. package/blockly_compressed_horizontal.js +2253 -0
  5. package/blockly_compressed_vertical.js +2281 -0
  6. package/blockly_uncompressed_horizontal.js +1210 -0
  7. package/blockly_uncompressed_vertical.js +1210 -0
  8. package/blocks_common/colour.js +61 -0
  9. package/blocks_common/math.js +154 -0
  10. package/blocks_common/matrix.js +54 -0
  11. package/blocks_common/note.js +57 -0
  12. package/blocks_common/text.js +56 -0
  13. package/blocks_compressed.js +36 -0
  14. package/blocks_compressed_horizontal.js +58 -0
  15. package/blocks_compressed_vertical.js +207 -0
  16. package/blocks_horizontal/control.js +207 -0
  17. package/blocks_horizontal/default_toolbox.js +139 -0
  18. package/blocks_horizontal/event.js +185 -0
  19. package/blocks_horizontal/wedo.js +316 -0
  20. package/blocks_vertical/control.js +531 -0
  21. package/blocks_vertical/data.js +670 -0
  22. package/blocks_vertical/default_toolbox.js +564 -0
  23. package/blocks_vertical/event.js +328 -0
  24. package/blocks_vertical/extensions.js +294 -0
  25. package/blocks_vertical/looks.js +589 -0
  26. package/blocks_vertical/motion.js +584 -0
  27. package/blocks_vertical/operators.js +470 -0
  28. package/blocks_vertical/procedures.js +971 -0
  29. package/blocks_vertical/sensing.js +539 -0
  30. package/blocks_vertical/sound.js +245 -0
  31. package/blocks_vertical/vertical_extensions.js +264 -0
  32. package/build/gen_blocks.js +1 -0
  33. package/build/test_expect.js +1 -0
  34. package/build/test_input.js +1 -0
  35. package/build.py +630 -0
  36. package/cleanup.sh +101 -0
  37. package/core/block.js +1811 -0
  38. package/core/block_animations.js +107 -0
  39. package/core/block_drag_surface.js +299 -0
  40. package/core/block_dragger.js +421 -0
  41. package/core/block_events.js +531 -0
  42. package/core/block_render_svg_horizontal.js +890 -0
  43. package/core/block_render_svg_vertical.js +1732 -0
  44. package/core/block_svg.js +1314 -0
  45. package/core/blockly.js +622 -0
  46. package/core/blocks.js +37 -0
  47. package/core/bubble.js +664 -0
  48. package/core/bubble_dragger.js +285 -0
  49. package/core/colours.js +147 -0
  50. package/core/comment.js +293 -0
  51. package/core/comment_events.js +539 -0
  52. package/core/connection.js +766 -0
  53. package/core/connection_db.js +300 -0
  54. package/core/constants.js +387 -0
  55. package/core/contextmenu.js +519 -0
  56. package/core/css.js +1350 -0
  57. package/core/data_category.js +490 -0
  58. package/core/dragged_connection_manager.js +260 -0
  59. package/core/dropdowndiv.js +408 -0
  60. package/core/events.js +429 -0
  61. package/core/events_abstract.js +113 -0
  62. package/core/extensions.js +450 -0
  63. package/core/field.js +807 -0
  64. package/core/field_angle.js +398 -0
  65. package/core/field_checkbox.js +133 -0
  66. package/core/field_colour.js +253 -0
  67. package/core/field_colour_slider.js +386 -0
  68. package/core/field_date.js +353 -0
  69. package/core/field_dropdown.js +483 -0
  70. package/core/field_iconmenu.js +307 -0
  71. package/core/field_image.js +193 -0
  72. package/core/field_label.js +136 -0
  73. package/core/field_label_serializable.js +125 -0
  74. package/core/field_matrix.js +566 -0
  75. package/core/field_note.js +850 -0
  76. package/core/field_number.js +366 -0
  77. package/core/field_numberdropdown.js +77 -0
  78. package/core/field_textdropdown.js +164 -0
  79. package/core/field_textinput.js +675 -0
  80. package/core/field_textinput_removable.js +105 -0
  81. package/core/field_variable.js +385 -0
  82. package/core/field_variable_getter.js +185 -0
  83. package/core/field_vertical_separator.js +161 -0
  84. package/core/flyout_base.js +923 -0
  85. package/core/flyout_button.js +322 -0
  86. package/core/flyout_dragger.js +83 -0
  87. package/core/flyout_extension_category_header.js +159 -0
  88. package/core/flyout_horizontal.js +475 -0
  89. package/core/flyout_vertical.js +770 -0
  90. package/core/generator.js +426 -0
  91. package/core/gesture.js +1011 -0
  92. package/core/grid.js +227 -0
  93. package/core/icon.js +205 -0
  94. package/core/inject.js +491 -0
  95. package/core/input.js +285 -0
  96. package/core/insertion_marker_manager.js +678 -0
  97. package/core/msg.js +62 -0
  98. package/core/mutator.js +426 -0
  99. package/core/names.js +198 -0
  100. package/core/options.js +244 -0
  101. package/core/procedures.js +577 -0
  102. package/core/rendered_connection.js +417 -0
  103. package/core/scratch_block_comment.js +653 -0
  104. package/core/scratch_blocks_utils.js +244 -0
  105. package/core/scratch_bubble.js +696 -0
  106. package/core/scratch_events.js +131 -0
  107. package/core/scratch_msgs.js +85 -0
  108. package/core/scrollbar.js +875 -0
  109. package/core/toolbox.js +801 -0
  110. package/core/tooltip.js +337 -0
  111. package/core/touch.js +226 -0
  112. package/core/trashcan.js +343 -0
  113. package/core/ui_events.js +91 -0
  114. package/core/ui_menu_utils.js +68 -0
  115. package/core/utils.js +948 -0
  116. package/core/variable_events.js +259 -0
  117. package/core/variable_map.js +415 -0
  118. package/core/variable_model.js +116 -0
  119. package/core/variables.js +674 -0
  120. package/core/warning.js +199 -0
  121. package/core/widgetdiv.js +344 -0
  122. package/core/workspace.js +673 -0
  123. package/core/workspace_audio.js +170 -0
  124. package/core/workspace_comment.js +432 -0
  125. package/core/workspace_comment_render_svg.js +723 -0
  126. package/core/workspace_comment_svg.js +611 -0
  127. package/core/workspace_drag_surface_svg.js +195 -0
  128. package/core/workspace_dragger.js +132 -0
  129. package/core/workspace_svg.js +2267 -0
  130. package/core/xml.js +919 -0
  131. package/core/zoom_controls.js +301 -0
  132. package/dist/horizontal.js +222 -0
  133. package/dist/vertical.js +222 -0
  134. package/dist/web/horizontal.js +232 -0
  135. package/dist/web/vertical.js +232 -0
  136. package/i18n/common.py +234 -0
  137. package/i18n/create_messages.py +165 -0
  138. package/i18n/create_scratch_msgs.js +69 -0
  139. package/i18n/dedup_json.py +73 -0
  140. package/i18n/js_to_json.js +46 -0
  141. package/i18n/js_to_json.py +136 -0
  142. package/i18n/json_to_js.js +52 -0
  143. package/i18n/json_to_js.py +185 -0
  144. package/i18n/sync_translations.sh +17 -0
  145. package/i18n/sync_tx_translations.js +121 -0
  146. package/i18n/test_scratch_msgs.js +87 -0
  147. package/i18n/tests.py +47 -0
  148. package/i18n/xliff_to_json.py +232 -0
  149. package/local_build.sh +70 -0
  150. package/media/1x1.gif +0 -0
  151. package/media/click.mp3 +0 -0
  152. package/media/click.ogg +0 -0
  153. package/media/click.wav +0 -0
  154. package/media/comment-arrow-down.svg +10 -0
  155. package/media/comment-arrow-up.svg +10 -0
  156. package/media/delete-x.svg +10 -0
  157. package/media/delete.mp3 +0 -0
  158. package/media/delete.ogg +0 -0
  159. package/media/delete.wav +0 -0
  160. package/media/dropdown-arrow-dark.svg +1 -0
  161. package/media/dropdown-arrow.svg +1 -0
  162. package/media/extensions/microbit-block-icon.svg +130 -0
  163. package/media/extensions/music-block-icon.svg +17 -0
  164. package/media/extensions/pen-block-icon.svg +19 -0
  165. package/media/extensions/wedo2-block-icon.svg +36 -0
  166. package/media/eyedropper.svg +22 -0
  167. package/media/green-flag.svg +17 -0
  168. package/media/handclosed.cur +0 -0
  169. package/media/handdelete.cur +0 -0
  170. package/media/handopen.cur +0 -0
  171. package/media/icons/arrow.svg +12 -0
  172. package/media/icons/arrow_button.svg +1 -0
  173. package/media/icons/control_forever.svg +1 -0
  174. package/media/icons/control_repeat.svg +1 -0
  175. package/media/icons/control_stop.svg +1 -0
  176. package/media/icons/control_wait.svg +1 -0
  177. package/media/icons/event_broadcast_blue.svg +1 -0
  178. package/media/icons/event_broadcast_coral.svg +1 -0
  179. package/media/icons/event_broadcast_green.svg +1 -0
  180. package/media/icons/event_broadcast_magenta.svg +1 -0
  181. package/media/icons/event_broadcast_orange.svg +1 -0
  182. package/media/icons/event_broadcast_purple.svg +1 -0
  183. package/media/icons/event_when-broadcast-received_blue.svg +1 -0
  184. package/media/icons/event_when-broadcast-received_coral.svg +1 -0
  185. package/media/icons/event_when-broadcast-received_green.svg +1 -0
  186. package/media/icons/event_when-broadcast-received_magenta.svg +1 -0
  187. package/media/icons/event_when-broadcast-received_orange.svg +1 -0
  188. package/media/icons/event_when-broadcast-received_purple.svg +1 -0
  189. package/media/icons/event_whenflagclicked.svg +1 -0
  190. package/media/icons/remove.svg +19 -0
  191. package/media/icons/set-led_blue.svg +1 -0
  192. package/media/icons/set-led_coral.svg +1 -0
  193. package/media/icons/set-led_green.svg +1 -0
  194. package/media/icons/set-led_magenta.svg +1 -0
  195. package/media/icons/set-led_mystery.svg +1 -0
  196. package/media/icons/set-led_orange.svg +1 -0
  197. package/media/icons/set-led_purple.svg +1 -0
  198. package/media/icons/set-led_white.svg +1 -0
  199. package/media/icons/set-led_yellow.svg +1 -0
  200. package/media/icons/wedo_motor-clockwise.svg +1 -0
  201. package/media/icons/wedo_motor-counterclockwise.svg +1 -0
  202. package/media/icons/wedo_motor-speed_fast.svg +1 -0
  203. package/media/icons/wedo_motor-speed_med.svg +1 -0
  204. package/media/icons/wedo_motor-speed_slow.svg +1 -0
  205. package/media/icons/wedo_when-distance_close.svg +1 -0
  206. package/media/icons/wedo_when-tilt-backward.svg +1 -0
  207. package/media/icons/wedo_when-tilt-forward.svg +1 -0
  208. package/media/icons/wedo_when-tilt-left.svg +1 -0
  209. package/media/icons/wedo_when-tilt-right.svg +1 -0
  210. package/media/icons/wedo_when-tilt.svg +1 -0
  211. package/media/repeat.svg +18 -0
  212. package/media/rotate-left.svg +1 -0
  213. package/media/rotate-right.svg +1 -0
  214. package/media/sprites.png +0 -0
  215. package/media/sprites.svg +74 -0
  216. package/media/status-not-ready.svg +13 -0
  217. package/media/status-ready.svg +13 -0
  218. package/media/zoom-in.svg +1 -0
  219. package/media/zoom-out.svg +1 -0
  220. package/media/zoom-reset.svg +1 -0
  221. package/msg/js/en.js +290 -0
  222. package/msg/json/en.json +285 -0
  223. package/msg/messages.js +353 -0
  224. package/msg/scratch_msgs.js +21247 -0
  225. package/package.json +52 -0
  226. package/pull_from_blockly.sh +151 -0
  227. package/renovate.json5 +15 -0
  228. package/shim/blockly_compressed_horizontal-blocks_compressed.js +1 -0
  229. package/shim/blockly_compressed_horizontal.Blockly.js +1 -0
  230. package/shim/blockly_compressed_horizontal.goog.js +1 -0
  231. package/shim/blockly_compressed_horizontal.js +1 -0
  232. package/shim/blockly_compressed_vertical-blocks_compressed.js +1 -0
  233. package/shim/blockly_compressed_vertical.Blockly.js +1 -0
  234. package/shim/blockly_compressed_vertical.goog.js +1 -0
  235. package/shim/blockly_compressed_vertical.js +1 -0
  236. package/shim/blocks_compressed_horizontal-blockly_compressed_horizontal-messages.js +1 -0
  237. package/shim/blocks_compressed_horizontal.js +1 -0
  238. package/shim/blocks_compressed_vertical-blockly_compressed_vertical-messages.js +1 -0
  239. package/shim/blocks_compressed_vertical.js +1 -0
  240. package/shim/gh-pages.js +1 -0
  241. package/shim/horizontal.js +1 -0
  242. package/shim/index.js +17 -0
  243. package/shim/vertical.js +1 -0
@@ -0,0 +1,670 @@
1
+ /**
2
+ * @license
3
+ * Visual Blocks Editor
4
+ *
5
+ * Copyright 2016 Massachusetts Institute of Technology
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ goog.provide('Blockly.Blocks.data');
24
+ goog.provide('Blockly.Constants.Data');
25
+
26
+ goog.require('Blockly.Blocks');
27
+ goog.require('Blockly.Colours');
28
+ goog.require('Blockly.constants');
29
+ goog.require('Blockly.ScratchBlocks.VerticalExtensions');
30
+
31
+
32
+ Blockly.Blocks['data_variable'] = {
33
+ /**
34
+ * Block of Variables
35
+ * @this Blockly.Block
36
+ */
37
+ init: function() {
38
+ this.jsonInit({
39
+ "message0": "%1",
40
+ "lastDummyAlign0": "CENTRE",
41
+ "args0": [
42
+ {
43
+ "type": "field_variable_getter",
44
+ "text": "",
45
+ "name": "VARIABLE",
46
+ "variableType": ""
47
+ }
48
+ ],
49
+ "category": Blockly.Categories.data,
50
+ "checkboxInFlyout": true,
51
+ "extensions": ["contextMenu_getVariableBlock", "colours_data", "output_string"]
52
+ });
53
+ }
54
+ };
55
+
56
+ Blockly.Blocks['data_setvariableto'] = {
57
+ /**
58
+ * Block to set variable to a certain value
59
+ * @this Blockly.Block
60
+ */
61
+ init: function() {
62
+ this.jsonInit({
63
+ "message0": Blockly.Msg.DATA_SETVARIABLETO,
64
+ "args0": [
65
+ {
66
+ "type": "field_variable",
67
+ "name": "VARIABLE"
68
+ },
69
+ {
70
+ "type": "input_value",
71
+ "name": "VALUE"
72
+ }
73
+ ],
74
+ "category": Blockly.Categories.data,
75
+ "extensions": ["colours_data", "shape_statement"]
76
+ });
77
+ }
78
+ };
79
+
80
+ Blockly.Blocks['data_changevariableby'] = {
81
+ /**
82
+ * Block to change variable by a certain value
83
+ * @this Blockly.Block
84
+ */
85
+ init: function() {
86
+ this.jsonInit({
87
+ "message0": Blockly.Msg.DATA_CHANGEVARIABLEBY,
88
+ "args0": [
89
+ {
90
+ "type": "field_variable",
91
+ "name": "VARIABLE"
92
+ },
93
+ {
94
+ "type": "input_value",
95
+ "name": "VALUE"
96
+ }
97
+ ],
98
+ "category": Blockly.Categories.data,
99
+ "extensions": ["colours_data", "shape_statement"]
100
+ });
101
+ }
102
+ };
103
+
104
+ Blockly.Blocks['data_showvariable'] = {
105
+ /**
106
+ * Block to show a variable
107
+ * @this Blockly.Block
108
+ */
109
+ init: function() {
110
+ this.jsonInit({
111
+ "message0": Blockly.Msg.DATA_SHOWVARIABLE,
112
+ "args0": [
113
+ {
114
+ "type": "field_variable",
115
+ "name": "VARIABLE"
116
+ }
117
+ ],
118
+ "previousStatement": null,
119
+ "nextStatement": null,
120
+ "category": Blockly.Categories.data,
121
+ "colour": Blockly.Colours.data.primary,
122
+ "colourSecondary": Blockly.Colours.data.secondary,
123
+ "colourTertiary": Blockly.Colours.data.tertiary
124
+ });
125
+ }
126
+ };
127
+
128
+ Blockly.Blocks['data_hidevariable'] = {
129
+ /**
130
+ * Block to hide a variable
131
+ * @this Blockly.Block
132
+ */
133
+ init: function() {
134
+ this.jsonInit({
135
+ "message0": Blockly.Msg.DATA_HIDEVARIABLE,
136
+ "args0": [
137
+ {
138
+ "type": "field_variable",
139
+ "name": "VARIABLE"
140
+ }
141
+ ],
142
+ "previousStatement": null,
143
+ "nextStatement": null,
144
+ "category": Blockly.Categories.data,
145
+ "colour": Blockly.Colours.data.primary,
146
+ "colourSecondary": Blockly.Colours.data.secondary,
147
+ "colourTertiary": Blockly.Colours.data.tertiary
148
+ });
149
+ }
150
+ };
151
+
152
+ Blockly.Blocks['data_listcontents'] = {
153
+ /**
154
+ * List reporter.
155
+ * @this Blockly.Block
156
+ */
157
+ init: function() {
158
+ this.jsonInit({
159
+ "message0": "%1",
160
+ "args0": [
161
+ {
162
+ "type": "field_variable_getter",
163
+ "text": "",
164
+ "name": "LIST",
165
+ "variableType": Blockly.LIST_VARIABLE_TYPE
166
+ }
167
+ ],
168
+ "category": Blockly.Categories.dataLists,
169
+ "extensions": ["contextMenu_getListBlock", "colours_data_lists", "output_string"],
170
+ "checkboxInFlyout": true
171
+ });
172
+ }
173
+ };
174
+
175
+ Blockly.Blocks['data_listindexall'] = {
176
+ /**
177
+ * List index menu, with all option.
178
+ * @this Blockly.Block
179
+ */
180
+ init: function() {
181
+ this.jsonInit({
182
+ "message0": "%1",
183
+ "args0": [
184
+ {
185
+ "type": "field_numberdropdown",
186
+ "name": "INDEX",
187
+ "value": "1",
188
+ "min": 1,
189
+ "precision": 1,
190
+ "options": [
191
+ ["1", "1"],
192
+ [Blockly.Msg.DATA_INDEX_LAST, "last"],
193
+ [Blockly.Msg.DATA_INDEX_ALL, "all"]
194
+ ]
195
+ }
196
+ ],
197
+ "category": Blockly.Categories.data,
198
+ "extensions": ["colours_textfield", "output_string"]
199
+ });
200
+ }
201
+ };
202
+
203
+ Blockly.Blocks['data_listindexrandom'] = {
204
+ /**
205
+ * List index menu, with random option.
206
+ * @this Blockly.Block
207
+ */
208
+ init: function() {
209
+ this.jsonInit({
210
+ "message0": "%1",
211
+ "args0": [
212
+ {
213
+ "type": "field_numberdropdown",
214
+ "name": "INDEX",
215
+ "value": "1",
216
+ "min": 1,
217
+ "precision": 1,
218
+ "options": [
219
+ ["1", "1"],
220
+ [Blockly.Msg.DATA_INDEX_LAST, "last"],
221
+ [Blockly.Msg.DATA_INDEX_RANDOM, "random"]
222
+ ]
223
+ }
224
+ ],
225
+ "category": Blockly.Categories.data,
226
+ "extensions": ["colours_textfield", "output_string"]
227
+ });
228
+ }
229
+ };
230
+
231
+ Blockly.Blocks['data_addtolist'] = {
232
+ /**
233
+ * Block to add item to list.
234
+ * @this Blockly.Block
235
+ */
236
+ init: function() {
237
+ this.jsonInit({
238
+ "message0": Blockly.Msg.DATA_ADDTOLIST,
239
+ "args0": [
240
+ {
241
+ "type": "input_value",
242
+ "name": "ITEM"
243
+ },
244
+ {
245
+ "type": "field_variable",
246
+ "name": "LIST",
247
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
248
+ }
249
+ ],
250
+ "category": Blockly.Categories.dataLists,
251
+ "extensions": ["colours_data_lists", "shape_statement"]
252
+ });
253
+ }
254
+ };
255
+
256
+ Blockly.Blocks['data_deleteoflist'] = {
257
+ /**
258
+ * Block to delete item from list.
259
+ * @this Blockly.Block
260
+ */
261
+ init: function() {
262
+ this.jsonInit({
263
+ "message0": Blockly.Msg.DATA_DELETEOFLIST,
264
+ "args0": [
265
+ {
266
+ "type": "input_value",
267
+ "name": "INDEX"
268
+ },
269
+ {
270
+ "type": "field_variable",
271
+ "name": "LIST",
272
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
273
+ }
274
+ ],
275
+ "category": Blockly.Categories.dataLists,
276
+ "extensions": ["colours_data_lists", "shape_statement"]
277
+ });
278
+ }
279
+ };
280
+
281
+ Blockly.Blocks['data_deletealloflist'] = {
282
+ /**
283
+ * Block to delete all items from list.
284
+ * @this Blockly.Block
285
+ */
286
+ init: function() {
287
+ this.jsonInit({
288
+ "message0": Blockly.Msg.DATA_DELETEALLOFLIST,
289
+ "args0": [
290
+ {
291
+ "type": "field_variable",
292
+ "name": "LIST",
293
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
294
+ }
295
+ ],
296
+ "category": Blockly.Categories.dataLists,
297
+ "extensions": ["colours_data_lists", "shape_statement"]
298
+ });
299
+ }
300
+ };
301
+
302
+ Blockly.Blocks['data_insertatlist'] = {
303
+ /**
304
+ * Block to insert item to list.
305
+ * @this Blockly.Block
306
+ */
307
+ init: function() {
308
+ this.jsonInit({
309
+ "message0": Blockly.Msg.DATA_INSERTATLIST,
310
+ "args0": [
311
+ {
312
+ "type": "input_value",
313
+ "name": "ITEM"
314
+ },
315
+ {
316
+ "type": "input_value",
317
+ "name": "INDEX"
318
+ },
319
+ {
320
+ "type": "field_variable",
321
+ "name": "LIST",
322
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
323
+ }
324
+ ],
325
+ "category": Blockly.Categories.dataLists,
326
+ "extensions": ["colours_data_lists", "shape_statement"]
327
+ });
328
+ }
329
+ };
330
+
331
+ Blockly.Blocks['data_replaceitemoflist'] = {
332
+ /**
333
+ * Block to insert item to list.
334
+ * @this Blockly.Block
335
+ */
336
+ init: function() {
337
+ this.jsonInit({
338
+ "message0": Blockly.Msg.DATA_REPLACEITEMOFLIST,
339
+ "args0": [
340
+ {
341
+ "type": "input_value",
342
+ "name": "INDEX"
343
+ },
344
+ {
345
+ "type": "field_variable",
346
+ "name": "LIST",
347
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
348
+ },
349
+ {
350
+ "type": "input_value",
351
+ "name": "ITEM"
352
+ }
353
+ ],
354
+ "category": Blockly.Categories.dataLists,
355
+ "extensions": ["colours_data_lists", "shape_statement"]
356
+ });
357
+ }
358
+ };
359
+
360
+ Blockly.Blocks['data_itemoflist'] = {
361
+ /**
362
+ * Block for reporting item of list.
363
+ * @this Blockly.Block
364
+ */
365
+ init: function() {
366
+ this.jsonInit({
367
+ "message0": Blockly.Msg.DATA_ITEMOFLIST,
368
+ "args0": [
369
+ {
370
+ "type": "input_value",
371
+ "name": "INDEX"
372
+ },
373
+ {
374
+ "type": "field_variable",
375
+ "name": "LIST",
376
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
377
+ }
378
+ ],
379
+ "output": null,
380
+ "category": Blockly.Categories.dataLists,
381
+ "extensions": ["colours_data_lists"],
382
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND
383
+ });
384
+ }
385
+ };
386
+
387
+ Blockly.Blocks['data_itemnumoflist'] = {
388
+ /**
389
+ * Block for reporting the item # of a string in a list.
390
+ * @this Blockly.Block
391
+ */
392
+ init: function() {
393
+ this.jsonInit({
394
+ "message0": Blockly.Msg.DATA_ITEMNUMOFLIST,
395
+ "args0": [
396
+ {
397
+ "type": "input_value",
398
+ "name": "ITEM"
399
+ },
400
+ {
401
+ "type": "field_variable",
402
+ "name": "LIST",
403
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
404
+ }
405
+ ],
406
+ "output": null,
407
+ "category": Blockly.Categories.dataLists,
408
+ "extensions": ["colours_data_lists"],
409
+ "outputShape": Blockly.OUTPUT_SHAPE_ROUND
410
+ });
411
+ }
412
+ };
413
+
414
+ Blockly.Blocks['data_lengthoflist'] = {
415
+ /**
416
+ * Block for reporting length of list.
417
+ * @this Blockly.Block
418
+ */
419
+ init: function() {
420
+ this.jsonInit({
421
+ "message0": Blockly.Msg.DATA_LENGTHOFLIST,
422
+ "args0": [
423
+ {
424
+ "type": "field_variable",
425
+ "name": "LIST",
426
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
427
+ }
428
+ ],
429
+ "category": Blockly.Categories.dataLists,
430
+ "extensions": ["colours_data_lists", "output_number"]
431
+ });
432
+ }
433
+ };
434
+
435
+ Blockly.Blocks['data_listcontainsitem'] = {
436
+ /**
437
+ * Block to report whether list contains item.
438
+ * @this Blockly.Block
439
+ */
440
+ init: function() {
441
+ this.jsonInit({
442
+ "message0": Blockly.Msg.DATA_LISTCONTAINSITEM,
443
+ "args0": [
444
+ {
445
+ "type": "field_variable",
446
+ "name": "LIST",
447
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
448
+ },
449
+ {
450
+ "type": "input_value",
451
+ "name": "ITEM"
452
+ }
453
+ ],
454
+ "category": Blockly.Categories.dataLists,
455
+ "extensions": ["colours_data_lists", "output_boolean"]
456
+ });
457
+ }
458
+ };
459
+
460
+ Blockly.Blocks['data_showlist'] = {
461
+ /**
462
+ * Block to show a list.
463
+ * @this Blockly.Block
464
+ */
465
+ init: function() {
466
+ this.jsonInit({
467
+ "message0": Blockly.Msg.DATA_SHOWLIST,
468
+ "args0": [
469
+ {
470
+ "type": "field_variable",
471
+ "name": "LIST",
472
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
473
+ }
474
+ ],
475
+ "category": Blockly.Categories.dataLists,
476
+ "extensions": ["colours_data_lists", "shape_statement"]
477
+ });
478
+ }
479
+ };
480
+
481
+ Blockly.Blocks['data_hidelist'] = {
482
+ /**
483
+ * Block to hide a list.
484
+ * @this Blockly.Block
485
+ */
486
+ init: function() {
487
+ this.jsonInit({
488
+ "message0": Blockly.Msg.DATA_HIDELIST,
489
+ "args0": [
490
+ {
491
+ "type": "field_variable",
492
+ "name": "LIST",
493
+ "variableTypes": [Blockly.LIST_VARIABLE_TYPE]
494
+ }
495
+ ],
496
+ "category": Blockly.Categories.dataLists,
497
+ "extensions": ["colours_data_lists", "shape_statement"]
498
+ });
499
+ }
500
+ };
501
+
502
+ /**
503
+ * Mixin to add a context menu for a data_variable block. It adds one item for
504
+ * each variable defined on the workspace.
505
+ * @mixin
506
+ * @augments Blockly.Block
507
+ * @package
508
+ * @readonly
509
+ */
510
+ Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_VARIABLE_MIXIN = {
511
+ /**
512
+ * Add context menu option to change the selected variable.
513
+ * @param {!Array} options List of menu options to add to.
514
+ * @this Blockly.Block
515
+ */
516
+ customContextMenu: function(options) {
517
+ var fieldName = 'VARIABLE';
518
+ if (this.isCollapsed()) {
519
+ return;
520
+ }
521
+ var currentVarName = this.getField(fieldName).text_;
522
+ if (!this.isInFlyout) {
523
+ var variablesList = this.workspace.getVariablesOfType('');
524
+ variablesList.sort(function(a, b) {
525
+ return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
526
+ });
527
+ for (var i = 0; i < variablesList.length; i++) {
528
+ var varName = variablesList[i].name;
529
+ if (varName == currentVarName) continue;
530
+
531
+ var option = {enabled: true};
532
+ option.text = varName;
533
+
534
+ option.callback =
535
+ Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
536
+ variablesList[i].getId(), fieldName);
537
+ options.push(option);
538
+ }
539
+ } else {
540
+ var renameOption = {
541
+ text: Blockly.Msg.RENAME_VARIABLE,
542
+ enabled: true,
543
+ callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
544
+ fieldName)
545
+ };
546
+ var deleteOption = {
547
+ text: Blockly.Msg.DELETE_VARIABLE.replace('%1', currentVarName),
548
+ enabled: true,
549
+ callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
550
+ fieldName)
551
+ };
552
+ options.push(renameOption);
553
+ options.push(deleteOption);
554
+ }
555
+ }
556
+ };
557
+
558
+ Blockly.Extensions.registerMixin('contextMenu_getVariableBlock',
559
+ Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_VARIABLE_MIXIN);
560
+
561
+ /**
562
+ * Mixin to add a context menu for a data_listcontents block. It adds one item for
563
+ * each list defined on the workspace.
564
+ * @mixin
565
+ * @augments Blockly.Block
566
+ * @package
567
+ * @readonly
568
+ */
569
+ Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_LIST_MIXIN = {
570
+ /**
571
+ * Add context menu option to change the selected list.
572
+ * @param {!Array} options List of menu options to add to.
573
+ * @this Blockly.Block
574
+ */
575
+ customContextMenu: function(options) {
576
+ var fieldName = 'LIST';
577
+ if (this.isCollapsed()) {
578
+ return;
579
+ }
580
+ var currentVarName = this.getField(fieldName).text_;
581
+ if (!this.isInFlyout) {
582
+ var variablesList = this.workspace.getVariablesOfType('list');
583
+ variablesList.sort(function(a, b) {
584
+ return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
585
+ });
586
+ for (var i = 0; i < variablesList.length; i++) {
587
+ var varName = variablesList[i].name;
588
+ if (varName == currentVarName) continue;
589
+
590
+ var option = {enabled: true};
591
+ option.text = varName;
592
+
593
+ option.callback =
594
+ Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
595
+ variablesList[i].getId(), fieldName);
596
+ options.push(option);
597
+ }
598
+ } else {
599
+ var renameOption = {
600
+ text: Blockly.Msg.RENAME_LIST,
601
+ enabled: true,
602
+ callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
603
+ fieldName)
604
+ };
605
+ var deleteOption = {
606
+ text: Blockly.Msg.DELETE_LIST.replace('%1', currentVarName),
607
+ enabled: true,
608
+ callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
609
+ fieldName)
610
+ };
611
+ options.push(renameOption);
612
+ options.push(deleteOption);
613
+ }
614
+ }
615
+ };
616
+ Blockly.Extensions.registerMixin('contextMenu_getListBlock',
617
+ Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_LIST_MIXIN);
618
+
619
+ /**
620
+ * Callback factory for dropdown menu options associated with a variable getter
621
+ * block. Each variable on the workspace gets its own item in the dropdown
622
+ * menu, and clicking on that item changes the text of the field on the source
623
+ * block.
624
+ * @param {!Blockly.Block} block The block to update.
625
+ * @param {string} id The id of the variable to set on this block.
626
+ * @param {string} fieldName The name of the field to update on the block.
627
+ * @return {!function()} A function that updates the block with the new name.
628
+ */
629
+ Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY = function(block,
630
+ id, fieldName) {
631
+ return function() {
632
+ var variableField = block.getField(fieldName);
633
+ if (!variableField) {
634
+ console.log("Tried to get a variable field on the wrong type of block.");
635
+ }
636
+ variableField.setValue(id);
637
+ };
638
+ };
639
+
640
+ /**
641
+ * Callback for rename variable dropdown menu option associated with a
642
+ * variable getter block.
643
+ * @param {!Blockly.Block} block The block with the variable to rename.
644
+ * @param {string} fieldName The name of the field to inspect on the block.
645
+ * @return {!function()} A function that renames the variable.
646
+ */
647
+ Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY = function(block,
648
+ fieldName) {
649
+ return function() {
650
+ var workspace = block.workspace;
651
+ var variable = block.getField(fieldName).getVariable();
652
+ Blockly.Variables.renameVariable(workspace, variable);
653
+ };
654
+ };
655
+
656
+ /**
657
+ * Callback for delete variable dropdown menu option associated with a
658
+ * variable getter block.
659
+ * @param {!Blockly.Block} block The block with the variable to delete.
660
+ * @param {string} fieldName The name of the field to inspect on the block.
661
+ * @return {!function()} A function that deletes the variable.
662
+ */
663
+ Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY = function(block,
664
+ fieldName) {
665
+ return function() {
666
+ var workspace = block.workspace;
667
+ var variable = block.getField(fieldName).getVariable();
668
+ workspace.deleteVariableById(variable.getId());
669
+ };
670
+ };