How agenciaego/egodesign-form works
Main Components
• Core Library (EgoForm Class): This is the primary export (src/egodesign.form.ts) that initializes the form and ties together all functionality.
• Validation Modules: Under src/modules you have components like ValidationClass.ts, tools.ts, and validationMessages.ts. These handle the validation logic, utility functions, and error messaging.
• Types and Interfaces: The src/types.d.ts file defines TypeScript types used throughout the library.
• Testing Suite: The tests directory (with files like egoform.test.ts, filters.test.ts, multisteps.test.ts) validates the library’s behaviors.
• Build and Configuration: The Rollup config (rollup.config.mjs), Vite config (vite.config.ts), tsconfig.json, and package.json indicate that the project uses a modern build system to transpile and bundle the library for distribution (dist folder).
Component Relationships and Data Flow
• At the entry point, the developer includes and instantiates the EgoForm class by passing configuration options and a DOM element representing the form.
• EgoForm then delegates to various modules:
• The Validation Module evaluates fields based on data attributes (e.g., data-type, min/max length) and applies built-in rules (like for text, email, URL, etc.) as well as any custom validations supplied via options.
• The Tools Module supports utility operations (for example, formatting input values).
• The Validation Messages Module supplies and customizes error messages that are shown in the UI.
• Event Handlers (onValidationError, onSubmitStart, onSubmitEnd, onSuccess, onError, etc.) are wired into these processes to notify the consumer about different states during the form submission lifecycle.
• The UI integration layer uses CSS classes (both required hard-coded classes and the customizable ones) to update the form’s visual state (e.g., adding error classes or indicating submission state).
Architectural Patterns and Design Principles
• Modular Design: The code is divided into a main core class and separate modules for validations and tools.
• Configuration-Driven Behavior: The library is highly customizable via options (for validations, classes, event callbacks, submission formats, etc.).
• Event-Driven Communication: Several callbacks are provided for hooking into the form’s lifecycle (e.g., step changes and submission events).