@pie-element/placement-ordering 7.7.9 → 7.8.1-beta.1443

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 (43) hide show
  1. package/CHANGELOG.md +374 -0
  2. package/README.md +1 -1
  3. package/configure/CHANGELOG.md +356 -0
  4. package/configure/lib/choice-editor.js +73 -65
  5. package/configure/lib/choice-editor.js.map +1 -1
  6. package/configure/lib/choice-tile.js +44 -48
  7. package/configure/lib/choice-tile.js.map +1 -1
  8. package/configure/lib/defaults.js +23 -0
  9. package/configure/lib/defaults.js.map +1 -1
  10. package/configure/lib/design.js +204 -94
  11. package/configure/lib/design.js.map +1 -1
  12. package/configure/lib/help.js.map +1 -1
  13. package/configure/lib/index.js +16 -2
  14. package/configure/lib/index.js.map +1 -1
  15. package/configure/lib/utils.js +14 -0
  16. package/configure/lib/utils.js.map +1 -0
  17. package/configure/package.json +6 -6
  18. package/controller/CHANGELOG.md +57 -0
  19. package/controller/lib/defaults.js.map +1 -1
  20. package/controller/lib/index.js +67 -16
  21. package/controller/lib/index.js.map +1 -1
  22. package/controller/lib/scoring.js +3 -3
  23. package/controller/lib/scoring.js.map +1 -1
  24. package/controller/package.json +3 -3
  25. package/docs/config-schema.json +145 -0
  26. package/docs/config-schema.json.md +113 -1
  27. package/docs/demo/config.js +2 -2
  28. package/docs/demo/generate.js +9 -10
  29. package/docs/demo/index.html +1 -2
  30. package/docs/demo/session.js +1 -1
  31. package/docs/pie-schema.json +48 -0
  32. package/docs/pie-schema.json.md +36 -0
  33. package/lib/index.js +4 -1
  34. package/lib/index.js.map +1 -1
  35. package/lib/main.js.map +1 -1
  36. package/lib/ordering.js +2 -1
  37. package/lib/ordering.js.map +1 -1
  38. package/lib/placement-ordering.js +73 -30
  39. package/lib/placement-ordering.js.map +1 -1
  40. package/lib/tile.js.map +1 -1
  41. package/lib/tiler.js +2 -2
  42. package/lib/tiler.js.map +1 -1
  43. package/package.json +7 -7
@@ -134,6 +134,18 @@ Indicates if the item has to be displayed in the Settings Panel
134
134
 
135
135
  Indicates the label for the item that has to be displayed in the Settings Panel
136
136
 
137
+ # `spellCheck` (object)
138
+
139
+ Properties of the `spellCheck` object:
140
+
141
+ ## `settings` (boolean)
142
+
143
+ Indicates if the item has to be displayed in the Settings Panel
144
+
145
+ ## `label` (string)
146
+
147
+ Indicates the label for the item that has to be displayed in the Settings Panel
148
+
137
149
  # `removeTilesAfterPlacing` (object)
138
150
 
139
151
  Properties of the `removeTilesAfterPlacing` object:
@@ -146,6 +158,10 @@ Indicates if the item has to be displayed in the Settings Panel
146
158
 
147
159
  Indicates the label for the item that has to be displayed in the Settings Panel
148
160
 
161
+ # `settingsPanelDisabled` (boolean)
162
+
163
+ Indicates if the settings panel is not available
164
+
149
165
  # `scoringType` (object)
150
166
 
151
167
  Properties of the `scoringType` object:
@@ -194,6 +210,74 @@ Indicates if the item has to be displayed in the Settings Panel
194
210
 
195
211
  Indicates the label for the item that has to be displayed in the Settings Panel
196
212
 
213
+ # `maxImageWidth` (object)
214
+
215
+ Properties of the `maxImageWidth` object:
216
+
217
+ ## `teacherInstructions` (number)
218
+
219
+ Indicates the max dimension for images in teacher instructions
220
+
221
+ ## `prompt` (number)
222
+
223
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
224
+
225
+ ## `rationale` (number)
226
+
227
+ Indicates the max dimension for images in rationale
228
+
229
+ ## `choicesWithPlacementArea` (number)
230
+
231
+ Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled
232
+
233
+ ## `choicesWithoutPlacementArea` (number)
234
+
235
+ Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled
236
+
237
+ ## `choices` (number)
238
+
239
+ Only available for the height prop: indicates the max height for images in choices and choices labels
240
+
241
+ # `maxImageHeight` (object)
242
+
243
+ Properties of the `maxImageHeight` object:
244
+
245
+ ## `teacherInstructions` (number)
246
+
247
+ Indicates the max dimension for images in teacher instructions
248
+
249
+ ## `prompt` (number)
250
+
251
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
252
+
253
+ ## `rationale` (number)
254
+
255
+ Indicates the max dimension for images in rationale
256
+
257
+ ## `choicesWithPlacementArea` (number)
258
+
259
+ Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled
260
+
261
+ ## `choicesWithoutPlacementArea` (number)
262
+
263
+ Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled
264
+
265
+ ## `choices` (number)
266
+
267
+ Only available for the height prop: indicates the max height for images in choices and choices labels
268
+
269
+ # `withRubric` (object)
270
+
271
+ Properties of the `withRubric` object:
272
+
273
+ ## `settings` (boolean)
274
+
275
+ Indicates if the item has to be displayed in the Settings Panel
276
+
277
+ ## `label` (string)
278
+
279
+ Indicates the label for the item that has to be displayed in the Settings Panel
280
+
197
281
  # `showPrompt` (boolean)
198
282
 
199
283
  Determines whether prompt field will be displayed or not
@@ -228,4 +312,32 @@ Indicates if the item has to be displayed in the Settings Panel
228
312
 
229
313
  ### `label` (string)
230
314
 
