reifyui 0.11.1 → 0.12.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 +2 -2
- package/dist/index.cjs +453 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -2
- package/dist/index.js +454 -159
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/CascadeMenu.jsx +210 -0
- package/src/components/ChatMessages.jsx +30 -9
- package/src/components/Chip.jsx +37 -10
- package/src/components/Composer.jsx +44 -0
- package/src/index.d.ts +17 -2
- package/src/index.js +2 -0
- package/src/sheet/SheetGrid.jsx +72 -6
- package/styles/chat.css +45 -5
- package/styles/chip.css +36 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reifyui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI \u2014 model-agnostic, framework-agnostic, design-system-native. The foundation for building generative-UI and agent products.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
7
|
"generative-ui",
|
|
@@ -0,0 +1,210 @@
|
|
|
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 }] — the second column for one item
|
|
38
|
+
* onPick(item, option)
|
|
39
|
+
* value { item, option } — the current pair: its item opens first and its option
|
|
40
|
+
* carries a check, so an editor of an existing choice shows where it stands
|
|
41
|
+
* filter 'auto' (default) | true | false — a filter field over the first column
|
|
42
|
+
* filterPlaceholder default 'Filter'
|
|
43
|
+
* emptyText first column has no match; noOptionsText: the item offers nothing
|
|
44
|
+
* optionsLabel accessible name of the second column, default 'Options'
|
|
45
|
+
* backLabel the way back in stacked mode, default 'Back'
|
|
46
|
+
* width side-by-side width, default 520; stackBelow: viewport px, default 560
|
|
47
|
+
*/
|
|
48
|
+
export function CascadeMenu(props) {
|
|
49
|
+
const {
|
|
50
|
+
open, anchorRef, onClose, label,
|
|
51
|
+
groups = [], optionsOf, onPick,
|
|
52
|
+
filter = 'auto', filterPlaceholder = 'Filter',
|
|
53
|
+
emptyText = 'Nothing matches.', noOptionsText = 'Nothing to choose here.',
|
|
54
|
+
optionsLabel = 'Options', backLabel = 'Back',
|
|
55
|
+
width = 520, stackBelow = 560, className, value,
|
|
56
|
+
} = props;
|
|
57
|
+
|
|
58
|
+
const rootRef = useRef(null);
|
|
59
|
+
const [q, setQ] = useState('');
|
|
60
|
+
const [activeId, setActiveId] = useState(null);
|
|
61
|
+
const [stage, setStage] = useState('items');
|
|
62
|
+
const [stacked, setStacked] = useState(false);
|
|
63
|
+
|
|
64
|
+
// Filtering happens on the label people read, nothing else.
|
|
65
|
+
const visible = useMemo(() => {
|
|
66
|
+
const needle = q.trim().toLowerCase();
|
|
67
|
+
if (!needle) return groups.filter((g) => g.items.length > 0);
|
|
68
|
+
return groups
|
|
69
|
+
.map((g) => ({ ...g, items: g.items.filter((it) => String(it.label).toLowerCase().includes(needle)) }))
|
|
70
|
+
.filter((g) => g.items.length > 0);
|
|
71
|
+
}, [groups, q]);
|
|
72
|
+
const flat = useMemo(() => itemsOf(visible), [visible]);
|
|
73
|
+
const active = flat.find((it) => it.id === activeId) || flat[0] || null;
|
|
74
|
+
const options = useMemo(() => (active && optionsOf ? optionsOf(active) : []), [active, optionsOf]);
|
|
75
|
+
const showFilter = filter === true || (filter === 'auto' && itemsOf(groups).length > FILTER_PAST);
|
|
76
|
+
|
|
77
|
+
// Fresh every time it opens: no stale filter, the first item highlighted, the first step shown.
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!open) return undefined;
|
|
80
|
+
setQ(''); setActiveId(value?.item ?? null); setStage('items');
|
|
81
|
+
const measure = () => setStacked(window.innerWidth < stackBelow);
|
|
82
|
+
measure();
|
|
83
|
+
window.addEventListener('resize', measure);
|
|
84
|
+
// Popover renders its children one effect later (it has to measure the anchor first), so the
|
|
85
|
+
// first focusable lands in the next frame.
|
|
86
|
+
const raf = requestAnimationFrame(() => {
|
|
87
|
+
const first = rootRef.current?.querySelector('input, button:not(:disabled)');
|
|
88
|
+
first?.focus({ preventScroll: true });
|
|
89
|
+
});
|
|
90
|
+
const anchor = anchorRef?.current;
|
|
91
|
+
return () => {
|
|
92
|
+
window.removeEventListener('resize', measure);
|
|
93
|
+
cancelAnimationFrame(raf);
|
|
94
|
+
// Close by Escape or by a pick: focus goes back where it came from. Close by a press
|
|
95
|
+
// elsewhere: the browser moves focus to that press afterwards, so this does not fight it.
|
|
96
|
+
anchor?.focus?.({ preventScroll: true });
|
|
97
|
+
};
|
|
98
|
+
}, [open, stackBelow]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
99
|
+
|
|
100
|
+
const focusIn = useCallback((col, index = 0) => {
|
|
101
|
+
const list = rootRef.current?.querySelectorAll(`.uic-cascade-${col} .uic-pop-item:not(:disabled)`);
|
|
102
|
+
if (!list || !list.length) return false;
|
|
103
|
+
const i = Math.max(0, Math.min(index, list.length - 1));
|
|
104
|
+
list[i].focus({ preventScroll: true });
|
|
105
|
+
return true;
|
|
106
|
+
}, []);
|
|
107
|
+
|
|
108
|
+
const enterOptions = useCallback(() => {
|
|
109
|
+
if (stacked) { setStage('options'); requestAnimationFrame(() => focusIn('options')); }
|
|
110
|
+
else focusIn('options');
|
|
111
|
+
}, [stacked, focusIn]);
|
|
112
|
+
|
|
113
|
+
const onKey = (e) => {
|
|
114
|
+
const el = document.activeElement;
|
|
115
|
+
const col = el?.closest?.('.uic-cascade-col');
|
|
116
|
+
const inItems = col?.classList.contains('uic-cascade-items');
|
|
117
|
+
const inOptions = col?.classList.contains('uic-cascade-options');
|
|
118
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
119
|
+
if (!col) return;
|
|
120
|
+
const list = Array.from(col.querySelectorAll('.uic-pop-item:not(:disabled)'));
|
|
121
|
+
const i = list.indexOf(el);
|
|
122
|
+
// From the filter field, ↓ steps onto the first row.
|
|
123
|
+
const next = i < 0 ? 0 : i + (e.key === 'ArrowDown' ? 1 : -1);
|
|
124
|
+
if (next < 0) { col.querySelector('input')?.focus(); e.preventDefault(); return; }
|
|
125
|
+
if (next >= list.length) return;
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
list[next].focus({ preventScroll: true });
|
|
128
|
+
} else if (e.key === 'ArrowRight' && inItems) {
|
|
129
|
+
e.preventDefault(); enterOptions();
|
|
130
|
+
} else if (e.key === 'ArrowLeft' && inOptions) {
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
if (stacked) { setStage('items'); requestAnimationFrame(() => focusIn('items', flat.indexOf(active))); }
|
|
133
|
+
else focusIn('items', flat.indexOf(active));
|
|
134
|
+
} else if (e.key === 'Enter' && el?.tagName === 'INPUT') {
|
|
135
|
+
// Enter in the filter means "this one": on to its options.
|
|
136
|
+
e.preventDefault(); enterOptions();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const showItems = !stacked || stage === 'items';
|
|
141
|
+
const showOptions = !stacked || stage === 'options';
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<Popover open={open} anchorRef={anchorRef} onClose={onClose} label={label}
|
|
145
|
+
width={stacked ? 320 : width} minHeight={260}
|
|
146
|
+
className={['uic-cascade-pop', className || ''].filter(Boolean).join(' ')}>
|
|
147
|
+
<div ref={rootRef} className={'uic-cascade' + (stacked ? ' is-stacked' : '')} onKeyDown={onKey}>
|
|
148
|
+
{showItems && (
|
|
149
|
+
<div className="uic-cascade-col uic-cascade-items">
|
|
150
|
+
{showFilter ? (
|
|
151
|
+
<SearchField className="uic-cascade-filter" value={q} onChange={setQ} placeholder={filterPlaceholder} />
|
|
152
|
+
) : null}
|
|
153
|
+
<div className="uic-pop-list">
|
|
154
|
+
{visible.map((g, gi) => (
|
|
155
|
+
<Fragment key={g.label || gi}>
|
|
156
|
+
{g.label ? <div className="uic-cascade-group">{g.label}</div> : null}
|
|
157
|
+
{g.items.map((it) => {
|
|
158
|
+
const on = active?.id === it.id;
|
|
159
|
+
return (
|
|
160
|
+
<button key={it.id} type="button"
|
|
161
|
+
className={'uic-pop-item uic-cascade-item' + (on ? ' is-active' : '')}
|
|
162
|
+
aria-expanded={on} aria-haspopup="true"
|
|
163
|
+
onFocus={() => setActiveId(it.id)}
|
|
164
|
+
onClick={() => { setActiveId(it.id); enterOptions(); }}>
|
|
165
|
+
{it.icon ? <span className="uic-cascade-ic" aria-hidden="true">{it.icon}</span> : null}
|
|
166
|
+
<span className="uic-chip-t">{it.label}</span>
|
|
167
|
+
{it.note ? <span className="uic-cascade-note">{it.note}</span> : null}
|
|
168
|
+
<span className="uic-cascade-chev" aria-hidden="true"><Chevron dir="right" size={14} /></span>
|
|
169
|
+
</button>
|
|
170
|
+
);
|
|
171
|
+
})}
|
|
172
|
+
</Fragment>
|
|
173
|
+
))}
|
|
174
|
+
{flat.length === 0 ? <div className="uic-pop-note">{emptyText}</div> : null}
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
)}
|
|
178
|
+
{showOptions && (
|
|
179
|
+
<div className="uic-cascade-col uic-cascade-options" role="group" aria-label={optionsLabel}>
|
|
180
|
+
<div className="uic-cascade-head">
|
|
181
|
+
{stacked ? (
|
|
182
|
+
<button type="button" className="uic-cascade-back" aria-label={backLabel}
|
|
183
|
+
onClick={() => { setStage('items'); requestAnimationFrame(() => focusIn('items', flat.indexOf(active))); }}>
|
|
184
|
+
<Chevron dir="left" size={14} />
|
|
185
|
+
</button>
|
|
186
|
+
) : null}
|
|
187
|
+
{active?.icon ? <span className="uic-cascade-ic" aria-hidden="true">{active.icon}</span> : null}
|
|
188
|
+
<span className="uic-chip-t">{active ? active.label : ''}</span>
|
|
189
|
+
</div>
|
|
190
|
+
<div className="uic-pop-list">
|
|
191
|
+
{options.map((o) => {
|
|
192
|
+
const on = !!value && active?.id === value.item && o.id === value.option;
|
|
193
|
+
return (
|
|
194
|
+
<button key={o.id} type="button" className={'uic-pop-item uic-cascade-opt' + (on ? ' is-on' : '')}
|
|
195
|
+
aria-current={on ? 'true' : undefined}
|
|
196
|
+
disabled={!!o.disabled} onClick={() => onPick?.(active, o)}>
|
|
197
|
+
{value ? <span className="uic-pop-check" aria-hidden="true">{on ? <Tick /> : null}</span> : null}
|
|
198
|
+
<span className="uic-chip-t">{o.label}</span>
|
|
199
|
+
{o.note ? <span className="uic-cascade-note">{o.note}</span> : null}
|
|
200
|
+
</button>
|
|
201
|
+
);
|
|
202
|
+
})}
|
|
203
|
+
{active && options.length === 0 ? <div className="uic-pop-note">{noOptionsText}</div> : null}
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
)}
|
|
207
|
+
</div>
|
|
208
|
+
</Popover>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
// accessoriesLeft nodes before the flexible spacer (attach button, model select, mic, …)
|
|
8
8
|
// accessoriesRight nodes after the spacer, before the send button
|
|
9
9
|
// renderSend() replaces the default send button entirely
|
|
10
|
+
// inline single-line layout: accessories, textarea and send share ONE row,
|
|
11
|
+
// vertically aligned (the classic chat input). Buttons stick to the
|
|
12
|
+
// bottom edge as the textarea grows, so multiline still reads right.
|
|
13
|
+
// tray node rendered INSIDE the card, under the action row — one seamless
|
|
14
|
+
// surface, no divider band. This is where a product puts the row that
|
|
15
|
+
// belongs to the message being composed (Arena's harness+model chips,
|
|
16
|
+
// a template picker, a recipient list) rather than to the app chrome.
|
|
10
17
|
// classNames { root, input, row } — each REPLACES the default class when provided,
|
|
11
18
|
// so a product can restyle wholesale without fighting the package CSS
|
|
12
19
|
//
|
|
@@ -28,6 +35,7 @@ export function Composer(props) {
|
|
|
28
35
|
placeholder,
|
|
29
36
|
rows = 1,
|
|
30
37
|
autoGrow = true,
|
|
38
|
+
inline = false,
|
|
31
39
|
maxRows = 15,
|
|
32
40
|
autoFocus,
|
|
33
41
|
// The composer on a landing page often has an ANIMATING placeholder (a typewriter cycling
|
|
@@ -35,6 +43,7 @@ export function Composer(props) {
|
|
|
35
43
|
// one is given — so the field announces a different name every few seconds.
|
|
36
44
|
inputAriaLabel,
|
|
37
45
|
attachments,
|
|
46
|
+
tray,
|
|
38
47
|
accessoriesLeft,
|
|
39
48
|
accessoriesRight,
|
|
40
49
|
renderSend,
|
|
@@ -56,6 +65,40 @@ export function Composer(props) {
|
|
|
56
65
|
el.style.overflowY = el.scrollHeight > max ? 'auto' : 'hidden';
|
|
57
66
|
}, [value, autoGrow, maxRows, taRef]);
|
|
58
67
|
|
|
68
|
+
const sendEl = renderSend ? renderSend() : (
|
|
69
|
+
<button type="button" className="uic-send" disabled={sendDisabled} onClick={() => onSend()} aria-label="Send message">
|
|
70
|
+
<IcSend />
|
|
71
|
+
</button>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (inline) {
|
|
75
|
+
return (
|
|
76
|
+
<div className={classNames.root ?? 'wbx-composer'}>
|
|
77
|
+
{attachments}
|
|
78
|
+
<div className="uic-composer-line">
|
|
79
|
+
{accessoriesLeft}
|
|
80
|
+
<textarea
|
|
81
|
+
ref={taRef}
|
|
82
|
+
className={classNames.input ?? 'wbx-composer-input'}
|
|
83
|
+
rows={rows}
|
|
84
|
+
value={value}
|
|
85
|
+
placeholder={placeholder}
|
|
86
|
+
aria-label={inputAriaLabel || placeholder}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
autoFocus={autoFocus}
|
|
89
|
+
onChange={(e) => onChange(e.target.value)}
|
|
90
|
+
onKeyDown={(e) => {
|
|
91
|
+
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); onSend(); }
|
|
92
|
+
}}
|
|
93
|
+
/>
|
|
94
|
+
{accessoriesRight}
|
|
95
|
+
{sendEl}
|
|
96
|
+
</div>
|
|
97
|
+
{tray ? <div className="uic-composer-tray">{tray}</div> : null}
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
59
102
|
return (
|
|
60
103
|
<div className={classNames.root ?? 'wbx-composer'}>
|
|
61
104
|
{attachments}
|
|
@@ -89,6 +132,7 @@ export function Composer(props) {
|
|
|
89
132
|
</button>
|
|
90
133
|
)}
|
|
91
134
|
</div>
|
|
135
|
+
{tray ? <div className="uic-composer-tray">{tray}</div> : null}
|
|
92
136
|
</div>
|
|
93
137
|
);
|
|
94
138
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// authored by hand rather than inferred. Components accept the props documented in
|
|
5
5
|
// the README; where a prop set is open-ended (render slots, passthrough) the type is
|
|
6
6
|
// intentionally permissive rather than falsely precise.
|
|
7
|
-
import type { ComponentType, ReactNode } from 'react';
|
|
7
|
+
import type { ComponentType, ForwardRefExoticComponent, ReactNode, RefAttributes } from 'react';
|
|
8
8
|
|
|
9
9
|
// ── streaming ──────────────────────────────────────────────────────────────
|
|
10
10
|
export interface SSEEvent { type: string; [k: string]: unknown; }
|
|
@@ -183,8 +183,14 @@ export interface ComposerProps {
|
|
|
183
183
|
/** The accessible name. Give one whenever the placeholder animates — it is otherwise the only
|
|
184
184
|
* name the field has, and it changes every few seconds. */
|
|
185
185
|
inputAriaLabel?: string;
|
|
186
|
+
/** Single-line layout: accessories, textarea and send share ONE row (the classic chat
|
|
187
|
+
* input); buttons stick to the bottom edge as the textarea grows. */
|
|
188
|
+
inline?: boolean;
|
|
186
189
|
/** Node rendered ABOVE the textarea, e.g. a row of staged attachments. */
|
|
187
190
|
attachments?: ReactNode;
|
|
191
|
+
/** Node rendered INSIDE the card, under the action row — one seamless surface, for the row
|
|
192
|
+
* that belongs to the message being composed (route chips, a template picker). */
|
|
193
|
+
tray?: ReactNode;
|
|
188
194
|
accessoriesLeft?: ReactNode;
|
|
189
195
|
accessoriesRight?: ReactNode;
|
|
190
196
|
/** Replaces the default send button entirely. */
|
|
@@ -348,9 +354,18 @@ export interface ChipProps {
|
|
|
348
354
|
onRemove?: () => void;
|
|
349
355
|
/** Required with onRemove: "✕" alone does not say which of five chips it removes. */
|
|
350
356
|
removeLabel?: string;
|
|
357
|
+
/** The dashed "open slot" look for a choice not yet made. Defaults to clickable-and-unselected;
|
|
358
|
+
* pass slot={false} for a chip that is clickable AND already set. */
|
|
359
|
+
slot?: boolean;
|
|
360
|
+
/** A compact control the chip carries between the label and the ✕ (the caller's control —
|
|
361
|
+
* never wrapped in the chip's own press target). */
|
|
362
|
+
trailing?: ReactNode;
|
|
351
363
|
className?: string;
|
|
364
|
+
/** Everything else lands on the press target (aria-expanded, aria-haspopup, data-*). */
|
|
365
|
+
[k: string]: unknown;
|
|
352
366
|
}
|
|
353
|
-
|
|
367
|
+
/** ref lands on the OUTERMOST element — the box a Popover or CascadeMenu anchors against. */
|
|
368
|
+
export const Chip: ForwardRefExoticComponent<ChipProps & RefAttributes<HTMLElement>>;
|
|
354
369
|
|
|
355
370
|
export interface SearchFieldProps {
|
|
356
371
|
value: string;
|
package/src/index.js
CHANGED
|
@@ -63,6 +63,8 @@ export { SearchField } from './components/SearchField.jsx';
|
|
|
63
63
|
// Anchored panel with placement built in — flips, clamps to the viewport, closes on Escape and
|
|
64
64
|
// outside press. Ten hand-rolled versions of this existed; one survived a phone.
|
|
65
65
|
export { Popover } from './components/Popover.jsx';
|
|
66
|
+
// Two-level pick in one panel (items, then the highlighted item's options), on Popover.
|
|
67
|
+
export { CascadeMenu } from './components/CascadeMenu.jsx';
|
|
66
68
|
// A dialog whose body is yours (useDialog answers a question; this holds content). Shares the
|
|
67
69
|
// dialog host's Escape ordering and overlay layer. Needs styles/preview.css.
|
|
68
70
|
export { Modal } from './components/Modal.jsx';
|
package/src/sheet/SheetGrid.jsx
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// SheetGrid — the reusable AI-spreadsheet grid.
|
|
2
2
|
//
|
|
3
|
+
// CLAMP_LINE / CLAMP_PAD are the line height and the vertical padding a cell is laid out with;
|
|
4
|
+
// they turn a measured row height into a number of lines for `--shg-clamp`, which host CSS uses
|
|
5
|
+
// for line-clamp.
|
|
6
|
+
//
|
|
3
7
|
// Product-agnostic: it renders a sheet JSON and calls back for edits/runs. All I/O is injected —
|
|
4
8
|
// this file has no product API.
|
|
5
9
|
//
|
|
@@ -23,7 +27,13 @@
|
|
|
23
27
|
//
|
|
24
28
|
// Editing is optimistic: local edits call onChange with the next sheet; the host persists and
|
|
25
29
|
// hands truth back through `sheet`.
|
|
26
|
-
import { useEffect, useRef, useState } from 'react';
|
|
30
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
31
|
+
|
|
32
|
+
const CLAMP_LINE = 18;
|
|
33
|
+
const CLAMP_PAD = 10;
|
|
34
|
+
// A cell says which of its children is the clamped text by marking it. Without a mark the cell IS
|
|
35
|
+
// its text (the built-in value cell), which is the right default.
|
|
36
|
+
const CLAMP_TEXT_SEL = '[data-shg-clamp-text]';
|
|
27
37
|
import { createPortal } from 'react-dom';
|
|
28
38
|
|
|
29
39
|
const cellKey = (rowId, colId) => `${rowId}:${colId}`;
|
|
@@ -209,6 +219,7 @@ export function SheetGrid({
|
|
|
209
219
|
const [dropAt, setDropAt] = useState(null); // {kind, id, after} current drop slot
|
|
210
220
|
const inputRef = useRef(null);
|
|
211
221
|
const dragRef = useRef(null);
|
|
222
|
+
const gridRef = useRef(null);
|
|
212
223
|
|
|
213
224
|
// An unknown type still renders — as plain text, editable. Refusing to draw a column because
|
|
214
225
|
// its type is unfamiliar would hide the person's data from them.
|
|
@@ -305,6 +316,64 @@ export function SheetGrid({
|
|
|
305
316
|
|
|
306
317
|
useEffect(() => { if (editing && inputRef.current) inputRef.current.focus(); }, [editing]);
|
|
307
318
|
|
|
319
|
+
// How many lines of text a row has room for.
|
|
320
|
+
//
|
|
321
|
+
// This used to be derived from the row's STORED height, falling back to 34px — one line — for
|
|
322
|
+
// any row that had never been sized. But a row is very often tall because of a NEIGHBOURING
|
|
323
|
+
// column: an agent cell with files under its answer, or simply a taller one. Every other cell
|
|
324
|
+
// in that row then showed a single ellipsised line with the rest of the row empty beneath it,
|
|
325
|
+
// which is what the space was there for.
|
|
326
|
+
//
|
|
327
|
+
// Measured with every clamp forced back to one line first. That is the whole trick: the basis
|
|
328
|
+
// has to be the height the row's OTHER content needs, never the height the clamp itself just
|
|
329
|
+
// produced. Deriving it from the rendered height directly feeds back — more lines makes the
|
|
330
|
+
// row taller, which allows more lines — and the rows grow without bound (92 → 137 → 182 → …).
|
|
331
|
+
useLayoutEffect(() => {
|
|
332
|
+
const rowsEl = gridRef.current?.querySelectorAll('tbody tr[data-row-id]');
|
|
333
|
+
if (!rowsEl || !rowsEl.length) return;
|
|
334
|
+
const trs = Array.from(rowsEl);
|
|
335
|
+
|
|
336
|
+
// 1. Put every clamp back to one line, so what we measure next is the height the row's other
|
|
337
|
+
// content NEEDS rather than the height the last clamp happened to produce.
|
|
338
|
+
for (const tr of trs) {
|
|
339
|
+
tr.style.removeProperty('--shg-clamp');
|
|
340
|
+
for (const td of tr.children) td.style.setProperty('--shg-clamp', '1');
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// 2. Measure, in one pass: the row, and per cell whatever sits ALONGSIDE its text (an agent
|
|
344
|
+
// cell keeps its files under its answer). Measured on the text's own box, which sizes to
|
|
345
|
+
// its content — the <td> is stretched to the row and would report the row height for every
|
|
346
|
+
// cell, making them all look equally full.
|
|
347
|
+
const plan = trs.map((tr) => ({
|
|
348
|
+
base: tr.offsetHeight,
|
|
349
|
+
cells: Array.from(tr.children).map((td) => {
|
|
350
|
+
const txt = td.querySelector(CLAMP_TEXT_SEL);
|
|
351
|
+
const box = txt && txt.parentElement;
|
|
352
|
+
return { td, extra: box ? Math.max(0, box.scrollHeight - txt.offsetHeight) : 0 };
|
|
353
|
+
}),
|
|
354
|
+
}));
|
|
355
|
+
|
|
356
|
+
// 3. Give every cell in a row the same amount of room for text.
|
|
357
|
+
//
|
|
358
|
+
// `floor` is the line count the row's own height already allows. `need` is how tall the row
|
|
359
|
+
// must be for the cell carrying the most alongside its text — the one with files under it —
|
|
360
|
+
// to still get that many lines. Every other cell then fills THAT height, which is the whole
|
|
361
|
+
// point: a cell with nothing under its text was showing one ellipsised line beside a
|
|
362
|
+
// neighbour whose files made the row four times taller.
|
|
363
|
+
//
|
|
364
|
+
// extra + lines*LINE <= need by construction, so no cell outgrows the height this was
|
|
365
|
+
// measured against, and `base` is always re-measured at one line — so a second pass
|
|
366
|
+
// computes the same answer instead of ratcheting the rows upward.
|
|
367
|
+
for (const { base, cells } of plan) {
|
|
368
|
+
const floorLines = Math.max(1, Math.floor((base - CLAMP_PAD) / CLAMP_LINE));
|
|
369
|
+
const need = Math.max(...cells.map((c) => c.extra)) + floorLines * CLAMP_LINE + CLAMP_PAD;
|
|
370
|
+
for (const { td, extra } of cells) {
|
|
371
|
+
const lines = Math.max(floorLines, Math.floor((need - extra - CLAMP_PAD) / CLAMP_LINE));
|
|
372
|
+
td.style.setProperty('--shg-clamp', String(lines));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
308
377
|
const mutate = (fn) => {
|
|
309
378
|
if (readOnly || !onChange) return;
|
|
310
379
|
const next = JSON.parse(JSON.stringify(sheet));
|
|
@@ -431,7 +500,7 @@ export function SheetGrid({
|
|
|
431
500
|
};
|
|
432
501
|
|
|
433
502
|
return (
|
|
434
|
-
<div className="shg">
|
|
503
|
+
<div className="shg" ref={gridRef}>
|
|
435
504
|
<div className="shg-scroll">
|
|
436
505
|
<table className="shg-table">
|
|
437
506
|
<thead>
|
|
@@ -470,10 +539,7 @@ export function SheetGrid({
|
|
|
470
539
|
<tbody>
|
|
471
540
|
{rows.map((row, ri) => (
|
|
472
541
|
<tr key={row.id} data-row-id={row.id}
|
|
473
|
-
style={{
|
|
474
|
-
...(rowHeight(row) ? { height: rowHeight(row) } : null),
|
|
475
|
-
'--shg-clamp': Math.max(1, Math.floor(((rowHeight(row) || 34) - 10) / 18)),
|
|
476
|
-
}}>
|
|
542
|
+
style={rowHeight(row) ? { height: rowHeight(row) } : undefined}>
|
|
477
543
|
<td className={'shg-rownum' + dndClass('row', row.id)} style={numStyle}
|
|
478
544
|
title="Drag to reorder" {...dndProps('row', row.id)}>
|
|
479
545
|
<span>{ri + 1}</span>
|