@xenosystem/elements-react 0.0.9 → 0.0.11
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/README.md +41 -41
- package/dist/containers/Avatar.d.ts +8 -1
- package/dist/containers/Avatar.js +3 -3
- package/dist/containers/BulkActionBar.d.ts +20 -0
- package/dist/containers/BulkActionBar.js +8 -0
- package/dist/containers/DataTable.d.ts +50 -6
- package/dist/containers/DataTable.js +185 -11
- package/dist/containers/Table.d.ts +2 -2
- package/dist/containers/Table.js +4 -3
- package/dist/content/Kbd.d.ts +16 -0
- package/dist/content/Kbd.js +8 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +12 -1
- package/dist/nav/Breadcrumb.d.ts +22 -0
- package/dist/nav/Breadcrumb.js +10 -0
- package/dist/overlays/CommandPalette.d.ts +43 -0
- package/dist/overlays/CommandPalette.js +96 -0
- package/dist/overlays/Popover.d.ts +27 -12
- package/dist/overlays/Popover.js +101 -7
- package/dist/overlays/ShortcutsSheet.d.ts +21 -0
- package/dist/overlays/ShortcutsSheet.js +7 -0
- package/dist/overlays/Tooltip.d.ts +21 -10
- package/dist/overlays/Tooltip.js +93 -9
- package/dist/shortcuts.d.ts +45 -0
- package/dist/shortcuts.js +164 -0
- package/dist/status/Banner.d.ts +23 -0
- package/dist/status/Banner.js +8 -0
- package/dist/status/Toast.d.ts +28 -0
- package/dist/status/Toast.js +11 -0
- package/dist/uiTree.d.ts +53 -0
- package/dist/uiTree.js +197 -0
- package/dist/useDialog.d.ts +3 -1
- package/dist/useDialog.js +37 -1
- package/dist/useMenu.js +31 -1
- package/dist/useToastQueue.d.ts +29 -0
- package/dist/useToastQueue.js +73 -0
- package/package.json +10 -4
- package/src/chrome-separated.css +133 -72
- package/src/chrome-unified.css +48 -16
- package/src/containers/Badges.css +52 -28
- package/src/containers/avatar.css +7 -2
- package/src/containers/bulk-action-bar.css +45 -0
- package/src/containers/card.css +14 -13
- package/src/containers/chip.css +1 -1
- package/src/containers/panel.css +16 -53
- package/src/containers/table.css +107 -1
- package/src/content/kbd.css +33 -0
- package/src/content/model-picker.css +2 -1
- package/src/controls.css +25 -11
- package/src/fonts.css +8 -2
- package/src/forced-colors.css +41 -0
- package/src/layout-platform.css +473 -0
- package/src/mcp-app-platform.css +1019 -0
- package/src/nav/breadcrumb.css +84 -0
- package/src/overlays/command-palette.css +157 -0
- package/src/overlays/menu.css +25 -16
- package/src/overlays/modal.css +9 -27
- package/src/overlays/onboarding.css +1305 -0
- package/src/overlays/segmented-control.css +6 -3
- package/src/overlays/shortcuts-sheet.css +55 -0
- package/src/overlays/tooltip.css +22 -4
- package/src/size.css +40 -0
- package/src/status/banner.css +83 -0
- package/src/status/toast.css +95 -0
- package/src/xeno-elements.css +63 -44
- package/src/xeno-theme.css +75 -31
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `<CommandPalette>` — the ⌘K command, navigation, and search overlay shared across Corpus,
|
|
4
|
+
* Creator, Workshop, and Desktop Shell (560px wide, 8px radius, `--xeno-pop` depth, grouped
|
|
5
|
+
* rows, ↑/↓/Enter/Esc keyboard navigation, and optional footer hints).
|
|
6
|
+
*/
|
|
7
|
+
export interface CommandPaletteItem {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly group?: string;
|
|
11
|
+
readonly description?: string;
|
|
12
|
+
readonly keywords?: readonly string[];
|
|
13
|
+
readonly shortcut?: readonly string[];
|
|
14
|
+
readonly badge?: ReactNode;
|
|
15
|
+
readonly disabled?: boolean;
|
|
16
|
+
readonly onSelect?: () => void;
|
|
17
|
+
}
|
|
18
|
+
export interface CommandPaletteProps {
|
|
19
|
+
/** Whether the palette is mounted and visible. */
|
|
20
|
+
readonly open: boolean;
|
|
21
|
+
/** Called on Esc, scrim click, or after selection (unless `closeOnSelect={false}`). */
|
|
22
|
+
readonly onClose: () => void;
|
|
23
|
+
/** Available items, optionally grouped via `item.group`. */
|
|
24
|
+
readonly items: readonly CommandPaletteItem[];
|
|
25
|
+
/** Controlled query value (optional; falls back to internal state). */
|
|
26
|
+
readonly query?: string;
|
|
27
|
+
/** Called when the search input changes. */
|
|
28
|
+
readonly onQueryChange?: (query: string) => void;
|
|
29
|
+
/** Called whenever an item is chosen. */
|
|
30
|
+
readonly onSelect?: (item: CommandPaletteItem) => void;
|
|
31
|
+
/** Input placeholder. */
|
|
32
|
+
readonly placeholder?: string;
|
|
33
|
+
/** Text shown when no items match the query. */
|
|
34
|
+
readonly emptyMessage?: ReactNode;
|
|
35
|
+
/** Accessible label for the dialog. */
|
|
36
|
+
readonly label?: string;
|
|
37
|
+
/** Close automatically on item select. Default `true`. */
|
|
38
|
+
readonly closeOnSelect?: boolean;
|
|
39
|
+
/** Optional custom footer content. */
|
|
40
|
+
readonly footer?: ReactNode;
|
|
41
|
+
readonly className?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function CommandPalette({ open, onClose, items, query: controlledQuery, onQueryChange, onSelect, placeholder, emptyMessage, label, closeOnSelect, footer, className, }: CommandPaletteProps): ReactElement | null;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useDialog } from '../useDialog.js';
|
|
4
|
+
import { XenoElement } from '../XenoElement.js';
|
|
5
|
+
import { Kbd } from '../content/Kbd.js';
|
|
6
|
+
import { cx } from '../controls/util.js';
|
|
7
|
+
import Search from '@xenosystem/elements/elements/search';
|
|
8
|
+
export function CommandPalette({ open, onClose, items, query: controlledQuery, onQueryChange, onSelect, placeholder = 'Type a command or search…', emptyMessage = 'No matching commands.', label = 'Command palette', closeOnSelect = true, footer, className, }) {
|
|
9
|
+
const [internalQuery, setInternalQuery] = useState('');
|
|
10
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
11
|
+
const scrimArmed = useRef(false);
|
|
12
|
+
const inputRef = useRef(null);
|
|
13
|
+
const listId = useId();
|
|
14
|
+
const { panelProps } = useDialog({ open, onClose });
|
|
15
|
+
const query = controlledQuery ?? internalQuery;
|
|
16
|
+
const setQuery = (next) => {
|
|
17
|
+
if (controlledQuery === undefined)
|
|
18
|
+
setInternalQuery(next);
|
|
19
|
+
onQueryChange?.(next);
|
|
20
|
+
setActiveIndex(0);
|
|
21
|
+
};
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (open) {
|
|
24
|
+
setActiveIndex(0);
|
|
25
|
+
inputRef.current?.focus();
|
|
26
|
+
}
|
|
27
|
+
}, [open]);
|
|
28
|
+
const filtered = useMemo(() => {
|
|
29
|
+
const q = query.trim().toLowerCase();
|
|
30
|
+
if (!q)
|
|
31
|
+
return items;
|
|
32
|
+
return items.filter((item) => {
|
|
33
|
+
const hay = [item.label, item.group ?? '', item.description ?? '', ...(item.keywords ?? [])]
|
|
34
|
+
.join(' ')
|
|
35
|
+
.toLowerCase();
|
|
36
|
+
return hay.includes(q);
|
|
37
|
+
});
|
|
38
|
+
}, [items, query]);
|
|
39
|
+
const grouped = useMemo(() => {
|
|
40
|
+
const map = new Map();
|
|
41
|
+
for (const item of filtered) {
|
|
42
|
+
const key = item.group ?? '';
|
|
43
|
+
const list = map.get(key);
|
|
44
|
+
if (list)
|
|
45
|
+
list.push(item);
|
|
46
|
+
else
|
|
47
|
+
map.set(key, [item]);
|
|
48
|
+
}
|
|
49
|
+
return [...map.entries()];
|
|
50
|
+
}, [filtered]);
|
|
51
|
+
if (!open)
|
|
52
|
+
return null;
|
|
53
|
+
const choose = (item) => {
|
|
54
|
+
if (item.disabled)
|
|
55
|
+
return;
|
|
56
|
+
item.onSelect?.();
|
|
57
|
+
onSelect?.(item);
|
|
58
|
+
if (closeOnSelect)
|
|
59
|
+
onClose();
|
|
60
|
+
};
|
|
61
|
+
const onKeyDown = (e) => {
|
|
62
|
+
if (e.key === 'ArrowDown') {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
if (filtered.length > 0)
|
|
65
|
+
setActiveIndex((i) => (i + 1) % filtered.length);
|
|
66
|
+
}
|
|
67
|
+
else if (e.key === 'ArrowUp') {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
if (filtered.length > 0)
|
|
70
|
+
setActiveIndex((i) => (i - 1 + filtered.length) % filtered.length);
|
|
71
|
+
}
|
|
72
|
+
else if (e.key === 'Enter') {
|
|
73
|
+
const item = filtered[activeIndex];
|
|
74
|
+
if (item && !item.disabled) {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
choose(item);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const onScrimMouseDown = (e) => {
|
|
81
|
+
scrimArmed.current = e.target === e.currentTarget;
|
|
82
|
+
};
|
|
83
|
+
const onScrimClick = (e) => {
|
|
84
|
+
if (e.target === e.currentTarget && scrimArmed.current)
|
|
85
|
+
onClose();
|
|
86
|
+
scrimArmed.current = false;
|
|
87
|
+
};
|
|
88
|
+
let flatIndex = -1;
|
|
89
|
+
const activeItem = filtered[activeIndex];
|
|
90
|
+
return (_jsx("div", { className: "xeno-palette-overlay", onMouseDown: onScrimMouseDown, onClick: onScrimClick, children: _jsxs("div", { ...panelProps, role: "dialog", "aria-modal": "true", "aria-label": label, className: cx('xeno-palette', className), children: [_jsxs("div", { className: "xeno-palette-head", children: [_jsx("span", { className: "xeno-palette-icon", "aria-hidden": "true", children: _jsx(XenoElement, { decl: Search, size: 15 }) }), _jsx("input", { ref: inputRef, type: "text", role: "combobox", "aria-expanded": "true", "aria-controls": listId, "aria-activedescendant": activeItem ? `${listId}-${activeItem.id}` : undefined, "aria-autocomplete": "list", className: "xeno-palette-input", value: query, placeholder: placeholder, onChange: (e) => setQuery(e.target.value), onKeyDown: onKeyDown }), _jsx(Kbd, { children: "Esc" })] }), _jsx("div", { id: listId, role: "listbox", className: "xeno-palette-list", children: filtered.length === 0 ? (_jsx("div", { className: "xeno-palette-empty", children: emptyMessage })) : (grouped.map(([group, groupItems]) => (_jsxs("div", { className: "xeno-palette-group", role: "group", "aria-label": group || undefined, children: [group ? _jsx("div", { className: "xeno-palette-group-label", children: group }) : null, groupItems.map((item) => {
|
|
91
|
+
flatIndex += 1;
|
|
92
|
+
const idx = flatIndex;
|
|
93
|
+
const active = idx === activeIndex;
|
|
94
|
+
return (_jsxs("button", { id: `${listId}-${item.id}`, type: "button", role: "option", "aria-selected": active, disabled: item.disabled, className: "xeno-palette-item", "data-active": active ? 'true' : undefined, onMouseEnter: () => setActiveIndex(idx), onClick: () => choose(item), children: [_jsxs("span", { className: "xeno-palette-item-copy", children: [_jsx("span", { className: "xeno-palette-item-label", children: item.label }), item.description ? (_jsx("span", { className: "xeno-palette-item-desc", children: item.description })) : null] }), item.badge ? _jsx("span", { className: "xeno-palette-item-badge", children: item.badge }) : null, item.shortcut ? _jsx(Kbd, { keys: item.shortcut }) : null] }, item.id));
|
|
95
|
+
})] }, group || '__ungrouped')))) }), _jsx("div", { className: "xeno-palette-foot", children: footer ?? (_jsxs(_Fragment, { children: [_jsxs("span", { className: "xeno-palette-hint", children: [_jsx(Kbd, { keys: ['↑', '↓'] }), " navigate"] }), _jsxs("span", { className: "xeno-palette-hint", children: [_jsx(Kbd, { children: "\u21B5" }), " select"] }), _jsxs("span", { className: "xeno-palette-hint", children: [_jsx(Kbd, { children: "Esc" }), " close"] })] })) })] }) }));
|
|
96
|
+
}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import type { HTMLAttributes, ReactElement, ReactNode, Ref } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
* `<Popover>` —
|
|
4
|
-
* holds the `trigger`; while `open`, an absolutely-positioned panel (`--xeno-elevated`, a hairline
|
|
5
|
-
* border, one soft uncoloured shadow, `--xeno-radius-md`) is placed below the trigger, aligned to its
|
|
6
|
-
* `start` (default) or `end` edge. Nothing renders inside the panel until it is open.
|
|
3
|
+
* `<Popover>` — portaled, collision-aware anchored overlay.
|
|
7
4
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* listbox, or any anchored surface on top of the same anchoring + dismissal behaviour.
|
|
5
|
+
* Client-side, the floating panel portals to `document.body` (preserving the nearest `.xeno`
|
|
6
|
+
* ancestor's `data-theme`, `data-chrome`, and `data-density` attributes) so it escapes any parent
|
|
7
|
+
* `overflow: hidden` panel, card, or scroll region. Coordinates are computed from the trigger rect
|
|
8
|
+
* with automatic vertical flipping (`bottom` ↔ `top`) and horizontal viewport clamping, updated on
|
|
9
|
+
* scroll and resize. During SSR (or when `portal={false}`), the panel renders inline so server
|
|
10
|
+
* markup stays self-contained.
|
|
15
11
|
*/
|
|
16
12
|
export interface PopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
17
13
|
/** Whether the panel is mounted + visible. Nothing renders in the panel when false. */
|
|
@@ -24,9 +20,28 @@ export interface PopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'chil
|
|
|
24
20
|
readonly children?: ReactNode;
|
|
25
21
|
/** Which trigger edge the panel aligns to. Default `start`. */
|
|
26
22
|
readonly align?: 'start' | 'end';
|
|
23
|
+
/** Preferred side relative to the trigger before collision flipping. Default `'bottom'`. */
|
|
24
|
+
readonly side?: 'bottom' | 'top';
|
|
25
|
+
/** Pixel gap between trigger and panel. Default `6`. */
|
|
26
|
+
readonly sideOffset?: number;
|
|
27
|
+
/** Portal panel to `document.body` on the client to escape `overflow: hidden`. Default `true`. */
|
|
28
|
+
readonly portal?: boolean;
|
|
27
29
|
/** Attached to the panel node (composition seam — e.g. {@link Menu} queries its items). */
|
|
28
30
|
readonly panelRef?: Ref<HTMLDivElement>;
|
|
29
31
|
/** Spread onto the panel node — `role`, `aria-*`, `onKeyDown`, `onClick`, … (composition seam). */
|
|
30
32
|
readonly panelProps?: HTMLAttributes<HTMLDivElement>;
|
|
31
33
|
}
|
|
32
|
-
|
|
34
|
+
interface FloatingPos {
|
|
35
|
+
readonly top: number;
|
|
36
|
+
readonly left: number;
|
|
37
|
+
readonly side: 'bottom' | 'top';
|
|
38
|
+
}
|
|
39
|
+
export declare function computeFloatingPosition(anchor: DOMRect, panel: {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
}, viewport: {
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
}, align: 'start' | 'end', preferredSide: 'bottom' | 'top', offset: number): FloatingPos;
|
|
46
|
+
export declare function Popover({ open, onOpenChange, trigger, children, align, side, sideOffset, portal, panelRef, panelProps, className, ...rest }: PopoverProps): ReactElement;
|
|
47
|
+
export {};
|
package/dist/overlays/Popover.js
CHANGED
|
@@ -1,16 +1,96 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
3
4
|
import { cx } from '../controls/util.js';
|
|
4
|
-
|
|
5
|
+
const VIEWPORT_MARGIN = 8;
|
|
6
|
+
function readThemeContext(anchor) {
|
|
7
|
+
if (!anchor)
|
|
8
|
+
return {};
|
|
9
|
+
const themed = anchor.closest('[data-theme]');
|
|
10
|
+
const chromed = anchor.closest('[data-chrome]');
|
|
11
|
+
const dense = anchor.closest('[data-density]');
|
|
12
|
+
const theme = themed?.getAttribute('data-theme') ?? undefined;
|
|
13
|
+
const chrome = chromed?.getAttribute('data-chrome') ?? undefined;
|
|
14
|
+
const density = dense?.getAttribute('data-density') ?? undefined;
|
|
15
|
+
return {
|
|
16
|
+
...(theme ? { theme } : {}),
|
|
17
|
+
...(chrome ? { chrome } : {}),
|
|
18
|
+
...(density ? { density } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function computeFloatingPosition(anchor, panel, viewport, align, preferredSide, offset) {
|
|
22
|
+
const belowTop = anchor.bottom + offset;
|
|
23
|
+
const aboveTop = anchor.top - offset - panel.height;
|
|
24
|
+
let resolvedSide = preferredSide;
|
|
25
|
+
let top = preferredSide === 'bottom' ? belowTop : aboveTop;
|
|
26
|
+
if (preferredSide === 'bottom' && belowTop + panel.height > viewport.height - VIEWPORT_MARGIN && aboveTop >= VIEWPORT_MARGIN) {
|
|
27
|
+
resolvedSide = 'top';
|
|
28
|
+
top = aboveTop;
|
|
29
|
+
}
|
|
30
|
+
else if (preferredSide === 'top' && aboveTop < VIEWPORT_MARGIN && belowTop + panel.height <= viewport.height - VIEWPORT_MARGIN) {
|
|
31
|
+
resolvedSide = 'bottom';
|
|
32
|
+
top = belowTop;
|
|
33
|
+
}
|
|
34
|
+
top = Math.max(VIEWPORT_MARGIN, Math.min(top, Math.max(VIEWPORT_MARGIN, viewport.height - panel.height - VIEWPORT_MARGIN)));
|
|
35
|
+
const rawLeft = align === 'end' ? anchor.right - panel.width : anchor.left;
|
|
36
|
+
const left = Math.max(VIEWPORT_MARGIN, Math.min(rawLeft, Math.max(VIEWPORT_MARGIN, viewport.width - panel.width - VIEWPORT_MARGIN)));
|
|
37
|
+
return { top: Math.round(top), left: Math.round(left), side: resolvedSide };
|
|
38
|
+
}
|
|
39
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
40
|
+
export function Popover({ open, onOpenChange, trigger, children, align = 'start', side = 'bottom', sideOffset = 6, portal = true, panelRef, panelProps, className, ...rest }) {
|
|
5
41
|
const rootRef = useRef(null);
|
|
42
|
+
const localPanelRef = useRef(null);
|
|
6
43
|
const restoreFocus = useRef(null);
|
|
7
|
-
|
|
44
|
+
const [portalTarget, setPortalTarget] = useState(null);
|
|
45
|
+
const [pos, setPos] = useState(null);
|
|
46
|
+
const [themeCtx, setThemeCtx] = useState({});
|
|
47
|
+
const attachPanelRef = useCallback((node) => {
|
|
48
|
+
localPanelRef.current = node;
|
|
49
|
+
if (typeof panelRef === 'function')
|
|
50
|
+
panelRef(node);
|
|
51
|
+
else if (panelRef && 'current' in panelRef) {
|
|
52
|
+
;
|
|
53
|
+
panelRef.current = node;
|
|
54
|
+
}
|
|
55
|
+
}, [panelRef]);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (portal && typeof document !== 'undefined')
|
|
58
|
+
setPortalTarget(document.body);
|
|
59
|
+
else
|
|
60
|
+
setPortalTarget(null);
|
|
61
|
+
}, [portal]);
|
|
62
|
+
const updatePosition = useCallback(() => {
|
|
63
|
+
const anchorEl = rootRef.current;
|
|
64
|
+
const panelEl = localPanelRef.current;
|
|
65
|
+
if (!anchorEl || !panelEl || typeof window === 'undefined')
|
|
66
|
+
return;
|
|
67
|
+
const anchorRect = anchorEl.getBoundingClientRect();
|
|
68
|
+
const panelRect = panelEl.getBoundingClientRect();
|
|
69
|
+
setPos(computeFloatingPosition(anchorRect, { width: panelRect.width || 180, height: panelRect.height || 120 }, { width: window.innerWidth, height: window.innerHeight }, align, side, sideOffset));
|
|
70
|
+
setThemeCtx(readThemeContext(anchorEl));
|
|
71
|
+
}, [align, side, sideOffset]);
|
|
72
|
+
useIsomorphicLayoutEffect(() => {
|
|
73
|
+
if (!open || !portalTarget)
|
|
74
|
+
return;
|
|
75
|
+
updatePosition();
|
|
76
|
+
window.addEventListener('resize', updatePosition);
|
|
77
|
+
window.addEventListener('scroll', updatePosition, true);
|
|
78
|
+
return () => {
|
|
79
|
+
window.removeEventListener('resize', updatePosition);
|
|
80
|
+
window.removeEventListener('scroll', updatePosition, true);
|
|
81
|
+
};
|
|
82
|
+
}, [open, portalTarget, updatePosition]);
|
|
83
|
+
// Dismissal — check both the trigger wrapper AND the portaled panel so clicks inside never dismiss.
|
|
8
84
|
useEffect(() => {
|
|
9
85
|
if (!open)
|
|
10
86
|
return;
|
|
11
87
|
const onPointer = (e) => {
|
|
12
|
-
|
|
13
|
-
|
|
88
|
+
const target = e.target;
|
|
89
|
+
if (rootRef.current?.contains(target))
|
|
90
|
+
return;
|
|
91
|
+
if (localPanelRef.current?.contains(target))
|
|
92
|
+
return;
|
|
93
|
+
onOpenChange?.(false);
|
|
14
94
|
};
|
|
15
95
|
const onKey = (e) => {
|
|
16
96
|
if (e.key === 'Escape')
|
|
@@ -33,6 +113,20 @@ export function Popover({ open, onOpenChange, trigger, children, align = 'start'
|
|
|
33
113
|
restoreFocus.current = null;
|
|
34
114
|
}
|
|
35
115
|
}, [open]);
|
|
36
|
-
const { className: panelClassName, ...restPanel } = panelProps ?? {};
|
|
37
|
-
|
|
116
|
+
const { className: panelClassName, style: panelStyle, ...restPanel } = panelProps ?? {};
|
|
117
|
+
const floatingStyle = portalTarget && pos
|
|
118
|
+
? {
|
|
119
|
+
...panelStyle,
|
|
120
|
+
position: 'fixed',
|
|
121
|
+
top: pos.top,
|
|
122
|
+
left: pos.left,
|
|
123
|
+
right: 'auto',
|
|
124
|
+
zIndex: 1000,
|
|
125
|
+
}
|
|
126
|
+
: panelStyle;
|
|
127
|
+
const panelNode = open ? (_jsx("div", { ref: attachPanelRef, className: cx('xeno-popover-panel', portalTarget ? 'xeno-popover-panel--portaled' : false, panelClassName), "data-align": align, "data-side": pos?.side ?? side, style: floatingStyle, ...restPanel, children: children })) : null;
|
|
128
|
+
return (_jsxs("div", { ref: rootRef, className: cx('xeno-popover', className), ...rest, children: [trigger, panelNode &&
|
|
129
|
+
(portalTarget
|
|
130
|
+
? createPortal(_jsx("div", { className: "xeno xeno-popover-portal", "data-theme": themeCtx.theme, "data-chrome": themeCtx.chrome, "data-density": themeCtx.density, children: panelNode }), portalTarget)
|
|
131
|
+
: panelNode)] }));
|
|
38
132
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `<ShortcutsSheet>` — keyboard shortcuts dialog (`?` in Corpus, Creator, Motion, and Workshop),
|
|
4
|
+
* composed directly on `<Modal>` + `<Kbd>` with grouped 2-column sections.
|
|
5
|
+
*/
|
|
6
|
+
export interface ShortcutEntry {
|
|
7
|
+
readonly label: string;
|
|
8
|
+
readonly keys: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export interface ShortcutSection {
|
|
11
|
+
readonly title: string;
|
|
12
|
+
readonly items: readonly ShortcutEntry[];
|
|
13
|
+
}
|
|
14
|
+
export interface ShortcutsSheetProps {
|
|
15
|
+
readonly open: boolean;
|
|
16
|
+
readonly onClose: () => void;
|
|
17
|
+
readonly sections: readonly ShortcutSection[];
|
|
18
|
+
readonly title?: string;
|
|
19
|
+
readonly className?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function ShortcutsSheet({ open, onClose, sections, title, className, }: ShortcutsSheetProps): ReactElement | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Modal } from './Modal.js';
|
|
3
|
+
import { Kbd } from '../content/Kbd.js';
|
|
4
|
+
import { cx } from '../controls/util.js';
|
|
5
|
+
export function ShortcutsSheet({ open, onClose, sections, title = 'Keyboard shortcuts', className, }) {
|
|
6
|
+
return (_jsx(Modal, { open: open, onClose: onClose, title: title, className: cx('xeno-shortcuts-modal', className), children: _jsx("div", { className: "xeno-shortcuts-grid", children: sections.map((section) => (_jsxs("section", { className: "xeno-shortcuts-section", children: [_jsx("h3", { className: "xeno-shortcuts-heading", children: section.title }), _jsx("dl", { className: "xeno-shortcuts-list", children: section.items.map((item) => (_jsxs("div", { className: "xeno-shortcuts-row", children: [_jsx("dt", { className: "xeno-shortcuts-label", children: item.label }), _jsx("dd", { className: "xeno-shortcuts-keys", children: _jsx(Kbd, { keys: item.keys, size: "md" }) })] }, `${section.title}-${item.label}`))) })] }, section.title))) }) }));
|
|
7
|
+
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
* `<Tooltip>` — a hover/focus hint
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
* and
|
|
7
|
-
* animates opacity/transform. Reveal is instant on keyboard focus and, on hover, waits `delay` ms;
|
|
8
|
-
* per the ARIA tooltip pattern, Escape dismisses it while the pointer/focus stay put.
|
|
9
|
-
*
|
|
10
|
-
* Monochrome shell: an `--xeno-elevated` panel with a hairline border and muted 12px mono text.
|
|
3
|
+
* `<Tooltip>` — a hover/focus hint that portals to `document.body` on the client (escaping
|
|
4
|
+
* `overflow: hidden` scroll containers and stacking contexts) and flips/clamps against the
|
|
5
|
+
* viewport edges (`top ↔ bottom`, `left ↔ right`). Falls back to inline rendering on SSR so
|
|
6
|
+
* `role="tooltip"` and `aria-describedby` are always present in static HTML.
|
|
11
7
|
*/
|
|
12
8
|
export type TooltipSide = 'top' | 'bottom' | 'left' | 'right';
|
|
13
9
|
export interface TooltipProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'content' | 'children'> {
|
|
@@ -15,9 +11,24 @@ export interface TooltipProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'con
|
|
|
15
11
|
readonly content: ReactNode;
|
|
16
12
|
/** The trigger. A single element is wired with `aria-describedby`; other nodes render as-is. */
|
|
17
13
|
readonly children: ReactNode;
|
|
18
|
-
/**
|
|
14
|
+
/** Preferred side of the trigger. Flips automatically if clipped at the viewport edge. Default `top`. */
|
|
19
15
|
readonly side?: TooltipSide;
|
|
20
16
|
/** Milliseconds to wait before the hover reveal (keyboard focus is always instant). Default 150. */
|
|
21
17
|
readonly delay?: number;
|
|
18
|
+
/** Render the tooltip via a `document.body` portal on the client. Default `true`. */
|
|
19
|
+
readonly portal?: boolean;
|
|
22
20
|
}
|
|
23
|
-
export
|
|
21
|
+
export interface TooltipPosition {
|
|
22
|
+
readonly top: number;
|
|
23
|
+
readonly left: number;
|
|
24
|
+
readonly side: TooltipSide;
|
|
25
|
+
}
|
|
26
|
+
/** Pure collision-flip & viewport-clamp placement for Tooltip (also exported for tests). */
|
|
27
|
+
export declare function computeTooltipPosition(anchor: Pick<DOMRect, 'top' | 'bottom' | 'left' | 'right' | 'width' | 'height'>, panel: {
|
|
28
|
+
readonly width: number;
|
|
29
|
+
readonly height: number;
|
|
30
|
+
}, viewport: {
|
|
31
|
+
readonly width: number;
|
|
32
|
+
readonly height: number;
|
|
33
|
+
}, preferredSide?: TooltipSide, gap?: number): TooltipPosition;
|
|
34
|
+
export declare function Tooltip({ content, children, side, delay, portal, className, onKeyDown, onMouseEnter, onMouseLeave, onFocus, onBlur, ...rest }: TooltipProps): ReactElement;
|
package/dist/overlays/Tooltip.js
CHANGED
|
@@ -1,12 +1,62 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { cloneElement, isValidElement, useCallback, useEffect, useId, useRef, useState, } from 'react';
|
|
2
|
+
import { cloneElement, isValidElement, useCallback, useEffect, useId, useLayoutEffect, useRef, useState, } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
3
4
|
import { cx } from '../controls/util.js';
|
|
4
|
-
|
|
5
|
+
const VIEWPORT_PAD = 8;
|
|
6
|
+
/** Pure collision-flip & viewport-clamp placement for Tooltip (also exported for tests). */
|
|
7
|
+
export function computeTooltipPosition(anchor, panel, viewport, preferredSide = 'top', gap = 8) {
|
|
8
|
+
let side = preferredSide;
|
|
9
|
+
const w = panel.width || 120;
|
|
10
|
+
const h = panel.height || 28;
|
|
11
|
+
if (side === 'top' && anchor.top - gap - h < VIEWPORT_PAD && anchor.bottom + gap + h <= viewport.height - VIEWPORT_PAD) {
|
|
12
|
+
side = 'bottom';
|
|
13
|
+
}
|
|
14
|
+
else if (side === 'bottom' && anchor.bottom + gap + h > viewport.height - VIEWPORT_PAD && anchor.top - gap - h >= VIEWPORT_PAD) {
|
|
15
|
+
side = 'top';
|
|
16
|
+
}
|
|
17
|
+
else if (side === 'left' && anchor.left - gap - w < VIEWPORT_PAD && anchor.right + gap + w <= viewport.width - VIEWPORT_PAD) {
|
|
18
|
+
side = 'right';
|
|
19
|
+
}
|
|
20
|
+
else if (side === 'right' && anchor.right + gap + w > viewport.width - VIEWPORT_PAD && anchor.left - gap - w >= VIEWPORT_PAD) {
|
|
21
|
+
side = 'left';
|
|
22
|
+
}
|
|
23
|
+
let top = 0;
|
|
24
|
+
let left = 0;
|
|
25
|
+
if (side === 'top') {
|
|
26
|
+
top = anchor.top - gap - h;
|
|
27
|
+
left = anchor.left + anchor.width / 2 - w / 2;
|
|
28
|
+
}
|
|
29
|
+
else if (side === 'bottom') {
|
|
30
|
+
top = anchor.bottom + gap;
|
|
31
|
+
left = anchor.left + anchor.width / 2 - w / 2;
|
|
32
|
+
}
|
|
33
|
+
else if (side === 'left') {
|
|
34
|
+
top = anchor.top + anchor.height / 2 - h / 2;
|
|
35
|
+
left = anchor.left - gap - w;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
top = anchor.top + anchor.height / 2 - h / 2;
|
|
39
|
+
left = anchor.right + gap;
|
|
40
|
+
}
|
|
41
|
+
top = Math.max(VIEWPORT_PAD, Math.min(viewport.height - h - VIEWPORT_PAD, top));
|
|
42
|
+
left = Math.max(VIEWPORT_PAD, Math.min(viewport.width - w - VIEWPORT_PAD, left));
|
|
43
|
+
return { top: Math.round(top), left: Math.round(left), side };
|
|
44
|
+
}
|
|
45
|
+
const useIsoLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
46
|
+
export function Tooltip({ content, children, side = 'top', delay = 150, portal = true, className, onKeyDown, onMouseEnter, onMouseLeave, onFocus, onBlur, ...rest }) {
|
|
5
47
|
const panelId = useId();
|
|
48
|
+
const rootRef = useRef(null);
|
|
49
|
+
const panelRef = useRef(null);
|
|
6
50
|
const [hovered, setHovered] = useState(false);
|
|
7
51
|
const [focused, setFocused] = useState(false);
|
|
8
52
|
const [dismissed, setDismissed] = useState(false);
|
|
53
|
+
const [mounted, setMounted] = useState(false);
|
|
54
|
+
const [pos, setPos] = useState(null);
|
|
55
|
+
const [scopeAttrs, setScopeAttrs] = useState({});
|
|
9
56
|
const timer = useRef(undefined);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
setMounted(true);
|
|
59
|
+
}, []);
|
|
10
60
|
const clear = useCallback(() => {
|
|
11
61
|
if (timer.current !== undefined) {
|
|
12
62
|
clearTimeout(timer.current);
|
|
@@ -14,10 +64,6 @@ export function Tooltip({ content, children, side = 'top', delay = 150, classNam
|
|
|
14
64
|
}
|
|
15
65
|
}, []);
|
|
16
66
|
useEffect(() => clear, [clear]);
|
|
17
|
-
/* Every one of these CHAINS the caller's handler rather than replacing it. They used to be written
|
|
18
|
-
after `{...rest}` in the JSX, which meant a caller's `onMouseEnter` / `onMouseLeave` / `onFocus` /
|
|
19
|
-
`onBlur` was silently overridden — `onKeyDown` was already chained here, which is what shows the
|
|
20
|
-
other four were an oversight rather than a decision. */
|
|
21
67
|
const openHover = useCallback((e) => {
|
|
22
68
|
onMouseEnter?.(e);
|
|
23
69
|
clear();
|
|
@@ -50,12 +96,50 @@ export function Tooltip({ content, children, side = 'top', delay = 150, classNam
|
|
|
50
96
|
}, [onKeyDown]);
|
|
51
97
|
const open = (hovered || focused) && !dismissed;
|
|
52
98
|
const state = open ? 'open' : 'closed';
|
|
53
|
-
|
|
54
|
-
|
|
99
|
+
const canPortal = portal && mounted && typeof document !== 'undefined';
|
|
100
|
+
useIsoLayoutEffect(() => {
|
|
101
|
+
if (!canPortal || !rootRef.current)
|
|
102
|
+
return;
|
|
103
|
+
const scope = rootRef.current.closest('.xeno');
|
|
104
|
+
const chromeHost = rootRef.current.closest('[data-chrome]');
|
|
105
|
+
const densityHost = rootRef.current.closest('[data-density]');
|
|
106
|
+
setScopeAttrs({
|
|
107
|
+
...(scope?.getAttribute('data-theme') ? { theme: scope.getAttribute('data-theme') } : {}),
|
|
108
|
+
...(chromeHost?.getAttribute('data-chrome') ? { chrome: chromeHost.getAttribute('data-chrome') } : {}),
|
|
109
|
+
...(densityHost?.getAttribute('data-density') ? { density: densityHost.getAttribute('data-density') } : {}),
|
|
110
|
+
});
|
|
111
|
+
}, [canPortal, open]);
|
|
112
|
+
useIsoLayoutEffect(() => {
|
|
113
|
+
if (!open || !canPortal)
|
|
114
|
+
return;
|
|
115
|
+
const update = () => {
|
|
116
|
+
const anchorEl = rootRef.current;
|
|
117
|
+
const panelEl = panelRef.current;
|
|
118
|
+
if (!anchorEl)
|
|
119
|
+
return;
|
|
120
|
+
const anchorRect = anchorEl.getBoundingClientRect();
|
|
121
|
+
const panelRect = panelEl?.getBoundingClientRect();
|
|
122
|
+
setPos(computeTooltipPosition(anchorRect, { width: panelRect?.width ?? 120, height: panelRect?.height ?? 28 }, { width: window.innerWidth, height: window.innerHeight }, side, 8));
|
|
123
|
+
};
|
|
124
|
+
update();
|
|
125
|
+
window.addEventListener('scroll', update, true);
|
|
126
|
+
window.addEventListener('resize', update);
|
|
127
|
+
return () => {
|
|
128
|
+
window.removeEventListener('scroll', update, true);
|
|
129
|
+
window.removeEventListener('resize', update);
|
|
130
|
+
};
|
|
131
|
+
}, [open, canPortal, side]);
|
|
55
132
|
const trigger = isValidElement(children)
|
|
56
133
|
? cloneElement(children, {
|
|
57
134
|
'aria-describedby': panelId,
|
|
58
135
|
})
|
|
59
136
|
: children;
|
|
60
|
-
|
|
137
|
+
const resolvedSide = pos?.side ?? side;
|
|
138
|
+
const portaledStyle = canPortal && pos
|
|
139
|
+
? { position: 'fixed', top: pos.top, left: pos.left, zIndex: 1050 }
|
|
140
|
+
: undefined;
|
|
141
|
+
const panelNode = (_jsxs("span", { ref: panelRef, className: cx('xeno-tooltip-panel', canPortal ? 'xeno-tooltip-panel--portaled' : false), role: "tooltip", id: panelId, "data-side": resolvedSide, "data-state": state, style: portaledStyle, children: [content, _jsx("span", { className: "xeno-tooltip-arrow", "aria-hidden": "true" })] }));
|
|
142
|
+
return (_jsxs("span", { ref: rootRef, className: cx('xeno-tooltip', className), "data-side": resolvedSide, "data-state": state, ...rest, onMouseEnter: openHover, onMouseLeave: closeHover, onFocus: openFocus, onBlur: closeFocus, onKeyDown: handleKeyDown, children: [trigger, canPortal
|
|
143
|
+
? createPortal(_jsx("span", { className: "xeno xeno-tooltip-portal", "data-theme": scopeAttrs.theme, "data-chrome": scopeAttrs.chrome, "data-density": scopeAttrs.density, children: panelNode }), document.body)
|
|
144
|
+
: panelNode] }));
|
|
61
145
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { CommandPaletteItem } from './overlays/CommandPalette.js';
|
|
2
|
+
import type { ShortcutSection } from './overlays/ShortcutsSheet.js';
|
|
3
|
+
/**
|
|
4
|
+
* Unified Keyboard-Shortcut Registry — single source of truth for global keyboard chords
|
|
5
|
+
* (`mod+k`, `?`, `mod+j`) and Linear-style two-key sequences (`g o`, `g s`), plus deterministic
|
|
6
|
+
* collision detection and zero-drift derivation of `ShortcutsSheet` sections & `CommandPalette` items.
|
|
7
|
+
*/
|
|
8
|
+
export interface ShortcutBinding {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
/** Canonical chord (`mod+k`, `?`, `shift+d`) or space-separated sequence (`g o`, `g s`). */
|
|
11
|
+
readonly chord: string;
|
|
12
|
+
readonly label: string;
|
|
13
|
+
readonly group: string;
|
|
14
|
+
/** Optional keywords for CommandPalette fuzzy filtering. */
|
|
15
|
+
readonly keywords?: readonly string[];
|
|
16
|
+
/** Allow firing even when focus is inside an input/textarea (default `true` for `mod+` chords, `false` otherwise). */
|
|
17
|
+
readonly allowInInputs?: boolean;
|
|
18
|
+
readonly disabled?: boolean;
|
|
19
|
+
readonly onTrigger: () => void;
|
|
20
|
+
}
|
|
21
|
+
export interface ShortcutCollision {
|
|
22
|
+
readonly chord: string;
|
|
23
|
+
readonly ids: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** Convert a canonical chord string (`mod+k`, `g s`) into display keycaps (`['⌘', 'K']`, `['G', 'S']`). */
|
|
26
|
+
export declare function formatShortcutKeys(chord: string): readonly string[];
|
|
27
|
+
/** Detect duplicate chords or sequence-prefix conflicts across all registered bindings. */
|
|
28
|
+
export declare function detectShortcutCollisions(bindings: readonly ShortcutBinding[]): readonly ShortcutCollision[];
|
|
29
|
+
/** Derive `ShortcutsSheet` sections directly from the live shortcut registry (zero drift). */
|
|
30
|
+
export declare function toShortcutSections(bindings: readonly ShortcutBinding[]): readonly ShortcutSection[];
|
|
31
|
+
/** Derive `CommandPalette` items directly from the live shortcut registry (zero drift). */
|
|
32
|
+
export declare function toCommandItems(bindings: readonly ShortcutBinding[]): readonly CommandPaletteItem[];
|
|
33
|
+
export interface UseShortcutRegistryResult {
|
|
34
|
+
readonly sections: readonly ShortcutSection[];
|
|
35
|
+
readonly commandItems: readonly CommandPaletteItem[];
|
|
36
|
+
readonly collisions: readonly ShortcutCollision[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Bind a unified set of keyboard shortcuts on `window` (supporting chords and 2-key sequences)
|
|
40
|
+
* and return derived `ShortcutsSheet` sections, `CommandPalette` items, and any detected collisions.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useShortcutRegistry(bindings: readonly ShortcutBinding[], options?: {
|
|
43
|
+
readonly enabled?: boolean;
|
|
44
|
+
readonly sequenceTimeoutMs?: number;
|
|
45
|
+
}): UseShortcutRegistryResult;
|