schema-components 2.0.2 → 2.1.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 (197) hide show
  1. package/README.md +133 -1
  2. package/dist/SchemaComponent-B__6-5-E.d.mts +277 -0
  3. package/dist/SchemaComponent-BxzzsHsK.mjs +668 -0
  4. package/dist/adapter-ktQaheWB.d.mts +213 -0
  5. package/dist/constructorTypes-BdCiMS6e.d.mts +30 -0
  6. package/dist/core/adapter.d.mts +3 -213
  7. package/dist/core/constraintHint.d.mts +1 -1
  8. package/dist/core/constraints.d.mts +2 -2
  9. package/dist/core/contexts.d.mts +71 -0
  10. package/dist/core/contexts.mjs +1 -0
  11. package/dist/core/diagnostics.d.mts +1 -1
  12. package/dist/core/errors.d.mts +1 -1
  13. package/dist/core/fieldOrder.d.mts +1 -1
  14. package/dist/{react → core}/fieldPath.d.mts +2 -2
  15. package/dist/{react → core}/fieldPath.mjs +3 -3
  16. package/dist/core/formats.d.mts +1 -1
  17. package/dist/core/inferValue.d.mts +1 -1
  18. package/dist/core/limits.d.mts +1 -1
  19. package/dist/core/merge.d.mts +1 -1
  20. package/dist/core/normalise.d.mts +2 -2
  21. package/dist/core/ref.d.mts +1 -1
  22. package/dist/core/renderField.d.mts +147 -0
  23. package/dist/core/renderField.mjs +115 -0
  24. package/dist/core/renderer.d.mts +2 -199
  25. package/dist/core/swagger2.d.mts +1 -1
  26. package/dist/core/typeInference.d.mts +1 -982
  27. package/dist/core/types.d.mts +1 -1
  28. package/dist/core/unionMatch.d.mts +1 -1
  29. package/dist/core/version.d.mts +1 -1
  30. package/dist/core/walkBuilders.d.mts +3 -3
  31. package/dist/core/walker.d.mts +1 -1
  32. package/dist/{errors-Dki7tji4.d.mts → errors-DbaI04x2.d.mts} +1 -1
  33. package/dist/html/a11y.d.mts +2 -2
  34. package/dist/html/renderToHtml.d.mts +5 -5
  35. package/dist/html/renderToHtml.mjs +33 -18
  36. package/dist/html/renderToHtmlStream.d.mts +5 -5
  37. package/dist/html/renderers.d.mts +1 -1
  38. package/dist/html/streamRenderers.d.mts +15 -6
  39. package/dist/html/streamRenderers.mjs +56 -10
  40. package/dist/{inferValue-Ce-PviSD.d.mts → inferValue-eAnh50EM.d.mts} +3 -3
  41. package/dist/lit/SchemaComponent.d.mts +125 -0
  42. package/dist/lit/SchemaComponent.mjs +2 -0
  43. package/dist/lit/SchemaField.d.mts +65 -0
  44. package/dist/lit/SchemaField.mjs +2 -0
  45. package/dist/lit/SchemaView.d.mts +14 -0
  46. package/dist/lit/SchemaView.mjs +2 -0
  47. package/dist/lit/constructorTypes.d.mts +2 -0
  48. package/dist/lit/constructorTypes.mjs +1 -0
  49. package/dist/lit/contexts.d.mts +78 -0
  50. package/dist/lit/contexts.mjs +238 -0
  51. package/dist/lit/defaultResolver.d.mts +33 -0
  52. package/dist/lit/defaultResolver.mjs +2 -0
  53. package/dist/lit/registry.d.mts +66 -0
  54. package/dist/lit/registry.mjs +2 -0
  55. package/dist/lit/renderers/baseElement.d.mts +131 -0
  56. package/dist/lit/renderers/baseElement.mjs +109 -0
  57. package/dist/lit/renderers/recordHelpers.d.mts +25 -0
  58. package/dist/lit/renderers/recordHelpers.mjs +55 -0
  59. package/dist/lit/renderers/scArray.d.mts +14 -0
  60. package/dist/lit/renderers/scArray.mjs +86 -0
  61. package/dist/lit/renderers/scBoolean.d.mts +15 -0
  62. package/dist/lit/renderers/scBoolean.mjs +47 -0
  63. package/dist/lit/renderers/scConditional.d.mts +23 -0
  64. package/dist/lit/renderers/scConditional.mjs +65 -0
  65. package/dist/lit/renderers/scDiscriminated.d.mts +23 -0
  66. package/dist/lit/renderers/scDiscriminated.mjs +138 -0
  67. package/dist/lit/renderers/scEnum.d.mts +16 -0
  68. package/dist/lit/renderers/scEnum.mjs +66 -0
  69. package/dist/lit/renderers/scFile.d.mts +15 -0
  70. package/dist/lit/renderers/scFile.mjs +53 -0
  71. package/dist/lit/renderers/scLiteralNullNever.d.mts +30 -0
  72. package/dist/lit/renderers/scLiteralNullNever.mjs +57 -0
  73. package/dist/lit/renderers/scNumber.d.mts +15 -0
  74. package/dist/lit/renderers/scNumber.mjs +64 -0
  75. package/dist/lit/renderers/scObject.d.mts +14 -0
  76. package/dist/lit/renderers/scObject.mjs +57 -0
  77. package/dist/lit/renderers/scRecord.d.mts +14 -0
  78. package/dist/lit/renderers/scRecord.mjs +112 -0
  79. package/dist/lit/renderers/scString.d.mts +19 -0
  80. package/dist/lit/renderers/scString.mjs +165 -0
  81. package/dist/lit/renderers/scTuple.d.mts +14 -0
  82. package/dist/lit/renderers/scTuple.mjs +58 -0
  83. package/dist/lit/renderers/scUnion.d.mts +14 -0
  84. package/dist/lit/renderers/scUnion.mjs +44 -0
  85. package/dist/lit/renderers/scUnknown.d.mts +15 -0
  86. package/dist/lit/renderers/scUnknown.mjs +45 -0
  87. package/dist/lit/ssr.d.mts +37 -0
  88. package/dist/lit/ssr.mjs +9565 -0
  89. package/dist/lit/types.d.mts +2 -0
  90. package/dist/lit/types.mjs +1 -0
  91. package/dist/lit/widget.d.mts +71 -0
  92. package/dist/lit/widget.mjs +87 -0
  93. package/dist/openapi/ApiCallbacks.d.mts +1 -1
  94. package/dist/openapi/ApiLinks.d.mts +1 -1
  95. package/dist/openapi/ApiResponseHeaders.d.mts +1 -1
  96. package/dist/openapi/ApiSecurity.d.mts +1 -1
  97. package/dist/openapi/components.d.mts +4 -4
  98. package/dist/openapi/parser.d.mts +2 -2
  99. package/dist/openapi/resolve.d.mts +1 -1
  100. package/dist/preact/SchemaComponent.d.mts +3 -0
  101. package/dist/preact/SchemaComponent.mjs +26 -0
  102. package/dist/preact/SchemaErrorBoundary.d.mts +2 -0
  103. package/dist/preact/SchemaErrorBoundary.mjs +20 -0
  104. package/dist/preact/SchemaView.d.mts +2 -0
  105. package/dist/preact/SchemaView.mjs +22 -0
  106. package/dist/preact/headless.d.mts +2 -0
  107. package/dist/preact/headless.mjs +18 -0
  108. package/dist/react/SchemaComponent.d.mts +3 -270
  109. package/dist/react/SchemaComponent.mjs +41 -32
  110. package/dist/react/SchemaView.d.mts +6 -6
  111. package/dist/react/SchemaView.mjs +32 -29
  112. package/dist/react/a11y.d.mts +2 -2
  113. package/dist/react/fieldShell.d.mts +1 -1
  114. package/dist/react/headless.d.mts +1 -1
  115. package/dist/react/headlessRenderers.d.mts +2 -2
  116. package/dist/{ref-DdsbekXX.d.mts → ref-DWrQG1Er.d.mts} +1 -1
  117. package/dist/renderer-ab9E52Bp.d.mts +245 -0
  118. package/dist/solid/SchemaComponent.d.mts +136 -0
  119. package/dist/solid/SchemaComponent.mjs +391 -0
  120. package/dist/solid/SchemaErrorBoundary.d.mts +38 -0
  121. package/dist/solid/SchemaErrorBoundary.mjs +57 -0
  122. package/dist/solid/SchemaField.d.mts +40 -0
  123. package/dist/solid/SchemaField.mjs +113 -0
  124. package/dist/solid/SchemaView.d.mts +54 -0
  125. package/dist/solid/SchemaView.mjs +168 -0
  126. package/dist/solid/a11y.d.mts +70 -0
  127. package/dist/solid/a11y.mjs +71 -0
  128. package/dist/solid/contexts.d.mts +37 -0
  129. package/dist/solid/contexts.mjs +66 -0
  130. package/dist/solid/headless.d.mts +10 -0
  131. package/dist/solid/headless.mjs +27 -0
  132. package/dist/solid/renderers.d.mts +79 -0
  133. package/dist/solid/renderers.mjs +840 -0
  134. package/dist/solid/types.d.mts +90 -0
  135. package/dist/solid/types.mjs +1 -0
  136. package/dist/solid/widget.d.mts +29 -0
  137. package/dist/solid/widget.mjs +35 -0
  138. package/dist/themes/mantine.d.mts +1 -1
  139. package/dist/themes/mui.d.mts +1 -1
  140. package/dist/themes/radix.d.mts +1 -1
  141. package/dist/themes/shadcn.d.mts +1 -1
  142. package/dist/typeInference-Y8tNEQJk.d.mts +983 -0
  143. package/dist/types-BCy7K3nk.d.mts +125 -0
  144. package/package.json +73 -1
  145. package/src/svelte/SchemaComponent.svelte +427 -0
  146. package/src/svelte/SchemaErrorBoundary.svelte +66 -0
  147. package/src/svelte/SchemaField.svelte +216 -0
  148. package/src/svelte/SchemaProvider.svelte +46 -0
  149. package/src/svelte/SchemaView.svelte +244 -0
  150. package/src/svelte/a11y.ts +112 -0
  151. package/src/svelte/contexts.ts +79 -0
  152. package/src/svelte/dispatch.ts +267 -0
  153. package/src/svelte/headless.ts +73 -0
  154. package/src/svelte/headlessFns.ts +124 -0
  155. package/src/svelte/renderers/Array.svelte +98 -0
  156. package/src/svelte/renderers/Boolean.svelte +43 -0
  157. package/src/svelte/renderers/Conditional.svelte +67 -0
  158. package/src/svelte/renderers/DiscriminatedUnion.svelte +197 -0
  159. package/src/svelte/renderers/Enum.svelte +53 -0
  160. package/src/svelte/renderers/Fallback.svelte +24 -0
  161. package/src/svelte/renderers/File.svelte +46 -0
  162. package/src/svelte/renderers/Literal.svelte +29 -0
  163. package/src/svelte/renderers/Mount.svelte +24 -0
  164. package/src/svelte/renderers/Negation.svelte +35 -0
  165. package/src/svelte/renderers/Never.svelte +24 -0
  166. package/src/svelte/renderers/Null.svelte +19 -0
  167. package/src/svelte/renderers/Number.svelte +68 -0
  168. package/src/svelte/renderers/Object.svelte +74 -0
  169. package/src/svelte/renderers/Record.svelte +134 -0
  170. package/src/svelte/renderers/RecursionSentinel.svelte +27 -0
  171. package/src/svelte/renderers/String.svelte +152 -0
  172. package/src/svelte/renderers/Tuple.svelte +84 -0
  173. package/src/svelte/renderers/Union.svelte +49 -0
  174. package/src/svelte/renderers/Unknown.svelte +42 -0
  175. package/src/svelte/svelte-modules.d.ts +25 -0
  176. package/src/svelte/types.ts +238 -0
  177. package/src/svelte/widget.ts +62 -0
  178. package/src/vue/SchemaComponent.vue +274 -0
  179. package/src/vue/SchemaErrorBoundary.vue +60 -0
  180. package/src/vue/SchemaField.vue +178 -0
  181. package/src/vue/SchemaProvider.vue +39 -0
  182. package/src/vue/SchemaView.vue +198 -0
  183. package/src/vue/VNodeHost.ts +32 -0
  184. package/src/vue/contexts.ts +116 -0
  185. package/src/vue/eventTargets.ts +35 -0
  186. package/src/vue/headless.ts +61 -0
  187. package/src/vue/idPrefix.ts +79 -0
  188. package/src/vue/renderField.ts +182 -0
  189. package/src/vue/renderers.ts +1297 -0
  190. package/src/vue/resolver.ts +45 -0
  191. package/src/vue/types.ts +140 -0
  192. package/src/vue/vue-shim.d.ts +25 -0
  193. package/src/vue/widget.ts +51 -0
  194. /package/dist/{diagnostics-BTrm3O6J.d.mts → diagnostics-mftUZI7c.d.mts} +0 -0
  195. /package/dist/{limits-x4OiyJxh.d.mts → limits-Vv9hUbI_.d.mts} +0 -0
  196. /package/dist/{types-BrYbjC7_.d.mts → types-BBQaEPfE.d.mts} +0 -0
  197. /package/dist/{version-DL8U5RuA.d.mts → version-BEBx10ND.d.mts} +0 -0
