fumadocs-openapi 12.1.1 → 12.2.0

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 (37) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/dist/.translations/index.d.ts +62 -17
  3. package/dist/.translations/keys.js +62 -17
  4. package/dist/operation.d.ts +6 -1
  5. package/dist/operation.js +2 -4
  6. package/dist/packages/shared-api/dist/components/select.js +8 -7
  7. package/dist/playground/auth.d.ts +5 -1
  8. package/dist/playground/auth.js +7 -2
  9. package/dist/playground/fetcher.d.ts +8 -0
  10. package/dist/playground/fetcher.js +30 -1
  11. package/dist/playground/index.d.ts +2 -1
  12. package/dist/playground/index.js +2 -1
  13. package/dist/playground/use-playground.d.ts +62 -0
  14. package/dist/playground/use-playground.js +140 -0
  15. package/dist/ui/components/endpoint.js +37 -0
  16. package/dist/ui/operation/index.js +6 -14
  17. package/dist/ui/playground/client.d.ts +9 -26
  18. package/dist/ui/playground/client.js +149 -389
  19. package/dist/ui/playground/components/fields.js +693 -0
  20. package/dist/ui/playground/components/oauth-panel.js +182 -0
  21. package/dist/ui/playground/components/request-panel.js +480 -0
  22. package/dist/ui/playground/components/response-panel.js +150 -0
  23. package/dist/ui/playground/components/result-display.d.ts +1 -0
  24. package/dist/ui/playground/components/result-display.js +185 -168
  25. package/dist/ui/playground/components/segmented.js +21 -0
  26. package/dist/ui/playground/components/server-select.js +100 -89
  27. package/dist/ui/playground/components/url-bar.js +96 -0
  28. package/dist/ui/playground/status-info.js +32 -45
  29. package/dist/utils/document/load.js +1 -1
  30. package/package.json +10 -10
  31. package/dist/packages/shared-api/dist/components/collapsible.d.ts +0 -7
  32. package/dist/packages/shared-api/dist/components/collapsible.js +0 -16
  33. package/dist/packages/shared-api/dist/components/dialog.js +0 -55
  34. package/dist/packages/shared-api/dist/components/input.js +0 -14
  35. package/dist/packages/shared-api/dist/components/label.js +0 -11
  36. package/dist/packages/shared-api/dist/components/playground/inputs.js +0 -439
  37. package/dist/ui/playground/components/oauth-dialog.js +0 -259
@@ -1,421 +1,181 @@
1
1
  "use client";
2
- import { pathnameFromRequest } from "../../requests/generators/index.js";
3
- import { useQuery } from "../../packages/shared-api/dist/utils/use-query.js";
4
- import { useAuthFields, usePlaygroundAuth } from "../../playground/auth.js";
5
- import { useServer } from "../../utils/use-server.js";
6
2
  import { useOpenAPI } from "../../utils/create-page.js";
7
- import { encodeRequestData } from "../../requests/media/encode.js";
8
3
  import { useExampleRequests, useOperation } from "../../operation.js";
9
- import { MethodLabel } from "../components/method-label.js";
4
+ import { usePlayground } from "../../playground/use-playground.js";
10
5
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
11
- import { Markdown } from "../components/markdown.js";
12
6
  import { cn } from "../../utils/cn.js";
