@pie-element/placement-ordering 7.5.3-next.137 → 7.5.3-next.1372

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.
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "@pie-element/placement-ordering-configure",
3
- "version": "5.2.1",
3
+ "version": "6.1.0",
4
4
  "private": true,
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
7
7
  "dependencies": {
8
8
  "@material-ui/core": "^3.9.2",
9
9
  "@material-ui/icons": "^3.0.1",
10
- "@pie-framework/pie-configure-events": "^1.2.0",
11
- "@pie-lib/config-ui": "^10.10.2",
12
- "@pie-lib/editable-html": "^7.17.2",
13
- "@pie-lib/scoring-config": "^3.5.131",
10
+ "@pie-framework/pie-configure-events": "^1.3.0",
11
+ "@pie-lib/config-ui": "^11.0.20",
12
+ "@pie-lib/editable-html": "^9.2.2",
13
+ "@pie-lib/scoring-config": "^3.5.184",
14
14
  "debug": "^3.1.0",
15
15
  "lodash": "^4.17.15",
16
16
  "nested-property": "^0.0.7",
17
+ "pluralize": "^8.0.0",
17
18
  "prop-types": "^15.6.2",
18
19
  "react": "^16.8.1",
19
20
  "react-dnd": "^9.3.2",
@@ -3,6 +3,91 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [6.4.7](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.6...@pie-element/placement-ordering-controller@6.4.7) (2022-05-16)
7
+
8
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
9
+
10
+
11
+
12
+
13
+
14
+ ## [6.4.6](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.5...@pie-element/placement-ordering-controller@6.4.6) (2022-03-08)
15
+
16
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
17
+
18
+
19
+
20
+
21
+
22
+ ## [6.4.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.1...@pie-element/placement-ordering-controller@6.4.2) (2021-12-01)
23
+
24
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
25
+
26
+
27
+
28
+
29
+
30
+ ## [6.4.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.3.3...@pie-element/placement-ordering-controller@6.4.1) (2021-11-11)
31
+
32
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
33
+
34
+
35
+
36
+
37
+
38
+ # [6.4.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.3.2...@pie-element/placement-ordering-controller@6.4.0) (2021-11-11)
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * **placement-ordering:** fix create correct session for IBX browse items PD-1349 ([e84c30d](https://github.com/pie-framework/pie-elements/commit/e84c30dd075085ef5d917f2893568bca2003d225))
44
+
45
+
46
+ ### Features
47
+
48
+ * **placement-ordering:** add baseline validation for authoring PD-600, PD-1334 ([2350279](https://github.com/pie-framework/pie-elements/commit/23502790000e3c4f14e4dae6744519b004eb1172))
49
+
50
+
51
+
52
+
53
+
54
+
55
+ ## [6.3.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.3.2...@pie-element/placement-ordering-controller@6.3.3) (2021-11-01)
56
+
57
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
58
+
59
+
60
+
61
+
62
+
63
+ ## [6.3.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.3.0...@pie-element/placement-ordering-controller@6.3.2) (2021-08-05)
64
+
65
+
66
+ ### Bug Fixes
67
+
68
+ * force bump ([5ea7295](https://github.com/pie-framework/pie-elements/commit/5ea7295e4755fbc492a76e7ec69e5fc35b196919))
69
+
70
+
71
+
72
+
73
+
74
+ # [6.3.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.2.0...@pie-element/placement-ordering-controller@6.3.0) (2021-06-29)
75
+
76
+
77
+ ### Bug Fixes
78
+
79
+ * **placement-ordering:** fixed createCorrectResponseSession and added more tests for it PD-542 ([#574](https://github.com/pie-framework/pie-elements/issues/574)) ([16fb27f](https://github.com/pie-framework/pie-elements/commit/16fb27f1c32d75f7744cf5f24dc53b9a251090c2))
80
+ * **placement-ordering:** Fixed Placement Ordering items are displaying an incorrect label - PD-1147 ([#576](https://github.com/pie-framework/pie-elements/issues/576)) ([c7e3284](https://github.com/pie-framework/pie-elements/commit/c7e3284d0eadd6ccc082f474f385b565217db0f9))
81
+
82
+
83
+ ### Features
84
+
85
+ * Displayed a message when the item has one or more alternate answers - PD-167 ([#590](https://github.com/pie-framework/pie-elements/issues/590)) ([889d8b5](https://github.com/pie-framework/pie-elements/commit/889d8b578a915c997a95bd5cd4bdf18f53cc2b68))
86
+
87
+
88
+
89
+
90
+
6
91
  # [6.2.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.1.14...@pie-element/placement-ordering-controller@6.2.0) (2021-04-07)
7
92
 
8
93
 
@@ -5,10 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.outcome = outcome;
8
+ exports.createCorrectResponseSession = void 0;
9
9
  exports.createDefaultModel = createDefaultModel;
10
10
  exports.model = model;
11
- exports.createCorrectResponseSession = exports.normalize = exports.questionError = void 0;
11
+ exports.normalize = void 0;
12
+ exports.outcome = outcome;
13
+ exports.validate = exports.questionError = void 0;
12
14
 
13
15
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
16
 
@@ -28,9 +30,11 @@ var _debug = _interopRequireDefault(require("debug"));
28
30
 
29
31
  var _defaults = _interopRequireDefault(require("./defaults"));
30
32
 
31
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
33
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
32
34
 
33
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
35
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
36
+
37
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
34
38
 
35
39
  var log = (0, _debug["default"])('@pie-element:placement-ordering:controller');
36
40
 
@@ -101,14 +105,22 @@ function model(question, session, env) {
101
105
  case 0:
102
106
  normalizedQuestion = normalize(question);
103
107
  base = {};
108
+
109
+ if (_lodash["default"].every(question.alternateResponses, _lodash["default"].isArray)) {
110
+ log('Deprecated structure of alternateResponses is in use');
111
+ console.error('Deprecated structure of alternateResponses is in use');
112
+ }
113
+
104
114
  base.env = env;
105
115
  base.outcomes = [];
106
116
  base.completeLength = (normalizedQuestion.correctResponse || []).length;
107
- base.choices = normalizedQuestion.choices;
117
+ base.choices = (normalizedQuestion.choices || []).filter(function (choice) {
118
+ return choice.label;
119
+ });
108
120
  base.note = normalizedQuestion.note;
109
121
  base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;
110
122
 
111
- if (env.mode === 'gather' && !normalizedQuestion.placementArea) {
123
+ if (env.mode === 'gather' && !normalizedQuestion.placementArea && !session.value) {
112
124
  session.value = base.choices.map(function (m) {
113
125
  return m.id;
114
126
  });
@@ -182,7 +194,7 @@ function model(question, session, env) {
182
194
  resolve(base);
183
195
  }
184
196
 
185
- case 15:
197
+ case 16:
186
198
  case "end":
187
199
  return _context.stop();
188
200
  }
@@ -199,10 +211,9 @@ function model(question, session, env) {
199
211
  var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
200
212
  return new Promise(function (resolve) {
201
213
  if (env.mode !== 'evaluate' && env.role === 'instructor') {
202
- var correctResponse = question.correctResponse;
203
214
  resolve({
204
215
  id: '1',
205
- value: correctResponse
216
+ value: (0, _scoring.flattenCorrect)(question)
206
217
  });
207
218
  } else {
208
219
  resolve(null);
@@ -211,4 +222,26 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
211
222
  };
212
223
 
213
224
  exports.createCorrectResponseSession = createCorrectResponseSession;
225
+
226
+ var validate = function validate() {
227
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
228
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
229
+ var choices = model.choices,
230
+ correctResponse = model.correctResponse;
231
+ var errors = {};
232
+ var choicesIds = (choices || []).map(function (choice) {
233
+ return choice.id;
234
+ });
235
+ var correctResponseIds = (correctResponse || []).map(function (response) {
236
+ return response.id || response;
237
+ });
238
+
239
+ if ((0, _isEqual["default"])(choicesIds, correctResponseIds)) {
240
+ errors.orderError = 'The correct ordering should not be identical to the initial ordering.';
241
+ }
242
+
243
+ return errors;
244
+ };
245
+
246
+ exports.validate = validate;
214
247
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","questionError","Error","outcome","question","session","env","Promise","resolve","reject","_","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","outcomes","completeLength","length","choices","note","showNote","alternateResponses","mode","placementArea","value","map","m","id","prompt","config","orientation","includeTargets","choiceLabelEnabled","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","role","rationale","teacherInstructions","allCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","arr","allCorrect","correct","isEqual","correctness","feedback","then","createCorrectResponseSession"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB;AAAA,SAC3B,IAAIC,KAAJ,CAAU,qDAAV,CAD2B;AAAA,CAAtB;;;;AAGA,SAASC,OAAT,CAAiBC,QAAjB,EAA2BC,OAA3B,EAAoCC,GAApC,EAAyC;AAC9C,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;AACtC,QAAI,CAACJ,OAAD,IAAYK,mBAAEC,OAAF,CAAUN,OAAV,CAAhB,EAAoC;AAClCG,MAAAA,OAAO,CAAC;AAAEI,QAAAA,KAAK,EAAE,CAAT;AAAYC,QAAAA,KAAK,EAAE;AAAnB,OAAD,CAAP;AACD;;AAED,QACE,CAACT,QAAD,IACA,CAACA,QAAQ,CAACU,eADV,IAEAJ,mBAAEC,OAAF,CAAUP,QAAQ,CAACU,eAAnB,CAHF,EAIE;AACAL,MAAAA,MAAM,CAACR,aAAa,EAAd,CAAN;AACD,KAND,MAMO;AACL,UAAI;AACF,YAAMc,CAAC,GAAG,oBAAMX,QA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E,GAAX,EAAmB;AAC7D,SAAO,IAAIC,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAC5B,QAAIF,GAAG,CAACgC,IAAJ,KAAa,UAAb,IAA2BhC,GAAG,CAACkD,IAAJ,KAAa,YAA5C,EAA0D;AAAA,UAChD1C,eADgD,GAC5BV,QAD4B,CAChDU,eADgD;AAGxDN,MAAAA,OAAO,CAAC;AACNmC,QAAAA,EAAE,EAAE,GADE;AAENH,QAAAA,KAAK,EAAE1B;AAFD,OAAD,CAAP;AAID,KAPD,MAOO;AACLN,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAXM,CAAP;AAYD,CAbM","sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport _ from 'lodash';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\n\nconst log = debug('@pie-element:placement-ordering:controller');\n\nexport const questionError = () =>\n new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || _.isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (\n !question ||\n !question.correctResponse ||\n _.isEmpty(question.correctResponse)\n ) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {})\n ? s\n : s === 1\n ? 1\n : 0;\n resolve({\n score: finalScore\n });\n } catch (e) {\n reject(e);\n }\n }\n });\n}\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => {\n resolve({\n ...defaults,\n ...model\n });\n });\n}\n\nexport const normalize = question => ({\n ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n base.env = env;\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = normalizedQuestion.choices;\n base.note = normalizedQuestion.note;\n base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;\n\n if (env.mode === 'gather' && !normalizedQuestion.placementArea) {\n session.value = base.choices.map(m => m.id);\n }\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n base.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled) {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = _.reduce(\n value,\n (acc, c, idx) => acc + (cr[idx] === c ? 1 : 0),\n 0\n );\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore\n };\n }\n\n return info;\n },\n { arr: [], score: 0 }\n );\n\n base.outcomes = _.map(value, function(c, idx) {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'\n };\n });\n\n const allCorrect = allCorrectResponses.reduce((correct, cr) => {\n if (_.isEqual(cr, value)) {\n return true;\n }\n\n return correct;\n }, false);\n\n base.correctness = allCorrect ? 'correct' : 'incorrect';\n\n if (!allCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n getFeedbackForCorrectness(\n base.correctness,\n normalizedQuestion.feedback\n ).then(feedback => {\n base.feedback = feedback;\n resolve(base);\n });\n } else {\n resolve(base);\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { correctResponse } = question;\n\n resolve({\n id: '1',\n value: correctResponse\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","questionError","Error","outcome","question","session","env","Promise","resolve","reject","_","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","every","alternateResponses","isArray","console","error","outcomes","completeLength","length","choices","filter","choice","label","note","showNote","mode","placementArea","value","map","m","id","prompt","config","orientation","includeTargets","choiceLabelEnabled","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","role","rationale","teacherInstructions","allCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","arr","allCorrect","correct","isEqual","correctness","feedback","then","createCorrectResponseSession","validate","errors","choicesIds","correctResponseIds","response","orderError"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB;AAAA,SAC3B,IAAIC,KAAJ,CAAU,qDAAV,CAD2B;AAAA,CAAtB;;;;AAGA,SAASC,OAAT,CAAiBC,QAAjB,EAA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aA,IAAM2E,QAAQ,GAAG,SAAXA,QAAW,GAA6B;AAAA,MAA5B9D,KAA4B,uEAApB,EAAoB;AAAA,MAAhB+B,MAAgB,uEAAP,EAAO;AACnD,MAAQb,OAAR,GAAqClB,KAArC,CAAQkB,OAAR;AAAA,MAAiBzB,eAAjB,GAAqCO,KAArC,CAAiBP,eAAjB;AACA,MAAMsE,MAAM,GAAG,EAAf;AAEA,MAAMC,UAAU,GAAG,CAAC9C,OAAO,IAAI,EAAZ,EAAgBS,GAAhB,CAAoB,UAAAP,MAAM;AAAA,WAAIA,MAAM,CAACS,EAAX;AAAA,GAA1B,CAAnB;AACA,MAAMoC,kBAAkB,GAAG,CAACxE,eAAe,IAAI,EAApB,EAAwBkC,GAAxB,CAA4B,UAAAuC,QAAQ;AAAA,WAAIA,QAAQ,CAACrC,EAAT,IAAeqC,QAAnB;AAAA,GAApC,CAA3B;;AAEA,MAAI,yBAAQF,UAAR,EAAoBC,kBAApB,CAAJ,EAA6C;AAC3CF,IAAAA,MAAM,CAACI,UAAP,GAAoB,uEAApB;AACD;;AAED,SAAOJ,MAAP;AACD,CAZM","sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport _ from 'lodash';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\nimport isEqual from 'lodash/isEqual';\n\nconst log = debug('@pie-element:placement-ordering:controller');\n\nexport const questionError = () =>\n new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || _.isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (\n !question ||\n !question.correctResponse ||\n _.isEmpty(question.correctResponse)\n ) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {})\n ? s\n : s === 1\n ? 1\n : 0;\n resolve({\n score: finalScore\n });\n } catch (e) {\n reject(e);\n }\n }\n });\n}\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => {\n resolve({\n ...defaults,\n ...model\n });\n });\n}\n\nexport const normalize = question => ({\n ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n if (_.every(question.alternateResponses, _.isArray)) {\n log('Deprecated structure of alternateResponses is in use');\n console.error('Deprecated structure of alternateResponses is in use');\n }\n\n base.env = env;\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = (normalizedQuestion.choices || []).filter(choice => choice.label);\n base.note = normalizedQuestion.note;\n base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;\n\n if (env.mode === 'gather' && !normalizedQuestion.placementArea && !session.value) {\n session.value = base.choices.map(m => m.id);\n }\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n base.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled) {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = _.reduce(\n value,\n (acc, c, idx) => acc + (cr[idx] === c ? 1 : 0),\n 0\n );\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore\n };\n }\n\n return info;\n },\n { arr: [], score: 0 }\n );\n\n base.outcomes = _.map(value, function(c, idx) {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'\n };\n });\n\n const allCorrect = allCorrectResponses.reduce((correct, cr) => {\n if (_.isEqual(cr, value)) {\n return true;\n }\n\n return correct;\n }, false);\n\n base.correctness = allCorrect ? 'correct' : 'incorrect';\n\n if (!allCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n getFeedbackForCorrectness(\n base.correctness,\n normalizedQuestion.feedback\n ).then(feedback => {\n base.feedback = feedback;\n resolve(base);\n });\n } else {\n resolve(base);\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n id: '1',\n value: flattenCorrect(question)\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { choices, correctResponse } = model;\n const errors = {};\n\n const choicesIds = (choices || []).map(choice => choice.id);\n const correctResponseIds = (correctResponse || []).map(response => response.id || response);\n\n if (isEqual(choicesIds, correctResponseIds)) {\n errors.orderError = 'The correct ordering should not be identical to the initial ordering.';\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.score = exports.getAllCorrectResponses = exports.flattenCorrect = exports.pairwiseCombinationScore = exports.illegalArgumentError = void 0;
8
+ exports.score = exports.pairwiseCombinationScore = exports.illegalArgumentError = exports.getAllCorrectResponses = exports.flattenCorrect = void 0;
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
@@ -17,9 +17,9 @@ var _jsCombinatorics = require("js-combinatorics");
17
17
 
18
18
  var _debug = _interopRequireDefault(require("debug"));
19
19
 
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
21
 
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
23
 
24
24
  var log = (0, _debug["default"])('pie-elements:placement-ordering:controller');
25
25
 
@@ -99,7 +99,14 @@ var flattenCorrect = function flattenCorrect(question) {
99
99
  exports.flattenCorrect = flattenCorrect;
100
100
 
101
101
  var getAllCorrectResponses = function getAllCorrectResponses(question) {
102
- return [flattenCorrect(question)].concat((0, _toConsumableArray2["default"])(question.alternateResponses || []));
102
+ var alternates = (question.alternateResponses || []).map(function (alternate) {
103
+ if (Array.isArray(alternate)) {
104
+ return alternate;
105
+ }
106
+
107
+ return alternate.response;
108
+ });
109
+ return [flattenCorrect(question)].concat((0, _toConsumableArray2["default"])(alternates));
103
110
  };
104
111
  /**
105
112
  * Returns the score for a session. If weighted scoring is present in the correctResponse
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/scoring.js"],"names":["log","illegalArgumentError","answer","Error","pairwiseCombinationScore","correct","opts","allowDuplicates","orderMustBeComplete","_","isEqual","uniq","length","Array","isArray","correctCombo","toArray","answerCombo","diff","differenceWith","comboLengthDiff","total","actual","n","toFixed","parseFloat","flattenCorrect","question","correctResponse","map","r","id","getAllCorrectResponses","alternateResponses","score","session","value","allCorrectResponse","configure","removeTilesAfterPlacing","bestScore","forEach","cr","currentScore"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAAAC,MAAM;AAAA,SACxC,IAAIC,KAAJ,8BACwBD,MADxB,qDADwC;AAAA,CAAnC;;;;AAIA,IAAME,wBAAwB,GAAG,SAA3BA,wBAA2B,CAACC,OAAD,EAAUH,MAAV,EAAkBI,IAAlB,EAA2B;AACjEA,EAAAA,IAAI;AAAKC,IAAAA,eAAe,EAAE,KAAtB;AAA6BC,IAAAA,mBAAmB,EAAE;AAAlD,KAA4DF,IAA5D,CAAJ;;AAEA,MAAI,CAACA,IAAI,CAACC,eAAN,IAAyB,CAACE,mBAAEC,OAAF,CAAUD,mBAAEE,IAAF,CAAON,OA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AmBC,uBAA1C,MAAuE,KADzE;AAGA;AACF;AACA;AACE;;AAEA,MAAIC,SAAS,GAAG,CAAhB;AAEAH,EAAAA,kBAAkB,CAACI,OAAnB,CAA2B,UAACC,EAAD,EAAQ;AACjC,QAAMC,YAAY,GAAGvC,wBAAwB,CAACsC,EAAD,EAAKN,KAAL,EAAY;AACvD7B,MAAAA,eAAe,EAAfA;AADuD,KAAZ,CAA7C;;AAIA,QAAIoC,YAAY,IAAIH,SAApB,EAA+B;AAC7BA,MAAAA,SAAS,GAAGG,YAAZ;AACD;AACF,GARD;AAUA,SAAOH,SAAP;AACD,CA7BM","sourcesContent":["import _ from 'lodash';\nimport { combination } from 'js-combinatorics';\nimport debug from 'debug';\n\nconst log = debug('pie-elements:placement-ordering:controller');\n\nexport const illegalArgumentError = answer =>\n new Error(\n `Cant score answer: ${answer} it has duplicates and allowDuplicates is false`\n );\nexport const pairwiseCombinationScore = (correct, answer, opts) => {\n opts = { allowDuplicates: false, orderMustBeComplete: false, ...opts };\n\n if (!opts.allowDuplicates && !_.isEqual(_.uniq(correct), correct)) {\n throw illegalArgumentError(answer);\n }\n\n if (\n opts.allowDuplicates === false &&\n answer.length !== _.uniq(answer).length\n ) {\n return 0;\n }\n\n answer = opts.allowDuplicates !== false ? answer : _.uniq(answer);\n\n log('answer:', answer);\n if (!Array.isArray(correct) || correct.length === 0) {\n throw new Error('correct must be non empty an array');\n }\n\n if (correct.length === 1) {\n return _.isEqual(correct, answer) ? 1 : 0;\n }\n\n if (!Array.isArray(answer) || answer.length < 2) {\n return 0;\n }\n\n if (answer.length > correct.length) {\n return 0;\n }\n\n if (correct.length !== answer.length && opts.orderMustBeComplete) {\n return 0;\n }\n\n const correctCombo = combination(correct, 2).toArray();\n const answerCombo = combination(answer, 2).toArray();\n\n const diff = _.differenceWith(answerCombo, correctCombo, _.isEqual);\n\n const comboLengthDiff = correctCombo.length - answerCombo.length;\n\n const total = correctCombo.length;\n const actual = total - diff.length - comboLengthDiff;\n\n const n = (actual / total).toFixed(2);\n\n return parseFloat(n);\n};\n\n/**\n * Flattens the correctResponse into an array of ordered identifiers representing the\n * correct response.\n */\nexport const flattenCorrect = question =>\n question.correctResponse\n ? question.correctResponse.map(r => (r && r.id ? r.id : r))\n : [];\n\n/**\n * Returns all correct responses for this question\n * @param question - array\n */\nexport const getAllCorrectResponses = question => [\n flattenCorrect(question),\n ...(question.alternateResponses || [])\n];\n\n/**\n * Returns the score for a session. If weighted scoring is present in the correctResponse\n * field for the question, this will be used. If partial scoring is present in the question\n * model, this will be used. Otherwise the default scoring mechanism (0 for any incorrect, 1\n * for all correct) will be used.\n */\n\nexport const score = (question, session) => {\n const { value } = session || {};\n\n if (!value) {\n return 0;\n }\n\n const allCorrectResponse = getAllCorrectResponses(question);\n const allowDuplicates =\n (question.configure && question.configure.removeTilesAfterPlacing) !== false;\n\n /**\n * We require this to be the case - locking\n */\n //const orderMustBeComplete = true;\n\n let bestScore = 0;\n\n allCorrectResponse.forEach((cr) => {\n const currentScore = pairwiseCombinationScore(cr, value, {\n allowDuplicates\n });\n\n if (currentScore >= bestScore) {\n bestScore = currentScore;\n }\n });\n\n return bestScore;\n};\n"],"file":"scoring.js"}
1
+ {"version":3,"sources":["../src/scoring.js"],"names":["log","illegalArgumentError","answer","Error","pairwiseCombinationScore","correct","opts","allowDuplicates","orderMustBeComplete","_","isEqual","uniq","length","Array","isArray","correctCombo","toArray","answerCombo","diff","differenceWith","comboLengthDiff","total","actual","n","toFixed","parseFloat","flattenCorrect","question","correctResponse","map","r","id","getAllCorrectResponses","alternates","alternateResponses","alternate","response","score","session","value","allCorrectResponse","configure","removeTilesAfterPlacing","bestScore","forEach","cr","currentScore"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAAAC,MAAM;AAAA,SACxC,IAAIC,KAAJ,8BACwBD,MAD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AK,CAACC,OAAN,CAAcqB,SAAd,CAAJ,EAA8B;AAE5B,aAAOA,SAAP;AACD;;AAED,WAAOA,SAAS,CAACC,QAAjB;AACD,GAPkB,CAAnB;AASA,UAASV,cAAc,CAACC,QAAD,CAAvB,6CAAsCM,UAAtC;AACD,CAXM;AAaP;AACA;AACA;AACA;AACA;AACA;;;;;AAEO,IAAMI,KAAK,GAAG,SAARA,KAAQ,CAACV,QAAD,EAAWW,OAAX,EAAuB;AAC1C,aAAkBA,OAAO,IAAI,EAA7B;AAAA,MAAQC,KAAR,QAAQA,KAAR;;AAEA,MAAI,CAACA,KAAL,EAAY;AACV,WAAO,CAAP;AACD;;AAED,MAAMC,kBAAkB,GAAGR,sBAAsB,CAACL,QAAD,CAAjD;AACA,MAAMpB,eAAe,GACnB,CAACoB,QAAQ,CAACc,SAAT,IAAsBd,QAAQ,CAACc,SAAT,CAAmBC,uBAA1C,MAAuE,KADzE;AAGA;AACF;AACA;AACE;;AAEA,MAAIC,SAAS,GAAG,CAAhB;AAEAH,EAAAA,kBAAkB,CAACI,OAAnB,CAA2B,UAACC,EAAD,EAAQ;AACjC,QAAMC,YAAY,GAAG1C,wBAAwB,CAACyC,EAAD,EAAKN,KAAL,EAAY;AACvDhC,MAAAA,eAAe,EAAfA;AADuD,KAAZ,CAA7C;;AAIA,QAAIuC,YAAY,IAAIH,SAApB,EAA+B;AAC7BA,MAAAA,SAAS,GAAGG,YAAZ;AACD;AACF,GARD;AAUA,SAAOH,SAAP;AACD,CA7BM","sourcesContent":["import _ from 'lodash';\nimport { combination } from 'js-combinatorics';\nimport debug from 'debug';\n\nconst log = debug('pie-elements:placement-ordering:controller');\n\nexport const illegalArgumentError = answer =>\n new Error(\n `Cant score answer: ${answer} it has duplicates and allowDuplicates is false`\n );\nexport const pairwiseCombinationScore = (correct, answer, opts) => {\n opts = { allowDuplicates: false, orderMustBeComplete: false, ...opts };\n\n if (!opts.allowDuplicates && !_.isEqual(_.uniq(correct), correct)) {\n throw illegalArgumentError(answer);\n }\n\n if (\n opts.allowDuplicates === false &&\n answer.length !== _.uniq(answer).length\n ) {\n return 0;\n }\n\n answer = opts.allowDuplicates !== false ? answer : _.uniq(answer);\n\n log('answer:', answer);\n if (!Array.isArray(correct) || correct.length === 0) {\n throw new Error('correct must be non empty an array');\n }\n\n if (correct.length === 1) {\n return _.isEqual(correct, answer) ? 1 : 0;\n }\n\n if (!Array.isArray(answer) || answer.length < 2) {\n return 0;\n }\n\n if (answer.length > correct.length) {\n return 0;\n }\n\n if (correct.length !== answer.length && opts.orderMustBeComplete) {\n return 0;\n }\n\n const correctCombo = combination(correct, 2).toArray();\n const answerCombo = combination(answer, 2).toArray();\n\n const diff = _.differenceWith(answerCombo, correctCombo, _.isEqual);\n\n const comboLengthDiff = correctCombo.length - answerCombo.length;\n\n const total = correctCombo.length;\n const actual = total - diff.length - comboLengthDiff;\n\n const n = (actual / total).toFixed(2);\n\n return parseFloat(n);\n};\n\n/**\n * Flattens the correctResponse into an array of ordered identifiers representing the\n * correct response.\n */\nexport const flattenCorrect = question =>\n question.correctResponse\n ? question.correctResponse.map(r => (r && r.id ? r.id : r))\n : [];\n\n/**\n * Returns all correct responses for this question\n * @param question - array\n */\nexport const getAllCorrectResponses = question => {\n const alternates = (question.alternateResponses || []).map(alternate => {\n if (Array.isArray(alternate)) {\n\n return alternate;\n }\n\n return alternate.response;\n });\n\n return [ flattenCorrect(question), ...alternates ];\n};\n\n/**\n * Returns the score for a session. If weighted scoring is present in the correctResponse\n * field for the question, this will be used. If partial scoring is present in the question\n * model, this will be used. Otherwise the default scoring mechanism (0 for any incorrect, 1\n * for all correct) will be used.\n */\n\nexport const score = (question, session) => {\n const { value } = session || {};\n\n if (!value) {\n return 0;\n }\n\n const allCorrectResponse = getAllCorrectResponses(question);\n const allowDuplicates =\n (question.configure && question.configure.removeTilesAfterPlacing) !== false;\n\n /**\n * We require this to be the case - locking\n */\n //const orderMustBeComplete = true;\n\n let bestScore = 0;\n\n allCorrectResponse.forEach((cr) => {\n const currentScore = pairwiseCombinationScore(cr, value, {\n allowDuplicates\n });\n\n if (currentScore >= bestScore) {\n bestScore = currentScore;\n }\n });\n\n return bestScore;\n};\n"],"file":"scoring.js"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/placement-ordering-controller",
3
- "version": "6.2.1",
3
+ "version": "6.4.7",
4
4
  "private": true,
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -179,6 +179,22 @@
179
179
  }
180
180
  }
181
181
  },
182
+ "spellCheck": {
183
+ "title": "ConfigureProp",
184
+ "type": "object",
185
+ "properties": {
186
+ "settings": {
187
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
188
+ "type": "boolean",
189
+ "title": "settings"
190
+ },
191
+ "label": {
192
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
193
+ "type": "string",
194
+ "title": "label"
195
+ }
196
+ }
197
+ },
182
198
  "removeTilesAfterPlacing": {
183
199
  "title": "ConfigureProp",
184
200
  "type": "object",
@@ -259,6 +275,94 @@
259
275
  }
260
276
  }
261
277
  },
278
+ "maxImageWidth": {
279
+ "title": "ConfigureMaxImageDimensionsProp",
280
+ "type": "object",
281
+ "properties": {
282
+ "teacherInstructions": {
283
+ "description": "Indicates the max dimension for images in teacher instructions",
284
+ "type": "number",
285
+ "title": "teacherInstructions"
286
+ },
287
+ "prompt": {
288
+ "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",
289
+ "type": "number",
290
+ "title": "prompt"
291
+ },
292
+ "rationale": {
293
+ "description": "Indicates the max dimension for images in rationale",
294
+ "type": "number",
295
+ "title": "rationale"
296
+ },
297
+ "choicesWithPlacementArea": {
298
+ "description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled",
299
+ "type": "number",
300
+ "title": "choicesWithPlacementArea"
301
+ },
302
+ "choicesWithoutPlacementArea": {
303
+ "description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled",
304
+ "type": "number",
305
+ "title": "choicesWithoutPlacementArea"
306
+ },
307
+ "choices": {
308
+ "description": "Only available for the height prop: indicates the max height for images in choices and choices labels",
309
+ "type": "number",
310
+ "title": "choices"
311
+ }
312
+ }
313
+ },
314
+ "maxImageHeight": {
315
+ "title": "ConfigureMaxImageDimensionsProp",
316
+ "type": "object",
317
+ "properties": {
318
+ "teacherInstructions": {
319
+ "description": "Indicates the max dimension for images in teacher instructions",
320
+ "type": "number",
321
+ "title": "teacherInstructions"
322
+ },
323
+ "prompt": {
324
+ "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",
325
+ "type": "number",
326
+ "title": "prompt"
327
+ },
328
+ "rationale": {
329
+ "description": "Indicates the max dimension for images in rationale",
330
+ "type": "number",
331
+ "title": "rationale"
332
+ },
333
+ "choicesWithPlacementArea": {
334
+ "description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled",
335
+ "type": "number",
336
+ "title": "choicesWithPlacementArea"
337
+ },
338
+ "choicesWithoutPlacementArea": {
339
+ "description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled",
340
+ "type": "number",
341
+ "title": "choicesWithoutPlacementArea"
342
+ },
343
+ "choices": {
344
+ "description": "Only available for the height prop: indicates the max height for images in choices and choices labels",
345
+ "type": "number",
346
+ "title": "choices"
347
+ }
348
+ }
349
+ },
350
+ "withRubric": {
351
+ "title": "ConfigureProp",
352
+ "type": "object",
353
+ "properties": {
354
+ "settings": {
355
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
356
+ "type": "boolean",
357
+ "title": "settings"
358
+ },
359
+ "label": {
360
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
361
+ "type": "string",
362
+ "title": "label"
363
+ }
364
+ }
365
+ },
262
366
  "showPrompt": {
263
367
  "description": "Determines whether prompt field will be displayed or not",
264
368
  "default": true,
@@ -294,6 +398,42 @@
294
398
  "title": "label"
295
399
  }
296
400
  }
401
+ },
402
+ "ConfigureMaxImageDimensionsProp": {
403
+ "title": "ConfigureMaxImageDimensionsProp",
404
+ "type": "object",
405
+ "properties": {
406
+ "teacherInstructions": {
407
+ "description": "Indicates the max dimension for images in teacher instructions",
408
+ "type": "number",
409
+ "title": "teacherInstructions"
410
+ },
411
+ "prompt": {
412
+ "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",
413
+ "type": "number",
414
+ "title": "prompt"
415
+ },
416
+ "rationale": {
417
+ "description": "Indicates the max dimension for images in rationale",
418
+ "type": "number",
419
+ "title": "rationale"
420
+ },
421
+ "choicesWithPlacementArea": {
422
+ "description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled",
423
+ "type": "number",
424
+ "title": "choicesWithPlacementArea"
425
+ },
426
+ "choicesWithoutPlacementArea": {
427
+ "description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled",
428
+ "type": "number",
429
+ "title": "choicesWithoutPlacementArea"
430
+ },
431
+ "choices": {
432
+ "description": "Only available for the height prop: indicates the max height for images in choices and choices labels",
433
+ "type": "number",
434
+ "title": "choices"
435
+ }
436
+ }
297
437
  }
298
438
  },
299
439
  "$schema": "http://json-schema.org/draft-07/schema#"