scratch-blocks 2.0.2 → 2.0.3
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/commitlint.config.js +2 -2
- package/dist/main.mjs +1 -2
- package/dist/types/msg/scratch_msgs.d.ts.map +1 -1
- package/dist/types/src/block_reporting.d.ts.map +1 -1
- package/dist/types/src/blocks/colour.d.ts +0 -19
- package/dist/types/src/blocks/colour.d.ts.map +1 -1
- package/dist/types/src/blocks/control.d.ts +0 -19
- package/dist/types/src/blocks/control.d.ts.map +1 -1
- package/dist/types/src/blocks/data.d.ts +0 -19
- package/dist/types/src/blocks/data.d.ts.map +1 -1
- package/dist/types/src/blocks/event.d.ts +0 -19
- package/dist/types/src/blocks/event.d.ts.map +1 -1
- package/dist/types/src/blocks/looks.d.ts +0 -19
- package/dist/types/src/blocks/looks.d.ts.map +1 -1
- package/dist/types/src/blocks/math.d.ts +0 -19
- package/dist/types/src/blocks/math.d.ts.map +1 -1
- package/dist/types/src/blocks/matrix.d.ts +0 -19
- package/dist/types/src/blocks/matrix.d.ts.map +1 -1
- package/dist/types/src/blocks/motion.d.ts +0 -19
- package/dist/types/src/blocks/motion.d.ts.map +1 -1
- package/dist/types/src/blocks/note.d.ts +0 -19
- package/dist/types/src/blocks/note.d.ts.map +1 -1
- package/dist/types/src/blocks/operators.d.ts +0 -19
- package/dist/types/src/blocks/operators.d.ts.map +1 -1
- package/dist/types/src/blocks/procedures.d.ts +6 -9
- package/dist/types/src/blocks/procedures.d.ts.map +1 -1
- package/dist/types/src/blocks/sensing.d.ts +0 -19
- package/dist/types/src/blocks/sensing.d.ts.map +1 -1
- package/dist/types/src/blocks/sound.d.ts +0 -19
- package/dist/types/src/blocks/sound.d.ts.map +1 -1
- package/dist/types/src/blocks/text.d.ts +0 -19
- package/dist/types/src/blocks/text.d.ts.map +1 -1
- package/dist/types/src/blocks/vertical_extensions.d.ts +0 -19
- package/dist/types/src/blocks/vertical_extensions.d.ts.map +1 -1
- package/dist/types/src/checkable_continuous_flyout.d.ts +2 -7
- package/dist/types/src/checkable_continuous_flyout.d.ts.map +1 -1
- package/dist/types/src/checkbox_bubble.d.ts +13 -12
- package/dist/types/src/checkbox_bubble.d.ts.map +1 -1
- package/dist/types/src/colours.d.ts.map +1 -1
- package/dist/types/src/constants.d.ts +0 -7
- package/dist/types/src/constants.d.ts.map +1 -1
- package/dist/types/src/context_menu_items.d.ts +0 -5
- package/dist/types/src/context_menu_items.d.ts.map +1 -1
- package/dist/types/src/data_category.d.ts +2 -4
- package/dist/types/src/data_category.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_base.d.ts +2 -3
- package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_change.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_change.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_collapse.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_collapse.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_create.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_create.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_delete.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_delete.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_move.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_move.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_resize.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_resize.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_end.d.ts +1 -2
- package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_outside.d.ts +1 -2
- package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
- package/dist/types/src/events/events_scratch_variable_create.d.ts +0 -5
- package/dist/types/src/events/events_scratch_variable_create.d.ts.map +1 -1
- package/dist/types/src/fields/field_colour_slider.d.ts +3 -27
- package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
- package/dist/types/src/fields/field_matrix.d.ts +0 -19
- package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
- package/dist/types/src/fields/field_note.d.ts +8 -23
- package/dist/types/src/fields/field_note.d.ts.map +1 -1
- package/dist/types/src/fields/field_textinput_removable.d.ts +2 -4
- package/dist/types/src/fields/field_textinput_removable.d.ts.map +1 -1
- package/dist/types/src/fields/field_variable_getter.d.ts +0 -19
- package/dist/types/src/fields/field_variable_getter.d.ts.map +1 -1
- package/dist/types/src/fields/field_vertical_separator.d.ts +0 -19
- package/dist/types/src/fields/field_vertical_separator.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_angle.d.ts +0 -19
- package/dist/types/src/fields/scratch_field_angle.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_dropdown.d.ts +0 -5
- package/dist/types/src/fields/scratch_field_dropdown.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_number.d.ts +0 -19
- package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_variable.d.ts +4 -7
- package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
- package/dist/types/src/flyout_checkbox_icon.d.ts +2 -3
- package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
- package/dist/types/src/glows.d.ts +1 -3
- package/dist/types/src/glows.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +50 -51
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/procedures.d.ts +6 -8
- package/dist/types/src/procedures.d.ts.map +1 -1
- package/dist/types/src/recyclable_block_flyout_inflater.d.ts +3 -5
- package/dist/types/src/recyclable_block_flyout_inflater.d.ts.map +1 -1
- package/dist/types/src/renderer/bowler_hat.d.ts +2 -3
- package/dist/types/src/renderer/bowler_hat.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/cat_face.d.ts +6 -5
- package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/constants.d.ts +2 -2
- package/dist/types/src/renderer/cat/constants.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/drawer.d.ts +3 -4
- package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/path_object.d.ts +2 -3
- package/dist/types/src/renderer/cat/path_object.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/render_info.d.ts +3 -4
- package/dist/types/src/renderer/cat/render_info.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/renderer.d.ts +6 -7
- package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
- package/dist/types/src/renderer/constants.d.ts +4 -4
- package/dist/types/src/renderer/constants.d.ts.map +1 -1
- package/dist/types/src/renderer/drawer.d.ts +5 -4
- package/dist/types/src/renderer/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/path_object.d.ts +1 -3
- package/dist/types/src/renderer/path_object.d.ts.map +1 -1
- package/dist/types/src/renderer/render_info.d.ts +3 -4
- package/dist/types/src/renderer/render_info.d.ts.map +1 -1
- package/dist/types/src/renderer/renderer.d.ts +8 -15
- package/dist/types/src/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/scratch_block_paster.d.ts +0 -5
- package/dist/types/src/scratch_block_paster.d.ts.map +1 -1
- package/dist/types/src/scratch_blocks_utils.d.ts +0 -20
- package/dist/types/src/scratch_blocks_utils.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_bubble.d.ts +1 -4
- package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_icon.d.ts +2 -3
- package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
- package/dist/types/src/scratch_connection_checker.d.ts +0 -5
- package/dist/types/src/scratch_connection_checker.d.ts.map +1 -1
- package/dist/types/src/scratch_continuous_category.d.ts +5 -5
- package/dist/types/src/scratch_continuous_category.d.ts.map +1 -1
- package/dist/types/src/scratch_continuous_toolbox.d.ts +3 -6
- package/dist/types/src/scratch_continuous_toolbox.d.ts.map +1 -1
- package/dist/types/src/scratch_dragger.d.ts +1 -10
- package/dist/types/src/scratch_dragger.d.ts.map +1 -1
- package/dist/types/src/scratch_insertion_marker_previewer.d.ts +0 -5
- package/dist/types/src/scratch_insertion_marker_previewer.d.ts.map +1 -1
- package/dist/types/src/scratch_variable_map.d.ts +0 -5
- package/dist/types/src/scratch_variable_map.d.ts.map +1 -1
- package/dist/types/src/scratch_variable_model.d.ts +1 -2
- package/dist/types/src/scratch_variable_model.d.ts.map +1 -1
- package/dist/types/src/scratch_zoom_controls.d.ts +4 -6
- package/dist/types/src/scratch_zoom_controls.d.ts.map +1 -1
- package/dist/types/src/shadows.d.ts +2 -2
- package/dist/types/src/shadows.d.ts.map +1 -1
- package/dist/types/src/status_indicator_label.d.ts +4 -6
- package/dist/types/src/status_indicator_label.d.ts.map +1 -1
- package/dist/types/src/status_indicator_label_flyout_inflater.d.ts +1 -6
- package/dist/types/src/status_indicator_label_flyout_inflater.d.ts.map +1 -1
- package/dist/types/src/variables.d.ts +4 -8
- package/dist/types/src/variables.d.ts.map +1 -1
- package/dist/types/src/xml.d.ts +2 -3
- package/dist/types/src/xml.d.ts.map +1 -1
- package/dist/types/tests/jsunit/block_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/connection_db_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/connection_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/event_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/extensions_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_number_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_variable_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/gesture_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/input_test.d.ts +1 -0
- package/dist/types/tests/jsunit/input_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/json_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/names_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/procedure_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/svg_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/test_utilities.d.ts.map +1 -1
- package/dist/types/tests/jsunit/utils_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/variable_map_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/variable_model_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/widget_div_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/xml_test.d.ts.map +1 -1
- package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +1 -1
- package/eslint.config.mjs +69 -0
- package/i18n/create_scratch_msgs.js +44 -45
- package/i18n/js_to_json.js +40 -32
- package/i18n/json_to_js.js +37 -37
- package/i18n/sync_tx_translations.js +64 -65
- package/i18n/test_scratch_msgs.js +66 -63
- package/msg/js/en.js +289 -287
- package/msg/json/en.json +284 -284
- package/msg/messages.js +289 -287
- package/msg/scratch_msgs.js +22959 -22970
- package/package.json +6 -3
- package/prettier.config.mjs +3 -0
- package/release.config.js +7 -7
- package/renovate.json5 +7 -9
- package/src/block_reporting.ts +15 -18
- package/src/blocks/colour.ts +12 -15
- package/src/blocks/control.ts +167 -177
- package/src/blocks/data.ts +225 -292
- package/src/blocks/event.ts +121 -123
- package/src/blocks/looks.ts +165 -167
- package/src/blocks/math.ts +44 -46
- package/src/blocks/matrix.ts +11 -13
- package/src/blocks/motion.ts +151 -153
- package/src/blocks/note.ts +11 -13
- package/src/blocks/operators.ts +158 -160
- package/src/blocks/procedures.ts +415 -523
- package/src/blocks/sensing.ts +163 -165
- package/src/blocks/sound.ts +58 -60
- package/src/blocks/text.ts +10 -12
- package/src/blocks/vertical_extensions.ts +86 -102
- package/src/checkable_continuous_flyout.ts +25 -42
- package/src/checkbox_bubble.ts +83 -100
- package/src/colours.ts +35 -37
- package/src/constants.ts +22 -29
- package/src/context_menu_items.ts +56 -81
- package/src/css.ts +3 -4
- package/src/data_category.ts +137 -251
- package/src/events/events_block_comment_base.ts +21 -31
- package/src/events/events_block_comment_change.ts +21 -42
- package/src/events/events_block_comment_collapse.ts +22 -43
- package/src/events/events_block_comment_create.ts +29 -46
- package/src/events/events_block_comment_delete.ts +10 -19
- package/src/events/events_block_comment_move.ts +27 -52
- package/src/events/events_block_comment_resize.ts +28 -55
- package/src/events/events_block_drag_end.ts +16 -26
- package/src/events/events_block_drag_outside.ts +12 -22
- package/src/events/events_scratch_variable_create.ts +33 -56
- package/src/fields/field_colour_slider.ts +173 -228
- package/src/fields/field_matrix.ts +200 -269
- package/src/fields/field_note.ts +272 -377
- package/src/fields/field_textinput_removable.ts +25 -40
- package/src/fields/field_variable_getter.ts +26 -31
- package/src/fields/field_vertical_separator.ts +19 -24
- package/src/fields/scratch_field_angle.ts +150 -186
- package/src/fields/scratch_field_dropdown.ts +15 -19
- package/src/fields/scratch_field_number.ts +123 -180
- package/src/fields/scratch_field_variable.ts +54 -75
- package/src/flyout_checkbox_icon.ts +18 -28
- package/src/glows.ts +51 -58
- package/src/index.ts +119 -133
- package/src/procedures.ts +146 -213
- package/src/recyclable_block_flyout_inflater.ts +14 -25
- package/src/renderer/bowler_hat.ts +6 -8
- package/src/renderer/cat/cat_face.ts +98 -99
- package/src/renderer/cat/constants.ts +67 -87
- package/src/renderer/cat/drawer.ts +21 -27
- package/src/renderer/cat/path_object.ts +3 -5
- package/src/renderer/cat/render_info.ts +5 -8
- package/src/renderer/cat/renderer.ts +11 -15
- package/src/renderer/constants.ts +34 -49
- package/src/renderer/drawer.ts +35 -51
- package/src/renderer/path_object.ts +4 -10
- package/src/renderer/render_info.ts +36 -56
- package/src/renderer/renderer.ts +16 -29
- package/src/scratch_block_paster.ts +12 -20
- package/src/scratch_blocks_utils.ts +4 -7
- package/src/scratch_comment_bubble.ts +70 -101
- package/src/scratch_comment_icon.ts +74 -123
- package/src/scratch_connection_checker.ts +7 -17
- package/src/scratch_continuous_category.ts +24 -28
- package/src/scratch_continuous_toolbox.ts +20 -27
- package/src/scratch_dragger.ts +42 -81
- package/src/scratch_insertion_marker_previewer.ts +6 -11
- package/src/scratch_variable_map.ts +5 -12
- package/src/scratch_variable_model.ts +4 -11
- package/src/scratch_zoom_controls.ts +101 -156
- package/src/shadows.ts +32 -37
- package/src/status_indicator_label.ts +54 -67
- package/src/status_indicator_label_flyout_inflater.ts +11 -21
- package/src/variables.ts +89 -138
- package/src/xml.ts +21 -35
- package/tsconfig.json +2 -6
- package/types/continuous-toolbox.d.ts +1 -1
- package/dist/main.mjs.LICENSE.txt +0 -163
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2024 Google LLC
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import type { ScratchCommentIcon } from "./scratch_comment_icon";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import type { ScratchCommentIcon } from './scratch_comment_icon'
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Class responsible for handling the pasting of copied blocks.
|
|
@@ -13,35 +11,32 @@ import type { ScratchCommentIcon } from "./scratch_comment_icon";
|
|
|
13
11
|
class ScratchBlockPaster extends Blockly.clipboard.BlockPaster {
|
|
14
12
|
/**
|
|
15
13
|
* Deserializes the given block data onto the workspace.
|
|
16
|
-
*
|
|
17
14
|
* @param copyData The serialized block state to create a copy of on the
|
|
18
15
|
* workspace.
|
|
19
16
|
* @param workspace The workspace to paste the block onto.
|
|
20
17
|
* @param coordinate The location to paste the block.
|
|
18
|
+
* @returns The newly pasted block, or undefined if pasting failed.
|
|
21
19
|
*/
|
|
22
20
|
paste(
|
|
23
21
|
copyData: Blockly.clipboard.BlockCopyData,
|
|
24
22
|
workspace: Blockly.WorkspaceSvg,
|
|
25
|
-
coordinate: Blockly.utils.Coordinate
|
|
23
|
+
coordinate: Blockly.utils.Coordinate,
|
|
26
24
|
) {
|
|
27
|
-
const block = super.paste(copyData, workspace, coordinate)
|
|
28
|
-
if (
|
|
29
|
-
block
|
|
30
|
-
block?.type === "argument_reporter_string_number"
|
|
31
|
-
) {
|
|
32
|
-
block.setDragStrategy(new Blockly.dragging.BlockDragStrategy(block));
|
|
25
|
+
const block = super.paste(copyData, workspace, coordinate)
|
|
26
|
+
if (block?.type === 'argument_reporter_boolean' || block?.type === 'argument_reporter_string_number') {
|
|
27
|
+
block.setDragStrategy(new Blockly.dragging.BlockDragStrategy(block))
|
|
33
28
|
}
|
|
34
29
|
|
|
35
30
|
// Deserialization of blocks suppresses events, so even though this gets
|
|
36
31
|
// fired for blocks with comments, the VM will never receive it, causing its
|
|
37
32
|
// state to get out of sync. Manually fire it here (after suppression has
|
|
38
33
|
// been turned off) if needed.
|
|
39
|
-
const commentIcon = block?.getIcon(Blockly.icons.IconType.COMMENT)
|
|
34
|
+
const commentIcon = block?.getIcon(Blockly.icons.IconType.COMMENT)
|
|
40
35
|
if (commentIcon) {
|
|
41
|
-
(commentIcon as ScratchCommentIcon).fireCreateEvent()
|
|
36
|
+
;(commentIcon as ScratchCommentIcon).fireCreateEvent()
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
return block
|
|
39
|
+
return block
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
42
|
|
|
@@ -50,9 +45,6 @@ class ScratchBlockPaster extends Blockly.clipboard.BlockPaster {
|
|
|
50
45
|
* place.
|
|
51
46
|
*/
|
|
52
47
|
export function registerScratchBlockPaster() {
|
|
53
|
-
Blockly.clipboard.registry.unregister(ScratchBlockPaster.TYPE)
|
|
54
|
-
Blockly.clipboard.registry.register(
|
|
55
|
-
ScratchBlockPaster.TYPE,
|
|
56
|
-
new ScratchBlockPaster()
|
|
57
|
-
);
|
|
48
|
+
Blockly.clipboard.registry.unregister(ScratchBlockPaster.TYPE)
|
|
49
|
+
Blockly.clipboard.registry.register(ScratchBlockPaster.TYPE, new ScratchBlockPaster())
|
|
58
50
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Visual Blocks Editor
|
|
4
3
|
*
|
|
5
4
|
* Copyright 2018 Google Inc.
|
|
@@ -17,23 +16,21 @@
|
|
|
17
16
|
* See the License for the specific language governing permissions and
|
|
18
17
|
* limitations under the License.
|
|
19
18
|
*/
|
|
20
|
-
|
|
21
19
|
/**
|
|
22
|
-
* @
|
|
20
|
+
* @file Utility methods for Scratch Blocks but not Blockly.
|
|
23
21
|
* @author fenichel@google.com (Rachel Fenichel)
|
|
24
22
|
*/
|
|
25
|
-
import * as Blockly from
|
|
23
|
+
import * as Blockly from 'blockly/core'
|
|
26
24
|
|
|
27
25
|
/**
|
|
28
26
|
* Compare strings with natural number sorting.
|
|
29
|
-
*
|
|
30
27
|
* @param str1 First input.
|
|
31
28
|
* @param str2 Second input.
|
|
32
29
|
* @returns -1, 0, or 1 to signify greater than, equality, or less than.
|
|
33
30
|
*/
|
|
34
31
|
export function compareStrings(str1: string, str2: string): number {
|
|
35
32
|
return str1.localeCompare(str2, [], {
|
|
36
|
-
sensitivity:
|
|
33
|
+
sensitivity: 'base',
|
|
37
34
|
numeric: true,
|
|
38
|
-
})
|
|
35
|
+
})
|
|
39
36
|
}
|
|
@@ -1,54 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2024 Google LLC
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import * as Blockly from "blockly/core";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* A Scratch-style comment bubble for block comments.
|
|
11
|
-
* @implements {IBubble}
|
|
12
|
-
* @implements {ISelectable}
|
|
13
9
|
*/
|
|
14
10
|
export class ScratchCommentBubble
|
|
15
11
|
extends Blockly.comments.CommentView
|
|
16
12
|
implements Blockly.IBubble, Blockly.ISelectable
|
|
17
13
|
{
|
|
18
|
-
id: string
|
|
19
|
-
private sourceBlock: Blockly.BlockSvg | null
|
|
20
|
-
private anchor?: Blockly.utils.Coordinate
|
|
21
|
-
private anchorChain?: SVGLineElement
|
|
22
|
-
private dragStartLocation?: Blockly.utils.Coordinate
|
|
14
|
+
id: string
|
|
15
|
+
private sourceBlock: Blockly.BlockSvg | null
|
|
16
|
+
private anchor?: Blockly.utils.Coordinate
|
|
17
|
+
private anchorChain?: SVGLineElement
|
|
18
|
+
private dragStartLocation?: Blockly.utils.Coordinate
|
|
23
19
|
|
|
24
20
|
constructor(sourceBlock: Blockly.BlockSvg) {
|
|
25
|
-
const commentId = `${sourceBlock.id}_comment
|
|
26
|
-
super(sourceBlock.workspace, commentId)
|
|
27
|
-
this.sourceBlock = sourceBlock
|
|
28
|
-
this.disposing = false
|
|
29
|
-
this.id = commentId
|
|
30
|
-
this.setPlaceholderText(Blockly.Msg.WORKSPACE_COMMENT_DEFAULT_TEXT)
|
|
31
|
-
this.getSvgRoot().setAttribute(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
this.getSvgRoot().setAttribute("id", this.id);
|
|
36
|
-
|
|
37
|
-
Blockly.browserEvents.conditionalBind(
|
|
38
|
-
this.getSvgRoot(),
|
|
39
|
-
"pointerdown",
|
|
40
|
-
this,
|
|
41
|
-
this.startGesture
|
|
42
|
-
);
|
|
21
|
+
const commentId = `${sourceBlock.id}_comment`
|
|
22
|
+
super(sourceBlock.workspace, commentId)
|
|
23
|
+
this.sourceBlock = sourceBlock
|
|
24
|
+
this.disposing = false
|
|
25
|
+
this.id = commentId
|
|
26
|
+
this.setPlaceholderText(Blockly.Msg.WORKSPACE_COMMENT_DEFAULT_TEXT)
|
|
27
|
+
this.getSvgRoot().setAttribute('style', `--colour-commentBorder: ${sourceBlock.getColourTertiary()};`)
|
|
28
|
+
this.getSvgRoot().setAttribute('id', this.id)
|
|
29
|
+
|
|
30
|
+
Blockly.browserEvents.conditionalBind(this.getSvgRoot(), 'pointerdown', this, this.startGesture)
|
|
43
31
|
// Don't zoom with mousewheel; let it scroll instead.
|
|
44
|
-
Blockly.browserEvents.conditionalBind(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this,
|
|
48
|
-
(e: WheelEvent) => {
|
|
49
|
-
e.stopPropagation();
|
|
50
|
-
}
|
|
51
|
-
);
|
|
32
|
+
Blockly.browserEvents.conditionalBind(this.getSvgRoot(), 'wheel', this, (e: WheelEvent) => {
|
|
33
|
+
e.stopPropagation()
|
|
34
|
+
})
|
|
52
35
|
}
|
|
53
36
|
|
|
54
37
|
setDeleteStyle(enable: boolean) {}
|
|
@@ -58,85 +41,76 @@ export class ScratchCommentBubble
|
|
|
58
41
|
unselect() {}
|
|
59
42
|
|
|
60
43
|
isMovable() {
|
|
61
|
-
return true
|
|
44
|
+
return true
|
|
62
45
|
}
|
|
63
46
|
|
|
64
47
|
moveDuringDrag(newLocation: Blockly.utils.Coordinate) {
|
|
65
|
-
this.moveTo(newLocation)
|
|
48
|
+
this.moveTo(newLocation)
|
|
66
49
|
}
|
|
67
50
|
|
|
68
|
-
moveTo(xOrCoordinate: number, y: number): void
|
|
69
|
-
moveTo(xOrCoordinate: Blockly.utils.Coordinate): void
|
|
51
|
+
moveTo(xOrCoordinate: number, y: number): void
|
|
52
|
+
moveTo(xOrCoordinate: Blockly.utils.Coordinate): void
|
|
70
53
|
moveTo(xOrCoordinate: Blockly.utils.Coordinate | number, y?: number) {
|
|
71
54
|
const destination =
|
|
72
55
|
xOrCoordinate instanceof Blockly.utils.Coordinate
|
|
73
56
|
? xOrCoordinate
|
|
74
|
-
: new Blockly.utils.Coordinate(xOrCoordinate, y!)
|
|
75
|
-
super.moveTo(destination)
|
|
76
|
-
this.redrawAnchorChain()
|
|
57
|
+
: new Blockly.utils.Coordinate(xOrCoordinate, y!)
|
|
58
|
+
super.moveTo(destination)
|
|
59
|
+
this.redrawAnchorChain()
|
|
77
60
|
}
|
|
78
61
|
|
|
79
62
|
startGesture(e: PointerEvent) {
|
|
80
|
-
const gesture = this.workspace.getGesture(e)
|
|
63
|
+
const gesture = this.workspace.getGesture(e)
|
|
81
64
|
if (gesture) {
|
|
82
65
|
// ScratchCommentBubble implements IBubble structurally but TypeScript
|
|
83
66
|
// cannot verify it because IBubble.drag has a different signature here.
|
|
84
|
-
gesture.handleBubbleStart(e, this as unknown as Blockly.IBubble)
|
|
85
|
-
Blockly.common.setSelected(this)
|
|
67
|
+
gesture.handleBubbleStart(e, this as unknown as Blockly.IBubble)
|
|
68
|
+
Blockly.common.setSelected(this)
|
|
86
69
|
}
|
|
87
70
|
}
|
|
88
71
|
|
|
89
72
|
startDrag(event: PointerEvent) {
|
|
90
|
-
this.dragStartLocation = this.getRelativeToSurfaceXY()
|
|
91
|
-
this.workspace.setResizesEnabled(false)
|
|
92
|
-
this.workspace.getLayerManager()?.moveToDragLayer(this)
|
|
93
|
-
Blockly.utils.dom.addClass(this.getSvgRoot(),
|
|
73
|
+
this.dragStartLocation = this.getRelativeToSurfaceXY()
|
|
74
|
+
this.workspace.setResizesEnabled(false)
|
|
75
|
+
this.workspace.getLayerManager()?.moveToDragLayer(this)
|
|
76
|
+
Blockly.utils.dom.addClass(this.getSvgRoot(), 'blocklyDragging')
|
|
94
77
|
}
|
|
95
78
|
|
|
96
79
|
drag(newLocation: Blockly.utils.Coordinate, event?: PointerEvent) {
|
|
97
|
-
this.moveTo(newLocation)
|
|
80
|
+
this.moveTo(newLocation)
|
|
98
81
|
}
|
|
99
82
|
|
|
100
83
|
endDrag() {
|
|
101
|
-
this.workspace
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.workspace.setResizesEnabled(false);
|
|
105
|
-
Blockly.utils.dom.removeClass(this.getSvgRoot(), "blocklyDragging");
|
|
84
|
+
this.workspace.getLayerManager()?.moveOffDragLayer(this, Blockly.layers.BUBBLE)
|
|
85
|
+
this.workspace.setResizesEnabled(false)
|
|
86
|
+
Blockly.utils.dom.removeClass(this.getSvgRoot(), 'blocklyDragging')
|
|
106
87
|
Blockly.Events.fire(
|
|
107
|
-
new (Blockly.Events.get(
|
|
108
|
-
|
|
109
|
-
this.dragStartLocation,
|
|
110
|
-
this.getRelativeToSurfaceXY()
|
|
111
|
-
)
|
|
112
|
-
);
|
|
88
|
+
new (Blockly.Events.get('block_comment_move'))(this, this.dragStartLocation, this.getRelativeToSurfaceXY()),
|
|
89
|
+
)
|
|
113
90
|
}
|
|
114
91
|
|
|
115
92
|
revertDrag() {
|
|
116
|
-
this.moveTo(this.dragStartLocation!)
|
|
93
|
+
this.moveTo(this.dragStartLocation!)
|
|
117
94
|
}
|
|
118
95
|
|
|
119
96
|
setAnchorLocation(newAnchor: Blockly.utils.Coordinate) {
|
|
120
|
-
const oldAnchor = this.anchor
|
|
121
|
-
const alreadyAnchored = !!this.anchor
|
|
122
|
-
this.anchor = newAnchor
|
|
97
|
+
const oldAnchor = this.anchor
|
|
98
|
+
const alreadyAnchored = !!this.anchor
|
|
99
|
+
this.anchor = newAnchor
|
|
123
100
|
if (!alreadyAnchored) {
|
|
124
|
-
this.dropAnchor()
|
|
101
|
+
this.dropAnchor()
|
|
125
102
|
} else {
|
|
126
|
-
const oldLocation = this.getRelativeToSurfaceXY()
|
|
127
|
-
const delta = Blockly.utils.Coordinate.difference(this.anchor, oldAnchor!)
|
|
128
|
-
const newLocation = Blockly.utils.Coordinate.sum(oldLocation, delta)
|
|
129
|
-
this.moveTo(newLocation)
|
|
103
|
+
const oldLocation = this.getRelativeToSurfaceXY()
|
|
104
|
+
const delta = Blockly.utils.Coordinate.difference(this.anchor, oldAnchor!)
|
|
105
|
+
const newLocation = Blockly.utils.Coordinate.sum(oldLocation, delta)
|
|
106
|
+
this.moveTo(newLocation)
|
|
130
107
|
}
|
|
131
108
|
}
|
|
132
109
|
|
|
133
110
|
dropAnchor() {
|
|
134
|
-
const verticalOffset = 16
|
|
135
|
-
this.moveTo(
|
|
136
|
-
|
|
137
|
-
this.anchor!.y - verticalOffset
|
|
138
|
-
);
|
|
139
|
-
const location = this.getRelativeToSurfaceXY();
|
|
111
|
+
const verticalOffset = 16
|
|
112
|
+
this.moveTo(this.anchor!.x + 40 * (this.workspace.RTL ? -1 : 1), this.anchor!.y - verticalOffset)
|
|
113
|
+
const location = this.getRelativeToSurfaceXY()
|
|
140
114
|
this.anchorChain = Blockly.utils.dom.createSvgElement(
|
|
141
115
|
Blockly.utils.Svg.LINE,
|
|
142
116
|
{
|
|
@@ -146,52 +120,47 @@ export class ScratchCommentBubble
|
|
|
146
120
|
y2: verticalOffset,
|
|
147
121
|
style: `stroke: ${this.sourceBlock!.getColourTertiary()}; stroke-width: 1`,
|
|
148
122
|
},
|
|
149
|
-
this.getSvgRoot()
|
|
150
|
-
)
|
|
151
|
-
this.getSvgRoot().insertBefore(
|
|
152
|
-
this.anchorChain,
|
|
153
|
-
this.getSvgRoot().firstChild
|
|
154
|
-
);
|
|
123
|
+
this.getSvgRoot(),
|
|
124
|
+
)
|
|
125
|
+
this.getSvgRoot().insertBefore(this.anchorChain, this.getSvgRoot().firstChild)
|
|
155
126
|
}
|
|
156
127
|
|
|
157
128
|
redrawAnchorChain() {
|
|
158
|
-
if (!this.anchorChain) return
|
|
129
|
+
if (!this.anchorChain) return
|
|
159
130
|
|
|
160
|
-
const location = this.getRelativeToSurfaceXY()
|
|
161
|
-
this.anchorChain
|
|
162
|
-
this.anchorChain
|
|
131
|
+
const location = this.getRelativeToSurfaceXY()
|
|
132
|
+
this.anchorChain.setAttribute('x1', `${this.anchor!.x - location.x}`)
|
|
133
|
+
this.anchorChain.setAttribute('y1', `${this.anchor!.y - location.y}`)
|
|
163
134
|
}
|
|
164
135
|
|
|
165
136
|
getId() {
|
|
166
|
-
return this.id
|
|
137
|
+
return this.id
|
|
167
138
|
}
|
|
168
139
|
|
|
169
140
|
getSourceBlock() {
|
|
170
|
-
return this.sourceBlock
|
|
141
|
+
return this.sourceBlock
|
|
171
142
|
}
|
|
172
143
|
|
|
173
144
|
dispose() {
|
|
174
|
-
this.disposing = true
|
|
175
|
-
Blockly.utils.dom.removeNode(this.anchorChain ?? null)
|
|
145
|
+
this.disposing = true
|
|
146
|
+
Blockly.utils.dom.removeNode(this.anchorChain ?? null)
|
|
176
147
|
if (this.sourceBlock) {
|
|
177
|
-
Blockly.Events.fire(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const block = this.sourceBlock;
|
|
181
|
-
this.sourceBlock = null;
|
|
148
|
+
Blockly.Events.fire(new (Blockly.Events.get('block_comment_delete'))(this, this.sourceBlock))
|
|
149
|
+
const block = this.sourceBlock
|
|
150
|
+
this.sourceBlock = null
|
|
182
151
|
if (!block.isDeadOrDying()) {
|
|
183
|
-
block.setCommentText(null)
|
|
152
|
+
block.setCommentText(null)
|
|
184
153
|
}
|
|
185
154
|
}
|
|
186
|
-
super.dispose()
|
|
155
|
+
super.dispose()
|
|
187
156
|
}
|
|
188
157
|
|
|
189
158
|
getFocusableElement() {
|
|
190
|
-
return this.getSvgRoot()
|
|
159
|
+
return this.getSvgRoot()
|
|
191
160
|
}
|
|
192
161
|
|
|
193
162
|
getFocusableTree() {
|
|
194
|
-
return this.workspace
|
|
163
|
+
return this.workspace
|
|
195
164
|
}
|
|
196
165
|
|
|
197
166
|
onNodeFocus() {}
|
|
@@ -199,6 +168,6 @@ export class ScratchCommentBubble
|
|
|
199
168
|
onNodeBlur() {}
|
|
200
169
|
|
|
201
170
|
canBeFocused() {
|
|
202
|
-
return true
|
|
171
|
+
return true
|
|
203
172
|
}
|
|
204
173
|
}
|
|
@@ -1,169 +1,125 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2024 Google LLC
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import { ScratchCommentBubble } from "./scratch_comment_bubble";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import { ScratchCommentBubble } from './scratch_comment_bubble'
|
|
9
7
|
|
|
10
8
|
interface CommentState {
|
|
11
|
-
text: string
|
|
12
|
-
height: number
|
|
13
|
-
width: number
|
|
14
|
-
x: number
|
|
15
|
-
y: number
|
|
16
|
-
collapsed: boolean
|
|
9
|
+
text: string
|
|
10
|
+
height: number
|
|
11
|
+
width: number
|
|
12
|
+
x: number
|
|
13
|
+
y: number
|
|
14
|
+
collapsed: boolean
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* Custom comment icon that draws no icon indicator, used for block comments.
|
|
21
19
|
*/
|
|
22
|
-
export class ScratchCommentIcon
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
private onTextChangedListener: (oldText: string, newText: string) => void;
|
|
28
|
-
private onSizeChangedListener: (
|
|
29
|
-
oldSize: Blockly.utils.Size,
|
|
30
|
-
newSize: Blockly.utils.Size
|
|
31
|
-
) => void;
|
|
32
|
-
private onCollapseListener: (collapsed: boolean) => void;
|
|
20
|
+
export class ScratchCommentIcon extends Blockly.icons.Icon implements Blockly.ISerializable, Blockly.IHasBubble {
|
|
21
|
+
private commentBubble: ScratchCommentBubble
|
|
22
|
+
private onTextChangedListener: (oldText: string, newText: string) => void
|
|
23
|
+
private onSizeChangedListener: (oldSize: Blockly.utils.Size, newSize: Blockly.utils.Size) => void
|
|
24
|
+
private onCollapseListener: (collapsed: boolean) => void
|
|
33
25
|
|
|
34
26
|
constructor(protected sourceBlock: Blockly.BlockSvg) {
|
|
35
|
-
super(sourceBlock)
|
|
36
|
-
this.commentBubble = new ScratchCommentBubble(this.sourceBlock)
|
|
37
|
-
this.fireCreateEvent()
|
|
38
|
-
this.onTextChangedListener = this.onTextChanged.bind(this)
|
|
39
|
-
this.onSizeChangedListener = this.onSizeChanged.bind(this)
|
|
40
|
-
this.onCollapseListener = this.onCollapsed.bind(this)
|
|
41
|
-
this.commentBubble.addTextChangeListener(this.onTextChangedListener)
|
|
42
|
-
this.commentBubble.addSizeChangeListener(this.onSizeChangedListener)
|
|
43
|
-
this.commentBubble.addOnCollapseListener(this.onCollapseListener)
|
|
27
|
+
super(sourceBlock)
|
|
28
|
+
this.commentBubble = new ScratchCommentBubble(this.sourceBlock)
|
|
29
|
+
this.fireCreateEvent()
|
|
30
|
+
this.onTextChangedListener = this.onTextChanged.bind(this)
|
|
31
|
+
this.onSizeChangedListener = this.onSizeChanged.bind(this)
|
|
32
|
+
this.onCollapseListener = this.onCollapsed.bind(this)
|
|
33
|
+
this.commentBubble.addTextChangeListener(this.onTextChangedListener)
|
|
34
|
+
this.commentBubble.addSizeChangeListener(this.onSizeChangedListener)
|
|
35
|
+
this.commentBubble.addOnCollapseListener(this.onCollapseListener)
|
|
44
36
|
}
|
|
45
37
|
|
|
46
38
|
getType(): Blockly.icons.IconType<ScratchCommentIcon> {
|
|
47
|
-
return Blockly.icons.IconType.COMMENT
|
|
39
|
+
return Blockly.icons.IconType.COMMENT
|
|
48
40
|
}
|
|
49
41
|
|
|
50
42
|
initView(pointerDownListener: (e: PointerEvent) => void) {
|
|
51
43
|
// Scratch comments have no indicator icon on the block.
|
|
52
|
-
return
|
|
44
|
+
return
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
getSize(): Blockly.utils.Size {
|
|
56
48
|
// Awful hack to cancel out the default padding added to icons.
|
|
57
|
-
return new Blockly.utils.Size(-8, 0)
|
|
49
|
+
return new Blockly.utils.Size(-8, 0)
|
|
58
50
|
}
|
|
59
51
|
|
|
60
52
|
getAnchorPoint(): Blockly.utils.Coordinate {
|
|
61
|
-
const blockRect = this.sourceBlock.getBoundingRectangleWithoutChildren()
|
|
62
|
-
const y = blockRect.top + this.offsetInBlock.y
|
|
63
|
-
const x = this.sourceBlock.workspace.RTL ? blockRect.left : blockRect.right
|
|
64
|
-
return new Blockly.utils.Coordinate(x, y)
|
|
53
|
+
const blockRect = this.sourceBlock.getBoundingRectangleWithoutChildren()
|
|
54
|
+
const y = blockRect.top + this.offsetInBlock.y
|
|
55
|
+
const x = this.sourceBlock.workspace.RTL ? blockRect.left : blockRect.right
|
|
56
|
+
return new Blockly.utils.Coordinate(x, y)
|
|
65
57
|
}
|
|
66
58
|
|
|
67
59
|
onLocationChange(blockOrigin: Blockly.utils.Coordinate) {
|
|
68
|
-
if (!this.sourceBlock || !this.commentBubble) return
|
|
60
|
+
if (!this.sourceBlock || !this.commentBubble) return
|
|
69
61
|
|
|
70
62
|
if (this.sourceBlock.isInsertionMarker()) {
|
|
71
|
-
this.commentBubble.dispose()
|
|
72
|
-
return
|
|
63
|
+
this.commentBubble.dispose()
|
|
64
|
+
return
|
|
73
65
|
}
|
|
74
66
|
|
|
75
|
-
super.onLocationChange(blockOrigin)
|
|
76
|
-
const oldBubbleLocation = this.commentBubble.getRelativeToSurfaceXY()
|
|
77
|
-
this.commentBubble.setAnchorLocation(this.getAnchorPoint())
|
|
78
|
-
const newBubbleLocation = this.commentBubble.getRelativeToSurfaceXY()
|
|
67
|
+
super.onLocationChange(blockOrigin)
|
|
68
|
+
const oldBubbleLocation = this.commentBubble.getRelativeToSurfaceXY()
|
|
69
|
+
this.commentBubble.setAnchorLocation(this.getAnchorPoint())
|
|
70
|
+
const newBubbleLocation = this.commentBubble.getRelativeToSurfaceXY()
|
|
79
71
|
Blockly.Events.fire(
|
|
80
|
-
new (Blockly.Events.get(
|
|
81
|
-
|
|
82
|
-
oldBubbleLocation,
|
|
83
|
-
newBubbleLocation
|
|
84
|
-
)
|
|
85
|
-
);
|
|
72
|
+
new (Blockly.Events.get('block_comment_move'))(this.commentBubble, oldBubbleLocation, newBubbleLocation),
|
|
73
|
+
)
|
|
86
74
|
}
|
|
87
75
|
|
|
88
76
|
setText(text: string) {
|
|
89
|
-
this.commentBubble?.setText(text)
|
|
77
|
+
this.commentBubble?.setText(text)
|
|
90
78
|
}
|
|
91
79
|
|
|
92
80
|
getText(): string {
|
|
93
|
-
return this.commentBubble?.getText() ??
|
|
81
|
+
return this.commentBubble?.getText() ?? ''
|
|
94
82
|
}
|
|
95
83
|
|
|
96
84
|
onTextChanged(oldText: string, newText: string) {
|
|
97
85
|
Blockly.Events.fire(
|
|
98
|
-
new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
null,
|
|
102
|
-
oldText,
|
|
103
|
-
newText
|
|
104
|
-
)
|
|
105
|
-
);
|
|
106
|
-
Blockly.Events.fire(
|
|
107
|
-
new (Blockly.Events.get("block_comment_change"))(
|
|
108
|
-
this.commentBubble,
|
|
109
|
-
oldText,
|
|
110
|
-
newText
|
|
111
|
-
)
|
|
112
|
-
);
|
|
86
|
+
new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))(this.sourceBlock, 'comment', null, oldText, newText),
|
|
87
|
+
)
|
|
88
|
+
Blockly.Events.fire(new (Blockly.Events.get('block_comment_change'))(this.commentBubble, oldText, newText))
|
|
113
89
|
}
|
|
114
90
|
|
|
115
91
|
onCollapsed(collapsed: boolean) {
|
|
116
|
-
Blockly.Events.fire(
|
|
117
|
-
new (Blockly.Events.get("block_comment_collapse"))(
|
|
118
|
-
this.commentBubble,
|
|
119
|
-
collapsed
|
|
120
|
-
)
|
|
121
|
-
);
|
|
92
|
+
Blockly.Events.fire(new (Blockly.Events.get('block_comment_collapse'))(this.commentBubble, collapsed))
|
|
122
93
|
}
|
|
123
94
|
|
|
124
95
|
onSizeChanged(oldSize: Blockly.utils.Size, newSize: Blockly.utils.Size) {
|
|
125
|
-
Blockly.Events.fire(
|
|
126
|
-
new (Blockly.Events.get("block_comment_resize"))(
|
|
127
|
-
this.commentBubble,
|
|
128
|
-
oldSize,
|
|
129
|
-
newSize
|
|
130
|
-
)
|
|
131
|
-
);
|
|
96
|
+
Blockly.Events.fire(new (Blockly.Events.get('block_comment_resize'))(this.commentBubble, oldSize, newSize))
|
|
132
97
|
}
|
|
133
98
|
|
|
134
99
|
setBubbleSize(size: Blockly.utils.Size) {
|
|
135
|
-
this.commentBubble?.setSize(size)
|
|
100
|
+
this.commentBubble?.setSize(size)
|
|
136
101
|
}
|
|
137
102
|
|
|
138
103
|
getBubbleSize(): Blockly.utils.Size {
|
|
139
|
-
return this.commentBubble?.getSize() ?? new Blockly.utils.Size(0, 0)
|
|
104
|
+
return this.commentBubble?.getSize() ?? new Blockly.utils.Size(0, 0)
|
|
140
105
|
}
|
|
141
106
|
|
|
142
107
|
setBubbleLocation(newLocation: Blockly.utils.Coordinate) {
|
|
143
|
-
const oldLocation = this.getBubbleLocation()
|
|
144
|
-
this.commentBubble?.moveTo(newLocation)
|
|
145
|
-
Blockly.Events.fire(
|
|
146
|
-
new (Blockly.Events.get("block_comment_move"))(
|
|
147
|
-
this.commentBubble,
|
|
148
|
-
oldLocation,
|
|
149
|
-
newLocation
|
|
150
|
-
)
|
|
151
|
-
);
|
|
108
|
+
const oldLocation = this.getBubbleLocation()
|
|
109
|
+
this.commentBubble?.moveTo(newLocation)
|
|
110
|
+
Blockly.Events.fire(new (Blockly.Events.get('block_comment_move'))(this.commentBubble, oldLocation, newLocation))
|
|
152
111
|
}
|
|
153
112
|
|
|
154
113
|
getBubbleLocation(): Blockly.utils.Coordinate {
|
|
155
|
-
return this.commentBubble?.getRelativeToSurfaceXY()
|
|
114
|
+
return this.commentBubble?.getRelativeToSurfaceXY()
|
|
156
115
|
}
|
|
157
116
|
|
|
158
117
|
saveState(): CommentState | null {
|
|
159
|
-
if (!this.commentBubble) return null
|
|
160
|
-
|
|
161
|
-
const size = this.getBubbleSize()
|
|
162
|
-
const bubbleLocation = this.commentBubble.getRelativeToSurfaceXY()
|
|
163
|
-
const delta = Blockly.utils.Coordinate.difference(
|
|
164
|
-
bubbleLocation,
|
|
165
|
-
this.workspaceLocation
|
|
166
|
-
);
|
|
118
|
+
if (!this.commentBubble) return null
|
|
119
|
+
|
|
120
|
+
const size = this.getBubbleSize()
|
|
121
|
+
const bubbleLocation = this.commentBubble.getRelativeToSurfaceXY()
|
|
122
|
+
const delta = Blockly.utils.Coordinate.difference(bubbleLocation, this.workspaceLocation)
|
|
167
123
|
return {
|
|
168
124
|
text: this.getText(),
|
|
169
125
|
height: size.height,
|
|
@@ -171,51 +127,46 @@ export class ScratchCommentIcon
|
|
|
171
127
|
x: delta.x,
|
|
172
128
|
y: delta.y,
|
|
173
129
|
collapsed: this.commentBubble.isCollapsed(),
|
|
174
|
-
}
|
|
130
|
+
}
|
|
175
131
|
}
|
|
176
132
|
|
|
177
133
|
loadState(state: CommentState) {
|
|
178
|
-
Blockly.Events.setGroup(true)
|
|
179
|
-
this.setText(state
|
|
180
|
-
this.setBubbleSize(new Blockly.utils.Size(state
|
|
181
|
-
const delta = new Blockly.utils.Coordinate(state
|
|
182
|
-
const newBubbleLocation = Blockly.utils.Coordinate.sum(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
)
|
|
186
|
-
this.commentBubble.moveTo(newBubbleLocation);
|
|
187
|
-
this.commentBubble.setCollapsed(state["collapsed"]);
|
|
188
|
-
Blockly.Events.setGroup(false);
|
|
134
|
+
Blockly.Events.setGroup(true)
|
|
135
|
+
this.setText(state.text)
|
|
136
|
+
this.setBubbleSize(new Blockly.utils.Size(state.width, state.height))
|
|
137
|
+
const delta = new Blockly.utils.Coordinate(state.x, state.y)
|
|
138
|
+
const newBubbleLocation = Blockly.utils.Coordinate.sum(this.workspaceLocation, delta)
|
|
139
|
+
this.commentBubble.moveTo(newBubbleLocation)
|
|
140
|
+
this.commentBubble.setCollapsed(state.collapsed)
|
|
141
|
+
Blockly.Events.setGroup(false)
|
|
189
142
|
}
|
|
190
143
|
|
|
191
144
|
bubbleIsVisible(): boolean {
|
|
192
|
-
return true
|
|
145
|
+
return true
|
|
193
146
|
}
|
|
194
147
|
|
|
195
148
|
async setBubbleVisible(visible: boolean) {
|
|
196
|
-
this.commentBubble.setCollapsed(!visible)
|
|
149
|
+
this.commentBubble.setCollapsed(!visible)
|
|
197
150
|
}
|
|
198
151
|
|
|
199
152
|
getBubble(): ScratchCommentBubble | null {
|
|
200
|
-
return this.commentBubble
|
|
153
|
+
return this.commentBubble
|
|
201
154
|
}
|
|
202
155
|
|
|
203
156
|
dispose() {
|
|
204
|
-
this.commentBubble.dispose()
|
|
205
|
-
super.dispose()
|
|
157
|
+
this.commentBubble.dispose()
|
|
158
|
+
super.dispose()
|
|
206
159
|
}
|
|
207
160
|
|
|
208
161
|
canBeFocused() {
|
|
209
|
-
return false
|
|
162
|
+
return false
|
|
210
163
|
}
|
|
211
164
|
|
|
212
165
|
/**
|
|
213
166
|
* Fires a block comment create event corresponding to this icon's comment.
|
|
214
167
|
*/
|
|
215
168
|
fireCreateEvent() {
|
|
216
|
-
Blockly.Events.fire(
|
|
217
|
-
new (Blockly.Events.get("block_comment_create"))(this.commentBubble)
|
|
218
|
-
);
|
|
169
|
+
Blockly.Events.fire(new (Blockly.Events.get('block_comment_create'))(this.commentBubble))
|
|
219
170
|
}
|
|
220
171
|
}
|
|
221
172
|
|
|
@@ -223,5 +174,5 @@ Blockly.registry.register(
|
|
|
223
174
|
Blockly.registry.Type.ICON,
|
|
224
175
|
Blockly.icons.IconType.COMMENT.toString(),
|
|
225
176
|
ScratchCommentIcon,
|
|
226
|
-
true
|
|
227
|
-
)
|
|
177
|
+
true,
|
|
178
|
+
)
|