@khanacademy/perseus-core 14.1.0 → 15.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/index.d.ts CHANGED
@@ -127,7 +127,6 @@ export { default as getMatcherPublicWidgetOptions, shuffleMatcher, } from "./wid
127
127
  export type { MatcherPublicWidgetOptions } from "./widgets/matcher/matcher-util";
128
128
  export { shuffle, seededRNG, random } from "./utils/random-util";
129
129
  export { default as PerseusFeatureFlags } from "./feature-flags";
130
- export { registerCoreWidgets } from "./widgets/core-widget-registry";
131
130
  export { traverse } from "./traversal";
132
131
  export { isItemAccessible, violatingWidgets } from "./accessibility";
133
132
  export { isLabeledSVG, getRealImageUrl, getBaseUrl, getSvgUrl, getDataUrl, getImageSizeModern, } from "./utils/util.graphie";
package/dist/index.js CHANGED
@@ -209,7 +209,7 @@ const parsePerseusItem$1=object({question:parsePerseusRenderer,hints:defaulted(a
209
209
 
210
210
  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.")}}
211
211
 
212
- const libName="@khanacademy/perseus-core";const libVersion="14.1.0";perseusUtils.addLibraryVersionToPerseusDebug(libName,libVersion);
212
+ const libName="@khanacademy/perseus-core";const libVersion="15.0.0";perseusUtils.addLibraryVersionToPerseusDebug(libName,libVersion);
213
213
 
214
214
  const Errors=Object.freeze({Unknown:"Unknown",Internal:"Internal",InvalidInput:"InvalidInput",NotAllowed:"NotAllowed",TransientService:"TransientService",Service:"Service"});
215
215
 
@@ -345,7 +345,7 @@ var coreWidgetRegistry = /*#__PURE__*/Object.freeze({
345
345
 
346
346
  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)})}
347
347
 
348
- 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}}
348
+ 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)){if(widget.static){splitWidgets[id]=widget;}else {const publicWidgetOptionsFun=getPublicWidgetOptionsFunction(widget.type);splitWidgets[id]={...widget,options:publicWidgetOptionsFun(widget.options)};}}return {...original,widgets:splitWidgets}}
349
349
 
350
350
  function getGroupPublicWidgetOptions(options){return splitPerseusRenderer(options)}
351
351
 
@@ -361,6 +361,8 @@ const noop=function(){};const deepCallbackFor=function(contentCallback,widgetCal
361
361
 
362
362
  function violatingWidgets(itemData){const widgetTypes=[];traverse(itemData.question,null,function(info){if(info.type&&!isAccessible(info.type,info.options)){widgetTypes.push(info.type);}});return [...new Set(widgetTypes)]}function isItemAccessible(itemData){return violatingWidgets(itemData).length===0}
363
363
 
364
+ registerCoreWidgets();
365
+
364
366
  exports.CoreWidgetRegistry = coreWidgetRegistry;
365
367
  exports.Errors = Errors;
366
368
  exports.GrapherUtil = grapherUtil;
@@ -455,7 +457,6 @@ exports.pluck = pluck;
455
457
  exports.pythonProgramLogic = pythonProgramWidgetLogic;
456
458
  exports.radioLogic = radioWidgetLogic;
457
459
  exports.random = random;
458
- exports.registerCoreWidgets = registerCoreWidgets;
459
460
  exports.seededRNG = seededRNG;
460
461
  exports.shuffle = shuffle;
461
462
  exports.shuffleMatcher = shuffleMatcher;