How scooter7/conversational-form works
Project type and purpose
• This is an open-source front-end JavaScript/TypeScript library (“Conversational Form”) that transforms standard HTML forms into conversational chat-style interfaces. It ships as a distributable bundle (JS + CSS) and is intended for integration into any web page.
High-level architectural components
A. Source modules
• cf.Tag classes (form-tags folder): takes native form inputs/buttons and wraps them in “Tag” objects
• cf.Data.Dictionary (dictionaryData): holds default question and error messages
• cf.Logic.FlowManager: orchestrates the question flow, determines next Tag, handles branching, re-usable variables
• cf.UI elements (ui folder):
– BasicElement, ScrollController, UserInput: low-level DOM renderers and event handlers
– ChatList, ChatResponse: chat message components
– ControlElements (buttons, radio, checkbox, upload): interactive widgets
• Styles (stylus files under src/styles): theme variables and UI component styles
B. Build pipeline
• gulp-tasks:
– scripts.js: compiles TypeScript → JavaScript, bundles modules
– styles.js: compiles Stylus → CSS
– images.js: processes images
– bower.js/package.json: manages front-end dependencies
• gulpfile.js coordinates sub-tasks and outputs:
– dist/conversational-form.min.js
– dist/conversational-form.min.css
C. Documentation and examples
• docs/: static site with demos (HTML/CSS/JS)
• test/: HTML pages for automated/manual test scenarios
Interactions & data flows
• [Developer’s web page] includes dist JS/CSS →
ConversationalForm auto-scans DOM for <form cf-form-element> →
Instantiates cf.ConversationalForm →
Internally runs Tag.createTag() over form elements →
FlowManager sequences questions using Dictionary data →
UI components render chat bubbles and control elements →
UserInput captures answers →
FlowManager updates state & renders next question →
On completion, submitCallback or form.submit() fires →
Collected form data posted to server or handled by callback
• Build pipeline reads TS/Stylus/images → transforms → writes to dist/ for consumption.
Architectural patterns & design principles
• Modular, single-responsibility classes: Tags, Logic, UI are separated
• MVC-style separation:
• Model: Tag definitions + Dictionary
• Controller: FlowManager
• View: UI element classes + stylus styles
• Plugin/extension points:
• Custom tags via Tag.createTag()
• Override dictionaryData / dictionaryAI
• Custom submitCallback and userImage
• TypeScript for type safety; Gulp for task automation; Stylus for theming.