UNPKG

form-preview-df

Version:

Resusable Form Preview Components

95 lines 3.9 kB
import { TFormComponent, ICondition } from '../types/form-builder-schema.model'; export interface IAvailableComponent { id: string; label: string; type: string; key: string; } export interface IConditionalLogic { action: 'show' | 'hide' | 'always'; when: 'all' | 'any'; conditions: ICondition[]; } export interface IConditionalEvaluationResult { shouldShow: boolean; evaluatedConditions: Array<{ condition: ICondition; result: boolean; componentValue: any; }>; } export declare class ConditionalLogicService { private static instance; private constructor(); static getInstance(): ConditionalLogicService; /** * Get all available components in the form for conditional logic * @param formSchema - The current form schema containing all components * @param excludeComponentId - Optional component ID to exclude from the list * @returns Array of available components with their metadata */ getAvailableComponentsForConditional(formSchema: TFormComponent[], excludeComponentId?: string): IAvailableComponent[]; getApplicableOperators(componentType: string): string[]; validateConditionalLogic(conditional: IConditionalLogic, formSchema: TFormComponent[]): { isValid: boolean; errors: string[]; }; /** * Evaluate whether a component should be shown based on conditional logic * @param conditional - The conditional logic to evaluate * @param formSchema - The current form schema * @param formValues - Current form values (component values) * @returns Evaluation result with details */ evaluateConditionalLogic(conditional: IConditionalLogic, formSchema: TFormComponent[], formValues: Record<string, any>): IConditionalEvaluationResult; /** * Get the current value of a component * @param componentId - The component ID to get value for * @param formSchema - The current form schema * @param formValues - Current form values * @returns The component value or undefined if not found */ private getComponentValue; /** * Evaluate a single condition * @param condition - The condition to evaluate * @param componentValue - The current value of the component * @returns Boolean result of the condition evaluation */ private evaluateCondition; /** * Evaluate checkbox-specific conditions (checked/notChecked) * @param componentValue - The current value of the checkbox component * @param expectedValue - Either 'checked' or 'notChecked' * @returns Boolean result of the checkbox condition evaluation */ private evaluateCheckboxCondition; /** * Determine if a checkbox component is checked based on its value * @param componentValue - The current value of the checkbox component * @returns Boolean indicating if checkbox is checked */ private isCheckboxChecked; /** * Determine final result based on 'when' condition (all/any) and action (show/hide) * @param conditional - The conditional logic configuration * @param evaluatedConditions - Array of evaluated conditions * @returns Final boolean result */ private determineFinalResult; private isEqual; private isEmpty; private contains; private isGreaterThan; private isLessThan; private isGreaterThanOrEqual; private isLessThanOrEqual; private isValidConditionValue; createDefaultConditionalLogic(): IConditionalLogic; getOperatorDisplayText(operator: string): string; getActionDisplayText(action: string): string; getConditionalLogicSummary(conditional: IConditionalLogic, formSchema: TFormComponent[]): string; private formatConditionValue; } export declare const conditionalLogicService: ConditionalLogicService; //# sourceMappingURL=conditionalLogicService.d.ts.map