@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/data-schema.d.ts
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -4492,7 +4492,7 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
4492
4492
|
if (null == r) return {};
|
|
4493
4493
|
var t = {};
|
|
4494
4494
|
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
4495
|
-
if (e.
|
|
4495
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
4496
4496
|
t[n] = r[n];
|
|
4497
4497
|
}
|
|
4498
4498
|
return t;
|
|
@@ -4506,7 +4506,7 @@ const parseHint = object({
|
|
|
4506
4506
|
images: parseImages
|
|
4507
4507
|
});
|
|
4508
4508
|
|
|
4509
|
-
const _excluded$
|
|
4509
|
+
const _excluded$a = ["type", "options"];
|
|
4510
4510
|
const parsePerseusItem$1 = object({
|
|
4511
4511
|
question: parsePerseusRenderer,
|
|
4512
4512
|
hints: defaulted(array(parseHint), () => []),
|
|
@@ -4533,7 +4533,7 @@ const parsePerseusItem$1 = object({
|
|
|
4533
4533
|
// The "type" and "options" fields don't seem to be used anywhere. This
|
|
4534
4534
|
// migration function removes them.
|
|
4535
4535
|
function migrateAnswerArea(rawValue, ctx) {
|
|
4536
|
-
const rest = _objectWithoutPropertiesLoose(rawValue, _excluded$
|
|
4536
|
+
const rest = _objectWithoutPropertiesLoose(rawValue, _excluded$a);
|
|
4537
4537
|
return ctx.success(rest);
|
|
4538
4538
|
}
|
|
4539
4539
|
|
|
@@ -4611,7 +4611,7 @@ function throwErrorIfCheatingDetected() {
|
|
|
4611
4611
|
|
|
4612
4612
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
4613
4613
|
const libName = "@khanacademy/perseus-core";
|
|
4614
|
-
const libVersion = "3.
|
|
4614
|
+
const libVersion = "3.5.0";
|
|
4615
4615
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
4616
4616
|
|
|
4617
4617
|
/**
|
|
@@ -4710,7 +4710,7 @@ const mapObject = function mapObject(obj, lambda) {
|
|
|
4710
4710
|
return result;
|
|
4711
4711
|
};
|
|
4712
4712
|
|
|
4713
|
-
const defaultWidgetOptions$
|
|
4713
|
+
const defaultWidgetOptions$v = {
|
|
4714
4714
|
items: [],
|
|
4715
4715
|
categories: [],
|
|
4716
4716
|
values: [],
|
|
@@ -4718,11 +4718,11 @@ const defaultWidgetOptions$u = {
|
|
|
4718
4718
|
};
|
|
4719
4719
|
const categorizerWidgetLogic = {
|
|
4720
4720
|
name: "categorizer",
|
|
4721
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4721
|
+
defaultWidgetOptions: defaultWidgetOptions$v
|
|
4722
4722
|
};
|
|
4723
4723
|
|
|
4724
4724
|
const DEFAULT_HEIGHT = 400;
|
|
4725
|
-
const defaultWidgetOptions$
|
|
4725
|
+
const defaultWidgetOptions$u = {
|
|
4726
4726
|
programID: "",
|
|
4727
4727
|
programType: null,
|
|
4728
4728
|
settings: [{
|
|
@@ -4735,19 +4735,21 @@ const defaultWidgetOptions$t = {
|
|
|
4735
4735
|
};
|
|
4736
4736
|
const csProgramWidgetLogic = {
|
|
4737
4737
|
name: "cs-program",
|
|
4738
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4738
|
+
defaultWidgetOptions: defaultWidgetOptions$u,
|
|
4739
|
+
supportedAlignments: ["block", "full-width"]
|
|
4739
4740
|
};
|
|
4740
4741
|
|
|
4741
|
-
const defaultWidgetOptions$
|
|
4742
|
+
const defaultWidgetOptions$t = {
|
|
4742
4743
|
togglePrompt: "",
|
|
4743
4744
|
definition: ""
|
|
4744
4745
|
};
|
|
4745
4746
|
const definitionWidgetLogic = {
|
|
4746
4747
|
name: "definition",
|
|
4747
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4748
|
+
defaultWidgetOptions: defaultWidgetOptions$t,
|
|
4749
|
+
defaultAlignment: "inline"
|
|
4748
4750
|
};
|
|
4749
4751
|
|
|
4750
|
-
const defaultWidgetOptions$
|
|
4752
|
+
const defaultWidgetOptions$s = {
|
|
4751
4753
|
placeholder: "",
|
|
4752
4754
|
choices: [{
|
|
4753
4755
|
content: "",
|
|
@@ -4756,10 +4758,11 @@ const defaultWidgetOptions$r = {
|
|
|
4756
4758
|
};
|
|
4757
4759
|
const dropdownWidgetLogic = {
|
|
4758
4760
|
name: "definition",
|
|
4759
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4761
|
+
defaultWidgetOptions: defaultWidgetOptions$s,
|
|
4762
|
+
defaultAlignment: "inline-block"
|
|
4760
4763
|
};
|
|
4761
4764
|
|
|
4762
|
-
const defaultWidgetOptions$
|
|
4765
|
+
const defaultWidgetOptions$r = {
|
|
4763
4766
|
showPrompt: "Explain",
|
|
4764
4767
|
hidePrompt: "Hide explanation",
|
|
4765
4768
|
explanation: "explanation goes here\n\nmore explanation",
|
|
@@ -4767,7 +4770,8 @@ const defaultWidgetOptions$q = {
|
|
|
4767
4770
|
};
|
|
4768
4771
|
const explanationWidgetLogic = {
|
|
4769
4772
|
name: "explanation",
|
|
4770
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4773
|
+
defaultWidgetOptions: defaultWidgetOptions$r,
|
|
4774
|
+
defaultAlignment: "inline"
|
|
4771
4775
|
};
|
|
4772
4776
|
|
|
4773
4777
|
const currentVersion$3 = {
|
|
@@ -4790,7 +4794,7 @@ const widgetOptionsUpgrades$2 = {
|
|
|
4790
4794
|
}]
|
|
4791
4795
|
})
|
|
4792
4796
|
};
|
|
4793
|
-
const defaultWidgetOptions$
|
|
4797
|
+
const defaultWidgetOptions$q = {
|
|
4794
4798
|
answerForms: [],
|
|
4795
4799
|
times: false,
|
|
4796
4800
|
buttonSets: ["basic"],
|
|
@@ -4801,26 +4805,52 @@ const expressionWidgetLogic = {
|
|
|
4801
4805
|
name: "expression",
|
|
4802
4806
|
version: currentVersion$3,
|
|
4803
4807
|
widgetOptionsUpgrades: widgetOptionsUpgrades$2,
|
|
4804
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4808
|
+
defaultWidgetOptions: defaultWidgetOptions$q,
|
|
4809
|
+
defaultAlignment: "inline-block"
|
|
4805
4810
|
};
|
|
4806
4811
|
|
|
4807
|
-
const defaultWidgetOptions$
|
|
4812
|
+
const defaultWidgetOptions$p = {
|
|
4808
4813
|
title: "",
|
|
4809
4814
|
content: "",
|
|
4810
4815
|
widgets: {},
|
|
4811
4816
|
images: {},
|
|
4812
4817
|
hint: null
|
|
4813
4818
|
};
|
|
4814
|
-
const
|
|
4819
|
+
const gradedGroupWidgetLogic = {
|
|
4815
4820
|
name: "graded-group",
|
|
4816
|
-
defaultWidgetOptions: defaultWidgetOptions$
|
|
4821
|
+
defaultWidgetOptions: defaultWidgetOptions$p
|
|
4817
4822
|
};
|
|
4818
4823
|
|
|
4819
|
-
const defaultWidgetOptions$
|
|
4824
|
+
const defaultWidgetOptions$o = {
|
|
4820
4825
|
gradedGroups: []
|
|
4821
4826
|
};
|
|
4822
|
-
const
|
|
4827
|
+
const gradedGroupSetWidgetLogic = {
|
|
4823
4828
|
name: "graded-group-set",
|
|
4829
|
+
defaultWidgetOptions: defaultWidgetOptions$o
|
|
4830
|
+
};
|
|
4831
|
+
|
|
4832
|
+
const defaultWidgetOptions$n = {
|
|
4833
|
+
graph: {
|
|
4834
|
+
labels: ["x", "y"],
|
|
4835
|
+
range: [[-10, 10], [-10, 10]],
|
|
4836
|
+
step: [1, 1],
|
|
4837
|
+
backgroundImage: {
|
|
4838
|
+
url: null
|
|
4839
|
+
},
|
|
4840
|
+
markings: "graph",
|
|
4841
|
+
rulerLabel: "",
|
|
4842
|
+
rulerTicks: 10,
|
|
4843
|
+
valid: true,
|
|
4844
|
+
showTooltips: false
|
|
4845
|
+
},
|
|
4846
|
+
correct: {
|
|
4847
|
+
type: "linear",
|
|
4848
|
+
coords: null
|
|
4849
|
+
},
|
|
4850
|
+
availableTypes: ["linear"]
|
|
4851
|
+
};
|
|
4852
|
+
const grapherWidgetLogic = {
|
|
4853
|
+
name: "grapher",
|
|
4824
4854
|
defaultWidgetOptions: defaultWidgetOptions$n
|
|
4825
4855
|
};
|
|
4826
4856
|
|
|
@@ -4832,7 +4862,7 @@ const defaultWidgetOptions$m = {
|
|
|
4832
4862
|
// `the GroupMetadataEditor`
|
|
4833
4863
|
metadata: undefined
|
|
4834
4864
|
};
|
|
4835
|
-
const
|
|
4865
|
+
const groupWidgetLogic = {
|
|
4836
4866
|
name: "group",
|
|
4837
4867
|
defaultWidgetOptions: defaultWidgetOptions$m
|
|
4838
4868
|
};
|
|
@@ -4868,7 +4898,9 @@ const defaultWidgetOptions$k = {
|
|
|
4868
4898
|
};
|
|
4869
4899
|
const imageWidgetLogic = {
|
|
4870
4900
|
name: "image",
|
|
4871
|
-
defaultWidgetOptions: defaultWidgetOptions$k
|
|
4901
|
+
defaultWidgetOptions: defaultWidgetOptions$k,
|
|
4902
|
+
supportedAlignments: ["block", "full-width"],
|
|
4903
|
+
defaultAlignment: "block"
|
|
4872
4904
|
};
|
|
4873
4905
|
|
|
4874
4906
|
const defaultWidgetOptions$j = {
|
|
@@ -4882,7 +4914,8 @@ const defaultWidgetOptions$j = {
|
|
|
4882
4914
|
};
|
|
4883
4915
|
const inputNumberWidgetLogic = {
|
|
4884
4916
|
name: "input-number",
|
|
4885
|
-
defaultWidgetOptions: defaultWidgetOptions$j
|
|
4917
|
+
defaultWidgetOptions: defaultWidgetOptions$j,
|
|
4918
|
+
defaultAlignment: "inline-block"
|
|
4886
4919
|
};
|
|
4887
4920
|
|
|
4888
4921
|
const defaultWidgetOptions$i = {
|
|
@@ -4963,7 +4996,7 @@ const matrixWidgetLogic = {
|
|
|
4963
4996
|
defaultWidgetOptions: defaultWidgetOptions$e
|
|
4964
4997
|
};
|
|
4965
4998
|
|
|
4966
|
-
const _excluded$
|
|
4999
|
+
const _excluded$9 = ["imageUrl", "imageTop", "imageLeft"];
|
|
4967
5000
|
const currentVersion$2 = {
|
|
4968
5001
|
major: 1,
|
|
4969
5002
|
minor: 0
|
|
@@ -4975,7 +5008,7 @@ const widgetOptionsUpgrades$1 = {
|
|
|
4975
5008
|
imageTop,
|
|
4976
5009
|
imageLeft
|
|
4977
5010
|
} = v0options,
|
|
4978
|
-
rest = _objectWithoutPropertiesLoose(v0options, _excluded$
|
|
5011
|
+
rest = _objectWithoutPropertiesLoose(v0options, _excluded$9);
|
|
4979
5012
|
return _extends({}, rest, {
|
|
4980
5013
|
image: {
|
|
4981
5014
|
url: imageUrl,
|
|
@@ -5039,7 +5072,8 @@ const defaultWidgetOptions$b = {
|
|
|
5039
5072
|
};
|
|
5040
5073
|
const numericInputWidgetLogic = {
|
|
5041
5074
|
name: "numeric-input",
|
|
5042
|
-
defaultWidgetOptions: defaultWidgetOptions$b
|
|
5075
|
+
defaultWidgetOptions: defaultWidgetOptions$b,
|
|
5076
|
+
defaultAlignment: "inline-block"
|
|
5043
5077
|
};
|
|
5044
5078
|
|
|
5045
5079
|
const defaultWidgetOptions$a = {
|
|
@@ -5081,7 +5115,8 @@ const defaultWidgetOptions$8 = {
|
|
|
5081
5115
|
const passageRefWidgetLogic = {
|
|
5082
5116
|
name: "passageRef",
|
|
5083
5117
|
version: currentVersion$1,
|
|
5084
|
-
defaultWidgetOptions: defaultWidgetOptions$8
|
|
5118
|
+
defaultWidgetOptions: defaultWidgetOptions$8,
|
|
5119
|
+
defaultAlignment: "inline"
|
|
5085
5120
|
};
|
|
5086
5121
|
|
|
5087
5122
|
const defaultWidgetOptions$7 = {
|
|
@@ -5089,14 +5124,15 @@ const defaultWidgetOptions$7 = {
|
|
|
5089
5124
|
};
|
|
5090
5125
|
const passageRefTargetWidgetLogic = {
|
|
5091
5126
|
name: "passageRefTarget",
|
|
5092
|
-
defaultWidgetOptions: defaultWidgetOptions$7
|
|
5127
|
+
defaultWidgetOptions: defaultWidgetOptions$7,
|
|
5128
|
+
defaultAlignment: "inline"
|
|
5093
5129
|
};
|
|
5094
5130
|
|
|
5095
5131
|
const defaultWidgetOptions$6 = {
|
|
5096
5132
|
url: "",
|
|
5097
5133
|
description: ""
|
|
5098
5134
|
};
|
|
5099
|
-
const
|
|
5135
|
+
const phetSimulationWidgetLogic = {
|
|
5100
5136
|
name: "phet-simulation",
|
|
5101
5137
|
defaultWidgetOptions: defaultWidgetOptions$6
|
|
5102
5138
|
};
|
|
@@ -5130,7 +5166,7 @@ const pythonProgramWidgetLogic = {
|
|
|
5130
5166
|
defaultWidgetOptions: defaultWidgetOptions$4
|
|
5131
5167
|
};
|
|
5132
5168
|
|
|
5133
|
-
const _excluded = ["noneOfTheAbove"];
|
|
5169
|
+
const _excluded$8 = ["noneOfTheAbove"];
|
|
5134
5170
|
const currentVersion = {
|
|
5135
5171
|
major: 1,
|
|
5136
5172
|
minor: 0
|
|
@@ -5140,7 +5176,7 @@ const widgetOptionsUpgrades = {
|
|
|
5140
5176
|
const {
|
|
5141
5177
|
noneOfTheAbove
|
|
5142
5178
|
} = v0props,
|
|
5143
|
-
rest = _objectWithoutPropertiesLoose(v0props, _excluded);
|
|
5179
|
+
rest = _objectWithoutPropertiesLoose(v0props, _excluded$8);
|
|
5144
5180
|
if (noneOfTheAbove) {
|
|
5145
5181
|
throw new Error("radio widget v0 no longer supports auto noneOfTheAbove");
|
|
5146
5182
|
}
|
|
@@ -5198,9 +5234,237 @@ const defaultWidgetOptions = {
|
|
|
5198
5234
|
};
|
|
5199
5235
|
const videoWidgetLogic = {
|
|
5200
5236
|
name: "video",
|
|
5201
|
-
defaultWidgetOptions
|
|
5237
|
+
defaultWidgetOptions,
|
|
5238
|
+
supportedAlignments: ["block", "float-left", "float-right", "full-width"],
|
|
5239
|
+
defaultAlignment: "block"
|
|
5202
5240
|
};
|
|
5203
5241
|
|
|
5242
|
+
const widgets = {};
|
|
5243
|
+
function registerWidget(type, logic) {
|
|
5244
|
+
widgets[type] = logic;
|
|
5245
|
+
}
|
|
5246
|
+
function isWidgetRegistered(type) {
|
|
5247
|
+
const widgetLogic = widgets[type];
|
|
5248
|
+
return !!widgetLogic;
|
|
5249
|
+
}
|
|
5250
|
+
function getCurrentVersion(type) {
|
|
5251
|
+
const widgetLogic = widgets[type];
|
|
5252
|
+
return (widgetLogic == null ? void 0 : widgetLogic.version) || {
|
|
5253
|
+
major: 0,
|
|
5254
|
+
minor: 0
|
|
5255
|
+
};
|
|
5256
|
+
}
|
|
5257
|
+
function getWidgetOptionsUpgrades(type) {
|
|
5258
|
+
const widgetLogic = widgets[type];
|
|
5259
|
+
return (widgetLogic == null ? void 0 : widgetLogic.widgetOptionsUpgrades) || {};
|
|
5260
|
+
}
|
|
5261
|
+
function getDefaultWidgetOptions(type) {
|
|
5262
|
+
const widgetLogic = widgets[type];
|
|
5263
|
+
return (widgetLogic == null ? void 0 : widgetLogic.defaultWidgetOptions) || {};
|
|
5264
|
+
}
|
|
5265
|
+
|
|
5266
|
+
/**
|
|
5267
|
+
* Handling for the optional alignments for widgets
|
|
5268
|
+
* See widget-container.jsx for details on how alignments are implemented.
|
|
5269
|
+
*/
|
|
5270
|
+
|
|
5271
|
+
/**
|
|
5272
|
+
* Returns the list of supported alignments for the given (string) widget
|
|
5273
|
+
* type. This is used primarily at editing time to display the choices
|
|
5274
|
+
* for the user.
|
|
5275
|
+
*
|
|
5276
|
+
* Supported alignments are given as an array of strings in the exports of
|
|
5277
|
+
* a widget's module.
|
|
5278
|
+
*/
|
|
5279
|
+
const getSupportedAlignments = type => {
|
|
5280
|
+
var _widgetLogic$supporte;
|
|
5281
|
+
const widgetLogic = widgets[type];
|
|
5282
|
+
if (!(widgetLogic != null && (_widgetLogic$supporte = widgetLogic.supportedAlignments) != null && _widgetLogic$supporte[0])) {
|
|
5283
|
+
// default alignments
|
|
5284
|
+
return ["default"];
|
|
5285
|
+
}
|
|
5286
|
+
return widgetLogic == null ? void 0 : widgetLogic.supportedAlignments;
|
|
5287
|
+
};
|
|
5288
|
+
|
|
5289
|
+
/**
|
|
5290
|
+
* For the given (string) widget type, determine the default alignment for
|
|
5291
|
+
* the widget. This is used at rendering time to go from "default" alignment
|
|
5292
|
+
* to the actual alignment displayed on the screen.
|
|
5293
|
+
*
|
|
5294
|
+
* The default alignment is given either as a string (called
|
|
5295
|
+
* `defaultAlignment`) or a function (called `getDefaultAlignment`) on
|
|
5296
|
+
* the exports of a widget's module.
|
|
5297
|
+
*/
|
|
5298
|
+
const getDefaultAlignment = type => {
|
|
5299
|
+
const widgetLogic = widgets[type];
|
|
5300
|
+
if (!(widgetLogic != null && widgetLogic.defaultAlignment)) {
|
|
5301
|
+
return "block";
|
|
5302
|
+
}
|
|
5303
|
+
return widgetLogic.defaultAlignment;
|
|
5304
|
+
};
|
|
5305
|
+
registerWidget("categorizer", categorizerWidgetLogic);
|
|
5306
|
+
registerWidget("cs-program", csProgramWidgetLogic);
|
|
5307
|
+
registerWidget("definition", definitionWidgetLogic);
|
|
5308
|
+
registerWidget("dropdown", dropdownWidgetLogic);
|
|
5309
|
+
registerWidget("explanation", explanationWidgetLogic);
|
|
5310
|
+
registerWidget("expression", expressionWidgetLogic);
|
|
5311
|
+
registerWidget("graded-group", gradedGroupWidgetLogic);
|
|
5312
|
+
registerWidget("graded-group-set", gradedGroupSetWidgetLogic);
|
|
5313
|
+
registerWidget("grapher", grapherWidgetLogic);
|
|
5314
|
+
registerWidget("group", groupWidgetLogic);
|
|
5315
|
+
registerWidget("iframe", iframeWidgetLogic);
|
|
5316
|
+
registerWidget("image", imageWidgetLogic);
|
|
5317
|
+
registerWidget("input-number", inputNumberWidgetLogic);
|
|
5318
|
+
registerWidget("interaction", interactionWidgetLogic);
|
|
5319
|
+
registerWidget("interactive-graph", interactiveGraphWidgetLogic);
|
|
5320
|
+
registerWidget("label-image", labelImageWidgetLogic);
|
|
5321
|
+
registerWidget("matcher", matcherWidgetLogic);
|
|
5322
|
+
registerWidget("matrix", matrixWidgetLogic);
|
|
5323
|
+
registerWidget("measurer", measurerWidgetLogic);
|
|
5324
|
+
registerWidget("number-line", numberLineWidgetLogic);
|
|
5325
|
+
registerWidget("numeric-input", numericInputWidgetLogic);
|
|
5326
|
+
registerWidget("orderer", ordererWidgetLogic);
|
|
5327
|
+
registerWidget("passage", passageWidgetLogic);
|
|
5328
|
+
registerWidget("passage-ref", passageRefWidgetLogic);
|
|
5329
|
+
registerWidget("passage-ref-target", passageRefTargetWidgetLogic);
|
|
5330
|
+
registerWidget("phet-simulation", phetSimulationWidgetLogic);
|
|
5331
|
+
registerWidget("plotter", plotterWidgetLogic);
|
|
5332
|
+
registerWidget("python-program", pythonProgramWidgetLogic);
|
|
5333
|
+
registerWidget("radio", radioWidgetLogic);
|
|
5334
|
+
registerWidget("sorter", sorterWidgetLogic);
|
|
5335
|
+
registerWidget("table", tableWidgetLogic);
|
|
5336
|
+
registerWidget("video", videoWidgetLogic);
|
|
5337
|
+
|
|
5338
|
+
var coreWidgetRegistry = /*#__PURE__*/Object.freeze({
|
|
5339
|
+
__proto__: null,
|
|
5340
|
+
isWidgetRegistered: isWidgetRegistered,
|
|
5341
|
+
getCurrentVersion: getCurrentVersion,
|
|
5342
|
+
getWidgetOptionsUpgrades: getWidgetOptionsUpgrades,
|
|
5343
|
+
getDefaultWidgetOptions: getDefaultWidgetOptions,
|
|
5344
|
+
getSupportedAlignments: getSupportedAlignments,
|
|
5345
|
+
getDefaultAlignment: getDefaultAlignment
|
|
5346
|
+
});
|
|
5347
|
+
|
|
5348
|
+
const DEFAULT_STATIC = false;
|
|
5349
|
+
const upgradeWidgetInfoToLatestVersion = oldWidgetInfo => {
|
|
5350
|
+
const type = oldWidgetInfo.type;
|
|
5351
|
+
// NOTE(jeremy): This looks like it could be replaced by fixing types so
|
|
5352
|
+
// that `type` is non-optional. But we're seeing this in Sentry today so I
|
|
5353
|
+
// suspect we have legacy data (potentially unpublished) and we should
|
|
5354
|
+
// figure that out before depending solely on types.
|
|
5355
|
+
if (!_.isString(type)) {
|
|
5356
|
+
throw new PerseusError("widget type must be a string, but was: " + type, Errors.Internal);
|
|
5357
|
+
}
|
|
5358
|
+
if (!isWidgetRegistered(type)) {
|
|
5359
|
+
// If we have a widget that isn't registered, we can't upgrade it
|
|
5360
|
+
// TODO(aria): Figure out what the best thing to do here would be
|
|
5361
|
+
return oldWidgetInfo;
|
|
5362
|
+
}
|
|
5363
|
+
|
|
5364
|
+
// Unversioned widgets (pre-July 2014) are all implicitly 0.0
|
|
5365
|
+
const initialVersion = oldWidgetInfo.version || {
|
|
5366
|
+
major: 0,
|
|
5367
|
+
minor: 0
|
|
5368
|
+
};
|
|
5369
|
+
const latestVersion = getCurrentVersion(type);
|
|
5370
|
+
|
|
5371
|
+
// If the widget version is later than what we understand (major
|
|
5372
|
+
// version is higher than latest, or major versions are equal and minor
|
|
5373
|
+
// version is higher than latest), don't perform any upgrades.
|
|
5374
|
+
if (initialVersion.major > latestVersion.major || initialVersion.major === latestVersion.major && initialVersion.minor > latestVersion.minor) {
|
|
5375
|
+
return oldWidgetInfo;
|
|
5376
|
+
}
|
|
5377
|
+
|
|
5378
|
+
// We do a clone here so that it's safe to mutate the input parameter
|
|
5379
|
+
// in propUpgrades functions (which I will probably accidentally do at
|
|
5380
|
+
// some point, and we would like to not break when that happens).
|
|
5381
|
+
let newEditorOptions = _.clone(oldWidgetInfo.options) || {};
|
|
5382
|
+
const upgradePropsMap = getWidgetOptionsUpgrades(type);
|
|
5383
|
+
|
|
5384
|
+
// Empty props usually mean a newly created widget by the editor,
|
|
5385
|
+
// and are always considerered up-to-date.
|
|
5386
|
+
// Mostly, we'd rather not run upgrade functions on props that are
|
|
5387
|
+
// not complete.
|
|
5388
|
+
if (_.keys(newEditorOptions).length !== 0) {
|
|
5389
|
+
// We loop through all the versions after the current version of
|
|
5390
|
+
// the loaded widget, up to and including the latest version of the
|
|
5391
|
+
// loaded widget, and run the upgrade function to bring our loaded
|
|
5392
|
+
// widget's props up to that version.
|
|
5393
|
+
// There is a little subtlety here in that we call
|
|
5394
|
+
// upgradePropsMap[1] to upgrade *to* version 1,
|
|
5395
|
+
// (not from version 1).
|
|
5396
|
+
for (let nextVersion = initialVersion.major + 1; nextVersion <= latestVersion.major; nextVersion++) {
|
|
5397
|
+
if (upgradePropsMap[String(nextVersion)]) {
|
|
5398
|
+
newEditorOptions = upgradePropsMap[String(nextVersion)](newEditorOptions);
|
|
5399
|
+
} else {
|
|
5400
|
+
throw new PerseusError("No upgrade found for widget. Cannot render.", Errors.Internal, {
|
|
5401
|
+
metadata: {
|
|
5402
|
+
type,
|
|
5403
|
+
fromMajorVersion: nextVersion - 1,
|
|
5404
|
+
toMajorVersion: nextVersion,
|
|
5405
|
+
oldWidgetInfo: JSON.stringify(oldWidgetInfo)
|
|
5406
|
+
}
|
|
5407
|
+
});
|
|
5408
|
+
}
|
|
5409
|
+
}
|
|
5410
|
+
}
|
|
5411
|
+
|
|
5412
|
+
// Minor version upgrades (eg. new optional props) don't have
|
|
5413
|
+
// transform functions. Instead, we fill in the new props with their
|
|
5414
|
+
// defaults.
|
|
5415
|
+
const defaultOptions = getDefaultWidgetOptions(type);
|
|
5416
|
+
newEditorOptions = _extends({}, defaultOptions, newEditorOptions);
|
|
5417
|
+
let alignment = oldWidgetInfo.alignment;
|
|
5418
|
+
|
|
5419
|
+
// Widgets that support multiple alignments will "lock in" the
|
|
5420
|
+
// alignment to the alignment that would be listed first in the
|
|
5421
|
+
// select box. If the widget only supports one alignment, the
|
|
5422
|
+
// alignment value will likely just end up as "default".
|
|
5423
|
+
if (alignment == null || alignment === "default") {
|
|
5424
|
+
var _getSupportedAlignmen;
|
|
5425
|
+
alignment = (_getSupportedAlignmen = getSupportedAlignments(type)) == null ? void 0 : _getSupportedAlignmen[0];
|
|
5426
|
+
if (!alignment) {
|
|
5427
|
+
throw new PerseusError("No default alignment found when upgrading widget", Errors.Internal, {
|
|
5428
|
+
metadata: {
|
|
5429
|
+
widgetType: type
|
|
5430
|
+
}
|
|
5431
|
+
});
|
|
5432
|
+
}
|
|
5433
|
+
}
|
|
5434
|
+
let widgetStatic = oldWidgetInfo.static;
|
|
5435
|
+
if (widgetStatic == null) {
|
|
5436
|
+
widgetStatic = DEFAULT_STATIC;
|
|
5437
|
+
}
|
|
5438
|
+
return _extends({}, oldWidgetInfo, {
|
|
5439
|
+
// maintain other info, like type
|
|
5440
|
+
// After upgrading we guarantee that the version is up-to-date
|
|
5441
|
+
version: latestVersion,
|
|
5442
|
+
// Default graded to true (so null/undefined becomes true):
|
|
5443
|
+
graded: oldWidgetInfo.graded != null ? oldWidgetInfo.graded : true,
|
|
5444
|
+
alignment: alignment,
|
|
5445
|
+
static: widgetStatic,
|
|
5446
|
+
options: newEditorOptions
|
|
5447
|
+
});
|
|
5448
|
+
};
|
|
5449
|
+
function getUpgradedWidgetOptions(oldWidgetOptions) {
|
|
5450
|
+
return mapObject(oldWidgetOptions, (widgetInfo, widgetId) => {
|
|
5451
|
+
if (!widgetInfo.type || !widgetInfo.alignment) {
|
|
5452
|
+
const newValues = {};
|
|
5453
|
+
if (!widgetInfo.type) {
|
|
5454
|
+
// TODO: why does widget have no type?
|
|
5455
|
+
// We don't want to derive type from widget ID
|
|
5456
|
+
// see: LEMS-1845
|
|
5457
|
+
newValues.type = widgetId.split(" ")[0];
|
|
5458
|
+
}
|
|
5459
|
+
if (!widgetInfo.alignment) {
|
|
5460
|
+
newValues.alignment = "default";
|
|
5461
|
+
}
|
|
5462
|
+
widgetInfo = _extends({}, widgetInfo, newValues);
|
|
5463
|
+
}
|
|
5464
|
+
return upgradeWidgetInfoToLatestVersion(widgetInfo);
|
|
5465
|
+
});
|
|
5466
|
+
}
|
|
5467
|
+
|
|
5204
5468
|
/**
|
|
5205
5469
|
* For details on the individual options, see the
|
|
5206
5470
|
* PerseusOrdererWidgetOptions type
|
|
@@ -5236,6 +5500,10 @@ function getCategorizerPublicWidgetOptions(options) {
|
|
|
5236
5500
|
};
|
|
5237
5501
|
}
|
|
5238
5502
|
|
|
5503
|
+
function getCSProgramPublicWidgetOptions(options) {
|
|
5504
|
+
return options;
|
|
5505
|
+
}
|
|
5506
|
+
|
|
5239
5507
|
/**
|
|
5240
5508
|
* For details on the individual options, see the
|
|
5241
5509
|
* PerseusExpressionWidgetOptions type
|
|
@@ -5256,5 +5524,162 @@ function getExpressionPublicWidgetOptions(options) {
|
|
|
5256
5524
|
};
|
|
5257
5525
|
}
|
|
5258
5526
|
|
|
5259
|
-
|
|
5527
|
+
const _excluded$7 = ["correct"];
|
|
5528
|
+
function getGrapherPublicWidgetOptions(options) {
|
|
5529
|
+
const publicOptions = _objectWithoutPropertiesLoose(options, _excluded$7);
|
|
5530
|
+
return publicOptions;
|
|
5531
|
+
}
|
|
5532
|
+
|
|
5533
|
+
const _excluded$6 = ["correct"];
|
|
5534
|
+
function getInteractiveGraphPublicWidgetOptions(options) {
|
|
5535
|
+
const publicOptions = _objectWithoutPropertiesLoose(options, _excluded$6);
|
|
5536
|
+
return publicOptions;
|
|
5537
|
+
}
|
|
5538
|
+
|
|
5539
|
+
const _excluded$5 = ["answers"];
|
|
5540
|
+
/**
|
|
5541
|
+
* For details on the individual options, see the
|
|
5542
|
+
* PerseusLabelImageWidgetOptions type
|
|
5543
|
+
*/
|
|
5544
|
+
|
|
5545
|
+
function getLabelImagePublicWidgetOptions(options) {
|
|
5546
|
+
return _extends({}, options, {
|
|
5547
|
+
markers: options.markers.map(getLabelImageMarkerPublicData)
|
|
5548
|
+
});
|
|
5549
|
+
}
|
|
5550
|
+
function getLabelImageMarkerPublicData(marker) {
|
|
5551
|
+
const publicData = _objectWithoutPropertiesLoose(marker, _excluded$5);
|
|
5552
|
+
return publicData;
|
|
5553
|
+
}
|
|
5554
|
+
|
|
5555
|
+
/**
|
|
5556
|
+
* For details on the individual options, see the
|
|
5557
|
+
* PerseusSorterWidgetOptions type
|
|
5558
|
+
*/
|
|
5559
|
+
|
|
5560
|
+
/**
|
|
5561
|
+
* Given a PerseusSorterWidgetOptions object, return a new object with only
|
|
5562
|
+
* the public options that should be exposed to the client.
|
|
5563
|
+
*/
|
|
5564
|
+
function getSorterPublicWidgetOptions(options) {
|
|
5565
|
+
return {
|
|
5566
|
+
// Note(Tamara): This does not provide correct answer information any longer.
|
|
5567
|
+
// To maintain compatibility with the original widget options, we are
|
|
5568
|
+
// keeping the key the same. Represents initial state of the cards here.
|
|
5569
|
+
correct: options.correct.slice().sort(),
|
|
5570
|
+
padding: options.padding,
|
|
5571
|
+
layout: options.layout
|
|
5572
|
+
};
|
|
5573
|
+
}
|
|
5574
|
+
|
|
5575
|
+
/**
|
|
5576
|
+
* For details on the individual options, see the
|
|
5577
|
+
* PerseusDropdownWidgetOptions type
|
|
5578
|
+
*/
|
|
5579
|
+
|
|
5580
|
+
/**
|
|
5581
|
+
* Given a PerseusDropdownWidgetOptions object, return a new object with only
|
|
5582
|
+
* the public options that should be exposed to the client.
|
|
5583
|
+
*/
|
|
5584
|
+
function getDropdownPublicWidgetOptions(options) {
|
|
5585
|
+
return {
|
|
5586
|
+
choices: options.choices.map(choice => ({
|
|
5587
|
+
content: choice.content
|
|
5588
|
+
})),
|
|
5589
|
+
placeholder: options.placeholder,
|
|
5590
|
+
static: options.static,
|
|
5591
|
+
visibleLabel: options.visibleLabel,
|
|
5592
|
+
ariaLabel: options.ariaLabel
|
|
5593
|
+
};
|
|
5594
|
+
}
|
|
5595
|
+
|
|
5596
|
+
const _excluded$4 = ["answers"];
|
|
5597
|
+
/**
|
|
5598
|
+
* For details on the individual options, see the
|
|
5599
|
+
* PerseusNumericInputWidgetOptions type
|
|
5600
|
+
*/
|
|
5601
|
+
|
|
5602
|
+
/**
|
|
5603
|
+
* Given a PerseusNumericInputWidgetOptions object, return a new object with only
|
|
5604
|
+
* the public options that should be exposed to the client.
|
|
5605
|
+
*/
|
|
5606
|
+
function getNumericInputPublicWidgetOptions(options) {
|
|
5607
|
+
const publicWidgetOptions = _objectWithoutPropertiesLoose(options, _excluded$4);
|
|
5608
|
+
return publicWidgetOptions;
|
|
5609
|
+
}
|
|
5610
|
+
|
|
5611
|
+
const _excluded$3 = ["correctX", "correctRel"];
|
|
5612
|
+
function getNumberLinePublicWidgetOptions(options) {
|
|
5613
|
+
const publicOptions = _objectWithoutPropertiesLoose(options, _excluded$3);
|
|
5614
|
+
return publicOptions;
|
|
5615
|
+
}
|
|
5616
|
+
|
|
5617
|
+
/**
|
|
5618
|
+
* For details on the individual options, see the
|
|
5619
|
+
* PerseusRadioWidgetOptions type
|
|
5620
|
+
*/
|
|
5621
|
+
|
|
5622
|
+
/**
|
|
5623
|
+
* Only the options from each Radio choice that should be exposed to the client.
|
|
5624
|
+
*/
|
|
5625
|
+
|
|
5626
|
+
/**
|
|
5627
|
+
* Given a PerseusRadioChoice object, return a new object with only the public
|
|
5628
|
+
* data that should be included in the Radio public widget options.
|
|
5629
|
+
*/
|
|
5630
|
+
function getRadioChoicePublicData(choice) {
|
|
5631
|
+
const {
|
|
5632
|
+
content,
|
|
5633
|
+
isNoneOfTheAbove,
|
|
5634
|
+
widgets
|
|
5635
|
+
} = choice;
|
|
5636
|
+
return {
|
|
5637
|
+
content,
|
|
5638
|
+
isNoneOfTheAbove,
|
|
5639
|
+
widgets
|
|
5640
|
+
};
|
|
5641
|
+
}
|
|
5642
|
+
|
|
5643
|
+
/**
|
|
5644
|
+
* Given a PerseusRadioWidgetOptions object, return a new object with only
|
|
5645
|
+
* the public options that should be exposed to the client.
|
|
5646
|
+
*/
|
|
5647
|
+
function getRadioPublicWidgetOptions(options) {
|
|
5648
|
+
return _extends({}, options, {
|
|
5649
|
+
choices: options.choices.map(getRadioChoicePublicData)
|
|
5650
|
+
});
|
|
5651
|
+
}
|
|
5652
|
+
|
|
5653
|
+
const _excluded$2 = ["answers"];
|
|
5654
|
+
function getTablePublicWidgetOptions(options) {
|
|
5655
|
+
const publicOptions = _objectWithoutPropertiesLoose(options, _excluded$2);
|
|
5656
|
+
return publicOptions;
|
|
5657
|
+
}
|
|
5658
|
+
|
|
5659
|
+
function getIFramePublicWidgetOptions(options) {
|
|
5660
|
+
return options;
|
|
5661
|
+
}
|
|
5662
|
+
|
|
5663
|
+
const _excluded$1 = ["answers"];
|
|
5664
|
+
function getMatrixPublicWidgetOptions(options) {
|
|
5665
|
+
const publicOptions = _objectWithoutPropertiesLoose(options, _excluded$1);
|
|
5666
|
+
return publicOptions;
|
|
5667
|
+
}
|
|
5668
|
+
|
|
5669
|
+
const _excluded = ["correct"];
|
|
5670
|
+
/**
|
|
5671
|
+
* For details on the individual options, see the
|
|
5672
|
+
* PerseusPlotterWidgetOptions type
|
|
5673
|
+
*/
|
|
5674
|
+
|
|
5675
|
+
/**
|
|
5676
|
+
* Given a PerseusPlotterWidgetOptions object, return a new object with only
|
|
5677
|
+
* the public options that should be exposed to the client.
|
|
5678
|
+
*/
|
|
5679
|
+
function getPlotterPublicWidgetOptions(options) {
|
|
5680
|
+
const publicOptions = _objectWithoutPropertiesLoose(options, _excluded);
|
|
5681
|
+
return publicOptions;
|
|
5682
|
+
}
|
|
5683
|
+
|
|
5684
|
+
export { coreWidgetRegistry as CoreWidgetRegistry, Errors, grapherUtil as GrapherUtil, ItemExtras, PerseusError, PerseusExpressionAnswerFormConsidered, addLibraryVersionToPerseusDebug, addWidget, approximateDeepEqual, approximateEqual, categorizerWidgetLogic as categorizerLogic, csProgramWidgetLogic as csProgramLogic, deepClone, definitionWidgetLogic as definitionLogic, dropdownWidgetLogic as dropdownLogic, explanationWidgetLogic as explanationLogic, expressionWidgetLogic as expressionLogic, getCSProgramPublicWidgetOptions, getCategorizerPublicWidgetOptions, getDecimalSeparator, getDropdownPublicWidgetOptions, getExpressionPublicWidgetOptions, getGrapherPublicWidgetOptions, getIFramePublicWidgetOptions, getInteractiveGraphPublicWidgetOptions, getLabelImagePublicWidgetOptions, getMatrixPublicWidgetOptions, getMatrixSize, getNumberLinePublicWidgetOptions, getNumericInputPublicWidgetOptions, getOrdererPublicWidgetOptions, getPlotterPublicWidgetOptions, getRadioPublicWidgetOptions, getSorterPublicWidgetOptions, getTablePublicWidgetOptions, getUpgradedWidgetOptions, getWidgetIdsFromContent, getWidgetIdsFromContentByType, gradedGroupWidgetLogic as gradedGroupLogic, gradedGroupSetWidgetLogic as gradedGroupSetLogic, grapherWidgetLogic as grapherLogic, groupWidgetLogic as groupLogic, iframeWidgetLogic as iframeLogic, imageWidgetLogic as imageLogic, inputNumberWidgetLogic as inputNumberLogic, interactionWidgetLogic as interactionLogic, interactiveGraphWidgetLogic as interactiveGraphLogic, isFailure, isSuccess, labelImageWidgetLogic as labelImageLogic, libVersion, lockedFigureColorNames, lockedFigureColors, lockedFigureFillStyles, mapObject, matcherWidgetLogic as matcherLogic, matrixWidgetLogic as matrixLogic, measurerWidgetLogic as measurerLogic, numberLineWidgetLogic as numberLineLogic, numericInputWidgetLogic as numericInputLogic, ordererWidgetLogic as ordererLogic, parseAndMigratePerseusArticle, parseAndMigratePerseusItem, parsePerseusItem, passageWidgetLogic as passageLogic, passageRefWidgetLogic as passageRefLogic, passageRefTargetWidgetLogic as passageRefTargetLogic, phetSimulationWidgetLogic as phetSimulationLogic, plotterWidgetLogic as plotterLogic, plotterPlotTypes, pluck, pythonProgramWidgetLogic as pythonProgramLogic, radioWidgetLogic as radioLogic, sorterWidgetLogic as sorterLogic, tableWidgetLogic as tableLogic, upgradeWidgetInfoToLatestVersion, videoWidgetLogic as videoLogic };
|
|
5260
5685
|
//# sourceMappingURL=index.js.map
|