231
- Indicates the label for the item that has to be displayed in the Settings Panel
315
+ Indicates the label for the item that has to be displayed in the Settings Panel
316
+
317
+ ## `ConfigureMaxImageDimensionsProp` (object)
318
+
319
+ Properties of the `ConfigureMaxImageDimensionsProp` object:
320
+
321
+ ### `teacherInstructions` (number)
322
+
323
+ Indicates the max dimension for images in teacher instructions
324
+
325
+ ### `prompt` (number)
326
+
327
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
328
+
329
+ ### `rationale` (number)
330
+
331
+ Indicates the max dimension for images in rationale
332
+
333
+ ### `choicesWithPlacementArea` (number)
334
+
335
+ Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled
336
+
337
+ ### `choicesWithoutPlacementArea` (number)
338
+
339
+ Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled
340
+
341
+ ### `choices` (number)
342
+
343
+ Only available for the height prop: indicates the max height for images in choices and choices labels
@@ -2,7 +2,7 @@ const { model } = require('./generate');
2
2
 
3
3
  module.exports = {
4
4
  elements: {
5
- 'placement-ordering': '../..'
5
+ 'placement-ordering': '../..',
6
6
  },
7
- models: [model('1', 'placement-ordering')]
7
+ models: [model('1', 'placement-ordering')],
8
8
  };
@@ -9,7 +9,7 @@ exports.model = (id, element) => ({
9
9
  },
10
10
  {
11
11
  id: 'c2',
12
- label: 'Lemon'
12
+ label: 'Lemon',
13
13
  },
14
14
  {
15
15
  id: 'c3',
@@ -21,23 +21,21 @@ exports.model = (id, element) => ({
21
21
  },
22
22
  ],
23
23
  correctResponse: ['c1', 'c2', 'c3', 'c4'],
24
- alternateResponses: [
25
- { response: ['c4', 'c3', 'c2', 'c1'] },
26
- ],
24
+ alternateResponses: [{ response: ['c4', 'c3', 'c2', 'c1'] }],
27
25
  enableImages: false,
28
26
  feedback: {
29
27
  correct: {
30
28
  type: 'custom',
31
- custom: 'foo'
29
+ custom: 'foo',
32
30
  },
33
31
  incorrect: {
34
32
  type: 'custom',
35
- custom: 'no'
33
+ custom: 'no',
36
34
  },
37
35
  partial: {
38
36
  type: 'custom',
39
- custom: 'nearly'
40
- }
37
+ custom: 'nearly',
38
+ },
41
39
  },
42
40
  feedbackEnabled: true,
43
41
  prompt: 'Arrange the fruits alphabetically',
@@ -46,8 +44,9 @@ exports.model = (id, element) => ({
46
44
  numberedGuides: false,
47
45
  orientation: 'vertical',
48
46
  partialScoring: false,
49
- placementArea: true,
47
+ placementArea: false,
50
48
  scoringType: 'auto',
51
49
  targetLabel: 'Answers',
52
- toolbarEditorPosition: 'bottom'
50
+ toolbarEditorPosition: 'bottom',
51
+ rubricEnabled: false,
53
52
  });
@@ -1,2 +1 @@
1
- <placement-ordering pie-id="1"></placement-ordering>
2
- <placement-ordering pie-id="2"></placement-ordering>
1
+ <placement-ordering pie-id="1"></placement-ordering> <placement-ordering pie-id="2"></placement-ordering>
@@ -2,6 +2,6 @@ module.exports = [
2
2
  {
3
3
  id: '1',
4
4
  element: 'placement-ordering',
5
- value: [undefined, 'c1', 'c2', undefined]
5
+ value: ['c3', 'c1', 'c2', undefined]
6
6
  }
7
7
  ];
@@ -347,6 +347,11 @@
347
347
  "type": "boolean",
348
348
  "title": "choiceLabelEnabled"
349
349
  },
350
+ "spellCheckEnabled": {
351
+ "description": "Indicates if spellcheck is enabled for the author. Default value is true",
352
+ "type": "boolean",
353
+ "title": "spellCheckEnabled"
354
+ },
350
355
  "note": {
351
356
  "description": "Indicates the note for the answer",
352
357
  "type": "string",
@@ -362,6 +367,11 @@
362
367
  "type": "string",
363
368
  "title": "toolbarEditorPosition"
364
369
  },
370
+ "rubricEnabled": {
371
+ "description": "Indicates if Rubric is enabled",
372
+ "type": "boolean",
373
+ "title": "rubricEnabled"
374
+ },
365
375
  "id": {
366
376
  "description": "Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.",
367
377
  "type": "string",
@@ -380,6 +390,8 @@
380
390
  "feedbackEnabled",
381
391
  "id",
382
392
  "rationaleEnabled",
393
+ "rubricEnabled",
394
+ "spellCheckEnabled",
383
395
  "studentInstructionsEnabled",
384
396
  "teacherInstructionsEnabled"
385
397
  ],
@@ -400,6 +412,42 @@
400
412
  }
401
413
  }
402
414
  },
