blockly 11.2.0-beta.0 → 11.2.0-beta.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.
@@ -42,6 +42,7 @@ export declare class TextInputBubble extends Bubble {
42
42
  private readonly DEFAULT_SIZE;
43
43
  /** The minimum size of this bubble, including borders. */
44
44
  private readonly MIN_SIZE;
45
+ private editable;
45
46
  /**
46
47
  * @param workspace The workspace this bubble belongs to.
47
48
  * @param anchor The anchor location of the thing this bubble is attached to.
@@ -54,6 +55,10 @@ export declare class TextInputBubble extends Bubble {
54
55
  getText(): string;
55
56
  /** Sets the text of this bubble. Calls change listeners. */
56
57
  setText(text: string): void;
58
+ /** Sets whether or not the text in the bubble is editable. */
59
+ setEditable(editable: boolean): void;
60
+ /** Returns whether or not the text in the bubble is editable. */
61
+ isEditable(): boolean;
57
62
  /** Adds a change listener to be notified when this bubble's text changes. */
58
63
  addTextChangeListener(listener: () => void): void;
59
64
  /** Adds a change listener to be notified when this bubble's size changes. */
@@ -102,11 +102,11 @@ export declare class Connection implements IASTNodeLocationWithBlock {
102
102
  * Called when an attempted connection fails. NOP by default (i.e. for
103
103
  * headless workspaces).
104
104
  *
105
- * @param _otherConnection Connection that this connection failed to connect
106
- * to.
105
+ * @param _superiorConnection Connection that this connection failed to connect
106
+ * to. The provided connection should be the superior connection.
107
107
  * @internal
108
108
  */
109
- onFailedConnect(_otherConnection: Connection): void;
109
+ onFailedConnect(_superiorConnection: Connection): void;
110
110
  /**
111
111
  * Connect this connection to another connection.
112
112
  *
@@ -54,6 +54,13 @@ export declare class FieldDropdown extends Field<string> {
54
54
  suffixField: string | null;
55
55
  private selectedOption;
56
56
  clickTarget_: SVGElement | null;
57
+ /**
58
+ * The y offset from the top of the field to the top of the image, if an image
59
+ * is selected.
60
+ */
61
+ protected static IMAGE_Y_OFFSET: number;
62
+ /** The total vertical padding above and below an image. */
63
+ protected static IMAGE_Y_PADDING: number;
57
64
  /**
58
65
  * @param menuGenerator A non-empty array of options for a dropdown list, or a
59
66
  * function which generates these options. Also accepts Field.SKIP_SETUP
@@ -196,6 +203,33 @@ export declare class FieldDropdown extends Field<string> {
196
203
  * @internal
197
204
  */
198
205
  static fromJson(options: FieldDropdownFromJsonConfig): FieldDropdown;
206
+ /**
207
+ * Factor out common words in statically defined options.
208
+ * Create prefix and/or suffix labels.
209
+ */
210
+ protected trimOptions(options: MenuOption[]): {
211
+ options: MenuOption[];
212
+ prefix?: string;
213
+ suffix?: string;
214
+ };
215
+ /**
216
+ * Use the calculated prefix and suffix lengths to trim all of the options in
217
+ * the given array.
218
+ *
219
+ * @param options Array of option tuples:
220
+ * (human-readable text or image, language-neutral name).
221
+ * @param prefixLength The length of the common prefix.
222
+ * @param suffixLength The length of the common suffix
223
+ * @returns A new array with all of the option text trimmed.
224
+ */
225
+ private applyTrim;
226
+ /**
227
+ * Validates the data structure to be processed as an options list.
228
+ *
229
+ * @param options The proposed dropdown options.
230
+ * @throws {TypeError} If proposed options are incorrectly structured.
231
+ */
232
+ protected validateOptions(options: MenuOption[]): void;
199
233
  }
200
234
  /**
201
235
  * Definition of a human-readable image dropdown option.
@@ -22,10 +22,8 @@ export declare class CommentIcon extends Icon implements IHasBubble, ISerializab
22
22
  * weight values are rendered farther toward the end of the block.
23
23
  */
24
24
  static readonly WEIGHT = 3;
25
- /** The bubble used to show editable text to the user. */
25
+ /** The bubble used to show comment text to the user. */
26
26
  private textInputBubble;
27
- /** The bubble used to show non-editable text to the user. */
28
- private textBubble;
29
27
  /** The text of this comment. */
30
28
  private text;
31
29
  /** The size of this comment (which is applied to the editable bubble). */
@@ -90,6 +88,7 @@ export declare class CommentIcon extends Icon implements IHasBubble, ISerializab
90
88
  private showEditableBubble;
91
89
  /** Shows the non editable text bubble for this comment. */
92
90
  private showNonEditableBubble;
91
+ protected createBubble(): void;
93
92
  /** Hides any open bubbles owned by this comment. */
94
93
  private hideBubble;
95
94
  /**
@@ -60,10 +60,15 @@ export declare class RenderedConnection extends Connection {
60
60
  * Move the block(s) belonging to the connection to a point where they don't
61
61
  * visually interfere with the specified connection.
62
62
  *
63
- * @param staticConnection The connection to move away from.
63
+ * @param superiorConnection The connection to move away from. The provided
64
+ * connection should be the superior connection and should not be
65
+ * connected to this connection.
66
+ * @param initiatedByThis Whether or not the block group that was manipulated
67
+ * recently causing bump checks is associated with the inferior
68
+ * connection. Defaults to false.
64
69
  * @internal
65
70
  */
66
- bumpAwayFrom(staticConnection: RenderedConnection): void;
71
+ bumpAwayFrom(superiorConnection: RenderedConnection, initiatedByThis?: boolean): void;
67
72
  /**
68
73
  * Change the connection's coordinates.
69
74
  *
@@ -162,11 +167,11 @@ export declare class RenderedConnection extends Connection {
162
167
  * Bumps this connection away from the other connection. Called when an
163
168
  * attempted connection fails.
164
169
  *
165
- * @param otherConnection Connection that this connection failed to connect
166
- * to.
170
+ * @param superiorConnection Connection that this connection failed to connect
171
+ * to. The provided connection should be the superior connection.
167
172
  * @internal
168
173
  */
169
- onFailedConnect(otherConnection: Connection): void;
174
+ onFailedConnect(superiorConnection: Connection): void;
170
175
  /**
171
176
  * Disconnect two blocks that are connected by this connection.
172
177
  *
@@ -30,13 +30,13 @@ export declare class ShortcutRegistry {
30
30
  * Registers a keyboard shortcut.
31
31
  *
32
32
  * @param shortcut The shortcut for this key code.
33
- * @param opt_allowOverrides True to prevent a warning when overriding an
33
+ * @param allowOverrides True to prevent a warning when overriding an
34
34
  * already registered item.
35
35
  * @throws {Error} if a shortcut with the same name already exists.
36
36
  */
37
- register(shortcut: KeyboardShortcut, opt_allowOverrides?: boolean): void;
37
+ register(shortcut: KeyboardShortcut, allowOverrides?: boolean): void;
38
38
  /**
39
- * Unregisters a keyboard shortcut registered with the given key code. This
39
+ * Unregisters a keyboard shortcut registered with the given name. This
40
40
  * will also remove any key mappings that reference this shortcut.
41
41
  *
42
42
  * @param shortcutName The name of the shortcut to unregister.
@@ -46,16 +46,23 @@ export declare class ShortcutRegistry {
46
46
  /**
47
47
  * Adds a mapping between a keycode and a keyboard shortcut.
48
48
  *
49
+ * Normally only one shortcut can be mapped to any given keycode,
50
+ * but setting allowCollisions to true allows a keyboard to be
51
+ * mapped to multiple shortcuts. In that case, when onKeyDown is
52
+ * called with the given keystroke, it will process the mapped
53
+ * shortcuts in reverse order, from the most- to least-recently
54
+ * mapped).
55
+ *
49
56
  * @param keyCode The key code for the keyboard shortcut. If registering a key
50
57
  * code with a modifier (ex: ctrl+c) use
51
58
  * ShortcutRegistry.registry.createSerializedKey;
52
59
  * @param shortcutName The name of the shortcut to execute when the given
53
60
  * keycode is pressed.
54
- * @param opt_allowCollision True to prevent an error when adding a shortcut
61
+ * @param allowCollision True to prevent an error when adding a shortcut
55
62
  * to a key that is already mapped to a shortcut.
56
63
  * @throws {Error} if the given key code is already mapped to a shortcut.
57
64
  */
58
- addKeyMapping(keyCode: string | number | KeyCodes, shortcutName: string, opt_allowCollision?: boolean): void;
65
+ addKeyMapping(keyCode: string | number | KeyCodes, shortcutName: string, allowCollision?: boolean): void;
59
66
  /**
60
67
  * Removes a mapping between a keycode and a keyboard shortcut.
61
68
  *
@@ -64,11 +71,11 @@ export declare class ShortcutRegistry {
64
71
  * ShortcutRegistry.registry.createSerializedKey;
65
72
  * @param shortcutName The name of the shortcut to execute when the given
66
73
  * keycode is pressed.
67
- * @param opt_quiet True to not console warn when there is no shortcut to
74
+ * @param quiet True to not console warn when there is no shortcut to
68
75
  * remove.
69
76
  * @returns True if a key mapping was removed, false otherwise.
70
77
  */
71
- removeKeyMapping(keyCode: string, shortcutName: string, opt_quiet?: boolean): boolean;
78
+ removeKeyMapping(keyCode: string, shortcutName: string, quiet?: boolean): boolean;
72
79
  /**
73
80
  * Removes all the key mappings for a shortcut with the given name.
74
81
  * Useful when changing the default key mappings and the key codes registered
@@ -105,6 +112,21 @@ export declare class ShortcutRegistry {
105
112
  /**
106
113
  * Handles key down events.
107
114
  *
115
+ * - Any `KeyboardShortcut`(s) mapped to the keycodes that cause
116
+ * event `e` to be fired will be processed, in order from least-
117
+ * to most-recently registered.
118
+ * - If the shortcut's `preconditionFn` exists it will be called.
119
+ * If `preconditionFn` returns false the shortcut's `callback`
120
+ * function will be skipped. Processing will continue with the
121
+ * next shortcut, if any.
122
+ * - The shortcut's `callback` function will then be called. If it
123
+ * returns true, processing will terminate and `onKeyDown` will
124
+ * return true. If it returns false, processing will continue
125
+ * with with the next shortcut, if any.
126
+ * - If all registered shortcuts for the given keycode have been
127
+ * processed without any having returned true, `onKeyDown` will
128
+ * return false.
129
+ *
108
130
  * @param workspace The main workspace where the event was captured.
109
131
  * @param e The key down event.
110
132
  * @returns True if the event was handled, false otherwise.
@@ -145,18 +167,56 @@ export declare class ShortcutRegistry {
145
167
  *
146
168
  * @param keyCode Number code representing the key.
147
169
  * @param modifiers List of modifier key codes to be used with the key. All
148
- * valid modifiers can be found in the ShortcutRegistry.modifierKeys.
170
+ * valid modifiers can be found in the `ShortcutRegistry.modifierKeys`.
149
171
  * @returns The serialized key code for the given modifiers and key.
150
172
  */
151
173
  createSerializedKey(keyCode: number, modifiers: KeyCodes[] | null): string;
152
174
  }
