fumadocs-openapi 12.1.1 → 12.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/generated/shared.css +1 -1
- package/dist/.translations/index.d.ts +63 -20
- package/dist/.translations/keys.js +63 -20
- package/dist/operation.d.ts +6 -1
- package/dist/operation.js +2 -4
- package/dist/packages/shared-api/dist/.translations/index.d.ts +1 -0
- package/dist/packages/shared-api/dist/.translations/keys.js +1 -0
- package/dist/packages/shared-api/dist/auto-anchor/index.js +54 -10
- package/dist/packages/shared-api/dist/components/accordion.js +3 -11
- package/dist/packages/shared-api/dist/components/collapsible.js +2 -2
- package/dist/packages/shared-api/dist/components/schema/client.d.ts +5 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +408 -455
- package/dist/packages/shared-api/dist/components/select-tab.js +7 -12
- package/dist/packages/shared-api/dist/components/select.js +8 -7
- package/dist/playground/auth.d.ts +5 -1
- package/dist/playground/auth.js +7 -2
- package/dist/playground/fetcher.d.ts +8 -0
- package/dist/playground/fetcher.js +30 -1
- package/dist/playground/index.d.ts +2 -1
- package/dist/playground/index.js +2 -1
- package/dist/playground/use-playground.d.ts +62 -0
- package/dist/playground/use-playground.js +140 -0
- package/dist/ui/components/dialog.js +14 -0
- package/dist/ui/components/endpoint.js +40 -0
- package/dist/ui/components/heading.js +1 -1
- package/dist/ui/components/schema.js +1 -1
- package/dist/ui/components/segmented.js +21 -0
- package/dist/ui/operation/index.js +267 -250
- package/dist/ui/playground/client.d.ts +9 -26
- package/dist/ui/playground/client.js +150 -389
- package/dist/ui/playground/components/fields.js +693 -0
- package/dist/ui/playground/components/oauth-panel.js +182 -0
- package/dist/ui/playground/components/request-panel.js +480 -0
- package/dist/ui/playground/components/response-panel.js +150 -0
- package/dist/ui/playground/components/result-display.d.ts +1 -0
- package/dist/ui/playground/components/result-display.js +185 -168
- package/dist/ui/playground/components/server-select.js +100 -89
- package/dist/ui/playground/components/url-bar.js +96 -0
- package/dist/ui/playground/status-info.js +32 -45
- package/dist/utils/document/load.js +1 -1
- package/package.json +12 -12
- package/dist/packages/shared-api/dist/auto-anchor/client.js +0 -20
- package/dist/packages/shared-api/dist/components/collapsible.d.ts +0 -7
- package/dist/packages/shared-api/dist/components/dialog.js +0 -55
- package/dist/packages/shared-api/dist/components/input.js +0 -14
- package/dist/packages/shared-api/dist/components/label.js +0 -11
- package/dist/packages/shared-api/dist/components/playground/inputs.js +0 -439
- package/dist/packages/shared-api/dist/components/popover.js +0 -23
- package/dist/packages/shared-api/dist/utils/merge-refs.js +0 -11
- package/dist/ui/playground/components/oauth-dialog.js +0 -259
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCodeUsage, useOperation, useResponseExamples } from "../../../operation.js";
|
|
3
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
|
+
import { Markdown } from "../../components/markdown.js";
|
|
5
|
+
import { ClientCodeBlock } from "../../components/codeblock.js";
|
|
6
|
+
import { cn } from "../../../utils/cn.js";
|
|
7
|
+
import { Segmented, SegmentedList, SegmentedPanel } from "../../components/segmented.js";
|
|
8
|
+
import { DefaultResultDisplay, PanelHeader, panelCodeBlock } from "./result-display.js";
|
|
9
|
+
import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
13
|
+
import { SendHorizontal } from "lucide-react";
|
|
14
|
+
import { CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger } from "fumadocs-ui/components/codeblock";
|
|
15
|
+
//#region src/ui/playground/components/response-panel.tsx
|
|
16
|
+
/** the code usages of the request, above its response or the documented examples */
|
|
17
|
+
function ResponsePanel({ response, loading, onReset, ResultDisplay = DefaultResultDisplay, className }) {
|
|
18
|
+
const t = useTranslations({ note: "playground" });
|
|
19
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
20
|
+
className: cn("@container flex min-h-0 flex-col", className),
|
|
21
|
+
children: [/* @__PURE__ */ jsx(RequestExample, {}), /* @__PURE__ */ jsxs("div", {
|
|
22
|
+
className: "relative flex min-h-0 flex-1 flex-col",
|
|
23
|
+
children: [response ? /* @__PURE__ */ jsx(ResultDisplay, {
|
|
24
|
+
data: response.result,
|
|
25
|
+
reset: onReset,
|
|
26
|
+
className: "starting:opacity-0 motion-safe:transition-[opacity,translate] motion-safe:duration-300 motion-safe:starting:translate-y-1"
|
|
27
|
+
}, response.id) : /* @__PURE__ */ jsx(ResponseExamples, {}), loading && /* @__PURE__ */ jsxs("div", {
|
|
28
|
+
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",
|
|
29
|
+
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }), t("Sending request...")]
|
|
30
|
+
})]
|
|
31
|
+
})]
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function RequestExample() {
|
|
35
|
+
const items = Array.from(useOperation().codeUsages.map());
|
|
36
|
+
if (items.length === 0) return null;
|
|
37
|
+
return /* @__PURE__ */ jsxs(CodeBlockTabs, {
|
|
38
|
+
groupId: "fumadocs_openapi_requests",
|
|
39
|
+
defaultValue: items[0][0],
|
|
40
|
+
className: "my-0 shrink-0 rounded-none border-0 border-b bg-transparent",
|
|
41
|
+
children: [/* @__PURE__ */ jsx(CodeBlockTabsList, {
|
|
42
|
+
className: "h-10 items-stretch border-b [scrollbar-width:none]",
|
|
43
|
+
children: items.map(([id, item]) => /* @__PURE__ */ jsx(CodeBlockTabsTrigger, {
|
|
44
|
+
value: id,
|
|
45
|
+
children: item.label ?? item.lang
|
|
46
|
+
}, id))
|
|
47
|
+
}), items.map(([id, item]) => /* @__PURE__ */ jsx(CodeBlockTab, {
|
|
48
|
+
value: id,
|
|
49
|
+
children: /* @__PURE__ */ jsx(UsageCode, {
|
|
50
|
+
id,
|
|
51
|
+
lang: item.lang
|
|
52
|
+
})
|
|
53
|
+
}, id))]
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function UsageCode({ id, lang }) {
|
|
57
|
+
const code = useCodeUsage(id);
|
|
58
|
+
if (!code) return null;
|
|
59
|
+
return /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
60
|
+
lang,
|
|
61
|
+
code,
|
|
62
|
+
codeblock: {
|
|
63
|
+
className: "rounded-none border-0 bg-transparent shadow-none",
|
|
64
|
+
viewportProps: { className: "max-h-[min(18rem,30vh)]" }
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function ResponseExamples() {
|
|
69
|
+
const t = useTranslations({ note: "playground" });
|
|
70
|
+
const tabs = useResponseExamples();
|
|
71
|
+
const [code, setCode] = useState();
|
|
72
|
+
const [selected, setSelected] = useState(0);
|
|
73
|
+
if (tabs.length === 0) return /* @__PURE__ */ jsxs("div", {
|
|
74
|
+
className: "flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",
|
|
75
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
76
|
+
className: "rounded-xl border bg-fd-secondary p-2.5 text-fd-muted-foreground",
|
|
77
|
+
children: /* @__PURE__ */ jsx(SendHorizontal, { className: "size-4" })
|
|
78
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
79
|
+
className: "text-sm text-fd-muted-foreground",
|
|
80
|
+
children: t("Send a request to see its response.")
|
|
81
|
+
})]
|
|
82
|
+
});
|
|
83
|
+
const tab = tabs.find((item) => item.code === code) ?? tabs[0];
|
|
84
|
+
const examples = tab.examples ?? [];
|
|
85
|
+
const example = examples[selected];
|
|
86
|
+
return /* @__PURE__ */ jsxs(Segmented, {
|
|
87
|
+
value: tab.code,
|
|
88
|
+
onValueChange: (value) => {
|
|
89
|
+
setCode(value);
|
|
90
|
+
setSelected(0);
|
|
91
|
+
},
|
|
92
|
+
className: "flex min-h-0 flex-1 flex-col",
|
|
93
|
+
children: [/* @__PURE__ */ jsxs(PanelHeader, { children: [
|
|
94
|
+
/* @__PURE__ */ jsx("span", {
|
|
95
|
+
className: "shrink-0 text-[0.8125rem] font-medium",
|
|
96
|
+
children: t("Response")
|
|
97
|
+
}),
|
|
98
|
+
/* @__PURE__ */ jsx("div", {
|
|
99
|
+
title: tab.response.description,
|
|
100
|
+
className: "min-w-0 flex-1 truncate text-xs text-fd-muted-foreground [&_*]:inline [&_a]:underline",
|
|
101
|
+
children: tab.response.description && /* @__PURE__ */ jsx(Markdown, { md: tab.response.description })
|
|
102
|
+
}),
|
|
103
|
+
examples.length > 1 && /* @__PURE__ */ jsxs(Select, {
|
|
104
|
+
items: examples.map((item, i) => ({
|
|
105
|
+
value: String(i),
|
|
106
|
+
label: item.label
|
|
107
|
+
})),
|
|
108
|
+
value: String(selected),
|
|
109
|
+
onValueChange: (v) => v !== null && setSelected(Number(v)),
|
|
110
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
111
|
+
className: "h-7 w-auto max-w-40 shrink-0 gap-1.5 border-0 bg-transparent px-2 text-xs hover:bg-fd-accent focus:ring-0 focus-visible:ring-2",
|
|
112
|
+
children: /* @__PURE__ */ jsx(SelectValue, { className: "truncate" })
|
|
113
|
+
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
114
|
+
align: "end",
|
|
115
|
+
children: examples.map((item, i) => /* @__PURE__ */ jsx(SelectItem, {
|
|
116
|
+
value: String(i),
|
|
117
|
+
className: "text-xs",
|
|
118
|
+
children: item.label
|
|
119
|
+
}, i))
|
|
120
|
+
})]
|
|
121
|
+
}),
|
|
122
|
+
/* @__PURE__ */ jsx(SegmentedList, {
|
|
123
|
+
className: "max-w-1/2 shrink-0 overflow-x-auto [scrollbar-width:none]",
|
|
124
|
+
items: tabs.map((item) => ({
|
|
125
|
+
value: item.code,
|
|
126
|
+
label: /* @__PURE__ */ jsx("span", {
|
|
127
|
+
className: "font-mono",
|
|
128
|
+
children: item.code
|
|
129
|
+
})
|
|
130
|
+
}))
|
|
131
|
+
})
|
|
132
|
+
] }), /* @__PURE__ */ jsx(SegmentedPanel, {
|
|
133
|
+
value: tab.code,
|
|
134
|
+
className: "flex min-h-0 flex-1 flex-col overflow-auto",
|
|
135
|
+
children: example ? /* @__PURE__ */ jsx("div", {
|
|
136
|
+
className: "min-h-0 flex-1",
|
|
137
|
+
children: /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
138
|
+
lang: "json",
|
|
139
|
+
code: JSON.stringify(example.sample, null, 2),
|
|
140
|
+
codeblock: panelCodeBlock
|
|
141
|
+
})
|
|
142
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
143
|
+
className: "p-4 text-sm text-fd-muted-foreground",
|
|
144
|
+
children: t("No example available.")
|
|
145
|
+
})
|
|
146
|
+
}, tab.code)]
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { ResponsePanel };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FetchResult } from "../../../playground/fetcher.js";
|
|
2
2
|
import { ComponentProps } from "react";
|
|
3
|
+
import "fumadocs-ui/components/codeblock";
|
|
3
4
|
//#region src/ui/playground/components/result-display.d.ts
|
|
4
5
|
export interface ResultDisplayProps extends ComponentProps<'div'> {
|
|
5
6
|
data: FetchResult;
|
|
@@ -2,48 +2,60 @@
|
|
|
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 {
|
|
6
|
-
import {
|
|
7
|
-
import { Fragment
|
|
8
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { Segmented, SegmentedList, SegmentedPanel } from "../../components/segmented.js";
|
|
6
|
+
import { Fragment, useCallback, useMemo, useState } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
8
|
import { useTranslations } from "@fuma-translate/react";
|
|
10
|
-
import {
|
|
11
|
-
import { ChevronDown, CircleX, DownloadIcon, SignpostIcon } from "lucide-react";
|
|
9
|
+
import { DownloadIcon, FileIcon, X } from "lucide-react";
|
|
12
10
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
13
11
|
//#region src/ui/playground/components/result-display.tsx
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
|
16
27
|
function DefaultResultDisplay({ data, reset, ...rest }) {
|
|
17
28
|
const t = useTranslations({ note: "playground result display" });
|
|
18
29
|
if (data.type === "client_error") return /* @__PURE__ */ jsxs("div", {
|
|
19
30
|
...rest,
|
|
20
|
-
className: cn(
|
|
21
|
-
children: [
|
|
22
|
-
/* @__PURE__ */
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/* @__PURE__ */ jsx("p", {
|
|
27
|
-
className: "text-sm font-medium me-auto",
|
|
28
|
-
children: t("Client Error")
|
|
29
|
-
}),
|
|
30
|
-
/* @__PURE__ */ jsx("button", {
|
|
31
|
-
type: "button",
|
|
32
|
-
className: cn(buttonVariants({
|
|
33
|
-
size: "sm",
|
|
34
|
-
variant: "outline"
|
|
35
|
-
})),
|
|
36
|
-
onClick: () => reset(),
|
|
37
|
-
children: t("Close")
|
|
38
|
-
})
|
|
39
|
-
]
|
|
31
|
+
className: cn("flex min-h-0 flex-1 flex-col", rest.className),
|
|
32
|
+
children: [/* @__PURE__ */ jsxs(PanelHeader, { children: [
|
|
33
|
+
/* @__PURE__ */ jsx("span", { className: "size-2 shrink-0 rounded-full bg-red-500" }),
|
|
34
|
+
/* @__PURE__ */ jsx("span", {
|
|
35
|
+
className: "text-[0.8125rem] font-medium",
|
|
36
|
+
children: t("Request Failed")
|
|
40
37
|
}),
|
|
41
|
-
/* @__PURE__ */
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
/* @__PURE__ */ jsx("button", {
|
|
39
|
+
type: "button",
|
|
40
|
+
"aria-label": t("Clear"),
|
|
41
|
+
className: cn(iconButtonClassName, "ms-auto"),
|
|
42
|
+
onClick: reset,
|
|
43
|
+
children: /* @__PURE__ */ jsx(X, {})
|
|
44
|
+
})
|
|
45
|
+
] }), /* @__PURE__ */ jsxs("div", {
|
|
46
|
+
className: "flex flex-col gap-3 overflow-auto p-4 text-sm",
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ jsx("p", { children: data.message }),
|
|
49
|
+
/* @__PURE__ */ jsx("p", {
|
|
50
|
+
className: "font-mono text-xs break-all text-fd-muted-foreground",
|
|
51
|
+
children: data.url
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsx("p", {
|
|
54
|
+
className: "rounded-lg border bg-fd-secondary p-3 text-xs text-fd-muted-foreground",
|
|
55
|
+
children: t("Check the server URL. If the API does not allow cross-origin requests from this site, a proxy is needed.")
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
})]
|
|
47
59
|
});
|
|
48
60
|
return /* @__PURE__ */ jsx(ResponseResult, {
|
|
49
61
|
data,
|
|
@@ -66,167 +78,172 @@ function getTextFormat(mime) {
|
|
|
66
78
|
if (mime.startsWith("text/")) return "text";
|
|
67
79
|
return null;
|
|
68
80
|
}
|
|
81
|
+
function formatDuration(ms) {
|
|
82
|
+
return ms < 1e3 ? `${Math.round(ms)} ms` : `${(ms / 1e3).toFixed(2)} s`;
|
|
83
|
+
}
|
|
84
|
+
function formatSize(bytes) {
|
|
85
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
86
|
+
if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)} kB`;
|
|
87
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
88
|
+
}
|
|
69
89
|
function ResponseResult({ data, reset, ...rest }) {
|
|
70
90
|
const t = useTranslations({ note: "playground result display" });
|
|
71
91
|
const statusInfo = useStatusInfo(data.status);
|
|
72
|
-
const [
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
const [view, setView] = useState("body");
|
|
93
|
+
const type = data.mediaType ?? "text/plain";
|
|
94
|
+
const headers = Array.from(data.headers);
|
|
95
|
+
const size = data.body.byteLength;
|
|
96
|
+
const bodyUrlRef = useCallback((element) => {
|
|
97
|
+
if (!element) return;
|
|
98
|
+
const url = URL.createObjectURL(new Blob([data.body], { type }));
|
|
99
|
+
if (element instanceof HTMLAnchorElement) element.href = url;
|
|
100
|
+
else element.src = url;
|
|
101
|
+
return () => URL.revokeObjectURL(url);
|
|
78
102
|
}, [data.body, type]);
|
|
79
103
|
let body;
|
|
80
|
-
if (type.startsWith("image/")) body =
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
if (type.startsWith("image/")) body = /* @__PURE__ */ jsx("div", {
|
|
105
|
+
className: "flex min-h-full items-center justify-center p-4",
|
|
106
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
107
|
+
ref: bodyUrlRef,
|
|
108
|
+
alt: "",
|
|
109
|
+
className: "max-w-full rounded-lg border"
|
|
110
|
+
})
|
|
83
111
|
});
|
|
84
|
-
else if (
|
|
112
|
+
else if (size > 0) {
|
|
85
113
|
const lang = getTextFormat(type);
|
|
86
114
|
if (lang) body = /* @__PURE__ */ jsx(TextResult, {
|
|
87
115
|
lang,
|
|
88
|
-
contentType: type,
|
|
89
|
-
charset: parameters.charset,
|
|
90
116
|
data
|
|
91
117
|
});
|
|
92
118
|
else body = /* @__PURE__ */ jsxs("div", {
|
|
93
|
-
className: "
|
|
94
|
-
children: [
|
|
95
|
-
className: "
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
119
|
+
className: "flex h-full flex-col items-center justify-center gap-2 p-6 text-center",
|
|
120
|
+
children: [
|
|
121
|
+
/* @__PURE__ */ jsx(FileIcon, { className: "size-5 text-fd-muted-foreground" }),
|
|
122
|
+
/* @__PURE__ */ jsx("p", {
|
|
123
|
+
className: "text-sm font-medium",
|
|
124
|
+
children: t("Binary response body, {length} bytes", { variables: { length: String(size) } })
|
|
125
|
+
}),
|
|
126
|
+
type && /* @__PURE__ */ jsx("p", {
|
|
127
|
+
className: "font-mono text-xs text-fd-muted-foreground",
|
|
128
|
+
children: type
|
|
129
|
+
})
|
|
130
|
+
]
|
|
101
131
|
});
|
|
102
|
-
}
|
|
103
|
-
|
|
132
|
+
} else body = /* @__PURE__ */ jsxs("div", {
|
|
133
|
+
className: "flex h-full flex-col items-center justify-center gap-1 p-6 text-center",
|
|
134
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
135
|
+
className: "text-4xl font-light tracking-tight tabular-nums",
|
|
136
|
+
children: data.status
|
|
137
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
138
|
+
className: "text-sm text-fd-muted-foreground",
|
|
139
|
+
children: t("Empty response body")
|
|
140
|
+
})]
|
|
141
|
+
});
|
|
142
|
+
return /* @__PURE__ */ jsx("div", {
|
|
104
143
|
...rest,
|
|
105
|
-
className: cn(
|
|
106
|
-
children:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
144
|
+
className: cn("flex min-h-0 flex-1 flex-col", rest.className),
|
|
145
|
+
children: /* @__PURE__ */ jsxs(Segmented, {
|
|
146
|
+
value: view,
|
|
147
|
+
onValueChange: setView,
|
|
148
|
+
className: "flex min-h-0 flex-1 flex-col",
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ jsxs(PanelHeader, { children: [
|
|
151
|
+
/* @__PURE__ */ jsx("span", { className: cn("size-2 shrink-0 rounded-full motion-safe:transition-transform motion-safe:duration-300 motion-safe:starting:scale-0", statusInfo.color) }),
|
|
111
152
|
/* @__PURE__ */ jsxs("p", {
|
|
112
|
-
className: "min-w-0
|
|
153
|
+
className: "min-w-0 truncate text-[0.8125rem] font-medium",
|
|
113
154
|
children: [
|
|
114
|
-
|
|
155
|
+
/* @__PURE__ */ jsx("span", {
|
|
156
|
+
className: "tabular-nums",
|
|
157
|
+
children: data.status
|
|
158
|
+
}),
|
|
115
159
|
" ",
|
|
116
|
-
|
|
160
|
+
/* @__PURE__ */ jsx("span", {
|
|
161
|
+
className: "font-normal text-fd-muted-foreground",
|
|
162
|
+
children: statusInfo.description
|
|
163
|
+
})
|
|
117
164
|
]
|
|
118
165
|
}),
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
166
|
+
/* @__PURE__ */ jsxs("p", {
|
|
167
|
+
className: "hidden shrink-0 text-xs text-fd-muted-foreground tabular-nums @md:block",
|
|
168
|
+
children: [
|
|
169
|
+
formatDuration(data.duration),
|
|
170
|
+
" · ",
|
|
171
|
+
formatSize(size)
|
|
172
|
+
]
|
|
173
|
+
}),
|
|
174
|
+
/* @__PURE__ */ jsx(SegmentedList, {
|
|
175
|
+
className: "ms-auto shrink-0",
|
|
176
|
+
items: [{
|
|
177
|
+
value: "body",
|
|
178
|
+
label: t("Body")
|
|
179
|
+
}, {
|
|
180
|
+
value: "headers",
|
|
181
|
+
label: /* @__PURE__ */ jsxs(Fragment$1, { children: [t("Headers"), /* @__PURE__ */ jsx("span", {
|
|
182
|
+
className: "text-fd-muted-foreground tabular-nums",
|
|
183
|
+
children: headers.length
|
|
184
|
+
})] })
|
|
185
|
+
}]
|
|
127
186
|
}),
|
|
128
|
-
/* @__PURE__ */
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
187
|
+
/* @__PURE__ */ jsxs("div", {
|
|
188
|
+
className: "flex shrink-0 items-center",
|
|
189
|
+
children: [size > 0 && /* @__PURE__ */ jsx("a", {
|
|
190
|
+
ref: bodyUrlRef,
|
|
191
|
+
download: data.fileName ?? "response",
|
|
192
|
+
"aria-label": t("Download"),
|
|
193
|
+
title: t("Download"),
|
|
194
|
+
className: iconButtonClassName,
|
|
195
|
+
children: /* @__PURE__ */ jsx(DownloadIcon, {})
|
|
196
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
197
|
+
type: "button",
|
|
198
|
+
"aria-label": t("Clear"),
|
|
199
|
+
title: t("Clear"),
|
|
200
|
+
className: iconButtonClassName,
|
|
201
|
+
onClick: reset,
|
|
202
|
+
children: /* @__PURE__ */ jsx(X, {})
|
|
203
|
+
})]
|
|
136
204
|
})
|
|
137
|
-
]
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
205
|
+
] }),
|
|
206
|
+
/* @__PURE__ */ jsx(SegmentedPanel, {
|
|
207
|
+
value: "body",
|
|
208
|
+
className: "min-h-0 flex-1 overflow-auto",
|
|
209
|
+
children: body
|
|
210
|
+
}),
|
|
211
|
+
/* @__PURE__ */ jsxs(SegmentedPanel, {
|
|
212
|
+
value: "headers",
|
|
213
|
+
className: "min-h-0 flex-1 overflow-auto",
|
|
214
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
215
|
+
className: "border-b px-4 py-2.5 font-mono text-xs break-all text-fd-muted-foreground",
|
|
216
|
+
children: data.url
|
|
217
|
+
}), /* @__PURE__ */ jsx("dl", {
|
|
218
|
+
className: "grid grid-cols-[minmax(0,2fr)_minmax(0,3fr)] font-mono text-xs",
|
|
219
|
+
children: headers.map(([name, value]) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
|
|
220
|
+
className: "truncate border-b py-2 ps-4 pe-2 text-fd-muted-foreground",
|
|
221
|
+
children: name
|
|
222
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
223
|
+
className: "border-b border-s px-3 py-2 break-all",
|
|
224
|
+
children: value
|
|
225
|
+
})] }, name))
|
|
226
|
+
})]
|
|
227
|
+
})
|
|
228
|
+
]
|
|
229
|
+
})
|
|
146
230
|
});
|
|
147
231
|
}
|
|
148
|
-
function
|
|
149
|
-
const t = useTranslations({ note: "playground result display" });
|
|
150
|
-
const entries = Array.from(headers);
|
|
151
|
-
if (entries.length === 0) return;
|
|
152
|
-
return /* @__PURE__ */ jsxs(Collapsible, { children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
153
|
-
className: "group inline-flex w-fit items-center gap-1 text-xs font-medium text-fd-muted-foreground hover:text-fd-accent-foreground",
|
|
154
|
-
children: [
|
|
155
|
-
t("Headers"),
|
|
156
|
-
/* @__PURE__ */ jsxs("span", {
|
|
157
|
-
className: "font-normal",
|
|
158
|
-
children: [
|
|
159
|
-
"(",
|
|
160
|
-
entries.length,
|
|
161
|
-
")"
|
|
162
|
-
]
|
|
163
|
-
}),
|
|
164
|
-
/* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5 group-data-[panel-open]:rotate-180" })
|
|
165
|
-
]
|
|
166
|
-
}), /* @__PURE__ */ jsx(CollapsibleContent, { children: /* @__PURE__ */ jsx("dl", {
|
|
167
|
-
className: "grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 pt-2 font-mono text-xs",
|
|
168
|
-
children: entries.map(([name, value]) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
|
|
169
|
-
className: "text-fd-muted-foreground",
|
|
170
|
-
children: name
|
|
171
|
-
}), /* @__PURE__ */ jsx("dd", {
|
|
172
|
-
className: "break-all",
|
|
173
|
-
children: value
|
|
174
|
-
})] }, name))
|
|
175
|
-
}) })] });
|
|
176
|
-
}
|
|
177
|
-
function TextResult({ lang, charset, data, contentType }) {
|
|
232
|
+
function TextResult({ lang, data }) {
|
|
178
233
|
const code = useMemo(() => {
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return out;
|
|
188
|
-
}, [
|
|
189
|
-
lang,
|
|
190
|
-
charset,
|
|
191
|
-
data.body
|
|
192
|
-
]);
|
|
234
|
+
const text = data.text();
|
|
235
|
+
if (lang !== "json") return text;
|
|
236
|
+
try {
|
|
237
|
+
return JSON.stringify(JSON.parse(text), null, 2);
|
|
238
|
+
} catch {
|
|
239
|
+
return text;
|
|
240
|
+
}
|
|
241
|
+
}, [lang, data]);
|
|
193
242
|
return /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
194
243
|
lang: code.length > 5e3 ? "text" : lang,
|
|
195
244
|
code,
|
|
196
|
-
codeblock:
|
|
197
|
-
className: "text-xs font-mono",
|
|
198
|
-
children: contentType
|
|
199
|
-
}) }
|
|
245
|
+
codeblock: panelCodeBlock
|
|
200
246
|
});
|
|
201
247
|
}
|
|
202
|
-
function ImageResult({ mime, src }) {
|
|
203
|
-
return /* @__PURE__ */ jsxs("figure", {
|
|
204
|
-
className: "w-full p-1 bg-fd-card border rounded-lg shadow-sm",
|
|
205
|
-
children: [/* @__PURE__ */ jsx("figcaption", {
|
|
206
|
-
className: "text-xs text-fd-muted-foreground font-mono p-1 pb-2",
|
|
207
|
-
children: mime
|
|
208
|
-
}), /* @__PURE__ */ jsx("img", {
|
|
209
|
-
src,
|
|
210
|
-
alt: "",
|
|
211
|
-
className: "w-full rounded-md"
|
|
212
|
-
})]
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* The file name from `Content-Disposition`, preferring `filename*` (RFC 6266), without directories.
|
|
217
|
-
*/
|
|
218
|
-
function getFileName(headers) {
|
|
219
|
-
const disposition = headers.get("Content-Disposition") ?? "";
|
|
220
|
-
const extended = /(?:^|;)\s*filename\*\s*=\s*[^']*'[^']*'([^\s;"]+)/i.exec(disposition);
|
|
221
|
-
let name;
|
|
222
|
-
if (extended) try {
|
|
223
|
-
name = decodeURIComponent(extended[1]);
|
|
224
|
-
} catch {}
|
|
225
|
-
if (!name) {
|
|
226
|
-
const match = /(?:^|;)\s*filename\s*=\s*(?:"((?:\\.|[^"\\])*)"|([^\s;]+))/i.exec(disposition);
|
|
227
|
-
name = match?.[1]?.replace(/\\(.)/g, "$1") ?? match?.[2];
|
|
228
|
-
}
|
|
229
|
-
return name?.replace(/^.*[/\\]/, "") || "response";
|
|
230
|
-
}
|
|
231
248
|
//#endregion
|
|
232
|
-
export { DefaultResultDisplay };
|
|
249
|
+
export { DefaultResultDisplay, PanelHeader, iconButtonClassName, panelCodeBlock };
|