@pie-lib/math-toolbar 1.11.23-next.0 → 2.0.0-beta.1

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.
@@ -1,90 +1,67 @@
1
1
  import React from 'react';
2
2
  import classNames from 'classnames';
3
+ import get from 'lodash/get';
3
4
  import debug from 'debug';
4
- import { withStyles } from '@material-ui/core/styles';
5
+ import { makeStyles } from '@material-ui/styles';
5
6
  import PropTypes from 'prop-types';
6
7
  import { mq } from '@pie-lib/math-input';
7
8
 
8
9
  const log = debug('@pie-lib:math-toolbar:math-preview');
9
10
 
10
- export class RawMathPreview extends React.Component {
11
- static propTypes = {
12
- latex: PropTypes.string,
13
- node: PropTypes.object,
14
- classes: PropTypes.object,
15
- isSelected: PropTypes.bool,
16
- onFocus: PropTypes.func,
17
- onBlur: PropTypes.func,
18
- };
19
-
20
- render() {
21
- log('[render] data: ', this.props.node.data);
22
- const latex = this.props.node.data.get('latex');
23
- const { classes, isSelected, onFocus, onBlur } = this.props;
24
- return (
25
- <div className={classNames(classes.root, isSelected && classes.selected)}>
26
- {' '}
27
- <span className={classes.insideOverlay} />
28
- <mq.Static latex={latex} onFocus={onFocus} onBlur={onBlur} />
29
- </div>
30
- );
31
- }
32
- }
33
-
34
- const mp = (theme) => ({
11
+ const useStyles = makeStyles(theme => ({
35
12
  root: {
36
13
  display: 'inline-flex',
37
14
  alignItems: 'center',
38
15
  position: 'relative',
39
16
  '& *': {
40
17
  fontFamily: 'MJXZERO, MJXTEX !important',
41
- '-webkit-font-smoothing': 'antialiased !important',
18
+ '-webkit-font-smoothing': 'antialiased !important'
42
19
  },
43
20
  '& > .mq-math-mode > span > var': {
44
- fontFamily: 'MJXZERO, MJXTEX-I !important',
21
+ fontFamily: 'MJXZERO, MJXTEX-I !important'
45
22
  },
46
23
  '& > .mq-math-mode span var': {
47
- fontFamily: 'MJXZERO, MJXTEX-I !important',
24
+ fontFamily: 'MJXZERO, MJXTEX-I !important'
48
25
  },
49
26
  '& > .mq-math-mode .mq-nonSymbola': {
50
- fontFamily: 'MJXZERO, MJXTEX-I !important',
27
+ fontFamily: 'MJXZERO, MJXTEX-I !important'
51
28
  },
52
29
  '& > .mq-math-mode > span > var.mq-operator-name': {
53
- fontFamily: 'MJXZERO, MJXTEX !important',
30
+ fontFamily: 'MJXZERO, MJXTEX !important'
54
31
  },
55
32
  '& > .mq-math-mode': {
56
- border: 'solid 1px lightgrey',
33
+ border: 'solid 1px lightgrey'
57
34
  },
58
35
  '& > .mq-focused': {
59
36
  outline: 'none',
60
37
  boxShadow: 'none',
61
38
  border: 'solid 1px black',
62
- borderRadius: '0px',
39
+ borderRadius: '0px'
63
40
  },
64
41
  '& > .mq-math-mode .mq-root-block': {
65
- paddingTop: '7px !important',
42
+ paddingTop: '7px !important'
66
43
  },
67
44
  '& > .mq-math-mode .mq-overarc ': {
68
- paddingTop: '0.45em !important',
45
+ paddingTop: '0.45em !important'
69
46
  },
70
47
  '& > .mq-math-mode .mq-sqrt-prefix': {
71
48
  verticalAlign: 'bottom !important',
72
49
  top: '0 !important',
73
- left: '-0.1em !important',
50
+ left: '-0.1em !important'
74
51
  },
75
52
  '& > .mq-math-mode .mq-denominator': {
76
53
  marginTop: '-5px !important',
77
- padding: '0.5em 0.1em 0.1em !important',
54
+ padding: '0.5em 0.1em 0.1em !important'
78
55
  },
79
56
  '& > .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {
80
57
  padding: '0 0.1em !important',
81
58
  paddingBottom: '0 !important',
82
- marginBottom: '4.5px',
59
+ marginBottom: '4.5px'
83
60
  },
84
61
  '& > .mq-math-mode sup.mq-nthroot': {
85
62
  fontSize: '70.7% !important',
86
63
  verticalAlign: '0.5em !important',
87
- paddingRight: '0.15em',
64
+ paddingRight: '0.15em'
88
65
  },
89
66
  '& > .mq-longdiv-inner': {
90
67
  marginTop: '-1px',
@@ -93,107 +70,138 @@ const mp = (theme) => ({
93
70
  '& > .mq-empty': {
94
71
  padding: '0 !important',
95
72
  marginLeft: '0px !important',
96
- marginTop: '2px',
97
- },
73
+ marginTop: '2px'
74
+ }
98
75
  },
99
76
  '& > .mq-math-mode .mq-longdiv': {
100
- display: 'inline-flex !important',
77
+ display: 'inline-flex !important'
101
78
  },
102
79
  '& > .mq-math-mode .mq-longdiv .mq-longdiv-inner .mq-empty': {
103
80
  paddingTop: '6px !important',
104
- paddingLeft: '4px !important',
81
+ paddingLeft: '4px !important'
105
82
  },
106
83
  '& > .mq-math-mode .mq-longdiv .mq-longdiv-inner': {
107
- marginLeft: '0 !important',
84
+ marginLeft: '0 !important'
108
85
  },
109
86
  '& > .mq-math-mode .mq-supsub': {
110
- fontSize: '70.7% !important',
87
+ fontSize: '70.7% !important'
111
88
  },
112
89
  '& > .mq-math-mode .mq-overarrow': {
113
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
90
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
114
91
  },
115
92
  '& > .mq-math-mode .mq-paren': {
116
93
  verticalAlign: 'top !important',
117
- padding: '1px 0.1em !important',
94
+ padding: '1px 0.1em !important'
118
95
  },
119
96
 
120
97
  '& > .mq-math-mode .mq-sqrt-stem': {
121
98
  borderTop: '0.07em solid',
122
99
  marginLeft: '-1.5px',
123
100
  marginTop: '-2px !important',
124
- paddingTop: '5px !important',
101
+ paddingTop: '5px !important'
125
102
  },
126
103
  '& > .mq-supsub ': {
127
- fontSize: '70.7%',
104
+ fontSize: '70.7%'
128
105
  },
129
106
 
130
107
  '& > .mq-math-mode .mq-supsub.mq-sup-only': {
131
108
  verticalAlign: '-0.1em !important',
132
109
 
133
110
  '& .mq-sup': {
134
- marginBottom: '0px !important',
135
- },
111
+ marginBottom: '0px !important'
112
+ }
136
113
  },
137
114
  '& .mq-overarrow-inner': {
138
115
  paddingTop: '0 !important',
139
- border: 'none !important',
116
+ border: 'none !important'
140
117
  },
141
118
  '& .mq-editable-field .mq-cursor': {
142
- marginTop: '-15px !important',
119
+ marginTop: '-15px !important'
143
120
  },
144
121
  '& .mq-overarrow.mq-arrow-both': {
145
122
  top: '7.5px',
146
123
  marginTop: '0px',
147
124
  minWidth: '1.23em',
148
125
  '& *': {
149
- lineHeight: '1 !important',
126
+ lineHeight: '1 !important'
150
127
  },
151
128
  '&:before': {
152
129
  top: '-0.4em',
153
- left: '-1px',
130
+ left: '-1px'
154
131
  },
155
132
  '&:after': {
156
133
  top: '0px !important',
157
134
  position: 'absolute',
158
- right: '-2px',
135
+ right: '-2px'
159
136
  },
160
137
  '&.mq-empty:after': {
161
- top: '-0.45em',
162
- },
138
+ top: '-0.45em'
139
+ }
163
140
  },
164
141
  '& .mq-overarrow.mq-arrow-right': {
165
142
  '&:before': {
166
143
  top: '-0.4em',
167
- right: '-1px',
168
- },
144
+ right: '-1px'
145
+ }
169
146
  },
170
147
  '& .mq-overarrow-inner-right': {
171
- display: 'none !important',
148
+ display: 'none !important'
172
149
  },
173
150
  '& .mq-overarrow-inner-left': {
174
- display: 'none !important',
151
+ display: 'none !important'
175
152
  },
176
153
  '& .mq-longdiv-inner': {
177
154
  borderTop: '1px solid !important',
178
- paddingTop: '1.5px !important',
155
+ paddingTop: '1.5px !important'
179
156
  },
180
157
  '& .mq-parallelogram': {
181
- lineHeight: 0.85,
182
- },
158
+ lineHeight: 0.85
159
+ }
183
160
  },
184
161
  selected: {
185
- border: `solid 1px ${theme.palette.primary.main}`,
162
+ border: `solid 1px ${get(theme, 'palette.primary.main')}`,
186
163
  '& > .mq-math-mode': {
187
- border: 'solid 0px lightgrey',
188
- },
164
+ border: 'solid 0px lightgrey'
165
+ }
189
166
  },
