@pie-element/multiple-choice 5.9.0 → 5.9.3-next.1014

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/multiple-choice-configure",
3
- "version": "3.4.0",
3
+ "version": "4.1.6",
4
4
  "private": true,
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -8,9 +8,9 @@
8
8
  "@material-ui/core": "^3.9.2",
9
9
  "@material-ui/icons": "^3.0.1",
10
10
  "@pie-framework/pie-configure-events": "^1.2.0",
11
- "@pie-lib/config-ui": "^10.9.2",
12
- "@pie-lib/editable-html": "^7.16.19",
13
- "@pie-lib/scoring-config": "^3.5.128",
11
+ "@pie-lib/config-ui": "^10.13.3",
12
+ "@pie-lib/editable-html": "^7.22.6",
13
+ "@pie-lib/scoring-config": "^3.5.163",
14
14
  "debug": "^3.1.0",
15
15
  "lodash": "^4.17.15",
16
16
  "prop-types": "^15.6.2",
@@ -3,6 +3,60 @@
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
+ ## [3.5.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/multiple-choice-controller@3.4.1...@pie-element/multiple-choice-controller@3.5.1) (2021-11-11)
7
+
8
+ **Note:** Version bump only for package @pie-element/multiple-choice-controller
9
+
10
+
11
+
12
+
13
+
14
+ # [3.5.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/multiple-choice-controller@3.3.3...@pie-element/multiple-choice-controller@3.5.0) (2021-11-11)
15
+
16
+
17
+ ### Features
18
+
19
+ * **multiple-choice:** accessibility label - added aria label to checkbox and radio input types ([22514bb](https://github.com/pie-framework/pie-elements/commit/22514bb5e2476bc79a55756ff9a5c0c1e0642a29))
20
+ * if there are no choices - do not show grid columns dropdown BREAKING CHANGE: removed verticalMode(boolean) from model & configuration - and replaced it with choicesLayout(string) ([1c36ae8](https://github.com/pie-framework/pie-elements/commit/1c36ae8b7f9369b2723a6a84e7350370e1186c50))
21
+ * **multiple-choice:** added possibility to change layout - vertical, grid, horizontal ([46e7681](https://github.com/pie-framework/pie-elements/commit/46e7681a178ff29c983db1c7b6206389b55e2a00))
22
+
23
+
24
+
25
+
26
+
27
+
28
+ ## [3.4.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/multiple-choice-controller@3.4.0...@pie-element/multiple-choice-controller@3.4.1) (2021-09-01)
29
+
30
+ **Note:** Version bump only for package @pie-element/multiple-choice-controller
31
+
32
+
33
+
34
+
35
+
36
+ # [3.4.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/multiple-choice-controller@3.3.3...@pie-element/multiple-choice-controller@3.4.0) (2021-08-05)
37
+
38
+
39
+ ### Features
40
+
41
+ * **multiple-choice:** accessibility label - added aria label to checkbox and radio input types ([22514bb](https://github.com/pie-framework/pie-elements/commit/22514bb5e2476bc79a55756ff9a5c0c1e0642a29))
42
+ * if there are no choices - do not show grid columns dropdown BREAKING CHANGE: removed verticalMode(boolean) from model & configuration - and replaced it with choicesLayout(string) ([1c36ae8](https://github.com/pie-framework/pie-elements/commit/1c36ae8b7f9369b2723a6a84e7350370e1186c50))
43
+ * **multiple-choice:** added possibility to change layout - vertical, grid, horizontal ([46e7681](https://github.com/pie-framework/pie-elements/commit/46e7681a178ff29c983db1c7b6206389b55e2a00))
44
+
45
+
46
+
47
+
48
+
49
+ ## [3.3.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/multiple-choice-controller@3.3.1...@pie-element/multiple-choice-controller@3.3.3) (2021-08-05)
50
+
51
+
52
+ ### Bug Fixes
53
+
54
+ * force bump ([5ea7295](https://github.com/pie-framework/pie-elements/commit/5ea7295e4755fbc492a76e7ec69e5fc35b196919))
55
+
56
+
57
+
58
+
59
+
6
60
  ## [3.3.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/multiple-choice-controller@3.3.0...@pie-element/multiple-choice-controller@3.3.1) (2021-06-29)
7
61
 
8
62
  **Note:** Version bump only for package @pie-element/multiple-choice-controller
@@ -7,10 +7,12 @@ exports["default"] = void 0;
7
7
  var _default = {
8
8
  promptEnabled: true,
9
9
  rationaleEnabled: true,
10
+ accessibilityLabelsEnabled: false,
10
11
  teacherInstructionsEnabled: true,
11
12
  studentInstructionsEnabled: true,
12
- verticalMode: true,
13
- choicePrefix: 'letters'
13
+ choicePrefix: 'letters',
14
+ choicesLayout: 'vertical',
15
+ gridColumns: '2'
14
16
  };
15
17
  exports["default"] = _default;
16
18
  //# sourceMappingURL=defaults.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.js"],"names":["promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","verticalMode","choicePrefix"],"mappings":";;;;;;eAAe;AACbA,EAAAA,aAAa,EAAE,IADF;AAEbC,EAAAA,gBAAgB,EAAE,IAFL;AAGbC,EAAAA,0BAA0B,EAAE,IAHf;AAIbC,EAAAA,0BAA0B,EAAE,IAJf;AAKbC,EAAAA,YAAY,EAAE,IALD;AAMbC,EAAAA,YAAY,EAAE;AAND,C","sourcesContent":["export default {\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n verticalMode: true,\n choicePrefix: 'letters',\n};\n"],"file":"defaults.js"}
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["promptEnabled","rationaleEnabled","accessibilityLabelsEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","choicePrefix","choicesLayout","gridColumns"],"mappings":";;;;;;eAAe;AACbA,EAAAA,aAAa,EAAE,IADF;AAEbC,EAAAA,gBAAgB,EAAE,IAFL;AAGbC,EAAAA,0BAA0B,EAAE,KAHf;AAIbC,EAAAA,0BAA0B,EAAE,IAJf;AAKbC,EAAAA,0BAA0B,EAAE,IALf;AAMbC,EAAAA,YAAY,EAAE,SAND;AAObC,EAAAA,aAAa,EAAE,UAPF;AAQbC,EAAAA,WAAW,EAAE;AARA,C","sourcesContent":["export default {\n promptEnabled: true,\n rationaleEnabled: true,\n accessibilityLabelsEnabled: false,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n choicePrefix: 'letters',\n choicesLayout: 'vertical',\n gridColumns: '2'\n};\n"],"file":"defaults.js"}
@@ -5,15 +5,22 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.createCorrectResponseSession = void 0;
8
9
  exports.createDefaultModel = createDefaultModel;
10
+ exports.getScore = void 0;
9
11
  exports.model = model;
12
+ exports.normalize = void 0;
10
13
  exports.outcome = outcome;
11
- exports.createCorrectResponseSession = exports.getScore = exports.normalize = void 0;
14
+ exports.validate = void 0;
12
15
 
13
16
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
17
 
18
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
19
+
15
20
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
21
 
22
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
23
+
17
24
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
25
 
19
26
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
@@ -24,9 +31,11 @@ var _defaults = _interopRequireDefault(require("./defaults"));
24
31
 
25
32
  var _controllerUtils = require("@pie-lib/controller-utils");
26
33
 
27
- 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; }
34
+ var _excluded = ["verticalMode", "choicesLayout"];
28
35
 
29
- 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; }
36
+ 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; }
37
+
38
+ 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; }
30
39
 
31
40
  var prepareChoice = function prepareChoice(model, env, defaultFeedback) {
32
41
  return function (choice) {
@@ -39,6 +48,10 @@ var prepareChoice = function prepareChoice(model, env, defaultFeedback) {
39
48
  value: choice.value
40
49
  };
41
50
 
51
+ if (model.accessibilityLabelsEnabled) {
52
+ out.accessibility = (0, _utils.parseHTML)(choice.accessibility).textContent || choice.value;
53
+ }
54
+
42
55
  if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
43
56
  out.rationale = model.rationaleEnabled ? choice.rationale : null;
44
57
  } else {
@@ -71,7 +84,16 @@ function createDefaultModel() {
71
84
  }
72
85
 
73
86
  var normalize = function normalize(question) {
74
- return _objectSpread(_objectSpread({}, _defaults["default"]), question);
87
+ var _ref2 = question || {},
88
+ verticalMode = _ref2.verticalMode,
89
+ choicesLayout = _ref2.choicesLayout,
90
+ questionProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
91
+
92
+ return _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"]), questionProps), {}, {
93
+ // This is used for offering support for old models which have the property verticalMode
94
+ // Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel
95
+ choicesLayout: choicesLayout || verticalMode === false && 'horizontal' || _defaults["default"].choicesLayout
96
+ });
75
97
  };
76
98
  /**
77
99
  *
@@ -90,7 +112,7 @@ function model(_x, _x2, _x3, _x4) {
90
112
 
91
113
  function _model() {
92
114
  _model = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(question, session, env, updateSession) {
93
- var normalizedQuestion, defaultFeedback, choices, lockChoiceOrder, out, _ref3, role, mode;
115
+ var normalizedQuestion, defaultFeedback, choices, lockChoiceOrder, out, _ref4, role, mode;
94
116
 
95
117
  return _regenerator["default"].wrap(function _callee$(_context) {
96
118
  while (1) {
@@ -120,13 +142,14 @@ function _model() {
120
142
  disabled: env.mode !== 'gather',
121
143
  mode: env.mode,
122
144
  prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
123
- verticalMode: normalizedQuestion.verticalMode,
145
+ choicesLayout: normalizedQuestion.choicesLayout,
146
+ gridColumns: normalizedQuestion.gridColumns,
124
147
  choiceMode: normalizedQuestion.choiceMode,
125
148
  keyMode: normalizedQuestion.choicePrefix,
126
149
  choices: choices,
127
150
  responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(normalizedQuestion, session) : undefined
128
151
  };
129
- _ref3 = env || {}, role = _ref3.role, mode = _ref3.mode;
152
+ _ref4 = env || {}, role = _ref4.role, mode = _ref4.mode;
130
153
 
131
154
  if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
132
155
  out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
@@ -206,10 +229,10 @@ function outcome(model, session, env) {
206
229
  var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
207
230
  return new Promise(function (resolve) {
208
231
  if (env.mode !== 'evaluate' && env.role === 'instructor') {
209
- var _ref2 = question || {
232
+ var _ref3 = question || {
210
233
  choices: []
211
234
  },
212
- choices = _ref2.choices;
235
+ choices = _ref3.choices;
213
236
 
214
237
  resolve({
215
238
  id: '1',
@@ -226,4 +249,57 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
226
249
  };
227
250
 
228
251
  exports.createCorrectResponseSession = createCorrectResponseSession;
252
+
253
+ var validate = function validate() {
254
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
255
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
256
+ var choices = model.choices;
257
+ var _config$minAnswerChoi = config.minAnswerChoices,
258
+ minAnswerChoices = _config$minAnswerChoi === void 0 ? 2 : _config$minAnswerChoi,
259
+ maxAnswerChoices = config.maxAnswerChoices;
260
+ var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
261
+ var choicesErrors = {};
262
+ var hasCorrectResponse = false;
263
+ reversedChoices.forEach(function (choice, index) {
264
+ var correct = choice.correct,
265
+ value = choice.value,
266
+ label = choice.label;
267
+
268
+ if (correct) {
269
+ hasCorrectResponse = true;
270
+ }
271
+
272
+ if (label === '' || label === '<div></div>') {
273
+ choicesErrors[value] = 'Content should not be empty.';
274
+ } else {
275
+ var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
276
+ return c.label === label;
277
+ });
278
+
279
+ if (identicalAnswer) {
280
+ choicesErrors[value] = 'Content should be unique.';
281
+ }
282
+ }
283
+ });
284
+ var errors = {};
285
+ var nbOfChoices = (choices || []).length;
286
+
287
+ if (nbOfChoices < minAnswerChoices) {
288
+ errors.answerChoicesError = "There should be at least ".concat(minAnswerChoices, " choices defined.");
289
+ } else if (nbOfChoices > maxAnswerChoices) {
290
+ errors.answerChoicesError = "No more than ".concat(maxAnswerChoices, " choices should be defined.");
291
+ }
292
+
293
+ if (!hasCorrectResponse) {
294
+ errors.correctResponseError = 'No correct response defined.';
295
+ }
296
+
297
+ if (!(0, _isEmpty["default"])(choicesErrors)) {
298
+ errors.choicesErrors = choicesErrors;
299
+ }
300
+
301
+ return errors;
302
+ };
303
+
304
+ exports.validate = validate;
229
305
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["prepareChoice","model","env","defaultFeedback","choice","role","mode","out","label","value","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","createDefaultModel","Promise","resolve","defaults","normalize","question","session","updateSession","normalizedQuestion","Object","assign","incorrect","choices","map","lockChoiceOrder","disabled","prompt","promptEnabled","verticalMode","choiceMode","keyMode","choicePrefix","responseCorrect","undefined","teacherInstructions","teacherInstructionsEnabled","getScore","config","selectedChoices","correctChoices","filter","ch","score","reduce","acc","selectedChoice","find","length","str","parseFloat","toFixed","outcome","empty","partialScoringEnabled","partialScoring","enabled","createCorrectResponseSession","id","c"],"mappings":";;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAQC,GAAR,EAAaC,eAAb;AAAA,SAAiC,UAAAC,MAAM,EAAI;AAAA,eACxCF,GAAG,IAAI,EADiC;AAAA,QACvDG,IADuD,QACvDA,IADuD;AAAA,QACjDC,IADiD,QACjDA,IADiD;;AAE/D,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KADJ;AAEVC,MAAAA,KAAK,EAAEL,MAAM,CAACK;AAFJ,KAAZ;;AAKA,QAAIJ,IAAI,KAAK,YAAT,KAA0BC,IAAI,KAAK,MAAT,IAAmBA,IAAI,KAAK,UAAtD,CAAJ,EAAuE;AACrEC,MAAAA,GAAG,CAACG,SAAJ,GAAgBT,KAAK,CAACU,gBAAN,GAAyBP,MAAM,CAACM,SAAhC,GAA4C,IAA5D;AACD,KAFD,MAEO;AACLH,MAA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OAAO,CAACkB,MAAR,CAAe,UAAAkB,CAAC;AAAA,iBAAIA,CAAC,CAACrD,OAAN;AAAA,SAAhB,EAA+BkB,GAA/B,CAAmC,UAAAmC,CAAC;AAAA,iBAAIA,CAAC,CAACxD,KAAN;AAAA,SAApC;AAFD,OAAD,CAAP;AAID,KAPD,MAOO;AACLU,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAXM,CAAP;AAYD,CAbM","sourcesContent":["/* eslint-disable no-console */\nimport isEmpty from 'lodash/isEmpty';\nimport { isResponseCorrect } from './utils';\nimport defaults from './defaults';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-lib/controller-utils';\n\nconst prepareChoice = (model, env, defaultFeedback) => choice => {\n const { role, mode } = env || {};\n const out = {\n label: choice.label,\n value: choice.value\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = model.rationaleEnabled ? choice.rationale : null;\n } else {\n out.rationale = null;\n }\n\n if (mode === 'evaluate') {\n out.correct = !!choice.correct;\n\n if (model.feedbackEnabled) {\n const feedbackType = (choice.feedback && choice.feedback.type) || 'none';\n\n if (feedbackType === 'default') {\n out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];\n } else if (feedbackType === 'custom') {\n out.feedback = choice.feedback.value;\n }\n }\n }\n\n return out;\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => resolve({ ...defaults, ...model }));\n}\n\nexport const normalize = question => ({ ...defaults, ...question });\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n const normalizedQuestion = normalize(question);\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n normalizedQuestion.defaultFeedback\n );\n\n let choices = normalizedQuestion.choices.map(\n prepareChoice(normalizedQuestion, env, defaultFeedback)\n );\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(\n choices,\n session,\n updateSession,\n 'value'\n );\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n verticalMode: normalizedQuestion.verticalMode,\n choiceMode: normalizedQuestion.choiceMode,\n keyMode: normalizedQuestion.choicePrefix,\n choices,\n responseCorrect:\n env.mode === 'evaluate' ? isResponseCorrect(normalizedQuestion, session) : undefined\n };\n\n const { role, mode } = env || {};\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.teacherInstructions = null;\n }\n\n return out;\n}\n\n\nexport const getScore = (config, session) => {\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n const selectedChoices = session.value || [];\n const correctChoices = (config.choices || []).filter(ch => ch.correct);\n\n let score = selectedChoices.reduce((acc, selectedChoice) =>\n acc + (correctChoices.find(ch => ch.value === selectedChoice) ? 1 : 0), 0);\n\n if (correctChoices.length < selectedChoices.length) {\n score -= selectedChoices.length - correctChoices.length;\n\n if (score < 0) {\n score = 0;\n }\n }\n\n const str = correctChoices.length ? score / correctChoices.length : 0;\n\n return parseFloat(str.toFixed(2));\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will\n * override the value in `model`.\n * @param {Object} model - the main model\n * @param {*} session\n * @param {Object} env\n */\nexport function outcome(model, session, env) {\n return new Promise(resolve => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n } else {\n const partialScoringEnabled =\n partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n const score = getScore(model, session);\n\n resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question || { choices: [] };\n\n resolve({\n id: '1',\n value: choices.filter(c => c.correct).map(c => c.value)\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["prepareChoice","model","env","defaultFeedback","choice","role","mode","out","label","value","accessibilityLabelsEnabled","accessibility","textContent","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","createDefaultModel","Promise","resolve","defaults","normalize","question","verticalMode","choicesLayout","questionProps","session","updateSession","normalizedQuestion","Object","assign","incorrect","choices","map","lockChoiceOrder","disabled","prompt","promptEnabled","gridColumns","choiceMode","keyMode","choicePrefix","responseCorrect","undefined","teacherInstructions","teacherInstructionsEnabled","getScore","config","selectedChoices","correctChoices","filter","ch","score","reduce","acc","selectedChoice","find","length","str","parseFloat","toFixed","outcome","empty","partialScoringEnabled","partialScoring","enabled","createCorrectResponseSession","id","c","validate","minAnswerChoices","maxAnswerChoices","reversedChoices","reverse","choicesErrors","hasCorrectResponse","forEach","index","identicalAnswer","slice","some","errors","nbOfChoices","answerChoicesError","correctResponseError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAQC,GAAR,EAAaC,eAAb;AAAA,SAAiC,UAAAC,MAAM,EAAI;AAC/D,eAAuBF,GAAG,IAAI,EAA9B;AAAA,QAAQG,IAAR,QAAQA,IAAR;AAAA,QAAcC,IAAd,QAAcA,IAAd;;AACA,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KADJ;AAEVC,MAAAA,KAAK,EAAEL,MAAM,CAACK;AAFJ,KAAZ;;AAKA,QAAIR,KAAK,CAACS,0BAAV,EAAsC;AACpCH,MAAAA,GAAG,CAACI,aAAJ,GAAoB,sBAAUP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,IAAAA,MAAM,CAACP,aAAP,GAAuBA,aAAvB;AACD;;AAED,SAAOO,MAAP;AACD,CA3CM","sourcesContent":["/* eslint-disable no-console */\nimport isEmpty from 'lodash/isEmpty';\nimport { isResponseCorrect, parseHTML } from './utils';\nimport defaults from './defaults';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-lib/controller-utils';\n\nconst prepareChoice = (model, env, defaultFeedback) => choice => {\n const { role, mode } = env || {};\n const out = {\n label: choice.label,\n value: choice.value,\n };\n\n if (model.accessibilityLabelsEnabled) {\n out.accessibility = parseHTML(choice.accessibility).textContent || choice.value;\n }\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = model.rationaleEnabled ? choice.rationale : null;\n } else {\n out.rationale = null;\n }\n\n if (mode === 'evaluate') {\n out.correct = !!choice.correct;\n\n if (model.feedbackEnabled) {\n const feedbackType = (choice.feedback && choice.feedback.type) || 'none';\n\n if (feedbackType === 'default') {\n out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];\n } else if (feedbackType === 'custom') {\n out.feedback = choice.feedback.value;\n }\n }\n }\n\n return out;\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => resolve({ ...defaults, ...model }));\n}\n\nexport const normalize = question => {\n const { verticalMode, choicesLayout, ...questionProps } = question || {};\n\n return {\n ...defaults,\n ...questionProps,\n // This is used for offering support for old models which have the property verticalMode\n // Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel\n choicesLayout: choicesLayout || (verticalMode === false && 'horizontal') || defaults.choicesLayout\n };\n};\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n const normalizedQuestion = normalize(question);\n\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n normalizedQuestion.defaultFeedback\n );\n\n let choices = normalizedQuestion.choices.map(\n prepareChoice(normalizedQuestion, env, defaultFeedback)\n );\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(\n choices,\n session,\n updateSession,\n 'value'\n );\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n choicesLayout: normalizedQuestion.choicesLayout,\n gridColumns: normalizedQuestion.gridColumns,\n choiceMode: normalizedQuestion.choiceMode,\n keyMode: normalizedQuestion.choicePrefix,\n choices,\n responseCorrect:\n env.mode === 'evaluate' ? isResponseCorrect(normalizedQuestion, session) : undefined\n };\n\n const { role, mode } = env || {};\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.teacherInstructions = null;\n }\n\n return out;\n}\n\n\nexport const getScore = (config, session) => {\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n const selectedChoices = session.value || [];\n const correctChoices = (config.choices || []).filter(ch => ch.correct);\n\n let score = selectedChoices.reduce((acc, selectedChoice) =>\n acc + (correctChoices.find(ch => ch.value === selectedChoice) ? 1 : 0), 0);\n\n if (correctChoices.length < selectedChoices.length) {\n score -= selectedChoices.length - correctChoices.length;\n\n if (score < 0) {\n score = 0;\n }\n }\n\n const str = correctChoices.length ? score / correctChoices.length : 0;\n\n return parseFloat(str.toFixed(2));\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will\n * override the value in `model`.\n * @param {Object} model - the main model\n * @param {*} session\n * @param {Object} env\n */\nexport function outcome(model, session, env) {\n return new Promise(resolve => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n } else {\n const partialScoringEnabled =\n partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n const score = getScore(model, session);\n\n resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question || { choices: [] };\n\n resolve({\n id: '1',\n value: choices.filter(c => c.correct).map(c => c.value)\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { choices } = model;\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n const reversedChoices = [...choices || []].reverse();\n const choicesErrors = {};\n let hasCorrectResponse = false;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n }\n\n if (label === '' || label === '<div></div>') {\n choicesErrors[value] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[value] = 'Content should be unique.';\n }\n }\n });\n\n const errors = {};\n const nbOfChoices = (choices || []).length;\n\n if (nbOfChoices < minAnswerChoices) {\n errors.answerChoicesError = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.answerChoicesError = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (!hasCorrectResponse) {\n errors.correctResponseError = 'No correct response defined.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\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.isResponseCorrect = exports.getCorrectResponse = void 0;
8
+ exports.parseHTML = exports.isResponseCorrect = exports.getCorrectResponse = void 0;
9
9
 
10
10
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
11
11
 
@@ -25,4 +25,12 @@ var isResponseCorrect = function isResponseCorrect(question, session) {
25
25
  };
26
26
 
27
27
  exports.isResponseCorrect = isResponseCorrect;
28
+
29
+ var parseHTML = function parseHTML(html) {
30
+ var template = document.createElement('template');
31
+ template.innerHTML = html;
32
+ return template.content;
33
+ };
34
+
35
+ exports.parseHTML = parseHTML;
28
36
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","value","sort","isResponseCorrect","question","session","correctResponse"],"mappings":";;;;;;;;;AAAA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAAaA,OAAO,CACnDC,MAD4C,CACrC,UAAAC,CAAC;AAAA,WAAIA,CAAC,CAACC,OAAN;AAAA,GADoC,EAE5CC,GAF4C,CAExC,UAAAF,CAAC;AAAA,WAAIA,CAAC,CAACG,KAAN;AAAA,GAFuC,EAG5CC,IAH4C,EAAb;AAAA,CAA3B;;;;AAKA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,OAAX,EAAuB;AACtD,MAAIC,eAAe,GAAGX,kBAAkB,CAACS,QAAQ,CAACR,OAAV,CAAxC;AACA,SAAOS,OAAO,IAAI,yBAAQ,CAACA,OAAO,CAACJ,KAAR,IAAiB,EAAlB,EAAsBC,IAAtB,EAAR,EAAsCI,eAAtC,CAAlB;AACD,CAHM","sourcesContent":["import isEqual from 'lodash/isEqual';\n\nexport const getCorrectResponse = (choices) => choices\n .filter(c => c.correct)\n .map(c => c.value)\n .sort();\n\nexport const isResponseCorrect = (question, session) => {\n let correctResponse = getCorrectResponse(question.choices);\n return session && isEqual((session.value || []).sort(), correctResponse);\n};\n"],"file":"utils.js"}
1
+ {"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","value","sort","isResponseCorrect","question","session","correctResponse","parseHTML","html","template","document","createElement","innerHTML","content"],"mappings":";;;;;;;;;AAAA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAAaA,OAAO,CACnDC,MAD4C,CACrC,UAAAC,CAAC;AAAA,WAAIA,CAAC,CAACC,OAAN;AAAA,GADoC,EAE5CC,GAF4C,CAExC,UAAAF,CAAC;AAAA,WAAIA,CAAC,CAACG,KAAN;AAAA,GAFuC,EAG5CC,IAH4C,EAAb;AAAA,CAA3B;;;;AAKA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,OAAX,EAAuB;AACtD,MAAIC,eAAe,GAAGX,kBAAkB,CAACS,QAAQ,CAACR,OAAV,CAAxC;AACA,SAAOS,OAAO,IAAI,yBAAQ,CAACA,OAAO,CAACJ,KAAR,IAAiB,EAAlB,EAAsBC,IAAtB,EAAR,EAAsCI,eAAtC,CAAlB;AACD,CAHM;;;;AAKA,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,IAAD,EAAU;AACjC,MAAMC,QAAQ,GAAGC,QAAQ,CAACC,aAAT,CAAuB,UAAvB,CAAjB;AACAF,EAAAA,QAAQ,CAACG,SAAT,GAAqBJ,IAArB;AACA,SAAOC,QAAQ,CAACI,OAAhB;AACD,CAJM","sourcesContent":["import isEqual from 'lodash/isEqual';\n\nexport const getCorrectResponse = (choices) => choices\n .filter(c => c.correct)\n .map(c => c.value)\n .sort();\n\nexport const isResponseCorrect = (question, session) => {\n let correctResponse = getCorrectResponse(question.choices);\n return session && isEqual((session.value || []).sort(), correctResponse);\n};\n\nexport const parseHTML = (html) => {\n const template = document.createElement('template');\n template.innerHTML = html;\n return template.content;\n};\n"],"file":"utils.js"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/multiple-choice-controller",
3
3
  "private": true,
4
- "version": "3.3.1",
4
+ "version": "3.5.4",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
@@ -106,7 +106,39 @@
106
106
  }
107
107
  }
108
108
  },
109
- "verticalMode": {
109
+ "spellCheck": {
110
+ "title": "ConfigureProp",
111
+ "type": "object",
112
+ "properties": {
113
+ "settings": {
114
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
115
+ "type": "boolean",
116
+ "title": "settings"
117
+ },
118
+ "label": {
119
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
120
+ "type": "string",
121
+ "title": "label"
122
+ }
123
+ }
124
+ },
125
+ "choicesLayout": {
126
+ "title": "ConfigureProp",
127
+ "type": "object",
128
+ "properties": {
129
+ "settings": {
130
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
131
+ "type": "boolean",
132
+ "title": "settings"
133
+ },
134
+ "label": {
135
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
136
+ "type": "string",
137
+ "title": "label"
138
+ }
139
+ }
140
+ },
141
+ "gridColumns": {
110
142
  "title": "ConfigureProp",
111
143
  "type": "object",
112
144
  "properties": {
@@ -239,6 +271,84 @@
239
271
  }
240
272
  }
241
273
  },
274
+ "accessibility": {
275
+ "title": "ConfigureProp",
276
+ "type": "object",
277
+ "properties": {
278
+ "settings": {
279
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
280
+ "type": "boolean",
281
+ "title": "settings"
282
+ },
283
+ "label": {
284
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
285
+ "type": "string",
286
+ "title": "label"
287
+ }
288
+ }
289
+ },
290
+ "minAnswerChoices": {
291
+ "description": "Minimum number of answer choices",
292
+ "type": "number",
293
+ "title": "minAnswerChoices"
294
+ },
295
+ "maxAnswerChoices": {
296
+ "description": "Maximum number of answer choices",
297
+ "type": "number",
298
+ "title": "maxAnswerChoices"
299
+ },
300
+ "maxImageWidth": {
301
+ "title": "ConfigureMaxImageDimensionsProp",
302
+ "type": "object",
303
+ "properties": {
304
+ "teacherInstructions": {
305
+ "description": "Indicates the max dimension for images in teacher instructions",
306
+ "type": "number",
307
+ "title": "teacherInstructions"
308
+ },
309
+ "prompt": {
310
+ "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",
311
+ "type": "number",
312
+ "title": "prompt"
313
+ },
314
+ "rationale": {
315
+ "description": "Indicates the max dimension for images in rationale",
316
+ "type": "number",
317
+ "title": "rationale"
318
+ },
319
+ "choices": {
320
+ "description": "Indicates the max dimension for images in choices",
321
+ "type": "number",
322
+ "title": "choices"
323
+ }
324
+ }
325
+ },
326
+ "maxImageHeight": {
327
+ "title": "ConfigureMaxImageDimensionsProp",
328
+ "type": "object",
329
+ "properties": {
330
+ "teacherInstructions": {
331
+ "description": "Indicates the max dimension for images in teacher instructions",
332
+ "type": "number",
333
+ "title": "teacherInstructions"
334
+ },
335
+ "prompt": {
336
+ "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",
337
+ "type": "number",
338
+ "title": "prompt"
339
+ },
340
+ "rationale": {
341
+ "description": "Indicates the max dimension for images in rationale",
342
+ "type": "number",
343
+ "title": "rationale"
344
+ },
345
+ "choices": {
346
+ "description": "Indicates the max dimension for images in choices",
347
+ "type": "number",
348
+ "title": "choices"
349
+ }
350
+ }
351
+ },
242
352
  "showPrompt": {
243
353
  "description": "Determines whether prompt field will be displayed or not",
244
354
  "default": true,
@@ -289,6 +399,32 @@
289
399
  "title": "enabled"
290
400
  }
291
401
  }
402
+ },
403
+ "ConfigureMaxImageDimensionsProp": {
404
+ "title": "ConfigureMaxImageDimensionsProp",
405
+ "type": "object",
406
+ "properties": {
407
+ "teacherInstructions": {
408
+ "description": "Indicates the max dimension for images in teacher instructions",
409
+ "type": "number",
410
+ "title": "teacherInstructions"
411
+ },
412
+ "prompt": {
413
+ "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",
414
+ "type": "number",
415
+ "title": "prompt"
416
+ },
417
+ "rationale": {
418
+ "description": "Indicates the max dimension for images in rationale",
419
+ "type": "number",
420
+ "title": "rationale"
421
+ },
422
+ "choices": {
423
+ "description": "Indicates the max dimension for images in choices",
424
+ "type": "number",
425
+ "title": "choices"
426
+ }
427
+ }
292
428
  }
293
429
  },
294
430
  "$schema": "http://json-schema.org/draft-07/schema#"