UNPKG

extended-dynamic-forms

Version:

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

48 lines (46 loc) 1.4 kB
import { ErrorSchema } from '@rjsf/utils'; import { RulesLogic } from 'json-logic-js'; export type JsonLogicRule = RulesLogic; export type ConditionPredicate = (formData: any) => boolean; export type Condition = ConditionPredicate | JsonLogicRule; export interface Rule<T> { name: string; condition: Condition; effect: T; order?: number; } export interface EngineConfig<T, C = any> { applyEffects: (effects: T[], baseConfig: C, formData: any) => C; defaultConfig: () => C; } export type ConditionalEngineHook<T, C = any> = (rules: Rule<T>[], baseConfig: C, formData: any) => C; export interface UiEffect { op: 'add' | 'remove' | 'replace'; path: string; value?: any; } export interface JsonPatchSchemaEffect { op: 'add' | 'remove' | 'replace'; path: string; value?: any; } export interface CustomSchemaEffect { op: 'require' | 'optional'; path: string; field: string; } export type SchemaEffect = JsonPatchSchemaEffect | CustomSchemaEffect; export interface ValidationEffect { /** * Name of the validation rule for debugging purposes */ name: string; /** * Determines if this validation should be applied based on current form data */ isActive: Condition; /** * Applies validation logic and adds errors to the ErrorSchema */ validate: (errors: ErrorSchema, formData: any) => void; }