@opencode/ui 2.2.4 → 2.2.6

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.
Files changed (127) hide show
  1. package/dist/actions/button/button.d.ts +2 -2
  2. package/dist/actions/icon-button/icon-button.d.ts +1 -1
  3. package/dist/components/animated-number-machine.d.ts +95 -0
  4. package/dist/components/file-icon-machine.d.ts +40 -0
  5. package/dist/components/file-icon.d.ts +0 -2
  6. package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
  7. package/dist/components/image-flight-machine.d.ts +135 -0
  8. package/dist/components/image-zoom-machine.d.ts +95 -0
  9. package/dist/components/image-zoom.d.ts +6 -3
  10. package/dist/components/list.d.ts +2 -6
  11. package/dist/components/menu-scroll.d.ts +12 -0
  12. package/dist/components/popover-machine.d.ts +96 -0
  13. package/dist/components/popover.d.ts +2 -2
  14. package/dist/components/resize-handle-machine.d.ts +71 -0
  15. package/dist/components/resize-handle.d.ts +2 -0
  16. package/dist/components/scroll-view-machine.d.ts +68 -0
  17. package/dist/components/scroll-view.d.ts +2 -2
  18. package/dist/components/spinner.d.ts +11 -3
  19. package/dist/components/text-field-machine.d.ts +62 -0
  20. package/dist/components/text-reveal-machine.d.ts +90 -0
  21. package/dist/components/typewriter-machine.d.ts +62 -0
  22. package/dist/context/dialog-machine.d.ts +125 -0
  23. package/dist/context/dialog.d.ts +17 -16
  24. package/dist/data-display/line-comment/line-comment.d.ts +9 -0
  25. package/dist/data-display/line-comment/machine.d.ts +157 -0
  26. package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
  27. package/dist/data-display/project-avatar/animation.d.ts +1 -1
  28. package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
  29. package/dist/feedback/toast/machine.d.ts +57 -0
  30. package/dist/feedback/toast/toast.d.ts +1 -1
  31. package/dist/forms/checkbox/checkbox.d.ts +6 -1
  32. package/dist/forms/select/machine.d.ts +45 -0
  33. package/dist/forms/select/select.d.ts +4 -0
  34. package/dist/forms/text-input/text-input.d.ts +4 -2
  35. package/dist/forms/textarea/textarea.d.ts +1 -0
  36. package/dist/forms/typeahead/machine.d.ts +85 -0
  37. package/dist/hooks/auto-scroll-machine.d.ts +89 -0
  38. package/dist/hooks/create-auto-scroll.d.ts +1 -1
  39. package/dist/hooks/list-machine.d.ts +150 -0
  40. package/dist/hooks/use-filtered-list.d.ts +21 -35
  41. package/dist/i18n/en.d.ts +5 -0
  42. package/dist/icons/catalog.d.ts +8 -0
  43. package/dist/navigation/menu/machine.d.ts +49 -0
  44. package/dist/navigation/menu/menu.d.ts +5 -3
  45. package/dist/navigation/segmented-control/machine.d.ts +46 -0
  46. package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
  47. package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
  48. package/dist/overlays/tooltip/machine.d.ts +146 -0
  49. package/dist/theme/context.d.ts +38 -14
  50. package/dist/theme/machine.d.ts +174 -0
  51. package/dist/typography/text-shimmer/machine.d.ts +48 -0
  52. package/package.json +19 -3
  53. package/src/actions/button/button.tsx +11 -6
  54. package/src/actions/icon-button/icon-button.tsx +17 -4
  55. package/src/components/animated-number-machine.ts +214 -0
  56. package/src/components/animated-number.tsx +134 -83
  57. package/src/components/file-icon-machine.ts +78 -0
  58. package/src/components/file-icon.tsx +96 -579
  59. package/src/components/file-icons/choose-icon-name.ts +574 -0
  60. package/src/components/image-flight-machine.ts +247 -0
  61. package/src/components/image-preview.css +5 -2
  62. package/src/components/image-preview.tsx +390 -252
  63. package/src/components/image-zoom-machine.ts +191 -0
  64. package/src/components/image-zoom.ts +22 -14
  65. package/src/components/list.tsx +46 -137
  66. package/src/components/menu-scroll.css +70 -0
  67. package/src/components/menu-scroll.tsx +161 -0
  68. package/src/components/popover-machine.ts +198 -0
  69. package/src/components/popover.tsx +157 -89
  70. package/src/components/resize-handle-machine.ts +174 -0
  71. package/src/components/resize-handle.tsx +116 -67
  72. package/src/components/scroll-view-machine.ts +244 -0
  73. package/src/components/scroll-view.tsx +163 -116
  74. package/src/components/spinner.css +18 -5
  75. package/src/components/spinner.tsx +28 -14
  76. package/src/components/text-field-machine.ts +102 -0
  77. package/src/components/text-field.tsx +78 -24
  78. package/src/components/text-reveal-machine.ts +184 -0
  79. package/src/components/text-reveal.tsx +96 -93
  80. package/src/components/typewriter-machine.ts +134 -0
  81. package/src/components/typewriter.tsx +50 -39
  82. package/src/context/dialog-machine.ts +280 -0
  83. package/src/context/dialog.tsx +168 -177
  84. package/src/data-display/line-comment/line-comment.tsx +196 -132
  85. package/src/data-display/line-comment/machine.ts +391 -0
  86. package/src/data-display/project-avatar/animation-machine.ts +182 -0
  87. package/src/data-display/project-avatar/animation.ts +67 -38
  88. package/src/feedback/activity-ring/activity-ring.tsx +1 -1
  89. package/src/feedback/toast/machine.ts +115 -0
  90. package/src/feedback/toast/toast.tsx +55 -59
  91. package/src/forms/checkbox/checkbox-compact.css +169 -0
  92. package/src/forms/checkbox/checkbox.tsx +93 -31
  93. package/src/forms/search-list/search-list.css +5 -1
  94. package/src/forms/search-list/search-list.tsx +4 -4
  95. package/src/forms/select/machine.ts +81 -0
  96. package/src/forms/select/select.css +59 -17
  97. package/src/forms/select/select.tsx +67 -31
  98. package/src/forms/text-input/text-input.css +30 -16
  99. package/src/forms/text-input/text-input.tsx +6 -2
  100. package/src/forms/textarea/textarea.css +13 -8
  101. package/src/forms/textarea/textarea.tsx +3 -1
  102. package/src/forms/typeahead/machine.ts +253 -0
  103. package/src/forms/typeahead/typeahead.tsx +75 -66
  104. package/src/hooks/auto-scroll-machine.ts +261 -0
  105. package/src/hooks/create-auto-scroll.tsx +110 -205
  106. package/src/hooks/list-machine.ts +359 -0
  107. package/src/hooks/use-filtered-list.tsx +101 -112
  108. package/src/i18n/en.ts +6 -1
  109. package/src/icons/catalog.ts +8 -0
  110. package/src/navigation/menu/machine.ts +109 -0
  111. package/src/navigation/menu/menu.tsx +130 -22
  112. package/src/navigation/segmented-control/machine.ts +72 -0
  113. package/src/navigation/segmented-control/segmented-control.tsx +46 -46
  114. package/src/overlays/dialog/dialog.tsx +7 -1
  115. package/src/overlays/mcp-sign-in/machine.ts +343 -0
  116. package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
  117. package/src/overlays/tooltip/machine.ts +303 -0
  118. package/src/overlays/tooltip/tooltip.tsx +157 -92
  119. package/src/styles/theme.css +10 -2
  120. package/src/styles/tokens/theme.css +13 -0
  121. package/src/theme/context.tsx +192 -269
  122. package/src/theme/machine.ts +508 -0
  123. package/src/theme/themes/oc-2.json +2 -0
  124. package/src/theme/v2/mapping.ts +12 -8
  125. package/src/typography/text-shimmer/machine.ts +90 -0
  126. package/src/typography/text-shimmer/text-shimmer.css +71 -39
  127. 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 fuzzysort from "fuzzysort"
