@pie-element/multiple-choice 7.6.1-beta.3 → 7.6.1-beta.4

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,"file":"utils.js","names":["generateValidationMessage","config","minAnswerChoices","maxAnswerChoices","answerChoicesMessage","concat","correctAnswerMessage","message","exports"],"sources":["../src/utils.js"],"sourcesContent":["export const generateValidationMessage = (config) => {\n const { minAnswerChoices, maxAnswerChoices } = config;\n\n const answerChoicesMessage =\n `\\nThere should be at least ${minAnswerChoices} ` +\n (maxAnswerChoices ? `and at most ${maxAnswerChoices} ` : '') +\n 'answer choices defined.' +\n '\\nEvery answer choice should be non-blank and unique.';\n\n const correctAnswerMessage = '\\nA correct answer must be defined.';\n\n const message = 'Validation requirements:' + answerChoicesMessage + correctAnswerMessage;\n\n return message;\n};\n"],"mappings":";;;;;;AAAO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAAyBA,CAAIC,MAAM,EAAK;EACnD,IAAQC,gBAAgB,GAAuBD,MAAM,CAA7CC,gBAAgB;IAAEC,gBAAgB,GAAKF,MAAM,CAA3BE,gBAAgB;EAE1C,IAAMC,oBAAoB,GACxB,8BAAAC,MAAA,CAA8BH,gBAAgB,UAC7CC,gBAAgB,kBAAAE,MAAA,CAAkBF,gBAAgB,SAAM,EAAE,CAAC,GAC5D,yBAAyB,GACzB,uDAAuD;EAEzD,IAAMG,oBAAoB,GAAG,qCAAqC;EAElE,IAAMC,OAAO,GAAG,0BAA0B,GAAGH,oBAAoB,GAAGE,oBAAoB;EAExF,OAAOC,OAAO;AAChB,CAAC;AAACC,OAAA,CAAAR,yBAAA,GAAAA,yBAAA"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _default = {
8
+ promptEnabled: true,
9
+ rationaleEnabled: true,
10
+ accessibilityLabelsEnabled: false,
11
+ teacherInstructionsEnabled: true,
12
+ studentInstructionsEnabled: true,
13
+ choicePrefix: 'letters',
14
+ choicesLayout: 'vertical',
15
+ gridColumns: '2'
16
+ };
17
+ exports["default"] = _default;
18
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","names":["promptEnabled","rationaleEnabled","accessibilityLabelsEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","choicePrefix","choicesLayout","gridColumns","exports","_default"],"sources":["../src/defaults.js"],"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"],"mappings":";;;;;;eAAe;EACbA,aAAa,EAAE,IAAI;EACnBC,gBAAgB,EAAE,IAAI;EACtBC,0BAA0B,EAAE,KAAK;EACjCC,0BAA0B,EAAE,IAAI;EAChCC,0BAA0B,EAAE,IAAI;EAChCC,YAAY,EAAE,SAAS;EACvBC,aAAa,EAAE,UAAU;EACzBC,WAAW,EAAE;AACf,CAAC;AAAAC,OAAA,cAAAC,QAAA"}
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createCorrectResponseSession = void 0;
8
+ exports.createDefaultModel = createDefaultModel;
9
+ exports.getScore = void 0;
10
+ exports.model = model;
11
+ exports.normalize = void 0;
12
+ exports.outcome = outcome;
13
+ exports.validate = void 0;
14
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
15
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
16
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
17
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
18
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
20
+ var _utils = require("./utils");
21
+ var _defaults = _interopRequireDefault(require("./defaults"));
22
+ var _controllerUtils = require("@pie-lib/controller-utils");
23
+ var _excluded = ["verticalMode", "choicesLayout"];
24
+ 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; }
25
+ 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; } /* eslint-disable no-console */
26
+ var prepareChoice = function prepareChoice(model, env, defaultFeedback) {
27
+ return function (choice) {
28
+ var _ref = env || {},
29
+ role = _ref.role,
30
+ mode = _ref.mode;
31
+ var out = {
32
+ label: choice.label,
33
+ value: choice.value
34
+ };
35
+ if (model.accessibilityLabelsEnabled) {
36
+ out.accessibility = (0, _utils.parseHTML)(choice.accessibility).textContent || choice.value;
37
+ }
38
+ if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
39
+ out.rationale = model.rationaleEnabled ? choice.rationale : null;
40
+ } else {
41
+ out.rationale = null;
42
+ }
43
+ if (mode === 'evaluate') {
44
+ out.correct = !!choice.correct;
45
+ if (model.feedbackEnabled) {
46
+ var feedbackType = choice.feedback && choice.feedback.type || 'none';
47
+ if (feedbackType === 'default') {
48
+ out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
49
+ } else if (feedbackType === 'custom') {
50
+ out.feedback = choice.feedback.value;
51
+ }
52
+ }
53
+ }
54
+ return out;
55
+ };
56
+ };
57
+ function createDefaultModel() {
58
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
59
+ return new Promise(function (resolve) {
60
+ return resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
61
+ });
62
+ }
63
+ var normalize = function normalize(question) {
64
+ var _ref2 = question || {},
65
+ verticalMode = _ref2.verticalMode,
66
+ choicesLayout = _ref2.choicesLayout,
67
+ questionProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
68
+ return _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"]), questionProps), {}, {
69
+ // This is used for offering support for old models which have the property verticalMode
70
+ // Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel
71
+ choicesLayout: choicesLayout || verticalMode === false && 'horizontal' || _defaults["default"].choicesLayout
72
+ });
73
+ };
74
+
75
+ /**
76
+ *
77
+ * @param {*} question
78
+ * @param {*} session
79
+ * @param {*} env
80
+ * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
81
+ */
82
+ exports.normalize = normalize;
83
+ function model(_x, _x2, _x3, _x4) {
84
+ return _model.apply(this, arguments);
85
+ }
86
+ function _model() {
87
+ _model = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(question, session, env, updateSession) {
88
+ var normalizedQuestion, defaultFeedback, choices, lockChoiceOrder, out, _ref4, role, mode;
89
+ return _regenerator["default"].wrap(function _callee$(_context) {
90
+ while (1) switch (_context.prev = _context.next) {
91
+ case 0:
92
+ normalizedQuestion = normalize(question);
93
+ defaultFeedback = Object.assign({
94
+ correct: 'Correct',
95
+ incorrect: 'Incorrect'
96
+ }, normalizedQuestion.defaultFeedback);
97
+ choices = normalizedQuestion.choices.map(prepareChoice(normalizedQuestion, env, defaultFeedback));
98
+ lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
99
+ if (lockChoiceOrder) {
100
+ _context.next = 8;
101
+ break;
102
+ }
103
+ _context.next = 7;
104
+ return (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'value');
105
+ case 7:
106
+ choices = _context.sent;
107
+ case 8:
108
+ out = {
109
+ disabled: env.mode !== 'gather',
110
+ mode: env.mode,
111
+ prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
112
+ choicesLayout: normalizedQuestion.choicesLayout,
113
+ gridColumns: normalizedQuestion.gridColumns,
114
+ choiceMode: normalizedQuestion.choiceMode,
115
+ keyMode: normalizedQuestion.choicePrefix,
116
+ choices: choices,
117
+ responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(normalizedQuestion, session) : undefined
118
+ };
119
+ _ref4 = env || {}, role = _ref4.role, mode = _ref4.mode;
120
+ if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
121
+ out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
122
+ } else {
123
+ out.teacherInstructions = null;
124
+ }
125
+ return _context.abrupt("return", out);
126
+ case 12:
127
+ case "end":
128
+ return _context.stop();
129
+ }
130
+ }, _callee);
131
+ }));
132
+ return _model.apply(this, arguments);
133
+ }
134
+ var getScore = function getScore(config, session) {
135
+ if (!session || (0, _isEmpty["default"])(session)) {
136
+ return 0;
137
+ }
138
+ var selectedChoices = session.value || [];
139
+ var correctChoices = (config.choices || []).filter(function (ch) {
140
+ return ch.correct;
141
+ });
142
+ var score = selectedChoices.reduce(function (acc, selectedChoice) {
143
+ return acc + (correctChoices.find(function (ch) {
144
+ return ch.value === selectedChoice;
145
+ }) ? 1 : 0);
146
+ }, 0);
147
+ if (correctChoices.length < selectedChoices.length) {
148
+ score -= selectedChoices.length - correctChoices.length;
149
+ if (score < 0) {
150
+ score = 0;
151
+ }
152
+ }
153
+ var str = correctChoices.length ? score / correctChoices.length : 0;
154
+ return parseFloat(str.toFixed(2));
155
+ };
156
+
157
+ /**
158
+ *
159
+ * The score is partial by default for checkbox mode, allOrNothing for radio mode.
160
+ * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will
161
+ * override the value in `model`.
162
+ * @param {Object} model - the main model
163
+ * @param {*} session
164
+ * @param {Object} env
165
+ */
166
+ exports.getScore = getScore;
167
+ function outcome(model, session, env) {
168
+ return new Promise(function (resolve) {
169
+ if (!session || (0, _isEmpty["default"])(session)) {
170
+ resolve({
171
+ score: 0,
172
+ empty: true
173
+ });
174
+ } else {
175
+ var partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
176
+ var score = getScore(model, session);
177
+ resolve({
178
+ score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
179
+ empty: false
180
+ });
181
+ }
182
+ });
183
+ }
184
+ var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
185
+ return new Promise(function (resolve) {
186
+ if (env.mode !== 'evaluate' && env.role === 'instructor') {
187
+ var _ref3 = question || {
188
+ choices: []
189
+ },
190
+ choices = _ref3.choices;
191
+ resolve({
192
+ id: '1',
193
+ value: choices.filter(function (c) {
194
+ return c.correct;
195
+ }).map(function (c) {
196
+ return c.value;
197
+ })
198
+ });
199
+ } else {
200
+ resolve(null);
201
+ }
202
+ });
203
+ };
204
+ exports.createCorrectResponseSession = createCorrectResponseSession;
205
+ var validate = function validate() {
206
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
207
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
208
+ var choices = model.choices;
209
+ var _config$minAnswerChoi = config.minAnswerChoices,
210
+ minAnswerChoices = _config$minAnswerChoi === void 0 ? 2 : _config$minAnswerChoi,
211
+ maxAnswerChoices = config.maxAnswerChoices;
212
+ var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
213
+ var choicesErrors = {};
214
+ var hasCorrectResponse = false;
215
+ reversedChoices.forEach(function (choice, index) {
216
+ var correct = choice.correct,
217
+ value = choice.value,
218
+ label = choice.label;
219
+ if (correct) {
220
+ hasCorrectResponse = true;
221
+ }
222
+ if (label === '' || label === '<div></div>') {
223
+ choicesErrors[value] = 'Content should not be empty.';
224
+ } else {
225
+ var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
226
+ return c.label === label;
227
+ });
228
+ if (identicalAnswer) {
229
+ choicesErrors[value] = 'Content should be unique.';
230
+ }
231
+ }
232
+ });
233
+ var errors = {};
234
+ var nbOfChoices = (choices || []).length;
235
+ if (nbOfChoices < minAnswerChoices) {
236
+ errors.answerChoicesError = "There should be at least ".concat(minAnswerChoices, " choices defined.");
237
+ } else if (nbOfChoices > maxAnswerChoices) {
238
+ errors.answerChoicesError = "No more than ".concat(maxAnswerChoices, " choices should be defined.");
239
+ }
240
+ if (!hasCorrectResponse) {
241
+ errors.correctResponseError = 'No correct response defined.';
242
+ }
243
+ if (!(0, _isEmpty["default"])(choicesErrors)) {
244
+ errors.choicesErrors = choicesErrors;
245
+ }
246
+ return errors;
247
+ };
248
+ exports.validate = validate;
249
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_isEmpty","_interopRequireDefault","require","_utils","_defaults","_controllerUtils","_excluded","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","prepareChoice","model","env","defaultFeedback","choice","_ref","role","mode","out","label","value","accessibilityLabelsEnabled","accessibility","parseHTML","textContent","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","createDefaultModel","undefined","Promise","resolve","defaults","normalize","question","_ref2","verticalMode","choicesLayout","questionProps","_objectWithoutProperties2","exports","_x","_x2","_x3","_x4","_model","_asyncToGenerator2","_regenerator","mark","_callee","session","updateSession","normalizedQuestion","choices","lockChoiceOrder","_ref4","wrap","_callee$","_context","prev","next","assign","incorrect","map","lockChoices","getShuffledChoices","sent","disabled","prompt","promptEnabled","gridColumns","choiceMode","keyMode","choicePrefix","responseCorrect","isResponseCorrect","teacherInstructions","teacherInstructionsEnabled","abrupt","stop","getScore","config","isEmpty","selectedChoices","correctChoices","ch","score","reduce","acc","selectedChoice","find","str","parseFloat","toFixed","outcome","empty","partialScoringEnabled","partialScoring","enabled","createCorrectResponseSession","_ref3","id","c","validate","_config$minAnswerChoi","minAnswerChoices","maxAnswerChoices","reversedChoices","_toConsumableArray2","reverse","choicesErrors","hasCorrectResponse","index","identicalAnswer","slice","some","errors","nbOfChoices","answerChoicesError","concat","correctResponseError"],"sources":["../src/index.js"],"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(prepareChoice(normalizedQuestion, env, defaultFeedback));\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'value');\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: 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\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(\n (acc, selectedChoice) => acc + (correctChoices.find((ch) => ch.value === selectedChoice) ? 1 : 0),\n 0,\n );\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 = 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 corre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B;EAC9D;EAEA,IAAI,CAAC,IAAAtC,mBAAO,EAAC4B,aAAa,CAAC,EAAE;IAC3BM,MAAM,CAACN,aAAa,GAAGA,aAAa;EACtC;EAEA,OAAOM,MAAM;AACf,CAAC;AAAC5E,OAAA,CAAA+D,QAAA,GAAAA,QAAA"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.parseHTML = exports.isResponseCorrect = exports.getCorrectResponse = void 0;
8
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
9
+ var getCorrectResponse = function getCorrectResponse(choices) {
10
+ return choices.filter(function (c) {
11
+ return c.correct;
12
+ }).map(function (c) {
13
+ return c.value;
14
+ }).sort();
15
+ };
16
+ exports.getCorrectResponse = getCorrectResponse;
17
+ var isResponseCorrect = function isResponseCorrect(question, session) {
18
+ var correctResponse = getCorrectResponse(question.choices);
19
+ return session && (0, _isEqual["default"])((session.value || []).sort(), correctResponse);
20
+ };
21
+ exports.isResponseCorrect = isResponseCorrect;
22
+ var parseHTML = function parseHTML(html) {
23
+ var template = document.createElement('template');
24
+ template.innerHTML = html;
25
+ return template.content;
26
+ };
27
+ exports.parseHTML = parseHTML;
28
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["_isEqual","_interopRequireDefault","require","getCorrectResponse","choices","filter","c","correct","map","value","sort","exports","isResponseCorrect","question","session","correctResponse","isEqual","parseHTML","html","template","document","createElement","innerHTML","content"],"sources":["../src/utils.js"],"sourcesContent":["import isEqual from 'lodash/isEqual';\n\nexport const getCorrectResponse = (choices) =>\n 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"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAIC,OAAO;EAAA,OACxCA,OAAO,CACJC,MAAM,CAAC,UAACC,CAAC;IAAA,OAAKA,CAAC,CAACC,OAAO;EAAA,EAAC,CACxBC,GAAG,CAAC,UAACF,CAAC;IAAA,OAAKA,CAAC,CAACG,KAAK;EAAA,EAAC,CACnBC,IAAI,CAAC,CAAC;AAAA;AAACC,OAAA,CAAAR,kBAAA,GAAAA,kBAAA;AAEL,IAAMS,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAIC,QAAQ,EAAEC,OAAO,EAAK;EACtD,IAAIC,eAAe,GAAGZ,kBAAkB,CAACU,QAAQ,CAACT,OAAO,CAAC;EAC1D,OAAOU,OAAO,IAAI,IAAAE,mBAAO,EAAC,CAACF,OAAO,CAACL,KAAK,IAAI,EAAE,EAAEC,IAAI,CAAC,CAAC,EAAEK,eAAe,CAAC;AAC1E,CAAC;AAACJ,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAEK,IAAMK,SAAS,GAAG,SAAZA,SAASA,CAAIC,IAAI,EAAK;EACjC,IAAMC,QAAQ,GAAGC,QAAQ,CAACC,aAAa,CAAC,UAAU,CAAC;EACnDF,QAAQ,CAACG,SAAS,GAAGJ,IAAI;EACzB,OAAOC,QAAQ,CAACI,OAAO;AACzB,CAAC;AAACZ,OAAA,CAAAM,SAAA,GAAAA,SAAA"}
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = exports.StyledRadio = exports.StyledFormControlLabel = exports.StyledCheckbox = exports.ChoiceInput = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
11
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+ var _FormControlLabel = _interopRequireDefault(require("@material-ui/core/FormControlLabel"));
17
+ var _react = _interopRequireDefault(require("react"));
18
+ var _propTypes = _interopRequireDefault(require("prop-types"));
19
+ var _styles = require("@material-ui/core/styles");
20
+ var _Checkbox = _interopRequireDefault(require("@material-ui/core/Checkbox"));
21
+ var _renderUi = require("@pie-lib/render-ui");
22
+ var _feedbackTick = _interopRequireDefault(require("./feedback-tick"));
23
+ var _Radio = _interopRequireDefault(require("@material-ui/core/Radio"));
24
+ var _classnames = _interopRequireDefault(require("classnames"));
25
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
26
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
27
+ 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; }
28
+ 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; }
29
+ var CLASS_NAME = 'multiple-choice-component';
30
+ var styleSheet = function styleSheet() {
31
+ return {
32
+ row: {
33
+ display: 'flex',
34
+ alignItems: 'center',
35
+ backgroundColor: _renderUi.color.background()
36
+ },
37
+ checkboxHolder: {
38
+ display: 'flex',
39
+ alignItems: 'center',
40
+ backgroundColor: _renderUi.color.background(),
41
+ flex: 1,
42
+ '& label': {
43
+ color: _renderUi.color.text()
44
+ }
45
+ },
46
+ horizontalLayout: (0, _defineProperty2["default"])({}, "& .".concat(CLASS_NAME), {
47
+ paddingRight: '8px'
48
+ })
49
+ };
50
+ };
51
+ var formStyleSheet = {
52
+ label: {
53
+ color: "".concat(_renderUi.color.text(), " !important"),
54
+ //'var(--choice-input-color, black)'
55
+ backgroundColor: _renderUi.color.background()
56
+ }
57
+ };
58
+ var StyledFormControlLabel = (0, _styles.withStyles)(formStyleSheet, {
59
+ name: 'FormControlLabel'
60
+ })(function (props) {
61
+ return /*#__PURE__*/_react["default"].createElement(_FormControlLabel["default"], (0, _extends2["default"])({}, props, {
62
+ classes: {
63
+ label: props.classes.label
64
+ }
65
+ }));
66
+ });
67
+ exports.StyledFormControlLabel = StyledFormControlLabel;
68
+ var colorStyle = function colorStyle(varName, fallback) {
69
+ return (0, _defineProperty2["default"])({}, "&.".concat(CLASS_NAME), {
70
+ color: "var(--choice-input-".concat(varName, ", ").concat(fallback, ") !important")
71
+ });
72
+ };
73
+ var inputStyles = {
74
+ 'correct-root': colorStyle('correct-color', _renderUi.color.text()),
75
+ 'correct-checked': colorStyle('correct-selected-color', _renderUi.color.correct()),
76
+ //green[500]),
77
+ 'correct-disabled': colorStyle('correct-disabled-color', _renderUi.color.disabled()),
78
+ //'grey'),
79
+ 'incorrect-root': colorStyle('incorrect-color', _renderUi.color.incorrect()),
80
+ 'incorrect-checked': colorStyle('incorrect-checked', _renderUi.color.incorrect()),
81
+ //orange[500]),
82
+ 'incorrect-disabled': colorStyle('incorrect-disabled-color', _renderUi.color.disabled()),
83
+ root: _objectSpread(_objectSpread({}, colorStyle('color', _renderUi.color.text())), {}, {
84
+ '&:hover': {
85
+ color: "".concat(_renderUi.color.primaryLight(), " !important")
86
+ }
87
+ }),
88
+ checked: colorStyle('selected-color', _renderUi.color.primary()),
89
+ disabled: _objectSpread(_objectSpread({}, colorStyle('disabled-color', _renderUi.color.text())), {}, {
90
+ opacity: 0.6,
91
+ cursor: 'not-allowed !important',
92
+ pointerEvents: 'initial !important'
93
+ })
94
+ };
95
+ var StyledCheckbox = (0, _styles.withStyles)(inputStyles)(function (props) {
96
+ var correctness = props.correctness,
97
+ classes = props.classes,
98
+ checked = props.checked,
99
+ onChange = props.onChange,
100
+ disabled = props.disabled,
101
+ accessibility = props.accessibility;
102
+ var key = function key(k) {
103
+ return correctness ? "".concat(correctness, "-").concat(k) : k;
104
+ };
105
+ var resolved = {
106
+ root: classes[key('root')],
107
+ checked: classes[key('checked')],
108
+ disabled: classes[key('disabled')]
109
+ };
110
+ var miniProps = {
111
+ checked: checked,
112
+ onChange: onChange,
113
+ disabled: disabled
114
+ };
115
+ return /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], (0, _extends2["default"])({
116
+ "aria-label": accessibility
117
+ }, miniProps, {
118
+ className: CLASS_NAME,
119
+ classes: {
120
+ root: resolved.root,
121
+ checked: resolved.checked,
122
+ disabled: "".concat(correctness ? '' : resolved.disabled)
123
+ }
124
+ }));
125
+ });
126
+ exports.StyledCheckbox = StyledCheckbox;
127
+ var StyledRadio = (0, _styles.withStyles)(inputStyles)(function (props) {
128
+ var correctness = props.correctness,
129
+ classes = props.classes,
130
+ checked = props.checked,
131
+ onChange = props.onChange,
132
+ disabled = props.disabled,
133
+ accessibility = props.accessibility;
134
+ var key = function key(k) {
135
+ return correctness ? "".concat(correctness, "-").concat(k) : k;
136
+ };
137
+ var resolved = {
138
+ root: classes[key('root')],
139
+ checked: classes[key('checked')],
140
+ disabled: classes[key('disabled')]
141
+ };
142
+ var miniProps = {
143
+ checked: checked,
144
+ onChange: onChange,
145
+ disabled: disabled
146
+ };
147
+ return /*#__PURE__*/_react["default"].createElement(_Radio["default"], (0, _extends2["default"])({
148
+ "aria-label": accessibility
149
+ }, miniProps, {
150
+ className: CLASS_NAME,
151
+ classes: {
152
+ root: resolved.root,
153
+ checked: resolved.checked,
154
+ disabled: "".concat(correctness ? '' : resolved.disabled)
155
+ }
156
+ }));
157
+ });
158
+ exports.StyledRadio = StyledRadio;
159
+ var ChoiceInput = /*#__PURE__*/function (_React$Component) {
160
+ (0, _inherits2["default"])(ChoiceInput, _React$Component);
161
+ var _super = _createSuper(ChoiceInput);
162
+ function ChoiceInput(props) {
163
+ var _this;
164
+ (0, _classCallCheck2["default"])(this, ChoiceInput);
165
+ _this = _super.call(this, props);
166
+ _this.onToggleChoice = _this.onToggleChoice.bind((0, _assertThisInitialized2["default"])(_this));
167
+ return _this;
168
+ }
169
+ (0, _createClass2["default"])(ChoiceInput, [{
170
+ key: "onToggleChoice",
171
+ value: function onToggleChoice() {
172
+ this.props.onChange({
173
+ value: this.props.value,
174
+ selected: !this.props.checked
175
+ });
176
+ }
177
+ }, {
178
+ key: "render",
179
+ value: function render() {
180
+ var _this$props = this.props,
181
+ choiceMode = _this$props.choiceMode,
182
+ disabled = _this$props.disabled,
183
+ displayKey = _this$props.displayKey,
184
+ feedback = _this$props.feedback,
185
+ label = _this$props.label,
186
+ checked = _this$props.checked,
187
+ correctness = _this$props.correctness,
188
+ classes = _this$props.classes,
189
+ className = _this$props.className,
190
+ rationale = _this$props.rationale,
191
+ accessibility = _this$props.accessibility,
192
+ hideTick = _this$props.hideTick,
193
+ isEvaluateMode = _this$props.isEvaluateMode,
194
+ choicesLayout = _this$props.choicesLayout;
195
+ var Tag = choiceMode === 'checkbox' ? StyledCheckbox : StyledRadio;
196
+ var classSuffix = choiceMode === 'checkbox' ? 'checkbox' : 'radio-button';
197
+ var holderClassNames = (0, _classnames["default"])(classes.checkboxHolder, (0, _defineProperty2["default"])({}, classes.horizontalLayout, choicesLayout === 'horizontal'));
198
+ return /*#__PURE__*/_react["default"].createElement("div", {
199
+ className: (0, _classnames["default"])(className, 'corespring-' + classSuffix, 'choice-input')
200
+ }, /*#__PURE__*/_react["default"].createElement("div", {
201
+ className: classes.row
202
+ }, !hideTick && isEvaluateMode && /*#__PURE__*/_react["default"].createElement(_feedbackTick["default"], {
203
+ correctness: correctness
204
+ }), /*#__PURE__*/_react["default"].createElement("div", {
205
+ className: (0, _classnames["default"])(holderClassNames, 'checkbox-holder')
206
+ }, /*#__PURE__*/_react["default"].createElement(StyledFormControlLabel, {
207
+ disabled: disabled,
208
+ label: displayKey ? displayKey + '. ' : '',
209
+ control: /*#__PURE__*/_react["default"].createElement(Tag, {
210
+ accessibility: accessibility,
211
+ checked: checked,
212
+ correctness: correctness,
213
+ onChange: this.onToggleChoice
214
+ })
215
+ }), /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
216
+ className: "label",
217
+ onClick: this.onToggleChoice,
218
+ prompt: label,
219
+ tagName: "span"
220
+ }))), rationale && /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
221
+ className: "rationale",
222
+ defaultClassName: "rationale",
223
+ prompt: rationale
224
+ }), /*#__PURE__*/_react["default"].createElement(_renderUi.Feedback, {
225
+ feedback: feedback,
226
+ correctness: correctness
227
+ }));
228
+ }
229
+ }]);
230
+ return ChoiceInput;
231
+ }(_react["default"].Component);
232
+ exports.ChoiceInput = ChoiceInput;
233
+ (0, _defineProperty2["default"])(ChoiceInput, "propTypes", {
234
+ choiceMode: _propTypes["default"].oneOf(['radio', 'checkbox']),
235
+ displayKey: _propTypes["default"].string.isRequired,
236
+ checked: _propTypes["default"].bool.isRequired,
237
+ correctness: _propTypes["default"].string,
238
+ disabled: _propTypes["default"].bool.isRequired,
239
+ feedback: _propTypes["default"].string,
240
+ label: _propTypes["default"].string.isRequired,
241
+ rationale: _propTypes["default"].string,
242
+ accessibility: _propTypes["default"].string,
243
+ onChange: _propTypes["default"].func.isRequired,
244
+ value: _propTypes["default"].string.isRequired,
245
+ classes: _propTypes["default"].object,
246
+ className: _propTypes["default"].string,
247
+ hideTick: _propTypes["default"].bool,
248
+ isEvaluateMode: _propTypes["default"].bool,
249
+ choicesLayout: _propTypes["default"].oneOf(['vertical', 'grid', 'horizontal'])
250
+ });
251
+ (0, _defineProperty2["default"])(ChoiceInput, "defaultProps", {
252
+ rationale: null,
253
+ accessibility: null,
254
+ checked: false,
255
+ isEvaluateMode: false
256
+ });
257
+ var _default = (0, _styles.withStyles)(styleSheet)(ChoiceInput);
258
+ exports["default"] = _default;
259
+ //# sourceMappingURL=choice-input.js.map