fix(worksheets): add borrowNotation and borrowingHints to DisplayRules interfaces

Add missing subtraction-specific scaffold fields to DisplayRules and
ResolvedDisplayOptions interfaces, and include them in resolveDisplayForProblem.

This fixes TypeScript errors and ensures these fields are properly resolved
for each problem in smart difficulty mode.

Part of subtraction scaffolding integration that was lost during git stash.

🤖 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-08 14:51:55 -06:00
parent aa24a1346b
commit 3b908ac453
1 changed files with 48 additions and 40 deletions

View File

@ -1,32 +1,36 @@
// Display rules for conditional per-problem scaffolding
import type { ProblemMeta, SubtractionProblemMeta } from './problemAnalysis'
import type { ProblemMeta, SubtractionProblemMeta } from "./problemAnalysis";
export type AnyProblemMeta = ProblemMeta | SubtractionProblemMeta
export type AnyProblemMeta = ProblemMeta | SubtractionProblemMeta;
export type RuleMode =
| 'always' // Always show this display option
| 'never' // Never show this display option
| 'whenRegrouping' // Show when problem requires any regrouping
| 'whenMultipleRegroups' // Show when 2+ place values regroup
| 'when3PlusDigits' // Show when maxDigits >= 3
| "always" // Always show this display option
| "never" // Never show this display option
| "whenRegrouping" // Show when problem requires any regrouping
| "whenMultipleRegroups" // Show when 2+ place values regroup
| "when3PlusDigits"; // Show when maxDigits >= 3
export interface DisplayRules {
carryBoxes: RuleMode
answerBoxes: RuleMode
placeValueColors: RuleMode
tenFrames: RuleMode
problemNumbers: RuleMode
cellBorders: RuleMode
carryBoxes: RuleMode;
answerBoxes: RuleMode;
placeValueColors: RuleMode;
tenFrames: RuleMode;
problemNumbers: RuleMode;
cellBorders: RuleMode;
borrowNotation: RuleMode; // Subtraction: scratch boxes showing borrowed 10s
borrowingHints: RuleMode; // Subtraction: arrows and visual hints
}
export interface ResolvedDisplayOptions {
showCarryBoxes: boolean
showAnswerBoxes: boolean
showPlaceValueColors: boolean
showTenFrames: boolean
showProblemNumbers: boolean
showCellBorder: boolean
showCarryBoxes: boolean;
showAnswerBoxes: boolean;
showPlaceValueColors: boolean;
showTenFrames: boolean;
showProblemNumbers: boolean;
showCellBorder: boolean;
showBorrowNotation: boolean; // Subtraction: scratch work boxes in minuend
showBorrowingHints: boolean; // Subtraction: hints with arrows
}
/**
@ -35,24 +39,26 @@ export interface ResolvedDisplayOptions {
*/
export function evaluateRule(mode: RuleMode, problem: AnyProblemMeta): boolean {
switch (mode) {
case 'always':
return true
case "always":
return true;
case 'never':
return false
case "never":
return false;
case 'whenRegrouping':
case "whenRegrouping":
// Works for both: requiresRegrouping (addition) or requiresBorrowing (subtraction)
return 'requiresRegrouping' in problem
return "requiresRegrouping" in problem
? problem.requiresRegrouping
: problem.requiresBorrowing
: problem.requiresBorrowing;
case 'whenMultipleRegroups':
case "whenMultipleRegroups":
// Works for both: regroupCount (addition) or borrowCount (subtraction)
return 'regroupCount' in problem ? problem.regroupCount >= 2 : problem.borrowCount >= 2
return "regroupCount" in problem
? problem.regroupCount >= 2
: problem.borrowCount >= 2;
case 'when3PlusDigits':
return problem.maxDigits >= 3
case "when3PlusDigits":
return problem.maxDigits >= 3;
}
}
@ -62,10 +68,10 @@ export function evaluateRule(mode: RuleMode, problem: AnyProblemMeta): boolean {
*/
export function resolveDisplayForProblem(
rules: DisplayRules,
problem: AnyProblemMeta
problem: AnyProblemMeta,
): ResolvedDisplayOptions {
console.log('[resolveDisplayForProblem] Input rules:', rules)
console.log('[resolveDisplayForProblem] Problem meta:', problem)
console.log("[resolveDisplayForProblem] Input rules:", rules);
console.log("[resolveDisplayForProblem] Problem meta:", problem);
const resolved = {
showCarryBoxes: evaluateRule(rules.carryBoxes, problem),
@ -74,15 +80,17 @@ export function resolveDisplayForProblem(
showTenFrames: evaluateRule(rules.tenFrames, problem),
showProblemNumbers: evaluateRule(rules.problemNumbers, problem),
showCellBorder: evaluateRule(rules.cellBorders, problem),
}
showBorrowNotation: evaluateRule(rules.borrowNotation, problem),
showBorrowingHints: evaluateRule(rules.borrowingHints, problem),
};
console.log('[resolveDisplayForProblem] Resolved display options:', resolved)
console.log("[resolveDisplayForProblem] Resolved display options:", resolved);
console.log(
'[resolveDisplayForProblem] Ten-frames rule:',
"[resolveDisplayForProblem] Ten-frames rule:",
rules.tenFrames,
'-> showTenFrames:',
resolved.showTenFrames
)
"-> showTenFrames:",
resolved.showTenFrames,
);
return resolved
return resolved;
}