@graphql-markdown/nuxt-theme 0.0.0-stage → 0.1.1
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 +196 -2
- package/app/app-config.d.ts +15 -0
- package/app/app.config.ts +22 -0
- package/app/assets/css/main.css +85 -0
- package/app/components/ApiCodeColumn.vue +53 -0
- package/app/components/ApiDocumentContent.vue +45 -0
- package/app/components/ApiNamespaceLanding.vue +29 -0
- package/app/components/ApiOverviewGrid.vue +38 -0
- package/app/components/ApiSinglePageEntry.vue +75 -0
- package/app/components/ApiSinglePageSection.vue +32 -0
- package/app/components/SchemaCodeCard.vue +68 -0
- package/app/components/SiteFooter.vue +13 -0
- package/app/components/SiteHeader.vue +31 -0
- package/app/composables/useApiCodeCards.ts +96 -0
- package/app/composables/useApiDocument.ts +69 -0
- package/app/composables/useApiNavigation.ts +212 -0
- package/app/composables/useApiReferencePage.ts +164 -0
- package/app/composables/useApiSinglePage.ts +320 -0
- package/app/composables/useClipboardCopy.ts +56 -0
- package/app/composables/useHierarchyMode.ts +48 -0
- package/app/layouts/reference.vue +128 -0
- package/app/pages/api-reference/[...slug].vue +233 -0
- package/app/utils/api-document.ts +329 -0
- package/app/utils/mdc.ts +60 -0
- package/app/utils/navigation-tree.ts +28 -0
- package/bin/swizzle.mjs +256 -0
- package/content.config.ts +13 -0
- package/formatter.ts +77 -0
- package/generate.ts +91 -0
- package/modules/generate.ts +72 -0
- package/modules/prerender.ts +104 -0
- package/nuxt.config.ts +16 -0
- package/package.json +81 -4
- package/swizzle.manifest.mjs +84 -0
- package/swizzle.manifest.ts +11 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { codeToHtml } from "shiki";
|
|
2
|
+
import {
|
|
3
|
+
CODE_COLUMN_SECTIONS,
|
|
4
|
+
codeColumnNodeIndexes,
|
|
5
|
+
definitionCode,
|
|
6
|
+
findDeprecationNotice,
|
|
7
|
+
isOperationCategory,
|
|
8
|
+
schemaKindLabel,
|
|
9
|
+
sectionCode,
|
|
10
|
+
splitDocumentSections,
|
|
11
|
+
toRenderableNode,
|
|
12
|
+
withoutDeprecationNotice,
|
|
13
|
+
} from "~/utils/api-document";
|
|
14
|
+
import type { MdcNode } from "~/utils/mdc";
|
|
15
|
+
import { detectLanguage } from "./useApiCodeCards";
|
|
16
|
+
import type {
|
|
17
|
+
ApiNavigationBranch,
|
|
18
|
+
ApiNavigationLeaf,
|
|
19
|
+
ApiNavigationNode,
|
|
20
|
+
} from "./useApiNavigation";
|
|
21
|
+
|
|
22
|
+
/** True for a namespace/schema's own generated landing doc, never a real entry. */
|
|
23
|
+
const isLandingDoc = (path: string): boolean => {
|
|
24
|
+
return path.endsWith("/generated");
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Anvil's own order: queries, then mutations, then subscriptions, then types. */
|
|
28
|
+
const OPERATION_KINDS = ["queries", "mutations", "subscriptions"] as const;
|
|
29
|
+
type OperationKind = (typeof OPERATION_KINDS)[number];
|
|
30
|
+
type BucketId = OperationKind | "types";
|
|
31
|
+
|
|
32
|
+
interface CodeCard {
|
|
33
|
+
label: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
code: string;
|
|
36
|
+
html: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* One entry of the single-page view. Typed by the swizzlable
|
|
41
|
+
* `ApiSinglePageEntry.vue` component, whose import knip can't see.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export interface ApiSinglePageEntry {
|
|
46
|
+
anchorId: string;
|
|
47
|
+
title: string;
|
|
48
|
+
kindLabel: string;
|
|
49
|
+
isDeprecated: boolean;
|
|
50
|
+
deprecationReason?: string;
|
|
51
|
+
lead?: Record<string, any>;
|
|
52
|
+
sections: { id: string; title: string; document: Record<string, any> }[];
|
|
53
|
+
definitionCard?: CodeCard;
|
|
54
|
+
exampleCards: CodeCard[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ApiSinglePageBucket {
|
|
58
|
+
id: BucketId;
|
|
59
|
+
title: string;
|
|
60
|
+
entries: ApiSinglePageEntry[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface RawPage {
|
|
64
|
+
path: string;
|
|
65
|
+
title: string;
|
|
66
|
+
/** Undeclared custom frontmatter, stamped by `formatter.ts`; Nuxt Content
|
|
67
|
+
* surfaces it under `meta`, not as a top-level field. */
|
|
68
|
+
kind?: string;
|
|
69
|
+
body: { [key: string]: unknown; value: MdcNode[] };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A GraphQL type and an operation can share a name (a `user` query and a
|
|
74
|
+
* `User` object type both exist in the same schema) — `@graphql-markdown/core`'s
|
|
75
|
+
* flat-hierarchy renderer (`renderTypeEntities`) already resolves that by
|
|
76
|
+
* prefixing the generated *filename* itself with the entity kind
|
|
77
|
+
* (`objects-user.mdx` vs `queries-user.mdx`), so the page's own trailing path
|
|
78
|
+
* segment is already unique by the time it reaches here — this just reads it
|
|
79
|
+
* back verbatim rather than adding a second prefix on top of one that's
|
|
80
|
+
* already there. Exported so `[...slug].vue` can redirect an old per-type
|
|
81
|
+
* route to the exact same anchor this composable gives that page's entry on
|
|
82
|
+
* the single-page view — one source of truth, so the two can't drift apart.
|
|
83
|
+
*/
|
|
84
|
+
export const anchorIdFor = (page: { path: string; kind?: string }): string => {
|
|
85
|
+
return page.path.split("/").findLast(Boolean) ?? page.path;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const bucketIdFor = (kind: string | undefined): BucketId => {
|
|
89
|
+
return kind && (OPERATION_KINDS as readonly string[]).includes(kind)
|
|
90
|
+
? (kind as OperationKind)
|
|
91
|
+
: "types";
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const BUCKET_TITLES: Record<BucketId, string> = {
|
|
95
|
+
queries: "Queries",
|
|
96
|
+
mutations: "Mutations",
|
|
97
|
+
subscriptions: "Subscriptions",
|
|
98
|
+
types: "Types",
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Highlights every card a single page carries, dropping any it has no
|
|
102
|
+
* snippet for — mirrors `useApiCodeCards`'s own `toCards`, one page at a
|
|
103
|
+
* time, so per-page work can run in parallel across the whole schema. */
|
|
104
|
+
const highlightCards = async (
|
|
105
|
+
requests: { label: string; kind: string; code?: string }[],
|
|
106
|
+
shikiTheme: string,
|
|
107
|
+
): Promise<CodeCard[]> => {
|
|
108
|
+
return Promise.all(
|
|
109
|
+
requests
|
|
110
|
+
.filter((request): request is typeof request & { code: string } => {
|
|
111
|
+
return Boolean(request.code);
|
|
112
|
+
})
|
|
113
|
+
.map(async (request) => {
|
|
114
|
+
return {
|
|
115
|
+
...request,
|
|
116
|
+
html: await codeToHtml(request.code, {
|
|
117
|
+
lang: detectLanguage(request.code),
|
|
118
|
+
theme: shikiTheme,
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const buildEntry = async (
|
|
126
|
+
page: RawPage,
|
|
127
|
+
shikiTheme: string,
|
|
128
|
+
): Promise<ApiSinglePageEntry> => {
|
|
129
|
+
const documentBody = page.body.value;
|
|
130
|
+
const deprecationReason = findDeprecationNotice(page.body);
|
|
131
|
+
const inCodeColumn = codeColumnNodeIndexes(documentBody);
|
|
132
|
+
const documentNodes = withoutDeprecationNotice(
|
|
133
|
+
documentBody.filter((_, index) => {
|
|
134
|
+
return !inCodeColumn.has(index);
|
|
135
|
+
}),
|
|
136
|
+
deprecationReason,
|
|
137
|
+
).map(toRenderableNode);
|
|
138
|
+
|
|
139
|
+
const { lead, sections } = splitDocumentSections(documentNodes);
|
|
140
|
+
const asDocument = (nodes: MdcNode[]): RawPage => {
|
|
141
|
+
return { ...page, body: { ...page.body, value: nodes } };
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const isOperation = isOperationCategory(page.kind);
|
|
145
|
+
const kindLabel = schemaKindLabel(page.kind);
|
|
146
|
+
const filteredSections = CODE_COLUMN_SECTIONS.filter((section) => {
|
|
147
|
+
return !section.operationOnly || isOperation;
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const [definitionCard, exampleCards] = await Promise.all([
|
|
151
|
+
highlightCards(
|
|
152
|
+
[{ label: "SDL", kind: kindLabel, code: definitionCode(documentBody) }],
|
|
153
|
+
shikiTheme,
|
|
154
|
+
),
|
|
155
|
+
highlightCards(
|
|
156
|
+
filteredSections.map(({ title, label, kind }) => {
|
|
157
|
+
return {
|
|
158
|
+
label: label ?? title,
|
|
159
|
+
kind: kind ?? kindLabel,
|
|
160
|
+
code: sectionCode(documentBody, title),
|
|
161
|
+
};
|
|
162
|
+
}),
|
|
163
|
+
shikiTheme,
|
|
164
|
+
),
|
|
165
|
+
]);
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
anchorId: anchorIdFor(page),
|
|
169
|
+
title: page.title,
|
|
170
|
+
kindLabel,
|
|
171
|
+
isDeprecated: Boolean(deprecationReason),
|
|
172
|
+
deprecationReason,
|
|
173
|
+
lead: lead.length ? asDocument(lead) : undefined,
|
|
174
|
+
sections: sections.map(({ nodes, ...section }) => {
|
|
175
|
+
return { ...section, document: asDocument(nodes) };
|
|
176
|
+
}),
|
|
177
|
+
definitionCard: definitionCard[0],
|
|
178
|
+
exampleCards,
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Everything the single-page reference view needs: every generated page's
|
|
184
|
+
* full body, fixed up and split into lead/sections the same way
|
|
185
|
+
* `useApiDocument` does for one page at a time, grouped into
|
|
186
|
+
* Queries/Mutations/Subscriptions/Types buckets in Anvil's order, with every
|
|
187
|
+
* definition and example already Shiki-highlighted. Rendered at the base
|
|
188
|
+
* route (`[...slug].vue`'s landing branch) whenever `useHierarchyMode()`
|
|
189
|
+
* detects flat hierarchy, in place of the per-type catalog.
|
|
190
|
+
*
|
|
191
|
+
* Deliberately independent of `useApiNavigation.ts` (which drives the
|
|
192
|
+
* existing per-page sidebar/search): it groups by folder-path segments with a
|
|
193
|
+
* `kind`-based fallback for flat hierarchy, whereas this always groups by the
|
|
194
|
+
* `kind` frontmatter directly, so it groups correctly under `hierarchy: "api" | "entity" | "flat"`
|
|
195
|
+
* alike, with a single code path.
|
|
196
|
+
*
|
|
197
|
+
* Not built to scale indefinitely: every entry's definition/examples are
|
|
198
|
+
* Shiki-highlighted up front (one build-time cost, parallelized across
|
|
199
|
+
* entries) and every entry hydrates its own copy-button state, so a schema
|
|
200
|
+
* with hundreds of types renders as hundreds of small interactive islands on
|
|
201
|
+
* one page. Consumers with very large schemas should prefer `"api"`/`"entity"`
|
|
202
|
+
* hierarchy over `"flat"`.
|
|
203
|
+
*/
|
|
204
|
+
export const useApiSinglePage = async (
|
|
205
|
+
enabled = true,
|
|
206
|
+
): Promise<{
|
|
207
|
+
buckets: ComputedRef<ApiSinglePageBucket[]>;
|
|
208
|
+
}> => {
|
|
209
|
+
const config = useAppConfig();
|
|
210
|
+
const shikiTheme = config.gqlmd.shikiTheme;
|
|
211
|
+
|
|
212
|
+
// The whole fetch-and-build pipeline runs inside `useAsyncData`'s own
|
|
213
|
+
// handler (not just the raw query) so `[...slug].vue` and `reference.vue`
|
|
214
|
+
// — which both call this composable under flat hierarchy — share one
|
|
215
|
+
// cached result under this key instead of each redoing the Shiki
|
|
216
|
+
// highlighting pass.
|
|
217
|
+
// When `enabled` is false (non-flat hierarchy) the handler returns empty
|
|
218
|
+
// buckets without querying or highlighting, under a distinct key.
|
|
219
|
+
const { data: buckets } = await useAsyncData(
|
|
220
|
+
enabled
|
|
221
|
+
? "api-reference-single-page"
|
|
222
|
+
: "api-reference-single-page-disabled",
|
|
223
|
+
async (): Promise<ApiSinglePageBucket[]> => {
|
|
224
|
+
if (!enabled) {
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const items = await queryCollection("content")
|
|
229
|
+
.order("path", "ASC")
|
|
230
|
+
.select("path", "title", "body", "meta")
|
|
231
|
+
.all();
|
|
232
|
+
|
|
233
|
+
const rawPages = items
|
|
234
|
+
.filter((item) => {
|
|
235
|
+
return !isLandingDoc(item.path);
|
|
236
|
+
})
|
|
237
|
+
.map<RawPage>((item) => {
|
|
238
|
+
return {
|
|
239
|
+
path: item.path,
|
|
240
|
+
title: item.title,
|
|
241
|
+
// Nuxt Content's generated query type claims `meta` is always
|
|
242
|
+
// present, but real content items can omit it — this optional
|
|
243
|
+
// chain is load-bearing (see the same pattern and rationale in
|
|
244
|
+
// `useApiNavigation.ts`).
|
|
245
|
+
kind:
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
247
|
+
typeof item.meta?.kind === "string" ? item.meta.kind : undefined,
|
|
248
|
+
// Nuxt Content's generated `MarkdownRoot` type has no index signature,
|
|
249
|
+
// so it doesn't structurally satisfy `RawPage["body"]` even though its
|
|
250
|
+
// `value: MdcNode[]` shape matches at runtime — same as every other
|
|
251
|
+
// composable in this app that touches a content body (see
|
|
252
|
+
// `useApiDocument.ts`, which sidesteps this by typing `page` loosely).
|
|
253
|
+
body: item.body as unknown as RawPage["body"],
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const entries = await Promise.all(
|
|
258
|
+
rawPages.map(async (page) => {
|
|
259
|
+
return buildEntry(page, shikiTheme);
|
|
260
|
+
}),
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
return (["queries", "mutations", "subscriptions", "types"] as const)
|
|
264
|
+
.map((id) => {
|
|
265
|
+
return {
|
|
266
|
+
id,
|
|
267
|
+
title: BUCKET_TITLES[id],
|
|
268
|
+
entries: entries
|
|
269
|
+
.filter((_, index) => {
|
|
270
|
+
return bucketIdFor(rawPages[index]!.kind) === id;
|
|
271
|
+
})
|
|
272
|
+
.sort((a, b) => {
|
|
273
|
+
return a.title.localeCompare(b.title);
|
|
274
|
+
}),
|
|
275
|
+
};
|
|
276
|
+
})
|
|
277
|
+
.filter((bucket) => {
|
|
278
|
+
return bucket.entries.length > 0;
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
buckets: computed(() => {
|
|
285
|
+
return buckets.value ?? [];
|
|
286
|
+
}),
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The `useApiNavigation`-shaped anchor tree for the single-page view's own
|
|
292
|
+
* sidebar: same `ApiNavigationNode` type, but every leaf's `path` is an
|
|
293
|
+
* in-page hash (`#<anchorId>`) instead of a route — `UContentNavigation`'s
|
|
294
|
+
* link already treats a hash-only `to` as an in-page scroll, so no custom
|
|
295
|
+
* click handling is needed.
|
|
296
|
+
*/
|
|
297
|
+
export const useApiSinglePageNavigation = (
|
|
298
|
+
buckets: ApiSinglePageBucket[],
|
|
299
|
+
): ApiNavigationNode[] => {
|
|
300
|
+
return buckets.map((bucket): ApiNavigationBranch => {
|
|
301
|
+
return {
|
|
302
|
+
title: bucket.title,
|
|
303
|
+
children: bucket.entries.map((entry): ApiNavigationLeaf => {
|
|
304
|
+
return {
|
|
305
|
+
title: entry.title,
|
|
306
|
+
path: `#${entry.anchorId}`,
|
|
307
|
+
isDeprecated: entry.isDeprecated,
|
|
308
|
+
ui: { linkTitle: "font-mono text-[small]" },
|
|
309
|
+
badge: entry.isDeprecated
|
|
310
|
+
? {
|
|
311
|
+
label: "deprecated",
|
|
312
|
+
color: "error" as const,
|
|
313
|
+
variant: "subtle" as const,
|
|
314
|
+
}
|
|
315
|
+
: undefined,
|
|
316
|
+
};
|
|
317
|
+
}),
|
|
318
|
+
};
|
|
319
|
+
});
|
|
320
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from "vue";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copy-to-clipboard state for a code card. `@vueuse/core` is only present as
|
|
5
|
+
* a hoisted dependency of `@nuxt/ui`, so the clipboard call is written
|
|
6
|
+
* against the platform API instead.
|
|
7
|
+
*/
|
|
8
|
+
export const useClipboardCopy = (
|
|
9
|
+
label: () => string,
|
|
10
|
+
): {
|
|
11
|
+
copied: Ref<boolean>;
|
|
12
|
+
copy: (text: string) => Promise<void>;
|
|
13
|
+
copyButtonProps: ComputedRef<Record<string, string>>;
|
|
14
|
+
} => {
|
|
15
|
+
const copied = ref(false);
|
|
16
|
+
let resetTimer: ReturnType<typeof setTimeout> | undefined;
|
|
17
|
+
|
|
18
|
+
const copyLabel = computed(() => {
|
|
19
|
+
return copied.value ? "Copied" : `Copy ${label()} snippet`;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// `aria-label` (not `ariaLabel`): UButton has no such prop, so this falls
|
|
23
|
+
// through as a raw attribute — Vue does not hyphenate an unrecognized
|
|
24
|
+
// camelCase key for fallthrough attrs, so `ariaLabel` would render as the
|
|
25
|
+
// DOM attribute `arialabel`, which screen readers don't recognize.
|
|
26
|
+
const copyButtonProps = computed<Record<string, string>>(() => {
|
|
27
|
+
return {
|
|
28
|
+
icon: copied.value ? "i-lucide-check" : "i-lucide-copy",
|
|
29
|
+
color: "neutral",
|
|
30
|
+
variant: "ghost",
|
|
31
|
+
size: "xs",
|
|
32
|
+
"aria-label": copyLabel.value,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const copy = async (text: string): Promise<void> => {
|
|
37
|
+
try {
|
|
38
|
+
await navigator.clipboard.writeText(text);
|
|
39
|
+
copied.value = true;
|
|
40
|
+
clearTimeout(resetTimer);
|
|
41
|
+
resetTimer = setTimeout(() => {
|
|
42
|
+
copied.value = false;
|
|
43
|
+
}, 1500);
|
|
44
|
+
} catch {
|
|
45
|
+
// Clipboard access needs a secure context; leave the icon unchanged when
|
|
46
|
+
// the browser refuses rather than reporting a copy that did not happen.
|
|
47
|
+
copied.value = false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
onUnmounted(() => {
|
|
52
|
+
clearTimeout(resetTimer);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return { copied, copy, copyButtonProps };
|
|
56
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether the generated API reference content is using
|
|
3
|
+
* `printTypeOptions.hierarchy: "flat"` (see `@graphql-markdown/core`'s
|
|
4
|
+
* `hierarchy` option) — nothing in the generated content or app config says
|
|
5
|
+
* this explicitly, so it's inferred from path shape: under flat hierarchy
|
|
6
|
+
* every non-landing generated page has exactly one path segment past the
|
|
7
|
+
* shared `baseURL` root (no category folders); under `"api"`/`"entity"`
|
|
8
|
+
* hierarchy, pages are nested at least one level deeper.
|
|
9
|
+
*
|
|
10
|
+
* `[...slug].vue` and `reference.vue` both call this to decide whether to
|
|
11
|
+
* show the single-page reference (see `useApiSinglePage.ts`) in place of the
|
|
12
|
+
* per-type catalog — a schema generated with `hierarchy: "api"` or
|
|
13
|
+
* `"entity"` is unaffected either way, since this always resolves `false`
|
|
14
|
+
* for those.
|
|
15
|
+
*/
|
|
16
|
+
export const useHierarchyMode = async (): Promise<{
|
|
17
|
+
isFlat: ComputedRef<boolean>;
|
|
18
|
+
}> => {
|
|
19
|
+
const config = useAppConfig();
|
|
20
|
+
const rootDepth = computed(() => {
|
|
21
|
+
return (config.gqlmd.baseURL as string).split("/").filter(Boolean).length;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const { data } = await useAsyncData(
|
|
25
|
+
"api-reference-hierarchy-mode",
|
|
26
|
+
async () => {
|
|
27
|
+
const items = await queryCollection("content").select("path").all();
|
|
28
|
+
const nonLanding = items.filter((item) => {
|
|
29
|
+
return !item.path.endsWith("/generated");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
nonLanding.length > 0 &&
|
|
34
|
+
nonLanding.every((item) => {
|
|
35
|
+
return (
|
|
36
|
+
item.path.split("/").filter(Boolean).length === rootDepth.value + 1
|
|
37
|
+
);
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
isFlat: computed(() => {
|
|
45
|
+
return data.value ?? false;
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex min-h-screen flex-col bg-default font-sans text-default">
|
|
3
|
+
<SiteHeader>
|
|
4
|
+
<template #leading>
|
|
5
|
+
<UButton
|
|
6
|
+
icon="i-lucide-menu"
|
|
7
|
+
color="neutral"
|
|
8
|
+
variant="ghost"
|
|
9
|
+
class="lg:hidden"
|
|
10
|
+
aria-label="Open navigation"
|
|
11
|
+
@click="isSidebarOpen = true"
|
|
12
|
+
/>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<template #right>
|
|
16
|
+
<UContentSearchButton />
|
|
17
|
+
|
|
18
|
+
<UButton
|
|
19
|
+
v-if="config.gqlmd.githubUrl"
|
|
20
|
+
:to="config.gqlmd.githubUrl"
|
|
21
|
+
target="_blank"
|
|
22
|
+
icon="i-lucide-github"
|
|
23
|
+
color="neutral"
|
|
24
|
+
variant="outline"
|
|
25
|
+
aria-label="Repository on GitHub"
|
|
26
|
+
title="Repository on GitHub"
|
|
27
|
+
/>
|
|
28
|
+
</template>
|
|
29
|
+
</SiteHeader>
|
|
30
|
+
|
|
31
|
+
<div class="relative flex w-full flex-1">
|
|
32
|
+
<USidebar
|
|
33
|
+
v-model:open="isSidebarOpen"
|
|
34
|
+
collapsible="offcanvas"
|
|
35
|
+
mode="slideover"
|
|
36
|
+
title="GraphQL API"
|
|
37
|
+
:ui="{
|
|
38
|
+
container:
|
|
39
|
+
'top-(--ui-header-height) h-[calc(100vh-var(--ui-header-height))] border-r border-default bg-muted',
|
|
40
|
+
header: 'px-8',
|
|
41
|
+
body: 'p-8 pt-4',
|
|
42
|
+
}"
|
|
43
|
+
class="[--sidebar-width:var(--gqlmd-sidebar-width)]"
|
|
44
|
+
>
|
|
45
|
+
<template #header>
|
|
46
|
+
<NuxtLink
|
|
47
|
+
:to="baseURLPath"
|
|
48
|
+
class="block text-sm font-semibold text-dimmed transition hover:text-primary"
|
|
49
|
+
>
|
|
50
|
+
GraphQL API
|
|
51
|
+
</NuxtLink>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<UContentNavigation
|
|
55
|
+
class="gqlmd-api-nav"
|
|
56
|
+
:navigation="navigationSections as unknown as ContentNavigationItem[]"
|
|
57
|
+
default-open
|
|
58
|
+
:ui="{ link: 'text-sm', trigger: 'font-normal' }"
|
|
59
|
+
/>
|
|
60
|
+
</USidebar>
|
|
61
|
+
|
|
62
|
+
<slot />
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<SiteFooter />
|
|
66
|
+
|
|
67
|
+
<ClientOnly>
|
|
68
|
+
<!-- Nuxt UI reads the dialog's accessible name from `contentSearch.title`
|
|
69
|
+
and `contentSearch.description`, which its bundled locales do not
|
|
70
|
+
define — without these props the modal announces the raw keys. -->
|
|
71
|
+
<UContentSearch
|
|
72
|
+
:navigation="navigationSections as unknown as ContentNavigationItem[]"
|
|
73
|
+
:files="searchFiles ?? []"
|
|
74
|
+
title="Search the API reference"
|
|
75
|
+
description="Find an operation, type, field, or example by name."
|
|
76
|
+
/>
|
|
77
|
+
</ClientOnly>
|
|
78
|
+
</div>
|
|
79
|
+
</template>
|
|
80
|
+
|
|
81
|
+
<script setup lang="ts">
|
|
82
|
+
import type { ContentNavigationItem } from "@nuxt/content";
|
|
83
|
+
import { useApiSinglePageNavigation } from "~/composables/useApiSinglePage";
|
|
84
|
+
|
|
85
|
+
const config = useAppConfig();
|
|
86
|
+
const baseURLPath = useApiBaseURL();
|
|
87
|
+
const isSidebarOpen = ref(true);
|
|
88
|
+
|
|
89
|
+
// @nuxt/content's ContentNavigationItem requires a `path` on every node,
|
|
90
|
+
// including branches — real Nuxt Content trees always have one (folder index
|
|
91
|
+
// pages). This layer's own ApiNavigationBranch is a synthetic category
|
|
92
|
+
// grouping with no backing page, so it deliberately omits `path`; the two
|
|
93
|
+
// components below only ever read `title`/`children`/a leaf's own `path`, so
|
|
94
|
+
// the cast at each binding is safe in practice even though the type doesn't
|
|
95
|
+
// structurally match. UContentNavigation's `navigation` prop actually wants
|
|
96
|
+
// the stricter ContentNavigationLink (which extends this with only optional
|
|
97
|
+
// fields), so the same cast satisfies it too.
|
|
98
|
+
const { isFlat } = await useHierarchyMode();
|
|
99
|
+
const { buckets } = await useApiSinglePage(isFlat.value);
|
|
100
|
+
const { sections } = await useApiNavigation();
|
|
101
|
+
|
|
102
|
+
const navigationSections = computed(() =>
|
|
103
|
+
isFlat.value ? useApiSinglePageNavigation(buckets.value) : sections.value,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const { data: searchFiles } = await useAsyncData("api-reference-search", () =>
|
|
107
|
+
queryCollectionSearchSections("content"),
|
|
108
|
+
);
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
<style scoped>
|
|
112
|
+
/* Top-level section headers */
|
|
113
|
+
/* fallow-ignore-next-line css-selector-complexity -- Nuxt UI navigation slots have no class hooks */
|
|
114
|
+
.gqlmd-api-nav > ul > li[data-slot="itemWithChildren"] > button {
|
|
115
|
+
font-size: 0.85rem;
|
|
116
|
+
font-weight: 800;
|
|
117
|
+
text-transform: uppercase;
|
|
118
|
+
color: var(--ui-primary);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* Nested section headers (inside content divs at any depth) */
|
|
122
|
+
/* fallow-ignore-next-line css-selector-complexity -- Nuxt UI navigation slots have no class hooks */
|
|
123
|
+
.gqlmd-api-nav [data-slot="content"] li[data-slot="itemWithChildren"] > button {
|
|
124
|
+
font-weight: 400;
|
|
125
|
+
font-size: 0.875rem;
|
|
126
|
+
text-transform: none;
|
|
127
|
+
}
|
|
128
|
+
</style>
|