schema-components 2.0.2 → 2.1.0

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 (180) hide show
  1. package/README.md +98 -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 +81 -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 +3 -3
  39. package/dist/{inferValue-Ce-PviSD.d.mts → inferValue-eAnh50EM.d.mts} +3 -3
  40. package/dist/lit/SchemaComponent.d.mts +125 -0
  41. package/dist/lit/SchemaComponent.mjs +2 -0
  42. package/dist/lit/SchemaField.d.mts +65 -0
  43. package/dist/lit/SchemaField.mjs +2 -0
  44. package/dist/lit/SchemaView.d.mts +14 -0
  45. package/dist/lit/SchemaView.mjs +2 -0
  46. package/dist/lit/constructorTypes.d.mts +2 -0
  47. package/dist/lit/constructorTypes.mjs +1 -0
  48. package/dist/lit/contexts.d.mts +78 -0
  49. package/dist/lit/contexts.mjs +238 -0
  50. package/dist/lit/defaultResolver.d.mts +33 -0
  51. package/dist/lit/defaultResolver.mjs +2 -0
  52. package/dist/lit/registry.d.mts +66 -0
  53. package/dist/lit/registry.mjs +2 -0
  54. package/dist/lit/renderers/baseElement.d.mts +131 -0
  55. package/dist/lit/renderers/baseElement.mjs +109 -0
  56. package/dist/lit/renderers/recordHelpers.d.mts +25 -0
  57. package/dist/lit/renderers/recordHelpers.mjs +55 -0
  58. package/dist/lit/renderers/scArray.d.mts +14 -0
  59. package/dist/lit/renderers/scArray.mjs +86 -0
  60. package/dist/lit/renderers/scBoolean.d.mts +15 -0
  61. package/dist/lit/renderers/scBoolean.mjs +47 -0
  62. package/dist/lit/renderers/scConditional.d.mts +23 -0
  63. package/dist/lit/renderers/scConditional.mjs +65 -0
  64. package/dist/lit/renderers/scDiscriminated.d.mts +23 -0
  65. package/dist/lit/renderers/scDiscriminated.mjs +138 -0
  66. package/dist/lit/renderers/scEnum.d.mts +16 -0
  67. package/dist/lit/renderers/scEnum.mjs +66 -0
  68. package/dist/lit/renderers/scFile.d.mts +15 -0
  69. package/dist/lit/renderers/scFile.mjs +53 -0
  70. package/dist/lit/renderers/scLiteralNullNever.d.mts +30 -0
  71. package/dist/lit/renderers/scLiteralNullNever.mjs +57 -0
  72. package/dist/lit/renderers/scNumber.d.mts +15 -0
  73. package/dist/lit/renderers/scNumber.mjs +64 -0
  74. package/dist/lit/renderers/scObject.d.mts +14 -0
  75. package/dist/lit/renderers/scObject.mjs +57 -0
  76. package/dist/lit/renderers/scRecord.d.mts +14 -0
  77. package/dist/lit/renderers/scRecord.mjs +112 -0
  78. package/dist/lit/renderers/scString.d.mts +19 -0
  79. package/dist/lit/renderers/scString.mjs +165 -0
  80. package/dist/lit/renderers/scTuple.d.mts +14 -0
  81. package/dist/lit/renderers/scTuple.mjs +58 -0
  82. package/dist/lit/renderers/scUnion.d.mts +14 -0
  83. package/dist/lit/renderers/scUnion.mjs +44 -0
  84. package/dist/lit/renderers/scUnknown.d.mts +15 -0
  85. package/dist/lit/renderers/scUnknown.mjs +45 -0
  86. package/dist/lit/ssr.d.mts +37 -0
  87. package/dist/lit/ssr.mjs +9565 -0
  88. package/dist/lit/types.d.mts +2 -0
  89. package/dist/lit/types.mjs +1 -0
  90. package/dist/lit/widget.d.mts +71 -0
  91. package/dist/lit/widget.mjs +87 -0
  92. package/dist/openapi/ApiCallbacks.d.mts +1 -1
  93. package/dist/openapi/ApiLinks.d.mts +1 -1
  94. package/dist/openapi/ApiResponseHeaders.d.mts +1 -1
  95. package/dist/openapi/ApiSecurity.d.mts +1 -1
  96. package/dist/openapi/components.d.mts +4 -4
  97. package/dist/openapi/parser.d.mts +2 -2
  98. package/dist/openapi/resolve.d.mts +1 -1
  99. package/dist/preact/SchemaComponent.d.mts +3 -0
  100. package/dist/preact/SchemaComponent.mjs +26 -0
  101. package/dist/preact/SchemaErrorBoundary.d.mts +2 -0
  102. package/dist/preact/SchemaErrorBoundary.mjs +20 -0
  103. package/dist/preact/SchemaView.d.mts +2 -0
  104. package/dist/preact/SchemaView.mjs +22 -0
  105. package/dist/preact/headless.d.mts +2 -0
  106. package/dist/preact/headless.mjs +18 -0
  107. package/dist/react/SchemaComponent.d.mts +3 -270
  108. package/dist/react/SchemaComponent.mjs +41 -32
  109. package/dist/react/SchemaView.d.mts +6 -6
  110. package/dist/react/SchemaView.mjs +32 -29
  111. package/dist/react/a11y.d.mts +2 -2
  112. package/dist/react/fieldShell.d.mts +1 -1
  113. package/dist/react/headless.d.mts +1 -1
  114. package/dist/react/headlessRenderers.d.mts +2 -2
  115. package/dist/{ref-DdsbekXX.d.mts → ref-DWrQG1Er.d.mts} +1 -1
  116. package/dist/renderer-ab9E52Bp.d.mts +245 -0
  117. package/dist/solid/SchemaComponent.d.mts +136 -0
  118. package/dist/solid/SchemaComponent.mjs +391 -0
  119. package/dist/solid/SchemaErrorBoundary.d.mts +38 -0
  120. package/dist/solid/SchemaErrorBoundary.mjs +57 -0
  121. package/dist/solid/SchemaField.d.mts +40 -0
  122. package/dist/solid/SchemaField.mjs +113 -0
  123. package/dist/solid/SchemaView.d.mts +54 -0
  124. package/dist/solid/SchemaView.mjs +168 -0
  125. package/dist/solid/a11y.d.mts +70 -0
  126. package/dist/solid/a11y.mjs +71 -0
  127. package/dist/solid/contexts.d.mts +37 -0
  128. package/dist/solid/contexts.mjs +66 -0
  129. package/dist/solid/headless.d.mts +10 -0
  130. package/dist/solid/headless.mjs +27 -0
  131. package/dist/solid/renderers.d.mts +79 -0
  132. package/dist/solid/renderers.mjs +840 -0
  133. package/dist/solid/types.d.mts +90 -0
  134. package/dist/solid/types.mjs +1 -0
  135. package/dist/solid/widget.d.mts +29 -0
  136. package/dist/solid/widget.mjs +35 -0
  137. package/dist/themes/mantine.d.mts +1 -1
  138. package/dist/themes/mui.d.mts +1 -1
  139. package/dist/themes/radix.d.mts +1 -1
  140. package/dist/themes/shadcn.d.mts +1 -1
  141. package/dist/typeInference-Y8tNEQJk.d.mts +983 -0
  142. package/dist/types-BCy7K3nk.d.mts +125 -0
  143. package/package.json +71 -1
  144. package/src/svelte/SchemaComponent.svelte +427 -0
  145. package/src/svelte/SchemaErrorBoundary.svelte +66 -0
  146. package/src/svelte/SchemaField.svelte +216 -0
  147. package/src/svelte/SchemaProvider.svelte +46 -0
  148. package/src/svelte/SchemaView.svelte +244 -0
  149. package/src/svelte/a11y.ts +112 -0
  150. package/src/svelte/contexts.ts +79 -0
  151. package/src/svelte/dispatch.ts +267 -0
  152. package/src/svelte/headless.ts +73 -0
  153. package/src/svelte/headlessFns.ts +124 -0
  154. package/src/svelte/renderers/Array.svelte +98 -0
  155. package/src/svelte/renderers/Boolean.svelte +43 -0
  156. package/src/svelte/renderers/Conditional.svelte +67 -0
  157. package/src/svelte/renderers/DiscriminatedUnion.svelte +197 -0
  158. package/src/svelte/renderers/Enum.svelte +53 -0
  159. package/src/svelte/renderers/Fallback.svelte +24 -0
  160. package/src/svelte/renderers/File.svelte +46 -0
  161. package/src/svelte/renderers/Literal.svelte +29 -0
  162. package/src/svelte/renderers/Mount.svelte +24 -0
  163. package/src/svelte/renderers/Negation.svelte +35 -0
  164. package/src/svelte/renderers/Never.svelte +24 -0
  165. package/src/svelte/renderers/Null.svelte +19 -0
  166. package/src/svelte/renderers/Number.svelte +68 -0
  167. package/src/svelte/renderers/Object.svelte +74 -0
  168. package/src/svelte/renderers/Record.svelte +134 -0
  169. package/src/svelte/renderers/RecursionSentinel.svelte +27 -0
  170. package/src/svelte/renderers/String.svelte +152 -0
  171. package/src/svelte/renderers/Tuple.svelte +84 -0
  172. package/src/svelte/renderers/Union.svelte +49 -0
  173. package/src/svelte/renderers/Unknown.svelte +42 -0
  174. package/src/svelte/svelte-modules.d.ts +25 -0
  175. package/src/svelte/types.ts +238 -0
  176. package/src/svelte/widget.ts +62 -0
  177. /package/dist/{diagnostics-BTrm3O6J.d.mts → diagnostics-mftUZI7c.d.mts} +0 -0
  178. /package/dist/{limits-x4OiyJxh.d.mts → limits-Vv9hUbI_.d.mts} +0 -0
  179. /package/dist/{types-BrYbjC7_.d.mts → types-BBQaEPfE.d.mts} +0 -0
  180. /package/dist/{version-DL8U5RuA.d.mts → version-BEBx10ND.d.mts} +0 -0
