@pie-lib/math-input 7.1.1-next.0 → 7.2.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/lib/horizontal-keypad.js +0 -3
  2. package/lib/horizontal-keypad.js.map +1 -1
  3. package/lib/index.js +0 -8
  4. package/lib/index.js.map +1 -1
  5. package/lib/keypad/index.js +2 -24
  6. package/lib/keypad/index.js.map +1 -1
  7. package/lib/keypad/keys-layout.js +4 -13
  8. package/lib/keypad/keys-layout.js.map +1 -1
  9. package/lib/keys/basic-operators.js +0 -1
  10. package/lib/keys/basic-operators.js.map +1 -1
  11. package/lib/keys/chars.js +0 -1
  12. package/lib/keys/chars.js.map +1 -1
  13. package/lib/keys/comparison.js +0 -10
  14. package/lib/keys/comparison.js.map +1 -1
  15. package/lib/keys/constants.js +0 -1
  16. package/lib/keys/constants.js.map +1 -1
  17. package/lib/keys/digits.js +2 -8
  18. package/lib/keys/digits.js.map +1 -1
  19. package/lib/keys/edit.js +0 -1
  20. package/lib/keys/edit.js.map +1 -1
  21. package/lib/keys/exponent.js +0 -1
  22. package/lib/keys/exponent.js.map +1 -1
  23. package/lib/keys/fractions.js +0 -1
  24. package/lib/keys/fractions.js.map +1 -1
  25. package/lib/keys/geometry.js +0 -10
  26. package/lib/keys/geometry.js.map +1 -1
  27. package/lib/keys/grades.js +0 -12
  28. package/lib/keys/grades.js.map +1 -1
  29. package/lib/keys/index.js +0 -7
  30. package/lib/keys/index.js.map +1 -1
  31. package/lib/keys/log.js +0 -1
  32. package/lib/keys/log.js.map +1 -1
  33. package/lib/keys/logic.js +0 -1
  34. package/lib/keys/logic.js.map +1 -1
  35. package/lib/keys/matrices.js +0 -1
  36. package/lib/keys/matrices.js.map +1 -1
  37. package/lib/keys/misc.js +0 -1
  38. package/lib/keys/misc.js.map +1 -1
  39. package/lib/keys/navigation.js +0 -1
  40. package/lib/keys/navigation.js.map +1 -1
  41. package/lib/keys/operators.js +0 -1
  42. package/lib/keys/operators.js.map +1 -1
  43. package/lib/keys/statistics.js +0 -1
  44. package/lib/keys/statistics.js.map +1 -1
  45. package/lib/keys/sub-sup.js +0 -1
  46. package/lib/keys/sub-sup.js.map +1 -1
  47. package/lib/keys/trigonometry.js +0 -1
  48. package/lib/keys/trigonometry.js.map +1 -1
  49. package/lib/keys/utils.js +8 -23
  50. package/lib/keys/utils.js.map +1 -1
  51. package/lib/keys/vars.js +0 -1
  52. package/lib/keys/vars.js.map +1 -1
  53. package/lib/math-input.js +0 -8
  54. package/lib/math-input.js.map +1 -1
  55. package/lib/mq/common-mq-styles.js +0 -10
  56. package/lib/mq/common-mq-styles.js.map +1 -1
  57. package/lib/mq/custom-elements.js +0 -1
  58. package/lib/mq/custom-elements.js.map +1 -1
  59. package/lib/mq/index.js +0 -1
  60. package/lib/mq/index.js.map +1 -1
  61. package/lib/mq/input.js +0 -10
  62. package/lib/mq/input.js.map +1 -1
  63. package/lib/mq/static.js +0 -14
  64. package/lib/mq/static.js.map +1 -1
  65. package/lib/updateSpans.js +0 -6
  66. package/lib/updateSpans.js.map +1 -1
  67. package/package.json +7 -3
  68. package/src/__tests__/horizontal-keypad.test.jsx +463 -0
  69. package/src/__tests__/index.test.js +242 -0
  70. package/src/__tests__/updateSpans.test.js +297 -0
  71. package/src/index.jsx +5 -6
  72. package/src/keypad/__tests__/keys-layout.test.js +0 -1
  73. package/src/keypad/index.jsx +3 -4
  74. package/src/keypad/keys-layout.js +4 -5
  75. package/src/keys/__tests__/utils.test.js +1 -1
  76. package/src/keys/digits.js +1 -1
  77. package/src/keys/index.js +5 -6
  78. package/src/keys/utils.js +6 -11
  79. package/src/mq/__tests__/custom-elements.test.js +342 -0
  80. package/NEXT.CHANGELOG.json +0 -1
