@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,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Visual Blocks Editor
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2011 Google Inc.
|
|
6
|
+
* https://developers.google.com/blockly/
|
|
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
|
+
/**
|
|
22
|
+
* @fileoverview Components for managing connections between blocks.
|
|
23
|
+
* @author fraser@google.com (Neil Fraser)
|
|
24
|
+
*/
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
goog.provide('Blockly.ConnectionDB');
|
|
28
|
+
|
|
29
|
+
goog.require('Blockly.Connection');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Database of connections.
|
|
34
|
+
* Connections are stored in order of their vertical component. This way
|
|
35
|
+
* connections in an area may be looked up quickly using a binary search.
|
|
36
|
+
* @constructor
|
|
37
|
+
*/
|
|
38
|
+
Blockly.ConnectionDB = function() {
|
|
39
|
+
/**
|
|
40
|
+
* Array of connections sorted by y coordinate.
|
|
41
|
+
* @type {!Array.<!Blockly.Connection>}
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
this.connections_ = [];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Add a connection to the database. Must not already exist in DB.
|
|
49
|
+
* @param {!Blockly.Connection} connection The connection to be added.
|
|
50
|
+
*/
|
|
51
|
+
Blockly.ConnectionDB.prototype.addConnection = function(connection) {
|
|
52
|
+
if (connection.inDB_) {
|
|
53
|
+
throw Error('Connection already in database.');
|
|
54
|
+
}
|
|
55
|
+
if (connection.getSourceBlock().isInFlyout) {
|
|
56
|
+
// Don't bother maintaining a database of connections in a flyout.
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
var position = this.findPositionForConnection_(connection);
|
|
60
|
+
this.connections_.splice(position, 0, connection);
|
|
61
|
+
connection.inDB_ = true;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Find the given connection.
|
|
66
|
+
* Starts by doing a binary search to find the approximate location, then
|
|
67
|
+
* linearly searches nearby for the exact connection.
|
|
68
|
+
* @param {!Blockly.Connection} conn The connection to find.
|
|
69
|
+
* @return {number} The index of the connection, or -1 if the connection was
|
|
70
|
+
* not found.
|
|
71
|
+
*/
|
|
72
|
+
Blockly.ConnectionDB.prototype.findConnection = function(conn) {
|
|
73
|
+
if (!this.connections_.length) {
|
|
74
|
+
return -1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var bestGuess = this.findPositionForConnection_(conn);
|
|
78
|
+
if (bestGuess >= this.connections_.length) {
|
|
79
|
+
// Not in list
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
var yPos = conn.y_;
|
|
84
|
+
// Walk forward and back on the y axis looking for the connection.
|
|
85
|
+
var pointerMin = bestGuess;
|
|
86
|
+
var pointerMax = bestGuess;
|
|
87
|
+
while (pointerMin >= 0 && this.connections_[pointerMin].y_ == yPos) {
|
|
88
|
+
if (this.connections_[pointerMin] == conn) {
|
|
89
|
+
return pointerMin;
|
|
90
|
+
}
|
|
91
|
+
pointerMin--;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
while (pointerMax < this.connections_.length &&
|
|
95
|
+
this.connections_[pointerMax].y_ == yPos) {
|
|
96
|
+
if (this.connections_[pointerMax] == conn) {
|
|
97
|
+
return pointerMax;
|
|
98
|
+
}
|
|
99
|
+
pointerMax++;
|
|
100
|
+
}
|
|
101
|
+
return -1;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Finds a candidate position for inserting this connection into the list.
|
|
106
|
+
* This will be in the correct y order but makes no guarantees about ordering in
|
|
107
|
+
* the x axis.
|
|
108
|
+
* @param {!Blockly.Connection} connection The connection to insert.
|
|
109
|
+
* @return {number} The candidate index.
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
Blockly.ConnectionDB.prototype.findPositionForConnection_ = function(
|
|
113
|
+
connection) {
|
|
114
|
+
if (!this.connections_.length) {
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
var pointerMin = 0;
|
|
118
|
+
var pointerMax = this.connections_.length;
|
|
119
|
+
while (pointerMin < pointerMax) {
|
|
120
|
+
var pointerMid = Math.floor((pointerMin + pointerMax) / 2);
|
|
121
|
+
if (this.connections_[pointerMid].y_ < connection.y_) {
|
|
122
|
+
pointerMin = pointerMid + 1;
|
|
123
|
+
} else if (this.connections_[pointerMid].y_ > connection.y_) {
|
|
124
|
+
pointerMax = pointerMid;
|
|
125
|
+
} else {
|
|
126
|
+
pointerMin = pointerMid;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return pointerMin;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Remove a connection from the database. Must already exist in DB.
|
|
135
|
+
* @param {!Blockly.Connection} connection The connection to be removed.
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
138
|
+
Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) {
|
|
139
|
+
if (!connection.inDB_) {
|
|
140
|
+
throw Error('Connection not in database.');
|
|
141
|
+
}
|
|
142
|
+
var removalIndex = this.findConnection(connection);
|
|
143
|
+
if (removalIndex == -1) {
|
|
144
|
+
throw Error('Unable to find connection in connectionDB.');
|
|
145
|
+
}
|
|
146
|
+
connection.inDB_ = false;
|
|
147
|
+
this.connections_.splice(removalIndex, 1);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Find all nearby connections to the given connection.
|
|
152
|
+
* Type checking does not apply, since this function is used for bumping.
|
|
153
|
+
* @param {!Blockly.Connection} connection The connection whose neighbours
|
|
154
|
+
* should be returned.
|
|
155
|
+
* @param {number} maxRadius The maximum radius to another connection.
|
|
156
|
+
* @return {!Array.<Blockly.Connection>} List of connections.
|
|
157
|
+
*/
|
|
158
|
+
Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) {
|
|
159
|
+
var db = this.connections_;
|
|
160
|
+
var currentX = connection.x_;
|
|
161
|
+
var currentY = connection.y_;
|
|
162
|
+
|
|
163
|
+
// Binary search to find the closest y location.
|
|
164
|
+
var pointerMin = 0;
|
|
165
|
+
var pointerMax = db.length - 2;
|
|
166
|
+
var pointerMid = pointerMax;
|
|
167
|
+
while (pointerMin < pointerMid) {
|
|
168
|
+
if (db[pointerMid].y_ < currentY) {
|
|
169
|
+
pointerMin = pointerMid;
|
|
170
|
+
} else {
|
|
171
|
+
pointerMax = pointerMid;
|
|
172
|
+
}
|
|
173
|
+
pointerMid = Math.floor((pointerMin + pointerMax) / 2);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
var neighbours = [];
|
|
177
|
+
/**
|
|
178
|
+
* Computes if the current connection is within the allowed radius of another
|
|
179
|
+
* connection.
|
|
180
|
+
* This function is a closure and has access to outside variables.
|
|
181
|
+
* @param {number} yIndex The other connection's index in the database.
|
|
182
|
+
* @return {boolean} True if the current connection's vertical distance from
|
|
183
|
+
* the other connection is less than the allowed radius.
|
|
184
|
+
*/
|
|
185
|
+
function checkConnection_(yIndex) {
|
|
186
|
+
var dx = currentX - db[yIndex].x_;
|
|
187
|
+
var dy = currentY - db[yIndex].y_;
|
|
188
|
+
var r = Math.sqrt(dx * dx + dy * dy);
|
|
189
|
+
if (r <= maxRadius) {
|
|
190
|
+
neighbours.push(db[yIndex]);
|
|
191
|
+
}
|
|
192
|
+
return dy < maxRadius;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Walk forward and back on the y axis looking for the closest x,y point.
|
|
196
|
+
pointerMin = pointerMid;
|
|
197
|
+
pointerMax = pointerMid;
|
|
198
|
+
if (db.length) {
|
|
199
|
+
while (pointerMin >= 0 && checkConnection_(pointerMin)) {
|
|
200
|
+
pointerMin--;
|
|
201
|
+
}
|
|
202
|
+
do {
|
|
203
|
+
pointerMax++;
|
|
204
|
+
} while (pointerMax < db.length && checkConnection_(pointerMax));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return neighbours;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Is the candidate connection close to the reference connection.
|
|
213
|
+
* Extremely fast; only looks at Y distance.
|
|
214
|
+
* @param {number} index Index in database of candidate connection.
|
|
215
|
+
* @param {number} baseY Reference connection's Y value.
|
|
216
|
+
* @param {number} maxRadius The maximum radius to another connection.
|
|
217
|
+
* @return {boolean} True if connection is in range.
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) {
|
|
221
|
+
return (Math.abs(this.connections_[index].y_ - baseY) <= maxRadius);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Find the closest compatible connection to this connection.
|
|
226
|
+
* @param {!Blockly.Connection} conn The connection searching for a compatible
|
|
227
|
+
* mate.
|
|
228
|
+
* @param {number} maxRadius The maximum radius to another connection.
|
|
229
|
+
* @param {!goog.math.Coordinate} dxy Offset between this connection's location
|
|
230
|
+
* in the database and the current location (as a result of dragging).
|
|
231
|
+
* @return {!{connection: ?Blockly.Connection, radius: number}} Contains two
|
|
232
|
+
* properties:' connection' which is either another connection or null,
|
|
233
|
+
* and 'radius' which is the distance.
|
|
234
|
+
*/
|
|
235
|
+
Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius,
|
|
236
|
+
dxy) {
|
|
237
|
+
// Don't bother.
|
|
238
|
+
if (!this.connections_.length) {
|
|
239
|
+
return {connection: null, radius: maxRadius};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Stash the values of x and y from before the drag.
|
|
243
|
+
var baseY = conn.y_;
|
|
244
|
+
var baseX = conn.x_;
|
|
245
|
+
|
|
246
|
+
conn.x_ = baseX + dxy.x;
|
|
247
|
+
conn.y_ = baseY + dxy.y;
|
|
248
|
+
|
|
249
|
+
// findPositionForConnection finds an index for insertion, which is always
|
|
250
|
+
// after any block with the same y index. We want to search both forward
|
|
251
|
+
// and back, so search on both sides of the index.
|
|
252
|
+
var closestIndex = this.findPositionForConnection_(conn);
|
|
253
|
+
|
|
254
|
+
var bestConnection = null;
|
|
255
|
+
var bestRadius = maxRadius;
|
|
256
|
+
var temp;
|
|
257
|
+
|
|
258
|
+
// Walk forward and back on the y axis looking for the closest x,y point.
|
|
259
|
+
var pointerMin = closestIndex - 1;
|
|
260
|
+
while (pointerMin >= 0 && this.isInYRange_(pointerMin, conn.y_, maxRadius)) {
|
|
261
|
+
temp = this.connections_[pointerMin];
|
|
262
|
+
if (conn.isConnectionAllowed(temp, bestRadius)) {
|
|
263
|
+
bestConnection = temp;
|
|
264
|
+
bestRadius = temp.distanceFrom(conn);
|
|
265
|
+
}
|
|
266
|
+
pointerMin--;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
var pointerMax = closestIndex;
|
|
270
|
+
while (pointerMax < this.connections_.length &&
|
|
271
|
+
this.isInYRange_(pointerMax, conn.y_, maxRadius)) {
|
|
272
|
+
temp = this.connections_[pointerMax];
|
|
273
|
+
if (conn.isConnectionAllowed(temp, bestRadius)) {
|
|
274
|
+
bestConnection = temp;
|
|
275
|
+
bestRadius = temp.distanceFrom(conn);
|
|
276
|
+
}
|
|
277
|
+
pointerMax++;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Reset the values of x and y.
|
|
281
|
+
conn.x_ = baseX;
|
|
282
|
+
conn.y_ = baseY;
|
|
283
|
+
|
|
284
|
+
// If there were no valid connections, bestConnection will be null.
|
|
285
|
+
return {connection: bestConnection, radius: bestRadius};
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Initialize a set of connection DBs for a specified workspace.
|
|
290
|
+
* @param {!Blockly.Workspace} workspace The workspace this DB is for.
|
|
291
|
+
*/
|
|
292
|
+
Blockly.ConnectionDB.init = function(workspace) {
|
|
293
|
+
// Create four databases, one for each connection type.
|
|
294
|
+
var dbList = [];
|
|
295
|
+
dbList[Blockly.INPUT_VALUE] = new Blockly.ConnectionDB();
|
|
296
|
+
dbList[Blockly.OUTPUT_VALUE] = new Blockly.ConnectionDB();
|
|
297
|
+
dbList[Blockly.NEXT_STATEMENT] = new Blockly.ConnectionDB();
|
|
298
|
+
dbList[Blockly.PREVIOUS_STATEMENT] = new Blockly.ConnectionDB();
|
|
299
|
+
workspace.connectionDBList = dbList;
|
|
300
|
+
};
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Visual Blocks Editor
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2016 Google Inc.
|
|
6
|
+
* https://developers.google.com/blockly/
|
|
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
|
+
/**
|
|
22
|
+
* @fileoverview Blockly constants.
|
|
23
|
+
* @author fenichel@google.com (Rachel Fenichel)
|
|
24
|
+
*/
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
goog.provide('Blockly.constants');
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Number of pixels the mouse must move before a drag starts.
|
|
32
|
+
*/
|
|
33
|
+
Blockly.DRAG_RADIUS = 3;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Number of pixels the mouse must move before a drag/scroll starts from the
|
|
37
|
+
* flyout. Because the drag-intention is determined when this is reached, it is
|
|
38
|
+
* larger than Blockly.DRAG_RADIUS so that the drag-direction is clearer.
|
|
39
|
+
*/
|
|
40
|
+
Blockly.FLYOUT_DRAG_RADIUS = 10;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Maximum misalignment between connections for them to snap together.
|
|
44
|
+
*/
|
|
45
|
+
Blockly.SNAP_RADIUS = 48;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Maximum misalignment between connections for them to snap together,
|
|
49
|
+
* when a connection is already highlighted.
|
|
50
|
+
*/
|
|
51
|
+
Blockly.CONNECTING_SNAP_RADIUS = 68;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* How much to prefer staying connected to the current connection over moving to
|
|
55
|
+
* a new connection. The current previewed connection is considered to be this
|
|
56
|
+
* much closer to the matching connection on the block than it actually is.
|
|
57
|
+
*/
|
|
58
|
+
Blockly.CURRENT_CONNECTION_PREFERENCE = 20;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Delay in ms between trigger and bumping unconnected block out of alignment.
|
|
62
|
+
*/
|
|
63
|
+
Blockly.BUMP_DELAY = 0;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Number of characters to truncate a collapsed block to.
|
|
67
|
+
*/
|
|
68
|
+
Blockly.COLLAPSE_CHARS = 30;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Length in ms for a touch to become a long press.
|
|
72
|
+
*/
|
|
73
|
+
Blockly.LONGPRESS = 750;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Distance to scroll when a mouse wheel event is received and its delta mode
|
|
77
|
+
* is line (0x1) instead of pixel (0x0). In these cases, a single "scroll" has
|
|
78
|
+
* a delta of 1, which makes the workspace scroll very slowly (just one pixel).
|
|
79
|
+
* To compensate, that delta is multiplied by this value.
|
|
80
|
+
* @const
|
|
81
|
+
* @package
|
|
82
|
+
*/
|
|
83
|
+
Blockly.LINE_SCROLL_MULTIPLIER = 15;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Prevent a sound from playing if another sound preceded it within this many
|
|
87
|
+
* milliseconds.
|
|
88
|
+
*/
|
|
89
|
+
Blockly.SOUND_LIMIT = 100;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* When dragging a block out of a stack, split the stack in two (true), or drag
|
|
93
|
+
* out the block healing the stack (false).
|
|
94
|
+
*/
|
|
95
|
+
Blockly.DRAG_STACK = true;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The richness of block colours, regardless of the hue.
|
|
99
|
+
* Must be in the range of 0 (inclusive) to 1 (exclusive).
|
|
100
|
+
*/
|
|
101
|
+
Blockly.HSV_SATURATION = 0.45;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The intensity of block colours, regardless of the hue.
|
|
105
|
+
* Must be in the range of 0 (inclusive) to 1 (exclusive).
|
|
106
|
+
*/
|
|
107
|
+
Blockly.HSV_VALUE = 0.65;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Sprited icons and images.
|
|
111
|
+
*/
|
|
112
|
+
Blockly.SPRITE = {
|
|
113
|
+
width: 96,
|
|
114
|
+
height: 124,
|
|
115
|
+
url: 'sprites.png'
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Constants below this point are not intended to be changed.
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Required name space for SVG elements.
|
|
122
|
+
* @const
|
|
123
|
+
*/
|
|
124
|
+
Blockly.SVG_NS = 'http://www.w3.org/2000/svg';
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Required name space for HTML elements.
|
|
128
|
+
* @const
|
|
129
|
+
*/
|
|
130
|
+
Blockly.HTML_NS = 'http://www.w3.org/1999/xhtml';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* ENUM for a right-facing value input. E.g. 'set item to' or 'return'.
|
|
134
|
+
* @const
|
|
135
|
+
*/
|
|
136
|
+
Blockly.INPUT_VALUE = 1;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* ENUM for a left-facing value output. E.g. 'random fraction'.
|
|
140
|
+
* @const
|
|
141
|
+
*/
|
|
142
|
+
Blockly.OUTPUT_VALUE = 2;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* ENUM for a down-facing block stack. E.g. 'if-do' or 'else'.
|
|
146
|
+
* @const
|
|
147
|
+
*/
|
|
148
|
+
Blockly.NEXT_STATEMENT = 3;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* ENUM for an up-facing block stack. E.g. 'break out of loop'.
|
|
152
|
+
* @const
|
|
153
|
+
*/
|
|
154
|
+
Blockly.PREVIOUS_STATEMENT = 4;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* ENUM for an dummy input. Used to add field(s) with no input.
|
|
158
|
+
* @const
|
|
159
|
+
*/
|
|
160
|
+
Blockly.DUMMY_INPUT = 5;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* ENUM for left alignment.
|
|
164
|
+
* @const
|
|
165
|
+
*/
|
|
166
|
+
Blockly.ALIGN_LEFT = -1;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* ENUM for centre alignment.
|
|
170
|
+
* @const
|
|
171
|
+
*/
|
|
172
|
+
Blockly.ALIGN_CENTRE = 0;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* ENUM for right alignment.
|
|
176
|
+
* @const
|
|
177
|
+
*/
|
|
178
|
+
Blockly.ALIGN_RIGHT = 1;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* ENUM for no drag operation.
|
|
182
|
+
* @const
|
|
183
|
+
*/
|
|
184
|
+
Blockly.DRAG_NONE = 0;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* ENUM for inside the sticky DRAG_RADIUS.
|
|
188
|
+
* @const
|
|
189
|
+
*/
|
|
190
|
+
Blockly.DRAG_STICKY = 1;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between
|
|
194
|
+
* clicks and drags.
|
|
195
|
+
* @const
|
|
196
|
+
*/
|
|
197
|
+
Blockly.DRAG_BEGIN = 1;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* ENUM for freely draggable (outside the DRAG_RADIUS, if one applies).
|
|
201
|
+
* @const
|
|
202
|
+
*/
|
|
203
|
+
Blockly.DRAG_FREE = 2;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Lookup table for determining the opposite type of a connection.
|
|
207
|
+
* @const
|
|
208
|
+
*/
|
|
209
|
+
Blockly.OPPOSITE_TYPE = [];
|
|
210
|
+
Blockly.OPPOSITE_TYPE[Blockly.INPUT_VALUE] = Blockly.OUTPUT_VALUE;
|
|
211
|
+
Blockly.OPPOSITE_TYPE[Blockly.OUTPUT_VALUE] = Blockly.INPUT_VALUE;
|
|
212
|
+
Blockly.OPPOSITE_TYPE[Blockly.NEXT_STATEMENT] = Blockly.PREVIOUS_STATEMENT;
|
|
213
|
+
Blockly.OPPOSITE_TYPE[Blockly.PREVIOUS_STATEMENT] = Blockly.NEXT_STATEMENT;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* ENUM for toolbox and flyout at top of screen.
|
|
217
|
+
* @const
|
|
218
|
+
*/
|
|
219
|
+
Blockly.TOOLBOX_AT_TOP = 0;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* ENUM for toolbox and flyout at bottom of screen.
|
|
223
|
+
* @const
|
|
224
|
+
*/
|
|
225
|
+
Blockly.TOOLBOX_AT_BOTTOM = 1;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* ENUM for toolbox and flyout at left of screen.
|
|
229
|
+
* @const
|
|
230
|
+
*/
|
|
231
|
+
Blockly.TOOLBOX_AT_LEFT = 2;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* ENUM for toolbox and flyout at right of screen.
|
|
235
|
+
* @const
|
|
236
|
+
*/
|
|
237
|
+
Blockly.TOOLBOX_AT_RIGHT = 3;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* ENUM for output shape: hexagonal (booleans/predicates).
|
|
241
|
+
* @const
|
|
242
|
+
*/
|
|
243
|
+
Blockly.OUTPUT_SHAPE_HEXAGONAL = 1;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* ENUM for output shape: rounded (numbers).
|
|
247
|
+
* @const
|
|
248
|
+
*/
|
|
249
|
+
Blockly.OUTPUT_SHAPE_ROUND = 2;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* ENUM for output shape: squared (any/all values; strings).
|
|
253
|
+
* @const
|
|
254
|
+
*/
|
|
255
|
+
Blockly.OUTPUT_SHAPE_SQUARE = 3;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* ENUM for categories.
|
|
259
|
+
* @const
|
|
260
|
+
*/
|
|
261
|
+
Blockly.Categories = {
|
|
262
|
+
"motion": "motion",
|
|
263
|
+
"looks": "looks",
|
|
264
|
+
"sound": "sounds",
|
|
265
|
+
"pen": "pen",
|
|
266
|
+
"data": "data",
|
|
267
|
+
"dataLists": "data-lists",
|
|
268
|
+
"event": "events",
|
|
269
|
+
"control": "control",
|
|
270
|
+
"sensing": "sensing",
|
|
271
|
+
"operators": "operators",
|
|
272
|
+
"more": "more"
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* ENUM representing that an event is not in any delete areas.
|
|
277
|
+
* Null for backwards compatibility reasons.
|
|
278
|
+
* @const
|
|
279
|
+
*/
|
|
280
|
+
Blockly.DELETE_AREA_NONE = null;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* ENUM representing that an event is in the delete area of the trash can.
|
|
284
|
+
* @const
|
|
285
|
+
*/
|
|
286
|
+
Blockly.DELETE_AREA_TRASH = 1;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* ENUM representing that an event is in the delete area of the toolbox or
|
|
290
|
+
* flyout.
|
|
291
|
+
* @const
|
|
292
|
+
*/
|
|
293
|
+
Blockly.DELETE_AREA_TOOLBOX = 2;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* String for use in the "custom" attribute of a category in toolbox xml.
|
|
297
|
+
* This string indicates that the category should be dynamically populated with
|
|
298
|
+
* variable blocks.
|
|
299
|
+
* @const {string}
|
|
300
|
+
*/
|
|
301
|
+
Blockly.VARIABLE_CATEGORY_NAME = 'VARIABLE';
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* String for use in the "custom" attribute of a category in toolbox xml.
|
|
305
|
+
* This string indicates that the category should be dynamically populated with
|
|
306
|
+
* procedure blocks.
|
|
307
|
+
* @const {string}
|
|
308
|
+
*/
|
|
309
|
+
Blockly.PROCEDURE_CATEGORY_NAME = 'PROCEDURE';
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* String for use in the dropdown created in field_variable.
|
|
313
|
+
* This string indicates that this option in the dropdown is 'Rename
|
|
314
|
+
* variable...' and if selected, should trigger the prompt to rename a variable.
|
|
315
|
+
* @const {string}
|
|
316
|
+
*/
|
|
317
|
+
Blockly.RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID';
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* String for use in the dropdown created in field_variable.
|
|
321
|
+
* This string indicates that this option in the dropdown is 'Delete the "%1"
|
|
322
|
+
* variable' and if selected, should trigger the prompt to delete a variable.
|
|
323
|
+
* @const {string}
|
|
324
|
+
*/
|
|
325
|
+
Blockly.DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID';
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* String for use in the dropdown created in field_variable,
|
|
329
|
+
* specifically for broadcast messages.
|
|
330
|
+
* This string indicates that this option in the dropdown is 'New message...'
|
|
331
|
+
* and if selected, should trigger the prompt to create a new message.
|
|
332
|
+
* @const {string}
|
|
333
|
+
*/
|
|
334
|
+
Blockly.NEW_BROADCAST_MESSAGE_ID = 'NEW_BROADCAST_MESSAGE_ID';
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* String representing the variable type of broadcast message blocks.
|
|
338
|
+
* This string, for use in differentiating between types of variables,
|
|
339
|
+
* indicates that the current variable is a broadcast message.
|
|
340
|
+
* @const {string}
|
|
341
|
+
*/
|
|
342
|
+
Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE = 'broadcast_msg';
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* String representing the variable type of list blocks.
|
|
346
|
+
* This string, for use in differentiating between types of variables,
|
|
347
|
+
* indicates that the current variable is a list.
|
|
348
|
+
* @const {string}
|
|
349
|
+
*/
|
|
350
|
+
Blockly.LIST_VARIABLE_TYPE = 'list';
|
|
351
|
+
|
|
352
|
+
// TODO (#1251) Replace '' below with 'scalar', and start using this constant
|
|
353
|
+
// everywhere.
|
|
354
|
+
/**
|
|
355
|
+
* String representing the variable type of scalar variables.
|
|
356
|
+
* This string, for use in differentiating between types of variables,
|
|
357
|
+
* indicates that the current variable is a scalar variable.
|
|
358
|
+
* @const {string}
|
|
359
|
+
*/
|
|
360
|
+
Blockly.SCALAR_VARIABLE_TYPE = '';
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* The type of all procedure definition blocks.
|
|
364
|
+
* @const {string}
|
|
365
|
+
*/
|
|
366
|
+
Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE = 'procedures_definition';
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* The type of all procedure prototype blocks.
|
|
370
|
+
* @const {string}
|
|
371
|
+
*/
|
|
372
|
+
Blockly.PROCEDURES_PROTOTYPE_BLOCK_TYPE = 'procedures_prototype';
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* The type of all procedure call blocks.
|
|
376
|
+
* @const {string}
|
|
377
|
+
*/
|
|
378
|
+
Blockly.PROCEDURES_CALL_BLOCK_TYPE = 'procedures_call';
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Enum for procedure call statements.
|
|
382
|
+
*/
|
|
383
|
+
Blockly.PROCEDURES_CALL_TYPE_STATEMENT = 0;
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Enum for procedure call round reporters.
|
|
387
|
+
*/
|
|
388
|
+
Blockly.PROCEDURES_CALL_TYPE_REPORTER = 1;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Enum for procedure call booleans.
|
|
392
|
+
*/
|
|
393
|
+
Blockly.PROCEDURES_CALL_TYPE_BOOLEAN = 2;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* The type of all procedure return blocks.
|
|
397
|
+
* @const {string}
|
|
398
|
+
*/
|
|
399
|
+
Blockly.PROCEDURES_RETURN_BLOCK_TYPE = 'procedures_return';
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* ENUM for flyout status button states.
|
|
403
|
+
* @const
|
|
404
|
+
*/
|
|
405
|
+
Blockly.StatusButtonState = {
|
|
406
|
+
"READY": "ready",
|
|
407
|
+
"NOT_READY": "not ready",
|
|
408
|
+
};
|