@@ -0,0 +1,2 @@
1
+ import { i as _LitFunctionShapeAssertion, n as LitRenderFunction, r as LitRenderProps, t as LitComponentResolver } from "../types-BCy7K3nk.mjs";
2
+ export { LitComponentResolver, LitRenderFunction, LitRenderProps, _LitFunctionShapeAssertion };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ //#region src/lit/widget.d.ts
2
+ /**
3
+ * Widget registry for the Lit adapter.
4
+ *
5
+ * Where the React adapter's widget registry stores function values
6
+ * (`(props: RenderProps) => unknown`), the Lit adapter stores Custom
7
+ * Element tag names — because every renderer override on the Web
8
+ * Components side IS a Custom Element. A schema field carrying
9
+ * `.meta({ component: "color-picker" })` is rendered by looking up
10
+ * the tag name registered against `"color-picker"` and emitting an
11
+ * instance of that element with the per-field props attached.
12
+ *
13
+ * Two scopes are supported:
14
+ *
15
+ * 1. **Global** — `registerLitWidget(name, tag)` writes to a module-level
16
+ * map shared by every `<schema-component>` in the document. Matches
17
+ * the React `registerWidget()` global default behaviour.
18
+ * 2. **Instance** — the `widgets` property on `<schema-component>` (a
19
+ * `LitWidgetMap` from `lit/contexts.ts`) overrides the global map
20
+ * for the wrapped subtree.
21
+ *
22
+ * Resolution order: instance widgets → global widgets → resolver →
23
+ * default Custom Element registry. The same order the React adapter
24
+ * implements; the only difference is the per-step lookup returns a
25
+ * tag name rather than a function value.
26
+ *
27
+ * @packageDocumentation
28
+ */
29
+ /**
30
+ * Register a widget globally. The widget is resolved when a schema
31
+ * field has `.meta({ component: name })` and the rendered element is
32
+ * an instance of the matching Custom Element tag.
33
+ *
34
+ * `tag` must be a valid Custom Element name (containing a hyphen) and
35
+ * SHOULD be registered via `customElements.define` before any
36
+ * `<schema-component>` in the document instantiates the corresponding
37
+ * field — otherwise the browser emits an unupgraded element and the
38
+ * registered handler never runs.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { registerLitWidget } from "schema-components/lit/widget";
43
+ * import "./my-color-picker.ts"; // calls customElements.define("my-color-picker", ...)
44
+ *
45
+ * registerLitWidget("color-picker", "my-color-picker");
46
+ * ```
47
+ *
48
+ * @param name - Widget hint name (matches `.meta({ component })`).
49
+ * @param tag - Custom Element tag name (e.g. `my-color-picker`).
50
+ */
51
+ declare function registerLitWidget(name: string, tag: string): void;
52
+ /**
53
+ * Resolve a widget hint to a Custom Element tag name, considering
54
+ * instance widgets first and falling back to the global registry.
55
+ *
56
+ * @param name - Widget hint name from `.meta({ component })`.
57
+ * @param instanceWidgets - Optional instance-scoped overrides.
58
+ * @returns The Custom Element tag, or `undefined` when no widget is
59
+ * registered under `name` at either scope.
60
+ */
61
+ declare function resolveLitWidget(name: string, instanceWidgets?: ReadonlyMap<string, string>): string | undefined;
62
+ /**
63
+ * Clear every globally registered widget. Intended for test isolation
64
+ * — `registerLitWidget` writes to module-level state, and that state
65
+ * leaks across test cases without an explicit reset.
66
+ *
67
+ * @internal
68
+ */
69
+ declare function __clearGlobalLitWidgets(): void;
70
+ //#endregion
71
+ export { __clearGlobalLitWidgets, registerLitWidget, resolveLitWidget };
@@ -0,0 +1,87 @@
1
+ //#region src/lit/widget.ts
2
+ /**
3
+ * Widget registry for the Lit adapter.
4
+ *
5
+ * Where the React adapter's widget registry stores function values
6
+ * (`(props: RenderProps) => unknown`), the Lit adapter stores Custom
7
+ * Element tag names — because every renderer override on the Web
8
+ * Components side IS a Custom Element. A schema field carrying
9
+ * `.meta({ component: "color-picker" })` is rendered by looking up
10
+ * the tag name registered against `"color-picker"` and emitting an
11
+ * instance of that element with the per-field props attached.
12
+ *
13
+ * Two scopes are supported:
14
+ *
15
+ * 1. **Global** — `registerLitWidget(name, tag)` writes to a module-level
16
+ * map shared by every `<schema-component>` in the document. Matches
17
+ * the React `registerWidget()` global default behaviour.
18
+ * 2. **Instance** — the `widgets` property on `<schema-component>` (a
19
+ * `LitWidgetMap` from `lit/contexts.ts`) overrides the global map
20
+ * for the wrapped subtree.
21
+ *
22
+ * Resolution order: instance widgets → global widgets → resolver →
23
+ * default Custom Element registry. The same order the React adapter
24
+ * implements; the only difference is the per-step lookup returns a
25
+ * tag name rather than a function value.
26
+ *
27
+ * @packageDocumentation
28
+ */
29
+ /**
30
+ * Global widget registry — `widget-name` → custom element tag name.
31
+ *
32
+ * Internal; consumers register via {@link registerLitWidget} and read
33
+ * via {@link resolveLitWidget} so the map shape can evolve without
34
+ * breaking callers.
35
+ */
36
+ const globalLitWidgets = /* @__PURE__ */ new Map();
37
+ /**
38
+ * Register a widget globally. The widget is resolved when a schema
39
+ * field has `.meta({ component: name })` and the rendered element is
40
+ * an instance of the matching Custom Element tag.
41
+ *
42
+ * `tag` must be a valid Custom Element name (containing a hyphen) and
43
+ * SHOULD be registered via `customElements.define` before any
44
+ * `<schema-component>` in the document instantiates the corresponding
45
+ * field — otherwise the browser emits an unupgraded element and the
46
+ * registered handler never runs.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import { registerLitWidget } from "schema-components/lit/widget";
51
+ * import "./my-color-picker.ts"; // calls customElements.define("my-color-picker", ...)
52
+ *
53
+ * registerLitWidget("color-picker", "my-color-picker");
54
+ * ```
55
+ *
56
+ * @param name - Widget hint name (matches `.meta({ component })`).
57
+ * @param tag - Custom Element tag name (e.g. `my-color-picker`).
58
+ */
59
+ function registerLitWidget(name, tag) {
60
+ globalLitWidgets.set(name, tag);
61
+ }
62
+ /**
63
+ * Resolve a widget hint to a Custom Element tag name, considering
64
+ * instance widgets first and falling back to the global registry.
65
+ *
66
+ * @param name - Widget hint name from `.meta({ component })`.
67
+ * @param instanceWidgets - Optional instance-scoped overrides.
68
+ * @returns The Custom Element tag, or `undefined` when no widget is
69
+ * registered under `name` at either scope.
70
+ */
71
+ function resolveLitWidget(name, instanceWidgets) {
72
+ const instance = instanceWidgets?.get(name);
73
+ if (instance !== void 0) return instance;
74
+ return globalLitWidgets.get(name);
75
+ }
76
+ /**
77
+ * Clear every globally registered widget. Intended for test isolation
78
+ * — `registerLitWidget` writes to module-level state, and that state
79
+ * leaks across test cases without an explicit reset.
80
+ *
81
+ * @internal
82
+ */
83
+ function __clearGlobalLitWidgets() {
84
+ globalLitWidgets.clear();
85
+ }
86
+ //#endregion
87
+ export { __clearGlobalLitWidgets, registerLitWidget, resolveLitWidget };
@@ -1,4 +1,4 @@
1
- import { w as SchemaMeta } from "../types-BrYbjC7_.mjs";
1
+ import { w as SchemaMeta } from "../types-BBQaEPfE.mjs";
2
2
  import { CallbackInfo } from "./parser.mjs";
