@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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # @khanacademy/perseus
2
2
 
3
+ ## 7.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 5611204a: Adds back the export of the unwrapped keypad for Khanmigo
8
+ - Updated dependencies [b4c06409]
9
+ - Updated dependencies [5611204a]
10
+ - Updated dependencies [b4430dce]
11
+ - @khanacademy/perseus-core@0.1.0
12
+ - @khanacademy/math-input@8.1.0
13
+
14
+ ## 7.0.0
15
+
16
+ ### Major Changes
17
+
18
+ - f9ee9d24: Move KeypadContext from Perseus to MathInput
19
+
20
+ ### Minor Changes
21
+
22
+ - b18986d3: Adds useV2Keypad API option for switching between new and legacy keypads
23
+
24
+ ### Patch Changes
25
+
26
+ - b18986d3: Replace Legacy/Mobile keypads with a component that switches between them
27
+ - Updated dependencies [f9ee9d24]
28
+ - Updated dependencies [b18986d3]
29
+ - @khanacademy/math-input@8.0.0
30
+
3
31
  ## 6.7.0
4
32
 
5
33
  ### Minor Changes
package/dist/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as KAS from '@khanacademy/kas';
2
- import { keyTranslator, createMathField, mathQuillInstance, KeypadInput, KeypadType, keypadElementPropType, LegacyKeypad } from '@khanacademy/math-input';
2
+ import { keyTranslator, createMathField, mathQuillInstance, KeypadInput, KeypadType, keypadElementPropType, MobileKeypad } from '@khanacademy/math-input';
3
3
  import * as PerseusLinter from '@khanacademy/perseus-linter';
4
4
  import { linterContextDefault, Rule, linterContextProps } from '@khanacademy/perseus-linter';
5
5
  import * as i18n from '@khanacademy/wonder-blocks-i18n';
