@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.
Files changed (119) 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 +9 -3
  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/machine.d.ts +157 -0
  25. package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
  26. package/dist/data-display/project-avatar/animation.d.ts +1 -1
  27. package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
  28. package/dist/feedback/toast/machine.d.ts +57 -0
  29. package/dist/feedback/toast/toast.d.ts +1 -1
  30. package/dist/forms/checkbox/checkbox.d.ts +6 -1
  31. package/dist/forms/select/machine.d.ts +45 -0
  32. package/dist/forms/select/select.d.ts +4 -0
  33. package/dist/forms/typeahead/machine.d.ts +85 -0
  34. package/dist/hooks/auto-scroll-machine.d.ts +89 -0
  35. package/dist/hooks/create-auto-scroll.d.ts +1 -1
  36. package/dist/hooks/list-machine.d.ts +150 -0
  37. package/dist/hooks/use-filtered-list.d.ts +21 -35
  38. package/dist/i18n/en.d.ts +5 -0
  39. package/dist/icons/catalog.d.ts +8 -0
  40. package/dist/navigation/menu/machine.d.ts +49 -0
  41. package/dist/navigation/menu/menu.d.ts +5 -3
  42. package/dist/navigation/segmented-control/machine.d.ts +46 -0
  43. package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
  44. package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
  45. package/dist/overlays/tooltip/machine.d.ts +146 -0
  46. package/dist/theme/context.d.ts +38 -14
  47. package/dist/theme/machine.d.ts +174 -0
  48. package/dist/typography/text-shimmer/machine.d.ts +48 -0
  49. package/package.json +128 -111
  50. package/src/actions/button/button.tsx +11 -6
  51. package/src/actions/icon-button/icon-button.tsx +17 -4
  52. package/src/components/animated-number-machine.ts +214 -0
  53. package/src/components/animated-number.tsx +134 -83
  54. package/src/components/file-icon-machine.ts +78 -0
  55. package/src/components/file-icon.tsx +96 -579
  56. package/src/components/file-icons/choose-icon-name.ts +574 -0
  57. package/src/components/image-flight-machine.ts +247 -0
  58. package/src/components/image-preview.css +5 -2
  59. package/src/components/image-preview.tsx +390 -252
  60. package/src/components/image-zoom-machine.ts +191 -0
  61. package/src/components/image-zoom.ts +22 -14
  62. package/src/components/list.tsx +46 -137
  63. package/src/components/menu-scroll.css +19 -8
  64. package/src/components/menu-scroll.tsx +111 -34
  65. package/src/components/popover-machine.ts +198 -0
  66. package/src/components/popover.tsx +157 -89
  67. package/src/components/resize-handle-machine.ts +174 -0
  68. package/src/components/resize-handle.tsx +116 -67
  69. package/src/components/scroll-view-machine.ts +244 -0
  70. package/src/components/scroll-view.tsx +163 -116
  71. package/src/components/spinner.css +18 -5
  72. package/src/components/spinner.tsx +28 -14
  73. package/src/components/text-field-machine.ts +102 -0
  74. package/src/components/text-field.tsx +78 -24
  75. package/src/components/text-reveal-machine.ts +184 -0
  76. package/src/components/text-reveal.tsx +96 -93
  77. package/src/components/typewriter-machine.ts +134 -0
  78. package/src/components/typewriter.tsx +50 -39
  79. package/src/context/dialog-machine.ts +280 -0
  80. package/src/context/dialog.tsx +168 -177
  81. package/src/data-display/line-comment/line-comment.tsx +157 -178
  82. package/src/data-display/line-comment/machine.ts +391 -0
  83. package/src/data-display/project-avatar/animation-machine.ts +182 -0
  84. package/src/data-display/project-avatar/animation.ts +67 -38
  85. package/src/feedback/activity-ring/activity-ring.tsx +1 -1
  86. package/src/feedback/toast/machine.ts +115 -0
  87. package/src/feedback/toast/toast.tsx +59 -59
  88. package/src/forms/checkbox/checkbox-compact.css +169 -0
  89. package/src/forms/checkbox/checkbox.tsx +93 -31
  90. package/src/forms/inline-input/inline-input.css +0 -1
  91. package/src/forms/search-list/search-list.css +5 -1
  92. package/src/forms/search-list/search-list.tsx +18 -10
  93. package/src/forms/select/machine.ts +81 -0
  94. package/src/forms/select/select.css +59 -17
  95. package/src/forms/select/select.tsx +74 -32
  96. package/src/forms/typeahead/machine.ts +253 -0
  97. package/src/forms/typeahead/typeahead.tsx +70 -62
  98. package/src/hooks/auto-scroll-machine.ts +261 -0
  99. package/src/hooks/create-auto-scroll.tsx +110 -205
  100. package/src/hooks/list-machine.ts +359 -0
  101. package/src/hooks/use-filtered-list.tsx +101 -112
  102. package/src/i18n/en.ts +6 -1
  103. package/src/i18n/uk.ts +3 -3
  104. package/src/icons/catalog.ts +8 -0
  105. package/src/navigation/menu/machine.ts +109 -0
  106. package/src/navigation/menu/menu.tsx +133 -22
  107. package/src/navigation/segmented-control/machine.ts +72 -0
  108. package/src/navigation/segmented-control/segmented-control.tsx +46 -46
  109. package/src/overlays/dialog/dialog.tsx +7 -1
  110. package/src/overlays/mcp-sign-in/machine.ts +343 -0
  111. package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
  112. package/src/overlays/tooltip/machine.ts +303 -0
  113. package/src/overlays/tooltip/tooltip.tsx +159 -92
  114. package/src/styles/theme.css +10 -2
  115. package/src/theme/context.tsx +192 -269
  116. package/src/theme/machine.ts +508 -0
  117. package/src/typography/text-shimmer/machine.ts +90 -0
  118. package/src/typography/text-shimmer/text-shimmer.css +71 -39
  119. package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
