UNPKG

extended-dynamic-forms

Version:

Extended React JSON Schema Form (RJSF) v6 with custom components, widgets, templates, layouts, and form events

89 lines (87 loc) 2.73 kB
import { FormProps } from '@rjsf/core'; import { RJSFSchema, UiSchema } from '@rjsf/utils'; export interface FormEventHandlers { beforeSubmit?: (data: any) => Promise<any> | any; afterSubmit?: (data: any) => Promise<void> | void; beforeValidation?: (data: any) => Promise<any> | any; afterValidation?: (data: any, errors: any) => Promise<void> | void; } export interface FormFieldEvent { eventType: 'focus' | 'blur' | 'change'; fieldId: string; fieldValue: any; schema?: any; formData?: any; timestamp: number; fieldPath?: string[]; } export interface WebhookConfig { url: string; method?: 'POST' | 'PUT' | 'PATCH'; headers?: Record<string, string>; events?: ('focus' | 'blur' | 'change')[]; debounceMs?: number; retries?: number; timeout?: number; } export interface FieldEventHandlers { onFieldFocus?: (event: FormFieldEvent) => Promise<void> | void; onFieldBlur?: (event: FormFieldEvent) => Promise<void> | void; onFieldChange?: (event: FormFieldEvent) => Promise<void> | void; } export interface ExtendedFormProps extends Omit<FormProps, 'validator'>, FormEventHandlers, FieldEventHandlers { schema: RJSFSchema; uiSchema?: UiSchema; webhooks?: WebhookConfig[]; conditionals?: ConditionalConfig; } export interface CustomWidgetProps { label?: string; required?: boolean; disabled?: boolean; readonly?: boolean; autofocus?: boolean; placeholder?: string; help?: string; rawErrors?: string[]; } export interface ConditionalRule { conditions: Record<string, any>; event: ConditionalEvent; order?: number; priority?: number; } export interface ConditionalEvent { type: string; params?: Record<string, any>; } export interface ConditionalAction { (params: any, schema: RJSFSchema, uiSchema: UiSchema, formData: any): void; propTypes?: any; validate?: (params: any, schema: RJSFSchema, uiSchema: UiSchema) => void; } export interface ConditionalActions { [actionType: string]: ConditionalAction; } export interface ConditionalEngine { new (rules: ConditionalRule[], schema: RJSFSchema): ConditionalEngineInstance; } export interface ConditionalEngineInstance { addRule(rule: ConditionalRule): void; run(formData: any): Promise<ConditionalEvent[]>; } export interface ConditionalConfig { rules?: ConditionalRule[]; engine?: ConditionalEngine; extraActions?: ConditionalActions; onSchemaChange?: (schemas: { schema: RJSFSchema; uiSchema: UiSchema; }) => void; } export interface ConditionalState { currentSchema: RJSFSchema; currentUiSchema: UiSchema; rules: ConditionalRule[]; isProcessing: boolean; }