@khanacademy/perseus 17.8.0 → 18.0.1
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/CHANGELOG.md +40 -0
- package/dist/es/index.css +0 -4
- package/dist/es/index.js +1422 -1021
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +0 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1321 -954
- package/dist/index.js.map +1 -1
- package/dist/perseus-types.d.ts +4 -3
- package/dist/renderer.d.ts +6 -6
- package/dist/server-item-renderer.d.ts +2 -4
- package/dist/strings.js +1 -1
- package/dist/types.d.ts +19 -2
- package/dist/util/drawing-transform.d.ts +21 -0
- package/dist/util/extract-perseus-data.d.ts +26 -0
- package/dist/util/graph-bounds.d.ts +9 -0
- package/dist/util/graphie.d.ts +2 -0
- package/dist/util/interval.d.ts +1 -0
- package/dist/util/parse-perseus-json.d.ts +10 -0
- package/dist/util/tex.d.ts +1 -3
- package/dist/widgets/deprecated-standin/index.d.ts +4 -4
- package/dist/widgets/passage.d.ts +3 -3
- package/dist/widgets.d.ts +16 -6
- package/package.json +9 -9
- package/src/__tests__/extract-perseus-data.test.ts +1027 -0
- package/src/index.ts +6 -1
- package/src/init.ts +1 -1
- package/src/perseus-types.ts +4 -3
- package/src/renderer.tsx +12 -9
- package/src/server-item-renderer.tsx +2 -4
- package/src/styles/widgets/image.less +0 -3
- package/src/types.ts +19 -16
- package/src/util/drawing-transform.test.ts +67 -0
- package/src/util/drawing-transform.ts +102 -0
- package/src/util/extract-perseus-data.ts +539 -0
- package/src/util/graph-bounds.ts +23 -0
- package/src/util/graphie.ts +1167 -1258
- package/src/util/interactive.ts +2 -2
- package/src/util/interval.ts +4 -0
- package/src/util/parse-perseus-json.test.ts +10 -0
- package/src/util/parse-perseus-json.ts +13 -0
- package/src/util/tex.ts +11 -84
- package/src/widgets/__stories__/image.stories.tsx +12 -26
- package/src/widgets/__tests__/__snapshots__/grapher.test.ts.snap +72 -288
- package/src/widgets/__tests__/__snapshots__/interaction.test.ts.snap +5 -20
- package/src/widgets/__tests__/__snapshots__/interactive-graph.test.ts.snap +32 -128
- package/src/widgets/__tests__/__snapshots__/number-line.test.ts.snap +22 -88
- package/src/widgets/__tests__/__snapshots__/plotter.test.tsx.snap +12 -48
- package/src/widgets/deprecated-standin/__stories__/deprecated-standin.stories.tsx +8 -12
- package/src/widgets/deprecated-standin/__tests__/__snapshots__/deprecated-standin.test.ts.snap +6 -7
- package/src/widgets/deprecated-standin/index.tsx +8 -7
- package/src/widgets/interactive-graph.tsx +3 -2
- package/src/widgets/label-image/answer-pill.tsx +6 -1
- package/src/widgets/passage.tsx +5 -7
- package/src/widgets.ts +34 -10
- package/tsconfig-build.tsbuildinfo +1 -1
package/src/widgets.ts
CHANGED
|
@@ -3,12 +3,12 @@ import _ from "underscore";
|
|
|
3
3
|
import {Errors, Log} from "./logging/log";
|
|
4
4
|
import {PerseusError} from "./perseus-error";
|
|
5
5
|
|
|
6
|
+
import type {PerseusWidget} from "./perseus-types";
|
|
6
7
|
import type {
|
|
7
8
|
Alignment,
|
|
8
9
|
Tracking,
|
|
9
10
|
Version,
|
|
10
11
|
WidgetExports,
|
|
11
|
-
WidgetInfo,
|
|
12
12
|
WidgetTransform,
|
|
13
13
|
} from "./types";
|
|
14
14
|
import type * as React from "react";
|
|
@@ -79,6 +79,30 @@ export const registerEditors = (editorsToRegister: ReadonlyArray<Editor>) => {
|
|
|
79
79
|
});
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param name - the widget that you are trying to replace
|
|
85
|
+
* @param replacementName - the name of the widget that takes its place
|
|
86
|
+
*
|
|
87
|
+
* e.g. replaceEditor("transformer", "always-correct") will make it so the
|
|
88
|
+
* transformer widget is replaced by the always correct widget
|
|
89
|
+
*/
|
|
90
|
+
export const replaceEditor = (name: string, replacementName: string) => {
|
|
91
|
+
const substituteEditor = editors[replacementName];
|
|
92
|
+
|
|
93
|
+
if (!substituteEditor && Log) {
|
|
94
|
+
const errorMsg = `Failed to replace editor ${name} with ${replacementName}`;
|
|
95
|
+
Log.error(errorMsg, Errors.Internal);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
editors[name] = substituteEditor;
|
|
100
|
+
|
|
101
|
+
if (Log) {
|
|
102
|
+
Log.log(`INFO: Replacing editor ${name} with ${replacementName}`);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
82
106
|
export const getWidget = (
|
|
83
107
|
name: string,
|
|
84
108
|
): React.ComponentType<any> | null | undefined => {
|
|
@@ -106,12 +130,12 @@ export const getTransform = (
|
|
|
106
130
|
return _.has(widgets, name) ? widgets[name].transform || _.identity : null;
|
|
107
131
|
};
|
|
108
132
|
|
|
109
|
-
export const getVersion = (name: string): Version |
|
|
133
|
+
export const getVersion = (name: string): Version | undefined => {
|
|
110
134
|
const widgetInfo = widgets[name];
|
|
111
135
|
if (widgetInfo) {
|
|
112
136
|
return widgets[name].version || {major: 0, minor: 0};
|
|
113
137
|
}
|
|
114
|
-
return
|
|
138
|
+
return;
|
|
115
139
|
};
|
|
116
140
|
|
|
117
141
|
export const getVersionVector = (): {
|
|
@@ -136,7 +160,7 @@ export const getPublicWidgets = (): ReadonlyArray<WidgetExports> => {
|
|
|
136
160
|
);
|
|
137
161
|
};
|
|
138
162
|
|
|
139
|
-
export const isAccessible = (widgetInfo:
|
|
163
|
+
export const isAccessible = (widgetInfo: PerseusWidget): boolean => {
|
|
140
164
|
const accessible = widgets[widgetInfo.type].accessible;
|
|
141
165
|
if (typeof accessible === "function") {
|
|
142
166
|
return accessible(widgetInfo.options);
|
|
@@ -149,8 +173,8 @@ export const getAllWidgetTypes = (): ReadonlyArray<string> => {
|
|
|
149
173
|
};
|
|
150
174
|
|
|
151
175
|
export const upgradeWidgetInfoToLatestVersion = (
|
|
152
|
-
oldWidgetInfo:
|
|
153
|
-
):
|
|
176
|
+
oldWidgetInfo: PerseusWidget,
|
|
177
|
+
): PerseusWidget => {
|
|
154
178
|
const type = oldWidgetInfo.type;
|
|
155
179
|
// TODO(LP-10707): Remove unnecessary type checking (`type` is a string)
|
|
156
180
|
if (!_.isString(type)) {
|
|
@@ -271,9 +295,9 @@ export const upgradeWidgetInfoToLatestVersion = (
|
|
|
271
295
|
};
|
|
272
296
|
|
|
273
297
|
export const getRendererPropsForWidgetInfo = (
|
|
274
|
-
widgetInfo:
|
|
298
|
+
widgetInfo: PerseusWidget,
|
|
275
299
|
problemNum?: number,
|
|
276
|
-
):
|
|
300
|
+
): PerseusWidget => {
|
|
277
301
|
const type = widgetInfo.type;
|
|
278
302
|
const widgetExports = widgets[type];
|
|
279
303
|
if (widgetExports == null) {
|
|
@@ -298,9 +322,9 @@ export const getRendererPropsForWidgetInfo = (
|
|
|
298
322
|
};
|
|
299
323
|
|
|
300
324
|
export const traverseChildWidgets = (
|
|
301
|
-
widgetInfo:
|
|
325
|
+
widgetInfo: PerseusWidget,
|
|
302
326
|
traverseRenderer: any,
|
|
303
|
-
):
|
|
327
|
+
): PerseusWidget => {
|
|
304
328
|
if (!traverseRenderer) {
|
|
305
329
|
throw new PerseusError(
|
|
306
330
|
"traverseRenderer must be provided, but was not",
|