@@ -0,0 +1,191 @@
1
+ /** The element a pan captures the pointer on: the preview's body for an image, the borrowed video for a video. */
2
+ export type PanTarget = "viewport" | "video"
3
+
4
+ /**
5
+ * The press under way. A `backdrop-press` began on the backdrop around the image and stayed put, so the click that ends
6
+ * it closes the preview. A pan captures the pointer, so its click lands on the backdrop wherever it began: `onBackdrop`
7
+ * says whether it began there, and `moved` whether it has moved, so the click that ends a moved pan neither closes the
8
+ * preview nor plays the video.
9
+ */
10
+ export type PreviewZoomGesture =
11
+ | { readonly type: "idle" }
12
+ | { readonly type: "backdrop-press" }
13
+ | {
14
+ readonly type: "panning"
15
+ readonly pointerId: number
16
+ readonly target: PanTarget
17
+ readonly onBackdrop: boolean
18
+ readonly moved: boolean
19
+ }
20
+
21
+ /**
22
+ * `gliding` is an eased zoom under way on the frame loop. Scale and offsets live on springs in the driver, not here: a
23
+ * frame of a glide or a pan writes no state. A press does not stop a glide, so a third click of a double-click zoom
24
+ * leaves it running; the hand moving does.
25
+ */
26
+ export type PreviewZoomState =
27
+ | { readonly status: "still" | "gliding"; readonly gesture: PreviewZoomGesture }
28
+ | { readonly status: "disposed" }
29
+
30
+ /** `zoomed` is whether the image shows above fit once the event's change applies. */
31
+ export type PreviewZoomEvent =
32
+ | {
33
+ readonly type: "pointer.down"
34
+ readonly pointerId: number
35
+ readonly button: number
36
+ /** `content` is anywhere in the preview but its body, such as the band around it or the controls. */
37
+ readonly target: PanTarget | "content"
38
+ readonly onBackdrop: boolean
39
+ readonly zoomed: boolean
40
+ }
41
+ | { readonly type: "pointer.moved"; readonly pointerId: number }
42
+ | { readonly type: "pointer.up"; readonly pointerId: number }
43
+ /** `pointercancel`, `lostpointercapture`, or a move with the primary button already up: the pan ends unreleased. */
44
+ | { readonly type: "pointer.cancel"; readonly pointerId: number }
45
+ | { readonly type: "backdrop.click"; readonly onBackdrop: boolean }
46
+ /** Pinch, wheel, drag or a resize set the view directly. */
47
+ | { readonly type: "follow"; readonly zoomed: boolean }
48
+ | { readonly type: "glide.start" }
49
+ | { readonly type: "glide.settled"; readonly zoomed: boolean }
50
+ | { readonly type: "disposed" }
51
+
52
+ export type PreviewZoomEffect =
53
+ | { readonly type: "pointer.capture"; readonly target: PanTarget; readonly pointerId: number }
54
+ | { readonly type: "pointer.release"; readonly target: PanTarget; readonly pointerId: number }
55
+ | { readonly type: "glide.loop.start" }
56
+ | { readonly type: "glide.loop.stop" }
57
+ /** Swallows the click that ends a moved pan over the video, so it does not play or pause it. */
58
+ | { readonly type: "video.suppress-click" }
59
+ | { readonly type: "dialog.close" }
60
+
61
+ export type PreviewZoomTransition = {
62
+ readonly state: PreviewZoomState
63
+ readonly effects: readonly PreviewZoomEffect[]
64
+ }
65
+
66
+ const IDLE: PreviewZoomGesture = Object.freeze({ type: "idle" })
67
+
68
+ const BACKDROP_PRESS: PreviewZoomGesture = Object.freeze({ type: "backdrop-press" })
69
+
70
+ const NONE: readonly PreviewZoomEffect[] = Object.freeze([])
71
+
72
+ export const INITIAL_PREVIEW_ZOOM_STATE: PreviewZoomState = Object.freeze({ status: "still", gesture: IDLE })
73
+
74
+ const DISPOSED: PreviewZoomState = Object.freeze({ status: "disposed" })
75
+
76
+ export function transitionPreviewZoom(state: PreviewZoomState, event: PreviewZoomEvent): PreviewZoomTransition {
77
+ if (state.status === "disposed") return unchanged(state)
78
+ const gliding = state.status === "gliding"
79
+ const pan = state.gesture.type === "panning" ? state.gesture : undefined
80
+
81
+ if (event.type === "disposed") {
82
+ return { state: DISPOSED, effects: [...release(pan), ...(gliding ? [{ type: "glide.loop.stop" } as const] : [])] }
83
+ }
84
+
85
+ if (event.type === "pointer.down") {
86
+ // A second pointer leaves the pan alone; the same pointer pressing again means its release never arrived.
87
+ if (pan && pan.pointerId !== event.pointerId) return unchanged(state)
88
+
89
+ if (event.button === 0 && event.zoomed && event.target !== "content") {
90
+ return {
91
+ state: {
92
+ status: state.status,
93
+ gesture: {
94
+ type: "panning",
95
+ pointerId: event.pointerId,
96
+ target: event.target,
97
+ onBackdrop: event.onBackdrop,
98
+ moved: false,
99
+ },
100
+ },
101
+ effects: [{ type: "pointer.capture", target: event.target, pointerId: event.pointerId }],
102
+ }
103
+ }
104
+
105
+ return gesture(state, event.button === 0 && event.onBackdrop ? BACKDROP_PRESS : IDLE)
106
+ }
107
+
108
+ if (event.type === "pointer.moved") {
109
+ if (pan?.pointerId !== event.pointerId || pan.moved) return unchanged(state)
110
+
111
+ return gesture(state, { ...pan, onBackdrop: false, moved: true })
112
+ }
113
+
114
+ if (event.type === "pointer.up") {
115
+ if (pan?.pointerId !== event.pointerId) return unchanged(state)
116
+
117
+ if (pan.moved && pan.target === "video") {
118
+ return { state: { status: state.status, gesture: IDLE }, effects: [{ type: "video.suppress-click" }] }
119
+ }
120
+
121
+ return gesture(state, !pan.moved && pan.onBackdrop ? BACKDROP_PRESS : IDLE)
122
+ }
123
+
124
+ if (event.type === "pointer.cancel") {
125
+ if (pan?.pointerId !== event.pointerId) return unchanged(state)
126
+
127
+ return { state: { status: state.status, gesture: IDLE }, effects: release(pan) }
128
+ }
129
+
130
+ if (event.type === "backdrop.click") {
131
+ if (state.gesture.type !== "backdrop-press") return unchanged(state)
132
+
133
+ return {
134
+ state: { status: state.status, gesture: IDLE },
135
+ effects: event.onBackdrop ? [{ type: "dialog.close" }] : NONE,
136
+ }
137
+ }
138
+
139
+ // An eased zoom takes over from a pan, so a pan never outlives a zoom back to fit.
140
+ if (event.type === "glide.start") {
141
+ if (gliding && !pan) return unchanged(state)
142
+
143
+ return {
144
+ state: { status: "gliding", gesture: pan ? IDLE : state.gesture },
145
+ effects: [...release(pan), ...(gliding ? [] : [{ type: "glide.loop.start" } as const])],
146
+ }
147
+ }
148
+
149
+ if (event.type === "glide.settled" && !gliding) return unchanged(state)
150
+ // The hand takes over from an eased zoom; a pan ends once the image is back at fit.
151
+ const ends = pan && !event.zoomed ? pan : undefined
152
+
153
+ if (!gliding && !ends) return unchanged(state)
154
+
155
+ return {
156
+ state: { status: "still", gesture: ends ? IDLE : state.gesture },
157
+ effects: [...(gliding ? [{ type: "glide.loop.stop" } as const] : []), ...release(ends)],
158
+ }
159
+ }
160
+
161
+ /** Whether a pan holds the pointer, which shows the grabbing cursor. */
162
+ export function selectDragging(state: PreviewZoomState) {
163
+ return state.status !== "disposed" && state.gesture.type === "panning"
164
+ }
165
+
166
+ /** Whether `pointerId` is the pointer the pan under way follows. */
167
+ export function selectPanPointer(state: PreviewZoomState, pointerId: number) {
168
+ return state.status !== "disposed" && state.gesture.type === "panning" && state.gesture.pointerId === pointerId
169
+ }
170
+
171
+ function gesture(state: Exclude<PreviewZoomState, { status: "disposed" }>, next: PreviewZoomGesture) {
172
+ if (state.gesture === next) return unchanged(state)
173
+
174
+ return { state: { status: state.status, gesture: next }, effects: NONE }
175
+ }
176
+
177
+ function release(pan: Extract<PreviewZoomGesture, { type: "panning" }> | undefined): readonly PreviewZoomEffect[] {
178
+ if (!pan) return NONE
179
+
180
+ return [{ type: "pointer.release", target: pan.target, pointerId: pan.pointerId }]
181
+ }
182
+
183
+ // Every pointer move of a pan dispatches events that change nothing; answering them with the transition already built
184
+ // for that state keeps the hot path allocation-free.
185
+ let last: PreviewZoomTransition = Object.freeze({ state: DISPOSED, effects: NONE })
186
+
187
+ function unchanged(state: PreviewZoomState) {
188
+ if (last.state !== state) last = Object.freeze({ state, effects: NONE })
189
+
190
+ return last
191
+ }
@@ -59,26 +59,25 @@ export function detailScale(fitRatio: number) {
59
59
  }
