@krapwoo/ds-viewer 0.9.1 → 0.11.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/README.md +82 -0
- package/dist/cli/doctor.js +182 -3
- package/dist/cli/staticPage.js +129 -0
- package/dist/native/catalog/catalogNavigation.js +62 -3
- package/dist/native/catalog/comparison.js +14 -3
- package/dist/native/catalog/pageApi.js +408 -0
- package/dist/native/catalog/tokens.js +67 -12
- package/native/catalog/BoundedOverlayViewport.tsx +2 -2
- package/native/catalog/CatalogButton.tsx +2 -2
- package/native/catalog/CatalogSearchInput.tsx +3 -3
- package/native/catalog/CatalogShell.tsx +213 -32
- package/native/catalog/CatalogSidebar.tsx +69 -19
- package/native/catalog/ComparisonGrid.tsx +4 -4
- package/native/catalog/ComparisonGroups.tsx +3 -3
- package/native/catalog/ComparisonList.tsx +2 -2
- package/native/catalog/FamilyPage.tsx +1188 -0
- package/native/catalog/MotionSpecimen.tsx +3 -3
- package/native/catalog/PhoneFrame.tsx +2 -2
- package/native/catalog/PropsTable.tsx +7 -7
- package/native/catalog/ReferenceDetails.tsx +33 -22
- package/native/catalog/SectionBlock.tsx +57 -27
- package/native/catalog/SpacingScaleGallery.tsx +3 -3
- package/native/catalog/Swatch.tsx +3 -3
- package/native/catalog/TokenLayouts.tsx +6 -9
- package/native/catalog/TokenRow.tsx +2 -2
- package/native/catalog/TypeScaleGallery.tsx +2 -2
- package/native/catalog/UpdatePanel.tsx +29 -30
- package/native/catalog/VariantGroup.tsx +3 -6
- package/native/catalog/catalogNavigation.ts +89 -3
- package/native/catalog/comparison.ts +17 -6
- package/native/catalog/familyModel.ts +192 -0
- package/native/catalog/index.ts +8 -2
- package/native/catalog/overlayViewport.ts +30 -10
- package/native/catalog/pageApi.ts +357 -15
- package/native/catalog/tokens.ts +70 -12
- package/native/catalog/types.ts +106 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
import type { ComparisonDef, ComposedOfEntry, NavGroup, PreviewWidths, PropDef, SectionDef, SpecimenSize, SpecimenSurfaceKind, TokenSection, VariantSlot } from './types';
|
|
2
|
+
import type { CatalogAnatomy, CatalogMember, CatalogMemberSection, ComparisonDef, ComposedOfEntry, NavGroup, PreviewWidths, PropDef, SectionDef, SpecimenSize, SpecimenSurfaceKind, TokenSection, VariantSlot } from './types.ts';
|
|
3
3
|
|
|
4
4
|
/** `SectionDef` without the derived fields (`id`/`path`/`props` come from detection and
|
|
5
5
|
* generated props), plus the three fields design §1 "Page shape" adds. */
|
|
@@ -46,6 +46,35 @@ export interface CatalogPageInput<TId extends string = string> {
|
|
|
46
46
|
/** Extra text per prop, appended to its generated description. A note naming a prop that no
|
|
47
47
|
* longer exists is a `doctor` error from 0.3 — 0.1 has no `doctor`, so it is silently unused. */
|
|
48
48
|
propNotes?: Record<string, string>;
|
|
49
|
+
/** Spec §5.1: documents a family of related declarations on one page instead of a single
|
|
50
|
+
* component. When set, the page's own `component`/`whenToUse`/`a11y`/specimens are not used —
|
|
51
|
+
* those live on the members (the whole is a member too) — and the viewer renders a `FamilyPage`
|
|
52
|
+
* (`SectionDef.family`) rather than the normal single-component layout. Requires `whole` and
|
|
53
|
+
* `sections`; validated by this file's own `validateFamily`. */
|
|
54
|
+
members?: CatalogMember[];
|
|
55
|
+
/** The family's whole: a member id, required when `members` is set. Its own id must equal this
|
|
56
|
+
* page's `id`. */
|
|
57
|
+
whole?: string;
|
|
58
|
+
/** How the family's non-whole members are grouped and rendered, required when `members` is set.
|
|
59
|
+
* Ordering only — numbering follows each member's own `parent` (`numberFor`); a Related member
|
|
60
|
+
* (outside every `inWhole` section) is never numbered. */
|
|
61
|
+
sections?: CatalogMemberSection[];
|
|
62
|
+
/** Extra names for the page itself (its whole) — e.g. retired page ids that are not member ids.
|
|
63
|
+
* Included in uniqueness validation, routing and search alongside `members[].aliases`. V2c item
|
|
64
|
+
* 15: only takes effect on a page with `members` (a family page) — accepted but unused on a
|
|
65
|
+
* normal page, which never resolves it to anywhere. */
|
|
66
|
+
aliases?: string[];
|
|
67
|
+
/** Family-level "Not shown in the browser" line, under the page head. V2c item 15: only takes
|
|
68
|
+
* effect on a page with `members` — unused on a normal page. */
|
|
69
|
+
notShown?: string;
|
|
70
|
+
/** Label for the disclosure's API part (spec V2b item 9), e.g. `'Swift API'`. Defaults to
|
|
71
|
+
* `'API'` when absent — a generic viewer must never hardcode a host app's own wording. V2c
|
|
72
|
+
* item 15: only takes effect on a page with `members` — unused on a normal page. */
|
|
73
|
+
apiLabel?: string;
|
|
74
|
+
/** Slice D1 item 1: the anatomy box `FamilyPage` renders first, right after the page head —
|
|
75
|
+
* a picture of the whole with numbered pins and a legend. Only takes effect on a page with
|
|
76
|
+
* `members`. */
|
|
77
|
+
anatomy?: CatalogAnatomy;
|
|
49
78
|
}
|
|
50
79
|
|
|
51
80
|
export interface CatalogPage<TId extends string = string> extends CatalogPageInput<TId> {
|
|
@@ -95,17 +124,237 @@ function mergePropNotes(component: GeneratedComponent, propNotes: Record<string,
|
|
|
95
124
|
return [...own, ...inherited];
|
|
96
125
|
}
|
|
97
126
|
|
|
98
|
-
/** Human-readable problems with a page's
|
|
99
|
-
* whose `component` isn't in `knownNames` (every real
|
|
100
|
-
* every page id — the full catalog
|
|
101
|
-
*
|
|
102
|
-
|
|
127
|
+
/** Human-readable problems with a page's (or, V2d, a family member's own) `composedOf`, in
|
|
128
|
+
* declaration order: one line per entry whose `component` isn't in `knownNames` (every real
|
|
129
|
+
* component name, documented or not, plus every page id and family member id — the full catalog
|
|
130
|
+
* inventory `buildCatalogSections` already has on hand). Empty when every name resolves,
|
|
131
|
+
* including when `composedOf` itself is omitted. Takes only the `component` field (never the
|
|
132
|
+
* narrower `ComposedOfEntry[]` type) so `cli/doctor.ts`'s own statically-read `{ component:
|
|
133
|
+
* string }[]` shape — which never carries `role`/`relationship` — satisfies it too. */
|
|
134
|
+
export function validateComposedOf(composedOf: { component: string }[] | undefined, knownNames: ReadonlySet<string>): string[] {
|
|
103
135
|
if (!composedOf) return [];
|
|
104
136
|
return composedOf
|
|
105
137
|
.filter((entry) => !knownNames.has(entry.component))
|
|
106
138
|
.map((entry) => `composedOf references unknown component "${entry.component}".`);
|
|
107
139
|
}
|
|
108
140
|
|
|
141
|
+
/** The subset of a family page's shape `validateFamily` and `numberFor` need. The real page
|
|
142
|
+
* carries full `CatalogMember` records; these functions only ever read `id`/`parent`/`aliases`. */
|
|
143
|
+
export interface FamilyOutlineInput {
|
|
144
|
+
whole?: string;
|
|
145
|
+
sections?: CatalogMemberSection[];
|
|
146
|
+
members?: Array<Pick<CatalogMember, 'id' | 'parent'>>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface FamilyPageLike extends FamilyOutlineInput {
|
|
150
|
+
id: string;
|
|
151
|
+
/** N6: `hasSpecimens` is not a `CatalogMember` field — each caller computes it (a non-empty
|
|
152
|
+
* `variants`/`states`/`comparison` at runtime, `StaticMember.hasExamples` in `doctor`) so
|
|
153
|
+
* `validateFamily` can flag a `list`-section member authored with a specimen that `FoldedRow`
|
|
154
|
+
* never renders. */
|
|
155
|
+
members?: Array<Pick<CatalogMember, 'id' | 'parent' | 'aliases'> & { hasSpecimens?: boolean }>;
|
|
156
|
+
aliases?: string[];
|
|
157
|
+
/** Slice D1 item 3: the minimal shape `validateFamily` needs from `CatalogPageInput.anatomy` —
|
|
158
|
+
* decoupled from the full `CatalogAnatomy` type (which carries a `picture` React node this pure
|
|
159
|
+
* module never touches). */
|
|
160
|
+
anatomy?: FamilyAnatomyLike;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Slice D1 item 3. */
|
|
164
|
+
export interface FamilyAnatomyLike {
|
|
165
|
+
groups: ReadonlyArray<{ label: string; items: ReadonlyArray<{ member: string } | { other: string }> }>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Validates a family page (spec §5.1): exactly one whole belonging to no section; every other
|
|
169
|
+
* member in exactly one section; every parent resolving within the page with no cycles; member
|
|
170
|
+
* and alias ids unique catalog-wide and never colliding with a page id, except the whole (whose
|
|
171
|
+
* id equals its own page's id). Returns `[]` for a page without `members`. `allPageIds` and
|
|
172
|
+
* `otherMemberIds` are the ids used by every *other* page/member in the catalog. */
|
|
173
|
+
export function validateFamily(page: FamilyPageLike, allPageIds: ReadonlySet<string>, otherMemberIds: ReadonlySet<string>): string[] {
|
|
174
|
+
const { members } = page;
|
|
175
|
+
if (!members || members.length === 0) return [];
|
|
176
|
+
const issues: string[] = [];
|
|
177
|
+
|
|
178
|
+
if (!page.whole || !page.sections) {
|
|
179
|
+
issues.push(`Family "${page.id}": "members" requires both "whole" and "sections".`);
|
|
180
|
+
return issues;
|
|
181
|
+
}
|
|
182
|
+
const whole = page.whole;
|
|
183
|
+
const byId = new Map(members.map((m) => [m.id, m]));
|
|
184
|
+
|
|
185
|
+
if (!byId.has(whole)) {
|
|
186
|
+
issues.push(`Family "${page.id}": whole "${whole}" is not one of its members.`);
|
|
187
|
+
}
|
|
188
|
+
if (whole !== page.id) {
|
|
189
|
+
issues.push(`Family "${page.id}": whole "${whole}" must have the same id as the page.`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// V2c item 2: a section listing an id that is not one of the page's own members — reported
|
|
193
|
+
// here, rather than left to crash the renderer or silently occupy authored order in `numberFor`.
|
|
194
|
+
// N6: a `list`-section member authored with a specimen — `FoldedRow` never renders one, so this
|
|
195
|
+
// degrades to a silently dropped specimen rather than a crash, same as the unknown-id case.
|
|
196
|
+
for (const section of page.sections) {
|
|
197
|
+
for (const id of section.members) {
|
|
198
|
+
const resolved = byId.get(id);
|
|
199
|
+
if (!resolved) {
|
|
200
|
+
issues.push(`Family "${page.id}": section "${section.label}" lists "${id}", which is not a member of this page.`);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (section.kind === 'list' && resolved.hasSpecimens) {
|
|
204
|
+
issues.push(`Family "${page.id}": "${id}" has specimens, but list sections show members as folded rows without specimens.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const sectionCountById = new Map<string, number>();
|
|
210
|
+
for (const section of page.sections) {
|
|
211
|
+
for (const id of section.members) sectionCountById.set(id, (sectionCountById.get(id) ?? 0) + 1);
|
|
212
|
+
}
|
|
213
|
+
if (sectionCountById.has(whole)) {
|
|
214
|
+
issues.push(`Family "${page.id}": the whole "${whole}" must not appear in any section.`);
|
|
215
|
+
}
|
|
216
|
+
for (const m of members) {
|
|
217
|
+
if (m.id === whole) continue;
|
|
218
|
+
const count = sectionCountById.get(m.id) ?? 0;
|
|
219
|
+
if (count === 0) issues.push(`Family "${page.id}": member "${m.id}" is not in any section.`);
|
|
220
|
+
else if (count > 1) issues.push(`Family "${page.id}": member "${m.id}" is in more than one section.`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
for (const m of members) {
|
|
224
|
+
if (m.parent === undefined) continue;
|
|
225
|
+
if (!byId.has(m.parent)) {
|
|
226
|
+
issues.push(`Family "${page.id}": member "${m.id}" has an unknown parent "${m.parent}".`);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const seen = new Set([m.id]);
|
|
230
|
+
let current: string | undefined = m.parent;
|
|
231
|
+
let cycle = false;
|
|
232
|
+
while (current !== undefined) {
|
|
233
|
+
if (seen.has(current)) {
|
|
234
|
+
cycle = true;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
seen.add(current);
|
|
238
|
+
current = byId.get(current)?.parent;
|
|
239
|
+
}
|
|
240
|
+
if (cycle) issues.push(`Family "${page.id}": member "${m.id}" has a parent cycle.`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const seenInPage = new Set<string>();
|
|
244
|
+
const checkId = (id: string, isWhole: boolean) => {
|
|
245
|
+
if (seenInPage.has(id)) issues.push(`Family "${page.id}": id "${id}" is used more than once on this page.`);
|
|
246
|
+
seenInPage.add(id);
|
|
247
|
+
if (isWhole) return;
|
|
248
|
+
if (allPageIds.has(id)) issues.push(`Family "${page.id}": id "${id}" collides with another page's id.`);
|
|
249
|
+
if (otherMemberIds.has(id)) issues.push(`Family "${page.id}": id "${id}" collides with another member or alias elsewhere in the catalog.`);
|
|
250
|
+
};
|
|
251
|
+
for (const m of members) {
|
|
252
|
+
checkId(m.id, m.id === whole);
|
|
253
|
+
for (const alias of m.aliases ?? []) checkId(alias, false);
|
|
254
|
+
}
|
|
255
|
+
for (const alias of page.aliases ?? []) checkId(alias, false);
|
|
256
|
+
|
|
257
|
+
// Slice D1 item 3: an anatomy `member` item must name a real, non-whole member of this page, and
|
|
258
|
+
// each member may be pinned to the picture's legend at most once.
|
|
259
|
+
// D2 item A2: a member item whose member has no number — outside every `inWhole` section, or
|
|
260
|
+
// under a parent that isn't itself numbered — must also be reported; left unchecked, it renders
|
|
261
|
+
// a blank 34px pin slot in the legend and nothing at all from `AnatomyPin` in the picture.
|
|
262
|
+
if (page.anatomy) {
|
|
263
|
+
const numbered = numberFor(page);
|
|
264
|
+
const seenAnatomyMembers = new Set<string>();
|
|
265
|
+
for (const group of page.anatomy.groups) {
|
|
266
|
+
for (const item of group.items) {
|
|
267
|
+
if (!('member' in item)) continue;
|
|
268
|
+
if (item.member === whole) {
|
|
269
|
+
issues.push(`Family "${page.id}": anatomy item "${item.member}" names the whole.`);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (!byId.has(item.member)) {
|
|
273
|
+
issues.push(`Family "${page.id}": anatomy item "${item.member}" is not a member of this page.`);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (seenAnatomyMembers.has(item.member)) {
|
|
277
|
+
issues.push(`Family "${page.id}": anatomy lists member "${item.member}" more than once.`);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
seenAnatomyMembers.add(item.member);
|
|
281
|
+
if (!numbered.has(item.member)) {
|
|
282
|
+
issues.push(`Family "${page.id}": anatomy item "${item.member}" has no number.`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return issues;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Slice D1 item 2: anatomy-first numbering — the only numbering rule for every family page (not
|
|
292
|
+
* only one with `anatomy` set; it superseded the earlier whole-and-letters rule outright). The
|
|
293
|
+
* whole gets no number. A **top-level part** is any member of an `inWhole` section whose `parent`
|
|
294
|
+
* is the whole, or who has no `parent` at all (an in-whole root with no Swift parent edge is still
|
|
295
|
+
* top-level) — numbered `1`, `2`, `3`… in authored order (the order a member first appears
|
|
296
|
+
* scanning `inWhole` sections, in section order). A child takes its parent's number plus `.1`,
|
|
297
|
+
* `.2`, … in authored order. Members outside any `inWhole` section (Related) get no number at
|
|
298
|
+
* all. Returns an empty map for a page without members. */
|
|
299
|
+
export function numberFor(page: FamilyOutlineInput): Map<string, { number: string; level: number }> {
|
|
300
|
+
const outline = new Map<string, { number: string; level: number }>();
|
|
301
|
+
const { whole, sections, members } = page;
|
|
302
|
+
if (!whole || !sections || !members) return outline;
|
|
303
|
+
|
|
304
|
+
const memberIds = new Set(members.map((m) => m.id));
|
|
305
|
+
// Only `inWhole` sections contribute to numbering — a Related section's members are never
|
|
306
|
+
// top-level parts, and never occupy authored order (so they can't be skipped-over roots either).
|
|
307
|
+
const authoredOrder: string[] = [];
|
|
308
|
+
const seen = new Set<string>();
|
|
309
|
+
for (const section of sections) {
|
|
310
|
+
if (!section.inWhole) continue;
|
|
311
|
+
for (const id of section.members) {
|
|
312
|
+
if (!seen.has(id) && memberIds.has(id)) {
|
|
313
|
+
seen.add(id);
|
|
314
|
+
authoredOrder.push(id);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const parentOf = new Map(members.map((m) => [m.id, m.parent]));
|
|
320
|
+
const childrenOf = new Map<string, string[]>();
|
|
321
|
+
for (const id of authoredOrder) {
|
|
322
|
+
const parent = parentOf.get(id);
|
|
323
|
+
if (parent === undefined) continue;
|
|
324
|
+
childrenOf.set(parent, [...(childrenOf.get(parent) ?? []), id]);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// V2c item 14's cycle guard: bad data already reported by `validateFamily` must degrade to a
|
|
328
|
+
// partial outline, never an infinite recursion.
|
|
329
|
+
const assignChildren = (parentId: string, parentNumber: string, level: number, visited: Set<string>) => {
|
|
330
|
+
const kids = childrenOf.get(parentId) ?? [];
|
|
331
|
+
kids.forEach((childId, index) => {
|
|
332
|
+
if (visited.has(childId)) return;
|
|
333
|
+
visited.add(childId);
|
|
334
|
+
const number = `${parentNumber}.${index + 1}`;
|
|
335
|
+
outline.set(childId, { number, level: level + 1 });
|
|
336
|
+
assignChildren(childId, number, level + 1, visited);
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const visited = new Set<string>([whole]);
|
|
341
|
+
const topLevel = authoredOrder.filter((id) => {
|
|
342
|
+
const parent = parentOf.get(id);
|
|
343
|
+
return parent === undefined || parent === whole;
|
|
344
|
+
});
|
|
345
|
+
let next = 0;
|
|
346
|
+
for (const id of topLevel) {
|
|
347
|
+
if (visited.has(id)) continue;
|
|
348
|
+
visited.add(id);
|
|
349
|
+
next += 1;
|
|
350
|
+
const number = String(next);
|
|
351
|
+
outline.set(id, { number, level: 2 });
|
|
352
|
+
assignChildren(id, number, 2, visited);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return outline;
|
|
356
|
+
}
|
|
357
|
+
|
|
109
358
|
function orderGroups<TId extends string>(groupIds: Map<string, TId[]>, groupOrder: string[] | undefined): NavGroup<TId>[] {
|
|
110
359
|
const listed = groupOrder ?? [];
|
|
111
360
|
const labels = [...groupIds.keys()];
|
|
@@ -128,13 +377,47 @@ export function buildCatalogSections<TId extends string>(
|
|
|
128
377
|
groupOrder?: string[],
|
|
129
378
|
): { sections: SectionDef<TId>[]; groups: NavGroup<TId>[] } {
|
|
130
379
|
const componentByName = new Map(components.map((c) => [c.name, c]));
|
|
131
|
-
|
|
380
|
+
// A page with `members` documents every member's own `component` instead of `page.component ??
|
|
381
|
+
// page.id` — that fallback never applies to a family page (spec §5.1).
|
|
382
|
+
const documented = new Set<string>();
|
|
383
|
+
for (const page of pages) {
|
|
384
|
+
if (page.members && page.members.length > 0) {
|
|
385
|
+
for (const member of page.members) if (member.component) documented.add(member.component);
|
|
386
|
+
} else {
|
|
387
|
+
documented.add(page.component ?? page.id);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
132
390
|
const groupIds = new Map<string, TId[]>();
|
|
133
391
|
const addToGroup = (group: string, id: TId) => groupIds.set(group, [...(groupIds.get(group) ?? []), id]);
|
|
134
|
-
// Every name a page's `composedOf` could legitimately point
|
|
135
|
-
// or not — an undocumented one is still a real part of the
|
|
136
|
-
// (token pages, standalone recipes, …)
|
|
137
|
-
|
|
392
|
+
// Every name a page's (or, V2d, a family member's own) `composedOf` could legitimately point
|
|
393
|
+
// at: every real component (documented or not — an undocumented one is still a real part of the
|
|
394
|
+
// design system), every page id (token pages, standalone recipes, …), every family member id
|
|
395
|
+
// (a member's composedOf may point at a sibling member, or a member of another family), and —
|
|
396
|
+
// N8 — every member alias and page-level alias: `FamilyPage`'s own `resolvesAddress` already
|
|
397
|
+
// treats these as working links (`aliasTargets`), so this warning must accept the same names.
|
|
398
|
+
const knownComposedOfNames = new Set<string>([
|
|
399
|
+
...componentByName.keys(),
|
|
400
|
+
...pages.map((page) => page.id),
|
|
401
|
+
...pages.flatMap((page) => (page.members ?? []).map((member) => member.id)),
|
|
402
|
+
...pages.flatMap((page) => (page.members ?? []).flatMap((member) => member.aliases ?? [])),
|
|
403
|
+
...pages.flatMap((page) => page.aliases ?? []),
|
|
404
|
+
]);
|
|
405
|
+
|
|
406
|
+
// Every id/alias a family page's own `members` and `aliases` use, keyed by page id — gathered up
|
|
407
|
+
// front so `validateFamily` (above) can check catalog-wide uniqueness against every *other*
|
|
408
|
+
// page's ids.
|
|
409
|
+
const allPageIds = new Set(pages.map((page) => page.id));
|
|
410
|
+
const familyIdsByPage = new Map<TId, Set<string>>();
|
|
411
|
+
for (const page of pages) {
|
|
412
|
+
if (!page.members) continue;
|
|
413
|
+
const ids = new Set<string>();
|
|
414
|
+
for (const member of page.members) {
|
|
415
|
+
ids.add(member.id);
|
|
416
|
+
for (const alias of member.aliases ?? []) ids.add(alias);
|
|
417
|
+
}
|
|
418
|
+
for (const alias of page.aliases ?? []) ids.add(alias);
|
|
419
|
+
familyIdsByPage.set(page.id, ids);
|
|
420
|
+
}
|
|
138
421
|
|
|
139
422
|
// Design §4 "duplicate-page-id" rule's viewer-side equivalent — this is the one place in the
|
|
140
423
|
// whole viewer that already resolves every page's id to build sections/groups, so it costs
|
|
@@ -142,14 +425,63 @@ export function buildCatalogSections<TId extends string>(
|
|
|
142
425
|
// `CatalogShell.tsx` would otherwise just let the last one silently win).
|
|
143
426
|
const seenIds = new Set<TId>();
|
|
144
427
|
const sections: SectionDef<TId>[] = pages.map((page) => {
|
|
428
|
+
// N2: `seenIds` must be populated (and consulted, below in the undocumented-component loop)
|
|
429
|
+
// regardless of `__DEV__` — only the `console.warn` calls are development-only diagnostics;
|
|
430
|
+
// a production bundle (Metro's `__DEV__ = false`) still needs the stub-skip to work.
|
|
431
|
+
if (seenIds.has(page.id)) {
|
|
432
|
+
if ((globalThis as { __DEV__?: boolean }).__DEV__) {
|
|
433
|
+
console.warn(`[Catalog] Page id "${page.id}" is used by more than one page; only the last one will show. Give one of them its own "id".`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
seenIds.add(page.id);
|
|
145
437
|
if ((globalThis as { __DEV__?: boolean }).__DEV__) {
|
|
146
|
-
if (seenIds.has(page.id)) console.warn(`[Catalog] Page id "${page.id}" is used by more than one page; only the last one will show. Give one of them its own "id".`);
|
|
147
|
-
seenIds.add(page.id);
|
|
148
438
|
for (const issue of validateComposedOf(page.composedOf, knownComposedOfNames)) console.warn(`[Catalog] ${page.id}: ${issue}`);
|
|
439
|
+
// V2d item 4: the same validation, per family member's own `composedOf`.
|
|
440
|
+
for (const member of page.members ?? []) {
|
|
441
|
+
for (const issue of validateComposedOf(member.composedOf, knownComposedOfNames)) {
|
|
442
|
+
console.warn(`[Catalog] ${page.id}.${member.id}: ${issue}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
149
445
|
}
|
|
150
|
-
const
|
|
151
|
-
const
|
|
446
|
+
const isFamily = page.members !== undefined && page.members.length > 0;
|
|
447
|
+
const componentName = isFamily ? undefined : (page.component ?? page.id);
|
|
448
|
+
const component = componentName ? componentByName.get(componentName) : undefined;
|
|
152
449
|
addToGroup(page.group, page.id);
|
|
450
|
+
|
|
451
|
+
let family: SectionDef<TId>['family'];
|
|
452
|
+
if (isFamily) {
|
|
453
|
+
const otherPageIds = new Set([...allPageIds].filter((id) => id !== page.id));
|
|
454
|
+
const otherMemberIds = new Set<string>();
|
|
455
|
+
for (const [id, ids] of familyIdsByPage) if (id !== page.id) for (const memberId of ids) otherMemberIds.add(memberId);
|
|
456
|
+
// `hasSpecimens` is computed here, as doctor does, so the list-section rule also fires in
|
|
457
|
+
// the development console, not only in `ds-viewer doctor`.
|
|
458
|
+
const members = page.members!.map((member) => ({
|
|
459
|
+
...member,
|
|
460
|
+
hasSpecimens: Boolean(member.variants?.items?.length || member.states?.items?.length || member.comparison),
|
|
461
|
+
}));
|
|
462
|
+
const issues = validateFamily({ ...page, members, anatomy: page.anatomy }, otherPageIds, otherMemberIds);
|
|
463
|
+
if ((globalThis as { __DEV__?: boolean }).__DEV__) {
|
|
464
|
+
for (const issue of issues) console.error(`[Catalog] ${issue}`);
|
|
465
|
+
}
|
|
466
|
+
family = {
|
|
467
|
+
whole: page.whole!,
|
|
468
|
+
sections: page.sections!,
|
|
469
|
+
outline: numberFor(page),
|
|
470
|
+
notShown: page.notShown,
|
|
471
|
+
aliases: page.aliases,
|
|
472
|
+
apiLabel: page.apiLabel,
|
|
473
|
+
anatomy: page.anatomy,
|
|
474
|
+
members: page.members!.map((member) => {
|
|
475
|
+
const memberComponent = member.component ? componentByName.get(member.component) : undefined;
|
|
476
|
+
return {
|
|
477
|
+
...member,
|
|
478
|
+
props: memberComponent ? mergePropNotes(memberComponent, undefined) : undefined,
|
|
479
|
+
path: memberComponent?.file ?? member.source,
|
|
480
|
+
};
|
|
481
|
+
}),
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
153
485
|
// Important finding 4: a standalone page (no matching component record) has no props to show
|
|
154
486
|
// and nothing to say "This component takes no props" about — hide the Props box, and fall back
|
|
155
487
|
// to the page's own file as its Source instead of an empty path.
|
|
@@ -179,12 +511,22 @@ export function buildCatalogSections<TId extends string>(
|
|
|
179
511
|
composedOf: page.composedOf,
|
|
180
512
|
internalProps: page.internalProps,
|
|
181
513
|
intentionalStaticPreview: page.intentionalStaticPreview,
|
|
514
|
+
family,
|
|
182
515
|
};
|
|
183
516
|
});
|
|
184
517
|
|
|
185
518
|
const undocumented = components.filter((component) => !documented.has(component.name)).sort((a, b) => a.name.localeCompare(b.name));
|
|
186
519
|
for (const component of undocumented) {
|
|
187
520
|
const id = component.name as TId;
|
|
521
|
+
// V2c item 7: a component with no page of its own, whose name happens to collide with an
|
|
522
|
+
// authored page's own id (most likely a family page, which never resolves `documented` via the
|
|
523
|
+
// `page.component ?? page.id` fallback) — its stub must never win that id in `sections`.
|
|
524
|
+
if (seenIds.has(id)) {
|
|
525
|
+
if ((globalThis as { __DEV__?: boolean }).__DEV__) {
|
|
526
|
+
console.warn(`[Catalog] Component "${id}" has no catalog page of its own, and "${id}" is already used by another page's id; skipping its stub.`);
|
|
527
|
+
}
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
188
530
|
sections.push({ id, description: 'No examples documented.', path: component.file, props: mergePropNotes(component, undefined) });
|
|
189
531
|
addToGroup('Components', id);
|
|
190
532
|
}
|
package/native/catalog/tokens.ts
CHANGED
|
@@ -28,6 +28,32 @@ export const CATALOG_TYPE = {
|
|
|
28
28
|
'4xl': 40,
|
|
29
29
|
} as const;
|
|
30
30
|
|
|
31
|
+
export const CATALOG_FONT = { code: 'Menlo, monospace' } as const;
|
|
32
|
+
|
|
33
|
+
/** The catalog's fixed set of typography roles, each a complete `fontSize`/`fontWeight`/
|
|
34
|
+
* `lineHeight` (plus `letterSpacing`/`textTransform`/`fontFamily` where the role needs them)
|
|
35
|
+
* built on `CATALOG_TYPE`. Every catalog-chrome text style spreads one of these rather than
|
|
36
|
+
* setting its own typography properties directly (enforced by
|
|
37
|
+
* `__tests__/textRoles.test.ts`). */
|
|
38
|
+
export const CATALOG_TEXT = {
|
|
39
|
+
pageTitle: { fontSize: CATALOG_TYPE.pageTitle, fontWeight: '700', lineHeight: 34 },
|
|
40
|
+
heading1: { fontSize: CATALOG_TYPE['2xl'], fontWeight: '700', lineHeight: 30 },
|
|
41
|
+
heading2: { fontSize: CATALOG_TYPE.xl, fontWeight: '700', lineHeight: 24 },
|
|
42
|
+
heading3: { fontSize: CATALOG_TYPE.lg, fontWeight: '700', lineHeight: 22 },
|
|
43
|
+
icon: { fontSize: CATALOG_TYPE.lg, fontWeight: '400', lineHeight: 22 },
|
|
44
|
+
body: { fontSize: CATALOG_TYPE.md, fontWeight: '400', lineHeight: 20 },
|
|
45
|
+
bodyStrong: { fontSize: CATALOG_TYPE.md, fontWeight: '700', lineHeight: 20 },
|
|
46
|
+
caption: { fontSize: CATALOG_TYPE.sm, fontWeight: '400', lineHeight: 18 },
|
|
47
|
+
captionStrong: { fontSize: CATALOG_TYPE.sm, fontWeight: '700', lineHeight: 18 },
|
|
48
|
+
label: { fontSize: CATALOG_TYPE.sm, fontWeight: '700', lineHeight: 18, letterSpacing: 0.72, textTransform: 'uppercase' },
|
|
49
|
+
micro: { fontSize: CATALOG_TYPE.xs, fontWeight: '400', lineHeight: 14 },
|
|
50
|
+
microLabel: { fontSize: CATALOG_TYPE.xs, fontWeight: '700', lineHeight: 14, letterSpacing: 0.6, textTransform: 'uppercase' },
|
|
51
|
+
code: { fontSize: CATALOG_TYPE.md, fontWeight: '400', lineHeight: 20, fontFamily: CATALOG_FONT.code },
|
|
52
|
+
codeSmall: { fontSize: CATALOG_TYPE.sm, fontWeight: '400', lineHeight: 18, fontFamily: CATALOG_FONT.code },
|
|
53
|
+
codeSmallStrong: { fontSize: CATALOG_TYPE.sm, fontWeight: '700', lineHeight: 18, fontFamily: CATALOG_FONT.code },
|
|
54
|
+
codeMicro: { fontSize: CATALOG_TYPE.xs, fontWeight: '400', lineHeight: 14, fontFamily: CATALOG_FONT.code },
|
|
55
|
+
} as const;
|
|
56
|
+
|
|
31
57
|
export const CATALOG_SPACE = {
|
|
32
58
|
xs: 4,
|
|
33
59
|
sm: 8,
|
|
@@ -75,22 +101,44 @@ export const CATALOG_LAYOUT = {
|
|
|
75
101
|
export const CATALOG_MAX_CONTENT_WIDTH = 1200;
|
|
76
102
|
|
|
77
103
|
/** When to reach for each catalog-chrome type size. Rendered in the framework catalog's Type
|
|
78
|
-
* Scale page.
|
|
104
|
+
* Scale page. Every size is now consumed through a `CATALOG_TEXT` role (see `CATALOG_TEXT_USE`)
|
|
105
|
+
* rather than directly. */
|
|
79
106
|
export const CATALOG_TYPE_USE: Record<keyof typeof CATALOG_TYPE, string> = {
|
|
80
|
-
xs: '
|
|
81
|
-
tableHeader: '
|
|
82
|
-
sm: '
|
|
83
|
-
panelHeading: '
|
|
84
|
-
md: '
|
|
85
|
-
lg: '
|
|
86
|
-
brand: '
|
|
87
|
-
xl:
|
|
88
|
-
'2xl':
|
|
89
|
-
pageTitle: '
|
|
107
|
+
xs: 'Backs the `micro`, `microLabel` and `codeMicro` roles: token values and meta captions; sidebar group labels and OS badges (uppercase); a prop\'s type and default value (monospace).',
|
|
108
|
+
tableHeader: 'Reserved — no current consumer; grid column headers and list cell captions now use the `captionStrong` role (built on `sm`).',
|
|
109
|
+
sm: 'Backs the `caption`, `captionStrong`, `label`, `codeSmall` and `codeSmallStrong` roles: breadcrumbs, block/prop descriptions, swatch/token names, table captions, monospace prop names and file paths.',
|
|
110
|
+
panelHeading: 'Reserved — no current consumer; reference-panel and update-page headings now use the `label` role (built on `sm`).',
|
|
111
|
+
md: 'Backs the `body`, `bodyStrong` and `code` roles: descriptions, nav links, the filter field, switch labels, a long unbroken value that needs to wrap at its \'/\'s (monospace).',
|
|
112
|
+
lg: 'Backs the `heading3` and `icon` roles: a result note\'s title; pager arrows and the filter field\'s clear (×) glyph.',
|
|
113
|
+
brand: 'Reserved — no current consumer; the sidebar app name now uses the `heading2` role (built on `xl`).',
|
|
114
|
+
xl: 'Backs the `heading2` role: the app name at the top of the sidebar.',
|
|
115
|
+
'2xl': 'Backs the `heading1` role: the update page\'s version numbers and the arrow between them.',
|
|
116
|
+
pageTitle: 'Backs the `pageTitle` role: the selected page\'s title, including the update page\'s own title.',
|
|
90
117
|
'3xl': 'Reserved — no current consumer.',
|
|
91
118
|
'4xl': 'Reserved — no current consumer.',
|
|
92
119
|
};
|
|
93
120
|
|
|
121
|
+
/** When to reach for each catalog-chrome typography role. Rendered in the framework catalog's
|
|
122
|
+
* Type Scale page. */
|
|
123
|
+
export const CATALOG_TEXT_USE: Record<keyof typeof CATALOG_TEXT, string> = {
|
|
124
|
+
pageTitle: 'The selected page\'s title, including the update page\'s own title.',
|
|
125
|
+
heading1: 'The update page\'s version numbers and the arrow between them.',
|
|
126
|
+
heading2: 'The app name at the top of the sidebar.',
|
|
127
|
+
heading3: 'A result note\'s title (the update page\'s success/failure banner).',
|
|
128
|
+
icon: 'Glyph-only controls: pager arrows, the filter field\'s clear (×) glyph, the update banner\'s close (×) glyph.',
|
|
129
|
+
body: 'Default body text: descriptions, nav links, the filter field, update-page facts/notes/steps.',
|
|
130
|
+
bodyStrong: 'Emphasised body text: grid/list row headers, switch and step labels, inline-bold notice text.',
|
|
131
|
+
caption: 'Secondary text: breadcrumbs, status captions, block/prop descriptions, sidebar subtitle/footer, update-page captions.',
|
|
132
|
+
captionStrong: 'Emphasised secondary text: grid column headers, grid/list/table captions, reference-panel subheadings, swatch/token names, replay and result links, step-icon glyphs.',
|
|
133
|
+
label: 'Uppercase labels and headings: block and preview-frame labels, token-section labels, reference-panel and update-page headings.',
|
|
134
|
+
micro: 'The smallest text: token values and meta captions, a prop\'s default-value label.',
|
|
135
|
+
microLabel: 'Uppercase micro labels: variant-group names, sidebar group labels, OS badges.',
|
|
136
|
+
code: 'Monospace body text: a long unbroken value that needs to wrap at its \'/\'s.',
|
|
137
|
+
codeSmall: 'Monospace secondary text: a prop\'s optional marker, the update page\'s inline code, file paths and log lines.',
|
|
138
|
+
codeSmallStrong: 'Emphasised monospace secondary text: a prop\'s own name.',
|
|
139
|
+
codeMicro: 'Monospace micro text: a prop\'s type and default value.',
|
|
140
|
+
};
|
|
141
|
+
|
|
94
142
|
/** When to reach for each catalog-chrome spacing step. Rendered in the framework catalog's
|
|
95
143
|
* Spacing page. */
|
|
96
144
|
export const CATALOG_SPACE_USE: Record<keyof typeof CATALOG_SPACE, string> = {
|
|
@@ -135,7 +183,17 @@ export const CATALOG_COLOR = {
|
|
|
135
183
|
accentSubtle: '#e9efff',
|
|
136
184
|
/** 3px keyboard focus ring on every catalog control. */
|
|
137
185
|
focusRing: '#c9d7ff',
|
|
138
|
-
|
|
186
|
+
/** Family-page Part tree connector line (Slice D1/D2) — the approved reference's own line color
|
|
187
|
+
* has no match among the other tokens above. */
|
|
188
|
+
treeLine: '#a9bdf0',
|
|
189
|
+
/** Family-page API code block: a dark surface and its text, the one place the catalog shows a
|
|
190
|
+
* member's raw API signature. Dark on purpose so it reads as code, not as catalog chrome. */
|
|
191
|
+
codeSurface: '#1d1d1f',
|
|
192
|
+
codeOnSurface: '#e8e8e8',
|
|
193
|
+
/** @deprecated kept for the public API; re-points at `CATALOG_FONT.code` so there is one source
|
|
194
|
+
* of truth. New code should reach for `CATALOG_FONT.code` (or a `CATALOG_TEXT` `code*` role)
|
|
195
|
+
* instead. */
|
|
196
|
+
code: CATALOG_FONT.code,
|
|
139
197
|
/** Major-update banner background/border/text (design §5 "Viewer notice"). */
|
|
140
198
|
warning: '#8a4b00',
|
|
141
199
|
warningSubtle: '#fff4e0',
|