@khanacademy/perseus 42.0.1 → 42.0.2

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
@@ -19006,13 +19006,13 @@ const getInputNumberRenameMap = json => {
19006
19006
  };
19007
19007
 
19008
19008
  // Convert the user input data keys from input-number to numeric-input
19009
- const convertUserInputNumberData = userInputMap => {
19009
+ const convertUserInputNumberData = (userInputMap, renameMap) => {
19010
19010
  const updatedUserInputMap = {
19011
19011
  ...userInputMap
19012
19012
  };
19013
19013
  for (const key of Object.keys(userInputMap)) {
19014
19014
  if (key.includes("input-number")) {
19015
- const updatedKey = key.replace("input-number", "numeric-input");
19015
+ const updatedKey = renameMap[key];
19016
19016
  updatedUserInputMap[updatedKey] = userInputMap[key];
19017
19017
  delete updatedUserInputMap[key];
19018
19018
  }
@@ -19020,6 +19020,19 @@ const convertUserInputNumberData = userInputMap => {
19020
19020
  return updatedUserInputMap;
19021
19021
  };
19022
19022
 
19023
+ // Used to convert InputNumber widgets to NumericInput widgets for scoring
19024
+ const convertInputNumberForScoring = (rubric, userInputMap) => {
19025
+ // First we need to create a map of the old input-number keys to the new numeric-input keys
19026
+ // so that we can ensure we update the content, widgets, AND userInput accordingly
19027
+ const renameMap = getInputNumberRenameMap(rubric);
19028
+ const convertedRubric = convertInputNumberJson(rubric, renameMap);
19029
+ const convertedUserData = convertUserInputNumberData(userInputMap, renameMap);
19030
+ return {
19031
+ convertedRubric,
19032
+ convertedUserData
19033
+ };
19034
+ };
19035
+
19023
19036
  const widgetRegExes = [/input-number \d+/]; // We can add more regexes here in the future
19024
19037
 
19025
19038
  // This utils in this file are used to modernize our Perseus JSON structure,
@@ -19027,6 +19040,7 @@ const widgetRegExes = [/input-number \d+/]; // We can add more regexes here in t
19027
19040
  // content creators use the Editor Page to update content containing these widgets.
19028
19041
  // Currently, we're only converting input-number to numeric-input,
19029
19042
  // but we can add more conversions here in the future.
19043
+
19030
19044
  // Modernize the json content of a PerseusRenderer object
19031
19045
  // by converting deprecated widgets to their modern equivalents
19032
19046
  const convertDeprecatedWidgets = json => {
@@ -19056,11 +19070,13 @@ const conversionRequired = json => {
19056
19070
  return false;
19057
19071
  };
19058
19072
 
19059
- // Convert the user input data keys for deprecated widgets to their modern equivalents
19060
- const convertUserInputData = userInputMap => {
19061
- // Currently we're only converting input-number to numeric-input,
19062
- // But we can add more conversions here in the future
19063
- return convertUserInputNumberData(userInputMap);
19073
+ /**
19074
+ * Convert the deprecated widgets in the rubric and user data to their
19075
+ * modern equivalents for scoring. These need to be updated together
19076
+ * in order to ensure that the widgetKeys match between the rubric and user data.
19077
+ */
19078
+ const convertDeprecatedWidgetsForScoring = (rubric, userInputMap) => {
19079
+ return convertInputNumberForScoring(rubric, userInputMap);
19064
19080
  };
19065
19081
 
19066
19082
  // These are all the current widgets that require user-input and are supported for automatic scoring
@@ -19662,12 +19678,19 @@ function scorePerseusItem(perseusRenderData, userInputMap,
19662
19678
  // TODO(LEMS-2461,LEMS-2391): these probably
19663
19679
  // need to be removed before we move this to the server
19664
19680
  strings, locale) {
19681
+ let convertedRenderData = perseusRenderData;
19682
+ let convertedUserInputMap = userInputMap;
19683
+
19665
19684
  // Check if the PerseusRenderer object contains any deprecated widgets that need to be converted
19666
19685
  const mustConvertData = conversionRequired(perseusRenderData);
19667
- const convertedRenderData = mustConvertData ? convertDeprecatedWidgets(perseusRenderData) // Convert deprecated widgets to their modern equivalents
19668
- : perseusRenderData;
19669
- const convertedUserInputMap = mustConvertData ? convertUserInputData(userInputMap) // Convert deprecated user input data keys to their modern equivalents
19670
- : userInputMap;
19686
+ if (mustConvertData) {
19687
+ const {
19688
+ convertedRubric,
19689
+ convertedUserData
19690
+ } = convertDeprecatedWidgetsForScoring(perseusRenderData, userInputMap);
19691
+ convertedRenderData = convertedRubric;
19692
+ convertedUserInputMap = convertedUserData;
19693
+ }
19671
19694
 
19672
19695
  // There seems to be a chance that PerseusRenderer.widgets might include
19673
19696
  // widget data for widgets that are not in PerseusRenderer.content,
@@ -45398,7 +45421,7 @@ const init = function () {
45398
45421
 
45399
45422
  // This file is processed by a Rollup plugin (replace) to inject the production
45400
45423
  const libName = "@khanacademy/perseus";
45401
- const libVersion = "42.0.1";
45424
+ const libVersion = "42.0.2";
45402
45425
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
45403
45426
 
45404
45427
  const apiVersion = {