/* global React */
const { useState: useTState } = React;
// ============================================================
// PAGE HEADER (breadcrumbs, title, last-updated)
// ============================================================
function PageHeader({ crumbs = [], title, lastUpdated, summary }) {
return (
{title}
{summary && {summary}
}
{lastUpdated && (
Updated {lastUpdated}
)}
);
}
// ============================================================
// PROSE — typography sample block
// ============================================================
function Prose({ children }) {
return
{children}
;
}
// ============================================================
// CODE BLOCK (Mission Control aesthetic)
// ============================================================
function CodeBlock({ filename, lang = "php", children, lineNumbers = false }) {
const [copied, setCopied] = useTState(false);
const onCopy = () => {
setCopied(true);
setTimeout(() => setCopied(false), 1400);
};
// children is array of {type, text} tokens, or a string
const rendered = Array.isArray(children) ? children : [{ text: children }];
return (
{filename &&
{filename}
}
{lang}
{rendered.map((line, i) => (
{lineNumbers && {i + 1}}
))}
);
}
// Token helper — wraps text in a syntax-color span
function tk(cls, text) {
return `${text}`;
}
// Pre-tokenized PHP sample (saves us writing a real lexer)
const phpSample = [
{ text: `${tk("kw", "namespace")} ${tk("ns", "App\\\\Controllers")};` },
{ text: `` },
{ text: `${tk("kw", "use")} ${tk("ns", "Nibiru\\\\Controller")};` },
{ text: `${tk("kw", "use")} ${tk("ns", "Nibiru\\\\Form")};` },
{ text: `` },
{ text: `${tk("kw", "class")} ${tk("cn", "BookingController")} ${tk("kw", "extends")} ${tk("cn", "Controller")} {` },
{ text: ` ${tk("kw", "public")} ${tk("kw", "function")} ${tk("fn", "create")}(${tk("var", "$req")}) {` },
{ text: ` ${tk("var", "$form")} = ${tk("kw", "new")} ${tk("cn", "Form")}();` },
{ text: ` ${tk("var", "$form")}->${tk("fn", "addInputType")}(${tk("str", "'email'")}, ${tk("str", "'address'")});` },
{ text: ` ${tk("kw", "return")} ${tk("var", "$this")}->${tk("fn", "view")}(${tk("str", "'booking/create'")}, [` },
{ text: ` ${tk("str", "'form'")} => ${tk("var", "$form")},` },
{ text: ` ]);` },
{ text: ` }` },
{ text: `}` },
];
const sqlSample = [
{ text: `${tk("kw", "SELECT")} ${tk("var", "id")}, ${tk("var", "title")}, ${tk("var", "created_at")}` },
{ text: `${tk("kw", "FROM")} ${tk("cn", "bookings")}` },
{ text: `${tk("kw", "WHERE")} ${tk("var", "user_id")} = ${tk("num", "42")}` },
{ text: ` ${tk("kw", "AND")} ${tk("var", "status")} = ${tk("str", "'confirmed'")}` },
{ text: `${tk("kw", "ORDER BY")} ${tk("var", "created_at")} ${tk("kw", "DESC")}` },
{ text: `${tk("kw", "LIMIT")} ${tk("num", "20")};` },
];
const yamlSample = [
{ text: `${tk("kw", "app")}:` },
{ text: ` ${tk("kw", "name")}: ${tk("str", "Nibiru")}` },
{ text: ` ${tk("kw", "version")}: ${tk("str", "2.0.0")}` },
{ text: ` ${tk("kw", "modules")}:` },
{ text: ` - ${tk("str", "auth")}` },
{ text: ` - ${tk("str", "blog")}` },
{ text: ` - ${tk("str", "api")}` },
];
// ============================================================
// CALLOUTS (cosmic-coded)
// ============================================================
function Callout({ kind = "note", title, children }) {
const icons = {
note: ,
tip: ,
warning: ,
danger: ,
};
const labels = { note: "Note", tip: "Tip", warning: "Warning", danger: "Danger" };
return (
{icons[kind]}
{title || labels[kind]}
{children}
);
}
// ============================================================
// TABLE
// ============================================================
function DocTable({ headers, rows }) {
return (
{headers.map((h, i) => | {h} | )}
{rows.map((row, i) => (
{row.map((cell, j) => | {cell} | )}
))}
);
}
Object.assign(window, { PageHeader, Prose, CodeBlock, Callout, DocTable, phpSample, sqlSample, yamlSample, tk });