@boba-cli/list 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,218 @@
1
+ import { Style } from '@boba-cli/chapstick';
2
+ import { KeyMap, HelpModel } from '@boba-cli/help';
3
+ import { Binding } from '@boba-cli/key';
4
+ import { PaginatorModel } from '@boba-cli/paginator';
5
+ import { SpinnerModel } from '@boba-cli/spinner';
6
+ import { Cmd, Msg } from '@boba-cli/tea';
7
+
8
+ /**
9
+ * Items displayed in a list must implement this interface.
10
+ * @public
11
+ */
12
+ interface Item {
13
+ /** Text used for filtering. */
14
+ filterValue(): string;
15
+ /** Title shown in the list. */
16
+ title(): string;
17
+ /** Optional description. */
18
+ description(): string;
19
+ }
20
+ /**
21
+ * Simple default item implementation.
22
+ * @public
23
+ */
24
+ declare class DefaultItem implements Item {
25
+ private readonly titleText;
26
+ private readonly descText;
27
+ constructor(titleText: string, descText?: string);
28
+ filterValue(): string;
29
+ title(): string;
30
+ description(): string;
31
+ }
32
+
33
+ /**
34
+ * Style configuration for the list component.
35
+ * @public
36
+ */
37
+ interface ListStyles {
38
+ title: Style;
39
+ titleBar: Style;
40
+ spinner: Style;
41
+ filterPrompt: Style;
42
+ filterCursor: Style;
43
+ noItems: Style;
44
+ statusBar: Style;
45
+ statusEmpty: Style;
46
+ pagination: Style;
47
+ help: Style;
48
+ normalTitle: Style;
49
+ normalDesc: Style;
50
+ selectedTitle: Style;
51
+ selectedDesc: Style;
52
+ dimmedTitle: Style;
53
+ dimmedDesc: Style;
54
+ }
55
+ /** Default styles used by the list component. @public */
56
+ declare function defaultStyles(): ListStyles;
57
+ /**
58
+ * Merge user provided overrides with defaults.
59
+ * @public
60
+ */
61
+ declare function mergeStyles(overrides?: Partial<ListStyles>): ListStyles;
62
+
63
+ /**
64
+ * Delegate interface for rendering list items.
65
+ * @public
66
+ */
67
+ interface ItemDelegate<T extends Item> {
68
+ /** Height of each item in lines. */
69
+ height(): number;
70
+ /** Spacing between items in lines. */
71
+ spacing(): number;
72
+ /** Render an item to a string. */
73
+ render(item: T, index: number, selected: boolean): string;
74
+ }
75
+ /**
76
+ * Default delegate renders a title plus optional description.
77
+ * @public
78
+ */
79
+ declare class DefaultDelegate implements ItemDelegate<Item> {
80
+ #private;
81
+ constructor(styles?: ListStyles);
82
+ height(): number;
83
+ spacing(): number;
84
+ render(item: Item, _index: number, selected: boolean): string;
85
+ /** Return a copy using different styles. */
86
+ withStyles(styles: ListStyles): DefaultDelegate;
87
+ }
88
+
89
+ /**
90
+ * Keyboard bindings for the list component.
91
+ * @public
92
+ */
93
+ interface ListKeyMap extends KeyMap {
94
+ cursorUp: Binding;
95
+ cursorDown: Binding;
96
+ gotoTop: Binding;
97
+ gotoBottom: Binding;
98
+ nextPage: Binding;
99
+ prevPage: Binding;
100
+ filter: Binding;
101
+ clearFilter: Binding;
102
+ acceptFilter: Binding;
103
+ cancelFilter: Binding;
104
+ showFullHelp: Binding;
105
+ closeFullHelp: Binding;
106
+ quit: Binding;
107
+ forceQuit: Binding;
108
+ }
109
+ /** Default bindings modeled after the Go bubbles list. @public */
110
+ declare const defaultKeyMap: ListKeyMap;
111
+
112
+ /** Filtering lifecycle for the list. @public */
113
+ type FilterState = 'unfiltered' | 'filtering' | 'applied';
114
+ /**
115
+ * Construction options for {@link ListModel}.
116
+ * @public
117
+ */
118
+ interface ListOptions<T extends Item> {
119
+ items: T[];
120
+ delegate?: ItemDelegate<T>;
121
+ width?: number;
122
+ height?: number;
123
+ title?: string;
124
+ showTitle?: boolean;
125
+ showFilter?: boolean;
126
+ showStatusBar?: boolean;
127
+ showPagination?: boolean;
128
+ showHelp?: boolean;
129
+ filteringEnabled?: boolean;
130
+ styles?: Partial<ListStyles>;
131
+ keyMap?: ListKeyMap;
132
+ }
133
+
134
+ /**
135
+ * Composite list component with filtering, pagination, spinner, and help.
136
+ * @public
137
+ */
138
+ declare class ListModel<T extends Item> {
139
+ readonly items: T[];
140
+ readonly filteredItems: T[];
141
+ readonly cursor: number;
142
+ readonly filterValue: string;
143
+ readonly filterState: FilterState;
144
+ readonly paginator: PaginatorModel;
145
+ readonly help: HelpModel;
146
+ readonly spinner: SpinnerModel;
147
+ readonly delegate: ItemDelegate<T>;
148
+ readonly styles: ListStyles;
149
+ readonly keyMap: ListKeyMap;
150
+ readonly width: number;
151
+ readonly height: number;
152
+ readonly title: string;
153
+ readonly showTitle: boolean;
154
+ readonly showFilter: boolean;
155
+ readonly showStatusBar: boolean;
156
+ readonly showPagination: boolean;
157
+ readonly showHelp: boolean;
158
+ readonly filteringEnabled: boolean;
159
+ readonly loading: boolean;
160
+ private constructor();
161
+ /** Create a new list model. */
162
+ static new<T extends Item>(options: ListOptions<T>): ListModel<T>;
163
+ /** Currently selected item (after filtering). */
164
+ selectedItem(): T | undefined;
165
+ /** Index of the selected item within the filtered collection. */
166
+ selectedIndex(): number;
167
+ /** Items visible on the current page. */
168
+ visibleItems(): T[];
169
+ /** Move cursor up by one item. */
170
+ cursorUp(): ListModel<T>;
171
+ /** Move cursor down by one item. */
172
+ cursorDown(): ListModel<T>;
173
+ /** Jump to first item. */
174
+ gotoTop(): ListModel<T>;
175
+ /** Jump to last item. */
176
+ gotoBottom(): ListModel<T>;
177
+ /** Move to next page. */
178
+ nextPage(): ListModel<T>;
179
+ /** Move to previous page. */
180
+ prevPage(): ListModel<T>;
181
+ /** Begin filtering. */
182
+ startFiltering(): ListModel<T>;
183
+ /** Set the filter query. */
184
+ setFilter(value: string): ListModel<T>;
185
+ /** Accept the current filter value. */
186
+ acceptFilter(): ListModel<T>;
187
+ /** Cancel filtering and restore the unfiltered list. */
188
+ cancelFilter(): ListModel<T>;
189
+ /** Clear the filter text and results. */
190
+ clearFilter(): ListModel<T>;
191
+ /** Replace items with a new list. */
192
+ setItems(items: T[]): ListModel<T>;
193
+ /** Insert a single item. */
194
+ insertItem(index: number, item: T): ListModel<T>;
195
+ /** Remove an item by index. */
196
+ removeItem(index: number): ListModel<T>;
197
+ /** Enter loading mode and start the spinner. */
198
+ startLoading(): [ListModel<T>, Cmd<Msg>];
199
+ /** Stop loading. */
200
+ stopLoading(): ListModel<T>;
201
+ /** Update width. */
202
+ setWidth(width: number): ListModel<T>;
203
+ /** Update height and adjust pagination. */
204
+ setHeight(height: number): ListModel<T>;
205
+ /** Show detailed help. */
206
+ showHelpView(): ListModel<T>;
207
+ /** Hide detailed help. */
208
+ hideHelpView(): ListModel<T>;
209
+ /** Tea init - start spinner if already loading. */
210
+ init(): Cmd<Msg>;
211
+ /** Handle Tea messages. */
212
+ update(msg: Msg): [ListModel<T>, Cmd<Msg>];
213
+ /** Render the list to a string. */
214
+ view(): string;
215
+ private with;
216
+ }
217
+
218
+ export { DefaultDelegate, DefaultItem, type FilterState, type Item, type ItemDelegate, type ListKeyMap, ListModel, type ListOptions, type ListStyles, defaultKeyMap, defaultStyles, mergeStyles };
@@ -0,0 +1,218 @@
1
+ import { Style } from '@boba-cli/chapstick';
2
+ import { KeyMap, HelpModel } from '@boba-cli/help';
3
+ import { Binding } from '@boba-cli/key';
4
+ import { PaginatorModel } from '@boba-cli/paginator';
5
+ import { SpinnerModel } from '@boba-cli/spinner';
6
+ import { Cmd, Msg } from '@boba-cli/tea';
7
+
8
+ /**
9
+ * Items displayed in a list must implement this interface.
10
+ * @public
11
+ */
12
+ interface Item {
13
+ /** Text used for filtering. */
14
+ filterValue(): string;
15
+ /** Title shown in the list. */
16
+ title(): string;
17
+ /** Optional description. */
18
+ description(): string;
19
+ }
20
+ /**
21
+ * Simple default item implementation.
22
+ * @public
23
+ */
24
+ declare class DefaultItem implements Item {
25
+ private readonly titleText;
26
+ private readonly descText;
27
+ constructor(titleText: string, descText?: string);
28
+ filterValue(): string;
29
+ title(): string;
30
+ description(): string;
31
+ }
32
+
33
+ /**
34
+ * Style configuration for the list component.
35
+ * @public
36
+ */
37
+ interface ListStyles {
38
+ title: Style;
39
+ titleBar: Style;
40
+ spinner: Style;
41
+ filterPrompt: Style;
42
+ filterCursor: Style;
43
+ noItems: Style;
44
+ statusBar: Style;
45
+ statusEmpty: Style;
46
+ pagination: Style;
47
+ help: Style;
48
+ normalTitle: Style;
49
+ normalDesc: Style;
50
+ selectedTitle: Style;
51
+ selectedDesc: Style;
52
+ dimmedTitle: Style;
53
+ dimmedDesc: Style;
54
+ }
55
+ /** Default styles used by the list component. @public */
56
+ declare function defaultStyles(): ListStyles;
57
+ /**
58
+ * Merge user provided overrides with defaults.
59
+ * @public
60
+ */
61
+ declare function mergeStyles(overrides?: Partial<ListStyles>): ListStyles;
62
+
63
+ /**
64
+ * Delegate interface for rendering list items.
65
+ * @public
66
+ */
67
+ interface ItemDelegate<T extends Item> {
68
+ /** Height of each item in lines. */
69
+ height(): number;
70
+ /** Spacing between items in lines. */
71
+ spacing(): number;
72
+ /** Render an item to a string. */
73
+ render(item: T, index: number, selected: boolean): string;
74
+ }
75
+ /**
76
+ * Default delegate renders a title plus optional description.
77
+ * @public
78
+ */
79
+ declare class DefaultDelegate implements ItemDelegate<Item> {
80
+ #private;
81
+ constructor(styles?: ListStyles);
82
+ height(): number;
83
+ spacing(): number;
84
+ render(item: Item, _index: number, selected: boolean): string;
85
+ /** Return a copy using different styles. */
86
+ withStyles(styles: ListStyles): DefaultDelegate;
87
+ }
88
+
89
+ /**
90
+ * Keyboard bindings for the list component.
91
+ * @public
92
+ */
93
+ interface ListKeyMap extends KeyMap {
94
+ cursorUp: Binding;
95
+ cursorDown: Binding;
96
+ gotoTop: Binding;
97
+ gotoBottom: Binding;
98
+ nextPage: Binding;
99
+ prevPage: Binding;
100
+ filter: Binding;
101
+ clearFilter: Binding;
102
+ acceptFilter: Binding;
103
+ cancelFilter: Binding;
104
+ showFullHelp: Binding;
105
+ closeFullHelp: Binding;
106
+ quit: Binding;
107
+ forceQuit: Binding;
108
+ }
109
+ /** Default bindings modeled after the Go bubbles list. @public */
110
+ declare const defaultKeyMap: ListKeyMap;
111
+
112
+ /** Filtering lifecycle for the list. @public */
113
+ type FilterState = 'unfiltered' | 'filtering' | 'applied';
114
+ /**
115
+ * Construction options for {@link ListModel}.
116
+ * @public
117
+ */
118
+ interface ListOptions<T extends Item> {
119
+ items: T[];
120
+ delegate?: ItemDelegate<T>;
121
+ width?: number;
122
+ height?: number;
123
+ title?: string;
124
+ showTitle?: boolean;
125
+ showFilter?: boolean;
126
+ showStatusBar?: boolean;
127
+ showPagination?: boolean;
128
+ showHelp?: boolean;
129
+ filteringEnabled?: boolean;
130
+ styles?: Partial<ListStyles>;
131
+ keyMap?: ListKeyMap;
132
+ }
133
+
134
+ /**
135
+ * Composite list component with filtering, pagination, spinner, and help.
136
+ * @public
137
+ */
138
+ declare class ListModel<T extends Item> {
139
+ readonly items: T[];
140
+ readonly filteredItems: T[];
141
+ readonly cursor: number;
142
+ readonly filterValue: string;
143
+ readonly filterState: FilterState;
144
+ readonly paginator: PaginatorModel;
145
+ readonly help: HelpModel;
146
+ readonly spinner: SpinnerModel;
147
+ readonly delegate: ItemDelegate<T>;
148
+ readonly styles: ListStyles;
149
+ readonly keyMap: ListKeyMap;
150
+ readonly width: number;
151
+ readonly height: number;
152
+ readonly title: string;
153
+ readonly showTitle: boolean;
154
+ readonly showFilter: boolean;
155
+ readonly showStatusBar: boolean;
156
+ readonly showPagination: boolean;
157
+ readonly showHelp: boolean;
158
+ readonly filteringEnabled: boolean;
159
+ readonly loading: boolean;
160
+ private constructor();
161
+ /** Create a new list model. */
162
+ static new<T extends Item>(options: ListOptions<T>): ListModel<T>;
163
+ /** Currently selected item (after filtering). */
164
+ selectedItem(): T | undefined;
165
+ /** Index of the selected item within the filtered collection. */
166
+ selectedIndex(): number;
167
+ /** Items visible on the current page. */
168
+ visibleItems(): T[];
169
+ /** Move cursor up by one item. */
170
+ cursorUp(): ListModel<T>;
171
+ /** Move cursor down by one item. */
172
+ cursorDown(): ListModel<T>;
173
+ /** Jump to first item. */
174
+ gotoTop(): ListModel<T>;
175
+ /** Jump to last item. */
176
+ gotoBottom(): ListModel<T>;
177
+ /** Move to next page. */
178
+ nextPage(): ListModel<T>;
179
+ /** Move to previous page. */
180
+ prevPage(): ListModel<T>;
181
+ /** Begin filtering. */
182
+ startFiltering(): ListModel<T>;
183
+ /** Set the filter query. */
184
+ setFilter(value: string): ListModel<T>;
185
+ /** Accept the current filter value. */
186
+ acceptFilter(): ListModel<T>;
187
+ /** Cancel filtering and restore the unfiltered list. */
188
+ cancelFilter(): ListModel<T>;
189
+ /** Clear the filter text and results. */
190
+ clearFilter(): ListModel<T>;
191
+ /** Replace items with a new list. */
192
+ setItems(items: T[]): ListModel<T>;
193
+ /** Insert a single item. */
194
+ insertItem(index: number, item: T): ListModel<T>;
195
+ /** Remove an item by index. */
196
+ removeItem(index: number): ListModel<T>;
197
+ /** Enter loading mode and start the spinner. */
198
+ startLoading(): [ListModel<T>, Cmd<Msg>];
199
+ /** Stop loading. */
200
+ stopLoading(): ListModel<T>;
201
+ /** Update width. */
202
+ setWidth(width: number): ListModel<T>;
203
+ /** Update height and adjust pagination. */
204
+ setHeight(height: number): ListModel<T>;
205
+ /** Show detailed help. */
206
+ showHelpView(): ListModel<T>;
207
+ /** Hide detailed help. */
208
+ hideHelpView(): ListModel<T>;
209
+ /** Tea init - start spinner if already loading. */
210
+ init(): Cmd<Msg>;
211
+ /** Handle Tea messages. */
212
+ update(msg: Msg): [ListModel<T>, Cmd<Msg>];
213
+ /** Render the list to a string. */
214
+ view(): string;
215
+ private with;
216
+ }
217
+
218
+ export { DefaultDelegate, DefaultItem, type FilterState, type Item, type ItemDelegate, type ListKeyMap, ListModel, type ListOptions, type ListStyles, defaultKeyMap, defaultStyles, mergeStyles };