@@ -0,0 +1,297 @@
1
+ import { updateSpans } from '../updateSpans';
2
+
3
+ describe('updateSpans', () => {
4
+ beforeEach(() => {
5
+ document.body.innerHTML = '';
6
+ });
7
+
8
+ afterEach(() => {
9
+ document.body.innerHTML = '';
10
+ });
11
+
12
+ describe('prime notation (′ and ′′)', () => {
13
+ it('should add data-prime attribute to single prime', () => {
14
+ const span = document.createElement('span');
15
+ span.setAttribute('mathquill-command-id', '1');
16
+ span.innerText = '′';
17
+ document.body.appendChild(span);
18
+
19
+ updateSpans();
20
+
21
+ expect(span.getAttribute('data-prime')).toBe('true');
22
+ });
23
+
24
+ it('should add data-prime attribute to double prime', () => {
25
+ const span = document.createElement('span');
26
+ span.setAttribute('mathquill-command-id', '1');
27
+ span.innerText = '′′';
28
+ document.body.appendChild(span);
29
+
30
+ updateSpans();
31
+
32
+ expect(span.getAttribute('data-prime')).toBe('true');
33
+ });
34
+
35
+ it('should not add data-prime if already present', () => {
36
+ const span = document.createElement('span');
37
+ span.setAttribute('mathquill-command-id', '1');
38
+ span.innerText = '′';
39
+ span.setAttribute('data-prime', 'true');
40
+ document.body.appendChild(span);
41
+
42
+ updateSpans();
43
+
44
+ expect(span.getAttribute('data-prime')).toBe('true');
45
+ });
46
+
47
+ it('should handle multiple prime notation spans', () => {
48
+ const span1 = document.createElement('span');
49
+ span1.setAttribute('mathquill-command-id', '1');
50
+ span1.innerText = '′';
51
+ document.body.appendChild(span1);
52
+
53
+ const span2 = document.createElement('span');
54
+ span2.setAttribute('mathquill-command-id', '2');
55
+ span2.innerText = '′′';
56
+ document.body.appendChild(span2);
57
+
58
+ updateSpans();
59
+
60
+ expect(span1.getAttribute('data-prime')).toBe('true');
61
+ expect(span2.getAttribute('data-prime')).toBe('true');
62
+ });
63
+ });
64
+
65
+ describe('combined scenarios', () => {
66
+ it('should handle both parallel and prime notation in same document', () => {
67
+ const parallelSpan = document.createElement('span');
68
+ parallelSpan.setAttribute('mathquill-command-id', '1');
69
+ parallelSpan.innerText = '∥';
70
+ document.body.appendChild(parallelSpan);
71
+
72
+ const primeSpan = document.createElement('span');
73
+ primeSpan.setAttribute('mathquill-command-id', '2');
74
+ primeSpan.innerText = '′';
75
+ document.body.appendChild(primeSpan);
76
+
77
+ updateSpans();
78
+
79
+ expect(parallelSpan.style.fontSize).toBe('32px');
80
+ expect(primeSpan.getAttribute('data-prime')).toBe('true');
81
+ });
82
+
83
+ it('should handle complex document with multiple span types', () => {
84
+ const parallelSpan = document.createElement('span');
85
+ parallelSpan.setAttribute('mathquill-command-id', '1');
86
+ parallelSpan.innerText = '∥';
87
+ document.body.appendChild(parallelSpan);
88
+
89
+ const primeSpan = document.createElement('span');
90
+ primeSpan.setAttribute('mathquill-command-id', '2');
91
+ primeSpan.innerText = '′';
92
+ document.body.appendChild(primeSpan);
93
+
94
+ const normalSpan = document.createElement('span');
95
+ normalSpan.setAttribute('mathquill-command-id', '3');
96
+ normalSpan.innerText = 'x';
97
+ document.body.appendChild(normalSpan);
98
+
99
+ const editableParallel = document.createElement('span');
100
+ editableParallel.setAttribute('mathquill-command-id', '4');
101
+ editableParallel.innerText = '∥';
102
+ editableParallel.className = 'mq-editable-field';
103
+ document.body.appendChild(editableParallel);
104
+
105
+ updateSpans();
106
+
107
+ expect(parallelSpan.style.fontSize).toBe('32px');
108
+ expect(primeSpan.getAttribute('data-prime')).toBe('true');
109
+ expect(normalSpan.style.fontSize).toBe('');
110
+ expect(normalSpan.getAttribute('data-prime')).toBeNull();
111
+ expect(editableParallel.style.fontSize).toBe('');
112
+ });
113
+ });
114
+
115
+ describe('edge cases', () => {
116
+ it('should handle empty document', () => {
117
+ expect(() => updateSpans()).not.toThrow();
118
+ });
119
+
120
+ it('should handle document with no mathquill spans', () => {
121
+ const span = document.createElement('span');
122
+ span.innerText = '∥';
123
+ document.body.appendChild(span);
124
+
125
+ expect(() => updateSpans()).not.toThrow();
126
+ expect(span.style.fontSize).toBe('');
127
+ });
128
+
129
+ it('should handle spans with empty innerText', () => {
130
+ const span = document.createElement('span');
131
+ span.setAttribute('mathquill-command-id', '1');
132
+ span.innerText = '';
133
+ document.body.appendChild(span);
134
+
135
+ expect(() => updateSpans()).not.toThrow();
136
+ });
137
+
138
+ it('should handle spans with whitespace', () => {
139
+ const span = document.createElement('span');
140
+ span.setAttribute('mathquill-command-id', '1');
141
+ span.innerText = ' ';
142
+ document.body.appendChild(span);
143
+
144
+ expect(() => updateSpans()).not.toThrow();
145
+ });
146
+
147
+ it('should handle null or undefined spans gracefully', () => {
148
+ const span = document.createElement('span');
149
+ span.setAttribute('mathquill-command-id', '1');
150
+ span.innerText = '∥';
151
+ document.body.appendChild(span);
152
+
153
+ expect(() => updateSpans()).not.toThrow();
154
+ });
155
+ });
156
+
157
+ describe('idempotency', () => {
158
+ it('should be safe to call multiple times on parallel notation', () => {
159
+ const span = document.createElement('span');
160
+ span.setAttribute('mathquill-command-id', '1');
161
+ span.innerText = '∥';
162
+ document.body.appendChild(span);
163
+
164
+ updateSpans();
165
+ const fontSize1 = span.style.fontSize;
166
+
167
+ updateSpans();
168
+ const fontSize2 = span.style.fontSize;
169
+
170
+ updateSpans();
171
+ const fontSize3 = span.style.fontSize;
172
+
173
+ expect(fontSize1).toBe('32px');
174
+ expect(fontSize2).toBe('32px');
175
+ expect(fontSize3).toBe('32px');
176
+ });
177
+
178
+ it('should be safe to call multiple times on prime notation', () => {
179
+ const span = document.createElement('span');
180
+ span.setAttribute('mathquill-command-id', '1');
181
+ span.innerText = '′';
182
+ document.body.appendChild(span);
183
+
184
+ updateSpans();
185
+ expect(span.getAttribute('data-prime')).toBe('true');
186
+
187
+ updateSpans();
188
+ expect(span.getAttribute('data-prime')).toBe('true');
189
+
190
+ updateSpans();
191
+ expect(span.getAttribute('data-prime')).toBe('true');
192
+ });
193
+ });
194
+
195
+ describe('className variations', () => {
196
+ it('should modify parallel notation with classes other than mq-editable-field', () => {
197
+ const span = document.createElement('span');
198
+ span.setAttribute('mathquill-command-id', '1');
199
+ span.innerText = '∥';
200
+ span.className = 'some-other-class';
201
+ document.body.appendChild(span);
202
+
203
+ updateSpans();
204
+
205
+ expect(span.style.fontSize).toBe('32px');
206
+ });
207
+
208
+ it('should modify parallel notation with no className', () => {
209
+ const span = document.createElement('span');
210
+ span.setAttribute('mathquill-command-id', '1');
211
+ span.innerText = '∥';
212
+ document.body.appendChild(span);
213
+
214
+ updateSpans();
215
+
216
+ expect(span.style.fontSize).toBe('32px');
217
+ });
218
+ });
219
+
220
+ describe('nested structures', () => {
221
+ it('should handle spans nested in other elements', () => {
222
+ const container = document.createElement('div');
223
+ const span = document.createElement('span');
224
+ span.setAttribute('mathquill-command-id', '1');
225
+ span.innerText = '∥';
226
+ container.appendChild(span);
227
+ document.body.appendChild(container);
228
+
229
+ updateSpans();
230
+
231
+ expect(span.style.fontSize).toBe('32px');
232
+ });
233
+
234
+ it('should handle deeply nested spans', () => {
235
+ const level1 = document.createElement('div');
236
+ const level2 = document.createElement('div');
237
+ const level3 = document.createElement('div');
238
+ const span = document.createElement('span');
239
+ span.setAttribute('mathquill-command-id', '1');
240
+ span.innerText = '′';
241
+
242
+ level3.appendChild(span);
243
+ level2.appendChild(level3);
244
+ level1.appendChild(level2);
245
+ document.body.appendChild(level1);
246
+
247
+ updateSpans();
248
+
249
+ expect(span.getAttribute('data-prime')).toBe('true');
250
+ });
251
+ });
252
+
253
+ describe('special characters', () => {
254
+ it('should only match exact parallel symbol', () => {
255
+ const symbols = ['||', '|', '‖', '∥∥', 'parallel'];
256
+
257
+ symbols.forEach((symbol, index) => {
258
+ const span = document.createElement('span');
259
+ span.setAttribute('mathquill-command-id', String(index));
260
+ span.innerText = symbol;
261
+ document.body.appendChild(span);
262
+ });
263
+
264
+ const parallelSpan = document.createElement('span');
265
+ parallelSpan.setAttribute('mathquill-command-id', 'correct');
266
+ parallelSpan.innerText = '∥';
267
+ document.body.appendChild(parallelSpan);
268
+
269
+ updateSpans();
270
+
271
+ expect(parallelSpan.style.fontSize).toBe('32px');
272
+
273
+ symbols.forEach((_, index) => {
274
+ const span = document.querySelector(`span[mathquill-command-id="${index}"]`);
275
+ expect(span.style.fontSize).toBe('');
276
+ });
277
+ });
278
+
279
+ it('should only match exact prime symbols', () => {
280
+ const symbols = ["'", '"', '`', '´', 'prime'];
281
+
282
+ symbols.forEach((symbol, index) => {
283
+ const span = document.createElement('span');
284
+ span.setAttribute('mathquill-command-id', String(index));
285
+ span.innerText = symbol;
286
+ document.body.appendChild(span);
287
+ });
288
+
289
+ updateSpans();
290
+
291
+ symbols.forEach((_, index) => {
292
+ const span = document.querySelector(`span[mathquill-command-id="${index}"]`);
293
+ expect(span.getAttribute('data-prime')).toBeNull();
294
+ });
295
+ });
296
+ });
297
+ });
package/src/index.jsx CHANGED
@@ -1,5 +1,10 @@
1
1
  import { keysForGrade } from './keys/grades';
