feat(worksheets): Phase 10 - Add operator validation

Adds validation for operator field in worksheet config:
- Validate operator is one of: addition, subtraction, or mixed
- Add clarifying comment that digit range applies to both operations
- All other validation rules apply uniformly to both operators

Completes the 10-phase implementation plan for subtraction support.
The worksheet creator now fully supports:
- Addition only
- Subtraction only
- Mixed mode (50/50 addition and subtraction)

All phases complete:
1.  Operator selection UI
2.  Subtraction problem generation
3.  Problem analysis for smart mode
4.  Typst rendering with borrow boxes
5.  Unified typstGenerator dispatch
6.  Display rules for both operators
7.  Auto-save persistence
8.  Preview/example routes
9.  DisplayOptionsPreview component
10.  Validation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Thomas Hallock 2025-11-07 22:32:14 -06:00
parent d5bbd783b3
commit d93dfac461
1 changed files with 7 additions and 0 deletions

View File

@ -56,6 +56,7 @@ export function validateWorksheetConfig(formState: WorksheetFormState): Validati
}
// V4: Validate digitRange (min and max must be 1-5, min <= max)
// Note: Same range applies to both addition and subtraction
const digitRange = formState.digitRange ?? { min: 2, max: 2 }
if (!digitRange.min || digitRange.min < 1 || digitRange.min > 5) {
errors.push('Digit range min must be between 1 and 5')
@ -67,6 +68,12 @@ export function validateWorksheetConfig(formState: WorksheetFormState): Validati
errors.push('Digit range min cannot be greater than max')
}
// V4: Validate operator (addition, subtraction, or mixed)
const operator = formState.operator ?? 'addition'
if (!['addition', 'subtraction', 'mixed'].includes(operator)) {
errors.push('Operator must be "addition", "subtraction", or "mixed"')
}
// Validate seed (must be positive integer)
const seed = formState.seed ?? Date.now() % 2147483647
if (!Number.isInteger(seed) || seed < 0) {