blockly 12.0.1-beta.1 → 12.1.0

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/core/blockly.d.ts CHANGED
@@ -106,6 +106,7 @@ import { IVariableMap } from './interfaces/i_variable_map.js';
106
106
  import { IVariableModel, IVariableState } from './interfaces/i_variable_model.js';
107
107
  import { LineCursor } from './keyboard_nav/line_cursor.js';
108
108
  import { Marker } from './keyboard_nav/marker.js';
109
+ import { KeyboardNavigationController, keyboardNavigationController } from './keyboard_navigation_controller.js';
109
110
  import type { LayerManager } from './layer_manager.js';
110
111
  import * as layers from './layers.js';
111
112
  import { MarkerManager } from './marker_manager.js';
@@ -281,5 +282,5 @@ export * from './navigator.js';
281
282
  export * from './toast.js';
282
283
  export { Block, BlockSvg, BlocklyOptions, Blocks, CollapsibleToolboxCategory, ComponentManager, Connection, ConnectionChecker, ConnectionDB, ConnectionType, ContextMenu, ContextMenuItems, ContextMenuRegistry, Css, DeleteArea, DragTarget, Events, Extensions, LineCursor, Procedures, ShortcutItems, Themes, Tooltip, Touch, Variables, VariablesDynamic, WidgetDiv, Xml, blockAnimations, blockRendering, browserEvents, bubbles, bumpObjects, clipboard, comments, common, constants, dialog, dragging, fieldRegistry, geras, Procedures as procedures, registry, thrasos, uiPosition, utils, zelos, };
283
284
  export declare const DropDownDiv: typeof dropDownDiv;
