blockly 9.1.1 → 9.2.1

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.
Files changed (121) hide show
  1. package/blockly.min.js +395 -347
  2. package/blockly_compressed.js +392 -344
  3. package/blockly_compressed.js.map +1 -1
  4. package/blocks_compressed.js +3 -3
  5. package/blocks_compressed.js.map +1 -1
  6. package/core/any_aliases.d.ts +1 -1
  7. package/core/block.d.ts +3 -1
  8. package/core/block_dragger.d.ts +3 -3
  9. package/core/block_svg.d.ts +2 -2
  10. package/core/blockly.d.ts +21 -26
  11. package/core/blockly_options.d.ts +1 -0
  12. package/core/blocks.d.ts +2 -2
  13. package/core/browser_events.d.ts +2 -4
  14. package/core/bubble.d.ts +8 -8
  15. package/core/bubble_dragger.d.ts +3 -3
  16. package/core/component_manager.d.ts +1 -1
  17. package/core/contextmenu_registry.d.ts +5 -5
  18. package/core/dropdowndiv.d.ts +8 -4
  19. package/core/events/events.d.ts +21 -1
  20. package/core/events/events_abstract.d.ts +14 -1
  21. package/core/events/events_block_base.d.ts +12 -1
  22. package/core/events/events_block_change.d.ts +11 -0
  23. package/core/events/events_block_create.d.ts +11 -0
  24. package/core/events/events_block_delete.d.ts +11 -0
  25. package/core/events/events_block_drag.d.ts +11 -0
  26. package/core/events/events_block_move.d.ts +14 -0
  27. package/core/events/events_bubble_open.d.ts +11 -0
  28. package/core/events/events_click.d.ts +11 -0
  29. package/core/events/events_comment_base.d.ts +11 -0
  30. package/core/events/events_comment_change.d.ts +11 -0
  31. package/core/events/events_comment_create.d.ts +11 -0
  32. package/core/events/events_comment_delete.d.ts +21 -1
  33. package/core/events/events_comment_move.d.ts +11 -0
  34. package/core/events/events_marker_move.d.ts +11 -0
  35. package/core/events/events_procedure_base.d.ts +26 -0
  36. package/core/events/events_procedure_change_return.d.ts +40 -0
  37. package/core/events/events_procedure_create.d.ts +34 -0
  38. package/core/events/events_procedure_delete.d.ts +32 -0
  39. package/core/events/events_procedure_enable.d.ts +34 -0
  40. package/core/events/events_procedure_parameter_base.d.ts +26 -0
  41. package/core/events/events_procedure_parameter_create.d.ts +42 -0
  42. package/core/events/events_procedure_parameter_delete.d.ts +41 -0
  43. package/core/events/events_procedure_parameter_rename.d.ts +36 -0
  44. package/core/events/events_procedure_rename.d.ts +35 -0
  45. package/core/events/events_selected.d.ts +11 -0
  46. package/core/events/events_theme_change.d.ts +11 -0
  47. package/core/events/events_toolbox_item_select.d.ts +11 -0
  48. package/core/events/events_trashcan_open.d.ts +11 -0
  49. package/core/events/events_var_base.d.ts +11 -0
  50. package/core/events/events_var_create.d.ts +11 -0
  51. package/core/events/events_var_delete.d.ts +11 -0
  52. package/core/events/events_var_rename.d.ts +11 -0
  53. package/core/events/events_viewport.d.ts +11 -0
  54. package/core/events/utils.d.ts +17 -1
  55. package/core/field.d.ts +20 -9
  56. package/core/field_angle.d.ts +6 -6
  57. package/core/field_checkbox.d.ts +4 -3
  58. package/core/field_colour.d.ts +4 -3
  59. package/core/field_dropdown.d.ts +7 -6
  60. package/core/field_image.d.ts +2 -2
  61. package/core/field_input.d.ts +229 -0
  62. package/core/field_label.d.ts +2 -2
  63. package/core/field_label_serializable.d.ts +1 -1
  64. package/core/field_multilineinput.d.ts +3 -2
  65. package/core/field_number.d.ts +7 -4
  66. package/core/field_registry.d.ts +8 -5
  67. package/core/field_textinput.d.ts +6 -201
  68. package/core/field_variable.d.ts +3 -2
  69. package/core/flyout_base.d.ts +3 -4
  70. package/core/flyout_button.d.ts +1 -1
  71. package/core/gesture.d.ts +127 -50
  72. package/core/icon.d.ts +4 -4
  73. package/core/input.d.ts +8 -7
  74. package/core/insertion_marker_manager.d.ts +80 -63
  75. package/core/interfaces/i_copyable.d.ts +1 -1
  76. package/core/interfaces/i_observable.d.ts +21 -0
  77. package/core/interfaces/i_parameter_model.d.ts +3 -5
  78. package/core/keyboard_nav/ast_node.d.ts +1 -1
  79. package/core/metrics_manager.d.ts +5 -5
  80. package/core/mutator.d.ts +1 -1
  81. package/core/names.d.ts +1 -1
  82. package/core/options.d.ts +5 -4
  83. package/core/procedures/observable_parameter_model.d.ts +17 -0
  84. package/core/procedures/observable_procedure_map.d.ts +1 -1
  85. package/core/procedures/observable_procedure_model.d.ts +13 -0
  86. package/core/procedures.d.ts +1 -1
  87. package/core/registry.d.ts +1 -1
  88. package/core/rendered_connection.d.ts +1 -1
  89. package/core/renderers/common/constants.d.ts +3 -3
  90. package/core/serialization/procedures.d.ts +26 -2
  91. package/core/shortcut_registry.d.ts +1 -1
  92. package/core/theme.d.ts +4 -4
  93. package/core/theme_manager.d.ts +1 -1
  94. package/core/toolbox/category.d.ts +1 -1
  95. package/core/toolbox/collapsible_category.d.ts +1 -1
  96. package/core/toolbox/separator.d.ts +1 -1
  97. package/core/toolbox/toolbox.d.ts +1 -1
  98. package/core/tooltip.d.ts +2 -2
  99. package/core/touch.d.ts +12 -17
  100. package/core/utils/toolbox.d.ts +7 -7
  101. package/core/utils/xml.d.ts +44 -2
  102. package/core/workspace_comment_svg.d.ts +18 -17
  103. package/core/workspace_svg.d.ts +13 -15
  104. package/core.js +3 -6
  105. package/msg/bs.js +12 -12
  106. package/msg/de.js +6 -6
  107. package/msg/diq.js +6 -6
  108. package/msg/es.js +15 -15
  109. package/msg/fr.js +2 -2
  110. package/msg/he.js +1 -1
  111. package/msg/hy.js +43 -43
  112. package/msg/is.js +17 -17
  113. package/msg/ja.js +1 -1
  114. package/msg/ko.js +3 -3
  115. package/msg/nb.js +1 -1
  116. package/msg/oc.js +2 -2
  117. package/msg/smn.js +24 -24
  118. package/msg/zh-hant.js +10 -10
  119. package/package.json +7 -6
  120. package/core/interfaces/i_registrable_field.d.ts +0 -19
  121. package/core/touch_gesture.d.ts +0 -130
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type { VariableModel } from '../variable_model.js';
7
7
  import { VarBase, VarBaseJson } from './events_var_base.js';
