@pie-lib/math-toolbar 3.0.3-next.36 → 3.0.3-next.38

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/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.
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.RawDoneButton = exports.DoneButton = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _react = _interopRequireDefault(require("react"));
10
- var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
11
- var _Check = _interopRequireDefault(require("@mui/icons-material/Check"));
12
- var _styles = require("@mui/material/styles");
13
- var _propTypes = _interopRequireDefault(require("prop-types"));
14
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
- var StyledIconButton = (0, _styles.styled)(_IconButton["default"])(function (_ref) {
17
- var theme = _ref.theme,
18
- hideBackground = _ref.hideBackground;
19
- return _objectSpread(_objectSpread({
20
- verticalAlign: 'top',
21
- width: '28px',
22
- height: '28px',
23
- color: '#00bb00'
24
- }, hideBackground && {
25
- backgroundColor: theme.palette.common.white,
26
- '&:hover': {
27
- backgroundColor: theme.palette.grey[200]
28
- }
29
- }), {}, {
30
- '& .MuiIconButton-label': {
31
- position: 'absolute',
32
- top: '2px'
33
- }
34
- });
35
- });
36
- var RawDoneButton = exports.RawDoneButton = function RawDoneButton(_ref2) {
37
- var onClick = _ref2.onClick,
38
- hideBackground = _ref2.hideBackground;
39
- return /*#__PURE__*/_react["default"].createElement(StyledIconButton, {
40
- "aria-label": "Done",
41
- onClick: onClick,
42
- hideBackground: hideBackground,
43
- size: "large"
44
- }, /*#__PURE__*/_react["default"].createElement(_Check["default"], null));
45
- };
46
- RawDoneButton.propTypes = {
47
- onClick: _propTypes["default"].func,
48
- hideBackground: _propTypes["default"].bool
49
- };
50
- var DoneButton = exports.DoneButton = RawDoneButton;
51
- //# sourceMappingURL=done-button.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"done-button.js","names":["_react","_interopRequireDefault","require","_IconButton","_Check","_styles","_propTypes","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","StyledIconButton","styled","IconButton","_ref","theme","hideBackground","verticalAlign","width","height","color","backgroundColor","palette","common","white","grey","position","top","RawDoneButton","exports","_ref2","onClick","createElement","size","propTypes","PropTypes","func","bool","DoneButton"],"sources":["../src/done-button.jsx"],"sourcesContent":["import React from 'react';\n\nimport IconButton from '@mui/material/IconButton';\nimport Check from '@mui/icons-material/Check';\nimport { styled } from '@mui/material/styles';\nimport PropTypes from 'prop-types';\n\nconst StyledIconButton = styled(IconButton)(({ theme, hideBackground }) => ({\n verticalAlign: 'top',\n width: '28px',\n height: '28px',\n color: '#00bb00',\n ...(hideBackground && {\n backgroundColor: theme.palette.common.white,\n '&:hover': {\n backgroundColor: theme.palette.grey[200],\n },\n }),\n '& .MuiIconButton-label': {\n position: 'absolute',\n top: '2px',\n },\n}));\n\nexport const RawDoneButton = ({ onClick, hideBackground }) => (\n <StyledIconButton aria-label=\"Done\" onClick={onClick} hideBackground={hideBackground} size=\"large\">\n <Check />\n </StyledIconButton>\n);\n\nRawDoneButton.propTypes = {\n onClick: PropTypes.func,\n hideBackground: PropTypes.bool,\n};\n\nexport const DoneButton = RawDoneButton;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAL,sBAAA,CAAAC,OAAA;AAAmC,SAAAK,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,aAAAhB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAE,MAAA,CAAAc,yBAAA,GAAAd,MAAA,CAAAe,gBAAA,CAAAlB,CAAA,EAAAG,MAAA,CAAAc,yBAAA,CAAAf,CAAA,KAAAH,OAAA,CAAAI,MAAA,CAAAD,CAAA,GAAAa,OAAA,WAAAd,CAAA,IAAAE,MAAA,CAAAgB,cAAA,CAAAnB,CAAA,EAAAC,CAAA,EAAAE,MAAA,CAAAK,wBAAA,CAAAN,CAAA,EAAAD,CAAA,iBAAAD,CAAA;AAEnC,IAAMoB,gBAAgB,GAAG,IAAAC,cAAM,EAACC,sBAAU,CAAC,CAAC,UAAAC,IAAA;EAAA,IAAGC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,cAAc,GAAAF,IAAA,CAAdE,cAAc;EAAA,OAAAb,aAAA,CAAAA,aAAA;IAClEc,aAAa,EAAE,KAAK;IACpBC,KAAK,EAAE,MAAM;IACbC,MAAM,EAAE,MAAM;IACdC,KAAK,EAAE;EAAS,GACZJ,cAAc,IAAI;IACpBK,eAAe,EAAEN,KAAK,CAACO,OAAO,CAACC,MAAM,CAACC,KAAK;IAC3C,SAAS,EAAE;MACTH,eAAe,EAAEN,KAAK,CAACO,OAAO,CAACG,IAAI,CAAC,GAAG;IACzC;EACF,CAAC;IACD,wBAAwB,EAAE;MACxBC,QAAQ,EAAE,UAAU;MACpBC,GAAG,EAAE;IACP;EAAC;AAAA,CACD,CAAC;AAEI,IAAMC,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,SAAhBA,aAAaA,CAAAE,KAAA;EAAA,IAAMC,OAAO,GAAAD,KAAA,CAAPC,OAAO;IAAEf,cAAc,GAAAc,KAAA,CAAdd,cAAc;EAAA,oBACrDjC,MAAA,YAAAiD,aAAA,CAACrB,gBAAgB;IAAC,cAAW,MAAM;IAACoB,OAAO,EAAEA,OAAQ;IAACf,cAAc,EAAEA,cAAe;IAACiB,IAAI,EAAC;EAAO,gBAChGlD,MAAA,YAAAiD,aAAA,CAAC7C,MAAA,WAAK,MAAE,CACQ,CAAC;AAAA,CACpB;AAEDyC,aAAa,CAACM,SAAS,GAAG;EACxBH,OAAO,EAAEI,qBAAS,CAACC,IAAI;EACvBpB,cAAc,EAAEmB,qBAAS,CAACE;AAC5B,CAAC;AAEM,IAAMC,UAAU,GAAAT,OAAA,CAAAS,UAAA,GAAGV,aAAa","ignoreList":[]}
@@ -1,528 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = exports.EditorAndPad = void 0;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
11
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
12
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
- var _react = _interopRequireDefault(require("react"));
15
- var _debug = _interopRequireDefault(require("debug"));
16
- var _propTypes = _interopRequireDefault(require("prop-types"));
17
- var _Button = _interopRequireDefault(require("@mui/material/Button"));
18
- var _styles = require("@mui/material/styles");
19
- var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
20
- var _Select = _interopRequireDefault(require("@mui/material/Select"));
21
- var _lodashEs = require("lodash-es");
22
- var _FormControl = _interopRequireDefault(require("@mui/material/FormControl"));
23
- var _InputLabel = _interopRequireDefault(require("@mui/material/InputLabel"));
24
- var _mathInput = require("@pie-lib/math-input");
25
- var _renderUi = require("@pie-lib/render-ui");
26
- var _utils = require("./utils");
27
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
28
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
29
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
30
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
31
- var _mq$CommonMqStyles = _mathInput.mq.CommonMqStyles,
32
- commonMqFontStyles = _mq$CommonMqStyles.commonMqFontStyles,
33
- commonMqKeyboardStyles = _mq$CommonMqStyles.commonMqKeyboardStyles,
34
- longdivStyles = _mq$CommonMqStyles.longdivStyles,
35
- supsubStyles = _mq$CommonMqStyles.supsubStyles;
36
- var log = (0, _debug["default"])('@pie-lib:math-toolbar:editor-and-pad');
37
- var decimalRegex = /\.|,/g;
38
- var MathToolbarContainer = (0, _styles.styled)('div')(function (_ref) {
39
- var theme = _ref.theme;
40
- return {
41
- zIndex: 9,
42
- position: 'relative',
43
- textAlign: 'center',
44
- width: 'auto',
45
- '& > .mq-math-mode': {
46
- border: 'solid 1px lightgrey'
47
- },
48
- '& > .mq-focused': {
49
- outline: 'none',
50
- boxShadow: 'none',
51
- border: "dotted 1px ".concat(theme.palette.primary.main),
52
- borderRadius: '0px'
53
- },
54
- '& .mq-overarrow-inner': {
55
- border: 'none !important',
56
- paddingTop: '0 !important'
57
- },
58
- '& .mq-overarrow-inner-right': {
59
- display: 'none !important'
60
- },
61
- '& .mq-overarrow-inner-left': {
62
- display: 'none !important'
63
- },
64
- '& .mq-longdiv-inner': {
65
- borderTop: '1px solid !important',
66
- paddingTop: '1.5px !important'
67
- },
68
- '& .mq-overarrow.mq-arrow-both': {
69
- top: '7.8px',
70
- marginTop: '0px',
71
- minWidth: '1.23em'
72
- },
73
- '& .mq-parallelogram': {
74
- lineHeight: 0.85
75
- }
76
- };
77
- });
78
- var InputAndTypeContainer = (0, _styles.styled)('div')(function (_ref2) {
79
- var theme = _ref2.theme,
80
- hide = _ref2.hide;
81
- return {
82
- display: hide ? 'none' : 'flex',
83
- alignItems: 'center',
84
- '& .mq-editable-field .mq-cursor': {
85
- top: '-4px'
86
- },
87
- '& .mq-math-mode .mq-selection, .mq-editable-field .mq-selection': {
88
- paddingTop: '18px'
89
- },
90
- '& .mq-math-mode .mq-overarrow': {
91
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
92
- },
93
- '& .mq-math-mode .mq-overline .mq-overline-inner': {
94
- paddingTop: '0.4em !important'
95
- },
96
- '& .mq-overarrow.mq-arrow-both': {
97
- minWidth: '1.23em',
98
- '& *': {
99
- lineHeight: '1 !important'
100
- },
101
- '&:before': {
102
- top: '-0.45em',
103
- left: '-1px'
104
- },
105
- '&:after': {
106
- position: 'absolute !important',
107
- top: '0px !important',
108
- right: '-2px'
109
- },
110
- '&.mq-empty:after': {
111
- top: '-0.45em'
112
- }
113
- },
114
- '& .mq-overarrow.mq-arrow-right': {
115
- '&:before': {
116
- top: '-0.4em',
117
- right: '-1px'
118
- }
119
- },
120
- '& *': _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, commonMqFontStyles), supsubStyles), longdivStyles), {}, {
121
- '& .mq-math-mode .mq-sqrt-prefix': {
122
- verticalAlign: 'baseline !important',
123
- top: '1px !important',
124
- left: '-0.1em !important'
125
- },
126
- '& .mq-math-mode .mq-overarc ': {
127
- paddingTop: '0.45em !important'
128
- },
129
- '& .mq-math-mode .mq-empty': {
130
- padding: '9px 1px !important'
131
- },
132
- '& .mq-math-mode .mq-root-block': {
133
- paddingTop: '10px'
134
- },
135
- '& .mq-scaled .mq-sqrt-prefix': {
136
- top: '0 !important'
137
- },
138
- '& .mq-math-mode .mq-longdiv .mq-longdiv-inner': {
139
- marginLeft: '4px !important',
140
- paddingTop: '6px !important',
141
- paddingLeft: '6px !important'
142
- },
143
- '& .mq-math-mode .mq-paren': {
144
- verticalAlign: 'top !important',
145
- padding: '1px 0.1em !important'
146
- },
147
- '& .mq-math-mode .mq-sqrt-stem': {
148
- borderTop: '0.07em solid',
149
- marginLeft: '-1.5px',
150
- marginTop: '-2px !important',
151
- paddingTop: '5px !important'
152
- },
153
- '& .mq-math-mode .mq-denominator': {
154
- marginTop: '-5px !important',
155
- padding: '0.5em 0.1em 0.1em !important'
156
- },
157
- '& .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {
158
- padding: '0 0.1em !important',
159
- paddingBottom: '0 !important',
160
- marginBottom: '-2px'
161
- }
162
- }),
163
- '& span[data-prime="true"]': {
164
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
165
- }
166
- };
167
- });
168
- var StyledFormControl = (0, _styles.styled)(_FormControl["default"])({
169
- flex: 'initial',
170
- width: '25%',
171
- minWidth: '100px',
172
- marginLeft: '15px',
173
- marginTop: '5px',
174
- marginBottom: '5px',
175
- marginRight: '5px',
176
- '& label': {
177
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
178
- },
179
- '& div': {
180
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
181
- }
182
- });
183
- var StyledInputLabel = (0, _styles.styled)(_InputLabel["default"])(function () {
184
- return {
185
- backgroundColor: 'transparent'
186
- };
187
- });
188
- var InputContainerDiv = (0, _styles.styled)('div')(function (_ref3) {
189
- var theme = _ref3.theme,
190
- error = _ref3.error;
191
- return _objectSpread(_objectSpread({
192
- minWidth: '500px',
193
- maxWidth: '900px',
194
- minHeight: '30px',
195
- width: '100%',
196
- display: 'flex',
197
- marginTop: theme.spacing(1),
198
- marginBottom: theme.spacing(1)
199
- }, error && {
200
- border: '2px solid red'
201
- }), {}, {
202
- '& .mq-sqrt-prefix .mq-scaled': {
203
- verticalAlign: 'middle !important'
204
- }
205
- });
206
- });
207
- var MathEditor = (0, _styles.styled)(_mathInput.mq.Input)(function (_ref4) {
208
- var controlledKeypadMode = _ref4.controlledKeypadMode;
209
- return {
210
- maxWidth: controlledKeypadMode ? '400px' : '500px',
211
- color: _renderUi.color.text(),
212
- backgroundColor: _renderUi.color.background(),
213
- padding: '2px'
214
- };
215
- });
216
- var AddAnswerBlockButton = (0, _styles.styled)(_Button["default"])({
217
- position: 'absolute',
218
- right: '12px',
219
- border: '1px solid lightgrey',
220
- color: _renderUi.color.text()
221
- });
222
- var StyledHr = (0, _styles.styled)('hr')(function (_ref5) {
223
- var theme = _ref5.theme;
224
- return {
225
- padding: 0,
226
- margin: 0,
227
- height: '1px',
228
- border: 'none',
229
- borderBottom: "solid 1px ".concat(theme.palette.primary.main)
230
- };
231
- });
232
- var KeyboardContainer = (0, _styles.styled)(_mathInput.HorizontalKeypad)(function (_ref6) {
233
- var mode = _ref6.mode;
234
- return _objectSpread(_objectSpread({}, commonMqKeyboardStyles), mode === 'language' && {
235
- '& *': {
236
- fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
237
- }
238
- });
239
- });
240
- var toNodeData = function toNodeData(data) {
241
- if (!data) {
242
- return;
243
- }
244
- var type = data.type,
245
- value = data.value;
246
- if (type === 'command' || type === 'cursor') {
247
- return data;
248
- } else if (type === 'answer') {
249
- return _objectSpread({
250
- type: 'answer'
251
- }, data);
252
- } else if (value === 'clear') {
253
- return {
254
- type: 'clear'
255
- };
256
- } else {
257
- return {
258
- type: 'write',
259
- value: value
260
- };
261
- }
262
- };
263
- var EditorAndPad = exports.EditorAndPad = /*#__PURE__*/function (_React$Component) {
264
- function EditorAndPad(props) {
265
- var _this;
266
- (0, _classCallCheck2["default"])(this, EditorAndPad);
267
- _this = _callSuper(this, EditorAndPad, [props]);
268
- (0, _defineProperty2["default"])(_this, "onClick", function (data) {
269
- var _this$props = _this.props,
270
- noDecimal = _this$props.noDecimal,
271
- noLatexHandling = _this$props.noLatexHandling,
272
- onChange = _this$props.onChange;
273
- var c = toNodeData(data);
274
- log('mathChange: ', c);
275
- if (noLatexHandling) {
276
- onChange(c.value);
277
- return;
278
- }
279
-
280
- // if decimals are not allowed for this response, we discard the input
281
- if (noDecimal && (c.value === '.' || c.value === ',')) {
282
- return;
283
- }
284
- if (!c) {
285
- return;
286
- }
287
- if (c.type === 'clear') {
288
- log('call clear...');
289
- _this.input.clear();
290
- } else if (c.type === 'command') {
291
- _this.input.command(c.value);
292
- } else if (c.type === 'cursor') {
293
- _this.input.keystroke(c.value);
294
- } else if (c.type === 'answer') {
295
- _this.input.write('%response%');
296
- } else {
297
- _this.input.write(c.value);
298
- }
299
- });
300
- (0, _defineProperty2["default"])(_this, "updateDisable", function (isEdit) {
301
- var maxResponseAreas = _this.props.maxResponseAreas;
302
- if (maxResponseAreas) {
303
- var shouldDisable = _this.checkResponseAreasNumber(maxResponseAreas, isEdit);
304
- _this.setState({
305
- addDisabled: shouldDisable
306
- });
307
- }
308
- });
309
- (0, _defineProperty2["default"])(_this, "onAnswerBlockClick", function () {
310
- _this.props.onAnswerBlockAdd();
311
- _this.onClick({
312
- type: 'answer'
313
- });
314
- _this.updateDisable(true);
315
- });
316
- (0, _defineProperty2["default"])(_this, "onEditorChange", function (latex) {
317
- var _this$props2 = _this.props,
318
- onChange = _this$props2.onChange,
319
- noDecimal = _this$props2.noDecimal;
320
- (0, _mathInput.updateSpans)();
321
- (0, _utils.markFractionBaseSuperscripts)();
322
- _this.updateDisable(true);
323
-
324
- // if no decimals are allowed and the last change is a decimal dot, discard the change
325
- if (noDecimal && (latex.indexOf('.') !== -1 || latex.indexOf(',') !== -1) && _this.input) {
326
- _this.input.clear();
327
- _this.input.write(latex.replace(decimalRegex, ''));
328
- return;
329
- }
330
-
331
- // eslint-disable-next-line no-useless-escape
332
- var regexMatch = latex.match(/[0-9]\\ \\frac\{[^\{]*\}\{ \}/);
333
- if (_this.input && regexMatch && regexMatch !== null && regexMatch !== void 0 && regexMatch.length) {
334
- try {
335
- _this.input.mathField.__controller.cursor.insLeftOf(_this.input.mathField.__controller.cursor.parent[-1].parent);
336
- _this.input.mathField.el().dispatchEvent(new KeyboardEvent('keydown', {
337
- keyCode: 8
338
- }));
339
- } catch (e) {
340
- // eslint-disable-next-line no-console
341
- console.error(e.toString());
342
- }
343
- return;
344
- }
345
- onChange(latex);
346
- });
347
- (0, _defineProperty2["default"])(_this, "onEditorTypeChange", function (evt) {
348
- _this.setState({
349
- equationEditor: evt.target.value
350
- });
351
- });
352
- (0, _defineProperty2["default"])(_this, "checkResponseAreasNumber", function (maxResponseAreas, isEdit) {
353
- var _ref7 = _this.input && _this.input.props || {},
354
- latex = _ref7.latex;
355
- if (latex) {
356
- var count = (latex.match(/answerBlock/g) || []).length;
357
- return isEdit ? count === maxResponseAreas - 1 : count === maxResponseAreas;
358
- }
359
- return false;
360
- });
361
- _this.state = {
362
- equationEditor: 'item-authoring',
363
- addDisabled: false
364
- };
365
- return _this;
366
- }
367
- (0, _inherits2["default"])(EditorAndPad, _React$Component);
368
- return (0, _createClass2["default"])(EditorAndPad, [{
369
- key: "componentDidMount",
370
- value: function componentDidMount() {
371
- if (this.input && this.props.autoFocus) {
372
- this.input.focus();
373
- }
374
- }
375
- }, {
376
- key: "shouldComponentUpdate",
377
- value:
378
- /** Only render if the mathquill instance's latex is different
379
- * or the keypad state changed from one state to the other (shown / hidden) */
380
- function shouldComponentUpdate(nextProps, nextState) {
381
- var inputIsDifferent = this.input.mathField.latex() !== nextProps.latex;
382
- log('[shouldComponentUpdate] ', 'inputIsDifferent: ', inputIsDifferent);
383
- if (!(0, _lodashEs.isEqual)(this.props.error, nextProps.error)) {
384
- return true;
385
- }
386
- if (!inputIsDifferent && this.props.keypadMode !== nextProps.keypadMode) {
387
- return true;
388
- }
389
- if (!inputIsDifferent && this.props.noDecimal !== nextProps.noDecimal) {
390
- return true;
391
- }
392
- if (!inputIsDifferent && this.state.equationEditor !== nextState.equationEditor) {
393
- return true;
394
- }
395
- if (!inputIsDifferent && this.props.controlledKeypad) {
396
- return this.props.showKeypad !== nextProps.showKeypad;
397
- }
398
- return inputIsDifferent;
399
- }
400
- }, {
401
- key: "render",
402
- value: function render() {
403
- var _this2 = this;
404
- var _this$props3 = this.props,
405
- classNames = _this$props3.classNames,
406
- keypadMode = _this$props3.keypadMode,
407
- allowAnswerBlock = _this$props3.allowAnswerBlock,
408
- additionalKeys = _this$props3.additionalKeys,
409
- controlledKeypad = _this$props3.controlledKeypad,
410
- controlledKeypadMode = _this$props3.controlledKeypadMode,
411
- showKeypad = _this$props3.showKeypad,
412
- setKeypadInteraction = _this$props3.setKeypadInteraction,
413
- noDecimal = _this$props3.noDecimal,
414
- hideInput = _this$props3.hideInput,
415
- layoutForKeyPad = _this$props3.layoutForKeyPad,
416
- latex = _this$props3.latex,
417
- _onFocus = _this$props3.onFocus,
418
- _onBlur = _this$props3.onBlur,
419
- error = _this$props3.error;
420
- var shouldShowKeypad = !controlledKeypad || controlledKeypad && showKeypad;
421
- var addDisabled = this.state.addDisabled;
422
- log('[render]', latex);
423
- return /*#__PURE__*/_react["default"].createElement(MathToolbarContainer, {
424
- className: classNames.mathToolbar
425
- }, /*#__PURE__*/_react["default"].createElement(InputAndTypeContainer, {
426
- hide: hideInput
427
- }, controlledKeypadMode && /*#__PURE__*/_react["default"].createElement(StyledFormControl, {
428
- variant: 'standard'
429
- }, /*#__PURE__*/_react["default"].createElement(StyledInputLabel, {
430
- id: "equation-editor-label"
431
- }, 'Equation Editor'), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
432
- labelId: "equation-editor-label",
433
- id: "equation-editor-select",
434
- name: "equationEditor",
435
- label: 'Equation Editor',
436
- onChange: this.onEditorTypeChange,
437
- value: this.state.equationEditor,
438
- MenuProps: {
439
- transitionDuration: {
440
- enter: 225,
441
- exit: 195
442
- }
443
- }
444
- }, /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
445
- value: "non-negative-integers"
446
- }, "Numeric - Non-Negative Integers"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
447
- value: "integers"
448
- }, "Numeric - Integers"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
449
- value: "decimals"
450
- }, "Numeric - Decimals"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
451
- value: "fractions"
452
- }, "Numeric - Fractions"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
453
- value: 1
454
- }, "Grade 1 - 2"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
455
- value: 3
456
- }, "Grade 3 - 5"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
457
- value: 6
458
- }, "Grade 6 - 7"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
459
- value: 8
460
- }, "Grade 8 - HS"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
461
- value: 'geometry'
462
- }, "Geometry"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
463
- value: 'advanced-algebra'
464
- }, "Advanced Algebra"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
465
- value: 'statistics'
466
- }, "Statistics"), /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
467
- value: 'item-authoring'
468
- }, "Item Authoring"))), /*#__PURE__*/_react["default"].createElement(InputContainerDiv, {
469
- error: error
470
- }, /*#__PURE__*/_react["default"].createElement(MathEditor, {
471
- onFocus: function onFocus() {
472
- _onFocus && _onFocus();
473
- _this2.updateDisable(false);
474
- },
475
- onBlur: function onBlur(event) {
476
- _this2.updateDisable(false);
477
- _onBlur && _onBlur(event);
478
- },
479
- className: classNames && classNames.editor || '',
480
- controlledKeypadMode: controlledKeypadMode,
481
- ref: function ref(r) {
482
- return _this2.input = r;
483
- },
484
- latex: latex,
485
- onChange: this.onEditorChange
486
- }))), allowAnswerBlock && /*#__PURE__*/_react["default"].createElement(AddAnswerBlockButton, {
487
- type: "primary",
488
- style: {
489
- bottom: shouldShowKeypad ? '320px' : '20px'
490
- },
491
- onClick: this.onAnswerBlockClick,
492
- disabled: addDisabled
493
- }, "+ Response Area"), /*#__PURE__*/_react["default"].createElement(StyledHr, null), shouldShowKeypad && /*#__PURE__*/_react["default"].createElement(KeyboardContainer, {
494
- mode: controlledKeypadMode ? this.state.equationEditor : keypadMode,
495
- controlledKeypadMode: controlledKeypadMode,
496
- layoutForKeyPad: layoutForKeyPad,
497
- additionalKeys: additionalKeys,
498
- onClick: this.onClick,
499
- noDecimal: noDecimal,
500
- setKeypadInteraction: setKeypadInteraction
501
- }));
502
- }
503
- }]);
504
- }(_react["default"].Component);
505
- (0, _defineProperty2["default"])(EditorAndPad, "propTypes", {
506
- classNames: _propTypes["default"].object,
507
- keypadMode: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
508
- autoFocus: _propTypes["default"].bool,
509
- allowAnswerBlock: _propTypes["default"].bool,
510
- showKeypad: _propTypes["default"].bool,
511
- controlledKeypad: _propTypes["default"].bool,
512
- controlledKeypadMode: _propTypes["default"].bool,
513
- error: _propTypes["default"].string,
514
- noDecimal: _propTypes["default"].bool,
515
- hideInput: _propTypes["default"].bool,
516
- noLatexHandling: _propTypes["default"].bool,
517
- layoutForKeyPad: _propTypes["default"].object,
518
- maxResponseAreas: _propTypes["default"].number,
519
- additionalKeys: _propTypes["default"].array,
520
- latex: _propTypes["default"].string.isRequired,
521
- onAnswerBlockAdd: _propTypes["default"].func,
522
- onFocus: _propTypes["default"].func,
523
- onBlur: _propTypes["default"].func,
524
- onChange: _propTypes["default"].func.isRequired,
525
- setKeypadInteraction: _propTypes["default"].func
526
- });
527
- var _default = exports["default"] = EditorAndPad;
528
- //# sourceMappingURL=editor-and-pad.js.map