@krapwoo/ds-viewer 0.2.0 → 0.4.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.
Files changed (52) hide show
  1. package/README.md +151 -0
  2. package/config/index.ts +4 -2
  3. package/dist/cli/agentsFile.js +31 -0
  4. package/dist/cli/dev.js +312 -15
  5. package/dist/cli/doctor.js +502 -0
  6. package/dist/cli/endpoint.js +142 -0
  7. package/dist/cli/explain.js +151 -0
  8. package/dist/cli/githubAction.js +65 -0
  9. package/dist/cli/init.js +9 -5
  10. package/dist/cli/kitDiff.js +132 -0
  11. package/dist/cli/kitRoot.js +20 -0
  12. package/dist/cli/main.js +123 -15
  13. package/dist/cli/migrate.js +30 -0
  14. package/dist/cli/migrateEntry.js +19 -0
  15. package/dist/cli/migrations/index.js +14 -0
  16. package/dist/cli/migrations/types.js +9 -0
  17. package/dist/cli/packageManager.js +29 -0
  18. package/dist/cli/packageVersion.js +24 -0
  19. package/dist/cli/pageIndex.js +27 -1
  20. package/dist/cli/props.js +4 -3
  21. package/dist/cli/semver.js +26 -0
  22. package/dist/cli/staticPage.js +356 -0
  23. package/dist/cli/sync.js +11 -4
  24. package/dist/cli/update.js +93 -0
  25. package/dist/cli/updateCheck.js +143 -0
  26. package/dist/cli/updatePlan.js +202 -0
  27. package/dist/cli/workspace.js +10 -5
  28. package/dist/native/catalog/catalogNavigation.js +129 -0
  29. package/dist/native/catalog/comparison.js +283 -0
  30. package/dist/native/catalog/tokens.js +134 -0
  31. package/dist/native/catalog/types.js +1 -0
  32. package/native/catalog/CatalogShell.tsx +105 -11
  33. package/native/catalog/CatalogSidebar.tsx +58 -2
  34. package/native/catalog/ComparisonGrid.tsx +9 -7
  35. package/native/catalog/SectionBlock.tsx +5 -0
  36. package/native/catalog/SpacingScaleGallery.tsx +1 -1
  37. package/native/catalog/UpdatePanel.tsx +556 -0
  38. package/native/catalog/catalogNavigation.ts +70 -1
  39. package/native/catalog/comparison.ts +63 -5
  40. package/native/catalog/index.ts +5 -1
  41. package/native/catalog/pageApi.ts +11 -2
  42. package/native/catalog/tokens.ts +15 -0
  43. package/native/catalog/types.ts +19 -5
  44. package/native/catalog/updatePanelState.ts +74 -0
  45. package/package.json +5 -1
  46. package/starter-kit/components/Avatar/Avatar.catalog.tsx +4 -22
  47. package/starter-kit/components/Badge/Badge.catalog.tsx +15 -23
  48. package/starter-kit/components/Banner/Banner.tsx +1 -1
  49. package/starter-kit/components/BottomSheet/BottomSheet.tsx +2 -2
  50. package/starter-kit/components/Button/Button.catalog.tsx +15 -29
  51. package/starter-kit/components/Dialog/Dialog.tsx +2 -2
  52. package/starter-kit/components/Pill/Pill.catalog.tsx +12 -26
