@xenosystem/elements-react 0.0.10 → 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/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 +9 -3
- 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,164 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
const MOD_KEYS = new Set(['mod', 'ctrl', 'meta', 'alt', 'shift']);
|
|
3
|
+
const normalizeChord = (raw) => raw
|
|
4
|
+
.trim()
|
|
5
|
+
.toLowerCase()
|
|
6
|
+
.split(/\s+/)
|
|
7
|
+
.map((step) => {
|
|
8
|
+
const parts = step.split('+').filter(Boolean);
|
|
9
|
+
const mods = parts.filter((p) => MOD_KEYS.has(p)).sort();
|
|
10
|
+
const key = parts.find((p) => !MOD_KEYS.has(p)) ?? '';
|
|
11
|
+
return [...mods, key].filter(Boolean).join('+');
|
|
12
|
+
})
|
|
13
|
+
.join(' ');
|
|
14
|
+
/** Convert a canonical chord string (`mod+k`, `g s`) into display keycaps (`['⌘', 'K']`, `['G', 'S']`). */
|
|
15
|
+
export function formatShortcutKeys(chord) {
|
|
16
|
+
const norm = normalizeChord(chord);
|
|
17
|
+
return norm.split(' ').flatMap((step) => step.split('+').map((part) => {
|
|
18
|
+
if (part === 'mod' || part === 'meta')
|
|
19
|
+
return '⌘';
|
|
20
|
+
if (part === 'ctrl')
|
|
21
|
+
return 'Ctrl';
|
|
22
|
+
if (part === 'alt')
|
|
23
|
+
return '⌥';
|
|
24
|
+
if (part === 'shift')
|
|
25
|
+
return '⇧';
|
|
26
|
+
if (part === 'enter')
|
|
27
|
+
return '↵';
|
|
28
|
+
if (part === 'escape' || part === 'esc')
|
|
29
|
+
return 'Esc';
|
|
30
|
+
if (part === 'backspace')
|
|
31
|
+
return '⌫';
|
|
32
|
+
return part.length === 1 ? part.toUpperCase() : part;
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
/** Detect duplicate chords or sequence-prefix conflicts across all registered bindings. */
|
|
36
|
+
export function detectShortcutCollisions(bindings) {
|
|
37
|
+
const byChord = new Map();
|
|
38
|
+
for (const b of bindings) {
|
|
39
|
+
if (b.disabled)
|
|
40
|
+
continue;
|
|
41
|
+
const key = normalizeChord(b.chord);
|
|
42
|
+
const list = byChord.get(key) ?? [];
|
|
43
|
+
list.push(b.id);
|
|
44
|
+
byChord.set(key, list);
|
|
45
|
+
}
|
|
46
|
+
const collisions = [];
|
|
47
|
+
for (const [chord, ids] of byChord) {
|
|
48
|
+
if (ids.length > 1)
|
|
49
|
+
collisions.push({ chord, ids });
|
|
50
|
+
}
|
|
51
|
+
return collisions;
|
|
52
|
+
}
|
|
53
|
+
/** Derive `ShortcutsSheet` sections directly from the live shortcut registry (zero drift). */
|
|
54
|
+
export function toShortcutSections(bindings) {
|
|
55
|
+
const grouped = new Map();
|
|
56
|
+
for (const b of bindings) {
|
|
57
|
+
if (b.disabled)
|
|
58
|
+
continue;
|
|
59
|
+
const list = grouped.get(b.group) ?? [];
|
|
60
|
+
list.push({ label: b.label, keys: formatShortcutKeys(b.chord) });
|
|
61
|
+
grouped.set(b.group, list);
|
|
62
|
+
}
|
|
63
|
+
return Array.from(grouped.entries()).map(([title, items]) => ({ title, items }));
|
|
64
|
+
}
|
|
65
|
+
/** Derive `CommandPalette` items directly from the live shortcut registry (zero drift). */
|
|
66
|
+
export function toCommandItems(bindings) {
|
|
67
|
+
return bindings
|
|
68
|
+
.filter((b) => !b.disabled)
|
|
69
|
+
.map((b) => ({
|
|
70
|
+
id: b.id,
|
|
71
|
+
label: b.label,
|
|
72
|
+
group: b.group,
|
|
73
|
+
shortcut: formatShortcutKeys(b.chord),
|
|
74
|
+
...(b.keywords ? { keywords: b.keywords } : {}),
|
|
75
|
+
onSelect: b.onTrigger,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
function isEditableTarget(target) {
|
|
79
|
+
if (!(target instanceof HTMLElement))
|
|
80
|
+
return false;
|
|
81
|
+
const tag = target.tagName;
|
|
82
|
+
return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || target.isContentEditable;
|
|
83
|
+
}
|
|
84
|
+
function eventToStep(e) {
|
|
85
|
+
const mods = [];
|
|
86
|
+
if (e.altKey)
|
|
87
|
+
mods.push('alt');
|
|
88
|
+
if (e.metaKey || e.ctrlKey)
|
|
89
|
+
mods.push('mod');
|
|
90
|
+
if (e.shiftKey && e.key.length > 1)
|
|
91
|
+
mods.push('shift');
|
|
92
|
+
const key = e.key.toLowerCase();
|
|
93
|
+
return [...mods.sort(), key].join('+');
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Bind a unified set of keyboard shortcuts on `window` (supporting chords and 2-key sequences)
|
|
97
|
+
* and return derived `ShortcutsSheet` sections, `CommandPalette` items, and any detected collisions.
|
|
98
|
+
*/
|
|
99
|
+
export function useShortcutRegistry(bindings, options = {}) {
|
|
100
|
+
const enabled = options.enabled ?? true;
|
|
101
|
+
const sequenceTimeoutMs = options.sequenceTimeoutMs ?? 750;
|
|
102
|
+
const bindingsRef = useRef(bindings);
|
|
103
|
+
bindingsRef.current = bindings;
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!enabled || typeof window === 'undefined')
|
|
106
|
+
return;
|
|
107
|
+
let prefix = null;
|
|
108
|
+
let timer = null;
|
|
109
|
+
const clearPrefix = () => {
|
|
110
|
+
prefix = null;
|
|
111
|
+
if (timer !== null) {
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
timer = null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const onKeyDown = (e) => {
|
|
117
|
+
const step = eventToStep(e);
|
|
118
|
+
const editable = isEditableTarget(e.target);
|
|
119
|
+
const list = bindingsRef.current;
|
|
120
|
+
// 1. Check active 2-key sequence completion first
|
|
121
|
+
if (prefix !== null) {
|
|
122
|
+
const combo = `${prefix} ${step}`;
|
|
123
|
+
const seqMatch = list.find((b) => !b.disabled && normalizeChord(b.chord) === combo);
|
|
124
|
+
if (seqMatch) {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
clearPrefix();
|
|
127
|
+
seqMatch.onTrigger();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
clearPrefix();
|
|
131
|
+
}
|
|
132
|
+
// 2. Check if this key starts a 2-key sequence (only outside text inputs)
|
|
133
|
+
if (!editable && list.some((b) => !b.disabled && normalizeChord(b.chord).startsWith(`${step} `))) {
|
|
134
|
+
prefix = step;
|
|
135
|
+
timer = setTimeout(clearPrefix, sequenceTimeoutMs);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// 3. Check single-step chord match
|
|
139
|
+
const match = list.find((b) => {
|
|
140
|
+
if (b.disabled)
|
|
141
|
+
return false;
|
|
142
|
+
const norm = normalizeChord(b.chord);
|
|
143
|
+
if (norm !== step)
|
|
144
|
+
return false;
|
|
145
|
+
const allowInInputs = b.allowInInputs ?? norm.includes('mod+');
|
|
146
|
+
return !editable || allowInInputs;
|
|
147
|
+
});
|
|
148
|
+
if (match) {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
match.onTrigger();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
window.addEventListener('keydown', onKeyDown);
|
|
154
|
+
return () => {
|
|
155
|
+
clearPrefix();
|
|
156
|
+
window.removeEventListener('keydown', onKeyDown);
|
|
157
|
+
};
|
|
158
|
+
}, [enabled, sequenceTimeoutMs]);
|
|
159
|
+
return useMemo(() => ({
|
|
160
|
+
sections: toShortcutSections(bindings),
|
|
161
|
+
commandItems: toCommandItems(bindings),
|
|
162
|
+
collisions: detectShortcutCollisions(bindings),
|
|
163
|
+
}), [bindings]);
|
|
164
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `<Banner>` — full-width 32px system/connection/runner status strip under an app header
|
|
4
|
+
* (Creator `degraded` / `offline` connection banner, Corpus runner status strip).
|
|
5
|
+
*
|
|
6
|
+
* Uses a 7px square tone indicator, soft semantic background (`--xeno-warn-soft`,
|
|
7
|
+
* `--xeno-danger-soft`, `--xeno-ok-soft`, `--xeno-info-soft`), and optional trailing action /
|
|
8
|
+
* dismiss button.
|
|
9
|
+
*/
|
|
10
|
+
export type BannerTone = 'neutral' | 'info' | 'ok' | 'warn' | 'danger';
|
|
11
|
+
export interface BannerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
12
|
+
/** Semantic tone. Default `'info'`. */
|
|
13
|
+
readonly tone?: BannerTone;
|
|
14
|
+
/** Main status message. */
|
|
15
|
+
readonly children: ReactNode;
|
|
16
|
+
/** Optional trailing action (e.g. a compact "Retry now" button). */
|
|
17
|
+
readonly action?: ReactNode;
|
|
18
|
+
/** When supplied, renders a trailing dismiss button. */
|
|
19
|
+
readonly onDismiss?: () => void;
|
|
20
|
+
/** Accessible label for the dismiss button. */
|
|
21
|
+
readonly dismissLabel?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function Banner({ tone, children, action, onDismiss, dismissLabel, className, role, ...rest }: BannerProps): ReactElement;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { IconButton } from '../controls/IconButton.js';
|
|
3
|
+
import { cx } from '../controls/util.js';
|
|
4
|
+
import X from '@xenosystem/elements/elements/x';
|
|
5
|
+
export function Banner({ tone = 'info', children, action, onDismiss, dismissLabel = 'Dismiss banner', className, role, ...rest }) {
|
|
6
|
+
const liveRole = role ?? (tone === 'danger' || tone === 'warn' ? 'alert' : 'status');
|
|
7
|
+
return (_jsxs("div", { className: cx('xeno-banner', className), "data-tone": tone, role: liveRole, ...rest, children: [_jsx("span", { className: "xeno-banner-dot", "aria-hidden": "true" }), _jsx("div", { className: "xeno-banner-body", children: children }), action ? _jsx("div", { className: "xeno-banner-action", children: action }) : null, onDismiss ? (_jsx(IconButton, { icon: X, size: "xs", variant: "ghost", "aria-label": dismissLabel, className: "xeno-banner-dismiss", onClick: onDismiss })) : null] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `<Toast>` & `<ToastStack>` — floating confirmation and error notifications measured from
|
|
4
|
+
* Corpus, Creator, Desktop Shell and Workshop (`--xeno-pop` shadow, 6px radius, 7px square status
|
|
5
|
+
* mark, optional action and dismiss control).
|
|
6
|
+
*/
|
|
7
|
+
export type ToastTone = 'neutral' | 'info' | 'ok' | 'warn' | 'danger';
|
|
8
|
+
export interface ToastProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'children'> {
|
|
9
|
+
/** Semantic tone. Default `'neutral'`. */
|
|
10
|
+
readonly tone?: ToastTone;
|
|
11
|
+
/** Primary short message (or title when `description` is also set). */
|
|
12
|
+
readonly title: ReactNode;
|
|
13
|
+
/** Optional secondary detail line. */
|
|
14
|
+
readonly description?: ReactNode;
|
|
15
|
+
/** Optional inline action button (e.g. "Undo", "View"). */
|
|
16
|
+
readonly action?: ReactNode;
|
|
17
|
+
/** When provided, shows a close button. */
|
|
18
|
+
readonly onDismiss?: () => void;
|
|
19
|
+
/** Accessible label for the close button. */
|
|
20
|
+
readonly dismissLabel?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function Toast({ tone, title, description, action, onDismiss, dismissLabel, className, role, ...rest }: ToastProps): ReactElement;
|
|
23
|
+
export interface ToastStackProps extends HTMLAttributes<HTMLDivElement> {
|
|
24
|
+
/** Corner placement. Default `'bottom-right'`. */
|
|
25
|
+
readonly placement?: 'bottom-right' | 'bottom-center' | 'top-right';
|
|
26
|
+
readonly children?: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
export declare function ToastStack({ placement, children, className, ...rest }: ToastStackProps): ReactElement;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { IconButton } from '../controls/IconButton.js';
|
|
3
|
+
import { cx } from '../controls/util.js';
|
|
4
|
+
import X from '@xenosystem/elements/elements/x';
|
|
5
|
+
export function Toast({ tone = 'neutral', title, description, action, onDismiss, dismissLabel = 'Dismiss notification', className, role, ...rest }) {
|
|
6
|
+
const liveRole = role ?? (tone === 'danger' ? 'alert' : 'status');
|
|
7
|
+
return (_jsxs("div", { className: cx('xeno-toast', className), "data-tone": tone, role: liveRole, ...rest, children: [_jsx("span", { className: "xeno-toast-dot", "aria-hidden": "true" }), _jsxs("div", { className: "xeno-toast-copy", children: [_jsx("div", { className: "xeno-toast-title", children: title }), description ? _jsx("div", { className: "xeno-toast-desc", children: description }) : null] }), action ? _jsx("div", { className: "xeno-toast-action", children: action }) : null, onDismiss ? (_jsx(IconButton, { icon: X, size: "xs", variant: "ghost", "aria-label": dismissLabel, className: "xeno-toast-dismiss", onClick: onDismiss })) : null] }));
|
|
8
|
+
}
|
|
9
|
+
export function ToastStack({ placement = 'bottom-right', children, className, ...rest }) {
|
|
10
|
+
return (_jsx("div", { className: cx('xeno-toast-stack', className), "data-placement": placement, "aria-live": "polite", "aria-relevant": "additions text", ...rest, children: children }));
|
|
11
|
+
}
|
package/dist/uiTree.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-Describing Live Runtime UI Tree (`window.__XENO_UI_TREE__`).
|
|
3
|
+
*
|
|
4
|
+
* Gives `/apptest`, `xeno-use`, and XENO agents a deterministic, zero-selector semantic view of
|
|
5
|
+
* every visible XENO control, menu, panel, table, and state on the page — the Web/Electron
|
|
6
|
+
* counterpart to Unreal's `XenoUseBridge`.
|
|
7
|
+
*/
|
|
8
|
+
export interface XenoUiRect {
|
|
9
|
+
readonly x: number;
|
|
10
|
+
readonly y: number;
|
|
11
|
+
readonly width: number;
|
|
12
|
+
readonly height: number;
|
|
13
|
+
}
|
|
14
|
+
export interface XenoUiNode {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly unit: string;
|
|
17
|
+
readonly role: string;
|
|
18
|
+
readonly label: string;
|
|
19
|
+
readonly disabled: boolean;
|
|
20
|
+
readonly selected?: boolean | 'mixed';
|
|
21
|
+
readonly expanded?: boolean;
|
|
22
|
+
readonly sort?: string;
|
|
23
|
+
readonly tone?: string;
|
|
24
|
+
readonly rect: XenoUiRect;
|
|
25
|
+
readonly actions: readonly ('click' | 'focus')[];
|
|
26
|
+
}
|
|
27
|
+
export interface XenoUiTreeSnapshot {
|
|
28
|
+
readonly version: 1;
|
|
29
|
+
readonly capturedAt: string;
|
|
30
|
+
readonly theme: string;
|
|
31
|
+
readonly chrome: string;
|
|
32
|
+
readonly density: string;
|
|
33
|
+
readonly viewport: {
|
|
34
|
+
readonly width: number;
|
|
35
|
+
readonly height: number;
|
|
36
|
+
};
|
|
37
|
+
readonly nodeCount: number;
|
|
38
|
+
readonly nodes: readonly XenoUiNode[];
|
|
39
|
+
}
|
|
40
|
+
export interface XenoUiBridge {
|
|
41
|
+
readonly snapshot: () => XenoUiTreeSnapshot;
|
|
42
|
+
readonly findByLabel: (query: string) => readonly XenoUiNode[];
|
|
43
|
+
readonly findByUnit: (unit: string) => readonly XenoUiNode[];
|
|
44
|
+
readonly click: (nodeId: string) => boolean;
|
|
45
|
+
readonly focus: (nodeId: string) => boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Capture a deterministic semantic UI tree snapshot from `root` (defaults to `document.body`). */
|
|
48
|
+
export declare function snapshotXenoUiTree(root?: HTMLElement | null): XenoUiTreeSnapshot;
|
|
49
|
+
/**
|
|
50
|
+
* Mount `window.__XENO_UI_TREE__` for live agent & `/apptest` introspection and action dispatch.
|
|
51
|
+
* Returns an uninstall cleanup function.
|
|
52
|
+
*/
|
|
53
|
+
export declare function installXenoUiTree(root?: HTMLElement | null): () => void;
|
package/dist/uiTree.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-Describing Live Runtime UI Tree (`window.__XENO_UI_TREE__`).
|
|
3
|
+
*
|
|
4
|
+
* Gives `/apptest`, `xeno-use`, and XENO agents a deterministic, zero-selector semantic view of
|
|
5
|
+
* every visible XENO control, menu, panel, table, and state on the page — the Web/Electron
|
|
6
|
+
* counterpart to Unreal's `XenoUseBridge`.
|
|
7
|
+
*/
|
|
8
|
+
const INTERACTIVE_SELECTOR = [
|
|
9
|
+
'button',
|
|
10
|
+
'a[href]',
|
|
11
|
+
'input',
|
|
12
|
+
'textarea',
|
|
13
|
+
'select',
|
|
14
|
+
'[role="button"]',
|
|
15
|
+
'[role="menuitem"]',
|
|
16
|
+
'[role="menuitemcheckbox"]',
|
|
17
|
+
'[role="tab"]',
|
|
18
|
+
'[role="radio"]',
|
|
19
|
+
'[role="checkbox"]',
|
|
20
|
+
'[role="switch"]',
|
|
21
|
+
'[role="option"]',
|
|
22
|
+
'[role="dialog"]',
|
|
23
|
+
'[role="menu"]',
|
|
24
|
+
'[role="status"]',
|
|
25
|
+
'[role="alert"]',
|
|
26
|
+
'.xeno-panel',
|
|
27
|
+
'.xeno-card',
|
|
28
|
+
'.xeno-table',
|
|
29
|
+
'.xc-inspector-pane',
|
|
30
|
+
'.xc-nav-rail',
|
|
31
|
+
].join(', ');
|
|
32
|
+
function inferUnit(el) {
|
|
33
|
+
const explicit = el.getAttribute('data-xeno-unit');
|
|
34
|
+
if (explicit)
|
|
35
|
+
return explicit;
|
|
36
|
+
for (const cls of Array.from(el.classList)) {
|
|
37
|
+
if ((cls.startsWith('xeno-') || cls.startsWith('xc-')) && !cls.includes('--')) {
|
|
38
|
+
return cls;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return el.getAttribute('role') ?? el.tagName.toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
function inferLabel(el) {
|
|
44
|
+
const aria = el.getAttribute('aria-label');
|
|
45
|
+
if (aria)
|
|
46
|
+
return aria.trim();
|
|
47
|
+
const labelledBy = el.getAttribute('aria-labelledby');
|
|
48
|
+
if (labelledBy) {
|
|
49
|
+
const text = labelledBy
|
|
50
|
+
.split(/\s+/)
|
|
51
|
+
.map((id) => document.getElementById(id)?.textContent?.trim() ?? '')
|
|
52
|
+
.filter(Boolean)
|
|
53
|
+
.join(' ');
|
|
54
|
+
if (text)
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
58
|
+
return (el.placeholder || el.name || el.value || '').trim();
|
|
59
|
+
}
|
|
60
|
+
const title = el.getAttribute('title');
|
|
61
|
+
if (title)
|
|
62
|
+
return title.trim();
|
|
63
|
+
return (el.textContent ?? '').replace(/\s+/g, ' ').trim().slice(0, 120);
|
|
64
|
+
}
|
|
65
|
+
function isVisible(el) {
|
|
66
|
+
if (el.hidden || el.getAttribute('aria-hidden') === 'true')
|
|
67
|
+
return false;
|
|
68
|
+
const style = typeof window !== 'undefined' ? window.getComputedStyle(el) : null;
|
|
69
|
+
if (style && (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0')) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/** Capture a deterministic semantic UI tree snapshot from `root` (defaults to `document.body`). */
|
|
75
|
+
export function snapshotXenoUiTree(root) {
|
|
76
|
+
const container = root ?? (typeof document !== 'undefined' ? document.body : null);
|
|
77
|
+
const scopeEl = container?.querySelector('.xeno') ?? (container?.closest('.xeno') ?? null);
|
|
78
|
+
const chromeEl = scopeEl?.closest('[data-chrome]') ?? container?.querySelector('[data-chrome]');
|
|
79
|
+
const densityEl = scopeEl?.closest('[data-density]') ?? container?.querySelector('[data-density]');
|
|
80
|
+
const nodes = [];
|
|
81
|
+
if (container) {
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
const els = Array.from(container.querySelectorAll(INTERACTIVE_SELECTOR));
|
|
84
|
+
let idx = 0;
|
|
85
|
+
for (const el of els) {
|
|
86
|
+
if (seen.has(el) || !isVisible(el))
|
|
87
|
+
continue;
|
|
88
|
+
seen.add(el);
|
|
89
|
+
const r = el.getBoundingClientRect();
|
|
90
|
+
const role = el.getAttribute('role') ?? el.tagName.toLowerCase();
|
|
91
|
+
const label = inferLabel(el);
|
|
92
|
+
const unit = inferUnit(el);
|
|
93
|
+
const id = el.getAttribute('data-xeno-node-id') ?? el.getAttribute('data-testid') ?? `${unit}#${++idx}`;
|
|
94
|
+
el.setAttribute('data-xeno-node-id', id);
|
|
95
|
+
const ariaSelected = el.getAttribute('aria-selected') ?? el.getAttribute('aria-checked') ?? el.getAttribute('aria-current');
|
|
96
|
+
const selected = ariaSelected === 'mixed'
|
|
97
|
+
? 'mixed'
|
|
98
|
+
: ariaSelected === 'true' || ariaSelected === 'page' || el.getAttribute('data-selection') === 'on'
|
|
99
|
+
? true
|
|
100
|
+
: ariaSelected === 'false' || el.getAttribute('data-selection') === 'off'
|
|
101
|
+
? false
|
|
102
|
+
: undefined;
|
|
103
|
+
const ariaExpanded = el.getAttribute('aria-expanded');
|
|
104
|
+
const expanded = ariaExpanded === 'true' ? true : ariaExpanded === 'false' ? false : undefined;
|
|
105
|
+
const sort = el.getAttribute('aria-sort') ?? undefined;
|
|
106
|
+
const tone = el.getAttribute('data-tone') ?? undefined;
|
|
107
|
+
const disabled = el.disabled === true ||
|
|
108
|
+
el.getAttribute('aria-disabled') === 'true' ||
|
|
109
|
+
el.getAttribute('data-availability') === 'disabled';
|
|
110
|
+
const isActionable = el.tagName === 'BUTTON' ||
|
|
111
|
+
el.tagName === 'A' ||
|
|
112
|
+
el.tagName === 'INPUT' ||
|
|
113
|
+
el.tagName === 'SELECT' ||
|
|
114
|
+
el.tagName === 'TEXTAREA' ||
|
|
115
|
+
role === 'menuitem' ||
|
|
116
|
+
role === 'tab' ||
|
|
117
|
+
role === 'radio' ||
|
|
118
|
+
role === 'checkbox' ||
|
|
119
|
+
role === 'switch' ||
|
|
120
|
+
role === 'button';
|
|
121
|
+
nodes.push({
|
|
122
|
+
id,
|
|
123
|
+
unit,
|
|
124
|
+
role,
|
|
125
|
+
label,
|
|
126
|
+
disabled,
|
|
127
|
+
...(selected !== undefined ? { selected } : {}),
|
|
128
|
+
...(expanded !== undefined ? { expanded } : {}),
|
|
129
|
+
...(sort ? { sort } : {}),
|
|
130
|
+
...(tone ? { tone } : {}),
|
|
131
|
+
rect: {
|
|
132
|
+
x: Math.round(r.left),
|
|
133
|
+
y: Math.round(r.top),
|
|
134
|
+
width: Math.round(r.width),
|
|
135
|
+
height: Math.round(r.height),
|
|
136
|
+
},
|
|
137
|
+
actions: isActionable && !disabled ? ['click', 'focus'] : ['focus'],
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
version: 1,
|
|
143
|
+
capturedAt: new Date().toISOString(),
|
|
144
|
+
theme: scopeEl?.getAttribute('data-theme') ?? 'dark',
|
|
145
|
+
chrome: chromeEl?.getAttribute('data-chrome') ?? 'separated',
|
|
146
|
+
density: densityEl?.getAttribute('data-density') ?? 'default',
|
|
147
|
+
viewport: {
|
|
148
|
+
width: typeof window !== 'undefined' ? window.innerWidth : 0,
|
|
149
|
+
height: typeof window !== 'undefined' ? window.innerHeight : 0,
|
|
150
|
+
},
|
|
151
|
+
nodeCount: nodes.length,
|
|
152
|
+
nodes,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Mount `window.__XENO_UI_TREE__` for live agent & `/apptest` introspection and action dispatch.
|
|
157
|
+
* Returns an uninstall cleanup function.
|
|
158
|
+
*/
|
|
159
|
+
export function installXenoUiTree(root) {
|
|
160
|
+
if (typeof window === 'undefined')
|
|
161
|
+
return () => { };
|
|
162
|
+
const targetRoot = () => root ?? document.body;
|
|
163
|
+
const escapeAttr = (v) => typeof CSS !== 'undefined' && typeof CSS.escape === 'function' ? CSS.escape(v) : v.replace(/["\\]/g, '\\$&');
|
|
164
|
+
const bridge = {
|
|
165
|
+
snapshot: () => snapshotXenoUiTree(targetRoot()),
|
|
166
|
+
findByLabel: (query) => {
|
|
167
|
+
const q = query.trim().toLowerCase();
|
|
168
|
+
return snapshotXenoUiTree(targetRoot()).nodes.filter((n) => n.label.toLowerCase().includes(q));
|
|
169
|
+
},
|
|
170
|
+
findByUnit: (unit) => {
|
|
171
|
+
const q = unit.trim().toLowerCase();
|
|
172
|
+
return snapshotXenoUiTree(targetRoot()).nodes.filter((n) => n.unit.toLowerCase().includes(q));
|
|
173
|
+
},
|
|
174
|
+
click: (nodeId) => {
|
|
175
|
+
snapshotXenoUiTree(targetRoot());
|
|
176
|
+
const el = document.querySelector(`[data-xeno-node-id="${escapeAttr(nodeId)}"]`);
|
|
177
|
+
if (!el)
|
|
178
|
+
return false;
|
|
179
|
+
el.click();
|
|
180
|
+
return true;
|
|
181
|
+
},
|
|
182
|
+
focus: (nodeId) => {
|
|
183
|
+
snapshotXenoUiTree(targetRoot());
|
|
184
|
+
const el = document.querySelector(`[data-xeno-node-id="${escapeAttr(nodeId)}"]`);
|
|
185
|
+
if (!el)
|
|
186
|
+
return false;
|
|
187
|
+
el.focus();
|
|
188
|
+
return true;
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
window.__XENO_UI_TREE__ = bridge;
|
|
192
|
+
return () => {
|
|
193
|
+
const win = window;
|
|
194
|
+
if (win.__XENO_UI_TREE__ === bridge)
|
|
195
|
+
delete win.__XENO_UI_TREE__;
|
|
196
|
+
};
|
|
197
|
+
}
|
package/dist/useDialog.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface UseDialogOptions<T extends HTMLElement> {
|
|
|
29
29
|
readonly panelRef?: MutableRefObject<T | null>;
|
|
30
30
|
/** Lock the page scroll behind the dialog. Default `true`. */
|
|
31
31
|
readonly lockScroll?: boolean;
|
|
32
|
+
/** Mark background siblings outside the dialog `inert` while open (WAI-ARIA APG). Default `true`. */
|
|
33
|
+
readonly inertBackground?: boolean;
|
|
32
34
|
}
|
|
33
35
|
export interface UseDialogResult<T extends HTMLElement> {
|
|
34
36
|
/** The dialog panel. `panelProps` already carries it. */
|
|
@@ -42,4 +44,4 @@ export interface UseDialogResult<T extends HTMLElement> {
|
|
|
42
44
|
readonly onKeyDown: (e: ReactKeyboardEvent<T>) => void;
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
|
-
export declare function useDialog<T extends HTMLElement = HTMLDivElement>({ open, onClose, panelRef: providedRef, lockScroll, }: UseDialogOptions<T>): UseDialogResult<T>;
|
|
47
|
+
export declare function useDialog<T extends HTMLElement = HTMLDivElement>({ open, onClose, panelRef: providedRef, lockScroll, inertBackground, }: UseDialogOptions<T>): UseDialogResult<T>;
|
package/dist/useDialog.js
CHANGED
|
@@ -23,7 +23,35 @@ const unlockPageScroll = () => {
|
|
|
23
23
|
if (scrollLocks === 0)
|
|
24
24
|
document.body.style.overflow = scrollPrevious;
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
/** Refcounted `inert` locks per element so stacked dialogs never clear each other's background guard. */
|
|
27
|
+
const inertCounts = new WeakMap();
|
|
28
|
+
const inertOriginal = new WeakMap();
|
|
29
|
+
function acquireInert(panel) {
|
|
30
|
+
const locked = [];
|
|
31
|
+
for (const child of Array.from(document.body.children)) {
|
|
32
|
+
if (!(child instanceof HTMLElement))
|
|
33
|
+
continue;
|
|
34
|
+
if (child.contains(panel))
|
|
35
|
+
continue;
|
|
36
|
+
const prev = inertCounts.get(child) ?? 0;
|
|
37
|
+
if (prev === 0) {
|
|
38
|
+
inertOriginal.set(child, child.hasAttribute('inert'));
|
|
39
|
+
child.setAttribute('inert', '');
|
|
40
|
+
}
|
|
41
|
+
inertCounts.set(child, prev + 1);
|
|
42
|
+
locked.push(child);
|
|
43
|
+
}
|
|
44
|
+
return () => {
|
|
45
|
+
for (const child of locked) {
|
|
46
|
+
const next = Math.max(0, (inertCounts.get(child) ?? 1) - 1);
|
|
47
|
+
inertCounts.set(child, next);
|
|
48
|
+
if (next === 0 && !inertOriginal.get(child)) {
|
|
49
|
+
child.removeAttribute('inert');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function useDialog({ open, onClose, panelRef: providedRef, lockScroll = true, inertBackground = true, }) {
|
|
27
55
|
const ownRef = useRef(null);
|
|
28
56
|
const panelRef = providedRef ?? ownRef;
|
|
29
57
|
const restoreFocus = useRef(null);
|
|
@@ -51,6 +79,14 @@ export function useDialog({ open, onClose, panelRef: providedRef, lockScroll = t
|
|
|
51
79
|
lockPageScroll();
|
|
52
80
|
return unlockPageScroll;
|
|
53
81
|
}, [open, lockScroll]);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!open || !inertBackground)
|
|
84
|
+
return;
|
|
85
|
+
const panel = panelRef.current;
|
|
86
|
+
if (!panel || typeof document === 'undefined')
|
|
87
|
+
return;
|
|
88
|
+
return acquireInert(panel);
|
|
89
|
+
}, [open, inertBackground, panelRef]);
|
|
54
90
|
/**
|
|
55
91
|
* Focus in when the panel APPEARS, not when `open` turns true.
|
|
56
92
|
*
|
package/dist/useMenu.js
CHANGED
|
@@ -5,6 +5,14 @@ export function useMenu({ open, onClose, menuRef: providedRef, itemSelector = DE
|
|
|
5
5
|
const menuRef = providedRef ?? ownRef;
|
|
6
6
|
const openRef = useRef(open);
|
|
7
7
|
openRef.current = open;
|
|
8
|
+
const typeaheadBuf = useRef('');
|
|
9
|
+
const typeaheadTimer = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
return () => {
|
|
12
|
+
if (typeaheadTimer.current !== null)
|
|
13
|
+
clearTimeout(typeaheadTimer.current);
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
8
16
|
const items = useCallback(() => {
|
|
9
17
|
const root = menuRef.current;
|
|
10
18
|
if (!root)
|
|
@@ -86,8 +94,30 @@ export function useMenu({ open, onClose, menuRef: providedRef, itemSelector = DE
|
|
|
86
94
|
e.preventDefault();
|
|
87
95
|
onClose?.();
|
|
88
96
|
break;
|
|
89
|
-
default:
|
|
97
|
+
default: {
|
|
98
|
+
// WAI-ARIA APG 1.2 character type-ahead: printable keys jump to the next matching enabled item.
|
|
99
|
+
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && e.key !== ' ') {
|
|
100
|
+
if (typeaheadTimer.current !== null)
|
|
101
|
+
clearTimeout(typeaheadTimer.current);
|
|
102
|
+
typeaheadBuf.current += e.key.toLowerCase();
|
|
103
|
+
typeaheadTimer.current = setTimeout(() => {
|
|
104
|
+
typeaheadBuf.current = '';
|
|
105
|
+
typeaheadTimer.current = null;
|
|
106
|
+
}, 500);
|
|
107
|
+
const prefix = typeaheadBuf.current;
|
|
108
|
+
const start = current >= 0 ? current : -1;
|
|
109
|
+
for (let offset = 1; offset <= list.length; offset += 1) {
|
|
110
|
+
const idx = (start + offset) % list.length;
|
|
111
|
+
const label = (list[idx]?.textContent ?? '').trim().toLowerCase();
|
|
112
|
+
if (label.startsWith(prefix)) {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
list[idx]?.focus();
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
90
119
|
break;
|
|
120
|
+
}
|
|
91
121
|
}
|
|
92
122
|
}, [items, focusAt, onClose]);
|
|
93
123
|
const onClick = useCallback((e) => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ToastTone } from './status/Toast.js';
|
|
2
|
+
/**
|
|
3
|
+
* Managed Toast Queue with auto-dismiss, hover-to-pause, bounded stack size, and first-class
|
|
4
|
+
* optimistic `undo()` callbacks — ready to render directly into `<ToastStack>`.
|
|
5
|
+
*/
|
|
6
|
+
export interface QueuedToast {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly title: string;
|
|
9
|
+
readonly description?: string;
|
|
10
|
+
readonly tone?: ToastTone;
|
|
11
|
+
readonly durationMs?: number;
|
|
12
|
+
readonly undoLabel?: string;
|
|
13
|
+
readonly onUndo?: () => void;
|
|
14
|
+
}
|
|
15
|
+
export interface PushToastInput extends Omit<QueuedToast, 'id'> {
|
|
16
|
+
readonly id?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface UseToastQueueResult {
|
|
19
|
+
readonly toasts: readonly QueuedToast[];
|
|
20
|
+
readonly push: (toast: PushToastInput) => string;
|
|
21
|
+
readonly dismiss: (id: string) => void;
|
|
22
|
+
readonly pause: (id: string) => void;
|
|
23
|
+
readonly resume: (id: string) => void;
|
|
24
|
+
readonly clear: () => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function useToastQueue(options?: {
|
|
27
|
+
readonly maxVisible?: number;
|
|
28
|
+
readonly defaultDurationMs?: number;
|
|
29
|
+
}): UseToastQueueResult;
|