@khanacademy/math-input 12.1.1 → 13.1.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/components/keypad/keypad.d.ts +1 -1
  3. package/dist/components/keypad/mobile-keypad.d.ts +2 -1
  4. package/dist/components/keypad/shared-keys.d.ts +1 -1
  5. package/dist/es/index.js +30 -10
  6. package/dist/es/index.js.map +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +30 -10
  9. package/dist/index.js.map +1 -1
  10. package/dist/types.d.ts +1 -0
  11. package/package.json +1 -1
  12. package/src/components/__tests__/integration.test.tsx +287 -0
  13. package/src/components/keypad/__tests__/__snapshots__/keypad.test.tsx.snap +84 -26
  14. package/src/components/keypad/__tests__/keypad-v2-mathquill.test.tsx +1 -1
  15. package/src/components/keypad/__tests__/keypad.test.tsx +30 -0
  16. package/src/components/keypad/keypad-button.stories.tsx +2 -1
  17. package/src/components/keypad/keypad-button.tsx +3 -0
  18. package/src/components/keypad/keypad-mathquill.stories.tsx +2 -2
  19. package/src/components/keypad/keypad-pages/fractions-page.tsx +1 -1
  20. package/src/components/keypad/keypad-pages/keypad-pages.stories.tsx +1 -1
  21. package/src/components/keypad/keypad.tsx +3 -3
  22. package/src/components/keypad/mobile-keypad.tsx +21 -4
  23. package/src/components/keypad/navigation-pad.stories.tsx +1 -1
  24. package/src/components/keypad/shared-keys.tsx +4 -4
  25. package/src/components/tabbar/tabbar.stories.tsx +4 -1
  26. package/src/{components/keypad/keypad.stories.tsx → full-keypad.stories.tsx} +6 -6
  27. package/src/{full-math-input.stories.tsx → full-mobile-input.stories.tsx} +15 -3
  28. package/src/index.ts +1 -1
  29. package/src/types.ts +1 -0
  30. package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @khanacademy/math-input
2
2
 
3
+ ## 13.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3b19a1bf: Ensured that we're properly calling componentWillUnmount
8
+
9
+ ### Patch Changes
10
+
11
+ - 7e2ae0ef: Bugfix for fraction button in v2 fraction keypad
12
+ - 1dc460c7: Add tests for mobile MathInput
13
+
14
+ ## 13.0.0
15
+
16
+ ### Major Changes
17
+
18
+ - 609aeb0a: Ensured that the multiplication symbol in our keypad matches the selected symbol from content.
19
+
20
+ ### Patch Changes
21
+
22
+ - 91f88d0b: Bugfix: v1 and v2 keypad using different FRAC configs
23
+ - 4aac71b3: Hide v2 mobile MathInput keypad when it's never been activated
24
+
3
25
  ## 12.1.1
4
26
 
5
27
  ### Patch Changes