13
- import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../../packages/shared-api/dist/components/collapsible.js";
14
- import { DefaultResultDisplay } from "./components/result-display.js";
15
- import { SchemaProvider, anyFields, useResolvedSchema } from "../../packages/shared-api/dist/components/playground/schema.js";
16
- import { Label } from "../../packages/shared-api/dist/components/label.js";
17
- import ServerSelect from "./components/server-select.js";
18
- import { FieldInput, FieldSet, JsonInput, ObjectInput } from "../../packages/shared-api/dist/components/playground/inputs.js";
19
- import { OAuthDialog, OAuthDialogContent, OAuthDialogTrigger } from "./components/oauth-dialog.js";
20
- import { Spinner } from "../../packages/shared-api/dist/components/spinner.js";
21
- import { Fragment, createContext, use, useEffect, useMemo, useRef, useState } from "react";
22
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
23
- import { StfProvider, useDataEngine, useFieldValue, useListener, useStf } from "@fumari/stf";
24
- import { stringifyFieldKey } from "@fumari/stf/lib/utils";
7
+ import { Segmented, SegmentedList } from "./components/segmented.js";
8
+ import { DefaultResultDisplay, iconButtonClassName } from "./components/result-display.js";
9
+ import { EndpointBar } from "../components/endpoint.js";
10
+ import { SchemaProvider } from "../../packages/shared-api/dist/components/playground/schema.js";
11
+ import { UrlBar } from "./components/url-bar.js";
12
+ import { RequestPanel } from "./components/request-panel.js";
13
+ import { ResponsePanel } from "./components/response-panel.js";
14
+ import { useState } from "react";
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ import { StfProvider, useFieldValue } from "@fumari/stf";
25
17
  import { useTranslations } from "@fuma-translate/react";
26
- import { ChevronDown, LoaderCircle, PlusIcon } from "lucide-react";
18
+ import { Play, X } from "lucide-react";
27
19
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
20
+ import { Dialog } from "@base-ui/react/dialog";
28
21
  import { useOnChange } from "fumadocs-core/utils/use-on-change";
29
22
  //#region src/ui/playground/client.tsx
