@fumadocs/api-docs 0.0.1

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 (179) hide show
  1. package/LICENSE +21 -0
  2. package/css/generated/shared.css +1 -0
  3. package/css/preset.css +1 -0
  4. package/dist/.translations/index.d.ts +28 -0
  5. package/dist/.translations/keys.js +28 -0
  6. package/dist/_virtual/_rolldown/runtime.js +4 -0
  7. package/dist/auto-anchor/client.d.ts +16 -0
  8. package/dist/auto-anchor/client.js +20 -0
  9. package/dist/auto-anchor/index.d.ts +9 -0
  10. package/dist/auto-anchor/index.js +17 -0
  11. package/dist/codegen.d.ts +38 -0
  12. package/dist/codegen.js +35 -0
  13. package/dist/components/accordion.d.ts +22 -0
  14. package/dist/components/accordion.js +67 -0
  15. package/dist/components/dialog.d.ts +39 -0
  16. package/dist/components/dialog.js +61 -0
  17. package/dist/components/input.d.ts +8 -0
  18. package/dist/components/input.js +17 -0
  19. package/dist/components/playground/inputs.d.ts +50 -0
  20. package/dist/components/playground/inputs.js +426 -0
  21. package/dist/components/playground/schema.d.ts +66 -0
  22. package/dist/components/playground/schema.js +144 -0
  23. package/dist/components/schema/client.d.ts +17 -0
  24. package/dist/components/schema/client.js +415 -0
  25. package/dist/components/schema/index.d.ts +102 -0
  26. package/dist/components/schema/index.js +276 -0
  27. package/dist/components/select-tab.d.ts +33 -0
  28. package/dist/components/select-tab.js +56 -0
  29. package/dist/components/select.d.ts +16 -0
  30. package/dist/components/select.js +72 -0
  31. package/dist/components/spinner.d.ts +7 -0
  32. package/dist/components/spinner.js +14 -0
  33. package/dist/i18n.d.ts +7 -0
  34. package/dist/i18n.js +7 -0
  35. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/bundle.js +239 -0
  36. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/dereference.js +187 -0
  37. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/index.d.ts +157 -0
  38. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/index.js +136 -0
  39. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/normalize-args.js +41 -0
  40. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/options.d.ts +166 -0
  41. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/options.js +124 -0
  42. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parse.js +109 -0
  43. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parsers/binary.js +30 -0
  44. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parsers/json.js +46 -0
  45. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parsers/text.js +36 -0
  46. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parsers/yaml.js +49 -0
  47. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/pointer.d.ts +96 -0
  48. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/pointer.js +242 -0
  49. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/ref.d.ts +190 -0
  50. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/ref.js +247 -0
  51. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/refs.d.ts +134 -0
  52. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/refs.js +210 -0
  53. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolve-external.js +100 -0
  54. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/file.js +41 -0
  55. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js +112 -0
  56. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/types/index.d.ts +133 -0
  57. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/convert-path-to-posix.js +8 -0
  58. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/errors.d.ts +34 -0
  59. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/errors.js +146 -0
  60. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/is-windows.js +5 -0
  61. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/maybe.js +18 -0
  62. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/next.js +11 -0
  63. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/plugins.js +99 -0
  64. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/schema-resources.js +30 -0
  65. package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/url.js +315 -0
  66. package/dist/node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js +108 -0
  67. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js +110 -0
  68. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/code.js +138 -0
  69. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/index.js +674 -0
  70. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/scope.js +141 -0
  71. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/errors.js +102 -0
  72. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/index.js +223 -0
  73. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/names.js +28 -0
  74. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/ref_error.js +18 -0
  75. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/resolve.js +133 -0
  76. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/rules.js +61 -0
  77. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/util.js +146 -0
  78. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/applicability.js +23 -0
  79. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/boolSchema.js +48 -0
  80. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js +172 -0
  81. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/defaults.js +31 -0
  82. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/index.js +433 -0
  83. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/keyword.js +113 -0
  84. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/subschema.js +72 -0
  85. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/core.js +583 -0
  86. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/data.js +18 -0
  87. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/index.js +42 -0
  88. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/applicator.js +50 -0
  89. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/content.js +20 -0
  90. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/core.js +51 -0
  91. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/format-annotation.js +16 -0
  92. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/meta-data.js +36 -0
  93. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/unevaluated.js +19 -0
  94. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.js +85 -0
  95. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/schema.js +59 -0
  96. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/equal.js +12 -0
  97. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/ucs2length.js +25 -0
  98. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/uri.js +12 -0
  99. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/validation_error.js +16 -0
  100. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +57 -0
  101. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +96 -0
  102. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/allOf.js +29 -0
  103. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +16 -0
  104. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/contains.js +89 -0
  105. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +87 -0
  106. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js +16 -0
  107. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/if.js +62 -0
  108. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/index.js +60 -0
  109. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items.js +59 -0
  110. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items2020.js +34 -0
  111. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/not.js +31 -0
  112. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +51 -0
  113. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +61 -0
  114. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +17 -0
  115. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/properties.js +52 -0
  116. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +41 -0
  117. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +17 -0
  118. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/code.js +130 -0
  119. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/id.js +14 -0
  120. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/index.js +22 -0
  121. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/ref.js +112 -0
  122. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/index.js +101 -0
  123. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/types.js +14 -0
  124. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/draft2020.js +35 -0
  125. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js +46 -0
  126. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js +45 -0
  127. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/index.js +22 -0
  128. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js +20 -0
  129. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js +15 -0
  130. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
  131. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/index.js +10 -0
  132. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/metadata.js +23 -0
  133. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/next.js +19 -0
  134. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/index.js +13 -0
  135. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js +46 -0
  136. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js +59 -0
  137. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/const.js +27 -0
  138. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/dependentRequired.js +17 -0
  139. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/enum.js +49 -0
  140. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/index.js +48 -0
  141. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitContains.js +18 -0
  142. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitItems.js +28 -0
  143. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitLength.js +33 -0
  144. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +47 -0
  145. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +28 -0
  146. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +27 -0
  147. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/pattern.js +38 -0
  148. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/required.js +72 -0
  149. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +70 -0
  150. package/dist/node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js +33 -0
  151. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/index.js +236 -0
  152. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/schemes.js +187 -0
  153. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/utils.js +282 -0
  154. package/dist/node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js +78 -0
  155. package/dist/schema/bundle.d.ts +2 -0
  156. package/dist/schema/bundle.js +2 -0
  157. package/dist/schema/dereference.d.ts +19 -0
  158. package/dist/schema/dereference.js +49 -0
  159. package/dist/schema/index.d.ts +21 -0
  160. package/dist/schema/index.js +0 -0
  161. package/dist/schema/merge.d.ts +12 -0
  162. package/dist/schema/merge.js +156 -0
  163. package/dist/schema/ref.d.ts +20 -0
  164. package/dist/schema/ref.js +43 -0
  165. package/dist/schema/resolve-ref.d.ts +4 -0
  166. package/dist/schema/resolve-ref.js +11 -0
  167. package/dist/schema/sample.d.ts +12 -0
  168. package/dist/schema/sample.js +442 -0
  169. package/dist/schema/to-string.d.ts +10 -0
  170. package/dist/schema/to-string.js +51 -0
  171. package/dist/utils/cn.js +2 -0
  172. package/dist/utils/deep-equal.js +21 -0
  173. package/dist/utils/id-to-title.d.ts +4 -0
  174. package/dist/utils/id-to-title.js +12 -0
  175. package/dist/utils/is-plain-object.js +8 -0
  176. package/dist/utils/merge-refs.js +11 -0
  177. package/dist/utils/url.d.ts +5 -0
  178. package/dist/utils/url.js +13 -0
  179. package/package.json +105 -0