2
- import { createEffect, createMemo, createResource, on } from "solid-js"
3
- import { createStore } from "solid-js/store"
4
- import { createList } from "solid-list"
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: { category: string; items: T[] }, b: { category: string; items: T[] }) => number
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
- export function groupItems<T>(
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 [store, setStore] = createStore<{ filter: string }>({ filter: "" })
30
+ const [state, setState] = createSignal(createListState<T>(props.filter))
31
+ let loadTimer: ReturnType<typeof setTimeout> | undefined
41
32
 
42
- type Group = { category: string; items: [T, ...T[]] }
33
+ const dispatch = (event: ListEvent<T>, keyboard?: KeyboardEvent) => {
34
+ const result = transitionList(untrack(state), event, props)
43
35
 
44
- const empty: Group[] = []
36
+ if (result.handled) keyboard?.preventDefault()
45
37
 
46
- const search = (all: T[], needle: string) => {
47
- const skipFilter = props.skipFilter
48
- const filterable = skipFilter ? all.filter((item) => !skipFilter(item)) : all
49
- const skipped = skipFilter ? all.filter(skipFilter) : []
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
- // oxlint-disable-next-line anti-slop/no-runtime-typeof -- plain string lists have no keys to search by
52
- const strings = !props.filterKeys && filterable.every((e) => typeof e === "string")
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
- // SAFETY: when `strings` holds, every element is a string, so the matched targets are the items.
55
- const filtered = strings
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
- const [grouped, { refetch }] = createResource(
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 reset = () => {
90
- const all = flat()
91
-
92
- if (all.length === 0) return
93
- list.setActive(props.key(all[0]))
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 onKeyDown = (event: KeyboardEvent) => {
97
- if (event.key === "Enter" && !event.isComposing) {
98
- event.preventDefault()
99
- const selectedIndex = flat().findIndex((x) => props.key(x) === list.active())
100
- const selected = flat()[selectedIndex]
101
-
102
- if (selected) props.onSelect?.(selected, selectedIndex)
103
- } else if (event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
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
- createEffect(
122
- on(grouped, () => {
123
- reset()
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
- const onInput = (value: string) => {
128
- setStore("filter", value)
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
- grouped,
133
- filter: () => store.filter,
134
- flat,
135
- reset,
136
- refetch,
137
- clear: () => setStore("filter", ""),
138
- onKeyDown,
139
- onInput,
140
- active: list.active,
141
- setActive: list.setActive,
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": "Rewind to here",
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",
@@ -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"/>`,