schema-components 1.21.0 → 1.23.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 (91) hide show
  1. package/README.md +3 -1
  2. package/dist/core/adapter.d.mts +115 -4
  3. package/dist/core/adapter.mjs +405 -75
  4. package/dist/core/constraints.d.mts +2 -2
  5. package/dist/core/constraints.mjs +0 -7
  6. package/dist/core/cssClasses.d.mts +52 -0
  7. package/dist/core/cssClasses.mjs +51 -0
  8. package/dist/core/diagnostics.d.mts +1 -1
  9. package/dist/core/errors.d.mts +1 -1
  10. package/dist/core/errors.mjs +5 -13
  11. package/dist/core/fieldOrder.d.mts +1 -1
  12. package/dist/core/formats.d.mts +30 -2
  13. package/dist/core/formats.mjs +33 -1
  14. package/dist/core/idPath.d.mts +54 -0
  15. package/dist/core/idPath.mjs +66 -0
  16. package/dist/core/limits.d.mts +2 -0
  17. package/dist/core/limits.mjs +23 -0
  18. package/dist/core/merge.d.mts +10 -1
  19. package/dist/core/merge.mjs +49 -10
  20. package/dist/core/normalise.d.mts +40 -3
  21. package/dist/core/normalise.mjs +2 -2
  22. package/dist/core/openapi30.d.mts +15 -1
  23. package/dist/core/openapi30.mjs +2 -2
  24. package/dist/core/openapiConstants.d.mts +67 -0
  25. package/dist/core/openapiConstants.mjs +90 -0
  26. package/dist/core/ref.d.mts +2 -2
  27. package/dist/core/ref.mjs +85 -6
  28. package/dist/core/refChain.d.mts +70 -0
  29. package/dist/core/refChain.mjs +44 -0
  30. package/dist/core/renderer.d.mts +1 -1
  31. package/dist/core/renderer.mjs +0 -2
  32. package/dist/core/swagger2.d.mts +1 -1
  33. package/dist/core/swagger2.mjs +1 -1
  34. package/dist/core/typeInference.d.mts +982 -2
  35. package/dist/core/types.d.mts +2 -2
  36. package/dist/core/types.mjs +1 -4
  37. package/dist/core/unionMatch.d.mts +36 -0
  38. package/dist/core/unionMatch.mjs +53 -0
  39. package/dist/core/version.d.mts +1 -1
  40. package/dist/core/version.mjs +29 -17
  41. package/dist/core/walkBuilders.d.mts +23 -4
  42. package/dist/core/walkBuilders.mjs +27 -7
  43. package/dist/core/walker.d.mts +1 -1
  44. package/dist/core/walker.mjs +123 -47
  45. package/dist/{diagnostics-CbBPsxSt.d.mts → diagnostics-BS2kaUyE.d.mts} +1 -1
  46. package/dist/{errors-QEwOtQAA.d.mts → errors-g_MCTQel.d.mts} +10 -16
  47. package/dist/html/a11y.d.mts +9 -4
  48. package/dist/html/a11y.mjs +10 -12
  49. package/dist/html/renderToHtml.d.mts +10 -3
  50. package/dist/html/renderToHtml.mjs +13 -3
  51. package/dist/html/renderToHtmlStream.d.mts +2 -2
  52. package/dist/html/renderToHtmlStream.mjs +12 -1
  53. package/dist/html/renderers.d.mts +43 -8
  54. package/dist/html/renderers.mjs +136 -116
  55. package/dist/html/streamRenderers.d.mts +6 -6
  56. package/dist/html/streamRenderers.mjs +129 -89
  57. package/dist/limits-Cw5QZND8.d.mts +29 -0
  58. package/dist/{normalise-DaSrnr8g.mjs → normalise-DCYp06Sr.mjs} +770 -227
  59. package/dist/openapi/ApiCallbacks.d.mts +1 -1
  60. package/dist/openapi/ApiLinks.d.mts +1 -1
  61. package/dist/openapi/ApiResponseHeaders.d.mts +1 -1
  62. package/dist/openapi/ApiSecurity.d.mts +1 -1
  63. package/dist/openapi/ApiSecurity.mjs +16 -2
  64. package/dist/openapi/components.d.mts +234 -23
  65. package/dist/openapi/components.mjs +183 -52
  66. package/dist/openapi/parser.d.mts +9 -8
  67. package/dist/openapi/parser.mjs +252 -70
  68. package/dist/openapi/resolve.d.mts +31 -15
  69. package/dist/openapi/resolve.mjs +260 -40
  70. package/dist/react/SchemaComponent.d.mts +126 -36
  71. package/dist/react/SchemaComponent.mjs +95 -57
  72. package/dist/react/SchemaView.d.mts +30 -10
  73. package/dist/react/SchemaView.mjs +2 -2
  74. package/dist/react/a11y.d.mts +21 -0
  75. package/dist/react/a11y.mjs +24 -0
  76. package/dist/react/fieldPath.d.mts +1 -1
  77. package/dist/react/headless.d.mts +1 -1
  78. package/dist/react/headless.mjs +1 -2
  79. package/dist/react/headlessRenderers.d.mts +9 -11
  80. package/dist/react/headlessRenderers.mjs +51 -102
  81. package/dist/{ref-si8ViYun.d.mts → ref-DjLEKa_E.d.mts} +38 -3
  82. package/dist/{renderer-DI6ZYf7a.d.mts → renderer-CXJ8y0qw.d.mts} +2 -2
  83. package/dist/themes/mantine.d.mts +1 -1
  84. package/dist/themes/mui.d.mts +1 -1
  85. package/dist/themes/radix.d.mts +1 -1
  86. package/dist/themes/shadcn.d.mts +1 -1
  87. package/dist/themes/shadcn.mjs +2 -1
  88. package/dist/{types-BnxPEElk.d.mts → types-BTB73MB8.d.mts} +35 -14
  89. package/dist/{version-D-u7aMfy.d.mts → version-BFTVLsdb.d.mts} +7 -1
  90. package/package.json +1 -3
  91. package/dist/typeInference-Bxw3NOG1.d.mts +0 -647
