Registry as Archify cards on the model page; cards under model diagrams from registry descriptions
- model page: registry elements are rendered as Archify info cards (type colour dot, label, id · type, description, used-in chips that open the diagram), replacing the table - resolveRefs: a diagram without cards of its own gets one card per drawn shared element that has a description, so the registry text shows under every model diagram as it does on hand-written diagrams - unit tests for generated cards, own cards winning and no cards without refs; docs and changelog
This commit is contained in:
1 parent
57914d435c
commit
38cdc7604f
6 files changed
+102
-17
No files matched your search
@@ -55,6 +55,42 @@ export interface Registry {
|
||||
problems: ModelProblem[];
|
||||
}
|
||||
|
||||
/** Archify card dot colour for a component type (the colours Archify gives the nodes). */
|
||||
const DOT_BY_TYPE: Record<string, string> = {
|
||||
frontend: 'cyan',
|
||||
backend: 'emerald',
|
||||
database: 'violet',
|
||||
cloud: 'amber',
|
||||
security: 'rose',
|
||||
messagebus: 'orange',
|
||||
external: 'slate',
|
||||
};
|
||||
|
||||
export function dotForType(type?: string): string {
|
||||
return DOT_BY_TYPE[type ?? ''] ?? 'slate';
|
||||
}
|
||||
|
||||
export interface Card {
|
||||
dot: string;
|
||||
title: string;
|
||||
items: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Archify info cards for registry elements: one per element that has a
|
||||
* description, titled by its label. What a diagram gets below itself when
|
||||
* it draws shared elements and defines no cards of its own.
|
||||
*/
|
||||
export function cardsFromElements(elements: Iterable<RegistryElement>): Card[] {
|
||||
const cards: Card[] = [];
|
||||
for (const element of elements) {
|
||||
if (!element.description) continue;
|
||||
const items = [element.description.trim()];
|
||||
cards.push({ dot: dotForType(element.type), title: element.label ?? element.id, items });
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
export function isMainFile(fileName: string): boolean {
|
||||
return (fileName.split(/[\\/]/).pop() ?? '') === MAIN_FILE;
|
||||
}
|
||||
@@ -172,6 +208,8 @@ export interface ResolveOptions {
|
||||
* Expands `ref` components from the registry and strips what Archify does
|
||||
* not know. Component order and indexes are kept, so Archify's diagnostics
|
||||
* (JSON pointers) still point at the right component in the source file.
|
||||
* A diagram without `cards` of its own gets cards from the descriptions of
|
||||
* the shared elements it draws, so the registry text shows under the diagram.
|
||||
*/
|
||||
export function resolveRefs(doc: unknown, options: ResolveOptions): ResolvedDiagram {
|
||||
const problems: ModelProblem[] = [];
|
||||
@@ -229,6 +267,13 @@ export function resolveRefs(doc: unknown, options: ResolveOptions): ResolvedDiag
|
||||
if (link) links.set(id, link);
|
||||
return merged;
|
||||
});
|
||||
if (diagram.cards === undefined && refs.size) {
|
||||
const seen = new Set<string>();
|
||||
const elements: RegistryElement[] = [];
|
||||
for (const element of refs.values()) if (!seen.has(element.id)) { seen.add(element.id); elements.push(element); }
|
||||
const cards = cardsFromElements(elements);
|
||||
if (cards.length) diagram.cards = cards;
|
||||
}
|
||||
return { diagram, problems, refs, links, used };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user