blockly 12.0.0-beta.3 → 12.0.0-beta.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.
@@ -10,7 +10,6 @@
10
10
  */
11
11
  import './events/events_selected.js';
12
12
  import { Block } from './block.js';
13
- import { IDeletable } from './blockly.js';
14
13
  import { BlockCopyData } from './clipboard/block_paster.js';
15
14
  import type { Connection } from './connection.js';
16
15
  import { ConnectionType } from './connection_type.js';
@@ -20,7 +19,9 @@ import { MutatorIcon } from './icons/mutator_icon.js';
20
19
  import type { Input } from './inputs/input.js';
21
20
  import type { IASTNodeLocationSvg } from './interfaces/i_ast_node_location_svg.js';
22
21
  import type { IBoundedElement } from './interfaces/i_bounded_element.js';
22
+ import { IContextMenu } from './interfaces/i_contextmenu.js';
23
23
  import type { ICopyable } from './interfaces/i_copyable.js';
24
+ import { IDeletable } from './interfaces/i_deletable.js';
24
25
  import type { IDragStrategy, IDraggable } from './interfaces/i_draggable.js';
25
26
  import { IIcon } from './interfaces/i_icon.js';
26
27
  import { RenderedConnection } from './rendered_connection.js';
@@ -35,7 +36,7 @@ import type { WorkspaceSvg } from './workspace_svg.js';
35
36
  * Class for a block's SVG representation.
36
37
  * Not normally called directly, workspace.newBlock() is preferred.
37
38
  */
38
- export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBoundedElement, ICopyable<BlockCopyData>, IDraggable, IDeletable {
39
+ export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBoundedElement, IContextMenu, ICopyable<BlockCopyData>, IDraggable, IDeletable {
39
40
  /**
40
41
  * Constant for identifying rows that are to be rendered inline.
41
42
  * Don't collide with Blockly.inputTypes.
@@ -248,14 +249,20 @@ export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBou
248
249
  *
249
250
  * @returns Context menu options or null if no menu.
250
251
  */
251
- protected generateContextMenu(): Array<ContextMenuOption | LegacyContextMenuOption> | null;
252
+ protected generateContextMenu(e: Event): Array<ContextMenuOption | LegacyContextMenuOption> | null;
253
+ /**
254
+ * Gets the location in which to show the context menu for this block.
255
+ * Use the location of a click if the block was clicked, or a location
256
+ * based on the block's fields otherwise.
257
+ */
258
+ protected calculateContextMenuLocation(e: Event): Coordinate;
252
259
  /**
253
260
  * Show the context menu for this block.
254
261
  *
255
262
  * @param e Mouse event.
256
263
  * @internal
257
264
  */
258
- showContextMenu(e: PointerEvent): void;
265
+ showContextMenu(e: Event): void;
259
266
  /**
260
267
  * Updates the locations of any parts of the block that need to know where
261
268
  * they are (e.g. connections, icons).
@@ -705,6 +712,13 @@ export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBou
705
712
  * @internal
706
713
  */
707
714
  highlightShapeForInput(conn: RenderedConnection, add: boolean): void;
715
+ /**
716
+ * Returns the drag strategy currently in use by this block.
717
+ *
718
+ * @internal
719
+ * @returns This block's drag strategy.
720
+ */
721
+ getDragStrategy(): IDragStrategy;
708
722
  /** Sets the drag strategy for this block. */
709
723
  setDragStrategy(dragStrategy: IDragStrategy): void;
710
724
  /** Returns whether this block is movable or not. */
@@ -95,7 +95,7 @@ export declare class RenderedWorkspaceComment extends WorkspaceComment implement
95
95
  */
96
96
  toCopyData(): WorkspaceCommentCopyData | null;
97
97
  /** Show a context menu for this comment. */
98
- showContextMenu(e: PointerEvent): void;
98
+ showContextMenu(e: Event): void;
99
99
  /** Snap this comment to the nearest grid point. */
100
100
  snapToGrid(): void;
101
101
  }
@@ -7,9 +7,12 @@ import type { Block } from './block.js';
7
7
  import type { BlockSvg } from './block_svg.js';
8
8
  import type { ContextMenuOption, LegacyContextMenuOption } from './contextmenu_registry.js';
9
9
  import * as serializationBlocks from './serialization/blocks.js';
10
+ import { Coordinate } from './utils/coordinate.js';
10
11
  import type { WorkspaceSvg } from './workspace_svg.js';
11
12
  /**
12
13
  * Gets the block the context menu is currently attached to.
14
+ * It is not recommended that you use this function; instead,
15
+ * use the scope object passed to the context menu callback.
13
16
  *
14
17
  * @returns The block the context menu is attached to.
15
18
  */
@@ -23,12 +26,13 @@ export declare function setCurrentBlock(block: Block | null): void;
23
26
  /**
24
27
  * Construct the menu based on the list of options and show the menu.
25
28
  *
26
- * @param e Mouse event.
29
+ * @param menuOpenEvent Event that caused the menu to open.
27
30
  * @param options Array of menu options.
28
31
  * @param rtl True if RTL, false if LTR.
29
32
  * @param workspace The workspace associated with the context menu, if any.
33
+ * @param location The screen coordinates at which to show the menu.
30
34
  */
31
- export declare function show(e: PointerEvent, options: (ContextMenuOption | LegacyContextMenuOption)[], rtl: boolean, workspace?: WorkspaceSvg): void;
35
+ export declare function show(menuOpenEvent: Event, options: (ContextMenuOption | LegacyContextMenuOption)[], rtl: boolean, workspace?: WorkspaceSvg, location?: Coordinate): void;
32
36
  /**
33
37
  * Hide the context menu.
34
38
  */
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import type { BlockSvg } from './block_svg.js';
12
12
  import { RenderedWorkspaceComment } from './comments/rendered_workspace_comment.js';
13
+ import { Coordinate } from './utils/coordinate.js';
13
14
  import type { WorkspaceSvg } from './workspace_svg.js';
14
15
  /**
15
16
  * Class for the registry of context menu items. This is intended to be a
@@ -54,7 +55,7 @@ export declare class ContextMenuRegistry {
54
55
  * block being clicked on)
55
56
  * @returns the list of ContextMenuOptions
56
57
  */
57
- getContextMenuOptions(scopeType: ScopeType, scope: Scope): ContextMenuOption[];
58
+ getContextMenuOptions(scopeType: ScopeType, scope: Scope, menuOpenEvent: Event): ContextMenuOption[];
58
59
  }
