schema-components 1.28.2 → 1.29.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 (81) hide show
  1. package/dist/{adapter-DqlAnZ_w.d.mts → adapter-DcWi4XXn.d.mts} +60 -9
  2. package/dist/core/adapter.d.mts +2 -2
  3. package/dist/core/adapter.mjs +20 -1
  4. package/dist/core/constraints.d.mts +34 -2
  5. package/dist/core/constraints.mjs +32 -0
  6. package/dist/core/cssClasses.d.mts +1 -0
  7. package/dist/core/diagnostics.d.mts +1 -1
  8. package/dist/core/errors.d.mts +1 -1
  9. package/dist/core/errors.mjs +22 -12
  10. package/dist/core/fieldOrder.d.mts +1 -1
  11. package/dist/core/formats.d.mts +7 -1
  12. package/dist/core/formats.mjs +6 -0
  13. package/dist/core/limits.d.mts +1 -1
  14. package/dist/core/limits.mjs +1 -0
  15. package/dist/core/merge.d.mts +11 -1
  16. package/dist/core/normalise.d.mts +17 -2
  17. package/dist/core/openapiConstants.d.mts +1 -0
  18. package/dist/core/ref.d.mts +1 -1
  19. package/dist/core/renderer.d.mts +1 -1
  20. package/dist/core/renderer.mjs +5 -0
  21. package/dist/core/swagger2.d.mts +1 -1
  22. package/dist/core/typeInference.d.mts +2 -2
  23. package/dist/core/types.d.mts +1 -1
  24. package/dist/core/types.mjs +17 -0
  25. package/dist/core/unionMatch.d.mts +1 -1
  26. package/dist/core/version.d.mts +1 -1
  27. package/dist/core/walkBuilders.d.mts +48 -3
  28. package/dist/core/walkBuilders.mjs +30 -0
  29. package/dist/core/walker.d.mts +14 -1
  30. package/dist/core/walker.mjs +13 -0
  31. package/dist/{diagnostics-Cbwak-ZX.d.mts → diagnostics-ByEzkjrA.d.mts} +8 -0
  32. package/dist/{errors-DQSIK4n1.d.mts → errors-D8JndRwI.d.mts} +23 -13
  33. package/dist/html/a11y.d.mts +2 -2
  34. package/dist/html/html.d.mts +11 -0
  35. package/dist/html/html.mjs +11 -0
  36. package/dist/html/renderToHtml.d.mts +25 -5
  37. package/dist/html/renderToHtml.mjs +18 -3
  38. package/dist/html/renderToHtmlStream.d.mts +41 -9
  39. package/dist/html/renderToHtmlStream.mjs +32 -7
  40. package/dist/html/renderers.d.mts +7 -1
  41. package/dist/html/renderers.mjs +6 -0
  42. package/dist/html/streamRenderers.d.mts +31 -3
  43. package/dist/html/streamRenderers.mjs +28 -0
  44. package/dist/{limits-DJhgx5Ay.d.mts → limits-DswmqWuy.d.mts} +1 -0
  45. package/dist/openapi/ApiCallbacks.d.mts +13 -1
  46. package/dist/openapi/ApiCallbacks.mjs +7 -0
  47. package/dist/openapi/ApiLinks.d.mts +13 -1
  48. package/dist/openapi/ApiLinks.mjs +7 -0
  49. package/dist/openapi/ApiResponseHeaders.d.mts +13 -1
  50. package/dist/openapi/ApiResponseHeaders.mjs +7 -0
  51. package/dist/openapi/ApiSecurity.d.mts +14 -1
  52. package/dist/openapi/ApiSecurity.mjs +8 -0
  53. package/dist/openapi/components.d.mts +96 -12
  54. package/dist/openapi/components.mjs +71 -2
  55. package/dist/openapi/parser.d.mts +129 -2
  56. package/dist/openapi/parser.mjs +72 -0
  57. package/dist/openapi/resolve.d.mts +7 -1
  58. package/dist/react/SchemaComponent.d.mts +84 -6
  59. package/dist/react/SchemaComponent.mjs +62 -1
  60. package/dist/react/SchemaErrorBoundary.d.mts +18 -1
  61. package/dist/react/SchemaErrorBoundary.mjs +13 -1
  62. package/dist/react/SchemaView.d.mts +32 -8
  63. package/dist/react/SchemaView.mjs +20 -5
  64. package/dist/react/a11y.d.mts +1 -1
  65. package/dist/react/fieldPath.d.mts +1 -1
  66. package/dist/react/headless.d.mts +1 -1
  67. package/dist/react/headlessRenderers.d.mts +13 -2
  68. package/dist/react/headlessRenderers.mjs +12 -1
  69. package/dist/{ref-TdeMfaV_.d.mts → ref-CPh8rKQ3.d.mts} +1 -1
  70. package/dist/{renderer-Ul9taFYp.d.mts → renderer-OaOz-n6-.d.mts} +17 -1
  71. package/dist/themes/mantine.d.mts +29 -3
  72. package/dist/themes/mantine.mjs +28 -2
  73. package/dist/themes/mui.d.mts +29 -2
  74. package/dist/themes/mui.mjs +29 -2
  75. package/dist/themes/radix.d.mts +40 -3
  76. package/dist/themes/radix.mjs +39 -2
  77. package/dist/themes/shadcn.d.mts +22 -1
  78. package/dist/themes/shadcn.mjs +21 -0
  79. package/dist/{types-BTB73MB8.d.mts → types-C2Ay1FEh.d.mts} +23 -0
  80. package/dist/{version-ZzL5R6cS.d.mts → version-DL8U5RuA.d.mts} +6 -0
  81. package/package.json +5 -1
