@adea-ai/ui 0.160.3 → 0.161.0
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/layout/contextual-sidebar/contextual-sidebar.d.ts.map +1 -1
- package/dist/components/layout/contextual-sidebar/contextual-sidebar.js +21 -1
- package/dist/components/layout/contextual-sidebar/contextual-sidebar.js.map +1 -1
- package/dist/components/layout/split-layout/index.d.ts +1 -0
- package/dist/components/layout/split-layout/index.d.ts.map +1 -1
- package/dist/components/layout/split-layout/index.js +2 -1
- package/dist/components/layout/split-layout/pane-focus.d.ts +29 -0
- package/dist/components/layout/split-layout/pane-focus.d.ts.map +1 -0
- package/dist/components/layout/split-layout/pane-focus.js +77 -0
- package/dist/components/layout/split-layout/pane-focus.js.map +1 -0
- package/dist/components/layout/split-layout/split-layout.d.ts +6 -0
- package/dist/components/layout/split-layout/split-layout.d.ts.map +1 -1
- package/dist/components/layout/split-layout/split-layout.js +25 -9
- package/dist/components/layout/split-layout/split-layout.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/r/registry.json +5 -0
- package/dist/r/split-layout.json +5 -0
- package/dist/r/src/components/layout/contextual-sidebar/contextual-sidebar.tsx +23 -0
- package/dist/r/src/components/layout/split-layout/index.ts +1 -0
- package/dist/r/src/components/layout/split-layout/pane-focus.ts +111 -0
- package/dist/r/src/components/layout/split-layout/split-layout.tsx +27 -1
- package/package.json +7 -1
- package/registry.json +5 -0
- package/src/components/layout/contextual-sidebar/contextual-sidebar.tsx +23 -0
- package/src/components/layout/split-layout/index.ts +1 -0
- package/src/components/layout/split-layout/pane-focus.ts +111 -0
- package/src/components/layout/split-layout/split-layout.tsx +27 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// How a pane takes focus: on hover (the pointer moving onto it activates it, so the keys typed
|
|
2
|
+
// next go to it) or on click. The choice is a device preference kept in `localStorage`, shared by
|
|
3
|
+
// every pane surface: SplitLayout reads it by default, and a host's own pane (a floating window,
|
|
4
|
+
// for instance) calls `focusPaneOnHover` from its `pointermove` to behave the same way.
|
|
5
|
+
|
|
6
|
+
export type PaneFocusMode = 'hover' | 'click'
|
|
7
|
+
|
|
8
|
+
const STORAGE_KEY = 'adea:pane-focus-mode:v1'
|
|
9
|
+
|
|
10
|
+
// One shared copy, because the preference reaches the page from more than one bundle.
|
|
11
|
+
type PaneFocusState = { value: PaneFocusMode | undefined; listeners: Set<() => void> }
|
|
12
|
+
const STATE_KEY = Symbol.for('adea.ui.pane-focus-mode')
|
|
13
|
+
const state: PaneFocusState = ((globalThis as Record<symbol, unknown>)[STATE_KEY] ??= {
|
|
14
|
+
value: undefined,
|
|
15
|
+
listeners: new Set<() => void>(),
|
|
16
|
+
}) as PaneFocusState
|
|
17
|
+
|
|
18
|
+
function storage(): Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | undefined {
|
|
19
|
+
try {
|
|
20
|
+
return typeof localStorage === 'undefined' ? undefined : localStorage
|
|
21
|
+
} catch {
|
|
22
|
+
return undefined
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** How panes take focus: on hover unless the person chose click. */
|
|
27
|
+
export function paneFocusMode(): PaneFocusMode {
|
|
28
|
+
if (state.value === undefined) {
|
|
29
|
+
let saved: string | null = null
|
|
30
|
+
try {
|
|
31
|
+
saved = storage()?.getItem(STORAGE_KEY) ?? null
|
|
32
|
+
} catch {
|
|
33
|
+
// Unreadable storage means the default.
|
|
34
|
+
}
|
|
35
|
+
state.value = saved === 'click' ? 'click' : 'hover'
|
|
36
|
+
}
|
|
37
|
+
return state.value
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function setPaneFocusMode(value: PaneFocusMode): void {
|
|
41
|
+
state.value = value
|
|
42
|
+
try {
|
|
43
|
+
if (value === 'hover') storage()?.removeItem(STORAGE_KEY)
|
|
44
|
+
else storage()?.setItem(STORAGE_KEY, value)
|
|
45
|
+
} catch {
|
|
46
|
+
// The choice still applies for this session.
|
|
47
|
+
}
|
|
48
|
+
for (const listener of state.listeners) listener()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Calls `listener` after the choice changes; returns the way to stop. */
|
|
52
|
+
export function subscribePaneFocusMode(listener: () => void): () => void {
|
|
53
|
+
state.listeners.add(listener)
|
|
54
|
+
return () => state.listeners.delete(listener)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A pane's own element that takes the keys when hover activates it (a terminal's input, say). */
|
|
58
|
+
export const PANE_FOCUS_TARGET = '[data-pane-focus-target]'
|
|
59
|
+
|
|
60
|
+
// Focus inside an open overlay is never taken by a pane the pointer passes over.
|
|
61
|
+
const OVERLAY = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]'
|
|
62
|
+
const EDITABLE = 'input, textarea, select, [contenteditable=""], [contenteditable="true"]'
|
|
63
|
+
|
|
64
|
+
// The element each pane last had focus in, so hovering back returns the keys to it.
|
|
65
|
+
const lastFocused = new WeakMap<HTMLElement, HTMLElement>()
|
|
66
|
+
|
|
67
|
+
/** Remembers where focus is inside `pane`; call from the pane's `focusin`. */
|
|
68
|
+
export function rememberPaneFocus(pane: HTMLElement, target: EventTarget | null): void {
|
|
69
|
+
if (target instanceof HTMLElement && target !== pane && pane.contains(target))
|
|
70
|
+
lastFocused.set(pane, target)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type PointerLike = Pick<PointerEvent, 'pointerType' | 'buttons' | 'movementX' | 'movementY'>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Whether the pointer moving over `pane` should activate it. Only a real mouse move with no button
|
|
77
|
+
* held counts: a touch, a pen tap, a drag, a selection or content shifting under a still pointer
|
|
78
|
+
* does not. Focus already inside the pane, inside an open overlay, or in a text field that is in
|
|
79
|
+
* no pane (no `[data-pane-id]` ancestor) and outside `scope` stays where it is.
|
|
80
|
+
*/
|
|
81
|
+
export function hoverTakesFocus(event: PointerLike, pane: HTMLElement, scope?: Element): boolean {
|
|
82
|
+
if (event.pointerType !== 'mouse' || event.buttons !== 0) return false
|
|
83
|
+
if (event.movementX === 0 && event.movementY === 0) return false
|
|
84
|
+
const active = pane.ownerDocument.activeElement
|
|
85
|
+
if (!active || active === pane.ownerDocument.body) return true
|
|
86
|
+
if (pane.contains(active)) return false
|
|
87
|
+
if (active.closest(OVERLAY)) return false
|
|
88
|
+
const inPane = active.closest('[data-pane-id]') !== null || (scope?.contains(active) ?? false)
|
|
89
|
+
return inPane || !active.matches(EDITABLE)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Moves focus into `pane` as a hover activation: back to the element it last had focus in, else
|
|
94
|
+
* its `data-pane-focus-target`, else the pane itself. The pane's `focusin` then marks it active.
|
|
95
|
+
* Returns whether focus moved.
|
|
96
|
+
*/
|
|
97
|
+
export function focusPaneOnHover(
|
|
98
|
+
event: PointerLike,
|
|
99
|
+
pane: HTMLElement,
|
|
100
|
+
options: { scope?: Element; mode?: PaneFocusMode } = {}
|
|
101
|
+
): boolean {
|
|
102
|
+
if ((options.mode ?? paneFocusMode()) !== 'hover') return false
|
|
103
|
+
if (!hoverTakesFocus(event, pane, options.scope)) return false
|
|
104
|
+
const remembered = lastFocused.get(pane)
|
|
105
|
+
const target =
|
|
106
|
+
(remembered?.isConnected && pane.contains(remembered) ? remembered : undefined) ??
|
|
107
|
+
pane.querySelector<HTMLElement>(PANE_FOCUS_TARGET) ??
|
|
108
|
+
pane
|
|
109
|
+
target.focus({ preventScroll: true })
|
|
110
|
+
return pane.contains(pane.ownerDocument.activeElement)
|
|
111
|
+
}
|
|
@@ -19,6 +19,13 @@ import { resizeSeparatorClass } from '../../../lib/resize-separator'
|
|
|
19
19
|
import { cn } from '../../../lib/utils'
|
|
20
20
|
import { computeLayoutFrames, type LayoutRect } from './geometry'
|
|
21
21
|
import { paneDropIntent, type PaneDropIntent } from './drop'
|
|
22
|
+
import {
|
|
23
|
+
focusPaneOnHover,
|
|
24
|
+
paneFocusMode,
|
|
25
|
+
rememberPaneFocus,
|
|
26
|
+
subscribePaneFocusMode,
|
|
27
|
+
type PaneFocusMode,
|
|
28
|
+
} from './pane-focus'
|
|
22
29
|
import { fastIcon } from '../../../lib/fast-icon'
|
|
23
30
|
|
|
24
31
|
// lucide icons drawn from a cloned template (see fastIcon).
|
|
@@ -73,6 +80,11 @@ export type SplitLayoutProps<L extends SplitLayoutLeaf> = {
|
|
|
73
80
|
labelForSeparator?: (branch: SplitLayoutBranch<L>) => string
|
|
74
81
|
onResize: (splitId: string, ratio: number) => void
|
|
75
82
|
onFocus?: (leafId: string) => void
|
|
83
|
+
/**
|
|
84
|
+
* How a pane takes focus. `hover` activates the pane the mouse moves onto (keys typed next go to
|
|
85
|
+
* it); `click` waits for a click. Defaults to the device preference (`paneFocusMode`).
|
|
86
|
+
*/
|
|
87
|
+
focusMode?: PaneFocusMode
|
|
76
88
|
/** Host performs the model transition and returns the surviving focus destination. */
|
|
77
89
|
onClose?: (leafId: string) => string | undefined
|
|
78
90
|
/** Pointer placement only; the host supplies keyboard commands and performs the model transition. */
|
|
@@ -230,6 +242,9 @@ export function SplitLayout<L extends SplitLayoutLeaf>(props: SplitLayoutProps<L
|
|
|
230
242
|
const [drag, setDrag] = createSignal<{ id: string; token: string }>()
|
|
231
243
|
const [drop, setDrop] = createSignal<{ id: string; intent: PaneDropIntent }>()
|
|
232
244
|
const [resizeController, setResizeController] = createSignal<ResizeControllerState<L>>()
|
|
245
|
+
const [preferredFocusMode, setPreferredFocusMode] = createSignal(paneFocusMode())
|
|
246
|
+
onCleanup(subscribePaneFocusMode(() => setPreferredFocusMode(paneFocusMode())))
|
|
247
|
+
const focusMode = () => props.focusMode ?? preferredFocusMode()
|
|
233
248
|
const reloadRequired = () => resizeControllerEntry >= resizeControllerEntries.length
|
|
234
249
|
const cancelPendingFocusRestore = () => {
|
|
235
250
|
if (pendingFocusFrame !== undefined) cancelAnimationFrame(pendingFocusFrame)
|
|
@@ -528,7 +543,18 @@ export function SplitLayout<L extends SplitLayoutLeaf>(props: SplitLayoutProps<L
|
|
|
528
543
|
}}
|
|
529
544
|
style={rectStyle(frames().get(id)?.rect ?? { x: 0, y: 0, width: 0, height: 0 })}
|
|
530
545
|
class="absolute flex min-h-0 min-w-0 flex-col overflow-hidden border border-border transition-opacity motion-reduce:transition-none data-[drag-source]:opacity-40 data-[focused]:border-primary bg-background text-foreground focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring"
|
|
531
|
-
|
|
546
|
+
data-focus-mode={focusMode()}
|
|
547
|
+
onFocusIn={(event) => {
|
|
548
|
+
rememberPaneFocus(event.currentTarget, event.target)
|
|
549
|
+
props.onFocus?.(id)
|
|
550
|
+
}}
|
|
551
|
+
onPointerMove={(event) => {
|
|
552
|
+
if (drag()) return
|
|
553
|
+
focusPaneOnHover(event, event.currentTarget, {
|
|
554
|
+
mode: focusMode(),
|
|
555
|
+
...(root ? { scope: root } : {}),
|
|
556
|
+
})
|
|
557
|
+
}}
|
|
532
558
|
>
|
|
533
559
|
<header class="flex min-w-0 shrink-0 items-center gap-2 bg-surface px-2">
|
|
534
560
|
<span
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.161.0",
|
|
4
4
|
"description": "The Adea design system: ui-sdk-backed Solid components, semantic OKLCH tokens, and the app-shell layout primitives shared by Adea and Cortana.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adea",
|
|
@@ -128,6 +128,12 @@
|
|
|
128
128
|
"development": "./src/components/conversation/transcript-composition.tsx",
|
|
129
129
|
"import": "./dist/components/conversation/transcript-composition.js"
|
|
130
130
|
},
|
|
131
|
+
"./components/layout/split-layout/pane-focus": {
|
|
132
|
+
"types": "./dist/components/layout/split-layout/pane-focus.d.ts",
|
|
133
|
+
"solid": "./src/components/layout/split-layout/pane-focus.ts",
|
|
134
|
+
"development": "./src/components/layout/split-layout/pane-focus.ts",
|
|
135
|
+
"import": "./dist/components/layout/split-layout/pane-focus.js"
|
|
136
|
+
},
|
|
131
137
|
"./components/layout/split-layout/tree": {
|
|
132
138
|
"types": "./dist/components/layout/split-layout/tree.d.ts",
|
|
133
139
|
"solid": "./src/components/layout/split-layout/tree.ts",
|
package/registry.json
CHANGED
|
@@ -2227,6 +2227,11 @@
|
|
|
2227
2227
|
"type": "registry:ui",
|
|
2228
2228
|
"target": "components/layout/split-layout/model.ts"
|
|
2229
2229
|
},
|
|
2230
|
+
{
|
|
2231
|
+
"path": "src/components/layout/split-layout/pane-focus.ts",
|
|
2232
|
+
"type": "registry:ui",
|
|
2233
|
+
"target": "components/layout/split-layout/pane-focus.ts"
|
|
2234
|
+
},
|
|
2230
2235
|
{
|
|
2231
2236
|
"path": "src/components/layout/split-layout/resize-controller-core-retry.tsx",
|
|
2232
2237
|
"type": "registry:ui",
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
createUniqueId,
|
|
9
9
|
flush,
|
|
10
10
|
onCleanup,
|
|
11
|
+
onSettled,
|
|
11
12
|
} from 'solid-js'
|
|
12
13
|
import { MD_BREAKPOINT } from '#lib/breakpoints'
|
|
13
14
|
import { cn } from '#lib/utils'
|
|
@@ -350,6 +351,7 @@ export function ContextualSidebar(props: ContextualSidebarProps) {
|
|
|
350
351
|
{props.footer ? (
|
|
351
352
|
<SidebarNavFooter class={props.footerClass}>{props.footer(context)}</SidebarNavFooter>
|
|
352
353
|
) : null}
|
|
354
|
+
{mobile ? <FocusNavigationOnMount aside={() => element} /> : null}
|
|
353
355
|
</Show>
|
|
354
356
|
</SidebarNav>
|
|
355
357
|
)
|
|
@@ -376,3 +378,24 @@ export function ContextualSidebar(props: ContextualSidebarProps) {
|
|
|
376
378
|
</>
|
|
377
379
|
)
|
|
378
380
|
}
|
|
381
|
+
|
|
382
|
+
const FIRST_CONTROL =
|
|
383
|
+
'button:not(:disabled), [href], input:not(:disabled):not([type="hidden"]), ' +
|
|
384
|
+
'select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])'
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The mobile navigation renders once its aside is connected, a tick after the Sheet placed its
|
|
388
|
+
* initial focus on what it held then: its own Close, or the panel. Hand that focus to the
|
|
389
|
+
* navigation's first control, as a keyboard opener expects; focus already inside the
|
|
390
|
+
* navigation, or outside the Sheet, stays where it is.
|
|
391
|
+
*/
|
|
392
|
+
function FocusNavigationOnMount(props: { aside: () => HTMLElement | undefined }) {
|
|
393
|
+
onSettled(() => {
|
|
394
|
+
const aside = props.aside()
|
|
395
|
+
const sheet = aside?.closest<HTMLElement>('[role="dialog"]')
|
|
396
|
+
const active = document.activeElement
|
|
397
|
+
if (!aside || !sheet || !active || !sheet.contains(active) || aside.contains(active)) return
|
|
398
|
+
aside.querySelector<HTMLElement>(FIRST_CONTROL)?.focus()
|
|
399
|
+
})
|
|
400
|
+
return null
|
|
401
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// How a pane takes focus: on hover (the pointer moving onto it activates it, so the keys typed
|
|
2
|
+
// next go to it) or on click. The choice is a device preference kept in `localStorage`, shared by
|
|
3
|
+
// every pane surface: SplitLayout reads it by default, and a host's own pane (a floating window,
|
|
4
|
+
// for instance) calls `focusPaneOnHover` from its `pointermove` to behave the same way.
|
|
5
|
+
|
|
6
|
+
export type PaneFocusMode = 'hover' | 'click'
|
|
7
|
+
|
|
8
|
+
const STORAGE_KEY = 'adea:pane-focus-mode:v1'
|
|
9
|
+
|
|
10
|
+
// One shared copy, because the preference reaches the page from more than one bundle.
|
|
11
|
+
type PaneFocusState = { value: PaneFocusMode | undefined; listeners: Set<() => void> }
|
|
12
|
+
const STATE_KEY = Symbol.for('adea.ui.pane-focus-mode')
|
|
13
|
+
const state: PaneFocusState = ((globalThis as Record<symbol, unknown>)[STATE_KEY] ??= {
|
|
14
|
+
value: undefined,
|
|
15
|
+
listeners: new Set<() => void>(),
|
|
16
|
+
}) as PaneFocusState
|
|
17
|
+
|
|
18
|
+
function storage(): Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | undefined {
|
|
19
|
+
try {
|
|
20
|
+
return typeof localStorage === 'undefined' ? undefined : localStorage
|
|
21
|
+
} catch {
|
|
22
|
+
return undefined
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** How panes take focus: on hover unless the person chose click. */
|
|
27
|
+
export function paneFocusMode(): PaneFocusMode {
|
|
28
|
+
if (state.value === undefined) {
|
|
29
|
+
let saved: string | null = null
|
|
30
|
+
try {
|
|
31
|
+
saved = storage()?.getItem(STORAGE_KEY) ?? null
|
|
32
|
+
} catch {
|
|
33
|
+
// Unreadable storage means the default.
|
|
34
|
+
}
|
|
35
|
+
state.value = saved === 'click' ? 'click' : 'hover'
|
|
36
|
+
}
|
|
37
|
+
return state.value
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function setPaneFocusMode(value: PaneFocusMode): void {
|
|
41
|
+
state.value = value
|
|
42
|
+
try {
|
|
43
|
+
if (value === 'hover') storage()?.removeItem(STORAGE_KEY)
|
|
44
|
+
else storage()?.setItem(STORAGE_KEY, value)
|
|
45
|
+
} catch {
|
|
46
|
+
// The choice still applies for this session.
|
|
47
|
+
}
|
|
48
|
+
for (const listener of state.listeners) listener()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Calls `listener` after the choice changes; returns the way to stop. */
|
|
52
|
+
export function subscribePaneFocusMode(listener: () => void): () => void {
|
|
53
|
+
state.listeners.add(listener)
|
|
54
|
+
return () => state.listeners.delete(listener)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A pane's own element that takes the keys when hover activates it (a terminal's input, say). */
|
|
58
|
+
export const PANE_FOCUS_TARGET = '[data-pane-focus-target]'
|
|
59
|
+
|
|
60
|
+
// Focus inside an open overlay is never taken by a pane the pointer passes over.
|
|
61
|
+
const OVERLAY = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]'
|
|
62
|
+
const EDITABLE = 'input, textarea, select, [contenteditable=""], [contenteditable="true"]'
|
|
63
|
+
|
|
64
|
+
// The element each pane last had focus in, so hovering back returns the keys to it.
|
|
65
|
+
const lastFocused = new WeakMap<HTMLElement, HTMLElement>()
|
|
66
|
+
|
|
67
|
+
/** Remembers where focus is inside `pane`; call from the pane's `focusin`. */
|
|
68
|
+
export function rememberPaneFocus(pane: HTMLElement, target: EventTarget | null): void {
|
|
69
|
+
if (target instanceof HTMLElement && target !== pane && pane.contains(target))
|
|
70
|
+
lastFocused.set(pane, target)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type PointerLike = Pick<PointerEvent, 'pointerType' | 'buttons' | 'movementX' | 'movementY'>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Whether the pointer moving over `pane` should activate it. Only a real mouse move with no button
|
|
77
|
+
* held counts: a touch, a pen tap, a drag, a selection or content shifting under a still pointer
|
|
78
|
+
* does not. Focus already inside the pane, inside an open overlay, or in a text field that is in
|
|
79
|
+
* no pane (no `[data-pane-id]` ancestor) and outside `scope` stays where it is.
|
|
80
|
+
*/
|
|
81
|
+
export function hoverTakesFocus(event: PointerLike, pane: HTMLElement, scope?: Element): boolean {
|
|
82
|
+
if (event.pointerType !== 'mouse' || event.buttons !== 0) return false
|
|
83
|
+
if (event.movementX === 0 && event.movementY === 0) return false
|
|
84
|
+
const active = pane.ownerDocument.activeElement
|
|
85
|
+
if (!active || active === pane.ownerDocument.body) return true
|
|
86
|
+
if (pane.contains(active)) return false
|
|
87
|
+
if (active.closest(OVERLAY)) return false
|
|
88
|
+
const inPane = active.closest('[data-pane-id]') !== null || (scope?.contains(active) ?? false)
|
|
89
|
+
return inPane || !active.matches(EDITABLE)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Moves focus into `pane` as a hover activation: back to the element it last had focus in, else
|
|
94
|
+
* its `data-pane-focus-target`, else the pane itself. The pane's `focusin` then marks it active.
|
|
95
|
+
* Returns whether focus moved.
|
|
96
|
+
*/
|
|
97
|
+
export function focusPaneOnHover(
|
|
98
|
+
event: PointerLike,
|
|
99
|
+
pane: HTMLElement,
|
|
100
|
+
options: { scope?: Element; mode?: PaneFocusMode } = {}
|
|
101
|
+
): boolean {
|
|
102
|
+
if ((options.mode ?? paneFocusMode()) !== 'hover') return false
|
|
103
|
+
if (!hoverTakesFocus(event, pane, options.scope)) return false
|
|
104
|
+
const remembered = lastFocused.get(pane)
|
|
105
|
+
const target =
|
|
106
|
+
(remembered?.isConnected && pane.contains(remembered) ? remembered : undefined) ??
|
|
107
|
+
pane.querySelector<HTMLElement>(PANE_FOCUS_TARGET) ??
|
|
108
|
+
pane
|
|
109
|
+
target.focus({ preventScroll: true })
|
|
110
|
+
return pane.contains(pane.ownerDocument.activeElement)
|
|
111
|
+
}
|
|
@@ -19,6 +19,13 @@ import { resizeSeparatorClass } from '#lib/resize-separator'
|
|
|
19
19
|
import { cn } from '#lib/utils'
|
|
20
20
|
import { computeLayoutFrames, type LayoutRect } from './geometry'
|
|
21
21
|
import { paneDropIntent, type PaneDropIntent } from './drop'
|
|
22
|
+
import {
|
|
23
|
+
focusPaneOnHover,
|
|
24
|
+
paneFocusMode,
|
|
25
|
+
rememberPaneFocus,
|
|
26
|
+
subscribePaneFocusMode,
|
|
27
|
+
type PaneFocusMode,
|
|
28
|
+
} from './pane-focus'
|
|
22
29
|
import { fastIcon } from '#lib/fast-icon'
|
|
23
30
|
|
|
24
31
|
// lucide icons drawn from a cloned template (see fastIcon).
|
|
@@ -73,6 +80,11 @@ export type SplitLayoutProps<L extends SplitLayoutLeaf> = {
|
|
|
73
80
|
labelForSeparator?: (branch: SplitLayoutBranch<L>) => string
|
|
74
81
|
onResize: (splitId: string, ratio: number) => void
|
|
75
82
|
onFocus?: (leafId: string) => void
|
|
83
|
+
/**
|
|
84
|
+
* How a pane takes focus. `hover` activates the pane the mouse moves onto (keys typed next go to
|
|
85
|
+
* it); `click` waits for a click. Defaults to the device preference (`paneFocusMode`).
|
|
86
|
+
*/
|
|
87
|
+
focusMode?: PaneFocusMode
|
|
76
88
|
/** Host performs the model transition and returns the surviving focus destination. */
|
|
77
89
|
onClose?: (leafId: string) => string | undefined
|
|
78
90
|
/** Pointer placement only; the host supplies keyboard commands and performs the model transition. */
|
|
@@ -230,6 +242,9 @@ export function SplitLayout<L extends SplitLayoutLeaf>(props: SplitLayoutProps<L
|
|
|
230
242
|
const [drag, setDrag] = createSignal<{ id: string; token: string }>()
|
|
231
243
|
const [drop, setDrop] = createSignal<{ id: string; intent: PaneDropIntent }>()
|
|
232
244
|
const [resizeController, setResizeController] = createSignal<ResizeControllerState<L>>()
|
|
245
|
+
const [preferredFocusMode, setPreferredFocusMode] = createSignal(paneFocusMode())
|
|
246
|
+
onCleanup(subscribePaneFocusMode(() => setPreferredFocusMode(paneFocusMode())))
|
|
247
|
+
const focusMode = () => props.focusMode ?? preferredFocusMode()
|
|
233
248
|
const reloadRequired = () => resizeControllerEntry >= resizeControllerEntries.length
|
|
234
249
|
const cancelPendingFocusRestore = () => {
|
|
235
250
|
if (pendingFocusFrame !== undefined) cancelAnimationFrame(pendingFocusFrame)
|
|
@@ -528,7 +543,18 @@ export function SplitLayout<L extends SplitLayoutLeaf>(props: SplitLayoutProps<L
|
|
|
528
543
|
}}
|
|
529
544
|
style={rectStyle(frames().get(id)?.rect ?? { x: 0, y: 0, width: 0, height: 0 })}
|
|
530
545
|
class="absolute flex min-h-0 min-w-0 flex-col overflow-hidden border border-border transition-opacity motion-reduce:transition-none data-[drag-source]:opacity-40 data-[focused]:border-primary bg-background text-foreground focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring"
|
|
531
|
-
|
|
546
|
+
data-focus-mode={focusMode()}
|
|
547
|
+
onFocusIn={(event) => {
|
|
548
|
+
rememberPaneFocus(event.currentTarget, event.target)
|
|
549
|
+
props.onFocus?.(id)
|
|
550
|
+
}}
|
|
551
|
+
onPointerMove={(event) => {
|
|
552
|
+
if (drag()) return
|
|
553
|
+
focusPaneOnHover(event, event.currentTarget, {
|
|
554
|
+
mode: focusMode(),
|
|
555
|
+
...(root ? { scope: root } : {}),
|
|
556
|
+
})
|
|
557
|
+
}}
|
|
532
558
|
>
|
|
533
559
|
<header class="flex min-w-0 shrink-0 items-center gap-2 bg-surface px-2">
|
|
534
560
|
<span
|