fumadocs-openapi 12.5.2 → 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 (45) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/dist/.translations/index.d.ts +0 -32
  3. package/dist/.translations/keys.js +0 -32
  4. package/dist/generate-file.js +15 -17
  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 +34 -4
  10. package/dist/packages/shared-api/dist/.translations/keys.js +34 -4
  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/dialog.js +15 -1
  15. package/dist/packages/shared-api/dist/components/example.js +90 -16
  16. package/dist/packages/shared-api/dist/components/playground/fields.js +3 -3
  17. package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
  18. package/dist/packages/shared-api/dist/components/playground/panels.js +88 -5
  19. package/dist/packages/shared-api/dist/components/playground/result.js +187 -0
  20. package/dist/packages/shared-api/dist/components/schema/client.js +22 -0
  21. package/dist/packages/shared-api/dist/components/select-tab.js +8 -3
  22. package/dist/packages/shared-api/dist/source.d.ts +11 -0
  23. package/dist/packages/shared-api/dist/source.js +50 -0
  24. package/dist/requests/generators/curl.js +6 -9
  25. package/dist/requests/generators/go.js +5 -5
  26. package/dist/requests/generators/rust.js +3 -2
  27. package/dist/requests/media/adapter.js +16 -7
  28. package/dist/requests/media/resolve-adapter.js +15 -12
  29. package/dist/requests/string-utils.js +4 -32
  30. package/dist/server/index.d.ts +2 -7
  31. package/dist/server/index.js +26 -64
  32. package/dist/ui/base.js +2 -2
  33. package/dist/ui/operation/index.js +5 -36
  34. package/dist/ui/operation/usage-tabs.js +45 -56
  35. package/dist/ui/playground/client.js +18 -50
  36. package/dist/ui/playground/components/{oauth-panel.js → auth.js} +19 -7
  37. package/dist/ui/playground/components/request-panel.js +3 -65
  38. package/dist/ui/playground/components/response-panel.js +7 -18
  39. package/dist/ui/playground/components/result-display.js +45 -166
  40. package/dist/ui/playground/components/url-bar.js +2 -19
  41. package/dist/utils/create-page.d.ts +0 -4
  42. package/dist/utils/create-page.js +3 -5
  43. package/dist/utils/pages/preset-auto.js +139 -148
  44. package/package.json +5 -5
  45. 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,6 +10,7 @@ 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 { CopyTypeScript } from "../../packages/shared-api/dist/components/copy-typescript.js";
13
14
  import { Segmented, SegmentedList, SegmentedPanel } from "../../packages/shared-api/dist/components/segmented.js";
14
15
  import { EndpointBar } from "../components/endpoint.js";
15
16
  import { DialogPopup } from "../../packages/shared-api/dist/components/dialog.js";
@@ -17,9 +18,8 @@ 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,11 +3,11 @@ 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, captionedCodeBlock, cardCodeBlock, exampleCardClassName } from "../../packages/shared-api/dist/components/example.js";
6
+ import { ExampleHeader, ExampleSelect, captionCodeBlock, cardCodeBlock, exampleActions, exampleCardClassName, exampleCodeBlock, selectCodeUsage, useCodeUsageId } from "../../packages/shared-api/dist/components/example.js";
7
7
  import { ClientCodeBlock } from "../components/codeblock.js";
8
8
  import { Markdown } from "../components/markdown.js";
9
9
  import { cn } from "../../utils/cn.js";
10
- import { useState, useSyncExternalStore } from "react";
10
+ import { useState } from "react";
11
11
  import { getRaw } from "@scalar/json-magic/magic-proxy";
12
12
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
13
  import { useTranslations } from "@fuma-translate/react";
@@ -23,7 +23,7 @@ function UsageTabs() {
23
23
  usageTabs: ctx.content?.renderAPIExampleUsageTabs ? ctx.content.renderAPIExampleUsageTabs(codeUsages, ctx) : /* @__PURE__ */ jsx(CodeUsages, {
24
24
  title: t("Example Request"),
25
25
  selectExample: selectable,
26
- className: cn("mb-4", exampleCardClassName)
26
+ className: "mb-4"
27
27
  }),
28
28
  responseTabs: /* @__PURE__ */ jsx(ResponseTabs, {})
29
29
  };
@@ -67,22 +67,11 @@ function UsageTabsSelector() {
67
67
  });
68
68
  }
