@pie-lib/math-input 6.27.1-next.0 → 6.28.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.
- package/esm/index.js +2134 -0
- package/esm/index.js.map +1 -0
- package/package.json +9 -2
package/esm/index.js
ADDED
|
@@ -0,0 +1,2134 @@
|
|
|
1
|
+
import * as _ from 'lodash';
|
|
2
|
+
import ___default from 'lodash';
|
|
3
|
+
import times from 'lodash/times';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import Button from '@material-ui/core/Button';
|
|
7
|
+
import IconButton from '@material-ui/core/IconButton';
|
|
8
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import { fade, lighten } from '@material-ui/core/styles/colorManipulator';
|
|
11
|
+
import green from '@material-ui/core/colors/green';
|
|
12
|
+
import debug from 'debug';
|
|
13
|
+
import MathQuill from '@pie-framework/mathquill';
|
|
14
|
+
|
|
15
|
+
function _extends() {
|
|
16
|
+
_extends = Object.assign || function (target) {
|
|
17
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
18
|
+
var source = arguments[i];
|
|
19
|
+
|
|
20
|
+
for (var key in source) {
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
22
|
+
target[key] = source[key];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return _extends.apply(this, arguments);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const set$f = o => _extends({}, o, {
|
|
34
|
+
category: 'comparison'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const lessThan = set$f({
|
|
38
|
+
name: 'Less than',
|
|
39
|
+
latex: '<',
|
|
40
|
+
command: '\\lt'
|
|
41
|
+
});
|
|
42
|
+
const greaterThan = set$f({
|
|
43
|
+
name: 'Greater than',
|
|
44
|
+
latex: '>',
|
|
45
|
+
command: '\\gt'
|
|
46
|
+
});
|
|
47
|
+
const lessThanEqual = set$f({
|
|
48
|
+
name: 'Less than or equal',
|
|
49
|
+
latex: '\\le',
|
|
50
|
+
symbol: '<=',
|
|
51
|
+
command: '\\le',
|
|
52
|
+
ariaLabel: 'less than or equal to'
|
|
53
|
+
});
|
|
54
|
+
const greaterThanEqual = set$f({
|
|
55
|
+
name: 'Greater than or equal',
|
|
56
|
+
symbol: '>=',
|
|
57
|
+
command: '\\ge',
|
|
58
|
+
latex: '\\ge'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
var comparison = /*#__PURE__*/Object.freeze({
|
|
62
|
+
__proto__: null,
|
|
63
|
+
greaterThan: greaterThan,
|
|
64
|
+
greaterThanEqual: greaterThanEqual,
|
|
65
|
+
lessThan: lessThan,
|
|
66
|
+
lessThanEqual: lessThanEqual
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const mkSet = category => o => _extends({}, o, {
|
|
70
|
+
category
|
|
71
|
+
});
|
|
72
|
+
const transformToKeySetStructure = (data = []) => {
|
|
73
|
+
const structure = [];
|
|
74
|
+
|
|
75
|
+
___default.times(5, () => {
|
|
76
|
+
structure.push([]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
let ln = data.length;
|
|
80
|
+
let i = 0;
|
|
81
|
+
let j = 0;
|
|
82
|
+
|
|
83
|
+
while (j < ln) {
|
|
84
|
+
structure[i++].push(data[j++]);
|
|
85
|
+
|
|
86
|
+
if (i === 5) {
|
|
87
|
+
i = 0;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return structure;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const latexAndNameDontExist = base => k => {
|
|
95
|
+
const flattened = ___default.flatten(base);
|
|
96
|
+
|
|
97
|
+
const latexExists = flattened.some(b => b.latex === k.latex);
|
|
98
|
+
const nameExists = flattened.some(b => b.name === k.name);
|
|
99
|
+
return !latexExists && !nameExists;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const extendKeySet = (base = [], keySetData = []) => {
|
|
103
|
+
keySetData = keySetData.filter(latexAndNameDontExist(base));
|
|
104
|
+
const final = [];
|
|
105
|
+
|
|
106
|
+
___default.times(5 - base.length, () => {
|
|
107
|
+
base.push([]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
___default.times(5, () => {
|
|
111
|
+
final.push([]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const extra = transformToKeySetStructure(keySetData);
|
|
115
|
+
|
|
116
|
+
for (let i = 0; i < 5; i++) {
|
|
117
|
+
final[i] = [...base[i], ...extra[i]];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return final;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const set$e = mkSet('vars');
|
|
124
|
+
const x = set$e({
|
|
125
|
+
name: 'X',
|
|
126
|
+
latex: 'x',
|
|
127
|
+
write: 'x'
|
|
128
|
+
});
|
|
129
|
+
const y = set$e({
|
|
130
|
+
name: 'Y',
|
|
131
|
+
latex: 'y',
|
|
132
|
+
write: 'y'
|
|
133
|
+
});
|
|
134
|
+
const theta = set$e({
|
|
135
|
+
name: 'Theta',
|
|
136
|
+
latex: '\\theta',
|
|
137
|
+
write: '\\theta'
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
var vars = /*#__PURE__*/Object.freeze({
|
|
141
|
+
__proto__: null,
|
|
142
|
+
theta: theta,
|
|
143
|
+
x: x,
|
|
144
|
+
y: y
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const set$d = mkSet('fractions');
|
|
148
|
+
const blankOverBlank = set$d({
|
|
149
|
+
name: 'blank/blank',
|
|
150
|
+
latex: '\\frac{}{}',
|
|
151
|
+
command: '\\frac',
|
|
152
|
+
ariaLabel: 'fraction'
|
|
153
|
+
});
|
|
154
|
+
const xOverBlank = set$d({
|
|
155
|
+
latex: '\\frac{x}{ }',
|
|
156
|
+
name: 'X/blank',
|
|
157
|
+
label: 'x/[]',
|
|
158
|
+
command: '/',
|
|
159
|
+
ariaLabel: 'x over blank fraction'
|
|
160
|
+
});
|
|
161
|
+
const xBlankBlank = set$d({
|
|
162
|
+
name: 'X (blank/blank)',
|
|
163
|
+
latex: 'x\\frac{}{}',
|
|
164
|
+
label: 'x([]/[])',
|
|
165
|
+
command: '\\frac',
|
|
166
|
+
ariaLabel: 'mixed number'
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
var fractions = /*#__PURE__*/Object.freeze({
|
|
170
|
+
__proto__: null,
|
|
171
|
+
blankOverBlank: blankOverBlank,
|
|
172
|
+
xBlankBlank: xBlankBlank,
|
|
173
|
+
xOverBlank: xOverBlank
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const set$c = mkSet('exponent');
|
|
177
|
+
const squared = set$c({
|
|
178
|
+
name: 'Squared',
|
|
179
|
+
latex: 'x^2',
|
|
180
|
+
write: '^2'
|
|
181
|
+
});
|
|
182
|
+
const xToPowerOfN = set$c({
|
|
183
|
+
name: 'X to the power of n',
|
|
184
|
+
latex: 'x^{}',
|
|
185
|
+
command: '^',
|
|
186
|
+
ariaLabel: 'exponent'
|
|
187
|
+
});
|
|
188
|
+
const squareRoot = set$c({
|
|
189
|
+
name: 'Square root',
|
|
190
|
+
latex: '\\sqrt{}',
|
|
191
|
+
command: '\\sqrt'
|
|
192
|
+
});
|
|
193
|
+
const nthRoot = set$c({
|
|
194
|
+
name: 'Nth root',
|
|
195
|
+
latex: '\\sqrt[{}]{}',
|
|
196
|
+
command: '\\nthroot'
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
var exponent = /*#__PURE__*/Object.freeze({
|
|
200
|
+
__proto__: null,
|
|
201
|
+
nthRoot: nthRoot,
|
|
202
|
+
squareRoot: squareRoot,
|
|
203
|
+
squared: squared,
|
|
204
|
+
xToPowerOfN: xToPowerOfN
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const set$b = mkSet('misc');
|
|
208
|
+
const plusMinus = set$b({
|
|
209
|
+
name: 'Plus or Minus',
|
|
210
|
+
latex: '\\pm',
|
|
211
|
+
write: '\\pm'
|
|
212
|
+
});
|
|
213
|
+
const absValue = set$b({
|
|
214
|
+
name: 'Absolute Value',
|
|
215
|
+
latex: '\\abs{}',
|
|
216
|
+
symbol: '| |',
|
|
217
|
+
command: '|'
|
|
218
|
+
});
|
|
219
|
+
const parenthesis = set$b({
|
|
220
|
+
name: 'Parenthesis',
|
|
221
|
+
latex: '\\left(\\right)',
|
|
222
|
+
symbol: '( )',
|
|
223
|
+
command: '('
|
|
224
|
+
});
|
|
225
|
+
const brackets = set$b({
|
|
226
|
+
name: 'Brackets',
|
|
227
|
+
latex: '\\left[\\right]',
|
|
228
|
+
symbol: '[ ]',
|
|
229
|
+
command: '['
|
|
230
|
+
});
|
|
231
|
+
const percentage = set$b({
|
|
232
|
+
name: 'Percent',
|
|
233
|
+
latex: '%',
|
|
234
|
+
command: '%'
|
|
235
|
+
});
|
|
236
|
+
const approx = set$b({
|
|
237
|
+
latex: '\\approx',
|
|
238
|
+
command: '\\approx',
|
|
239
|
+
ariaLabel: 'Approximately equal to'
|
|
240
|
+
});
|
|
241
|
+
const nApprox = set$b({
|
|
242
|
+
latex: '\\napprox',
|
|
243
|
+
command: '\\napprox',
|
|
244
|
+
ariaLabel: 'Not pproximately equal to'
|
|
245
|
+
});
|
|
246
|
+
const notEqual = set$b({
|
|
247
|
+
latex: '\\neq',
|
|
248
|
+
command: '\\neq',
|
|
249
|
+
ariaLabel: 'Not equals'
|
|
250
|
+
});
|
|
251
|
+
const similar = set$b({
|
|
252
|
+
latex: '\\sim',
|
|
253
|
+
command: '\\sim',
|
|
254
|
+
ariaLabel: 'Similar'
|
|
255
|
+
});
|
|
256
|
+
const notSimilar = set$b({
|
|
257
|
+
latex: '\\nsim',
|
|
258
|
+
command: '\\nsim',
|
|
259
|
+
ariaLabel: 'Not similar'
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
var misc = /*#__PURE__*/Object.freeze({
|
|
263
|
+
__proto__: null,
|
|
264
|
+
absValue: absValue,
|
|
265
|
+
approx: approx,
|
|
266
|
+
brackets: brackets,
|
|
267
|
+
nApprox: nApprox,
|
|
268
|
+
notEqual: notEqual,
|
|
269
|
+
notSimilar: notSimilar,
|
|
270
|
+
parenthesis: parenthesis,
|
|
271
|
+
percentage: percentage,
|
|
272
|
+
plusMinus: plusMinus,
|
|
273
|
+
similar: similar
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const set$a = mkSet('constants');
|
|
277
|
+
const pi = set$a({
|
|
278
|
+
name: 'Pi',
|
|
279
|
+
label: 'π',
|
|
280
|
+
latex: '\\pi',
|
|
281
|
+
command: '\\pi',
|
|
282
|
+
category: 'constants'
|
|
283
|
+
});
|
|
284
|
+
const eulers = set$a({
|
|
285
|
+
name: 'Eulers',
|
|
286
|
+
label: 'e',
|
|
287
|
+
latex: 'e',
|
|
288
|
+
command: 'e',
|
|
289
|
+
category: 'constants'
|
|
290
|
+
});
|
|
291
|
+
const infinity = set$a({
|
|
292
|
+
name: 'Infinity',
|
|
293
|
+
label: '\\infty',
|
|
294
|
+
latex: '\\infty',
|
|
295
|
+
command: '\\infty',
|
|
296
|
+
category: 'constants'
|
|
297
|
+
});
|
|
298
|
+
const halfInfinity = set$a({
|
|
299
|
+
name: 'Half Infinity',
|
|
300
|
+
label: '\\propto',
|
|
301
|
+
latex: '\\propto',
|
|
302
|
+
command: '\\propto',
|
|
303
|
+
category: 'constants'
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
var constants = /*#__PURE__*/Object.freeze({
|
|
307
|
+
__proto__: null,
|
|
308
|
+
eulers: eulers,
|
|
309
|
+
halfInfinity: halfInfinity,
|
|
310
|
+
infinity: infinity,
|
|
311
|
+
pi: pi
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const set$9 = mkSet('trigonometry');
|
|
315
|
+
const sin = set$9({
|
|
316
|
+
name: 'sine',
|
|
317
|
+
label: 'sin',
|
|
318
|
+
command: '\\sin',
|
|
319
|
+
latex: '\\sin'
|
|
320
|
+
});
|
|
321
|
+
const cos = set$9({
|
|
322
|
+
name: 'cosine',
|
|
323
|
+
label: 'cos',
|
|
324
|
+
command: '\\cos',
|
|
325
|
+
latex: '\\cos'
|
|
326
|
+
});
|
|
327
|
+
const tan = set$9({
|
|
328
|
+
name: 'tanget',
|
|
329
|
+
label: 'tan',
|
|
330
|
+
command: '\\tan',
|
|
331
|
+
latex: '\\tan'
|
|
332
|
+
});
|
|
333
|
+
const sec = set$9({
|
|
334
|
+
name: 'secant',
|
|
335
|
+
label: 'sec',
|
|
336
|
+
command: '\\sec',
|
|
337
|
+
latex: '\\sec'
|
|
338
|
+
});
|
|
339
|
+
const csc = set$9({
|
|
340
|
+
name: 'cosecant',
|
|
341
|
+
label: 'csc',
|
|
342
|
+
command: '\\csc',
|
|
343
|
+
latex: '\\csc'
|
|
344
|
+
});
|
|
345
|
+
const cot = set$9({
|
|
346
|
+
name: 'cotangent',
|
|
347
|
+
label: 'cot',
|
|
348
|
+
command: '\\cot',
|
|
349
|
+
latex: '\\cot'
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
var trigonometry = /*#__PURE__*/Object.freeze({
|
|
353
|
+
__proto__: null,
|
|
354
|
+
cos: cos,
|
|
355
|
+
cot: cot,
|
|
356
|
+
csc: csc,
|
|
357
|
+
sec: sec,
|
|
358
|
+
sin: sin,
|
|
359
|
+
tan: tan
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
const set$8 = o => _extends({}, o, {
|
|
363
|
+
category: 'geometry'
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const overline = set$8({
|
|
367
|
+
name: 'Line',
|
|
368
|
+
latex: '\\overline{}',
|
|
369
|
+
command: '\\overline'
|
|
370
|
+
});
|
|
371
|
+
const overRightArrow = set$8({
|
|
372
|
+
name: 'Ray',
|
|
373
|
+
latex: '\\overrightarrow{}',
|
|
374
|
+
command: '\\overrightarrow'
|
|
375
|
+
});
|
|
376
|
+
const overLeftRightArrow = set$8({
|
|
377
|
+
name: 'Segment',
|
|
378
|
+
latex: '\\overleftrightarrow{\\overline{}}',
|
|
379
|
+
// used this notation to display the pink box
|
|
380
|
+
symbol: 'AB',
|
|
381
|
+
command: '\\overleftrightarrow'
|
|
382
|
+
});
|
|
383
|
+
const segment = set$8({
|
|
384
|
+
name: 'Segment',
|
|
385
|
+
latex: '\\overleftrightarrow{AB}',
|
|
386
|
+
write: '\\overleftrightarrow{AB}',
|
|
387
|
+
label: 'AB'
|
|
388
|
+
});
|
|
389
|
+
const parallel = set$8({
|
|
390
|
+
name: 'Parallel',
|
|
391
|
+
latex: '\\parallel',
|
|
392
|
+
command: '\\parallel'
|
|
393
|
+
});
|
|
394
|
+
const notParallel = set$8({
|
|
395
|
+
name: 'Not Parallel',
|
|
396
|
+
latex: '\\nparallel',
|
|
397
|
+
command: '\\nparallel'
|
|
398
|
+
});
|
|
399
|
+
const perpindicular = set$8({
|
|
400
|
+
name: 'Perpendicular',
|
|
401
|
+
latex: '\\perp',
|
|
402
|
+
command: '\\perpendicular'
|
|
403
|
+
});
|
|
404
|
+
const angle = set$8({
|
|
405
|
+
name: 'Angle',
|
|
406
|
+
latex: '\\angle',
|
|
407
|
+
command: '\\angle'
|
|
408
|
+
});
|
|
409
|
+
const overArc = set$8({
|
|
410
|
+
name: 'Over arc',
|
|
411
|
+
latex: '\\overarc{\\overline{}}',
|
|
412
|
+
// used this notation to display the pink box
|
|
413
|
+
command: '\\overarc'
|
|
414
|
+
});
|
|
415
|
+
const measureOfAngle = set$8({
|
|
416
|
+
name: 'Measured Angle',
|
|
417
|
+
latex: '\\measuredangle',
|
|
418
|
+
command: ['m', '\\angle']
|
|
419
|
+
});
|
|
420
|
+
const triangle = set$8({
|
|
421
|
+
name: 'Triangle',
|
|
422
|
+
latex: '\\triangle',
|
|
423
|
+
command: '\\triangle'
|
|
424
|
+
});
|
|
425
|
+
const square = set$8({
|
|
426
|
+
name: 'Square',
|
|
427
|
+
latex: '\\square',
|
|
428
|
+
command: '\\square'
|
|
429
|
+
});
|
|
430
|
+
const parallelogram = set$8({
|
|
431
|
+
name: 'Parallelogram',
|
|
432
|
+
latex: '\\parallelogram',
|
|
433
|
+
command: '\\parallelogram'
|
|
434
|
+
});
|
|
435
|
+
const circledDot = set$8({
|
|
436
|
+
name: 'Circled Dot',
|
|
437
|
+
latex: '\\odot',
|
|
438
|
+
command: '\\odot'
|
|
439
|
+
});
|
|
440
|
+
const degree = set$8({
|
|
441
|
+
name: 'Degree',
|
|
442
|
+
latex: '\\degree',
|
|
443
|
+
command: '\\degree'
|
|
444
|
+
});
|
|
445
|
+
const similarTo = set$8({
|
|
446
|
+
name: 'Similar',
|
|
447
|
+
command: '\\sim',
|
|
448
|
+
latex: '\\sim'
|
|
449
|
+
});
|
|
450
|
+
const congruentTo = set$8({
|
|
451
|
+
name: 'Congruent To',
|
|
452
|
+
command: '\\cong',
|
|
453
|
+
latex: '\\cong'
|
|
454
|
+
});
|
|
455
|
+
const notCongruentTo = set$8({
|
|
456
|
+
name: 'Not Congruent To',
|
|
457
|
+
command: '\\ncong',
|
|
458
|
+
latex: '\\ncong'
|
|
459
|
+
});
|
|
460
|
+
const primeArcminute = set$8({
|
|
461
|
+
name: 'Prime',
|
|
462
|
+
label: 'pam',
|
|
463
|
+
// eslint-disable-next-line
|
|
464
|
+
latex: "'",
|
|
465
|
+
// eslint-disable-next-line
|
|
466
|
+
write: "'"
|
|
467
|
+
});
|
|
468
|
+
const doublePrimeArcSecond = set$8({
|
|
469
|
+
name: 'Double Prime',
|
|
470
|
+
// eslint-disable-next-line
|
|
471
|
+
latex: "''",
|
|
472
|
+
// eslint-disable-next-line
|
|
473
|
+
write: "''"
|
|
474
|
+
});
|
|
475
|
+
const leftArrow = set$8({
|
|
476
|
+
name: 'Left Arrow',
|
|
477
|
+
latex: '\\leftarrow',
|
|
478
|
+
command: '\\leftarrow'
|
|
479
|
+
});
|
|
480
|
+
const rightArrow = set$8({
|
|
481
|
+
name: 'Right Arrow',
|
|
482
|
+
latex: '\\rightarrow',
|
|
483
|
+
command: '\\rightarrow'
|
|
484
|
+
});
|
|
485
|
+
const leftrightArrow = set$8({
|
|
486
|
+
name: 'Left and Right Arrow',
|
|
487
|
+
latex: '\\leftrightarrow',
|
|
488
|
+
command: '\\leftrightarrow'
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
var geometry = /*#__PURE__*/Object.freeze({
|
|
492
|
+
__proto__: null,
|
|
493
|
+
angle: angle,
|
|
494
|
+
circledDot: circledDot,
|
|
495
|
+
congruentTo: congruentTo,
|
|
496
|
+
degree: degree,
|
|
497
|
+
doublePrimeArcSecond: doublePrimeArcSecond,
|
|
498
|
+
leftArrow: leftArrow,
|
|
499
|
+
leftrightArrow: leftrightArrow,
|
|
500
|
+
measureOfAngle: measureOfAngle,
|
|
501
|
+
notCongruentTo: notCongruentTo,
|
|
502
|
+
notParallel: notParallel,
|
|
503
|
+
overArc: overArc,
|
|
504
|
+
overLeftRightArrow: overLeftRightArrow,
|
|
505
|
+
overRightArrow: overRightArrow,
|
|
506
|
+
overline: overline,
|
|
507
|
+
parallel: parallel,
|
|
508
|
+
parallelogram: parallelogram,
|
|
509
|
+
perpindicular: perpindicular,
|
|
510
|
+
primeArcminute: primeArcminute,
|
|
511
|
+
rightArrow: rightArrow,
|
|
512
|
+
segment: segment,
|
|
513
|
+
similarTo: similarTo,
|
|
514
|
+
square: square,
|
|
515
|
+
triangle: triangle
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
const set$7 = mkSet('operators');
|
|
519
|
+
const circleDot = set$7({
|
|
520
|
+
name: 'CircleDot',
|
|
521
|
+
label: '⋅',
|
|
522
|
+
write: '\\cdot',
|
|
523
|
+
ariaLabel: 'Dot multiplier'
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
var operators = /*#__PURE__*/Object.freeze({
|
|
527
|
+
__proto__: null,
|
|
528
|
+
circleDot: circleDot
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
const set$6 = mkSet('log');
|
|
532
|
+
const log$3 = set$6({
|
|
533
|
+
name: 'Log',
|
|
534
|
+
label: 'log',
|
|
535
|
+
command: '\\log',
|
|
536
|
+
latex: '\\log'
|
|
537
|
+
});
|
|
538
|
+
const logSubscript = set$6({
|
|
539
|
+
name: 'log base n',
|
|
540
|
+
label: 'log s',
|
|
541
|
+
latex: '\\log_{}',
|
|
542
|
+
command: ['\\log', '_']
|
|
543
|
+
});
|
|
544
|
+
const ln = set$6({
|
|
545
|
+
name: 'natural log',
|
|
546
|
+
label: 'ln',
|
|
547
|
+
command: '\\ln',
|
|
548
|
+
latex: '\\ln'
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
var log$4 = /*#__PURE__*/Object.freeze({
|
|
552
|
+
__proto__: null,
|
|
553
|
+
ln: ln,
|
|
554
|
+
log: log$3,
|
|
555
|
+
logSubscript: logSubscript
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
const set$5 = mkSet('sub-sup');
|
|
559
|
+
const superscript = set$5({
|
|
560
|
+
name: 'Superscript',
|
|
561
|
+
latex: 'x^{}',
|
|
562
|
+
command: '^'
|
|
563
|
+
});
|
|
564
|
+
const subscript = set$5({
|
|
565
|
+
name: 'Subscript',
|
|
566
|
+
latex: 'x_{}',
|
|
567
|
+
command: '_'
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
var subSup = /*#__PURE__*/Object.freeze({
|
|
571
|
+
__proto__: null,
|
|
572
|
+
subscript: subscript,
|
|
573
|
+
superscript: superscript
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
const set$4 = mkSet('statistics');
|
|
577
|
+
const xBar = set$4({
|
|
578
|
+
name: 'X Bar',
|
|
579
|
+
label: 'x̄',
|
|
580
|
+
latex: '\\overline{x}',
|
|
581
|
+
write: '\\overline{x}'
|
|
582
|
+
});
|
|
583
|
+
const yBar = set$4({
|
|
584
|
+
name: 'Y Bar',
|
|
585
|
+
latex: '\\overline{y}',
|
|
586
|
+
write: '\\overline{y}'
|
|
587
|
+
});
|
|
588
|
+
const mu = set$4({
|
|
589
|
+
name: 'mu',
|
|
590
|
+
label: 'mu',
|
|
591
|
+
latex: '\\mu',
|
|
592
|
+
write: '\\mu'
|
|
593
|
+
});
|
|
594
|
+
const sigma = set$4({
|
|
595
|
+
name: 'Sigma',
|
|
596
|
+
ariaLabel: 'Uppercase Sigma',
|
|
597
|
+
label: '\\Sigma',
|
|
598
|
+
latex: '\\Sigma',
|
|
599
|
+
write: '\\Sigma'
|
|
600
|
+
});
|
|
601
|
+
const smallSigma = set$4({
|
|
602
|
+
name: 'sigma',
|
|
603
|
+
ariaLabel: 'Lowercase Sigma',
|
|
604
|
+
label: '\\sigma',
|
|
605
|
+
latex: '\\sigma',
|
|
606
|
+
write: '\\sigma'
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
var statistics = /*#__PURE__*/Object.freeze({
|
|
610
|
+
__proto__: null,
|
|
611
|
+
mu: mu,
|
|
612
|
+
sigma: sigma,
|
|
613
|
+
smallSigma: smallSigma,
|
|
614
|
+
xBar: xBar,
|
|
615
|
+
yBar: yBar
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
const DELETE = '\u232B';
|
|
619
|
+
const LEFT_ARROW = '◀';
|
|
620
|
+
const RIGHT_ARROW = '▶';
|
|
621
|
+
const DIVIDE = '\u00F7';
|
|
622
|
+
const MULTIPLY = '\u00D7';
|
|
623
|
+
|
|
624
|
+
const set$3 = mkSet('operators');
|
|
625
|
+
const equals = set$3({
|
|
626
|
+
write: '=',
|
|
627
|
+
label: '='
|
|
628
|
+
});
|
|
629
|
+
const plus = set$3({
|
|
630
|
+
write: '+',
|
|
631
|
+
label: '+'
|
|
632
|
+
});
|
|
633
|
+
const minus = set$3({
|
|
634
|
+
write: '−',
|
|
635
|
+
label: '−'
|
|
636
|
+
});
|
|
637
|
+
const divide = set$3({
|
|
638
|
+
name: 'divide',
|
|
639
|
+
label: DIVIDE,
|
|
640
|
+
command: '\\divide',
|
|
641
|
+
otherNotation: '\\div'
|
|
642
|
+
});
|
|
643
|
+
const multiply = set$3({
|
|
644
|
+
name: 'multiply',
|
|
645
|
+
label: MULTIPLY,
|
|
646
|
+
command: '\\times'
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
var basicOperators = /*#__PURE__*/Object.freeze({
|
|
650
|
+
__proto__: null,
|
|
651
|
+
divide: divide,
|
|
652
|
+
equals: equals,
|
|
653
|
+
minus: minus,
|
|
654
|
+
multiply: multiply,
|
|
655
|
+
plus: plus
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
const set$2 = mkSet('matrices');
|
|
659
|
+
const singleCellMatrix = set$2({
|
|
660
|
+
name: 'Single Cell Matrix',
|
|
661
|
+
label: '[ ]',
|
|
662
|
+
write: '\\begin{pmatrix}\\end{pmatrix}'
|
|
663
|
+
});
|
|
664
|
+
const doubleCellMatrix = set$2({
|
|
665
|
+
name: 'Double Cell Matrix',
|
|
666
|
+
label: '[ ] [ ] \\\\newline [ ] [ ]',
|
|
667
|
+
write: '\\begin{bmatrix}&\\\\&\\end{bmatrix}'
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
var matrices = /*#__PURE__*/Object.freeze({
|
|
671
|
+
__proto__: null,
|
|
672
|
+
doubleCellMatrix: doubleCellMatrix,
|
|
673
|
+
singleCellMatrix: singleCellMatrix
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
const digitMap = {
|
|
677
|
+
0: 'zero',
|
|
678
|
+
1: 'one',
|
|
679
|
+
2: 'two',
|
|
680
|
+
3: 'three',
|
|
681
|
+
4: 'four',
|
|
682
|
+
5: 'five',
|
|
683
|
+
6: 'six',
|
|
684
|
+
7: 'seven',
|
|
685
|
+
8: 'eight',
|
|
686
|
+
9: 'nine'
|
|
687
|
+
};
|
|
688
|
+
const comma$1 = {
|
|
689
|
+
name: 'comma',
|
|
690
|
+
label: ',',
|
|
691
|
+
write: ',',
|
|
692
|
+
category: 'digit'
|
|
693
|
+
};
|
|
694
|
+
const decimalPoint$1 = {
|
|
695
|
+
name: 'decimal-point',
|
|
696
|
+
label: '.',
|
|
697
|
+
write: '.',
|
|
698
|
+
category: 'digit'
|
|
699
|
+
};
|
|
700
|
+
var digits = times(10, String).map(n => {
|
|
701
|
+
return {
|
|
702
|
+
name: digitMap[n],
|
|
703
|
+
write: n,
|
|
704
|
+
label: n,
|
|
705
|
+
category: 'digit'
|
|
706
|
+
};
|
|
707
|
+
}).reduce((acc, o) => {
|
|
708
|
+
acc[o.name] = o;
|
|
709
|
+
return acc;
|
|
710
|
+
}, {
|
|
711
|
+
comma: comma$1,
|
|
712
|
+
decimalPoint: decimalPoint$1
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
const set$1 = mkSet('logic');
|
|
716
|
+
const therefore = set$1({
|
|
717
|
+
name: 'Therefore',
|
|
718
|
+
label: '∴',
|
|
719
|
+
write: '∴'
|
|
720
|
+
});
|
|
721
|
+
const longDivision = set$1({
|
|
722
|
+
name: 'Long division',
|
|
723
|
+
latex: '\\longdiv{}',
|
|
724
|
+
command: '\\longdiv'
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
const set = mkSet('navigation');
|
|
728
|
+
const left = set({
|
|
729
|
+
label: LEFT_ARROW,
|
|
730
|
+
keystroke: 'Left',
|
|
731
|
+
ariaLabel: 'Move cursor left'
|
|
732
|
+
});
|
|
733
|
+
const right = set({
|
|
734
|
+
label: RIGHT_ARROW,
|
|
735
|
+
keystroke: 'Right',
|
|
736
|
+
ariaLabel: 'Move cursor right'
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
const del = {
|
|
740
|
+
label: DELETE,
|
|
741
|
+
category: 'edit',
|
|
742
|
+
keystroke: 'Backspace',
|
|
743
|
+
ariaLabel: 'Delete'
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
const hs = [[blankOverBlank, percentage, x, squared, squareRoot], [circleDot, y, subscript, xToPowerOfN, nthRoot], [plusMinus, lessThan, greaterThan, lessThanEqual, greaterThanEqual], [pi, theta, parenthesis, brackets, absValue], [notEqual, sin, cos, tan, degree]];
|
|
747
|
+
|
|
748
|
+
const advancedAlgebra = (() => {
|
|
749
|
+
const out = [...hs.map(arr => [...arr])];
|
|
750
|
+
out[0].push({
|
|
751
|
+
name: 'i',
|
|
752
|
+
latex: 'i',
|
|
753
|
+
write: 'i'
|
|
754
|
+
});
|
|
755
|
+
out[1].push(log$3);
|
|
756
|
+
out[2].push(logSubscript);
|
|
757
|
+
out[3].push(ln);
|
|
758
|
+
out[4].push(eulers);
|
|
759
|
+
return out;
|
|
760
|
+
})();
|
|
761
|
+
|
|
762
|
+
const statisticsSet = (() => {
|
|
763
|
+
const out = [...hs.map(arr => [...arr])];
|
|
764
|
+
out[0].push(mu);
|
|
765
|
+
out[1].push(xBar);
|
|
766
|
+
out[2].push(yBar);
|
|
767
|
+
out[3].push(sigma);
|
|
768
|
+
out[4].push(smallSigma);
|
|
769
|
+
return out;
|
|
770
|
+
})();
|
|
771
|
+
|
|
772
|
+
const gradeSets = [{
|
|
773
|
+
predicate: n => n >= 3 && n <= 5,
|
|
774
|
+
set: [[lessThan, greaterThan], [xOverBlank, xBlankBlank], [x, longDivision], [squared, xToPowerOfN]]
|
|
775
|
+
}, {
|
|
776
|
+
predicate: n => n >= 6 && n <= 7,
|
|
777
|
+
set: [[degree, lessThan, greaterThan], [circleDot, lessThanEqual, greaterThanEqual], [x, y, squared, xToPowerOfN], [plusMinus, xOverBlank, xBlankBlank, squareRoot], [pi, parenthesis, absValue, nthRoot]]
|
|
778
|
+
}, {
|
|
779
|
+
predicate: n => n >= 8 || n === 'HS',
|
|
780
|
+
set: hs
|
|
781
|
+
}, {
|
|
782
|
+
predicate: 'non-negative-integers',
|
|
783
|
+
set: [[digits.seven, digits.eight, digits.nine], [digits.four, digits.five, digits.six], [digits.one, digits.two, digits.three], [digits.zero, {
|
|
784
|
+
name: '',
|
|
785
|
+
latex: '',
|
|
786
|
+
write: ''
|
|
787
|
+
}, {
|
|
788
|
+
name: '',
|
|
789
|
+
latex: '',
|
|
790
|
+
write: ''
|
|
791
|
+
}], [left, right, del]]
|
|
792
|
+
}, {
|
|
793
|
+
predicate: 'integers',
|
|
794
|
+
set: [[digits.seven, digits.eight, digits.nine], [digits.four, digits.five, digits.six], [digits.one, digits.two, digits.three], [digits.zero, {
|
|
795
|
+
name: '',
|
|
796
|
+
latex: '',
|
|
797
|
+
write: ''
|
|
798
|
+
}, minus], [left, right, del]]
|
|
799
|
+
}, {
|
|
800
|
+
predicate: 'decimals',
|
|
801
|
+
set: [[digits.seven, digits.eight, digits.nine], [digits.four, digits.five, digits.six], [digits.one, digits.two, digits.three], [digits.zero, digits.decimalPoint, minus], [left, right, del]]
|
|
802
|
+
}, {
|
|
803
|
+
predicate: 'fractions',
|
|
804
|
+
set: [[digits.seven, digits.eight, digits.nine], [digits.four, digits.five, digits.six], [digits.one, digits.two, digits.three], [digits.zero, blankOverBlank, minus], [left, right, del]]
|
|
805
|
+
}, {
|
|
806
|
+
predicate: 'geometry',
|
|
807
|
+
set: [[blankOverBlank, degree, primeArcminute, doublePrimeArcSecond, congruentTo, similarTo], [circleDot, angle, measureOfAngle, triangle, notCongruentTo, notSimilar], [sin, cos, tan, pi, squareRoot, nthRoot], [csc, sec, cot, theta, subscript, xToPowerOfN], [overline, overRightArrow, overLeftRightArrow, overArc, perpindicular, parallel]]
|
|
808
|
+
}, // {
|
|
809
|
+
// predicate: 'miscellaneous',
|
|
810
|
+
// set: [
|
|
811
|
+
// [
|
|
812
|
+
// subSup.superscript,
|
|
813
|
+
// subSup.subscript,
|
|
814
|
+
// fractions.blankOverBlank,
|
|
815
|
+
// misc.percentage,
|
|
816
|
+
// geometry.segment,
|
|
817
|
+
// geometry.parallel
|
|
818
|
+
// ],
|
|
819
|
+
// [
|
|
820
|
+
// exponent.squareRoot,
|
|
821
|
+
// exponent.nthRoot,
|
|
822
|
+
// misc.absValue,
|
|
823
|
+
// misc.parenthesis,
|
|
824
|
+
// geometry.perpindicular,
|
|
825
|
+
// geometry.angle
|
|
826
|
+
// ],
|
|
827
|
+
// [
|
|
828
|
+
// comparison.lessThan,
|
|
829
|
+
// comparison.greaterThan,
|
|
830
|
+
// geometry.degree,
|
|
831
|
+
// misc.approx,
|
|
832
|
+
// geometry.measureOfAngle,
|
|
833
|
+
// geometry.triangle
|
|
834
|
+
// ],
|
|
835
|
+
// [
|
|
836
|
+
// misc.nApprox,
|
|
837
|
+
// misc.notEqual,
|
|
838
|
+
// geometry.congruentTo,
|
|
839
|
+
// geometry.notCongruentTo,
|
|
840
|
+
// geometry.parallelogram,
|
|
841
|
+
// geometry.circledDot
|
|
842
|
+
// ],
|
|
843
|
+
// [
|
|
844
|
+
// misc.similar,
|
|
845
|
+
// misc.notSimilar,
|
|
846
|
+
// comparison.lessThanEqual,
|
|
847
|
+
// comparison.greaterThanEqual,
|
|
848
|
+
// vars.x,
|
|
849
|
+
// vars.y
|
|
850
|
+
// ]
|
|
851
|
+
// ]
|
|
852
|
+
// },
|
|
853
|
+
// {
|
|
854
|
+
// predicate: 'everything',
|
|
855
|
+
// set: [
|
|
856
|
+
// [
|
|
857
|
+
// subSup.superscript,
|
|
858
|
+
// subSup.subscript,
|
|
859
|
+
// fractions.blankOverBlank,
|
|
860
|
+
// misc.percentage,
|
|
861
|
+
// geometry.segment,
|
|
862
|
+
// geometry.parallel
|
|
863
|
+
// ],
|
|
864
|
+
// [
|
|
865
|
+
// exponent.squareRoot,
|
|
866
|
+
// exponent.nthRoot,
|
|
867
|
+
// misc.absValue,
|
|
868
|
+
// misc.parenthesis,
|
|
869
|
+
// geometry.perpindicular,
|
|
870
|
+
// geometry.angle
|
|
871
|
+
// ],
|
|
872
|
+
// [
|
|
873
|
+
// comparison.lessThan,
|
|
874
|
+
// comparison.greaterThan,
|
|
875
|
+
// geometry.degree,
|
|
876
|
+
// misc.approx,
|
|
877
|
+
// geometry.measureOfAngle,
|
|
878
|
+
// geometry.triangle
|
|
879
|
+
// ],
|
|
880
|
+
// [
|
|
881
|
+
// misc.nApprox,
|
|
882
|
+
// misc.notEqual,
|
|
883
|
+
// geometry.congruentTo,
|
|
884
|
+
// geometry.notCongruentTo,
|
|
885
|
+
// geometry.parallelogram,
|
|
886
|
+
// geometry.circledDot
|
|
887
|
+
// ],
|
|
888
|
+
// [
|
|
889
|
+
// misc.similar,
|
|
890
|
+
// misc.notSimilar,
|
|
891
|
+
// comparison.lessThanEqual,
|
|
892
|
+
// comparison.greaterThanEqual,
|
|
893
|
+
// vars.x,
|
|
894
|
+
// vars.y
|
|
895
|
+
// ]
|
|
896
|
+
// ]
|
|
897
|
+
// },
|
|
898
|
+
{
|
|
899
|
+
predicate: 'advanced-algebra',
|
|
900
|
+
set: advancedAlgebra
|
|
901
|
+
}, {
|
|
902
|
+
predicate: 'statistics',
|
|
903
|
+
set: statisticsSet
|
|
904
|
+
}, {
|
|
905
|
+
predicate: 'item-authoring',
|
|
906
|
+
set: [[divide, blankOverBlank, longDivision, halfInfinity, squared, squareRoot, overline, overRightArrow, overLeftRightArrow, log$3], [multiply, circleDot, {
|
|
907
|
+
name: '',
|
|
908
|
+
latex: '',
|
|
909
|
+
write: ''
|
|
910
|
+
}, subscript, xToPowerOfN, nthRoot, perpindicular, parallel, overArc, logSubscript], [plusMinus, pi, theta, degree, angle, leftArrow, rightArrow, triangle, square, ln], [notEqual, absValue, smallSigma, mu, therefore, sigma, leftrightArrow, sin, cos, tan], [lessThanEqual, greaterThanEqual, {
|
|
911
|
+
name: '',
|
|
912
|
+
latex: '',
|
|
913
|
+
write: ''
|
|
914
|
+
}, {
|
|
915
|
+
name: '',
|
|
916
|
+
latex: '',
|
|
917
|
+
write: ''
|
|
918
|
+
}, infinity, {
|
|
919
|
+
name: '',
|
|
920
|
+
latex: '',
|
|
921
|
+
write: ''
|
|
922
|
+
}, {
|
|
923
|
+
name: '',
|
|
924
|
+
latex: '',
|
|
925
|
+
write: ''
|
|
926
|
+
}, csc, sec, cot]]
|
|
927
|
+
}, // for grade 1-2, we want to display the base set only
|
|
928
|
+
// we need it here because we don't want to display the default set (grade 8)
|
|
929
|
+
{
|
|
930
|
+
predicate: n => n >= 1 && n <= 2,
|
|
931
|
+
set: []
|
|
932
|
+
}];
|
|
933
|
+
const keysForGrade = n => {
|
|
934
|
+
const number = parseInt(n, 10);
|
|
935
|
+
n = isNaN(number) ? n : number;
|
|
936
|
+
|
|
937
|
+
if (!n) {
|
|
938
|
+
return [];
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
const match = gradeSets.find(gs => {
|
|
942
|
+
if (typeof gs.predicate === 'string') {
|
|
943
|
+
return gs.predicate === n;
|
|
944
|
+
} else {
|
|
945
|
+
return gs.predicate(n);
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
if (match) {
|
|
950
|
+
return match.set || [];
|
|
951
|
+
} // if the grade is not found, return the default set which is grade 8 (as per PD-3549), for mode language it is not the default
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
if (n !== 'language') {
|
|
955
|
+
return gradeSets[2].set;
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
const ALL_KEYS = [...Object.values(basicOperators), ...Object.values(comparison), ...Object.values(constants), ...Object.values(digits), ...Object.values(exponent), ...Object.values(fractions), ...Object.values(geometry), ...Object.values(log$4), ...Object.values(matrices), ...Object.values(misc), ...Object.values(operators), ...Object.values(statistics), ...Object.values(subSup), ...Object.values(trigonometry), ...Object.values(vars)];
|
|
959
|
+
const normalizeAdditionalKeys = additionalKeys => {
|
|
960
|
+
return (additionalKeys || []).map(additionalkey => {
|
|
961
|
+
const {
|
|
962
|
+
latex
|
|
963
|
+
} = additionalkey;
|
|
964
|
+
const predefinedKey = (ALL_KEYS || []).find(key => latex === key.latex || latex === key.write || latex === key.command || latex === key.otherNotation);
|
|
965
|
+
return !latex ? additionalkey : predefinedKey || additionalkey;
|
|
966
|
+
});
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
// increase the font of parallel notation
|
|
970
|
+
const updateSpans = () => {
|
|
971
|
+
const spans = Array.from(document.querySelectorAll('span[mathquill-command-id]'));
|
|
972
|
+
(spans || []).forEach(span => {
|
|
973
|
+
if (span && span.innerText === '∥' && span.className !== 'mq-editable-field') {
|
|
974
|
+
span.style.fontSize = '32px';
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
if ((span.innerText === '′' || span.innerText === '′′') && !span.hasAttribute('data-prime')) {
|
|
978
|
+
span.setAttribute('data-prime', 'true');
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
const {
|
|
984
|
+
one,
|
|
985
|
+
two,
|
|
986
|
+
three,
|
|
987
|
+
four,
|
|
988
|
+
five,
|
|
989
|
+
six,
|
|
990
|
+
seven,
|
|
991
|
+
eight,
|
|
992
|
+
nine,
|
|
993
|
+
zero,
|
|
994
|
+
comma,
|
|
995
|
+
decimalPoint
|
|
996
|
+
} = digits;
|
|
997
|
+
const baseSet = [[seven, eight, nine, divide], [four, five, six, multiply], [one, two, three, minus], [zero, decimalPoint, comma, plus], [left, right, del, equals]];
|
|
998
|
+
|
|
999
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
1000
|
+
__proto__: null,
|
|
1001
|
+
baseSet: baseSet,
|
|
1002
|
+
comparison: comparison,
|
|
1003
|
+
exponent: exponent,
|
|
1004
|
+
fractions: fractions,
|
|
1005
|
+
misc: misc
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
const registerLineBreak = function registerLineBreak(MQ) {
|
|
1009
|
+
MQ.registerEmbed('newLine', () => {
|
|
1010
|
+
return {
|
|
1011
|
+
htmlString: '<div class="newLine"></div>',
|
|
1012
|
+
text: () => 'testText',
|
|
1013
|
+
latex: () => '\\embed{newLine}[]'
|
|
1014
|
+
};
|
|
1015
|
+
});
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
let MQ$1;
|
|
1019
|
+
|
|
1020
|
+
if (typeof window !== 'undefined') {
|
|
1021
|
+
MQ$1 = MathQuill.getInterface(2);
|
|
1022
|
+
|
|
1023
|
+
if (MQ$1 && MQ$1.registerEmbed) {
|
|
1024
|
+
registerLineBreak(MQ$1);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
const log$2 = debug('math-input:mq:input');
|
|
1029
|
+
/**
|
|
1030
|
+
* Wrapper for MathQuill MQ.MathField.
|
|
1031
|
+
*/
|
|
1032
|
+
|
|
1033
|
+
class Input extends React.Component {
|
|
1034
|
+
constructor(...args) {
|
|
1035
|
+
super(...args);
|
|
1036
|
+
|
|
1037
|
+
this.onInputEdit = () => {
|
|
1038
|
+
log$2('[onInputEdit] ...');
|
|
1039
|
+
const {
|
|
1040
|
+
onChange
|
|
1041
|
+
} = this.props;
|
|
1042
|
+
|
|
1043
|
+
if (!this.mathField) {
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
if (onChange) {
|
|
1048
|
+
onChange(this.mathField.latex());
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
this.refresh = () => {
|
|
1053
|
+
this.blur();
|
|
1054
|
+
this.focus();
|
|
1055
|
+
};
|
|
1056
|
+
|
|
1057
|
+
this.onKeyPress = event => {
|
|
1058
|
+
const keys = Object.keys(this.mathField.__controller.options);
|
|
1059
|
+
|
|
1060
|
+
if (keys.indexOf('ignoreNextMousedown') < 0) {
|
|
1061
|
+
// It seems like the controller has the above handler as an option
|
|
1062
|
+
// when all the right events are set and everything works fine
|
|
1063
|
+
// this seems to work in all cases
|
|
1064
|
+
this.refresh();
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
if (event.charCode === 13) {
|
|
1068
|
+
event.preventDefault();
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
this.onClick = event => {
|
|
1074
|
+
const {
|
|
1075
|
+
onClick
|
|
1076
|
+
} = this.props;
|
|
1077
|
+
this.refresh();
|
|
1078
|
+
onClick && onClick(event);
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
componentDidMount() {
|
|
1083
|
+
if (!MQ$1) {
|
|
1084
|
+
throw new Error('MQ is not defined - but component has mounted?');
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
this.mathField = MQ$1.MathField(this.input, {
|
|
1088
|
+
handlers: {
|
|
1089
|
+
edit: this.onInputEdit.bind(this)
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
this.updateLatex();
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
componentDidUpdate() {
|
|
1096
|
+
this.updateLatex();
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
updateLatex() {
|
|
1100
|
+
if (!this.mathField) {
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
const {
|
|
1105
|
+
latex
|
|
1106
|
+
} = this.props;
|
|
1107
|
+
|
|
1108
|
+
if (latex !== undefined && latex !== null) {
|
|
1109
|
+
this.mathField.latex(latex);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
clear() {
|
|
1114
|
+
this.mathField.latex('');
|
|
1115
|
+
return '';
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
blur() {
|
|
1119
|
+
log$2('blur mathfield');
|
|
1120
|
+
this.mathField.blur();
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
focus() {
|
|
1124
|
+
log$2('focus mathfield...');
|
|
1125
|
+
this.mathField.focus();
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
command(v) {
|
|
1129
|
+
log$2('command: ', v);
|
|
1130
|
+
|
|
1131
|
+
if (Array.isArray(v)) {
|
|
1132
|
+
v.forEach(vv => {
|
|
1133
|
+
this.mathField.cmd(vv);
|
|
1134
|
+
});
|
|
1135
|
+
} else {
|
|
1136
|
+
this.mathField.cmd(v);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
this.mathField.focus();
|
|
1140
|
+
return this.mathField.latex();
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
keystroke(v) {
|
|
1144
|
+
this.mathField.keystroke(v);
|
|
1145
|
+
this.mathField.focus();
|
|
1146
|
+
return this.mathField.latex();
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
write(v) {
|
|
1150
|
+
log$2('write: ', v);
|
|
1151
|
+
this.mathField.write(v);
|
|
1152
|
+
this.mathField.focus();
|
|
1153
|
+
return this.mathField.latex();
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
shouldComponentUpdate(nextProps) {
|
|
1157
|
+
log$2('next: ', nextProps.latex);
|
|
1158
|
+
log$2('current: ', this.mathField.latex());
|
|
1159
|
+
return nextProps.latex !== this.mathField.latex();
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
render() {
|
|
1163
|
+
const {
|
|
1164
|
+
onFocus,
|
|
1165
|
+
onBlur,
|
|
1166
|
+
classes,
|
|
1167
|
+
className
|
|
1168
|
+
} = this.props;
|
|
1169
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
1170
|
+
className: classNames(classes.input, className),
|
|
1171
|
+
onKeyDown: this.onKeyPress,
|
|
1172
|
+
onClick: this.onClick,
|
|
1173
|
+
onFocus: onFocus,
|
|
1174
|
+
onBlur: onBlur,
|
|
1175
|
+
ref: r => this.input = r
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
}
|
|
1180
|
+
Input.propTypes = {
|
|
1181
|
+
className: PropTypes.string,
|
|
1182
|
+
classes: PropTypes.object.isRequired,
|
|
1183
|
+
onClick: PropTypes.func,
|
|
1184
|
+
onChange: PropTypes.func,
|
|
1185
|
+
latex: PropTypes.string,
|
|
1186
|
+
onFocus: PropTypes.func,
|
|
1187
|
+
onBlur: PropTypes.func
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1190
|
+
const styles$1 = () => ({});
|
|
1191
|
+
|
|
1192
|
+
var input = withStyles(styles$1)(Input);
|
|
1193
|
+
|
|
1194
|
+
let MQ;
|
|
1195
|
+
|
|
1196
|
+
if (typeof window !== 'undefined') {
|
|
1197
|
+
MQ = MathQuill.getInterface(2);
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
const log$1 = debug('pie-lib:math-input:mq:static');
|
|
1201
|
+
const REGEX = /\\MathQuillMathField\[r\d*\]\{(.*?)\}/g;
|
|
1202
|
+
const WHITESPACE_REGEX = / /g;
|
|
1203
|
+
|
|
1204
|
+
function stripSpaces(string = '') {
|
|
1205
|
+
return string.replace(WHITESPACE_REGEX, '');
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
function countBraces(latex) {
|
|
1209
|
+
let count = 0;
|
|
1210
|
+
|
|
1211
|
+
for (let i = 0; i < (latex || '').length; i++) {
|
|
1212
|
+
if (latex[i] === '{') {
|
|
1213
|
+
count++;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
return count;
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Wrapper for MathQuill MQ.MathField.
|
|
1221
|
+
*/
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
class Static extends React.Component {
|
|
1225
|
+
constructor(props) {
|
|
1226
|
+
super(props);
|
|
1227
|
+
|
|
1228
|
+
this.createLiveRegion = () => {
|
|
1229
|
+
this.liveRegion = document.createElement('div');
|
|
1230
|
+
this.liveRegion.style.position = 'absolute';
|
|
1231
|
+
this.liveRegion.style.width = '1px';
|
|
1232
|
+
this.liveRegion.style.height = '1px';
|
|
1233
|
+
this.liveRegion.style.marginTop = '-1px';
|
|
1234
|
+
this.liveRegion.style.clip = 'rect(1px, 1px, 1px, 1px)';
|
|
1235
|
+
this.liveRegion.style.overflow = 'hidden';
|
|
1236
|
+
this.liveRegion.setAttribute('aria-live', 'polite');
|
|
1237
|
+
this.liveRegion.setAttribute('aria-atomic', 'true');
|
|
1238
|
+
document.body.appendChild(this.liveRegion);
|
|
1239
|
+
};
|
|
1240
|
+
|
|
1241
|
+
this.addEventListeners = () => {
|
|
1242
|
+
const input = this.inputRef.current;
|
|
1243
|
+
|
|
1244
|
+
if (input) {
|
|
1245
|
+
input.addEventListener('keydown', this.handleKeyDown);
|
|
1246
|
+
input.addEventListener('click', this.handleMathKeyboardClick);
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1250
|
+
this.removeEventListeners = () => {
|
|
1251
|
+
const input = this.inputRef.current;
|
|
1252
|
+
|
|
1253
|
+
if (input) {
|
|
1254
|
+
input.removeEventListener('keydown', this.handleKeyDown);
|
|
1255
|
+
input.removeEventListener('click', this.handleMathKeyboardClick);
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
this.removeLiveRegion = () => {
|
|
1260
|
+
if (this.liveRegion) {
|
|
1261
|
+
document.body.removeChild(this.liveRegion);
|
|
1262
|
+
this.liveRegion = null;
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
|
|
1266
|
+
this.handleKeyDown = event => {
|
|
1267
|
+
if ((event == null ? void 0 : event.key) === 'Backspace' || (event == null ? void 0 : event.key) === 'Delete') {
|
|
1268
|
+
this.setState({
|
|
1269
|
+
isDeleteKeyPressed: true
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
this.setState({
|
|
1274
|
+
inputSource: 'keyboard'
|
|
1275
|
+
});
|
|
1276
|
+
};
|
|
1277
|
+
|
|
1278
|
+
this.handleMathKeyboardClick = () => {
|
|
1279
|
+
this.setState({
|
|
1280
|
+
inputSource: 'mathKeyboard'
|
|
1281
|
+
});
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
this.onInputEdit = field => {
|
|
1285
|
+
if (!this.mathField) {
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
const name = this.props.getFieldName(field, this.mathField.innerFields);
|
|
1290
|
+
|
|
1291
|
+
if (this.props.onSubFieldChange) {
|
|
1292
|
+
var _this$inputRef;
|
|
1293
|
+
|
|
1294
|
+
// eslint-disable-next-line no-useless-escape
|
|
1295
|
+
const regexMatch = field.latex().match(/[0-9]\\ \\frac\{[^\{]*\}\{ \}/);
|
|
1296
|
+
|
|
1297
|
+
if ((_this$inputRef = this.inputRef) != null && _this$inputRef.current && regexMatch && regexMatch != null && regexMatch.length) {
|
|
1298
|
+
try {
|
|
1299
|
+
field.__controller.cursor.insLeftOf(field.__controller.cursor.parent[-1].parent);
|
|
1300
|
+
|
|
1301
|
+
field.el().dispatchEvent(new KeyboardEvent('keydown', {
|
|
1302
|
+
keyCode: 8
|
|
1303
|
+
}));
|
|
1304
|
+
} catch (e) {
|
|
1305
|
+
// eslint-disable-next-line no-console
|
|
1306
|
+
console.error(e.toString());
|
|
1307
|
+
}
|
|
1308
|
+
} else {
|
|
1309
|
+
this.props.onSubFieldChange(name, field.latex());
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
this.announceLatexConversion(field.latex());
|
|
1314
|
+
};
|
|
1315
|
+
|
|
1316
|
+
this.announceLatexConversion = newLatex => {
|
|
1317
|
+
if (!this.state) {
|
|
1318
|
+
console.error('State is not initialized');
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
const {
|
|
1323
|
+
previousLatex,
|
|
1324
|
+
inputSource,
|
|
1325
|
+
isDeleteKeyPressed
|
|
1326
|
+
} = this.state;
|
|
1327
|
+
const announcement = 'Converted to math symbol';
|
|
1328
|
+
|
|
1329
|
+
if (inputSource === 'keyboard' && !isDeleteKeyPressed) {
|
|
1330
|
+
const newBraces = countBraces(newLatex);
|
|
1331
|
+
const oldBraces = countBraces(previousLatex);
|
|
1332
|
+
|
|
1333
|
+
if (newBraces > oldBraces) {
|
|
1334
|
+
this.announceMessage(announcement);
|
|
1335
|
+
} else {
|
|
1336
|
+
try {
|
|
1337
|
+
this.mathField.parseLatex(previousLatex);
|
|
1338
|
+
this.mathField.parseLatex(newLatex);
|
|
1339
|
+
|
|
1340
|
+
if (newLatex == previousLatex) {
|
|
1341
|
+
this.announceMessage(announcement);
|
|
1342
|
+
}
|
|
1343
|
+
} catch (e) {
|
|
1344
|
+
console.warn('Error parsing latex:', e.message);
|
|
1345
|
+
console.warn(e);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
this.setState({
|
|
1351
|
+
previousLatex: newLatex,
|
|
1352
|
+
isDeleteKeyPressed: false
|
|
1353
|
+
});
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
this.announceMessage = message => {
|
|
1357
|
+
this.setState({
|
|
1358
|
+
previousLatex: ''
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
if (this.liveRegion) {
|
|
1362
|
+
this.liveRegion.textContent = message; // Clear the message after it is announced
|
|
1363
|
+
|
|
1364
|
+
setTimeout(() => {
|
|
1365
|
+
this.liveRegion.textContent = '';
|
|
1366
|
+
}, 500);
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
this.update = () => {
|
|
1371
|
+
if (!MQ) {
|
|
1372
|
+
throw new Error('MQ is not defined - but component has mounted?');
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
if (!this.mathField) {
|
|
1376
|
+
var _this$inputRef2;
|
|
1377
|
+
|
|
1378
|
+
this.mathField = MQ.StaticMath((_this$inputRef2 = this.inputRef) == null ? void 0 : _this$inputRef2.current, {
|
|
1379
|
+
handlers: {
|
|
1380
|
+
edit: this.onInputEdit.bind(this)
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
try {
|
|
1386
|
+
this.mathField.parseLatex(this.props.latex);
|
|
1387
|
+
this.mathField.latex(this.props.latex);
|
|
1388
|
+
} catch (e) {
|
|
1389
|
+
// default latex if received has errors
|
|
1390
|
+
this.mathField.latex('\\MathQuillMathField[r1]{}');
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
this.blur = () => {
|
|
1395
|
+
log$1('blur mathfield');
|
|
1396
|
+
this.mathField.blur();
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
this.focus = () => {
|
|
1400
|
+
log$1('focus mathfield...');
|
|
1401
|
+
this.mathField.focus();
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
this.onFocus = e => {
|
|
1405
|
+
try {
|
|
1406
|
+
let rootBlock = e.target.parentElement.nextSibling;
|
|
1407
|
+
let id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);
|
|
1408
|
+
|
|
1409
|
+
if (!id) {
|
|
1410
|
+
rootBlock = rootBlock.parentElement;
|
|
1411
|
+
id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
const innerField = this.mathField.innerFields.find(f => f.id === id);
|
|
1415
|
+
|
|
1416
|
+
if (innerField) {
|
|
1417
|
+
const name = this.props.getFieldName(innerField, this.mathField.innerFields);
|
|
1418
|
+
|
|
1419
|
+
if (this.props.setInput) {
|
|
1420
|
+
this.props.setInput(innerField);
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
this.props.onSubFieldFocus(name, innerField);
|
|
1424
|
+
}
|
|
1425
|
+
} catch (err) {
|
|
1426
|
+
// eslint-disable-next-line no-console
|
|
1427
|
+
console.error('error finding root block', err.message);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
this.state = {
|
|
1432
|
+
announcement: '',
|
|
1433
|
+
previousLatex: '',
|
|
1434
|
+
inputSource: null,
|
|
1435
|
+
isDeleteKeyPressed: false
|
|
1436
|
+
};
|
|
1437
|
+
this.inputRef = /*#__PURE__*/React.createRef();
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
componentDidMount() {
|
|
1441
|
+
this.update();
|
|
1442
|
+
updateSpans();
|
|
1443
|
+
this.createLiveRegion();
|
|
1444
|
+
this.addEventListeners();
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
componentDidUpdate() {
|
|
1448
|
+
this.update();
|
|
1449
|
+
updateSpans();
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
componentWillUnmount() {
|
|
1453
|
+
this.removeLiveRegion();
|
|
1454
|
+
this.removeEventListeners();
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
shouldComponentUpdate(nextProps) {
|
|
1458
|
+
try {
|
|
1459
|
+
const parsedLatex = this.mathField.parseLatex(nextProps.latex);
|
|
1460
|
+
const stripped = stripSpaces(parsedLatex);
|
|
1461
|
+
const newFieldCount = (nextProps.latex.match(REGEX) || []).length;
|
|
1462
|
+
const out = stripped !== stripSpaces(this.mathField.latex().trim()) || newFieldCount !== Object.keys(this.mathField.innerFields).length / 2;
|
|
1463
|
+
log$1('[shouldComponentUpdate] ', out);
|
|
1464
|
+
return out;
|
|
1465
|
+
} catch (e) {
|
|
1466
|
+
// eslint-disable-next-line no-console
|
|
1467
|
+
console.warn('Error parsing latex:', e.message, 'skip update'); // eslint-disable-next-line no-console
|
|
1468
|
+
|
|
1469
|
+
console.warn(e);
|
|
1470
|
+
return false;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
render() {
|
|
1475
|
+
const {
|
|
1476
|
+
onBlur,
|
|
1477
|
+
className
|
|
1478
|
+
} = this.props;
|
|
1479
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
1480
|
+
className: className,
|
|
1481
|
+
onFocus: this.onFocus,
|
|
1482
|
+
onBlur: onBlur,
|
|
1483
|
+
ref: this.inputRef
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
}
|
|
1488
|
+
Static.propTypes = {
|
|
1489
|
+
latex: PropTypes.string.isRequired,
|
|
1490
|
+
onFocus: PropTypes.func,
|
|
1491
|
+
onBlur: PropTypes.func,
|
|
1492
|
+
className: PropTypes.string,
|
|
1493
|
+
getFieldName: PropTypes.func,
|
|
1494
|
+
onSubFieldChange: PropTypes.func,
|
|
1495
|
+
onSubFieldFocus: PropTypes.func,
|
|
1496
|
+
setInput: PropTypes.func
|
|
1497
|
+
};
|
|
1498
|
+
Static.defaultProps = {
|
|
1499
|
+
getFieldName: () => {}
|
|
1500
|
+
};
|
|
1501
|
+
|
|
1502
|
+
const commonMqFontStyles = {
|
|
1503
|
+
fontFamily: 'MJXZERO, MJXTEX !important',
|
|
1504
|
+
'-webkit-font-smoothing': 'antialiased !important',
|
|
1505
|
+
'& .mq-math-mode > span > var': {
|
|
1506
|
+
fontFamily: 'MJXZERO, MJXTEX-I !important'
|
|
1507
|
+
},
|
|
1508
|
+
'& .mq-math-mode span var': {
|
|
1509
|
+
fontFamily: 'MJXZERO, MJXTEX-I !important'
|
|
1510
|
+
},
|
|
1511
|
+
'& .mq-math-mode .mq-nonSymbola': {
|
|
1512
|
+
fontFamily: 'MJXZERO, MJXTEX-I !important'
|
|
1513
|
+
},
|
|
1514
|
+
'& .mq-math-mode > span > var.mq-operator-name': {
|
|
1515
|
+
fontFamily: 'MJXZERO, MJXTEX !important'
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
const longdivStyles = {
|
|
1519
|
+
'& .mq-longdiv-inner': {
|
|
1520
|
+
marginTop: '-1px',
|
|
1521
|
+
marginLeft: '5px !important;',
|
|
1522
|
+
'& > .mq-empty': {
|
|
1523
|
+
padding: '0 !important',
|
|
1524
|
+
marginLeft: '0px !important',
|
|
1525
|
+
marginTop: '2px'
|
|
1526
|
+
}
|
|
1527
|
+
},
|
|
1528
|
+
'& .mq-math-mode .mq-longdiv': {
|
|
1529
|
+
display: 'inline-flex !important'
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
const supsubStyles = {
|
|
1533
|
+
'& .mq-math-mode sup.mq-nthroot': {
|
|
1534
|
+
fontSize: '70% !important',
|
|
1535
|
+
verticalAlign: '0.5em !important',
|
|
1536
|
+
paddingRight: '0.15em'
|
|
1537
|
+
},
|
|
1538
|
+
'& .mq-math-mode .mq-supsub': {
|
|
1539
|
+
fontSize: '70.7% !important'
|
|
1540
|
+
},
|
|
1541
|
+
'& .mq-supsub ': {
|
|
1542
|
+
fontSize: '70.7%'
|
|
1543
|
+
},
|
|
1544
|
+
'& .mq-math-mode .mq-supsub.mq-sup-only': {
|
|
1545
|
+
verticalAlign: '-0.1em !important',
|
|
1546
|
+
'& .mq-sup': {
|
|
1547
|
+
marginBottom: '0px !important'
|
|
1548
|
+
}
|
|
1549
|
+
},
|
|
1550
|
+
|
|
1551
|
+
/* But when the base is a fraction, move it higher */
|
|
1552
|
+
'& .mq-math-mode .mq-fraction + .mq-supsub.mq-sup-only': {
|
|
1553
|
+
verticalAlign: '0.4em !important'
|
|
1554
|
+
},
|
|
1555
|
+
'& .mq-math-mode .mq-supsub.mq-sup-only.mq-after-fraction-group': {
|
|
1556
|
+
verticalAlign: '0.4em !important'
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
const commonMqKeyboardStyles = {
|
|
1560
|
+
'& *': _extends({}, commonMqFontStyles, longdivStyles, {
|
|
1561
|
+
'& .mq-math-mode .mq-sqrt-prefix': {
|
|
1562
|
+
top: '0 !important'
|
|
1563
|
+
},
|
|
1564
|
+
'& .mq-math-mode .mq-empty': {
|
|
1565
|
+
padding: '9px 1px !important'
|
|
1566
|
+
},
|
|
1567
|
+
'& .mq-math-mode .mq-supsub': {
|
|
1568
|
+
fontSize: '70.7% !important'
|
|
1569
|
+
},
|
|
1570
|
+
'& .mq-math-mode .mq-sqrt-stem': {
|
|
1571
|
+
marginTop: '-5px',
|
|
1572
|
+
paddingTop: '4px'
|
|
1573
|
+
},
|
|
1574
|
+
'& .mq-math-mode .mq-paren': {
|
|
1575
|
+
verticalAlign: 'middle !important'
|
|
1576
|
+
},
|
|
1577
|
+
'& .mq-math-mode .mq-overarrow .mq-overarrow-inner .mq-empty': {
|
|
1578
|
+
padding: '0 !important'
|
|
1579
|
+
},
|
|
1580
|
+
'& .mq-math-mode .mq-overline .mq-overline-inner .mq-empty ': {
|
|
1581
|
+
padding: '0 !important'
|
|
1582
|
+
}
|
|
1583
|
+
})
|
|
1584
|
+
};
|
|
1585
|
+
var commonMqStyles = {
|
|
1586
|
+
commonMqFontStyles,
|
|
1587
|
+
longdivStyles,
|
|
1588
|
+
supsubStyles,
|
|
1589
|
+
commonMqKeyboardStyles
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
1593
|
+
__proto__: null,
|
|
1594
|
+
CommonMqStyles: commonMqStyles,
|
|
1595
|
+
Input: input,
|
|
1596
|
+
Static: Static
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
const MAIN_CONTAINER_CLASS = 'main-container';
|
|
1600
|
+
var editableHtmlConstants = {
|
|
1601
|
+
MAIN_CONTAINER_CLASS};
|
|
1602
|
+
|
|
1603
|
+
/**
|
|
1604
|
+
* Sort additional keys.
|
|
1605
|
+
*
|
|
1606
|
+
* Expects an array of rows.
|
|
1607
|
+
* @param {} keys
|
|
1608
|
+
*/
|
|
1609
|
+
|
|
1610
|
+
const sortKeys = keys => {
|
|
1611
|
+
// add any missing rows
|
|
1612
|
+
_.times(5 - keys.length, () => {
|
|
1613
|
+
keys.push([]);
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
const out = _.zip.apply(null, keys);
|
|
1617
|
+
|
|
1618
|
+
return out;
|
|
1619
|
+
};
|
|
1620
|
+
|
|
1621
|
+
const log = debug('pie-lib:math-inline:keypad');
|
|
1622
|
+
const LatexButton = withStyles(theme => ({
|
|
1623
|
+
root: {
|
|
1624
|
+
textTransform: 'none',
|
|
1625
|
+
padding: 0,
|
|
1626
|
+
margin: 0,
|
|
1627
|
+
fontSize: '110% !important'
|
|
1628
|
+
},
|
|
1629
|
+
latexButton: {
|
|
1630
|
+
pointerEvents: 'none',
|
|
1631
|
+
textTransform: 'none !important',
|
|
1632
|
+
'& .mq-scaled.mq-sqrt-prefix': {
|
|
1633
|
+
transform: 'scale(1, 0.9) !important'
|
|
1634
|
+
},
|
|
1635
|
+
'& .mq-sup-only .mq-sup': {
|
|
1636
|
+
marginBottom: '0.9px !important'
|
|
1637
|
+
},
|
|
1638
|
+
'& .mq-empty': {
|
|
1639
|
+
backgroundColor: `${fade(theme.palette.secondary.main, 0.4)} !important`
|
|
1640
|
+
},
|
|
1641
|
+
'& .mq-overline .mq-overline-inner': {
|
|
1642
|
+
borderTop: '2px solid black'
|
|
1643
|
+
},
|
|
1644
|
+
'& .mq-non-leaf.mq-overline': {
|
|
1645
|
+
borderTop: 'none !important' // fixing PD-4873 - in OT, it has border-top 1px and adds extra line
|
|
1646
|
+
|
|
1647
|
+
},
|
|
1648
|
+
'& .mq-overarrow': {
|
|
1649
|
+
width: '30px',
|
|
1650
|
+
marginTop: '0 !important',
|
|
1651
|
+
borderTop: '2px solid black',
|
|
1652
|
+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
|
|
1653
|
+
'&.mq-arrow-both': {
|
|
1654
|
+
top: '0px !important',
|
|
1655
|
+
'& *': {
|
|
1656
|
+
lineHeight: '1 !important',
|
|
1657
|
+
borderTop: 'none !important' // fixing PD-4873 - in OT, it has border-top 1px and adds extra line,
|
|
1658
|
+
|
|
1659
|
+
},
|
|
1660
|
+
'&:before': {
|
|
1661
|
+
fontSize: '80%',
|
|
1662
|
+
left: 'calc(-13%) !important',
|
|
1663
|
+
top: '-0.31em !important'
|
|
1664
|
+
},
|
|
1665
|
+
'&:after': {
|
|
1666
|
+
fontSize: '80% !important',
|
|
1667
|
+
right: 'calc(-13%) !important',
|
|
1668
|
+
top: '-1.5em'
|
|
1669
|
+
},
|
|
1670
|
+
'&.mq-empty:before': {
|
|
1671
|
+
fontSize: '80%',
|
|
1672
|
+
left: 'calc(-13%)',
|
|
1673
|
+
top: '-0.26em'
|
|
1674
|
+
},
|
|
1675
|
+
'&.mq-empty:after': {
|
|
1676
|
+
fontSize: '80%',
|
|
1677
|
+
right: 'calc(-13%)',
|
|
1678
|
+
top: '-0.26em'
|
|
1679
|
+
},
|
|
1680
|
+
'&.mq-empty': {
|
|
1681
|
+
minHeight: '1.4em'
|
|
1682
|
+
}
|
|
1683
|
+
},
|
|
1684
|
+
'&.mq-arrow-right:before': {
|
|
1685
|
+
fontSize: '80%',
|
|
1686
|
+
right: 'calc(-13%) !important',
|
|
1687
|
+
top: '-0.26em !important'
|
|
1688
|
+
},
|
|
1689
|
+
'& .mq-overarrow-inner': {
|
|
1690
|
+
border: 'none !important'
|
|
1691
|
+
},
|
|
1692
|
+
'& .mq-overarrow-inner .mq-overarrow-inner-right': {
|
|
1693
|
+
display: 'none !important'
|
|
1694
|
+
}
|
|
1695
|
+
},
|
|
1696
|
+
'& .mq-root-block': {
|
|
1697
|
+
padding: '5px !important'
|
|
1698
|
+
},
|
|
1699
|
+
'& .mq-overarrow.mq-arrow-both.mq-empty:after': {
|
|
1700
|
+
right: '-6px',
|
|
1701
|
+
fontSize: '80% !important',
|
|
1702
|
+
top: '-3px'
|
|
1703
|
+
},
|
|
1704
|
+
'& .mq-overarrow.mq-arrow-right.mq-empty:before': {
|
|
1705
|
+
right: '-5px',
|
|
1706
|
+
fontSize: '80% !important',
|
|
1707
|
+
top: '-3px'
|
|
1708
|
+
},
|
|
1709
|
+
'& .mq-overarrow.mq-arrow-both.mq-empty:before': {
|
|
1710
|
+
left: '-6px',
|
|
1711
|
+
fontSize: '80% !important',
|
|
1712
|
+
top: '-3px'
|
|
1713
|
+
},
|
|
1714
|
+
'& .mq-longdiv-inner': {
|
|
1715
|
+
borderTop: '1px solid !important',
|
|
1716
|
+
paddingTop: '1.5px !important'
|
|
1717
|
+
},
|
|
1718
|
+
'& .mq-parallelogram': {
|
|
1719
|
+
lineHeight: 0.85
|
|
1720
|
+
},
|
|
1721
|
+
'& .mq-overarc': {
|
|
1722
|
+
borderTop: '2px solid black !important',
|
|
1723
|
+
'& .mq-overline': {
|
|
1724
|
+
borderTop: 'none !important' // fixing PD-4873 - in OT, it has border-top 1px and adds extra line
|
|
1725
|
+
|
|
1726
|
+
},
|
|
1727
|
+
'& .mq-overline-inner': {
|
|
1728
|
+
borderTop: 'none !important',
|
|
1729
|
+
paddingTop: '0 !important'
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
},
|
|
1733
|
+
parallelButton: {
|
|
1734
|
+
fontStyle: 'italic !important'
|
|
1735
|
+
},
|
|
1736
|
+
leftRightArrowButton: {
|
|
1737
|
+
'& .mq-overarrow.mq-arrow-both': {
|
|
1738
|
+
'& .mq-overline-inner': {
|
|
1739
|
+
borderTop: 'none !important',
|
|
1740
|
+
paddingTop: '0 !important'
|
|
1741
|
+
},
|
|
1742
|
+
'&:after': {
|
|
1743
|
+
position: 'absolute !important',
|
|
1744
|
+
top: '0px !important'
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
}))(props => {
|
|
1749
|
+
let buttonClass;
|
|
1750
|
+
|
|
1751
|
+
if (props.latex === '\\parallel') {
|
|
1752
|
+
buttonClass = classNames(props.classes.latexButton, props.mqClassName, props.classes.parallelButton);
|
|
1753
|
+
} else if (props.latex === '\\overleftrightarrow{\\overline{}}') {
|
|
1754
|
+
buttonClass = classNames(props.classes.latexButton, props.mqClassName, props.classes.leftRightArrowButton);
|
|
1755
|
+
} else {
|
|
1756
|
+
buttonClass = classNames(props.classes.latexButton, props.mqClassName);
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
try {
|
|
1760
|
+
const MQ = MathQuill.getInterface(2);
|
|
1761
|
+
const span = document.createElement('span');
|
|
1762
|
+
span.innerHTML = '';
|
|
1763
|
+
const mathField = MQ.StaticMath(span);
|
|
1764
|
+
mathField.parseLatex(props.latex);
|
|
1765
|
+
mathField.latex(props.latex);
|
|
1766
|
+
} catch (e) {
|
|
1767
|
+
// received latex has errors - do not create button
|
|
1768
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
1772
|
+
className: classNames(props.classes.root, props.className),
|
|
1773
|
+
onClick: props.onClick,
|
|
1774
|
+
"aria-label": props.ariaLabel
|
|
1775
|
+
}, /*#__PURE__*/React.createElement(Static, {
|
|
1776
|
+
className: buttonClass,
|
|
1777
|
+
latex: props.latex
|
|
1778
|
+
}));
|
|
1779
|
+
});
|
|
1780
|
+
|
|
1781
|
+
const createCustomLayout = layoutObj => {
|
|
1782
|
+
if (layoutObj) {
|
|
1783
|
+
return {
|
|
1784
|
+
gridTemplateColumns: `repeat(${layoutObj.columns}, minmax(min-content, 150px))`,
|
|
1785
|
+
gridTemplateRows: `repeat(${layoutObj.rows}, minmax(40px, 60px))`,
|
|
1786
|
+
gridAutoFlow: 'initial'
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
return {};
|
|
1791
|
+
};
|
|
1792
|
+
|
|
1793
|
+
class KeyPad extends React.Component {
|
|
1794
|
+
constructor(props) {
|
|
1795
|
+
super(props);
|
|
1796
|
+
|
|
1797
|
+
this.handleKeypadInteraction = () => {
|
|
1798
|
+
// Check if the setKeypadInteraction prop is available, which is used for both
|
|
1799
|
+
// the language keypad and the special characters keypad
|
|
1800
|
+
if (this.props.setKeypadInteraction) {
|
|
1801
|
+
this.props.setKeypadInteraction(true);
|
|
1802
|
+
}
|
|
1803
|
+
};
|
|
1804
|
+
|
|
1805
|
+
this.buttonClick = key => {
|
|
1806
|
+
log('[buttonClick]', key);
|
|
1807
|
+
const {
|
|
1808
|
+
onPress
|
|
1809
|
+
} = this.props;
|
|
1810
|
+
onPress(key);
|
|
1811
|
+
};
|
|
1812
|
+
|
|
1813
|
+
this.flowKeys = (base, extras) => {
|
|
1814
|
+
const transposed = [...sortKeys(base), ...sortKeys(extras)];
|
|
1815
|
+
return ___default.flatten(transposed);
|
|
1816
|
+
};
|
|
1817
|
+
|
|
1818
|
+
this.keyIsNotAllowed = key => {
|
|
1819
|
+
const {
|
|
1820
|
+
noDecimal
|
|
1821
|
+
} = this.props;
|
|
1822
|
+
|
|
1823
|
+
if ((key.write === '.' && key.label === '.' || key.write === ',' && key.label === ',') && noDecimal) {
|
|
1824
|
+
return true;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
return false;
|
|
1828
|
+
};
|
|
1829
|
+
|
|
1830
|
+
this.keypadRef = /*#__PURE__*/React.createRef();
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
componentDidMount() {
|
|
1834
|
+
var _this$keypadRef;
|
|
1835
|
+
|
|
1836
|
+
const keyPadElement = (_this$keypadRef = this.keypadRef) == null ? void 0 : _this$keypadRef.current;
|
|
1837
|
+
const mainContainer = keyPadElement == null ? void 0 : keyPadElement.closest(`.${editableHtmlConstants.MAIN_CONTAINER_CLASS}`);
|
|
1838
|
+
const currentToolbar = keyPadElement == null ? void 0 : keyPadElement.closest('.pie-toolbar'); // need only for math keyboard so we need also controlledKeypadMode
|
|
1839
|
+
|
|
1840
|
+
if (this.props.controlledKeypadMode && mainContainer && currentToolbar) {
|
|
1841
|
+
const mainContainerPosition = mainContainer.getBoundingClientRect();
|
|
1842
|
+
const currentToolbarPosition = currentToolbar.getBoundingClientRect();
|
|
1843
|
+
const difference = mainContainerPosition.top + mainContainerPosition.height - (currentToolbarPosition.top + currentToolbarPosition.height);
|
|
1844
|
+
|
|
1845
|
+
if (difference < 0) {
|
|
1846
|
+
const totalHeight = mainContainerPosition.height + mainContainerPosition.top - difference; // increase the height of the main container if keyboard needs it
|
|
1847
|
+
|
|
1848
|
+
if (mainContainer) {
|
|
1849
|
+
mainContainer.style.height = `${totalHeight}px`;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
if (keyPadElement) {
|
|
1855
|
+
keyPadElement.addEventListener('touchstart', this.handleKeypadInteraction, true);
|
|
1856
|
+
keyPadElement.addEventListener('mousedown', this.handleKeypadInteraction, true);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
componentWillUnmount() {
|
|
1861
|
+
var _this$keypadRef2;
|
|
1862
|
+
|
|
1863
|
+
const keyPadElement = (_this$keypadRef2 = this.keypadRef) == null ? void 0 : _this$keypadRef2.current; // need only for math keyboard
|
|
1864
|
+
|
|
1865
|
+
if (this.props.controlledKeypadMode && keyPadElement) {
|
|
1866
|
+
const mainContainer = keyPadElement.closest(`.${editableHtmlConstants.MAIN_CONTAINER_CLASS}`);
|
|
1867
|
+
|
|
1868
|
+
if (mainContainer) {
|
|
1869
|
+
mainContainer.style.height = 'unset';
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
if (keyPadElement) {
|
|
1874
|
+
keyPadElement.removeEventListener('touchstart', this.handleKeypadInteraction, true);
|
|
1875
|
+
keyPadElement.removeEventListener('mousedown', this.handleKeypadInteraction, true);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
render() {
|
|
1880
|
+
const {
|
|
1881
|
+
classes,
|
|
1882
|
+
className,
|
|
1883
|
+
baseSet,
|
|
1884
|
+
additionalKeys,
|
|
1885
|
+
layoutForKeyPad,
|
|
1886
|
+
onFocus,
|
|
1887
|
+
mode
|
|
1888
|
+
} = this.props;
|
|
1889
|
+
const noBaseSet = ['non-negative-integers', 'integers', 'decimals', 'fractions', 'item-authoring', 'language'];
|
|
1890
|
+
const keysWithoutBaseSet = noBaseSet.includes(mode);
|
|
1891
|
+
const allKeys = keysWithoutBaseSet ? this.flowKeys([], additionalKeys || []) : this.flowKeys(baseSet, additionalKeys || []); //, ...sortKeys(additionalKeys)];
|
|
1892
|
+
|
|
1893
|
+
const shift = allKeys.length % 5 ? 1 : 0;
|
|
1894
|
+
|
|
1895
|
+
const style = _extends({
|
|
1896
|
+
gridTemplateColumns: `repeat(${Math.floor(allKeys.length / 5) + shift}, minmax(min-content, 150px))`
|
|
1897
|
+
}, createCustomLayout(layoutForKeyPad));
|
|
1898
|
+
|
|
1899
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1900
|
+
ref: this.keypadRef,
|
|
1901
|
+
className: classNames(classes.keys, className, classes[mode]),
|
|
1902
|
+
style: style,
|
|
1903
|
+
onFocus: onFocus
|
|
1904
|
+
}, allKeys.map((k, index) => {
|
|
1905
|
+
const onClick = this.buttonClick.bind(this, k);
|
|
1906
|
+
|
|
1907
|
+
if (!k) {
|
|
1908
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
1909
|
+
key: `empty-${index}`
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
const common = _extends({
|
|
1914
|
+
onClick,
|
|
1915
|
+
className: classNames(classes.labelButton, !keysWithoutBaseSet && classes[k.category], classes[k.extraClass], k.label === ',' && classes.comma, k.label === '.' && classes.dot),
|
|
1916
|
+
disabled: this.keyIsNotAllowed(k),
|
|
1917
|
+
key: `${k.label || k.latex || k.command}-${index}`
|
|
1918
|
+
}, k.actions || {}, k.extraProps || {});
|
|
1919
|
+
|
|
1920
|
+
if (k.latex) {
|
|
1921
|
+
return /*#__PURE__*/React.createElement(LatexButton, _extends({
|
|
1922
|
+
latex: k.latex,
|
|
1923
|
+
key: index
|
|
1924
|
+
}, common, {
|
|
1925
|
+
className: classes.latexButton,
|
|
1926
|
+
ariaLabel: k.ariaLabel ? k.ariaLabel : k.name || k.label
|
|
1927
|
+
}));
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
if (k.label) {
|
|
1931
|
+
return /*#__PURE__*/React.createElement(Button, _extends({
|
|
1932
|
+
key: index
|
|
1933
|
+
}, common, {
|
|
1934
|
+
className: classNames(common.className, {
|
|
1935
|
+
[classes.deleteButton]: k.label === '⌫'
|
|
1936
|
+
}),
|
|
1937
|
+
"aria-label": k.ariaLabel ? k.ariaLabel : k.name || k.label
|
|
1938
|
+
}), k.label);
|
|
1939
|
+
} else {
|
|
1940
|
+
const Icon = k.icon ? k.icon : 'div';
|
|
1941
|
+
return /*#__PURE__*/React.createElement(IconButton, _extends({
|
|
1942
|
+
tabIndex: '-1'
|
|
1943
|
+
}, common, {
|
|
1944
|
+
key: index
|
|
1945
|
+
}), /*#__PURE__*/React.createElement(Icon, {
|
|
1946
|
+
className: classes.icon
|
|
1947
|
+
}));
|
|
1948
|
+
}
|
|
1949
|
+
}));
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
}
|
|
1953
|
+
KeyPad.propTypes = {
|
|
1954
|
+
classes: PropTypes.object.isRequired,
|
|
1955
|
+
className: PropTypes.string,
|
|
1956
|
+
controlledKeypadMode: PropTypes.bool,
|
|
1957
|
+
baseSet: PropTypes.array,
|
|
1958
|
+
additionalKeys: PropTypes.array,
|
|
1959
|
+
layoutForKeyPad: PropTypes.object,
|
|
1960
|
+
onPress: PropTypes.func.isRequired,
|
|
1961
|
+
onFocus: PropTypes.func,
|
|
1962
|
+
noDecimal: PropTypes.bool,
|
|
1963
|
+
setKeypadInteraction: PropTypes.func,
|
|
1964
|
+
mode: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
1965
|
+
};
|
|
1966
|
+
KeyPad.defaultProps = {
|
|
1967
|
+
baseSet: baseSet,
|
|
1968
|
+
noDecimal: false
|
|
1969
|
+
};
|
|
1970
|
+
|
|
1971
|
+
const styles = theme => ({
|
|
1972
|
+
keys: _extends({}, commonMqKeyboardStyles, {
|
|
1973
|
+
width: '100%',
|
|
1974
|
+
display: 'grid',
|
|
1975
|
+
gridTemplateRows: 'repeat(5, minmax(40px, 60px))',
|
|
1976
|
+
gridRowGap: '0px',
|
|
1977
|
+
gridColumnGap: '0px',
|
|
1978
|
+
gridAutoFlow: 'column'
|
|
1979
|
+
}),
|
|
1980
|
+
character: {
|
|
1981
|
+
textTransform: 'initial !important',
|
|
1982
|
+
gridTemplateRows: 'repeat(5, minmax(40px, 50px)) !important'
|
|
1983
|
+
},
|
|
1984
|
+
language: {
|
|
1985
|
+
gridTemplateRows: 'repeat(4, minmax(40px, 50px)) !important',
|
|
1986
|
+
'& *': {
|
|
1987
|
+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
|
|
1988
|
+
}
|
|
1989
|
+
},
|
|
1990
|
+
holder: {
|
|
1991
|
+
position: 'relative',
|
|
1992
|
+
width: '100%',
|
|
1993
|
+
height: '100%',
|
|
1994
|
+
backgroundColor: '#cef',
|
|
1995
|
+
borderRadius: 0,
|
|
1996
|
+
padding: `${theme.spacing.unit}px 0 ${theme.spacing.unit}px 0`
|
|
1997
|
+
},
|
|
1998
|
+
labelButton: {
|
|
1999
|
+
minWidth: 'auto',
|
|
2000
|
+
fontSize: '140% !important',
|
|
2001
|
+
backgroundColor: lighten(theme.palette.primary.light, 0.5),
|
|
2002
|
+
'&:hover': {
|
|
2003
|
+
backgroundColor: lighten(theme.palette.primary.light, 0.7)
|
|
2004
|
+
},
|
|
2005
|
+
borderRadius: 0
|
|
2006
|
+
},
|
|
2007
|
+
latexButton: {
|
|
2008
|
+
minWidth: 'auto',
|
|
2009
|
+
borderRadius: 0,
|
|
2010
|
+
backgroundColor: lighten(theme.palette.primary.light, 0.5),
|
|
2011
|
+
'&:hover': {
|
|
2012
|
+
backgroundColor: lighten(theme.palette.primary.light, 0.7)
|
|
2013
|
+
}
|
|
2014
|
+
},
|
|
2015
|
+
deleteButton: {
|
|
2016
|
+
'& > span': {
|
|
2017
|
+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
|
|
2018
|
+
}
|
|
2019
|
+
},
|
|
2020
|
+
base: {},
|
|
2021
|
+
operators: {
|
|
2022
|
+
backgroundColor: lighten(theme.palette.secondary.light, 0.5),
|
|
2023
|
+
'&:hover': {
|
|
2024
|
+
backgroundColor: lighten(theme.palette.secondary.light, 0.7)
|
|
2025
|
+
}
|
|
2026
|
+
},
|
|
2027
|
+
comparison: {
|
|
2028
|
+
backgroundColor: lighten(green[500], 0.5),
|
|
2029
|
+
'&:hover': {
|
|
2030
|
+
backgroundColor: lighten(green[500], 0.7)
|
|
2031
|
+
}
|
|
2032
|
+
},
|
|
2033
|
+
comma: {
|
|
2034
|
+
fontSize: '200% !important',
|
|
2035
|
+
lineHeight: '100%'
|
|
2036
|
+
},
|
|
2037
|
+
dot: {
|
|
2038
|
+
fontSize: '200% !important',
|
|
2039
|
+
lineHeight: '100%'
|
|
2040
|
+
},
|
|
2041
|
+
icon: {
|
|
2042
|
+
height: '30px'
|
|
2043
|
+
}
|
|
2044
|
+
});
|
|
2045
|
+
|
|
2046
|
+
var Keypad = withStyles(styles)(KeyPad);
|
|
2047
|
+
|
|
2048
|
+
const toOldModel = d => {
|
|
2049
|
+
if (d.command) {
|
|
2050
|
+
return {
|
|
2051
|
+
value: d.command,
|
|
2052
|
+
type: 'command'
|
|
2053
|
+
};
|
|
2054
|
+
} else if (d.write) {
|
|
2055
|
+
return {
|
|
2056
|
+
value: d.write
|
|
2057
|
+
};
|
|
2058
|
+
} else if (d.keystroke) {
|
|
2059
|
+
return {
|
|
2060
|
+
type: 'cursor',
|
|
2061
|
+
value: d.keystroke
|
|
2062
|
+
};
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
|
|
2066
|
+
class HorizontalKeypad extends React.Component {
|
|
2067
|
+
constructor(...args) {
|
|
2068
|
+
super(...args);
|
|
2069
|
+
|
|
2070
|
+
this.keypadPress = data => {
|
|
2071
|
+
const {
|
|
2072
|
+
onClick
|
|
2073
|
+
} = this.props;
|
|
2074
|
+
onClick(toOldModel(data));
|
|
2075
|
+
};
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
render() {
|
|
2079
|
+
const {
|
|
2080
|
+
mode,
|
|
2081
|
+
onFocus,
|
|
2082
|
+
controlledKeypadMode,
|
|
2083
|
+
noDecimal,
|
|
2084
|
+
className,
|
|
2085
|
+
additionalKeys,
|
|
2086
|
+
layoutForKeyPad,
|
|
2087
|
+
setKeypadInteraction
|
|
2088
|
+
} = this.props;
|
|
2089
|
+
const normalizedKeys = normalizeAdditionalKeys(additionalKeys);
|
|
2090
|
+
return /*#__PURE__*/React.createElement(Keypad, {
|
|
2091
|
+
className: className,
|
|
2092
|
+
controlledKeypadMode: controlledKeypadMode,
|
|
2093
|
+
onFocus: onFocus,
|
|
2094
|
+
noDecimal: noDecimal,
|
|
2095
|
+
layoutForKeyPad: layoutForKeyPad,
|
|
2096
|
+
additionalKeys: extendKeySet(keysForGrade(mode), normalizedKeys),
|
|
2097
|
+
onPress: this.keypadPress,
|
|
2098
|
+
mode: mode,
|
|
2099
|
+
setKeypadInteraction: setKeypadInteraction
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
}
|
|
2104
|
+
HorizontalKeypad.propTypes = {
|
|
2105
|
+
className: PropTypes.string,
|
|
2106
|
+
controlledKeypadMode: PropTypes.bool,
|
|
2107
|
+
mode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
2108
|
+
layoutForKeyPad: PropTypes.object,
|
|
2109
|
+
onClick: PropTypes.func.isRequired,
|
|
2110
|
+
onFocus: PropTypes.func,
|
|
2111
|
+
noDecimal: PropTypes.bool,
|
|
2112
|
+
additionalKeys: PropTypes.array,
|
|
2113
|
+
setKeypadInteraction: PropTypes.func
|
|
2114
|
+
};
|
|
2115
|
+
HorizontalKeypad.defaultProps = {
|
|
2116
|
+
mode: 'scientific',
|
|
2117
|
+
noDecimal: false,
|
|
2118
|
+
additionalKeys: []
|
|
2119
|
+
};
|
|
2120
|
+
|
|
2121
|
+
const addLeftBracket = s => s.indexOf('\\(') === 0 ? s : `\\(${s}`;
|
|
2122
|
+
|
|
2123
|
+
const addRightBracket = s => s.indexOf('\\)') === s.length - 2 ? s : `${s}\\)`;
|
|
2124
|
+
|
|
2125
|
+
const rmLeftBracket = s => s.indexOf('\\(') === 0 ? s.substring(2) : s;
|
|
2126
|
+
|
|
2127
|
+
const rmRightBracket = s => s.indexOf('\\)') === s.length - 2 ? s.substring(0, s.length - 2) : s;
|
|
2128
|
+
|
|
2129
|
+
const addBrackets = s => addRightBracket(addLeftBracket(s));
|
|
2130
|
+
|
|
2131
|
+
const removeBrackets = s => rmRightBracket(rmLeftBracket(s));
|
|
2132
|
+
|
|
2133
|
+
export { HorizontalKeypad, addBrackets, index$1 as keys, keysForGrade, index as mq, removeBrackets, updateSpans };
|
|
2134
|
+
//# sourceMappingURL=index.js.map
|