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
@@ -1,13 +1,12 @@
1
1
  import { fromSchema, getPageProps } from "../utils/pages/builder.js";
2
2
  import { toStaticData } from "../utils/pages/to-static-data.js";
3
3
  import { createAutoPreset } from "../utils/pages/preset-auto.js";
4
+ import { toVirtualFiles } from "../packages/shared-api/dist/source.js";
4
5
  import { createProxy } from "./proxy.js";
5
6
  import { createOAuthHandler } from "./oauth.js";
6
7
  import { loadDocument } from "../utils/document/load.js";
7
8
  import { MethodLabel } from "../ui/components/method-label.js";
8
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
- import path from "node:path";
10
- import { PathUtils } from "fumadocs-core/source";
11
10
  //#region src/server/index.tsx
12
11
  function createOpenAPI(options = {}) {
13
12
  const { disableCache = false } = options;
@@ -31,7 +30,6 @@ function createOpenAPI(options = {}) {
31
30
  return Object.fromEntries(entries);
32
31
  }
33
32
  async function getVirtualFiles(server, options, docFilesCache) {
34
- const { baseDir = "", meta = false } = options;
35
33
  const files = [];
36
34
  for (const [id, schema] of Object.entries(await server.getSchemas())) {
37
35
  const cachedDocFiles = docFilesCache?.get(schema);
@@ -39,71 +37,35 @@ function createOpenAPI(options = {}) {
39
37
  files.push(...cachedDocFiles);
40
38
  continue;
41
39
  }
42
- const entries = onEntries(fromSchema(id, schema.bundled, createAutoPreset(options)));
43
- docFilesCache?.set(schema, entries);
44
- files.push(...entries);
45
- function onEntry(entry) {
40
+ const entries = toVirtualFiles(fromSchema(id, schema.bundled, createAutoPreset(options)), options, (entry) => {
46
41
  const props = getPageProps(entry);
47
42
  return {
48
- type: "page",
49
- path: `${baseDir}/${entry.path}`,
50
- data: {
51
- ...entry.info,
52
- getOpenAPIPageProps() {
53
- return {
54
- payload: {
55
- bundled: schema.bundled,
56
- proxyUrl: server.options.proxyUrl
57
- },
58
- ...props
59
- };
60
- },
61
- getSchema() {
62
- return {
63
- id,
64
- bundled: schema.bundled
65
- };
66
- },
67
- ...toStaticData(props, schema.bundled),
68
- _openapi: {
69
- method: entry.type === "operation" || entry.type === "webhook" ? entry.item.method : void 0,
70
- webhook: entry.type === "webhook",
71
- deprecated: entry.info.deprecated
72
- }
43
+ ...entry.info,
44
+ getOpenAPIPageProps() {
45
+ return {
46
+ payload: {
47
+ bundled: schema.bundled,
48
+ proxyUrl: server.options.proxyUrl
49
+ },
50
+ ...props
51
+ };
52
+ },
53
+ getSchema() {
54
+ return {
55
+ id,
56
+ bundled: schema.bundled
57
+ };
58
+ },
59
+ ...toStaticData(props, schema.bundled),
60
+ _openapi: {
61
+ method: entry.type === "operation" || entry.type === "webhook" ? entry.item.method : void 0,
62
+ webhook: entry.type === "webhook",
63
+ deprecated: entry.info.deprecated
73
64
  }
74
65
  };
75
- }
76
- function onEntries(entries, parent) {
77
- const out = [];
78
- if (!meta) {
79
- for (const entry of entries) if (entry.type === "group") out.push(...onEntries(entry.entries, entry));
80
- else out.push(onEntry(entry));
81
- return out;
82
- }
83
- const { folderStyle = "folder" } = meta === true ? {} : meta;
84
- const pages = [];
85
- for (const entry of entries) {
86
- const relativePath = PathUtils.slash(parent ? path.relative(parent.path, entry.path) : entry.path);
87
- if (entry.type === "group") {
88
- out.push(...onEntries(entry.entries, entry));
89
- if (folderStyle === "folder") pages.push(relativePath);
90
- else pages.push(`---${entry.info.title}---`, `...${relativePath}`);
91
- } else {
92
- out.push(onEntry(entry));
93
- pages.push(relativePath.slice(0, -path.extname(entry.path).length));
94
- }
95
- }
96
- if (pages.length > 0) out.push({
97
- type: "meta",
98
- path: path.join(baseDir, parent?.path ?? "", "meta.json"),
99
- data: {
100
- title: parent?.info.title,
101
- description: parent?.info.description,
102
- pages
103
- }
104
- });
105
- return out;
106
- }
66
+ });
67
+ docFilesCache?.set(schema, entries);
68
+ files.push(...entries);
107
69
  }
108
70
  return files;
109
71
  }
package/dist/ui/base.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { createOpenAPIRenderer } from "../utils/create-page.js";
2
+ import { createRenderer } from "../utils/create-page.js";
3
3
  import { Schema } from "../packages/shared-api/dist/components/schema/index.js";
4
4
  import { Operation } from "./operation/index.js";
5
5
  import { jsxs } from "react/jsx-runtime";
@@ -8,7 +8,7 @@ import { jsxs } from "react/jsx-runtime";
8
8
  * Create `<OpenAPIPage />` (a client component) without the full Shiki bundle.
9
9
  */
10
10
  function createOpenAPIPageBase(options) {
11
- return createOpenAPIRenderer({
11
+ return createRenderer({
12
12
  ...options,
13
13
  components: {
14
14
  SchemaUI: Schema,
@@ -10,16 +10,16 @@ import { AnchorSection, useAnchorLink } from "../../packages/shared-api/dist/aut
10
10
  import { SchemaUI } from "../components/schema.js";
11
11
  import { SelectTab, SelectTabTrigger, SelectTabs } from "../../packages/shared-api/dist/components/select-tab.js";
12
12
  import { Heading } from "../components/heading.js";
13
- import { Segmented, SegmentedList, SegmentedPanel } from "../components/segmented.js";
13
+ import { CopyTypeScript } from "../../packages/shared-api/dist/components/copy-typescript.js";
14
+ import { Segmented, SegmentedList, SegmentedPanel } from "../../packages/shared-api/dist/components/segmented.js";
14
15
  import { EndpointBar } from "../components/endpoint.js";
15
- import { DialogPopup } from "../components/dialog.js";
16
+ import { DialogPopup } from "../../packages/shared-api/dist/components/dialog.js";
16
17
  import PlaygroundClient from "../playground/client.js";
17
18
  import { Fragment, useState } from "react";
18
19
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
19
20
  import { useTranslations } from "@fuma-translate/react";
20
- import { Check, ChevronRight, Copy, Plus, X } from "lucide-react";
21
+ import { ChevronRight, Plus, X } from "lucide-react";
21
22
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
22
- import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
23
23
  import { Dialog } from "@base-ui/react/dialog";
24
24
  import { Callout } from "fumadocs-ui/components/callout";
25
25
  //#region src/ui/operation/index.tsx
@@ -88,7 +88,7 @@ function OperationContent({ showTitle, showDescription, headingLevel = 2 }) {
88
88
  children: /* @__PURE__ */ jsx(MediaContent, {
89
89
  schema: content.schema,
90
90
  required: requestBody.required,
91
- selector: /* @__PURE__ */ jsx(CardSelector, { items }),
91
+ selector: /* @__PURE__ */ jsx(SelectTabTrigger, { items }),
92
92
  request: true
93
93
  })
94
94
  }, mediaType))
@@ -153,7 +153,7 @@ function OperationContent({ showTitle, showDescription, headingLevel = 2 }) {
153
153
  className: "overflow-hidden rounded-xl border bg-fd-card",
154
154
  children: [/* @__PURE__ */ jsx("div", {
155
155
  className: "flex h-9 items-center border-b ps-1.5 pe-1 text-[0.8125rem] not-prose",
156
- children: /* @__PURE__ */ jsx(CardSelector, { items })
156
+ children: /* @__PURE__ */ jsx(SelectTabTrigger, { items })
157
157
  }), security.map((requirement, i) => /* @__PURE__ */ jsx(SelectTab, {
158
158
  value: items[i].value,
159
159
  className: "px-3",
@@ -272,17 +272,6 @@ function SectionHeader({ id, depth, title, children }) {
272
272
  }), children]
273
273
  });
274
274
  }
275
- /** selects the variant shown in a card, like the media type */
276
- function CardSelector({ items }) {
277
- if (items.length > 1) return /* @__PURE__ */ jsx(SelectTabTrigger, {
278
- items,
279
- className: "h-7 w-auto gap-1 border-0 bg-transparent px-1.5 py-0 text-[0.8125rem] font-medium hover:bg-fd-accent hover:text-fd-accent-foreground focus:ring-0 focus-visible:ring-2 focus-visible:ring-inset data-popup-open:bg-fd-accent"
280
- });
281
- return /* @__PURE__ */ jsx("span", {
282
- className: "min-w-0 px-1.5 font-medium",
283
- children: items[0].label
284
- });
285
- }
286
275
  /** the schema of a request body or response in a media type */
287
276
  function MediaContent({ schema, required, selector, request = false }) {
288
277
  const { method } = useOperation();
@@ -312,26 +301,6 @@ function MediaContent({ schema, required, selector, request = false }) {
312
301
  writeOnly: request && method !== "get"
313
302
  });
314
303
  }
315
- function CopyTypeScript({ name, generate }) {
316
- const t = useTranslations({ note: "TypeScript definitions" });
317
- const [isChecked, onCopy] = useCopyButton(() => {
318
- const code = generate();
319
- if (typeof code === "string") return navigator.clipboard.writeText(code);
320
- return Promise.resolve(code).then((code) => {
321
- if (code) return navigator.clipboard.writeText(code);
322
- });
323
- });
324
- return /* @__PURE__ */ jsxs("button", {
325
- type: "button",
326
- title: t("Use the {name} type in TypeScript.", { variables: { name } }),
327
- onClick: onCopy,
328
- className: cn(buttonVariants({
329
- variant: "ghost",
330
- size: "sm"
331
- }), "-my-1 shrink-0 gap-1.5 text-fd-muted-foreground [&_svg]:size-3.5"),
332
- children: [isChecked ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Copy, {}), "TypeScript"]
333
- });
334
- }
335
304
  function ResponseSection({ responses, headingLevel }) {
336
305
  const t = useTranslations({ note: "operation page" });
337
306
  const [selected, setSelected] = useState(responses[0].status);
@@ -379,7 +348,7 @@ function ResponseContent({ item: { status, response, content }, onLink }) {
379
348
  anchorSegments: [mediaType],
380
349
  children: /* @__PURE__ */ jsx(MediaContent, {
381
350
  schema: media.schema,
382
- selector: /* @__PURE__ */ jsx(CardSelector, { items })
351
+ selector: /* @__PURE__ */ jsx(SelectTabTrigger, { items })
383
352
  })
384
353
  }, mediaType))]
385
354
  })
