@pie-element/image-cloze-association 3.6.0 → 3.6.3-next.1014
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 +187 -0
- package/configure/CHANGELOG.md +128 -0
- package/configure/lib/defaults.js +11 -0
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/index.js +3 -3
- package/configure/lib/root.js +20 -7
- package/configure/lib/root.js.map +1 -1
- package/configure/package.json +2 -2
- package/configure/src/defaults.js +12 -1
- package/configure/src/root.jsx +34 -21
- package/controller/CHANGELOG.md +41 -0
- package/controller/lib/index.js +4 -3
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +3 -3
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +1 -1
- package/controller/src/utils.js +1 -2
- package/docs/config-schema.json +79 -0
- package/docs/config-schema.json.md +61 -1
- package/docs/pie-schema.json +28 -1
- package/docs/pie-schema.json.md +20 -0
- package/lib/image-container.js +7 -3
- package/lib/image-container.js.map +1 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/interactive-section.js +1 -1
- package/lib/interactive-section.js.map +1 -1
- package/lib/possible-response.js +11 -4
- package/lib/possible-response.js.map +1 -1
- package/lib/root.js +63 -14
- package/lib/root.js.map +1 -1
- package/lib/utils-correctness.js +31 -3
- package/lib/utils-correctness.js.map +1 -1
- package/package.json +6 -4
- package/src/__tests__/__snapshots__/root.test.jsx.snap +6 -0
- package/src/index.js +5 -0
- package/src/possible-response.jsx +12 -3
- package/src/root.jsx +78 -29
- package/src/utils-correctness.js +22 -0
package/src/root.jsx
CHANGED
|
@@ -6,11 +6,12 @@ import { CSSTransition, TransitionGroup } from 'react-transition-group';
|
|
|
6
6
|
import { ShowRationale } from '@pie-lib/icons';
|
|
7
7
|
import { Collapsible, PreviewPrompt } from '@pie-lib/render-ui';
|
|
8
8
|
import { withStyles } from '@material-ui/core/styles';
|
|
9
|
+
import CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';
|
|
9
10
|
|
|
10
11
|
import Image from './image-container';
|
|
11
12
|
import InteractiveSection from './interactive-section';
|
|
12
13
|
import PossibleResponses from './possible-responses';
|
|
13
|
-
import { getAnswersCorrectness } from './utils-correctness';
|
|
14
|
+
import { getUnansweredAnswers, getAnswersCorrectness } from './utils-correctness';
|
|
14
15
|
import _ from 'lodash';
|
|
15
16
|
|
|
16
17
|
const generateId = () =>
|
|
@@ -64,6 +65,7 @@ class ImageClozeAssociationComponent extends React.Component {
|
|
|
64
65
|
id: `${index}`,
|
|
65
66
|
})),
|
|
66
67
|
maxResponsePerZone: maxResponsePerZone || 1,
|
|
68
|
+
showCorrect: false
|
|
67
69
|
};
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -200,6 +202,8 @@ class ImageClozeAssociationComponent extends React.Component {
|
|
|
200
202
|
updateAnswer(answersToStore);
|
|
201
203
|
};
|
|
202
204
|
|
|
205
|
+
toggleCorrect = showCorrect => this.setState({ showCorrect });
|
|
206
|
+
|
|
203
207
|
render() {
|
|
204
208
|
const {
|
|
205
209
|
model: {
|
|
@@ -212,6 +216,7 @@ class ImageClozeAssociationComponent extends React.Component {
|
|
|
212
216
|
teacherInstructions,
|
|
213
217
|
prompt,
|
|
214
218
|
showDashedBorder,
|
|
219
|
+
mode,
|
|
215
220
|
},
|
|
216
221
|
} = this.props;
|
|
217
222
|
const {
|
|
@@ -221,17 +226,38 @@ class ImageClozeAssociationComponent extends React.Component {
|
|
|
221
226
|
responseContainers,
|
|
222
227
|
maxResponsePerZone,
|
|
223
228
|
maxResponsePerZoneWarning,
|
|
229
|
+
showCorrect
|
|
224
230
|
} = this.state;
|
|
231
|
+
const isEvaluateMode = mode === 'evaluate';
|
|
232
|
+
const showToggle = isEvaluateMode && !responseCorrect;
|
|
233
|
+
|
|
234
|
+
const { validResponse } = validation || {};
|
|
235
|
+
const correctAnswers = [];
|
|
236
|
+
|
|
237
|
+
if (validResponse) {
|
|
238
|
+
(validResponse.value || []).forEach((container, i) => {
|
|
239
|
+
(container.images || []).forEach(v => {
|
|
240
|
+
correctAnswers.push({
|
|
241
|
+
value: v,
|
|
242
|
+
containerIndex: i
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
}
|
|
225
247
|
|
|
226
248
|
const warningMessage =
|
|
227
249
|
`You’ve reached the limit of ${maxResponsePerZone} responses per area.` +
|
|
228
250
|
'To add another response, one must first be removed.';
|
|
229
251
|
|
|
230
|
-
|
|
252
|
+
let answersToShow =
|
|
231
253
|
responseCorrect !== undefined
|
|
232
254
|
? getAnswersCorrectness(answers, validation, duplicateResponses)
|
|
233
255
|
: answers;
|
|
234
256
|
|
|
257
|
+
if (responseCorrect === false && maxResponsePerZone === 1) {
|
|
258
|
+
answersToShow = [...answersToShow, ...getUnansweredAnswers(answersToShow, validation)];
|
|
259
|
+
}
|
|
260
|
+
|
|
235
261
|
return (
|
|
236
262
|
<div>
|
|
237
263
|
<PreviewPrompt className="prompt" prompt={prompt} />
|
|
@@ -243,7 +269,7 @@ class ImageClozeAssociationComponent extends React.Component {
|
|
|
243
269
|
visible: 'Hide Teacher Instructions',
|
|
244
270
|
}}
|
|
245
271
|
>
|
|
246
|
-
<
|
|
272
|
+
<PreviewPrompt prompt={teacherInstructions} />
|
|
247
273
|
</Collapsible>
|
|
248
274
|
)}
|
|
249
275
|
|
|
@@ -251,32 +277,55 @@ class ImageClozeAssociationComponent extends React.Component {
|
|
|
251
277
|
<span dangerouslySetInnerHTML={{ __html: stimulus }} />
|
|
252
278
|
</Typography>
|
|
253
279
|
|
|
254
|
-
<
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
+
<CorrectAnswerToggle
|
|
281
|
+
show={showToggle}
|
|
282
|
+
toggled={showCorrect}
|
|
283
|
+
onToggle={this.toggleCorrect}
|
|
284
|
+
/>
|
|
285
|
+
<br/>
|
|
286
|
+
|
|
287
|
+
{(showCorrect && showToggle) ? (
|
|
288
|
+
<InteractiveSection responseCorrect={true}>
|
|
289
|
+
<Image
|
|
290
|
+
canDrag={false}
|
|
291
|
+
answers={correctAnswers}
|
|
292
|
+
draggingElement={draggingElement}
|
|
293
|
+
duplicateResponses={duplicateResponses}
|
|
294
|
+
image={image}
|
|
295
|
+
onAnswerSelect={this.handleOnAnswerSelect}
|
|
296
|
+
onDragAnswerBegin={this.beginDrag}
|
|
297
|
+
onDragAnswerEnd={this.handleOnDragEnd}
|
|
298
|
+
responseContainers={responseContainers}
|
|
299
|
+
showDashedBorder={showDashedBorder}
|
|
300
|
+
/>
|
|
301
|
+
</InteractiveSection>
|
|
302
|
+
) : (
|
|
303
|
+
<InteractiveSection responseCorrect={responseCorrect}>
|
|
304
|
+
<Image
|
|
305
|
+
canDrag={!disabled}
|
|
306
|
+
answers={answersToShow}
|
|
307
|
+
draggingElement={draggingElement}
|
|
308
|
+
duplicateResponses={duplicateResponses}
|
|
309
|
+
image={image}
|
|
310
|
+
onAnswerSelect={this.handleOnAnswerSelect}
|
|
311
|
+
onDragAnswerBegin={this.beginDrag}
|
|
312
|
+
onDragAnswerEnd={this.handleOnDragEnd}
|
|
313
|
+
responseContainers={responseContainers}
|
|
314
|
+
showDashedBorder={showDashedBorder}
|
|
315
|
+
/>
|
|
316
|
+
|
|
317
|
+
{maxResponsePerZoneWarning && (
|
|
318
|
+
<WarningInfo message={warningMessage}/>
|
|
319
|
+
)}
|
|
320
|
+
|
|
321
|
+
<PossibleResponses
|
|
322
|
+
canDrag={!disabled}
|
|
323
|
+
data={possibleResponses}
|
|
324
|
+
onAnswerRemove={this.handleOnAnswerRemove}
|
|
325
|
+
onDragBegin={this.beginDrag}
|
|
326
|
+
onDragEnd={this.handleOnDragEnd}
|
|
327
|
+
/>
|
|
328
|
+
</InteractiveSection>)}
|
|
280
329
|
</div>
|
|
281
330
|
);
|
|
282
331
|
}
|
package/src/utils-correctness.js
CHANGED
|
@@ -35,6 +35,28 @@ const getUniqueCorrectAnswers = (answers, validResponses) => {
|
|
|
35
35
|
return finalAnswers;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
export const getUnansweredAnswers = (answers, validation) => {
|
|
39
|
+
const { validResponse: { value } = {}} = validation;
|
|
40
|
+
|
|
41
|
+
const unansweredAnswers = (value || []).reduce((unanswered, response, index) => {
|
|
42
|
+
const isAnswered = !!answers.find(answer => answer.containerIndex === index);
|
|
43
|
+
|
|
44
|
+
if (!isAnswered) {
|
|
45
|
+
return [...unanswered, {
|
|
46
|
+
id: `unanswered-${index}`,
|
|
47
|
+
value: response.images[0] || '',
|
|
48
|
+
containerIndex: index,
|
|
49
|
+
isCorrect: false,
|
|
50
|
+
hidden: true
|
|
51
|
+
}];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return unanswered;
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
57
|
+
return unansweredAnswers;
|
|
58
|
+
};
|
|
59
|
+
|
|
38
60
|
export const getAnswersCorrectness = (answers, validation) => {
|
|
39
61
|
const { validResponse: { value }, altResponses } = validation;
|
|
40
62
|
|