@@ -1,11 +1,21 @@
1
- import { A as UnknownField, D as StringField, b as NumberField, c as FieldBase, j as WalkedField, o as Editability, p as FileField, r as BooleanField, v as NullField, w as SchemaMeta } from "../types-BTB73MB8.mjs";
2
- import { i as DiagnosticsOptions } from "../diagnostics-Cbwak-ZX.mjs";
3
- import { t as ExternalResolver } from "../ref-TdeMfaV_.mjs";
1
+ import { A as UnknownField, D as StringField, b as NumberField, c as FieldBase, j as WalkedField, o as Editability, p as FileField, r as BooleanField, v as NullField, w as SchemaMeta } from "../types-C2Ay1FEh.mjs";
2
+ import { i as DiagnosticsOptions } from "../diagnostics-ByEzkjrA.mjs";
3
+ import { t as ExternalResolver } from "../ref-CPh8rKQ3.mjs";
4
4
 
5
5
  //#region src/core/walkBuilders.d.ts
6
+ /** Read a key from a JSON object, returning the value when it is a string and `undefined` otherwise. */
6
7
  declare function getString(obj: Record<string, unknown>, key: string): string | undefined;
8
+ /** Read a key from a JSON object, returning the value when it is an array and `undefined` otherwise. */
7
9
  declare function getArray(obj: Record<string, unknown>, key: string): unknown[] | undefined;
10
+ /** Read a key from a JSON object, returning the value when it is a plain object and `undefined` otherwise. */
8
11
  declare function getObject(obj: Record<string, unknown>, key: string): Record<string, unknown> | undefined;
