pldf-interview-engine
v1.0.0
Published
Interview wizard engine for parsed interviews from pldf-parser
Downloads
3
Maintainers
Readme
PLDF Interview Engine
An interactive interview wizard engine that takes parsed interview data from pldf-parser and generates dynamic, user-friendly interview wizards.
Features
- Dynamic Question Rendering: Automatically renders questions with various field types
- State Management: Tracks user progress with auto-save to localStorage
- Template Processing: Supports variable substitution using
${variable}syntax viapldf-template - Code Execution: Safely executes code blocks to compute derived values
- Dependency Resolution: Automatically orders questions based on variable dependencies
- Browser & Node.js: Works in both browser and Node.js environments (UMD modules)
- Customizable Styling: Includes default CSS with easy customization options
- Event System: Subscribe to interview events for custom integrations
Installation
npm install pldf-interview-engineQuick Start
Browser Usage
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="node_modules/pldf-interview-engine/css/styles.css">
</head>
<body>
<div id="interview"></div>
<script src="node_modules/pldf-interview-engine/js/state-manager.js"></script>
<script src="node_modules/pldf-interview-engine/js/field-renderer.js"></script>
<script src="node_modules/pldf-interview-engine/js/code-executor.js"></script>
<script src="node_modules/pldf-interview-engine/js/interview-wizard.js"></script>
<script>
// Your parsed interview data from pldf-parser
const interview = { /* ... */ };
const wizard = new InterviewWizard(interview, {
container: '#interview',
onComplete: (answers) => {
console.log('Interview completed:', answers);
}
});
wizard.initialize().then(() => wizard.start());
</script>
</body>
</html>Node.js Usage
const InterviewWizard = require('pldf-interview-engine');
const interview = { /* parsed interview data */ };
const wizard = new InterviewWizard(interview, {
onComplete: (answers) => {
console.log('Interview completed:', answers);
}
});
wizard.start();With pldf-parser Integration
const { DocassembleParser } = require('pldf-parser');
const InterviewWizard = require('pldf-interview-engine');
// Parse a YAML file
const interview = DocassembleParser.parseFile('interview.yml');
// Create and start the wizard
const wizard = new InterviewWizard(interview, {
container: '#interview',
autoSave: true,
onComplete: (answers) => {
console.log('Answers:', answers);
}
});
wizard.initialize().then(() => wizard.start());Configuration Options
new InterviewWizard(interview, {
container: '#interview',
autoSave: true,
saveKey: 'pldf_interview_state',
onComplete: (answers) => { /* ... */ },
onBlockChange: (block, index) => { /* ... */ },
cssPrefix: 'pldf'
});Supported Field Types
- text: Single-line text input
- email: Email address input
- number: Numeric input
- currency: Number input with decimal precision
- date: Date picker
- yesno: Yes/No radio buttons
- radio: Single selection from multiple options
- checkboxes: Multiple selection from options
- dropdown: Dropdown select menu
- textarea: Multi-line text input
Interview Structure
The engine expects interview objects with this structure:
{
filePath: 'interview.yml',
blocks: [
{
blockType: 'question',
question: 'What is your name?',
subquestion: 'Optional additional text',
fields: [ /* field objects */ ],
buttons: [ /* button objects */ ],
mandatory: false,
variables: ['var1', 'var2']
}
],
getQuestionOrder: function(definedVars) {
return /* ordered array of blocks */;
}
}This structure is automatically created by pldf-parser.
API Reference
InterviewWizard
Methods
initialize(): Initializes the wizard (returns Promise)start(): Starts the interviewnext(): Advances to the next questionprevious(): Goes back to previous questioncomplete(): Marks interview as completerestart(): Resets and restartsgetAnswers(): Returns all collected answersgetState(): Returns current stateloadState(state): Loads a saved state
Examples
See the examples/ directory for complete examples:
basic-usage.js: Simple Node.js examplewith-parser.js: Integration with pldf-parserdemo.html: Interactive browser demo
Development
Running Tests
npm testRunning the Demo
npm start
# Then open http://localhost:3000/examples/demo.htmlIntegration with PLDF Ecosystem
This package is part of the PLDF ecosystem:
- pldf-parser: Parses interview YAML files → Interview objects
- pldf-interview-engine (this package): Interview objects → Interactive wizards
- pldf-template: Generates documents from answers and templates
License
MIT
Links
- GitHub: https://github.com/step21/pldf-interview-engine
- Issues: https://github.com/step21/pldf-interview-engine/issues
- npm: https://www.npmjs.com/package/pldf-interview-engine
