@pie-lib/mask-markup 1.30.6-esmbeta.2 → 1.31.0-mui-update.0
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 +36 -0
- package/lib/choices/choice.js +74 -203
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +19 -52
- package/lib/choices/index.js.map +1 -1
- package/lib/componentize.js +1 -5
- package/lib/componentize.js.map +1 -1
- package/lib/components/blank.js +292 -357
- package/lib/components/blank.js.map +1 -1
- package/lib/components/correct-input.js +41 -65
- package/lib/components/correct-input.js.map +1 -1
- package/lib/components/dropdown.js +203 -248
- package/lib/components/dropdown.js.map +1 -1
- package/lib/components/input.js +10 -17
- package/lib/components/input.js.map +1 -1
- package/lib/constructed-response.js +38 -52
- package/lib/constructed-response.js.map +1 -1
- package/lib/customizable.js +5 -9
- package/lib/customizable.js.map +1 -1
- package/lib/drag-in-the-blank.js +117 -96
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/index.js +0 -7
- package/lib/index.js.map +1 -1
- package/lib/inline-dropdown.js +4 -12
- package/lib/inline-dropdown.js.map +1 -1
- package/lib/mask.js +40 -112
- package/lib/mask.js.map +1 -1
- package/lib/serialization.js +8 -48
- package/lib/serialization.js.map +1 -1
- package/lib/with-mask.js +26 -55
- package/lib/with-mask.js.map +1 -1
- package/package.json +12 -17
- package/src/choices/choice.jsx +58 -154
- package/src/choices/index.jsx +8 -2
- package/src/components/blank.jsx +272 -262
- package/src/components/correct-input.jsx +33 -39
- package/src/components/dropdown.jsx +165 -156
- package/src/constructed-response.jsx +22 -18
- package/src/drag-in-the-blank.jsx +97 -39
- package/src/mask.jsx +18 -27
- package/esm/index.js +0 -81026
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -1
package/src/components/blank.jsx
CHANGED
|
@@ -1,269 +1,253 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React from 'react';
|
|
1
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
3
2
|
import ReactDOM from 'react-dom';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
5
4
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
6
5
|
import debug from 'debug';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
6
|
+
import { useDraggable, useDroppable } from '@dnd-kit/core';
|
|
7
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
9
|
+
import Chip from '@mui/material/Chip';
|
|
10
10
|
import classnames from 'classnames';
|
|
11
11
|
import { color } from '@pie-lib/render-ui';
|
|
12
|
+
import { grey } from '@mui/material/colors';
|
|
12
13
|
|
|
13
14
|
const log = debug('pie-lib:mask-markup:blank');
|
|
14
|
-
export const DRAG_TYPE = 'MaskBlank';
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const StyledContent = styled('span')(() => ({
|
|
17
|
+
border: `solid 0px ${color.primary()}`,
|
|
18
|
+
minWidth: '200px',
|
|
19
|
+
touchAction: 'none',
|
|
20
|
+
overflow: 'hidden',
|
|
21
|
+
whiteSpace: 'nowrap', // Prevent line wrapping
|
|
22
|
+
'&.over': {
|
|
23
|
+
whiteSpace: 'nowrap',
|
|
21
24
|
overflow: 'hidden',
|
|
22
|
-
whiteSpace: 'nowrap', // Prevent line wrapping
|
|
23
|
-
},
|
|
24
|
-
chip: {
|
|
25
|
-
backgroundColor: color.background(),
|
|
26
|
-
border: `2px dashed ${color.text()}`,
|
|
27
|
-
color: color.text(),
|
|
28
|
-
fontSize: 'inherit',
|
|
29
|
-
maxWidth: '374px',
|
|
30
|
-
position: 'relative',
|
|
31
|
-
borderRadius: '3px',
|
|
32
25
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
'& p': {
|
|
47
|
-
marginTop: '0',
|
|
48
|
-
marginBottom: '0',
|
|
49
|
-
},
|
|
50
|
-
'& mjx-frac': {
|
|
51
|
-
fontSize: '120% !important',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
hidden: {
|
|
55
|
-
color: 'transparent',
|
|
56
|
-
opacity: 0,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
const StyledChip = styled(Chip)(() => ({
|
|
29
|
+
backgroundColor: color.background(),
|
|
30
|
+
border: `2px dashed ${color.text()}`,
|
|
31
|
+
color: color.text(),
|
|
32
|
+
fontSize: 'inherit',
|
|
33
|
+
maxWidth: '374px',
|
|
34
|
+
position: 'relative',
|
|
35
|
+
borderRadius: '3px',
|
|
36
|
+
'&.over': {
|
|
37
|
+
whiteSpace: 'nowrap',
|
|
38
|
+
overflow: 'hidden',
|
|
57
39
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
maxWidth: '60px',
|
|
40
|
+
'&.parentOver': {
|
|
41
|
+
border: `1px solid ${grey[500]}`,
|
|
42
|
+
backgroundColor: `${grey[300]}`,
|
|
62
43
|
},
|
|
63
|
-
correct: {
|
|
44
|
+
'&.correct': {
|
|
64
45
|
border: `solid 1px ${color.correct()}`,
|
|
65
46
|
},
|
|
66
|
-
incorrect: {
|
|
47
|
+
'&.incorrect': {
|
|
67
48
|
border: `solid 1px ${color.incorrect()}`,
|
|
68
49
|
},
|
|
69
|
-
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const StyledChipLabel = styled('span')(() => ({
|
|
53
|
+
whiteSpace: 'normal',
|
|
54
|
+
// Added for touch devices, for image content.
|
|
55
|
+
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
56
|
+
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
57
|
+
pointerEvents: 'none',
|
|
58
|
+
'& img': {
|
|
59
|
+
display: 'block',
|
|
60
|
+
padding: '2px 0',
|
|
61
|
+
},
|
|
62
|
+
// Remove default <p> margins to ensure consistent spacing across all wrapped content (p, span, div, math)
|
|
63
|
+
// Padding for top and bottom will instead be controlled by the container for consistent layout
|
|
64
|
+
// Ensures consistent behavior with pie-api-browser, where marginTop is already removed by a Bootstrap stylesheet
|
|
65
|
+
'& p': {
|
|
66
|
+
marginTop: '0',
|
|
67
|
+
marginBottom: '0',
|
|
68
|
+
},
|
|
69
|
+
'& mjx-frac': {
|
|
70
|
+
fontSize: '120% !important',
|
|
71
|
+
},
|
|
72
|
+
'&.over': {
|
|
70
73
|
whiteSpace: 'nowrap',
|
|
71
74
|
overflow: 'hidden',
|
|
72
75
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
'&.hidden': {
|
|
77
|
+
color: 'transparent',
|
|
78
|
+
opacity: 0,
|
|
79
|
+
},
|
|
80
|
+
'&.dragged': {
|
|
81
|
+
position: 'absolute',
|
|
82
|
+
left: 16,
|
|
83
|
+
maxWidth: '60px',
|
|
76
84
|
},
|
|
77
85
|
}));
|
|
78
86
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
function BlankContent({
|
|
88
|
+
disabled,
|
|
89
|
+
choice,
|
|
90
|
+
isOver,
|
|
91
|
+
dragItem,
|
|
92
|
+
correct,
|
|
93
|
+
emptyResponseAreaWidth,
|
|
94
|
+
emptyResponseAreaHeight,
|
|
95
|
+
}) {
|
|
96
|
+
const rootRef = useRef(null);
|
|
97
|
+
const spanRef = useRef(null);
|
|
98
|
+
const [dimensions, setDimensions] = useState({ height: 0, width: 0 });
|
|
99
|
+
|
|
100
|
+
const handleImageLoad = () => {
|
|
101
|
+
updateDimensions();
|
|
90
102
|
};
|
|
91
103
|
|
|
92
|
-
handleElements() {
|
|
93
|
-
const imageElement =
|
|
94
|
-
|
|
104
|
+
const handleElements = () => {
|
|
105
|
+
const imageElement = spanRef.current?.querySelector('img');
|
|
95
106
|
if (imageElement) {
|
|
96
|
-
imageElement.onload =
|
|
107
|
+
imageElement.onload = handleImageLoad;
|
|
97
108
|
} else {
|
|
98
109
|
setTimeout(() => {
|
|
99
|
-
|
|
110
|
+
updateDimensions();
|
|
100
111
|
}, 300);
|
|
101
112
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
componentDidMount() {
|
|
105
|
-
this.handleElements();
|
|
106
|
-
if (this.rootRef) {
|
|
107
|
-
this.rootRef.addEventListener('touchstart', this.handleTouchStart, { passive: false });
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
componentDidUpdate(prevProps) {
|
|
112
|
-
renderMath(this.rootRef);
|
|
113
|
-
const { choice: currentChoice } = this.props;
|
|
114
|
-
const { choice: prevChoice } = prevProps;
|
|
115
|
-
|
|
116
|
-
if (JSON.stringify(currentChoice) !== JSON.stringify(prevChoice)) {
|
|
117
|
-
if (!currentChoice) {
|
|
118
|
-
this.setState({
|
|
119
|
-
height: 0,
|
|
120
|
-
width: 0,
|
|
121
|
-
});
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
this.handleElements();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
componentWillUnmount() {
|
|
129
|
-
if (this.rootRef) {
|
|
130
|
-
this.rootRef.removeEventListener('touchstart', this.handleTouchStart);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
handleTouchStart = (e) => {
|
|
135
|
-
e.preventDefault();
|
|
136
|
-
this.touchStartTimer = setTimeout(() => {
|
|
137
|
-
this.startDrag();
|
|
138
|
-
}, 300); // Start drag after 300ms (touch and hold duration)
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
startDrag = () => {
|
|
142
|
-
const { connectDragSource, disabled } = this.props;
|
|
143
|
-
if (!disabled) {
|
|
144
|
-
connectDragSource(this.rootRef);
|
|
145
|
-
}
|
|
146
113
|
};
|
|
147
114
|
|
|
148
|
-
updateDimensions() {
|
|
149
|
-
if (
|
|
115
|
+
const updateDimensions = () => {
|
|
116
|
+
if (spanRef.current && rootRef.current) {
|
|
150
117
|
// Temporarily set rootRef width to 'auto' for natural measurement
|
|
151
|
-
|
|
118
|
+
rootRef.current.style.width = 'auto';
|
|
152
119
|
|
|
153
120
|
// Get the natural dimensions of the content
|
|
154
|
-
const width =
|
|
155
|
-
const height =
|
|
121
|
+
const width = spanRef.current.offsetWidth || 0;
|
|
122
|
+
const height = spanRef.current.offsetHeight || 0;
|
|
156
123
|
|
|
157
124
|
const widthWithPadding = width + 24; // 12px padding on each side
|
|
158
125
|
const heightWithPadding = height + 24; // 12px padding on top and bottom
|
|
159
126
|
|
|
160
|
-
const responseAreaWidth = parseFloat(
|
|
161
|
-
const responseAreaHeight = parseFloat(
|
|
127
|
+
const responseAreaWidth = parseFloat(emptyResponseAreaWidth) || 0;
|
|
128
|
+
const responseAreaHeight = parseFloat(emptyResponseAreaHeight) || 0;
|
|
162
129
|
|
|
163
130
|
const adjustedWidth = widthWithPadding <= responseAreaWidth ? responseAreaWidth : widthWithPadding;
|
|
164
131
|
const adjustedHeight = heightWithPadding <= responseAreaHeight ? responseAreaHeight : heightWithPadding;
|
|
165
132
|
|
|
166
|
-
|
|
133
|
+
setDimensions(prevState => ({
|
|
167
134
|
width: adjustedWidth > responseAreaWidth ? adjustedWidth : prevState.width,
|
|
168
135
|
height: adjustedHeight > responseAreaHeight ? adjustedHeight : prevState.height,
|
|
169
136
|
}));
|
|
170
137
|
|
|
171
|
-
|
|
172
|
-
|
|
138
|
+
rootRef.current.style.width = `${adjustedWidth}px`;
|
|
139
|
+
rootRef.current.style.height = `${adjustedHeight}px`;
|
|
173
140
|
}
|
|
174
|
-
}
|
|
141
|
+
};
|
|
175
142
|
|
|
176
|
-
addDraggableFalseAttributes(parent) {
|
|
177
|
-
parent.childNodes
|
|
178
|
-
|
|
179
|
-
elem
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
143
|
+
const addDraggableFalseAttributes = (parent) => {
|
|
144
|
+
if (parent && parent.childNodes) {
|
|
145
|
+
parent.childNodes.forEach((elem) => {
|
|
146
|
+
if (elem instanceof Element || elem instanceof HTMLDocument) {
|
|
147
|
+
elem.setAttribute('draggable', false);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
183
152
|
|
|
184
|
-
getRootDimensions() {
|
|
153
|
+
const getRootDimensions = () => {
|
|
185
154
|
// Handle potential non-numeric values
|
|
186
|
-
const responseAreaWidth = !isNaN(parseFloat(
|
|
187
|
-
? parseFloat(
|
|
155
|
+
const responseAreaWidth = !isNaN(parseFloat(emptyResponseAreaWidth))
|
|
156
|
+
? parseFloat(emptyResponseAreaWidth)
|
|
188
157
|
: 0;
|
|
189
|
-
const responseAreaHeight = !isNaN(parseFloat(
|
|
190
|
-
? parseFloat(
|
|
158
|
+
const responseAreaHeight = !isNaN(parseFloat(emptyResponseAreaHeight))
|
|
159
|
+
? parseFloat(emptyResponseAreaHeight)
|
|
191
160
|
: 0;
|
|
192
161
|
|
|
193
162
|
const rootStyle = {
|
|
194
|
-
height:
|
|
195
|
-
width:
|
|
163
|
+
height: dimensions.height || responseAreaHeight,
|
|
164
|
+
width: dimensions.width || responseAreaWidth,
|
|
196
165
|
};
|
|
197
166
|
|
|
198
167
|
// add minWidth, minHeight if width and height are not defined
|
|
199
|
-
// minWidth, minHeight will be also in model in the future
|
|
200
168
|
return {
|
|
201
169
|
...rootStyle,
|
|
202
170
|
...(responseAreaWidth ? {} : { minWidth: 90 }),
|
|
203
171
|
...(responseAreaHeight ? {} : { minHeight: 32 }),
|
|
204
172
|
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
handleElements();
|
|
177
|
+
}, []);
|
|
178
|
+
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
if (rootRef.current) {
|
|
181
|
+
renderMath(rootRef.current);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
if (JSON.stringify(choice) !== JSON.stringify(choice)) {
|
|
187
|
+
if (!choice) {
|
|
188
|
+
setDimensions({ height: 0, width: 0 });
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
handleElements();
|
|
192
|
+
}
|
|
193
|
+
}, [choice]);
|
|
194
|
+
|
|
195
|
+
const draggedLabel = dragItem && isOver && dragItem.choice && dragItem.choice.value;
|
|
196
|
+
const label = choice && choice.value;
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<StyledChip
|
|
200
|
+
clickable={false}
|
|
201
|
+
disabled={true}
|
|
202
|
+
ref={rootRef}
|
|
203
|
+
component="span"
|
|
204
|
+
label={
|
|
205
|
+
<React.Fragment>
|
|
206
|
+
<StyledChipLabel
|
|
207
|
+
className={classnames({
|
|
208
|
+
over: isOver,
|
|
209
|
+
hidden: draggedLabel,
|
|
210
|
+
})}
|
|
211
|
+
ref={(ref) => {
|
|
212
|
+
if (ref) {
|
|
213
|
+
spanRef.current = ref;
|
|
214
|
+
ref.innerHTML = label || '';
|
|
215
|
+
addDraggableFalseAttributes(ref);
|
|
216
|
+
}
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
{' '}
|
|
220
|
+
</StyledChipLabel>
|
|
221
|
+
{draggedLabel && (
|
|
222
|
+
<StyledChipLabel
|
|
223
|
+
className={classnames({
|
|
224
|
+
over: isOver,
|
|
225
|
+
dragged: true,
|
|
227
226
|
})}
|
|
228
227
|
ref={(ref) => {
|
|
229
228
|
if (ref) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
ref.innerHTML = label || '';
|
|
233
|
-
this.addDraggableFalseAttributes(ref);
|
|
229
|
+
ref.innerHTML = draggedLabel || '';
|
|
230
|
+
addDraggableFalseAttributes(ref);
|
|
234
231
|
}
|
|
235
232
|
}}
|
|
236
233
|
>
|
|
237
234
|
{' '}
|
|
238
|
-
</
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
</React.Fragment>
|
|
255
|
-
}
|
|
256
|
-
className={classnames(classes.chip, isOver && classes.over, isOver && classes.parentOver, {
|
|
257
|
-
[classes.correct]: correct !== undefined && correct,
|
|
258
|
-
[classes.incorrect]: correct !== undefined && !correct,
|
|
259
|
-
})}
|
|
260
|
-
variant={disabled ? 'outlined' : undefined}
|
|
261
|
-
style={{
|
|
262
|
-
...this.getRootDimensions(),
|
|
263
|
-
}}
|
|
264
|
-
/>
|
|
265
|
-
);
|
|
266
|
-
}
|
|
235
|
+
</StyledChipLabel>
|
|
236
|
+
)}
|
|
237
|
+
</React.Fragment>
|
|
238
|
+
}
|
|
239
|
+
className={classnames({
|
|
240
|
+
over: isOver,
|
|
241
|
+
parentOver: isOver,
|
|
242
|
+
correct: correct !== undefined && correct,
|
|
243
|
+
incorrect: correct !== undefined && !correct,
|
|
244
|
+
})}
|
|
245
|
+
variant={disabled ? 'outlined' : undefined}
|
|
246
|
+
style={{
|
|
247
|
+
...getRootDimensions(),
|
|
248
|
+
}}
|
|
249
|
+
/>
|
|
250
|
+
);
|
|
267
251
|
}
|
|
268
252
|
|
|
269
253
|
BlankContent.defaultProps = {
|
|
@@ -276,85 +260,111 @@ BlankContent.propTypes = {
|
|
|
276
260
|
disabled: PropTypes.bool,
|
|
277
261
|
duplicates: PropTypes.bool,
|
|
278
262
|
choice: PropTypes.object,
|
|
279
|
-
classes: PropTypes.object,
|
|
280
263
|
isOver: PropTypes.bool,
|
|
281
264
|
dragItem: PropTypes.object,
|
|
282
265
|
correct: PropTypes.bool,
|
|
283
266
|
onChange: PropTypes.func,
|
|
284
267
|
emptyResponseAreaWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
285
268
|
emptyResponseAreaHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
269
|
+
instanceId: PropTypes.string,
|
|
286
270
|
};
|
|
287
271
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
272
|
+
// New functional component using @dnd-kit hooks
|
|
273
|
+
function DragDropBlank({
|
|
274
|
+
id,
|
|
275
|
+
disabled,
|
|
276
|
+
duplicates,
|
|
277
|
+
choice,
|
|
278
|
+
correct,
|
|
279
|
+
onChange,
|
|
280
|
+
emptyResponseAreaWidth,
|
|
281
|
+
emptyResponseAreaHeight,
|
|
282
|
+
instanceId
|
|
283
|
+
}) {
|
|
284
|
+
// Setup draggable functionality
|
|
285
|
+
const {
|
|
286
|
+
attributes: dragAttributes,
|
|
287
|
+
listeners: dragListeners,
|
|
288
|
+
setNodeRef: setDragNodeRef,
|
|
289
|
+
transform,
|
|
290
|
+
isDragging,
|
|
291
|
+
} = useDraggable({
|
|
292
|
+
id: `mask-blank-drag-${id}`,
|
|
293
|
+
disabled: disabled || !choice,
|
|
294
|
+
data: {
|
|
295
|
+
id: id,
|
|
296
|
+
choice: choice,
|
|
297
|
+
instanceId: instanceId,
|
|
298
|
+
fromChoice: false, // This is from a blank, not from choices
|
|
299
|
+
type: 'MaskBlank',
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// Setup droppable functionality
|
|
304
|
+
const {
|
|
305
|
+
setNodeRef: setDropNodeRef,
|
|
306
|
+
isOver,
|
|
307
|
+
active: dragItem,
|
|
308
|
+
} = useDroppable({
|
|
309
|
+
id: `mask-blank-drop-${id}`,
|
|
310
|
+
data: {
|
|
311
|
+
id: id,
|
|
312
|
+
accepts: ['MaskBlank'],
|
|
313
|
+
instanceId: instanceId,
|
|
314
|
+
},
|
|
315
|
+
});
|
|
305
316
|
|
|
306
|
-
|
|
317
|
+
// Combine refs for both drag and drop
|
|
318
|
+
const setNodeRef = (node) => {
|
|
319
|
+
setDragNodeRef(node);
|
|
320
|
+
setDropNodeRef(node);
|
|
321
|
+
};
|
|
307
322
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
323
|
+
const style = {
|
|
324
|
+
transform: CSS.Translate.toString(transform),
|
|
325
|
+
opacity: isDragging ? 0.5 : 1,
|
|
326
|
+
};
|
|
311
327
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
328
|
+
return (
|
|
329
|
+
<StyledContent
|
|
330
|
+
ref={setNodeRef}
|
|
331
|
+
style={style}
|
|
332
|
+
className={isOver ? 'over' : ''}
|
|
333
|
+
{...dragAttributes}
|
|
334
|
+
{...dragListeners}
|
|
335
|
+
>
|
|
336
|
+
<BlankContent
|
|
337
|
+
id={id}
|
|
338
|
+
disabled={disabled}
|
|
339
|
+
duplicates={duplicates}
|
|
340
|
+
choice={choice}
|
|
341
|
+
isOver={isOver}
|
|
342
|
+
dragItem={dragItem?.data?.current}
|
|
343
|
+
correct={correct}
|
|
344
|
+
onChange={onChange}
|
|
345
|
+
emptyResponseAreaWidth={emptyResponseAreaWidth}
|
|
346
|
+
emptyResponseAreaHeight={emptyResponseAreaHeight}
|
|
347
|
+
instanceId={instanceId}
|
|
348
|
+
/>
|
|
349
|
+
</StyledContent>
|
|
350
|
+
);
|
|
351
|
+
}
|
|
318
352
|
|
|
319
|
-
|
|
320
|
-
|
|
353
|
+
DragDropBlank.defaultProps = {
|
|
354
|
+
emptyResponseAreaWidth: 0,
|
|
355
|
+
emptyResponseAreaHeight: 0,
|
|
321
356
|
};
|
|
322
357
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
beginDrag(props) {
|
|
334
|
-
return {
|
|
335
|
-
id: props.id,
|
|
336
|
-
choice: props.choice,
|
|
337
|
-
instanceId: props.instanceId,
|
|
338
|
-
fromChoice: true,
|
|
339
|
-
};
|
|
340
|
-
},
|
|
341
|
-
endDrag(props, monitor) {
|
|
342
|
-
// this will be null if it did not drop
|
|
343
|
-
const dropResult = monitor.getDropResult();
|
|
344
|
-
|
|
345
|
-
if (!dropResult || dropResult.dropped) {
|
|
346
|
-
const draggedItem = monitor.getItem();
|
|
347
|
-
|
|
348
|
-
if (draggedItem.fromChoice) {
|
|
349
|
-
props.onChange(props.id, undefined);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
},
|
|
358
|
+
DragDropBlank.propTypes = {
|
|
359
|
+
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
360
|
+
disabled: PropTypes.bool,
|
|
361
|
+
duplicates: PropTypes.bool,
|
|
362
|
+
choice: PropTypes.object,
|
|
363
|
+
correct: PropTypes.bool,
|
|
364
|
+
onChange: PropTypes.func,
|
|
365
|
+
emptyResponseAreaWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
366
|
+
emptyResponseAreaHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
367
|
+
instanceId: PropTypes.string,
|
|
353
368
|
};
|
|
354
369
|
|
|
355
|
-
|
|
356
|
-
connectDragSource: connect.dragSource(),
|
|
357
|
-
isDragging: monitor.isDragging(),
|
|
358
|
-
}))(DropTile);
|
|
359
|
-
|
|
360
|
-
export default DragDropTile;
|
|
370
|
+
export default DragDropBlank;
|