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.
- package/css/generated/shared.css +1 -1
- package/dist/.translations/index.d.ts +0 -32
- package/dist/.translations/keys.js +0 -32
- package/dist/generate-file.js +15 -17
- package/dist/index.browser.d.ts +8 -3
- package/dist/index.browser.js +11 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/packages/shared-api/dist/.translations/index.d.ts +34 -4
- package/dist/packages/shared-api/dist/.translations/keys.js +34 -4
- package/dist/packages/shared-api/dist/codegen.d.ts +21 -1
- package/dist/packages/shared-api/dist/codegen.js +63 -1
- package/dist/packages/shared-api/dist/components/copy-typescript.js +31 -0
- package/dist/packages/shared-api/dist/components/dialog.js +15 -1
- package/dist/packages/shared-api/dist/components/example.js +90 -16
- package/dist/packages/shared-api/dist/components/playground/fields.js +3 -3
- package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/panels.js +88 -5
- package/dist/packages/shared-api/dist/components/playground/result.js +187 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +22 -0
- package/dist/packages/shared-api/dist/components/select-tab.js +8 -3
- package/dist/packages/shared-api/dist/source.d.ts +11 -0
- package/dist/packages/shared-api/dist/source.js +50 -0
- package/dist/requests/generators/curl.js +6 -9
- package/dist/requests/generators/go.js +5 -5
- package/dist/requests/generators/rust.js +3 -2
- package/dist/requests/media/adapter.js +16 -7
- package/dist/requests/media/resolve-adapter.js +15 -12
- package/dist/requests/string-utils.js +4 -32
- package/dist/server/index.d.ts +2 -7
- package/dist/server/index.js +26 -64
- package/dist/ui/base.js +2 -2
- package/dist/ui/operation/index.js +5 -36
- package/dist/ui/operation/usage-tabs.js +45 -56
- package/dist/ui/playground/client.js +18 -50
- package/dist/ui/playground/components/{oauth-panel.js → auth.js} +19 -7
- package/dist/ui/playground/components/request-panel.js +3 -65
- package/dist/ui/playground/components/response-panel.js +7 -18
- package/dist/ui/playground/components/result-display.js +45 -166
- package/dist/ui/playground/components/url-bar.js +2 -19
- package/dist/utils/create-page.d.ts +0 -4
- package/dist/utils/create-page.js +3 -5
- package/dist/utils/pages/preset-auto.js +139 -148
- package/package.json +5 -5
- package/dist/ui/playground/status-info.js +0 -39
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare namespace codegen_d_exports {
|
|
2
|
-
export { CodeUsageGenerator, CodeUsageGeneratorRegistry, InlineCodeUsageGenerator, createCodeUsageGeneratorRegistry };
|
|
2
|
+
export { CodeUsageGenerator, CodeUsageGeneratorRegistry, InlineCodeUsageGenerator, createCodeUsageGeneratorRegistry, csharpRawString, goString, javaTextBlock, jsTemplateLiteral, pythonString, rustEscapedString, rustString, shellQuote };
|
|
3
3
|
}
|
|
4
4
|
//#region src/codegen.d.ts
|
|
5
5
|
export interface CodeUsageGeneratorRegistry<Data = unknown, Context = unknown> {
|
|
@@ -37,6 +37,26 @@ export interface InlineCodeUsageGenerator<Data = unknown, Context = unknown> {
|
|
|
37
37
|
}
|
|
38
38
|
export declare function createCodeUsageGeneratorRegistry<Data, Context>(inherit?: CodeUsageGeneratorRegistry<Data, Context>): CodeUsageGeneratorRegistry<Data, Context>;
|
|
39
39
|
type CodeUsageGeneratorFn<Data, Context> = (data: Data, context: Context) => string;
|
|
40
|
+
/** a Python triple-quoted string */
|
|
41
|
+
export declare function pythonString(str: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* A Java text block, escapes keep the white space Java strips from each line.
|
|
44
|
+
*
|
|
45
|
+
* A final line break puts the closing delimiter on its own line.
|
|
46
|
+
*/
|
|
47
|
+
export declare function javaTextBlock(str: string): string;
|
|
48
|
+
/** a JavaScript template literal */
|
|
49
|
+
export declare function jsTemplateLiteral(str: string): string;
|
|
50
|
+
/** a Go raw string, the characters it can't hold are concatenated as interpreted strings */
|
|
51
|
+
export declare function goString(str: string): string;
|
|
52
|
+
/** a Rust string with escapes, rustc rejects text direction controls in literals */
|
|
53
|
+
export declare function rustEscapedString(str: string): string;
|
|
54
|
+
/** a Rust raw string with enough `#` to hold `"#`, escaped for the CRs and text direction controls it can't hold */
|
|
55
|
+
export declare function rustString(str: string): string;
|
|
56
|
+
/** a C# raw string literal, the delimiter is longer than every run of quotes inside */
|
|
57
|
+
export declare function csharpRawString(str: string): string;
|
|
58
|
+
/** single quotes keep the string literal, each `'` closes them to add an escaped quote */
|
|
59
|
+
export declare function shellQuote(str: string): string;
|
|
40
60
|
//#endregion
|
|
41
61
|
//#endregion
|
|
42
62
|
export { codegen_d_exports };
|
|
@@ -29,5 +29,67 @@ function createCodeUsageGeneratorRegistry(inherit) {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
/** escapes a character with a backslash, CR and NUL as escape sequences */
|
|
33
|
+
function backslash(c) {
|
|
34
|
+
return c === "\r" ? "\\r" : c === "\0" ? "\\000" : `\\${c}`;
|
|
35
|
+
}
|
|
36
|
+
/** content of a Python triple-quoted string or Java text block, quotes are escaped where they'd close it */
|
|
37
|
+
function escapeTripleQuotes(str) {
|
|
38
|
+
return str.replace(/[\\\r\0]|"(?=""|$)/g, backslash);
|
|
39
|
+
}
|
|
40
|
+
/** a Python triple-quoted string */
|
|
41
|
+
function pythonString(str) {
|
|
42
|
+
return `"""${escapeTripleQuotes(str)}"""`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A Java text block, escapes keep the white space Java strips from each line.
|
|
46
|
+
*
|
|
47
|
+
* A final line break puts the closing delimiter on its own line.
|
|
48
|
+
*/
|
|
49
|
+
function javaTextBlock(str) {
|
|
50
|
+
const content = escapeTripleQuotes(str).replace(/(?:[^\S\n]|[\x1c-\x1f])(?=\n)/g, (c) => c === " " ? "\\s" : `${c}\\n\\`);
|
|
51
|
+
return !str.endsWith("\n") && /^[\s\x1c-\x1f]|[\s\x1c-\x1f]$/.test(str) ? `"""\n${content}\\\n"""` : `"""\n${content}"""`;
|
|
52
|
+
}
|
|
53
|
+
/** a JavaScript template literal */
|
|
54
|
+
function jsTemplateLiteral(str) {
|
|
55
|
+
return `\`${str.replace(/[\\`\r]|\$\{/g, backslash)}\``;
|
|
56
|
+
}
|
|
57
|
+
const goEscapes = {
|
|
58
|
+
"`": "\"`\"",
|
|
59
|
+
"\r": "\"\\r\"",
|
|
60
|
+
"\0": "\"\\x00\"",
|
|
61
|
+
"": "\"\\uFEFF\""
|
|
62
|
+
};
|
|
63
|
+
/** a Go raw string, the characters it can't hold are concatenated as interpreted strings */
|
|
64
|
+
function goString(str) {
|
|
65
|
+
return `\`${str.replace(/[`\r\0\uFEFF]/g, (c) => `\` + ${goEscapes[c]} + \``)}\``;
|
|
66
|
+
}
|
|
67
|
+
const rustEscapes = {
|
|
68
|
+
"\\": "\\\\",
|
|
69
|
+
"\"": "\\\"",
|
|
70
|
+
"\r": "\\r",
|
|
71
|
+
" ": "\\t"
|
|
72
|
+
};
|
|
73
|
+
/** a Rust string with escapes, rustc rejects text direction controls in literals */
|
|
74
|
+
function rustEscapedString(str) {
|
|
75
|
+
return `"${str.replace(/[\\"\r\t\u202a-\u202e\u2066-\u2069]/g, (c) => rustEscapes[c] ?? `\\u{${c.charCodeAt(0).toString(16)}}`)}"`;
|
|
76
|
+
}
|
|
77
|
+
/** a Rust raw string with enough `#` to hold `"#`, escaped for the CRs and text direction controls it can't hold */
|
|
78
|
+
function rustString(str) {
|
|
79
|
+
if (/[\r\u202a-\u202e\u2066-\u2069]/.test(str)) return rustEscapedString(str);
|
|
80
|
+
let hashes = "#";
|
|
81
|
+
while (str.includes(`"${hashes}`)) hashes += "#";
|
|
82
|
+
return `r${hashes}"${str}"${hashes}`;
|
|
83
|
+
}
|
|
84
|
+
/** a C# raw string literal, the delimiter is longer than every run of quotes inside */
|
|
85
|
+
function csharpRawString(str) {
|
|
86
|
+
let quotes = "\"\"\"";
|
|
87
|
+
while (str.includes(quotes)) quotes += "\"";
|
|
88
|
+
return `${quotes}\n${str}\n${quotes}`;
|
|
89
|
+
}
|
|
90
|
+
/** single quotes keep the string literal, each `'` closes them to add an escaped quote */
|
|
91
|
+
function shellQuote(str) {
|
|
92
|
+
return `'${str.replaceAll("'", `'\\''`)}'`;
|
|
93
|
+
}
|
|
32
94
|
//#endregion
|
|
33
|
-
export { createCodeUsageGeneratorRegistry };
|
|
95
|
+
export { createCodeUsageGeneratorRegistry, csharpRawString, goString, javaTextBlock, jsTemplateLiteral, pythonString, rustEscapedString, rustString, shellQuote };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../utils/cn.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
5
|
+
import { Check, Copy } from "lucide-react";
|
|
6
|
+
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
7
|
+
import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
|
|
8
|
+
//#region ../shared-api/dist/components/copy-typescript.js
|
|
9
|
+
/** copies the TypeScript definitions of a schema, generated on click */
|
|
10
|
+
function CopyTypeScript({ name, generate }) {
|
|
11
|
+
const t = useTranslations({ note: "TypeScript definitions" });
|
|
12
|
+
const [isChecked, onCopy] = useCopyButton(() => {
|
|
13
|
+
const code = generate();
|
|
14
|
+
if (typeof code === "string") return navigator.clipboard.writeText(code);
|
|
15
|
+
return Promise.resolve(code).then((code) => {
|
|
16
|
+
if (code) return navigator.clipboard.writeText(code);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
20
|
+
type: "button",
|
|
21
|
+
title: t("Use the {name} type in TypeScript.", { variables: { name } }),
|
|
22
|
+
onClick: onCopy,
|
|
23
|
+
className: cn(buttonVariants({
|
|
24
|
+
variant: "ghost",
|
|
25
|
+
size: "sm"
|
|
26
|
+
}), "-my-1 shrink-0 gap-1.5 text-fd-muted-foreground [&_svg]:size-3.5"),
|
|
27
|
+
children: [isChecked ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Copy, {}), "TypeScript"]
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { CopyTypeScript };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../utils/cn.js";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
5
|
+
import { Play } from "lucide-react";
|
|
6
|
+
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
4
7
|
import { Dialog } from "@base-ui/react/dialog";
|
|
5
8
|
//#region ../shared-api/dist/components/dialog.js
|
|
6
9
|
/** the popup of a dialog, a window on larger screens and the full screen on smaller ones */
|
|
@@ -10,5 +13,16 @@ function DialogPopup({ className, children }) {
|
|
|
10
13
|
children
|
|
11
14
|
})] });
|
|
12
15
|
}
|
|
16
|
+
/** opens the playground dialog, `children` replace its icon, like the status of a connection */
|
|
17
|
+
function PlaygroundTrigger({ children }) {
|
|
18
|
+
const t = useTranslations({ note: "playground" });
|
|
19
|
+
return /* @__PURE__ */ jsxs(Dialog.Trigger, {
|
|
20
|
+
className: cn(buttonVariants({
|
|
21
|
+
variant: "primary",
|
|
22
|
+
size: "sm"
|
|
23
|
+
}), "group shrink-0 gap-1.5 rounded-[5px] px-3 transition-[background-color,scale] active:scale-[0.97] motion-reduce:transition-none"),
|
|
24
|
+
children: [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")]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
13
27
|
//#endregion
|
|
14
|
-
export { DialogPopup };
|
|
28
|
+
export { DialogPopup, PlaygroundTrigger };
|
|
@@ -1,36 +1,110 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../utils/cn.js";
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
7
|
+
import { Check, Clipboard } from "lucide-react";
|
|
8
|
+
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
9
|
+
import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
|
|
5
10
|
//#region ../shared-api/dist/components/example.js
|
|
6
|
-
|
|
11
|
+
const selectedCodeUsages = /* @__PURE__ */ new Map();
|
|
12
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
13
|
+
function subscribe(listener) {
|
|
14
|
+
listeners.add(listener);
|
|
15
|
+
return () => {
|
|
16
|
+
listeners.delete(listener);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** kept in memory, also when the storage is blocked */
|
|
20
|
+
function getCodeUsageId(key) {
|
|
21
|
+
let id = selectedCodeUsages.get(key);
|
|
22
|
+
if (id === void 0) {
|
|
23
|
+
try {
|
|
24
|
+
id = sessionStorage.getItem(key);
|
|
25
|
+
} catch {
|
|
26
|
+
id = null;
|
|
27
|
+
}
|
|
28
|
+
selectedCodeUsages.set(key, id);
|
|
29
|
+
}
|
|
30
|
+
return id;
|
|
31
|
+
}
|
|
32
|
+
/** the id of the code sample language selected in the session, stored under `key`, `null` until one is selected */
|
|
33
|
+
function useCodeUsageId(key) {
|
|
34
|
+
return useSyncExternalStore(subscribe, () => getCodeUsageId(key), () => null);
|
|
35
|
+
}
|
|
36
|
+
function selectCodeUsage(key, id) {
|
|
37
|
+
selectedCodeUsages.set(key, id);
|
|
38
|
+
try {
|
|
39
|
+
sessionStorage.setItem(key, id);
|
|
40
|
+
} catch {}
|
|
41
|
+
for (const listener of listeners) listener();
|
|
42
|
+
}
|
|
43
|
+
/** styles the title bar of a code block like `<ExampleHeader />` */
|
|
44
|
+
const titleBarClassName = "[&>div:has(>figcaption)]:h-10 [&_figcaption]:text-[0.8125rem] [&_figcaption]:font-medium [&_figcaption]:text-fd-foreground";
|
|
45
|
+
/** an example card, a code block with its controls in its title bar, it shrinks with its column */
|
|
46
|
+
const exampleCodeBlock = { className: `grid min-h-0 grid-rows-[auto_minmax(0,1fr)] [&_figcaption]:overflow-visible ${titleBarClassName}` };
|
|
47
|
+
/** a code block under another one in its example card, its title is a caption */
|
|
48
|
+
const captionCodeBlock = { className: "grid min-h-0 grid-rows-[auto_minmax(0,1fr)] rounded-none border-x-0 border-b-0 [&_figcaption]:text-xs [&_figcaption]:font-medium" };
|
|
49
|
+
/** the actions of a code block's title bar, `controls` before its copy button */
|
|
50
|
+
function exampleActions(controls) {
|
|
51
|
+
return ({ className, children }) => /* @__PURE__ */ jsxs("div", {
|
|
52
|
+
className: cn("flex items-center", className),
|
|
53
|
+
children: [controls, children]
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** a code block filling its example card, under an `<ExampleHeader />` with its copy button */
|
|
7
57
|
const cardCodeBlock = {
|
|
8
58
|
className: "flex min-h-0 flex-col rounded-none border-0 bg-transparent shadow-none",
|
|
9
|
-
viewportProps: { className: "min-h-0" }
|
|
10
|
-
|
|
11
|
-
/** a code block under its caption */
|
|
12
|
-
const captionedCodeBlock = {
|
|
13
|
-
...cardCodeBlock,
|
|
14
|
-
viewportProps: { className: "min-h-0 pt-2" }
|
|
59
|
+
viewportProps: { className: "min-h-0" },
|
|
60
|
+
allowCopy: false
|
|
15
61
|
};
|
|
16
62
|
const exampleCardClassName = "flex min-h-0 flex-col overflow-hidden rounded-xl border bg-fd-card";
|
|
17
|
-
/** the
|
|
18
|
-
function
|
|
63
|
+
/** copies the code below, like the copy button of code blocks */
|
|
64
|
+
function ExampleCopy({ text }) {
|
|
65
|
+
const t = useTranslations({ note: "code block" });
|
|
66
|
+
const [checked, onCopy] = useCopyButton(() => navigator.clipboard.writeText(text));
|
|
67
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
68
|
+
type: "button",
|
|
69
|
+
"aria-live": "polite",
|
|
70
|
+
"data-checked": checked || void 0,
|
|
71
|
+
onClick: onCopy,
|
|
72
|
+
className: cn(buttonVariants({ size: "icon-xs" }), "hover:text-fd-accent-foreground data-checked:text-fd-accent-foreground"),
|
|
73
|
+
children: [checked ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Clipboard, {}), /* @__PURE__ */ jsx("span", {
|
|
74
|
+
className: "sr-only",
|
|
75
|
+
children: checked ? t("Copied Text", { note: "aria-label" }) : t("Copy Text", { note: "aria-label" })
|
|
76
|
+
})]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** for example cards with more under their header row than a code block's title bar holds, it looks like one */
|
|
80
|
+
function ExampleHeader({ title, description, copy, className, children }) {
|
|
19
81
|
return /* @__PURE__ */ jsxs("div", {
|
|
20
|
-
className: "
|
|
21
|
-
children: [
|
|
22
|
-
className: "
|
|
23
|
-
children:
|
|
24
|
-
|
|
82
|
+
className: "shrink-0 border-b ps-4 pe-2 text-fd-muted-foreground",
|
|
83
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
84
|
+
className: cn("flex h-[calc(--spacing(10)-1px)] items-center text-[0.8125rem] font-medium", className),
|
|
85
|
+
children: [
|
|
86
|
+
title && /* @__PURE__ */ jsx("span", {
|
|
87
|
+
className: "me-auto truncate text-fd-foreground",
|
|
88
|
+
children: title
|
|
89
|
+
}),
|
|
90
|
+
children,
|
|
91
|
+
copy && /* @__PURE__ */ jsx(ExampleCopy, { text: copy })
|
|
92
|
+
]
|
|
93
|
+
}), description]
|
|
25
94
|
});
|
|
26
95
|
}
|
|
96
|
+
/** a single item is a plain label */
|
|
27
97
|
function ExampleSelect({ items, value, onValueChange, align = "end", className }) {
|
|
98
|
+
if (items.length === 1) return /* @__PURE__ */ jsx("span", {
|
|
99
|
+
className: "px-2 text-fd-muted-foreground",
|
|
100
|
+
children: items[0].label
|
|
101
|
+
});
|
|
28
102
|
return /* @__PURE__ */ jsxs(Select, {
|
|
29
103
|
items,
|
|
30
104
|
value,
|
|
31
105
|
onValueChange: (v) => v !== null && onValueChange(v),
|
|
32
106
|
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
33
|
-
className: cn("h-7 w-fit max-w-
|
|
107
|
+
className: cn("h-7 w-fit max-w-40 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),
|
|
34
108
|
children: /* @__PURE__ */ jsx(SelectValue, { className: "min-w-0 truncate" })
|
|
35
109
|
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
36
110
|
align,
|
|
@@ -48,4 +122,4 @@ function ExampleSelect({ items, value, onValueChange, align = "end", className }
|
|
|
48
122
|
});
|
|
49
123
|
}
|
|
50
124
|
//#endregion
|
|
51
|
-
export { ExampleHeader, ExampleSelect,
|
|
125
|
+
export { ExampleHeader, ExampleSelect, captionCodeBlock, cardCodeBlock, exampleActions, exampleCardClassName, exampleCodeBlock, selectCodeUsage, titleBarClassName, useCodeUsageId };
|
|
@@ -527,7 +527,7 @@ function getRemoval(required, removable) {
|
|
|
527
527
|
if (removable) return "remove";
|
|
528
528
|
if (!required) return "unset";
|
|
529
529
|
}
|
|
530
|
-
function FieldRow({ entry: { name, fieldName, schema }, required = false, description, onNavigate, onRemove }) {
|
|
530
|
+
function FieldRow({ entry: { name, fieldName, schema }, required = false, description, type: label, onNavigate, onRemove }) {
|
|
531
531
|
const { readOnly, writeOnly } = useSchemaContext();
|
|
532
532
|
const resolved = useResolvedSchema(schema);
|
|
533
533
|
const t = useTranslations({ note: "playground" });
|
|
@@ -553,12 +553,12 @@ function FieldRow({ entry: { name, fieldName, schema }, required = false, descri
|
|
|
553
553
|
const type = getType(field);
|
|
554
554
|
if (type === "object" || type === "array") return /* @__PURE__ */ jsx(NavRow, {
|
|
555
555
|
...props,
|
|
556
|
-
type: typeLabel(field, true),
|
|
556
|
+
type: label ?? typeLabel(field, true),
|
|
557
557
|
onNavigate
|
|
558
558
|
});
|
|
559
559
|
return /* @__PURE__ */ jsx(ValueRow, {
|
|
560
560
|
...props,
|
|
561
|
-
type: cellType(field,
|
|
561
|
+
type: selector ?? label ?? cellType(field, null)
|
|
562
562
|
});
|
|
563
563
|
}
|
|
564
564
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useDataEngine, useFieldValue } from "@fumari/stf";
|
|
5
|
+
//#region ../shared-api/dist/components/playground/json-editor.js
|
|
6
|
+
function JsonEditor({ fieldName }) {
|
|
7
|
+
const engine = useDataEngine();
|
|
8
|
+
const [value] = useFieldValue(fieldName);
|
|
9
|
+
const [draft, setDraft] = useState(() => ({
|
|
10
|
+
value,
|
|
11
|
+
text: formatJson(value),
|
|
12
|
+
error: ""
|
|
13
|
+
}));
|
|
14
|
+
if (draft.value !== value) setDraft({
|
|
15
|
+
value,
|
|
16
|
+
text: formatJson(value),
|
|
17
|
+
error: ""
|
|
18
|
+
});
|
|
19
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
20
|
+
className: "flex flex-col",
|
|
21
|
+
children: [/* @__PURE__ */ jsx("textarea", {
|
|
22
|
+
"aria-label": "JSON",
|
|
23
|
+
value: draft.text,
|
|
24
|
+
spellCheck: false,
|
|
25
|
+
onChange: (e) => {
|
|
26
|
+
const text = e.target.value;
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(text);
|
|
29
|
+
setDraft({
|
|
30
|
+
value: parsed,
|
|
31
|
+
text,
|
|
32
|
+
error: ""
|
|
33
|
+
});
|
|
34
|
+
engine.update(fieldName, parsed);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
setDraft({
|
|
37
|
+
...draft,
|
|
38
|
+
text,
|
|
39
|
+
error: err instanceof Error ? err.message : ""
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
className: "min-h-60 w-full resize-none bg-transparent px-4 py-3 font-mono text-[0.8125rem] leading-relaxed outline-none field-sizing-content"
|
|
44
|
+
}), draft.error && /* @__PURE__ */ jsx("p", {
|
|
45
|
+
className: "border-t px-4 py-2 font-mono text-xs text-red-400",
|
|
46
|
+
children: draft.error
|
|
47
|
+
})]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function formatJson(value) {
|
|
51
|
+
return JSON.stringify(value ?? {}, null, 2);
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { JsonEditor };
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../../utils/cn.js";
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
|
|
4
|
+
import { titleBarClassName } from "../example.js";
|
|
5
|
+
import { Segmented, SegmentedList } from "../segmented.js";
|
|
6
|
+
import { Spinner } from "../spinner.js";
|
|
4
7
|
import { useSchemaUtils } from "./schema.js";
|
|
5
8
|
import { FieldRows, getNestedFields, resolveField } from "./fields.js";
|
|
6
|
-
import { useState } from "react";
|
|
9
|
+
import { memo, useState } from "react";
|
|
7
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
11
|
import { useDataEngine } from "@fumari/stf";
|
|
9
12
|
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
10
13
|
import { useTranslations } from "@fuma-translate/react";
|
|
11
|
-
import { ArrowLeft, ChevronRight } from "lucide-react";
|
|
14
|
+
import { ArrowLeft, ChevronRight, SendHorizontal } from "lucide-react";
|
|
12
15
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
13
16
|
//#region ../shared-api/dist/components/playground/panels.js
|
|
14
17
|
const motionClassNames = {
|
|
@@ -24,9 +27,11 @@ const iconButtonClassName = cn(buttonVariants({
|
|
|
24
27
|
}), "text-fd-muted-foreground [&_svg]:size-3.5");
|
|
25
28
|
/** a code block filling its panel */
|
|
26
29
|
const panelCodeBlock = {
|
|
27
|
-
className:
|
|
28
|
-
viewportProps: { className: "h-
|
|
30
|
+
className: `flex h-full flex-col rounded-none border-0 bg-transparent shadow-none ${titleBarClassName}`,
|
|
31
|
+
viewportProps: { className: "min-h-0 flex-1 max-h-none" }
|
|
29
32
|
};
|
|
33
|
+
/** a code block on top of a panel */
|
|
34
|
+
const panelTopCodeBlock = { className: `shrink-0 rounded-none border-0 border-b ${titleBarClassName}` };
|
|
30
35
|
function PanelHeader({ className, ...props }) {
|
|
31
36
|
return /* @__PURE__ */ jsx("div", {
|
|
32
37
|
...props,
|
|
@@ -243,5 +248,83 @@ function Section({ icon: Icon, title, count, actions, children }) {
|
|
|
243
248
|
}), children]
|
|
244
249
|
});
|
|
245
250
|
}
|
|
251
|
+
/** switches the panels of a playground on small screens, memoized as its indicator measures the tabs on render */
|
|
252
|
+
const ViewSwitch = memo(function ViewSwitch({ value, onValueChange, items }) {
|
|
253
|
+
return /* @__PURE__ */ jsx(Segmented, {
|
|
254
|
+
value,
|
|
255
|
+
onValueChange,
|
|
256
|
+
className: "shrink-0 px-3 pb-3 md:hidden",
|
|
257
|
+
children: /* @__PURE__ */ jsx(SegmentedList, {
|
|
258
|
+
className: "*:flex-1 *:justify-center",
|
|
259
|
+
items
|
|
260
|
+
})
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
/** the example request loaded in a playground, in the header of its dialog */
|
|
264
|
+
function RequestExampleSelect({ items, value, onValueChange, disabled }) {
|
|
265
|
+
const t = useTranslations({ note: "playground" });
|
|
266
|
+
if (items.length <= 1) return null;
|
|
267
|
+
return /* @__PURE__ */ jsxs(Select, {
|
|
268
|
+
items,
|
|
269
|
+
value,
|
|
270
|
+
disabled,
|
|
271
|
+
onValueChange: (v) => v !== null && onValueChange(v),
|
|
272
|
+
children: [/* @__PURE__ */ jsxs(SelectTrigger, {
|
|
273
|
+
className: "h-8 w-auto max-w-64 gap-1.5 border-0 bg-transparent px-2 text-xs hover:bg-fd-accent focus:ring-0 focus-visible:ring-2",
|
|
274
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
275
|
+
className: "text-fd-muted-foreground",
|
|
276
|
+
children: t("Example")
|
|
277
|
+
}), /* @__PURE__ */ jsx(SelectValue, { className: "truncate font-medium" })]
|
|
278
|
+
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
279
|
+
align: "end",
|
|
280
|
+
children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
281
|
+
value: item.value,
|
|
282
|
+
children: item.label
|
|
283
|
+
}, item.value))
|
|
284
|
+
})]
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/** the keyboard shortcut to send */
|
|
288
|
+
function SendShortcut() {
|
|
289
|
+
const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent);
|
|
290
|
+
return /* @__PURE__ */ jsxs("kbd", {
|
|
291
|
+
className: "hidden font-sans text-xs opacity-60 sm:inline",
|
|
292
|
+
children: [isMac ? "⌘" : "Ctrl", " ↵"]
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function SendButton({ sending, disabled }) {
|
|
296
|
+
const t = useTranslations({ note: "playground" });
|
|
297
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
298
|
+
type: "submit",
|
|
299
|
+
disabled: sending || disabled,
|
|
300
|
+
className: cn(buttonVariants({ variant: "primary" }), "h-10 shrink-0 gap-2 rounded-xl px-4 transition-[background-color,scale] active:scale-[0.97] disabled:opacity-80 motion-reduce:transition-none"),
|
|
301
|
+
children: [
|
|
302
|
+
sending ? /* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }) : /* @__PURE__ */ jsx(SendHorizontal, { className: "size-3.5" }),
|
|
303
|
+
t("Send"),
|
|
304
|
+
/* @__PURE__ */ jsx(SendShortcut, {})
|
|
305
|
+
]
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/** an empty panel, telling what fills it */
|
|
309
|
+
function Placeholder({ icon: Icon, className, children }) {
|
|
310
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
311
|
+
className: cn("flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center", className),
|
|
312
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
313
|
+
className: "rounded-xl border bg-fd-secondary p-2.5 text-fd-muted-foreground",
|
|
314
|
+
children: /* @__PURE__ */ jsx(Icon, { className: "size-4" })
|
|
315
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
316
|
+
className: "text-sm text-fd-muted-foreground",
|
|
317
|
+
children
|
|
318
|
+
})]
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/** covers the response while its request is sent */
|
|
322
|
+
function SendingOverlay() {
|
|
323
|
+
const t = useTranslations({ note: "playground" });
|
|
324
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
325
|
+
className: "absolute inset-0 flex items-center justify-center gap-2 bg-fd-card/70 text-sm text-fd-muted-foreground backdrop-blur-[1px] transition-opacity delay-150 duration-200 starting:opacity-0",
|
|
326
|
+
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }), t("Sending request...")]
|
|
327
|
+
});
|
|
328
|
+
}
|
|
246
329
|
//#endregion
|
|
247
|
-
export { Crumb, FieldPanel, OverviewLayer, Panel, PanelHeader, PanelNav, Section, iconButtonClassName, panelCodeBlock, useFieldStack };
|
|
330
|
+
export { Crumb, FieldPanel, OverviewLayer, Panel, PanelHeader, PanelNav, Placeholder, RequestExampleSelect, Section, SendButton, SendShortcut, SendingOverlay, ViewSwitch, iconButtonClassName, panelCodeBlock, panelTopCodeBlock, useFieldStack };
|