@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/warning.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Visual Blocks Editor
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2012 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 Object representing a warning.
|
|
23
|
+
* @author fraser@google.com (Neil Fraser)
|
|
24
|
+
*/
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
goog.provide('Blockly.Warning');
|
|
28
|
+
|
|
29
|
+
goog.require('Blockly.Bubble');
|
|
30
|
+
goog.require('Blockly.Events.Ui');
|
|
31
|
+
goog.require('Blockly.Icon');
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Class for a warning.
|
|
36
|
+
* @param {!Blockly.Block} block The block associated with this warning.
|
|
37
|
+
* @extends {Blockly.Icon}
|
|
38
|
+
* @constructor
|
|
39
|
+
*/
|
|
40
|
+
Blockly.Warning = function(block) {
|
|
41
|
+
Blockly.Warning.superClass_.constructor.call(this, block);
|
|
42
|
+
this.createIcon();
|
|
43
|
+
// The text_ object can contain multiple warnings.
|
|
44
|
+
this.text_ = {};
|
|
45
|
+
};
|
|
46
|
+
goog.inherits(Blockly.Warning, Blockly.Icon);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Does this icon get hidden when the block is collapsed.
|
|
50
|
+
*/
|
|
51
|
+
Blockly.Warning.prototype.collapseHidden = false;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Draw the warning icon.
|
|
55
|
+
* @param {!Element} group The icon group.
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
Blockly.Warning.prototype.drawIcon_ = function(group) {
|
|
59
|
+
// Triangle with rounded corners.
|
|
60
|
+
Blockly.utils.createSvgElement('path',
|
|
61
|
+
{
|
|
62
|
+
'class': 'blocklyIconShape',
|
|
63
|
+
'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z'
|
|
64
|
+
},
|
|
65
|
+
group);
|
|
66
|
+
// Can't use a real '!' text character since different browsers and operating
|
|
67
|
+
// systems render it differently.
|
|
68
|
+
// Body of exclamation point.
|
|
69
|
+
Blockly.utils.createSvgElement('path',
|
|
70
|
+
{
|
|
71
|
+
'class': 'blocklyIconSymbol',
|
|
72
|
+
'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z'
|
|
73
|
+
},
|
|
74
|
+
group);
|
|
75
|
+
// Dot of exclamation point.
|
|
76
|
+
Blockly.utils.createSvgElement('rect',
|
|
77
|
+
{
|
|
78
|
+
'class': 'blocklyIconSymbol',
|
|
79
|
+
'x': '7',
|
|
80
|
+
'y': '11',
|
|
81
|
+
'height': '2',
|
|
82
|
+
'width': '2'
|
|
83
|
+
},
|
|
84
|
+
group);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Create the text for the warning's bubble.
|
|
89
|
+
* @param {string} text The text to display.
|
|
90
|
+
* @return {!SVGTextElement} The top-level node of the text.
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
Blockly.Warning.textToDom_ = function(text) {
|
|
94
|
+
var paragraph = /** @type {!SVGTextElement} */
|
|
95
|
+
(Blockly.utils.createSvgElement(
|
|
96
|
+
'text',
|
|
97
|
+
{
|
|
98
|
+
'class': 'blocklyText blocklyBubbleText',
|
|
99
|
+
'y': Blockly.Bubble.BORDER_WIDTH
|
|
100
|
+
},
|
|
101
|
+
null)
|
|
102
|
+
);
|
|
103
|
+
var lines = text.split('\n');
|
|
104
|
+
for (var i = 0; i < lines.length; i++) {
|
|
105
|
+
var tspanElement = Blockly.utils.createSvgElement('tspan',
|
|
106
|
+
{'dy': '1em', 'x': Blockly.Bubble.BORDER_WIDTH}, paragraph);
|
|
107
|
+
var textNode = document.createTextNode(lines[i]);
|
|
108
|
+
tspanElement.appendChild(textNode);
|
|
109
|
+
}
|
|
110
|
+
return paragraph;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Show or hide the warning bubble.
|
|
115
|
+
* @param {boolean} visible True if the bubble should be visible.
|
|
116
|
+
*/
|
|
117
|
+
Blockly.Warning.prototype.setVisible = function(visible) {
|
|
118
|
+
if (visible == this.isVisible()) {
|
|
119
|
+
// No change.
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
Blockly.Events.fire(
|
|
123
|
+
new Blockly.Events.Ui(this.block_, 'warningOpen', !visible, visible));
|
|
124
|
+
if (visible) {
|
|
125
|
+
// Create the bubble to display all warnings.
|
|
126
|
+
var paragraph = Blockly.Warning.textToDom_(this.getText());
|
|
127
|
+
this.bubble_ = new Blockly.Bubble(
|
|
128
|
+
/** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace),
|
|
129
|
+
paragraph, this.block_.svgPath_, this.iconXY_, null, null);
|
|
130
|
+
if (this.block_.RTL) {
|
|
131
|
+
// Right-align the paragraph.
|
|
132
|
+
// This cannot be done until the bubble is rendered on screen.
|
|
133
|
+
var maxWidth = paragraph.getBBox().width;
|
|
134
|
+
for (var i = 0, textElement; textElement = paragraph.childNodes[i]; i++) {
|
|
135
|
+
textElement.setAttribute('text-anchor', 'end');
|
|
136
|
+
textElement.setAttribute('x', maxWidth + Blockly.Bubble.BORDER_WIDTH);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.updateColour();
|
|
140
|
+
// Bump the warning into the right location.
|
|
141
|
+
var size = this.bubble_.getBubbleSize();
|
|
142
|
+
this.bubble_.setBubbleSize(size.width, size.height);
|
|
143
|
+
} else {
|
|
144
|
+
// Dispose of the bubble.
|
|
145
|
+
this.bubble_.dispose();
|
|
146
|
+
this.bubble_ = null;
|
|
147
|
+
this.body_ = null;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Bring the warning to the top of the stack when clicked on.
|
|
153
|
+
* @param {!Event} _e Mouse up event.
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
Blockly.Warning.prototype.bodyFocus_ = function(_e) {
|
|
157
|
+
this.bubble_.promote_();
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Set this warning's text.
|
|
162
|
+
* @param {string} text Warning text (or '' to delete).
|
|
163
|
+
* @param {string} id An ID for this text entry to be able to maintain
|
|
164
|
+
* multiple warnings.
|
|
165
|
+
*/
|
|
166
|
+
Blockly.Warning.prototype.setText = function(text, id) {
|
|
167
|
+
if (this.text_[id] == text) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (text) {
|
|
171
|
+
this.text_[id] = text;
|
|
172
|
+
} else {
|
|
173
|
+
delete this.text_[id];
|
|
174
|
+
}
|
|
175
|
+
if (this.isVisible()) {
|
|
176
|
+
this.setVisible(false);
|
|
177
|
+
this.setVisible(true);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get this warning's texts.
|
|
183
|
+
* @return {string} All texts concatenated into one string.
|
|
184
|
+
*/
|
|
185
|
+
Blockly.Warning.prototype.getText = function() {
|
|
186
|
+
var allWarnings = [];
|
|
187
|
+
for (var id in this.text_) {
|
|
188
|
+
allWarnings.push(this.text_[id]);
|
|
189
|
+
}
|
|
190
|
+
return allWarnings.join('\n');
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Dispose of this warning.
|
|
195
|
+
*/
|
|
196
|
+
Blockly.Warning.prototype.dispose = function() {
|
|
197
|
+
this.block_.warning = null;
|
|
198
|
+
Blockly.Icon.prototype.dispose.call(this);
|
|
199
|
+
};
|
|
@@ -0,0 +1,344 @@
|
|
|
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 div that floats on top of Blockly. This singleton contains
|
|
23
|
+
* temporary HTML UI widgets that the user is currently interacting with.
|
|
24
|
+
* E.g. text input areas, colour pickers, context menus.
|
|
25
|
+
* @author fraser@google.com (Neil Fraser)
|
|
26
|
+
*/
|
|
27
|
+
'use strict';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @name Blockly.WidgetDiv
|
|
31
|
+
* @namespace
|
|
32
|
+
**/
|
|
33
|
+
goog.provide('Blockly.WidgetDiv');
|
|
34
|
+
|
|
35
|
+
goog.require('Blockly.Css');
|
|
36
|
+
goog.require('goog.dom');
|
|
37
|
+
goog.require('goog.dom.TagName');
|
|
38
|
+
goog.require('goog.style');
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The HTML container. Set once by Blockly.WidgetDiv.createDom.
|
|
43
|
+
* @type {Element}
|
|
44
|
+
*/
|
|
45
|
+
Blockly.WidgetDiv.DIV = null;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The object currently using this container.
|
|
49
|
+
* @type {Object}
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
Blockly.WidgetDiv.owner_ = null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Optional cleanup function set by whichever object uses the widget.
|
|
56
|
+
* This is called as soon as a dispose is desired. If the dispose should
|
|
57
|
+
* be animated, the animation should start on the call of dispose_.
|
|
58
|
+
* @type {Function}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
Blockly.WidgetDiv.dispose_ = null;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Optional function called at the end of a dispose animation.
|
|
65
|
+
* Set by whichever object is using the widget.
|
|
66
|
+
* @type {Function}
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
Blockly.WidgetDiv.disposeAnimationFinished_ = null;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Timer ID for the dispose animation.
|
|
73
|
+
* @type {number}
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
Blockly.WidgetDiv.disposeAnimationTimer_ = null;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Length of time in seconds for the dispose animation.
|
|
80
|
+
* @type {number}
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
Blockly.WidgetDiv.disposeAnimationTimerLength_ = 0;
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Create the widget div and inject it onto the page.
|
|
88
|
+
*/
|
|
89
|
+
Blockly.WidgetDiv.createDom = function() {
|
|
90
|
+
if (Blockly.WidgetDiv.DIV) {
|
|
91
|
+
return; // Already created.
|
|
92
|
+
}
|
|
93
|
+
// Create an HTML container for popup overlays (e.g. editor widgets).
|
|
94
|
+
Blockly.WidgetDiv.DIV =
|
|
95
|
+
goog.dom.createDom(goog.dom.TagName.DIV, 'blocklyWidgetDiv');
|
|
96
|
+
document.body.appendChild(Blockly.WidgetDiv.DIV);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Initialize and display the widget div. Close the old one if needed.
|
|
101
|
+
* @param {!Object} newOwner The object that will be using this container.
|
|
102
|
+
* @param {boolean} rtl Right-to-left (true) or left-to-right (false).
|
|
103
|
+
* @param {Function=} opt_dispose Optional cleanup function to be run when the widget
|
|
104
|
+
* is closed. If the dispose is animated, this function must start the animation.
|
|
105
|
+
* @param {Function=} opt_disposeAnimationFinished Optional cleanup function to be run
|
|
106
|
+
* when the widget is done animating and must disappear.
|
|
107
|
+
* @param {number=} opt_disposeAnimationTimerLength Length of animation time in seconds
|
|
108
|
+
if a dispose animation is provided.
|
|
109
|
+
*/
|
|
110
|
+
Blockly.WidgetDiv.show = function(newOwner, rtl, opt_dispose,
|
|
111
|
+
opt_disposeAnimationFinished, opt_disposeAnimationTimerLength) {
|
|
112
|
+
Blockly.WidgetDiv.hide();
|
|
113
|
+
Blockly.WidgetDiv.owner_ = newOwner;
|
|
114
|
+
Blockly.WidgetDiv.dispose_ = opt_dispose;
|
|
115
|
+
Blockly.WidgetDiv.disposeAnimationFinished_ = opt_disposeAnimationFinished;
|
|
116
|
+
Blockly.WidgetDiv.disposeAnimationTimerLength_ = opt_disposeAnimationTimerLength;
|
|
117
|
+
// Temporarily move the widget to the top of the screen so that it does not
|
|
118
|
+
// cause a scrollbar jump in Firefox when displayed.
|
|
119
|
+
var xy = goog.style.getViewportPageOffset(document);
|
|
120
|
+
Blockly.WidgetDiv.DIV.style.top = xy.y + 'px';
|
|
121
|
+
Blockly.WidgetDiv.DIV.style.direction = rtl ? 'rtl' : 'ltr';
|
|
122
|
+
Blockly.WidgetDiv.DIV.style.display = 'block';
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Repositions the widgetDiv on window resize. If it doesn't know how to
|
|
127
|
+
* calculate the new position, it wll just hide it instead.
|
|
128
|
+
*/
|
|
129
|
+
Blockly.WidgetDiv.repositionForWindowResize = function() {
|
|
130
|
+
// This condition mainly catches the widget div when it is being used as a
|
|
131
|
+
// text input. It is important not to close it in this case because on Android,
|
|
132
|
+
// when a field is focused, the soft keyboard opens triggering a window resize
|
|
133
|
+
// event and we want the widget div to stick around so users can type into it.
|
|
134
|
+
if (Blockly.WidgetDiv.owner_
|
|
135
|
+
&& Blockly.WidgetDiv.owner_.getScaledBBox_
|
|
136
|
+
&& Blockly.WidgetDiv.owner_.getSize) {
|
|
137
|
+
var widgetScaledBBox = Blockly.WidgetDiv.owner_.getScaledBBox_();
|
|
138
|
+
var widgetSize = Blockly.WidgetDiv.owner_.getSize();
|
|
139
|
+
Blockly.WidgetDiv.positionInternal_(widgetScaledBBox.left, widgetScaledBBox.top,
|
|
140
|
+
widgetSize.height);
|
|
141
|
+
} else {
|
|
142
|
+
Blockly.WidgetDiv.hide();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Destroy the widget and hide the div.
|
|
148
|
+
* @param {boolean=} opt_noAnimate If set, animation will not be run for the hide.
|
|
149
|
+
*/
|
|
150
|
+
Blockly.WidgetDiv.hide = function(opt_noAnimate) {
|
|
151
|
+
if (Blockly.WidgetDiv.disposeAnimationTimer_) {
|
|
152
|
+
// An animation timer is set already.
|
|
153
|
+
// This happens when a previous widget was animating out,
|
|
154
|
+
// but Blockly is hiding the widget to create a new one.
|
|
155
|
+
// So, short-circuit the animation and clear the timer.
|
|
156
|
+
window.clearTimeout(Blockly.WidgetDiv.disposeAnimationTimer_);
|
|
157
|
+
Blockly.WidgetDiv.disposeAnimationFinished_ && Blockly.WidgetDiv.disposeAnimationFinished_();
|
|
158
|
+
Blockly.WidgetDiv.disposeAnimationFinished_ = null;
|
|
159
|
+
Blockly.WidgetDiv.disposeAnimationTimer_ = null;
|
|
160
|
+
Blockly.WidgetDiv.owner_ = null;
|
|
161
|
+
Blockly.WidgetDiv.hideAndClearDom_();
|
|
162
|
+
} else if (Blockly.WidgetDiv.isVisible()) {
|
|
163
|
+
// No animation timer set, but the widget is visible
|
|
164
|
+
// Start animation out (or immediately hide)
|
|
165
|
+
Blockly.WidgetDiv.dispose_ && Blockly.WidgetDiv.dispose_();
|
|
166
|
+
Blockly.WidgetDiv.dispose_ = null;
|
|
167
|
+
// If we want to animate out, set the appropriate timer for final dispose.
|
|
168
|
+
if (Blockly.WidgetDiv.disposeAnimationFinished_ && !opt_noAnimate) {
|
|
169
|
+
Blockly.WidgetDiv.disposeAnimationTimer_ = window.setTimeout(
|
|
170
|
+
Blockly.WidgetDiv.hide, // Come back to hide and take the first branch.
|
|
171
|
+
Blockly.WidgetDiv.disposeAnimationTimerLength_ * 1000
|
|
172
|
+
);
|
|
173
|
+
} else {
|
|
174
|
+
// No timer provided (or no animation desired) - auto-hide the DOM now.
|
|
175
|
+
Blockly.WidgetDiv.disposeAnimationFinished_ && Blockly.WidgetDiv.disposeAnimationFinished_();
|
|
176
|
+
Blockly.WidgetDiv.disposeAnimationFinished_ = null;
|
|
177
|
+
Blockly.WidgetDiv.owner_ = null;
|
|
178
|
+
Blockly.WidgetDiv.hideAndClearDom_();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Hide all DOM for the WidgetDiv, and clear its children.
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
187
|
+
Blockly.WidgetDiv.hideAndClearDom_ = function() {
|
|
188
|
+
Blockly.WidgetDiv.DIV.style.display = 'none';
|
|
189
|
+
Blockly.WidgetDiv.DIV.style.left = '';
|
|
190
|
+
Blockly.WidgetDiv.DIV.style.top = '';
|
|
191
|
+
Blockly.WidgetDiv.DIV.style.height = '';
|
|
192
|
+
goog.dom.removeChildren(Blockly.WidgetDiv.DIV);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Is the container visible?
|
|
197
|
+
* @return {boolean} True if visible.
|
|
198
|
+
*/
|
|
199
|
+
Blockly.WidgetDiv.isVisible = function() {
|
|
200
|
+
return !!Blockly.WidgetDiv.owner_;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Destroy the widget and hide the div if it is being used by the specified
|
|
205
|
+
* object.
|
|
206
|
+
* @param {!Object} oldOwner The object that was using this container.
|
|
207
|
+
*/
|
|
208
|
+
Blockly.WidgetDiv.hideIfOwner = function(oldOwner) {
|
|
209
|
+
if (Blockly.WidgetDiv.owner_ == oldOwner) {
|
|
210
|
+
Blockly.WidgetDiv.hide();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Position the widget at a given location. Prevent the widget from going
|
|
216
|
+
* offscreen top or left (right in RTL).
|
|
217
|
+
* @param {number} anchorX Horizontal location (window coordinates, not body).
|
|
218
|
+
* @param {number} anchorY Vertical location (window coordinates, not body).
|
|
219
|
+
* @param {!goog.math.Size} windowSize Height/width of window.
|
|
220
|
+
* @param {!goog.math.Coordinate} scrollOffset X/y of window scrollbars.
|
|
221
|
+
* @param {boolean} rtl True if RTL, false if LTR.
|
|
222
|
+
*/
|
|
223
|
+
Blockly.WidgetDiv.position = function(anchorX, anchorY, windowSize,
|
|
224
|
+
scrollOffset, rtl) {
|
|
225
|
+
// Don't let the widget go above the top edge of the window.
|
|
226
|
+
if (anchorY < scrollOffset.y) {
|
|
227
|
+
anchorY = scrollOffset.y;
|
|
228
|
+
}
|
|
229
|
+
if (rtl) {
|
|
230
|
+
// Don't let the widget go right of the right edge of the window.
|
|
231
|
+
if (anchorX > windowSize.width + scrollOffset.x) {
|
|
232
|
+
anchorX = windowSize.width + scrollOffset.x;
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
// Don't let the widget go left of the left edge of the window.
|
|
236
|
+
if (anchorX < scrollOffset.x) {
|
|
237
|
+
anchorX = scrollOffset.x;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
Blockly.WidgetDiv.positionInternal_(anchorX, anchorY, windowSize.height);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Set the widget div's position and height. This function does nothing clever:
|
|
245
|
+
* it will not ensure that your widget div ends up in the visible window.
|
|
246
|
+
* @param {number} x Horizontal location (window coordinates, not body).
|
|
247
|
+
* @param {number} y Vertical location (window coordinates, not body).
|
|
248
|
+
* @param {number} height The height of the widget div (pixels).
|
|
249
|
+
* @private
|
|
250
|
+
*/
|
|
251
|
+
Blockly.WidgetDiv.positionInternal_ = function(x, y, height) {
|
|
252
|
+
Blockly.WidgetDiv.DIV.style.left = x + 'px';
|
|
253
|
+
Blockly.WidgetDiv.DIV.style.top = y + 'px';
|
|
254
|
+
Blockly.WidgetDiv.DIV.style.height = height + 'px';
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Position the widget div based on an anchor rectangle.
|
|
259
|
+
* The widget should be placed adjacent to but not overlapping the anchor
|
|
260
|
+
* rectangle. The preferred position is directly below and aligned to the left
|
|
261
|
+
* (ltr) or right (rtl) side of the anchor.
|
|
262
|
+
* @param {!Object} viewportBBox The bounding rectangle of the current viewport,
|
|
263
|
+
* in window coordinates.
|
|
264
|
+
* @param {!Object} anchorBBox The bounding rectangle of the anchor, in window
|
|
265
|
+
* coordinates.
|
|
266
|
+
* @param {!goog.math.Size} widgetSize The size of the widget that is inside the
|
|
267
|
+
* widget div, in window coordinates.
|
|
268
|
+
* @param {boolean} rtl Whether the workspace is in RTL mode. This determines
|
|
269
|
+
* horizontal alignment.
|
|
270
|
+
* @package
|
|
271
|
+
*/
|
|
272
|
+
Blockly.WidgetDiv.positionWithAnchor = function(viewportBBox, anchorBBox,
|
|
273
|
+
widgetSize, rtl) {
|
|
274
|
+
var y = Blockly.WidgetDiv.calculateY_(viewportBBox, anchorBBox, widgetSize);
|
|
275
|
+
var x = Blockly.WidgetDiv.calculateX_(viewportBBox, anchorBBox, widgetSize,
|
|
276
|
+
rtl);
|
|
277
|
+
|
|
278
|
+
if (y < 0) {
|
|
279
|
+
Blockly.WidgetDiv.positionInternal_(x, 0, widgetSize.height + y);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
Blockly.WidgetDiv.positionInternal_(x, y, widgetSize.height);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Calculate an x position (in window coordinates) such that the widget will not
|
|
288
|
+
* be offscreen on the right or left.
|
|
289
|
+
* @param {!Object} viewportBBox The bounding rectangle of the current viewport,
|
|
290
|
+
* in window coordinates.
|
|
291
|
+
* @param {!Object} anchorBBox The bounding rectangle of the anchor, in window
|
|
292
|
+
* coordinates.
|
|
293
|
+
* @param {goog.math.Size} widgetSize The dimensions of the widget inside the
|
|
294
|
+
* widget div.
|
|
295
|
+
* @param {boolean} rtl Whether the Blockly workspace is in RTL mode.
|
|
296
|
+
* @return {number} A valid x-coordinate for the top left corner of the widget
|
|
297
|
+
* div, in window coordinates.
|
|
298
|
+
* @private
|
|
299
|
+
*/
|
|
300
|
+
Blockly.WidgetDiv.calculateX_ = function(viewportBBox, anchorBBox, widgetSize,
|
|
301
|
+
rtl) {
|
|
302
|
+
if (rtl) {
|
|
303
|
+
// Try to align the right side of the field and the right side of the widget.
|
|
304
|
+
var widgetLeft = anchorBBox.right - widgetSize.width;
|
|
305
|
+
// Don't go offscreen left.
|
|
306
|
+
var x = Math.max(widgetLeft, viewportBBox.left);
|
|
307
|
+
// But really don't go offscreen right:
|
|
308
|
+
return Math.min(x, viewportBBox.right - widgetSize.width);
|
|
309
|
+
} else {
|
|
310
|
+
// Try to align the left side of the field and the left side of the widget.
|
|
311
|
+
// Don't go offscreen right.
|
|
312
|
+
var x = Math.min(anchorBBox.left,
|
|
313
|
+
viewportBBox.right - widgetSize.width);
|
|
314
|
+
// But left is more important, because that's where the text is.
|
|
315
|
+
return Math.max(x, viewportBBox.left);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Calculate a y position (in window coordinates) such that the widget will not
|
|
321
|
+
* be offscreen on the top or bottom.
|
|
322
|
+
* @param {!Object} viewportBBox The bounding rectangle of the current viewport,
|
|
323
|
+
* in window coordinates.
|
|
324
|
+
* @param {!Object} anchorBBox The bounding rectangle of the anchor, in window
|
|
325
|
+
* coordinates.
|
|
326
|
+
* @param {goog.math.Size} widgetSize The dimensions of the widget inside the
|
|
327
|
+
* widget div.
|
|
328
|
+
* @return {number} A valid y-coordinate for the top left corner of the widget
|
|
329
|
+
* div, in window coordinates.
|
|
330
|
+
* @private
|
|
331
|
+
*/
|
|
332
|
+
Blockly.WidgetDiv.calculateY_ = function(viewportBBox, anchorBBox, widgetSize) {
|
|
333
|
+
// Flip the widget vertically if off the bottom.
|
|
334
|
+
if (anchorBBox.bottom + widgetSize.height >=
|
|
335
|
+
viewportBBox.bottom) {
|
|
336
|
+
// The bottom of the widget is at the top of the field.
|
|
337
|
+
return anchorBBox.top - widgetSize.height;
|
|
338
|
+
// The widget could go off the top of the window, but it would also go off
|
|
339
|
+
// the bottom. The window is just too small.
|
|
340
|
+
} else {
|
|
341
|
+
// The top of the widget is at the bottom of the field.
|
|
342
|
+
return anchorBBox.bottom;
|
|
343
|
+
}
|
|
344
|
+
};
|