@pie-lib/mask-markup 3.1.4 → 4.0.0-next.37

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