reifyui 0.11.1 → 0.13.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/README.md +31 -2
- package/dist/chart.js +2 -0
- package/dist/chart.js.map +1 -1
- package/dist/chunk-EL2DHWOH.js +1710 -0
- package/dist/chunk-EL2DHWOH.js.map +1 -0
- package/dist/chunk-J633KV57.js +41 -0
- package/dist/chunk-J633KV57.js.map +1 -0
- package/dist/chunk-J7SECRIG.js +295 -0
- package/dist/chunk-J7SECRIG.js.map +1 -0
- package/dist/chunk-PIRPLH2Z.js +231 -0
- package/dist/chunk-PIRPLH2Z.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-UKG4Z6QK.js +130 -0
- package/dist/chunk-UKG4Z6QK.js.map +1 -0
- package/dist/chunk-ZYWE47EO.js +19 -0
- package/dist/chunk-ZYWE47EO.js.map +1 -0
- package/dist/collab.cjs +169 -0
- package/dist/collab.cjs.map +1 -0
- package/dist/collab.d.ts +30 -0
- package/dist/collab.js +18 -0
- package/dist/collab.js.map +1 -0
- package/dist/graph.cjs +2244 -0
- package/dist/graph.cjs.map +1 -0
- package/dist/graph.d.ts +41 -0
- package/dist/graph.js +1870 -0
- package/dist/graph.js.map +1 -0
- package/dist/harness.js +1 -0
- package/dist/harness.js.map +1 -1
- package/dist/index.cjs +2044 -867
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +20 -2
- package/dist/index.js +892 -1686
- package/dist/index.js.map +1 -1
- package/dist/sheet-doc.cjs +235 -0
- package/dist/sheet-doc.cjs.map +1 -0
- package/dist/sheet-doc.d.ts +16 -0
- package/dist/sheet-doc.js +20 -0
- package/dist/sheet-doc.js.map +1 -0
- package/dist/sheet.cjs +2322 -0
- package/dist/sheet.cjs.map +1 -0
- package/dist/sheet.d.ts +23 -0
- package/dist/sheet.js +237 -0
- package/dist/sheet.js.map +1 -0
- package/dist/slides.js +2 -0
- package/dist/slides.js.map +1 -1
- package/package.json +35 -3
- package/src/auth/client.js +4 -2
- package/src/collab/colors.js +18 -0
- package/src/collab/index.d.ts +30 -0
- package/src/collab/index.js +8 -0
- package/src/collab/keepAlive.js +34 -0
- package/src/collab/useLiveDoc.js +76 -0
- package/src/components/CascadeMenu.jsx +216 -0
- package/src/components/ChatMessages.jsx +30 -9
- package/src/components/Chip.jsx +37 -10
- package/src/components/Composer.jsx +80 -2
- package/src/components/resizable.jsx +82 -12
- package/src/graph/ConnectPane.jsx +634 -0
- package/src/graph/ConnectToolDetail.jsx +565 -0
- package/src/graph/LogsPane.jsx +328 -0
- package/src/graph/Skeleton.jsx +13 -0
- package/src/graph/draft.js +108 -0
- package/src/graph/format.js +37 -0
- package/src/graph/index.d.ts +41 -0
- package/src/graph/index.js +14 -0
- package/src/graph/useGraphCollab.js +299 -0
- package/src/graph/vgraph.js +215 -0
- package/src/index.d.ts +20 -2
- package/src/index.js +6 -1
- package/src/mention/MentionInput.jsx +420 -0
- package/src/mention/mentionModel.js +177 -0
- package/src/sheet/RunStrip.jsx +57 -0
- package/src/sheet/SheetGrid.jsx +444 -353
- package/src/sheet/doc.d.ts +16 -0
- package/src/sheet/index.d.ts +23 -0
- package/src/sheet/index.js +10 -0
- package/src/sheet/sheetDoc.js +203 -0
- package/src/sheet/useSheetCollab.js +102 -0
- package/src/sheet/useSheetRun.js +80 -0
- package/styles/chat.css +47 -5
- package/styles/chip.css +36 -0
- package/styles/graph.css +395 -0
- package/styles/mention.css +79 -0
- package/styles/sheet.css +156 -112
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// reifyui/collab — public type surface (hand-authored; the source is plain-ESM React).
|
|
2
|
+
import type * as Y from 'yjs';
|
|
3
|
+
|
|
4
|
+
export interface LiveDocOptions {
|
|
5
|
+
/** The collaboration server (Hocuspocus) URL. */
|
|
6
|
+
url: string;
|
|
7
|
+
/** The document name; one document per resource. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** A bearer ticket for the document, as the host's collaboration service issues it. */
|
|
10
|
+
token?: string;
|
|
11
|
+
/** Called once the document is synced; `doc` is the shared Y.Doc. */
|
|
12
|
+
onSynced?(doc: Y.Doc): void;
|
|
13
|
+
[k: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface LiveDoc {
|
|
16
|
+
doc: Y.Doc | null;
|
|
17
|
+
provider: unknown;
|
|
18
|
+
synced: boolean;
|
|
19
|
+
status: string;
|
|
20
|
+
awareness: unknown;
|
|
21
|
+
[k: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** One live-document core: provider lifecycle, sync state, awareness, for any live surface. */
|
|
24
|
+
export function useLiveDoc(options: LiveDocOptions | null): LiveDoc;
|
|
25
|
+
/** Keep awareness renewed from a worker clock so a hidden tab's presence never lapses. */
|
|
26
|
+
export function keepPresenceAlive(provider: unknown, periodMs?: number): () => void;
|
|
27
|
+
export const PEER_PALETTE: readonly string[];
|
|
28
|
+
/** The palette color for a peer id, stable across every host. */
|
|
29
|
+
export function peerColor(id: string | number): string;
|
|
30
|
+
export function withAlpha(color: string, alpha: number): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// reifyui/collab — one live-document core for any collaborative surface.
|
|
2
|
+
//
|
|
3
|
+
// A separate entry because it pulls in yjs and the Hocuspocus provider: importing a Button
|
|
4
|
+
// from the root never costs a CRDT. Presence colors and the worker-clock keep-alive ride along
|
|
5
|
+
// (they have no dependencies) so a host wires collaboration from one import.
|
|
6
|
+
export { useLiveDoc } from './useLiveDoc.js';
|
|
7
|
+
export { keepPresenceAlive } from './keepAlive.js';
|
|
8
|
+
export { PEER_PALETTE, peerColor, withAlpha } from './colors.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// keepPresenceAlive — renew this client's awareness on a clock the browser
|
|
2
|
+
// does not throttle.
|
|
3
|
+
//
|
|
4
|
+
// Yjs awareness renews a client's own state every 15s on a main-thread timer
|
|
5
|
+
// and every other client drops a state it has not heard from for 30s. A tab
|
|
6
|
+
// in the background gets its timers throttled to once a minute, so its
|
|
7
|
+
// presence expires for everyone else and reappears when the timer finally
|
|
8
|
+
// fires: a flag that flickers every minute on every other screen. Worker
|
|
9
|
+
// clocks are not throttled, so the renewal runs there and the main thread
|
|
10
|
+
// only relays it. One helper for every live document (sheets, canvases,
|
|
11
|
+
// docs).
|
|
12
|
+
const TICK_MS = 10_000;
|
|
13
|
+
|
|
14
|
+
export function keepPresenceAlive(awareness, intervalMs = TICK_MS) {
|
|
15
|
+
if (!awareness || typeof Worker === 'undefined' || typeof Blob === 'undefined') return () => {};
|
|
16
|
+
let url = '';
|
|
17
|
+
let worker = null;
|
|
18
|
+
try {
|
|
19
|
+
url = URL.createObjectURL(new Blob([`setInterval(() => postMessage(0), ${Math.max(1000, intervalMs)});`],
|
|
20
|
+
{ type: 'text/javascript' }));
|
|
21
|
+
worker = new Worker(url);
|
|
22
|
+
} catch {
|
|
23
|
+
if (url) URL.revokeObjectURL(url);
|
|
24
|
+
return () => {};
|
|
25
|
+
}
|
|
26
|
+
worker.onmessage = () => {
|
|
27
|
+
const state = awareness.getLocalState();
|
|
28
|
+
if (state !== null && state !== undefined) awareness.setLocalState(state); // same state, new clock
|
|
29
|
+
};
|
|
30
|
+
return () => {
|
|
31
|
+
worker.terminate();
|
|
32
|
+
URL.revokeObjectURL(url);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// useLiveDoc — the one provider lifecycle for every live document on the
|
|
2
|
+
// platform's realtime sidecar: a sheet, a graph canvas, a doc. It takes a
|
|
3
|
+
// host-authenticated ticket ({url, doc, token}), connects, re-tickets when the
|
|
4
|
+
// token ages out, retries quietly when realtime is unreachable, and exposes
|
|
5
|
+
// the document once synced, the awareness states of everyone in it, and one
|
|
6
|
+
// field for what THIS person publishes (re-applied on every reconnect).
|
|
7
|
+
// Surfaces build their own shape on top: what to read from the document and
|
|
8
|
+
// what presence means for them.
|
|
9
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
+
import { HocuspocusProvider } from '@hocuspocus/provider';
|
|
11
|
+
import { keepPresenceAlive } from './keepAlive.js';
|
|
12
|
+
|
|
13
|
+
export function useLiveDoc(resourceId, { fetchTicket, field = 'presence' } = {}) {
|
|
14
|
+
const [doc, setDoc] = useState(null); // the Y.Doc, once synced
|
|
15
|
+
const [provider, setProvider] = useState(null);
|
|
16
|
+
const [ready, setReady] = useState(false);
|
|
17
|
+
const [states, setStates] = useState([]); // [{clientId, ...awareness}]
|
|
18
|
+
const [selfClientId, setSelfClientId] = useState(null);
|
|
19
|
+
const providerRef = useRef(null);
|
|
20
|
+
const lastRef = useRef(null); // this person's last published value
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!resourceId || typeof fetchTicket !== 'function') return undefined;
|
|
24
|
+
let dead = false;
|
|
25
|
+
let current = null;
|
|
26
|
+
let retry = null;
|
|
27
|
+
let stopKeepAlive = () => {};
|
|
28
|
+
|
|
29
|
+
async function connect() {
|
|
30
|
+
let ticket = null;
|
|
31
|
+
try { ticket = await fetchTicket(resourceId); } catch { ticket = null; }
|
|
32
|
+
if (dead) return;
|
|
33
|
+
if (!ticket) { retry = window.setTimeout(connect, 60_000); return; } // realtime unreachable: try later
|
|
34
|
+
current = new HocuspocusProvider({
|
|
35
|
+
url: ticket.url, name: ticket.doc, parameters: { cg_token: ticket.token },
|
|
36
|
+
onAuthenticationFailed: () => {
|
|
37
|
+
// The token aged out (or access was revoked): tear down and re-ticket.
|
|
38
|
+
stopKeepAlive();
|
|
39
|
+
try { current.destroy(); } catch { /* down */ }
|
|
40
|
+
if (!dead) retry = window.setTimeout(connect, 5_000);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
stopKeepAlive = keepPresenceAlive(current.awareness);
|
|
44
|
+
providerRef.current = current;
|
|
45
|
+
setProvider(current);
|
|
46
|
+
if (lastRef.current) { try { current.setAwarenessField(field, lastRef.current); } catch { /* not yet */ } }
|
|
47
|
+
current.on('awarenessUpdate', ({ states: next }) => { if (!dead) setStates(next || []); });
|
|
48
|
+
current.on('synced', () => {
|
|
49
|
+
if (dead) return;
|
|
50
|
+
setSelfClientId(current.awareness ? current.awareness.clientID : null);
|
|
51
|
+
setDoc(current.document);
|
|
52
|
+
setReady(true);
|
|
53
|
+
});
|
|
54
|
+
current.on('status', ({ status }) => { if (!dead && status === 'disconnected') setReady(false); });
|
|
55
|
+
}
|
|
56
|
+
connect();
|
|
57
|
+
return () => {
|
|
58
|
+
dead = true; window.clearTimeout(retry);
|
|
59
|
+
stopKeepAlive();
|
|
60
|
+
if (current) { try { current.destroy(); } catch { /* closing */ } }
|
|
61
|
+
providerRef.current = null;
|
|
62
|
+
setProvider(null); setDoc(null); setReady(false); setStates([]); setSelfClientId(null);
|
|
63
|
+
};
|
|
64
|
+
// fetchTicket is a host constant; re-subscribing on its identity would reconnect every render.
|
|
65
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
+
}, [resourceId]);
|
|
67
|
+
|
|
68
|
+
/** Publish what this person is doing; kept and re-applied across reconnects. */
|
|
69
|
+
const setAwareness = useCallback((value) => {
|
|
70
|
+
lastRef.current = value;
|
|
71
|
+
const p = providerRef.current;
|
|
72
|
+
if (p) { try { p.setAwarenessField(field, value); } catch { /* closing */ } }
|
|
73
|
+
}, [field]);
|
|
74
|
+
|
|
75
|
+
return { doc, provider, ready, states, selfClientId, setAwareness };
|
|
76
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// CascadeMenu — a two-level choice in one panel. The first column lists the things you can pick;
|
|
2
|
+
// the second lists the options of the one you pressed or arrowed onto; a press in the second
|
|
3
|
+
// column IS the pick. A menu with a submenu, laid flat: both levels stay visible, so
|
|
4
|
+
// nothing has to be hovered just right to stay open, and the reader sees "harness, then model"
|
|
5
|
+
// as one gesture instead of a modal with a filter, a list, and a second control afterwards.
|
|
6
|
+
//
|
|
7
|
+
// It rides on Popover, so it portals to the body, flips to the side with room, clamps to the
|
|
8
|
+
// viewport and scrolls inside the height it was given — the panel never runs off the screen.
|
|
9
|
+
// Under `stackBelow` px of viewport the two columns cannot sit side by side, so the same panel
|
|
10
|
+
// walks them as steps: pick in the first, the second replaces it with a way back.
|
|
11
|
+
//
|
|
12
|
+
// Choosing in the first column is a press or a focus, NOT a hover. A hover-driven second column
|
|
13
|
+
// is the classic submenu trap: the pointer crossing other rows on its diagonal way to an option
|
|
14
|
+
// swaps the options out from under it. Here the first column changes only on click or on
|
|
15
|
+
// keyboard focus, so the path to an option is never a race.
|
|
16
|
+
//
|
|
17
|
+
// Keyboard: ↑↓ move within a column, → enters the options of the chosen item, ← returns to it,
|
|
18
|
+
// Enter/Space press (native buttons), Escape closes (Popover). Focus lands inside on open and
|
|
19
|
+
// goes back to the anchor on close.
|
|
20
|
+
import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
21
|
+
import { Popover } from './Popover.jsx';
|
|
22
|
+
import { SearchField } from './SearchField.jsx';
|
|
23
|
+
import { Chevron, Svg } from './icons.jsx';
|
|
24
|
+
|
|
25
|
+
const Tick = () => <Svg s={14}><path d="M20 6 9 17l-5-5" /></Svg>;
|
|
26
|
+
|
|
27
|
+
const FILTER_PAST = 8; // 'auto': a filter field appears once the first column is longer than this
|
|
28
|
+
|
|
29
|
+
const itemsOf = (groups) => groups.flatMap((g) => g.items);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* open, anchorRef, onClose as Popover
|
|
33
|
+
* label accessible name of the panel
|
|
34
|
+
* groups [{ label, items: [{ id, label, icon, note }] }] — the first column, grouped;
|
|
35
|
+
* a note is a small trailing word, e.g. 'fixed' on the one item a locked
|
|
36
|
+
* chooser offers
|
|
37
|
+
* optionsOf(item) -> [{ id, label, disabled, note, badge }] — the second column for one item;
|
|
38
|
+
* a badge is a node at the row's end, e.g. which key serves a model, and
|
|
39
|
+
* is what gives way (its own ellipsis) when the row is narrow
|
|
40
|
+
* optionsFooter a node under the options, e.g. what the options without a badge mean
|
|
41
|
+
* onPick(item, option)
|
|
42
|
+
* value { item, option } — the current pair: its item opens first and its option
|
|
43
|
+
* carries a check, so an editor of an existing choice shows where it stands
|
|
44
|
+
* filter 'auto' (default) | true | false — a filter field over the first column
|
|
45
|
+
* filterPlaceholder default 'Filter'
|
|
46
|
+
* emptyText first column has no match; noOptionsText: the item offers nothing
|
|
47
|
+
* optionsLabel accessible name of the second column, default 'Options'
|
|
48
|
+
* backLabel the way back in stacked mode, default 'Back'
|
|
49
|
+
* width side-by-side width, default 520; stackBelow: viewport px, default 560
|
|
50
|
+
*/
|
|
51
|
+
export function CascadeMenu(props) {
|
|
52
|
+
const {
|
|
53
|
+
open, anchorRef, onClose, label,
|
|
54
|
+
groups = [], optionsOf, onPick,
|
|
55
|
+
filter = 'auto', filterPlaceholder = 'Filter',
|
|
56
|
+
emptyText = 'Nothing matches.', noOptionsText = 'Nothing to choose here.',
|
|
57
|
+
optionsLabel = 'Options', backLabel = 'Back', optionsFooter,
|
|
58
|
+
width = 520, stackBelow = 560, className, value,
|
|
59
|
+
} = props;
|
|
60
|
+
|
|
61
|
+
const rootRef = useRef(null);
|
|
62
|
+
const [q, setQ] = useState('');
|
|
63
|
+
const [activeId, setActiveId] = useState(null);
|
|
64
|
+
const [stage, setStage] = useState('items');
|
|
65
|
+
const [stacked, setStacked] = useState(false);
|
|
66
|
+
|
|
67
|
+
// Filtering happens on the label people read, nothing else.
|
|
68
|
+
const visible = useMemo(() => {
|
|
69
|
+
const needle = q.trim().toLowerCase();
|
|
70
|
+
if (!needle) return groups.filter((g) => g.items.length > 0);
|
|
71
|
+
return groups
|
|
72
|
+
.map((g) => ({ ...g, items: g.items.filter((it) => String(it.label).toLowerCase().includes(needle)) }))
|
|
73
|
+
.filter((g) => g.items.length > 0);
|
|
74
|
+
}, [groups, q]);
|
|
75
|
+
const flat = useMemo(() => itemsOf(visible), [visible]);
|
|
76
|
+
const active = flat.find((it) => it.id === activeId) || flat[0] || null;
|
|
77
|
+
const options = useMemo(() => (active && optionsOf ? optionsOf(active) : []), [active, optionsOf]);
|
|
78
|
+
const showFilter = filter === true || (filter === 'auto' && itemsOf(groups).length > FILTER_PAST);
|
|
79
|
+
|
|
80
|
+
// Fresh every time it opens: no stale filter, the first item highlighted, the first step shown.
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!open) return undefined;
|
|
83
|
+
setQ(''); setActiveId(value?.item ?? null); setStage('items');
|
|
84
|
+
const measure = () => setStacked(window.innerWidth < stackBelow);
|
|
85
|
+
measure();
|
|
86
|
+
window.addEventListener('resize', measure);
|
|
87
|
+
// Popover renders its children one effect later (it has to measure the anchor first), so the
|
|
88
|
+
// first focusable lands in the next frame.
|
|
89
|
+
const raf = requestAnimationFrame(() => {
|
|
90
|
+
const first = rootRef.current?.querySelector('input, button:not(:disabled)');
|
|
91
|
+
first?.focus({ preventScroll: true });
|
|
92
|
+
});
|
|
93
|
+
const anchor = anchorRef?.current;
|
|
94
|
+
return () => {
|
|
95
|
+
window.removeEventListener('resize', measure);
|
|
96
|
+
cancelAnimationFrame(raf);
|
|
97
|
+
// Close by Escape or by a pick: focus goes back where it came from. Close by a press
|
|
98
|
+
// elsewhere: the browser moves focus to that press afterwards, so this does not fight it.
|
|
99
|
+
anchor?.focus?.({ preventScroll: true });
|
|
100
|
+
};
|
|
101
|
+
}, [open, stackBelow]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
102
|
+
|
|
103
|
+
const focusIn = useCallback((col, index = 0) => {
|
|
104
|
+
const list = rootRef.current?.querySelectorAll(`.uic-cascade-${col} .uic-pop-item:not(:disabled)`);
|
|
105
|
+
if (!list || !list.length) return false;
|
|
106
|
+
const i = Math.max(0, Math.min(index, list.length - 1));
|
|
107
|
+
list[i].focus({ preventScroll: true });
|
|
108
|
+
return true;
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
const enterOptions = useCallback(() => {
|
|
112
|
+
if (stacked) { setStage('options'); requestAnimationFrame(() => focusIn('options')); }
|
|
113
|
+
else focusIn('options');
|
|
114
|
+
}, [stacked, focusIn]);
|
|
115
|
+
|
|
116
|
+
const onKey = (e) => {
|
|
117
|
+
const el = document.activeElement;
|
|
118
|
+
const col = el?.closest?.('.uic-cascade-col');
|
|
119
|
+
const inItems = col?.classList.contains('uic-cascade-items');
|
|
120
|
+
const inOptions = col?.classList.contains('uic-cascade-options');
|
|
121
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
122
|
+
if (!col) return;
|
|
123
|
+
const list = Array.from(col.querySelectorAll('.uic-pop-item:not(:disabled)'));
|
|
124
|
+
const i = list.indexOf(el);
|
|
125
|
+
// From the filter field, ↓ steps onto the first row.
|
|
126
|
+
const next = i < 0 ? 0 : i + (e.key === 'ArrowDown' ? 1 : -1);
|
|
127
|
+
if (next < 0) { col.querySelector('input')?.focus(); e.preventDefault(); return; }
|
|
128
|
+
if (next >= list.length) return;
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
list[next].focus({ preventScroll: true });
|
|
131
|
+
} else if (e.key === 'ArrowRight' && inItems) {
|
|
132
|
+
e.preventDefault(); enterOptions();
|
|
133
|
+
} else if (e.key === 'ArrowLeft' && inOptions) {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
if (stacked) { setStage('items'); requestAnimationFrame(() => focusIn('items', flat.indexOf(active))); }
|
|
136
|
+
else focusIn('items', flat.indexOf(active));
|
|
137
|
+
} else if (e.key === 'Enter' && el?.tagName === 'INPUT') {
|
|
138
|
+
// Enter in the filter means "this one": on to its options.
|
|
139
|
+
e.preventDefault(); enterOptions();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const showItems = !stacked || stage === 'items';
|
|
144
|
+
const showOptions = !stacked || stage === 'options';
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<Popover open={open} anchorRef={anchorRef} onClose={onClose} label={label}
|
|
148
|
+
width={stacked ? 320 : width} minHeight={260}
|
|
149
|
+
className={['uic-cascade-pop', className || ''].filter(Boolean).join(' ')}>
|
|
150
|
+
<div ref={rootRef} className={'uic-cascade' + (stacked ? ' is-stacked' : '')} onKeyDown={onKey}>
|
|
151
|
+
{showItems && (
|
|
152
|
+
<div className="uic-cascade-col uic-cascade-items">
|
|
153
|
+
{showFilter ? (
|
|
154
|
+
<SearchField className="uic-cascade-filter" value={q} onChange={setQ} placeholder={filterPlaceholder} />
|
|
155
|
+
) : null}
|
|
156
|
+
<div className="uic-pop-list">
|
|
157
|
+
{visible.map((g, gi) => (
|
|
158
|
+
<Fragment key={g.label || gi}>
|
|
159
|
+
{g.label ? <div className="uic-cascade-group">{g.label}</div> : null}
|
|
160
|
+
{g.items.map((it) => {
|
|
161
|
+
const on = active?.id === it.id;
|
|
162
|
+
return (
|
|
163
|
+
<button key={it.id} type="button"
|
|
164
|
+
className={'uic-pop-item uic-cascade-item' + (on ? ' is-active' : '')}
|
|
165
|
+
aria-expanded={on} aria-haspopup="true"
|
|
166
|
+
onFocus={() => setActiveId(it.id)}
|
|
167
|
+
onClick={() => { setActiveId(it.id); enterOptions(); }}>
|
|
168
|
+
{it.icon ? <span className="uic-cascade-ic" aria-hidden="true">{it.icon}</span> : null}
|
|
169
|
+
<span className="uic-chip-t">{it.label}</span>
|
|
170
|
+
{it.note ? <span className="uic-cascade-note">{it.note}</span> : null}
|
|
171
|
+
<span className="uic-cascade-chev" aria-hidden="true"><Chevron dir="right" size={14} /></span>
|
|
172
|
+
</button>
|
|
173
|
+
);
|
|
174
|
+
})}
|
|
175
|
+
</Fragment>
|
|
176
|
+
))}
|
|
177
|
+
{flat.length === 0 ? <div className="uic-pop-note">{emptyText}</div> : null}
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
)}
|
|
181
|
+
{showOptions && (
|
|
182
|
+
<div className="uic-cascade-col uic-cascade-options" role="group" aria-label={optionsLabel}>
|
|
183
|
+
<div className="uic-cascade-head">
|
|
184
|
+
{stacked ? (
|
|
185
|
+
<button type="button" className="uic-cascade-back" aria-label={backLabel}
|
|
186
|
+
onClick={() => { setStage('items'); requestAnimationFrame(() => focusIn('items', flat.indexOf(active))); }}>
|
|
187
|
+
<Chevron dir="left" size={14} />
|
|
188
|
+
</button>
|
|
189
|
+
) : null}
|
|
190
|
+
{active?.icon ? <span className="uic-cascade-ic" aria-hidden="true">{active.icon}</span> : null}
|
|
191
|
+
<span className="uic-chip-t">{active ? active.label : ''}</span>
|
|
192
|
+
</div>
|
|
193
|
+
<div className="uic-pop-list">
|
|
194
|
+
{options.map((o) => {
|
|
195
|
+
const on = !!value && active?.id === value.item && o.id === value.option;
|
|
196
|
+
return (
|
|
197
|
+
<button key={o.id} type="button"
|
|
198
|
+
className={'uic-pop-item uic-cascade-opt' + (on ? ' is-on' : '') + (o.badge ? ' has-badge' : '')}
|
|
199
|
+
aria-current={on ? 'true' : undefined}
|
|
200
|
+
disabled={!!o.disabled} onClick={() => onPick?.(active, o)}>
|
|
201
|
+
{value ? <span className="uic-pop-check" aria-hidden="true">{on ? <Tick /> : null}</span> : null}
|
|
202
|
+
<span className="uic-chip-t">{o.label}</span>
|
|
203
|
+
{o.note ? <span className="uic-cascade-note">{o.note}</span> : null}
|
|
204
|
+
{o.badge || null}
|
|
205
|
+
</button>
|
|
206
|
+
);
|
|
207
|
+
})}
|
|
208
|
+
{active && options.length === 0 ? <div className="uic-pop-note">{noOptionsText}</div> : null}
|
|
209
|
+
</div>
|
|
210
|
+
{optionsFooter || null}
|
|
211
|
+
</div>
|
|
212
|
+
)}
|
|
213
|
+
</div>
|
|
214
|
+
</Popover>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// (HR renders its attachment cards here)
|
|
13
13
|
// workingExtra(m, i) extra content on the live Working row (HR's Stop button)
|
|
14
14
|
// assistantFooter(m, i) content below a finished assistant turn (file cards, action row)
|
|
15
|
+
// roleLabel(m, i) small caption above a turn ("You", the agent's name); none by default
|
|
15
16
|
// renderStep(step, j) per-step override inside the activity timeline
|
|
16
17
|
// statusLabels terminal badge copy per status
|
|
17
18
|
// workingLabel / toolLabels live-indicator + timeline copy
|
|
@@ -19,13 +20,23 @@ import React from 'react';
|
|
|
19
20
|
import { ToolGroup } from './ToolSteps.jsx';
|
|
20
21
|
|
|
21
22
|
export const DEFAULT_STATUS_LABELS = {
|
|
22
|
-
failed: '✕ Failed
|
|
23
|
+
failed: '✕ Failed. See the output above for the reason',
|
|
23
24
|
cancelled: '◼ Stopped by you',
|
|
24
|
-
|
|
25
|
+
// Claims only what is true of every cause: an incomplete turn may have hit its step or time
|
|
26
|
+
// budget, or been cut mid-flight (a replica restart under a live turn settles as incomplete).
|
|
27
|
+
// Asserting "step or time limit" for all of them sent an operator debugging a limit that was
|
|
28
|
+
// never reached. A host that knows the actual cause says so in its own chrome (statusLabels /
|
|
29
|
+
// assistantFooter).
|
|
30
|
+
incomplete: '◔ Stopped before finishing. Continue to resume',
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
const defaultMarkdown = (text) => <div style={{ whiteSpace: 'pre-wrap' }}>{text}</div>;
|
|
28
34
|
|
|
35
|
+
// Reduced motion: the typewriter is motion — render streamed text directly.
|
|
36
|
+
const REDUCED_MOTION = typeof window !== 'undefined'
|
|
37
|
+
&& typeof window.matchMedia === 'function'
|
|
38
|
+
&& window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
39
|
+
|
|
29
40
|
// Typewriter reveal for the actively-streaming text block. Deltas arrive in ~1.2s bursts, so raw
|
|
30
41
|
// rendering makes short answers pop in whole. This fills characters at a deliberate pace: reveal
|
|
31
42
|
// the currently-pending text over ~REVEAL_SEC seconds, but never slower than MIN_CPS (so the last
|
|
@@ -39,7 +50,8 @@ const defaultMarkdown = (text) => <div style={{ whiteSpace: 'pre-wrap' }}>{text}
|
|
|
39
50
|
const REVEAL_SEC = 3; // a pending burst fills over ~3s...
|
|
40
51
|
const MIN_CPS = 10; // ...unless the tail is small, then at least this many chars/sec
|
|
41
52
|
function TypewriterText(props) {
|
|
42
|
-
const { text,
|
|
53
|
+
const { text, render } = props;
|
|
54
|
+
const active = props.active && !REDUCED_MOTION;
|
|
43
55
|
const [n, setN] = React.useState(() => (text ? text.length : 0));
|
|
44
56
|
const textRef = React.useRef(text);
|
|
45
57
|
textRef.current = text;
|
|
@@ -70,13 +82,18 @@ function TypewriterText(props) {
|
|
|
70
82
|
// NOTE: components take a single `props` object and destructure inside — TypeScript consumers
|
|
71
83
|
// (HR is TSX) infer inline-destructured JS props as REQUIRED, which would force every slot.
|
|
72
84
|
export function UserTurn(props) {
|
|
73
|
-
const { msg, children } = props;
|
|
85
|
+
const { msg, children, label } = props;
|
|
86
|
+
const bubble = (
|
|
87
|
+
<div className="wbx-bubble-user">
|
|
88
|
+
{children}
|
|
89
|
+
{msg.text && <div className="wbx-bubble-text">{msg.text}</div>}
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
// With a caption, caption and bubble share one column so the caption's left edge is the
|
|
93
|
+
// bubble's left edge (the design), while the column itself still sits at the trailing side.
|
|
74
94
|
return (
|
|
75
95
|
<div className="wbx-turn user">
|
|
76
|
-
<div className="wbx-
|
|
77
|
-
{children}
|
|
78
|
-
{msg.text && <div className="wbx-bubble-text">{msg.text}</div>}
|
|
79
|
-
</div>
|
|
96
|
+
{label ? <div className="wbx-turn-body"><div className="wbx-role">{label}</div>{bubble}</div> : bubble}
|
|
80
97
|
</div>
|
|
81
98
|
);
|
|
82
99
|
}
|
|
@@ -91,9 +108,11 @@ export function AssistantTurn(props) {
|
|
|
91
108
|
renderStep,
|
|
92
109
|
toolLabels,
|
|
93
110
|
footer,
|
|
111
|
+
label,
|
|
94
112
|
} = props;
|
|
95
113
|
return (
|
|
96
114
|
<div className="wbx-turn asst">
|
|
115
|
+
{label ? <div className="wbx-role">{label}</div> : null}
|
|
97
116
|
{msg.blocks.map((b, bi) => (b.kind === 'tools'
|
|
98
117
|
? <ToolGroup key={bi} reasoning={b.reasoning} steps={b.steps}
|
|
99
118
|
running={msg.status === 'running' && bi === msg.blocks.length - 1}
|
|
@@ -168,6 +187,7 @@ export function ChatMessages(props) {
|
|
|
168
187
|
renderStep,
|
|
169
188
|
workingLabel,
|
|
170
189
|
toolLabels,
|
|
190
|
+
roleLabel,
|
|
171
191
|
} = props;
|
|
172
192
|
return (
|
|
173
193
|
<>
|
|
@@ -177,7 +197,7 @@ export function ChatMessages(props) {
|
|
|
177
197
|
if (el !== undefined) return <React.Fragment key={i}>{el}</React.Fragment>;
|
|
178
198
|
}
|
|
179
199
|
return m.role === 'user' ? (
|
|
180
|
-
<UserTurn key={i} msg={m}>{userExtras?.(m, i)}</UserTurn>
|
|
200
|
+
<UserTurn key={i} msg={m} label={roleLabel?.(m, i)}>{userExtras?.(m, i)}</UserTurn>
|
|
181
201
|
) : (
|
|
182
202
|
<AssistantTurn key={i} msg={m}
|
|
183
203
|
renderMarkdown={renderMarkdown}
|
|
@@ -186,6 +206,7 @@ export function ChatMessages(props) {
|
|
|
186
206
|
statusLabels={statusLabels}
|
|
187
207
|
renderStep={renderStep}
|
|
188
208
|
toolLabels={toolLabels}
|
|
209
|
+
label={roleLabel?.(m, i)}
|
|
189
210
|
footer={assistantFooter?.(m, i)} />
|
|
190
211
|
);
|
|
191
212
|
})}
|
package/src/components/Chip.jsx
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
//
|
|
8
8
|
// Width is CSS, not a prop: two of the copies set maxWidth 180 and 220 inline on the same
|
|
9
9
|
// component in the same app. The label ellipsizes against the row it is in.
|
|
10
|
-
import React from 'react';
|
|
10
|
+
import React, { forwardRef } from 'react';
|
|
11
11
|
import { IcX } from './icons.jsx';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -15,15 +15,28 @@ import { IcX } from './icons.jsx';
|
|
|
15
15
|
* icon leading glyph
|
|
16
16
|
* title native tooltip, usually the untruncated label
|
|
17
17
|
* selected this chip stands for something chosen (brand fill)
|
|
18
|
-
* onClick makes the chip itself a button
|
|
18
|
+
* onClick makes the chip itself a button
|
|
19
|
+
* slot the dashed "open slot" look for a chip that stands for a choice not yet made
|
|
20
|
+
* (+ add a file). Defaults to clickable-and-unselected, which is how every earlier
|
|
21
|
+
* caller got it; pass slot={false} for a chip that is clickable AND already set,
|
|
22
|
+
* e.g. a chosen route that opens its own editor.
|
|
19
23
|
* onRemove adds a trailing ✕ button; removeLabel is REQUIRED with it, because "✕" alone tells
|
|
20
24
|
* a screen reader nothing about which of five chips it removes
|
|
25
|
+
* trailing a node rendered between the label and the ✕ — a compact control the chip carries,
|
|
26
|
+
* e.g. a per-route model <select> in a comparison bar. It is the CALLER's control:
|
|
27
|
+
* the chip never wraps it in its own press target, so a select inside a clickable
|
|
28
|
+
* chip still opens instead of triggering the chip.
|
|
29
|
+
* ref lands on the OUTERMOST element, the box a Popover or CascadeMenu anchors against.
|
|
30
|
+
* ...rest goes onto the press target (aria-expanded, aria-haspopup, data-*), so a chip that
|
|
31
|
+
* opens a menu can say so to assistive tech without the library naming every attribute.
|
|
21
32
|
*/
|
|
22
|
-
export function Chip(props) {
|
|
23
|
-
const { label, icon, title, selected = false, onClick, onRemove, removeLabel, className
|
|
33
|
+
export const Chip = forwardRef(function Chip(props, ref) {
|
|
34
|
+
const { label, icon, title, selected = false, onClick, onRemove, removeLabel, trailing, className,
|
|
35
|
+
slot, ...rest } = props;
|
|
36
|
+
const isSlot = slot ?? (Boolean(onClick) && !selected);
|
|
24
37
|
const cls = ['uic-chip',
|
|
25
38
|
selected ? 'is-selected' : '',
|
|
26
|
-
|
|
39
|
+
isSlot ? 'is-open' : '',
|
|
27
40
|
className || ''].filter(Boolean).join(' ');
|
|
28
41
|
|
|
29
42
|
const body = (
|
|
@@ -35,10 +48,13 @@ export function Chip(props) {
|
|
|
35
48
|
|
|
36
49
|
// A chip that is both pressable and removable is two controls, so the outer element stays a
|
|
37
50
|
// plain span and the press target becomes its own button — never a button inside a button.
|
|
51
|
+
const trail = trailing ? <span className="uic-chip-tr">{trailing}</span> : null;
|
|
52
|
+
|
|
38
53
|
if (onClick && onRemove) {
|
|
39
54
|
return (
|
|
40
|
-
<span className={cls} title={title}>
|
|
41
|
-
<button type="button" className="uic-chip-press" onClick={onClick}>{body}</button>
|
|
55
|
+
<span ref={ref} className={cls} title={title}>
|
|
56
|
+
<button type="button" className="uic-chip-press" onClick={onClick} {...rest}>{body}</button>
|
|
57
|
+
{trail}
|
|
42
58
|
<button type="button" className="uic-chip-x" aria-label={removeLabel} onClick={onRemove}>
|
|
43
59
|
<IcX size={12} />
|
|
44
60
|
</button>
|
|
@@ -46,11 +62,22 @@ export function Chip(props) {
|
|
|
46
62
|
);
|
|
47
63
|
}
|
|
48
64
|
if (onClick) {
|
|
49
|
-
|
|
65
|
+
// trailing needs its own interactivity, and a control inside a <button> is invalid HTML the
|
|
66
|
+
// browser un-nests unpredictably — so a clickable chip that carries one keeps the split form.
|
|
67
|
+
if (trailing) {
|
|
68
|
+
return (
|
|
69
|
+
<span ref={ref} className={cls} title={title}>
|
|
70
|
+
<button type="button" className="uic-chip-press" onClick={onClick} {...rest}>{body}</button>
|
|
71
|
+
{trail}
|
|
72
|
+
</span>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return <button ref={ref} type="button" className={cls} title={title} onClick={onClick} {...rest}>{body}</button>;
|
|
50
76
|
}
|
|
51
77
|
return (
|
|
52
|
-
<span className={cls} title={title}>
|
|
78
|
+
<span ref={ref} className={cls} title={title} {...rest}>
|
|
53
79
|
{body}
|
|
80
|
+
{trail}
|
|
54
81
|
{onRemove ? (
|
|
55
82
|
<button type="button" className="uic-chip-x" aria-label={removeLabel} onClick={onRemove}>
|
|
56
83
|
<IcX size={12} />
|
|
@@ -58,4 +85,4 @@ export function Chip(props) {
|
|
|
58
85
|
) : null}
|
|
59
86
|
</span>
|
|
60
87
|
);
|
|
61
|
-
}
|
|
88
|
+
});
|