@khanacademy/math-input 17.3.0 → 17.4.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.
@@ -1,3 +1,4 @@
1
+ /// <reference path="../../../types/aphrodite.d.ts" />
1
2
  import type { StyleType } from "@khanacademy/wonder-blocks-core";
2
3
  import type { CSSProperties } from "aphrodite";
3
4
  export type AnimationStyles = {
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import type { KeypadAPI } from "../../types";
2
+ import type { KeypadAPI, KeypadContextType } from "../../types";
3
3
  type Props = {
4
4
  keypadElement?: KeypadAPI;
5
5
  onBlur: () => void;
@@ -21,6 +21,7 @@ type HandleState = {
21
21
  type State = {
22
22
  focused: boolean;
23
23
  handle: HandleState;
24
+ showInputFocusStyle: boolean;
24
25
  };
25
26
  declare class MathInput extends React.Component<Props, State> {
26
27
  didTouchOutside: boolean | null | undefined;
@@ -48,7 +49,7 @@ declare class MathInput extends React.Component<Props, State> {
48
49
  _hideCursorHandle: () => void;
49
50
  _handleScroll: () => void;
50
51
  blur: () => void;
51
- focus: () => void;
52
+ focus: (setKeypadActive: KeypadContextType["setKeypadActive"]) => void;
52
53
  /**
53
54
  * Tries to determine which DOM node to place the cursor next to based on
54
55
  * where the user drags the cursor handle. If it finds a node it will
@@ -82,8 +83,8 @@ declare class MathInput extends React.Component<Props, State> {
82
83
  * @param {number} y - the y coordinate in the viewport
83
84
  */
84
85
  _insertCursorAtClosestNode: (arg1: number, arg2: number) => void;
85
- handleTouchStart: (e: React.TouchEvent<HTMLDivElement>, keypadActive: boolean, setKeypadActive: (keypadActive: boolean) => void) => void;
86
- handleClick: (e: React.MouseEvent<HTMLDivElement>, keypadActive: boolean, setKeypadActive: (keypadActive: boolean) => void) => void;
86
+ handleTouchStart: (e: React.TouchEvent<HTMLDivElement>, keypadActive: KeypadContextType["keypadActive"], setKeypadActive: KeypadContextType["setKeypadActive"]) => void;
87
+ handleClick: (e: React.MouseEvent<HTMLDivElement>, keypadActive: KeypadContextType["keypadActive"], setKeypadActive: KeypadContextType["setKeypadActive"]) => void;
87
88
  handleTouchMove: (arg1: React.TouchEvent<HTMLDivElement>) => void;
88
89
  handleTouchEnd: (arg1: React.TouchEvent<HTMLDivElement>) => void;
89
90
  /**
package/dist/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { addLibraryVersionToPerseusDebug } from '@khanacademy/perseus-core';
2
- import Color from '@khanacademy/wonder-blocks-color';
3
2
  import * as i18n from '@khanacademy/wonder-blocks-i18n';
4
3
  import { getDecimalSeparator, getLocale } from '@khanacademy/wonder-blocks-i18n';
4
+ import { color } from '@khanacademy/wonder-blocks-tokens';
5
5
  import { entries } from '@khanacademy/wonder-stuff-core';
6
6
  import { StyleSheet, css } from 'aphrodite';
7
7
  import * as React from 'react';
@@ -17,19 +17,21 @@ import PropTypes from 'prop-types';
17
17
 
18
18
  // This file is processed by a Rollup plugin (replace) to inject the production
19
19
  const libName = "@khanacademy/math-input";
20
- const libVersion = "17.3.0";
20
+ const libVersion = "17.4.1";
21
21
  addLibraryVersionToPerseusDebug(libName, libVersion);
22
22
 
23
23
  function _extends() {
24
24
  _extends = Object.assign ? Object.assign.bind() : function (target) {
25
25
  for (var i = 1; i < arguments.length; i++) {
26
26
  var source = arguments[i];
27
+
27
28
  for (var key in source) {
28
29
  if (Object.prototype.hasOwnProperty.call(source, key)) {
29
30
  target[key] = source[key];
30
31
  }
31
32
  }
32
33
  }
34
+
33
35
  return target;
34
36
  };
35
37
  return _extends.apply(this, arguments);
@@ -1499,6 +1501,7 @@ class MathInput extends React.Component {
1499
1501
  this._containerBounds = void 0;
1500
1502
  this.state = {
1501
1503
  focused: false,
1504
+ showInputFocusStyle: false,
1502
1505
  handle: {
1503
1506
  animateIntoPosition: false,
1504
1507
  visible: false,
@@ -1564,15 +1567,14 @@ class MathInput extends React.Component {
1564
1567
  };
1565
1568
  this.blur = () => {
1566
1569
  this.mathField.blur();
1567
- this.props.onBlur && this.props.onBlur();
1568
1570
  this.setState({
1569
- focused: false,
1571
+ showInputFocusStyle: false,
1570
1572
  handle: {
1571
1573
  visible: false
1572
1574
  }
1573
1575
  });
1574
1576
  };
1575
- this.focus = () => {
1577
+ this.focus = setKeypadActive => {
1576
1578
  var _this$props$keypadEle, _this$props;
1577
1579
  // Pass this component's handleKey method to the keypad so it can call
1578
1580
  // it whenever it needs to trigger a keypress action.
@@ -1600,8 +1602,10 @@ class MathInput extends React.Component {
1600
1602
  });
1601
1603
  this.mathField.focus();
1602
1604
  (_this$props = this.props) == null || _this$props.onFocus();
1605
+ setKeypadActive(true);
1603
1606
  this.setState({
1604
- focused: true
1607
+ focused: true,
1608
+ showInputFocusStyle: true
1605
1609
  }, () => {
1606
1610
  // NOTE(charlie): We use `setTimeout` to allow for a layout pass to
1607
1611
  // occur. Otherwise, the keypad is measured incorrectly. Ideally,
@@ -1814,7 +1818,7 @@ class MathInput extends React.Component {
1814
1818
 
1815
1819
  // Trigger a focus event, if we're not already focused.
1816
1820
  if (!this.state.focused) {
1817
- this.focus();
1821
+ this.focus(setKeypadActive);
1818
1822
  }
1819
1823
 
1820
1824
  // If the user clicked on the input using a mouse or tap gesture,
@@ -1852,7 +1856,7 @@ class MathInput extends React.Component {
1852
1856
 
1853
1857
  // Trigger a focus event, if we're not already focused.
1854
1858
  if (!this.state.focused) {
1855
- this.focus();
1859
+ this.focus(setKeypadActive);
1856
1860
  }
1857
1861
 
1858
1862
  // If the user clicked on the input using a mouse or tap gesture,
@@ -2125,7 +2129,10 @@ class MathInput extends React.Component {
2125
2129
  // dismissal. This code needs to be generalized to handle
2126
2130
  // multi-touch.
2127
2131
  if (this.state.focused && this.didTouchOutside && !this.didScroll) {
2132
+ var _this$props$onBlur, _this$props2;
2128
2133
  this.blur();
2134
+ this.mathField.blur();
2135
+ (_this$props$onBlur = (_this$props2 = this.props).onBlur) == null || _this$props$onBlur.call(_this$props2);
2129
2136
  }
2130
2137
  this.didTouchOutside = false;
2131
2138
  this.didScroll = false;
@@ -2150,6 +2157,7 @@ class MathInput extends React.Component {
2150
2157
  // in which case we don't want to dismiss the keypad on check.
2151
2158
  if (!isWithinKeypadBounds(x, y)) {
2152
2159
  this.blur();
2160
+ this.props.onBlur && this.props.onBlur();
2153
2161
  }
2154
2162
  }
2155
2163
  }
@@ -2188,7 +2196,7 @@ class MathInput extends React.Component {
2188
2196
  }
2189
2197
  render() {
2190
2198
  const {
2191
- focused,
2199
+ showInputFocusStyle,
2192
2200
  handle
2193
2201
  } = this.state;
2194
2202
  const {
@@ -2196,8 +2204,8 @@ class MathInput extends React.Component {
2196
2204
  } = this.props;
2197
2205
  const innerStyle = _extends({}, inlineStyles.innerContainer, {
2198
2206
  borderWidth: this.getBorderWidthPx()
2199
- }, focused ? {
2200
- borderColor: Color.blue
2207
+ }, showInputFocusStyle ? {
2208
+ borderColor: color.blue
2201
2209
  } : {}, style);
2202
2210
 
2203
2211
  // NOTE(diedra): This label explicitly refers to tapping because this field
@@ -2231,13 +2239,17 @@ class MathInput extends React.Component {
2231
2239
  ref: node => {
2232
2240
  this.inputRef = node;
2233
2241
  },
2242
+ onFocus: () => {
2243
+ this.focus(setKeypadActive);
2244
+ },
2245
+ onBlur: this.blur,
2234
2246
  onKeyUp: this.handleKeyUp
2235
2247
  }, /*#__PURE__*/React.createElement("div", {
2236
2248
  ref: node => {
2237
2249
  this._mathContainer = ReactDOM.findDOMNode(node);
2238
2250
  },
2239
2251
  style: innerStyle
2240
- })), focused && handle.visible && /*#__PURE__*/React.createElement(CursorHandle, _extends({}, handle, {
2252
+ })), showInputFocusStyle && handle.visible && /*#__PURE__*/React.createElement(CursorHandle, _extends({}, handle, {
2241
2253
  onTouchStart: this.onCursorHandleTouchStart,
2242
2254
  onTouchMove: this.onCursorHandleTouchMove,
2243
2255
  onTouchEnd: this.onCursorHandleTouchEnd,
@@ -2288,9 +2300,9 @@ const inlineStyles = {
2288
2300
  boxSizing: "border-box",
2289
2301
  position: "relative",
2290
2302
  borderStyle: "solid",
2291
- borderColor: Color.offBlack50,
2303
+ borderColor: color.offBlack50,
2292
2304
  borderRadius: 4,
2293
- color: Color.offBlack
2305
+ color: color.offBlack
2294
2306
  }
2295
2307
  };
2296
2308
 
@@ -2415,7 +2427,7 @@ const styles$6 = StyleSheet.create({
2415
2427
  marginLeft: 1
2416
2428
  },
2417
2429
  hovered: {
2418
- background: `linear-gradient(0deg, rgba(24, 101, 242, 0.32), rgba(24, 101, 242, 0.32)), ${Color.white}`,
2430
+ background: `linear-gradient(0deg, rgba(24, 101, 242, 0.32), rgba(24, 101, 242, 0.32)), ${color.white}`,
2419
2431
  border: "1px solid #1865F2"
2420
2432
  },
2421
2433
  pressed: {
@@ -2423,7 +2435,7 @@ const styles$6 = StyleSheet.create({
2423
2435
  },
2424
2436
  focused: {
2425
2437
  outline: "none",
2426
- border: `2px solid ${Color.blue}`
2438
+ border: `2px solid ${color.blue}`
2427
2439
  },
2428
2440
  innerBox: {
2429
2441
  boxSizing: "border-box",
@@ -2435,7 +2447,7 @@ const styles$6 = StyleSheet.create({
2435
2447
  alignItems: "center"
2436
2448
  },
2437
2449
  innerBoxPressed: {
2438
- border: `1px solid ${Color.white}`
2450
+ border: `1px solid ${color.white}`
2439
2451
  },
2440
2452
  activeIndicator: {
2441
2453
  position: "absolute",
@@ -2453,15 +2465,15 @@ const styles$6 = StyleSheet.create({
2453
2465
  });
2454
2466
  function imageTintColor(itemState, hovered, focused, pressed) {
2455
2467
  if (itemState === "disabled") {
2456
- return Color.offBlack64;
2468
+ return color.offBlack64;
2457
2469
  } else if (pressed) {
2458
- return Color.white;
2470
+ return color.white;
2459
2471
  } else if (itemState === "active") {
2460
- return Color.blue;
2472
+ return color.blue;
2461
2473
  } else if (hovered) {
2462
- return Color.blue;
2474
+ return color.blue;
2463
2475
  }
2464
- return Color.offBlack64;
2476
+ return color.offBlack64;
2465
2477
  }
2466
2478
  class TabbarItem extends React.Component {
2467
2479
  render() {
@@ -4540,9 +4552,9 @@ const styles$4 = StyleSheet.create({
4540
4552
  display: "flex",
4541
4553
  justifyContent: "center",
4542
4554
  alignItems: "center",
4543
- boxShadow: `0px 1px 0px ${Color.offBlack32}`,
4555
+ boxShadow: `0px 1px 0px ${color.offBlack32}`,
4544
4556
  boxSizing: "border-box",
4545
- background: Color.white,
4557
+ background: color.white,
4546
4558
  borderRadius: 4,
4547
4559
  borderWidth: 2,
4548
4560
  borderStyle: "solid",
@@ -4553,19 +4565,19 @@ const styles$4 = StyleSheet.create({
4553
4565
  padding: 1
4554
4566
  },
4555
4567
  hovered: {
4556
- borderColor: Color.blue,
4568
+ borderColor: color.blue,
4557
4569
  padding: 1,
4558
4570
  boxShadow: "none"
4559
4571
  },
4560
4572
  focused: {
4561
- borderColor: Color.blue,
4573
+ borderColor: color.blue,
4562
4574
  padding: 0,
4563
4575
  boxShadow: "none"
4564
4576
  },
4565
4577
  pressed: {
4566
4578
  border: "2px solid #1B50B3",
4567
4579
  padding: 0,
4568
- background: `linear-gradient(0deg, rgba(24, 101, 242, 0.32), rgba(24, 101, 242, 0.32)), ${Color.white}`,
4580
+ background: `linear-gradient(0deg, rgba(24, 101, 242, 0.32), rgba(24, 101, 242, 0.32)), ${color.white}`,
4569
4581
  boxShadow: "none"
4570
4582
  },
4571
4583
  outerBoxBase: {
@@ -4920,13 +4932,13 @@ const styles$3 = StyleSheet.create({
4920
4932
  width: "100%"
4921
4933
  },
4922
4934
  base: {
4923
- boxShadow: `0px 1px 0px ${Color.offBlack32}`,
4935
+ boxShadow: `0px 1px 0px ${color.offBlack32}`,
4924
4936
  display: "flex",
4925
4937
  justifyContent: "center",
4926
4938
  alignItems: "center",
4927
- background: Color.white,
4939
+ background: color.white,
4928
4940
  borderWidth: 2,
4929
- borderColor: Color.white
4941
+ borderColor: color.white
4930
4942
  },
4931
4943
  up: {
4932
4944
  borderTopLeftRadius: borderRadiusPx,
@@ -4945,16 +4957,16 @@ const styles$3 = StyleSheet.create({
4945
4957
  borderBottomLeftRadius: borderRadiusPx
4946
4958
  },
4947
4959
  hovered: {
4948
- borderColor: Color.blue,
4960
+ borderColor: color.blue,
4949
4961
  boxShadow: "none"
4950
4962
  },
4951
4963
  focused: {
4952
- borderColor: Color.blue,
4964
+ borderColor: color.blue,
4953
4965
  boxShadow: "none"
4954
4966
  },
4955
4967
  pressed: {
4956
4968
  border: "2px solid #1B50B3",
4957
- background: `linear-gradient(0deg, rgba(24, 101, 242, 0.32), rgba(24, 101, 242, 0.32)), ${Color.white}`,
4969
+ background: `linear-gradient(0deg, rgba(24, 101, 242, 0.32), rgba(24, 101, 242, 0.32)), ${color.white}`,
4958
4970
  boxShadow: "none"
4959
4971
  }
4960
4972
  });
@@ -5004,7 +5016,7 @@ const styles$2 = StyleSheet.create({
5004
5016
  spacer: {
5005
5017
  gridColumn: 2,
5006
5018
  gridRow: 2,
5007
- background: Color.white
5019
+ background: color.white
5008
5020
  }
5009
5021
  });
5010
5022
 
@@ -5198,11 +5210,11 @@ const styles$1 = StyleSheet.create({
5198
5210
  alignItems: "center"
5199
5211
  },
5200
5212
  wrapper: {
5201
- background: Color.white
5213
+ background: color.white
5202
5214
  },
5203
5215
  expandedWrapper: {
5204
5216
  borderWidth: "1px 1px 0 1px",
5205
- borderColor: Color.offBlack32,
5217
+ borderColor: color.offBlack32,
5206
5218
  maxWidth: expandedViewThreshold,
5207
5219
  borderRadius: "3px 3px 0 0"
5208
5220
  },