@opencode/ui 2.2.5 → 2.2.7
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.
- package/dist/actions/button/button.d.ts +2 -2
- package/dist/actions/icon-button/icon-button.d.ts +1 -1
- package/dist/components/animated-number-machine.d.ts +95 -0
- package/dist/components/file-icon-machine.d.ts +40 -0
- package/dist/components/file-icon.d.ts +0 -2
- package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
- package/dist/components/image-flight-machine.d.ts +135 -0
- package/dist/components/image-zoom-machine.d.ts +95 -0
- package/dist/components/image-zoom.d.ts +6 -3
- package/dist/components/list.d.ts +2 -6
- package/dist/components/menu-scroll.d.ts +9 -3
- package/dist/components/popover-machine.d.ts +96 -0
- package/dist/components/popover.d.ts +2 -2
- package/dist/components/resize-handle-machine.d.ts +71 -0
- package/dist/components/resize-handle.d.ts +2 -0
- package/dist/components/scroll-view-machine.d.ts +68 -0
- package/dist/components/scroll-view.d.ts +2 -2
- package/dist/components/spinner.d.ts +11 -3
- package/dist/components/text-field-machine.d.ts +62 -0
- package/dist/components/text-reveal-machine.d.ts +90 -0
- package/dist/components/typewriter-machine.d.ts +62 -0
- package/dist/context/dialog-machine.d.ts +125 -0
- package/dist/context/dialog.d.ts +17 -16
- package/dist/data-display/line-comment/machine.d.ts +157 -0
- package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
- package/dist/data-display/project-avatar/animation.d.ts +1 -1
- package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
- package/dist/feedback/toast/machine.d.ts +57 -0
- package/dist/feedback/toast/toast.d.ts +1 -1
- package/dist/forms/checkbox/checkbox.d.ts +6 -1
- package/dist/forms/select/machine.d.ts +45 -0
- package/dist/forms/select/select.d.ts +4 -0
- package/dist/forms/typeahead/machine.d.ts +85 -0
- package/dist/hooks/auto-scroll-machine.d.ts +89 -0
- package/dist/hooks/create-auto-scroll.d.ts +1 -1
- package/dist/hooks/list-machine.d.ts +150 -0
- package/dist/hooks/use-filtered-list.d.ts +21 -35
- package/dist/i18n/en.d.ts +5 -0
- package/dist/icons/catalog.d.ts +8 -0
- package/dist/navigation/menu/machine.d.ts +49 -0
- package/dist/navigation/menu/menu.d.ts +5 -3
- package/dist/navigation/segmented-control/machine.d.ts +46 -0
- package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
- package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
- package/dist/overlays/tooltip/machine.d.ts +146 -0
- package/dist/theme/context.d.ts +38 -14
- package/dist/theme/machine.d.ts +174 -0
- package/dist/typography/text-shimmer/machine.d.ts +48 -0
- package/package.json +128 -111
- package/src/actions/button/button.tsx +11 -6
- package/src/actions/icon-button/icon-button.tsx +17 -4
- package/src/components/animated-number-machine.ts +214 -0
- package/src/components/animated-number.tsx +134 -83
- package/src/components/file-icon-machine.ts +78 -0
- package/src/components/file-icon.tsx +96 -579
- package/src/components/file-icons/choose-icon-name.ts +574 -0
- package/src/components/image-flight-machine.ts +247 -0
- package/src/components/image-preview.css +5 -2
- package/src/components/image-preview.tsx +390 -252
- package/src/components/image-zoom-machine.ts +191 -0
- package/src/components/image-zoom.ts +22 -14
- package/src/components/list.tsx +46 -137
- package/src/components/menu-scroll.css +19 -8
- package/src/components/menu-scroll.tsx +111 -34
- package/src/components/popover-machine.ts +198 -0
- package/src/components/popover.tsx +157 -89
- package/src/components/resize-handle-machine.ts +174 -0
- package/src/components/resize-handle.tsx +116 -67
- package/src/components/scroll-view-machine.ts +244 -0
- package/src/components/scroll-view.tsx +163 -116
- package/src/components/spinner.css +18 -5
- package/src/components/spinner.tsx +28 -14
- package/src/components/text-field-machine.ts +102 -0
- package/src/components/text-field.tsx +78 -24
- package/src/components/text-reveal-machine.ts +184 -0
- package/src/components/text-reveal.tsx +96 -93
- package/src/components/typewriter-machine.ts +134 -0
- package/src/components/typewriter.tsx +50 -39
- package/src/context/dialog-machine.ts +280 -0
- package/src/context/dialog.tsx +168 -177
- package/src/data-display/line-comment/line-comment.tsx +157 -178
- package/src/data-display/line-comment/machine.ts +391 -0
- package/src/data-display/project-avatar/animation-machine.ts +182 -0
- package/src/data-display/project-avatar/animation.ts +67 -38
- package/src/feedback/activity-ring/activity-ring.tsx +1 -1
- package/src/feedback/toast/machine.ts +115 -0
- package/src/feedback/toast/toast.tsx +59 -59
- package/src/forms/checkbox/checkbox-compact.css +169 -0
- package/src/forms/checkbox/checkbox.tsx +93 -31
- package/src/forms/inline-input/inline-input.css +0 -1
- package/src/forms/search-list/search-list.css +5 -1
- package/src/forms/search-list/search-list.tsx +18 -10
- package/src/forms/select/machine.ts +81 -0
- package/src/forms/select/select.css +59 -17
- package/src/forms/select/select.tsx +74 -32
- package/src/forms/typeahead/machine.ts +253 -0
- package/src/forms/typeahead/typeahead.tsx +70 -62
- package/src/hooks/auto-scroll-machine.ts +261 -0
- package/src/hooks/create-auto-scroll.tsx +110 -205
- package/src/hooks/list-machine.ts +359 -0
- package/src/hooks/use-filtered-list.tsx +101 -112
- package/src/i18n/en.ts +6 -1
- package/src/i18n/uk.ts +3 -3
- package/src/icons/catalog.ts +8 -0
- package/src/navigation/menu/machine.ts +109 -0
- package/src/navigation/menu/menu.tsx +133 -22
- package/src/navigation/segmented-control/machine.ts +72 -0
- package/src/navigation/segmented-control/segmented-control.tsx +46 -46
- package/src/overlays/dialog/dialog.tsx +7 -1
- package/src/overlays/mcp-sign-in/machine.ts +343 -0
- package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
- package/src/overlays/tooltip/machine.ts +303 -0
- package/src/overlays/tooltip/tooltip.tsx +159 -92
- package/src/styles/theme.css +10 -2
- package/src/theme/context.tsx +192 -269
- package/src/theme/machine.ts +508 -0
- package/src/typography/text-shimmer/machine.ts +90 -0
- package/src/typography/text-shimmer/text-shimmer.css +71 -39
- package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import fuzzysort from "fuzzysort"
|
|
2
|
+
|
|
3
|
+
/** How long an async `items(query)` may run before the list reports it failed rather than loading forever. */
|
|
4
|
+
export const LIST_LOAD_TIMEOUT_MS = 15_000
|
|
5
|
+
|
|
6
|
+
export type ListGroup<T> = { category: string; items: T[] }
|
|
7
|
+
|
|
8
|
+
export type ListConfig<T> = {
|
|
9
|
+
readonly key: (item: T) => string
|
|
10
|
+
readonly filterKeys?: string[]
|
|
11
|
+
readonly skipFilter?: (item: T) => boolean
|
|
12
|
+
readonly groupBy?: (item: T) => string
|
|
13
|
+
readonly sortBy?: (a: T, b: T) => number
|
|
14
|
+
readonly sortGroupsBy?: (a: ListGroup<T>, b: ListGroup<T>) => number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The one copy of the query. A `controlled` list shows the parent's `filter` prop and only reports edits. */
|
|
18
|
+
export type ListFilter = { readonly type: "uncontrolled" | "controlled"; readonly query: string }
|
|
19
|
+
|
|
20
|
+
/** `mouse` while the pointer drives the highlight, so the list does not scroll under it. */
|
|
21
|
+
export type ListHighlight = { readonly mode: "keyboard" | "mouse"; readonly activeKey: string | null }
|
|
22
|
+
|
|
23
|
+
type ListData<T> = {
|
|
24
|
+
readonly filter: ListFilter
|
|
25
|
+
readonly groups: ListGroup<T>[]
|
|
26
|
+
readonly rows: T[]
|
|
27
|
+
readonly keys: string[]
|
|
28
|
+
readonly highlight: ListHighlight
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* `loading` keeps the last rows on screen; `epoch` is the last attempt that settled. `failed` means the current
|
|
33
|
+
* query's async load rejected or timed out, which the list reports instead of "No results". `disposed` keeps the last
|
|
34
|
+
* data for readers that run during cleanup and ignores every event.
|
|
35
|
+
*/
|
|
36
|
+
export type ListState<T> =
|
|
37
|
+
| (ListData<T> & { readonly status: "ready" | "failed"; readonly epoch: number })
|
|
38
|
+
| (ListData<T> & { readonly status: "loading"; readonly attempt: number })
|
|
39
|
+
| (ListData<T> & { readonly status: "disposed" })
|
|
40
|
+
|
|
41
|
+
type LiveListState<T> = Exclude<ListState<T>, { readonly status: "disposed" }>
|
|
42
|
+
|
|
43
|
+
export type ListKeyDown = {
|
|
44
|
+
readonly type: "key.down"
|
|
45
|
+
readonly key: string
|
|
46
|
+
readonly ctrl: boolean
|
|
47
|
+
readonly alt: boolean
|
|
48
|
+
readonly meta: boolean
|
|
49
|
+
readonly shift: boolean
|
|
50
|
+
readonly composing: boolean
|
|
51
|
+
/** A search input keeps Home, End and Tab for the text field. */
|
|
52
|
+
readonly search: boolean
|
|
53
|
+
/** Escape, or a key the caller's `onKeyEvent` already handled. */
|
|
54
|
+
readonly claimed: boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type ListEvent<T> =
|
|
58
|
+
| { readonly type: "query.change"; readonly value: string; readonly force?: boolean }
|
|
59
|
+
| { readonly type: "filter.controlled"; readonly value: string }
|
|
60
|
+
| { readonly type: "filter.uncontrolled" }
|
|
61
|
+
| { readonly type: "items.reload" }
|
|
62
|
+
| { readonly type: "load.resolved"; readonly attempt: number; readonly items: T[] }
|
|
63
|
+
| { readonly type: "load.failed"; readonly attempt: number }
|
|
64
|
+
| { readonly type: "load.timed-out"; readonly attempt: number }
|
|
65
|
+
| { readonly type: "pointer.move"; readonly key: string; readonly moved: boolean }
|
|
66
|
+
| { readonly type: "pointer.leave" }
|
|
67
|
+
| { readonly type: "active.set"; readonly key: string | null }
|
|
68
|
+
| { readonly type: "active.reset" }
|
|
69
|
+
| { readonly type: "disposed" }
|
|
70
|
+
| ListKeyDown
|
|
71
|
+
|
|
72
|
+
export type ListEffect<T> =
|
|
73
|
+
| { readonly type: "load"; readonly attempt: number; readonly query: string }
|
|
74
|
+
/** Stops the settled or abandoned attempt's timeout. */
|
|
75
|
+
| { readonly type: "cancel.load" }
|
|
76
|
+
| { readonly type: "notify.filter"; readonly value: string }
|
|
77
|
+
| { readonly type: "select"; readonly item: T; readonly index: number }
|
|
78
|
+
|
|
79
|
+
export type ListEmptyState =
|
|
80
|
+
| { readonly type: "loading" }
|
|
81
|
+
| { readonly type: "failed" }
|
|
82
|
+
| { readonly type: "empty"; readonly query: string }
|
|
83
|
+
|
|
84
|
+
export type ListTransition<T> = {
|
|
85
|
+
readonly state: ListState<T>
|
|
86
|
+
readonly effects: ListEffect<T>[]
|
|
87
|
+
readonly handled: boolean
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function createListState<T>(filter?: string): ListState<T> {
|
|
91
|
+
return {
|
|
92
|
+
status: "ready",
|
|
93
|
+
epoch: 0,
|
|
94
|
+
filter: filter === undefined ? { type: "uncontrolled", query: "" } : { type: "controlled", query: filter },
|
|
95
|
+
groups: [],
|
|
96
|
+
rows: [],
|
|
97
|
+
keys: [],
|
|
98
|
+
highlight: { mode: "keyboard", activeKey: null },
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function transitionList<T>(state: ListState<T>, event: ListEvent<T>, config: ListConfig<T>): ListTransition<T> {
|
|
103
|
+
if (state.status === "disposed") return unchanged(state)
|
|
104
|
+
|
|
105
|
+
if (event.type === "disposed")
|
|
106
|
+
return changed(
|
|
107
|
+
{
|
|
108
|
+
status: "disposed",
|
|
109
|
+
filter: state.filter,
|
|
110
|
+
groups: state.groups,
|
|
111
|
+
rows: state.rows,
|
|
112
|
+
keys: state.keys,
|
|
113
|
+
highlight: state.highlight,
|
|
114
|
+
},
|
|
115
|
+
state.status === "loading" ? [{ type: "cancel.load" }] : [],
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
if (event.type === "query.change") return queryChanged(state, event.value, event.force === true)
|
|
119
|
+
|
|
120
|
+
if (event.type === "filter.controlled") {
|
|
121
|
+
if (event.value !== state.filter.query) return load(state, { type: "controlled", query: event.value })
|
|
122
|
+
|
|
123
|
+
if (state.filter.type === "controlled") return unchanged(state)
|
|
124
|
+
|
|
125
|
+
return changed({ ...state, filter: { type: "controlled", query: event.value } })
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (event.type === "filter.uncontrolled") {
|
|
129
|
+
if (state.filter.type === "uncontrolled") return unchanged(state)
|
|
130
|
+
|
|
131
|
+
return changed({ ...state, filter: { type: "uncontrolled", query: state.filter.query } })
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (event.type === "items.reload") return load(state, state.filter)
|
|
135
|
+
|
|
136
|
+
if (event.type === "load.resolved" || event.type === "load.failed" || event.type === "load.timed-out") {
|
|
137
|
+
const current = state.status === "loading" ? state.attempt : state.epoch
|
|
138
|
+
// A slow search that timed out still shows its results when they arrive, until a newer attempt starts.
|
|
139
|
+
const late = state.status === "failed" && event.type === "load.resolved"
|
|
140
|
+
|
|
141
|
+
if ((state.status !== "loading" && !late) || event.attempt !== current) return unchanged(state)
|
|
142
|
+
const groups = event.type === "load.resolved" ? filterItems(event.items, state.filter.query, config) : []
|
|
143
|
+
const rows = groups.flatMap((group) => group.items)
|
|
144
|
+
const keys = rows.map(config.key)
|
|
145
|
+
|
|
146
|
+
return changed(
|
|
147
|
+
{
|
|
148
|
+
status: event.type === "load.resolved" ? "ready" : "failed",
|
|
149
|
+
epoch: current,
|
|
150
|
+
filter: state.filter,
|
|
151
|
+
groups,
|
|
152
|
+
rows,
|
|
153
|
+
keys,
|
|
154
|
+
// Each result set opens on its first row; `current` only marks the selected item.
|
|
155
|
+
highlight: { mode: state.highlight.mode, activeKey: keys[0] ?? null },
|
|
156
|
+
},
|
|
157
|
+
late ? [] : [{ type: "cancel.load" }],
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (event.type === "pointer.move") {
|
|
162
|
+
if (!event.moved || (state.highlight.mode === "mouse" && state.highlight.activeKey === event.key))
|
|
163
|
+
return unchanged(state)
|
|
164
|
+
|
|
165
|
+
return changed({ ...state, highlight: { mode: "mouse", activeKey: event.key } })
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (event.type === "pointer.leave") {
|
|
169
|
+
if (state.highlight.mode === "keyboard" || state.highlight.activeKey === null) return unchanged(state)
|
|
170
|
+
|
|
171
|
+
return changed({ ...state, highlight: { mode: "mouse", activeKey: null } })
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (event.type === "active.set") return highlight(state, event.key || null)
|
|
175
|
+
|
|
176
|
+
if (event.type === "active.reset") return state.keys.length ? highlight(state, state.keys[0]) : unchanged(state)
|
|
177
|
+
|
|
178
|
+
return keyDown(state, event)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function selectListLoading<T>(state: ListState<T>) {
|
|
182
|
+
return state.status === "loading"
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function selectListFailed<T>(state: ListState<T>) {
|
|
186
|
+
return state.status === "failed"
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** What the list says when it has no rows to show. */
|
|
190
|
+
export function selectListEmptyState<T>(state: ListState<T>): ListEmptyState {
|
|
191
|
+
if (state.status === "loading") return { type: "loading" }
|
|
192
|
+
|
|
193
|
+
if (state.status === "failed") return { type: "failed" }
|
|
194
|
+
|
|
195
|
+
return { type: "empty", query: state.filter.query }
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The highlighted row and its index among all rows. */
|
|
199
|
+
export function listActive<T>(state: Pick<ListState<T>, "rows" | "keys" | "highlight">) {
|
|
200
|
+
const index = state.highlight.activeKey === null ? -1 : state.keys.indexOf(state.highlight.activeKey)
|
|
201
|
+
|
|
202
|
+
return index < 0 ? undefined : { item: state.rows[index], index }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Where the list scrolls to keep the keyboard highlight in view; the pointer never scrolls it. */
|
|
206
|
+
export function listScrollTarget<T>(
|
|
207
|
+
state: Pick<ListState<T>, "keys" | "highlight">,
|
|
208
|
+
): { type: "none" } | { type: "top" } | { type: "item"; key: string } {
|
|
209
|
+
const key = state.highlight.activeKey
|
|
210
|
+
|
|
211
|
+
if (state.highlight.mode === "mouse" || key === null || state.keys.length === 0) return { type: "none" }
|
|
212
|
+
|
|
213
|
+
if (key === state.keys[0]) return { type: "top" }
|
|
214
|
+
|
|
215
|
+
return { type: "item", key }
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function groupItems<T>(items: T[], config: Pick<ListConfig<T>, "groupBy" | "sortBy" | "sortGroupsBy">) {
|
|
219
|
+
// A plain object keeps the group order of `Object.entries`, where numeric-looking categories sort first.
|
|
220
|
+
const byCategory: Record<string, T[]> = {}
|
|
221
|
+
|
|
222
|
+
for (const item of items) {
|
|
223
|
+
const category = config.groupBy ? config.groupBy(item) : ""
|
|
224
|
+
byCategory[category] ??= []
|
|
225
|
+
byCategory[category].push(item)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const groups = Object.entries(byCategory).map(([category, group]) => ({
|
|
229
|
+
category,
|
|
230
|
+
items: config.sortBy ? group.sort(config.sortBy) : group,
|
|
231
|
+
}))
|
|
232
|
+
|
|
233
|
+
return config.sortGroupsBy ? groups.sort(config.sortGroupsBy) : groups
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function queryChanged<T>(state: LiveListState<T>, value: string, force: boolean): ListTransition<T> {
|
|
237
|
+
const same = value === state.filter.query
|
|
238
|
+
|
|
239
|
+
if (same && !force) return unchanged(state)
|
|
240
|
+
const notify: ListEffect<T> = { type: "notify.filter", value }
|
|
241
|
+
|
|
242
|
+
// A controlled list waits for the parent to pass the new `filter` back.
|
|
243
|
+
if (state.filter.type === "controlled" && !same) return unchanged(state, [notify])
|
|
244
|
+
const next = load(state, { type: state.filter.type, query: value })
|
|
245
|
+
|
|
246
|
+
return { ...next, effects: [notify, ...next.effects] }
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function load<T>(state: LiveListState<T>, filter: ListFilter): ListTransition<T> {
|
|
250
|
+
const attempt = (state.status === "loading" ? state.attempt : state.epoch) + 1
|
|
251
|
+
|
|
252
|
+
return changed(
|
|
253
|
+
{
|
|
254
|
+
status: "loading",
|
|
255
|
+
attempt,
|
|
256
|
+
filter,
|
|
257
|
+
groups: state.groups,
|
|
258
|
+
rows: state.rows,
|
|
259
|
+
keys: state.keys,
|
|
260
|
+
highlight: state.highlight,
|
|
261
|
+
},
|
|
262
|
+
[{ type: "load", attempt, query: filter.query }],
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function highlight<T>(state: LiveListState<T>, activeKey: string | null): ListTransition<T> {
|
|
267
|
+
if (activeKey === state.highlight.activeKey) return unchanged(state)
|
|
268
|
+
|
|
269
|
+
return changed({ ...state, highlight: { mode: state.highlight.mode, activeKey } })
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function keyDown<T>(state: ListState<T>, event: ListKeyDown): ListTransition<T> {
|
|
273
|
+
const next: ListState<T> =
|
|
274
|
+
state.highlight.mode === "keyboard" ? state : { ...state, highlight: { ...state.highlight, mode: "keyboard" } }
|
|
275
|
+
|
|
276
|
+
if (event.claimed) return changed(next)
|
|
277
|
+
|
|
278
|
+
if (event.key === "Enter" && !event.composing) {
|
|
279
|
+
const active = listActive(next)
|
|
280
|
+
|
|
281
|
+
return changed(next, active ? [{ type: "select", item: active.item, index: active.index }] : [], true)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const move = navigate(event, next.keys, next.highlight.activeKey)
|
|
285
|
+
|
|
286
|
+
if (!move) return changed(next)
|
|
287
|
+
|
|
288
|
+
if (move.key === undefined) return changed(next, [], true)
|
|
289
|
+
|
|
290
|
+
return changed({ ...next, highlight: { mode: "keyboard", activeKey: move.key } }, [], true)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function navigate(event: ListKeyDown, keys: string[], active: string | null): { key?: string } | undefined {
|
|
294
|
+
const index = active === null ? -1 : keys.indexOf(active)
|
|
295
|
+
|
|
296
|
+
if (event.ctrl && !event.meta && !event.alt && !event.shift) {
|
|
297
|
+
if (event.key !== "n" && event.key !== "p") return
|
|
298
|
+
|
|
299
|
+
return { key: step(keys, index, event.key === "n" ? 1 : -1) }
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Option+Arrow and Cmd+Arrow edit text on macOS.
|
|
303
|
+
if (event.alt || event.meta || keys.length === 0) return
|
|
304
|
+
|
|
305
|
+
if (event.key === "ArrowDown") return { key: step(keys, index, 1) }
|
|
306
|
+
|
|
307
|
+
if (event.key === "ArrowUp") return { key: step(keys, index, -1) }
|
|
308
|
+
|
|
309
|
+
if (event.search) return
|
|
310
|
+
|
|
311
|
+
if (event.key === "Home") return { key: keys[0] }
|
|
312
|
+
|
|
313
|
+
if (event.key === "End") return { key: keys[keys.length - 1] }
|
|
314
|
+
|
|
315
|
+
if (event.key !== "Tab" || index < 0) return
|
|
316
|
+
const next = index + (event.shift ? -1 : 1)
|
|
317
|
+
|
|
318
|
+
if (next < 0 || next >= keys.length) return
|
|
319
|
+
|
|
320
|
+
return { key: keys[next] }
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function step(keys: string[], index: number, direction: 1 | -1) {
|
|
324
|
+
if (keys.length === 0) return
|
|
325
|
+
|
|
326
|
+
if (index < 0) return direction === 1 ? keys[0] : keys[keys.length - 1]
|
|
327
|
+
|
|
328
|
+
return keys[(index + direction + keys.length) % keys.length]
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function filterItems<T>(items: T[], query: string, config: ListConfig<T>) {
|
|
332
|
+
const needle = query.toLowerCase()
|
|
333
|
+
|
|
334
|
+
return groupItems(needle ? search(items, needle, config) : items, config)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function search<T>(all: T[], needle: string, config: ListConfig<T>) {
|
|
338
|
+
const skipFilter = config.skipFilter
|
|
339
|
+
const filterable = skipFilter ? all.filter((item) => !skipFilter(item)) : all
|
|
340
|
+
const skipped = skipFilter ? all.filter(skipFilter) : []
|
|
341
|
+
|
|
342
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- plain string lists have no keys to search by
|
|
343
|
+
const strings = !config.filterKeys && filterable.every((e) => typeof e === "string")
|
|
344
|
+
|
|
345
|
+
// SAFETY: when `strings` holds, every element is a string, so the matched targets are the items.
|
|
346
|
+
const filtered = strings
|
|
347
|
+
? (fuzzysort.go(needle, filterable as string[]).map((x) => x.target) as T[])
|
|
348
|
+
: fuzzysort.go(needle, filterable, { keys: config.filterKeys! }).map((x) => x.obj)
|
|
349
|
+
|
|
350
|
+
return skipped.length ? [...filtered, ...skipped] : filtered
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function changed<T>(state: ListState<T>, effects: ListEffect<T>[] = [], handled = false): ListTransition<T> {
|
|
354
|
+
return { state, effects, handled }
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function unchanged<T>(state: ListState<T>, effects: ListEffect<T>[] = []): ListTransition<T> {
|
|
358
|
+
return { state, effects, handled: false }
|
|
359
|
+
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { batch, createComputed, createMemo, createReaction, createSignal, on, onCleanup, untrack } from "solid-js"
|
|
2
|
+
import {
|
|
3
|
+
createListState,
|
|
4
|
+
LIST_LOAD_TIMEOUT_MS,
|
|
5
|
+
selectListFailed,
|
|
6
|
+
selectListLoading,
|
|
7
|
+
transitionList,
|
|
8
|
+
type ListEvent,
|
|
9
|
+
type ListGroup,
|
|
10
|
+
} from "./list-machine"
|
|
11
|
+
|
|
12
|
+
export { groupItems } from "./list-machine"
|
|
5
13
|
|
|
6
14
|
export interface FilteredListProps<T> {
|
|
7
15
|
items: T[] | ((filter: string) => T[] | Promise<T[]>)
|
|
@@ -10,134 +18,115 @@ export interface FilteredListProps<T> {
|
|
|
10
18
|
current?: T
|
|
11
19
|
groupBy?: (x: T) => string
|
|
12
20
|
sortBy?: (a: T, b: T) => number
|
|
13
|
-
sortGroupsBy?: (a:
|
|
21
|
+
sortGroupsBy?: (a: ListGroup<T>, b: ListGroup<T>) => number
|
|
14
22
|
skipFilter?: (item: T) => boolean
|
|
15
23
|
onSelect?: (value: T | undefined, index: number) => void
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
items: T[],
|
|
20
|
-
props: Pick<FilteredListProps<T>, "groupBy" | "sortBy" | "sortGroupsBy">,
|
|
21
|
-
) {
|
|
22
|
-
// A plain object keeps the group order of `Object.entries`, where numeric-looking categories sort first.
|
|
23
|
-
const byCategory: Record<string, T[]> = {}
|
|
24
|
-
|
|
25
|
-
for (const item of items) {
|
|
26
|
-
const category = props.groupBy ? props.groupBy(item) : ""
|
|
27
|
-
byCategory[category] ??= []
|
|
28
|
-
byCategory[category].push(item)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const groups = Object.entries(byCategory).map(([category, group]) => ({
|
|
32
|
-
category,
|
|
33
|
-
items: props.sortBy ? group.sort(props.sortBy) : group,
|
|
34
|
-
}))
|
|
35
|
-
|
|
36
|
-
return props.sortGroupsBy ? groups.sort(props.sortGroupsBy) : groups
|
|
24
|
+
/** Makes the query parent-owned: the list shows this value and reports edits through `onFilter`. */
|
|
25
|
+
filter?: string
|
|
26
|
+
onFilter?: (value: string) => void
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
export function useFilteredList<T>(props: FilteredListProps<T>) {
|
|
40
|
-
const [
|
|
30
|
+
const [state, setState] = createSignal(createListState<T>(props.filter))
|
|
31
|
+
let loadTimer: ReturnType<typeof setTimeout> | undefined
|
|
41
32
|
|
|
42
|
-
|
|
33
|
+
const dispatch = (event: ListEvent<T>, keyboard?: KeyboardEvent) => {
|
|
34
|
+
const result = transitionList(untrack(state), event, props)
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
if (result.handled) keyboard?.preventDefault()
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
// A synchronous load settles inside the batch, so readers never see its `loading` step.
|
|
39
|
+
batch(() => {
|
|
40
|
+
setState(() => result.state)
|
|
41
|
+
result.effects.forEach((effect) => {
|
|
42
|
+
if (effect.type === "cancel.load") clearTimeout(loadTimer)
|
|
50
43
|
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
if (effect.type === "load") load(effect.attempt, effect.query)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
result.effects.forEach((effect) => {
|
|
48
|
+
if (effect.type === "notify.filter") props.onFilter?.(effect.value)
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
? (fuzzysort.go(needle, filterable as string[]).map((x) => x.target) as T[])
|
|
57
|
-
: fuzzysort.go(needle, filterable, { keys: props.filterKeys! }).map((x) => x.obj)
|
|
58
|
-
|
|
59
|
-
return skipped.length ? [...filtered, ...skipped] : filtered
|
|
50
|
+
if (effect.type === "select") props.onSelect?.(effect.item, effect.index)
|
|
51
|
+
})
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
filter: store.filter,
|
|
65
|
-
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- `items` is either a list or a loader for one
|
|
66
|
-
items: typeof props.items === "function" ? props.items(store.filter) : props.items,
|
|
67
|
-
}),
|
|
68
|
-
async ({ filter, items }) => {
|
|
69
|
-
const query = filter ?? ""
|
|
70
|
-
const needle = query.toLowerCase()
|
|
71
|
-
const all = (await Promise.resolve(items)) || []
|
|
72
|
-
|
|
73
|
-
const matched = needle ? search(all, needle) : all
|
|
74
|
-
|
|
75
|
-
return groupItems(matched, props)
|
|
76
|
-
},
|
|
77
|
-
{ initialValue: empty },
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
const flat = createMemo(() => (grouped.latest || []).flatMap((x) => x.items))
|
|
81
|
-
|
|
82
|
-
// Lists open on their first row; `current` only marks the selected item.
|
|
83
|
-
const list = createList({
|
|
84
|
-
items: () => flat().map(props.key),
|
|
85
|
-
initialActive: flat()[0] ? props.key(flat()[0]) : "",
|
|
86
|
-
loop: true,
|
|
87
|
-
})
|
|
54
|
+
// Tracks what the last load read (`props.items`, or the signals `items(query)` reads) and reloads when it changes.
|
|
55
|
+
const track = createReaction(() => dispatch({ type: "items.reload" }))
|
|
88
56
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
57
|
+
const load = (attempt: number, query: string) => {
|
|
58
|
+
clearTimeout(loadTimer)
|
|
59
|
+
track(() => {
|
|
60
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- `items` is either a list or a loader for one
|
|
61
|
+
const items = typeof props.items === "function" ? props.items(query) : props.items
|
|
62
|
+
untrack(() => settle(attempt, items))
|
|
63
|
+
})
|
|
94
64
|
}
|
|
95
65
|
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (event.key === "n" || event.key === "p") {
|
|
105
|
-
event.preventDefault()
|
|
106
|
-
|
|
107
|
-
const navEvent = new KeyboardEvent("keydown", {
|
|
108
|
-
key: event.key === "n" ? "ArrowDown" : "ArrowUp",
|
|
109
|
-
bubbles: true,
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
list.onKeyDown(navEvent)
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
// Skip list navigation for text editing shortcuts (e.g., Option+Arrow, Option+Backspace on macOS)
|
|
116
|
-
if (event.altKey || event.metaKey) return
|
|
117
|
-
list.onKeyDown(event)
|
|
118
|
-
}
|
|
66
|
+
const settle = (attempt: number, items: T[] | Promise<T[]>) => {
|
|
67
|
+
if (Array.isArray(items)) return dispatch({ type: "load.resolved", attempt, items })
|
|
68
|
+
|
|
69
|
+
loadTimer = setTimeout(() => dispatch({ type: "load.timed-out", attempt }), LIST_LOAD_TIMEOUT_MS)
|
|
70
|
+
void items.then(
|
|
71
|
+
(items) => dispatch({ type: "load.resolved", attempt, items: items ?? [] }),
|
|
72
|
+
() => dispatch({ type: "load.failed", attempt }),
|
|
73
|
+
)
|
|
119
74
|
}
|
|
120
75
|
|
|
121
|
-
|
|
122
|
-
on(
|
|
123
|
-
|
|
124
|
-
|
|
76
|
+
createComputed(
|
|
77
|
+
on(
|
|
78
|
+
() => props.filter,
|
|
79
|
+
(value) => dispatch(value === undefined ? { type: "filter.uncontrolled" } : { type: "filter.controlled", value }),
|
|
80
|
+
{ defer: true },
|
|
81
|
+
),
|
|
125
82
|
)
|
|
126
83
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
84
|
+
onCleanup(() => dispatch({ type: "disposed" }))
|
|
85
|
+
|
|
86
|
+
dispatch({ type: "items.reload" })
|
|
87
|
+
|
|
88
|
+
const groups = createMemo(() => state().groups)
|
|
89
|
+
const loading = createMemo(() => selectListLoading(state()))
|
|
90
|
+
const failed = createMemo(() => selectListFailed(state()))
|
|
130
91
|
|
|
131
92
|
return {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
93
|
+
state,
|
|
94
|
+
dispatch,
|
|
95
|
+
grouped: {
|
|
96
|
+
get latest() {
|
|
97
|
+
return groups()
|
|
98
|
+
},
|
|
99
|
+
get loading() {
|
|
100
|
+
return loading()
|
|
101
|
+
},
|
|
102
|
+
get state(): "ready" | "refreshing" | "errored" {
|
|
103
|
+
if (loading()) return "refreshing"
|
|
104
|
+
|
|
105
|
+
return failed() ? "errored" : "ready"
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
filter: createMemo(() => state().filter.query),
|
|
109
|
+
flat: createMemo(() => state().rows),
|
|
110
|
+
active: createMemo(() => state().highlight.activeKey),
|
|
111
|
+
reset: () => dispatch({ type: "active.reset" }),
|
|
112
|
+
refetch: () => dispatch({ type: "items.reload" }),
|
|
113
|
+
clear: () => dispatch({ type: "query.change", value: "" }),
|
|
114
|
+
onInput: (value: string) => dispatch({ type: "query.change", value }),
|
|
115
|
+
setActive: (key: string | null) => dispatch({ type: "active.set", key }),
|
|
116
|
+
onKeyDown: (event: KeyboardEvent, options?: { search?: boolean; claimed?: boolean }) =>
|
|
117
|
+
dispatch(
|
|
118
|
+
{
|
|
119
|
+
type: "key.down",
|
|
120
|
+
key: event.key,
|
|
121
|
+
ctrl: event.ctrlKey,
|
|
122
|
+
alt: event.altKey,
|
|
123
|
+
meta: event.metaKey,
|
|
124
|
+
shift: event.shiftKey,
|
|
125
|
+
composing: event.isComposing,
|
|
126
|
+
search: options?.search === true,
|
|
127
|
+
claimed: options?.claimed === true,
|
|
128
|
+
},
|
|
129
|
+
event,
|
|
130
|
+
),
|
|
142
131
|
}
|
|
143
132
|
}
|
package/src/i18n/en.ts
CHANGED
|
@@ -72,6 +72,8 @@ const source = {
|
|
|
72
72
|
"ui.sessionTurn.diffs.showAll": "Show all",
|
|
73
73
|
"ui.sessionTurn.diffs.showLess": "Show less",
|
|
74
74
|
"ui.sessionTurn.diffs.more": "+{{count}} more files",
|
|
75
|
+
"ui.sessionTurn.diffs.failed": "Diff unavailable",
|
|
76
|
+
"ui.sessionTurn.diffs.retry": "Retry",
|
|
75
77
|
|
|
76
78
|
"ui.sessionTurn.retry.retrying": "retrying",
|
|
77
79
|
"ui.sessionTurn.retry.inSeconds": "in {{seconds}}s",
|
|
@@ -151,6 +153,7 @@ const source = {
|
|
|
151
153
|
|
|
152
154
|
"ui.list.loading": "Loading",
|
|
153
155
|
"ui.list.empty": "No results",
|
|
156
|
+
"ui.list.failed": "Failed to load results",
|
|
154
157
|
"ui.list.clearFilter": "Clear filter",
|
|
155
158
|
"ui.list.emptyWithFilter.prefix": "No results for",
|
|
156
159
|
"ui.list.emptyWithFilter.suffix": "",
|
|
@@ -281,7 +284,8 @@ const source = {
|
|
|
281
284
|
"ui.message.copyMessage": "Copy message",
|
|
282
285
|
"ui.message.copyFullMessage": "Copy full message",
|
|
283
286
|
"ui.message.forkMessage": "Fork from here",
|
|
284
|
-
"ui.message.revertMessage": "
|
|
287
|
+
"ui.message.revertMessage": "Revert to here",
|
|
288
|
+
"ui.message.undoMessage": "Undo",
|
|
285
289
|
"ui.message.moreActions": "More actions",
|
|
286
290
|
"ui.message.moveToQueue": "Move to queue",
|
|
287
291
|
"ui.message.pending": "Pending",
|
|
@@ -294,6 +298,7 @@ const source = {
|
|
|
294
298
|
"ui.message.duration.seconds": "{{count}}s",
|
|
295
299
|
"ui.message.duration.minutesSeconds": "{{minutes}}m {{seconds}}s",
|
|
296
300
|
"ui.message.duration.hoursMinutes": "{{hours}}h {{minutes}}m",
|
|
301
|
+
"ui.message.tokensPerSecond": "{{value}} tok/s",
|
|
297
302
|
"ui.message.interrupted": "Interrupted",
|
|
298
303
|
"ui.message.modelVariant": "{{model}} ({{variant}})",
|
|
299
304
|
"ui.message.time.justNow": "Just now",
|
package/src/i18n/uk.ts
CHANGED
|
@@ -120,8 +120,8 @@ export const dict = {
|
|
|
120
120
|
"ui.sessionTurn.status.consideringNextSteps": "Розгляд наступних кроків",
|
|
121
121
|
|
|
122
122
|
"ui.messagePart.diagnostic.error": "Помилка",
|
|
123
|
-
"ui.messagePart.title.edit": "
|
|
124
|
-
"ui.messagePart.title.write": "
|
|
123
|
+
"ui.messagePart.title.edit": "Редагування",
|
|
124
|
+
"ui.messagePart.title.write": "Запис",
|
|
125
125
|
"ui.messagePart.option.typeOwnAnswer": "Введіть власну відповідь",
|
|
126
126
|
"ui.messagePart.review.title": "Перевірте свої відповіді",
|
|
127
127
|
"ui.messagePart.questions.dismissed": "Запитання відхилено",
|
|
@@ -240,7 +240,7 @@ export const dict = {
|
|
|
240
240
|
"ui.question.custom.placeholder": "Введіть свою відповідь…",
|
|
241
241
|
"ui.messagePart.context.match.one": "({{count}} збіг)",
|
|
242
242
|
"ui.messagePart.context.match.other": "({{count}} збігу)",
|
|
243
|
-
"ui.tool.execute": "
|
|
243
|
+
"ui.tool.execute": "Виконання",
|
|
244
244
|
"ui.tool.loadedFile": "Завантажено файл {{path}}",
|
|
245
245
|
"ui.tool.loadedSkill": "Завантажено навичку {{name}}",
|
|
246
246
|
"ui.tool.shell.writingCommand": "Записування команди...",
|
package/src/icons/catalog.ts
CHANGED
|
@@ -2,6 +2,14 @@ import { additionalIcons, additionalIconViewBox } from "./icon/additional-icons"
|
|
|
2
2
|
|
|
3
3
|
// Consumers center the SVG viewport, so each icon must center its artwork within its viewBox.
|
|
4
4
|
const icons = {
|
|
5
|
+
"outline-list-changelog": {
|
|
6
|
+
viewBox: "0 0 16 16",
|
|
7
|
+
body: `<path d="M3 14.5V15H4V14.5H3.5H3ZM4 1.5V1H3V1.5H3.5H4ZM8.5 1.5V1H8V1.5H8.5ZM14.5 1.5H15V1H14.5V1.5ZM14.5 6.5V7H15V6.5H14.5ZM8.5 6.5H8V7H8.5V6.5ZM8.5 9.5V9H8V9.5H8.5ZM14.5 9.5H15V9H14.5V9.5ZM14.5 14.5V15H15V14.5H14.5ZM8.5 14.5H8V15H8.5V14.5ZM3.5 6H4V1.5H3.5H3V6H3.5ZM8.5 1.5V2H14.5V1.5V1H8.5V1.5ZM14.5 1.5H14V6.5H14.5H15V1.5H14.5ZM14.5 6.5V6H8.5V6.5V7H14.5V6.5ZM8.5 6.5H9V1.5H8.5H8V6.5H8.5ZM8.5 9.5V10H14.5V9.5V9H8.5V9.5ZM14.5 9.5H14V14.5H14.5H15V9.5H14.5ZM14.5 14.5V14H8.5V14.5V15H14.5V14.5ZM8.5 14.5H9V9.5H8.5H8V14.5H8.5ZM3.5 10V10.5C4.8807 10.5 6 9.38075 6 8H5.5H5C5 8.82845 4.32843 9.5 3.5 9.5V10ZM5.5 8H6C6 6.61925 4.8807 5.5 3.5 5.5V6V6.5C4.32843 6.5 5 7.17155 5 8H5.5ZM3.5 6V5.5C2.1193 5.5 1 6.61925 1 8H1.5H2C2 7.17155 2.67157 6.5 3.5 6.5V6ZM1.5 8H1C1 9.38075 2.1193 10.5 3.5 10.5V10V9.5C2.67157 9.5 2 8.82845 2 8H1.5ZM3.5 14.5H4V10H3.5H3V14.5H3.5Z" fill="currentColor"/>`,
|
|
8
|
+
},
|
|
9
|
+
"outline-pair": {
|
|
10
|
+
viewBox: "0 0 16 16",
|
|
11
|
+
body: `<path d="M4.5 10V13.5H11.5V10" stroke="currentColor"/><path d="M3.5 4.5V2.5H5.5V4.5" stroke-linecap="square" stroke="currentColor"/><path d="M10.5 4.5V2.5H12.5V4.5" stroke-linecap="square" stroke="currentColor"/><path d="M9.5 4.5H13.5V10.5H9.5V4.5Z" stroke-linecap="square" stroke="currentColor"/><path d="M2.5 4.5H6.5V10.5H2.5V4.5Z" stroke-linecap="square" stroke="currentColor"/>`,
|
|
12
|
+
},
|
|
5
13
|
lock: {
|
|
6
14
|
viewBox: "0 0 16 16",
|
|
7
15
|
body: `<rect x="3.5" y="7" width="9" height="7" rx="1" stroke="currentColor"/><path d="M5 7V5a3 3 0 0 1 6 0v2M8 10v1" stroke="currentColor" stroke-linecap="round"/>`,
|