@khanacademy/perseus-core 5.3.0 → 5.4.1

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/index.js CHANGED
@@ -1993,6 +1993,15 @@ const lockedFigureFillStyles = {
1993
1993
 
1994
1994
  // Not associated with a specific figure
1995
1995
 
1996
+ /**
1997
+ * Determines how unsimplified fractions are scored.
1998
+ *
1999
+ * - "required" means unsimplified fractions are considered invalid input, and
2000
+ * the learner can try again.
2001
+ * - "enforced" means unsimplified fractions are marked incorrect.
2002
+ * - "optional" means unsimplified fractions are accepted.
2003
+ */
2004
+
1996
2005
  const plotterPlotTypes = ["bar", "line", "pic", "histogram", "dotplot"];
1997
2006
 
1998
2007
  // Used to represent 2-D points and ranges
@@ -2277,7 +2286,21 @@ const parseNumberLineWidget = parseWidget(constant("number-line"), object({
2277
2286
  }));
2278
2287
 
2279
2288
  const parseMathFormat = enumeration("integer", "mixed", "improper", "proper", "decimal", "percent", "pi");
2280
- const parseSimplify = enumeration("required", "correct", "enforced", "optional");
2289
+ const parseSimplify = pipeParsers(union(constant(null)).or(constant(undefined)).or(boolean).or(constant("required")).or(constant("correct")).or(constant("enforced")).or(constant("optional")).or(constant("accepted")).parser).then(convert(deprecatedSimplifyValuesToRequired)).parser;
2290
+ function deprecatedSimplifyValuesToRequired(simplify) {
2291
+ switch (simplify) {
2292
+ case "enforced":
2293
+ case "required":
2294
+ case "optional":
2295
+ return simplify;
2296
+ // NOTE(benchristel): "accepted", "correct", true, false, undefined, and
2297
+ // null are all treated the same as "required" during scoring, so we
2298
+ // convert them to "required" here to preserve behavior. See the tests
2299
+ // in score-numeric-input.test.ts
2300
+ default:
2301
+ return "required";
2302
+ }
2303
+ }
2281
2304
  const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
2282
2305
  answers: array(object({
2283
2306
  message: string,
@@ -2292,12 +2315,7 @@ const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
2292
2315
  // TODO(benchristel): simplify should never be a boolean, but we
2293
2316
  // have some content where it is anyway. If we ever backfill
2294
2317
  // the data, we should simplify `simplify`.
2295
- simplify: optional(nullable(union(parseSimplify).or(pipeParsers(boolean).then(convert(value => {
2296
- if (typeof value === "boolean") {
2297
- return value ? "required" : "optional";
2298
- }
2299
- return value;
2300
- })).parser).parser))
2318
+ simplify: parseSimplify
2301
2319
  })),
2302
2320
  labelText: optional(string),
2303
2321
  size: string,
@@ -2306,7 +2324,7 @@ const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
2306
2324
  static: defaulted(boolean, () => false),
2307
2325
  answerForms: optional(array(object({
2308
2326
  name: parseMathFormat,
2309
- simplify: optional(nullable(enumeration("required", "correct", "enforced", "optional")))
2327
+ simplify: parseSimplify
2310
2328
  })))
2311
2329
  }));
2312
2330
 
@@ -2885,7 +2903,7 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
2885
2903
 
2886
2904
  // This file is processed by a Rollup plugin (replace) to inject the production
2887
2905
  const libName = "@khanacademy/perseus-core";
2888
- const libVersion = "5.3.0";
2906
+ const libVersion = "5.4.1";
2889
2907
  addLibraryVersionToPerseusDebug(libName, libVersion);
2890
2908
 
2891
2909
  /**
@@ -4089,8 +4107,9 @@ function getUpgradedWidgetOptions(oldWidgetOptions) {
4089
4107
  }
4090
4108
 
4091
4109
  /**
4092
- * Upgrades widget options and removes answerful data for all the widgets in a
4093
- * Perseus item.
4110
+ * Return a copy of a Perseus item with rubric data removed (ie answers)
4111
+ *
4112
+ * @param originalItem - the original, full Perseus item (which includes the rubric - aka answer data)
4094
4113
  */
4095
4114
  function splitPerseusItem(originalItem) {
4096
4115
  const item = ___default["default"].clone(originalItem);