@opencode/ui 0.0.0-dev-750 → 0.0.0-dev-784
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/components/animated-number-machine.d.ts +95 -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/scroll-view-machine.d.ts +66 -0
- package/dist/components/scroll-view.d.ts +2 -2
- package/dist/components/text-field-machine.d.ts +62 -0
- package/dist/components/text-reveal-machine.d.ts +90 -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/toast/machine.d.ts +57 -0
- package/dist/feedback/toast/toast.d.ts +1 -1
- package/dist/forms/select/machine.d.ts +45 -0
- package/dist/forms/typeahead/machine.d.ts +85 -0
- package/dist/navigation/menu/machine.d.ts +49 -0
- package/dist/navigation/segmented-control/machine.d.ts +46 -0
- package/dist/theme/context.d.ts +20 -9
- package/dist/theme/machine.d.ts +174 -0
- package/package.json +2 -2
- package/src/components/animated-number-machine.ts +214 -0
- package/src/components/animated-number.tsx +134 -83
- 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 +113 -83
- package/src/components/scroll-view-machine.ts +231 -0
- package/src/components/scroll-view.tsx +163 -116
- 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/data-display/line-comment/line-comment.tsx +154 -178
- package/src/data-display/line-comment/machine.ts +392 -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/toast/machine.ts +115 -0
- package/src/feedback/toast/toast.tsx +55 -59
- package/src/forms/select/machine.ts +81 -0
- package/src/forms/select/select.tsx +49 -27
- package/src/forms/typeahead/machine.ts +253 -0
- package/src/forms/typeahead/typeahead.tsx +70 -62
- package/src/navigation/menu/machine.ts +109 -0
- package/src/navigation/menu/menu.tsx +118 -20
- package/src/navigation/segmented-control/machine.ts +72 -0
- package/src/navigation/segmented-control/segmented-control.tsx +46 -46
- package/src/theme/context.tsx +134 -240
- package/src/theme/machine.ts +508 -0
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import { splitProps, type JSX } from "solid-js"
|
|
1
|
+
import { createSignal, onCleanup, splitProps, untrack, type JSX } from "solid-js"
|
|
2
|
+
import {
|
|
3
|
+
INITIAL_RESIZE_HANDLE_STATE,
|
|
4
|
+
RESIZE_DRAG_CANCELLED,
|
|
5
|
+
RESIZE_HANDLE_DISPOSED,
|
|
6
|
+
resizeSign,
|
|
7
|
+
resizeSize,
|
|
8
|
+
selectResizeHandleActive,
|
|
9
|
+
transitionResizeHandle,
|
|
10
|
+
type ResizeHandleEvent,
|
|
11
|
+
type ResizeHandleState,
|
|
12
|
+
} from "./resize-handle-machine"
|
|
2
13
|
|
|
3
14
|
export interface ResizeHandleProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "onResize"> {
|
|
4
15
|
direction: "horizontal" | "vertical"
|
|
@@ -31,104 +42,123 @@ export function ResizeHandle(props: ResizeHandleProps) {
|
|
|
31
42
|
"classList",
|
|
32
43
|
])
|
|
33
44
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
45
|
+
const [dragState, setDragState] = createSignal<ResizeHandleState>(INITIAL_RESIZE_HANDLE_STATE)
|
|
46
|
+
const edge = () => local.edge ?? (local.direction === "vertical" ? "start" : "end")
|
|
47
|
+
const moved = { type: "pointer.moved" as const, pointerId: 0, pos: 0 }
|
|
48
|
+
let handle: HTMLDivElement | undefined
|
|
49
|
+
let body: { userSelect: string; overflow: string; cursor: string } | undefined
|
|
50
|
+
|
|
51
|
+
const dispatch = (event: ResizeHandleEvent) => {
|
|
52
|
+
const prev = untrack(dragState)
|
|
53
|
+
const next = transitionResizeHandle(prev, event)
|
|
54
|
+
|
|
55
|
+
if (next.state !== prev) setDragState(next.state)
|
|
56
|
+
|
|
57
|
+
for (const effect of next.effects) {
|
|
58
|
+
switch (effect) {
|
|
59
|
+
case "lock-body":
|
|
60
|
+
if (next.state.status !== "pressed") break
|
|
61
|
+
body = {
|
|
62
|
+
userSelect: document.body.style.userSelect,
|
|
63
|
+
overflow: document.body.style.overflow,
|
|
64
|
+
cursor: document.body.style.cursor,
|
|
65
|
+
}
|
|
66
|
+
document.body.style.userSelect = "none"
|
|
67
|
+
document.body.style.overflow = "hidden"
|
|
68
|
+
document.body.style.cursor = next.state.session.direction === "horizontal" ? "col-resize" : "row-resize"
|
|
69
|
+
window.addEventListener("pointermove", onPointerMove)
|
|
70
|
+
window.addEventListener("pointerup", onPointerUp)
|
|
71
|
+
window.addEventListener("pointercancel", onPointerCancel)
|
|
72
|
+
window.addEventListener("blur", onBlur)
|
|
73
|
+
break
|
|
74
|
+
case "unlock-body":
|
|
75
|
+
window.removeEventListener("pointermove", onPointerMove)
|
|
76
|
+
window.removeEventListener("pointerup", onPointerUp)
|
|
77
|
+
window.removeEventListener("pointercancel", onPointerCancel)
|
|
78
|
+
window.removeEventListener("blur", onBlur)
|
|
79
|
+
|
|
80
|
+
if (prev.status === "pressed" || prev.status === "dragging") {
|
|
81
|
+
if (handle?.hasPointerCapture(prev.session.pointerId)) handle.releasePointerCapture(prev.session.pointerId)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (body) Object.assign(document.body.style, body)
|
|
85
|
+
body = undefined
|
|
86
|
+
break
|
|
87
|
+
case "dragging-true":
|
|
88
|
+
case "dragging-false":
|
|
89
|
+
local.onDraggingChange?.(effect === "dragging-true")
|
|
90
|
+
break
|
|
91
|
+
case "collapse-true":
|
|
92
|
+
case "collapse-false":
|
|
93
|
+
local.onCollapseChange?.(effect === "collapse-true")
|
|
94
|
+
break
|
|
95
|
+
case "collapse-commit":
|
|
96
|
+
local.onCollapse?.()
|
|
97
|
+
break
|
|
98
|
+
case "resize":
|
|
99
|
+
if (next.state.status === "dragging") local.onResize(resizeSize(next.state.session, moved.pos))
|
|
100
|
+
break
|
|
67
101
|
}
|
|
68
|
-
|
|
69
|
-
const pos = local.direction === "horizontal" ? moveEvent.clientX : moveEvent.clientY
|
|
70
|
-
|
|
71
|
-
const delta =
|
|
72
|
-
local.direction === "vertical"
|
|
73
|
-
? edge === "end"
|
|
74
|
-
? pos - start
|
|
75
|
-
: start - pos
|
|
76
|
-
: (edge === "start") !== rtl
|
|
77
|
-
? start - pos
|
|
78
|
-
: pos - start
|
|
79
|
-
|
|
80
|
-
current = startSize + delta
|
|
81
|
-
const nextCollapsed = threshold > 0 && current < threshold
|
|
82
|
-
|
|
83
|
-
if (nextCollapsed !== collapsed) {
|
|
84
|
-
collapsed = nextCollapsed
|
|
85
|
-
onCollapseChange?.(collapsed)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
onResize(Math.min(max, Math.max(min, current)))
|
|
89
102
|
}
|
|
103
|
+
}
|
|
90
104
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
document.body.style.overflow = ""
|
|
94
|
-
document.body.style.cursor = ""
|
|
95
|
-
handle?.removeAttribute("data-dragging")
|
|
96
|
-
document.removeEventListener("mousemove", onMouseMove)
|
|
97
|
-
document.removeEventListener("mouseup", onMouseUp)
|
|
98
|
-
|
|
99
|
-
if (moved) onDraggingChange?.(false)
|
|
100
|
-
|
|
101
|
-
if (collapsed) {
|
|
102
|
-
onCollapse?.()
|
|
103
|
-
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
onCollapseChange?.(false)
|
|
108
|
-
}
|
|
105
|
+
const onPointerMove = (e: PointerEvent) => {
|
|
106
|
+
const state = untrack(dragState)
|
|
109
107
|
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
if (state.status !== "pressed" && state.status !== "dragging") return
|
|
109
|
+
moved.pointerId = e.pointerId
|
|
110
|
+
moved.pos = state.session.direction === "horizontal" ? e.clientX : e.clientY
|
|
111
|
+
dispatch(moved)
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
const onPointerUp = (e: PointerEvent) => dispatch({ type: "pointer.up", pointerId: e.pointerId })
|
|
115
|
+
const onPointerCancel = (e: PointerEvent) => dispatch({ type: "drag.cancelled", pointerId: e.pointerId })
|
|
116
|
+
const onBlur = () => dispatch(RESIZE_DRAG_CANCELLED)
|
|
117
|
+
|
|
118
|
+
onCleanup(() => dispatch(RESIZE_HANDLE_DISPOSED))
|
|
119
119
|
|
|
120
120
|
return (
|
|
121
121
|
<div
|
|
122
122
|
{...rest}
|
|
123
|
+
ref={handle}
|
|
123
124
|
data-component="resize-handle"
|
|
124
125
|
data-direction={local.direction}
|
|
125
|
-
data-edge={
|
|
126
|
+
data-edge={edge()}
|
|
127
|
+
data-dragging={selectResizeHandleActive(dragState()) ? "" : undefined}
|
|
126
128
|
classList={{
|
|
127
129
|
...local.classList,
|
|
128
130
|
[local.class ?? ""]: !!local.class,
|
|
129
131
|
}}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
// Bubbles on purpose: wrappers start their own resize state from this `pointerdown`.
|
|
133
|
+
onPointerDown={(e) => {
|
|
134
|
+
const rtl = local.direction === "horizontal" && getComputedStyle(e.currentTarget).direction === "rtl"
|
|
135
|
+
|
|
136
|
+
dispatch({
|
|
137
|
+
type: "pointer.down",
|
|
138
|
+
button: e.button,
|
|
139
|
+
ctrlKey: e.ctrlKey,
|
|
140
|
+
detail: e.detail,
|
|
141
|
+
session: {
|
|
142
|
+
pointerId: e.pointerId,
|
|
143
|
+
direction: local.direction,
|
|
144
|
+
sign: resizeSign(local.direction, edge(), rtl),
|
|
145
|
+
startPos: local.direction === "horizontal" ? e.clientX : e.clientY,
|
|
146
|
+
startSize: local.size,
|
|
147
|
+
min: local.min,
|
|
148
|
+
max: local.max,
|
|
149
|
+
threshold: local.collapseThreshold ?? 0,
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
// The handle holds the pointer until the button comes up, so hover stays on it rather than following the
|
|
154
|
+
// pointer across the panels it resizes, each crossing restyling their contents.
|
|
155
|
+
if (e.isTrusted && untrack(dragState).status === "pressed") e.currentTarget.setPointerCapture(e.pointerId)
|
|
156
|
+
}}
|
|
157
|
+
// Keeps focus and text selection where they are; canceling `pointerdown` would not.
|
|
158
|
+
onMouseDown={(e) => {
|
|
159
|
+
if (selectResizeHandleActive(untrack(dragState))) e.preventDefault()
|
|
160
|
+
}}
|
|
161
|
+
onLostPointerCapture={(e) => dispatch({ type: "drag.cancelled", pointerId: e.pointerId })}
|
|
132
162
|
/>
|
|
133
163
|
)
|
|
134
164
|
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
export const SCROLL_IDLE_MS = 800
|
|
2
|
+
|
|
3
|
+
export type ScrollAxis = "vertical" | "horizontal"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `scrolling` shows the thumb until `SCROLL_IDLE_MS` after the last scroll. `dragging` holds the pointer on one thumb;
|
|
7
|
+
* `scrolled` records a scroll during the drag, so its release keeps the thumb up for the idle delay. A thumb exists
|
|
8
|
+
* only while its axis overflows, so losing that overflow ends a drag on it.
|
|
9
|
+
*/
|
|
10
|
+
export type ScrollThumbState =
|
|
11
|
+
| {
|
|
12
|
+
readonly status: "idle" | "scrolling"
|
|
13
|
+
readonly hovered: boolean
|
|
14
|
+
readonly verticalOverflow: boolean
|
|
15
|
+
readonly horizontalOverflow: boolean
|
|
16
|
+
}
|
|
17
|
+
| {
|
|
18
|
+
readonly status: "dragging"
|
|
19
|
+
readonly axis: ScrollAxis
|
|
20
|
+
readonly pointerId: number
|
|
21
|
+
readonly grabOffset: number
|
|
22
|
+
readonly rtl: boolean
|
|
23
|
+
readonly hovered: boolean
|
|
24
|
+
readonly scrolled: boolean
|
|
25
|
+
readonly verticalOverflow: boolean
|
|
26
|
+
readonly horizontalOverflow: boolean
|
|
27
|
+
}
|
|
28
|
+
| { readonly status: "disposed" }
|
|
29
|
+
|
|
30
|
+
export type ScrollThumbEvent =
|
|
31
|
+
| { readonly type: "hover.changed"; readonly hovered: boolean }
|
|
32
|
+
| { readonly type: "scrolled" }
|
|
33
|
+
| { readonly type: "idle.elapsed" }
|
|
34
|
+
| { readonly type: "overflow.changed"; readonly vertical: boolean; readonly horizontal: boolean }
|
|
35
|
+
| {
|
|
36
|
+
readonly type: "drag.started"
|
|
37
|
+
readonly axis: ScrollAxis
|
|
38
|
+
readonly pointerId: number
|
|
39
|
+
readonly grabOffset: number
|
|
40
|
+
readonly rtl: boolean
|
|
41
|
+
}
|
|
42
|
+
| { readonly type: "drag.ended"; readonly pointerId: number }
|
|
43
|
+
| { readonly type: "disposed" }
|
|
44
|
+
|
|
45
|
+
export type ScrollThumbEffect = "reset-idle-timer" | "clear-idle-timer" | "release-capture"
|
|
46
|
+
|
|
47
|
+
export type ScrollThumbTransition = {
|
|
48
|
+
readonly state: ScrollThumbState
|
|
49
|
+
readonly effects: readonly ScrollThumbEffect[]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type Resting = Extract<ScrollThumbState, { readonly status: "idle" | "scrolling" }>
|
|
53
|
+
|
|
54
|
+
type Dragging = Extract<ScrollThumbState, { readonly status: "dragging" }>
|
|
55
|
+
|
|
56
|
+
// Scroll, wheel and resize fire every frame. Every resting state and the common transitions are prebuilt, so those
|
|
57
|
+
// events allocate nothing.
|
|
58
|
+
const RESTING = (["idle", "scrolling"] as const).flatMap((status) =>
|
|
59
|
+
[false, true].flatMap((hovered) =>
|
|
60
|
+
[false, true].flatMap((verticalOverflow) =>
|
|
61
|
+
[false, true].map(
|
|
62
|
+
(horizontalOverflow): Resting => Object.freeze({ status, hovered, verticalOverflow, horizontalOverflow }),
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const DISPOSED: ScrollThumbState = Object.freeze({ status: "disposed" })
|
|
69
|
+
|
|
70
|
+
export const INITIAL_SCROLL_THUMB_STATE: ScrollThumbState = resting("idle", false, false, false)
|
|
71
|
+
|
|
72
|
+
export const SCROLLED: ScrollThumbEvent = Object.freeze({ type: "scrolled" })
|
|
73
|
+
|
|
74
|
+
export const SCROLL_IDLE_ELAPSED: ScrollThumbEvent = Object.freeze({ type: "idle.elapsed" })
|
|
75
|
+
|
|
76
|
+
export const HOVER_ENTERED: ScrollThumbEvent = Object.freeze({ type: "hover.changed", hovered: true })
|
|
77
|
+
|
|
78
|
+
export const HOVER_LEFT: ScrollThumbEvent = Object.freeze({ type: "hover.changed", hovered: false })
|
|
79
|
+
|
|
80
|
+
export const SCROLL_THUMB_DISPOSED: ScrollThumbEvent = Object.freeze({ type: "disposed" })
|
|
81
|
+
|
|
82
|
+
const OVERFLOW = [false, true].flatMap((vertical) =>
|
|
83
|
+
[false, true].map(
|
|
84
|
+
(horizontal): ScrollThumbEvent => Object.freeze({ type: "overflow.changed", vertical, horizontal }),
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const NONE: readonly ScrollThumbEffect[] = Object.freeze([])
|
|
89
|
+
|
|
90
|
+
const RESET: readonly ScrollThumbEffect[] = Object.freeze(["reset-idle-timer"])
|
|
91
|
+
|
|
92
|
+
const CLEAR: readonly ScrollThumbEffect[] = Object.freeze(["clear-idle-timer"])
|
|
93
|
+
|
|
94
|
+
const RELEASE: readonly ScrollThumbEffect[] = Object.freeze(["release-capture"])
|
|
95
|
+
|
|
96
|
+
const RELEASE_AND_RESET: readonly ScrollThumbEffect[] = Object.freeze(["release-capture", "reset-idle-timer"])
|
|
97
|
+
|
|
98
|
+
const RELEASE_AND_CLEAR: readonly ScrollThumbEffect[] = Object.freeze(["release-capture", "clear-idle-timer"])
|
|
99
|
+
|
|
100
|
+
const KEEP = new Map<ScrollThumbState, ScrollThumbTransition>(
|
|
101
|
+
[...RESTING, DISPOSED].map((state) => [state, Object.freeze({ state, effects: NONE })]),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const RESTART = new Map<ScrollThumbState, ScrollThumbTransition>(
|
|
105
|
+
RESTING.map((state) => [state, Object.freeze({ state, effects: RESET })]),
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
export function overflowChanged(vertical: boolean, horizontal: boolean) {
|
|
109
|
+
return OVERFLOW[(vertical ? 2 : 0) + (horizontal ? 1 : 0)]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function transitionScrollThumb(state: ScrollThumbState, event: ScrollThumbEvent): ScrollThumbTransition {
|
|
113
|
+
if (state.status === "disposed") return to(state, NONE)
|
|
114
|
+
|
|
115
|
+
if (event.type === "disposed")
|
|
116
|
+
return to(DISPOSED, state.status === "dragging" ? RELEASE_AND_CLEAR : state.status === "scrolling" ? CLEAR : NONE)
|
|
117
|
+
|
|
118
|
+
if (state.status === "dragging") return transitionDragging(state, event)
|
|
119
|
+
|
|
120
|
+
return transitionResting(state, event)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function selectShowVerticalThumb(state: ScrollThumbState) {
|
|
124
|
+
return state.status !== "disposed" && state.verticalOverflow
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function selectShowHorizontalThumb(state: ScrollThumbState) {
|
|
128
|
+
return state.status !== "disposed" && state.horizontalOverflow
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function selectDraggingAxis(state: ScrollThumbState) {
|
|
132
|
+
return state.status === "dragging" ? state.axis : undefined
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** `hoverReveals` is the `hover` visibility mode; in `scroll` mode only scrolling and dragging show the thumb. */
|
|
136
|
+
export function selectThumbVisible(state: ScrollThumbState, hoverReveals: boolean) {
|
|
137
|
+
if (state.status === "dragging" || state.status === "scrolling") return true
|
|
138
|
+
|
|
139
|
+
return state.status === "idle" && hoverReveals && state.hovered
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function transitionResting(
|
|
143
|
+
state: Resting,
|
|
144
|
+
event: Exclude<ScrollThumbEvent, { type: "disposed" }>,
|
|
145
|
+
): ScrollThumbTransition {
|
|
146
|
+
switch (event.type) {
|
|
147
|
+
case "hover.changed":
|
|
148
|
+
return to(resting(state.status, event.hovered, state.verticalOverflow, state.horizontalOverflow), NONE)
|
|
149
|
+
case "scrolled":
|
|
150
|
+
if (!state.verticalOverflow && !state.horizontalOverflow) return to(state, NONE)
|
|
151
|
+
|
|
152
|
+
return to(resting("scrolling", state.hovered, state.verticalOverflow, state.horizontalOverflow), RESET)
|
|
153
|
+
case "idle.elapsed":
|
|
154
|
+
if (state.status !== "scrolling") return to(state, NONE)
|
|
155
|
+
|
|
156
|
+
return to(resting("idle", state.hovered, state.verticalOverflow, state.horizontalOverflow), NONE)
|
|
157
|
+
case "overflow.changed":
|
|
158
|
+
if (state.status === "scrolling" && !event.vertical && !event.horizontal)
|
|
159
|
+
return to(resting("idle", state.hovered, false, false), CLEAR)
|
|
160
|
+
|
|
161
|
+
return to(resting(state.status, state.hovered, event.vertical, event.horizontal), NONE)
|
|
162
|
+
case "drag.started":
|
|
163
|
+
if (!(event.axis === "vertical" ? state.verticalOverflow : state.horizontalOverflow)) return to(state, NONE)
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
state: {
|
|
167
|
+
status: "dragging",
|
|
168
|
+
axis: event.axis,
|
|
169
|
+
pointerId: event.pointerId,
|
|
170
|
+
grabOffset: event.grabOffset,
|
|
171
|
+
rtl: event.rtl,
|
|
172
|
+
hovered: state.hovered,
|
|
173
|
+
scrolled: state.status === "scrolling",
|
|
174
|
+
verticalOverflow: state.verticalOverflow,
|
|
175
|
+
horizontalOverflow: state.horizontalOverflow,
|
|
176
|
+
},
|
|
177
|
+
effects: state.status === "scrolling" ? CLEAR : NONE,
|
|
178
|
+
}
|
|
179
|
+
case "drag.ended":
|
|
180
|
+
return to(state, NONE)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function transitionDragging(
|
|
185
|
+
state: Dragging,
|
|
186
|
+
event: Exclude<ScrollThumbEvent, { type: "disposed" }>,
|
|
187
|
+
): ScrollThumbTransition {
|
|
188
|
+
switch (event.type) {
|
|
189
|
+
case "hover.changed":
|
|
190
|
+
if (event.hovered === state.hovered) return to(state, NONE)
|
|
191
|
+
|
|
192
|
+
return to({ ...state, hovered: event.hovered }, NONE)
|
|
193
|
+
case "scrolled":
|
|
194
|
+
if (state.scrolled) return to(state, NONE)
|
|
195
|
+
|
|
196
|
+
return to({ ...state, scrolled: true }, NONE)
|
|
197
|
+
case "overflow.changed":
|
|
198
|
+
// The thumb unmounts with its overflow, and a removed element drops pointer capture without a `pointerup`.
|
|
199
|
+
if (!(state.axis === "vertical" ? event.vertical : event.horizontal))
|
|
200
|
+
return release(state, event.vertical, event.horizontal)
|
|
201
|
+
|
|
202
|
+
if (event.vertical === state.verticalOverflow && event.horizontal === state.horizontalOverflow)
|
|
203
|
+
return to(state, NONE)
|
|
204
|
+
|
|
205
|
+
return to({ ...state, verticalOverflow: event.vertical, horizontalOverflow: event.horizontal }, NONE)
|
|
206
|
+
case "drag.ended":
|
|
207
|
+
if (event.pointerId !== state.pointerId) return to(state, NONE)
|
|
208
|
+
|
|
209
|
+
return release(state, state.verticalOverflow, state.horizontalOverflow)
|
|
210
|
+
case "idle.elapsed":
|
|
211
|
+
case "drag.started":
|
|
212
|
+
return to(state, NONE)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function release(state: Dragging, vertical: boolean, horizontal: boolean) {
|
|
217
|
+
if (state.scrolled && (vertical || horizontal))
|
|
218
|
+
return to(resting("scrolling", state.hovered, vertical, horizontal), RELEASE_AND_RESET)
|
|
219
|
+
|
|
220
|
+
return to(resting("idle", state.hovered, vertical, horizontal), RELEASE)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function to(state: ScrollThumbState, effects: readonly ScrollThumbEffect[]): ScrollThumbTransition {
|
|
224
|
+
const cached = effects === NONE ? KEEP.get(state) : effects === RESET ? RESTART.get(state) : undefined
|
|
225
|
+
|
|
226
|
+
return cached ?? { state, effects }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function resting(status: Resting["status"], hovered: boolean, vertical: boolean, horizontal: boolean) {
|
|
230
|
+
return RESTING[(status === "scrolling" ? 8 : 0) + (hovered ? 4 : 0) + (vertical ? 2 : 0) + (horizontal ? 1 : 0)]
|
|
231
|
+
}
|