/** * Form Field Component Registry * * Provides a registry system for form field components that enables: * - Tree-shaking: Heavy components (code editor, markdown) are only bundled when registered * - Dynamic field types: Users can add custom field renderers * - Lazy loading: Components can be registered at runtime * * Extends BaseRegistry for shared mechanics (subscribe, onClear, etc.). * * @module form/fieldRegistry * * @example Basic usage with light fields only (no codemirror): * ```typescript * import { SchemaForm } from "@flowdrop/flowdrop/form"; * // Uses only basic fields - small bundle size * ``` * * @example Adding code editor support: * ```typescript * import { fieldComponentRegistry } from "@flowdrop/flowdrop/form"; * import { FormCodeEditor, codeEditorFieldMatcher } from "@flowdrop/flowdrop/form/code"; * * fieldComponentRegistry.register("code-editor", { * component: FormCodeEditor, * matcher: codeEditorFieldMatcher, * priority: 100 * }); * ``` */ import type { Component } from 'svelte'; import type { FieldSchema } from '../components/form/types.js'; import { BaseRegistry } from '../registry/BaseRegistry.js'; /** * Base field component props that all registered field components should accept. * Components may have additional specific props. */ export interface FieldComponentProps { /** Field identifier */ id: string; /** Current field value */ value: unknown; /** Placeholder text */ placeholder?: string; /** Whether field is required */ required?: boolean; /** ARIA description ID */ ariaDescribedBy?: string; /** Change callback */ onChange: (value: unknown) => void; /** Additional schema-derived props */ [key: string]: unknown; } /** * Function type for determining if a field schema should use a specific component */ export type FieldMatcher = (schema: FieldSchema) => boolean; /** * Generic component type that accepts any props * This is needed because different field components have different prop requirements */ export type FieldComponent = Component; /** * Framework-agnostic matcher registration (no Svelte dependency). * Contains the matching logic and priority without the component. */ export interface FieldMatcherRegistration { /** Function to determine if this registration should handle a given schema */ matcher: FieldMatcher; /** Priority for matching (higher = checked first) */ priority: number; } /** * Full registration entry for a field component. * Extends FieldMatcherRegistration with the Svelte component needed for rendering. */ export interface FieldComponentRegistration extends FieldMatcherRegistration { /** The Svelte component to render */ component: FieldComponent; } /** * Class-based field component registry. * Extends BaseRegistry with priority-based field resolution. */ declare class FieldComponentRegistry extends BaseRegistry { /** Cached ordered keys by priority (highest first), invalidated on mutation */ private orderedKeys; /** * Register a field component. * Silently overwrites existing registrations (preserves legacy behavior). * * @param type - Unique identifier for this field type * @param registration - The field component registration */ register(type: string, registration: FieldComponentRegistration): void; /** * Override unregister to invalidate the priority cache. */ unregister(key: string): boolean; /** * Override clear to invalidate the priority cache. */ clear(): void; /** * Resolve which component should render a given field schema. * Checks registered matchers in priority order (highest first). * * @param schema - The field schema to resolve * @returns The matching registration or null if no match */ resolveFieldComponent(schema: FieldSchema): FieldComponentRegistration | null; /** * Get keys ordered by priority (cached). */ private getOrderedKeys; } /** Singleton instance of the field component registry */ export declare const fieldComponentRegistry: FieldComponentRegistry; /** * Matcher for hidden fields (should not render) */ export declare const hiddenFieldMatcher: FieldMatcher; /** * Matcher for checkbox group fields (enum with multiple) */ export declare const checkboxGroupMatcher: FieldMatcher; /** * Matcher for enum select fields */ export declare const enumSelectMatcher: FieldMatcher; /** * Matcher for multiline textarea fields */ export declare const textareaMatcher: FieldMatcher; /** * Matcher for range slider fields */ export declare const rangeMatcher: FieldMatcher; /** * Matcher for string text fields */ export declare const textFieldMatcher: FieldMatcher; /** * Matcher for number fields */ export declare const numberFieldMatcher: FieldMatcher; /** * Matcher for boolean toggle fields */ export declare const toggleMatcher: FieldMatcher; /** * Matcher for select fields with labeled options (JSON Schema oneOf pattern) * * @example * ```json * { "type": "string", "oneOf": [{ "const": "a", "title": "Option A" }] } * ``` */ export declare const selectOptionsMatcher: FieldMatcher; /** * Matcher for array fields */ export declare const arrayMatcher: FieldMatcher; /** * Matcher for autocomplete fields * Matches when format is "autocomplete" and autocomplete config with URL is provided */ export declare const autocompleteMatcher: FieldMatcher; export {};