59
60
  export declare namespace ContextMenuRegistry {
60
61
  /**
@@ -91,12 +92,13 @@ export declare namespace ContextMenuRegistry {
91
92
  /**
92
93
  * @param scope Object that provides a reference to the thing that had its
93
94
  * context menu opened.
94
- * @param e The original event that triggered the context menu to open. Not
95
- * the event that triggered the click on the option.
95
+ * @param menuOpenEvent The original event that triggered the context menu to open.
96
+ * @param menuSelectEvent The event that triggered the option being selected.
97
+ * @param location The location in screen coordinates where the menu was opened.
96
98
  */
97
- callback: (scope: Scope, e: PointerEvent) => void;
99
+ callback: (scope: Scope, menuOpenEvent: Event, menuSelectEvent: Event, location: Coordinate) => void;
98
100
  displayText: ((p1: Scope) => string | HTMLElement) | string | HTMLElement;
99
- preconditionFn: (p1: Scope) => string;
101
+ preconditionFn: (p1: Scope, menuOpenEvent: Event) => string;
100
102
  separator?: never;
101
103
  }
102
104
  /**
@@ -128,10 +130,11 @@ export declare namespace ContextMenuRegistry {
128
130
  /**
129
131
  * @param scope Object that provides a reference to the thing that had its
130
132
  * context menu opened.
131
- * @param e The original event that triggered the context menu to open. Not
132
- * the event that triggered the click on the option.
133
+ * @param menuOpenEvent The original event that triggered the context menu to open.
134
+ * @param menuSelectEvent The event that triggered the option being selected.
135
+ * @param location The location in screen coordinates where the menu was opened.
133
136
  */
134
- callback: (scope: Scope, e: PointerEvent) => void;
137
+ callback: (scope: Scope, menuOpenEvent: Event, menuSelectEvent: Event, location: Coordinate) => void;
135
138
  separator?: never;
136
139
  }
137
140
  /**
@@ -141,7 +141,18 @@ export declare class LineCursor extends Marker {
141
141
  * should be traversed.
142
142
  * @returns The next node in the traversal.
143
143
  */
144
- getNextNode(node: ASTNode | null, isValid: (p1: ASTNode | null) => boolean): ASTNode | null;
144
+ private getNextNodeImpl;
145
+ /**
146
+ * Get the next node in the AST, optionally allowing for loopback.
147
+ *
148
+ * @param node The current position in the AST.
149
+ * @param isValid A function true/false depending on whether the given node
150
+ * should be traversed.
151
+ * @param loop Whether to loop around to the beginning of the workspace if
152
+ * novalid node was found.
153
+ * @returns The next node in the traversal.
154
+ */
155
+ getNextNode(node: ASTNode | null, isValid: (p1: ASTNode | null) => boolean, loop: boolean): ASTNode | null;
145
156
  /**
146
157
  * Reverses the pre order traversal in order to find the previous node. This
147
158
  * will allow a user to easily navigate the entire Blockly AST without having
@@ -153,7 +164,19 @@ export declare class LineCursor extends Marker {
153
164
  * @returns The previous node in the traversal or null if no previous node
154
165
  * exists.
155
166
  */
