@khanacademy/perseus 6.7.0 → 7.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 +28 -0
- package/dist/es/index.js +37 -37
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +36 -37
- package/dist/index.js.flow +0 -3
- package/dist/index.js.map +1 -1
- package/dist/item-renderer.d.ts +2 -1
- package/dist/item-renderer.js.flow +2 -6
- package/dist/perseus-api.d.ts +3 -0
- package/dist/perseus-api.js.flow +3 -0
- package/dist/server-item-renderer.d.ts +2 -1
- package/dist/server-item-renderer.js.flow +2 -6
- package/dist/types.d.ts +2 -17
- package/dist/types.js.flow +2 -17
- package/dist/util.d.ts +5 -2
- package/dist/util.js.flow +5 -2
- package/dist/widgets/matcher.d.ts +1 -0
- package/dist/widgets/matcher.js.flow +1 -0
- package/dist/widgets/simulator.d.ts +1 -0
- package/dist/widgets/simulator.js.flow +1 -0
- package/dist/widgets/sorter.d.ts +1 -0
- package/dist/widgets/sorter.js.flow +1 -0
- package/package.json +3 -3
- package/src/index.ts +0 -3
- package/src/item-renderer.tsx +2 -1
- package/src/mixins/provide-keypad.tsx +10 -8
- package/src/perseus-api.tsx +6 -0
- package/src/server-item-renderer.tsx +2 -1
- package/src/types.ts +5 -20
- package/src/util.ts +21 -2
- package/src/widgets/__stories__/expression.stories.tsx +1 -1
- package/src/widgets/__stories__/test-keypad-context-wrapper.tsx +3 -5
- package/tsconfig-build.tsbuildinfo +1 -1
- package/dist/keypad-context.d.ts +0 -20
- package/dist/keypad-context.js.flow +0 -18
- package/src/keypad-context.ts +0 -34
package/dist/index.d.ts
CHANGED
|
@@ -55,7 +55,6 @@ export * as Dependencies from "./dependencies";
|
|
|
55
55
|
export { Errors, Log } from "./logging/log";
|
|
56
56
|
export { PerseusError } from "./perseus-error";
|
|
57
57
|
export { default as JiptParagraphs } from "./jipt-paragraphs";
|
|
58
|
-
export { default as KeypadContext } from "./keypad-context";
|
|
59
58
|
export { default as KhanMath } from "./util/math";
|
|
60
59
|
export { default as LoadingContext } from "./loading-context";
|
|
61
60
|
export { default as mediaQueries } from "./styles/media-queries";
|
|
@@ -87,7 +86,7 @@ export { default as WIDGET_PROP_DENYLIST } from "./mixins/widget-prop-denylist";
|
|
|
87
86
|
export type { PerseusOptions } from "./init";
|
|
88
87
|
export type { ILogger, LogErrorOptions, ErrorKind } from "./logging/log";
|
|
89
88
|
export type { ServerItemRenderer as ServerItemRendererComponent } from "./server-item-renderer";
|
|
90
|
-
export type { Alignment, APIOptions, APIOptionsWithDefaults, ChangeHandler, DeviceType, DomInsertCheckFn, EditorMode, FocusPath, Hint, ImageDict, ImageUploader, JiptLabelStore, JiptRenderer,
|
|
89
|
+
export type { Alignment, APIOptions, APIOptionsWithDefaults, ChangeHandler, DeviceType, DomInsertCheckFn, EditorMode, FocusPath, Hint, ImageDict, ImageUploader, JiptLabelStore, JiptRenderer, LinterContextProps, PerseusDependencies, PerseusScore, Version, VideoData, VideoKind, WidgetDict, WidgetExports, WidgetInfo, } from "./types";
|
|
91
90
|
export type { ParsedValue } from "./util";
|
|
92
91
|
export type { MathFormat, InputNumberWidget, PerseusImageBackground, PerseusInteractiveGraphWidgetOptions, PerseusRadioWidgetOptions, PerseusExpressionWidgetOptions, PerseusRenderer, } from "./perseus-types";
|
|
93
92
|
export type { Coord } from "./interactive2/types";
|
package/dist/index.js
CHANGED
|
@@ -1492,6 +1492,10 @@ const ApiOptions = {
|
|
|
1492
1492
|
nativeKeypadProxy: PropTypes__default["default"].func,
|
|
1493
1493
|
// Indicates whether or not to use mobile styling.
|
|
1494
1494
|
isMobile: PropTypes__default["default"].bool,
|
|
1495
|
+
// Whether to use v1 (Legacy) Keypad for MathInput mobile or
|
|
1496
|
+
// use the new v2 Keypad
|
|
1497
|
+
// TODO [LC-1088]: remove after v2 release
|
|
1498
|
+
useV2Keypad: PropTypes__default["default"].bool,
|
|
1495
1499
|
// A function, called with a bool indicating whether use of the
|
|
1496
1500
|
// drawing area (scratchpad) should be allowed/disallowed.
|
|
1497
1501
|
// Previously handled by `Khan.scratchpad.enable/disable`
|
|
@@ -1530,6 +1534,7 @@ const ApiOptions = {
|
|
|
1530
1534
|
defaults: {
|
|
1531
1535
|
isArticle: false,
|
|
1532
1536
|
isMobile: false,
|
|
1537
|
+
useV2Keypad: false,
|
|
1533
1538
|
onInputError: function () {},
|
|
1534
1539
|
onFocusChange: function () {},
|
|
1535
1540
|
GroupMetadataEditor: StubTagEditor,
|
|
@@ -3002,7 +3007,7 @@ const defaultContext$2 = {
|
|
|
3002
3007
|
assetStatuses: {},
|
|
3003
3008
|
setAssetStatus: (assetKey, loaded) => {}
|
|
3004
3009
|
};
|
|
3005
|
-
const context$
|
|
3010
|
+
const context$1 = /*#__PURE__*/React__namespace.createContext(defaultContext$2);
|
|
3006
3011
|
|
|
3007
3012
|
/* eslint-disable @babel/no-invalid-this, getter-return, one-var */
|
|
3008
3013
|
let supportsPassive = false;
|
|
@@ -3678,6 +3683,21 @@ const supportsPassiveEvents = () => {
|
|
|
3678
3683
|
function captureScratchpadTouchStart$4(e) {
|
|
3679
3684
|
e.stopPropagation();
|
|
3680
3685
|
}
|
|
3686
|
+
async function getImageSizeModern(url) {
|
|
3687
|
+
const image = new Image();
|
|
3688
|
+
return new Promise((resolve, reject) => {
|
|
3689
|
+
// Handle the success case
|
|
3690
|
+
image.onload = () => {
|
|
3691
|
+
resolve([image.naturalWidth, image.naturalHeight]);
|
|
3692
|
+
};
|
|
3693
|
+
|
|
3694
|
+
// Handle the error case
|
|
3695
|
+
image.onerror = reject;
|
|
3696
|
+
|
|
3697
|
+
// Kick off the loading
|
|
3698
|
+
image.src = url;
|
|
3699
|
+
});
|
|
3700
|
+
}
|
|
3681
3701
|
function getImageSize(url, callback) {
|
|
3682
3702
|
const img = new Image();
|
|
3683
3703
|
img.onload = function () {
|
|
@@ -3812,6 +3832,7 @@ const Util = {
|
|
|
3812
3832
|
supportsPassiveEvents,
|
|
3813
3833
|
captureScratchpadTouchStart: captureScratchpadTouchStart$4,
|
|
3814
3834
|
getImageSize,
|
|
3835
|
+
getImageSizeModern,
|
|
3815
3836
|
getRealImageUrl,
|
|
3816
3837
|
isLabeledSVG,
|
|
3817
3838
|
getBaseUrl,
|
|
@@ -17659,7 +17680,7 @@ class ZoomableTeX extends React__namespace.Component {
|
|
|
17659
17680
|
return /*#__PURE__*/React__namespace.createElement(Zoomable, {
|
|
17660
17681
|
readyToMeasure: this.state.isRendered,
|
|
17661
17682
|
computeChildBounds: computeMathBounds
|
|
17662
|
-
}, /*#__PURE__*/React__namespace.createElement(context$
|
|
17683
|
+
}, /*#__PURE__*/React__namespace.createElement(context$1.Consumer, null, _ref => {
|
|
17663
17684
|
let {
|
|
17664
17685
|
setAssetStatus
|
|
17665
17686
|
} = _ref;
|
|
@@ -19787,7 +19808,7 @@ class Renderer extends React__namespace.Component {
|
|
|
19787
19808
|
}, /*#__PURE__*/React__namespace.createElement(ErrorBoundary, null, /*#__PURE__*/React__namespace.createElement("div", {
|
|
19788
19809
|
className: "perseus-block-math-inner",
|
|
19789
19810
|
style: innerStyle
|
|
19790
|
-
}, /*#__PURE__*/React__namespace.createElement(context$
|
|
19811
|
+
}, /*#__PURE__*/React__namespace.createElement(context$1.Consumer, null, _ref => {
|
|
19791
19812
|
let {
|
|
19792
19813
|
setAssetStatus
|
|
19793
19814
|
} = _ref;
|
|
@@ -19812,7 +19833,7 @@ class Renderer extends React__namespace.Component {
|
|
|
19812
19833
|
// wrap to the next line
|
|
19813
19834
|
whiteSpace: "nowrap"
|
|
19814
19835
|
}
|
|
19815
|
-
}, /*#__PURE__*/React__namespace.createElement(ErrorBoundary, null, /*#__PURE__*/React__namespace.createElement("span", null), /*#__PURE__*/React__namespace.createElement(context$
|
|
19836
|
+
}, /*#__PURE__*/React__namespace.createElement(ErrorBoundary, null, /*#__PURE__*/React__namespace.createElement("span", null), /*#__PURE__*/React__namespace.createElement(context$1.Consumer, null, _ref2 => {
|
|
19816
19837
|
let {
|
|
19817
19838
|
setAssetStatus
|
|
19818
19839
|
} = _ref2;
|
|
@@ -19843,7 +19864,7 @@ class Renderer extends React__namespace.Component {
|
|
|
19843
19864
|
const responsive = !state.inTable;
|
|
19844
19865
|
return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
19845
19866
|
key: state.key
|
|
19846
|
-
}, /*#__PURE__*/React__namespace.createElement(context$
|
|
19867
|
+
}, /*#__PURE__*/React__namespace.createElement(context$1.Consumer, null, _ref3 => {
|
|
19847
19868
|
let {
|
|
19848
19869
|
setAssetStatus
|
|
19849
19870
|
} = _ref3;
|
|
@@ -31908,7 +31929,7 @@ class LabelImage extends React__namespace.Component {
|
|
|
31908
31929
|
// than its rendered in the widget, this would
|
|
31909
31930
|
// result in a zoom of the image.
|
|
31910
31931
|
selectedMarkerIndex !== -1 && styles$f.imageInteractionDisabled)
|
|
31911
|
-
}, /*#__PURE__*/React__namespace.createElement(context$
|
|
31932
|
+
}, /*#__PURE__*/React__namespace.createElement(context$1.Consumer, null, _ref => {
|
|
31912
31933
|
let {
|
|
31913
31934
|
setAssetStatus
|
|
31914
31935
|
} = _ref;
|
|
@@ -44177,13 +44198,9 @@ const ProvideKeypad = {
|
|
|
44177
44198
|
},
|
|
44178
44199
|
componentDidMount() {
|
|
44179
44200
|
const _this = this;
|
|
44180
|
-
if (
|
|
44181
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'props' does not exist on type '{ readonly propTypes: { readonly apiOptions: React.PropType<{ customKeypad?: boolean | undefined; nativeKeypadProxy?: ((...a: readonly any[]) => unknown) | undefined; }>; readonly keypadStyle: Requireable<any>; }; readonly getInitialState: () => { ...; }; readonly componentDidMount: () => void; readonly componentWil...'.
|
|
44182
|
-
_this.props.apiOptions &&
|
|
44183
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'props' does not exist on type '{ readonly propTypes: { readonly apiOptions: React.PropType<{ customKeypad?: boolean | undefined; nativeKeypadProxy?: ((...a: readonly any[]) => unknown) | undefined; }>; readonly keypadStyle: Requireable<any>; }; readonly getInitialState: () => { ...; }; readonly componentDidMount: () => void; readonly componentWil...'.
|
|
44184
|
-
_this.props.apiOptions.customKeypad &&
|
|
44185
44201
|
// @ts-expect-error [FEI-5003] - TS2339 - Property 'props' does not exist on type '{ readonly propTypes: { readonly apiOptions: React.PropType<{ customKeypad?: boolean | undefined; nativeKeypadProxy?: ((...a: readonly any[]) => unknown) | undefined; }>; readonly keypadStyle: Requireable<any>; }; readonly getInitialState: () => { ...; }; readonly componentDidMount: () => void; readonly componentWil...'.
|
|
44186
|
-
|
|
44202
|
+
const apiOptions = _this.props.apiOptions;
|
|
44203
|
+
if (apiOptions && apiOptions.customKeypad && !apiOptions.nativeKeypadProxy) {
|
|
44187
44204
|
var _document$body;
|
|
44188
44205
|
// TODO(charlie): Render this and the wrapped component in the same
|
|
44189
44206
|
// React tree. We may also want to add this keypad asynchronously
|
|
@@ -44192,7 +44209,7 @@ const ProvideKeypad = {
|
|
|
44192
44209
|
_this._keypadContainer = document.createElement("div");
|
|
44193
44210
|
// @ts-expect-error [FEI-5003] - TS2339 - Property '_keypadContainer' does not exist on type '{ readonly propTypes: { readonly apiOptions: React.PropType<{ customKeypad?: boolean | undefined; nativeKeypadProxy?: ((...a: readonly any[]) => unknown) | undefined; }>; readonly keypadStyle: Requireable<any>; }; readonly getInitialState: () => { ...; }; readonly componentDidMount: () => void; readonly componentWil...'.
|
|
44194
44211
|
(_document$body = document.body) === null || _document$body === void 0 ? void 0 : _document$body.appendChild(_this._keypadContainer);
|
|
44195
|
-
render( /*#__PURE__*/React__namespace.createElement(mathInput.
|
|
44212
|
+
render( /*#__PURE__*/React__namespace.createElement(mathInput.MobileKeypad, {
|
|
44196
44213
|
onElementMounted: element => {
|
|
44197
44214
|
// NOTE(kevinb): The reason why this setState works is
|
|
44198
44215
|
// b/c we're calling it manually from item-renderer.jsx
|
|
@@ -44208,7 +44225,8 @@ const ProvideKeypad = {
|
|
|
44208
44225
|
}
|
|
44209
44226
|
// @ts-expect-error [FEI-5003] - TS2339 - Property 'props' does not exist on type '{ readonly propTypes: { readonly apiOptions: React.PropType<{ customKeypad?: boolean | undefined; nativeKeypadProxy?: ((...a: readonly any[]) => unknown) | undefined; }>; readonly keypadStyle: Requireable<any>; }; readonly getInitialState: () => { ...; }; readonly componentDidMount: () => void; readonly componentWil...'.
|
|
44210
44227
|
,
|
|
44211
|
-
style: _this.props.keypadStyle
|
|
44228
|
+
style: _this.props.keypadStyle,
|
|
44229
|
+
useV2Keypad: apiOptions.useV2Keypad
|
|
44212
44230
|
}),
|
|
44213
44231
|
// @ts-expect-error [FEI-5003] - TS2339 - Property '_keypadContainer' does not exist on type '{ readonly propTypes: { readonly apiOptions: React.PropType<{ customKeypad?: boolean | undefined; nativeKeypadProxy?: ((...a: readonly any[]) => unknown) | undefined; }>; readonly keypadStyle: Requireable<any>; }; readonly getInitialState: () => { ...; }; readonly componentDidMount: () => void; readonly componentWil...'.
|
|
44214
44232
|
_this._keypadContainer);
|
|
@@ -45135,7 +45153,7 @@ _defineProperty(ItemRenderer, "defaultProps", {
|
|
|
45135
45153
|
const defaultContext = {
|
|
45136
45154
|
onRendered: isRendered => {}
|
|
45137
45155
|
};
|
|
45138
|
-
const context
|
|
45156
|
+
const context = /*#__PURE__*/React__namespace.createContext(defaultContext);
|
|
45139
45157
|
|
|
45140
45158
|
const {
|
|
45141
45159
|
mapObject
|
|
@@ -45406,7 +45424,7 @@ class ServerItemRenderer extends React__namespace.Component {
|
|
|
45406
45424
|
assetStatuses: this.state.assetStatuses,
|
|
45407
45425
|
setAssetStatus: this.setAssetStatus
|
|
45408
45426
|
};
|
|
45409
|
-
const questionRenderer = /*#__PURE__*/React__namespace.createElement(context$
|
|
45427
|
+
const questionRenderer = /*#__PURE__*/React__namespace.createElement(context$1.Provider, {
|
|
45410
45428
|
value: contextValue
|
|
45411
45429
|
}, /*#__PURE__*/React__namespace.createElement(Renderer, {
|
|
45412
45430
|
keypadElement: this.props.keypadElement,
|
|
@@ -45453,7 +45471,7 @@ const styles$3 = aphrodite.StyleSheet.create({
|
|
|
45453
45471
|
marginLeft: 50
|
|
45454
45472
|
}
|
|
45455
45473
|
});
|
|
45456
|
-
const ref = /*#__PURE__*/React__namespace.forwardRef((props, ref) => /*#__PURE__*/React__namespace.createElement(context
|
|
45474
|
+
const ref = /*#__PURE__*/React__namespace.forwardRef((props, ref) => /*#__PURE__*/React__namespace.createElement(context.Consumer, null, _ref => {
|
|
45457
45475
|
let {
|
|
45458
45476
|
onRendered
|
|
45459
45477
|
} = _ref;
|
|
@@ -45947,24 +45965,6 @@ var constants = /*#__PURE__*/Object.freeze({
|
|
|
45947
45965
|
perseusFrameBorderWidth: perseusFrameBorderWidth
|
|
45948
45966
|
});
|
|
45949
45967
|
|
|
45950
|
-
/**
|
|
45951
|
-
* KeypadContext provides a way to the Keypad and (Server)ItemRenderer to
|
|
45952
|
-
* communicate.
|
|
45953
|
-
*
|
|
45954
|
-
* The KeypadContext.Provider wraps the ExerciseFooter while KeypadContext.Consumer
|
|
45955
|
-
* wraps each (Server)ItemRenderer render site and the Keypad rendered in the
|
|
45956
|
-
* ExerciseFooter.
|
|
45957
|
-
*/
|
|
45958
|
-
// @ts-expect-error [FEI-5003] - TS2322 - Type 'Context<{ setKeypadElement: (keypadElement: HTMLElement | null | undefined) => void; keypadElement: null; setRenderer: (renderer: RendererInterface | null | undefined) => void; renderer: null; setScrollableElement: (scrollableElement: HTMLElement | ... 1 more ... | undefined) => void; scrollableElement: null; }>' is not assignable to type 'Context<KeypadContext>'.
|
|
45959
|
-
const context = /*#__PURE__*/React__namespace.createContext({
|
|
45960
|
-
setKeypadElement: keypadElement => {},
|
|
45961
|
-
keypadElement: null,
|
|
45962
|
-
setRenderer: renderer => {},
|
|
45963
|
-
renderer: null,
|
|
45964
|
-
setScrollableElement: scrollableElement => {},
|
|
45965
|
-
scrollableElement: null
|
|
45966
|
-
});
|
|
45967
|
-
|
|
45968
45968
|
// TODO(FEI-4010): Remove `Perseus` prefix for all types here
|
|
45969
45969
|
// TODO(FEI-4011): Use types generated by https://github.com/jaredly/generate-perseus-flowtypes
|
|
45970
45970
|
|
|
@@ -47107,10 +47107,9 @@ exports.InputNumber = InputNumber$1;
|
|
|
47107
47107
|
exports.InteractiveGraphWidget = InteractiveGraph$1;
|
|
47108
47108
|
exports.ItemRenderer = ItemRenderer;
|
|
47109
47109
|
exports.JiptParagraphs = JiptParagraphs;
|
|
47110
|
-
exports.KeypadContext = context;
|
|
47111
47110
|
exports.KhanColors = KhanColors;
|
|
47112
47111
|
exports.KhanMath = KhanMath;
|
|
47113
|
-
exports.LoadingContext = context
|
|
47112
|
+
exports.LoadingContext = context;
|
|
47114
47113
|
exports.Log = Log;
|
|
47115
47114
|
exports.MatrixWidget = Matrix$1;
|
|
47116
47115
|
exports.MultiItems = MultiItems;
|
package/dist/index.js.flow
CHANGED
|
@@ -49,7 +49,6 @@ declare export * as Dependencies from "./dependencies";
|
|
|
49
49
|
declare export { Errors, Log } from "./logging/log";
|
|
50
50
|
declare export { PerseusError } from "./perseus-error";
|
|
51
51
|
declare export { default as JiptParagraphs } from "./jipt-paragraphs";
|
|
52
|
-
declare export { default as KeypadContext } from "./keypad-context";
|
|
53
52
|
declare export { default as KhanMath } from "./util/math";
|
|
54
53
|
declare export { default as LoadingContext } from "./loading-context";
|
|
55
54
|
declare export { default as mediaQueries } from "./styles/media-queries";
|
|
@@ -86,11 +85,9 @@ export type {
|
|
|
86
85
|
ImageUploader,
|
|
87
86
|
JiptLabelStore,
|
|
88
87
|
JiptRenderer,
|
|
89
|
-
KEScore,
|
|
90
88
|
LinterContextProps,
|
|
91
89
|
PerseusDependencies,
|
|
92
90
|
PerseusScore,
|
|
93
|
-
RendererInterface,
|
|
94
91
|
Version,
|
|
95
92
|
VideoData,
|
|
96
93
|
VideoKind,
|