fumadocs-openapi 10.2.1 → 10.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (278) hide show
  1. package/dist/generate-file.d.ts +53 -49
  2. package/dist/generate-file.d.ts.map +1 -1
  3. package/dist/generate-file.js +88 -102
  4. package/dist/generate-file.js.map +1 -0
  5. package/dist/index.d.ts +6 -6
  6. package/dist/index.js +3 -1
  7. package/dist/playground/client.d.ts +88 -72
  8. package/dist/playground/client.d.ts.map +1 -1
  9. package/dist/playground/client.js +446 -296
  10. package/dist/playground/client.js.map +1 -0
  11. package/dist/playground/components/inputs.js +395 -172
  12. package/dist/playground/components/inputs.js.map +1 -0
  13. package/dist/playground/components/oauth-dialog.js +270 -174
  14. package/dist/playground/components/oauth-dialog.js.map +1 -0
  15. package/dist/playground/components/server-select.js +115 -55
  16. package/dist/playground/components/server-select.js.map +1 -0
  17. package/dist/playground/fetcher.d.ts +10 -18
  18. package/dist/playground/fetcher.d.ts.map +1 -1
  19. package/dist/playground/fetcher.js +67 -75
  20. package/dist/playground/fetcher.js.map +1 -0
  21. package/dist/playground/get-default-values.js +23 -26
  22. package/dist/playground/get-default-values.js.map +1 -0
  23. package/dist/playground/index.d.ts +23 -13
  24. package/dist/playground/index.d.ts.map +1 -1
  25. package/dist/playground/index.js +87 -91
  26. package/dist/playground/index.js.map +1 -0
  27. package/dist/playground/lazy.js +9 -2
  28. package/dist/playground/lazy.js.map +1 -0
  29. package/dist/playground/schema.d.ts +18 -55
  30. package/dist/playground/schema.d.ts.map +1 -1
  31. package/dist/playground/schema.js +117 -106
  32. package/dist/playground/schema.js.map +1 -0
  33. package/dist/playground/status-info.js +49 -37
  34. package/dist/playground/status-info.js.map +1 -0
  35. package/dist/requests/generators/csharp.js +40 -50
  36. package/dist/requests/generators/csharp.js.map +1 -0
  37. package/dist/requests/generators/curl.js +28 -27
  38. package/dist/requests/generators/curl.js.map +1 -0
  39. package/dist/requests/generators/go.js +39 -35
  40. package/dist/requests/generators/go.js.map +1 -0
  41. package/dist/requests/generators/index.js +49 -43
  42. package/dist/requests/generators/index.js.map +1 -0
  43. package/dist/requests/generators/java.js +56 -67
  44. package/dist/requests/generators/java.js.map +1 -0
  45. package/dist/requests/generators/javascript.js +38 -45
  46. package/dist/requests/generators/javascript.js.map +1 -0
  47. package/dist/requests/generators/python.js +33 -37
  48. package/dist/requests/generators/python.js.map +1 -0
  49. package/dist/requests/media/adapter.d.ts +38 -84
  50. package/dist/requests/media/adapter.d.ts.map +1 -1
  51. package/dist/requests/media/adapter.js +122 -169
  52. package/dist/requests/media/adapter.js.map +1 -0
  53. package/dist/requests/media/encode.d.ts +12 -7
  54. package/dist/requests/media/encode.d.ts.map +1 -1
  55. package/dist/requests/media/encode.js +129 -109
  56. package/dist/requests/media/encode.js.map +1 -0
  57. package/dist/requests/media/resolve-adapter.js +28 -28
  58. package/dist/requests/media/resolve-adapter.js.map +1 -0
  59. package/dist/requests/string-utils.js +28 -35
  60. package/dist/requests/string-utils.js.map +1 -0
  61. package/dist/requests/to-python-object.js +16 -28
  62. package/dist/requests/to-python-object.js.map +1 -0
  63. package/dist/requests/types.d.ts +25 -21
  64. package/dist/requests/types.d.ts.map +1 -1
  65. package/dist/scalar/client.js +57 -20
  66. package/dist/scalar/client.js.map +1 -0
  67. package/dist/scalar/index.d.ts +8 -2
  68. package/dist/scalar/index.d.ts.map +1 -1
  69. package/dist/scalar/index.js +29 -19
  70. package/dist/scalar/index.js.map +1 -0
  71. package/dist/server/create.d.ts +29 -25
  72. package/dist/server/create.d.ts.map +1 -1
  73. package/dist/server/create.js +42 -39
  74. package/dist/server/create.js.map +1 -0
  75. package/dist/server/index.d.ts +3 -3
  76. package/dist/server/index.js +4 -2
  77. package/dist/server/proxy.d.ts +28 -28
  78. package/dist/server/proxy.d.ts.map +1 -1
  79. package/dist/server/proxy.js +58 -75
  80. package/dist/server/proxy.js.map +1 -0
  81. package/dist/server/source-api.d.ts +32 -25
  82. package/dist/server/source-api.d.ts.map +1 -1
  83. package/dist/server/source-api.js +82 -69
  84. package/dist/server/source-api.js.map +1 -0
  85. package/dist/types.d.ts +41 -36
  86. package/dist/types.d.ts.map +1 -1
  87. package/dist/ui/api-page.d.ts +140 -136
  88. package/dist/ui/api-page.d.ts.map +1 -1
  89. package/dist/ui/api-page.js +134 -118
  90. package/dist/ui/api-page.js.map +1 -0
  91. package/dist/ui/client/index.d.ts +30 -26
  92. package/dist/ui/client/index.d.ts.map +1 -1
  93. package/dist/ui/client/index.js +8 -2
  94. package/dist/ui/client/index.js.map +1 -0
  95. package/dist/ui/client/storage-key.js +16 -10
  96. package/dist/ui/client/storage-key.js.map +1 -0
  97. package/dist/ui/components/accordion.js +40 -14
  98. package/dist/ui/components/accordion.js.map +1 -0
  99. package/dist/ui/components/dialog.js +51 -15
  100. package/dist/ui/components/dialog.js.map +1 -0
  101. package/dist/ui/components/input.js +18 -8
  102. package/dist/ui/components/input.js.map +1 -0
  103. package/dist/ui/components/method-label.js +38 -33
  104. package/dist/ui/components/method-label.js.map +1 -0
  105. package/dist/ui/components/select.js +66 -15
  106. package/dist/ui/components/select.js.map +1 -0
  107. package/dist/ui/contexts/api.js +96 -85
  108. package/dist/ui/contexts/api.js.map +1 -0
  109. package/dist/ui/contexts/api.lazy.js +9 -2
  110. package/dist/ui/contexts/api.lazy.js.map +1 -0
  111. package/dist/ui/index.d.ts +2 -2
  112. package/dist/ui/index.js +3 -1
  113. package/dist/ui/operation/client.js +65 -27
  114. package/dist/ui/operation/client.js.map +1 -0
  115. package/dist/ui/operation/index.js +403 -186
  116. package/dist/ui/operation/index.js.map +1 -0
  117. package/dist/ui/operation/request-tabs.d.ts +15 -16
  118. package/dist/ui/operation/request-tabs.d.ts.map +1 -1
  119. package/dist/ui/operation/request-tabs.js +151 -131
  120. package/dist/ui/operation/request-tabs.js.map +1 -0
  121. package/dist/ui/operation/response-tabs.d.ts +27 -28
  122. package/dist/ui/operation/response-tabs.d.ts.map +1 -1
  123. package/dist/ui/operation/response-tabs.js +73 -56
  124. package/dist/ui/operation/response-tabs.js.map +1 -0
  125. package/dist/ui/operation/usage-tabs/client.js +117 -88
  126. package/dist/ui/operation/usage-tabs/client.js.map +1 -0
  127. package/dist/ui/operation/usage-tabs/index.d.ts +22 -21
  128. package/dist/ui/operation/usage-tabs/index.d.ts.map +1 -1
  129. package/dist/ui/operation/usage-tabs/index.js +63 -48
  130. package/dist/ui/operation/usage-tabs/index.js.map +1 -0
  131. package/dist/ui/operation/usage-tabs/lazy.js +11 -4
  132. package/dist/ui/operation/usage-tabs/lazy.js.map +1 -0
  133. package/dist/ui/schema/client.d.ts +11 -7
  134. package/dist/ui/schema/client.d.ts.map +1 -1
  135. package/dist/ui/schema/client.js +213 -127
  136. package/dist/ui/schema/client.js.map +1 -0
  137. package/dist/ui/schema/index.d.ts +51 -50
  138. package/dist/ui/schema/index.d.ts.map +1 -1
  139. package/dist/ui/schema/index.js +225 -248
  140. package/dist/ui/schema/index.js.map +1 -0
  141. package/dist/ui/schema/lazy.js +9 -2
  142. package/dist/ui/schema/lazy.js.map +1 -0
  143. package/dist/utils/cn.js +3 -1
  144. package/dist/utils/deep-equal.js +18 -26
  145. package/dist/utils/deep-equal.js.map +1 -0
  146. package/dist/utils/get-typescript-schema.js +21 -19
  147. package/dist/utils/get-typescript-schema.js.map +1 -0
  148. package/dist/utils/id-to-title.js +13 -16
  149. package/dist/utils/id-to-title.js.map +1 -0
  150. package/dist/utils/lazy.js +13 -11
  151. package/dist/utils/lazy.js.map +1 -0
  152. package/dist/utils/merge-schema.js +130 -174
  153. package/dist/utils/merge-schema.js.map +1 -0
  154. package/dist/utils/pages/builder.d.ts +80 -76
  155. package/dist/utils/pages/builder.d.ts.map +1 -1
  156. package/dist/utils/pages/builder.js +101 -118
  157. package/dist/utils/pages/builder.js.map +1 -0
  158. package/dist/utils/pages/preset-auto.d.ts +58 -55
  159. package/dist/utils/pages/preset-auto.d.ts.map +1 -1
  160. package/dist/utils/pages/preset-auto.js +124 -137
  161. package/dist/utils/pages/preset-auto.js.map +1 -0
  162. package/dist/utils/pages/to-body.js +21 -18
  163. package/dist/utils/pages/to-body.js.map +1 -0
  164. package/dist/utils/pages/to-static-data.js +48 -40
  165. package/dist/utils/pages/to-static-data.js.map +1 -0
  166. package/dist/utils/pages/to-text.d.ts +43 -41
  167. package/dist/utils/pages/to-text.d.ts.map +1 -1
  168. package/dist/utils/pages/to-text.js +93 -126
  169. package/dist/utils/pages/to-text.js.map +1 -0
  170. package/dist/utils/process-document.d.ts +18 -19
  171. package/dist/utils/process-document.d.ts.map +1 -1
  172. package/dist/utils/process-document.js +43 -54
  173. package/dist/utils/process-document.js.map +1 -0
  174. package/dist/utils/remove-undefined.js +18 -18
  175. package/dist/utils/remove-undefined.js.map +1 -0
  176. package/dist/utils/schema-to-string.js +46 -64
  177. package/dist/utils/schema-to-string.js.map +1 -0
  178. package/dist/utils/schema.d.ts +11 -27
  179. package/dist/utils/schema.d.ts.map +1 -1
  180. package/dist/utils/schema.js +43 -44
  181. package/dist/utils/schema.js.map +1 -0
  182. package/dist/utils/url.js +35 -56
  183. package/dist/utils/url.js.map +1 -0
  184. package/dist/utils/use-query.js +39 -33
  185. package/dist/utils/use-query.js.map +1 -0
  186. package/package.json +35 -34
  187. package/dist/index.d.ts.map +0 -1
  188. package/dist/playground/components/inputs.d.ts +0 -25
  189. package/dist/playground/components/inputs.d.ts.map +0 -1
  190. package/dist/playground/components/oauth-dialog.d.ts +0 -13
  191. package/dist/playground/components/oauth-dialog.d.ts.map +0 -1
  192. package/dist/playground/components/server-select.d.ts +0 -3
  193. package/dist/playground/components/server-select.d.ts.map +0 -1
  194. package/dist/playground/get-default-values.d.ts +0 -3
  195. package/dist/playground/get-default-values.d.ts.map +0 -1
  196. package/dist/playground/lazy.d.ts +0 -2
  197. package/dist/playground/lazy.d.ts.map +0 -1
  198. package/dist/playground/status-info.d.ts +0 -8
  199. package/dist/playground/status-info.d.ts.map +0 -1
  200. package/dist/requests/generators/csharp.d.ts +0 -3
  201. package/dist/requests/generators/csharp.d.ts.map +0 -1
  202. package/dist/requests/generators/curl.d.ts +0 -3
  203. package/dist/requests/generators/curl.d.ts.map +0 -1
  204. package/dist/requests/generators/go.d.ts +0 -3
  205. package/dist/requests/generators/go.d.ts.map +0 -1
  206. package/dist/requests/generators/index.d.ts +0 -3
  207. package/dist/requests/generators/index.d.ts.map +0 -1
  208. package/dist/requests/generators/java.d.ts +0 -3
  209. package/dist/requests/generators/java.d.ts.map +0 -1
  210. package/dist/requests/generators/javascript.d.ts +0 -3
  211. package/dist/requests/generators/javascript.d.ts.map +0 -1
  212. package/dist/requests/generators/python.d.ts +0 -3
  213. package/dist/requests/generators/python.d.ts.map +0 -1
  214. package/dist/requests/media/resolve-adapter.d.ts +0 -19
  215. package/dist/requests/media/resolve-adapter.d.ts.map +0 -1
  216. package/dist/requests/string-utils.d.ts +0 -7
  217. package/dist/requests/string-utils.d.ts.map +0 -1
  218. package/dist/requests/to-python-object.d.ts +0 -2
  219. package/dist/requests/to-python-object.d.ts.map +0 -1
  220. package/dist/requests/types.js +0 -1
  221. package/dist/scalar/client.d.ts +0 -7
  222. package/dist/scalar/client.d.ts.map +0 -1
  223. package/dist/server/index.d.ts.map +0 -1
  224. package/dist/types.js +0 -1
  225. package/dist/ui/client/storage-key.d.ts +0 -9
  226. package/dist/ui/client/storage-key.d.ts.map +0 -1
  227. package/dist/ui/components/accordion.d.ts +0 -8
  228. package/dist/ui/components/accordion.d.ts.map +0 -1
  229. package/dist/ui/components/dialog.d.ts +0 -20
  230. package/dist/ui/components/dialog.d.ts.map +0 -1
  231. package/dist/ui/components/input.d.ts +0 -6
  232. package/dist/ui/components/input.d.ts.map +0 -1
  233. package/dist/ui/components/method-label.d.ts +0 -10
  234. package/dist/ui/components/method-label.d.ts.map +0 -1
  235. package/dist/ui/components/select.d.ts +0 -14
  236. package/dist/ui/components/select.d.ts.map +0 -1
  237. package/dist/ui/contexts/api.d.ts +0 -33
  238. package/dist/ui/contexts/api.d.ts.map +0 -1
  239. package/dist/ui/contexts/api.lazy.d.ts +0 -2
  240. package/dist/ui/contexts/api.lazy.d.ts.map +0 -1
  241. package/dist/ui/icons.d.ts +0 -49
  242. package/dist/ui/icons.d.ts.map +0 -1
  243. package/dist/ui/icons.js +0 -281
  244. package/dist/ui/index.d.ts.map +0 -1
  245. package/dist/ui/operation/client.d.ts +0 -19
  246. package/dist/ui/operation/client.d.ts.map +0 -1
  247. package/dist/ui/operation/index.d.ts +0 -12
  248. package/dist/ui/operation/index.d.ts.map +0 -1
  249. package/dist/ui/operation/usage-tabs/client.d.ts +0 -23
  250. package/dist/ui/operation/usage-tabs/client.d.ts.map +0 -1
  251. package/dist/ui/operation/usage-tabs/lazy.d.ts +0 -4
  252. package/dist/ui/operation/usage-tabs/lazy.d.ts.map +0 -1
  253. package/dist/ui/schema/lazy.d.ts +0 -2
  254. package/dist/ui/schema/lazy.d.ts.map +0 -1
  255. package/dist/utils/cn.d.ts +0 -2
  256. package/dist/utils/cn.d.ts.map +0 -1
  257. package/dist/utils/deep-equal.d.ts +0 -2
  258. package/dist/utils/deep-equal.d.ts.map +0 -1
  259. package/dist/utils/get-typescript-schema.d.ts +0 -4
  260. package/dist/utils/get-typescript-schema.d.ts.map +0 -1
  261. package/dist/utils/id-to-title.d.ts +0 -2
  262. package/dist/utils/id-to-title.d.ts.map +0 -1
  263. package/dist/utils/lazy.d.ts +0 -5
  264. package/dist/utils/lazy.d.ts.map +0 -1
  265. package/dist/utils/merge-schema.d.ts +0 -7
  266. package/dist/utils/merge-schema.d.ts.map +0 -1
  267. package/dist/utils/pages/to-body.d.ts +0 -4
  268. package/dist/utils/pages/to-body.d.ts.map +0 -1
  269. package/dist/utils/pages/to-static-data.d.ts +0 -10
  270. package/dist/utils/pages/to-static-data.d.ts.map +0 -1
  271. package/dist/utils/remove-undefined.d.ts +0 -2
  272. package/dist/utils/remove-undefined.d.ts.map +0 -1
  273. package/dist/utils/schema-to-string.d.ts +0 -8
  274. package/dist/utils/schema-to-string.d.ts.map +0 -1
  275. package/dist/utils/url.d.ts +0 -11
  276. package/dist/utils/url.d.ts.map +0 -1
  277. package/dist/utils/use-query.d.ts +0 -8
  278. package/dist/utils/use-query.d.ts.map +0 -1
