@pie-lib/math-input 6.11.5-next.0 → 6.11.5-next.1844
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.json +6 -1536
- package/CHANGELOG.md +178 -117
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/horizontal-keypad.js +9 -3
- package/lib/horizontal-keypad.js.map +1 -1
- package/lib/index.js +10 -14
- package/lib/index.js.map +1 -1
- package/lib/keypad/index.js +95 -24
- package/lib/keypad/index.js.map +1 -1
- package/lib/keys/geometry.js +4 -2
- package/lib/keys/geometry.js.map +1 -1
- package/lib/keys/grades.js +12 -0
- package/lib/keys/grades.js.map +1 -1
- package/lib/keys/log.js +1 -1
- package/lib/keys/log.js.map +1 -1
- package/lib/mq/common-mq-styles.js +110 -0
- package/lib/mq/common-mq-styles.js.map +1 -0
- package/lib/mq/index.js +8 -0
- package/lib/mq/index.js.map +1 -1
- package/lib/mq/input.js +12 -10
- package/lib/mq/input.js.map +1 -1
- package/lib/mq/static.js +198 -75
- package/lib/mq/static.js.map +1 -1
- package/lib/shared/constants.js +16 -0
- package/lib/updateSpans.js +23 -0
- package/lib/updateSpans.js.map +1 -0
- package/package.json +4 -2
- package/src/__tests__/__snapshots__/math-input-test.jsx.snap +152 -0
- package/src/__tests__/math-input-test.jsx +85 -0
- package/src/horizontal-keypad.jsx +14 -1
- package/src/index.jsx +1 -10
- package/src/keypad/__tests__/__snapshots__/index.test.jsx.snap +193 -0
- package/src/keypad/__tests__/index.test.jsx +24 -0
- package/src/keypad/__tests__/keys-layout.test.js +15 -0
- package/src/keypad/index.jsx +99 -15
- package/src/keys/__tests__/utils.test.js +57 -0
- package/src/keys/geometry.js +6 -2
- package/src/keys/grades.js +11 -0
- package/src/keys/log.js +1 -1
- package/src/mq/__tests__/__snapshots__/input.test.jsx.snap +9 -0
- package/src/mq/__tests__/input.test.jsx +92 -0
- package/src/mq/__tests__/static.test.jsx +57 -0
- package/src/mq/common-mq-styles.js +105 -0
- package/src/mq/index.js +2 -1
- package/src/mq/input.jsx +22 -9
- package/src/mq/static.jsx +142 -13
- package/src/updateSpans.js +15 -0
- package/README.md +0 -27
package/src/keypad/index.jsx
CHANGED
|
@@ -6,13 +6,16 @@ import { withStyles } from '@material-ui/core/styles';
|
|
|
6
6
|
import classNames from 'classnames';
|
|
7
7
|
import { lighten, fade } from '@material-ui/core/styles/colorManipulator';
|
|
8
8
|
import green from '@material-ui/core/colors/green';
|
|
9
|
-
import { sortKeys } from './keys-layout';
|
|
10
|
-
import * as mq from '../mq';
|
|
11
|
-
import { baseSet } from '../keys';
|
|
12
9
|
import debug from 'debug';
|
|
13
10
|
import _ from 'lodash';
|
|
14
11
|
import MathQuill from '@pie-framework/mathquill';
|
|
15
12
|
|
|
13
|
+
import * as mq from '../mq';
|
|
14
|
+
import { baseSet } from '../keys';
|
|
15
|
+
import editableHtmlConstants from '../../../editable-html/src/constants';
|
|
16
|
+
import { commonMqKeyboardStyles } from '../mq/common-mq-styles';
|
|
17
|
+
import { sortKeys } from './keys-layout';
|
|
18
|
+
|
|
16
19
|
const log = debug('pie-lib:math-inline:keypad');
|
|
17
20
|
|
|
18
21
|
const LatexButton = withStyles((theme) => ({
|
|
@@ -37,6 +40,9 @@ const LatexButton = withStyles((theme) => ({
|
|
|
37
40
|
'& .mq-overline .mq-overline-inner': {
|
|
38
41
|
borderTop: '2px solid black',
|
|
39
42
|
},
|
|
43
|
+
'& .mq-non-leaf.mq-overline': {
|
|
44
|
+
borderTop: 'none !important', // fixing PD-4873 - in OT, it has border-top 1px and adds extra line
|
|
45
|
+
},
|
|
40
46
|
'& .mq-overarrow': {
|
|
41
47
|
width: '30px',
|
|
42
48
|
marginTop: '0 !important',
|
|
@@ -47,11 +53,12 @@ const LatexButton = withStyles((theme) => ({
|
|
|
47
53
|
top: '0px !important',
|
|
48
54
|
'& *': {
|
|
49
55
|
lineHeight: '1 !important',
|
|
56
|
+
borderTop: 'none !important', // fixing PD-4873 - in OT, it has border-top 1px and adds extra line,
|
|
50
57
|
},
|
|
51
58
|
'&:before': {
|
|
52
59
|
fontSize: '80%',
|
|
53
|
-
left: 'calc(-13%)',
|
|
54
|
-
top: '-0.31em',
|
|
60
|
+
left: 'calc(-13%) !important',
|
|
61
|
+
top: '-0.31em !important',
|
|
55
62
|
},
|
|
56
63
|
'&:after': {
|
|
57
64
|
fontSize: '80% !important',
|
|
@@ -74,8 +81,8 @@ const LatexButton = withStyles((theme) => ({
|
|
|
74
81
|
},
|
|
75
82
|
'&.mq-arrow-right:before': {
|
|
76
83
|
fontSize: '80%',
|
|
77
|
-
right: 'calc(-13%)',
|
|
78
|
-
top: '-0.26em',
|
|
84
|
+
right: 'calc(-13%) !important',
|
|
85
|
+
top: '-0.26em !important',
|
|
79
86
|
},
|
|
80
87
|
'& .mq-overarrow-inner': {
|
|
81
88
|
border: 'none !important',
|
|
@@ -111,6 +118,9 @@ const LatexButton = withStyles((theme) => ({
|
|
|
111
118
|
},
|
|
112
119
|
'& .mq-overarc': {
|
|
113
120
|
borderTop: '2px solid black !important',
|
|
121
|
+
'& .mq-overline': {
|
|
122
|
+
borderTop: 'none !important', // fixing PD-4873 - in OT, it has border-top 1px and adds extra line
|
|
123
|
+
},
|
|
114
124
|
'& .mq-overline-inner': {
|
|
115
125
|
borderTop: 'none !important',
|
|
116
126
|
paddingTop: '0 !important',
|
|
@@ -118,7 +128,7 @@ const LatexButton = withStyles((theme) => ({
|
|
|
118
128
|
},
|
|
119
129
|
},
|
|
120
130
|
parallelButton: {
|
|
121
|
-
fontStyle: 'italic',
|
|
131
|
+
fontStyle: 'italic !important',
|
|
122
132
|
},
|
|
123
133
|
leftRightArrowButton: {
|
|
124
134
|
'& .mq-overarrow.mq-arrow-both': {
|
|
@@ -183,22 +193,83 @@ export class KeyPad extends React.Component {
|
|
|
183
193
|
static propTypes = {
|
|
184
194
|
classes: PropTypes.object.isRequired,
|
|
185
195
|
className: PropTypes.string,
|
|
196
|
+
controlledKeypadMode: PropTypes.bool,
|
|
186
197
|
baseSet: PropTypes.array,
|
|
187
198
|
additionalKeys: PropTypes.array,
|
|
188
199
|
layoutForKeyPad: PropTypes.object,
|
|
189
200
|
onPress: PropTypes.func.isRequired,
|
|
190
201
|
onFocus: PropTypes.func,
|
|
191
202
|
noDecimal: PropTypes.bool,
|
|
192
|
-
|
|
203
|
+
setKeypadInteraction: PropTypes.func,
|
|
204
|
+
mode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
193
205
|
};
|
|
194
206
|
static defaultProps = {
|
|
195
207
|
baseSet: baseSet,
|
|
196
208
|
noDecimal: false,
|
|
197
209
|
};
|
|
198
210
|
|
|
211
|
+
constructor(props) {
|
|
212
|
+
super(props);
|
|
213
|
+
this.keypadRef = React.createRef();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
componentDidMount() {
|
|
217
|
+
const keyPadElement = this.keypadRef?.current;
|
|
218
|
+
const mainContainer = keyPadElement?.closest(`.${editableHtmlConstants.MAIN_CONTAINER_CLASS}`);
|
|
219
|
+
const currentToolbar = keyPadElement?.closest('.pie-toolbar');
|
|
220
|
+
|
|
221
|
+
// need only for math keyboard so we need also controlledKeypadMode
|
|
222
|
+
if (this.props.controlledKeypadMode && mainContainer && currentToolbar) {
|
|
223
|
+
const mainContainerPosition = mainContainer.getBoundingClientRect();
|
|
224
|
+
const currentToolbarPosition = currentToolbar.getBoundingClientRect();
|
|
225
|
+
const difference =
|
|
226
|
+
mainContainerPosition.top +
|
|
227
|
+
mainContainerPosition.height -
|
|
228
|
+
(currentToolbarPosition.top + currentToolbarPosition.height);
|
|
229
|
+
if (difference < 0) {
|
|
230
|
+
const totalHeight = mainContainerPosition.height + mainContainerPosition.top - difference;
|
|
231
|
+
// increase the height of the main container if keyboard needs it
|
|
232
|
+
if (mainContainer) {
|
|
233
|
+
mainContainer.style.height = `${totalHeight}px`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (keyPadElement) {
|
|
239
|
+
keyPadElement.addEventListener('touchstart', this.handleKeypadInteraction, true);
|
|
240
|
+
keyPadElement.addEventListener('mousedown', this.handleKeypadInteraction, true);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
componentWillUnmount() {
|
|
245
|
+
const keyPadElement = this.keypadRef?.current;
|
|
246
|
+
// need only for math keyboard
|
|
247
|
+
if (this.props.controlledKeypadMode && keyPadElement) {
|
|
248
|
+
const mainContainer = keyPadElement.closest(`.${editableHtmlConstants.MAIN_CONTAINER_CLASS}`);
|
|
249
|
+
|
|
250
|
+
if (mainContainer) {
|
|
251
|
+
mainContainer.style.height = 'unset';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (keyPadElement) {
|
|
256
|
+
keyPadElement.removeEventListener('touchstart', this.handleKeypadInteraction, true);
|
|
257
|
+
keyPadElement.removeEventListener('mousedown', this.handleKeypadInteraction, true);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
handleKeypadInteraction = () => {
|
|
262
|
+
// Check if the setKeypadInteraction prop is available, which is used for both
|
|
263
|
+
// the language keypad and the special characters keypad
|
|
264
|
+
if (this.props.setKeypadInteraction) {
|
|
265
|
+
this.props.setKeypadInteraction(true);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
199
269
|
buttonClick = (key) => {
|
|
200
270
|
log('[buttonClick]', key);
|
|
201
271
|
const { onPress } = this.props;
|
|
272
|
+
|
|
202
273
|
onPress(key);
|
|
203
274
|
};
|
|
204
275
|
|
|
@@ -234,7 +305,12 @@ export class KeyPad extends React.Component {
|
|
|
234
305
|
};
|
|
235
306
|
|
|
236
307
|
return (
|
|
237
|
-
<div
|
|
308
|
+
<div
|
|
309
|
+
ref={this.keypadRef}
|
|
310
|
+
className={classNames(classes.keys, className, classes[mode])}
|
|
311
|
+
style={style}
|
|
312
|
+
onFocus={onFocus}
|
|
313
|
+
>
|
|
238
314
|
{allKeys.map((k, index) => {
|
|
239
315
|
const onClick = this.buttonClick.bind(this, k);
|
|
240
316
|
|
|
@@ -271,7 +347,12 @@ export class KeyPad extends React.Component {
|
|
|
271
347
|
|
|
272
348
|
if (k.label) {
|
|
273
349
|
return (
|
|
274
|
-
<Button
|
|
350
|
+
<Button
|
|
351
|
+
key={index}
|
|
352
|
+
{...common}
|
|
353
|
+
className={classNames(common.className, { [classes.deleteButton]: k.label === '⌫' })}
|
|
354
|
+
aria-label={k.ariaLabel ? k.ariaLabel : k.name || k.label}
|
|
355
|
+
>
|
|
275
356
|
{k.label}
|
|
276
357
|
</Button>
|
|
277
358
|
);
|
|
@@ -292,9 +373,7 @@ export class KeyPad extends React.Component {
|
|
|
292
373
|
|
|
293
374
|
const styles = (theme) => ({
|
|
294
375
|
keys: {
|
|
295
|
-
|
|
296
|
-
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
|
|
297
|
-
},
|
|
376
|
+
...commonMqKeyboardStyles,
|
|
298
377
|
width: '100%',
|
|
299
378
|
display: 'grid',
|
|
300
379
|
gridTemplateRows: 'repeat(5, minmax(40px, 60px))',
|
|
@@ -307,7 +386,7 @@ const styles = (theme) => ({
|
|
|
307
386
|
gridTemplateRows: 'repeat(5, minmax(40px, 50px)) !important',
|
|
308
387
|
},
|
|
309
388
|
language: {
|
|
310
|
-
gridTemplateRows: 'repeat(
|
|
389
|
+
gridTemplateRows: 'repeat(4, minmax(40px, 50px)) !important',
|
|
311
390
|
'& *': {
|
|
312
391
|
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
|
|
313
392
|
},
|
|
@@ -337,6 +416,11 @@ const styles = (theme) => ({
|
|
|
337
416
|
backgroundColor: lighten(theme.palette.primary.light, 0.7),
|
|
338
417
|
},
|
|
339
418
|
},
|
|
419
|
+
deleteButton: {
|
|
420
|
+
'& > span': {
|
|
421
|
+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
|
|
422
|
+
},
|
|
423
|
+
},
|
|
340
424
|
base: {},
|
|
341
425
|
operators: {
|
|
342
426
|
backgroundColor: lighten(theme.palette.secondary.light, 0.5),
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { extendKeySet } from '../utils';
|
|
2
|
+
import { keysForGrade, gradeSets } from '../grades';
|
|
3
|
+
import * as comparison from '../../keys/comparison';
|
|
4
|
+
|
|
5
|
+
describe('utils', () => {
|
|
6
|
+
const base = [[comparison.lessThan]];
|
|
7
|
+
describe('extendKeySet', () => {
|
|
8
|
+
it('removes duplicates by latex key', () => {
|
|
9
|
+
const extras = [{ name: 'foo', latex: '<', write: '<', label: 'less than' }];
|
|
10
|
+
const result = extendKeySet(base, extras);
|
|
11
|
+
const resultTwo = extendKeySet(base, []);
|
|
12
|
+
expect(result).toEqual(resultTwo);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('removes duplicates by name key', () => {
|
|
16
|
+
const extras = [{ name: 'Less than', latex: 'this is latex', write: '<', label: '<' }];
|
|
17
|
+
const result = extendKeySet(base, extras);
|
|
18
|
+
const resultTwo = extendKeySet(base, []);
|
|
19
|
+
expect(result).toEqual(resultTwo);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('keysForGrade', () => {
|
|
24
|
+
it.each`
|
|
25
|
+
key | expected
|
|
26
|
+
${'1'} | ${[]}
|
|
27
|
+
${'2'} | ${[]}
|
|
28
|
+
${'3'} | ${gradeSets[0].set}
|
|
29
|
+
${'4'} | ${gradeSets[0].set}
|
|
30
|
+
${'5'} | ${gradeSets[0].set}
|
|
31
|
+
${'6'} | ${gradeSets[1].set}
|
|
32
|
+
${'7'} | ${gradeSets[1].set}
|
|
33
|
+
${'8'} | ${gradeSets[2].set}
|
|
34
|
+
${'9'} | ${gradeSets[2].set}
|
|
35
|
+
${'HS'} | ${gradeSets[2].set}
|
|
36
|
+
${'non-negative-integers'} | ${gradeSets[3].set}
|
|
37
|
+
${'integers'} | ${gradeSets[4].set}
|
|
38
|
+
${'decimals'} | ${gradeSets[5].set}
|
|
39
|
+
${'fractions'} | ${gradeSets[6].set}
|
|
40
|
+
${'geometry'} | ${gradeSets[7].set}
|
|
41
|
+
${'advanced-algebra'} | ${gradeSets[8].set}
|
|
42
|
+
${'statistics'} | ${gradeSets[9].set}
|
|
43
|
+
${'something else'} | ${gradeSets[2].set}
|
|
44
|
+
${undefined} | ${[]}
|
|
45
|
+
${null} | ${[]}
|
|
46
|
+
${0} | ${[]}
|
|
47
|
+
${'0'} | ${[]}
|
|
48
|
+
`('$key => $expected', ({ key, expected }) => {
|
|
49
|
+
expect(keysForGrade(key)).toEqual(expected);
|
|
50
|
+
|
|
51
|
+
const n = parseInt(key, 10);
|
|
52
|
+
if (!isNaN(n)) {
|
|
53
|
+
expect(keysForGrade(n)).toEqual(expected);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
package/src/keys/geometry.js
CHANGED
|
@@ -101,6 +101,7 @@ export const congruentTo = set({
|
|
|
101
101
|
command: '\\cong',
|
|
102
102
|
latex: '\\cong',
|
|
103
103
|
});
|
|
104
|
+
|
|
104
105
|
export const notCongruentTo = set({
|
|
105
106
|
name: 'Not Congruent To',
|
|
106
107
|
command: '\\ncong',
|
|
@@ -115,10 +116,13 @@ export const primeArcminute = set({
|
|
|
115
116
|
// eslint-disable-next-line
|
|
116
117
|
write: "'",
|
|
117
118
|
});
|
|
119
|
+
|
|
118
120
|
export const doublePrimeArcSecond = set({
|
|
119
121
|
name: 'Double Prime',
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
// eslint-disable-next-line
|
|
123
|
+
latex: "''",
|
|
124
|
+
// eslint-disable-next-line
|
|
125
|
+
write: "''",
|
|
122
126
|
});
|
|
123
127
|
|
|
124
128
|
export const leftArrow = set({
|
package/src/keys/grades.js
CHANGED
|
@@ -304,6 +304,12 @@ export const gradeSets = [
|
|
|
304
304
|
],
|
|
305
305
|
],
|
|
306
306
|
},
|
|
307
|
+
// for grade 1-2, we want to display the base set only
|
|
308
|
+
// we need it here because we don't want to display the default set (grade 8)
|
|
309
|
+
{
|
|
310
|
+
predicate: (n) => n >= 1 && n <= 2,
|
|
311
|
+
set: [],
|
|
312
|
+
},
|
|
307
313
|
];
|
|
308
314
|
|
|
309
315
|
export const keysForGrade = (n) => {
|
|
@@ -324,6 +330,11 @@ export const keysForGrade = (n) => {
|
|
|
324
330
|
if (match) {
|
|
325
331
|
return match.set || [];
|
|
326
332
|
}
|
|
333
|
+
|
|
334
|
+
// if the grade is not found, return the default set which is grade 8 (as per PD-3549), for mode language it is not the default
|
|
335
|
+
if (n !== 'language') {
|
|
336
|
+
return gradeSets[2].set;
|
|
337
|
+
}
|
|
327
338
|
};
|
|
328
339
|
|
|
329
340
|
const ALL_KEYS = [
|
package/src/keys/log.js
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Input } from '../input';
|
|
4
|
+
|
|
5
|
+
describe('Input', () => {
|
|
6
|
+
let w;
|
|
7
|
+
let onChange;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
onChange = jest.fn();
|
|
11
|
+
});
|
|
12
|
+
const wrapper = (extras) => {
|
|
13
|
+
const defaults = {
|
|
14
|
+
classes: {},
|
|
15
|
+
className: 'className',
|
|
16
|
+
onChange,
|
|
17
|
+
};
|
|
18
|
+
const props = { ...defaults, ...extras };
|
|
19
|
+
const out = shallow(<Input {...props} />);
|
|
20
|
+
|
|
21
|
+
out.mathField = () => out.instance().mathField;
|
|
22
|
+
return out;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('snapshot', () => {
|
|
26
|
+
it('renders', () => {
|
|
27
|
+
w = wrapper();
|
|
28
|
+
expect(w).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('logic', () => {
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
w = wrapper();
|
|
34
|
+
});
|
|
35
|
+
describe('clear', () => {
|
|
36
|
+
it('calls latex', () => {
|
|
37
|
+
w.instance().clear();
|
|
38
|
+
expect(w.mathField().latex).toHaveBeenCalledWith('');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('blur', () => {
|
|
42
|
+
it('calls blur', () => {
|
|
43
|
+
w.instance().blur();
|
|
44
|
+
expect(w.mathField().blur).toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('focus', () => {
|
|
48
|
+
it('calls focus', () => {
|
|
49
|
+
w.instance().focus();
|
|
50
|
+
expect(w.mathField().focus).toHaveBeenCalled();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('command', () => {
|
|
54
|
+
it('calls cmd', () => {
|
|
55
|
+
w.instance().command('foo');
|
|
56
|
+
expect(w.mathField().cmd).toHaveBeenCalledWith('foo');
|
|
57
|
+
});
|
|
58
|
+
it('calls cmd if passed an array', () => {
|
|
59
|
+
w.instance().command(['foo', 'bar']);
|
|
60
|
+
expect(w.mathField().cmd).toHaveBeenCalledWith('foo');
|
|
61
|
+
expect(w.mathField().cmd).toHaveBeenCalledWith('bar');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('keystroke', () => {
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
w.instance().keystroke('9');
|
|
68
|
+
});
|
|
69
|
+
it('calls keystroke', () => expect(w.mathField().keystroke).toHaveBeenCalledWith('9'));
|
|
70
|
+
it('calls focus', () => expect(w.mathField().focus).toHaveBeenCalled());
|
|
71
|
+
it('calls latex', () => expect(w.mathField().latex).toHaveBeenCalled());
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('write', () => {
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
w.instance().write('hi');
|
|
77
|
+
});
|
|
78
|
+
it('calls write', () => expect(w.mathField().write).toHaveBeenCalledWith('hi'));
|
|
79
|
+
it('calls focus', () => expect(w.mathField().focus).toHaveBeenCalled());
|
|
80
|
+
it('calls latex', () => expect(w.mathField().latex).toHaveBeenCalled());
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('onInputEdit', () => {
|
|
84
|
+
it('calls onChange', () => {
|
|
85
|
+
w = wrapper();
|
|
86
|
+
w.mathField().latex.mockReturnValue('foo');
|
|
87
|
+
w.instance().onInputEdit();
|
|
88
|
+
expect(onChange).toHaveBeenCalledWith('foo');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Static from '../static';
|
|
4
|
+
|
|
5
|
+
const Mathquill = require('@pie-framework/mathquill');
|
|
6
|
+
|
|
7
|
+
jest.mock('@pie-framework/mathquill', () => ({
|
|
8
|
+
StaticMath: jest.fn().mockReturnValue({
|
|
9
|
+
latex: jest.fn(),
|
|
10
|
+
parseLatex: jest.fn(),
|
|
11
|
+
}),
|
|
12
|
+
getInterface: jest.fn().mockReturnThis(),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
describe('static', () => {
|
|
16
|
+
let w;
|
|
17
|
+
describe('mount', () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
w = shallow(<Static latex="foo" />, {
|
|
20
|
+
disableLifecycleMethods: true,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
w.instance().input = {};
|
|
24
|
+
w.instance().componentDidMount();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('set the html', () => {
|
|
28
|
+
expect(Mathquill.getInterface().StaticMath().latex).toBeCalledWith('foo');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('calls MQ.StaticMath', () => {
|
|
32
|
+
expect(Mathquill.getInterface().StaticMath).toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('shouldComponentUpdate', () => {
|
|
37
|
+
it('returns false if there is an error', () => {
|
|
38
|
+
w = shallow(<Static latex="foo" />, { disableLifecycleMethods: true });
|
|
39
|
+
w.instance().mathField = {
|
|
40
|
+
parseLatex: jest.fn((e) => {
|
|
41
|
+
throw new Error('boom');
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
expect(w.instance().shouldComponentUpdate({ latex: '\\abs{}' })).toEqual(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('returns true if ??', () => {
|
|
48
|
+
w = shallow(<Static latex="foo" />, { disableLifecycleMethods: true });
|
|
49
|
+
w.instance().mathField = {
|
|
50
|
+
latex: jest.fn().mockReturnValue('foo'),
|
|
51
|
+
parseLatex: jest.fn().mockReturnValue('foo'),
|
|
52
|
+
innerFields: ['field1', 'field2'],
|
|
53
|
+
};
|
|
54
|
+
expect(w.instance().shouldComponentUpdate({ latex: '\\abs{}' })).toEqual(true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export const commonMqFontStyles = {
|
|
2
|
+
fontFamily: 'MJXZERO, MJXTEX !important',
|
|
3
|
+
'-webkit-font-smoothing': 'antialiased !important',
|
|
4
|
+
|
|
5
|
+
'& .mq-math-mode > span > var': {
|
|
6
|
+
fontFamily: 'MJXZERO, MJXTEX-I !important',
|
|
7
|
+
},
|
|
8
|
+
'& .mq-math-mode span var': {
|
|
9
|
+
fontFamily: 'MJXZERO, MJXTEX-I !important',
|
|
10
|
+
},
|
|
11
|
+
'& .mq-math-mode .mq-nonSymbola': {
|
|
12
|
+
fontFamily: 'MJXZERO, MJXTEX-I !important',
|
|
13
|
+
},
|
|
14
|
+
'& .mq-math-mode > span > var.mq-operator-name': {
|
|
15
|
+
fontFamily: 'MJXZERO, MJXTEX !important',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const longdivStyles = {
|
|
20
|
+
'& .mq-longdiv-inner': {
|
|
21
|
+
marginTop: '-1px',
|
|
22
|
+
marginLeft: '5px !important;',
|
|
23
|
+
|
|
24
|
+
'& > .mq-empty': {
|
|
25
|
+
padding: '0 !important',
|
|
26
|
+
marginLeft: '0px !important',
|
|
27
|
+
marginTop: '2px',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
'& .mq-math-mode .mq-longdiv': {
|
|
32
|
+
display: 'inline-flex !important',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const supsubStyles = {
|
|
37
|
+
'& .mq-math-mode sup.mq-nthroot': {
|
|
38
|
+
fontSize: '70% !important',
|
|
39
|
+
verticalAlign: '0.5em !important',
|
|
40
|
+
paddingRight: '0.15em',
|
|
41
|
+
},
|
|
42
|
+
'& .mq-math-mode .mq-supsub': {
|
|
43
|
+
fontSize: '70.7% !important',
|
|
44
|
+
},
|
|
45
|
+
'& .mq-supsub ': {
|
|
46
|
+
fontSize: '70.7%',
|
|
47
|
+
},
|
|
48
|
+
'& .mq-math-mode .mq-supsub.mq-sup-only': {
|
|
49
|
+
verticalAlign: '-0.1em !important',
|
|
50
|
+
|
|
51
|
+
'& .mq-sup': {
|
|
52
|
+
marginBottom: '0px !important',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
/* But when the base is a fraction, move it higher */
|
|
56
|
+
'& .mq-math-mode .mq-fraction + .mq-supsub.mq-sup-only': {
|
|
57
|
+
verticalAlign: '0.4em !important',
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
'& .mq-math-mode .mq-supsub.mq-sup-only.mq-after-fraction-group': {
|
|
61
|
+
verticalAlign: '0.4em !important',
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const commonMqKeyboardStyles = {
|
|
66
|
+
'& *': {
|
|
67
|
+
...commonMqFontStyles,
|
|
68
|
+
...longdivStyles,
|
|
69
|
+
'& .mq-math-mode .mq-sqrt-prefix': {
|
|
70
|
+
top: '0 !important',
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
'& .mq-math-mode .mq-empty': {
|
|
74
|
+
padding: '9px 1px !important',
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
'& .mq-math-mode .mq-supsub': {
|
|
78
|
+
fontSize: '70.7% !important',
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
'& .mq-math-mode .mq-sqrt-stem': {
|
|
82
|
+
marginTop: '-5px',
|
|
83
|
+
paddingTop: '4px',
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
'& .mq-math-mode .mq-paren': {
|
|
87
|
+
verticalAlign: 'middle !important',
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
'& .mq-math-mode .mq-overarrow .mq-overarrow-inner .mq-empty': {
|
|
91
|
+
padding: '0 !important',
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
'& .mq-math-mode .mq-overline .mq-overline-inner .mq-empty ': {
|
|
95
|
+
padding: '0 !important',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default {
|
|
101
|
+
commonMqFontStyles,
|
|
102
|
+
longdivStyles,
|
|
103
|
+
supsubStyles,
|
|
104
|
+
commonMqKeyboardStyles,
|
|
105
|
+
};
|
package/src/mq/index.js
CHANGED