12
+ /**
13
+ * Options accepted by `walk`. Use to inject meta overrides, field-level
14
+ * overrides, the root document for cross-document `$ref` resolution, a
15
+ * diagnostics sink, and an external `$ref` resolver.
16
+ *
17
+ * @group Walkers
18
+ */
9
19
  interface WalkOptions {
10
20
  componentMeta?: SchemaMeta | undefined;
11
21
  rootMeta?: SchemaMeta | undefined;
@@ -18,9 +28,34 @@ interface WalkOptions {
18
28
  /** Sync resolver for external $ref URIs. */
19
29
  externalResolver?: ExternalResolver;
20
30
  }
31
+ /**
32
+ * Extract recognised meta keywords (`readOnly`, `writeOnly`,
33
+ * `description`, `title`, `deprecated`, `default`, `component`,
34
+ * `example`, `examples`) from a JSON Schema node into the `SchemaMeta`
35
+ * shape consumed by the walker.
36
+ */
21
37
  declare function extractMetaFromJson(schema: Record<string, unknown>): SchemaMeta;
38
+ /**
39
+ * Project the meta-style keys (`readOnly`, `writeOnly`, `description`,
40
+ * `title`, `deprecated`, `component`, `visible`, `order`) out of a
41
+ * field override object into a `SchemaMeta`. Returns `undefined` when
42
+ * the override has no meta fields so the walker can short-circuit.
43
+ */
22
44
  declare function extractSchemaMetaFields(overrides: Record<string, unknown> | undefined): SchemaMeta | undefined;
45
+ /**
46
+ * Pluck the nested override at `key` from a parent field override map.
47
+ * Returns `undefined` when no override is present or when the entry is
48
+ * not a non-array object.
49
+ */
23
50
  declare function extractChildOverride(overrides: Record<string, unknown> | undefined, key: string): Record<string, unknown> | undefined;
51
+ /**
52
+ * Mutable context threaded through every recursive walk step. Carries
53
+ * the merged metadata, field overrides, document root, nullability /
54
+ * optionality flags, `$ref` cache, diagnostics sink, and per-document
55
+ * `$ref` depth bound that `walkBuilders` and the walker itself share.
56
+ *
57
+ * @group Walkers
58
+ */
24
59
  interface WalkContext {
25
60
  componentMeta: SchemaMeta | undefined;
26
61
  rootMeta: SchemaMeta | undefined;
@@ -46,11 +81,17 @@ interface WalkContext {
46
81
  declare function buildBase(schema: Record<string, unknown>, ctx: WalkContext): FieldBase & {
47
82
  editability: Editability;
48
83
  };
84
+ /** Build a walked `StringField` from a JSON Schema node. */
49
85
  declare function buildStringField(schema: Record<string, unknown>, ctx: WalkContext): StringField;
86
+ /** Build a walked `NumberField` from a JSON Schema node. */
50
87
  declare function buildNumberField(schema: Record<string, unknown>, ctx: WalkContext): NumberField;
88
+ /** Build a walked `BooleanField` from a JSON Schema node. */
51
89
  declare function buildBooleanField(schema: Record<string, unknown>, ctx: WalkContext): BooleanField;
90
+ /** Build a walked `NullField` from a JSON Schema node. */
52
91
  declare function buildNullField(schema: Record<string, unknown>, ctx: WalkContext): NullField;
92
+ /** Build a walked `UnknownField` (permissive open-shape) from a JSON Schema node. */
53
93
  declare function buildUnknownField(schema: Record<string, unknown>, ctx: WalkContext): UnknownField;
94
+ /** Build a walked `FileField` from a JSON Schema node carrying `contentMediaType`. */
54
95
  declare function buildFileField(schema: Record<string, unknown>, ctx: WalkContext): FileField;
55
96
  /**
56
97
  * Walk a map of sub-schemas (patternProperties, dependentSchemas, $defs).
@@ -69,6 +110,10 @@ declare function walkDependentRequiredMap(map: Record<string, unknown>): Record<
69
110
  * Used to strip composition keywords before walking the base schema.
70
111
  */
71
112
  declare function withoutKeys(schema: Record<string, unknown>, keys: string[]): Record<string, unknown>;
113
+ /**
114
+ * Type guard for a JSON primitive: string, number, boolean, or null.
115
+ * Used to short-circuit walk-time decisions about leaf values.
116
+ */
72
117
  declare function isPrimitive(value: unknown): value is string | number | boolean | null;
73
118
  /**
74
119
  * Convert any JSON-shaped value to a display string suitable for
@@ -2,14 +2,17 @@ import { isObject } from "./guards.mjs";
2
2
  import { extractFileConstraints, extractNumberConstraints, extractStringConstraints } from "./constraints.mjs";
3
3
  import { resolveEditability } from "./types.mjs";
4
4
  //#region src/core/walkBuilders.ts
5
+ /** Read a key from a JSON object, returning the value when it is a string and `undefined` otherwise. */
5
6
  function getString(obj, key) {
6
7
  const value = obj[key];
7
8
  return typeof value === "string" ? value : void 0;
8
9
  }
10
+ /** Read a key from a JSON object, returning the value when it is an array and `undefined` otherwise. */
9
11
  function getArray(obj, key) {
10
12
  const value = obj[key];
11
13
  return Array.isArray(value) ? value : void 0;
12
14
  }
15
+ /** Read a key from a JSON object, returning the value when it is a plain object and `undefined` otherwise. */
13
16
  function getObject(obj, key) {
14
17
  const value = obj[key];
15
18
  return isObject(value) ? value : void 0;
@@ -25,6 +28,12 @@ const META_KEYWORDS = new Set([
25
28
  "example",
26
29
  "examples"
27
30
  ]);
31
+ /**
32
+ * Extract recognised meta keywords (`readOnly`, `writeOnly`,
33
+ * `description`, `title`, `deprecated`, `default`, `component`,
34
+ * `example`, `examples`) from a JSON Schema node into the `SchemaMeta`
35
+ * shape consumed by the walker.
36
+ */
28
37
  function extractMetaFromJson(schema) {
29
38
  const meta = {};
30
39
  for (const [key, value] of Object.entries(schema)) if (META_KEYWORDS.has(key)) meta[key] = value;
@@ -40,12 +49,23 @@ const OVERRIDE_META_KEYS = new Set([
40
49
  "visible",
41
50
  "order"
42
51
  ]);
52
+ /**
53
+ * Project the meta-style keys (`readOnly`, `writeOnly`, `description`,
54
+ * `title`, `deprecated`, `component`, `visible`, `order`) out of a
55
+ * field override object into a `SchemaMeta`. Returns `undefined` when
56
+ * the override has no meta fields so the walker can short-circuit.
57
+ */
43
58
  function extractSchemaMetaFields(overrides) {
44
59
  if (overrides === void 0) return void 0;
45
60
  const meta = {};
46
61
  for (const key of Object.keys(overrides)) if (OVERRIDE_META_KEYS.has(key)) meta[key] = overrides[key];
47
62
  return Object.keys(meta).length > 0 ? meta : void 0;
48
63
  }
64
+ /**
65
+ * Pluck the nested override at `key` from a parent field override map.
66
+ * Returns `undefined` when no override is present or when the entry is
67
+ * not a non-array object.
68
+ */
49
69
  function extractChildOverride(overrides, key) {
50
70
  if (overrides === void 0) return void 0;
51
71
  const child = overrides[key];
@@ -77,6 +97,7 @@ function buildBase(schema, ctx) {
77
97
  ...examples !== void 0 ? { examples } : {}
78
98
  };
79
99
  }
100
+ /** Build a walked `StringField` from a JSON Schema node. */
80
101
  function buildStringField(schema, ctx) {
81
102
  return {
82
103
  ...buildBase(schema, ctx),
@@ -84,6 +105,7 @@ function buildStringField(schema, ctx) {
84
105
  constraints: extractStringConstraints(schema, ctx.diagnostics, ctx.pointer)
85
106
  };
86
107
  }
108
+ /** Build a walked `NumberField` from a JSON Schema node. */
87
109
  function buildNumberField(schema, ctx) {
88
110
  return {
89
111
  ...buildBase(schema, ctx),
@@ -91,6 +113,7 @@ function buildNumberField(schema, ctx) {
91
113
  constraints: extractNumberConstraints(schema)
92
114
  };
93
115
  }
116
+ /** Build a walked `BooleanField` from a JSON Schema node. */
94
117
  function buildBooleanField(schema, ctx) {
95
118
  return {
96
119
  ...buildBase(schema, ctx),
@@ -98,6 +121,7 @@ function buildBooleanField(schema, ctx) {
98
121
  constraints: {}
99
122
  };
100
123
  }
124
+ /** Build a walked `NullField` from a JSON Schema node. */
101
125
  function buildNullField(schema, ctx) {
102
126
  return {
103
127
  ...buildBase(schema, ctx),
@@ -105,6 +129,7 @@ function buildNullField(schema, ctx) {
105
129
  constraints: {}
106
130
  };
107
131
  }
132
+ /** Build a walked `UnknownField` (permissive open-shape) from a JSON Schema node. */
108
133
  function buildUnknownField(schema, ctx) {
109
134
  return {
110
135
  ...buildBase(schema, ctx),
@@ -112,6 +137,7 @@ function buildUnknownField(schema, ctx) {
112
137
  constraints: {}
113
138
  };
114
139
  }
140
+ /** Build a walked `FileField` from a JSON Schema node carrying `contentMediaType`. */
115
141
  function buildFileField(schema, ctx) {
116
142
  return {
117
143
  ...buildBase(schema, ctx),
@@ -148,6 +174,10 @@ function withoutKeys(schema, keys) {
148
174
  for (const [key, value] of Object.entries(schema)) if (!keys.includes(key)) result[key] = value;
149
175
  return result;
150
176
  }
177
+ /**
178
+ * Type guard for a JSON primitive: string, number, boolean, or null.
179
+ * Used to short-circuit walk-time decisions about leaf values.
180
+ */
151
181
  function isPrimitive(value) {
152
182
  return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
153
183
  }
@@ -1,7 +1,20 @@
1
- import { j as WalkedField } from "../types-BTB73MB8.mjs";
1
+ import { j as WalkedField } from "../types-C2Ay1FEh.mjs";
2
2
  import { WalkOptions } from "./walkBuilders.mjs";
3
3
 
4
4
  //#region src/core/walker.d.ts
5
+ /**
6
+ * Walk a normalised JSON Schema and produce a {@link WalkedField} tree
7
+ * that drives every rendering pipeline in schema-components (React,
8
+ * HTML, streaming HTML).
9
+ *
10
+ * Reads standard Draft 2020-12 keywords only — no Zod internals. Handles
11
+ * `$ref` resolution, `allOf` merging, `nullable` detection from
12
+ * `anyOf`, and discriminated-union detection from `oneOf` + `const`.
13
+ * Pass `rootDocument` so cross-document refs resolve correctly and
14
+ * `diagnostics` to receive per-keyword warnings.
15
+ *
16
+ * @group Walkers
17
+ */
5
18
  declare function walk(schema: unknown, options?: WalkOptions): WalkedField;
6
19
  //#endregion
7
20
  export { walk };
@@ -90,6 +90,19 @@ function applyStrictestUnevaluated(merged, branches) {
90
90
  if (strictestProps !== void 0) merged.unevaluatedProperties = strictestProps;
91
91
  if (strictestItems !== void 0) merged.unevaluatedItems = strictestItems;
92
92
  }
93
+ /**
94
+ * Walk a normalised JSON Schema and produce a {@link WalkedField} tree
95
+ * that drives every rendering pipeline in schema-components (React,
96
+ * HTML, streaming HTML).
97
+ *
98
+ * Reads standard Draft 2020-12 keywords only — no Zod internals. Handles
99
+ * `$ref` resolution, `allOf` merging, `nullable` detection from
100
+ * `anyOf`, and discriminated-union detection from `oneOf` + `const`.
101
+ * Pass `rootDocument` so cross-document refs resolve correctly and
102
+ * `diagnostics` to receive per-keyword warnings.
103
+ *
104
+ * @group Walkers
105
+ */
93
106
  function walk(schema, options = {}) {
94
107
  const { componentMeta, rootMeta, fieldOverrides, rootDocument, diagnostics, externalResolver } = options;
95
108
  if (typeof schema === "boolean") return walkBooleanSchema(schema);
@@ -15,10 +15,14 @@
15
15
  /**
16
16
  * Machine-readable codes identifying each class of diagnostic.
17
17
  * Stable across releases — consumers can pattern-match on these.
18
+ *
19
+ * @group Diagnostics
18
20
  */
19
21
  type DiagnosticCode = "allof-conflict" | "assumed-draft" | "bare-exclusive-bound" | "conditional-fallback" | "cross-schema-relative-ref-unsupported" | "cyclic-header-ref" | "cyclic-link-ref" | "cyclic-parameter-ref" | "cyclic-path-item-ref" | "dependencies-conflict" | "dependent-required-invalid" | "depth-exceeded" | "discriminator-inconsistent" | "divisible-by-conflict" | "doc-not-object" | "dropped-swagger-feature" | "header-ref-too-deep" | "duplicate-body-parameter" | "duplicate-operation-id" | "dynamic-ref-degraded" | "enum-value-filtered" | "external-ref" | "invalid-const" | "invalid-id-fragment" | "keyword-out-of-draft" | "link-ref-too-deep" | "legacy-dependencies-split" | "legacy-dependencies-split-2019" | "non-json-media-type-fallback" | "parameter-missing-schema" | "parameter-ref-too-deep" | "path-item-ref-too-deep" | "path-webhook-name-collision" | "pattern-invalid" | "prototype-polluting-property" | "recursive-anchor-collision" | "relative-ref-resolved" | "required-non-string" | "schema-allof-incompatible" | "swagger-collection-format-dropped" | "swagger-cyclic-parameter-ref" | "swagger-invalid-file-parameter" | "swagger-malformed-oauth-flow" | "swagger-missing-consumes" | "swagger-missing-host" | "type-mismatch" | "type-negation-fallback" | "unknown-format" | "unknown-json-schema-dialect" | "unknown-keyword" | "unknown-openapi-version" | "unknown-parameter-location" | "unknown-security-scheme-type" | "unresolved-ref" | "unsupported-type" | "zod-codec-nested-output-only" | "zod-codec-output-only" | "zod-preprocess-output-only" | "zod-promise-nested-unwrap";
20
22
  /**
21
23
  * A single diagnostic emitted during schema processing.
24
+ *
25
+ * @group Diagnostics
22
26
  */
23
27
  interface Diagnostic {
24
28
  /** Machine-readable code for programmatic handling. */
@@ -32,10 +36,14 @@ interface Diagnostic {
32
36
  }
33
37
  /**
34
38
  * Callback that receives each diagnostic as it is emitted.
39
+ *
40
+ * @group Diagnostics
35
41
  */
36
42
  type DiagnosticSink = (d: Diagnostic) => void;
37
43
  /**
38
44
  * Diagnostics configuration threaded through the processing pipeline.
45
+ *
46
+ * @group Diagnostics
39
47
  */
40
48
  interface DiagnosticsOptions {
41
49
  /**
@@ -1,14 +1,17 @@
1
- import { T as SchemaType } from "./types-BTB73MB8.mjs";
1
+ import { T as SchemaType } from "./types-C2Ay1FEh.mjs";
2
2
 
3
3
  //#region src/core/errors.d.ts
4
4
  /**
5
- * Base class for all schema-components errors.
6
- * Catch this to handle any library error uniformly.
5
+ * Base class for every schema-components error. Catch this to handle
6
+ * any library error uniformly.
7
7
  *
8
- * Forwards the optional `cause` to the native ES2022 `Error` constructor so
9
- * `error.cause` is wired up by the runtime and rendered correctly by
10
- * `util.inspect` ("Caused by: ..."). Subclasses that need a typed `cause`
11
- * field still get it via the platform's own `Error.cause` getter.
8
+ * Forwards the optional `cause` to the native ES2022 `Error` constructor
9
+ * so `error.cause` is wired up by the runtime and rendered correctly by
10
+ * `util.inspect` ("Caused by: ..."). Subclasses that need a typed
11
+ * `cause` field still get it via the platform's own `Error.cause`
12
+ * getter.
13
+ *
14
+ * @group Errors
12
15
  */
13
16
  declare class SchemaError extends Error {
14
17
  /** The schema input that caused the error. */
@@ -19,7 +22,12 @@ declare class SchemaError extends Error {
19
22
  * The adapter failed to convert the input schema to JSON Schema.
20
23
  *
21
24
  * Causes: invalid Zod schema, Zod 3 schema (unsupported), malformed
22
- * JSON Schema, missing OpenAPI ref, unsupported ref format.
25
+ * JSON Schema, missing OpenAPI ref, unsupported ref format,
26
+ * unrepresentable Zod types, conversion bugs, cycles, and duplicate
27
+ * ids. The `kind` field carries the precise classification — see the
28
+ * union declaration below.
29
+ *
30
+ * @group Errors
23
31
  */
24
32
  declare class SchemaNormalisationError extends SchemaError {
25
33
  readonly kind: "invalid-zod" | "unsupported-schema" | "zod3-unsupported" | "zod-transform-unsupported" | "zod-type-unrepresentable" | "zod-conversion-failed" | "zod-conversion-bug" | "zod-cycle-detected" | "zod-duplicate-id" | "invalid-json-schema" | "openapi-missing-ref" | "openapi-invalid" | "unknown";
@@ -31,9 +39,10 @@ declare class SchemaNormalisationError extends SchemaError {
31
39
  constructor(message: string, schema: unknown, kind: SchemaNormalisationError["kind"], zodType?: string, cause?: unknown);
32
40
  }
33
41
  /**
34
- * A theme adapter's render function threw during rendering.
42
+ * A theme adapter's render function threw during rendering. The
43
+ * original error is preserved on `cause`.
35
44
  *
36
- * The `cause` is the original error from the render function.
45
+ * @group Errors
37
46
  */
38
47
  declare class SchemaRenderError extends SchemaError {
39
48
  /**
@@ -45,10 +54,11 @@ declare class SchemaRenderError extends SchemaError {
45
54
  constructor(message: string, schema: unknown, schemaType: SchemaType, cause: unknown);
46
55
  }
47
56
  /**
48
- * A field path couldn't be resolved against the walked schema tree.
57
+ * A field path could not be resolved against the walked schema tree.
58
+ * Produced by `<SchemaField>` when the `path` prop does not match any
59
+ * field in the schema.
49
60
  *
50
- * This is produced by `<SchemaField>` when the `path` prop doesn't
51
- * match any field in the schema.
61
+ * @group Errors
52
62
  */
53
63
  declare class SchemaFieldError extends SchemaError {
54
64
  /** The unresolvable dot-separated path. */
@@ -1,5 +1,5 @@
1
- import { j as WalkedField } from "../types-BTB73MB8.mjs";
2
- import { t as AllConstraints } from "../renderer-Ul9taFYp.mjs";
1
+ import { j as WalkedField } from "../types-C2Ay1FEh.mjs";
2
+ import { t as AllConstraints } from "../renderer-OaOz-n6-.mjs";
3
3
  import { HtmlAttributes, HtmlNode } from "./html.mjs";
4
4
 
5
5
  //#region src/html/a11y.d.ts
@@ -65,6 +65,7 @@ type AttrValue = string | number | boolean | undefined;
65
65
  * arbitrary `data-*` and `aria-*` keys are allowed via index signature.
66
66
  */
67
67
  type HtmlAttributes = Record<string, AttrValue>;
68
+ /** HTML5 void-element tag names — self-closing, must not carry children. */
68
69
  declare const VOID_ELEMENTS: Set<string>;
69
70
  /**
70
71
  * Build an HTML element node.
@@ -103,7 +104,17 @@ declare function raw(html: string): HtmlRaw;
103
104
  * @returns HTML string
104
105
  */
105
106
  declare function serialize(node: HtmlNode): string;
107
+ /**
108
+ * Serialise a single {@link HtmlElement} to a string, taking care of
109
+ * void-element self-closing, attribute serialisation, and recursive
110
+ * child rendering. Use {@link serialize} for arbitrary nodes.
111
+ */
106
112
  declare function serializeElement(el: HtmlElement): string;
113
+ /**
114
+ * Serialise an attribute map to the `key="value"` form used inside an
115
+ * opening tag. `false` / `undefined` values are omitted; `true` renders
116
+ * as a boolean attribute (just the name).
117
+ */
107
118
  declare function serializeAttributes(attrs: HtmlAttributes): string;
108
119
  /**
109
120
  * Serialise an HTML node to chunks, yielded at natural element boundaries.
@@ -1,4 +1,5 @@
1
1
  //#region src/html/html.ts
2
+ /** HTML5 void-element tag names — self-closing, must not carry children. */
2
3
  const VOID_ELEMENTS = new Set([
3
4
  "area",
4
5
  "base",
@@ -80,6 +81,11 @@ function serialize(node) {
80
81
  if (node.tag === "") return node.children.map((child) => serialize(child)).join("");
81
82
  return serializeElement(node);
82
83
  }
84
+ /**
85
+ * Serialise a single {@link HtmlElement} to a string, taking care of
86
+ * void-element self-closing, attribute serialisation, and recursive
87
+ * child rendering. Use {@link serialize} for arbitrary nodes.
88
+ */
83
89
  function serializeElement(el) {
84
90
  const attrs = serializeAttributes(el.attributes);
85
91
  if (VOID_ELEMENTS.has(el.tag)) return `<${el.tag}${attrs}>`;
@@ -87,6 +93,11 @@ function serializeElement(el) {
87
93
  const inner = el.children.map((child) => serialize(child)).join("");
88
94
  return `<${el.tag}${attrs}>${inner}</${el.tag}>`;
89
95
  }
96
+ /**
97
+ * Serialise an attribute map to the `key="value"` form used inside an
98
+ * opening tag. `false` / `undefined` values are omitted; `true` renders
99
+ * as a boolean attribute (just the name).
100
+ */
90
101
  function serializeAttributes(attrs) {
91
102
  const parts = [];
92
103
  for (const [key, value] of Object.entries(attrs)) {
@@ -1,14 +1,22 @@
1
- import { w as SchemaMeta } from "../types-BTB73MB8.mjs";
2
- import { o as HtmlResolver } from "../renderer-Ul9taFYp.mjs";
1
+ import { w as SchemaMeta } from "../types-C2Ay1FEh.mjs";
2
+ import { o as HtmlResolver } from "../renderer-OaOz-n6-.mjs";
3
3
 
4
4
  //#region src/html/renderToHtml.d.ts
5
5
  /**
6
- * Build the recursion-cap sentinel element. The label is interpolated
7
- * via `h()` + `serialize` so any HTML in `meta.description` (which is
6
+ * Build the recursion-cap sentinel element used when the renderer
7
+ * encounters circular schema references. The label is interpolated via
8
+ * `h()` + `serialize` so any HTML in `meta.description` (which is
8
9
  * schema-author content but can equally be sourced from user-supplied
9
10
  * JSON Schema input) is escaped — never interpolated into raw markup.
11
+ *
12
+ * @group HTML
10
13
  */
11
14
  declare function recursionSentinelHtml(label: string): string;
15
+ /**
16
+ * Options accepted by {@link renderToHtml}.
17
+ *
18
+ * @group HTML
19
+ */
12
20
  interface RenderToHtmlOptions {
13
21
  /** The data value to render. */
14
22
  value?: unknown;
@@ -28,11 +36,23 @@ interface RenderToHtmlOptions {
28
36
  resolver?: HtmlResolver;
29
37
  }
30
38
  /**
31
- * Render a schema to an HTML string.
39
+ * Render a schema to a semantic HTML string.
40
+ *
41
+ * Framework-agnostic alternative to the React rendering pipeline.
42
+ * Shares the same normalise → walk → render pipeline, but emits
43
+ * escaped HTML with `sc-` prefixed classes rather than ReactNodes.
44
+ * Pass `resolver` to plug in a custom HTML renderer.
32
45
  *
46
+ * @group HTML
33
47
  * @param schema - Zod schema, JSON Schema, or OpenAPI document
34
48
  * @param options - Value, overrides, and resolver options
35
49
  * @returns Semantic HTML string with `sc-` prefixed classes
50
+ * @example
51
+ * ```tsx
52
+ * import { renderToHtml } from "schema-components/html/renderToHtml";
53
+ *
54
+ * const html = renderToHtml(userSchema, { value: user, readOnly: true });
55
+ * ```
36
56
  */
37
57
  declare function renderToHtml(schema: unknown, options?: RenderToHtmlOptions): string;
38
58
  //#endregion
@@ -27,20 +27,35 @@ import { defaultHtmlResolver } from "./renderers.mjs";
27
27
  * });
28
28
  */
29
29
  /**
30
- * Build the recursion-cap sentinel element. The label is interpolated
31
- * via `h()` + `serialize` so any HTML in `meta.description` (which is
30
+ * Build the recursion-cap sentinel element used when the renderer
31
+ * encounters circular schema references. The label is interpolated via
32
+ * `h()` + `serialize` so any HTML in `meta.description` (which is
32
33
  * schema-author content but can equally be sourced from user-supplied
33
34
  * JSON Schema input) is escaped — never interpolated into raw markup.
35
+ *
36
+ * @group HTML
34
37
  */
35
38
  function recursionSentinelHtml(label) {
36
39
  return serialize(h("fieldset", { class: "sc-recursive" }, h("em", {}, `↻ ${label} (recursive)`)));
37
40
  }
38
41
  /**
39
- * Render a schema to an HTML string.
42
+ * Render a schema to a semantic HTML string.
43
+ *
44
+ * Framework-agnostic alternative to the React rendering pipeline.
45
+ * Shares the same normalise → walk → render pipeline, but emits
46
+ * escaped HTML with `sc-` prefixed classes rather than ReactNodes.
47
+ * Pass `resolver` to plug in a custom HTML renderer.
40
48
  *
49
+ * @group HTML
41
50
  * @param schema - Zod schema, JSON Schema, or OpenAPI document
42
51
  * @param options - Value, overrides, and resolver options
43
52
  * @returns Semantic HTML string with `sc-` prefixed classes
53
+ * @example
54
+ * ```tsx
55
+ * import { renderToHtml } from "schema-components/html/renderToHtml";
56
+ *
57
+ * const html = renderToHtml(userSchema, { value: user, readOnly: true });
58
+ * ```
44
59
  */
45
60
  function renderToHtml(schema, options = {}) {
46
61
  const mergedMeta = { ...options.meta };
@@ -1,7 +1,14 @@
1
- import { w as SchemaMeta } from "../types-BTB73MB8.mjs";
2
- import { o as HtmlResolver } from "../renderer-Ul9taFYp.mjs";
1
+ import { w as SchemaMeta } from "../types-C2Ay1FEh.mjs";
2
+ import { o as HtmlResolver } from "../renderer-OaOz-n6-.mjs";
3
3
 
4
4
  //#region src/html/renderToHtmlStream.d.ts
5
+ /**
6
+ * Options accepted by the streaming HTML renderers
7
+ * ({@link renderToHtmlChunks}, {@link renderToHtmlStream},
8
+ * {@link renderToHtmlReadable}).
9
+ *
10
+ * @group HTML
11
+ */
5
12
  interface StreamRenderOptions {
6
13
  /** The data value to render. */
7
14
  value?: unknown;
@@ -21,19 +28,44 @@ interface StreamRenderOptions {
21
28
  resolver?: HtmlResolver;
22
29
  }
23
30
  /**
24
- * Render a schema as an iterable of HTML string chunks.
25
- * Each chunk is a self-contained HTML fragment.
31
+ * Render a schema as a synchronous iterable of HTML string chunks. Each
32
+ * chunk is a self-contained HTML fragment, ready to write to a stream
33
+ * or concatenate into a single string. Use when the host can flush
34
+ * output incrementally but does not need cooperative scheduling.
35
+ *
36
+ * @group HTML
37
+ * @example
38
+ * ```tsx
39
+ * import { renderToHtmlChunks } from "schema-components/html/renderToHtmlStream";
40
+ *
41
+ * for (const chunk of renderToHtmlChunks(userSchema, { value: user })) {
42
+ * response.write(chunk);
43
+ * }
44
+ * ```
26
45
  */
27
46
  declare function renderToHtmlChunks(schema: unknown, options?: StreamRenderOptions): Iterable<string>;
28
47
  /**
29
- * Render a schema as an async iterable of HTML string chunks.
30
- * Yields `undefined` between chunks to allow the event loop to process
31
- * other tasks (cooperative scheduling).
48
+ * Render a schema as an async iterable of HTML string chunks. Yields
49
+ * back to the event loop between chunks via a microtask so other tasks
50
+ * (queued I/O, timers) can run between fragments.
51
+ *
52
+ * @group HTML
32
53
  */
33
54
  declare function renderToHtmlStream(schema: unknown, options?: StreamRenderOptions): AsyncIterable<string>;
34
55
  /**
35
- * Render a schema as a web `ReadableStream<string>`.
36
- * Uses the async rendering pipeline internally.
56
+ * Render a schema as a web `ReadableStream<string>` so it can be piped
57
+ * into a `Response` body. Pulls chunks lazily from the synchronous
58
+ * chunk iterator under the hood.
59
+ *
60
+ * @group HTML
61
+ * @example
62
+ * ```tsx
63
+ * import { renderToHtmlReadable } from "schema-components/html/renderToHtmlStream";
64
+ *
65
+ * return new Response(renderToHtmlReadable(userSchema, { value: user }), {
66
+ * headers: { "content-type": "text/html" },
67
+ * });
68
+ * ```
37
69
  */
38
70
  declare function renderToHtmlReadable(schema: unknown, options?: StreamRenderOptions): ReadableStream<string>;
39
71
  //#endregion
@@ -19,17 +19,31 @@ import { streamField } from "./streamRenderers.mjs";
19
19
  * - `renderToHtmlReadable(schema, options)` → web `ReadableStream<string>`
20
20
  */
21
21
  /**
22
- * Render a schema as an iterable of HTML string chunks.
23
- * Each chunk is a self-contained HTML fragment.
22
+ * Render a schema as a synchronous iterable of HTML string chunks. Each
23
+ * chunk is a self-contained HTML fragment, ready to write to a stream
24
+ * or concatenate into a single string. Use when the host can flush
25
+ * output incrementally but does not need cooperative scheduling.
26
+ *
27
+ * @group HTML
28
+ * @example
29
+ * ```tsx
30
+ * import { renderToHtmlChunks } from "schema-components/html/renderToHtmlStream";
31
+ *
32
+ * for (const chunk of renderToHtmlChunks(userSchema, { value: user })) {
33
+ * response.write(chunk);
34
+ * }
35
+ * ```
24
36
  */
25
37
  function renderToHtmlChunks(schema, options = {}) {
26
38
  const { tree, resolver } = prepareTree(schema, options);
27
39
  return streamField(tree, options.value ?? tree.defaultValue, mergeHtmlResolvers(resolver, defaultHtmlResolver), "", resolver);
28
40
  }
29
41
  /**
30
- * Render a schema as an async iterable of HTML string chunks.
31
- * Yields `undefined` between chunks to allow the event loop to process
32
- * other tasks (cooperative scheduling).
42
+ * Render a schema as an async iterable of HTML string chunks. Yields
43
+ * back to the event loop between chunks via a microtask so other tasks
44
+ * (queued I/O, timers) can run between fragments.
45
+ *
46
+ * @group HTML
33
47
  */
34
48
  async function* renderToHtmlStream(schema, options = {}) {
35
49
  const { tree, resolver } = prepareTree(schema, options);
@@ -41,8 +55,19 @@ async function* renderToHtmlStream(schema, options = {}) {
41
55
  }
42
56
  }
43
57
  /**
44
- * Render a schema as a web `ReadableStream<string>`.
45
- * Uses the async rendering pipeline internally.
58
+ * Render a schema as a web `ReadableStream<string>` so it can be piped
59
+ * into a `Response` body. Pulls chunks lazily from the synchronous
60
+ * chunk iterator under the hood.
61
+ *
62
+ * @group HTML
63
+ * @example
64
+ * ```tsx
65
+ * import { renderToHtmlReadable } from "schema-components/html/renderToHtmlStream";
66
+ *
67
+ * return new Response(renderToHtmlReadable(userSchema, { value: user }), {
68
+ * headers: { "content-type": "text/html" },
69
+ * });
70
+ * ```
46
71
  */
47
72
  function renderToHtmlReadable(schema, options = {}) {
48
73
  const { tree, resolver } = prepareTree(schema, options);
@@ -1,5 +1,5 @@
1
1
  import { dateInputType } from "../core/formats.mjs";
2
- import { o as HtmlResolver } from "../renderer-Ul9taFYp.mjs";
2
+ import { o as HtmlResolver } from "../renderer-OaOz-n6-.mjs";
3
3
  import { matchUnionOption } from "../core/unionMatch.mjs";
4
4
 
5
5
  //#region src/html/renderers.d.ts
@@ -34,6 +34,12 @@ declare function panelId(path: string): string;
34
34
  * `panelId` above — see its comment.
35
35
  */
36
36
  declare function tabId(path: string, i: number): string;
37
+ /**
38
+ * Default HTML resolver used by `renderToHtml` and the streaming
39
+ * renderers when the consumer does not pass a custom resolver. Maps
40
+ * every `WalkedField` variant to a semantic HTML renderer built on the
41
+ * `h()` element builder.
42
+ */
37
43
  declare const defaultHtmlResolver: HtmlResolver;
38
44
  //#endregion
39
45
  export { dateInputType, defaultHtmlResolver, fieldId, matchUnionOption, panelId, tabId };
@@ -428,6 +428,12 @@ function renderNeverHtml(props) {
428
428
  ...ariaReadonlyAttrs()
429
429
  }, h("em", {}, "never matches")));
430
430
  }
431
+ /**
432
+ * Default HTML resolver used by `renderToHtml` and the streaming
433
+ * renderers when the consumer does not pass a custom resolver. Maps
434
+ * every `WalkedField` variant to a semantic HTML renderer built on the
435
+ * `h()` element builder.
436
+ */
431
437
  const defaultHtmlResolver = {
432
438
  string: renderStringHtml,
433
439
  number: renderNumberHtml,