scratch-blocks 2.0.1 → 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/AGENTS.md +140 -0
- 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 +7 -31
- 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 +5 -8
- 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 +4 -5
- 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 +7 -8
- package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
- package/dist/types/src/renderer/constants.d.ts +41 -0
- package/dist/types/src/renderer/constants.d.ts.map +1 -0
- package/dist/types/src/renderer/drawer.d.ts +7 -6
- 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 +9 -16
- 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 +3 -6
- package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_icon.d.ts +3 -4
- 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 +2 -11
- 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 +2 -3
- 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 +3 -3
- 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 +16 -19
- package/src/blocks/colour.ts +12 -15
- package/src/blocks/control.ts +171 -174
- package/src/blocks/data.ts +233 -272
- 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 +421 -511
- 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 +59 -84
- package/src/css.ts +3 -4
- package/src/data_category.ts +137 -251
- package/src/events/events_block_comment_base.ts +23 -30
- package/src/events/events_block_comment_change.ts +21 -42
- package/src/events/events_block_comment_collapse.ts +27 -36
- package/src/events/events_block_comment_create.ts +32 -46
- package/src/events/events_block_comment_delete.ts +12 -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 +37 -42
- package/src/fields/field_colour_slider.ts +186 -216
- package/src/fields/field_matrix.ts +202 -270
- package/src/fields/field_note.ts +277 -375
- 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 +151 -187
- package/src/fields/scratch_field_dropdown.ts +15 -19
- package/src/fields/scratch_field_number.ts +125 -181
- package/src/fields/scratch_field_variable.ts +57 -75
- package/src/flyout_checkbox_icon.ts +18 -28
- package/src/glows.ts +52 -59
- package/src/index.ts +119 -133
- package/src/procedures.ts +150 -209
- 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 +12 -16
- 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 +39 -56
- package/src/renderer/renderer.ts +17 -30
- package/src/scratch_block_paster.ts +12 -20
- package/src/scratch_blocks_utils.ts +4 -7
- package/src/scratch_comment_bubble.ts +76 -105
- package/src/scratch_comment_icon.ts +75 -124
- 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 +6 -13
- 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 +92 -141
- package/src/xml.ts +21 -35
- package/tsconfig.json +3 -7
- package/types/continuous-toolbox.d.ts +1 -1
- package/dist/main.mjs.LICENSE.txt +0 -163
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Visual Blocks Editor
|
|
4
3
|
*
|
|
5
4
|
* Copyright 2012 Google Inc.
|
|
@@ -17,46 +16,46 @@
|
|
|
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 Variable input field.
|
|
23
21
|
* @author fraser@google.com (Neil Fraser)
|
|
24
22
|
*/
|
|
25
|
-
import * as Blockly from
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import {
|
|
29
|
-
import
|
|
23
|
+
import * as Blockly from 'blockly/core'
|
|
24
|
+
import { ScratchMsgs } from '../../msg/scratch_msgs.js'
|
|
25
|
+
import * as Constants from '../constants'
|
|
26
|
+
import type { ScratchVariableModel } from '../scratch_variable_model'
|
|
27
|
+
import { createVariable, renameVariable } from '../variables'
|
|
30
28
|
|
|
31
29
|
export class ScratchFieldVariable extends Blockly.FieldVariable {
|
|
32
|
-
private originalStyle
|
|
30
|
+
private originalStyle!: string
|
|
33
31
|
|
|
34
32
|
constructor(
|
|
35
33
|
varName: string | null | typeof Blockly.Field.SKIP_SETUP,
|
|
36
34
|
validator?: Blockly.FieldVariableValidator,
|
|
37
35
|
variableTypes?: string[],
|
|
38
36
|
defaultType?: string,
|
|
39
|
-
config?: Blockly.FieldVariableConfig
|
|
37
|
+
config?: Blockly.FieldVariableConfig,
|
|
40
38
|
) {
|
|
41
|
-
super(varName, validator, variableTypes, defaultType, config)
|
|
42
|
-
|
|
39
|
+
super(varName, validator, variableTypes, defaultType, config)
|
|
40
|
+
// dropdownCreate returns MenuOption[] rather than Blockly.MenuGenerator's
|
|
41
|
+
// MenuOption[][] variant; the cast is needed to satisfy FieldVariable's
|
|
42
|
+
// menuGenerator_ type while the actual runtime shape is compatible.
|
|
43
|
+
this.menuGenerator_ = ScratchFieldVariable.dropdownCreate as unknown as Blockly.MenuGenerator
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
initModel() {
|
|
46
47
|
if (!this.getVariable()) {
|
|
47
|
-
const sourceBlock = this.getSourceBlock()
|
|
48
|
+
const sourceBlock = this.getSourceBlock()
|
|
48
49
|
if (sourceBlock) {
|
|
49
|
-
const broadcastVariable = this.initFlyoutBroadcast(
|
|
50
|
-
sourceBlock.workspace as Blockly.WorkspaceSvg
|
|
51
|
-
);
|
|
50
|
+
const broadcastVariable = this.initFlyoutBroadcast(sourceBlock.workspace as Blockly.WorkspaceSvg)
|
|
52
51
|
if (broadcastVariable) {
|
|
53
|
-
this.doValueUpdate_(broadcastVariable.getId())
|
|
54
|
-
return
|
|
52
|
+
this.doValueUpdate_(broadcastVariable.getId())
|
|
53
|
+
return
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
super.initModel()
|
|
58
|
+
super.initModel()
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
/**
|
|
@@ -66,118 +65,101 @@ export class ScratchFieldVariable extends Blockly.FieldVariable {
|
|
|
66
65
|
* selected option when the workspace is refreshed.
|
|
67
66
|
* Re-sort the broadcast messages by name, and set the field value to the id
|
|
68
67
|
* of the variable that comes first in sorted order.
|
|
69
|
-
*
|
|
70
68
|
* @param workspace The flyout workspace containing the broadcast block.
|
|
71
69
|
* @returns The variable of type 'broadcast_msg' that comes first in sorted
|
|
72
70
|
* order.
|
|
73
71
|
*/
|
|
74
|
-
initFlyoutBroadcast(
|
|
75
|
-
workspace
|
|
76
|
-
): Blockly.IVariableModel<Blockly.IVariableState> {
|
|
77
|
-
const broadcastVars = workspace.getVariablesOfType(
|
|
78
|
-
Constants.BROADCAST_MESSAGE_VARIABLE_TYPE
|
|
79
|
-
);
|
|
72
|
+
initFlyoutBroadcast(workspace: Blockly.WorkspaceSvg): Blockly.IVariableModel<Blockly.IVariableState> | undefined {
|
|
73
|
+
const broadcastVars = workspace.getVariablesOfType(Constants.BROADCAST_MESSAGE_VARIABLE_TYPE)
|
|
80
74
|
if (
|
|
81
75
|
workspace.isFlyout &&
|
|
82
76
|
this.getDefaultType() == Constants.BROADCAST_MESSAGE_VARIABLE_TYPE &&
|
|
83
77
|
broadcastVars.length != 0
|
|
84
78
|
) {
|
|
85
|
-
broadcastVars.sort(Blockly.Variables.compareByName)
|
|
86
|
-
return broadcastVars[0]
|
|
79
|
+
broadcastVars.sort(Blockly.Variables.compareByName)
|
|
80
|
+
return broadcastVars[0]
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
83
|
|
|
90
84
|
/**
|
|
91
85
|
* Return a sorted list of variable names for variable dropdown menus.
|
|
92
86
|
* Include a special option at the end for creating a new variable name.
|
|
93
|
-
*
|
|
94
87
|
* @returns Array of variable names.
|
|
95
88
|
*/
|
|
96
89
|
static dropdownCreate(this: ScratchFieldVariable): Blockly.MenuOption[] {
|
|
97
|
-
let options = super.dropdownCreate()
|
|
98
|
-
const type = this.getDefaultType()
|
|
90
|
+
let options = super.dropdownCreate()
|
|
91
|
+
const type = this.getDefaultType()
|
|
99
92
|
if (type === Constants.BROADCAST_MESSAGE_VARIABLE_TYPE) {
|
|
100
|
-
options.splice(-2, 2, [
|
|
101
|
-
ScratchMsgs.translate("NEW_BROADCAST_MESSAGE"),
|
|
102
|
-
Constants.NEW_BROADCAST_MESSAGE_ID,
|
|
103
|
-
]);
|
|
93
|
+
options.splice(-2, 2, [ScratchMsgs.translate('NEW_BROADCAST_MESSAGE'), Constants.NEW_BROADCAST_MESSAGE_ID])
|
|
104
94
|
} else if (type === Constants.LIST_VARIABLE_TYPE) {
|
|
105
|
-
options = options.map(
|
|
95
|
+
options = options.map(option => {
|
|
106
96
|
if (option[1] === Blockly.RENAME_VARIABLE_ID) {
|
|
107
|
-
return [ScratchMsgs.translate(
|
|
97
|
+
return [ScratchMsgs.translate('RENAME_LIST'), option[1]]
|
|
108
98
|
} else if (option[1] === Blockly.DELETE_VARIABLE_ID) {
|
|
109
|
-
return [
|
|
110
|
-
ScratchMsgs.translate("DELETE_LIST").replace("%1", this.getText()),
|
|
111
|
-
option[1],
|
|
112
|
-
];
|
|
99
|
+
return [ScratchMsgs.translate('DELETE_LIST').replace('%1', this.getText()), option[1]]
|
|
113
100
|
}
|
|
114
|
-
return option
|
|
115
|
-
})
|
|
101
|
+
return option
|
|
102
|
+
})
|
|
116
103
|
}
|
|
117
104
|
|
|
118
|
-
return options
|
|
105
|
+
return options
|
|
119
106
|
}
|
|
120
107
|
|
|
121
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Handle the selection of an item in the variable dropdown menu.
|
|
122
110
|
* Special case the 'Rename variable...', 'Delete variable...',
|
|
123
111
|
* and 'New message...' options.
|
|
124
112
|
* In the rename case, prompt the user for a new name.
|
|
125
|
-
*
|
|
126
113
|
* @param menu The Menu component clicked.
|
|
127
114
|
* @param menuItem The MenuItem selected within menu.
|
|
128
115
|
*/
|
|
129
116
|
onItemSelected_(menu: Blockly.Menu, menuItem: Blockly.MenuItem) {
|
|
130
|
-
const sourceBlock = this.getSourceBlock()
|
|
117
|
+
const sourceBlock = this.getSourceBlock()
|
|
131
118
|
if (sourceBlock && !sourceBlock.isDeadOrDying()) {
|
|
132
|
-
const selectedItem = menuItem.getValue()
|
|
119
|
+
const selectedItem = menuItem.getValue()
|
|
133
120
|
if (selectedItem === Constants.NEW_BROADCAST_MESSAGE_ID) {
|
|
134
121
|
createVariable(
|
|
135
122
|
sourceBlock.workspace as Blockly.WorkspaceSvg,
|
|
136
|
-
|
|
123
|
+
varId => {
|
|
137
124
|
if (varId) {
|
|
138
|
-
this.setValue(varId)
|
|
125
|
+
this.setValue(varId)
|
|
139
126
|
}
|
|
140
127
|
},
|
|
141
|
-
Constants.BROADCAST_MESSAGE_VARIABLE_TYPE
|
|
142
|
-
)
|
|
143
|
-
return
|
|
128
|
+
Constants.BROADCAST_MESSAGE_VARIABLE_TYPE,
|
|
129
|
+
)
|
|
130
|
+
return
|
|
144
131
|
} else if (selectedItem === Blockly.RENAME_VARIABLE_ID) {
|
|
145
|
-
renameVariable(
|
|
146
|
-
|
|
147
|
-
this.getVariable() as ScratchVariableModel
|
|
148
|
-
);
|
|
149
|
-
return;
|
|
132
|
+
renameVariable(sourceBlock.workspace as Blockly.WorkspaceSvg, this.getVariable() as ScratchVariableModel)
|
|
133
|
+
return
|
|
150
134
|
}
|
|
151
135
|
}
|
|
152
|
-
super.onItemSelected_(menu, menuItem)
|
|
136
|
+
super.onItemSelected_(menu, menuItem)
|
|
153
137
|
}
|
|
154
138
|
|
|
155
139
|
showEditor_(event: PointerEvent) {
|
|
156
|
-
super.showEditor_(event)
|
|
157
|
-
const sourceBlock = this.getSourceBlock()
|
|
158
|
-
const styleName = sourceBlock.getStyleName()
|
|
140
|
+
super.showEditor_(event)
|
|
141
|
+
const sourceBlock = this.getSourceBlock()!
|
|
142
|
+
const styleName = sourceBlock.getStyleName()
|
|
159
143
|
const style = (sourceBlock.workspace as Blockly.WorkspaceSvg)
|
|
160
144
|
.getRenderer()
|
|
161
145
|
.getConstants()
|
|
162
|
-
.getBlockStyle(styleName)
|
|
146
|
+
.getBlockStyle(styleName)
|
|
163
147
|
if (sourceBlock.isShadow()) {
|
|
164
|
-
this.originalStyle = styleName
|
|
165
|
-
sourceBlock.setStyle(`${this.originalStyle}_selected`)
|
|
148
|
+
this.originalStyle = styleName
|
|
149
|
+
sourceBlock.setStyle(`${this.originalStyle}_selected`)
|
|
166
150
|
} else if (this.borderRect_) {
|
|
167
151
|
this.borderRect_.setAttribute(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
: style.colourTertiary
|
|
172
|
-
);
|
|
152
|
+
'fill',
|
|
153
|
+
'colourQuaternary' in style ? `${style.colourQuaternary}` : style.colourTertiary,
|
|
154
|
+
)
|
|
173
155
|
}
|
|
174
156
|
}
|
|
175
157
|
|
|
176
158
|
dropdownDispose_() {
|
|
177
|
-
super.dropdownDispose_()
|
|
178
|
-
const sourceBlock = this.getSourceBlock()
|
|
159
|
+
super.dropdownDispose_()
|
|
160
|
+
const sourceBlock = this.getSourceBlock()!
|
|
179
161
|
if (sourceBlock.isShadow()) {
|
|
180
|
-
sourceBlock.setStyle(this.originalStyle)
|
|
162
|
+
sourceBlock.setStyle(this.originalStyle)
|
|
181
163
|
}
|
|
182
164
|
}
|
|
183
165
|
}
|
|
@@ -186,6 +168,6 @@ export class ScratchFieldVariable extends Blockly.FieldVariable {
|
|
|
186
168
|
* Register the field and any dependencies.
|
|
187
169
|
*/
|
|
188
170
|
export function registerScratchFieldVariable() {
|
|
189
|
-
Blockly.fieldRegistry.unregister(
|
|
190
|
-
Blockly.fieldRegistry.register(
|
|
171
|
+
Blockly.fieldRegistry.unregister('field_variable')
|
|
172
|
+
Blockly.fieldRegistry.register('field_variable', ScratchFieldVariable)
|
|
191
173
|
}
|
|
@@ -1,57 +1,52 @@
|
|
|
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 { CheckboxBubble } from "./checkbox_bubble";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import { CheckboxBubble } from './checkbox_bubble'
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Invisible icon that exists solely to host the corresponding checkbox bubble.
|
|
12
10
|
*/
|
|
13
|
-
export class FlyoutCheckboxIcon
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
private checkboxBubble: CheckboxBubble;
|
|
18
|
-
private type = new Blockly.icons.IconType("checkbox");
|
|
11
|
+
export class FlyoutCheckboxIcon extends Blockly.icons.Icon implements Blockly.IHasBubble {
|
|
12
|
+
private checkboxBubble!: CheckboxBubble
|
|
13
|
+
private type = new Blockly.icons.IconType('checkbox')
|
|
19
14
|
|
|
20
15
|
constructor(protected override sourceBlock: Blockly.BlockSvg) {
|
|
21
|
-
super(sourceBlock)
|
|
16
|
+
super(sourceBlock)
|
|
22
17
|
if (this.sourceBlock.workspace.isFlyout) {
|
|
23
|
-
this.checkboxBubble = new CheckboxBubble(this.sourceBlock)
|
|
18
|
+
this.checkboxBubble = new CheckboxBubble(this.sourceBlock)
|
|
24
19
|
}
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
getType(): Blockly.icons.IconType<FlyoutCheckboxIcon> {
|
|
28
|
-
return this.type
|
|
23
|
+
return this.type
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
getSize(): Blockly.utils.Size {
|
|
32
27
|
// Awful hack to cancel out the default padding added to icons.
|
|
33
|
-
return new Blockly.utils.Size(-8, 0)
|
|
28
|
+
return new Blockly.utils.Size(-8, 0)
|
|
34
29
|
}
|
|
35
30
|
|
|
36
31
|
isClickableInFlyout(): boolean {
|
|
37
|
-
return false
|
|
32
|
+
return false
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
bubbleIsVisible(): boolean {
|
|
41
|
-
return this.sourceBlock.workspace.isFlyout
|
|
36
|
+
return this.sourceBlock.workspace.isFlyout
|
|
42
37
|
}
|
|
43
38
|
|
|
44
39
|
onLocationChange(blockOrigin: Blockly.utils.Coordinate) {
|
|
45
|
-
this.checkboxBubble?.updateLocation()
|
|
40
|
+
this.checkboxBubble?.updateLocation()
|
|
46
41
|
}
|
|
47
42
|
|
|
48
43
|
setChecked(checked: boolean) {
|
|
49
|
-
this.checkboxBubble?.setChecked(checked)
|
|
44
|
+
this.checkboxBubble?.setChecked(checked)
|
|
50
45
|
}
|
|
51
46
|
|
|
52
47
|
dispose() {
|
|
53
|
-
this.checkboxBubble?.dispose()
|
|
54
|
-
super.dispose()
|
|
48
|
+
this.checkboxBubble?.dispose()
|
|
49
|
+
super.dispose()
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
// These methods are required by the interfaces, but intentionally have no
|
|
@@ -62,17 +57,12 @@ export class FlyoutCheckboxIcon
|
|
|
62
57
|
initView(pointerDownListener: (e: PointerEvent) => void) {}
|
|
63
58
|
|
|
64
59
|
canBeFocused() {
|
|
65
|
-
return false
|
|
60
|
+
return false
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
getBubble() {
|
|
69
|
-
return this.checkboxBubble
|
|
64
|
+
return this.checkboxBubble
|
|
70
65
|
}
|
|
71
66
|
}
|
|
72
67
|
|
|
73
|
-
Blockly.registry.register(
|
|
74
|
-
Blockly.registry.Type.ICON,
|
|
75
|
-
"checkbox",
|
|
76
|
-
FlyoutCheckboxIcon,
|
|
77
|
-
true
|
|
78
|
-
);
|
|
68
|
+
Blockly.registry.register(Blockly.registry.Type.ICON, 'checkbox', FlyoutCheckboxIcon, true)
|
package/src/glows.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
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 { Colours } from "./colours";
|
|
5
|
+
import * as Blockly from 'blockly/core'
|
|
6
|
+
import { Colours } from './colours'
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Glow/unglow a stack in the workspace.
|
|
12
|
-
*
|
|
13
10
|
* @param id ID of block which starts the stack.
|
|
14
11
|
* @param isGlowingStack Whether to glow the stack.
|
|
15
12
|
*/
|
|
@@ -17,17 +14,17 @@ export function glowStack(id: string, isGlowingStack: boolean) {
|
|
|
17
14
|
const block = (Blockly.getMainWorkspace().getBlockById(id) ||
|
|
18
15
|
(Blockly.getMainWorkspace() as Blockly.WorkspaceSvg)
|
|
19
16
|
.getFlyout()
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
?.getWorkspace()
|
|
18
|
+
?.getBlockById(id)) as Blockly.BlockSvg
|
|
22
19
|
if (!block) {
|
|
23
|
-
throw
|
|
20
|
+
throw new Error('Tried to glow block that does not exist.')
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
const svg = block.getSvgRoot()
|
|
27
|
-
if (isGlowingStack && !svg.hasAttribute(
|
|
28
|
-
svg.setAttribute(
|
|
29
|
-
} else if (!isGlowingStack && svg.hasAttribute(
|
|
30
|
-
svg.removeAttribute(
|
|
23
|
+
const svg = block.getSvgRoot()
|
|
24
|
+
if (isGlowingStack && !svg.hasAttribute('filter')) {
|
|
25
|
+
svg.setAttribute('filter', 'url(#blocklyStackGlowFilter)')
|
|
26
|
+
} else if (!isGlowingStack && svg.hasAttribute('filter')) {
|
|
27
|
+
svg.removeAttribute('filter')
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
|
|
@@ -36,74 +33,70 @@ export function glowStack(id: string, isGlowingStack: boolean) {
|
|
|
36
33
|
* @param workspace The workspace whose DOM the filter will be inserted in.
|
|
37
34
|
*/
|
|
38
35
|
export function buildGlowFilter(workspace: Blockly.WorkspaceSvg) {
|
|
39
|
-
const svg = workspace.getParentSvg()
|
|
40
|
-
const defs = Blockly.utils.dom.createSvgElement(
|
|
41
|
-
Blockly.utils.Svg.DEFS,
|
|
42
|
-
{},
|
|
43
|
-
svg
|
|
44
|
-
);
|
|
36
|
+
const svg = workspace.getParentSvg()
|
|
37
|
+
const defs = Blockly.utils.dom.createSvgElement(Blockly.utils.Svg.DEFS, {}, svg)
|
|
45
38
|
// Using a dilate distorts the block shape.
|
|
46
39
|
// Instead use a gaussian blur, and then set all alpha to 1 with a transfer.
|
|
47
40
|
const stackGlowFilter = Blockly.utils.dom.createSvgElement(
|
|
48
|
-
|
|
41
|
+
'filter',
|
|
49
42
|
{
|
|
50
|
-
id:
|
|
51
|
-
height:
|
|
52
|
-
width:
|
|
53
|
-
y:
|
|
54
|
-
x:
|
|
43
|
+
id: 'blocklyStackGlowFilter',
|
|
44
|
+
height: '160%',
|
|
45
|
+
width: '180%',
|
|
46
|
+
y: '-30%',
|
|
47
|
+
x: '-40%',
|
|
55
48
|
},
|
|
56
|
-
defs
|
|
57
|
-
)
|
|
49
|
+
defs,
|
|
50
|
+
)
|
|
58
51
|
Blockly.utils.dom.createSvgElement(
|
|
59
|
-
|
|
52
|
+
'feGaussianBlur',
|
|
60
53
|
{
|
|
61
|
-
in:
|
|
54
|
+
in: 'SourceGraphic',
|
|
62
55
|
stdDeviation: Colours.stackGlowSize,
|
|
63
56
|
},
|
|
64
|
-
stackGlowFilter
|
|
65
|
-
)
|
|
57
|
+
stackGlowFilter,
|
|
58
|
+
)
|
|
66
59
|
// Set all gaussian blur pixels to 1 opacity before applying flood
|
|
67
60
|
const componentTransfer = Blockly.utils.dom.createSvgElement(
|
|
68
|
-
|
|
69
|
-
{ result:
|
|
70
|
-
stackGlowFilter
|
|
71
|
-
)
|
|
61
|
+
'feComponentTransfer',
|
|
62
|
+
{ result: 'outBlur' },
|
|
63
|
+
stackGlowFilter,
|
|
64
|
+
)
|
|
72
65
|
Blockly.utils.dom.createSvgElement(
|
|
73
|
-
|
|
66
|
+
'feFuncA',
|
|
74
67
|
{
|
|
75
|
-
type:
|
|
76
|
-
tableValues:
|
|
68
|
+
type: 'table',
|
|
69
|
+
tableValues: '0' + ' 1'.repeat(16),
|
|
77
70
|
},
|
|
78
|
-
componentTransfer
|
|
79
|
-
)
|
|
71
|
+
componentTransfer,
|
|
72
|
+
)
|
|
80
73
|
// Color the highlight
|
|
81
74
|
Blockly.utils.dom.createSvgElement(
|
|
82
|
-
|
|
75
|
+
'feFlood',
|
|
83
76
|
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
result:
|
|
77
|
+
'flood-color': Colours.stackGlow,
|
|
78
|
+
'flood-opacity': Colours.stackGlowOpacity,
|
|
79
|
+
result: 'outColor',
|
|
87
80
|
},
|
|
88
|
-
stackGlowFilter
|
|
89
|
-
)
|
|
81
|
+
stackGlowFilter,
|
|
82
|
+
)
|
|
90
83
|
Blockly.utils.dom.createSvgElement(
|
|
91
|
-
|
|
84
|
+
'feComposite',
|
|
92
85
|
{
|
|
93
|
-
in:
|
|
94
|
-
in2:
|
|
95
|
-
operator:
|
|
96
|
-
result:
|
|
86
|
+
in: 'outColor',
|
|
87
|
+
in2: 'outBlur',
|
|
88
|
+
operator: 'in',
|
|
89
|
+
result: 'outGlow',
|
|
97
90
|
},
|
|
98
|
-
stackGlowFilter
|
|
99
|
-
)
|
|
91
|
+
stackGlowFilter,
|
|
92
|
+
)
|
|
100
93
|
Blockly.utils.dom.createSvgElement(
|
|
101
|
-
|
|
94
|
+
'feComposite',
|
|
102
95
|
{
|
|
103
|
-
in:
|
|
104
|
-
in2:
|
|
105
|
-
operator:
|
|
96
|
+
in: 'SourceGraphic',
|
|
97
|
+
in2: 'outGlow',
|
|
98
|
+
operator: 'over',
|
|
106
99
|
},
|
|
107
|
-
stackGlowFilter
|
|
108
|
-
)
|
|
100
|
+
stackGlowFilter,
|
|
101
|
+
)
|
|
109
102
|
}
|