@lukoweb/apitogo 0.1.1 → 0.1.2

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.
Files changed (91) hide show
  1. package/dist/cli/cli.js +17 -6
  2. package/dist/declarations/lib/ui/Command.d.ts +1 -1
  3. package/dist/declarations/lib/util/MdxComponents.d.ts +1 -1
  4. package/package.json +1 -1
  5. package/src/app/main.tsx +150 -150
  6. package/src/config/loader.ts +245 -245
  7. package/src/index.ts +33 -33
  8. package/src/lib/authentication/components/CallbackHandler.tsx +45 -45
  9. package/src/lib/authentication/components/SignIn.tsx +46 -46
  10. package/src/lib/authentication/components/SignUp.tsx +48 -48
  11. package/src/lib/authentication/providers/clerk.tsx +224 -224
  12. package/src/lib/authentication/ui/AuthCard.tsx +7 -7
  13. package/src/lib/authentication/ui/EmailLinkCallbackUi.tsx +129 -125
  14. package/src/lib/authentication/ui/EmailLinkSentUi.tsx +105 -101
  15. package/src/lib/authentication/ui/EmailLinkSignInUi.tsx +100 -96
  16. package/src/lib/authentication/ui/EmailVerificationUi.tsx +128 -124
  17. package/src/lib/authentication/ui/ZudokuAuthUi.tsx +620 -616
  18. package/src/lib/components/AiAssistantMenuItems.tsx +102 -102
  19. package/src/lib/components/Autocomplete.tsx +123 -123
  20. package/src/lib/components/DeveloperHint.tsx +39 -35
  21. package/src/lib/components/Header.tsx +260 -260
  22. package/src/lib/components/Layout.tsx +53 -53
  23. package/src/lib/components/Main.tsx +51 -51
  24. package/src/lib/components/Mermaid.tsx +74 -70
  25. package/src/lib/components/MobileTopNavigation.tsx +276 -276
  26. package/src/lib/components/MultiSelect.tsx +86 -82
  27. package/src/lib/components/TopNavigation.tsx +103 -103
  28. package/src/lib/components/index.ts +26 -26
  29. package/src/lib/components/navigation/NavigationCategory.tsx +157 -157
  30. package/src/lib/components/navigation/NavigationFilterInput.tsx +35 -35
  31. package/src/lib/components/navigation/NavigationItem.tsx +181 -177
  32. package/src/lib/core/RouteGuard.tsx +193 -193
  33. package/src/lib/errors/ErrorMessage.tsx +50 -46
  34. package/src/lib/plugins/api-catalog/Catalog.tsx +80 -80
  35. package/src/lib/plugins/api-keys/CreateApiKey.tsx +128 -124
  36. package/src/lib/plugins/api-keys/CreateApiKeyDialog.tsx +49 -49
  37. package/src/lib/plugins/api-keys/SettingsApiKeys.tsx +72 -72
  38. package/src/lib/plugins/api-keys/settings/ApiKeyItem.tsx +342 -342
  39. package/src/lib/plugins/api-keys/settings/RevealApiKey.tsx +127 -127
  40. package/src/lib/plugins/markdown/MdxPage.tsx +285 -285
  41. package/src/lib/plugins/openapi/ApiHeader.tsx +96 -96
  42. package/src/lib/plugins/openapi/CollapsibleCode.tsx +88 -88
  43. package/src/lib/plugins/openapi/DownloadSchemaButton.tsx +94 -94
  44. package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -52
  45. package/src/lib/plugins/openapi/OperationListItem.tsx +183 -183
  46. package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +63 -63
  47. package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +120 -117
  48. package/src/lib/plugins/openapi/SchemaInfo.tsx +344 -344
  49. package/src/lib/plugins/openapi/SchemaList.tsx +113 -113
  50. package/src/lib/plugins/openapi/Sidecar.tsx +312 -309
  51. package/src/lib/plugins/openapi/SidecarExamples.tsx +177 -174
  52. package/src/lib/plugins/openapi/components/EnumValues.tsx +58 -58
  53. package/src/lib/plugins/openapi/components/ResponseContent.tsx +117 -114
  54. package/src/lib/plugins/openapi/playground/BodyPanel.tsx +274 -271
  55. package/src/lib/plugins/openapi/playground/CollapsibleHeader.tsx +51 -51
  56. package/src/lib/plugins/openapi/playground/ExamplesDropdown.tsx +60 -60
  57. package/src/lib/plugins/openapi/playground/Headers.tsx +188 -181
  58. package/src/lib/plugins/openapi/playground/IdentityDialog.tsx +75 -75
  59. package/src/lib/plugins/openapi/playground/IdentitySelector.tsx +38 -38
  60. package/src/lib/plugins/openapi/playground/ParamsGrid.tsx +45 -45
  61. package/src/lib/plugins/openapi/playground/Playground.tsx +602 -599
  62. package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +56 -56
  63. package/src/lib/plugins/openapi/playground/QueryParams.tsx +151 -148
  64. package/src/lib/plugins/openapi/playground/RequestLoginDialog.tsx +70 -70
  65. package/src/lib/plugins/openapi/playground/request-panel/MultipartField.tsx +91 -91
  66. package/src/lib/plugins/openapi/playground/result-panel/AudioPlayer.tsx +50 -50
  67. package/src/lib/plugins/openapi/playground/result-panel/ResponseTab.tsx +355 -355
  68. package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +106 -102
  69. package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +189 -184
  70. package/src/lib/plugins/openapi/schema/SchemaView.tsx +299 -299
  71. package/src/lib/plugins/search-pagefind/IndexingDialog.tsx +162 -162
  72. package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +202 -202
  73. package/src/lib/plugins/search-pagefind/ResultList.tsx +122 -118
  74. package/src/lib/ui/ActionButton.tsx +21 -21
  75. package/src/lib/ui/Command.tsx +191 -191
  76. package/src/lib/util/MdxComponents.tsx +150 -150
  77. package/src/vite/config.ts +234 -231
  78. package/src/vite/dev-server.ts +291 -291
  79. package/src/vite/plugin-api-keys.ts +50 -50
  80. package/src/vite/plugin-api.ts +320 -318
  81. package/src/vite/plugin-auth.ts +38 -38
  82. package/src/vite/plugin-component.ts +45 -39
  83. package/src/vite/plugin-config.ts +75 -75
  84. package/src/vite/plugin-custom-pages.ts +36 -36
  85. package/src/vite/plugin-docs.ts +202 -202
  86. package/src/vite/plugin-markdown-export.ts +214 -214
  87. package/src/vite/plugin-mdx.ts +149 -149
  88. package/src/vite/plugin-navigation.ts +106 -106
  89. package/src/vite/plugin-search.ts +47 -47
  90. package/src/vite/plugin.ts +42 -42
  91. package/src/vite/prerender/prerender.ts +233 -233
