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 2016 Massachusetts Institute of Technology
|
|
@@ -17,13 +16,12 @@
|
|
|
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 Field for numbers. Includes validator and numpad on touch.
|
|
23
21
|
* @author tmickel@mit.edu (Tim Mickel)
|
|
24
22
|
*/
|
|
25
|
-
import * as Blockly from
|
|
26
|
-
import { Colours } from
|
|
23
|
+
import * as Blockly from 'blockly/core'
|
|
24
|
+
import { Colours } from '../colours'
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* Class for an editable number field.
|
|
@@ -33,127 +31,105 @@ import { Colours } from "../colours";
|
|
|
33
31
|
* These properties are included here (i.e. instead of just accepting a
|
|
34
32
|
* decimalAllowed, negativeAllowed) to maintain API compatibility with Blockly
|
|
35
33
|
* and Blockly for Android.
|
|
36
|
-
* @param
|
|
34
|
+
* @param opt_value The initial content of the field. The value
|
|
37
35
|
* should cast to a number, and if it does not, '0' will be used.
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
36
|
+
* @param opt_min Minimum value.
|
|
37
|
+
* @param opt_max Maximum value.
|
|
38
|
+
* @param opt_precision Precision for value.
|
|
39
|
+
* @param opt_validator An optional function that is called
|
|
42
40
|
* to validate any constraints on what the user entered. Takes the new
|
|
43
41
|
* text as an argument and returns the accepted text or null to abort
|
|
44
42
|
* the change.
|
|
45
|
-
* @extends {Blockly.FieldTextInput}
|
|
46
|
-
* @constructor
|
|
47
43
|
*/
|
|
48
44
|
class ScratchFieldNumber extends Blockly.FieldTextInput {
|
|
49
|
-
private negativeAllowed_ = true
|
|
50
|
-
private decimalAllowed_ = true
|
|
51
|
-
private exponentialAllowed_ = true
|
|
45
|
+
private negativeAllowed_ = true
|
|
46
|
+
private decimalAllowed_ = true
|
|
47
|
+
private exponentialAllowed_ = true
|
|
52
48
|
/**
|
|
53
49
|
* Fixed width of the num-pad drop-down, in px.
|
|
54
|
-
* @type {number}
|
|
55
|
-
* @const
|
|
56
50
|
*/
|
|
57
|
-
static DROPDOWN_WIDTH = 168
|
|
51
|
+
static DROPDOWN_WIDTH = 168
|
|
58
52
|
|
|
59
53
|
/**
|
|
60
54
|
* Buttons for the num-pad, in order from the top left.
|
|
61
55
|
* Values are strings of the number or symbol will be added to the field text
|
|
62
56
|
* when the button is pressed.
|
|
63
|
-
* @type {Array.<string>}
|
|
64
|
-
* @const
|
|
65
57
|
*/
|
|
66
58
|
// Calculator order
|
|
67
|
-
static NUMPAD_BUTTONS = [
|
|
68
|
-
"7",
|
|
69
|
-
"8",
|
|
70
|
-
"9",
|
|
71
|
-
"4",
|
|
72
|
-
"5",
|
|
73
|
-
"6",
|
|
74
|
-
"1",
|
|
75
|
-
"2",
|
|
76
|
-
"3",
|
|
77
|
-
".",
|
|
78
|
-
"0",
|
|
79
|
-
"-",
|
|
80
|
-
" ",
|
|
81
|
-
];
|
|
59
|
+
static NUMPAD_BUTTONS = ['7', '8', '9', '4', '5', '6', '1', '2', '3', '.', '0', '-', ' ']
|
|
82
60
|
|
|
83
61
|
/**
|
|
84
62
|
* Src for the delete icon to be shown on the num-pad.
|
|
85
|
-
* @type {string}
|
|
86
|
-
* @const
|
|
87
63
|
*/
|
|
88
64
|
static NUMPAD_DELETE_ICON =
|
|
89
|
-
|
|
90
|
-
|
|
65
|
+
'data:image/svg+xml;utf8,' +
|
|
66
|
+
'<svg ' +
|
|
91
67
|
'xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">' +
|
|
92
68
|
'<path d="M28.89,11.45H16.79a2.86,2.86,0,0,0-2,.84L9.09,1' +
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
'8a2.85,2.85,0,0,0,0,4l5.69,5.69a2.86,2.86,0,0,0,2,.84h12' +
|
|
70
|
+
'.1a2.86,2.86,0,0,0,2.86-2.86V14.31A2.86,2.86,0,0,0,28.89' +
|
|
71
|
+
',11.45ZM27.15,22.73a1,1,0,0,1,0,1.41,1,1,0,0,1-.71.3,1,1' +
|
|
72
|
+
',0,0,1-.71-0.3L23,21.41l-2.73,2.73a1,1,0,0,1-1.41,0,1,1,' +
|
|
73
|
+
'0,0,1,0-1.41L21.59,20l-2.73-2.73a1,1,0,0,1,0-1.41,1,1,0,' +
|
|
98
74
|
'0,1,1.41,0L23,18.59l2.73-2.73a1,1,0,1,1,1.42,1.41L24.42,20Z" fill="' +
|
|
99
75
|
Colours.numPadText +
|
|
100
|
-
'"/></svg>'
|
|
76
|
+
'"/></svg>'
|
|
101
77
|
|
|
102
78
|
configure_(config: Blockly.FieldNumberFromJsonConfig) {
|
|
103
|
-
super.configure_(config)
|
|
79
|
+
super.configure_(config)
|
|
104
80
|
this.decimalAllowed_ =
|
|
105
|
-
typeof config.precision ==
|
|
81
|
+
typeof config.precision == 'undefined' ||
|
|
106
82
|
isNaN(config.precision) ||
|
|
107
83
|
config.precision == 0 ||
|
|
108
|
-
Math.floor(config.precision) != config.precision
|
|
109
|
-
this.negativeAllowed_ =
|
|
110
|
-
|
|
111
|
-
this.exponentialAllowed_ = this.decimalAllowed_;
|
|
84
|
+
Math.floor(config.precision) != config.precision
|
|
85
|
+
this.negativeAllowed_ = typeof config.min == 'undefined' || isNaN(config.min) || config.min < 0
|
|
86
|
+
this.exponentialAllowed_ = this.decimalAllowed_
|
|
112
87
|
}
|
|
113
88
|
|
|
114
89
|
/**
|
|
115
90
|
* Return an appropriate restrictor, depending on whether this FieldNumber
|
|
116
91
|
* allows decimal or negative numbers.
|
|
117
|
-
* @
|
|
92
|
+
* @returns Regular expression for this FieldNumber's restrictor.
|
|
118
93
|
*/
|
|
119
94
|
getNumRestrictor() {
|
|
120
|
-
let pattern =
|
|
95
|
+
let pattern = '[\\d]' // Always allow digits.
|
|
121
96
|
if (this.decimalAllowed_) {
|
|
122
|
-
pattern +=
|
|
97
|
+
pattern += '|[\\.]'
|
|
123
98
|
}
|
|
124
99
|
if (this.negativeAllowed_) {
|
|
125
|
-
pattern +=
|
|
100
|
+
pattern += '|[-]'
|
|
126
101
|
}
|
|
127
102
|
if (this.exponentialAllowed_) {
|
|
128
|
-
pattern +=
|
|
103
|
+
pattern += '|[eE]'
|
|
129
104
|
}
|
|
130
|
-
return new RegExp(pattern)
|
|
105
|
+
return new RegExp(pattern)
|
|
131
106
|
}
|
|
132
107
|
|
|
133
108
|
/**
|
|
134
109
|
* Show the inline free-text editor on top of the text and the num-pad if
|
|
135
110
|
* appropriate.
|
|
111
|
+
* @param e The triggering pointer event.
|
|
136
112
|
*/
|
|
137
113
|
showEditor_(e: PointerEvent) {
|
|
138
114
|
// Do not focus on mobile devices so we can show the num-pad
|
|
139
|
-
const showNumPad = e
|
|
140
|
-
super.showEditor_(e, showNumPad)
|
|
115
|
+
const showNumPad = e?.pointerType === 'touch'
|
|
116
|
+
super.showEditor_(e, showNumPad)
|
|
141
117
|
|
|
142
118
|
// Show a numeric keypad in the drop-down on touch
|
|
143
119
|
if (showNumPad) {
|
|
144
|
-
this.htmlInput_
|
|
145
|
-
this.showNumPad_()
|
|
120
|
+
this.htmlInput_!.select()
|
|
121
|
+
this.showNumPad_()
|
|
146
122
|
}
|
|
147
123
|
}
|
|
148
124
|
|
|
149
125
|
onHtmlInputKeyDown_(e: KeyboardEvent) {
|
|
150
|
-
super.onHtmlInputKeyDown_(e)
|
|
126
|
+
super.onHtmlInputKeyDown_(e)
|
|
151
127
|
// key can be things like "Backspace", so only validate when it represents a single
|
|
152
128
|
// character so as to allow non-textual input to work as normal.
|
|
153
129
|
if (e.key.length === 1) {
|
|
154
|
-
const validator = this.getNumRestrictor()
|
|
130
|
+
const validator = this.getNumRestrictor()
|
|
155
131
|
if (!e.key.match(validator)) {
|
|
156
|
-
e.preventDefault()
|
|
132
|
+
e.preventDefault()
|
|
157
133
|
}
|
|
158
134
|
}
|
|
159
135
|
}
|
|
@@ -162,23 +138,20 @@ class ScratchFieldNumber extends Blockly.FieldTextInput {
|
|
|
162
138
|
* Show the number pad.
|
|
163
139
|
*/
|
|
164
140
|
private showNumPad_() {
|
|
165
|
-
const contentDiv = Blockly.DropDownDiv.getContentDiv()
|
|
141
|
+
const contentDiv = Blockly.DropDownDiv.getContentDiv()
|
|
166
142
|
|
|
167
143
|
// Accessibility properties
|
|
168
|
-
contentDiv.setAttribute(
|
|
169
|
-
contentDiv.setAttribute(
|
|
144
|
+
contentDiv.setAttribute('role', 'menu')
|
|
145
|
+
contentDiv.setAttribute('aria-haspopup', 'true')
|
|
170
146
|
|
|
171
|
-
this.addButtons_(contentDiv)
|
|
147
|
+
this.addButtons_(contentDiv)
|
|
172
148
|
|
|
173
149
|
// Set colour and size of drop-down
|
|
174
|
-
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
175
|
-
Blockly.DropDownDiv.setColour(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)
|
|
179
|
-
contentDiv.style.width = ScratchFieldNumber.DROPDOWN_WIDTH + "px";
|
|
180
|
-
|
|
181
|
-
this.position_();
|
|
150
|
+
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
151
|
+
Blockly.DropDownDiv.setColour(sourceBlock.getParent()!.getColour(), sourceBlock.getColourTertiary())
|
|
152
|
+
contentDiv.style.width = ScratchFieldNumber.DROPDOWN_WIDTH + 'px'
|
|
153
|
+
|
|
154
|
+
this.position_()
|
|
182
155
|
}
|
|
183
156
|
|
|
184
157
|
/**
|
|
@@ -187,181 +160,152 @@ class ScratchFieldNumber extends Blockly.FieldTextInput {
|
|
|
187
160
|
private position_() {
|
|
188
161
|
// Calculate positioning for the drop-down
|
|
189
162
|
// sourceBlock_ is the rendered shadow field input box
|
|
190
|
-
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
191
|
-
const scale = sourceBlock.workspace.scale
|
|
192
|
-
|
|
193
|
-
bBox.width *= scale
|
|
194
|
-
bBox.height *= scale
|
|
195
|
-
const position = this.getAbsoluteXY_()
|
|
163
|
+
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
164
|
+
const scale = sourceBlock.workspace.scale
|
|
165
|
+
const bBox = sourceBlock.getHeightWidth()
|
|
166
|
+
bBox.width *= scale
|
|
167
|
+
bBox.height *= scale
|
|
168
|
+
const position = this.getAbsoluteXY_()
|
|
196
169
|
// If we can fit it, render below the shadow block
|
|
197
|
-
const primaryX = position.x + bBox.width / 2
|
|
198
|
-
const primaryY = position.y + bBox.height
|
|
170
|
+
const primaryX = position.x + bBox.width / 2
|
|
171
|
+
const primaryY = position.y + bBox.height
|
|
199
172
|
// If we can't fit it, render above the entire parent block
|
|
200
|
-
const secondaryX = primaryX
|
|
201
|
-
const secondaryY = position.y
|
|
173
|
+
const secondaryX = primaryX
|
|
174
|
+
const secondaryY = position.y
|
|
202
175
|
|
|
203
|
-
Blockly.DropDownDiv.setBoundsElement(
|
|
204
|
-
sourceBlock.workspace.getParentSvg().parentElement
|
|
205
|
-
);
|
|
176
|
+
Blockly.DropDownDiv.setBoundsElement(sourceBlock.workspace.getParentSvg().parentElement)
|
|
206
177
|
Blockly.DropDownDiv.show(
|
|
207
178
|
this,
|
|
208
|
-
this.getSourceBlock()
|
|
179
|
+
this.getSourceBlock()!.RTL,
|
|
209
180
|
primaryX,
|
|
210
181
|
primaryY,
|
|
211
182
|
secondaryX,
|
|
212
183
|
secondaryY,
|
|
213
|
-
|
|
214
|
-
|
|
184
|
+
false,
|
|
185
|
+
this.onHide_.bind(this),
|
|
186
|
+
)
|
|
215
187
|
}
|
|
216
188
|
|
|
217
189
|
/**
|
|
218
190
|
* Add number, punctuation, and erase buttons to the numeric keypad's content
|
|
219
191
|
* div.
|
|
220
|
-
*
|
|
221
192
|
* @param contentDiv The div for the numeric keypad.
|
|
222
193
|
*/
|
|
223
194
|
private addButtons_(contentDiv: Element) {
|
|
224
|
-
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
225
|
-
const buttonColour = sourceBlock.getParent()
|
|
226
|
-
const buttonBorderColour = sourceBlock.getParent()
|
|
195
|
+
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
196
|
+
const buttonColour = sourceBlock.getParent()!.getColour()
|
|
197
|
+
const buttonBorderColour = sourceBlock.getParent()!.getColourTertiary()
|
|
227
198
|
|
|
228
199
|
// Add numeric keypad buttons
|
|
229
|
-
const buttons = ScratchFieldNumber.NUMPAD_BUTTONS
|
|
200
|
+
const buttons = ScratchFieldNumber.NUMPAD_BUTTONS
|
|
230
201
|
for (let i = 0, buttonText; (buttonText = buttons[i]); i++) {
|
|
231
|
-
const button = document.createElement(
|
|
232
|
-
button.setAttribute(
|
|
233
|
-
button.setAttribute(
|
|
202
|
+
const button = document.createElement('button')
|
|
203
|
+
button.setAttribute('role', 'menuitem')
|
|
204
|
+
button.setAttribute('class', 'blocklyNumPadButton')
|
|
234
205
|
button.setAttribute(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
);
|
|
243
|
-
button.title = buttonText;
|
|
244
|
-
button.innerHTML = buttonText;
|
|
245
|
-
Blockly.browserEvents.bind(
|
|
246
|
-
button,
|
|
247
|
-
"mousedown",
|
|
248
|
-
button,
|
|
249
|
-
this.numPadButtonTouch.bind(this)
|
|
250
|
-
);
|
|
251
|
-
if (buttonText == "." && !this.decimalAllowed_) {
|
|
206
|
+
'style',
|
|
207
|
+
'background:' + buttonColour + ';' + 'border: 1px solid ' + buttonBorderColour + ';',
|
|
208
|
+
)
|
|
209
|
+
button.title = buttonText
|
|
210
|
+
button.innerHTML = buttonText
|
|
211
|
+
Blockly.browserEvents.bind(button, 'mousedown', button, this.numPadButtonTouch.bind(this))
|
|
212
|
+
if (buttonText == '.' && !this.decimalAllowed_) {
|
|
252
213
|
// Don't show the decimal point for inputs that must be round numbers
|
|
253
|
-
button.setAttribute(
|
|
254
|
-
} else if (buttonText ==
|
|
255
|
-
continue
|
|
256
|
-
} else if (buttonText ==
|
|
257
|
-
continue
|
|
258
|
-
} else if (buttonText ==
|
|
259
|
-
button.setAttribute(
|
|
214
|
+
button.setAttribute('style', 'visibility: hidden')
|
|
215
|
+
} else if (buttonText == '-' && !this.negativeAllowed_) {
|
|
216
|
+
continue
|
|
217
|
+
} else if (buttonText == ' ' && !this.negativeAllowed_) {
|
|
218
|
+
continue
|
|
219
|
+
} else if (buttonText == ' ' && this.negativeAllowed_) {
|
|
220
|
+
button.setAttribute('style', 'visibility: hidden')
|
|
260
221
|
}
|
|
261
|
-
contentDiv.appendChild(button)
|
|
222
|
+
contentDiv.appendChild(button)
|
|
262
223
|
}
|
|
263
224
|
// Add erase button to the end
|
|
264
|
-
const eraseButton = document.createElement(
|
|
265
|
-
eraseButton.setAttribute(
|
|
266
|
-
eraseButton.setAttribute(
|
|
225
|
+
const eraseButton = document.createElement('button')
|
|
226
|
+
eraseButton.setAttribute('role', 'menuitem')
|
|
227
|
+
eraseButton.setAttribute('class', 'blocklyNumPadButton')
|
|
267
228
|
eraseButton.setAttribute(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
eraseImage.src = ScratchFieldNumber.NUMPAD_DELETE_ICON;
|
|
280
|
-
eraseButton.appendChild(eraseImage);
|
|
281
|
-
|
|
282
|
-
Blockly.browserEvents.bind(
|
|
283
|
-
eraseButton,
|
|
284
|
-
"mousedown",
|
|
285
|
-
null,
|
|
286
|
-
this.numPadEraseButtonTouch.bind(this)
|
|
287
|
-
);
|
|
288
|
-
contentDiv.appendChild(eraseButton);
|
|
229
|
+
'style',
|
|
230
|
+
'background:' + buttonColour + ';' + 'border: 1px solid ' + buttonBorderColour + ';',
|
|
231
|
+
)
|
|
232
|
+
eraseButton.title = 'Delete'
|
|
233
|
+
|
|
234
|
+
const eraseImage = document.createElement('img')
|
|
235
|
+
eraseImage.src = ScratchFieldNumber.NUMPAD_DELETE_ICON
|
|
236
|
+
eraseButton.appendChild(eraseImage)
|
|
237
|
+
|
|
238
|
+
Blockly.browserEvents.bind(eraseButton, 'mousedown', null, this.numPadEraseButtonTouch.bind(this))
|
|
239
|
+
contentDiv.appendChild(eraseButton)
|
|
289
240
|
}
|
|
290
241
|
|
|
291
242
|
/**
|
|
292
243
|
* Call for when a num-pad number or punctuation button is touched.
|
|
293
244
|
* Determine what the user is inputting and update the text field appropriately.
|
|
294
|
-
*
|
|
295
245
|
* @param e DOM event triggering the touch.
|
|
296
246
|
*/
|
|
297
247
|
numPadButtonTouch(e: PointerEvent) {
|
|
298
248
|
// String of the button (e.g., '7')
|
|
299
|
-
const spliceValue = (e.target as HTMLElement).innerText
|
|
249
|
+
const spliceValue = (e.target as HTMLElement).innerText
|
|
300
250
|
// Old value of the text field
|
|
301
|
-
const oldValue = this.htmlInput_
|
|
251
|
+
const oldValue = this.htmlInput_!.value
|
|
302
252
|
// Determine the selected portion of the text field
|
|
303
|
-
const selectionStart = this.htmlInput_
|
|
304
|
-
const selectionEnd = this.htmlInput_
|
|
253
|
+
const selectionStart = this.htmlInput_!.selectionStart ?? 0
|
|
254
|
+
const selectionEnd = this.htmlInput_!.selectionEnd ?? 0
|
|
305
255
|
|
|
306
256
|
// Splice in the new value
|
|
307
|
-
const newValue =
|
|
308
|
-
oldValue.slice(0, selectionStart) +
|
|
309
|
-
spliceValue +
|
|
310
|
-
oldValue.slice(selectionEnd);
|
|
257
|
+
const newValue = oldValue.slice(0, selectionStart) + spliceValue + oldValue.slice(selectionEnd)
|
|
311
258
|
|
|
312
259
|
// Set new value and advance the cursor
|
|
313
|
-
this.updateDisplay_(newValue, selectionStart + spliceValue.length)
|
|
260
|
+
this.updateDisplay_(newValue, selectionStart + spliceValue.length)
|
|
314
261
|
|
|
315
262
|
// This is just a click.
|
|
316
|
-
Blockly.Touch.clearTouchIdentifier()
|
|
263
|
+
Blockly.Touch.clearTouchIdentifier()
|
|
317
264
|
|
|
318
265
|
// Prevent default to not lose input focus
|
|
319
|
-
e.preventDefault()
|
|
266
|
+
e.preventDefault()
|
|
320
267
|
}
|
|
321
268
|
|
|
322
269
|
/**
|
|
323
270
|
* Call for when the num-pad erase button is touched.
|
|
324
271
|
* Determine what the user is asking to erase, and erase it.
|
|
325
|
-
*
|
|
326
272
|
* @param e DOM event triggering the touch.
|
|
327
273
|
*/
|
|
328
274
|
numPadEraseButtonTouch(e: PointerEvent) {
|
|
329
275
|
// Old value of the text field
|
|
330
|
-
const oldValue = this.htmlInput_
|
|
276
|
+
const oldValue = this.htmlInput_!.value
|
|
331
277
|
// Determine what is selected to erase (if anything)
|
|
332
|
-
let selectionStart = this.htmlInput_
|
|
333
|
-
const selectionEnd = this.htmlInput_
|
|
278
|
+
let selectionStart = this.htmlInput_!.selectionStart ?? 0
|
|
279
|
+
const selectionEnd = this.htmlInput_!.selectionEnd ?? 0
|
|
334
280
|
|
|
335
281
|
// If selection is zero-length, shift start to the left 1 character
|
|
336
282
|
if (selectionStart == selectionEnd) {
|
|
337
|
-
selectionStart = Math.max(0, selectionStart - 1)
|
|
283
|
+
selectionStart = Math.max(0, selectionStart - 1)
|
|
338
284
|
}
|
|
339
285
|
|
|
340
286
|
// Cut out selected range
|
|
341
|
-
const newValue =
|
|
342
|
-
oldValue.slice(0, selectionStart) + oldValue.slice(selectionEnd);
|
|
287
|
+
const newValue = oldValue.slice(0, selectionStart) + oldValue.slice(selectionEnd)
|
|
343
288
|
|
|
344
|
-
this.updateDisplay_(newValue, selectionStart)
|
|
289
|
+
this.updateDisplay_(newValue, selectionStart)
|
|
345
290
|
|
|
346
291
|
// This is just a click.
|
|
347
|
-
Blockly.Touch.clearTouchIdentifier()
|
|
292
|
+
Blockly.Touch.clearTouchIdentifier()
|
|
348
293
|
|
|
349
294
|
// Prevent default to not lose input focus which resets cursors in Chrome
|
|
350
|
-
e.preventDefault()
|
|
295
|
+
e.preventDefault()
|
|
351
296
|
}
|
|
352
297
|
|
|
353
298
|
/**
|
|
354
299
|
* Update the displayed value and resize/scroll the text field as needed.
|
|
355
|
-
*
|
|
356
300
|
* @param newValue The new text to display.
|
|
357
301
|
* @param newSelection The new index to put the cursor
|
|
358
302
|
*/
|
|
359
303
|
private updateDisplay_(newValue: string, newSelection: number) {
|
|
360
|
-
this.setEditorValue_(newValue)
|
|
304
|
+
this.setEditorValue_(newValue)
|
|
361
305
|
// Resize and scroll the text field appropriately
|
|
362
|
-
const htmlInput = this.htmlInput_
|
|
363
|
-
htmlInput.setSelectionRange(newSelection, newSelection)
|
|
364
|
-
htmlInput.scrollLeft = htmlInput.scrollWidth
|
|
306
|
+
const htmlInput = this.htmlInput_!
|
|
307
|
+
htmlInput.setSelectionRange(newSelection, newSelection)
|
|
308
|
+
htmlInput.scrollLeft = htmlInput.scrollWidth
|
|
365
309
|
}
|
|
366
310
|
|
|
367
311
|
/**
|
|
@@ -369,17 +313,17 @@ class ScratchFieldNumber extends Blockly.FieldTextInput {
|
|
|
369
313
|
*/
|
|
370
314
|
onHide_() {
|
|
371
315
|
// Clear accessibility properties
|
|
372
|
-
Blockly.DropDownDiv.getContentDiv().removeAttribute(
|
|
373
|
-
Blockly.DropDownDiv.getContentDiv().removeAttribute(
|
|
316
|
+
Blockly.DropDownDiv.getContentDiv().removeAttribute('role')
|
|
317
|
+
Blockly.DropDownDiv.getContentDiv().removeAttribute('aria-haspopup')
|
|
374
318
|
}
|
|
375
319
|
}
|
|
376
320
|
|
|
377
|
-
ScratchFieldNumber.prototype.DEFAULT_VALUE =
|
|
321
|
+
ScratchFieldNumber.prototype.DEFAULT_VALUE = ''
|
|
378
322
|
|
|
379
323
|
/**
|
|
380
324
|
* Register the field and any dependencies.
|
|
381
325
|
*/
|
|
382
326
|
export function registerScratchFieldNumber() {
|
|
383
|
-
Blockly.fieldRegistry.unregister(
|
|
384
|
-
Blockly.fieldRegistry.register(
|
|
327
|
+
Blockly.fieldRegistry.unregister('field_number')
|
|
328
|
+
Blockly.fieldRegistry.register('field_number', ScratchFieldNumber)
|
|
385
329
|
}
|