import { IEventEmitter } from '@breadstone/mosaik-elements'; import { KeyboardController } from '../../../../Controllers/KeyboardController'; import type { IItemsChangedEventDetail, ISelectionChangedEventDetail } from '../../../../events'; import { CustomElement } from '../../../Abstracts/CustomElement'; import type { IConnectedCallback } from '../../../Abstracts/Interfaces/IConnectedCallback'; import type { IDisconnectedCallback } from '../../../Abstracts/Interfaces/IDisconnectedCallback'; import type { ISelectorElementProps } from './ISelectorElementProps'; import type { SelectorItemElement } from './SelectorItemElement'; /** * Selector - An abstract foundation for single-item selection behavior with comprehensive keyboard navigation. * * @description * The SelectorElement provides the core functionality for components that support single-item * selection from a collection of child elements. This abstract base class manages selection state, * keyboard navigation (Home/End keys, next/previous selection), slot-based item discovery, and * reactive selection change notifications. It is designed to be extended by concrete implementations * such as dropdowns, listboxes, radio groups, tab panels, menu lists, or any component requiring * single-selection patterns. The element automatically tracks slotted child items, maintains * selected index and item references, and provides a comprehensive API for programmatic selection * control with full accessibility support. * * @name Selector * @category Selectors * * @slot - Default slot for selector item elements * * @fires selectionChanged {SelectionChangedEvent} - Fired when the selected item changes, providing both old and new selected items * @fires itemsChanged {ItemsChangedEvent} - Fired when the slotted items collection changes (items added, removed, or reordered) * @fires changed {PropertyChangedEvent} - Fired when any property changes * @fires connected {ConnectedEvent} - Fired when the element is connected to the DOM * * @keyhandle Home - Selects the first item in the collection * @keyhandle End - Selects the last item in the collection * * @example * Extending for a custom dropdown: * ```typescript * class DropdownElement extends SelectorElement { * protected override onSelectionChanged(oldIndex: number, newIndex: number): void { * super.onSelectionChanged(oldIndex, newIndex); * this.displayText = this.selectedItem?.displayText || ''; * this.close(); * } * } * ``` * * @example * Programmatic selection control: * ```typescript * const selector = document.querySelector('my-selector'); * selector.select(0); // Select by index * selector.select('option-1'); // Select by value * selector.selectNext(); // Move to next item * selector.selectPrevious(); // Move to previous item * selector.selectFirst(); // Jump to first item * selector.selectLast(); // Jump to last item * selector.resetSelection(); // Clear selection * ``` * * @example * Listening to selection changes: * ```typescript * const selector = document.querySelector('my-selector'); * selector.addEventListener('selectionChanged', (event) => { * const { oldValue, newValue } = event.detail; * console.log('Selection changed from', oldValue, 'to', newValue); * console.log('Selected index:', selector.selectedIndex); * console.log('Selected item:', selector.selectedItem); * }); * ``` * * @example * Using with slotted items: * ```html * * Option One * Option Two * Option Three * * ``` * * @public * @abstract */ export declare abstract class SelectorElement extends CustomElement implements IConnectedCallback, IDisconnectedCallback, ISelectorElementProps { private readonly _keyboardController; private readonly _itemsChanged; private readonly _selectionChanged; private _selectedItem; private _selectedIndex; private _slotChangeSubscription; /** * @public */ constructor(); /** * Returns the `is` property. * The `is` property represents natural name of this element. * * @public * @static * @readonly */ static get is(): string; /** * Gets or sets the `items` property. * * @private * @readonly */ get items(): Array; /** * Gets a value that indicates whether the selector contains items. * * @private * @readonly */ get hasItems(): boolean; /** * Gets the first item in the current selection or returns null if the selection is empty. * * @private * @readonly */ get selectedItem(): TItem | null; protected set selectedItem(value: TItem | null); /** * Gets the index of the first item in the current selection or returns -1 if the selection is empty. * * @private * @readonly */ get selectedIndex(): number; protected set selectedIndex(value: number); /** * Called when the selection has changed. * Provides reference to `ISelectionChangedEventDetail` as event detail. * * @public * @readonly * @eventProperty */ get selectionChanged(): IEventEmitter>; /** * Called when the items has changed. * Provides reference to `IItemsChangedEventDetail` as event detail. * * @public * @readonly * @eventProperty */ get itemsChanged(): IEventEmitter; /** * @protected * @readonly */ protected get keyboard(): KeyboardController; /** * @public * @override */ connectedCallback(): void; /** * @public * @override */ disconnectedCallback(): void; /** * Select the item. * * @public * @param item - The element, index or value to select. */ select(item: string | number | TItem): void; /** * Deselect the item. * * @public * @param item - The element or index to deselect. */ deselect(item: TItem | number): void; /** * Resets the current selection. * * @public */ resetSelection(): void; /** * Select the next item after current selected item/index. * * @public */ selectNext(): void; /** * Select the previous item before current selected item/index. * * @public */ selectPrevious(): void; /** * Select the first item. * * @public */ selectFirst(): void; /** * Select the last item. * * @public */ selectLast(): void; /** * @protected * @override */ protected onApplyTemplate(): void; /** * @protected * @virtual */ protected onSelectionChanged(oldIndex: number, newIndex: number, cb?: (prev: TItem | null | undefined, next: TItem | null | undefined) => void): void; /** * @protected * @virtual */ protected onItemsChanged(): void; } /** * @public */ declare global { } //# sourceMappingURL=SelectorElement.d.ts.map