@furystack/shades-common-components
Version:
Common UI components for FuryStack Shades
54 lines • 2.16 kB
TypeScript
import { EventHub, ObservableValue, type ListenerErrorPayload } from '@furystack/utils';
export interface CollectionData<T> {
entries: T[];
count: number;
}
export interface CollectionServiceOptions<T> {
/**
* An optional field that can be used for quick search
*/
searchField?: keyof T;
/**
* A field used as a stable identity key for entries.
* When provided, the service automatically reconciles `focusedEntry`,
* `selection`, and the internal SHIFT+click focus anchor after `data`
* changes so that stale object references are swapped for their matching
* counterparts in the new data array. This keeps keyboard navigation and
* selection working correctly when the backing data is rebuilt with new
* object instances.
*/
idField?: keyof T;
}
export declare class CollectionService<T> extends EventHub<{
onRowClick: T;
onRowDoubleClick: T;
onListenerError: ListenerErrorPayload;
}> implements Disposable {
private options;
private dataSubscription?;
[Symbol.dispose](): void;
isSelected: (entry: T) => boolean;
addToSelection: (entry: T) => void;
removeFromSelection: (entry: T) => void;
toggleSelection: (entry: T) => void;
data: ObservableValue<CollectionData<T>>;
focusedEntry: ObservableValue<T | undefined>;
/**
* Stores the focused entry captured on pointerdown, before the focus event
* can update focusedEntry. Used as the anchor for SHIFT+click range selection.
* Call {@link setFocusAnchor} from `onpointerdown` to snapshot the anchor
* before focus shifts.
*/
private focusAnchor;
/** Snapshot the current focused entry as the anchor for SHIFT+click range selection. */
setFocusAnchor(): void;
selection: ObservableValue<T[]>;
searchTerm: ObservableValue<string>;
hasFocus: ObservableValue<boolean>;
handleKeyDown(ev: KeyboardEvent): void;
handleRowClick(entry: T, ev: MouseEvent): void;
private reconcileRefs;
constructor(options?: CollectionServiceOptions<T>);
handleRowDoubleClick(entry: T): void;
}
//# sourceMappingURL=collection-service.d.ts.map