|
| 1 | +import type { Denops } from "jsr:@denops/std@^7.3.2"; |
| 2 | +import type { |
| 3 | + Action, |
| 4 | + Coordinator, |
| 5 | + Curator, |
| 6 | + Detail, |
| 7 | + Matcher, |
| 8 | + Previewer, |
| 9 | + Renderer, |
| 10 | + Sorter, |
| 11 | + Source, |
| 12 | + Theme, |
| 13 | +} from "jsr:@vim-fall/core@^0.2.1"; |
| 14 | + |
| 15 | +import type { Derivable, DerivableArray, DerivableMap } from "./derivable.ts"; |
| 16 | + |
| 17 | +/** |
| 18 | + * Represents a collection of actions that can be invoked. |
| 19 | + * |
| 20 | + * @template T - The type of items the actions operate on. |
| 21 | + * @template A - The type representing the default action name. |
| 22 | + */ |
| 23 | +export type Actions<T extends Detail, A extends string> = |
| 24 | + & Record<string, Action<T>> |
| 25 | + & { [key in A]: Action<T> }; |
| 26 | + |
| 27 | +/** |
| 28 | + * Parameters required to configure an item picker. |
| 29 | + * |
| 30 | + * @template T - The type of items in the picker. |
| 31 | + * @template A - The type representing the default action name. |
| 32 | + */ |
| 33 | +export type ItemPickerParams<T extends Detail, A extends string> = { |
| 34 | + name: string; |
| 35 | + source: Source<T>; |
| 36 | + actions: Actions<T, NoInfer<A>>; |
| 37 | + defaultAction: A; |
| 38 | + matchers: [Matcher<NoInfer<T>>, ...Matcher<NoInfer<T>>[]]; |
| 39 | + sorters?: Sorter<NoInfer<T>>[]; |
| 40 | + renderers?: Renderer<NoInfer<T>>[]; |
| 41 | + previewers?: Previewer<NoInfer<T>>[]; |
| 42 | + coordinator?: Coordinator; |
| 43 | + theme?: Theme; |
| 44 | +}; |
| 45 | + |
| 46 | +/** |
| 47 | + * Parameters required to configure an action picker. |
| 48 | + */ |
| 49 | +export type ActionPickerParams = { |
| 50 | + matchers: [Matcher<Action<Detail>>, ...Matcher<Action<Detail>>[]]; |
| 51 | + sorters?: Sorter<Action<Detail>>[]; |
| 52 | + renderers?: Renderer<Action<Detail>>[]; |
| 53 | + previewers?: Previewer<Action<Detail>>[]; |
| 54 | + coordinator?: Coordinator; |
| 55 | + theme?: Theme; |
| 56 | +}; |
| 57 | + |
| 58 | +/** |
| 59 | + * Global configuration settings. |
| 60 | + */ |
| 61 | +export type GlobalConfig = { |
| 62 | + coordinator: Coordinator; |
| 63 | + theme: Theme; |
| 64 | +}; |
| 65 | + |
| 66 | +/** |
| 67 | + * Defines an item picker based on a source and matchers. |
| 68 | + * |
| 69 | + * @template T - The type of items handled by the picker. |
| 70 | + * @template A - The type representing the default action name. |
| 71 | + */ |
| 72 | +export type DefineItemPickerFromSource = <T extends Detail, A extends string>( |
| 73 | + name: string, |
| 74 | + source: Derivable<Source<T>>, |
| 75 | + params: { |
| 76 | + actions: DerivableMap<Actions<NoInfer<T>, NoInfer<A>>>; |
| 77 | + defaultAction: A; |
| 78 | + matchers: DerivableArray<[Matcher<NoInfer<T>>, ...Matcher<NoInfer<T>>[]]>; |
| 79 | + sorters?: DerivableArray<Sorter<NoInfer<T>>[]>; |
| 80 | + renderers?: DerivableArray<Renderer<NoInfer<T>>[]>; |
| 81 | + previewers?: DerivableArray<Previewer<NoInfer<T>>[]>; |
| 82 | + coordinator?: Derivable<Coordinator>; |
| 83 | + theme?: Derivable<Theme>; |
| 84 | + }, |
| 85 | +) => void; |
| 86 | + |
| 87 | +/** |
| 88 | + * Defines an item picker based on a curator. |
| 89 | + * |
| 90 | + * @template T - The type of items handled by the picker. |
| 91 | + * @template A - The type representing the default action name. |
| 92 | + */ |
| 93 | +export type DefineItemPickerFromCurator = <T extends Detail, A extends string>( |
| 94 | + name: string, |
| 95 | + curator: Derivable<Curator<T>>, |
| 96 | + params: { |
| 97 | + actions: DerivableMap<Actions<NoInfer<T>, NoInfer<A>>>; |
| 98 | + defaultAction: A; |
| 99 | + sorters?: DerivableArray<Sorter<NoInfer<T>>[]>; |
| 100 | + renderers?: DerivableArray<Renderer<NoInfer<T>>[]>; |
| 101 | + previewers?: DerivableArray<Previewer<NoInfer<T>>[]>; |
| 102 | + coordinator?: Derivable<Coordinator>; |
| 103 | + theme?: Derivable<Theme>; |
| 104 | + }, |
| 105 | +) => void; |
| 106 | + |
| 107 | +/** |
| 108 | + * Refines the configuration for an action picker. |
| 109 | + */ |
| 110 | +export type RefineActionPicker = ( |
| 111 | + params: { |
| 112 | + matchers: DerivableArray< |
| 113 | + [Matcher<Action<Detail>>, ...Matcher<Action<Detail>>[]] |
| 114 | + >; |
| 115 | + sorters?: DerivableArray<Sorter<Action<Detail>>[]>; |
| 116 | + renderers?: DerivableArray<Renderer<Action<Detail>>[]>; |
| 117 | + previewers?: DerivableArray<Previewer<Action<Detail>>[]>; |
| 118 | + coordinator?: Derivable<Coordinator>; |
| 119 | + theme?: Derivable<Theme>; |
| 120 | + }, |
| 121 | +) => void; |
| 122 | + |
| 123 | +/** |
| 124 | + * Refines the global configuration, allowing customization of global coordinator and theme. |
| 125 | + */ |
| 126 | +export type RefineGlobalConfig = ( |
| 127 | + params: { |
| 128 | + coordinator?: Derivable<Coordinator>; |
| 129 | + theme?: Derivable<Theme>; |
| 130 | + }, |
| 131 | +) => void; |
| 132 | + |
| 133 | +/** |
| 134 | + * The entrypoint for configuring the picker environment. |
| 135 | + * |
| 136 | + * @param params - An object containing various picker setup functions and the Denops instance. |
| 137 | + */ |
| 138 | +export type Entrypoint = (params: { |
| 139 | + denops: Denops; |
| 140 | + defineItemPickerFromSource: DefineItemPickerFromSource; |
| 141 | + defineItemPickerFromCurator: DefineItemPickerFromCurator; |
| 142 | + refineActionPicker: RefineActionPicker; |
| 143 | + refineGlobalConfig: RefineGlobalConfig; |
| 144 | +}) => void | Promise<void>; |
0 commit comments