@@ -1,186 +1,409 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { useState, } from 'react';
4
- import { ChevronDown, Plus, Trash2, X } from '../../ui/icons.js';
5
- import { useController, useFieldArray, useFormContext } from 'react-hook-form';
6
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../../ui/components/select.js';
7
- import { Input, labelVariants } from '../../ui/components/input.js';
8
- import { getDefaultValue } from '../get-default-values.js';
9
- import { cn } from '../../utils/cn.js';
10
- import { buttonVariants } from 'fumadocs-ui/components/ui/button';
11
- import { FormatFlags, schemaToString } from '../../utils/schema-to-string.js';
12
- import { anyFields, useFieldInfo, useResolvedSchema, useSchemaScope, } from '../../playground/schema.js';
2
+
3
+ import { cn } from "../../utils/cn.js";
4
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/components/select.js";
5
+ import { Input, labelVariants } from "../../ui/components/input.js";
6
+ import { getDefaultValue } from "../get-default-values.js";
7
+ import { FormatFlags, schemaToString } from "../../utils/schema-to-string.js";
8
+ import { anyFields, useFieldInfo, useResolvedSchema, useSchemaScope } from "../schema.js";
9
+ import { useState } from "react";
10
+ import { useController, useFieldArray, useFormContext } from "react-hook-form";
11
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
+ import { ChevronDown, Plus, Trash2, X } from "lucide-react";
13
+ import { buttonVariants } from "fumadocs-ui/components/ui/button";
14
+
15
+ //#region src/playground/components/inputs.tsx
13
16
  function FieldLabel(props) {
14
- return (_jsx("label", { ...props, className: cn('w-full inline-flex items-center gap-0.5', props.className), children: props.children }));
17
+ return /* @__PURE__ */ jsx("label", {
18
+ ...props,
19
+ className: cn("w-full inline-flex items-center gap-0.5", props.className),
20
+ children: props.children
21
+ });
15
22
  }
