@pie-lib/mask-markup 2.0.0-beta.1 → 2.0.0-beta.2
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 +143 -35
- package/lib/choices/choice.js +22 -31
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +9 -33
- package/lib/choices/index.js.map +1 -1
- package/lib/componentize.js +1 -4
- package/lib/componentize.js.map +1 -1
- package/lib/components/blank.js +61 -86
- package/lib/components/blank.js.map +1 -1
- package/lib/components/correct-input.js +9 -25
- package/lib/components/correct-input.js.map +1 -1
- package/lib/components/dropdown.js +11 -37
- package/lib/components/dropdown.js.map +1 -1
- package/lib/components/input.js +14 -17
- package/lib/components/input.js.map +1 -1
- package/lib/constructed-response.js +11 -14
- package/lib/constructed-response.js.map +1 -1
- package/lib/drag-in-the-blank.js +21 -50
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/index.js +1 -7
- package/lib/index.js.map +1 -1
- package/lib/inline-dropdown.js +6 -11
- package/lib/inline-dropdown.js.map +1 -1
- package/lib/mask.js +8 -49
- package/lib/mask.js.map +1 -1
- package/lib/new-serialization.js +6 -59
- package/lib/new-serialization.js.map +1 -0
- package/lib/parse-html.js +7 -6
- package/lib/parse-html.js.map +1 -0
- package/lib/serialization.js +9 -42
- package/lib/serialization.js.map +1 -1
- package/lib/test-serializer.js +4 -55
- package/lib/test-serializer.js.map +1 -0
- package/lib/with-mask.js +6 -30
- package/lib/with-mask.js.map +1 -1
- package/package.json +7 -7
- package/src/choices/choice.jsx +27 -13
- package/src/choices/index.jsx +17 -13
- package/src/components/blank.jsx +43 -31
- package/src/components/correct-input.jsx +18 -18
- package/src/components/dropdown.jsx +27 -38
- package/src/components/input.jsx +6 -3
- package/src/constructed-response.jsx +5 -4
- package/src/drag-in-the-blank.jsx +12 -12
- package/src/index.js +1 -8
- package/src/inline-dropdown.jsx +4 -3
- package/src/mask.jsx +13 -14
- package/src/new-serialization.jsx +19 -19
- package/src/parse-html.js +1 -1
- package/src/serialization.js +19 -14
- package/src/test-serializer.js +9 -9
- package/src/with-mask.jsx +2 -9
package/src/components/blank.jsx
CHANGED
|
@@ -14,42 +14,51 @@ export const DRAG_TYPE = 'MaskBlank';
|
|
|
14
14
|
const useStyles = withStyles(() => ({
|
|
15
15
|
content: {
|
|
16
16
|
border: `solid 0px ${color.primary()}`,
|
|
17
|
-
minWidth: '200px'
|
|
17
|
+
minWidth: '200px',
|
|
18
|
+
touchAction: 'none',
|
|
19
|
+
overflow: 'hidden',
|
|
18
20
|
},
|
|
19
21
|
chip: {
|
|
22
|
+
backgroundColor: color.background(),
|
|
23
|
+
border: `1px solid ${color.text()}`,
|
|
24
|
+
color: color.text(),
|
|
20
25
|
minWidth: '90px',
|
|
21
26
|
fontSize: 'inherit',
|
|
22
27
|
minHeight: '32px',
|
|
23
28
|
height: 'auto',
|
|
24
29
|
maxWidth: '374px',
|
|
25
|
-
position: 'relative'
|
|
30
|
+
position: 'relative',
|
|
26
31
|
},
|
|
27
32
|
chipLabel: {
|
|
28
33
|
whiteSpace: 'pre-wrap',
|
|
34
|
+
// Added for touch devices, for image content.
|
|
35
|
+
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
36
|
+
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
37
|
+
pointerEvents: 'none',
|
|
29
38
|
'& img': {
|
|
30
39
|
display: 'block',
|
|
31
|
-
padding: '2px 0'
|
|
32
|
-
}
|
|
40
|
+
padding: '2px 0',
|
|
41
|
+
},
|
|
33
42
|
},
|
|
34
43
|
hidden: {
|
|
35
44
|
color: 'transparent',
|
|
36
|
-
opacity: 0
|
|
45
|
+
opacity: 0,
|
|
37
46
|
},
|
|
38
47
|
dragged: {
|
|
39
48
|
position: 'absolute',
|
|
40
|
-
left:
|
|
41
|
-
maxWidth: '60px'
|
|
49
|
+
left: 16,
|
|
50
|
+
maxWidth: '60px',
|
|
42
51
|
},
|
|
43
52
|
correct: {
|
|
44
|
-
border: `solid 1px ${color.correct()}
|
|
53
|
+
border: `solid 1px ${color.correct()}`,
|
|
45
54
|
},
|
|
46
55
|
incorrect: {
|
|
47
|
-
border: `solid 1px ${color.incorrect()}
|
|
56
|
+
border: `solid 1px ${color.incorrect()}`,
|
|
48
57
|
},
|
|
49
58
|
over: {
|
|
50
59
|
whiteSpace: 'nowrap',
|
|
51
|
-
overflow: 'hidden'
|
|
52
|
-
}
|
|
60
|
+
overflow: 'hidden',
|
|
61
|
+
},
|
|
53
62
|
}));
|
|
54
63
|
|
|
55
64
|
export class BlankContent extends React.Component {
|
|
@@ -62,13 +71,13 @@ export class BlankContent extends React.Component {
|
|
|
62
71
|
isOver: PropTypes.bool,
|
|
63
72
|
dragItem: PropTypes.object,
|
|
64
73
|
correct: PropTypes.bool,
|
|
65
|
-
onChange: PropTypes.func
|
|
74
|
+
onChange: PropTypes.func,
|
|
66
75
|
};
|
|
67
76
|
|
|
68
77
|
constructor() {
|
|
69
78
|
super();
|
|
70
79
|
this.state = {
|
|
71
|
-
height: 0
|
|
80
|
+
height: 0,
|
|
72
81
|
};
|
|
73
82
|
}
|
|
74
83
|
|
|
@@ -80,20 +89,20 @@ export class BlankContent extends React.Component {
|
|
|
80
89
|
if (JSON.stringify(currentChoice) !== JSON.stringify(prevChoice)) {
|
|
81
90
|
if (!currentChoice) {
|
|
82
91
|
this.setState({
|
|
83
|
-
height: 0
|
|
92
|
+
height: 0,
|
|
84
93
|
});
|
|
85
94
|
return;
|
|
86
95
|
}
|
|
87
96
|
setTimeout(() => {
|
|
88
97
|
this.setState({
|
|
89
|
-
height: this.spanRef.offsetHeight
|
|
98
|
+
height: this.spanRef.offsetHeight,
|
|
90
99
|
});
|
|
91
100
|
}, 300);
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
addDraggableFalseAttributes(parent) {
|
|
96
|
-
parent.childNodes.forEach(elem => {
|
|
105
|
+
parent.childNodes.forEach((elem) => {
|
|
97
106
|
if (elem instanceof Element || elem instanceof HTMLDocument) {
|
|
98
107
|
elem.setAttribute('draggable', false);
|
|
99
108
|
}
|
|
@@ -106,8 +115,11 @@ export class BlankContent extends React.Component {
|
|
|
106
115
|
const label = choice && choice.value;
|
|
107
116
|
|
|
108
117
|
return (
|
|
118
|
+
// TODO the Chip element is causing drag problems on touch devices. Avoid using Chip and consider refactoring the code. Keep in mind that Chip is a span with a button role, which interferes with seamless touch device dragging.
|
|
109
119
|
<Chip
|
|
110
|
-
|
|
120
|
+
clickable={false}
|
|
121
|
+
disabled={true}
|
|
122
|
+
ref={(ref) => {
|
|
111
123
|
//eslint-disable-next-line
|
|
112
124
|
this.rootRef = ReactDOM.findDOMNode(ref);
|
|
113
125
|
}}
|
|
@@ -116,9 +128,9 @@ export class BlankContent extends React.Component {
|
|
|
116
128
|
<React.Fragment>
|
|
117
129
|
<span
|
|
118
130
|
className={classnames(classes.chipLabel, isOver && classes.over, {
|
|
119
|
-
[classes.hidden]: draggedLabel
|
|
131
|
+
[classes.hidden]: draggedLabel,
|
|
120
132
|
})}
|
|
121
|
-
ref={ref => {
|
|
133
|
+
ref={(ref) => {
|
|
122
134
|
if (ref) {
|
|
123
135
|
//eslint-disable-next-line
|
|
124
136
|
this.spanRef = ReactDOM.findDOMNode(ref);
|
|
@@ -132,7 +144,7 @@ export class BlankContent extends React.Component {
|
|
|
132
144
|
{draggedLabel && (
|
|
133
145
|
<span
|
|
134
146
|
className={classnames(classes.chipLabel, isOver && classes.over, classes.dragged)}
|
|
135
|
-
ref={ref => {
|
|
147
|
+
ref={(ref) => {
|
|
136
148
|
if (ref) {
|
|
137
149
|
//eslint-disable-next-line
|
|
138
150
|
this.spanRef = ReactDOM.findDOMNode(ref);
|
|
@@ -148,14 +160,14 @@ export class BlankContent extends React.Component {
|
|
|
148
160
|
}
|
|
149
161
|
className={classnames(classes.chip, isOver && classes.over, {
|
|
150
162
|
[classes.correct]: correct !== undefined && correct,
|
|
151
|
-
[classes.incorrect]: correct !== undefined && !correct
|
|
163
|
+
[classes.incorrect]: correct !== undefined && !correct,
|
|
152
164
|
})}
|
|
153
165
|
variant={disabled ? 'outlined' : undefined}
|
|
154
166
|
style={{
|
|
155
|
-
...(this.state.height ? { height: this.state.height } : {})
|
|
167
|
+
...(this.state.height ? { height: this.state.height } : {}),
|
|
156
168
|
}}
|
|
157
169
|
classes={{
|
|
158
|
-
label: isOver && classes.over
|
|
170
|
+
label: isOver && classes.over,
|
|
159
171
|
}}
|
|
160
172
|
/>
|
|
161
173
|
);
|
|
@@ -171,8 +183,8 @@ const connectedBlankContent = useStyles(({ connectDragSource, connectDropTarget,
|
|
|
171
183
|
connectDragSource(
|
|
172
184
|
<span className={classnames(classes.content, isOver && classes.over)}>
|
|
173
185
|
<StyledBlankContent {...props} />
|
|
174
|
-
</span
|
|
175
|
-
)
|
|
186
|
+
</span>,
|
|
187
|
+
),
|
|
176
188
|
);
|
|
177
189
|
});
|
|
178
190
|
|
|
@@ -187,20 +199,20 @@ const tileTarget = {
|
|
|
187
199
|
}
|
|
188
200
|
|
|
189
201
|
return {
|
|
190
|
-
dropped: draggedItem.id !== props.id
|
|
202
|
+
dropped: draggedItem.id !== props.id,
|
|
191
203
|
};
|
|
192
204
|
},
|
|
193
205
|
canDrop(props, monitor) {
|
|
194
206
|
const draggedItem = monitor.getItem();
|
|
195
207
|
|
|
196
208
|
return draggedItem.instanceId === props.instanceId;
|
|
197
|
-
}
|
|
209
|
+
},
|
|
198
210
|
};
|
|
199
211
|
|
|
200
212
|
const DropTile = DropTarget(DRAG_TYPE, tileTarget, (connect, monitor) => ({
|
|
201
213
|
connectDropTarget: connect.dropTarget(),
|
|
202
214
|
isOver: monitor.isOver(),
|
|
203
|
-
dragItem: monitor.getItem()
|
|
215
|
+
dragItem: monitor.getItem(),
|
|
204
216
|
}))(connectedBlankContent);
|
|
205
217
|
|
|
206
218
|
const tileSource = {
|
|
@@ -212,7 +224,7 @@ const tileSource = {
|
|
|
212
224
|
id: props.id,
|
|
213
225
|
choice: props.choice,
|
|
214
226
|
instanceId: props.instanceId,
|
|
215
|
-
fromChoice: true
|
|
227
|
+
fromChoice: true,
|
|
216
228
|
};
|
|
217
229
|
},
|
|
218
230
|
endDrag(props, monitor) {
|
|
@@ -226,12 +238,12 @@ const tileSource = {
|
|
|
226
238
|
props.onChange(props.id, undefined);
|
|
227
239
|
}
|
|
228
240
|
}
|
|
229
|
-
}
|
|
241
|
+
},
|
|
230
242
|
};
|
|
231
243
|
|
|
232
244
|
const DragDropTile = DragSource(DRAG_TYPE, tileSource, (connect, monitor) => ({
|
|
233
245
|
connectDragSource: connect.dragSource(),
|
|
234
|
-
isDragging: monitor.isDragging()
|
|
246
|
+
isDragging: monitor.isDragging(),
|
|
235
247
|
}))(DropTile);
|
|
236
248
|
|
|
237
249
|
export default DragDropTile;
|
|
@@ -4,8 +4,8 @@ import classnames from 'classnames';
|
|
|
4
4
|
import { withStyles } from '@material-ui/core/styles';
|
|
5
5
|
import { color } from '@pie-lib/render-ui';
|
|
6
6
|
|
|
7
|
-
const correctStyle = color => ({
|
|
8
|
-
borderColor: `${color} !important
|
|
7
|
+
const correctStyle = (color) => ({
|
|
8
|
+
borderColor: `${color} !important`,
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
export default withStyles(() => ({
|
|
@@ -18,37 +18,37 @@ export default withStyles(() => ({
|
|
|
18
18
|
padding: '10px 20px 10px 10px',
|
|
19
19
|
'&:disabled': {
|
|
20
20
|
opacity: 0.8,
|
|
21
|
-
cursor: 'not-allowed !important'
|
|
21
|
+
cursor: 'not-allowed !important',
|
|
22
22
|
},
|
|
23
23
|
'&:hover': {
|
|
24
24
|
borderColor: color.primary(),
|
|
25
25
|
'&:disabled': {
|
|
26
|
-
borderColor: 'initial'
|
|
27
|
-
}
|
|
26
|
+
borderColor: 'initial',
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
29
|
'&:focus': {
|
|
30
|
-
borderColor: color.primaryDark()
|
|
31
|
-
}
|
|
30
|
+
borderColor: color.primaryDark(),
|
|
31
|
+
},
|
|
32
32
|
},
|
|
33
33
|
crInput: {
|
|
34
|
-
padding: '8px !important'
|
|
34
|
+
padding: '8px !important',
|
|
35
35
|
},
|
|
36
36
|
correct: correctStyle(color.correct()),
|
|
37
37
|
incorrect: correctStyle(color.incorrect()),
|
|
38
38
|
box: {
|
|
39
|
-
fontSize: 'inherit'
|
|
39
|
+
fontSize: 'inherit',
|
|
40
40
|
},
|
|
41
41
|
outlinedInput: {
|
|
42
42
|
padding: '2px',
|
|
43
43
|
borderRadius: '4px',
|
|
44
44
|
'& fieldset': {
|
|
45
|
-
border: 0
|
|
46
|
-
}
|
|
45
|
+
border: 0,
|
|
46
|
+
},
|
|
47
47
|
},
|
|
48
48
|
notchedOutline: {
|
|
49
|
-
borderColor: color.correct()
|
|
50
|
-
}
|
|
51
|
-
}))(props => {
|
|
49
|
+
borderColor: color.correct(),
|
|
50
|
+
},
|
|
51
|
+
}))((props) => {
|
|
52
52
|
const {
|
|
53
53
|
correct,
|
|
54
54
|
charactersLimit,
|
|
@@ -65,7 +65,7 @@ export default withStyles(() => ({
|
|
|
65
65
|
|
|
66
66
|
if (width) {
|
|
67
67
|
inputProps.style = {
|
|
68
|
-
width: `${width + Math.round(width / 10) + 1}ch
|
|
68
|
+
width: `${width + Math.round(width / 10) + 1}ch`, // added some extra space for capital letters
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -74,14 +74,14 @@ export default withStyles(() => ({
|
|
|
74
74
|
className={classnames({
|
|
75
75
|
[classes.disabledInput]: disabled,
|
|
76
76
|
[classes.box]: isBox,
|
|
77
|
-
[classes.outlinedInput]: true
|
|
77
|
+
[classes.outlinedInput]: true,
|
|
78
78
|
})}
|
|
79
79
|
classes={{
|
|
80
80
|
input: classnames({
|
|
81
81
|
[classes.input]: true,
|
|
82
82
|
[classes[label]]: label,
|
|
83
|
-
[classes.crInput]: isConstructedResponse
|
|
84
|
-
})
|
|
83
|
+
[classes.crInput]: isConstructedResponse,
|
|
84
|
+
}),
|
|
85
85
|
}}
|
|
86
86
|
inputProps={inputProps}
|
|
87
87
|
labelWidth={0}
|
|
@@ -14,10 +14,8 @@ class Dropdown extends React.Component {
|
|
|
14
14
|
onChange: PropTypes.func,
|
|
15
15
|
classes: PropTypes.object,
|
|
16
16
|
correct: PropTypes.bool,
|
|
17
|
-
choices: PropTypes.arrayOf(
|
|
18
|
-
|
|
19
|
-
),
|
|
20
|
-
showCorrectAnswer: PropTypes.bool
|
|
17
|
+
choices: PropTypes.arrayOf(PropTypes.shape({ value: PropTypes.string, label: PropTypes.string })),
|
|
18
|
+
showCorrectAnswer: PropTypes.bool,
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
constructor(props) {
|
|
@@ -25,35 +23,26 @@ class Dropdown extends React.Component {
|
|
|
25
23
|
|
|
26
24
|
this.state = {
|
|
27
25
|
showCheckmark: false,
|
|
28
|
-
open: false
|
|
26
|
+
open: false,
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
showCheckmarkAndOpen = () => {
|
|
33
31
|
this.setState({
|
|
34
32
|
showCheckmark: true,
|
|
35
|
-
open: true
|
|
33
|
+
open: true,
|
|
36
34
|
});
|
|
37
35
|
};
|
|
38
36
|
|
|
39
37
|
hideCheckmarkAndClose = () => {
|
|
40
38
|
this.setState({
|
|
41
39
|
showCheckmark: false,
|
|
42
|
-
open: false
|
|
40
|
+
open: false,
|
|
43
41
|
});
|
|
44
42
|
};
|
|
45
43
|
|
|
46
44
|
render() {
|
|
47
|
-
const {
|
|
48
|
-
classes,
|
|
49
|
-
id,
|
|
50
|
-
correct,
|
|
51
|
-
disabled,
|
|
52
|
-
value,
|
|
53
|
-
onChange,
|
|
54
|
-
choices,
|
|
55
|
-
showCorrectAnswer
|
|
56
|
-
} = this.props;
|
|
45
|
+
const { classes, id, correct, disabled, value, onChange, choices, showCorrectAnswer } = this.props;
|
|
57
46
|
|
|
58
47
|
const { showCheckmark, open } = this.state;
|
|
59
48
|
|
|
@@ -63,7 +52,7 @@ class Dropdown extends React.Component {
|
|
|
63
52
|
root: classes.root,
|
|
64
53
|
icon: classes.icon,
|
|
65
54
|
selectMenu: classes.selectMenu,
|
|
66
|
-
select: classes.select
|
|
55
|
+
select: classes.select,
|
|
67
56
|
}}
|
|
68
57
|
disabled={disabled}
|
|
69
58
|
value={value || ''}
|
|
@@ -73,9 +62,9 @@ class Dropdown extends React.Component {
|
|
|
73
62
|
input={<CorrectInput correct={showCorrectAnswer || correct} />}
|
|
74
63
|
MenuProps={{
|
|
75
64
|
keepMounted: true,
|
|
76
|
-
disablePortal: true
|
|
65
|
+
disablePortal: true,
|
|
77
66
|
}}
|
|
78
|
-
onChange={e => {
|
|
67
|
+
onChange={(e) => {
|
|
79
68
|
onChange(id, e.target.value);
|
|
80
69
|
}}
|
|
81
70
|
>
|
|
@@ -88,7 +77,7 @@ class Dropdown extends React.Component {
|
|
|
88
77
|
<span
|
|
89
78
|
className={classes.label}
|
|
90
79
|
dangerouslySetInnerHTML={{
|
|
91
|
-
__html: c.label
|
|
80
|
+
__html: c.label,
|
|
92
81
|
}}
|
|
93
82
|
/>
|
|
94
83
|
{showCheckmark && (
|
|
@@ -115,57 +104,57 @@ const styles = () => ({
|
|
|
115
104
|
border: `1px solid ${color.text()}`,
|
|
116
105
|
borderRadius: '5px',
|
|
117
106
|
color: color.text(),
|
|
118
|
-
backgroundColor: color.background()
|
|
119
|
-
}
|
|
107
|
+
backgroundColor: color.background(),
|
|
108
|
+
},
|
|
120
109
|
},
|
|
121
110
|
select: {
|
|
122
111
|
'&:focus': {
|
|
123
|
-
borderRadius: '4px'
|
|
124
|
-
}
|
|
112
|
+
borderRadius: '4px',
|
|
113
|
+
},
|
|
125
114
|
},
|
|
126
115
|
selectMenu: {
|
|
127
116
|
backgroundColor: color.background(),
|
|
128
117
|
'&:hover': {
|
|
129
|
-
borderColor: 'initial'
|
|
118
|
+
borderColor: 'initial',
|
|
130
119
|
},
|
|
131
120
|
'&:focus': {
|
|
132
|
-
borderColor: 'initial'
|
|
133
|
-
}
|
|
121
|
+
borderColor: 'initial',
|
|
122
|
+
},
|
|
134
123
|
},
|
|
135
124
|
icon: {
|
|
136
|
-
color: color.text()
|
|
125
|
+
color: color.text(),
|
|
137
126
|
},
|
|
138
127
|
selected: {
|
|
139
128
|
color: `${color.text()} !important`,
|
|
140
129
|
backgroundColor: `${color.background()} !important`,
|
|
141
130
|
'&:hover': {
|
|
142
131
|
color: color.text(),
|
|
143
|
-
backgroundColor: `${color.secondaryLight()} !important
|
|
144
|
-
}
|
|
132
|
+
backgroundColor: `${color.secondaryLight()} !important`,
|
|
133
|
+
},
|
|
145
134
|
},
|
|
146
135
|
menuRoot: {
|
|
147
136
|
color: color.text(),
|
|
148
137
|
backgroundColor: color.background(),
|
|
149
138
|
'&:focus': {
|
|
150
139
|
color: color.text(),
|
|
151
|
-
backgroundColor: color.background()
|
|
140
|
+
backgroundColor: color.background(),
|
|
152
141
|
},
|
|
153
142
|
'&:hover': {
|
|
154
143
|
color: color.text(),
|
|
155
|
-
backgroundColor: color.secondaryLight()
|
|
144
|
+
backgroundColor: color.secondaryLight(),
|
|
156
145
|
},
|
|
157
146
|
boxSizing: 'border-box',
|
|
158
147
|
padding: '25px',
|
|
159
148
|
'&:first-of-type': {
|
|
160
|
-
borderRadius: '3px 3px 0 0'
|
|
149
|
+
borderRadius: '3px 3px 0 0',
|
|
161
150
|
},
|
|
162
151
|
'&:last-of-type': {
|
|
163
|
-
borderRadius: '0 0 3px 3px'
|
|
164
|
-
}
|
|
152
|
+
borderRadius: '0 0 3px 3px',
|
|
153
|
+
},
|
|
165
154
|
},
|
|
166
155
|
label: {
|
|
167
|
-
fontSize: 'max(1rem, 14px)'
|
|
168
|
-
}
|
|
156
|
+
fontSize: 'max(1rem, 14px)',
|
|
157
|
+
},
|
|
169
158
|
});
|
|
170
159
|
|
|
171
160
|
export default withStyles(styles)(Dropdown);
|
package/src/components/input.jsx
CHANGED
|
@@ -12,7 +12,7 @@ const Input = ({
|
|
|
12
12
|
onChange,
|
|
13
13
|
showCorrectAnswer,
|
|
14
14
|
spellCheck,
|
|
15
|
-
width
|
|
15
|
+
width,
|
|
16
16
|
}) => {
|
|
17
17
|
return (
|
|
18
18
|
<CorrectInput
|
|
@@ -25,7 +25,7 @@ const Input = ({
|
|
|
25
25
|
spellCheck={spellCheck}
|
|
26
26
|
isBox={true}
|
|
27
27
|
width={width}
|
|
28
|
-
onChange={e => {
|
|
28
|
+
onChange={(e) => {
|
|
29
29
|
onChange(id, e.target.value);
|
|
30
30
|
}}
|
|
31
31
|
/>
|
|
@@ -39,7 +39,10 @@ Input.propTypes = {
|
|
|
39
39
|
disabled: PropTypes.bool,
|
|
40
40
|
spellCheck: PropTypes.bool,
|
|
41
41
|
correct: PropTypes.bool,
|
|
42
|
-
showCorrectAnswer: PropTypes.bool
|
|
42
|
+
showCorrectAnswer: PropTypes.bool,
|
|
43
|
+
charactersLimit: PropTypes.number,
|
|
44
|
+
width: PropTypes.number,
|
|
45
|
+
isConstructedResponse: PropTypes.bool,
|
|
43
46
|
};
|
|
44
47
|
|
|
45
48
|
export default Input;
|
|
@@ -2,16 +2,17 @@ import React from 'react';
|
|
|
2
2
|
import Input from './components/input';
|
|
3
3
|
import { withMask } from './with-mask';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// eslint-disable-next-line react/display-name
|
|
6
|
+
export default withMask('input', (props) => (node, data, onChange) => {
|
|
6
7
|
const dataset = node.data ? node.data.dataset || {} : {};
|
|
7
8
|
if (dataset.component === 'input') {
|
|
9
|
+
// eslint-disable-next-line react/prop-types
|
|
8
10
|
const { adjustedLimit, disabled, feedback, showCorrectAnswer, maxLength, spellCheck } = props;
|
|
9
11
|
|
|
10
12
|
// the first answer is the correct one
|
|
13
|
+
// eslint-disable-next-line react/prop-types
|
|
11
14
|
const correctAnswer = ((props.choices && dataset && props.choices[dataset.id]) || [])[0];
|
|
12
|
-
const finalValue = showCorrectAnswer
|
|
13
|
-
? correctAnswer && correctAnswer.label
|
|
14
|
-
: data[dataset.id] || '';
|
|
15
|
+
const finalValue = showCorrectAnswer ? correctAnswer && correctAnswer.label : data[dataset.id] || '';
|
|
15
16
|
const width = maxLength && maxLength[dataset.id];
|
|
16
17
|
|
|
17
18
|
return (
|
|
@@ -5,13 +5,15 @@ import Choices from './choices';
|
|
|
5
5
|
import Blank from './components/blank';
|
|
6
6
|
import { withMask } from './with-mask';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// eslint-disable-next-line react/display-name
|
|
9
|
+
const Masked = withMask('blank', (props) => (node, data, onChange) => {
|
|
9
10
|
const dataset = node.data ? node.data.dataset || {} : {};
|
|
10
|
-
|
|
11
11
|
if (dataset.component === 'blank') {
|
|
12
|
+
// eslint-disable-next-line react/prop-types
|
|
12
13
|
const { disabled, duplicates, correctResponse, feedback, showCorrectAnswer } = props;
|
|
13
14
|
const choiceId = showCorrectAnswer ? correctResponse[dataset.id] : data[dataset.id];
|
|
14
|
-
|
|
15
|
+
// eslint-disable-next-line react/prop-types
|
|
16
|
+
const choice = choiceId && props.choices.find((c) => c.id === choiceId);
|
|
15
17
|
|
|
16
18
|
return (
|
|
17
19
|
<Blank
|
|
@@ -32,19 +34,17 @@ export default class DragInTheBlank extends React.Component {
|
|
|
32
34
|
markup: PropTypes.string,
|
|
33
35
|
layout: PropTypes.object,
|
|
34
36
|
choicesPosition: PropTypes.string,
|
|
35
|
-
choices: PropTypes.arrayOf(
|
|
36
|
-
PropTypes.shape({ label: PropTypes.string, value: PropTypes.string })
|
|
37
|
-
),
|
|
37
|
+
choices: PropTypes.arrayOf(PropTypes.shape({ label: PropTypes.string, value: PropTypes.string })),
|
|
38
38
|
value: PropTypes.object,
|
|
39
39
|
onChange: PropTypes.func,
|
|
40
40
|
duplicates: PropTypes.bool,
|
|
41
41
|
disabled: PropTypes.bool,
|
|
42
42
|
feedback: PropTypes.object,
|
|
43
43
|
correctResponse: PropTypes.object,
|
|
44
|
-
showCorrectAnswer: PropTypes.bool
|
|
44
|
+
showCorrectAnswer: PropTypes.bool,
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
UNSAFE_componentWillReceiveProps() {
|
|
48
48
|
if (this.rootRef) {
|
|
49
49
|
renderMath(this.rootRef);
|
|
50
50
|
}
|
|
@@ -54,7 +54,7 @@ export default class DragInTheBlank extends React.Component {
|
|
|
54
54
|
renderMath(this.rootRef);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
getPositionDirection = choicePosition => {
|
|
57
|
+
getPositionDirection = (choicePosition) => {
|
|
58
58
|
let flexDirection;
|
|
59
59
|
|
|
60
60
|
switch (choicePosition) {
|
|
@@ -88,17 +88,17 @@ export default class DragInTheBlank extends React.Component {
|
|
|
88
88
|
correctResponse,
|
|
89
89
|
disabled,
|
|
90
90
|
feedback,
|
|
91
|
-
showCorrectAnswer
|
|
91
|
+
showCorrectAnswer,
|
|
92
92
|
} = this.props;
|
|
93
93
|
|
|
94
94
|
const choicePosition = choicesPosition || 'below';
|
|
95
95
|
const style = {
|
|
96
96
|
display: 'flex',
|
|
97
|
-
flexDirection: this.getPositionDirection(choicePosition)
|
|
97
|
+
flexDirection: this.getPositionDirection(choicePosition),
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
return (
|
|
101
|
-
<div ref={ref => ref && (this.rootRef = ref)} style={style}>
|
|
101
|
+
<div ref={(ref) => ref && (this.rootRef = ref)} style={style}>
|
|
102
102
|
<Choices
|
|
103
103
|
choicePosition={choicePosition}
|
|
104
104
|
duplicates={duplicates}
|
package/src/index.js
CHANGED
|
@@ -4,11 +4,4 @@ import ConstructedResponse from './constructed-response';
|
|
|
4
4
|
import InlineDropdown from './inline-dropdown';
|
|
5
5
|
import componentize from './componentize';
|
|
6
6
|
|
|
7
|
-
export {
|
|
8
|
-
withMask,
|
|
9
|
-
buildLayoutFromMarkup,
|
|
10
|
-
DragInTheBlank,
|
|
11
|
-
ConstructedResponse,
|
|
12
|
-
InlineDropdown,
|
|
13
|
-
componentize
|
|
14
|
-
};
|
|
7
|
+
export { withMask, buildLayoutFromMarkup, DragInTheBlank, ConstructedResponse, InlineDropdown, componentize };
|
package/src/inline-dropdown.jsx
CHANGED
|
@@ -2,12 +2,13 @@ import React from 'react';
|
|
|
2
2
|
import Dropdown from './components/dropdown';
|
|
3
3
|
import { withMask } from './with-mask';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// eslint-disable-next-line react/display-name
|
|
6
|
+
export default withMask('dropdown', (props) => (node, data, onChange) => {
|
|
6
7
|
const dataset = node.data ? node.data.dataset || {} : {};
|
|
7
8
|
if (dataset.component === 'dropdown') {
|
|
9
|
+
// eslint-disable-next-line react/prop-types
|
|
8
10
|
const { choices, disabled, feedback, showCorrectAnswer } = props;
|
|
9
|
-
const correctAnswer =
|
|
10
|
-
choices && choices[dataset.id] && choices[dataset.id].find(c => c.correct);
|
|
11
|
+
const correctAnswer = choices && choices[dataset.id] && choices[dataset.id].find((c) => c.correct);
|
|
11
12
|
const finalChoice = showCorrectAnswer ? correctAnswer && correctAnswer.value : data[dataset.id];
|
|
12
13
|
|
|
13
14
|
return (
|