156
- getPreviousNode(node: ASTNode | null, isValid: (p1: ASTNode | null) => boolean): ASTNode | null;
167
+ private getPreviousNodeImpl;
168
+ /**
169
+ * Get the previous node in the AST, optionally allowing for loopback.
170
+ *
171
+ * @param node The current position in the AST.
172
+ * @param isValid A function true/false depending on whether the given node
173
+ * should be traversed.
174
+ * @param loop Whether to loop around to the end of the workspace if no
175
+ * valid node was found.
176
+ * @returns The previous node in the traversal or null if no previous node
177
+ * exists.
178
+ */
179
+ getPreviousNode(node: ASTNode | null, isValid: (p1: ASTNode | null) => boolean, loop: boolean): ASTNode | null;
157
180
  /**
158
181
  * From the given node find either the next valid sibling or the parent's
159
182
  * next sibling.
@@ -309,5 +332,17 @@ export declare class LineCursor extends Marker {
309
332
  * @param newNode The new node.
310
333
  */
311
334
  private updateSelectionFromNode;
335
+ /**
336
+ * Get the first navigable node on the workspace, or null if none exist.
337
+ *
338
+ * @returns The first navigable node on the workspace, or null.
339
+ */
340
+ getFirstNode(): ASTNode | null;
341
+ /**
342
+ * Get the last navigable node on the workspace, or null if none exist.
343
+ *
344
+ * @returns The last navigable node on the workspace, or null.
345
+ */
346
+ getLastNode(): ASTNode | null;
312
347
  }
313
348
  //# sourceMappingURL=line_cursor.d.ts.map
@@ -120,9 +120,12 @@ export declare class MenuItem {
120
120
  * Performs the appropriate action when the menu item is activated
121
121
  * by the user.
122
122
  *
123
+ * @param menuSelectEvent the event that triggered the selection
124
+ * of the menu item.
125
+ *
123
126
  * @internal
124
127
  */
125
- performAction(): void;
128
+ performAction(menuSelectEvent: Event): void;
126
129
  /**
127
130
  * Set the handler that's called when the menu item is activated by the user.
128
131
  * `obj` will be used as the 'this' object in the function when called.
@@ -131,6 +134,6 @@ export declare class MenuItem {
131
134
  * @param obj Used as the 'this' object in fn when called.
132
135
  * @internal
133
136
  */
134
- onAction(fn: (p1: MenuItem) => void, obj: object): void;
137
+ onAction(fn: (p1: MenuItem, menuSelectEvent: Event) => void, obj: object): void;
135
138
  }
136
139
  //# sourceMappingURL=menuitem.d.ts.map
@@ -22,6 +22,7 @@ import { Gesture } from './gesture.js';
22
22
  import { Grid } from './grid.js';
23
23
  import type { IASTNodeLocationSvg } from './interfaces/i_ast_node_location_svg.js';
24
24
  import type { IBoundedElement } from './interfaces/i_bounded_element.js';
25
+ import { IContextMenu } from './interfaces/i_contextmenu.js';
25
26
  import type { IDragTarget } from './interfaces/i_drag_target.js';
26
27
  import type { IFlyout } from './interfaces/i_flyout.js';
27
28
  import type { IMetricsManager } from './interfaces/i_metrics_manager.js';
@@ -50,7 +51,7 @@ import { ZoomControls } from './zoom_controls.js';
50
51
  * Class for a workspace. This is an onscreen area with optional trashcan,
51
52
  * scrollbars, bubbles, and dragging.
52
53
  */
53
- export declare class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
54
+ export declare class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg, IContextMenu {
54
55
  /**
55
56
  * A wrapper function called when a resize event occurs.
56
57
  * You can pass the result to `eventHandling.unbind`.
@@ -711,7 +712,7 @@ export declare class WorkspaceSvg extends Workspace implements IASTNodeLocationS
711
712
  * @param e Mouse event.
712
713
  * @internal
713
714
  */
714
- showContextMenu(e: PointerEvent): void;
715
+ showContextMenu(e: Event): void;
715
716
  /**
716
717
  * Modify the block tree on the existing toolbox.
717
718
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockly",
3
- "version": "12.0.0-beta.3",
3
+ "version": "12.0.0-beta.4",
4
4
  "description": "Blockly is a library for building visual programming editors.",
5
5
  "keywords": [
6
6
  "blockly"