@khanacademy/math-input 17.3.0 → 17.4.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.
- package/dist/components/aphrodite-css-transition-group/types.d.ts +1 -0
- package/dist/components/input/math-input.d.ts +5 -4
- package/dist/es/index.js +22 -10
- package/dist/es/index.js.map +1 -1
- package/dist/fake-react-native-web/text.d.ts +1 -0
- package/dist/index.js +19 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -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:
|
|
86
|
-
handleClick: (e: React.MouseEvent<HTMLDivElement>, keypadActive:
|
|
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
|
@@ -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.
|
|
20
|
+
const libVersion = "17.4.0";
|
|
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
|
-
|
|
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
|
-
|
|
2199
|
+
showInputFocusStyle,
|
|
2192
2200
|
handle
|
|
2193
2201
|
} = this.state;
|
|
2194
2202
|
const {
|
|
@@ -2196,7 +2204,7 @@ class MathInput extends React.Component {
|
|
|
2196
2204
|
} = this.props;
|
|
2197
2205
|
const innerStyle = _extends({}, inlineStyles.innerContainer, {
|
|
2198
2206
|
borderWidth: this.getBorderWidthPx()
|
|
2199
|
-
},
|
|
2207
|
+
}, showInputFocusStyle ? {
|
|
2200
2208
|
borderColor: Color.blue
|
|
2201
2209
|
} : {}, style);
|
|
2202
2210
|
|
|
@@ -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
|
-
})),
|
|
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,
|