@opencode/ui 2.2.5 → 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 +9 -3
- package/dist/components/popover-machine.d.ts +96 -0
- package/dist/components/popover.d.ts +2 -2
- package/dist/components/resize-handle-machine.d.ts +71 -0
- package/dist/components/resize-handle.d.ts +2 -0
- package/dist/components/scroll-view-machine.d.ts +68 -0
- package/dist/components/scroll-view.d.ts +2 -2
- package/dist/components/spinner.d.ts +11 -3
- package/dist/components/text-field-machine.d.ts +62 -0
- package/dist/components/text-reveal-machine.d.ts +90 -0
- package/dist/components/typewriter-machine.d.ts +62 -0
- package/dist/context/dialog-machine.d.ts +125 -0
- package/dist/context/dialog.d.ts +17 -16
- package/dist/data-display/line-comment/machine.d.ts +157 -0
- package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
- package/dist/data-display/project-avatar/animation.d.ts +1 -1
- package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
- package/dist/feedback/toast/machine.d.ts +57 -0
- package/dist/feedback/toast/toast.d.ts +1 -1
- package/dist/forms/checkbox/checkbox.d.ts +6 -1
- package/dist/forms/select/machine.d.ts +45 -0
- package/dist/forms/select/select.d.ts +4 -0
- package/dist/forms/typeahead/machine.d.ts +85 -0
- package/dist/hooks/auto-scroll-machine.d.ts +89 -0
- package/dist/hooks/create-auto-scroll.d.ts +1 -1
- package/dist/hooks/list-machine.d.ts +150 -0
- package/dist/hooks/use-filtered-list.d.ts +21 -35
- package/dist/i18n/en.d.ts +5 -0
- package/dist/icons/catalog.d.ts +8 -0
- package/dist/navigation/menu/machine.d.ts +49 -0
- package/dist/navigation/menu/menu.d.ts +5 -3
- package/dist/navigation/segmented-control/machine.d.ts +46 -0
- package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
- package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
- package/dist/overlays/tooltip/machine.d.ts +146 -0
- package/dist/theme/context.d.ts +38 -14
- package/dist/theme/machine.d.ts +174 -0
- package/dist/typography/text-shimmer/machine.d.ts +48 -0
- package/package.json +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 +19 -8
- package/src/components/menu-scroll.tsx +111 -34
- package/src/components/popover-machine.ts +198 -0
- package/src/components/popover.tsx +157 -89
- package/src/components/resize-handle-machine.ts +174 -0
- package/src/components/resize-handle.tsx +116 -67
- package/src/components/scroll-view-machine.ts +244 -0
- package/src/components/scroll-view.tsx +163 -116
- package/src/components/spinner.css +18 -5
- package/src/components/spinner.tsx +28 -14
- package/src/components/text-field-machine.ts +102 -0
- package/src/components/text-field.tsx +78 -24
- package/src/components/text-reveal-machine.ts +184 -0
- package/src/components/text-reveal.tsx +96 -93
- package/src/components/typewriter-machine.ts +134 -0
- package/src/components/typewriter.tsx +50 -39
- package/src/context/dialog-machine.ts +280 -0
- package/src/context/dialog.tsx +168 -177
- package/src/data-display/line-comment/line-comment.tsx +157 -178
- package/src/data-display/line-comment/machine.ts +391 -0
- package/src/data-display/project-avatar/animation-machine.ts +182 -0
- package/src/data-display/project-avatar/animation.ts +67 -38
- package/src/feedback/activity-ring/activity-ring.tsx +1 -1
- package/src/feedback/toast/machine.ts +115 -0
- package/src/feedback/toast/toast.tsx +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/typeahead/machine.ts +253 -0
- package/src/forms/typeahead/typeahead.tsx +70 -62
- package/src/hooks/auto-scroll-machine.ts +261 -0
- package/src/hooks/create-auto-scroll.tsx +110 -205
- package/src/hooks/list-machine.ts +359 -0
- package/src/hooks/use-filtered-list.tsx +101 -112
- package/src/i18n/en.ts +6 -1
- package/src/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/theme/context.tsx +192 -269
- package/src/theme/machine.ts +508 -0
- package/src/typography/text-shimmer/machine.ts +90 -0
- package/src/typography/text-shimmer/text-shimmer.css +71 -39
- package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createEffect,
|
|
3
|
+
createSignal,
|
|
4
|
+
mergeProps,
|
|
5
|
+
on,
|
|
6
|
+
onCleanup,
|
|
7
|
+
onMount,
|
|
8
|
+
Show,
|
|
9
|
+
splitProps,
|
|
10
|
+
untrack,
|
|
11
|
+
type ComponentProps,
|
|
12
|
+
type JSX,
|
|
13
|
+
} from "solid-js"
|
|
2
14
|
import { Portal } from "solid-js/web"
|
|
3
15
|
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
4
16
|
import { createStore } from "solid-js/store"
|
|
5
17
|
import { useI18n } from "../context/i18n"
|
|
18
|
+
import {
|
|
19
|
+
HOVER_ENTERED,
|
|
20
|
+
HOVER_LEFT,
|
|
21
|
+
INITIAL_SCROLL_THUMB_STATE,
|
|
22
|
+
overflowChanged,
|
|
23
|
+
SCROLL_IDLE_ELAPSED,
|
|
24
|
+
SCROLL_IDLE_MS,
|
|
25
|
+
SCROLL_THUMB_DISPOSED,
|
|
26
|
+
SCROLLED,
|
|
27
|
+
selectDraggingAxis,
|
|
28
|
+
selectShowHorizontalThumb,
|
|
29
|
+
selectShowVerticalThumb,
|
|
30
|
+
selectThumbVisible,
|
|
31
|
+
transitionScrollThumb,
|
|
32
|
+
type ScrollAxis,
|
|
33
|
+
type ScrollThumbEvent,
|
|
34
|
+
type ScrollThumbState,
|
|
35
|
+
} from "./scroll-view-machine"
|
|
6
36
|
|
|
7
37
|
export type ScrollViewThumbVisibility = "hover" | "scroll"
|
|
8
38
|
|
|
@@ -113,19 +143,34 @@ export function scrollOffsetFromThumbPointer(input: {
|
|
|
113
143
|
scrollClientSize?: number
|
|
114
144
|
reverse?: boolean
|
|
115
145
|
}) {
|
|
146
|
+
return thumbScrollOffset(
|
|
147
|
+
input.pointer - input.viewportStart - input.grabOffset,
|
|
148
|
+
input.clientSize,
|
|
149
|
+
input.scrollSize,
|
|
150
|
+
input.thumbSize,
|
|
151
|
+
input.scrollClientSize ?? input.clientSize,
|
|
152
|
+
input.reverse ?? false,
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Scalar arguments, so a drag's `pointermove` builds no options object.
|
|
157
|
+
function thumbScrollOffset(
|
|
158
|
+
thumbOffset: number,
|
|
159
|
+
clientSize: number,
|
|
160
|
+
scrollSize: number,
|
|
161
|
+
thumbSize: number,
|
|
162
|
+
scrollClientSize: number,
|
|
163
|
+
reverse: boolean,
|
|
164
|
+
) {
|
|
116
165
|
const padding = 8
|
|
117
|
-
const maxThumbStart =
|
|
166
|
+
const maxThumbStart = clientSize - padding * 2 - thumbSize
|
|
118
167
|
|
|
119
168
|
if (maxThumbStart <= 0) return 0
|
|
120
169
|
|
|
121
|
-
const thumbStart = Math.max(
|
|
122
|
-
|
|
123
|
-
Math.min(input.pointer - input.viewportStart - padding - input.grabOffset, maxThumbStart),
|
|
124
|
-
)
|
|
170
|
+
const thumbStart = Math.max(0, Math.min(thumbOffset - padding, maxThumbStart))
|
|
171
|
+
const progress = reverse ? 1 - thumbStart / maxThumbStart : thumbStart / maxThumbStart
|
|
125
172
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return progress * Math.max(0, input.scrollSize - (input.scrollClientSize ?? input.clientSize))
|
|
173
|
+
return progress * Math.max(0, scrollSize - scrollClientSize)
|
|
129
174
|
}
|
|
130
175
|
|
|
131
176
|
/**
|
|
@@ -169,52 +214,53 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
169
214
|
let horizontalThumbRef!: HTMLDivElement
|
|
170
215
|
|
|
171
216
|
const thumbMount = () => local.thumbContainer
|
|
172
|
-
const thumbHover = () => local.thumbHoverTarget
|
|
173
|
-
const hoverRoot = () => !local.thumbHoverTarget && !local.thumbContainer
|
|
174
217
|
|
|
175
218
|
const [state, setState] = createStore({
|
|
176
|
-
isHovered: false,
|
|
177
|
-
dragging: undefined as "vertical" | "horizontal" | undefined,
|
|
178
|
-
isScrolling: false,
|
|
179
219
|
verticalThumbSize: 0,
|
|
180
220
|
verticalThumbStart: 0,
|
|
181
|
-
showVerticalThumb: false,
|
|
182
221
|
horizontalThumbSize: 0,
|
|
183
222
|
horizontalThumbStart: 0,
|
|
184
|
-
showHorizontalThumb: false,
|
|
185
223
|
})
|
|
186
224
|
|
|
187
|
-
const
|
|
188
|
-
const isDragging = () => state.dragging !== undefined
|
|
189
|
-
const isScrolling = () => state.isScrolling
|
|
225
|
+
const [thumbState, setThumbState] = createSignal<ScrollThumbState>(INITIAL_SCROLL_THUMB_STATE)
|
|
190
226
|
const vertical = () => local.orientation === "vertical" || local.orientation === "both"
|
|
191
227
|
const horizontal = () => local.orientation === "horizontal" || local.orientation === "both"
|
|
228
|
+
const thumbVisible = () => selectThumbVisible(thumbState(), local.thumbVisibility === "hover")
|
|
229
|
+
let idleTimer: ReturnType<typeof setTimeout> | undefined
|
|
192
230
|
|
|
193
|
-
|
|
231
|
+
const onIdleElapsed = () => {
|
|
232
|
+
idleTimer = undefined
|
|
233
|
+
dispatch(SCROLL_IDLE_ELAPSED)
|
|
234
|
+
}
|
|
194
235
|
|
|
195
|
-
const
|
|
196
|
-
|
|
236
|
+
const dispatch = (event: ScrollThumbEvent) => {
|
|
237
|
+
const prev = untrack(thumbState)
|
|
238
|
+
const next = transitionScrollThumb(prev, event)
|
|
197
239
|
|
|
198
|
-
if (
|
|
199
|
-
scrollIdleTimer = setTimeout(() => setState("isScrolling", false), 800)
|
|
200
|
-
}
|
|
240
|
+
if (next.state !== prev) setThumbState(next.state)
|
|
201
241
|
|
|
202
|
-
|
|
203
|
-
|
|
242
|
+
for (const effect of next.effects) {
|
|
243
|
+
if (effect === "release-capture") {
|
|
244
|
+
if (prev.status !== "dragging") continue
|
|
245
|
+
const thumb = prev.axis === "vertical" ? verticalThumbRef : horizontalThumbRef
|
|
204
246
|
|
|
205
|
-
|
|
247
|
+
if (thumb?.hasPointerCapture(prev.pointerId)) thumb.releasePointerCapture(prev.pointerId)
|
|
248
|
+
continue
|
|
249
|
+
}
|
|
206
250
|
|
|
207
|
-
|
|
251
|
+
clearTimeout(idleTimer)
|
|
252
|
+
idleTimer = effect === "reset-idle-timer" ? setTimeout(onIdleElapsed, SCROLL_IDLE_MS) : undefined
|
|
253
|
+
}
|
|
208
254
|
}
|
|
209
255
|
|
|
210
|
-
onCleanup(() =>
|
|
211
|
-
if (scrollIdleTimer !== undefined) clearTimeout(scrollIdleTimer)
|
|
212
|
-
})
|
|
256
|
+
onCleanup(() => dispatch(SCROLL_THUMB_DISPOSED))
|
|
213
257
|
|
|
214
258
|
const updateThumb = () => {
|
|
215
259
|
if (!viewportRef) return
|
|
216
260
|
const trackPadding = 8
|
|
217
261
|
const minThumbSize = 32
|
|
262
|
+
let verticalOverflow = false
|
|
263
|
+
let horizontalOverflow = false
|
|
218
264
|
|
|
219
265
|
if (vertical()) {
|
|
220
266
|
const adjustment = local.verticalScrollAdjustment ?? 0
|
|
@@ -227,14 +273,12 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
227
273
|
|
|
228
274
|
const maxScroll = scrollHeight - viewportRef.clientHeight
|
|
229
275
|
const maxStart = trackSize - size
|
|
230
|
-
|
|
276
|
+
verticalOverflow = maxScroll > 0
|
|
231
277
|
setState("verticalThumbSize", size)
|
|
232
278
|
setState(
|
|
233
279
|
"verticalThumbStart",
|
|
234
280
|
trackPadding + (maxScroll > 0 ? ((viewportRef.scrollTop + adjustment) / maxScroll) * maxStart : 0),
|
|
235
281
|
)
|
|
236
|
-
} else {
|
|
237
|
-
setState("showVerticalThumb", false)
|
|
238
282
|
}
|
|
239
283
|
|
|
240
284
|
if (horizontal()) {
|
|
@@ -249,12 +293,12 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
249
293
|
const rtl = getComputedStyle(viewportRef).direction === "rtl"
|
|
250
294
|
const offset = Math.max(0, Math.min(rtl ? -viewportRef.scrollLeft : viewportRef.scrollLeft, maxScroll))
|
|
251
295
|
const start = maxScroll > 0 ? (offset / maxScroll) * maxStart : 0
|
|
252
|
-
|
|
296
|
+
horizontalOverflow = maxScroll > 0
|
|
253
297
|
setState("horizontalThumbSize", size)
|
|
254
298
|
setState("horizontalThumbStart", trackPadding + (rtl ? maxStart - start : start))
|
|
255
|
-
} else {
|
|
256
|
-
setState("showHorizontalThumb", false)
|
|
257
299
|
}
|
|
300
|
+
|
|
301
|
+
dispatch(overflowChanged(verticalOverflow, horizontalOverflow))
|
|
258
302
|
}
|
|
259
303
|
|
|
260
304
|
onMount(() => {
|
|
@@ -266,7 +310,7 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
266
310
|
// appears later), after layout. Measuring here as well would force a synchronous layout per
|
|
267
311
|
// ScrollView while the page is still rendering.
|
|
268
312
|
createResizeObserver(
|
|
269
|
-
() => [viewportRef, viewportRef.firstElementChild, thumbMount()].filter(
|
|
313
|
+
() => [viewportRef, viewportRef.firstElementChild, thumbMount()].filter((element) => element != null),
|
|
270
314
|
updateThumb,
|
|
271
315
|
)
|
|
272
316
|
})
|
|
@@ -286,19 +330,22 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
286
330
|
onCleanup(() => observer.disconnect())
|
|
287
331
|
})
|
|
288
332
|
|
|
333
|
+
const onHoverEnter = () => dispatch(HOVER_ENTERED)
|
|
334
|
+
const onHoverLeave = () => dispatch(HOVER_LEFT)
|
|
335
|
+
|
|
336
|
+
// One element owns hover at a time. Swapping it ends the hover, so a target that stops owning it while hovered
|
|
337
|
+
// cannot leave the thumb shown.
|
|
289
338
|
createEffect(() => {
|
|
290
|
-
const target =
|
|
339
|
+
const target = local.thumbHoverTarget ?? (local.thumbContainer ? undefined : rootRef)
|
|
291
340
|
|
|
292
341
|
if (!target) return
|
|
293
342
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
target.addEventListener("pointerenter", enter)
|
|
297
|
-
target.addEventListener("pointerleave", leave)
|
|
343
|
+
target.addEventListener("pointerenter", onHoverEnter)
|
|
344
|
+
target.addEventListener("pointerleave", onHoverLeave)
|
|
298
345
|
onCleanup(() => {
|
|
299
|
-
target.removeEventListener("pointerenter",
|
|
300
|
-
target.removeEventListener("pointerleave",
|
|
301
|
-
|
|
346
|
+
target.removeEventListener("pointerenter", onHoverEnter)
|
|
347
|
+
target.removeEventListener("pointerleave", onHoverLeave)
|
|
348
|
+
dispatch(HOVER_LEFT)
|
|
302
349
|
})
|
|
303
350
|
})
|
|
304
351
|
|
|
@@ -309,70 +356,67 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
309
356
|
}
|
|
310
357
|
}
|
|
311
358
|
|
|
312
|
-
const onThumbPointerDown = (axis:
|
|
359
|
+
const onThumbPointerDown = (axis: ScrollAxis, e: PointerEvent & { currentTarget: HTMLDivElement }) => {
|
|
360
|
+
if (e.button !== 0) return
|
|
313
361
|
e.preventDefault()
|
|
314
362
|
e.stopPropagation()
|
|
315
363
|
prepareScroll()
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
axis
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
364
|
+
const rect = e.currentTarget.getBoundingClientRect()
|
|
365
|
+
|
|
366
|
+
dispatch({
|
|
367
|
+
type: "drag.started",
|
|
368
|
+
axis,
|
|
369
|
+
pointerId: e.pointerId,
|
|
370
|
+
grabOffset: axis === "vertical" ? e.clientY - rect.top : e.clientX - rect.left,
|
|
371
|
+
rtl: axis === "horizontal" && getComputedStyle(viewportRef).direction === "rtl",
|
|
372
|
+
})
|
|
325
373
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const onPointerMove = (e: PointerEvent) => {
|
|
329
|
-
prepareScroll()
|
|
330
|
-
const vertical = axis === "vertical"
|
|
331
|
-
const rtl = !vertical && getComputedStyle(viewportRef).direction === "rtl"
|
|
332
|
-
|
|
333
|
-
const offset = scrollOffsetFromThumbPointer({
|
|
334
|
-
pointer: vertical ? e.clientY : e.clientX,
|
|
335
|
-
viewportStart: vertical ? track.getBoundingClientRect().top : track.getBoundingClientRect().left,
|
|
336
|
-
grabOffset,
|
|
337
|
-
clientSize: vertical ? track.clientHeight : track.clientWidth,
|
|
338
|
-
scrollClientSize: vertical ? viewportRef.clientHeight : viewportRef.clientWidth,
|
|
339
|
-
scrollSize: vertical ? viewportRef.scrollHeight : viewportRef.scrollWidth,
|
|
340
|
-
thumbSize: vertical ? state.verticalThumbSize : state.horizontalThumbSize,
|
|
341
|
-
reverse: rtl,
|
|
342
|
-
})
|
|
374
|
+
if (e.isTrusted && selectDraggingAxis(untrack(thumbState)) === axis) e.currentTarget.setPointerCapture(e.pointerId)
|
|
375
|
+
}
|
|
343
376
|
|
|
344
|
-
|
|
345
|
-
|
|
377
|
+
const onThumbPointerMove = (e: PointerEvent) => {
|
|
378
|
+
const drag = untrack(thumbState)
|
|
346
379
|
|
|
347
|
-
|
|
348
|
-
|
|
380
|
+
if (drag.status !== "dragging" || drag.pointerId !== e.pointerId) return
|
|
381
|
+
prepareScroll()
|
|
382
|
+
const vertical = drag.axis === "vertical"
|
|
383
|
+
const track = thumbMount() ?? viewportRef
|
|
384
|
+
const rect = track.getBoundingClientRect()
|
|
385
|
+
|
|
386
|
+
const offset = thumbScrollOffset(
|
|
387
|
+
vertical ? e.clientY - rect.top - drag.grabOffset : e.clientX - rect.left - drag.grabOffset,
|
|
388
|
+
vertical ? track.clientHeight : track.clientWidth,
|
|
389
|
+
vertical ? viewportRef.scrollHeight : viewportRef.scrollWidth,
|
|
390
|
+
vertical ? state.verticalThumbSize : state.horizontalThumbSize,
|
|
391
|
+
vertical ? viewportRef.clientHeight : viewportRef.clientWidth,
|
|
392
|
+
drag.rtl,
|
|
393
|
+
)
|
|
349
394
|
|
|
350
|
-
|
|
351
|
-
|
|
395
|
+
if (vertical) {
|
|
396
|
+
viewportRef.scrollTop = offset
|
|
352
397
|
|
|
353
|
-
|
|
354
|
-
setState("dragging", undefined)
|
|
355
|
-
thumb.releasePointerCapture(e.pointerId)
|
|
356
|
-
thumb.removeEventListener("pointermove", onPointerMove)
|
|
357
|
-
thumb.removeEventListener("pointerup", done)
|
|
358
|
-
thumb.removeEventListener("pointercancel", done)
|
|
398
|
+
return
|
|
359
399
|
}
|
|
360
400
|
|
|
361
|
-
|
|
362
|
-
thumb.addEventListener("pointerup", done)
|
|
363
|
-
thumb.addEventListener("pointercancel", done)
|
|
401
|
+
viewportRef.scrollLeft = drag.rtl ? -offset : offset
|
|
364
402
|
}
|
|
365
403
|
|
|
404
|
+
const onThumbPointerEnd = (e: PointerEvent) => dispatch({ type: "drag.ended", pointerId: e.pointerId })
|
|
405
|
+
|
|
366
406
|
const renderVerticalThumb = () => (
|
|
367
407
|
<div
|
|
368
408
|
ref={(el) => {
|
|
369
409
|
verticalThumbRef = el
|
|
370
410
|
}}
|
|
371
411
|
onPointerDown={(event) => onThumbPointerDown("vertical", event)}
|
|
412
|
+
onPointerMove={onThumbPointerMove}
|
|
413
|
+
onPointerUp={onThumbPointerEnd}
|
|
414
|
+
onPointerCancel={onThumbPointerEnd}
|
|
415
|
+
onLostPointerCapture={onThumbPointerEnd}
|
|
372
416
|
class="scroll-view__thumb"
|
|
373
417
|
data-orientation="vertical"
|
|
374
418
|
data-visible={thumbVisible()}
|
|
375
|
-
data-dragging={
|
|
419
|
+
data-dragging={selectDraggingAxis(thumbState()) === "vertical"}
|
|
376
420
|
style={{
|
|
377
421
|
height: `${state.verticalThumbSize}px`,
|
|
378
422
|
transform: `translateY(${state.verticalThumbStart}px)`,
|
|
@@ -387,10 +431,14 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
387
431
|
horizontalThumbRef = el
|
|
388
432
|
}}
|
|
389
433
|
onPointerDown={(event) => onThumbPointerDown("horizontal", event)}
|
|
434
|
+
onPointerMove={onThumbPointerMove}
|
|
435
|
+
onPointerUp={onThumbPointerEnd}
|
|
436
|
+
onPointerCancel={onThumbPointerEnd}
|
|
437
|
+
onLostPointerCapture={onThumbPointerEnd}
|
|
390
438
|
class="scroll-view__thumb"
|
|
391
439
|
data-orientation="horizontal"
|
|
392
440
|
data-visible={thumbVisible()}
|
|
393
|
-
data-dragging={
|
|
441
|
+
data-dragging={selectDraggingAxis(thumbState()) === "horizontal"}
|
|
394
442
|
style={{
|
|
395
443
|
width: `${state.horizontalThumbSize}px`,
|
|
396
444
|
transform: `translateX(${state.horizontalThumbStart}px)`,
|
|
@@ -468,12 +516,6 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
468
516
|
class={`scroll-view ${local.class || ""}`}
|
|
469
517
|
data-orientation={local.orientation}
|
|
470
518
|
style={local.style}
|
|
471
|
-
onPointerEnter={() => {
|
|
472
|
-
if (hoverRoot()) setState("isHovered", true)
|
|
473
|
-
}}
|
|
474
|
-
onPointerLeave={() => {
|
|
475
|
-
if (hoverRoot()) setState("isHovered", false)
|
|
476
|
-
}}
|
|
477
519
|
{...rest}
|
|
478
520
|
>
|
|
479
521
|
{/* Viewport */}
|
|
@@ -483,47 +525,42 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
483
525
|
data-scrollable
|
|
484
526
|
onScroll={(e) => {
|
|
485
527
|
updateThumb()
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (typeof events.onScroll === "function") events.onScroll(e as any)
|
|
528
|
+
dispatch(SCROLLED)
|
|
529
|
+
forward(events.onScroll, e)
|
|
489
530
|
}}
|
|
490
531
|
// Passive so the compositor never waits on the main thread to scroll; onWheel cannot cancel.
|
|
491
532
|
on:wheel={{
|
|
492
533
|
passive: true,
|
|
493
534
|
handleEvent: (e) => {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
if (typeof handler === "function") handler(e as any)
|
|
498
|
-
|
|
499
|
-
if (Array.isArray(handler)) handler[0](handler[1], e as any)
|
|
535
|
+
dispatch(SCROLLED)
|
|
536
|
+
// SAFETY: this listener is on the viewport div, so `currentTarget` is that div and `target` an element in it.
|
|
537
|
+
forward(events.onWheel, e as WheelEvent & { currentTarget: HTMLDivElement; target: Element })
|
|
500
538
|
},
|
|
501
539
|
}}
|
|
502
|
-
onTouchStart={events.onTouchStart
|
|
503
|
-
onTouchMove={events.onTouchMove
|
|
504
|
-
onTouchEnd={events.onTouchEnd
|
|
505
|
-
onTouchCancel={events.onTouchCancel
|
|
506
|
-
onPointerDown={events.onPointerDown
|
|
507
|
-
onClick={events.onClick
|
|
540
|
+
onTouchStart={events.onTouchStart}
|
|
541
|
+
onTouchMove={events.onTouchMove}
|
|
542
|
+
onTouchEnd={events.onTouchEnd}
|
|
543
|
+
onTouchCancel={events.onTouchCancel}
|
|
544
|
+
onPointerDown={events.onPointerDown}
|
|
545
|
+
onClick={events.onClick}
|
|
508
546
|
tabIndex={0}
|
|
509
547
|
role="region"
|
|
510
548
|
aria-label={i18n.t("ui.scrollView.ariaLabel")}
|
|
511
549
|
onKeyDown={(e) => {
|
|
512
550
|
onKeyDown(e)
|
|
513
|
-
|
|
514
|
-
if (typeof events.onKeyDown === "function") events.onKeyDown(e as any)
|
|
551
|
+
forward(events.onKeyDown, e)
|
|
515
552
|
}}
|
|
516
553
|
>
|
|
517
554
|
{local.children}
|
|
518
555
|
</div>
|
|
519
556
|
|
|
520
557
|
{/* Thumb Overlay — optionally portaled into an external track */}
|
|
521
|
-
<Show when={
|
|
558
|
+
<Show when={selectShowVerticalThumb(thumbState())}>
|
|
522
559
|
<Show when={thumbMount()} fallback={renderVerticalThumb()}>
|
|
523
560
|
{(mount) => <Portal mount={mount()}>{renderVerticalThumb()}</Portal>}
|
|
524
561
|
</Show>
|
|
525
562
|
</Show>
|
|
526
|
-
<Show when={
|
|
563
|
+
<Show when={selectShowHorizontalThumb(thumbState())}>
|
|
527
564
|
<Show when={thumbMount()} fallback={renderHorizontalThumb()}>
|
|
528
565
|
{(mount) => <Portal mount={mount()}>{renderHorizontalThumb()}</Portal>}
|
|
529
566
|
</Show>
|
|
@@ -531,3 +568,13 @@ export function ScrollView(props: ScrollViewProps) {
|
|
|
531
568
|
</div>
|
|
532
569
|
)
|
|
533
570
|
}
|
|
571
|
+
|
|
572
|
+
// A forwarded handler may be a function or Solid's bound `[handler, data]` pair.
|
|
573
|
+
function forward<E extends Event>(
|
|
574
|
+
handler: JSX.EventHandlerUnion<HTMLDivElement, E> | undefined,
|
|
575
|
+
event: E & { currentTarget: HTMLDivElement; target: Element },
|
|
576
|
+
) {
|
|
577
|
+
if (handler instanceof Function) return handler(event)
|
|
578
|
+
|
|
579
|
+
if (handler) handler[0](handler[1], event)
|
|
580
|
+
}
|
|
@@ -1,21 +1,34 @@
|
|
|
1
|
+
/* `width` and `height` props arrive as variables, so classes and other CSS still size the spinner over them, as they
|
|
2
|
+
did over an SVG's attributes. */
|
|
3
|
+
[data-slot="spinner-dots"] {
|
|
4
|
+
position: relative;
|
|
5
|
+
display: block;
|
|
6
|
+
width: var(--spinner-width, 18px);
|
|
7
|
+
height: var(--spinner-height, auto);
|
|
8
|
+
aspect-ratio: 1;
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
[data-component="spinner"] {
|
|
2
12
|
color: inherit;
|
|
3
13
|
flex-shrink: 0;
|
|
4
|
-
width: 18px;
|
|
5
|
-
aspect-ratio: 1;
|
|
6
14
|
}
|
|
7
15
|
|
|
8
16
|
/* Each dot rests at its frozen pose, so reduced motion only has to stop the animation. */
|
|
9
|
-
[data-slot="spinner-dots"]
|
|
17
|
+
[data-slot="spinner-dots"] > svg {
|
|
18
|
+
position: absolute;
|
|
19
|
+
inset: 0;
|
|
20
|
+
width: 100%;
|
|
21
|
+
height: 100%;
|
|
22
|
+
overflow: visible;
|
|
10
23
|
opacity: var(--still);
|
|
11
24
|
}
|
|
12
25
|
|
|
13
26
|
/* syncSpinPhase marks spinners out of view; `!important` beats the inline animation each dot carries. */
|
|
14
|
-
[data-slot="spinner-dots"][data-offscreen]
|
|
27
|
+
[data-slot="spinner-dots"][data-offscreen] > svg {
|
|
15
28
|
animation-play-state: paused !important;
|
|
16
29
|
}
|
|
17
30
|
|
|
18
|
-
:root[data-motion="reduce"] [data-slot="spinner-dots"]
|
|
31
|
+
:root[data-motion="reduce"] [data-slot="spinner-dots"] > svg {
|
|
19
32
|
/* Beats the inline animation each dot carries. */
|
|
20
33
|
animation: none !important;
|
|
21
34
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { For, splitProps, type ComponentProps } from "solid-js"
|
|
1
|
+
import { For, splitProps, type ComponentProps, type JSX } from "solid-js"
|
|
2
2
|
import { syncSpinPhase } from "../hooks/spin-phase"
|
|
3
3
|
import { radarDots, radarKeyframes, radarLoop } from "./spinner-radar"
|
|
4
4
|
|
|
@@ -12,8 +12,20 @@ const dots = radarDots()
|
|
|
12
12
|
// The keyframes are added to the document once, the first time a spinner renders.
|
|
13
13
|
let added = false
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Each dot is its own SVG over the whole box, drawn exactly where it sat in one SVG. The compositor runs the opacity
|
|
17
|
+
* animation of an SVG element but not of a shape inside one, so a spinner no longer restyles and repaints on every
|
|
18
|
+
* frame. `width` and `height` size it like an SVG's attributes, below any CSS size.
|
|
19
|
+
*/
|
|
20
|
+
export function Spinner(
|
|
21
|
+
props: Omit<ComponentProps<"span">, "style"> & {
|
|
22
|
+
"data-component"?: string
|
|
23
|
+
width?: number
|
|
24
|
+
height?: number
|
|
25
|
+
style?: JSX.CSSProperties
|
|
26
|
+
},
|
|
27
|
+
) {
|
|
28
|
+
const [local, rest] = splitProps(props, ["class", "classList", "data-component", "width", "height", "style"])
|
|
17
29
|
|
|
18
30
|
if (!added) {
|
|
19
31
|
added = true
|
|
@@ -23,32 +35,34 @@ export function Spinner(props: ComponentProps<"svg"> & { "data-component"?: stri
|
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
return (
|
|
26
|
-
<
|
|
38
|
+
<span
|
|
27
39
|
{...rest}
|
|
28
40
|
ref={syncSpinPhase}
|
|
29
|
-
viewBox="0 0 16 16"
|
|
30
41
|
data-component={local["data-component"] ?? "spinner"}
|
|
31
42
|
data-slot="spinner-dots"
|
|
32
43
|
classList={{ ...local.classList, [local.class ?? ""]: !!local.class }}
|
|
33
|
-
|
|
44
|
+
style={{
|
|
45
|
+
...local.style,
|
|
46
|
+
"--spinner-width": local.width === undefined ? undefined : `${local.width}px`,
|
|
47
|
+
"--spinner-height": local.height === undefined ? undefined : `${local.height}px`,
|
|
48
|
+
}}
|
|
34
49
|
>
|
|
35
50
|
<For each={dots}>
|
|
36
51
|
{(dot) => (
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
width={dot.size}
|
|
41
|
-
height={dot.size}
|
|
42
|
-
rx={dot.size * 0.24}
|
|
52
|
+
<svg
|
|
53
|
+
viewBox="0 0 16 16"
|
|
54
|
+
fill="currentColor"
|
|
43
55
|
style={{
|
|
44
56
|
"--still": dot.still,
|
|
45
57
|
animation: dot.steady
|
|
46
58
|
? undefined
|
|
47
59
|
: `${keyframes}-${dot.shape} calc(${radarLoop}s * var(--spinner-time, 1)) linear calc(${-radarLoop * (1 - dot.at)}s * var(--spinner-time, 1)) infinite`,
|
|
48
60
|
}}
|
|
49
|
-
|
|
61
|
+
>
|
|
62
|
+
<rect x={dot.x} y={dot.y} width={dot.size} height={dot.size} rx={dot.size * 0.24} />
|
|
63
|
+
</svg>
|
|
50
64
|
)}
|
|
51
65
|
</For>
|
|
52
|
-
</
|
|
66
|
+
</span>
|
|
53
67
|
)
|
|
54
68
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export const TEXT_FIELD_COPIED_MS = 2_000
|
|
2
|
+
|
|
3
|
+
/** A clipboard write that never settles gives up, so the button can copy again. */
|
|
4
|
+
export const TEXT_FIELD_COPY_TIMEOUT_MS = 2_000
|
|
5
|
+
|
|
6
|
+
export type TextFieldCopyKind = "clipboard" | "link"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The copy button's feedback. `copying` claims the click before the write starts, so a second click waits for it;
|
|
10
|
+
* `keepCopied` keeps the checkmark of an earlier copy while a repeat copy settles. `attempt` lets only the latest
|
|
11
|
+
* write, its timeout and its own reset timer move the button.
|
|
12
|
+
*/
|
|
13
|
+
export type TextFieldCopyState =
|
|
14
|
+
| { readonly status: "idle"; readonly issued: number }
|
|
15
|
+
| { readonly status: "copying"; readonly attempt: number; readonly keepCopied: boolean }
|
|
16
|
+
| { readonly status: "copied"; readonly attempt: number }
|
|
17
|
+
| { readonly status: "disposed" }
|
|
18
|
+
|
|
19
|
+
export type TextFieldCopyEvent =
|
|
20
|
+
| { readonly type: "copy.requested"; readonly value: string; readonly enabled: boolean }
|
|
21
|
+
| { readonly type: "copy.succeeded"; readonly attempt: number }
|
|
22
|
+
| { readonly type: "copy.failed"; readonly attempt: number }
|
|
23
|
+
| { readonly type: "copy.timed-out"; readonly attempt: number }
|
|
24
|
+
| { readonly type: "reset.elapsed"; readonly attempt: number }
|
|
25
|
+
| { readonly type: "disposed" }
|
|
26
|
+
|
|
27
|
+
export type TextFieldCopyEffect =
|
|
28
|
+
| { readonly type: "clipboard.write"; readonly attempt: number; readonly value: string; readonly timeoutMs: number }
|
|
29
|
+
| { readonly type: "reset.schedule"; readonly attempt: number; readonly delayMs: number }
|
|
30
|
+
| { readonly type: "timer.clear" }
|
|
31
|
+
|
|
32
|
+
export type TextFieldCopyTransition = {
|
|
33
|
+
readonly state: TextFieldCopyState
|
|
34
|
+
readonly effects: readonly TextFieldCopyEffect[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const INITIAL_TEXT_FIELD_COPY_STATE: TextFieldCopyState = Object.freeze({ status: "idle", issued: 0 })
|
|
38
|
+
|
|
39
|
+
const NO_EFFECTS: readonly TextFieldCopyEffect[] = Object.freeze([])
|
|
40
|
+
|
|
41
|
+
const TIMER_CLEAR: TextFieldCopyEffect = Object.freeze({ type: "timer.clear" })
|
|
42
|
+
|
|
43
|
+
const DISPOSED: TextFieldCopyState = Object.freeze({ status: "disposed" })
|
|
44
|
+
|
|
45
|
+
export function transitionTextFieldCopy(state: TextFieldCopyState, event: TextFieldCopyEvent): TextFieldCopyTransition {
|
|
46
|
+
if (state.status === "disposed") return { state, effects: NO_EFFECTS }
|
|
47
|
+
|
|
48
|
+
if (event.type === "disposed")
|
|
49
|
+
return { state: DISPOSED, effects: state.status === "idle" ? NO_EFFECTS : [TIMER_CLEAR] }
|
|
50
|
+
|
|
51
|
+
if (event.type === "copy.requested") {
|
|
52
|
+
if (!event.enabled || state.status === "copying") return { state, effects: NO_EFFECTS }
|
|
53
|
+
const attempt = (state.status === "idle" ? state.issued : state.attempt) + 1
|
|
54
|
+
const timeoutMs = TEXT_FIELD_COPY_TIMEOUT_MS
|
|
55
|
+
const write: TextFieldCopyEffect = { type: "clipboard.write", attempt, value: event.value, timeoutMs }
|
|
56
|
+
|
|
57
|
+
if (state.status === "copied") {
|
|
58
|
+
return { state: { status: "copying", attempt, keepCopied: true }, effects: [TIMER_CLEAR, write] }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { state: { status: "copying", attempt, keepCopied: false }, effects: [write] }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (state.status === "idle" || event.attempt !== state.attempt) return { state, effects: NO_EFFECTS }
|
|
65
|
+
|
|
66
|
+
if (state.status === "copying" && event.type === "copy.succeeded") {
|
|
67
|
+
return {
|
|
68
|
+
state: { status: "copied", attempt: state.attempt },
|
|
69
|
+
effects: [TIMER_CLEAR, { type: "reset.schedule", attempt: state.attempt, delayMs: TEXT_FIELD_COPIED_MS }],
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (state.status === "copying" && (event.type === "copy.failed" || event.type === "copy.timed-out")) {
|
|
74
|
+
return { state: { status: "idle", issued: state.attempt }, effects: [TIMER_CLEAR] }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (state.status === "copied" && event.type === "reset.elapsed") {
|
|
78
|
+
return { state: { status: "idle", issued: state.attempt }, effects: NO_EFFECTS }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { state, effects: NO_EFFECTS }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function selectTextFieldCopied(state: TextFieldCopyState) {
|
|
85
|
+
return state.status === "copied" || (state.status === "copying" && state.keepCopied)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function selectTextFieldCopyLabelKey(state: TextFieldCopyState, kind: TextFieldCopyKind | undefined) {
|
|
89
|
+
if (selectTextFieldCopied(state)) return "ui.textField.copied"
|
|
90
|
+
|
|
91
|
+
if (kind === "link") return "ui.textField.copyLink"
|
|
92
|
+
|
|
93
|
+
return "ui.textField.copyToClipboard"
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function selectTextFieldCopyIcon(state: TextFieldCopyState, kind: TextFieldCopyKind | undefined) {
|
|
97
|
+
if (selectTextFieldCopied(state)) return "check"
|
|
98
|
+
|
|
99
|
+
if (kind === "link") return "link"
|
|
100
|
+
|
|
101
|
+
return "copy"
|
|
102
|
+
}
|