@pie-lib/math-input-mathlive 1.0.8 → 1.0.9-next.6618

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 (37) hide show
  1. package/LICENSE.md +5 -0
  2. package/README.md +1 -1
  3. package/lib/mathlive-instance.js +0 -13
  4. package/lib/mathlive-instance.js.map +1 -1
  5. package/lib/mf/input.js +5 -18
  6. package/lib/mf/input.js.map +1 -1
  7. package/lib/mf/static.js +4 -17
  8. package/lib/mf/static.js.map +1 -1
  9. package/package.json +4 -3
  10. package/src/__tests__/keypad-label.test.jsx +13 -5
  11. package/src/mathlive-instance.js +0 -12
  12. package/src/mf/input.jsx +5 -19
  13. package/src/mf/static.jsx +4 -20
  14. package/lib/__tests__/composites.test.js +0 -255
  15. package/lib/__tests__/composites.test.js.map +0 -1
  16. package/lib/__tests__/drop-in-compat.test.js +0 -133
  17. package/lib/__tests__/drop-in-compat.test.js.map +0 -1
  18. package/lib/__tests__/index.test.js +0 -118
  19. package/lib/__tests__/index.test.js.map +0 -1
  20. package/lib/__tests__/input-imperative.test.js +0 -155
  21. package/lib/__tests__/input-imperative.test.js.map +0 -1
  22. package/lib/__tests__/keypad-label.test.js +0 -44
  23. package/lib/__tests__/keypad-label.test.js.map +0 -1
  24. package/lib/__tests__/keypad-render.test.js +0 -206
  25. package/lib/__tests__/keypad-render.test.js.map +0 -1
  26. package/lib/__tests__/latex-bridge.test.js +0 -251
  27. package/lib/__tests__/latex-bridge.test.js.map +0 -1
  28. package/lib/__tests__/mathlive-instance.test.js +0 -188
  29. package/lib/__tests__/mathlive-instance.test.js.map +0 -1
  30. package/lib/__tests__/mount-race.test.js +0 -194
  31. package/lib/__tests__/mount-race.test.js.map +0 -1
  32. package/lib/__tests__/static-prompts.test.js +0 -282
  33. package/lib/__tests__/static-prompts.test.js.map +0 -1
  34. package/src/__tests__/composites.test.jsx +0 -220
  35. package/src/__tests__/keypad-render.test.jsx +0 -123
  36. package/src/__tests__/mount-race.test.jsx +0 -129
  37. package/src/__tests__/static-prompts.test.jsx +0 -251
