fumadocs-openapi 12.5.1 → 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 +11 -8
- 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/requests/string-utils.js +7 -1
- package/dist/ui/operation/index.js +2 -2
- package/dist/ui/operation/usage-tabs.js +6 -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/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 +4 -4
|
@@ -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,16 +13,6 @@ 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" });
|
|
@@ -32,7 +23,7 @@ function UsageTabs() {
|
|
|
32
23
|
usageTabs: ctx.content?.renderAPIExampleUsageTabs ? ctx.content.renderAPIExampleUsageTabs(codeUsages, ctx) : /* @__PURE__ */ jsx(CodeUsages, {
|
|
33
24
|
title: t("Example Request"),
|
|
34
25
|
selectExample: selectable,
|
|
35
|
-
className: "mb-4
|
|
26
|
+
className: cn("mb-4", exampleCardClassName)
|
|
36
27
|
}),
|
|
37
28
|
responseTabs: /* @__PURE__ */ jsx(ResponseTabs, {})
|
|
38
29
|
};
|
|
@@ -75,38 +66,6 @@ function UsageTabsSelector() {
|
|
|
75
66
|
}, item.value)) })]
|
|
76
67
|
});
|
|
77
68
|
}
|
|
78
|
-
function ExampleHeader({ title, children }) {
|
|
79
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
80
|
-
className: "flex h-10 shrink-0 items-center gap-2 border-b ps-4 pe-1.5 text-[0.8125rem] font-medium",
|
|
81
|
-
children: [title && /* @__PURE__ */ jsx("span", {
|
|
82
|
-
className: "me-auto truncate",
|
|
83
|
-
children: title
|
|
84
|
-
}), children]
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
function ExampleSelect({ items, value, onValueChange, align = "end", className }) {
|
|
88
|
-
return /* @__PURE__ */ jsxs(Select, {
|
|
89
|
-
items,
|
|
90
|
-
value,
|
|
91
|
-
onValueChange: (v) => v !== null && onValueChange(v),
|
|
92
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
93
|
-
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),
|
|
94
|
-
children: /* @__PURE__ */ jsx(SelectValue, { className: "min-w-0 truncate" })
|
|
95
|
-
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
96
|
-
align,
|
|
97
|
-
className: "max-w-80",
|
|
98
|
-
children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
99
|
-
value: item.value,
|
|
100
|
-
description: item.description && /* @__PURE__ */ jsx("div", {
|
|
101
|
-
className: "prose prose-xs prose-no-margin font-normal text-fd-muted-foreground",
|
|
102
|
-
children: /* @__PURE__ */ jsx(Markdown, { md: item.description })
|
|
103
|
-
}),
|
|
104
|
-
className: "text-[0.8125rem] font-medium",
|
|
105
|
-
children: item.label
|
|
106
|
-
}, item.value))
|
|
107
|
-
})]
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
69
|
const storageKey = "fumadocs_openapi_requests";
|
|
111
70
|
const listeners = /* @__PURE__ */ new Set();
|
|
112
71
|
function subscribe(listener) {
|
|
@@ -140,7 +99,7 @@ function CodeUsages({ title, selectExample = false, className, viewportClassName
|
|
|
140
99
|
items: examples.items.map((item) => ({
|
|
141
100
|
value: item.id,
|
|
142
101
|
label: item.name,
|
|
143
|
-
description: item.description
|
|
102
|
+
description: item.description && /* @__PURE__ */ jsx(Markdown, { md: item.description })
|
|
144
103
|
})),
|
|
145
104
|
value: example.id,
|
|
146
105
|
onValueChange: examples.select,
|
|
@@ -214,7 +173,7 @@ function ResponseTabsDefaultContent({ tabs }) {
|
|
|
214
173
|
children: t("Empty")
|
|
215
174
|
});
|
|
216
175
|
return /* @__PURE__ */ jsxs("div", {
|
|
217
|
-
className: "mb-4
|
|
176
|
+
className: cn("mb-4", exampleCardClassName),
|
|
218
177
|
children: [/* @__PURE__ */ jsxs(ExampleHeader, {
|
|
219
178
|
title: t("Example Response"),
|
|
220
179
|
children: [schema !== void 0 && /* @__PURE__ */ jsxs("label", {
|
|
@@ -267,7 +226,7 @@ function RequestTabsDefaultContent() {
|
|
|
267
226
|
path: t("Path Parameters")
|
|
268
227
|
};
|
|
269
228
|
return /* @__PURE__ */ jsxs("div", {
|
|
270
|
-
className:
|
|
229
|
+
className: exampleCardClassName,
|
|
271
230
|
children: [
|
|
272
231
|
/* @__PURE__ */ jsx(ExampleHeader, {
|
|
273
232
|
title: t("Example Requests"),
|
|
@@ -319,4 +278,4 @@ function RequestTabsDefaultContent() {
|
|
|
319
278
|
});
|
|
320
279
|
}
|
|
321
280
|
//#endregion
|
|
322
|
-
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 };
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useServer } from "../../../utils/use-server.js";
|
|
3
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
3
|
import { cn } from "../../../utils/cn.js";
|
|
5
|
-
import {
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { StfProvider, useFieldValue, useListener, useStf } from "@fumari/stf";
|
|
4
|
+
import { ServerPopover, ServerVariables } from "../../../packages/shared-api/dist/components/playground/server-select.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
6
|
import { useTranslations } from "@fuma-translate/react";
|
|
9
|
-
import { Check, ChevronDown } from "lucide-react";
|
|
10
|
-
import { Popover } from "@base-ui/react/popover";
|
|
11
7
|
//#region src/ui/playground/components/server-select.tsx
|
|
12
8
|
/** the base URL of requests, selects the server and edits its variables */
|
|
13
9
|
function ServerSelect({ className }) {
|
|
14
10
|
const { servers, server, resolveUrl, setServer, setServerVariables } = useServer();
|
|
15
|
-
const [open, setOpen] = useState(false);
|
|
16
11
|
const t = useTranslations({ note: "playground server select" });
|
|
17
12
|
const base = resolveUrl().replace(/\/$/, "");
|
|
18
13
|
if (!servers || servers.length === 0) return /* @__PURE__ */ jsx("span", {
|
|
@@ -20,121 +15,28 @@ function ServerSelect({ className }) {
|
|
|
20
15
|
children: base
|
|
21
16
|
});
|
|
22
17
|
const serverSchema = server ? servers.find((item) => item.url === server.url) : void 0;
|
|
23
|
-
return /* @__PURE__ */
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const selected = item.url === server?.url;
|
|
46
|
-
return /* @__PURE__ */ jsxs("button", {
|
|
47
|
-
type: "button",
|
|
48
|
-
"aria-pressed": selected,
|
|
49
|
-
onClick: () => {
|
|
50
|
-
setServer(item.url);
|
|
51
|
-
if (!item.variables) setOpen(false);
|
|
52
|
-
},
|
|
53
|
-
className: "flex w-full items-start gap-2 rounded-lg px-2.5 py-2 text-start transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:bg-fd-accent focus-visible:outline-none",
|
|
54
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
55
|
-
className: "min-w-0 flex-1",
|
|
56
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
57
|
-
className: "block font-mono text-[0.8125rem] break-all",
|
|
58
|
-
children: item.url
|
|
59
|
-
}), item.description && /* @__PURE__ */ jsx("span", {
|
|
60
|
-
className: "mt-0.5 block text-xs text-fd-muted-foreground",
|
|
61
|
-
children: item.description
|
|
62
|
-
})]
|
|
63
|
-
}), selected && /* @__PURE__ */ jsx(Check, { className: "mt-0.5 size-3.5 shrink-0 text-fd-primary" })]
|
|
64
|
-
}, item.url);
|
|
65
|
-
}),
|
|
66
|
-
server?.variables && serverSchema?.variables && /* @__PURE__ */ jsx(ServerVariables, {
|
|
67
|
-
defaultValues: server.variables,
|
|
68
|
-
schema: serverSchema.variables,
|
|
69
|
-
onChange: setServerVariables
|
|
70
|
-
}, server.url)
|
|
71
|
-
]
|
|
72
|
-
})
|
|
73
|
-
}) })]
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function ServerVariables({ defaultValues, onChange, schema }) {
|
|
77
|
-
const t = useTranslations({ note: "playground server select" });
|
|
78
|
-
const stf = useStf({ defaultValues: () => structuredClone(defaultValues) });
|
|
79
|
-
const timerRef = useRef(null);
|
|
80
|
-
useListener({
|
|
81
|
-
stf,
|
|
82
|
-
onUpdate() {
|
|
83
|
-
if (timerRef.current !== null) window.clearTimeout(timerRef.current);
|
|
84
|
-
timerRef.current = window.setTimeout(() => onChange(stf.dataEngine.getData()), 300);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return /* @__PURE__ */ jsx(StfProvider, {
|
|
88
|
-
value: stf,
|
|
89
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
90
|
-
className: "mt-1 flex flex-col gap-2.5 border-t px-2.5 pt-2.5 pb-2",
|
|
91
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
92
|
-
className: "text-xs font-medium text-fd-muted-foreground",
|
|
93
|
-
children: t("Variables")
|
|
94
|
-
}), Object.entries(schema).map(([key, variable]) => /* @__PURE__ */ jsxs("div", {
|
|
95
|
-
className: "grid grid-cols-[minmax(0,2fr)_minmax(0,3fr)] items-center gap-3",
|
|
96
|
-
children: [/* @__PURE__ */ jsxs("label", {
|
|
97
|
-
htmlFor: `server-${key}`,
|
|
98
|
-
className: "min-w-0",
|
|
99
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
100
|
-
className: "block truncate font-mono text-[0.8125rem]",
|
|
101
|
-
children: key
|
|
102
|
-
}), variable.description && /* @__PURE__ */ jsx("span", {
|
|
103
|
-
className: "block text-xs text-fd-muted-foreground",
|
|
104
|
-
children: variable.description
|
|
105
|
-
})]
|
|
106
|
-
}), /* @__PURE__ */ jsx(VariableInput, {
|
|
107
|
-
fieldName: key,
|
|
108
|
-
variable
|
|
109
|
-
})]
|
|
110
|
-
}, key))]
|
|
111
|
-
})
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
function VariableInput({ fieldName, variable }) {
|
|
115
|
-
const t = useTranslations({ note: "playground server select" });
|
|
116
|
-
const id = `server-${fieldName}`;
|
|
117
|
-
const [value, setValue] = useFieldValue([fieldName], { compute(currentValue) {
|
|
118
|
-
return typeof currentValue === "string" ? currentValue : void 0;
|
|
119
|
-
} });
|
|
120
|
-
if (variable.enum) return /* @__PURE__ */ jsxs(Select, {
|
|
121
|
-
value: value ?? null,
|
|
122
|
-
onValueChange: (v) => v !== null && setValue(v),
|
|
123
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
124
|
-
id,
|
|
125
|
-
className: "h-8 py-1 text-[0.8125rem]",
|
|
126
|
-
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
127
|
-
}), /* @__PURE__ */ jsx(SelectContent, { children: variable.enum.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
128
|
-
value: item,
|
|
129
|
-
children: item
|
|
130
|
-
}, item)) })]
|
|
131
|
-
});
|
|
132
|
-
return /* @__PURE__ */ jsx("input", {
|
|
133
|
-
id,
|
|
134
|
-
value: value ?? "",
|
|
135
|
-
onChange: (e) => setValue(e.target.value),
|
|
136
|
-
placeholder: t("Enter Value"),
|
|
137
|
-
className: "h-8 w-full rounded-md border bg-fd-secondary px-2 font-mono text-[0.8125rem] text-fd-secondary-foreground outline-none placeholder:text-fd-muted-foreground focus-visible:ring-2 focus-visible:ring-fd-ring"
|
|
18
|
+
return /* @__PURE__ */ jsx(ServerPopover, {
|
|
19
|
+
label: base,
|
|
20
|
+
title: t("Server URL"),
|
|
21
|
+
value: server?.url,
|
|
22
|
+
onValueChange: setServer,
|
|
23
|
+
className,
|
|
24
|
+
options: servers.map((item) => ({
|
|
25
|
+
value: item.url,
|
|
26
|
+
hasVariables: item.variables !== void 0,
|
|
27
|
+
label: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
28
|
+
className: "block font-mono text-[0.8125rem] break-all",
|
|
29
|
+
children: item.url
|
|
30
|
+
}), item.description && /* @__PURE__ */ jsx("span", {
|
|
31
|
+
className: "mt-0.5 block text-xs text-fd-muted-foreground",
|
|
32
|
+
children: item.description
|
|
33
|
+
})] })
|
|
34
|
+
})),
|
|
35
|
+
children: server?.variables && serverSchema?.variables && /* @__PURE__ */ jsx(ServerVariables, {
|
|
36
|
+
defaultValues: server.variables,
|
|
37
|
+
variables: serverSchema.variables,
|
|
38
|
+
onChange: setServerVariables
|
|
39
|
+
}, server.url)
|
|
138
40
|
});
|
|
139
41
|
}
|
|
140
42
|
//#endregion
|