@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.
- 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 +12 -0
- 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/line-comment.d.ts +9 -0
- 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/text-input/text-input.d.ts +4 -2
- package/dist/forms/textarea/textarea.d.ts +1 -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 +19 -3
- 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 +70 -0
- package/src/components/menu-scroll.tsx +161 -0
- 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 +196 -132
- 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 +55 -59
- package/src/forms/checkbox/checkbox-compact.css +169 -0
- package/src/forms/checkbox/checkbox.tsx +93 -31
- package/src/forms/search-list/search-list.css +5 -1
- package/src/forms/search-list/search-list.tsx +4 -4
- package/src/forms/select/machine.ts +81 -0
- package/src/forms/select/select.css +59 -17
- package/src/forms/select/select.tsx +67 -31
- package/src/forms/text-input/text-input.css +30 -16
- package/src/forms/text-input/text-input.tsx +6 -2
- package/src/forms/textarea/textarea.css +13 -8
- package/src/forms/textarea/textarea.tsx +3 -1
- package/src/forms/typeahead/machine.ts +253 -0
- package/src/forms/typeahead/typeahead.tsx +75 -66
- 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/icons/catalog.ts +8 -0
- package/src/navigation/menu/machine.ts +109 -0
- package/src/navigation/menu/menu.tsx +130 -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 +157 -92
- package/src/styles/theme.css +10 -2
- package/src/styles/tokens/theme.css +13 -0
- package/src/theme/context.tsx +192 -269
- package/src/theme/machine.ts +508 -0
- package/src/theme/themes/oc-2.json +2 -0
- package/src/theme/v2/mapping.ts +12 -8
- 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
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
border: 0;
|
|
10
10
|
border-radius: 6px;
|
|
11
11
|
outline: 1px solid transparent;
|
|
12
|
-
outline-offset:
|
|
13
|
-
background:
|
|
14
|
-
|
|
15
|
-
box-shadow: var(--v2-elevation-button-neutral);
|
|
12
|
+
outline-offset: -1px;
|
|
13
|
+
background: var(--v2-background-bg-base);
|
|
14
|
+
box-shadow: var(--v2-elevation-input);
|
|
16
15
|
flex: none;
|
|
17
16
|
align-self: stretch;
|
|
18
17
|
transition:
|
|
@@ -21,10 +20,16 @@
|
|
|
21
20
|
box-shadow 85ms ease-out;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
[data-component="textarea-v2"]
|
|
25
|
-
background:
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
[data-component="textarea-v2"][data-surface="layer-1"] {
|
|
24
|
+
background: var(--v2-background-bg-layer-01);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@media (hover: hover) {
|
|
28
|
+
[data-component="textarea-v2"]:where(:hover):not([data-disabled], [data-invalid]):not(:focus-within) {
|
|
29
|
+
box-shadow:
|
|
30
|
+
inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover),
|
|
31
|
+
var(--v2-elevation-input);
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
[data-component="textarea-v2"]:where(:focus-within):not([data-disabled], [data-invalid]) {
|
|
@@ -4,14 +4,16 @@ import "./textarea.css"
|
|
|
4
4
|
export interface TextareaProps extends ComponentProps<"textarea"> {
|
|
5
5
|
/** Error styling for the field and value text. */
|
|
6
6
|
invalid?: boolean
|
|
7
|
+
surface?: "base" | "layer-1"
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export function Textarea(props: TextareaProps) {
|
|
10
|
-
const [local, textareaProps] = splitProps(props, ["class", "classList", "invalid", "disabled", "rows"])
|
|
11
|
+
const [local, textareaProps] = splitProps(props, ["class", "classList", "invalid", "disabled", "rows", "surface"])
|
|
11
12
|
|
|
12
13
|
return (
|
|
13
14
|
<div
|
|
14
15
|
data-component="textarea-v2"
|
|
16
|
+
data-surface={local.surface ?? "base"}
|
|
15
17
|
data-disabled={local.disabled ? "" : undefined}
|
|
16
18
|
data-invalid={local.invalid ? "" : undefined}
|
|
17
19
|
classList={{
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
export const TYPEAHEAD_REQUEST_TIMEOUT_MS = 15_000
|
|
2
|
+
|
|
3
|
+
export type TypeaheadInitial<T> = { readonly items: T[]; readonly failed?: boolean }
|
|
4
|
+
|
|
5
|
+
type TypeaheadLive<T> = {
|
|
6
|
+
/** The input's text; the query is this text trimmed. */
|
|
7
|
+
readonly input: string
|
|
8
|
+
/** The user has typed, so later result changes animate the list height. */
|
|
9
|
+
readonly searched: boolean
|
|
10
|
+
/** Some answer has arrived, so the empty row may show. */
|
|
11
|
+
readonly answered: boolean
|
|
12
|
+
/** The parent's opening results, shown for the empty query. */
|
|
13
|
+
readonly initial: TypeaheadInitial<T> | undefined
|
|
14
|
+
readonly cache: ReadonlyMap<string, T[]>
|
|
15
|
+
readonly shown: T[]
|
|
16
|
+
/** `shown` holds rows the pending query does not match; they stay dimmed instead of collapsing the list. */
|
|
17
|
+
readonly stale: boolean
|
|
18
|
+
/** The last attempt issued, so the next request gets a fresh one. */
|
|
19
|
+
readonly issued: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* `debouncing` waits for typing to pause; `loading` has a request in flight. Both name their `attempt`, and a timer or
|
|
24
|
+
* result from another attempt is ignored. `failed` is the current query's failure only.
|
|
25
|
+
*/
|
|
26
|
+
export type TypeaheadState<T> =
|
|
27
|
+
| (TypeaheadLive<T> & { readonly status: "ready" | "failed" })
|
|
28
|
+
| (TypeaheadLive<T> & { readonly status: "debouncing" | "loading"; readonly attempt: number })
|
|
29
|
+
| { readonly status: "disposed" }
|
|
30
|
+
|
|
31
|
+
export type TypeaheadEvent<T> =
|
|
32
|
+
| { readonly type: "initial.synced"; readonly initial: TypeaheadInitial<T> | undefined }
|
|
33
|
+
| {
|
|
34
|
+
readonly type: "input.changed"
|
|
35
|
+
readonly input: string
|
|
36
|
+
readonly delayMs: number
|
|
37
|
+
readonly match: (item: T, query: string) => boolean
|
|
38
|
+
}
|
|
39
|
+
| { readonly type: "debounce.elapsed"; readonly attempt: number }
|
|
40
|
+
| { readonly type: "retry.requested" }
|
|
41
|
+
| { readonly type: "request.succeeded"; readonly attempt: number; readonly items: T[] }
|
|
42
|
+
| { readonly type: "request.failed"; readonly attempt: number }
|
|
43
|
+
| { readonly type: "request.timed-out"; readonly attempt: number }
|
|
44
|
+
| { readonly type: "disposed" }
|
|
45
|
+
|
|
46
|
+
/** Each effect first cancels the pending debounce or request, then starts its own work. */
|
|
47
|
+
export type TypeaheadEffect =
|
|
48
|
+
| { readonly type: "cancel" }
|
|
49
|
+
| { readonly type: "debounce"; readonly attempt: number; readonly delayMs: number }
|
|
50
|
+
| { readonly type: "request"; readonly attempt: number; readonly query: string }
|
|
51
|
+
|
|
52
|
+
export type TypeaheadTransition<T> = {
|
|
53
|
+
readonly state: TypeaheadState<T>
|
|
54
|
+
readonly effects: readonly TypeaheadEffect[]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type Live<T> = Exclude<TypeaheadState<T>, { status: "disposed" }>
|
|
58
|
+
|
|
59
|
+
const NONE: readonly TypeaheadEffect[] = Object.freeze([])
|
|
60
|
+
|
|
61
|
+
const CANCEL: readonly TypeaheadEffect[] = Object.freeze([Object.freeze({ type: "cancel" })])
|
|
62
|
+
|
|
63
|
+
const DISPOSED = Object.freeze({ status: "disposed" as const })
|
|
64
|
+
|
|
65
|
+
const EMPTY: never[] = []
|
|
66
|
+
|
|
67
|
+
export function createTypeaheadState<T>(initial: TypeaheadInitial<T> | undefined): TypeaheadTransition<T> {
|
|
68
|
+
const live = {
|
|
69
|
+
input: "",
|
|
70
|
+
searched: false,
|
|
71
|
+
answered: initial !== undefined,
|
|
72
|
+
initial,
|
|
73
|
+
cache: new Map<string, T[]>(),
|
|
74
|
+
shown: initial && !initial.failed ? initial.items : [],
|
|
75
|
+
stale: false,
|
|
76
|
+
issued: 0,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (initial) return { state: { ...live, status: initial.failed ? "failed" : "ready" }, effects: NONE }
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
state: { ...live, issued: 1, status: "loading", attempt: 1 },
|
|
83
|
+
effects: [{ type: "request", attempt: 1, query: "" }],
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function transitionTypeahead<T>(state: TypeaheadState<T>, event: TypeaheadEvent<T>): TypeaheadTransition<T> {
|
|
88
|
+
if (state.status === "disposed") return { state, effects: NONE }
|
|
89
|
+
|
|
90
|
+
switch (event.type) {
|
|
91
|
+
case "disposed":
|
|
92
|
+
return { state: DISPOSED, effects: busy(state) ? CANCEL : NONE }
|
|
93
|
+
case "initial.synced":
|
|
94
|
+
return syncInitial(state, event.initial)
|
|
95
|
+
case "input.changed":
|
|
96
|
+
return changeInput(state, event)
|
|
97
|
+
case "debounce.elapsed":
|
|
98
|
+
if (state.status !== "debouncing" || state.attempt !== event.attempt) return { state, effects: NONE }
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
state: { ...state, status: "loading" },
|
|
102
|
+
effects: [{ type: "request", attempt: state.attempt, query: query(state) }],
|
|
103
|
+
}
|
|
104
|
+
case "retry.requested": {
|
|
105
|
+
if (state.status !== "failed") return { state, effects: NONE }
|
|
106
|
+
const attempt = state.issued + 1
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
state: { ...live(state), issued: attempt, status: "loading", attempt },
|
|
110
|
+
effects: [{ type: "request", attempt, query: query(state) }],
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
case "request.succeeded":
|
|
115
|
+
if (state.status !== "loading" || state.attempt !== event.attempt) return { state, effects: NONE }
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
state: {
|
|
119
|
+
...live(state),
|
|
120
|
+
cache: new Map(state.cache).set(query(state), event.items),
|
|
121
|
+
shown: event.items,
|
|
122
|
+
stale: false,
|
|
123
|
+
answered: true,
|
|
124
|
+
status: "ready",
|
|
125
|
+
},
|
|
126
|
+
effects: CANCEL,
|
|
127
|
+
}
|
|
128
|
+
case "request.failed":
|
|
129
|
+
case "request.timed-out":
|
|
130
|
+
if (state.status !== "loading" || state.attempt !== event.attempt) return { state, effects: NONE }
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
state: { ...live(state), shown: EMPTY, stale: false, answered: true, status: "failed" },
|
|
134
|
+
effects: CANCEL,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function selectTypeaheadInput<T>(state: TypeaheadState<T>) {
|
|
140
|
+
return state.status === "disposed" ? "" : state.input
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function selectTypeaheadPending<T>(state: TypeaheadState<T>) {
|
|
144
|
+
return state.status === "debouncing" || state.status === "loading"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function selectTypeaheadFailed<T>(state: TypeaheadState<T>) {
|
|
148
|
+
return state.status === "failed"
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function selectTypeaheadItems<T>(state: TypeaheadState<T>): T[] {
|
|
152
|
+
return state.status === "disposed" ? EMPTY : state.shown
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function selectTypeaheadStale<T>(state: TypeaheadState<T>) {
|
|
156
|
+
return state.status !== "disposed" && state.stale
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function selectTypeaheadAnimateHeight<T>(state: TypeaheadState<T>) {
|
|
160
|
+
return state.status !== "disposed" && state.searched && state.shown.length > 0
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function selectTypeaheadAnswered<T>(state: TypeaheadState<T>) {
|
|
164
|
+
return state.status !== "disposed" && state.answered
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// The parent owns the opening list, so a refresh reaches an open panel for the empty query; a typed query keeps its
|
|
168
|
+
// own results and picks the new list up when it is cleared.
|
|
169
|
+
function syncInitial<T>(state: Live<T>, initial: TypeaheadInitial<T> | undefined): TypeaheadTransition<T> {
|
|
170
|
+
if (initial === state.initial) return { state, effects: NONE }
|
|
171
|
+
|
|
172
|
+
// A request for the empty query is already on its way and answers for itself.
|
|
173
|
+
if (!initial || query(state) !== "" || state.status === "loading")
|
|
174
|
+
return { state: { ...state, initial }, effects: NONE }
|
|
175
|
+
const cache = new Map(state.cache)
|
|
176
|
+
cache.delete("")
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
state: {
|
|
180
|
+
...live(state),
|
|
181
|
+
initial,
|
|
182
|
+
cache,
|
|
183
|
+
shown: initial.failed ? EMPTY : initial.items,
|
|
184
|
+
stale: false,
|
|
185
|
+
answered: true,
|
|
186
|
+
status: initial.failed ? "failed" : "ready",
|
|
187
|
+
},
|
|
188
|
+
effects: NONE,
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// A cached or empty query answers at once; a typed one waits for `delayMs`. Rows narrow while it is pending, and
|
|
193
|
+
// broadening waits for an answer so speculative rows never flash.
|
|
194
|
+
function changeInput<T>(
|
|
195
|
+
state: Live<T>,
|
|
196
|
+
event: Extract<TypeaheadEvent<T>, { type: "input.changed" }>,
|
|
197
|
+
): TypeaheadTransition<T> {
|
|
198
|
+
const next = event.input.trim()
|
|
199
|
+
|
|
200
|
+
if (next === query(state)) {
|
|
201
|
+
if (event.input === state.input && state.searched) return { state, effects: NONE }
|
|
202
|
+
|
|
203
|
+
return { state: { ...state, input: event.input, searched: true }, effects: NONE }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const base = { ...live(state), input: event.input, searched: true }
|
|
207
|
+
const cancel = busy(state) ? CANCEL : NONE
|
|
208
|
+
const opening = next === "" ? state.initial : undefined
|
|
209
|
+
const cached = state.cache.get(next) ?? (opening && !opening.failed ? opening.items : undefined)
|
|
210
|
+
|
|
211
|
+
if (cached)
|
|
212
|
+
return { state: { ...base, shown: cached, stale: false, answered: true, status: "ready" }, effects: cancel }
|
|
213
|
+
|
|
214
|
+
if (opening?.failed)
|
|
215
|
+
return { state: { ...base, shown: EMPTY, stale: false, answered: true, status: "failed" }, effects: cancel }
|
|
216
|
+
const attempt = state.issued + 1
|
|
217
|
+
const narrowed = state.shown.filter((item) => event.match(item, next))
|
|
218
|
+
|
|
219
|
+
const rows =
|
|
220
|
+
narrowed.length > 0 ? { shown: narrowed, stale: false } : { shown: state.shown, stale: state.shown.length > 0 }
|
|
221
|
+
|
|
222
|
+
if (next === "" || event.delayMs <= 0)
|
|
223
|
+
return {
|
|
224
|
+
state: { ...base, ...rows, issued: attempt, status: "loading", attempt },
|
|
225
|
+
effects: [{ type: "request", attempt, query: next }],
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
state: { ...base, ...rows, issued: attempt, status: "debouncing", attempt },
|
|
230
|
+
effects: [{ type: "debounce", attempt, delayMs: event.delayMs }],
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function query<T>(state: Live<T>) {
|
|
235
|
+
return state.input.trim()
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function busy<T>(state: Live<T>) {
|
|
239
|
+
return state.status === "debouncing" || state.status === "loading"
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function live<T>(state: Live<T>): TypeaheadLive<T> {
|
|
243
|
+
return {
|
|
244
|
+
input: state.input,
|
|
245
|
+
searched: state.searched,
|
|
246
|
+
answered: state.answered,
|
|
247
|
+
initial: state.initial,
|
|
248
|
+
cache: state.cache,
|
|
249
|
+
shown: state.shown,
|
|
250
|
+
stale: state.stale,
|
|
251
|
+
issued: state.issued,
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
2
|
-
import { createEffect,
|
|
3
|
-
import { createStore } from "solid-js/store"
|
|
2
|
+
import { createEffect, createSignal, For, type JSX, on, onCleanup, Show, untrack } from "solid-js"
|
|
4
3
|
import { Icon } from "@opencode/ui/icon"
|
|
5
4
|
import { abort } from "@opencode/util/abort"
|
|
6
5
|
import { useI18n } from "../../context/i18n"
|
|
7
6
|
import { Loader } from "../../feedback/loader/loader"
|
|
7
|
+
import { MenuScroll } from "../../components/menu-scroll"
|
|
8
8
|
import { createTypeahead } from "./controller"
|
|
9
|
+
import {
|
|
10
|
+
createTypeaheadState,
|
|
11
|
+
selectTypeaheadAnimateHeight,
|
|
12
|
+
selectTypeaheadAnswered,
|
|
13
|
+
selectTypeaheadFailed,
|
|
14
|
+
selectTypeaheadInput,
|
|
15
|
+
selectTypeaheadItems,
|
|
16
|
+
selectTypeaheadPending,
|
|
17
|
+
selectTypeaheadStale,
|
|
18
|
+
transitionTypeahead,
|
|
19
|
+
TYPEAHEAD_REQUEST_TIMEOUT_MS,
|
|
20
|
+
type TypeaheadEffect,
|
|
21
|
+
type TypeaheadEvent,
|
|
22
|
+
} from "./machine"
|
|
9
23
|
|
|
10
24
|
export { createTypeahead } from "./controller"
|
|
11
25
|
|
|
@@ -28,77 +42,72 @@ export function Typeahead<T>(props: {
|
|
|
28
42
|
children: (item: T) => JSX.Element
|
|
29
43
|
}) {
|
|
30
44
|
const i18n = useI18n()
|
|
31
|
-
|
|
32
|
-
const [
|
|
33
|
-
|
|
34
|
-
searched: boolean
|
|
35
|
-
answered?: string
|
|
36
|
-
failed?: boolean
|
|
37
|
-
loading?: boolean
|
|
38
|
-
}>({ query: "", searched: false, answered: props.initial ? "" : undefined })
|
|
39
|
-
|
|
40
|
-
const cache = new Map<string, T[]>()
|
|
45
|
+
const created = createTypeaheadState(props.initial)
|
|
46
|
+
const [machine, setMachine] = createSignal(created.state)
|
|
47
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
41
48
|
let request: AbortController | undefined
|
|
42
49
|
let input: HTMLInputElement | undefined
|
|
43
|
-
onCleanup(() => abort(request))
|
|
44
50
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
const dispatch = (event: TypeaheadEvent<T>) => {
|
|
52
|
+
const prev = untrack(machine)
|
|
53
|
+
const next = transitionTypeahead(prev, event)
|
|
54
|
+
|
|
55
|
+
if (next.state !== prev) setMachine(next.state)
|
|
56
|
+
next.effects.forEach(run)
|
|
57
|
+
}
|
|
50
58
|
|
|
51
|
-
const
|
|
59
|
+
const run = (effect: TypeaheadEffect) => {
|
|
60
|
+
clearTimeout(timer)
|
|
61
|
+
timer = undefined
|
|
52
62
|
abort(request)
|
|
63
|
+
request = undefined
|
|
64
|
+
|
|
65
|
+
if (effect.type === "cancel") return
|
|
66
|
+
const attempt = effect.attempt
|
|
67
|
+
|
|
68
|
+
if (effect.type === "debounce") {
|
|
69
|
+
timer = setTimeout(() => dispatch({ type: "debounce.elapsed", attempt }), effect.delayMs)
|
|
70
|
+
|
|
71
|
+
return
|
|
72
|
+
}
|
|
53
73
|
|
|
54
|
-
if (cache.has(query)) return setStore({ answered: query, failed: false, loading: false })
|
|
55
74
|
const current = (request = new AbortController())
|
|
56
|
-
|
|
57
|
-
|
|
75
|
+
// A source that ignores the signal or stalls must still end in a state the user can retry from.
|
|
76
|
+
timer = setTimeout(() => dispatch({ type: "request.timed-out", attempt }), TYPEAHEAD_REQUEST_TIMEOUT_MS)
|
|
77
|
+
props.source(effect.query, current.signal).then(
|
|
58
78
|
(items) => {
|
|
59
|
-
if (current.signal.aborted)
|
|
60
|
-
|
|
61
|
-
|
|
79
|
+
if (!current.signal.aborted) dispatch({ type: "request.succeeded", attempt, items })
|
|
80
|
+
},
|
|
81
|
+
() => {
|
|
82
|
+
if (!current.signal.aborted) dispatch({ type: "request.failed", attempt })
|
|
62
83
|
},
|
|
63
|
-
() => !current.signal.aborted && setStore({ answered: query, failed: true, loading: false }),
|
|
64
84
|
)
|
|
65
85
|
}
|
|
66
86
|
|
|
67
|
-
|
|
87
|
+
created.effects.forEach(run)
|
|
88
|
+
|
|
68
89
|
createEffect(
|
|
69
90
|
on(
|
|
70
|
-
|
|
71
|
-
(
|
|
72
|
-
|
|
73
|
-
abort(request)
|
|
74
|
-
const timer = setTimeout(() => search(next), props.delay)
|
|
75
|
-
onCleanup(() => clearTimeout(timer))
|
|
76
|
-
},
|
|
77
|
-
{ defer: !!props.initial },
|
|
91
|
+
() => props.initial,
|
|
92
|
+
(initial) => dispatch({ type: "initial.synced", initial }),
|
|
93
|
+
{ defer: true },
|
|
78
94
|
),
|
|
79
95
|
)
|
|
80
96
|
|
|
81
|
-
|
|
82
|
-
const results = createMemo<{ items: T[]; stale: boolean }>((previous) => {
|
|
83
|
-
const next = query()
|
|
84
|
-
const preloaded = opening()
|
|
85
|
-
|
|
86
|
-
if (preloaded) return { items: preloaded.failed ? [] : preloaded.items, stale: false }
|
|
97
|
+
onCleanup(() => dispatch({ type: "disposed" }))
|
|
87
98
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (cache.has(next) || cached.length > 0) return { items: cached, stale: false }
|
|
92
|
-
|
|
93
|
-
return { items: previous?.items ?? [], stale: !!previous?.items.length }
|
|
94
|
-
})
|
|
99
|
+
const changeInput = (value: string) =>
|
|
100
|
+
dispatch({ type: "input.changed", input: value, delayMs: props.delay, match: props.match })
|
|
95
101
|
|
|
96
|
-
const
|
|
102
|
+
const items = () => selectTypeaheadItems(machine())
|
|
103
|
+
const stale = () => selectTypeaheadStale(machine())
|
|
104
|
+
const pending = () => selectTypeaheadPending(machine())
|
|
105
|
+
const animateHeight = () => selectTypeaheadAnimateHeight(machine())
|
|
97
106
|
|
|
98
107
|
const typeahead = createTypeahead<T>({
|
|
99
|
-
items
|
|
108
|
+
items,
|
|
100
109
|
key: (item) => props.key(item),
|
|
101
|
-
stale
|
|
110
|
+
stale,
|
|
102
111
|
onSelect: (item) => props.onSelect(item),
|
|
103
112
|
})
|
|
104
113
|
|
|
@@ -130,21 +139,21 @@ export function Typeahead<T>(props: {
|
|
|
130
139
|
aria-activedescendant={typeahead.activeID()}
|
|
131
140
|
aria-label={props.placeholder}
|
|
132
141
|
placeholder={props.placeholder}
|
|
133
|
-
value={
|
|
142
|
+
value={selectTypeaheadInput(machine())}
|
|
134
143
|
autocomplete="off"
|
|
135
144
|
spellcheck={false}
|
|
136
145
|
class="h-8 min-w-0 flex-1 outline-none placeholder:text-v2-text-text-faint"
|
|
137
|
-
onInput={(event) =>
|
|
146
|
+
onInput={(event) => changeInput(event.currentTarget.value)}
|
|
138
147
|
onKeyDown={typeahead.onKeyDown}
|
|
139
148
|
/>
|
|
140
|
-
<Show when={
|
|
149
|
+
<Show when={selectTypeaheadInput(machine())}>
|
|
141
150
|
<button
|
|
142
151
|
type="button"
|
|
143
152
|
aria-label={i18n.t("ui.list.clearFilter")}
|
|
144
153
|
class="flex size-5 shrink-0 items-center justify-center rounded-sm text-v2-icon-icon-faint outline-none hover:text-v2-icon-icon-base focus-visible:text-v2-icon-icon-base"
|
|
145
154
|
onPointerDown={(event) => event.preventDefault()}
|
|
146
155
|
onClick={() => {
|
|
147
|
-
|
|
156
|
+
changeInput("")
|
|
148
157
|
input?.focus()
|
|
149
158
|
}}
|
|
150
159
|
>
|
|
@@ -165,14 +174,14 @@ export function Typeahead<T>(props: {
|
|
|
165
174
|
)
|
|
166
175
|
}
|
|
167
176
|
>
|
|
168
|
-
|
|
169
|
-
<div
|
|
177
|
+
<MenuScroll
|
|
170
178
|
id={typeahead.listID}
|
|
171
179
|
role="listbox"
|
|
172
|
-
|
|
173
|
-
|
|
180
|
+
class="max-h-56"
|
|
181
|
+
viewportClass="p-1"
|
|
182
|
+
classList={{ hidden: items().length === 0 }}
|
|
174
183
|
>
|
|
175
|
-
<For each={
|
|
184
|
+
<For each={items()}>
|
|
176
185
|
{(item) => (
|
|
177
186
|
<div
|
|
178
187
|
id={typeahead.optionID(item)}
|
|
@@ -180,7 +189,7 @@ export function Typeahead<T>(props: {
|
|
|
180
189
|
aria-selected={typeahead.activeItem() === item}
|
|
181
190
|
aria-current={props.selected === props.key(item) ? "true" : undefined}
|
|
182
191
|
class="flex h-7 min-w-0 cursor-default select-none items-center gap-2 rounded-sm px-2 transition-opacity duration-150 aria-selected:bg-v2-overlay-simple-overlay-hover"
|
|
183
|
-
classList={{ "opacity-50":
|
|
192
|
+
classList={{ "opacity-50": stale() }}
|
|
184
193
|
onMouseMove={(event) => {
|
|
185
194
|
// A static cursor must not steal the active row while the keyboard scrolls the list.
|
|
186
195
|
if (event.movementX !== 0 || event.movementY !== 0) typeahead.setActive(props.key(item))
|
|
@@ -195,19 +204,19 @@ export function Typeahead<T>(props: {
|
|
|
195
204
|
</div>
|
|
196
205
|
)}
|
|
197
206
|
</For>
|
|
198
|
-
</
|
|
207
|
+
</MenuScroll>
|
|
199
208
|
{/* Stays mounted while a retry or a newer query is pending, so the list never collapses to nothing. */}
|
|
200
|
-
<Show when={
|
|
209
|
+
<Show when={items().length === 0}>
|
|
201
210
|
<div
|
|
202
211
|
class="mx-1 flex h-9 items-center px-2 py-1 text-v2-text-text-faint"
|
|
203
|
-
classList={{ invisible:
|
|
212
|
+
classList={{ invisible: !selectTypeaheadAnswered(machine()) }}
|
|
204
213
|
>
|
|
205
|
-
<Show when={
|
|
214
|
+
<Show when={selectTypeaheadFailed(machine())} fallback={props.emptyLabel}>
|
|
206
215
|
<button
|
|
207
216
|
type="button"
|
|
208
217
|
class="-mx-2 flex h-7 flex-1 items-center rounded-sm px-2 text-start text-v2-text-text-base outline-none hover:bg-v2-overlay-simple-overlay-hover focus-visible:bg-v2-overlay-simple-overlay-hover"
|
|
209
218
|
onMouseDown={(event) => event.preventDefault()}
|
|
210
|
-
onClick={() =>
|
|
219
|
+
onClick={() => dispatch({ type: "retry.requested" })}
|
|
211
220
|
>
|
|
212
221
|
{props.retryLabel}
|
|
213
222
|
</button>
|