@pie-lib/mask-markup 3.0.4-next.31 → 3.0.4-next.32
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/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/choices/choice.d.ts +24 -0
- package/dist/choices/choice.js +77 -0
- package/dist/choices/index.d.ts +25 -0
- package/dist/choices/index.js +49 -0
- package/dist/componentize.d.ts +12 -0
- package/dist/componentize.js +4 -0
- package/dist/components/blank.d.ts +39 -0
- package/dist/components/blank.js +240 -0
- package/dist/components/correct-input.d.ts +11 -0
- package/dist/components/dropdown.d.ts +37 -0
- package/dist/components/dropdown.js +320 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/constructed-response.d.ts +44 -0
- package/dist/constructed-response.js +55 -0
- package/dist/customizable.d.ts +43 -0
- package/dist/customizable.js +8 -0
- package/dist/drag-in-the-blank.d.ts +37 -0
- package/dist/drag-in-the-blank.js +164 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7 -0
- package/dist/inline-dropdown.d.ts +44 -0
- package/dist/inline-dropdown.js +24 -0
- package/dist/mask.d.ts +30 -0
- package/dist/mask.js +99 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
- package/dist/serialization.d.ts +34 -0
- package/dist/serialization.js +132 -0
- package/dist/with-mask.d.ts +55 -0
- package/dist/with-mask.js +45 -0
- package/package.json +39 -20
- package/CHANGELOG.json +0 -17
- package/CHANGELOG.md +0 -1256
- package/LICENSE.md +0 -5
- package/lib/choices/choice.js +0 -116
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -103
- package/lib/choices/index.js.map +0 -1
- package/lib/componentize.js +0 -21
- package/lib/componentize.js.map +0 -1
- package/lib/components/blank.js +0 -371
- package/lib/components/blank.js.map +0 -1
- package/lib/components/correct-input.js +0 -94
- package/lib/components/correct-input.js.map +0 -1
- package/lib/components/dropdown.js +0 -483
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/input.js +0 -50
- package/lib/components/input.js.map +0 -1
- package/lib/constructed-response.js +0 -101
- package/lib/constructed-response.js.map +0 -1
- package/lib/customizable.js +0 -42
- package/lib/customizable.js.map +0 -1
- package/lib/drag-in-the-blank.js +0 -254
- package/lib/drag-in-the-blank.js.map +0 -1
- package/lib/index.js +0 -55
- package/lib/index.js.map +0 -1
- package/lib/inline-dropdown.js +0 -40
- package/lib/inline-dropdown.js.map +0 -1
- package/lib/mask.js +0 -198
- package/lib/mask.js.map +0 -1
- package/lib/serialization.js +0 -261
- package/lib/serialization.js.map +0 -1
- package/lib/with-mask.js +0 -97
- package/lib/with-mask.js.map +0 -1
- package/src/__tests__/drag-in-the-blank.test.js +0 -111
- package/src/__tests__/index.test.js +0 -38
- package/src/__tests__/mask.test.js +0 -381
- package/src/__tests__/serialization.test.js +0 -54
- package/src/__tests__/utils.js +0 -1
- package/src/__tests__/with-mask.test.js +0 -76
- package/src/choices/__tests__/index.test.js +0 -75
- package/src/choices/choice.jsx +0 -97
- package/src/choices/index.jsx +0 -64
- package/src/componentize.js +0 -13
- package/src/components/__tests__/blank.test.js +0 -199
- package/src/components/__tests__/correct-input.test.js +0 -90
- package/src/components/__tests__/dropdown.test.js +0 -129
- package/src/components/__tests__/input.test.js +0 -102
- package/src/components/blank.jsx +0 -386
- package/src/components/correct-input.jsx +0 -82
- package/src/components/dropdown.jsx +0 -423
- package/src/components/input.jsx +0 -48
- package/src/constructed-response.jsx +0 -87
- package/src/customizable.jsx +0 -34
- package/src/drag-in-the-blank.jsx +0 -241
- package/src/index.js +0 -16
- package/src/inline-dropdown.jsx +0 -29
- package/src/mask.jsx +0 -172
- package/src/serialization.js +0 -260
- package/src/with-mask.jsx +0 -75
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import Button from '@mui/material/Button';
|
|
4
|
-
import InputLabel from '@mui/material/InputLabel';
|
|
5
|
-
import Menu from '@mui/material/Menu';
|
|
6
|
-
import MenuItem from '@mui/material/MenuItem';
|
|
7
|
-
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
|
|
8
|
-
import ArrowDropUpIcon from '@mui/icons-material/ArrowDropUp';
|
|
9
|
-
import Close from '@mui/icons-material/Close';
|
|
10
|
-
import Check from '@mui/icons-material/Check';
|
|
11
|
-
import { styled } from '@mui/material/styles';
|
|
12
|
-
|
|
13
|
-
import { color } from '@pie-lib/render-ui';
|
|
14
|
-
import { renderMath } from '@pie-lib/math-rendering';
|
|
15
|
-
|
|
16
|
-
const StyledButton = styled(Button)(() => ({
|
|
17
|
-
color: color.text(),
|
|
18
|
-
border: `1px solid ${color.borderGray()}`,
|
|
19
|
-
borderRadius: '4px',
|
|
20
|
-
justifyContent: 'space-between',
|
|
21
|
-
backgroundColor: color.background(),
|
|
22
|
-
position: 'relative',
|
|
23
|
-
height: '45px',
|
|
24
|
-
width: 'fit-content',
|
|
25
|
-
margin: '2px',
|
|
26
|
-
textTransform: 'none',
|
|
27
|
-
'& span': {
|
|
28
|
-
paddingRight: '24px',
|
|
29
|
-
},
|
|
30
|
-
'& svg': {
|
|
31
|
-
position: 'absolute',
|
|
32
|
-
right: '4px',
|
|
33
|
-
top: 'calc(50% - 12px)',
|
|
34
|
-
pointerEvents: 'none',
|
|
35
|
-
color: color.text(),
|
|
36
|
-
marginLeft: '5px',
|
|
37
|
-
},
|
|
38
|
-
'&.Mui-focused': {
|
|
39
|
-
outline: `3px solid ${color.tertiary()}`,
|
|
40
|
-
outlineOffset: '2px',
|
|
41
|
-
borderWidth: '3px',
|
|
42
|
-
},
|
|
43
|
-
'&.disabledCorrect': {
|
|
44
|
-
borderWidth: '2px',
|
|
45
|
-
borderColor: color.correct(),
|
|
46
|
-
color: `${color.text()} !important`,
|
|
47
|
-
},
|
|
48
|
-
'&.disabledIncorrect': {
|
|
49
|
-
borderWidth: '2px',
|
|
50
|
-
borderColor: color.incorrectWithIcon(),
|
|
51
|
-
color: `${color.text()} !important`,
|
|
52
|
-
},
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
const StyledMenu = styled(Menu)(() => ({
|
|
56
|
-
backgroundColor: color.background(),
|
|
57
|
-
border: `1px solid ${color.correct()} !important`,
|
|
58
|
-
'&:hover': {
|
|
59
|
-
border: `1px solid ${color.text()} `,
|
|
60
|
-
borderColor: 'initial',
|
|
61
|
-
},
|
|
62
|
-
'&:focus': {
|
|
63
|
-
border: `1px solid ${color.text()}`,
|
|
64
|
-
borderColor: 'initial',
|
|
65
|
-
},
|
|
66
|
-
// remove default padding on the inner list
|
|
67
|
-
'& .MuiList-root': {
|
|
68
|
-
padding: 0,
|
|
69
|
-
},
|
|
70
|
-
}));
|
|
71
|
-
|
|
72
|
-
const StyledMenuItem = styled(MenuItem)(() => ({
|
|
73
|
-
// base text/layout styles (from old JSS - before mui v5 migration)
|
|
74
|
-
height: 24,
|
|
75
|
-
overflow: 'hidden',
|
|
76
|
-
fontSize: '1rem',
|
|
77
|
-
fontWeight: 400,
|
|
78
|
-
fontFamily: 'inherit',
|
|
79
|
-
lineHeight: '1.5em',
|
|
80
|
-
whiteSpace: 'nowrap',
|
|
81
|
-
|
|
82
|
-
// custom styles
|
|
83
|
-
color: color.text(),
|
|
84
|
-
backgroundColor: color.background(),
|
|
85
|
-
'&.Mui-focusVisible': {
|
|
86
|
-
outline: `3px solid ${color.tertiary()}`,
|
|
87
|
-
outlineOffset: '-1px', // keeps it inside the item
|
|
88
|
-
color: color.text(),
|
|
89
|
-
backgroundColor: color.background(),
|
|
90
|
-
},
|
|
91
|
-
'&:hover': {
|
|
92
|
-
color: color.text(),
|
|
93
|
-
backgroundColor: color.dropdownBackground(),
|
|
94
|
-
},
|
|
95
|
-
boxSizing: 'border-box',
|
|
96
|
-
padding: '16px 8px',
|
|
97
|
-
borderRadius: '4px',
|
|
98
|
-
'&.selected': {
|
|
99
|
-
color: `${color.text()} !important`,
|
|
100
|
-
backgroundColor: `${color.background()} !important`,
|
|
101
|
-
'&:hover': {
|
|
102
|
-
color: color.text(),
|
|
103
|
-
backgroundColor: `${color.dropdownBackground()} !important`,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
}));
|
|
107
|
-
|
|
108
|
-
const StyledLabel = styled('span')(() => ({
|
|
109
|
-
fontSize: 'max(1rem, 14px)',
|
|
110
|
-
}));
|
|
111
|
-
|
|
112
|
-
const StyledSelectedIndicator = styled('span')(() => ({
|
|
113
|
-
fontSize: 'max(1rem, 14px)',
|
|
114
|
-
flexShrink: 0,
|
|
115
|
-
paddingLeft: '8px',
|
|
116
|
-
}));
|
|
117
|
-
|
|
118
|
-
const StyledInputLabel = styled(InputLabel)(() => ({
|
|
119
|
-
position: 'absolute',
|
|
120
|
-
left: '-10000px',
|
|
121
|
-
top: 'auto',
|
|
122
|
-
width: '1px',
|
|
123
|
-
height: '1px',
|
|
124
|
-
overflow: 'hidden',
|
|
125
|
-
}));
|
|
126
|
-
|
|
127
|
-
const StyledCorrectnessIcon = styled(Check)(() => ({
|
|
128
|
-
color: `${color.white()} !important`,
|
|
129
|
-
position: 'absolute',
|
|
130
|
-
top: '-8px !important',
|
|
131
|
-
left: '-8px',
|
|
132
|
-
marginLeft: '0 !important',
|
|
133
|
-
borderRadius: '50%',
|
|
134
|
-
fontSize: '16px',
|
|
135
|
-
padding: '2px',
|
|
136
|
-
'&.correct': {
|
|
137
|
-
backgroundColor: color.correct(),
|
|
138
|
-
},
|
|
139
|
-
'&.incorrect': {
|
|
140
|
-
backgroundColor: color.incorrectWithIcon(),
|
|
141
|
-
},
|
|
142
|
-
}));
|
|
143
|
-
|
|
144
|
-
const StyledIncorrectnessIcon = styled(Close)(() => ({
|
|
145
|
-
color: `${color.white()} !important`,
|
|
146
|
-
position: 'absolute',
|
|
147
|
-
top: '-8px !important',
|
|
148
|
-
left: '-8px',
|
|
149
|
-
marginLeft: '0 !important',
|
|
150
|
-
borderRadius: '50%',
|
|
151
|
-
fontSize: '16px',
|
|
152
|
-
padding: '2px',
|
|
153
|
-
'&.correct': {
|
|
154
|
-
backgroundColor: color.correct(),
|
|
155
|
-
},
|
|
156
|
-
'&.incorrect': {
|
|
157
|
-
backgroundColor: color.incorrectWithIcon(),
|
|
158
|
-
},
|
|
159
|
-
}));
|
|
160
|
-
|
|
161
|
-
class Dropdown extends React.Component {
|
|
162
|
-
static propTypes = {
|
|
163
|
-
id: PropTypes.string,
|
|
164
|
-
value: PropTypes.string,
|
|
165
|
-
disabled: PropTypes.bool,
|
|
166
|
-
onChange: PropTypes.func,
|
|
167
|
-
correct: PropTypes.bool,
|
|
168
|
-
choices: PropTypes.arrayOf(PropTypes.shape({ value: PropTypes.string, label: PropTypes.string })),
|
|
169
|
-
showCorrectAnswer: PropTypes.bool,
|
|
170
|
-
singleQuery: PropTypes.bool,
|
|
171
|
-
correctValue: PropTypes.string,
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
constructor(props) {
|
|
175
|
-
super(props);
|
|
176
|
-
|
|
177
|
-
this.state = {
|
|
178
|
-
anchorEl: null,
|
|
179
|
-
highlightedOptionId: null,
|
|
180
|
-
menuWidth: null,
|
|
181
|
-
previewValue: null,
|
|
182
|
-
};
|
|
183
|
-
this.hiddenRef = React.createRef();
|
|
184
|
-
this.buttonRef = React.createRef();
|
|
185
|
-
this.previewRef = React.createRef();
|
|
186
|
-
this.elementRefs = [];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
componentDidMount() {
|
|
190
|
-
// measure hidden menu width once
|
|
191
|
-
if (this.hiddenRef.current && this.state.menuWidth === null) {
|
|
192
|
-
this.setState({ menuWidth: this.hiddenRef.current.clientWidth });
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
componentDidUpdate(prevProps, prevState) {
|
|
197
|
-
const hiddenEl = this.hiddenRef.current;
|
|
198
|
-
|
|
199
|
-
const dropdownJustOpened = !prevState.anchorEl && this.state.anchorEl;
|
|
200
|
-
if (dropdownJustOpened) {
|
|
201
|
-
this.elementRefs.forEach((ref) => {
|
|
202
|
-
if (!ref) return;
|
|
203
|
-
|
|
204
|
-
const containsLatex = ref.querySelector('[data-latex], [data-raw]');
|
|
205
|
-
const hasMathJax = ref.querySelector('mjx-container');
|
|
206
|
-
const mathHandled = ref.querySelector('[data-math-handled="true"]');
|
|
207
|
-
|
|
208
|
-
if (containsLatex && (!mathHandled || !hasMathJax)) {
|
|
209
|
-
renderMath(ref);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (hiddenEl) {
|
|
215
|
-
const newWidth = hiddenEl.clientWidth;
|
|
216
|
-
if (newWidth !== this.state.menuWidth) {
|
|
217
|
-
this.elementRefs.forEach((ref) => {
|
|
218
|
-
if (ref) renderMath(ref);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
renderMath(hiddenEl);
|
|
222
|
-
this.setState({ menuWidth: newWidth });
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
handleClick = (event) => {
|
|
228
|
-
const { id, value, choices } = this.props;
|
|
229
|
-
let highlightedOptionId = null;
|
|
230
|
-
|
|
231
|
-
if (value) {
|
|
232
|
-
const selectedIndex = (choices || []).findIndex((c) => c.value === value);
|
|
233
|
-
if (selectedIndex >= 0) {
|
|
234
|
-
highlightedOptionId = `dropdown-option-${id}-${selectedIndex}`;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
this.setState({ anchorEl: event.currentTarget, highlightedOptionId });
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
handleClose = () => {
|
|
242
|
-
const { value } = this.props;
|
|
243
|
-
this.setState({ anchorEl: null, previewValue: null, highlightedOptionId: null });
|
|
244
|
-
// clear displayed preview if no selection
|
|
245
|
-
if (!value && this.previewRef.current) {
|
|
246
|
-
this.previewRef.current.innerHTML = '';
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
handleHighlight = (index) => {
|
|
251
|
-
const highlightedOptionId = `dropdown-option-${this.props.id}-${index}`;
|
|
252
|
-
|
|
253
|
-
// preview on hover if nothing selected
|
|
254
|
-
const stateUpdate = { highlightedOptionId };
|
|
255
|
-
if (!this.props.value) {
|
|
256
|
-
stateUpdate.previewValue = this.props.choices[index].value;
|
|
257
|
-
}
|
|
258
|
-
this.setState(stateUpdate);
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
handleSelect = (value, index) => {
|
|
262
|
-
this.props.onChange(this.props.id, value);
|
|
263
|
-
this.handleHighlight(index);
|
|
264
|
-
this.handleClose();
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
handleHover = (index) => {
|
|
268
|
-
const selectedValue = this.props.value;
|
|
269
|
-
|
|
270
|
-
if (selectedValue) return;
|
|
271
|
-
|
|
272
|
-
const highlightedOptionId = `dropdown-option-${this.props.id}-${index}`;
|
|
273
|
-
const previewValue = this.state.previewValue;
|
|
274
|
-
|
|
275
|
-
this.setState({ highlightedOptionId, previewValue }, () => {
|
|
276
|
-
// On hover, preview the math-rendered content inside the button if no value is selected.
|
|
277
|
-
const ref = this.elementRefs[index];
|
|
278
|
-
const preview = this.previewRef.current;
|
|
279
|
-
|
|
280
|
-
if (ref && preview) {
|
|
281
|
-
preview.innerHTML = ref.innerHTML;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
getLabel(choices, value) {
|
|
287
|
-
const found = (choices || []).find((choice) => choice.value === value);
|
|
288
|
-
|
|
289
|
-
return found ? found.label.trim() : undefined;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
render() {
|
|
293
|
-
const { id, correct, disabled, value, choices, showCorrectAnswer, singleQuery, correctValue } = this.props;
|
|
294
|
-
const { anchorEl } = this.state;
|
|
295
|
-
const open = Boolean(anchorEl);
|
|
296
|
-
const buttonId = `dropdown-button-${id}`;
|
|
297
|
-
const menuId = `dropdown-menu-${id}`;
|
|
298
|
-
const valueDisplayId = `dropdown-value-${id}`;
|
|
299
|
-
|
|
300
|
-
// Determine the class for disabled state, view mode and evaluate mode
|
|
301
|
-
let disabledClass;
|
|
302
|
-
// Reset elementRefs before each render to avoid stale references
|
|
303
|
-
this.elementRefs = [];
|
|
304
|
-
|
|
305
|
-
if (disabled && correct !== undefined) {
|
|
306
|
-
disabledClass = correct || showCorrectAnswer ? 'disabledCorrect' : 'disabledIncorrect';
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Create distinct, visually hidden labels for each dropdown
|
|
310
|
-
const incrementedId = parseInt(id, 10) + 1;
|
|
311
|
-
const labelId = singleQuery ? 'Query-label' : `Query-label-${incrementedId}`;
|
|
312
|
-
const labelText = singleQuery ? 'Query' : `Query ${incrementedId}`;
|
|
313
|
-
|
|
314
|
-
// Changed from Select to Button for dropdown to enhance accessibility. This modification offers explicit control over aria attributes and focuses management, ensuring the dropdown is compliant with accessibility standards. The use of Button and Menu components allows for better handling of keyboard interactions and provides accessible labels and menus, aligning with WCAG guidelines and improving usability for assistive technology users.
|
|
315
|
-
let correctnessIcon = null;
|
|
316
|
-
if (disabled && correct !== undefined) {
|
|
317
|
-
correctnessIcon =
|
|
318
|
-
correct || showCorrectAnswer ? (
|
|
319
|
-
<StyledCorrectnessIcon className="correct" />
|
|
320
|
-
) : (
|
|
321
|
-
<StyledIncorrectnessIcon className="incorrect" />
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return (
|
|
326
|
-
<>
|
|
327
|
-
<div
|
|
328
|
-
ref={this.hiddenRef}
|
|
329
|
-
style={{ position: 'absolute', visibility: 'hidden', top: 0, left: 0 }}
|
|
330
|
-
tabIndex={-1}
|
|
331
|
-
aria-hidden="true"
|
|
332
|
-
>
|
|
333
|
-
{(choices || []).map((c, index) => (
|
|
334
|
-
<StyledMenuItem key={index} tabIndex={-1} aria-hidden="true">
|
|
335
|
-
<StyledLabel dangerouslySetInnerHTML={{ __html: c.label }} />
|
|
336
|
-
</StyledMenuItem>
|
|
337
|
-
))}
|
|
338
|
-
</div>
|
|
339
|
-
<StyledInputLabel id={labelId} tabIndex={-1} aria-hidden="true">
|
|
340
|
-
{labelText}
|
|
341
|
-
</StyledInputLabel>
|
|
342
|
-
<StyledButton
|
|
343
|
-
ref={this.buttonRef}
|
|
344
|
-
style={{
|
|
345
|
-
...(this.state.menuWidth && { minWidth: `calc(${this.state.menuWidth}px + 8px)` }),
|
|
346
|
-
borderWidth: open ? '2px' : '1px',
|
|
347
|
-
transition: 'border-width 0.2s ease-in-out',
|
|
348
|
-
}}
|
|
349
|
-
aria-controls={open ? menuId : undefined}
|
|
350
|
-
aria-haspopup="listbox"
|
|
351
|
-
aria-expanded={open ? 'true' : undefined}
|
|
352
|
-
aria-activedescendant={this.state.highlightedOptionId}
|
|
353
|
-
onClick={this.handleClick}
|
|
354
|
-
className={disabledClass}
|
|
355
|
-
disabled={disabled}
|
|
356
|
-
id={buttonId}
|
|
357
|
-
role="combobox"
|
|
358
|
-
aria-label={`Select an option for ${labelText}`}
|
|
359
|
-
aria-labelledby={valueDisplayId}
|
|
360
|
-
>
|
|
361
|
-
{correctnessIcon}
|
|
362
|
-
<StyledLabel
|
|
363
|
-
id={valueDisplayId}
|
|
364
|
-
ref={this.previewRef}
|
|
365
|
-
dangerouslySetInnerHTML={{
|
|
366
|
-
__html: correctValue
|
|
367
|
-
? correctValue
|
|
368
|
-
: open && this.state.previewValue
|
|
369
|
-
? this.getLabel(choices, this.state.previewValue)
|
|
370
|
-
: this.getLabel(choices, value) || '',
|
|
371
|
-
}}
|
|
372
|
-
/>
|
|
373
|
-
{open ? <ArrowDropUpIcon /> : <ArrowDropDownIcon />}
|
|
374
|
-
</StyledButton>
|
|
375
|
-
<StyledMenu
|
|
376
|
-
id={menuId}
|
|
377
|
-
anchorEl={anchorEl}
|
|
378
|
-
keepMounted
|
|
379
|
-
open={open}
|
|
380
|
-
onClose={this.handleClose}
|
|
381
|
-
getContentAnchorEl={null}
|
|
382
|
-
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
|
|
383
|
-
transformOrigin={{ vertical: 'top', horizontal: 'left' }}
|
|
384
|
-
transitionDuration={{ enter: 225, exit: 195 }}
|
|
385
|
-
slotProps={{
|
|
386
|
-
paper: this.state.menuWidth ? { style: { minWidth: this.state.menuWidth, padding: '4px' } } : undefined,
|
|
387
|
-
list: {
|
|
388
|
-
'aria-labelledby': buttonId,
|
|
389
|
-
role: 'listbox',
|
|
390
|
-
disablePadding: true,
|
|
391
|
-
},
|
|
392
|
-
}}
|
|
393
|
-
>
|
|
394
|
-
{(choices || []).map((c, index) => {
|
|
395
|
-
const optionId = `dropdown-option-${id}-${index}`;
|
|
396
|
-
|
|
397
|
-
return (
|
|
398
|
-
<StyledMenuItem
|
|
399
|
-
id={optionId}
|
|
400
|
-
className={c.value === value ? 'selected' : ''}
|
|
401
|
-
selected={c.value === value}
|
|
402
|
-
key={`${c.label}-${index}`}
|
|
403
|
-
value={c.value}
|
|
404
|
-
onClick={() => this.handleSelect(c.value, index)}
|
|
405
|
-
role="option"
|
|
406
|
-
aria-selected={this.state.highlightedOptionId === optionId ? 'true' : undefined}
|
|
407
|
-
onMouseOver={() => this.handleHover(index)}
|
|
408
|
-
>
|
|
409
|
-
<StyledLabel
|
|
410
|
-
ref={(ref) => (this.elementRefs[index] = ref)}
|
|
411
|
-
dangerouslySetInnerHTML={{ __html: c.label }}
|
|
412
|
-
/>
|
|
413
|
-
<StyledSelectedIndicator dangerouslySetInnerHTML={{ __html: c.value === value ? ' ✓' : '' }} />
|
|
414
|
-
</StyledMenuItem>
|
|
415
|
-
);
|
|
416
|
-
})}
|
|
417
|
-
</StyledMenu>
|
|
418
|
-
</>
|
|
419
|
-
);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
export default Dropdown;
|
package/src/components/input.jsx
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import CorrectInput from './correct-input';
|
|
4
|
-
|
|
5
|
-
const Input = ({
|
|
6
|
-
disabled,
|
|
7
|
-
correct,
|
|
8
|
-
charactersLimit,
|
|
9
|
-
id,
|
|
10
|
-
isConstructedResponse,
|
|
11
|
-
value,
|
|
12
|
-
onChange,
|
|
13
|
-
showCorrectAnswer,
|
|
14
|
-
spellCheck,
|
|
15
|
-
width,
|
|
16
|
-
}) => {
|
|
17
|
-
return (
|
|
18
|
-
<CorrectInput
|
|
19
|
-
disabled={disabled}
|
|
20
|
-
correct={showCorrectAnswer || correct}
|
|
21
|
-
charactersLimit={charactersLimit}
|
|
22
|
-
variant="outlined"
|
|
23
|
-
value={value}
|
|
24
|
-
isConstructedResponse={isConstructedResponse}
|
|
25
|
-
spellCheck={spellCheck}
|
|
26
|
-
isBox={true}
|
|
27
|
-
width={width}
|
|
28
|
-
onChange={(e) => {
|
|
29
|
-
onChange(id, e.target.value);
|
|
30
|
-
}}
|
|
31
|
-
/>
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
Input.propTypes = {
|
|
36
|
-
id: PropTypes.string,
|
|
37
|
-
value: PropTypes.string,
|
|
38
|
-
onChange: PropTypes.func,
|
|
39
|
-
disabled: PropTypes.bool,
|
|
40
|
-
spellCheck: PropTypes.bool,
|
|
41
|
-
correct: PropTypes.bool,
|
|
42
|
-
showCorrectAnswer: PropTypes.bool,
|
|
43
|
-
charactersLimit: PropTypes.number,
|
|
44
|
-
width: PropTypes.number,
|
|
45
|
-
isConstructedResponse: PropTypes.bool,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export default Input;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { styled } from '@mui/material/styles';
|
|
3
|
-
import classnames from 'classnames';
|
|
4
|
-
|
|
5
|
-
import { color } from '@pie-lib/render-ui';
|
|
6
|
-
import { withMask } from './with-mask';
|
|
7
|
-
//import EditableHtml from '@pie-lib/editable-html-tip-tap';
|
|
8
|
-
|
|
9
|
-
let EditableHtml;
|
|
10
|
-
let StyledEditableHtml;
|
|
11
|
-
|
|
12
|
-
// - mathquill error window not defined
|
|
13
|
-
if (typeof window !== 'undefined') {
|
|
14
|
-
EditableHtml = require('@pie-lib/editable-html-tip-tap')['default'];
|
|
15
|
-
StyledEditableHtml = styled(EditableHtml)(() => ({
|
|
16
|
-
display: 'inline-block',
|
|
17
|
-
verticalAlign: 'middle',
|
|
18
|
-
margin: '4px',
|
|
19
|
-
borderRadius: '4px',
|
|
20
|
-
border: `1px solid ${color.black()}`,
|
|
21
|
-
'&.correct': {
|
|
22
|
-
border: `1px solid ${color.correct()}`,
|
|
23
|
-
},
|
|
24
|
-
'&.incorrect': {
|
|
25
|
-
border: `1px solid ${color.incorrect()}`,
|
|
26
|
-
},
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const MaskedInput = (props) => (node, data) => {
|
|
31
|
-
const { adjustedLimit, disabled, feedback, showCorrectAnswer, maxLength, spellCheck, pluginProps, onChange } = props;
|
|
32
|
-
const dataset = node.data?.dataset || {};
|
|
33
|
-
|
|
34
|
-
if (dataset.component === 'input') {
|
|
35
|
-
const correctAnswer = ((props.choices && dataset && props.choices[dataset.id]) || [])[0];
|
|
36
|
-
const finalValue = showCorrectAnswer ? correctAnswer && correctAnswer.label : data[dataset.id] || '';
|
|
37
|
-
const width = maxLength && maxLength[dataset.id];
|
|
38
|
-
const feedbackStatus = feedback && feedback[dataset.id];
|
|
39
|
-
const isCorrect = showCorrectAnswer || feedbackStatus === 'correct';
|
|
40
|
-
const isIncorrect = !showCorrectAnswer && feedbackStatus === 'incorrect';
|
|
41
|
-
|
|
42
|
-
const handleInputChange = (newValue) => {
|
|
43
|
-
const updatedValue = {
|
|
44
|
-
...data,
|
|
45
|
-
[dataset.id]: newValue,
|
|
46
|
-
};
|
|
47
|
-
onChange(updatedValue);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const handleKeyDown = (event) => {
|
|
51
|
-
// the keyCode value for the Enter/Return key is 13
|
|
52
|
-
if (event.key === 'Enter' || event.keyCode === 13) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<StyledEditableHtml
|
|
59
|
-
id={dataset.id}
|
|
60
|
-
key={`${node.type}-input-${dataset.id}`}
|
|
61
|
-
disabled={showCorrectAnswer || disabled}
|
|
62
|
-
disableUnderline
|
|
63
|
-
onChange={handleInputChange}
|
|
64
|
-
markup={finalValue || ''}
|
|
65
|
-
charactersLimit={adjustedLimit ? width : 25}
|
|
66
|
-
activePlugins={['languageCharacters']}
|
|
67
|
-
pluginProps={pluginProps}
|
|
68
|
-
languageCharactersProps={[{ language: 'spanish' }]}
|
|
69
|
-
spellCheck={spellCheck}
|
|
70
|
-
adjustWidthForLimit
|
|
71
|
-
onKeyDown={handleKeyDown}
|
|
72
|
-
autoWidthToolbar
|
|
73
|
-
toolbarOpts={{
|
|
74
|
-
minWidth: 'auto',
|
|
75
|
-
noBorder: true,
|
|
76
|
-
isHidden: !!pluginProps?.characters?.disabled,
|
|
77
|
-
}}
|
|
78
|
-
className={classnames({
|
|
79
|
-
correct: isCorrect,
|
|
80
|
-
incorrect: isIncorrect,
|
|
81
|
-
})}
|
|
82
|
-
/>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export default withMask('input', MaskedInput);
|
package/src/customizable.jsx
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// import Input from './components/input';
|
|
2
|
-
import { withMask } from './with-mask';
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line react/display-name
|
|
5
|
-
export default withMask('input', (props) => (node, data, onChange) => {
|
|
6
|
-
const dataset = node.data ? node.data.dataset || {} : {};
|
|
7
|
-
if (dataset.component === 'input') {
|
|
8
|
-
// eslint-disable-next-line react/prop-types
|
|
9
|
-
// const { adjustedLimit, disabled, feedback, showCorrectAnswer, maxLength, spellCheck } = props;
|
|
10
|
-
|
|
11
|
-
// the first answer is the correct one
|
|
12
|
-
// eslint-disable-next-line react/prop-types
|
|
13
|
-
// const correctAnswer = ((props.choices && dataset && props.choices[dataset.id]) || [])[0];
|
|
14
|
-
// const finalValue = showCorrectAnswer ? correctAnswer && correctAnswer.label : data[dataset.id] || '';
|
|
15
|
-
// const width = maxLength && maxLength[dataset.id];
|
|
16
|
-
|
|
17
|
-
return props.customMarkMarkupComponent(dataset.id);
|
|
18
|
-
// return (
|
|
19
|
-
// <Input
|
|
20
|
-
// key={`${node.type}-input-${dataset.id}`}
|
|
21
|
-
// correct={feedback && feedback[dataset.id] && feedback[dataset.id] === 'correct'}
|
|
22
|
-
// disabled={showCorrectAnswer || disabled}
|
|
23
|
-
// value={finalValue}
|
|
24
|
-
// id={dataset.id}
|
|
25
|
-
// onChange={onChange}
|
|
26
|
-
// showCorrectAnswer={showCorrectAnswer}
|
|
27
|
-
// width={width}
|
|
28
|
-
// charactersLimit={adjustedLimit ? width : 25}
|
|
29
|
-
// isConstructedResponse={true}
|
|
30
|
-
// spellCheck={spellCheck}
|
|
31
|
-
// />
|
|
32
|
-
// );
|
|
33
|
-
}
|
|
34
|
-
});
|