UNPKG

@blockly/field-grid-dropdown

Version:
96 lines 3.29 kB
/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { MenuOption } from 'blockly/core'; import { GridItem } from './grid_item'; /** * Class for managing a group of items displayed in a grid. */ export declare class Grid { private readonly columns; private readonly rtl; /** Mapping from grid item ID to index in the items list. */ private itemIndices; /** List of items displayed in this grid. */ private items; /** Root DOM element of this grid. */ private root; /** Identifier for keydown handler to be unregistered in dispose(). */ private keyDownHandler; /** Identifier for pointermove handler to be unregistered in dispose(). */ private pointerMoveHandler; /** Function to be called when an item in this grid is selected. */ private selectionCallback?; /** * Creates a new Grid instance. * * @param container The parent element of this grid in the DOM. * @param options A list of MenuOption objects representing the items to be * shown in this grid. * @param columns The number of columns to display items in. * @param rtl True if this grid is being shown in a right-to-left environment. * @param selectionCallback Function to be called when an item in the grid is * selected. */ constructor(container: HTMLElement, options: MenuOption[], columns: number, rtl: boolean, selectionCallback: (selectedItem: GridItem) => void); /** * Creates grid items in the DOM given a list of model objects. * * @param options A list of grid item model objects. */ private populateItems; /** * Disposes of this grid. */ dispose(): void; /** * Handles a keydown event in the grid, generally by moving focus. * * @param e The keydown event to handle. */ private onKeyDown; /** * Handles a pointermove event in the grid by focusing the hovered item. * * @param e The pointermove event to handle. */ private onPointerMove; /** * Selects the item with the given value in the grid. * * @param value The value of the grid item to select. */ setSelectedValue(value: string): void; /** * Moves browser focus to the grid item at the given index. * * @param index The index of the item to focus. * @param relative True to interpret the index as relative to the currently * focused item, false to move focus to it as an absolute value. */ private moveFocus; /** * Returns the index of the given item within the grid. * * @param item The item to return the index of. * @returns The index of the given item within the grid. */ private indexOfItem; /** * Returns the GridItem object at the given index in the grid. * * @param index The index to retrieve the grid item at. * @returns The GridItem at the given index, or undefined if the index is * invalid. */ private itemAtIndex; /** * Returns the currently focused grid item, if any. * * @returns The focused grid item, or undefined if no item is focused. */ private getFocusedItem; } //# sourceMappingURL=grid.d.ts.map