From 4e28310855a10ea2630ddae553e6b4acfdeea6fc Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Mon, 26 Oct 2026 13:59:16 -0400 Subject: [PATCH] Docs: tables that read on a phone, and settings as definition lists Tables render through components/table.tsx: one rounded box that scrolls sideways only when it must (with a fade on the side that has more), a quiet header, a hairline between rows and no column lines. Columns are sized from their content: short keys and identifiers stay on one line, long text gets a minimum width so it never squeezes to a word a line, and code in text cells breaks at its separators, never mid-word. Lists whose items open with a bold term and a line break are styled as parameter lists. The plugin manifest reference, the skills frontmatter fields and the API error fields use them instead of tables; the self-host guides follow in the platform repo. A new e2e suite checks the table pages at 1440 and 390 px in both themes. --- docs/app/global.css | 126 +++++++++++++++++++++- docs/components/mdx.tsx | 2 + docs/components/table.tsx | 132 ++++++++++++++++++++++++ docs/content/docs/api/errors.mdx | 11 +- docs/content/docs/concepts/skills.mdx | 14 +-- docs/e2e/site.spec.ts | 5 +- docs/e2e/tables.spec.ts | 112 ++++++++++++++++++++ docs/scripts/lib/manifest-reference.mjs | 27 +++-- 8 files changed, 407 insertions(+), 22 deletions(-) create mode 100644 docs/components/table.tsx create mode 100644 docs/e2e/tables.spec.ts diff --git a/docs/app/global.css b/docs/app/global.css index e645f9f1..c622093e 100644 --- a/docs/app/global.css +++ b/docs/app/global.css @@ -45,9 +45,91 @@ html > body[data-scroll-locked] { body { overflow-wrap: anywhere; } - table { - overflow-wrap: break-word; - } +} + +/* Tables (components/table.tsx). One rounded box, a quiet header, a hairline + between rows and no lines between columns. Columns of short keys stay on + one line; columns of text get a minimum width from the component, so a + wide table scrolls inside its box (with a fade on the side that has more) + and the page never scrolls sideways. */ +.ch-table { + --tbl-bg: var(--color-fd-background); + --tbl-fade: color-mix(in oklab, var(--color-fd-foreground) 14%, transparent); + position: relative; + max-width: 100%; + margin: 1.5rem 0; + overflow-x: auto; + overscroll-behavior-x: contain; + border: 1px solid var(--color-fd-border); + border-radius: 0.75rem; + /* Shadows at the edges that only show while there is more to scroll: the + covers move with the content, the shadows stay with the box. */ + background: + linear-gradient(to right, var(--tbl-bg) 30%, transparent) left / 2.5rem 100% no-repeat local, + linear-gradient(to left, var(--tbl-bg) 30%, transparent) right / 2.5rem 100% no-repeat local, + radial-gradient(farthest-side at 0 50%, var(--tbl-fade), transparent) left / 0.875rem 100% no-repeat scroll, + radial-gradient(farthest-side at 100% 50%, var(--tbl-fade), transparent) right / 0.875rem 100% no-repeat scroll, + var(--tbl-bg); +} +.ch-table:focus-visible { + outline: 2px solid var(--color-fd-ring); + outline-offset: 2px; +} +.ch-table table { + width: 100%; + margin: 0; + border: 0; + border-radius: 0; + border-collapse: separate; + border-spacing: 0; + background: transparent; + overflow: visible; + font-size: 0.875rem; + line-height: 1.55; + overflow-wrap: break-word; +} +.ch-table th, +.ch-table td { + padding: 0.625rem 0.875rem; + border-inline-start: 0; + text-align: start; + vertical-align: top; +} +.ch-table th { + background: color-mix(in oklab, var(--color-fd-muted) 70%, transparent); + border-bottom: 1px solid var(--color-fd-border); + color: var(--color-fd-muted-foreground); + font-size: 0.8125rem; + font-weight: 600; + white-space: nowrap; +} +.ch-table tbody tr:not(:last-child) td { + border-bottom: 1px solid color-mix(in oklab, var(--color-fd-border) 75%, transparent); +} +/* The first column names the row: a little heavier than the cells beside it. */ +.ch-table td:first-child { + color: var(--color-fd-foreground); + font-weight: 500; +} +.ch-table td:not(:first-child) { + color: color-mix(in oklab, var(--color-fd-foreground) 86%, var(--color-fd-muted-foreground)); +} +.ch-table [data-fit='key'] { + white-space: nowrap; +} +/* Code in a cell is a chip that wraps at its separators (components/table.tsx + puts break points after . / - _ and the like), never mid-word. */ +.ch-table code { + font-size: 0.8125em; + padding: 0.0625rem 0.3rem; + white-space: normal; + overflow-wrap: break-word; + word-break: normal; + box-decoration-break: clone; + -webkit-box-decoration-break: clone; +} +.ch-table [data-fit='key'] code { + white-space: nowrap; } ::selection { @@ -250,3 +332,41 @@ h1 > .ch-badge { .ch-dg-text[open] summary { margin-bottom: 0.25rem; } + +/* Definition lists: a list whose items open with a bold term and a line + break (a setting, a check, an error code, then what it means). Written in + plain Markdown, so the self-host guides read the same on GitHub: + - **`retainData`** *boolean, default `true`*\ + Keep tables ... when stacks are deleted. + Here they lose the bullets and get a hairline between items, like a + parameter list. The italic part is muted metadata (a type, a default, a + label such as "Fix:"). */ +.prose ul:has(> li > strong:first-child ~ br) { + list-style: none; + padding-inline-start: 0; + margin-block: 1.25rem 1.5rem; + border-top: 1px solid var(--color-fd-border); +} +.prose ul:has(> li > strong:first-child ~ br) > li { + margin: 0; + padding: 0.75rem 0 0.8rem; + padding-inline-start: 0; + border-bottom: 1px solid color-mix(in oklab, var(--color-fd-border) 75%, transparent); + font-size: 0.9375rem; + line-height: 1.65; +} +.prose ul:has(> li > strong:first-child ~ br) > li > strong:first-child { + color: var(--color-fd-foreground); + font-weight: 600; +} +.prose ul:has(> li > strong:first-child ~ br) > li > em { + font-style: normal; + font-size: 0.875em; + color: var(--color-fd-muted-foreground); +} +.prose ul:has(> li > strong:first-child ~ br) > li > strong:first-child { + font-size: 1rem; +} +.prose ul:has(> li > strong:first-child ~ br) > li > strong:first-child + em { + margin-inline-start: 0.35rem; +} diff --git a/docs/components/mdx.tsx b/docs/components/mdx.tsx index 3b31458f..27e0f8dc 100644 --- a/docs/components/mdx.tsx +++ b/docs/components/mdx.tsx @@ -8,10 +8,12 @@ import type { MDXComponents } from 'mdx/types'; import { Badge } from '@/components/badge'; import { Path, Paths, Tile, Tiles } from '@/components/home'; import { Diagram } from '@/components/diagram'; +import { Table } from '@/components/table'; export function getMDXComponents(components?: MDXComponents) { return { ...defaultMdxComponents, + table: Table, Tab, Tabs, Step, diff --git a/docs/components/table.tsx b/docs/components/table.tsx new file mode 100644 index 00000000..1a895efc --- /dev/null +++ b/docs/components/table.tsx @@ -0,0 +1,132 @@ +import { Children, cloneElement, isValidElement, type ComponentProps, type CSSProperties, type ReactElement, type ReactNode } from 'react'; + +/* + * Every Markdown table on the site (hand-written MDX and the imported + * self-host guides) renders through this. Styles are in app/global.css + * (.ch-table). + * + * The columns are sized from what is in them, the way a person laying the + * table out would do it: + * - a column whose cells are all short (a key, a type, "Yes") stays on one + * line, so `models.provider` or "Required" never breaks; + * - a column of longer text gets a minimum width, so on a phone it scrolls + * inside its box instead of squeezing into one word a line. + * The box scrolls sideways only when the table is wider than the page, with + * a fade on the side that has more. + */ + +type El = ReactElement<{ children?: ReactNode; style?: CSSProperties; 'data-fit'?: string }>; + +/** The text of a cell, as a reader sees it. */ +export function textOf(node: ReactNode): string { + if (node == null || typeof node === 'boolean') return ''; + if (typeof node === 'string' || typeof node === 'number') return String(node); + if (Array.isArray(node)) return node.map(textOf).join(''); + if (isValidElement(node)) return textOf((node as El).props.children); + return ''; +} + +const elements = (children: ReactNode): El[] => Children.toArray(children).filter(isValidElement) as El[]; + +/** A cell that holds only identifiers: inline code, with commas or spaces between. */ +function codeOnly(children: ReactNode): boolean { + const parts = Children.toArray(children); + return parts.length > 0 && parts.every((p) => (typeof p === 'string' ? /^[\s,]*$/.test(p) : isValidElement(p) && p.type === 'code')); +} + +type Column = { length: number; code: boolean }; + +/** Per column: the longest cell (header included), and whether every body cell is code. */ +function columns(sections: El[]): Column[] { + const cols: Column[] = []; + for (const section of sections) { + const body = section.type !== 'thead'; + for (const row of elements(section.props.children)) { + elements(row.props.children).forEach((cell, i) => { + const col = (cols[i] ??= { length: 0, code: true }); + const text = textOf(cell.props.children).trim(); + col.length = Math.max(col.length, text.length); + if (body && text && !codeOnly(cell.props.children)) col.code = false; + }); + } + } + return cols; +} + +/** Short enough to keep on one line: keys, types, defaults, yes and no. */ +const NOWRAP_MAX = 22; + +/** How a column is laid out, from its longest cell. */ +/** Identifiers up to this long stay whole when a column holds nothing else. */ +const CODE_NOWRAP_MAX = 36; + +export function columnFit({ length, code }: Column, columns: number): { fit: 'key' | 'text'; minWidth?: string } { + if (length <= NOWRAP_MAX || (code && length <= CODE_NOWRAP_MAX)) return { fit: 'key' }; + // Two columns share the width well on their own; a minimum would only make + // a phone scroll. + if (columns < 3) return { fit: 'text' }; + if (length > 90) return { fit: 'text', minWidth: '15rem' }; + if (length > 50) return { fit: 'text', minWidth: '11rem' }; + return { fit: 'text', minWidth: '8rem' }; +} + +export function Table({ children, ...props }: ComponentProps<'table'>) { + const sections = elements(children); + const cols = columns(sections); + const fits = cols.map((col) => columnFit(col, cols.length)); + const laidOut = sections.map((section) => + cloneElement(section, { + children: elements(section.props.children).map((row) => + cloneElement(row, { + children: elements(row.props.children).map((cell, i) => + cloneElement(cell, { + // Chrome breaks at even under nowrap: key columns get none. + children: fits[i]?.fit === 'key' ? cell.props.children : withBreaks(cell.props.children), + 'data-fit': fits[i]?.fit, + style: fits[i]?.minWidth ? { ...cell.props.style, minWidth: fits[i].minWidth } : cell.props.style, + }), + ), + }), + ), + }), + ); + const header = textOf(sections[0]).trim(); + return ( + // Focusable so a keyboard can scroll a wide table (WCAG 2.1.1). +
+ {laidOut}
+
+ ); +} + +/** + * Break points in a long identifier: before a dot, after a slash, hyphen, + * underscore and the like, and never in its first two characters. So + * `coderhelm--data-` wraps at a hyphen and `doctor.json` at + * its dot, never mid-word. + */ +const BREAKS = /(?<=..)(?=\.[^\s.])|(?<=..[/_\-:,=@])(?=\S)/g; + +export function breakable(text: string): ReactNode[] { + if (text.length < 14) return [text]; + const parts: ReactNode[] = []; + let last = 0; + for (const m of text.matchAll(BREAKS)) { + const at = m.index ?? 0; + if (at === last || at >= text.length) continue; + parts.push(text.slice(last, at), ); + last = at; + } + parts.push(text.slice(last)); + return parts; +} + +/** A cell's content with break points added to its inline code. */ +function withBreaks(node: ReactNode): ReactNode { + return Children.map(node, (child) => { + if (!isValidElement(child)) return child; + const el = child as El; + if (el.type === 'code' && typeof el.props.children === 'string') return cloneElement(el, { children: breakable(el.props.children) }); + return el.props.children === undefined ? el : cloneElement(el, { children: withBreaks(el.props.children) }); + }); +} diff --git a/docs/content/docs/api/errors.mdx b/docs/content/docs/api/errors.mdx index a242c5fe..7f8df105 100644 --- a/docs/content/docs/api/errors.mdx +++ b/docs/content/docs/api/errors.mdx @@ -13,11 +13,12 @@ A failed request answers with a `4xx` or `5xx` status and a JSON body: } ``` -| Field | Type | Description | -| --- | --- | --- | -| `error` | string | A sentence to show a person. Its wording can change. | -| `code` | string | What went wrong, for programs. Branch on this, not on `error`. | -| `scope` | string | Only with `missing_scope`: the scope the key would need. | +- **`error`** *string*\ + A sentence to show a person. Its wording can change. +- **`code`** *string*\ + What went wrong, for programs. Branch on this, not on `error`. +- **`scope`** *string*\ + Only with `missing_scope`: the scope the key would need. ## Codes diff --git a/docs/content/docs/concepts/skills.mdx b/docs/content/docs/concepts/skills.mdx index f84f450f..1fd8a74b 100644 --- a/docs/content/docs/concepts/skills.mdx +++ b/docs/content/docs/concepts/skills.mdx @@ -48,12 +48,14 @@ description: How to write a database migration in this codebase. Read before cha - Every migration has a down step... ``` -| Field | Type | Default | Notes | -| --- | --- | --- | --- | -| `name` | string | The folder name (skills) or file name (agents, commands) | Lowercased; characters other than `a-z 0-9 - _ .` become `-`; up to 64 characters. | -| `description` | string | The first line of the body that is not a heading | Up to 240 characters. Agents choose skills by their description, so make it say when to use the skill. | -| `tools` or `allowed-tools` | list, or one string split by commas | none | Claude Code tool names, mapped to CoderHelm's own (below). | -| `model` | string | none | Agents only. A hint for which model answers. | +- **`name`** *string, default the folder name (skills) or file name (agents, commands)*\ + Lowercased; characters other than `a-z 0-9 - _ .` become `-`; up to 64 characters. +- **`description`** *string, default the first line of the body that is not a heading*\ + Up to 240 characters. Agents choose skills by their description, so make it say when to use the skill. +- **`tools`** or **`allowed-tools`** *list, or one string split by commas*\ + Claude Code tool names, mapped to CoderHelm's own (below). +- **`model`** *string*\ + Agents only. A hint for which model answers. Claude Code tool names map to these abilities: `Read` to read files, `Edit` and `MultiEdit` to edit files, `Write` to write files, `Grep` to search code, and `Glob` and `LS` to list files. Others (shell, web, notebooks, sub-agents) have no equivalent and are reported as missing. diff --git a/docs/e2e/site.spec.ts b/docs/e2e/site.spec.ts index 3df71497..a55cdfa4 100644 --- a/docs/e2e/site.spec.ts +++ b/docs/e2e/site.spec.ts @@ -48,8 +48,9 @@ test('plugins have shipped: the manifest reference has no Coming soon badge, and await page.goto('/plugins/manifest-reference/'); await expect(page.getByRole('heading', { level: 1 })).toContainText('Manifest reference'); await expect(page.locator('h1 .ch-badge')).toHaveCount(0); - await expect(page.getByRole('cell', { name: 'results', exact: true }).first()).toBeVisible(); - await expect(page.getByRole('cell', { name: 'name', exact: true }).first()).toBeVisible(); + // Every field is a definition list item: its name, then its type and what it does. + await expect(page.locator('#nd-page li > strong > code', { hasText: /^results$/ }).first()).toBeVisible(); + await expect(page.locator('#nd-page li > strong > code', { hasText: /^name$/ }).first()).toBeVisible(); await expect(page.getByRole('link', { name: /edit on github/i })).toHaveAttribute('href', /CoderHelm\/coderhelm\/blob\/main\/docs\/schemas\/plugin-manifest\.schema\.json/); // No plugin page is marked unreleased in the sidebar. await expect(page.locator('aside a[href*="/plugins/"] .ch-badge')).toHaveCount(0); diff --git a/docs/e2e/tables.spec.ts b/docs/e2e/tables.spec.ts new file mode 100644 index 00000000..b16c3d5c --- /dev/null +++ b/docs/e2e/tables.spec.ts @@ -0,0 +1,112 @@ +import { expect, test, type Page } from '@playwright/test'; +import fs from 'node:fs'; +import path from 'node:path'; + +// Tables (components/table.tsx) and definition lists (app/global.css), at +// desktop and phone widths, in both themes. + +const SHOTS = process.env.E2E_SHOTS; + +async function shot(page: Page, name: string) { + if (!SHOTS) return; + fs.mkdirSync(SHOTS, { recursive: true }); + await page.screenshot({ path: path.join(SHOTS, `${name}.png`), fullPage: true }); +} + +/** Pages with the most, widest or longest tables and lists. */ +const TABLE_PAGES = [ + '/self-host/backups/', + '/self-host/options/', + '/self-host/config-reference/', + '/self-host/check-your-install/', + '/self-host/domains/', + '/self-host/troubleshooting/', + '/self-host/hybrid/', + '/self-host/knowledge-sources/', + '/concepts/knowledge-sources/', + '/concepts/agent-permissions/', + '/api/errors/', + '/api/pagination/', + '/plugins/manifest-reference/', +]; + +/** What each table looks like on the page, for the checks below. */ +async function tableFacts(page: Page) { + return page.evaluate(() => { + const lineHeight = (el: Element) => parseFloat(getComputedStyle(el).lineHeight) || 20; + return [...document.querySelectorAll('#nd-page table')].map((table) => { + const box = table.parentElement!; + return { + inBox: box.classList.contains('ch-table') && box.getAttribute('role') === 'region' && box.tabIndex === 0, + boxScrolls: getComputedStyle(box).overflowX === 'auto', + headersOnOneLine: [...table.querySelectorAll('th')].every((th) => th.getBoundingClientRect().height <= lineHeight(th) * 1.6 + 22), + // An identifier in a key column never wraps. + wrappedKeys: [...table.querySelectorAll('td[data-fit="key"] code')] + .filter((c) => c.getClientRects().length > 1) + .map((c) => c.textContent), + // A text column never shrinks to a word a line. + narrowText: [...table.querySelectorAll('td[data-fit="text"]')] + .filter((td) => td.getBoundingClientRect().width < 110) + .map((td) => td.textContent?.slice(0, 40)), + }; + }); + }); +} + +for (const scheme of ['dark', 'light'] as const) { + for (const [width, height] of [ + [1440, 900], + [390, 844], + ] as const) { + test.describe(`tables at ${width}px in ${scheme}`, () => { + test.use({ viewport: { width, height }, colorScheme: scheme, ...(width === 390 ? { isMobile: true, hasTouch: true } : {}) }); + + for (const url of TABLE_PAGES) { + test(`${url}: tables scroll in their box, the page never sideways`, async ({ page }) => { + await page.goto(url); + await page.waitForLoadState('networkidle'); + const { scroll, inner } = await page.evaluate(() => ({ scroll: document.documentElement.scrollWidth, inner: window.innerWidth })); + expect(scroll, `${url} is ${scroll}px wide on a ${inner}px screen`).toBeLessThanOrEqual(inner); + for (const t of await tableFacts(page)) { + expect(t.inBox, 'every table sits in a focusable scroll box').toBe(true); + expect(t.boxScrolls).toBe(true); + expect(t.headersOnOneLine, 'header cells stay on one line').toBe(true); + expect(t.wrappedKeys, 'identifiers in key columns stay whole').toEqual([]); + expect(t.narrowText, 'no text column is squeezed to a word a line').toEqual([]); + } + await shot(page, `${url.replace(/^\/|\/$/g, '').replace(/\//g, '_')}-${width}-${scheme}`); + }); + } + }); + } +} + +test('settings, checks and fields read as definition lists, not wide tables', async ({ page }) => { + // The self-host guides (options, config reference, backups, troubleshooting) + // join this list once platform.lock.json pins the platform commit that + // turned their tables into lists. + for (const [url, term] of [ + ['/plugins/manifest-reference/', 'monthly_tokens'], + ['/concepts/skills/', 'description'], + ['/api/errors/', 'scope'], + ] as const) { + await page.goto(url); + const item = page.locator('#nd-page li').filter({ has: page.locator('strong', { hasText: term }) }).first(); + await expect(item, `${url}: ${term}`).toBeVisible(); + const list = item.locator('xpath=..'); + expect(await list.evaluate((ul) => getComputedStyle(ul).listStyleType), `${url}: no bullets`).toBe('none'); + expect(await item.evaluate((li) => parseFloat(getComputedStyle(li).borderBottomWidth)), `${url}: a hairline between items`).toBeGreaterThan(0); + } +}); + +test('an imported page shows no import comment, and its edit link opens the platform source', async ({ page }) => { + for (const name of ['backups', 'email', 'options']) { + await page.goto(`/self-host/${name}/`); + await expect(page.locator('#nd-page')).not.toContainText('{/*'); + await expect(page.locator('#nd-page')).not.toContainText('Imported from'); + await expect(page.getByRole('link', { name: /edit on github/i })).toHaveAttribute( + 'href', + `https://github.com/CoderHelm/coderhelm-platform/blob/main/docs/self-host/${name}.md`, + ); + } +}); diff --git a/docs/scripts/lib/manifest-reference.mjs b/docs/scripts/lib/manifest-reference.mjs index f409a9a5..5a7f61a9 100644 --- a/docs/scripts/lib/manifest-reference.mjs +++ b/docs/scripts/lib/manifest-reference.mjs @@ -2,7 +2,13 @@ // page, the schema at /schema/plugin-manifest.v1.json and the validator are // one source. -const esc = (s) => String(s ?? '').replace(/\|/g, '\\|').replace(/[<>{}]/g, (c) => `\\${c}`).replace(/\n/g, ' '); +/** MDX-safe text: braces and angle brackets escaped outside inline code (inside it they are literal). */ +const esc = (s) => + String(s ?? '') + .replace(/\n/g, ' ') + .split(/(`[^`]*`)/) + .map((part, i) => (i % 2 ? part : part.replace(/[<>{}]/g, (c) => `\\${c}`))) + .join(''); function resolve(schema, node) { if (node && node.$ref) { @@ -18,7 +24,7 @@ function resolve(schema, node) { function typeOf(schema, node) { node = resolve(schema, node); if (node.const !== undefined) return `\`${JSON.stringify(node.const)}\``; - if (node.enum) return node.enum.map((v) => `\`${v}\``).join(' \\| '); + if (node.enum) return node.enum.map((v) => `\`${v}\``).join(' or '); if (node.oneOf) return node.oneOf.map((n) => typeOf(schema, n)).join(' or '); if (node.type === 'array') { const items = resolve(schema, node.items); @@ -32,10 +38,15 @@ function typeOf(schema, node) { const fmtDefault = (v) => (v === undefined ? '' : `\`${JSON.stringify(v)}\``); +/** + * A field list, one item per field: the name, then its type, whether it is + * required and its default (muted), then what it does. A parameter list reads + * better than a five-column table, on a phone most of all. + */ function table(schema, node, prefix = '') { node = resolve(schema, node); const required = new Set(node.required ?? []); - const rows = ['| Field | Type | Required | Default | Description |', '| --- | --- | --- | --- | --- |']; + const items = []; for (const [key, raw] of Object.entries(node.properties ?? {})) { if (key === '$schema') continue; const prop = resolve(schema, raw); @@ -43,9 +54,13 @@ function table(schema, node, prefix = '') { if (prop.pattern) desc += ` Must match \`${prop.pattern}\`.`; if (prop.maxLength) desc += ` At most ${prop.maxLength} characters.`; if (prop.examples) desc += ` Example: ${prop.examples.map((e) => `\`${e}\``).join(', ')}.`; - rows.push(`| \`${prefix}${key}\` | ${typeOf(schema, raw)} | ${required.has(key) ? 'yes' : 'no'} | ${esc(fmtDefault(prop.default))} | ${esc(desc)} |`); + const meta = [typeOf(schema, raw), required.has(key) ? 'required' : null, prop.default === undefined ? null : `default ${fmtDefault(prop.default)}`] + .filter(Boolean) + .join(', '); + const head = `- **\`${prefix}${key}\`** *${esc(meta)}*`; + items.push(desc.trim() ? `${head}\\\n ${esc(desc.trim())}` : head); } - return rows.join('\n'); + return items.join('\n'); } export function renderManifestReference(schema) { @@ -75,7 +90,7 @@ export function renderManifestReference(schema) { '', '## Top-level fields', '', - esc(schema.description).replace(/\\\|/g, '|'), + esc(schema.description), '', table(schema, schema), '',