@gsa-tts/graymatter-ui 0.3.13 → 0.3.15
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 +8 -4
- package/package.json +6 -3
- package/src/components/ApiDocSubNavList.svelte +25 -0
- package/src/components/ApiDocSubNavMenu.svelte +464 -0
- package/src/components/ApiDocSubNavMenuItem.svelte +116 -0
- package/src/components/index.ts +3 -0
- package/src/content/api/endpoints.mdx +174 -0
- package/src/content/api/getting-started.mdx +84 -0
- package/src/content/api/support.mdx +10 -0
- package/src/layouts/BaseLayout.astro +17 -0
- package/src/layouts/DocsLayout.astro +178 -0
- package/src/types/subnav.ts +15 -0
- package/src/utils/copyButtonScript.ts +107 -0
- package/src/utils/generateApiNavData.ts +113 -0
- package/src/utils/index.ts +2 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { SubNavData } from '../types/subnav.js';
|
|
2
|
+
|
|
3
|
+
// Interface for API documentation metadata
|
|
4
|
+
export interface ApiDocMetadata {
|
|
5
|
+
id: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
sortOrder: number;
|
|
10
|
+
content?: string; // Raw MDX content for heading extraction
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Interface for navigation items with recursive children
|
|
14
|
+
interface NavItem {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
href: string;
|
|
18
|
+
children: NavItem[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Extract headings from MDX content
|
|
22
|
+
function extractHeadings(content: string) {
|
|
23
|
+
const headingRegex = /^(#{1,6})\s+(.+)$/gm;
|
|
24
|
+
const headings: Array<{ level: number; text: string; id: string }> = [];
|
|
25
|
+
let match;
|
|
26
|
+
|
|
27
|
+
while ((match = headingRegex.exec(content)) !== null) {
|
|
28
|
+
const level = match[1]?.length || 0;
|
|
29
|
+
const text = match[2]?.trim() || '';
|
|
30
|
+
// Create a simple ID from the heading text
|
|
31
|
+
const id = text
|
|
32
|
+
.toLowerCase()
|
|
33
|
+
.replace(/[^a-z0-9\s-]/g, '')
|
|
34
|
+
.replace(/\s+/g, '-');
|
|
35
|
+
headings.push({ level, text, id });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return headings;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Convert headings to nested navigation structure
|
|
42
|
+
function headingsToNavItems(
|
|
43
|
+
headings: Array<{ level: number; text: string; id: string }>
|
|
44
|
+
): NavItem[] {
|
|
45
|
+
const items: NavItem[] = [];
|
|
46
|
+
const stack: Array<NavItem & { level: number }> = [];
|
|
47
|
+
|
|
48
|
+
headings.forEach(heading => {
|
|
49
|
+
const item = {
|
|
50
|
+
id: heading.id,
|
|
51
|
+
title: heading.text,
|
|
52
|
+
href: `#${heading.id}`,
|
|
53
|
+
children: [],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Find the correct parent level
|
|
57
|
+
while (stack.length > 0) {
|
|
58
|
+
const lastItem = stack[stack.length - 1];
|
|
59
|
+
if (lastItem && lastItem.level >= heading.level) {
|
|
60
|
+
stack.pop();
|
|
61
|
+
} else {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (stack.length === 0) {
|
|
67
|
+
// Top level item
|
|
68
|
+
items.push(item);
|
|
69
|
+
} else {
|
|
70
|
+
// Nested item
|
|
71
|
+
const parent = stack[stack.length - 1];
|
|
72
|
+
if (parent) {
|
|
73
|
+
parent.children.push(item);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
stack.push({ ...item, level: heading.level });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return items;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Generate navigation data dynamically from API documentation metadata
|
|
84
|
+
export function generateApiDocumentationNavData(
|
|
85
|
+
apiDocs: ApiDocMetadata[]
|
|
86
|
+
): SubNavData {
|
|
87
|
+
// Sort by sortOrder
|
|
88
|
+
const sortedDocs = [...apiDocs].sort((a, b) => a.sortOrder - b.sortOrder);
|
|
89
|
+
|
|
90
|
+
// Convert to navigation items with dynamic heading extraction
|
|
91
|
+
const items = sortedDocs.map(doc => {
|
|
92
|
+
// Extract headings from content if provided
|
|
93
|
+
const children = doc.content
|
|
94
|
+
? headingsToNavItems(extractHeadings(doc.content))
|
|
95
|
+
: [];
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
id: doc.slug,
|
|
99
|
+
title: doc.title,
|
|
100
|
+
href: `/api/documentation#${doc.slug}`,
|
|
101
|
+
children,
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
sections: [
|
|
107
|
+
{
|
|
108
|
+
header: 'API Documentation',
|
|
109
|
+
items,
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
}
|
package/src/utils/index.ts
CHANGED