8
+ import type { Workspace } from '../workspace.js';
8
9
  /**
9
10
  * Class for a variable deletion event.
10
11
  *
@@ -30,6 +31,16 @@ export declare class VarDelete extends VarBase {
30
31
  * @param json JSON representation.
31
32
  */
32
33
  fromJson(json: VarDeleteJson): void;
34
+ /**
35
+ * Deserializes the JSON event.
36
+ *
37
+ * @param event The event to append new properties to. Should be a subclass
38
+ * of VarDelete, but we can't specify that due to the fact that parameters
39
+ * to static methods in subclasses must be supertypes of parameters to
40
+ * static methods in superclasses.
41
+ * @internal
42
+ */
43
+ static fromJson(json: VarDeleteJson, workspace: Workspace, event?: any): VarDelete;
33
44
  /**
34
45
  * Run a variable deletion event.
35
46
  *
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type { VariableModel } from '../variable_model.js';
7
7
  import { VarBase, VarBaseJson } from './events_var_base.js';
8
+ import type { Workspace } from '../workspace.js';
8
9
  /**
9
10
  * Class for a variable rename event.
10
11
  *
@@ -31,6 +32,16 @@ export declare class VarRename extends VarBase {
31
32
  * @param json JSON representation.
32
33
  */
33
34
  fromJson(json: VarRenameJson): void;
