import { j as WalkedField } from "../types-BBQaEPfE.mjs"; import { l as RenderFunction } from "../renderer-ab9E52Bp.mjs"; //#region src/core/renderField.d.ts /** * Per-adapter configuration consumed by {@link dispatchRenderField}. * * Each adapter (React, HTML, future Vue / Solid / Svelte / Lit) supplies * one of these to plug its own per-field-props shape, output type, and * fallback/error behaviour into the shared dispatch loop without having * the dispatcher hardcode any framework-specific imports. * * @typeParam Props - The shape of the per-field props passed to render * functions and widgets (e.g. `RenderProps` for React, * `HtmlRenderProps` for HTML). * @typeParam Output - The type each render function and widget emits * for a single field (e.g. `unknown` / `ReactNode` for React, * `string` for HTML). * @typeParam Resolver - The resolver shape that maps schema types to * render functions (e.g. `ComponentResolver` for React, * `HtmlResolver` for HTML). */ interface DispatchConfig { /** * Build the per-field props handed to the render function or widget * when it is about to be invoked. Called at most once per dispatch * — adapters that need the same props for both the widget lookup * and the resolver lookup may call it twice through the * `dispatchRenderField` boundary. */ buildProps: (tree: WalkedField, path: string) => Props; /** * Look up a render function for `tree.type` in the resolver. Each * adapter wires this to its own `getRenderFunction` / * `getHtmlRenderFn` lookup so the dispatcher does not need to know * which resolver shape applies. * * The returned render function's output is typed `unknown` rather * than `Output` so adapters whose render functions historically * returned a broader type (React's * `RenderFunction\`) compose naturally. The * dispatcher hands the `unknown` return value to * {@link DispatchConfig.coerceResult}, which narrows it to * `Output` once per dispatch. */ lookupRenderFn: (type: WalkedField["type"], resolver: Resolver) => RenderFunction | undefined; /** * Produce the output emitted when the dispatcher hits * {@link MAX_RENDER_DEPTH}. Adapters return their own sentinel * (React: a `
` element; HTML: the `recursionSentinelHtml` * string; etc.) so the caller decides how to mark recursive * positions in the rendered output. */ recursionSentinel: (tree: WalkedField) => Output; /** * Produce the output emitted when no widget or resolver render * function handled the field. Most adapters either return a * `` of the stringified value (React) or throw — the * dispatcher does not interpret the return value, only forwards * it. */ fallback: (tree: WalkedField, value: unknown, path: string) => Output; /** * Coerce the raw `unknown` return value of a render function or * widget into the adapter's `Output` type, or `undefined` if the * result should be discarded (so the dispatcher falls through to * the next step). * * The `step` argument identifies which dispatch stage produced * the result — `"widget"` for a `.meta({ component })` match, * `"resolver"` for the per-type render function. The two cases * historically differed in how they treated `null` / * `undefined` returns (widget falls through; resolver * short-circuits with `null` so empty-array suppressions render * nothing), and adapters can preserve that asymmetry by * branching on `step`. * * Each adapter applies its own validity check here — React * narrows via `isValidElement`/string/number, HTML treats every * string as valid, etc. Returning `undefined` makes the * dispatcher behave as if no renderer produced output. */ coerceResult: (result: unknown, step: "widget" | "resolver") => Output | undefined; /** * Optional widget-lookup hook. When present, the dispatcher * consults it before the resolver lookup. Called once per * dispatch with the value of `tree.meta.component`; should * return the registered render function or `undefined` if no * widget matches. The returned function's output type matches * the resolver lookup (`unknown`) — see * {@link DispatchConfig.lookupRenderFn}. */ lookupWidget?: (name: string) => RenderFunction | undefined; /** * Wrap a render-time error in a {@link SchemaRenderError} (or a * caller-specified subclass) so every adapter routes thrown * errors through the same structured path. Called only for * errors thrown by the resolver render function — widget errors * propagate without wrapping, matching the historic React * behaviour where widgets are user code at the application * boundary. */ wrapRenderError?: (err: unknown, tree: WalkedField, path: string) => Error; } /** * Arguments accepted by {@link dispatchRenderField}. * * @typeParam Props - The per-field props shape. * @typeParam Output - The adapter's per-field output type. * @typeParam Resolver - The resolver shape mapping schema types to * render functions. */ interface DispatchArgs { /** The walked field to render. */ tree: WalkedField; /** The data value at this position in the tree. */ value: unknown; /** Dot-separated path from the schema root. */ path: string; /** Recursion depth — incremented by callers as they descend. */ depth: number; /** The merged resolver to look up the per-type render function on. */ resolver: Resolver; /** The dispatch configuration for the active adapter. */ config: DispatchConfig; } /** * Framework-agnostic dispatch loop shared by the React, HTML, and * future adapters. See the module-level documentation for the fixed * dispatch order. * * The dispatcher itself is intentionally side-effect free — it never * imports React, never builds HTML strings, and never reads any global * state. Adapter-specific work (widget registry lookup, recursion * sentinel construction, result coercion, error wrapping) is supplied * via the {@link DispatchConfig} argument. * * @typeParam Props - The per-field props shape. * @typeParam Output - The adapter's per-field output type. * @typeParam Resolver - The resolver shape. * @returns The output produced by the matched widget, render function, * or fallback — exactly one of the four dispatch steps always emits * a value. */ declare function dispatchRenderField(args: DispatchArgs): Output; //#endregion export { DispatchArgs, DispatchConfig, dispatchRenderField };