@khanacademy/perseus 11.5.0 → 11.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/es/index.css +6 -6
- package/dist/es/index.js +17 -5
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +6 -6
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/dist/widgets/numeric-input.d.ts +1 -1
- package/package.json +3 -2
- package/src/__tests__/__snapshots__/server-item-renderer.test.tsx.snap +3 -3
- package/src/__tests__/item-renderer.test.tsx +24 -18
- package/src/hint-renderer.tsx +1 -0
- package/src/multi-items/__tests__/__snapshots__/multi-renderer.test.tsx.snap +1 -1
- package/src/perseus-types.ts +2 -1
- package/src/styles/khan-exercise.css +6 -4
- package/src/styles/perseus-renderer.less +0 -1
- package/src/widgets/__stories__/test-keypad-context-wrapper.tsx +7 -21
- package/src/widgets/__tests__/expression-mobile.test.tsx +333 -0
- package/src/widgets/__tests__/numeric-input.test.ts +35 -0
- package/src/widgets/numeric-input.tsx +22 -10
- package/tsconfig-build.tsbuildinfo +1 -1
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
PerseusNumericInputAnswer,
|
|
16
16
|
PerseusNumericInputWidgetOptions,
|
|
17
17
|
PerseusNumericInputAnswerForm,
|
|
18
|
+
MathFormat,
|
|
18
19
|
} from "../perseus-types";
|
|
19
20
|
import type {
|
|
20
21
|
FocusPath,
|
|
@@ -25,7 +26,11 @@ import type {
|
|
|
25
26
|
|
|
26
27
|
const ParseTex = TexWrangler.parseTex;
|
|
27
28
|
|
|
28
|
-
const answerFormButtons
|
|
29
|
+
const answerFormButtons: ReadonlyArray<{
|
|
30
|
+
title: string;
|
|
31
|
+
value: MathFormat;
|
|
32
|
+
content: string;
|
|
33
|
+
}> = [
|
|
29
34
|
{title: "Integers", value: "integer", content: "6"},
|
|
30
35
|
{title: "Decimals", value: "decimal", content: "0.75"},
|
|
31
36
|
{title: "Proper fractions", value: "proper", content: "\u2157"},
|
|
@@ -149,8 +154,8 @@ export class NumericInput extends React.Component<Props, State> {
|
|
|
149
154
|
return answerStrings[0];
|
|
150
155
|
}
|
|
151
156
|
|
|
152
|
-
static validate(
|
|
153
|
-
const
|
|
157
|
+
static validate(userInput: UserInput, rubric: Rubric): PerseusScore {
|
|
158
|
+
const defaultAnswerForms = answerFormButtons
|
|
154
159
|
.map((e) => e["value"])
|
|
155
160
|
// Don't default to validating the answer as a pi answer
|
|
156
161
|
// if answerForm isn't set on the answer
|
|
@@ -159,6 +164,18 @@ export class NumericInput extends React.Component<Props, State> {
|
|
|
159
164
|
|
|
160
165
|
const createValidator = (answer: PerseusNumericInputAnswer) => {
|
|
161
166
|
const stringAnswer = `${answer.value}`;
|
|
167
|
+
|
|
168
|
+
// Always validate against the provided answer forms (pi, decimal, etc.)
|
|
169
|
+
const validatorForms = [...(answer.answerForms ?? [])];
|
|
170
|
+
|
|
171
|
+
// When an answer is set to strict, we validate using ONLY
|
|
172
|
+
// the provided answerForms. If strict is false, or if there
|
|
173
|
+
// were no provided answer forms, we will include all
|
|
174
|
+
// of the default answer forms in our validator.
|
|
175
|
+
if (!answer.strict || validatorForms.length === 0) {
|
|
176
|
+
validatorForms.push(...defaultAnswerForms);
|
|
177
|
+
}
|
|
178
|
+
|
|
162
179
|
return KhanAnswerTypes.number.createValidatorFunctional(
|
|
163
180
|
stringAnswer,
|
|
164
181
|
{
|
|
@@ -169,19 +186,14 @@ export class NumericInput extends React.Component<Props, State> {
|
|
|
169
186
|
: "optional",
|
|
170
187
|
inexact: true, // TODO(merlob) backfill / delete
|
|
171
188
|
maxError: answer.maxError,
|
|
172
|
-
forms:
|
|
173
|
-
answer.strict &&
|
|
174
|
-
answer.answerForms &&
|
|
175
|
-
answer.answerForms.length !== 0
|
|
176
|
-
? answer.answerForms
|
|
177
|
-
: allAnswerForms,
|
|
189
|
+
forms: validatorForms,
|
|
178
190
|
},
|
|
179
191
|
);
|
|
180
192
|
};
|
|
181
193
|
|
|
182
194
|
// We may have received TeX; try to parse it before grading.
|
|
183
195
|
// If `currentValue` is not TeX, this should be a no-op.
|
|
184
|
-
const currentValue = ParseTex(
|
|
196
|
+
const currentValue = ParseTex(userInput.currentValue);
|
|
185
197
|
const correctAnswers = rubric.answers.filter(
|
|
186
198
|
(answer) => answer.status === "correct",
|
|
187
199
|
);
|