16
23
  function FieldLabelName({ required = false, ...props }) {
17
- return (_jsxs("span", { ...props, className: cn(labelVariants(), 'font-mono me-auto', props.className), children: [props.children, required && _jsx("span", { className: "text-red-400/80 mx-1", children: "*" })] }));
24
+ return /* @__PURE__ */ jsxs("span", {
25
+ ...props,
26
+ className: cn(labelVariants(), "font-mono me-auto", props.className),
27
+ children: [props.children, required && /* @__PURE__ */ jsx("span", {
28
+ className: "text-red-400/80 mx-1",
29
+ children: "*"
30
+ })]
31
+ });
18
32
  }
19
33
  function FieldLabelType(props) {
20
- return (_jsx("code", { ...props, className: cn('text-xs text-fd-muted-foreground', props.className), children: props.children }));
34
+ return /* @__PURE__ */ jsx("code", {
35
+ ...props,
36
+ className: cn("text-xs text-fd-muted-foreground", props.className),
37
+ children: props.children
38
+ });
21
39
  }
22
- export function ObjectInput({ field: _field, fieldName, ...props }) {
23
- const field = useResolvedSchema(_field);
24
- return (_jsxs("div", { ...props, className: cn('grid grid-cols-1 gap-4 @md:grid-cols-2', props.className), children: [Object.entries(field.properties ?? {}).map(([key, child]) => (_jsx(FieldSet, { name: key, field: child, fieldName: `${fieldName}.${key}`, isRequired: field.required?.includes(key) }, key))), (field.additionalProperties || field.patternProperties) && (_jsx(DynamicProperties, { fieldName: fieldName, filterKey: (v) => !field.properties || !Object.keys(field.properties).includes(v), getType: (key) => {
25
- for (const pattern in field.patternProperties) {
26
- if (key.match(RegExp(pattern))) {
27
- return field.patternProperties[pattern];
28
- }
29
- }
30
- if (field.additionalProperties)
31
- return field.additionalProperties;
32
- return anyFields;
33
- } }))] }));
40
+ function ObjectInput({ field: _field, fieldName, ...props }) {
41
+ const field = useResolvedSchema(_field);
42
+ return /* @__PURE__ */ jsxs("div", {
43
+ ...props,
44
+ className: cn("grid grid-cols-1 gap-4 @md:grid-cols-2", props.className),
45
+ children: [Object.entries(field.properties ?? {}).map(([key, child]) => /* @__PURE__ */ jsx(FieldSet, {
46
+ name: key,
47
+ field: child,
48
+ fieldName: `${fieldName}.${key}`,
49
+ isRequired: field.required?.includes(key)
50
+ }, key)), (field.additionalProperties || field.patternProperties) && /* @__PURE__ */ jsx(DynamicProperties, {
51
+ fieldName,
52
+ filterKey: (v) => !field.properties || !Object.keys(field.properties).includes(v),
53
+ getType: (key) => {
54
+ for (const pattern in field.patternProperties) if (key.match(RegExp(pattern))) return field.patternProperties[pattern];
55
+ if (field.additionalProperties) return field.additionalProperties;
56
+ return anyFields;
57
+ }
58
+ })]
59
+ });
34
60
  }
35
- export function JsonInput({ fieldName }) {
36
- const controller = useController({
37
- name: fieldName,
38
- });
39
- const [error, setError] = useState(null);
40
- const [value, setValue] = useState(() => JSON.stringify(controller.field.value, null, 2));
41
- return (_jsxs("div", { className: "flex flex-col bg-fd-secondary text-fd-secondary-foreground overflow-hidden border rounded-lg", children: [_jsx("textarea", { ...controller.field, value: value, className: "p-2 h-[240px] text-sm font-mono resize-none focus-visible:outline-none", onChange: (v) => {
42
- setValue(v.target.value);
43
- try {
44
- controller.field.onChange(JSON.parse(v.target.value));
45
- setError(null);
46
- }
47
- catch (e) {
48
- if (e instanceof Error)
49
- setError(e.message);
50
- }
51
- } }), _jsx("p", { className: "p-2 text-xs font-mono border-t text-red-400 empty:hidden", children: error })] }));
61
+ function JsonInput({ fieldName }) {
62
+ const controller = useController({ name: fieldName });
63
+ const [error, setError] = useState(null);
64
+ const [value, setValue] = useState(() => JSON.stringify(controller.field.value, null, 2));
65
+ return /* @__PURE__ */ jsxs("div", {
66
+ className: "flex flex-col bg-fd-secondary text-fd-secondary-foreground overflow-hidden border rounded-lg",
67
+ children: [/* @__PURE__ */ jsx("textarea", {
68
+ ...controller.field,
69
+ value,
70
+ className: "p-2 h-[240px] text-sm font-mono resize-none focus-visible:outline-none",
71
+ onChange: (v) => {
72
+ setValue(v.target.value);
73
+ try {
74
+ controller.field.onChange(JSON.parse(v.target.value));
75
+ setError(null);
76
+ } catch (e) {
77
+ if (e instanceof Error) setError(e.message);
78
+ }
79
+ }
80
+ }), /* @__PURE__ */ jsx("p", {
81
+ className: "p-2 text-xs font-mono border-t text-red-400 empty:hidden",
82
+ children: error
83
+ })]
84
+ });
52
85
  }
53
- function DynamicProperties({ fieldName, filterKey = () => true, getType = () => anyFields, }) {
54
- const { control, setValue, getValues } = useFormContext();
55
- const [nextName, setNextName] = useState('');
56
- const [properties, setProperties] = useState(() => {
57
- const value = getValues(fieldName);
58
- if (value)
59
- return Object.keys(value).filter(filterKey);
60
- return [];
61
- });
62
- const onAppend = () => {
63
- const name = nextName.trim();
64
- if (name.length === 0)
65
- return;
66
- setProperties((p) => {
67
- if (p.includes(name) || !filterKey(name))
68
- return p;
69
- const type = getType(name);
70
- setValue(`${fieldName}.${name}`, getDefaultValue(type));
71
- setNextName('');
72
- return [...p, name];
73
- });
74
- };
75
- return (_jsxs(_Fragment, { children: [properties.map((item) => {
76
- const type = getType(item);
77
- return (_jsx(FieldSet, { name: item, field: type, fieldName: `${fieldName}.${item}`, toolbar: _jsx("button", { type: "button", "aria-label": "Remove Item", className: cn(buttonVariants({
78
- color: 'outline',
79
- size: 'icon-xs',
80
- })), onClick: () => {
81
- setProperties((p) => p.filter((prop) => prop !== item));
82
- control.unregister(`${fieldName}.${item}`);
83
- }, children: _jsx(Trash2, {}) }) }, item));
84
- }), _jsxs("div", { className: "flex gap-2 col-span-full", children: [_jsx(Input, { value: nextName, placeholder: "Enter Property Name", onChange: (e) => setNextName(e.target.value), onKeyDown: (e) => {
85
- if (e.key === 'Enter') {
86
- onAppend();
87
- e.preventDefault();
88
- }
89
- } }), _jsx("button", { type: "button", className: cn(buttonVariants({ color: 'secondary', size: 'sm' }), 'px-4'), onClick: onAppend, children: "New" })] })] }));
86
+ function DynamicProperties({ fieldName, filterKey = () => true, getType = () => anyFields }) {
87
+ const { control, setValue, getValues } = useFormContext();
88
+ const [nextName, setNextName] = useState("");
89
+ const [properties, setProperties] = useState(() => {
90
+ const value = getValues(fieldName);
91
+ if (value) return Object.keys(value).filter(filterKey);
92
+ return [];
93
+ });
94
+ const onAppend = () => {
95
+ const name = nextName.trim();
96
+ if (name.length === 0) return;
97
+ setProperties((p) => {
98
+ if (p.includes(name) || !filterKey(name)) return p;
99
+ const type = getType(name);
100
+ setValue(`${fieldName}.${name}`, getDefaultValue(type));
101
+ setNextName("");
102
+ return [...p, name];
103
+ });
104
+ };
105
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [properties.map((item) => {
106
+ return /* @__PURE__ */ jsx(FieldSet, {
107
+ name: item,
108
+ field: getType(item),
109
+ fieldName: `${fieldName}.${item}`,
110
+ toolbar: /* @__PURE__ */ jsx("button", {
111
+ type: "button",
112
+ "aria-label": "Remove Item",
113
+ className: cn(buttonVariants({
114
+ color: "outline",
115
+ size: "icon-xs"
116
+ })),
117
+ onClick: () => {
118
+ setProperties((p) => p.filter((prop) => prop !== item));
119
+ control.unregister(`${fieldName}.${item}`);
120
+ },
121
+ children: /* @__PURE__ */ jsx(Trash2, {})
122
+ })
123
+ }, item);
124
+ }), /* @__PURE__ */ jsxs("div", {
125
+ className: "flex gap-2 col-span-full",
126
+ children: [/* @__PURE__ */ jsx(Input, {
127
+ value: nextName,
128
+ placeholder: "Enter Property Name",
129
+ onChange: (e) => setNextName(e.target.value),
130
+ onKeyDown: (e) => {
131
+ if (e.key === "Enter") {
132
+ onAppend();
133
+ e.preventDefault();
134
+ }
135
+ }
136
+ }), /* @__PURE__ */ jsx("button", {
137
+ type: "button",
138
+ className: cn(buttonVariants({
139
+ color: "secondary",
140
+ size: "sm"
141
+ }), "px-4"),
142
+ onClick: onAppend,
143
+ children: "New"
144
+ })]
145
+ })] });
90
146
  }
91
- export function FieldInput({ field, fieldName, isRequired, ...props }) {
92
- const form = useFormContext();
93
- const { field: { value, onChange, ...restField }, fieldState, } = useController({
94
- control: form.control,
95
- name: fieldName,
96
- });
97
- if (field.type === 'null')
98
- return;
99
- if (field.type === 'string' && field.format === 'binary') {
100
- return (_jsxs("div", { ...props, children: [_jsx("label", { htmlFor: fieldName, className: cn(buttonVariants({
101
- color: 'secondary',
102
- className: 'w-full h-9 gap-2 truncate',
103
- })), children: value instanceof File ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-fd-muted-foreground text-xs", children: "Selected" }), _jsx("span", { className: "truncate w-0 flex-1 text-end", children: value.name })] })) : (_jsx("span", { className: "text-fd-muted-foreground", children: "Upload" })) }), _jsx("input", { id: fieldName, type: "file", multiple: false, onChange: (e) => {
104
- if (!e.target.files)
105
- return;
106
- onChange(e.target.files.item(0));
107
- }, hidden: true, ...restField })] }));
108
- }
109
- if (field.type === 'boolean') {
110
- return (_jsxs(Select, { value: String(value), onValueChange: (value) => onChange(value === 'undefined' ? undefined : value === 'true'), disabled: restField.disabled, children: [_jsx(SelectTrigger, { id: fieldName, className: props.className, ...restField, children: _jsx(SelectValue, {}) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "true", children: "True" }), _jsx(SelectItem, { value: "false", children: "False" }), !isRequired && _jsx(SelectItem, { value: "undefined", children: "Unset" })] })] }));
111
- }
112
- const isNumber = field.type === 'integer' || field.type === 'number';
113
- return (_jsxs("div", { ...props, className: cn('flex flex-row gap-2', props.className), children: [_jsx(Input, { id: fieldName, placeholder: "Enter value", type: isNumber ? 'number' : 'text', step: field.type === 'integer' ? 1 : undefined, value: value ?? '', onChange: (e) => {
114
- if (isNumber && !Number.isNaN(e.target.valueAsNumber)) {
115
- onChange(e.target.valueAsNumber);
116
- }
117
- else if (!isNumber) {
118
- onChange(e.target.value);
119
- }
120
- }, ...restField }), fieldState.isDirty && (_jsx("button", { type: "button",
121
- // TODO: `react-hook-form` doesn't support setting a value to `undefined` (aka remove the value), if there's a default value defined.
122
- // the default value is kept by `react-hook-form` internally, we cannot manipulate it.
123
- // hence, we can only support resetting to the default value.
124
- // perhaps when we migrate to Tanstack Form, we can reconsider this.
125
- onClick: () => form.resetField(fieldName), className: "text-fd-muted-foreground", children: _jsx(X, { className: "size-4" }) }))] }));
147
+ function FieldInput({ field, fieldName, isRequired, ...props }) {
148
+ const form = useFormContext();
149
+ const { field: { value, onChange, ...restField }, fieldState } = useController({
150
+ control: form.control,
151
+ name: fieldName
152
+ });
153
+ if (field.type === "null") return;
154
+ if (field.type === "string" && field.format === "binary") return /* @__PURE__ */ jsxs("div", {
155
+ ...props,
156
+ children: [/* @__PURE__ */ jsx("label", {
157
+ htmlFor: fieldName,
158
+ className: cn(buttonVariants({
159
+ color: "secondary",
160
+ className: "w-full h-9 gap-2 truncate"
161
+ })),
162
+ children: value instanceof File ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
163
+ className: "text-fd-muted-foreground text-xs",
164
+ children: "Selected"
165
+ }), /* @__PURE__ */ jsx("span", {
166
+ className: "truncate w-0 flex-1 text-end",
167
+ children: value.name
168
+ })] }) : /* @__PURE__ */ jsx("span", {
169
+ className: "text-fd-muted-foreground",
170
+ children: "Upload"
171
+ })
172
+ }), /* @__PURE__ */ jsx("input", {
173
+ id: fieldName,
174
+ type: "file",
175
+ multiple: false,
176
+ onChange: (e) => {
177
+ if (!e.target.files) return;
178
+ onChange(e.target.files.item(0));
179
+ },
180
+ hidden: true,
181
+ ...restField
182
+ })]
183
+ });
184
+ if (field.type === "boolean") return /* @__PURE__ */ jsxs(Select, {
185
+ value: String(value),
186
+ onValueChange: (value$1) => onChange(value$1 === "undefined" ? void 0 : value$1 === "true"),
187
+ disabled: restField.disabled,
188
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
189
+ id: fieldName,
190
+ className: props.className,
191
+ ...restField,
192
+ children: /* @__PURE__ */ jsx(SelectValue, {})
193
+ }), /* @__PURE__ */ jsxs(SelectContent, { children: [
194
+ /* @__PURE__ */ jsx(SelectItem, {
195
+ value: "true",
196
+ children: "True"
197
+ }),
198
+ /* @__PURE__ */ jsx(SelectItem, {
199
+ value: "false",
200
+ children: "False"
201
+ }),
202
+ !isRequired && /* @__PURE__ */ jsx(SelectItem, {
203
+ value: "undefined",
204
+ children: "Unset"
205
+ })
206
+ ] })]
207
+ });
208
+ const isNumber = field.type === "integer" || field.type === "number";
209
+ return /* @__PURE__ */ jsxs("div", {
210
+ ...props,
211
+ className: cn("flex flex-row gap-2", props.className),
212
+ children: [/* @__PURE__ */ jsx(Input, {
213
+ id: fieldName,
214
+ placeholder: "Enter value",
215
+ type: isNumber ? "number" : "text",
216
+ step: field.type === "integer" ? 1 : void 0,
217
+ value: value ?? "",
218
+ onChange: (e) => {
219
+ if (isNumber && !Number.isNaN(e.target.valueAsNumber)) onChange(e.target.valueAsNumber);
220
+ else if (!isNumber) onChange(e.target.value);
221
+ },
222
+ ...restField
223
+ }), fieldState.isDirty && /* @__PURE__ */ jsx("button", {
224
+ type: "button",
225
+ onClick: () => form.resetField(fieldName),
226
+ className: "text-fd-muted-foreground",
227
+ children: /* @__PURE__ */ jsx(X, { className: "size-4" })
228
+ })]
229
+ });
126
230
  }
