-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandBar.d.ts
124 lines (124 loc) · 3.72 KB
/
commandBar.d.ts
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
/**
* Takes an SVG string and converts it into an HTML element. Useful for
* displaying icons in the command bar.
*
* @param {string} svg
* @returns {HTMLElement}
*/
export function renderSvgFromString(svg: string): HTMLElement;
/** @extends {C8<CommandBarAttrs, CommandBarRefs, never>} */
export class CommandBar extends C8<CommandBarAttrs, CommandBarRefs, never> {
static disabledFeatures: string[];
/** @type {import("@andreasphil/c8").Attrs<CommandBarAttrs>} */
static attrs: import("@andreasphil/c8").Attrs<CommandBarAttrs>;
/** @type {Array<keyof HTMLElementEventMap>} */
static events: Array<keyof HTMLElementEventMap>;
static get instance(): CommandBar;
constructor();
disconnectedCallback(): void;
/**
* @template {keyof CommandBarAttrs} T
* @param {T} name
*/
attributeChangedCallback<T extends keyof CommandBarAttrs>(name: T): void;
/**
* @private Cannot be strictly private for Vue compat reasons, but should be
* treated as internal.
*/
private updatePlaceholder;
/**
* @private Cannot be strictly private for Vue compat reasons, but should be
* treated as internal.
*/
private updateEmptyMessage;
open(initialQuery?: string): void;
onDialogClose(): void;
/**
* @param {Command[]} toRegister
* @returns {() => void}
*/
registerCommand(...toRegister: Command[]): () => void;
/** @param {string[]} toRemove */
removeCommand(...toRemove: string[]): void;
/** @param {InputEvent} event */
onSearch(event: InputEvent): void;
#private;
}
export type KeyboardShortcut = Partial<Pick<KeyboardEvent, "key" | "metaKey" | "altKey" | "ctrlKey" | "shiftKey">>;
export type Command = {
/**
* The unique identifier of the command. Can be any string.
*/
id: string;
/**
* The visible name of the command.
*/
name: string;
/**
* A list of aliases of the command. If the user
* searches for one of them, the alias will be treated as if it was the name
* of the command.
*/
alias?: string[];
/**
* A unique combination of characters. If the user
* types those exact characters in the search field, the associated command
* will be shown prominently and highlighted.
*/
chord?: string;
/**
* An additional label displayed before the name.
*/
groupName?: string;
/**
* Icon of the command. Should be a string
* (which will be inserted as text content) or an HTML element (which will be
* inserted as-is).
*/
icon?: string | HTMLElement;
/**
* Callback to run when the command is invoked.
*/
action: () => void;
/**
* Used for sorting. Items with a higher weight
* will always appear before items with a lower weight.
*/
weight?: number;
};
export type CommandBarAttrs = {
/**
* When true, repeats the most recent command
* when ⌘. is pressed.
*/
allowRepeat: boolean;
/**
* Changes the text of the message that is
* displayed when no results are found. Defaults to "Sorry, couldnʼt find
* anything."
*/
emptyMessage?: string;
/**
* Allows you to set a custom hotkey.
* Defaults to ⌘K.
*/
hotkey?: KeyboardShortcut;
/**
* Limits the number of results that are
* shown. Defaults to 10.
*/
limitResults?: number;
/**
* Changes the placeholder of the search field.
* Defaults to "Search..."
*/
placeholder?: string;
};
export type CommandBarRefs = {
host: HTMLDialogElement;
searchLabel: HTMLLabelElement;
search: HTMLInputElement;
results: HTMLUListElement;
emptyMessage: HTMLParagraphElement;
};
import { C8 } from "@andreasphil/c8";