@pie-lib/mask-markup 3.0.12 → 3.1.0-beta
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/CHANGELOG.md +0 -48
- package/lib/__tests__/drag-in-the-blank.test.js +129 -0
- package/lib/__tests__/drag-in-the-blank.test.js.map +1 -0
- package/lib/__tests__/index.test.js +39 -0
- package/lib/__tests__/index.test.js.map +1 -0
- package/lib/__tests__/mask.test.js +344 -0
- package/lib/__tests__/mask.test.js.map +1 -0
- package/lib/__tests__/serialization.test.js +44 -0
- package/lib/__tests__/serialization.test.js.map +1 -0
- package/lib/__tests__/utils.js +14 -0
- package/lib/__tests__/utils.js.map +1 -0
- package/lib/__tests__/with-mask.test.js +110 -0
- package/lib/__tests__/with-mask.test.js.map +1 -0
- package/lib/choices/__tests__/index.test.js +139 -0
- package/lib/choices/__tests__/index.test.js.map +1 -0
- package/lib/choices/choice.js +3 -0
- package/lib/choices/choice.js.map +1 -1
- package/lib/components/__tests__/blank.test.js +293 -0
- package/lib/components/__tests__/blank.test.js.map +1 -0
- package/lib/components/__tests__/correct-input.test.js +132 -0
- package/lib/components/__tests__/correct-input.test.js.map +1 -0
- package/lib/components/__tests__/dropdown.test.js +202 -0
- package/lib/components/__tests__/dropdown.test.js.map +1 -0
- package/lib/components/__tests__/input.test.js +129 -0
- package/lib/components/__tests__/input.test.js.map +1 -0
- package/lib/components/blank.js +14 -3
- package/lib/components/blank.js.map +1 -1
- package/package.json +6 -6
- package/src/choices/__tests__/index.test.js +34 -0
- package/src/choices/choice.jsx +5 -2
- package/src/components/__tests__/blank.test.js +33 -0
- package/src/components/blank.jsx +20 -4
- package/LICENSE.md +0 -5
|
@@ -4,6 +4,21 @@ import Choice from '../choice';
|
|
|
4
4
|
import { choice } from '../../__tests__/utils';
|
|
5
5
|
import Choices from '../index';
|
|
6
6
|
|
|
7
|
+
// Collect the CSS rules emotion/MUI injected into the document (jsdom uses insertRule).
|
|
8
|
+
const collectEmotionRules = () => {
|
|
9
|
+
const rules = [];
|
|
10
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
11
|
+
try {
|
|
12
|
+
for (const rule of Array.from(sheet.cssRules)) {
|
|
13
|
+
rules.push(rule.cssText);
|
|
14
|
+
}
|
|
15
|
+
} catch (e) {
|
|
16
|
+
/* inaccessible stylesheet */
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return rules;
|
|
20
|
+
};
|
|
21
|
+
|
|
7
22
|
// Mock @dnd-kit hooks to avoid DndContext requirement
|
|
8
23
|
jest.mock('@dnd-kit/core', () => ({
|
|
9
24
|
useDraggable: jest.fn(() => ({
|
|
@@ -71,5 +86,24 @@ describe('index', () => {
|
|
|
71
86
|
expect(container.firstChild).toBeInTheDocument();
|
|
72
87
|
});
|
|
73
88
|
});
|
|
89
|
+
|
|
90
|
+
describe('fraction math styling', () => {
|
|
91
|
+
it('enlarges numerator/denominator digits adjacent to a fraction to 120%', () => {
|
|
92
|
+
render(<Choice {...defaultProps} />);
|
|
93
|
+
// The new rule targets mjx-mn digits that sit next to an mjx-mfrac.
|
|
94
|
+
const rule = collectEmotionRules().find((r) => r.includes('mjx-mn') && r.includes('mjx-mfrac'));
|
|
95
|
+
expect(rule).toBeDefined();
|
|
96
|
+
expect(rule).toMatch(/mjx-mn:has\(~\s*mjx-mfrac\)/);
|
|
97
|
+
expect(rule).toMatch(/mjx-mfrac\s*~\s*mjx-mn/);
|
|
98
|
+
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('keeps the existing mjx-frac 120% rule', () => {
|
|
102
|
+
render(<Choice {...defaultProps} />);
|
|
103
|
+
const rule = collectEmotionRules().find((r) => /(^|[^-])mjx-frac/.test(r) && !r.includes('mjx-mfrac'));
|
|
104
|
+
expect(rule).toBeDefined();
|
|
105
|
+
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
74
108
|
});
|
|
75
109
|
});
|
package/src/choices/choice.jsx
CHANGED
|
@@ -50,6 +50,9 @@ const StyledChipLabel = styled('span')(() => ({
|
|
|
50
50
|
'& mjx-frac': {
|
|
51
51
|
fontSize: '120% !important',
|
|
52
52
|
},
|
|
53
|
+
'& mjx-mn:has(~ mjx-mfrac), mjx-mfrac ~ mjx-mn': {
|
|
54
|
+
fontSize: '120% !important',
|
|
55
|
+
},
|
|
53
56
|
}));
|
|
54
57
|
|
|
55
58
|
export default function Choice({ choice, disabled, instanceId }) {
|
|
@@ -71,8 +74,8 @@ export default function Choice({ choice, disabled, instanceId }) {
|
|
|
71
74
|
style={
|
|
72
75
|
isDragging
|
|
73
76
|
? {
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
width: rootRef.current?.offsetWidth || 90, // min-width of chip is 90px, so if we don't have the width, we can use 90px as a fallback
|
|
78
|
+
height: rootRef.current?.offsetHeight || 32, // min-height of chip is 32px, so if we don't have the height, we can use 32px as a fallback
|
|
76
79
|
}
|
|
77
80
|
: {}
|
|
78
81
|
}
|
|
@@ -30,6 +30,21 @@ jest.mock('@pie-lib/math-rendering', () => ({
|
|
|
30
30
|
renderMath: jest.fn(),
|
|
31
31
|
}));
|
|
32
32
|
|
|
33
|
+
// Collect the CSS rules emotion/MUI injected into the document (jsdom uses insertRule).
|
|
34
|
+
const collectEmotionRules = () => {
|
|
35
|
+
const rules = [];
|
|
36
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
37
|
+
try {
|
|
38
|
+
for (const rule of Array.from(sheet.cssRules)) {
|
|
39
|
+
rules.push(rule.cssText);
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {
|
|
42
|
+
/* inaccessible stylesheet */
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return rules;
|
|
46
|
+
};
|
|
47
|
+
|
|
33
48
|
describe('Blank', () => {
|
|
34
49
|
const { renderMath } = require('@pie-lib/math-rendering');
|
|
35
50
|
const onChange = jest.fn();
|
|
@@ -184,6 +199,24 @@ describe('Blank', () => {
|
|
|
184
199
|
});
|
|
185
200
|
});
|
|
186
201
|
|
|
202
|
+
describe('fraction math styling', () => {
|
|
203
|
+
it('enlarges numerator/denominator digits adjacent to a fraction to 120%', () => {
|
|
204
|
+
render(<Blank {...defaultProps} />);
|
|
205
|
+
const rule = collectEmotionRules().find((r) => r.includes('mjx-mn') && r.includes('mjx-mfrac'));
|
|
206
|
+
expect(rule).toBeDefined();
|
|
207
|
+
expect(rule).toMatch(/mjx-mn:has\(~\s*mjx-mfrac\)/);
|
|
208
|
+
expect(rule).toMatch(/mjx-mfrac\s*~\s*mjx-mn/);
|
|
209
|
+
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('keeps the existing mjx-frac 120% rule', () => {
|
|
213
|
+
render(<Blank {...defaultProps} />);
|
|
214
|
+
const rule = collectEmotionRules().find((r) => /(^|[^-])mjx-frac/.test(r) && !r.includes('mjx-mfrac'));
|
|
215
|
+
expect(rule).toBeDefined();
|
|
216
|
+
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
187
220
|
describe('drag and drop', () => {
|
|
188
221
|
it('accepts drag item when not disabled', () => {
|
|
189
222
|
render(<Blank {...defaultProps} isOver={true} dragItem={{ choice: { value: 'Dog' } }} />);
|
package/src/components/blank.jsx
CHANGED
|
@@ -76,6 +76,9 @@ const StyledChipLabel = styled('span')(() => ({
|
|
|
76
76
|
'& mjx-frac': {
|
|
77
77
|
fontSize: '120% !important',
|
|
78
78
|
},
|
|
79
|
+
'& mjx-mn:has(~ mjx-mfrac), mjx-mfrac ~ mjx-mn': {
|
|
80
|
+
fontSize: '120% !important',
|
|
81
|
+
},
|
|
79
82
|
'&.over': {
|
|
80
83
|
whiteSpace: 'nowrap',
|
|
81
84
|
overflow: 'hidden',
|
|
@@ -125,11 +128,25 @@ function BlankContent({
|
|
|
125
128
|
};
|
|
126
129
|
|
|
127
130
|
const getMeasureNode = () => {
|
|
128
|
-
if (!spanRef.current)
|
|
131
|
+
if (!spanRef.current) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
129
135
|
const mjx = spanRef.current.querySelector('mjx-container');
|
|
130
|
-
|
|
136
|
+
|
|
137
|
+
if (mjx && spanRef.current.parentElement) {
|
|
138
|
+
return spanRef.current.parentElement;
|
|
139
|
+
}
|
|
140
|
+
|
|
131
141
|
const img = spanRef.current.querySelector('img');
|
|
132
|
-
|
|
142
|
+
|
|
143
|
+
if (img) {
|
|
144
|
+
// If there's text alongside the image, measure the full span to capture both dimensions
|
|
145
|
+
const hasTextContent = spanRef.current.textContent.trim().length > 0;
|
|
146
|
+
|
|
147
|
+
return hasTextContent ? spanRef.current : img;
|
|
148
|
+
}
|
|
149
|
+
|
|
133
150
|
return spanRef.current;
|
|
134
151
|
};
|
|
135
152
|
|
|
@@ -166,7 +183,6 @@ function BlankContent({
|
|
|
166
183
|
const adjustedWidth = widthWithPadding <= responseAreaWidth ? responseAreaWidth : widthWithPadding;
|
|
167
184
|
const adjustedHeight = heightWithPadding <= responseAreaHeight ? responseAreaHeight : heightWithPadding;
|
|
168
185
|
|
|
169
|
-
|
|
170
186
|
setDimensions((prevState) => ({
|
|
171
187
|
width: adjustedWidth > responseAreaWidth ? adjustedWidth : prevState.width,
|
|
172
188
|
height: adjustedHeight > responseAreaHeight ? adjustedHeight : prevState.height,
|
package/LICENSE.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
Copyright 2019 CoreSpring Inc
|
|
2
|
-
|
|
3
|
-
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
-
|
|
5
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|