69
69
  const storageKey = "fumadocs_openapi_requests";
70
- const listeners = /* @__PURE__ */ new Set();
71
- function subscribe(listener) {
72
- listeners.add(listener);
73
- return () => {
74
- listeners.delete(listener);
75
- };
76
- }
77
- function select(id) {
78
- sessionStorage.setItem(storageKey, id);
79
- for (const listener of listeners) listener();
80
- }
81
70
  /** the code usages of the selected example request, with a select of their languages */
82
71
  function CodeUsages({ title, selectExample = false, className, viewportClassName }) {
83
72
  const generators = useOperation().codeUsages.map();
84
73
  const examples = useExampleRequests();
85
- const selected = useSyncExternalStore(subscribe, () => sessionStorage.getItem(storageKey), () => null);
74
+ const selected = useCodeUsageId(storageKey);
86
75
  const id = selected !== null && generators.has(selected) ? selected : generators.keys().next().value;
87
76
  const code = useCodeUsage(id ?? "");
88
77
  if (id === void 0) return null;
@@ -91,11 +80,11 @@ function CodeUsages({ title, selectExample = false, className, viewportClassName
91
80
  label: item.label ?? item.lang
92
81
  }));
93
82
  const example = selectExample && examples.items.length > 1 ? examples.items.find((item) => item.id === examples.selected) : void 0;
94
- return /* @__PURE__ */ jsxs("div", {
95
- className,
96
- children: [/* @__PURE__ */ jsxs(ExampleHeader, {
97
- title: !example && title,
98
- 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, {
99
88
  items: examples.items.map((item) => ({
100
89
  value: item.id,
101
90
  label: item.name,
@@ -104,23 +93,16 @@ function CodeUsages({ title, selectExample = false, className, viewportClassName
104
93
  value: example.id,
105
94
  onValueChange: examples.select,
106
95
  align: "start",
107
- className: "-ms-2 me-auto max-w-none min-w-0 shrink text-fd-foreground"
108
- }), items.length > 1 ? /* @__PURE__ */ jsx(ExampleSelect, {
96
+ className: "-ms-2 max-w-full text-fd-foreground"
97
+ }) : title,
98
+ Actions: exampleActions(/* @__PURE__ */ jsx(ExampleSelect, {
109
99
  items,
110
100
  value: id,
111
- onValueChange: select
112
- }) : /* @__PURE__ */ jsx("span", {
113
- className: "px-2 text-fd-muted-foreground",
114
- children: items[0].label
115
- })]
116
- }), code && /* @__PURE__ */ jsx(ClientCodeBlock, {
117
- lang: generators.get(id).lang,
118
- code,
119
- codeblock: {
120
- ...cardCodeBlock,
121
- viewportProps: { className: cn(cardCodeBlock.viewportProps.className, viewportClassName) }
122
- }
123
- })]
101
+ onValueChange: (value) => selectCodeUsage(storageKey, value)
102
+ })),
103
+ className: cn(exampleCodeBlock.className, className),
104
+ viewportProps: { className: viewportClassName }
105
+ }
124
106
  });
125
107
  }
