@pie-lib/math-toolbar 1.31.1 → 1.32.0-mui-update.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.
@@ -2,10 +2,10 @@ import React from 'react';
2
2
  import debug from 'debug';
3
3
  import PropTypes from 'prop-types';
4
4
  import cx from 'classnames';
5
- import Button from '@material-ui/core/Button';
6
- import { withStyles } from '@material-ui/core/styles';
7
- import MenuItem from '@material-ui/core/MenuItem';
8
- import Select from '@material-ui/core/Select';
5
+ import Button from '@mui/material/Button';
6
+ import { styled } from '@mui/material/styles';
7
+ import MenuItem from '@mui/material/MenuItem';
8
+ import Select from '@mui/material/Select';
9
9
  import isEqual from 'lodash/isEqual';
10
10
 
11
11
  import { HorizontalKeypad, mq, updateSpans } from '@pie-lib/math-input';
@@ -17,6 +17,198 @@ const log = debug('@pie-lib:math-toolbar:editor-and-pad');
17
17
 
18
18
  const decimalRegex = /\.|,/g;
19
19
 
20
+ const MathToolbarContainer = styled('div')(({ theme }) => ({
21
+ zIndex: 9,
22
+ position: 'relative',
23
+ textAlign: 'center',
24
+ width: 'auto',
25
+ '& > .mq-math-mode': {
26
+ border: 'solid 1px lightgrey',
27
+ },
28
+ '& > .mq-focused': {
29
+ outline: 'none',
30
+ boxShadow: 'none',
31
+ border: `dotted 1px ${theme.palette.primary.main}`,
32
+ borderRadius: '0px',
33
+ },
34
+ '& .mq-overarrow-inner': {
35
+ border: 'none !important',
36
+ paddingTop: '0 !important',
37
+ },
38
+ '& .mq-overarrow-inner-right': {
39
+ display: 'none !important',
40
+ },
41
+ '& .mq-overarrow-inner-left': {
42
+ display: 'none !important',
43
+ },
44
+ '& .mq-longdiv-inner': {
45
+ borderTop: '1px solid !important',
46
+ paddingTop: '1.5px !important',
47
+ },
48
+ '& .mq-overarrow.mq-arrow-both': {
49
+ top: '7.8px',
50
+ marginTop: '0px',
51
+ minWidth: '1.23em',
52
+ },
53
+ '& .mq-parallelogram': {
54
+ lineHeight: 0.85,
55
+ },
56
+ }));
57
+
58
+ const InputAndTypeContainer = styled('div')(({ theme, hide }) => ({
59
+ display: hide ? 'none' : 'flex',
60
+ alignItems: 'center',
61
+ '& .mq-editable-field .mq-cursor': {
62
+ top: '-4px',
63
+ },
64
+ '& .mq-math-mode .mq-selection, .mq-editable-field .mq-selection': {
65
+ paddingTop: '18px',
66
+ },
67
+ '& .mq-math-mode .mq-overarrow': {
68
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
69
+ },
70
+ '& .mq-math-mode .mq-overline .mq-overline-inner': {
71
+ paddingTop: '0.4em !important',
72
+ },
73
+ '& .mq-overarrow.mq-arrow-both': {
74
+ minWidth: '1.23em',
75
+ '& *': {
76
+ lineHeight: '1 !important',
77
+ },
78
+ '&:before': {
79
+ top: '-0.45em',
80
+ left: '-1px',
81
+ },
82
+ '&:after': {
83
+ position: 'absolute !important',
84
+ top: '0px !important',
85
+ right: '-2px',
86
+ },
87
+ '&.mq-empty:after': {
88
+ top: '-0.45em',
89
+ },
90
+ },
91
+ '& .mq-overarrow.mq-arrow-right': {
92
+ '&:before': {
93
+ top: '-0.4em',
94
+ right: '-1px',
95
+ },
96
+ },
97
+ '& *': {
98
+ ...commonMqFontStyles,
99
+ ...supsubStyles,
100
+ ...longdivStyles,
101
+ '& .mq-math-mode .mq-sqrt-prefix': {
102
+ verticalAlign: 'baseline !important',
103
+ top: '1px !important',
104
+ left: '-0.1em !important',
105
+ },
106
+ '& .mq-math-mode .mq-overarc ': {
107
+ paddingTop: '0.45em !important',
108
+ },
109
+ '& .mq-math-mode .mq-empty': {
110
+ padding: '9px 1px !important',
111
+ },
112
+ '& .mq-math-mode .mq-root-block': {
113
+ paddingTop: '10px',
114
+ },
115
+ '& .mq-scaled .mq-sqrt-prefix': {
116
+ top: '0 !important',
117
+ },
118
+ '& .mq-math-mode .mq-longdiv .mq-longdiv-inner': {
119
+ marginLeft: '4px !important',
120
+ paddingTop: '6px !important',
121
+ paddingLeft: '6px !important',
122
+ },
123
+ '& .mq-math-mode .mq-paren': {
124
+ verticalAlign: 'top !important',
125
+ padding: '1px 0.1em !important',
126
+ },
127
+ '& .mq-math-mode .mq-sqrt-stem': {
128
+ borderTop: '0.07em solid',
129
+ marginLeft: '-1.5px',
130
+ marginTop: '-2px !important',
131
+ paddingTop: '5px !important',
132
+ },
133
+ '& .mq-math-mode .mq-denominator': {
134
+ marginTop: '-5px !important',
135
+ padding: '0.5em 0.1em 0.1em !important',
136
+ },
137
+ '& .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {
138
+ padding: '0 0.1em !important',
139
+ paddingBottom: '0 !important',
140
+ marginBottom: '-2px',
141
+ },
142
+ },
143
+ '& span[data-prime="true"]': {
144
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
145
+ },
146
+ }));
147
+
148
+ const SelectContainer = styled(InputContainer)({
149
+ flex: 'initial',
150
+ width: '25%',
151
+ minWidth: '100px',
152
+ marginLeft: '15px',
153
+ marginTop: '5px',
154
+ marginBottom: '5px',
155
+ marginRight: '5px',
156
+ '& label': {
157
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
158
+ },
159
+ '& div': {
160
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
161
+ },
162
+ });
163
+
164
+ const StyledSelect = styled(Select)({});
165
+
166
+ const InputContainerDiv = styled('div')(({ theme, error }) => ({
167
+ minWidth: '500px',
168
+ maxWidth: '900px',
169
+ minHeight: '30px',
170
+ width: '100%',
171
+ display: 'flex',
172
+ marginTop: theme.spacing(1),
173
+ marginBottom: theme.spacing(1),
174
+ ...(error && {
175
+ border: '2px solid red',
176
+ }),
177
+ '& .mq-sqrt-prefix .mq-scaled': {
178
+ verticalAlign: 'middle !important',
179
+ },
180
+ }));
181
+
182
+ const MathEditor = styled(mq.Input)(({ controlledKeypadMode }) => ({
183
+ maxWidth: controlledKeypadMode ? '400px' : '500px',
184
+ color: color.text(),
185
+ backgroundColor: color.background(),
186
+ padding: '2px',
187
+ }));
188
+
189
+ const AddAnswerBlockButton = styled(Button)({
190
+ position: 'absolute',
191
+ right: '12px',
192
+ border: '1px solid lightgrey',
193
+ });
194
+
195
+ const StyledHr = styled('hr')(({ theme }) => ({
196
+ padding: 0,
197
+ margin: 0,
198
+ height: '1px',
199
+ border: 'none',
200
+ borderBottom: `solid 1px ${theme.palette.primary.main}`,
201
+ }));
202
+
203
+ const KeyboardContainer = styled(HorizontalKeypad)(({ mode }) => ({
204
+ ...commonMqKeyboardStyles,
205
+ ...(mode === 'language' && {
206
+ '& *': {
207
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
208
+ },
209
+ }),
210
+ }));
211
+
20
212
  const toNodeData = (data) => {
21
213
  if (!data) {
22
214
  return;
@@ -56,7 +248,6 @@ export class EditorAndPad extends React.Component {
56
248
  onFocus: PropTypes.func,
57
249
  onBlur: PropTypes.func,
58
250
  onChange: PropTypes.func.isRequired,
59
- classes: PropTypes.object,
60
251
  setKeypadInteraction: PropTypes.func,
61
252
  };
62
253
 
@@ -218,7 +409,6 @@ export class EditorAndPad extends React.Component {
218
409
  latex,
219
410
  onFocus,
220
411
  onBlur,
221
- classes,
222
412
  error,
223
413
  } = this.props;
224
414
  const shouldShowKeypad = !controlledKeypad || (controlledKeypad && showKeypad);
@@ -227,11 +417,11 @@ export class EditorAndPad extends React.Component {
227
417
  log('[render]', latex);
228
418
 
229
419
  return (
230
- <div className={cx(classes.mathToolbar, classNames.mathToolbar)}>
231
- <div className={cx(classes.inputAndTypeContainer, { [classes.hide]: hideInput })}>
420
+ <MathToolbarContainer className={cx(classNames.mathToolbar)}>
421
+ <InputAndTypeContainer hide={hideInput}>
232
422
  {controlledKeypadMode && (
233
- <InputContainer label="Equation Editor" className={classes.selectContainer}>
234
- <Select className={classes.select} onChange={this.onEditorTypeChange} value={this.state.equationEditor}>
423
+ <SelectContainer label="Equation Editor">
424
+ <StyledSelect onChange={this.onEditorTypeChange} value={this.state.equationEditor}>
235
425
  <MenuItem value="non-negative-integers">Numeric - Non-Negative Integers</MenuItem>
236
426
  <MenuItem value="integers">Numeric - Integers</MenuItem>
237
427
  <MenuItem value="decimals">Numeric - Decimals</MenuItem>
@@ -244,11 +434,11 @@ export class EditorAndPad extends React.Component {
244
434
  <MenuItem value={'advanced-algebra'}>Advanced Algebra</MenuItem>
245
435
  <MenuItem value={'statistics'}>Statistics</MenuItem>
246
436
  <MenuItem value={'item-authoring'}>Item Authoring</MenuItem>
247
- </Select>
248
- </InputContainer>
437
+ </StyledSelect>
438
+ </SelectContainer>
249
439
  )}
250
- <div className={cx(classes.inputContainer, error ? classes.error : '')}>
251
- <mq.Input
440
+ <InputContainerDiv error={error}>
441
+ <MathEditor
252
442
  onFocus={() => {
253
443
  onFocus && onFocus();
254
444
  this.updateDisable(false);
@@ -257,243 +447,39 @@ export class EditorAndPad extends React.Component {
257
447
  this.updateDisable(false);
258
448
  onBlur && onBlur(event);
259
449
  }}
260
- className={cx(classes.mathEditor, classNames.editor, !controlledKeypadMode ? classes.longMathEditor : '')}
450
+ className={cx(classNames.editor)}
451
+ controlledKeypadMode={controlledKeypadMode}
261
452
  innerRef={(r) => (this.input = r)}
262
453
  latex={latex}
263
454
  onChange={this.onEditorChange}
264
455
  />
265
- </div>
266
- </div>
456
+ </InputContainerDiv>
457
+ </InputAndTypeContainer>
267
458
  {allowAnswerBlock && (
268
- <Button
269
- className={classes.addAnswerBlockButton}
459
+ <AddAnswerBlockButton
270
460
  type="primary"
271
461
  style={{ bottom: shouldShowKeypad ? '320px' : '20px' }}
272
462
  onClick={this.onAnswerBlockClick}
273
463
  disabled={addDisabled}
274
464
  >
275
465
  + Response Area
276
- </Button>
466
+ </AddAnswerBlockButton>
277
467
  )}
278
- <hr className={classes.hr} />
468
+ <StyledHr />
279
469
  {shouldShowKeypad && (
280
- <HorizontalKeypad
281
- className={cx(classes[keypadMode], classes.keyboard)}
470
+ <KeyboardContainer
471
+ mode={controlledKeypadMode ? this.state.equationEditor : keypadMode}
282
472
  controlledKeypadMode={controlledKeypadMode}
283
473
  layoutForKeyPad={layoutForKeyPad}
284
474
  additionalKeys={additionalKeys}
285
- mode={controlledKeypadMode ? this.state.equationEditor : keypadMode}
286
475
  onClick={this.onClick}
287
476
  noDecimal={noDecimal}
288
477
  setKeypadInteraction={setKeypadInteraction}
289
478
  />
290
479
  )}
291
- </div>
480
+ </MathToolbarContainer>
292
481
  );
293
482
  }
294
483
  }
295
484
 
296
- const styles = (theme) => ({
297
- inputAndTypeContainer: {
298
- display: 'flex',
299
- alignItems: 'center',
300
- '& .mq-editable-field .mq-cursor': {
301
- top: '-4px',
302
- },
303
- '& .mq-math-mode .mq-selection, .mq-editable-field .mq-selection': {
304
- paddingTop: '18px',
305
- },
306
- '& .mq-math-mode .mq-overarrow': {
307
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
308
- },
309
- '& .mq-math-mode .mq-overline .mq-overline-inner': {
310
- paddingTop: '0.4em !important',
311
- },
312
- '& .mq-overarrow.mq-arrow-both': {
313
- minWidth: '1.23em',
314
- '& *': {
315
- lineHeight: '1 !important',
316
- },
317
- '&:before': {
318
- top: '-0.45em',
319
- left: '-1px',
320
- },
321
- '&:after': {
322
- position: 'absolute !important',
323
- top: '0px !important',
324
- right: '-2px',
325
- },
326
- '&.mq-empty:after': {
327
- top: '-0.45em',
328
- },
329
- },
330
- '& .mq-overarrow.mq-arrow-right': {
331
- '&:before': {
332
- top: '-0.4em',
333
- right: '-1px',
334
- },
335
- },
336
-
337
- '& *': {
338
- ...commonMqFontStyles,
339
- ...supsubStyles,
340
- ...longdivStyles,
341
- '& .mq-math-mode .mq-sqrt-prefix': {
342
- verticalAlign: 'baseline !important',
343
- top: '1px !important',
344
- left: '-0.1em !important',
345
- },
346
-
347
- '& .mq-math-mode .mq-overarc ': {
348
- paddingTop: '0.45em !important',
349
- },
350
-
351
- '& .mq-math-mode .mq-empty': {
352
- padding: '9px 1px !important',
353
- },
354
-
355
- '& .mq-math-mode .mq-root-block': {
356
- paddingTop: '10px',
357
- },
358
-
359
- '& .mq-scaled .mq-sqrt-prefix': {
360
- top: '0 !important',
361
- },
362
-
363
- '& .mq-math-mode .mq-longdiv .mq-longdiv-inner': {
364
- marginLeft: '4px !important',
365
- paddingTop: '6px !important',
366
- paddingLeft: '6px !important',
367
- },
368
-
369
- '& .mq-math-mode .mq-paren': {
370
- verticalAlign: 'top !important',
371
- padding: '1px 0.1em !important',
372
- },
373
-
374
- '& .mq-math-mode .mq-sqrt-stem': {
375
- borderTop: '0.07em solid',
376
- marginLeft: '-1.5px',
377
- marginTop: '-2px !important',
378
- paddingTop: '5px !important',
379
- },
380
-
381
- '& .mq-math-mode .mq-denominator': {
382
- marginTop: '-5px !important',
383
- padding: '0.5em 0.1em 0.1em !important',
384
- },
385
-
386
- '& .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {
387
- padding: '0 0.1em !important',
388
- paddingBottom: '0 !important',
389
- marginBottom: '-2px',
390
- },
391
- },
392
-
393
- '& span[data-prime="true"]': {
394
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
395
- },
396
- },
397
- hide: {
398
- display: 'none',
399
- },
400
- selectContainer: {
401
- flex: 'initial',
402
- width: '25%',
403
- minWidth: '100px',
404
- marginLeft: '15px',
405
- marginTop: '5px',
406
- marginBottom: '5px',
407
- marginRight: '5px',
408
-
409
- '& label': {
410
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
411
- },
412
-
413
- '& div': {
414
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
415
- },
416
- },
417
- mathEditor: {
418
- maxWidth: '400px',
419
- color: color.text(),
420
- backgroundColor: color.background(),
421
- padding: '2px',
422
- },
423
- longMathEditor: {
424
- maxWidth: '500px',
425
- },
426
- addAnswerBlockButton: {
427
- position: 'absolute',
428
- right: '12px',
429
- border: '1px solid lightgrey',
430
- },
431
- hr: {
432
- padding: 0,
433
- margin: 0,
434
- height: '1px',
435
- border: 'none',
436
- borderBottom: `solid 1px ${theme.palette.primary.main}`,
437
- },
438
- mathToolbar: {
439
- zIndex: 9,
440
- position: 'relative',
441
- textAlign: 'center',
442
- width: 'auto',
443
- '& > .mq-math-mode': {
444
- border: 'solid 1px lightgrey',
445
- },
446
- '& > .mq-focused': {
447
- outline: 'none',
448
- boxShadow: 'none',
449
- border: `dotted 1px ${theme.palette.primary.main}`,
450
- borderRadius: '0px',
451
- },
452
- '& .mq-overarrow-inner': {
453
- border: 'none !important',
454
- paddingTop: '0 !important',
455
- },
456
- '& .mq-overarrow-inner-right': {
457
- display: 'none !important',
458
- },
459
- '& .mq-overarrow-inner-left': {
460
- display: 'none !important',
461
- },
462
- '& .mq-longdiv-inner': {
463
- borderTop: '1px solid !important',
464
- paddingTop: '1.5px !important',
465
- },
466
- '& .mq-overarrow.mq-arrow-both': {
467
- top: '7.8px',
468
- marginTop: '0px',
469
- minWidth: '1.23em',
470
- },
471
- '& .mq-parallelogram': {
472
- lineHeight: 0.85,
473
- },
474
- },
475
- inputContainer: {
476
- minWidth: '500px',
477
- maxWidth: '900px',
478
- minHeight: '30px',
479
- width: '100%',
480
- display: 'flex',
481
- marginTop: theme.spacing.unit,
482
- marginBottom: theme.spacing.unit,
483
-
484
- '& .mq-sqrt-prefix .mq-scaled': {
485
- verticalAlign: 'middle !important',
486
- },
487
- },
488
- error: {
489
- border: '2px solid red',
490
- },
491
- keyboard: commonMqKeyboardStyles,
492
- language: {
493
- '& *': {
494
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
495
- },
496
- },
497
- });
498
-
499
- export default withStyles(styles)(EditorAndPad);
485
+ export default EditorAndPad;
package/src/index.jsx CHANGED
@@ -3,11 +3,18 @@ import PropTypes from 'prop-types';
3
3
  import cx from 'classnames';
4
4
  import EditorAndPad from './editor-and-pad';
5
5
  import { DoneButton } from './done-button';
6
- import { withStyles } from '@material-ui/core/styles';
6
+ import { styled } from '@mui/material/styles';
7
7
  import MathPreview from './math-preview';
8
8
 
9
9
  export { MathPreview };
10
10
 
11
+ const PureToolbarContainer = styled('div')({
12
+ display: 'flex',
13
+ width: '100%',
14
+ zIndex: 8,
15
+ alignItems: 'center',
16
+ });
17
+
11
18
  export class MathToolbar extends React.Component {
12
19
  static propTypes = {
13
20
  autoFocus: PropTypes.bool,
@@ -131,7 +138,6 @@ export class RawPureToolbar extends React.Component {
131
138
  onAnswerBlockAdd: PropTypes.func,
132
139
  additionalKeys: PropTypes.array,
133
140
  onFocus: PropTypes.func,
134
- classes: PropTypes.object.isRequired,
135
141
  autoFocus: PropTypes.bool,
136
142
  noDecimal: PropTypes.bool,
137
143
  allowAnswerBlock: PropTypes.bool,
@@ -175,13 +181,12 @@ export class RawPureToolbar extends React.Component {
175
181
  onBlur,
176
182
  hideDoneButton,
177
183
  hideDoneButtonBackground,
178
- classes,
179
184
  error,
180
185
  maxResponseAreas,
181
186
  } = this.props;
182
187
 
183
188
  return (
184
- <div className={cx(classes.pureToolbar, (classNames || {}).toolbar)} ref={keyPadCharacterRef}>
189
+ <PureToolbarContainer className={cx((classNames || {}).toolbar)} ref={keyPadCharacterRef}>
185
190
  <div />
186
191
  <EditorAndPad
187
192
  autoFocus={autoFocus}
@@ -208,17 +213,9 @@ export class RawPureToolbar extends React.Component {
208
213
  {(!controlledKeypad || (controlledKeypad && showKeypad)) && !hideDoneButton && (
209
214
  <DoneButton hideBackground={hideDoneButtonBackground} onClick={onDone} />
210
215
  )}
211
- </div>
216
+ </PureToolbarContainer>
212
217
  );
213
218
  }
214
219
  }
215
- const styles = () => ({
216
- pureToolbar: {
217
- display: 'flex',
218
- width: '100%',
219
- zIndex: 8,
220
- alignItems: 'center',
221
- },
222
- });
223
220
 
224
- export const PureToolbar = withStyles(styles)(RawPureToolbar);
221
+ export const PureToolbar = RawPureToolbar;