@pie-element/image-cloze-association 3.6.2 → 3.6.3-next.1016

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 (45) hide show
  1. package/CHANGELOG.md +176 -0
  2. package/configure/CHANGELOG.md +117 -0
  3. package/configure/lib/defaults.js +11 -0
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/index.js +3 -3
  6. package/configure/lib/root.js +20 -7
  7. package/configure/lib/root.js.map +1 -1
  8. package/configure/package.json +2 -2
  9. package/configure/src/defaults.js +12 -1
  10. package/configure/src/root.jsx +34 -21
  11. package/controller/CHANGELOG.md +30 -0
  12. package/controller/lib/index.js +4 -3
  13. package/controller/lib/index.js.map +1 -1
  14. package/controller/lib/utils.js +3 -3
  15. package/controller/lib/utils.js.map +1 -1
  16. package/controller/package.json +1 -1
  17. package/controller/src/utils.js +1 -2
  18. package/docs/config-schema.json +79 -0
  19. package/docs/config-schema.json.md +61 -1
  20. package/docs/pie-schema.json +28 -1
  21. package/docs/pie-schema.json.md +20 -0
  22. package/lib/image-container.js +7 -3
  23. package/lib/image-container.js.map +1 -1
  24. package/lib/index.js +4 -1
  25. package/lib/index.js.map +1 -1
  26. package/lib/interactive-section.js +1 -1
  27. package/lib/interactive-section.js.map +1 -1
  28. package/lib/possible-response.js +11 -4
  29. package/lib/possible-response.js.map +1 -1
  30. package/lib/root.js +63 -14
  31. package/lib/root.js.map +1 -1
  32. package/lib/utils-correctness.js +31 -3
  33. package/lib/utils-correctness.js.map +1 -1
  34. package/package.json +6 -4
  35. package/src/__tests__/__snapshots__/root.test.jsx.snap +6 -0
  36. package/src/index.js +5 -0
  37. package/src/possible-response.jsx +12 -3
  38. package/src/root.jsx +78 -29
  39. package/src/utils-correctness.js +22 -0
  40. package/module/configure.js +0 -529
  41. package/module/controller.js +0 -18992
  42. package/module/demo.js +0 -93
  43. package/module/element.js +0 -1021
  44. package/module/index.html +0 -16
  45. package/module/manifest.json +0 -10
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
- const answersToShow =
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
- <div dangerouslySetInnerHTML={{ __html: teacherInstructions }} />
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
- <InteractiveSection responseCorrect={responseCorrect}>
255
- <Image
256
- canDrag={!disabled}
257
- answers={answersToShow}
258
- draggingElement={draggingElement}
259
- duplicateResponses={duplicateResponses}
260
- image={image}
261
- onAnswerSelect={this.handleOnAnswerSelect}
262
- onDragAnswerBegin={this.beginDrag}
263
- onDragAnswerEnd={this.handleOnDragEnd}
264
- responseContainers={responseContainers}
265
- showDashedBorder={showDashedBorder}
266
- />
267
-
268
- {maxResponsePerZoneWarning && (
269
- <WarningInfo message={warningMessage} />
270
- )}
271
-
272
- <PossibleResponses
273
- canDrag={!disabled}
274
- data={possibleResponses}
275
- onAnswerRemove={this.handleOnAnswerRemove}
276
- onDragBegin={this.beginDrag}
277
- onDragEnd={this.handleOnDragEnd}
278
- />
279
- </InteractiveSection>
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
  }
@@ -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