@khanacademy/perseus-core 12.1.0 → 13.0.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 +38 -41
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +40 -42
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/perseus-parsers/cs-program-user-input.d.ts +4 -0
- package/dist/parse-perseus-json/perseus-parsers/cs-program-user-input.typetest.d.ts +1 -0
- package/dist/parse-perseus-json/perseus-parsers/free-response-user-input.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/free-response-user-input.typetest.d.ts +1 -0
- package/dist/parse-perseus-json/perseus-parsers/grapher-user-input.d.ts +24 -0
- package/dist/parse-perseus-json/perseus-parsers/grapher-user-input.typetest.d.ts +1 -0
- package/dist/parse-perseus-json/perseus-parsers/iframe-user-input.d.ts +4 -0
- package/dist/parse-perseus-json/perseus-parsers/iframe-user-input.typetest.d.ts +1 -0
- package/dist/utils/get-default-answer-area.d.ts +2 -0
- package/dist/widgets/apply-defaults.d.ts +3 -0
- package/dist/widgets/core-widget-registry.d.ts +0 -1
- package/dist/widgets/expression/index.d.ts +7 -1
- package/dist/widgets/logic-export.types.d.ts +0 -1
- package/dist/widgets/measurer/index.d.ts +7 -1
- package/dist/widgets/radio/derive-num-correct.d.ts +2 -0
- package/dist/widgets/radio/index.d.ts +7 -1
- package/package.json +4 -4
- package/dist/widgets/expression/expression-upgrade.d.ts +0 -11
- package/dist/widgets/measurer/measurer-upgrade.d.ts +0 -10
- package/dist/widgets/radio/radio-upgrade.d.ts +0 -12
- package/dist/widgets/upgrade.d.ts +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -89,7 +89,8 @@ export { default as tableLogic } from "./widgets/table";
|
|
|
89
89
|
export type { TableDefaultWidgetOptions } from "./widgets/table";
|
|
90
90
|
export { default as videoLogic } from "./widgets/video";
|
|
91
91
|
export type { VideoDefaultWidgetOptions } from "./widgets/video";
|
|
92
|
-
export {
|
|
92
|
+
export { applyDefaultsToWidgets, applyDefaultsToWidget, } from "./widgets/apply-defaults";
|
|
93
|
+
export { default as getDefaultAnswerArea } from "./utils/get-default-answer-area";
|
|
93
94
|
export { default as splitPerseusItem, splitPerseusItemJSON, } from "./utils/split-perseus-item";
|
|
94
95
|
export { default as Registry } from "./utils/registry";
|
|
95
96
|
export type * from "./widgets/logic-export.types";
|
|
@@ -115,7 +116,7 @@ export { default as getNumericInputPublicWidgetOptions } from "./widgets/numeric
|
|
|
115
116
|
export { default as getNumberLinePublicWidgetOptions } from "./widgets/number-line/number-line-util";
|
|
116
117
|
export type { NumberLinePublicWidgetOptions } from "./widgets/number-line/number-line-util";
|
|
117
118
|
export { default as getRadioPublicWidgetOptions } from "./widgets/radio/radio-util";
|
|
118
|
-
export { deriveNumCorrect } from "./widgets/radio/
|
|
119
|
+
export { deriveNumCorrect } from "./widgets/radio/derive-num-correct";
|
|
119
120
|
export { default as getTablePublicWidgetOptions } from "./widgets/table/table-util";
|
|
120
121
|
export { default as getIFramePublicWidgetOptions } from "./widgets/iframe/iframe-util";
|
|
121
122
|
export { default as getMatrixPublicWidgetOptions } from "./widgets/matrix/matrix-util";
|
package/dist/index.js
CHANGED
|
@@ -183,7 +183,7 @@ const parsePlotterWidget=parseWidget(constant("plotter"),object({labels:array(st
|
|
|
183
183
|
|
|
184
184
|
const parsePythonProgramWidget=parseWidget(constant("python-program"),object({programID:string,height:number}));
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
function deriveNumCorrect(options){const{choices,numCorrect}=options;return numCorrect??choices.filter(c=>c.correct).length}
|
|
187
187
|
|
|
188
188
|
const parseWidgetsMapOrUndefined=defaulted(optional((rawVal,ctx)=>parseWidgetsMap(rawVal,ctx)),()=>undefined);function getDefaultOptions(){return {choices:[{content:""},{content:""},{content:""},{content:""}]}}const version2=optional(object({major:constant(2),minor:number}));const parseRadioWidgetV2=parseWidgetWithVersion(version2,constant("radio"),defaulted(object({numCorrect:optional(number),choices:array(object({content:defaulted(string,()=>""),clue:optional(string),correct:optional(boolean),isNoneOfTheAbove:optional(boolean),widgets:parseWidgetsMapOrUndefined})),hasNoneOfTheAbove:optional(boolean),countChoices:optional(boolean),randomize:optional(boolean),multipleSelect:optional(boolean),deselectEnabled:optional(boolean),onePerLine:optional(boolean),displayCount:optional(any),noneOfTheAbove:optional(constant(false))}),getDefaultOptions));const version1=optional(object({major:constant(1),minor:number}));const parseRadioWidgetV1=parseWidgetWithVersion(version1,constant("radio"),defaulted(object({choices:array(object({content:defaulted(string,()=>""),clue:optional(string),correct:optional(boolean),isNoneOfTheAbove:optional(boolean),widgets:parseWidgetsMapOrUndefined})),hasNoneOfTheAbove:optional(boolean),countChoices:optional(boolean),randomize:optional(boolean),multipleSelect:optional(boolean),deselectEnabled:optional(boolean),onePerLine:optional(boolean),displayCount:optional(any),noneOfTheAbove:optional(constant(false))}),getDefaultOptions));function migrateV1ToV2(widget){const{options}=widget;return {...widget,version:{major:2,minor:0},options:{...options,numCorrect:deriveNumCorrect(options)}}}const version0=optional(object({major:constant(0),minor:number}));const parseRadioWidgetV0=parseWidgetWithVersion(version0,constant("radio"),defaulted(object({choices:array(object({content:defaulted(string,()=>""),clue:optional(string),correct:optional(boolean),isNoneOfTheAbove:optional(boolean),widgets:parseWidgetsMapOrUndefined})),hasNoneOfTheAbove:optional(boolean),countChoices:optional(boolean),randomize:optional(boolean),multipleSelect:optional(boolean),deselectEnabled:optional(boolean),onePerLine:optional(boolean),displayCount:optional(any),noneOfTheAbove:optional(constant(false))}),getDefaultOptions));function migrateV0ToV1(widget){const{options}=widget;const{noneOfTheAbove:_,...rest}=options;return {...widget,version:{major:1,minor:0},options:{...rest,hasNoneOfTheAbove:false,noneOfTheAbove:undefined}}}const parseRadioWidget=versionedWidgetOptions(2,parseRadioWidgetV2).withMigrationFrom(1,parseRadioWidgetV1,migrateV1ToV2).withMigrationFrom(0,parseRadioWidgetV0,migrateV0ToV1).parser;
|
|
189
189
|
|
|
@@ -207,7 +207,7 @@ const parsePerseusItem$1=object({question:parsePerseusRenderer,hints:defaulted(a
|
|
|
207
207
|
|
|
208
208
|
function parsePerseusItem(json){if(isRealJSONParse(JSON.parse)){return JSON.parse(json)}throw new Error("Something went wrong.")}function parseAndMigratePerseusItem(data){throwErrorIfCheatingDetected();const object=typeof data==="string"?JSON.parse(data):data;const result=parse(object,parsePerseusItem$1);if(isFailure(result)){return failure({message:result.detail,invalidObject:object})}return result}function parseAndMigratePerseusArticle(data){throwErrorIfCheatingDetected();const object=typeof data==="string"?JSON.parse(data):data;const result=parse(object,parsePerseusArticle);if(isFailure(result)){return failure({message:result.detail,invalidObject:object})}return result}function throwErrorIfCheatingDetected(){if(!isRealJSONParse(JSON.parse)){throw new Error("Something went wrong.")}}
|
|
209
209
|
|
|
210
|
-
const libName="@khanacademy/perseus-core";const libVersion="
|
|
210
|
+
const libName="@khanacademy/perseus-core";const libVersion="13.0.0";perseusUtils.addLibraryVersionToPerseusDebug(libName,libVersion);
|
|
211
211
|
|
|
212
212
|
const Errors=Object.freeze({Unknown:"Unknown",Internal:"Internal",InvalidInput:"InvalidInput",NotAllowed:"NotAllowed",TransientService:"TransientService",Service:"Service"});
|
|
213
213
|
|
|
@@ -217,105 +217,101 @@ const pluck=function(table,subKey){return ___default.default.object(___default.d
|
|
|
217
217
|
|
|
218
218
|
function getCategorizerPublicWidgetOptions(options){return {items:options.items,categories:options.categories,randomizeItems:options.randomizeItems,static:options.static}}
|
|
219
219
|
|
|
220
|
-
const defaultWidgetOptions$
|
|
220
|
+
const defaultWidgetOptions$w={items:[],categories:[],values:[],randomizeItems:false};const categorizerWidgetLogic={name:"categorizer",defaultWidgetOptions: defaultWidgetOptions$w,getPublicWidgetOptions:getCategorizerPublicWidgetOptions};
|
|
221
221
|
|
|
222
222
|
function getCSProgramPublicWidgetOptions(options){return options}
|
|
223
223
|
|
|
224
|
-
const DEFAULT_HEIGHT=400;const defaultWidgetOptions$
|
|
224
|
+
const DEFAULT_HEIGHT=400;const defaultWidgetOptions$v={programID:"",programType:null,settings:[{name:"",value:""}],showEditor:false,showButtons:false,height:DEFAULT_HEIGHT};const csProgramWidgetLogic={name:"cs-program",defaultWidgetOptions: defaultWidgetOptions$v,supportedAlignments:["block","full-width"],getPublicWidgetOptions:getCSProgramPublicWidgetOptions};
|
|
225
225
|
|
|
226
|
-
const defaultWidgetOptions$
|
|
226
|
+
const defaultWidgetOptions$u={togglePrompt:"",definition:""};const definitionWidgetLogic={name:"definition",defaultWidgetOptions: defaultWidgetOptions$u,defaultAlignment:"inline"};
|
|
227
227
|
|
|
228
228
|
function getDropdownPublicWidgetOptions(options){return {choices:options.choices.map(choice=>({content:choice.content})),placeholder:options.placeholder,static:options.static,visibleLabel:options.visibleLabel,ariaLabel:options.ariaLabel}}
|
|
229
229
|
|
|
230
|
-
const defaultWidgetOptions$
|
|
230
|
+
const defaultWidgetOptions$t={placeholder:"",choices:[{content:"",correct:false}]};const dropdownWidgetLogic={name:"dropdown",defaultWidgetOptions: defaultWidgetOptions$t,defaultAlignment:"inline-block",getPublicWidgetOptions:getDropdownPublicWidgetOptions};
|
|
231
231
|
|
|
232
|
-
const defaultWidgetOptions$
|
|
233
|
-
|
|
234
|
-
const currentVersion$2={major:2,minor:0};const widgetOptionsUpgrades$1={"2":v1options=>{return {times:v1options.times,buttonSets:v1options.buttonSets,functions:v1options.functions,buttonsVisible:v1options.buttonsVisible,visibleLabel:v1options.visibleLabel,ariaLabel:v1options.ariaLabel,answerForms:v1options.answerForms,extraKeys:v1options.extraKeys||deriveExtraKeys(v1options)}},"1":v0options=>{return {times:v0options.times,buttonSets:v0options.buttonSets,functions:v0options.functions,buttonsVisible:v0options.buttonsVisible,visibleLabel:v0options.visibleLabel,ariaLabel:v0options.ariaLabel,extraKeys:v0options.extraKeys,answerForms:[{considered:"correct",form:v0options.form,simplify:v0options.simplify,value:v0options.value}]}}};const defaultWidgetOptions$q={answerForms:[],times:false,buttonSets:["basic"],functions:["f","g","h"]};
|
|
232
|
+
const defaultWidgetOptions$s={showPrompt:"Explain",hidePrompt:"Hide explanation",explanation:"explanation goes here\n\nmore explanation",widgets:{}};const explanationWidgetLogic={name:"explanation",defaultWidgetOptions: defaultWidgetOptions$s,defaultAlignment:"inline"};
|
|
235
233
|
|
|
236
234
|
function getExpressionPublicWidgetOptions(options){return {buttonSets:options.buttonSets,functions:options.functions,times:options.times,visibleLabel:options.visibleLabel,ariaLabel:options.ariaLabel,buttonsVisible:options.buttonsVisible,extraKeys:options.extraKeys}}
|
|
237
235
|
|
|
238
|
-
const expressionWidgetLogic={name:"expression",version:currentVersion$
|
|
236
|
+
const currentVersion$3={major:2,minor:0};const defaultWidgetOptions$r={answerForms:[],times:false,buttonSets:["basic"],functions:["f","g","h"]};const expressionWidgetLogic={name:"expression",version:currentVersion$3,defaultWidgetOptions:defaultWidgetOptions$r,defaultAlignment:"inline-block",getPublicWidgetOptions:getExpressionPublicWidgetOptions};
|
|
239
237
|
|
|
240
|
-
const defaultWidgetOptions$
|
|
238
|
+
const defaultWidgetOptions$q={title:"",content:"",widgets:{},images:{},hint:null};const gradedGroupWidgetLogic={name:"graded-group",defaultWidgetOptions: defaultWidgetOptions$q};
|
|
241
239
|
|
|
242
240
|
function getFreeResponsePublicWidgetOptions(options){return {allowUnlimitedCharacters:options.allowUnlimitedCharacters,characterLimit:options.characterLimit,placeholder:options.placeholder,question:options.question}}
|
|
243
241
|
|
|
244
|
-
const defaultWidgetOptions$
|
|
242
|
+
const defaultWidgetOptions$p={allowUnlimitedCharacters:false,characterLimit:500,placeholder:"Please provide response here",question:"",scoringCriteria:[{text:""}]};const freeResponseWidgetLogic={name:"free-response",defaultWidgetOptions: defaultWidgetOptions$p,getPublicWidgetOptions:getFreeResponsePublicWidgetOptions};
|
|
245
243
|
|
|
246
|
-
const defaultWidgetOptions$
|
|
244
|
+
const defaultWidgetOptions$o={gradedGroups:[]};const gradedGroupSetWidgetLogic={name:"graded-group-set",defaultWidgetOptions: defaultWidgetOptions$o};
|
|
247
245
|
|
|
248
246
|
function getGrapherPublicWidgetOptions(options){const{correct:_,...publicOptions}=options;return publicOptions}
|
|
249
247
|
|
|
250
|
-
const defaultWidgetOptions$
|
|
248
|
+
const defaultWidgetOptions$n={graph:{labels:["x","y"],range:[[-10,10],[-10,10]],step:[1,1],backgroundImage:{url:null},markings:"graph",rulerLabel:"",rulerTicks:10,valid:true,showTooltips:false},correct:{type:"linear",coords:null},availableTypes:["linear"]};const grapherWidgetLogic={name:"grapher",defaultWidgetOptions: defaultWidgetOptions$n,getPublicWidgetOptions:getGrapherPublicWidgetOptions};
|
|
251
249
|
|
|
252
250
|
class Registry{throwIfUnregistered(){if(!this.anythingRegistered){throw new Error(`${this.name} accessed before initialization!`)}}has(key){this.throwIfUnregistered();return Object.prototype.hasOwnProperty.call(this.contents,key)}get(key){this.throwIfUnregistered();return this.contents[key]}keys(){this.throwIfUnregistered();return Object.keys(this.contents)}entries(){this.throwIfUnregistered();return Object.entries(this.contents)}set(key,value){this.anythingRegistered=true;this.contents[key]=value;}constructor(name="Registry"){this.contents={};this.anythingRegistered=false;this.name=name;}}
|
|
253
251
|
|
|
254
252
|
function getIFramePublicWidgetOptions(options){return options}
|
|
255
253
|
|
|
256
|
-
const defaultWidgetOptions$
|
|
254
|
+
const defaultWidgetOptions$m={url:"",settings:[{name:"",value:""}],width:"400",height:"400",allowFullScreen:false,allowTopNavigation:false};const iframeWidgetLogic={name:"iframe",defaultWidgetOptions: defaultWidgetOptions$m,getPublicWidgetOptions:getIFramePublicWidgetOptions};
|
|
257
255
|
|
|
258
|
-
const defaultWidgetOptions$
|
|
256
|
+
const defaultWidgetOptions$l={title:"",range:[[0,10],[0,10]],box:[400,400],backgroundImage:{url:null,width:0,height:0},labels:[],alt:"",caption:""};const imageWidgetLogic={name:"image",defaultWidgetOptions: defaultWidgetOptions$l,supportedAlignments:["block","full-width"],defaultAlignment:"block"};
|
|
259
257
|
|
|
260
258
|
function getInputNumberPublicWidgetOptions(options){const{value:_,...publicWidgetOptions}=options;return publicWidgetOptions}
|
|
261
259
|
|
|
262
|
-
const defaultWidgetOptions$
|
|
260
|
+
const defaultWidgetOptions$k={value:0,simplify:"required",size:"normal",inexact:false,maxError:.1,answerType:"number",rightAlign:false};const inputNumberWidgetLogic={name:"input-number",defaultWidgetOptions: defaultWidgetOptions$k,defaultAlignment:"inline-block",getPublicWidgetOptions:getInputNumberPublicWidgetOptions};
|
|
263
261
|
|
|
264
|
-
const defaultWidgetOptions$
|
|
262
|
+
const defaultWidgetOptions$j={graph:{box:[400,400],labels:["x","y"],range:[[-10,10],[-10,10]],tickStep:[1,1],gridStep:[1,1],markings:"graph"},elements:[]};const interactionWidgetLogic={name:"interaction",defaultWidgetOptions: defaultWidgetOptions$j};
|
|
265
263
|
|
|
266
264
|
function getInteractiveGraphPublicWidgetOptions(options){const{correct:_,...publicOptions}=options;return publicOptions}
|
|
267
265
|
|
|
268
|
-
const defaultWidgetOptions$
|
|
266
|
+
const defaultWidgetOptions$i={labels:["x","y"],labelLocation:"onAxis",range:[[-10,10],[-10,10]],step:[1,1],backgroundImage:{url:null},markings:"graph",showTooltips:false,showProtractor:false,graph:{type:"linear"},correct:{type:"linear",coords:null}};const interactiveGraphWidgetLogic={name:"interactive-graph",defaultWidgetOptions: defaultWidgetOptions$i,getPublicWidgetOptions:getInteractiveGraphPublicWidgetOptions};
|
|
269
267
|
|
|
270
268
|
function getLabelImagePublicWidgetOptions(options){return {...options,markers:options.markers.map(getLabelImageMarkerPublicData)}}function getLabelImageMarkerPublicData(marker){const{answers:_,...publicData}=marker;return publicData}
|
|
271
269
|
|
|
272
|
-
const defaultWidgetOptions$
|
|
270
|
+
const defaultWidgetOptions$h={choices:[],imageAlt:"",imageUrl:"",imageWidth:0,imageHeight:0,markers:[],multipleAnswers:false,hideChoicesFromInstructions:false};const labelImageWidgetLogic={name:"label-image",defaultWidgetOptions: defaultWidgetOptions$h,getPublicWidgetOptions:getLabelImagePublicWidgetOptions};
|
|
273
271
|
|
|
274
272
|
const seededRNG=function(seed){let randomSeed=seed;return function(){let seed=randomSeed;seed=seed+0x7ed55d16+(seed<<12)&0xffffffff;seed=(seed^0xc761c23c^seed>>>19)&0xffffffff;seed=seed+0x165667b1+(seed<<5)&0xffffffff;seed=(seed+0xd3a2646c^seed<<9)&0xffffffff;seed=seed+0xfd7046c5+(seed<<3)&0xffffffff;seed=(seed^0xb55a4f09^seed>>>16)&0xffffffff;return (randomSeed=seed&0xfffffff)/0x10000000}};function shuffle(array,randomSeed,ensurePermuted=false){let random;if(typeof randomSeed==="function"){random=randomSeed;}else {random=seededRNG(randomSeed);}function isValidShuffle(shuffled){return ensurePermuted?!___default.default.isEqual(array,shuffled):true}return constrainedShuffle(array,random,isValidShuffle)}function constrainedShuffle(array,random,isValidShuffle){const maxIterations=100;const shuffled=[...array];if(shuffled.every(value=>___default.default.isEqual(value,shuffled[0]))){return shuffled}for(let i=0;i<maxIterations;i++){shuffleInPlace(shuffled,random);if(isValidShuffle(shuffled)){return shuffled}}throw new Error(`constrainedShuffle: constraint not met after ${maxIterations} attempts`)}function shuffleInPlace(a,random){for(let i=a.length-1;i>0;i--){const k=randomIntInRange(0,i,random);[a[k],a[i]]=[a[i],a[k]];}}function randomIntInRange(min,max,random){return Math.floor(random()*(max-min+1))+min}const random=seededRNG(new Date().getTime()&0xffffffff);
|
|
275
273
|
|
|
276
274
|
const shuffleMatcher=props=>{const rng=seededRNG(props.problemNum);return {left:!props.orderMatters?props.left:shuffleDisplacingFirst$1(props.left,rng),right:shuffleDisplacingFirst$1(props.right,rng)}};function getMatcherPublicWidgetOptions(options){return {...options,left:options.orderMatters?sortAllButFirst$1(options.left):options.left,right:sortAllButFirst$1(options.right)}}function sortAllButFirst$1([first,...rest]){return [first,...rest.sort()]}function shuffleDisplacingFirst$1(array,rng){function isFirstElementDisplaced(shuffled){return shuffled[0]!==array[0]}return constrainedShuffle(array,rng,isFirstElementDisplaced)}
|
|
277
275
|
|
|
278
|
-
const defaultWidgetOptions$
|
|
276
|
+
const defaultWidgetOptions$g={left:["$x$","$y$","$z$"],right:["$1$","$2$","$3$"],labels:["test","label"],orderMatters:false,padding:true};const matcherWidgetLogic={name:"matcher",defaultWidgetOptions: defaultWidgetOptions$g,getPublicWidgetOptions:getMatcherPublicWidgetOptions};
|
|
279
277
|
|
|
280
278
|
function getMatrixPublicWidgetOptions(options){const{answers:_,...publicOptions}=options;return publicOptions}
|
|
281
279
|
|
|
282
|
-
const defaultWidgetOptions$
|
|
283
|
-
|
|
284
|
-
const currentVersion$1={major:1,minor:0};const widgetOptionsUpgrades={"1":v0options=>{const{imageUrl,imageTop,imageLeft,...rest}=v0options;return {...rest,image:{url:imageUrl,top:imageTop,left:imageLeft}}}};const defaultWidgetOptions$d={box:[480,480],image:{},showProtractor:true,showRuler:false,rulerLabel:"",rulerTicks:10,rulerPixels:40,rulerLength:10};
|
|
280
|
+
const defaultWidgetOptions$f={matrixBoardSize:[3,3],answers:[[]],prefix:"",suffix:"",cursorPosition:[0,0]};const matrixWidgetLogic={name:"matrix",defaultWidgetOptions: defaultWidgetOptions$f,getPublicWidgetOptions:getMatrixPublicWidgetOptions};
|
|
285
281
|
|
|
286
|
-
const measurerWidgetLogic={name:"measurer",version:currentVersion$
|
|
282
|
+
const currentVersion$2={major:1,minor:0};const defaultWidgetOptions$e={box:[480,480],image:{},showProtractor:true,showRuler:false,rulerLabel:"",rulerTicks:10,rulerPixels:40,rulerLength:10};const measurerWidgetLogic={name:"measurer",version:currentVersion$2,defaultWidgetOptions:defaultWidgetOptions$e};
|
|
287
283
|
|
|
288
284
|
function getNumberLinePublicWidgetOptions(options){const{correctX:_,correctRel:__,...publicOptions}=options;return publicOptions}
|
|
289
285
|
|
|
290
|
-
const defaultWidgetOptions$
|
|
286
|
+
const defaultWidgetOptions$d={range:[0,10],labelRange:[null,null],labelStyle:"decimal",labelTicks:true,divisionRange:[1,12],numDivisions:5,snapDivisions:2,tickStep:null,correctRel:"eq",correctX:null,initialX:null,showTooltips:false};const numberLineWidgetLogic={name:"number-line",defaultWidgetOptions: defaultWidgetOptions$d,getPublicWidgetOptions:getNumberLinePublicWidgetOptions};
|
|
291
287
|
|
|
292
288
|
function getNumericInputAnswerPublicData(answer){const{answerForms,simplify,status}=answer;return {answerForms,simplify,status}}function getNumericInputPublicWidgetOptions(options){const{answers,...publicWidgetOptions}=options;return {...publicWidgetOptions,answers:answers.map(getNumericInputAnswerPublicData)}}
|
|
293
289
|
|
|
294
|
-
const defaultWidgetOptions$
|
|
290
|
+
const defaultWidgetOptions$c={answers:[{value:null,status:"correct",message:"",simplify:"required",answerForms:[],strict:false,maxError:null}],size:"normal",coefficient:false,labelText:"",rightAlign:false};const numericInputWidgetLogic={name:"numeric-input",defaultWidgetOptions: defaultWidgetOptions$c,defaultAlignment:"inline-block",getPublicWidgetOptions:getNumericInputPublicWidgetOptions};
|
|
295
291
|
|
|
296
292
|
function getOrdererPublicWidgetOptions(fullOptions){const{options,height,layout}=fullOptions;return {options,height,layout}}
|
|
297
293
|
|
|
298
|
-
const defaultWidgetOptions$
|
|
294
|
+
const defaultWidgetOptions$b={correctOptions:[{content:"$x$"}],otherOptions:[{content:"$y$"}],height:"normal",layout:"horizontal"};const ordererWidgetLogic={name:"orderer",defaultWidgetOptions: defaultWidgetOptions$b,getPublicWidgetOptions:getOrdererPublicWidgetOptions};
|
|
299
295
|
|
|
300
|
-
const defaultWidgetOptions$
|
|
296
|
+
const defaultWidgetOptions$a={passageTitle:"",passageText:"",footnotes:"",showLineNumbers:true};const passageWidgetLogic={name:"passage",defaultWidgetOptions: defaultWidgetOptions$a};
|
|
301
297
|
|
|
302
|
-
const currentVersion={major:0,minor:1};const defaultWidgetOptions$
|
|
298
|
+
const currentVersion$1={major:0,minor:1};const defaultWidgetOptions$9={passageNumber:1,referenceNumber:1,summaryText:""};
|
|
303
299
|
|
|
304
|
-
const passageRefWidgetLogic={name:"passage-ref",version:currentVersion,defaultWidgetOptions:defaultWidgetOptions$
|
|
300
|
+
const passageRefWidgetLogic={name:"passage-ref",version:currentVersion$1,defaultWidgetOptions:defaultWidgetOptions$9,defaultAlignment:"inline"};
|
|
305
301
|
|
|
306
|
-
const defaultWidgetOptions$
|
|
302
|
+
const defaultWidgetOptions$8={content:""};const passageRefTargetWidgetLogic={name:"passage-ref-target",defaultWidgetOptions: defaultWidgetOptions$8,defaultAlignment:"inline"};
|
|
307
303
|
|
|
308
|
-
const defaultWidgetOptions$
|
|
304
|
+
const defaultWidgetOptions$7={url:"",description:""};const phetSimulationWidgetLogic={name:"phet-simulation",defaultWidgetOptions: defaultWidgetOptions$7};
|
|
309
305
|
|
|
310
306
|
function getPlotterPublicWidgetOptions(options){const{correct:_,...publicOptions}=options;return publicOptions}
|
|
311
307
|
|
|
312
|
-
const defaultWidgetOptions$
|
|
308
|
+
const defaultWidgetOptions$6={scaleY:1,maxY:10,snapsPerLine:2,correct:[1],starting:[1],type:"bar",labels:["",""],categories:[""],picSize:30,picBoxHeight:36,plotDimensions:[275,200],labelInterval:1,picUrl:null};const plotterWidgetLogic={name:"plotter",defaultWidgetOptions: defaultWidgetOptions$6,getPublicWidgetOptions:getPlotterPublicWidgetOptions};
|
|
313
309
|
|
|
314
|
-
const defaultWidgetOptions$
|
|
310
|
+
const defaultWidgetOptions$5={programID:"",height:400};const pythonProgramWidgetLogic={name:"python-program",defaultWidgetOptions: defaultWidgetOptions$5};
|
|
315
311
|
|
|
316
312
|
function getRadioChoicePublicData(choice){const{content,isNoneOfTheAbove,widgets}=choice;return {content,isNoneOfTheAbove,widgets}}function usesNumCorrect(multipleSelect,countChoices,numCorrect){return multipleSelect&&countChoices&&numCorrect}function getRadioPublicWidgetOptions(options){const{numCorrect,choices,multipleSelect,countChoices}=options;return {...options,numCorrect:usesNumCorrect(multipleSelect,countChoices,numCorrect)?numCorrect:undefined,choices:choices.map(getRadioChoicePublicData)}}
|
|
317
313
|
|
|
318
|
-
const radioWidgetLogic={name:"radio",version:currentVersion
|
|
314
|
+
const currentVersion={major:2,minor:0};const defaultWidgetOptions$4={choices:[{},{},{},{}],displayCount:null,randomize:false,hasNoneOfTheAbove:false,multipleSelect:false,countChoices:false,deselectEnabled:false};const radioWidgetLogic={name:"radio",version:currentVersion,defaultWidgetOptions:defaultWidgetOptions$4,getPublicWidgetOptions:getRadioPublicWidgetOptions};
|
|
319
315
|
|
|
320
316
|
function getSorterPublicWidgetOptions(options){return {...options,correct:sortAllButFirst(options.correct)}}function shuffleSorter(props){const{correct,problemNum}=props;const rng=seededRNG(problemNum??0);return shuffleDisplacingFirst(correct,rng)}function sortAllButFirst([first,...rest]){return [first,...rest.sort()]}function shuffleDisplacingFirst(array,rng){function isFirstElementDisplaced(shuffled){return shuffled[0]!==array[0]}return constrainedShuffle(array,rng,isFirstElementDisplaced)}
|
|
321
317
|
|
|
@@ -327,7 +323,7 @@ const defaultRows=4;const defaultColumns=1;const answers=new Array(defaultRows).
|
|
|
327
323
|
|
|
328
324
|
const defaultWidgetOptions$1={location:""};const videoWidgetLogic={name:"video",defaultWidgetOptions: defaultWidgetOptions$1,supportedAlignments:["block","float-left","float-right","full-width"],defaultAlignment:"block"};
|
|
329
325
|
|
|
330
|
-
const widgets=new Registry("Core widget registry");function registerWidget(type,logic){widgets.set(type,logic);}function isWidgetRegistered(type){const widgetLogic=widgets.get(type);return !!widgetLogic}function getCurrentVersion(type){const widgetLogic=widgets.get(type);return widgetLogic?.version||{major:0,minor:0}}const getPublicWidgetOptionsFunction=type=>{return widgets.get(type)?.getPublicWidgetOptions??(i=>i)};function
|
|
326
|
+
const widgets=new Registry("Core widget registry");function registerWidget(type,logic){widgets.set(type,logic);}function isWidgetRegistered(type){const widgetLogic=widgets.get(type);return !!widgetLogic}function getCurrentVersion(type){const widgetLogic=widgets.get(type);return widgetLogic?.version||{major:0,minor:0}}const getPublicWidgetOptionsFunction=type=>{return widgets.get(type)?.getPublicWidgetOptions??(i=>i)};function getDefaultWidgetOptions(type){const widgetLogic=widgets.get(type);return widgetLogic?.defaultWidgetOptions||{}}const getSupportedAlignments=type=>{const widgetLogic=widgets.get(type);if(!widgetLogic?.supportedAlignments?.[0]){return ["default"]}return widgetLogic?.supportedAlignments};const getDefaultAlignment=type=>{const widgetLogic=widgets.get(type);if(!widgetLogic?.defaultAlignment){return "block"}return widgetLogic.defaultAlignment};function registerCoreWidgets(){const widgets=[categorizerWidgetLogic,csProgramWidgetLogic,definitionWidgetLogic,dropdownWidgetLogic,explanationWidgetLogic,expressionWidgetLogic,gradedGroupWidgetLogic,gradedGroupSetWidgetLogic,grapherWidgetLogic,groupWidgetLogic,iframeWidgetLogic,imageWidgetLogic,inputNumberWidgetLogic,interactionWidgetLogic,interactiveGraphWidgetLogic,labelImageWidgetLogic,matcherWidgetLogic,matrixWidgetLogic,measurerWidgetLogic,numberLineWidgetLogic,numericInputWidgetLogic,ordererWidgetLogic,passageWidgetLogic,passageRefWidgetLogic,passageRefTargetWidgetLogic,phetSimulationWidgetLogic,plotterWidgetLogic,pythonProgramWidgetLogic,radioWidgetLogic,sorterWidgetLogic,tableWidgetLogic,videoWidgetLogic];widgets.forEach(w=>{registerWidget(w.name,w);});}
|
|
331
327
|
|
|
332
328
|
var coreWidgetRegistry = /*#__PURE__*/Object.freeze({
|
|
333
329
|
__proto__: null,
|
|
@@ -336,19 +332,20 @@ var coreWidgetRegistry = /*#__PURE__*/Object.freeze({
|
|
|
336
332
|
getDefaultWidgetOptions: getDefaultWidgetOptions,
|
|
337
333
|
getPublicWidgetOptionsFunction: getPublicWidgetOptionsFunction,
|
|
338
334
|
getSupportedAlignments: getSupportedAlignments,
|
|
339
|
-
getWidgetOptionsUpgrades: getWidgetOptionsUpgrades,
|
|
340
335
|
isWidgetRegistered: isWidgetRegistered,
|
|
341
336
|
registerCoreWidgets: registerCoreWidgets
|
|
342
337
|
});
|
|
343
338
|
|
|
344
|
-
const DEFAULT_STATIC=false;const
|
|
339
|
+
const DEFAULT_STATIC=false;const applyDefaultsToWidget=oldWidgetInfo=>{const type=oldWidgetInfo.type;if(!___default.default.isString(type)){throw new PerseusError("widget type must be a string, but was: "+type,Errors.Internal)}if(!isWidgetRegistered(type)){return oldWidgetInfo}const initialVersion=oldWidgetInfo.version||{major:0,minor:0};const latestVersion=getCurrentVersion(type);if(initialVersion.major>latestVersion.major||initialVersion.major===latestVersion.major&&initialVersion.minor>latestVersion.minor){return oldWidgetInfo}let newEditorOptions=___default.default.clone(oldWidgetInfo.options)??{};const defaultOptions=getDefaultWidgetOptions(type);newEditorOptions={...defaultOptions,...newEditorOptions};let alignment=oldWidgetInfo.alignment;if(alignment==null||alignment==="default"){alignment=getSupportedAlignments(type)?.[0];if(!alignment){throw new PerseusError("No default alignment found when upgrading widget",Errors.Internal,{metadata:{widgetType:type}})}}let widgetStatic=oldWidgetInfo.static;if(widgetStatic==null){widgetStatic=DEFAULT_STATIC;}return {...oldWidgetInfo,version:latestVersion,graded:oldWidgetInfo.graded!=null?oldWidgetInfo.graded:true,alignment:alignment,static:widgetStatic,options:newEditorOptions}};function applyDefaultsToWidgets(oldWidgetOptions){return mapObject(oldWidgetOptions,(widgetInfo,widgetId)=>{if(!widgetInfo.type||!widgetInfo.alignment){const newValues={};if(!widgetInfo.type){newValues.type=widgetId.split(" ")[0];}if(!widgetInfo.alignment){newValues.alignment="default";}widgetInfo={...widgetInfo,...newValues};}return applyDefaultsToWidget(widgetInfo)})}
|
|
345
340
|
|
|
346
|
-
function splitPerseusRenderer(original){const clone=deepClone(original);const originalWidgets=clone.widgets??{};const upgradedWidgets=
|
|
341
|
+
function splitPerseusRenderer(original){const clone=deepClone(original);const originalWidgets=clone.widgets??{};const upgradedWidgets=applyDefaultsToWidgets(originalWidgets);const splitWidgets={};for(const[id,widget]of Object.entries(upgradedWidgets)){const publicWidgetOptionsFun=getPublicWidgetOptionsFunction(widget.type);splitWidgets[id]={...widget,options:publicWidgetOptionsFun(widget.options)};}return {...original,widgets:splitWidgets}}
|
|
347
342
|
|
|
348
343
|
function getGroupPublicWidgetOptions(options){return splitPerseusRenderer(options)}
|
|
349
344
|
|
|
350
345
|
const defaultWidgetOptions={content:"",widgets:{},images:{}};const groupWidgetLogic={name:"group",defaultWidgetOptions,getPublicWidgetOptions:getGroupPublicWidgetOptions};
|
|
351
346
|
|
|
347
|
+
function getDefaultAnswerArea(){return ItemExtras.reduce((acc,curr)=>({...acc,[curr]:false}),{})}
|
|
348
|
+
|
|
352
349
|
function splitPerseusItem(original){const item=deepClone(original);return {...item,question:splitPerseusRenderer(item.question),hints:[]}}function splitPerseusItemJSON(data){const parseResult=parseAndMigratePerseusItem(data);if(isFailure(parseResult)){throw new SyntaxError(parseResult.detail.message)}const item=parseResult.value;return JSON.stringify(splitPerseusItem(item))}
|
|
353
350
|
|
|
354
351
|
const PerseusFeatureFlags=["new-radio-widget"];
|
|
@@ -362,6 +359,8 @@ exports.PerseusExpressionAnswerFormConsidered = PerseusExpressionAnswerFormConsi
|
|
|
362
359
|
exports.PerseusFeatureFlags = PerseusFeatureFlags;
|
|
363
360
|
exports.Registry = Registry;
|
|
364
361
|
exports.addWidget = addWidget;
|
|
362
|
+
exports.applyDefaultsToWidget = applyDefaultsToWidget;
|
|
363
|
+
exports.applyDefaultsToWidgets = applyDefaultsToWidgets;
|
|
365
364
|
exports.approximateDeepEqual = approximateDeepEqual;
|
|
366
365
|
exports.approximateEqual = approximateEqual;
|
|
367
366
|
exports.categorizerLogic = categorizerWidgetLogic;
|
|
@@ -379,6 +378,7 @@ exports.generateTestPerseusRenderer = generateTestPerseusRenderer;
|
|
|
379
378
|
exports.getCSProgramPublicWidgetOptions = getCSProgramPublicWidgetOptions;
|
|
380
379
|
exports.getCategorizerPublicWidgetOptions = getCategorizerPublicWidgetOptions;
|
|
381
380
|
exports.getDecimalSeparator = getDecimalSeparator;
|
|
381
|
+
exports.getDefaultAnswerArea = getDefaultAnswerArea;
|
|
382
382
|
exports.getDropdownPublicWidgetOptions = getDropdownPublicWidgetOptions;
|
|
383
383
|
exports.getExpressionPublicWidgetOptions = getExpressionPublicWidgetOptions;
|
|
384
384
|
exports.getFreeResponsePublicWidgetOptions = getFreeResponsePublicWidgetOptions;
|
|
@@ -397,7 +397,6 @@ exports.getPlotterPublicWidgetOptions = getPlotterPublicWidgetOptions;
|
|
|
397
397
|
exports.getRadioPublicWidgetOptions = getRadioPublicWidgetOptions;
|
|
398
398
|
exports.getSorterPublicWidgetOptions = getSorterPublicWidgetOptions;
|
|
399
399
|
exports.getTablePublicWidgetOptions = getTablePublicWidgetOptions;
|
|
400
|
-
exports.getUpgradedWidgetOptions = getUpgradedWidgetOptions;
|
|
401
400
|
exports.getWidgetIdsFromContent = getWidgetIdsFromContent;
|
|
402
401
|
exports.getWidgetIdsFromContentByType = getWidgetIdsFromContentByType;
|
|
403
402
|
exports.gradedGroupLogic = gradedGroupWidgetLogic;
|
|
@@ -447,7 +446,6 @@ exports.sorterLogic = sorterWidgetLogic;
|
|
|
447
446
|
exports.splitPerseusItem = splitPerseusItem;
|
|
448
447
|
exports.splitPerseusItemJSON = splitPerseusItemJSON;
|
|
449
448
|
exports.tableLogic = tableWidgetLogic;
|
|
450
|
-
exports.upgradeWidgetInfoToLatestVersion = upgradeWidgetInfoToLatestVersion;
|
|
451
449
|
exports.usesNumCorrect = usesNumCorrect;
|
|
452
450
|
exports.videoLogic = videoWidgetLogic;
|
|
453
451
|
//# sourceMappingURL=index.js.map
|