@@ -1,251 +0,0 @@
1
- import Static from '../mf/static';
2
-
3
- /**
4
- * The answer-block contract: `\MathQuillMathField[id]{}` in stored latex becomes
5
- * a MathLive prompt, and sub-field values/focus are surfaced through the same
6
- * callbacks @pie-lib/math-input exposed (`onSubFieldChange`, `onSubFieldFocus`,
7
- * `getFieldName`, `setInput`).
8
- *
9
- * Driven against a stub mathfield: a real <math-field> needs a browser, and what
10
- * matters here is the mapping, not MathLive's rendering.
11
- */
12
- const stubField = (values = {}, selection = null) => ({
13
- values: { ...values },
14
- getPrompts() {
15
- return Object.keys(this.values);
16
- },
17
- getPromptValue(id) {
18
- return this.values[id];
19
- },
20
- setPromptValue(id, v) {
21
- this.values[id] = v;
22
- },
23
- getPromptRange(id) {
24
- const i = Object.keys(this.values).indexOf(id);
25
-
26
- return [i * 10, i * 10 + 5];
27
- },
28
- selection,
29
- addEventListener() {},
30
- removeEventListener() {},
31
- focus() {
32
- this.focused = true;
33
- },
34
- blur() {
35
- this.blurred = true;
36
- },
37
- remove() {},
38
- });
39
-
40
- const make = (props = {}) => new Static({ latex: 'x=\\MathQuillMathField[r1]{}', getFieldName: () => {}, ...props });
41
-
42
- describe('Static: answer blocks / prompts', () => {
43
- describe('isInteractive', () => {
44
- it('is interactive when the latex has answer blocks', () => {
45
- expect(make({ latex: 'x=\\MathQuillMathField[r1]{}' }).isInteractive()).toBe(true);
46
- expect(make({ latex: 'x=\\placeholder[r1]{}' }).isInteractive()).toBe(true);
47
- });
48
-
49
- it('is display-only for plain latex', () => {
50
- expect(make({ latex: '\\frac{1}{2}' }).isInteractive()).toBe(false);
51
- expect(make({ latex: '' }).isInteractive()).toBe(false);
52
- });
53
- });
54
-
55
- describe('values', () => {
56
- it('returns {} before the field exists', () => {
57
- expect(make().values()).toEqual({});
58
- });
59
-
60
- it('maps each prompt id to its stored-form latex', () => {
61
- const s = make();
62
-
63
- s.mathField = stubField({ r1: '7', r2: '\\placeholder{}' });
64
-
65
- // \placeholder must not leak into stored values
66
- expect(s.values()).toEqual({ r1: '7', r2: '' });
67
- });
68
- });
69
-
70
- describe('promptHandle / innerFields', () => {
71
- it('exposes a MathQuill-field-like handle with get/set latex', () => {
72
- const s = make();
73
-
74
- s.mathField = stubField({ r1: '7' });
75
-
76
- const h = s.promptHandle('r1');
77
-
78
- expect(h.id).toEqual('r1');
79
- expect(h.latex()).toEqual('7');
80
-
81
- h.latex('9');
82
- expect(s.mathField.values.r1).toEqual('9');
83
- });
84
-
85
- it('handle latex() is safe with no field', () => {
86
- expect(make().promptHandle('r1').latex()).toEqual('');
87
- });
88
-
89
- it('innerFields returns one handle per prompt', () => {
90
- const s = make();
91
-
92
- s.mathField = stubField({ r1: '1', r2: '2' });
93
-
94
- expect(s.innerFields.map((f) => f.id)).toEqual(['r1', 'r2']);
95
- expect(make().innerFields).toEqual([]);
96
- });
97
- });
98
-
99
- describe('onSubFieldChange', () => {
100
- it('fires only for prompts whose value changed', () => {
101
- const onSubFieldChange = jest.fn();
102
- const s = make({ onSubFieldChange });
103
-
104
- s.mathField = stubField({ r1: '1', r2: '2' });
105
- s.promptValues = { r1: '1', r2: '2' };
106
-
107
- s.mathField.values.r2 = '5';
108
- s.onPromptInput();
109
-
110
- expect(onSubFieldChange).toHaveBeenCalledTimes(1);
111
- expect(onSubFieldChange).toHaveBeenCalledWith('r2', '5');
112
- });
113
-
114
- it('uses getFieldName when it returns a name', () => {
115
- const onSubFieldChange = jest.fn();
116
- const s = make({ onSubFieldChange, getFieldName: (handle) => 'named-' + handle.id });
117
-
118
- s.mathField = stubField({ r1: '1' });
119
- s.promptValues = {};
120
-
121
- s.onPromptInput();
122
-
123
- expect(onSubFieldChange).toHaveBeenCalledWith('named-r1', '1');
124
- });
125
-
126
- it('still tracks values when no callback is supplied', () => {
127
- const s = make();
128
-
129
- s.mathField = stubField({ r1: '3' });
130
- s.onPromptInput();
131
-
132
- expect(s.promptValues).toEqual({ r1: '3' });
133
- });
134
- });
135
-
136
- describe('onSubFieldFocus', () => {
137
- it('reports the prompt containing the selection, plus setInput', () => {
138
- const onSubFieldFocus = jest.fn();
139
- const setInput = jest.fn();
140
- const s = make({ onSubFieldFocus, setInput });
141
-
142
- // r2 occupies offsets 10..15
143
- s.mathField = stubField({ r1: '', r2: '' }, { ranges: [[11, 11]] });
144
- s.onPromptFocus();
145
-
146
- expect(onSubFieldFocus).toHaveBeenCalledTimes(1);
147
- expect(onSubFieldFocus.mock.calls[0][0]).toEqual('r2');
148
- expect(onSubFieldFocus.mock.calls[0][1].id).toEqual('r2');
149
- expect(setInput).toHaveBeenCalled();
150
- });
151
-
152
- it('does nothing without a selection', () => {
153
- const onSubFieldFocus = jest.fn();
154
- const s = make({ onSubFieldFocus });
155
-
156
- s.mathField = stubField({ r1: '' }, null);
157
- s.onPromptFocus();
158
-
159
- expect(onSubFieldFocus).not.toHaveBeenCalled();
160
- });
161
-
162
- it('does not throw when the field is missing', () => {
163
- const s = make({ onSubFieldFocus: jest.fn() });
164
-
165
- expect(() => s.onPromptFocus()).not.toThrow();
166
- });
167
- });
168
-
169
- describe('accessibility announcements', () => {
170
- afterEach(() => {
171
- document.body.innerHTML = '';
172
- });
173
-
174
- it('creates a polite off-screen live region', () => {
175
- const s = make();
176
-
177
- s.createLiveRegion();
178
-
179
- expect(s.liveRegion.getAttribute('aria-live')).toEqual('polite');
180
- expect(s.liveRegion.getAttribute('aria-atomic')).toEqual('true');
181
- expect(document.body.contains(s.liveRegion)).toBe(true);
182
-
183
- s.removeLiveRegion();
184
- expect(s.liveRegion).toBeUndefined();
185
- });
186
-
187
- it('does not create a second region', () => {
188
- const s = make();
189
-
190
- s.createLiveRegion();
191
- const first = s.liveRegion;
192
-
193
- s.createLiveRegion();
194
- expect(s.liveRegion).toBe(first);
195
- s.removeLiveRegion();
196
- });
197
-
198
- it('announces when typed input expands into a command', () => {
199
- const s = make();
200
-
201
- s.createLiveRegion();
202
- s.promptValues = { r1: 'x' };
203
- // grew by more than one char AND gained a backslash => a conversion
204
- s.announceConversion({ r1: 'x\\frac{}{}' });
205
-
206
- expect(s.liveRegion.textContent).toEqual('Converted to math symbol');
207
- s.removeLiveRegion();
208
- });
209
-
210
- it('does not announce ordinary typing', () => {
211
- const s = make();
212
-
213
- s.createLiveRegion();
214
- s.promptValues = { r1: 'x' };
215
- s.announceConversion({ r1: 'xy' });
216
-
217
- expect(s.liveRegion.textContent).toEqual('');
218
- s.removeLiveRegion();
219
- });
220
-
221
- it('does not announce a deletion', () => {
222
- const s = make();
223
-
224
- s.createLiveRegion();
225
- s.promptValues = { r1: 'x\\frac{}{}' };
226
- s.onKeyDown({ key: 'Backspace' });
227
- s.announceConversion({ r1: 'x' });
228
-
229
- expect(s.liveRegion.textContent).toEqual('');
230
- s.removeLiveRegion();
231
- });
232
- });
233
-
234
- describe('focus / blur', () => {
235
- it('delegates to the field and is safe without one', () => {
236
- const s = make();
237
-
238
- expect(() => {
239
- s.focus();
240
- s.blur();
241
- }).not.toThrow();
242
-
243
- s.mathField = stubField();
244
- s.focus();
245
- s.blur();
246
-
247
- expect(s.mathField.focused).toBe(true);
248
- expect(s.mathField.blurred).toBe(true);
249
- });
250
- });
251
- });