@pie-lib/math-toolbar 3.1.0-beta.2 → 3.1.0-beta.4
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/lib/__tests__/editor-and-pad-mathlive.test.js +272 -0
- package/lib/__tests__/editor-and-pad-mathlive.test.js.map +1 -0
- package/lib/__tests__/math-preview.test.js +70 -0
- package/lib/__tests__/math-preview.test.js.map +1 -1
- package/lib/math-preview.js +4 -0
- package/lib/math-preview.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/editor-and-pad-mathlive.test.js +178 -0
- package/src/__tests__/math-preview.test.js +65 -0
- package/src/math-preview.jsx +4 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
5
|
+
var _editorAndPad = require("../editor-and-pad");
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
/**
|
|
9
|
+
* Covers the call sites that changed when this package moved from
|
|
10
|
+
* @pie-lib/math-input (MathQuill) to @pie-lib/math-input-mathlive.
|
|
11
|
+
*
|
|
12
|
+
* All three were MathQuill-shaped and silently changed meaning:
|
|
13
|
+
* - shouldComponentUpdate read `this.input.mathField.latex()`, which throws now
|
|
14
|
+
* (and the field loads asynchronously, so `this.input` can be null)
|
|
15
|
+
* - the mixed-number workaround poked `__controller.cursor`, a MathQuill
|
|
16
|
+
* internal with no MathLive equivalent
|
|
17
|
+
* - onClick routes keypad presses through the imperative field API
|
|
18
|
+
*/
|
|
19
|
+
describe('EditorAndPad after the MathLive migration', function () {
|
|
20
|
+
var props = function props() {
|
|
21
|
+
var over = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22
|
+
return _objectSpread({
|
|
23
|
+
classes: {},
|
|
24
|
+
classNames: {},
|
|
25
|
+
onChange: jest.fn()
|
|
26
|
+
}, over);
|
|
27
|
+
};
|
|
28
|
+
describe('shouldComponentUpdate', function () {
|
|
29
|
+
it('treats a missing input ref as different, so the first render is not skipped', function () {
|
|
30
|
+
var c = new _editorAndPad.EditorAndPad(props({
|
|
31
|
+
latex: 'x'
|
|
32
|
+
}));
|
|
33
|
+
c.input = null;
|
|
34
|
+
expect(c.shouldComponentUpdate({
|
|
35
|
+
latex: 'x'
|
|
36
|
+
}, {})).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('does not throw when the math engine has not loaded yet', function () {
|
|
39
|
+
var c = new _editorAndPad.EditorAndPad(props({
|
|
40
|
+
latex: 'x'
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
// latex() returns '' until MathLive is ready
|
|
44
|
+
c.input = {
|
|
45
|
+
latex: function latex() {
|
|
46
|
+
return '';
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
expect(function () {
|
|
50
|
+
return c.shouldComponentUpdate({
|
|
51
|
+
latex: 'x'
|
|
52
|
+
}, {});
|
|
53
|
+
}).not.toThrow();
|
|
54
|
+
expect(c.shouldComponentUpdate({
|
|
55
|
+
latex: 'x'
|
|
56
|
+
}, {})).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
it('skips the update when the field already holds the incoming latex', function () {
|
|
59
|
+
var c = new _editorAndPad.EditorAndPad(props({
|
|
60
|
+
latex: 'x',
|
|
61
|
+
keypadMode: 'a',
|
|
62
|
+
noDecimal: false
|
|
63
|
+
}));
|
|
64
|
+
c.input = {
|
|
65
|
+
latex: function latex() {
|
|
66
|
+
return 'x';
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
c.state = {
|
|
70
|
+
equationEditor: 'geometry'
|
|
71
|
+
};
|
|
72
|
+
expect(c.shouldComponentUpdate({
|
|
73
|
+
latex: 'x',
|
|
74
|
+
keypadMode: 'a',
|
|
75
|
+
noDecimal: false
|
|
76
|
+
}, c.state)).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
it('re-renders when the field differs from the incoming latex', function () {
|
|
79
|
+
var c = new _editorAndPad.EditorAndPad(props({
|
|
80
|
+
latex: 'y'
|
|
81
|
+
}));
|
|
82
|
+
c.input = {
|
|
83
|
+
latex: function latex() {
|
|
84
|
+
return 'x';
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
expect(c.shouldComponentUpdate({
|
|
88
|
+
latex: 'y'
|
|
89
|
+
}, {})).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
it('uses input.latex(), never input.mathField.latex()', function () {
|
|
92
|
+
var c = new _editorAndPad.EditorAndPad(props({
|
|
93
|
+
latex: 'x'
|
|
94
|
+
}));
|
|
95
|
+
var latex = jest.fn(function () {
|
|
96
|
+
return 'x';
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// deliberately no `mathField` - the old code would have thrown here
|
|
100
|
+
c.input = {
|
|
101
|
+
latex: latex
|
|
102
|
+
};
|
|
103
|
+
c.state = {
|
|
104
|
+
equationEditor: 'geometry'
|
|
105
|
+
};
|
|
106
|
+
c.shouldComponentUpdate({
|
|
107
|
+
latex: 'x'
|
|
108
|
+
}, c.state);
|
|
109
|
+
expect(latex).toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('onClick key routing', function () {
|
|
113
|
+
var withInput = function withInput() {
|
|
114
|
+
var over = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
115
|
+
var c = new _editorAndPad.EditorAndPad(props(over));
|
|
116
|
+
var calls = {
|
|
117
|
+
write: [],
|
|
118
|
+
command: [],
|
|
119
|
+
keystroke: [],
|
|
120
|
+
clear: 0
|
|
121
|
+
};
|
|
122
|
+
c.input = {
|
|
123
|
+
write: function write(v) {
|
|
124
|
+
return calls.write.push(v);
|
|
125
|
+
},
|
|
126
|
+
command: function command(v) {
|
|
127
|
+
return calls.command.push(v);
|
|
128
|
+
},
|
|
129
|
+
keystroke: function keystroke(v) {
|
|
130
|
+
return calls.keystroke.push(v);
|
|
131
|
+
},
|
|
132
|
+
clear: function clear() {
|
|
133
|
+
return calls.clear++;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
c.updateDisable = function () {};
|
|
137
|
+
return {
|
|
138
|
+
c: c,
|
|
139
|
+
calls: calls
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// toNodeData keys this off `value === 'clear'`, not `type`
|
|
144
|
+
it('clear', function () {
|
|
145
|
+
var _withInput = withInput(),
|
|
146
|
+
c = _withInput.c,
|
|
147
|
+
calls = _withInput.calls;
|
|
148
|
+
c.onClick({
|
|
149
|
+
value: 'clear'
|
|
150
|
+
});
|
|
151
|
+
expect(calls.clear).toBe(1);
|
|
152
|
+
});
|
|
153
|
+
it('command', function () {
|
|
154
|
+
var _withInput2 = withInput(),
|
|
155
|
+
c = _withInput2.c,
|
|
156
|
+
calls = _withInput2.calls;
|
|
157
|
+
c.onClick({
|
|
158
|
+
type: 'command',
|
|
159
|
+
value: '\\frac'
|
|
160
|
+
});
|
|
161
|
+
expect(calls.command).toEqual(['\\frac']);
|
|
162
|
+
});
|
|
163
|
+
it('cursor keystroke', function () {
|
|
164
|
+
var _withInput3 = withInput(),
|
|
165
|
+
c = _withInput3.c,
|
|
166
|
+
calls = _withInput3.calls;
|
|
167
|
+
c.onClick({
|
|
168
|
+
type: 'cursor',
|
|
169
|
+
value: 'Left'
|
|
170
|
+
});
|
|
171
|
+
expect(calls.keystroke).toEqual(['Left']);
|
|
172
|
+
});
|
|
173
|
+
it('answer block writes the response token', function () {
|
|
174
|
+
var _withInput4 = withInput(),
|
|
175
|
+
c = _withInput4.c,
|
|
176
|
+
calls = _withInput4.calls;
|
|
177
|
+
c.onClick({
|
|
178
|
+
type: 'answer'
|
|
179
|
+
});
|
|
180
|
+
expect(calls.write).toEqual(['%response%']);
|
|
181
|
+
});
|
|
182
|
+
it('plain value', function () {
|
|
183
|
+
var _withInput5 = withInput(),
|
|
184
|
+
c = _withInput5.c,
|
|
185
|
+
calls = _withInput5.calls;
|
|
186
|
+
c.onClick({
|
|
187
|
+
value: 'x'
|
|
188
|
+
});
|
|
189
|
+
expect(calls.write).toEqual(['x']);
|
|
190
|
+
});
|
|
191
|
+
it('ignores a nullish key', function () {
|
|
192
|
+
var _withInput6 = withInput(),
|
|
193
|
+
c = _withInput6.c,
|
|
194
|
+
calls = _withInput6.calls;
|
|
195
|
+
expect(function () {
|
|
196
|
+
return c.onClick(null);
|
|
197
|
+
}).not.toThrow();
|
|
198
|
+
expect(calls.write).toEqual([]);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
describe('onEditorChange', function () {
|
|
202
|
+
var withInput = function withInput() {
|
|
203
|
+
var over = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
204
|
+
var onChange = jest.fn();
|
|
205
|
+
var c = new _editorAndPad.EditorAndPad(props(_objectSpread({
|
|
206
|
+
onChange: onChange
|
|
207
|
+
}, over)));
|
|
208
|
+
var calls = {
|
|
209
|
+
keystroke: [],
|
|
210
|
+
clear: 0,
|
|
211
|
+
write: []
|
|
212
|
+
};
|
|
213
|
+
c.input = {
|
|
214
|
+
keystroke: function keystroke(v) {
|
|
215
|
+
return calls.keystroke.push(v);
|
|
216
|
+
},
|
|
217
|
+
clear: function clear() {
|
|
218
|
+
return calls.clear++;
|
|
219
|
+
},
|
|
220
|
+
write: function write(v) {
|
|
221
|
+
return calls.write.push(v);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
c.updateDisable = function () {};
|
|
225
|
+
return {
|
|
226
|
+
c: c,
|
|
227
|
+
onChange: onChange,
|
|
228
|
+
calls: calls
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
it('propagates ordinary latex to onChange', function () {
|
|
232
|
+
var _withInput7 = withInput(),
|
|
233
|
+
c = _withInput7.c,
|
|
234
|
+
onChange = _withInput7.onChange;
|
|
235
|
+
c.onEditorChange('\\frac{1}{2}');
|
|
236
|
+
expect(onChange).toHaveBeenCalledWith('\\frac{1}{2}');
|
|
237
|
+
});
|
|
238
|
+
it('strips decimals when noDecimal is set', function () {
|
|
239
|
+
var _withInput8 = withInput({
|
|
240
|
+
noDecimal: true
|
|
241
|
+
}),
|
|
242
|
+
c = _withInput8.c,
|
|
243
|
+
onChange = _withInput8.onChange,
|
|
244
|
+
calls = _withInput8.calls;
|
|
245
|
+
c.onEditorChange('1.5');
|
|
246
|
+
expect(calls.clear).toBe(1);
|
|
247
|
+
expect(calls.write).toEqual(['15']);
|
|
248
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
249
|
+
});
|
|
250
|
+
it('undoes the empty fraction after a digit with a public delete, not MathQuill internals', function () {
|
|
251
|
+
var _withInput9 = withInput(),
|
|
252
|
+
c = _withInput9.c,
|
|
253
|
+
onChange = _withInput9.onChange,
|
|
254
|
+
calls = _withInput9.calls;
|
|
255
|
+
|
|
256
|
+
// the shape the old __controller hack targeted
|
|
257
|
+
c.onEditorChange('2\\ \\frac{1}{ }');
|
|
258
|
+
expect(calls.keystroke).toEqual(['Backspace']);
|
|
259
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
260
|
+
});
|
|
261
|
+
it('does not treat normal fractions as the mixed-number case', function () {
|
|
262
|
+
var _withInput0 = withInput(),
|
|
263
|
+
c = _withInput0.c,
|
|
264
|
+
onChange = _withInput0.onChange,
|
|
265
|
+
calls = _withInput0.calls;
|
|
266
|
+
c.onEditorChange('\\frac{1}{2}');
|
|
267
|
+
expect(calls.keystroke).toEqual([]);
|
|
268
|
+
expect(onChange).toHaveBeenCalled();
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
//# sourceMappingURL=editor-and-pad-mathlive.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor-and-pad-mathlive.test.js","names":["_editorAndPad","require","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","describe","props","over","undefined","classes","classNames","onChange","jest","fn","it","c","EditorAndPad","latex","input","expect","shouldComponentUpdate","toBe","not","toThrow","keypadMode","noDecimal","state","equationEditor","toHaveBeenCalled","withInput","calls","write","command","keystroke","clear","v","updateDisable","_withInput","onClick","value","_withInput2","type","toEqual","_withInput3","_withInput4","_withInput5","_withInput6","_withInput7","onEditorChange","toHaveBeenCalledWith","_withInput8","_withInput9","_withInput0"],"sources":["../../src/__tests__/editor-and-pad-mathlive.test.js"],"sourcesContent":["import { EditorAndPad } from '../editor-and-pad';\n\n/**\n * Covers the call sites that changed when this package moved from\n * @pie-lib/math-input (MathQuill) to @pie-lib/math-input-mathlive.\n *\n * All three were MathQuill-shaped and silently changed meaning:\n * - shouldComponentUpdate read `this.input.mathField.latex()`, which throws now\n * (and the field loads asynchronously, so `this.input` can be null)\n * - the mixed-number workaround poked `__controller.cursor`, a MathQuill\n * internal with no MathLive equivalent\n * - onClick routes keypad presses through the imperative field API\n */\ndescribe('EditorAndPad after the MathLive migration', () => {\n const props = (over = {}) => ({ classes: {}, classNames: {}, onChange: jest.fn(), ...over });\n\n describe('shouldComponentUpdate', () => {\n it('treats a missing input ref as different, so the first render is not skipped', () => {\n const c = new EditorAndPad(props({ latex: 'x' }));\n\n c.input = null;\n\n expect(c.shouldComponentUpdate({ latex: 'x' }, {})).toBe(true);\n });\n\n it('does not throw when the math engine has not loaded yet', () => {\n const c = new EditorAndPad(props({ latex: 'x' }));\n\n // latex() returns '' until MathLive is ready\n c.input = { latex: () => '' };\n\n expect(() => c.shouldComponentUpdate({ latex: 'x' }, {})).not.toThrow();\n expect(c.shouldComponentUpdate({ latex: 'x' }, {})).toBe(true);\n });\n\n it('skips the update when the field already holds the incoming latex', () => {\n const c = new EditorAndPad(props({ latex: 'x', keypadMode: 'a', noDecimal: false }));\n\n c.input = { latex: () => 'x' };\n c.state = { equationEditor: 'geometry' };\n\n expect(c.shouldComponentUpdate({ latex: 'x', keypadMode: 'a', noDecimal: false }, c.state)).toBe(false);\n });\n\n it('re-renders when the field differs from the incoming latex', () => {\n const c = new EditorAndPad(props({ latex: 'y' }));\n\n c.input = { latex: () => 'x' };\n\n expect(c.shouldComponentUpdate({ latex: 'y' }, {})).toBe(true);\n });\n\n it('uses input.latex(), never input.mathField.latex()', () => {\n const c = new EditorAndPad(props({ latex: 'x' }));\n const latex = jest.fn(() => 'x');\n\n // deliberately no `mathField` - the old code would have thrown here\n c.input = { latex };\n c.state = { equationEditor: 'geometry' };\n c.shouldComponentUpdate({ latex: 'x' }, c.state);\n\n expect(latex).toHaveBeenCalled();\n });\n });\n\n describe('onClick key routing', () => {\n const withInput = (over = {}) => {\n const c = new EditorAndPad(props(over));\n const calls = { write: [], command: [], keystroke: [], clear: 0 };\n\n c.input = {\n write: (v) => calls.write.push(v),\n command: (v) => calls.command.push(v),\n keystroke: (v) => calls.keystroke.push(v),\n clear: () => calls.clear++,\n };\n c.updateDisable = () => {};\n\n return { c, calls };\n };\n\n // toNodeData keys this off `value === 'clear'`, not `type`\n it('clear', () => {\n const { c, calls } = withInput();\n\n c.onClick({ value: 'clear' });\n expect(calls.clear).toBe(1);\n });\n\n it('command', () => {\n const { c, calls } = withInput();\n\n c.onClick({ type: 'command', value: '\\\\frac' });\n expect(calls.command).toEqual(['\\\\frac']);\n });\n\n it('cursor keystroke', () => {\n const { c, calls } = withInput();\n\n c.onClick({ type: 'cursor', value: 'Left' });\n expect(calls.keystroke).toEqual(['Left']);\n });\n\n it('answer block writes the response token', () => {\n const { c, calls } = withInput();\n\n c.onClick({ type: 'answer' });\n expect(calls.write).toEqual(['%response%']);\n });\n\n it('plain value', () => {\n const { c, calls } = withInput();\n\n c.onClick({ value: 'x' });\n expect(calls.write).toEqual(['x']);\n });\n\n it('ignores a nullish key', () => {\n const { c, calls } = withInput();\n\n expect(() => c.onClick(null)).not.toThrow();\n expect(calls.write).toEqual([]);\n });\n });\n\n describe('onEditorChange', () => {\n const withInput = (over = {}) => {\n const onChange = jest.fn();\n const c = new EditorAndPad(props({ onChange, ...over }));\n const calls = { keystroke: [], clear: 0, write: [] };\n\n c.input = {\n keystroke: (v) => calls.keystroke.push(v),\n clear: () => calls.clear++,\n write: (v) => calls.write.push(v),\n };\n c.updateDisable = () => {};\n\n return { c, onChange, calls };\n };\n\n it('propagates ordinary latex to onChange', () => {\n const { c, onChange } = withInput();\n\n c.onEditorChange('\\\\frac{1}{2}');\n expect(onChange).toHaveBeenCalledWith('\\\\frac{1}{2}');\n });\n\n it('strips decimals when noDecimal is set', () => {\n const { c, onChange, calls } = withInput({ noDecimal: true });\n\n c.onEditorChange('1.5');\n\n expect(calls.clear).toBe(1);\n expect(calls.write).toEqual(['15']);\n expect(onChange).not.toHaveBeenCalled();\n });\n\n it('undoes the empty fraction after a digit with a public delete, not MathQuill internals', () => {\n const { c, onChange, calls } = withInput();\n\n // the shape the old __controller hack targeted\n c.onEditorChange('2\\\\ \\\\frac{1}{ }');\n\n expect(calls.keystroke).toEqual(['Backspace']);\n expect(onChange).not.toHaveBeenCalled();\n });\n\n it('does not treat normal fractions as the mixed-number case', () => {\n const { c, onChange, calls } = withInput();\n\n c.onEditorChange('\\\\frac{1}{2}');\n\n expect(calls.keystroke).toEqual([]);\n exp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,CAACR,QAAQ,CAAC,CAACiB,gBAAgB,CAAC,CAAC;IACrC,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
4
5
|
var _react = _interopRequireDefault(require("react"));
|
|
5
6
|
var _react2 = require("@testing-library/react");
|
|
6
7
|
var _mathPreview = _interopRequireDefault(require("../math-preview"));
|
|
8
|
+
/** Every rule emotion has injected so far, as CSSStyleRule objects. */
|
|
9
|
+
var injectedRules = function injectedRules() {
|
|
10
|
+
return Array.from(document.querySelectorAll('style[data-emotion]')).flatMap(function (tag) {
|
|
11
|
+
return tag.sheet ? Array.from(tag.sheet.cssRules) : [];
|
|
12
|
+
}).filter(function (rule) {
|
|
13
|
+
return rule.selectorText;
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The `.ML__latex` rule that actually applies to `element`.
|
|
19
|
+
*
|
|
20
|
+
* Matching with `element.matches` rather than string comparison means the
|
|
21
|
+
* assertions cover the selector too: a rule written as `& > .ML__latex` would
|
|
22
|
+
* not match the nested markup MathLive emits, and these tests would fail.
|
|
23
|
+
*/
|
|
24
|
+
var mathLiveRuleFor = function mathLiveRuleFor(element) {
|
|
25
|
+
return injectedRules().find(function (rule) {
|
|
26
|
+
return rule.selectorText.includes('.ML__latex') && element.matches(rule.selectorText);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Stand in for MathLive's `convertLatexToMarkup` output, which is
|
|
32
|
+
* `<span class="ML__latex">...</span>` nested inside `mf.Static`'s holder span.
|
|
33
|
+
* MathLive does not load under jsdom, so the markup is added by hand.
|
|
34
|
+
*/
|
|
35
|
+
var addStaticMarkup = function addStaticMarkup(container) {
|
|
36
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
37
|
+
var parent = container.firstChild;
|
|
38
|
+
for (var i = 1; i < depth; i += 1) {
|
|
39
|
+
var wrapper = document.createElement('span');
|
|
40
|
+
parent.appendChild(wrapper);
|
|
41
|
+
parent = wrapper;
|
|
42
|
+
}
|
|
43
|
+
var markup = document.createElement('span');
|
|
44
|
+
markup.className = 'ML__latex';
|
|
45
|
+
parent.appendChild(markup);
|
|
46
|
+
return markup;
|
|
47
|
+
};
|
|
7
48
|
describe('MathPreview', function () {
|
|
8
49
|
var defaultProps = {
|
|
9
50
|
latex: 'sqrt(5)',
|
|
@@ -17,5 +58,34 @@ describe('MathPreview', function () {
|
|
|
17
58
|
container = _render.container;
|
|
18
59
|
expect(container.firstChild).toBeInTheDocument();
|
|
19
60
|
});
|
|
61
|
+
describe('MathLive static markup', function () {
|
|
62
|
+
it('is outlined and padded when not selected', function () {
|
|
63
|
+
var _render2 = (0, _react2.render)(/*#__PURE__*/_react["default"].createElement(_mathPreview["default"], (0, _extends2["default"])({}, defaultProps, {
|
|
64
|
+
isSelected: false
|
|
65
|
+
}))),
|
|
66
|
+
container = _render2.container;
|
|
67
|
+
var rule = mathLiveRuleFor(addStaticMarkup(container));
|
|
68
|
+
expect(rule).toBeDefined();
|
|
69
|
+
expect(rule.style.getPropertyValue('border')).toEqual('solid 1px lightgrey');
|
|
70
|
+
expect(rule.style.getPropertyValue('padding')).toEqual('5px');
|
|
71
|
+
});
|
|
72
|
+
it('drops its outline and padding when selected, so only the container border shows', function () {
|
|
73
|
+
var _render3 = (0, _react2.render)(/*#__PURE__*/_react["default"].createElement(_mathPreview["default"], (0, _extends2["default"])({}, defaultProps, {
|
|
74
|
+
isSelected: true
|
|
75
|
+
}))),
|
|
76
|
+
container = _render3.container;
|
|
77
|
+
var rule = mathLiveRuleFor(addStaticMarkup(container));
|
|
78
|
+
expect(rule).toBeDefined();
|
|
79
|
+
expect(rule.style.getPropertyValue('border')).toEqual('solid 0px lightgrey');
|
|
80
|
+
expect(rule.style.getPropertyValue('padding')).toEqual('0px');
|
|
81
|
+
});
|
|
82
|
+
it('is styled at any depth below the container, not just as a direct child', function () {
|
|
83
|
+
var _render4 = (0, _react2.render)(/*#__PURE__*/_react["default"].createElement(_mathPreview["default"], (0, _extends2["default"])({}, defaultProps, {
|
|
84
|
+
isSelected: false
|
|
85
|
+
}))),
|
|
86
|
+
container = _render4.container;
|
|
87
|
+
expect(mathLiveRuleFor(addStaticMarkup(container, 3))).toBeDefined();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
20
90
|
});
|
|
21
91
|
//# sourceMappingURL=math-preview.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math-preview.test.js","names":["_react","_interopRequireDefault","require","_react2","_mathPreview","describe","defaultProps","latex","classes","isSelected","onFocus","jest","fn","onBlur","it","_render","render","
|
|
1
|
+
{"version":3,"file":"math-preview.test.js","names":["_react","_interopRequireDefault","require","_react2","_mathPreview","injectedRules","Array","from","document","querySelectorAll","flatMap","tag","sheet","cssRules","filter","rule","selectorText","mathLiveRuleFor","element","find","includes","matches","addStaticMarkup","container","depth","arguments","length","undefined","parent","firstChild","i","wrapper","createElement","appendChild","markup","className","describe","defaultProps","latex","classes","isSelected","onFocus","jest","fn","onBlur","it","_render","render","expect","toBeInTheDocument","_render2","_extends2","toBeDefined","style","getPropertyValue","toEqual","_render3","_render4"],"sources":["../../src/__tests__/math-preview.test.js"],"sourcesContent":["import React from 'react';\nimport { render } from '@testing-library/react';\nimport MathPreview from '../math-preview';\n\n/** Every rule emotion has injected so far, as CSSStyleRule objects. */\nconst injectedRules = () =>\n Array.from(document.querySelectorAll('style[data-emotion]'))\n .flatMap((tag) => (tag.sheet ? Array.from(tag.sheet.cssRules) : []))\n .filter((rule) => rule.selectorText);\n\n/**\n * The `.ML__latex` rule that actually applies to `element`.\n *\n * Matching with `element.matches` rather than string comparison means the\n * assertions cover the selector too: a rule written as `& > .ML__latex` would\n * not match the nested markup MathLive emits, and these tests would fail.\n */\nconst mathLiveRuleFor = (element) =>\n injectedRules().find((rule) => rule.selectorText.includes('.ML__latex') && element.matches(rule.selectorText));\n\n/**\n * Stand in for MathLive's `convertLatexToMarkup` output, which is\n * `<span class=\"ML__latex\">...</span>` nested inside `mf.Static`'s holder span.\n * MathLive does not load under jsdom, so the markup is added by hand.\n */\nconst addStaticMarkup = (container, depth = 1) => {\n let parent = container.firstChild;\n\n for (let i = 1; i < depth; i += 1) {\n const wrapper = document.createElement('span');\n\n parent.appendChild(wrapper);\n parent = wrapper;\n }\n\n const markup = document.createElement('span');\n\n markup.className = 'ML__latex';\n parent.appendChild(markup);\n\n return markup;\n};\n\ndescribe('MathPreview', () => {\n const defaultProps = {\n latex: 'sqrt(5)',\n classes: {},\n isSelected: false,\n onFocus: jest.fn(),\n onBlur: jest.fn(),\n };\n\n it('renders with default props', () => {\n const { container } = render(<MathPreview {...defaultProps} />);\n expect(container.firstChild).toBeInTheDocument();\n });\n\n describe('MathLive static markup', () => {\n it('is outlined and padded when not selected', () => {\n const { container } = render(<MathPreview {...defaultProps} isSelected={false} />);\n const rule = mathLiveRuleFor(addStaticMarkup(container));\n\n expect(rule).toBeDefined();\n expect(rule.style.getPropertyValue('border')).toEqual('solid 1px lightgrey');\n expect(rule.style.getPropertyValue('padding')).toEqual('5px');\n });\n\n it('drops its outline and padding when selected, so only the container border shows', () => {\n const { container } = render(<MathPreview {...defaultProps} isSelected />);\n const rule = mathLiveRuleFor(addStaticMarkup(container));\n\n expect(rule).toBeDefined();\n expect(rule.style.getPropertyValue('border')).toEqual('solid 0px lightgrey');\n expect(rule.style.getPropertyValue('padding')).toEqual('0px');\n });\n\n it('is styled at any depth below the container, not just as a direct child', () => {\n const { container } = render(<MathPreview {...defaultProps} isSelected={false} />);\n\n expect(mathLiveRuleFor(addStaticMarkup(container, 3))).toBeDefined();\n });\n });\n});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/math-preview.js
CHANGED
|
@@ -38,6 +38,10 @@ var MathPreviewContainer = (0, _styles.styled)('div')(function (_ref) {
|
|
|
38
38
|
'& > .mq-math-mode': {
|
|
39
39
|
border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey'
|
|
40
40
|
},
|
|
41
|
+
'& .ML__latex': {
|
|
42
|
+
border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',
|
|
43
|
+
padding: isSelected ? '0px' : '5px'
|
|
44
|
+
},
|
|
41
45
|
'& > .mq-focused': {
|
|
42
46
|
outline: 'none',
|
|
43
47
|
boxShadow: 'none',
|
package/lib/math-preview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math-preview.js","names":["_react","_interopRequireDefault","require","_debug","_styles","_propTypes","_mathInputMathlive","_utils","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","ownKeys","r","Object","keys","getOwnPropertySymbols","filter","getOwnPropertyDescriptor","enumerable","push","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","_mq$CommonMqStyles","mq","CommonMqStyles","commonMqFontStyles","longdivStyles","supsubStyles","log","debug","MathPreviewContainer","styled","_ref","theme","isSelected","display","alignItems","position","border","outline","boxShadow","borderRadius","paddingTop","verticalAlign","top","left","marginTop","padding","paddingBottom","marginBottom","paddingLeft","marginLeft","fontFamily","borderTop","minWidth","lineHeight","right","concat","palette","primary","main","InsideOverlay","bottom","RawMathPreview","exports","_React$Component","_classCallCheck2","_inherits2","_createClass2","key","value","componentDidMount","markFractionBaseSuperscripts","componentDidUpdate","prevProps","props","latex","render","_this$props","onFocus","onBlur","createElement","Static","React","Component","PropTypes","string","bool","func","_default"],"sources":["../src/math-preview.jsx"],"sourcesContent":["import React from 'react';\nimport debug from 'debug';\nimport { styled } from '@mui/material/styles';\nimport PropTypes from 'prop-types';\nimport { mq } from '@pie-lib/math-input-mathlive';\nimport { markFractionBaseSuperscripts } from './utils';\n\nconst { commonMqFontStyles, longdivStyles, supsubStyles } = mq.CommonMqStyles;\n\nconst log = debug('@pie-lib:math-toolbar:math-preview');\n\nconst MathPreviewContainer = styled('div')(({ theme, isSelected }) => ({\n display: 'inline-flex',\n alignItems: 'center',\n position: 'relative',\n '& *': commonMqFontStyles,\n ...supsubStyles,\n ...longdivStyles,\n '& > .mq-math-mode': {\n border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',\n },\n '& > .mq-focused': {\n outline: 'none',\n boxShadow: 'none',\n border: 'solid 1px black',\n borderRadius: '0px',\n },\n '& > .mq-math-mode .mq-root-block': {\n paddingTop: '7px !important',\n },\n '& > .mq-math-mode .mq-overarc ': {\n paddingTop: '0.45em !important',\n },\n '& > .mq-math-mode .mq-sqrt-prefix': {\n verticalAlign: 'baseline !important',\n top: '1px !important',\n left: '-0.1em !important',\n },\n '& > .mq-math-mode .mq-denominator': {\n marginTop: '-5px !important',\n padding: '0.5em 0.1em 0.1em !important',\n },\n '& > .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {\n padding: '0 0.1em !important',\n paddingBottom: '0 !important',\n marginBottom: '-2px',\n },\n '& > .mq-math-mode .mq-longdiv .mq-longdiv-inner .mq-empty': {\n paddingTop: '6px !important',\n paddingLeft: '4px !important',\n },\n '& > .mq-math-mode .mq-longdiv .mq-longdiv-inner': {\n marginLeft: '0 !important',\n },\n '& > .mq-math-mode .mq-overarrow': {\n fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',\n },\n '& > .mq-math-mode .mq-paren': {\n verticalAlign: 'top !important',\n padding: '1px 0.1em !important',\n },\n '& > .mq-math-mode .mq-sqrt-stem': {\n borderTop: '0.07em solid',\n marginLeft: '-1.5px',\n marginTop: '-2px !important',\n paddingTop: '5px !important',\n },\n '& .mq-overarrow-inner': {\n paddingTop: '0 !important',\n border: 'none !important',\n },\n '& .mq-editable-field .mq-cursor': {\n marginTop: '-15px !important',\n },\n '& .mq-overarrow.mq-arrow-both': {\n top: '7.5px',\n marginTop: '0px',\n minWidth: '1.23em',\n '& *': {\n lineHeight: '1 !important',\n },\n '&:before': {\n top: '-0.4em',\n left: '-1px',\n },\n '&:after': {\n top: '0px !important',\n position: 'absolute !important',\n right: '-2px',\n },\n '&.mq-empty:after': {\n top: '-0.45em',\n },\n },\n '& .mq-overarrow.mq-arrow-right': {\n '&:before': {\n top: '-0.4em',\n right: '-1px',\n },\n },\n '& .mq-overarrow-inner-right': {\n display: 'none !important',\n },\n '& .mq-overarrow-inner-left': {\n display: 'none !important',\n },\n '& .mq-longdiv-inner': {\n borderTop: '1px solid !important',\n paddingTop: '1.5px !important',\n },\n '& .mq-parallelogram': {\n lineHeight: 0.85,\n },\n '& span[data-prime=\"true\"]': {\n fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',\n },\n ...(isSelected && {\n border: `solid 1px ${theme.palette.primary.main}`,\n }),\n}));\n\nconst InsideOverlay = styled('span')({\n position: 'absolute',\n bottom: 0,\n left: 0,\n right: 0,\n top: 0,\n});\n\nexport class RawMathPreview extends React.Component {\n static propTypes = {\n latex: PropTypes.string,\n isSelected: PropTypes.bool,\n onFocus: PropTypes.func,\n onBlur: PropTypes.func,\n };\n\n componentDidMount() {\n markFractionBaseSuperscripts();\n }\n\n componentDidUpdate(prevProps) {\n // Re-run only if LaTeX changed\n if (this.props.latex !== prevProps.latex) {\n markFractionBaseSuperscripts();\n }\n }\n\n render() {\n const { isSelected, onFocus, onBlur, latex } = this.props;\n log('[render] latex: ', latex);\n return (\n <MathPreviewContainer isSelected={isSelected}>\n {' '}\n <InsideOverlay />\n <mq.Static latex={latex} onFocus={onFocus} onBlur={onBlur} />\n </MathPreviewContainer>\n );\n }\n}\n\nexport default RawMathPreview;\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBA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E;QACxC,IAAAJ,mCAA4B,EAAC,CAAC;MAChC;IACF;EAAC;IAAAH,GAAA;IAAAC,KAAA,EAED,SAAAO,MAAMA,CAAA,EAAG;MACP,IAAAC,WAAA,GAA+C,IAAI,CAACH,KAAK;QAAjDzC,UAAU,GAAA4C,WAAA,CAAV5C,UAAU;QAAE6C,OAAO,GAAAD,WAAA,CAAPC,OAAO;QAAEC,MAAM,GAAAF,WAAA,CAANE,MAAM;QAAEJ,KAAK,GAAAE,WAAA,CAALF,KAAK;MAC1ChD,GAAG,CAAC,kBAAkB,EAAEgD,KAAK,CAAC;MAC9B,oBACE9F,MAAA,YAAAmG,aAAA,CAACnD,oBAAoB;QAACI,UAAU,EAAEA;MAAW,GAC1C,GAAG,eACJpD,MAAA,YAAAmG,aAAA,CAACpB,aAAa,MAAE,CAAC,eACjB/E,MAAA,YAAAmG,aAAA,CAAC7F,kBAAA,CAAAmC,EAAE,CAAC2D,MAAM;QAACN,KAAK,EAAEA,KAAM;QAACG,OAAO,EAAEA,OAAQ;QAACC,MAAM,EAAEA;MAAO,CAAE,CACxC,CAAC;IAE3B;EAAC;AAAA,EA7BiCG,iBAAK,CAACC,SAAS;AAAA,IAAAlE,gBAAA,aAAtC6C,cAAc,eACN;EACjBa,KAAK,EAAES,qBAAS,CAACC,MAAM;EACvBpD,UAAU,EAAEmD,qBAAS,CAACE,IAAI;EAC1BR,OAAO,EAAEM,qBAAS,CAACG,IAAI;EACvBR,MAAM,EAAEK,qBAAS,CAACG;AACpB,CAAC;AAAA,IAAAC,QAAA,GAAAzB,OAAA,cA0BYD,cAAc","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"math-preview.js","names":["_react","_interopRequireDefault","require","_debug","_styles","_propTypes","_mathInputMathlive","_utils","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","ownKeys","r","Object","keys","getOwnPropertySymbols","filter","getOwnPropertyDescriptor","enumerable","push","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","_mq$CommonMqStyles","mq","CommonMqStyles","commonMqFontStyles","longdivStyles","supsubStyles","log","debug","MathPreviewContainer","styled","_ref","theme","isSelected","display","alignItems","position","border","padding","outline","boxShadow","borderRadius","paddingTop","verticalAlign","top","left","marginTop","paddingBottom","marginBottom","paddingLeft","marginLeft","fontFamily","borderTop","minWidth","lineHeight","right","concat","palette","primary","main","InsideOverlay","bottom","RawMathPreview","exports","_React$Component","_classCallCheck2","_inherits2","_createClass2","key","value","componentDidMount","markFractionBaseSuperscripts","componentDidUpdate","prevProps","props","latex","render","_this$props","onFocus","onBlur","createElement","Static","React","Component","PropTypes","string","bool","func","_default"],"sources":["../src/math-preview.jsx"],"sourcesContent":["import React from 'react';\nimport debug from 'debug';\nimport { styled } from '@mui/material/styles';\nimport PropTypes from 'prop-types';\nimport { mq } from '@pie-lib/math-input-mathlive';\nimport { markFractionBaseSuperscripts } from './utils';\n\nconst { commonMqFontStyles, longdivStyles, supsubStyles } = mq.CommonMqStyles;\n\nconst log = debug('@pie-lib:math-toolbar:math-preview');\n\nconst MathPreviewContainer = styled('div')(({ theme, isSelected }) => ({\n display: 'inline-flex',\n alignItems: 'center',\n position: 'relative',\n '& *': commonMqFontStyles,\n ...supsubStyles,\n ...longdivStyles,\n '& > .mq-math-mode': {\n border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',\n },\n '& .ML__latex': {\n border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',\n padding: isSelected ? '0px' : '5px',\n },\n '& > .mq-focused': {\n outline: 'none',\n boxShadow: 'none',\n border: 'solid 1px black',\n borderRadius: '0px',\n },\n '& > .mq-math-mode .mq-root-block': {\n paddingTop: '7px !important',\n },\n '& > .mq-math-mode .mq-overarc ': {\n paddingTop: '0.45em !important',\n },\n '& > .mq-math-mode .mq-sqrt-prefix': {\n verticalAlign: 'baseline !important',\n top: '1px !important',\n left: '-0.1em !important',\n },\n '& > .mq-math-mode .mq-denominator': {\n marginTop: '-5px !important',\n padding: '0.5em 0.1em 0.1em !important',\n },\n '& > .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {\n padding: '0 0.1em !important',\n paddingBottom: '0 !important',\n marginBottom: '-2px',\n },\n '& > .mq-math-mode .mq-longdiv .mq-longdiv-inner .mq-empty': {\n paddingTop: '6px !important',\n paddingLeft: '4px !important',\n },\n '& > .mq-math-mode .mq-longdiv .mq-longdiv-inner': {\n marginLeft: '0 !important',\n },\n '& > .mq-math-mode .mq-overarrow': {\n fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',\n },\n '& > .mq-math-mode .mq-paren': {\n verticalAlign: 'top !important',\n padding: '1px 0.1em !important',\n },\n '& > .mq-math-mode .mq-sqrt-stem': {\n borderTop: '0.07em solid',\n marginLeft: '-1.5px',\n marginTop: '-2px !important',\n paddingTop: '5px !important',\n },\n '& .mq-overarrow-inner': {\n paddingTop: '0 !important',\n border: 'none !important',\n },\n '& .mq-editable-field .mq-cursor': {\n marginTop: '-15px !important',\n },\n '& .mq-overarrow.mq-arrow-both': {\n top: '7.5px',\n marginTop: '0px',\n minWidth: '1.23em',\n '& *': {\n lineHeight: '1 !important',\n },\n '&:before': {\n top: '-0.4em',\n left: '-1px',\n },\n '&:after': {\n top: '0px !important',\n position: 'absolute !important',\n right: '-2px',\n },\n '&.mq-empty:after': {\n top: '-0.45em',\n },\n },\n '& .mq-overarrow.mq-arrow-right': {\n '&:before': {\n top: '-0.4em',\n right: '-1px',\n },\n },\n '& .mq-overarrow-inner-right': {\n display: 'none !important',\n },\n '& .mq-overarrow-inner-left': {\n display: 'none !important',\n },\n '& .mq-longdiv-inner': {\n borderTop: '1px solid !important',\n paddingTop: '1.5px !important',\n },\n '& .mq-parallelogram': {\n lineHeight: 0.85,\n },\n '& span[data-prime=\"true\"]': {\n fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',\n },\n ...(isSelected && {\n border: `solid 1px ${theme.palette.primary.main}`,\n }),\n}));\n\nconst InsideOverlay = styled('span')({\n position: 'absolute',\n bottom: 0,\n left: 0,\n right: 0,\n top: 0,\n});\n\nexport class RawMathPreview extends React.Component {\n static propTypes = {\n latex: PropTypes.string,\n isSelected: PropTypes.bool,\n onFocus: PropTypes.func,\n onBlur: PropTypes.func,\n };\n\n componentDidMount() {\n markFractionBaseSuperscripts();\n }\n\n componentDidUpdate(prevProps) {\n // Re-run only if LaTeX changed\n if (this.props.latex !== prevProps.latex) {\n markFractionBaseSuperscripts();\n }\n }\n\n render() {\n const { isSelected, onFocus, onBlur, latex } = this.props;\n log('[render] latex: ', latex);\n return (\n <MathPreviewContainer isSelected={isSelected}>\n {' '}\n <InsideOverlay />\n <mq.Static latex={latex} onFocus={onFocus} onBlur={onBlur} />\n </MathPreviewContainer>\n );\n }\n}\n\nexport default RawMathPreview;\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAAuD,SAAAM,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,OAAAE,gBAAA,aAAAF,CAAA,OAAAG,2BAAA,aAAAJ,CAAA,EAAAK,yBAAA,KAAAC,OAAA,CAAAC,SAAA,CAAAN,CAAA,EAAAC,CAAA,YAAAC,gBAAA,aAAAH,CAAA,EAAAQ,WAAA,IAAAP,CAAA,CAAAQ,KAAA,CAAAT,CAAA,EAAAE,CAAA;AAAA,SAAAG,0BAAA,cAAAL,CAAA,IAAAU,OAAA,CAAAC,SAAA,CAAAC,OAAA,CAAAC,IAAA,CAAAP,OAAA,CAAAC,SAAA,CAAAG,OAAA,i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GAAG,eACJpD,MAAA,YAAAmG,aAAA,CAACpB,aAAa,MAAE,CAAC,eACjB/E,MAAA,YAAAmG,aAAA,CAAC7F,kBAAA,CAAAmC,EAAE,CAAC2D,MAAM;QAACN,KAAK,EAAEA,KAAM;QAACG,OAAO,EAAEA,OAAQ;QAACC,MAAM,EAAEA;MAAO,CAAE,CACxC,CAAC;IAE3B;EAAC;AAAA,EA7BiCG,iBAAK,CAACC,SAAS;AAAA,IAAAlE,gBAAA,aAAtC6C,cAAc,eACN;EACjBa,KAAK,EAAES,qBAAS,CAACC,MAAM;EACvBpD,UAAU,EAAEmD,qBAAS,CAACE,IAAI;EAC1BR,OAAO,EAAEM,qBAAS,CAACG,IAAI;EACvBR,MAAM,EAAEK,qBAAS,CAACG;AACpB,CAAC;AAAA,IAAAC,QAAA,GAAAzB,OAAA,cA0BYD,cAAc","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "3.1.0-beta.
|
|
6
|
+
"version": "3.1.0-beta.4",
|
|
7
7
|
"description": "Math toolbar for editing math equations",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"math",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@emotion/styled": "^11.14.1",
|
|
22
22
|
"@mui/icons-material": "^7.3.4",
|
|
23
23
|
"@mui/material": "^7.3.4",
|
|
24
|
-
"@pie-lib/math-input-mathlive": "^1.0.
|
|
24
|
+
"@pie-lib/math-input-mathlive": "^1.0.8",
|
|
25
25
|
"@pie-lib/render-ui": "^6.1.0",
|
|
26
26
|
"debug": "^4.1.1",
|
|
27
27
|
"lodash-es": "^4.17.23",
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { EditorAndPad } from '../editor-and-pad';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Covers the call sites that changed when this package moved from
|
|
5
|
+
* @pie-lib/math-input (MathQuill) to @pie-lib/math-input-mathlive.
|
|
6
|
+
*
|
|
7
|
+
* All three were MathQuill-shaped and silently changed meaning:
|
|
8
|
+
* - shouldComponentUpdate read `this.input.mathField.latex()`, which throws now
|
|
9
|
+
* (and the field loads asynchronously, so `this.input` can be null)
|
|
10
|
+
* - the mixed-number workaround poked `__controller.cursor`, a MathQuill
|
|
11
|
+
* internal with no MathLive equivalent
|
|
12
|
+
* - onClick routes keypad presses through the imperative field API
|
|
13
|
+
*/
|
|
14
|
+
describe('EditorAndPad after the MathLive migration', () => {
|
|
15
|
+
const props = (over = {}) => ({ classes: {}, classNames: {}, onChange: jest.fn(), ...over });
|
|
16
|
+
|
|
17
|
+
describe('shouldComponentUpdate', () => {
|
|
18
|
+
it('treats a missing input ref as different, so the first render is not skipped', () => {
|
|
19
|
+
const c = new EditorAndPad(props({ latex: 'x' }));
|
|
20
|
+
|
|
21
|
+
c.input = null;
|
|
22
|
+
|
|
23
|
+
expect(c.shouldComponentUpdate({ latex: 'x' }, {})).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('does not throw when the math engine has not loaded yet', () => {
|
|
27
|
+
const c = new EditorAndPad(props({ latex: 'x' }));
|
|
28
|
+
|
|
29
|
+
// latex() returns '' until MathLive is ready
|
|
30
|
+
c.input = { latex: () => '' };
|
|
31
|
+
|
|
32
|
+
expect(() => c.shouldComponentUpdate({ latex: 'x' }, {})).not.toThrow();
|
|
33
|
+
expect(c.shouldComponentUpdate({ latex: 'x' }, {})).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('skips the update when the field already holds the incoming latex', () => {
|
|
37
|
+
const c = new EditorAndPad(props({ latex: 'x', keypadMode: 'a', noDecimal: false }));
|
|
38
|
+
|
|
39
|
+
c.input = { latex: () => 'x' };
|
|
40
|
+
c.state = { equationEditor: 'geometry' };
|
|
41
|
+
|
|
42
|
+
expect(c.shouldComponentUpdate({ latex: 'x', keypadMode: 'a', noDecimal: false }, c.state)).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('re-renders when the field differs from the incoming latex', () => {
|
|
46
|
+
const c = new EditorAndPad(props({ latex: 'y' }));
|
|
47
|
+
|
|
48
|
+
c.input = { latex: () => 'x' };
|
|
49
|
+
|
|
50
|
+
expect(c.shouldComponentUpdate({ latex: 'y' }, {})).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('uses input.latex(), never input.mathField.latex()', () => {
|
|
54
|
+
const c = new EditorAndPad(props({ latex: 'x' }));
|
|
55
|
+
const latex = jest.fn(() => 'x');
|
|
56
|
+
|
|
57
|
+
// deliberately no `mathField` - the old code would have thrown here
|
|
58
|
+
c.input = { latex };
|
|
59
|
+
c.state = { equationEditor: 'geometry' };
|
|
60
|
+
c.shouldComponentUpdate({ latex: 'x' }, c.state);
|
|
61
|
+
|
|
62
|
+
expect(latex).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('onClick key routing', () => {
|
|
67
|
+
const withInput = (over = {}) => {
|
|
68
|
+
const c = new EditorAndPad(props(over));
|
|
69
|
+
const calls = { write: [], command: [], keystroke: [], clear: 0 };
|
|
70
|
+
|
|
71
|
+
c.input = {
|
|
72
|
+
write: (v) => calls.write.push(v),
|
|
73
|
+
command: (v) => calls.command.push(v),
|
|
74
|
+
keystroke: (v) => calls.keystroke.push(v),
|
|
75
|
+
clear: () => calls.clear++,
|
|
76
|
+
};
|
|
77
|
+
c.updateDisable = () => {};
|
|
78
|
+
|
|
79
|
+
return { c, calls };
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// toNodeData keys this off `value === 'clear'`, not `type`
|
|
83
|
+
it('clear', () => {
|
|
84
|
+
const { c, calls } = withInput();
|
|
85
|
+
|
|
86
|
+
c.onClick({ value: 'clear' });
|
|
87
|
+
expect(calls.clear).toBe(1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('command', () => {
|
|
91
|
+
const { c, calls } = withInput();
|
|
92
|
+
|
|
93
|
+
c.onClick({ type: 'command', value: '\\frac' });
|
|
94
|
+
expect(calls.command).toEqual(['\\frac']);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('cursor keystroke', () => {
|
|
98
|
+
const { c, calls } = withInput();
|
|
99
|
+
|
|
100
|
+
c.onClick({ type: 'cursor', value: 'Left' });
|
|
101
|
+
expect(calls.keystroke).toEqual(['Left']);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('answer block writes the response token', () => {
|
|
105
|
+
const { c, calls } = withInput();
|
|
106
|
+
|
|
107
|
+
c.onClick({ type: 'answer' });
|
|
108
|
+
expect(calls.write).toEqual(['%response%']);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('plain value', () => {
|
|
112
|
+
const { c, calls } = withInput();
|
|
113
|
+
|
|
114
|
+
c.onClick({ value: 'x' });
|
|
115
|
+
expect(calls.write).toEqual(['x']);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('ignores a nullish key', () => {
|
|
119
|
+
const { c, calls } = withInput();
|
|
120
|
+
|
|
121
|
+
expect(() => c.onClick(null)).not.toThrow();
|
|
122
|
+
expect(calls.write).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('onEditorChange', () => {
|
|
127
|
+
const withInput = (over = {}) => {
|
|
128
|
+
const onChange = jest.fn();
|
|
129
|
+
const c = new EditorAndPad(props({ onChange, ...over }));
|
|
130
|
+
const calls = { keystroke: [], clear: 0, write: [] };
|
|
131
|
+
|
|
132
|
+
c.input = {
|
|
133
|
+
keystroke: (v) => calls.keystroke.push(v),
|
|
134
|
+
clear: () => calls.clear++,
|
|
135
|
+
write: (v) => calls.write.push(v),
|
|
136
|
+
};
|
|
137
|
+
c.updateDisable = () => {};
|
|
138
|
+
|
|
139
|
+
return { c, onChange, calls };
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
it('propagates ordinary latex to onChange', () => {
|
|
143
|
+
const { c, onChange } = withInput();
|
|
144
|
+
|
|
145
|
+
c.onEditorChange('\\frac{1}{2}');
|
|
146
|
+
expect(onChange).toHaveBeenCalledWith('\\frac{1}{2}');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('strips decimals when noDecimal is set', () => {
|
|
150
|
+
const { c, onChange, calls } = withInput({ noDecimal: true });
|
|
151
|
+
|
|
152
|
+
c.onEditorChange('1.5');
|
|
153
|
+
|
|
154
|
+
expect(calls.clear).toBe(1);
|
|
155
|
+
expect(calls.write).toEqual(['15']);
|
|
156
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('undoes the empty fraction after a digit with a public delete, not MathQuill internals', () => {
|
|
160
|
+
const { c, onChange, calls } = withInput();
|
|
161
|
+
|
|
162
|
+
// the shape the old __controller hack targeted
|
|
163
|
+
c.onEditorChange('2\\ \\frac{1}{ }');
|
|
164
|
+
|
|
165
|
+
expect(calls.keystroke).toEqual(['Backspace']);
|
|
166
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('does not treat normal fractions as the mixed-number case', () => {
|
|
170
|
+
const { c, onChange, calls } = withInput();
|
|
171
|
+
|
|
172
|
+
c.onEditorChange('\\frac{1}{2}');
|
|
173
|
+
|
|
174
|
+
expect(calls.keystroke).toEqual([]);
|
|
175
|
+
expect(onChange).toHaveBeenCalled();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -2,6 +2,45 @@ import React from 'react';
|
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import MathPreview from '../math-preview';
|
|
4
4
|
|
|
5
|
+
/** Every rule emotion has injected so far, as CSSStyleRule objects. */
|
|
6
|
+
const injectedRules = () =>
|
|
7
|
+
Array.from(document.querySelectorAll('style[data-emotion]'))
|
|
8
|
+
.flatMap((tag) => (tag.sheet ? Array.from(tag.sheet.cssRules) : []))
|
|
9
|
+
.filter((rule) => rule.selectorText);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The `.ML__latex` rule that actually applies to `element`.
|
|
13
|
+
*
|
|
14
|
+
* Matching with `element.matches` rather than string comparison means the
|
|
15
|
+
* assertions cover the selector too: a rule written as `& > .ML__latex` would
|
|
16
|
+
* not match the nested markup MathLive emits, and these tests would fail.
|
|
17
|
+
*/
|
|
18
|
+
const mathLiveRuleFor = (element) =>
|
|
19
|
+
injectedRules().find((rule) => rule.selectorText.includes('.ML__latex') && element.matches(rule.selectorText));
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Stand in for MathLive's `convertLatexToMarkup` output, which is
|
|
23
|
+
* `<span class="ML__latex">...</span>` nested inside `mf.Static`'s holder span.
|
|
24
|
+
* MathLive does not load under jsdom, so the markup is added by hand.
|
|
25
|
+
*/
|
|
26
|
+
const addStaticMarkup = (container, depth = 1) => {
|
|
27
|
+
let parent = container.firstChild;
|
|
28
|
+
|
|
29
|
+
for (let i = 1; i < depth; i += 1) {
|
|
30
|
+
const wrapper = document.createElement('span');
|
|
31
|
+
|
|
32
|
+
parent.appendChild(wrapper);
|
|
33
|
+
parent = wrapper;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const markup = document.createElement('span');
|
|
37
|
+
|
|
38
|
+
markup.className = 'ML__latex';
|
|
39
|
+
parent.appendChild(markup);
|
|
40
|
+
|
|
41
|
+
return markup;
|
|
42
|
+
};
|
|
43
|
+
|
|
5
44
|
describe('MathPreview', () => {
|
|
6
45
|
const defaultProps = {
|
|
7
46
|
latex: 'sqrt(5)',
|
|
@@ -15,4 +54,30 @@ describe('MathPreview', () => {
|
|
|
15
54
|
const { container } = render(<MathPreview {...defaultProps} />);
|
|
16
55
|
expect(container.firstChild).toBeInTheDocument();
|
|
17
56
|
});
|
|
57
|
+
|
|
58
|
+
describe('MathLive static markup', () => {
|
|
59
|
+
it('is outlined and padded when not selected', () => {
|
|
60
|
+
const { container } = render(<MathPreview {...defaultProps} isSelected={false} />);
|
|
61
|
+
const rule = mathLiveRuleFor(addStaticMarkup(container));
|
|
62
|
+
|
|
63
|
+
expect(rule).toBeDefined();
|
|
64
|
+
expect(rule.style.getPropertyValue('border')).toEqual('solid 1px lightgrey');
|
|
65
|
+
expect(rule.style.getPropertyValue('padding')).toEqual('5px');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('drops its outline and padding when selected, so only the container border shows', () => {
|
|
69
|
+
const { container } = render(<MathPreview {...defaultProps} isSelected />);
|
|
70
|
+
const rule = mathLiveRuleFor(addStaticMarkup(container));
|
|
71
|
+
|
|
72
|
+
expect(rule).toBeDefined();
|
|
73
|
+
expect(rule.style.getPropertyValue('border')).toEqual('solid 0px lightgrey');
|
|
74
|
+
expect(rule.style.getPropertyValue('padding')).toEqual('0px');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('is styled at any depth below the container, not just as a direct child', () => {
|
|
78
|
+
const { container } = render(<MathPreview {...defaultProps} isSelected={false} />);
|
|
79
|
+
|
|
80
|
+
expect(mathLiveRuleFor(addStaticMarkup(container, 3))).toBeDefined();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
18
83
|
});
|
package/src/math-preview.jsx
CHANGED
|
@@ -19,6 +19,10 @@ const MathPreviewContainer = styled('div')(({ theme, isSelected }) => ({
|
|
|
19
19
|
'& > .mq-math-mode': {
|
|
20
20
|
border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',
|
|
21
21
|
},
|
|
22
|
+
'& .ML__latex': {
|
|
23
|
+
border: isSelected ? 'solid 0px lightgrey' : 'solid 1px lightgrey',
|
|
24
|
+
padding: isSelected ? '0px' : '5px',
|
|
25
|
+
},
|
|
22
26
|
'& > .mq-focused': {
|
|
23
27
|
outline: 'none',
|
|
24
28
|
boxShadow: 'none',
|