fumadocs-openapi 12.5.0 → 12.5.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.
- package/css/generated/shared.css +1 -1
- package/dist/.translations/index.d.ts +0 -29
- package/dist/.translations/keys.js +1 -30
- package/dist/generate-file.js +4 -4
- package/dist/packages/shared-api/dist/.translations/index.d.ts +18 -0
- package/dist/packages/shared-api/dist/.translations/keys.js +19 -1
- package/dist/packages/shared-api/dist/components/defaults.js +13 -19
- package/dist/{ui → packages/shared-api/dist}/components/dialog.js +2 -2
- package/dist/packages/shared-api/dist/components/example.js +51 -0
- package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js +16 -15
- package/dist/packages/shared-api/dist/components/playground/panels.js +247 -0
- package/dist/packages/shared-api/dist/components/playground/param-input.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/schema.js +5 -3
- package/dist/packages/shared-api/dist/components/playground/server-select.js +130 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +1 -1
- package/dist/{ui → packages/shared-api/dist}/components/segmented.js +2 -2
- package/dist/packages/shared-api/dist/components/select.js +6 -2
- package/dist/requests/string-utils.js +7 -1
- package/dist/server/index.js +2 -5
- package/dist/ui/operation/index.js +20 -13
- package/dist/ui/operation/usage-tabs.js +26 -47
- package/dist/ui/playground/client.js +7 -4
- package/dist/ui/playground/components/oauth-panel.js +2 -2
- package/dist/ui/playground/components/request-panel.js +12 -195
- package/dist/ui/playground/components/response-panel.js +5 -3
- package/dist/ui/playground/components/result-display.d.ts +0 -1
- package/dist/ui/playground/components/result-display.js +3 -18
- package/dist/ui/playground/components/server-select.js +24 -122
- package/dist/ui/playground/components/url-bar.js +6 -47
- package/dist/utils/create-page.d.ts +1 -0
- package/dist/utils/pages/builder.js +2 -2
- package/dist/utils/pages/preset-auto.js +15 -4
- package/dist/utils/pages/to-static-data.js +2 -7
- package/dist/utils/pages/to-text.js +2 -2
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { OperationProvider, useOperation } from "../../operation.js";
|
|
3
|
-
import { useOpenAPI, useRenderContext
|
|
3
|
+
import { useOpenAPI, useRenderContext } from "../../utils/create-page.js";
|
|
4
4
|
import { Badge } from "../../packages/shared-api/dist/components/badge.js";
|
|
5
5
|
import { MethodLabel } from "../components/method-label.js";
|
|
6
6
|
import { Markdown } from "../components/markdown.js";
|
|
@@ -10,9 +10,9 @@ import { AnchorSection, useAnchorLink } from "../../packages/shared-api/dist/aut
|
|
|
10
10
|
import { SchemaUI } from "../components/schema.js";
|
|
11
11
|
import { SelectTab, SelectTabTrigger, SelectTabs } from "../../packages/shared-api/dist/components/select-tab.js";
|
|
12
12
|
import { Heading } from "../components/heading.js";
|
|
13
|
-
import { Segmented, SegmentedList, SegmentedPanel } from "
|
|
13
|
+
import { Segmented, SegmentedList, SegmentedPanel } from "../../packages/shared-api/dist/components/segmented.js";
|
|
14
14
|
import { EndpointBar } from "../components/endpoint.js";
|
|
15
|
-
import { DialogPopup } from "
|
|
15
|
+
import { DialogPopup } from "../../packages/shared-api/dist/components/dialog.js";
|
|
16
16
|
import PlaygroundClient from "../playground/client.js";
|
|
17
17
|
import { Fragment, useState } from "react";
|
|
18
18
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -286,11 +286,7 @@ function CardSelector({ items }) {
|
|
|
286
286
|
/** the schema of a request body or response in a media type */
|
|
287
287
|
function MediaContent({ schema, required, selector, request = false }) {
|
|
288
288
|
const { method } = useOperation();
|
|
289
|
-
const
|
|
290
|
-
name: request ? "RequestBody" : "ResponseBody",
|
|
291
|
-
readOnly: !request,
|
|
292
|
-
writeOnly: request
|
|
293
|
-
});
|
|
289
|
+
const { doc, generateTypeScriptDefinitions } = useOpenAPI();
|
|
294
290
|
if (!schema) return /* @__PURE__ */ jsx("div", {
|
|
295
291
|
className: "not-prose flex h-9 items-center rounded-xl border bg-fd-card ps-1.5 pe-1 text-[0.8125rem]",
|
|
296
292
|
children: selector
|
|
@@ -301,9 +297,14 @@ function MediaContent({ schema, required, selector, request = false }) {
|
|
|
301
297
|
as: "body",
|
|
302
298
|
required,
|
|
303
299
|
selector,
|
|
304
|
-
actions:
|
|
305
|
-
|
|
306
|
-
|
|
300
|
+
actions: generateTypeScriptDefinitions && /* @__PURE__ */ jsx(CopyTypeScript, {
|
|
301
|
+
name: request ? "request body" : "response body",
|
|
302
|
+
generate: () => generateTypeScriptDefinitions(schema, {
|
|
303
|
+
name: request ? "RequestBody" : "ResponseBody",
|
|
304
|
+
readOnly: !request,
|
|
305
|
+
writeOnly: request,
|
|
306
|
+
doc
|
|
307
|
+
})
|
|
307
308
|
})
|
|
308
309
|
},
|
|
309
310
|
root: schema,
|
|
@@ -311,9 +312,15 @@ function MediaContent({ schema, required, selector, request = false }) {
|
|
|
311
312
|
writeOnly: request && method !== "get"
|
|
312
313
|
});
|
|
313
314
|
}
|
|
314
|
-
function CopyTypeScript({
|
|
315
|
+
function CopyTypeScript({ name, generate }) {
|
|
315
316
|
const t = useTranslations({ note: "TypeScript definitions" });
|
|
316
|
-
const [isChecked, onCopy] = useCopyButton(() =>
|
|
317
|
+
const [isChecked, onCopy] = useCopyButton(() => {
|
|
318
|
+
const code = generate();
|
|
319
|
+
if (typeof code === "string") return navigator.clipboard.writeText(code);
|
|
320
|
+
return Promise.resolve(code).then((code) => {
|
|
321
|
+
if (code) return navigator.clipboard.writeText(code);
|
|
322
|
+
});
|
|
323
|
+
});
|
|
317
324
|
return /* @__PURE__ */ jsxs("button", {
|
|
318
325
|
type: "button",
|
|
319
326
|
title: t("Use the {name} type in TypeScript.", { variables: { name } }),
|
|
@@ -3,6 +3,7 @@ import { useCodeUsage, useExampleRequests, useOperation, useResponseExamples } f
|
|
|
3
3
|
import { useOpenAPI, useRenderContext } from "../../utils/create-page.js";
|
|
4
4
|
import { MethodLabel } from "../components/method-label.js";
|
|
5
5
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
|
|
6
|
+
import { ExampleHeader, ExampleSelect, captionedCodeBlock, cardCodeBlock, exampleCardClassName } from "../../packages/shared-api/dist/components/example.js";
|
|
6
7
|
import { ClientCodeBlock } from "../components/codeblock.js";
|
|
7
8
|
import { Markdown } from "../components/markdown.js";
|
|
8
9
|
import { cn } from "../../utils/cn.js";
|
|
@@ -12,25 +13,17 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
12
13
|
import { useTranslations } from "@fuma-translate/react";
|
|
13
14
|
import { Switch } from "@base-ui/react/switch";
|
|
14
15
|
//#region src/ui/operation/usage-tabs.tsx
|
|
15
|
-
/** a code block filling its card */
|
|
16
|
-
const cardCodeBlock = {
|
|
17
|
-
className: "flex min-h-0 flex-col rounded-none border-0 bg-transparent shadow-none",
|
|
18
|
-
viewportProps: { className: "min-h-0" }
|
|
19
|
-
};
|
|
20
|
-
/** a code block under its caption */
|
|
21
|
-
const captionedCodeBlock = {
|
|
22
|
-
...cardCodeBlock,
|
|
23
|
-
viewportProps: { className: "min-h-0 pt-2" }
|
|
24
|
-
};
|
|
25
16
|
function UsageTabs() {
|
|
26
17
|
const ctx = useRenderContext();
|
|
27
18
|
const t = useTranslations({ note: "operation page" });
|
|
28
19
|
const { operation, codeUsages } = useOperation();
|
|
20
|
+
const selectable = !operation["x-exclusiveCodeSample"];
|
|
29
21
|
const slots = {
|
|
30
|
-
selector:
|
|
22
|
+
selector: ctx.content?.renderAPIExampleUsageTabs && selectable ? /* @__PURE__ */ jsx(UsageTabsSelector, {}) : null,
|
|
31
23
|
usageTabs: ctx.content?.renderAPIExampleUsageTabs ? ctx.content.renderAPIExampleUsageTabs(codeUsages, ctx) : /* @__PURE__ */ jsx(CodeUsages, {
|
|
32
24
|
title: t("Example Request"),
|
|
33
|
-
|
|
25
|
+
selectExample: selectable,
|
|
26
|
+
className: cn("mb-4", exampleCardClassName)
|
|
34
27
|
}),
|
|
35
28
|
responseTabs: /* @__PURE__ */ jsx(ResponseTabs, {})
|
|
36
29
|
};
|
|
@@ -73,33 +66,6 @@ function UsageTabsSelector() {
|
|
|
73
66
|
}, item.value)) })]
|
|
74
67
|
});
|
|
75
68
|
}
|
|
76
|
-
function ExampleHeader({ title, children }) {
|
|
77
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
78
|
-
className: "flex h-10 shrink-0 items-center gap-2 border-b ps-4 pe-1.5 text-[0.8125rem] font-medium",
|
|
79
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
80
|
-
className: "me-auto truncate",
|
|
81
|
-
children: title
|
|
82
|
-
}), children]
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function ExampleSelect({ items, value, onValueChange, className }) {
|
|
86
|
-
return /* @__PURE__ */ jsxs(Select, {
|
|
87
|
-
items,
|
|
88
|
-
value,
|
|
89
|
-
onValueChange: (v) => v !== null && onValueChange(v),
|
|
90
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
91
|
-
className: cn("h-7 w-fit max-w-1/2 shrink-0 gap-1.5 border-0 bg-transparent px-2 py-0 text-[0.8125rem] font-medium text-fd-muted-foreground hover:text-fd-accent-foreground focus:ring-0 focus-visible:ring-2 data-popup-open:bg-fd-accent data-popup-open:text-fd-accent-foreground", className),
|
|
92
|
-
children: /* @__PURE__ */ jsx(SelectValue, { className: "min-w-0 truncate" })
|
|
93
|
-
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
94
|
-
align: "end",
|
|
95
|
-
children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
96
|
-
value: item.value,
|
|
97
|
-
className: "text-[0.8125rem]",
|
|
98
|
-
children: item.label
|
|
99
|
-
}, item.value))
|
|
100
|
-
})]
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
69
|
const storageKey = "fumadocs_openapi_requests";
|
|
104
70
|
const listeners = /* @__PURE__ */ new Set();
|
|
105
71
|
function subscribe(listener) {
|
|
@@ -113,8 +79,9 @@ function select(id) {
|
|
|
113
79
|
for (const listener of listeners) listener();
|
|
114
80
|
}
|
|
115
81
|
/** the code usages of the selected example request, with a select of their languages */
|
|
116
|
-
function CodeUsages({ title, className, viewportClassName }) {
|
|
82
|
+
function CodeUsages({ title, selectExample = false, className, viewportClassName }) {
|
|
117
83
|
const generators = useOperation().codeUsages.map();
|
|
84
|
+
const examples = useExampleRequests();
|
|
118
85
|
const selected = useSyncExternalStore(subscribe, () => sessionStorage.getItem(storageKey), () => null);
|
|
119
86
|
const id = selected !== null && generators.has(selected) ? selected : generators.keys().next().value;
|
|
120
87
|
const code = useCodeUsage(id ?? "");
|
|
@@ -123,18 +90,29 @@ function CodeUsages({ title, className, viewportClassName }) {
|
|
|
123
90
|
value,
|
|
124
91
|
label: item.label ?? item.lang
|
|
125
92
|
}));
|
|
93
|
+
const example = selectExample && examples.items.length > 1 ? examples.items.find((item) => item.id === examples.selected) : void 0;
|
|
126
94
|
return /* @__PURE__ */ jsxs("div", {
|
|
127
95
|
className,
|
|
128
|
-
children: [/* @__PURE__ */
|
|
129
|
-
title,
|
|
130
|
-
children:
|
|
96
|
+
children: [/* @__PURE__ */ jsxs(ExampleHeader, {
|
|
97
|
+
title: !example && title,
|
|
98
|
+
children: [example && /* @__PURE__ */ jsx(ExampleSelect, {
|
|
99
|
+
items: examples.items.map((item) => ({
|
|
100
|
+
value: item.id,
|
|
101
|
+
label: item.name,
|
|
102
|
+
description: item.description && /* @__PURE__ */ jsx(Markdown, { md: item.description })
|
|
103
|
+
})),
|
|
104
|
+
value: example.id,
|
|
105
|
+
onValueChange: examples.select,
|
|
106
|
+
align: "start",
|
|
107
|
+
className: "-ms-2 me-auto max-w-none min-w-0 shrink text-fd-foreground"
|
|
108
|
+
}), items.length > 1 ? /* @__PURE__ */ jsx(ExampleSelect, {
|
|
131
109
|
items,
|
|
132
110
|
value: id,
|
|
133
111
|
onValueChange: select
|
|
134
112
|
}) : /* @__PURE__ */ jsx("span", {
|
|
135
113
|
className: "px-2 text-fd-muted-foreground",
|
|
136
114
|
children: items[0].label
|
|
137
|
-
})
|
|
115
|
+
})]
|
|
138
116
|
}), code && /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
139
117
|
lang: generators.get(id).lang,
|
|
140
118
|
code,
|
|
@@ -179,6 +157,7 @@ function ResponseTabsDefaultContent({ tabs }) {
|
|
|
179
157
|
})),
|
|
180
158
|
value: String(index),
|
|
181
159
|
onValueChange: (v) => setIndex(Number(v)),
|
|
160
|
+
align: "start",
|
|
182
161
|
className: "-ms-2"
|
|
183
162
|
}), example.description && /* @__PURE__ */ jsx("div", {
|
|
184
163
|
className: "prose prose-xs prose-no-margin text-fd-muted-foreground",
|
|
@@ -194,7 +173,7 @@ function ResponseTabsDefaultContent({ tabs }) {
|
|
|
194
173
|
children: t("Empty")
|
|
195
174
|
});
|
|
196
175
|
return /* @__PURE__ */ jsxs("div", {
|
|
197
|
-
className: "mb-4
|
|
176
|
+
className: cn("mb-4", exampleCardClassName),
|
|
198
177
|
children: [/* @__PURE__ */ jsxs(ExampleHeader, {
|
|
199
178
|
title: t("Example Response"),
|
|
200
179
|
children: [schema !== void 0 && /* @__PURE__ */ jsxs("label", {
|
|
@@ -247,7 +226,7 @@ function RequestTabsDefaultContent() {
|
|
|
247
226
|
path: t("Path Parameters")
|
|
248
227
|
};
|
|
249
228
|
return /* @__PURE__ */ jsxs("div", {
|
|
250
|
-
className:
|
|
229
|
+
className: exampleCardClassName,
|
|
251
230
|
children: [
|
|
252
231
|
/* @__PURE__ */ jsx(ExampleHeader, {
|
|
253
232
|
title: t("Example Requests"),
|
|
@@ -299,4 +278,4 @@ function RequestTabsDefaultContent() {
|
|
|
299
278
|
});
|
|
300
279
|
}
|
|
301
280
|
//#endregion
|
|
302
|
-
export { CodeUsages,
|
|
281
|
+
export { CodeUsages, RequestTabs, UsageTabs };
|
|
@@ -3,12 +3,14 @@ import { useExampleRequests, useOperation } from "../../operation.js";
|
|
|
3
3
|
import { useOpenAPI } from "../../utils/create-page.js";
|
|
4
4
|
import { usePlayground } from "../../playground/use-playground.js";
|
|
5
5
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
|
|
6
|
+
import { Markdown } from "../components/markdown.js";
|
|
6
7
|
import { cn } from "../../utils/cn.js";
|
|
7
|
-
import { Segmented, SegmentedList } from "
|
|
8
|
-
import { DefaultResultDisplay, iconButtonClassName } from "./components/result-display.js";
|
|
9
|
-
import { EndpointBar } from "../components/endpoint.js";
|
|
10
|
-
import { DialogPopup } from "../components/dialog.js";
|
|
8
|
+
import { Segmented, SegmentedList } from "../../packages/shared-api/dist/components/segmented.js";
|
|
11
9
|
import { SchemaProvider } from "../../packages/shared-api/dist/components/playground/schema.js";
|
|
10
|
+
import { iconButtonClassName } from "../../packages/shared-api/dist/components/playground/panels.js";
|
|
11
|
+
import { DefaultResultDisplay } from "./components/result-display.js";
|
|
12
|
+
import { EndpointBar } from "../components/endpoint.js";
|
|
13
|
+
import { DialogPopup } from "../../packages/shared-api/dist/components/dialog.js";
|
|
12
14
|
import { UrlBar } from "./components/url-bar.js";
|
|
13
15
|
import { RequestPanel, mutualTLSProvider } from "./components/request-panel.js";
|
|
14
16
|
import { oauthPanelProvider } from "./components/oauth-panel.js";
|
|
@@ -46,6 +48,7 @@ function PlaygroundClient({ writeOnly = true, readOnly = false, authProviders, t
|
|
|
46
48
|
docRoot: doc.dereferenced,
|
|
47
49
|
writeOnly,
|
|
48
50
|
readOnly,
|
|
51
|
+
Markdown,
|
|
49
52
|
children: /* @__PURE__ */ jsxs(Dialog.Root, {
|
|
50
53
|
open,
|
|
51
54
|
onOpenChange: setOpen,
|
|
@@ -5,9 +5,9 @@ import { finishOAuthFlow, requestOAuthToken, useAuthRedirect, useOpenIdConnectFl
|
|
|
5
5
|
import { useOpenAPI } from "../../../utils/create-page.js";
|
|
6
6
|
import { Markdown } from "../../components/markdown.js";
|
|
7
7
|
import { cn } from "../../../utils/cn.js";
|
|
8
|
-
import {
|
|
8
|
+
import { CheckRow, SelectRow, TextRow, ValueRow } from "../../../packages/shared-api/dist/components/playground/fields.js";
|
|
9
|
+
import { iconButtonClassName } from "../../../packages/shared-api/dist/components/playground/panels.js";
|
|
9
10
|
import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
|
|
10
|
-
import { CheckRow, SelectRow, TextRow, ValueRow } from "./fields.js";
|
|
11
11
|
import { Suspense, useEffect, useRef, useState } from "react";
|
|
12
12
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { StfProvider, useDataEngine, useStf } from "@fumari/stf";
|
|
@@ -3,16 +3,16 @@ import { useOperation } from "../../../operation.js";
|
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
4
|
import { Markdown } from "../../components/markdown.js";
|
|
5
5
|
import { cn } from "../../../utils/cn.js";
|
|
6
|
-
import { Segmented, SegmentedList } from "
|
|
7
|
-
import { anyFields, useResolvedSchema
|
|
8
|
-
import { FieldRow, FieldRows, LinkRow, ValueRow,
|
|
6
|
+
import { Segmented, SegmentedList } from "../../../packages/shared-api/dist/components/segmented.js";
|
|
7
|
+
import { anyFields, useResolvedSchema } from "../../../packages/shared-api/dist/components/playground/schema.js";
|
|
8
|
+
import { FieldRow, FieldRows, LinkRow, ValueRow, getRemoval } from "../../../packages/shared-api/dist/components/playground/fields.js";
|
|
9
|
+
import { Crumb, FieldPanel, OverviewLayer, Panel, PanelNav, Section, useFieldStack } from "../../../packages/shared-api/dist/components/playground/panels.js";
|
|
9
10
|
import { Fragment, createContext, use, useState } from "react";
|
|
10
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
import { useDataEngine, useFieldValue } from "@fumari/stf";
|
|
12
13
|
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
13
14
|
import { useTranslations } from "@fuma-translate/react";
|
|
14
|
-
import {
|
|
15
|
-
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
15
|
+
import { Braces, Cookie, KeyRound, PlusIcon, Route, Rows3, ShieldCheck, SlidersHorizontal } from "lucide-react";
|
|
16
16
|
//#region src/ui/playground/components/request-panel.tsx
|
|
17
17
|
const sectionIcons = {
|
|
18
18
|
path: Route,
|
|
@@ -20,22 +20,11 @@ const sectionIcons = {
|
|
|
20
20
|
header: Rows3,
|
|
21
21
|
cookie: Cookie
|
|
22
22
|
};
|
|
23
|
-
const motionClassNames = {
|
|
24
|
-
forward: "motion-safe:starting:translate-x-6",
|
|
25
|
-
back: "motion-safe:starting:-translate-x-6",
|
|
26
|
-
next: "motion-safe:starting:translate-y-4",
|
|
27
|
-
previous: "motion-safe:starting:-translate-y-4"
|
|
28
|
-
};
|
|
29
|
-
const transitionClassName = "motion-safe:transition-[opacity,translate] motion-safe:duration-300 motion-safe:ease-[cubic-bezier(0.16,1,0.3,1)]";
|
|
30
23
|
/** the overview of all request inputs, nested fields open in their own panel */
|
|
31
24
|
function RequestPanel({ playground: { auth, body }, onSubmit, className, ...options }) {
|
|
32
25
|
const t = useTranslations({ note: "playground" });
|
|
33
|
-
const
|
|
34
|
-
const { generateDefault } = useSchemaUtils();
|
|
35
|
-
const [stack, setStack] = useState([]);
|
|
26
|
+
const fields = useFieldStack();
|
|
36
27
|
const [authorizing, setAuthorizing] = useState(null);
|
|
37
|
-
const [motion, setMotion] = useState("forward");
|
|
38
|
-
const current = stack.at(-1);
|
|
39
28
|
const sectionNames = {
|
|
40
29
|
path: t("Path"),
|
|
41
30
|
query: t("Query"),
|
|
@@ -43,21 +32,6 @@ function RequestPanel({ playground: { auth, body }, onSubmit, className, ...opti
|
|
|
43
32
|
cookie: t("Cookies"),
|
|
44
33
|
body: t("Body")
|
|
45
34
|
};
|
|
46
|
-
function navigate(next, nextMotion) {
|
|
47
|
-
const target = next.at(-1);
|
|
48
|
-
if (target) engine.init(target.fieldName, () => {
|
|
49
|
-
const field = resolveField(target.schema, void 0);
|
|
50
|
-
return field ? generateDefault(field) : void 0;
|
|
51
|
-
});
|
|
52
|
-
setMotion(nextMotion ?? (next.length >= stack.length ? "forward" : "back"));
|
|
53
|
-
setStack(next);
|
|
54
|
-
}
|
|
55
|
-
function openNested(parents) {
|
|
56
|
-
return (entry, siblings) => navigate([...parents, {
|
|
57
|
-
...entry,
|
|
58
|
-
siblings: getNestedFields(engine, siblings)
|
|
59
|
-
}]);
|
|
60
|
-
}
|
|
61
35
|
let panel = null;
|
|
62
36
|
if (authorizing) {
|
|
63
37
|
const { field, component: Component } = authorizing;
|
|
@@ -80,19 +54,9 @@ function RequestPanel({ playground: { auth, body }, onSubmit, className, ...opti
|
|
|
80
54
|
close
|
|
81
55
|
})
|
|
82
56
|
});
|
|
83
|
-
} else if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
nav: /* @__PURE__ */ jsx(Breadcrumbs, {
|
|
87
|
-
root: sectionNames[stack[0].fieldName[0]],
|
|
88
|
-
stack,
|
|
89
|
-
onNavigate: navigate
|
|
90
|
-
}),
|
|
91
|
-
children: /* @__PURE__ */ jsx(FieldRows, {
|
|
92
|
-
entry: current,
|
|
93
|
-
showDescription: true,
|
|
94
|
-
onNavigate: openNested(stack)
|
|
95
|
-
})
|
|
57
|
+
} else if (fields.stack.length > 0) panel = /* @__PURE__ */ jsx(FieldPanel, {
|
|
58
|
+
fields,
|
|
59
|
+
root: sectionNames[fields.stack[0].fieldName[0]]
|
|
96
60
|
});
|
|
97
61
|
return /* @__PURE__ */ jsxs("div", {
|
|
98
62
|
className: cn("@container grid min-h-0", className),
|
|
@@ -100,144 +64,20 @@ function RequestPanel({ playground: { auth, body }, onSubmit, className, ...opti
|
|
|
100
64
|
noValidate: true,
|
|
101
65
|
className: "contents",
|
|
102
66
|
onSubmit,
|
|
103
|
-
children: [/* @__PURE__ */ jsx(
|
|
104
|
-
|
|
67
|
+
children: [/* @__PURE__ */ jsx(OverviewLayer, {
|
|
68
|
+
covered: panel !== null,
|
|
105
69
|
children: /* @__PURE__ */ jsx(Overview, {
|
|
106
70
|
...options,
|
|
107
71
|
auth,
|
|
108
72
|
body,
|
|
109
73
|
sectionNames,
|
|
110
|
-
onNavigate: openNested([]),
|
|
74
|
+
onNavigate: fields.openNested([]),
|
|
111
75
|
onAuthorize: setAuthorizing
|
|
112
76
|
})
|
|
113
77
|
}), !authorizing && panel]
|
|
114
78
|
}), authorizing && panel]
|
|
115
79
|
});
|
|
116
80
|
}
|
|
117
|
-
/** a panel over the overview, its content animates in when `id` changes */
|
|
118
|
-
function Panel({ id, motion, nav, children }) {
|
|
119
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
120
|
-
className: "flex min-h-0 flex-col [grid-area:1/1]",
|
|
121
|
-
children: [nav, /* @__PURE__ */ jsx("div", {
|
|
122
|
-
className: cn("fd-scroll-container min-h-0 flex-1 overflow-y-auto starting:opacity-0", transitionClassName, motionClassNames[motion]),
|
|
123
|
-
children
|
|
124
|
-
}, id)]
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
const crumbClassName = "truncate rounded-md px-1.5 py-1 text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring";
|
|
128
|
-
/** the bar on top of a panel, going back to the overview from `root` */
|
|
129
|
-
function PanelNav({ root, onRoot, onBack, end, children }) {
|
|
130
|
-
const t = useTranslations({ note: "playground" });
|
|
131
|
-
return /* @__PURE__ */ jsxs("nav", {
|
|
132
|
-
"aria-label": t("Breadcrumb"),
|
|
133
|
-
className: "flex h-10 shrink-0 items-center gap-1 border-b ps-1.5 pe-1.5 text-[0.8125rem]",
|
|
134
|
-
children: [
|
|
135
|
-
/* @__PURE__ */ jsx("button", {
|
|
136
|
-
type: "button",
|
|
137
|
-
"aria-label": t("Back"),
|
|
138
|
-
onClick: onBack,
|
|
139
|
-
className: cn(buttonVariants({
|
|
140
|
-
variant: "ghost",
|
|
141
|
-
size: "icon-xs"
|
|
142
|
-
}), "me-1 text-fd-muted-foreground"),
|
|
143
|
-
children: /* @__PURE__ */ jsx(ArrowLeft, {})
|
|
144
|
-
}),
|
|
145
|
-
/* @__PURE__ */ jsxs("ol", {
|
|
146
|
-
className: "flex min-w-0 items-center gap-0.5",
|
|
147
|
-
children: [/* @__PURE__ */ jsx("li", {
|
|
148
|
-
className: "flex min-w-0 shrink-0 items-center",
|
|
149
|
-
children: /* @__PURE__ */ jsx("button", {
|
|
150
|
-
type: "button",
|
|
151
|
-
onClick: onRoot,
|
|
152
|
-
className: crumbClassName,
|
|
153
|
-
children: root
|
|
154
|
-
})
|
|
155
|
-
}), children]
|
|
156
|
-
}),
|
|
157
|
-
end
|
|
158
|
-
]
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
function Crumb({ children }) {
|
|
162
|
-
return /* @__PURE__ */ jsxs("li", {
|
|
163
|
-
className: "flex min-w-0 items-center gap-0.5 last:shrink-0 motion-safe:transition-opacity motion-safe:starting:opacity-0",
|
|
164
|
-
children: [/* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 shrink-0 text-fd-muted-foreground/60" }), children]
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
function Breadcrumbs({ root, stack, onNavigate }) {
|
|
168
|
-
const t = useTranslations({ note: "playground" });
|
|
169
|
-
const engine = useDataEngine();
|
|
170
|
-
const current = stack[stack.length - 1];
|
|
171
|
-
return /* @__PURE__ */ jsx(PanelNav, {
|
|
172
|
-
root,
|
|
173
|
-
onRoot: () => onNavigate([]),
|
|
174
|
-
onBack: () => onNavigate(stack.slice(0, -1)),
|
|
175
|
-
end: current.removal && /* @__PURE__ */ jsx("button", {
|
|
176
|
-
type: "button",
|
|
177
|
-
onClick: () => {
|
|
178
|
-
engine.delete(current.fieldName);
|
|
179
|
-
onNavigate(stack.slice(0, -1));
|
|
180
|
-
},
|
|
181
|
-
className: cn(buttonVariants({
|
|
182
|
-
variant: "ghost",
|
|
183
|
-
size: "sm"
|
|
184
|
-
}), "ms-auto shrink-0 text-fd-muted-foreground"),
|
|
185
|
-
children: current.removal === "remove" ? t("Remove") : t("Unset")
|
|
186
|
-
}),
|
|
187
|
-
children: stack.map((entry, i) => {
|
|
188
|
-
const { siblings } = entry;
|
|
189
|
-
let node;
|
|
190
|
-
if (i < stack.length - 1) node = /* @__PURE__ */ jsx("button", {
|
|
191
|
-
type: "button",
|
|
192
|
-
onClick: () => onNavigate(stack.slice(0, i + 1)),
|
|
193
|
-
className: cn(crumbClassName, "font-mono"),
|
|
194
|
-
children: entry.name
|
|
195
|
-
});
|
|
196
|
-
else if (siblings && siblings.length > 1) node = /* @__PURE__ */ jsx(SiblingSelect, {
|
|
197
|
-
entry,
|
|
198
|
-
siblings,
|
|
199
|
-
onSelect: (sibling, motion) => onNavigate([...stack.slice(0, -1), {
|
|
200
|
-
...sibling,
|
|
201
|
-
siblings
|
|
202
|
-
}], motion)
|
|
203
|
-
});
|
|
204
|
-
else node = /* @__PURE__ */ jsx("span", {
|
|
205
|
-
"aria-current": "page",
|
|
206
|
-
className: "truncate px-1.5 py-1 font-mono font-medium",
|
|
207
|
-
children: entry.name
|
|
208
|
-
});
|
|
209
|
-
return /* @__PURE__ */ jsx(Crumb, { children: node }, stringifyFieldKey(entry.fieldName));
|
|
210
|
-
})
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
/** the current field, switches to the other nested fields of its parent */
|
|
214
|
-
function SiblingSelect({ entry, siblings, onSelect }) {
|
|
215
|
-
const t = useTranslations({ note: "playground" });
|
|
216
|
-
const current = stringifyFieldKey(entry.fieldName);
|
|
217
|
-
const items = siblings.map((item) => ({
|
|
218
|
-
value: stringifyFieldKey(item.fieldName),
|
|
219
|
-
label: item.name
|
|
220
|
-
}));
|
|
221
|
-
return /* @__PURE__ */ jsxs(Select, {
|
|
222
|
-
items,
|
|
223
|
-
value: current,
|
|
224
|
-
onValueChange: (value) => {
|
|
225
|
-
const next = items.findIndex((item) => item.value === value);
|
|
226
|
-
if (next === -1 || value === current) return;
|
|
227
|
-
const prev = items.findIndex((item) => item.value === current);
|
|
228
|
-
onSelect(siblings[next], next > prev ? "next" : "previous");
|
|
229
|
-
},
|
|
230
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
231
|
-
"aria-label": t("Switch Field"),
|
|
232
|
-
className: "h-7 w-auto min-w-0 gap-1 border-0 bg-transparent px-1.5 py-0 font-mono text-[0.8125rem] font-medium text-fd-foreground hover:bg-fd-accent focus:ring-0 focus-visible:ring-2 data-popup-open:bg-fd-accent",
|
|
233
|
-
children: /* @__PURE__ */ jsx(SelectValue, { className: "truncate" })
|
|
234
|
-
}), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
235
|
-
value: item.value,
|
|
236
|
-
className: "font-mono text-[0.8125rem]",
|
|
237
|
-
children: item.label
|
|
238
|
-
}, item.value)) })]
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
81
|
function Overview({ auth, body, sectionNames, onNavigate, onAuthorize, renderParameterField, renderBodyField }) {
|
|
242
82
|
const t = useTranslations({ note: "playground" });
|
|
243
83
|
const { parameters } = useOperation();
|
|
@@ -280,29 +120,6 @@ function getParameterSchema(param) {
|
|
|
280
120
|
if (param.content) for (const type in param.content) return param.content[type].schema ?? anyFields;
|
|
281
121
|
return param.schema ?? anyFields;
|
|
282
122
|
}
|
|
283
|
-
function Section({ icon: Icon, title, count, actions, children }) {
|
|
284
|
-
return /* @__PURE__ */ jsxs("section", {
|
|
285
|
-
className: "border-b last:border-b-0",
|
|
286
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
287
|
-
className: "sticky top-0 z-10 flex h-10 items-center gap-2 border-b bg-fd-card ps-4 pe-2 @sm:pe-7.5",
|
|
288
|
-
children: [
|
|
289
|
-
/* @__PURE__ */ jsx(Icon, { className: "size-3.5 shrink-0 text-fd-primary" }),
|
|
290
|
-
/* @__PURE__ */ jsx("h3", {
|
|
291
|
-
className: "text-[0.8125rem] font-medium",
|
|
292
|
-
children: title
|
|
293
|
-
}),
|
|
294
|
-
count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
295
|
-
className: "text-xs text-fd-muted-foreground tabular-nums",
|
|
296
|
-
children: count
|
|
297
|
-
}),
|
|
298
|
-
/* @__PURE__ */ jsx("div", {
|
|
299
|
-
className: "flex min-w-0 flex-1 items-center justify-end gap-2",
|
|
300
|
-
children: actions
|
|
301
|
-
})
|
|
302
|
-
]
|
|
303
|
-
}), children]
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
123
|
function AuthSection({ auth, onAuthorize }) {
|
|
307
124
|
const t = useTranslations({ note: "playground" });
|
|
308
125
|
const { requirements, selected, select, fields } = auth;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useResponseExamples } from "../../../operation.js";
|
|
3
|
+
import { ExampleSelect } from "../../../packages/shared-api/dist/components/example.js";
|
|
3
4
|
import { ClientCodeBlock } from "../../components/codeblock.js";
|
|
4
5
|
import { Markdown } from "../../components/markdown.js";
|
|
5
6
|
import { cn } from "../../../utils/cn.js";
|
|
6
|
-
import { CodeUsages
|
|
7
|
-
import { Segmented, SegmentedList, SegmentedPanel } from "
|
|
8
|
-
import {
|
|
7
|
+
import { CodeUsages } from "../../operation/usage-tabs.js";
|
|
8
|
+
import { Segmented, SegmentedList, SegmentedPanel } from "../../../packages/shared-api/dist/components/segmented.js";
|
|
9
|
+
import { PanelHeader, panelCodeBlock } from "../../../packages/shared-api/dist/components/playground/panels.js";
|
|
10
|
+
import { DefaultResultDisplay } from "./result-display.js";
|
|
9
11
|
import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
|
|
10
12
|
import { useState } from "react";
|
|
11
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FetchResult } from "../../../playground/fetcher.js";
|
|
2
2
|
import { ComponentProps } from "react";
|
|
3
|
-
import "fumadocs-ui/components/codeblock";
|
|
4
3
|
//#region src/ui/playground/components/result-display.d.ts
|
|
5
4
|
export interface ResultDisplayProps extends ComponentProps<'div'> {
|
|
6
5
|
data: FetchResult;
|
|
@@ -2,28 +2,13 @@
|
|
|
2
2
|
import { ClientCodeBlock } from "../../components/codeblock.js";
|
|
3
3
|
import { cn } from "../../../utils/cn.js";
|
|
4
4
|
import { useStatusInfo } from "../status-info.js";
|
|
5
|
-
import { Segmented, SegmentedList, SegmentedPanel } from "
|
|
5
|
+
import { Segmented, SegmentedList, SegmentedPanel } from "../../../packages/shared-api/dist/components/segmented.js";
|
|
6
|
+
import { PanelHeader, iconButtonClassName, panelCodeBlock } from "../../../packages/shared-api/dist/components/playground/panels.js";
|
|
6
7
|
import { Fragment, useCallback, useMemo, useState } from "react";
|
|
7
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { useTranslations } from "@fuma-translate/react";
|
|
9
10
|
import { DownloadIcon, FileIcon, X } from "lucide-react";
|
|
10
|
-
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
11
11
|
//#region src/ui/playground/components/result-display.tsx
|
|
12
|
-
const iconButtonClassName = cn(buttonVariants({
|
|
13
|
-
variant: "ghost",
|
|
14
|
-
size: "icon-sm"
|
|
15
|
-
}), "text-fd-muted-foreground [&_svg]:size-3.5");
|
|
16
|
-
/** a code block filling its panel */
|
|
17
|
-
const panelCodeBlock = {
|
|
18
|
-
className: "h-full rounded-none border-0 bg-transparent shadow-none",
|
|
19
|
-
viewportProps: { className: "h-full max-h-none" }
|
|
20
|
-
};
|
|
21
|
-
function PanelHeader({ className, ...props }) {
|
|
22
|
-
return /* @__PURE__ */ jsx("div", {
|
|
23
|
-
...props,
|
|
24
|
-
className: cn("flex h-10 shrink-0 items-center gap-2.5 border-b ps-4 pe-1.5", className)
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
12
|
function DefaultResultDisplay({ data, reset, ...rest }) {
|
|
28
13
|
const t = useTranslations({ note: "playground result display" });
|
|
29
14
|
if (data.type === "client_error") return /* @__PURE__ */ jsxs("div", {
|
|
@@ -246,4 +231,4 @@ function TextResult({ lang, data }) {
|
|
|
246
231
|
});
|
|
247
232
|
}
|
|
248
233
|
//#endregion
|
|
249
|
-
export { DefaultResultDisplay
|
|
234
|
+
export { DefaultResultDisplay };
|