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 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_!.select()
|
|
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,22 +160,20 @@ 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
179
|
this.getSourceBlock()!.RTL,
|
|
@@ -211,158 +182,130 @@ class ScratchFieldNumber extends Blockly.FieldTextInput {
|
|
|
211
182
|
secondaryX,
|
|
212
183
|
secondaryY,
|
|
213
184
|
false,
|
|
214
|
-
this.onHide_.bind(this)
|
|
215
|
-
)
|
|
185
|
+
this.onHide_.bind(this),
|
|
186
|
+
)
|
|
216
187
|
}
|
|
217
188
|
|
|
218
189
|
/**
|
|
219
190
|
* Add number, punctuation, and erase buttons to the numeric keypad's content
|
|
220
191
|
* div.
|
|
221
|
-
*
|
|
222
192
|
* @param contentDiv The div for the numeric keypad.
|
|
223
193
|
*/
|
|
224
194
|
private addButtons_(contentDiv: Element) {
|
|
225
|
-
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
226
|
-
const buttonColour =
|
|
227
|
-
const buttonBorderColour =
|
|
195
|
+
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
196
|
+
const buttonColour = sourceBlock.getParent()!.getColour()
|
|
197
|
+
const buttonBorderColour = sourceBlock.getParent()!.getColourTertiary()
|
|
228
198
|
|
|
229
199
|
// Add numeric keypad buttons
|
|
230
|
-
const buttons = ScratchFieldNumber.NUMPAD_BUTTONS
|
|
200
|
+
const buttons = ScratchFieldNumber.NUMPAD_BUTTONS
|
|
231
201
|
for (let i = 0, buttonText; (buttonText = buttons[i]); i++) {
|
|
232
|
-
const button = document.createElement(
|
|
233
|
-
button.setAttribute(
|
|
234
|
-
button.setAttribute(
|
|
202
|
+
const button = document.createElement('button')
|
|
203
|
+
button.setAttribute('role', 'menuitem')
|
|
204
|
+
button.setAttribute('class', 'blocklyNumPadButton')
|
|
235
205
|
button.setAttribute(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
);
|
|
244
|
-
button.title = buttonText;
|
|
245
|
-
button.innerHTML = buttonText;
|
|
246
|
-
Blockly.browserEvents.bind(
|
|
247
|
-
button,
|
|
248
|
-
"mousedown",
|
|
249
|
-
button,
|
|
250
|
-
this.numPadButtonTouch.bind(this)
|
|
251
|
-
);
|
|
252
|
-
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_) {
|
|
253
213
|
// Don't show the decimal point for inputs that must be round numbers
|
|
254
|
-
button.setAttribute(
|
|
255
|
-
} else if (buttonText ==
|
|
256
|
-
continue
|
|
257
|
-
} else if (buttonText ==
|
|
258
|
-
continue
|
|
259
|
-
} else if (buttonText ==
|
|
260
|
-
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')
|
|
261
221
|
}
|
|
262
|
-
contentDiv.appendChild(button)
|
|
222
|
+
contentDiv.appendChild(button)
|
|
263
223
|
}
|
|
264
224
|
// Add erase button to the end
|
|
265
|
-
const eraseButton = document.createElement(
|
|
266
|
-
eraseButton.setAttribute(
|
|
267
|
-
eraseButton.setAttribute(
|
|
225
|
+
const eraseButton = document.createElement('button')
|
|
226
|
+
eraseButton.setAttribute('role', 'menuitem')
|
|
227
|
+
eraseButton.setAttribute('class', 'blocklyNumPadButton')
|
|
268
228
|
eraseButton.setAttribute(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
eraseImage.src = ScratchFieldNumber.NUMPAD_DELETE_ICON;
|
|
281
|
-
eraseButton.appendChild(eraseImage);
|
|
282
|
-
|
|
283
|
-
Blockly.browserEvents.bind(
|
|
284
|
-
eraseButton,
|
|
285
|
-
"mousedown",
|
|
286
|
-
null,
|
|
287
|
-
this.numPadEraseButtonTouch.bind(this)
|
|
288
|
-
);
|
|
289
|
-
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)
|
|
290
240
|
}
|
|
291
241
|
|
|
292
242
|
/**
|
|
293
243
|
* Call for when a num-pad number or punctuation button is touched.
|
|
294
244
|
* Determine what the user is inputting and update the text field appropriately.
|
|
295
|
-
*
|
|
296
245
|
* @param e DOM event triggering the touch.
|
|
297
246
|
*/
|
|
298
247
|
numPadButtonTouch(e: PointerEvent) {
|
|
299
248
|
// String of the button (e.g., '7')
|
|
300
|
-
const spliceValue = (e.target as HTMLElement).innerText
|
|
249
|
+
const spliceValue = (e.target as HTMLElement).innerText
|
|
301
250
|
// Old value of the text field
|
|
302
|
-
const oldValue = this.htmlInput_!.value
|
|
251
|
+
const oldValue = this.htmlInput_!.value
|
|
303
252
|
// Determine the selected portion of the text field
|
|
304
|
-
const selectionStart = this.htmlInput_!.selectionStart ?? 0
|
|
305
|
-
const selectionEnd = this.htmlInput_!.selectionEnd ?? 0
|
|
253
|
+
const selectionStart = this.htmlInput_!.selectionStart ?? 0
|
|
254
|
+
const selectionEnd = this.htmlInput_!.selectionEnd ?? 0
|
|
306
255
|
|
|
307
256
|
// Splice in the new value
|
|
308
|
-
const newValue =
|
|
309
|
-
oldValue.slice(0, selectionStart) +
|
|
310
|
-
spliceValue +
|
|
311
|
-
oldValue.slice(selectionEnd);
|
|
257
|
+
const newValue = oldValue.slice(0, selectionStart) + spliceValue + oldValue.slice(selectionEnd)
|
|
312
258
|
|
|
313
259
|
// Set new value and advance the cursor
|
|
314
|
-
this.updateDisplay_(newValue, selectionStart + spliceValue.length)
|
|
260
|
+
this.updateDisplay_(newValue, selectionStart + spliceValue.length)
|
|
315
261
|
|
|
316
262
|
// This is just a click.
|
|
317
|
-
Blockly.Touch.clearTouchIdentifier()
|
|
263
|
+
Blockly.Touch.clearTouchIdentifier()
|
|
318
264
|
|
|
319
265
|
// Prevent default to not lose input focus
|
|
320
|
-
e.preventDefault()
|
|
266
|
+
e.preventDefault()
|
|
321
267
|
}
|
|
322
268
|
|
|
323
269
|
/**
|
|
324
270
|
* Call for when the num-pad erase button is touched.
|
|
325
271
|
* Determine what the user is asking to erase, and erase it.
|
|
326
|
-
*
|
|
327
272
|
* @param e DOM event triggering the touch.
|
|
328
273
|
*/
|
|
329
274
|
numPadEraseButtonTouch(e: PointerEvent) {
|
|
330
275
|
// Old value of the text field
|
|
331
|
-
const oldValue = this.htmlInput_!.value
|
|
276
|
+
const oldValue = this.htmlInput_!.value
|
|
332
277
|
// Determine what is selected to erase (if anything)
|
|
333
|
-
let selectionStart = this.htmlInput_!.selectionStart ?? 0
|
|
334
|
-
const selectionEnd = this.htmlInput_!.selectionEnd ?? 0
|
|
278
|
+
let selectionStart = this.htmlInput_!.selectionStart ?? 0
|
|
279
|
+
const selectionEnd = this.htmlInput_!.selectionEnd ?? 0
|
|
335
280
|
|
|
336
281
|
// If selection is zero-length, shift start to the left 1 character
|
|
337
282
|
if (selectionStart == selectionEnd) {
|
|
338
|
-
selectionStart = Math.max(0, selectionStart - 1)
|
|
283
|
+
selectionStart = Math.max(0, selectionStart - 1)
|
|
339
284
|
}
|
|
340
285
|
|
|
341
286
|
// Cut out selected range
|
|
342
|
-
const newValue =
|
|
343
|
-
oldValue.slice(0, selectionStart) + oldValue.slice(selectionEnd);
|
|
287
|
+
const newValue = oldValue.slice(0, selectionStart) + oldValue.slice(selectionEnd)
|
|
344
288
|
|
|
345
|
-
this.updateDisplay_(newValue, selectionStart)
|
|
289
|
+
this.updateDisplay_(newValue, selectionStart)
|
|
346
290
|
|
|
347
291
|
// This is just a click.
|
|
348
|
-
Blockly.Touch.clearTouchIdentifier()
|
|
292
|
+
Blockly.Touch.clearTouchIdentifier()
|
|
349
293
|
|
|
350
294
|
// Prevent default to not lose input focus which resets cursors in Chrome
|
|
351
|
-
e.preventDefault()
|
|
295
|
+
e.preventDefault()
|
|
352
296
|
}
|
|
353
297
|
|
|
354
298
|
/**
|
|
355
299
|
* Update the displayed value and resize/scroll the text field as needed.
|
|
356
|
-
*
|
|
357
300
|
* @param newValue The new text to display.
|
|
358
301
|
* @param newSelection The new index to put the cursor
|
|
359
302
|
*/
|
|
360
303
|
private updateDisplay_(newValue: string, newSelection: number) {
|
|
361
|
-
this.setEditorValue_(newValue)
|
|
304
|
+
this.setEditorValue_(newValue)
|
|
362
305
|
// Resize and scroll the text field appropriately
|
|
363
|
-
const htmlInput = this.htmlInput_
|
|
364
|
-
htmlInput.setSelectionRange(newSelection, newSelection)
|
|
365
|
-
htmlInput.scrollLeft = htmlInput.scrollWidth
|
|
306
|
+
const htmlInput = this.htmlInput_!
|
|
307
|
+
htmlInput.setSelectionRange(newSelection, newSelection)
|
|
308
|
+
htmlInput.scrollLeft = htmlInput.scrollWidth
|
|
366
309
|
}
|
|
367
310
|
|
|
368
311
|
/**
|
|
@@ -370,17 +313,17 @@ class ScratchFieldNumber extends Blockly.FieldTextInput {
|
|
|
370
313
|
*/
|
|
371
314
|
onHide_() {
|
|
372
315
|
// Clear accessibility properties
|
|
373
|
-
Blockly.DropDownDiv.getContentDiv().removeAttribute(
|
|
374
|
-
Blockly.DropDownDiv.getContentDiv().removeAttribute(
|
|
316
|
+
Blockly.DropDownDiv.getContentDiv().removeAttribute('role')
|
|
317
|
+
Blockly.DropDownDiv.getContentDiv().removeAttribute('aria-haspopup')
|
|
375
318
|
}
|
|
376
319
|
}
|
|
377
320
|
|
|
378
|
-
ScratchFieldNumber.prototype.DEFAULT_VALUE =
|
|
321
|
+
ScratchFieldNumber.prototype.DEFAULT_VALUE = ''
|
|
379
322
|
|
|
380
323
|
/**
|
|
381
324
|
* Register the field and any dependencies.
|
|
382
325
|
*/
|
|
383
326
|
export function registerScratchFieldNumber() {
|
|
384
|
-
Blockly.fieldRegistry.unregister(
|
|
385
|
-
Blockly.fieldRegistry.register(
|
|
327
|
+
Blockly.fieldRegistry.unregister('field_number')
|
|
328
|
+
Blockly.fieldRegistry.register('field_number', ScratchFieldNumber)
|
|
386
329
|
}
|