@@ -0,0 +1,283 @@
1
+ /** Approved geometry. `cellPadding` equals CATALOG_SPACE.lg (asserted in tests). The laptop
2
+ * content width is a 1280px viewport minus the 264px sidebar and 32px side padding. */
3
+ export const MATRIX_LAYOUT = {
4
+ rowHeaderWidth: 120,
5
+ columnMaxWidth: 402,
6
+ cellPadding: 16,
7
+ rowMinHeight: 150,
8
+ laptopContentWidth: 952,
9
+ };
10
+ /** Component previews never render wider than a phone. */
11
+ export const PREVIEW_MAX_WIDTH = 402;
12
+ /** Two blocks share a row only when that saves at least this much page height. */
13
+ export const PLACEMENT_MIN_SAVING = 120;
14
+ /** A Props column is never narrower than this; below it the Props box uses one column. */
15
+ export const PROPS_MIN_COLUMN_WIDTH = 360;
16
+ /** Gap between the two Props columns (CATALOG_SPACE['2xl']). */
17
+ export const PROPS_COLUMN_GAP = 32;
18
+ /** Smallest column or cell width per specimen size. Wide specimens are fixed at phone width. */
19
+ export const COLUMN_MIN_WIDTH = { compact: 160, regular: 240, wide: 402 };
20
+ /** `Array.isArray`'s built-in type guard narrows to a mutable `any[]`, which a `readonly T[]`
21
+ * union member is never assignable to — so the `else` branch of `Array.isArray(axis) ? ... :
22
+ * ...` keeps `axis`'s full union type instead of narrowing away the array member. This explicit
23
+ * predicate sidesteps that (never caught before Task 4: this file had never been typechecked by
24
+ * `tsc` until `cli/doctor.ts`'s import pulled it into the root `tsconfig.json`'s program). */
25
+ function isBoundAxis(axis) {
26
+ return !Array.isArray(axis);
27
+ }
28
+ /** A `GridAxis`'s own items, whether it's a plain array or bound to a prop — every reader of
29
+ * `ComparisonDef.rows`/`columns` goes through this (never `Array.isArray` directly), so a future
30
+ * third axis shape only needs to change this one function. */
31
+ export function axisItems(axis) {
32
+ return isBoundAxis(axis) ? [...axis.items] : [...axis];
33
+ }
34
+ /** The prop name a `GridAxis` is bound to, or undefined for a plain, unbound axis. */
35
+ export function axisProp(axis) {
36
+ return isBoundAxis(axis) ? axis.prop : undefined;
37
+ }
38
+ /**
39
+ * Shared page-authoring helper (design §1 "Page shape", §4 "Binding examples to props"). Every
40
+ * grid comparison in the starter kit builds its `ComparisonDef` with this instead of its own local
41
+ * copy, so `cli/staticPage.ts`'s static reader has exactly one call shape to recognize anywhere a
42
+ * page's `comparison` field is produced by a function call rather than written as a plain object
43
+ * literal. `rows`/`columns` accept either a plain item array (unbound) or `{ prop, items }` (bound)
44
+ * — the cell grid itself is unaffected either way, since cells are always keyed by each axis's own
45
+ * items regardless of whether that axis names a prop. Lives here, beside `axisItems`/`axisProp`,
46
+ * rather than in its own `grid.ts` — every other file in this module has only *type-only* relative
47
+ * imports; a bare, no-extension value import would be the first of its kind in `native/catalog`.
48
+ *
49
+ * Each cell is a real instance with exactly the props its row and column name. Never build these by
50
+ * multiplying `variants` with `states` — those are pre-rendered nodes and cannot be combined.
51
+ */
52
+ export function grid(rowLabel, columnLabel, rows, columns, cell, size) {
53
+ const rowItems = axisItems(rows);
54
+ const columnItems = axisItems(columns);
55
+ return {
56
+ rowLabel,
57
+ columnLabel,
58
+ rows,
59
+ columns,
60
+ cells: rowItems.flatMap((row) => columnItems.map((column) => ({ rowKey: row.key, columnKey: column.key, node: cell(row.key, column.key) }))),
61
+ size,
62
+ };
63
+ }
64
+ /** How many grid columns fit beside the row header on a 1280px laptop without scrolling. */
65
+ export function gridColumnLimit(size) {
66
+ return Math.floor((MATRIX_LAYOUT.laptopContentWidth - MATRIX_LAYOUT.rowHeaderWidth) / COLUMN_MIN_WIDTH[size]);
67
+ }
68
+ export function gridWidthBounds(columnCount, size) {
69
+ const n = Math.max(0, columnCount);
70
+ return {
71
+ minWidth: MATRIX_LAYOUT.rowHeaderWidth + n * COLUMN_MIN_WIDTH[size],
72
+ maxWidth: MATRIX_LAYOUT.rowHeaderWidth + n * MATRIX_LAYOUT.columnMaxWidth,
73
+ };
74
+ }
75
+ /** Balanced wrapping for a one-axis list inside a single bordered card (1px outer border). Each
76
+ * cell's 1px divider sits inside its own width, so no cell is ever wider than 402px. Uses as few
77
+ * rows as fit, then spreads items evenly across them so a short last row leaves as little empty
78
+ * space as possible. `fillers` blank cells complete the last row. */
79
+ export function listGeometry(itemCount, availableWidth, size) {
80
+ if (itemCount <= 0)
81
+ return { columns: 0, rows: 0, fillers: 0, cellWidth: 0, containerWidth: 0 };
82
+ const inner = Math.max(0, availableWidth - 2);
83
+ const min = COLUMN_MIN_WIDTH[size];
84
+ const maxColumns = Math.max(1, Math.min(itemCount, Math.floor(inner / min)));
85
+ const rows = Math.ceil(itemCount / maxColumns);
86
+ const columns = Math.ceil(itemCount / rows);
87
+ const fitted = Math.floor(inner / columns);
88
+ const cellWidth = size === 'wide' ? MATRIX_LAYOUT.columnMaxWidth : Math.max(min, Math.min(MATRIX_LAYOUT.columnMaxWidth, fitted));
89
+ return {
90
+ columns,
91
+ rows,
92
+ fillers: rows * columns - itemCount,
93
+ cellWidth,
94
+ containerWidth: columns * cellWidth + 2,
95
+ };
96
+ }
97
+ export function cellKey(rowKey, columnKey) {
98
+ return `${rowKey}\u0000${columnKey}`;
99
+ }
100
+ export function indexCells(def) {
101
+ const index = new Map();
102
+ for (const cell of def.cells) {
103
+ const key = cellKey(cell.rowKey, cell.columnKey);
104
+ if (!index.has(key))
105
+ index.set(key, cell);
106
+ }
107
+ return index;
108
+ }
109
+ /** Human-readable problems in a stable order: axis duplicates, column fit, each cell in
110
+ * declaration order, then missing coordinates in row-major order. Empty when valid. */
111
+ export function validateComparison(def) {
112
+ const rowItems = axisItems(def.rows);
113
+ const columnItems = axisItems(def.columns);
114
+ if (rowItems.length === 0 || columnItems.length === 0) {
115
+ return ['Comparison needs at least one row and one column.'];
116
+ }
117
+ const issues = [];
118
+ const rowKeys = new Set();
119
+ for (const row of rowItems) {
120
+ if (rowKeys.has(row.key))
121
+ issues.push(`Duplicate row key "${row.key}".`);
122
+ rowKeys.add(row.key);
123
+ }
124
+ const columnKeys = new Set();
125
+ for (const column of columnItems) {
126
+ if (columnKeys.has(column.key))
127
+ issues.push(`Duplicate column key "${column.key}".`);
128
+ columnKeys.add(column.key);
129
+ }
130
+ const size = def.size ?? 'regular';
131
+ const limit = gridColumnLimit(size);
132
+ if (columnKeys.size > limit) {
133
+ issues.push(`Grid has ${columnKeys.size} columns; at most ${limit} ${size} columns fit a 1280px laptop. Swap the axes or use two lists.`);
134
+ }
135
+ const seen = new Set();
136
+ for (const cell of def.cells) {
137
+ const key = cellKey(cell.rowKey, cell.columnKey);
138
+ if (seen.has(key)) {
139
+ issues.push(`Duplicate cell for row "${cell.rowKey}" and column "${cell.columnKey}".`);
140
+ continue;
141
+ }
142
+ seen.add(key);
143
+ if (!rowKeys.has(cell.rowKey)) {
144
+ issues.push(`Cell references undeclared row "${cell.rowKey}".`);
145
+ continue;
146
+ }
147
+ if (!columnKeys.has(cell.columnKey)) {
148
+ issues.push(`Cell references undeclared column "${cell.columnKey}".`);
149
+ continue;
150
+ }
151
+ const hasNode = cell.node !== undefined;
152
+ const hasReason = typeof cell.unavailableReason === 'string' && cell.unavailableReason.length > 0;
153
+ if (hasNode === hasReason) {
154
+ issues.push(`Cell for row "${cell.rowKey}" and column "${cell.columnKey}" must provide exactly one of node or unavailableReason.`);
155
+ }
156
+ }
157
+ for (const rowKey of rowKeys) {
158
+ for (const columnKey of columnKeys) {
159
+ if (!seen.has(cellKey(rowKey, columnKey))) {
160
+ issues.push(`Missing cell for row "${rowKey}" and column "${columnKey}".`);
161
+ }
162
+ }
163
+ }
164
+ return issues;
165
+ }
166
+ /** `states` minus items whose key is already a grid row or column. */
167
+ export function remainingStates(states, comparison) {
168
+ if (!states)
169
+ return undefined;
170
+ if (!comparison)
171
+ return states;
172
+ const covered = new Set([...axisItems(comparison.rows).map((row) => row.key), ...axisItems(comparison.columns).map((column) => column.key)]);
173
+ const items = states.items.filter((item) => !covered.has(item.key));
174
+ return items.length > 0 ? { ...states, items } : undefined;
175
+ }
176
+ /** Specimen size for a one-axis slot: the section's explicit size, else wide for full-width
177
+ * (itemsFill) slots, else regular. */
178
+ export function slotSize(def, slot) {
179
+ return def.specimenSize ?? (slot.itemsFill ? 'wide' : 'regular');
180
+ }
181
+ function slotItems(slot) {
182
+ return slot.items.map((item) => ({ key: item.key, label: item.name, node: item.node, fill: item.fill || slot.itemsFill }));
183
+ }
184
+ /** Preview widths, each capped at phone width. 'full' is kept for catalog chrome and token pages. */
185
+ function previewWidths(requested, fallback) {
186
+ const widths = requested ?? fallback ?? [PREVIEW_MAX_WIDTH];
187
+ return widths === 'full' ? 'full' : widths.map((w) => Math.min(w, PREVIEW_MAX_WIDTH));
188
+ }
189
+ /** Grouped rows when at least one state names a variant through `group`. Every variant gets a row:
190
+ * its grouped states, or the variant's own example when it has none. States without a matching
191
+ * group are returned as leftovers for "Other configurations". */
192
+ function groupStates(variants, states) {
193
+ const variantKeys = new Set(variants.items.map((v) => v.key));
194
+ if (!states.items.some((s) => s.group !== undefined && variantKeys.has(s.group)))
195
+ return undefined;
196
+ const fill = (item, slot) => item.fill || slot.itemsFill;
197
+ const groups = variants.items.map((variant) => {
198
+ const own = states.items.filter((s) => s.group === variant.key);
199
+ const items = own.length > 0
200
+ ? own.map((s) => ({ key: s.key, label: s.name, node: s.node, fill: fill(s, states) }))
201
+ : [{ key: variant.key, label: variant.name, node: variant.node, fill: fill(variant, variants) }];
202
+ return { key: variant.key, label: variant.name, items };
203
+ });
204
+ const rest = states.items.filter((s) => s.group === undefined || !variantKeys.has(s.group));
205
+ for (const s of rest) {
206
+ if (s.group !== undefined && globalThis.__DEV__) {
207
+ console.warn(`[Catalog] state "${s.key}" names group "${s.group}", which matches no variant key; it is shown under "Other configurations".`);
208
+ }
209
+ }
210
+ return { groups, leftovers: rest.length > 0 ? { ...states, items: rest } : undefined };
211
+ }
212
+ /** The visual blocks of one page, in reading order. Reference details are not included. A page
213
+ * never shows an empty block next to a real one; with nothing documented at all it shows one
214
+ * "No examples documented." block. */
215
+ export function presentationBlocks(def, options = {}) {
216
+ if (def.tokenGallery) {
217
+ const title = def.fullWidthLabel ?? 'Tokens';
218
+ return [def.render ? { kind: 'preview', title, widths: 'full' } : { kind: 'empty', title, message: 'Nothing to preview.' }];
219
+ }
220
+ const hide = def.hide ?? {};
221
+ const blocks = [];
222
+ let states = hide.states ? undefined : remainingStates(def.states, def.comparison);
223
+ if (!hide.variants) {
224
+ const grouped = !def.comparison && def.variants && states ? groupStates(def.variants, states) : undefined;
225
+ if (def.comparison) {
226
+ blocks.push({
227
+ kind: 'grid',
228
+ title: `${def.comparison.rowLabel} × ${def.comparison.columnLabel}`,
229
+ size: def.comparison.size ?? def.specimenSize ?? 'regular',
230
+ comparison: def.comparison,
231
+ });
232
+ }
233
+ else if (grouped && def.variants) {
234
+ // Grouped rows place several cells beside a row header, so full-width (itemsFill) slots do
235
+ // not force 402px cells here; a cell's own `fill` still stretches its specimen.
236
+ blocks.push({ kind: 'grouped', title: 'Variant × configuration', size: def.specimenSize ?? 'regular', groups: grouped.groups });
237
+ states = grouped.leftovers;
238
+ }
239
+ else if (def.variants) {
240
+ blocks.push({ kind: 'list', title: 'Variants', size: slotSize(def, def.variants), items: slotItems(def.variants) });
241
+ }
242
+ else if (def.render) {
243
+ blocks.push({ kind: 'preview', title: 'Preview', widths: previewWidths(def.previewWidths, options.defaultPreviewWidths) });
244
+ }
245
+ }
246
+ if (states) {
247
+ const secondary = blocks.length > 0 && blocks[0].kind !== 'list';
248
+ blocks.push({
249
+ kind: 'list',
250
+ title: secondary ? 'Other configurations' : 'States / configurations',
251
+ size: slotSize(def, states),
252
+ items: slotItems(states),
253
+ });
254
+ }
255
+ if (blocks.length === 0 && !hide.variants && !hide.states) {
256
+ blocks.push({ kind: 'empty', title: 'Examples', message: 'No examples documented.' });
257
+ }
258
+ return blocks;
259
+ }
260
+ /** Side by side or stacked, for a page with exactly two blocks. Tries both and keeps the shorter;
261
+ * stays stacked unless side by side saves at least PLACEMENT_MIN_SAVING. Only a list can move
262
+ * beside a first block that hugs its content, and only when its cells keep their minimum width. */
263
+ export function choosePlacement({ available, gap, first, second }) {
264
+ if (second.kind !== 'list' || !second.itemCount || !second.size)
265
+ return 'stacked';
266
+ const firstWidth = first.width ?? available;
267
+ if (firstWidth > available * 0.7)
268
+ return 'stacked';
269
+ const room = available - firstWidth - gap;
270
+ const minCell = second.size === 'wide' ? MATRIX_LAYOUT.columnMaxWidth : COLUMN_MIN_WIDTH[second.size];
271
+ if (room < minCell + 2)
272
+ return 'stacked';
273
+ const stackedRows = listGeometry(second.itemCount, available, second.size).rows;
274
+ const sideRows = listGeometry(second.itemCount, room, second.size).rows;
275
+ const rowHeight = second.height / Math.max(1, stackedRows);
276
+ const sideHeight = Math.max(first.height, sideRows * rowHeight);
277
+ const stackedHeight = first.height + gap + second.height;
278
+ return sideHeight <= stackedHeight - PLACEMENT_MIN_SAVING ? 'side' : 'stacked';
279
+ }
280
+ /** Props box columns: two, filled across first, for 4+ props when each column keeps its minimum. */
281
+ export function propsColumns(count, width) {
282
+ return count >= 4 && width >= 2 * PROPS_MIN_COLUMN_WIDTH + PROPS_COLUMN_GAP ? 2 : 1;
283
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Catalog-only design tokens — the visual system of the catalog interface itself.
3
+ *
4
+ * Deliberately independent of any host app's design-system tokens (DS_SEMANTIC / DS_PALETTE /
5
+ * DS_SPACING): the catalog documents a design system, it does not consume one. Keeping its chrome
6
+ * on its own tokens means a change to the host app's tokens never restyles the catalog, and this
7
+ * folder can be copied into another app's repo unchanged.
8
+ *
9
+ * Values match the approved Studio Matrix references
10
+ * (docs/design/2026-10-06-catalog-studio-matrix-*.html), with one deliberate exception:
11
+ * `textMuted` stays #666666 because the references' #777777 fails WCAG AA contrast.
12
+ */
13
+ export const CATALOG_TYPE = {
14
+ xs: 10,
15
+ tableHeader: 11,
16
+ sm: 12,
17
+ panelHeading: 13,
18
+ md: 14,
19
+ lg: 16,
20
+ brand: 17,
21
+ xl: 20,
22
+ '2xl': 24,
23
+ pageTitle: 28,
24
+ '3xl': 32,
25
+ '4xl': 40,
26
+ };
27
+ export const CATALOG_SPACE = {
28
+ xs: 4,
29
+ sm: 8,
30
+ md: 12,
31
+ lg: 16,
32
+ xl: 24,
33
+ '2xl': 32,
34
+ '3xl': 40,
35
+ };
36
+ export const CATALOG_RADIUS = {
37
+ sm: 8,
38
+ control: 9,
39
+ md: 12,
40
+ card: 14,
41
+ };
42
+ /** Exact chrome measurements from the approved references that are not spacing-scale steps. */
43
+ export const CATALOG_LAYOUT = {
44
+ sidebarWidth: 264,
45
+ sidebarPaddingTop: 24,
46
+ sidebarPaddingX: 18,
47
+ mainPaddingTop: 28,
48
+ mainPaddingX: 32,
49
+ controlSize: 44,
50
+ focusRingWidth: 3,
51
+ navItemPaddingY: 8,
52
+ navItemPaddingX: 10,
53
+ panelPadding: 20,
54
+ factPaddingY: 9,
55
+ blockLabelGap: 14,
56
+ blockGap: 28,
57
+ /** Sidebar logo header (design `docs/design/2026-10-08-ds-viewer-sidebar-logo-approved.html`,
58
+ * "C · Adaptive", approved 2026-10-08) — see `native/catalog/logoLayout.ts`. */
59
+ logoMark: 32,
60
+ logoWordmarkHeight: 28,
61
+ logoCaptionGap: 6,
62
+ /** Max width of the update page's content column (approved mockup: direction "C · Update
63
+ * page", content at most 512px) — independent of `CATALOG_MAX_CONTENT_WIDTH` (1200px), which
64
+ * is every other page's column width. */
65
+ updateContentMaxWidth: 512,
66
+ };
67
+ /** Max width of the main content column. */
68
+ export const CATALOG_MAX_CONTENT_WIDTH = 1200;
69
+ /** When to reach for each catalog-chrome type size. Rendered in the framework catalog's Type
70
+ * Scale page. */
71
+ export const CATALOG_TYPE_USE = {
72
+ xs: 'Sidebar group labels (uppercase); a prop\'s type annotation.',
73
+ tableHeader: 'Grid column headers and list cell captions (uppercase).',
74
+ sm: 'Breadcrumb, catalog caption, block labels, prop names and descriptions.',
75
+ panelHeading: 'Reference-panel headings: Guidance, Quick reference, Props (uppercase).',
76
+ md: 'Default body text: descriptions, nav links, grid row headers, quick-reference rows, the filter field.',
77
+ lg: 'Pager arrows and the filter field\'s clear (×) glyph.',
78
+ brand: 'The app name at the top of the sidebar.',
79
+ xl: 'Reserved — no current consumer.',
80
+ '2xl': 'Reserved — no current consumer.',
81
+ pageTitle: 'The selected page\'s title.',
82
+ '3xl': 'Reserved — no current consumer.',
83
+ '4xl': 'Reserved — no current consumer.',
84
+ };
85
+ /** When to reach for each catalog-chrome spacing step. Rendered in the framework catalog's
86
+ * Spacing page. */
87
+ export const CATALOG_SPACE_USE = {
88
+ xs: 'Tight gap — e.g. between a token\'s rendered value and its use-note.',
89
+ sm: 'Small gap — below the filter field; between a preview frame\'s label and its demo.',
90
+ md: 'Medium gap — between a card\'s contents; token-row divider padding.',
91
+ lg: 'Grid and list cell padding (16px); row gap in scale galleries.',
92
+ xl: 'Preview-card padding; gap between preview frames.',
93
+ '2xl': 'Gap between the reference panel\'s Guidance and Quick reference columns.',
94
+ '3xl': 'Bottom padding of the main column.',
95
+ };
96
+ export const CATALOG_COLOR = {
97
+ text: '#181818',
98
+ // #666666, not the references' #777777: #777 is 4.14–4.48:1 on this file's surfaces (WCAG AA
99
+ // needs 4.5:1); #666 is 5.3–5.7:1.
100
+ textMuted: '#666666',
101
+ /** Dividers inside grids, lists, props tables, token rows. */
102
+ border: '#e4e4e4',
103
+ /** Sidebar edge, reference card, filter field. */
104
+ borderHairline: '#dddddd',
105
+ /** Grid, list, and preview cards; pager buttons. */
106
+ borderStrong: '#d7d7d7',
107
+ /** Quick-reference row dividers. */
108
+ borderSubtle: '#eeeeee',
109
+ surface: '#ffffff',
110
+ /** Table headers, row headers, cell captions, filter field. */
111
+ surfaceMuted: '#fafafa',
112
+ /** Hover and pressed feedback on nav rows and buttons. */
113
+ surfacePressed: '#f1f3f8',
114
+ pageBackground: '#f6f6f4',
115
+ chip: '#eeeeee',
116
+ /** Active nav label, prop types, scale bars. */
117
+ accent: '#174dc6',
118
+ /** Active nav row background. */
119
+ accentSubtle: '#e9efff',
120
+ /** 3px keyboard focus ring on every catalog control. */
121
+ focusRing: '#c9d7ff',
122
+ code: 'Menlo',
123
+ /** Major-update banner background/border/text (design §5 "Viewer notice"). */
124
+ warning: '#8a4b00',
125
+ warningSubtle: '#fff4e0',
126
+ warningBorder: '#f0cf97',
127
+ /** "Can't prepare"/failure note-boxes on the update page. */
128
+ danger: '#b3261e',
129
+ dangerSubtle: '#fdecea',
130
+ dangerBorder: '#f2b8b5',
131
+ /** The update page's post-update success note-box and "Updated" pill. */
132
+ success: '#1e6b3a',
133
+ successSubtle: '#e8f5ec',
134
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,16 @@
1
1
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import { AccessibilityInfo, Platform, ScrollView, StyleSheet, Text, View, findNodeHandle } from 'react-native';
2
+ import { AccessibilityInfo, Platform, Pressable, ScrollView, StyleSheet, Text, View, findNodeHandle } from 'react-native';
3
3
  import type { ImageSourcePropType } from 'react-native';
4
- import { CATALOG_COLOR, CATALOG_LAYOUT, CATALOG_MAX_CONTENT_WIDTH, CATALOG_SPACE, CATALOG_TYPE } from './tokens';
4
+ import { CATALOG_COLOR, CATALOG_LAYOUT, CATALOG_MAX_CONTENT_WIDTH, CATALOG_RADIUS, CATALOG_SPACE, CATALOG_TYPE } from './tokens';
5
5
  import { CatalogSidebar } from './CatalogSidebar';
6
6
  import { SectionBlock } from './SectionBlock';
7
- import { groupLabelFor, hashForId, idFromHash, neighbors, orderedIds } from './catalogNavigation';
8
- import type { NavGroup, PreviewWidths, SectionDef } from './types';
7
+ import { UpdatePanel } from './UpdatePanel';
8
+ import { groupLabelFor, hashForId, neighbors, orderedIds, resolveActiveFromHash, shouldShowMajorBanner, footerLabel, UPDATE_PAGE_ID } from './catalogNavigation';
9
+ import type { NavGroup, PreviewWidths, SectionDef, UpdateNotice } from './types';
10
+
11
+ /** `active` can be a real page id, or the reserved update-page id — never both a generic `TId`
12
+ * constraint and a hardcoded string literal type at once, which is why this is its own alias. */
13
+ type ShellPageId<TId extends string> = TId | typeof UPDATE_PAGE_ID;
9
14
 
10
15
  function isWeb(): boolean {
11
16
  return Platform.OS === 'web' && typeof window !== 'undefined';
@@ -36,6 +41,62 @@ function resetMainScroll(scrollView: ScrollView | null): void {
36
41
  scrollView.scrollTo({ y: 0, animated: false });
37
42
  }
38
43
 
44
+ /** The approved mockup's exact copy shape: `"⚠ DS Viewer <version> is available — includes
45
+ * breaking changes · Migration guide · Review update"`, dismissible with an `×` labeled "Dismiss
46
+ * for <version>". The release's own GitHub page stands in for a dedicated migration-guide URL,
47
+ * which this plan's design text does not otherwise name.
48
+ *
49
+ * Important finding, Fable correction pass: both links now carry a real `href` — `role="link"`
50
+ * with only `onPress` (as `CatalogSidebar.tsx`'s own finding already documents) never activates on
51
+ * Enter under react-native-web unless the element is a genuine anchor. `role="status"` (not
52
+ * `"alert"`, the mockup's own choice) — a non-urgent notice should not interrupt assistive tech. */
53
+ function MajorBanner({ update, onReviewUpdate, onDismiss }: { update: UpdateNotice; onReviewUpdate: () => void; onDismiss: () => void }) {
54
+ const releaseUrl = `https://github.com/krapwoo/design-system-viewer/releases/tag/v${update.latest}`;
55
+ return (
56
+ <View style={bannerStyles.banner} role="status">
57
+ <Text style={bannerStyles.text}>
58
+ {'⚠ '}
59
+ <Text style={bannerStyles.bold}>{`DS Viewer ${update.latest} is available`}</Text>
60
+ {' — includes breaking changes · '}
61
+ <Text
62
+ role="link"
63
+ style={bannerStyles.link}
64
+ {...({ href: releaseUrl, hrefAttrs: { target: '_blank', rel: 'noopener noreferrer' } } as Record<string, unknown>)}
65
+ >
66
+ Migration guide
67
+ </Text>
68
+ {' · '}
69
+ <Text role="link" style={bannerStyles.link} onPress={onReviewUpdate} {...({ href: hashForId(UPDATE_PAGE_ID) } as Record<string, unknown>)}>
70
+ Review update
71
+ </Text>
72
+ </Text>
73
+ <Pressable onPress={onDismiss} accessibilityRole="button" accessibilityLabel={`Dismiss for ${update.latest}`} style={bannerStyles.close}>
74
+ <Text style={bannerStyles.closeGlyph}>×</Text>
75
+ </Pressable>
76
+ </View>
77
+ );
78
+ }
79
+
80
+ const bannerStyles = StyleSheet.create({
81
+ banner: {
82
+ flexDirection: 'row',
83
+ alignItems: 'center',
84
+ gap: CATALOG_SPACE.md,
85
+ backgroundColor: CATALOG_COLOR.warningSubtle,
86
+ borderWidth: 1,
87
+ borderColor: CATALOG_COLOR.warningBorder,
88
+ borderRadius: CATALOG_RADIUS.md,
89
+ paddingVertical: 10,
90
+ paddingHorizontal: 14,
91
+ marginBottom: 18,
92
+ },
93
+ text: { flex: 1, fontSize: CATALOG_TYPE.md, color: CATALOG_COLOR.warning },
94
+ bold: { fontWeight: '700' },
95
+ link: { color: CATALOG_COLOR.warning, fontWeight: '700', textDecorationLine: 'underline' },
96
+ close: { width: 32, height: 32, borderRadius: CATALOG_RADIUS.sm, alignItems: 'center', justifyContent: 'center' },
97
+ closeGlyph: { fontSize: 18, color: CATALOG_COLOR.warning },
98
+ });
99
+
39
100
  /**
40
101
  * The whole catalog: a persistent, searchable sidebar plus ONE selected page. Selecting a page
41
102
  * replaces the main content (no long scrolling document, no scroll-spy). On web the page lives in
@@ -49,6 +110,8 @@ export function CatalogShell<TId extends string>({
49
110
  groups,
50
111
  sections,
51
112
  defaultPreviewWidths,
113
+ update,
114
+ updateEndpoint,
52
115
  }: {
53
116
  /** Short product/app name — the sidebar logo and the breadcrumb root. */
54
117
  appName: string;
@@ -62,11 +125,20 @@ export function CatalogShell<TId extends string>({
62
125
  /** Preview widths for component pages without their own `previewWidths`. Default: `[402]`
63
126
  * (phone width). Pass 'full' for a catalog whose previews are not phone components. */
64
127
  defaultPreviewWidths?: PreviewWidths;
128
+ /** Design §5's update notice — `null`/`undefined` when no update is known (disabled, offline,
129
+ * or already up to date; the viewer treats all three identically: no footer, no banner, no
130
+ * update page content). */
131
+ update?: UpdateNotice | null;
132
+ /** The local endpoint's base URL and per-run secret — `dev` generates both (Task 18) and
133
+ * `writeWorkspace`'s generated entry file bakes them in (Task 17). Absent in a build that
134
+ * disables the endpoint entirely — `UpdatePanel` degrades to showing the plan/notice with no
135
+ * **Update now** button when this is missing. */
136
+ updateEndpoint?: { baseUrl: string; secret: string };
65
137
  }) {
66
138
  const sectionsById = useMemo(() => new Map(sections.map((def) => [def.id, def])), [sections]);
67
139
  const order = useMemo(() => orderedIds(groups, new Set(sectionsById.keys())), [groups, sectionsById]);
68
- const [active, setActive] = useState<TId | undefined>(() =>
69
- isWeb() ? idFromHash(window.location.hash, order) : order[0],
140
+ const [active, setActive] = useState<ShellPageId<TId> | undefined>(() =>
141
+ isWeb() ? resolveActiveFromHash(window.location.hash, order) : order[0],
70
142
  );
71
143
 
72
144
  const scrollRef = useRef<ScrollView>(null);
@@ -76,7 +148,7 @@ export function CatalogShell<TId extends string>({
76
148
  const pushHistoryNext = useRef(false);
77
149
  const focusHeadingNext = useRef(false);
78
150
 
79
- const select = useCallback((id: TId) => {
151
+ const select = useCallback((id: ShellPageId<TId>) => {
80
152
  if (id === activeRef.current) {
81
153
  focusElement(headingRef.current);
82
154
  return;
@@ -90,7 +162,7 @@ export function CatalogShell<TId extends string>({
90
162
  useEffect(() => {
91
163
  if (!isWeb()) return;
92
164
  const onHashChange = () => {
93
- const id = idFromHash(window.location.hash, order);
165
+ const id = resolveActiveFromHash(window.location.hash, order);
94
166
  if (id === undefined) return;
95
167
  if (id !== activeRef.current) {
96
168
  focusHeadingNext.current = true;
@@ -123,18 +195,40 @@ export function CatalogShell<TId extends string>({
123
195
  if (focus) focusElement(headingRef.current);
124
196
  }, [active]);
125
197
 
126
- const activeDef = active !== undefined ? sectionsById.get(active) : undefined;
198
+ const activeDef = active !== undefined && active !== UPDATE_PAGE_ID ? sectionsById.get(active) : undefined;
199
+
200
+ const [dismissedMajor, setDismissedMajor] = useState<string | null>(() =>
201
+ isWeb() ? window.localStorage.getItem('ds-viewer-dismissed-major') : null,
202
+ );
203
+ const dismissMajorBanner = useCallback(() => {
204
+ if (!update) return;
205
+ if (isWeb()) window.localStorage.setItem('ds-viewer-dismissed-major', update.latest);
206
+ setDismissedMajor(update.latest);
207
+ }, [update]);
208
+ const footer = footerLabel(update)
209
+ ? { label: footerLabel(update)!, active: active === UPDATE_PAGE_ID, onPress: () => select(UPDATE_PAGE_ID) }
210
+ : undefined;
211
+ // Design: the banner shows on every *normal* page; once you're already looking at the update
212
+ // page there is nothing left for "Review update" to do, so it's hidden there (confirmed against
213
+ // the approved mockup's own `frame()`: the banner only ever renders when `!isPanel`).
214
+ const showBanner = active !== UPDATE_PAGE_ID && shouldShowMajorBanner(update, dismissedMajor);
127
215
 
128
216
  return (
129
217
  <View style={styles.root}>
130
- <CatalogSidebar logo={appName} logoImageSource={logoImageSource} caption={title} groups={groups} active={active} onPress={select} />
218
+ <CatalogSidebar logo={appName} logoImageSource={logoImageSource} caption={title} groups={groups} active={active} onPress={select} footer={footer} />
131
219
  <ScrollView ref={scrollRef} style={styles.main} contentContainerStyle={styles.mainContent}>
132
- {activeDef ? (
220
+ {active === UPDATE_PAGE_ID ? (
221
+ <UpdatePanel update={update ?? null} endpoint={updateEndpoint} appName={appName} headingRef={headingRef} />
222
+ ) : activeDef ? (
133
223
  <SectionBlock
134
224
  key={activeDef.id}
135
225
  def={activeDef}
136
226
  groupLabel={groupLabelFor(groups, activeDef.id)}
137
227
  breadcrumbRoot={appName}
228
+ // The approved mockup's own `PAGE_BG` order: crumb, then banner, then title — the
229
+ // banner used to render above the breadcrumb instead (Important finding, Fable
230
+ // correction pass).
231
+ banner={showBanner && update ? <MajorBanner update={update} onReviewUpdate={() => select(UPDATE_PAGE_ID)} onDismiss={dismissMajorBanner} /> : undefined}
138
232
  pager={{
139
233
  previousId: neighbors(order, activeDef.id).previous,
140
234
  nextId: neighbors(order, activeDef.id).next,