@@ -8,7 +8,7 @@ export type Props = {
8
8
  cursorContext?: typeof CursorContext[keyof typeof CursorContext];
9
9
  showDismiss?: boolean;
10
10
  expandedView?: boolean;
11
- multiplicationDot?: boolean;
11
+ convertDotToTimes?: boolean;
12
12
  divisionKey?: boolean;
13
13
  trigonometry?: boolean;
14
14
  preAlgebra?: boolean;
@@ -23,6 +23,7 @@ type Props = {
23
23
  type State = {
24
24
  active: boolean;
25
25
  containerWidth: number;
26
+ hasBeenActivated: boolean;
26
27
  keypadConfig?: KeypadConfiguration;
27
28
  keyHandler?: KeyHandler;
28
29
  cursor?: Cursor;
@@ -34,7 +35,7 @@ declare class MobileKeypad extends React.Component<Props, State> implements Keyp
34
35
  hasMounted: boolean;
35
36
  state: State;
36
37
  componentDidMount(): void;
37
- componentWillUnMount(): void;
38
+ componentWillUnmount(): void;
38
39
  _resize: () => void;
39
40
  _throttleResizeHandler: () => void;
40
41
  activate: () => void;
@@ -5,7 +5,7 @@ type Props = {
5
5
  onClickKey: ClickKeyCallback;
6
6
  selectedPage: KeypadPageType;
7
7
  cursorContext?: typeof CursorContext[keyof typeof CursorContext];
8
- multiplicationDot?: boolean;
8
+ convertDotToTimes?: boolean;
9
9
  divisionKey?: boolean;
10
10
  };
11
11
  export default function SharedKeys(props: Props): JSX.Element;
package/dist/es/index.js CHANGED
@@ -4371,6 +4371,10 @@ const KeypadButton$2 = ({
4371
4371
  gridColumn: coord[0] + 1,
4372
4372
  gridRow: coord[1] + 1
4373
4373
  }, style)
4374
+ // Unfortunately the CDOT and TIMES buttons are identical in the DOM
4375
+ // apart from the ICON SVG, so we need to use testId.
4376
+ ,
4377
+ testId: keyConfig.id
4374
4378
  }, /*#__PURE__*/React.createElement(Clickable, {
4375
4379
  onClick: e => onClickKey(keyConfig.id, e),
4376
4380
  style: styles$g.clickable,
@@ -4558,7 +4562,7 @@ function FractionsPage(props) {
4558
4562
  coord: [3, 1],
4559
4563
  secondary: true
4560
4564
  }), /*#__PURE__*/React.createElement(KeypadButton$2, {
4561
- keyConfig: KeyConfigs.FRAC_INCLUSIVE,
4565
+ keyConfig: KeyConfigs.FRAC,
4562
4566
  onClickKey: onClickKey,
4563
4567
  coord: [3, 2],
4564
4568
  secondary: true
@@ -4869,7 +4873,7 @@ function SharedKeys(props) {
4869
4873
  onClickKey,
4870
4874
  cursorContext,
4871
4875
  divisionKey,
4872
- multiplicationDot,
4876
+ convertDotToTimes,
4873
4877
  selectedPage
4874
4878
  } = props;
4875
4879
  const cursorKeyConfig = getCursorContextConfig(cursorContext);
@@ -4887,12 +4891,12 @@ function SharedKeys(props) {
4887
4891
  coord: [5, 0],
4888
4892
  secondary: true
4889
4893
  }), /*#__PURE__*/React.createElement(KeypadButton$2, {
4890
- keyConfig: KeyConfigs.FRAC_INCLUSIVE,
4894
+ keyConfig: KeyConfigs.FRAC,
4891
4895
  onClickKey: onClickKey,
4892
4896
  coord: fractionCoord,
4893
4897
  secondary: true
4894
4898
  }), /*#__PURE__*/React.createElement(KeypadButton$2, {
4895
- keyConfig: multiplicationDot ? KeyConfigs.CDOT : KeyConfigs.TIMES,
4899
+ keyConfig: convertDotToTimes ? KeyConfigs.TIMES : KeyConfigs.CDOT,
4896
4900
  onClickKey: onClickKey,
4897
4901
  coord: [4, 1],
4898
4902
  secondary: true
@@ -4963,7 +4967,7 @@ function Keypad$2(props) {
4963
4967
  onClickKey,
4964
4968
  cursorContext,
4965
4969
  extraKeys,
4966
- multiplicationDot,
4970
+ convertDotToTimes,
4967
4971
  divisionKey,
4968
4972
  preAlgebra,
4969
4973
  logarithms,
@@ -5041,7 +5045,7 @@ function Keypad$2(props) {
5041
5045
  }), !fractionsOnly && /*#__PURE__*/React.createElement(SharedKeys, {
5042
5046
  onClickKey: onClickKey,
5043
5047
  cursorContext: cursorContext,
5044
- multiplicationDot: multiplicationDot,
5048
+ convertDotToTimes: convertDotToTimes,
5045
5049
  divisionKey: divisionKey,
5046
5050
  selectedPage: selectedPage
5047
5051
  })), expandedView && /*#__PURE__*/React.createElement(NavigationPad$1, {
@@ -5101,7 +5105,8 @@ class MobileKeypad extends React.Component {
5101
5105
  this.hasMounted = false;
5102
5106
  this.state = {
5103
5107
  active: false,
5104
- containerWidth: 0
5108
+ containerWidth: 0,
5109
+ hasBeenActivated: false
5105
5110
  };
5106
5111
  this._resize = () => {
5107
5112
  var _this$_containerRef$c;
@@ -5122,7 +5127,8 @@ class MobileKeypad extends React.Component {
5122
5127
  };
5123
5128
  this.activate = () => {
5124
5129
  this.setState({
5125
- active: true
5130
+ active: true,
5131
+ hasBeenActivated: true
5126
5132
  });
5127
5133
  };
5128
5134
  this.dismiss = () => {
@@ -5177,7 +5183,7 @@ class MobileKeypad extends React.Component {
5177
5183
  }
5178
5184
  }
5179
5185
  }
5180
- componentWillUnMount() {
5186
+ componentWillUnmount() {
5181
5187
  var _this$_containerResiz;
5182
5188
  window.removeEventListener("resize", this._throttleResizeHandler);
5183
5189
  window.removeEventListener("orientationchange", this._throttleResizeHandler);
@@ -5200,6 +5206,7 @@ class MobileKeypad extends React.Component {
5200
5206
  } = this.props;
5201
5207
  const {
5202
5208
  active,
5209
+ hasBeenActivated,
5203
5210
  containerWidth,
5204
5211
  cursor,
5205
5212
  keypadConfig
@@ -5209,9 +5216,22 @@ class MobileKeypad extends React.Component {
5209
5216
  styles$c.keypadContainer, active && styles$c.activeKeypadContainer,
5210
5217
  // styles passed as props
5211
5218
  ...(Array.isArray(style) ? style : [style])];
5219
+
5220
+ // If the keypad is yet to have ever been activated, we keep it invisible
5221
+ // so as to avoid, e.g., the keypad flashing at the bottom of the page
5222
+ // during the initial render.
5223
+ // Done inline (dynamicStyle) since stylesheets might not be loaded yet.
5224
+ let dynamicStyle = {};
5225
+ if (!active && !hasBeenActivated) {
5226
+ dynamicStyle = {
5227
+ visibility: "hidden"
5228
+ };
5229
+ }
5212
5230
  const isExpression = (keypadConfig == null ? void 0 : keypadConfig.keypadType) === "EXPRESSION";
5231
+ const convertDotToTimes = keypadConfig == null ? void 0 : keypadConfig.times;
5213
5232
  return /*#__PURE__*/React.createElement(View, {
5214
5233
  style: containerStyle,
5234
+ dynamicStyle: dynamicStyle,
5215
5235
  forwardRef: this._containerRef,
5216
5236
  ref: element => {
5217
5237
  if (!this.hasMounted && element) {
@@ -5238,7 +5258,7 @@ class MobileKeypad extends React.Component {
5238
5258
  onClickKey: key => this._handleClickKey(key),
5239
5259
  cursorContext: cursor == null ? void 0 : cursor.context,
5240
5260
  fractionsOnly: !isExpression,
5241
- multiplicationDot: isExpression,
5261
+ convertDotToTimes: convertDotToTimes,
5242
5262
  divisionKey: isExpression,
5243
5263
  trigonometry: isExpression,
5244
5264
  preAlgebra: isExpression,