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