@pie-lib/math-toolbar 3.0.3-next.36 → 3.0.3-next.37
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/done-button.d.ts +30 -0
- package/dist/done-button.js +34 -0
- package/dist/editor-and-pad.d.ts +47 -0
- package/dist/editor-and-pad.js +352 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +158 -0
- package/dist/math-preview.d.ts +22 -0
- package/dist/math-preview.js +125 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +9 -0
- package/package.json +31 -25
- package/CHANGELOG.json +0 -17
- package/CHANGELOG.md +0 -1049
- package/LICENSE.md +0 -5
- package/lib/done-button.js +0 -51
- package/lib/done-button.js.map +0 -1
- package/lib/editor-and-pad.js +0 -528
- package/lib/editor-and-pad.js.map +0 -1
- package/lib/index.js +0 -241
- package/lib/index.js.map +0 -1
- package/lib/math-preview.js +0 -192
- package/lib/math-preview.js.map +0 -1
- package/lib/utils.js +0 -17
- package/lib/utils.js.map +0 -1
- package/src/__tests__/editor-and-pad.test.js +0 -16
- package/src/__tests__/index.test.js +0 -21
- package/src/__tests__/math-preview.test.js +0 -18
- package/src/done-button.jsx +0 -36
- package/src/editor-and-pad.jsx +0 -498
- package/src/index.jsx +0 -220
- package/src/math-preview.jsx +0 -162
- package/src/utils.js +0 -11
package/src/index.jsx
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import EditorAndPad from './editor-and-pad';
|
|
4
|
-
import { DoneButton } from './done-button';
|
|
5
|
-
import { styled } from '@mui/material/styles';
|
|
6
|
-
import MathPreview from './math-preview';
|
|
7
|
-
|
|
8
|
-
export { MathPreview };
|
|
9
|
-
|
|
10
|
-
const PureToolbarContainer = styled('div')({
|
|
11
|
-
display: 'flex',
|
|
12
|
-
width: '100%',
|
|
13
|
-
zIndex: 8,
|
|
14
|
-
alignItems: 'center',
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export class MathToolbar extends React.Component {
|
|
18
|
-
static propTypes = {
|
|
19
|
-
autoFocus: PropTypes.bool,
|
|
20
|
-
allowAnswerBlock: PropTypes.bool,
|
|
21
|
-
controlledKeypad: PropTypes.bool,
|
|
22
|
-
controlledKeypadMode: PropTypes.bool,
|
|
23
|
-
keypadMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
24
|
-
classNames: PropTypes.object,
|
|
25
|
-
error: PropTypes.string,
|
|
26
|
-
maxResponseAreas: PropTypes.number,
|
|
27
|
-
showKeypad: PropTypes.bool,
|
|
28
|
-
noDecimal: PropTypes.bool,
|
|
29
|
-
additionalKeys: PropTypes.array,
|
|
30
|
-
latex: PropTypes.string.isRequired,
|
|
31
|
-
onAnswerBlockAdd: PropTypes.func,
|
|
32
|
-
onChange: PropTypes.func,
|
|
33
|
-
onDone: PropTypes.func.isRequired,
|
|
34
|
-
onFocus: PropTypes.func,
|
|
35
|
-
onBlur: PropTypes.func,
|
|
36
|
-
hideDoneButton: PropTypes.bool,
|
|
37
|
-
keyPadCharacterRef: PropTypes.func,
|
|
38
|
-
setKeypadInteraction: PropTypes.func,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
static defaultProps = {
|
|
42
|
-
classNames: {},
|
|
43
|
-
keypadMode: 'item-authoring',
|
|
44
|
-
autoFocus: false,
|
|
45
|
-
allowAnswerBlock: false,
|
|
46
|
-
controlledKeypad: false,
|
|
47
|
-
controlledKeypadMode: false,
|
|
48
|
-
noDecimal: false,
|
|
49
|
-
showKeypad: true,
|
|
50
|
-
additionalKeys: [],
|
|
51
|
-
onChange: () => {},
|
|
52
|
-
onAnswerBlockAdd: () => {},
|
|
53
|
-
onFocus: () => {},
|
|
54
|
-
hideDoneButton: false,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
constructor(props) {
|
|
58
|
-
super(props);
|
|
59
|
-
this.state = {
|
|
60
|
-
latex: props.latex,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
done = () => {
|
|
65
|
-
this.props.onDone(this.state.latex);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
69
|
-
this.setState({ latex: nextProps.latex });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
onChange = (latex) => {
|
|
73
|
-
this.setState({ latex });
|
|
74
|
-
this.props.onChange(latex);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
render() {
|
|
78
|
-
const { latex } = this.state;
|
|
79
|
-
const {
|
|
80
|
-
classNames,
|
|
81
|
-
autoFocus,
|
|
82
|
-
allowAnswerBlock,
|
|
83
|
-
onAnswerBlockAdd,
|
|
84
|
-
controlledKeypad,
|
|
85
|
-
controlledKeypadMode,
|
|
86
|
-
keypadMode,
|
|
87
|
-
noDecimal,
|
|
88
|
-
additionalKeys,
|
|
89
|
-
showKeypad,
|
|
90
|
-
onFocus,
|
|
91
|
-
onBlur,
|
|
92
|
-
hideDoneButton,
|
|
93
|
-
error,
|
|
94
|
-
keyPadCharacterRef,
|
|
95
|
-
setKeypadInteraction,
|
|
96
|
-
maxResponseAreas,
|
|
97
|
-
} = this.props;
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<PureToolbar
|
|
101
|
-
autoFocus={autoFocus}
|
|
102
|
-
classNames={classNames}
|
|
103
|
-
onAnswerBlockAdd={onAnswerBlockAdd}
|
|
104
|
-
allowAnswerBlock={allowAnswerBlock}
|
|
105
|
-
latex={latex}
|
|
106
|
-
additionalKeys={additionalKeys}
|
|
107
|
-
noDecimal={noDecimal}
|
|
108
|
-
keypadMode={keypadMode}
|
|
109
|
-
keyPadCharacterRef={keyPadCharacterRef}
|
|
110
|
-
setKeypadInteraction={setKeypadInteraction}
|
|
111
|
-
onChange={this.onChange}
|
|
112
|
-
onDone={this.done}
|
|
113
|
-
onFocus={onFocus}
|
|
114
|
-
onBlur={onBlur}
|
|
115
|
-
showKeypad={showKeypad}
|
|
116
|
-
controlledKeypad={controlledKeypad}
|
|
117
|
-
controlledKeypadMode={controlledKeypadMode}
|
|
118
|
-
hideDoneButton={hideDoneButton}
|
|
119
|
-
error={error}
|
|
120
|
-
maxResponseAreas={maxResponseAreas}
|
|
121
|
-
/>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export class RawPureToolbar extends React.Component {
|
|
127
|
-
static propTypes = {
|
|
128
|
-
classNames: PropTypes.object,
|
|
129
|
-
latex: PropTypes.string.isRequired,
|
|
130
|
-
keypadMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
131
|
-
hideInput: PropTypes.bool,
|
|
132
|
-
noLatexHandling: PropTypes.bool,
|
|
133
|
-
layoutForKeyPad: PropTypes.object,
|
|
134
|
-
onChange: PropTypes.func.isRequired,
|
|
135
|
-
onDone: PropTypes.func.isRequired,
|
|
136
|
-
onBlur: PropTypes.func,
|
|
137
|
-
onAnswerBlockAdd: PropTypes.func,
|
|
138
|
-
additionalKeys: PropTypes.array,
|
|
139
|
-
onFocus: PropTypes.func,
|
|
140
|
-
autoFocus: PropTypes.bool,
|
|
141
|
-
noDecimal: PropTypes.bool,
|
|
142
|
-
allowAnswerBlock: PropTypes.bool,
|
|
143
|
-
controlledKeypad: PropTypes.bool,
|
|
144
|
-
controlledKeypadMode: PropTypes.bool,
|
|
145
|
-
showKeypad: PropTypes.bool,
|
|
146
|
-
hideDoneButton: PropTypes.bool,
|
|
147
|
-
hideDoneButtonBackground: PropTypes.bool,
|
|
148
|
-
error: PropTypes.any,
|
|
149
|
-
maxResponseAreas: PropTypes.number,
|
|
150
|
-
keyPadCharacterRef: PropTypes.object,
|
|
151
|
-
setKeypadInteraction: PropTypes.func,
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
static defaultProps = {
|
|
155
|
-
classNames: {},
|
|
156
|
-
hideDoneButtonBackground: false,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
render() {
|
|
160
|
-
const {
|
|
161
|
-
classNames,
|
|
162
|
-
autoFocus,
|
|
163
|
-
allowAnswerBlock,
|
|
164
|
-
onAnswerBlockAdd,
|
|
165
|
-
controlledKeypad,
|
|
166
|
-
controlledKeypadMode,
|
|
167
|
-
additionalKeys,
|
|
168
|
-
showKeypad,
|
|
169
|
-
keypadMode,
|
|
170
|
-
noDecimal,
|
|
171
|
-
hideInput,
|
|
172
|
-
noLatexHandling,
|
|
173
|
-
layoutForKeyPad,
|
|
174
|
-
keyPadCharacterRef,
|
|
175
|
-
setKeypadInteraction,
|
|
176
|
-
latex,
|
|
177
|
-
onChange,
|
|
178
|
-
onDone,
|
|
179
|
-
onFocus,
|
|
180
|
-
onBlur,
|
|
181
|
-
hideDoneButton,
|
|
182
|
-
hideDoneButtonBackground,
|
|
183
|
-
error,
|
|
184
|
-
maxResponseAreas,
|
|
185
|
-
} = this.props;
|
|
186
|
-
|
|
187
|
-
return (
|
|
188
|
-
<PureToolbarContainer className={(classNames && classNames.toolbar) || ''} ref={keyPadCharacterRef}>
|
|
189
|
-
<div />
|
|
190
|
-
<EditorAndPad
|
|
191
|
-
autoFocus={autoFocus}
|
|
192
|
-
keypadMode={keypadMode}
|
|
193
|
-
classNames={classNames || {}}
|
|
194
|
-
controlledKeypad={controlledKeypad}
|
|
195
|
-
controlledKeypadMode={controlledKeypadMode}
|
|
196
|
-
noDecimal={noDecimal}
|
|
197
|
-
hideInput={hideInput}
|
|
198
|
-
noLatexHandling={noLatexHandling}
|
|
199
|
-
layoutForKeyPad={layoutForKeyPad}
|
|
200
|
-
showKeypad={showKeypad}
|
|
201
|
-
additionalKeys={additionalKeys}
|
|
202
|
-
allowAnswerBlock={allowAnswerBlock}
|
|
203
|
-
onAnswerBlockAdd={onAnswerBlockAdd}
|
|
204
|
-
latex={latex}
|
|
205
|
-
onChange={onChange}
|
|
206
|
-
onFocus={onFocus}
|
|
207
|
-
onBlur={onBlur}
|
|
208
|
-
error={error}
|
|
209
|
-
maxResponseAreas={maxResponseAreas}
|
|
210
|
-
setKeypadInteraction={setKeypadInteraction}
|
|
211
|
-
/>
|
|
212
|
-
{(!controlledKeypad || (controlledKeypad && showKeypad)) && !hideDoneButton && (
|
|
213
|
-
<DoneButton hideBackground={hideDoneButtonBackground} onClick={onDone} />
|
|
214
|
-
)}
|
|
215
|
-
</PureToolbarContainer>
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export const PureToolbar = RawPureToolbar;
|
package/src/math-preview.jsx
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import debug from 'debug';
|
|
3
|
-
import { styled } from '@mui/material/styles';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { mq } from '@pie-lib/math-input';
|
|
6
|
-
import { markFractionBaseSuperscripts } from './utils';
|
|
7
|
-
|
|
8
|
-
const { commonMqFontStyles, longdivStyles, supsubStyles } = mq.CommonMqStyles;
|
|
9
|
-
|
|
10
|
-
const log = debug('@pie-lib:math-toolbar:math-preview');
|
|
11
|
-
|
|
12
|
-
const MathPreviewContainer = styled('div')(({ theme, isSelected }) => ({
|
|
13
|
-
display: 'inline-flex',
|
|
14
|
-
alignItems: 'center',
|
|
15
|
-
position: 'relative',
|
|
16
|
-
'& *': commonMqFontStyles,
|
|
17
|
-
...supsubStyles,
|
|
18
|
-
...longdivStyles,
|
|
19
|
-
'& > .mq-math-mode': {
|
|
20
|
-
border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',
|
|
21
|
-
},
|
|
22
|
-
'& > .mq-focused': {
|
|
23
|
-
outline: 'none',
|
|
24
|
-
boxShadow: 'none',
|
|
25
|
-
border: 'solid 1px black',
|
|
26
|
-
borderRadius: '0px',
|
|
27
|
-
},
|
|
28
|
-
'& > .mq-math-mode .mq-root-block': {
|
|
29
|
-
paddingTop: '7px !important',
|
|
30
|
-
},
|
|
31
|
-
'& > .mq-math-mode .mq-overarc ': {
|
|
32
|
-
paddingTop: '0.45em !important',
|
|
33
|
-
},
|
|
34
|
-
'& > .mq-math-mode .mq-sqrt-prefix': {
|
|
35
|
-
verticalAlign: 'baseline !important',
|
|
36
|
-
top: '1px !important',
|
|
37
|
-
left: '-0.1em !important',
|
|
38
|
-
},
|
|
39
|
-
'& > .mq-math-mode .mq-denominator': {
|
|
40
|
-
marginTop: '-5px !important',
|
|
41
|
-
padding: '0.5em 0.1em 0.1em !important',
|
|
42
|
-
},
|
|
43
|
-
'& > .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {
|
|
44
|
-
padding: '0 0.1em !important',
|
|
45
|
-
paddingBottom: '0 !important',
|
|
46
|
-
marginBottom: '-2px',
|
|
47
|
-
},
|
|
48
|
-
'& > .mq-math-mode .mq-longdiv .mq-longdiv-inner .mq-empty': {
|
|
49
|
-
paddingTop: '6px !important',
|
|
50
|
-
paddingLeft: '4px !important',
|
|
51
|
-
},
|
|
52
|
-
'& > .mq-math-mode .mq-longdiv .mq-longdiv-inner': {
|
|
53
|
-
marginLeft: '0 !important',
|
|
54
|
-
},
|
|
55
|
-
'& > .mq-math-mode .mq-overarrow': {
|
|
56
|
-
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
|
|
57
|
-
},
|
|
58
|
-
'& > .mq-math-mode .mq-paren': {
|
|
59
|
-
verticalAlign: 'top !important',
|
|
60
|
-
padding: '1px 0.1em !important',
|
|
61
|
-
},
|
|
62
|
-
'& > .mq-math-mode .mq-sqrt-stem': {
|
|
63
|
-
borderTop: '0.07em solid',
|
|
64
|
-
marginLeft: '-1.5px',
|
|
65
|
-
marginTop: '-2px !important',
|
|
66
|
-
paddingTop: '5px !important',
|
|
67
|
-
},
|
|
68
|
-
'& .mq-overarrow-inner': {
|
|
69
|
-
paddingTop: '0 !important',
|
|
70
|
-
border: 'none !important',
|
|
71
|
-
},
|
|
72
|
-
'& .mq-editable-field .mq-cursor': {
|
|
73
|
-
marginTop: '-15px !important',
|
|
74
|
-
},
|
|
75
|
-
'& .mq-overarrow.mq-arrow-both': {
|
|
76
|
-
top: '7.5px',
|
|
77
|
-
marginTop: '0px',
|
|
78
|
-
minWidth: '1.23em',
|
|
79
|
-
'& *': {
|
|
80
|
-
lineHeight: '1 !important',
|
|
81
|
-
},
|
|
82
|
-
'&:before': {
|
|
83
|
-
top: '-0.4em',
|
|
84
|
-
left: '-1px',
|
|
85
|
-
},
|
|
86
|
-
'&:after': {
|
|
87
|
-
top: '0px !important',
|
|
88
|
-
position: 'absolute !important',
|
|
89
|
-
right: '-2px',
|
|
90
|
-
},
|
|
91
|
-
'&.mq-empty:after': {
|
|
92
|
-
top: '-0.45em',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
'& .mq-overarrow.mq-arrow-right': {
|
|
96
|
-
'&:before': {
|
|
97
|
-
top: '-0.4em',
|
|
98
|
-
right: '-1px',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
'& .mq-overarrow-inner-right': {
|
|
102
|
-
display: 'none !important',
|
|
103
|
-
},
|
|
104
|
-
'& .mq-overarrow-inner-left': {
|
|
105
|
-
display: 'none !important',
|
|
106
|
-
},
|
|
107
|
-
'& .mq-longdiv-inner': {
|
|
108
|
-
borderTop: '1px solid !important',
|
|
109
|
-
paddingTop: '1.5px !important',
|
|
110
|
-
},
|
|
111
|
-
'& .mq-parallelogram': {
|
|
112
|
-
lineHeight: 0.85,
|
|
113
|
-
},
|
|
114
|
-
'& span[data-prime="true"]': {
|
|
115
|
-
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
|
|
116
|
-
},
|
|
117
|
-
...(isSelected && {
|
|
118
|
-
border: `solid 1px ${theme.palette.primary.main}`,
|
|
119
|
-
}),
|
|
120
|
-
}));
|
|
121
|
-
|
|
122
|
-
const InsideOverlay = styled('span')({
|
|
123
|
-
position: 'absolute',
|
|
124
|
-
bottom: 0,
|
|
125
|
-
left: 0,
|
|
126
|
-
right: 0,
|
|
127
|
-
top: 0,
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
export class RawMathPreview extends React.Component {
|
|
131
|
-
static propTypes = {
|
|
132
|
-
latex: PropTypes.string,
|
|
133
|
-
isSelected: PropTypes.bool,
|
|
134
|
-
onFocus: PropTypes.func,
|
|
135
|
-
onBlur: PropTypes.func,
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
componentDidMount() {
|
|
139
|
-
markFractionBaseSuperscripts();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
componentDidUpdate(prevProps) {
|
|
143
|
-
// Re-run only if LaTeX changed
|
|
144
|
-
if (this.props.latex !== prevProps.latex) {
|
|
145
|
-
markFractionBaseSuperscripts();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
render() {
|
|
150
|
-
const { isSelected, onFocus, onBlur, latex } = this.props;
|
|
151
|
-
log('[render] latex: ', latex);
|
|
152
|
-
return (
|
|
153
|
-
<MathPreviewContainer isSelected={isSelected}>
|
|
154
|
-
{' '}
|
|
155
|
-
<InsideOverlay />
|
|
156
|
-
<mq.Static latex={latex} onFocus={onFocus} onBlur={onBlur} />
|
|
157
|
-
</MathPreviewContainer>
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export default RawMathPreview;
|
package/src/utils.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const markFractionBaseSuperscripts = () => {
|
|
2
|
-
document.querySelectorAll('.mq-supsub.mq-sup-only').forEach((supsub) => {
|
|
3
|
-
const prev = supsub.previousElementSibling;
|
|
4
|
-
|
|
5
|
-
if (prev && prev.classList.contains('mq-non-leaf') && prev.querySelector('.mq-fraction')) {
|
|
6
|
-
supsub.classList.add('mq-after-fraction-group');
|
|
7
|
-
} else {
|
|
8
|
-
supsub.classList.remove('mq-after-fraction-group');
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
};
|