@pie-lib/mask-markup 3.0.4-next.3 → 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.
Files changed (107) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +4 -0
  2. package/dist/choices/choice.d.ts +24 -0
  3. package/dist/choices/choice.js +77 -0
  4. package/dist/choices/index.d.ts +25 -0
  5. package/dist/choices/index.js +49 -0
  6. package/dist/componentize.d.ts +12 -0
  7. package/dist/componentize.js +4 -0
  8. package/dist/components/blank.d.ts +39 -0
  9. package/dist/components/blank.js +240 -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 +320 -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 +55 -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 +37 -0
  19. package/dist/drag-in-the-blank.js +164 -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/mask.d.ts +30 -0
  25. package/dist/mask.js +99 -0
  26. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  27. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
  28. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
  29. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
  30. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
  31. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
  32. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
  33. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
  34. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
  35. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
  36. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
  37. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
  38. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
  39. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
  40. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
  41. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
  42. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
  43. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
  44. package/dist/serialization.d.ts +34 -0
  45. package/dist/serialization.js +132 -0
  46. package/dist/with-mask.d.ts +55 -0
  47. package/dist/with-mask.js +45 -0
  48. package/package.json +39 -20
  49. package/CHANGELOG.json +0 -17
  50. package/CHANGELOG.md +0 -1256
  51. package/LICENSE.md +0 -5
  52. package/lib/choices/choice.js +0 -116
  53. package/lib/choices/choice.js.map +0 -1
  54. package/lib/choices/index.js +0 -103
  55. package/lib/choices/index.js.map +0 -1
  56. package/lib/componentize.js +0 -21
  57. package/lib/componentize.js.map +0 -1
  58. package/lib/components/blank.js +0 -371
  59. package/lib/components/blank.js.map +0 -1
  60. package/lib/components/correct-input.js +0 -94
  61. package/lib/components/correct-input.js.map +0 -1
  62. package/lib/components/dropdown.js +0 -468
  63. package/lib/components/dropdown.js.map +0 -1
  64. package/lib/components/input.js +0 -50
  65. package/lib/components/input.js.map +0 -1
  66. package/lib/constructed-response.js +0 -101
  67. package/lib/constructed-response.js.map +0 -1
  68. package/lib/customizable.js +0 -42
  69. package/lib/customizable.js.map +0 -1
  70. package/lib/drag-in-the-blank.js +0 -254
  71. package/lib/drag-in-the-blank.js.map +0 -1
  72. package/lib/index.js +0 -55
  73. package/lib/index.js.map +0 -1
  74. package/lib/inline-dropdown.js +0 -40
  75. package/lib/inline-dropdown.js.map +0 -1
  76. package/lib/mask.js +0 -198
  77. package/lib/mask.js.map +0 -1
  78. package/lib/serialization.js +0 -261
  79. package/lib/serialization.js.map +0 -1
  80. package/lib/with-mask.js +0 -97
  81. package/lib/with-mask.js.map +0 -1
  82. package/src/__tests__/drag-in-the-blank.test.js +0 -111
  83. package/src/__tests__/index.test.js +0 -38
  84. package/src/__tests__/mask.test.js +0 -381
  85. package/src/__tests__/serialization.test.js +0 -54
  86. package/src/__tests__/utils.js +0 -1
  87. package/src/__tests__/with-mask.test.js +0 -76
  88. package/src/choices/__tests__/index.test.js +0 -75
  89. package/src/choices/choice.jsx +0 -97
  90. package/src/choices/index.jsx +0 -64
  91. package/src/componentize.js +0 -13
  92. package/src/components/__tests__/blank.test.js +0 -169
  93. package/src/components/__tests__/correct-input.test.js +0 -90
  94. package/src/components/__tests__/dropdown.test.js +0 -93
  95. package/src/components/__tests__/input.test.js +0 -102
  96. package/src/components/blank.jsx +0 -386
  97. package/src/components/correct-input.jsx +0 -82
  98. package/src/components/dropdown.jsx +0 -410
  99. package/src/components/input.jsx +0 -48
  100. package/src/constructed-response.jsx +0 -87
  101. package/src/customizable.jsx +0 -34
  102. package/src/drag-in-the-blank.jsx +0 -241
  103. package/src/index.js +0 -16
  104. package/src/inline-dropdown.jsx +0 -29
  105. package/src/mask.jsx +0 -172
  106. package/src/serialization.js +0 -260
  107. package/src/with-mask.jsx +0 -75
