$ show surveyjs/survey-library
This is a monorepo for SurveyJS, a comprehensive open-source form/survey library that renders dynamic JSON-based forms across multiple frontend frameworks (React, Angular, Vue 3, and plain JavaScript). The core engine (`survey-core`) handles model parsing, validation, expressions, triggers, input masks, drag-and-drop, theming, and localization. It provides 20+ question types (text, checkbox, radio, dropdown, matrix, ranking, file, signature, etc.) with extensible UI components via framework-specific rendering packages. The library also includes a built-in linter for survey JSON static analysis and a tester for programmatic survey test execution. Architecture follows a layered pattern: core logic separate from UI, with each framework package consuming the core via a shared set of exported model classes. The codebase is large (2896 files) but well-structured, featuring a custom expression parser (PEG), a modular action-bar system, advanced popup management with focus trapping, and a generic drag-drop engine. Maintenance is active with frequent releases, but there is some technical drift in the form of commented-out legacy testcafe tests, auto-generated theme files, and cross-framework duplication that requires careful synchronization.
The LLM identified 4 files worth highlighting for reuse:
A PEG-based parser (generated from grammar.pegjs) that parses survey expressions into an AST. These expressions power conditional visibility, calculated values, validation rules, and triggers. The parser is hand-tuned for survey-specific syntax (e.g., curly-brace variable references) and is a well-crafted, isolated component demonstrating non-trivial compiler design skills. Could be reused or studied for building custom expression languages.
A generic drag-and-drop engine that abstracts the complexities of DOM-based drag operations. It provides shortcut ghost rendering, drop-target detection via DOM paths, and event hooks (onDragStart, onDrop, onDragEnd) that decouple the physics from application logic. The engine is framework-agnostic and reusable for any drag-drop scenario (ranking, reordering, matrix rows). Demonstrates careful separation of concerns and non-trivial cursor/touch handling.
A modal popup manager that manages a stack of modal layers, implements focus trapping (keyboard navigation within the modal), and coordinates animations and overlays. It is independent of rendering framework and can be used in any web application. The implementation demonstrates professional-grade accessibility patterns (ARIA attributes, focus restoration) and robust state management for overlapping modals.
Defines the ILintRule interface and a registry for survey JSON linting rules. Each rule (e.g., duplicate names, unknown references, expression type mismatch) is a separate class implementing `run()`. The framework supports severity levels, suppression (via `survey.lintIgnore`), and generates structured results. This pattern is highly reusable for any JSON-validation tool and demonstrates clean separation of rule logic from the lint runner.