@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
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
export function defineCatalogPage(page) {
|
|
2
|
+
return { ...page, __dsViewerPage: true };
|
|
3
|
+
}
|
|
4
|
+
function mergePropNotes(component, propNotes) {
|
|
5
|
+
const own = component.props.map((prop) => ({
|
|
6
|
+
name: prop.name,
|
|
7
|
+
type: prop.type,
|
|
8
|
+
required: prop.required,
|
|
9
|
+
default: prop.default,
|
|
10
|
+
desc: propNotes?.[prop.name] ? `${prop.desc} ${propNotes[prop.name]}`.trim() : prop.desc,
|
|
11
|
+
}));
|
|
12
|
+
// Design §3: props inherited from node_modules (e.g. `extends TextInputProps`) are summarised as
|
|
13
|
+
// one row per source instead of being listed individually.
|
|
14
|
+
const inherited = component.inheritedFrom.map((source) => ({
|
|
15
|
+
name: `${source} props`,
|
|
16
|
+
type: 'inherited',
|
|
17
|
+
required: true,
|
|
18
|
+
desc: `Plus all ${source} props, not listed individually.`,
|
|
19
|
+
}));
|
|
20
|
+
return [...own, ...inherited];
|
|
21
|
+
}
|
|
22
|
+
/** Human-readable problems with a page's (or, V2d, a family member's own) `composedOf`, in
|
|
23
|
+
* declaration order: one line per entry whose `component` isn't in `knownNames` (every real
|
|
24
|
+
* component name, documented or not, plus every page id and family member id — the full catalog
|
|
25
|
+
* inventory `buildCatalogSections` already has on hand). Empty when every name resolves,
|
|
26
|
+
* including when `composedOf` itself is omitted. Takes only the `component` field (never the
|
|
27
|
+
* narrower `ComposedOfEntry[]` type) so `cli/doctor.ts`'s own statically-read `{ component:
|
|
28
|
+
* string }[]` shape — which never carries `role`/`relationship` — satisfies it too. */
|
|
29
|
+
export function validateComposedOf(composedOf, knownNames) {
|
|
30
|
+
if (!composedOf)
|
|
31
|
+
return [];
|
|
32
|
+
return composedOf
|
|
33
|
+
.filter((entry) => !knownNames.has(entry.component))
|
|
34
|
+
.map((entry) => `composedOf references unknown component "${entry.component}".`);
|
|
35
|
+
}
|
|
36
|
+
/** Validates a family page (spec §5.1): exactly one whole belonging to no section; every other
|
|
37
|
+
* member in exactly one section; every parent resolving within the page with no cycles; member
|
|
38
|
+
* and alias ids unique catalog-wide and never colliding with a page id, except the whole (whose
|
|
39
|
+
* id equals its own page's id). Returns `[]` for a page without `members`. `allPageIds` and
|
|
40
|
+
* `otherMemberIds` are the ids used by every *other* page/member in the catalog. */
|
|
41
|
+
export function validateFamily(page, allPageIds, otherMemberIds) {
|
|
42
|
+
const { members } = page;
|
|
43
|
+
if (!members || members.length === 0)
|
|
44
|
+
return [];
|
|
45
|
+
const issues = [];
|
|
46
|
+
if (!page.whole || !page.sections) {
|
|
47
|
+
issues.push(`Family "${page.id}": "members" requires both "whole" and "sections".`);
|
|
48
|
+
return issues;
|
|
49
|
+
}
|
|
50
|
+
const whole = page.whole;
|
|
51
|
+
const byId = new Map(members.map((m) => [m.id, m]));
|
|
52
|
+
if (!byId.has(whole)) {
|
|
53
|
+
issues.push(`Family "${page.id}": whole "${whole}" is not one of its members.`);
|
|
54
|
+
}
|
|
55
|
+
if (whole !== page.id) {
|
|
56
|
+
issues.push(`Family "${page.id}": whole "${whole}" must have the same id as the page.`);
|
|
57
|
+
}
|
|
58
|
+
// V2c item 2: a section listing an id that is not one of the page's own members — reported
|
|
59
|
+
// here, rather than left to crash the renderer or silently occupy authored order in `numberFor`.
|
|
60
|
+
// N6: a `list`-section member authored with a specimen — `FoldedRow` never renders one, so this
|
|
61
|
+
// degrades to a silently dropped specimen rather than a crash, same as the unknown-id case.
|
|
62
|
+
for (const section of page.sections) {
|
|
63
|
+
for (const id of section.members) {
|
|
64
|
+
const resolved = byId.get(id);
|
|
65
|
+
if (!resolved) {
|
|
66
|
+
issues.push(`Family "${page.id}": section "${section.label}" lists "${id}", which is not a member of this page.`);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (section.kind === 'list' && resolved.hasSpecimens) {
|
|
70
|
+
issues.push(`Family "${page.id}": "${id}" has specimens, but list sections show members as folded rows without specimens.`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const sectionCountById = new Map();
|
|
75
|
+
for (const section of page.sections) {
|
|
76
|
+
for (const id of section.members)
|
|
77
|
+
sectionCountById.set(id, (sectionCountById.get(id) ?? 0) + 1);
|
|
78
|
+
}
|
|
79
|
+
if (sectionCountById.has(whole)) {
|
|
80
|
+
issues.push(`Family "${page.id}": the whole "${whole}" must not appear in any section.`);
|
|
81
|
+
}
|
|
82
|
+
for (const m of members) {
|
|
83
|
+
if (m.id === whole)
|
|
84
|
+
continue;
|
|
85
|
+
const count = sectionCountById.get(m.id) ?? 0;
|
|
86
|
+
if (count === 0)
|
|
87
|
+
issues.push(`Family "${page.id}": member "${m.id}" is not in any section.`);
|
|
88
|
+
else if (count > 1)
|
|
89
|
+
issues.push(`Family "${page.id}": member "${m.id}" is in more than one section.`);
|
|
90
|
+
}
|
|
91
|
+
for (const m of members) {
|
|
92
|
+
if (m.parent === undefined)
|
|
93
|
+
continue;
|
|
94
|
+
if (!byId.has(m.parent)) {
|
|
95
|
+
issues.push(`Family "${page.id}": member "${m.id}" has an unknown parent "${m.parent}".`);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const seen = new Set([m.id]);
|
|
99
|
+
let current = m.parent;
|
|
100
|
+
let cycle = false;
|
|
101
|
+
while (current !== undefined) {
|
|
102
|
+
if (seen.has(current)) {
|
|
103
|
+
cycle = true;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
seen.add(current);
|
|
107
|
+
current = byId.get(current)?.parent;
|
|
108
|
+
}
|
|
109
|
+
if (cycle)
|
|
110
|
+
issues.push(`Family "${page.id}": member "${m.id}" has a parent cycle.`);
|
|
111
|
+
}
|
|
112
|
+
const seenInPage = new Set();
|
|
113
|
+
const checkId = (id, isWhole) => {
|
|
114
|
+
if (seenInPage.has(id))
|
|
115
|
+
issues.push(`Family "${page.id}": id "${id}" is used more than once on this page.`);
|
|
116
|
+
seenInPage.add(id);
|
|
117
|
+
if (isWhole)
|
|
118
|
+
return;
|
|
119
|
+
if (allPageIds.has(id))
|
|
120
|
+
issues.push(`Family "${page.id}": id "${id}" collides with another page's id.`);
|
|
121
|
+
if (otherMemberIds.has(id))
|
|
122
|
+
issues.push(`Family "${page.id}": id "${id}" collides with another member or alias elsewhere in the catalog.`);
|
|
123
|
+
};
|
|
124
|
+
for (const m of members) {
|
|
125
|
+
checkId(m.id, m.id === whole);
|
|
126
|
+
for (const alias of m.aliases ?? [])
|
|
127
|
+
checkId(alias, false);
|
|
128
|
+
}
|
|
129
|
+
for (const alias of page.aliases ?? [])
|
|
130
|
+
checkId(alias, false);
|
|
131
|
+
// Slice D1 item 3: an anatomy `member` item must name a real, non-whole member of this page, and
|
|
132
|
+
// each member may be pinned to the picture's legend at most once.
|
|
133
|
+
// D2 item A2: a member item whose member has no number — outside every `inWhole` section, or
|
|
134
|
+
// under a parent that isn't itself numbered — must also be reported; left unchecked, it renders
|
|
135
|
+
// a blank 34px pin slot in the legend and nothing at all from `AnatomyPin` in the picture.
|
|
136
|
+
if (page.anatomy) {
|
|
137
|
+
const numbered = numberFor(page);
|
|
138
|
+
const seenAnatomyMembers = new Set();
|
|
139
|
+
for (const group of page.anatomy.groups) {
|
|
140
|
+
for (const item of group.items) {
|
|
141
|
+
if (!('member' in item))
|
|
142
|
+
continue;
|
|
143
|
+
if (item.member === whole) {
|
|
144
|
+
issues.push(`Family "${page.id}": anatomy item "${item.member}" names the whole.`);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (!byId.has(item.member)) {
|
|
148
|
+
issues.push(`Family "${page.id}": anatomy item "${item.member}" is not a member of this page.`);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (seenAnatomyMembers.has(item.member)) {
|
|
152
|
+
issues.push(`Family "${page.id}": anatomy lists member "${item.member}" more than once.`);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
seenAnatomyMembers.add(item.member);
|
|
156
|
+
if (!numbered.has(item.member)) {
|
|
157
|
+
issues.push(`Family "${page.id}": anatomy item "${item.member}" has no number.`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return issues;
|
|
163
|
+
}
|
|
164
|
+
/** Slice D1 item 2: anatomy-first numbering — the only numbering rule for every family page (not
|
|
165
|
+
* only one with `anatomy` set; it superseded the earlier whole-and-letters rule outright). The
|
|
166
|
+
* whole gets no number. A **top-level part** is any member of an `inWhole` section whose `parent`
|
|
167
|
+
* is the whole, or who has no `parent` at all (an in-whole root with no Swift parent edge is still
|
|
168
|
+
* top-level) — numbered `1`, `2`, `3`… in authored order (the order a member first appears
|
|
169
|
+
* scanning `inWhole` sections, in section order). A child takes its parent's number plus `.1`,
|
|
170
|
+
* `.2`, … in authored order. Members outside any `inWhole` section (Related) get no number at
|
|
171
|
+
* all. Returns an empty map for a page without members. */
|
|
172
|
+
export function numberFor(page) {
|
|
173
|
+
const outline = new Map();
|
|
174
|
+
const { whole, sections, members } = page;
|
|
175
|
+
if (!whole || !sections || !members)
|
|
176
|
+
return outline;
|
|
177
|
+
const memberIds = new Set(members.map((m) => m.id));
|
|
178
|
+
// Only `inWhole` sections contribute to numbering — a Related section's members are never
|
|
179
|
+
// top-level parts, and never occupy authored order (so they can't be skipped-over roots either).
|
|
180
|
+
const authoredOrder = [];
|
|
181
|
+
const seen = new Set();
|
|
182
|
+
for (const section of sections) {
|
|
183
|
+
if (!section.inWhole)
|
|
184
|
+
continue;
|
|
185
|
+
for (const id of section.members) {
|
|
186
|
+
if (!seen.has(id) && memberIds.has(id)) {
|
|
187
|
+
seen.add(id);
|
|
188
|
+
authoredOrder.push(id);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const parentOf = new Map(members.map((m) => [m.id, m.parent]));
|
|
193
|
+
const childrenOf = new Map();
|
|
194
|
+
for (const id of authoredOrder) {
|
|
195
|
+
const parent = parentOf.get(id);
|
|
196
|
+
if (parent === undefined)
|
|
197
|
+
continue;
|
|
198
|
+
childrenOf.set(parent, [...(childrenOf.get(parent) ?? []), id]);
|
|
199
|
+
}
|
|
200
|
+
// V2c item 14's cycle guard: bad data already reported by `validateFamily` must degrade to a
|
|
201
|
+
// partial outline, never an infinite recursion.
|
|
202
|
+
const assignChildren = (parentId, parentNumber, level, visited) => {
|
|
203
|
+
const kids = childrenOf.get(parentId) ?? [];
|
|
204
|
+
kids.forEach((childId, index) => {
|
|
205
|
+
if (visited.has(childId))
|
|
206
|
+
return;
|
|
207
|
+
visited.add(childId);
|
|
208
|
+
const number = `${parentNumber}.${index + 1}`;
|
|
209
|
+
outline.set(childId, { number, level: level + 1 });
|
|
210
|
+
assignChildren(childId, number, level + 1, visited);
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
const visited = new Set([whole]);
|
|
214
|
+
const topLevel = authoredOrder.filter((id) => {
|
|
215
|
+
const parent = parentOf.get(id);
|
|
216
|
+
return parent === undefined || parent === whole;
|
|
217
|
+
});
|
|
218
|
+
let next = 0;
|
|
219
|
+
for (const id of topLevel) {
|
|
220
|
+
if (visited.has(id))
|
|
221
|
+
continue;
|
|
222
|
+
visited.add(id);
|
|
223
|
+
next += 1;
|
|
224
|
+
const number = String(next);
|
|
225
|
+
outline.set(id, { number, level: 2 });
|
|
226
|
+
assignChildren(id, number, 2, visited);
|
|
227
|
+
}
|
|
228
|
+
return outline;
|
|
229
|
+
}
|
|
230
|
+
function orderGroups(groupIds, groupOrder) {
|
|
231
|
+
const listed = groupOrder ?? [];
|
|
232
|
+
const labels = [...groupIds.keys()];
|
|
233
|
+
const ordered = [...listed.filter((label) => groupIds.has(label)), ...labels.filter((label) => !listed.includes(label)).sort()];
|
|
234
|
+
return ordered.map((label) => ({ label, ids: groupIds.get(label) ?? [] }));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Builds the viewer's `sections`/`groups` from authored pages plus generated component data — the
|
|
238
|
+
* logic the generated entry file (Task 12) runs on every bundle. A documented component's page
|
|
239
|
+
* supplies everything page-authored; its props always come from `components` (never authored by
|
|
240
|
+
* hand). A component with no page still appears, with "No examples documented." (design §2).
|
|
241
|
+
*/
|
|
242
|
+
export function buildCatalogSections(
|
|
243
|
+
// The generated page index (Task 9) always fills in `id` (`id ?? component ?? file stem`) and
|
|
244
|
+
// `file` (the page's own project-relative path), so pages arriving here have both even though
|
|
245
|
+
// authors may omit them.
|
|
246
|
+
pages, components, groupOrder) {
|
|
247
|
+
const componentByName = new Map(components.map((c) => [c.name, c]));
|
|
248
|
+
// A page with `members` documents every member's own `component` instead of `page.component ??
|
|
249
|
+
// page.id` — that fallback never applies to a family page (spec §5.1).
|
|
250
|
+
const documented = new Set();
|
|
251
|
+
for (const page of pages) {
|
|
252
|
+
if (page.members && page.members.length > 0) {
|
|
253
|
+
for (const member of page.members)
|
|
254
|
+
if (member.component)
|
|
255
|
+
documented.add(member.component);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
documented.add(page.component ?? page.id);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const groupIds = new Map();
|
|
262
|
+
const addToGroup = (group, id) => groupIds.set(group, [...(groupIds.get(group) ?? []), id]);
|
|
263
|
+
// Every name a page's (or, V2d, a family member's own) `composedOf` could legitimately point
|
|
264
|
+
// at: every real component (documented or not — an undocumented one is still a real part of the
|
|
265
|
+
// design system), every page id (token pages, standalone recipes, …), every family member id
|
|
266
|
+
// (a member's composedOf may point at a sibling member, or a member of another family), and —
|
|
267
|
+
// N8 — every member alias and page-level alias: `FamilyPage`'s own `resolvesAddress` already
|
|
268
|
+
// treats these as working links (`aliasTargets`), so this warning must accept the same names.
|
|
269
|
+
const knownComposedOfNames = new Set([
|
|
270
|
+
...componentByName.keys(),
|
|
271
|
+
...pages.map((page) => page.id),
|
|
272
|
+
...pages.flatMap((page) => (page.members ?? []).map((member) => member.id)),
|
|
273
|
+
...pages.flatMap((page) => (page.members ?? []).flatMap((member) => member.aliases ?? [])),
|
|
274
|
+
...pages.flatMap((page) => page.aliases ?? []),
|
|
275
|
+
]);
|
|
276
|
+
// Every id/alias a family page's own `members` and `aliases` use, keyed by page id — gathered up
|
|
277
|
+
// front so `validateFamily` (above) can check catalog-wide uniqueness against every *other*
|
|
278
|
+
// page's ids.
|
|
279
|
+
const allPageIds = new Set(pages.map((page) => page.id));
|
|
280
|
+
const familyIdsByPage = new Map();
|
|
281
|
+
for (const page of pages) {
|
|
282
|
+
if (!page.members)
|
|
283
|
+
continue;
|
|
284
|
+
const ids = new Set();
|
|
285
|
+
for (const member of page.members) {
|
|
286
|
+
ids.add(member.id);
|
|
287
|
+
for (const alias of member.aliases ?? [])
|
|
288
|
+
ids.add(alias);
|
|
289
|
+
}
|
|
290
|
+
for (const alias of page.aliases ?? [])
|
|
291
|
+
ids.add(alias);
|
|
292
|
+
familyIdsByPage.set(page.id, ids);
|
|
293
|
+
}
|
|
294
|
+
// Design §4 "duplicate-page-id" rule's viewer-side equivalent — this is the one place in the
|
|
295
|
+
// whole viewer that already resolves every page's id to build sections/groups, so it costs
|
|
296
|
+
// nothing extra to also notice two pages claiming the same one (`sectionsById` in
|
|
297
|
+
// `CatalogShell.tsx` would otherwise just let the last one silently win).
|
|
298
|
+
const seenIds = new Set();
|
|
299
|
+
const sections = pages.map((page) => {
|
|
300
|
+
// N2: `seenIds` must be populated (and consulted, below in the undocumented-component loop)
|
|
301
|
+
// regardless of `__DEV__` — only the `console.warn` calls are development-only diagnostics;
|
|
302
|
+
// a production bundle (Metro's `__DEV__ = false`) still needs the stub-skip to work.
|
|
303
|
+
if (seenIds.has(page.id)) {
|
|
304
|
+
if (globalThis.__DEV__) {
|
|
305
|
+
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".`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
seenIds.add(page.id);
|
|
309
|
+
if (globalThis.__DEV__) {
|
|
310
|
+
for (const issue of validateComposedOf(page.composedOf, knownComposedOfNames))
|
|
311
|
+
console.warn(`[Catalog] ${page.id}: ${issue}`);
|
|
312
|
+
// V2d item 4: the same validation, per family member's own `composedOf`.
|
|
313
|
+
for (const member of page.members ?? []) {
|
|
314
|
+
for (const issue of validateComposedOf(member.composedOf, knownComposedOfNames)) {
|
|
315
|
+
console.warn(`[Catalog] ${page.id}.${member.id}: ${issue}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const isFamily = page.members !== undefined && page.members.length > 0;
|
|
320
|
+
const componentName = isFamily ? undefined : (page.component ?? page.id);
|
|
321
|
+
const component = componentName ? componentByName.get(componentName) : undefined;
|
|
322
|
+
addToGroup(page.group, page.id);
|
|
323
|
+
let family;
|
|
324
|
+
if (isFamily) {
|
|
325
|
+
const otherPageIds = new Set([...allPageIds].filter((id) => id !== page.id));
|
|
326
|
+
const otherMemberIds = new Set();
|
|
327
|
+
for (const [id, ids] of familyIdsByPage)
|
|
328
|
+
if (id !== page.id)
|
|
329
|
+
for (const memberId of ids)
|
|
330
|
+
otherMemberIds.add(memberId);
|
|
331
|
+
// `hasSpecimens` is computed here, as doctor does, so the list-section rule also fires in
|
|
332
|
+
// the development console, not only in `ds-viewer doctor`.
|
|
333
|
+
const members = page.members.map((member) => ({
|
|
334
|
+
...member,
|
|
335
|
+
hasSpecimens: Boolean(member.variants?.items?.length || member.states?.items?.length || member.comparison),
|
|
336
|
+
}));
|
|
337
|
+
const issues = validateFamily({ ...page, members, anatomy: page.anatomy }, otherPageIds, otherMemberIds);
|
|
338
|
+
if (globalThis.__DEV__) {
|
|
339
|
+
for (const issue of issues)
|
|
340
|
+
console.error(`[Catalog] ${issue}`);
|
|
341
|
+
}
|
|
342
|
+
family = {
|
|
343
|
+
whole: page.whole,
|
|
344
|
+
sections: page.sections,
|
|
345
|
+
outline: numberFor(page),
|
|
346
|
+
notShown: page.notShown,
|
|
347
|
+
aliases: page.aliases,
|
|
348
|
+
apiLabel: page.apiLabel,
|
|
349
|
+
anatomy: page.anatomy,
|
|
350
|
+
members: page.members.map((member) => {
|
|
351
|
+
const memberComponent = member.component ? componentByName.get(member.component) : undefined;
|
|
352
|
+
return {
|
|
353
|
+
...member,
|
|
354
|
+
props: memberComponent ? mergePropNotes(memberComponent, undefined) : undefined,
|
|
355
|
+
path: memberComponent?.file ?? member.source,
|
|
356
|
+
};
|
|
357
|
+
}),
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
// Important finding 4: a standalone page (no matching component record) has no props to show
|
|
361
|
+
// and nothing to say "This component takes no props" about — hide the Props box, and fall back
|
|
362
|
+
// to the page's own file as its Source instead of an empty path.
|
|
363
|
+
return {
|
|
364
|
+
id: page.id,
|
|
365
|
+
title: page.title,
|
|
366
|
+
osComponent: page.osComponent,
|
|
367
|
+
description: page.description,
|
|
368
|
+
path: component?.file ?? page.source ?? page.file,
|
|
369
|
+
whenToUse: page.whenToUse,
|
|
370
|
+
props: component ? mergePropNotes(component, page.propNotes) : undefined,
|
|
371
|
+
a11y: page.a11y,
|
|
372
|
+
variants: page.variants,
|
|
373
|
+
states: page.states,
|
|
374
|
+
render: page.render,
|
|
375
|
+
// `tokenSections` makes a page a token gallery by itself.
|
|
376
|
+
tokenGallery: page.tokenGallery || (page.tokenSections !== undefined && page.tokenSections.length > 0) || undefined,
|
|
377
|
+
tokenSections: page.tokenSections,
|
|
378
|
+
tokenColumns: page.tokenColumns,
|
|
379
|
+
fullWidthLabel: page.fullWidthLabel,
|
|
380
|
+
comparison: page.comparison,
|
|
381
|
+
specimenSize: page.specimenSize,
|
|
382
|
+
specimenSurface: page.specimenSurface,
|
|
383
|
+
previewWidths: page.previewWidths,
|
|
384
|
+
previewLayout: page.previewLayout,
|
|
385
|
+
hide: component ? page.hide : { ...page.hide, props: true },
|
|
386
|
+
composedOf: page.composedOf,
|
|
387
|
+
internalProps: page.internalProps,
|
|
388
|
+
intentionalStaticPreview: page.intentionalStaticPreview,
|
|
389
|
+
family,
|
|
390
|
+
};
|
|
391
|
+
});
|
|
392
|
+
const undocumented = components.filter((component) => !documented.has(component.name)).sort((a, b) => a.name.localeCompare(b.name));
|
|
393
|
+
for (const component of undocumented) {
|
|
394
|
+
const id = component.name;
|
|
395
|
+
// V2c item 7: a component with no page of its own, whose name happens to collide with an
|
|
396
|
+
// authored page's own id (most likely a family page, which never resolves `documented` via the
|
|
397
|
+
// `page.component ?? page.id` fallback) — its stub must never win that id in `sections`.
|
|
398
|
+
if (seenIds.has(id)) {
|
|
399
|
+
if (globalThis.__DEV__) {
|
|
400
|
+
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.`);
|
|
401
|
+
}
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
sections.push({ id, description: 'No examples documented.', path: component.file, props: mergePropNotes(component, undefined) });
|
|
405
|
+
addToGroup('Components', id);
|
|
406
|
+
}
|
|
407
|
+
return { sections, groups: orderGroups(groupIds, groupOrder) };
|
|
408
|
+
}
|
|
@@ -26,6 +26,30 @@ export const CATALOG_TYPE = {
|
|
|
26
26
|
'3xl': 32,
|
|
27
27
|
'4xl': 40,
|
|
28
28
|
};
|
|
29
|
+
export const CATALOG_FONT = { code: 'Menlo, monospace' };
|
|
30
|
+
/** The catalog's fixed set of typography roles, each a complete `fontSize`/`fontWeight`/
|
|
31
|
+
* `lineHeight` (plus `letterSpacing`/`textTransform`/`fontFamily` where the role needs them)
|
|
32
|
+
* built on `CATALOG_TYPE`. Every catalog-chrome text style spreads one of these rather than
|
|
33
|
+
* setting its own typography properties directly (enforced by
|
|
34
|
+
* `__tests__/textRoles.test.ts`). */
|
|
35
|
+
export const CATALOG_TEXT = {
|
|
36
|
+
pageTitle: { fontSize: CATALOG_TYPE.pageTitle, fontWeight: '700', lineHeight: 34 },
|
|
37
|
+
heading1: { fontSize: CATALOG_TYPE['2xl'], fontWeight: '700', lineHeight: 30 },
|
|
38
|
+
heading2: { fontSize: CATALOG_TYPE.xl, fontWeight: '700', lineHeight: 24 },
|
|
39
|
+
heading3: { fontSize: CATALOG_TYPE.lg, fontWeight: '700', lineHeight: 22 },
|
|
40
|
+
icon: { fontSize: CATALOG_TYPE.lg, fontWeight: '400', lineHeight: 22 },
|
|
41
|
+
body: { fontSize: CATALOG_TYPE.md, fontWeight: '400', lineHeight: 20 },
|
|
42
|
+
bodyStrong: { fontSize: CATALOG_TYPE.md, fontWeight: '700', lineHeight: 20 },
|
|
43
|
+
caption: { fontSize: CATALOG_TYPE.sm, fontWeight: '400', lineHeight: 18 },
|
|
44
|
+
captionStrong: { fontSize: CATALOG_TYPE.sm, fontWeight: '700', lineHeight: 18 },
|
|
45
|
+
label: { fontSize: CATALOG_TYPE.sm, fontWeight: '700', lineHeight: 18, letterSpacing: 0.72, textTransform: 'uppercase' },
|
|
46
|
+
micro: { fontSize: CATALOG_TYPE.xs, fontWeight: '400', lineHeight: 14 },
|
|
47
|
+
microLabel: { fontSize: CATALOG_TYPE.xs, fontWeight: '700', lineHeight: 14, letterSpacing: 0.6, textTransform: 'uppercase' },
|
|
48
|
+
code: { fontSize: CATALOG_TYPE.md, fontWeight: '400', lineHeight: 20, fontFamily: CATALOG_FONT.code },
|
|
49
|
+
codeSmall: { fontSize: CATALOG_TYPE.sm, fontWeight: '400', lineHeight: 18, fontFamily: CATALOG_FONT.code },
|
|
50
|
+
codeSmallStrong: { fontSize: CATALOG_TYPE.sm, fontWeight: '700', lineHeight: 18, fontFamily: CATALOG_FONT.code },
|
|
51
|
+
codeMicro: { fontSize: CATALOG_TYPE.xs, fontWeight: '400', lineHeight: 14, fontFamily: CATALOG_FONT.code },
|
|
52
|
+
};
|
|
29
53
|
export const CATALOG_SPACE = {
|
|
30
54
|
xs: 4,
|
|
31
55
|
sm: 8,
|
|
@@ -69,21 +93,42 @@ export const CATALOG_LAYOUT = {
|
|
|
69
93
|
/** Max width of the main content column. */
|
|
70
94
|
export const CATALOG_MAX_CONTENT_WIDTH = 1200;
|
|
71
95
|
/** When to reach for each catalog-chrome type size. Rendered in the framework catalog's Type
|
|
72
|
-
* Scale page.
|
|
96
|
+
* Scale page. Every size is now consumed through a `CATALOG_TEXT` role (see `CATALOG_TEXT_USE`)
|
|
97
|
+
* rather than directly. */
|
|
73
98
|
export const CATALOG_TYPE_USE = {
|
|
74
|
-
xs: '
|
|
75
|
-
tableHeader: '
|
|
76
|
-
sm: '
|
|
77
|
-
panelHeading: '
|
|
78
|
-
md: '
|
|
79
|
-
lg: '
|
|
80
|
-
brand: '
|
|
81
|
-
xl:
|
|
82
|
-
'2xl':
|
|
83
|
-
pageTitle: '
|
|
99
|
+
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).',
|
|
100
|
+
tableHeader: 'Reserved — no current consumer; grid column headers and list cell captions now use the `captionStrong` role (built on `sm`).',
|
|
101
|
+
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.',
|
|
102
|
+
panelHeading: 'Reserved — no current consumer; reference-panel and update-page headings now use the `label` role (built on `sm`).',
|
|
103
|
+
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).',
|
|
104
|
+
lg: 'Backs the `heading3` and `icon` roles: a result note\'s title; pager arrows and the filter field\'s clear (×) glyph.',
|
|
105
|
+
brand: 'Reserved — no current consumer; the sidebar app name now uses the `heading2` role (built on `xl`).',
|
|
106
|
+
xl: 'Backs the `heading2` role: the app name at the top of the sidebar.',
|
|
107
|
+
'2xl': 'Backs the `heading1` role: the update page\'s version numbers and the arrow between them.',
|
|
108
|
+
pageTitle: 'Backs the `pageTitle` role: the selected page\'s title, including the update page\'s own title.',
|
|
84
109
|
'3xl': 'Reserved — no current consumer.',
|
|
85
110
|
'4xl': 'Reserved — no current consumer.',
|
|
86
111
|
};
|
|
112
|
+
/** When to reach for each catalog-chrome typography role. Rendered in the framework catalog's
|
|
113
|
+
* Type Scale page. */
|
|
114
|
+
export const CATALOG_TEXT_USE = {
|
|
115
|
+
pageTitle: 'The selected page\'s title, including the update page\'s own title.',
|
|
116
|
+
heading1: 'The update page\'s version numbers and the arrow between them.',
|
|
117
|
+
heading2: 'The app name at the top of the sidebar.',
|
|
118
|
+
heading3: 'A result note\'s title (the update page\'s success/failure banner).',
|
|
119
|
+
icon: 'Glyph-only controls: pager arrows, the filter field\'s clear (×) glyph, the update banner\'s close (×) glyph.',
|
|
120
|
+
body: 'Default body text: descriptions, nav links, the filter field, update-page facts/notes/steps.',
|
|
121
|
+
bodyStrong: 'Emphasised body text: grid/list row headers, switch and step labels, inline-bold notice text.',
|
|
122
|
+
caption: 'Secondary text: breadcrumbs, status captions, block/prop descriptions, sidebar subtitle/footer, update-page captions.',
|
|
123
|
+
captionStrong: 'Emphasised secondary text: grid column headers, grid/list/table captions, reference-panel subheadings, swatch/token names, replay and result links, step-icon glyphs.',
|
|
124
|
+
label: 'Uppercase labels and headings: block and preview-frame labels, token-section labels, reference-panel and update-page headings.',
|
|
125
|
+
micro: 'The smallest text: token values and meta captions, a prop\'s default-value label.',
|
|
126
|
+
microLabel: 'Uppercase micro labels: variant-group names, sidebar group labels, OS badges.',
|
|
127
|
+
code: 'Monospace body text: a long unbroken value that needs to wrap at its \'/\'s.',
|
|
128
|
+
codeSmall: 'Monospace secondary text: a prop\'s optional marker, the update page\'s inline code, file paths and log lines.',
|
|
129
|
+
codeSmallStrong: 'Emphasised monospace secondary text: a prop\'s own name.',
|
|
130
|
+
codeMicro: 'Monospace micro text: a prop\'s type and default value.',
|
|
131
|
+
};
|
|
87
132
|
/** When to reach for each catalog-chrome spacing step. Rendered in the framework catalog's
|
|
88
133
|
* Spacing page. */
|
|
89
134
|
export const CATALOG_SPACE_USE = {
|
|
@@ -127,7 +172,17 @@ export const CATALOG_COLOR = {
|
|
|
127
172
|
accentSubtle: '#e9efff',
|
|
128
173
|
/** 3px keyboard focus ring on every catalog control. */
|
|
129
174
|
focusRing: '#c9d7ff',
|
|
130
|
-
|
|
175
|
+
/** Family-page Part tree connector line (Slice D1/D2) — the approved reference's own line color
|
|
176
|
+
* has no match among the other tokens above. */
|
|
177
|
+
treeLine: '#a9bdf0',
|
|
178
|
+
/** Family-page API code block: a dark surface and its text, the one place the catalog shows a
|
|
179
|
+
* member's raw API signature. Dark on purpose so it reads as code, not as catalog chrome. */
|
|
180
|
+
codeSurface: '#1d1d1f',
|
|
181
|
+
codeOnSurface: '#e8e8e8',
|
|
182
|
+
/** @deprecated kept for the public API; re-points at `CATALOG_FONT.code` so there is one source
|
|
183
|
+
* of truth. New code should reach for `CATALOG_FONT.code` (or a `CATALOG_TEXT` `code*` role)
|
|
184
|
+
* instead. */
|
|
185
|
+
code: CATALOG_FONT.code,
|
|
131
186
|
/** Major-update banner background/border/text (design §5 "Viewer notice"). */
|
|
132
187
|
warning: '#8a4b00',
|
|
133
188
|
warningSubtle: '#fff4e0',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { Platform, StyleSheet, Text, View } from 'react-native';
|
|
3
|
-
import { CATALOG_COLOR,
|
|
3
|
+
import { CATALOG_COLOR, CATALOG_TEXT } from './tokens';
|
|
4
4
|
import { isFiniteOverlaySize, overlayStageDimensions, resolveOverlayViewport, type OverlaySlot } from './overlayViewport';
|
|
5
5
|
|
|
6
6
|
function isWeb(): boolean {
|
|
@@ -108,5 +108,5 @@ const styles = StyleSheet.create({
|
|
|
108
108
|
height: '100%',
|
|
109
109
|
borderWidth: 0,
|
|
110
110
|
},
|
|
111
|
-
status: { position: 'absolute',
|
|
111
|
+
status: { position: 'absolute', ...CATALOG_TEXT.caption, color: CATALOG_COLOR.textMuted },
|
|
112
112
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { forwardRef, useState } from 'react';
|
|
2
2
|
import { ActivityIndicator, Pressable, StyleSheet, Text, type View } from 'react-native';
|
|
3
|
-
import { CATALOG_COLOR, CATALOG_LAYOUT, CATALOG_RADIUS, CATALOG_SPACE,
|
|
3
|
+
import { CATALOG_COLOR, CATALOG_LAYOUT, CATALOG_RADIUS, CATALOG_SPACE, CATALOG_TEXT } from './tokens';
|
|
4
4
|
|
|
5
5
|
/** The viewer's own button, for catalog chrome and demo triggers (not an app component): a rounded
|
|
6
6
|
* rectangle, primary in the accent blue, secondary outlined. `disabled` greys it and stops the
|
|
@@ -77,7 +77,7 @@ const styles = StyleSheet.create({
|
|
|
77
77
|
disabled: { backgroundColor: CATALOG_COLOR.controlDisabled, borderColor: CATALOG_COLOR.controlDisabled },
|
|
78
78
|
// Same ring as the sidebar's: an outline, so focusing never shifts the layout.
|
|
79
79
|
focus: { outlineWidth: CATALOG_LAYOUT.focusRingWidth, outlineStyle: 'solid', outlineColor: CATALOG_COLOR.focusRing } as object,
|
|
80
|
-
label: {
|
|
80
|
+
label: { ...CATALOG_TEXT.bodyStrong },
|
|
81
81
|
labelPrimary: { color: '#ffffff' },
|
|
82
82
|
labelSecondary: { color: CATALOG_COLOR.text },
|
|
83
83
|
labelBusy: { color: CATALOG_COLOR.textMuted },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef, useState } from 'react';
|
|
2
2
|
import { View, Text, TextInput, Pressable, StyleSheet } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { CATALOG_TEXT, CATALOG_COLOR, CATALOG_SPACE, CATALOG_RADIUS, CATALOG_LAYOUT } from './tokens';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Plain search input for filtering the catalog's own sidebar nav. Deliberately built from bare
|
|
@@ -74,7 +74,7 @@ const styles = StyleSheet.create({
|
|
|
74
74
|
backgroundColor: CATALOG_COLOR.surfaceMuted,
|
|
75
75
|
},
|
|
76
76
|
boxFocused: { outlineWidth: CATALOG_LAYOUT.focusRingWidth, outlineStyle: 'solid', outlineColor: CATALOG_COLOR.focusRing },
|
|
77
|
-
input: { flex: 1,
|
|
77
|
+
input: { flex: 1, ...CATALOG_TEXT.body, color: CATALOG_COLOR.text, padding: 0 },
|
|
78
78
|
// A full 44×44 target: react-native-web does not honor hitSlop for pointer or keyboard.
|
|
79
79
|
clearButton: {
|
|
80
80
|
width: CATALOG_LAYOUT.controlSize, height: CATALOG_LAYOUT.controlSize,
|
|
@@ -82,5 +82,5 @@ const styles = StyleSheet.create({
|
|
|
82
82
|
},
|
|
83
83
|
focusRing: { outlineWidth: CATALOG_LAYOUT.focusRingWidth, outlineStyle: 'solid', outlineColor: CATALOG_COLOR.focusRing },
|
|
84
84
|
clearButtonActive: { backgroundColor: CATALOG_COLOR.surfacePressed },
|
|
85
|
-
clear: {
|
|
85
|
+
clear: { ...CATALOG_TEXT.icon, color: CATALOG_COLOR.textMuted, paddingHorizontal: 2 },
|
|
86
86
|
});
|