fumadocs-openapi 6.0.1 → 6.0.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/dist/build-routes.d.ts +15 -0
- package/dist/build-routes.d.ts.map +1 -0
- package/dist/build-routes.js +38 -0
- package/dist/generate-file.d.ts +38 -0
- package/dist/generate-file.d.ts.map +1 -0
- package/dist/generate-file.js +118 -0
- package/dist/generate.d.ts +48 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +129 -0
- package/dist/index.d.ts +4 -274
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -389
- package/dist/render/codeblock.d.ts +9 -0
- package/dist/render/codeblock.d.ts.map +1 -0
- package/dist/render/codeblock.js +13 -0
- package/dist/render/heading.d.ts +4 -0
- package/dist/render/heading.d.ts.map +1 -0
- package/dist/render/heading.js +6 -0
- package/dist/render/markdown.d.ts +5 -0
- package/dist/render/markdown.d.ts.map +1 -0
- package/dist/render/markdown.js +25 -0
- package/dist/render/operation.d.ts +17 -0
- package/dist/render/operation.d.ts.map +1 -0
- package/dist/render/operation.js +230 -0
- package/dist/render/playground.d.ts +66 -0
- package/dist/render/playground.d.ts.map +1 -0
- package/dist/render/playground.js +181 -0
- package/dist/render/renderer.d.ts +76 -0
- package/dist/render/renderer.d.ts.map +1 -0
- package/dist/render/renderer.js +23 -0
- package/dist/render/schema.d.ts +29 -0
- package/dist/render/schema.d.ts.map +1 -0
- package/dist/render/schema.js +151 -0
- package/dist/requests/curl.d.ts +3 -0
- package/dist/requests/curl.d.ts.map +1 -0
- package/dist/requests/curl.js +33 -0
- package/dist/requests/go.d.ts +3 -0
- package/dist/requests/go.d.ts.map +1 -0
- package/dist/requests/go.js +54 -0
- package/dist/requests/javascript.d.ts +3 -0
- package/dist/requests/javascript.d.ts.map +1 -0
- package/dist/requests/javascript.js +49 -0
- package/dist/requests/python.d.ts +3 -0
- package/dist/requests/python.d.ts.map +1 -0
- package/dist/requests/python.js +45 -0
- package/dist/scalar/client.d.ts +6 -0
- package/dist/scalar/client.d.ts.map +1 -0
- package/dist/scalar/client.js +25 -0
- package/dist/scalar/index.d.ts +4 -173
- package/dist/scalar/index.d.ts.map +1 -0
- package/dist/scalar/index.js +4 -11
- package/dist/server/api-page.d.ts +33 -0
- package/dist/server/api-page.d.ts.map +1 -0
- package/dist/server/api-page.js +59 -0
- package/dist/server/create-method.d.ts +7 -0
- package/dist/server/create-method.d.ts.map +1 -0
- package/dist/server/create-method.js +12 -0
- package/dist/server/create.d.ts +16 -0
- package/dist/server/create.d.ts.map +1 -0
- package/dist/server/create.js +11 -0
- package/dist/server/index.d.ts +3 -221
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +2 -1493
- package/dist/server/proxy.d.ts +8 -0
- package/dist/server/proxy.d.ts.map +1 -0
- package/dist/server/proxy.js +53 -0
- package/dist/server/source-api.d.ts +8 -0
- package/dist/server/source-api.d.ts.map +1 -0
- package/dist/server/source-api.js +34 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/ui/client.d.ts +22 -0
- package/dist/ui/client.d.ts.map +1 -0
- package/dist/ui/client.js +10 -0
- package/dist/ui/components/input.d.ts +6 -0
- package/dist/ui/components/input.d.ts.map +1 -0
- package/dist/ui/components/input.js +10 -0
- package/dist/ui/components/method-label.d.ts +5 -0
- package/dist/ui/components/method-label.d.ts.map +1 -0
- package/dist/ui/components/method-label.js +33 -0
- package/dist/ui/components/select.d.ts +14 -0
- package/dist/ui/components/select.d.ts.map +1 -0
- package/dist/ui/components/select.js +24 -0
- package/dist/ui/components/variants.d.ts +6 -0
- package/dist/ui/components/variants.d.ts.map +1 -0
- package/dist/ui/components/variants.js +26 -0
- package/dist/ui/contexts/api.d.ts +28 -0
- package/dist/ui/contexts/api.d.ts.map +1 -0
- package/dist/ui/contexts/api.js +74 -0
- package/dist/ui/contexts/schema.d.ts +17 -0
- package/dist/ui/contexts/schema.d.ts.map +1 -0
- package/dist/ui/contexts/schema.js +8 -0
- package/dist/ui/index.d.ts +12 -302
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +18 -98
- package/dist/ui/playground/fetcher.d.ts +34 -0
- package/dist/ui/playground/fetcher.d.ts.map +1 -0
- package/dist/ui/{fetcher-CsHhplmD.js → playground/fetcher.js} +45 -44
- package/dist/ui/playground/get-default-values.d.ts +4 -0
- package/dist/ui/playground/get-default-values.d.ts.map +1 -0
- package/dist/ui/playground/get-default-values.js +24 -0
- package/dist/ui/playground/index.d.ts +44 -0
- package/dist/ui/playground/index.d.ts.map +1 -0
- package/dist/ui/playground/index.js +187 -0
- package/dist/ui/playground/inputs.d.ts +23 -0
- package/dist/ui/playground/inputs.d.ts.map +1 -0
- package/dist/ui/playground/inputs.js +172 -0
- package/dist/ui/playground/resolve.d.ts +6 -0
- package/dist/ui/playground/resolve.d.ts.map +1 -0
- package/dist/ui/playground/resolve.js +14 -0
- package/dist/ui/playground/status-info.d.ts +8 -0
- package/dist/ui/playground/status-info.d.ts.map +1 -0
- package/dist/ui/playground/status-info.js +40 -0
- package/dist/ui/server-select.d.ts +3 -0
- package/dist/ui/server-select.d.ts.map +1 -0
- package/dist/ui/server-select.js +27 -0
- package/dist/utils/combine-schema.d.ts +6 -0
- package/dist/utils/combine-schema.d.ts.map +1 -0
- package/dist/utils/combine-schema.js +46 -0
- package/dist/utils/generate-document.d.ts +20 -0
- package/dist/utils/generate-document.d.ts.map +1 -0
- package/dist/utils/generate-document.js +82 -0
- package/dist/utils/generate-sample.d.ts +33 -0
- package/dist/utils/generate-sample.d.ts.map +1 -0
- package/dist/utils/generate-sample.js +97 -0
- package/dist/utils/get-security.d.ts +8 -0
- package/dist/utils/get-security.d.ts.map +1 -0
- package/dist/utils/get-security.js +23 -0
- package/dist/utils/get-typescript-schema.d.ts +4 -0
- package/dist/utils/get-typescript-schema.d.ts.map +1 -0
- package/dist/utils/get-typescript-schema.js +18 -0
- package/dist/utils/id-to-title.d.ts +2 -0
- package/dist/utils/id-to-title.d.ts.map +1 -0
- package/dist/utils/id-to-title.js +17 -0
- package/dist/utils/input-to-string.d.ts +5 -0
- package/dist/utils/input-to-string.d.ts.map +1 -0
- package/dist/utils/input-to-string.js +21 -0
- package/dist/utils/process-document.d.ts +14 -0
- package/dist/utils/process-document.d.ts.map +1 -0
- package/dist/utils/process-document.js +32 -0
- package/dist/utils/schema.d.ts +9 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +16 -0
- package/dist/utils/server-url.d.ts +2 -0
- package/dist/utils/server-url.d.ts.map +1 -0
- package/dist/utils/server-url.js +7 -0
- package/dist/utils/use-query.d.ts +6 -0
- package/dist/utils/use-query.d.ts.map +1 -0
- package/dist/utils/use-query.js +22 -0
- package/package.json +7 -7
- package/dist/scalar/client-client-BXAjVueF.js +0 -93
- package/dist/ui/client-client-CYO00OiB.js +0 -107
- package/dist/ui/index-client-BUeWwFWK.js +0 -1116
- package/dist/ui/server-select-client-Ct_HJ46K.js +0 -86
|
@@ -1,1116 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { forwardRef, createElement, useState, useMemo, useRef, useEffect, Fragment as Fragment$1 } from 'react';
|
|
4
|
-
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
|
-
import { useFormContext, Controller, useFieldArray, useForm, FormProvider } from 'react-hook-form';
|
|
6
|
-
import { cn, buttonVariants } from 'fumadocs-ui/components/api';
|
|
7
|
-
import { u as useSchemaContext, a as useApiContext, S as SchemaContext } from './client-client-CYO00OiB.js';
|
|
8
|
-
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
9
|
-
import { cva } from 'class-variance-authority';
|
|
10
|
-
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
|
11
|
-
import { S as ServerSelect } from './server-select-client-Ct_HJ46K.js';
|
|
12
|
-
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from 'fumadocs-ui/components/ui/collapsible';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @license lucide-react v0.474.0 - ISC
|
|
16
|
-
*
|
|
17
|
-
* This source code is licensed under the ISC license.
|
|
18
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
19
|
-
*/ const toKebabCase = (string)=>string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
20
|
-
const mergeClasses = (...classes)=>classes.filter((className, index, array)=>{
|
|
21
|
-
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
22
|
-
}).join(" ").trim();
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @license lucide-react v0.474.0 - ISC
|
|
26
|
-
*
|
|
27
|
-
* This source code is licensed under the ISC license.
|
|
28
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
29
|
-
*/ var defaultAttributes = {
|
|
30
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
31
|
-
width: 24,
|
|
32
|
-
height: 24,
|
|
33
|
-
viewBox: "0 0 24 24",
|
|
34
|
-
fill: "none",
|
|
35
|
-
stroke: "currentColor",
|
|
36
|
-
strokeWidth: 2,
|
|
37
|
-
strokeLinecap: "round",
|
|
38
|
-
strokeLinejoin: "round"
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const Icon = /*#__PURE__*/ forwardRef(({ color = "currentColor", size = 24, strokeWidth = 2, absoluteStrokeWidth, className = "", children, iconNode, ...rest }, ref)=>{
|
|
42
|
-
return /*#__PURE__*/ createElement("svg", {
|
|
43
|
-
ref,
|
|
44
|
-
...defaultAttributes,
|
|
45
|
-
width: size,
|
|
46
|
-
height: size,
|
|
47
|
-
stroke: color,
|
|
48
|
-
strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
|
|
49
|
-
className: mergeClasses("lucide", className),
|
|
50
|
-
...rest
|
|
51
|
-
}, [
|
|
52
|
-
...iconNode.map(([tag, attrs])=>/*#__PURE__*/ createElement(tag, attrs)),
|
|
53
|
-
...Array.isArray(children) ? children : [
|
|
54
|
-
children
|
|
55
|
-
]
|
|
56
|
-
]);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const createLucideIcon = (iconName, iconNode)=>{
|
|
60
|
-
const Component = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ createElement(Icon, {
|
|
61
|
-
ref,
|
|
62
|
-
iconNode,
|
|
63
|
-
className: mergeClasses(`lucide-${toKebabCase(iconName)}`, className),
|
|
64
|
-
...props
|
|
65
|
-
}));
|
|
66
|
-
Component.displayName = `${iconName}`;
|
|
67
|
-
return Component;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const __iconNode$6 = [
|
|
71
|
-
[
|
|
72
|
-
"path",
|
|
73
|
-
{
|
|
74
|
-
d: "M20 6 9 17l-5-5",
|
|
75
|
-
key: "1gmf2c"
|
|
76
|
-
}
|
|
77
|
-
]
|
|
78
|
-
];
|
|
79
|
-
const Check = createLucideIcon("Check", __iconNode$6);
|
|
80
|
-
|
|
81
|
-
const __iconNode$5 = [
|
|
82
|
-
[
|
|
83
|
-
"path",
|
|
84
|
-
{
|
|
85
|
-
d: "m6 9 6 6 6-6",
|
|
86
|
-
key: "qrunsl"
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
];
|
|
90
|
-
const ChevronDown = createLucideIcon("ChevronDown", __iconNode$5);
|
|
91
|
-
|
|
92
|
-
const __iconNode$4 = [
|
|
93
|
-
[
|
|
94
|
-
"path",
|
|
95
|
-
{
|
|
96
|
-
d: "m18 15-6-6-6 6",
|
|
97
|
-
key: "153udz"
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
];
|
|
101
|
-
const ChevronUp = createLucideIcon("ChevronUp", __iconNode$4);
|
|
102
|
-
|
|
103
|
-
const __iconNode$3 = [
|
|
104
|
-
[
|
|
105
|
-
"circle",
|
|
106
|
-
{
|
|
107
|
-
cx: "12",
|
|
108
|
-
cy: "12",
|
|
109
|
-
r: "10",
|
|
110
|
-
key: "1mglay"
|
|
111
|
-
}
|
|
112
|
-
],
|
|
113
|
-
[
|
|
114
|
-
"path",
|
|
115
|
-
{
|
|
116
|
-
d: "m9 12 2 2 4-4",
|
|
117
|
-
key: "dzmm74"
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
];
|
|
121
|
-
const CircleCheck = createLucideIcon("CircleCheck", __iconNode$3);
|
|
122
|
-
|
|
123
|
-
const __iconNode$2 = [
|
|
124
|
-
[
|
|
125
|
-
"circle",
|
|
126
|
-
{
|
|
127
|
-
cx: "12",
|
|
128
|
-
cy: "12",
|
|
129
|
-
r: "10",
|
|
130
|
-
key: "1mglay"
|
|
131
|
-
}
|
|
132
|
-
],
|
|
133
|
-
[
|
|
134
|
-
"path",
|
|
135
|
-
{
|
|
136
|
-
d: "m15 9-6 6",
|
|
137
|
-
key: "1uzhvr"
|
|
138
|
-
}
|
|
139
|
-
],
|
|
140
|
-
[
|
|
141
|
-
"path",
|
|
142
|
-
{
|
|
143
|
-
d: "m9 9 6 6",
|
|
144
|
-
key: "z0biqf"
|
|
145
|
-
}
|
|
146
|
-
]
|
|
147
|
-
];
|
|
148
|
-
const CircleX = createLucideIcon("CircleX", __iconNode$2);
|
|
149
|
-
|
|
150
|
-
const __iconNode$1 = [
|
|
151
|
-
[
|
|
152
|
-
"path",
|
|
153
|
-
{
|
|
154
|
-
d: "M5 12h14",
|
|
155
|
-
key: "1ays0h"
|
|
156
|
-
}
|
|
157
|
-
],
|
|
158
|
-
[
|
|
159
|
-
"path",
|
|
160
|
-
{
|
|
161
|
-
d: "M12 5v14",
|
|
162
|
-
key: "s699le"
|
|
163
|
-
}
|
|
164
|
-
]
|
|
165
|
-
];
|
|
166
|
-
const Plus = createLucideIcon("Plus", __iconNode$1);
|
|
167
|
-
|
|
168
|
-
const __iconNode = [
|
|
169
|
-
[
|
|
170
|
-
"path",
|
|
171
|
-
{
|
|
172
|
-
d: "M3 6h18",
|
|
173
|
-
key: "d0wm0j"
|
|
174
|
-
}
|
|
175
|
-
],
|
|
176
|
-
[
|
|
177
|
-
"path",
|
|
178
|
-
{
|
|
179
|
-
d: "M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",
|
|
180
|
-
key: "4alrt4"
|
|
181
|
-
}
|
|
182
|
-
],
|
|
183
|
-
[
|
|
184
|
-
"path",
|
|
185
|
-
{
|
|
186
|
-
d: "M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",
|
|
187
|
-
key: "v07s0e"
|
|
188
|
-
}
|
|
189
|
-
],
|
|
190
|
-
[
|
|
191
|
-
"line",
|
|
192
|
-
{
|
|
193
|
-
x1: "10",
|
|
194
|
-
x2: "10",
|
|
195
|
-
y1: "11",
|
|
196
|
-
y2: "17",
|
|
197
|
-
key: "1uufr5"
|
|
198
|
-
}
|
|
199
|
-
],
|
|
200
|
-
[
|
|
201
|
-
"line",
|
|
202
|
-
{
|
|
203
|
-
x1: "14",
|
|
204
|
-
x2: "14",
|
|
205
|
-
y1: "11",
|
|
206
|
-
y2: "17",
|
|
207
|
-
key: "xtxkd"
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
];
|
|
211
|
-
const Trash2 = createLucideIcon("Trash2", __iconNode);
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Resolve reference
|
|
215
|
-
*/ function resolve(schema, references) {
|
|
216
|
-
if (typeof schema === 'string') return references[schema];
|
|
217
|
-
if (schema.type !== 'ref') return schema;
|
|
218
|
-
return {
|
|
219
|
-
...references[schema.schema],
|
|
220
|
-
description: schema.description,
|
|
221
|
-
isRequired: schema.isRequired
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function getDefaultValue(item, references) {
|
|
226
|
-
if (item.type === 'object') return Object.fromEntries(Object.entries(item.properties).map(([key, prop])=>[
|
|
227
|
-
key,
|
|
228
|
-
getDefaultValue(prop.type === 'ref' ? references[prop.schema] : prop, references)
|
|
229
|
-
]));
|
|
230
|
-
if (item.type === 'array') return [];
|
|
231
|
-
if (item.type === 'null') return null;
|
|
232
|
-
if (item.type === 'switcher') {
|
|
233
|
-
const first = Object.values(item.items).at(0);
|
|
234
|
-
if (!first) return '';
|
|
235
|
-
return getDefaultValue(resolve(first, references), references);
|
|
236
|
-
}
|
|
237
|
-
if (item.type === 'file') return undefined;
|
|
238
|
-
return String(item.defaultValue);
|
|
239
|
-
}
|
|
240
|
-
function getDefaultValues(field, context) {
|
|
241
|
-
return Object.fromEntries(field.map((p)=>[
|
|
242
|
-
p.name,
|
|
243
|
-
getDefaultValue(p, context)
|
|
244
|
-
]));
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const Select = SelectPrimitive.Root;
|
|
248
|
-
const SelectValue = SelectPrimitive.Value;
|
|
249
|
-
const SelectTrigger = /*#__PURE__*/ forwardRef(({ className, children, ...props }, ref)=>/*#__PURE__*/ jsxs(SelectPrimitive.Trigger, {
|
|
250
|
-
ref: ref,
|
|
251
|
-
className: cn('flex h-10 items-center w-full rounded-md border px-3 py-2 text-start text-[13px] text-fd-foreground hover:bg-fd-accent focus:outline-none focus:ring-2 focus:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className),
|
|
252
|
-
...props,
|
|
253
|
-
children: [
|
|
254
|
-
children,
|
|
255
|
-
/*#__PURE__*/ jsx(SelectPrimitive.Icon, {
|
|
256
|
-
asChild: true,
|
|
257
|
-
children: /*#__PURE__*/ jsx(ChevronDown, {
|
|
258
|
-
className: "ms-auto size-4 text-fd-muted-foreground"
|
|
259
|
-
})
|
|
260
|
-
})
|
|
261
|
-
]
|
|
262
|
-
}));
|
|
263
|
-
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
|
264
|
-
const SelectScrollUpButton = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.ScrollUpButton, {
|
|
265
|
-
ref: ref,
|
|
266
|
-
className: cn('flex items-center justify-center py-1', className),
|
|
267
|
-
...props,
|
|
268
|
-
children: /*#__PURE__*/ jsx(ChevronUp, {
|
|
269
|
-
className: "size-4"
|
|
270
|
-
})
|
|
271
|
-
}));
|
|
272
|
-
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
|
|
273
|
-
const SelectScrollDownButton = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.ScrollDownButton, {
|
|
274
|
-
ref: ref,
|
|
275
|
-
className: cn('flex items-center justify-center py-1', className),
|
|
276
|
-
...props,
|
|
277
|
-
children: /*#__PURE__*/ jsx(ChevronDown, {
|
|
278
|
-
className: "size-4"
|
|
279
|
-
})
|
|
280
|
-
}));
|
|
281
|
-
SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
|
|
282
|
-
const SelectContent = /*#__PURE__*/ forwardRef(({ className, children, position, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.Portal, {
|
|
283
|
-
children: /*#__PURE__*/ jsxs(SelectPrimitive.Content, {
|
|
284
|
-
ref: ref,
|
|
285
|
-
className: cn('z-50 overflow-hidden rounded-lg border bg-fd-popover text-fd-popover-foreground shadow-md', className),
|
|
286
|
-
position: position,
|
|
287
|
-
...props,
|
|
288
|
-
children: [
|
|
289
|
-
/*#__PURE__*/ jsx(SelectScrollUpButton, {}),
|
|
290
|
-
/*#__PURE__*/ jsx(SelectPrimitive.Viewport, {
|
|
291
|
-
className: "p-1",
|
|
292
|
-
children: children
|
|
293
|
-
}),
|
|
294
|
-
/*#__PURE__*/ jsx(SelectScrollDownButton, {})
|
|
295
|
-
]
|
|
296
|
-
})
|
|
297
|
-
}));
|
|
298
|
-
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
|
299
|
-
const SelectLabel = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.Label, {
|
|
300
|
-
ref: ref,
|
|
301
|
-
className: cn('py-1.5 pe-2 ps-6 text-sm font-semibold', className),
|
|
302
|
-
...props
|
|
303
|
-
}));
|
|
304
|
-
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
|
305
|
-
const SelectItem = /*#__PURE__*/ forwardRef(({ className, children, ...props }, ref)=>/*#__PURE__*/ jsxs(SelectPrimitive.Item, {
|
|
306
|
-
ref: ref,
|
|
307
|
-
className: cn('flex select-none flex-row items-center rounded-md py-1.5 pe-2 ps-6 text-[13px] outline-none focus:bg-fd-accent focus:text-fd-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className),
|
|
308
|
-
...props,
|
|
309
|
-
children: [
|
|
310
|
-
/*#__PURE__*/ jsx(SelectPrimitive.ItemIndicator, {
|
|
311
|
-
className: "absolute start-2",
|
|
312
|
-
children: /*#__PURE__*/ jsx(Check, {
|
|
313
|
-
className: "size-4"
|
|
314
|
-
})
|
|
315
|
-
}),
|
|
316
|
-
/*#__PURE__*/ jsx(SelectPrimitive.ItemText, {
|
|
317
|
-
children: children
|
|
318
|
-
})
|
|
319
|
-
]
|
|
320
|
-
}));
|
|
321
|
-
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
|
322
|
-
const SelectSeparator = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.Separator, {
|
|
323
|
-
ref: ref,
|
|
324
|
-
className: cn('my-1 h-px bg-fd-muted', className),
|
|
325
|
-
...props
|
|
326
|
-
}));
|
|
327
|
-
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
|
328
|
-
|
|
329
|
-
const labelVariants = cva('text-[13px] font-mono text-fd-card-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70');
|
|
330
|
-
const Input = /*#__PURE__*/ React.forwardRef(({ className, type, ...props }, ref)=>{
|
|
331
|
-
return /*#__PURE__*/ jsx("input", {
|
|
332
|
-
type: type,
|
|
333
|
-
className: cn('flex h-9 w-full rounded-md border bg-transparent px-2 py-1.5 text-[13px] text-fd-foreground transition-colors placeholder:text-fd-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className),
|
|
334
|
-
ref: ref,
|
|
335
|
-
...props
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
Input.displayName = 'Input';
|
|
339
|
-
|
|
340
|
-
function FieldHeader({ name, required = false, type, ...props }) {
|
|
341
|
-
return /*#__PURE__*/ jsxs("label", {
|
|
342
|
-
...props,
|
|
343
|
-
className: cn('w-full inline-flex items-center gap-1', props.className),
|
|
344
|
-
children: [
|
|
345
|
-
/*#__PURE__*/ jsx("span", {
|
|
346
|
-
className: cn(labelVariants()),
|
|
347
|
-
children: name
|
|
348
|
-
}),
|
|
349
|
-
required ? /*#__PURE__*/ jsx("span", {
|
|
350
|
-
className: "text-red-500",
|
|
351
|
-
children: "*"
|
|
352
|
-
}) : null,
|
|
353
|
-
/*#__PURE__*/ jsx("div", {
|
|
354
|
-
className: "flex-1"
|
|
355
|
-
}),
|
|
356
|
-
type ? /*#__PURE__*/ jsx("code", {
|
|
357
|
-
className: "text-xs text-fd-muted-foreground",
|
|
358
|
-
children: type
|
|
359
|
-
}) : null,
|
|
360
|
-
props.children
|
|
361
|
-
]
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
function ObjectInput({ field, fieldName, ...props }) {
|
|
365
|
-
const { references } = useSchemaContext();
|
|
366
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
367
|
-
...props,
|
|
368
|
-
className: cn('flex flex-col gap-6', props.className),
|
|
369
|
-
children: [
|
|
370
|
-
Object.entries(field.properties).map(([key, child])=>/*#__PURE__*/ jsx(FieldSet, {
|
|
371
|
-
name: key,
|
|
372
|
-
field: resolve(child, references),
|
|
373
|
-
fieldName: `${fieldName}.${key}`
|
|
374
|
-
}, key)),
|
|
375
|
-
field.additionalProperties ? /*#__PURE__*/ jsx(AdditionalProperties, {
|
|
376
|
-
fieldName: fieldName,
|
|
377
|
-
type: field.additionalProperties
|
|
378
|
-
}) : null
|
|
379
|
-
]
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
function AdditionalProperties({ fieldName, type }) {
|
|
383
|
-
const { control, setValue } = useFormContext();
|
|
384
|
-
const { references, dynamic } = useSchemaContext();
|
|
385
|
-
const [nextName, setNextName] = useState('');
|
|
386
|
-
const [properties, setProperties] = useState(()=>{
|
|
387
|
-
const d = dynamic.current.get(`additional_${fieldName}`);
|
|
388
|
-
if (d?.type === 'object') return d.properties;
|
|
389
|
-
return [];
|
|
390
|
-
});
|
|
391
|
-
dynamic.current.set(`additional_${fieldName}`, {
|
|
392
|
-
type: 'object',
|
|
393
|
-
properties
|
|
394
|
-
});
|
|
395
|
-
const onAppend = ()=>{
|
|
396
|
-
const name = nextName.trim();
|
|
397
|
-
if (name.length === 0) return;
|
|
398
|
-
setProperties((p)=>{
|
|
399
|
-
if (p.includes(name)) return p;
|
|
400
|
-
setValue(`${fieldName}.${name}`, '');
|
|
401
|
-
setNextName('');
|
|
402
|
-
return [
|
|
403
|
-
...p,
|
|
404
|
-
name
|
|
405
|
-
];
|
|
406
|
-
});
|
|
407
|
-
};
|
|
408
|
-
const types = typeof type === 'string' ? resolveDynamicTypes(references[type], references) : undefined;
|
|
409
|
-
return /*#__PURE__*/ jsxs(Fragment, {
|
|
410
|
-
children: [
|
|
411
|
-
properties.map((item)=>/*#__PURE__*/ jsx(FieldSet, {
|
|
412
|
-
name: item,
|
|
413
|
-
field: {
|
|
414
|
-
type: 'switcher',
|
|
415
|
-
items: types ?? anyFields,
|
|
416
|
-
isRequired: false
|
|
417
|
-
},
|
|
418
|
-
fieldName: `${fieldName}.${item}`,
|
|
419
|
-
toolbar: /*#__PURE__*/ jsx("button", {
|
|
420
|
-
type: "button",
|
|
421
|
-
"aria-label": "Remove Item",
|
|
422
|
-
className: cn(buttonVariants({
|
|
423
|
-
color: 'secondary',
|
|
424
|
-
size: 'sm'
|
|
425
|
-
})),
|
|
426
|
-
onClick: ()=>{
|
|
427
|
-
setProperties((p)=>p.filter((prop)=>prop !== item));
|
|
428
|
-
control.unregister(`${fieldName}.${item}`);
|
|
429
|
-
},
|
|
430
|
-
children: /*#__PURE__*/ jsx(Trash2, {
|
|
431
|
-
className: "size-4"
|
|
432
|
-
})
|
|
433
|
-
})
|
|
434
|
-
}, item)),
|
|
435
|
-
/*#__PURE__*/ jsxs("div", {
|
|
436
|
-
className: "flex flex-row gap-1",
|
|
437
|
-
children: [
|
|
438
|
-
/*#__PURE__*/ jsx(Input, {
|
|
439
|
-
value: nextName,
|
|
440
|
-
placeholder: "Enter Property Name",
|
|
441
|
-
onChange: (e)=>{
|
|
442
|
-
setNextName(e.target.value);
|
|
443
|
-
},
|
|
444
|
-
onKeyDown: (e)=>{
|
|
445
|
-
if (e.key === 'Enter') {
|
|
446
|
-
onAppend();
|
|
447
|
-
e.preventDefault();
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}),
|
|
451
|
-
/*#__PURE__*/ jsx("button", {
|
|
452
|
-
type: "button",
|
|
453
|
-
className: cn(buttonVariants({
|
|
454
|
-
color: 'secondary'
|
|
455
|
-
})),
|
|
456
|
-
onClick: onAppend,
|
|
457
|
-
children: "New"
|
|
458
|
-
})
|
|
459
|
-
]
|
|
460
|
-
})
|
|
461
|
-
]
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
function resolveDynamicTypes(schema, references) {
|
|
465
|
-
if (schema.type !== 'switcher') return {
|
|
466
|
-
[schema.type]: schema
|
|
467
|
-
};
|
|
468
|
-
return Object.fromEntries(Object.entries(schema.items).map(([key, value])=>[
|
|
469
|
-
key,
|
|
470
|
-
resolve(value, references)
|
|
471
|
-
]));
|
|
472
|
-
}
|
|
473
|
-
const anyFields = {
|
|
474
|
-
string: {
|
|
475
|
-
type: 'string',
|
|
476
|
-
isRequired: false,
|
|
477
|
-
defaultValue: ''
|
|
478
|
-
},
|
|
479
|
-
boolean: {
|
|
480
|
-
type: 'boolean',
|
|
481
|
-
isRequired: false,
|
|
482
|
-
defaultValue: ''
|
|
483
|
-
},
|
|
484
|
-
number: {
|
|
485
|
-
type: 'number',
|
|
486
|
-
isRequired: false,
|
|
487
|
-
defaultValue: ''
|
|
488
|
-
},
|
|
489
|
-
object: {
|
|
490
|
-
type: 'object',
|
|
491
|
-
properties: {},
|
|
492
|
-
additionalProperties: true,
|
|
493
|
-
isRequired: false
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
anyFields.array = {
|
|
497
|
-
type: 'array',
|
|
498
|
-
isRequired: false,
|
|
499
|
-
items: {
|
|
500
|
-
type: 'switcher',
|
|
501
|
-
isRequired: false,
|
|
502
|
-
items: anyFields
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
function FieldInput({ field, fieldName, ...props }) {
|
|
506
|
-
const { control, register } = useFormContext();
|
|
507
|
-
if (field.type === 'null') return null;
|
|
508
|
-
if (field.type === 'object') {
|
|
509
|
-
return /*#__PURE__*/ jsx(ObjectInput, {
|
|
510
|
-
field: field,
|
|
511
|
-
fieldName: fieldName,
|
|
512
|
-
...props,
|
|
513
|
-
className: cn('rounded-lg border border-fd-primary/20 bg-fd-card p-3 shadow-sm', props.className)
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
if (field.type === 'array') {
|
|
517
|
-
return /*#__PURE__*/ jsx(ArrayInput, {
|
|
518
|
-
fieldName: fieldName,
|
|
519
|
-
field: field,
|
|
520
|
-
...props,
|
|
521
|
-
className: cn('rounded-lg border border-fd-primary/20 bg-fd-background p-3 shadow-sm', props.className)
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
if (field.type === 'file' || field.type === 'boolean') {
|
|
525
|
-
return /*#__PURE__*/ jsx(Controller, {
|
|
526
|
-
control: control,
|
|
527
|
-
name: fieldName,
|
|
528
|
-
render: ({ field: { value, onChange, ...restField } })=>field.type === 'file' ? /*#__PURE__*/ jsx("input", {
|
|
529
|
-
id: fieldName,
|
|
530
|
-
type: "file",
|
|
531
|
-
multiple: false,
|
|
532
|
-
onChange: (e)=>{
|
|
533
|
-
if (!e.target.files) return;
|
|
534
|
-
onChange(e.target.files.item(0));
|
|
535
|
-
},
|
|
536
|
-
...props,
|
|
537
|
-
...restField
|
|
538
|
-
}) : /*#__PURE__*/ jsxs(Select, {
|
|
539
|
-
value: value,
|
|
540
|
-
onValueChange: onChange,
|
|
541
|
-
disabled: restField.disabled,
|
|
542
|
-
children: [
|
|
543
|
-
/*#__PURE__*/ jsx(SelectTrigger, {
|
|
544
|
-
id: fieldName,
|
|
545
|
-
className: props.className,
|
|
546
|
-
...restField,
|
|
547
|
-
children: /*#__PURE__*/ jsx(SelectValue, {})
|
|
548
|
-
}),
|
|
549
|
-
/*#__PURE__*/ jsxs(SelectContent, {
|
|
550
|
-
children: [
|
|
551
|
-
/*#__PURE__*/ jsx(SelectItem, {
|
|
552
|
-
value: "true",
|
|
553
|
-
children: "True"
|
|
554
|
-
}),
|
|
555
|
-
/*#__PURE__*/ jsx(SelectItem, {
|
|
556
|
-
value: "false",
|
|
557
|
-
children: "False"
|
|
558
|
-
}),
|
|
559
|
-
field.isRequired ? null : /*#__PURE__*/ jsx(SelectItem, {
|
|
560
|
-
value: "null",
|
|
561
|
-
children: "Null"
|
|
562
|
-
})
|
|
563
|
-
]
|
|
564
|
-
})
|
|
565
|
-
]
|
|
566
|
-
})
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
return /*#__PURE__*/ jsx(Input, {
|
|
570
|
-
id: fieldName,
|
|
571
|
-
placeholder: "Enter value",
|
|
572
|
-
type: field.type === 'string' ? 'text' : 'number',
|
|
573
|
-
...register(fieldName),
|
|
574
|
-
...props
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
function FieldSet({ field, fieldName, toolbar, name, ...props }) {
|
|
578
|
-
const { references, dynamic } = useSchemaContext();
|
|
579
|
-
const [value, setValue] = useState(()=>{
|
|
580
|
-
if (field.type !== 'switcher') return '';
|
|
581
|
-
const d = dynamic.current.get(fieldName);
|
|
582
|
-
const items = Object.keys(field.items);
|
|
583
|
-
if (d?.type === 'field') {
|
|
584
|
-
// schemas are passed from server components, they shouldn't be re-constructed
|
|
585
|
-
const cached = items.find((item)=>d.schema === field.items[item]);
|
|
586
|
-
if (cached) return cached;
|
|
587
|
-
}
|
|
588
|
-
return items[0];
|
|
589
|
-
});
|
|
590
|
-
if (field.type === 'null') return null;
|
|
591
|
-
if (value && field.type === 'switcher') {
|
|
592
|
-
dynamic.current.set(fieldName, {
|
|
593
|
-
type: 'field',
|
|
594
|
-
schema: field.items[value]
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
if (field.type === 'switcher') {
|
|
598
|
-
const child = resolve(field.items[value], references);
|
|
599
|
-
return /*#__PURE__*/ jsxs("fieldset", {
|
|
600
|
-
...props,
|
|
601
|
-
className: cn('flex flex-col gap-1.5', props.className),
|
|
602
|
-
children: [
|
|
603
|
-
/*#__PURE__*/ jsxs(FieldHeader, {
|
|
604
|
-
name: name,
|
|
605
|
-
htmlFor: fieldName,
|
|
606
|
-
required: field.isRequired,
|
|
607
|
-
children: [
|
|
608
|
-
/*#__PURE__*/ jsx("select", {
|
|
609
|
-
value: value,
|
|
610
|
-
onChange: (e)=>setValue(e.target.value),
|
|
611
|
-
className: "text-xs",
|
|
612
|
-
children: Object.keys(field.items).map((item)=>/*#__PURE__*/ jsx("option", {
|
|
613
|
-
value: item,
|
|
614
|
-
children: item
|
|
615
|
-
}, item))
|
|
616
|
-
}),
|
|
617
|
-
toolbar
|
|
618
|
-
]
|
|
619
|
-
}),
|
|
620
|
-
/*#__PURE__*/ jsx("p", {
|
|
621
|
-
className: "text-xs text-fd-muted-foreground",
|
|
622
|
-
children: field.description
|
|
623
|
-
}),
|
|
624
|
-
child.type === 'switcher' ? /*#__PURE__*/ jsx(FieldSet, {
|
|
625
|
-
field: child,
|
|
626
|
-
fieldName: fieldName
|
|
627
|
-
}) : /*#__PURE__*/ jsx(FieldInput, {
|
|
628
|
-
field: child,
|
|
629
|
-
fieldName: fieldName
|
|
630
|
-
})
|
|
631
|
-
]
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
return /*#__PURE__*/ jsxs("fieldset", {
|
|
635
|
-
...props,
|
|
636
|
-
className: cn('flex flex-col gap-1.5', props.className),
|
|
637
|
-
children: [
|
|
638
|
-
/*#__PURE__*/ jsx(FieldHeader, {
|
|
639
|
-
htmlFor: fieldName,
|
|
640
|
-
name: name,
|
|
641
|
-
required: field.isRequired,
|
|
642
|
-
type: field.type,
|
|
643
|
-
children: toolbar
|
|
644
|
-
}),
|
|
645
|
-
/*#__PURE__*/ jsx(FieldInput, {
|
|
646
|
-
field: field,
|
|
647
|
-
fieldName: fieldName
|
|
648
|
-
})
|
|
649
|
-
]
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
function ArrayInput({ fieldName, field, ...props }) {
|
|
653
|
-
const { references } = useSchemaContext();
|
|
654
|
-
const items = resolve(field.items, references);
|
|
655
|
-
const { fields, append, remove } = useFieldArray({
|
|
656
|
-
name: fieldName
|
|
657
|
-
});
|
|
658
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
659
|
-
...props,
|
|
660
|
-
className: cn('flex flex-col gap-2', props.className),
|
|
661
|
-
children: [
|
|
662
|
-
fields.map((item, index)=>/*#__PURE__*/ jsx(FieldSet, {
|
|
663
|
-
name: `${fieldName.split('.').at(-1)}[${index}]`,
|
|
664
|
-
field: items,
|
|
665
|
-
fieldName: `${fieldName}.${index}`,
|
|
666
|
-
toolbar: /*#__PURE__*/ jsx("button", {
|
|
667
|
-
type: "button",
|
|
668
|
-
"aria-label": "Remove Item",
|
|
669
|
-
className: cn(buttonVariants({
|
|
670
|
-
color: 'secondary',
|
|
671
|
-
size: 'sm'
|
|
672
|
-
})),
|
|
673
|
-
onClick: ()=>{
|
|
674
|
-
remove(index);
|
|
675
|
-
},
|
|
676
|
-
children: /*#__PURE__*/ jsx(Trash2, {
|
|
677
|
-
className: "size-4"
|
|
678
|
-
})
|
|
679
|
-
})
|
|
680
|
-
}, item.id)),
|
|
681
|
-
/*#__PURE__*/ jsxs("button", {
|
|
682
|
-
type: "button",
|
|
683
|
-
className: cn(buttonVariants({
|
|
684
|
-
color: 'outline',
|
|
685
|
-
className: 'gap-1.5 py-2',
|
|
686
|
-
size: 'sm'
|
|
687
|
-
})),
|
|
688
|
-
onClick: ()=>{
|
|
689
|
-
append(getDefaultValue(items, references));
|
|
690
|
-
},
|
|
691
|
-
children: [
|
|
692
|
-
/*#__PURE__*/ jsx(Plus, {
|
|
693
|
-
className: "size-4"
|
|
694
|
-
}),
|
|
695
|
-
"New Item"
|
|
696
|
-
]
|
|
697
|
-
})
|
|
698
|
-
]
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
const statusMap = {
|
|
703
|
-
400: {
|
|
704
|
-
description: 'Bad Request',
|
|
705
|
-
color: 'text-red-500',
|
|
706
|
-
icon: CircleX
|
|
707
|
-
},
|
|
708
|
-
401: {
|
|
709
|
-
description: 'Unauthorized',
|
|
710
|
-
color: 'text-red-500',
|
|
711
|
-
icon: CircleX
|
|
712
|
-
},
|
|
713
|
-
403: {
|
|
714
|
-
description: 'Forbidden',
|
|
715
|
-
color: 'text-red-500',
|
|
716
|
-
icon: CircleX
|
|
717
|
-
},
|
|
718
|
-
404: {
|
|
719
|
-
description: 'Not Found',
|
|
720
|
-
color: 'text-fd-muted-foreground',
|
|
721
|
-
icon: CircleX
|
|
722
|
-
},
|
|
723
|
-
500: {
|
|
724
|
-
description: 'Internal Server Error',
|
|
725
|
-
color: 'text-red-500',
|
|
726
|
-
icon: CircleX
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
function getStatusInfo(status) {
|
|
730
|
-
if (status in statusMap) {
|
|
731
|
-
return statusMap[status];
|
|
732
|
-
}
|
|
733
|
-
if (status >= 200 && status < 300) {
|
|
734
|
-
return {
|
|
735
|
-
description: 'Successful',
|
|
736
|
-
color: 'text-green-500',
|
|
737
|
-
icon: CircleCheck
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
if (status >= 400) {
|
|
741
|
-
return {
|
|
742
|
-
description: 'Error',
|
|
743
|
-
color: 'text-red-500',
|
|
744
|
-
icon: CircleX
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
|
-
return {
|
|
748
|
-
description: 'No Description',
|
|
749
|
-
color: 'text-fd-muted-foreground',
|
|
750
|
-
icon: CircleX
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
function getUrl(url, variables) {
|
|
755
|
-
let out = url;
|
|
756
|
-
for (const [key, value] of Object.entries(variables)){
|
|
757
|
-
out = out.replaceAll(`{${key}}`, value);
|
|
758
|
-
}
|
|
759
|
-
return out;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
const variants = cva('font-mono font-medium', {
|
|
763
|
-
variants: {
|
|
764
|
-
color: {
|
|
765
|
-
green: 'text-green-600 dark:text-green-400',
|
|
766
|
-
yellow: 'text-yellow-600 dark:text-yellow-400',
|
|
767
|
-
red: 'text-red-600 dark:text-red-400',
|
|
768
|
-
blue: 'text-blue-600 dark:text-blue-400',
|
|
769
|
-
orange: 'text-orange-600 dark:text-orange-400'
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
});
|
|
773
|
-
function getBadgeColor(method) {
|
|
774
|
-
switch(method.toUpperCase()){
|
|
775
|
-
case 'PUT':
|
|
776
|
-
return 'yellow';
|
|
777
|
-
case 'PATCH':
|
|
778
|
-
return 'orange';
|
|
779
|
-
case 'POST':
|
|
780
|
-
return 'blue';
|
|
781
|
-
case 'DELETE':
|
|
782
|
-
return 'red';
|
|
783
|
-
default:
|
|
784
|
-
return 'green';
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
function MethodLabel({ children, ...props }) {
|
|
788
|
-
return /*#__PURE__*/ jsx("span", {
|
|
789
|
-
...props,
|
|
790
|
-
className: cn(variants({
|
|
791
|
-
color: getBadgeColor(children)
|
|
792
|
-
}), props.className),
|
|
793
|
-
children: children.toUpperCase()
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
function useQuery(fn) {
|
|
798
|
-
const [loading, setLoading] = useState(false);
|
|
799
|
-
const [data, setData] = useState();
|
|
800
|
-
return useMemo(()=>({
|
|
801
|
-
isLoading: loading,
|
|
802
|
-
data,
|
|
803
|
-
start (input) {
|
|
804
|
-
setLoading(true);
|
|
805
|
-
void fn(input).then((res)=>{
|
|
806
|
-
setData(res);
|
|
807
|
-
}).catch(()=>{
|
|
808
|
-
setData(undefined);
|
|
809
|
-
}).finally(()=>{
|
|
810
|
-
setLoading(false);
|
|
811
|
-
});
|
|
812
|
-
}
|
|
813
|
-
}), [
|
|
814
|
-
data,
|
|
815
|
-
fn,
|
|
816
|
-
loading
|
|
817
|
-
]);
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
function defaultAuthValue(auth) {
|
|
821
|
-
if (!auth || auth.type === 'apiKey') return '';
|
|
822
|
-
if (auth.type === 'http' && auth.scheme === 'basic') {
|
|
823
|
-
return {
|
|
824
|
-
username: '',
|
|
825
|
-
password: ''
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
return 'Bearer';
|
|
829
|
-
}
|
|
830
|
-
function APIPlayground({ route, method = 'GET', authorization, path = [], header = [], query = [], body, fields = {}, schemas, proxyUrl, components: { ResultDisplay = DefaultResultDisplay } = {}, ...props }) {
|
|
831
|
-
const { serverRef } = useApiContext();
|
|
832
|
-
const dynamicRef = useRef(new Map());
|
|
833
|
-
const form = useForm({
|
|
834
|
-
defaultValues: {
|
|
835
|
-
authorization: defaultAuthValue(authorization),
|
|
836
|
-
path: getDefaultValues(path, schemas),
|
|
837
|
-
query: getDefaultValues(query, schemas),
|
|
838
|
-
header: getDefaultValues(header, schemas),
|
|
839
|
-
body: body ? getDefaultValue(body, schemas) : undefined
|
|
840
|
-
}
|
|
841
|
-
});
|
|
842
|
-
const testQuery = useQuery(async (input)=>{
|
|
843
|
-
const fetcher = await import('./fetcher-CsHhplmD.js').then((mod)=>mod.createBrowserFetcher(body, schemas));
|
|
844
|
-
const query = {
|
|
845
|
-
...input.query
|
|
846
|
-
};
|
|
847
|
-
const header = {
|
|
848
|
-
...input.header
|
|
849
|
-
};
|
|
850
|
-
if (input.authorization && authorization) {
|
|
851
|
-
if (authorization.type === 'apiKey') {
|
|
852
|
-
if (authorization.in === 'header') {
|
|
853
|
-
header[authorization.name] = input.authorization;
|
|
854
|
-
} else if (authorization.in === 'query') {
|
|
855
|
-
query[authorization.name] = input.authorization;
|
|
856
|
-
} else {
|
|
857
|
-
if ('cookie' in header) {
|
|
858
|
-
header.Cookie = header.cookie;
|
|
859
|
-
delete header.cookie;
|
|
860
|
-
}
|
|
861
|
-
header.Cookie = [
|
|
862
|
-
header.Cookie,
|
|
863
|
-
`${authorization.name}=${input.authorization}`
|
|
864
|
-
].filter((s)=>s.length > 0).join('; ');
|
|
865
|
-
}
|
|
866
|
-
} else if (authorization.type === 'http' && authorization.scheme === 'basic') {
|
|
867
|
-
if (typeof input.authorization === 'object') header.Authorization = `Basic ${btoa(`${input.authorization.username}:${input.authorization.password}`)}`;
|
|
868
|
-
} else {
|
|
869
|
-
header.Authorization = input.authorization;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
const serverUrl = serverRef.current ? getUrl(serverRef.current.url, serverRef.current.variables) : window.location.origin;
|
|
873
|
-
let url = `${serverUrl}${createPathnameFromInput(route, input.path, query)}`;
|
|
874
|
-
if (proxyUrl) {
|
|
875
|
-
const updated = new URL(proxyUrl, window.location.origin);
|
|
876
|
-
updated.searchParams.append('url', url);
|
|
877
|
-
url = updated.toString();
|
|
878
|
-
}
|
|
879
|
-
return fetcher.fetch({
|
|
880
|
-
url: url.toString(),
|
|
881
|
-
header,
|
|
882
|
-
body: body ? {
|
|
883
|
-
mediaType: body.mediaType,
|
|
884
|
-
value: input.body
|
|
885
|
-
} : undefined,
|
|
886
|
-
dynamicFields: dynamicRef.current,
|
|
887
|
-
method
|
|
888
|
-
});
|
|
889
|
-
});
|
|
890
|
-
useEffect(()=>{
|
|
891
|
-
if (!authorization) return;
|
|
892
|
-
const key = `__fumadocs_auth_${JSON.stringify(authorization)}`;
|
|
893
|
-
const cached = localStorage.getItem(key);
|
|
894
|
-
if (cached) form.setValue('authorization', JSON.parse(cached));
|
|
895
|
-
const subscription = form.watch((value, { name })=>{
|
|
896
|
-
if (!name || !name.startsWith('authorization') || !value.authorization) return;
|
|
897
|
-
localStorage.setItem(key, JSON.stringify(value.authorization));
|
|
898
|
-
});
|
|
899
|
-
return ()=>{
|
|
900
|
-
subscription.unsubscribe();
|
|
901
|
-
};
|
|
902
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- mounted only once
|
|
903
|
-
}, []);
|
|
904
|
-
const onSubmit = form.handleSubmit((value)=>{
|
|
905
|
-
testQuery.start(value);
|
|
906
|
-
});
|
|
907
|
-
function renderCustomField(fieldName, info, field, key) {
|
|
908
|
-
if (field) {
|
|
909
|
-
return /*#__PURE__*/ jsx(Controller, {
|
|
910
|
-
control: form.control,
|
|
911
|
-
render: (props)=>field.render({
|
|
912
|
-
...props,
|
|
913
|
-
info
|
|
914
|
-
}),
|
|
915
|
-
name: fieldName
|
|
916
|
-
}, key);
|
|
917
|
-
}
|
|
918
|
-
return /*#__PURE__*/ jsx(FieldSet, {
|
|
919
|
-
name: info.name,
|
|
920
|
-
fieldName: fieldName,
|
|
921
|
-
field: info
|
|
922
|
-
}, key);
|
|
923
|
-
}
|
|
924
|
-
return /*#__PURE__*/ jsx(FormProvider, {
|
|
925
|
-
...form,
|
|
926
|
-
children: /*#__PURE__*/ jsx(SchemaContext.Provider, {
|
|
927
|
-
value: useMemo(()=>({
|
|
928
|
-
references: schemas,
|
|
929
|
-
dynamic: dynamicRef
|
|
930
|
-
}), [
|
|
931
|
-
schemas
|
|
932
|
-
]),
|
|
933
|
-
children: /*#__PURE__*/ jsxs("form", {
|
|
934
|
-
...props,
|
|
935
|
-
className: cn('not-prose flex flex-col gap-2 rounded-xl border p-3 shadow-md', props.className),
|
|
936
|
-
onSubmit: onSubmit,
|
|
937
|
-
children: [
|
|
938
|
-
/*#__PURE__*/ jsx(FormHeader, {
|
|
939
|
-
method: method,
|
|
940
|
-
route: route,
|
|
941
|
-
isLoading: testQuery.isLoading
|
|
942
|
-
}),
|
|
943
|
-
/*#__PURE__*/ jsx(CollapsiblePanel, {
|
|
944
|
-
title: "Server URL",
|
|
945
|
-
children: /*#__PURE__*/ jsx(ServerSelect, {})
|
|
946
|
-
}),
|
|
947
|
-
header.length > 0 || authorization ? /*#__PURE__*/ jsxs(CollapsiblePanel, {
|
|
948
|
-
title: "Headers",
|
|
949
|
-
children: [
|
|
950
|
-
authorization?.type === 'http' && authorization.scheme === 'basic' ? renderCustomField('authorization', {
|
|
951
|
-
name: 'Authorization',
|
|
952
|
-
type: 'object',
|
|
953
|
-
isRequired: true,
|
|
954
|
-
properties: {
|
|
955
|
-
username: {
|
|
956
|
-
type: 'string',
|
|
957
|
-
isRequired: true,
|
|
958
|
-
defaultValue: ''
|
|
959
|
-
},
|
|
960
|
-
password: {
|
|
961
|
-
type: 'string',
|
|
962
|
-
isRequired: true,
|
|
963
|
-
defaultValue: ''
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
}, fields.auth) : authorization ? renderCustomField('authorization', {
|
|
967
|
-
name: 'Authorization',
|
|
968
|
-
type: 'string',
|
|
969
|
-
isRequired: true,
|
|
970
|
-
description: 'The Authorization access token',
|
|
971
|
-
defaultValue: ''
|
|
972
|
-
}, fields.auth) : null,
|
|
973
|
-
header.map((field)=>renderCustomField(`header.${field.name}`, field, fields.header, field.name))
|
|
974
|
-
]
|
|
975
|
-
}) : null,
|
|
976
|
-
path.length > 0 ? /*#__PURE__*/ jsx(CollapsiblePanel, {
|
|
977
|
-
title: "Path",
|
|
978
|
-
children: path.map((field)=>renderCustomField(`path.${field.name}`, field, fields.path, field.name))
|
|
979
|
-
}) : null,
|
|
980
|
-
query.length > 0 ? /*#__PURE__*/ jsx(CollapsiblePanel, {
|
|
981
|
-
title: "Query",
|
|
982
|
-
children: query.map((field)=>renderCustomField(`query.${field.name}`, field, fields.query, field.name))
|
|
983
|
-
}) : null,
|
|
984
|
-
body ? /*#__PURE__*/ jsx(CollapsiblePanel, {
|
|
985
|
-
title: "Body",
|
|
986
|
-
children: body.type === 'object' && !fields.body ? /*#__PURE__*/ jsx(ObjectInput, {
|
|
987
|
-
field: body,
|
|
988
|
-
fieldName: "body"
|
|
989
|
-
}) : renderCustomField('body', body, fields.body)
|
|
990
|
-
}) : null,
|
|
991
|
-
testQuery.data ? /*#__PURE__*/ jsx(ResultDisplay, {
|
|
992
|
-
data: testQuery.data
|
|
993
|
-
}) : null
|
|
994
|
-
]
|
|
995
|
-
})
|
|
996
|
-
})
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
function createPathnameFromInput(route, path, query) {
|
|
1000
|
-
let pathname = route;
|
|
1001
|
-
for (const key of Object.keys(path)){
|
|
1002
|
-
const paramValue = path[key];
|
|
1003
|
-
if (typeof paramValue === 'string' && paramValue.length > 0) pathname = pathname.replace(`{${key}}`, paramValue);
|
|
1004
|
-
}
|
|
1005
|
-
const searchParams = new URLSearchParams();
|
|
1006
|
-
for (const key of Object.keys(query)){
|
|
1007
|
-
const paramValue = query[key];
|
|
1008
|
-
if (typeof paramValue === 'string' && paramValue.length > 0) searchParams.append(key, paramValue);
|
|
1009
|
-
}
|
|
1010
|
-
return searchParams.size > 0 ? `${pathname}?${searchParams.toString()}` : pathname;
|
|
1011
|
-
}
|
|
1012
|
-
function Route({ route, ...props }) {
|
|
1013
|
-
const segments = route.split('/').filter((part)=>part.length > 0);
|
|
1014
|
-
return /*#__PURE__*/ jsx("div", {
|
|
1015
|
-
...props,
|
|
1016
|
-
className: cn('flex flex-row items-center gap-0.5 overflow-auto text-nowrap', props.className),
|
|
1017
|
-
children: segments.map((part, index)=>/*#__PURE__*/ jsxs(Fragment$1, {
|
|
1018
|
-
children: [
|
|
1019
|
-
/*#__PURE__*/ jsx("span", {
|
|
1020
|
-
className: "text-fd-muted-foreground",
|
|
1021
|
-
children: "/"
|
|
1022
|
-
}),
|
|
1023
|
-
part.startsWith('{') && part.endsWith('}') ? /*#__PURE__*/ jsx("code", {
|
|
1024
|
-
className: "bg-fd-primary/10 text-fd-primary",
|
|
1025
|
-
children: part
|
|
1026
|
-
}) : /*#__PURE__*/ jsx("code", {
|
|
1027
|
-
className: "text-fd-foreground",
|
|
1028
|
-
children: part
|
|
1029
|
-
})
|
|
1030
|
-
]
|
|
1031
|
-
}, index))
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
function FormHeader({ route, method, isLoading }) {
|
|
1035
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
1036
|
-
className: "flex flex-row items-center gap-2 text-sm",
|
|
1037
|
-
children: [
|
|
1038
|
-
/*#__PURE__*/ jsx(MethodLabel, {
|
|
1039
|
-
children: method
|
|
1040
|
-
}),
|
|
1041
|
-
/*#__PURE__*/ jsx(Route, {
|
|
1042
|
-
route: route,
|
|
1043
|
-
className: "flex-1"
|
|
1044
|
-
}),
|
|
1045
|
-
/*#__PURE__*/ jsx("button", {
|
|
1046
|
-
type: "submit",
|
|
1047
|
-
className: cn(buttonVariants({
|
|
1048
|
-
color: 'primary',
|
|
1049
|
-
size: 'sm'
|
|
1050
|
-
}), 'px-3 py-1.5'),
|
|
1051
|
-
disabled: isLoading,
|
|
1052
|
-
children: "Send"
|
|
1053
|
-
})
|
|
1054
|
-
]
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
function DefaultResultDisplay({ data }) {
|
|
1058
|
-
const statusInfo = useMemo(()=>getStatusInfo(data.status), [
|
|
1059
|
-
data.status
|
|
1060
|
-
]);
|
|
1061
|
-
const { shikiOptions } = useApiContext();
|
|
1062
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
1063
|
-
className: "flex flex-col gap-3 rounded-lg border bg-fd-card p-4",
|
|
1064
|
-
children: [
|
|
1065
|
-
/*#__PURE__*/ jsxs("div", {
|
|
1066
|
-
className: "inline-flex items-center gap-1.5 text-sm font-medium text-fd-foreground",
|
|
1067
|
-
children: [
|
|
1068
|
-
/*#__PURE__*/ jsx(statusInfo.icon, {
|
|
1069
|
-
className: cn('size-4', statusInfo.color)
|
|
1070
|
-
}),
|
|
1071
|
-
statusInfo.description
|
|
1072
|
-
]
|
|
1073
|
-
}),
|
|
1074
|
-
/*#__PURE__*/ jsx("p", {
|
|
1075
|
-
className: "text-sm text-fd-muted-foreground",
|
|
1076
|
-
children: data.status
|
|
1077
|
-
}),
|
|
1078
|
-
data.data ? /*#__PURE__*/ jsx(DynamicCodeBlock, {
|
|
1079
|
-
lang: typeof data.data === 'string' && data.data.length > 50000 ? 'text' : data.type,
|
|
1080
|
-
code: typeof data.data === 'string' ? data.data : JSON.stringify(data.data, null, 2),
|
|
1081
|
-
...shikiOptions
|
|
1082
|
-
}) : null
|
|
1083
|
-
]
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
function CollapsiblePanel({ title, children, ...props }) {
|
|
1087
|
-
return /*#__PURE__*/ jsxs(Collapsible, {
|
|
1088
|
-
...props,
|
|
1089
|
-
className: "border rounded-xl bg-fd-card text-fd-card-foreground overflow-hidden",
|
|
1090
|
-
children: [
|
|
1091
|
-
/*#__PURE__*/ jsxs(CollapsibleTrigger, {
|
|
1092
|
-
className: "group w-full inline-flex items-center gap-2 justify-between p-3 text-sm font-medium hover:bg-fd-accent",
|
|
1093
|
-
children: [
|
|
1094
|
-
title,
|
|
1095
|
-
/*#__PURE__*/ jsx(ChevronDown, {
|
|
1096
|
-
className: "size-4 group-data-[state=open]:rotate-180"
|
|
1097
|
-
})
|
|
1098
|
-
]
|
|
1099
|
-
}),
|
|
1100
|
-
/*#__PURE__*/ jsx(CollapsibleContent, {
|
|
1101
|
-
children: /*#__PURE__*/ jsx("div", {
|
|
1102
|
-
className: "flex flex-col gap-4 p-3",
|
|
1103
|
-
children: children
|
|
1104
|
-
})
|
|
1105
|
-
})
|
|
1106
|
-
]
|
|
1107
|
-
});
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
var index = {
|
|
1111
|
-
__proto__: null,
|
|
1112
|
-
APIPlayground: APIPlayground,
|
|
1113
|
-
CollapsiblePanel: CollapsiblePanel
|
|
1114
|
-
};
|
|
1115
|
-
|
|
1116
|
-
export { ChevronDown as C, Input as I, Select as S, SelectTrigger as a, SelectValue as b, SelectContent as c, SelectItem as d, index as i, labelVariants as l, resolve as r };
|