@@ -1,3 +1,4 @@
1
+ import { fieldDomId, hintIdFor } from "../core/idPath.mjs";
1
2
  import { h } from "./html.mjs";
2
3
  //#region src/html/a11y.ts
3
4
  /**
@@ -17,24 +18,21 @@ function joinPath(parent, suffix) {
17
18
  return `${parent}.${suffix}`;
18
19
  }
19
20
  /**
20
- * Normalise a path into the id segment used after the `sc-` prefix.
21
- * Dots (object nesting) and brackets (array indices) become hyphens so
22
- * the id remains a valid CSS selector and matches test query semantics.
23
- */
24
- function normaliseIdSegment(value) {
25
- return value.replace(/[.[\]]+/g, "-").replace(/-+$/g, "");
26
- }
27
- /**
28
- * Build the input ID for a field at a given path.
21
+ * Build the input ID for a field at a given path. Joins `path` and `key`
22
+ * via `joinPath` then delegates to the canonical `fieldDomId` helper from
23
+ * `core/idPath.ts` so every render pipeline emits identical ids for the
24
+ * same structural position.
29
25
  */
30
26
  function buildInputId(path, key) {
31
- return `sc-${normaliseIdSegment(joinPath(path, key))}`;
27
+ return fieldDomId(joinPath(path, key));
32
28
  }
33
29
  /**
34
- * Derive the hint element ID from the input ID.
30
+ * Derive the hint element ID from the input ID. Thin re-export of the
31
+ * canonical helper so this module remains the one-stop a11y surface for
32
+ * the HTML renderers.
35
33
  */
36
34
  function buildHintId(inputId) {
37
- return `${inputId}-hint`;
35
+ return hintIdFor(inputId);
38
36
  }