60
60
 
61
61
  /**
62
- * The `object-view-box` that shows `view` of media fitted at `size`, for media that must zoom inside its own box, such
63
- * as a video under its controls. The inset is in the media's natural pixels.
62
+ * The `object-view-box` that shows the view at `scale`, `x` and `y` of media fitted at `size`, for media that must zoom
63
+ * inside its own box, such as a video under its controls. The inset is in the media's natural pixels. It takes the view
64
+ * as numbers, so painting a frame of a glide allocates nothing but the string.
64
65
  */
65
66
  export function viewBox(
66
- view: ZoomView,
67
+ scale: number,
68
+ x: number,
69
+ y: number,
67
70
  size: { width: number; height: number },
68
71
  natural: { width: number; height: number },
69
72
  ) {
70
- if (view.scale <= 1) return "none"
73
+ if (scale <= 1) return "none"
71
74
 
72
- const edge = (offset: number, fitted: number) => 0.5 - 0.5 / view.scale - offset / (view.scale * fitted)
75
+ const top = px(edge(y, size.height, scale) * natural.height)
76
+ const right = px(edge(-x, size.width, scale) * natural.width)
77
+ const bottom = px(edge(-y, size.height, scale) * natural.height)
78
+ const left = px(edge(x, size.width, scale) * natural.width)
73
79
 
74
- const inset = [
75
- edge(view.y, size.height) * natural.height,
76
- edge(-view.x, size.width) * natural.width,
77
- edge(-view.y, size.height) * natural.height,
78
- edge(view.x, size.width) * natural.width,
79
- ]
80
-
81
- return `inset(${inset.map((value) => `${Math.max(0, Math.round(value * 100) / 100)}px`).join(" ")})`
80
+ return `inset(${top} ${right} ${bottom} ${left})`
82
81
  }