@@ -0,0 +1,426 @@
1
+ "use client";
2
+ import { cn } from "../../utils/cn.js";
3
+ import { Input, labelVariants } from "../input.js";
4
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
5
+ import "../../schema/to-string.js";
6
+ import { anyFields, useFieldInfo, useResolvedSchema, useSchemaContext, useSchemaUtils } from "./schema.js";
7
+ import { useState } from "react";
8
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
+ import { ChevronRight, Plus, Trash2, X } from "lucide-react";
10
+ import { buttonVariants } from "fumadocs-ui/components/ui/button";
11
+ import { cva } from "class-variance-authority";
12
+ import { useTranslations } from "@fuma-translate/react";
13
+ import { useArray, useDataEngine, useFieldValue, useObject } from "@fumari/stf";
14
+ import { stringifyFieldKey } from "@fumari/stf/lib/utils";
15
+ //#region src/components/playground/inputs.tsx
16
+ const fieldLabelVariants = cva("w-full inline-flex items-center gap-0.5");
17
+ function FieldLabelType(props) {
18
+ return /* @__PURE__ */ jsx("code", {
19
+ ...props,
20
+ className: cn("text-xs text-fd-muted-foreground", props.className),
21
+ children: props.children
22
+ });
23
+ }
24
+ function ObjectInput({ field: _field, fieldName, ...props }) {
25
+ const { generateDefault } = useSchemaUtils();
26
+ const field = useResolvedSchema(_field);
27
+ const schemaPropKeys = field.properties ? Object.keys(field.properties) : [];
28
+ const { patternProperties = {}, additionalProperties, "x-playground-lazy": isLazy = schemaPropKeys.length > 100 } = field;
29
+ const isDynamic = Object.keys(patternProperties).length > 0 || additionalProperties;
30
+ const [nextName, setNextName] = useState("");
31
+ const { properties, onAppend, onDelete, _objectKeys } = useObject(fieldName, {
32
+ lazy: isLazy,
33
+ defaultValue: () => generateDefault(field),
34
+ properties: field.properties ?? {},
35
+ fallback: additionalProperties,
36
+ patternProperties
37
+ });
38
+ const hiddenProperties = isLazy ? schemaPropKeys.filter((key) => !_objectKeys.includes(key)) : [];
39
+ const t = useTranslations({ note: "playground" });
40
+ return /* @__PURE__ */ jsxs("div", {
41
+ ...props,
42
+ className: cn("grid grid-cols-1 gap-4 @md:grid-cols-2 *:data-[collapsible=true]:order-last", props.className),
43
+ children: [
44
+ isLazy && hiddenProperties.length > 0 && /* @__PURE__ */ jsxs(Select, {
45
+ value: "",
46
+ onValueChange: onAppend,
47
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
48
+ className: "col-span-full",
49
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("Show Property") })
50
+ }), /* @__PURE__ */ jsx(SelectContent, { children: hiddenProperties.map((key) => /* @__PURE__ */ jsx(SelectItem, {
51
+ value: key,
52
+ children: key
53
+ }, key)) })]
54
+ }),
55
+ properties.map((child) => {
56
+ let toolbar = null;
57
+ if (child.kind === "pattern" || child.kind === "fallback") toolbar = /* @__PURE__ */ jsx("button", {
58
+ type: "button",
59
+ "aria-label": t("Remove Item", { note: "aria-label" }),
60
+ className: cn(buttonVariants({
61
+ color: "outline",
62
+ size: "icon-xs"
63
+ })),
64
+ onClick: () => {
65
+ onDelete(child.key);
66
+ },
67
+ children: /* @__PURE__ */ jsx(Trash2, {})
68
+ });
69
+ return /* @__PURE__ */ jsx(FieldSet, {
70
+ name: child.key,
71
+ field: child.info,
72
+ fieldName: child.field,
73
+ isRequired: field.required?.includes(child.key),
74
+ toolbar
75
+ }, child.key);
76
+ }),
77
+ isDynamic && /* @__PURE__ */ jsxs("div", {
78
+ className: "flex gap-2 order-last col-span-full",
79
+ children: [/* @__PURE__ */ jsx(Input, {
80
+ value: nextName,
81
+ placeholder: t("Enter Property Name"),
82
+ onChange: (e) => setNextName(e.target.value),
83
+ onKeyDown: (e) => {
84
+ if (e.key === "Enter") {
85
+ setNextName("");
86
+ onAppend(nextName);
87
+ e.preventDefault();
88
+ }
89
+ }
90
+ }), /* @__PURE__ */ jsx("button", {
91
+ type: "button",
92
+ className: cn(buttonVariants({
93
+ color: "secondary",
94
+ size: "sm"
95
+ }), "px-4"),
96
+ onClick: () => {
97
+ onAppend(nextName);
98
+ setNextName("");
99
+ },
100
+ children: t("New")
101
+ })]
102
+ })
103
+ ]
104
+ });
105
+ }
106
+ function JsonInput({ fieldName }) {
107
+ const engine = useDataEngine();
108
+ const [error, setError] = useState(null);
109
+ const [value, setValue] = useState(() => JSON.stringify(engine.init(fieldName, {}), null, 2));
110
+ return /* @__PURE__ */ jsxs("div", {
111
+ className: "flex flex-col bg-fd-secondary text-fd-secondary-foreground overflow-hidden border rounded-lg",
112
+ children: [/* @__PURE__ */ jsx("textarea", {
113
+ value,
114
+ className: "p-2 h-[240px] text-sm font-mono resize-none focus-visible:outline-none",
115
+ onChange: (v) => {
116
+ setValue(v.target.value);
117
+ try {
118
+ engine.update(fieldName, JSON.parse(v.target.value));
119
+ setError(null);
120
+ } catch (e) {
121
+ if (e instanceof Error) setError(e.message);
122
+ }
123
+ }
124
+ }), /* @__PURE__ */ jsx("p", {
125
+ className: "p-2 text-xs font-mono border-t text-red-400 empty:hidden",
126
+ children: error
127
+ })]
128
+ });
129
+ }
130
+ function FieldInput({ field, fieldName, isRequired, ...props }) {
131
+ const [value, setValue] = useFieldValue(fieldName);
132
+ const id = stringifyFieldKey(fieldName);
133
+ const t = useTranslations({ note: "playground" });
134
+ if (field.type === "null") return;
135
+ if (field.type === "string" && field.format === "binary") return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("label", {
136
+ htmlFor: id,
137
+ className: cn(buttonVariants({
138
+ color: "secondary",
139
+ className: "w-full h-9 gap-2 truncate"
140
+ })),
141
+ children: value instanceof File ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
142
+ className: "text-fd-muted-foreground text-xs",
143
+ children: t("Selected")
144
+ }), /* @__PURE__ */ jsx("span", {
145
+ className: "truncate w-0 flex-1 text-end",
146
+ children: value.name
147
+ })] }) : /* @__PURE__ */ jsx("span", {
148
+ className: "text-fd-muted-foreground",
149
+ children: t("Upload")
150
+ })
151
+ }), /* @__PURE__ */ jsx("input", {
152
+ id,
153
+ type: "file",
154
+ multiple: false,
155
+ onChange: (e) => {
156
+ if (!e.target.files || e.target.files.length === 0) return;
157
+ setValue(e.target.files.item(0));
158
+ },
159
+ hidden: true
160
+ })] });
161
+ if (field.enum && field.enum.length > 0) {
162
+ const idx = field.enum.indexOf(value);
163
+ return /* @__PURE__ */ jsxs(Select, {
164
+ value: idx === -1 && isRequired ? "" : String(idx),
165
+ onValueChange: (v) => setValue(field.enum[Number(v)]),
166
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
167
+ id,
168
+ ...props,
169
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("Select") })
170
+ }), /* @__PURE__ */ jsxs(SelectContent, { children: [field.enum.map((item, i) => /* @__PURE__ */ jsx(SelectItem, {
171
+ value: String(i),
172
+ children: typeof item === "string" ? item : JSON.stringify(item, null, 2)
173
+ }, i)), !isRequired && /* @__PURE__ */ jsx(SelectItem, {
174
+ value: "-1",
175
+ children: /* @__PURE__ */ jsx("span", {
176
+ className: "text-fd-muted-foreground",
177
+ children: t("Unset")
178
+ })
179
+ })] })]
180
+ });
181
+ }
182
+ if (field.type === "boolean") return /* @__PURE__ */ jsxs(Select, {
183
+ value: String(value),
184
+ onValueChange: (value) => setValue(value === "undefined" ? void 0 : value === "true"),
185
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
186
+ id,
187
+ ...props,
188
+ children: /* @__PURE__ */ jsx(SelectValue, {})
189
+ }), /* @__PURE__ */ jsxs(SelectContent, { children: [
190
+ /* @__PURE__ */ jsx(SelectItem, {
191
+ value: "true",
192
+ children: "True"
193
+ }),
194
+ /* @__PURE__ */ jsx(SelectItem, {
195
+ value: "false",
196
+ children: "False"
197
+ }),
198
+ !isRequired && /* @__PURE__ */ jsx(SelectItem, {
199
+ value: "undefined",
200
+ children: /* @__PURE__ */ jsx("span", {
201
+ className: "text-fd-muted-foreground",
202
+ children: t("Unset")
203
+ })
204
+ })
205
+ ] })]
206
+ });
207
+ const isNumber = field.type === "integer" || field.type === "number";
208
+ return /* @__PURE__ */ jsx(Input, {
209
+ id,
210
+ placeholder: t("Enter value"),
211
+ type: isNumber ? "number" : "text",
212
+ step: field.type === "integer" ? 1 : void 0,
213
+ value: String(value ?? ""),
214
+ onChange: (e) => {
215
+ if (isNumber) setValue(Number.isNaN(e.target.valueAsNumber) ? void 0 : e.target.valueAsNumber);
216
+ else if (!isNumber) setValue(e.target.value);
217
+ }
218
+ });
219
+ }
220
+ function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth = 0, slotType, collapsible = true, ...props }) {
221
+ const { readOnly, writeOnly } = useSchemaContext();
222
+ const { generateDefault, schemaToString } = useSchemaUtils();
223
+ const field = useResolvedSchema(_field);
224
+ const [show, setShow] = useState(!collapsible);
225
+ const { info, updateInfo } = useFieldInfo(fieldName, field, depth);
226
+ const id = stringifyFieldKey(fieldName);
227
+ const dataEngine = useDataEngine();
228
+ const [isDefined] = useFieldValue(fieldName, { compute(currentValue) {
229
+ return currentValue !== void 0;
230
+ } });
231
+ if (_field === false) return;
232
+ if (field.readOnly && !readOnly) return;
233
+ if (field.writeOnly && !writeOnly) return;
234
+ if (collapsible && !isDefined && show) setShow(false);
235
+ function renderLabelTrigger(schema = field) {
236
+ if (!collapsible) return renderLabelName();
237
+ return /* @__PURE__ */ jsxs("button", {
238
+ type: "button",
239
+ className: cn(labelVariants(), "inline-flex items-center gap-1 font-mono me-auto"),
240
+ onClick: () => {
241
+ dataEngine.init(fieldName, generateDefault(schema));
242
+ setShow((prev) => !prev);
243
+ },
244
+ children: [
245
+ /* @__PURE__ */ jsx(ChevronRight, { className: cn("size-3.5 text-fd-muted-foreground", show && "rotate-90") }),
246
+ name,
247
+ isRequired && /* @__PURE__ */ jsx("span", {
248
+ className: "text-red-400/80",
249
+ children: "*"
250
+ })
251
+ ]
252
+ });
253
+ }
254
+ function renderLabelName() {
255
+ return /* @__PURE__ */ jsxs("span", {
256
+ className: cn(labelVariants(), "font-mono me-auto"),
257
+ children: [name, isRequired && /* @__PURE__ */ jsx("span", {
258
+ className: "text-red-400/80 mx-1",
259
+ children: "*"
260
+ })]
261
+ });
262
+ }
263
+ function renderUnsetButton() {
264
+ return /* @__PURE__ */ jsx("button", {
265
+ type: "button",
266
+ onClick: () => dataEngine.delete(fieldName),
267
+ className: "text-fd-muted-foreground hover:text-fd-accent-foreground",
268
+ children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
269
+ });
270
+ }
271
+ if (info.unionField && field[info.unionField] && field[info.unionField].length > 0) {
272
+ const union = field[info.unionField];
273
+ const showSelect = union.length > 1;
274
+ return /* @__PURE__ */ jsx(FieldSet, {
275
+ ...props,
276
+ name,
277
+ fieldName,
278
+ isRequired,
279
+ field: union[info.oneOf],
280
+ depth: depth + 1,
281
+ slotType: showSelect ? false : slotType,
282
+ collapsible,
283
+ toolbar: /* @__PURE__ */ jsxs(Fragment$1, { children: [showSelect && /* @__PURE__ */ jsx("select", {
284
+ className: "text-xs font-mono",
285
+ value: info.oneOf,
286
+ onChange: (e) => {
287
+ updateInfo({ oneOf: Number(e.target.value) });
288
+ },
289
+ children: union.map((item, i) => /* @__PURE__ */ jsx("option", {
290
+ value: i,
291
+ className: "bg-fd-popover text-fd-popover-foreground",
292
+ children: schemaToString(item, 1)
293
+ }, i))
294
+ }), toolbar] })
295
+ });
296
+ }
297
+ if (Array.isArray(field.type)) {
298
+ const showSelect = field.type.length > 1;
299
+ return /* @__PURE__ */ jsx(FieldSet, {
300
+ ...props,
301
+ name,
302
+ fieldName,
303
+ isRequired,
304
+ field: {
305
+ ...field,
306
+ type: info.selectedType
307
+ },
308
+ collapsible,
309
+ depth: depth + 1,
310
+ slotType: showSelect ? false : slotType,
311
+ toolbar: /* @__PURE__ */ jsxs(Fragment$1, { children: [showSelect && /* @__PURE__ */ jsx("select", {
312
+ className: "text-xs font-mono",
313
+ value: info.selectedType,
314
+ onChange: (e) => {
315
+ updateInfo({ selectedType: e.target.value });
316
+ },
317
+ children: field.type.map((item) => /* @__PURE__ */ jsx("option", {
318
+ value: item,
319
+ className: "bg-fd-popover text-fd-popover-foreground",
320
+ children: item
321
+ }, item))
322
+ }), toolbar] })
323
+ });
324
+ }
325
+ if (field.type === "object") return /* @__PURE__ */ jsxs("fieldset", {
326
+ ...props,
327
+ "data-collapsible": collapsible,
328
+ className: cn("flex flex-col gap-1.5 col-span-full @container", props.className),
329
+ children: [/* @__PURE__ */ jsxs("div", {
330
+ className: fieldLabelVariants(),
331
+ children: [
332
+ renderLabelTrigger(field),
333
+ slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: schemaToString(field) }),
334
+ toolbar,
335
+ !isRequired && isDefined && renderUnsetButton()
336
+ ]
337
+ }), show && /* @__PURE__ */ jsx(ObjectInput, {
338
+ field,
339
+ fieldName,
340
+ className: "rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm"
341
+ })]
342
+ });
343
+ if (field.type === "array") return /* @__PURE__ */ jsxs("fieldset", {
344
+ ...props,
345
+ "data-collapsible": collapsible,
346
+ className: cn("flex flex-col gap-1.5 col-span-full", props.className),
347
+ children: [/* @__PURE__ */ jsxs("div", {
348
+ className: fieldLabelVariants(),
349
+ children: [
350
+ renderLabelTrigger(),
351
+ slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: schemaToString(field) }),
352
+ toolbar,
353
+ !isRequired && isDefined && renderUnsetButton()
354
+ ]
355
+ }), show && /* @__PURE__ */ jsx(ArrayInput, {
356
+ fieldName,
357
+ items: field.items ?? anyFields,
358
+ className: "rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm"
359
+ })]
360
+ });
361
+ return /* @__PURE__ */ jsxs("fieldset", {
362
+ ...props,
363
+ className: cn("flex flex-col gap-1.5", props.className),
364
+ children: [/* @__PURE__ */ jsxs("label", {
365
+ className: fieldLabelVariants(),
366
+ htmlFor: id,
367
+ children: [
368
+ renderLabelName(),
369
+ slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: schemaToString(field) }),
370
+ toolbar,
371
+ !isRequired && isDefined && renderUnsetButton()
372
+ ]
373
+ }), /* @__PURE__ */ jsx(FieldInput, {
374
+ field,
375
+ fieldName,
376
+ isRequired
377
+ })]
378
+ });
379
+ }
380
+ function ArrayInput({ fieldName, items: itemSchema, ...props }) {
381
+ const name = fieldName.at(-1) ?? "";
382
+ const { generateDefault } = useSchemaUtils();
383
+ const { items, insertItem, removeItem } = useArray(fieldName);
384
+ const t = useTranslations({ note: "playground" });
385
+ return /* @__PURE__ */ jsxs("div", {
386
+ ...props,
387
+ className: cn("flex flex-col gap-2", props.className),
388
+ children: [items.map((item) => /* @__PURE__ */ jsx(FieldSet, {
389
+ name: /* @__PURE__ */ jsxs("span", {
390
+ className: "text-fd-muted-foreground",
391
+ children: [
392
+ name,
393
+ "[",
394
+ item.index,
395
+ "]"
396
+ ]
397
+ }),
398
+ field: itemSchema,
399
+ isRequired: true,
400
+ fieldName: item.field,
401
+ toolbar: /* @__PURE__ */ jsx("button", {
402
+ type: "button",
403
+ "aria-label": t("Remove Item", { note: "aria-label" }),
404
+ className: cn(buttonVariants({
405
+ color: "outline",
406
+ size: "icon-xs"
407
+ })),
408
+ onClick: () => removeItem(item.index),
409
+ children: /* @__PURE__ */ jsx(Trash2, {})
410
+ })
411
+ }, item.index)), /* @__PURE__ */ jsxs("button", {
412
+ type: "button",
413
+ className: cn(buttonVariants({
414
+ color: "secondary",
415
+ className: "gap-1.5 py-2",
416
+ size: "sm"
417
+ })),
418
+ onClick: () => {
419
+ insertItem(generateDefault(itemSchema));
420
+ },
421
+ children: [/* @__PURE__ */ jsx(Plus, { className: "size-4" }), t("New Item")]
422
+ })]
423
+ });
424
+ }
425
+ //#endregion
426
+ export { FieldInput, FieldSet, JsonInput, ObjectInput };
@@ -0,0 +1,66 @@
1
+ import { ParsedSchema } from "../../schema/index.js";
2
+ import { FormatFlags } from "../../schema/to-string.js";
3
+ import { ReactNode } from "react";
4
+ import { FieldKey } from "@fumari/stf";
5
+ import { Ajv2020 } from "/Users/xred/dev/fumadocs/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";
6
+
7
+ //#region src/components/playground/schema.d.ts
8
+ interface SchemaContextType extends SchemaScope {
9
+ ajv: Ajv2020;
10
+ docRoot: Exclude<ParsedSchema, boolean>;
11
+ }
12
+ interface SchemaScope {
13
+ /**
14
+ * show write only fields
15
+ */
16
+ writeOnly: boolean;
17
+ /**
18
+ * show read only fields
19
+ */
20
+ readOnly: boolean;
21
+ }
22
+ type UnionField = 'anyOf' | 'oneOf';
23
+ interface FieldInfo {
24
+ selectedType?: string;
25
+ oneOf: number;
26
+ /**
27
+ * The actual field that represents union members.
28
+ */
29
+ unionField?: UnionField;
30
+ }
31
+ declare const anyFields: {
32
+ type: string[];
33
+ items: true;
34
+ additionalProperties: true;
35
+ };
36
+ declare function SchemaProvider({
37
+ readOnly,
38
+ writeOnly,
39
+ docRoot,
40
+ children
41
+ }: Omit<SchemaContextType, 'ajv'> & {
42
+ children: ReactNode;
43
+ }): import("react").JSX.Element;
44
+ declare function useSchemaContext(): SchemaContextType;
45
+ /**
46
+ * A hook to store dynamic info of a field, such as selected schema of `oneOf`.
47
+ *
48
+ * @param fieldName - field name of form.
49
+ * @param schema - The **resolved** JSON Schema to generate initial values.
50
+ * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
51
+ */
52
+ declare function useFieldInfo(fieldName: FieldKey, schema: Exclude<ParsedSchema, boolean>, depth?: number): {
53
+ info: FieldInfo;
54
+ schema: Exclude<ParsedSchema, boolean>;
55
+ updateInfo: (value: Partial<FieldInfo>) => void;
56
+ };
57
+ declare function useSchemaUtils(): {
58
+ generateDefault(schema: ParsedSchema): unknown;
59
+ schemaToString(value: ParsedSchema, flags?: FormatFlags): string;
60
+ };
61
+ /**
62
+ * dereference & merge `allOf`.
63
+ */
64
+ declare function useResolvedSchema(raw: ParsedSchema): Exclude<ParsedSchema, boolean>;
65
+ //#endregion
66
+ export { FieldInfo, SchemaProvider, SchemaScope, anyFields, useFieldInfo, useResolvedSchema, useSchemaContext, useSchemaUtils };
@@ -0,0 +1,144 @@
1
+ import { dereferenceShallow } from "../../schema/dereference.js";
2
+ import { mergeAllOf } from "../../schema/merge.js";
3
+ import { sample } from "../../schema/sample.js";
4
+ import { schemaToString } from "../../schema/to-string.js";
5
+ import { require__2020 } from "../../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";
6
+ import { createContext, use, useMemo } from "react";
7
+ import { jsx } from "react/jsx-runtime";
8
+ import { useDataEngine, useFieldValue, useNamespace } from "@fumari/stf";
9
+ import { stringifyFieldKey } from "@fumari/stf/lib/utils";
10
+ //#region src/components/playground/schema.tsx
11
+ var import__2020 = require__2020();
12
+ const SchemaContext = createContext(void 0);
13
+ const anyFields = {
14
+ type: [
15
+ "string",
16
+ "number",
17
+ "boolean",
18
+ "array",
19
+ "object"
20
+ ],
21
+ items: true,
22
+ additionalProperties: true
23
+ };
24
+ function SchemaProvider({ readOnly, writeOnly, docRoot, children }) {
25
+ const ajv = useMemo(() => new import__2020.Ajv2020({
26
+ strict: false,
27
+ validateSchema: false,
28
+ validateFormats: false
29
+ }), []);
30
+ return /* @__PURE__ */ jsx(SchemaContext.Provider, {
31
+ value: useMemo(() => ({
32
+ ajv,
33
+ readOnly,
34
+ writeOnly,
35
+ docRoot
36
+ }), [
37
+ docRoot,
38
+ ajv,
39
+ readOnly,
40
+ writeOnly
41
+ ]),
42
+ children
43
+ });
44
+ }
45
+ function useSchemaContext() {
46
+ return use(SchemaContext);
47
+ }
48
+ /**
49
+ * A hook to store dynamic info of a field, such as selected schema of `oneOf`.
50
+ *
51
+ * @param fieldName - field name of form.
52
+ * @param schema - The **resolved** JSON Schema to generate initial values.
53
+ * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
54
+ */
55
+ function useFieldInfo(fieldName, schema, depth = 0) {
56
+ const { docRoot: doc, ajv } = useSchemaContext();
57
+ const engine = useDataEngine();
58
+ const { generateDefault } = useSchemaUtils();
59
+ const [info, setInfo] = useFieldValue([], { stf: useNamespace({
60
+ namespace: `field-info:${depth}:${stringifyFieldKey(fieldName)}`,
61
+ initial() {
62
+ const value = engine.get(fieldName);
63
+ const out = { oneOf: -1 };
64
+ const union = getUnion(schema);
65
+ if (union) {
66
+ const [members, field] = union;
67
+ out.oneOf = members.findIndex((item) => typeof item === "object" && ajv.validate({
68
+ ...doc,
69
+ ...item
70
+ }, value));
71
+ if (out.oneOf === -1) out.oneOf = 0;
72
+ out.unionField = field;
73
+ }
74
+ if (Array.isArray(schema.type)) {
75
+ const types = schema.type;
76
+ out.selectedType = types.find((type) => {
77
+ return ajv.validate({
78
+ ...doc,
79
+ ...schema,
80
+ type
81
+ }, value);
82
+ }) ?? types[0];
83
+ }
84
+ return out;
85
+ }
86
+ }) });
87
+ return {
88
+ info,
89
+ schema,
90
+ updateInfo(value) {
91
+ const updated = {
92
+ ...info,
93
+ ...value
94
+ };
95
+ if (updated.oneOf === info.oneOf && updated.selectedType === info.selectedType) return;
96
+ setInfo(updated);
97
+ let valueSchema = schema;
98
+ if (updated.unionField) valueSchema = schema[updated.unionField][updated.oneOf];
99
+ else if (updated.selectedType) valueSchema = {
100
+ ...schema,
101
+ type: updated.selectedType,
102
+ examples: void 0
103
+ };
104
+ engine.update(fieldName, generateDefault(valueSchema));
105
+ }
106
+ };
107
+ }
108
+ function useSchemaUtils() {
109
+ const { readOnly, docRoot: doc } = useSchemaContext();
110
+ return {
111
+ generateDefault(schema) {
112
+ return sample(schema, {
113
+ skipNonRequired: true,
114
+ skipReadOnly: !readOnly,
115
+ quiet: true
116
+ }, doc);
117
+ },
118
+ schemaToString(value, flags) {
119
+ return schemaToString(value, (raw) => ({
120
+ raw,
121
+ dereferenced: dereferenceShallow(raw, doc)
122
+ }), flags);
123
+ }
124
+ };
125
+ }
126
+ /**
127
+ * dereference & merge `allOf`.
128
+ */
129
+ function useResolvedSchema(raw) {
130
+ const { docRoot: doc } = useSchemaContext();
131
+ return useMemo(() => {
132
+ let out = dereferenceShallow(raw, doc);
133
+ if (typeof out === "object" && out.allOf) out = mergeAllOf(out, { dereference(schema) {
134
+ return dereferenceShallow(schema, doc);
135
+ } });
136
+ return typeof out === "boolean" ? anyFields : out;
137
+ }, [doc, raw]);
138
+ }
139
+ function getUnion(schema) {
140
+ if (schema.anyOf) return [schema.anyOf, "anyOf"];
141
+ if (schema.oneOf) return [schema.oneOf, "oneOf"];
142
+ }
143
+ //#endregion
144
+ export { SchemaProvider, anyFields, useFieldInfo, useResolvedSchema, useSchemaContext, useSchemaUtils };
@@ -0,0 +1,17 @@
1
+ import { SchemaUIGeneratedData } from "./index.js";
2
+
3
+ //#region src/components/schema/client.d.ts
4
+ interface SchemaUIProps {
5
+ name: string;
6
+ required?: boolean;
7
+ as?: 'property' | 'body';
8
+ generated: SchemaUIGeneratedData;
9
+ }
10
+ declare function SchemaUI({
11
+ name,
12
+ required,
13
+ as,
14
+ generated
15
+ }: SchemaUIProps): import("react").JSX.Element;
16
+ //#endregion
17
+ export { SchemaUI, SchemaUIProps };