@opencode/ui 0.0.0-dev-1289 → 0.0.0-dev-1290
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.
|
@@ -18,6 +18,8 @@ export declare function RedirectPasteForm(props: {
|
|
|
18
18
|
submitting: boolean;
|
|
19
19
|
/** Focuses the field on mount, for a dialog where pasting is the main action. */
|
|
20
20
|
autofocus?: boolean;
|
|
21
|
+
/** Leaves submitting to Enter and the caller's own button. */
|
|
22
|
+
hideSubmit?: boolean;
|
|
21
23
|
onInput: (value: string) => void;
|
|
22
24
|
onSubmit: () => void;
|
|
23
25
|
}): import("solid-js").JSX.Element;
|
|
@@ -11,12 +11,14 @@ export type TooltipState =
|
|
|
11
11
|
readonly status: "idle";
|
|
12
12
|
readonly hovered: boolean;
|
|
13
13
|
readonly disabled: boolean;
|
|
14
|
-
}
|
|
15
|
-
/** `pressing` lasts from a press on the trigger until that press ends, so its click keeps the tooltip open. */
|
|
16
|
-
| {
|
|
14
|
+
} | {
|
|
17
15
|
readonly status: "open";
|
|
18
16
|
readonly hovered: boolean;
|
|
19
|
-
|
|
17
|
+
}
|
|
18
|
+
/** A press keeps the tooltip hidden until the next hover or keyboard focus. */
|
|
19
|
+
| {
|
|
20
|
+
readonly status: "dismissed";
|
|
21
|
+
readonly disabled: boolean;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* A popup the trigger opened (a menu, a popover) hides the tooltip. While it is open, a modal layer turns pointer
|
|
@@ -60,16 +62,12 @@ export type TooltipEvent = {
|
|
|
60
62
|
readonly type: "pointer.moved";
|
|
61
63
|
readonly inside: boolean;
|
|
62
64
|
}
|
|
63
|
-
/** The trigger
|
|
65
|
+
/** The trigger received focus independently of a pointer press. */
|
|
64
66
|
| {
|
|
65
67
|
readonly type: "focused";
|
|
66
68
|
} | {
|
|
67
69
|
readonly type: "trigger.pressed";
|
|
68
70
|
}
|
|
69
|
-
/** The press ended, after the click it caused, if any. */
|
|
70
|
-
| {
|
|
71
|
-
readonly type: "press.ended";
|
|
72
|
-
}
|
|
73
71
|
/** The microtask after the pointer left, once Kobalte has seen the tooltip open and started its skip-delay window. */
|
|
74
72
|
| {
|
|
75
73
|
readonly type: "leave.settled";
|
|
@@ -82,8 +80,7 @@ export type TooltipEvent = {
|
|
|
82
80
|
} | {
|
|
83
81
|
readonly type: "disposed";
|
|
84
82
|
};
|
|
85
|
-
|
|
86
|
-
export type TooltipEffect = "replay" | "schedule-leave";
|
|
83
|
+
export type TooltipEffect = "replay" | "schedule-leave" | "cancel-opening" | "hide";
|
|
87
84
|
export type TooltipTransition = {
|
|
88
85
|
readonly state: TooltipState;
|
|
89
86
|
readonly effects: readonly TooltipEffect[];
|
|
@@ -94,7 +91,6 @@ export declare const POINTER_INSIDE: TooltipEvent;
|
|
|
94
91
|
export declare const POINTER_OUTSIDE: TooltipEvent;
|
|
95
92
|
export declare const FOCUSED: TooltipEvent;
|
|
96
93
|
export declare const TRIGGER_PRESSED: TooltipEvent;
|
|
97
|
-
export declare const PRESS_ENDED: TooltipEvent;
|
|
98
94
|
export declare const LEAVE_SETTLED: TooltipEvent;
|
|
99
95
|
export declare const POPUP_EXPANDED: TooltipEvent;
|
|
100
96
|
export declare const POPUP_COLLAPSED: TooltipEvent;
|
|
@@ -112,7 +108,9 @@ export declare function selectTooltipMounted(state: TooltipState): state is {
|
|
|
112
108
|
} | {
|
|
113
109
|
readonly status: "open";
|
|
114
110
|
readonly hovered: boolean;
|
|
115
|
-
|
|
111
|
+
} | {
|
|
112
|
+
readonly status: "dismissed";
|
|
113
|
+
readonly disabled: boolean;
|
|
116
114
|
} | {
|
|
117
115
|
readonly status: "suppressed";
|
|
118
116
|
readonly popup: "open";
|
|
@@ -131,8 +129,10 @@ export declare function selectTooltipMounted(state: TooltipState): state is {
|
|
|
131
129
|
};
|
|
132
130
|
export declare function selectTooltipOpen(state: TooltipState): boolean;
|
|
133
131
|
export declare function selectTooltipForceOpen(state: TooltipState): boolean | undefined;
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
export declare function selectTooltipDismissed(state: TooltipState): state is {
|
|
133
|
+
readonly status: "dismissed";
|
|
134
|
+
readonly disabled: boolean;
|
|
135
|
+
};
|
|
136
136
|
/** A popup suppresses the tooltip, so the driver reports where the pointer moves. */
|
|
137
137
|
export declare function selectTooltipTracking(state: TooltipState): state is {
|
|
138
138
|
readonly status: "suppressed";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencode/ui",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-1290",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -309,7 +309,7 @@
|
|
|
309
309
|
"dependencies": {
|
|
310
310
|
"@kitlangton/solid-motion": "0.2.2",
|
|
311
311
|
"@kobalte/core": "0.13.13",
|
|
312
|
-
"@opencode/util": "0.0.0-dev-
|
|
312
|
+
"@opencode/util": "0.0.0-dev-1290",
|
|
313
313
|
"@pierre/diffs": "1.6.1",
|
|
314
314
|
"@pierre/highlights": "0.2.0",
|
|
315
315
|
"@solid-primitives/event-listener": "2.4.6",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createUniqueId, onMount, Show } from "solid-js"
|
|
2
|
-
import {
|
|
2
|
+
import { Icon } from "@opencode/ui/icon"
|
|
3
|
+
import { IconButton } from "@opencode/ui/icon-button"
|
|
3
4
|
import { TextInput } from "@opencode/ui/text-input"
|
|
4
5
|
import { useI18n } from "../../context/i18n"
|
|
5
6
|
|
|
@@ -19,6 +20,8 @@ export function RedirectPasteForm(props: {
|
|
|
19
20
|
submitting: boolean
|
|
20
21
|
/** Focuses the field on mount, for a dialog where pasting is the main action. */
|
|
21
22
|
autofocus?: boolean
|
|
23
|
+
/** Leaves submitting to Enter and the caller's own button. */
|
|
24
|
+
hideSubmit?: boolean
|
|
22
25
|
onInput: (value: string) => void
|
|
23
26
|
onSubmit: () => void
|
|
24
27
|
}) {
|
|
@@ -42,13 +45,14 @@ export function RedirectPasteForm(props: {
|
|
|
42
45
|
event.preventDefault()
|
|
43
46
|
props.onSubmit()
|
|
44
47
|
}}
|
|
45
|
-
class="flex flex-col items-start gap-
|
|
48
|
+
class="flex flex-col items-start gap-2 self-stretch"
|
|
46
49
|
>
|
|
47
50
|
<label class="flex w-full flex-col gap-2 font-[530] leading-4 text-v2-text-text-base">
|
|
48
51
|
{i18n.t("ui.redirectPaste.label")}
|
|
49
52
|
<TextInput
|
|
50
53
|
ref={input}
|
|
51
54
|
class="!w-full"
|
|
55
|
+
appearance="large"
|
|
52
56
|
name="redirect"
|
|
53
57
|
placeholder={i18n.t("ui.redirectPaste.placeholder")}
|
|
54
58
|
value={props.value}
|
|
@@ -58,18 +62,28 @@ export function RedirectPasteForm(props: {
|
|
|
58
62
|
autocomplete="off"
|
|
59
63
|
spellcheck={false}
|
|
60
64
|
onInput={(event) => props.onInput(event.currentTarget.value)}
|
|
65
|
+
trailing={
|
|
66
|
+
!props.hideSubmit && (
|
|
67
|
+
<IconButton
|
|
68
|
+
type="submit"
|
|
69
|
+
size="small"
|
|
70
|
+
variant="ghost"
|
|
71
|
+
icon={<Icon name="arrow-right" />}
|
|
72
|
+
disabled={props.locked}
|
|
73
|
+
aria-busy={props.submitting}
|
|
74
|
+
aria-label={i18n.t("ui.common.continue")}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
61
78
|
/>
|
|
62
79
|
</label>
|
|
63
80
|
<Show when={error()}>
|
|
64
81
|
{(message) => (
|
|
65
|
-
<div id={errorID} role="alert" class="
|
|
82
|
+
<div id={errorID} role="alert" class="text-xs text-v2-state-fg-danger">
|
|
66
83
|
{message()}
|
|
67
84
|
</div>
|
|
68
85
|
)}
|
|
69
86
|
</Show>
|
|
70
|
-
<Button type="submit" variant="contrast" disabled={props.locked} aria-busy={props.submitting}>
|
|
71
|
-
{i18n.t("ui.common.continue")}
|
|
72
|
-
</Button>
|
|
73
87
|
</form>
|
|
74
88
|
)
|
|
75
89
|
}
|
|
@@ -6,8 +6,9 @@ export type TooltipState =
|
|
|
6
6
|
/** Kobalte is not mounted yet. Most triggers are never hovered, so it mounts on the first hover or focus. */
|
|
7
7
|
| { readonly status: "unmounted"; readonly disabled: boolean }
|
|
8
8
|
| { readonly status: "idle"; readonly hovered: boolean; readonly disabled: boolean }
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
| { readonly status: "open"; readonly hovered: boolean }
|
|
10
|
+
/** A press keeps the tooltip hidden until the next hover or keyboard focus. */
|
|
11
|
+
| { readonly status: "dismissed"; readonly disabled: boolean }
|
|
11
12
|
/**
|
|
12
13
|
* A popup the trigger opened (a menu, a popover) hides the tooltip. While it is open, a modal layer turns pointer
|
|
13
14
|
* events off for the page, so the trigger's own enter and leave events lie and `hovered` follows the pointer's
|
|
@@ -33,19 +34,16 @@ export type TooltipEvent =
|
|
|
33
34
|
| { readonly type: "pointer.left" }
|
|
34
35
|
/** Where a pointer move landed while a popup suppresses the tooltip, measured against the trigger's box. */
|
|
35
36
|
| { readonly type: "pointer.moved"; readonly inside: boolean }
|
|
36
|
-
/** The trigger
|
|
37
|
+
/** The trigger received focus independently of a pointer press. */
|
|
37
38
|
| { readonly type: "focused" }
|
|
38
39
|
| { readonly type: "trigger.pressed" }
|
|
39
|
-
/** The press ended, after the click it caused, if any. */
|
|
40
|
-
| { readonly type: "press.ended" }
|
|
41
40
|
/** The microtask after the pointer left, once Kobalte has seen the tooltip open and started its skip-delay window. */
|
|
42
41
|
| { readonly type: "leave.settled" }
|
|
43
42
|
| { readonly type: "popup.changed"; readonly expanded: boolean }
|
|
44
43
|
| { readonly type: "kobalte.changed"; readonly open: boolean }
|
|
45
44
|
| { readonly type: "disposed" }
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
export type TooltipEffect = "replay" | "schedule-leave"
|
|
46
|
+
export type TooltipEffect = "replay" | "schedule-leave" | "cancel-opening" | "hide"
|
|
49
47
|
|
|
50
48
|
export type TooltipTransition = {
|
|
51
49
|
readonly state: TooltipState
|
|
@@ -69,7 +67,9 @@ const UNMOUNTED = [false, true].map((disabled) => freeze({ status: "unmounted",
|
|
|
69
67
|
|
|
70
68
|
const IDLE = [0, 1, 2, 3].map((key) => freeze({ status: "idle", hovered: !!(key & 1), disabled: !!(key & 2) }))
|
|
71
69
|
|
|
72
|
-
const OPEN = [
|
|
70
|
+
const OPEN = [false, true].map((hovered) => freeze({ status: "open", hovered }))
|
|
71
|
+
|
|
72
|
+
const DISMISSED = [false, true].map((disabled) => freeze({ status: "dismissed", disabled }))
|
|
73
73
|
|
|
74
74
|
const POPUP_OPEN = [0, 1, 2, 3].map((key) =>
|
|
75
75
|
freeze({ status: "suppressed", popup: "open", hovered: !!(key & 1), disabled: !!(key & 2) }),
|
|
@@ -93,7 +93,7 @@ const unmounted = (disabled: boolean) => UNMOUNTED[bit(disabled)]
|
|
|
93
93
|
|
|
94
94
|
const idle = (hovered: boolean, disabled: boolean) => IDLE[bit(hovered) | (bit(disabled) << 1)]
|
|
95
95
|
|
|
96
|
-
const open = (hovered: boolean
|
|
96
|
+
const open = (hovered: boolean) => OPEN[bit(hovered)]
|
|
97
97
|
|
|
98
98
|
const popupOpen = (hovered: boolean, disabled: boolean) => POPUP_OPEN[bit(hovered) | (bit(disabled) << 1)]
|
|
99
99
|
|
|
@@ -102,16 +102,17 @@ const popupClosed = (disabled: boolean) => POPUP_CLOSED[bit(disabled)]
|
|
|
102
102
|
const controlled = (open: boolean, hovered: boolean, expanded: boolean, disabled: boolean) =>
|
|
103
103
|
CONTROLLED[bit(open) | (bit(hovered) << 1) | (bit(expanded) << 2) | (bit(disabled) << 3)]
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
function withEffect(state: TooltipState, effect: TooltipEffect): TooltipTransition {
|
|
106
|
+
return Object.freeze({ state, effects: Object.freeze([effect]) })
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const REPLAY_HOVER = withEffect(idle(true, false), "replay")
|
|
106
110
|
|
|
107
|
-
const
|
|
111
|
+
const LEAVING = withEffect(open(false), "schedule-leave")
|
|
108
112
|
|
|
109
|
-
const
|
|
113
|
+
const CANCEL_OPENING = withEffect(DISMISSED[0], "cancel-opening")
|
|
110
114
|
|
|
111
|
-
const
|
|
112
|
-
state: open(false, false),
|
|
113
|
-
effects: Object.freeze<TooltipEffect[]>(["schedule-leave"]),
|
|
114
|
-
})
|
|
115
|
+
const HIDE = withEffect(DISMISSED[0], "hide")
|
|
115
116
|
|
|
116
117
|
export const POINTER_ENTERED: TooltipEvent = Object.freeze({ type: "pointer.entered" })
|
|
117
118
|
|
|
@@ -125,8 +126,6 @@ export const FOCUSED: TooltipEvent = Object.freeze({ type: "focused" })
|
|
|
125
126
|
|
|
126
127
|
export const TRIGGER_PRESSED: TooltipEvent = Object.freeze({ type: "trigger.pressed" })
|
|
127
128
|
|
|
128
|
-
export const PRESS_ENDED: TooltipEvent = Object.freeze({ type: "press.ended" })
|
|
129
|
-
|
|
130
129
|
export const LEAVE_SETTLED: TooltipEvent = Object.freeze({ type: "leave.settled" })
|
|
131
130
|
|
|
132
131
|
export const POPUP_EXPANDED: TooltipEvent = Object.freeze({ type: "popup.changed", expanded: true })
|
|
@@ -178,9 +177,8 @@ export function selectTooltipForceOpen(state: TooltipState) {
|
|
|
178
177
|
return state.status === "controlled" ? state.open : undefined
|
|
179
178
|
}
|
|
180
179
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return state.status === "open" && state.pressing
|
|
180
|
+
export function selectTooltipDismissed(state: TooltipState) {
|
|
181
|
+
return state.status === "dismissed"
|
|
184
182
|
}
|
|
185
183
|
|
|
186
184
|
/** A popup suppresses the tooltip, so the driver reports where the pointer moves. */
|
|
@@ -200,7 +198,7 @@ function next(state: TooltipState, event: TooltipEvent): TooltipState | TooltipT
|
|
|
200
198
|
|
|
201
199
|
if (event.type === "pointer.entered") return REPLAY_HOVER
|
|
202
200
|
|
|
203
|
-
if (event.type === "focused") return
|
|
201
|
+
if (event.type === "focused") return idle(false, false)
|
|
204
202
|
|
|
205
203
|
return state
|
|
206
204
|
}
|
|
@@ -212,28 +210,35 @@ function next(state: TooltipState, event: TooltipEvent): TooltipState | TooltipT
|
|
|
212
210
|
|
|
213
211
|
if (event.type === "popup.changed" && event.expanded) return popupOpen(state.hovered, state.disabled)
|
|
214
212
|
|
|
215
|
-
if (event.type === "
|
|
213
|
+
if (event.type === "trigger.pressed" && state.hovered && !state.disabled) return CANCEL_OPENING
|
|
214
|
+
|
|
215
|
+
if (event.type === "kobalte.changed" && event.open && !state.disabled) return open(state.hovered)
|
|
216
216
|
|
|
217
217
|
return state
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
if (state.status === "open") {
|
|
221
|
-
if (event.type === "pointer.entered") return open(true
|
|
221
|
+
if (event.type === "pointer.entered") return open(true)
|
|
222
222
|
|
|
223
|
-
if (event.type === "pointer.left") return state.hovered
|
|
223
|
+
if (event.type === "pointer.left") return state.hovered ? LEAVING : state
|
|
224
224
|
|
|
225
225
|
if (event.type === "leave.settled") return state.hovered ? state : idle(false, false)
|
|
226
226
|
|
|
227
|
-
if (event.type === "trigger.pressed") return
|
|
228
|
-
|
|
229
|
-
if (event.type === "press.ended") return open(state.hovered, false)
|
|
227
|
+
if (event.type === "trigger.pressed") return HIDE
|
|
230
228
|
|
|
231
229
|
if (event.type === "popup.changed" && event.expanded) return popupOpen(state.hovered, false)
|
|
232
230
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
231
|
+
if (event.type === "kobalte.changed" && !event.open) return idle(state.hovered, false)
|
|
232
|
+
|
|
233
|
+
return state
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (state.status === "dismissed") {
|
|
237
|
+
if (event.type === "pointer.left") return idle(false, state.disabled)
|
|
238
|
+
|
|
239
|
+
if (event.type === "focused") return idle(true, state.disabled)
|
|
240
|
+
|
|
241
|
+
if (event.type === "popup.changed" && event.expanded) return popupOpen(true, state.disabled)
|
|
237
242
|
|
|
238
243
|
return state
|
|
239
244
|
}
|
|
@@ -281,7 +286,9 @@ function sync(state: TooltipState, forceOpen: boolean | undefined, disabled: boo
|
|
|
281
286
|
return controlled(forceOpen, state.hovered, true, disabled)
|
|
282
287
|
}
|
|
283
288
|
|
|
284
|
-
if (state.status === "suppressed"
|
|
289
|
+
if (state.status === "suppressed" || state.status === "dismissed") {
|
|
290
|
+
return controlled(forceOpen, true, false, disabled)
|
|
291
|
+
}
|
|
285
292
|
|
|
286
293
|
return controlled(forceOpen, state.hovered, false, disabled)
|
|
287
294
|
}
|
|
@@ -292,6 +299,8 @@ function sync(state: TooltipState, forceOpen: boolean | undefined, disabled: boo
|
|
|
292
299
|
|
|
293
300
|
if (state.status === "open") return disabled ? idle(state.hovered, true) : state
|
|
294
301
|
|
|
302
|
+
if (state.status === "dismissed") return DISMISSED[bit(disabled)]
|
|
303
|
+
|
|
295
304
|
if (state.status === "suppressed" && state.popup === "open") return popupOpen(state.hovered, disabled)
|
|
296
305
|
|
|
297
306
|
if (state.status === "suppressed") return popupClosed(disabled)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Content, Portal, Root, Trigger } from "@kobalte/core/tooltip"
|
|
1
|
+
import { Content, Portal, Root, Trigger, useTooltipContext, type TooltipContextValue } from "@kobalte/core/tooltip"
|
|
2
|
+
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
2
3
|
import { createComputed, createSignal, onCleanup, onMount, Show, splitProps, untrack, type JSX } from "solid-js"
|
|
3
4
|
import type { ComponentProps } from "solid-js"
|
|
4
5
|
import { spread } from "solid-js/web"
|
|
@@ -15,11 +16,10 @@ import {
|
|
|
15
16
|
POINTER_OUTSIDE,
|
|
16
17
|
POPUP_COLLAPSED,
|
|
17
18
|
POPUP_EXPANDED,
|
|
18
|
-
|
|
19
|
+
selectTooltipDismissed,
|
|
19
20
|
selectTooltipForceOpen,
|
|
20
21
|
selectTooltipMounted,
|
|
21
22
|
selectTooltipOpen,
|
|
22
|
-
selectTooltipPressing,
|
|
23
23
|
selectTooltipTracking,
|
|
24
24
|
syncPropsEvent,
|
|
25
25
|
transitionTooltip,
|
|
@@ -41,13 +41,46 @@ export interface TooltipProps extends ComponentProps<typeof Root> {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
type TriggerHandlers = {
|
|
44
|
-
onPointerEnter
|
|
45
|
-
onFocus
|
|
44
|
+
onPointerEnter: (event: PointerEvent) => void
|
|
45
|
+
onFocus: (event: FocusEvent) => void
|
|
46
|
+
onBlur: (event: FocusEvent) => void
|
|
47
|
+
onClick: (event: MouseEvent) => void
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
// Expanded panels still need tooltips; only an open popup suppresses its trigger's tooltip.
|
|
49
51
|
const POPUP = '[aria-haspopup]:not([aria-haspopup="false"]):is([aria-expanded="true"], [data-expanded])'
|
|
50
52
|
|
|
53
|
+
// A closing popup can restore focus to its button. Only Tab should open the button's tooltip.
|
|
54
|
+
let triggers = 0
|
|
55
|
+
|
|
56
|
+
let tabbing = false
|
|
57
|
+
|
|
58
|
+
function startTab(event: KeyboardEvent) {
|
|
59
|
+
tabbing = event.key === "Tab"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function endTab() {
|
|
63
|
+
tabbing = false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function listenForTab() {
|
|
67
|
+
if (++triggers === 1) {
|
|
68
|
+
window.addEventListener("keydown", startTab, true)
|
|
69
|
+
window.addEventListener("keyup", endTab, true)
|
|
70
|
+
window.addEventListener("pointerdown", endTab, true)
|
|
71
|
+
window.addEventListener("blur", endTab)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
onCleanup(() => {
|
|
75
|
+
if (--triggers) return
|
|
76
|
+
window.removeEventListener("keydown", startTab, true)
|
|
77
|
+
window.removeEventListener("keyup", endTab, true)
|
|
78
|
+
window.removeEventListener("pointerdown", endTab, true)
|
|
79
|
+
window.removeEventListener("blur", endTab)
|
|
80
|
+
endTab()
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
51
84
|
export function Tooltip(props: TooltipProps) {
|
|
52
85
|
return (
|
|
53
86
|
<Show when={!props.inactive} fallback={props.children}>
|
|
@@ -58,9 +91,13 @@ export function Tooltip(props: TooltipProps) {
|
|
|
58
91
|
|
|
59
92
|
function ActiveTooltip(props: TooltipProps) {
|
|
60
93
|
let ref: HTMLDivElement | undefined
|
|
94
|
+
|
|
61
95
|
let handlers: TriggerHandlers | undefined
|
|
96
|
+
|
|
62
97
|
let observer: MutationObserver | undefined
|
|
63
98
|
|
|
99
|
+
let kobalte: TooltipContextValue | undefined
|
|
100
|
+
|
|
64
101
|
const [local, others] = splitProps(props, [
|
|
65
102
|
"children",
|
|
66
103
|
"appearance",
|
|
@@ -79,7 +116,7 @@ function ActiveTooltip(props: TooltipProps) {
|
|
|
79
116
|
// open it, or as soon as a caller controls it with forceOpen.
|
|
80
117
|
const [tooltip, setTooltip] = createSignal(createTooltipState(local.forceOpen, !!others.disabled))
|
|
81
118
|
|
|
82
|
-
const dispatch = (event: TooltipEvent, source?: PointerEvent
|
|
119
|
+
const dispatch = (event: TooltipEvent, source?: PointerEvent) => {
|
|
83
120
|
const previous = untrack(tooltip)
|
|
84
121
|
const transition = transitionTooltip(previous, event)
|
|
85
122
|
|
|
@@ -91,10 +128,13 @@ function ActiveTooltip(props: TooltipProps) {
|
|
|
91
128
|
for (const effect of transition.effects) {
|
|
92
129
|
if (effect === "schedule-leave") queueMicrotask(settleLeave)
|
|
93
130
|
|
|
94
|
-
//
|
|
95
|
-
if (effect === "
|
|
131
|
+
// hideTooltip starts the skip window; cancelling a pending hover shouldn't.
|
|
132
|
+
if (effect === "cancel-opening") kobalte?.cancelOpening()
|
|
133
|
+
|
|
134
|
+
if (effect === "hide") kobalte?.hideTooltip(true)
|
|
96
135
|
|
|
97
|
-
|
|
136
|
+
// Kobalte attached its listeners while this event was being dispatched, too late to receive it.
|
|
137
|
+
if (effect === "replay" && source) handlers?.onPointerEnter(source)
|
|
98
138
|
}
|
|
99
139
|
}
|
|
100
140
|
|
|
@@ -102,8 +142,6 @@ function ActiveTooltip(props: TooltipProps) {
|
|
|
102
142
|
// tooltips if it still sees this one open.
|
|
103
143
|
const settleLeave = () => dispatch(LEAVE_SETTLED)
|
|
104
144
|
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)
|
|
107
145
|
|
|
108
146
|
const onPointerMove = (event: PointerEvent) => {
|
|
109
147
|
if (!ref) return
|
|
@@ -117,18 +155,6 @@ function ActiveTooltip(props: TooltipProps) {
|
|
|
117
155
|
|
|
118
156
|
// Attaches the listeners and observer the state needs and detaches the rest.
|
|
119
157
|
const reconcile = (previous: TooltipState, state: TooltipState) => {
|
|
120
|
-
const pressing = selectTooltipPressing(state)
|
|
121
|
-
|
|
122
|
-
if (pressing && !selectTooltipPressing(previous)) {
|
|
123
|
-
window.addEventListener("pointerup", onPressEnd, true)
|
|
124
|
-
window.addEventListener("pointercancel", onPressEnd, true)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!pressing && selectTooltipPressing(previous)) {
|
|
128
|
-
window.removeEventListener("pointerup", onPressEnd, true)
|
|
129
|
-
window.removeEventListener("pointercancel", onPressEnd, true)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
158
|
const tracking = selectTooltipTracking(state)
|
|
133
159
|
|
|
134
160
|
if (tracking && !selectTooltipTracking(previous)) {
|
|
@@ -155,6 +181,7 @@ function ActiveTooltip(props: TooltipProps) {
|
|
|
155
181
|
}
|
|
156
182
|
|
|
157
183
|
createComputed(() => dispatch(syncPropsEvent(local.forceOpen, !!others.disabled)))
|
|
184
|
+
onMount(listenForTab)
|
|
158
185
|
onMount(() => reconcile(untrack(tooltip), untrack(tooltip)))
|
|
159
186
|
onCleanup(() => dispatch(DISPOSED_EVENT))
|
|
160
187
|
|
|
@@ -162,19 +189,30 @@ function ActiveTooltip(props: TooltipProps) {
|
|
|
162
189
|
// the trigger and its children in place, with their focus and hover.
|
|
163
190
|
const adopt = (triggerProps: TriggerHandlers) => {
|
|
164
191
|
handlers = triggerProps
|
|
192
|
+
kobalte = useTooltipContext()
|
|
165
193
|
|
|
166
194
|
if (!ref) return null
|
|
195
|
+
// Tab-close buttons stop pointerdown propagation.
|
|
196
|
+
makeEventListener(
|
|
197
|
+
ref,
|
|
198
|
+
"pointerdown",
|
|
199
|
+
(event) => {
|
|
200
|
+
if (event.pointerType !== "touch") dispatch(TRIGGER_PRESSED)
|
|
201
|
+
},
|
|
202
|
+
true,
|
|
203
|
+
)
|
|
204
|
+
|
|
167
205
|
// Kobalte owns the open state attributes from here, and spread never removes an attribute it did not set, so a
|
|
168
206
|
// tooltip that mounts open would keep the closed marker.
|
|
169
207
|
ref.removeAttribute("data-closed")
|
|
170
|
-
|
|
208
|
+
const [, rest] = splitProps(triggerProps, ["onFocus", "onBlur", "onClick"])
|
|
209
|
+
spread(ref, rest, false, true)
|
|
171
210
|
|
|
172
211
|
return null
|
|
173
212
|
}
|
|
174
213
|
|
|
175
214
|
return (
|
|
176
215
|
<>
|
|
177
|
-
{/* These listeners are attached before Kobalte's, so the machine sees each hover and focus first. */}
|
|
178
216
|
<div
|
|
179
217
|
ref={(el) => {
|
|
180
218
|
ref = el
|
|
@@ -188,14 +226,23 @@ function ActiveTooltip(props: TooltipProps) {
|
|
|
188
226
|
onPointerEnter={(event) => {
|
|
189
227
|
if (event.pointerType !== "touch") dispatch(POINTER_ENTERED, event)
|
|
190
228
|
}}
|
|
191
|
-
|
|
229
|
+
onFocusIn={(event) => {
|
|
230
|
+
if (!tabbing && (event.target !== ref || selectTooltipDismissed(untrack(tooltip)))) return
|
|
231
|
+
dispatch(FOCUSED)
|
|
232
|
+
handlers?.onFocus(event)
|
|
233
|
+
}}
|
|
234
|
+
onFocusOut={(event) => handlers?.onBlur(event)}
|
|
235
|
+
onClick={(event) => {
|
|
236
|
+
if (event instanceof PointerEvent && event.pointerType === "touch") return
|
|
237
|
+
handlers?.onClick(event)
|
|
238
|
+
}}
|
|
192
239
|
>
|
|
193
240
|
{local.children}
|
|
194
241
|
</div>
|
|
195
242
|
<Show when={selectTooltipMounted(tooltip())}>
|
|
196
243
|
<Root
|
|
197
244
|
gutter={4}
|
|
198
|
-
openDelay={
|
|
245
|
+
openDelay={600}
|
|
199
246
|
skipDelayDuration={300}
|
|
200
247
|
{...others}
|
|
201
248
|
closeDelay={0}
|
|
@@ -207,7 +254,6 @@ function ActiveTooltip(props: TooltipProps) {
|
|
|
207
254
|
tooltip before Kobalte's listener ran, which then skipped the skip-delay window. */}
|
|
208
255
|
<Trigger
|
|
209
256
|
as={adopt}
|
|
210
|
-
onPointerDown={() => dispatch(TRIGGER_PRESSED)}
|
|
211
257
|
onPointerLeave={(event: PointerEvent) => {
|
|
212
258
|
if (event.pointerType !== "touch") dispatch(POINTER_LEFT)
|
|
213
259
|
}}
|