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 2013 Google Inc.
|
|
@@ -17,62 +16,59 @@
|
|
|
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 Angle input field.
|
|
23
21
|
* @author fraser@google.com (Neil Fraser)
|
|
24
22
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
import * as Blockly from "blockly/core";
|
|
23
|
+
import * as Blockly from 'blockly/core'
|
|
28
24
|
|
|
29
25
|
class ScratchFieldAngle extends Blockly.FieldNumber {
|
|
30
26
|
/**
|
|
31
27
|
* The highlighted portion of the angle picker circle, between 0º and the
|
|
32
28
|
* selected angle.
|
|
33
29
|
*/
|
|
34
|
-
private gauge?: SVGPathElement
|
|
30
|
+
private gauge?: SVGPathElement
|
|
35
31
|
|
|
36
32
|
/**
|
|
37
33
|
* The line to the angle picker handle.
|
|
38
34
|
*/
|
|
39
|
-
private line?: SVGLineElement
|
|
35
|
+
private line?: SVGLineElement
|
|
40
36
|
|
|
41
37
|
/**
|
|
42
38
|
* The grabbable handle used to choose an angle.
|
|
43
39
|
*/
|
|
44
|
-
private handle?: SVGGElement
|
|
40
|
+
private handle?: SVGGElement
|
|
45
41
|
|
|
46
42
|
/**
|
|
47
43
|
* The arrow graphic shown on the grab handle.
|
|
48
44
|
*/
|
|
49
|
-
private arrow?: SVGImageElement
|
|
45
|
+
private arrow?: SVGImageElement
|
|
50
46
|
|
|
51
47
|
/**
|
|
52
48
|
* Opaque identifier used to unbind event listener in dispose().
|
|
53
49
|
*/
|
|
54
|
-
private mouseDownWrapper_!: Blockly.browserEvents.Data
|
|
50
|
+
private mouseDownWrapper_!: Blockly.browserEvents.Data
|
|
55
51
|
|
|
56
52
|
/**
|
|
57
53
|
* Opaque identifier used to unbind event listener in dispose().
|
|
58
54
|
*/
|
|
59
|
-
private mouseMoveWrapper!: Blockly.browserEvents.Data
|
|
55
|
+
private mouseMoveWrapper!: Blockly.browserEvents.Data
|
|
60
56
|
|
|
61
57
|
/**
|
|
62
58
|
* Opaque identifier used to unbind event listener in dispose().
|
|
63
59
|
*/
|
|
64
|
-
private mouseUpWrapper!: Blockly.browserEvents.Data
|
|
60
|
+
private mouseUpWrapper!: Blockly.browserEvents.Data
|
|
65
61
|
|
|
66
62
|
/**
|
|
67
63
|
* Round angles to the nearest 15 degrees when using mouse.
|
|
68
64
|
* Set to 0 to disable rounding.
|
|
69
65
|
*/
|
|
70
|
-
ROUND = 15
|
|
66
|
+
ROUND = 15
|
|
71
67
|
|
|
72
68
|
/**
|
|
73
69
|
* Half the width of protractor image.
|
|
74
70
|
*/
|
|
75
|
-
HALF = 120 / 2
|
|
71
|
+
HALF = 120 / 2
|
|
76
72
|
|
|
77
73
|
/* The following two settings work together to set the behaviour of the angle
|
|
78
74
|
* picker. While many combinations are possible, two modes are typical:
|
|
@@ -89,245 +85,214 @@ class ScratchFieldAngle extends Blockly.FieldNumber {
|
|
|
89
85
|
/**
|
|
90
86
|
* Angle increases clockwise (true) or counterclockwise (false).
|
|
91
87
|
*/
|
|
92
|
-
CLOCKWISE = true
|
|
88
|
+
CLOCKWISE = true
|
|
93
89
|
|
|
94
90
|
/**
|
|
95
91
|
* Offset the location of 0 degrees (and all angles) by a constant.
|
|
96
92
|
* Usually either 0 (0 = right) or 90 (0 = up).
|
|
97
93
|
*/
|
|
98
|
-
OFFSET = 90
|
|
94
|
+
OFFSET = 90
|
|
99
95
|
|
|
100
96
|
/**
|
|
101
97
|
* Maximum allowed angle before wrapping.
|
|
102
98
|
* Usually either 360 (for 0 to 359.9) or 180 (for -179.9 to 180).
|
|
103
99
|
*/
|
|
104
|
-
WRAP = 180
|
|
100
|
+
WRAP = 180
|
|
105
101
|
|
|
106
102
|
/**
|
|
107
103
|
* Radius of drag handle
|
|
108
104
|
*/
|
|
109
|
-
HANDLE_RADIUS = 10
|
|
105
|
+
HANDLE_RADIUS = 10
|
|
110
106
|
|
|
111
107
|
/**
|
|
112
108
|
* Width of drag handle arrow
|
|
113
109
|
*/
|
|
114
|
-
ARROW_WIDTH = this.HANDLE_RADIUS
|
|
110
|
+
ARROW_WIDTH = this.HANDLE_RADIUS
|
|
115
111
|
|
|
116
112
|
/**
|
|
117
113
|
* Half the stroke-width used for the "glow" around the drag handle, rounded
|
|
118
114
|
* up to nearest whole pixel.
|
|
119
115
|
*/
|
|
120
116
|
|
|
121
|
-
HANDLE_GLOW_WIDTH = 3
|
|
117
|
+
HANDLE_GLOW_WIDTH = 3
|
|
122
118
|
|
|
123
119
|
/**
|
|
124
120
|
* Radius of protractor circle. Slightly smaller than protractor size since
|
|
125
121
|
* otherwise SVG crops off half the border at the edges.
|
|
126
122
|
*/
|
|
127
|
-
RADIUS = this.HALF - this.HANDLE_RADIUS - this.HANDLE_GLOW_WIDTH
|
|
123
|
+
RADIUS = this.HALF - this.HANDLE_RADIUS - this.HANDLE_GLOW_WIDTH
|
|
128
124
|
|
|
129
125
|
/**
|
|
130
126
|
* Radius of central dot circle.
|
|
131
127
|
*/
|
|
132
|
-
CENTER_RADIUS = 2
|
|
128
|
+
CENTER_RADIUS = 2
|
|
133
129
|
|
|
134
130
|
/**
|
|
135
131
|
* Path to the arrow svg icon.
|
|
136
132
|
*/
|
|
137
|
-
ARROW_SVG_PATH =
|
|
133
|
+
ARROW_SVG_PATH = 'icons/arrow.svg'
|
|
138
134
|
|
|
139
135
|
/**
|
|
140
136
|
* Clean up this FieldAngle, as well as the inherited FieldNumber.
|
|
141
137
|
*/
|
|
142
138
|
dispose() {
|
|
143
|
-
super.dispose()
|
|
144
|
-
this.gauge = undefined
|
|
139
|
+
super.dispose()
|
|
140
|
+
this.gauge = undefined
|
|
145
141
|
if (this.mouseDownWrapper_) {
|
|
146
|
-
Blockly.browserEvents.unbind(this.mouseDownWrapper_)
|
|
142
|
+
Blockly.browserEvents.unbind(this.mouseDownWrapper_)
|
|
147
143
|
}
|
|
148
144
|
if (this.mouseUpWrapper) {
|
|
149
|
-
Blockly.browserEvents.unbind(this.mouseUpWrapper)
|
|
145
|
+
Blockly.browserEvents.unbind(this.mouseUpWrapper)
|
|
150
146
|
}
|
|
151
147
|
if (this.mouseMoveWrapper) {
|
|
152
|
-
Blockly.browserEvents.unbind(this.mouseMoveWrapper)
|
|
148
|
+
Blockly.browserEvents.unbind(this.mouseMoveWrapper)
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
151
|
|
|
156
152
|
/**
|
|
157
153
|
* Show the inline free-text editor on top of the text.
|
|
154
|
+
* @param event The triggering pointer event.
|
|
158
155
|
*/
|
|
159
156
|
showEditor_(event: PointerEvent) {
|
|
160
157
|
// Mobile browsers have issues with in-line textareas (focus & keyboards).
|
|
161
158
|
// Also, don't let the parent take ephemeral focus since the drop-down div
|
|
162
159
|
// below will handle it, instead.
|
|
163
|
-
const noFocus =
|
|
164
|
-
|
|
165
|
-
Blockly.utils.userAgent.ANDROID ||
|
|
166
|
-
Blockly.utils.userAgent.IPAD;
|
|
167
|
-
super.showEditor_(event, noFocus, false);
|
|
160
|
+
const noFocus = Blockly.utils.userAgent.MOBILE || Blockly.utils.userAgent.ANDROID || Blockly.utils.userAgent.IPAD
|
|
161
|
+
super.showEditor_(event, noFocus, false)
|
|
168
162
|
|
|
169
163
|
// If there is an existing drop-down someone else owns, hide it immediately and clear it.
|
|
170
|
-
Blockly.DropDownDiv.hideWithoutAnimation()
|
|
171
|
-
Blockly.DropDownDiv.clearContent()
|
|
172
|
-
const div = Blockly.DropDownDiv.getContentDiv()
|
|
164
|
+
Blockly.DropDownDiv.hideWithoutAnimation()
|
|
165
|
+
Blockly.DropDownDiv.clearContent()
|
|
166
|
+
const div = Blockly.DropDownDiv.getContentDiv()
|
|
173
167
|
// Build the SVG DOM.
|
|
174
168
|
const svg = Blockly.utils.dom.createSvgElement(
|
|
175
|
-
|
|
169
|
+
'svg',
|
|
176
170
|
{
|
|
177
|
-
xmlns:
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
version:
|
|
181
|
-
height: this.HALF * 2 +
|
|
182
|
-
width: this.HALF * 2 +
|
|
171
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
172
|
+
'xmlns:html': 'http://www.w3.org/1999/xhtml',
|
|
173
|
+
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
|
174
|
+
version: '1.1',
|
|
175
|
+
height: this.HALF * 2 + 'px',
|
|
176
|
+
width: this.HALF * 2 + 'px',
|
|
183
177
|
},
|
|
184
|
-
div
|
|
185
|
-
)
|
|
178
|
+
div,
|
|
179
|
+
)
|
|
186
180
|
Blockly.utils.dom.createSvgElement(
|
|
187
|
-
|
|
181
|
+
'circle',
|
|
188
182
|
{
|
|
189
183
|
cx: this.HALF,
|
|
190
184
|
cy: this.HALF,
|
|
191
185
|
r: this.RADIUS,
|
|
192
|
-
fill: (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
stroke: (
|
|
196
|
-
this.getSourceBlock()!.getParent() as Blockly.BlockSvg
|
|
197
|
-
).getColourTertiary(),
|
|
198
|
-
class: "blocklyAngleCircle",
|
|
186
|
+
fill: (this.getSourceBlock()!.getParent() as Blockly.BlockSvg).getColourSecondary(),
|
|
187
|
+
stroke: (this.getSourceBlock()!.getParent() as Blockly.BlockSvg).getColourTertiary(),
|
|
188
|
+
class: 'blocklyAngleCircle',
|
|
199
189
|
},
|
|
200
|
-
svg
|
|
201
|
-
)
|
|
202
|
-
this.gauge = Blockly.utils.dom.createSvgElement(
|
|
203
|
-
"path",
|
|
204
|
-
{ class: "blocklyAngleGauge" },
|
|
205
|
-
svg
|
|
206
|
-
);
|
|
190
|
+
svg,
|
|
191
|
+
)
|
|
192
|
+
this.gauge = Blockly.utils.dom.createSvgElement('path', { class: 'blocklyAngleGauge' }, svg)
|
|
207
193
|
// The moving line, x2 and y2 are set in updateGraph
|
|
208
194
|
this.line = Blockly.utils.dom.createSvgElement(
|
|
209
|
-
|
|
195
|
+
'line',
|
|
210
196
|
{
|
|
211
197
|
x1: this.HALF,
|
|
212
198
|
y1: this.HALF,
|
|
213
|
-
class:
|
|
199
|
+
class: 'blocklyAngleLine',
|
|
214
200
|
},
|
|
215
|
-
svg
|
|
216
|
-
)
|
|
201
|
+
svg,
|
|
202
|
+
)
|
|
217
203
|
// The fixed vertical line at the offset
|
|
218
|
-
const offsetRadians = (Math.PI * this.OFFSET) / 180
|
|
204
|
+
const offsetRadians = (Math.PI * this.OFFSET) / 180
|
|
219
205
|
Blockly.utils.dom.createSvgElement(
|
|
220
|
-
|
|
206
|
+
'line',
|
|
221
207
|
{
|
|
222
208
|
x1: this.HALF,
|
|
223
209
|
y1: this.HALF,
|
|
224
210
|
x2: this.HALF + this.RADIUS * Math.cos(offsetRadians),
|
|
225
211
|
y2: this.HALF - this.RADIUS * Math.sin(offsetRadians),
|
|
226
|
-
class:
|
|
212
|
+
class: 'blocklyAngleLine',
|
|
227
213
|
},
|
|
228
|
-
svg
|
|
229
|
-
)
|
|
214
|
+
svg,
|
|
215
|
+
)
|
|
230
216
|
// Draw markers around the edge.
|
|
231
217
|
for (let angle = 0; angle < 360; angle += 15) {
|
|
232
218
|
Blockly.utils.dom.createSvgElement(
|
|
233
|
-
|
|
219
|
+
'line',
|
|
234
220
|
{
|
|
235
221
|
x1: this.HALF + this.RADIUS - 13,
|
|
236
222
|
y1: this.HALF,
|
|
237
223
|
x2: this.HALF + this.RADIUS - 7,
|
|
238
224
|
y2: this.HALF,
|
|
239
|
-
class:
|
|
240
|
-
transform:
|
|
241
|
-
"rotate(" + angle + "," + this.HALF + "," + this.HALF + ")",
|
|
225
|
+
class: 'blocklyAngleMarks',
|
|
226
|
+
transform: 'rotate(' + angle + ',' + this.HALF + ',' + this.HALF + ')',
|
|
242
227
|
},
|
|
243
|
-
svg
|
|
244
|
-
)
|
|
228
|
+
svg,
|
|
229
|
+
)
|
|
245
230
|
}
|
|
246
231
|
// Center point
|
|
247
232
|
Blockly.utils.dom.createSvgElement(
|
|
248
|
-
|
|
233
|
+
'circle',
|
|
249
234
|
{
|
|
250
235
|
cx: this.HALF,
|
|
251
236
|
cy: this.HALF,
|
|
252
237
|
r: this.CENTER_RADIUS,
|
|
253
|
-
class:
|
|
238
|
+
class: 'blocklyAngleCenterPoint',
|
|
254
239
|
},
|
|
255
|
-
svg
|
|
256
|
-
)
|
|
240
|
+
svg,
|
|
241
|
+
)
|
|
257
242
|
// Handle group: a circle and the arrow image
|
|
258
|
-
this.handle = Blockly.utils.dom.createSvgElement(
|
|
243
|
+
this.handle = Blockly.utils.dom.createSvgElement('g', {}, svg)
|
|
259
244
|
Blockly.utils.dom.createSvgElement(
|
|
260
|
-
|
|
245
|
+
'circle',
|
|
261
246
|
{
|
|
262
247
|
cx: 0,
|
|
263
248
|
cy: 0,
|
|
264
249
|
r: this.HANDLE_RADIUS,
|
|
265
|
-
class:
|
|
250
|
+
class: 'blocklyAngleDragHandle',
|
|
266
251
|
},
|
|
267
|
-
this.handle
|
|
268
|
-
)
|
|
252
|
+
this.handle,
|
|
253
|
+
)
|
|
269
254
|
this.arrow = Blockly.utils.dom.createSvgElement(
|
|
270
|
-
|
|
255
|
+
'image',
|
|
271
256
|
{
|
|
272
257
|
width: this.ARROW_WIDTH,
|
|
273
258
|
height: this.ARROW_WIDTH,
|
|
274
259
|
x: -this.ARROW_WIDTH / 2,
|
|
275
260
|
y: -this.ARROW_WIDTH / 2,
|
|
276
|
-
class:
|
|
261
|
+
class: 'blocklyAngleDragArrow',
|
|
277
262
|
},
|
|
278
|
-
this.handle
|
|
279
|
-
)
|
|
263
|
+
this.handle,
|
|
264
|
+
)
|
|
280
265
|
this.arrow.setAttributeNS(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
Blockly.getMainWorkspace().options.pathToMedia + this.ARROW_SVG_PATH
|
|
284
|
-
)
|
|
266
|
+
'http://www.w3.org/1999/xlink',
|
|
267
|
+
'xlink:href',
|
|
268
|
+
Blockly.getMainWorkspace().options.pathToMedia + this.ARROW_SVG_PATH,
|
|
269
|
+
)
|
|
285
270
|
|
|
286
271
|
Blockly.DropDownDiv.setColour(
|
|
287
272
|
(this.getSourceBlock()!.getParent() as Blockly.BlockSvg).getColour(),
|
|
288
|
-
(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
Blockly.
|
|
293
|
-
this,
|
|
294
|
-
this.getSourceBlock() as Blockly.BlockSvg
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
this.mouseDownWrapper_ = Blockly.browserEvents.bind(
|
|
298
|
-
this.handle,
|
|
299
|
-
"mousedown",
|
|
300
|
-
this,
|
|
301
|
-
this.onMouseDown
|
|
302
|
-
);
|
|
273
|
+
(this.getSourceBlock()!.getParent() as Blockly.BlockSvg).getColourTertiary(),
|
|
274
|
+
)
|
|
275
|
+
Blockly.DropDownDiv.showPositionedByBlock(this, this.getSourceBlock() as Blockly.BlockSvg)
|
|
276
|
+
|
|
277
|
+
this.mouseDownWrapper_ = Blockly.browserEvents.bind(this.handle, 'mousedown', this, this.onMouseDown)
|
|
303
278
|
|
|
304
|
-
this.updateGraph()
|
|
279
|
+
this.updateGraph()
|
|
305
280
|
}
|
|
306
281
|
|
|
307
282
|
/**
|
|
308
283
|
* Set the angle to match the mouse's position.
|
|
309
284
|
*/
|
|
310
285
|
onMouseDown() {
|
|
311
|
-
this.mouseMoveWrapper = Blockly.browserEvents.bind(
|
|
312
|
-
|
|
313
|
-
"mousemove",
|
|
314
|
-
this,
|
|
315
|
-
this.onMouseMove
|
|
316
|
-
);
|
|
317
|
-
this.mouseUpWrapper = Blockly.browserEvents.bind(
|
|
318
|
-
document.body,
|
|
319
|
-
"mouseup",
|
|
320
|
-
this,
|
|
321
|
-
this.onMouseUp
|
|
322
|
-
);
|
|
286
|
+
this.mouseMoveWrapper = Blockly.browserEvents.bind(document.body, 'mousemove', this, this.onMouseMove)
|
|
287
|
+
this.mouseUpWrapper = Blockly.browserEvents.bind(document.body, 'mouseup', this, this.onMouseUp)
|
|
323
288
|
}
|
|
324
289
|
|
|
325
290
|
/**
|
|
326
291
|
* Set the angle to match the mouse's position.
|
|
327
292
|
*/
|
|
328
293
|
onMouseUp() {
|
|
329
|
-
Blockly.browserEvents.unbind(this.mouseMoveWrapper)
|
|
330
|
-
Blockly.browserEvents.unbind(this.mouseUpWrapper)
|
|
294
|
+
Blockly.browserEvents.unbind(this.mouseMoveWrapper)
|
|
295
|
+
Blockly.browserEvents.unbind(this.mouseUpWrapper)
|
|
331
296
|
}
|
|
332
297
|
|
|
333
298
|
/**
|
|
@@ -335,33 +300,33 @@ class ScratchFieldAngle extends Blockly.FieldNumber {
|
|
|
335
300
|
* @param e Mouse move event.
|
|
336
301
|
*/
|
|
337
302
|
onMouseMove(e: PointerEvent) {
|
|
338
|
-
e.preventDefault()
|
|
339
|
-
const bBox = this.gauge!.ownerSVGElement!.getBoundingClientRect()
|
|
340
|
-
const dx = e.clientX - bBox.left - this.HALF
|
|
341
|
-
const dy = e.clientY - bBox.top - this.HALF
|
|
342
|
-
let angle = Math.atan(-dy / dx)
|
|
303
|
+
e.preventDefault()
|
|
304
|
+
const bBox = this.gauge!.ownerSVGElement!.getBoundingClientRect()
|
|
305
|
+
const dx = e.clientX - bBox.left - this.HALF
|
|
306
|
+
const dy = e.clientY - bBox.top - this.HALF
|
|
307
|
+
let angle = Math.atan(-dy / dx)
|
|
343
308
|
if (isNaN(angle)) {
|
|
344
309
|
// This shouldn't happen, but let's not let this error propagate further.
|
|
345
|
-
return
|
|
310
|
+
return
|
|
346
311
|
}
|
|
347
|
-
angle = this.toDegrees(angle)
|
|
312
|
+
angle = this.toDegrees(angle)
|
|
348
313
|
// 0: East, 90: North, 180: West, 270: South.
|
|
349
314
|
if (dx < 0) {
|
|
350
|
-
angle += 180
|
|
315
|
+
angle += 180
|
|
351
316
|
} else if (dy > 0) {
|
|
352
|
-
angle += 360
|
|
317
|
+
angle += 360
|
|
353
318
|
}
|
|
354
319
|
if (this.CLOCKWISE) {
|
|
355
|
-
angle = this.OFFSET + 360 - angle
|
|
320
|
+
angle = this.OFFSET + 360 - angle
|
|
356
321
|
} else {
|
|
357
|
-
angle -= this.OFFSET
|
|
322
|
+
angle -= this.OFFSET
|
|
358
323
|
}
|
|
359
324
|
if (this.ROUND) {
|
|
360
|
-
angle = Math.round(angle / this.ROUND) * this.ROUND
|
|
325
|
+
angle = Math.round(angle / this.ROUND) * this.ROUND
|
|
361
326
|
}
|
|
362
|
-
this.setValue(angle)
|
|
363
|
-
this.setEditorValue_(this.getValue())
|
|
364
|
-
this.resizeEditor_()
|
|
327
|
+
this.setValue(angle)
|
|
328
|
+
this.setEditorValue_(this.getValue())
|
|
329
|
+
this.resizeEditor_()
|
|
365
330
|
}
|
|
366
331
|
|
|
367
332
|
/**
|
|
@@ -369,61 +334,61 @@ class ScratchFieldAngle extends Blockly.FieldNumber {
|
|
|
369
334
|
*/
|
|
370
335
|
private updateGraph() {
|
|
371
336
|
if (!this.gauge) {
|
|
372
|
-
return
|
|
337
|
+
return
|
|
373
338
|
}
|
|
374
|
-
const angleDegrees = (Number(this.getValue()) % 360) + this.OFFSET
|
|
375
|
-
let angleRadians = this.toRadians(angleDegrees)
|
|
376
|
-
const path = [
|
|
377
|
-
let x2 = this.HALF
|
|
378
|
-
let y2 = this.HALF
|
|
339
|
+
const angleDegrees = (Number(this.getValue()) % 360) + this.OFFSET
|
|
340
|
+
let angleRadians = this.toRadians(angleDegrees)
|
|
341
|
+
const path = ['M ', this.HALF, ',', this.HALF]
|
|
342
|
+
let x2 = this.HALF
|
|
343
|
+
let y2 = this.HALF
|
|
379
344
|
if (!isNaN(angleRadians)) {
|
|
380
|
-
const angle1 = this.toRadians(this.OFFSET)
|
|
381
|
-
const x1 = Math.cos(angle1) * this.RADIUS
|
|
382
|
-
const y1 = Math.sin(angle1) * -this.RADIUS
|
|
345
|
+
const angle1 = this.toRadians(this.OFFSET)
|
|
346
|
+
const x1 = Math.cos(angle1) * this.RADIUS
|
|
347
|
+
const y1 = Math.sin(angle1) * -this.RADIUS
|
|
383
348
|
if (this.CLOCKWISE) {
|
|
384
|
-
angleRadians = 2 * angle1 - angleRadians
|
|
349
|
+
angleRadians = 2 * angle1 - angleRadians
|
|
385
350
|
}
|
|
386
|
-
x2 += Math.cos(angleRadians) * this.RADIUS
|
|
387
|
-
y2 -= Math.sin(angleRadians) * this.RADIUS
|
|
351
|
+
x2 += Math.cos(angleRadians) * this.RADIUS
|
|
352
|
+
y2 -= Math.sin(angleRadians) * this.RADIUS
|
|
388
353
|
// Use large arc only if input value is greater than wrap
|
|
389
|
-
const largeFlag = Math.abs(angleDegrees - this.OFFSET) > 180 ? 1 : 0
|
|
390
|
-
let sweepFlag = Number(this.CLOCKWISE)
|
|
354
|
+
const largeFlag = Math.abs(angleDegrees - this.OFFSET) > 180 ? 1 : 0
|
|
355
|
+
let sweepFlag = Number(this.CLOCKWISE)
|
|
391
356
|
if (angleDegrees < this.OFFSET) {
|
|
392
|
-
sweepFlag = 1 - sweepFlag
|
|
357
|
+
sweepFlag = 1 - sweepFlag // Sweep opposite direction if less than the offset
|
|
393
358
|
}
|
|
394
359
|
path.push(
|
|
395
|
-
|
|
360
|
+
' l ',
|
|
396
361
|
x1,
|
|
397
|
-
|
|
362
|
+
',',
|
|
398
363
|
y1,
|
|
399
|
-
|
|
364
|
+
' A ',
|
|
400
365
|
this.RADIUS,
|
|
401
|
-
|
|
366
|
+
',',
|
|
402
367
|
this.RADIUS,
|
|
403
|
-
|
|
368
|
+
' 0 ',
|
|
404
369
|
largeFlag,
|
|
405
|
-
|
|
370
|
+
' ',
|
|
406
371
|
sweepFlag,
|
|
407
|
-
|
|
372
|
+
' ',
|
|
408
373
|
x2,
|
|
409
|
-
|
|
374
|
+
',',
|
|
410
375
|
y2,
|
|
411
|
-
|
|
412
|
-
)
|
|
376
|
+
' z',
|
|
377
|
+
)
|
|
413
378
|
|
|
414
379
|
// Image rotation needs to be set in degrees
|
|
415
|
-
let imageRotation: number
|
|
380
|
+
let imageRotation: number
|
|
416
381
|
if (this.CLOCKWISE) {
|
|
417
|
-
imageRotation = angleDegrees + 2 * this.OFFSET
|
|
382
|
+
imageRotation = angleDegrees + 2 * this.OFFSET
|
|
418
383
|
} else {
|
|
419
|
-
imageRotation = -angleDegrees
|
|
384
|
+
imageRotation = -angleDegrees
|
|
420
385
|
}
|
|
421
|
-
this.arrow!.setAttribute(
|
|
386
|
+
this.arrow!.setAttribute('transform', 'rotate(' + imageRotation + ')')
|
|
422
387
|
}
|
|
423
|
-
this.gauge
|
|
424
|
-
this.line!.setAttribute(
|
|
425
|
-
this.line!.setAttribute(
|
|
426
|
-
this.handle!.setAttribute(
|
|
388
|
+
this.gauge.setAttribute('d', path.join(''))
|
|
389
|
+
this.line!.setAttribute('x2', `${x2}`)
|
|
390
|
+
this.line!.setAttribute('y2', `${y2}`)
|
|
391
|
+
this.handle!.setAttribute('transform', 'translate(' + x2 + ',' + y2 + ')')
|
|
427
392
|
}
|
|
428
393
|
|
|
429
394
|
/**
|
|
@@ -433,53 +398,52 @@ class ScratchFieldAngle extends Blockly.FieldNumber {
|
|
|
433
398
|
*/
|
|
434
399
|
doClassValidation_(text: string): number | null {
|
|
435
400
|
if (text === null) {
|
|
436
|
-
return null
|
|
401
|
+
return null
|
|
437
402
|
}
|
|
438
|
-
let n = parseFloat(text ||
|
|
403
|
+
let n = parseFloat(text || '0')
|
|
439
404
|
if (isNaN(n)) {
|
|
440
|
-
return null
|
|
405
|
+
return null
|
|
441
406
|
}
|
|
442
|
-
n = n % 360
|
|
407
|
+
n = n % 360
|
|
443
408
|
if (n < 0) {
|
|
444
|
-
n += 360
|
|
409
|
+
n += 360
|
|
445
410
|
}
|
|
446
411
|
if (n > this.WRAP) {
|
|
447
|
-
n -= 360
|
|
412
|
+
n -= 360
|
|
448
413
|
}
|
|
449
|
-
return Number(n)
|
|
414
|
+
return Number(n)
|
|
450
415
|
}
|
|
451
416
|
|
|
452
417
|
doValueUpdate_(newValue: number) {
|
|
453
|
-
super.doValueUpdate_(newValue)
|
|
454
|
-
this.updateGraph()
|
|
418
|
+
super.doValueUpdate_(newValue)
|
|
419
|
+
this.updateGraph()
|
|
455
420
|
}
|
|
456
421
|
|
|
457
422
|
toDegrees(radians: number) {
|
|
458
|
-
return (radians * 180) / Math.PI
|
|
423
|
+
return (radians * 180) / Math.PI
|
|
459
424
|
}
|
|
460
425
|
|
|
461
426
|
toRadians(degrees: number) {
|
|
462
|
-
return (degrees * Math.PI) / 180
|
|
427
|
+
return (degrees * Math.PI) / 180
|
|
463
428
|
}
|
|
464
429
|
|
|
465
430
|
/**
|
|
466
431
|
* Construct a FieldAngle from a JSON arg object.
|
|
467
|
-
*
|
|
468
432
|
* @param options A JSON object with options (angle).
|
|
469
433
|
* @returns The new field instance.
|
|
470
434
|
*/
|
|
471
435
|
fromJson(options: ScratchFieldAngleJsonConfig): ScratchFieldAngle {
|
|
472
|
-
return new ScratchFieldAngle(options
|
|
436
|
+
return new ScratchFieldAngle(options.angle)
|
|
473
437
|
}
|
|
474
438
|
}
|
|
475
439
|
|
|
476
440
|
export interface ScratchFieldAngleJsonConfig {
|
|
477
|
-
angle?: number
|
|
441
|
+
angle?: number
|
|
478
442
|
}
|
|
479
443
|
|
|
480
444
|
/**
|
|
481
445
|
* Register the field and any dependencies.
|
|
482
446
|
*/
|
|
483
447
|
export function registerScratchFieldAngle() {
|
|
484
|
-
Blockly.fieldRegistry.register(
|
|
448
|
+
Blockly.fieldRegistry.register('field_angle', ScratchFieldAngle)
|
|
485
449
|
}
|
|
@@ -1,36 +1,32 @@
|
|
|
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
|
class ScratchFieldDropdown extends Blockly.FieldDropdown {
|
|
10
|
-
private originalStyle!: string
|
|
8
|
+
private originalStyle!: string
|
|
11
9
|
|
|
12
10
|
showEditor_(event: PointerEvent) {
|
|
13
|
-
super.showEditor_(event)
|
|
14
|
-
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
15
|
-
const style = sourceBlock.style
|
|
11
|
+
super.showEditor_(event)
|
|
12
|
+
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
13
|
+
const style = sourceBlock.style
|
|
16
14
|
if (sourceBlock.isShadow()) {
|
|
17
|
-
this.originalStyle = sourceBlock.getStyleName()
|
|
18
|
-
sourceBlock.setStyle(`${this.originalStyle}_selected`)
|
|
15
|
+
this.originalStyle = sourceBlock.getStyleName()
|
|
16
|
+
sourceBlock.setStyle(`${this.originalStyle}_selected`)
|
|
19
17
|
} else if (this.borderRect_) {
|
|
20
18
|
this.borderRect_.setAttribute(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
: style.colourTertiary
|
|
25
|
-
);
|
|
19
|
+
'fill',
|
|
20
|
+
'colourQuaternary' in style ? `${style.colourQuaternary}` : style.colourTertiary,
|
|
21
|
+
)
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
dropdownDispose_() {
|
|
30
|
-
super.dropdownDispose_()
|
|
31
|
-
const sourceBlock = this.getSourceBlock()
|
|
26
|
+
super.dropdownDispose_()
|
|
27
|
+
const sourceBlock = this.getSourceBlock()!
|
|
32
28
|
if (sourceBlock.isShadow()) {
|
|
33
|
-
sourceBlock.setStyle(this.originalStyle)
|
|
29
|
+
sourceBlock.setStyle(this.originalStyle)
|
|
34
30
|
}
|
|
35
31
|
}
|
|
36
32
|
}
|
|
@@ -39,6 +35,6 @@ class ScratchFieldDropdown extends Blockly.FieldDropdown {
|
|
|
39
35
|
* Register the field and any dependencies.
|
|
40
36
|
*/
|
|
41
37
|
export function registerScratchFieldDropdown() {
|
|
42
|
-
Blockly.fieldRegistry.unregister(
|
|
43
|
-
Blockly.fieldRegistry.register(
|
|
38
|
+
Blockly.fieldRegistry.unregister('field_dropdown')
|
|
39
|
+
Blockly.fieldRegistry.register('field_dropdown', ScratchFieldDropdown)
|
|
44
40
|
}
|