@khanacademy/perseus-core
Advanced tools
Comparing version 0.0.0-PR2015-20250118020016 to 0.0.0-PR2015-20250127191930
@@ -37,2 +37,45 @@ /** | ||
/** | ||
* A utility type that constructs a widget map from a "registry interface". | ||
* The keys of the registry should be the widget type (aka, "categorizer" or | ||
* "radio", etc) and the value should be the option type stored in the value | ||
* of the map. | ||
* | ||
* You can think of this as a type that generates another type. We use | ||
* "registry interfaces" as a way to keep a set of widget types to their data | ||
* type in several places in Perseus. This type then allows us to generate a | ||
* map type that maps a widget id to its data type and keep strong typing by | ||
* widget id. | ||
* | ||
* For example, given a fictitious registry such as this: | ||
* | ||
* ``` | ||
* interface DummyRegistry { | ||
* categorizer: { categories: ReadonlyArray<string> }; | ||
* dropdown: { choices: ReadonlyArray<string> }: | ||
* } | ||
* ``` | ||
* | ||
* If we create a DummyMap using this helper: | ||
* | ||
* ``` | ||
* type DummyMap = MakeWidgetMap<DummyRegistry>; | ||
* ``` | ||
* | ||
* We'll get a map that looks like this: | ||
* | ||
* ``` | ||
* type DummyMap = { | ||
* `categorizer ${number}`: { categories: ReadonlyArray<string> }; | ||
* `dropdown ${number}`: { choices: ReadonlyArray<string> }; | ||
* } | ||
* ``` | ||
* | ||
* We use interfaces for the registries so that they can be extended in cases | ||
* where the consuming app brings along their own widgets. Interfaces in | ||
* TypeScript are always open (ie. you can extend them) whereas types aren't. | ||
*/ | ||
export type MakeWidgetMap<TRegistry> = { | ||
[Property in keyof TRegistry as `${Property & string} ${number}`]: TRegistry[Property]; | ||
}; | ||
/** | ||
* Our core set of Perseus widgets. | ||
@@ -58,3 +101,3 @@ * | ||
* ```typescript | ||
* declare module "@khanacademy/perseus" { | ||
* declare module "@khanacademy/perseus-core" { | ||
* interface PerseusWidgetTypes { | ||
@@ -101,3 +144,2 @@ * // A new widget | ||
measurer: MeasurerWidget; | ||
"mock-widget": MockWidget; | ||
"molecule-renderer": MoleculeRendererWidget; | ||
@@ -134,6 +176,15 @@ "number-line": NumberLineWidget; | ||
*/ | ||
export type PerseusWidgetsMap = { | ||
[Property in keyof PerseusWidgetTypes as `${Property} ${number}`]: PerseusWidgetTypes[Property]; | ||
}; | ||
export type PerseusWidgetsMap = MakeWidgetMap<PerseusWidgetTypes>; | ||
/** | ||
* PerseusWidget is a union of all the different types of widget options that | ||
* Perseus knows about. | ||
* | ||
* Thanks to it being based on PerseusWidgetTypes interface, this union is | ||
* automatically extended to include widgets used in tests without those widget | ||
* option types seeping into our production types. | ||
* | ||
* @see MockWidget for an example | ||
*/ | ||
export type PerseusWidget = PerseusWidgetTypes[keyof PerseusWidgetTypes]; | ||
/** | ||
* A "PerseusItem" is a classic Perseus item. It is rendered by the | ||
@@ -235,3 +286,2 @@ * `ServerItemRenderer` and the layout is pre-set. | ||
export type MeasurerWidget = WidgetOptions<'measurer', PerseusMeasurerWidgetOptions>; | ||
export type MockWidget = WidgetOptions<'mock-widget', MockWidgetOptions>; | ||
export type NumberLineWidget = WidgetOptions<'number-line', PerseusNumberLineWidgetOptions>; | ||
@@ -253,3 +303,2 @@ export type NumericInputWidget = WidgetOptions<'numeric-input', PerseusNumericInputWidgetOptions>; | ||
export type DeprecatedStandinWidget = WidgetOptions<'deprecated-standin', object>; | ||
export type PerseusWidget = CategorizerWidget | CSProgramWidget | DefinitionWidget | DropdownWidget | ExplanationWidget | ExpressionWidget | GradedGroupSetWidget | GradedGroupWidget | GrapherWidget | GroupWidget | IFrameWidget | ImageWidget | InputNumberWidget | InteractionWidget | InteractiveGraphWidget | LabelImageWidget | MatcherWidget | MatrixWidget | MeasurerWidget | MockWidget | MoleculeRendererWidget | NumberLineWidget | NumericInputWidget | OrdererWidget | PassageRefWidget | PassageWidget | PhetSimulationWidget | PlotterWidget | PythonProgramWidget | RadioWidget | RefTargetWidget | SorterWidget | TableWidget | VideoWidget | DeprecatedStandinWidget; | ||
/** | ||
@@ -732,3 +781,3 @@ * A background image applied to various widgets. | ||
initialX: number | null | undefined; | ||
showTooltip?: boolean; | ||
showTooltips?: boolean; | ||
static: boolean; | ||
@@ -965,6 +1014,2 @@ }; | ||
}; | ||
export type MockWidgetOptions = { | ||
static?: boolean; | ||
value: string; | ||
}; | ||
export type PerseusInputNumberWidgetOptions = { | ||
@@ -971,0 +1016,0 @@ answerType?: "number" | "decimal" | "integer" | "rational" | "improper" | "mixed" | "percent" | "pi"; |
@@ -10,2 +10,3 @@ export type { PerseusAnalyticsEvent, AnalyticsEventHandlerFn } from "./analytics"; | ||
export { approximateEqual, approximateDeepEqual } from "./utils/equality"; | ||
export { getWidgetIdsFromContent, getWidgetIdsFromContentByType, } from "./utils/widget-id-utils"; | ||
export { default as deepClone } from "./utils/deep-clone"; | ||
@@ -18,1 +19,67 @@ export * as GrapherUtil from "./utils/grapher-util"; | ||
export { pluck, mapObject } from "./utils/objective_"; | ||
export { default as categorizerLogic } from "./widgets/categorizer"; | ||
export type { CategorizerDefaultWidgetOptions } from "./widgets/categorizer"; | ||
export { default as csProgramLogic } from "./widgets/cs-program"; | ||
export type { CSProgramDefaultWidgetOptions } from "./widgets/cs-program"; | ||
export { default as definitionLogic } from "./widgets/definition"; | ||
export type { DefinitionDefaultWidgetOptions } from "./widgets/definition"; | ||
export { default as dropdownLogic } from "./widgets/dropdown"; | ||
export type { DropdownDefaultWidgetOptions } from "./widgets/dropdown"; | ||
export { default as explanationLogic } from "./widgets/explanation"; | ||
export type { ExplanationDefaultWidgetOptions } from "./widgets/explanation"; | ||
export { default as expressionLogic } from "./widgets/expression"; | ||
export type { ExpressionDefaultWidgetOptions } from "./widgets/expression"; | ||
export { default as gradedGroupLogic } from "./widgets/graded-group"; | ||
export type { GradedGroupDefaultWidgetOptions } from "./widgets/graded-group"; | ||
export { default as gradedGroupSetLogic } from "./widgets/graded-group-set"; | ||
export type { GradedGroupSetDefaultWidgetOptions } from "./widgets/graded-group-set"; | ||
export { default as groupLogic } from "./widgets/group"; | ||
export type { GroupDefaultWidgetOptions } from "./widgets/group"; | ||
export { default as iframeLogic } from "./widgets/iframe"; | ||
export type { IFrameDefaultWidgetOptions } from "./widgets/iframe"; | ||
export { default as imageLogic } from "./widgets/image"; | ||
export type { ImageDefaultWidgetOptions } from "./widgets/image"; | ||
export { default as inputNumberLogic } from "./widgets/input-number"; | ||
export type { InputNumberDefaultWidgetOptions } from "./widgets/input-number"; | ||
export { default as interactionLogic } from "./widgets/interaction"; | ||
export type { InteractionDefaultWidgetOptions } from "./widgets/interaction"; | ||
export { default as interactiveGraphLogic } from "./widgets/interactive-graph"; | ||
export type { InteractiveGraphDefaultWidgetOptions } from "./widgets/interactive-graph"; | ||
export { default as labelImageLogic } from "./widgets/label-image"; | ||
export type { LabelImageDefaultWidgetOptions } from "./widgets/label-image"; | ||
export { default as matcherLogic } from "./widgets/matcher"; | ||
export type { MatcherDefaultWidgetOptions } from "./widgets/matcher"; | ||
export { default as matrixLogic } from "./widgets/matrix"; | ||
export type { MatrixDefaultWidgetOptions } from "./widgets/matrix"; | ||
export { default as measurerLogic } from "./widgets/measurer"; | ||
export type { MeasurerDefaultWidgetOptions } from "./widgets/measurer"; | ||
export { default as numberLineLogic } from "./widgets/number-line"; | ||
export type { NumberLineDefaultWidgetOptions } from "./widgets/number-line"; | ||
export { default as numericInputLogic } from "./widgets/numeric-input"; | ||
export type { NumericInputDefaultWidgetOptions } from "./widgets/numeric-input"; | ||
export { default as ordererLogic } from "./widgets/orderer"; | ||
export type { OrdererDefaultWidgetOptions } from "./widgets/orderer"; | ||
export { default as passageLogic } from "./widgets/passage"; | ||
export type { PassageDefaultWidgetOptions } from "./widgets/passage"; | ||
export { default as passageRefLogic } from "./widgets/passage-ref"; | ||
export type { PassageRefDefaultWidgetOptions } from "./widgets/passage-ref"; | ||
export { default as passageRefTargetLogic } from "./widgets/passage-ref-target"; | ||
export type { PassageRefTargetDefaultWidgetOptions } from "./widgets/passage-ref-target"; | ||
export { default as phetSimulationLogic } from "./widgets/phet-simulation"; | ||
export type { PhetSimulationDefaultWidgetOptions } from "./widgets/phet-simulation"; | ||
export { default as plotterLogic } from "./widgets/plotter"; | ||
export type { PlotterDefaultWidgetOptions } from "./widgets/plotter"; | ||
export { default as pythonProgramLogic } from "./widgets/python-program"; | ||
export type { PythonProgramDefaultWidgetOptions } from "./widgets/python-program"; | ||
export { default as radioLogic } from "./widgets/radio"; | ||
export type { RadioDefaultWidgetOptions } from "./widgets/radio"; | ||
export { default as sorterLogic } from "./widgets/sorter"; | ||
export type { SorterDefaultWidgetOptions } from "./widgets/sorter"; | ||
export { default as tableLogic } from "./widgets/table"; | ||
export type { TableDefaultWidgetOptions } from "./widgets/table"; | ||
export { default as videoLogic } from "./widgets/video"; | ||
export type { VideoDefaultWidgetOptions } from "./widgets/video"; | ||
export type * from "./widgets/logic-export.types"; | ||
export { default as getOrdererPublicWidgetOptions } from "./widgets/orderer/orderer-util"; | ||
export { default as getCategorizerPublicWidgetOptions } from "./widgets/categorizer/categorizer-util"; | ||
export { default as getExpressionPublicWidgetOptions } from "./widgets/expression/expression-util"; |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "0.0.0-PR2015-20250118020016", | ||
"version": "0.0.0-PR2015-20250127191930", | ||
"publishConfig": { | ||
@@ -9,0 +9,0 @@ "access": "public" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
946754
61
8197