@rtkelly-labs/design-system 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +1 -1
- package/dist/components/DataTable.js +135 -52
- package/dist/components/DataTable.js.map +1 -1
- package/dist/components/InlineAction.js +58 -0
- package/dist/components/InlineAction.js.map +1 -0
- package/dist/components/ResourceState.js +55 -0
- package/dist/components/ResourceState.js.map +1 -0
- package/dist/components/docs/figures/ChangeSummary.js +5 -5
- package/dist/components/docs/figures/ChangeSummary.js.map +1 -1
- package/dist/components/docs/figures/DrawingSheet.js +4 -1
- package/dist/components/docs/figures/DrawingSheet.js.map +1 -1
- package/dist/components/docs/figures/FigureSurfaceContext.js +9 -0
- package/dist/components/docs/figures/FigureSurfaceContext.js.map +1 -0
- package/dist/components/docs/figures/FileChangeTree.js +4 -4
- package/dist/components/docs/figures/FileChangeTree.js.map +1 -1
- package/dist/components/docs/figures/IndexedSection.js +8 -2
- package/dist/components/docs/figures/IndexedSection.js.map +1 -1
- package/dist/components/docs/figures/index.js.map +1 -1
- package/dist/hooks/usePolledResource.js +98 -0
- package/dist/hooks/usePolledResource.js.map +1 -0
- package/dist/index.d.ts +303 -5
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/theme.js +12 -0
- package/dist/lib/theme.js.map +1 -1
- package/dist/lib/units.js +25 -0
- package/dist/lib/units.js.map +1 -0
- package/dist/theme/contrast.js +15 -0
- package/dist/theme/contrast.js.map +1 -1
- package/dist/theme/levels.js +31 -0
- package/dist/theme/levels.js.map +1 -1
- package/dist/theme.css +30 -0
- package/package.json +2 -2
- package/tokens/palette.midnight.tokens.json +50 -0
- package/tokens/palette.sketch.tokens.json +50 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/docs/figures/ChangeSummary.tsx"],"sourcesContent":["/**\n * Adapted from mdxcn by Keshav Bagaade, MIT licensed.\n * Source: https://github.com/keshav-exe/mdxcn/blob/2928126ba146ebbae9c2351deca27d27bb40e744/registry/default/graph-diff/graph-diff.tsx\n * The local port removes motion and graph variables while retaining the\n * source component's Markdown and `<Line>` data forms.\n */\n\nimport type { ReactNode } from 'react';\nimport * as React from 'react';\nimport {\n childItems,\n defineAsciiItem,\n AsciiFrameBody,\n AsciiFrameRule,\n hasHost,\n itemText,\n listItems,\n splitLabel,\n textOf,\n type FigurePalette,\n} from './FigureFrame';\nimport { cn } from '../../../lib/recipe';\n\nexport type DiffSign = 'add' | 'remove' | 'keep';\n\nexport interface DiffRow {\n /** Falls back to the child text for `<Line value=\"31 kb\">app</Line>`. */\n label?: string;\n value: string;\n sign?: DiffSign;\n}\n\nexport interface DiffLineProps extends DiffRow {\n /** Draw the row under a rule as the total. */\n total?: boolean;\n}\n\nexport interface ChangeSummaryProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Accessible name; the enclosing FigureFrame owns the caption. */\n label?: string;\n /** Data form. If omitted, the component reads Markdown or `<Line>` children. */\n rows?: DiffRow[];\n /** Optional typed total shown below the row rule. */\n footer?: DiffRow;\n /** Markdown list or `<Line>` content used to derive rows. */\n children?: ReactNode;\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/docs/figures/ChangeSummary.tsx"],"sourcesContent":["/**\n * Adapted from mdxcn by Keshav Bagaade, MIT licensed.\n * Source: https://github.com/keshav-exe/mdxcn/blob/2928126ba146ebbae9c2351deca27d27bb40e744/registry/default/graph-diff/graph-diff.tsx\n * The local port removes motion and graph variables while retaining the\n * source component's Markdown and `<Line>` data forms.\n */\n\nimport type { ReactNode } from 'react';\nimport * as React from 'react';\nimport {\n childItems,\n defineAsciiItem,\n AsciiFrameBody,\n AsciiFrameRule,\n hasHost,\n itemText,\n listItems,\n splitLabel,\n textOf,\n type FigurePalette,\n} from './FigureFrame';\nimport { cn } from '../../../lib/recipe';\n\nexport type DiffSign = 'add' | 'remove' | 'keep';\n\nexport interface DiffRow {\n /** Falls back to the child text for `<Line value=\"31 kb\">app</Line>`. */\n label?: string;\n value: string;\n sign?: DiffSign;\n}\n\nexport interface DiffLineProps extends DiffRow {\n /** Draw the row under a rule as the total. */\n total?: boolean;\n}\n\nexport interface ChangeSummaryProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Accessible name; the enclosing FigureFrame owns the caption. */\n label?: string;\n /** Data form. If omitted, the component reads Markdown or `<Line>` children. */\n rows?: DiffRow[];\n /** Optional typed total shown below the row rule. */\n footer?: DiffRow;\n /** Markdown list or `<Line>` content used to derive rows. */\n children?: ReactNode;\n /**\n * Accepted for symmetry with the other figures and ignored: additions and removals take the\n * `delta` roles, so a summary reads the same in a `multi` figure as in a `mono` one.\n */\n palette?: FigurePalette;\n /** Additional classes for this summary. */\n className?: string;\n}\n\n/** MDX-only diff item, for example `<Line sign=\"add\" value=\"31 kb\">app</Line>`. */\nexport const Line = defineAsciiItem<DiffLineProps>('Line');\n\nfunction signOf(value: string): DiffSign | undefined {\n if (/^\\+/.test(value.trim())) return 'add';\n if (/^[−-]/.test(value.trim())) return 'remove';\n return undefined;\n}\n\nfunction diffFromList(children: ReactNode): DiffLineProps[] {\n return listItems(children).map((item) => {\n const { label, rest } = splitLabel(itemText(item));\n const content = (item.props as { children?: ReactNode }).children;\n return {\n label,\n value: rest.replace(/^[+−-]\\s*/, '') || rest,\n sign: signOf(rest),\n total: hasHost(content, ['strong', 'b']),\n };\n });\n}\n\n/** Signs are change, so they take the `delta` roles whatever palette the surrounding figures use. */\nfunction signClass(sign: DiffSign): string {\n if (sign === 'add') return 'text-delta-added';\n if (sign === 'remove') return 'text-delta-removed';\n return 'text-content-primary';\n}\n\nfunction lineText(row: DiffRow): string {\n return `${row.label ?? ''} ${row.value}`.trim();\n}\n\n/** Renders additions, removals, and unchanged rows with a readable text summary. */\nexport const ChangeSummary = React.forwardRef<HTMLDivElement, ChangeSummaryProps>(function ChangeSummary({ label = 'Change summary', rows: rowsProp, footer: footerProp, children, palette: _palette, className, ...rest }, ref) {\n const listed = diffFromList(children);\n const tagged = childItems(children, Line).map((entry) => ({ ...entry, label: entry.label ?? textOf(entry.children) }));\n const lines = listed.length > 0 ? listed : tagged;\n const rows = (rowsProp ?? lines.filter((entry) => !entry.total)).map((entry) => ({ ...entry, label: entry.label ?? '' }));\n const footerLine = footerProp ?? lines.find((entry) => entry.total);\n const footer = footerLine ? { ...footerLine, label: footerLine.label ?? '' } : undefined;\n\n return (\n <AsciiFrameBody data-slot=\"change-summary\" ref={ref} {...rest} className={cn('flex flex-col gap-3', className)}>\n <ul className=\"flex flex-col gap-2\" aria-label={label}>\n {rows.map((row, index) => {\n const sign = row.sign ?? 'keep';\n const tone = signClass(sign);\n return (\n <li className=\"grid grid-cols-[1.25rem_minmax(0,1fr)_8ch] items-baseline gap-x-3\" key={`${lineText(row)}-${index}`} aria-label={`${sign}: ${lineText(row)}`}>\n <span aria-hidden=\"true\" className={cn('select-none text-center', sign === 'keep' ? 'text-content-muted' : tone)}>{sign === 'keep' ? ' ' : sign === 'add' ? '+' : '-'}</span>\n <span className={tone}>{row.label}</span>\n <span className={cn('text-right tabular-nums', tone)}>{row.value}</span>\n </li>\n );\n })}\n </ul>\n {footer ? <><AsciiFrameRule /><div className=\"grid grid-cols-[1.25rem_minmax(0,1fr)_8ch] items-baseline gap-x-3\" aria-label={`total: ${lineText(footer)}`}><span aria-hidden=\"true\" className=\"text-content-muted\"> </span><span className=\"text-content-primary\">{footer.label}</span><span className=\"text-right tabular-nums text-content-primary\">{footer.value}</span></div></> : null}\n <span className=\"sr-only\">{rows.length === 0 && !footer ? 'Empty diff.' : `${rows.length} changed row${rows.length === 1 ? '' : 's'}${footer ? `, total ${lineText(footer)}` : ''}.`}</span>\n </AsciiFrameBody>\n );\n});\n"],"mappings":";AAQA,YAAY,WAAW;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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KAAK,WAAW,IAAI,KAAK,GAAG,GAAG,SAAS,WAAW,SAAS,MAAM,CAAC,KAAK,EAAE,KAAI;AAAA,KACvL;AAEN,CAAC;","names":["ChangeSummary"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
// src/components/docs/figures/DrawingSheet.tsx
|
|
2
4
|
import * as React from "react";
|
|
3
5
|
import { cn } from "../../../lib/recipe.js";
|
|
6
|
+
import { FigureSurfaceContext } from "./FigureSurfaceContext.js";
|
|
4
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
8
|
var LETTERS = "ABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
6
9
|
function sheetRowLabel(index) {
|
|
@@ -26,7 +29,7 @@ var DrawingSheet = React.forwardRef(function DrawingSheet2({ columns = 4, rows =
|
|
|
26
29
|
top > 0 && side > 0 ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "border-b-2 border-r-2 border-edge-strong" }) : null,
|
|
27
30
|
top > 0 ? /* @__PURE__ */ jsx("div", { "aria-hidden": "true", "data-slot": "drawing-sheet-columns", className: "flex select-none border-b-2 border-edge-strong font-mono text-xs text-content-muted", children: Array.from({ length: top }, (_, index) => /* @__PURE__ */ jsx("span", { className: cn("flex-1 py-1 text-center", index > 0 && "border-l border-edge-default"), children: index + 1 }, index)) }) : null,
|
|
28
31
|
side > 0 ? /* @__PURE__ */ jsx("div", { "aria-hidden": "true", "data-slot": "drawing-sheet-rows", className: "flex select-none flex-col border-r-2 border-edge-strong font-mono text-xs text-content-muted", children: Array.from({ length: side }, (_, index) => /* @__PURE__ */ jsx("span", { className: cn("flex flex-1 items-center justify-center", index > 0 && "border-t border-edge-default"), children: sheetRowLabel(index) }, index)) }) : null,
|
|
29
|
-
/* @__PURE__ */ jsx("div", { "data-slot": "drawing-sheet-body", className: "flex min-w-0 flex-col gap-6 p-3 sm:p-6", children })
|
|
32
|
+
/* @__PURE__ */ jsx("div", { "data-slot": "drawing-sheet-body", className: "flex min-w-0 flex-col gap-6 p-3 sm:p-6", children: /* @__PURE__ */ jsx(FigureSurfaceContext.Provider, { value: "sheet", children }) })
|
|
30
33
|
]
|
|
31
34
|
}
|
|
32
35
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/docs/figures/DrawingSheet.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/docs/figures/DrawingSheet.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\nimport * as React from 'react';\nimport { cn } from '../../../lib/recipe';\n\n\n\nimport { FigureSurfaceContext } from './FigureSurfaceContext';\n\nconst LETTERS = 'ABCDEFGHJKLMNPQRSTUVWXYZ';\n\n/** Row reference for an index — drawing-sheet convention skips I and O, which read as 1 and 0. */\nfunction sheetRowLabel(index: number): string {\n const letter = LETTERS[index % LETTERS.length] ?? 'A';\n return index < LETTERS.length ? letter : `${letter}${Math.floor(index / LETTERS.length) + 1}`;\n}\n\nexport interface DrawingSheetProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Grid references across the top edge, numbered from 1. `0` hides the top ruler. */\n columns?: number;\n /** Grid references down the left edge, lettered from A. `0` hides the side ruler. */\n rows?: number;\n /** Sheet content, usually one or more `IndexedSection`s. */\n children?: ReactNode;\n /** Additional classes for the root. */\n className?: string;\n}\n\n/**\n * An engineering drawing sheet: a hard border with numbered columns along the top and lettered\n * rows down the side, so a review can point at \"B2\" rather than \"the second box on the left\".\n *\n * The references divide the sheet evenly and are decorative — they are hidden from assistive\n * technology, which navigates by the sections' headings instead.\n */\nexport const DrawingSheet = React.forwardRef<HTMLDivElement, DrawingSheetProps>(function DrawingSheet({ columns = 4, rows = 3, children, className, ...rest }, ref) {\n const top = Math.max(0, Math.floor(columns));\n const side = Math.max(0, Math.floor(rows));\n return (\n <div\n ref={ref}\n {...rest}\n data-slot=\"drawing-sheet\"\n className={cn(\n 'grid w-full border-2 border-edge-strong bg-surface-base text-content-primary',\n side > 0 ? 'grid-cols-[1.75rem_minmax(0,1fr)]' : 'grid-cols-[minmax(0,1fr)]',\n top > 0 ? 'grid-rows-[auto_1fr]' : 'grid-rows-[1fr]',\n className,\n )}\n >\n {top > 0 && side > 0 ? <span aria-hidden=\"true\" className=\"border-b-2 border-r-2 border-edge-strong\" /> : null}\n {top > 0 ? (\n <div aria-hidden=\"true\" data-slot=\"drawing-sheet-columns\" className=\"flex select-none border-b-2 border-edge-strong font-mono text-xs text-content-muted\">\n {Array.from({ length: top }, (_, index) => (\n <span key={index} className={cn('flex-1 py-1 text-center', index > 0 && 'border-l border-edge-default')}>\n {index + 1}\n </span>\n ))}\n </div>\n ) : null}\n {side > 0 ? (\n <div aria-hidden=\"true\" data-slot=\"drawing-sheet-rows\" className=\"flex select-none flex-col border-r-2 border-edge-strong font-mono text-xs text-content-muted\">\n {Array.from({ length: side }, (_, index) => (\n <span key={index} className={cn('flex flex-1 items-center justify-center', index > 0 && 'border-t border-edge-default')}>\n {sheetRowLabel(index)}\n </span>\n ))}\n </div>\n ) : null}\n <div data-slot=\"drawing-sheet-body\" className=\"flex min-w-0 flex-col gap-6 p-3 sm:p-6\">\n <FigureSurfaceContext.Provider value=\"sheet\">\n {children}\n </FigureSurfaceContext.Provider>\n </div>\n </div>\n );\n});\n"],"mappings":";;;AAGA,YAAY,WAAW;AACvB,SAAS,UAAU;AAInB,SAAS,4BAA4B;AAgCjC,SAWyB,KAXzB;AA9BJ,IAAM,UAAU;AAGhB,SAAS,cAAc,OAAuB;AAC5C,QAAM,SAAS,QAAQ,QAAQ,QAAQ,MAAM,KAAK;AAClD,SAAO,QAAQ,QAAQ,SAAS,SAAS,GAAG,MAAM,GAAG,KAAK,MAAM,QAAQ,QAAQ,MAAM,IAAI,CAAC;AAC7F;AAoBO,IAAM,eAAqB,iBAA8C,SAASA,cAAa,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,WAAW,GAAG,KAAK,GAAG,KAAK;AAClK,QAAM,MAAM,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,CAAC;AAC3C,QAAM,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC;AACzC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACC,GAAG;AAAA,MACJ,aAAU;AAAA,MACV,WAAW;AAAA,QACT;AAAA,QACA,OAAO,IAAI,sCAAsC;AAAA,QACjD,MAAM,IAAI,yBAAyB;AAAA,QACnC;AAAA,MACF;AAAA,MAEC;AAAA,cAAM,KAAK,OAAO,IAAI,oBAAC,UAAK,eAAY,QAAO,WAAU,4CAA2C,IAAK;AAAA,QACzG,MAAM,IACL,oBAAC,SAAI,eAAY,QAAO,aAAU,yBAAwB,WAAU,uFACjE,gBAAM,KAAK,EAAE,QAAQ,IAAI,GAAG,CAAC,GAAG,UAC/B,oBAAC,UAAiB,WAAW,GAAG,2BAA2B,QAAQ,KAAK,8BAA8B,GACnG,kBAAQ,KADA,KAEX,CACD,GACH,IACE;AAAA,QACH,OAAO,IACN,oBAAC,SAAI,eAAY,QAAO,aAAU,sBAAqB,WAAU,gGAC9D,gBAAM,KAAK,EAAE,QAAQ,KAAK,GAAG,CAAC,GAAG,UAChC,oBAAC,UAAiB,WAAW,GAAG,2CAA2C,QAAQ,KAAK,8BAA8B,GACnH,wBAAc,KAAK,KADX,KAEX,CACD,GACH,IACE;AAAA,QACJ,oBAAC,SAAI,aAAU,sBAAqB,WAAU,0CAC5C,8BAAC,qBAAqB,UAArB,EAA8B,OAAM,SAClC,UACH,GACF;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;","names":["DrawingSheet"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/docs/figures/FigureSurfaceContext.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\n\nexport type FigureSurface = 'base' | 'sheet';\n\n/**\n * Context communicating the enclosing figure container surface to child sections.\n *\n * When nested inside a `DrawingSheet`, child `IndexedSection` elements step up to\n * `bg-surface-raised` to provide crisp contrast against the sheet's `bg-surface-base`\n * grid canvas, preventing the \"same-surface sandwich\" effect.\n */\nexport const FigureSurfaceContext = React.createContext<FigureSurface | null>(null);\n"],"mappings":";;;AAEA,YAAY,WAAW;AAWhB,IAAM,uBAA6B,oBAAoC,IAAI;","names":[]}
|
|
@@ -11,10 +11,10 @@ var DEFAULT_VIEW_LABELS = { before: "Before", changes: "Changes", after: "After"
|
|
|
11
11
|
var DEFAULT_CHANGE_LABELS = { add: "added", modify: "modified", rename: "renamed", remove: "removed" };
|
|
12
12
|
var GLYPH = { add: "+", modify: "~", rename: "\u2192", remove: "\u2212" };
|
|
13
13
|
var TONE = {
|
|
14
|
-
add: { text: "text-
|
|
15
|
-
modify: { text: "text-
|
|
16
|
-
rename: { text: "text-
|
|
17
|
-
remove: { text: "text-
|
|
14
|
+
add: { text: "text-delta-added", fill: "bg-delta-added" },
|
|
15
|
+
modify: { text: "text-content-secondary", fill: "bg-content-secondary" },
|
|
16
|
+
rename: { text: "text-delta-moved", fill: "bg-delta-moved" },
|
|
17
|
+
remove: { text: "text-delta-removed", fill: "bg-delta-removed" }
|
|
18
18
|
};
|
|
19
19
|
function isDirectory(node) {
|
|
20
20
|
return node.children != null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/docs/figures/FileChangeTree.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\nimport * as React from 'react';\nimport { AsciiFrameBody } from './FigureFrame';\nimport { cn } from '../../../lib/recipe';\n\nexport type FileChange = 'add' | 'modify' | 'remove' | 'rename';\nexport type FileChangeView = 'before' | 'changes' | 'after';\n\nexport interface FileChangeNode {\n /** File or directory name. A node with `children` is drawn as a directory. */\n name: string;\n /** How the file changed. Omit for an unchanged file or a directory. */\n change?: FileChange;\n /** One line on what changed, drawn under the name. */\n note?: ReactNode;\n /** Entries inside a directory. */\n children?: FileChangeNode[];\n}\n\nexport interface FileChangeTreeProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {\n /** Accessible name; the enclosing frame owns the caption. */\n label?: string;\n /** Top-level entries. Each one becomes a column under the shared connector. */\n nodes: FileChangeNode[];\n /** Controlled view. `changes` marks every entry; `before` and `after` show the tree on one side of the change. */\n view?: FileChangeView;\n /** Initial view when uncontrolled. */\n defaultView?: FileChangeView;\n /** Called when the reader picks a view. */\n onViewChange?: (view: FileChangeView) => void;\n /** Hide the before / changes / after switch and the tallies. */\n hideFooter?: boolean;\n /** Accessible label for the view selection button group. */\n viewGroupLabel?: string;\n /** Replaces the switch's button text, for translated pages. */\n viewLabels?: Partial<Record<FileChangeView, string>>;\n /** Replaces the tally words, for translated pages. */\n changeLabels?: Partial<Record<FileChange, string>>;\n /** Additional classes for the root. */\n className?: string;\n}\n\nconst VIEWS: readonly FileChangeView[] = ['before', 'changes', 'after'];\nconst CHANGES: readonly FileChange[] = ['add', 'modify', 'rename', 'remove'];\n\nconst DEFAULT_VIEW_LABELS: Record<FileChangeView, string> = { before: 'Before', changes: 'Changes', after: 'After' };\nconst DEFAULT_CHANGE_LABELS: Record<FileChange, string> = { add: 'added', modify: 'modified', rename: 'renamed', remove: 'removed' };\n\nconst GLYPH: Record<FileChange, string> = { add: '+', modify: '~', rename: '→', remove: '−' };\n\n/** A change is meaning, so it is addressed through intent roles, never accents. */\nconst TONE: Record<FileChange, { text: string; fill: string }> = {\n add: { text: 'text-intent-success', fill: 'bg-intent-success' },\n modify: { text: 'text-intent-warning', fill: 'bg-intent-warning' },\n rename: { text: 'text-intent-info', fill: 'bg-intent-info' },\n remove: { text: 'text-intent-danger', fill: 'bg-intent-danger' },\n};\n\nfunction isDirectory(node: FileChangeNode): boolean {\n return node.children != null;\n}\n\n/** Drops what does not exist on one side of the change, and empty directories with it. */\nfunction visible(nodes: FileChangeNode[], view: FileChangeView): FileChangeNode[] {\n return nodes.flatMap((node) => {\n if (view === 'before' && node.change === 'add') return [];\n if (view === 'after' && node.change === 'remove') return [];\n if (!isDirectory(node)) return [node];\n const children = visible(node.children ?? [], view);\n return children.length > 0 || view === 'changes' ? [{ ...node, children }] : [];\n });\n}\n\nfunction tally(nodes: FileChangeNode[], counts: Record<FileChange, number> = { add: 0, modify: 0, rename: 0, remove: 0 }): Record<FileChange, number> {\n for (const node of nodes) {\n if (node.change) counts[node.change] += 1;\n if (node.children) tally(node.children, counts);\n }\n return counts;\n}\n\nfunction ChangeMark({ change }: { change: FileChange }) {\n return (\n <span\n aria-hidden=\"true\"\n data-slot=\"file-change-tree-mark\"\n className={cn('inline-flex size-4 shrink-0 select-none items-center justify-center text-[0.7rem] font-bold leading-none text-content-inverse', TONE[change].fill)}\n >\n {GLYPH[change]}\n </span>\n );\n}\n\nfunction Entries({ nodes, view, changeLabels }: { nodes: FileChangeNode[]; view: FileChangeView; changeLabels: Record<FileChange, string> }) {\n return (\n <ul className=\"flex flex-col gap-3\" data-slot=\"file-change-tree-list\">\n {nodes.map((node, index) => {\n const last = index === nodes.length - 1;\n const marked = view === 'changes' && node.change != null;\n const change = marked ? node.change : undefined;\n return (\n <li key={`${node.name}-${index}`} className=\"relative pl-6\" data-slot=\"file-change-tree-entry\">\n {/* The elbow: a stem down to this row, then a tick across to it. The last row's stem stops at its tick. */}\n <span aria-hidden=\"true\" className={cn('absolute left-0 top-0 border-l-2 border-edge-subtle', last ? 'h-[0.8em]' : '-bottom-3')} />\n <span aria-hidden=\"true\" className=\"absolute left-0 top-[0.8em] w-4 border-t-2 border-edge-subtle\" />\n <div className=\"flex items-center gap-2\">\n {change ? <ChangeMark change={change} /> : null}\n <span data-slot=\"file-change-tree-name\" className={cn('min-w-0 break-all font-mono', change ? TONE[change].text : 'text-content-primary', change === 'remove' && 'line-through')}>\n {node.name}\n </span>\n {change ? <span className=\"sr-only\">({changeLabels[change]})</span> : null}\n </div>\n {node.note != null && !isDirectory(node) ? <p data-slot=\"file-change-tree-note\" className=\"m-0 mt-1 text-pretty text-content-secondary\">{node.note}</p> : null}\n {isDirectory(node) && (node.children?.length ?? 0) > 0 ? (\n <div className=\"mt-3\">\n <Entries nodes={node.children ?? []} view={view} changeLabels={changeLabels} />\n </div>\n ) : null}\n </li>\n );\n })}\n </ul>\n );\n}\n\n/**\n * A changeset drawn as its directory layout: each top-level directory is a boxed column under\n * one connector, its files hang from a ruled tree with a change mark and a one-line note, and a\n * footer tallies the change and switches between the tree before, the change itself, and after.\n *\n * Stacks into one column below the `sm` breakpoint, where the connector is dropped.\n */\nexport const FileChangeTree = React.forwardRef<HTMLDivElement, FileChangeTreeProps>(function FileChangeTree(\n { label = 'File changes', nodes, view: viewProp, defaultView = 'changes', onViewChange, hideFooter = false, viewGroupLabel, viewLabels, changeLabels, className, ...rest },\n ref,\n) {\n const [uncontrolled, setUncontrolled] = React.useState<FileChangeView>(defaultView);\n const view = viewProp ?? uncontrolled;\n const views = { ...DEFAULT_VIEW_LABELS, ...viewLabels };\n const changes = { ...DEFAULT_CHANGE_LABELS, ...changeLabels };\n const columns = visible(nodes, view);\n const counts = tally(nodes);\n const connected = columns.length > 1;\n\n const pick = (next: FileChangeView) => {\n if (viewProp == null) setUncontrolled(next);\n onViewChange?.(next);\n };\n\n return (\n <AsciiFrameBody ref={ref} {...rest} data-slot=\"file-change-tree\" className={cn('flex flex-col gap-6 font-mono text-sm', className)}>\n <div role=\"list\" aria-label={label} className=\"flex flex-col gap-8 sm:flex-row sm:gap-6\">\n {columns.map((column, index) => {\n const first = index === 0;\n const last = index === columns.length - 1;\n const marked = view === 'changes' && column.change != null;\n return (\n <div role=\"listitem\" key={`${column.name}-${index}`} className=\"relative flex min-w-0 flex-1 flex-col\" data-slot=\"file-change-tree-column\">\n {connected ? (\n <span aria-hidden=\"true\" className=\"relative hidden h-6 sm:block\">\n {/* The shared bar, carried half a gap past each side so neighbours meet; the ends stop at the drop. */}\n <span className={cn('absolute top-0 border-t-2 border-edge-strong', first ? 'left-1/2' : '-left-3', last ? 'right-1/2' : '-right-3')} />\n <span className=\"absolute left-1/2 top-0 h-full border-l-2 border-edge-strong\" />\n </span>\n ) : null}\n <div className=\"flex items-center justify-center gap-2 border-2 border-edge-strong bg-surface-base px-3 py-3 font-semibold text-content-primary\" data-slot=\"file-change-tree-root\">\n {marked && column.change ? <ChangeMark change={column.change} /> : null}\n <span className={cn('break-all', marked && column.change ? TONE[column.change].text : undefined)}>{column.name}</span>\n {marked && column.change ? <span className=\"sr-only\">({changes[column.change]})</span> : null}\n </div>\n {column.note != null ? <p data-slot=\"file-change-tree-note\" className=\"m-0 mt-2 text-pretty text-content-secondary\">{column.note}</p> : null}\n {(column.children?.length ?? 0) > 0 ? (\n <div className=\"ml-4 mt-4\">\n <Entries nodes={column.children ?? []} view={view} changeLabels={changes} />\n </div>\n ) : null}\n </div>\n );\n })}\n </div>\n {hideFooter ? null : (\n <div className=\"flex flex-wrap items-center justify-between gap-4\" data-slot=\"file-change-tree-footer\">\n <p className=\"m-0 flex flex-wrap gap-x-5 gap-y-1 font-mono tabular-nums\" data-slot=\"file-change-tree-tally\">\n {CHANGES.filter((change) => counts[change] > 0).map((change) => (\n <span key={change} className={TONE[change].text}>\n <span aria-hidden=\"true\">{GLYPH[change]}</span>\n {counts[change]} {changes[change]}\n </span>\n ))}\n </p>\n <div role=\"group\" aria-label={viewGroupLabel ?? 'View'} className=\"flex border-2 border-edge-default\" data-slot=\"file-change-tree-views\">\n {VIEWS.map((option, index) => (\n <button\n key={option}\n type=\"button\"\n aria-pressed={view === option}\n onClick={() => pick(option)}\n className={cn(\n 'px-4 py-1.5 text-content-secondary hover:bg-surface-raised',\n index > 0 && 'border-l-2 border-edge-default',\n view === option && 'bg-content-primary font-semibold text-content-inverse hover:bg-content-primary',\n )}\n >\n {views[option]}\n </button>\n ))}\n </div>\n </div>\n )}\n </AsciiFrameBody>\n );\n});\n"],"mappings":";;;AAGA,YAAY,WAAW;AACvB,SAAS,sBAAsB;AAC/B,SAAS,UAAU;AAgFf,cA2BoB,YA3BpB;AAzCJ,IAAM,QAAmC,CAAC,UAAU,WAA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B,WAAW;AAAA,YACT;AAAA,YACA,QAAQ,KAAK;AAAA,YACb,SAAS,UAAU;AAAA,UACrB;AAAA,UAEC,gBAAM,MAAM;AAAA;AAAA,QAVR;AAAA,MAWP,CACD,GACH;AAAA,OACF;AAAA,KAEJ;AAEJ,CAAC;","names":["FileChangeTree"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/docs/figures/FileChangeTree.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\nimport * as React from 'react';\nimport { AsciiFrameBody } from './FigureFrame';\nimport { cn } from '../../../lib/recipe';\n\nexport type FileChange = 'add' | 'modify' | 'remove' | 'rename';\nexport type FileChangeView = 'before' | 'changes' | 'after';\n\nexport interface FileChangeNode {\n /** File or directory name. A node with `children` is drawn as a directory. */\n name: string;\n /** How the file changed. Omit for an unchanged file or a directory. */\n change?: FileChange;\n /** One line on what changed, drawn under the name. */\n note?: ReactNode;\n /** Entries inside a directory. */\n children?: FileChangeNode[];\n}\n\nexport interface FileChangeTreeProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {\n /** Accessible name; the enclosing frame owns the caption. */\n label?: string;\n /** Top-level entries. Each one becomes a column under the shared connector. */\n nodes: FileChangeNode[];\n /** Controlled view. `changes` marks every entry; `before` and `after` show the tree on one side of the change. */\n view?: FileChangeView;\n /** Initial view when uncontrolled. */\n defaultView?: FileChangeView;\n /** Called when the reader picks a view. */\n onViewChange?: (view: FileChangeView) => void;\n /** Hide the before / changes / after switch and the tallies. */\n hideFooter?: boolean;\n /** Accessible label for the view selection button group. */\n viewGroupLabel?: string;\n /** Replaces the switch's button text, for translated pages. */\n viewLabels?: Partial<Record<FileChangeView, string>>;\n /** Replaces the tally words, for translated pages. */\n changeLabels?: Partial<Record<FileChange, string>>;\n /** Additional classes for the root. */\n className?: string;\n}\n\nconst VIEWS: readonly FileChangeView[] = ['before', 'changes', 'after'];\nconst CHANGES: readonly FileChange[] = ['add', 'modify', 'rename', 'remove'];\n\nconst DEFAULT_VIEW_LABELS: Record<FileChangeView, string> = { before: 'Before', changes: 'Changes', after: 'After' };\nconst DEFAULT_CHANGE_LABELS: Record<FileChange, string> = { add: 'added', modify: 'modified', rename: 'renamed', remove: 'removed' };\n\nconst GLYPH: Record<FileChange, string> = { add: '+', modify: '~', rename: '→', remove: '−' };\n\n/**\n * A change is a change, so it is addressed through the `delta` roles — not `intent`, which would\n * call an added file a success and a removed one a danger, and not accents, which carry nothing.\n * A modification has no delta role of its own: it is neither an addition nor a removal, so it\n * takes the secondary ink and is told apart by its `~` mark.\n */\nconst TONE: Record<FileChange, { text: string; fill: string }> = {\n add: { text: 'text-delta-added', fill: 'bg-delta-added' },\n modify: { text: 'text-content-secondary', fill: 'bg-content-secondary' },\n rename: { text: 'text-delta-moved', fill: 'bg-delta-moved' },\n remove: { text: 'text-delta-removed', fill: 'bg-delta-removed' },\n};\n\nfunction isDirectory(node: FileChangeNode): boolean {\n return node.children != null;\n}\n\n/** Drops what does not exist on one side of the change, and empty directories with it. */\nfunction visible(nodes: FileChangeNode[], view: FileChangeView): FileChangeNode[] {\n return nodes.flatMap((node) => {\n if (view === 'before' && node.change === 'add') return [];\n if (view === 'after' && node.change === 'remove') return [];\n if (!isDirectory(node)) return [node];\n const children = visible(node.children ?? [], view);\n return children.length > 0 || view === 'changes' ? [{ ...node, children }] : [];\n });\n}\n\nfunction tally(nodes: FileChangeNode[], counts: Record<FileChange, number> = { add: 0, modify: 0, rename: 0, remove: 0 }): Record<FileChange, number> {\n for (const node of nodes) {\n if (node.change) counts[node.change] += 1;\n if (node.children) tally(node.children, counts);\n }\n return counts;\n}\n\nfunction ChangeMark({ change }: { change: FileChange }) {\n return (\n <span\n aria-hidden=\"true\"\n data-slot=\"file-change-tree-mark\"\n className={cn('inline-flex size-4 shrink-0 select-none items-center justify-center text-[0.7rem] font-bold leading-none text-content-inverse', TONE[change].fill)}\n >\n {GLYPH[change]}\n </span>\n );\n}\n\nfunction Entries({ nodes, view, changeLabels }: { nodes: FileChangeNode[]; view: FileChangeView; changeLabels: Record<FileChange, string> }) {\n return (\n <ul className=\"flex flex-col gap-3\" data-slot=\"file-change-tree-list\">\n {nodes.map((node, index) => {\n const last = index === nodes.length - 1;\n const marked = view === 'changes' && node.change != null;\n const change = marked ? node.change : undefined;\n return (\n <li key={`${node.name}-${index}`} className=\"relative pl-6\" data-slot=\"file-change-tree-entry\">\n {/* The elbow: a stem down to this row, then a tick across to it. The last row's stem stops at its tick. */}\n <span aria-hidden=\"true\" className={cn('absolute left-0 top-0 border-l-2 border-edge-subtle', last ? 'h-[0.8em]' : '-bottom-3')} />\n <span aria-hidden=\"true\" className=\"absolute left-0 top-[0.8em] w-4 border-t-2 border-edge-subtle\" />\n <div className=\"flex items-center gap-2\">\n {change ? <ChangeMark change={change} /> : null}\n <span data-slot=\"file-change-tree-name\" className={cn('min-w-0 break-all font-mono', change ? TONE[change].text : 'text-content-primary', change === 'remove' && 'line-through')}>\n {node.name}\n </span>\n {change ? <span className=\"sr-only\">({changeLabels[change]})</span> : null}\n </div>\n {node.note != null && !isDirectory(node) ? <p data-slot=\"file-change-tree-note\" className=\"m-0 mt-1 text-pretty text-content-secondary\">{node.note}</p> : null}\n {isDirectory(node) && (node.children?.length ?? 0) > 0 ? (\n <div className=\"mt-3\">\n <Entries nodes={node.children ?? []} view={view} changeLabels={changeLabels} />\n </div>\n ) : null}\n </li>\n );\n })}\n </ul>\n );\n}\n\n/**\n * A changeset drawn as its directory layout: each top-level directory is a boxed column under\n * one connector, its files hang from a ruled tree with a change mark and a one-line note, and a\n * footer tallies the change and switches between the tree before, the change itself, and after.\n *\n * Stacks into one column below the `sm` breakpoint, where the connector is dropped.\n */\nexport const FileChangeTree = React.forwardRef<HTMLDivElement, FileChangeTreeProps>(function FileChangeTree(\n { label = 'File changes', nodes, view: viewProp, defaultView = 'changes', onViewChange, hideFooter = false, viewGroupLabel, viewLabels, changeLabels, className, ...rest },\n ref,\n) {\n const [uncontrolled, setUncontrolled] = React.useState<FileChangeView>(defaultView);\n const view = viewProp ?? uncontrolled;\n const views = { ...DEFAULT_VIEW_LABELS, ...viewLabels };\n const changes = { ...DEFAULT_CHANGE_LABELS, ...changeLabels };\n const columns = visible(nodes, view);\n const counts = tally(nodes);\n const connected = columns.length > 1;\n\n const pick = (next: FileChangeView) => {\n if (viewProp == null) setUncontrolled(next);\n onViewChange?.(next);\n };\n\n return (\n <AsciiFrameBody ref={ref} {...rest} data-slot=\"file-change-tree\" className={cn('flex flex-col gap-6 font-mono text-sm', className)}>\n <div role=\"list\" aria-label={label} className=\"flex flex-col gap-8 sm:flex-row sm:gap-6\">\n {columns.map((column, index) => {\n const first = index === 0;\n const last = index === columns.length - 1;\n const marked = view === 'changes' && column.change != null;\n return (\n <div role=\"listitem\" key={`${column.name}-${index}`} className=\"relative flex min-w-0 flex-1 flex-col\" data-slot=\"file-change-tree-column\">\n {connected ? (\n <span aria-hidden=\"true\" className=\"relative hidden h-6 sm:block\">\n {/* The shared bar, carried half a gap past each side so neighbours meet; the ends stop at the drop. */}\n <span className={cn('absolute top-0 border-t-2 border-edge-strong', first ? 'left-1/2' : '-left-3', last ? 'right-1/2' : '-right-3')} />\n <span className=\"absolute left-1/2 top-0 h-full border-l-2 border-edge-strong\" />\n </span>\n ) : null}\n <div className=\"flex items-center justify-center gap-2 border-2 border-edge-strong bg-surface-base px-3 py-3 font-semibold text-content-primary\" data-slot=\"file-change-tree-root\">\n {marked && column.change ? <ChangeMark change={column.change} /> : null}\n <span className={cn('break-all', marked && column.change ? TONE[column.change].text : undefined)}>{column.name}</span>\n {marked && column.change ? <span className=\"sr-only\">({changes[column.change]})</span> : null}\n </div>\n {column.note != null ? <p data-slot=\"file-change-tree-note\" className=\"m-0 mt-2 text-pretty text-content-secondary\">{column.note}</p> : null}\n {(column.children?.length ?? 0) > 0 ? (\n <div className=\"ml-4 mt-4\">\n <Entries nodes={column.children ?? []} view={view} changeLabels={changes} />\n </div>\n ) : null}\n </div>\n );\n })}\n </div>\n {hideFooter ? null : (\n <div className=\"flex flex-wrap items-center justify-between gap-4\" data-slot=\"file-change-tree-footer\">\n <p className=\"m-0 flex flex-wrap gap-x-5 gap-y-1 font-mono tabular-nums\" data-slot=\"file-change-tree-tally\">\n {CHANGES.filter((change) => counts[change] > 0).map((change) => (\n <span key={change} className={TONE[change].text}>\n <span aria-hidden=\"true\">{GLYPH[change]}</span>\n {counts[change]} {changes[change]}\n </span>\n ))}\n </p>\n <div role=\"group\" aria-label={viewGroupLabel ?? 'View'} className=\"flex border-2 border-edge-default\" data-slot=\"file-change-tree-views\">\n {VIEWS.map((option, index) => (\n <button\n key={option}\n type=\"button\"\n aria-pressed={view === option}\n onClick={() => pick(option)}\n className={cn(\n 'px-4 py-1.5 text-content-secondary hover:bg-surface-raised',\n index > 0 && 'border-l-2 border-edge-default',\n view === option && 'bg-content-primary font-semibold text-content-inverse hover:bg-content-primary',\n )}\n >\n {views[option]}\n </button>\n ))}\n </div>\n </div>\n )}\n </AsciiFrameBody>\n );\n});\n"],"mappings":";;;AAGA,YAAY,WAAW;AACvB,SAAS,sBAAsB;AAC/B,SAAS,UAAU;AAqFf,cA2BoB,YA3BpB;AA9CJ,IAAM,QAAmC,CAAC,UAAU,WAAW,OAAO;AACtE,IAAM,UAAiC,CAAC,OAAO,UAAU,UAAU,QAAQ;AAE3E,IAAM,sBAAsD,EAAE,QAAQ,UAAU,SAAS,WAAW,OAAO,QAAQ;AACnH,IAAM,wBAAoD,EAAE,KAAK,SAAS,QAAQ,YAAY,QAAQ,WAAW,QAAQ,UAAU;AAEnI,IAAM,QAAoC,EAAE,KAAK,KAAK,QAAQ,KAAK,QAAQ,UAAK,QAAQ,SAAI;AAQ5F,IAAM,OAA2D;AAAA,EAC/D,KAAK,EAAE,MAAM,oBAAoB,MAAM,iBAAiB;AAAA,EACxD,QAAQ,EAAE,MAAM,0BAA0B,MAAM,uBAAuB;AAAA,EACvE,QAAQ,EAAE,MAAM,oBAAoB,MAAM,iBAAiB;AAAA,EAC3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ACb,8BAAC,WAAQ,OAAO,OAAO,YAAY,CAAC,GAAG,MAAY,cAAc,SAAS,GAC5E,IACE;AAAA,WAlBoB,GAAG,OAAO,IAAI,IAAI,KAAK,EAmBjD;AAAA,IAEJ,CAAC,GACH;AAAA,IACC,aAAa,OACZ,qBAAC,SAAI,WAAU,qDAAoD,aAAU,2BAC3E;AAAA,0BAAC,OAAE,WAAU,6DAA4D,aAAU,0BAChF,kBAAQ,OAAO,CAAC,WAAW,OAAO,MAAM,IAAI,CAAC,EAAE,IAAI,CAAC,WACnD,qBAAC,UAAkB,WAAW,KAAK,MAAM,EAAE,MACzC;AAAA,4BAAC,UAAK,eAAY,QAAQ,gBAAM,MAAM,GAAE;AAAA,QACvC,OAAO,MAAM;AAAA,QAAE;AAAA,QAAE,QAAQ,MAAM;AAAA,WAFvB,MAGX,CACD,GACH;AAAA,MACA,oBAAC,SAAI,MAAK,SAAQ,cAAY,kBAAkB,QAAQ,WAAU,qCAAoC,aAAU,0BAC7G,gBAAM,IAAI,CAAC,QAAQ,UAClB;AAAA,QAAC;AAAA;AAAA,UAEC,MAAK;AAAA,UACL,gBAAc,SAAS;AAAA,UACvB,SAAS,MAAM,KAAK,MAAM;AAAA,UAC1B,WAAW;AAAA,YACT;AAAA,YACA,QAAQ,KAAK;AAAA,YACb,SAAS,UAAU;AAAA,UACrB;AAAA,UAEC,gBAAM,MAAM;AAAA;AAAA,QAVR;AAAA,MAWP,CACD,GACH;AAAA,OACF;AAAA,KAEJ;AAEJ,CAAC;","names":["FileChangeTree"]}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
// src/components/docs/figures/IndexedSection.tsx
|
|
2
4
|
import * as React from "react";
|
|
3
5
|
import { cn } from "../../../lib/recipe.js";
|
|
6
|
+
import { FigureSurfaceContext } from "./FigureSurfaceContext.js";
|
|
4
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
var IndexedSection = React.forwardRef(function IndexedSection2({ index, title, headingLevel = 3, actions, children, className, ...rest }, ref) {
|
|
8
|
+
var IndexedSection = React.forwardRef(function IndexedSection2({ index, title, headingLevel = 3, actions, surface, children, className, ...rest }, ref) {
|
|
9
|
+
const enclosingSurface = React.useContext(FigureSurfaceContext);
|
|
10
|
+
const resolvedSurface = surface ?? (enclosingSurface === "sheet" ? "raised" : "base");
|
|
11
|
+
const surfaceClass = resolvedSurface === "raised" ? "bg-surface-raised" : resolvedSurface === "transparent" ? "bg-transparent" : "bg-surface-base";
|
|
6
12
|
const headingId = React.useId();
|
|
7
13
|
const Heading = `h${headingLevel}`;
|
|
8
14
|
return /* @__PURE__ */ jsxs(
|
|
@@ -12,7 +18,7 @@ var IndexedSection = React.forwardRef(function IndexedSection2({ index, title, h
|
|
|
12
18
|
"aria-labelledby": headingId,
|
|
13
19
|
...rest,
|
|
14
20
|
"data-slot": "indexed-section",
|
|
15
|
-
className: cn("flex min-w-0 flex-col border-2 border-edge-strong
|
|
21
|
+
className: cn("flex min-w-0 flex-col border-2 border-edge-strong", surfaceClass, className),
|
|
16
22
|
children: [
|
|
17
23
|
/* @__PURE__ */ jsxs("header", { "data-slot": "indexed-section-header", className: "flex items-stretch border-b-2 border-edge-strong", children: [
|
|
18
24
|
/* @__PURE__ */ jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/docs/figures/IndexedSection.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/docs/figures/IndexedSection.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\nimport * as React from 'react';\nimport { cn } from '../../../lib/recipe';\nimport { FigureSurfaceContext } from './FigureSurfaceContext';\n\nexport interface IndexedSectionProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {\n /** Short reference drawn in the solid tab, such as `A`, `B2`, or `01`. */\n index: ReactNode;\n /** Section heading. */\n title: ReactNode;\n /** Heading level for `title`, so the section sits correctly in the page outline. */\n headingLevel?: 2 | 3 | 4;\n /** Controls drawn at the right of the header, such as a comment button. */\n actions?: ReactNode;\n /**\n * Surface elevation rung for the section background.\n * If omitted, defaults to `'raised'` when nested in a `DrawingSheet`, or `'base'` standalone.\n */\n surface?: 'base' | 'raised' | 'transparent';\n /** Section content. */\n children?: ReactNode;\n /** Additional classes for the root. */\n className?: string;\n}\n\n/**\n * An indexed section container: a solid high-contrast index tab, a heading, an optional actions\n * slot, and a hard-ruled body. Works on its own, inside an article/spec, or within a `DrawingSheet`.\n */\nexport const IndexedSection = React.forwardRef<HTMLElement, IndexedSectionProps>(function IndexedSection(\n { index, title, headingLevel = 3, actions, surface, children, className, ...rest },\n ref,\n) {\n const enclosingSurface = React.useContext(FigureSurfaceContext);\n const resolvedSurface = surface ?? (enclosingSurface === 'sheet' ? 'raised' : 'base');\n const surfaceClass = resolvedSurface === 'raised'\n ? 'bg-surface-raised'\n : resolvedSurface === 'transparent'\n ? 'bg-transparent'\n : 'bg-surface-base';\n\n const headingId = React.useId();\n const Heading = `h${headingLevel}` as const;\n return (\n <section\n ref={ref}\n aria-labelledby={headingId}\n {...rest}\n data-slot=\"indexed-section\"\n className={cn('flex min-w-0 flex-col border-2 border-edge-strong', surfaceClass, className)}\n >\n <header data-slot=\"indexed-section-header\" className=\"flex items-stretch border-b-2 border-edge-strong\">\n <span\n data-slot=\"indexed-section-index\"\n className=\"flex min-w-12 items-center justify-center bg-content-primary px-3 font-mono text-lg font-bold text-content-inverse\"\n >\n {index}\n </span>\n <Heading\n id={headingId}\n data-slot=\"indexed-section-title\"\n className=\"m-0 flex flex-1 items-center px-4 py-3 font-mono text-lg font-bold tracking-tight text-content-primary\"\n >\n {title}\n </Heading>\n {actions != null ? (\n <div data-slot=\"indexed-section-actions\" className=\"flex items-center gap-2 px-3\">\n {actions}\n </div>\n ) : null}\n </header>\n <div data-slot=\"indexed-section-body\" className=\"min-w-0 p-4 sm:p-6\">\n {children}\n </div>\n </section>\n );\n});\n"],"mappings":";;;AAGA,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,4BAA4B;AAgD/B,SACE,KADF;AAtBC,IAAM,iBAAuB,iBAA6C,SAASA,gBACxF,EAAE,OAAO,OAAO,eAAe,GAAG,SAAS,SAAS,UAAU,WAAW,GAAG,KAAK,GACjF,KACA;AACA,QAAM,mBAAyB,iBAAW,oBAAoB;AAC9D,QAAM,kBAAkB,YAAY,qBAAqB,UAAU,WAAW;AAC9E,QAAM,eAAe,oBAAoB,WACrC,sBACA,oBAAoB,gBAClB,mBACA;AAEN,QAAM,YAAkB,YAAM;AAC9B,QAAM,UAAU,IAAI,YAAY;AAChC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,mBAAiB;AAAA,MAChB,GAAG;AAAA,MACJ,aAAU;AAAA,MACV,WAAW,GAAG,qDAAqD,cAAc,SAAS;AAAA,MAE1F;AAAA,6BAAC,YAAO,aAAU,0BAAyB,WAAU,oDACnD;AAAA;AAAA,YAAC;AAAA;AAAA,cACC,aAAU;AAAA,cACV,WAAU;AAAA,cAET;AAAA;AAAA,UACH;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACC,IAAI;AAAA,cACJ,aAAU;AAAA,cACV,WAAU;AAAA,cAET;AAAA;AAAA,UACH;AAAA,UACC,WAAW,OACV,oBAAC,SAAI,aAAU,2BAA0B,WAAU,gCAChD,mBACH,IACE;AAAA,WACN;AAAA,QACA,oBAAC,SAAI,aAAU,wBAAuB,WAAU,sBAC7C,UACH;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;","names":["IndexedSection"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/docs/figures/index.ts"],"sourcesContent":["export { FigureFrame } from './FigureFrame';\nexport type { FigureFrameProps } from './FigureFrame';\nexport * from './FlowDiagram';\nexport * from './Timeline';\nexport * from './ChangeSummary';\nexport * from './BeforeAfter';\nexport * from './UptimeStrip';\nexport * from './TreeDiagram';\nexport * from './FileChangeTree';\nexport * from './DrawingSheet';\nexport * from './IndexedSection';\nexport * from './ActivityGrid';\nexport * from './GanttChart';\nexport * from './Terminal';\nexport * from './Steps';\nexport * from './SwatchCompare';\nexport * from './MetricStrip';\nexport * from './TokenTable';\nexport * from './Decision';\nexport * from './TermGrid';\n"],"mappings":";AAAA,SAAS,mBAAmB;AAE5B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/docs/figures/index.ts"],"sourcesContent":["export { FigureFrame } from './FigureFrame';\nexport type { FigureFrameProps } from './FigureFrame';\nexport * from './FlowDiagram';\nexport * from './Timeline';\nexport * from './ChangeSummary';\nexport * from './BeforeAfter';\nexport * from './UptimeStrip';\nexport * from './TreeDiagram';\nexport * from './FileChangeTree';\nexport * from './DrawingSheet';\nexport * from './IndexedSection';\nexport type { FigureSurface } from './FigureSurfaceContext';\nexport * from './ActivityGrid';\nexport * from './GanttChart';\nexport * from './Terminal';\nexport * from './Steps';\nexport * from './SwatchCompare';\nexport * from './MetricStrip';\nexport * from './TokenTable';\nexport * from './Decision';\nexport * from './TermGrid';\n"],"mappings":";AAAA,SAAS,mBAAmB;AAE5B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/hooks/usePolledResource.ts
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
function messageOf(reason) {
|
|
6
|
+
return (reason instanceof Error ? reason.message : String(reason)) || "Unknown error";
|
|
7
|
+
}
|
|
8
|
+
function usePolledResource(load, { key, intervalMs = 3e4, enabled = true } = {}) {
|
|
9
|
+
const [snapshot, setSnapshot] = useState(() => ({
|
|
10
|
+
key,
|
|
11
|
+
data: void 0,
|
|
12
|
+
error: void 0,
|
|
13
|
+
loading: enabled,
|
|
14
|
+
updatedAt: void 0
|
|
15
|
+
}));
|
|
16
|
+
const loadRef = useRef(load);
|
|
17
|
+
const keyRef = useRef(key);
|
|
18
|
+
const intervalRef = useRef(intervalMs);
|
|
19
|
+
const enabledRef = useRef(enabled);
|
|
20
|
+
const generation = useRef(0);
|
|
21
|
+
const timer = useRef(void 0);
|
|
22
|
+
const missed = useRef(false);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
loadRef.current = load;
|
|
25
|
+
keyRef.current = key;
|
|
26
|
+
intervalRef.current = intervalMs;
|
|
27
|
+
enabledRef.current = enabled;
|
|
28
|
+
});
|
|
29
|
+
const run = useCallback(function loadNow() {
|
|
30
|
+
if (!enabledRef.current) return;
|
|
31
|
+
clearTimeout(timer.current);
|
|
32
|
+
missed.current = false;
|
|
33
|
+
const mine = ++generation.current;
|
|
34
|
+
const forKey = keyRef.current;
|
|
35
|
+
setSnapshot(
|
|
36
|
+
(prev) => prev.key === forKey ? { ...prev, loading: true } : { key: forKey, data: void 0, error: void 0, loading: true, updatedAt: void 0 }
|
|
37
|
+
);
|
|
38
|
+
const schedule = () => {
|
|
39
|
+
const every = intervalRef.current;
|
|
40
|
+
if (every <= 0) return;
|
|
41
|
+
timer.current = setTimeout(() => {
|
|
42
|
+
if (document.visibilityState === "visible") loadNow();
|
|
43
|
+
else missed.current = true;
|
|
44
|
+
}, every);
|
|
45
|
+
};
|
|
46
|
+
let pending;
|
|
47
|
+
try {
|
|
48
|
+
pending = Promise.resolve(loadRef.current());
|
|
49
|
+
} catch (reason) {
|
|
50
|
+
pending = Promise.reject(reason);
|
|
51
|
+
}
|
|
52
|
+
pending.then(
|
|
53
|
+
(value) => {
|
|
54
|
+
if (mine !== generation.current) return;
|
|
55
|
+
setSnapshot({ key: forKey, data: value, error: void 0, loading: false, updatedAt: Date.now() });
|
|
56
|
+
schedule();
|
|
57
|
+
},
|
|
58
|
+
(reason) => {
|
|
59
|
+
if (mine !== generation.current) return;
|
|
60
|
+
setSnapshot((prev) => ({ ...prev, error: messageOf(reason), loading: false }));
|
|
61
|
+
schedule();
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}, []);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!enabled) return void 0;
|
|
67
|
+
const requests = generation;
|
|
68
|
+
run();
|
|
69
|
+
return () => {
|
|
70
|
+
requests.current++;
|
|
71
|
+
clearTimeout(timer.current);
|
|
72
|
+
missed.current = false;
|
|
73
|
+
setSnapshot((prev) => prev.loading ? { ...prev, loading: false } : prev);
|
|
74
|
+
};
|
|
75
|
+
}, [key, enabled, intervalMs, run]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!enabled) return void 0;
|
|
78
|
+
const onVisibilityChange = () => {
|
|
79
|
+
if (document.visibilityState === "visible" && missed.current) run();
|
|
80
|
+
};
|
|
81
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
82
|
+
return () => document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
83
|
+
}, [enabled, run]);
|
|
84
|
+
if (snapshot.key !== key) {
|
|
85
|
+
return { data: void 0, error: void 0, loading: enabled, updatedAt: void 0, reload: run };
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
data: snapshot.data,
|
|
89
|
+
error: snapshot.error,
|
|
90
|
+
loading: enabled && snapshot.loading,
|
|
91
|
+
updatedAt: snapshot.updatedAt,
|
|
92
|
+
reload: run
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
usePolledResource
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=usePolledResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/usePolledResource.ts"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nexport interface UsePolledResourceOptions {\n /**\n * What is being loaded — an id, a filter, a page number. A change of key\n * drops the previous key's data and loads afresh. The load function itself is\n * read through a ref, so a new closure on every render reloads nothing; the\n * key is what says the question changed.\n */\n key?: string | number;\n /**\n * Milliseconds between loads, counted from when the previous one settled.\n * Default `30_000`. Zero or less loads once and never polls.\n */\n intervalMs?: number;\n /** Load and poll while true. Default true. While false nothing loads, and `reload` does nothing. */\n enabled?: boolean;\n}\n\nexport interface UsePolledResourceResult<T> {\n /** The last good answer for the current key, kept when a later load fails. */\n data: T | undefined;\n /** Why the latest load failed, as a message; cleared by the next success. */\n error: string | undefined;\n /** True while a load for the current key is in flight. */\n loading: boolean;\n /** When `data` was last loaded, as epoch milliseconds — what `FreshnessIndicator` takes as `updatedAt`. */\n updatedAt: number | undefined;\n /** Load now, superseding any load in flight, and restart the poll from when it settles. */\n reload: () => void;\n}\n\ninterface Snapshot<T> {\n key: string | number | undefined;\n data: T | undefined;\n error: string | undefined;\n loading: boolean;\n updatedAt: number | undefined;\n}\n\n/** An error, a rejection reason or a thrown string, as one line a person can read. */\nfunction messageOf(reason: unknown): string {\n // `new Error()` and `reject('')` still failed; an empty message must not read as success.\n return (reason instanceof Error ? reason.message : String(reason)) || 'Unknown error';\n}\n\n/**\n * Data that refreshes itself while someone is looking at it.\n *\n * Loads once on mount, then again `intervalMs` after each load settles — but\n * only while `document.visibilityState` is `visible`. A background tab costs\n * nothing. A tick that falls due while the tab is hidden is remembered, and the\n * load happens the moment the tab is shown again, so a reader returning after\n * ten minutes sees fresh data at once rather than ten-minute-old data for up to\n * another interval. A tab that is hidden and shown again *before* a tick fell\n * due does not load, so switching back and forth does not hammer the source.\n *\n * Counting the interval from when a load settles, not on a fixed clock, means a\n * load slower than the interval is never cut off by the next tick.\n *\n * ## What it guarantees\n *\n * - **The newest request wins.** Every load takes a generation number, and an\n * answer that arrives after a newer request was made is discarded. A slow\n * response for an old key can never overwrite a fast one for the new key.\n * - **A failure keeps the last good answer.** `data` survives a failed load and\n * `error` says why, so a view can show what it had with a stale warning —\n * which is what `ResourceState` renders.\n * - **A new key starts empty.** Changing `key` clears `data`, `error` and\n * `updatedAt` in the same render, so the previous key's answer is never\n * shown as though it belonged to the new one.\n *\n * Errors are normalised to a message string: the one thing a view does with a\n * failure is show it, and doing that once here saves every caller doing it.\n */\nexport function usePolledResource<T>(\n load: () => Promise<T>,\n { key, intervalMs = 30_000, enabled = true }: UsePolledResourceOptions = {},\n): UsePolledResourceResult<T> {\n const [snapshot, setSnapshot] = useState<Snapshot<T>>(() => ({\n key,\n data: undefined,\n error: undefined,\n loading: enabled,\n updatedAt: undefined,\n }));\n\n const loadRef = useRef(load);\n const keyRef = useRef(key);\n const intervalRef = useRef(intervalMs);\n const enabledRef = useRef(enabled);\n const generation = useRef(0);\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const missed = useRef(false);\n\n // Declared first, so every effect below reads this render's values.\n useEffect(() => {\n loadRef.current = load;\n keyRef.current = key;\n intervalRef.current = intervalMs;\n enabledRef.current = enabled;\n });\n\n // Named, so the poll's timeout re-enters it without reading `run` before it exists.\n const run = useCallback(function loadNow() {\n if (!enabledRef.current) return;\n clearTimeout(timer.current);\n missed.current = false;\n const mine = ++generation.current;\n const forKey = keyRef.current;\n\n setSnapshot((prev) =>\n prev.key === forKey\n ? { ...prev, loading: true }\n : { key: forKey, data: undefined, error: undefined, loading: true, updatedAt: undefined },\n );\n\n const schedule = () => {\n const every = intervalRef.current;\n if (every <= 0) return;\n timer.current = setTimeout(() => {\n if (document.visibilityState === 'visible') loadNow();\n else missed.current = true;\n }, every);\n };\n\n let pending: Promise<T>;\n try {\n pending = Promise.resolve(loadRef.current());\n } catch (reason) {\n pending = Promise.reject(reason);\n }\n\n pending.then(\n (value) => {\n if (mine !== generation.current) return;\n setSnapshot({ key: forKey, data: value, error: undefined, loading: false, updatedAt: Date.now() });\n schedule();\n },\n (reason: unknown) => {\n if (mine !== generation.current) return;\n setSnapshot((prev) => ({ ...prev, error: messageOf(reason), loading: false }));\n schedule();\n },\n );\n }, []);\n\n useEffect(() => {\n if (!enabled) return undefined;\n const requests = generation;\n run();\n return () => {\n // Whatever is in flight now answers a question nobody is asking.\n requests.current++;\n clearTimeout(timer.current);\n missed.current = false;\n setSnapshot((prev) => (prev.loading ? { ...prev, loading: false } : prev));\n };\n }, [key, enabled, intervalMs, run]);\n\n useEffect(() => {\n if (!enabled) return undefined;\n const onVisibilityChange = () => {\n if (document.visibilityState === 'visible' && missed.current) run();\n };\n document.addEventListener('visibilitychange', onVisibilityChange);\n return () => document.removeEventListener('visibilitychange', onVisibilityChange);\n }, [enabled, run]);\n\n // The render after a key change, before the effect has loaded anything: the\n // snapshot still holds the old key's answer, which must not be shown.\n if (snapshot.key !== key) {\n return { data: undefined, error: undefined, loading: enabled, updatedAt: undefined, reload: run };\n }\n\n return {\n data: snapshot.data,\n error: snapshot.error,\n loading: enabled && snapshot.loading,\n updatedAt: snapshot.updatedAt,\n reload: run,\n };\n}\n"],"mappings":";;;AAEA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAyCzD,SAAS,UAAU,QAAyB;AAE1C,UAAQ,kBAAkB,QAAQ,OAAO,UAAU,OAAO,MAAM,MAAM;AACxE;AA+BO,SAAS,kBACd,MACA,EAAE,KAAK,aAAa,KAAQ,UAAU,KAAK,IAA8B,CAAC,GAC9C;AAC5B,QAAM,CAAC,UAAU,WAAW,IAAI,SAAsB,OAAO;AAAA,IAC3D;AAAA,IACA,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,EACb,EAAE;AAEF,QAAM,UAAU,OAAO,IAAI;AAC3B,QAAM,SAAS,OAAO,GAAG;AACzB,QAAM,cAAc,OAAO,UAAU;AACrC,QAAM,aAAa,OAAO,OAAO;AACjC,QAAM,aAAa,OAAO,CAAC;AAC3B,QAAM,QAAQ,OAAkD,MAAS;AACzE,Q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