@@ -1,410 +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) => this.setState({ anchorEl: event.currentTarget });
228
-
229
- handleClose = () => {
230
- const { value } = this.props;
231
- this.setState({ anchorEl: null, previewValue: null, highlightedOptionId: null });
232
- // clear displayed preview if no selection
233
- if (!value && this.previewRef.current) {
234
- this.previewRef.current.innerHTML = '';
235
- }
236
- };
237
-
238
- handleHighlight = (index) => {
239
- const highlightedOptionId = `dropdown-option-${this.props.id}-${index}`;
240
-
241
- // preview on hover if nothing selected
242
- const stateUpdate = { highlightedOptionId };
243
- if (!this.props.value) {
244
- stateUpdate.previewValue = this.props.choices[index].value;
245
- }
246
- this.setState(stateUpdate);
247
- };
248
-
249
- handleSelect = (value, index) => {
250
- this.props.onChange(this.props.id, value);
251
- this.handleHighlight(index);
252
- this.handleClose();
253
- };
254
-
255
- handleHover = (index) => {
256
- const selectedValue = this.props.value;
257
-
258
- if (selectedValue) return;
259
-
260
- const highlightedOptionId = `dropdown-option-${this.props.id}-${index}`;
261
- const previewValue = this.state.previewValue;
262
-
263
- this.setState({ highlightedOptionId, previewValue }, () => {
264
- // On hover, preview the math-rendered content inside the button if no value is selected.
265
- const ref = this.elementRefs[index];
266
- const preview = this.previewRef.current;
267
-
268
- if (ref && preview) {
269
- preview.innerHTML = ref.innerHTML;
270
- }
271
- });
272
- };
273
-
274
- getLabel(choices, value) {
275
- const found = (choices || []).find((choice) => choice.value === value);
276
-
277
- return found ? found.label.trim() : undefined;
278
- }
279
-
280
- render() {
281
- const { id, correct, disabled, value, choices, showCorrectAnswer, singleQuery, correctValue } = this.props;
282
- const { anchorEl } = this.state;
283
- const open = Boolean(anchorEl);
284
- const buttonId = `dropdown-button-${id}`;
285
- const menuId = `dropdown-menu-${id}`;
286
- const valueDisplayId = `dropdown-value-${id}`;
287
-
288
- // Determine the class for disabled state, view mode and evaluate mode
289
- let disabledClass;
290
- // Reset elementRefs before each render to avoid stale references
291
- this.elementRefs = [];
292
-
293
- if (disabled && correct !== undefined) {
294
- disabledClass = correct || showCorrectAnswer ? 'disabledCorrect' : 'disabledIncorrect';
295
- }
296
-
297
- // Create distinct, visually hidden labels for each dropdown
298
- const incrementedId = parseInt(id, 10) + 1;
299
- const labelId = singleQuery ? 'Query-label' : `Query-label-${incrementedId}`;
300
- const labelText = singleQuery ? 'Query' : `Query ${incrementedId}`;
301
-
302
- // 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.
303
- let correctnessIcon = null;
304
- if (disabled && correct !== undefined) {
305
- correctnessIcon =
306
- correct || showCorrectAnswer ? (
307
- <StyledCorrectnessIcon className="correct" />
308
- ) : (
309
- <StyledIncorrectnessIcon className="incorrect" />
310
- );
311
- }
312
-
313
- return (
314
- <>
315
- <div
316
- ref={this.hiddenRef}
317
- style={{ position: 'absolute', visibility: 'hidden', top: 0, left: 0 }}
318
- tabIndex={-1}
319
- aria-hidden="true"
320
- >
321
- {(choices || []).map((c, index) => (
322
- <StyledMenuItem key={index} tabIndex={-1} aria-hidden="true">
323
- <StyledLabel dangerouslySetInnerHTML={{ __html: c.label }} />
324
- </StyledMenuItem>
325
- ))}
326
- </div>
327
- <StyledInputLabel id={labelId} tabIndex={-1} aria-hidden="true">
328
- {labelText}
329
- </StyledInputLabel>
330
- <StyledButton
331
- ref={this.buttonRef}
332
- style={{
333
- ...(this.state.menuWidth && { minWidth: `calc(${this.state.menuWidth}px + 8px)` }),
334
- borderWidth: open ? '2px' : '1px',
335
- transition: 'border-width 0.2s ease-in-out',
336
- }}
337
- aria-controls={open ? menuId : undefined}
338
- aria-haspopup="listbox"
339
- aria-expanded={open ? 'true' : undefined}
340
- aria-activedescendant={this.state.highlightedOptionId}
341
- onClick={this.handleClick}
342
- className={disabledClass}
343
- disabled={disabled}
344
- id={buttonId}
345
- role="combobox"
346
- aria-label={`Select an option for ${labelText}`}
347
- aria-labelledby={valueDisplayId}
348
- >
349
- {correctnessIcon}
350
- <StyledLabel
351
- id={valueDisplayId}
352
- ref={this.previewRef}
353
- dangerouslySetInnerHTML={{
354
- __html: correctValue
355
- ? correctValue
356
- : open && this.state.previewValue
357
- ? this.getLabel(choices, this.state.previewValue)
358
- : this.getLabel(choices, value) || '',
359
- }}
360
- />
361
- {open ? <ArrowDropUpIcon /> : <ArrowDropDownIcon />}
362
- </StyledButton>
363
- <StyledMenu
364
- id={menuId}
365
- anchorEl={anchorEl}
366
- keepMounted
367
- open={open}
368
- onClose={this.handleClose}
369
- getContentAnchorEl={null}
370
- anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
371
- transformOrigin={{ vertical: 'top', horizontal: 'left' }}
372
- transitionDuration={{ enter: 225, exit: 195 }}
373
- slotProps={{
374
- paper: this.state.menuWidth ? { style: { minWidth: this.state.menuWidth, padding: '4px' } } : undefined,
375
- list: {
376
- 'aria-labelledby': buttonId,
377
- role: 'listbox',
378
- disablePadding: true,
379
- },
380
- }}
381
- >
382
- {(choices || []).map((c, index) => {
383
- const optionId = `dropdown-option-${id}-${index}`;
384
-
385
- return (
386
- <StyledMenuItem
387
- id={optionId}
388
- className={c.value === value ? 'selected' : ''}
389
- key={`${c.label}-${index}`}
390
- value={c.value}
391
- onClick={() => this.handleSelect(c.value, index)}
392
- role="option"
393
- aria-selected={this.state.highlightedOptionId === optionId ? 'true' : undefined}
394
- onMouseOver={() => this.handleHover(index)}
395
- >
396
- <StyledLabel
397
- ref={(ref) => (this.elementRefs[index] = ref)}
398
- dangerouslySetInnerHTML={{ __html: c.label }}
399
- />
400
- <StyledSelectedIndicator dangerouslySetInnerHTML={{ __html: c.value === value ? ' &check;' : '' }} />
401
- </StyledMenuItem>
402
- );
403
- })}
404
- </StyledMenu>
405
- </>
406
- );
407
- }
408
- }
409
-
410
- 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
- });