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.
- package/css/generated/shared.css +1 -1
- package/dist/.translations/index.d.ts +0 -61
- package/dist/.translations/keys.js +1 -62
- package/dist/generate-file.js +19 -21
- 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 +52 -4
- package/dist/packages/shared-api/dist/.translations/keys.js +53 -5
- 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/defaults.js +13 -19
- package/dist/{ui → packages/shared-api/dist}/components/dialog.js +17 -3
- package/dist/packages/shared-api/dist/components/example.js +125 -0
- package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js +14 -11
- package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/panels.js +330 -0
- package/dist/packages/shared-api/dist/components/playground/param-input.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/result.js +187 -0
- package/dist/packages/shared-api/dist/components/playground/schema.js +5 -3
- package/dist/packages/shared-api/dist/components/playground/server-select.js +130 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +23 -1
- package/dist/{ui → packages/shared-api/dist}/components/segmented.js +2 -2
- 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 +7 -29
- 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 +7 -38
- package/dist/ui/operation/usage-tabs.js +49 -101
- package/dist/ui/playground/client.js +22 -51
- package/dist/ui/playground/components/{oauth-panel.js → auth.js} +20 -8
- package/dist/ui/playground/components/request-panel.js +14 -259
- package/dist/ui/playground/components/response-panel.js +11 -20
- package/dist/ui/playground/components/result-display.d.ts +0 -1
- package/dist/ui/playground/components/result-display.js +46 -182
- package/dist/ui/playground/components/server-select.js +24 -122
- package/dist/ui/playground/components/url-bar.js +8 -66
- package/dist/utils/create-page.d.ts +0 -4
- package/dist/utils/create-page.js +3 -5
- package/dist/utils/pages/builder.js +2 -2
- package/dist/utils/pages/preset-auto.js +139 -137
- package/dist/utils/pages/to-static-data.js +2 -7
- package/dist/utils/pages/to-text.js +2 -2
- package/package.json +6 -6
- package/dist/ui/playground/status-info.js +0 -39
|
@@ -1,31 +1,79 @@
|
|
|
1
1
|
//#region ../shared-api/dist/.translations/keys.js
|
|
2
2
|
var keys_default = [
|
|
3
|
+
"1 item(playground)",
|
|
4
|
+
"Accepted(playground status info)",
|
|
5
|
+
"Add Item(playground)",
|
|
6
|
+
"Add(playground)",
|
|
7
|
+
"Back(playground)",
|
|
8
|
+
"Bad Gateway(playground status info)",
|
|
9
|
+
"Bad Request(playground status info)",
|
|
10
|
+
"Body(playground result display)",
|
|
11
|
+
"Breadcrumb(playground)",
|
|
12
|
+
"Check the server URL. If the API does not allow cross-origin requests from this site, a proxy is needed.(playground result display)",
|
|
13
|
+
"Choose a file(playground)",
|
|
14
|
+
"Clear(playground result display)",
|
|
15
|
+
"Conflict(playground status info)",
|
|
3
16
|
"Copied Link(schema UI)(aria-label)",
|
|
17
|
+
"Copied Text(code block)(aria-label)",
|
|
18
|
+
"Copied(playground)(aria-label)",
|
|
4
19
|
"Copy Link(schema UI)(aria-label)",
|
|
20
|
+
"Copy Text(code block)(aria-label)",
|
|
21
|
+
"Copy(playground)(aria-label)",
|
|
22
|
+
"Created(playground status info)",
|
|
5
23
|
"Default(schema UI)",
|
|
6
24
|
"Deprecated(schema UI)",
|
|
25
|
+
"Empty response body(playground result display)",
|
|
7
26
|
"Enter Property Name(playground)",
|
|
27
|
+
"Enter Value(playground server select)",
|
|
8
28
|
"Enter value(playground)",
|
|
29
|
+
"Error(playground status info)",
|
|
30
|
+
"Example(playground)",
|
|
9
31
|
"Example(schema UI)",
|
|
32
|
+
"Field Info(playground)",
|
|
10
33
|
"Filter Properties(schema UI)",
|
|
34
|
+
"Forbidden(playground status info)",
|
|
11
35
|
"Format(schema UI)",
|
|
36
|
+
"Found(playground status info)",
|
|
37
|
+
"Headers(playground result display)",
|
|
38
|
+
"Internal Server Error(playground status info)",
|
|
12
39
|
"Items(schema UI)",
|
|
13
40
|
"Length(schema UI)",
|
|
14
41
|
"Match(schema UI)",
|
|
42
|
+
"Method Not Allowed(playground status info)",
|
|
43
|
+
"Moved Permanently(playground status info)",
|
|
15
44
|
"Multiple Of(schema UI)",
|
|
16
|
-
"
|
|
17
|
-
"New(playground)",
|
|
45
|
+
"No Content(playground status info)",
|
|
18
46
|
"No property matching(schema UI)",
|
|
47
|
+
"Not Found(playground status info)",
|
|
48
|
+
"Not Modified(playground status info)",
|
|
49
|
+
"Not set(playground)",
|
|
50
|
+
"OK(playground status info)",
|
|
19
51
|
"Properties(schema UI)",
|
|
52
|
+
"Property Name(playground)",
|
|
20
53
|
"Range(schema UI)",
|
|
54
|
+
"Redirect(playground status info)",
|
|
21
55
|
"Remove Item(playground)(aria-label)",
|
|
56
|
+
"Remove(playground)",
|
|
57
|
+
"Request Failed(playground result display)",
|
|
58
|
+
"Schema(playground)",
|
|
22
59
|
"Select(playground)",
|
|
23
|
-
"
|
|
60
|
+
"Send(playground)",
|
|
61
|
+
"Sending request...(playground)",
|
|
62
|
+
"Service Unavailable(playground status info)",
|
|
24
63
|
"Show Path(schema UI)(aria-label)",
|
|
25
64
|
"Show Property(playground)",
|
|
65
|
+
"Successful(playground status info)",
|
|
66
|
+
"Switch Field(playground)",
|
|
67
|
+
"Too Many Requests(playground status info)",
|
|
68
|
+
"Try in Playground(playground)",
|
|
69
|
+
"Type(playground)",
|
|
70
|
+
"Unauthorized(playground status info)",
|
|
71
|
+
"Unprocessable Content(playground status info)",
|
|
26
72
|
"Unset(playground)",
|
|
27
|
-
"
|
|
28
|
-
"Value in(schema UI)"
|
|
73
|
+
"Use the {name} type in TypeScript.(TypeScript definitions)",
|
|
74
|
+
"Value in(schema UI)",
|
|
75
|
+
"Variables(playground server select)",
|
|
76
|
+
"{count} items(playground)"
|
|
29
77
|
];
|
|
30
78
|
//#endregion
|
|
31
79
|
export { keys_default as default };
|
|
@@ -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 };
|
|
@@ -25,12 +25,12 @@ function createPageComponents({ shiki, shikiOptions = defaultShikiOptions, compo
|
|
|
25
25
|
options: shikiOptions,
|
|
26
26
|
...props
|
|
27
27
|
}));
|
|
28
|
-
let
|
|
28
|
+
let render;
|
|
29
29
|
return {
|
|
30
30
|
CodeBlock,
|
|
31
31
|
Markdown: components.Markdown ?? (({ md }) => useMemo(() => {
|
|
32
|
-
|
|
33
|
-
return
|
|
32
|
+
render ??= createRenderer(CodeBlock);
|
|
33
|
+
return render(md);
|
|
34
34
|
}, [md])),
|
|
35
35
|
Heading: components.Heading ?? (({ depth, ...props }) => /* @__PURE__ */ jsx(Heading, {
|
|
36
36
|
as: `h${depth}`,
|
|
@@ -38,7 +38,7 @@ function createPageComponents({ shiki, shikiOptions = defaultShikiOptions, compo
|
|
|
38
38
|
}))
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function createRenderer(CodeBlock) {
|
|
42
42
|
function Pre(props) {
|
|
43
43
|
const codeProps = Children.only(props.children).props;
|
|
44
44
|
const content = codeProps.children;
|
|
@@ -49,22 +49,16 @@ function createProcessor(CodeBlock) {
|
|
|
49
49
|
code: content.trimEnd()
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
...
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const options = {
|
|
53
|
+
...JsxRuntime,
|
|
54
|
+
components: {
|
|
55
|
+
...defaultMdxComponents,
|
|
56
|
+
img: "img",
|
|
57
|
+
pre: Pre
|
|
58
|
+
}
|
|
56
59
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return toJsxRuntime(tree, {
|
|
60
|
-
development: false,
|
|
61
|
-
filePath: file.path,
|
|
62
|
-
...JsxRuntime,
|
|
63
|
-
components: mdxComponents
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return remark().use(remarkGfm).use(remarkRehype).use(rehypeReact);
|
|
60
|
+
const processor = remark().use(remarkGfm).use(remarkRehype);
|
|
61
|
+
return (md) => toJsxRuntime(processor.runSync(processor.parse(md)), options);
|
|
68
62
|
}
|
|
69
63
|
//#endregion
|
|
70
64
|
export { createPageComponents, defaultShikiOptions };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { cn } from "
|
|
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
|
-
//#region
|
|
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 */
|
|
7
10
|
function DialogPopup({ className, children }) {
|
|
8
11
|
return /* @__PURE__ */ jsxs(Dialog.Portal, { children: [/* @__PURE__ */ jsx(Dialog.Backdrop, { className: "fixed inset-0 z-50 bg-black/40 backdrop-blur-xs transition-opacity duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0" }), /* @__PURE__ */ jsx(Dialog.Popup, {
|
|
@@ -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 };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../utils/cn.js";
|
|
3
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
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";
|
|
10
|
+
//#region ../shared-api/dist/components/example.js
|
|
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 */
|
|
57
|
+
const cardCodeBlock = {
|
|
58
|
+
className: "flex min-h-0 flex-col rounded-none border-0 bg-transparent shadow-none",
|
|
59
|
+
viewportProps: { className: "min-h-0" },
|
|
60
|
+
allowCopy: false
|
|
61
|
+
};
|
|
62
|
+
const exampleCardClassName = "flex min-h-0 flex-col overflow-hidden rounded-xl border bg-fd-card";
|
|
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 }) {
|
|
81
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
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]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** a single item is a plain label */
|
|
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
|
+
});
|
|
102
|
+
return /* @__PURE__ */ jsxs(Select, {
|
|
103
|
+
items,
|
|
104
|
+
value,
|
|
105
|
+
onValueChange: (v) => v !== null && onValueChange(v),
|
|
106
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
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),
|
|
108
|
+
children: /* @__PURE__ */ jsx(SelectValue, { className: "min-w-0 truncate" })
|
|
109
|
+
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
110
|
+
align,
|
|
111
|
+
className: "max-w-80",
|
|
112
|
+
children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
113
|
+
value: item.value,
|
|
114
|
+
description: item.description && /* @__PURE__ */ jsx("div", {
|
|
115
|
+
className: "prose prose-xs prose-no-margin font-normal text-fd-muted-foreground",
|
|
116
|
+
children: item.description
|
|
117
|
+
}),
|
|
118
|
+
className: "text-[0.8125rem] font-medium",
|
|
119
|
+
children: item.label
|
|
120
|
+
}, item.value))
|
|
121
|
+
})]
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { ExampleHeader, ExampleSelect, captionCodeBlock, cardCodeBlock, exampleActions, exampleCardClassName, exampleCodeBlock, selectCodeUsage, titleBarClassName, useCodeUsageId };
|
package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { anyFields, useFieldInfo, useResolvedSchema, useSchemaContext, useSchemaUtils } from "../../../packages/shared-api/dist/components/playground/schema.js";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { Select as Select$1, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
|
|
4
|
+
import { anyFields, useFieldInfo, useResolvedSchema, useSchemaContext, useSchemaUtils } from "./schema.js";
|
|
6
5
|
import { Fragment, useId, useMemo, useState } from "react";
|
|
7
6
|
import { dereference, matches, matchesType, mergeAllOf, stringify } from "@fumadocs/json-schema";
|
|
8
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -14,7 +13,7 @@ import { Select } from "@base-ui/react/select";
|
|
|
14
13
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
15
14
|
import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
|
|
16
15
|
import { Popover } from "@base-ui/react/popover";
|
|
17
|
-
//#region
|
|
16
|
+
//#region ../shared-api/dist/components/playground/fields.js
|
|
18
17
|
/** the type of a field, at the end of its cell like a unit */
|
|
19
18
|
const typeClassName = "flex shrink-0 items-center pe-1 font-mono text-xs text-fd-muted-foreground";
|
|
20
19
|
/** holds the actions of field, reserved in tables so their types align, an end padding when stacked */
|
|
@@ -203,7 +202,7 @@ function FieldInfo({ name, field, description }) {
|
|
|
203
202
|
}),
|
|
204
203
|
description && /* @__PURE__ */ jsx("div", {
|
|
205
204
|
className: "mt-1.5 text-xs leading-relaxed text-fd-muted-foreground prose-no-margin [&_a]:underline [&_code]:font-mono",
|
|
206
|
-
children: /* @__PURE__ */ jsx(
|
|
205
|
+
children: /* @__PURE__ */ jsx(FieldMarkdown, { md: description })
|
|
207
206
|
}),
|
|
208
207
|
constraints.length > 0 && /* @__PURE__ */ jsx("dl", {
|
|
209
208
|
className: "mt-2.5 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 border-t pt-2.5 text-xs",
|
|
@@ -330,7 +329,7 @@ function FieldValue({ id, fieldName, field, required = false }) {
|
|
|
330
329
|
});
|
|
331
330
|
}
|
|
332
331
|
if (field.type === "boolean") return /* @__PURE__ */ jsx("div", {
|
|
333
|
-
className: "flex flex-1 items-center gap-0.5
|
|
332
|
+
className: "flex flex-1 items-center gap-0.5 ps-1 pe-2",
|
|
334
333
|
children: [true, false].map((option) => /* @__PURE__ */ jsx("button", {
|
|
335
334
|
type: "button",
|
|
336
335
|
"aria-pressed": value === option,
|
|
@@ -528,7 +527,7 @@ function getRemoval(required, removable) {
|
|
|
528
527
|
if (removable) return "remove";
|
|
529
528
|
if (!required) return "unset";
|
|
530
529
|
}
|
|
531
|
-
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 }) {
|
|
532
531
|
const { readOnly, writeOnly } = useSchemaContext();
|
|
533
532
|
const resolved = useResolvedSchema(schema);
|
|
534
533
|
const t = useTranslations({ note: "playground" });
|
|
@@ -554,12 +553,12 @@ function FieldRow({ entry: { name, fieldName, schema }, required = false, descri
|
|
|
554
553
|
const type = getType(field);
|
|
555
554
|
if (type === "object" || type === "array") return /* @__PURE__ */ jsx(NavRow, {
|
|
556
555
|
...props,
|
|
557
|
-
type: typeLabel(field, true),
|
|
556
|
+
type: label ?? typeLabel(field, true),
|
|
558
557
|
onNavigate
|
|
559
558
|
});
|
|
560
559
|
return /* @__PURE__ */ jsx(ValueRow, {
|
|
561
560
|
...props,
|
|
562
|
-
type: cellType(field,
|
|
561
|
+
type: selector ?? label ?? cellType(field, null)
|
|
563
562
|
});
|
|
564
563
|
}
|
|
565
564
|
});
|
|
@@ -694,7 +693,7 @@ function FieldRows({ entry, onNavigate, showDescription = false }) {
|
|
|
694
693
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
695
694
|
showDescription && field.description && /* @__PURE__ */ jsx("div", {
|
|
696
695
|
className: "border-b px-4 py-2.5 text-xs text-fd-muted-foreground [&_a]:underline",
|
|
697
|
-
children: /* @__PURE__ */ jsx(
|
|
696
|
+
children: /* @__PURE__ */ jsx(FieldMarkdown, { md: field.description })
|
|
698
697
|
}),
|
|
699
698
|
selector && /* @__PURE__ */ jsxs("div", {
|
|
700
699
|
className: "flex min-h-10 items-center gap-2 border-b ps-4 pe-4 text-xs text-fd-muted-foreground @sm:pe-8",
|
|
@@ -708,5 +707,9 @@ function FieldRows({ entry, onNavigate, showDescription = false }) {
|
|
|
708
707
|
}
|
|
709
708
|
});
|
|
710
709
|
}
|
|
710
|
+
function FieldMarkdown({ md }) {
|
|
711
|
+
const { Markdown } = useSchemaContext();
|
|
712
|
+
return Markdown ? /* @__PURE__ */ jsx(Markdown, { md }) : md;
|
|
713
|
+
}
|
|
711
714
|
//#endregion
|
|
712
715
|
export { CellSelect, CheckRow, FieldRow, FieldRows, LinkRow, Row, SelectRow, TextRow, ValueRow, getNestedFields, getRemoval, resolveField };
|
|
@@ -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 };
|