schema-components 1.29.0 → 2.0.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 (90) hide show
  1. package/README.md +38 -16
  2. package/dist/core/adapter.d.mts +213 -3
  3. package/dist/core/adapter.mjs +1 -1
  4. package/dist/core/constraintHint.d.mts +15 -0
  5. package/dist/core/constraintHint.mjs +24 -0
  6. package/dist/core/constraints.d.mts +2 -2
  7. package/dist/core/constraints.mjs +1 -1
  8. package/dist/core/diagnostics.d.mts +1 -1
  9. package/dist/core/errors.d.mts +1 -1
  10. package/dist/core/fieldOrder.d.mts +1 -1
  11. package/dist/core/formats.d.mts +1 -1
  12. package/dist/core/idPath.d.mts +35 -5
  13. package/dist/core/idPath.mjs +79 -7
  14. package/dist/core/inferValue.d.mts +2 -0
  15. package/dist/core/inferValue.mjs +1 -0
  16. package/dist/core/limits.d.mts +1 -1
  17. package/dist/core/limits.mjs +5 -0
  18. package/dist/core/merge.d.mts +12 -1
  19. package/dist/core/merge.mjs +66 -3
  20. package/dist/core/normalise.d.mts +1 -1
  21. package/dist/core/normalise.mjs +1 -1
  22. package/dist/core/openapi30.mjs +1 -1
  23. package/dist/core/ref.d.mts +1 -1
  24. package/dist/core/refChain.d.mts +3 -4
  25. package/dist/core/refChain.mjs +2 -3
  26. package/dist/core/renderer.d.mts +199 -2
  27. package/dist/core/swagger2.d.mts +1 -1
  28. package/dist/core/swagger2.mjs +1 -1
  29. package/dist/core/typeInference.d.mts +3 -3
  30. package/dist/core/types.d.mts +1 -1
  31. package/dist/core/unionMatch.d.mts +1 -1
  32. package/dist/core/uri.d.mts +12 -4
  33. package/dist/core/uri.mjs +30 -4
  34. package/dist/core/walkBuilders.d.mts +18 -6
  35. package/dist/core/walkBuilders.mjs +3 -1
  36. package/dist/core/walker.d.mts +1 -1
  37. package/dist/core/walker.mjs +5 -0
  38. package/dist/{diagnostics-ByEzkjrA.d.mts → diagnostics-BTrm3O6J.d.mts} +1 -1
  39. package/dist/{errors-D8JndRwI.d.mts → errors-Dki7tji4.d.mts} +1 -1
  40. package/dist/html/a11y.d.mts +3 -7
  41. package/dist/html/a11y.mjs +1 -16
  42. package/dist/html/renderToHtml.d.mts +22 -9
  43. package/dist/html/renderToHtml.mjs +2 -1
  44. package/dist/html/renderToHtmlStream.d.mts +24 -11
  45. package/dist/html/renderToHtmlStream.mjs +2 -1
  46. package/dist/html/renderers.d.mts +2 -33
  47. package/dist/html/renderers.mjs +39 -91
  48. package/dist/html/streamRenderers.d.mts +3 -3
  49. package/dist/html/streamRenderers.mjs +13 -8
  50. package/dist/inferValue-PPXWJpbN.d.mts +77 -0
  51. package/dist/{limits-DswmqWuy.d.mts → limits-x4OiyJxh.d.mts} +5 -0
  52. package/dist/{normalise-Db1xaxgx.mjs → normalise-DB-Xtjmn.mjs} +43 -2
  53. package/dist/openapi/ApiCallbacks.d.mts +1 -1
  54. package/dist/openapi/ApiLinks.d.mts +1 -1
  55. package/dist/openapi/ApiResponseHeaders.d.mts +1 -1
  56. package/dist/openapi/ApiSecurity.d.mts +1 -1
  57. package/dist/openapi/ApiSecurity.mjs +21 -8
  58. package/dist/openapi/bundle.d.mts +31 -0
  59. package/dist/openapi/components.d.mts +41 -10
  60. package/dist/openapi/components.mjs +19 -13
  61. package/dist/openapi/parser.d.mts +13 -13
  62. package/dist/openapi/parser.mjs +12 -12
  63. package/dist/openapi/resolve.d.mts +38 -49
  64. package/dist/openapi/resolve.mjs +62 -56
  65. package/dist/react/SchemaComponent.d.mts +19 -95
  66. package/dist/react/SchemaComponent.mjs +12 -1
  67. package/dist/react/SchemaView.d.mts +11 -7
  68. package/dist/react/SchemaView.mjs +3 -1
  69. package/dist/react/a11y.d.mts +74 -7
  70. package/dist/react/a11y.mjs +67 -6
  71. package/dist/react/fieldPath.d.mts +16 -1
  72. package/dist/react/fieldPath.mjs +25 -1
  73. package/dist/react/fieldShell.d.mts +49 -0
  74. package/dist/react/fieldShell.mjs +37 -0
  75. package/dist/react/headless.d.mts +1 -1
  76. package/dist/react/headlessRenderers.d.mts +2 -2
  77. package/dist/react/headlessRenderers.mjs +123 -54
  78. package/dist/{ref-CPh8rKQ3.d.mts → ref-DdsbekXX.d.mts} +33 -1
  79. package/dist/themes/mantine.d.mts +36 -20
  80. package/dist/themes/mantine.mjs +179 -150
  81. package/dist/themes/mui.d.mts +47 -21
  82. package/dist/themes/mui.mjs +259 -222
  83. package/dist/themes/radix.d.mts +38 -23
  84. package/dist/themes/radix.mjs +208 -180
  85. package/dist/themes/shadcn.d.mts +6 -3
  86. package/dist/themes/shadcn.mjs +93 -93
  87. package/dist/{types-C2Ay1FEh.d.mts → types-BrYbjC7_.d.mts} +7 -0
  88. package/package.json +4 -1
  89. package/dist/adapter-DcWi4XXn.d.mts +0 -223
  90. package/dist/renderer-OaOz-n6-.d.mts +0 -185
