Files
chatkit/dist/react/Markdown.js
T
CatoandClaude Opus 5.5 ed759a8516 feat: chatkit v0.1 — one chat for every product (#1)
* feat: chatkit v0.1 — one chat for every product

The fleet had 13 chats in 10 repos, each written fresh, each missing what
another had fixed. This extracts loki /loki (composer, thread, messages,
markdown, attachments) and adds heidi's microphone and orangecat's keyboard fix:

- Composer: auto-growing 16px textarea, Enter/Shift+Enter/IME, Send and Stop
  in one slot, attachments with paste, mic always present, every label
  translatable, app-specific controls in slots.
- useDictation: browser recogniser first; missing or SILENT (4 s watchdog,
  bounded permission wait) -> record and transcribe on the server; a dead
  recogniser remembered 30 days; every failure shown in words.
- ChatThread/ChatMessage: stick-to-bottom + jump button, speaker names once two
  agents speak, Copy on answers, Retry on the last one, failed turns visible.
- Markdown with no HTML path; javascript: links stay text.
- styles.css: --ck-* variables defaulting to @bitbaum/design-tokens.
- verify = format, lint, types, build, 18 unit/render tests and 21 browser
  checks (390px + desktop, light + dark, a sentence through a fake mic past a
  silent recogniser). Browser checks mutation-tested (14px input, 60 s
  watchdog) — both fail as they should.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(styles): --ck-* defaults at zero specificity on :root, so an app's own values win

Declared on the chat's elements they overrode any app setting --ck-* at the
root — the opposite of what the README promised. Found preparing loki, whose
colour variables are full OKLCH colours under the design-token names and so
must map them. New browser check: a :root --ck-accent reaches the chat.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 23:14:53 -07:00

58 lines
3.1 KiB
JavaScript

import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { isInternalHref, parseBlocks, parseInline } from "../markdown.js";
/** A plain anchor: same-site paths in place, everything else in a new tab. */
export const defaultRenderLink = ({ href, internal, className, children }) => internal ? (_jsx("a", { href: href, className: className, children: children })) : (_jsx("a", { href: href, className: className, target: "_blank", rel: "noopener noreferrer", children: children }));
function Inline({ spans, citations, renderLink, }) {
return (_jsx(_Fragment, { children: spans.map((s, i) => {
switch (s.kind) {
case "code":
return (_jsx("code", { className: "ck-code", children: s.text }, i));
case "strong":
return _jsx("strong", { children: s.text }, i);
case "em":
return _jsx("em", { children: s.text }, i);
case "link":
return (_jsx("span", { children: renderLink({
href: s.href,
internal: isInternalHref(s.href),
className: "ck-link",
children: s.text,
}) }, i));
case "cite": {
const known = s.ids.filter((id) => citations?.[id]);
if (known.length === 0)
return null;
return (_jsx("sup", { className: "ck-cite", title: known
.map((id) => `${id} — ${citations[id].label}\n${citations[id].detail}`)
.join("\n\n"), children: known.join(" ") }, i));
}
default:
return _jsx("span", { children: s.text }, i);
}
}) }));
}
/**
* Model output as readable text: paragraphs, lists, headings, bold, italic,
* code, links and citations. Never HTML — nothing here can inject markup.
*/
export function Markdown({ text, citations, renderLink = defaultRenderLink, className, }) {
const inline = (t) => (_jsx(Inline, { spans: parseInline(t), citations: citations, renderLink: renderLink }));
return (_jsx("div", { className: className ? `ck-md ${className}` : "ck-md", children: parseBlocks(text).map((b, i) => {
switch (b.kind) {
case "code":
return (_jsx("pre", { className: "ck-pre", "data-lang": b.lang || undefined, children: _jsx("code", { children: b.code }) }, i));
case "ul":
case "ol": {
const List = b.kind;
return (_jsx(List, { children: b.items.map((item, j) => (_jsx("li", { children: inline(item) }, j))) }, i));
}
case "h":
return (_jsx("p", { className: "ck-md-h", children: inline(b.text) }, i));
case "quote":
return _jsx("blockquote", { children: inline(b.text) }, i);
default:
return _jsx("p", { children: inline(b.text) }, i);
}
}) }));
}
//# sourceMappingURL=Markdown.js.map