284
- export { BlockFlyoutInflater, ButtonFlyoutInflater, CodeGenerator, Field, FieldCheckbox, FieldCheckboxConfig, FieldCheckboxFromJsonConfig, FieldCheckboxValidator, FieldConfig, FieldDropdown, FieldDropdownConfig, FieldDropdownFromJsonConfig, FieldDropdownValidator, FieldImage, FieldImageConfig, FieldImageFromJsonConfig, FieldLabel, FieldLabelConfig, FieldLabelFromJsonConfig, FieldLabelSerializable, FieldNumber, FieldNumberConfig, FieldNumberFromJsonConfig, FieldNumberValidator, FieldTextInput, FieldTextInputConfig, FieldTextInputFromJsonConfig, FieldTextInputValidator, FieldValidator, FieldVariable, FieldVariableConfig, FieldVariableFromJsonConfig, FieldVariableValidator, Flyout, FlyoutButton, FlyoutItem, FlyoutMetricsManager, FlyoutSeparator, FocusManager, FocusableTreeTraverser, CodeGenerator as Generator, Gesture, Grid, HorizontalFlyout, IAutoHideable, IBoundedElement, IBubble, ICollapsibleToolboxItem, IComponent, IConnectionChecker, IConnectionPreviewer, IContextMenu, ICopyData, ICopyable, IDeletable, IDeleteArea, IDragStrategy, IDragTarget, IDraggable, IDragger, IFlyout, IFlyoutInflater, IFocusableNode, IFocusableTree, IHasBubble, IIcon, IKeyboardAccessible, IMetricsManager, IMovable, IObservable, IPaster, IPositionable, IRegistrable, IRenderedElement, ISelectable, ISelectableToolboxItem, ISerializable, IStyleable, IToolbox, IToolboxItem, IVariableBackedParameterModel, IVariableMap, IVariableModel, IVariableState, ImageProperties, Input, InsertionMarkerPreviewer, LabelFlyoutInflater, LayerManager, Marker, MarkerManager, Menu, MenuGenerator, MenuGeneratorFunction, MenuItem, MenuOption, MetricsManager, Msg, Names, Options, RenderedConnection, ReturnEphemeralFocus, Scrollbar, ScrollbarPair, SeparatorFlyoutInflater, ShortcutRegistry, Theme, ThemeManager, Toolbox, ToolboxCategory, ToolboxItem, ToolboxSeparator, Trashcan, UnattachedFieldError, VariableMap, VariableModel, VerticalFlyout, Workspace, WorkspaceAudio, WorkspaceDragger, WorkspaceSvg, ZoomControls, config, getFocusManager, hasBubble, icons, inject, inputs, isCopyable, isDeletable, isDraggable, isIcon, isObservable, isPaster, isRenderedElement, isSelectable, isSerializable, isVariableBackedParameterModel, layers, renderManagement, serialization, setLocale, };
285
+ export { BlockFlyoutInflater, ButtonFlyoutInflater, CodeGenerator, Field, FieldCheckbox, FieldCheckboxConfig, FieldCheckboxFromJsonConfig, FieldCheckboxValidator, FieldConfig, FieldDropdown, FieldDropdownConfig, FieldDropdownFromJsonConfig, FieldDropdownValidator, FieldImage, FieldImageConfig, FieldImageFromJsonConfig, FieldLabel, FieldLabelConfig, FieldLabelFromJsonConfig, FieldLabelSerializable, FieldNumber, FieldNumberConfig, FieldNumberFromJsonConfig, FieldNumberValidator, FieldTextInput, FieldTextInputConfig, FieldTextInputFromJsonConfig, FieldTextInputValidator, FieldValidator, FieldVariable, FieldVariableConfig, FieldVariableFromJsonConfig, FieldVariableValidator, Flyout, FlyoutButton, FlyoutItem, FlyoutMetricsManager, FlyoutSeparator, FocusManager, FocusableTreeTraverser, CodeGenerator as Generator, Gesture, Grid, HorizontalFlyout, IAutoHideable, IBoundedElement, IBubble, ICollapsibleToolboxItem, IComponent, IConnectionChecker, IConnectionPreviewer, IContextMenu, ICopyData, ICopyable, IDeletable, IDeleteArea, IDragStrategy, IDragTarget, IDraggable, IDragger, IFlyout, IFlyoutInflater, IFocusableNode, IFocusableTree, IHasBubble, IIcon, IKeyboardAccessible, IMetricsManager, IMovable, IObservable, IPaster, IPositionable, IRegistrable, IRenderedElement, ISelectable, ISelectableToolboxItem, ISerializable, IStyleable, IToolbox, IToolboxItem, IVariableBackedParameterModel, IVariableMap, IVariableModel, IVariableState, ImageProperties, Input, InsertionMarkerPreviewer, KeyboardNavigationController, LabelFlyoutInflater, LayerManager, Marker, MarkerManager, Menu, MenuGenerator, MenuGeneratorFunction, MenuItem, MenuOption, MetricsManager, Msg, Names, Options, RenderedConnection, ReturnEphemeralFocus, Scrollbar, ScrollbarPair, SeparatorFlyoutInflater, ShortcutRegistry, Theme, ThemeManager, Toolbox, ToolboxCategory, ToolboxItem, ToolboxSeparator, Trashcan, UnattachedFieldError, VariableMap, VariableModel, VerticalFlyout, Workspace, WorkspaceAudio, WorkspaceDragger, WorkspaceSvg, ZoomControls, config, getFocusManager, hasBubble, icons, inject, inputs, isCopyable, isDeletable, isDraggable, isIcon, isObservable, isPaster, isRenderedElement, isSelectable, isSerializable, isVariableBackedParameterModel, keyboardNavigationController, layers, renderManagement, serialization, setLocale, };
285
286
  //# sourceMappingURL=blockly.d.ts.map
