@khanacademy/math-input 17.0.4 → 17.0.6
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/input/math-wrapper.d.ts +2 -2
- package/dist/components/input/mathquill-types.d.ts +49 -6
- package/dist/es/index.js +8 -6
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/.eslintrc.js +0 -18
- package/CHANGELOG.md +0 -660
- package/less/main.less +0 -2
- package/less/overrides.less +0 -122
- package/src/components/__tests__/integration.test.tsx +0 -300
- package/src/components/aphrodite-css-transition-group/index.tsx +0 -78
- package/src/components/aphrodite-css-transition-group/transition-child.tsx +0 -192
- package/src/components/aphrodite-css-transition-group/types.ts +0 -20
- package/src/components/aphrodite-css-transition-group/util.ts +0 -97
- package/src/components/input/__tests__/context-tracking.test.ts +0 -176
- package/src/components/input/__tests__/mathquill-helpers.test.ts +0 -105
- package/src/components/input/__tests__/mathquill.test.ts +0 -747
- package/src/components/input/__tests__/test-math-wrapper.ts +0 -29
- package/src/components/input/cursor-contexts.ts +0 -37
- package/src/components/input/cursor-handle.tsx +0 -137
- package/src/components/input/cursor-styles.ts +0 -10
- package/src/components/input/drag-listener.ts +0 -79
- package/src/components/input/math-input.tsx +0 -1036
- package/src/components/input/math-wrapper.ts +0 -189
- package/src/components/input/mathquill-helpers.ts +0 -262
- package/src/components/input/mathquill-instance.ts +0 -106
- package/src/components/input/mathquill-types.ts +0 -32
- package/src/components/input/scroll-into-view.ts +0 -65
- package/src/components/key-handlers/__tests__/handle-jump-out.test.ts +0 -94
- package/src/components/key-handlers/handle-arrow.ts +0 -70
- package/src/components/key-handlers/handle-backspace.ts +0 -277
- package/src/components/key-handlers/handle-exponent.ts +0 -53
- package/src/components/key-handlers/handle-jump-out.ts +0 -107
- package/src/components/key-handlers/key-translator.ts +0 -222
- package/src/components/keypad/__tests__/__snapshots__/keypad.test.tsx.snap +0 -1913
- package/src/components/keypad/__tests__/__snapshots__/mobile-keypad.test.tsx.snap +0 -600
- package/src/components/keypad/__tests__/keypad-button.test.tsx +0 -84
- package/src/components/keypad/__tests__/keypad-v2-mathquill.test.tsx +0 -304
- package/src/components/keypad/__tests__/keypad-v2.cypress.ts +0 -16
- package/src/components/keypad/__tests__/keypad.test.tsx +0 -321
- package/src/components/keypad/__tests__/mobile-keypad.test.tsx +0 -115
- package/src/components/keypad/__tests__/test-data-tabs.ts +0 -21
- package/src/components/keypad/button-assets.tsx +0 -1880
- package/src/components/keypad/index.tsx +0 -2
- package/src/components/keypad/keypad-button.stories.tsx +0 -81
- package/src/components/keypad/keypad-button.tsx +0 -124
- package/src/components/keypad/keypad-mathquill.stories.tsx +0 -109
- package/src/components/keypad/keypad-pages/extras-page.tsx +0 -35
- package/src/components/keypad/keypad-pages/fractions-page.tsx +0 -125
- package/src/components/keypad/keypad-pages/geometry-page.tsx +0 -34
- package/src/components/keypad/keypad-pages/keypad-pages.stories.tsx +0 -37
- package/src/components/keypad/keypad-pages/numbers-page.tsx +0 -94
- package/src/components/keypad/keypad-pages/operators-page.tsx +0 -117
- package/src/components/keypad/keypad.tsx +0 -233
- package/src/components/keypad/mobile-keypad-internals.tsx +0 -240
- package/src/components/keypad/mobile-keypad.tsx +0 -24
- package/src/components/keypad/navigation-button.tsx +0 -127
- package/src/components/keypad/navigation-pad.stories.tsx +0 -26
- package/src/components/keypad/navigation-pad.tsx +0 -67
- package/src/components/keypad/shared-keys.tsx +0 -109
- package/src/components/keypad/utils.ts +0 -34
- package/src/components/keypad-context.tsx +0 -70
- package/src/components/prop-types.ts +0 -16
- package/src/components/tabbar/__tests__/tabbar.test.tsx +0 -105
- package/src/components/tabbar/icons.tsx +0 -122
- package/src/components/tabbar/index.ts +0 -1
- package/src/components/tabbar/item.tsx +0 -146
- package/src/components/tabbar/tabbar.stories.tsx +0 -83
- package/src/components/tabbar/tabbar.tsx +0 -65
- package/src/data/key-configs.ts +0 -770
- package/src/data/keys.ts +0 -123
- package/src/enums.ts +0 -27
- package/src/fake-react-native-web/index.ts +0 -11
- package/src/fake-react-native-web/text.tsx +0 -55
- package/src/fake-react-native-web/view.tsx +0 -91
- package/src/full-keypad.stories.tsx +0 -142
- package/src/full-mobile-input.stories.tsx +0 -115
- package/src/index.ts +0 -52
- package/src/types.ts +0 -70
- package/src/utils.test.ts +0 -33
- package/src/utils.ts +0 -61
- package/src/version.ts +0 -10
- package/tsconfig-build.json +0 -11
- package/tsconfig-build.tsbuildinfo +0 -1
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import MathWrapper from "../math-wrapper";
|
|
2
|
-
|
|
3
|
-
export default class TestMathWrapper extends MathWrapper {
|
|
4
|
-
getContent() {
|
|
5
|
-
return this.mathField.latex();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
selectAll() {
|
|
9
|
-
this.mathField.select();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
clearSelection() {
|
|
13
|
-
this.mathField.clearSelection();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
moveToStart() {
|
|
17
|
-
this.mathField.moveToLeftEnd();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
isSelected() {
|
|
21
|
-
const selection = this.getSelection();
|
|
22
|
-
|
|
23
|
-
if (selection) {
|
|
24
|
-
return selection.ends[-1][-1] === 0 && selection.ends[1][1] === 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enum that defines the various contexts in which a cursor can exist. The
|
|
3
|
-
* active context is determined first by looking at the cursor's siblings (e.g.,
|
|
4
|
-
* for the `BEFORE_FRACTION` context), and then at its direct parent. Though a
|
|
5
|
-
* cursor could in theory be nested in multiple contexts, we only care about the
|
|
6
|
-
* immediate context.
|
|
7
|
-
*
|
|
8
|
-
* TODO(charlie): Add a context to represent being inside of a radical. Right
|
|
9
|
-
* now, we show the dismiss button rather than allowing the user to jump out of
|
|
10
|
-
* the radical.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export enum CursorContext {
|
|
14
|
-
// The cursor is not in any of the other viable contexts.
|
|
15
|
-
NONE = "NONE",
|
|
16
|
-
|
|
17
|
-
// The cursor is within a set of parentheses.
|
|
18
|
-
IN_PARENS = "IN_PARENS",
|
|
19
|
-
|
|
20
|
-
// The cursor is within a superscript (e.g., an exponent).
|
|
21
|
-
IN_SUPER_SCRIPT = "IN_SUPER_SCRIPT",
|
|
22
|
-
|
|
23
|
-
// The cursor is within a subscript (e.g., the base of a custom logarithm).
|
|
24
|
-
IN_SUB_SCRIPT = "IN_SUB_SCRIPT",
|
|
25
|
-
|
|
26
|
-
// The cursor is in the numerator of a fraction.
|
|
27
|
-
IN_NUMERATOR = "IN_NUMERATOR",
|
|
28
|
-
|
|
29
|
-
// The cursor is in the denominator of a fraction.
|
|
30
|
-
IN_DENOMINATOR = "IN_DENOMINATOR",
|
|
31
|
-
|
|
32
|
-
// The cursor is sitting before a fraction; that is, the cursor is within
|
|
33
|
-
// what looks to be a mixed number preceding a fraction. This will only be
|
|
34
|
-
// the case when the only math between the cursor and the fraction to its
|
|
35
|
-
// write is non-leaf math (numbers and variables).
|
|
36
|
-
BEFORE_FRACTION = "BEFORE_FRACTION",
|
|
37
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Renders the green tear-shaped handle under the cursor.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as React from "react";
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
cursorHandleRadiusPx,
|
|
9
|
-
cursorHandleDistanceMultiplier,
|
|
10
|
-
} from "./cursor-styles";
|
|
11
|
-
|
|
12
|
-
const touchTargetRadiusPx = 2 * cursorHandleRadiusPx;
|
|
13
|
-
const touchTargetHeightPx = 2 * touchTargetRadiusPx;
|
|
14
|
-
const touchTargetWidthPx = 2 * touchTargetRadiusPx;
|
|
15
|
-
|
|
16
|
-
const cursorRadiusPx = cursorHandleRadiusPx;
|
|
17
|
-
const cursorHeightPx = cursorHandleDistanceMultiplier * (cursorRadiusPx * 4);
|
|
18
|
-
const cursorWidthPx = 4 * cursorRadiusPx;
|
|
19
|
-
|
|
20
|
-
type Props = {
|
|
21
|
-
animateIntoPosition: boolean;
|
|
22
|
-
onTouchCancel: (arg1: React.TouchEvent<HTMLSpanElement>) => void;
|
|
23
|
-
onTouchEnd: (arg1: React.TouchEvent<HTMLSpanElement>) => void;
|
|
24
|
-
onTouchMove: (arg1: React.TouchEvent<HTMLSpanElement>) => void;
|
|
25
|
-
onTouchStart: (arg1: React.TouchEvent<HTMLSpanElement>) => void;
|
|
26
|
-
visible: boolean;
|
|
27
|
-
x: number;
|
|
28
|
-
y: number;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type DefaultProps = {
|
|
32
|
-
animateIntoPosition: Props["animateIntoPosition"];
|
|
33
|
-
visible: Props["visible"];
|
|
34
|
-
x: Props["x"];
|
|
35
|
-
y: Props["y"];
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
class CursorHandle extends React.Component<Props> {
|
|
39
|
-
static defaultProps: DefaultProps = {
|
|
40
|
-
animateIntoPosition: false,
|
|
41
|
-
visible: false,
|
|
42
|
-
x: 0,
|
|
43
|
-
y: 0,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
render(): React.ReactNode {
|
|
47
|
-
const {x, y, animateIntoPosition} = this.props;
|
|
48
|
-
|
|
49
|
-
const animationStyle = animateIntoPosition
|
|
50
|
-
? {
|
|
51
|
-
transitionDuration: "100ms",
|
|
52
|
-
transitionProperty: "transform",
|
|
53
|
-
}
|
|
54
|
-
: {};
|
|
55
|
-
const transformString = `translate(${x}px, ${y}px)`;
|
|
56
|
-
|
|
57
|
-
const outerStyle = {
|
|
58
|
-
position: "absolute",
|
|
59
|
-
// This is essentially webapp's interactiveComponent + 1.
|
|
60
|
-
// TODO(charlie): Pull in those styles somehow to avoid breakages.
|
|
61
|
-
zIndex: 4,
|
|
62
|
-
left: -touchTargetWidthPx / 2,
|
|
63
|
-
top: 0,
|
|
64
|
-
transform: transformString,
|
|
65
|
-
width: touchTargetWidthPx,
|
|
66
|
-
height: touchTargetHeightPx,
|
|
67
|
-
// Touch events that start on the cursor shouldn't be allowed to
|
|
68
|
-
// produce page scrolls.
|
|
69
|
-
touchAction: "none",
|
|
70
|
-
...animationStyle,
|
|
71
|
-
} as const;
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<span
|
|
75
|
-
style={outerStyle}
|
|
76
|
-
onTouchStart={this.props.onTouchStart}
|
|
77
|
-
onTouchMove={this.props.onTouchMove}
|
|
78
|
-
onTouchEnd={this.props.onTouchEnd}
|
|
79
|
-
onTouchCancel={this.props.onTouchCancel}
|
|
80
|
-
>
|
|
81
|
-
<svg
|
|
82
|
-
fill="none"
|
|
83
|
-
width={cursorWidthPx}
|
|
84
|
-
height={cursorHeightPx}
|
|
85
|
-
viewBox={`0 0 ${cursorWidthPx} ${cursorHeightPx}`}
|
|
86
|
-
>
|
|
87
|
-
<filter
|
|
88
|
-
id="math-input_cursor"
|
|
89
|
-
colorInterpolationFilters="sRGB"
|
|
90
|
-
filterUnits="userSpaceOnUse"
|
|
91
|
-
height={cursorHeightPx * 0.87} // ~40
|
|
92
|
-
width={cursorWidthPx * 0.82} // ~36
|
|
93
|
-
x="4"
|
|
94
|
-
y="0"
|
|
95
|
-
>
|
|
96
|
-
<feFlood floodOpacity="0" result="BackgroundImageFix" />
|
|
97
|
-
<feColorMatrix
|
|
98
|
-
in="SourceAlpha"
|
|
99
|
-
type="matrix"
|
|
100
|
-
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
|
|
101
|
-
/>
|
|
102
|
-
<feOffset dy="4" />
|
|
103
|
-
<feGaussianBlur stdDeviation="4" />
|
|
104
|
-
<feColorMatrix
|
|
105
|
-
type="matrix"
|
|
106
|
-
values="0 0 0 0 0.129412 0 0 0 0 0.141176 0 0 0 0 0.172549 0 0 0 0.08 0"
|
|
107
|
-
/>
|
|
108
|
-
<feBlend
|
|
109
|
-
in2="BackgroundImageFix"
|
|
110
|
-
mode="normal"
|
|
111
|
-
result="effect1_dropShadow"
|
|
112
|
-
/>
|
|
113
|
-
<feBlend
|
|
114
|
-
in="SourceGraphic"
|
|
115
|
-
in2="effect1_dropShadow"
|
|
116
|
-
mode="normal"
|
|
117
|
-
result="shape"
|
|
118
|
-
/>
|
|
119
|
-
</filter>
|
|
120
|
-
<g filter="url(#math-input_cursor)">
|
|
121
|
-
<path
|
|
122
|
-
d="m22 4-7.07 7.0284c-1.3988 1.3901-2.3515 3.1615-2.7376 5.09-.3861 1.9284-.1883 3.9274.5685 5.7441s2.0385 3.3694 3.6831 4.4619c1.6445 1.0925 3.5781 1.6756 5.556 1.6756s3.9115-.5831 5.556-1.6756c1.6446-1.0925 2.9263-2.6452 3.6831-4.4619s.9546-3.8157.5685-5.7441c-.3861-1.9285-1.3388-3.6999-2.7376-5.09z"
|
|
123
|
-
fill="#1865f2"
|
|
124
|
-
/>
|
|
125
|
-
</g>
|
|
126
|
-
<path
|
|
127
|
-
d="m14.9301 10.4841 7.0699-7.06989 7.0699 7.06989.0001.0001c1.3988 1.3984 2.3515 3.1802 2.7376 5.1201s.1883 3.9507-.5685 5.7782c-.7568 1.8274-2.0385 3.3894-3.6831 4.4883-1.6445 1.099-3.5781 1.6855-5.556 1.6855s-3.9115-.5865-5.556-1.6855c-1.6446-1.0989-2.9263-2.6609-3.6831-4.4883-.7568-1.8275-.9546-3.8383-.5685-5.7782s1.3388-3.7217 2.7376-5.1201z"
|
|
128
|
-
stroke="#fff"
|
|
129
|
-
strokeWidth="2"
|
|
130
|
-
/>
|
|
131
|
-
</svg>
|
|
132
|
-
</span>
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export default CursorHandle;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common parameters used to style components.
|
|
3
|
-
*/
|
|
4
|
-
export const cursorHandleRadiusPx = 11;
|
|
5
|
-
|
|
6
|
-
// The amount to multiply the radius by to get the distance from the
|
|
7
|
-
// center to the tip of the cursor handle. The cursor is a circle with
|
|
8
|
-
// one quadrant replace with a square. The hypotenuse of the square is
|
|
9
|
-
// 1.045 times the radius of the circle.
|
|
10
|
-
export const cursorHandleDistanceMultiplier = 1.045;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A gesture recognizer that detects 'drags', crudely defined as either scrolls
|
|
3
|
-
* or touches that move a sufficient distance.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// The 'slop' factor, after which we consider the use to be dragging. The value
|
|
7
|
-
// is taken from the Android SDK. It won't be robust to page zoom and the like,
|
|
8
|
-
// but it should be good enough for our purposes.
|
|
9
|
-
const touchSlopPx = 8;
|
|
10
|
-
|
|
11
|
-
class DragListener {
|
|
12
|
-
_scrollListener: () => void;
|
|
13
|
-
_moveListener: (evt: TouchEvent) => void;
|
|
14
|
-
_endAndCancelListener: (evt: TouchEvent) => void;
|
|
15
|
-
|
|
16
|
-
constructor(onDrag, initialEvent) {
|
|
17
|
-
// We detect drags in two ways. First, by listening for the window
|
|
18
|
-
// scroll event (we consider any legitimate scroll to be a drag).
|
|
19
|
-
this._scrollListener = () => {
|
|
20
|
-
onDrag();
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// And second, by listening for touch moves and tracking the each
|
|
24
|
-
// finger's displacement. This allows us to track, e.g., when the user
|
|
25
|
-
// scrolls within an individual view.
|
|
26
|
-
const touchLocationsById = {};
|
|
27
|
-
for (let i = 0; i < initialEvent.changedTouches.length; i++) {
|
|
28
|
-
const touch = initialEvent.changedTouches[i];
|
|
29
|
-
touchLocationsById[touch.identifier] = [
|
|
30
|
-
touch.clientX,
|
|
31
|
-
touch.clientY,
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this._moveListener = (evt) => {
|
|
36
|
-
for (let i = 0; i < evt.changedTouches.length; i++) {
|
|
37
|
-
const touch = evt.changedTouches[i];
|
|
38
|
-
const initialTouchLocation =
|
|
39
|
-
touchLocationsById[touch.identifier];
|
|
40
|
-
if (initialTouchLocation) {
|
|
41
|
-
const touchLocation = [touch.clientX, touch.clientY];
|
|
42
|
-
const dx = touchLocation[0] - initialTouchLocation[0];
|
|
43
|
-
const dy = touchLocation[1] - initialTouchLocation[1];
|
|
44
|
-
|
|
45
|
-
const squaredDist = dx * dx + dy * dy;
|
|
46
|
-
const squaredTouchSlop = touchSlopPx * touchSlopPx;
|
|
47
|
-
|
|
48
|
-
if (squaredDist > squaredTouchSlop) {
|
|
49
|
-
onDrag();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Clean-up any terminated gestures, since some browsers reuse
|
|
56
|
-
// identifiers.
|
|
57
|
-
this._endAndCancelListener = (evt) => {
|
|
58
|
-
for (let i = 0; i < evt.changedTouches.length; i++) {
|
|
59
|
-
delete touchLocationsById[evt.changedTouches[i].identifier];
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
attach() {
|
|
65
|
-
window.addEventListener("scroll", this._scrollListener);
|
|
66
|
-
window.addEventListener("touchmove", this._moveListener);
|
|
67
|
-
window.addEventListener("touchend", this._endAndCancelListener);
|
|
68
|
-
window.addEventListener("touchcancel", this._endAndCancelListener);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
detach() {
|
|
72
|
-
window.removeEventListener("scroll", this._scrollListener);
|
|
73
|
-
window.removeEventListener("touchmove", this._moveListener);
|
|
74
|
-
window.removeEventListener("touchend", this._endAndCancelListener);
|
|
75
|
-
window.removeEventListener("touchcancel", this._endAndCancelListener);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default DragListener;
|