fumadocs-openapi 12.1.0 → 12.2.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 -17
- package/dist/.translations/keys.js +63 -17
- package/dist/operation.d.ts +6 -1
- package/dist/operation.js +2 -4
- package/dist/packages/shared-api/dist/components/select.js +8 -7
- package/dist/playground/auth.d.ts +13 -3
- package/dist/playground/auth.js +58 -46
- 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/endpoint.js +37 -0
- package/dist/ui/operation/index.js +6 -14
- package/dist/ui/playground/client.d.ts +9 -26
- package/dist/ui/playground/client.js +150 -390
- 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 +187 -147
- package/dist/ui/playground/components/segmented.js +21 -0
- 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 +10 -10
- package/dist/packages/shared-api/dist/components/collapsible.d.ts +0 -7
- package/dist/packages/shared-api/dist/components/collapsible.js +0 -16
- 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/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 "./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 "./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, 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,144 +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
|
|
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);
|
|
102
|
+
}, [data.body, type]);
|
|
73
103
|
let body;
|
|
74
|
-
if (type.startsWith("image/")) body = /* @__PURE__ */ jsx(
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
})
|
|
77
111
|
});
|
|
78
|
-
else if (
|
|
112
|
+
else if (size > 0) {
|
|
79
113
|
const lang = getTextFormat(type);
|
|
80
114
|
if (lang) body = /* @__PURE__ */ jsx(TextResult, {
|
|
81
115
|
lang,
|
|
82
|
-
contentType: type,
|
|
83
|
-
charset: parameters.charset,
|
|
84
116
|
data
|
|
85
117
|
});
|
|
86
118
|
else body = /* @__PURE__ */ jsxs("div", {
|
|
87
|
-
className: "
|
|
88
|
-
children: [
|
|
89
|
-
className: "
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
]
|
|
95
131
|
});
|
|
96
|
-
}
|
|
97
|
-
|
|
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", {
|
|
98
143
|
...rest,
|
|
99
|
-
className: cn(
|
|
100
|
-
children:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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) }),
|
|
105
152
|
/* @__PURE__ */ jsxs("p", {
|
|
106
|
-
className: "text-
|
|
153
|
+
className: "min-w-0 truncate text-[0.8125rem] font-medium",
|
|
107
154
|
children: [
|
|
108
|
-
|
|
155
|
+
/* @__PURE__ */ jsx("span", {
|
|
156
|
+
className: "tabular-nums",
|
|
157
|
+
children: data.status
|
|
158
|
+
}),
|
|
109
159
|
" ",
|
|
110
|
-
|
|
160
|
+
/* @__PURE__ */ jsx("span", {
|
|
161
|
+
className: "font-normal text-fd-muted-foreground",
|
|
162
|
+
children: statusInfo.description
|
|
163
|
+
})
|
|
164
|
+
]
|
|
165
|
+
}),
|
|
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)
|
|
111
172
|
]
|
|
112
173
|
}),
|
|
113
|
-
/* @__PURE__ */ jsx(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
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
|
+
}]
|
|
186
|
+
}),
|
|
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
|
+
})]
|
|
121
204
|
})
|
|
122
|
-
]
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
+
})
|
|
131
230
|
});
|
|
132
231
|
}
|
|
133
|
-
function
|
|
134
|
-
const t = useTranslations({ note: "playground result display" });
|
|
135
|
-
const entries = Array.from(headers);
|
|
136
|
-
if (entries.length === 0) return;
|
|
137
|
-
return /* @__PURE__ */ jsxs(Collapsible, { children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
138
|
-
className: "group inline-flex w-fit items-center gap-1 text-xs font-medium text-fd-muted-foreground hover:text-fd-accent-foreground",
|
|
139
|
-
children: [
|
|
140
|
-
t("Headers"),
|
|
141
|
-
/* @__PURE__ */ jsxs("span", {
|
|
142
|
-
className: "font-normal",
|
|
143
|
-
children: [
|
|
144
|
-
"(",
|
|
145
|
-
entries.length,
|
|
146
|
-
")"
|
|
147
|
-
]
|
|
148
|
-
}),
|
|
149
|
-
/* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5 group-data-[panel-open]:rotate-180" })
|
|
150
|
-
]
|
|
151
|
-
}), /* @__PURE__ */ jsx(CollapsibleContent, { children: /* @__PURE__ */ jsx("dl", {
|
|
152
|
-
className: "grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 pt-2 font-mono text-xs",
|
|
153
|
-
children: entries.map(([name, value]) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
|
|
154
|
-
className: "text-fd-muted-foreground",
|
|
155
|
-
children: name
|
|
156
|
-
}), /* @__PURE__ */ jsx("dd", {
|
|
157
|
-
className: "break-all",
|
|
158
|
-
children: value
|
|
159
|
-
})] }, name))
|
|
160
|
-
}) })] });
|
|
161
|
-
}
|
|
162
|
-
function TextResult({ lang, charset, data, contentType }) {
|
|
232
|
+
function TextResult({ lang, data }) {
|
|
163
233
|
const code = useMemo(() => {
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return out;
|
|
173
|
-
}, [
|
|
174
|
-
lang,
|
|
175
|
-
charset,
|
|
176
|
-
data.body
|
|
177
|
-
]);
|
|
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]);
|
|
178
242
|
return /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
179
243
|
lang: code.length > 5e3 ? "text" : lang,
|
|
180
244
|
code,
|
|
181
|
-
codeblock:
|
|
182
|
-
className: "text-xs font-mono",
|
|
183
|
-
children: contentType
|
|
184
|
-
}) }
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
function ImageResult({ mime, buffer }) {
|
|
188
|
-
const [objectUrl, setObjectUrl] = useState(null);
|
|
189
|
-
useEffect(() => {
|
|
190
|
-
const blob = new Blob([buffer], { type: mime });
|
|
191
|
-
const url = URL.createObjectURL(blob);
|
|
192
|
-
setObjectUrl(url);
|
|
193
|
-
return () => URL.revokeObjectURL(url);
|
|
194
|
-
}, [mime, buffer]);
|
|
195
|
-
if (!objectUrl) return;
|
|
196
|
-
return /* @__PURE__ */ jsxs("figure", {
|
|
197
|
-
className: "w-full p-1 bg-fd-card border rounded-lg shadow-sm",
|
|
198
|
-
children: [/* @__PURE__ */ jsx("figcaption", {
|
|
199
|
-
className: "text-xs text-fd-muted-foreground font-mono p-1 pb-2",
|
|
200
|
-
children: mime
|
|
201
|
-
}), /* @__PURE__ */ jsx("img", {
|
|
202
|
-
src: objectUrl,
|
|
203
|
-
alt: "",
|
|
204
|
-
className: "w-full rounded-md"
|
|
205
|
-
})]
|
|
245
|
+
codeblock: panelCodeBlock
|
|
206
246
|
});
|
|
207
247
|
}
|
|
208
248
|
//#endregion
|
|
209
|
-
export { DefaultResultDisplay };
|
|
249
|
+
export { DefaultResultDisplay, PanelHeader, iconButtonClassName, panelCodeBlock };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../../utils/cn.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Tabs } from "@base-ui/react/tabs";
|
|
5
|
+
//#region src/ui/playground/components/segmented.tsx
|
|
6
|
+
const Segmented = Tabs.Root;
|
|
7
|
+
const SegmentedPanel = Tabs.Panel;
|
|
8
|
+
/** a pill switch with a sliding indicator, its panels go in `<SegmentedPanel />` */
|
|
9
|
+
function SegmentedList({ items, className, ...props }) {
|
|
10
|
+
return /* @__PURE__ */ jsxs(Tabs.List, {
|
|
11
|
+
...props,
|
|
12
|
+
className: cn("relative z-0 flex items-center rounded-lg bg-fd-secondary p-0.5 text-xs font-medium", className),
|
|
13
|
+
children: [items.map((item) => /* @__PURE__ */ jsx(Tabs.Tab, {
|
|
14
|
+
value: item.value,
|
|
15
|
+
className: "inline-flex h-6 items-center gap-1.5 rounded-md px-2 text-fd-muted-foreground transition-colors hover:text-fd-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring data-active:text-fd-foreground",
|
|
16
|
+
children: item.label
|
|
17
|
+
}, item.value)), /* @__PURE__ */ jsx(Tabs.Indicator, { className: "absolute top-(--active-tab-top) left-0 -z-1 h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) rounded-md bg-fd-background shadow-sm ring-1 ring-fd-border transition-[translate,width] duration-250 ease-[cubic-bezier(0.16,1,0.3,1)] motion-reduce:transition-none dark:bg-fd-accent" })]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Segmented, SegmentedList, SegmentedPanel };
|