@@ -1433,6 +1433,10 @@ const ApiOptions = {
1433
1433
  nativeKeypadProxy: PropTypes.func,
1434
1434
  // Indicates whether or not to use mobile styling.
1435
1435
  isMobile: PropTypes.bool,
1436
+ // Whether to use v1 (Legacy) Keypad for MathInput mobile or
1437
+ // use the new v2 Keypad
1438
+ // TODO [LC-1088]: remove after v2 release
1439
+ useV2Keypad: PropTypes.bool,
1436
1440
  // A function, called with a bool indicating whether use of the
1437
1441
  // drawing area (scratchpad) should be allowed/disallowed.
1438
1442
  // Previously handled by `Khan.scratchpad.enable/disable`
@@ -1471,6 +1475,7 @@ const ApiOptions = {
1471
1475
  defaults: {
1472
1476
  isArticle: false,
1473
1477
  isMobile: false,
1478
+ useV2Keypad: false,
1474
1479
  onInputError: function () {},
1475
1480
  onFocusChange: function () {},
1476
1481
  GroupMetadataEditor: StubTagEditor,
@@ -2938,7 +2943,7 @@ const defaultContext$2 = {
2938
2943
  assetStatuses: {},
2939
2944
  setAssetStatus: (assetKey, loaded) => {}
2940
2945
  };
2941
- const context$2 = /*#__PURE__*/React.createContext(defaultContext$2);
2946
+ const context$1 = /*#__PURE__*/React.createContext(defaultContext$2);
2942
2947
 
2943
2948
  /* eslint-disable @babel/no-invalid-this, getter-return, one-var */
2944
2949
  let supportsPassive = false;
@@ -3613,6 +3618,21 @@ const supportsPassiveEvents = () => {
3613
3618
  function captureScratchpadTouchStart$4(e) {
3614
3619
  e.stopPropagation();
3615
3620
  }
3621
+ async function getImageSizeModern(url) {
3622
+ const image = new Image();
3623
+ return new Promise((resolve, reject) => {
3624
+ // Handle the success case
3625
+ image.onload = () => {
3626
+ resolve([image.naturalWidth, image.naturalHeight]);
3627
+ };
3628
+
3629
+ // Handle the error case
3630
+ image.onerror = reject;
3631
+
3632
+ // Kick off the loading
3633
+ image.src = url;
3634
+ });
3635
+ }
3616
3636
  function getImageSize(url, callback) {
3617
3637
  const img = new Image();
3618
3638
  img.onload = function () {
@@ -3747,6 +3767,7 @@ const Util = {
3747
3767
  supportsPassiveEvents,
3748
3768
  captureScratchpadTouchStart: captureScratchpadTouchStart$4,
3749
3769
  getImageSize,
3770
+ getImageSizeModern,
3750
3771
  getRealImageUrl,
3751
3772
  isLabeledSVG,
3752
3773
  getBaseUrl,
@@ -17597,7 +17618,7 @@ class ZoomableTeX extends React.Component {
17597
17618
  return /*#__PURE__*/React.createElement(Zoomable, {
17598
17619
  readyToMeasure: this.state.isRendered,
17599
17620
  computeChildBounds: computeMathBounds
17600
- }, /*#__PURE__*/React.createElement(context$2.Consumer, null, ({
17621
+ }, /*#__PURE__*/React.createElement(context$1.Consumer, null, ({
17601
17622
  setAssetStatus
17602
17623
  }) => /*#__PURE__*/React.createElement(Tex, {
17603
17624
  onRender: this.handleRender,
@@ -19687,7 +19708,7 @@ class Renderer extends React.Component {
19687
19708
  }, /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement("div", {
19688
19709
  className: "perseus-block-math-inner",
19689
19710
  style: innerStyle
19690
- }, /*#__PURE__*/React.createElement(context$2.Consumer, null, ({
19711
+ }, /*#__PURE__*/React.createElement(context$1.Consumer, null, ({
19691
19712
  setAssetStatus
19692
19713
  }) => /*#__PURE__*/React.createElement(Tex, {
19693
19714
  setAssetStatus: setAssetStatus
@@ -19709,7 +19730,7 @@ class Renderer extends React.Component {
19709
19730
  // wrap to the next line
19710
19731
  whiteSpace: "nowrap"
19711
19732
  }
19712
- }, /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement("span", null), /*#__PURE__*/React.createElement(context$2.Consumer, null, ({
19733
+ }, /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement("span", null), /*#__PURE__*/React.createElement(context$1.Consumer, null, ({
19713
19734
  setAssetStatus
19714
19735
  }) => /*#__PURE__*/React.createElement(Tex, {
19715
19736
  onRender: this.props.onRender,
@@ -19737,7 +19758,7 @@ class Renderer extends React.Component {
19737
19758
  const responsive = !state.inTable;
19738
19759
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
19739
19760
  key: state.key
19740
- }, /*#__PURE__*/React.createElement(context$2.Consumer, null, ({
19761
+ }, /*#__PURE__*/React.createElement(context$1.Consumer, null, ({
19741
19762
  setAssetStatus
19742
19763
  }) => /*#__PURE__*/React.createElement(SvgImage, _extends({
19743
19764
  setAssetStatus: setAssetStatus
@@ -31728,7 +31749,7 @@ class LabelImage extends React.Component {
31728
31749
  // than its rendered in the widget, this would
31729
31750
  // result in a zoom of the image.
31730
31751
  selectedMarkerIndex !== -1 && styles$f.imageInteractionDisabled)
31731
- }, /*#__PURE__*/React.createElement(context$2.Consumer, null, ({
31752
+ }, /*#__PURE__*/React.createElement(context$1.Consumer, null, ({
31732
31753
  setAssetStatus
31733
31754
  }) => /*#__PURE__*/React.createElement(SvgImage, {
31734
31755
  alt: imageAlt,
@@ -43944,13 +43965,9 @@ const ProvideKeypad = {
43944
43965
  },
43945
43966
  componentDidMount() {
43946
43967
  const _this = this;
43947
- if (
43948
- // @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...'.
43949
- _this.props.apiOptions &&
43950
- // @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...'.
43951
- _this.props.apiOptions.customKeypad &&
43952
43968
  // @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...'.
43953
- !_this.props.apiOptions.nativeKeypadProxy) {
43969
+ const apiOptions = _this.props.apiOptions;
43970
+ if (apiOptions && apiOptions.customKeypad && !apiOptions.nativeKeypadProxy) {
43954
43971
  var _document$body;
43955
43972
  // TODO(charlie): Render this and the wrapped component in the same
43956
43973
  // React tree. We may also want to add this keypad asynchronously
@@ -43959,7 +43976,7 @@ const ProvideKeypad = {
43959
43976
  _this._keypadContainer = document.createElement("div");
43960
43977
  // @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...'.
43961
43978
  (_document$body = document.body) == null ? void 0 : _document$body.appendChild(_this._keypadContainer);
43962
- render( /*#__PURE__*/React.createElement(LegacyKeypad, {
43979
+ render( /*#__PURE__*/React.createElement(MobileKeypad, {
43963
43980
  onElementMounted: element => {
43964
43981
  // NOTE(kevinb): The reason why this setState works is
43965
43982
  // b/c we're calling it manually from item-renderer.jsx
@@ -43975,7 +43992,8 @@ const ProvideKeypad = {
43975
43992
  }
43976
43993
  // @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...'.
43977
43994
  ,
43978
- style: _this.props.keypadStyle
43995
+ style: _this.props.keypadStyle,
43996
+ useV2Keypad: apiOptions.useV2Keypad
43979
43997
  }),
43980
43998
  // @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...'.
43981
43999
  _this._keypadContainer);
@@ -44889,7 +44907,7 @@ ItemRenderer.defaultProps = {
44889
44907
  const defaultContext = {
44890
44908
  onRendered: isRendered => {}
44891
44909
  };
44892
- const context$1 = /*#__PURE__*/React.createContext(defaultContext);
44910
+ const context = /*#__PURE__*/React.createContext(defaultContext);
44893
44911
 
44894
44912
  const {
44895
44913
  mapObject
@@ -45157,7 +45175,7 @@ class ServerItemRenderer extends React.Component {
45157
45175
  assetStatuses: this.state.assetStatuses,
45158
45176
  setAssetStatus: this.setAssetStatus
45159
45177
  };
45160
- const questionRenderer = /*#__PURE__*/React.createElement(context$2.Provider, {
45178
+ const questionRenderer = /*#__PURE__*/React.createElement(context$1.Provider, {
45161
45179
  value: contextValue
45162
45180
  }, /*#__PURE__*/React.createElement(Renderer, {
45163
45181
  keypadElement: this.props.keypadElement,
@@ -45204,7 +45222,7 @@ const styles$3 = StyleSheet.create({
45204
45222
  marginLeft: 50
45205
45223
  }
45206
45224
  });
45207
- const ref = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(context$1.Consumer, null, ({
45225
+ const ref = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(context.Consumer, null, ({
45208
45226
  onRendered
45209
45227
  }) => /*#__PURE__*/React.createElement(ServerItemRenderer, _extends({}, props, {
45210
45228
  onRendered: onRendered,
@@ -45695,24 +45713,6 @@ var constants = /*#__PURE__*/Object.freeze({
45695
45713
  perseusFrameBorderWidth: perseusFrameBorderWidth
45696
45714
  });
45697
45715
 
45698
- /**
45699
- * KeypadContext provides a way to the Keypad and (Server)ItemRenderer to
45700
- * communicate.
45701
- *
45702
- * The KeypadContext.Provider wraps the ExerciseFooter while KeypadContext.Consumer
45703
- * wraps each (Server)ItemRenderer render site and the Keypad rendered in the
45704
- * ExerciseFooter.
45705
- */
45706
- // @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>'.
45707
- const context = /*#__PURE__*/React.createContext({
45708
- setKeypadElement: keypadElement => {},
45709
- keypadElement: null,
45710
- setRenderer: renderer => {},
45711
- renderer: null,
45712
- setScrollableElement: scrollableElement => {},
45713
- scrollableElement: null
45714
- });
45715
-
45716
45716
  // TODO(FEI-4010): Remove `Perseus` prefix for all types here
45717
45717
  // TODO(FEI-4011): Use types generated by https://github.com/jaredly/generate-perseus-flowtypes
45718
45718
 
@@ -46881,5 +46881,5 @@ const EditorJsonify = {
46881
46881
  const apiVersion = version.apiVersion;
46882
46882
  const itemDataVersion = version.itemDataVersion;
46883
46883
 
46884
- export { ApiOptions, ArrowPicker, ArticleRenderer, BaseRadio, Categorizer$1 as Categorizer, changeable as Changeable, ClassNames, ColorPicker, DashPicker, dependencies as Dependencies, EditorJsonify, ElementContainer, Errors, Expression, util as GrapherUtil, Grapher$1 as GrapherWidget, HintRenderer, HintsRenderer, InputNumber$1 as InputNumber, InteractiveGraph$1 as InteractiveGraphWidget, ItemRenderer, JiptParagraphs, context as KeypadContext, KhanColors, KhanMath, context$1 as LoadingContext, Log, Matrix$1 as MatrixWidget, MultiItems, NumericInput$1 as NumericInput, PerseusError, PerseusExpressionAnswerFormConsidered, PerseusMarkdown, Plotter$1 as PlotterWidget, Radio, Renderer, ref as ServerItemRenderer, sizingUtils as SizingUtils, Table$1 as TableWidget, Transformer$1 as TransformerWidget, Util, denylist as WIDGET_PROP_DENYLIST, WidgetJsonifyDeprecated, widgets$1 as Widgets, apiVersion, buildEmptyItemTreeForShape, buildMapper, components, constants, displaySigFigs, globalConstants, globalStyles, iconPaths as icons, init, interactiveSizes$1 as interactiveSizes, isItemRenderableByVersion, itemDataVersion, itemToTree, ItemVersion as itemVersion, mediaQueries, preprocessTex, registerAllWidgetsForTesting, shapes, traverse, violatingWidgets, allWidgets as widgets };
46884
+ export { ApiOptions, ArrowPicker, ArticleRenderer, BaseRadio, Categorizer$1 as Categorizer, changeable as Changeable, ClassNames, ColorPicker, DashPicker, dependencies as Dependencies, EditorJsonify, ElementContainer, Errors, Expression, util as GrapherUtil, Grapher$1 as GrapherWidget, HintRenderer, HintsRenderer, InputNumber$1 as InputNumber, InteractiveGraph$1 as InteractiveGraphWidget, ItemRenderer, JiptParagraphs, KhanColors, KhanMath, context as LoadingContext, Log, Matrix$1 as MatrixWidget, MultiItems, NumericInput$1 as NumericInput, PerseusError, PerseusExpressionAnswerFormConsidered, PerseusMarkdown, Plotter$1 as PlotterWidget, Radio, Renderer, ref as ServerItemRenderer, sizingUtils as SizingUtils, Table$1 as TableWidget, Transformer$1 as TransformerWidget, Util, denylist as WIDGET_PROP_DENYLIST, WidgetJsonifyDeprecated, widgets$1 as Widgets, apiVersion, buildEmptyItemTreeForShape, buildMapper, components, constants, displaySigFigs, globalConstants, globalStyles, iconPaths as icons, init, interactiveSizes$1 as interactiveSizes, isItemRenderableByVersion, itemDataVersion, itemToTree, ItemVersion as itemVersion, mediaQueries, preprocessTex, registerAllWidgetsForTesting, shapes, traverse, violatingWidgets, allWidgets as widgets };
46885
46885
  //# sourceMappingURL=index.js.map