@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
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "@
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { useAuthState } from "../../authentication/state.js";
|
|
14
|
-
import { useZudoku } from "../../components/context/ZudokuContext.js";
|
|
15
|
-
import { SEARCH_PROTECTED_SECTION } from "../../core/RouteGuard.js";
|
|
16
|
-
import { joinUrl } from "../../util/joinUrl.js";
|
|
17
|
-
import { getResults } from "./get-results.js";
|
|
18
|
-
import type { PagefindOptions } from "./index.js";
|
|
19
|
-
import { ResultList } from "./ResultList.js";
|
|
20
|
-
import type { Pagefind } from "./types.js";
|
|
21
|
-
|
|
22
|
-
const IndexingDialog = lazy(() => import("./IndexingDialog.js"));
|
|
23
|
-
|
|
24
|
-
const DEFAULT_RANKING = {
|
|
25
|
-
// Slightly lower than default because API docs tend to have repetitive terms (parameter names, HTTP methods, etc.)
|
|
26
|
-
termFrequency: 0.8,
|
|
27
|
-
// Lower than default because API documentation pages tend to be longer due to comprehensive endpoint documentation
|
|
28
|
-
pageLength: 0.6,
|
|
29
|
-
// Slightly higher than default because in technical documentation, exact matches should be prioritized
|
|
30
|
-
termSimilarity: 1.2,
|
|
31
|
-
// Slightly lower than default because API docs might have legitimate repetition of terms
|
|
32
|
-
termSaturation: 1.2,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const importPagefind = (basePath?: string): Promise<Pagefind> =>
|
|
36
|
-
import.meta.env.DEV
|
|
37
|
-
? // @ts-expect-error TypeScript can't resolve the import
|
|
38
|
-
import(/* @vite-ignore */ "/pagefind/pagefind.js")
|
|
39
|
-
: import(/* @vite-ignore */ joinUrl(basePath, "/pagefind/pagefind.js"));
|
|
40
|
-
|
|
41
|
-
const usePagefind = (options: PagefindOptions) => {
|
|
42
|
-
const {
|
|
43
|
-
options: { basePath },
|
|
44
|
-
} = useZudoku();
|
|
45
|
-
const { data: pagefind, ...result } = useQuery<Pagefind>({
|
|
46
|
-
queryKey: ["pagefind", options.ranking],
|
|
47
|
-
retry: false,
|
|
48
|
-
queryFn: async () => {
|
|
49
|
-
const pagefind = await importPagefind(basePath);
|
|
50
|
-
await pagefind.init();
|
|
51
|
-
await pagefind.options({
|
|
52
|
-
ranking: {
|
|
53
|
-
termFrequency:
|
|
54
|
-
options.ranking?.termFrequency ?? DEFAULT_RANKING.termFrequency,
|
|
55
|
-
pageLength: options.ranking?.pageLength ?? DEFAULT_RANKING.pageLength,
|
|
56
|
-
termSimilarity:
|
|
57
|
-
options.ranking?.termSimilarity ?? DEFAULT_RANKING.termSimilarity,
|
|
58
|
-
termSaturation:
|
|
59
|
-
options.ranking?.termSaturation ?? DEFAULT_RANKING.termSaturation,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return pagefind;
|
|
64
|
-
},
|
|
65
|
-
enabled: typeof window !== "undefined",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (result.isError && result.error.message !== "NOT_BUILT_YET") {
|
|
69
|
-
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
70
|
-
console.error(result.error);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return { ...result, pagefind };
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const PagefindSearch = ({
|
|
77
|
-
isOpen,
|
|
78
|
-
onClose,
|
|
79
|
-
options,
|
|
80
|
-
}: {
|
|
81
|
-
isOpen: boolean;
|
|
82
|
-
onClose: () => void;
|
|
83
|
-
options: PagefindOptions;
|
|
84
|
-
}) => {
|
|
85
|
-
const { pagefind, error, isError } = usePagefind(options);
|
|
86
|
-
const [searchTerm, setSearchTerm] = useState("");
|
|
87
|
-
const [selectedValue, setSelectedValue] = useState<string>("");
|
|
88
|
-
const auth = useAuthState();
|
|
89
|
-
const context = useZudoku();
|
|
90
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
91
|
-
|
|
92
|
-
const { data: searchResults } = useQuery({
|
|
93
|
-
queryKey: ["pagefind-search", searchTerm, auth.isAuthenticated],
|
|
94
|
-
queryFn: async () => {
|
|
95
|
-
const filters = auth.isAuthenticated
|
|
96
|
-
? undefined
|
|
97
|
-
: { not: { section: SEARCH_PROTECTED_SECTION } };
|
|
98
|
-
|
|
99
|
-
const search = await pagefind?.search(searchTerm, { filters });
|
|
100
|
-
if (!search) return [];
|
|
101
|
-
return getResults({ search, options, auth, context });
|
|
102
|
-
},
|
|
103
|
-
placeholderData: keepPreviousData,
|
|
104
|
-
enabled: !!pagefind && !!searchTerm,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
if (!searchResults?.length) return;
|
|
109
|
-
|
|
110
|
-
const firstResult = searchResults.at(0);
|
|
111
|
-
if (!firstResult) return;
|
|
112
|
-
|
|
113
|
-
const firstValue = `${firstResult.meta.title}-${firstResult.url}`;
|
|
114
|
-
setSelectedValue(firstValue);
|
|
115
|
-
}, [searchResults]);
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<CommandDialog
|
|
119
|
-
command={{
|
|
120
|
-
shouldFilter: false,
|
|
121
|
-
loop: true,
|
|
122
|
-
value: selectedValue,
|
|
123
|
-
onValueChange: setSelectedValue,
|
|
124
|
-
}}
|
|
125
|
-
content={{ className: "max-w-[750px]" }}
|
|
126
|
-
open={isOpen}
|
|
127
|
-
onOpenChange={onClose}
|
|
128
|
-
>
|
|
129
|
-
<VisuallyHidden>
|
|
130
|
-
<DialogTitle>Search</DialogTitle>
|
|
131
|
-
</VisuallyHidden>
|
|
132
|
-
<CommandInput
|
|
133
|
-
ref={inputRef}
|
|
134
|
-
placeholder="Search..."
|
|
135
|
-
value={searchTerm}
|
|
136
|
-
onValueChange={setSearchTerm}
|
|
137
|
-
disabled={isError}
|
|
138
|
-
/>
|
|
139
|
-
<CommandEmpty>
|
|
140
|
-
{searchTerm ? (
|
|
141
|
-
<div className="flex flex-col items-center">
|
|
142
|
-
No results found.
|
|
143
|
-
<Button
|
|
144
|
-
variant="link"
|
|
145
|
-
onClick={() => {
|
|
146
|
-
setSearchTerm("");
|
|
147
|
-
inputRef.current?.focus();
|
|
148
|
-
}}
|
|
149
|
-
>
|
|
150
|
-
Clear search
|
|
151
|
-
</Button>
|
|
152
|
-
</div>
|
|
153
|
-
) : (
|
|
154
|
-
"Start typing to search"
|
|
155
|
-
)}
|
|
156
|
-
</CommandEmpty>
|
|
157
|
-
{isError && error.message !== "NOT_BUILT_YET" ? (
|
|
158
|
-
<div className="p-4 text-sm">
|
|
159
|
-
An error occurred while loading search.
|
|
160
|
-
</div>
|
|
161
|
-
) : (
|
|
162
|
-
<>
|
|
163
|
-
<ResultList
|
|
164
|
-
basePath={context.options.basePath}
|
|
165
|
-
searchResults={searchResults ?? []}
|
|
166
|
-
searchTerm={searchTerm}
|
|
167
|
-
onClose={onClose}
|
|
168
|
-
maxSubResults={options.maxSubResults}
|
|
169
|
-
/>
|
|
170
|
-
<div className="flex justify-between p-2 items-center">
|
|
171
|
-
<div className="flex items-center text-xs text-muted-foreground">
|
|
172
|
-
<KbdGroup className="ms-0 me-1">
|
|
173
|
-
<Kbd>↑</Kbd>
|
|
174
|
-
<Kbd>↓</Kbd>
|
|
175
|
-
</KbdGroup>
|
|
176
|
-
Navigate
|
|
177
|
-
<KbdGroup className="ms-4 me-1">
|
|
178
|
-
<Kbd>↵</Kbd>
|
|
179
|
-
</KbdGroup>
|
|
180
|
-
Select
|
|
181
|
-
<KbdGroup className="ms-4 me-1">
|
|
182
|
-
<Kbd>Esc</Kbd>
|
|
183
|
-
</KbdGroup>
|
|
184
|
-
Close dialog
|
|
185
|
-
</div>
|
|
186
|
-
{import.meta.env.DEV && (
|
|
187
|
-
<IndexingDialog>
|
|
188
|
-
<Button
|
|
189
|
-
variant="outline"
|
|
190
|
-
className="h-7 text-xs text-muted-foreground"
|
|
191
|
-
>
|
|
192
|
-
<ListPlusIcon />
|
|
193
|
-
Build Search Index
|
|
194
|
-
</Button>
|
|
195
|
-
</IndexingDialog>
|
|
196
|
-
)}
|
|
197
|
-
</div>
|
|
198
|
-
</>
|
|
199
|
-
)}
|
|
200
|
-
</CommandDialog>
|
|
201
|
-
);
|
|
202
|
-
};
|
|
1
|
+
import { Button } from "@lukoweb/apitogo/ui/Button.js";
|
|
2
|
+
import {
|
|
3
|
+
CommandDialog,
|
|
4
|
+
CommandEmpty,
|
|
5
|
+
CommandInput,
|
|
6
|
+
} from "@lukoweb/apitogo/ui/Command.js";
|
|
7
|
+
import { DialogTitle } from "@lukoweb/apitogo/ui/Dialog.js";
|
|
8
|
+
import { Kbd, KbdGroup } from "@lukoweb/apitogo/ui/Kbd.js";
|
|
9
|
+
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
|
|
10
|
+
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
|
11
|
+
import { ListPlusIcon } from "lucide-react";
|
|
12
|
+
import { lazy, useEffect, useRef, useState } from "react";
|
|
13
|
+
import { useAuthState } from "../../authentication/state.js";
|
|
14
|
+
import { useZudoku } from "../../components/context/ZudokuContext.js";
|
|
15
|
+
import { SEARCH_PROTECTED_SECTION } from "../../core/RouteGuard.js";
|
|
16
|
+
import { joinUrl } from "../../util/joinUrl.js";
|
|
17
|
+
import { getResults } from "./get-results.js";
|
|
18
|
+
import type { PagefindOptions } from "./index.js";
|
|
19
|
+
import { ResultList } from "./ResultList.js";
|
|
20
|
+
import type { Pagefind } from "./types.js";
|
|
21
|
+
|
|
22
|
+
const IndexingDialog = lazy(() => import("./IndexingDialog.js"));
|
|
23
|
+
|
|
24
|
+
const DEFAULT_RANKING = {
|
|
25
|
+
// Slightly lower than default because API docs tend to have repetitive terms (parameter names, HTTP methods, etc.)
|
|
26
|
+
termFrequency: 0.8,
|
|
27
|
+
// Lower than default because API documentation pages tend to be longer due to comprehensive endpoint documentation
|
|
28
|
+
pageLength: 0.6,
|
|
29
|
+
// Slightly higher than default because in technical documentation, exact matches should be prioritized
|
|
30
|
+
termSimilarity: 1.2,
|
|
31
|
+
// Slightly lower than default because API docs might have legitimate repetition of terms
|
|
32
|
+
termSaturation: 1.2,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const importPagefind = (basePath?: string): Promise<Pagefind> =>
|
|
36
|
+
import.meta.env.DEV
|
|
37
|
+
? // @ts-expect-error TypeScript can't resolve the import
|
|
38
|
+
import(/* @vite-ignore */ "/pagefind/pagefind.js")
|
|
39
|
+
: import(/* @vite-ignore */ joinUrl(basePath, "/pagefind/pagefind.js"));
|
|
40
|
+
|
|
41
|
+
const usePagefind = (options: PagefindOptions) => {
|
|
42
|
+
const {
|
|
43
|
+
options: { basePath },
|
|
44
|
+
} = useZudoku();
|
|
45
|
+
const { data: pagefind, ...result } = useQuery<Pagefind>({
|
|
46
|
+
queryKey: ["pagefind", options.ranking],
|
|
47
|
+
retry: false,
|
|
48
|
+
queryFn: async () => {
|
|
49
|
+
const pagefind = await importPagefind(basePath);
|
|
50
|
+
await pagefind.init();
|
|
51
|
+
await pagefind.options({
|
|
52
|
+
ranking: {
|
|
53
|
+
termFrequency:
|
|
54
|
+
options.ranking?.termFrequency ?? DEFAULT_RANKING.termFrequency,
|
|
55
|
+
pageLength: options.ranking?.pageLength ?? DEFAULT_RANKING.pageLength,
|
|
56
|
+
termSimilarity:
|
|
57
|
+
options.ranking?.termSimilarity ?? DEFAULT_RANKING.termSimilarity,
|
|
58
|
+
termSaturation:
|
|
59
|
+
options.ranking?.termSaturation ?? DEFAULT_RANKING.termSaturation,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return pagefind;
|
|
64
|
+
},
|
|
65
|
+
enabled: typeof window !== "undefined",
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (result.isError && result.error.message !== "NOT_BUILT_YET") {
|
|
69
|
+
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
70
|
+
console.error(result.error);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { ...result, pagefind };
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const PagefindSearch = ({
|
|
77
|
+
isOpen,
|
|
78
|
+
onClose,
|
|
79
|
+
options,
|
|
80
|
+
}: {
|
|
81
|
+
isOpen: boolean;
|
|
82
|
+
onClose: () => void;
|
|
83
|
+
options: PagefindOptions;
|
|
84
|
+
}) => {
|
|
85
|
+
const { pagefind, error, isError } = usePagefind(options);
|
|
86
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
87
|
+
const [selectedValue, setSelectedValue] = useState<string>("");
|
|
88
|
+
const auth = useAuthState();
|
|
89
|
+
const context = useZudoku();
|
|
90
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
91
|
+
|
|
92
|
+
const { data: searchResults } = useQuery({
|
|
93
|
+
queryKey: ["pagefind-search", searchTerm, auth.isAuthenticated],
|
|
94
|
+
queryFn: async () => {
|
|
95
|
+
const filters = auth.isAuthenticated
|
|
96
|
+
? undefined
|
|
97
|
+
: { not: { section: SEARCH_PROTECTED_SECTION } };
|
|
98
|
+
|
|
99
|
+
const search = await pagefind?.search(searchTerm, { filters });
|
|
100
|
+
if (!search) return [];
|
|
101
|
+
return getResults({ search, options, auth, context });
|
|
102
|
+
},
|
|
103
|
+
placeholderData: keepPreviousData,
|
|
104
|
+
enabled: !!pagefind && !!searchTerm,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (!searchResults?.length) return;
|
|
109
|
+
|
|
110
|
+
const firstResult = searchResults.at(0);
|
|
111
|
+
if (!firstResult) return;
|
|
112
|
+
|
|
113
|
+
const firstValue = `${firstResult.meta.title}-${firstResult.url}`;
|
|
114
|
+
setSelectedValue(firstValue);
|
|
115
|
+
}, [searchResults]);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<CommandDialog
|
|
119
|
+
command={{
|
|
120
|
+
shouldFilter: false,
|
|
121
|
+
loop: true,
|
|
122
|
+
value: selectedValue,
|
|
123
|
+
onValueChange: setSelectedValue,
|
|
124
|
+
}}
|
|
125
|
+
content={{ className: "max-w-[750px]" }}
|
|
126
|
+
open={isOpen}
|
|
127
|
+
onOpenChange={onClose}
|
|
128
|
+
>
|
|
129
|
+
<VisuallyHidden>
|
|
130
|
+
<DialogTitle>Search</DialogTitle>
|
|
131
|
+
</VisuallyHidden>
|
|
132
|
+
<CommandInput
|
|
133
|
+
ref={inputRef}
|
|
134
|
+
placeholder="Search..."
|
|
135
|
+
value={searchTerm}
|
|
136
|
+
onValueChange={setSearchTerm}
|
|
137
|
+
disabled={isError}
|
|
138
|
+
/>
|
|
139
|
+
<CommandEmpty>
|
|
140
|
+
{searchTerm ? (
|
|
141
|
+
<div className="flex flex-col items-center">
|
|
142
|
+
No results found.
|
|
143
|
+
<Button
|
|
144
|
+
variant="link"
|
|
145
|
+
onClick={() => {
|
|
146
|
+
setSearchTerm("");
|
|
147
|
+
inputRef.current?.focus();
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
Clear search
|
|
151
|
+
</Button>
|
|
152
|
+
</div>
|
|
153
|
+
) : (
|
|
154
|
+
"Start typing to search"
|
|
155
|
+
)}
|
|
156
|
+
</CommandEmpty>
|
|
157
|
+
{isError && error.message !== "NOT_BUILT_YET" ? (
|
|
158
|
+
<div className="p-4 text-sm">
|
|
159
|
+
An error occurred while loading search.
|
|
160
|
+
</div>
|
|
161
|
+
) : (
|
|
162
|
+
<>
|
|
163
|
+
<ResultList
|
|
164
|
+
basePath={context.options.basePath}
|
|
165
|
+
searchResults={searchResults ?? []}
|
|
166
|
+
searchTerm={searchTerm}
|
|
167
|
+
onClose={onClose}
|
|
168
|
+
maxSubResults={options.maxSubResults}
|
|
169
|
+
/>
|
|
170
|
+
<div className="flex justify-between p-2 items-center">
|
|
171
|
+
<div className="flex items-center text-xs text-muted-foreground">
|
|
172
|
+
<KbdGroup className="ms-0 me-1">
|
|
173
|
+
<Kbd>↑</Kbd>
|
|
174
|
+
<Kbd>↓</Kbd>
|
|
175
|
+
</KbdGroup>
|
|
176
|
+
Navigate
|
|
177
|
+
<KbdGroup className="ms-4 me-1">
|
|
178
|
+
<Kbd>↵</Kbd>
|
|
179
|
+
</KbdGroup>
|
|
180
|
+
Select
|
|
181
|
+
<KbdGroup className="ms-4 me-1">
|
|
182
|
+
<Kbd>Esc</Kbd>
|
|
183
|
+
</KbdGroup>
|
|
184
|
+
Close dialog
|
|
185
|
+
</div>
|
|
186
|
+
{import.meta.env.DEV && (
|
|
187
|
+
<IndexingDialog>
|
|
188
|
+
<Button
|
|
189
|
+
variant="outline"
|
|
190
|
+
className="h-7 text-xs text-muted-foreground"
|
|
191
|
+
>
|
|
192
|
+
<ListPlusIcon />
|
|
193
|
+
Build Search Index
|
|
194
|
+
</Button>
|
|
195
|
+
</IndexingDialog>
|
|
196
|
+
)}
|
|
197
|
+
</div>
|
|
198
|
+
</>
|
|
199
|
+
)}
|
|
200
|
+
</CommandDialog>
|
|
201
|
+
);
|
|
202
|
+
};
|
|
@@ -1,118 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
(sum, loc) => sum + loc.balanced_score,
|
|
15
|
-
0,
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
1
|
+
import {
|
|
2
|
+
CommandGroup,
|
|
3
|
+
CommandItem,
|
|
4
|
+
CommandList,
|
|
5
|
+
} from "@lukoweb/apitogo/ui/Command.js";
|
|
6
|
+
import { BracketsIcon, FileTextIcon } from "lucide-react";
|
|
7
|
+
import { useLayoutEffect, useRef } from "react";
|
|
8
|
+
import { Link, useNavigate } from "react-router";
|
|
9
|
+
import { joinUrl } from "../../util/joinUrl.js";
|
|
10
|
+
import type { PagefindSearchFragment, PagefindSubResult } from "./types.js";
|
|
11
|
+
|
|
12
|
+
const sortSubResults = (a: PagefindSubResult, b: PagefindSubResult) => {
|
|
13
|
+
const aScore = a.weighted_locations.reduce(
|
|
14
|
+
(sum, loc) => sum + loc.balanced_score,
|
|
15
|
+
0,
|
|
16
|
+
);
|
|
17
|
+
const bScore = b.weighted_locations.reduce(
|
|
18
|
+
(sum, loc) => sum + loc.balanced_score,
|
|
19
|
+
0,
|
|
20
|
+
);
|
|
21
|
+
return bScore - aScore;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const hoverClassname = `cursor-pointer border border-transparent data-[selected=true]:border-border`;
|
|
25
|
+
|
|
26
|
+
export const ResultList = ({
|
|
27
|
+
basePath,
|
|
28
|
+
searchResults,
|
|
29
|
+
searchTerm,
|
|
30
|
+
onClose,
|
|
31
|
+
maxSubResults = 4,
|
|
32
|
+
}: {
|
|
33
|
+
basePath?: string;
|
|
34
|
+
searchResults: PagefindSearchFragment[];
|
|
35
|
+
searchTerm: string;
|
|
36
|
+
onClose: () => void;
|
|
37
|
+
maxSubResults?: number;
|
|
38
|
+
}) => {
|
|
39
|
+
const navigate = useNavigate();
|
|
40
|
+
const commandListRef = useRef<HTMLDivElement | null>(null);
|
|
41
|
+
|
|
42
|
+
useLayoutEffect(() => {
|
|
43
|
+
if (!searchTerm) return;
|
|
44
|
+
requestAnimationFrame(() => {
|
|
45
|
+
commandListRef.current?.scrollTo({ top: 0 });
|
|
46
|
+
});
|
|
47
|
+
}, [searchTerm]);
|
|
48
|
+
|
|
49
|
+
const stripBasePath = (url: string) => {
|
|
50
|
+
if (basePath && url.startsWith(basePath)) {
|
|
51
|
+
return joinUrl(url.slice(basePath.length));
|
|
52
|
+
}
|
|
53
|
+
return url;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<CommandList className="max-h-[450px]" ref={commandListRef}>
|
|
58
|
+
{searchTerm && searchResults.length > 0 && (
|
|
59
|
+
<CommandGroup
|
|
60
|
+
className="text-sm text-muted-foreground"
|
|
61
|
+
heading={`${searchResults.length} results for "${searchTerm}"`}
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
{searchTerm &&
|
|
65
|
+
searchResults.map((result) => (
|
|
66
|
+
<CommandGroup
|
|
67
|
+
key={[result.meta.title ?? result.excerpt, result.url].join("-")}
|
|
68
|
+
>
|
|
69
|
+
<CommandItem
|
|
70
|
+
asChild
|
|
71
|
+
value={`${result.meta.title}-${result.url}`}
|
|
72
|
+
className={hoverClassname}
|
|
73
|
+
onSelect={() => {
|
|
74
|
+
void navigate(stripBasePath(result.url));
|
|
75
|
+
onClose();
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
<Link to={stripBasePath(result.url)}>
|
|
79
|
+
{result.meta.section === "openapi" ? (
|
|
80
|
+
<BracketsIcon />
|
|
81
|
+
) : (
|
|
82
|
+
<FileTextIcon />
|
|
83
|
+
)}
|
|
84
|
+
{result.meta.category && (
|
|
85
|
+
<span className="text-muted-foreground">
|
|
86
|
+
{result.meta.category} ›{" "}
|
|
87
|
+
</span>
|
|
88
|
+
)}
|
|
89
|
+
{result.meta.title}
|
|
90
|
+
</Link>
|
|
91
|
+
</CommandItem>
|
|
92
|
+
{result.sub_results
|
|
93
|
+
.sort(sortSubResults)
|
|
94
|
+
.slice(0, maxSubResults)
|
|
95
|
+
.map((subResult) => (
|
|
96
|
+
<CommandItem
|
|
97
|
+
asChild
|
|
98
|
+
key={`sub-${result.meta.title}-${subResult.url}`}
|
|
99
|
+
value={`sub-${result.meta.title}-${subResult.url}`}
|
|
100
|
+
className={hoverClassname}
|
|
101
|
+
onSelect={() => {
|
|
102
|
+
void navigate(stripBasePath(subResult.url));
|
|
103
|
+
onClose();
|
|
104
|
+
}}
|
|
105
|
+
>
|
|
106
|
+
<Link to={stripBasePath(subResult.url)} onClick={onClose}>
|
|
107
|
+
<div className="flex flex-col items-start gap-2 ms-2.5 ps-5 border-l border-muted-foreground/50">
|
|
108
|
+
<span className="font-bold">{subResult.title}</span>
|
|
109
|
+
<span
|
|
110
|
+
className="line-clamp-2 text-[13px] [&_mark]:bg-primary [&_mark]:text-primary-foreground"
|
|
111
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: Pagefind provides sanitized HTML
|
|
112
|
+
dangerouslySetInnerHTML={{ __html: subResult.excerpt }}
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
</Link>
|
|
116
|
+
</CommandItem>
|
|
117
|
+
))}
|
|
118
|
+
</CommandGroup>
|
|
119
|
+
))}
|
|
120
|
+
</CommandList>
|
|
121
|
+
);
|
|
122
|
+
};
|