Skip to content

Commit d570eb2

Browse files
committed
feat!: rename to @vim-fall/custom and refine definitions
1 parent 42eb9c3 commit d570eb2

File tree

6 files changed

+73
-104
lines changed

6 files changed

+73
-104
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# 🍂 fall-config
1+
# 🍂 fall-custom
22

3-
[![JSR](https://jsr.io/badges/@vim-fall/config)](https://jsr.io/@vim-fall/config)
3+
[![JSR](https://jsr.io/badges/@vim-fall/custom)](https://jsr.io/@vim-fall/custom)
44
[![Deno](https://img.shields.io/badge/Deno%202.x-333?logo=deno&logoColor=fff)](#)
5-
[![Test](https://github.com/vim-fall/deno-fall-config/actions/workflows/test.yml/badge.svg)](https://github.com/vim-fall/deno-fall-config/actions/workflows/test.yml)
5+
[![Test](https://github.com/vim-fall/deno-fall-custom/actions/workflows/test.yml/badge.svg)](https://github.com/vim-fall/deno-fall-custom/actions/workflows/test.yml)
66
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
77

8-
Module to configure [Fall](https://github.com/vim-fall/fall.vim), a Vim/Neovim
8+
Library to customize [Fall](https://github.com/vim-fall/fall.vim), a Vim/Neovim
99
fuzzy finder plugin powered by
1010
[Denops](https://github.com/vim-denops/denops.vim).
1111

deno.jsonc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "@vim-fall/config",
2+
"name": "@vim-fall/custom",
33
"version": "0.0.0",
44
"exports": {
55
".": "./mod.ts",
66
"./action-picker": "./action_picker.ts",
77
"./derivable": "./derivable.ts",
8-
"./global-config": "./global_config.ts",
9-
"./item-picker": "./item_picker.ts"
8+
"./picker": "./picker.ts",
9+
"./setting": "./setting.ts"
1010
},
1111
"publish": {
1212
"include": [

global_config.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

mod.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Denops } from "@denops/std";
22
import type {
3-
DefineItemPickerFromCurator,
4-
DefineItemPickerFromSource,
5-
} from "./item_picker.ts";
3+
DefinePickerFromCurator,
4+
DefinePickerFromSource,
5+
} from "./picker.ts";
66
import type { RefineActionPicker } from "./action_picker.ts";
7-
import type { RefineGlobalConfig } from "./global_config.ts";
7+
import type { RefineSetting } from "./setting.ts";
88

99
/**
1010
* The entrypoint for configuring the picker environment.
@@ -13,15 +13,15 @@ import type { RefineGlobalConfig } from "./global_config.ts";
1313
*/
1414
export type Entrypoint = (params: {
1515
denops: Denops;
16-
defineItemPickerFromSource: DefineItemPickerFromSource;
17-
defineItemPickerFromCurator: DefineItemPickerFromCurator;
16+
definePickerFromSource: DefinePickerFromSource;
17+
definePickerFromCurator: DefinePickerFromCurator;
1818
refineActionPicker: RefineActionPicker;
19-
refineGlobalConfig: RefineGlobalConfig;
19+
refineSetting: RefineSetting;
2020
}) => void | Promise<void>;
2121

2222
export type {
23-
DefineItemPickerFromCurator,
24-
DefineItemPickerFromSource,
25-
} from "./item_picker.ts";
23+
DefinePickerFromCurator,
24+
DefinePickerFromSource,
25+
} from "./picker.ts";
2626
export type { RefineActionPicker } from "./action_picker.ts";
27-
export type { RefineGlobalConfig } from "./global_config.ts";
27+
export type { RefineSetting } from "./setting.ts";

item_picker.ts renamed to picker.ts

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Actions<T extends Detail = Detail, A extends string = string> =
2929
* @template T - The type of items in the picker.
3030
* @template A - The type representing the default action name.
3131
*/
32-
export type ItemPickerParams<
32+
export type PickerParams<
3333
T extends Detail = Detail,
3434
A extends string = string,
3535
> = {
@@ -51,7 +51,7 @@ export type ItemPickerParams<
5151
* @template T - The type of items handled by the picker.
5252
* @template A - The type representing the default action name.
5353
*/
54-
export type DefineItemPickerFromSource = <T extends Detail, A extends string>(
54+
export type DefinePickerFromSource = <T extends Detail, A extends string>(
5555
name: string,
5656
source: Derivable<Source<T>>,
5757
params: {
@@ -74,7 +74,7 @@ export type DefineItemPickerFromSource = <T extends Detail, A extends string>(
7474
* @template T - The type of items handled by the picker.
7575
* @template A - The type representing the default action name.
7676
*/
77-
export type DefineItemPickerFromCurator = <T extends Detail, A extends string>(
77+
export type DefinePickerFromCurator = <T extends Detail, A extends string>(
7878
name: string,
7979
curator: Derivable<Curator<T>>,
8080
params: {
@@ -91,29 +91,17 @@ export type DefineItemPickerFromCurator = <T extends Detail, A extends string>(
9191
/**
9292
* Builds a function to define an item picker based on a source and matchers with the given map.
9393
*
94-
* @param itemPickerParamsMap - The map to store the defined item pickers.
94+
* @param pickerParamsMap - The map to store the defined item pickers.
9595
* @returns The function to define an item picker based on a source and matchers.
9696
*/
97-
export function buildDefineItemPickerFromSource(
98-
itemPickerParamsMap: Map<string, ItemPickerParams<Detail>>,
99-
): DefineItemPickerFromSource {
100-
function validatePickerName(name: string): void {
101-
if (itemPickerParamsMap.has(name)) {
102-
throw new Error(`Item picker "${name}" is already defined.`);
103-
}
104-
if (name.startsWith("@")) {
105-
throw new Error(`Name "${name}" must not start with "@".`);
106-
}
107-
}
97+
export function buildDefinePickerFromSource(
98+
pickerParamsMap: Map<string, PickerParams<Detail>>,
99+
): DefinePickerFromSource {
108100
return (
109101
name,
110102
source,
111103
params,
112104
) => {
113-
if (itemPickerParamsMap.has(name)) {
114-
throw new Error(`Item picker "${name}" is already defined.`);
115-
}
116-
validatePickerName(name);
117105
const derivedParams = omitUndefinedAttributes({
118106
actions: deriveMap(params.actions) as Actions,
119107
defaultAction: params.defaultAction,
@@ -126,38 +114,28 @@ export function buildDefineItemPickerFromSource(
126114
coordinator: derive(params.coordinator),
127115
theme: derive(params.theme),
128116
});
129-
validateActions(derivedParams.actions);
130-
itemPickerParamsMap.set(name, {
117+
pickerParamsMap.set(name, {
131118
...derivedParams,
132119
name,
133120
source: derive(source),
134-
} as ItemPickerParams<Detail, string>);
121+
} as PickerParams<Detail, string>);
135122
};
136123
}
137124

138125
/**
139126
* Builds a function to define an item picker based on a curator with the given map.
140127
*
141-
* @param itemPickerParamsMap - The map to store the defined item pickers.
128+
* @param pickerParamsMap - The map to store the defined item pickers.
142129
* @returns The function to define an item picker based on a curator.
143130
*/
144-
export function buildDefineItemPickerFromCurator(
145-
itemPickerParamsMap: Map<string, ItemPickerParams<Detail>>,
146-
): DefineItemPickerFromCurator {
147-
function validatePickerName(name: string): void {
148-
if (itemPickerParamsMap.has(name)) {
149-
throw new Error(`Item picker "${name}" is already defined.`);
150-
}
151-
if (name.startsWith("@")) {
152-
throw new Error(`Name "${name}" must not start with "@".`);
153-
}
154-
}
131+
export function buildDefinePickerFromCurator(
132+
pickerParamsMap: Map<string, PickerParams<Detail>>,
133+
): DefinePickerFromCurator {
155134
return (
156135
name,
157136
curator,
158137
params,
159138
) => {
160-
validatePickerName(name);
161139
const source = new CuratorSourceMatcher(derive(curator));
162140
const derivedParams = omitUndefinedAttributes({
163141
actions: deriveMap(params.actions) as Actions,
@@ -170,8 +148,7 @@ export function buildDefineItemPickerFromCurator(
170148
coordinator: derive(params.coordinator),
171149
theme: derive(params.theme),
172150
});
173-
validateActions(derivedParams.actions);
174-
itemPickerParamsMap.set(name, {
151+
pickerParamsMap.set(name, {
175152
...derivedParams,
176153
name,
177154
source,
@@ -231,11 +208,3 @@ function omitUndefinedAttributes<
231208
Object.entries(map).filter(([, v]) => v !== undefined),
232209
) as R;
233210
}
234-
235-
function validateActions(actions: Record<string, Action>): void {
236-
Object.entries(actions).forEach(([name, _action]) => {
237-
if (name.startsWith("@")) {
238-
throw new Error(`Action name "${name}" must not start with "@".`);
239-
}
240-
});
241-
}

setting.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { Coordinator } from "@vim-fall/core/coordinator";
2+
import type { Theme } from "@vim-fall/core/theme";
3+
4+
import { type Derivable, derive } from "./derivable.ts";
5+
6+
/**
7+
* Setting.
8+
*/
9+
export type Setting = {
10+
coordinator: Coordinator;
11+
theme: Theme;
12+
};
13+
14+
/**
15+
* Refines the setting, allowing customization of global coordinator and theme.
16+
*/
17+
export type RefineSetting = (
18+
params: Readonly<{
19+
coordinator?: Derivable<Coordinator>;
20+
theme?: Derivable<Theme>;
21+
}>,
22+
) => void;
23+
24+
/**
25+
* Builds a function that refines the setting based on the provided parameters.
26+
*
27+
* @param setting The setting to refine.
28+
* @returns The function that refines the setting.
29+
*/
30+
export function buildRefineSetting(
31+
setting: Setting,
32+
): RefineSetting {
33+
return (params) => {
34+
if (params.theme) {
35+
setting.theme = derive(params.theme);
36+
}
37+
if (params.coordinator) {
38+
setting.coordinator = derive(params.coordinator);
39+
}
40+
};
41+
}

0 commit comments

Comments
 (0)