@@ -1,309 +1,312 @@
1
- import { useMemo, useState, useTransition } from "react";
2
- import { useSearchParams } from "react-router";
3
- import { useZudoku } from "@lukoweb/apitogo/hooks";
4
- import { Badge } from "@lukoweb/apitogo/ui/Badge.js";
5
- import { NativeSelect, NativeSelectOption } from "@lukoweb/apitogo/ui/NativeSelect.js";
6
- import { SyntaxHighlight } from "@lukoweb/apitogo/ui/SyntaxHighlight.js";
7
- import { useAuthState } from "../../authentication/state.js";
8
- import { PathRenderer } from "../../components/PathRenderer.js";
9
- import { cn } from "../../util/cn.js";
10
- import { useOnScreen } from "../../util/useOnScreen.js";
11
- import { ColorizedParam } from "./ColorizedParam.js";
12
- import { NonHighlightedCode } from "./components/NonHighlightedCode.js";
13
- import { useOasConfig } from "./context.js";
14
- import { GeneratedExampleSidecarBox } from "./GeneratedExampleSidecarBox.js";
15
- import type { OperationsFragmentFragment } from "./graphql/graphql.js";
16
- import { graphql } from "./graphql/index.js";
17
- import { PlaygroundDialogWrapper } from "./PlaygroundDialogWrapper.js";
18
- import { RequestBodySidecarBox } from "./RequestBodySidecarBox.js";
19
- import { ResponsesSidecarBox } from "./ResponsesSidecarBox.js";
20
- import * as SidecarBox from "./SidecarBox.js";
21
- import { createHttpSnippet, getConverted } from "./util/createHttpSnippet.js";
22
- import { generateSchemaExample } from "./util/generateSchemaExample.js";
23
- import { methodForColor } from "./util/methodToColor.js";
24
-
25
- export const GetServerQuery = graphql(/* GraphQL */ `
26
- query getServerQuery($input: JSON!, $type: SchemaType!) {
27
- schema(input: $input, type: $type) {
28
- url
29
- servers {
30
- url
31
- }
32
- }
33
- }
34
- `);
35
-
36
- const EXAMPLE_LANGUAGES = [
37
- { value: "shell", label: "cURL" },
38
- { value: "js", label: "JavaScript" },
39
- { value: "python", label: "Python" },
40
- { value: "java", label: "Java" },
41
- { value: "go", label: "Go" },
42
- { value: "csharp", label: "C#" },
43
- { value: "kotlin", label: "Kotlin" },
44
- { value: "objc", label: "Objective-C" },
45
- { value: "php", label: "PHP" },
46
- { value: "ruby", label: "Ruby" },
47
- { value: "swift", label: "Swift" },
48
- ];
49
-
50
- export const Sidecar = ({
51
- operation,
52
- selectedResponse,
53
- globalSelectedServer,
54
- shouldLazyHighlight,
55
- }: {
56
- operation: OperationsFragmentFragment;
57
- selectedResponse?: string;
58
- globalSelectedServer?: string;
59
- shouldLazyHighlight?: boolean;
60
- }) => {
61
- const { options } = useOasConfig();
62
- const auth = useAuthState();
63
- const context = useZudoku();
64
-
65
- const methodTextColor = methodForColor(operation.method);
66
-
67
- const [searchParams, setSearchParams] = useSearchParams();
68
- const [, startTransition] = useTransition();
69
-
70
- const supportedLanguages = options?.supportedLanguages ?? EXAMPLE_LANGUAGES;
71
-
72
- const preferredLang =
73
- searchParams.get("lang") ?? options?.examplesLanguage ?? "shell";
74
-
75
- const selectedLang =
76
- supportedLanguages.find((lang) => lang.value === preferredLang)?.value ??
77
- supportedLanguages.at(0)?.value ??
78
- "shell";
79
-
80
- const requestBodyContent = operation.requestBody?.content;
81
- const transformedRequestBodyContent =
82
- requestBodyContent && options?.transformExamples
83
- ? options.transformExamples({
84
- auth,
85
- type: "request",
86
- operation,
87
- content: requestBodyContent,
88
- context,
89
- })
90
- : requestBodyContent;
91
-
92
- const [selectedRequestExample, setSelectedRequestExample] = useState<{
93
- contentTypeIndex: number;
94
- exampleIndex: number;
95
- }>({
96
- contentTypeIndex: 0,
97
- exampleIndex: 0,
98
- });
99
-
100
- const selectedContent = transformedRequestBodyContent?.at(
101
- selectedRequestExample.contentTypeIndex,
102
- );
103
- const currentExample = selectedContent?.examples?.at(
104
- selectedRequestExample.exampleIndex,
105
- );
106
-
107
- const currentExampleCode = currentExample
108
- ? (currentExample?.value ?? currentExample)
109
- : selectedContent?.schema
110
- ? generateSchemaExample(selectedContent?.schema)
111
- : undefined;
112
-
113
- const path = (
114
- <PathRenderer
115
- path={operation.path}
116
- renderParam={({ name }) => (
117
- <ColorizedParam
118
- name={name}
119
- backgroundOpacity="0"
120
- className="py-px px-0.5"
121
- // same as in `ParameterListItem`
122
- slug={`${operation.slug}-${name}`}
123
- >
124
- {`{${name}}`}
125
- </ColorizedParam>
126
- )}
127
- />
128
- );
129
-
130
- // Manual server selection takes precedence over the server hierarchy.
131
- // If no manual selection, fall back to operation's first server (already respects operation > path > global hierarchy)
132
- const selectedServer =
133
- globalSelectedServer || operation.servers.at(0)?.url || "";
134
-
135
- const httpSnippetCode = useMemo<string | undefined>(() => {
136
- const converted = options?.generateCodeSnippet?.({
137
- selectedLang,
138
- selectedServer,
139
- context,
140
- operation,
141
- example: currentExampleCode,
142
- auth,
143
- });
144
-
145
- if (converted) return converted;
146
-
147
- const snippet = createHttpSnippet({
148
- operation,
149
- selectedServer,
150
- exampleBody: currentExampleCode
151
- ? {
152
- mimeType: selectedContent?.mediaType ?? "application/json",
153
- text: JSON.stringify(currentExampleCode, null, 2),
154
- }
155
- : { mimeType: selectedContent?.mediaType ?? "application/json" },
156
- });
157
-
158
- return getConverted(snippet, selectedLang);
159
- }, [
160
- currentExampleCode,
161
- operation,
162
- selectedServer,
163
- selectedLang,
164
- selectedContent,
165
- options,
166
- auth,
167
- context,
168
- ]);
169
-
170
- const [ref, isOnScreen] = useOnScreen({ rootMargin: "200px 0px 200px 0px" });
171
-
172
- const showPlayground =
173
- isOnScreen &&
174
- (operation.extensions["x-explorer-enabled"] === true ||
175
- operation.extensions["x-zudoku-playground-enabled"] === true ||
176
- (operation.extensions["x-explorer-enabled"] === undefined &&
177
- operation.extensions["x-zudoku-playground-enabled"] === undefined &&
178
- !options?.disablePlayground));
179
-
180
- const hasResponseExamples = operation.responses.some((response) =>
181
- response.content?.some((content) => (content.examples?.length ?? 0) > 0),
182
- );
183
-
184
- return (
185
- <aside
186
- ref={ref}
187
- className="flex flex-col sticky top-(--scroll-padding) gap-4"
188
- data-pagefind-ignore="all"
189
- >
190
- <SidecarBox.Root>
191
- <SidecarBox.Head className="py-1.5">
192
- <div className="flex items-center flex-wrap gap-2 justify-between w-full">
193
- <span className="font-mono wrap-break-word leading-6 space-x-1">
194
- <Badge
195
- variant="outline"
196
- className={cn(
197
- methodTextColor,
198
- "px-1.5 rounded-md border-none bg-current/7 dark:bg-current/15",
199
- )}
200
- >
201
- {operation.method.toUpperCase()}
202
- </Badge>
203
- {path}
204
- </span>
205
- <div className="flex items-center gap-1">
206
- <NativeSelect
207
- className="py-0.5 h-fit max-w-32 truncate bg-background"
208
- value={selectedLang}
209
- onChange={(e) => {
210
- startTransition(() => {
211
- setSearchParams((prev) => {
212
- prev.set("lang", e.target.value);
213
- return prev;
214
- });
215
- });
216
- }}
217
- >
218
- {supportedLanguages.map((language) => (
219
- <NativeSelectOption
220
- key={language.value}
221
- value={language.value}
222
- >
223
- {language.label}
224
- </NativeSelectOption>
225
- ))}
226
- </NativeSelect>
227
- {showPlayground && (
228
- <PlaygroundDialogWrapper
229
- servers={operation.servers.map((server) => server.url)}
230
- operation={operation}
231
- examples={requestBodyContent ?? undefined}
232
- />
233
- )}
234
- </div>
235
- </div>
236
- </SidecarBox.Head>
237
- <SidecarBox.Body>
238
- {shouldLazyHighlight && !isOnScreen ? (
239
- <NonHighlightedCode code={httpSnippetCode ?? ""} />
240
- ) : (
241
- <SyntaxHighlight
242
- embedded
243
- language={selectedLang}
244
- className="[--scrollbar-color:gray] rounded-none text-xs max-h-[200px]"
245
- // biome-ignore lint/style/noNonNullAssertion: code is guaranteed to be defined
246
- code={httpSnippetCode!}
247
- />
248
- )}
249
- </SidecarBox.Body>
250
- </SidecarBox.Root>
251
-
252
- {transformedRequestBodyContent && currentExample ? (
253
- <RequestBodySidecarBox
254
- content={transformedRequestBodyContent}
255
- onExampleChange={(selected) => {
256
- setSelectedRequestExample(selected);
257
- }}
258
- selectedContentIndex={selectedRequestExample.contentTypeIndex}
259
- selectedExampleIndex={selectedRequestExample.exampleIndex}
260
- isOnScreen={isOnScreen}
261
- shouldLazyHighlight={shouldLazyHighlight}
262
- />
263
- ) : transformedRequestBodyContent && currentExampleCode ? (
264
- <GeneratedExampleSidecarBox
265
- isOnScreen={isOnScreen}
266
- shouldLazyHighlight={shouldLazyHighlight}
267
- code={JSON.stringify(currentExampleCode, null, 2)}
268
- />
269
- ) : null}
270
-
271
- {hasResponseExamples ? (
272
- <ResponsesSidecarBox
273
- isOnScreen={isOnScreen}
274
- shouldLazyHighlight={shouldLazyHighlight}
275
- selectedResponse={selectedResponse}
276
- responses={operation.responses.map((response) => ({
277
- ...response,
278
- content:
279
- response.content && options?.transformExamples
280
- ? options.transformExamples({
281
- auth,
282
- type: "response",
283
- context,
284
- operation,
285
- content: response.content,
286
- })
287
- : response.content,
288
- }))}
289
- />
290
- ) : (
291
- <ResponsesSidecarBox
292
- isGenerated
293
- isOnScreen={isOnScreen}
294
- shouldLazyHighlight={shouldLazyHighlight}
295
- selectedResponse={selectedResponse}
296
- responses={operation.responses.map((response) => ({
297
- ...response,
298
- content: response.content?.map((content) => ({
299
- ...content,
300
- examples: content.schema
301
- ? [{ name: "", value: generateSchemaExample(content.schema) }]
302
- : content.examples,
303
- })),
304
- }))}
305
- />
306
- )}
307
- </aside>
308
- );
309
- };
1
+ import { useZudoku } from "@lukoweb/apitogo/hooks";
2
+ import { Badge } from "@lukoweb/apitogo/ui/Badge.js";
3
+ import {
4
+ NativeSelect,
5
+ NativeSelectOption,
6
+ } from "@lukoweb/apitogo/ui/NativeSelect.js";
7
+ import { SyntaxHighlight } from "@lukoweb/apitogo/ui/SyntaxHighlight.js";
8
+ import { useMemo, useState, useTransition } from "react";
9
+ import { useSearchParams } from "react-router";
10
+ import { useAuthState } from "../../authentication/state.js";
11
+ import { PathRenderer } from "../../components/PathRenderer.js";
12
+ import { cn } from "../../util/cn.js";
13
+ import { useOnScreen } from "../../util/useOnScreen.js";
14
+ import { ColorizedParam } from "./ColorizedParam.js";
15
+ import { NonHighlightedCode } from "./components/NonHighlightedCode.js";
16
+ import { useOasConfig } from "./context.js";
17
+ import { GeneratedExampleSidecarBox } from "./GeneratedExampleSidecarBox.js";
18
+ import type { OperationsFragmentFragment } from "./graphql/graphql.js";
19
+ import { graphql } from "./graphql/index.js";
20
+ import { PlaygroundDialogWrapper } from "./PlaygroundDialogWrapper.js";
21
+ import { RequestBodySidecarBox } from "./RequestBodySidecarBox.js";
22
+ import { ResponsesSidecarBox } from "./ResponsesSidecarBox.js";
23
+ import * as SidecarBox from "./SidecarBox.js";
24
+ import { createHttpSnippet, getConverted } from "./util/createHttpSnippet.js";
25
+ import { generateSchemaExample } from "./util/generateSchemaExample.js";
26
+ import { methodForColor } from "./util/methodToColor.js";
27
+
28
+ export const GetServerQuery = graphql(/* GraphQL */ `
29
+ query getServerQuery($input: JSON!, $type: SchemaType!) {
30
+ schema(input: $input, type: $type) {
31
+ url
32
+ servers {
33
+ url
34
+ }
35
+ }
36
+ }
37
+ `);
38
+
39
+ const EXAMPLE_LANGUAGES = [
40
+ { value: "shell", label: "cURL" },
41
+ { value: "js", label: "JavaScript" },
42
+ { value: "python", label: "Python" },
43
+ { value: "java", label: "Java" },
44
+ { value: "go", label: "Go" },
45
+ { value: "csharp", label: "C#" },
46
+ { value: "kotlin", label: "Kotlin" },
47
+ { value: "objc", label: "Objective-C" },
48
+ { value: "php", label: "PHP" },
49
+ { value: "ruby", label: "Ruby" },
50
+ { value: "swift", label: "Swift" },
51
+ ];
52
+
53
+ export const Sidecar = ({
54
+ operation,
55
+ selectedResponse,
56
+ globalSelectedServer,
57
+ shouldLazyHighlight,
58
+ }: {
59
+ operation: OperationsFragmentFragment;
60
+ selectedResponse?: string;
61
+ globalSelectedServer?: string;
62
+ shouldLazyHighlight?: boolean;
63
+ }) => {
64
+ const { options } = useOasConfig();
65
+ const auth = useAuthState();
66
+ const context = useZudoku();
67
+
68
+ const methodTextColor = methodForColor(operation.method);
69
+
70
+ const [searchParams, setSearchParams] = useSearchParams();
71
+ const [, startTransition] = useTransition();
72
+
73
+ const supportedLanguages = options?.supportedLanguages ?? EXAMPLE_LANGUAGES;
74
+
75
+ const preferredLang =
76
+ searchParams.get("lang") ?? options?.examplesLanguage ?? "shell";
77
+
78
+ const selectedLang =
79
+ supportedLanguages.find((lang) => lang.value === preferredLang)?.value ??
80
+ supportedLanguages.at(0)?.value ??
81
+ "shell";
82
+
83
+ const requestBodyContent = operation.requestBody?.content;
84
+ const transformedRequestBodyContent =
85
+ requestBodyContent && options?.transformExamples
86
+ ? options.transformExamples({
87
+ auth,
88
+ type: "request",
89
+ operation,
90
+ content: requestBodyContent,
91
+ context,
92
+ })
93
+ : requestBodyContent;
94
+
95
+ const [selectedRequestExample, setSelectedRequestExample] = useState<{
96
+ contentTypeIndex: number;
97
+ exampleIndex: number;
98
+ }>({
99
+ contentTypeIndex: 0,
100
+ exampleIndex: 0,
101
+ });
102
+
103
+ const selectedContent = transformedRequestBodyContent?.at(
104
+ selectedRequestExample.contentTypeIndex,
105
+ );
106
+ const currentExample = selectedContent?.examples?.at(
107
+ selectedRequestExample.exampleIndex,
108
+ );
109
+
110
+ const currentExampleCode = currentExample
111
+ ? (currentExample?.value ?? currentExample)
112
+ : selectedContent?.schema
113
+ ? generateSchemaExample(selectedContent?.schema)
114
+ : undefined;
115
+
116
+ const path = (
117
+ <PathRenderer
118
+ path={operation.path}
119
+ renderParam={({ name }) => (
120
+ <ColorizedParam
121
+ name={name}
122
+ backgroundOpacity="0"
123
+ className="py-px px-0.5"
124
+ // same as in `ParameterListItem`
125
+ slug={`${operation.slug}-${name}`}
126
+ >
127
+ {`{${name}}`}
128
+ </ColorizedParam>
129
+ )}
130
+ />
131
+ );
132
+
133
+ // Manual server selection takes precedence over the server hierarchy.
134
+ // If no manual selection, fall back to operation's first server (already respects operation > path > global hierarchy)
135
+ const selectedServer =
136
+ globalSelectedServer || operation.servers.at(0)?.url || "";
137
+
138
+ const httpSnippetCode = useMemo<string | undefined>(() => {
139
+ const converted = options?.generateCodeSnippet?.({
140
+ selectedLang,
141
+ selectedServer,
142
+ context,
143
+ operation,
144
+ example: currentExampleCode,
145
+ auth,
146
+ });
147
+
148
+ if (converted) return converted;
149
+
150
+ const snippet = createHttpSnippet({
151
+ operation,
152
+ selectedServer,
153
+ exampleBody: currentExampleCode
154
+ ? {
155
+ mimeType: selectedContent?.mediaType ?? "application/json",
156
+ text: JSON.stringify(currentExampleCode, null, 2),
157
+ }
158
+ : { mimeType: selectedContent?.mediaType ?? "application/json" },
159
+ });
160
+
161
+ return getConverted(snippet, selectedLang);
162
+ }, [
163
+ currentExampleCode,
164
+ operation,
165
+ selectedServer,
166
+ selectedLang,
167
+ selectedContent,
168
+ options,
169
+ auth,
170
+ context,
171
+ ]);
172
+
173
+ const [ref, isOnScreen] = useOnScreen({ rootMargin: "200px 0px 200px 0px" });
174
+
175
+ const showPlayground =
176
+ isOnScreen &&
177
+ (operation.extensions["x-explorer-enabled"] === true ||
178
+ operation.extensions["x-zudoku-playground-enabled"] === true ||
179
+ (operation.extensions["x-explorer-enabled"] === undefined &&
180
+ operation.extensions["x-zudoku-playground-enabled"] === undefined &&
181
+ !options?.disablePlayground));
182
+
183
+ const hasResponseExamples = operation.responses.some((response) =>
184
+ response.content?.some((content) => (content.examples?.length ?? 0) > 0),
185
+ );
186
+
187
+ return (
188
+ <aside
189
+ ref={ref}
190
+ className="flex flex-col sticky top-(--scroll-padding) gap-4"
191
+ data-pagefind-ignore="all"
192
+ >
193
+ <SidecarBox.Root>
194
+ <SidecarBox.Head className="py-1.5">
195
+ <div className="flex items-center flex-wrap gap-2 justify-between w-full">
196
+ <span className="font-mono wrap-break-word leading-6 space-x-1">
197
+ <Badge
198
+ variant="outline"
199
+ className={cn(
200
+ methodTextColor,
201
+ "px-1.5 rounded-md border-none bg-current/7 dark:bg-current/15",
202
+ )}
203
+ >
204
+ {operation.method.toUpperCase()}
205
+ </Badge>
206
+ {path}
207
+ </span>
208
+ <div className="flex items-center gap-1">
209
+ <NativeSelect
210
+ className="py-0.5 h-fit max-w-32 truncate bg-background"
211
+ value={selectedLang}
212
+ onChange={(e) => {
213
+ startTransition(() => {
214
+ setSearchParams((prev) => {
215
+ prev.set("lang", e.target.value);
216
+ return prev;
217
+ });
218
+ });
219
+ }}
220
+ >
221
+ {supportedLanguages.map((language) => (
222
+ <NativeSelectOption
223
+ key={language.value}
224
+ value={language.value}
225
+ >
226
+ {language.label}
227
+ </NativeSelectOption>
228
+ ))}
229
+ </NativeSelect>
230
+ {showPlayground && (
231
+ <PlaygroundDialogWrapper
232
+ servers={operation.servers.map((server) => server.url)}
233
+ operation={operation}
234
+ examples={requestBodyContent ?? undefined}
235
+ />
236
+ )}
237
+ </div>
238
+ </div>
239
+ </SidecarBox.Head>
240
+ <SidecarBox.Body>
241
+ {shouldLazyHighlight && !isOnScreen ? (
242
+ <NonHighlightedCode code={httpSnippetCode ?? ""} />
243
+ ) : (
244
+ <SyntaxHighlight
245
+ embedded
246
+ language={selectedLang}
247
+ className="[--scrollbar-color:gray] rounded-none text-xs max-h-[200px]"
248
+ // biome-ignore lint/style/noNonNullAssertion: code is guaranteed to be defined
249
+ code={httpSnippetCode!}
250
+ />
251
+ )}
252
+ </SidecarBox.Body>
253
+ </SidecarBox.Root>
254
+
255
+ {transformedRequestBodyContent && currentExample ? (
256
+ <RequestBodySidecarBox
257
+ content={transformedRequestBodyContent}
258
+ onExampleChange={(selected) => {
259
+ setSelectedRequestExample(selected);
260
+ }}
261
+ selectedContentIndex={selectedRequestExample.contentTypeIndex}
262
+ selectedExampleIndex={selectedRequestExample.exampleIndex}
263
+ isOnScreen={isOnScreen}
264
+ shouldLazyHighlight={shouldLazyHighlight}
265
+ />
266
+ ) : transformedRequestBodyContent && currentExampleCode ? (
267
+ <GeneratedExampleSidecarBox
268
+ isOnScreen={isOnScreen}
269
+ shouldLazyHighlight={shouldLazyHighlight}
270
+ code={JSON.stringify(currentExampleCode, null, 2)}
271
+ />
272
+ ) : null}
273
+
274
+ {hasResponseExamples ? (
275
+ <ResponsesSidecarBox
276
+ isOnScreen={isOnScreen}
277
+ shouldLazyHighlight={shouldLazyHighlight}
278
+ selectedResponse={selectedResponse}
279
+ responses={operation.responses.map((response) => ({
280
+ ...response,
281
+ content:
282
+ response.content && options?.transformExamples
283
+ ? options.transformExamples({
284
+ auth,
285
+ type: "response",
286
+ context,
287
+ operation,
288
+ content: response.content,
289
+ })
290
+ : response.content,
291
+ }))}
292
+ />
293
+ ) : (
294
+ <ResponsesSidecarBox
295
+ isGenerated
296
+ isOnScreen={isOnScreen}
297
+ shouldLazyHighlight={shouldLazyHighlight}
298
+ selectedResponse={selectedResponse}
299
+ responses={operation.responses.map((response) => ({
300
+ ...response,
301
+ content: response.content?.map((content) => ({
302
+ ...content,
303
+ examples: content.schema
304
+ ? [{ name: "", value: generateSchemaExample(content.schema) }]
305
+ : content.examples,
306
+ })),
307
+ }))}
308
+ />
309
+ )}
310
+ </aside>
311
+ );
312
+ };