fumadocs-openapi 12.5.1 → 12.5.3
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 -61
- package/dist/.translations/keys.js +1 -62
- package/dist/generate-file.js +19 -21
- package/dist/index.browser.d.ts +8 -3
- package/dist/index.browser.js +11 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/packages/shared-api/dist/.translations/index.d.ts +52 -4
- package/dist/packages/shared-api/dist/.translations/keys.js +53 -5
- package/dist/packages/shared-api/dist/codegen.d.ts +21 -1
- package/dist/packages/shared-api/dist/codegen.js +63 -1
- package/dist/packages/shared-api/dist/components/copy-typescript.js +31 -0
- package/dist/packages/shared-api/dist/components/defaults.js +13 -19
- package/dist/{ui → packages/shared-api/dist}/components/dialog.js +17 -3
- package/dist/packages/shared-api/dist/components/example.js +125 -0
- package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js +14 -11
- package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/panels.js +330 -0
- package/dist/packages/shared-api/dist/components/playground/param-input.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/result.js +187 -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 +23 -1
- package/dist/{ui → packages/shared-api/dist}/components/segmented.js +2 -2
- package/dist/packages/shared-api/dist/components/select-tab.js +8 -3
- package/dist/packages/shared-api/dist/source.d.ts +11 -0
- package/dist/packages/shared-api/dist/source.js +50 -0
- package/dist/requests/generators/curl.js +6 -9
- package/dist/requests/generators/go.js +5 -5
- package/dist/requests/generators/rust.js +3 -2
- package/dist/requests/media/adapter.js +16 -7
- package/dist/requests/media/resolve-adapter.js +15 -12
- package/dist/requests/string-utils.js +7 -29
- package/dist/server/index.d.ts +2 -7
- package/dist/server/index.js +26 -64
- package/dist/ui/base.js +2 -2
- package/dist/ui/operation/index.js +7 -38
- package/dist/ui/operation/usage-tabs.js +49 -101
- package/dist/ui/playground/client.js +22 -51
- package/dist/ui/playground/components/{oauth-panel.js → auth.js} +20 -8
- package/dist/ui/playground/components/request-panel.js +14 -259
- package/dist/ui/playground/components/response-panel.js +11 -20
- package/dist/ui/playground/components/result-display.d.ts +0 -1
- package/dist/ui/playground/components/result-display.js +46 -182
- package/dist/ui/playground/components/server-select.js +24 -122
- package/dist/ui/playground/components/url-bar.js +8 -66
- package/dist/utils/create-page.d.ts +0 -4
- package/dist/utils/create-page.js +3 -5
- package/dist/utils/pages/builder.js +2 -2
- package/dist/utils/pages/preset-auto.js +139 -137
- package/dist/utils/pages/to-static-data.js +2 -7
- package/dist/utils/pages/to-text.js +2 -2
- package/package.json +6 -6
- package/dist/ui/playground/status-info.js +0 -39
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useOperation } from "../../../operation.js";
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
|
-
import { Markdown } from "../../components/markdown.js";
|
|
5
4
|
import { cn } from "../../../utils/cn.js";
|
|
6
|
-
import { Segmented, SegmentedList } from "
|
|
7
|
-
import { anyFields, useResolvedSchema
|
|
8
|
-
import { FieldRow, FieldRows, LinkRow, ValueRow,
|
|
5
|
+
import { Segmented, SegmentedList } from "../../../packages/shared-api/dist/components/segmented.js";
|
|
6
|
+
import { anyFields, useResolvedSchema } from "../../../packages/shared-api/dist/components/playground/schema.js";
|
|
7
|
+
import { FieldRow, FieldRows, LinkRow, ValueRow, getRemoval } from "../../../packages/shared-api/dist/components/playground/fields.js";
|
|
8
|
+
import { Crumb, FieldPanel, OverviewLayer, Panel, PanelNav, Section, useFieldStack } from "../../../packages/shared-api/dist/components/playground/panels.js";
|
|
9
|
+
import { JsonEditor } from "../../../packages/shared-api/dist/components/playground/json-editor.js";
|
|
9
10
|
import { Fragment, createContext, use, useState } from "react";
|
|
10
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { useDataEngine, useFieldValue } from "@fumari/stf";
|
|
12
12
|
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
13
13
|
import { useTranslations } from "@fuma-translate/react";
|
|
14
|
-
import {
|
|
15
|
-
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
14
|
+
import { Braces, Cookie, KeyRound, PlusIcon, Route, Rows3, SlidersHorizontal } from "lucide-react";
|
|
16
15
|
//#region src/ui/playground/components/request-panel.tsx
|
|
17
16
|
const sectionIcons = {
|
|
18
17
|
path: Route,
|
|
@@ -20,22 +19,11 @@ const sectionIcons = {
|
|
|
20
19
|
header: Rows3,
|
|
21
20
|
cookie: Cookie
|
|
22
21
|
};
|
|
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
22
|
/** the overview of all request inputs, nested fields open in their own panel */
|
|
31
23
|
function RequestPanel({ playground: { auth, body }, onSubmit, className, ...options }) {
|
|
32
24
|
const t = useTranslations({ note: "playground" });
|
|
33
|
-
const
|
|
34
|
-
const { generateDefault } = useSchemaUtils();
|
|
35
|
-
const [stack, setStack] = useState([]);
|
|
25
|
+
const fields = useFieldStack();
|
|
36
26
|
const [authorizing, setAuthorizing] = useState(null);
|
|
37
|
-
const [motion, setMotion] = useState("forward");
|
|
38
|
-
const current = stack.at(-1);
|
|
39
27
|
const sectionNames = {
|
|
40
28
|
path: t("Path"),
|
|
41
29
|
query: t("Query"),
|
|
@@ -43,21 +31,6 @@ function RequestPanel({ playground: { auth, body }, onSubmit, className, ...opti
|
|
|
43
31
|
cookie: t("Cookies"),
|
|
44
32
|
body: t("Body")
|
|
45
33
|
};
|
|
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
34
|
let panel = null;
|
|
62
35
|
if (authorizing) {
|
|
63
36
|
const { field, component: Component } = authorizing;
|
|
@@ -80,19 +53,9 @@ function RequestPanel({ playground: { auth, body }, onSubmit, className, ...opti
|
|
|
80
53
|
close
|
|
81
54
|
})
|
|
82
55
|
});
|
|
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
|
-
})
|
|
56
|
+
} else if (fields.stack.length > 0) panel = /* @__PURE__ */ jsx(FieldPanel, {
|
|
57
|
+
fields,
|
|
58
|
+
root: sectionNames[fields.stack[0].fieldName[0]]
|
|
96
59
|
});
|
|
97
60
|
return /* @__PURE__ */ jsxs("div", {
|
|
98
61
|
className: cn("@container grid min-h-0", className),
|
|
@@ -100,144 +63,20 @@ function RequestPanel({ playground: { auth, body }, onSubmit, className, ...opti
|
|
|
100
63
|
noValidate: true,
|
|
101
64
|
className: "contents",
|
|
102
65
|
onSubmit,
|
|
103
|
-
children: [/* @__PURE__ */ jsx(
|
|
104
|
-
|
|
66
|
+
children: [/* @__PURE__ */ jsx(OverviewLayer, {
|
|
67
|
+
covered: panel !== null,
|
|
105
68
|
children: /* @__PURE__ */ jsx(Overview, {
|
|
106
69
|
...options,
|
|
107
70
|
auth,
|
|
108
71
|
body,
|
|
109
72
|
sectionNames,
|
|
110
|
-
onNavigate: openNested([]),
|
|
73
|
+
onNavigate: fields.openNested([]),
|
|
111
74
|
onAuthorize: setAuthorizing
|
|
112
75
|
})
|
|
113
76
|
}), !authorizing && panel]
|
|
114
77
|
}), authorizing && panel]
|
|
115
78
|
});
|
|
116
79
|
}
|
|
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
80
|
function Overview({ auth, body, sectionNames, onNavigate, onAuthorize, renderParameterField, renderBodyField }) {
|
|
242
81
|
const t = useTranslations({ note: "playground" });
|
|
243
82
|
const { parameters } = useOperation();
|
|
@@ -280,29 +119,6 @@ function getParameterSchema(param) {
|
|
|
280
119
|
if (param.content) for (const type in param.content) return param.content[type].schema ?? anyFields;
|
|
281
120
|
return param.schema ?? anyFields;
|
|
282
121
|
}
|
|
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
122
|
function AuthSection({ auth, onAuthorize }) {
|
|
307
123
|
const t = useTranslations({ note: "playground" });
|
|
308
124
|
const { requirements, selected, select, fields } = auth;
|
|
@@ -375,20 +191,6 @@ function AuthPanelRow({ title, component }) {
|
|
|
375
191
|
children: title
|
|
376
192
|
});
|
|
377
193
|
}
|
|
378
|
-
/** mutual TLS schemes, they have no value */
|
|
379
|
-
const mutualTLSProvider = {
|
|
380
|
-
on: ({ scheme }) => scheme.type === "mutualTLS",
|
|
381
|
-
render: function MutualTLSNote({ field }) {
|
|
382
|
-
const t = useTranslations({ note: "playground" });
|
|
383
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
384
|
-
className: "flex gap-2 border-b px-4 py-2.5 text-xs text-fd-muted-foreground last:border-b-0",
|
|
385
|
-
children: [/* @__PURE__ */ jsx(ShieldCheck, { className: "mt-px size-3.5 shrink-0" }), /* @__PURE__ */ jsxs("div", {
|
|
386
|
-
className: "min-w-0 flex-1 [&_a]:underline",
|
|
387
|
-
children: [/* @__PURE__ */ jsx("p", { children: t("Requires a client certificate installed in your browser.") }), field.scheme.description && /* @__PURE__ */ jsx(Markdown, { md: field.scheme.description })]
|
|
388
|
-
})]
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
194
|
function BodySection({ body, renderBodyField, onNavigate }) {
|
|
393
195
|
const t = useTranslations({ note: "playground" });
|
|
394
196
|
const [mode, setMode] = useState("form");
|
|
@@ -430,52 +232,5 @@ function BodySection({ body, renderBodyField, onNavigate }) {
|
|
|
430
232
|
children: content
|
|
431
233
|
});
|
|
432
234
|
}
|
|
433
|
-
function JsonEditor({ fieldName }) {
|
|
434
|
-
const engine = useDataEngine();
|
|
435
|
-
const [value] = useFieldValue(fieldName);
|
|
436
|
-
const [draft, setDraft] = useState(() => ({
|
|
437
|
-
value,
|
|
438
|
-
text: formatJson(value),
|
|
439
|
-
error: ""
|
|
440
|
-
}));
|
|
441
|
-
if (draft.value !== value) setDraft({
|
|
442
|
-
value,
|
|
443
|
-
text: formatJson(value),
|
|
444
|
-
error: ""
|
|
445
|
-
});
|
|
446
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
447
|
-
className: "flex flex-col",
|
|
448
|
-
children: [/* @__PURE__ */ jsx("textarea", {
|
|
449
|
-
"aria-label": "JSON",
|
|
450
|
-
value: draft.text,
|
|
451
|
-
spellCheck: false,
|
|
452
|
-
onChange: (e) => {
|
|
453
|
-
const text = e.target.value;
|
|
454
|
-
try {
|
|
455
|
-
const parsed = JSON.parse(text);
|
|
456
|
-
setDraft({
|
|
457
|
-
value: parsed,
|
|
458
|
-
text,
|
|
459
|
-
error: ""
|
|
460
|
-
});
|
|
461
|
-
engine.update(fieldName, parsed);
|
|
462
|
-
} catch (err) {
|
|
463
|
-
setDraft({
|
|
464
|
-
...draft,
|
|
465
|
-
text,
|
|
466
|
-
error: err instanceof Error ? err.message : ""
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
},
|
|
470
|
-
className: "min-h-60 w-full resize-none bg-transparent px-4 py-3 font-mono text-[0.8125rem] leading-relaxed outline-none field-sizing-content"
|
|
471
|
-
}), draft.error && /* @__PURE__ */ jsx("p", {
|
|
472
|
-
className: "border-t px-4 py-2 font-mono text-xs text-red-400",
|
|
473
|
-
children: draft.error
|
|
474
|
-
})]
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
function formatJson(value) {
|
|
478
|
-
return JSON.stringify(value ?? {}, null, 2);
|
|
479
|
-
}
|
|
480
235
|
//#endregion
|
|
481
|
-
export { RequestPanel
|
|
236
|
+
export { RequestPanel };
|
|
@@ -1,12 +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 {
|
|
9
|
-
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, Placeholder, SendingOverlay, panelCodeBlock, panelTopCodeBlock } from "../../../packages/shared-api/dist/components/playground/panels.js";
|
|
10
|
+
import { DefaultResultDisplay } from "./result-display.js";
|
|
10
11
|
import { useState } from "react";
|
|
11
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
13
|
import { useTranslations } from "@fuma-translate/react";
|
|
@@ -18,7 +19,7 @@ function ResponsePanel({ response, loading, onReset, ResultDisplay = DefaultResu
|
|
|
18
19
|
className: cn("@container flex min-h-0 flex-col", className),
|
|
19
20
|
children: [/* @__PURE__ */ jsx(CodeUsages, {
|
|
20
21
|
title: t("Request"),
|
|
21
|
-
className:
|
|
22
|
+
className: panelTopCodeBlock.className,
|
|
22
23
|
viewportClassName: "max-h-[min(18rem,30vh)]"
|
|
23
24
|
}), /* @__PURE__ */ jsxs("div", {
|
|
24
25
|
className: "relative flex min-h-0 flex-1 flex-col",
|
|
@@ -26,10 +27,7 @@ function ResponsePanel({ response, loading, onReset, ResultDisplay = DefaultResu
|
|
|
26
27
|
data: response.result,
|
|
27
28
|
reset: onReset,
|
|
28
29
|
className: "starting:opacity-0 motion-safe:transition-[opacity,translate] motion-safe:duration-300 motion-safe:starting:translate-y-1"
|
|
29
|
-
}, response.id) : /* @__PURE__ */ jsx(ResponseExamples, {}), loading && /* @__PURE__ */
|
|
30
|
-
className: "absolute inset-0 flex items-center justify-center gap-2 bg-fd-card/70 text-sm text-fd-muted-foreground backdrop-blur-[1px] transition-opacity delay-150 duration-200 starting:opacity-0",
|
|
31
|
-
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }), t("Sending request...")]
|
|
32
|
-
})]
|
|
30
|
+
}, response.id) : /* @__PURE__ */ jsx(ResponseExamples, {}), loading && /* @__PURE__ */ jsx(SendingOverlay, {})]
|
|
33
31
|
})]
|
|
34
32
|
});
|
|
35
33
|
}
|
|
@@ -38,15 +36,9 @@ function ResponseExamples() {
|
|
|
38
36
|
const tabs = useResponseExamples();
|
|
39
37
|
const [code, setCode] = useState();
|
|
40
38
|
const [selected, setSelected] = useState(0);
|
|
41
|
-
if (tabs.length === 0) return /* @__PURE__ */
|
|
42
|
-
|
|
43
|
-
children:
|
|
44
|
-
className: "rounded-xl border bg-fd-secondary p-2.5 text-fd-muted-foreground",
|
|
45
|
-
children: /* @__PURE__ */ jsx(SendHorizontal, { className: "size-4" })
|
|
46
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
47
|
-
className: "text-sm text-fd-muted-foreground",
|
|
48
|
-
children: t("Send a request to see its response.")
|
|
49
|
-
})]
|
|
39
|
+
if (tabs.length === 0) return /* @__PURE__ */ jsx(Placeholder, {
|
|
40
|
+
icon: SendHorizontal,
|
|
41
|
+
children: t("Send a request to see its response.")
|
|
50
42
|
});
|
|
51
43
|
const tab = tabs.find((item) => item.code === code) ?? tabs[0];
|
|
52
44
|
const examples = tab.examples ?? [];
|
|
@@ -72,8 +64,7 @@ function ResponseExamples() {
|
|
|
72
64
|
label: item.label
|
|
73
65
|
})),
|
|
74
66
|
value: String(selected),
|
|
75
|
-
onValueChange: (v) => setSelected(Number(v))
|
|
76
|
-
className: "max-w-40"
|
|
67
|
+
onValueChange: (v) => setSelected(Number(v))
|
|
77
68
|
}),
|
|
78
69
|
/* @__PURE__ */ jsx(SegmentedList, {
|
|
79
70
|
className: "max-w-1/2 shrink-0 overflow-x-auto [scrollbar-width:none]",
|
|
@@ -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;
|