153
175
  export declare namespace ShortcutRegistry {
176
+ /** Interface defining a keyboard shortcut. */
154
177
  interface KeyboardShortcut {
155
- callback?: (p1: WorkspaceSvg, p2: Event, p3: KeyboardShortcut) => boolean;
178
+ /**
179
+ * The function to be called when the shorctut is invoked.
180
+ *
181
+ * @param workspace The `WorkspaceSvg` when the shortcut was
182
+ * invoked.
183
+ * @param e The event that caused the shortcut to be activated.
184
+ * @param shortcut The `KeyboardShortcut` that was activated
185
+ * (i.e., the one this callback is attached to).
186
+ * @returns Returning true ends processing of the invoked keycode.
187
+ * Returning false causes processing to continue with the
188
+ * next-most-recently registered shortcut for the invoked
189
+ * keycode.
190
+ */
191
+ callback?: (workspace: WorkspaceSvg, e: Event, shortcut: KeyboardShortcut) => boolean;
192
+ /** The name of the shortcut. Should be unique. */
156
193
  name: string;
157
- preconditionFn?: (p1: WorkspaceSvg) => boolean;
194
+ /**
195
+ * A function to be called when the shortcut is invoked, before
196
+ * calling `callback`, to decide if this shortcut is applicable in
197
+ * the current situation.
198
+ *
199
+ * @param workspace The `WorkspaceSvg` where the shortcut was
200
+ * invoked.
201
+ * @returns True iff `callback` function should be called.
202
+ */
203
+ preconditionFn?: (workspace: WorkspaceSvg) => boolean;
204
+ /** Optional arbitray extra data attached to the shortcut. */
158
205
  metadata?: object;
206
+ /**
207
+ * Optional list of key codes to be bound (via
208
+ * ShortcutRegistry.prototype.addKeyMapping) to this shortcut.
209
+ */
159
210
  keyCodes?: (number | string)[];
211
+ /**
212
+ * Value of `allowCollision` to pass to `addKeyMapping` when
213
+ * binding this shortcut's `.keyCodes` (if any).
214
+ *
215
+ * N.B.: this is only used for binding keycodes at the time this
216
+ * shortcut is initially registered, not for any subsequent
217
+ * `addKeyMapping` calls that happen to reference this shortcut's
218
+ * name.
219
+ */
160
220
  allowCollision?: boolean;
161
221
  }
162
222
  /** Supported modifiers. */
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { WorkspaceSvg } from '../workspace_svg.js';
7
+ import { Coordinate } from './coordinate.js';
8
+ /**
9
+ * Start tracking a drag of an object on this workspace by recording the offset
10
+ * between the pointer's current location and the object's starting location.
11
+ *
12
+ * Used for resizing block comments and workspace comments.
13
+ *
14
+ * @param workspace The workspace where the drag is occurring.
15
+ * @param e Pointer down event.
16
+ * @param xy Starting location of object.
17
+ */
18
+ export declare function start(workspace: WorkspaceSvg, e: PointerEvent, xy: Coordinate): void;
19
+ /**
20
+ * Compute the new position of a dragged object in this workspace based on the
21
+ * current pointer position and the offset between the pointer's starting
22
+ * location and the object's starting location.
23
+ *
24
+ * The start function should have be called previously, when the drag started.
25
+ *
26
+ * Used for resizing block comments and workspace comments.
27
+ *
28
+ * @param workspace The workspace where the drag is occurring.
29
+ * @param e Pointer move event.
30
+ * @returns New location of object.
31
+ */
32
+ export declare function move(workspace: WorkspaceSvg, e: PointerEvent): Coordinate;
33
+ //# sourceMappingURL=drag.d.ts.map
@@ -10,6 +10,7 @@
10
10
  *
11
11
  * @class
12
12
  */
13
+ import { Coordinate } from './coordinate.js';
13
14
  /**
14
15
  * Class for representing rectangular regions.
15
16
  */
@@ -25,7 +26,15 @@ export declare class Rect {
25
26
  * @param right Right.
26
27
  */
27
28
  constructor(top: number, bottom: number, left: number, right: number);
29
+ /**
30
+ * Creates a new copy of this rectangle.
31
+ *
32
+ * @returns A copy of this Rect.
33
+ */
34
+ clone(): Rect;
35
+ /** Returns the height of this rectangle. */
28
36
  getHeight(): number;
37
+ /** Returns the width of this rectangle. */
29
38
  getWidth(): number;
30
39
  /**
31
40
  * Tests whether this rectangle contains a x/y coordinate.
@@ -43,5 +52,22 @@ export declare class Rect {
43
52
  * @returns Whether this rectangle intersects the provided rectangle.
44
53
  */
45
54
  intersects(other: Rect): boolean;
55
+ /**
56
+ * Compares bounding rectangles for equality.
57
+ *
58
+ * @param a A Rect.
59
+ * @param b A Rect.
60
+ * @returns True iff the bounding rectangles are equal, or if both are null.
61
+ */
62
+ static equals(a?: Rect | null, b?: Rect | null): boolean;
63
+ /**
64
+ * Creates a new Rect using a position and supplied dimensions.
65
+ *
66
+ * @param position The upper left coordinate of the new rectangle.
67
+ * @param width The width of the rectangle, in pixels.
68
+ * @param height The height of the rectangle, in pixels.
69
+ * @returns A newly created Rect using the provided Coordinate and dimensions.
70
+ */
71
+ static createFromPoint(position: Coordinate, width: number, height: number): Rect;
46
72
  }
47
73
  //# sourceMappingURL=rect.d.ts.map
@@ -138,8 +138,6 @@ export declare class WorkspaceSvg extends Workspace implements IASTNodeLocationS
138
138
  startScrollX: number;
139
139
  /** Vertical scroll value when scrolling started in pixel units. */
140
140
  startScrollY: number;
141
- /** Distance from mouse to object being dragged. */
142
- private dragDeltaXY;
143
141
  /** Current scale. */
144
142
  scale: number;
145
143
  /** Cached scale value. Used to detect changes in viewport. */
@@ -704,7 +702,7 @@ export declare class WorkspaceSvg extends Workspace implements IASTNodeLocationS
704
702
  * blocks on the workspace.
705
703
  */
706
704
  getBlocksBoundingBox(): Rect;
707
- /** Clean up the workspace by ordering all the blocks in a column. */
705
+ /** Clean up the workspace by ordering all the blocks in a column such that none overlap. */
708
706
  cleanUp(): void;
709
707
  /**
710
708
  * Show the context menu for the workspace.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockly",
3
- "version": "11.2.0-beta.0",
3
+ "version": "11.2.0-beta.1",
4
4
  "description": "Blockly is a library for building visual programming editors.",
5
5
  "keywords": [
6
6
  "blockly"
@@ -78,11 +78,11 @@
78
78
  "@typescript-eslint/parser": "^8.1.0",
79
79
  "async-done": "^2.0.0",
80
80
  "chai": "^5.1.1",
81
- "concurrently": "^8.0.1",
81
+ "concurrently": "^9.0.1",
82
82
  "eslint": "^8.4.1",
83
83
  "eslint-config-google": "^0.14.0",
84
84
  "eslint-config-prettier": "^9.0.0",
85
- "eslint-plugin-jsdoc": "^48.0.2",
85
+ "eslint-plugin-jsdoc": "^50.4.3",
86
86
  "glob": "^10.3.4",
87
87
  "google-closure-compiler": "^20240317.0.0",
88
88
  "gulp": "^5.0.0",
@@ -110,7 +110,7 @@
110
110
  "yargs": "^17.2.1"
111
111
  },
112
112
  "dependencies": {
113
- "jsdom": "25.0.0"
113
+ "jsdom": "25.0.1"
114
114
  },
115
115
  "engines": {
116
116
  "node": ">=18"