@@ -70,8 +70,8 @@ export declare abstract class Bubble implements IBubble, ISelectable {
70
70
  * when automatically positioning.
71
71
  * @param overriddenFocusableElement An optional replacement to the focusable
72
72
  * element that's represented by this bubble (as a focusable node). This
73
- * element will have its ID and tabindex overwritten. If not provided, the
74
- * focusable element of this node will default to the bubble's SVG root.
73
+ * element will have its ID overwritten. If not provided, the focusable
74
+ * element of this node will default to the bubble's SVG root.
75
75
  */
76
76
  constructor(workspace: WorkspaceSvg, anchor: Coordinate, ownerRect?: Rect | undefined, overriddenFocusableElement?: SVGElement | HTMLElement);
77
77
  /** Dispose of this bubble. */
package/core/common.d.ts CHANGED
@@ -148,6 +148,14 @@ export declare function createBlockDefinitionsFromJsonArray(jsonArray: any[]): {
148
148
  export declare function defineBlocks(blocks: {
149
149
  [key: string]: BlockDefinition;
150
150
  }): void;
151
+ /**
152
+ * Handle a key-down on SVG drawing surface. Does nothing if the main workspace
153
+ * is not visible.
154
+ *
155
+ * @internal
156
+ * @param e Key down event.
157
+ */
158
+ export declare function globalShortcutHandler(e: KeyboardEvent): void;
151
159
  export declare const TEST_ONLY: {
152
160
  defineBlocksWithJsonArrayInternal: typeof defineBlocksWithJsonArrayInternal;
153
161
  };
@@ -401,9 +401,17 @@ export declare abstract class Flyout extends DeleteArea implements IAutoHideable
401
401
  * is registered for that type.
402
402
  */
403
403
  protected getInflaterForType(type: string): IFlyoutInflater | null;
404
- /** See IFocusableNode.getFocusableElement. */
404
+ /**
405
+ * See IFocusableNode.getFocusableElement.
406
+ *
407
+ * @deprecated v12: Use the Flyout's workspace for focus operations, instead.
408
+ */
405
409
  getFocusableElement(): HTMLElement | SVGElement;
406
- /** See IFocusableNode.getFocusableTree. */
410
+ /**
411
+ * See IFocusableNode.getFocusableTree.
412
+ *
413
+ * @deprecated v12: Use the Flyout's workspace for focus operations, instead.
414
+ */
407
415
  getFocusableTree(): IFocusableTree;
408
416
  /** See IFocusableNode.onNodeFocus. */
409
417
  onNodeFocus(): void;
@@ -411,17 +419,37 @@ export declare abstract class Flyout extends DeleteArea implements IAutoHideable
411
419
  onNodeBlur(): void;
412
420
  /** See IFocusableNode.canBeFocused. */
413
421
  canBeFocused(): boolean;
414
- /** See IFocusableTree.getRootFocusableNode. */
422
+ /**
423
+ * See IFocusableNode.getRootFocusableNode.
424
+ *
425
+ * @deprecated v12: Use the Flyout's workspace for focus operations, instead.
426
+ */
415
427
  getRootFocusableNode(): IFocusableNode;
416
- /** See IFocusableTree.getRestoredFocusableNode. */
428
+ /**
429
+ * See IFocusableNode.getRestoredFocusableNode.
430
+ *
431
+ * @deprecated v12: Use the Flyout's workspace for focus operations, instead.
432
+ */
417
433
  getRestoredFocusableNode(_previousNode: IFocusableNode | null): IFocusableNode | null;
418
- /** See IFocusableTree.getNestedTrees. */
434
+ /**
435
+ * See IFocusableNode.getNestedTrees.
436
+ *
437
+ * @deprecated v12: Use the Flyout's workspace for focus operations, instead.
438
+ */
419
439
  getNestedTrees(): Array<IFocusableTree>;
420
- /** See IFocusableTree.lookUpFocusableNode. */
440
+ /**
441
+ * See IFocusableNode.lookUpFocusableNode.
442
+ *
443
+ * @deprecated v12: Use the Flyout's workspace for focus operations, instead.
444
+ */
421
445
  lookUpFocusableNode(_id: string): IFocusableNode | null;
422
446
  /** See IFocusableTree.onTreeFocus. */
423
447
  onTreeFocus(_node: IFocusableNode, _previousTree: IFocusableTree | null): void;
424
- /** See IFocusableTree.onTreeBlur. */
425
- onTreeBlur(nextTree: IFocusableTree | null): void;
448
+ /**
449
+ * See IFocusableNode.onTreeBlur.
450
+ *
451
+ * @deprecated v12: Use the Flyout's workspace for focus operations, instead.
452
+ */
453
+ onTreeBlur(_nextTree: IFocusableTree | null): void;
426
454
  }
427
455
  //# sourceMappingURL=flyout_base.d.ts.map
@@ -67,14 +67,30 @@ export declare class FocusManager {
67
67
  * This function throws if the provided tree is already currently registered
68
68
  * in this manager. Use isRegistered to check in cases when it can't be
69
69
  * certain whether the tree has been registered.
70
+ *
71
+ * The tree's registration can be customized to configure automatic tab stops.
72
+ * This specifically provides capability for the user to be able to tab
73
+ * navigate to the root of the tree but only when the tree doesn't hold active
74
+ * focus. If this functionality is disabled then the tree's root will
75
+ * automatically be made focusable (but not tabbable) when it is first focused
76
+ * in the same way as any other focusable node.
77
+ *
78
+ * @param tree The IFocusableTree to register.
79
+ * @param rootShouldBeAutoTabbable Whether the root of this tree should be
80
+ * added as a top-level page tab stop when it doesn't hold active focus.
70
81
  */
71
- registerTree(tree: IFocusableTree): void;
82
+ registerTree(tree: IFocusableTree, rootShouldBeAutoTabbable?: boolean): void;
72
83
  /**
73
84
  * Returns whether the specified tree has already been registered in this
74
85
  * manager using registerTree and hasn't yet been unregistered using
75
86
  * unregisterTree.
76
87
  */
77
88
  isRegistered(tree: IFocusableTree): boolean;
89
+ /**
90
+ * Returns the TreeRegistration for the specified tree, or null if the tree is
91
+ * not currently registered.
92
+ */
93
+ private lookUpRegistration;
78
94
  /**
79
95
  * Unregisters a IFocusableTree from automatic focus management.
80
96
  *
@@ -83,6 +99,9 @@ export declare class FocusManager {
83
99
  *
84
100
  * This function throws if the provided tree is not currently registered in
85
101
  * this manager.
102
+ *
103
+ * This function will reset the tree's root element tabindex if the tree was
104
+ * registered with automatic tab management.
86
105
  */
87
106
  unregisterTree(tree: IFocusableTree): void;
88
107
  /**
@@ -133,6 +152,9 @@ export declare class FocusManager {
133
152
  * canBeFocused() method returns false), it will be ignored and any existing
134
153
  * focus state will remain unchanged.
135
154
  *
155
+ * Note that this may update the specified node's element's tabindex to ensure
156
+ * that it can be properly read out by screenreaders while focused.
157
+ *
136
158
  * @param focusableNode The node that should receive active focus.
137
159
  */
138
160
  focusNode(focusableNode: IFocusableNode): void;
@@ -155,6 +177,10 @@ export declare class FocusManager {
155
177
  * simultaneously will result in an error being thrown).
156
178
  */
157
179
  takeEphemeralFocus(focusableElement: HTMLElement | SVGElement): ReturnEphemeralFocus;
180
+ /**
181
+ * @returns whether something is currently holding ephemeral focus
182
+ */
183
+ ephemeralFocusTaken(): boolean;
158
184
  /**
159
185
  * Ensures that the manager is currently allowing operations that change its
160
186
  * internal focus state (such as via focusNode()).
@@ -17,13 +17,11 @@ export interface IFocusableNode {
17
17
  * - blocklyActiveFocus
18
18
  * - blocklyPassiveFocus
19
19
  *
20
- * The returned element must also have a valid ID specified, and unique across
21
- * the entire page. Failing to have a properly unique ID could result in
22
- * trying to focus one node (such as via a mouse click) leading to another
23
- * node with the same ID actually becoming focused by FocusManager. The
24
- * returned element must also have a negative tabindex (since the focus
25
- * manager itself will manage its tab index and a tab index must be present in
26
- * order for the element to be focusable in the DOM).
20
+ * The returned element must also have a valid ID specified, and this ID
21
+ * should be unique across the entire page. Failing to have a properly unique
22
+ * ID could result in trying to focus one node (such as via a mouse click)
23
+ * leading to another node with the same ID actually becoming focused by
24
+ * FocusManager.
27
25
  *
28
26
  * The returned element must be visible if the node is ever focused via
29
27
  * FocusManager.focusNode() or FocusManager.focusTree(). It's allowed for an
@@ -32,7 +30,11 @@ export interface IFocusableNode {
32
30
  *
33
31
  * It's expected the actual returned element will not change for the lifetime
34
32
  * of the node (that is, its properties can change but a new element should
35
- * never be returned).
33
+ * never be returned). Also, the returned element will have its tabindex
34
+ * overwritten throughout the lifecycle of this node and FocusManager.
35
+ *
36
+ * If a node requires the ability to be focused directly without first being
37
+ * focused via FocusManager then it must set its own tab index.
36
38
  *
37
39
  * @returns The HTMLElement or SVGElement which can both receive focus and be
38
40
  * visually represented as actively or passively focused for this node.
@@ -4,8 +4,11 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { BlockSvg } from '../block_svg.js';
7
+ import type { Field } from '../field.js';
8
+ import type { Icon } from '../icons/icon.js';
7
9
  import type { IFocusableNode } from '../interfaces/i_focusable_node.js';
8
10
  import type { INavigationPolicy } from '../interfaces/i_navigation_policy.js';
11
+ import { RenderedConnection } from '../rendered_connection.js';
9
12
  /**
10
13
  * Set of rules controlling keyboard navigation from a block.
11
14
  */
@@ -56,4 +59,25 @@ export declare class BlockNavigationPolicy implements INavigationPolicy<BlockSvg
56
59
  */
57
60
  isApplicable(current: any): current is BlockSvg;
58
61
  }
62
+ /**
63
+ * Returns the next/previous stack relative to the given block's stack.
64
+ *
65
+ * @param current The block whose stack will be navigated relative to.
66
+ * @param delta The difference in index to navigate; positive values navigate
67
+ * to the nth next stack, while negative values navigate to the nth previous
68
+ * stack.
69
+ * @returns The first block in the stack offset by `delta` relative to the
70
+ * current block's stack, or the last block in the stack offset by `delta`
71
+ * relative to the current block's stack when navigating backwards.
72
+ */
73
+ export declare function navigateStacks(current: BlockSvg, delta: number): BlockSvg | null;
74
+ /**
75
+ * Returns the next navigable item relative to the provided block child.
76
+ *
77
+ * @param current The navigable block child item to navigate relative to.
78
+ * @param delta The difference in index to navigate; positive values navigate
79
+ * forward by n, while negative values navigate backwards by n.
80
+ * @returns The navigable block child offset by `delta` relative to `current`.
81
+ */
82
+ export declare function navigateBlock(current: Icon | Field | RenderedConnection | BlockSvg, delta: number): IFocusableNode | null;
59
83
  //# sourceMappingURL=block_navigation_policy.d.ts.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * The KeyboardNavigationController handles coordinating Blockly-wide
8
+ * keyboard navigation behavior, such as enabling/disabling full
9
+ * cursor visualization.
10
+ */
11
+ export declare class KeyboardNavigationController {
12
+ /** Whether the user is actively using keyboard navigation. */
13
+ private isActive;
14
+ /** Css class name added to body if keyboard nav is active. */
15
+ private activeClassName;
16
+ /**
17
+ * Sets whether a user is actively using keyboard navigation.
18
+ *
19
+ * If they are, apply a css class to the entire page so that
20
+ * focused items can apply additional styling for keyboard users.
21
+ *
22
+ * Note that since enabling keyboard navigation presents significant UX changes
23
+ * (such as cursor visualization and move mode), callers should take care to
24
+ * only set active keyboard navigation when they have a high confidence in that
25
+ * being the correct state. In general, in any given mouse or key input situation
26
+ * callers can choose one of three paths:
27
+ * 1. Do nothing. This should be the choice for neutral actions that don't
28
+ * predominantly imply keyboard or mouse usage (such as clicking to select a block).
29
+ * 2. Disable keyboard navigation. This is the best choice when a user is definitely
30
+ * predominantly using the mouse (such as using a right click to open the context menu).
31
+ * 3. Enable keyboard navigation. This is the best choice when there's high confidence
32
+ * a user actually intends to use it (such as attempting to use the arrow keys to move
33
+ * around).
34
+ *
35
+ * @param isUsing
36
+ */
37
+ setIsActive(isUsing?: boolean): void;
38
+ /**
39
+ * @returns true if the user is actively using keyboard navigation
40
+ * (e.g., has recently taken some action that is only relevant to keyboard users)
41
+ */
42
+ getIsActive(): boolean;
43
+ /** Adds or removes the css class that indicates keyboard navigation is active. */
44
+ private updateActiveVisualization;
45
+ }
46
+ /** Singleton instance of the keyboard navigation controller. */
47
+ export declare const keyboardNavigationController: KeyboardNavigationController;
48
+ //# sourceMappingURL=keyboard_navigation_controller.d.ts.map
@@ -6,7 +6,7 @@
6
6
  import * as browserEvents from '../browser_events.js';
7
7
  import { DeleteArea } from '../delete_area.js';
8
8
  import '../events/events_toolbox_item_select.js';
9
- import type { IAutoHideable } from '../interfaces/i_autohideable.js';
9
+ import { type IAutoHideable } from '../interfaces/i_autohideable.js';
10
10
  import type { IDraggable } from '../interfaces/i_draggable.js';
11
11
  import type { IFlyout } from '../interfaces/i_flyout.js';
12
12
  import type { IFocusableNode } from '../interfaces/i_focusable_node.js';
@@ -412,6 +412,6 @@ export declare class Toolbox extends DeleteArea implements IAutoHideable, IKeybo
412
412
  /** See IFocusableTree.onTreeFocus. */
413
413
  onTreeFocus(node: IFocusableNode, _previousTree: IFocusableTree | null): void;
414
414
  /** See IFocusableTree.onTreeBlur. */
415
- onTreeBlur(_nextTree: IFocusableTree | null): void;
415
+ onTreeBlur(nextTree: IFocusableTree | null): void;
416
416
  }
417
417
  //# sourceMappingURL=toolbox.d.ts.map
package/index.mjs CHANGED
@@ -55,6 +55,7 @@ export const {
55
55
  INPUT_VALUE,
56
56
  Input,
57
57
  InsertionMarkerPreviewer,
58
+ KeyboardNavigationController,
58
59
  LabelFlyoutInflater,
59
60
  LineCursor,
60
61
  Marker,
@@ -144,7 +145,10 @@ export const {
144
145
  isSelectable,
145
146
  isSerializable,
146
147
  isVariableBackedParameterModel,
148
+ keyboardNavigationController,
147
149
  layers,
150
+ navigateBlock,
151
+ navigateStacks,
148
152
  procedures,
149
153
  registry,
150
154
  renderManagement,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockly",
3
- "version": "12.0.1-beta.1",
3
+ "version": "12.1.0",
4
4
  "description": "Blockly is a library for building visual programming editors.",
5
5
  "keywords": [
6
6
  "blockly"