35
+ /**
36
+ * Deserializes the JSON event.
37
+ *
38
+ * @param event The event to append new properties to. Should be a subclass
39
+ * of VarRename, but we can't specify that due to the fact that parameters
40
+ * to static methods in subclasses must be supertypes of parameters to
41
+ * static methods in superclasses.
42
+ * @internal
43
+ */
44
+ static fromJson(json: VarRenameJson, workspace: Workspace, event?: any): VarRename;
34
45
  /**
35
46
  * Run a variable rename event.
36
47
  *
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { AbstractEventJson } from './events_abstract.js';
7
7
  import { UiBase } from './events_ui_base.js';
8
+ import type { Workspace } from '../workspace.js';
8
9
  /**
9
10
  * Class for a viewport change event.
10
11
  *
@@ -40,6 +41,16 @@ export declare class ViewportChange extends UiBase {
40
41
  * @param json JSON representation.
41
42
  */
42
43
  fromJson(json: ViewportChangeJson): void;
44
+ /**
45
+ * Deserializes the JSON event.
46
+ *
47
+ * @param event The event to append new properties to. Should be a subclass
48
+ * of Viewport, but we can't specify that due to the fact that parameters
49
+ * to static methods in subclasses must be supertypes of parameters to
50
+ * static methods in superclasses.
51
+ * @internal
52
+ */
53
+ static fromJson(json: ViewportChangeJson, workspace: Workspace, event?: any): ViewportChange;
43
54
  }
