@pie-element/multiple-choice 13.5.0-beta.7 → 14.0.0-next.20261002094057

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 (150) hide show
  1. package/author.js +2 -0
  2. package/configure.js +2 -0
  3. package/controller.js +1 -0
  4. package/dist/author/defaults.d.ts +205 -0
  5. package/dist/author/defaults.js +151 -0
  6. package/dist/author/index.d.ts +26 -0
  7. package/dist/author/index.js +119 -0
  8. package/dist/author/main.d.ts +34 -0
  9. package/dist/author/main.js +287 -0
  10. package/dist/author/utils.d.ts +9 -0
  11. package/dist/author/utils.js +7 -0
  12. package/dist/browser/Radio-CfqdhvRH.js +9769 -0
  13. package/dist/browser/Radio-CfqdhvRH.js.map +1 -0
  14. package/dist/browser/assets/Symbola-4c507403.woff2 +0 -0
  15. package/dist/browser/author/index.js +35079 -0
  16. package/dist/browser/author/index.js.map +1 -0
  17. package/dist/browser/controller/index.js +204 -0
  18. package/dist/browser/controller/index.js.map +1 -0
  19. package/dist/browser/delivery/index.js +303 -0
  20. package/dist/browser/delivery/index.js.map +1 -0
  21. package/dist/browser/dist-CHbLnyuX.js +111 -0
  22. package/dist/browser/dist-CHbLnyuX.js.map +1 -0
  23. package/dist/browser/editor-runtime/Radio-D3ynJgVj.js +9769 -0
  24. package/dist/browser/editor-runtime/Radio-D3ynJgVj.js.map +1 -0
  25. package/dist/browser/editor-runtime/assets/Symbola-4c507403.woff2 +0 -0
  26. package/dist/browser/editor-runtime/author/index.js +18670 -0
  27. package/dist/browser/editor-runtime/author/index.js.map +1 -0
  28. package/dist/browser/editor-runtime/controller/index.js +204 -0
  29. package/dist/browser/editor-runtime/controller/index.js.map +1 -0
  30. package/dist/browser/editor-runtime/delivery/index.js +303 -0
  31. package/dist/browser/editor-runtime/delivery/index.js.map +1 -0
  32. package/dist/browser/editor-runtime/dist-CHbLnyuX.js +111 -0
  33. package/dist/browser/editor-runtime/dist-CHbLnyuX.js.map +1 -0
  34. package/dist/browser/editor-runtime/main-BzlfiDu3.js +2553 -0
  35. package/dist/browser/editor-runtime/main-BzlfiDu3.js.map +1 -0
  36. package/dist/browser/editor-runtime/print/index.js +45 -0
  37. package/dist/browser/editor-runtime/print/index.js.map +1 -0
  38. package/dist/browser/main-0JQfvG0B.js +2553 -0
  39. package/dist/browser/main-0JQfvG0B.js.map +1 -0
  40. package/dist/browser/print/index.js +45 -0
  41. package/dist/browser/print/index.js.map +1 -0
  42. package/dist/controller/defaults.d.ts +35 -0
  43. package/dist/controller/defaults.js +29 -0
  44. package/dist/controller/index.d.ts +65 -0
  45. package/dist/controller/index.js +129 -0
  46. package/dist/controller/utils.d.ts +10 -0
  47. package/dist/controller/utils.js +8 -0
  48. package/dist/delivery/choice-input.d.ts +44 -0
  49. package/dist/delivery/choice-input.js +280 -0
  50. package/dist/delivery/choice.d.ts +20 -0
  51. package/dist/delivery/choice.js +106 -0
  52. package/dist/delivery/feedback-tick.d.ts +20 -0
  53. package/dist/delivery/feedback-tick.js +104 -0
  54. package/dist/delivery/index.d.ts +37 -0
  55. package/dist/delivery/index.js +217 -0
  56. package/dist/delivery/main.d.ts +31 -0
  57. package/dist/delivery/main.js +51 -0
  58. package/dist/delivery/multiple-choice.d.ts +61 -0
  59. package/dist/delivery/multiple-choice.js +245 -0
  60. package/dist/delivery/session-updater.d.ts +10 -0
  61. package/dist/delivery/session-updater.js +9 -0
  62. package/dist/delivery/utils.d.ts +10 -0
  63. package/dist/delivery/utils.js +4 -0
  64. package/dist/index.d.ts +1 -0
  65. package/dist/index.iife.d.ts +8 -0
  66. package/dist/index.iife.js +148 -0
  67. package/dist/index.js +2 -0
  68. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  69. package/dist/print/index.d.ts +15 -0
  70. package/dist/print/index.js +45 -0
  71. package/dist/runtime-support.d.ts +12 -0
  72. package/dist/runtime-support.js +12 -0
  73. package/module/print.js +18205 -1
  74. package/module/print.js.map +1 -0
  75. package/package.json +107 -30
  76. package/print.js +2 -0
  77. package/CHANGELOG.json +0 -1972
  78. package/CHANGELOG.md +0 -2777
  79. package/LICENSE.md +0 -5
  80. package/PRINT.md +0 -35
  81. package/README.md +0 -56
  82. package/choice.png +0 -0
  83. package/configure/CHANGELOG.json +0 -1387
  84. package/configure/CHANGELOG.md +0 -2117
  85. package/configure/lib/__tests__/root.test.js +0 -279
  86. package/configure/lib/defaults.js +0 -203
  87. package/configure/lib/defaults.js.map +0 -1
  88. package/configure/lib/index.js +0 -203
  89. package/configure/lib/index.js.map +0 -1
  90. package/configure/lib/main.js +0 -484
  91. package/configure/lib/main.js.map +0 -1
  92. package/configure/lib/utils.js +0 -18
  93. package/configure/lib/utils.js.map +0 -1
  94. package/configure/package.json +0 -22
  95. package/controller/CHANGELOG.json +0 -527
  96. package/controller/CHANGELOG.md +0 -1448
  97. package/controller/lib/__tests__/index.test.js +0 -561
  98. package/controller/lib/__tests__/utils.test.js +0 -8
  99. package/controller/lib/defaults.js +0 -33
  100. package/controller/lib/defaults.js.map +0 -1
  101. package/controller/lib/index.js +0 -298
  102. package/controller/lib/index.js.map +0 -1
  103. package/controller/lib/utils.js +0 -15
  104. package/controller/lib/utils.js.map +0 -1
  105. package/controller/package.json +0 -15
  106. package/docs/config-schema.json +0 -2993
  107. package/docs/config-schema.json.md +0 -2217
  108. package/docs/demo/config.js +0 -8
  109. package/docs/demo/generate.js +0 -61
  110. package/docs/demo/index.html +0 -1
  111. package/docs/demo/pie.manifest.json +0 -11
  112. package/docs/demo/session.js +0 -7
  113. package/docs/pie-schema.json +0 -1332
  114. package/docs/pie-schema.json.md +0 -1015
  115. package/lib/__tests__/choice-input-test.js +0 -49
  116. package/lib/__tests__/choice-input.test.js +0 -49
  117. package/lib/__tests__/index-test.js +0 -206
  118. package/lib/__tests__/index.test.js +0 -221
  119. package/lib/__tests__/key-events-test.js +0 -95
  120. package/lib/__tests__/key-events.test.js +0 -107
  121. package/lib/__tests__/multiple-choice-test.js +0 -101
  122. package/lib/__tests__/multiple-choice.test.js +0 -256
  123. package/lib/__tests__/session-updater-test.js +0 -70
  124. package/lib/__tests__/session-updater.test.js +0 -70
  125. package/lib/choice-input.js +0 -383
  126. package/lib/choice-input.js.map +0 -1
  127. package/lib/choice.js +0 -192
  128. package/lib/choice.js.map +0 -1
  129. package/lib/feedback-tick.js +0 -134
  130. package/lib/feedback-tick.js.map +0 -1
  131. package/lib/index.js +0 -405
  132. package/lib/index.js.map +0 -1
  133. package/lib/main.js +0 -63
  134. package/lib/main.js.map +0 -1
  135. package/lib/multiple-choice.js +0 -399
  136. package/lib/multiple-choice.js.map +0 -1
  137. package/lib/print.js +0 -94
  138. package/lib/print.js.map +0 -1
  139. package/lib/session-updater.js +0 -37
  140. package/lib/session-updater.js.map +0 -1
  141. package/lib/utils.js +0 -14
  142. package/lib/utils.js.map +0 -1
  143. package/module/configure.js +0 -1
  144. package/module/controller.js +0 -3045
  145. package/module/demo.js +0 -86
  146. package/module/element.js +0 -1
  147. package/module/index.html +0 -21
  148. package/module/manifest.json +0 -14
  149. package/module/print-demo.js +0 -124
  150. package/module/print.html +0 -18
