import { elements, type XinStyleSheet } from 'tosijs'; import type { JSONSchema } from './json-schema.js'; /** What a plugin is handed. `set` writes the model — the plugin never owns the value. */ export interface FieldPluginContext { schema: JSONSchema; /** dotted path into the form's value, e.g. `scores.0.threshold` */ path: string; label: string; required: boolean; value: unknown; /** write this field's value; the form fires `change`, exactly as for a built-in control */ set: (value: unknown) => void; elements: typeof elements; } export interface FieldPlugin { /** * Build the control. Called ONCE per field; the form wraps it in the usual labelled field * with the error slot, so a plugin renders the control and nothing else. */ render: (context: FieldPluginContext) => HTMLElement; /** * Put a value into an already-rendered control — the form's `value` can change without the * schema changing, and rebuilding the element instead would take focus off a slider the * user is dragging. * * Required, deliberately: a control that cannot accept a value back is not compatible with * a form whose model owns the data, and finding that out at authoring time beats finding it * out when a save silently reverts. */ sync: (element: HTMLElement, value: unknown) => void; /** injected under `tosi-schema-form-plugin-` when the plugin registers */ styles?: XinStyleSheet; } /** * Claim a schema `format`. * * Registering the same format twice replaces the plugin — last one wins, which is what lets * an application override a library's default for its own pages. */ export declare function registerFieldPlugin(format: string, plugin: FieldPlugin): void; export declare function fieldPlugin(format: string | undefined): FieldPlugin | undefined; /** Called with the newly-claimed format, so live forms using it can pick it up. */ export declare function onFieldPluginsChanged(listener: (format: string) => void): void; /** Does this schema use `format` anywhere? What decides whether a form cares about a plugin. */ export declare function schemaUsesFormat(schema: JSONSchema | undefined, format: string): boolean;