fumadocs-openapi 12.1.1 → 12.3.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.
- package/css/generated/shared.css +1 -1
- package/dist/.translations/index.d.ts +63 -20
- package/dist/.translations/keys.js +63 -20
- package/dist/operation.d.ts +6 -1
- package/dist/operation.js +2 -4
- package/dist/packages/shared-api/dist/.translations/index.d.ts +1 -0
- package/dist/packages/shared-api/dist/.translations/keys.js +1 -0
- package/dist/packages/shared-api/dist/auto-anchor/index.js +54 -10
- package/dist/packages/shared-api/dist/components/accordion.js +3 -11
- package/dist/packages/shared-api/dist/components/collapsible.js +2 -2
- package/dist/packages/shared-api/dist/components/schema/client.d.ts +5 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +408 -455
- package/dist/packages/shared-api/dist/components/select-tab.js +7 -12
- package/dist/packages/shared-api/dist/components/select.js +8 -7
- package/dist/playground/auth.d.ts +5 -1
- package/dist/playground/auth.js +7 -2
- package/dist/playground/fetcher.d.ts +8 -0
- package/dist/playground/fetcher.js +30 -1
- package/dist/playground/index.d.ts +2 -1
- package/dist/playground/index.js +2 -1
- package/dist/playground/use-playground.d.ts +62 -0
- package/dist/playground/use-playground.js +140 -0
- package/dist/ui/components/dialog.js +14 -0
- package/dist/ui/components/endpoint.js +40 -0
- package/dist/ui/components/heading.js +1 -1
- package/dist/ui/components/schema.js +1 -1
- package/dist/ui/components/segmented.js +21 -0
- package/dist/ui/operation/index.js +267 -250
- package/dist/ui/playground/client.d.ts +9 -26
- package/dist/ui/playground/client.js +150 -389
- package/dist/ui/playground/components/fields.js +693 -0
- package/dist/ui/playground/components/oauth-panel.js +182 -0
- package/dist/ui/playground/components/request-panel.js +480 -0
- package/dist/ui/playground/components/response-panel.js +150 -0
- package/dist/ui/playground/components/result-display.d.ts +1 -0
- package/dist/ui/playground/components/result-display.js +185 -168
- package/dist/ui/playground/components/server-select.js +100 -89
- package/dist/ui/playground/components/url-bar.js +96 -0
- package/dist/ui/playground/status-info.js +32 -45
- package/dist/utils/document/load.js +1 -1
- package/package.json +12 -12
- package/dist/packages/shared-api/dist/auto-anchor/client.js +0 -20
- package/dist/packages/shared-api/dist/components/collapsible.d.ts +0 -7
- package/dist/packages/shared-api/dist/components/dialog.js +0 -55
- package/dist/packages/shared-api/dist/components/input.js +0 -14
- package/dist/packages/shared-api/dist/components/label.js +0 -11
- package/dist/packages/shared-api/dist/components/playground/inputs.js +0 -439
- package/dist/packages/shared-api/dist/components/popover.js +0 -23
- package/dist/packages/shared-api/dist/utils/merge-refs.js +0 -11
- package/dist/ui/playground/components/oauth-dialog.js +0 -259
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { ParameterObject } from "../../types.js";
|
|
2
|
-
import { BrowserFetcherOptions } from "../../playground/fetcher.js";
|
|
3
2
|
import { DefaultResultDisplay, ResultDisplayProps } from "./components/result-display.js";
|
|
4
|
-
import {
|
|
5
|
-
import { AuthField } from "../../playground/auth.js";
|
|
3
|
+
import { PlaygroundOptions, RequestBodyInfo } from "../../playground/use-playground.js";
|
|
6
4
|
import { ComponentProps, FC, ReactNode } from "react";
|
|
7
|
-
import { JsonSchema } from "@fumadocs/json-schema";
|
|
8
5
|
import { FieldKey } from "@fumari/stf";
|
|
9
6
|
//#region src/ui/playground/client.d.ts
|
|
7
|
+
export interface PlaygroundClientProps extends ComponentProps<'div'>, PlaygroundClientOptions {
|
|
8
|
+
/** @deprecated it defaults to `true` for requests */
|
|
9
|
+
writeOnly?: boolean;
|
|
10
|
+
/** @deprecated it defaults to `false` for requests */
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** @deprecated use `usePlayground().stf` for the form */
|
|
10
14
|
export interface FormValues extends Record<string, unknown> {
|
|
11
15
|
path: Record<string, unknown>;
|
|
12
16
|
query: Record<string, unknown>;
|
|
@@ -14,23 +18,9 @@ export interface FormValues extends Record<string, unknown> {
|
|
|
14
18
|
cookie: Record<string, unknown>;
|
|
15
19
|
body: unknown;
|
|
16
20
|
}
|
|
17
|
-
export interface
|
|
18
|
-
writeOnly: boolean;
|
|
19
|
-
readOnly: boolean;
|
|
20
|
-
}
|
|
21
|
-
export interface CollapsiblePanelProps extends Omit<ComponentProps<typeof Collapsible>, 'title'> {
|
|
22
|
-
'data-type': 'authorization' | 'body' | ParamType;
|
|
23
|
-
title: ReactNode;
|
|
24
|
-
}
|
|
25
|
-
export interface PlaygroundClientOptions {
|
|
26
|
-
/**
|
|
27
|
-
* transform fields for auth-specific parameters (e.g. header)
|
|
28
|
-
*/
|
|
29
|
-
transformAuthInputs?: (fields: AuthField[]) => AuthField[];
|
|
30
|
-
fetchOptions?: BrowserFetcherOptions;
|
|
21
|
+
export interface PlaygroundClientOptions extends PlaygroundOptions {
|
|
31
22
|
components?: {
|
|
32
23
|
ResultDisplay?: FC<ResultDisplayProps>;
|
|
33
|
-
CollapsiblePanel?: FC<CollapsiblePanelProps>;
|
|
34
24
|
};
|
|
35
25
|
/**
|
|
36
26
|
* render the parameter inputs of API endpoint.
|
|
@@ -48,14 +38,7 @@ export interface PlaygroundClientOptions {
|
|
|
48
38
|
*/
|
|
49
39
|
renderBodyField?: (fieldName: 'body', info: RequestBodyInfo) => ReactNode;
|
|
50
40
|
}
|
|
51
|
-
interface RequestBodyInfo {
|
|
52
|
-
schema: JsonSchema;
|
|
53
|
-
mediaType: string;
|
|
54
|
-
}
|
|
55
41
|
export default function PlaygroundClient({ writeOnly, readOnly, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }: PlaygroundClientProps): import("react").JSX.Element;
|
|
56
|
-
declare const ParamTypes: readonly ['path', 'header', 'cookie', 'query'];
|
|
57
|
-
type ParamType = (typeof ParamTypes)[number];
|
|
58
|
-
export declare function DefaultCollapsiblePanel({ title, children, ...props }: CollapsiblePanelProps): import("react").JSX.Element;
|
|
59
42
|
export declare const Custom: {
|
|
60
43
|
useController(fieldName: FieldKey, options?: {
|
|
61
44
|
defaultValue?: unknown;
|
|
@@ -1,421 +1,182 @@
|
|
|
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 {
|
|
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 {
|
|
14
|
-
import { DefaultResultDisplay } from "./components/result-display.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { StfProvider,
|
|
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 { DialogPopup } from "../components/dialog.js";
|
|
11
|
+
import { SchemaProvider } from "../../packages/shared-api/dist/components/playground/schema.js";
|
|
12
|
+
import { UrlBar } from "./components/url-bar.js";
|
|
13
|
+
import { RequestPanel } from "./components/request-panel.js";
|
|
14
|
+
import { ResponsePanel } from "./components/response-panel.js";
|
|
15
|
+
import { useState } from "react";
|
|
16
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
import { StfProvider, useFieldValue } from "@fumari/stf";
|
|
25
18
|
import { useTranslations } from "@fuma-translate/react";
|
|
26
|
-
import {
|
|
19
|
+
import { Play, X } from "lucide-react";
|
|
27
20
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
21
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
28
22
|
import { useOnChange } from "fumadocs-core/utils/use-on-change";
|
|
29
23
|
//#region src/ui/playground/client.tsx
|
|
30
|
-
|
|
31
|
-
function usePlaygroundOptions() {
|
|
32
|
-
return use(OptionsContext);
|
|
33
|
-
}
|
|
34
|
-
function PlaygroundClient({ writeOnly, readOnly, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }) {
|
|
24
|
+
function PlaygroundClient({ writeOnly = true, readOnly = false, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }) {
|
|
35
25
|
const t = useTranslations({ note: "playground" });
|
|
36
|
-
const { doc
|
|
37
|
-
const {
|
|
38
|
-
const
|
|
39
|
-
const options = useMemo(() => ({
|
|
40
|
-
transformAuthInputs,
|
|
41
|
-
fetchOptions,
|
|
42
|
-
components,
|
|
43
|
-
renderParameterField,
|
|
44
|
-
renderBodyField
|
|
45
|
-
}), [
|
|
26
|
+
const { doc } = useOpenAPI();
|
|
27
|
+
const { path, method, operation } = useOperation();
|
|
28
|
+
const playground = usePlayground({
|
|
46
29
|
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
|
|
30
|
+
fetchOptions
|
|
78
31
|
});
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
}
|
|
32
|
+
const [open, setOpen] = useState(false);
|
|
33
|
+
useOnChange(playground.auth.flowReturned, (returned) => {
|
|
34
|
+
if (returned) setOpen(true);
|
|
108
35
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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", {
|
|
36
|
+
return /* @__PURE__ */ jsx(StfProvider, {
|
|
37
|
+
value: playground.stf,
|
|
38
|
+
children: /* @__PURE__ */ jsx(SchemaProvider, {
|
|
39
|
+
docRoot: doc.dereferenced,
|
|
40
|
+
writeOnly,
|
|
41
|
+
readOnly,
|
|
42
|
+
children: /* @__PURE__ */ jsxs(Dialog.Root, {
|
|
43
|
+
open,
|
|
44
|
+
onOpenChange: setOpen,
|
|
45
|
+
children: [/* @__PURE__ */ jsx(EndpointBar, {
|
|
46
|
+
method,
|
|
47
|
+
route: path,
|
|
48
|
+
deprecated: operation.deprecated,
|
|
131
49
|
...rest,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
})
|
|
50
|
+
children: /* @__PURE__ */ jsxs(Dialog.Trigger, {
|
|
51
|
+
className: cn(buttonVariants({
|
|
52
|
+
variant: "primary",
|
|
53
|
+
size: "sm"
|
|
54
|
+
}), "group shrink-0 gap-1.5 rounded-lg px-3 transition-[background-color,scale] active:scale-[0.97] motion-reduce:transition-none"),
|
|
55
|
+
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")]
|
|
56
|
+
})
|
|
57
|
+
}), /* @__PURE__ */ jsx(DialogPopup, {
|
|
58
|
+
className: "sm:h-[min(52rem,calc(100dvh-3rem))] sm:w-[min(80rem,calc(100vw-3rem))]",
|
|
59
|
+
children: /* @__PURE__ */ jsx(PlaygroundDialog, {
|
|
60
|
+
playground,
|
|
61
|
+
renderParameterField,
|
|
62
|
+
renderBodyField,
|
|
63
|
+
ResultDisplay: components?.ResultDisplay
|
|
64
|
+
})
|
|
65
|
+
})]
|
|
176
66
|
})
|
|
177
67
|
})
|
|
178
68
|
});
|
|
179
69
|
}
|
|
180
|
-
function
|
|
70
|
+
function PlaygroundDialog({ playground, renderParameterField, renderBodyField, ResultDisplay }) {
|
|
181
71
|
const t = useTranslations({ note: "playground" });
|
|
182
|
-
const {
|
|
183
|
-
const
|
|
184
|
-
const [
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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,
|
|
72
|
+
const { title, method, path, operation, parameters } = useOperation();
|
|
73
|
+
const { response, isSending, send, clearResponse } = playground;
|
|
74
|
+
const [view, setView] = useState("request");
|
|
75
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
76
|
+
noValidate: true,
|
|
77
|
+
className: "flex min-h-0 flex-1 flex-col",
|
|
78
|
+
onSubmit: (e) => {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
send();
|
|
81
|
+
setView("response");
|
|
82
|
+
},
|
|
83
|
+
onKeyDown: (e) => {
|
|
84
|
+
if (e.key !== "Enter" || !(e.metaKey || e.ctrlKey)) return;
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
e.currentTarget.requestSubmit();
|
|
87
|
+
},
|
|
211
88
|
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
89
|
/* @__PURE__ */ jsxs("div", {
|
|
220
|
-
className: "
|
|
221
|
-
children: [
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
className: "font-medium font-mono text-fd-primary",
|
|
238
|
-
children: id
|
|
239
|
-
}), /* @__PURE__ */ jsx(Markdown, { md: scheme.description })] }, id);
|
|
90
|
+
className: "flex h-12 shrink-0 items-center gap-2 ps-4 pe-2 sm:ps-5",
|
|
91
|
+
children: [
|
|
92
|
+
/* @__PURE__ */ jsx(Dialog.Title, {
|
|
93
|
+
className: "truncate text-sm font-medium",
|
|
94
|
+
children: title
|
|
95
|
+
}),
|
|
96
|
+
operation.deprecated && /* @__PURE__ */ jsx("span", {
|
|
97
|
+
className: "rounded-md bg-amber-500/10 px-1.5 py-0.5 text-xs font-medium text-amber-600 dark:text-amber-400",
|
|
98
|
+
children: t("Deprecated")
|
|
99
|
+
}),
|
|
100
|
+
/* @__PURE__ */ jsxs("div", {
|
|
101
|
+
className: "ms-auto flex items-center gap-1",
|
|
102
|
+
children: [/* @__PURE__ */ jsx(ExampleSelect, {}), /* @__PURE__ */ jsx(Dialog.Close, {
|
|
103
|
+
"aria-label": t("Close"),
|
|
104
|
+
className: iconButtonClassName,
|
|
105
|
+
children: /* @__PURE__ */ jsx(X, {})
|
|
106
|
+
})]
|
|
240
107
|
})
|
|
241
|
-
|
|
108
|
+
]
|
|
242
109
|
}),
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
title: displayNames[type],
|
|
283
|
-
children: /* @__PURE__ */ jsx(ParameterItem, {
|
|
284
|
-
parameters: items,
|
|
285
|
-
type
|
|
110
|
+
/* @__PURE__ */ jsx("div", {
|
|
111
|
+
className: "shrink-0 px-3 pb-3 sm:px-4",
|
|
112
|
+
children: /* @__PURE__ */ jsx(UrlBar, {
|
|
113
|
+
method,
|
|
114
|
+
route: path,
|
|
115
|
+
parameters: parameters.find((group) => group.in === "path")?.items ?? [],
|
|
116
|
+
deprecated: operation.deprecated,
|
|
117
|
+
loading: isSending
|
|
118
|
+
})
|
|
119
|
+
}),
|
|
120
|
+
/* @__PURE__ */ jsx(Segmented, {
|
|
121
|
+
value: view,
|
|
122
|
+
onValueChange: setView,
|
|
123
|
+
className: "shrink-0 px-3 pb-3 md:hidden",
|
|
124
|
+
children: /* @__PURE__ */ jsx(SegmentedList, {
|
|
125
|
+
className: "*:flex-1 *:justify-center",
|
|
126
|
+
items: [{
|
|
127
|
+
value: "request",
|
|
128
|
+
label: t("Request")
|
|
129
|
+
}, {
|
|
130
|
+
value: "response",
|
|
131
|
+
label: t("Response")
|
|
132
|
+
}]
|
|
133
|
+
})
|
|
134
|
+
}),
|
|
135
|
+
/* @__PURE__ */ jsxs("div", {
|
|
136
|
+
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)]",
|
|
137
|
+
children: [/* @__PURE__ */ jsx(RequestPanel, {
|
|
138
|
+
playground,
|
|
139
|
+
renderParameterField,
|
|
140
|
+
renderBodyField,
|
|
141
|
+
className: cn(view !== "request" && "max-md:hidden")
|
|
142
|
+
}), /* @__PURE__ */ jsx(ResponsePanel, {
|
|
143
|
+
response,
|
|
144
|
+
loading: isSending,
|
|
145
|
+
onReset: clearResponse,
|
|
146
|
+
ResultDisplay,
|
|
147
|
+
className: cn("md:border-s", view !== "response" && "max-md:hidden")
|
|
148
|
+
})]
|
|
286
149
|
})
|
|
287
|
-
|
|
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" }
|
|
150
|
+
]
|
|
344
151
|
});
|
|
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
152
|
}
|
|
354
|
-
function
|
|
355
|
-
const {
|
|
356
|
-
const [open, setOpen] = useState(false);
|
|
357
|
-
const engine = useDataEngine();
|
|
153
|
+
function ExampleSelect() {
|
|
154
|
+
const { items, selected, select } = useExampleRequests();
|
|
358
155
|
const t = useTranslations({ note: "playground" });
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}), /* @__PURE__ */ jsx(OAuthDialogContent, {
|
|
381
|
-
setOpen,
|
|
382
|
-
schemeId: field.schemeId,
|
|
383
|
-
scopes: field.scopes,
|
|
384
|
-
setToken: (token) => engine.update(["header", "Authorization"], token)
|
|
385
|
-
})]
|
|
386
|
-
})]
|
|
156
|
+
if (items.length <= 1) return null;
|
|
157
|
+
const options = items.map((item) => ({
|
|
158
|
+
value: item.id,
|
|
159
|
+
label: item.name
|
|
160
|
+
}));
|
|
161
|
+
return /* @__PURE__ */ jsxs(Select, {
|
|
162
|
+
items: options,
|
|
163
|
+
value: selected ?? null,
|
|
164
|
+
onValueChange: (v) => v !== null && select(v),
|
|
165
|
+
children: [/* @__PURE__ */ jsxs(SelectTrigger, {
|
|
166
|
+
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",
|
|
167
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
168
|
+
className: "text-fd-muted-foreground",
|
|
169
|
+
children: t("Example")
|
|
170
|
+
}), /* @__PURE__ */ jsx(SelectValue, { className: "truncate font-medium" })]
|
|
171
|
+
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
172
|
+
align: "end",
|
|
173
|
+
children: options.map((option) => /* @__PURE__ */ jsx(SelectItem, {
|
|
174
|
+
value: option.value,
|
|
175
|
+
children: option.label
|
|
176
|
+
}, option.value))
|
|
387
177
|
})]
|
|
388
178
|
});
|
|
389
179
|
}
|
|
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
180
|
const Custom = { useController(fieldName, options) {
|
|
420
181
|
const [value, setValue] = useFieldValue(fieldName, options);
|
|
421
182
|
return {
|
|
@@ -424,4 +185,4 @@ const Custom = { useController(fieldName, options) {
|
|
|
424
185
|
};
|
|
425
186
|
} };
|
|
426
187
|
//#endregion
|
|
427
|
-
export { Custom,
|
|
188
|
+
export { Custom, DefaultResultDisplay, PlaygroundClient as default };
|