package/README.md CHANGED
@@ -12,7 +12,7 @@ React components that render UI from Zod schemas, JSON Schema, and OpenAPI docum
12
12
  npm install schema-components
13
13
  ```
14
14
 
15
- Peer dependencies: `zod@^4.0.0`, `react@^18.0.0 || ^19.0.0`.
15
+ Peer dependencies: `zod@^4.0.0`, `react@^18.0.0 || ^19.0.0`. `preact@>=10.0.0` is also accepted as an optional peer for the Preact entry point — see [Preact support](#preact-support).
16
16
 
17
17
  ### Zod version requirement
18
18
 
@@ -20,6 +20,138 @@ schema-components requires **Zod 4**. If you are on Zod 3, see the [Zod 4 migrat
20
20
 
21
21
  Schemas from other libraries that conform to the [Standard Schema](https://standardschema.dev/) spec (valibot, arktype, ...) are also detected and rejected. When the input advertises a `~standard.vendor` field, the error message includes the vendor name so consumers know which library produced the input.
22
22
 
23
+ ### Preact support
24
+
25
+ Preact is supported as an optional peer dependency via `preact/compat` aliasing. The Preact entry point (`schema-components/preact/*`) re-exports every public symbol from the React entry point (`SchemaComponent`, `SchemaProvider`, `SchemaField`, `SchemaView`, `SchemaErrorBoundary`, `registerWidget`, `headlessResolver`). The renderer tree is identical — `preact/compat` translates React-style `onChange` to `onInput` at render time, matching the "fires on every keystroke" semantics the controlled inputs rely on.
26
+
27
+ Import from `schema-components/preact/*` instead of `schema-components/react/*`, then configure your bundler to alias `react` and `react-dom` to `preact/compat`.
28
+
29
+ ```tsx
30
+ import { SchemaComponent } from "schema-components/preact/SchemaComponent";
31
+ ```
32
+
33
+ #### Vite
34
+
35
+ ```ts
36
+ // vite.config.ts
37
+ import { defineConfig } from "vite";
38
+
39
+ export default defineConfig({
40
+ resolve: {
41
+ alias: {
42
+ "react-dom/test-utils": "preact/test-utils",
43
+ "react-dom/client": "preact/compat/client",
44
+ "react-dom/server": "preact/compat/server",
45
+ "react-dom": "preact/compat",
46
+ "react/jsx-runtime": "preact/jsx-runtime",
47
+ "react/jsx-dev-runtime": "preact/jsx-dev-runtime",
48
+ react: "preact/compat",
49
+ },
50
+ },
51
+ });
52
+ ```
53
+
54
+ The order matters: longer, path-specific entries (`react-dom/client`, `react/jsx-runtime`) must come before the bare entries (`react`, `react-dom`) so they get a chance to claim the request first.
55
+
56
+ #### Next.js
57
+
58
+ ```ts
59
+ // next.config.ts
60
+ import type { NextConfig } from "next";
61
+
62
+ const config: NextConfig = {
63
+ webpack(webpackConfig) {
64
+ webpackConfig.resolve.alias = {
65
+ ...webpackConfig.resolve.alias,
66
+ "react-dom/test-utils": "preact/test-utils",
67
+ "react-dom/client": "preact/compat/client",
68
+ "react-dom/server": "preact/compat/server",
69
+ "react-dom": "preact/compat",
70
+ "react/jsx-runtime": "preact/jsx-runtime",
71
+ "react/jsx-dev-runtime": "preact/jsx-dev-runtime",
72
+ react: "preact/compat",
73
+ };
74
+ return webpackConfig;
75
+ },
76
+ };
77
+
78
+ export default config;
79
+ ```
80
+
81
+ #### Node (without a bundler)
82
+
83
+ Use the package manager's overrides field to swap the resolved package at install time. For npm:
84
+
85
+ ```jsonc
86
+ // package.json
87
+ {
88
+ "overrides": {
89
+ "react": "npm:@preact/compat@*",
90
+ "react-dom": "npm:@preact/compat@*"
91
+ }
92
+ }
93
+ ```
94
+
95
+ For pnpm:
96
+
97
+ ```jsonc
98
+ // package.json
99
+ {
100
+ "pnpm": {
101
+ "overrides": {
102
+ "react": "npm:@preact/compat@*",
103
+ "react-dom": "npm:@preact/compat@*"
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ For yarn, use the `resolutions` field with the same value.
110
+
111
+ #### Known limitations
112
+
113
+ 1. **React Server Components is React-only.** `<SchemaView>` runs as a client component under Preact, losing the zero-client-JS deployment story documented in [Server Components](#server-components). The component still renders correctly — it just executes in the browser rather than at request time on the server.
114
+ 2. **`onChange` semantics requires `preact/compat`.** Raw `preact` (without `compat`) fires `onChange` on commit / blur, matching the DOM standard. `preact/compat` aliases `onChange` to `onInput` so the controlled inputs fire on every keystroke, matching React's behaviour. Importing from `schema-components/preact/*` without aliasing `react` to `preact/compat` will leave events misrouted.
115
+ 3. **HTML serialization differs slightly.** Preact emits HTML5 boolean-attribute shorthand (`value` for an empty string) where React emits `value=""`. The semantics are identical; only string snapshots that match the exact React form will need adjusting under Preact.
116
+ 4. **Vnode prop shape differs.** Preact-compat rewrites React-style event prop names (`onChange`, `onBlur`) to lowercase DOM event names (`oninput`, `onfocusout`) on the vnode prop bag during rendering. Tests that inspect a React element's `.props` directly (rather than the rendered DOM) need to expect the lowercase form when running under Preact.
117
+
118
+ The test suite is parametrised with a `unit-preact` Vitest project that runs the same files under `preact/compat` aliasing. Run it via `pnpm test:preact` from the repo root, or directly with `pnpm exec vitest run --project=unit-preact` from `packages/core`. A small set of tests (the ones bound to the three known limitations above) fail intentionally; the remaining ~99% pass under both runtimes and establish the cross-runtime regression boundary.
119
+
120
+ ### Vue support
121
+
122
+ Vue 3.5+ is supported as an optional peer dependency. The Vue adapter ships as **source** under `schema-components/vue/*` — the `.vue` Single File Components are not pre-compiled into the published tarball. Consumers need a Vite or webpack toolchain with `@vitejs/plugin-vue` (or equivalent) to compile the SFCs at their own build step.
123
+
124
+ ```ts
125
+ // vite.config.ts
126
+ import { defineConfig } from "vite";
127
+ import vue from "@vitejs/plugin-vue";
128
+
129
+ export default defineConfig({
130
+ plugins: [vue()],
131
+ });
132
+ ```
133
+
134
+ ```vue
135
+ <script setup lang="ts">
136
+ import { ref } from "vue";
137
+ import SchemaComponent from "schema-components/vue/SchemaComponent.vue";
138
+ import { z } from "zod";
139
+
140
+ const userSchema = z.object({
141
+ name: z.string(),
142
+ email: z.email(),
143
+ });
144
+
145
+ const user = ref({ name: "Ada", email: "ada@example.com" });
146
+ </script>
147
+
148
+ <template>
149
+ <SchemaComponent :schema="userSchema" v-model="user" />
150
+ </template>
151
+ ```
152
+
153
+ The `./vue/*` export subpath resolves to the source tree (`src/vue/*.ts`) and `./vue/*.vue` resolves to the `.vue` SFCs under `src/vue/`. The same pattern is used by the Svelte adapter — both rely on the consumer's bundler to handle the framework-specific compilation step.
154
+
23
155
  ## `SchemaComponent`
24
156
 
25
157
  The single entry point. Accepts Zod schemas, JSON Schema objects, or OpenAPI documents:
@@ -0,0 +1,277 @@
1
+ import { j as WalkedField, w as SchemaMeta } from "./types-BBQaEPfE.mjs";
2
+ import { t as Diagnostic } from "./diagnostics-mftUZI7c.mjs";
3
+ import { r as SchemaIoSide } from "./adapter-ktQaheWB.mjs";
4
+ import { d as WidgetMap, i as ComponentResolver, u as RenderProps } from "./renderer-ab9E52Bp.mjs";
5
+ import { t as SchemaError } from "./errors-DbaI04x2.mjs";
6
+ import { d as PathOfType, f as RejectUnrepresentableZod, r as FromJSONSchema } from "./typeInference-Y8tNEQJk.mjs";
7
+ import { n as InferSchemaValue, t as InferFields } from "./inferValue-eAnh50EM.mjs";
8
+ import { z } from "zod";
9
+ import * as _$react_jsx_runtime0 from "react/jsx-runtime";
10
+ import { ReactNode } from "react";
11
+
12
+ //#region src/react/SchemaComponent.d.ts
13
+ /**
14
+ * Provide a theme resolver and scoped widgets to every `<SchemaComponent>`
15
+ * and `<SchemaView>` rendered inside the subtree.
16
+ *
17
+ * Wrap an application (or a region of it) with `<SchemaProvider>` so a
18
+ * single theme — typically one of the bundled adapters
19
+ * (`shadcnResolver`, `muiResolver`, `mantineResolver`, `radixResolver`)
20
+ * or a custom one — drives every schema render. Without a provider,
21
+ * schema-components fall back to the headless HTML renderer.
22
+ *
23
+ * @group Components
24
+ * @example
25
+ * ```tsx
26
+ * import { SchemaProvider } from "schema-components/react/SchemaComponent";
27
+ * import { shadcnResolver } from "schema-components/themes/shadcn";
28
+ *
29
+ * <SchemaProvider resolver={shadcnResolver}>
30
+ * <SchemaComponent schema={userSchema} value={user} onChange={setUser} />
31
+ * </SchemaProvider>
32
+ * ```
33
+ */
34
+ declare function SchemaProvider({
35
+ resolver,
36
+ widgets,
37
+ children
38
+ }: {
39
+ resolver: ComponentResolver; /** Scoped widgets available to all SchemaComponents in this subtree. */
40
+ widgets?: WidgetMap;
41
+ children: ReactNode;
42
+ }): _$react_jsx_runtime0.JSX.Element;
43
+ /**
44
+ * Register a widget globally. The widget is resolved when a schema field
45
+ * has `.meta({ component: name })`.
46
+ *
47
+ * For scoped registration, use the `widgets` prop on `<SchemaComponent>`
48
+ * or `<SchemaProvider>` instead.
49
+ */
50
+ declare function registerWidget(name: string, render: (props: RenderProps) => unknown): void;
51
+ /**
52
+ * Clear every globally registered widget. Intended for test isolation —
53
+ * `registerWidget` writes to module-level state and that state otherwise
54
+ * leaks across test cases, making the test suite order-dependent. Tests
55
+ * should call this from an `afterEach` hook.
56
+ *
57
+ * @internal
58
+ */
59
+ declare function __clearGlobalWidgets(): void;
60
+ /**
61
+ * Props accepted by {@link SchemaComponent}.
62
+ *
63
+ * The generic parameters carry the inferred schema shape through to
64
+ * `value`, `onChange`, and `fields` so a typed `schema` prop drives
65
+ * typed props on the rest of the component.
66
+ *
67
+ * @group Components
68
+ */
69
+ interface SchemaComponentProps<T = unknown, Ref extends string | undefined = undefined, Mode extends SchemaIoSide = "output"> {
70
+ /**
71
+ * Zod schema, JSON Schema object, or OpenAPI document.
72
+ *
73
+ * Zod 4 types that cannot round-trip through `z.toJSONSchema()`
74
+ * (bigint, date, map, set, symbol, function, undefined, void, nan,
75
+ * codec) are rejected at the type level via
76
+ * {@link RejectUnrepresentableZod}. Runtime conversion would throw
77
+ * `SchemaNormalisationError` with kind `zod-type-unrepresentable`
78
+ * — the static rejection surfaces the same failure at compile time.
79
+ */
80
+ schema: RejectUnrepresentableZod<T>;
81
+ /** For OpenAPI: a ref string like "#/components/schemas/User" or "/users/post". */
82
+ ref?: Ref;
83
+ /**
84
+ * Which side of every transform / pipe / codec to render.
85
+ *
86
+ * - `"output"` (default) — renderer draws the OUTPUT side of the
87
+ * schema. For a `z.codec(z.string(), z.number(), …)` chain
88
+ * this renders a number input. `value` and `onChange` therefore
89
+ * carry the OUTPUT shape, and `validate` runs `safeEncode`
90
+ * (the reverse direction) so user-supplied OUTPUT values are
91
+ * validated against the codec.
92
+ * - `"input"` — renderer draws the INPUT side instead. For the
93
+ * same codec this renders a string input, `value` and
94
+ * `onChange` carry the INPUT shape, and `validate` runs
95
+ * `safeParse` (the forward direction).
96
+ *
97
+ * The choice is propagated through `normaliseSchema` →
98
+ * `normaliseZod4` → `z.toJSONSchema(..., { io })` so a single
99
+ * source of truth drives both the rendered JSON Schema shape and
100
+ * the validation direction. Has no effect for plain JSON Schema
101
+ * or OpenAPI inputs — those advertise a single canonical shape.
102
+ */
103
+ io?: Mode;
104
+ /**
105
+ * Current value to render. Typed against
106
+ * `InferSchemaValue<T, Ref, Mode>` so the prop tracks the schema's
107
+ * inferred shape for the chosen `io` direction.
108
+ *
109
+ * Falls back to `unknown` when the schema's value type cannot be
110
+ * statically inferred (runtime `Record<string, unknown>` JSON
111
+ * Schemas, OpenAPI documents without a ref, etc.), so untyped
112
+ * call sites still compile.
113
+ *
114
+ * Use {@link InferredOutputValue} or {@link InferredInputValue}
115
+ * to narrow a value declared at the call site:
116
+ *
117
+ * ```tsx
118
+ * const user: InferredOutputValue<typeof userSchema> = { ... };
119
+ * <SchemaComponent schema={userSchema} value={user} readOnly />
120
+ * ```
121
+ */
122
+ value?: InferSchemaValue<T, Ref, Mode>;
123
+ /**
124
+ * Called when the value changes (editable fields). The parameter
125
+ * shares the same shape as {@link SchemaComponentProps.value} so
126
+ * a controlled component can round-trip the value through React
127
+ * state without re-shaping.
128
+ *
129
+ * Falls back to `unknown` for schemas whose value type cannot be
130
+ * statically inferred — see {@link SchemaComponentProps.value}.
131
+ */
132
+ onChange?: (value: InferSchemaValue<T, Ref, Mode>) => void;
133
+ /** Run schema.safeParse() on change and surface errors via onValidationError. */
134
+ validate?: boolean;
135
+ /** Called with the ZodError when validation fails. */
136
+ onValidationError?: (error: unknown) => void;
137
+ /** Called when schema normalisation or rendering fails. */
138
+ onError?: (error: SchemaError) => void;
139
+ /** Called with each diagnostic emitted during schema processing. */
140
+ onDiagnostic?: (diagnostic: Diagnostic) => void;
141
+ /** When true, any diagnostic becomes a thrown error. */
142
+ strict?: boolean;
143
+ /** Per-field meta overrides — nested object mirroring schema shape. */
144
+ fields?: InferFields<T, Ref>;
145
+ /** Meta overrides applied to the root schema. */
146
+ meta?: SchemaMeta;
147
+ /** Convenience: sets readOnly on all fields. */
148
+ readOnly?: boolean;
149
+ /** Convenience: sets writeOnly on all fields. */
150
+ writeOnly?: boolean;
151
+ /** Convenience: sets description on the root. */
152
+ description?: string;
153
+ /** Instance-scoped widgets — override context and global widgets. */
154
+ widgets?: WidgetMap;
155
+ /**
156
+ * Prefix used for every input `id`/label `htmlFor` in this component
157
+ * subtree. Defaults to a per-instance value from `useId()` so multiple
158
+ * `<SchemaComponent>` instances on the same page never collide. Override
159
+ * for deterministic ids in screenshot tests.
160
+ */
161
+ idPrefix?: string;
162
+ }
163
+ /**
164
+ * Render an editable (or read-only) UI from a Zod schema, JSON Schema, or
165
+ * OpenAPI document.
166
+ *
167
+ * Auto-detects the input format, normalises to JSON Schema via the
168
+ * adapter, walks the JSON Schema tree, and delegates per-field rendering
169
+ * to the {@link ComponentResolver} supplied via {@link SchemaProvider} —
170
+ * falling back to a headless HTML renderer when no provider is present.
171
+ *
172
+ * Pass `readOnly` to render a presentational view instead of inputs, or
173
+ * wrap with `<SchemaProvider resolver={…}>` to swap the theme.
174
+ *
175
+ * @group Components
176
+ * @example
177
+ * ```tsx
178
+ * import { z } from "zod";
179
+ * import { SchemaComponent } from "schema-components/react/SchemaComponent";
180
+ *
181
+ * const userSchema = z.object({ name: z.string(), email: z.email() });
182
+ *
183
+ * <SchemaComponent schema={userSchema} value={user} onChange={setUser} />
184
+ * ```
185
+ */
186
+ declare function SchemaComponent<T = unknown, Ref extends string | undefined = undefined, Mode extends SchemaIoSide = "output">(props: SchemaComponentProps<T, Ref, Mode>): ReactNode;
187
+ /**
188
+ * Append a child path suffix to a parent path. When the suffix is omitted
189
+ * (e.g. transparent wrappers like union options), the parent path is
190
+ * returned unchanged so the child inherits the parent's id.
191
+ *
192
+ * Bracketed array indices like `[0]` append directly so `tags` + `[0]`
193
+ * becomes `tags[0]` rather than `tags.[0]` — matching the canonical form
194
+ * used by `html/a11y.ts` `joinPath` and `core/fieldPath.ts` `resolvePath`,
195
+ * which already parses bracket notation when navigating WalkedField trees.
196
+ */
197
+ declare function joinPath(parent: string, suffix: string | undefined): string;
198
+ /**
199
+ * Normalise a `useId()` value into a DOM-id-safe prefix. React's `useId`
200
+ * returns values containing `:` characters (e.g. `«:r0:»`) which are
201
+ * invalid in CSS selectors. Replace any run of non-alphanumeric characters
202
+ * with a single hyphen and trim leading/trailing hyphens.
203
+ */
204
+ declare function sanitisePrefix(value: string): string;
205
+ /**
206
+ * Render a single walked field through the resolved widget /
207
+ * resolver / headless pipeline. Used internally by
208
+ * {@link SchemaComponent} and {@link SchemaField}, exported so other
209
+ * React-side components (e.g. the OpenAPI renderers) can dispatch
210
+ * into the same fallback chain.
211
+ *
212
+ * Thin React-flavoured wrapper around the framework-agnostic
213
+ * `dispatchRenderField` (from `core/renderField`): it constructs a
214
+ * React-shaped `DispatchConfig` (widget lookup against the
215
+ * instance → context → global chain, recursion sentinel as a React
216
+ * `<fieldset>`, fallback as a `<span>`-wrapped value) and forwards
217
+ * the call.
218
+ */
219
+ declare function renderField(tree: WalkedField, value: unknown, onChange: (v: unknown) => void, userResolver: ComponentResolver | undefined, renderChild: (tree: WalkedField, value: unknown, onChange: (v: unknown) => void, pathSuffix?: string) => ReactNode, path: string, instanceWidgets?: WidgetMap, contextWidgets?: WidgetMap, depth?: number): ReactNode;
220
+ /**
221
+ * Infer the schema's output type for SchemaField path inference.
222
+ */
223
+ type InferSchemaType<T> = T extends z.ZodType ? z.infer<T> : T extends object ? unknown extends FromJSONSchema<T> ? unknown : FromJSONSchema<T> : unknown;
224
+ /**
225
+ * Props accepted by {@link SchemaField}. The generic `P` constrains
226
+ * `path` to dot-paths reachable through the schema's inferred value
227
+ * type — typed schemas get autocomplete; runtime schemas fall back to
228
+ * `string`.
229
+ *
230
+ * @group Components
231
+ */
232
+ interface SchemaFieldProps<T = unknown, Ref extends string | undefined = undefined, P extends string = PathOfType<InferSchemaType<T>> | (string extends PathOfType<InferSchemaType<T>> ? string : never)> {
233
+ /**
234
+ * Dot-separated path to the field (e.g. "address.city").
235
+ * When the schema is a Zod schema or typed `as const`, only valid
236
+ * paths are accepted. Falls back to `string` for runtime schemas.
237
+ */
238
+ path: P;
239
+ /**
240
+ * The schema to extract the field from. Subject to the same
241
+ * unrepresentable-Zod rejection as {@link SchemaComponentProps.schema}.
242
+ */
243
+ schema: RejectUnrepresentableZod<T>;
244
+ /** For OpenAPI: a ref string. */
245
+ ref?: Ref;
246
+ /** Current value of the field at the given path. */
247
+ value?: unknown;
248
+ /** Called with the updated root value when this field changes. */
249
+ onChange?: (value: unknown) => void;
250
+ /** Override meta for this specific field. */
251
+ meta?: SchemaMeta;
252
+ /** Run validation on change. */
253
+ validate?: boolean;
254
+ onValidationError?: (error: unknown) => void;
255
+ }
256
+ /**
257
+ * Render a single field from a schema by dot-separated `path`.
258
+ *
259
+ * Walks the full schema tree and resolves the field at the supplied
260
+ * `path`, then renders only that field through the same resolver
261
+ * pipeline as {@link SchemaComponent}. Useful for embedding individual
262
+ * fields inside bespoke layouts.
263
+ *
264
+ * @group Components
265
+ */
266
+ declare function SchemaField<T = unknown, Ref extends string | undefined = undefined, P extends string = PathOfType<InferSchemaType<T>> | (string extends PathOfType<InferSchemaType<T>> ? string : never)>({
267
+ path,
268
+ schema: schemaInput,
269
+ ref: refInput,
270
+ value,
271
+ onChange,
272
+ meta: fieldMeta,
273
+ validate,
274
+ onValidationError
275
+ }: SchemaFieldProps<T, Ref, P>): ReactNode;
276
+ //#endregion
277
+ export { SchemaProvider as a, registerWidget as c, SchemaFieldProps as i, renderField as l, SchemaComponentProps as n, __clearGlobalWidgets as o, SchemaField as r, joinPath as s, SchemaComponent as t, sanitisePrefix as u };