@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,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Visual Blocks Editor
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2017 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 in charge of loading, storing, and playing audio for a
|
|
23
|
+
* workspace.
|
|
24
|
+
* @author fenichel@google.com (Rachel Fenichel)
|
|
25
|
+
*/
|
|
26
|
+
'use strict';
|
|
27
|
+
|
|
28
|
+
goog.provide('Blockly.WorkspaceAudio');
|
|
29
|
+
|
|
30
|
+
goog.require('goog.userAgent');
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Class for loading, storing, and playing audio for a workspace.
|
|
35
|
+
* @param {Blockly.WorkspaceSvg} parentWorkspace The parent of the workspace
|
|
36
|
+
* this audio object belongs to, or null.
|
|
37
|
+
* @constructor
|
|
38
|
+
*/
|
|
39
|
+
Blockly.WorkspaceAudio = function(parentWorkspace) {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The parent of the workspace this object belongs to, or null. May be
|
|
43
|
+
* checked for sounds that this object can't find.
|
|
44
|
+
* @type {Blockly.WorkspaceSvg}
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
this.parentWorkspace_ = parentWorkspace;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Database of pre-loaded sounds.
|
|
51
|
+
* @private
|
|
52
|
+
* @const
|
|
53
|
+
*/
|
|
54
|
+
this.SOUNDS_ = Object.create(null);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Time that the last sound was played.
|
|
59
|
+
* @type {Date}
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
Blockly.WorkspaceAudio.prototype.lastSound_ = null;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Dispose of this audio manager.
|
|
66
|
+
* @package
|
|
67
|
+
*/
|
|
68
|
+
Blockly.WorkspaceAudio.prototype.dispose = function() {
|
|
69
|
+
this.parentWorkspace_ = null;
|
|
70
|
+
this.SOUNDS_ = null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Load an audio file. Cache it, ready for instantaneous playing.
|
|
75
|
+
* @param {!Array.<string>} filenames List of file types in decreasing order of
|
|
76
|
+
* preference (i.e. increasing size). E.g. ['media/go.mp3', 'media/go.wav']
|
|
77
|
+
* Filenames include path from Blockly's root. File extensions matter.
|
|
78
|
+
* @param {string} name Name of sound.
|
|
79
|
+
* @package
|
|
80
|
+
*/
|
|
81
|
+
Blockly.WorkspaceAudio.prototype.load = function(filenames, name) {
|
|
82
|
+
if (!filenames.length) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
var audioTest = new window['Audio']();
|
|
87
|
+
} catch (e) {
|
|
88
|
+
// No browser support for Audio.
|
|
89
|
+
// IE can throw an error even if the Audio object exists.
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var sound;
|
|
93
|
+
for (var i = 0; i < filenames.length; i++) {
|
|
94
|
+
var filename = filenames[i];
|
|
95
|
+
var ext = filename.match(/\.(\w+)$/);
|
|
96
|
+
if (ext && audioTest.canPlayType('audio/' + ext[1])) {
|
|
97
|
+
// Found an audio format we can play.
|
|
98
|
+
sound = new window['Audio'](filename);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (sound && sound.play) {
|
|
103
|
+
this.SOUNDS_[name] = sound;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Preload all the audio files so that they play quickly when asked for.
|
|
109
|
+
* @package
|
|
110
|
+
*/
|
|
111
|
+
Blockly.WorkspaceAudio.prototype.preload = function() {
|
|
112
|
+
for (var name in this.SOUNDS_) {
|
|
113
|
+
var sound = this.SOUNDS_[name];
|
|
114
|
+
sound.volume = 0.01;
|
|
115
|
+
var playPromise = sound.play();
|
|
116
|
+
|
|
117
|
+
// Edge does not return a promise, so we need to check.
|
|
118
|
+
if (playPromise) {
|
|
119
|
+
// If we don't wait for the play request to complete before calling pause() we will get an exception:
|
|
120
|
+
// Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().
|
|
121
|
+
// See more: https://developers.google.com/web/updates/2017/06/play-request-was-interrupted
|
|
122
|
+
playPromise.then(sound.pause).catch(function() {
|
|
123
|
+
// Play without user interaction was prevented.
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
sound.pause();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// iOS can only process one sound at a time. Trying to load more than one
|
|
130
|
+
// corrupts the earlier ones. Just load one and leave the others uncached.
|
|
131
|
+
if (goog.userAgent.IPAD || goog.userAgent.IPHONE) {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Play a named sound at specified volume. If volume is not specified,
|
|
139
|
+
* use full volume (1).
|
|
140
|
+
* @param {string} name Name of sound.
|
|
141
|
+
* @param {number=} opt_volume Volume of sound (0-1).
|
|
142
|
+
*/
|
|
143
|
+
Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) {
|
|
144
|
+
var sound = this.SOUNDS_[name];
|
|
145
|
+
if (sound) {
|
|
146
|
+
// Don't play one sound on top of another.
|
|
147
|
+
var now = new Date;
|
|
148
|
+
if (this.lastSound_ != null &&
|
|
149
|
+
now - this.lastSound_ < Blockly.SOUND_LIMIT) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
this.lastSound_ = now;
|
|
153
|
+
var mySound;
|
|
154
|
+
var ie9 = goog.userAgent.DOCUMENT_MODE &&
|
|
155
|
+
goog.userAgent.DOCUMENT_MODE === 9;
|
|
156
|
+
if (ie9 || goog.userAgent.IPAD || goog.userAgent.ANDROID) {
|
|
157
|
+
// Creating a new audio node causes lag in IE9, Android and iPad. Android
|
|
158
|
+
// and IE9 refetch the file from the server, iPad uses a singleton audio
|
|
159
|
+
// node which must be deleted and recreated for each new audio tag.
|
|
160
|
+
mySound = sound;
|
|
161
|
+
} else {
|
|
162
|
+
mySound = sound.cloneNode();
|
|
163
|
+
}
|
|
164
|
+
mySound.volume = (opt_volume === undefined ? 1 : opt_volume);
|
|
165
|
+
mySound.play();
|
|
166
|
+
} else if (this.parentWorkspace_) {
|
|
167
|
+
// Maybe a workspace on a lower level knows about this sound.
|
|
168
|
+
this.parentWorkspace_.getAudioManager().play(name, opt_volume);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Visual Blocks Editor
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2017 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 code comment on the workspace.
|
|
23
|
+
* @author fenichel@google.com (Rachel Fenichel)
|
|
24
|
+
*/
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
goog.provide('Blockly.WorkspaceComment');
|
|
28
|
+
|
|
29
|
+
goog.require('Blockly.Events.CommentChange');
|
|
30
|
+
goog.require('Blockly.Events.CommentCreate');
|
|
31
|
+
goog.require('Blockly.Events.CommentDelete');
|
|
32
|
+
goog.require('Blockly.Events.CommentMove');
|
|
33
|
+
|
|
34
|
+
goog.require('goog.math.Coordinate');
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Class for a workspace comment.
|
|
39
|
+
* @param {!Blockly.Workspace} workspace The block's workspace.
|
|
40
|
+
* @param {string} content The content of this workspace comment.
|
|
41
|
+
* @param {number} height Height of the comment.
|
|
42
|
+
* @param {number} width Width of the comment.
|
|
43
|
+
* @param {boolean} minimized Whether this comment is in the minimized state
|
|
44
|
+
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
|
|
45
|
+
* create a new ID. If the ID conflicts with an in-use ID, a new one will
|
|
46
|
+
* be generated.
|
|
47
|
+
* @constructor
|
|
48
|
+
*/
|
|
49
|
+
Blockly.WorkspaceComment = function(workspace, content, height, width, minimized, opt_id) {
|
|
50
|
+
/** @type {string} */
|
|
51
|
+
this.id = (opt_id && !workspace.getCommentById(opt_id)) ?
|
|
52
|
+
opt_id : Blockly.utils.genUid();
|
|
53
|
+
|
|
54
|
+
workspace.addTopComment(this);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The comment's position in workspace units. (0, 0) is at the workspace's
|
|
58
|
+
* origin; scale does not change this value.
|
|
59
|
+
* @type {!goog.math.Coordinate}
|
|
60
|
+
* @protected
|
|
61
|
+
*/
|
|
62
|
+
this.xy_ = new goog.math.Coordinate(0, 0);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The comment's height in workspace units. Scale does not change this value.
|
|
66
|
+
* @type {number}
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
this.height_ = height;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The comment's width in workspace units. Scale does not change this value.
|
|
73
|
+
* @type {number}
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
this.width_ = width;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The comment's minimized state.
|
|
80
|
+
* @type{boolean}
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
this.isMinimized_ = minimized;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @type {!Blockly.Workspace}
|
|
87
|
+
*/
|
|
88
|
+
this.workspace = workspace;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @protected
|
|
92
|
+
* @type {boolean}
|
|
93
|
+
*/
|
|
94
|
+
this.RTL = workspace.RTL;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @type {boolean}
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
this.deletable_ = true;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @type {boolean}
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
this.movable_ = true;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @protected
|
|
110
|
+
* @type {!string}
|
|
111
|
+
*/
|
|
112
|
+
this.content_ = content;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @package
|
|
116
|
+
* @type {boolean}
|
|
117
|
+
*/
|
|
118
|
+
this.isComment = true;
|
|
119
|
+
|
|
120
|
+
Blockly.WorkspaceComment.fireCreateEvent(this);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Maximum lable length (actual label length will include
|
|
125
|
+
* one additional character, the ellipsis).
|
|
126
|
+
* @private
|
|
127
|
+
*/
|
|
128
|
+
Blockly.WorkspaceComment.MAX_LABEL_LENGTH = 12;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Dispose of this comment.
|
|
132
|
+
* @package
|
|
133
|
+
*/
|
|
134
|
+
Blockly.WorkspaceComment.prototype.dispose = function() {
|
|
135
|
+
if (!this.workspace) {
|
|
136
|
+
// The comment has already been deleted.
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (Blockly.Events.isEnabled()) {
|
|
141
|
+
Blockly.Events.fire(new Blockly.Events.CommentDelete(this));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Remove from the list of top comments and the comment database.
|
|
145
|
+
this.workspace.removeTopComment(this);
|
|
146
|
+
this.workspace = null;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// Height, width, x, and y are all stored on even non-rendered comments, to
|
|
150
|
+
// preserve state if you pass the contents through a headless workspace.
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get comment height.
|
|
154
|
+
* @return {number} comment height.
|
|
155
|
+
* @package
|
|
156
|
+
*/
|
|
157
|
+
Blockly.WorkspaceComment.prototype.getHeight = function() {
|
|
158
|
+
return this.height_;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Set comment height.
|
|
163
|
+
* @param {number} height comment height.
|
|
164
|
+
* @package
|
|
165
|
+
*/
|
|
166
|
+
Blockly.WorkspaceComment.prototype.setHeight = function(height) {
|
|
167
|
+
this.height_ = height;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get comment width.
|
|
172
|
+
* @return {number} comment width.
|
|
173
|
+
* @package
|
|
174
|
+
*/
|
|
175
|
+
Blockly.WorkspaceComment.prototype.getWidth = function() {
|
|
176
|
+
return this.width_;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Set comment width.
|
|
181
|
+
* @param {number} width comment width.
|
|
182
|
+
* @package
|
|
183
|
+
*/
|
|
184
|
+
Blockly.WorkspaceComment.prototype.setWidth = function(width) {
|
|
185
|
+
this.width_ = width;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Get the height and width of this comment.
|
|
190
|
+
* @return {{height: number, width: number}} The height and width of this comment;
|
|
191
|
+
* these numbers do not change as the workspace scales.
|
|
192
|
+
*/
|
|
193
|
+
Blockly.WorkspaceComment.prototype.getHeightWidth = function() {
|
|
194
|
+
return {height: this.height_, width: this.width_};
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get stored location.
|
|
199
|
+
* @return {!goog.math.Coordinate} The comment's stored location. This is not
|
|
200
|
+
* valid if the comment is currently being dragged.
|
|
201
|
+
* @package
|
|
202
|
+
*/
|
|
203
|
+
Blockly.WorkspaceComment.prototype.getXY = function() {
|
|
204
|
+
return this.xy_.clone();
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Move a comment by a relative offset.
|
|
209
|
+
* @param {number} dx Horizontal offset, in workspace units.
|
|
210
|
+
* @param {number} dy Vertical offset, in workspace units.
|
|
211
|
+
* @package
|
|
212
|
+
*/
|
|
213
|
+
Blockly.WorkspaceComment.prototype.moveBy = function(dx, dy) {
|
|
214
|
+
var event = new Blockly.Events.CommentMove(this);
|
|
215
|
+
this.xy_.translate(dx, dy);
|
|
216
|
+
event.recordNew();
|
|
217
|
+
Blockly.Events.fire(event);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Get whether this comment is deletable or not.
|
|
222
|
+
* @return {boolean} True if deletable.
|
|
223
|
+
* @package
|
|
224
|
+
*/
|
|
225
|
+
Blockly.WorkspaceComment.prototype.isDeletable = function() {
|
|
226
|
+
return this.deletable_ &&
|
|
227
|
+
!(this.workspace && this.workspace.options.readOnly);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Set whether this comment is deletable or not.
|
|
232
|
+
* @param {boolean} deletable True if deletable.
|
|
233
|
+
* @package
|
|
234
|
+
*/
|
|
235
|
+
Blockly.WorkspaceComment.prototype.setDeletable = function(deletable) {
|
|
236
|
+
this.deletable_ = deletable;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Get whether this comment is movable or not.
|
|
241
|
+
* @return {boolean} True if movable.
|
|
242
|
+
* @package
|
|
243
|
+
*/
|
|
244
|
+
Blockly.WorkspaceComment.prototype.isMovable = function() {
|
|
245
|
+
return this.movable_ &&
|
|
246
|
+
!(this.workspace && this.workspace.options.readOnly);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Set whether this comment is movable or not.
|
|
251
|
+
* @param {boolean} movable True if movable.
|
|
252
|
+
* @package
|
|
253
|
+
*/
|
|
254
|
+
Blockly.WorkspaceComment.prototype.setMovable = function(movable) {
|
|
255
|
+
this.movable_ = movable;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Returns this comment's text.
|
|
260
|
+
* @return {string} Comment text.
|
|
261
|
+
* @package
|
|
262
|
+
*/
|
|
263
|
+
Blockly.WorkspaceComment.prototype.getText = function() {
|
|
264
|
+
return this.content_;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Set this comment's text content.
|
|
269
|
+
* @param {string} text Comment text.
|
|
270
|
+
* @package
|
|
271
|
+
*/
|
|
272
|
+
Blockly.WorkspaceComment.prototype.setText = function(text) {
|
|
273
|
+
if (this.content_ != text) {
|
|
274
|
+
Blockly.Events.fire(new Blockly.Events.CommentChange(
|
|
275
|
+
this, {text: this.content_}, {text: text}));
|
|
276
|
+
this.content_ = text;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Check whether this comment is currently minimized.
|
|
282
|
+
* @return {boolean} True if minimized
|
|
283
|
+
* @package
|
|
284
|
+
*/
|
|
285
|
+
Blockly.WorkspaceComment.prototype.isMinimized = function() {
|
|
286
|
+
return this.isMinimized_;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Encode a comment subtree as XML with XY coordinates.
|
|
291
|
+
* @param {boolean=} opt_noId True if the encoder should skip the comment id.
|
|
292
|
+
* @return {!Element} Tree of XML elements.
|
|
293
|
+
* @package
|
|
294
|
+
*/
|
|
295
|
+
Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) {
|
|
296
|
+
var element = this.toXml(opt_noId);
|
|
297
|
+
element.setAttribute('x', Math.round(this.xy_.x));
|
|
298
|
+
element.setAttribute('y', Math.round(this.xy_.y));
|
|
299
|
+
element.setAttribute('h', this.height_);
|
|
300
|
+
element.setAttribute('w', this.width_);
|
|
301
|
+
return element;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Get the truncated text for this comment to display in the minimized
|
|
306
|
+
* top bar.
|
|
307
|
+
* @return {string} The truncated comment text
|
|
308
|
+
* @package
|
|
309
|
+
*/
|
|
310
|
+
Blockly.WorkspaceComment.prototype.getLabelText = function() {
|
|
311
|
+
if (this.content_.length > Blockly.WorkspaceComment.MAX_LABEL_LENGTH) {
|
|
312
|
+
if (this.RTL) {
|
|
313
|
+
return '\u2026' + this.content_.slice(0, Blockly.WorkspaceComment.MAX_LABEL_LENGTH);
|
|
314
|
+
}
|
|
315
|
+
return this.content_.slice(0, Blockly.WorkspaceComment.MAX_LABEL_LENGTH) + '\u2026';
|
|
316
|
+
} else {
|
|
317
|
+
return this.content_;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Encode a comment subtree as XML, but don't serialize the XY coordinates or
|
|
323
|
+
* width and height. If you need that additional information use toXmlWithXY.
|
|
324
|
+
* @param {boolean=} opt_noId True if the encoder should skip the comment id.
|
|
325
|
+
* @return {!Element} Tree of XML elements.
|
|
326
|
+
* @package
|
|
327
|
+
*/
|
|
328
|
+
Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) {
|
|
329
|
+
var commentElement = goog.dom.createDom('comment');
|
|
330
|
+
if (!opt_noId) {
|
|
331
|
+
commentElement.setAttribute('id', this.id);
|
|
332
|
+
}
|
|
333
|
+
if (this.isMinimized_) {
|
|
334
|
+
commentElement.setAttribute('minimized', true);
|
|
335
|
+
}
|
|
336
|
+
commentElement.textContent = this.getText();
|
|
337
|
+
return commentElement;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Fire a create event for the given workspace comment, if comments are enabled.
|
|
342
|
+
* @param {!Blockly.WorkspaceComment} comment The comment that was just created.
|
|
343
|
+
* @package
|
|
344
|
+
*/
|
|
345
|
+
Blockly.WorkspaceComment.fireCreateEvent = function(comment) {
|
|
346
|
+
if (Blockly.Events.isEnabled()) {
|
|
347
|
+
var existingGroup = Blockly.Events.getGroup();
|
|
348
|
+
if (!existingGroup) {
|
|
349
|
+
Blockly.Events.setGroup(true);
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
Blockly.Events.fire(new Blockly.Events.CommentCreate(comment));
|
|
353
|
+
} finally {
|
|
354
|
+
if (!existingGroup) {
|
|
355
|
+
Blockly.Events.setGroup(false);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Decode an XML comment tag and create a comment on the workspace.
|
|
363
|
+
* @param {!Element} xmlComment XML comment element.
|
|
364
|
+
* @param {!Blockly.Workspace} workspace The workspace.
|
|
365
|
+
* @return {!Blockly.WorkspaceComment} The created workspace comment.
|
|
366
|
+
* @package
|
|
367
|
+
*/
|
|
368
|
+
Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) {
|
|
369
|
+
var info = Blockly.WorkspaceComment.parseAttributes(xmlComment);
|
|
370
|
+
|
|
371
|
+
var comment = new Blockly.WorkspaceComment(
|
|
372
|
+
workspace, info.content, info.h, info.w, info.minimized, info.id);
|
|
373
|
+
|
|
374
|
+
if (!isNaN(info.x) && !isNaN(info.y)) {
|
|
375
|
+
comment.moveBy(info.x, info.y);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
Blockly.WorkspaceComment.fireCreateEvent(comment);
|
|
379
|
+
return comment;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Decode an XML comment tag and return the results in an object.
|
|
384
|
+
* @param {!Element} xml XML comment element.
|
|
385
|
+
* @return {!Object} An object containing the information about the comment.
|
|
386
|
+
* @package
|
|
387
|
+
*/
|
|
388
|
+
Blockly.WorkspaceComment.parseAttributes = function(xml) {
|
|
389
|
+
var xmlH = xml.getAttribute('h');
|
|
390
|
+
var xmlW = xml.getAttribute('w');
|
|
391
|
+
|
|
392
|
+
return {
|
|
393
|
+
/* @type {string} */
|
|
394
|
+
id: xml.getAttribute('id'),
|
|
395
|
+
/**
|
|
396
|
+
* The height of the comment in workspace units, or 100 if not specified.
|
|
397
|
+
* @type {number}
|
|
398
|
+
*/
|
|
399
|
+
h: xmlH ? parseInt(xmlH, 10) : 100,
|
|
400
|
+
/**
|
|
401
|
+
* The width of the comment in workspace units, or 100 if not specified.
|
|
402
|
+
* @type {number}
|
|
403
|
+
*/
|
|
404
|
+
w: xmlW ? parseInt(xmlW, 10) : 100,
|
|
405
|
+
/**
|
|
406
|
+
* The x position of the comment in workspace coordinates, or NaN if not
|
|
407
|
+
* specified in the XML.
|
|
408
|
+
* @type {number}
|
|
409
|
+
*/
|
|
410
|
+
x: parseInt(xml.getAttribute('x'), 10),
|
|
411
|
+
/**
|
|
412
|
+
* The y position of the comment in workspace coordinates, or NaN if not
|
|
413
|
+
* specified in the XML.
|
|
414
|
+
* @type {number}
|
|
415
|
+
*/
|
|
416
|
+
y: parseInt(xml.getAttribute('y'), 10),
|
|
417
|
+
/**
|
|
418
|
+
* Whether this comment is minimized. Defaults to false if not specified in
|
|
419
|
+
* the XML.
|
|
420
|
+
* @type {boolean}
|
|
421
|
+
*/
|
|
422
|
+
minimized: xml.getAttribute('minimized') == 'true' || false,
|
|
423
|
+
/* @type {string} */
|
|
424
|
+
content: xml.textContent
|
|
425
|
+
};
|
|
426
|
+
};
|