83
82
 
84
83
  /** The zoom factor for one wheel event, bounded so a coarse mouse-wheel notch is a step rather than a jump. */
@@ -86,13 +85,22 @@ export function wheelZoomFactor(deltaY: number) {
86
85
  return Math.exp(-clamp(deltaY, -30, 30) / 100)
87
86
  }
88
87
 
89
- function clampAxis(offset: number, size: number, viewport: number) {
88
+ /** Keeps one axis of a zoomed image of `size` covering a `viewport` it overflows, and centered in one it fits. */
89
+ export function clampAxis(offset: number, size: number, viewport: number) {
90
90
  const limit = Math.max(0, (size - viewport) / 2)
91
91
 
92
92
  // Adding zero turns -0 into 0.
93
93
  return clamp(offset, -limit, limit) + 0
94
94
  }
95
95
 
96
+ function edge(offset: number, fitted: number, scale: number) {
97
+ return 0.5 - 0.5 / scale - offset / (scale * fitted)
98
+ }
99
+
100
+ function px(value: number) {
101
+ return `${Math.max(0, Math.round(value * 100) / 100)}px`
102
+ }
103
+
96
104
  function clamp(value: number, min: number, max: number) {
97
105
  return Math.min(Math.max(value, min), max)
98
106
  }
@@ -1,8 +1,9 @@
1
1
  import { type FilteredListProps, useFilteredList } from "@opencode/ui/hooks"
2
- import { createEffect, For, type JSX, on, Show } from "solid-js"
2
+ import { createEffect, createMemo, createSignal, For, type JSX, on, Show } from "solid-js"
3
3
  import { createStore } from "solid-js/store"
4
4
  import { makeEventListener } from "@solid-primitives/event-listener"
5
5
  import { useI18n } from "../context/i18n"
6
+ import { listActive, listScrollTarget, selectListEmptyState } from "../hooks/list-machine"
6
7
  import { Icon, type IconProps } from "@opencode/ui/icon"
7
8
  import { IconButton } from "@opencode/ui/icon-button"
8
9
  import { TextField } from "./text-field"
@@ -28,21 +29,16 @@ export interface ListAddProps {
28
29
  render: () => JSX.Element
29
30
  }
30
31
 
31
- export interface ListAddProps {
32
- class?: string
33
- render: () => JSX.Element
34
- }
35
-
36
32
  export interface ListProps<T> extends FilteredListProps<T> {
37
33
  class?: string
38
34
  children: (item: T) => JSX.Element
39
35
  emptyMessage?: string
40
36
  loadingMessage?: string
37
+ /** Shown when an async `items` loader rejects or times out. */
38
+ errorMessage?: string
41
39
  onKeyEvent?: (event: KeyboardEvent, item: T | undefined) => void
42
40
  onMove?: (item: T | undefined) => void
43
- onFilter?: (value: string) => void
44
41
  activeIcon?: IconProps["name"]
45
- filter?: string
46
42
  search?: ListSearchProps | boolean
47
43
  itemWrapper?: (item: T, node: JSX.Element) => JSX.Element
48
44
  divider?: boolean
@@ -60,16 +56,7 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
60
56
  const i18n = useI18n()
61
57
  let inputRef: HTMLInputElement | HTMLTextAreaElement | undefined
62
58
 
63
- const [store, setStore] = createStore({
64
- mouseActive: false,
65
- scrollRef: undefined as HTMLDivElement | undefined,
66
- internalFilter: "",
67
- })
68
-
69
- const scrollRef = () => store.scrollRef
70
- const setScrollRef = (el: HTMLDivElement | undefined) => setStore("scrollRef", el)
71
- const internalFilter = () => store.internalFilter
72
- const setInternalFilter = (value: string) => setStore("internalFilter", value)
59
+ const [scrollRef, setScrollRef] = createSignal<HTMLDivElement>()
73
60
 
74
61
  const scrollIntoView = (container: HTMLDivElement, node: HTMLElement, block: "center" | "nearest") => {
75
62
  const containerRect = container.getBoundingClientRect()
@@ -92,121 +79,43 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
92
79
  container.scrollTop = Math.max(0, Math.min(target, max))
93
80
  }
94
81
 
95
- const { filter, grouped, flat, active, setActive, onKeyDown, onInput, refetch } = useFilteredList<T>(props)
82
+ const list = useFilteredList<T>(props)
83
+ const keys = createMemo(() => list.state().keys)
84
+ const highlight = createMemo(() => list.state().highlight)
96
85
 
97
- const searchProps = () => (typeof props.search === "object" ? props.search : {})
86
+ const searchProps = () => (props.search && props.search !== true ? props.search : {})
98
87
  const searchAction = () => searchProps().action
99
88
  const addProps = () => props.add
100
89
  const showAdd = () => !!addProps()
101
90
 
102
- const moved = (event: MouseEvent) => event.movementX !== 0 || event.movementY !== 0
103
-
104
- const applyFilter = (value: string, options?: { ref?: boolean }) => {
105
- const prev = filter()
106
- setInternalFilter(value)
107
- onInput(value)
108
- props.onFilter?.(value)
109
-
110
- if (!options?.ref) return
111
-
112
- // Force a refetch even if the value is unchanged.
113
- // This is important for programmatic changes like Tab completion.
114
- if (prev === value) {
115
- void refetch()
116
-
117
- return
118
- }
119
-
120
- queueMicrotask(() => refetch())
121
- }
122
-
123
- createEffect(() => {
124
- if (props.filter === undefined) return
125
-
126
- if (props.filter === internalFilter()) return
127
- setInternalFilter(props.filter)
128
- onInput(props.filter)
129
- })
130
-
131
- createEffect(
132
- on(
133
- filter,
134
- () => {
135
- scrollRef()?.scrollTo(0, 0)
136
- },
137
- { defer: true },
138
- ),
139
- )
91
+ createEffect(on(list.filter, () => scrollRef()?.scrollTo(0, 0), { defer: true }))
140
92
 
141
93
  createEffect(() => {
142
- const all = flat()
143
-
144
- if (store.mouseActive || all.length === 0) return
94
+ const target = listScrollTarget({ keys: keys(), highlight: highlight() })
145
95
  const scroll = scrollRef()
146
96
 
147
- if (!scroll) return
148
-
149
- if (active() === props.key(all[0])) {
150
- scroll.scrollTo(0, 0)
151
-
152
- return
153
- }
97
+ if (!scroll || target.type === "none") return
154
98
 
155
- const key = active()
99
+ if (target.type === "top") return scroll.scrollTo(0, 0)
100
+ const element = findByKey(scroll, target.key)
156
101
 
157
- if (!key) return
158
- const element = findByKey(scroll, key)
159
-
160
- if (!element) return
161
- scrollIntoView(scroll, element, "center")
102
+ if (element) scrollIntoView(scroll, element, "center")
162
103
  })
163
104
 
164
- createEffect(() => {
165
- const all = flat()
166
- const current = active()
167
- const item = all.find((x) => props.key(x) === current)
168
- props.onMove?.(item)
169
- })
105
+ const activeItem = createMemo(() => listActive(list.state())?.item)
170
106
 
171
- const handleSelect = (item: T | undefined, index: number) => {
172
- props.onSelect?.(item, index)
173
- }
107
+ createEffect(() => props.onMove?.(activeItem()))
174
108
 
175
109
  const handleKey = (e: KeyboardEvent) => {
176
- setStore("mouseActive", false)
177
-
178
- if (e.key === "Escape") return
179
-
180
- const all = flat()
181
- const selected = all.find((x) => props.key(x) === active())
182
- const index = selected ? all.indexOf(selected) : -1
183
- props.onKeyEvent?.(e, selected)
184
-
185
- if (e.defaultPrevented) return
186
-
187
- if (e.key === "Enter" && !e.isComposing) {
188
- e.preventDefault()
189
-
190
- if (selected) handleSelect(selected, index)
191
- } else if (props.search) {
192
- if (e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey && (e.key === "n" || e.key === "p")) {
193
- onKeyDown(e)
194
-
195
- return
196
- }
197
-
198
- if (e.key === "ArrowDown" || e.key === "ArrowUp") {
199
- onKeyDown(e)
200
- }
201
- } else {
202
- onKeyDown(e)
203
- }
110
+ if (e.key !== "Escape") props.onKeyEvent?.(e, activeItem())
111
+ list.onKeyDown(e, { search: !!props.search, claimed: e.key === "Escape" || e.defaultPrevented })
204
112
  }
205
113
 
206
114
  props.ref?.({
207
115
  onKeyDown: handleKey,
208
116
  setScrollRef,
209
- setFilter: (value) => applyFilter(value, { ref: true }),
117
+ // Forces a reload even when the value is unchanged, for programmatic changes like Tab completion.
118
+ setFilter: (value) => list.dispatch({ type: "query.change", value, force: true }),
210
119
  })
211
120
 
212
121
  const renderAdd = () => {
@@ -222,10 +131,7 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
222
131
  }
223
132
 
224
133
  function GroupHeader(groupProps: { group: { category: string; items: T[] } }): JSX.Element {
225
- const [state, setState] = createStore({
226
- stuck: false,
227
- header: undefined as HTMLDivElement | undefined,
228
- })
134
+ const [state, setState] = createStore<{ stuck: boolean; header?: HTMLDivElement }>({ stuck: false })
229
135
 
230
136
  createEffect(() => {
231
137
  const scroll = scrollRef()
@@ -251,11 +157,15 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
251
157
  }
252
158
 
253
159
  const emptyMessage = () => {
254
- if (grouped.loading) return props.loadingMessage ?? i18n.t("ui.list.loading")
160
+ const empty = selectListEmptyState(list.state())
161
+
162
+ if (empty.type === "loading") return props.loadingMessage ?? i18n.t("ui.list.loading")
163
+
164
+ if (empty.type === "failed") return props.errorMessage ?? i18n.t("ui.list.failed")
255
165
 
256
166
  if (props.emptyMessage) return props.emptyMessage
257
167
 
258
- const query = filter()
168
+ const query = empty.query
259
169
 
260
170
  if (!query) return i18n.t("ui.list.empty")
261
171
 
@@ -304,8 +214,8 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
304
214
  ref={(el: HTMLInputElement | HTMLTextAreaElement) => {
305
215
  inputRef = el
306
216
  }}
307
- value={internalFilter()}
308
- onChange={(value) => applyFilter(value)}
217
+ value={list.filter()}
218
+ onChange={(value) => list.onInput(value)}
309
219
  onKeyDown={handleKey}
310
220
  placeholder={searchProps().placeholder}
311
221
  spellcheck={false}
@@ -314,12 +224,12 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
314
224
  autocapitalize="off"
315
225
  />
316
226
  </div>
317
- <Show when={internalFilter()}>
227
+ <Show when={list.filter()}>
318
228
  <IconButton
319
229
  icon={<Icon name="circle-x" />}
320
230
  variant="ghost"
321
231
  onClick={() => {
322
- setInternalFilter("")
232
+ list.clear()
323
233
  queueMicrotask(() => inputRef?.focus())
324
234
  }}
325
235
  aria-label={i18n.t("ui.list.clearFilter")}
@@ -331,16 +241,16 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
331
241
  </Show>
332
242
  <div ref={setScrollRef} data-slot="list-scroll">
333
243
  <Show
334
- when={flat().length > 0 || showAdd()}
244
+ when={list.flat().length > 0 || showAdd()}
335
245
  fallback={
336
246
  <div data-slot="list-empty-state">
337
247
  <div data-slot="list-message">{emptyMessage()}</div>
338
248
  </div>
339
249
  }
340
250
  >
341
- <For each={grouped.latest}>
251
+ <For each={list.grouped.latest}>
342
252
  {(group, groupIndex) => {
343
- const isLastGroup = () => groupIndex() === grouped.latest.length - 1
253
+ const isLastGroup = () => groupIndex() === list.grouped.latest.length - 1
344
254
 
345
255
  return (
346
256
  <div data-slot="list-group">
@@ -354,20 +264,19 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
354
264
  <button
355
265
  data-slot="list-item"
356
266
  data-key={props.key(item)}
357
- data-active={props.key(item) === active()}
267
+ data-active={props.key(item) === list.active()}
358
268
  data-selected={item === props.current}
359
- onClick={() => handleSelect(item, i())}
269
+ onClick={() => props.onSelect?.(item, i())}
360
270
  onKeyDown={handleKey}
361
271
  type="button"
362
- onMouseMove={(event) => {
363
- if (!moved(event)) return
364
- setStore("mouseActive", true)
365
- setActive(props.key(item))
366
- }}
367
- onMouseLeave={() => {
368
- if (!store.mouseActive) return
369
- setActive(null)
370
- }}
272
+ onMouseMove={(event) =>
273
+ list.dispatch({
274
+ type: "pointer.move",
275
+ key: props.key(item),
276
+ moved: event.movementX !== 0 || event.movementY !== 0,
277
+ })
278
+ }
279
+ onMouseLeave={() => list.dispatch({ type: "pointer.leave" })}
371
280
  >
372
281
  {props.children(item)}
373
282
  <Show when={item === props.current}>
@@ -401,7 +310,7 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
401
310
  )
402
311
  }}
403
312
  </For>
404
- <Show when={grouped.latest.length === 0 && showAdd()}>
313
+ <Show when={list.grouped.latest.length === 0 && showAdd()}>
405
314
  <div data-slot="list-group">
406
315
  <div data-slot="list-items">{renderAdd()}</div>
407
316
  </div>
@@ -7,7 +7,7 @@
7
7
  isolation: isolate;
8
8
  }
9
9
 
10
- [data-slot="menu-scroll-viewport"] {
10
+ [data-component="menu-scroll"] > [data-scrollable] {
11
11
  min-height: 0;
12
12
  overflow-y: auto;
13
13
  }
@@ -16,12 +16,13 @@
16
16
  display: none;
17
17
  }
18
18
 
19
- @media (hover: hover) and (pointer: fine) {
20
- [data-slot="menu-scroll-viewport"] {
19
+ /* High-contrast modes keep the native scrollbar, which follows the system colours. */
20
+ @media (hover: hover) and (pointer: fine) and (forced-colors: none) {
21
+ [data-component="menu-scroll"] > [data-scrollable] {
21
22
  scrollbar-width: none;
22
23
  }
23
24
 
24
- [data-slot="menu-scroll-viewport"]::-webkit-scrollbar {
25
+ [data-component="menu-scroll"] > [data-scrollable]::-webkit-scrollbar {
25
26
  display: none;
26
27
  }
27
28
 
@@ -36,6 +37,7 @@
36
37
  pointer-events: none;
37
38
  touch-action: none;
38
39
  user-select: none;
40
+ transition: opacity 200ms ease;
39
41
 
40
42
  &::after {
41
43
  position: absolute;
@@ -45,15 +47,24 @@
45
47
  content: "";
46
48
  }
47
49
 
48
- &:hover::after,
49
- &[data-dragging]::after {
50
+ &:hover::after {
50
51
  background: var(--v2-border-border-strong);
51
52
  }
52
53
  }
53
54
 
54
- [data-component="menu-scroll"]:hover > [data-slot="menu-scroll-thumb"],
55
- [data-slot="menu-scroll-thumb"][data-dragging] {
55
+ [data-component="menu-scroll"]:is([data-scrolling], [data-dragging]) > [data-slot="menu-scroll-thumb"],
56
+ [data-slot="menu-scroll-thumb"]:hover {
56
57
  opacity: 1;
57
58
  pointer-events: auto;
58
59
  }
60
+
61
+ [data-component="menu-scroll"][data-dragging] > [data-slot="menu-scroll-thumb"]::after {
62
+ background: var(--v2-border-border-strong);
63
+ }
64
+ }
65
+
66
+ @media (prefers-reduced-motion: reduce) {
67
+ [data-slot="menu-scroll-thumb"] {
68
+ transition: none;
69
+ }
59
70
  }