mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 06:07:44 +01:00
"Who produces gallium?" now carries a ranked bar chart, not a list. chatkit
stays dependency-free: it defines the data contract (`ChartBlock`, mirroring
@bitbaum/chartkit's props for line, bars, share, timeline, tiles) and a
renderer slot (`renderers={{ chart }}` on ChatScreen, ChatThread, ChatMessage,
Markdown and RichAnswerBlock); the app injects the drawing.
- Parser: each kind validated field by field (bounded lists, finite numbers,
safe links). A malformed block is rejected by the parser and degrades to
its caption and a table of the safe rows; without a renderer, or when one
returns null, chatkit draws that table itself. A chart is never a blank.
- Instruction: when to draw (ranked 3+ rows -> bars, shares -> share, 3+
points over time -> line, 3+ dated events -> timeline, 2-4 figures ->
tiles), figures only from tool results, hrefs copied from the result.
- Copy and Listen read the figures as lines, never the wire JSON.
- Tests: node tests per kind, the fallback and the renderer paths; the
browser test renders a bars block through a stub renderer and a line block
through the fallback in demo/screen.html at 320/390/1280, with the
broken-word scan and no horizontal overflow.
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
57 lines
3.1 KiB
JavaScript
57 lines
3.1 KiB
JavaScript
"use client";
|
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
import { useLayoutEffect, useRef } from "react";
|
|
import { useViewportHeight } from "./hooks.js";
|
|
import { RichRenderersContext } from "./renderers.js";
|
|
/**
|
|
* The chat as the whole screen, the way the ChatGPT and Claude apps lay it
|
|
* out: the conversation runs edge to edge and top to bottom, and the controls
|
|
* FLOAT over it — a see-through header at the top, the composer at the bottom
|
|
* — instead of each taking a strip of the screen away from the reading.
|
|
*
|
|
* Words scroll under both. They fade out as they pass beneath the header and
|
|
* the composer, so the controls stay legible without an opaque bar behind
|
|
* them; the last line of an answer always rests above the composer, never
|
|
* behind it (the scroller is padded by the measured height of each).
|
|
*
|
|
* The heights are published as `--ck-top-inset` and `--ck-bottom-inset` on
|
|
* the screen, so an app whose thread is its own scroller pads it with them:
|
|
*
|
|
* .my-thread { padding-block: var(--ck-top-inset) var(--ck-bottom-inset); }
|
|
*
|
|
* chatkit's own `ChatThread` does that already.
|
|
*/
|
|
export function ChatScreen({ header, composer, footnote, children, fill = "parent", className, renderers, }) {
|
|
const rootRef = useRef(null);
|
|
const headerRef = useRef(null);
|
|
const dockRef = useRef(null);
|
|
useViewportHeight(rootRef, fill === "viewport");
|
|
const hasHeader = header != null && header !== false;
|
|
// Measured, not guessed: the composer grows with a long draft, a staged
|
|
// screenshot or a dictation problem, and the reading has to move with it.
|
|
useLayoutEffect(() => {
|
|
const root = rootRef.current;
|
|
if (!root)
|
|
return;
|
|
const sync = () => {
|
|
root.style.setProperty("--ck-top-inset", `${headerRef.current?.offsetHeight ?? 0}px`);
|
|
root.style.setProperty("--ck-bottom-inset", `${dockRef.current?.offsetHeight ?? 0}px`);
|
|
};
|
|
sync();
|
|
if (typeof ResizeObserver === "undefined")
|
|
return;
|
|
const observer = new ResizeObserver(sync);
|
|
if (headerRef.current)
|
|
observer.observe(headerRef.current);
|
|
if (dockRef.current)
|
|
observer.observe(dockRef.current);
|
|
return () => observer.disconnect();
|
|
}, [hasHeader]);
|
|
const cls = ["ck-screen"];
|
|
if (fill === "viewport")
|
|
cls.push("ck-screen-viewport");
|
|
if (className)
|
|
cls.push(className);
|
|
return (_jsxs("div", { ref: rootRef, className: cls.join(" "), children: [_jsx("div", { className: "ck-screen-body", children: renderers ? (_jsx(RichRenderersContext.Provider, { value: renderers, children: children })) : (children) }), hasHeader && (_jsx("div", { ref: headerRef, className: "ck-screen-header", children: _jsx("div", { className: "ck-screen-header-row", children: header }) })), _jsx("div", { ref: dockRef, className: "ck-screen-dock", children: _jsxs("div", { className: "ck-screen-column", children: [composer, footnote != null && _jsx("p", { className: "ck-screen-footnote", children: footnote })] }) })] }));
|
|
}
|
|
//# sourceMappingURL=Screen.js.map
|