fumadocs-openapi 12.5.0 → 12.5.2
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 -29
- package/dist/.translations/keys.js +1 -30
- package/dist/generate-file.js +4 -4
- package/dist/packages/shared-api/dist/.translations/index.d.ts +18 -0
- package/dist/packages/shared-api/dist/.translations/keys.js +19 -1
- package/dist/packages/shared-api/dist/components/defaults.js +13 -19
- package/dist/{ui → packages/shared-api/dist}/components/dialog.js +2 -2
- package/dist/packages/shared-api/dist/components/example.js +51 -0
- package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js +16 -15
- package/dist/packages/shared-api/dist/components/playground/panels.js +247 -0
- package/dist/packages/shared-api/dist/components/playground/param-input.js +54 -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 +1 -1
- package/dist/{ui → packages/shared-api/dist}/components/segmented.js +2 -2
- package/dist/packages/shared-api/dist/components/select.js +6 -2
- package/dist/requests/string-utils.js +7 -1
- package/dist/server/index.js +2 -5
- package/dist/ui/operation/index.js +20 -13
- package/dist/ui/operation/usage-tabs.js +26 -47
- package/dist/ui/playground/client.js +7 -4
- package/dist/ui/playground/components/oauth-panel.js +2 -2
- package/dist/ui/playground/components/request-panel.js +12 -195
- package/dist/ui/playground/components/response-panel.js +5 -3
- package/dist/ui/playground/components/result-display.d.ts +0 -1
- package/dist/ui/playground/components/result-display.js +3 -18
- package/dist/ui/playground/components/server-select.js +24 -122
- package/dist/ui/playground/components/url-bar.js +6 -47
- package/dist/utils/create-page.d.ts +1 -0
- package/dist/utils/pages/builder.js +2 -2
- package/dist/utils/pages/preset-auto.js +15 -4
- 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/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,
|
|
@@ -428,14 +427,12 @@ function CellSelect({ id, items, value, onValueChange, placeholder }) {
|
|
|
428
427
|
})
|
|
429
428
|
}), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
430
429
|
value: item.value,
|
|
430
|
+
description: item.description && /* @__PURE__ */ jsx("span", {
|
|
431
|
+
className: "text-xs text-fd-muted-foreground",
|
|
432
|
+
children: item.description
|
|
433
|
+
}),
|
|
431
434
|
className: "text-[0.8125rem]",
|
|
432
|
-
children: item.
|
|
433
|
-
className: "flex flex-col",
|
|
434
|
-
children: [item.label, /* @__PURE__ */ jsx("span", {
|
|
435
|
-
className: "text-xs text-fd-muted-foreground",
|
|
436
|
-
children: item.description
|
|
437
|
-
})]
|
|
438
|
-
}) : item.label
|
|
435
|
+
children: item.label
|
|
439
436
|
}, item.value)) })]
|
|
440
437
|
});
|
|
441
438
|
}
|
|
@@ -696,7 +693,7 @@ function FieldRows({ entry, onNavigate, showDescription = false }) {
|
|
|
696
693
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
697
694
|
showDescription && field.description && /* @__PURE__ */ jsx("div", {
|
|
698
695
|
className: "border-b px-4 py-2.5 text-xs text-fd-muted-foreground [&_a]:underline",
|
|
699
|
-
children: /* @__PURE__ */ jsx(
|
|
696
|
+
children: /* @__PURE__ */ jsx(FieldMarkdown, { md: field.description })
|
|
700
697
|
}),
|
|
701
698
|
selector && /* @__PURE__ */ jsxs("div", {
|
|
702
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",
|
|
@@ -710,5 +707,9 @@ function FieldRows({ entry, onNavigate, showDescription = false }) {
|
|
|
710
707
|
}
|
|
711
708
|
});
|
|
712
709
|
}
|
|
710
|
+
function FieldMarkdown({ md }) {
|
|
711
|
+
const { Markdown } = useSchemaContext();
|
|
712
|
+
return Markdown ? /* @__PURE__ */ jsx(Markdown, { md }) : md;
|
|
713
|
+
}
|
|
713
714
|
//#endregion
|
|
714
715
|
export { CellSelect, CheckRow, FieldRow, FieldRows, LinkRow, Row, SelectRow, TextRow, ValueRow, getNestedFields, getRemoval, resolveField };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
|
|
4
|
+
import { useSchemaUtils } from "./schema.js";
|
|
5
|
+
import { FieldRows, getNestedFields, resolveField } from "./fields.js";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { useDataEngine } from "@fumari/stf";
|
|
9
|
+
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
10
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
11
|
+
import { ArrowLeft, ChevronRight } from "lucide-react";
|
|
12
|
+
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
13
|
+
//#region ../shared-api/dist/components/playground/panels.js
|
|
14
|
+
const motionClassNames = {
|
|
15
|
+
forward: "motion-safe:starting:translate-x-6",
|
|
16
|
+
back: "motion-safe:starting:-translate-x-6",
|
|
17
|
+
next: "motion-safe:starting:translate-y-4",
|
|
18
|
+
previous: "motion-safe:starting:-translate-y-4"
|
|
19
|
+
};
|
|
20
|
+
const transitionClassName = "motion-safe:transition-[opacity,translate] motion-safe:duration-300 motion-safe:ease-[cubic-bezier(0.16,1,0.3,1)]";
|
|
21
|
+
const iconButtonClassName = cn(buttonVariants({
|
|
22
|
+
variant: "ghost",
|
|
23
|
+
size: "icon-sm"
|
|
24
|
+
}), "text-fd-muted-foreground [&_svg]:size-3.5");
|
|
25
|
+
/** a code block filling its panel */
|
|
26
|
+
const panelCodeBlock = {
|
|
27
|
+
className: "h-full rounded-none border-0 bg-transparent shadow-none",
|
|
28
|
+
viewportProps: { className: "h-full max-h-none" }
|
|
29
|
+
};
|
|
30
|
+
function PanelHeader({ className, ...props }) {
|
|
31
|
+
return /* @__PURE__ */ jsx("div", {
|
|
32
|
+
...props,
|
|
33
|
+
className: cn("flex h-10 shrink-0 items-center gap-2.5 border-b ps-4 pe-1.5", className)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** the path to the nested field open in a panel */
|
|
37
|
+
function useFieldStack() {
|
|
38
|
+
const engine = useDataEngine();
|
|
39
|
+
const { generateDefault } = useSchemaUtils();
|
|
40
|
+
const [stack, setStack] = useState([]);
|
|
41
|
+
const [motion, setMotion] = useState("forward");
|
|
42
|
+
function navigate(next, nextMotion) {
|
|
43
|
+
const target = next.at(-1);
|
|
44
|
+
if (target) engine.init(target.fieldName, () => {
|
|
45
|
+
const field = resolveField(target.schema, void 0);
|
|
46
|
+
return field ? generateDefault(field) : void 0;
|
|
47
|
+
});
|
|
48
|
+
setMotion(nextMotion ?? (next.length >= stack.length ? "forward" : "back"));
|
|
49
|
+
setStack(next);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
stack,
|
|
53
|
+
motion,
|
|
54
|
+
navigate,
|
|
55
|
+
/** opens a field nested in the last of `parents` */
|
|
56
|
+
openNested(parents) {
|
|
57
|
+
return (entry, siblings) => navigate([...parents, {
|
|
58
|
+
...entry,
|
|
59
|
+
siblings: getNestedFields(engine, siblings)
|
|
60
|
+
}]);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** the overview of fields, it stays under panels and keeps its scroll position */
|
|
65
|
+
function OverviewLayer({ covered, children }) {
|
|
66
|
+
return /* @__PURE__ */ jsx("div", {
|
|
67
|
+
className: cn("fd-scroll-container min-h-0 overflow-y-auto [grid-area:1/1]", transitionClassName, covered && "invisible opacity-0 motion-safe:-translate-x-6"),
|
|
68
|
+
children
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The panel of the field open in `fields`, breadcrumbs go back to `root`.
|
|
73
|
+
*/
|
|
74
|
+
function FieldPanel({ fields: { stack, motion, navigate, openNested }, root, disabled }) {
|
|
75
|
+
const current = stack[stack.length - 1];
|
|
76
|
+
const rows = /* @__PURE__ */ jsx(FieldRows, {
|
|
77
|
+
entry: current,
|
|
78
|
+
showDescription: true,
|
|
79
|
+
onNavigate: openNested(stack)
|
|
80
|
+
});
|
|
81
|
+
return /* @__PURE__ */ jsx(Panel, {
|
|
82
|
+
id: stringifyFieldKey(current.fieldName),
|
|
83
|
+
motion,
|
|
84
|
+
nav: /* @__PURE__ */ jsx(Breadcrumbs, {
|
|
85
|
+
root,
|
|
86
|
+
stack,
|
|
87
|
+
disabled,
|
|
88
|
+
onNavigate: navigate
|
|
89
|
+
}),
|
|
90
|
+
children: disabled === void 0 ? rows : /* @__PURE__ */ jsx("fieldset", {
|
|
91
|
+
disabled,
|
|
92
|
+
className: "contents",
|
|
93
|
+
children: rows
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** a panel over the overview, its content animates in when `id` changes */
|
|
98
|
+
function Panel({ id, motion, nav, children }) {
|
|
99
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
100
|
+
className: "flex min-h-0 flex-col [grid-area:1/1]",
|
|
101
|
+
children: [nav, /* @__PURE__ */ jsx("div", {
|
|
102
|
+
className: cn("fd-scroll-container min-h-0 flex-1 overflow-y-auto starting:opacity-0", transitionClassName, motionClassNames[motion]),
|
|
103
|
+
children
|
|
104
|
+
}, id)]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const crumbClassName = "truncate rounded-md px-1.5 py-1 text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring";
|
|
108
|
+
/** the bar on top of a panel, going back to the overview from `root` */
|
|
109
|
+
function PanelNav({ root, onRoot, onBack, end, children }) {
|
|
110
|
+
const t = useTranslations({ note: "playground" });
|
|
111
|
+
return /* @__PURE__ */ jsxs("nav", {
|
|
112
|
+
"aria-label": t("Breadcrumb"),
|
|
113
|
+
className: "flex h-10 shrink-0 items-center gap-1 border-b ps-1.5 pe-1.5 text-[0.8125rem]",
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ jsx("button", {
|
|
116
|
+
type: "button",
|
|
117
|
+
"aria-label": t("Back"),
|
|
118
|
+
onClick: onBack,
|
|
119
|
+
className: cn(buttonVariants({
|
|
120
|
+
variant: "ghost",
|
|
121
|
+
size: "icon-xs"
|
|
122
|
+
}), "me-1 text-fd-muted-foreground"),
|
|
123
|
+
children: /* @__PURE__ */ jsx(ArrowLeft, {})
|
|
124
|
+
}),
|
|
125
|
+
/* @__PURE__ */ jsxs("ol", {
|
|
126
|
+
className: "flex min-w-0 items-center gap-0.5",
|
|
127
|
+
children: [/* @__PURE__ */ jsx("li", {
|
|
128
|
+
className: "flex min-w-0 shrink-0 items-center",
|
|
129
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
130
|
+
type: "button",
|
|
131
|
+
onClick: onRoot,
|
|
132
|
+
className: crumbClassName,
|
|
133
|
+
children: root
|
|
134
|
+
})
|
|
135
|
+
}), children]
|
|
136
|
+
}),
|
|
137
|
+
end
|
|
138
|
+
]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function Crumb({ children }) {
|
|
142
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
143
|
+
className: "flex min-w-0 items-center gap-0.5 last:shrink-0 motion-safe:transition-opacity motion-safe:starting:opacity-0",
|
|
144
|
+
children: [/* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 shrink-0 text-fd-muted-foreground/60" }), children]
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
function Breadcrumbs({ root, stack, disabled, onNavigate }) {
|
|
148
|
+
const t = useTranslations({ note: "playground" });
|
|
149
|
+
const engine = useDataEngine();
|
|
150
|
+
const current = stack[stack.length - 1];
|
|
151
|
+
return /* @__PURE__ */ jsx(PanelNav, {
|
|
152
|
+
root,
|
|
153
|
+
onRoot: () => onNavigate([]),
|
|
154
|
+
onBack: () => onNavigate(stack.slice(0, -1)),
|
|
155
|
+
end: current.removal && /* @__PURE__ */ jsx("button", {
|
|
156
|
+
type: "button",
|
|
157
|
+
disabled,
|
|
158
|
+
onClick: () => {
|
|
159
|
+
engine.delete(current.fieldName);
|
|
160
|
+
onNavigate(stack.slice(0, -1));
|
|
161
|
+
},
|
|
162
|
+
className: cn(buttonVariants({
|
|
163
|
+
variant: "ghost",
|
|
164
|
+
size: "sm"
|
|
165
|
+
}), "ms-auto shrink-0 text-fd-muted-foreground"),
|
|
166
|
+
children: current.removal === "remove" ? t("Remove") : t("Unset")
|
|
167
|
+
}),
|
|
168
|
+
children: stack.map((entry, i) => {
|
|
169
|
+
const { siblings } = entry;
|
|
170
|
+
let node;
|
|
171
|
+
if (i < stack.length - 1) node = /* @__PURE__ */ jsx("button", {
|
|
172
|
+
type: "button",
|
|
173
|
+
onClick: () => onNavigate(stack.slice(0, i + 1)),
|
|
174
|
+
className: cn(crumbClassName, "font-mono"),
|
|
175
|
+
children: entry.name
|
|
176
|
+
});
|
|
177
|
+
else if (siblings && siblings.length > 1) node = /* @__PURE__ */ jsx(SiblingSelect, {
|
|
178
|
+
entry,
|
|
179
|
+
siblings,
|
|
180
|
+
onSelect: (sibling, motion) => onNavigate([...stack.slice(0, -1), {
|
|
181
|
+
...sibling,
|
|
182
|
+
siblings
|
|
183
|
+
}], motion)
|
|
184
|
+
});
|
|
185
|
+
else node = /* @__PURE__ */ jsx("span", {
|
|
186
|
+
"aria-current": "page",
|
|
187
|
+
className: "truncate px-1.5 py-1 font-mono font-medium",
|
|
188
|
+
children: entry.name
|
|
189
|
+
});
|
|
190
|
+
return /* @__PURE__ */ jsx(Crumb, { children: node }, stringifyFieldKey(entry.fieldName));
|
|
191
|
+
})
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/** the current field, switches to the other nested fields of its parent */
|
|
195
|
+
function SiblingSelect({ entry, siblings, onSelect }) {
|
|
196
|
+
const t = useTranslations({ note: "playground" });
|
|
197
|
+
const current = stringifyFieldKey(entry.fieldName);
|
|
198
|
+
const items = siblings.map((item) => ({
|
|
199
|
+
value: stringifyFieldKey(item.fieldName),
|
|
200
|
+
label: item.name
|
|
201
|
+
}));
|
|
202
|
+
return /* @__PURE__ */ jsxs(Select, {
|
|
203
|
+
items,
|
|
204
|
+
value: current,
|
|
205
|
+
onValueChange: (value) => {
|
|
206
|
+
const next = items.findIndex((item) => item.value === value);
|
|
207
|
+
if (next === -1 || value === current) return;
|
|
208
|
+
const prev = items.findIndex((item) => item.value === current);
|
|
209
|
+
onSelect(siblings[next], next > prev ? "next" : "previous");
|
|
210
|
+
},
|
|
211
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
212
|
+
"aria-label": t("Switch Field"),
|
|
213
|
+
className: "h-7 w-auto min-w-0 gap-1 border-0 bg-transparent px-1.5 py-0 font-mono text-[0.8125rem] font-medium text-fd-foreground hover:bg-fd-accent focus:ring-0 focus-visible:ring-2 data-popup-open:bg-fd-accent",
|
|
214
|
+
children: /* @__PURE__ */ jsx(SelectValue, { className: "truncate" })
|
|
215
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
216
|
+
value: item.value,
|
|
217
|
+
className: "font-mono text-[0.8125rem]",
|
|
218
|
+
children: item.label
|
|
219
|
+
}, item.value)) })]
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/** a group of fields in the overview, its header stays on top while scrolling */
|
|
223
|
+
function Section({ icon: Icon, title, count, actions, children }) {
|
|
224
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
225
|
+
className: "border-b last:border-b-0",
|
|
226
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
227
|
+
className: "sticky top-0 z-10 flex h-10 items-center gap-2 border-b bg-fd-card ps-4 pe-2 @sm:pe-7.5",
|
|
228
|
+
children: [
|
|
229
|
+
/* @__PURE__ */ jsx(Icon, { className: "size-3.5 shrink-0 text-fd-primary" }),
|
|
230
|
+
/* @__PURE__ */ jsx("h3", {
|
|
231
|
+
className: "text-[0.8125rem] font-medium",
|
|
232
|
+
children: title
|
|
233
|
+
}),
|
|
234
|
+
count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
235
|
+
className: "text-xs text-fd-muted-foreground tabular-nums",
|
|
236
|
+
children: count
|
|
237
|
+
}),
|
|
238
|
+
/* @__PURE__ */ jsx("div", {
|
|
239
|
+
className: "flex min-w-0 flex-1 items-center justify-end gap-2",
|
|
240
|
+
children: actions
|
|
241
|
+
})
|
|
242
|
+
]
|
|
243
|
+
}), children]
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
export { Crumb, FieldPanel, OverviewLayer, Panel, PanelHeader, PanelNav, Section, iconButtonClassName, panelCodeBlock, useFieldStack };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { useResolvedSchema } from "./schema.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useFieldValue } from "@fumari/stf";
|
|
6
|
+
//#region ../shared-api/dist/components/playground/param-input.js
|
|
7
|
+
const className = "mx-px rounded-md bg-fd-primary/10 px-1.5 py-0.5 text-fd-primary outline-none transition-colors placeholder:text-fd-primary/50 hover:bg-fd-primary/15 focus-visible:bg-fd-primary/15 focus-visible:ring-2 focus-visible:ring-fd-primary/30";
|
|
8
|
+
/** a parameter of a URL edited in place, like `{id}` of `/users/{id}` */
|
|
9
|
+
function ParamInput({ fieldName, name, schema = true, description }) {
|
|
10
|
+
const resolved = useResolvedSchema(schema);
|
|
11
|
+
const [value, setValue] = useFieldValue(fieldName);
|
|
12
|
+
const text = value == null ? "" : String(value);
|
|
13
|
+
if (resolved.enum && resolved.enum.length > 0) {
|
|
14
|
+
const options = resolved.enum;
|
|
15
|
+
return /* @__PURE__ */ jsxs("select", {
|
|
16
|
+
"aria-label": name,
|
|
17
|
+
title: description,
|
|
18
|
+
value: String(options.indexOf(value)),
|
|
19
|
+
onChange: (e) => setValue(options[Number(e.target.value)]),
|
|
20
|
+
className: cn(className, "cursor-pointer appearance-none"),
|
|
21
|
+
children: [/* @__PURE__ */ jsx("option", {
|
|
22
|
+
value: "-1",
|
|
23
|
+
disabled: true,
|
|
24
|
+
className: "bg-fd-popover text-fd-popover-foreground",
|
|
25
|
+
children: name
|
|
26
|
+
}), options.map((item, i) => /* @__PURE__ */ jsx("option", {
|
|
27
|
+
value: i,
|
|
28
|
+
className: "bg-fd-popover text-fd-popover-foreground",
|
|
29
|
+
children: String(item)
|
|
30
|
+
}, i))]
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const isNumber = resolved.type === "integer" || resolved.type === "number";
|
|
34
|
+
return /* @__PURE__ */ jsx("input", {
|
|
35
|
+
"aria-label": name,
|
|
36
|
+
title: description,
|
|
37
|
+
value: text,
|
|
38
|
+
placeholder: name,
|
|
39
|
+
autoComplete: "off",
|
|
40
|
+
spellCheck: false,
|
|
41
|
+
inputMode: isNumber ? "decimal" : void 0,
|
|
42
|
+
onChange: (e) => {
|
|
43
|
+
const v = e.target.value;
|
|
44
|
+
const number = Number(v);
|
|
45
|
+
if (v.length === 0) setValue(void 0);
|
|
46
|
+
else if (isNumber && String(number) === v && (resolved.type === "integer" ? Number.isInteger(number) : Number.isFinite(number))) setValue(number);
|
|
47
|
+
else setValue(v);
|
|
48
|
+
},
|
|
49
|
+
style: { width: `calc(${Math.max(text.length, name.length, 1)}ch + 0.75rem)` },
|
|
50
|
+
className
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { ParamInput };
|
|
@@ -16,16 +16,18 @@ const anyFields = {
|
|
|
16
16
|
items: true,
|
|
17
17
|
additionalProperties: true
|
|
18
18
|
};
|
|
19
|
-
function SchemaProvider({ readOnly, writeOnly, docRoot, children }) {
|
|
19
|
+
function SchemaProvider({ readOnly, writeOnly, docRoot, Markdown, children }) {
|
|
20
20
|
return /* @__PURE__ */ jsx(SchemaContext.Provider, {
|
|
21
21
|
value: useMemo(() => ({
|
|
22
22
|
readOnly,
|
|
23
23
|
writeOnly,
|
|
24
|
-
docRoot
|
|
24
|
+
docRoot,
|
|
25
|
+
Markdown
|
|
25
26
|
}), [
|
|
26
27
|
docRoot,
|
|
27
28
|
readOnly,
|
|
28
|
-
writeOnly
|
|
29
|
+
writeOnly,
|
|
30
|
+
Markdown
|
|
29
31
|
]),
|
|
30
32
|
children
|
|
31
33
|
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { StfProvider, useFieldValue, useListener, useStf } from "@fumari/stf";
|
|
7
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
8
|
+
import { Check, ChevronDown } from "lucide-react";
|
|
9
|
+
import { Popover } from "@base-ui/react/popover";
|
|
10
|
+
//#region ../shared-api/dist/components/playground/server-select.js
|
|
11
|
+
/**
|
|
12
|
+
* Selects the server in a popover, `children` goes below its options, like `<ServerVariables />`.
|
|
13
|
+
*/
|
|
14
|
+
function ServerPopover({ label, title, options, value, onValueChange, className, children }) {
|
|
15
|
+
const [open, setOpen] = useState(false);
|
|
16
|
+
return /* @__PURE__ */ jsxs(Popover.Root, {
|
|
17
|
+
open,
|
|
18
|
+
onOpenChange: setOpen,
|
|
19
|
+
children: [/* @__PURE__ */ jsxs(Popover.Trigger, {
|
|
20
|
+
className: cn("group flex min-w-0 shrink items-center gap-1 rounded-lg px-1.5 py-1 text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring data-popup-open:bg-fd-accent data-popup-open:text-fd-accent-foreground", className),
|
|
21
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
22
|
+
className: "truncate",
|
|
23
|
+
children: label
|
|
24
|
+
}), /* @__PURE__ */ jsx(ChevronDown, { className: "size-3 shrink-0 transition-transform duration-200 group-data-popup-open:rotate-180" })]
|
|
25
|
+
}), /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
|
|
26
|
+
side: "bottom",
|
|
27
|
+
align: "start",
|
|
28
|
+
sideOffset: 8,
|
|
29
|
+
className: "z-50",
|
|
30
|
+
children: /* @__PURE__ */ jsxs(Popover.Popup, {
|
|
31
|
+
className: "flex max-h-(--available-height) w-[min(26rem,calc(100vw-2rem))] origin-(--transform-origin) flex-col overflow-y-auto rounded-xl border bg-fd-popover p-1 text-sm text-fd-popover-foreground shadow-lg transition-[opacity,scale] duration-150 ease-out outline-none data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0",
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsx("p", {
|
|
34
|
+
className: "px-2.5 pt-1.5 pb-1 text-xs font-medium text-fd-muted-foreground",
|
|
35
|
+
children: title
|
|
36
|
+
}),
|
|
37
|
+
options.map((option) => {
|
|
38
|
+
const selected = option.value === value;
|
|
39
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
40
|
+
type: "button",
|
|
41
|
+
"aria-pressed": selected,
|
|
42
|
+
onClick: () => {
|
|
43
|
+
if (!selected) onValueChange(option.value);
|
|
44
|
+
if (!option.hasVariables) setOpen(false);
|
|
45
|
+
},
|
|
46
|
+
className: cn("flex w-full items-start gap-2 rounded-lg px-2.5 py-2 text-start focus-visible:ring-2 focus-visible:ring-fd-ring focus-visible:outline-none focus-visible:ring-inset", selected ? "bg-fd-accent text-fd-accent-foreground" : "hover:bg-fd-accent/50 hover:text-fd-accent-foreground"),
|
|
47
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
48
|
+
className: "min-w-0 flex-1",
|
|
49
|
+
children: option.label
|
|
50
|
+
}), selected && /* @__PURE__ */ jsx(Check, { className: "mt-0.5 size-3.5 shrink-0 text-fd-primary" })]
|
|
51
|
+
}, option.value);
|
|
52
|
+
}),
|
|
53
|
+
children
|
|
54
|
+
]
|
|
55
|
+
})
|
|
56
|
+
}) })]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Edits the variables of the selected server, they apply once typing stops. Key it by the server.
|
|
61
|
+
*/
|
|
62
|
+
function ServerVariables({ defaultValues, variables, onChange }) {
|
|
63
|
+
const t = useTranslations({ note: "playground server select" });
|
|
64
|
+
const stf = useStf({ defaultValues: () => structuredClone(defaultValues) });
|
|
65
|
+
const timerRef = useRef(void 0);
|
|
66
|
+
useListener({
|
|
67
|
+
stf,
|
|
68
|
+
onUpdate() {
|
|
69
|
+
window.clearTimeout(timerRef.current);
|
|
70
|
+
timerRef.current = window.setTimeout(() => onChange(stf.dataEngine.getData()), 300);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
useEffect(() => () => window.clearTimeout(timerRef.current), []);
|
|
74
|
+
return /* @__PURE__ */ jsx(StfProvider, {
|
|
75
|
+
value: stf,
|
|
76
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
77
|
+
className: "mt-1 flex flex-col gap-2.5 border-t px-2.5 pt-2.5 pb-2",
|
|
78
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
79
|
+
className: "text-xs font-medium text-fd-muted-foreground",
|
|
80
|
+
children: t("Variables")
|
|
81
|
+
}), Object.entries(variables).map(([key, variable]) => /* @__PURE__ */ jsxs("div", {
|
|
82
|
+
className: "grid grid-cols-[minmax(0,2fr)_minmax(0,3fr)] items-center gap-3",
|
|
83
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
84
|
+
htmlFor: `server-${key}`,
|
|
85
|
+
className: "min-w-0",
|
|
86
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
87
|
+
className: "block truncate font-mono text-[0.8125rem]",
|
|
88
|
+
children: key
|
|
89
|
+
}), variable.description && /* @__PURE__ */ jsx("span", {
|
|
90
|
+
className: "block text-xs text-fd-muted-foreground",
|
|
91
|
+
children: variable.description
|
|
92
|
+
})]
|
|
93
|
+
}), /* @__PURE__ */ jsx(VariableInput, {
|
|
94
|
+
fieldName: key,
|
|
95
|
+
variable
|
|
96
|
+
})]
|
|
97
|
+
}, key))]
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function VariableInput({ fieldName, variable }) {
|
|
102
|
+
const t = useTranslations({ note: "playground server select" });
|
|
103
|
+
const id = `server-${fieldName}`;
|
|
104
|
+
const [value, setValue] = useFieldValue([fieldName], { compute(currentValue) {
|
|
105
|
+
return typeof currentValue === "string" ? currentValue : void 0;
|
|
106
|
+
} });
|
|
107
|
+
if (variable.enum) return /* @__PURE__ */ jsxs(Select, {
|
|
108
|
+
value: value ?? null,
|
|
109
|
+
onValueChange: (v) => v !== null && setValue(v),
|
|
110
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
111
|
+
id,
|
|
112
|
+
className: "h-8 py-1 font-mono text-[0.8125rem]",
|
|
113
|
+
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
114
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: variable.enum.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
115
|
+
value: item,
|
|
116
|
+
className: "font-mono text-[0.8125rem]",
|
|
117
|
+
children: item
|
|
118
|
+
}, item)) })]
|
|
119
|
+
});
|
|
120
|
+
const example = variable.examples?.[0];
|
|
121
|
+
return /* @__PURE__ */ jsx("input", {
|
|
122
|
+
id,
|
|
123
|
+
value: value ?? "",
|
|
124
|
+
onChange: (e) => setValue(e.target.value),
|
|
125
|
+
placeholder: example ?? t("Enter Value"),
|
|
126
|
+
className: cn("h-8 w-full rounded-md border bg-fd-secondary px-2 font-mono text-[0.8125rem] text-fd-secondary-foreground outline-none placeholder:text-fd-muted-foreground focus-visible:ring-2 focus-visible:ring-fd-ring", example === void 0 && "placeholder:font-sans")
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { ServerPopover, ServerVariables };
|
|
@@ -7,8 +7,8 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
import { useTranslations } from "@fuma-translate/react";
|
|
8
8
|
import { CheckIcon, ChevronRightIcon, FilterIcon, FilterXIcon, LinkIcon } from "lucide-react";
|
|
9
9
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
10
|
-
import { flushSync } from "react-dom";
|
|
11
10
|
import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
|
|
11
|
+
import { flushSync } from "react-dom";
|
|
12
12
|
import { Menu } from "@base-ui/react/menu";
|
|
13
13
|
import { SchemaUIProvider, useSchemaUI } from "@fumadocs/json-schema/react/client";
|
|
14
14
|
//#region ../shared-api/dist/components/schema/client.js
|
|
@@ -1,8 +1,8 @@
|
|
|
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
4
|
import { Tabs } from "@base-ui/react/tabs";
|
|
5
|
-
//#region
|
|
5
|
+
//#region ../shared-api/dist/components/segmented.js
|
|
6
6
|
const Segmented = Tabs.Root;
|
|
7
7
|
const SegmentedPanel = Tabs.Panel;
|
|
8
8
|
/** a pill switch with a sliding indicator, its panels go in `<SegmentedPanel />` */
|
|
@@ -56,12 +56,16 @@ function SelectContent({ className, children, align = "start", side = "bottom",
|
|
|
56
56
|
})
|
|
57
57
|
}) });
|
|
58
58
|
}
|
|
59
|
-
function SelectItem({ className, children, ref, ...props }) {
|
|
59
|
+
function SelectItem({ className, children, description, ref, ...props }) {
|
|
60
|
+
const text = /* @__PURE__ */ jsx(Select.ItemText, { children });
|
|
60
61
|
return /* @__PURE__ */ jsxs(Select.Item, {
|
|
61
62
|
ref,
|
|
62
63
|
className: cn("flex select-none flex-row items-center gap-2 rounded-md py-1.5 px-2 text-sm outline-none data-[highlighted]:bg-fd-accent data-[highlighted]:text-fd-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className),
|
|
63
64
|
...props,
|
|
64
|
-
children: [
|
|
65
|
+
children: [description ? /* @__PURE__ */ jsxs("div", {
|
|
66
|
+
className: "flex flex-col",
|
|
67
|
+
children: [text, description]
|
|
68
|
+
}) : text, /* @__PURE__ */ jsx(Select.ItemIndicator, {
|
|
65
69
|
className: "ms-auto shrink-0",
|
|
66
70
|
children: /* @__PURE__ */ jsx(Check, { className: "size-3.5 text-fd-primary" })
|
|
67
71
|
})]
|
|
@@ -35,6 +35,12 @@ function doubleQuote(str) {
|
|
|
35
35
|
return `"${str.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
+
* A JSX attribute value, strings don't process escapes, an expression holds the ones with quotes.
|
|
39
|
+
*/
|
|
40
|
+
function jsxString(str) {
|
|
41
|
+
return str.includes("\"") ? `{${JSON.stringify(str)}}` : `"${str}"`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
38
44
|
* Returns the input string wrapped in Python triple double-quotes,
|
|
39
45
|
* escaping embedded triple quotes and backslashes.
|
|
40
46
|
*/
|
|
@@ -67,4 +73,4 @@ function indent(code, tab = 1) {
|
|
|
67
73
|
return code.split("\n").map((v) => v.length === 0 ? v : p + v).join("\n");
|
|
68
74
|
}
|
|
69
75
|
//#endregion
|
|
70
|
-
export { backtickQuote, cookieString, doubleQuote, goRawStringLiteral, indent, inputToString, rustRawStringLiteral, tripleDoubleQuote };
|
|
76
|
+
export { backtickQuote, cookieString, doubleQuote, goRawStringLiteral, indent, inputToString, jsxString, rustRawStringLiteral, tripleDoubleQuote };
|
package/dist/server/index.js
CHANGED
|
@@ -15,11 +15,8 @@ function createOpenAPI(options = {}) {
|
|
|
15
15
|
let resolvedInput = {};
|
|
16
16
|
if (Array.isArray(options.input)) for (const item of options.input) resolvedInput[item] = item;
|
|
17
17
|
else if (options.input) resolvedInput = options.input;
|
|
18
|
-
function getSchema(schemaId) {
|
|
19
|
-
if (!(schemaId in
|
|
20
|
-
console.warn(`[Fumadocs OpenAPI] the document "${schemaId}" is not listed in the input array, this may be unexpected and won't be cached properly.`);
|
|
21
|
-
return loadDocument(schemaId);
|
|
22
|
-
}
|
|
18
|
+
async function getSchema(schemaId) {
|
|
19
|
+
if (!Object.hasOwn(resolvedInput, schemaId)) throw new Error(`[Fumadocs OpenAPI] the document "${schemaId}" is not listed in "input", only documents from "input" can be loaded.`);
|
|
23
20
|
if (!disableCache) {
|
|
24
21
|
const cached = docCache.get(schemaId);
|
|
25
22
|
if (cached) return cached;
|