@pie-lib/math-toolbar 3.1.0-beta.9 → 4.0.0-next.42

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/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;
@@ -1,174 +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-mathlive';
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, outlineOnWrapper }) => ({
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
- '& .ML__latex': {
23
- border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',
24
- padding: isSelected ? '0px' : '5px',
25
- },
26
- ...(!outlineOnWrapper && {
27
- '&:not(:has(.ML__latex))': {
28
- border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',
29
- padding: isSelected ? '0px' : '5px',
30
- },
31
- }),
32
- '& > .mq-focused': {
33
- outline: 'none',
34
- boxShadow: 'none',
35
- border: 'solid 1px black',
36
- borderRadius: '0px',
37
- },
38
- '& > .mq-math-mode .mq-root-block': {
39
- paddingTop: '7px !important',
40
- },
41
- '& > .mq-math-mode .mq-overarc ': {
42
- paddingTop: '0.45em !important',
43
- },
44
- '& > .mq-math-mode .mq-sqrt-prefix': {
45
- verticalAlign: 'baseline !important',
46
- top: '1px !important',
47
- left: '-0.1em !important',
48
- },
49
- '& > .mq-math-mode .mq-denominator': {
50
- marginTop: '-5px !important',
51
- padding: '0.5em 0.1em 0.1em !important',
52
- },
53
- '& > .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {
54
- padding: '0 0.1em !important',
55
- paddingBottom: '0 !important',
56
- marginBottom: '-2px',
57
- },
58
- '& > .mq-math-mode .mq-longdiv .mq-longdiv-inner .mq-empty': {
59
- paddingTop: '6px !important',
60
- paddingLeft: '4px !important',
61
- },
62
- '& > .mq-math-mode .mq-longdiv .mq-longdiv-inner': {
63
- marginLeft: '0 !important',
64
- },
65
- '& > .mq-math-mode .mq-overarrow': {
66
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
67
- },
68
- '& > .mq-math-mode .mq-paren': {
69
- verticalAlign: 'top !important',
70
- padding: '1px 0.1em !important',
71
- },
72
- '& > .mq-math-mode .mq-sqrt-stem': {
73
- borderTop: '0.07em solid',
74
- marginLeft: '-1.5px',
75
- marginTop: '-2px !important',
76
- paddingTop: '5px !important',
77
- },
78
- '& .mq-overarrow-inner': {
79
- paddingTop: '0 !important',
80
- border: 'none !important',
81
- },
82
- '& .mq-editable-field .mq-cursor': {
83
- marginTop: '-15px !important',
84
- },
85
- '& .mq-overarrow.mq-arrow-both': {
86
- top: '7.5px',
87
- marginTop: '0px',
88
- minWidth: '1.23em',
89
- '& *': {
90
- lineHeight: '1 !important',
91
- },
92
- '&:before': {
93
- top: '-0.4em',
94
- left: '-1px',
95
- },
96
- '&:after': {
97
- top: '0px !important',
98
- position: 'absolute !important',
99
- right: '-2px',
100
- },
101
- '&.mq-empty:after': {
102
- top: '-0.45em',
103
- },
104
- },
105
- '& .mq-overarrow.mq-arrow-right': {
106
- '&:before': {
107
- top: '-0.4em',
108
- right: '-1px',
109
- },
110
- },
111
- '& .mq-overarrow-inner-right': {
112
- display: 'none !important',
113
- },
114
- '& .mq-overarrow-inner-left': {
115
- display: 'none !important',
116
- },
117
- '& .mq-longdiv-inner': {
118
- borderTop: '1px solid !important',
119
- paddingTop: '1.5px !important',
120
- },
121
- '& .mq-parallelogram': {
122
- lineHeight: 0.85,
123
- },
124
- '& span[data-prime="true"]': {
125
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
126
- },
127
- ...(isSelected &&
128
- !outlineOnWrapper && {
129
- border: `solid 1px ${theme.palette.primary.main}`,
130
- }),
131
- }));
132
-
133
- const InsideOverlay = styled('span')({
134
- position: 'absolute',
135
- bottom: 0,
136
- left: 0,
137
- right: 0,
138
- top: 0,
139
- });
140
-
141
- export class RawMathPreview extends React.Component {
142
- static propTypes = {
143
- latex: PropTypes.string,
144
- isSelected: PropTypes.bool,
145
- outlineOnWrapper: PropTypes.bool,
146
- onFocus: PropTypes.func,
147
- onBlur: PropTypes.func,
148
- };
149
-
150
- componentDidMount() {
151
- markFractionBaseSuperscripts();
152
- }
153
-
154
- componentDidUpdate(prevProps) {
155
- // Re-run only if LaTeX changed
156
- if (this.props.latex !== prevProps.latex) {
157
- markFractionBaseSuperscripts();
158
- }
159
- }
160
-
161
- render() {
162
- const { isSelected, outlineOnWrapper, onFocus, onBlur, latex } = this.props;
163
- log('[render] latex: ', latex);
164
- return (
165
- <MathPreviewContainer isSelected={isSelected} outlineOnWrapper={outlineOnWrapper}>
166
- {' '}
167
- <InsideOverlay />
168
- <mq.Static latex={latex} onFocus={onFocus} onBlur={onBlur} />
169
- </MathPreviewContainer>
170
- );
171
- }
172
- }
173
-
174
- 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
- };