3
3
  import { ReactNode } from "react";
4
4
 
@@ -1,4 +1,4 @@
1
- import { w as SchemaMeta } from "../types-BrYbjC7_.mjs";
1
+ import { w as SchemaMeta } from "../types-BBQaEPfE.mjs";
2
2
  import { LinkInfo } from "./parser.mjs";
3
3
  import { ReactNode } from "react";
4
4
 
@@ -1,4 +1,4 @@
1
- import { w as SchemaMeta } from "../types-BrYbjC7_.mjs";
1
+ import { w as SchemaMeta } from "../types-BBQaEPfE.mjs";
2
2
  import { HeaderInfo } from "./parser.mjs";
3
3
  import { ReactNode } from "react";
4
4
 
@@ -1,4 +1,4 @@
1
- import { w as SchemaMeta } from "../types-BrYbjC7_.mjs";
1
+ import { w as SchemaMeta } from "../types-BBQaEPfE.mjs";
2
2
  import { SecurityRequirement, SecurityScheme } from "./parser.mjs";
3
3
  import { ReactNode } from "react";
4
4
 
@@ -1,7 +1,7 @@
1
- import { u as FieldOverride, w as SchemaMeta } from "../types-BrYbjC7_.mjs";
2
- import { r as DiagnosticSink } from "../diagnostics-BTrm3O6J.mjs";
3
- import { WidgetMap } from "../core/renderer.mjs";
4
- import { InferParameterOverrides, InferRequestBodyFields, InferResponseFields, OpenAPIRequestBodyType, OpenAPIResponseType } from "../core/typeInference.mjs";
1
+ import { u as FieldOverride, w as SchemaMeta } from "../types-BBQaEPfE.mjs";
2
+ import { r as DiagnosticSink } from "../diagnostics-mftUZI7c.mjs";
3
+ import { d as WidgetMap } from "../renderer-ab9E52Bp.mjs";
4
+ import { a as InferParameterOverrides, l as OpenAPIRequestBodyType, o as InferRequestBodyFields, s as InferResponseFields, u as OpenAPIResponseType } from "../typeInference-Y8tNEQJk.mjs";
5
5
  import { ReactNode } from "react";
