@khanacademy/perseus 41.3.0 → 41.4.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/dist/es/index.js +36 -21
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +36 -21
- package/dist/index.js.map +1 -1
- package/dist/util/answer-types.d.ts +45 -2
- package/dist/validation.types.d.ts +4 -2
- package/dist/widgets/table/score-table.d.ts +1 -1
- package/dist/widgets/table/utils.d.ts +7 -0
- package/dist/widgets/table/validate-table.d.ts +6 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1588,7 +1588,7 @@ const MAXERROR_EPSILON = Math.pow(2, -42);
|
|
|
1588
1588
|
// TOOD(kevinb): Figure out how this relates to KEScore in
|
|
1589
1589
|
// perseus-all-package/types.js and see if there's a way to
|
|
1590
1590
|
// unify these types.
|
|
1591
|
-
|
|
1591
|
+
/**
|
|
1592
1592
|
* Answer types
|
|
1593
1593
|
*
|
|
1594
1594
|
* Utility for creating answerable questions displayed in exercises
|
|
@@ -1631,7 +1631,6 @@ const MAXERROR_EPSILON = Math.pow(2, -42);
|
|
|
1631
1631
|
* TODO(alpert): Think of a less-absurd name for createValidatorFunctional.
|
|
1632
1632
|
*
|
|
1633
1633
|
*/
|
|
1634
|
-
|
|
1635
1634
|
const KhanAnswerTypes = {
|
|
1636
1635
|
/*
|
|
1637
1636
|
* predicate answer type
|
|
@@ -2103,9 +2102,7 @@ const KhanAnswerTypes = {
|
|
|
2103
2102
|
})];
|
|
2104
2103
|
},
|
|
2105
2104
|
createValidatorFunctional: function (correctAnswer, options, strings) {
|
|
2106
|
-
return KhanAnswerTypes.predicate.createValidatorFunctional(
|
|
2107
|
-
// @ts-expect-error - TS2556 - A spread argument must either have a tuple type or be passed to a rest parameter.
|
|
2108
|
-
...KhanAnswerTypes.number.convertToPredicate(correctAnswer, options), strings);
|
|
2105
|
+
return KhanAnswerTypes.predicate.createValidatorFunctional(...KhanAnswerTypes.number.convertToPredicate(correctAnswer, options), strings);
|
|
2109
2106
|
}
|
|
2110
2107
|
},
|
|
2111
2108
|
/*
|
|
@@ -32367,6 +32364,9 @@ function replaceOutsideTeX(mathString) {
|
|
|
32367
32364
|
// Condense adjacent text nodes into a single text node
|
|
32368
32365
|
function condenseTextNodes(nodes) {
|
|
32369
32366
|
const result = [];
|
|
32367
|
+
if (!nodes) {
|
|
32368
|
+
return result;
|
|
32369
|
+
}
|
|
32370
32370
|
let currentText = "";
|
|
32371
32371
|
for (const node of nodes) {
|
|
32372
32372
|
if (node.type === "math") {
|
|
@@ -44512,17 +44512,23 @@ var Sorter$1 = {
|
|
|
44512
44512
|
scorer: scoreSorter
|
|
44513
44513
|
};
|
|
44514
44514
|
|
|
44515
|
-
|
|
44516
|
-
|
|
44517
|
-
|
|
44518
|
-
|
|
44519
|
-
|
|
44520
|
-
|
|
44521
|
-
|
|
44522
|
-
|
|
44523
|
-
|
|
44524
|
-
|
|
44525
|
-
|
|
44515
|
+
/**
|
|
44516
|
+
* Filters the given table (modelled as a 2D array) to remove any rows that are
|
|
44517
|
+
* completely empty.
|
|
44518
|
+
*
|
|
44519
|
+
* @returns A new table with only non-empty rows.
|
|
44520
|
+
*/
|
|
44521
|
+
const filterNonEmpty = function (table) {
|
|
44522
|
+
return table.filter(function (row) {
|
|
44523
|
+
// Return only rows that are non-empty.
|
|
44524
|
+
return row.some(cell => cell);
|
|
44525
|
+
});
|
|
44526
|
+
};
|
|
44527
|
+
|
|
44528
|
+
function validateTable(userInput) {
|
|
44529
|
+
const supplied = filterNonEmpty(userInput);
|
|
44530
|
+
const hasEmptyCell = supplied.some(function (row) {
|
|
44531
|
+
return row.some(function (cell) {
|
|
44526
44532
|
return cell === "";
|
|
44527
44533
|
});
|
|
44528
44534
|
});
|
|
@@ -44532,6 +44538,16 @@ function scoreTable(state, rubric, strings) {
|
|
|
44532
44538
|
message: null
|
|
44533
44539
|
};
|
|
44534
44540
|
}
|
|
44541
|
+
return null;
|
|
44542
|
+
}
|
|
44543
|
+
|
|
44544
|
+
function scoreTable(userInput, rubric, strings) {
|
|
44545
|
+
const validationResult = validateTable(userInput);
|
|
44546
|
+
if (validationResult != null) {
|
|
44547
|
+
return validationResult;
|
|
44548
|
+
}
|
|
44549
|
+
const supplied = filterNonEmpty(userInput);
|
|
44550
|
+
const solution = filterNonEmpty(rubric.answers);
|
|
44535
44551
|
if (supplied.length !== solution.length) {
|
|
44536
44552
|
return {
|
|
44537
44553
|
type: "points",
|
|
@@ -44542,17 +44558,16 @@ function scoreTable(state, rubric, strings) {
|
|
|
44542
44558
|
}
|
|
44543
44559
|
const createValidator = KhanAnswerTypes.number.createValidatorFunctional;
|
|
44544
44560
|
let message = null;
|
|
44545
|
-
const allCorrect =
|
|
44561
|
+
const allCorrect = solution.every(function (rowSolution) {
|
|
44546
44562
|
for (let i = 0; i < supplied.length; i++) {
|
|
44547
44563
|
const rowSupplied = supplied[i];
|
|
44548
|
-
const correct =
|
|
44564
|
+
const correct = rowSupplied.every(function (cellSupplied, i) {
|
|
44549
44565
|
const cellSolution = rowSolution[i];
|
|
44550
44566
|
const validator = createValidator(cellSolution, {
|
|
44551
44567
|
simplify: true
|
|
44552
44568
|
}, strings);
|
|
44553
44569
|
const result = validator(cellSupplied);
|
|
44554
44570
|
if (result.message) {
|
|
44555
|
-
// @ts-expect-error - TS2322 - Type 'string' is not assignable to type 'null'.
|
|
44556
44571
|
message = result.message;
|
|
44557
44572
|
}
|
|
44558
44573
|
return result.correct;
|
|
@@ -44568,7 +44583,7 @@ function scoreTable(state, rubric, strings) {
|
|
|
44568
44583
|
type: "points",
|
|
44569
44584
|
earned: allCorrect ? 1 : 0,
|
|
44570
44585
|
total: 1,
|
|
44571
|
-
message
|
|
44586
|
+
message
|
|
44572
44587
|
};
|
|
44573
44588
|
}
|
|
44574
44589
|
|
|
@@ -44971,7 +44986,7 @@ const init = function () {
|
|
|
44971
44986
|
|
|
44972
44987
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
44973
44988
|
const libName = "@khanacademy/perseus";
|
|
44974
|
-
const libVersion = "41.
|
|
44989
|
+
const libVersion = "41.4.0";
|
|
44975
44990
|
perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
44976
44991
|
|
|
44977
44992
|
const apiVersion = {
|