127
- export function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth = 0, slotType, collapsible = true, ...props }) {
128
- const { readOnly, writeOnly } = useSchemaScope();
129
- const field = useResolvedSchema(_field);
130
- const [show, setShow] = useState(!collapsible);
131
- const { info, updateInfo } = useFieldInfo(fieldName, field, depth);
132
- if (_field === false)
133
- return;
134
- if (field.readOnly && !readOnly)
135
- return;
136
- if (field.writeOnly && !writeOnly)
137
- return;
138
- if (info.unionField) {
139
- const union = field[info.unionField];
140
- const showSelect = union.length > 1;
141
- return (_jsx(FieldSet, { ...props, name: name, fieldName: fieldName, isRequired: isRequired, field: union[info.oneOf], depth: depth + 1, slotType: showSelect ? false : slotType, toolbar: _jsxs(_Fragment, { children: [showSelect && (_jsx("select", { className: "text-xs font-mono", value: info.oneOf, onChange: (e) => {
142
- updateInfo({
143
- oneOf: Number(e.target.value),
144
- });
145
- }, children: union.map((item, i) => (_jsx("option", { value: i, className: "bg-fd-popover text-fd-popover-foreground", children: schemaToString(item, undefined, FormatFlags.UseAlias) }, i))) })), toolbar] }) }));
146
- }
147
- if (Array.isArray(field.type)) {
148
- const showSelect = field.type.length > 1;
149
- return (_jsx(FieldSet, { ...props, name: name, fieldName: fieldName, isRequired: isRequired, field: {
150
- ...field,
151
- type: info.selectedType,
152
- }, depth: depth + 1, slotType: showSelect ? false : slotType, toolbar: _jsxs(_Fragment, { children: [showSelect && (_jsx("select", { className: "text-xs font-mono", value: info.selectedType, onChange: (e) => {
153
- updateInfo({
154
- selectedType: e.target.value,
155
- });
156
- }, children: field.type.map((item) => (_jsx("option", { value: item, className: "bg-fd-popover text-fd-popover-foreground", children: item }, item))) })), toolbar] }) }));
157
- }
158
- const showBn = collapsible && (_jsx("button", { type: "button", onClick: () => setShow((prev) => !prev), className: cn(buttonVariants({
159
- size: 'icon-xs',
160
- color: 'ghost',
161
- className: 'text-fd-muted-foreground -ms-1',
162
- })), children: _jsx(ChevronDown, { className: cn(show && 'rotate-180') }) }));
163
- if (field.type === 'object' || info.intersection) {
164
- return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5 col-span-full @container', props.className), children: [_jsxs(FieldLabel, { htmlFor: fieldName, children: [showBn, _jsx(FieldLabelName, { required: isRequired, children: name }), slotType ?? _jsx(FieldLabelType, { children: schemaToString(field) }), toolbar] }), show && (_jsx(ObjectInput, { field: info.intersection?.merged ?? field, fieldName: fieldName, ...props, className: cn('rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm', props.className) }))] }));
165
- }
166
- if (field.type === 'array') {
167
- return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5 col-span-full', props.className), children: [_jsxs(FieldLabel, { htmlFor: fieldName, children: [showBn, _jsx(FieldLabelName, { required: isRequired, children: name }), slotType ?? _jsx(FieldLabelType, { children: schemaToString(field) }), toolbar] }), show && (_jsx(ArrayInput, { fieldName: fieldName, items: field.items ?? anyFields, ...props, className: cn('rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm', props.className) }))] }));
168
- }
169
- return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5', props.className), children: [_jsxs(FieldLabel, { htmlFor: fieldName, children: [_jsx(FieldLabelName, { required: isRequired, children: name }), slotType ?? _jsx(FieldLabelType, { children: schemaToString(field) }), toolbar] }), _jsx(FieldInput, { field: field, fieldName: fieldName, isRequired: isRequired })] }));
231
+ function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth = 0, slotType, collapsible = true, ...props }) {
232
+ const { readOnly, writeOnly } = useSchemaScope();
233
+ const field = useResolvedSchema(_field);
234
+ const [show, setShow] = useState(!collapsible);
235
+ const { info, updateInfo } = useFieldInfo(fieldName, field, depth);
236
+ if (_field === false) return;
237
+ if (field.readOnly && !readOnly) return;
238
+ if (field.writeOnly && !writeOnly) return;
239
+ if (info.unionField) {
240
+ const union = field[info.unionField];
241
+ const showSelect = union.length > 1;
242
+ return /* @__PURE__ */ jsx(FieldSet, {
243
+ ...props,
244
+ name,
245
+ fieldName,
246
+ isRequired,
247
+ field: union[info.oneOf],
248
+ depth: depth + 1,
249
+ slotType: showSelect ? false : slotType,
250
+ toolbar: /* @__PURE__ */ jsxs(Fragment$1, { children: [showSelect && /* @__PURE__ */ jsx("select", {
251
+ className: "text-xs font-mono",
252
+ value: info.oneOf,
253
+ onChange: (e) => {
254
+ updateInfo({ oneOf: Number(e.target.value) });
255
+ },
256
+ children: union.map((item, i) => /* @__PURE__ */ jsx("option", {
257
+ value: i,
258
+ className: "bg-fd-popover text-fd-popover-foreground",
259
+ children: schemaToString(item, void 0, FormatFlags.UseAlias)
260
+ }, i))
261
+ }), toolbar] })
262
+ });
263
+ }
264
+ if (Array.isArray(field.type)) {
265
+ const showSelect = field.type.length > 1;
266
+ return /* @__PURE__ */ jsx(FieldSet, {
267
+ ...props,
268
+ name,
269
+ fieldName,
270
+ isRequired,
271
+ field: {
272
+ ...field,
273
+ type: info.selectedType
274
+ },
275
+ depth: depth + 1,
276
+ slotType: showSelect ? false : slotType,
277
+ toolbar: /* @__PURE__ */ jsxs(Fragment$1, { children: [showSelect && /* @__PURE__ */ jsx("select", {
278
+ className: "text-xs font-mono",
279
+ value: info.selectedType,
280
+ onChange: (e) => {
281
+ updateInfo({ selectedType: e.target.value });
282
+ },
283
+ children: field.type.map((item) => /* @__PURE__ */ jsx("option", {
284
+ value: item,
285
+ className: "bg-fd-popover text-fd-popover-foreground",
286
+ children: item
287
+ }, item))
288
+ }), toolbar] })
289
+ });
290
+ }
291
+ const showBn = collapsible && /* @__PURE__ */ jsx("button", {
292
+ type: "button",
293
+ onClick: () => setShow((prev) => !prev),
294
+ className: cn(buttonVariants({
295
+ size: "icon-xs",
296
+ color: "ghost",
297
+ className: "text-fd-muted-foreground -ms-1"
298
+ })),
299
+ children: /* @__PURE__ */ jsx(ChevronDown, { className: cn(show && "rotate-180") })
300
+ });
301
+ if (field.type === "object" || info.intersection) return /* @__PURE__ */ jsxs("fieldset", {
302
+ ...props,
303
+ className: cn("flex flex-col gap-1.5 col-span-full @container", props.className),
304
+ children: [/* @__PURE__ */ jsxs(FieldLabel, {
305
+ htmlFor: fieldName,
306
+ children: [
307
+ showBn,
308
+ /* @__PURE__ */ jsx(FieldLabelName, {
309
+ required: isRequired,
310
+ children: name
311
+ }),
312
+ slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: schemaToString(field) }),
313
+ toolbar
314
+ ]
315
+ }), show && /* @__PURE__ */ jsx(ObjectInput, {
316
+ field: info.intersection?.merged ?? field,
317
+ fieldName,
318
+ ...props,
319
+ className: cn("rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm", props.className)
320
+ })]
321
+ });
322
+ if (field.type === "array") return /* @__PURE__ */ jsxs("fieldset", {
323
+ ...props,
324
+ className: cn("flex flex-col gap-1.5 col-span-full", props.className),
325
+ children: [/* @__PURE__ */ jsxs(FieldLabel, {
326
+ htmlFor: fieldName,
327
+ children: [
328
+ showBn,
329
+ /* @__PURE__ */ jsx(FieldLabelName, {
330
+ required: isRequired,
331
+ children: name
332
+ }),
333
+ slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: schemaToString(field) }),
334
+ toolbar
335
+ ]
336
+ }), show && /* @__PURE__ */ jsx(ArrayInput, {
337
+ fieldName,
338
+ items: field.items ?? anyFields,
339
+ ...props,
340
+ className: cn("rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm", props.className)
341
+ })]
342
+ });
343
+ return /* @__PURE__ */ jsxs("fieldset", {
344
+ ...props,
345
+ className: cn("flex flex-col gap-1.5", props.className),
346
+ children: [/* @__PURE__ */ jsxs(FieldLabel, {
347
+ htmlFor: fieldName,
348
+ children: [
349
+ /* @__PURE__ */ jsx(FieldLabelName, {
350
+ required: isRequired,
351
+ children: name
352
+ }),
353
+ slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: schemaToString(field) }),
354
+ toolbar
355
+ ]
356
+ }), /* @__PURE__ */ jsx(FieldInput, {
357
+ field,
358
+ fieldName,
359
+ isRequired
360
+ })]
361
+ });
170
362
  }
