@pie-element/ebsr 8.5.1-beta.1 → 8.5.1-beta.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/main.jsx"],"names":["Panel","settings","toggle","radio","dropdown","styles","theme","part","display","flexDirection","paddingTop","spacing","unit","Main","choices","correctFound","map","choice","correct","model","key","onModelChanged","props","partA","choiceMode","removeExtraChoices","partB","classes","configuration","onConfigurationChanged","partLabelType","modelPartA","modelPartB","partialScoring","settingsPanelDisabled","scoringType","generalConfiguration","feedback","feedbackA","choiceModeA","choicePrefix","choicePrefixA","lockChoiceOrder","lockChoiceOrderA","prompt","promptA","teacherInstructions","teacherInstructionsA","studentInstructions","studentInstructionsA","choicesLayout","choicesLayoutA","gridColumns","gridColumnsA","rationale","rationaleA","spellCheck","spellCheckA","feedbackB","choiceModeB","choicePrefixB","lockChoiceOrderB","promptB","teacherInstructionsB","studentInstructionsB","choicesLayoutB","gridColumnsB","rationaleB","spellCheckB","type","typeIsNumber","firstPart","secondPart","nrOfColumnsAvailable","length","Array","from","_","i","panelSettings","partLabels","label","panelSettingsPartA","panelPropertiesPartA","panelSettingsPartB","panelPropertiesPartB","ref","_model","errors","React","Component","PropTypes","object","func","Styled"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAEA,IAAQA,KAAR,GAA2CC,kBAA3C,CAAQD,KAAR;AAAA,IAAeE,MAAf,GAA2CD,kBAA3C,CAAeC,MAAf;AAAA,IAAuBC,KAAvB,GAA2CF,kBAA3C,CAAuBE,KAAvB;AAAA,IAA8BC,QAA9B,GAA2CH,kBAA3C,CAA8BG,QAA9B;;AAEA,IAAMC,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,IAAI,EAAE;AACJC,MAAAA,OAAO,EAAE,MADL;AAEJC,MAAAA,aAAa,E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,CAAWH,KAAX,CAAiBqE,MAAjB,IAA2B,MAAI,CAAClE,KAAL,CAAWH,KAAX,CAAiBqE,MAAjB,CAAwB9D,KAApD,IAA8D;AAFxE;AAIA,YAAA,MAAI,CAACA,KAAL,CAAWE,aAAX,mCACKF,KADL,GAEKU,oBAFL;AAID;AACF;AAhBH,QAFF,CAvBF,CAlBF,CADF;AAkED;;;EA9MuBqD,kBAAMC,S;;;iCAAnB7E,I,eACQ;AACjBc,EAAAA,OAAO,EAAEgE,sBAAUC,MADF;AAEjBhE,EAAAA,aAAa,EAAE+D,sBAAUC,MAFR;AAGjBzE,EAAAA,KAAK,EAAEwE,sBAAUC,MAHA;AAIjBvE,EAAAA,cAAc,EAAEsE,sBAAUE,IAJT;AAKjBhE,EAAAA,sBAAsB,EAAE8D,sBAAUE;AALjB,C;AAgNrB,IAAMC,MAAM,GAAG,wBAAWzF,MAAX,EAAmBQ,IAAnB,CAAf;eAEeiF,M","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { settings, layout } from '@pie-lib/config-ui';\nimport { withStyles } from '@material-ui/core/styles';\n\nconst { Panel, toggle, radio, dropdown } = settings;\n\nconst styles = (theme) => ({\n part: {\n display: 'flex',\n flexDirection: 'column',\n '&:not(:first-child)': {\n paddingTop: theme.spacing.unit * 4,\n },\n },\n});\n\nexport class Main extends React.Component {\n static propTypes = {\n classes: PropTypes.object,\n configuration: PropTypes.object,\n model: PropTypes.object,\n onModelChanged: PropTypes.func,\n onConfigurationChanged: PropTypes.func,\n };\n\n removeExtraChoices = (choices) => {\n let correctFound = false;\n\n return (choices || []).map((choice) => {\n if (correctFound) {\n choice.correct = false;\n\n return choice;\n }\n\n if (choice.correct) {\n correctFound = true;\n }\n\n return choice;\n });\n };\n\n onModelChanged = (model, key) => {\n const { onModelChanged } = this.props;\n\n if (key === 'partA.choiceMode' && model.partA.choiceMode === 'radio') {\n model.partA.choices = this.removeExtraChoices(model.partA.choices);\n\n return onModelChanged(model, true);\n }\n\n if (key === 'partB.choiceMode' && model.partB.choiceMode === 'radio') {\n model.partB.choices = this.removeExtraChoices(model.partB.choices);\n\n return onModelChanged(model, true);\n }\n\n return onModelChanged(model);\n };\n\n render() {\n const { classes, model, configuration, onConfigurationChanged } = this.props;\n const { partLabelType, partA: modelPartA, partB: modelPartB } = model;\n const { partA, partB, partialScoring, settingsPanelDisabled, scoringType, ...generalConfiguration } = configuration;\n const {\n feedback: feedbackA = {},\n choiceMode: choiceModeA = {},\n choicePrefix: choicePrefixA = {},\n lockChoiceOrder: lockChoiceOrderA = {},\n prompt: promptA = {},\n teacherInstructions: teacherInstructionsA = {},\n studentInstructions: studentInstructionsA = {},\n choicesLayout: choicesLayoutA = {},\n gridColumns: gridColumnsA = {},\n rationale: rationaleA = {},\n spellCheck: spellCheckA = {},\n } = partA || {};\n const {\n feedback: feedbackB = {},\n choiceMode: choiceModeB = {},\n choicePrefix: choicePrefixB = {},\n lockChoiceOrder: lockChoiceOrderB = {},\n prompt: promptB = {},\n teacherInstructions: teacherInstructionsB = {},\n studentInstructions: studentInstructionsB = {},\n choicesLayout: choicesLayoutB = {},\n gridColumns: gridColumnsB = {},\n rationale: rationaleB = {},\n spellCheck: spellCheckB = {},\n } = partB || {};\n\n const type = partLabelType || 'Numbers';\n const typeIsNumber = type === 'Numbers';\n const firstPart = `Part ${typeIsNumber ? '1' : 'A'}`;\n const secondPart = `Part ${typeIsNumber ? '2' : 'B'}`;\n const nrOfColumnsAvailable = {\n partA:\n modelPartA.choices && modelPartA.choices.length\n ? Array.from({ length: modelPartA.choices.length }, (_, i) => `${i + 1}`)\n : [],\n partB:\n modelPartB.choices && modelPartB.choices.length\n ? Array.from({ length: modelPartB.choices.length }, (_, i) => `${i + 1}`)\n : [],\n };\n\n const panelSettings = {\n partLabels: generalConfiguration.partLabels.settings && toggle(generalConfiguration.partLabels.label),\n partLabelType: model.partLabels && dropdown('', ['Numbers', 'Letters']),\n partialScoring: partialScoring.settings && toggle(partialScoring.label),\n scoringType: scoringType.settings && radio(scoringType.label, ['auto', 'rubric']),\n };\n\n const panelSettingsPartA = {\n 'partA.choiceMode': choiceModeA.settings && radio(choiceModeA.label, ['checkbox', 'radio']),\n 'partA.choicePrefix': choicePrefixA.settings && radio(choicePrefixA.label, ['numbers', 'letters']),\n 'partA.lockChoiceOrder': lockChoiceOrderA.settings && toggle(lockChoiceOrderA.label),\n 'partA.choicesLayout':\n choicesLayoutA.settings && dropdown(choicesLayoutA.label, ['vertical', 'grid', 'horizontal']),\n 'partA.gridColumns':\n choicesLayoutA.settings &&\n modelPartA.choicesLayout === 'grid' &&\n nrOfColumnsAvailable.partA.length > 0 &&\n dropdown(gridColumnsA.label, nrOfColumnsAvailable.partA),\n };\n const panelPropertiesPartA = {\n 'partA.feedbackEnabled': feedbackA.settings && toggle(feedbackA.label),\n 'partA.promptEnabled': promptA.settings && toggle(promptA.label),\n 'partA.teacherInstructionsEnabled': teacherInstructionsA.settings && toggle(teacherInstructionsA.label),\n 'partA.studentInstructionsEnabled': studentInstructionsA.settings && toggle(studentInstructionsA.label),\n 'partA.rationaleEnabled': rationaleA.settings && toggle(rationaleA.label),\n 'partA.spellCheckEnabled': spellCheckA.settings && toggle(spellCheckA.label),\n };\n\n const panelSettingsPartB = {\n 'partB.choiceMode': choiceModeB.settings && radio(choiceModeB.label, ['checkbox', 'radio']),\n 'partB.choicePrefix': choicePrefixB.settings && radio(choicePrefixB.label, ['numbers', 'letters']),\n 'partB.lockChoiceOrder': lockChoiceOrderB.settings && toggle(lockChoiceOrderB.label),\n 'partB.choicesLayout':\n choicesLayoutB.settings && dropdown(choicesLayoutB.label, ['vertical', 'grid', 'horizontal']),\n 'partB.gridColumns':\n choicesLayoutB.settings &&\n modelPartB.choicesLayout === 'grid' &&\n nrOfColumnsAvailable.partB.length > 0 &&\n dropdown(gridColumnsB.label, nrOfColumnsAvailable.partB),\n };\n const panelPropertiesPartB = {\n 'partB.feedbackEnabled': feedbackB.settings && toggle(feedbackB.label),\n 'partB.promptEnabled': promptB.settings && toggle(promptB.label),\n 'partB.teacherInstructionsEnabled': teacherInstructionsB.settings && toggle(teacherInstructionsB.label),\n 'partB.studentInstructionsEnabled': studentInstructionsB.settings && toggle(studentInstructionsB.label),\n 'partB.rationaleEnabled': rationaleB.settings && toggle(rationaleB.label),\n 'partB.spellCheckEnabled': spellCheckB.settings && toggle(spellCheckB.label),\n };\n\n return (\n <layout.ConfigLayout\n hideSettings={settingsPanelDisabled}\n settings={\n <Panel\n model={model}\n onChangeModel={this.onModelChanged}\n configuration={configuration}\n onChangeConfiguration={onConfigurationChanged}\n groups={{\n 'Settings for both': panelSettings,\n [`Settings ${firstPart}`]: panelSettingsPartA,\n [`Properties ${firstPart}`]: panelPropertiesPartA,\n [`Settings ${secondPart}`]: panelSettingsPartB,\n [`Properties ${secondPart}`]: panelPropertiesPartB,\n }}\n />\n }\n >\n <div>\n <div className={classes.part}>\n {model.partLabels && <div>{firstPart}</div>}\n <ebsr-multiple-choice-configure\n id=\"A\"\n key=\"partA\"\n ref={(ref) => {\n if (ref) {\n // do not use destructuring to get model from props\n this.partA = ref;\n this.partA._model = {\n ...this.props.model.partA,\n errors: (this.props.model.errors && this.props.model.errors.partA) || {},\n };\n this.partA.configuration = {\n ...partA,\n ...generalConfiguration,\n };\n }\n }}\n />\n </div>\n\n <div className={classes.part}>\n {model.partLabels && <div>{secondPart}</div>}\n <ebsr-multiple-choice-configure\n id=\"B\"\n key=\"partB\"\n ref={(ref) => {\n if (ref) {\n // do not use destructuring to get model from props\n this.partB = ref;\n this.partB._model = {\n ...this.props.model.partB,\n errors: (this.props.model.errors && this.props.model.errors.partB) || {},\n };\n this.partB.configuration = {\n ...partB,\n ...generalConfiguration,\n };\n }\n }}\n />\n </div>\n </div>\n </layout.ConfigLayout>\n );\n }\n}\n\nconst Styled = withStyles(styles)(Main);\n\nexport default Styled;\n"],"file":"main.js"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _default = {
8
+ partA: {
9
+ choicePrefix: 'letters',
10
+ choices: [{
11
+ value: 'a',
12
+ label: 'label a'
13
+ }],
14
+ prompt: 'prompt a',
15
+ disabled: false
16
+ },
17
+ partB: {
18
+ choicePrefix: 'letters',
19
+ choices: [{
20
+ value: 'b',
21
+ label: 'label b'
22
+ }],
23
+ prompt: 'prompt b',
24
+ disabled: false
25
+ }
26
+ };
27
+ exports["default"] = _default;
28
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["partA","choicePrefix","choices","value","label","prompt","disabled","partB"],"mappings":";;;;;;eAAe;AACbA,EAAAA,KAAK,EAAE;AACLC,IAAAA,YAAY,EAAE,SADT;AAELC,IAAAA,OAAO,EAAE,CACP;AACEC,MAAAA,KAAK,EAAE,GADT;AAEEC,MAAAA,KAAK,EAAE;AAFT,KADO,CAFJ;AAQLC,IAAAA,MAAM,EAAE,UARH;AASLC,IAAAA,QAAQ,EAAE;AATL,GADM;AAYbC,EAAAA,KAAK,EAAE;AACLN,IAAAA,YAAY,EAAE,SADT;AAELC,IAAAA,OAAO,EAAE,CACP;AACEC,MAAAA,KAAK,EAAE,GADT;AAEEC,MAAAA,KAAK,EAAE;AAFT,KADO,CAFJ;AAQLC,IAAAA,MAAM,EAAE,UARH;AASLC,IAAAA,QAAQ,EAAE;AATL;AAZM,C","sourcesContent":["export default {\n partA: {\n choicePrefix: 'letters',\n choices: [\n {\n value: 'a',\n label: 'label a',\n },\n ],\n prompt: 'prompt a',\n disabled: false,\n },\n partB: {\n choicePrefix: 'letters',\n choices: [\n {\n value: 'b',\n label: 'label b',\n },\n ],\n prompt: 'prompt b',\n disabled: false,\n },\n};\n"],"file":"defaults.js"}
@@ -0,0 +1,473 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
9
+ exports.model = model;
10
+ exports.normalize = void 0;
11
+ exports.outcome = outcome;
12
+ exports.validate = void 0;
13
+
14
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
15
+
16
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
17
+
18
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
19
+
20
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
21
+
22
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
+
24
+ var _defaults = _interopRequireDefault(require("./defaults"));
25
+
26
+ var _controllerUtils = require("@pie-lib/controller-utils");
27
+
28
+ var _utils = require("./utils");
29
+
30
+ var _get = _interopRequireDefault(require("lodash/get"));
31
+
32
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
33
+
34
+ var _excluded = ["partA", "partB"];
35
+
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; }
39
+
40
+ var prepareChoice = function prepareChoice(model, env, defaultFeedback) {
41
+ return function (choice) {
42
+ var out = {
43
+ label: choice.label,
44
+ value: choice.value
45
+ };
46
+
47
+ if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
48
+ out.rationale = model.rationaleEnabled ? choice.rationale : null;
49
+ } else {
50
+ out.rationale = null;
51
+ }
52
+
53
+ if (env.mode === 'evaluate') {
54
+ out.correct = !!choice.correct;
55
+
56
+ if (model.feedbackEnabled) {
57
+ var feedbackType = choice.feedback && choice.feedback.type || 'none';
58
+
59
+ if (feedbackType === 'default') {
60
+ out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
61
+ } else if (feedbackType === 'custom') {
62
+ out.feedback = choice.feedback.value;
63
+ }
64
+ }
65
+ }
66
+
67
+ return out;
68
+ };
69
+ };
70
+
71
+ var parsePart = function parsePart(part, key, session, env) {
72
+ var defaultFeedback = Object.assign({
73
+ correct: 'Correct',
74
+ incorrect: 'Incorrect'
75
+ }, part.defaultFeedback);
76
+ var choices = part.choices ? part.choices.map(prepareChoice(part, env, defaultFeedback)) : [];
77
+ return _objectSpread(_objectSpread({}, part), {}, {
78
+ choices: choices,
79
+ disabled: env.mode !== 'gather',
80
+ complete: {
81
+ min: part.choices.filter(function (c) {
82
+ return c.correct;
83
+ }).length
84
+ },
85
+ responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(part, key, session) : undefined
86
+ });
87
+ };
88
+
89
+ var normalize = function normalize(_ref) {
90
+ var _ref$partA = _ref.partA,
91
+ partA = _ref$partA === void 0 ? {} : _ref$partA,
92
+ _ref$partB = _ref.partB,
93
+ partB = _ref$partB === void 0 ? {} : _ref$partB,
94
+ question = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
95
+ return _objectSpread(_objectSpread({
96
+ partLabels: true,
97
+ partLabelType: 'Letters'
98
+ }, question), {}, {
99
+ partA: _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"].partA), {}, {
100
+ rationaleEnabled: true,
101
+ feedbackEnabled: true,
102
+ promptEnabled: true,
103
+ teacherInstructionsEnabled: true,
104
+ studentInstructionsEnabled: true,
105
+ gridColumns: '2'
106
+ }, partA), {}, {
107
+ choicesLayout: partA.choicesLayout || partA.verticalMode === false && 'horizontal' || 'vertical'
108
+ }),
109
+ partB: _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"].partB), {}, {
110
+ rationaleEnabled: true,
111
+ promptEnabled: true,
112
+ feedbackEnabled: true,
113
+ teacherInstructionsEnabled: true,
114
+ studentInstructionsEnabled: true,
115
+ gridColumns: '2'
116
+ }, partB), {}, {
117
+ choicesLayout: partB.choicesLayout || partB.verticalMode === false && 'horizontal' || 'vertical'
118
+ })
119
+ });
120
+ };
121
+ /**
122
+ *
123
+ * @param {*} question
124
+ * @param {*} session
125
+ * @param {*} env
126
+ * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
127
+ */
128
+
129
+
130
+ exports.normalize = normalize;
131
+
132
+ function model(_x, _x2, _x3, _x4) {
133
+ return _model.apply(this, arguments);
134
+ }
135
+
136
+ function _model() {
137
+ _model = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(question, session, env, updateSession) {
138
+ var normalizedQuestion, partA, partB, shuffledValues, us, partASession, partALockChoiceOrder, _ref8, partAChoices, _ref9, partBChoices, partBSession, partBLockChoiceOrder;
139
+
140
+ return _regenerator["default"].wrap(function _callee$(_context) {
141
+ while (1) {
142
+ switch (_context.prev = _context.next) {
143
+ case 0:
144
+ normalizedQuestion = normalize(question);
145
+ partA = parsePart(normalizedQuestion.partA, 'partA', session, env);
146
+ partB = parsePart(normalizedQuestion.partB, 'partB', session, env);
147
+ shuffledValues = {};
148
+
149
+ us = function us(part) {
150
+ return function (id, element, update) {
151
+ return new Promise(function (resolve) {
152
+ shuffledValues[part] = update.shuffledValues;
153
+ resolve();
154
+ });
155
+ };
156
+ };
157
+
158
+ partASession = (0, _get["default"])(session, 'value.partA');
159
+ partALockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion.partA, partASession, env);
160
+ _ref8 = partA || {}, partAChoices = _ref8.choices;
161
+ _ref9 = partB || {}, partBChoices = _ref9.choices;
162
+
163
+ if (!(!partALockChoiceOrder && partAChoices && partAChoices.length)) {
164
+ _context.next = 13;
165
+ break;
166
+ }
167
+
168
+ _context.next = 12;
169
+ return (0, _controllerUtils.getShuffledChoices)(partAChoices, {
170
+ shuffledValues: (session.shuffledValues || {}).partA
171
+ }, us('partA'), 'value');
172
+
173
+ case 12:
174
+ partA.choices = _context.sent;
175
+
176
+ case 13:
177
+ partBSession = (0, _get["default"])(session, 'value.partB');
178
+ partBLockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion.partB, partBSession, env);
179
+
180
+ if (!(!partBLockChoiceOrder && partBChoices && partBChoices.length)) {
181
+ _context.next = 19;
182
+ break;
183
+ }
184
+
185
+ _context.next = 18;
186
+ return (0, _controllerUtils.getShuffledChoices)(partBChoices, {
187
+ shuffledValues: (session.shuffledValues || {}).partB
188
+ }, us('partB'), 'value');
189
+
190
+ case 18:
191
+ partB.choices = _context.sent;
192
+
193
+ case 19:
194
+ if (!(0, _isEmpty["default"])(shuffledValues)) {
195
+ if (updateSession && typeof updateSession === 'function') {
196
+ updateSession(session.id, session.element, {
197
+ shuffledValues: shuffledValues
198
+ })["catch"](function (e) {
199
+ console.error('update session failed', e);
200
+ });
201
+ }
202
+ }
203
+
204
+ if (normalizedQuestion.partLabels) {
205
+ partA.partLabel = normalizedQuestion.partLabelType === 'Letters' ? 'Part A' : 'Part 1';
206
+ partB.partLabel = normalizedQuestion.partLabelType === 'Letters' ? 'Part B' : 'Part 2';
207
+ } else {
208
+ partA.partLabel = undefined;
209
+ partB.partLabel = undefined;
210
+ }
211
+
212
+ if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
213
+ partA.teacherInstructions = normalizedQuestion.partA.teacherInstructionsEnabled ? normalizedQuestion.partA.teacherInstructions : null;
214
+ partB.teacherInstructions = normalizedQuestion.partB.teacherInstructionsEnabled ? normalizedQuestion.partB.teacherInstructions : null;
215
+ } else {
216
+ partA.teacherInstructions = null;
217
+ partB.teacherInstructions = null;
218
+ }
219
+
220
+ partA.prompt = normalizedQuestion.partA.promptEnabled ? normalizedQuestion.partA.prompt : null;
221
+ partB.prompt = normalizedQuestion.partB.promptEnabled ? normalizedQuestion.partB.prompt : null;
222
+ return _context.abrupt("return", new Promise(function (resolve) {
223
+ resolve({
224
+ disabled: env.mode !== 'gather',
225
+ mode: env.mode,
226
+ partA: partA,
227
+ partB: partB
228
+ });
229
+ }));
230
+
231
+ case 25:
232
+ case "end":
233
+ return _context.stop();
234
+ }
235
+ }
236
+ }, _callee);
237
+ }));
238
+ return _model.apply(this, arguments);
239
+ }
240
+
241
+ var createDefaultModel = function createDefaultModel() {
242
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
243
+ return new Promise(function (resolve) {
244
+ resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
245
+ });
246
+ };
247
+
248
+ exports.createDefaultModel = createDefaultModel;
249
+
250
+ var isCorrect = function isCorrect(c) {
251
+ return c.correct === true;
252
+ };
253
+
254
+ var getScore = function getScore(config, sessionPart, key, partialScoringEnabled) {
255
+ var _ref2 = config && config[key] || {},
256
+ _ref2$choices = _ref2.choices,
257
+ choices = _ref2$choices === void 0 ? [] : _ref2$choices;
258
+
259
+ var maxScore = choices.length;
260
+
261
+ var _ref3 = sessionPart || {},
262
+ sessionPartValue = _ref3.value;
263
+
264
+ var chosen = function chosen(c) {
265
+ return !!(sessionPartValue || []).find(function (v) {
266
+ return v === c.value;
267
+ });
268
+ };
269
+
270
+ var correctAndNotChosen = function correctAndNotChosen(c) {
271
+ return isCorrect(c) && !chosen(c);
272
+ };
273
+
274
+ var incorrectAndChosen = function incorrectAndChosen(c) {
275
+ return !isCorrect(c) && chosen(c);
276
+ };
277
+
278
+ var correctChoices = choices.reduce(function (total, choice) {
279
+ if (correctAndNotChosen(choice) || incorrectAndChosen(choice)) {
280
+ return total - 1;
281
+ } else {
282
+ return total;
283
+ }
284
+ }, choices.length); // determine score for a part
285
+
286
+ if (!partialScoringEnabled && correctChoices < maxScore) {
287
+ return 0;
288
+ }
289
+
290
+ return parseFloat(maxScore ? (correctChoices / maxScore).toFixed(2) : 0);
291
+ };
292
+
293
+ function outcome(config, session, env) {
294
+ return new Promise(function (resolve) {
295
+ var _ref4 = session || {},
296
+ value = _ref4.value;
297
+
298
+ if (!session || !value) {
299
+ resolve({
300
+ score: 0,
301
+ scoreA: 0,
302
+ scoreB: 0,
303
+ empty: true
304
+ });
305
+ }
306
+
307
+ if (value) {
308
+ var _ref5 = value || {},
309
+ partA = _ref5.partA,
310
+ partB = _ref5.partB;
311
+
312
+ var partialScoringEnabled = _controllerUtils.partialScoring.enabled(config, env);
313
+
314
+ var scoreA = getScore(config, partA, 'partA', partialScoringEnabled);
315
+ var scoreB = getScore(config, partB, 'partB', partialScoringEnabled);
316
+
317
+ if (!partialScoringEnabled) {
318
+ // The EBSR item is worth 1 point
319
+ // That point is awarded if and only if both parts are fully correct, otherwise no points are awarded
320
+ resolve({
321
+ score: scoreA === 1 && scoreB === 1 ? 1 : 0,
322
+ scoreA: scoreA,
323
+ scoreB: scoreB,
324
+ max: 1
325
+ });
326
+ } else {
327
+ // The EBSR item is worth 2 points
328
+ if (scoreA === 1) {
329
+ if (scoreB === 1) {
330
+ // If Part A and Part B are both correct, 2 points are awarded
331
+ resolve({
332
+ score: 2,
333
+ scoreA: scoreA,
334
+ scoreB: scoreB,
335
+ max: 2
336
+ });
337
+ } else {
338
+ // If Part A is correct and part B is incorrect, 1 point is awarded
339
+ resolve({
340
+ score: 1,
341
+ scoreA: scoreA,
342
+ scoreB: scoreB,
343
+ max: 2
344
+ });
345
+ }
346
+ } else {
347
+ // For all other combinations, no points are awarded
348
+ resolve({
349
+ score: 0,
350
+ scoreA: scoreA,
351
+ scoreB: scoreB,
352
+ max: 2
353
+ });
354
+ }
355
+ }
356
+ }
357
+ });
358
+ }
359
+
360
+ var returnPartCorrect = function returnPartCorrect(choices) {
361
+ var answers = [];
362
+ choices.forEach(function (i) {
363
+ var correct = i.correct,
364
+ value = i.value;
365
+
366
+ if (correct) {
367
+ answers.push(value);
368
+ }
369
+ });
370
+ return answers;
371
+ };
372
+
373
+ var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
374
+ return new Promise(function (resolve) {
375
+ if (env.mode !== 'evaluate' && env.role === 'instructor') {
376
+ var partA = question.partA,
377
+ partB = question.partB;
378
+ var partACorrect = returnPartCorrect(partA.choices);
379
+ var partBCorrect = returnPartCorrect(partB.choices);
380
+ resolve({
381
+ value: {
382
+ partA: {
383
+ id: 'partA',
384
+ value: partACorrect
385
+ },
386
+ partB: {
387
+ id: 'partB',
388
+ value: partBCorrect
389
+ }
390
+ },
391
+ id: '1'
392
+ });
393
+ } else {
394
+ resolve(null);
395
+ }
396
+ });
397
+ };
398
+
399
+ exports.createCorrectResponseSession = createCorrectResponseSession;
400
+
401
+ var validatePart = function validatePart() {
402
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
403
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
404
+ var choices = model.choices;
405
+ var _config$minAnswerChoi = config.minAnswerChoices,
406
+ minAnswerChoices = _config$minAnswerChoi === void 0 ? 2 : _config$minAnswerChoi,
407
+ maxAnswerChoices = config.maxAnswerChoices;
408
+ var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
409
+ var choicesErrors = {};
410
+ var hasCorrectResponse = false;
411
+ reversedChoices.forEach(function (choice, index) {
412
+ var correct = choice.correct,
413
+ value = choice.value,
414
+ label = choice.label;
415
+
416
+ if (correct) {
417
+ hasCorrectResponse = true;
418
+ }
419
+
420
+ if (label === '' || label === '<div></div>') {
421
+ choicesErrors[value] = 'Content should not be empty.';
422
+ } else {
423
+ var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
424
+ return c.label === label;
425
+ });
426
+
427
+ if (identicalAnswer) {
428
+ choicesErrors[value] = 'Content should be unique.';
429
+ }
430
+ }
431
+ });
432
+ var errors = {};
433
+ var nbOfChoices = (choices || []).length;
434
+
435
+ if (nbOfChoices < minAnswerChoices) {
436
+ errors.answerChoicesError = "There should be at least ".concat(minAnswerChoices, " choices defined.");
437
+ } else if (nbOfChoices > maxAnswerChoices) {
438
+ errors.answerChoicesError = "No more than ".concat(maxAnswerChoices, " choices should be defined.");
439
+ }
440
+
441
+ if (!hasCorrectResponse) {
442
+ errors.correctResponseError = 'No correct response defined.';
443
+ }
444
+
445
+ if (!(0, _isEmpty["default"])(choicesErrors)) {
446
+ errors.choicesErrors = choicesErrors;
447
+ }
448
+
449
+ return errors;
450
+ };
451
+
452
+ var validate = function validate() {
453
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
454
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
455
+
456
+ var _ref6 = model || {},
457
+ partA = _ref6.partA,
458
+ partB = _ref6.partB;
459
+
460
+ var _ref7 = config || {},
461
+ partAConfig = _ref7.partA,
462
+ partBConfig = _ref7.partB;
463
+
464
+ var partAErrors = validatePart(partA, partAConfig);
465
+ var partBErrors = validatePart(partB, partBConfig);
466
+ return {
467
+ partA: partAErrors,
468
+ partB: partBErrors
469
+ };
470
+ };
471
+
472
+ exports.validate = validate;
473
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.js"],"names":["prepareChoice","model","env","defaultFeedback","choice","out","label","value","role","mode","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","parsePart","part","key","session","Object","assign","incorrect","choices","map","disabled","complete","min","filter","c","length","responseCorrect","undefined","normalize","partA","partB","question","partLabels","partLabelType","defaults","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","gridColumns","choicesLayout","verticalMode","updateSession","normalizedQuestion","shuffledValues","us","id","element","update","Promise","resolve","partASession","partALockChoiceOrder","partAChoices","partBChoices","partBSession","partBLockChoiceOrder","e","console","error","partLabel","teacherInstructions","prompt","createDefaultModel","isCorrect","getScore","config","sessionPart","partialScoringEnabled","maxScore","sessionPartValue","chosen","find","v","correctAndNotChosen","incorrectAndChosen","correctChoices","reduce","total","parseFloat","toFixed","outcome","score","scoreA","scoreB","empty","partialScoring","enabled","max","returnPartCorrect","answers","forEach","i","push","createCorrectResponseSession","partACorrect","partBCorrect","validatePart","minAnswerChoices","maxAnswerChoices","reversedChoices","reverse","choicesErrors","hasCorrectResponse","index","identicalAnswer","slice","some","errors","nbOfChoices","answerChoicesError","correctResponseError","validate","partAConfig","partBConfig","partAErrors","partBErrors"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAQC,GAAR,EAAaC,eAAb;AAAA,SAAiC,UAACC,MAAD,EAAY;AACjE,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEF,MAAM,CAACE,KADJ;AAEVC,MAAAA,KAAK,EAAEH,MAAM,CAACG;AAFJ,KAAZ;;AAKA,QAAIL,GAAG,CAACM,IAAJ,KAAa,YAAb,KAA8BN,GAAG,CAACO,IAAJ,KAAa,MAAb,IAAuBP,GAAG,CAACO,IAAJ,KAAa,UAAlE,CAAJ,EAAmF;AACjFJ,MAAAA,GAAG,CAACK,SAAJ,GAAgBT,KAAK,CAACU,gBAAN,GAAyBP,MAAM,CAACM,SAAhC,GAA4C,IAA5D;AACD,KAFD,MAEO;AACLL,MAAAA,GAAG,CAACK,SAAJ,GAAgB,IAAhB;AACD;;AAED,QAAIR,GAAG,CAACO,IAAJ,KAAa,UAAjB,EAA6B;AAC3BJ,MAAAA,GAAG,CAACO,OAAJ,GAAc,CAAC,CAACR,MAAM,CAACQ,OAAvB;;AAEA,UAAIX,KAAK,CAACY,eAAV,EAA2B;AACzB,YAAMC,YAAY,GAAIV,MAAM,CAACW,QAAP,IAAmBX,MAAM,CAACW,QAAP,C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AACD,GAFD,MAEO,IAAIW,WAAW,GAAGV,gBAAlB,EAAoC;AACzCS,IAAAA,MAAM,CAACE,kBAAP,0BAA4CX,gBAA5C;AACD;;AAED,MAAI,CAACI,kBAAL,EAAyB;AACvBK,IAAAA,MAAM,CAACG,oBAAP,GAA8B,8BAA9B;AACD;;AAED,MAAI,CAAC,yBAAQT,aAAR,CAAL,EAA6B;AAC3BM,IAAAA,MAAM,CAACN,aAAP,GAAuBA,aAAvB;AACD;;AAED,SAAOM,MAAP;AACD,CA3CD;;AA6CO,IAAMI,QAAQ,GAAG,SAAXA,QAAW,GAA6B;AAAA,MAA5BpH,KAA4B,uEAApB,EAAoB;AAAA,MAAhBsE,MAAgB,uEAAP,EAAO;;AACnD,cAAyBtE,KAAK,IAAI,EAAlC;AAAA,MAAQkC,KAAR,SAAQA,KAAR;AAAA,MAAeC,KAAf,SAAeA,KAAf;;AACA,cAAmDmC,MAAM,IAAI,EAA7D;AAAA,MAAe+C,WAAf,SAAQnF,KAAR;AAAA,MAAmCoF,WAAnC,SAA4BnF,KAA5B;;AAEA,MAAMoF,WAAW,GAAGlB,YAAY,CAACnE,KAAD,EAAQmF,WAAR,CAAhC;AACA,MAAMG,WAAW,GAAGnB,YAAY,CAAClE,KAAD,EAAQmF,WAAR,CAAhC;AAEA,SAAO;AAAEpF,IAAAA,KAAK,EAAEqF,WAAT;AAAsBpF,IAAAA,KAAK,EAAEqF;AAA7B,GAAP;AACD,CARM","sourcesContent":["import defaults from './defaults';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport { isResponseCorrect } from './utils';\nimport get from 'lodash/get';\nimport isEmpty from 'lodash/isEmpty';\n\nconst prepareChoice = (model, env, defaultFeedback) => (choice) => {\n const out = {\n label: choice.label,\n value: choice.value,\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.rationale = model.rationaleEnabled ? choice.rationale : null;\n } else {\n out.rationale = null;\n }\n\n if (env.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\nconst parsePart = (part, key, session, env) => {\n const defaultFeedback = Object.assign({ correct: 'Correct', incorrect: 'Incorrect' }, part.defaultFeedback);\n\n let choices = part.choices ? part.choices.map(prepareChoice(part, env, defaultFeedback)) : [];\n\n return {\n ...part,\n choices,\n disabled: env.mode !== 'gather',\n complete: {\n min: part.choices.filter((c) => c.correct).length,\n },\n responseCorrect: env.mode === 'evaluate' ? isResponseCorrect(part, key, session) : undefined,\n };\n};\n\nexport const normalize = ({ partA = {}, partB = {}, ...question }) => ({\n partLabels: true,\n partLabelType: 'Letters',\n ...question,\n partA: {\n ...defaults.partA,\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n gridColumns: '2',\n ...partA,\n choicesLayout: partA.choicesLayout || (partA.verticalMode === false && 'horizontal') || 'vertical',\n },\n partB: {\n ...defaults.partB,\n rationaleEnabled: true,\n promptEnabled: true,\n feedbackEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n gridColumns: '2',\n ...partB,\n choicesLayout: partB.choicesLayout || (partB.verticalMode === false && 'horizontal') || 'vertical',\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 const partA = parsePart(normalizedQuestion.partA, 'partA', session, env);\n const partB = parsePart(normalizedQuestion.partB, 'partB', session, env);\n\n const shuffledValues = {};\n\n const us = (part) => (id, element, update) =>\n new Promise((resolve) => {\n shuffledValues[part] = update.shuffledValues;\n resolve();\n });\n\n const partASession = get(session, 'value.partA');\n const partALockChoiceOrder = lockChoices(normalizedQuestion.partA, partASession, env);\n\n const { choices: partAChoices } = partA || {};\n const { choices: partBChoices } = partB || {};\n\n if (!partALockChoiceOrder && partAChoices && partAChoices.length) {\n partA.choices = await getShuffledChoices(\n partAChoices,\n { shuffledValues: (session.shuffledValues || {}).partA },\n us('partA'),\n 'value',\n );\n }\n\n const partBSession = get(session, 'value.partB');\n const partBLockChoiceOrder = lockChoices(normalizedQuestion.partB, partBSession, env);\n\n if (!partBLockChoiceOrder && partBChoices && partBChoices.length) {\n partB.choices = await getShuffledChoices(\n partBChoices,\n { shuffledValues: (session.shuffledValues || {}).partB },\n us('partB'),\n 'value',\n );\n }\n\n if (!isEmpty(shuffledValues)) {\n if (updateSession && typeof updateSession === 'function') {\n updateSession(session.id, session.element, {\n shuffledValues,\n }).catch((e) => {\n console.error('update session failed', e);\n });\n }\n }\n\n if (normalizedQuestion.partLabels) {\n partA.partLabel = normalizedQuestion.partLabelType === 'Letters' ? 'Part A' : 'Part 1';\n partB.partLabel = normalizedQuestion.partLabelType === 'Letters' ? 'Part B' : 'Part 2';\n } else {\n partA.partLabel = undefined;\n partB.partLabel = undefined;\n }\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n partA.teacherInstructions = normalizedQuestion.partA.teacherInstructionsEnabled\n ? normalizedQuestion.partA.teacherInstructions\n : null;\n partB.teacherInstructions = normalizedQuestion.partB.teacherInstructionsEnabled\n ? normalizedQuestion.partB.teacherInstructions\n : null;\n } else {\n partA.teacherInstructions = null;\n partB.teacherInstructions = null;\n }\n\n partA.prompt = normalizedQuestion.partA.promptEnabled ? normalizedQuestion.partA.prompt : null;\n partB.prompt = normalizedQuestion.partB.promptEnabled ? normalizedQuestion.partB.prompt : null;\n\n return new Promise((resolve) => {\n resolve({\n disabled: env.mode !== 'gather',\n mode: env.mode,\n partA,\n partB,\n });\n });\n}\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nconst isCorrect = (c) => c.correct === true;\n\nconst getScore = (config, sessionPart, key, partialScoringEnabled) => {\n const { choices = [] } = (config && config[key]) || {};\n const maxScore = choices.length;\n const { value: sessionPartValue } = sessionPart || {};\n\n const chosen = (c) => !!(sessionPartValue || []).find((v) => v === c.value);\n const correctAndNotChosen = (c) => isCorrect(c) && !chosen(c);\n const incorrectAndChosen = (c) => !isCorrect(c) && chosen(c);\n const correctChoices = choices.reduce((total, choice) => {\n if (correctAndNotChosen(choice) || incorrectAndChosen(choice)) {\n return total - 1;\n } else {\n return total;\n }\n }, choices.length);\n\n // determine score for a part\n if (!partialScoringEnabled && correctChoices < maxScore) {\n return 0;\n }\n\n return parseFloat(maxScore ? (correctChoices / maxScore).toFixed(2) : 0);\n};\n\nexport function outcome(config, session, env) {\n return new Promise((resolve) => {\n const { value } = session || {};\n\n if (!session || !value) {\n resolve({ score: 0, scoreA: 0, scoreB: 0, empty: true });\n }\n\n if (value) {\n const { partA, partB } = value || {};\n\n const partialScoringEnabled = partialScoring.enabled(config, env);\n\n const scoreA = getScore(config, partA, 'partA', partialScoringEnabled);\n const scoreB = getScore(config, partB, 'partB', partialScoringEnabled);\n\n if (!partialScoringEnabled) {\n // The EBSR item is worth 1 point\n // That point is awarded if and only if both parts are fully correct, otherwise no points are awarded\n resolve({ score: scoreA === 1 && scoreB === 1 ? 1 : 0, scoreA, scoreB, max: 1 });\n } else {\n // The EBSR item is worth 2 points\n if (scoreA === 1) {\n if (scoreB === 1) {\n // If Part A and Part B are both correct, 2 points are awarded\n resolve({ score: 2, scoreA, scoreB, max: 2 });\n } else {\n // If Part A is correct and part B is incorrect, 1 point is awarded\n resolve({ score: 1, scoreA, scoreB, max: 2 });\n }\n } else {\n // For all other combinations, no points are awarded\n resolve({ score: 0, scoreA, scoreB, max: 2 });\n }\n }\n }\n });\n}\n\nconst returnPartCorrect = (choices) => {\n let answers = [];\n\n choices.forEach((i) => {\n const { correct, value } = i;\n if (correct) {\n answers.push(value);\n }\n });\n return answers;\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { partA, partB } = question;\n\n const partACorrect = returnPartCorrect(partA.choices);\n const partBCorrect = returnPartCorrect(partB.choices);\n\n resolve({\n value: {\n partA: {\n id: 'partA',\n value: partACorrect,\n },\n partB: {\n id: 'partB',\n value: partBCorrect,\n },\n },\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\nconst validatePart = (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\nexport const validate = (model = {}, config = {}) => {\n const { partA, partB } = model || {};\n const { partA: partAConfig, partB: partBConfig } = config || {};\n\n const partAErrors = validatePart(partA, partAConfig);\n const partBErrors = validatePart(partB, partBConfig);\n\n return { partA: partAErrors, partB: partBErrors };\n};\n"],"file":"index.js"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.isResponseCorrect = exports.getCorrectResponse = void 0;
9
+
10
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
11
+
12
+ var getCorrectResponse = function getCorrectResponse(choices) {
13
+ return choices && choices.filter(function (c) {
14
+ return c.correct;
15
+ }).map(function (c) {
16
+ return c.value;
17
+ }).sort();
18
+ };
19
+
20
+ exports.getCorrectResponse = getCorrectResponse;
21
+
22
+ var isResponseCorrect = function isResponseCorrect(question, key, session) {
23
+ var correctResponse = getCorrectResponse(question.choices);
24
+
25
+ if (session && session.value) {
26
+ return (0, _isEqual["default"])((session.value[key].value || []).sort(), correctResponse);
27
+ }
28
+
29
+ return false;
30
+ };
31
+
32
+ exports.isResponseCorrect = isResponseCorrect;
33
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","value","sort","isResponseCorrect","question","key","session","correctResponse"],"mappings":";;;;;;;;;AAAA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAChCA,OAAO,IACPA,OAAO,CACJC,MADH,CACU,UAACC,CAAD;AAAA,WAAOA,CAAC,CAACC,OAAT;AAAA,GADV,EAEGC,GAFH,CAEO,UAACF,CAAD;AAAA,WAAOA,CAAC,CAACG,KAAT;AAAA,GAFP,EAGGC,IAHH,EAFgC;AAAA,CAA3B;;;;AAOA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,GAAX,EAAgBC,OAAhB,EAA4B;AAC3D,MAAIC,eAAe,GAAGZ,kBAAkB,CAACS,QAAQ,CAACR,OAAV,CAAxC;;AAEA,MAAIU,OAAO,IAAIA,OAAO,CAACL,KAAvB,EAA8B;AAC5B,WAAO,yBAAQ,CAACK,OAAO,CAACL,KAAR,CAAcI,GAAd,EAAmBJ,KAAnB,IAA4B,EAA7B,EAAiCC,IAAjC,EAAR,EAAiDK,eAAjD,CAAP;AACD;;AAED,SAAO,KAAP;AACD,CARM","sourcesContent":["import isEqual from 'lodash/isEqual';\n\nexport const getCorrectResponse = (choices) =>\n choices &&\n choices\n .filter((c) => c.correct)\n .map((c) => c.value)\n .sort();\n\nexport const isResponseCorrect = (question, key, session) => {\n let correctResponse = getCorrectResponse(question.choices);\n\n if (session && session.value) {\n return isEqual((session.value[key].value || []).sort(), correctResponse);\n }\n\n return false;\n};\n"],"file":"utils.js"}