415
+ "ConfigureMaxImageDimensionsProp": {
416
+ "title": "ConfigureMaxImageDimensionsProp",
417
+ "type": "object",
418
+ "properties": {
419
+ "teacherInstructions": {
420
+ "description": "Indicates the max dimension for images in teacher instructions",
421
+ "type": "number",
422
+ "title": "teacherInstructions"
423
+ },
424
+ "prompt": {
425
+ "description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
426
+ "type": "number",
427
+ "title": "prompt"
428
+ },
429
+ "rationale": {
430
+ "description": "Indicates the max dimension for images in rationale",
431
+ "type": "number",
432
+ "title": "rationale"
433
+ },
434
+ "choicesWithPlacementArea": {
435
+ "description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled",
436
+ "type": "number",
437
+ "title": "choicesWithPlacementArea"
438
+ },
439
+ "choicesWithoutPlacementArea": {
440
+ "description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled",
441
+ "type": "number",
442
+ "title": "choicesWithoutPlacementArea"
443
+ },
444
+ "choices": {
445
+ "description": "Only available for the height prop: indicates the max height for images in choices and choices labels",
446
+ "type": "number",
447
+ "title": "choices"
448
+ }
449
+ }
450
+ },
403
451
  "Choice": {
404
452
  "title": "Choice",
405
453
  "type": "object",
@@ -155,6 +155,10 @@ Indicates if Teacher Instructions are enabled
155
155
 
156
156
  Indicates if Choice Label is enabled
157
157
 
158
+ # `spellCheckEnabled` (boolean, required)
159
+
160
+ Indicates if spellcheck is enabled for the author. Default value is true
161
+
158
162
  # `note` (string)
159
163
 
160
164
  Indicates the note for the answer
@@ -170,6 +174,10 @@ This element must be one of the following enum values:
170
174
 
171
175
  Default: `": 'bottom'"`
172
176
 
177
+ # `rubricEnabled` (boolean, required)
178
+
179
+ Indicates if Rubric is enabled
180
+
173
181
  # `id` (string, required)
174
182
 
175
183
  Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.
@@ -196,6 +204,34 @@ Indicates if the item has to be displayed in the Settings Panel
196
204
 
197
205
  Indicates the label for the item that has to be displayed in the Settings Panel
198
206
 
207
+ ## `ConfigureMaxImageDimensionsProp` (object)
208
+
209
+ Properties of the `ConfigureMaxImageDimensionsProp` object:
210
+
211
+ ### `teacherInstructions` (number)
212
+
213
+ Indicates the max dimension for images in teacher instructions
214
+
215
+ ### `prompt` (number)
216
+
217
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
218
+
219
+ ### `rationale` (number)
220
+
221
+ Indicates the max dimension for images in rationale
222
+
223
+ ### `choicesWithPlacementArea` (number)
224
+
225
+ Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled
226
+
227
+ ### `choicesWithoutPlacementArea` (number)
228
+
229
+ Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled
230
+
231
+ ### `choices` (number)
232
+
233
+ Only available for the height prop: indicates the max height for images in choices and choices labels
234
+
199
235
  ## `Choice` (object)
200
236
 
201
237
  Properties of the `Choice` object:
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports["default"] = void 0;
8
9
  Object.defineProperty(exports, "swap", {
9
10
  enumerable: true,
10
11
  get: function get() {
@@ -17,7 +18,6 @@ Object.defineProperty(exports, "withDragContext", {
17
18
  return _drag.withDragContext;
18
19
  }
19
20
  });
20
- exports["default"] = void 0;
21
21
 
22
22
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
23
23
 
@@ -116,6 +116,9 @@ var Ordering = /*#__PURE__*/function (_HTMLElement) {
116
116
  }
117
117
  }, {
118
118
  key: "session",
119
+ get: function get() {
120
+ return this._session;
121
+ },
119
122
  set: function set(newSession) {
120
123
  this._session = newSession;
121
124
  this.render();
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","Ordering","sessionChange","bind","_model","_session","element","React","createElement","Main","model","session","onSessionChange","ReactDOM","render","value","dispatchEvent","CustomEvent","bubbles","detail","component","tagName","toLowerCase","complete","length","completeLength","newModel","newSession","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,iCAAN,CAAZ;;IAIqBC,Q;;;;;AACnB,sBAAc;AAAA;;AAAA;AACZ;AACA,UAAKC,aAAL,GAAqB,MAAKA,aAAL,CAAmBC,IAAnB,gDAArB;AAFY;AAGb;;;;WAED,kBAAS;AAAA;;AACP,UAAI,KAAKC,MAAL,IAAe,KAAKC,QAAxB,EAAkC;AAChCL,QAAAA,GAAG,CAAC,oBAAD,EAAuB,KAAKK,Q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main from './main';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport compact from 'lodash/compact';\nimport debug from 'debug';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { swap } from './ordering';\nimport { withDragContext } from '@pie-lib/drag';\nconst log = debug('pie-elements:placement-ordering');\n\nexport { withDragContext, swap };\n\nexport default class Ordering extends HTMLElement {\n constructor() {\n super();\n this.sessionChange = this.sessionChange.bind(this);\n }\n\n render() {\n if (this._model && this._session) {\n log('[render] session: ', this._session);\n log('[render] model: ', this._model);\n\n const element = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onSessionChange: this.sessionChange\n });\n\n ReactDOM.render(element, this, () => {\n renderMath(this);\n });\n }\n }\n\n sessionChange(session) {\n this._session.value = session.value;\n this.render();\n this.dispatchEvent(\n new CustomEvent('session-changed', {\n bubbles: true,\n detail: {\n component: this.tagName.toLowerCase(),\n complete:\n this._session &&\n this._session.value &&\n compact(this._session.value).length === this._model.completeLength\n }\n })\n );\n }\n\n set model(newModel) {\n this._model = newModel;\n this.render();\n this.dispatchEvent(\n new CustomEvent('model-set', {\n bubbles: true,\n detail: {\n complete: false\n }\n })\n );\n }\n\n set session(newSession) {\n this._session = newSession;\n this.render();\n }\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","Ordering","sessionChange","bind","_model","_session","element","React","createElement","Main","model","session","onSessionChange","ReactDOM","render","value","dispatchEvent","CustomEvent","bubbles","detail","component","tagName","toLowerCase","complete","length","completeLength","newModel","newSession","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,iCAAN,CAAZ;;IAIqBC,Q;;;;;AACnB,sBAAc;AAAA;;AAAA;AACZ;AACA,UAAKC,aAAL,GAAqB,MAAKA,aAAL,CAAmBC,IAAnB,gDAArB;AAFY;AAGb;;;;WAED,kBAAS;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;SAOD,eAAc;AACZ,aAAO,KAAKlB,QAAZ;AACD,K;SAPD,aAAYsB,UAAZ,EAAwB;AACtB,WAAKtB,QAAL,GAAgBsB,UAAhB;AACA,WAAKb,MAAL;AACD;;;kDAtDmCc,W","sourcesContent":["import Main from './main';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport compact from 'lodash/compact';\nimport debug from 'debug';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { swap } from './ordering';\nimport { withDragContext } from '@pie-lib/drag';\nconst log = debug('pie-elements:placement-ordering');\n\nexport { withDragContext, swap };\n\nexport default class Ordering extends HTMLElement {\n constructor() {\n super();\n this.sessionChange = this.sessionChange.bind(this);\n }\n\n render() {\n if (this._model && this._session) {\n log('[render] session: ', this._session);\n log('[render] model: ', this._model);\n\n const element = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onSessionChange: this.sessionChange,\n });\n\n ReactDOM.render(element, this, () => {\n renderMath(this);\n });\n }\n }\n\n sessionChange(session) {\n this._session.value = session.value;\n this.render();\n this.dispatchEvent(\n new CustomEvent('session-changed', {\n bubbles: true,\n detail: {\n component: this.tagName.toLowerCase(),\n complete:\n this._session && this._session.value && compact(this._session.value).length === this._model.completeLength,\n },\n }),\n );\n }\n\n set model(newModel) {\n this._model = newModel;\n this.render();\n this.dispatchEvent(\n new CustomEvent('model-set', {\n bubbles: true,\n detail: {\n complete: false,\n },\n }),\n );\n }\n\n set session(newSession) {\n this._session = newSession;\n this.render();\n }\n\n get session() {\n return this._session;\n }\n}\n"],"file":"index.js"}
package/lib/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/main.jsx"],"names":["Main","props","model","session","onSessionChange","React","Component","PropTypes","object","isRequired","oneOfType","array","func","out"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;IAEMA,I;;;;;;;;;;;;WAUJ,kBAAS;AACP,wBAA4C,KAAKC,KAAjD;AAAA,UAAQC,KAAR,eAAQA,KAAR;AAAA,UAAeC,OAAf,eAAeA,OAAf;AAAA,UAAwBC,eAAxB,eAAwBA,eAAxB;AACA,0BACE,gCAAC,6BAAD;AACE,QAAA,KAAK,EAAEF,KADT;AAEE,QAAA,OAAO,EAAEC,OAFX;AAGE,QAAA,eAAe,EAAEC;AAHnB,QADF;AAOD;;;EAnBgBC,kBAAMC,S;;iCAAnBN,I,eACe;AACjBE,EAAAA,KAAK,EAAEK,sBAAUC,MAAV,CAAiBC,UADP;AAEjBN,EAAAA,OAAO,EAAEI,sBAAUG,SAAV,CAAoB,CAC3BH,sBAAUI,KAAV,CAAgBF,UADW,EAE3BF,sBAAUC,MAAV,CAAiBC,UAFU,CAApB,CAFQ;AAMjBL,EAAAA,eAAe,EAAEG,sBAAUK,IAAV,CAAeH;AANf,C;AAoBrB,IAAMI,GAAG,GAAG,2BAAgBb,IAAhB,CAAZ;eACea,G","sourcesContent":["import PlacementOrdering from './placement-ordering';\nimport React from 'react';\nimport { withDragContext } from '@pie-lib/drag';\n\nimport PropTypes from 'prop-types';\n\nclass Main extends React.Component {\n static propTypes = {\n model: PropTypes.object.isRequired,\n session: PropTypes.oneOfType([\n PropTypes.array.isRequired,\n PropTypes.object.isRequired\n ]),\n onSessionChange: PropTypes.func.isRequired\n };\n\n render() {\n const { model, session, onSessionChange } = this.props;\n return (\n <PlacementOrdering\n model={model}\n session={session}\n onSessionChange={onSessionChange}\n />\n );\n }\n}\nconst out = withDragContext(Main);\nexport default out;\n"],"file":"main.js"}
1
+ {"version":3,"sources":["../src/main.jsx"],"names":["Main","props","model","session","onSessionChange","React","Component","PropTypes","object","isRequired","oneOfType","array","func","out"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;IAEMA,I;;;;;;;;;;;;WAOJ,kBAAS;AACP,wBAA4C,KAAKC,KAAjD;AAAA,UAAQC,KAAR,eAAQA,KAAR;AAAA,UAAeC,OAAf,eAAeA,OAAf;AAAA,UAAwBC,eAAxB,eAAwBA,eAAxB;AACA,0BAAO,gCAAC,6BAAD;AAAmB,QAAA,KAAK,EAAEF,KAA1B;AAAiC,QAAA,OAAO,EAAEC,OAA1C;AAAmD,QAAA,eAAe,EAAEC;AAApE,QAAP;AACD;;;EAVgBC,kBAAMC,S;;iCAAnBN,I,eACe;AACjBE,EAAAA,KAAK,EAAEK,sBAAUC,MAAV,CAAiBC,UADP;AAEjBN,EAAAA,OAAO,EAAEI,sBAAUG,SAAV,CAAoB,CAACH,sBAAUI,KAAV,CAAgBF,UAAjB,EAA6BF,sBAAUC,MAAV,CAAiBC,UAA9C,CAApB,CAFQ;AAGjBL,EAAAA,eAAe,EAAEG,sBAAUK,IAAV,CAAeH;AAHf,C;AAWrB,IAAMI,GAAG,GAAG,2BAAgBb,IAAhB,CAAZ;eACea,G","sourcesContent":["import PlacementOrdering from './placement-ordering';\nimport React from 'react';\nimport { withDragContext } from '@pie-lib/drag';\n\nimport PropTypes from 'prop-types';\n\nclass Main extends React.Component {\n static propTypes = {\n model: PropTypes.object.isRequired,\n session: PropTypes.oneOfType([PropTypes.array.isRequired, PropTypes.object.isRequired]),\n onSessionChange: PropTypes.func.isRequired,\n };\n\n render() {\n const { model, session, onSessionChange } = this.props;\n return <PlacementOrdering model={model} session={session} onSessionChange={onSessionChange} />;\n }\n}\nconst out = withDragContext(Main);\nexport default out;\n"],"file":"main.js"}
package/lib/ordering.js CHANGED
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.buildState = buildState;
9
+ exports.push = void 0;
9
10
  exports.reducer = reducer;
10
- exports.swap = exports.push = void 0;
11
+ exports.swap = void 0;
11
12
 
12
13
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
14
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ordering.js"],"names":["log","push","arr","fromIndex","toIndex","movedItem","find","item","index","remainingItems","filter","slice","swap","length","undefined","Error","update","tmp","removeResponse","state","targetTile","response","id","updateResponse","from","to","opts","includeTargets","type","findIndex","r","buildTiles","choices","outcomes","targets","i","choice","c","outcome","out","Object","assign","empty","draggable","processedChoices","map","m","indexOf","allowSameChoiceInTargets","droppable","concat","reduce","acc","emptyTile","choiceTile","buildState","Array","tiles","reducer","action","target"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA,IAAMA,GAAG,GAAG,uBAAM,0CAAN,CAAZ;;AAEO,IAAMC,IAAI,GAAG,SAAPA,IAAO,CAACC,GAAD,EAAMC,SAAN,EAAiBC,OAAjB,EAA6B;AAC/C,MAAMC,SAAS,GAAGH,GAAG,CAACI,IAAJ,CAAS,UAACC,IAAD,EAAOC,KAAP;AAAA,WAAiBA,KAAK,KAAKL,SAA3B;AAAA,GAAT,CAAlB;AACA,MAAMM,cAAc,GAAGP,GAAG,CAACQ,MAAJ,CAAW,UAACH,IAAD,EAAOC,KAAP;AAAA,WAAiBA,KAAK,KAAKL,SAA3B;AAAA,GAAX,CAAvB;AAEA,uDACKM,cAAc,CAACE,KAAf,CAAqB,CAArB,EAAwBP,OAAxB,CADL,IAEEC,SAFF,uCAGKI,cAAc,CAACE,KAAf,CAAqBP,OAArB,CAHL;AAKD,CATM;;;;AAWA,IAAMQ,IAAI,GAAG,SAAPA,IAAO,CAACV,GAAD,EAAMC,SAAN,EAAiBC,OAAjB,EAA6B;AAC/CJ,EAAAA,GAAG,CAAC,QAAD,EAAWE,GAAX,EAAgBC,SAAhB,EAA2BC,OAA3B,CAAH;;AACA,MACE,CAACF,GAAD,IACAA,GAAG,CAACW,MAAJ,IAAc,CADd,IAEAV,SAAS,KAAKW,SAFd,IAGAV,OAAO,KAAKU,SAJd,EAKE;AACA,UAAM,IAAIC,KAAJ,gEACoDb,GADpD,eAC4DC,SAD5D,cACyEC,OADzE,EAAN;AAGD;;AACD,MAAMY,MAAM,GAAG,2BAAUd,GAAV,CAAf;AACA,MAAMe,GAAG,GAAGf,G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CAACc,QAHgB,EAItBd,KAAK,CAACO,IAJgB,CAAxB;;AAMA,eAAOc,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBtB,KAAlB,EAAyB;AAAEE,UAAAA,QAAQ,EAARA,SAAF;AAAYoC,UAAAA,KAAK,EAALA;AAAZ,SAAzB,CAAP;AACD;AAtBH;;AAwBA,SAAOtC,KAAP;AACD","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\nimport debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport map from 'lodash/map';\nimport assign from 'lodash/assign';\n\nconst log = debug('pie-elements:placement-ordering:ordering');\n\nexport const push = (arr, fromIndex, toIndex) => {\n const movedItem = arr.find((item, index) => index === fromIndex);\n const remainingItems = arr.filter((item, index) => index !== fromIndex);\n\n return [\n ...remainingItems.slice(0, toIndex),\n movedItem,\n ...remainingItems.slice(toIndex)\n ];\n}\n\nexport const swap = (arr, fromIndex, toIndex) => {\n log('[swap]', arr, fromIndex, toIndex);\n if (\n !arr ||\n arr.length <= 1 ||\n fromIndex === undefined ||\n toIndex === undefined\n ) {\n throw new Error(\n `swap requires a non-empty array, fromIndex, toIndex: ${arr}, ${fromIndex} ${toIndex}`\n );\n }\n const update = cloneDeep(arr);\n const tmp = arr[toIndex];\n update[toIndex] = update[fromIndex];\n update[fromIndex] = tmp;\n return update;\n};\n\nfunction removeResponse(state, targetTile) {\n const update = cloneDeep(state.response);\n\n if (update[targetTile.index] === targetTile.id) {\n update[targetTile.index] = undefined;\n } else {\n throw new Error(\n `Tried to remove from index: ${\n targetTile.index\n }, but the id doesn't match: array: ${update}, target: ${targetTile.id}`\n );\n }\n return update;\n}\n\nfunction updateResponse(state, from, to) {\n const { response, opts } = state;\n const update = cloneDeep(response);\n if (opts.includeTargets) {\n if (from.type === 'choice' && to.type === 'target') {\n update[to.index] = from.id;\n return update;\n } else if (from.type === 'target' && to.type === 'choice') {\n update[from.index] = undefined;\n return update;\n } else if (from.type === 'target' && to.type === 'target') {\n return swap(response, from.index, to.index);\n } else {\n log('do nothing to the response');\n return response;\n }\n } else {\n const fromIndex = state.response.findIndex(\n r => r !== undefined && r === from.id\n );\n const toIndex = state.response.findIndex(\n r => r !== undefined && r === to.id\n );\n log('fromIndex: ', fromIndex, 'toIndex:', toIndex);\n return push(state.response, fromIndex, toIndex);\n }\n}\n\nfunction buildTiles(choices, response, outcomes, opts) {\n if (opts.includeTargets) {\n const targets = [];\n for (let i = 0; i < response.length; i++) {\n const r = response[i];\n\n const choice = choices.find(\n c => r !== undefined && r !== null && c.id === r\n );\n //TODO: index needs to match too!!\n const outcome = outcomes[i];\n\n const out = Object.assign(\n { type: 'target', index: i, empty: choice === undefined },\n choice,\n outcome,\n { draggable: choice !== undefined }\n );\n\n targets.push(out);\n }\n\n const processedChoices = choices.map(m => {\n if (response.indexOf(m.id) !== -1 && !opts.allowSameChoiceInTargets) {\n return {\n type: 'choice',\n empty: true,\n droppable: true,\n draggable: false\n };\n } else {\n return Object.assign({}, m, {\n type: 'choice',\n droppable: false,\n draggable: true\n });\n }\n });\n\n return processedChoices.concat(targets);\n } else {\n return response.reduce((acc, id, index) => {\n const emptyTile = Object.assign(\n { type: 'empty', draggable: false, droppable: true },\n choices.find(m => m.id === id),\n outcomes[index]\n );\n const choiceTile = Object.assign(\n { type: 'choice', draggable: true, droppable: true },\n choices.find(m => m.id === id),\n outcomes[index]\n )\n\n if(index === 0) {\n acc.push(emptyTile)\n }\n\n acc.push(choiceTile, emptyTile);\n\n return acc;\n }, []);\n }\n}\n\nexport function buildState(choices, response, outcomes, opts) {\n opts = assign({ includeTargets: true }, opts);\n\n outcomes = outcomes || [];\n response =\n !response || isEmpty(response)\n ? opts.includeTargets\n ? new Array(choices.length)\n : map(choices, c => c.id)\n : response;\n return {\n choices,\n response,\n opts,\n outcomes,\n tiles: buildTiles(choices, response, outcomes, opts)\n };\n}\n\nexport function reducer(action, state) {\n switch (action.type) {\n case 'move': {\n const { from, to } = action;\n const response = updateResponse(state, from, to);\n const tiles = buildTiles(\n state.choices,\n response,\n state.outcomes,\n state.opts\n );\n return Object.assign({}, state, { response, tiles });\n }\n case 'remove': {\n const { target } = action;\n const response = removeResponse(state, target);\n const tiles = buildTiles(\n state.choices,\n response,\n state.outcomes,\n state.opts\n );\n return Object.assign({}, state, { response, tiles });\n }\n }\n return state;\n}\n"],"file":"ordering.js"}
1
+ {"version":3,"sources":["../src/ordering.js"],"names":["log","push","arr","fromIndex","toIndex","movedItem","find","item","index","remainingItems","filter","slice","swap","length","undefined","Error","update","tmp","removeResponse","state","targetTile","response","id","updateResponse","from","to","opts","includeTargets","type","findIndex","r","buildTiles","choices","outcomes","targets","i","choice","c","outcome","out","Object","assign","empty","draggable","processedChoices","map","m","indexOf","allowSameChoiceInTargets","droppable","concat","reduce","acc","emptyTile","choiceTile","buildState","Array","tiles","reducer","action","target"],"mappings":";;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA,IAAMA,GAAG,GAAG,uBAAM,0CAAN,CAAZ;;AAEO,IAAMC,IAAI,GAAG,SAAPA,IAAO,CAACC,GAAD,EAAMC,SAAN,EAAiBC,OAAjB,EAA6B;AAC/C,MAAMC,SAAS,GAAGH,GAAG,CAACI,IAAJ,CAAS,UAACC,IAAD,EAAOC,KAAP;AAAA,WAAiBA,KAAK,KAAKL,SAA3B;AAAA,GAAT,CAAlB;AACA,MAAMM,cAAc,GAAGP,GAAG,CAACQ,MAAJ,CAAW,UAACH,IAAD,EAAOC,KAAP;AAAA,WAAiBA,KAAK,KAAKL,SAA3B;AAAA,GAAX,CAAvB;AAEA,uDAAWM,cAAc,CAACE,KAAf,CAAqB,CAArB,EAAwBP,OAAxB,CAAX,IAA6CC,SAA7C,uCAA2DI,cAAc,CAACE,KAAf,CAAqBP,OAArB,CAA3D;AACD,CALM;;;;AAOA,IAAMQ,IAAI,GAAG,SAAPA,IAAO,CAACV,GAAD,EAAMC,SAAN,EAAiBC,OAAjB,EAA6B;AAC/CJ,EAAAA,GAAG,C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P,CAAc,EAAd,EAAkBtB,KAAlB,EAAyB;AAAEE,UAAAA,QAAQ,EAARA,QAAF;AAAYoC,UAAAA,KAAK,EAALA;AAAZ,SAAzB,CAAP;AACD;;AACD,SAAK,QAAL;AAAe;AACb,YAAQG,MAAR,GAAmBD,MAAnB,CAAQC,MAAR;;AACA,YAAMvC,SAAQ,GAAGH,cAAc,CAACC,KAAD,EAAQyC,MAAR,CAA/B;;AACA,YAAMH,MAAK,GAAG1B,UAAU,CAACZ,KAAK,CAACa,OAAP,EAAgBX,SAAhB,EAA0BF,KAAK,CAACc,QAAhC,EAA0Cd,KAAK,CAACO,IAAhD,CAAxB;;AACA,eAAOc,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBtB,KAAlB,EAAyB;AAAEE,UAAAA,QAAQ,EAARA,SAAF;AAAYoC,UAAAA,KAAK,EAALA;AAAZ,SAAzB,CAAP;AACD;AAZH;;AAcA,SAAOtC,KAAP;AACD","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\nimport debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport map from 'lodash/map';\nimport assign from 'lodash/assign';\n\nconst log = debug('pie-elements:placement-ordering:ordering');\n\nexport const push = (arr, fromIndex, toIndex) => {\n const movedItem = arr.find((item, index) => index === fromIndex);\n const remainingItems = arr.filter((item, index) => index !== fromIndex);\n\n return [...remainingItems.slice(0, toIndex), movedItem, ...remainingItems.slice(toIndex)];\n};\n\nexport const swap = (arr, fromIndex, toIndex) => {\n log('[swap]', arr, fromIndex, toIndex);\n if (!arr || arr.length <= 1 || fromIndex === undefined || toIndex === undefined) {\n throw new Error(`swap requires a non-empty array, fromIndex, toIndex: ${arr}, ${fromIndex} ${toIndex}`);\n }\n const update = cloneDeep(arr);\n const tmp = arr[toIndex];\n update[toIndex] = update[fromIndex];\n update[fromIndex] = tmp;\n return update;\n};\n\nfunction removeResponse(state, targetTile) {\n const update = cloneDeep(state.response);\n\n if (update[targetTile.index] === targetTile.id) {\n update[targetTile.index] = undefined;\n } else {\n throw new Error(\n `Tried to remove from index: ${targetTile.index}, but the id doesn't match: array: ${update}, target: ${targetTile.id}`,\n );\n }\n return update;\n}\n\nfunction updateResponse(state, from, to) {\n const { response, opts } = state;\n const update = cloneDeep(response);\n if (opts.includeTargets) {\n if (from.type === 'choice' && to.type === 'target') {\n update[to.index] = from.id;\n return update;\n } else if (from.type === 'target' && to.type === 'choice') {\n update[from.index] = undefined;\n return update;\n } else if (from.type === 'target' && to.type === 'target') {\n return swap(response, from.index, to.index);\n } else {\n log('do nothing to the response');\n return response;\n }\n } else {\n const fromIndex = state.response.findIndex((r) => r !== undefined && r === from.id);\n const toIndex = state.response.findIndex((r) => r !== undefined && r === to.id);\n log('fromIndex: ', fromIndex, 'toIndex:', toIndex);\n return push(state.response, fromIndex, toIndex);\n }\n}\n\nfunction buildTiles(choices, response, outcomes, opts) {\n if (opts.includeTargets) {\n const targets = [];\n for (let i = 0; i < response.length; i++) {\n const r = response[i];\n\n const choice = choices.find((c) => r !== undefined && r !== null && c.id === r);\n //TODO: index needs to match too!!\n const outcome = outcomes[i];\n\n const out = Object.assign({ type: 'target', index: i, empty: choice === undefined }, choice, outcome, {\n draggable: choice !== undefined,\n });\n\n targets.push(out);\n }\n\n const processedChoices = choices.map((m) => {\n if (response.indexOf(m.id) !== -1 && !opts.allowSameChoiceInTargets) {\n return {\n type: 'choice',\n empty: true,\n droppable: true,\n draggable: false,\n };\n } else {\n return Object.assign({}, m, {\n type: 'choice',\n droppable: false,\n draggable: true,\n });\n }\n });\n\n return processedChoices.concat(targets);\n } else {\n return response.reduce((acc, id, index) => {\n const emptyTile = Object.assign(\n { type: 'empty', draggable: false, droppable: true },\n choices.find((m) => m.id === id),\n outcomes[index],\n );\n const choiceTile = Object.assign(\n { type: 'choice', draggable: true, droppable: true },\n choices.find((m) => m.id === id),\n outcomes[index],\n );\n\n if (index === 0) {\n acc.push(emptyTile);\n }\n\n acc.push(choiceTile, emptyTile);\n\n return acc;\n }, []);\n }\n}\n\nexport function buildState(choices, response, outcomes, opts) {\n opts = assign({ includeTargets: true }, opts);\n\n outcomes = outcomes || [];\n response =\n !response || isEmpty(response)\n ? opts.includeTargets\n ? new Array(choices.length)\n : map(choices, (c) => c.id)\n : response;\n return {\n choices,\n response,\n opts,\n outcomes,\n tiles: buildTiles(choices, response, outcomes, opts),\n };\n}\n\nexport function reducer(action, state) {\n switch (action.type) {\n case 'move': {\n const { from, to } = action;\n const response = updateResponse(state, from, to);\n const tiles = buildTiles(state.choices, response, state.outcomes, state.opts);\n return Object.assign({}, state, { response, tiles });\n }\n case 'remove': {\n const { target } = action;\n const response = removeResponse(state, target);\n const tiles = buildTiles(state.choices, response, state.outcomes, state.opts);\n return Object.assign({}, state, { response, tiles });\n }\n }\n return state;\n}\n"],"file":"ordering.js"}
@@ -51,6 +51,8 @@ var _reactDom = _interopRequireDefault(require("react-dom"));
51
51
 