@@ -3,25 +3,16 @@ import { useCodeUsage, useExampleRequests, useOperation, useResponseExamples } f
3
3
  import { useOpenAPI, useRenderContext } from "../../utils/create-page.js";
4
4
  import { MethodLabel } from "../components/method-label.js";
5
5
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
6
+ import { ExampleHeader, ExampleSelect, captionCodeBlock, cardCodeBlock, exampleActions, exampleCardClassName, exampleCodeBlock, selectCodeUsage, useCodeUsageId } from "../../packages/shared-api/dist/components/example.js";
6
7
  import { ClientCodeBlock } from "../components/codeblock.js";
7
8
  import { Markdown } from "../components/markdown.js";
8
9
  import { cn } from "../../utils/cn.js";
9
- import { useState, useSyncExternalStore } from "react";
10
+ import { useState } from "react";
10
11
  import { getRaw } from "@scalar/json-magic/magic-proxy";
11
12
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
13
  import { useTranslations } from "@fuma-translate/react";
13
14
  import { Switch } from "@base-ui/react/switch";
14
15
  //#region src/ui/operation/usage-tabs.tsx
15
- /** a code block filling its card */
16
- const cardCodeBlock = {
17
- className: "flex min-h-0 flex-col rounded-none border-0 bg-transparent shadow-none",
18
- viewportProps: { className: "min-h-0" }
19
- };
20
- /** a code block under its caption */
21
- const captionedCodeBlock = {
22
- ...cardCodeBlock,
23
- viewportProps: { className: "min-h-0 pt-2" }
24
- };
25
16
  function UsageTabs() {
26
17
  const ctx = useRenderContext();
27
18
  const t = useTranslations({ note: "operation page" });
@@ -32,7 +23,7 @@ function UsageTabs() {
32
23
  usageTabs: ctx.content?.renderAPIExampleUsageTabs ? ctx.content.renderAPIExampleUsageTabs(codeUsages, ctx) : /* @__PURE__ */ jsx(CodeUsages, {
33
24
  title: t("Example Request"),
34
25
  selectExample: selectable,
35
- className: "mb-4 flex min-h-0 flex-col overflow-hidden rounded-xl border bg-fd-card"
26
+ className: "mb-4"
36
27
  }),
37
28
  responseTabs: /* @__PURE__ */ jsx(ResponseTabs, {})
38
29
  };
@@ -75,55 +66,12 @@ function UsageTabsSelector() {
75
66
  }, item.value)) })]
