@particle-academy/react-fancy 5.33.0 → 5.35.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/CHANGELOG.md +167 -0
- package/dist/activity-light.cjs +13 -0
- package/dist/activity-light.cjs.map +1 -0
- package/dist/activity-light.d.cts +64 -0
- package/dist/activity-light.d.ts +64 -0
- package/dist/activity-light.js +4 -0
- package/dist/activity-light.js.map +1 -0
- package/dist/button.cjs +4 -4
- package/dist/button.js +2 -2
- package/dist/{chunk-ZYVWKYPO.js → chunk-2OMB3OOR.js} +3 -3
- package/dist/{chunk-ZYVWKYPO.js.map → chunk-2OMB3OOR.js.map} +1 -1
- package/dist/{chunk-G6VMNSCM.js → chunk-46IPQEUP.js} +3 -3
- package/dist/{chunk-G6VMNSCM.js.map → chunk-46IPQEUP.js.map} +1 -1
- package/dist/{chunk-H6PXIB35.cjs → chunk-5Q7EQQTT.cjs} +4 -4
- package/dist/{chunk-H6PXIB35.cjs.map → chunk-5Q7EQQTT.cjs.map} +1 -1
- package/dist/{chunk-BQ77ZWFM.js → chunk-6ASZUE4T.js} +4 -4
- package/dist/{chunk-BQ77ZWFM.js.map → chunk-6ASZUE4T.js.map} +1 -1
- package/dist/{chunk-WEKQD4BQ.js → chunk-DCDW3LW6.js} +3 -3
- package/dist/{chunk-WEKQD4BQ.js.map → chunk-DCDW3LW6.js.map} +1 -1
- package/dist/{chunk-VRJTPXJ7.cjs → chunk-DNV7MUEE.cjs} +81 -20
- package/dist/chunk-DNV7MUEE.cjs.map +1 -0
- package/dist/{chunk-YMU3SS6D.cjs → chunk-E2SZBIAV.cjs} +16 -16
- package/dist/{chunk-YMU3SS6D.cjs.map → chunk-E2SZBIAV.cjs.map} +1 -1
- package/dist/chunk-EHNMKQ4O.cjs +71 -0
- package/dist/chunk-EHNMKQ4O.cjs.map +1 -0
- package/dist/chunk-IR6JSQ4O.cjs +233 -0
- package/dist/chunk-IR6JSQ4O.cjs.map +1 -0
- package/dist/{chunk-5TUZENNJ.cjs → chunk-MTUH2X3W.cjs} +4 -4
- package/dist/{chunk-5TUZENNJ.cjs.map → chunk-MTUH2X3W.cjs.map} +1 -1
- package/dist/{chunk-B4PFNSX7.js → chunk-O3WEV562.js} +79 -21
- package/dist/chunk-O3WEV562.js.map +1 -0
- package/dist/chunk-PZTA6NCD.js +69 -0
- package/dist/chunk-PZTA6NCD.js.map +1 -0
- package/dist/{chunk-UWL6U3L7.cjs → chunk-RMJGF7MN.cjs} +3 -3
- package/dist/{chunk-UWL6U3L7.cjs.map → chunk-RMJGF7MN.cjs.map} +1 -1
- package/dist/{chunk-EIUS2K72.js → chunk-TX6VUYBC.js} +3 -3
- package/dist/{chunk-EIUS2K72.js.map → chunk-TX6VUYBC.js.map} +1 -1
- package/dist/{chunk-LQFQ2UKU.cjs → chunk-WWUKTXPX.cjs} +3 -3
- package/dist/{chunk-LQFQ2UKU.cjs.map → chunk-WWUKTXPX.cjs.map} +1 -1
- package/dist/chunk-Z4CW3U6C.js +231 -0
- package/dist/chunk-Z4CW3U6C.js.map +1 -0
- package/dist/editor.cjs +4 -4
- package/dist/editor.js +2 -2
- package/dist/index-DXUAAZzE.d.cts +157 -0
- package/dist/index-DXUAAZzE.d.ts +157 -0
- package/dist/index.cjs +160 -138
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +27 -25
- package/dist/inputs.cjs +9 -9
- package/dist/inputs.js +3 -3
- package/dist/json-editor.cjs +15 -15
- package/dist/json-editor.js +4 -4
- package/dist/magic-wand.cjs +4 -4
- package/dist/magic-wand.js +3 -3
- package/dist/prompt-input.cjs +5 -4
- package/dist/prompt-input.d.cts +2 -77
- package/dist/prompt-input.d.ts +2 -77
- package/dist/prompt-input.js +4 -3
- package/dist/reason-tag.cjs +4 -4
- package/dist/reason-tag.js +3 -3
- package/dist/virtual-list.cjs +13 -0
- package/dist/virtual-list.cjs.map +1 -0
- package/dist/virtual-list.d.cts +125 -0
- package/dist/virtual-list.d.ts +125 -0
- package/dist/virtual-list.js +4 -0
- package/dist/virtual-list.js.map +1 -0
- package/package.json +23 -2
- package/dist/chunk-B4PFNSX7.js.map +0 -1
- package/dist/chunk-VRJTPXJ7.cjs.map +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkZU5Q77OT_cjs = require('./chunk-ZU5Q77OT.cjs');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
var ActivityLight = react.forwardRef(
|
|
8
|
+
({ level, direction, count = null, label, className, ...props }, ref) => {
|
|
9
|
+
if (level === null) return null;
|
|
10
|
+
const counted = typeof count === "number" && Number.isFinite(count);
|
|
11
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12
|
+
"span",
|
|
13
|
+
{
|
|
14
|
+
ref,
|
|
15
|
+
"data-react-fancy-activity-light": level,
|
|
16
|
+
...direction ? { "data-react-fancy-activity-light-direction": direction } : {},
|
|
17
|
+
"aria-label": counted ? `${label}: ${level}, ${count}` : `${label}: ${level}`,
|
|
18
|
+
role: "img",
|
|
19
|
+
className: chunkZU5Q77OT_cjs.cn(
|
|
20
|
+
"inline-flex items-center gap-1 align-middle",
|
|
21
|
+
LEVEL_CLASS[level],
|
|
22
|
+
className
|
|
23
|
+
),
|
|
24
|
+
...props,
|
|
25
|
+
children: [
|
|
26
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
27
|
+
"span",
|
|
28
|
+
{
|
|
29
|
+
"data-react-fancy-activity-light-dot": "",
|
|
30
|
+
"aria-hidden": "true",
|
|
31
|
+
className: chunkZU5Q77OT_cjs.cn("size-2 shrink-0 rounded-full bg-current", level === "live" && "animate-pulse")
|
|
32
|
+
}
|
|
33
|
+
),
|
|
34
|
+
direction && /* @__PURE__ */ jsxRuntime.jsx(
|
|
35
|
+
"span",
|
|
36
|
+
{
|
|
37
|
+
"data-react-fancy-activity-light-arrow": "",
|
|
38
|
+
"aria-hidden": "true",
|
|
39
|
+
className: "font-mono text-[0.625rem] leading-none",
|
|
40
|
+
children: DIRECTION_GLYPH[direction]
|
|
41
|
+
}
|
|
42
|
+
),
|
|
43
|
+
counted && /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
"span",
|
|
45
|
+
{
|
|
46
|
+
"data-react-fancy-activity-light-count": "",
|
|
47
|
+
className: "font-mono text-xs tabular-nums leading-none",
|
|
48
|
+
children: count
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
ActivityLight.displayName = "ActivityLight";
|
|
57
|
+
var LEVEL_CLASS = {
|
|
58
|
+
live: "text-emerald-500 dark:text-emerald-400",
|
|
59
|
+
recent: "text-sky-500 dark:text-sky-400",
|
|
60
|
+
quiet: "text-zinc-400 dark:text-zinc-500",
|
|
61
|
+
unseen: "text-amber-500 dark:text-amber-400"
|
|
62
|
+
};
|
|
63
|
+
var DIRECTION_GLYPH = {
|
|
64
|
+
in: "\u2190",
|
|
65
|
+
out: "\u2192",
|
|
66
|
+
both: "\u21C4"
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
exports.ActivityLight = ActivityLight;
|
|
70
|
+
//# sourceMappingURL=chunk-EHNMKQ4O.cjs.map
|
|
71
|
+
//# sourceMappingURL=chunk-EHNMKQ4O.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/ActivityLight/ActivityLight.tsx"],"names":["forwardRef","jsxs","cn","jsx"],"mappings":";;;;;;AAkCO,IAAM,aAAA,GAAgBA,gBAAA;AAAA,EAC3B,CAAC,EAAE,KAAA,EAAO,SAAA,EAAW,KAAA,GAAQ,IAAA,EAAM,KAAA,EAAO,SAAA,EAAW,GAAG,KAAA,EAAM,EAAG,GAAA,KAAQ;AAEvE,IAAA,IAAI,K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AA,EAEJ;AACF;AAEA,aAAA,CAAc,WAAA,GAAc,eAAA;AAM5B,IAAM,WAAA,GAA6C;AAAA,EACjD,IAAA,EAAM,wCAAA;AAAA,EACN,MAAA,EAAQ,gCAAA;AAAA,EACR,KAAA,EAAO,kCAAA;AAAA,EACP,MAAA,EAAQ;AACV,CAAA;AAEA,IAAM,eAAA,GAAyD;AAAA,EAC7D,EAAA,EAAI,QAAA;AAAA,EACJ,GAAA,EAAK,QAAA;AAAA,EACL,IAAA,EAAM;AACR,CAAA","file":"chunk-EHNMKQ4O.cjs","sourcesContent":["import { forwardRef } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport type { ActivityLightProps, ActivityLevel } from \"./ActivityLight.types\";\n\n/**\n * Activity on an **edge** — a relationship between two parties — with a recency\n * ramp and an optional volume.\n *\n * Not a presence dot. `Avatar status` belongs to one party and says whether\n * *they* are online; this belongs to a pair and says when *the link between\n * them* last moved. Use it in a comms column, a collaborator lane, anywhere the\n * subject is the relationship rather than the participant.\n *\n * ## Two kinds of nothing, and they must not look alike\n *\n * - **`level: null`** — the edge is real, its recency is not observable. Renders\n * NOTHING: no dot, no dash, no placeholder. A grey dot would assert \"quiet\",\n * which is a claim we cannot make.\n * - **`count: null`** or omitted — the edge's recency is known but its volume is\n * not. Renders the light with no number.\n * - **`count: 0`** — measured, and none. Renders `0`, because that is a fact.\n * Suppressing it would be indistinguishable from not having looked.\n *\n * The distinction reads as pedantic until a count is wrong in the direction\n * that flatters: a `0` where the truth is \"unknown\" tells the reader an agent\n * works alone, and they believe it.\n *\n * @example\n * ```tsx\n * <ActivityLight level=\"live\" direction=\"both\" count={12} label=\"Genie and Tynn\" />\n * <ActivityLight level=\"quiet\" count={0} label=\"Genie and Weaver\" />\n * <ActivityLight level={null} label=\"Genie and an unknown peer\" />\n * ```\n */\nexport const ActivityLight = forwardRef<HTMLSpanElement, ActivityLightProps>(\n ({ level, direction, count = null, label, className, ...props }, ref) => {\n // The one early return in the component, and the most important line in it.\n if (level === null) return null;\n\n const counted = typeof count === \"number\" && Number.isFinite(count);\n\n return (\n <span\n ref={ref}\n data-react-fancy-activity-light={level}\n {...(direction ? { \"data-react-fancy-activity-light-direction\": direction } : {})}\n aria-label={counted ? `${label}: ${level}, ${count}` : `${label}: ${level}`}\n role=\"img\"\n className={cn(\n \"inline-flex items-center gap-1 align-middle\",\n LEVEL_CLASS[level],\n className,\n )}\n {...props}\n >\n <span\n data-react-fancy-activity-light-dot=\"\"\n aria-hidden=\"true\"\n className={cn(\"size-2 shrink-0 rounded-full bg-current\", level === \"live\" && \"animate-pulse\")}\n />\n\n {direction && (\n <span\n data-react-fancy-activity-light-arrow=\"\"\n aria-hidden=\"true\"\n className=\"font-mono text-[0.625rem] leading-none\"\n >\n {DIRECTION_GLYPH[direction]}\n </span>\n )}\n\n {/* `counted` is the gate, NOT `count` — `0` is falsy and would vanish. */}\n {counted && (\n <span\n data-react-fancy-activity-light-count=\"\"\n className=\"font-mono text-xs tabular-nums leading-none\"\n >\n {count}\n </span>\n )}\n </span>\n );\n },\n);\n\nActivityLight.displayName = \"ActivityLight\";\n\n/**\n * The ramp. Each level is visually distinct from every other — a test asserts\n * that, because two levels that look alike make the ramp a lie.\n */\nconst LEVEL_CLASS: Record<ActivityLevel, string> = {\n live: \"text-emerald-500 dark:text-emerald-400\",\n recent: \"text-sky-500 dark:text-sky-400\",\n quiet: \"text-zinc-400 dark:text-zinc-500\",\n unseen: \"text-amber-500 dark:text-amber-400\",\n};\n\nconst DIRECTION_GLYPH: Record<\"in\" | \"out\" | \"both\", string> = {\n in: \"←\",\n out: \"→\",\n both: \"⇄\",\n};\n"]}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkZU5Q77OT_cjs = require('./chunk-ZU5Q77OT.cjs');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
function VirtualList({
|
|
8
|
+
items,
|
|
9
|
+
renderRow,
|
|
10
|
+
height = "100%",
|
|
11
|
+
estimateRowHeight = 32,
|
|
12
|
+
overscan = 6,
|
|
13
|
+
followTail = false,
|
|
14
|
+
onFollowChange,
|
|
15
|
+
onUnseenChange,
|
|
16
|
+
scrollToId = null,
|
|
17
|
+
onScrollToIdResolved,
|
|
18
|
+
className,
|
|
19
|
+
ref,
|
|
20
|
+
...props
|
|
21
|
+
}) {
|
|
22
|
+
const viewportRef = react.useRef(null);
|
|
23
|
+
const windowRef = react.useRef(null);
|
|
24
|
+
const heights = react.useRef(/* @__PURE__ */ new Map());
|
|
25
|
+
const [measured, setMeasured] = react.useState(0);
|
|
26
|
+
const [scrollTop, setScrollTop] = react.useState(0);
|
|
27
|
+
const [clientHeight, setClientHeight] = react.useState(0);
|
|
28
|
+
const attachViewport = react.useCallback(
|
|
29
|
+
(el) => {
|
|
30
|
+
viewportRef.current = el;
|
|
31
|
+
if (typeof ref === "function") ref(el);
|
|
32
|
+
else if (ref) ref.current = el;
|
|
33
|
+
},
|
|
34
|
+
[ref]
|
|
35
|
+
);
|
|
36
|
+
const viewport = clientHeight > 0 ? clientHeight : typeof height === "number" ? height : estimateRowHeight * 20;
|
|
37
|
+
const { offsets, total } = react.useMemo(() => {
|
|
38
|
+
const offs = new Float64Array(items.length + 1);
|
|
39
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
40
|
+
offs[i + 1] = offs[i] + (heights.current.get(items[i].id) ?? estimateRowHeight);
|
|
41
|
+
}
|
|
42
|
+
return { offsets: offs, total: items.length === 0 ? 0 : offs[items.length] };
|
|
43
|
+
}, [items, measured, estimateRowHeight]);
|
|
44
|
+
const indexAt = react.useCallback(
|
|
45
|
+
(y) => {
|
|
46
|
+
let lo = 0;
|
|
47
|
+
let hi = items.length - 1;
|
|
48
|
+
while (lo < hi) {
|
|
49
|
+
const mid = lo + hi + 1 >> 1;
|
|
50
|
+
if (offsets[mid] <= y) lo = mid;
|
|
51
|
+
else hi = mid - 1;
|
|
52
|
+
}
|
|
53
|
+
return Math.max(0, lo);
|
|
54
|
+
},
|
|
55
|
+
[items.length, offsets]
|
|
56
|
+
);
|
|
57
|
+
const start = Math.max(0, indexAt(scrollTop) - overscan);
|
|
58
|
+
const end = Math.min(items.length, indexAt(scrollTop + viewport) + 1 + overscan);
|
|
59
|
+
const visible = react.useMemo(() => items.slice(start, end), [items, start, end]);
|
|
60
|
+
const observer = react.useRef(null);
|
|
61
|
+
react.useEffect(() => {
|
|
62
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
63
|
+
const ro = new ResizeObserver(() => setMeasured((v) => v + 1));
|
|
64
|
+
observer.current = ro;
|
|
65
|
+
return () => {
|
|
66
|
+
ro.disconnect();
|
|
67
|
+
observer.current = null;
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
react.useLayoutEffect(() => {
|
|
71
|
+
const win = windowRef.current;
|
|
72
|
+
if (!win) return;
|
|
73
|
+
let changed = false;
|
|
74
|
+
for (const el of Array.from(win.children)) {
|
|
75
|
+
const id = el.getAttribute(ROW_ID_ATTR);
|
|
76
|
+
if (id === null) continue;
|
|
77
|
+
observer.current?.observe(el);
|
|
78
|
+
const h = el.getBoundingClientRect().height;
|
|
79
|
+
if (h > 0 && heights.current.get(id) !== h) {
|
|
80
|
+
heights.current.set(id, h);
|
|
81
|
+
changed = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const vp = viewportRef.current;
|
|
85
|
+
if (vp && vp.clientHeight > 0 && vp.clientHeight !== clientHeight) setClientHeight(vp.clientHeight);
|
|
86
|
+
if (changed) setMeasured((v) => v + 1);
|
|
87
|
+
});
|
|
88
|
+
const anchored = react.useRef(null);
|
|
89
|
+
const resolved = react.useRef(null);
|
|
90
|
+
react.useEffect(() => {
|
|
91
|
+
anchored.current = null;
|
|
92
|
+
resolved.current = null;
|
|
93
|
+
}, [scrollToId]);
|
|
94
|
+
react.useLayoutEffect(() => {
|
|
95
|
+
if (scrollToId === null || resolved.current === scrollToId) return;
|
|
96
|
+
const index = items.findIndex((item) => item.id === scrollToId);
|
|
97
|
+
if (index < 0) {
|
|
98
|
+
resolved.current = scrollToId;
|
|
99
|
+
onScrollToIdResolved?.(scrollToId, false);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const vp = viewportRef.current;
|
|
103
|
+
if (!vp) return;
|
|
104
|
+
const target = Math.max(0, Math.min(offsets[index], Math.max(0, total - viewport)));
|
|
105
|
+
if (anchored.current !== target) {
|
|
106
|
+
anchored.current = target;
|
|
107
|
+
vp.scrollTop = target;
|
|
108
|
+
setScrollTop(target);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (Math.abs(vp.scrollTop - target) <= 1) {
|
|
112
|
+
resolved.current = scrollToId;
|
|
113
|
+
onScrollToIdResolved?.(scrollToId, true);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
const reportedFollow = react.useRef(followTail);
|
|
117
|
+
const programmatic = react.useRef(false);
|
|
118
|
+
react.useEffect(() => {
|
|
119
|
+
reportedFollow.current = followTail;
|
|
120
|
+
}, [followTail]);
|
|
121
|
+
const askFollow = react.useCallback(
|
|
122
|
+
(next) => {
|
|
123
|
+
if (reportedFollow.current === next) return;
|
|
124
|
+
reportedFollow.current = next;
|
|
125
|
+
onFollowChange?.(next);
|
|
126
|
+
},
|
|
127
|
+
[onFollowChange]
|
|
128
|
+
);
|
|
129
|
+
react.useLayoutEffect(() => {
|
|
130
|
+
if (!followTail) return;
|
|
131
|
+
if (scrollToId !== null && resolved.current !== scrollToId) return;
|
|
132
|
+
const vp = viewportRef.current;
|
|
133
|
+
if (!vp) return;
|
|
134
|
+
const bottom = Math.max(0, total - viewport);
|
|
135
|
+
if (Math.abs(vp.scrollTop - bottom) > 0.5) {
|
|
136
|
+
programmatic.current = true;
|
|
137
|
+
vp.scrollTop = bottom;
|
|
138
|
+
setScrollTop(bottom);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const onScroll = react.useCallback(() => {
|
|
142
|
+
const vp = viewportRef.current;
|
|
143
|
+
if (!vp) return;
|
|
144
|
+
const next = vp.scrollTop;
|
|
145
|
+
const previous = scrollTop;
|
|
146
|
+
setScrollTop(next);
|
|
147
|
+
const bottom = Math.max(0, total - viewport);
|
|
148
|
+
const wasProgrammatic = programmatic.current;
|
|
149
|
+
programmatic.current = false;
|
|
150
|
+
if (next <= bottom - BOTTOM_SLACK) {
|
|
151
|
+
if (!wasProgrammatic && next < previous) askFollow(false);
|
|
152
|
+
} else {
|
|
153
|
+
askFollow(true);
|
|
154
|
+
}
|
|
155
|
+
}, [scrollTop, total, viewport, askFollow]);
|
|
156
|
+
const onWheel = react.useCallback(
|
|
157
|
+
(e) => {
|
|
158
|
+
if (e.deltaY < 0) askFollow(false);
|
|
159
|
+
},
|
|
160
|
+
[askFollow]
|
|
161
|
+
);
|
|
162
|
+
const onKeyDown = react.useCallback(
|
|
163
|
+
(e) => {
|
|
164
|
+
if (UPWARD_KEYS.has(e.key)) askFollow(false);
|
|
165
|
+
},
|
|
166
|
+
[askFollow]
|
|
167
|
+
);
|
|
168
|
+
const touchStart = react.useRef(null);
|
|
169
|
+
const onTouchStart = react.useCallback((e) => {
|
|
170
|
+
touchStart.current = e.touches[0]?.clientY ?? null;
|
|
171
|
+
}, []);
|
|
172
|
+
const onTouchMove = react.useCallback(
|
|
173
|
+
(e) => {
|
|
174
|
+
const from = touchStart.current;
|
|
175
|
+
const y = e.touches[0]?.clientY;
|
|
176
|
+
if (from !== null && y !== void 0 && y - from > TOUCH_SLOP) askFollow(false);
|
|
177
|
+
},
|
|
178
|
+
[askFollow]
|
|
179
|
+
);
|
|
180
|
+
const seen = react.useRef(items.length);
|
|
181
|
+
const reportedUnseen = react.useRef(null);
|
|
182
|
+
react.useEffect(() => {
|
|
183
|
+
const unseen = followTail ? 0 : Math.max(0, items.length - seen.current);
|
|
184
|
+
if (followTail) seen.current = items.length;
|
|
185
|
+
if (reportedUnseen.current === unseen) return;
|
|
186
|
+
reportedUnseen.current = unseen;
|
|
187
|
+
onUnseenChange?.(unseen);
|
|
188
|
+
}, [items.length, followTail, onUnseenChange]);
|
|
189
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
190
|
+
"div",
|
|
191
|
+
{
|
|
192
|
+
ref: attachViewport,
|
|
193
|
+
"data-react-fancy-virtual-list": "",
|
|
194
|
+
"data-react-fancy-virtual-list-following": followTail ? "true" : "false",
|
|
195
|
+
"data-react-fancy-virtual-list-rows": items.length,
|
|
196
|
+
role: "log",
|
|
197
|
+
tabIndex: 0,
|
|
198
|
+
className: chunkZU5Q77OT_cjs.cn("relative overflow-y-auto overflow-x-hidden outline-none", className),
|
|
199
|
+
style: { height },
|
|
200
|
+
onScroll,
|
|
201
|
+
onWheel,
|
|
202
|
+
onKeyDown,
|
|
203
|
+
onTouchStart,
|
|
204
|
+
onTouchMove,
|
|
205
|
+
...props,
|
|
206
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
207
|
+
"div",
|
|
208
|
+
{
|
|
209
|
+
"data-react-fancy-virtual-list-sizer": "",
|
|
210
|
+
style: { height: `${total}px`, position: "relative" },
|
|
211
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
212
|
+
"div",
|
|
213
|
+
{
|
|
214
|
+
ref: windowRef,
|
|
215
|
+
"data-react-fancy-virtual-list-window": "",
|
|
216
|
+
"data-react-fancy-virtual-list-start": start,
|
|
217
|
+
style: { transform: `translateY(${offsets[start] ?? 0}px)` },
|
|
218
|
+
children: visible.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx("div", { "data-react-fancy-virtual-row-id": item.id, children: renderRow(item, start + i) }, item.id))
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
var ROW_ID_ATTR = "data-react-fancy-virtual-row-id";
|
|
227
|
+
var BOTTOM_SLACK = 4;
|
|
228
|
+
var TOUCH_SLOP = 4;
|
|
229
|
+
var UPWARD_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "PageUp", "Home"]);
|
|
230
|
+
|
|
231
|
+
exports.VirtualList = VirtualList;
|
|
232
|
+
//# sourceMappingURL=chunk-IR6JSQ4O.cjs.map
|
|
233
|
+
//# sourceMappingURL=chunk-IR6JSQ4O.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/VirtualList/VirtualList.tsx"],"names":["useRef","useState","useCallback","useMemo","useEffect","useLayoutEffect","jsx","cn"],"mappings":";;;;;;AA4DO,SAAS,WAAA,CAAsC;AAAA,EACpD,KAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA,GAAS,MAAA;AAAA,EACT,iBAAA,GAAoB,EAAA;AAAA,EACpB,QAAA,GAAW,CAAA;AAAA,EACX,UAAA,GAAa,KAAA;AAAA,EACb,cAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA,GAAa,IAAA;AAAA,EACb,oBAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAwB;AACtB,EAAA,MAAM,WAAA,GAAcA,aAA8B,IAAI,CAAA;AACtD,EAAA,MAAM,SAAA,GAAYA,aAA8B,IAAI,CAAA;AAGpD,EAAA,MAAM,OAAA,GAAUA,YAAA,iBAAO,IAAI,GAAA,EAAqB,CAAA;AAEhD,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAIC,eAAS,CAAC,CAAA;AAE1C,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAIA,eAAS,CAAC,CAAA;AAC5C,EAAA,MAAM,CAAC,YAAA,EAAc,eAAe,CAAA,GAAIA,eAAS,CAAC,CAAA;AAElD,EAAA,MAAM,cAAA,GAAiBC,iBAAA;AAAA,IACrB,CAAC,EAAA,KAA8B;AAC7B,MAAA,WAAA,CAAY,OAAA,GAAU,EAAA;AACt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CAAA,EAAqC,EAAA;AAAA,cACrC,qCAAA,EAAqC,KAAA;AAAA,cACrC,KAAA,EAAO,EAAE,SAAA,EAAW,CAAA,WAAA,EAAc,QAAQ,KAAK,CAAA,IAAK,CAAC,CAAA,GAAA,CAAA,EAAM;AAAA,cAE1D,kBAAQ,GAAA,CAAI,CAAC,IAAA,EAAM,CAAA,oCACjB,KAAA,EAAA,EAAkB,iCAAA,EAAiC,IAAA,CAAK,EAAA,EACtD,oBAAU,IAAA,EAAM,KAAA,GAAQ,CAAC,CAAA,EAAA,EADlB,IAAA,CAAK,EAEf,CACD;AAAA;AAAA;AACH;AAAA;AACF;AAAA,GACF;AAEJ;AAEA,IAAM,WAAA,GAAc,iCAAA;AAEpB,IAAM,YAAA,GAAe,CAAA;AAErB,IAAM,UAAA,GAAa,CAAA;AACnB,IAAM,8BAAc,IAAI,GAAA,CAAI,CAAC,SAAA,EAAW,QAAA,EAAU,MAAM,CAAC,CAAA","file":"chunk-IR6JSQ4O.cjs","sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, TouchEvent, WheelEvent } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport type { VirtualListProps, VirtualListRow } from \"./VirtualList.types\";\n\n/**\n * A windowed list for ledgers that run to tens of thousands of rows — only the\n * visible slice is in the DOM, with **measured** variable row heights, deep\n * links by row id, and sticky-bottom tail-following.\n *\n * Built for an agent event stream, where every one of those three is load\n * bearing at once: message rows wrap and event rows do not, a link carries\n * `?at=<rowId>` to the exact row under discussion, and new rows arrive while\n * the human is reading older ones.\n *\n * ## Heights are measured, never predicted\n *\n * `estimateRowHeight` only seeds rows that have never been on screen. The\n * moment a row renders, its real height is measured and replaces the estimate,\n * and every offset after it moves. The alternative — a `rowHeight(item)`\n * callback — is a prediction about text wrapping, font loading and container\n * width, and when it is wrong the error accumulates down the list: rows draw in\n * the wrong place and `scrollToId` lands on a neighbour. Measuring is slower to\n * settle and correct when it does.\n *\n * ## Tail-follow breaks on INTENT, not on position\n *\n * Any upward gesture — wheel, drag, PageUp, Home — stops following\n * immediately, even when the list is still pinned to the bottom and\n * `scrollTop` has not changed yet. Position cannot tell \"the human scrolled\n * up\" from \"content grew downward\", so a position-only implementation keeps\n * following through a wheel-up and yanks the reader back on the next append.\n *\n * ## It is controlled\n *\n * `followTail` is the consumer's state. This component only ever *asks* via\n * `onFollowChange`, so the follow state is readable and writable by an agent\n * over a bridge, as the Human+ component contract requires. The `↓ n new` pill\n * is the consumer's to render, from `onUnseenChange`.\n *\n * @example\n * ```tsx\n * const [following, setFollowing] = useState(true);\n * const [unseen, setUnseen] = useState(0);\n *\n * <VirtualList\n * items={events}\n * renderRow={(e) => <StreamRow event={e} />}\n * height=\"100%\"\n * estimateRowHeight={28}\n * followTail={following}\n * onFollowChange={setFollowing}\n * onUnseenChange={setUnseen}\n * scrollToId={params.at}\n * />\n * {!following && unseen > 0 && (\n * <Button onClick={() => setFollowing(true)}>↓ {unseen} new</Button>\n * )}\n * ```\n */\nexport function VirtualList<T extends VirtualListRow>({\n items,\n renderRow,\n height = \"100%\",\n estimateRowHeight = 32,\n overscan = 6,\n followTail = false,\n onFollowChange,\n onUnseenChange,\n scrollToId = null,\n onScrollToIdResolved,\n className,\n ref,\n ...props\n}: VirtualListProps<T>) {\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n\n /** Measured heights by row id, so a height follows its row across a reindex. */\n const heights = useRef(new Map<string, number>());\n /** Bumped when a measurement actually changed, to recompute offsets. */\n const [measured, setMeasured] = useState(0);\n\n const [scrollTop, setScrollTop] = useState(0);\n const [clientHeight, setClientHeight] = useState(0);\n\n const attachViewport = useCallback(\n (el: HTMLDivElement | null) => {\n viewportRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) (ref as { current: HTMLDivElement | null }).current = el;\n },\n [ref],\n );\n\n // A number `height` IS the viewport height, and is usable before the element\n // has been measured. Without one, render a conservative first window so there\n // is something on screen for the measurement pass to work from.\n const viewport =\n clientHeight > 0 ? clientHeight : typeof height === \"number\" ? height : estimateRowHeight * 20;\n\n /**\n * Prefix sums of row heights: `offsets[i]` is where row `i` starts, and the\n * last entry is the total. Rebuilt whenever rows or measurements change —\n * O(n) once per change, against O(log n) per scroll from the binary search,\n * rather than O(n) on every scroll frame.\n */\n const { offsets, total } = useMemo(() => {\n const offs = new Float64Array(items.length + 1);\n for (let i = 0; i < items.length; i += 1) {\n offs[i + 1] = offs[i] + (heights.current.get(items[i].id) ?? estimateRowHeight);\n }\n\n return { offsets: offs, total: items.length === 0 ? 0 : offs[items.length] };\n }, [items, measured, estimateRowHeight]);\n\n /** First row whose span contains `y`. */\n const indexAt = useCallback(\n (y: number): number => {\n let lo = 0;\n let hi = items.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (offsets[mid] <= y) lo = mid;\n else hi = mid - 1;\n }\n\n return Math.max(0, lo);\n },\n [items.length, offsets],\n );\n\n const start = Math.max(0, indexAt(scrollTop) - overscan);\n const end = Math.min(items.length, indexAt(scrollTop + viewport) + 1 + overscan);\n const visible = useMemo(() => items.slice(start, end), [items, start, end]);\n\n // ---------------------------------------------------------------- measuring\n\n const observer = useRef<ResizeObserver | null>(null);\n\n useEffect(() => {\n // Absent in jsdom and in older runtimes. Without it the list still measures\n // on every render; it just does not notice a row reflowing in place.\n if (typeof ResizeObserver === \"undefined\") return;\n\n const ro = new ResizeObserver(() => setMeasured((v) => v + 1));\n observer.current = ro;\n\n return () => {\n ro.disconnect();\n observer.current = null;\n };\n }, []);\n\n // No dependency array on purpose: every render re-measures what is on screen,\n // and the `changed` guard is what stops it looping. A render that learns\n // nothing new sets no state.\n useLayoutEffect(() => {\n const win = windowRef.current;\n if (!win) return;\n\n let changed = false;\n for (const el of Array.from(win.children) as HTMLElement[]) {\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n observer.current?.observe(el);\n\n const h = el.getBoundingClientRect().height;\n // A zero height is \"not laid out yet\", not a 0px row. Recording it would\n // collapse the list and make every offset after it wrong.\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n const vp = viewportRef.current;\n if (vp && vp.clientHeight > 0 && vp.clientHeight !== clientHeight) setClientHeight(vp.clientHeight);\n\n if (changed) setMeasured((v) => v + 1);\n });\n\n // ------------------------------------------------------------- deep linking\n\n /** The target this component last moved to, to detect that it has settled. */\n const anchored = useRef<number | null>(null);\n const resolved = useRef<string | null>(null);\n\n useEffect(() => {\n // A new id is a new request, even if the old one had resolved.\n anchored.current = null;\n resolved.current = null;\n }, [scrollToId]);\n\n useLayoutEffect(() => {\n if (scrollToId === null || resolved.current === scrollToId) return;\n\n const index = items.findIndex((item) => item.id === scrollToId);\n if (index < 0) {\n // A link to a row that is no longer in the list. Leaving the viewport\n // where it is and SAYING SO is the only honest outcome — scrolling to the\n // top would be indistinguishable from a successful landing.\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, false);\n\n return;\n }\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n // Clamped the way the browser clamps: a row inside the final viewport-height\n // of the list cannot be brought to the top, and pretending otherwise would\n // leave this waiting for a position that can never be reached.\n const target = Math.max(0, Math.min(offsets[index], Math.max(0, total - viewport)));\n\n if (anchored.current !== target) {\n anchored.current = target;\n vp.scrollTop = target;\n setScrollTop(target);\n\n return;\n }\n\n // The target stopped moving as rows above it were measured, and we are on\n // it. Only now is the deep link actually honoured.\n if (Math.abs(vp.scrollTop - target) <= 1) {\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, true);\n }\n });\n\n // ------------------------------------------------------------- tail-follow\n\n const reportedFollow = useRef(followTail);\n const programmatic = useRef(false);\n\n useEffect(() => {\n // The prop is the truth, so adopt it rather than remembering what we asked\n // for. Otherwise a consumer that declines an `onFollowChange(false)` would\n // never be asked again.\n reportedFollow.current = followTail;\n }, [followTail]);\n\n const askFollow = useCallback(\n (next: boolean) => {\n if (reportedFollow.current === next) return;\n reportedFollow.current = next;\n onFollowChange?.(next);\n },\n [onFollowChange],\n );\n\n useLayoutEffect(() => {\n if (!followTail) return;\n // A pending deep link wins while it resolves; otherwise the two would fight\n // over the same scrollTop and the link would lose.\n if (scrollToId !== null && resolved.current !== scrollToId) return;\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n const bottom = Math.max(0, total - viewport);\n if (Math.abs(vp.scrollTop - bottom) > 0.5) {\n programmatic.current = true;\n vp.scrollTop = bottom;\n setScrollTop(bottom);\n }\n });\n\n const onScroll = useCallback(() => {\n const vp = viewportRef.current;\n if (!vp) return;\n\n const next = vp.scrollTop;\n const previous = scrollTop;\n setScrollTop(next);\n\n const bottom = Math.max(0, total - viewport);\n const wasProgrammatic = programmatic.current;\n programmatic.current = false;\n\n if (next <= bottom - BOTTOM_SLACK) {\n // Moved up, and not because we moved it.\n if (!wasProgrammatic && next < previous) askFollow(false);\n } else {\n askFollow(true);\n }\n }, [scrollTop, total, viewport, askFollow]);\n\n /** Any upward gesture is a statement of intent, whatever scrollTop says. */\n const onWheel = useCallback(\n (e: WheelEvent<HTMLDivElement>) => {\n if (e.deltaY < 0) askFollow(false);\n },\n [askFollow],\n );\n\n const onKeyDown = useCallback(\n (e: KeyboardEvent<HTMLDivElement>) => {\n if (UPWARD_KEYS.has(e.key)) askFollow(false);\n },\n [askFollow],\n );\n\n const touchStart = useRef<number | null>(null);\n\n const onTouchStart = useCallback((e: TouchEvent<HTMLDivElement>) => {\n touchStart.current = e.touches[0]?.clientY ?? null;\n }, []);\n\n const onTouchMove = useCallback(\n (e: TouchEvent<HTMLDivElement>) => {\n const from = touchStart.current;\n const y = e.touches[0]?.clientY;\n // Finger travelling DOWN drags the content down, which scrolls up.\n if (from !== null && y !== undefined && y - from > TOUCH_SLOP) askFollow(false);\n },\n [askFollow],\n );\n\n // ------------------------------------------------------------ unseen count\n\n const seen = useRef(items.length);\n const reportedUnseen = useRef<number | null>(null);\n\n useEffect(() => {\n const unseen = followTail ? 0 : Math.max(0, items.length - seen.current);\n if (followTail) seen.current = items.length;\n\n if (reportedUnseen.current === unseen) return;\n reportedUnseen.current = unseen;\n onUnseenChange?.(unseen);\n }, [items.length, followTail, onUnseenChange]);\n\n // ------------------------------------------------------------------ render\n\n return (\n <div\n ref={attachViewport}\n data-react-fancy-virtual-list=\"\"\n data-react-fancy-virtual-list-following={followTail ? \"true\" : \"false\"}\n data-react-fancy-virtual-list-rows={items.length}\n role=\"log\"\n tabIndex={0}\n className={cn(\"relative overflow-y-auto overflow-x-hidden outline-none\", className)}\n style={{ height }}\n onScroll={onScroll}\n onWheel={onWheel}\n onKeyDown={onKeyDown}\n onTouchStart={onTouchStart}\n onTouchMove={onTouchMove}\n {...props}\n >\n {/* Holds the full scroll range so the scrollbar is honest from the first\n paint, instead of growing as rows are discovered. */}\n <div\n data-react-fancy-virtual-list-sizer=\"\"\n style={{ height: `${total}px`, position: \"relative\" }}\n >\n <div\n ref={windowRef}\n data-react-fancy-virtual-list-window=\"\"\n data-react-fancy-virtual-list-start={start}\n style={{ transform: `translateY(${offsets[start] ?? 0}px)` }}\n >\n {visible.map((item, i) => (\n <div key={item.id} data-react-fancy-virtual-row-id={item.id}>\n {renderRow(item, start + i)}\n </div>\n ))}\n </div>\n </div>\n </div>\n );\n}\n\nconst ROW_ID_ATTR = \"data-react-fancy-virtual-row-id\";\n/** Within this many px of the bottom counts as \"at the bottom\". */\nconst BOTTOM_SLACK = 4;\n/** Ignore a touch jitter smaller than this before calling it an upward drag. */\nconst TOUCH_SLOP = 4;\nconst UPWARD_KEYS = new Set([\"ArrowUp\", \"PageUp\", \"Home\"]);\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkWKNVZUWZ_cjs = require('./chunk-WKNVZUWZ.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunkRMJGF7MN_cjs = require('./chunk-RMJGF7MN.cjs');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
|
|
7
7
|
var CONFIDENCE_TIERS = [
|
|
@@ -109,11 +109,11 @@ function ReasonTag({
|
|
|
109
109
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[10px] uppercase tracking-wider text-zinc-400", children: "sources" }),
|
|
110
110
|
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "mt-0.5 space-y-0.5 text-[12px]", children: sources.map((s, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: s.href ? /* @__PURE__ */ jsxRuntime.jsx("a", { className: "text-violet-600 hover:underline", href: s.href, children: s.label }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-zinc-600 dark:text-zinc-300", children: s.label }) }, i)) })
|
|
111
111
|
] }),
|
|
112
|
-
onFollowUp && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end pt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
112
|
+
onFollowUp && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end pt-1", children: /* @__PURE__ */ jsxRuntime.jsx(chunkRMJGF7MN_cjs.Button, { size: "sm", variant: "ghost", onClick: onFollowUp, children: "ask follow-up" }) })
|
|
113
113
|
] }) })
|
|
114
114
|
] });
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
exports.ReasonTag = ReasonTag;
|
|
118
|
-
//# sourceMappingURL=chunk-
|
|
119
|
-
//# sourceMappingURL=chunk-
|
|
118
|
+
//# sourceMappingURL=chunk-MTUH2X3W.cjs.map
|
|
119
|
+
//# sourceMappingURL=chunk-MTUH2X3W.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/ReasonTag/ReasonTag.tsx"],"names":["jsxs","jsx","Popover","Button"],"mappings":";;;;;;AAuDA,IAAM,gBAAA,GAAyE;AAAA,EAC7E,EAAE,GAAA,EAAK,IAAA,EAAM,KAAA,EAAO,SAAA,EAAW,OA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cAAA,CAAC,IAAA,EAAA,EACE,QAAA,EAAA,CAAA,CAAE,IAAA,kCACA,GAAA,EAAA,EAAE,SAAA,EAAU,iCAAA,EAAkC,IAAA,EAAM,CAAA,CAAE,IAAA,EACpD,QAAA,EAAA,CAAA,CAAE,KAAA,EACL,oBAEAA,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,kCAAA,EACb,QAAA,EAAA,CAAA,CAAE,KAAA,EACL,CAAA,EAAA,EARK,CAUT,CACD,CAAA,EACH;AAAA,OAAA,EACF,CAAA;AAAA,MAED,UAAA,oBACCA,cAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,yBACb,QAAA,kBAAAA,cAAA,CAACE,wBAAA,EAAA,EAAO,IAAA,EAAK,IAAA,EAAK,OAAA,EAAQ,OAAA,EAAQ,OAAA,EAAS,UAAA,EAAY,2BAEvD,CAAA,EACF;AAAA,KAAA,EAEJ,CAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"chunk-5TUZENNJ.cjs","sourcesContent":["import { Popover } from \"../Popover\";\nimport { Button } from \"../Button\";\n\n/**\n * ReasonTag — wraps any value with a small affordance that reveals the\n * agent's reasoning, sources, and confidence on hover or click.\n *\n * <ReasonTag\n * value=\"$1.4M\"\n * reason=\"Projected Q3 ARR after stacking renewals.\"\n * confidence={0.91}\n * sources={[{ label: \"Q2 actuals · CRM export\" }]}\n * by=\"Forecaster\"\n * />\n *\n * Three visual styles:\n * • \"dot\" — value with a tiny coloured dot (default, subtle)\n * • \"underline\" — dotted underline + trailing \"?\"\n * • \"chip\" — full coloured pill (loud)\n *\n * Confidence drives the colour via three tiers (high / medium / low),\n * so a quick visual scan tells the human which suggestions deserve a\n * second look without opening any tooltips.\n *\n * `pinned` swaps the popover for an inline annotation slot — useful\n * when explainability should always be visible, not buried in a hover.\n */\nexport type ReasonTagSource = { label: string; href?: string };\n\nexport type ReasonTagTheme = \"dot\" | \"underline\" | \"chip\";\n\nexport interface ReasonTagProps {\n /** The value the tag wraps — usually a number, label, or short phrase. */\n value: React.ReactNode;\n /** Free-text rationale shown in the popover / inline annotation. */\n reason: string;\n /** 0..1 confidence. Drives the tier colour. Defaults to 1. */\n confidence?: number;\n /** Optional list of sources (label + optional href). */\n sources?: ReasonTagSource[];\n /** Optional author / agent name shown in the popover header. */\n by?: string;\n /** Visual treatment for the trigger. */\n theme?: ReasonTagTheme;\n /**\n * When true, the popover is replaced with an always-visible inline\n * annotation below the value.\n */\n pinned?: boolean;\n /** Called when the user hits the \"ask follow-up\" action. */\n onFollowUp?: () => void;\n /** Optional className applied to the trigger element. */\n className?: string;\n}\n\nconst CONFIDENCE_TIERS: Array<{ min: number; color: string; label: string }> = [\n { min: 0.85, color: \"#10b981\", label: \"high\" },\n { min: 0.6, color: \"#f59e0b\", label: \"medium\" },\n { min: 0, color: \"#ef4444\", label: \"low\" },\n];\n\nfunction tier(c: number) {\n return CONFIDENCE_TIERS.find((t) => c >= t.min) ?? CONFIDENCE_TIERS[2];\n}\n\nexport function ReasonTag({\n value,\n reason,\n confidence = 1,\n sources = [],\n by,\n theme = \"dot\",\n pinned = false,\n onFollowUp,\n className,\n}: ReasonTagProps) {\n const t = tier(confidence);\n\n const trigger =\n theme === \"chip\" ? (\n <span\n className={`inline-flex cursor-help items-center gap-1 rounded-full px-2 py-0.5 text-[12px] font-medium ${className ?? \"\"}`}\n style={{ backgroundColor: t.color + \"22\", color: t.color }}\n >\n <span\n className=\"h-1.5 w-1.5 rounded-full\"\n style={{ backgroundColor: t.color }}\n />\n {value}\n <span className=\"text-[10px] opacity-70\">?</span>\n </span>\n ) : theme === \"underline\" ? (\n <span\n className={`cursor-help underline decoration-dotted underline-offset-2 ${className ?? \"\"}`}\n style={{ textDecorationColor: t.color }}\n >\n {value}\n <span\n className=\"ml-0.5 font-mono text-[10px]\"\n style={{ color: t.color }}\n >\n ?\n </span>\n </span>\n ) : (\n <span className={`inline-flex cursor-help items-baseline gap-1 ${className ?? \"\"}`}>\n <span className=\"font-medium\">{value}</span>\n <span\n className=\"inline-block h-1.5 w-1.5 rounded-full align-middle\"\n style={{ backgroundColor: t.color }}\n title=\"reason available\"\n />\n </span>\n );\n\n if (pinned) {\n return (\n <span className=\"inline-flex flex-col items-start gap-0.5 align-top\">\n {trigger}\n <span\n className=\"block max-w-[280px] rounded border-l-2 pl-2 text-[11px] leading-snug text-zinc-600 dark:text-zinc-300\"\n style={{ borderColor: t.color }}\n >\n {reason}\n </span>\n </span>\n );\n }\n\n return (\n <Popover hover>\n <Popover.Trigger>{trigger}</Popover.Trigger>\n <Popover.Content>\n <div className=\"w-72 space-y-2 text-sm\">\n <div className=\"flex items-baseline gap-2\">\n <span\n className=\"text-[10px] font-semibold uppercase tracking-wider\"\n style={{ color: t.color }}\n >\n {t.label} confidence · {(confidence * 100).toFixed(0)}%\n </span>\n {by && (\n <span className=\"ml-auto font-mono text-[10px] text-zinc-400\">\n @{by}\n </span>\n )}\n </div>\n <p className=\"text-[13px] leading-snug text-zinc-700 dark:text-zinc-200\">\n {reason}\n </p>\n {sources.length > 0 && (\n <div>\n <div className=\"text-[10px] uppercase tracking-wider text-zinc-400\">\n sources\n </div>\n <ul className=\"mt-0.5 space-y-0.5 text-[12px]\">\n {sources.map((s, i) => (\n <li key={i}>\n {s.href ? (\n <a className=\"text-violet-600 hover:underline\" href={s.href}>\n {s.label}\n </a>\n ) : (\n <span className=\"text-zinc-600 dark:text-zinc-300\">\n {s.label}\n </span>\n )}\n </li>\n ))}\n </ul>\n </div>\n )}\n {onFollowUp && (\n <div className=\"flex justify-end pt-1\">\n <Button size=\"sm\" variant=\"ghost\" onClick={onFollowUp}>\n ask follow-up\n </Button>\n </div>\n )}\n </div>\n </Popover.Content>\n </Popover>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/components/ReasonTag/ReasonTag.tsx"],"names":["jsxs","jsx","Popover","Button"],"mappings":";;;;;;AAuDA,IAAM,gBAAA,GAAyE;AAAA,EAC7E,EAAE,GAAA,EAAK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A,CAAI,CAAC,CAAA,EAAG,CAAA,qBACfA,cAAA,CAAC,IAAA,EAAA,EACE,QAAA,EAAA,CAAA,CAAE,IAAA,kCACA,GAAA,EAAA,EAAE,SAAA,EAAU,iCAAA,EAAkC,IAAA,EAAM,CAAA,CAAE,IAAA,EACpD,QAAA,EAAA,CAAA,CAAE,KAAA,EACL,oBAEAA,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,kCAAA,EACb,QAAA,EAAA,CAAA,CAAE,KAAA,EACL,CAAA,EAAA,EARK,CAUT,CACD,CAAA,EACH;AAAA,OAAA,EACF,CAAA;AAAA,MAED,UAAA,oBACCA,cAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,yBACb,QAAA,kBAAAA,cAAA,CAACE,wBAAA,EAAA,EAAO,IAAA,EAAK,IAAA,EAAK,OAAA,EAAQ,OAAA,EAAQ,OAAA,EAAS,UAAA,EAAY,2BAEvD,CAAA,EACF;AAAA,KAAA,EAEJ,CAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"chunk-MTUH2X3W.cjs","sourcesContent":["import { Popover } from \"../Popover\";\nimport { Button } from \"../Button\";\n\n/**\n * ReasonTag — wraps any value with a small affordance that reveals the\n * agent's reasoning, sources, and confidence on hover or click.\n *\n * <ReasonTag\n * value=\"$1.4M\"\n * reason=\"Projected Q3 ARR after stacking renewals.\"\n * confidence={0.91}\n * sources={[{ label: \"Q2 actuals · CRM export\" }]}\n * by=\"Forecaster\"\n * />\n *\n * Three visual styles:\n * • \"dot\" — value with a tiny coloured dot (default, subtle)\n * • \"underline\" — dotted underline + trailing \"?\"\n * • \"chip\" — full coloured pill (loud)\n *\n * Confidence drives the colour via three tiers (high / medium / low),\n * so a quick visual scan tells the human which suggestions deserve a\n * second look without opening any tooltips.\n *\n * `pinned` swaps the popover for an inline annotation slot — useful\n * when explainability should always be visible, not buried in a hover.\n */\nexport type ReasonTagSource = { label: string; href?: string };\n\nexport type ReasonTagTheme = \"dot\" | \"underline\" | \"chip\";\n\nexport interface ReasonTagProps {\n /** The value the tag wraps — usually a number, label, or short phrase. */\n value: React.ReactNode;\n /** Free-text rationale shown in the popover / inline annotation. */\n reason: string;\n /** 0..1 confidence. Drives the tier colour. Defaults to 1. */\n confidence?: number;\n /** Optional list of sources (label + optional href). */\n sources?: ReasonTagSource[];\n /** Optional author / agent name shown in the popover header. */\n by?: string;\n /** Visual treatment for the trigger. */\n theme?: ReasonTagTheme;\n /**\n * When true, the popover is replaced with an always-visible inline\n * annotation below the value.\n */\n pinned?: boolean;\n /** Called when the user hits the \"ask follow-up\" action. */\n onFollowUp?: () => void;\n /** Optional className applied to the trigger element. */\n className?: string;\n}\n\nconst CONFIDENCE_TIERS: Array<{ min: number; color: string; label: string }> = [\n { min: 0.85, color: \"#10b981\", label: \"high\" },\n { min: 0.6, color: \"#f59e0b\", label: \"medium\" },\n { min: 0, color: \"#ef4444\", label: \"low\" },\n];\n\nfunction tier(c: number) {\n return CONFIDENCE_TIERS.find((t) => c >= t.min) ?? CONFIDENCE_TIERS[2];\n}\n\nexport function ReasonTag({\n value,\n reason,\n confidence = 1,\n sources = [],\n by,\n theme = \"dot\",\n pinned = false,\n onFollowUp,\n className,\n}: ReasonTagProps) {\n const t = tier(confidence);\n\n const trigger =\n theme === \"chip\" ? (\n <span\n className={`inline-flex cursor-help items-center gap-1 rounded-full px-2 py-0.5 text-[12px] font-medium ${className ?? \"\"}`}\n style={{ backgroundColor: t.color + \"22\", color: t.color }}\n >\n <span\n className=\"h-1.5 w-1.5 rounded-full\"\n style={{ backgroundColor: t.color }}\n />\n {value}\n <span className=\"text-[10px] opacity-70\">?</span>\n </span>\n ) : theme === \"underline\" ? (\n <span\n className={`cursor-help underline decoration-dotted underline-offset-2 ${className ?? \"\"}`}\n style={{ textDecorationColor: t.color }}\n >\n {value}\n <span\n className=\"ml-0.5 font-mono text-[10px]\"\n style={{ color: t.color }}\n >\n ?\n </span>\n </span>\n ) : (\n <span className={`inline-flex cursor-help items-baseline gap-1 ${className ?? \"\"}`}>\n <span className=\"font-medium\">{value}</span>\n <span\n className=\"inline-block h-1.5 w-1.5 rounded-full align-middle\"\n style={{ backgroundColor: t.color }}\n title=\"reason available\"\n />\n </span>\n );\n\n if (pinned) {\n return (\n <span className=\"inline-flex flex-col items-start gap-0.5 align-top\">\n {trigger}\n <span\n className=\"block max-w-[280px] rounded border-l-2 pl-2 text-[11px] leading-snug text-zinc-600 dark:text-zinc-300\"\n style={{ borderColor: t.color }}\n >\n {reason}\n </span>\n </span>\n );\n }\n\n return (\n <Popover hover>\n <Popover.Trigger>{trigger}</Popover.Trigger>\n <Popover.Content>\n <div className=\"w-72 space-y-2 text-sm\">\n <div className=\"flex items-baseline gap-2\">\n <span\n className=\"text-[10px] font-semibold uppercase tracking-wider\"\n style={{ color: t.color }}\n >\n {t.label} confidence · {(confidence * 100).toFixed(0)}%\n </span>\n {by && (\n <span className=\"ml-auto font-mono text-[10px] text-zinc-400\">\n @{by}\n </span>\n )}\n </div>\n <p className=\"text-[13px] leading-snug text-zinc-700 dark:text-zinc-200\">\n {reason}\n </p>\n {sources.length > 0 && (\n <div>\n <div className=\"text-[10px] uppercase tracking-wider text-zinc-400\">\n sources\n </div>\n <ul className=\"mt-0.5 space-y-0.5 text-[12px]\">\n {sources.map((s, i) => (\n <li key={i}>\n {s.href ? (\n <a className=\"text-violet-600 hover:underline\" href={s.href}>\n {s.label}\n </a>\n ) : (\n <span className=\"text-zinc-600 dark:text-zinc-300\">\n {s.label}\n </span>\n )}\n </li>\n ))}\n </ul>\n </div>\n )}\n {onFollowUp && (\n <div className=\"flex justify-end pt-1\">\n <Button size=\"sm\" variant=\"ghost\" onClick={onFollowUp}>\n ask follow-up\n </Button>\n </div>\n )}\n </div>\n </Popover.Content>\n </Popover>\n );\n}\n"]}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
import { Tooltip } from './chunk-35EN5AYE.js';
|
|
2
|
-
import { Button } from './chunk-
|
|
3
|
-
import {
|
|
2
|
+
import { Button } from './chunk-46IPQEUP.js';
|
|
3
|
+
import { Icon } from './chunk-IVRYSSM7.js';
|
|
4
|
+
import { cn } from './chunk-MMW2JGKZ.js';
|
|
5
|
+
import { useState, useRef, useEffect, useMemo } from 'react';
|
|
4
6
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
7
|
|
|
8
|
+
// src/utils/platform.ts
|
|
9
|
+
var APPLE_UA_DATA_PLATFORMS = /* @__PURE__ */ new Set(["macos", "ios", "ipados"]);
|
|
10
|
+
var APPLE_FREE_TEXT = /\b(mac|macintosh|iphone|ipad|ipod|darwin)/i;
|
|
11
|
+
function detectPlatform(hints) {
|
|
12
|
+
if (!hints) return "generic";
|
|
13
|
+
const uaData = hints.userAgentData?.platform;
|
|
14
|
+
if (typeof uaData === "string" && uaData.length > 0) {
|
|
15
|
+
return APPLE_UA_DATA_PLATFORMS.has(uaData.trim().toLowerCase()) ? "apple" : "generic";
|
|
16
|
+
}
|
|
17
|
+
for (const value of [hints.platform, hints.userAgent]) {
|
|
18
|
+
if (typeof value === "string" && APPLE_FREE_TEXT.test(value)) return "apple";
|
|
19
|
+
}
|
|
20
|
+
return "generic";
|
|
21
|
+
}
|
|
22
|
+
function modifierKeyLabel(platform) {
|
|
23
|
+
return platform === "apple" ? "\u2318" : "Ctrl";
|
|
24
|
+
}
|
|
25
|
+
function browserPlatformHints() {
|
|
26
|
+
if (typeof navigator === "undefined") return null;
|
|
27
|
+
return navigator;
|
|
28
|
+
}
|
|
6
29
|
var DEFAULT_MENTION_COLOR = {
|
|
7
30
|
agent: "#a855f7",
|
|
8
31
|
file: "#10b981",
|
|
@@ -13,12 +36,15 @@ function PromptInput({
|
|
|
13
36
|
commands = [],
|
|
14
37
|
mentions = [],
|
|
15
38
|
showHint = true,
|
|
39
|
+
platform,
|
|
16
40
|
onSubmit,
|
|
17
|
-
placeholder
|
|
41
|
+
placeholder,
|
|
18
42
|
charsPerToken = 4,
|
|
19
43
|
mentionColor,
|
|
20
44
|
maxHeight = 280,
|
|
21
|
-
aboveInput
|
|
45
|
+
aboveInput,
|
|
46
|
+
className,
|
|
47
|
+
...rest
|
|
22
48
|
}) {
|
|
23
49
|
const [text, setText] = useState("");
|
|
24
50
|
const [attachments, setAttachments] = useState([]);
|
|
@@ -27,6 +53,13 @@ function PromptInput({
|
|
|
27
53
|
const fileRef = useRef(null);
|
|
28
54
|
const [dragOver, setDragOver] = useState(false);
|
|
29
55
|
const colors = mentionColor ?? DEFAULT_MENTION_COLOR;
|
|
56
|
+
const [detected, setDetected] = useState("generic");
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (platform) return;
|
|
59
|
+
setDetected(detectPlatform(browserPlatformHints()));
|
|
60
|
+
}, [platform]);
|
|
61
|
+
const modKey = modifierKeyLabel(platform ?? detected);
|
|
62
|
+
const resolvedPlaceholder = placeholder ?? `Ask anything. Type / for commands, @ for mentions. ${modKey}+Enter to send.`;
|
|
30
63
|
const tokens = useMemo(
|
|
31
64
|
() => Math.ceil(text.length / Math.max(1, charsPerToken)),
|
|
32
65
|
[text, charsPerToken]
|
|
@@ -160,13 +193,20 @@ function PromptInput({
|
|
|
160
193
|
return /* @__PURE__ */ jsxs(
|
|
161
194
|
"div",
|
|
162
195
|
{
|
|
196
|
+
...rest,
|
|
197
|
+
"data-react-fancy-prompt-input": "",
|
|
198
|
+
"data-react-fancy-prompt-input-drag": dragOver ? "over" : "idle",
|
|
163
199
|
onDragOver: (e) => {
|
|
164
200
|
e.preventDefault();
|
|
165
201
|
setDragOver(true);
|
|
166
202
|
},
|
|
167
203
|
onDragLeave: () => setDragOver(false),
|
|
168
204
|
onDrop,
|
|
169
|
-
className:
|
|
205
|
+
className: cn(
|
|
206
|
+
"relative rounded-md border bg-white transition dark:bg-zinc-900",
|
|
207
|
+
dragOver ? "border-violet-400 bg-violet-50/50 dark:border-violet-600 dark:bg-violet-950/30" : "border-zinc-200 dark:border-zinc-800",
|
|
208
|
+
className
|
|
209
|
+
),
|
|
170
210
|
children: [
|
|
171
211
|
aboveInput && /* @__PURE__ */ jsx("div", { className: "border-b border-zinc-200 dark:border-zinc-800", children: aboveInput }),
|
|
172
212
|
attachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5 border-b border-zinc-200 px-3 py-2 dark:border-zinc-800", children: attachments.map((a) => /* @__PURE__ */ jsxs(
|
|
@@ -174,7 +214,7 @@ function PromptInput({
|
|
|
174
214
|
{
|
|
175
215
|
className: "inline-flex items-center gap-1.5 rounded-md bg-zinc-100 px-2 py-0.5 text-[11px] dark:bg-zinc-800",
|
|
176
216
|
children: [
|
|
177
|
-
/* @__PURE__ */ jsx("
|
|
217
|
+
/* @__PURE__ */ jsx(Icon, { name: "paperclip", size: "xs", className: "text-zinc-400" }),
|
|
178
218
|
/* @__PURE__ */ jsx("span", { className: "font-mono", children: a.name }),
|
|
179
219
|
/* @__PURE__ */ jsx("span", { className: "text-zinc-400", children: fmtSize(a.bytes) }),
|
|
180
220
|
/* @__PURE__ */ jsx(
|
|
@@ -199,7 +239,7 @@ function PromptInput({
|
|
|
199
239
|
onChange: (e) => updateText(e.target.value, e.target.selectionStart),
|
|
200
240
|
onKeyDown,
|
|
201
241
|
onPaste,
|
|
202
|
-
placeholder,
|
|
242
|
+
placeholder: resolvedPlaceholder,
|
|
203
243
|
spellCheck: false,
|
|
204
244
|
className: "block w-full resize-none bg-transparent px-3 py-2.5 text-[14px] leading-relaxed outline-none placeholder:text-zinc-400",
|
|
205
245
|
rows: 3
|
|
@@ -265,9 +305,10 @@ function PromptInput({
|
|
|
265
305
|
{
|
|
266
306
|
variant: "ghost",
|
|
267
307
|
size: "sm",
|
|
308
|
+
icon: "paperclip",
|
|
268
309
|
className: "shrink-0",
|
|
269
310
|
onClick: () => fileRef.current?.click(),
|
|
270
|
-
children: "
|
|
311
|
+
children: "attach"
|
|
271
312
|
}
|
|
272
313
|
) }),
|
|
273
314
|
/* @__PURE__ */ jsx(
|
|
@@ -298,16 +339,33 @@ function PromptInput({
|
|
|
298
339
|
] })
|
|
299
340
|
] }),
|
|
300
341
|
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-2", children: [
|
|
301
|
-
showHint && /* @__PURE__ */ jsxs(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
342
|
+
showHint && /* @__PURE__ */ jsxs(
|
|
343
|
+
"span",
|
|
344
|
+
{
|
|
345
|
+
className: "hidden text-[10px] text-zinc-500 sm:inline",
|
|
346
|
+
"data-react-fancy-prompt-input-hint": modKey === "\u2318" ? "apple" : "generic",
|
|
347
|
+
children: [
|
|
348
|
+
/* @__PURE__ */ jsx("kbd", { className: "rounded border border-zinc-300 bg-zinc-50 px-1 py-0.5 font-mono text-[9px] text-zinc-700 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-300", children: modKey }),
|
|
349
|
+
" ",
|
|
350
|
+
"+",
|
|
351
|
+
" ",
|
|
352
|
+
/* @__PURE__ */ jsx("kbd", { className: "rounded border border-zinc-300 bg-zinc-50 px-1 py-0.5 font-mono text-[9px] text-zinc-700 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-300", children: "Enter" }),
|
|
353
|
+
" ",
|
|
354
|
+
"to send"
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
),
|
|
358
|
+
/* @__PURE__ */ jsx(
|
|
359
|
+
Button,
|
|
360
|
+
{
|
|
361
|
+
color: "violet",
|
|
362
|
+
size: "sm",
|
|
363
|
+
iconTrailing: "arrow-right",
|
|
364
|
+
className: "shrink-0",
|
|
365
|
+
onClick: submit,
|
|
366
|
+
children: "send"
|
|
367
|
+
}
|
|
368
|
+
)
|
|
311
369
|
] })
|
|
312
370
|
] })
|
|
313
371
|
]
|
|
@@ -324,6 +382,6 @@ function fmtSize(b) {
|
|
|
324
382
|
return `${(b / 1024 / 1024).toFixed(1)} MB`;
|
|
325
383
|
}
|
|
326
384
|
|
|
327
|
-
export { PromptInput };
|
|
328
|
-
//# sourceMappingURL=chunk-
|
|
329
|
-
//# sourceMappingURL=chunk-
|
|
385
|
+
export { PromptInput, browserPlatformHints, detectPlatform, modifierKeyLabel };
|
|
386
|
+
//# sourceMappingURL=chunk-O3WEV562.js.map
|
|
387
|
+
//# sourceMappingURL=chunk-O3WEV562.js.map
|