190
167
  insideOverlay: {
191
168
  position: 'absolute',
192
169
  bottom: 0,
193
170
  left: 0,
194
171
  right: 0,
195
- top: 0,
196
- },
172
+ top: 0
173
+ }
174
+ }));
175
+
176
+ export const RawMathPreview = React.forwardRef((props, ref) => {
177
+ log('[render] data: ', props.element.data);
178
+ const latex = props.element.data.latex;
179
+ const { isSelected, onFocus, onBlur, attributes, children } = props;
180
+ const classes = useStyles(props);
181
+
182
+ return (
183
+ <div
184
+ className={classNames(classes.root, isSelected && classes.selected)}
185
+ {...attributes}
186
+ contentEditable={false}
187
+ ref={ref}
188
+ >
189
+ {children}
190
+ {' '}
191
+ <span className={classes.insideOverlay} />
192
+ <mq.Static latex={latex} onFocus={onFocus} onBlur={onBlur} />
193
+ </div>
194
+ );
197
195
  });
198
196
 
199
- export default withStyles(mp)(RawMathPreview);
197
+ RawMathPreview.propTypes = {
198
+ element: PropTypes.object,
199
+ latex: PropTypes.string,
200
+ node: PropTypes.object,
201
+ classes: PropTypes.object,
202
+ isSelected: PropTypes.bool,
203
+ onFocus: PropTypes.func,
204
+ onBlur: PropTypes.func,
205
+ };
206
+
207
+ export default RawMathPreview;
package/LICENSE.md DELETED
@@ -1,5 +0,0 @@
1
- Copyright 2019 CoreSpring Inc
2
-
3
- Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
-
5
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.