171
363
  function ArrayInput({ fieldName, items, ...props }) {
172
- const name = fieldName.split('.').at(-1) ?? '';
173
- const { fields, append, remove } = useFieldArray({
174
- name: fieldName,
175
- });
176
- return (_jsxs("div", { ...props, className: cn('flex flex-col gap-2', props.className), children: [fields.map((item, index) => (_jsx(FieldSet, { name: _jsxs("span", { className: "text-fd-muted-foreground", children: [name, "[", index, "]"] }), field: items, isRequired: true, fieldName: `${fieldName}.${index}`, toolbar: _jsx("button", { type: "button", "aria-label": "Remove Item", className: cn(buttonVariants({
177
- color: 'outline',
178
- size: 'icon-xs',
179
- })), onClick: () => remove(index), children: _jsx(Trash2, {}) }) }, item.id))), _jsxs("button", { type: "button", className: cn(buttonVariants({
180
- color: 'secondary',
181
- className: 'gap-1.5 py-2',
182
- size: 'sm',
183
- })), onClick: () => {
184
- append(getDefaultValue(items));
185
- }, children: [_jsx(Plus, { className: "size-4" }), "New Item"] })] }));
364
+ const name = fieldName.split(".").at(-1) ?? "";
365
+ const { fields, append, remove } = useFieldArray({ name: fieldName });
366
+ return /* @__PURE__ */ jsxs("div", {
367
+ ...props,
368
+ className: cn("flex flex-col gap-2", props.className),
369
+ children: [fields.map((item, index) => /* @__PURE__ */ jsx(FieldSet, {
370
+ name: /* @__PURE__ */ jsxs("span", {
371
+ className: "text-fd-muted-foreground",
372
+ children: [
373
+ name,
374
+ "[",
375
+ index,
376
+ "]"
377
+ ]
378
+ }),
379
+ field: items,
380
+ isRequired: true,
381
+ fieldName: `${fieldName}.${index}`,
382
+ toolbar: /* @__PURE__ */ jsx("button", {
383
+ type: "button",
384
+ "aria-label": "Remove Item",
385
+ className: cn(buttonVariants({
386
+ color: "outline",
387
+ size: "icon-xs"
388
+ })),
389
+ onClick: () => remove(index),
390
+ children: /* @__PURE__ */ jsx(Trash2, {})
391
+ })
392
+ }, item.id)), /* @__PURE__ */ jsxs("button", {
393
+ type: "button",
394
+ className: cn(buttonVariants({
395
+ color: "secondary",
396
+ className: "gap-1.5 py-2",
397
+ size: "sm"
398
+ })),
399
+ onClick: () => {
400
+ append(getDefaultValue(items));
401
+ },
402
+ children: [/* @__PURE__ */ jsx(Plus, { className: "size-4" }), "New Item"]
403
+ })]
404
+ });
186
405
  }
406
+
407
+ //#endregion
408
+ export { FieldInput, FieldSet, JsonInput, ObjectInput };
409
+ //# sourceMappingURL=inputs.js.map