6
6
 
7
7
  //#region src/openapi/components.d.ts
@@ -1,5 +1,5 @@
1
- import { m as JsonObject } from "../types-BrYbjC7_.mjs";
2
- import { i as DiagnosticsOptions } from "../diagnostics-BTrm3O6J.mjs";
1
+ import { m as JsonObject } from "../types-BBQaEPfE.mjs";
2
+ import { i as DiagnosticsOptions } from "../diagnostics-mftUZI7c.mjs";
3
3
 
4
4
  //#region src/openapi/parser.d.ts
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { i as DiagnosticsOptions } from "../diagnostics-BTrm3O6J.mjs";
1
+ import { i as DiagnosticsOptions } from "../diagnostics-mftUZI7c.mjs";
2
2
  import { OpenApiDocument, OperationInfo, ParameterInfo, RequestBodyInfo, ResponseInfo } from "./parser.mjs";
3
3
 
4
4
  //#region src/openapi/resolve.d.ts
@@ -0,0 +1,3 @@
1
+ import { a as InferredValue, i as InferredOutputValue, r as InferredInputValue, t as InferFields } from "../inferValue-eAnh50EM.mjs";
2
+ import { a as SchemaProvider, c as registerWidget, i as SchemaFieldProps, n as SchemaComponentProps, r as SchemaField, t as SchemaComponent } from "../SchemaComponent-B__6-5-E.mjs";
3
+ export { type InferFields, type InferredInputValue, type InferredOutputValue, type InferredValue, SchemaComponent, type SchemaComponentProps, SchemaField, type SchemaFieldProps, SchemaProvider, registerWidget };
@@ -0,0 +1,26 @@
1
+ import { SchemaComponent, SchemaField, SchemaProvider, registerWidget } from "../react/SchemaComponent.mjs";
2
+ //#region src/preact/SchemaComponent.ts
3
+ /**
4
+ * Preact entry point for `<SchemaComponent>`, `<SchemaProvider>`,
5
+ * `<SchemaField>` and `registerWidget`.
6
+ *
7
+ * Every export below is the React adapter export imported under the
8
+ * same name and re-exported. The Preact entry point works because the
9
+ * consumer aliases `react` to `preact/compat` in their bundler — see
10
+ * the "Preact support" section of the README for the alias config
11
+ * required in Vite, Next.js, and Node consumers. Without the alias,
12
+ * the React imports here resolve to the real React runtime, which
13
+ * defeats the purpose of importing from the Preact entry point.
14
+ *
15
+ * Implementation note: the renderer tree is intentionally identical to
16
+ * the React adapter. `preact/compat` translates React-style `onChange`
17
+ * to `onInput`, matching the "fires on every keystroke" semantics that
18
+ * the controlled inputs in `react/headlessRenderers.tsx` rely on.
19
+ *
20
+ * The `import` + plain `export { ... }` idiom below (rather than
21
+ * `export { ... } from`) is deliberate: the project's lint rules ban
22
+ * `export ... from` outside `index` files, so each binding is brought
23
+ * into local scope before being exported.
24
+ */
25
+ //#endregion
26
+ export { SchemaComponent, SchemaField, SchemaProvider, registerWidget };
@@ -0,0 +1,2 @@
1
+ import { SchemaErrorBoundary, SchemaErrorBoundaryProps } from "../react/SchemaErrorBoundary.mjs";
2
+ export { SchemaErrorBoundary, type SchemaErrorBoundaryProps };
@@ -0,0 +1,20 @@
1
+ import { SchemaErrorBoundary } from "../react/SchemaErrorBoundary.mjs";
2
+ //#region src/preact/SchemaErrorBoundary.ts
3
+ /**
4
+ * Preact entry point for `<SchemaErrorBoundary>`.
5
+ *
6
+ * The export is the React adapter export imported under the same name
7
+ * and re-exported. The Preact entry point works because the consumer
8
+ * aliases `react` to `preact/compat` in their bundler — see the
9
+ * "Preact support" section of the README for the alias config required
10
+ * in Vite, Next.js, and Node consumers. The class component relies on
11
+ * `componentDidCatch` / `getDerivedStateFromError`, both of which are
12
+ * provided by `preact/compat`.
13
+ *
14
+ * The `import` + plain `export { ... }` idiom below (rather than
15
+ * `export { ... } from`) is deliberate: the project's lint rules ban
16
+ * `export ... from` outside `index` files, so each binding is brought
17
+ * into local scope before being exported.
18
+ */
19
+ //#endregion
20
+ export { SchemaErrorBoundary };
@@ -0,0 +1,2 @@
1
+ import { SchemaView, SchemaViewProps } from "../react/SchemaView.mjs";
2
+ export { SchemaView, type SchemaViewProps };
@@ -0,0 +1,22 @@
1
+ import { SchemaView } from "../react/SchemaView.mjs";
2
+ //#region src/preact/SchemaView.ts
3
+ /**
4
+ * Preact entry point for `<SchemaView>` — the read-only renderer.
5
+ *
6
+ * The export is the React adapter export imported under the same name
7
+ * and re-exported. The Preact entry point works because the consumer
8
+ * aliases `react` to `preact/compat` in their bundler — see the
9
+ * "Preact support" section of the README for the alias config required
10
+ * in Vite, Next.js, and Node consumers.
11
+ *
12
+ * Limitation: React Server Components is React-only. Under Preact,
13
+ * `<SchemaView>` runs as a client component and the zero-client-JS
14
+ * deployment story documented in the React README does not apply.
15
+ *
16
+ * The `import` + plain `export { ... }` idiom below (rather than
17
+ * `export { ... } from`) is deliberate: the project's lint rules ban
18
+ * `export ... from` outside `index` files, so each binding is brought
19
+ * into local scope before being exported.
20
+ */
21
+ //#endregion
22
+ export { SchemaView };
@@ -0,0 +1,2 @@
1
+ import { headlessResolver } from "../react/headless.mjs";
2
+ export { headlessResolver };
@@ -0,0 +1,18 @@
1
+ import { headlessResolver } from "../react/headless.mjs";
2
+ //#region src/preact/headless.ts
3
+ /**
4
+ * Preact entry point for the default headless `ComponentResolver`.
5
+ *
6
+ * The export is the React adapter export imported under the same name
7
+ * and re-exported. The Preact entry point works because the consumer
8
+ * aliases `react` to `preact/compat` in their bundler — see the
9
+ * "Preact support" section of the README for the alias config required
10
+ * in Vite, Next.js, and Node consumers.
11
+ *
12
+ * The `import` + plain `export { ... }` idiom below (rather than
13
+ * `export { ... } from`) is deliberate: the project's lint rules ban
14
+ * `export ... from` outside `index` files, so each binding is brought
15
+ * into local scope before being exported.
16
+ */
17
+ //#endregion
18
+ export { headlessResolver };
@@ -1,270 +1,3 @@
1
- import { j as WalkedField, w as SchemaMeta } from "../types-BrYbjC7_.mjs";
2
- import { t as Diagnostic } from "../diagnostics-BTrm3O6J.mjs";
3
- import { SchemaIoSide } from "../core/adapter.mjs";
4
- import { ComponentResolver, RenderProps, WidgetMap } from "../core/renderer.mjs";
5
- import { t as SchemaError } from "../errors-Dki7tji4.mjs";
6
- import { FromJSONSchema, PathOfType, RejectUnrepresentableZod } from "../core/typeInference.mjs";
7
- import { a as InferredValue, i as InferredOutputValue, n as InferSchemaValue, r as InferredInputValue, t as InferFields } from "../inferValue-Ce-PviSD.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 `react/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
- 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;
213
- /**
214
- * Infer the schema's output type for SchemaField path inference.
215
- */
216
- type InferSchemaType<T> = T extends z.ZodType ? z.infer<T> : T extends object ? unknown extends FromJSONSchema<T> ? unknown : FromJSONSchema<T> : unknown;
217
- /**
218
- * Props accepted by {@link SchemaField}. The generic `P` constrains
219
- * `path` to dot-paths reachable through the schema's inferred value
220
- * type — typed schemas get autocomplete; runtime schemas fall back to
221
- * `string`.
222
- *
223
- * @group Components
224
- */
225
- interface SchemaFieldProps<T = unknown, Ref extends string | undefined = undefined, P extends string = PathOfType<InferSchemaType<T>> | (string extends PathOfType<InferSchemaType<T>> ? string : never)> {
226
- /**
227
- * Dot-separated path to the field (e.g. "address.city").
228
- * When the schema is a Zod schema or typed `as const`, only valid
229
- * paths are accepted. Falls back to `string` for runtime schemas.
230
- */
231
- path: P;
232
- /**
233
- * The schema to extract the field from. Subject to the same
234
- * unrepresentable-Zod rejection as {@link SchemaComponentProps.schema}.
235
- */
236
- schema: RejectUnrepresentableZod<T>;
237
- /** For OpenAPI: a ref string. */
238
- ref?: Ref;
239
- /** Current value of the field at the given path. */
240
- value?: unknown;
241
- /** Called with the updated root value when this field changes. */
242
- onChange?: (value: unknown) => void;
243
- /** Override meta for this specific field. */
244
- meta?: SchemaMeta;
245
- /** Run validation on change. */
246
- validate?: boolean;
247
- onValidationError?: (error: unknown) => void;
248
- }
249
- /**
250
- * Render a single field from a schema by dot-separated `path`.
251
- *
252
- * Walks the full schema tree and resolves the field at the supplied
253
- * `path`, then renders only that field through the same resolver
254
- * pipeline as {@link SchemaComponent}. Useful for embedding individual
255
- * fields inside bespoke layouts.
256
- *
257
- * @group Components
258
- */
259
- declare function SchemaField<T = unknown, Ref extends string | undefined = undefined, P extends string = PathOfType<InferSchemaType<T>> | (string extends PathOfType<InferSchemaType<T>> ? string : never)>({
260
- path,
261
- schema: schemaInput,
262
- ref: refInput,
263
- value,
264
- onChange,
265
- meta: fieldMeta,
266
- validate,
267
- onValidationError
268
- }: SchemaFieldProps<T, Ref, P>): ReactNode;
269
- //#endregion
270
- export { type InferFields, type InferredInputValue, type InferredOutputValue, type InferredValue, SchemaComponent, SchemaComponentProps, SchemaField, SchemaFieldProps, SchemaProvider, __clearGlobalWidgets, joinPath, registerWidget, renderField, sanitisePrefix };
1
+ import { a as InferredValue, i as InferredOutputValue, r as InferredInputValue, t as InferFields } from "../inferValue-eAnh50EM.mjs";
2
+ import { a as SchemaProvider, c as registerWidget, i as SchemaFieldProps, l as renderField, n as SchemaComponentProps, o as __clearGlobalWidgets, r as SchemaField, s as joinPath, t as SchemaComponent, u as sanitisePrefix } from "../SchemaComponent-B__6-5-E.mjs";
3
+ export { InferFields, InferredInputValue, InferredOutputValue, InferredValue, SchemaComponent, SchemaComponentProps, SchemaField, SchemaFieldProps, SchemaProvider, __clearGlobalWidgets, joinPath, registerWidget, renderField, sanitisePrefix };