52
52
  var _mathRendering = require("@pie-lib/math-rendering");
53
53
 
54
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
55
+
54
56
  var _excluded = ["tiler", "ordering", "onDropChoice", "onRemoveChoice"];
55
57
 
56
58
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
@@ -93,6 +95,16 @@ var PlacementOrdering = /*#__PURE__*/function (_React$Component) {
93
95
 
94
96
  (0, _classCallCheck2["default"])(this, PlacementOrdering);
95
97
  _this = _super.call(this, props);
98
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "isValidSession", function (_ref) {
99
+ var model = _ref.model,
100
+ session = _ref.session;
101
+ var config = model.config;
102
+ var compactSessionValues = session && (0, _compact["default"])(session.value) || [];
103
+ var completeSession = compactSessionValues.length === model.choices.length; // if it includes targets, it doesn't have to contain all the choices selected (eg: only 2 targets were filled)
104
+ // but if it does not include targets, it's a must to have all choices selected
105
+
106
+ return config.includeTargets || completeSession;
107
+ });
96
108
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDropChoice", function (target, source, ordering) {
97
109
  var _this$props = _this.props,
98
110
  onSessionChange = _this$props.onSessionChange,
@@ -166,7 +178,22 @@ var PlacementOrdering = /*#__PURE__*/function (_React$Component) {
166
178
  (0, _createClass2["default"])(PlacementOrdering, [{
167
179
  key: "componentDidMount",
168
180
  value: function componentDidMount() {
169
- this.initSessionIfNeeded(this.props);
181
+ var _this2 = this;
182
+
183
+ var _this$props4 = this.props,
184
+ model = _this$props4.model,
185
+ session = _this$props4.session;
186
+
187
+ if (!this.isValidSession({
188
+ model: model,
189
+ session: session
190
+ })) {
191
+ this.setState({
192
+ defaultSessionValue: (0, _cloneDeep["default"])(session === null || session === void 0 ? void 0 : session.value)
193
+ }, function () {
194
+ return _this2.initSessionIfNeeded(_this2.props);
195
+ });
196
+ }
170
197
  }
171
198
  }, {
172
199
  key: "componentDidUpdate",
@@ -179,53 +206,69 @@ var PlacementOrdering = /*#__PURE__*/function (_React$Component) {
179
206
  }, {
180
207
  key: "UNSAFE_componentWillReceiveProps",
181
208
  value: function UNSAFE_componentWillReceiveProps(nextProps) {
209
+ var _this$props5, _this$props$session;
210
+
182
211
  var newState = {};
183
212
 
184
- if (!nextProps.model.correctResponse) {
213
+ var _nextProps$model = nextProps === null || nextProps === void 0 ? void 0 : nextProps.model,
214
+ correctResponse = _nextProps$model.correctResponse,
215
+ config = _nextProps$model.config,
216
+ choices = _nextProps$model.choices;
217
+
218
+ var _ref2 = ((_this$props5 = this.props) === null || _this$props5 === void 0 ? void 0 : _this$props5.model) || {},
219
+ oldConfig = _ref2.config,
220
+ oldChoices = _ref2.choices;
221
+
222
+ if (!correctResponse) {
185
223
  newState.showingCorrect = false;
186
224
  }
187
225
 
188
- var includeTargetsChanged = nextProps.model.config.includeTargets !== this.props.model.config.includeTargets;
189
- var choicesNumberChanged = nextProps.model.choices.length !== this.props.model.choices.length;
190
-
191
- if (includeTargetsChanged || choicesNumberChanged) {
192
- this.initSessionIfNeeded(nextProps, true);
226
+ var includeTargetsChanged = config.includeTargets !== oldConfig.includeTargets;
227
+ var choicesChanged = !(0, _isEqual["default"])(oldChoices, choices);
228
+ var isDefaultSession = (0, _isEqual["default"])(this.state.defaultSessionValue, (_this$props$session = this.props.session) === null || _this$props$session === void 0 ? void 0 : _this$props$session.value);
229
+ var isValidSession = this.isValidSession({
230
+ model: nextProps.model,
231
+ session: nextProps.session
232
+ }); // if the session is not valid anymore, it has to be reset
233
+ // OR
234
+ // if the session is the default one (set if the initial session was not valid or empty)
235
+ // and targets or choices changed, then we can reset the session
236
+ // but if the session is not the default one (it was set by the student), then we do not reset it
237
+
238
+ if (!isValidSession || isDefaultSession && (includeTargetsChanged || choicesChanged)) {
239
+ this.initSessionIfNeeded(nextProps);
193
240
  }
194
241
 
195
242
  this.setState(newState);
196
243
  }
197
244
  }, {
198
245
  key: "initSessionIfNeeded",
199
- value: function initSessionIfNeeded(props, reset) {
246
+ value: function initSessionIfNeeded(props) {
200
247
  var model = props.model,
201
248
  session = props.session,
202
249
  onSessionChange = props.onSessionChange;
203
250
  var newConfig = model.config;
204
- var compactSessionValues = session && (0, _compact["default"])(session.value) || [];
205
-
206
- if (!newConfig.includeTargets && compactSessionValues.length !== model.choices.length) {
207
- log('[initSessionIfNeeded] initing session...', newConfig.includeTargets);
208
- var update = (0, _cloneDeep["default"])(session);
209
- update.value = model.choices.map(function (m) {
210
- return m.id;
211
- });
212
- onSessionChange(update);
213
- } else if (newConfig.includeTargets) {
214
- var _update = (0, _cloneDeep["default"])(session);
215
-
216
- if (reset) {
217
- delete _update.value;
218
- }
251
+ var update = (0, _cloneDeep["default"])(session);
252
+ update.value = model.choices.map(function (m) {
253
+ return m.id;
254
+ });
219
255
 
220
- onSessionChange(_update);
256
+ if (newConfig.includeTargets) {
257
+ delete update.value;
221
258
  }
259
+
260
+ this.setState({
261
+ defaultSessionValue: (0, _cloneDeep["default"])(update === null || update === void 0 ? void 0 : update.value)
262
+ }, function () {
263
+ return onSessionChange(update);
264
+ });
222
265
  }
223
266
  }, {
224
267
  key: "render",
225
268
  value: function render() {
226
- var _this$props4 = this.props,
227
- classes = _this$props4.classes,
228
- model = _this$props4.model;
269
+ var _this$props6 = this.props,
270
+ classes = _this$props6.classes,
271
+ model = _this$props6.model;
229
272
  var correctResponse = model.correctResponse,
230
273
  correctness = model.correctness,
231
274
  prompt = model.prompt,
@@ -248,9 +291,9 @@ var PlacementOrdering = /*#__PURE__*/function (_React$Component) {
248
291
  var vertical = orientation === 'vertical';
249
292
  var ordering = this.createOrdering();
250
293
 
251
- var _ref = env || {},
252
- mode = _ref.mode,
253
- role = _ref.role;
294
+ var _ref3 = env || {},
295
+ mode = _ref3.mode,
296
+ role = _ref3.role;
254
297
 
255
298
  var Tiler = vertical ? _tiler.VerticalTiler : _tiler.HorizontalTiler;
256
299
  var displayNote = (showingCorrect || mode === 'view' && role === 'instructor') && showNote && note;