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.
Files changed (55) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/dist/.translations/index.d.ts +0 -61
  3. package/dist/.translations/keys.js +1 -62
  4. package/dist/generate-file.js +19 -21
  5. package/dist/index.browser.d.ts +8 -3
  6. package/dist/index.browser.js +11 -1
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +2 -1
  9. package/dist/packages/shared-api/dist/.translations/index.d.ts +52 -4
  10. package/dist/packages/shared-api/dist/.translations/keys.js +53 -5
  11. package/dist/packages/shared-api/dist/codegen.d.ts +21 -1
  12. package/dist/packages/shared-api/dist/codegen.js +63 -1
  13. package/dist/packages/shared-api/dist/components/copy-typescript.js +31 -0
  14. package/dist/packages/shared-api/dist/components/defaults.js +13 -19
  15. package/dist/{ui → packages/shared-api/dist}/components/dialog.js +17 -3
  16. package/dist/packages/shared-api/dist/components/example.js +125 -0
  17. package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js +14 -11
  18. package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
  19. package/dist/packages/shared-api/dist/components/playground/panels.js +330 -0
  20. package/dist/packages/shared-api/dist/components/playground/param-input.js +54 -0
  21. package/dist/packages/shared-api/dist/components/playground/result.js +187 -0
  22. package/dist/packages/shared-api/dist/components/playground/schema.js +5 -3
  23. package/dist/packages/shared-api/dist/components/playground/server-select.js +130 -0
  24. package/dist/packages/shared-api/dist/components/schema/client.js +23 -1
  25. package/dist/{ui → packages/shared-api/dist}/components/segmented.js +2 -2
  26. package/dist/packages/shared-api/dist/components/select-tab.js +8 -3
  27. package/dist/packages/shared-api/dist/source.d.ts +11 -0
  28. package/dist/packages/shared-api/dist/source.js +50 -0
  29. package/dist/requests/generators/curl.js +6 -9
  30. package/dist/requests/generators/go.js +5 -5
  31. package/dist/requests/generators/rust.js +3 -2
  32. package/dist/requests/media/adapter.js +16 -7
  33. package/dist/requests/media/resolve-adapter.js +15 -12
  34. package/dist/requests/string-utils.js +7 -29
  35. package/dist/server/index.d.ts +2 -7
  36. package/dist/server/index.js +26 -64
  37. package/dist/ui/base.js +2 -2
  38. package/dist/ui/operation/index.js +7 -38
  39. package/dist/ui/operation/usage-tabs.js +49 -101
  40. package/dist/ui/playground/client.js +22 -51
  41. package/dist/ui/playground/components/{oauth-panel.js → auth.js} +20 -8
  42. package/dist/ui/playground/components/request-panel.js +14 -259
  43. package/dist/ui/playground/components/response-panel.js +11 -20
  44. package/dist/ui/playground/components/result-display.d.ts +0 -1
  45. package/dist/ui/playground/components/result-display.js +46 -182
  46. package/dist/ui/playground/components/server-select.js +24 -122
  47. package/dist/ui/playground/components/url-bar.js +8 -66
  48. package/dist/utils/create-page.d.ts +0 -4
  49. package/dist/utils/create-page.js +3 -5
  50. package/dist/utils/pages/builder.js +2 -2
  51. package/dist/utils/pages/preset-auto.js +139 -137
  52. package/dist/utils/pages/to-static-data.js +2 -7
  53. package/dist/utils/pages/to-text.js +2 -2
  54. package/package.json +6 -6
  55. package/dist/ui/playground/status-info.js +0 -39
