mirror of
https://github.com/google/blockly.git
synced 2025-12-16 14:20:10 +01:00
* feat: Add interfaces for keyboard navigation. * feat: Add the Navigator. * feat: Make core types conform to INavigable. * feat: Require FlyoutItems elements to be INavigable. * feat: Add navigation policies for built-in types. * refactor: Convert Marker and LineCursor to operate on INavigables instead of ASTNodes. * chore: Delete dead code in ASTNode. * fix: Fix the tests. * chore: Assuage the linter. * fix: Fix advanced build/tests. * chore: Restore ASTNode tests. * refactor: Move isNavigable() validation into Navigator. * refactor: Exercise navigation instead of ASTNode. * chore: Rename astnode_test.js to navigation_test.js. * chore: Enable the navigation tests. * fix: Fix bug when retrieving the first child of an empty workspace.
77 lines
2.0 KiB
TypeScript
77 lines
2.0 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2024 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import {FlyoutButton} from './flyout_button.js';
|
|
import {FlyoutItem} from './flyout_item.js';
|
|
import type {IFlyout} from './interfaces/i_flyout.js';
|
|
import type {IFlyoutInflater} from './interfaces/i_flyout_inflater.js';
|
|
import * as registry from './registry.js';
|
|
import {ButtonOrLabelInfo} from './utils/toolbox.js';
|
|
|
|
const BUTTON_TYPE = 'button';
|
|
|
|
/**
|
|
* Class responsible for creating buttons for flyouts.
|
|
*/
|
|
export class ButtonFlyoutInflater implements IFlyoutInflater {
|
|
/**
|
|
* Inflates a flyout button from the given state and adds it to the flyout.
|
|
*
|
|
* @param state A JSON representation of a flyout button.
|
|
* @param flyout The flyout to create the button on.
|
|
* @returns A newly created FlyoutButton.
|
|
*/
|
|
load(state: object, flyout: IFlyout): FlyoutItem {
|
|
const button = new FlyoutButton(
|
|
flyout.getWorkspace(),
|
|
flyout.targetWorkspace!,
|
|
state as ButtonOrLabelInfo,
|
|
false,
|
|
);
|
|
button.show();
|
|
|
|
return new FlyoutItem(button, BUTTON_TYPE);
|
|
}
|
|
|
|
/**
|
|
* Returns the amount of space that should follow this button.
|
|
*
|
|
* @param state A JSON representation of a flyout button.
|
|
* @param defaultGap The default spacing for flyout items.
|
|
* @returns The amount of space that should follow this button.
|
|
*/
|
|
gapForItem(state: object, defaultGap: number): number {
|
|
return defaultGap;
|
|
}
|
|
|
|
/**
|
|
* Disposes of the given button.
|
|
*
|
|
* @param item The flyout button to dispose of.
|
|
*/
|
|
disposeItem(item: FlyoutItem): void {
|
|
const element = item.getElement();
|
|
if (element instanceof FlyoutButton) {
|
|
element.dispose();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the type of items this inflater is responsible for creating.
|
|
*
|
|
* @returns An identifier for the type of items this inflater creates.
|
|
*/
|
|
getType() {
|
|
return BUTTON_TYPE;
|
|
}
|
|
}
|
|
|
|
registry.register(
|
|
registry.Type.FLYOUT_INFLATER,
|
|
BUTTON_TYPE,
|
|
ButtonFlyoutInflater,
|
|
);
|