@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/es/index.js CHANGED
@@ -18800,11 +18800,11 @@ const getInputNumberRenameMap = json => {
18800
18800
  };
18801
18801
 
18802
18802
  // Convert the user input data keys from input-number to numeric-input
18803
- const convertUserInputNumberData = userInputMap => {
18803
+ const convertUserInputNumberData = (userInputMap, renameMap) => {
18804
18804
  const updatedUserInputMap = _extends({}, userInputMap);
18805
18805
  for (const key of Object.keys(userInputMap)) {
18806
18806
  if (key.includes("input-number")) {
18807
- const updatedKey = key.replace("input-number", "numeric-input");
18807
+ const updatedKey = renameMap[key];
18808
18808
  updatedUserInputMap[updatedKey] = userInputMap[key];
18809
18809
  delete updatedUserInputMap[key];
18810
18810
  }
@@ -18812,6 +18812,19 @@ const convertUserInputNumberData = userInputMap => {
18812
18812
  return updatedUserInputMap;
18813
18813
  };
18814
18814
 
18815
+ // Used to convert InputNumber widgets to NumericInput widgets for scoring
18816
+ const convertInputNumberForScoring = (rubric, userInputMap) => {
18817
+ // First we need to create a map of the old input-number keys to the new numeric-input keys
18818
+ // so that we can ensure we update the content, widgets, AND userInput accordingly
18819
+ const renameMap = getInputNumberRenameMap(rubric);
18820
+ const convertedRubric = convertInputNumberJson(rubric, renameMap);
18821
+ const convertedUserData = convertUserInputNumberData(userInputMap, renameMap);
18822
+ return {
18823
+ convertedRubric,
18824
+ convertedUserData
18825
+ };
18826
+ };
18827
+
18815
18828
  const widgetRegExes = [/input-number \d+/]; // We can add more regexes here in the future
18816
18829
 
18817
18830
  // This utils in this file are used to modernize our Perseus JSON structure,
@@ -18819,6 +18832,7 @@ const widgetRegExes = [/input-number \d+/]; // We can add more regexes here in t
18819
18832
  // content creators use the Editor Page to update content containing these widgets.
18820
18833
  // Currently, we're only converting input-number to numeric-input,
18821
18834
  // but we can add more conversions here in the future.
18835
+
18822
18836
  // Modernize the json content of a PerseusRenderer object
18823
18837
  // by converting deprecated widgets to their modern equivalents
18824
18838
  const convertDeprecatedWidgets = json => {
@@ -18848,11 +18862,13 @@ const conversionRequired = json => {
18848
18862
  return false;
18849
18863
  };
18850
18864
 
18851
- // Convert the user input data keys for deprecated widgets to their modern equivalents
18852
- const convertUserInputData = userInputMap => {
18853
- // Currently we're only converting input-number to numeric-input,
18854
- // But we can add more conversions here in the future
18855
- return convertUserInputNumberData(userInputMap);
18865
+ /**
18866
+ * Convert the deprecated widgets in the rubric and user data to their
18867
+ * modern equivalents for scoring. These need to be updated together
18868
+ * in order to ensure that the widgetKeys match between the rubric and user data.
18869
+ */
18870
+ const convertDeprecatedWidgetsForScoring = (rubric, userInputMap) => {
18871
+ return convertInputNumberForScoring(rubric, userInputMap);
18856
18872
  };
18857
18873
 
18858
18874
  // These are all the current widgets that require user-input and are supported for automatic scoring
@@ -19457,12 +19473,19 @@ function scorePerseusItem(perseusRenderData, userInputMap,
19457
19473
  // TODO(LEMS-2461,LEMS-2391): these probably
19458
19474
  // need to be removed before we move this to the server
19459
19475
  strings, locale) {
19476
+ let convertedRenderData = perseusRenderData;
19477
+ let convertedUserInputMap = userInputMap;
19478
+
19460
19479
  // Check if the PerseusRenderer object contains any deprecated widgets that need to be converted
19461
19480
  const mustConvertData = conversionRequired(perseusRenderData);
19462
- const convertedRenderData = mustConvertData ? convertDeprecatedWidgets(perseusRenderData) // Convert deprecated widgets to their modern equivalents
19463
- : perseusRenderData;
19464
- const convertedUserInputMap = mustConvertData ? convertUserInputData(userInputMap) // Convert deprecated user input data keys to their modern equivalents
19465
- : userInputMap;
19481
+ if (mustConvertData) {
19482
+ const {
19483
+ convertedRubric,
19484
+ convertedUserData
19485
+ } = convertDeprecatedWidgetsForScoring(perseusRenderData, userInputMap);
19486
+ convertedRenderData = convertedRubric;
19487
+ convertedUserInputMap = convertedUserData;
19488
+ }
19466
19489
 
19467
19490
  // There seems to be a chance that PerseusRenderer.widgets might include
19468
19491
  // widget data for widgets that are not in PerseusRenderer.content,
@@ -45030,7 +45053,7 @@ const init = function init() {
45030
45053
 
45031
45054
  // This file is processed by a Rollup plugin (replace) to inject the production
45032
45055
  const libName = "@khanacademy/perseus";
45033
- const libVersion = "42.0.1";
45056
+ const libVersion = "42.0.2";
45034
45057
  addLibraryVersionToPerseusDebug(libName, libVersion);
45035
45058
 
45036
45059
  const apiVersion = {