44
55
  export interface ViewportChangeJson extends AbstractEventJson {
45
56
  viewTop: number;
@@ -180,6 +180,22 @@ export declare const COMMENT_MOVE = "comment_move";
180
180
  * @alias Blockly.Events.utils.FINISHED_LOADING
181
181
  */
182
182
  export declare const FINISHED_LOADING = "finished_loading";
183
+ /** Name of event that creates a procedure model. */
184
+ export declare const PROCEDURE_CREATE = "procedure_create";
185
+ /** Name of event that deletes a procedure model. */
186
+ export declare const PROCEDURE_DELETE = "procedure_delete";
187
+ /** Name of event that renames a procedure model. */
188
+ export declare const PROCEDURE_RENAME = "procedure_rename";
189
+ /** Name of event that enables/disables a procedure model. */
190
+ export declare const PROCEDURE_ENABLE = "procedure_enable";
191
+ /** Name of event that changes the returntype of a procedure model. */
192
+ export declare const PROCEDURE_CHANGE_RETURN = "procedure_change_return";
193
+ /** Name of event that creates a procedure parameter. */
194
+ export declare const PROCEDURE_PARAMETER_CREATE = "procedure_parameter_create";
195
+ /** Name of event that deletes a procedure parameter. */
196
+ export declare const PROCEDURE_PARAMETER_DELETE = "procedure_parameter_delete";
197
+ /** Name of event that renames a procedure parameter. */
198
+ export declare const PROCEDURE_PARAMETER_RENAME = "procedure_parameter_rename";
183
199
  /**
184
200
  * Type of events that cause objects to be bumped back into the visible
185
201
  * portion of the workspace.
@@ -189,7 +205,7 @@ export declare const FINISHED_LOADING = "finished_loading";
189
205
  *
190
206
  * @alias Blockly.Events.utils.BumpEvent
191
207
  */
192
- export declare type BumpEvent = BlockCreate | BlockMove | CommentCreate | CommentMove;
208
+ export type BumpEvent = BlockCreate | BlockMove | CommentCreate | CommentMove;
193
209
  /**
194
210
  * List of events that cause objects to be bumped back into the visible
195
211
  * portion of the workspace.
package/core/field.d.ts CHANGED
@@ -17,12 +17,23 @@ import type { Coordinate } from './utils/coordinate.js';
17
17
  import { Rect } from './utils/rect.js';
18
18
  import { Sentinel } from './utils/sentinel.js';
19
19
  import { Size } from './utils/size.js';
20
+ export type FieldValidator<T = any> = (value?: T) => T | null | undefined;
20
21
  /**
21
22
  * Abstract class for an editable field.
22
23
  *
23
24
  * @alias Blockly.Field
24
25
  */
25
- export declare abstract class Field implements IASTNodeLocationSvg, IASTNodeLocationWithBlock, IKeyboardAccessible, IRegistrable {
26
+ export declare abstract class Field<T = any> implements IASTNodeLocationSvg, IASTNodeLocationWithBlock, IKeyboardAccessible, IRegistrable {
27
+ /**
28
+ * To overwrite the default value which is set in **Field**, directly update
29
+ * the prototype.
30
+ *
31
+ * Example:
32
+ * ```typescript
33
+ * FieldImage.prototype.DEFAULT_VALUE = null;
34
+ * ```
35
+ */
36
+ DEFAULT_VALUE: T | null;
26
37
  /** Non-breaking space. */
27
38
  static readonly NBSP = "\u00A0";
28
39
  /**
@@ -36,9 +47,9 @@ export declare abstract class Field implements IASTNodeLocationSvg, IASTNodeLoca
36
47
  * Static labels are usually unnamed.
37
48
  */
38
49
  name?: string;
39
- protected value_: any;
50
+ protected value_: T | null;
40
51
  /** Validation function called when user edits an editable field. */
41
- protected validator_: Function | null;
52
+ protected validator_: FieldValidator<T> | null;
42
53
  /**
43
54
  * Used to cache the field's tooltip value if setTooltip is called when the
44
55
  * field is not yet initialized. Is *not* guaranteed to be accurate.
@@ -124,7 +135,7 @@ export declare abstract class Field implements IASTNodeLocationSvg, IASTNodeLoca
124
135
  * Refer to the individual field's documentation for a list of properties
125
136
  * this parameter supports.
126
137
  */
127
- constructor(value: any, opt_validator?: Function | null, opt_config?: FieldConfig);
138
+ constructor(value: T | Sentinel, opt_validator?: FieldValidator<T> | null, opt_config?: FieldConfig);
128
139
  /**
129
140
  * Process the configuration map passed to the field.
130
141
  *
@@ -319,7 +330,7 @@ export declare abstract class Field implements IASTNodeLocationSvg, IASTNodeLoca
319
330
  * @param handler The validator function or null to clear a previous
320
331
  * validator.
321
332
  */
322
- setValidator(handler: Function): void;
333
+ setValidator(handler: FieldValidator<T>): void;
323
334
  /**
324
335
  * Gets the validation function for editable fields, or null if not set.
325
336
  *
@@ -509,11 +520,11 @@ export declare abstract class Field implements IASTNodeLocationSvg, IASTNodeLoca
509
520
  */
510
521
  protected doValueInvalid_(_invalidValue: any): void;
511
522
  /**
512
- * Handle a mouse down event on a field.
523
+ * Handle a pointerdown event on a field.
513
524
  *
514
- * @param e Mouse down event.
525
+ * @param e Pointer down event.
515
526
  */
516
- protected onMouseDown_(e: Event): void;
527
+ protected onMouseDown_(e: PointerEvent): void;
517
528
  /**
518
529
  * Sets the tooltip for this field.
519
530
  *
@@ -614,7 +625,7 @@ export interface FieldConfig {
614
625
  * For use by Field and descendants of Field. Constructors can change
615
626
  * in descendants, though they should contain all of Field's prototype methods.
616
627
  */
617
- export declare type FieldProto = Pick<typeof Field, 'prototype'>;
628
+ export type FieldProto = Pick<typeof Field, 'prototype'>;
618
629
  /**
619
630
  * Represents an error where the field is trying to access its block or
620
631
  * information about its block before it has actually been attached to said
@@ -3,15 +3,15 @@
3
3
  * Copyright 2013 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { FieldTextInputConfig, FieldTextInput } from './field_textinput.js';
6
+ import { FieldInput, FieldInputConfig, FieldInputValidator } from './field_input.js';
7
7
  import type { Sentinel } from './utils/sentinel.js';
8
+ export type FieldAngleValidator = FieldInputValidator<number>;
8
9
  /**
9
10
  * Class for an editable angle field.
10
11
  *
11
12
  * @alias Blockly.FieldAngle
12
13
  */
13
- export declare class FieldAngle extends FieldTextInput {
14
- /** The default value for this field. */
14
+ export declare class FieldAngle extends FieldInput<number> {
15
15
  /**
16
16
  * The default amount to round angles to when using a mouse or keyboard nav
17
17
  * input. Must be a positive integer to support keyboard navigation.
@@ -89,7 +89,7 @@ export declare class FieldAngle extends FieldTextInput {
89
89
  * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/angle#creation}
90
90
  * for a list of properties this parameter supports.
91
91
  */
92
- constructor(opt_value?: string | number | Sentinel, opt_validator?: Function, opt_config?: FieldAngleConfig);
92
+ constructor(opt_value?: string | number | Sentinel, opt_validator?: FieldAngleValidator, opt_config?: FieldAngleConfig);
93
93
  /**
94
94
  * Configure the field based on the given map of options.
95
95
  *
@@ -122,7 +122,7 @@ export declare class FieldAngle extends FieldTextInput {
122
122
  *
123
123
  * @param e Mouse move event.
124
124
  */
125
- protected onMouseMove_(e: Event): void;
125
+ protected onMouseMove_(e: PointerEvent): void;
126
126
  /**
127
127
  * Handles and displays values that are input via mouse or arrow key input.
128
128
  * These values need to be rounded and wrapped before being displayed so
@@ -184,7 +184,7 @@ export declare enum Mode {
184
184
  /**
185
185
  * Extra configuration options for the angle field.
186
186
  */
187
- export interface FieldAngleConfig extends FieldTextInputConfig {
187
+ export interface FieldAngleConfig extends FieldInputConfig {
188
188
  mode?: Mode;
189
189
  clockwise?: boolean;
190
190
  offset?: number;
@@ -4,14 +4,15 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import './events/events_block_change.js';
7
- import { FieldConfig, Field } from './field.js';
7
+ import { Field, FieldConfig, FieldValidator } from './field.js';
8
8
  import type { Sentinel } from './utils/sentinel.js';
9
+ export type FieldCheckboxValidator = FieldValidator<boolean>;
9
10
  /**
10
11
  * Class for a checkbox field.
11
12
  *
12
13
  * @alias Blockly.FieldCheckbox
13
14
  */
14
- export declare class FieldCheckbox extends Field {
15
+ export declare class FieldCheckbox extends Field<boolean> {
15
16
  /** Default character for the checkmark. */
16
17
  static readonly CHECK_CHAR = "\u2713";
17
18
  private checkChar_;
@@ -39,7 +40,7 @@ export declare class FieldCheckbox extends Field {
39
40
  * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation}
40
41
  * for a list of properties this parameter supports.
41
42
  */
42
- constructor(opt_value?: string | boolean | Sentinel, opt_validator?: Function, opt_config?: FieldCheckboxConfig);
43
+ constructor(opt_value?: string | boolean | Sentinel, opt_validator?: FieldCheckboxValidator, opt_config?: FieldCheckboxConfig);
43
44
  /**
44
45
  * Configure the field based on the given map of options.
45
46
  *
@@ -4,14 +4,15 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import './events/events_block_change.js';
7
- import { FieldConfig, Field } from './field.js';
7
+ import { Field, FieldConfig, FieldValidator } from './field.js';
8
8
  import type { Sentinel } from './utils/sentinel.js';
9
+ export type FieldColourValidator = FieldValidator<string>;
9
10
  /**
10
11
  * Class for a colour input field.
11
12
  *
12
13
  * @alias Blockly.FieldColour
13
14
  */
14
- export declare class FieldColour extends Field {
15
+ export declare class FieldColour extends Field<string> {
15
16
  /**
16
17
  * An array of colour strings for the palette.
17
18
  * Copied from goog.ui.ColorPicker.SIMPLE_GRID_COLORS
@@ -85,7 +86,7 @@ export declare class FieldColour extends Field {
85
86
  * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour}
86
87
  * for a list of properties this parameter supports.
87
88
  */
88
- constructor(opt_value?: string | Sentinel, opt_validator?: Function, opt_config?: FieldColourConfig);
89
+ constructor(opt_value?: string | Sentinel, opt_validator?: FieldColourValidator, opt_config?: FieldColourConfig);
89
90
  /**
90
91
  * Configure the field based on the given map of options.
91
92
  *
@@ -3,16 +3,17 @@
3
3
  * Copyright 2012 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { FieldConfig, Field } from './field.js';
6
+ import { Field, FieldConfig, FieldValidator } from './field.js';
7
7
  import { Menu } from './menu.js';
8
8
  import { MenuItem } from './menuitem.js';
9
9
  import type { Sentinel } from './utils/sentinel.js';
10
+ export type FieldDropdownValidator = FieldValidator<string>;
10
11
  /**
11
12
  * Class for an editable dropdown field.
12
13
  *
13
14
  * @alias Blockly.FieldDropdown
14
15
  */
15
- export declare class FieldDropdown extends Field {
16
+ export declare class FieldDropdown extends Field<string> {
16
17
  /** Horizontal distance that a checkmark overhangs the dropdown. */
17
18
  static CHECKMARK_OVERHANG: number;
18
19
  /**
@@ -73,7 +74,7 @@ export declare class FieldDropdown extends Field {
73
74
  * for a list of properties this parameter supports.
74
75
  * @throws {TypeError} If `menuGenerator` options are incorrectly structured.
75
76
  */
76
- constructor(menuGenerator: MenuGenerator, opt_validator?: Function, opt_config?: FieldConfig);
77
+ constructor(menuGenerator: MenuGenerator, opt_validator?: FieldDropdownValidator, opt_config?: FieldConfig);
77
78
  constructor(menuGenerator: Sentinel);
78
79
  /**
79
80
  * Sets the field's value based on the given XML element. Should only be
@@ -217,17 +218,17 @@ export interface ImageProperties {
217
218
  * readable value (text or image), and the second element is the language-
218
219
  * neutral value.
219
220
  */
220
- export declare type MenuOption = [string | ImageProperties, string];
221
+ export type MenuOption = [string | ImageProperties, string];
221
222
  /**
222
223
  * A function that generates an array of menu options for FieldDropdown
223
224
  * or its descendants.
224
225
  */
225
- export declare type MenuGeneratorFunction = (this: FieldDropdown) => MenuOption[];
226
+ export type MenuGeneratorFunction = (this: FieldDropdown) => MenuOption[];
226
227
  /**
227
228
  * Either an array of menu options or a function that generates an array of
228
229
  * menu options for FieldDropdown or its descendants.
229
230
  */
230
- export declare type MenuGenerator = MenuOption[] | MenuGeneratorFunction;
231
+ export type MenuGenerator = MenuOption[] | MenuGeneratorFunction;
231
232
  /**
232
233
  * fromJson config for the dropdown field.
233
234
  */
@@ -3,7 +3,7 @@
3
3
  * Copyright 2012 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { FieldConfig, Field } from './field.js';
6
+ import { Field, FieldConfig } from './field.js';
7
7
  import type { Sentinel } from './utils/sentinel.js';
8
8
  import { Size } from './utils/size.js';
9
9
  /**
@@ -11,7 +11,7 @@ import { Size } from './utils/size.js';
11
11
  *
12
12
  * @alias Blockly.FieldImage
13
13
  */
14
- export declare class FieldImage extends Field {
14
+ export declare class FieldImage extends Field<string> {
15
15
  /**
16
16
  * Vertical padding below the image, which is included in the reported height
17
17
  * of the field.
@@ -0,0 +1,229 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2012 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import './events/events_block_change.js';
7
+ import { Field, FieldConfig, FieldValidator } from './field.js';
8
+ import type { Sentinel } from './utils/sentinel.js';
9
+ import type { WorkspaceSvg } from './workspace_svg.js';
10
+ export type InputTypes = string | number;
11
+ export type FieldInputValidator<T extends InputTypes> = FieldValidator<T>;
12
+ /**
13
+ * Class for an editable text field.
14
+ *
15
+ * @alias Blockly.FieldInput
16
+ */
17
+ export declare abstract class FieldInput<T extends InputTypes> extends Field<T> {
18
+ /**
19
+ * Pixel size of input border radius.
20
+ * Should match blocklyText's border-radius in CSS.
21
+ */
22
+ static BORDERRADIUS: number;
23
+ /** Allow browser to spellcheck this field. */
24
+ protected spellcheck_: boolean;
25
+ /** The HTML input element. */
26
+ protected htmlInput_: HTMLInputElement | null;
27
+ /** True if the field's value is currently being edited via the UI. */
28
+ protected isBeingEdited_: boolean;
29
+ /**
30
+ * True if the value currently displayed in the field's editory UI is valid.
31
+ */
32
+ protected isTextValid_: boolean;
33
+ /** Key down event data. */
34
+ private onKeyDownWrapper_;
35
+ /** Key input event data. */
36
+ private onKeyInputWrapper_;
37
+ /**
38
+ * Whether the field should consider the whole parent block to be its click
39
+ * target.
40
+ */
41
+ fullBlockClickTarget_: boolean | null;
42
+ /** The workspace that this field belongs to. */
43
+ protected workspace_: WorkspaceSvg | null;
44
+ /**
45
+ * Serializable fields are saved by the serializer, non-serializable fields
46
+ * are not. Editable fields should also be serializable.
47
+ */
48
+ SERIALIZABLE: boolean;
49
+ /** Mouse cursor style when over the hotspot that initiates the editor. */
50
+ CURSOR: string;
51
+ clickTarget_: any;
52
+ value_: any;
53
+ isDirty_: any;
54
+ /**
55
+ * @param opt_value The initial value of the field. Should cast to a string.
56
+ * Defaults to an empty string if null or undefined. Also accepts
57
+ * Field.SKIP_SETUP if you wish to skip setup (only used by subclasses
58
+ * that want to handle configuration and setting the field value after
59
+ * their own constructors have run).
60
+ * @param opt_validator A function that is called to validate changes to the
61
+ * field's value. Takes in a string & returns a validated string, or null
62
+ * to abort the change.
63
+ * @param opt_config A map of options used to configure the field.
64
+ * See the [field creation documentation]{@link
65
+ * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation}
66
+ * for a list of properties this parameter supports.
67
+ */
68
+ constructor(opt_value?: string | Sentinel, opt_validator?: FieldInputValidator<T> | null, opt_config?: FieldInputConfig);
69
+ protected configure_(config: FieldInputConfig): void;
70
+ /** @internal */
71
+ initView(): void;
72
+ /**
73
+ * Ensure that the input value casts to a valid string.
74
+ *
75
+ * @param opt_newValue The input value.
76
+ * @returns A valid string, or null if invalid.
77
+ */
78
+ protected doClassValidation_(opt_newValue?: any): any;
79
+ /**
80
+ * Called by setValue if the text input is not valid. If the field is
81
+ * currently being edited it reverts value of the field to the previous
82
+ * value while allowing the display text to be handled by the htmlInput_.
83
+ *
84
+ * @param _invalidValue The input value that was determined to be invalid.
85
+ * This is not used by the text input because its display value is stored
86
+ * on the htmlInput_.
87
+ */
88
+ protected doValueInvalid_(_invalidValue: any): void;
89
+ /**
90
+ * Called by setValue if the text input is valid. Updates the value of the
91
+ * field, and updates the text of the field if it is not currently being
92
+ * edited (i.e. handled by the htmlInput_).
93
+ *
94
+ * @param newValue The value to be saved. The default validator guarantees
95
+ * that this is a string.
96
+ */
97
+ protected doValueUpdate_(newValue: any): void;
98
+ /**
99
+ * Updates text field to match the colour/style of the block.
100
+ *
101
+ * @internal
102
+ */
103
+ applyColour(): void;
104
+ /**
105
+ * Updates the colour of the htmlInput given the current validity of the
106
+ * field's value.
107
+ */
108
+ protected render_(): void;
109
+ /**
110
+ * Set whether this field is spellchecked by the browser.
111
+ *
112
+ * @param check True if checked.
113
+ */
114
+ setSpellcheck(check: boolean): void;
115
+ /**
116
+ * Show an editor for the field.
117
+ * Shows the inline free-text editor on top of the text by default.
118
+ * Shows a prompt editor for mobile browsers if the modalInputs option is
119
+ * enabled.
120
+ *
121
+ * @param _opt_e Optional mouse event that triggered the field to open, or
122
+ * undefined if triggered programmatically.
123
+ * @param opt_quietInput True if editor should be created without focus.
124
+ * Defaults to false.
125
+ */
126
+ protected showEditor_(_opt_e?: Event, opt_quietInput?: boolean): void;
127
+ /**
128
+ * Create and show a text input editor that is a prompt (usually a popup).
129
+ * Mobile browsers may have issues with in-line textareas (focus and
130
+ * keyboards).
131
+ */
132
+ private showPromptEditor_;
133
+ /**
134
+ * Create and show a text input editor that sits directly over the text input.
135
+ *
136
+ * @param quietInput True if editor should be created without focus.
137
+ */
138
+ private showInlineEditor_;
139
+ /**
140
+ * Create the text input editor widget.
141
+ *
142
+ * @returns The newly created text input editor.
143
+ */
144
+ protected widgetCreate_(): HTMLElement;
145
+ /**
146
+ * Closes the editor, saves the results, and disposes of any events or
147
+ * DOM-references belonging to the editor.
148
+ */
149
+ protected widgetDispose_(): void;
150
+ /**
151
+ * A callback triggered when the user is done editing the field via the UI.
152
+ *
153
+ * @param _value The new value of the field.
154
+ */
155
+ onFinishEditing_(_value: any): void;
156
+ /**
157
+ * Bind handlers for user input on the text input field's editor.
158
+ *
159
+ * @param htmlInput The htmlInput to which event handlers will be bound.
160
+ */
161
+ protected bindInputEvents_(htmlInput: HTMLElement): void;
162
+ /** Unbind handlers for user input and workspace size changes. */
163
+ protected unbindInputEvents_(): void;
164
+ /**
165
+ * Handle key down to the editor.
166
+ *
167
+ * @param e Keyboard event.
168
+ */
169
+ protected onHtmlInputKeyDown_(e: Event): void;
170
+ /**
171
+ * Handle a change to the editor.
172
+ *
173
+ * @param _e Keyboard event.
174
+ */
175
+ private onHtmlInputChange_;
176
+ /**
177
+ * Set the HTML input value and the field's internal value. The difference
178
+ * between this and `setValue` is that this also updates the HTML input
179
+ * value whilst editing.
180
+ *
181
+ * @param newValue New value.
182
+ */
183
+ protected setEditorValue_(newValue: any): void;
184
+ /** Resize the editor to fit the text. */
185
+ protected resizeEditor_(): void;
186
+ /**
187
+ * Returns whether or not the field is tab navigable.
188
+ *
189
+ * @returns True if the field is tab navigable.
190
+ */
191
+ isTabNavigable(): boolean;
192
+ /**
193
+ * Use the `getText_` developer hook to override the field's text
194
+ * representation. When we're currently editing, return the current HTML value
195
+ * instead. Otherwise, return null which tells the field to use the default
196
+ * behaviour (which is a string cast of the field's value).
197
+ *
198
+ * @returns The HTML value if we're editing, otherwise null.
199
+ */
200
+ protected getText_(): string | null;
201
+ /**
202
+ * Transform the provided value into a text to show in the HTML input.
203
+ * Override this method if the field's HTML input representation is different
204
+ * than the field's value. This should be coupled with an override of
205
+ * `getValueFromEditorText_`.
206
+ *
207
+ * @param value The value stored in this field.
208
+ * @returns The text to show on the HTML input.
209
+ */
210
+ protected getEditorText_(value: any): string;
211
+ /**
212
+ * Transform the text received from the HTML input into a value to store
213
+ * in this field.
214
+ * Override this method if the field's HTML input representation is different
215
+ * than the field's value. This should be coupled with an override of
216
+ * `getEditorText_`.
217
+ *
218
+ * @param text Text received from the HTML input.
219
+ * @returns The value to store.
220
+ */
221
+ protected getValueFromEditorText_(text: string): any;
222
+ }
223
+ /**
224
+ * Config options for the input field.
225
+ */
226
+ export interface FieldInputConfig extends FieldConfig {
227
+ spellcheck?: boolean;
228
+ }
229
+ //# sourceMappingURL=field_input.d.ts.map
@@ -3,14 +3,14 @@
3
3
  * Copyright 2012 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { FieldConfig, Field } from './field.js';
6
+ import { Field, FieldConfig } from './field.js';
7
7
  import type { Sentinel } from './utils/sentinel.js';
8
8
  /**
9
9
  * Class for a non-editable, non-serializable text field.
10
10
  *
11
11
  * @alias Blockly.FieldLabel
12
12
  */
13
- export declare class FieldLabel extends Field {
13
+ export declare class FieldLabel extends Field<string> {
14
14
  /** The html class name to use for this field. */
15
15
  private class_;
16
16
  /**
@@ -3,7 +3,7 @@
3
3
  * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { FieldLabelConfig, FieldLabelFromJsonConfig, FieldLabel } from './field_label.js';
6
+ import { FieldLabel, FieldLabelConfig, FieldLabelFromJsonConfig } from './field_label.js';
7
7
  /**
8
8
  * Class for a non-editable, serializable text field.
9
9
  *
@@ -3,8 +3,9 @@
3
3
  * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { FieldTextInputConfig, FieldTextInput } from './field_textinput.js';
6
+ import { FieldTextInput, FieldTextInputConfig, FieldTextInputValidator } from './field_textinput.js';
7
7
  import type { Sentinel } from './utils/sentinel.js';
8
+ export type FieldMultilineInputValidator = FieldTextInputValidator;
8
9
  /**
9
10
  * Class for an editable text area field.
10
11
  *
@@ -38,7 +39,7 @@ export declare class FieldMultilineInput extends FieldTextInput {
38
39
  * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation}
39
40
  * for a list of properties this parameter supports.
40
41
  */
41
- constructor(opt_value?: string | Sentinel, opt_validator?: Function, opt_config?: FieldMultilineInputConfig);
42
+ constructor(opt_value?: string | Sentinel, opt_validator?: FieldMultilineInputValidator, opt_config?: FieldMultilineInputConfig);
42
43
  protected configure_(config: FieldMultilineInputConfig): void;
43
44
  /**
44
45
  * Serializes this field's value to XML. Should only be called by Blockly.Xml.