This repository was archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommandbar.d.ts
More file actions
122 lines (107 loc) · 3.53 KB
/
commandbar.d.ts
File metadata and controls
122 lines (107 loc) · 3.53 KB
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
export interface CommandBar {
readonly boot: (args: CommandBarBootArgs) => void;
readonly addContext: (context: CommandBarContext) => void;
readonly removeContext: (key: string) => void;
readonly setContext: (context: CommandBarContext) => void;
readonly addCallback: <T = any, K = any>(name: string, callback: CommandBarCallback<T, K>) => void;
readonly removeCallback: (name: string) => void;
readonly addCommand: (command: CommandBarCommandConfig) => void;
readonly removeCommand: (name: string) => void;
readonly addRouter: (routerFunc: CommandBarRouterFunc) => void;
readonly addSearch: (category: string, searchFunc: CommandBarSearchFunc) => void;
readonly showGuide: (key: string) => void;
readonly open: (input?: string) => void;
readonly execute: (command: number | string) => void;
readonly onboard: () => void;
readonly isOpen: () => boolean | undefined;
readonly updateContextSettings: <T = any>(key: string, settings: CommandBarSearchSettings<T>) => void;
}
declare global {
interface Window {
CommandBar: CommandBar;
}
namespace CommandBarTypes {
// Core primitives
export type CommandBarContext<T = any> = Record<string, T>;
export type CommandBarCallbackArgs<T> = Record<string, T>;
export type CommandBarCallback<T, K> = (args: CommandBarCallbackArgs<T>, context: CommandBarContext<K>) => void;
// Special cases
export type CommandBarRouterFunc = (url: string) => void;
export type CommandBarSearchFunc = (url: string) => void;
// CommandBar.boot
export type CommandBarBootArgs = {
id: string;
} & CommandBarContext;
export enum TemplateTypes {
callback = "callback",
link = "link",
}
// Programmatic commands
export type LinkCommandTemplate = {
type: TemplateTypes.link;
value: string;
operation: "self" | "blank" | "router";
};
export type CallbackCommandTemplate = {
type: TemplateTypes.callback;
value: string;
};
export enum CommandBarArgumentTypes {
context = "context",
provided = "provided",
dependent = "dependent",
function = "function",
set = "set",
}
export type ContextArgument = {
type: CommandBarArgumentTypes.context;
value: string;
order_key: number;
label_field?: string;
};
export type ProvidedArgument = {
type: CommandBarArgumentTypes.provided;
value: "text" | "time";
order_key: number;
};
export type DependentArgument = {
type: CommandBarArgumentTypes.dependent;
value: string;
order_key: number;
};
export type FunctionArgument = {
type: CommandBarArgumentTypes.function;
value: string;
order_key: number;
};
export type SetArgument = {
type: CommandBarArgumentTypes.set;
value: string[];
order_key: number;
};
export type CommandBarArgument =
| ContextArgument
| ProvidedArgument
| DependentArgument
| FunctionArgument
| SetArgument;
export type CommandBarCommandConfig = {
name: string;
text: string;
template: LinkCommandTemplate | CallbackCommandTemplate;
shortcut_mac?: string[];
shortcut_win?: string[];
tags?: string[];
explanation?: string;
sort_key?: number;
arguments?: Record<string, CommandBarArgument>;
};
export type CommandBarSearchSettings<T> = {
search: boolean;
label_field?: keyof T;
search_fields?: keyof T[];
auto_execute?: boolean;
description_field?: keyof T;
};
}
}