schema-components 1.5.1 → 1.6.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.
- package/CHANGELOG.md +10 -0
- package/dist/core/adapter.d.mts +1 -1
- package/dist/core/renderer.d.mts +1 -1
- package/dist/core/types.d.mts +1 -1
- package/dist/core/walker.d.mts +1 -1
- package/dist/html/a11y.d.mts +1 -1
- package/dist/html/renderToHtml.d.mts +1 -1
- package/dist/openapi/components.d.mts +1 -1
- package/dist/openapi/parser.d.mts +1 -1
- package/dist/react/SchemaComponent.d.mts +1 -1
- package/dist/react/SchemaComponent.mjs +45 -10
- package/dist/react/SchemaView.d.mts +1 -1
- package/dist/react/headless.d.mts +1 -1
- package/dist/themes/mui.d.mts +1 -1
- package/dist/themes/shadcn.d.mts +1 -1
- package/dist/{types-DDCD6Xnx.d.mts → types-CnlV7bBK.d.mts} +9 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [1.6.0](https://github.com/Mearman/schema-components/compare/v1.5.1...v1.6.0) (2026-05-14)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* add per-field onValidationError and writeOnly tests ([bc65589](https://github.com/Mearman/schema-components/commit/bc655893601b8e015dd3c717eccc9bf9dffbbb42))
|
|
6
|
+
|
|
7
|
+
### Tests
|
|
8
|
+
|
|
9
|
+
* add writeOnly behaviour tests across all renderers ([abfb293](https://github.com/Mearman/schema-components/commit/abfb293498efc4d4095dec072fd1e5a9c3239035))
|
|
10
|
+
|
|
1
11
|
## [1.5.1](https://github.com/Mearman/schema-components/compare/v1.5.0...v1.5.1) (2026-05-14)
|
|
2
12
|
|
|
3
13
|
### Bug Fixes
|
package/dist/core/adapter.d.mts
CHANGED
package/dist/core/renderer.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as mergeResolvers, C as HtmlResolver, D as getHtmlRenderFn, E as RenderProps, O as getRenderFunction, S as HtmlRenderProps, T as RenderFunction, b as ComponentResolver, j as typeToKey, k as mergeHtmlResolvers, w as RESOLVER_KEYS, x as HtmlRenderFunction, y as BaseFieldProps } from "../types-
|
|
1
|
+
import { A as mergeResolvers, C as HtmlResolver, D as getHtmlRenderFn, E as RenderProps, O as getRenderFunction, S as HtmlRenderProps, T as RenderFunction, b as ComponentResolver, j as typeToKey, k as mergeHtmlResolvers, w as RESOLVER_KEYS, x as HtmlRenderFunction, y as BaseFieldProps } from "../types-CnlV7bBK.mjs";
|
|
2
2
|
export { BaseFieldProps, ComponentResolver, HtmlRenderFunction, HtmlRenderProps, HtmlResolver, RESOLVER_KEYS, RenderFunction, RenderProps, getHtmlRenderFn, getRenderFunction, mergeHtmlResolvers, mergeResolvers, typeToKey };
|
package/dist/core/types.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as HtmlResolver, E as RenderProps, S as HtmlRenderProps, T as RenderFunction, _ as WalkedField, a as FromJSONSchema, b as ComponentResolver, c as InferResponseFields, d as OpenAPIResponseType, f as PathOfType, g as TypeAtPath, h as SchemaType, i as FieldOverrides, l as JsonObject, m as SchemaMeta, n as FieldConstraints, o as InferParameterOverrides, p as ResolveOpenAPIRef, r as FieldOverride, s as InferRequestBodyFields, t as Editability, u as OpenAPIRequestBodyType, v as resolveEditability, x as HtmlRenderFunction, y as BaseFieldProps } from "../types-
|
|
1
|
+
import { C as HtmlResolver, E as RenderProps, S as HtmlRenderProps, T as RenderFunction, _ as WalkedField, a as FromJSONSchema, b as ComponentResolver, c as InferResponseFields, d as OpenAPIResponseType, f as PathOfType, g as TypeAtPath, h as SchemaType, i as FieldOverrides, l as JsonObject, m as SchemaMeta, n as FieldConstraints, o as InferParameterOverrides, p as ResolveOpenAPIRef, r as FieldOverride, s as InferRequestBodyFields, t as Editability, u as OpenAPIRequestBodyType, v as resolveEditability, x as HtmlRenderFunction, y as BaseFieldProps } from "../types-CnlV7bBK.mjs";
|
|
2
2
|
import { i as SchemaRenderError, n as SchemaFieldError, r as SchemaNormalisationError, t as SchemaError } from "../errors-DIKI2C78.mjs";
|
|
3
3
|
export { BaseFieldProps, ComponentResolver, Editability, FieldConstraints, FieldOverride, FieldOverrides, FromJSONSchema, HtmlRenderFunction, HtmlRenderProps, HtmlResolver, InferParameterOverrides, InferRequestBodyFields, InferResponseFields, JsonObject, OpenAPIRequestBodyType, OpenAPIResponseType, PathOfType, RenderFunction, RenderProps, ResolveOpenAPIRef, SchemaError, SchemaFieldError, SchemaMeta, SchemaNormalisationError, SchemaRenderError, SchemaType, TypeAtPath, WalkedField, resolveEditability };
|
package/dist/core/walker.d.mts
CHANGED
package/dist/html/a11y.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as HtmlResolver, S as HtmlRenderProps, m as SchemaMeta, x as HtmlRenderFunction } from "../types-
|
|
1
|
+
import { C as HtmlResolver, S as HtmlRenderProps, m as SchemaMeta, x as HtmlRenderFunction } from "../types-CnlV7bBK.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/html/renderToHtml.d.ts
|
|
4
4
|
interface RenderToHtmlOptions {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as InferResponseFields, m as SchemaMeta, o as InferParameterOverrides, r as FieldOverride, s as InferRequestBodyFields } from "../types-
|
|
1
|
+
import { c as InferResponseFields, m as SchemaMeta, o as InferParameterOverrides, r as FieldOverride, s as InferRequestBodyFields } from "../types-CnlV7bBK.mjs";
|
|
2
2
|
import { WidgetMap } from "../react/SchemaComponent.mjs";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as RenderProps, _ as WalkedField, a as FromJSONSchema, b as ComponentResolver, f as PathOfType, i as FieldOverrides, m as SchemaMeta, p as ResolveOpenAPIRef, r as FieldOverride } from "../types-
|
|
1
|
+
import { E as RenderProps, _ as WalkedField, a as FromJSONSchema, b as ComponentResolver, f as PathOfType, i as FieldOverrides, m as SchemaMeta, p as ResolveOpenAPIRef, r as FieldOverride } from "../types-CnlV7bBK.mjs";
|
|
2
2
|
import { t as SchemaError } from "../errors-DIKI2C78.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { ReactNode } from "react";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { isObject, toRecord } from "../core/guards.mjs";
|
|
2
|
+
import { isObject, toRecord, toRecordOrUndefined } from "../core/guards.mjs";
|
|
3
3
|
import { normaliseSchema } from "../core/adapter.mjs";
|
|
4
4
|
import { SchemaFieldError, SchemaNormalisationError, SchemaRenderError } from "../core/errors.mjs";
|
|
5
5
|
import { getRenderFunction, mergeResolvers } from "../core/renderer.mjs";
|
|
@@ -79,14 +79,21 @@ function SchemaComponent({ schema: schemaInput, ref: refInput, value, onChange,
|
|
|
79
79
|
throw error;
|
|
80
80
|
}
|
|
81
81
|
const handleChange = useCallback((nextValue) => {
|
|
82
|
-
if (validate)
|
|
82
|
+
if (validate) {
|
|
83
|
+
const error = runValidation(zodSchema, jsonSchema, nextValue);
|
|
84
|
+
if (error !== void 0) {
|
|
85
|
+
onValidationError?.(error);
|
|
86
|
+
dispatchFieldErrors(fields, error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
83
89
|
onChange?.(nextValue);
|
|
84
90
|
}, [
|
|
85
91
|
validate,
|
|
86
92
|
zodSchema,
|
|
87
93
|
jsonSchema,
|
|
88
94
|
onChange,
|
|
89
|
-
onValidationError
|
|
95
|
+
onValidationError,
|
|
96
|
+
fields
|
|
90
97
|
]);
|
|
91
98
|
const tree = walk(jsonSchema, {
|
|
92
99
|
componentMeta: mergedMeta,
|
|
@@ -99,15 +106,12 @@ function SchemaComponent({ schema: schemaInput, ref: refInput, value, onChange,
|
|
|
99
106
|
};
|
|
100
107
|
return renderField(tree, value ?? tree.defaultValue, handleChange, userResolver, renderChild, instanceWidgets, contextWidgets);
|
|
101
108
|
}
|
|
102
|
-
function runValidation(zodSchema, jsonSchema, value
|
|
109
|
+
function runValidation(zodSchema, jsonSchema, value) {
|
|
103
110
|
if (zodSchema !== void 0 && isObject(zodSchema)) {
|
|
104
111
|
const safeParseFn = zodSchema.safeParse;
|
|
105
112
|
if (isCallable(safeParseFn)) {
|
|
106
113
|
const result = safeParseFn(value);
|
|
107
|
-
if (isObject(result) && "success" in result && result.success !== true)
|
|
108
|
-
onError?.(result.error);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
114
|
+
if (isObject(result) && "success" in result && result.success !== true) return result.error;
|
|
111
115
|
return;
|
|
112
116
|
}
|
|
113
117
|
}
|
|
@@ -116,7 +120,7 @@ function runValidation(zodSchema, jsonSchema, value, onError) {
|
|
|
116
120
|
const safeParseFn = parsed.safeParse;
|
|
117
121
|
if (isCallable(safeParseFn)) {
|
|
118
122
|
const result = safeParseFn(value);
|
|
119
|
-
if (isObject(result) && "success" in result && result.success !== true)
|
|
123
|
+
if (isObject(result) && "success" in result && result.success !== true) return result.error;
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
}
|
|
@@ -197,7 +201,8 @@ function SchemaField({ path, schema: schemaInput, ref: refInput, value, onChange
|
|
|
197
201
|
const handleChange = useCallback((nextFieldValue) => {
|
|
198
202
|
if (validate) {
|
|
199
203
|
const newRootValue = setNestedValue(value, path, nextFieldValue);
|
|
200
|
-
runValidation(zodSchema, jsonSchema, newRootValue
|
|
204
|
+
const error = runValidation(zodSchema, jsonSchema, newRootValue);
|
|
205
|
+
if (error !== void 0) onValidationError?.(error);
|
|
201
206
|
}
|
|
202
207
|
const newRootValue = setNestedValue(value, path, nextFieldValue);
|
|
203
208
|
onChange?.(newRootValue);
|
|
@@ -280,6 +285,36 @@ function setNestedValue(root, path, leafValue) {
|
|
|
280
285
|
}
|
|
281
286
|
return result;
|
|
282
287
|
}
|
|
288
|
+
function isFieldErrorCallback(value) {
|
|
289
|
+
return typeof value === "function";
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Dispatch Zod errors to per-field onValidationError callbacks.
|
|
293
|
+
* Walks the fields override tree and matches errors by path prefix.
|
|
294
|
+
*/
|
|
295
|
+
function dispatchFieldErrors(fields, error) {
|
|
296
|
+
if (fields === void 0 || !isObject(error)) return;
|
|
297
|
+
if (!("issues" in error)) return;
|
|
298
|
+
const issues = error.issues;
|
|
299
|
+
if (!Array.isArray(issues)) return;
|
|
300
|
+
const overrides = toRecordOrUndefined(fields);
|
|
301
|
+
if (overrides === void 0) return;
|
|
302
|
+
for (const [key, override] of Object.entries(overrides)) {
|
|
303
|
+
if (override === void 0 || typeof override !== "object") continue;
|
|
304
|
+
if (override === null) continue;
|
|
305
|
+
if (!("onValidationError" in override)) continue;
|
|
306
|
+
const fieldCallback = override.onValidationError;
|
|
307
|
+
if (typeof fieldCallback !== "function") continue;
|
|
308
|
+
const fieldErrors = issues.filter((issue) => {
|
|
309
|
+
if (!isObject(issue)) return false;
|
|
310
|
+
if (!("path" in issue)) return false;
|
|
311
|
+
const path = issue.path;
|
|
312
|
+
if (!Array.isArray(path)) return false;
|
|
313
|
+
return path[0] === key;
|
|
314
|
+
});
|
|
315
|
+
if (fieldErrors.length > 0 && isFieldErrorCallback(fieldCallback)) fieldCallback({ issues: fieldErrors });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
283
318
|
function isCallable(value) {
|
|
284
319
|
return typeof value === "function";
|
|
285
320
|
}
|
package/dist/themes/mui.d.mts
CHANGED
package/dist/themes/shadcn.d.mts
CHANGED
|
@@ -166,14 +166,18 @@ type Editability = "presentation" | "input" | "editable";
|
|
|
166
166
|
declare function resolveEditability(propertyMeta: SchemaMeta | undefined, componentMeta: SchemaMeta | undefined, rootMeta: SchemaMeta | undefined): Editability;
|
|
167
167
|
/**
|
|
168
168
|
* Recursive mapped type that mirrors a schema's shape for per-field
|
|
169
|
-
*
|
|
170
|
-
* and also accept
|
|
169
|
+
* overrides. Each leaf accepts schema meta overrides and an optional
|
|
170
|
+
* per-field validation error callback. Objects recurse and also accept
|
|
171
|
+
* their own overrides.
|
|
171
172
|
*/
|
|
172
|
-
type FieldOverrides<T> = { [K in keyof T]?: T[K] extends object ? FieldOverrides<T[K]> &
|
|
173
|
+
type FieldOverrides<T> = { [K in keyof T]?: T[K] extends object ? FieldOverrides<T[K]> & FieldOverride : FieldOverride };
|
|
173
174
|
/**
|
|
174
|
-
*
|
|
175
|
+
* Per-field override. Extends SchemaMeta with a React-layer callback
|
|
176
|
+
* for per-field validation errors.
|
|
175
177
|
*/
|
|
176
|
-
type FieldOverride = Partial<SchemaMeta
|
|
178
|
+
type FieldOverride = Partial<SchemaMeta> & {
|
|
179
|
+
/** Called with the ZodError when this field fails validation. */onValidationError?: (error: unknown) => void;
|
|
180
|
+
};
|
|
177
181
|
type SchemaType = "string" | "number" | "boolean" | "null" | "enum" | "literal" | "object" | "array" | "record" | "union" | "discriminatedUnion" | "optional" | "nullable" | "default" | "readonly" | "pipe" | "lazy" | "file" | "unknown";
|
|
178
182
|
interface WalkedField {
|
|
179
183
|
type: SchemaType;
|