39
37
  /**
40
38
  * Build a human-readable constraint description string.
@@ -1,7 +1,14 @@
1
- import { T as SchemaMeta } from "../types-BnxPEElk.mjs";
2
- import { o as HtmlResolver } from "../renderer-DI6ZYf7a.mjs";
1
+ import { w as SchemaMeta } from "../types-BTB73MB8.mjs";
2
+ import { o as HtmlResolver } from "../renderer-CXJ8y0qw.mjs";
3
3
 
4
4
  //#region src/html/renderToHtml.d.ts
5
+ /**
6
+ * Build the recursion-cap sentinel element. The label is interpolated
7
+ * via `h()` + `serialize` so any HTML in `meta.description` (which is
8
+ * schema-author content but can equally be sourced from user-supplied
9
+ * JSON Schema input) is escaped — never interpolated into raw markup.
10
+ */
11
+ declare function recursionSentinelHtml(label: string): string;
5
12
  interface RenderToHtmlOptions {
6
13
  /** The data value to render. */
7
14
  value?: unknown;
@@ -29,4 +36,4 @@ interface RenderToHtmlOptions {
29
36
  */
30
37
  declare function renderToHtml(schema: unknown, options?: RenderToHtmlOptions): string;
31
38
  //#endregion
32
- export { RenderToHtmlOptions, renderToHtml };
39
+ export { RenderToHtmlOptions, recursionSentinelHtml, renderToHtml };
@@ -1,6 +1,8 @@
1
+ import "../core/limits.mjs";
1
2
  import { normaliseSchema } from "../core/adapter.mjs";
2
3
  import { getHtmlRenderFn, mergeHtmlResolvers } from "../core/renderer.mjs";
3
4
  import { walk } from "../core/walker.mjs";
5
+ import { h, serialize } from "./html.mjs";
4
6
  import { joinPath } from "./a11y.mjs";
5
7
  import { defaultHtmlResolver } from "./renderers.mjs";
6
8
  //#region src/html/renderToHtml.ts
@@ -25,6 +27,15 @@ import { defaultHtmlResolver } from "./renderers.mjs";
25
27
  * });
26
28
  */
27
29
  /**
30
+ * Build the recursion-cap sentinel element. The label is interpolated
31
+ * via `h()` + `serialize` so any HTML in `meta.description` (which is
32
+ * schema-author content but can equally be sourced from user-supplied
33
+ * JSON Schema input) is escaped — never interpolated into raw markup.
34
+ */
35
+ function recursionSentinelHtml(label) {
36
+ return serialize(h("fieldset", { class: "sc-recursive" }, h("em", {}, `↻ ${label} (recursive)`)));
37
+ }
38
+ /**
28
39
  * Render a schema to an HTML string.
29
40
  *
30
41
  * @param schema - Zod schema, JSON Schema, or OpenAPI document
@@ -44,9 +55,8 @@ function renderToHtml(schema, options = {}) {
44
55
  rootDocument
45
56
  });
46
57
  const resolver = options.resolver ?? defaultHtmlResolver;
47
- const MAX_HTML_DEPTH = 10;
48
58
  const makeRenderChild = (currentDepth, parentPath) => (childTree, childValue, pathSuffix) => {
49
- if (currentDepth >= MAX_HTML_DEPTH) return `<fieldset class="sc-recursive"><em>\u21bb ${typeof childTree.meta.description === "string" ? childTree.meta.description : "schema"} (recursive)</em></fieldset>`;
59
+ if (currentDepth >= 10) return recursionSentinelHtml(typeof childTree.meta.description === "string" ? childTree.meta.description : "schema");
50
60
  const childPath = joinPath(parentPath, pathSuffix);
51
61
  return renderFieldHtml(childTree, childValue, resolver, childPath, makeRenderChild(currentDepth + 1, childPath));
52
62
  };
@@ -73,4 +83,4 @@ function renderFieldHtml(tree, value, resolver, path, renderChild) {
73
83
  return renderFn(props);
74
84
  }
75
85
  //#endregion
76
- export { renderToHtml };
86
+ export { recursionSentinelHtml, renderToHtml };
@@ -1,5 +1,5 @@
1
- import { T as SchemaMeta } from "../types-BnxPEElk.mjs";
2
- import { o as HtmlResolver } from "../renderer-DI6ZYf7a.mjs";
1
+ import { w as SchemaMeta } from "../types-BTB73MB8.mjs";
2
+ import { o as HtmlResolver } from "../renderer-CXJ8y0qw.mjs";
3
3
 
4
4
  //#region src/html/renderToHtmlStream.d.ts
5
5
  interface StreamRenderOptions {
@@ -69,8 +69,19 @@ function prepareTree(schema, options) {
69
69
  resolver: options.resolver ?? defaultHtmlResolver
70
70
  };
71
71
  }
72
+ /**
73
+ * Cooperative scheduler yield used between async chunks. Resolves on the
74
+ * next microtask so the event loop can process queued I/O and timers
75
+ * without the four-millisecond clamp browsers apply to nested
76
+ * `setTimeout(..., 0)` calls. The cumulative cost of `setTimeout`-based
77
+ * yielding on a deep schema is measurable; the microtask form is free.
78
+ */
72
79
  function schedulerYield() {
73
- return new Promise((resolve) => setTimeout(resolve, 0));
80
+ return new Promise((resolve) => {
81
+ queueMicrotask(() => {
82
+ resolve(void 0);
83
+ });
84
+ });
74
85
  }