@@ -0,0 +1,330 @@
1
+ "use client";
2
+ import { cn } from "../../utils/cn.js";
3
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
4
+ import { titleBarClassName } from "../example.js";
5
+ import { Segmented, SegmentedList } from "../segmented.js";
6
+ import { Spinner } from "../spinner.js";
7
+ import { useSchemaUtils } from "./schema.js";
8
+ import { FieldRows, getNestedFields, resolveField } from "./fields.js";
9
+ import { memo, useState } from "react";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ import { useDataEngine } from "@fumari/stf";
12
+ import { stringifyFieldKey } from "@fumari/stf/lib/utils";
13
+ import { useTranslations } from "@fuma-translate/react";
14
+ import { ArrowLeft, ChevronRight, SendHorizontal } from "lucide-react";
15
+ import { buttonVariants } from "fumadocs-ui/components/ui/button";
16
+ //#region ../shared-api/dist/components/playground/panels.js
17
+ const motionClassNames = {
18
+ forward: "motion-safe:starting:translate-x-6",
19
+ back: "motion-safe:starting:-translate-x-6",
20
+ next: "motion-safe:starting:translate-y-4",
21
+ previous: "motion-safe:starting:-translate-y-4"
22
+ };
23
+ const transitionClassName = "motion-safe:transition-[opacity,translate] motion-safe:duration-300 motion-safe:ease-[cubic-bezier(0.16,1,0.3,1)]";
24
+ const iconButtonClassName = cn(buttonVariants({
25
+ variant: "ghost",
26
+ size: "icon-sm"
27
+ }), "text-fd-muted-foreground [&_svg]:size-3.5");
28
+ /** a code block filling its panel */
29
+ const panelCodeBlock = {
30
+ className: `flex h-full flex-col rounded-none border-0 bg-transparent shadow-none ${titleBarClassName}`,
31
+ viewportProps: { className: "min-h-0 flex-1 max-h-none" }
32
+ };
33
+ /** a code block on top of a panel */
34
+ const panelTopCodeBlock = { className: `shrink-0 rounded-none border-0 border-b ${titleBarClassName}` };
35
+ function PanelHeader({ className, ...props }) {
36
+ return /* @__PURE__ */ jsx("div", {
37
+ ...props,
38
+ className: cn("flex h-10 shrink-0 items-center gap-2.5 border-b ps-4 pe-1.5", className)
39
+ });
40
+ }
41
+ /** the path to the nested field open in a panel */
42
+ function useFieldStack() {
43
+ const engine = useDataEngine();
44
+ const { generateDefault } = useSchemaUtils();
45
+ const [stack, setStack] = useState([]);
46
+ const [motion, setMotion] = useState("forward");
47
+ function navigate(next, nextMotion) {
48
+ const target = next.at(-1);
49
+ if (target) engine.init(target.fieldName, () => {
50
+ const field = resolveField(target.schema, void 0);
51
+ return field ? generateDefault(field) : void 0;
52
+ });
53
+ setMotion(nextMotion ?? (next.length >= stack.length ? "forward" : "back"));
54
+ setStack(next);
55
+ }
56
+ return {
57
+ stack,
58
+ motion,
59
+ navigate,
60
+ /** opens a field nested in the last of `parents` */
61
+ openNested(parents) {
62
+ return (entry, siblings) => navigate([...parents, {
63
+ ...entry,
64
+ siblings: getNestedFields(engine, siblings)
65
+ }]);
66
+ }
67
+ };
68
+ }
69
+ /** the overview of fields, it stays under panels and keeps its scroll position */
70
+ function OverviewLayer({ covered, children }) {
71
+ return /* @__PURE__ */ jsx("div", {
72
+ className: cn("fd-scroll-container min-h-0 overflow-y-auto [grid-area:1/1]", transitionClassName, covered && "invisible opacity-0 motion-safe:-translate-x-6"),
73
+ children
74
+ });
75
+ }
76
+ /**
77
+ * The panel of the field open in `fields`, breadcrumbs go back to `root`.
78
+ */
79
+ function FieldPanel({ fields: { stack, motion, navigate, openNested }, root, disabled }) {
80
+ const current = stack[stack.length - 1];
81
+ const rows = /* @__PURE__ */ jsx(FieldRows, {
82
+ entry: current,
83
+ showDescription: true,
84
+ onNavigate: openNested(stack)
85
+ });
86
+ return /* @__PURE__ */ jsx(Panel, {
87
+ id: stringifyFieldKey(current.fieldName),
88
+ motion,
89
+ nav: /* @__PURE__ */ jsx(Breadcrumbs, {
90
+ root,
91
+ stack,
92
+ disabled,
93
+ onNavigate: navigate
94
+ }),
95
+ children: disabled === void 0 ? rows : /* @__PURE__ */ jsx("fieldset", {
96
+ disabled,
97
+ className: "contents",
98
+ children: rows
99
+ })
100
+ });
101
+ }
102
+ /** a panel over the overview, its content animates in when `id` changes */
103
+ function Panel({ id, motion, nav, children }) {
104
+ return /* @__PURE__ */ jsxs("div", {
105
+ className: "flex min-h-0 flex-col [grid-area:1/1]",
106
+ children: [nav, /* @__PURE__ */ jsx("div", {
107
+ className: cn("fd-scroll-container min-h-0 flex-1 overflow-y-auto starting:opacity-0", transitionClassName, motionClassNames[motion]),
108
+ children
109
+ }, id)]
110
+ });
111
+ }
112
+ 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";
113
+ /** the bar on top of a panel, going back to the overview from `root` */
114
+ function PanelNav({ root, onRoot, onBack, end, children }) {
115
+ const t = useTranslations({ note: "playground" });
116
+ return /* @__PURE__ */ jsxs("nav", {
117
+ "aria-label": t("Breadcrumb"),
118
+ className: "flex h-10 shrink-0 items-center gap-1 border-b ps-1.5 pe-1.5 text-[0.8125rem]",
119
+ children: [
120
+ /* @__PURE__ */ jsx("button", {
121
+ type: "button",
122
+ "aria-label": t("Back"),
123
+ onClick: onBack,
124
+ className: cn(buttonVariants({
125
+ variant: "ghost",
126
+ size: "icon-xs"
127
+ }), "me-1 text-fd-muted-foreground"),
128
+ children: /* @__PURE__ */ jsx(ArrowLeft, {})
129
+ }),
130
+ /* @__PURE__ */ jsxs("ol", {
131
+ className: "flex min-w-0 items-center gap-0.5",
132
+ children: [/* @__PURE__ */ jsx("li", {
133
+ className: "flex min-w-0 shrink-0 items-center",
134
+ children: /* @__PURE__ */ jsx("button", {
135
+ type: "button",
136
+ onClick: onRoot,
137
+ className: crumbClassName,
138
+ children: root
139
+ })
140
+ }), children]
141
+ }),
142
+ end
143
+ ]
144
+ });
145
+ }
146
+ function Crumb({ children }) {
147
+ return /* @__PURE__ */ jsxs("li", {
148
+ className: "flex min-w-0 items-center gap-0.5 last:shrink-0 motion-safe:transition-opacity motion-safe:starting:opacity-0",
149
+ children: [/* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 shrink-0 text-fd-muted-foreground/60" }), children]
150
+ });
151
+ }
152
+ function Breadcrumbs({ root, stack, disabled, onNavigate }) {
153
+ const t = useTranslations({ note: "playground" });
154
+ const engine = useDataEngine();
155
+ const current = stack[stack.length - 1];
156
+ return /* @__PURE__ */ jsx(PanelNav, {
157
+ root,
158
+ onRoot: () => onNavigate([]),
159
+ onBack: () => onNavigate(stack.slice(0, -1)),
160
+ end: current.removal && /* @__PURE__ */ jsx("button", {
161
+ type: "button",
162
+ disabled,
163
+ onClick: () => {
164
+ engine.delete(current.fieldName);
165
+ onNavigate(stack.slice(0, -1));
166
+ },
167
+ className: cn(buttonVariants({
168
+ variant: "ghost",
169
+ size: "sm"
170
+ }), "ms-auto shrink-0 text-fd-muted-foreground"),
171
+ children: current.removal === "remove" ? t("Remove") : t("Unset")
172
+ }),
173
+ children: stack.map((entry, i) => {
174
+ const { siblings } = entry;
175
+ let node;
176
+ if (i < stack.length - 1) node = /* @__PURE__ */ jsx("button", {
177
+ type: "button",
178
+ onClick: () => onNavigate(stack.slice(0, i + 1)),
179
+ className: cn(crumbClassName, "font-mono"),
180
+ children: entry.name
181
+ });
182
+ else if (siblings && siblings.length > 1) node = /* @__PURE__ */ jsx(SiblingSelect, {
183
+ entry,
184
+ siblings,
185
+ onSelect: (sibling, motion) => onNavigate([...stack.slice(0, -1), {
186
+ ...sibling,
187
+ siblings
188
+ }], motion)
189
+ });
190
+ else node = /* @__PURE__ */ jsx("span", {
191
+ "aria-current": "page",
192
+ className: "truncate px-1.5 py-1 font-mono font-medium",
193
+ children: entry.name
194
+ });
195
+ return /* @__PURE__ */ jsx(Crumb, { children: node }, stringifyFieldKey(entry.fieldName));
196
+ })
197
+ });
198
+ }
199
+ /** the current field, switches to the other nested fields of its parent */
200
+ function SiblingSelect({ entry, siblings, onSelect }) {
201
+ const t = useTranslations({ note: "playground" });
202
+ const current = stringifyFieldKey(entry.fieldName);
203
+ const items = siblings.map((item) => ({
204
+ value: stringifyFieldKey(item.fieldName),
205
+ label: item.name
206
+ }));
207
+ return /* @__PURE__ */ jsxs(Select, {
208
+ items,
209
+ value: current,
210
+ onValueChange: (value) => {
211
+ const next = items.findIndex((item) => item.value === value);
212
+ if (next === -1 || value === current) return;
213
+ const prev = items.findIndex((item) => item.value === current);
214
+ onSelect(siblings[next], next > prev ? "next" : "previous");
215
+ },
216
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
217
+ "aria-label": t("Switch Field"),
218
+ 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",
219
+ children: /* @__PURE__ */ jsx(SelectValue, { className: "truncate" })
220
+ }), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
221
+ value: item.value,
222
+ className: "font-mono text-[0.8125rem]",
223
+ children: item.label
224
+ }, item.value)) })]
225
+ });
226
+ }
227
+ /** a group of fields in the overview, its header stays on top while scrolling */
228
+ function Section({ icon: Icon, title, count, actions, children }) {
229
+ return /* @__PURE__ */ jsxs("section", {
230
+ className: "border-b last:border-b-0",
231
+ children: [/* @__PURE__ */ jsxs("div", {
232
+ 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",
233
+ children: [
234
+ /* @__PURE__ */ jsx(Icon, { className: "size-3.5 shrink-0 text-fd-primary" }),
235
+ /* @__PURE__ */ jsx("h3", {
236
+ className: "text-[0.8125rem] font-medium",
237
+ children: title
238
+ }),
239
+ count !== void 0 && /* @__PURE__ */ jsx("span", {
240
+ className: "text-xs text-fd-muted-foreground tabular-nums",
241
+ children: count
242
+ }),
243
+ /* @__PURE__ */ jsx("div", {
244
+ className: "flex min-w-0 flex-1 items-center justify-end gap-2",
245
+ children: actions
246
+ })
247
+ ]
248
+ }), children]
249
+ });
250
+ }
251
+ /** switches the panels of a playground on small screens, memoized as its indicator measures the tabs on render */
252
+ const ViewSwitch = memo(function ViewSwitch({ value, onValueChange, items }) {
253
+ return /* @__PURE__ */ jsx(Segmented, {
254
+ value,
255
+ onValueChange,
256
+ className: "shrink-0 px-3 pb-3 md:hidden",
257
+ children: /* @__PURE__ */ jsx(SegmentedList, {
258
+ className: "*:flex-1 *:justify-center",
259
+ items
260
+ })
261
+ });
262
+ });
263
+ /** the example request loaded in a playground, in the header of its dialog */
264
+ function RequestExampleSelect({ items, value, onValueChange, disabled }) {
265
+ const t = useTranslations({ note: "playground" });
266
+ if (items.length <= 1) return null;
267
+ return /* @__PURE__ */ jsxs(Select, {
268
+ items,
269
+ value,
270
+ disabled,
271
+ onValueChange: (v) => v !== null && onValueChange(v),
272
+ children: [/* @__PURE__ */ jsxs(SelectTrigger, {
273
+ className: "h-8 w-auto max-w-64 gap-1.5 border-0 bg-transparent px-2 text-xs hover:bg-fd-accent focus:ring-0 focus-visible:ring-2",
274
+ children: [/* @__PURE__ */ jsx("span", {
275
+ className: "text-fd-muted-foreground",
276
+ children: t("Example")
277
+ }), /* @__PURE__ */ jsx(SelectValue, { className: "truncate font-medium" })]
278
+ }), /* @__PURE__ */ jsx(SelectContent, {
279
+ align: "end",
280
+ children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
281
+ value: item.value,
282
+ children: item.label
283
+ }, item.value))
284
+ })]
285
+ });
286
+ }
287
+ /** the keyboard shortcut to send */
288
+ function SendShortcut() {
289
+ const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent);
290
+ return /* @__PURE__ */ jsxs("kbd", {
291
+ className: "hidden font-sans text-xs opacity-60 sm:inline",
292
+ children: [isMac ? "⌘" : "Ctrl", " ↵"]
293
+ });
294
+ }
295
+ function SendButton({ sending, disabled }) {
296
+ const t = useTranslations({ note: "playground" });
297
+ return /* @__PURE__ */ jsxs("button", {
298
+ type: "submit",
299
+ disabled: sending || disabled,
300
+ className: cn(buttonVariants({ variant: "primary" }), "h-10 shrink-0 gap-2 rounded-xl px-4 transition-[background-color,scale] active:scale-[0.97] disabled:opacity-80 motion-reduce:transition-none"),
301
+ children: [
302
+ sending ? /* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }) : /* @__PURE__ */ jsx(SendHorizontal, { className: "size-3.5" }),
303
+ t("Send"),
304
+ /* @__PURE__ */ jsx(SendShortcut, {})
305
+ ]
306
+ });
307
+ }
308
+ /** an empty panel, telling what fills it */
309
+ function Placeholder({ icon: Icon, className, children }) {
310
+ return /* @__PURE__ */ jsxs("div", {
311
+ className: cn("flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center", className),
312
+ children: [/* @__PURE__ */ jsx("div", {
313
+ className: "rounded-xl border bg-fd-secondary p-2.5 text-fd-muted-foreground",
314
+ children: /* @__PURE__ */ jsx(Icon, { className: "size-4" })
315
+ }), /* @__PURE__ */ jsx("p", {
316
+ className: "text-sm text-fd-muted-foreground",
317
+ children
318
+ })]
319
+ });
320
+ }
321
+ /** covers the response while its request is sent */
322
+ function SendingOverlay() {
323
+ const t = useTranslations({ note: "playground" });
324
+ return /* @__PURE__ */ jsxs("div", {
325
+ 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",
326
+ children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }), t("Sending request...")]
327
+ });
328
+ }
329
+ //#endregion
330
+ export { Crumb, FieldPanel, OverviewLayer, Panel, PanelHeader, PanelNav, Placeholder, RequestExampleSelect, Section, SendButton, SendShortcut, SendingOverlay, ViewSwitch, iconButtonClassName, panelCodeBlock, panelTopCodeBlock, useFieldStack };
@@ -0,0 +1,54 @@
1
+ "use client";
2
+ import { cn } from "../../utils/cn.js";
3
+ import { useResolvedSchema } from "./schema.js";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { useFieldValue } from "@fumari/stf";
6
+ //#region ../shared-api/dist/components/playground/param-input.js
7
+ const className = "mx-px rounded-md bg-fd-primary/10 px-1.5 py-0.5 text-fd-primary outline-none transition-colors placeholder:text-fd-primary/50 hover:bg-fd-primary/15 focus-visible:bg-fd-primary/15 focus-visible:ring-2 focus-visible:ring-fd-primary/30";
8
+ /** a parameter of a URL edited in place, like `{id}` of `/users/{id}` */
9
+ function ParamInput({ fieldName, name, schema = true, description }) {
10
+ const resolved = useResolvedSchema(schema);
11
+ const [value, setValue] = useFieldValue(fieldName);
12
+ const text = value == null ? "" : String(value);
13
+ if (resolved.enum && resolved.enum.length > 0) {
14
+ const options = resolved.enum;
15
+ return /* @__PURE__ */ jsxs("select", {
16
+ "aria-label": name,
17
+ title: description,
18
+ value: String(options.indexOf(value)),
19
+ onChange: (e) => setValue(options[Number(e.target.value)]),
20
+ className: cn(className, "cursor-pointer appearance-none"),
21
+ children: [/* @__PURE__ */ jsx("option", {
22
+ value: "-1",
23
+ disabled: true,
24
+ className: "bg-fd-popover text-fd-popover-foreground",
25
+ children: name
26
+ }), options.map((item, i) => /* @__PURE__ */ jsx("option", {
27
+ value: i,
28
+ className: "bg-fd-popover text-fd-popover-foreground",
29
+ children: String(item)
30
+ }, i))]
31
+ });
32
+ }
33
+ const isNumber = resolved.type === "integer" || resolved.type === "number";
34
+ return /* @__PURE__ */ jsx("input", {
35
+ "aria-label": name,
36
+ title: description,
37
+ value: text,
38
+ placeholder: name,
39
+ autoComplete: "off",
40
+ spellCheck: false,
41
+ inputMode: isNumber ? "decimal" : void 0,
42
+ onChange: (e) => {
43
+ const v = e.target.value;
44
+ const number = Number(v);
45
+ if (v.length === 0) setValue(void 0);
46
+ else if (isNumber && String(number) === v && (resolved.type === "integer" ? Number.isInteger(number) : Number.isFinite(number))) setValue(number);
47
+ else setValue(v);
48
+ },
49
+ style: { width: `calc(${Math.max(text.length, name.length, 1)}ch + 0.75rem)` },
50
+ className
51
+ });
52
+ }
53
+ //#endregion
54
+ export { ParamInput };
@@ -0,0 +1,187 @@
1
+ "use client";
2
+ import { cn } from "../../utils/cn.js";
3
+ import { Segmented, SegmentedList, SegmentedPanel } from "../segmented.js";
4
+ import { PanelHeader, iconButtonClassName } from "./panels.js";
5
+ import { Fragment, useState } from "react";
6
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
+ import { useTranslations } from "@fuma-translate/react";
8
+ import { X } from "lucide-react";
9
+ //#region ../shared-api/dist/components/playground/result.js
10
+ function ClearButton({ onClick, className }) {
11
+ const t = useTranslations({ note: "playground result display" });
12
+ return /* @__PURE__ */ jsx("button", {
13
+ type: "button",
14
+ "aria-label": t("Clear"),
15
+ title: t("Clear"),
16
+ className: cn(iconButtonClassName, className),
17
+ onClick,
18
+ children: /* @__PURE__ */ jsx(X, {})
19
+ });
20
+ }
21
+ /** a request without response, like a network error */
22
+ function RequestError({ message, url, onClear, ...rest }) {
23
+ const t = useTranslations({ note: "playground result display" });
24
+ return /* @__PURE__ */ jsxs("div", {
25
+ ...rest,
26
+ className: cn("flex min-h-0 flex-1 flex-col", rest.className),
27
+ children: [/* @__PURE__ */ jsxs(PanelHeader, { children: [
28
+ /* @__PURE__ */ jsx("span", { className: "size-2 shrink-0 rounded-full bg-red-500" }),
29
+ /* @__PURE__ */ jsx("span", {
30
+ className: "text-[0.8125rem] font-medium",
31
+ children: t("Request Failed")
32
+ }),
33
+ /* @__PURE__ */ jsx(ClearButton, {
34
+ onClick: onClear,
35
+ className: "ms-auto"
36
+ })
37
+ ] }), /* @__PURE__ */ jsxs("div", {
38
+ className: "flex flex-col gap-3 overflow-auto p-4 text-sm",
39
+ children: [
40
+ /* @__PURE__ */ jsx("p", { children: message }),
41
+ /* @__PURE__ */ jsx("p", {
42
+ className: "font-mono text-xs break-all text-fd-muted-foreground",
43
+ children: url
44
+ }),
45
+ /* @__PURE__ */ jsx("p", {
46
+ className: "rounded-lg border bg-fd-secondary p-3 text-xs text-fd-muted-foreground",
47
+ children: t("Check the server URL. If the API does not allow cross-origin requests from this site, a proxy is needed.")
48
+ })
49
+ ]
50
+ })]
51
+ });
52
+ }
53
+ function formatDuration(ms) {
54
+ return ms < 1e3 ? `${Math.round(ms)} ms` : `${(ms / 1e3).toFixed(2)} s`;
55
+ }
56
+ function formatSize(bytes) {
57
+ if (bytes < 1024) return `${bytes} B`;
58
+ if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)} kB`;
59
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
60
+ }
61
+ function useStatusInfo(status) {
62
+ const t = useTranslations({ note: "playground status info" });
63
+ const descriptions = {
64
+ 200: t("OK"),
65
+ 201: t("Created"),
66
+ 202: t("Accepted"),
67
+ 204: t("No Content"),
68
+ 301: t("Moved Permanently"),
69
+ 302: t("Found"),
70
+ 304: t("Not Modified"),
71
+ 400: t("Bad Request"),
72
+ 401: t("Unauthorized"),
73
+ 403: t("Forbidden"),
74
+ 404: t("Not Found"),
75
+ 405: t("Method Not Allowed"),
76
+ 409: t("Conflict"),
77
+ 422: t("Unprocessable Content"),
78
+ 429: t("Too Many Requests"),
79
+ 500: t("Internal Server Error"),
80
+ 502: t("Bad Gateway"),
81
+ 503: t("Service Unavailable")
82
+ };
83
+ if (status >= 200 && status < 300) return {
84
+ color: "bg-green-500",
85
+ description: descriptions[status] ?? t("Successful")
86
+ };
87
+ if (status >= 300 && status < 400) return {
88
+ color: "bg-blue-500",
89
+ description: descriptions[status] ?? t("Redirect")
90
+ };
91
+ return {
92
+ color: status >= 400 && status < 500 ? "bg-amber-500" : "bg-red-500",
93
+ description: descriptions[status] ?? t("Error")
94
+ };
95
+ }
96
+ /** the response of a request, with `children` as its body */
97
+ function ResponseView({ status, duration, size, url, headers, warning = false, actions, onClear, children, ...rest }) {
98
+ const t = useTranslations({ note: "playground result display" });
99
+ const statusInfo = useStatusInfo(status);
100
+ const [view, setView] = useState("body");
101
+ return /* @__PURE__ */ jsx("div", {
102
+ ...rest,
103
+ className: cn("flex min-h-0 flex-1 flex-col", rest.className),
104
+ children: /* @__PURE__ */ jsxs(Segmented, {
105
+ value: view,
106
+ onValueChange: setView,
107
+ className: "flex min-h-0 flex-1 flex-col",
108
+ children: [
109
+ /* @__PURE__ */ jsxs(PanelHeader, { children: [
110
+ /* @__PURE__ */ jsx("span", { className: cn("size-2 shrink-0 rounded-full motion-safe:transition-transform motion-safe:duration-300 motion-safe:starting:scale-0", warning ? "bg-amber-500" : statusInfo.color) }),
111
+ /* @__PURE__ */ jsxs("p", {
112
+ className: "min-w-0 truncate text-[0.8125rem] font-medium",
113
+ children: [
114
+ /* @__PURE__ */ jsx("span", {
115
+ className: "tabular-nums",
116
+ children: status
117
+ }),
118
+ " ",
119
+ /* @__PURE__ */ jsx("span", {
120
+ className: "font-normal text-fd-muted-foreground",
121
+ children: statusInfo.description
122
+ })
123
+ ]
124
+ }),
125
+ /* @__PURE__ */ jsxs("p", {
126
+ className: "hidden shrink-0 text-xs text-fd-muted-foreground tabular-nums @md:block",
127
+ children: [
128
+ formatDuration(duration),
129
+ " · ",
130
+ formatSize(size)
131
+ ]
132
+ }),
133
+ headers && /* @__PURE__ */ jsx(SegmentedList, {
134
+ className: "ms-auto shrink-0",
135
+ items: [{
136
+ value: "body",
137
+ label: t("Body")
138
+ }, {
139
+ value: "headers",
140
+ label: /* @__PURE__ */ jsxs(Fragment$1, { children: [t("Headers"), /* @__PURE__ */ jsx("span", {
141
+ className: "text-fd-muted-foreground tabular-nums",
142
+ children: headers.length
143
+ })] })
144
+ }]
145
+ }),
146
+ /* @__PURE__ */ jsxs("div", {
147
+ className: cn("flex shrink-0 items-center", !headers && "ms-auto"),
148
+ children: [actions, /* @__PURE__ */ jsx(ClearButton, { onClick: onClear })]
149
+ })
150
+ ] }),
151
+ /* @__PURE__ */ jsx(SegmentedPanel, {
152
+ value: "body",
153
+ className: "min-h-0 flex-1 overflow-auto",
154
+ children: size > 0 ? children : /* @__PURE__ */ jsxs("div", {
155
+ className: "flex h-full flex-col items-center justify-center gap-1 p-6 text-center",
156
+ children: [/* @__PURE__ */ jsx("p", {
157
+ className: "text-4xl font-light tracking-tight tabular-nums",
158
+ children: status
159
+ }), /* @__PURE__ */ jsx("p", {
160
+ className: "text-sm text-fd-muted-foreground",
161
+ children: t("Empty response body")
162
+ })]
163
+ })
164
+ }),
165
+ headers && /* @__PURE__ */ jsxs(SegmentedPanel, {
166
+ value: "headers",
167
+ className: "min-h-0 flex-1 overflow-auto",
168
+ children: [/* @__PURE__ */ jsx("p", {
169
+ className: "border-b px-4 py-2.5 font-mono text-xs break-all text-fd-muted-foreground",
170
+ children: url
171
+ }), /* @__PURE__ */ jsx("dl", {
172
+ className: "grid grid-cols-[minmax(0,2fr)_minmax(0,3fr)] font-mono text-xs",
173
+ children: headers.map(([name, value]) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
174
+ className: "truncate border-b py-2 ps-4 pe-2 text-fd-muted-foreground",
175
+ children: name
176
+ }), /* @__PURE__ */ jsx("dd", {
177
+ className: "border-b border-s px-3 py-2 break-all",
178
+ children: value
179
+ })] }, name))
180
+ })]
181
+ })
182
+ ]
183
+ })
184
+ });
185
+ }
186
+ //#endregion
187
+ export { RequestError, ResponseView };
@@ -16,16 +16,18 @@ const anyFields = {
16
16
  items: true,
17
17
  additionalProperties: true
18
18
  };
19
- function SchemaProvider({ readOnly, writeOnly, docRoot, children }) {
19
+ function SchemaProvider({ readOnly, writeOnly, docRoot, Markdown, children }) {
20
20
  return /* @__PURE__ */ jsx(SchemaContext.Provider, {
21
21
  value: useMemo(() => ({
22
22
  readOnly,
23
23
  writeOnly,
24
- docRoot
24
+ docRoot,
25
+ Markdown
25
26
  }), [
26
27
  docRoot,
27
28
  readOnly,
28
- writeOnly
29
+ writeOnly,
30
+ Markdown
29
31
  ]),
30
32
  children
31
33
  });