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