@pie-lib/math-input 0.1.0 → 0.1.1-next.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/horizontal-keypad.d.ts +1 -2
- package/dist/index.d.ts +0 -1
- package/dist/keypad/accessible-keypad.d.ts +2 -3
- package/dist/keypad/index.d.ts +0 -1
- package/dist/keypad/keys-layout.d.ts +0 -1
- package/dist/keypad/model.d.ts +0 -1
- package/dist/keys/basic-operators.d.ts +0 -1
- package/dist/keys/chars.d.ts +0 -1
- package/dist/keys/comparison.d.ts +0 -1
- package/dist/keys/constants.d.ts +0 -1
- package/dist/keys/digits.d.ts +0 -1
- package/dist/keys/edit.d.ts +0 -1
- package/dist/keys/exponent.d.ts +0 -1
- package/dist/keys/fractions.d.ts +0 -1
- package/dist/keys/geometry.d.ts +0 -1
- package/dist/keys/grades.d.ts +0 -1
- package/dist/keys/index.d.ts +0 -1
- package/dist/keys/log.d.ts +0 -1
- package/dist/keys/logic.d.ts +0 -1
- package/dist/keys/matrices.d.ts +0 -1
- package/dist/keys/misc.d.ts +0 -1
- package/dist/keys/navigation.d.ts +0 -1
- package/dist/keys/operators.d.ts +0 -1
- package/dist/keys/statistics.d.ts +0 -1
- package/dist/keys/sub-sup.d.ts +0 -1
- package/dist/keys/trigonometry.d.ts +0 -1
- package/dist/keys/utils.d.ts +0 -1
- package/dist/keys/vars.d.ts +0 -1
- package/dist/math-input.d.ts +1 -2
- package/dist/mq/common-mq-styles.d.ts +0 -1
- package/dist/mq/custom-elements.d.ts +0 -1
- package/dist/mq/index.d.ts +0 -1
- package/dist/mq/input.d.ts +1 -2
- package/dist/mq/static.d.ts +1 -2
- package/dist/updateSpans.d.ts +0 -1
- package/package.json +10 -4
- package/dist/horizontal-keypad.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/keypad/accessible-keypad.d.ts.map +0 -1
- package/dist/keypad/index.d.ts.map +0 -1
- package/dist/keypad/keys-layout.d.ts.map +0 -1
- package/dist/keypad/model.d.ts.map +0 -1
- package/dist/keys/basic-operators.d.ts.map +0 -1
- package/dist/keys/chars.d.ts.map +0 -1
- package/dist/keys/comparison.d.ts.map +0 -1
- package/dist/keys/constants.d.ts.map +0 -1
- package/dist/keys/digits.d.ts.map +0 -1
- package/dist/keys/edit.d.ts.map +0 -1
- package/dist/keys/exponent.d.ts.map +0 -1
- package/dist/keys/fractions.d.ts.map +0 -1
- package/dist/keys/geometry.d.ts.map +0 -1
- package/dist/keys/grades.d.ts.map +0 -1
- package/dist/keys/index.d.ts.map +0 -1
- package/dist/keys/log.d.ts.map +0 -1
- package/dist/keys/logic.d.ts.map +0 -1
- package/dist/keys/matrices.d.ts.map +0 -1
- package/dist/keys/misc.d.ts.map +0 -1
- package/dist/keys/navigation.d.ts.map +0 -1
- package/dist/keys/operators.d.ts.map +0 -1
- package/dist/keys/statistics.d.ts.map +0 -1
- package/dist/keys/sub-sup.d.ts.map +0 -1
- package/dist/keys/trigonometry.d.ts.map +0 -1
- package/dist/keys/utils.d.ts.map +0 -1
- package/dist/keys/vars.d.ts.map +0 -1
- package/dist/math-input.d.ts.map +0 -1
- package/dist/mq/common-mq-styles.d.ts.map +0 -1
- package/dist/mq/custom-elements.d.ts.map +0 -1
- package/dist/mq/index.d.ts.map +0 -1
- package/dist/mq/input.d.ts.map +0 -1
- package/dist/mq/static.d.ts.map +0 -1
- package/dist/updateSpans.d.ts.map +0 -1
- package/src/horizontal-keypad.tsx +0 -82
- package/src/index.tsx +0 -27
- package/src/keypad/accessible-keypad.tsx +0 -731
- package/src/keypad/index.tsx +0 -3
- package/src/keypad/keys-layout.ts +0 -26
- package/src/keypad/model.ts +0 -149
- package/src/keys/basic-operators.ts +0 -42
- package/src/keys/chars.ts +0 -15
- package/src/keys/comparison.ts +0 -38
- package/src/keys/constants.ts +0 -45
- package/src/keys/digits.ts +0 -50
- package/src/keys/edit.ts +0 -13
- package/src/keys/exponent.ts +0 -38
- package/src/keys/fractions.ts +0 -36
- package/src/keys/geometry.ts +0 -154
- package/src/keys/grades.ts +0 -377
- package/src/keys/index.ts +0 -30
- package/src/keys/log.ts +0 -32
- package/src/keys/logic.ts +0 -25
- package/src/keys/matrices.ts +0 -25
- package/src/keys/misc.ts +0 -75
- package/src/keys/navigation.ts +0 -18
- package/src/keys/operators.ts +0 -20
- package/src/keys/statistics.ts +0 -48
- package/src/keys/sub-sup.ts +0 -25
- package/src/keys/trigonometry.ts +0 -25
- package/src/keys/utils.ts +0 -76
- package/src/keys/vars.ts +0 -29
- package/src/math-input.tsx +0 -129
- package/src/mq/common-mq-styles.ts +0 -115
- package/src/mq/custom-elements.tsx +0 -21
- package/src/mq/index.ts +0 -15
- package/src/mq/input.tsx +0 -172
- package/src/mq/static.tsx +0 -279
- package/src/updateSpans.ts +0 -26
package/src/keys/trigonometry.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @synced-from pie-lib/packages/math-input/src/keys/trigonometry.js
|
|
4
|
-
* @auto-generated
|
|
5
|
-
*
|
|
6
|
-
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
-
* Manual edits will be overwritten on next sync.
|
|
8
|
-
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { mkSet } from './utils';
|
|
12
|
-
|
|
13
|
-
const set = mkSet('trigonometry');
|
|
14
|
-
|
|
15
|
-
export const sin = set({ name: 'sine', label: 'sin', command: '\\sin', latex: '\\sin' });
|
|
16
|
-
|
|
17
|
-
export const cos = set({ name: 'cosine', label: 'cos', command: '\\cos', latex: '\\cos' });
|
|
18
|
-
|
|
19
|
-
export const tan = set({ name: 'tanget', label: 'tan', command: '\\tan', latex: '\\tan' });
|
|
20
|
-
|
|
21
|
-
export const sec = set({ name: 'secant', label: 'sec', command: '\\sec', latex: '\\sec' });
|
|
22
|
-
|
|
23
|
-
export const csc = set({ name: 'cosecant', label: 'csc', command: '\\csc', latex: '\\csc' });
|
|
24
|
-
|
|
25
|
-
export const cot = set({ name: 'cotangent', label: 'cot', command: '\\cot', latex: '\\cot' });
|
package/src/keys/utils.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @synced-from pie-lib/packages/math-input/src/keys/utils.js
|
|
4
|
-
* @auto-generated
|
|
5
|
-
*
|
|
6
|
-
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
-
* Manual edits will be overwritten on next sync.
|
|
8
|
-
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { flatten, times } from 'lodash-es';
|
|
12
|
-
|
|
13
|
-
export const mkSet = (category) => (o) => ({ ...o, category });
|
|
14
|
-
|
|
15
|
-
export const toArray = (o) => Object.keys(o).map((k) => o[k]);
|
|
16
|
-
|
|
17
|
-
export const toKey = (category) => (v) => {
|
|
18
|
-
if (typeof v === 'string') {
|
|
19
|
-
return {
|
|
20
|
-
name: v,
|
|
21
|
-
label: v,
|
|
22
|
-
category,
|
|
23
|
-
write: v,
|
|
24
|
-
};
|
|
25
|
-
} else {
|
|
26
|
-
return {
|
|
27
|
-
...v,
|
|
28
|
-
category,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const transformToKeySetStructure = (data = []) => {
|
|
34
|
-
const structure = [];
|
|
35
|
-
|
|
36
|
-
times(5, () => structure.push([]));
|
|
37
|
-
|
|
38
|
-
let ln = data.length;
|
|
39
|
-
let i = 0;
|
|
40
|
-
let j = 0;
|
|
41
|
-
|
|
42
|
-
while (j < ln) {
|
|
43
|
-
structure[i++].push(data[j++]);
|
|
44
|
-
|
|
45
|
-
if (i === 5) {
|
|
46
|
-
i = 0;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return structure;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const latexAndNameDontExist = (base) => (k) => {
|
|
54
|
-
const flattened = flatten(base);
|
|
55
|
-
const latexExists = flattened.some((b) => b.latex === k.latex);
|
|
56
|
-
const nameExists = flattened.some((b) => b.name === k.name);
|
|
57
|
-
|
|
58
|
-
return !latexExists && !nameExists;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const extendKeySet = (base = [], keySetData = []) => {
|
|
62
|
-
keySetData = keySetData.filter(latexAndNameDontExist(base));
|
|
63
|
-
|
|
64
|
-
const final = [];
|
|
65
|
-
|
|
66
|
-
times(5 - base.length, () => base.push([]));
|
|
67
|
-
times(5, () => final.push([]));
|
|
68
|
-
|
|
69
|
-
const extra = transformToKeySetStructure(keySetData);
|
|
70
|
-
|
|
71
|
-
for (let i = 0; i < 5; i++) {
|
|
72
|
-
final[i] = [...base[i], ...extra[i]];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return final;
|
|
76
|
-
};
|
package/src/keys/vars.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @synced-from pie-lib/packages/math-input/src/keys/vars.js
|
|
4
|
-
* @auto-generated
|
|
5
|
-
*
|
|
6
|
-
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
-
* Manual edits will be overwritten on next sync.
|
|
8
|
-
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { mkSet } from './utils';
|
|
12
|
-
|
|
13
|
-
const set = mkSet('vars');
|
|
14
|
-
|
|
15
|
-
export const x = set({
|
|
16
|
-
name: 'X',
|
|
17
|
-
latex: 'x',
|
|
18
|
-
write: 'x',
|
|
19
|
-
});
|
|
20
|
-
export const y = set({
|
|
21
|
-
name: 'Y',
|
|
22
|
-
latex: 'y',
|
|
23
|
-
write: 'y',
|
|
24
|
-
});
|
|
25
|
-
export const theta = set({
|
|
26
|
-
name: 'Theta',
|
|
27
|
-
latex: '\\theta',
|
|
28
|
-
write: '\\theta',
|
|
29
|
-
});
|
package/src/math-input.tsx
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @synced-from pie-lib/packages/math-input/src/math-input.jsx
|
|
4
|
-
* @auto-generated
|
|
5
|
-
*
|
|
6
|
-
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
-
* Manual edits will be overwritten on next sync.
|
|
8
|
-
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import React from 'react';
|
|
12
|
-
import PropTypes from 'prop-types';
|
|
13
|
-
import { styled } from '@mui/material/styles';
|
|
14
|
-
import * as mq from './mq';
|
|
15
|
-
import { baseSet } from './keys';
|
|
16
|
-
import KeyPad from './keypad';
|
|
17
|
-
import debug from 'debug';
|
|
18
|
-
|
|
19
|
-
const log = debug('pie-lib:math-input');
|
|
20
|
-
|
|
21
|
-
const grey = 'rgba(0, 0, 0, 0.23)';
|
|
22
|
-
|
|
23
|
-
const MathInputContainer: any = styled('div')(({ theme, focused }) => ({
|
|
24
|
-
borderRadius: '4px',
|
|
25
|
-
border: `solid 1px ${focused ? theme.palette.primary.main : grey}`,
|
|
26
|
-
marginTop: theme.spacing(1),
|
|
27
|
-
marginBottom: theme.spacing(1),
|
|
28
|
-
transition: 'border 200ms linear',
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
const PadContainer: any = styled('div')({
|
|
32
|
-
width: '100%',
|
|
33
|
-
display: 'flex',
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const StyledMqInput: any = styled(mq.Input)(({ theme }) => ({
|
|
37
|
-
width: '100%',
|
|
38
|
-
border: `solid 0px ${theme.palette.primary.light}`,
|
|
39
|
-
transition: 'border 200ms linear',
|
|
40
|
-
padding: theme.spacing(1),
|
|
41
|
-
'&.mq-focused': {
|
|
42
|
-
outline: 'none',
|
|
43
|
-
boxShadow: 'none',
|
|
44
|
-
border: `solid 0px ${theme.palette.primary.dark}`,
|
|
45
|
-
},
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
export class MathInput extends React.Component {
|
|
49
|
-
static propTypes = {
|
|
50
|
-
className: PropTypes.string,
|
|
51
|
-
keyset: PropTypes.array,
|
|
52
|
-
displayMode: PropTypes.oneOf(['block', 'block-on-focus']),
|
|
53
|
-
latex: PropTypes.string,
|
|
54
|
-
onChange: PropTypes.func,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
static defaultProps = {
|
|
58
|
-
keyset: [],
|
|
59
|
-
displayMode: 'block',
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
constructor(props) {
|
|
63
|
-
super(props);
|
|
64
|
-
this.state = {
|
|
65
|
-
focused: false,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
keypadPress: any = (key) => {
|
|
70
|
-
log('[keypadPress] key:', key);
|
|
71
|
-
|
|
72
|
-
if (!this.input) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (key.latex && !key.command) {
|
|
77
|
-
this.input.write(key.latex);
|
|
78
|
-
} else if (key.write) {
|
|
79
|
-
this.input.write(key.write);
|
|
80
|
-
} else if (key.command) {
|
|
81
|
-
this.input.command(key.command);
|
|
82
|
-
} else if (key.keystroke) {
|
|
83
|
-
this.input.keystroke(key.keystroke);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
inputFocus: any = () => {
|
|
88
|
-
this.setState({ focused: true });
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
inputBlur: any = () => {
|
|
92
|
-
this.setState({ focused: false });
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
changeLatex: any = (l) => {
|
|
96
|
-
const { onChange } = this.props;
|
|
97
|
-
|
|
98
|
-
if (onChange && l !== this.props.latex) {
|
|
99
|
-
log('[changeLatex]', l, this.props.latex);
|
|
100
|
-
onChange(l);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
render() {
|
|
105
|
-
const { className, keyset, latex } = this.props;
|
|
106
|
-
const { focused } = this.state;
|
|
107
|
-
|
|
108
|
-
const showKeypad = true; // TODO: add support for different displayModes - displayMode === 'block' || focused;
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<MathInputContainer className={className} focused={focused}>
|
|
112
|
-
<StyledMqInput
|
|
113
|
-
innerRef={(r) => (this.input = r)}
|
|
114
|
-
onFocus={this.inputFocus}
|
|
115
|
-
onBlur={this.inputBlur}
|
|
116
|
-
latex={latex}
|
|
117
|
-
onChange={this.changeLatex}
|
|
118
|
-
/>
|
|
119
|
-
{showKeypad && (
|
|
120
|
-
<PadContainer>
|
|
121
|
-
<KeyPad baseSet={baseSet} additionalKeys={keyset} onPress={this.keypadPress} />
|
|
122
|
-
</PadContainer>
|
|
123
|
-
)}
|
|
124
|
-
</MathInputContainer>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export default MathInput;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @synced-from pie-lib/packages/math-input/src/mq/common-mq-styles.js
|
|
4
|
-
* @auto-generated
|
|
5
|
-
*
|
|
6
|
-
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
-
* Manual edits will be overwritten on next sync.
|
|
8
|
-
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export const commonMqFontStyles = {
|
|
12
|
-
fontFamily: 'MJXZERO, MJXTEX !important',
|
|
13
|
-
'-webkit-font-smoothing': 'antialiased !important',
|
|
14
|
-
|
|
15
|
-
'& .mq-math-mode > span > var': {
|
|
16
|
-
fontFamily: 'MJXZERO, MJXTEX-I !important',
|
|
17
|
-
},
|
|
18
|
-
'& .mq-math-mode span var': {
|
|
19
|
-
fontFamily: 'MJXZERO, MJXTEX-I !important',
|
|
20
|
-
},
|
|
21
|
-
'& .mq-math-mode .mq-nonSymbola': {
|
|
22
|
-
fontFamily: 'MJXZERO, MJXTEX-I !important',
|
|
23
|
-
},
|
|
24
|
-
'& .mq-math-mode > span > var.mq-operator-name': {
|
|
25
|
-
fontFamily: 'MJXZERO, MJXTEX !important',
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const longdivStyles = {
|
|
30
|
-
'& .mq-longdiv-inner': {
|
|
31
|
-
marginTop: '-1px',
|
|
32
|
-
marginLeft: '5px !important;',
|
|
33
|
-
|
|
34
|
-
'& > .mq-empty': {
|
|
35
|
-
padding: '0 !important',
|
|
36
|
-
marginLeft: '0px !important',
|
|
37
|
-
marginTop: '2px',
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
'& .mq-math-mode .mq-longdiv': {
|
|
42
|
-
display: 'inline-flex !important',
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const supsubStyles = {
|
|
47
|
-
'& .mq-math-mode sup.mq-nthroot': {
|
|
48
|
-
fontSize: '70% !important',
|
|
49
|
-
verticalAlign: '0.5em !important',
|
|
50
|
-
paddingRight: '0.15em',
|
|
51
|
-
},
|
|
52
|
-
'& .mq-math-mode .mq-supsub': {
|
|
53
|
-
fontSize: '70.7% !important',
|
|
54
|
-
},
|
|
55
|
-
'& .mq-supsub ': {
|
|
56
|
-
fontSize: '70.7%',
|
|
57
|
-
},
|
|
58
|
-
'& .mq-math-mode .mq-supsub.mq-sup-only': {
|
|
59
|
-
verticalAlign: '-0.1em !important',
|
|
60
|
-
|
|
61
|
-
'& .mq-sup': {
|
|
62
|
-
marginBottom: '0px !important',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
/* But when the base is a fraction, move it higher */
|
|
66
|
-
'& .mq-math-mode .mq-fraction + .mq-supsub.mq-sup-only': {
|
|
67
|
-
verticalAlign: '0.4em !important',
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
'& .mq-math-mode .mq-supsub.mq-sup-only.mq-after-fraction-group': {
|
|
71
|
-
verticalAlign: '0.4em !important',
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const commonMqKeyboardStyles = {
|
|
76
|
-
'& *': {
|
|
77
|
-
...commonMqFontStyles,
|
|
78
|
-
...longdivStyles,
|
|
79
|
-
'& .mq-math-mode .mq-sqrt-prefix': {
|
|
80
|
-
top: '0 !important',
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
'& .mq-math-mode .mq-empty': {
|
|
84
|
-
padding: '9px 1px !important',
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
'& .mq-math-mode .mq-supsub': {
|
|
88
|
-
fontSize: '70.7% !important',
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
'& .mq-math-mode .mq-sqrt-stem': {
|
|
92
|
-
marginTop: '-5px',
|
|
93
|
-
paddingTop: '4px',
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
'& .mq-math-mode .mq-paren': {
|
|
97
|
-
verticalAlign: 'middle !important',
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
'& .mq-math-mode .mq-overarrow .mq-overarrow-inner .mq-empty': {
|
|
101
|
-
padding: '0 !important',
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
'& .mq-math-mode .mq-overline .mq-overline-inner .mq-empty ': {
|
|
105
|
-
padding: '0 !important',
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export default {
|
|
111
|
-
commonMqFontStyles,
|
|
112
|
-
longdivStyles,
|
|
113
|
-
supsubStyles,
|
|
114
|
-
commonMqKeyboardStyles,
|
|
115
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @synced-from pie-lib/packages/math-input/src/mq/custom-elements.js
|
|
4
|
-
* @auto-generated
|
|
5
|
-
*
|
|
6
|
-
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
-
* Manual edits will be overwritten on next sync.
|
|
8
|
-
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const registerLineBreak = function(MQ) {
|
|
12
|
-
MQ.registerEmbed('newLine', () => {
|
|
13
|
-
return {
|
|
14
|
-
htmlString: '<div class="newLine"></div>',
|
|
15
|
-
text: () => 'testText',
|
|
16
|
-
latex: () => '\\embed{newLine}[]',
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { registerLineBreak };
|
package/src/mq/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @synced-from pie-lib/packages/math-input/src/mq/index.js
|
|
4
|
-
* @auto-generated
|
|
5
|
-
*
|
|
6
|
-
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
-
* Manual edits will be overwritten on next sync.
|
|
8
|
-
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import Input from './input';
|
|
12
|
-
import Static from './static';
|
|
13
|
-
import CommonMqStyles from './common-mq-styles';
|
|
14
|
-
|
|
15
|
-
export { Input, Static, CommonMqStyles };
|
package/src/mq/input.tsx
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @synced-from pie-lib/packages/math-input/src/mq/input.jsx
|
|
4
|
-
* @auto-generated
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import PropTypes from 'prop-types';
|
|
9
|
-
import { styled } from '@mui/material/styles';
|
|
10
|
-
import debug from 'debug';
|
|
11
|
-
import { registerLineBreak } from './custom-elements';
|
|
12
|
-
import MathQuill from '@pie-framework/mathquill';
|
|
13
|
-
|
|
14
|
-
let MQ;
|
|
15
|
-
if (typeof window !== 'undefined') {
|
|
16
|
-
MQ = MathQuill.getInterface(2);
|
|
17
|
-
|
|
18
|
-
if (MQ && MQ.registerEmbed) {
|
|
19
|
-
registerLineBreak(MQ);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const log = debug('math-input:mq:input');
|
|
24
|
-
|
|
25
|
-
const StyledSpan: any = styled('span')({
|
|
26
|
-
// No specific styles needed, but component is available for future styling
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Wrapper for MathQuill MQ.MathField.
|
|
31
|
-
*/
|
|
32
|
-
export class Input extends React.Component {
|
|
33
|
-
static propTypes = {
|
|
34
|
-
className: PropTypes.string,
|
|
35
|
-
onClick: PropTypes.func,
|
|
36
|
-
onChange: PropTypes.func,
|
|
37
|
-
latex: PropTypes.string,
|
|
38
|
-
onFocus: PropTypes.func,
|
|
39
|
-
onBlur: PropTypes.func,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
componentDidMount() {
|
|
43
|
-
if (!MQ) {
|
|
44
|
-
throw new Error('MQ is not defined - but component has mounted?');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
this.mathField = MQ.MathField(this.input, {
|
|
48
|
-
handlers: {
|
|
49
|
-
edit: this.onInputEdit.bind(this),
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
this.updateLatex();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
componentDidUpdate() {
|
|
57
|
-
this.updateLatex();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
updateLatex() {
|
|
61
|
-
if (!this.mathField) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const { latex } = this.props;
|
|
66
|
-
|
|
67
|
-
if (latex !== undefined && latex !== null) {
|
|
68
|
-
this.mathField.latex(latex);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
clear() {
|
|
73
|
-
this.mathField.latex('');
|
|
74
|
-
|
|
75
|
-
return '';
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
blur() {
|
|
79
|
-
log('blur mathfield');
|
|
80
|
-
this.mathField.blur();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
focus() {
|
|
84
|
-
log('focus mathfield...');
|
|
85
|
-
this.mathField.focus();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
command(v) {
|
|
89
|
-
log('command: ', v);
|
|
90
|
-
if (Array.isArray(v)) {
|
|
91
|
-
v.forEach((vv) => {
|
|
92
|
-
this.mathField.cmd(vv);
|
|
93
|
-
});
|
|
94
|
-
} else {
|
|
95
|
-
this.mathField.cmd(v);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.mathField.focus();
|
|
99
|
-
|
|
100
|
-
return this.mathField.latex();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
keystroke(v) {
|
|
104
|
-
this.mathField.keystroke(v);
|
|
105
|
-
this.mathField.focus();
|
|
106
|
-
|
|
107
|
-
return this.mathField.latex();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
write(v) {
|
|
111
|
-
log('write: ', v);
|
|
112
|
-
this.mathField.write(v);
|
|
113
|
-
this.mathField.focus();
|
|
114
|
-
|
|
115
|
-
return this.mathField.latex();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
onInputEdit: any = () => {
|
|
119
|
-
log('[onInputEdit] ...');
|
|
120
|
-
const { onChange } = this.props;
|
|
121
|
-
|
|
122
|
-
if (!this.mathField) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (onChange) {
|
|
127
|
-
onChange(this.mathField.latex());
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
refresh: any = () => {
|
|
132
|
-
this.blur();
|
|
133
|
-
this.focus();
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
onKeyPress: any = (event) => {
|
|
137
|
-
if (event.charCode === 13) {
|
|
138
|
-
event.preventDefault();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
onClick: any = (event) => {
|
|
143
|
-
const { onClick } = this.props;
|
|
144
|
-
|
|
145
|
-
this.refresh();
|
|
146
|
-
onClick && onClick(event);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
shouldComponentUpdate(nextProps) {
|
|
150
|
-
log('next: ', nextProps.latex);
|
|
151
|
-
log('current: ', this.mathField.latex());
|
|
152
|
-
|
|
153
|
-
return nextProps.latex !== this.mathField.latex();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
render() {
|
|
157
|
-
const { onFocus, onBlur, className } = this.props;
|
|
158
|
-
|
|
159
|
-
return (
|
|
160
|
-
<StyledSpan
|
|
161
|
-
className={className}
|
|
162
|
-
onKeyDown={this.onKeyPress}
|
|
163
|
-
onClick={this.onClick}
|
|
164
|
-
onFocus={onFocus}
|
|
165
|
-
onBlur={onBlur}
|
|
166
|
-
ref={(r) => (this.input = r)}
|
|
167
|
-
/>
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export default Input;
|