30
- const OptionsContext = createContext({});
31
- function usePlaygroundOptions() {
32
- return use(OptionsContext);
33
- }
34
- function PlaygroundClient({ writeOnly, readOnly, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }) {
23
+ function PlaygroundClient({ writeOnly = true, readOnly = false, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }) {
35
24
  const t = useTranslations({ note: "playground" });
36
- const { doc, mediaAdapters, proxyUrl } = useOpenAPI();
37
- const { dereferenced } = doc;
38
- const { path: route, method, operation, parameters: groups, requestBody } = useOperation();
39
- const options = useMemo(() => ({
40
- transformAuthInputs,
41
- fetchOptions,
42
- components,
43
- renderParameterField,
44
- renderBodyField
45
- }), [
25
+ const { doc } = useOpenAPI();
26
+ const { path, method, operation } = useOperation();
27
+ const playground = usePlayground({
46
28
  transformAuthInputs,
47
- fetchOptions,
48
- components,
49
- renderParameterField,
50
- renderBodyField
51
- ]);
52
- const parameters = useMemo(() => groups.flatMap((group) => group.items), [groups]);
53
- const body = useMemo(() => {
54
- if (!requestBody) return;
55
- const mediaType = "application/json" in requestBody.content ? "application/json" : Object.keys(requestBody.content)[0];
56
- return {
57
- mediaType,
58
- schema: requestBody.content[mediaType].schema ?? true
59
- };
60
- }, [requestBody]);
61
- const { items: examples, selected: exampleId, update } = useExampleRequests();
62
- const { resolveUrl } = useServer();
63
- const { ResultDisplay = DefaultResultDisplay, CollapsiblePanel = DefaultCollapsiblePanel } = components ?? {};
64
- const defaultValues = useMemo(() => {
65
- const requestData = examples.find((example) => example.id === exampleId)?.data;
66
- return {
67
- path: requestData?.path ?? {},
68
- query: requestData?.query ?? {},
69
- header: requestData?.header ?? {},
70
- body: requestData?.body ?? {},
71
- cookie: requestData?.cookie ?? {}
72
- };
73
- }, [examples, exampleId]);
74
- const stf = useStf({ defaultValues });
75
- const auth = useAuthFields(stf.dataEngine, {
76
- operation,
77
- transform: transformAuthInputs
29
+ fetchOptions
78
30
  });
79
- const testQuery = useQuery(async (input) => {
80
- const fetcher = await import("../../playground/index.js").then((mod) => mod.createBrowserFetcher(mediaAdapters, {
81
- proxyUrl,
82
- ...fetchOptions
83
- }));
84
- const encoded = encodeRequestData({
85
- ...auth.mapValues(input),
86
- method,
87
- bodyMediaType: body?.mediaType
88
- }, mediaAdapters, parameters);
89
- return fetcher.fetch(resolveUrl(pathnameFromRequest(route, encoded)), encoded);
90
- });
91
- const timerRef = useRef(null);
92
- const stfSync = useRef(false);
93
- function triggerExampleUpdate() {
94
- const data = {
95
- ...auth.mapValues(stf.dataEngine.getData()),
96
- method,
97
- bodyMediaType: body?.mediaType
98
- };
99
- update(data);
100
- }
101
- useListener({
102
- stf,
103
- onUpdate() {
104
- if (!stfSync.current) return;
105
- if (timerRef.current) window.clearTimeout(timerRef.current);
106
- timerRef.current = window.setTimeout(triggerExampleUpdate, 400);
107
- }
31
+ const [open, setOpen] = useState(false);
32
+ useOnChange(playground.auth.flowReturned, (returned) => {
33
+ if (returned) setOpen(true);
108
34
  });
109
- useEffect(() => {
110
- if (stf.dataEngine.getData() === defaultValues) return;
111
- stf.dataEngine.reset(defaultValues);
112
- }, [defaultValues]);
113
- useEffect(() => {
114
- const reset = auth.init();
115
- triggerExampleUpdate();
116
- stfSync.current = true;
117
- return () => {
118
- stfSync.current = false;
119
- reset();
120
- };
121
- }, [defaultValues, auth.init]);
122
- return /* @__PURE__ */ jsx(OptionsContext, {
123
- value: options,
124
- children: /* @__PURE__ */ jsx(StfProvider, {
125
- value: stf,
126
- children: /* @__PURE__ */ jsx(SchemaProvider, {
127
- docRoot: dereferenced,
128
- writeOnly,
129
- readOnly,
130
- children: /* @__PURE__ */ jsxs("form", {
35
+ return /* @__PURE__ */ jsx(StfProvider, {
36
+ value: playground.stf,
37
+ children: /* @__PURE__ */ jsx(SchemaProvider, {
38
+ docRoot: doc.dereferenced,
39
+ writeOnly,
40
+ readOnly,
41
+ children: /* @__PURE__ */ jsxs(Dialog.Root, {
42
+ open,
43
+ onOpenChange: setOpen,
44
+ children: [/* @__PURE__ */ jsx(EndpointBar, {
45
+ method,
46
+ route: path,
47
+ deprecated: operation.deprecated,
131
48
  ...rest,
132
- className: cn("not-prose flex flex-col rounded-xl border shadow-md overflow-hidden bg-fd-card text-fd-card-foreground", rest.className),
133
- onSubmit: (e) => {
134
- testQuery.start(stf.dataEngine.getData());
135
- e.preventDefault();
136
- },
137
- children: [
138
- /* @__PURE__ */ jsx(ServerSelect, { className: "border-b" }),
139
- /* @__PURE__ */ jsxs("div", {
140
- className: "flex flex-row items-center gap-2 text-sm p-3 not-last:pb-0",
141
- children: [
142
- /* @__PURE__ */ jsx(MethodLabel, { children: method }),
143
- /* @__PURE__ */ jsx(Route, {
144
- route,
145
- className: cn("flex-1", operation.deprecated && "line-through")
146
- }),
147
- /* @__PURE__ */ jsx("button", {
148
- type: "submit",
149
- className: cn(buttonVariants({
150
- variant: "default",
151
- size: "sm"
152
- }), "w-14 py-1.5"),
153
- disabled: testQuery.isLoading,
154
- children: testQuery.isLoading ? /* @__PURE__ */ jsx(LoaderCircle, { className: "size-4 animate-spin" }) : t("Send")
155
- })
156
- ]
157
- }),
158
- testQuery.data ? /* @__PURE__ */ jsx(ResultDisplay, {
159
- data: testQuery.data,
160
- reset: testQuery.reset
161
- }) : null,
162
- auth.requirements.length > 0 && /* @__PURE__ */ jsx(SecurityRequirements, {
163
- requirements: auth.requirements,
164
- selected: auth.selected,
165
- select: auth.select,
166
- children: auth.fields.map((field) => /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(AuthInput, { field }) }, stringifyFieldKey(field.fieldName)))
167
- }),
168
- /* @__PURE__ */ jsx(ParametersForm, { parameters }),
169
- body && /* @__PURE__ */ jsx(CollapsiblePanel, {
170
- "data-type": "body",
171
- title: t("Body"),
172
- children: renderBodyField ? renderBodyField("body", body) : /* @__PURE__ */ jsx(BodyInput, { field: body.schema })
173
- })
174
- ]
175
- })
49
+ children: /* @__PURE__ */ jsxs(Dialog.Trigger, {
50
+ className: cn(buttonVariants({
51
+ variant: "primary",
52
+ size: "sm"
53
+ }), "group shrink-0 gap-1.5 rounded-lg px-3 transition-[background-color,scale] active:scale-[0.97] motion-reduce:transition-none"),
54
+ children: [/* @__PURE__ */ jsx(Play, { className: "size-3 fill-current transition-transform duration-200 group-hover:translate-x-px motion-reduce:transition-none" }), t("Try in Playground")]
55
+ })
56
+ }), /* @__PURE__ */ jsxs(Dialog.Portal, { children: [/* @__PURE__ */ jsx(Dialog.Backdrop, { className: "fixed inset-0 z-50 bg-black/40 backdrop-blur-xs transition-opacity duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0" }), /* @__PURE__ */ jsx(Dialog.Popup, {
57
+ className: "fixed inset-0 z-50 flex flex-col overflow-hidden bg-fd-background text-fd-foreground outline-none transition-[opacity,scale] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] data-ending-style:scale-[0.98] data-ending-style:opacity-0 data-ending-style:duration-150 data-starting-style:scale-[0.98] data-starting-style:opacity-0 motion-reduce:transition-opacity sm:inset-auto sm:top-1/2 sm:left-1/2 sm:h-[min(52rem,calc(100dvh-3rem))] sm:w-[min(80rem,calc(100vw-3rem))] sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl sm:border sm:shadow-2xl",
58
+ children: /* @__PURE__ */ jsx(PlaygroundDialog, {
59
+ playground,
60
+ renderParameterField,
61
+ renderBodyField,
62
+ ResultDisplay: components?.ResultDisplay
63
+ })
64
+ })] })]
176
65
  })
177
66
  })
178
67
  });
179
68
  }
180
- function SecurityRequirements({ requirements, select, selected, children }) {
69
+ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, ResultDisplay }) {
181
70
  const t = useTranslations({ note: "playground" });
182
- const { isLoading, error } = usePlaygroundAuth();
183
- const defaultOpen = isLoading || error != null;
184
- const [open, setOpen] = useState(defaultOpen);
185
- const { CollapsiblePanel = DefaultCollapsiblePanel } = usePlaygroundOptions().components ?? {};
186
- useOnChange(defaultOpen, () => {
187
- if (defaultOpen) setOpen(true);
188
- });
189
- const items = requirements.map((requirement, i) => ({
190
- value: i,
191
- label: /* @__PURE__ */ jsx("span", {
192
- className: "inline-flex items-center gap-1 font-mono font-medium",
193
- children: requirement.map((item, i) => /* @__PURE__ */ jsxs(Fragment, { children: [i > 0 && /* @__PURE__ */ jsx(PlusIcon, { className: "text-fd-muted-foreground size-3.5" }), /* @__PURE__ */ jsx("span", {
194
- className: cn(item.scheme.deprecated && "text-fd-muted-foreground line-through"),
195
- children: item.id
196
- })] }, i))
197
- })
198
- }));
199
- return /* @__PURE__ */ jsxs(CollapsiblePanel, {
200
- title: /* @__PURE__ */ jsxs(Fragment$1, { children: [t("Authorization"), isLoading && /* @__PURE__ */ jsxs("span", {
201
- className: "border-s ps-2 inline-flex items-center gap-1.5 text-fd-muted-foreground text-xs font-mono",
202
- children: [
203
- /* @__PURE__ */ jsx(Spinner, {}),
204
- " ",
205
- t("Fetching token...")
206
- ]
207
- })] }),
208
- "data-type": "authorization",
209
- open,
210
- onOpenChange: setOpen,
71
+ const { title, method, path, operation, parameters } = useOperation();
72
+ const { response, isSending, send, clearResponse } = playground;
73
+ const [view, setView] = useState("request");
74
+ return /* @__PURE__ */ jsxs("form", {
75
+ noValidate: true,
76
+ className: "flex min-h-0 flex-1 flex-col",
77
+ onSubmit: (e) => {
78
+ e.preventDefault();
79
+ send();
80
+ setView("response");
81
+ },
82
+ onKeyDown: (e) => {
83
+ if (e.key !== "Enter" || !(e.metaKey || e.ctrlKey)) return;
84
+ e.preventDefault();
85
+ e.currentTarget.requestSubmit();
86
+ },
211
87
  children: [
212
- error != null && /* @__PURE__ */ jsxs("div", {
213
- className: "p-2 border rounded-lg bg-fd-secondary",
214
- children: [/* @__PURE__ */ jsx("p", {
215
- className: "text-fd-muted-foreground font-medium mb-1",
216
- children: t("Failed to fetch token")
217
- }), /* @__PURE__ */ jsx("p", { children: String(error) })]
218
- }),
219
88
  /* @__PURE__ */ jsxs("div", {
220
- className: "overflow-hidden rounded-md border bg-fd-secondary focus-within:ring focus-within:ring-fd-ring",
221
- children: [/* @__PURE__ */ jsxs(Select, {
222
- items,
223
- value: selected,
224
- onValueChange: (v) => v !== null && select(v),
225
- children: [/* @__PURE__ */ jsx(SelectTrigger, {
226
- className: "rounded-t-md rounded-b-none border-0 bg-transparent focus:ring-0",
227
- children: /* @__PURE__ */ jsx(SelectValue, {})
228
- }), /* @__PURE__ */ jsx(SelectContent, { children: items.map(({ value, label }) => /* @__PURE__ */ jsx(SelectItem, {
229
- value,
230
- children: label
231
- }, value)) })]
232
- }), /* @__PURE__ */ jsx("div", {
233
- className: "grid grid-cols-[auto_1fr] gap-2 border-t px-2 py-1.5 text-xs text-fd-muted-foreground empty:hidden",
234
- children: requirements[selected]?.map(({ id, scheme }, _, arr) => {
235
- if (!scheme.description) return;
236
- return /* @__PURE__ */ jsxs(Fragment, { children: [arr.length > 1 && /* @__PURE__ */ jsx("span", {
237
- className: "font-medium font-mono text-fd-primary",
238
- children: id
239
- }), /* @__PURE__ */ jsx(Markdown, { md: scheme.description })] }, id);
89
+ className: "flex h-12 shrink-0 items-center gap-2 ps-4 pe-2 sm:ps-5",
90
+ children: [
91
+ /* @__PURE__ */ jsx(Dialog.Title, {
92
+ className: "truncate text-sm font-medium",
93
+ children: title
94
+ }),
95
+ operation.deprecated && /* @__PURE__ */ jsx("span", {
96
+ className: "rounded-md bg-amber-500/10 px-1.5 py-0.5 text-xs font-medium text-amber-600 dark:text-amber-400",
97
+ children: t("Deprecated")
98
+ }),
99
+ /* @__PURE__ */ jsxs("div", {
100
+ className: "ms-auto flex items-center gap-1",
101
+ children: [/* @__PURE__ */ jsx(ExampleSelect, {}), /* @__PURE__ */ jsx(Dialog.Close, {
102
+ "aria-label": t("Close"),
103
+ className: iconButtonClassName,
104
+ children: /* @__PURE__ */ jsx(X, {})
105
+ })]
240
106
  })
241
- })]
107
+ ]
242
108
  }),
243
- children
244
- ]
245
- });
246
- }
247
- const ParamTypes = [
248
- "path",
249
- "header",
250
- "cookie",
251
- "query"
252
- ];
253
- function ParameterItem({ type, parameters }) {
254
- const { renderParameterField } = usePlaygroundOptions();
255
- return parameters.map((field) => {
256
- const fieldName = [type, field.name];
257
- if (renderParameterField) return renderParameterField(fieldName, field);
258
- const contentTypes = field.content && Object.keys(field.content);
259
- const schema = field.content && contentTypes && contentTypes.length > 0 ? field.content[contentTypes[0]].schema : field.schema;
260
- return /* @__PURE__ */ jsx(FieldSet, {
261
- name: field.name,
262
- fieldName,
263
- field: schema ?? anyFields,
264
- isRequired: field.required
265
- }, stringifyFieldKey(fieldName));
266
- });
267
- }
268
- function ParametersForm({ parameters }) {
269
- const { CollapsiblePanel = DefaultCollapsiblePanel } = usePlaygroundOptions().components ?? {};
270
- const t = useTranslations({ note: "playground" });
271
- const displayNames = {
272
- header: t("Header"),
273
- cookie: t("Cookies"),
274
- query: t("Query"),
275
- path: t("Path")
276
- };
277
- return ParamTypes.map((type) => {
278
- const items = parameters.filter((v) => v.in === type);
279
- if (items.length === 0) return;
280
- return /* @__PURE__ */ jsx(CollapsiblePanel, {
281
- "data-type": type,
282
- title: displayNames[type],
283
- children: /* @__PURE__ */ jsx(ParameterItem, {
284
- parameters: items,
285
- type
109
+ /* @__PURE__ */ jsx("div", {
110
+ className: "shrink-0 px-3 pb-3 sm:px-4",
111
+ children: /* @__PURE__ */ jsx(UrlBar, {
112
+ method,
113
+ route: path,
114
+ parameters: parameters.find((group) => group.in === "path")?.items ?? [],
115
+ deprecated: operation.deprecated,
116
+ loading: isSending
117
+ })
118
+ }),
119
+ /* @__PURE__ */ jsx(Segmented, {
120
+ value: view,
121
+ onValueChange: setView,
122
+ className: "shrink-0 px-3 pb-3 md:hidden",
123
+ children: /* @__PURE__ */ jsx(SegmentedList, {
124
+ className: "*:flex-1 *:justify-center",
125
+ items: [{
126
+ value: "request",
127
+ label: t("Request")
128
+ }, {
129
+ value: "response",
130
+ label: t("Response")
131
+ }]
132
+ })
133
+ }),
134
+ /* @__PURE__ */ jsxs("div", {
135
+ className: "mx-3 mb-3 grid min-h-0 flex-1 overflow-hidden rounded-xl border bg-fd-card sm:mx-4 sm:mb-4 md:grid-cols-[minmax(0,11fr)_minmax(0,9fr)]",
136
+ children: [/* @__PURE__ */ jsx(RequestPanel, {
137
+ playground,
138
+ renderParameterField,
139
+ renderBodyField,
140
+ className: cn(view !== "request" && "max-md:hidden")
141
+ }), /* @__PURE__ */ jsx(ResponsePanel, {
142
+ response,
143
+ loading: isSending,
144
+ onReset: clearResponse,
145
+ ResultDisplay,
146
+ className: cn("md:border-s", view !== "response" && "max-md:hidden")
147
+ })]
286
148
  })
287
- }, type);
288
- });
289
- }
290
- function BodyInput({ field: _field }) {
291
- const field = useResolvedSchema(_field);
292
- const [isJson, setIsJson] = useState(false);
293
- const t = useTranslations({ note: "playground" });
294
- if (field.format === "binary") return /* @__PURE__ */ jsx(FieldSet, {
295
- field,
296
- fieldName: ["body"],
297
- isRequired: true
298
- });
299
- if (isJson) return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
300
- className: cn(buttonVariants({
301
- variant: "secondary",
302
- size: "sm",
303
- className: "w-fit font-mono p-2"
304
- })),
305
- onClick: () => setIsJson(false),
306
- type: "button",
307
- children: t("Close JSON Editor")
308
- }), /* @__PURE__ */ jsx(JsonInput, { fieldName: ["body"] })] });
309
- return /* @__PURE__ */ jsx(FieldSet, {
310
- field,
311
- fieldName: ["body"],
312
- collapsible: false,
313
- isRequired: true,
314
- name: /* @__PURE__ */ jsx("button", {
315
- type: "button",
316
- className: cn(buttonVariants({
317
- variant: "secondary",
318
- size: "sm",
319
- className: "p-2"
320
- })),
321
- onClick: () => setIsJson(true),
322
- children: t("Open JSON Editor")
323
- })
324
- });
325
- }
326
- function AuthInput({ field }) {
327
- const t = useTranslations({ note: "playground" });
328
- const { fieldName, scheme } = field;
329
- if (scheme.type === "oauth2") return /* @__PURE__ */ jsx(OAuth2Input, { field });
330
- if (scheme.type === "http" && scheme.scheme === "basic") return /* @__PURE__ */ jsx(ObjectInput, {
331
- field: {
332
- type: "object",
333
- properties: {
334
- username: { type: "string" },
335
- password: { type: "string" }
336
- }
337
- },
338
- fieldName
339
- });
340
- if (scheme.type === "apiKey") return /* @__PURE__ */ jsx(FieldSet, {
341
- fieldName,
342
- name: `${scheme.name} (${scheme.in})`,
343
- field: { type: "string" }
149
+ ]
344
150
  });
345
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(FieldSet, {
346
- name: `${t("Authorization")} (${t("Header")})`,
347
- fieldName,
348
- field: { type: "string" }
349
- }), scheme.type !== "http" && /* @__PURE__ */ jsx("p", {
350
- className: "text-fd-muted-foreground text-xs",
351
- children: t("OpenID Connect is not supported at the moment, you can still set an access token here.")
352
- })] });
353
151
  }
354
- function OAuth2Input({ field }) {
355
- const { fieldName } = field;
356
- const [open, setOpen] = useState(false);
357
- const engine = useDataEngine();
152
+ function ExampleSelect() {
153
+ const { items, selected, select } = useExampleRequests();
358
154
  const t = useTranslations({ note: "playground" });
359
- return /* @__PURE__ */ jsxs("fieldset", {
360
- className: "flex flex-col gap-2",
361
- children: [/* @__PURE__ */ jsx(Label, {
362
- htmlFor: stringifyFieldKey(fieldName),
363
- children: t("Access Token")
364
- }), /* @__PURE__ */ jsxs("div", {
365
- className: "flex gap-2",
366
- children: [/* @__PURE__ */ jsx(FieldInput, {
367
- fieldName,
368
- field: { type: "string" },
369
- className: "flex-1"
370
- }), /* @__PURE__ */ jsxs(OAuthDialog, {
371
- open,
372
- onOpenChange: setOpen,
373
- children: [/* @__PURE__ */ jsx(OAuthDialogTrigger, {
374
- type: "button",
375
- className: cn(buttonVariants({
376
- size: "sm",
377
- variant: "secondary"
378
- })),
379
- children: t("Authorize")
380
- }), /* @__PURE__ */ jsx(OAuthDialogContent, {
381
- setOpen,
382
- schemeId: field.schemeId,
383
- scopes: field.scopes,
384
- setToken: (token) => engine.update(["header", "Authorization"], token)
385
- })]
386
- })]
155
+ if (items.length <= 1) return null;
156
+ const options = items.map((item) => ({
157
+ value: item.id,
158
+ label: item.name
159
+ }));
160
+ return /* @__PURE__ */ jsxs(Select, {
161
+ items: options,
162
+ value: selected ?? null,
163
+ onValueChange: (v) => v !== null && select(v),
164
+ children: [/* @__PURE__ */ jsxs(SelectTrigger, {
165
+ className: "h-8 w-auto max-w-64 gap-1.5 border-0 bg-transparent px-2 text-xs hover:bg-fd-accent focus:ring-0 focus-visible:ring-2",
166
+ children: [/* @__PURE__ */ jsx("span", {
167
+ className: "text-fd-muted-foreground",
168
+ children: t("Example")
169
+ }), /* @__PURE__ */ jsx(SelectValue, { className: "truncate font-medium" })]
170
+ }), /* @__PURE__ */ jsx(SelectContent, {
171
+ align: "end",
172
+ children: options.map((option) => /* @__PURE__ */ jsx(SelectItem, {
173
+ value: option.value,
174
+ children: option.label
175
+ }, option.value))
387
176
  })]
388
177
  });
389
178
  }
390
- function Route({ route, ...props }) {
391
- return /* @__PURE__ */ jsx("div", {
392
- ...props,
393
- className: cn("flex flex-row items-center gap-0.5 overflow-auto text-nowrap", props.className),
394
- children: route.split("/").map((part, index) => /* @__PURE__ */ jsxs(Fragment, { children: [index > 0 && /* @__PURE__ */ jsx("span", {
395
- className: "text-fd-muted-foreground",
396
- children: "/"
397
- }), part.startsWith("{") && part.endsWith("}") ? /* @__PURE__ */ jsx("code", {
398
- className: "bg-fd-primary/10 text-fd-primary",
399
- children: part
400
- }) : /* @__PURE__ */ jsx("code", {
401
- className: "text-fd-foreground",
402
- children: part
403
- })] }, index))
404
- });
405
- }
406
- function DefaultCollapsiblePanel({ title, children, ...props }) {
407
- return /* @__PURE__ */ jsxs(Collapsible, {
408
- ...props,
409
- className: cn("border-b last:border-b-0", props.className),
410
- children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
411
- className: "group w-full flex items-center gap-2 p-3 text-sm font-medium",
412
- children: [title, /* @__PURE__ */ jsx(ChevronDown, { className: "ms-auto size-3.5 text-fd-muted-foreground group-data-[panel-open]:rotate-180" })]
413
- }), /* @__PURE__ */ jsx(CollapsibleContent, { children: /* @__PURE__ */ jsx("div", {
414
- className: "flex flex-col gap-3 p-3 pt-1",
415
- children
416
- }) })]
417
- });
418
- }
419
179
  const Custom = { useController(fieldName, options) {
420
180
  const [value, setValue] = useFieldValue(fieldName, options);
421
181
  return {
@@ -424,4 +184,4 @@ const Custom = { useController(fieldName, options) {
424
184
  };
425
185
  } };
426
186
  //#endregion
427
- export { Custom, DefaultCollapsiblePanel, DefaultResultDisplay, PlaygroundClient as default };
187
+ export { Custom, DefaultResultDisplay, PlaygroundClient as default };