@@ -1,185 +0,0 @@
1
- import { E as StringConstraints, f as FileConstraints, j as WalkedField, t as ArrayConstraints, w as SchemaMeta, x as ObjectConstraints, y as NumberConstraints } from "./types-C2Ay1FEh.mjs";
2
-
3
- //#region src/core/renderer.d.ts
4
- /**
5
- * Flat intersection of all constraint types.
6
- * Used in renderer props where the render function receives the union
7
- * but knows (by resolver key) which subset applies.
8
- *
9
- * The walker's discriminated WalkedField enforces type-correct constraints
10
- * at construction time; the renderer consumes them as this flat type.
11
- */
12
- type AllConstraints = StringConstraints & NumberConstraints & ArrayConstraints & ObjectConstraints & FileConstraints;
13
- /**
14
- * Properties available on every schema field, regardless of rendering target.
15
- * Both React and HTML renderers receive these.
16
- *
17
- * Per-type schema data — enum values, object fields, array element schema,
18
- * union options, record key/value types, tuple `prefixItems`, conditional
19
- * if/then/else clauses, negation `negated`, recursive `refTarget`, literal
20
- * values — lives on the discriminated `tree`. Renderers narrow on
21
- * `tree.type` and read from the matching variant; there are no duplicate
22
- * sibling fields on these props.
23
- */
24
- interface BaseFieldProps {
25
- /** Current field value. */
26
- value: unknown;
27
- /** Whether to render as read-only display. */
28
- readOnly: boolean;
29
- /** Whether to render as an empty input. */
30
- writeOnly: boolean;
31
- /** Schema metadata for this field. */
32
- meta: SchemaMeta;
33
- /** Constraints from schema checks. */
34
- constraints: AllConstraints;
35
- /** Dot-separated path from root (e.g. "address.city"). */
36
- path: string;
37
- /** Example values from the schema's `examples` keyword. */
38
- examples?: unknown[];
39
- /** Walked field tree for recursive rendering. */
40
- tree: WalkedField;
41
- }
42
- /**
43
- * Props for React render functions. Extends BaseFieldProps with:
44
- * - `onChange` — callback to propagate value changes back to state
45
- * - `renderChild` — recursively renders a child field, threading onChange
46
- */
47
- interface RenderProps extends BaseFieldProps {
48
- /** Callback to update the field value. */
49
- onChange: (value: unknown) => void;
50
- /**
51
- * Render a child field. Theme adapters call this to recursively render
52
- * nested structures (object fields, array elements, union options).
53
- * The resolver and rendering context are already wired in.
54
- *
55
- * @param tree - The walked field tree for the child
56
- * @param value - The child's current value
57
- * @param onChange - Callback receiving the child's next value
58
- * @param pathSuffix - Path segment from the parent (e.g. "city",
59
- * "[0]"). Joined to the parent's path with a dot, or substituted
60
- * when the parent acts as a transparent wrapper (union options).
61
- * Required for every container — without it children inherit no
62
- * path and `inputId()` will throw.
63
- */
64
- renderChild: (tree: WalkedField, value: unknown, onChange: (v: unknown) => void, pathSuffix?: string) => unknown;
65
- }
66
- /**
67
- * Props for HTML render functions. Extends BaseFieldProps with:
68
- * - `renderChild` — recursively renders a child field to HTML string
69
- *
70
- * No `onChange` — HTML rendering is pure output with no event handling.
71
- */
72
- interface HtmlRenderProps extends BaseFieldProps {
73
- /**
74
- * Render a child field to an HTML string. Theme adapters call this
75
- * to recursively render nested structures.
76
- *
77
- * @param tree - The walked field tree for the child
78
- * @param value - The child's current value
79
- * @param pathSuffix - Path segment from the parent (e.g. "city",
80
- * "[0]"). When omitted, the child's description is used as fallback.
81
- */
82
- renderChild: (tree: WalkedField, value: unknown, pathSuffix?: string) => string;
83
- }
84
- /**
85
- * Build the `RenderProps` object handed to a resolver render function or a
86
- * widget. Used by both the server-side `<SchemaView>` (which has no
87
- * `onChange`) and the client-side `<SchemaComponent>` (which threads an
88
- * `onChange` callback).
89
- *
90
- * When `onChange` is `undefined` the caller is rendering in read-only mode:
91
- * a noop `onChange` is wired up, `readOnly` is forced to `true`, and
92
- * `writeOnly` is forced to `false`. Otherwise the editability is taken
93
- * from `tree.editability`.
94
- */
95
- declare function buildRenderProps(tree: WalkedField, value: unknown, onChange: ((next: unknown) => void) | undefined, renderChild: RenderProps["renderChild"], path: string): RenderProps;
96
- /**
97
- * Signature for a React render function attached to a
98
- * {@link ComponentResolver}. Receives the per-field {@link RenderProps}
99
- * built by the walker and returns any ReactNode-compatible value.
100
- */
101
- type RenderFunction = (props: RenderProps) => unknown;
102
- /**
103
- * Theme adapter — maps every schema field type to its React renderer.
104
- * Unset keys fall back to the headless resolver. Pass to
105
- * `SchemaProvider` (or `SchemaView.resolver`) to drive every
106
- * schema-driven render with a specific theme.
107
- */
108
- interface ComponentResolver {
109
- string?: RenderFunction;
110
- number?: RenderFunction;
111
- boolean?: RenderFunction;
112
- null?: RenderFunction;
113
- enum?: RenderFunction;
114
- object?: RenderFunction;
115
- array?: RenderFunction;
116
- tuple?: RenderFunction;
117
- record?: RenderFunction;
118
- union?: RenderFunction;
119
- discriminatedUnion?: RenderFunction;
120
- conditional?: RenderFunction;
121
- negation?: RenderFunction;
122
- recursive?: RenderFunction;
123
- literal?: RenderFunction;
124
- file?: RenderFunction;
125
- never?: RenderFunction;
126
- unknown?: RenderFunction;
127
- }
128
- /** An HTML render function returns a string. */
129
- type HtmlRenderFunction = (props: HtmlRenderProps) => string;
130
- /**
131
- * HTML resolver — maps schema types to HTML string renderers.
132
- * Structurally mirrors ComponentResolver but produces strings.
133
- */
134
- interface HtmlResolver {
135
- string?: HtmlRenderFunction;
136
- number?: HtmlRenderFunction;
137
- boolean?: HtmlRenderFunction;
138
- null?: HtmlRenderFunction;
139
- enum?: HtmlRenderFunction;
140
- object?: HtmlRenderFunction;
141
- array?: HtmlRenderFunction;
142
- tuple?: HtmlRenderFunction;
143
- record?: HtmlRenderFunction;
144
- union?: HtmlRenderFunction;
145
- discriminatedUnion?: HtmlRenderFunction;
146
- conditional?: HtmlRenderFunction;
147
- negation?: HtmlRenderFunction;
148
- recursive?: HtmlRenderFunction;
149
- literal?: HtmlRenderFunction;
150
- file?: HtmlRenderFunction;
151
- never?: HtmlRenderFunction;
152
- unknown?: HtmlRenderFunction;
153
- }
154
- /**
155
- * Canonical list of resolver keys, one per {@link WalkedField} variant.
156
- * Iterated by the resolver merge helpers so adding a new key here is the
157
- * single point of change when a new field variant is introduced.
158
- */
159
- declare const RESOLVER_KEYS: readonly ["string", "number", "boolean", "null", "enum", "object", "array", "tuple", "record", "union", "discriminatedUnion", "conditional", "negation", "literal", "file", "never", "unknown"];
160
- type ResolverKey = (typeof RESOLVER_KEYS)[number];
161
- /**
162
- * Map a schema type to the resolver key that handles it.
163
- * Every WalkedField variant has a direct resolver key — exhaustive switch
164
- * ensures new variants surface as a type error rather than silently
165
- * falling through to "unknown".
166
- */
167
- declare function typeToKey(type: WalkedField["type"]): ResolverKey;
168
- /**
169
- * Look up the render function for a schema type in a ComponentResolver.
170
- */
171
- declare function getRenderFunction(type: WalkedField["type"], resolver: ComponentResolver): RenderFunction | undefined;
172
- /**
173
- * Look up the render function for a schema type in an HtmlResolver.
174
- */
175
- declare function getHtmlRenderFn(type: WalkedField["type"], resolver: HtmlResolver): HtmlRenderFunction | undefined;
176
- /**
177
- * Merge two ComponentResolvers — user values take priority, fallback fills gaps.
178
- */
179
- declare function mergeResolvers(user: ComponentResolver, fallback: ComponentResolver): ComponentResolver;
180
- /**
181
- * Merge two HtmlResolvers — user values take priority, fallback fills gaps.
182
- */
183
- declare function mergeHtmlResolvers(user: HtmlResolver, fallback: HtmlResolver): HtmlResolver;
184
- //#endregion
185
- export { HtmlRenderProps as a, RenderFunction as c, getHtmlRenderFn as d, getRenderFunction as f, typeToKey as h, HtmlRenderFunction as i, RenderProps as l, mergeResolvers as m, BaseFieldProps as n, HtmlResolver as o, mergeHtmlResolvers as p, ComponentResolver as r, RESOLVER_KEYS as s, AllConstraints as t, buildRenderProps as u };