@pie-element/multiple-choice 13.2.2-next.1 → 13.2.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.
Files changed (114) hide show
  1. package/CHANGELOG.json +1972 -0
  2. package/CHANGELOG.md +2727 -0
  3. package/LICENSE.md +5 -0
  4. package/PRINT.md +35 -0
  5. package/README.md +56 -0
  6. package/choice.png +0 -0
  7. package/configure/CHANGELOG.json +1387 -0
  8. package/configure/CHANGELOG.md +2074 -0
  9. package/configure/lib/defaults.js +203 -0
  10. package/configure/lib/defaults.js.map +1 -0
  11. package/configure/lib/index.js +202 -0
  12. package/configure/lib/index.js.map +1 -0
  13. package/configure/lib/main.js +484 -0
  14. package/configure/lib/main.js.map +1 -0
  15. package/configure/lib/utils.js +18 -0
  16. package/configure/lib/utils.js.map +1 -0
  17. package/configure/package.json +22 -0
  18. package/controller/CHANGELOG.json +527 -0
  19. package/controller/CHANGELOG.md +1405 -0
  20. package/controller/lib/defaults.js +33 -0
  21. package/controller/lib/defaults.js.map +1 -0
  22. package/controller/lib/index.js +288 -0
  23. package/controller/lib/index.js.map +1 -0
  24. package/controller/lib/utils.js +15 -0
  25. package/controller/lib/utils.js.map +1 -0
  26. package/controller/package.json +15 -0
  27. package/docs/config-schema.json +2993 -0
  28. package/docs/config-schema.json.md +2217 -0
  29. package/docs/demo/config.js +8 -0
  30. package/docs/demo/generate.js +61 -0
  31. package/docs/demo/index.html +1 -0
  32. package/docs/demo/session.js +7 -0
  33. package/docs/pie-schema.json +1332 -0
  34. package/docs/pie-schema.json.md +1015 -0
  35. package/lib/choice-input.js +377 -0
  36. package/lib/choice-input.js.map +1 -0
  37. package/lib/choice.js +192 -0
  38. package/lib/choice.js.map +1 -0
  39. package/lib/feedback-tick.js +134 -0
  40. package/lib/feedback-tick.js.map +1 -0
  41. package/lib/index.js +402 -0
  42. package/lib/index.js.map +1 -0
  43. package/lib/main.js +63 -0
  44. package/lib/main.js.map +1 -0
  45. package/lib/multiple-choice.js +397 -0
  46. package/lib/multiple-choice.js.map +1 -0
  47. package/lib/print.js +94 -0
  48. package/lib/print.js.map +1 -0
  49. package/lib/session-updater.js +37 -0
  50. package/lib/session-updater.js.map +1 -0
  51. package/module/configure.js +1 -0
  52. package/module/controller.js +3045 -0
  53. package/module/demo.js +86 -0
  54. package/module/element.js +1 -0
  55. package/module/index.html +21 -0
  56. package/module/manifest.json +14 -0
  57. package/module/print-demo.js +124 -0
  58. package/module/print.html +18 -0
  59. package/module/print.js +1 -0
  60. package/package.json +29 -90
  61. package/configure.js +0 -2
  62. package/controller.js +0 -1
  63. package/dist/author/defaults.d.ts +0 -205
  64. package/dist/author/defaults.js +0 -151
  65. package/dist/author/index.d.ts +0 -26
  66. package/dist/author/index.js +0 -119
  67. package/dist/author/main.d.ts +0 -34
  68. package/dist/author/main.js +0 -287
  69. package/dist/author/utils.d.ts +0 -9
  70. package/dist/author/utils.js +0 -7
  71. package/dist/browser/Radio-D9xGO4mD.js +0 -9572
  72. package/dist/browser/Radio-D9xGO4mD.js.map +0 -1
  73. package/dist/browser/author/index.js +0 -39745
  74. package/dist/browser/author/index.js.map +0 -1
  75. package/dist/browser/controller/index.js +0 -199
  76. package/dist/browser/controller/index.js.map +0 -1
  77. package/dist/browser/delivery/index.js +0 -251
  78. package/dist/browser/delivery/index.js.map +0 -1
  79. package/dist/browser/dist-nl5urzAW.js +0 -107
  80. package/dist/browser/dist-nl5urzAW.js.map +0 -1
  81. package/dist/browser/main-D2qC-1Hm.js +0 -2440
  82. package/dist/browser/main-D2qC-1Hm.js.map +0 -1
  83. package/dist/browser/multiple-choice.css +0 -2
  84. package/dist/browser/print/index.js +0 -43
  85. package/dist/browser/print/index.js.map +0 -1
  86. package/dist/controller/defaults.d.ts +0 -35
  87. package/dist/controller/defaults.js +0 -29
  88. package/dist/controller/index.d.ts +0 -65
  89. package/dist/controller/index.js +0 -124
  90. package/dist/controller/utils.d.ts +0 -10
  91. package/dist/controller/utils.js +0 -8
  92. package/dist/delivery/choice-input.d.ts +0 -44
  93. package/dist/delivery/choice-input.js +0 -272
  94. package/dist/delivery/choice.d.ts +0 -20
  95. package/dist/delivery/choice.js +0 -105
  96. package/dist/delivery/feedback-tick.d.ts +0 -20
  97. package/dist/delivery/feedback-tick.js +0 -104
  98. package/dist/delivery/index.d.ts +0 -37
  99. package/dist/delivery/index.js +0 -214
  100. package/dist/delivery/main.d.ts +0 -31
  101. package/dist/delivery/main.js +0 -51
  102. package/dist/delivery/multiple-choice.d.ts +0 -61
  103. package/dist/delivery/multiple-choice.js +0 -244
  104. package/dist/delivery/session-updater.d.ts +0 -10
  105. package/dist/delivery/session-updater.js +0 -9
  106. package/dist/index.d.ts +0 -1
  107. package/dist/index.iife.d.ts +0 -8
  108. package/dist/index.iife.js +0 -148
  109. package/dist/index.js +0 -2
  110. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
  111. package/dist/print/index.d.ts +0 -15
  112. package/dist/print/index.js +0 -43
  113. package/dist/runtime-support.d.ts +0 -12
  114. package/dist/runtime-support.js +0 -12
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = exports.default = {
8
+ choiceMode: 'checkbox',
9
+ choicePrefix: 'letters',
10
+ choices: [],
11
+ choicesLayout: 'vertical',
12
+ feedbackEnabled: false,
13
+ gridColumns: 2,
14
+ lockChoiceOrder: true,
15
+ partialScoring: true,
16
+ prompt: '',
17
+ promptEnabled: true,
18
+ rationale: '',
19
+ rationaleEnabled: true,
20
+ scoringType: 'auto',
21
+ studentInstructionsEnabled: true,
22
+ teacherInstructions: '',
23
+ teacherInstructionsEnabled: true,
24
+ toolbarEditorPosition: 'bottom',
25
+ selectedAnswerBackgroundColor: 'initial',
26
+ selectedAnswerStrokeColor: 'initial',
27
+ selectedAnswerStrokeWidth: 'initial',
28
+ hoverAnswerBackgroundColor: 'initial',
29
+ hoverAnswerStrokeColor: 'initial',
30
+ hoverAnswerStrokeWidth: 'initial',
31
+ keyboardEventsEnabled: false
32
+ };
33
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","names":["choiceMode","choicePrefix","choices","choicesLayout","feedbackEnabled","gridColumns","lockChoiceOrder","partialScoring","prompt","promptEnabled","rationale","rationaleEnabled","scoringType","studentInstructionsEnabled","teacherInstructions","teacherInstructionsEnabled","toolbarEditorPosition","selectedAnswerBackgroundColor","selectedAnswerStrokeColor","selectedAnswerStrokeWidth","hoverAnswerBackgroundColor","hoverAnswerStrokeColor","hoverAnswerStrokeWidth","keyboardEventsEnabled"],"sources":["../src/defaults.js"],"sourcesContent":["export default {\n choiceMode: 'checkbox',\n choicePrefix: 'letters',\n choices: [],\n choicesLayout: 'vertical',\n feedbackEnabled: false,\n gridColumns: 2,\n lockChoiceOrder: true,\n partialScoring: true,\n prompt: '',\n promptEnabled: true,\n rationale: '',\n rationaleEnabled: true,\n scoringType: 'auto',\n studentInstructionsEnabled: true,\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n toolbarEditorPosition: 'bottom',\n selectedAnswerBackgroundColor: 'initial',\n selectedAnswerStrokeColor: 'initial',\n selectedAnswerStrokeWidth: 'initial',\n hoverAnswerBackgroundColor: 'initial',\n hoverAnswerStrokeColor: 'initial',\n hoverAnswerStrokeWidth: 'initial',\n keyboardEventsEnabled: false,\n};\n"],"mappings":";;;;;;iCAAe;EACbA,UAAU,EAAE,UAAU;EACtBC,YAAY,EAAE,SAAS;EACvBC,OAAO,EAAE,EAAE;EACXC,aAAa,EAAE,UAAU;EACzBC,eAAe,EAAE,KAAK;EACtBC,WAAW,EAAE,CAAC;EACdC,eAAe,EAAE,IAAI;EACrBC,cAAc,EAAE,IAAI;EACpBC,MAAM,EAAE,EAAE;EACVC,aAAa,EAAE,IAAI;EACnBC,SAAS,EAAE,EAAE;EACbC,gBAAgB,EAAE,IAAI;EACtBC,WAAW,EAAE,MAAM;EACnBC,0BAA0B,EAAE,IAAI;EAChCC,mBAAmB,EAAE,EAAE;EACvBC,0BAA0B,EAAE,IAAI;EAChCC,qBAAqB,EAAE,QAAQ;EAC/BC,6BAA6B,EAAE,SAAS;EACxCC,yBAAyB,EAAE,SAAS;EACpCC,yBAAyB,EAAE,SAAS;EACpCC,0BAA0B,EAAE,SAAS;EACrCC,sBAAsB,EAAE,SAAS;EACjCC,sBAAsB,EAAE,SAAS;EACjCC,qBAAqB,EAAE;AACzB,CAAC","ignoreList":[]}
@@ -0,0 +1,288 @@
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 = exports.getLogTrace = void 0;
10
+ exports.model = model;
11
+ exports.normalize = void 0;
12
+ exports.outcome = outcome;
13
+ exports.validate = void 0;
14
+ var _lodashEs = require("lodash-es");
15
+ var _utils = require("./utils");
16
+ var _defaults = _interopRequireDefault(require("./defaults"));
17
+ var _controllerUtils = require("@pie-lib/controller-utils");
18
+ /* eslint-disable no-console */
19
+
20
+ const prepareChoice = (model, env, defaultFeedback) => choice => {
21
+ const {
22
+ role,
23
+ mode
24
+ } = env || {};
25
+ const out = {
26
+ label: choice.label,
27
+ value: choice.value
28
+ };
29
+ if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
30
+ out.rationale = model.rationaleEnabled ? choice.rationale : null;
31
+ } else {
32
+ out.rationale = null;
33
+ }
34
+ if (mode === 'evaluate') {
35
+ out.correct = !!choice.correct;
36
+ if (model.feedbackEnabled) {
37
+ const feedbackType = choice.feedback && choice.feedback.type || 'none';
38
+ if (feedbackType === 'default') {
39
+ out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
40
+ } else if (feedbackType === 'custom') {
41
+ out.feedback = choice.feedback.value;
42
+ }
43
+ }
44
+ }
45
+ return out;
46
+ };
47
+ function createDefaultModel(model = {}) {
48
+ return new Promise(resolve => resolve({
49
+ ..._defaults.default,
50
+ ...model
51
+ }));
52
+ }
53
+ const normalize = question => {
54
+ const {
55
+ verticalMode,
56
+ choicesLayout,
57
+ ...questionProps
58
+ } = question || {};
59
+ return {
60
+ ..._defaults.default,
61
+ ...questionProps,
62
+ // This is used for offering support for old models which have the property verticalMode
63
+ // Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel
64
+ choicesLayout: choicesLayout || verticalMode === false && 'horizontal' || _defaults.default.choicesLayout
65
+ };
66
+ };
67
+
68
+ /**
69
+ *
70
+ * @param {*} question
71
+ * @param {*} session
72
+ * @param {*} env
73
+ * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
74
+ */
75
+ exports.normalize = normalize;
76
+ async function model(question, session, env, updateSession) {
77
+ const normalizedQuestion = normalize(question);
78
+ const defaultFeedback = Object.assign({
79
+ correct: 'Correct',
80
+ incorrect: 'Incorrect'
81
+ }, normalizedQuestion.defaultFeedback);
82
+ let choices = (normalizedQuestion.choices || []).map(prepareChoice(normalizedQuestion, env, defaultFeedback));
83
+ const lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
84
+ if (!lockChoiceOrder) {
85
+ choices = await (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'value');
86
+ }
87
+ const out = {
88
+ disabled: env.mode !== 'gather',
89
+ mode: env.mode,
90
+ prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
91
+ choicesLayout: normalizedQuestion.choicesLayout,
92
+ gridColumns: normalizedQuestion.gridColumns,
93
+ choiceMode: normalizedQuestion.choiceMode,
94
+ keyMode: normalizedQuestion.choicePrefix,
95
+ choices,
96
+ responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(normalizedQuestion, session) : undefined,
97
+ language: normalizedQuestion.language,
98
+ extraCSSRules: normalizedQuestion.extraCSSRules,
99
+ fontSizeFactor: normalizedQuestion.fontSizeFactor,
100
+ isSelectionButtonBelow: normalizedQuestion.isSelectionButtonBelow,
101
+ selectedAnswerBackgroundColor: normalizedQuestion.selectedAnswerBackgroundColor || 'initial',
102
+ selectedAnswerStrokeColor: normalizedQuestion.selectedAnswerStrokeColor || 'initial',
103
+ selectedAnswerStrokeWidth: normalizedQuestion.selectedAnswerStrokeWidth || 'initial',
104
+ hoverAnswerBackgroundColor: normalizedQuestion.hoverAnswerBackgroundColor || 'initial',
105
+ hoverAnswerStrokeColor: normalizedQuestion.hoverAnswerStrokeColor || 'initial',
106
+ hoverAnswerStrokeWidth: normalizedQuestion.hoverAnswerStrokeWidth || 'initial',
107
+ minSelections: normalizedQuestion.minSelections,
108
+ maxSelections: normalizedQuestion.maxSelections,
109
+ keyboardEventsEnabled: normalizedQuestion.keyboardEventsEnabled,
110
+ autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled,
111
+ completeAudioEnabled: normalizedQuestion.completeAudioEnabled,
112
+ customAudioButton: normalizedQuestion.customAudioButton
113
+ };
114
+ const {
115
+ role,
116
+ mode
117
+ } = env || {};
118
+ if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
119
+ out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
120
+ } else {
121
+ out.teacherInstructions = null;
122
+ }
123
+ return out;
124
+ }
125
+ const getScore = (config, session) => {
126
+ if (!session || (0, _lodashEs.isEmpty)(session)) {
127
+ return 0;
128
+ }
129
+ const selectedChoices = session.value || [];
130
+ const correctChoices = (config.choices || []).filter(ch => ch.correct);
131
+ let score = selectedChoices.reduce((acc, selectedChoice) => acc + (correctChoices.find(ch => ch.value === selectedChoice) ? 1 : 0), 0);
132
+ if (correctChoices.length < selectedChoices.length) {
133
+ score -= selectedChoices.length - correctChoices.length;
134
+ if (score < 0) {
135
+ score = 0;
136
+ }
137
+ }
138
+ const str = correctChoices.length ? score / correctChoices.length : 0;
139
+ return parseFloat(str.toFixed(2));
140
+ };
141
+
142
+ /**
143
+ * Generates detailed trace log for scoring evaluation
144
+ * @param {Object} model - the question model
145
+ * @param {Object} session - the student session
146
+ * @param {Object} env - the environment
147
+ * @returns {Array} traceLog - array of trace messages
148
+ */
149
+ exports.getScore = getScore;
150
+ const getLogTrace = (model, session, env) => {
151
+ const traceLog = [];
152
+ const selected = session?.value || [];
153
+ const questionType = model.choiceMode === 'radio' ? 'multiple-choice (radio)' : 'multiple-select (checkbox)';
154
+ traceLog.push(`Question type: ${questionType}.`);
155
+ if (selected.length) {
156
+ traceLog.push(`Student selected ${selected.length} answer(s): ${selected.join(', ')}.`);
157
+ } else {
158
+ traceLog.push('Student did not select any answers.');
159
+ }
160
+ const correctChoices = (model.choices || []).filter(c => c.correct);
161
+ const correctValues = correctChoices.map(c => c.value);
162
+ traceLog.push(`${correctChoices.length} correct answer(s) are defined for this question.`);
163
+ if (selected.length) {
164
+ const correctSelected = selected.filter(v => correctValues.includes(v));
165
+ const incorrectSelected = selected.filter(v => !correctValues.includes(v));
166
+ traceLog.push(`Student selected ${correctSelected.length} correct and ${incorrectSelected.length} incorrect answer(s).`);
167
+ }
168
+ const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
169
+ const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';
170
+ traceLog.push(`Score calculated using ${scoringMethod}.`);
171
+ const score = getScore(model, session);
172
+ traceLog.push(`Final score: ${score}.`);
173
+ return traceLog;
174
+ };
175
+
176
+ /**
177
+ *
178
+ * The score is partial by default for checkbox mode, allOrNothing for radio mode.
179
+ * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will
180
+ * override the value in `model`.
181
+ * @param {Object} model - the main model
182
+ * @param {*} session
183
+ * @param {Object} env
184
+ */
185
+ exports.getLogTrace = getLogTrace;
186
+ function outcome(model, session, env) {
187
+ return new Promise(resolve => {
188
+ if (!session || (0, _lodashEs.isEmpty)(session)) {
189
+ resolve({
190
+ score: 0,
191
+ empty: true,
192
+ traceLog: ['Student did not select any answers. Score is 0.']
193
+ });
194
+ } else {
195
+ const traceLog = getLogTrace(model, session, env);
196
+ const score = getScore(model, session);
197
+ const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
198
+ resolve({
199
+ score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
200
+ empty: false,
201
+ traceLog
202
+ });
203
+ }
204
+ });
205
+ }
206
+ const createCorrectResponseSession = (question, env) => {
207
+ return new Promise(resolve => {
208
+ if (env.mode !== 'evaluate' && env.role === 'instructor') {
209
+ const {
210
+ choices
211
+ } = question || {
212
+ choices: []
213
+ };
214
+ resolve({
215
+ id: '1',
216
+ value: choices.filter(c => c.correct).map(c => c.value)
217
+ });
218
+ } else {
219
+ resolve(null);
220
+ }
221
+ });
222
+ };
223
+
224
+ // remove all html tags
225
+ exports.createCorrectResponseSession = createCorrectResponseSession;
226
+ const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
227
+
228
+ // remove all html tags except img, iframe and source tag for audio
229
+ const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
230
+ const validate = (model = {}, config = {}) => {
231
+ const {
232
+ choices
233
+ } = model;
234
+ const {
235
+ minAnswerChoices = 2,
236
+ maxAnswerChoices
237
+ } = config;
238
+ const reversedChoices = [...(choices || [])].reverse();
239
+ const choicesErrors = {};
240
+ const rationaleErrors = {};
241
+ const errors = {};
242
+ ['teacherInstructions', 'prompt'].forEach(field => {
243
+ if (config[field]?.required && !getContent(model[field])) {
244
+ errors[field] = 'This field is required.';
245
+ }
246
+ });
247
+ let hasCorrectResponse = false;
248
+ reversedChoices.forEach((choice, index) => {
249
+ const {
250
+ correct,
251
+ value,
252
+ label,
253
+ rationale
254
+ } = choice;
255
+ if (correct) {
256
+ hasCorrectResponse = true;
257
+ }
258
+ if (!getContent(label)) {
259
+ choicesErrors[value] = 'Content should not be empty.';
260
+ } else {
261
+ const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);
262
+ if (identicalAnswer) {
263
+ choicesErrors[value] = 'Content should be unique.';
264
+ }
265
+ }
266
+ if (config.rationale?.required && !getContent(rationale)) {
267
+ rationaleErrors[value] = 'This field is required.';
268
+ }
269
+ });
270
+ const nbOfChoices = (choices || []).length;
271
+ if (nbOfChoices < minAnswerChoices) {
272
+ errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;
273
+ } else if (nbOfChoices > maxAnswerChoices) {
274
+ errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;
275
+ }
276
+ if (!hasCorrectResponse) {
277
+ errors.correctResponse = 'No correct response defined.';
278
+ }
279
+ if (!(0, _lodashEs.isEmpty)(choicesErrors)) {
280
+ errors.choices = choicesErrors;
281
+ }
282
+ if (!(0, _lodashEs.isEmpty)(rationaleErrors)) {
283
+ errors.rationale = rationaleErrors;
284
+ }
285
+ return errors;
286
+ };
287
+ exports.validate = validate;
288
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_lodashEs","require","_utils","_defaults","_interopRequireDefault","_controllerUtils","prepareChoice","model","env","defaultFeedback","choice","role","mode","out","label","value","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","createDefaultModel","Promise","resolve","defaults","normalize","question","verticalMode","choicesLayout","questionProps","exports","session","updateSession","normalizedQuestion","Object","assign","incorrect","choices","map","lockChoiceOrder","lockChoices","getShuffledChoices","disabled","prompt","promptEnabled","gridColumns","choiceMode","keyMode","choicePrefix","responseCorrect","isResponseCorrect","undefined","language","extraCSSRules","fontSizeFactor","isSelectionButtonBelow","selectedAnswerBackgroundColor","selectedAnswerStrokeColor","selectedAnswerStrokeWidth","hoverAnswerBackgroundColor","hoverAnswerStrokeColor","hoverAnswerStrokeWidth","minSelections","maxSelections","keyboardEventsEnabled","autoplayAudioEnabled","completeAudioEnabled","customAudioButton","teacherInstructions","teacherInstructionsEnabled","getScore","config","isEmpty","selectedChoices","correctChoices","filter","ch","score","reduce","acc","selectedChoice","find","length","str","parseFloat","toFixed","getLogTrace","traceLog","selected","questionType","push","join","c","correctValues","correctSelected","v","includes","incorrectSelected","partialScoringEnabled","partialScoring","enabled","scoringMethod","outcome","empty","createCorrectResponseSession","id","getInnerText","html","replaceAll","getContent","replace","validate","minAnswerChoices","maxAnswerChoices","reversedChoices","reverse","choicesErrors","rationaleErrors","errors","forEach","field","required","hasCorrectResponse","index","identicalAnswer","slice","some","nbOfChoices","answerChoices","correctResponse"],"sources":["../src/index.js"],"sourcesContent":["/* eslint-disable no-console */\nimport { isEmpty } from 'lodash-es';\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) => {\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 language: normalizedQuestion.language,\n extraCSSRules: normalizedQuestion.extraCSSRules,\n fontSizeFactor: normalizedQuestion.fontSizeFactor,\n isSelectionButtonBelow: normalizedQuestion.isSelectionButtonBelow,\n selectedAnswerBackgroundColor: normalizedQuestion.selectedAnswerBackgroundColor || 'initial',\n selectedAnswerStrokeColor: normalizedQuestion.selectedAnswerStrokeColor || 'initial',\n selectedAnswerStrokeWidth: normalizedQuestion.selectedAnswerStrokeWidth || 'initial',\n hoverAnswerBackgroundColor: normalizedQuestion.hoverAnswerBackgroundColor || 'initial',\n hoverAnswerStrokeColor: normalizedQuestion.hoverAnswerStrokeColor || 'initial',\n hoverAnswerStrokeWidth: normalizedQuestion.hoverAnswerStrokeWidth || 'initial',\n minSelections: normalizedQuestion.minSelections,\n maxSelections: normalizedQuestion.maxSelections,\n keyboardEventsEnabled: normalizedQuestion.keyboardEventsEnabled,\n autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled,\n completeAudioEnabled: normalizedQuestion.completeAudioEnabled,\n customAudioButton: normalizedQuestion.customAudioButton,\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 * Generates detailed trace log for scoring evaluation\n * @param {Object} model - the question model\n * @param {Object} session - the student session\n * @param {Object} env - the environment\n * @returns {Array} traceLog - array of trace messages\n */\nexport const getLogTrace = (model, session, env) => {\n const traceLog = [];\n const selected = session?.value || [];\n \n const questionType = model.choiceMode === 'radio' ? 'multiple-choice (radio)' : 'multiple-select (checkbox)';\n traceLog.push(`Question type: ${questionType}.`);\n \n if (selected.length) {\n traceLog.push(`Student selected ${selected.length} answer(s): ${selected.join(', ')}.`);\n } else {\n traceLog.push('Student did not select any answers.');\n }\n\n const correctChoices = (model.choices || []).filter((c) => c.correct);\n const correctValues = correctChoices.map((c) => c.value);\n traceLog.push(`${correctChoices.length} correct answer(s) are defined for this question.`);\n \n if (selected.length) {\n const correctSelected = selected.filter((v) => correctValues.includes(v));\n const incorrectSelected = selected.filter((v) => !correctValues.includes(v));\n traceLog.push(\n `Student selected ${correctSelected.length} correct and ${incorrectSelected.length} incorrect answer(s).`\n );\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';\n traceLog.push(`Score calculated using ${scoringMethod}.`);\n\n const score = getScore(model, session);\n traceLog.push(`Final score: ${score}.`);\n\n return traceLog;\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, traceLog: ['Student did not select any answers. Score is 0.'] });\n } else {\n const traceLog = getLogTrace(model, session, env);\n const score = getScore(model, session);\n const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n\n resolve({ \n score: partialScoringEnabled ? score : score === 1 ? 1 : 0, \n empty: false, \n traceLog \n });\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\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\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 const rationaleErrors = {};\n const errors = {};\n\n ['teacherInstructions', 'prompt'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n let hasCorrectResponse = false;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label, rationale } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n }\n\n if (!getContent(label)) {\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 if (config.rationale?.required && !getContent(rationale)) {\n rationaleErrors[value] = 'This field is required.';\n }\n });\n\n const nbOfChoices = (choices || []).length;\n\n if (nbOfChoices < minAnswerChoices) {\n errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (!hasCorrectResponse) {\n errors.correctResponse = 'No correct response defined.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choices = choicesErrors;\n }\n\n if (!isEmpty(rationaleErrors)) {\n errors.rationale = rationaleErrors;\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AAJA;;AAMA,MAAMK,aAAa,GAAGA,CAACC,KAAK,EAAEC,GAAG,EAAEC,eAAe,KAAMC,MAAM,IAAK;EACjE,MAAM;IAAEC,IAAI;IAAEC;EAAK,CAAC,GAAGJ,GAAG,IAAI,CAAC,CAAC;EAChC,MAAMK,GAAG,GAAG;IACVC,KAAK,EAAEJ,MAAM,CAACI,KAAK;IACnBC,KAAK,EAAEL,MAAM,CAACK;EAChB,CAAC;EAED,IAAIJ,IAAI,KAAK,YAAY,KAAKC,IAAI,KAAK,MAAM,IAAIA,IAAI,KAAK,UAAU,CAAC,EAAE;IACrEC,GAAG,CAACG,SAAS,GAAGT,KAAK,CAACU,gBAAgB,GAAGP,MAAM,CAACM,SAAS,GAAG,I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AChC;EAEA,IAAI,CAAC,IAAA5C,iBAAO,EAAC6C,eAAe,CAAC,EAAE;IAC7BC,MAAM,CAACxG,SAAS,GAAGuG,eAAe;EACpC;EAEA,OAAOC,MAAM;AACf,CAAC;AAACxF,OAAA,CAAAiF,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isResponseCorrect = exports.getCorrectResponse = void 0;
7
+ var _lodashEs = require("lodash-es");
8
+ const getCorrectResponse = choices => choices.filter(c => c.correct).map(c => c.value).sort();
9
+ exports.getCorrectResponse = getCorrectResponse;
10
+ const isResponseCorrect = (question, session) => {
11
+ let correctResponse = getCorrectResponse(question.choices);
12
+ return session && (0, _lodashEs.isEqual)((session.value || []).sort(), correctResponse);
13
+ };
14
+ exports.isResponseCorrect = isResponseCorrect;
15
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["_lodashEs","require","getCorrectResponse","choices","filter","c","correct","map","value","sort","exports","isResponseCorrect","question","session","correctResponse","isEqual"],"sources":["../src/utils.js"],"sourcesContent":["import { isEqual } from 'lodash-es';\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"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEO,MAAMC,kBAAkB,GAAIC,OAAO,IACxCA,OAAO,CACJC,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAACC,OAAO,CAAC,CACxBC,GAAG,CAAEF,CAAC,IAAKA,CAAC,CAACG,KAAK,CAAC,CACnBC,IAAI,CAAC,CAAC;AAACC,OAAA,CAAAR,kBAAA,GAAAA,kBAAA;AAEL,MAAMS,iBAAiB,GAAGA,CAACC,QAAQ,EAAEC,OAAO,KAAK;EACtD,IAAIC,eAAe,GAAGZ,kBAAkB,CAACU,QAAQ,CAACT,OAAO,CAAC;EAC1D,OAAOU,OAAO,IAAI,IAAAE,iBAAO,EAAC,CAACF,OAAO,CAACL,KAAK,IAAI,EAAE,EAAEC,IAAI,CAAC,CAAC,EAAEK,eAAe,CAAC;AAC1E,CAAC;AAACJ,OAAA,CAAAC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@pie-element/multiple-choice-controller",
3
+ "private": true,
4
+ "version": "8.1.1",
5
+ "description": "",
6
+ "main": "lib/index.js",
7
+ "module": "src/index.js",
8
+ "author": "",
9
+ "license": "ISC",
10
+ "dependencies": {
11
+ "@pie-lib/controller-utils": "2.0.2",
12
+ "debug": "^4.1.1",
13
+ "lodash-es": "^4.17.23"
14
+ }
15
+ }