126
108
  function ResponseTabs() {
@@ -141,13 +123,17 @@ function ResponseTabsDefaultContent({ tabs }) {
141
123
  const example = examples.at(index);
142
124
  const schema = tab.mediaType ? resolve(tab.response.content?.[tab.mediaType])?.schema : void 0;
143
125
  let body;
144
- if (showSchema && schema !== void 0) body = /* @__PURE__ */ jsx(ClientCodeBlock, {
145
- lang: "json",
146
- code: JSON.stringify(resolve(schema), (_, value) => getRaw(value), 2),
147
- codeblock: cardCodeBlock
148
- });
149
- 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) {
150
135
  const captioned = examples.length > 1 || example.description !== void 0;
136
+ text = JSON.stringify(example.sample, null, 2);
151
137
  body = /* @__PURE__ */ jsxs(Fragment$1, { children: [captioned && /* @__PURE__ */ jsxs("div", {
152
138
  className: "shrink-0 px-4 pt-2.5",
153
139
  children: [examples.length > 1 && /* @__PURE__ */ jsx(ExampleSelect, {
@@ -165,8 +151,11 @@ function ResponseTabsDefaultContent({ tabs }) {
165
151
  })]
166
152
  }), /* @__PURE__ */ jsx(ClientCodeBlock, {
167
153
  lang: "json",
168
- code: JSON.stringify(example.sample, null, 2),
169
- codeblock: captioned ? captionedCodeBlock : cardCodeBlock
154
+ code: text,
155
+ codeblock: captioned ? {
156
+ ...cardCodeBlock,
157
+ viewportProps: { className: "min-h-0 pt-2" }
158
+ } : cardCodeBlock
170
159
  })] });
171
160
  } else body = /* @__PURE__ */ jsx("div", {
172
161
  className: "px-4 py-3 text-sm text-fd-muted-foreground",
@@ -176,8 +165,9 @@ function ResponseTabsDefaultContent({ tabs }) {
176
165
  className: cn("mb-4", exampleCardClassName),
177
166
  children: [/* @__PURE__ */ jsxs(ExampleHeader, {
178
167
  title: t("Example Response"),
168
+ copy: text,
179
169
  children: [schema !== void 0 && /* @__PURE__ */ jsxs("label", {
180
- className: "flex shrink-0 items-center gap-2 text-fd-muted-foreground",
170
+ className: "me-2 flex shrink-0 items-center gap-2",
181
171
  children: [t("Schema"), /* @__PURE__ */ jsx(Switch.Root, {
182
172
  checked: showSchema,
183
173
  onCheckedChange: setShowSchema,
@@ -259,19 +249,18 @@ function RequestTabsDefaultContent() {
259
249
  Object.entries(displayNames).map(([k, v]) => {
260
250
  const data = requestData[k];
261
251
  if (!data || Object.keys(data).length === 0) return;
262
- return /* @__PURE__ */ jsxs("div", {
263
- className: "flex min-h-0 flex-col border-t",
264
- children: [/* @__PURE__ */ jsxs("div", {
265
- className: "flex shrink-0 px-4 pt-3 text-xs font-medium text-fd-muted-foreground",
266
- children: [v, k === "body" && /* @__PURE__ */ jsx("span", {
267
- 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",
268
261
  children: requestData.bodyMediaType
269
- })]
270
- }), /* @__PURE__ */ jsx(ClientCodeBlock, {
271
- lang: "json",
272
- code: JSON.stringify(data, null, 2),
273
- codeblock: captionedCodeBlock
274
- })]
262
+ })) : void 0
263
+ }
275
264
  }, k);
276
265
  })
277
266
  ]
@@ -2,37 +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";
6
5
  import { Markdown } from "../components/markdown.js";
7
6
  import { cn } from "../../utils/cn.js";
8
- import { Segmented, SegmentedList } from "../../packages/shared-api/dist/components/segmented.js";
9
7
  import { SchemaProvider } from "../../packages/shared-api/dist/components/playground/schema.js";
10
- import { iconButtonClassName } from "../../packages/shared-api/dist/components/playground/panels.js";
8
+ import { RequestExampleSelect, ViewSwitch, iconButtonClassName } from "../../packages/shared-api/dist/components/playground/panels.js";
11
9
  import { DefaultResultDisplay } from "./components/result-display.js";
12
10
  import { EndpointBar } from "../components/endpoint.js";
13
- import { DialogPopup } from "../../packages/shared-api/dist/components/dialog.js";
11
+ import { DialogPopup, PlaygroundTrigger } from "../../packages/shared-api/dist/components/dialog.js";
14
12
  import { UrlBar } from "./components/url-bar.js";
15
- import { RequestPanel, mutualTLSProvider } from "./components/request-panel.js";
16
- import { oauthPanelProvider } from "./components/oauth-panel.js";
13
+ import { builtinAuthProviders } from "./components/auth.js";
14
+ import { RequestPanel } from "./components/request-panel.js";
17
15
  import { ResponsePanel } from "./components/response-panel.js";
18
16
  import { useMemo, useState } from "react";
19
17
  import { jsx, jsxs } from "react/jsx-runtime";
20
18
  import { StfProvider, useFieldValue } from "@fumari/stf";
21
19
  import { useTranslations } from "@fuma-translate/react";
22
- import { Play, X } from "lucide-react";
23
- import { buttonVariants } from "fumadocs-ui/components/ui/button";
20
+ import { X } from "lucide-react";
24
21
  import { Dialog } from "@base-ui/react/dialog";
25
22
  import { useOnChange } from "fumadocs-core/utils/use-on-change";
26
23
  //#region src/ui/playground/client.tsx
27
24
  function PlaygroundClient({ writeOnly = true, readOnly = false, authProviders, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }) {
28
- const t = useTranslations({ note: "playground" });
29
25
  const { doc } = useOpenAPI();
30
26
  const { path, method, operation } = useOperation();
31
- const providers = useMemo(() => [
32
- ...authProviders ?? [],
33
- oauthPanelProvider,
34
- mutualTLSProvider
35
- ], [authProviders]);
27
+ const providers = useMemo(() => [...authProviders ?? [], ...builtinAuthProviders], [authProviders]);
36
28
  const playground = usePlayground({
37
29
  authProviders: providers,
38
30
  transformAuthInputs,
@@ -57,13 +49,7 @@ function PlaygroundClient({ writeOnly = true, readOnly = false, authProviders, t
57
49
  route: path,
58
50
  deprecated: operation.deprecated,
59
51
  ...rest,
60
- children: /* @__PURE__ */ jsxs(Dialog.Trigger, {
61
- className: cn(buttonVariants({
62
- variant: "primary",
63
- size: "sm"
64
- }), "group shrink-0 gap-1.5 rounded-lg px-3 transition-[background-color,scale] active:scale-[0.97] motion-reduce:transition-none"),
65
- 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")]
66
- })
52
+ children: /* @__PURE__ */ jsx(PlaygroundTrigger, {})
67
53
  }), /* @__PURE__ */ jsx(DialogPopup, {
68
54
  className: "sm:h-[min(52rem,calc(100dvh-3rem))] sm:w-[min(80rem,calc(100vw-3rem))]",
69
55
  children: /* @__PURE__ */ jsx(PlaygroundDialog, {
@@ -82,6 +68,13 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
82
68
  const { title, method, path, operation, parameters } = useOperation();
83
69
  const { response, isSending, send, clearResponse } = playground;
84
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]);
85
78
  const onSubmit = (e) => {
86
79
  e.preventDefault();
87
80
  send();
@@ -126,20 +119,10 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
126
119
  loading: isSending
127
120
  })
128
121
  }),
129
- /* @__PURE__ */ jsx(Segmented, {
122
+ /* @__PURE__ */ jsx(ViewSwitch, {
130
123
  value: view,
131
124
  onValueChange: setView,
132
- className: "shrink-0 px-3 pb-3 md:hidden",
133
- children: /* @__PURE__ */ jsx(SegmentedList, {
134
- className: "*:flex-1 *:justify-center",
135
- items: [{
136
- value: "request",
137
- label: t("Request")
138
- }, {
139
- value: "response",
140
- label: t("Response")
141
- }]
142
- })
125
+ items: views
143
126
  }),
144
127
  /* @__PURE__ */ jsxs("div", {
145
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)]",
@@ -162,29 +145,14 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
162
145
  }
163
146
  function ExampleSelect() {
164
147
  const { items, selected, select } = useExampleRequests();
165
- const t = useTranslations({ note: "playground" });
166
- if (items.length <= 1) return null;
167
148
  const options = items.map((item) => ({
168
149
  value: item.id,
169
150
  label: item.name
170
151
  }));
171
- return /* @__PURE__ */ jsxs(Select, {
152
+ return /* @__PURE__ */ jsx(RequestExampleSelect, {
172
153
  items: options,
173
154
  value: selected ?? null,
174
- onValueChange: (v) => v !== null && select(v),
175
- children: [/* @__PURE__ */ jsxs(SelectTrigger, {
176
- 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",
177
- children: [/* @__PURE__ */ jsx("span", {
178
- className: "text-fd-muted-foreground",
179
- children: t("Example")
180
- }), /* @__PURE__ */ jsx(SelectValue, { className: "truncate font-medium" })]
181
- }), /* @__PURE__ */ jsx(SelectContent, {
182
- align: "end",
183
- children: options.map((option) => /* @__PURE__ */ jsx(SelectItem, {
184
- value: option.value,
185
- children: option.label
186
- }, option.value))
187
- })]
155
+ onValueChange: select
188
156
  });
189
157
  }
190
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 { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
8
9
  import { CheckRow, SelectRow, TextRow, ValueRow } from "../../../packages/shared-api/dist/components/playground/fields.js";
9
10
  import { iconButtonClassName } from "../../../packages/shared-api/dist/components/playground/panels.js";
10
- import { Spinner } from "../../../packages/shared-api/dist/components/spinner.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 };