/** * Svelte context for the field-policy form primitives (#2048). * * `FieldPolicyProvider` seeds a {@link FieldPolicyContextValue} into the * component tree from a pre-resolved {@link ResolvedObjectFieldPolicy} (SSR * `initialData` or a client fetch by the app — no smrt-web import in the * primitives). `PolicyField` and the mode-UX compositions read it through * {@link getFieldPolicyContext} / {@link tryGetFieldPolicyContext}. * * Mirrors the established `tryGet…` pattern (`tryGetControlInteractionContext`, * `useI18n`'s process-wide fallback) so `PolicyField` degrades gracefully * outside a Provider: an unwrapped field renders its children verbatim, and a * consumer can adopt the primitives incrementally without wrapping the whole * form. * * The two accessors are a deliberate two-tier contract, not a style choice: * * - `tryGetFieldPolicyContext` is for a primitive that still has something * meaningful to render without a policy — today only `PolicyField`, whose * fallback is the caller's own children. * - `getFieldPolicyContext` is for the provider-only compositions * (`ModeSwitch`, `AdvancedFields`, `FormHelp`) whose entire output is derived * from the resolved policy. Degrading those would render an empty or absent * control rather than surface the missing Provider, so they throw with an * actionable message instead (#2272). * * One provider per form. `setContext` shadows, so a nested `FieldPolicyProvider` * gives its subtree a second, independent `FieldPolicyModeStore` — consumers * above the nested provider then stop tracking the `ModeSwitch` below it. */ import type { ResolvedFieldPolicy, ResolvedObjectFieldPolicy } from '../types.js'; /** UI display mode for progressive disclosure. */ export type FieldPolicyMode = 'basic' | 'advanced'; /** * Reactive mode store implemented as a class with `$state` fields. Svelte 5 * tracks `$state` on class instances correctly across context boundaries — * the instance is the reactive root, not the closure. */ export declare class FieldPolicyModeStore { current: FieldPolicyMode; constructor(initial?: FieldPolicyMode); set(next: FieldPolicyMode): void; toggle(): void; } /** Svelte 5 runes-backed reactive context published by FieldPolicyProvider. */ export interface FieldPolicyContextValue { /** The fully resolved policy for one object. */ readonly policy: ResolvedObjectFieldPolicy; /** Reactive mode store (basic/advanced) owned by the provider. */ readonly mode: FieldPolicyModeStore; /** * Lookup of a single field's resolved policy by name. * Returns `undefined` when the field is not in the resolved set. */ getField(fieldName: string): ResolvedFieldPolicy | undefined; /** Count of advanced-visible fields for the disclosure label. */ readonly advancedFieldCount: number; } /** Publish the context (called by FieldPolicyProvider). */ export declare function setFieldPolicyContext(context: FieldPolicyContextValue): void; /** Read the context, throwing when there is no Provider. */ export declare function getFieldPolicyContext(): FieldPolicyContextValue; /** * Optional reader — returns `undefined` when no Provider wraps the consumer. * Used by `PolicyField` so it can render children verbatim outside a Provider * (graceful degradation / incremental adoption). */ export declare function tryGetFieldPolicyContext(): FieldPolicyContextValue | undefined; //# sourceMappingURL=context.svelte.d.ts.map