-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtypes.ts
More file actions
114 lines (94 loc) · 2.75 KB
/
types.ts
File metadata and controls
114 lines (94 loc) · 2.75 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
import { Component } from 'solid-js';
import { DeepReadonly, Store } from 'solid-js/store';
export type ActionId = string;
export type ParentActionId = null | ActionId;
export type ActionShortcut = string;
export type ActionContext = Record<string, unknown>;
export type DynamicContextMap = Record<ActionId, ActionContext>;
export interface ActionsContext {
root: ActionContext;
dynamic: DynamicContextMap;
}
export interface RunArgs {
actionId: ActionId;
rootContext: ActionContext;
dynamicContext: ActionContext;
}
export interface BaseAction {
id: ActionId;
parentActionId: ParentActionId;
title: string;
subtitle: null | string;
keywords: Array<string>;
/**
* Keyboard Shortcut like `$mod+e`, `Shift+p`.
*/
shortcut: null | ActionShortcut;
/**
* Enable the action conditionally.
*/
cond?: (args: RunArgs) => boolean;
run?: (args: RunArgs) => void;
/**
* Prevent children from being displayed at the root level of the palette.
*
* Default: `true`
*/
isolateChildren?: boolean;
}
export interface ChildAction {
isolateChildren?: never;
}
export interface ParentAction {
parentActionId: never;
run?: never;
}
export type Action =
| (Omit<BaseAction, keyof ChildAction> & ChildAction)
| (Omit<BaseAction, keyof ParentAction> & ParentAction)
export type PartialAction = Partial<Action> & {
id: ActionId;
title: Action['title'];
};
export type Actions = Record<ActionId, Action>;
export type ActionsList = Array<Action>;
export type WrappedAction = DeepReadonly<Action>;
export type WrappedActionList = Array<WrappedAction>;
export interface ResultContentProps {
action: WrappedAction;
isActive: boolean;
}
export interface Components {
ResultContent: Component<ResultContentProps>;
}
export interface RootProps {
actions: Actions;
actionsContext: ActionContext;
components?: Components;
}
export interface StoreState {
visibility: 'opened' | 'closed';
searchText: string;
activeParentActionIdList: Array<ActionId>;
actions: Actions;
actionsContext: ActionsContext;
components?: Components;
}
export type StoreStateWrapped = Store<StoreState>;
export interface StoreMethods {
setSearchText: (newValue: string) => void;
setActionsContext: (actionId: ActionId, newData: ActionContext) => void;
resetActionsContext: (actionId: ActionId) => void;
openPalette: () => void;
closePalette: () => void;
togglePalette: () => void;
selectParentAction: (parentActionId: ActionId) => void;
revertParentAction: () => void;
resetParentAction: () => void;
}
export type StoreContext = [StoreStateWrapped, StoreMethods];
type CreateSyncActionsContextCallback = () => ActionContext;
export type CreateSyncActionsContext = (
actionId: ActionId,
callback: CreateSyncActionsContextCallback
) => void;