75
86
  //#endregion
76
87
  export { renderToHtmlChunks, renderToHtmlReadable, renderToHtmlStream };
@@ -1,15 +1,50 @@
1
- import { M as WalkedField } from "../types-BnxPEElk.mjs";
2
- import { o as HtmlResolver } from "../renderer-DI6ZYf7a.mjs";
1
+ import { dateInputType } from "../core/formats.mjs";
2
+ import { o as HtmlResolver } from "../renderer-CXJ8y0qw.mjs";
3
+ import { matchUnionOption } from "../core/unionMatch.mjs";
3
4
 
4
5
  //#region src/html/renderers.d.ts
5
- declare function dateInputType(format: string | undefined): string | undefined;
6
6
  /**
7
- * Normalise a structural path into a valid, `sc-` prefixed HTML ID.
8
- * Dots (object nesting) and brackets (array indices) become hyphens so
9
- * the id remains a valid CSS selector and predictable in test queries.
7
+ * Thin wrapper over `fieldDomId` from `core/idPath.ts`. Every render
8
+ * pipeline must derive ids from the same canonical normaliser so that
9
+ * `aria-controls`, `aria-labelledby`, and `htmlFor` references resolve
10
+ * consistently across the React, sync-HTML, and streaming-HTML outputs.
11
+ *
12
+ * The wrapper tolerates an empty path here (returning `sc-`) for the
13
+ * sole reason that a leaf renderer at the schema root would otherwise
14
+ * throw — `renderToHtml(z.string())` is a rare but valid call shape.
15
+ * Container renderers thread a non-empty path through `renderChild`, so
16
+ * the empty-id fallback can never produce sibling collisions inside a
17
+ * structured form.
18
+ *
19
+ * TODO(round7-integration): once `renderToHtml` always threads a stable
20
+ * root path (e.g. `"$"`) into the leaf renderers, drop this wrapper and
21
+ * call `fieldDomId` directly so the throw fires as designed.
10
22
  */
11
23
  declare function fieldId(path: string): string;
12
- declare function matchUnionOption(options: WalkedField[], value: unknown): WalkedField | undefined;
24
+ /**
25
+ * Tab-panel id for a discriminated union at `path`. Delegates to the
26
+ * canonical `panelIdFor` from `core/idPath.ts` for the normal case so
27
+ * the sync, streaming, and React renderers all emit identical ids; falls
28
+ * back to a structurally-equivalent string when the renderer is invoked
29
+ * with an empty root path (a discriminated union at the schema root —
30
+ * see the `fieldId` doc comment for the wider context).
31
+ *
32
+ * Exported because `streamRenderers.ts` needs to derive identical ids
33
+ * — the panel id on the `<div role="tabpanel">` must match the
34
+ * `aria-controls` on every tab regardless of which pipeline rendered it.
35
+ *
36
+ * TODO(round7-integration): drop the empty-path branch once `renderToHtml`
37
+ * threads a stable root path so `panelIdFor` can be called directly.
38
+ */
39
+ declare function panelId(path: string): string;
40
+ /**
41
+ * Tab id for tab `i` within a discriminated union at `path`. Mirror of
42
+ * `panelId` above — see its comment.
43
+ *
44
+ * TODO(round7-integration): drop the empty-path branch once `renderToHtml`
45
+ * threads a stable root path so `tabIdFor` can be called directly.
46
+ */
47
+ declare function tabId(path: string, i: number): string;
13
48
  declare const defaultHtmlResolver: HtmlResolver;
14
49
  //#endregion
15
- export { dateInputType, defaultHtmlResolver, fieldId, matchUnionOption };
50
+ export { dateInputType, defaultHtmlResolver, fieldId, matchUnionOption, panelId, tabId };