76
67
  });
77
68
  }
78
- function ExampleHeader({ title, children }) {
79
- return /* @__PURE__ */ jsxs("div", {
80
- className: "flex h-10 shrink-0 items-center gap-2 border-b ps-4 pe-1.5 text-[0.8125rem] font-medium",
81
- children: [title && /* @__PURE__ */ jsx("span", {
82
- className: "me-auto truncate",
83
- children: title
84
- }), children]
85
- });
86
- }
87
- function ExampleSelect({ items, value, onValueChange, align = "end", className }) {
88
- return /* @__PURE__ */ jsxs(Select, {
89
- items,
90
- value,
91
- onValueChange: (v) => v !== null && onValueChange(v),
92
- children: [/* @__PURE__ */ jsx(SelectTrigger, {
93
- className: cn("h-7 w-fit max-w-1/2 shrink-0 gap-1.5 border-0 bg-transparent px-2 py-0 text-[0.8125rem] font-medium text-fd-muted-foreground hover:text-fd-accent-foreground focus:ring-0 focus-visible:ring-2 data-popup-open:bg-fd-accent data-popup-open:text-fd-accent-foreground", className),
94
- children: /* @__PURE__ */ jsx(SelectValue, { className: "min-w-0 truncate" })
95
- }), /* @__PURE__ */ jsx(SelectContent, {
96
- align,
97
- className: "max-w-80",
98
- children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
99
- value: item.value,
100
- description: item.description && /* @__PURE__ */ jsx("div", {
101
- className: "prose prose-xs prose-no-margin font-normal text-fd-muted-foreground",
102
- children: /* @__PURE__ */ jsx(Markdown, { md: item.description })
103
- }),
104
- className: "text-[0.8125rem] font-medium",
105
- children: item.label
106
- }, item.value))
107
- })]
108
- });
109
- }
110
69
  const storageKey = "fumadocs_openapi_requests";
