@khanacademy/perseus 20.7.0 → 20.8.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 CHANGED
@@ -41763,7 +41763,7 @@ const init = function init(options) {
41763
41763
 
41764
41764
  // This file is processed by a Rollup plugin (replace) to inject the production
41765
41765
  const libName = "@khanacademy/perseus";
41766
- const libVersion = "20.7.0";
41766
+ const libVersion = "20.8.0";
41767
41767
  addLibraryVersionToPerseusDebug(libName, libVersion);
41768
41768
 
41769
41769
  const apiVersion = {
@@ -44420,6 +44420,66 @@ function injectWidgets(content, widgets) {
44420
44420
  return context;
44421
44421
  }
44422
44422
 
44423
+ /* Widgets that have individual answers */
44424
+ const INDIVIDUAL_ANSWER_WIDGETS = ["interactive-graph", "categorizer", "grapher"];
44425
+
44426
+ /* Widgets that are supported for automatic scoring */
44427
+ const SUPPORTED_WIDGETS = ["radio", "numeric-input", "input-number", "expression", ...INDIVIDUAL_ANSWER_WIDGETS];
44428
+ const getWidgetTypeFromWidgetKey = widgetKey => {
44429
+ return widgetKey.split(" ")[0];
44430
+ };
44431
+
44432
+ /* Verify if the perseus item has supported widgets for automatic scoring */
44433
+ const isWrongAnswerSupported = widgetKeys => {
44434
+ return widgetKeys.length !== 0 && widgetKeys.every(widgetKey => SUPPORTED_WIDGETS.includes(getWidgetTypeFromWidgetKey(widgetKey)));
44435
+ };
44436
+
44437
+ /* Verify if the widget key has an individual answer for the coach report view */
44438
+ const shouldHaveIndividualAnswer = widgetKey => {
44439
+ return INDIVIDUAL_ANSWER_WIDGETS.includes(getWidgetTypeFromWidgetKey(widgetKey));
44440
+ };
44441
+
44442
+ /* Returns the answer userInput submission for currently supported widgets */
44443
+ // TODO (LEMS-1834): Fix userInput any types to be specific
44444
+ const getAnswerFromUserInput = (widgetType, userInput) => {
44445
+ switch (widgetType) {
44446
+ case "categorizer":
44447
+ return userInput.values;
44448
+ case "input-number":
44449
+ return userInput.currentValue;
44450
+ case "numeric-input":
44451
+ return userInput.currentValue;
44452
+ case "radio":
44453
+ return userInput.choicesSelected;
44454
+ }
44455
+ return userInput;
44456
+ };
44457
+
44458
+ /* Returns the correct answer for a given widget key and Perseus Item */
44459
+ // TODO (LEMS-1835): We should fix the resonse type from getWidget to be specific.
44460
+ // TODO (LEMS-1836): We should also consider adding the getOneCorrectAnswerFromRubric method to all widgets.
44461
+ const getCorrectAnswerForWidgetKey = (widgetKey, itemData) => {
44462
+ const rubric = itemData.question.widgets[widgetKey].options;
44463
+ const widgetType = getWidgetTypeFromWidgetKey(widgetKey);
44464
+ const widget = getWidget(widgetType);
44465
+
44466
+ // @ts-expect-error - TS2339 - Property 'getOneCorrectAnswerFromRubric' does not exist on type 'ComponentType<any>'.
44467
+ return widget == null || widget.getOneCorrectAnswerFromRubric == null ? void 0 : widget.getOneCorrectAnswerFromRubric(rubric);
44468
+ };
44469
+
44470
+ /* Verify if the widget key exists in the content string of the Perseus Item */
44471
+ const isWidgetKeyInContent = (perseusItem, widgetKey) => {
44472
+ return perseusItem.question.content.indexOf(widgetKey) !== -1;
44473
+ };
44474
+
44475
+ /* Return an array of all the widget keys that exist in the content string of a Perseus Item */
44476
+ const getValidWidgetKeys = perseusItem => {
44477
+ const {
44478
+ widgets
44479
+ } = perseusItem.question;
44480
+ return keys(widgets).filter(key => isWidgetKeyInContent(perseusItem, key));
44481
+ };
44482
+
44423
44483
  /**
44424
44484
  * Helper to parse PerseusItem JSON
44425
44485
  * Why not just use JSON.parse? We want:
@@ -44691,5 +44751,5 @@ const EditorJsonify = {
44691
44751
  }
44692
44752
  };
44693
44753
 
44694
- export { ApiOptions, ArrowPicker, ArticleRenderer, BaseRadio, Categorizer$1 as Categorizer, changeable as Changeable, ClassNames, ColorPicker, DashPicker, dependencies as Dependencies, EditorJsonify, ElementContainer, Errors, Expression, util as GrapherUtil, Grapher$1 as GrapherWidget, HintRenderer, HintsRenderer, InputNumber$1 as InputNumber, InteractiveGraph$1 as InteractiveGraphWidget, ItemExtras, JiptParagraphs, KhanColors, KhanMath, context as LoadingContext, Log, Matrix$1 as MatrixWidget, MultiItems, NumericInput$1 as NumericInput, PerseusError, PerseusExpressionAnswerFormConsidered, PerseusMarkdown, Plotter$1 as PlotterWidget, QUESTION_WIDGETS, Radio, Renderer, ref as ServerItemRenderer, sizingUtils as SizingUtils, Table$1 as TableWidget, Util, denylist as WIDGET_PROP_DENYLIST, WidgetJsonifyDeprecated, WidgetType, widgets$1 as Widgets, addWidget, apiVersion, buildEmptyItemTreeForShape, buildMapper, components, constants, convertWidgetNameToEnum, displaySigFigs, generateTestPerseusItem, genericPerseusItemData, getAllWidgetIds, getAllWidgetTypes, getAnswersFromWidgets, getQuestionWidgetIds, getWidgetTypeFromWidgetId, globalConstants, globalStyles, iconPaths as icons, init, injectWidgets, interactiveSizes$1 as interactiveSizes, isItemRenderableByVersion, itemDataVersion, itemToTree, ItemVersion as itemVersion, libVersion, mediaQueries, parsePerseusItem, plotterPlotTypes, preprocessTex, registerAllWidgetsForTesting, shapes, traverse, violatingWidgets, allWidgets as widgets };
44754
+ export { ApiOptions, ArrowPicker, ArticleRenderer, BaseRadio, Categorizer$1 as Categorizer, changeable as Changeable, ClassNames, ColorPicker, DashPicker, dependencies as Dependencies, EditorJsonify, ElementContainer, Errors, Expression, util as GrapherUtil, Grapher$1 as GrapherWidget, HintRenderer, HintsRenderer, InputNumber$1 as InputNumber, InteractiveGraph$1 as InteractiveGraphWidget, ItemExtras, JiptParagraphs, KhanColors, KhanMath, context as LoadingContext, Log, Matrix$1 as MatrixWidget, MultiItems, NumericInput$1 as NumericInput, PerseusError, PerseusExpressionAnswerFormConsidered, PerseusMarkdown, Plotter$1 as PlotterWidget, QUESTION_WIDGETS, Radio, Renderer, ref as ServerItemRenderer, sizingUtils as SizingUtils, Table$1 as TableWidget, Util, denylist as WIDGET_PROP_DENYLIST, WidgetJsonifyDeprecated, WidgetType, widgets$1 as Widgets, addWidget, apiVersion, buildEmptyItemTreeForShape, buildMapper, components, constants, convertWidgetNameToEnum, displaySigFigs, generateTestPerseusItem, genericPerseusItemData, getAllWidgetIds, getAllWidgetTypes, getAnswerFromUserInput, getAnswersFromWidgets, getCorrectAnswerForWidgetKey, getQuestionWidgetIds, getValidWidgetKeys, getWidgetTypeFromWidgetId, getWidgetTypeFromWidgetKey, globalConstants, globalStyles, iconPaths as icons, init, injectWidgets, interactiveSizes$1 as interactiveSizes, isItemRenderableByVersion, isWidgetKeyInContent, isWrongAnswerSupported, itemDataVersion, itemToTree, ItemVersion as itemVersion, libVersion, mediaQueries, parsePerseusItem, plotterPlotTypes, preprocessTex, registerAllWidgetsForTesting, shapes, shouldHaveIndividualAnswer, traverse, violatingWidgets, allWidgets as widgets };
44695
44755
  //# sourceMappingURL=index.js.map