@@ -1,33 +0,0 @@
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
@@ -1 +0,0 @@
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":[]}
@@ -1,298 +0,0 @@
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
- let correctCount = 0;
249
- reversedChoices.forEach((choice, index) => {
250
- const {
251
- correct,
252
- value,
253
- label,
254
- rationale
255
- } = choice;
256
- if (correct) {
257
- hasCorrectResponse = true;
258
- correctCount++;
259
- }
260
- if (!getContent(label)) {
261
- choicesErrors[value] = 'Content should not be empty.';
262
- } else {
263
- const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);
264
- if (identicalAnswer) {
265
- choicesErrors[value] = 'Content should be unique.';
266
- }
267
- }
268
- if (config.rationale?.required && !getContent(rationale)) {
269
- rationaleErrors[value] = 'This field is required.';
270
- }
271
- });
272
- const nbOfChoices = (choices || []).length;
273
- if (nbOfChoices < minAnswerChoices) {
274
- errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;
275
- } else if (nbOfChoices > maxAnswerChoices) {
276
- errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;
277
- }
278
- if (!hasCorrectResponse) {
279
- errors.correctResponse = 'No correct response defined.';
280
- } else {
281
- const {
282
- maxSelections,
283
- choiceMode
284
- } = model;
285
- if (choiceMode !== 'radio' && maxSelections != null && correctCount > maxSelections) {
286
- errors.correctResponse = `The number of correct answers (${correctCount}) exceeds max selections (${maxSelections}). Students won't be able to select all correct answers.`;
287
- }
288
- }
289
- if (!(0, _lodashEs.isEmpty)(choicesErrors)) {
290
- errors.choices = choicesErrors;
291
- }
292
- if (!(0, _lodashEs.isEmpty)(rationaleErrors)) {
293
- errors.rationale = rationaleErrors;
294
- }
295
- return errors;
296
- };
297
- exports.validate = validate;
298
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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","correctCount","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 let correctCount = 0;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label, rationale } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n correctCount++;\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 } else {\n const { maxSelections, choiceMode } = model;\n\n if (choiceMode !== 'radio' && maxSelections != null && correctCount > maxSelections) {\n errors.correctResponse = `The number of correct answers (${correctCount}) exceeds max selections (${maxSelections}). Students won't be able to select all correct answers.`;\n }\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,MA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AEnE,aAAa;MAAEjB;IAAW,CAAC,GAAGzC,KAAK;IAE3C,IAAIyC,UAAU,KAAK,OAAO,IAAIiB,aAAa,IAAI,IAAI,IAAI4D,YAAY,GAAG5D,aAAa,EAAE;MACnFuD,MAAM,CAACY,eAAe,GAAG,kCAAkCP,YAAY,6BAA6B5D,aAAa,0DAA0D;IAC7K;EACF;EAEA,IAAI,CAAC,IAAAS,iBAAO,EAAC4C,aAAa,CAAC,EAAE;IAC3BE,MAAM,CAACjF,OAAO,GAAG+E,aAAa;EAChC;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":[]}
@@ -1,15 +0,0 @@
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
@@ -1 +0,0 @@
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":[]}
@@ -1,15 +0,0 @@
1
- {
2
- "name": "@pie-element/multiple-choice-controller",
3
- "private": true,
4
- "version": "8.4.0-beta.7",
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.3",
12
- "debug": "^4.1.1",
13
- "lodash-es": "^4.17.23"
14
- }
15
- }