scratch-blocks 2.0.2 → 2.0.4
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 -1
- 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 +7 -10
- 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 +7 -9
- 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 -55
- 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 +3 -12
- 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 +13 -10
- 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 +488 -536
- 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 +136 -250
- 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 +52 -73
- package/src/flyout_checkbox_icon.ts +18 -28
- package/src/glows.ts +51 -58
- package/src/index.ts +119 -133
- package/src/procedures.ts +144 -211
- 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 +13 -15
- 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 +22 -17
- package/src/scratch_continuous_category.ts +24 -28
- package/src/scratch_continuous_toolbox.ts +20 -27
- package/src/scratch_dragger.ts +54 -86
- 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,38 +1,43 @@
|
|
|
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
|
* Custom connection checker to restrict which blocks can be connected.
|
|
11
9
|
*/
|
|
12
10
|
class ScratchConnectionChecker extends Blockly.ConnectionChecker {
|
|
11
|
+
override canConnectWithReason(
|
|
12
|
+
a: Blockly.Connection | null,
|
|
13
|
+
b: Blockly.Connection | null,
|
|
14
|
+
isDragging: boolean,
|
|
15
|
+
opt_distance?: number,
|
|
16
|
+
): number {
|
|
17
|
+
// The prototype block is visual-only and should not accept any connections.
|
|
18
|
+
const isPrototypeConnection = (c: Blockly.Connection | null) =>
|
|
19
|
+
c?.getSourceBlock().type === 'procedures_prototype'
|
|
20
|
+
if (isPrototypeConnection(a) || isPrototypeConnection(b)) {
|
|
21
|
+
return Blockly.Connection.REASON_CHECKS_FAILED
|
|
22
|
+
}
|
|
23
|
+
return super.canConnectWithReason(a, b, isDragging, opt_distance)
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
/**
|
|
14
27
|
* Returns whether or not the two connections should be allowed to connect.
|
|
15
|
-
*
|
|
16
28
|
* @param a One of the connections to check.
|
|
17
29
|
* @param b The other connection to check.
|
|
18
30
|
* @param distance The maximum allowable distance between connections.
|
|
19
31
|
* @returns True if the connections should be allowed to connect.
|
|
20
32
|
*/
|
|
21
|
-
doDragChecks(
|
|
22
|
-
a: Blockly.RenderedConnection,
|
|
23
|
-
b: Blockly.RenderedConnection,
|
|
24
|
-
distance: number
|
|
25
|
-
): boolean {
|
|
33
|
+
doDragChecks(a: Blockly.RenderedConnection, b: Blockly.RenderedConnection, distance: number): boolean {
|
|
26
34
|
// This check prevents dragging a block into the slot occupied by the
|
|
27
35
|
// procedure caller example block in a procedure definition block.
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
b.getParentInput()?.name === "custom_block"
|
|
31
|
-
) {
|
|
32
|
-
return false;
|
|
36
|
+
if (b.getSourceBlock().type === 'procedures_definition' && b.getParentInput()?.name === 'custom_block') {
|
|
37
|
+
return false
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
return super.doDragChecks(a, b, distance)
|
|
40
|
+
return super.doDragChecks(a, b, distance)
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
|
|
@@ -40,5 +45,5 @@ Blockly.registry.register(
|
|
|
40
45
|
Blockly.registry.Type.CONNECTION_CHECKER,
|
|
41
46
|
Blockly.registry.DEFAULT,
|
|
42
47
|
ScratchConnectionChecker,
|
|
43
|
-
true
|
|
44
|
-
)
|
|
48
|
+
true,
|
|
49
|
+
)
|
|
@@ -1,15 +1,13 @@
|
|
|
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
|
|
8
|
-
import { ContinuousCategory } from "@blockly/continuous-toolbox";
|
|
5
|
+
import { ContinuousCategory } from '@blockly/continuous-toolbox'
|
|
6
|
+
import * as Blockly from 'blockly/core'
|
|
9
7
|
|
|
10
8
|
type StatusIndicatorCategoryInfo = Blockly.utils.toolbox.CategoryInfo & {
|
|
11
|
-
showStatusButton?: string
|
|
12
|
-
}
|
|
9
|
+
showStatusButton?: string
|
|
10
|
+
}
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Selectable category shown in the Scratch toolbox.
|
|
@@ -20,10 +18,10 @@ export class ScratchContinuousCategory extends ContinuousCategory {
|
|
|
20
18
|
* in the flyout, typically for extensions that interface with hardware
|
|
21
19
|
* devices.
|
|
22
20
|
*/
|
|
23
|
-
private showStatusButton = false
|
|
21
|
+
private showStatusButton = false
|
|
24
22
|
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new ScratchContinuousCategory.
|
|
27
25
|
* @param toolboxItemDef A toolbox item definition.
|
|
28
26
|
* @param parentToolbox The toolbox this category is being added to.
|
|
29
27
|
* @param opt_parent The parent toolbox category, if any.
|
|
@@ -31,10 +29,10 @@ export class ScratchContinuousCategory extends ContinuousCategory {
|
|
|
31
29
|
constructor(
|
|
32
30
|
toolboxItemDef: StatusIndicatorCategoryInfo,
|
|
33
31
|
parentToolbox: Blockly.Toolbox,
|
|
34
|
-
opt_parent?: Blockly.ICollapsibleToolboxItem
|
|
32
|
+
opt_parent?: Blockly.ICollapsibleToolboxItem,
|
|
35
33
|
) {
|
|
36
|
-
super(toolboxItemDef, parentToolbox, opt_parent)
|
|
37
|
-
this.showStatusButton = toolboxItemDef
|
|
34
|
+
super(toolboxItemDef, parentToolbox, opt_parent)
|
|
35
|
+
this.showStatusButton = toolboxItemDef.showStatusButton === 'true'
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
/**
|
|
@@ -43,14 +41,14 @@ export class ScratchContinuousCategory extends ContinuousCategory {
|
|
|
43
41
|
*/
|
|
44
42
|
createIconDom_(): HTMLElement {
|
|
45
43
|
if (this.toolboxItemDef_.iconURI) {
|
|
46
|
-
const icon = document.createElement(
|
|
47
|
-
icon.src = this.toolboxItemDef_.iconURI
|
|
48
|
-
icon.className =
|
|
49
|
-
return icon
|
|
44
|
+
const icon = document.createElement('img')
|
|
45
|
+
icon.src = this.toolboxItemDef_.iconURI
|
|
46
|
+
icon.className = 'categoryIconBubble'
|
|
47
|
+
return icon
|
|
50
48
|
} else {
|
|
51
|
-
const icon = super.createIconDom_()
|
|
52
|
-
icon.style.border = `1px solid ${this.toolboxItemDef_
|
|
53
|
-
return icon
|
|
49
|
+
const icon = super.createIconDom_()
|
|
50
|
+
icon.style.border = `1px solid ${this.toolboxItemDef_.secondaryColour}`
|
|
51
|
+
return icon
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
|
|
@@ -59,29 +57,27 @@ export class ScratchContinuousCategory extends ContinuousCategory {
|
|
|
59
57
|
* @param isSelected True if this category is selected.
|
|
60
58
|
*/
|
|
61
59
|
setSelected(isSelected: boolean) {
|
|
62
|
-
super.setSelected(isSelected)
|
|
60
|
+
super.setSelected(isSelected)
|
|
63
61
|
// Prevent hardcoding the background color to grey.
|
|
64
|
-
this.rowDiv_.style.backgroundColor =
|
|
62
|
+
this.rowDiv_.style.backgroundColor = ''
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
/**
|
|
68
66
|
* Returns whether or not this category's label in the flyout should display
|
|
69
67
|
* status indicators.
|
|
68
|
+
* @returns True if the status indicator button should be shown.
|
|
70
69
|
*/
|
|
71
70
|
shouldShowStatusButton() {
|
|
72
|
-
return this.showStatusButton
|
|
71
|
+
return this.showStatusButton
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
/** Registers this toolbox category and unregisters the default one. */
|
|
77
76
|
export function registerScratchContinuousCategory() {
|
|
78
|
-
Blockly.registry.unregister(
|
|
79
|
-
Blockly.registry.Type.TOOLBOX_ITEM,
|
|
80
|
-
ScratchContinuousCategory.registrationName
|
|
81
|
-
);
|
|
77
|
+
Blockly.registry.unregister(Blockly.registry.Type.TOOLBOX_ITEM, ScratchContinuousCategory.registrationName)
|
|
82
78
|
Blockly.registry.register(
|
|
83
79
|
Blockly.registry.Type.TOOLBOX_ITEM,
|
|
84
80
|
ScratchContinuousCategory.registrationName,
|
|
85
|
-
ScratchContinuousCategory
|
|
86
|
-
)
|
|
81
|
+
ScratchContinuousCategory,
|
|
82
|
+
)
|
|
87
83
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
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
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { STATUS_INDICATOR_LABEL_TYPE } from "./status_indicator_label_flyout_inflater";
|
|
5
|
+
import { ContinuousToolbox } from '@blockly/continuous-toolbox'
|
|
6
|
+
import * as Blockly from 'blockly/core'
|
|
7
|
+
import { ScratchContinuousCategory } from './scratch_continuous_category'
|
|
8
|
+
import { STATUS_INDICATOR_LABEL_TYPE } from './status_indicator_label_flyout_inflater'
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* A toolbox that displays items from all categories in one scrolling list.
|
|
@@ -16,7 +14,7 @@ export class ScratchContinuousToolbox extends ContinuousToolbox {
|
|
|
16
14
|
/**
|
|
17
15
|
* List of functions to run after the next time the toolbox renders.
|
|
18
16
|
*/
|
|
19
|
-
private postRenderCallbacks: (() => void)[] = []
|
|
17
|
+
private postRenderCallbacks: (() => void)[] = []
|
|
20
18
|
|
|
21
19
|
refreshSelection() {
|
|
22
20
|
// Intentionally a no-op, Scratch manually manages refreshing the toolbox
|
|
@@ -26,37 +24,33 @@ export class ScratchContinuousToolbox extends ContinuousToolbox {
|
|
|
26
24
|
/**
|
|
27
25
|
* Converts the given toolbox item to a corresponding array of items that
|
|
28
26
|
* should appear in the flyout.
|
|
29
|
-
*
|
|
30
|
-
* @param toolboxItem The toolbox item to convert.
|
|
27
|
+
* @param toolboxItem The toolbox item to translate into flyout content.
|
|
31
28
|
* @returns An array of flyout item definitions.
|
|
32
29
|
*/
|
|
33
30
|
protected convertToolboxItemToFlyoutItems(
|
|
34
|
-
toolboxItem: Blockly.IToolboxItem
|
|
31
|
+
toolboxItem: Blockly.IToolboxItem,
|
|
35
32
|
): Blockly.utils.toolbox.FlyoutItemInfoArray {
|
|
36
|
-
const contents = super.convertToolboxItemToFlyoutItems(toolboxItem)
|
|
37
|
-
if (
|
|
38
|
-
toolboxItem instanceof ScratchContinuousCategory &&
|
|
39
|
-
toolboxItem.shouldShowStatusButton()
|
|
40
|
-
) {
|
|
33
|
+
const contents = super.convertToolboxItemToFlyoutItems(toolboxItem)
|
|
34
|
+
if (toolboxItem instanceof ScratchContinuousCategory && toolboxItem.shouldShowStatusButton()) {
|
|
41
35
|
contents.splice(0, 1, {
|
|
42
36
|
kind: STATUS_INDICATOR_LABEL_TYPE,
|
|
43
37
|
id: toolboxItem.getId(),
|
|
44
38
|
text: toolboxItem.getName(),
|
|
45
|
-
})
|
|
39
|
+
})
|
|
46
40
|
}
|
|
47
|
-
return contents
|
|
41
|
+
return contents
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
/**
|
|
51
45
|
* Forcibly rerenders the toolbox, preserving selection when possible.
|
|
52
46
|
*/
|
|
53
47
|
forceRerender() {
|
|
54
|
-
const selectedCategoryName = this.selectedItem_?.getName()
|
|
55
|
-
this.getFlyout().show(this.getInitialFlyoutContents())
|
|
56
|
-
this.selectCategoryByName(selectedCategoryName)
|
|
57
|
-
let callback
|
|
48
|
+
const selectedCategoryName = this.selectedItem_?.getName()
|
|
49
|
+
this.getFlyout().show(this.getInitialFlyoutContents())
|
|
50
|
+
this.selectCategoryByName(selectedCategoryName)
|
|
51
|
+
let callback
|
|
58
52
|
while ((callback = this.postRenderCallbacks.shift())) {
|
|
59
|
-
callback()
|
|
53
|
+
callback()
|
|
60
54
|
}
|
|
61
55
|
}
|
|
62
56
|
|
|
@@ -65,22 +59,21 @@ export class ScratchContinuousToolbox extends ContinuousToolbox {
|
|
|
65
59
|
* @param callback A callback to run whenever the toolbox next rerenders.
|
|
66
60
|
*/
|
|
67
61
|
runAfterRerender(callback: () => void) {
|
|
68
|
-
this.postRenderCallbacks.push(callback)
|
|
62
|
+
this.postRenderCallbacks.push(callback)
|
|
69
63
|
}
|
|
70
64
|
|
|
71
65
|
/**
|
|
72
66
|
* Returns whether or not the given item should be deselected.
|
|
73
67
|
* Prevents items from being deselected without a replacement.
|
|
74
|
-
*
|
|
75
68
|
* @param oldItem The item that was previously selected.
|
|
76
69
|
* @param newItem The item that is proposed to be selected instead.
|
|
77
70
|
* @returns True if the old item should be allowed to be deselected.
|
|
78
71
|
*/
|
|
79
72
|
shouldDeselectItem_(
|
|
80
73
|
oldItem: Blockly.ISelectableToolboxItem | null,
|
|
81
|
-
newItem: Blockly.ISelectableToolboxItem | null
|
|
74
|
+
newItem: Blockly.ISelectableToolboxItem | null,
|
|
82
75
|
) {
|
|
83
|
-
if (!newItem) return false
|
|
84
|
-
return super.shouldDeselectItem_(oldItem, newItem)
|
|
76
|
+
if (!newItem) return false
|
|
77
|
+
return super.shouldDeselectItem_(oldItem, newItem)
|
|
85
78
|
}
|
|
86
79
|
}
|
package/src/scratch_dragger.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
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 { BlockDragOutside } from
|
|
9
|
-
import {
|
|
10
|
-
import { isProcedureBlock, getCallers } from "./procedures";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import { BlockDragEnd } from './events/events_block_drag_end'
|
|
7
|
+
import { BlockDragOutside } from './events/events_block_drag_outside'
|
|
8
|
+
import { isProcedureBlock, getCallers } from './procedures'
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* CSS class that allows the workspace to overflow its bounds when set.
|
|
14
12
|
*/
|
|
15
|
-
const BOUNDLESS_CLASS =
|
|
13
|
+
const BOUNDLESS_CLASS = 'boundless'
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* Class responsible for managing dragging items on the workspace.
|
|
@@ -21,138 +19,119 @@ export class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
21
19
|
/**
|
|
22
20
|
* Whether or not the current drag location is outside of the main workspace.
|
|
23
21
|
*/
|
|
24
|
-
draggedOutOfBounds = false
|
|
22
|
+
draggedOutOfBounds = false
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
25
|
* Whether or not the current drag started from the flyout.
|
|
28
26
|
*/
|
|
29
|
-
originatedFromFlyout = false
|
|
27
|
+
originatedFromFlyout = false
|
|
30
28
|
|
|
31
29
|
/**
|
|
32
30
|
* Sets the current item being dragged.
|
|
33
|
-
*
|
|
34
31
|
* @param draggable The item being dragged.
|
|
35
32
|
*/
|
|
36
33
|
setDraggable(draggable: Blockly.IDraggable) {
|
|
37
|
-
this.draggable = draggable
|
|
34
|
+
this.draggable = draggable
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
/**
|
|
41
38
|
* Handles the start of a drag operation.
|
|
42
|
-
*
|
|
43
39
|
* @param event The event that triggered the drag.
|
|
44
40
|
*/
|
|
45
41
|
onDragStart(event: PointerEvent) {
|
|
46
|
-
super.onDragStart(event)
|
|
42
|
+
super.onDragStart(event)
|
|
47
43
|
if (this.draggable instanceof Blockly.BlockSvg) {
|
|
48
|
-
this.workspace.addClass(BOUNDLESS_CLASS)
|
|
49
|
-
const absoluteMetrics = this.workspace
|
|
50
|
-
|
|
51
|
-
.getAbsoluteMetrics();
|
|
52
|
-
const viewMetrics = this.workspace.getMetricsManager().getViewMetrics();
|
|
44
|
+
this.workspace.addClass(BOUNDLESS_CLASS)
|
|
45
|
+
const absoluteMetrics = this.workspace.getMetricsManager().getAbsoluteMetrics()
|
|
46
|
+
const viewMetrics = this.workspace.getMetricsManager().getViewMetrics()
|
|
53
47
|
if (
|
|
54
48
|
this.workspace.RTL
|
|
55
|
-
? event.clientX >
|
|
56
|
-
this.workspace.getParentSvg().getBoundingClientRect().left +
|
|
57
|
-
viewMetrics.width
|
|
49
|
+
? event.clientX > this.workspace.getParentSvg().getBoundingClientRect().left + viewMetrics.width
|
|
58
50
|
: event.clientX < absoluteMetrics.left
|
|
59
51
|
) {
|
|
60
|
-
this.originatedFromFlyout = true
|
|
52
|
+
this.originatedFromFlyout = true
|
|
61
53
|
}
|
|
62
54
|
}
|
|
63
55
|
}
|
|
64
56
|
|
|
65
57
|
/**
|
|
66
58
|
* Handles motion during an ongoing drag operation.
|
|
67
|
-
*
|
|
68
59
|
* @param event The event that triggered this call.
|
|
69
60
|
* @param totalDelta The change in pointer position since the last invocation.
|
|
70
61
|
*/
|
|
71
62
|
onDrag(event: PointerEvent, totalDelta: Blockly.utils.Coordinate) {
|
|
72
|
-
super.onDrag(event, totalDelta)
|
|
73
|
-
this.updateOutOfBoundsState(event)
|
|
63
|
+
super.onDrag(event, totalDelta)
|
|
64
|
+
this.updateOutOfBoundsState(event)
|
|
74
65
|
}
|
|
75
66
|
|
|
76
67
|
/**
|
|
77
68
|
* Records whether or not the current drag is out of the workspace's bounds.
|
|
78
|
-
*
|
|
79
69
|
* @param event The event that triggered this call.
|
|
80
70
|
*/
|
|
81
71
|
updateOutOfBoundsState(event: PointerEvent) {
|
|
82
72
|
if (this.draggable instanceof Blockly.BlockSvg) {
|
|
83
|
-
const outOfBounds = !this.isInsideWorkspace(event)
|
|
73
|
+
const outOfBounds = !this.isInsideWorkspace(event)
|
|
84
74
|
if (outOfBounds !== this.draggedOutOfBounds) {
|
|
85
|
-
const event = new BlockDragOutside(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
);
|
|
89
|
-
Blockly.Events.fire(event);
|
|
90
|
-
this.draggedOutOfBounds = outOfBounds;
|
|
75
|
+
const event = new BlockDragOutside(this.getDragRoot(this.draggable) as Blockly.BlockSvg, outOfBounds)
|
|
76
|
+
Blockly.Events.fire(event)
|
|
77
|
+
this.draggedOutOfBounds = outOfBounds
|
|
91
78
|
}
|
|
92
79
|
}
|
|
93
80
|
}
|
|
94
81
|
|
|
95
82
|
/**
|
|
96
83
|
* Handles the end of a drag.
|
|
97
|
-
*
|
|
98
84
|
* @param event The event that ended the drag.
|
|
99
85
|
*/
|
|
100
86
|
onDragEnd(event: PointerEvent) {
|
|
87
|
+
// When the prototype block is dragged (via its DelegateToParentDraggable
|
|
88
|
+
// strategy), this.draggable is the prototype, but getDragRoot returns the
|
|
89
|
+
// definition. Handle both cases for the "procedure is in use" check.
|
|
90
|
+
const dragRoot = this.getDragRoot(this.draggable)
|
|
101
91
|
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.wouldDeleteDraggable(event,
|
|
92
|
+
dragRoot instanceof Blockly.BlockSvg &&
|
|
93
|
+
dragRoot.type === 'procedures_definition' &&
|
|
94
|
+
this.wouldDeleteDraggable(event, dragRoot.getRootBlock())
|
|
105
95
|
) {
|
|
106
|
-
const prototype =
|
|
107
|
-
.getInput("custom_block")!
|
|
108
|
-
.connection!.targetBlock();
|
|
96
|
+
const prototype = dragRoot.getInput('custom_block')!.connection!.targetBlock()
|
|
109
97
|
const hasCaller =
|
|
110
98
|
prototype instanceof Blockly.BlockSvg &&
|
|
111
99
|
isProcedureBlock(prototype) &&
|
|
112
|
-
getCallers(
|
|
113
|
-
prototype.getProcCode(),
|
|
114
|
-
this.draggable.workspace,
|
|
115
|
-
this.draggable.getRootBlock(),
|
|
116
|
-
false
|
|
117
|
-
).length > 0;
|
|
100
|
+
getCallers(prototype.getProcCode(), dragRoot.workspace, dragRoot.getRootBlock(), false).length > 0
|
|
118
101
|
|
|
119
102
|
if (hasCaller) {
|
|
120
|
-
Blockly.dialog.alert(Blockly.Msg.PROCEDURE_USED)
|
|
121
|
-
this.draggable.revertDrag()
|
|
122
|
-
this.draggable.endDrag()
|
|
123
|
-
return
|
|
103
|
+
Blockly.dialog.alert(Blockly.Msg.PROCEDURE_USED)
|
|
104
|
+
this.draggable.revertDrag()
|
|
105
|
+
this.draggable.endDrag()
|
|
106
|
+
return
|
|
124
107
|
}
|
|
125
108
|
}
|
|
126
109
|
|
|
127
|
-
super.onDragEnd(event)
|
|
110
|
+
super.onDragEnd(event)
|
|
128
111
|
|
|
129
|
-
this.updateOutOfBoundsState(event)
|
|
112
|
+
this.updateOutOfBoundsState(event)
|
|
130
113
|
if (this.draggable instanceof Blockly.BlockSvg) {
|
|
131
|
-
const event = new BlockDragEnd(
|
|
132
|
-
|
|
133
|
-
this.draggedOutOfBounds
|
|
134
|
-
);
|
|
135
|
-
Blockly.Events.fire(event);
|
|
114
|
+
const event = new BlockDragEnd(this.getDragRoot(this.draggable) as Blockly.BlockSvg, this.draggedOutOfBounds)
|
|
115
|
+
Blockly.Events.fire(event)
|
|
136
116
|
// If this block was dragged out of the flyout and dropped outside of
|
|
137
117
|
// the workspace (e.g. on a different sprite), the block that was created
|
|
138
118
|
// on the workspace in order to depict the block mid-drag needs to be
|
|
139
119
|
// deleted.
|
|
140
120
|
if (this.originatedFromFlyout && this.draggedOutOfBounds) {
|
|
141
121
|
Blockly.renderManagement.finishQueuedRenders().then(() => {
|
|
142
|
-
const rootBlock = this.getDragRoot(this.draggable)
|
|
122
|
+
const rootBlock = this.getDragRoot(this.draggable)
|
|
143
123
|
if (rootBlock instanceof Blockly.BlockSvg) {
|
|
144
|
-
rootBlock.dispose()
|
|
124
|
+
rootBlock.dispose()
|
|
145
125
|
}
|
|
146
|
-
})
|
|
126
|
+
})
|
|
147
127
|
}
|
|
148
128
|
}
|
|
149
|
-
this.workspace.removeClass(BOUNDLESS_CLASS)
|
|
129
|
+
this.workspace.removeClass(BOUNDLESS_CLASS)
|
|
150
130
|
}
|
|
151
131
|
|
|
152
132
|
/**
|
|
153
133
|
* Returns whether or not the dragged item should return to its starting
|
|
154
134
|
* position.
|
|
155
|
-
*
|
|
156
135
|
* @param event The drag event that triggered this check.
|
|
157
136
|
* @param rootDraggable The topmost item being dragged.
|
|
158
137
|
* @returns True if the draggable should return to its starting position.
|
|
@@ -161,15 +140,12 @@ export class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
161
140
|
// If a block is dragged out of the workspace to be e.g. dropped on another
|
|
162
141
|
// sprite, it should remain in the same place on the workspace where it was,
|
|
163
142
|
// rather than being moved to an invisible part of the workspace.
|
|
164
|
-
return (
|
|
165
|
-
this.draggedOutOfBounds || super.shouldReturnToStart(event, rootDraggable)
|
|
166
|
-
);
|
|
143
|
+
return this.draggedOutOfBounds || super.shouldReturnToStart(event, rootDraggable)
|
|
167
144
|
}
|
|
168
145
|
|
|
169
146
|
/**
|
|
170
|
-
* Returns the root element being dragged. For shadow blocks
|
|
171
|
-
* parent block.
|
|
172
|
-
*
|
|
147
|
+
* Returns the root element being dragged. For shadow blocks and the
|
|
148
|
+
* procedures_prototype block, this is the parent block.
|
|
173
149
|
* @param draggable The element being dragged directly.
|
|
174
150
|
* @returns The element being dragged, or its parent.
|
|
175
151
|
*/
|
|
@@ -177,35 +153,27 @@ export class ScratchDragger extends Blockly.dragging.Dragger {
|
|
|
177
153
|
// We can't just use getRootBlock() here because, when blocks are detached
|
|
178
154
|
// from a stack via dragging, getRootBlock() still returns the root of that
|
|
179
155
|
// stack.
|
|
180
|
-
if (
|
|
181
|
-
|
|
156
|
+
if (
|
|
157
|
+
draggable instanceof Blockly.BlockSvg &&
|
|
158
|
+
(draggable.isShadow() || draggable.type === 'procedures_prototype')
|
|
159
|
+
) {
|
|
160
|
+
return draggable.getParent()
|
|
182
161
|
}
|
|
183
162
|
|
|
184
|
-
return draggable
|
|
163
|
+
return draggable
|
|
185
164
|
}
|
|
186
165
|
|
|
187
166
|
/**
|
|
188
167
|
* Returns whether or not the given event occurred within the bounds of the
|
|
189
168
|
* workspace.
|
|
190
|
-
*
|
|
191
169
|
* @param event The event to check.
|
|
192
170
|
* @returns True if the event occurred inside the workspace.
|
|
193
171
|
*/
|
|
194
172
|
isInsideWorkspace(event: PointerEvent) {
|
|
195
|
-
const bounds = this.workspace.getParentSvg().getBoundingClientRect()
|
|
196
|
-
const workspaceRect = new Blockly.utils.Rect(
|
|
197
|
-
|
|
198
|
-
bounds.bottom,
|
|
199
|
-
bounds.left,
|
|
200
|
-
bounds.right
|
|
201
|
-
);
|
|
202
|
-
return workspaceRect.contains(event.clientX, event.clientY);
|
|
173
|
+
const bounds = this.workspace.getParentSvg().getBoundingClientRect()
|
|
174
|
+
const workspaceRect = new Blockly.utils.Rect(bounds.top, bounds.bottom, bounds.left, bounds.right)
|
|
175
|
+
return workspaceRect.contains(event.clientX, event.clientY)
|
|
203
176
|
}
|
|
204
177
|
}
|
|
205
178
|
|
|
206
|
-
Blockly.registry.register(
|
|
207
|
-
Blockly.registry.Type.BLOCK_DRAGGER,
|
|
208
|
-
Blockly.registry.DEFAULT,
|
|
209
|
-
ScratchDragger,
|
|
210
|
-
true
|
|
211
|
-
);
|
|
179
|
+
Blockly.registry.register(Blockly.registry.Type.BLOCK_DRAGGER, Blockly.registry.DEFAULT, ScratchDragger, true)
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Copyright 2025 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
|
* Displays an indicator of where a block being dragged will be connected.
|
|
@@ -13,7 +11,6 @@ class ScratchInsertionMarkerPreviewer extends Blockly.InsertionMarkerPreviewer {
|
|
|
13
11
|
/**
|
|
14
12
|
* Transforms the given block into a JSON representation used to construct an
|
|
15
13
|
* insertion marker.
|
|
16
|
-
*
|
|
17
14
|
* @param block The block to serialize and use as an insertion marker.
|
|
18
15
|
* @returns A JSON-formatted string corresponding to a serialized
|
|
19
16
|
* representation of the given block suitable for use as an insertion
|
|
@@ -25,15 +22,13 @@ class ScratchInsertionMarkerPreviewer extends Blockly.InsertionMarkerPreviewer {
|
|
|
25
22
|
addInputBlocks: true,
|
|
26
23
|
addNextBlocks: false,
|
|
27
24
|
doFullSerialization: false,
|
|
28
|
-
})
|
|
25
|
+
})
|
|
29
26
|
|
|
30
27
|
if (!blockJson) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`Failed to serialize source block. ${block.toDevString()}`
|
|
33
|
-
);
|
|
28
|
+
throw new Error(`Failed to serialize source block. ${block.toDevString()}`)
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
return blockJson
|
|
31
|
+
return blockJson
|
|
37
32
|
}
|
|
38
33
|
}
|
|
39
34
|
|
|
@@ -41,5 +36,5 @@ Blockly.registry.register(
|
|
|
41
36
|
Blockly.registry.Type.CONNECTION_PREVIEWER,
|
|
42
37
|
Blockly.registry.DEFAULT,
|
|
43
38
|
ScratchInsertionMarkerPreviewer,
|
|
44
|
-
true
|
|
45
|
-
)
|
|
39
|
+
true,
|
|
40
|
+
)
|
|
@@ -1,10 +1,8 @@
|
|
|
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
|
* Class that provides storage for variables.
|
|
@@ -14,15 +12,10 @@ class ScratchVariableMap extends Blockly.VariableMap {
|
|
|
14
12
|
// Variable names in Blockly are case-insensitive, but case sensitive in
|
|
15
13
|
// Scratch. Override the implementation to only return a variable whose name
|
|
16
14
|
// is identical to the one requested.
|
|
17
|
-
const variables = this.getVariablesOfType(type ??
|
|
18
|
-
if (!variables.length) return null
|
|
19
|
-
return variables.find((v) => v.getName() === name) ?? null
|
|
15
|
+
const variables = this.getVariablesOfType(type ?? '')
|
|
16
|
+
if (!variables.length) return null
|
|
17
|
+
return variables.find((v) => v.getName() === name) ?? null
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
Blockly.registry.register(
|
|
24
|
-
Blockly.registry.Type.VARIABLE_MAP,
|
|
25
|
-
Blockly.registry.DEFAULT,
|
|
26
|
-
ScratchVariableMap,
|
|
27
|
-
true
|
|
28
|
-
);
|
|
21
|
+
Blockly.registry.register(Blockly.registry.Type.VARIABLE_MAP, Blockly.registry.DEFAULT, ScratchVariableMap, true)
|
|
@@ -1,10 +1,8 @@
|
|
|
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
|
* Class that represents a variable with extra fields for Scratch.
|
|
@@ -16,15 +14,10 @@ export class ScratchVariableModel extends Blockly.VariableModel {
|
|
|
16
14
|
type?: string,
|
|
17
15
|
id?: string,
|
|
18
16
|
public isLocal = false,
|
|
19
|
-
public isCloud = false
|
|
17
|
+
public isCloud = false,
|
|
20
18
|
) {
|
|
21
|
-
super(workspace, name, type, id)
|
|
19
|
+
super(workspace, name, type, id)
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
Blockly.registry.register(
|
|
26
|
-
Blockly.registry.Type.VARIABLE_MODEL,
|
|
27
|
-
Blockly.registry.DEFAULT,
|
|
28
|
-
ScratchVariableModel,
|
|
29
|
-
true
|
|
30
|
-
);
|
|
23
|
+
Blockly.registry.register(Blockly.registry.Type.VARIABLE_MODEL, Blockly.registry.DEFAULT, ScratchVariableModel, true)
|