-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_picker.ts
74 lines (70 loc) · 2.38 KB
/
action_picker.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
import type { Action } from "@vim-fall/core/action";
import type { Coordinator } from "@vim-fall/core/coordinator";
import type { Detail } from "@vim-fall/core/item";
import type { Matcher } from "@vim-fall/core/matcher";
import type { Previewer } from "@vim-fall/core/previewer";
import type { Renderer } from "@vim-fall/core/renderer";
import type { Sorter } from "@vim-fall/core/sorter";
import type { Theme } from "@vim-fall/core/theme";
import {
type Derivable,
type DerivableArray,
derive,
deriveArray,
} from "./derivable.ts";
/**
* Parameters required to configure an action picker.
*/
export type ActionPickerParams = {
matchers: readonly [Matcher<Action<Detail>>, ...Matcher<Action<Detail>>[]];
sorters?: readonly Sorter<Action<Detail>>[];
renderers?: readonly Renderer<Action<Detail>>[];
previewers?: readonly Previewer<Action<Detail>>[];
coordinator?: Coordinator;
theme?: Theme;
};
/**
* Refines the configuration for an action picker.
*/
export type RefineActionPicker = (
params: Readonly<{
matchers: DerivableArray<
readonly [Matcher<Action<Detail>>, ...Matcher<Action<Detail>>[]]
>;
sorters?: DerivableArray<readonly Sorter<Action<Detail>>[]>;
renderers?: DerivableArray<readonly Renderer<Action<Detail>>[]>;
previewers?: DerivableArray<readonly Previewer<Action<Detail>>[]>;
coordinator?: Derivable<Coordinator>;
theme?: Derivable<Theme>;
}>,
) => void;
/**
* Builds a function that refines the configuration for an action picker using the provided parameters.
*
* @param actionPickerParams The parameters to configure the action picker.
* @returns The function that refines the configuration for an action picker.
*/
export function buildRefineActionPicker(
actionPickerParams: ActionPickerParams,
): RefineActionPicker {
return (params) => {
if (params.matchers) {
actionPickerParams.matchers = deriveArray(params.matchers);
}
if (params.sorters) {
actionPickerParams.sorters = deriveArray(params.sorters);
}
if (params.renderers) {
actionPickerParams.renderers = deriveArray(params.renderers);
}
if (params.previewers) {
actionPickerParams.previewers = deriveArray(params.previewers);
}
if (params.coordinator) {
actionPickerParams.coordinator = derive(params.coordinator);
}
if (params.theme) {
actionPickerParams.theme = derive(params.theme);
}
};
}