@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
package/core/blockly.js
ADDED
|
@@ -0,0 +1,620 @@
|
|
|
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 Core JavaScript library for Blockly.
|
|
23
|
+
* @author fraser@google.com (Neil Fraser)
|
|
24
|
+
*/
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The top level namespace used to access the Blockly library.
|
|
29
|
+
* @namespace Blockly
|
|
30
|
+
**/
|
|
31
|
+
goog.provide('Blockly');
|
|
32
|
+
|
|
33
|
+
goog.require('Blockly.BlockSvg.render');
|
|
34
|
+
goog.require('Blockly.DropDownDiv');
|
|
35
|
+
goog.require('Blockly.Events');
|
|
36
|
+
goog.require('Blockly.FieldAngle');
|
|
37
|
+
goog.require('Blockly.FieldCheckbox');
|
|
38
|
+
goog.require('Blockly.FieldColour');
|
|
39
|
+
goog.require('Blockly.FieldColourSlider');
|
|
40
|
+
// Date picker commented out since it increases footprint by 60%.
|
|
41
|
+
// Add it only if you need it.
|
|
42
|
+
//goog.require('Blockly.FieldDate');
|
|
43
|
+
goog.require('Blockly.FieldDropdown');
|
|
44
|
+
goog.require('Blockly.FieldIconMenu');
|
|
45
|
+
goog.require('Blockly.FieldImage');
|
|
46
|
+
goog.require('Blockly.FieldNote');
|
|
47
|
+
goog.require('Blockly.FieldTextInput');
|
|
48
|
+
goog.require('Blockly.FieldTextInputRemovable');
|
|
49
|
+
goog.require('Blockly.FieldTextDropdown');
|
|
50
|
+
goog.require('Blockly.FieldNumber');
|
|
51
|
+
goog.require('Blockly.FieldNumberDropdown');
|
|
52
|
+
goog.require('Blockly.FieldMatrix');
|
|
53
|
+
goog.require('Blockly.FieldVariable');
|
|
54
|
+
goog.require('Blockly.FieldVerticalSeparator');
|
|
55
|
+
goog.require('Blockly.Generator');
|
|
56
|
+
goog.require('Blockly.Msg');
|
|
57
|
+
goog.require('Blockly.Procedures');
|
|
58
|
+
goog.require('Blockly.ScratchMsgs');
|
|
59
|
+
goog.require('Blockly.Toolbox');
|
|
60
|
+
goog.require('Blockly.Touch');
|
|
61
|
+
goog.require('Blockly.WidgetDiv');
|
|
62
|
+
goog.require('Blockly.WorkspaceSvg');
|
|
63
|
+
goog.require('Blockly.constants');
|
|
64
|
+
goog.require('Blockly.inject');
|
|
65
|
+
goog.require('Blockly.utils');
|
|
66
|
+
goog.require('goog.color');
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// Turn off debugging when compiled.
|
|
70
|
+
/* eslint-disable no-unused-vars */
|
|
71
|
+
var CLOSURE_DEFINES = {'goog.DEBUG': false};
|
|
72
|
+
/* eslint-enable no-unused-vars */
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The main workspace most recently used.
|
|
76
|
+
* Set by Blockly.WorkspaceSvg.prototype.markFocused
|
|
77
|
+
* @type {Blockly.Workspace}
|
|
78
|
+
*/
|
|
79
|
+
Blockly.mainWorkspace = null;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Currently selected block.
|
|
83
|
+
* @type {Blockly.Block}
|
|
84
|
+
*/
|
|
85
|
+
Blockly.selected = null;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* All of the connections on blocks that are currently being dragged.
|
|
89
|
+
* @type {!Array.<!Blockly.Connection>}
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
Blockly.draggingConnections_ = [];
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Contents of the local clipboard.
|
|
96
|
+
* @type {Element}
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
Blockly.clipboardXml_ = null;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Source of the local clipboard.
|
|
103
|
+
* @type {Blockly.WorkspaceSvg}
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
Blockly.clipboardSource_ = null;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Cached value for whether 3D is supported.
|
|
110
|
+
* @type {!boolean}
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
Blockly.cache3dSupported_ = null;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Convert a hue (HSV model) into an RGB hex triplet.
|
|
117
|
+
* @param {number} hue Hue on a colour wheel (0-360).
|
|
118
|
+
* @return {string} RGB code, e.g. '#5ba65b'.
|
|
119
|
+
*/
|
|
120
|
+
Blockly.hueToRgb = function(hue) {
|
|
121
|
+
return goog.color.hsvToHex(hue, Blockly.HSV_SATURATION,
|
|
122
|
+
Blockly.HSV_VALUE * 255);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Returns the dimensions of the specified SVG image.
|
|
127
|
+
* @param {!Element} svg SVG image.
|
|
128
|
+
* @return {!Object} Contains width and height properties.
|
|
129
|
+
*/
|
|
130
|
+
Blockly.svgSize = function(svg) {
|
|
131
|
+
return {
|
|
132
|
+
width: svg.cachedWidth_,
|
|
133
|
+
height: svg.cachedHeight_
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Size the workspace when the contents change. This also updates
|
|
139
|
+
* scrollbars accordingly.
|
|
140
|
+
* @param {!Blockly.WorkspaceSvg} workspace The workspace to resize.
|
|
141
|
+
*/
|
|
142
|
+
Blockly.resizeSvgContents = function(workspace) {
|
|
143
|
+
workspace.resizeContents();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Size the SVG image to completely fill its container. Call this when the view
|
|
148
|
+
* actually changes sizes (e.g. on a window resize/device orientation change).
|
|
149
|
+
* See Blockly.resizeSvgContents to resize the workspace when the contents
|
|
150
|
+
* change (e.g. when a block is added or removed).
|
|
151
|
+
* Record the height/width of the SVG image.
|
|
152
|
+
* @param {!Blockly.WorkspaceSvg} workspace Any workspace in the SVG.
|
|
153
|
+
*/
|
|
154
|
+
Blockly.svgResize = function(workspace) {
|
|
155
|
+
var mainWorkspace = workspace;
|
|
156
|
+
while (mainWorkspace.options.parentWorkspace) {
|
|
157
|
+
mainWorkspace = mainWorkspace.options.parentWorkspace;
|
|
158
|
+
}
|
|
159
|
+
var svg = mainWorkspace.getParentSvg();
|
|
160
|
+
var div = svg.parentNode;
|
|
161
|
+
if (!div) {
|
|
162
|
+
// Workspace deleted, or something.
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
var width = div.offsetWidth;
|
|
166
|
+
var height = div.offsetHeight;
|
|
167
|
+
if (svg.cachedWidth_ != width) {
|
|
168
|
+
svg.setAttribute('width', width + 'px');
|
|
169
|
+
svg.cachedWidth_ = width;
|
|
170
|
+
}
|
|
171
|
+
if (svg.cachedHeight_ != height) {
|
|
172
|
+
svg.setAttribute('height', height + 'px');
|
|
173
|
+
svg.cachedHeight_ = height;
|
|
174
|
+
}
|
|
175
|
+
mainWorkspace.resize();
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Handle a key-down on SVG drawing surface. Does nothing if the main workspace is not visible.
|
|
180
|
+
* @param {!Event} e Key down event.
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
// TODO (https://github.com/google/blockly/issues/1998) handle cases where there are multiple workspaces
|
|
184
|
+
// and non-main workspaces are able to accept input.
|
|
185
|
+
Blockly.onKeyDown_ = function(e) {
|
|
186
|
+
if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e)
|
|
187
|
+
|| (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible())) {
|
|
188
|
+
// No key actions on readonly workspaces.
|
|
189
|
+
// When focused on an HTML text input widget, don't trap any keys.
|
|
190
|
+
// Ignore keypresses on rendered workspaces that have been explicitly
|
|
191
|
+
// hidden.
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
var deleteBlock = false;
|
|
195
|
+
if (e.keyCode == 27) {
|
|
196
|
+
// Pressing esc closes the context menu and any drop-down
|
|
197
|
+
Blockly.hideChaff();
|
|
198
|
+
Blockly.DropDownDiv.hide();
|
|
199
|
+
} else if (e.keyCode == 8 || e.keyCode == 46) {
|
|
200
|
+
// Delete or backspace.
|
|
201
|
+
// Stop the browser from going back to the previous page.
|
|
202
|
+
// Do this first to prevent an error in the delete code from resulting in
|
|
203
|
+
// data loss.
|
|
204
|
+
e.preventDefault();
|
|
205
|
+
// Don't delete while dragging. Jeez.
|
|
206
|
+
if (Blockly.mainWorkspace.isDragging()) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (Blockly.selected && Blockly.selected.isDeletable()) {
|
|
210
|
+
deleteBlock = true;
|
|
211
|
+
}
|
|
212
|
+
} else if (e.altKey || e.ctrlKey || e.metaKey) {
|
|
213
|
+
// Don't use meta keys during drags.
|
|
214
|
+
if (Blockly.mainWorkspace.isDragging()) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (Blockly.selected &&
|
|
218
|
+
Blockly.selected.isDeletable() && Blockly.selected.isMovable()) {
|
|
219
|
+
// Don't allow copying immovable or undeletable blocks. The next step
|
|
220
|
+
// would be to paste, which would create additional undeletable/immovable
|
|
221
|
+
// blocks on the workspace.
|
|
222
|
+
if (e.keyCode == 67) {
|
|
223
|
+
// 'c' for copy.
|
|
224
|
+
Blockly.hideChaff();
|
|
225
|
+
Blockly.copy_(Blockly.selected);
|
|
226
|
+
} else if (e.keyCode == 88 && !Blockly.selected.workspace.isFlyout) {
|
|
227
|
+
// 'x' for cut, but not in a flyout.
|
|
228
|
+
// Don't even copy the selected item in the flyout.
|
|
229
|
+
Blockly.copy_(Blockly.selected);
|
|
230
|
+
deleteBlock = true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (e.keyCode == 86) {
|
|
234
|
+
// 'v' for paste.
|
|
235
|
+
if (Blockly.clipboardXml_) {
|
|
236
|
+
Blockly.Events.setGroup(true);
|
|
237
|
+
// Pasting always pastes to the main workspace, even if the copy started
|
|
238
|
+
// in a flyout workspace.
|
|
239
|
+
var workspace = Blockly.clipboardSource_;
|
|
240
|
+
if (workspace.isFlyout) {
|
|
241
|
+
workspace = workspace.targetWorkspace;
|
|
242
|
+
}
|
|
243
|
+
workspace.paste(Blockly.clipboardXml_);
|
|
244
|
+
Blockly.Events.setGroup(false);
|
|
245
|
+
}
|
|
246
|
+
} else if (e.keyCode == 90 || e.keyCode === 89) {
|
|
247
|
+
// 'z' for undo 'Z' is for redo. 'y' is always redo.
|
|
248
|
+
e.preventDefault();
|
|
249
|
+
Blockly.hideChaff();
|
|
250
|
+
Blockly.mainWorkspace.undo(e.shiftKey || e.keyCode === 89);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Common code for delete and cut.
|
|
254
|
+
// Don't delete in the flyout.
|
|
255
|
+
if (deleteBlock && !Blockly.selected.workspace.isFlyout) {
|
|
256
|
+
Blockly.Events.setGroup(true);
|
|
257
|
+
Blockly.hideChaff();
|
|
258
|
+
Blockly.selected.dispose(/* heal */ true, true);
|
|
259
|
+
Blockly.Events.setGroup(false);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Copy a block or workspace comment onto the local clipboard.
|
|
265
|
+
* @param {!Blockly.Block | !Blockly.WorkspaceComment} toCopy Block or Workspace Comment
|
|
266
|
+
* to be copied.
|
|
267
|
+
* @private
|
|
268
|
+
*/
|
|
269
|
+
Blockly.copy_ = function(toCopy) {
|
|
270
|
+
if (toCopy.isComment) {
|
|
271
|
+
var xml = toCopy.toXmlWithXY();
|
|
272
|
+
} else {
|
|
273
|
+
var xml = Blockly.Xml.blockToDom(toCopy);
|
|
274
|
+
// Encode start position in XML.
|
|
275
|
+
var xy = toCopy.getRelativeToSurfaceXY();
|
|
276
|
+
xml.setAttribute('x', toCopy.RTL ? -xy.x : xy.x);
|
|
277
|
+
xml.setAttribute('y', xy.y);
|
|
278
|
+
}
|
|
279
|
+
Blockly.clipboardXml_ = xml;
|
|
280
|
+
Blockly.clipboardSource_ = toCopy.workspace;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Duplicate this block and its children, or a workspace comment.
|
|
285
|
+
* @param {!Blockly.Block | !Blockly.WorkspaceComment} toDuplicate Block or
|
|
286
|
+
* Workspace Comment to be copied.
|
|
287
|
+
* @private
|
|
288
|
+
*/
|
|
289
|
+
Blockly.duplicate_ = function(toDuplicate) {
|
|
290
|
+
// Save the clipboard.
|
|
291
|
+
var clipboardXml = Blockly.clipboardXml_;
|
|
292
|
+
var clipboardSource = Blockly.clipboardSource_;
|
|
293
|
+
|
|
294
|
+
// Create a duplicate via a copy/paste operation.
|
|
295
|
+
Blockly.copy_(toDuplicate);
|
|
296
|
+
toDuplicate.workspace.paste(Blockly.clipboardXml_);
|
|
297
|
+
|
|
298
|
+
// Restore the clipboard.
|
|
299
|
+
Blockly.clipboardXml_ = clipboardXml;
|
|
300
|
+
Blockly.clipboardSource_ = clipboardSource;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Cancel the native context menu, unless the focus is on an HTML input widget.
|
|
305
|
+
* @param {!Event} e Mouse down event.
|
|
306
|
+
* @private
|
|
307
|
+
*/
|
|
308
|
+
Blockly.onContextMenu_ = function(e) {
|
|
309
|
+
if (!Blockly.utils.isTargetInput(e)) {
|
|
310
|
+
// When focused on an HTML text input widget, don't cancel the context menu.
|
|
311
|
+
e.preventDefault();
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Close tooltips, context menus, dropdown selections, etc.
|
|
317
|
+
* @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
|
|
318
|
+
*/
|
|
319
|
+
Blockly.hideChaff = function(opt_allowToolbox) {
|
|
320
|
+
Blockly.hideChaffInternal_(opt_allowToolbox);
|
|
321
|
+
Blockly.WidgetDiv.hide(true);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Close tooltips, context menus, dropdown selections, etc.
|
|
326
|
+
* For some elements (e.g. field text inputs), rather than hiding, it will
|
|
327
|
+
* move them.
|
|
328
|
+
* @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
|
|
329
|
+
*/
|
|
330
|
+
Blockly.hideChaffOnResize = function(opt_allowToolbox) {
|
|
331
|
+
Blockly.hideChaffInternal_(opt_allowToolbox);
|
|
332
|
+
Blockly.WidgetDiv.repositionForWindowResize();
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Does a majority of the work for hideChaff including tooltips, dropdowns,
|
|
337
|
+
* toolbox, etc. It does not deal with the WidgetDiv.
|
|
338
|
+
* @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
|
|
339
|
+
* @private
|
|
340
|
+
*/
|
|
341
|
+
Blockly.hideChaffInternal_ = function(opt_allowToolbox) {
|
|
342
|
+
Blockly.Tooltip.hide();
|
|
343
|
+
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
344
|
+
if (!opt_allowToolbox) {
|
|
345
|
+
var workspace = Blockly.getMainWorkspace();
|
|
346
|
+
if (workspace.toolbox_ &&
|
|
347
|
+
workspace.toolbox_.flyout_ &&
|
|
348
|
+
workspace.toolbox_.flyout_.autoClose) {
|
|
349
|
+
workspace.toolbox_.clearSelection();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Returns the main workspace. Returns the last used main workspace (based on
|
|
356
|
+
* focus). Try not to use this function, particularly if there are multiple
|
|
357
|
+
* Blockly instances on a page.
|
|
358
|
+
* @return {!Blockly.Workspace} The main workspace.
|
|
359
|
+
*/
|
|
360
|
+
Blockly.getMainWorkspace = function() {
|
|
361
|
+
return Blockly.mainWorkspace;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Wrapper to window.alert() that app developers may override to
|
|
366
|
+
* provide alternatives to the modal browser window.
|
|
367
|
+
* @param {string} message The message to display to the user.
|
|
368
|
+
* @param {function()=} opt_callback The callback when the alert is dismissed.
|
|
369
|
+
*/
|
|
370
|
+
Blockly.alert = function(message, opt_callback) {
|
|
371
|
+
window.alert(message);
|
|
372
|
+
if (opt_callback) {
|
|
373
|
+
opt_callback();
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Wrapper to window.confirm() that app developers may override to
|
|
379
|
+
* provide alternatives to the modal browser window.
|
|
380
|
+
* @param {string} message The message to display to the user.
|
|
381
|
+
* @param {!function(boolean)} callback The callback for handling user response.
|
|
382
|
+
*/
|
|
383
|
+
Blockly.confirm = function(message, callback) {
|
|
384
|
+
callback(window.confirm(message));
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Wrapper to window.prompt() that app developers may override to provide
|
|
389
|
+
* alternatives to the modal browser window. Built-in browser prompts are
|
|
390
|
+
* often used for better text input experience on mobile device. We strongly
|
|
391
|
+
* recommend testing mobile when overriding this.
|
|
392
|
+
* @param {string} message The message to display to the user.
|
|
393
|
+
* @param {string} defaultValue The value to initialize the prompt with.
|
|
394
|
+
* @param {!function(string)} callback The callback for handling user response.
|
|
395
|
+
* @param {?string} _opt_title An optional title for the prompt.
|
|
396
|
+
* @param {?string} _opt_varType An optional variable type for variable specific
|
|
397
|
+
* prompt behavior.
|
|
398
|
+
*/
|
|
399
|
+
Blockly.prompt = function(message, defaultValue, callback, _opt_title,
|
|
400
|
+
_opt_varType) {
|
|
401
|
+
// opt_title and opt_varType are unused because we only need them to pass
|
|
402
|
+
// information to the scratch-gui, which overwrites this function
|
|
403
|
+
callback(window.prompt(message, defaultValue));
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* A callback for status buttons. The window.alert is here for testing and
|
|
408
|
+
* should be overridden.
|
|
409
|
+
* @param {string} id An identifier.
|
|
410
|
+
*/
|
|
411
|
+
Blockly.statusButtonCallback = function(id) {
|
|
412
|
+
window.alert('status button was pressed for ' + id);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Refresh the visual state of a status button in all extension category headers.
|
|
417
|
+
* @param {Blockly.Workspace} workspace A workspace.
|
|
418
|
+
*/
|
|
419
|
+
Blockly.refreshStatusButtons = function(workspace) {
|
|
420
|
+
var buttons = workspace.getFlyout().buttons_;
|
|
421
|
+
for (var i = 0; i < buttons.length; i++) {
|
|
422
|
+
if (buttons[i] instanceof Blockly.FlyoutExtensionCategoryHeader) {
|
|
423
|
+
buttons[i].refreshStatus();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Helper function for defining a block from JSON. The resulting function has
|
|
430
|
+
* the correct value of jsonDef at the point in code where jsonInit is called.
|
|
431
|
+
* @param {!Object} jsonDef The JSON definition of a block.
|
|
432
|
+
* @return {function()} A function that calls jsonInit with the correct value
|
|
433
|
+
* of jsonDef.
|
|
434
|
+
* @private
|
|
435
|
+
*/
|
|
436
|
+
Blockly.jsonInitFactory_ = function(jsonDef) {
|
|
437
|
+
return function() {
|
|
438
|
+
this.jsonInit(jsonDef);
|
|
439
|
+
};
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Define blocks from an array of JSON block definitions, as might be generated
|
|
444
|
+
* by the Blockly Developer Tools.
|
|
445
|
+
* @param {!Array.<!Object>} jsonArray An array of JSON block definitions.
|
|
446
|
+
*/
|
|
447
|
+
Blockly.defineBlocksWithJsonArray = function(jsonArray) {
|
|
448
|
+
for (var i = 0; i < jsonArray.length; i++) {
|
|
449
|
+
var elem = jsonArray[i];
|
|
450
|
+
if (!elem) {
|
|
451
|
+
console.warn(
|
|
452
|
+
'Block definition #' + i + ' in JSON array is ' + elem + '. ' +
|
|
453
|
+
'Skipping.');
|
|
454
|
+
} else {
|
|
455
|
+
var typename = elem.type;
|
|
456
|
+
if (typename == null || typename === '') {
|
|
457
|
+
console.warn(
|
|
458
|
+
'Block definition #' + i +
|
|
459
|
+
' in JSON array is missing a type attribute. Skipping.');
|
|
460
|
+
} else {
|
|
461
|
+
Blockly.Blocks[typename] = {
|
|
462
|
+
init: Blockly.jsonInitFactory_(elem)
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Bind an event to a function call. When calling the function, verifies that
|
|
471
|
+
* it belongs to the touch stream that is currently being processed, and splits
|
|
472
|
+
* multitouch events into multiple events as needed.
|
|
473
|
+
* @param {!EventTarget} node Node upon which to listen.
|
|
474
|
+
* @param {string} name Event name to listen to (e.g. 'mousedown').
|
|
475
|
+
* @param {Object} thisObject The value of 'this' in the function.
|
|
476
|
+
* @param {!Function} func Function to call when event is triggered.
|
|
477
|
+
* @param {boolean=} opt_noCaptureIdentifier True if triggering on this event
|
|
478
|
+
* should not block execution of other event handlers on this touch or other
|
|
479
|
+
* simultaneous touches.
|
|
480
|
+
* @param {boolean=} opt_noPreventDefault True if triggering on this event
|
|
481
|
+
* should prevent the default handler. False by default. If
|
|
482
|
+
* opt_noPreventDefault is provided, opt_noCaptureIdentifier must also be
|
|
483
|
+
* provided.
|
|
484
|
+
* @return {!Array.<!Array>} Opaque data that can be passed to unbindEvent_.
|
|
485
|
+
*/
|
|
486
|
+
Blockly.bindEventWithChecks_ = function(node, name, thisObject, func,
|
|
487
|
+
opt_noCaptureIdentifier, opt_noPreventDefault) {
|
|
488
|
+
var handled = false;
|
|
489
|
+
var wrapFunc = function(e) {
|
|
490
|
+
var captureIdentifier = !opt_noCaptureIdentifier;
|
|
491
|
+
// Handle each touch point separately. If the event was a mouse event, this
|
|
492
|
+
// will hand back an array with one element, which we're fine handling.
|
|
493
|
+
var events = Blockly.Touch.splitEventByTouches(e);
|
|
494
|
+
for (var i = 0, event; event = events[i]; i++) {
|
|
495
|
+
if (captureIdentifier && !Blockly.Touch.shouldHandleEvent(event)) {
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
Blockly.Touch.setClientFromTouch(event);
|
|
499
|
+
if (thisObject) {
|
|
500
|
+
func.call(thisObject, event);
|
|
501
|
+
} else {
|
|
502
|
+
func(event);
|
|
503
|
+
}
|
|
504
|
+
handled = true;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
node.addEventListener(name, wrapFunc, false);
|
|
509
|
+
var bindData = [[node, name, wrapFunc]];
|
|
510
|
+
|
|
511
|
+
// Add equivalent touch event.
|
|
512
|
+
if (name in Blockly.Touch.TOUCH_MAP) {
|
|
513
|
+
var touchWrapFunc = function(e) {
|
|
514
|
+
wrapFunc(e);
|
|
515
|
+
// Calling preventDefault stops the browser from scrolling/zooming the
|
|
516
|
+
// page.
|
|
517
|
+
var preventDef = !opt_noPreventDefault;
|
|
518
|
+
if (handled && preventDef) {
|
|
519
|
+
e.preventDefault();
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
for (var i = 0, type; type = Blockly.Touch.TOUCH_MAP[name][i]; i++) {
|
|
523
|
+
node.addEventListener(type, touchWrapFunc, false);
|
|
524
|
+
bindData.push([node, type, touchWrapFunc]);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return bindData;
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Bind an event to a function call. Handles multitouch events by using the
|
|
533
|
+
* coordinates of the first changed touch, and doesn't do any safety checks for
|
|
534
|
+
* simultaneous event processing.
|
|
535
|
+
* @deprecated in favor of bindEventWithChecks_, but preserved for external
|
|
536
|
+
* users.
|
|
537
|
+
* @param {!EventTarget} node Node upon which to listen.
|
|
538
|
+
* @param {string} name Event name to listen to (e.g. 'mousedown').
|
|
539
|
+
* @param {Object} thisObject The value of 'this' in the function.
|
|
540
|
+
* @param {!Function} func Function to call when event is triggered.
|
|
541
|
+
* @return {!Array.<!Array>} Opaque data that can be passed to unbindEvent_.
|
|
542
|
+
* @private
|
|
543
|
+
*/
|
|
544
|
+
Blockly.bindEvent_ = function(node, name, thisObject, func) {
|
|
545
|
+
var wrapFunc = function(e) {
|
|
546
|
+
if (thisObject) {
|
|
547
|
+
func.call(thisObject, e);
|
|
548
|
+
} else {
|
|
549
|
+
func(e);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
node.addEventListener(name, wrapFunc, false);
|
|
554
|
+
var bindData = [[node, name, wrapFunc]];
|
|
555
|
+
|
|
556
|
+
// Add equivalent touch event.
|
|
557
|
+
if (name in Blockly.Touch.TOUCH_MAP) {
|
|
558
|
+
var touchWrapFunc = function(e) {
|
|
559
|
+
// Punt on multitouch events.
|
|
560
|
+
if (e.changedTouches.length == 1) {
|
|
561
|
+
// Map the touch event's properties to the event.
|
|
562
|
+
var touchPoint = e.changedTouches[0];
|
|
563
|
+
e.clientX = touchPoint.clientX;
|
|
564
|
+
e.clientY = touchPoint.clientY;
|
|
565
|
+
}
|
|
566
|
+
wrapFunc(e);
|
|
567
|
+
|
|
568
|
+
// Stop the browser from scrolling/zooming the page.
|
|
569
|
+
e.preventDefault();
|
|
570
|
+
};
|
|
571
|
+
for (var i = 0, type; type = Blockly.Touch.TOUCH_MAP[name][i]; i++) {
|
|
572
|
+
node.addEventListener(type, touchWrapFunc, false);
|
|
573
|
+
bindData.push([node, type, touchWrapFunc]);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return bindData;
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Unbind one or more events event from a function call.
|
|
581
|
+
* @param {!Array.<!Array>} bindData Opaque data from bindEvent_.
|
|
582
|
+
* This list is emptied during the course of calling this function.
|
|
583
|
+
* @return {!Function} The function call.
|
|
584
|
+
* @private
|
|
585
|
+
*/
|
|
586
|
+
Blockly.unbindEvent_ = function(bindData) {
|
|
587
|
+
while (bindData.length) {
|
|
588
|
+
var bindDatum = bindData.pop();
|
|
589
|
+
var node = bindDatum[0];
|
|
590
|
+
var name = bindDatum[1];
|
|
591
|
+
var func = bindDatum[2];
|
|
592
|
+
node.removeEventListener(name, func, false);
|
|
593
|
+
}
|
|
594
|
+
return func;
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Is the given string a number (includes negative and decimals).
|
|
599
|
+
* @param {string} str Input string.
|
|
600
|
+
* @return {boolean} True if number, false otherwise.
|
|
601
|
+
*/
|
|
602
|
+
Blockly.isNumber = function(str) {
|
|
603
|
+
return !!str.match(/^\s*-?\d+(\.\d+)?\s*$/);
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
// IE9 does not have a console. Create a stub to stop errors.
|
|
607
|
+
if (!goog.global['console']) {
|
|
608
|
+
goog.global['console'] = {
|
|
609
|
+
'log': function() {},
|
|
610
|
+
'warn': function() {}
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// Export symbols that would otherwise be renamed by Closure compiler.
|
|
615
|
+
if (!goog.global['Blockly']) {
|
|
616
|
+
goog.global['Blockly'] = {};
|
|
617
|
+
}
|
|
618
|
+
goog.global['Blockly']['getMainWorkspace'] = Blockly.getMainWorkspace;
|
|
619
|
+
goog.global['Blockly']['goog'] = goog;
|
|
620
|
+
Blockly.goog = goog;
|
package/core/blocks.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Visual Blocks Editor
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2013 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 A mapping of block type names to block prototype objects.
|
|
23
|
+
* @author spertus@google.com (Ellen Spertus)
|
|
24
|
+
*/
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A mapping of block type names to block prototype objects.
|
|
29
|
+
* @name Blockly.Blocks
|
|
30
|
+
*/
|
|
31
|
+
goog.provide('Blockly.Blocks');
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* A mapping of block type names to block prototype objects.
|
|
35
|
+
* @type {!Object.<string,Object>}
|
|
36
|
+
*/
|
|
37
|
+
Blockly.Blocks = new Object(null);
|