File size: 12,704 Bytes
04ec17f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | import { type WritableBoxedValues, type ReadableBoxedValues } from "svelte-toolbelt";
import type { CommandState } from "./types.js";
import type { BitsKeyboardEvent, BitsMouseEvent, BitsPointerEvent, RefAttachment, WithRefOpts } from "../../internal/types.js";
interface GridItem {
index: number;
firstRowOfGroup: boolean;
ref: HTMLElement;
}
type ItemsGrid = GridItem[][];
interface CommandRootStateOpts extends WithRefOpts, ReadableBoxedValues<{
filter: (value: string, search: string, keywords?: string[]) => number;
shouldFilter: boolean;
loop: boolean;
vimBindings: boolean;
columns: number | null;
disablePointerSelection: boolean;
disableInitialScroll: boolean;
onStateChange?: (state: Readonly<CommandState>) => void;
}>, WritableBoxedValues<{
value: string;
}> {
}
export declare class CommandRootState {
#private;
static create(opts: CommandRootStateOpts): CommandRootState;
readonly opts: CommandRootStateOpts;
readonly attachment: RefAttachment;
sortAfterTick: boolean;
sortAndFilterAfterTick: boolean;
allItems: Set<string>;
allGroups: Map<string, Set<string>>;
allIds: Map<string, {
value: string;
keywords?: string[];
}>;
key: number;
viewportNode: HTMLElement | null;
inputNode: HTMLElement | null;
labelNode: HTMLElement | null;
commandState: CommandState;
_commandState: CommandState;
setState<K extends keyof CommandState>(key: K, value: CommandState[K], preventScroll?: boolean): void;
constructor(opts: CommandRootStateOpts);
/**
* Sets current value and triggers re-render if cleared.
*
* @param value - New value to set
*/
setValue(value: string, opts?: boolean): void;
/**
* Gets all non-disabled, visible command items.
*
* @returns Array of valid item elements
* @remarks Exposed for direct item access and bound checking
*/
getValidItems(): HTMLElement[];
/**
* Gets all visible command items.
*
* @returns Array of valid item elements
* @remarks Exposed for direct item access and bound checking
*/
getVisibleItems(): HTMLElement[];
/** Returns all visible items in a matrix structure
*
* @remarks Returns empty if the command isn't configured as a grid
*
* @returns
*/
get itemsGrid(): ItemsGrid;
/**
* Sets selection to item at specified index in valid items array.
* If index is out of bounds, does nothing.
*
* @param index - Zero-based index of item to select
* @remarks
* Uses `getValidItems()` to get selectable items, filtering out disabled/hidden ones.
* Access valid items directly via `getValidItems()` to check bounds before calling.
*
* @example
* // get valid items length for bounds check
* const items = getValidItems()
* if (index < items.length) {
* updateSelectedToIndex(index)
* }
*/
updateSelectedToIndex(index: number): void;
/**
* Updates selected item by moving up/down relative to current selection.
* Handles wrapping when loop option is enabled.
*
* @param change - Direction to move: 1 for next item, -1 for previous item
* @remarks
* The loop behavior wraps:
* - From last item to first when moving next
* - From first item to last when moving previous
*
* Uses `getValidItems()` to get all selectable items, which filters out disabled/hidden items.
* You can call `getValidItems()` directly to get the current valid items array.
*
* @example
* // select next item
* updateSelectedByItem(1)
*
* // get all valid items
* const items = getValidItems()
*/
updateSelectedByItem(change: number): void;
/**
* Moves selection to the first valid item in the next/previous group.
* If no group is found, falls back to selecting the next/previous item globally.
*
* @param change - Direction to move: 1 for next group, -1 for previous group
* @example
* // move to first item in next group
* updateSelectedByGroup(1)
*
* // move to first item in previous group
* updateSelectedByGroup(-1)
*/
updateSelectedByGroup(change: 1 | -1): void;
/**
* Maps item id to display value and search keywords.
* Returns cleanup function to remove mapping.
*
* @param id - Unique item identifier
* @param value - Display text
* @param keywords - Optional search boost terms
* @returns Cleanup function
*/
registerValue(value: string, keywords?: string[]): () => void;
/**
* Registers item in command list and its group.
* Handles filtering, sorting and selection updates.
*
* @param id - Item identifier
* @param groupId - Optional group to add item to
* @returns Cleanup function that handles selection
*/
registerItem(id: string, groupId: string | undefined): () => void;
/**
* Creates empty group if not exists.
*
* @param id - Group identifier
* @returns Cleanup function
*/
registerGroup(id: string): () => void;
get isGrid(): boolean;
onkeydown(e: BitsKeyboardEvent): void;
props: {
readonly id: string;
readonly role: "application";
readonly tabindex: -1;
readonly onkeydown: (e: BitsKeyboardEvent) => void;
};
}
interface CommandEmptyStateOpts extends WithRefOpts, ReadableBoxedValues<{
forceMount: boolean;
}> {
}
export declare class CommandEmptyState {
#private;
static create(opts: CommandEmptyStateOpts): CommandEmptyState;
readonly opts: CommandEmptyStateOpts;
readonly root: CommandRootState;
readonly attachment: RefAttachment;
readonly shouldRender: boolean;
constructor(opts: CommandEmptyStateOpts, root: CommandRootState);
readonly props: {
readonly id: string;
readonly role: "presentation";
};
}
interface CommandGroupContainerStateOpts extends WithRefOpts, ReadableBoxedValues<{
value: string;
forceMount: boolean;
}> {
}
export declare class CommandGroupContainerState {
static create(opts: CommandGroupContainerStateOpts): CommandGroupContainerState;
readonly opts: CommandGroupContainerStateOpts;
readonly root: CommandRootState;
readonly attachment: RefAttachment;
readonly shouldRender: boolean;
headingNode: HTMLElement | null;
trueValue: string;
constructor(opts: CommandGroupContainerStateOpts, root: CommandRootState);
readonly props: {
readonly id: string;
readonly role: "presentation";
readonly hidden: true | undefined;
readonly "data-value": string;
};
}
interface CommandGroupHeadingStateOpts extends WithRefOpts {
}
export declare class CommandGroupHeadingState {
static create(opts: CommandGroupHeadingStateOpts): CommandGroupHeadingState;
readonly opts: CommandGroupHeadingStateOpts;
readonly group: CommandGroupContainerState;
readonly attachment: RefAttachment;
constructor(opts: CommandGroupHeadingStateOpts, group: CommandGroupContainerState);
readonly props: {
readonly id: string;
};
}
interface CommandGroupItemsStateOpts extends WithRefOpts {
}
export declare class CommandGroupItemsState {
static create(opts: CommandGroupItemsStateOpts): CommandGroupItemsState;
readonly opts: CommandGroupItemsStateOpts;
readonly group: CommandGroupContainerState;
readonly attachment: RefAttachment;
constructor(opts: CommandGroupItemsStateOpts, group: CommandGroupContainerState);
readonly props: {
readonly id: string;
readonly role: "group";
readonly "aria-labelledby": string | undefined;
};
}
interface CommandInputStateOpts extends WithRefOpts, WritableBoxedValues<{
value: string;
}>, ReadableBoxedValues<{
autofocus: boolean;
}> {
}
export declare class CommandInputState {
#private;
static create(opts: CommandInputStateOpts): CommandInputState;
readonly opts: CommandInputStateOpts;
readonly root: CommandRootState;
readonly attachment: RefAttachment;
constructor(opts: CommandInputStateOpts, root: CommandRootState);
readonly props: {
readonly id: string;
readonly type: "text";
readonly autocomplete: "off";
readonly autocorrect: "off";
readonly spellcheck: false;
readonly "aria-autocomplete": "list";
readonly role: "combobox";
readonly "aria-expanded": "true" | "false";
readonly "aria-controls": string | undefined;
readonly "aria-labelledby": string | undefined;
readonly "aria-activedescendant": string | undefined;
};
}
interface CommandItemStateOpts extends WithRefOpts, ReadableBoxedValues<{
value: string;
disabled: boolean;
onSelect: () => void;
forceMount: boolean;
keywords: string[];
}> {
group: CommandGroupContainerState | null;
}
export declare class CommandItemState {
#private;
static create(opts: Omit<CommandItemStateOpts, "group">): CommandItemState;
readonly opts: CommandItemStateOpts;
readonly root: CommandRootState;
readonly attachment: RefAttachment;
readonly shouldRender: boolean;
readonly isSelected: boolean;
trueValue: string;
constructor(opts: CommandItemStateOpts, root: CommandRootState);
onpointermove(_: BitsPointerEvent): void;
onclick(_: BitsMouseEvent): void;
readonly props: {
readonly id: string;
readonly "aria-disabled": "true" | "false";
readonly "aria-selected": "true" | "false";
readonly "data-disabled": "" | undefined;
readonly "data-selected": "" | undefined;
readonly "data-value": string;
readonly "data-group": string | undefined;
readonly role: "option";
readonly onpointermove: (_: BitsPointerEvent) => void;
readonly onclick: (_: BitsMouseEvent) => void;
};
}
interface CommandLoadingStateOpts extends WithRefOpts, ReadableBoxedValues<{
progress: number;
}> {
}
export declare class CommandLoadingState {
static create(opts: CommandLoadingStateOpts): CommandLoadingState;
readonly opts: CommandLoadingStateOpts;
readonly attachment: RefAttachment;
constructor(opts: CommandLoadingStateOpts);
readonly props: {
readonly id: string;
readonly role: "progressbar";
readonly "aria-valuenow": number;
readonly "aria-valuemin": 0;
readonly "aria-valuemax": 100;
readonly "aria-label": "Loading...";
};
}
interface CommandSeparatorStateOpts extends WithRefOpts, ReadableBoxedValues<{
forceMount: boolean;
}> {
}
export declare class CommandSeparatorState {
static create(opts: CommandSeparatorStateOpts): CommandSeparatorState;
readonly opts: CommandSeparatorStateOpts;
readonly root: CommandRootState;
readonly attachment: RefAttachment;
readonly shouldRender: boolean;
constructor(opts: CommandSeparatorStateOpts, root: CommandRootState);
readonly props: {
readonly id: string;
readonly "aria-hidden": "true";
};
}
interface CommandListStateOpts extends WithRefOpts, ReadableBoxedValues<{
ariaLabel: string;
}> {
}
export declare class CommandListState {
static create(opts: CommandListStateOpts): CommandListState;
readonly opts: CommandListStateOpts;
readonly root: CommandRootState;
readonly attachment: RefAttachment;
constructor(opts: CommandListStateOpts, root: CommandRootState);
readonly props: {
readonly id: string;
readonly role: "listbox";
readonly "aria-label": string;
};
}
interface CommandLabelStateOpts extends WithRefOpts, ReadableBoxedValues<{
for?: string;
}> {
}
export declare class CommandLabelState {
static create(opts: CommandLabelStateOpts): CommandLabelState;
readonly opts: CommandLabelStateOpts;
readonly root: CommandRootState;
readonly attachment: RefAttachment;
constructor(opts: CommandLabelStateOpts, root: CommandRootState);
readonly props: {
readonly id: string;
readonly for: string | undefined;
readonly style: import("svelte-toolbelt").StyleProperties;
};
}
interface CommandViewportStateOpts extends WithRefOpts {
}
export declare class CommandViewportState {
static create(opts: CommandViewportStateOpts): CommandViewportState;
readonly opts: CommandViewportStateOpts;
readonly list: CommandListState;
readonly attachment: RefAttachment;
constructor(opts: CommandViewportStateOpts, list: CommandListState);
readonly props: {
readonly id: string;
};
}
export {};
|