@khanacademy/perseus-core 3.3.0 → 3.5.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/data-schema.d.ts +1 -1
- package/dist/es/index.js +459 -34
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +496 -30
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/widgets/core-widget-registry.d.ts +28 -0
- package/dist/widgets/cs-program/cs-program-util.d.ts +2 -0
- package/dist/widgets/dropdown/dropdown-util.d.ts +20 -0
- package/dist/widgets/graded-group/index.d.ts +2 -2
- package/dist/widgets/graded-group-set/index.d.ts +2 -2
- package/dist/widgets/grapher/grapher-util.d.ts +4 -0
- package/dist/widgets/grapher/index.d.ts +5 -0
- package/dist/widgets/group/index.d.ts +2 -2
- package/dist/widgets/iframe/iframe-util.d.ts +2 -0
- package/dist/widgets/interactive-graph/interactive-graph-util.d.ts +4 -0
- package/dist/widgets/label-image/label-image-util.d.ts +19 -0
- package/dist/widgets/logic-export.types.d.ts +3 -0
- package/dist/widgets/matrix/matrix-util.d.ts +4 -0
- package/dist/widgets/number-line/number-line-util.d.ts +4 -0
- package/dist/widgets/numeric-input/numeric-input-util.d.ts +19 -0
- package/dist/widgets/phet-simulation/index.d.ts +2 -2
- package/dist/widgets/plotter/plotter-util.d.ts +12 -0
- package/dist/widgets/radio/radio-util.d.ts +26 -0
- package/dist/widgets/sorter/sorter-util.d.ts +16 -0
- package/dist/widgets/table/table-util.d.ts +4 -0
- package/dist/widgets/upgrade.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4606,7 +4606,7 @@ function throwErrorIfCheatingDetected() {
|
|
|
4606
4606
|
|
|
4607
4607
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
4608
4608
|
const libName = "@khanacademy/perseus-core";
|
|
4609
|
-
const libVersion = "3.
|
|
4609
|
+
const libVersion = "3.5.0";
|
|
4610
4610
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
4611
4611
|
|
|
4612
4612
|
/**
|
|
@@ -4705,7 +4705,7 @@ const mapObject = function (obj, lambda) {
|
|
|
4705
4705
|
return result;
|
|
4706
4706
|
};
|
|
4707
4707
|
|
|
4708
|
-
const defaultWidgetOptions$
|
|
4708
|
+
const defaultWidgetOptions$v = {
|
|
4709
4709
|
items: [],
|
|
4710
4710
|
categories: [],
|
|
4711
4711
|
values: [],
|
|
@@ -4713,11 +4713,11 @@ const defaultWidgetOptions$u = {
|
|
|
4713
4713
|
};
|
|
4714
4714
|
const categorizerWidgetLogic = {
|
|
4715
4715
|
name: "categorizer",
|
|
4716
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4716
|
+
defaultWidgetOptions: defaultWidgetOptions$v
|
|
4717
4717
|
};
|
|
4718
4718
|
|
|
4719
4719
|
const DEFAULT_HEIGHT = 400;
|
|
4720
|
-
const defaultWidgetOptions$
|
|
4720
|
+
const defaultWidgetOptions$u = {
|
|
4721
4721
|
programID: "",
|
|
4722
4722
|
programType: null,
|
|
4723
4723
|
settings: [{
|
|
@@ -4730,19 +4730,21 @@ const defaultWidgetOptions$t = {
|
|
|
4730
4730
|
};
|
|
4731
4731
|
const csProgramWidgetLogic = {
|
|
4732
4732
|
name: "cs-program",
|
|
4733
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4733
|
+
defaultWidgetOptions: defaultWidgetOptions$u,
|
|
4734
|
+
supportedAlignments: ["block", "full-width"]
|
|
4734
4735
|
};
|
|
4735
4736
|
|
|
4736
|
-
const defaultWidgetOptions$
|
|
4737
|
+
const defaultWidgetOptions$t = {
|
|
4737
4738
|
togglePrompt: "",
|
|
4738
4739
|
definition: ""
|
|
4739
4740
|
};
|
|
4740
4741
|
const definitionWidgetLogic = {
|
|
4741
4742
|
name: "definition",
|
|
4742
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4743
|
+
defaultWidgetOptions: defaultWidgetOptions$t,
|
|
4744
|
+
defaultAlignment: "inline"
|
|
4743
4745
|
};
|
|
4744
4746
|
|
|
4745
|
-
const defaultWidgetOptions$
|
|
4747
|
+
const defaultWidgetOptions$s = {
|
|
4746
4748
|
placeholder: "",
|
|
4747
4749
|
choices: [{
|
|
4748
4750
|
content: "",
|
|
@@ -4751,10 +4753,11 @@ const defaultWidgetOptions$r = {
|
|
|
4751
4753
|
};
|
|
4752
4754
|
const dropdownWidgetLogic = {
|
|
4753
4755
|
name: "definition",
|
|
4754
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4756
|
+
defaultWidgetOptions: defaultWidgetOptions$s,
|
|
4757
|
+
defaultAlignment: "inline-block"
|
|
4755
4758
|
};
|
|
4756
4759
|
|
|
4757
|
-
const defaultWidgetOptions$
|
|
4760
|
+
const defaultWidgetOptions$r = {
|
|
4758
4761
|
showPrompt: "Explain",
|
|
4759
4762
|
hidePrompt: "Hide explanation",
|
|
4760
4763
|
explanation: "explanation goes here\n\nmore explanation",
|
|
@@ -4762,7 +4765,8 @@ const defaultWidgetOptions$q = {
|
|
|
4762
4765
|
};
|
|
4763
4766
|
const explanationWidgetLogic = {
|
|
4764
4767
|
name: "explanation",
|
|
4765
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4768
|
+
defaultWidgetOptions: defaultWidgetOptions$r,
|
|
4769
|
+
defaultAlignment: "inline"
|
|
4766
4770
|
};
|
|
4767
4771
|
|
|
4768
4772
|
const currentVersion$3 = {
|
|
@@ -4785,7 +4789,7 @@ const widgetOptionsUpgrades$2 = {
|
|
|
4785
4789
|
}]
|
|
4786
4790
|
})
|
|
4787
4791
|
};
|
|
4788
|
-
const defaultWidgetOptions$
|
|
4792
|
+
const defaultWidgetOptions$q = {
|
|
4789
4793
|
answerForms: [],
|
|
4790
4794
|
times: false,
|
|
4791
4795
|
buttonSets: ["basic"],
|
|
@@ -4796,26 +4800,52 @@ const expressionWidgetLogic = {
|
|
|
4796
4800
|
name: "expression",
|
|
4797
4801
|
version: currentVersion$3,
|
|
4798
4802
|
widgetOptionsUpgrades: widgetOptionsUpgrades$2,
|
|
4799
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4803
|
+
defaultWidgetOptions: defaultWidgetOptions$q,
|
|
4804
|
+
defaultAlignment: "inline-block"
|
|
4800
4805
|
};
|
|
4801
4806
|
|
|
4802
|
-
const defaultWidgetOptions$
|
|
4807
|
+
const defaultWidgetOptions$p = {
|
|
4803
4808
|
title: "",
|
|
4804
4809
|
content: "",
|
|
4805
4810
|
widgets: {},
|
|
4806
4811
|
images: {},
|
|
4807
4812
|
hint: null
|
|
4808
4813
|
};
|
|
4809
|
-
const
|
|
4814
|
+
const gradedGroupWidgetLogic = {
|
|
4810
4815
|
name: "graded-group",
|
|
4811
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4816
|
+
defaultWidgetOptions: defaultWidgetOptions$p
|
|
4812
4817
|
};
|
|
4813
4818
|
|
|
4814
|
-
const defaultWidgetOptions$
|
|
4819
|
+
const defaultWidgetOptions$o = {
|
|
4815
4820
|
gradedGroups: []
|
|
4816
4821
|
};
|
|
4817
|
-
const
|
|
4822
|
+
const gradedGroupSetWidgetLogic = {
|
|
4818
4823
|
name: "graded-group-set",
|
|
4824
|
+
defaultWidgetOptions: defaultWidgetOptions$o
|
|
4825
|
+
};
|
|
4826
|
+
|
|
4827
|
+
const defaultWidgetOptions$n = {
|
|
4828
|
+
graph: {
|
|
4829
|
+
labels: ["x", "y"],
|
|
4830
|
+
range: [[-10, 10], [-10, 10]],
|
|
4831
|
+
step: [1, 1],
|
|
4832
|
+
backgroundImage: {
|
|
4833
|
+
url: null
|
|
4834
|
+
},
|
|
4835
|
+
markings: "graph",
|
|
4836
|
+
rulerLabel: "",
|
|
4837
|
+
rulerTicks: 10,
|
|
4838
|
+
valid: true,
|
|
4839
|
+
showTooltips: false
|
|
4840
|
+
},
|
|
4841
|
+
correct: {
|
|
4842
|
+
type: "linear",
|
|
4843
|
+
coords: null
|
|
4844
|
+
},
|
|
4845
|
+
availableTypes: ["linear"]
|
|
4846
|
+
};
|
|
4847
|
+
const grapherWidgetLogic = {
|
|
4848
|
+
name: "grapher",
|
|
4819
4849
|
defaultWidgetOptions: defaultWidgetOptions$n
|
|
4820
4850
|
};
|
|
4821
4851
|
|
|
@@ -4827,7 +4857,7 @@ const defaultWidgetOptions$m = {
|
|
|
4827
4857
|
// `the GroupMetadataEditor`
|
|
4828
4858
|
metadata: undefined
|
|
4829
4859
|
};
|
|
4830
|
-
const
|
|
4860
|
+
const groupWidgetLogic = {
|
|
4831
4861
|
name: "group",
|
|
4832
4862
|
defaultWidgetOptions: defaultWidgetOptions$m
|
|
4833
4863
|
};
|
|
@@ -4863,7 +4893,9 @@ const defaultWidgetOptions$k = {
|
|
|
4863
4893
|
};
|
|
4864
4894
|
const imageWidgetLogic = {
|
|
4865
4895
|
name: "image",
|
|
4866
|
-
defaultWidgetOptions: defaultWidgetOptions$k
|
|
4896
|
+
defaultWidgetOptions: defaultWidgetOptions$k,
|
|
4897
|
+
supportedAlignments: ["block", "full-width"],
|
|
4898
|
+
defaultAlignment: "block"
|
|
4867
4899
|
};
|
|
4868
4900
|
|
|
4869
4901
|
const defaultWidgetOptions$j = {
|
|
@@ -4877,7 +4909,8 @@ const defaultWidgetOptions$j = {
|
|
|
4877
4909
|
};
|
|
4878
4910
|
const inputNumberWidgetLogic = {
|
|
4879
4911
|
name: "input-number",
|
|
4880
|
-
defaultWidgetOptions: defaultWidgetOptions$j
|
|
4912
|
+
defaultWidgetOptions: defaultWidgetOptions$j,
|
|
4913
|
+
defaultAlignment: "inline-block"
|
|
4881
4914
|
};
|
|
4882
4915
|
|
|
4883
4916
|
const defaultWidgetOptions$i = {
|
|
@@ -5034,7 +5067,8 @@ const defaultWidgetOptions$b = {
|
|
|
5034
5067
|
};
|
|
5035
5068
|
const numericInputWidgetLogic = {
|
|
5036
5069
|
name: "numeric-input",
|
|
5037
|
-
defaultWidgetOptions: defaultWidgetOptions$b
|
|
5070
|
+
defaultWidgetOptions: defaultWidgetOptions$b,
|
|
5071
|
+
defaultAlignment: "inline-block"
|
|
5038
5072
|
};
|
|
5039
5073
|
|
|
5040
5074
|
const defaultWidgetOptions$a = {
|
|
@@ -5076,7 +5110,8 @@ const defaultWidgetOptions$8 = {
|
|
|
5076
5110
|
const passageRefWidgetLogic = {
|
|
5077
5111
|
name: "passageRef",
|
|
5078
5112
|
version: currentVersion$1,
|
|
5079
|
-
defaultWidgetOptions: defaultWidgetOptions$8
|
|
5113
|
+
defaultWidgetOptions: defaultWidgetOptions$8,
|
|
5114
|
+
defaultAlignment: "inline"
|
|
5080
5115
|
};
|
|
5081
5116
|
|
|
5082
5117
|
const defaultWidgetOptions$7 = {
|
|
@@ -5084,14 +5119,15 @@ const defaultWidgetOptions$7 = {
|
|
|
5084
5119
|
};
|
|
5085
5120
|
const passageRefTargetWidgetLogic = {
|
|
5086
5121
|
name: "passageRefTarget",
|
|
5087
|
-
defaultWidgetOptions: defaultWidgetOptions$7
|
|
5122
|
+
defaultWidgetOptions: defaultWidgetOptions$7,
|
|
5123
|
+
defaultAlignment: "inline"
|
|
5088
5124
|
};
|
|
5089
5125
|
|
|
5090
5126
|
const defaultWidgetOptions$6 = {
|
|
5091
5127
|
url: "",
|
|
5092
5128
|
description: ""
|
|
5093
5129
|
};
|
|
5094
|
-
const
|
|
5130
|
+
const phetSimulationWidgetLogic = {
|
|
5095
5131
|
name: "phet-simulation",
|
|
5096
5132
|
defaultWidgetOptions: defaultWidgetOptions$6
|
|
5097
5133
|
};
|
|
@@ -5193,9 +5229,242 @@ const defaultWidgetOptions = {
|
|
|
5193
5229
|
};
|
|
5194
5230
|
const videoWidgetLogic = {
|
|
5195
5231
|
name: "video",
|
|
5196
|
-
defaultWidgetOptions
|
|
5232
|
+
defaultWidgetOptions,
|
|
5233
|
+
supportedAlignments: ["block", "float-left", "float-right", "full-width"],
|
|
5234
|
+
defaultAlignment: "block"
|
|
5197
5235
|
};
|
|
5198
5236
|
|
|
5237
|
+
const widgets = {};
|
|
5238
|
+
function registerWidget(type, logic) {
|
|
5239
|
+
widgets[type] = logic;
|
|
5240
|
+
}
|
|
5241
|
+
function isWidgetRegistered(type) {
|
|
5242
|
+
const widgetLogic = widgets[type];
|
|
5243
|
+
return !!widgetLogic;
|
|
5244
|
+
}
|
|
5245
|
+
function getCurrentVersion(type) {
|
|
5246
|
+
const widgetLogic = widgets[type];
|
|
5247
|
+
return widgetLogic?.version || {
|
|
5248
|
+
major: 0,
|
|
5249
|
+
minor: 0
|
|
5250
|
+
};
|
|
5251
|
+
}
|
|
5252
|
+
function getWidgetOptionsUpgrades(type) {
|
|
5253
|
+
const widgetLogic = widgets[type];
|
|
5254
|
+
return widgetLogic?.widgetOptionsUpgrades || {};
|
|
5255
|
+
}
|
|
5256
|
+
function getDefaultWidgetOptions(type) {
|
|
5257
|
+
const widgetLogic = widgets[type];
|
|
5258
|
+
return widgetLogic?.defaultWidgetOptions || {};
|
|
5259
|
+
}
|
|
5260
|
+
|
|
5261
|
+
/**
|
|
5262
|
+
* Handling for the optional alignments for widgets
|
|
5263
|
+
* See widget-container.jsx for details on how alignments are implemented.
|
|
5264
|
+
*/
|
|
5265
|
+
|
|
5266
|
+
/**
|
|
5267
|
+
* Returns the list of supported alignments for the given (string) widget
|
|
5268
|
+
* type. This is used primarily at editing time to display the choices
|
|
5269
|
+
* for the user.
|
|
5270
|
+
*
|
|
5271
|
+
* Supported alignments are given as an array of strings in the exports of
|
|
5272
|
+
* a widget's module.
|
|
5273
|
+
*/
|
|
5274
|
+
const getSupportedAlignments = type => {
|
|
5275
|
+
const widgetLogic = widgets[type];
|
|
5276
|
+
if (!widgetLogic?.supportedAlignments?.[0]) {
|
|
5277
|
+
// default alignments
|
|
5278
|
+
return ["default"];
|
|
5279
|
+
}
|
|
5280
|
+
return widgetLogic?.supportedAlignments;
|
|
5281
|
+
};
|
|
5282
|
+
|
|
5283
|
+
/**
|
|
5284
|
+
* For the given (string) widget type, determine the default alignment for
|
|
5285
|
+
* the widget. This is used at rendering time to go from "default" alignment
|
|
5286
|
+
* to the actual alignment displayed on the screen.
|
|
5287
|
+
*
|
|
5288
|
+
* The default alignment is given either as a string (called
|
|
5289
|
+
* `defaultAlignment`) or a function (called `getDefaultAlignment`) on
|
|
5290
|
+
* the exports of a widget's module.
|
|
5291
|
+
*/
|
|
5292
|
+
const getDefaultAlignment = type => {
|
|
5293
|
+
const widgetLogic = widgets[type];
|
|
5294
|
+
if (!widgetLogic?.defaultAlignment) {
|
|
5295
|
+
return "block";
|
|
5296
|
+
}
|
|
5297
|
+
return widgetLogic.defaultAlignment;
|
|
5298
|
+
};
|
|
5299
|
+
registerWidget("categorizer", categorizerWidgetLogic);
|
|
5300
|
+
registerWidget("cs-program", csProgramWidgetLogic);
|
|
5301
|
+
registerWidget("definition", definitionWidgetLogic);
|
|
5302
|
+
registerWidget("dropdown", dropdownWidgetLogic);
|
|
5303
|
+
registerWidget("explanation", explanationWidgetLogic);
|
|
5304
|
+
registerWidget("expression", expressionWidgetLogic);
|
|
5305
|
+
registerWidget("graded-group", gradedGroupWidgetLogic);
|
|
5306
|
+
registerWidget("graded-group-set", gradedGroupSetWidgetLogic);
|
|
5307
|
+
registerWidget("grapher", grapherWidgetLogic);
|
|
5308
|
+
registerWidget("group", groupWidgetLogic);
|
|
5309
|
+
registerWidget("iframe", iframeWidgetLogic);
|
|
5310
|
+
registerWidget("image", imageWidgetLogic);
|
|
5311
|
+
registerWidget("input-number", inputNumberWidgetLogic);
|
|
5312
|
+
registerWidget("interaction", interactionWidgetLogic);
|
|
5313
|
+
registerWidget("interactive-graph", interactiveGraphWidgetLogic);
|
|
5314
|
+
registerWidget("label-image", labelImageWidgetLogic);
|
|
5315
|
+
registerWidget("matcher", matcherWidgetLogic);
|
|
5316
|
+
registerWidget("matrix", matrixWidgetLogic);
|
|
5317
|
+
registerWidget("measurer", measurerWidgetLogic);
|
|
5318
|
+
registerWidget("number-line", numberLineWidgetLogic);
|
|
5319
|
+
registerWidget("numeric-input", numericInputWidgetLogic);
|
|
5320
|
+
registerWidget("orderer", ordererWidgetLogic);
|
|
5321
|
+
registerWidget("passage", passageWidgetLogic);
|
|
5322
|
+
registerWidget("passage-ref", passageRefWidgetLogic);
|
|
5323
|
+
registerWidget("passage-ref-target", passageRefTargetWidgetLogic);
|
|
5324
|
+
registerWidget("phet-simulation", phetSimulationWidgetLogic);
|
|
5325
|
+
registerWidget("plotter", plotterWidgetLogic);
|
|
5326
|
+
registerWidget("python-program", pythonProgramWidgetLogic);
|
|
5327
|
+
registerWidget("radio", radioWidgetLogic);
|
|
5328
|
+
registerWidget("sorter", sorterWidgetLogic);
|
|
5329
|
+
registerWidget("table", tableWidgetLogic);
|
|
5330
|
+
registerWidget("video", videoWidgetLogic);
|
|
5331
|
+
|
|
5332
|
+
var coreWidgetRegistry = /*#__PURE__*/Object.freeze({
|
|
5333
|
+
__proto__: null,
|
|
5334
|
+
isWidgetRegistered: isWidgetRegistered,
|
|
5335
|
+
getCurrentVersion: getCurrentVersion,
|
|
5336
|
+
getWidgetOptionsUpgrades: getWidgetOptionsUpgrades,
|
|
5337
|
+
getDefaultWidgetOptions: getDefaultWidgetOptions,
|
|
5338
|
+
getSupportedAlignments: getSupportedAlignments,
|
|
5339
|
+
getDefaultAlignment: getDefaultAlignment
|
|
5340
|
+
});
|
|
5341
|
+
|
|
5342
|
+
const DEFAULT_STATIC = false;
|
|
5343
|
+
const upgradeWidgetInfoToLatestVersion = oldWidgetInfo => {
|
|
5344
|
+
const type = oldWidgetInfo.type;
|
|
5345
|
+
// NOTE(jeremy): This looks like it could be replaced by fixing types so
|
|
5346
|
+
// that `type` is non-optional. But we're seeing this in Sentry today so I
|
|
5347
|
+
// suspect we have legacy data (potentially unpublished) and we should
|
|
5348
|
+
// figure that out before depending solely on types.
|
|
5349
|
+
if (!_.isString(type)) {
|
|
5350
|
+
throw new PerseusError("widget type must be a string, but was: " + type, Errors.Internal);
|
|
5351
|
+
}
|
|
5352
|
+
if (!isWidgetRegistered(type)) {
|
|
5353
|
+
// If we have a widget that isn't registered, we can't upgrade it
|
|
5354
|
+
// TODO(aria): Figure out what the best thing to do here would be
|
|
5355
|
+
return oldWidgetInfo;
|
|
5356
|
+
}
|
|
5357
|
+
|
|
5358
|
+
// Unversioned widgets (pre-July 2014) are all implicitly 0.0
|
|
5359
|
+
const initialVersion = oldWidgetInfo.version || {
|
|
5360
|
+
major: 0,
|
|
5361
|
+
minor: 0
|
|
5362
|
+
};
|
|
5363
|
+
const latestVersion = getCurrentVersion(type);
|
|
5364
|
+
|
|
5365
|
+
// If the widget version is later than what we understand (major
|
|
5366
|
+
// version is higher than latest, or major versions are equal and minor
|
|
5367
|
+
// version is higher than latest), don't perform any upgrades.
|
|
5368
|
+
if (initialVersion.major > latestVersion.major || initialVersion.major === latestVersion.major && initialVersion.minor > latestVersion.minor) {
|
|
5369
|
+
return oldWidgetInfo;
|
|
5370
|
+
}
|
|
5371
|
+
|
|
5372
|
+
// We do a clone here so that it's safe to mutate the input parameter
|
|
5373
|
+
// in propUpgrades functions (which I will probably accidentally do at
|
|
5374
|
+
// some point, and we would like to not break when that happens).
|
|
5375
|
+
let newEditorOptions = _.clone(oldWidgetInfo.options) || {};
|
|
5376
|
+
const upgradePropsMap = getWidgetOptionsUpgrades(type);
|
|
5377
|
+
|
|
5378
|
+
// Empty props usually mean a newly created widget by the editor,
|
|
5379
|
+
// and are always considerered up-to-date.
|
|
5380
|
+
// Mostly, we'd rather not run upgrade functions on props that are
|
|
5381
|
+
// not complete.
|
|
5382
|
+
if (_.keys(newEditorOptions).length !== 0) {
|
|
5383
|
+
// We loop through all the versions after the current version of
|
|
5384
|
+
// the loaded widget, up to and including the latest version of the
|
|
5385
|
+
// loaded widget, and run the upgrade function to bring our loaded
|
|
5386
|
+
// widget's props up to that version.
|
|
5387
|
+
// There is a little subtlety here in that we call
|
|
5388
|
+
// upgradePropsMap[1] to upgrade *to* version 1,
|
|
5389
|
+
// (not from version 1).
|
|
5390
|
+
for (let nextVersion = initialVersion.major + 1; nextVersion <= latestVersion.major; nextVersion++) {
|
|
5391
|
+
if (upgradePropsMap[String(nextVersion)]) {
|
|
5392
|
+
newEditorOptions = upgradePropsMap[String(nextVersion)](newEditorOptions);
|
|
5393
|
+
} else {
|
|
5394
|
+
throw new PerseusError("No upgrade found for widget. Cannot render.", Errors.Internal, {
|
|
5395
|
+
metadata: {
|
|
5396
|
+
type,
|
|
5397
|
+
fromMajorVersion: nextVersion - 1,
|
|
5398
|
+
toMajorVersion: nextVersion,
|
|
5399
|
+
oldWidgetInfo: JSON.stringify(oldWidgetInfo)
|
|
5400
|
+
}
|
|
5401
|
+
});
|
|
5402
|
+
}
|
|
5403
|
+
}
|
|
5404
|
+
}
|
|
5405
|
+
|
|
5406
|
+
// Minor version upgrades (eg. new optional props) don't have
|
|
5407
|
+
// transform functions. Instead, we fill in the new props with their
|
|
5408
|
+
// defaults.
|
|
5409
|
+
const defaultOptions = getDefaultWidgetOptions(type);
|
|
5410
|
+
newEditorOptions = {
|
|
5411
|
+
...defaultOptions,
|
|
5412
|
+
...newEditorOptions
|
|
5413
|
+
};
|
|
5414
|
+
let alignment = oldWidgetInfo.alignment;
|
|
5415
|
+
|
|
5416
|
+
// Widgets that support multiple alignments will "lock in" the
|
|
5417
|
+
// alignment to the alignment that would be listed first in the
|
|
5418
|
+
// select box. If the widget only supports one alignment, the
|
|
5419
|
+
// alignment value will likely just end up as "default".
|
|
5420
|
+
if (alignment == null || alignment === "default") {
|
|
5421
|
+
alignment = getSupportedAlignments(type)?.[0];
|
|
5422
|
+
if (!alignment) {
|
|
5423
|
+
throw new PerseusError("No default alignment found when upgrading widget", Errors.Internal, {
|
|
5424
|
+
metadata: {
|
|
5425
|
+
widgetType: type
|
|
5426
|
+
}
|
|
5427
|
+
});
|
|
5428
|
+
}
|
|
5429
|
+
}
|
|
5430
|
+
let widgetStatic = oldWidgetInfo.static;
|
|
5431
|
+
if (widgetStatic == null) {
|
|
5432
|
+
widgetStatic = DEFAULT_STATIC;
|
|
5433
|
+
}
|
|
5434
|
+
return {
|
|
5435
|
+
...oldWidgetInfo,
|
|
5436
|
+
// maintain other info, like type
|
|
5437
|
+
// After upgrading we guarantee that the version is up-to-date
|
|
5438
|
+
version: latestVersion,
|
|
5439
|
+
// Default graded to true (so null/undefined becomes true):
|
|
5440
|
+
graded: oldWidgetInfo.graded != null ? oldWidgetInfo.graded : true,
|
|
5441
|
+
alignment: alignment,
|
|
5442
|
+
static: widgetStatic,
|
|
5443
|
+
options: newEditorOptions
|
|
5444
|
+
};
|
|
5445
|
+
};
|
|
5446
|
+
function getUpgradedWidgetOptions(oldWidgetOptions) {
|
|
5447
|
+
return mapObject(oldWidgetOptions, (widgetInfo, widgetId) => {
|
|
5448
|
+
if (!widgetInfo.type || !widgetInfo.alignment) {
|
|
5449
|
+
const newValues = {};
|
|
5450
|
+
if (!widgetInfo.type) {
|
|
5451
|
+
// TODO: why does widget have no type?
|
|
5452
|
+
// We don't want to derive type from widget ID
|
|
5453
|
+
// see: LEMS-1845
|
|
5454
|
+
newValues.type = widgetId.split(" ")[0];
|
|
5455
|
+
}
|
|
5456
|
+
if (!widgetInfo.alignment) {
|
|
5457
|
+
newValues.alignment = "default";
|
|
5458
|
+
}
|
|
5459
|
+
widgetInfo = {
|
|
5460
|
+
...widgetInfo,
|
|
5461
|
+
...newValues
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
return upgradeWidgetInfoToLatestVersion(widgetInfo);
|
|
5465
|
+
});
|
|
5466
|
+
}
|
|
5467
|
+
|
|
5199
5468
|
/**
|
|
5200
5469
|
* For details on the individual options, see the
|
|
5201
5470
|
* PerseusOrdererWidgetOptions type
|
|
@@ -5231,6 +5500,10 @@ function getCategorizerPublicWidgetOptions(options) {
|
|
|
5231
5500
|
};
|
|
5232
5501
|
}
|
|
5233
5502
|
|
|
5503
|
+
function getCSProgramPublicWidgetOptions(options) {
|
|
5504
|
+
return options;
|
|
5505
|
+
}
|
|
5506
|
+
|
|
5234
5507
|
/**
|
|
5235
5508
|
* For details on the individual options, see the
|
|
5236
5509
|
* PerseusExpressionWidgetOptions type
|
|
@@ -5251,6 +5524,183 @@ function getExpressionPublicWidgetOptions(options) {
|
|
|
5251
5524
|
};
|
|
5252
5525
|
}
|
|
5253
5526
|
|
|
5527
|
+
function getGrapherPublicWidgetOptions(options) {
|
|
5528
|
+
const {
|
|
5529
|
+
correct: _,
|
|
5530
|
+
...publicOptions
|
|
5531
|
+
} = options;
|
|
5532
|
+
return publicOptions;
|
|
5533
|
+
}
|
|
5534
|
+
|
|
5535
|
+
function getInteractiveGraphPublicWidgetOptions(options) {
|
|
5536
|
+
const {
|
|
5537
|
+
correct: _,
|
|
5538
|
+
...publicOptions
|
|
5539
|
+
} = options;
|
|
5540
|
+
return publicOptions;
|
|
5541
|
+
}
|
|
5542
|
+
|
|
5543
|
+
/**
|
|
5544
|
+
* For details on the individual options, see the
|
|
5545
|
+
* PerseusLabelImageWidgetOptions type
|
|
5546
|
+
*/
|
|
5547
|
+
|
|
5548
|
+
function getLabelImagePublicWidgetOptions(options) {
|
|
5549
|
+
return {
|
|
5550
|
+
...options,
|
|
5551
|
+
markers: options.markers.map(getLabelImageMarkerPublicData)
|
|
5552
|
+
};
|
|
5553
|
+
}
|
|
5554
|
+
function getLabelImageMarkerPublicData(marker) {
|
|
5555
|
+
const {
|
|
5556
|
+
answers: _,
|
|
5557
|
+
...publicData
|
|
5558
|
+
} = marker;
|
|
5559
|
+
return publicData;
|
|
5560
|
+
}
|
|
5561
|
+
|
|
5562
|
+
/**
|
|
5563
|
+
* For details on the individual options, see the
|
|
5564
|
+
* PerseusSorterWidgetOptions type
|
|
5565
|
+
*/
|
|
5566
|
+
|
|
5567
|
+
/**
|
|
5568
|
+
* Given a PerseusSorterWidgetOptions object, return a new object with only
|
|
5569
|
+
* the public options that should be exposed to the client.
|
|
5570
|
+
*/
|
|
5571
|
+
function getSorterPublicWidgetOptions(options) {
|
|
5572
|
+
return {
|
|
5573
|
+
// Note(Tamara): This does not provide correct answer information any longer.
|
|
5574
|
+
// To maintain compatibility with the original widget options, we are
|
|
5575
|
+
// keeping the key the same. Represents initial state of the cards here.
|
|
5576
|
+
correct: options.correct.slice().sort(),
|
|
5577
|
+
padding: options.padding,
|
|
5578
|
+
layout: options.layout
|
|
5579
|
+
};
|
|
5580
|
+
}
|
|
5581
|
+
|
|
5582
|
+
/**
|
|
5583
|
+
* For details on the individual options, see the
|
|
5584
|
+
* PerseusDropdownWidgetOptions type
|
|
5585
|
+
*/
|
|
5586
|
+
|
|
5587
|
+
/**
|
|
5588
|
+
* Given a PerseusDropdownWidgetOptions object, return a new object with only
|
|
5589
|
+
* the public options that should be exposed to the client.
|
|
5590
|
+
*/
|
|
5591
|
+
function getDropdownPublicWidgetOptions(options) {
|
|
5592
|
+
return {
|
|
5593
|
+
choices: options.choices.map(choice => ({
|
|
5594
|
+
content: choice.content
|
|
5595
|
+
})),
|
|
5596
|
+
placeholder: options.placeholder,
|
|
5597
|
+
static: options.static,
|
|
5598
|
+
visibleLabel: options.visibleLabel,
|
|
5599
|
+
ariaLabel: options.ariaLabel
|
|
5600
|
+
};
|
|
5601
|
+
}
|
|
5602
|
+
|
|
5603
|
+
/**
|
|
5604
|
+
* For details on the individual options, see the
|
|
5605
|
+
* PerseusNumericInputWidgetOptions type
|
|
5606
|
+
*/
|
|
5607
|
+
|
|
5608
|
+
/**
|
|
5609
|
+
* Given a PerseusNumericInputWidgetOptions object, return a new object with only
|
|
5610
|
+
* the public options that should be exposed to the client.
|
|
5611
|
+
*/
|
|
5612
|
+
function getNumericInputPublicWidgetOptions(options) {
|
|
5613
|
+
const {
|
|
5614
|
+
answers: _,
|
|
5615
|
+
...publicWidgetOptions
|
|
5616
|
+
} = options;
|
|
5617
|
+
return publicWidgetOptions;
|
|
5618
|
+
}
|
|
5619
|
+
|
|
5620
|
+
function getNumberLinePublicWidgetOptions(options) {
|
|
5621
|
+
const {
|
|
5622
|
+
correctX: _,
|
|
5623
|
+
correctRel: __,
|
|
5624
|
+
...publicOptions
|
|
5625
|
+
} = options;
|
|
5626
|
+
return publicOptions;
|
|
5627
|
+
}
|
|
5628
|
+
|
|
5629
|
+
/**
|
|
5630
|
+
* For details on the individual options, see the
|
|
5631
|
+
* PerseusRadioWidgetOptions type
|
|
5632
|
+
*/
|
|
5633
|
+
|
|
5634
|
+
/**
|
|
5635
|
+
* Only the options from each Radio choice that should be exposed to the client.
|
|
5636
|
+
*/
|
|
5637
|
+
|
|
5638
|
+
/**
|
|
5639
|
+
* Given a PerseusRadioChoice object, return a new object with only the public
|
|
5640
|
+
* data that should be included in the Radio public widget options.
|
|
5641
|
+
*/
|
|
5642
|
+
function getRadioChoicePublicData(choice) {
|
|
5643
|
+
const {
|
|
5644
|
+
content,
|
|
5645
|
+
isNoneOfTheAbove,
|
|
5646
|
+
widgets
|
|
5647
|
+
} = choice;
|
|
5648
|
+
return {
|
|
5649
|
+
content,
|
|
5650
|
+
isNoneOfTheAbove,
|
|
5651
|
+
widgets
|
|
5652
|
+
};
|
|
5653
|
+
}
|
|
5654
|
+
|
|
5655
|
+
/**
|
|
5656
|
+
* Given a PerseusRadioWidgetOptions object, return a new object with only
|
|
5657
|
+
* the public options that should be exposed to the client.
|
|
5658
|
+
*/
|
|
5659
|
+
function getRadioPublicWidgetOptions(options) {
|
|
5660
|
+
return {
|
|
5661
|
+
...options,
|
|
5662
|
+
choices: options.choices.map(getRadioChoicePublicData)
|
|
5663
|
+
};
|
|
5664
|
+
}
|
|
5665
|
+
|
|
5666
|
+
function getTablePublicWidgetOptions(options) {
|
|
5667
|
+
const {
|
|
5668
|
+
answers: _,
|
|
5669
|
+
...publicOptions
|
|
5670
|
+
} = options;
|
|
5671
|
+
return publicOptions;
|
|
5672
|
+
}
|
|
5673
|
+
|
|
5674
|
+
function getIFramePublicWidgetOptions(options) {
|
|
5675
|
+
return options;
|
|
5676
|
+
}
|
|
5677
|
+
|
|
5678
|
+
function getMatrixPublicWidgetOptions(options) {
|
|
5679
|
+
const {
|
|
5680
|
+
answers: _,
|
|
5681
|
+
...publicOptions
|
|
5682
|
+
} = options;
|
|
5683
|
+
return publicOptions;
|
|
5684
|
+
}
|
|
5685
|
+
|
|
5686
|
+
/**
|
|
5687
|
+
* For details on the individual options, see the
|
|
5688
|
+
* PerseusPlotterWidgetOptions type
|
|
5689
|
+
*/
|
|
5690
|
+
|
|
5691
|
+
/**
|
|
5692
|
+
* Given a PerseusPlotterWidgetOptions object, return a new object with only
|
|
5693
|
+
* the public options that should be exposed to the client.
|
|
5694
|
+
*/
|
|
5695
|
+
function getPlotterPublicWidgetOptions(options) {
|
|
5696
|
+
const {
|
|
5697
|
+
correct: _,
|
|
5698
|
+
...publicOptions
|
|
5699
|
+
} = options;
|
|
5700
|
+
return publicOptions;
|
|
5701
|
+
}
|
|
5702
|
+
|
|
5703
|
+
exports.CoreWidgetRegistry = coreWidgetRegistry;
|
|
5254
5704
|
exports.Errors = Errors;
|
|
5255
5705
|
exports.GrapherUtil = grapherUtil;
|
|
5256
5706
|
exports.ItemExtras = ItemExtras;
|
|
@@ -5267,16 +5717,31 @@ exports.definitionLogic = definitionWidgetLogic;
|
|
|
5267
5717
|
exports.dropdownLogic = dropdownWidgetLogic;
|
|
5268
5718
|
exports.explanationLogic = explanationWidgetLogic;
|
|
5269
5719
|
exports.expressionLogic = expressionWidgetLogic;
|
|
5720
|
+
exports.getCSProgramPublicWidgetOptions = getCSProgramPublicWidgetOptions;
|
|
5270
5721
|
exports.getCategorizerPublicWidgetOptions = getCategorizerPublicWidgetOptions;
|
|
5271
5722
|
exports.getDecimalSeparator = getDecimalSeparator;
|
|
5723
|
+
exports.getDropdownPublicWidgetOptions = getDropdownPublicWidgetOptions;
|
|
5272
5724
|
exports.getExpressionPublicWidgetOptions = getExpressionPublicWidgetOptions;
|
|
5725
|
+
exports.getGrapherPublicWidgetOptions = getGrapherPublicWidgetOptions;
|
|
5726
|
+
exports.getIFramePublicWidgetOptions = getIFramePublicWidgetOptions;
|
|
5727
|
+
exports.getInteractiveGraphPublicWidgetOptions = getInteractiveGraphPublicWidgetOptions;
|
|
5728
|
+
exports.getLabelImagePublicWidgetOptions = getLabelImagePublicWidgetOptions;
|
|
5729
|
+
exports.getMatrixPublicWidgetOptions = getMatrixPublicWidgetOptions;
|
|
5273
5730
|
exports.getMatrixSize = getMatrixSize;
|
|
5731
|
+
exports.getNumberLinePublicWidgetOptions = getNumberLinePublicWidgetOptions;
|
|
5732
|
+
exports.getNumericInputPublicWidgetOptions = getNumericInputPublicWidgetOptions;
|
|
5274
5733
|
exports.getOrdererPublicWidgetOptions = getOrdererPublicWidgetOptions;
|
|
5734
|
+
exports.getPlotterPublicWidgetOptions = getPlotterPublicWidgetOptions;
|
|
5735
|
+
exports.getRadioPublicWidgetOptions = getRadioPublicWidgetOptions;
|
|
5736
|
+
exports.getSorterPublicWidgetOptions = getSorterPublicWidgetOptions;
|
|
5737
|
+
exports.getTablePublicWidgetOptions = getTablePublicWidgetOptions;
|
|
5738
|
+
exports.getUpgradedWidgetOptions = getUpgradedWidgetOptions;
|
|
5275
5739
|
exports.getWidgetIdsFromContent = getWidgetIdsFromContent;
|
|
5276
5740
|
exports.getWidgetIdsFromContentByType = getWidgetIdsFromContentByType;
|
|
5277
|
-
exports.gradedGroupLogic =
|
|
5278
|
-
exports.gradedGroupSetLogic =
|
|
5279
|
-
exports.
|
|
5741
|
+
exports.gradedGroupLogic = gradedGroupWidgetLogic;
|
|
5742
|
+
exports.gradedGroupSetLogic = gradedGroupSetWidgetLogic;
|
|
5743
|
+
exports.grapherLogic = grapherWidgetLogic;
|
|
5744
|
+
exports.groupLogic = groupWidgetLogic;
|
|
5280
5745
|
exports.iframeLogic = iframeWidgetLogic;
|
|
5281
5746
|
exports.imageLogic = imageWidgetLogic;
|
|
5282
5747
|
exports.inputNumberLogic = inputNumberWidgetLogic;
|
|
@@ -5302,7 +5767,7 @@ exports.parsePerseusItem = parsePerseusItem;
|
|
|
5302
5767
|
exports.passageLogic = passageWidgetLogic;
|
|
5303
5768
|
exports.passageRefLogic = passageRefWidgetLogic;
|
|
5304
5769
|
exports.passageRefTargetLogic = passageRefTargetWidgetLogic;
|
|
5305
|
-
exports.phetSimulationLogic =
|
|
5770
|
+
exports.phetSimulationLogic = phetSimulationWidgetLogic;
|
|
5306
5771
|
exports.plotterLogic = plotterWidgetLogic;
|
|
5307
5772
|
exports.plotterPlotTypes = plotterPlotTypes;
|
|
5308
5773
|
exports.pluck = pluck;
|
|
@@ -5310,5 +5775,6 @@ exports.pythonProgramLogic = pythonProgramWidgetLogic;
|
|
|
5310
5775
|
exports.radioLogic = radioWidgetLogic;
|
|
5311
5776
|
exports.sorterLogic = sorterWidgetLogic;
|
|
5312
5777
|
exports.tableLogic = tableWidgetLogic;
|
|
5778
|
+
exports.upgradeWidgetInfoToLatestVersion = upgradeWidgetInfoToLatestVersion;
|
|
5313
5779
|
exports.videoLogic = videoWidgetLogic;
|
|
5314
5780
|
//# sourceMappingURL=index.js.map
|