@opencode/ui 0.0.0-dev-724 → 0.0.0-dev-750
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/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/overlays/tooltip/machine.d.ts +146 -0
- package/package.json +3 -3
- 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/overlays/tooltip/machine.ts +303 -0
- package/src/overlays/tooltip/tooltip.tsx +160 -133
|
@@ -1,8 +1,32 @@
|
|
|
1
1
|
import { Content, Portal, Root, Trigger } from "@kobalte/core/tooltip"
|
|
2
|
-
import { createComputed,
|
|
2
|
+
import { createComputed, createSignal, onCleanup, onMount, Show, splitProps, untrack, type JSX } from "solid-js"
|
|
3
3
|
import type { ComponentProps } from "solid-js"
|
|
4
|
-
import { createStore } from "solid-js/store"
|
|
5
4
|
import { spread } from "solid-js/web"
|
|
5
|
+
import {
|
|
6
|
+
createTooltipState,
|
|
7
|
+
DISPOSED_EVENT,
|
|
8
|
+
FOCUSED,
|
|
9
|
+
KOBALTE_CLOSED,
|
|
10
|
+
KOBALTE_OPENED,
|
|
11
|
+
LEAVE_SETTLED,
|
|
12
|
+
POINTER_ENTERED,
|
|
13
|
+
POINTER_INSIDE,
|
|
14
|
+
POINTER_LEFT,
|
|
15
|
+
POINTER_OUTSIDE,
|
|
16
|
+
POPUP_COLLAPSED,
|
|
17
|
+
POPUP_EXPANDED,
|
|
18
|
+
PRESS_ENDED,
|
|
19
|
+
selectTooltipForceOpen,
|
|
20
|
+
selectTooltipMounted,
|
|
21
|
+
selectTooltipOpen,
|
|
22
|
+
selectTooltipPressing,
|
|
23
|
+
selectTooltipTracking,
|
|
24
|
+
syncPropsEvent,
|
|
25
|
+
transitionTooltip,
|
|
26
|
+
TRIGGER_PRESSED,
|
|
27
|
+
type TooltipEvent,
|
|
28
|
+
type TooltipState,
|
|
29
|
+
} from "./machine"
|
|
6
30
|
import "./tooltip.css"
|
|
7
31
|
|
|
8
32
|
export interface TooltipProps extends ComponentProps<typeof Root> {
|
|
@@ -21,19 +45,21 @@ type TriggerHandlers = {
|
|
|
21
45
|
onFocus?: (event: FocusEvent) => void
|
|
22
46
|
}
|
|
23
47
|
|
|
48
|
+
// Expanded panels still need tooltips; only an open popup suppresses its trigger's tooltip.
|
|
49
|
+
const POPUP = '[aria-haspopup]:not([aria-haspopup="false"]):is([aria-expanded="true"], [data-expanded])'
|
|
50
|
+
|
|
24
51
|
export function Tooltip(props: TooltipProps) {
|
|
52
|
+
return (
|
|
53
|
+
<Show when={!props.inactive} fallback={props.children}>
|
|
54
|
+
<ActiveTooltip {...props} />
|
|
55
|
+
</Show>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function ActiveTooltip(props: TooltipProps) {
|
|
25
60
|
let ref: HTMLDivElement | undefined
|
|
26
61
|
let handlers: TriggerHandlers | undefined
|
|
27
|
-
|
|
28
|
-
const [state, setState] = createStore({
|
|
29
|
-
open: false,
|
|
30
|
-
block: false,
|
|
31
|
-
expand: false,
|
|
32
|
-
// Kobalte's tooltip costs dozens of computations and listeners per trigger, and most triggers (an action on every
|
|
33
|
-
// timeline row, a copy button on every code block) are never hovered. It mounts on the first interaction that
|
|
34
|
-
// could open it, or as soon as a caller controls it with forceOpen.
|
|
35
|
-
mounted: false,
|
|
36
|
-
})
|
|
62
|
+
let observer: MutationObserver | undefined
|
|
37
63
|
|
|
38
64
|
const [local, others] = splitProps(props, [
|
|
39
65
|
"children",
|
|
@@ -48,80 +74,89 @@ export function Tooltip(props: TooltipProps) {
|
|
|
48
74
|
"value",
|
|
49
75
|
])
|
|
50
76
|
|
|
51
|
-
|
|
52
|
-
|
|
77
|
+
// Kobalte's tooltip costs dozens of computations and listeners per trigger, and most triggers (an action on every
|
|
78
|
+
// timeline row, a copy button on every code block) are never hovered. It mounts on the first interaction that could
|
|
79
|
+
// open it, or as soon as a caller controls it with forceOpen.
|
|
80
|
+
const [tooltip, setTooltip] = createSignal(createTooltipState(local.forceOpen, !!others.disabled))
|
|
53
81
|
|
|
54
|
-
const
|
|
55
|
-
const
|
|
82
|
+
const dispatch = (event: TooltipEvent, source?: PointerEvent | FocusEvent) => {
|
|
83
|
+
const previous = untrack(tooltip)
|
|
84
|
+
const transition = transitionTooltip(previous, event)
|
|
56
85
|
|
|
57
|
-
if (
|
|
86
|
+
if (transition.state !== previous) {
|
|
87
|
+
setTooltip(transition.state)
|
|
88
|
+
reconcile(previous, transition.state)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const effect of transition.effects) {
|
|
92
|
+
if (effect === "schedule-leave") queueMicrotask(settleLeave)
|
|
93
|
+
|
|
94
|
+
// Kobalte attached its listeners while this event was being dispatched, too late to receive it.
|
|
95
|
+
if (effect === "replay" && source instanceof PointerEvent) handlers?.onPointerEnter?.(source)
|
|
58
96
|
|
|
59
|
-
|
|
97
|
+
if (effect === "replay" && source instanceof FocusEvent) handlers?.onFocus?.(source)
|
|
98
|
+
}
|
|
60
99
|
}
|
|
61
100
|
|
|
62
|
-
|
|
63
|
-
|
|
101
|
+
// Kobalte's own pointerleave handler runs after this one and only starts the skip-delay window for neighbouring
|
|
102
|
+
// tooltips if it still sees this one open.
|
|
103
|
+
const settleLeave = () => dispatch(LEAVE_SETTLED)
|
|
104
|
+
const syncPopup = () => dispatch(ref?.querySelector(POPUP) ? POPUP_EXPANDED : POPUP_COLLAPSED)
|
|
105
|
+
// The press's click, if any, follows its pointerup in the same task.
|
|
106
|
+
const onPressEnd = () => setTimeout(dispatch, 0, PRESS_ENDED)
|
|
64
107
|
|
|
65
|
-
|
|
108
|
+
const onPointerMove = (event: PointerEvent) => {
|
|
109
|
+
if (!ref) return
|
|
110
|
+
const box = ref.getBoundingClientRect()
|
|
66
111
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
112
|
+
const inside =
|
|
113
|
+
event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom
|
|
70
114
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const expand = !!ref?.querySelector(
|
|
74
|
-
'[aria-haspopup]:not([aria-haspopup="false"]):is([aria-expanded="true"], [data-expanded])',
|
|
75
|
-
)
|
|
115
|
+
dispatch(inside ? POINTER_INSIDE : POINTER_OUTSIDE)
|
|
116
|
+
}
|
|
76
117
|
|
|
77
|
-
|
|
118
|
+
// Attaches the listeners and observer the state needs and detaches the rest.
|
|
119
|
+
const reconcile = (previous: TooltipState, state: TooltipState) => {
|
|
120
|
+
const pressing = selectTooltipPressing(state)
|
|
78
121
|
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
122
|
+
if (pressing && !selectTooltipPressing(previous)) {
|
|
123
|
+
window.addEventListener("pointerup", onPressEnd, true)
|
|
124
|
+
window.addEventListener("pointercancel", onPressEnd, true)
|
|
125
|
+
}
|
|
82
126
|
|
|
83
|
-
|
|
127
|
+
if (!pressing && selectTooltipPressing(previous)) {
|
|
128
|
+
window.removeEventListener("pointerup", onPressEnd, true)
|
|
129
|
+
window.removeEventListener("pointercancel", onPressEnd, true)
|
|
84
130
|
}
|
|
85
131
|
|
|
86
|
-
|
|
87
|
-
}
|
|
132
|
+
const tracking = selectTooltipTracking(state)
|
|
88
133
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
queueMicrotask(() => {
|
|
93
|
-
if (!inside()) close()
|
|
94
|
-
drop()
|
|
95
|
-
})
|
|
96
|
-
}
|
|
134
|
+
if (tracking && !selectTooltipTracking(previous)) {
|
|
135
|
+
window.addEventListener("pointermove", onPointerMove, { capture: true, passive: true })
|
|
136
|
+
}
|
|
97
137
|
|
|
98
|
-
|
|
99
|
-
if (state.mounted) return
|
|
100
|
-
setState("mounted", true)
|
|
138
|
+
if (!tracking && selectTooltipTracking(previous)) window.removeEventListener("pointermove", onPointerMove, true)
|
|
101
139
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
else handlers?.onFocus?.(event)
|
|
105
|
-
}
|
|
140
|
+
if (state.status === "disposed") {
|
|
141
|
+
observer?.disconnect()
|
|
106
142
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
})
|
|
143
|
+
return
|
|
144
|
+
}
|
|
110
145
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const obs = new MutationObserver(sync)
|
|
115
|
-
obs.observe(ref, {
|
|
146
|
+
if (!ref || observer || !selectTooltipMounted(state)) return
|
|
147
|
+
observer = new MutationObserver(syncPopup)
|
|
148
|
+
observer.observe(ref, {
|
|
116
149
|
subtree: true,
|
|
117
150
|
childList: true,
|
|
118
151
|
attributes: true,
|
|
119
152
|
attributeFilter: ["aria-expanded", "data-expanded", "aria-haspopup"],
|
|
120
153
|
})
|
|
121
|
-
|
|
122
|
-
}
|
|
154
|
+
syncPopup()
|
|
155
|
+
}
|
|
123
156
|
|
|
124
|
-
|
|
157
|
+
createComputed(() => dispatch(syncPropsEvent(local.forceOpen, !!others.disabled)))
|
|
158
|
+
onMount(() => reconcile(untrack(tooltip), untrack(tooltip)))
|
|
159
|
+
onCleanup(() => dispatch(DISPOSED_EVENT))
|
|
125
160
|
|
|
126
161
|
// Kobalte's trigger takes over the element rendered below instead of rendering one, so mounting the tooltip leaves
|
|
127
162
|
// the trigger and its children in place, with their focus and hover.
|
|
@@ -138,78 +173,70 @@ export function Tooltip(props: TooltipProps) {
|
|
|
138
173
|
}
|
|
139
174
|
|
|
140
175
|
return (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
ref=
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
176
|
+
<>
|
|
177
|
+
{/* These listeners are attached before Kobalte's, so the machine sees each hover and focus first. */}
|
|
178
|
+
<div
|
|
179
|
+
ref={(el) => {
|
|
180
|
+
ref = el
|
|
181
|
+
// Kobalte's trigger sets this on the element it renders; it sets it again here once it mounts.
|
|
182
|
+
el.setAttribute("type", "button")
|
|
183
|
+
}}
|
|
184
|
+
data-closed=""
|
|
185
|
+
tabIndex={local.triggerTabIndex}
|
|
186
|
+
data-component="tooltip-v2-trigger"
|
|
187
|
+
class={local.class}
|
|
188
|
+
onPointerEnter={(event) => {
|
|
189
|
+
if (event.pointerType !== "touch") dispatch(POINTER_ENTERED, event)
|
|
190
|
+
}}
|
|
191
|
+
onFocus={(event) => dispatch(FOCUSED, event)}
|
|
192
|
+
>
|
|
193
|
+
{local.children}
|
|
194
|
+
</div>
|
|
195
|
+
<Show when={selectTooltipMounted(tooltip())}>
|
|
196
|
+
<Root
|
|
197
|
+
gutter={4}
|
|
198
|
+
openDelay={400}
|
|
199
|
+
skipDelayDuration={300}
|
|
200
|
+
{...others}
|
|
201
|
+
closeDelay={0}
|
|
202
|
+
ignoreSafeArea={local.ignoreSafeArea ?? true}
|
|
203
|
+
open={selectTooltipOpen(tooltip())}
|
|
204
|
+
onOpenChange={(open) => dispatch(open ? KOBALTE_OPENED : KOBALTE_CLOSED)}
|
|
157
205
|
>
|
|
158
|
-
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
{...others}
|
|
166
|
-
closeDelay={0}
|
|
167
|
-
ignoreSafeArea={local.ignoreSafeArea ?? true}
|
|
168
|
-
open={controlled() ? local.forceOpen : state.open}
|
|
169
|
-
onOpenChange={(open) => {
|
|
170
|
-
if (controlled()) return
|
|
171
|
-
|
|
172
|
-
if (state.block && open) return
|
|
173
|
-
|
|
174
|
-
if (justClickedTrigger) {
|
|
175
|
-
justClickedTrigger = false
|
|
176
|
-
|
|
177
|
-
return
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
setState("open", open)
|
|
206
|
+
{/* Kobalte calls these inside its own listeners. As separate listeners, the leave microtask would close the
|
|
207
|
+
tooltip before Kobalte's listener ran, which then skipped the skip-delay window. */}
|
|
208
|
+
<Trigger
|
|
209
|
+
as={adopt}
|
|
210
|
+
onPointerDown={() => dispatch(TRIGGER_PRESSED)}
|
|
211
|
+
onPointerLeave={(event: PointerEvent) => {
|
|
212
|
+
if (event.pointerType !== "touch") dispatch(POINTER_LEFT)
|
|
181
213
|
}}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
e.preventDefault()
|
|
205
|
-
}}
|
|
206
|
-
>
|
|
207
|
-
{local.value}
|
|
208
|
-
</Content>
|
|
209
|
-
</Portal>
|
|
210
|
-
</Root>
|
|
211
|
-
</Show>
|
|
212
|
-
</Match>
|
|
213
|
-
</Switch>
|
|
214
|
+
/>
|
|
215
|
+
<Portal>
|
|
216
|
+
<Content
|
|
217
|
+
ref={(el) => {
|
|
218
|
+
const theme = ref?.closest("[data-theme]")?.getAttribute("data-theme")
|
|
219
|
+
|
|
220
|
+
if (theme) el.setAttribute("data-theme", theme)
|
|
221
|
+
}}
|
|
222
|
+
data-component="tooltip-v2"
|
|
223
|
+
data-appearance={local.appearance ?? "compact"}
|
|
224
|
+
data-placement={props.placement}
|
|
225
|
+
data-force-open={selectTooltipForceOpen(tooltip())}
|
|
226
|
+
class={local.contentClass}
|
|
227
|
+
style={local.contentStyle}
|
|
228
|
+
onPointerDownOutside={preventDismiss}
|
|
229
|
+
>
|
|
230
|
+
{local.value}
|
|
231
|
+
</Content>
|
|
232
|
+
</Portal>
|
|
233
|
+
</Root>
|
|
234
|
+
</Show>
|
|
235
|
+
</>
|
|
214
236
|
)
|
|
215
237
|
}
|
|
238
|
+
|
|
239
|
+
// A press on the trigger is outside the tooltip's layer; the machine decides whether it closes the tooltip.
|
|
240
|
+
function preventDismiss(event: Event) {
|
|
241
|
+
event.preventDefault()
|
|
242
|
+
}
|