@lukoweb/apitogo 0.1.1 → 0.1.3
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/dist/cli/cli.js +168 -57
- package/dist/declarations/lib/ui/Command.d.ts +1 -1
- package/dist/declarations/lib/util/MdxComponents.d.ts +1 -1
- package/package.json +2 -1
- package/src/app/main.tsx +150 -150
- package/src/config/loader.ts +245 -245
- package/src/index.ts +33 -33
- package/src/lib/authentication/components/CallbackHandler.tsx +45 -45
- package/src/lib/authentication/components/SignIn.tsx +46 -46
- package/src/lib/authentication/components/SignUp.tsx +48 -48
- package/src/lib/authentication/providers/clerk.tsx +224 -224
- package/src/lib/authentication/ui/AuthCard.tsx +7 -7
- package/src/lib/authentication/ui/EmailLinkCallbackUi.tsx +129 -125
- package/src/lib/authentication/ui/EmailLinkSentUi.tsx +105 -101
- package/src/lib/authentication/ui/EmailLinkSignInUi.tsx +100 -96
- package/src/lib/authentication/ui/EmailVerificationUi.tsx +128 -124
- package/src/lib/authentication/ui/ZudokuAuthUi.tsx +620 -616
- package/src/lib/components/AiAssistantMenuItems.tsx +102 -102
- package/src/lib/components/Autocomplete.tsx +123 -123
- package/src/lib/components/DeveloperHint.tsx +39 -35
- package/src/lib/components/Header.tsx +260 -260
- package/src/lib/components/Layout.tsx +53 -53
- package/src/lib/components/Main.tsx +51 -51
- package/src/lib/components/Mermaid.tsx +74 -70
- package/src/lib/components/MobileTopNavigation.tsx +276 -276
- package/src/lib/components/MultiSelect.tsx +86 -82
- package/src/lib/components/TopNavigation.tsx +103 -103
- package/src/lib/components/index.ts +26 -26
- package/src/lib/components/navigation/NavigationCategory.tsx +157 -157
- package/src/lib/components/navigation/NavigationFilterInput.tsx +35 -35
- package/src/lib/components/navigation/NavigationItem.tsx +181 -177
- package/src/lib/core/RouteGuard.tsx +193 -193
- package/src/lib/errors/ErrorMessage.tsx +50 -46
- package/src/lib/plugins/api-catalog/Catalog.tsx +80 -80
- package/src/lib/plugins/api-keys/CreateApiKey.tsx +128 -124
- package/src/lib/plugins/api-keys/CreateApiKeyDialog.tsx +49 -49
- package/src/lib/plugins/api-keys/SettingsApiKeys.tsx +72 -72
- package/src/lib/plugins/api-keys/settings/ApiKeyItem.tsx +342 -342
- package/src/lib/plugins/api-keys/settings/RevealApiKey.tsx +127 -127
- package/src/lib/plugins/markdown/MdxPage.tsx +285 -285
- package/src/lib/plugins/openapi/ApiHeader.tsx +96 -96
- package/src/lib/plugins/openapi/CollapsibleCode.tsx +88 -88
- package/src/lib/plugins/openapi/DownloadSchemaButton.tsx +94 -94
- package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -52
- package/src/lib/plugins/openapi/OperationListItem.tsx +183 -183
- package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +63 -63
- package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +120 -117
- package/src/lib/plugins/openapi/SchemaInfo.tsx +344 -344
- package/src/lib/plugins/openapi/SchemaList.tsx +113 -113
- package/src/lib/plugins/openapi/Sidecar.tsx +312 -309
- package/src/lib/plugins/openapi/SidecarExamples.tsx +177 -174
- package/src/lib/plugins/openapi/components/EnumValues.tsx +58 -58
- package/src/lib/plugins/openapi/components/ResponseContent.tsx +117 -114
- package/src/lib/plugins/openapi/playground/BodyPanel.tsx +274 -271
- package/src/lib/plugins/openapi/playground/CollapsibleHeader.tsx +51 -51
- package/src/lib/plugins/openapi/playground/ExamplesDropdown.tsx +60 -60
- package/src/lib/plugins/openapi/playground/Headers.tsx +188 -181
- package/src/lib/plugins/openapi/playground/IdentityDialog.tsx +75 -75
- package/src/lib/plugins/openapi/playground/IdentitySelector.tsx +38 -38
- package/src/lib/plugins/openapi/playground/ParamsGrid.tsx +45 -45
- package/src/lib/plugins/openapi/playground/Playground.tsx +602 -599
- package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +56 -56
- package/src/lib/plugins/openapi/playground/QueryParams.tsx +151 -148
- package/src/lib/plugins/openapi/playground/RequestLoginDialog.tsx +70 -70
- package/src/lib/plugins/openapi/playground/request-panel/MultipartField.tsx +91 -91
- package/src/lib/plugins/openapi/playground/result-panel/AudioPlayer.tsx +50 -50
- package/src/lib/plugins/openapi/playground/result-panel/ResponseTab.tsx +355 -355
- package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +106 -102
- package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +189 -184
- package/src/lib/plugins/openapi/schema/SchemaView.tsx +299 -299
- package/src/lib/plugins/search-pagefind/IndexingDialog.tsx +162 -162
- package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +202 -202
- package/src/lib/plugins/search-pagefind/ResultList.tsx +122 -118
- package/src/lib/ui/ActionButton.tsx +21 -21
- package/src/lib/ui/Command.tsx +191 -191
- package/src/lib/util/MdxComponents.tsx +150 -150
- package/src/vite/config.ts +234 -231
- package/src/vite/dev-server.ts +291 -291
- package/src/vite/plugin-api-keys.ts +50 -50
- package/src/vite/plugin-api.ts +320 -318
- package/src/vite/plugin-auth.ts +38 -38
- package/src/vite/plugin-component.ts +45 -39
- package/src/vite/plugin-config.ts +75 -75
- package/src/vite/plugin-custom-pages.ts +36 -36
- package/src/vite/plugin-docs.ts +202 -202
- package/src/vite/plugin-markdown-export.ts +214 -214
- package/src/vite/plugin-mdx.ts +149 -149
- package/src/vite/plugin-navigation.ts +106 -106
- package/src/vite/plugin-search.ts +47 -47
- package/src/vite/plugin.ts +42 -42
- package/src/vite/prerender/prerender.ts +233 -233
package/src/vite/plugin-mdx.ts
CHANGED
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
import rehypeMetaAsAttributes from "@lekoarts/rehype-meta-as-attributes";
|
|
2
|
-
import mdx from "@mdx-js/rollup";
|
|
3
|
-
import type { Root as HastRoot } from "hast";
|
|
4
|
-
import { toString as hastToString } from "hast-util-to-string";
|
|
5
|
-
import rehypeMdxImportMedia from "rehype-mdx-import-media";
|
|
6
|
-
import rehypeSlug from "rehype-slug";
|
|
7
|
-
import remarkComment from "remark-comment";
|
|
8
|
-
import remarkDirective from "remark-directive";
|
|
9
|
-
import remarkDirectiveRehype from "remark-directive-rehype";
|
|
10
|
-
import remarkFrontmatter from "remark-frontmatter";
|
|
11
|
-
import remarkGfm from "remark-gfm";
|
|
12
|
-
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
|
|
13
|
-
import type { PluggableList } from "unified";
|
|
14
|
-
import { EXIT, visit } from "unist-util-visit";
|
|
15
|
-
import type { Plugin } from "vite";
|
|
16
|
-
import { getCurrentConfig } from "../config/loader.js";
|
|
17
|
-
import { getBuildConfig } from "../config/validators/BuildSchema.js";
|
|
18
|
-
import {
|
|
19
|
-
createConfiguredShikiRehypePlugins,
|
|
20
|
-
highlighterPromise,
|
|
21
|
-
} from "../lib/shiki.js";
|
|
22
|
-
import rehypeExtractTocWithJsxExport from "./mdx/rehype-extract-toc-with-jsx-export.js";
|
|
23
|
-
import rehypeExtractTocWithJsx from "./mdx/rehype-extract-toc-with-jsx.js";
|
|
24
|
-
import { remarkCodeTabs } from "./mdx/remark-code-tabs.js";
|
|
25
|
-
import { remarkInjectFilepath } from "./mdx/remark-inject-filepath.js";
|
|
26
|
-
import { remarkLastModified } from "./mdx/remark-last-modified.js";
|
|
27
|
-
import { remarkLinkRewrite } from "./mdx/remark-link-rewrite.js";
|
|
28
|
-
import { remarkNormalizeImageUrl } from "./mdx/remark-normalize-image-url.js";
|
|
29
|
-
import { remarkStaticGeneration } from "./mdx/remark-static-generation.js";
|
|
30
|
-
import { exportMdxjsConst } from "./mdx/utils.js";
|
|
31
|
-
|
|
32
|
-
// Convert mdxJsxFlowElement img elements to regular element nodes
|
|
33
|
-
// so rehype-mdx-import-media can pick them up
|
|
34
|
-
// biome-ignore lint/suspicious/noExplicitAny: Allow any type
|
|
35
|
-
const rehypeNormalizeMdxImages = () => (tree: any) => {
|
|
36
|
-
visit(tree, ["mdxJsxFlowElement", "mdxJsxElement"], (node) => {
|
|
37
|
-
if (node.type !== "mdxJsxFlowElement") return;
|
|
38
|
-
if (!["img", "video"].includes(node.name)) return;
|
|
39
|
-
|
|
40
|
-
const hasStringSrc = node.attributes.some(
|
|
41
|
-
// biome-ignore lint/suspicious/noExplicitAny: Allow any type
|
|
42
|
-
(attr: any) =>
|
|
43
|
-
attr.type === "mdxJsxAttribute" &&
|
|
44
|
-
attr.name === "src" &&
|
|
45
|
-
typeof attr.value === "string",
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
if (!hasStringSrc) return;
|
|
49
|
-
|
|
50
|
-
node.type = "element";
|
|
51
|
-
node.tagName = node.name;
|
|
52
|
-
// biome-ignore lint/suspicious/noExplicitAny: Allow any type
|
|
53
|
-
node.properties = {} as Record<string, any>;
|
|
54
|
-
|
|
55
|
-
for (const attr of node.attributes) {
|
|
56
|
-
if (attr.type === "mdxJsxAttribute" && typeof attr.value === "string") {
|
|
57
|
-
node.properties[attr.name] = attr.value;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
delete node.name;
|
|
62
|
-
delete node.attributes;
|
|
63
|
-
delete node.children;
|
|
64
|
-
delete node.data;
|
|
65
|
-
delete node.position;
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const rehypeExcerptWithMdxExport = () => (tree: HastRoot) => {
|
|
70
|
-
let excerpt: string | undefined;
|
|
71
|
-
|
|
72
|
-
visit(tree, "element", (node, _index, parent) => {
|
|
73
|
-
if (node.tagName !== "p" || parent?.type !== "root") return;
|
|
74
|
-
|
|
75
|
-
excerpt = hastToString(node);
|
|
76
|
-
return EXIT;
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
if (!excerpt) return;
|
|
80
|
-
|
|
81
|
-
tree.children.unshift(exportMdxjsConst("excerpt", excerpt));
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const viteMdxPlugin = async (): Promise<Plugin> => {
|
|
85
|
-
const config = getCurrentConfig();
|
|
86
|
-
const buildConfig = await getBuildConfig();
|
|
87
|
-
const highlighter = await highlighterPromise;
|
|
88
|
-
|
|
89
|
-
const defaultRemarkPlugins = [
|
|
90
|
-
remarkStaticGeneration,
|
|
91
|
-
[remarkInjectFilepath, config.__meta.rootDir],
|
|
92
|
-
remarkComment,
|
|
93
|
-
remarkGfm,
|
|
94
|
-
remarkFrontmatter,
|
|
95
|
-
// --- important:
|
|
96
|
-
// this must be sandwiched between remarkFrontmatter and remarkMdxFrontmatter
|
|
97
|
-
remarkLastModified,
|
|
98
|
-
// ---
|
|
99
|
-
remarkMdxFrontmatter,
|
|
100
|
-
remarkDirective,
|
|
101
|
-
remarkDirectiveRehype,
|
|
102
|
-
remarkCodeTabs,
|
|
103
|
-
[remarkLinkRewrite, config.basePath],
|
|
104
|
-
[remarkNormalizeImageUrl, config.basePath],
|
|
105
|
-
...(config.build?.remarkPlugins ?? []),
|
|
106
|
-
] satisfies PluggableList;
|
|
107
|
-
|
|
108
|
-
const remarkPlugins =
|
|
109
|
-
typeof buildConfig?.remarkPlugins === "function"
|
|
110
|
-
? buildConfig.remarkPlugins(defaultRemarkPlugins)
|
|
111
|
-
: [...defaultRemarkPlugins, ...(buildConfig?.remarkPlugins ?? [])];
|
|
112
|
-
|
|
113
|
-
const defaultRehypePlugins = [
|
|
114
|
-
rehypeSlug,
|
|
115
|
-
rehypeExtractTocWithJsx,
|
|
116
|
-
rehypeExtractTocWithJsxExport,
|
|
117
|
-
rehypeExcerptWithMdxExport,
|
|
118
|
-
rehypeNormalizeMdxImages,
|
|
119
|
-
rehypeMdxImportMedia,
|
|
120
|
-
rehypeMetaAsAttributes,
|
|
121
|
-
...createConfiguredShikiRehypePlugins(
|
|
122
|
-
highlighter,
|
|
123
|
-
config.syntaxHighlighting?.themes,
|
|
124
|
-
),
|
|
125
|
-
...(config.build?.rehypePlugins ?? []),
|
|
126
|
-
] satisfies PluggableList;
|
|
127
|
-
|
|
128
|
-
const rehypePlugins =
|
|
129
|
-
typeof buildConfig?.rehypePlugins === "function"
|
|
130
|
-
? buildConfig.rehypePlugins(defaultRehypePlugins)
|
|
131
|
-
: [...defaultRehypePlugins, ...(buildConfig?.rehypePlugins ?? [])];
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
enforce: "pre",
|
|
135
|
-
...mdx({
|
|
136
|
-
providerImportSource:
|
|
137
|
-
config.__meta.mode === "internal" || config.__meta.mode === "standalone"
|
|
138
|
-
? "@mdx-js/react"
|
|
139
|
-
: "@lukoweb/apitogo/components",
|
|
140
|
-
mdxExtensions: [".mdx"],
|
|
141
|
-
format: "detect",
|
|
142
|
-
remarkPlugins,
|
|
143
|
-
rehypePlugins,
|
|
144
|
-
}),
|
|
145
|
-
name: "zudoku-mdx-plugin",
|
|
146
|
-
} as const;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export default viteMdxPlugin;
|
|
1
|
+
import rehypeMetaAsAttributes from "@lekoarts/rehype-meta-as-attributes";
|
|
2
|
+
import mdx from "@mdx-js/rollup";
|
|
3
|
+
import type { Root as HastRoot } from "hast";
|
|
4
|
+
import { toString as hastToString } from "hast-util-to-string";
|
|
5
|
+
import rehypeMdxImportMedia from "rehype-mdx-import-media";
|
|
6
|
+
import rehypeSlug from "rehype-slug";
|
|
7
|
+
import remarkComment from "remark-comment";
|
|
8
|
+
import remarkDirective from "remark-directive";
|
|
9
|
+
import remarkDirectiveRehype from "remark-directive-rehype";
|
|
10
|
+
import remarkFrontmatter from "remark-frontmatter";
|
|
11
|
+
import remarkGfm from "remark-gfm";
|
|
12
|
+
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
|
|
13
|
+
import type { PluggableList } from "unified";
|
|
14
|
+
import { EXIT, visit } from "unist-util-visit";
|
|
15
|
+
import type { Plugin } from "vite";
|
|
16
|
+
import { getCurrentConfig } from "../config/loader.js";
|
|
17
|
+
import { getBuildConfig } from "../config/validators/BuildSchema.js";
|
|
18
|
+
import {
|
|
19
|
+
createConfiguredShikiRehypePlugins,
|
|
20
|
+
highlighterPromise,
|
|
21
|
+
} from "../lib/shiki.js";
|
|
22
|
+
import rehypeExtractTocWithJsxExport from "./mdx/rehype-extract-toc-with-jsx-export.js";
|
|
23
|
+
import rehypeExtractTocWithJsx from "./mdx/rehype-extract-toc-with-jsx.js";
|
|
24
|
+
import { remarkCodeTabs } from "./mdx/remark-code-tabs.js";
|
|
25
|
+
import { remarkInjectFilepath } from "./mdx/remark-inject-filepath.js";
|
|
26
|
+
import { remarkLastModified } from "./mdx/remark-last-modified.js";
|
|
27
|
+
import { remarkLinkRewrite } from "./mdx/remark-link-rewrite.js";
|
|
28
|
+
import { remarkNormalizeImageUrl } from "./mdx/remark-normalize-image-url.js";
|
|
29
|
+
import { remarkStaticGeneration } from "./mdx/remark-static-generation.js";
|
|
30
|
+
import { exportMdxjsConst } from "./mdx/utils.js";
|
|
31
|
+
|
|
32
|
+
// Convert mdxJsxFlowElement img elements to regular element nodes
|
|
33
|
+
// so rehype-mdx-import-media can pick them up
|
|
34
|
+
// biome-ignore lint/suspicious/noExplicitAny: Allow any type
|
|
35
|
+
const rehypeNormalizeMdxImages = () => (tree: any) => {
|
|
36
|
+
visit(tree, ["mdxJsxFlowElement", "mdxJsxElement"], (node) => {
|
|
37
|
+
if (node.type !== "mdxJsxFlowElement") return;
|
|
38
|
+
if (!["img", "video"].includes(node.name)) return;
|
|
39
|
+
|
|
40
|
+
const hasStringSrc = node.attributes.some(
|
|
41
|
+
// biome-ignore lint/suspicious/noExplicitAny: Allow any type
|
|
42
|
+
(attr: any) =>
|
|
43
|
+
attr.type === "mdxJsxAttribute" &&
|
|
44
|
+
attr.name === "src" &&
|
|
45
|
+
typeof attr.value === "string",
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (!hasStringSrc) return;
|
|
49
|
+
|
|
50
|
+
node.type = "element";
|
|
51
|
+
node.tagName = node.name;
|
|
52
|
+
// biome-ignore lint/suspicious/noExplicitAny: Allow any type
|
|
53
|
+
node.properties = {} as Record<string, any>;
|
|
54
|
+
|
|
55
|
+
for (const attr of node.attributes) {
|
|
56
|
+
if (attr.type === "mdxJsxAttribute" && typeof attr.value === "string") {
|
|
57
|
+
node.properties[attr.name] = attr.value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
delete node.name;
|
|
62
|
+
delete node.attributes;
|
|
63
|
+
delete node.children;
|
|
64
|
+
delete node.data;
|
|
65
|
+
delete node.position;
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const rehypeExcerptWithMdxExport = () => (tree: HastRoot) => {
|
|
70
|
+
let excerpt: string | undefined;
|
|
71
|
+
|
|
72
|
+
visit(tree, "element", (node, _index, parent) => {
|
|
73
|
+
if (node.tagName !== "p" || parent?.type !== "root") return;
|
|
74
|
+
|
|
75
|
+
excerpt = hastToString(node);
|
|
76
|
+
return EXIT;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (!excerpt) return;
|
|
80
|
+
|
|
81
|
+
tree.children.unshift(exportMdxjsConst("excerpt", excerpt));
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const viteMdxPlugin = async (): Promise<Plugin> => {
|
|
85
|
+
const config = getCurrentConfig();
|
|
86
|
+
const buildConfig = await getBuildConfig();
|
|
87
|
+
const highlighter = await highlighterPromise;
|
|
88
|
+
|
|
89
|
+
const defaultRemarkPlugins = [
|
|
90
|
+
remarkStaticGeneration,
|
|
91
|
+
[remarkInjectFilepath, config.__meta.rootDir],
|
|
92
|
+
remarkComment,
|
|
93
|
+
remarkGfm,
|
|
94
|
+
remarkFrontmatter,
|
|
95
|
+
// --- important:
|
|
96
|
+
// this must be sandwiched between remarkFrontmatter and remarkMdxFrontmatter
|
|
97
|
+
remarkLastModified,
|
|
98
|
+
// ---
|
|
99
|
+
remarkMdxFrontmatter,
|
|
100
|
+
remarkDirective,
|
|
101
|
+
remarkDirectiveRehype,
|
|
102
|
+
remarkCodeTabs,
|
|
103
|
+
[remarkLinkRewrite, config.basePath],
|
|
104
|
+
[remarkNormalizeImageUrl, config.basePath],
|
|
105
|
+
...(config.build?.remarkPlugins ?? []),
|
|
106
|
+
] satisfies PluggableList;
|
|
107
|
+
|
|
108
|
+
const remarkPlugins =
|
|
109
|
+
typeof buildConfig?.remarkPlugins === "function"
|
|
110
|
+
? buildConfig.remarkPlugins(defaultRemarkPlugins)
|
|
111
|
+
: [...defaultRemarkPlugins, ...(buildConfig?.remarkPlugins ?? [])];
|
|
112
|
+
|
|
113
|
+
const defaultRehypePlugins = [
|
|
114
|
+
rehypeSlug,
|
|
115
|
+
rehypeExtractTocWithJsx,
|
|
116
|
+
rehypeExtractTocWithJsxExport,
|
|
117
|
+
rehypeExcerptWithMdxExport,
|
|
118
|
+
rehypeNormalizeMdxImages,
|
|
119
|
+
rehypeMdxImportMedia,
|
|
120
|
+
rehypeMetaAsAttributes,
|
|
121
|
+
...createConfiguredShikiRehypePlugins(
|
|
122
|
+
highlighter,
|
|
123
|
+
config.syntaxHighlighting?.themes,
|
|
124
|
+
),
|
|
125
|
+
...(config.build?.rehypePlugins ?? []),
|
|
126
|
+
] satisfies PluggableList;
|
|
127
|
+
|
|
128
|
+
const rehypePlugins =
|
|
129
|
+
typeof buildConfig?.rehypePlugins === "function"
|
|
130
|
+
? buildConfig.rehypePlugins(defaultRehypePlugins)
|
|
131
|
+
: [...defaultRehypePlugins, ...(buildConfig?.rehypePlugins ?? [])];
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
enforce: "pre",
|
|
135
|
+
...mdx({
|
|
136
|
+
providerImportSource:
|
|
137
|
+
config.__meta.mode === "internal" || config.__meta.mode === "standalone"
|
|
138
|
+
? "@mdx-js/react"
|
|
139
|
+
: "@lukoweb/apitogo/components",
|
|
140
|
+
mdxExtensions: [".mdx"],
|
|
141
|
+
format: "detect",
|
|
142
|
+
remarkPlugins,
|
|
143
|
+
rehypePlugins,
|
|
144
|
+
}),
|
|
145
|
+
name: "zudoku-mdx-plugin",
|
|
146
|
+
} as const;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default viteMdxPlugin;
|
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import { stringify } from "javascript-stringify";
|
|
2
|
-
import { isElement } from "react-is";
|
|
3
|
-
import type { Plugin, ViteDevServer } from "vite";
|
|
4
|
-
import { getCurrentConfig } from "../config/loader.js";
|
|
5
|
-
import { IconNames } from "../config/validators/icon-types.js";
|
|
6
|
-
import { NavigationResolver } from "../config/validators/NavigationSchema.js";
|
|
7
|
-
import invariant from "../lib/util/invariant.js";
|
|
8
|
-
import { writePluginDebugCode } from "./debug.js";
|
|
9
|
-
|
|
10
|
-
const toPascalCase = (str: string) =>
|
|
11
|
-
str.replace(/(^\w|-\w)/g, (match) => match.replace("-", "").toUpperCase());
|
|
12
|
-
|
|
13
|
-
const virtualModuleId = "virtual:zudoku-navigation";
|
|
14
|
-
export const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
15
|
-
|
|
16
|
-
export const invalidate = (server: ViteDevServer) => {
|
|
17
|
-
const navigationModule =
|
|
18
|
-
server.environments.ssr.moduleGraph.getModuleById(virtualModuleId);
|
|
19
|
-
if (!navigationModule) return;
|
|
20
|
-
|
|
21
|
-
server.environments.ssr.moduleGraph.invalidateModule(navigationModule);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const viteNavigationPlugin = (): Plugin => {
|
|
25
|
-
return {
|
|
26
|
-
name: "zudoku-navigation-plugin",
|
|
27
|
-
resolveId(id) {
|
|
28
|
-
if (id === virtualModuleId) {
|
|
29
|
-
return resolvedVirtualModuleId;
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
async load(id) {
|
|
33
|
-
if (id !== resolvedVirtualModuleId) return;
|
|
34
|
-
const config = getCurrentConfig();
|
|
35
|
-
|
|
36
|
-
const resolver = new NavigationResolver(config);
|
|
37
|
-
const resolvedNavigation = await resolver.resolve();
|
|
38
|
-
const resolvedRules = await resolver.resolveRules(
|
|
39
|
-
config.navigationRules ?? [],
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const collectedIcons = new Set<string>();
|
|
43
|
-
let hasMissingIcon = false;
|
|
44
|
-
|
|
45
|
-
const stringifyWithIcons = (value: unknown) =>
|
|
46
|
-
stringify(
|
|
47
|
-
value,
|
|
48
|
-
(value, _indent, next, key) => {
|
|
49
|
-
// Skip non-serializable React elements
|
|
50
|
-
if (isElement(value)) return undefined;
|
|
51
|
-
|
|
52
|
-
if (key === "icon" && typeof value === "string") {
|
|
53
|
-
const iconName = toPascalCase(value);
|
|
54
|
-
|
|
55
|
-
if (!IconNames.includes(value as IconNames)) {
|
|
56
|
-
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
57
|
-
console.warn(
|
|
58
|
-
`Icon "${value}" not found, see: https://lucide.dev/icons/`,
|
|
59
|
-
);
|
|
60
|
-
hasMissingIcon = true;
|
|
61
|
-
return "MissingIcon";
|
|
62
|
-
} else {
|
|
63
|
-
collectedIcons.add(iconName);
|
|
64
|
-
return iconName;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return next(value);
|
|
68
|
-
},
|
|
69
|
-
2,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const headerNavigationCode = stringifyWithIcons(
|
|
73
|
-
config.header?.navigation ?? [],
|
|
74
|
-
);
|
|
75
|
-
const navigationCode = stringifyWithIcons(resolvedNavigation);
|
|
76
|
-
const rulesCode = stringifyWithIcons(resolvedRules);
|
|
77
|
-
|
|
78
|
-
invariant(headerNavigationCode, "Failed to stringify header navigation");
|
|
79
|
-
invariant(navigationCode, "Failed to stringify navigation");
|
|
80
|
-
invariant(rulesCode, "Failed to stringify navigation rules");
|
|
81
|
-
|
|
82
|
-
await writePluginDebugCode(
|
|
83
|
-
config.__meta.rootDir,
|
|
84
|
-
"navigation-plugin",
|
|
85
|
-
`export const headerNavigation = ${headerNavigationCode};\nexport const navigation = ${navigationCode};\nexport const rules = ${rulesCode};`,
|
|
86
|
-
"js",
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
if (hasMissingIcon) {
|
|
90
|
-
collectedIcons.add("MissingIcon");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const importStatement =
|
|
94
|
-
collectedIcons.size > 0
|
|
95
|
-
? `import { ${[...collectedIcons].join(", ")} } from "@lukoweb/apitogo/icons";\n`
|
|
96
|
-
: "";
|
|
97
|
-
|
|
98
|
-
return [
|
|
99
|
-
importStatement,
|
|
100
|
-
`export const configuredHeaderNavigation = ${headerNavigationCode};`,
|
|
101
|
-
`export const configuredNavigation = ${navigationCode};`,
|
|
102
|
-
`export const configuredNavigationRules = ${rulesCode};`,
|
|
103
|
-
].join("\n");
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
};
|
|
1
|
+
import { stringify } from "javascript-stringify";
|
|
2
|
+
import { isElement } from "react-is";
|
|
3
|
+
import type { Plugin, ViteDevServer } from "vite";
|
|
4
|
+
import { getCurrentConfig } from "../config/loader.js";
|
|
5
|
+
import { IconNames } from "../config/validators/icon-types.js";
|
|
6
|
+
import { NavigationResolver } from "../config/validators/NavigationSchema.js";
|
|
7
|
+
import invariant from "../lib/util/invariant.js";
|
|
8
|
+
import { writePluginDebugCode } from "./debug.js";
|
|
9
|
+
|
|
10
|
+
const toPascalCase = (str: string) =>
|
|
11
|
+
str.replace(/(^\w|-\w)/g, (match) => match.replace("-", "").toUpperCase());
|
|
12
|
+
|
|
13
|
+
const virtualModuleId = "virtual:zudoku-navigation";
|
|
14
|
+
export const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
15
|
+
|
|
16
|
+
export const invalidate = (server: ViteDevServer) => {
|
|
17
|
+
const navigationModule =
|
|
18
|
+
server.environments.ssr.moduleGraph.getModuleById(virtualModuleId);
|
|
19
|
+
if (!navigationModule) return;
|
|
20
|
+
|
|
21
|
+
server.environments.ssr.moduleGraph.invalidateModule(navigationModule);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const viteNavigationPlugin = (): Plugin => {
|
|
25
|
+
return {
|
|
26
|
+
name: "zudoku-navigation-plugin",
|
|
27
|
+
resolveId(id) {
|
|
28
|
+
if (id === virtualModuleId) {
|
|
29
|
+
return resolvedVirtualModuleId;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
async load(id) {
|
|
33
|
+
if (id !== resolvedVirtualModuleId) return;
|
|
34
|
+
const config = getCurrentConfig();
|
|
35
|
+
|
|
36
|
+
const resolver = new NavigationResolver(config);
|
|
37
|
+
const resolvedNavigation = await resolver.resolve();
|
|
38
|
+
const resolvedRules = await resolver.resolveRules(
|
|
39
|
+
config.navigationRules ?? [],
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const collectedIcons = new Set<string>();
|
|
43
|
+
let hasMissingIcon = false;
|
|
44
|
+
|
|
45
|
+
const stringifyWithIcons = (value: unknown) =>
|
|
46
|
+
stringify(
|
|
47
|
+
value,
|
|
48
|
+
(value, _indent, next, key) => {
|
|
49
|
+
// Skip non-serializable React elements
|
|
50
|
+
if (isElement(value)) return undefined;
|
|
51
|
+
|
|
52
|
+
if (key === "icon" && typeof value === "string") {
|
|
53
|
+
const iconName = toPascalCase(value);
|
|
54
|
+
|
|
55
|
+
if (!IconNames.includes(value as IconNames)) {
|
|
56
|
+
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
57
|
+
console.warn(
|
|
58
|
+
`Icon "${value}" not found, see: https://lucide.dev/icons/`,
|
|
59
|
+
);
|
|
60
|
+
hasMissingIcon = true;
|
|
61
|
+
return "MissingIcon";
|
|
62
|
+
} else {
|
|
63
|
+
collectedIcons.add(iconName);
|
|
64
|
+
return iconName;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return next(value);
|
|
68
|
+
},
|
|
69
|
+
2,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const headerNavigationCode = stringifyWithIcons(
|
|
73
|
+
config.header?.navigation ?? [],
|
|
74
|
+
);
|
|
75
|
+
const navigationCode = stringifyWithIcons(resolvedNavigation);
|
|
76
|
+
const rulesCode = stringifyWithIcons(resolvedRules);
|
|
77
|
+
|
|
78
|
+
invariant(headerNavigationCode, "Failed to stringify header navigation");
|
|
79
|
+
invariant(navigationCode, "Failed to stringify navigation");
|
|
80
|
+
invariant(rulesCode, "Failed to stringify navigation rules");
|
|
81
|
+
|
|
82
|
+
await writePluginDebugCode(
|
|
83
|
+
config.__meta.rootDir,
|
|
84
|
+
"navigation-plugin",
|
|
85
|
+
`export const headerNavigation = ${headerNavigationCode};\nexport const navigation = ${navigationCode};\nexport const rules = ${rulesCode};`,
|
|
86
|
+
"js",
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (hasMissingIcon) {
|
|
90
|
+
collectedIcons.add("MissingIcon");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const importStatement =
|
|
94
|
+
collectedIcons.size > 0
|
|
95
|
+
? `import { ${[...collectedIcons].join(", ")} } from "@lukoweb/apitogo/icons";\n`
|
|
96
|
+
: "";
|
|
97
|
+
|
|
98
|
+
return [
|
|
99
|
+
importStatement,
|
|
100
|
+
`export const configuredHeaderNavigation = ${headerNavigationCode};`,
|
|
101
|
+
`export const configuredNavigation = ${navigationCode};`,
|
|
102
|
+
`export const configuredNavigationRules = ${rulesCode};`,
|
|
103
|
+
].join("\n");
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
};
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
2
|
-
import { getCurrentConfig } from "../config/loader.js";
|
|
3
|
-
|
|
4
|
-
export const viteSearchPlugin = (): Plugin => {
|
|
5
|
-
const virtualModuleId = "virtual:zudoku-search-plugin";
|
|
6
|
-
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
name: "zudoku-search-plugin",
|
|
10
|
-
resolveId(id) {
|
|
11
|
-
if (id === virtualModuleId) {
|
|
12
|
-
return resolvedVirtualModuleId;
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
async load(id) {
|
|
16
|
-
if (id !== resolvedVirtualModuleId) return;
|
|
17
|
-
|
|
18
|
-
const config = getCurrentConfig();
|
|
19
|
-
|
|
20
|
-
if (!config.search || config.__meta.mode === "standalone") {
|
|
21
|
-
return `export const configuredSearchPlugin = undefined;`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const code = [];
|
|
25
|
-
|
|
26
|
-
if (config.search.type === "inkeep") {
|
|
27
|
-
code.push(
|
|
28
|
-
`import config from 'virtual:zudoku-config';`,
|
|
29
|
-
`import { inkeepSearchPlugin } from "@lukoweb/apitogo/plugins/search-inkeep";`,
|
|
30
|
-
`export const configuredSearchPlugin = inkeepSearchPlugin(config.search);`,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
return code.join("\n");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (config.search.type === "pagefind") {
|
|
37
|
-
code.push(
|
|
38
|
-
`import config from 'virtual:zudoku-config';`,
|
|
39
|
-
`import { pagefindSearchPlugin } from "@lukoweb/apitogo/plugins/search-pagefind";`,
|
|
40
|
-
`export const configuredSearchPlugin = pagefindSearchPlugin(config.search);`,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
return code.join("\n");
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
};
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import { getCurrentConfig } from "../config/loader.js";
|
|
3
|
+
|
|
4
|
+
export const viteSearchPlugin = (): Plugin => {
|
|
5
|
+
const virtualModuleId = "virtual:zudoku-search-plugin";
|
|
6
|
+
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
name: "zudoku-search-plugin",
|
|
10
|
+
resolveId(id) {
|
|
11
|
+
if (id === virtualModuleId) {
|
|
12
|
+
return resolvedVirtualModuleId;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
async load(id) {
|
|
16
|
+
if (id !== resolvedVirtualModuleId) return;
|
|
17
|
+
|
|
18
|
+
const config = getCurrentConfig();
|
|
19
|
+
|
|
20
|
+
if (!config.search || config.__meta.mode === "standalone") {
|
|
21
|
+
return `export const configuredSearchPlugin = undefined;`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const code = [];
|
|
25
|
+
|
|
26
|
+
if (config.search.type === "inkeep") {
|
|
27
|
+
code.push(
|
|
28
|
+
`import config from 'virtual:zudoku-config';`,
|
|
29
|
+
`import { inkeepSearchPlugin } from "@lukoweb/apitogo/plugins/search-inkeep";`,
|
|
30
|
+
`export const configuredSearchPlugin = inkeepSearchPlugin(config.search);`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return code.join("\n");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (config.search.type === "pagefind") {
|
|
37
|
+
code.push(
|
|
38
|
+
`import config from 'virtual:zudoku-config';`,
|
|
39
|
+
`import { pagefindSearchPlugin } from "@lukoweb/apitogo/plugins/search-pagefind";`,
|
|
40
|
+
`export const configuredSearchPlugin = pagefindSearchPlugin(config.search);`,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return code.join("\n");
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
};
|