Files
chatkit/dist/react/RichBlock.js
T
CatoandClaude Fable 5.1 3fe57d0559 feat(answers): answers that read like the ChatGPT app's (0.13.0) (#24)
* feat(answers): answers that read like the ChatGPT app's (0.13.0)

Measured screen by screen against the ChatGPT app on a phone, and closed
in the package so every product gets it:

- Headings are signposts: a size up, with air above them, so a long answer
  can be scanned and found again.
- Options are cards: a numbered list whose items open with a bold name gets
  a tile badge, the name a size up, a hairline between cards, and a pill
  for a short tag written right after the name (`[Recommended]`). The
  instruction asks the model to mark the option it recommends that way.
- Sources are chips: a `[F2, F1]` handle is drawn after the sentence as
  "Fleet AGENTS.md +1", linked when the record has a link, and moved after
  the full stop when the model wrote it before.
- Links in the words that leave the site say so: dotted underline, arrow.
- A layered figure, `{"type":"stack"}`: full-width boxes top to bottom, a
  row of tiles where a layer has parts (icons from a closed list, never
  markup), the words that cross each arrow, an accent tone, a caption.
  `diagram` stays for an arbitrary graph.
- "Thought for 3m 38s ›" above an answer from `message.thinking`, closed by
  default; `live.steps` shows the same row open while a turn runs, with
  the newest step marked. `ThinkingRow` and `formatThinkingDuration` are
  exported; `thoughtFor`, `thought`, `thinking` join the thread labels.

Tests: tag and citation placement (core), stack validation and text form
(core), the whole answer rendered on the server (render), and the stack
fitting six tiles on a 390px phone with the thought line above (browser).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

* fix(markdown): no space before the full stop when a citation chip moves after it

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-22 11:19:18 +02:00

33 lines
5.3 KiB
JavaScript

"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useId, useState } from "react";
import { Sheet } from "./Sheet.js";
import { StackIconSvg } from "./icons.js";
export function RichAnswerBlock({ block, onReply, }) {
const id = useId();
const [selected, setSelected] = useState(null);
const [sent, setSent] = useState(false);
const [photo, setPhoto] = useState(null);
if (block.type === "audio")
return (_jsxs("figure", { className: "ck-rich ck-audio", children: [_jsx("figcaption", { className: "ck-rich-title", children: block.title }), block.creator && _jsx("p", { children: block.creator }), _jsx("audio", { controls: true, preload: "none", src: block.src, "aria-label": block.title }), block.caption && _jsx("p", { children: block.caption }), _jsxs("a", { href: block.src, target: "_blank", rel: "noopener noreferrer", children: [block.title, " \u2197"] })] }));
if (block.type === "gallery") {
const active = photo === null ? null : block.images[photo];
return (_jsxs("figure", { className: "ck-rich ck-gallery", children: [_jsx("figcaption", { className: "ck-rich-title", children: block.title }), _jsx("div", { className: "ck-gallery-grid", children: block.images.map((item, i) => (_jsxs("figure", { children: [_jsxs("button", { type: "button", className: "ck-photo", onClick: () => setPhoto(i), "aria-label": item.alt, "aria-haspopup": "dialog", children: [_jsx("img", { src: item.src, alt: item.alt, loading: "lazy", referrerPolicy: "no-referrer", onError: (e) => {
e.currentTarget.hidden = true;
} }), _jsx("span", { className: "ck-photo-label", children: item.alt })] }), item.caption && _jsx("figcaption", { children: item.caption })] }, i))) }), _jsxs(Sheet, { open: !!active, onClose: () => setPhoto(null), title: active?.alt ?? block.title, children: [active && (_jsx("img", { className: "ck-photo-full", src: active.src, alt: active.alt, referrerPolicy: "no-referrer" })), active?.caption && _jsx("p", { children: active.caption })] })] }));
}
if (block.type === "diagram")
return (_jsxs("figure", { className: "ck-rich ck-diagram", children: [_jsx("figcaption", { className: "ck-rich-title", children: block.title }), _jsx("ol", { className: "ck-diagram-nodes", children: block.nodes.map((n, i) => (_jsxs("li", { children: [_jsx("span", { className: "ck-diagram-number", "aria-hidden": true, children: i + 1 }), _jsxs("div", { children: [_jsx("strong", { children: n.label }), n.detail && _jsx("p", { children: n.detail })] })] }, n.id))) }), block.edges.length > 0 && (_jsx("ul", { className: "ck-diagram-edges", children: block.edges.map((e, i) => (_jsxs("li", { children: [_jsx("span", { children: block.nodes.find((n) => n.id === e.from).label }), _jsx("span", { className: "ck-diagram-arrow", "aria-hidden": true, children: "\u2192" }), _jsx("span", { children: block.nodes.find((n) => n.id === e.to).label }), e.label && _jsx("small", { children: e.label })] }, i))) }))] }));
if (block.type === "stack")
return (_jsxs("figure", { className: "ck-rich ck-stack", children: [_jsx("figcaption", { className: "ck-rich-title", children: block.title }), _jsx("div", { className: "ck-stack-layers", children: block.layers.map((layer, i) => (_jsxs("div", { className: "ck-stack-layer", children: [_jsx("div", { className: "ck-stack-row", style: { gridTemplateColumns: `repeat(${layer.nodes.length}, minmax(0, 1fr))` }, children: layer.nodes.map((n, j) => (_jsxs("div", { className: n.tone === "accent" ? "ck-stack-node ck-stack-accent" : "ck-stack-node", children: [n.icon && _jsx(StackIconSvg, { name: n.icon }), n.kicker && _jsx("span", { className: "ck-stack-kicker", children: n.kicker }), _jsx("strong", { className: "ck-stack-label", children: n.label }), n.detail && _jsx("span", { className: "ck-stack-detail", children: n.detail })] }, j))) }), i < block.layers.length - 1 && (_jsxs("div", { className: "ck-stack-link", children: [_jsx("span", { className: "ck-stack-arrow", "aria-hidden": true, children: layer.both ? "⇅" : "↓" }), layer.link && _jsx("span", { children: layer.link })] }))] }, i))) }), block.caption && _jsx("p", { className: "ck-stack-caption", children: block.caption })] }));
if (block.type === "callout")
return (_jsxs("aside", { className: "ck-rich ck-callout", children: [_jsx("strong", { className: "ck-rich-title", children: block.title }), _jsx("p", { children: block.body })] }));
return (_jsx("form", { className: "ck-rich ck-choice", onSubmit: (e) => {
e.preventDefault();
if (selected !== null && onReply && !sent) {
setSent(true);
onReply(block.options[selected].reply);
}
}, children: _jsxs("fieldset", { disabled: !onReply || sent, children: [_jsx("legend", { className: "ck-rich-title", children: block.title }), block.options.map((option, i) => (_jsxs("label", { className: "ck-choice-option", children: [_jsx("input", { type: "radio", name: id, value: i, checked: selected === i, onChange: () => setSelected(i) }), _jsx("span", { children: option.label })] }, i))), onReply && (_jsxs("button", { type: "submit", className: "ck-choice-submit", disabled: selected === null || sent, children: [block.submit, _jsx("span", { "aria-hidden": true, children: "\u2192" })] }))] }) }));
}
//# sourceMappingURL=RichBlock.js.map