import { w as SchemaMeta } from "./types-BBQaEPfE.mjs"; import { t as Diagnostic } from "./diagnostics-mftUZI7c.mjs"; import { r as SchemaIoSide } from "./adapter-ktQaheWB.mjs"; import { d as WidgetMap, i as ComponentResolver, u as RenderProps } from "./renderer-ab9E52Bp.mjs"; import { t as SchemaError } from "./errors-DbaI04x2.mjs"; import { d as PathOfType, f as RejectUnrepresentableZod, r as FromJSONSchema } from "./typeInference-Y8tNEQJk.mjs"; import { n as InferSchemaValue, t as InferFields } from "./inferValue-eAnh50EM.mjs"; import { z } from "zod"; import * as _$react_jsx_runtime0 from "react/jsx-runtime"; import { ReactNode } from "react"; //#region src/react/SchemaComponent.d.ts /** * Provide a theme resolver and scoped widgets to every `` * and `` rendered inside the subtree. * * Wrap an application (or a region of it) with `` so a * single theme — typically one of the bundled adapters * (`shadcnResolver`, `muiResolver`, `mantineResolver`, `radixResolver`) * or a custom one — drives every schema render. Without a provider, * schema-components fall back to the headless HTML renderer. * * @group Components * @example * ```tsx * import { SchemaProvider } from "schema-components/react/SchemaComponent"; * import { shadcnResolver } from "schema-components/themes/shadcn"; * * * * * ``` */ declare function SchemaProvider({ resolver, widgets, children }: { resolver: ComponentResolver; /** Scoped widgets available to all SchemaComponents in this subtree. */ widgets?: WidgetMap; children: ReactNode; }): _$react_jsx_runtime0.JSX.Element; /** * Register a widget globally. The widget is resolved when a schema field * has `.meta({ component: name })`. * * For scoped registration, use the `widgets` prop on `` * or `` instead. */ declare function registerWidget(name: string, render: (props: RenderProps) => unknown): void; /** * Clear every globally registered widget. Intended for test isolation — * `registerWidget` writes to module-level state and that state otherwise * leaks across test cases, making the test suite order-dependent. Tests * should call this from an `afterEach` hook. * * @internal */ declare function __clearGlobalWidgets(): void; /** * Props accepted by {@link SchemaComponent}. * * The generic parameters carry the inferred schema shape through to * `value`, `onChange`, and `fields` so a typed `schema` prop drives * typed props on the rest of the component. * * @group Components */ interface SchemaComponentProps { /** * Zod schema, JSON Schema object, or OpenAPI document. * * Zod 4 types that cannot round-trip through `z.toJSONSchema()` * (bigint, date, map, set, symbol, function, undefined, void, nan, * codec) are rejected at the type level via * {@link RejectUnrepresentableZod}. Runtime conversion would throw * `SchemaNormalisationError` with kind `zod-type-unrepresentable` * — the static rejection surfaces the same failure at compile time. */ schema: RejectUnrepresentableZod; /** * For OpenAPI / JSON Schema documents: a `$ref` string pointing at * the sub-schema to render — e.g. `"#/components/schemas/User"` or * `"/users/post"`. * * Named `schemaRef` (not `ref`) so the prop survives the React / * `preact/compat` `createElement` boundary, which strips the * reserved `ref` name from the vnode prop bag. */ schemaRef?: SchemaRef; /** * Which side of every transform / pipe / codec to render. * * - `"output"` (default) — renderer draws the OUTPUT side of the * schema. For a `z.codec(z.string(), z.number(), …)` chain * this renders a number input. `value` and `onChange` therefore * carry the OUTPUT shape, and `validate` runs `safeEncode` * (the reverse direction) so user-supplied OUTPUT values are * validated against the codec. * - `"input"` — renderer draws the INPUT side instead. For the * same codec this renders a string input, `value` and * `onChange` carry the INPUT shape, and `validate` runs * `safeParse` (the forward direction). * * The choice is propagated through `normaliseSchema` → * `normaliseZod4` → `z.toJSONSchema(..., { io })` so a single * source of truth drives both the rendered JSON Schema shape and * the validation direction. Has no effect for plain JSON Schema * or OpenAPI inputs — those advertise a single canonical shape. */ io?: Mode; /** * Current value to render. Typed against * `InferSchemaValue` so the prop tracks the * schema's inferred shape for the chosen `io` direction. * * Falls back to `unknown` when the schema's value type cannot be * statically inferred (runtime `Record` JSON * Schemas, OpenAPI documents without a ref, etc.), so untyped * call sites still compile. * * Use {@link InferredOutputValue} or {@link InferredInputValue} * to narrow a value declared at the call site: * * ```tsx * const user: InferredOutputValue = { ... }; * * ``` */ value?: InferSchemaValue; /** * Called when the value changes (editable fields). The parameter * shares the same shape as {@link SchemaComponentProps.value} so * a controlled component can round-trip the value through React * state without re-shaping. * * Falls back to `unknown` for schemas whose value type cannot be * statically inferred — see {@link SchemaComponentProps.value}. */ onChange?: (value: InferSchemaValue) => void; /** Run schema.safeParse() on change and surface errors via onValidationError. */ validate?: boolean; /** Called with the ZodError when validation fails. */ onValidationError?: (error: unknown) => void; /** Called when schema normalisation or rendering fails. */ onError?: (error: SchemaError) => void; /** Called with each diagnostic emitted during schema processing. */ onDiagnostic?: (diagnostic: Diagnostic) => void; /** When true, any diagnostic becomes a thrown error. */ strict?: boolean; /** Per-field meta overrides — nested object mirroring schema shape. */ fields?: InferFields; /** Meta overrides applied to the root schema. */ meta?: SchemaMeta; /** Convenience: sets readOnly on all fields. */ readOnly?: boolean; /** Convenience: sets writeOnly on all fields. */ writeOnly?: boolean; /** Convenience: sets description on the root. */ description?: string; /** Instance-scoped widgets — override context and global widgets. */ widgets?: WidgetMap; /** * Prefix used for every input `id`/label `htmlFor` in this component * subtree. Defaults to a per-instance value from `useId()` so multiple * `` instances on the same page never collide. Override * for deterministic ids in screenshot tests. */ idPrefix?: string; } /** * Render an editable (or read-only) UI from a Zod schema, JSON Schema, or * OpenAPI document. * * Auto-detects the input format, normalises to JSON Schema via the * adapter, walks the JSON Schema tree, and delegates per-field rendering * to the {@link ComponentResolver} supplied via {@link SchemaProvider} — * falling back to a headless HTML renderer when no provider is present. * * Pass `readOnly` to render a presentational view instead of inputs, or * wrap with `` to swap the theme. * * @group Components * @example * ```tsx * import { z } from "zod"; * import { SchemaComponent } from "schema-components/react/SchemaComponent"; * * const userSchema = z.object({ name: z.string(), email: z.email() }); * * * ``` */ declare function SchemaComponent(props: SchemaComponentProps): ReactNode; /** * Append a child path suffix to a parent path. When the suffix is omitted * (e.g. transparent wrappers like union options), the parent path is * returned unchanged so the child inherits the parent's id. * * Bracketed array indices like `[0]` append directly so `tags` + `[0]` * becomes `tags[0]` rather than `tags.[0]` — matching the canonical form * used by `html/a11y.ts` `joinPath` and `core/fieldPath.ts` `resolvePath`, * which already parses bracket notation when navigating WalkedField trees. */ declare function joinPath(parent: string, suffix: string | undefined): string; /** * Normalise a `useId()` value into a DOM-id-safe prefix. React's `useId` * returns values containing `:` characters (e.g. `«:r0:»`) which are * invalid in CSS selectors. Replace any run of non-alphanumeric characters * with a single hyphen and trim leading/trailing hyphens. */ declare function sanitisePrefix(value: string): string; /** * Render a single walked field through the resolved widget / * resolver / headless pipeline. Used internally by * {@link SchemaComponent} and {@link SchemaField}, exported so other * React-side components (e.g. the OpenAPI renderers) can dispatch * into the same fallback chain. Implementation lives in `./renderField.tsx`; * re-exported here for the public `react/SchemaComponent` entry point. */ /** * Infer the schema's output type for SchemaField path inference. */ type InferSchemaType = T extends z.ZodType ? z.infer : T extends object ? unknown extends FromJSONSchema ? unknown : FromJSONSchema : unknown; /** * Props accepted by {@link SchemaField}. The generic `P` constrains * `path` to dot-paths reachable through the schema's inferred value * type — typed schemas get autocomplete; runtime schemas fall back to * `string`. * * @group Components */ interface SchemaFieldProps> | (string extends PathOfType> ? string : never)> { /** * Dot-separated path to the field (e.g. "address.city"). * When the schema is a Zod schema or typed `as const`, only valid * paths are accepted. Falls back to `string` for runtime schemas. */ path: P; /** * The schema to extract the field from. Subject to the same * unrepresentable-Zod rejection as {@link SchemaComponentProps.schema}. */ schema: RejectUnrepresentableZod; /** * For OpenAPI / JSON Schema documents: a `$ref` string. Named * `schemaRef` (not `ref`) to avoid the React / `preact/compat` * reserved prop name. See {@link SchemaComponentProps.schemaRef}. */ schemaRef?: SchemaRef; /** Current value of the field at the given path. */ value?: unknown; /** Called with the updated root value when this field changes. */ onChange?: (value: unknown) => void; /** Override meta for this specific field. */ meta?: SchemaMeta; /** Run validation on change. */ validate?: boolean; onValidationError?: (error: unknown) => void; } /** * Render a single field from a schema by dot-separated `path`. * * Walks the full schema tree and resolves the field at the supplied * `path`, then renders only that field through the same resolver * pipeline as {@link SchemaComponent}. Useful for embedding individual * fields inside bespoke layouts. * * @group Components */ declare function SchemaField> | (string extends PathOfType> ? string : never)>({ path, schema: schemaInput, schemaRef: schemaRefInput, value, onChange, meta: fieldMeta, validate, onValidationError }: SchemaFieldProps): ReactNode; //#endregion export { SchemaProvider as a, registerWidget as c, SchemaFieldProps as i, sanitisePrefix as l, SchemaComponentProps as n, __clearGlobalWidgets as o, SchemaField as r, joinPath as s, SchemaComponent as t };