2
2
  import { updateSpans } from './updateSpans';
3
+ import * as keys from './keys';
4
+
5
+ import HorizontalKeypad from './horizontal-keypad';
6
+
7
+ import * as mq from './mq';
3
8
 
4
9
  const addLeftBracket = (s) => (s.indexOf('\\(') === 0 ? s : `\\(${s}`);
5
10
  const addRightBracket = (s) => (s.indexOf('\\)') === s.length - 2 ? s : `${s}\\)`);
@@ -9,10 +14,4 @@ const rmRightBracket = (s) => (s.indexOf('\\)') === s.length - 2 ? s.substring(0
9
14
  const addBrackets = (s) => addRightBracket(addLeftBracket(s));
10
15
  const removeBrackets = (s) => rmRightBracket(rmLeftBracket(s));
11
16
 
12
- import * as keys from './keys';
13
-
14
- import HorizontalKeypad from './horizontal-keypad';
15
-
16
- import * as mq from './mq';
17
-
18
17
  export { keysForGrade, addBrackets, removeBrackets, keys, HorizontalKeypad, mq, updateSpans };
@@ -1,5 +1,4 @@
1
1
  import { sortKeys } from '../keys-layout';
2
- import { baseSet, comparison } from '../../keys';
3
2
 
4
3
  describe('keys-layout', () => {
5
4
  describe('sortKeys', () => {
@@ -2,10 +2,9 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import Button from '@mui/material/Button';
4
4
  import IconButton from '@mui/material/IconButton';
5
- import { lighten, alpha, styled } from '@mui/material/styles';
5
+ import { alpha, lighten, styled } from '@mui/material/styles';
6
6
  import debug from 'debug';
7
- import _ from 'lodash';
8
- import MathQuill from '@pie-framework/mathquill';
7
+ import { flatten } from 'lodash-es';
9
8
  import * as mq from '../mq';
10
9
 
11
10
  import { baseSet } from '../keys';
@@ -341,7 +340,7 @@ export class KeyPad extends React.Component {
341
340
 
342
341
  flowKeys = (base, extras) => {
343
342
  const transposed = [...sortKeys(base), ...sortKeys(extras)];
344
- return _.flatten(transposed);
343
+ return flatten(transposed);
345
344
  };
346
345
 
347
346
  keyIsNotAllowed = (key) => {
@@ -1,4 +1,4 @@
1
- import * as _ from 'lodash';
1
+ import { times, zip } from 'lodash-es';
2
2
 
3
3
  /**
4
4
  * Sort additional keys.
@@ -8,10 +8,9 @@ import * as _ from 'lodash';
8
8
  */
9
9
  export const sortKeys = (keys) => {
10
10
  // add any missing rows
11
- _.times(5 - keys.length, () => {
12
- keys.push([]);
13
- });
11
+ times(5 - keys.length, () => keys.push([]));
12
+
13
+ const out = zip.apply(null, keys);
14
14
 
15
- const out = _.zip.apply(null, keys);
16
15
  return out;
17
16
  };
@@ -1,5 +1,5 @@
1
1
  import { extendKeySet } from '../utils';
2
- import { keysForGrade, gradeSets } from '../grades';
2
+ import { gradeSets, keysForGrade } from '../grades';
3
3
  import * as comparison from '../../keys/comparison';
4
4
 
5
5
  describe('utils', () => {
@@ -1,4 +1,4 @@
1
- import times from 'lodash/times';
1
+ import { times } from 'lodash-es';
2
2
 
3
3
  const digitMap = {
4
4
  0: 'zero',
package/src/keys/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import digits from './digits';
2
2
  import * as nav from './navigation';
3
3
  import * as edit from './edit';
4
- import { divide, multiply, plus, minus, equals } from './basic-operators';
4
+ import { divide, equals, minus, multiply, plus } from './basic-operators';
5
+ import * as comparison from './comparison';
6
+ import * as fractions from './fractions';
7
+ import * as exponent from './exponent';
8
+ import * as misc from './misc';
5
9
 
6
10
  const { one, two, three, four, five, six, seven, eight, nine, zero, comma, decimalPoint } = digits;
7
11
 
@@ -13,9 +17,4 @@ export const baseSet = [
13
17
  [nav.left, nav.right, edit.del, equals],
14
18
  ];
15
19
 
16
- import * as comparison from './comparison';
17
- import * as fractions from './fractions';
18
- import * as exponent from './exponent';
19
- import * as misc from './misc';
20
-
21
20
  export { comparison, fractions, exponent, misc };
package/src/keys/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import _ from 'lodash';
1
+ import { flatten, times } from 'lodash-es';
2
2
 
3
3
  export const mkSet = (category) => (o) => ({ ...o, category });
4
4
 
@@ -23,9 +23,7 @@ export const toKey = (category) => (v) => {
23
23
  export const transformToKeySetStructure = (data = []) => {
24
24
  const structure = [];
25
25
 
26
- _.times(5, () => {
27
- structure.push([]);
28
- });
26
+ times(5, () => structure.push([]));
29
27
 
30
28
  let ln = data.length;
31
29
  let i = 0;
@@ -43,9 +41,10 @@ export const transformToKeySetStructure = (data = []) => {
43
41
  };
44
42
 
45
43
  const latexAndNameDontExist = (base) => (k) => {
46
- const flattened = _.flatten(base);
44
+ const flattened = flatten(base);
47
45
  const latexExists = flattened.some((b) => b.latex === k.latex);
48
46
  const nameExists = flattened.some((b) => b.name === k.name);
47
+
49
48
  return !latexExists && !nameExists;
50
49
  };
51
50
 
@@ -54,12 +53,8 @@ export const extendKeySet = (base = [], keySetData = []) => {
54
53
 
55
54
  const final = [];
56
55
 
57
- _.times(5 - base.length, () => {
58
- base.push([]);
59
- });
60
- _.times(5, () => {
61
- final.push([]);
62
- });
56
+ times(5 - base.length, () => base.push([]));
57
+ times(5, () => final.push([]));
63
58
 
64
59
  const extra = transformToKeySetStructure(keySetData);
65
60