111
- const listeners = /* @__PURE__ */ new Set();
112
- function subscribe(listener) {
113
- listeners.add(listener);
114
- return () => {
115
- listeners.delete(listener);
116
- };
117
- }
118
- function select(id) {
119
- sessionStorage.setItem(storageKey, id);
120
- for (const listener of listeners) listener();
121
- }
122
70
  /** the code usages of the selected example request, with a select of their languages */
123
71
  function CodeUsages({ title, selectExample = false, className, viewportClassName }) {
124
72
  const generators = useOperation().codeUsages.map();
125
73
  const examples = useExampleRequests();
126
- const selected = useSyncExternalStore(subscribe, () => sessionStorage.getItem(storageKey), () => null);
74
+ const selected = useCodeUsageId(storageKey);
127
75
  const id = selected !== null && generators.has(selected) ? selected : generators.keys().next().value;
128
76
  const code = useCodeUsage(id ?? "");
129
77
  if (id === void 0) return null;
@@ -132,36 +80,29 @@ function CodeUsages({ title, selectExample = false, className, viewportClassName
132
80
  label: item.label ?? item.lang
133
81
  }));
134
82
  const example = selectExample && examples.items.length > 1 ? examples.items.find((item) => item.id === examples.selected) : void 0;
135
- return /* @__PURE__ */ jsxs("div", {
136
- className,
137
- children: [/* @__PURE__ */ jsxs(ExampleHeader, {
138
- title: !example && title,
139
- children: [example && /* @__PURE__ */ jsx(ExampleSelect, {
83
+ return /* @__PURE__ */ jsx(ClientCodeBlock, {
84
+ lang: generators.get(id).lang,
85
+ code: code ?? "",
86
+ codeblock: {
87
+ title: example ? /* @__PURE__ */ jsx(ExampleSelect, {
140
88
  items: examples.items.map((item) => ({
141
89
  value: item.id,
142
90
  label: item.name,
143
- description: item.description
91
+ description: item.description && /* @__PURE__ */ jsx(Markdown, { md: item.description })
144
92
  })),
145
93
  value: example.id,
146
94
  onValueChange: examples.select,
147
95
  align: "start",
148
- className: "-ms-2 me-auto max-w-none min-w-0 shrink text-fd-foreground"
149
- }), items.length > 1 ? /* @__PURE__ */ jsx(ExampleSelect, {
96
+ className: "-ms-2 max-w-full text-fd-foreground"
97
+ }) : title,
98
+ Actions: exampleActions(/* @__PURE__ */ jsx(ExampleSelect, {
150
99
  items,
151
100
  value: id,
152
- onValueChange: select
153
- }) : /* @__PURE__ */ jsx("span", {
154
- className: "px-2 text-fd-muted-foreground",
155
- children: items[0].label
156
- })]
157
- }), code && /* @__PURE__ */ jsx(ClientCodeBlock, {
158
- lang: generators.get(id).lang,
159
- code,
160
- codeblock: {
161
- ...cardCodeBlock,
162
- viewportProps: { className: cn(cardCodeBlock.viewportProps.className, viewportClassName) }
163
- }
164
- })]
101
+ onValueChange: (value) => selectCodeUsage(storageKey, value)
102
+ })),
103
+ className: cn(exampleCodeBlock.className, className),
104
+ viewportProps: { className: viewportClassName }
105
+ }
165
106
  });
166
107
  }
167
108
  function ResponseTabs() {
@@ -182,13 +123,17 @@ function ResponseTabsDefaultContent({ tabs }) {
182
123
  const example = examples.at(index);
183
124
  const schema = tab.mediaType ? resolve(tab.response.content?.[tab.mediaType])?.schema : void 0;
184
125
  let body;
185
- if (showSchema && schema !== void 0) body = /* @__PURE__ */ jsx(ClientCodeBlock, {
186
- lang: "json",
187
- code: JSON.stringify(resolve(schema), (_, value) => getRaw(value), 2),
188
- codeblock: cardCodeBlock
189
- });
190
- else if (example) {
126
+ let text;
127
+ if (showSchema && schema !== void 0) {
128
+ text = JSON.stringify(resolve(schema), (_, value) => getRaw(value), 2);
129
+ body = /* @__PURE__ */ jsx(ClientCodeBlock, {
130
+ lang: "json",
131
+ code: text,
132
+ codeblock: cardCodeBlock
133
+ });
134
+ } else if (example) {
191
135
  const captioned = examples.length > 1 || example.description !== void 0;
136
+ text = JSON.stringify(example.sample, null, 2);
192
137
  body = /* @__PURE__ */ jsxs(Fragment$1, { children: [captioned && /* @__PURE__ */ jsxs("div", {
193
138
  className: "shrink-0 px-4 pt-2.5",
194
139
  children: [examples.length > 1 && /* @__PURE__ */ jsx(ExampleSelect, {
@@ -206,19 +151,23 @@ function ResponseTabsDefaultContent({ tabs }) {
206
151
  })]
207
152
  }), /* @__PURE__ */ jsx(ClientCodeBlock, {
208
153
  lang: "json",
209
- code: JSON.stringify(example.sample, null, 2),
210
- codeblock: captioned ? captionedCodeBlock : cardCodeBlock
154
+ code: text,
155
+ codeblock: captioned ? {
156
+ ...cardCodeBlock,
157
+ viewportProps: { className: "min-h-0 pt-2" }
158
+ } : cardCodeBlock
211
159
  })] });
212
160
  } else body = /* @__PURE__ */ jsx("div", {
213
161
  className: "px-4 py-3 text-sm text-fd-muted-foreground",
214
162
  children: t("Empty")
215
163
  });
216
164
  return /* @__PURE__ */ jsxs("div", {
217
- className: "mb-4 flex min-h-0 flex-col overflow-hidden rounded-xl border bg-fd-card",
165
+ className: cn("mb-4", exampleCardClassName),
218
166
  children: [/* @__PURE__ */ jsxs(ExampleHeader, {
219
167
  title: t("Example Response"),
168
+ copy: text,
220
169
  children: [schema !== void 0 && /* @__PURE__ */ jsxs("label", {
221
- className: "flex shrink-0 items-center gap-2 text-fd-muted-foreground",
170
+ className: "me-2 flex shrink-0 items-center gap-2",
222
171
  children: [t("Schema"), /* @__PURE__ */ jsx(Switch.Root, {
223
172
  checked: showSchema,
224
173
  onCheckedChange: setShowSchema,
@@ -267,7 +216,7 @@ function RequestTabsDefaultContent() {
267
216
  path: t("Path Parameters")
268
217
  };
269
218
  return /* @__PURE__ */ jsxs("div", {
270
- className: "flex min-h-0 flex-col overflow-hidden rounded-xl border bg-fd-card",
219
+ className: exampleCardClassName,
271
220
  children: [
272
221
  /* @__PURE__ */ jsx(ExampleHeader, {
273
222
  title: t("Example Requests"),
@@ -300,23 +249,22 @@ function RequestTabsDefaultContent() {
300
249
  Object.entries(displayNames).map(([k, v]) => {
301
250
  const data = requestData[k];
302
251
  if (!data || Object.keys(data).length === 0) return;
303
- return /* @__PURE__ */ jsxs("div", {
304
- className: "flex min-h-0 flex-col border-t",
305
- children: [/* @__PURE__ */ jsxs("div", {
306
- className: "flex shrink-0 px-4 pt-3 text-xs font-medium text-fd-muted-foreground",
307
- children: [v, k === "body" && /* @__PURE__ */ jsx("span", {
308
- className: "ms-auto font-mono font-normal",
252
+ const json = JSON.stringify(data, null, 2);
253
+ return /* @__PURE__ */ jsx(ClientCodeBlock, {
254
+ lang: "json",
255
+ code: json,
256
+ codeblock: {
257
+ ...captionCodeBlock,
258
+ title: v,
259
+ Actions: k === "body" ? exampleActions(/* @__PURE__ */ jsx("span", {
260
+ className: "me-2 font-mono text-xs",
309
261
  children: requestData.bodyMediaType
310
- })]
311
- }), /* @__PURE__ */ jsx(ClientCodeBlock, {
312
- lang: "json",
313
- code: JSON.stringify(data, null, 2),
314
- codeblock: captionedCodeBlock
315
- })]
262
+ })) : void 0
263
+ }
316
264
  }, k);
317
265
  })
318
266
  ]
319
267
  });
320
268
  }
321
269
  //#endregion
322
- export { CodeUsages, ExampleSelect, RequestTabs, UsageTabs };
270
+ export { CodeUsages, RequestTabs, UsageTabs };
@@ -2,35 +2,29 @@
2
2
  import { useExampleRequests, useOperation } from "../../operation.js";
3
3
  import { useOpenAPI } from "../../utils/create-page.js";
4
4
  import { usePlayground } from "../../playground/use-playground.js";
5
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
5
+ import { Markdown } from "../components/markdown.js";
6
6
  import { cn } from "../../utils/cn.js";
7
- import { Segmented, SegmentedList } from "../components/segmented.js";
8
- import { DefaultResultDisplay, iconButtonClassName } from "./components/result-display.js";
9
- import { EndpointBar } from "../components/endpoint.js";
10
- import { DialogPopup } from "../components/dialog.js";
11
7
  import { SchemaProvider } from "../../packages/shared-api/dist/components/playground/schema.js";
8
+ import { RequestExampleSelect, ViewSwitch, iconButtonClassName } from "../../packages/shared-api/dist/components/playground/panels.js";
9
+ import { DefaultResultDisplay } from "./components/result-display.js";
10
+ import { EndpointBar } from "../components/endpoint.js";
11
+ import { DialogPopup, PlaygroundTrigger } from "../../packages/shared-api/dist/components/dialog.js";
12
12
  import { UrlBar } from "./components/url-bar.js";
13
- import { RequestPanel, mutualTLSProvider } from "./components/request-panel.js";
14
- import { oauthPanelProvider } from "./components/oauth-panel.js";
13
+ import { builtinAuthProviders } from "./components/auth.js";
14
+ import { RequestPanel } from "./components/request-panel.js";
15
15
  import { ResponsePanel } from "./components/response-panel.js";
16
16
  import { useMemo, useState } from "react";
17
17
  import { jsx, jsxs } from "react/jsx-runtime";
18
18
  import { StfProvider, useFieldValue } from "@fumari/stf";
19
19
  import { useTranslations } from "@fuma-translate/react";
20
- import { Play, X } from "lucide-react";
21
- import { buttonVariants } from "fumadocs-ui/components/ui/button";
20
+ import { X } from "lucide-react";
22
21
  import { Dialog } from "@base-ui/react/dialog";
23
22
  import { useOnChange } from "fumadocs-core/utils/use-on-change";
24
23
  //#region src/ui/playground/client.tsx
25
24
  function PlaygroundClient({ writeOnly = true, readOnly = false, authProviders, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }) {
26
- const t = useTranslations({ note: "playground" });
27
25
  const { doc } = useOpenAPI();
28
26
  const { path, method, operation } = useOperation();
29
- const providers = useMemo(() => [
30
- ...authProviders ?? [],
31
- oauthPanelProvider,
32
- mutualTLSProvider
33
- ], [authProviders]);
27
+ const providers = useMemo(() => [...authProviders ?? [], ...builtinAuthProviders], [authProviders]);
34
28
  const playground = usePlayground({
35
29
  authProviders: providers,
36
30
  transformAuthInputs,
@@ -46,6 +40,7 @@ function PlaygroundClient({ writeOnly = true, readOnly = false, authProviders, t
46
40
  docRoot: doc.dereferenced,
47
41
  writeOnly,
48
42
  readOnly,
43
+ Markdown,
49
44
  children: /* @__PURE__ */ jsxs(Dialog.Root, {
50
45
  open,
51
46
  onOpenChange: setOpen,
@@ -54,13 +49,7 @@ function PlaygroundClient({ writeOnly = true, readOnly = false, authProviders, t
54
49
  route: path,
55
50
  deprecated: operation.deprecated,
56
51
  ...rest,
57
- children: /* @__PURE__ */ jsxs(Dialog.Trigger, {
58
- className: cn(buttonVariants({
59
- variant: "primary",
60
- size: "sm"
61
- }), "group shrink-0 gap-1.5 rounded-lg px-3 transition-[background-color,scale] active:scale-[0.97] motion-reduce:transition-none"),
62
- children: [/* @__PURE__ */ jsx(Play, { className: "size-3 fill-current transition-transform duration-200 group-hover:translate-x-px motion-reduce:transition-none" }), t("Try in Playground")]
63
- })
52
+ children: /* @__PURE__ */ jsx(PlaygroundTrigger, {})
64
53
  }), /* @__PURE__ */ jsx(DialogPopup, {
65
54
  className: "sm:h-[min(52rem,calc(100dvh-3rem))] sm:w-[min(80rem,calc(100vw-3rem))]",
66
55
  children: /* @__PURE__ */ jsx(PlaygroundDialog, {
@@ -79,6 +68,13 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
79
68
  const { title, method, path, operation, parameters } = useOperation();
80
69
  const { response, isSending, send, clearResponse } = playground;
81
70
  const [view, setView] = useState("request");
71
+ const views = useMemo(() => [{
72
+ value: "request",
73
+ label: t("Request")
74
+ }, {
75
+ value: "response",
76
+ label: t("Response")
77
+ }], [t]);
82
78
  const onSubmit = (e) => {
83
79
  e.preventDefault();
84
80
  send();
@@ -123,20 +119,10 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
123
119
  loading: isSending
124
120
  })
125
121
  }),
126
- /* @__PURE__ */ jsx(Segmented, {
122
+ /* @__PURE__ */ jsx(ViewSwitch, {
127
123
  value: view,
128
124
  onValueChange: setView,
129
- className: "shrink-0 px-3 pb-3 md:hidden",
130
- children: /* @__PURE__ */ jsx(SegmentedList, {
131
- className: "*:flex-1 *:justify-center",
132
- items: [{
133
- value: "request",
134
- label: t("Request")
135
- }, {
136
- value: "response",
137
- label: t("Response")
138
- }]
139
- })
125
+ items: views
140
126
  }),
141
127
  /* @__PURE__ */ jsxs("div", {
142
128
  className: "mx-3 mb-3 grid min-h-0 flex-1 overflow-hidden rounded-xl border bg-fd-card sm:mx-4 sm:mb-4 md:grid-cols-[minmax(0,11fr)_minmax(0,9fr)]",
@@ -159,29 +145,14 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
159
145
  }
160
146
  function ExampleSelect() {
161
147
  const { items, selected, select } = useExampleRequests();
162
- const t = useTranslations({ note: "playground" });
163
- if (items.length <= 1) return null;
164
148
  const options = items.map((item) => ({
165
149
  value: item.id,
166
150
  label: item.name
167
151
  }));
168
- return /* @__PURE__ */ jsxs(Select, {
152
+ return /* @__PURE__ */ jsx(RequestExampleSelect, {
169
153
  items: options,
170
154
  value: selected ?? null,
171
- onValueChange: (v) => v !== null && select(v),
172
- children: [/* @__PURE__ */ jsxs(SelectTrigger, {
173
- 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",
174
- children: [/* @__PURE__ */ jsx("span", {
175
- className: "text-fd-muted-foreground",
176
- children: t("Example")
177
- }), /* @__PURE__ */ jsx(SelectValue, { className: "truncate font-medium" })]
178
- }), /* @__PURE__ */ jsx(SelectContent, {
179
- align: "end",
180
- children: options.map((option) => /* @__PURE__ */ jsx(SelectItem, {
181
- value: option.value,
182
- children: option.label
183
- }, option.value))
184
- })]
155
+ onValueChange: select
185
156
  });
186
157
  }
187
158
  const Custom = { useController(fieldName, options) {
@@ -5,19 +5,19 @@ import { finishOAuthFlow, requestOAuthToken, useAuthRedirect, useOpenIdConnectFl
5
5
  import { useOpenAPI } from "../../../utils/create-page.js";
6
6
  import { Markdown } from "../../components/markdown.js";
7
7
  import { cn } from "../../../utils/cn.js";
8
- import { iconButtonClassName } from "./result-display.js";
9
8
  import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
10
- import { CheckRow, SelectRow, TextRow, ValueRow } from "./fields.js";
9
+ import { CheckRow, SelectRow, TextRow, ValueRow } from "../../../packages/shared-api/dist/components/playground/fields.js";
10
+ import { iconButtonClassName } from "../../../packages/shared-api/dist/components/playground/panels.js";
11
11
  import { Suspense, useEffect, useRef, useState } from "react";
12
12
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
13
  import { StfProvider, useDataEngine, useStf } from "@fumari/stf";
14
14
  import { useTranslations } from "@fuma-translate/react";
15
- import { Check, Copy, ExternalLink } from "lucide-react";
15
+ import { Check, Copy, ExternalLink, ShieldCheck } from "lucide-react";
16
16
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
17
17
  import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
18
- //#region src/ui/playground/components/oauth-panel.tsx
19
- /** OAuth 2.0 and OpenID Connect schemes, authorized in a panel */
20
- const oauthPanelProvider = {
18
+ //#region src/ui/playground/components/auth.tsx
19
+ /** the rows of OAuth and mutual TLS schemes in the built-in UI, after the providers of page */
20
+ const builtinAuthProviders = [{
21
21
  on: ({ scheme }) => scheme.type === "oauth2" || scheme.type === "openIdConnect",
22
22
  render: function OAuthRows({ field, Value, Panel }) {
23
23
  const t = useTranslations({ note: "playground" });
@@ -55,7 +55,19 @@ const oauthPanelProvider = {
55
55
  })
56
56
  ] });
57
57
  }
58
- };
58
+ }, {
59
+ on: ({ scheme }) => scheme.type === "mutualTLS",
60
+ render: function MutualTLSNote({ field }) {
61
+ const t = useTranslations({ note: "playground" });
62
+ return /* @__PURE__ */ jsxs("div", {
63
+ className: "flex gap-2 border-b px-4 py-2.5 text-xs text-fd-muted-foreground last:border-b-0",
64
+ children: [/* @__PURE__ */ jsx(ShieldCheck, { className: "mt-px size-3.5 shrink-0" }), /* @__PURE__ */ jsxs("div", {
65
+ className: "min-w-0 flex-1 [&_a]:underline",
66
+ children: [/* @__PURE__ */ jsx("p", { children: t("Requires a client certificate installed in your browser.") }), field.scheme.description && /* @__PURE__ */ jsx(Markdown, { md: field.scheme.description })]
67
+ })]
68
+ });
69
+ }
70
+ }];
59
71
  /** obtain the access token of an OAuth 2.0 or OpenID Connect scheme */
60
72
  function OAuthPanel({ field, close }) {
61
73
  const t = useTranslations({ note: "OAuth dialog" });
@@ -340,4 +352,4 @@ function DeviceVerification({ code, onCancel }) {
340
352
  })] });
341
353
  }
342
354
  //#endregion
343
- export { oauthPanelProvider };
355
+ export { builtinAuthProviders };