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,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Visual Blocks Editor
|
|
4
3
|
*
|
|
5
4
|
* Copyright 2012 Google Inc.
|
|
@@ -17,49 +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!: string
|
|
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)
|
|
39
|
+
super(varName, validator, variableTypes, defaultType, config)
|
|
42
40
|
// dropdownCreate returns MenuOption[] rather than Blockly.MenuGenerator's
|
|
43
41
|
// MenuOption[][] variant; the cast is needed to satisfy FieldVariable's
|
|
44
42
|
// menuGenerator_ type while the actual runtime shape is compatible.
|
|
45
|
-
this.menuGenerator_ = ScratchFieldVariable.dropdownCreate as unknown as Blockly.MenuGenerator
|
|
43
|
+
this.menuGenerator_ = ScratchFieldVariable.dropdownCreate as unknown as Blockly.MenuGenerator
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
initModel() {
|
|
49
47
|
if (!this.getVariable()) {
|
|
50
|
-
const sourceBlock = this.getSourceBlock()
|
|
48
|
+
const sourceBlock = this.getSourceBlock()
|
|
51
49
|
if (sourceBlock) {
|
|
52
|
-
const broadcastVariable = this.initFlyoutBroadcast(
|
|
53
|
-
sourceBlock.workspace as Blockly.WorkspaceSvg
|
|
54
|
-
);
|
|
50
|
+
const broadcastVariable = this.initFlyoutBroadcast(sourceBlock.workspace as Blockly.WorkspaceSvg)
|
|
55
51
|
if (broadcastVariable) {
|
|
56
|
-
this.doValueUpdate_(broadcastVariable.getId())
|
|
57
|
-
return
|
|
52
|
+
this.doValueUpdate_(broadcastVariable.getId())
|
|
53
|
+
return
|
|
58
54
|
}
|
|
59
55
|
}
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
super.initModel()
|
|
58
|
+
super.initModel()
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
/**
|
|
@@ -69,118 +65,101 @@ export class ScratchFieldVariable extends Blockly.FieldVariable {
|
|
|
69
65
|
* selected option when the workspace is refreshed.
|
|
70
66
|
* Re-sort the broadcast messages by name, and set the field value to the id
|
|
71
67
|
* of the variable that comes first in sorted order.
|
|
72
|
-
*
|
|
73
68
|
* @param workspace The flyout workspace containing the broadcast block.
|
|
74
69
|
* @returns The variable of type 'broadcast_msg' that comes first in sorted
|
|
75
70
|
* order.
|
|
76
71
|
*/
|
|
77
|
-
initFlyoutBroadcast(
|
|
78
|
-
workspace
|
|
79
|
-
): Blockly.IVariableModel<Blockly.IVariableState> | undefined {
|
|
80
|
-
const broadcastVars = workspace.getVariablesOfType(
|
|
81
|
-
Constants.BROADCAST_MESSAGE_VARIABLE_TYPE
|
|
82
|
-
);
|
|
72
|
+
initFlyoutBroadcast(workspace: Blockly.WorkspaceSvg): Blockly.IVariableModel<Blockly.IVariableState> | undefined {
|
|
73
|
+
const broadcastVars = workspace.getVariablesOfType(Constants.BROADCAST_MESSAGE_VARIABLE_TYPE)
|
|
83
74
|
if (
|
|
84
75
|
workspace.isFlyout &&
|
|
85
76
|
this.getDefaultType() == Constants.BROADCAST_MESSAGE_VARIABLE_TYPE &&
|
|
86
77
|
broadcastVars.length != 0
|
|
87
78
|
) {
|
|
88
|
-
broadcastVars.sort(Blockly.Variables.compareByName)
|
|
89
|
-
return broadcastVars[0]
|
|
79
|
+
broadcastVars.sort(Blockly.Variables.compareByName)
|
|
80
|
+
return broadcastVars[0]
|
|
90
81
|
}
|
|
91
82
|
}
|
|
92
83
|
|
|
93
84
|
/**
|
|
94
85
|
* Return a sorted list of variable names for variable dropdown menus.
|
|
95
86
|
* Include a special option at the end for creating a new variable name.
|
|
96
|
-
*
|
|
97
87
|
* @returns Array of variable names.
|
|
98
88
|
*/
|
|
99
89
|
static dropdownCreate(this: ScratchFieldVariable): Blockly.MenuOption[] {
|
|
100
|
-
let options = super.dropdownCreate()
|
|
101
|
-
const type = this.getDefaultType()
|
|
90
|
+
let options = super.dropdownCreate()
|
|
91
|
+
const type = this.getDefaultType()
|
|
102
92
|
if (type === Constants.BROADCAST_MESSAGE_VARIABLE_TYPE) {
|
|
103
|
-
options.splice(-2, 2, [
|
|
104
|
-
ScratchMsgs.translate("NEW_BROADCAST_MESSAGE"),
|
|
105
|
-
Constants.NEW_BROADCAST_MESSAGE_ID,
|
|
106
|
-
]);
|
|
93
|
+
options.splice(-2, 2, [ScratchMsgs.translate('NEW_BROADCAST_MESSAGE'), Constants.NEW_BROADCAST_MESSAGE_ID])
|
|
107
94
|
} else if (type === Constants.LIST_VARIABLE_TYPE) {
|
|
108
95
|
options = options.map((option) => {
|
|
109
96
|
if (option[1] === Blockly.RENAME_VARIABLE_ID) {
|
|
110
|
-
return [ScratchMsgs.translate(
|
|
97
|
+
return [ScratchMsgs.translate('RENAME_LIST'), option[1]]
|
|
111
98
|
} else if (option[1] === Blockly.DELETE_VARIABLE_ID) {
|
|
112
|
-
return [
|
|
113
|
-
ScratchMsgs.translate("DELETE_LIST").replace("%1", this.getText()),
|
|
114
|
-
option[1],
|
|
115
|
-
];
|
|
99
|
+
return [ScratchMsgs.translate('DELETE_LIST').replace('%1', this.getText()), option[1]]
|
|
116
100
|
}
|
|
117
|
-
return option
|
|
118
|
-
})
|
|
101
|
+
return option
|
|
102
|
+
})
|
|
119
103
|
}
|
|
120
104
|
|
|
121
|
-
return options
|
|
105
|
+
return options
|
|
122
106
|
}
|
|
123
107
|
|
|
124
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Handle the selection of an item in the variable dropdown menu.
|
|
125
110
|
* Special case the 'Rename variable...', 'Delete variable...',
|
|
126
111
|
* and 'New message...' options.
|
|
127
112
|
* In the rename case, prompt the user for a new name.
|
|
128
|
-
*
|
|
129
113
|
* @param menu The Menu component clicked.
|
|
130
114
|
* @param menuItem The MenuItem selected within menu.
|
|
131
115
|
*/
|
|
132
116
|
onItemSelected_(menu: Blockly.Menu, menuItem: Blockly.MenuItem) {
|
|
133
|
-
const sourceBlock = this.getSourceBlock()
|
|
117
|
+
const sourceBlock = this.getSourceBlock()
|
|
134
118
|
if (sourceBlock && !sourceBlock.isDeadOrDying()) {
|
|
135
|
-
const selectedItem = menuItem.getValue()
|
|
119
|
+
const selectedItem = menuItem.getValue()
|
|
136
120
|
if (selectedItem === Constants.NEW_BROADCAST_MESSAGE_ID) {
|
|
137
121
|
createVariable(
|
|
138
122
|
sourceBlock.workspace as Blockly.WorkspaceSvg,
|
|
139
123
|
(varId) => {
|
|
140
124
|
if (varId) {
|
|
141
|
-
this.setValue(varId)
|
|
125
|
+
this.setValue(varId)
|
|
142
126
|
}
|
|
143
127
|
},
|
|
144
|
-
Constants.BROADCAST_MESSAGE_VARIABLE_TYPE
|
|
145
|
-
)
|
|
146
|
-
return
|
|
128
|
+
Constants.BROADCAST_MESSAGE_VARIABLE_TYPE,
|
|
129
|
+
)
|
|
130
|
+
return
|
|
147
131
|
} else if (selectedItem === Blockly.RENAME_VARIABLE_ID) {
|
|
148
|
-
renameVariable(
|
|
149
|
-
|
|
150
|
-
this.getVariable() as ScratchVariableModel
|
|
151
|
-
);
|
|
152
|
-
return;
|
|
132
|
+
renameVariable(sourceBlock.workspace as Blockly.WorkspaceSvg, this.getVariable() as ScratchVariableModel)
|
|
133
|
+
return
|
|
153
134
|
}
|
|
154
135
|
}
|
|
155
|
-
super.onItemSelected_(menu, menuItem)
|
|
136
|
+
super.onItemSelected_(menu, menuItem)
|
|
156
137
|
}
|
|
157
138
|
|
|
158
139
|
showEditor_(event: PointerEvent) {
|
|
159
|
-
super.showEditor_(event)
|
|
160
|
-
const sourceBlock = this.getSourceBlock()
|
|
161
|
-
const styleName = sourceBlock.getStyleName()
|
|
140
|
+
super.showEditor_(event)
|
|
141
|
+
const sourceBlock = this.getSourceBlock()!
|
|
142
|
+
const styleName = sourceBlock.getStyleName()
|
|
162
143
|
const style = (sourceBlock.workspace as Blockly.WorkspaceSvg)
|
|
163
144
|
.getRenderer()
|
|
164
145
|
.getConstants()
|
|
165
|
-
.getBlockStyle(styleName)
|
|
146
|
+
.getBlockStyle(styleName)
|
|
166
147
|
if (sourceBlock.isShadow()) {
|
|
167
|
-
this.originalStyle = styleName
|
|
168
|
-
sourceBlock.setStyle(`${this.originalStyle}_selected`)
|
|
148
|
+
this.originalStyle = styleName
|
|
149
|
+
sourceBlock.setStyle(`${this.originalStyle}_selected`)
|
|
169
150
|
} else if (this.borderRect_) {
|
|
170
151
|
this.borderRect_.setAttribute(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
: style.colourTertiary
|
|
175
|
-
);
|
|
152
|
+
'fill',
|
|
153
|
+
'colourQuaternary' in style ? `${style.colourQuaternary}` : style.colourTertiary,
|
|
154
|
+
)
|
|
176
155
|
}
|
|
177
156
|
}
|
|
178
157
|
|
|
179
158
|
dropdownDispose_() {
|
|
180
|
-
super.dropdownDispose_()
|
|
181
|
-
const sourceBlock = this.getSourceBlock()
|
|
159
|
+
super.dropdownDispose_()
|
|
160
|
+
const sourceBlock = this.getSourceBlock()!
|
|
182
161
|
if (sourceBlock.isShadow()) {
|
|
183
|
-
sourceBlock.setStyle(this.originalStyle)
|
|
162
|
+
sourceBlock.setStyle(this.originalStyle)
|
|
184
163
|
}
|
|
185
164
|
}
|
|
186
165
|
}
|
|
@@ -189,6 +168,6 @@ export class ScratchFieldVariable extends Blockly.FieldVariable {
|
|
|
189
168
|
* Register the field and any dependencies.
|
|
190
169
|
*/
|
|
191
170
|
export function registerScratchFieldVariable() {
|
|
192
|
-
Blockly.fieldRegistry.unregister(
|
|
193
|
-
Blockly.fieldRegistry.register(
|
|
171
|
+
Blockly.fieldRegistry.unregister('field_variable')
|
|
172
|
+
Blockly.fieldRegistry.register('field_variable', ScratchFieldVariable)
|
|
194
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
|
*/
|
|
@@ -18,16 +15,16 @@ export function glowStack(id: string, isGlowingStack: boolean) {
|
|
|
18
15
|
(Blockly.getMainWorkspace() as Blockly.WorkspaceSvg)
|
|
19
16
|
.getFlyout()
|
|
20
17
|
?.getWorkspace()
|
|
21
|
-
?.getBlockById(id)) as Blockly.BlockSvg
|
|
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
|
}
|