@pie-element/inline-dropdown 10.1.2-next.5 → 10.1.3
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.
- package/CHANGELOG.json +1082 -0
- package/CHANGELOG.md +2198 -0
- package/LICENSE.md +5 -0
- package/README.md +1 -0
- package/configure/CHANGELOG.json +647 -0
- package/configure/CHANGELOG.md +1955 -0
- package/configure/lib/defaults.js +192 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/index.js +135 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/inline-dropdown-toolbar.js +456 -0
- package/configure/lib/inline-dropdown-toolbar.js.map +1 -0
- package/configure/lib/main.js +612 -0
- package/configure/lib/main.js.map +1 -0
- package/configure/lib/markupUtils.js +50 -0
- package/configure/lib/markupUtils.js.map +1 -0
- package/configure/lib/response-area.js +48 -0
- package/configure/lib/response-area.js.map +1 -0
- package/configure/lib/utils.js +22 -0
- package/configure/lib/utils.js.map +1 -0
- package/configure/package.json +24 -0
- package/controller/CHANGELOG.json +467 -0
- package/controller/CHANGELOG.md +1283 -0
- package/controller/lib/defaults.js +25 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +295 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/utils.js +32 -0
- package/controller/lib/utils.js.map +1 -0
- package/controller/package.json +16 -0
- package/docs/config-schema.json +2854 -0
- package/docs/config-schema.json.md +2106 -0
- package/docs/demo/config.js +8 -0
- package/docs/demo/generate.js +76 -0
- package/docs/demo/index.html +1 -0
- package/docs/demo/session.js +11 -0
- package/docs/pie-schema.json +1152 -0
- package/docs/pie-schema.json.md +814 -0
- package/lib/index.js +85 -0
- package/lib/index.js.map +1 -0
- package/lib/inline-dropdown.js +176 -0
- package/lib/inline-dropdown.js.map +1 -0
- package/package.json +21 -85
- package/configure.js +0 -2
- package/controller.js +0 -1
- package/dist/author/defaults.d.ts +0 -194
- package/dist/author/defaults.js +0 -130
- package/dist/author/index.d.ts +0 -43
- package/dist/author/index.js +0 -83
- package/dist/author/inline-dropdown-toolbar.d.ts +0 -48
- package/dist/author/inline-dropdown-toolbar.js +0 -268
- package/dist/author/main.d.ts +0 -49
- package/dist/author/main.js +0 -379
- package/dist/author/markupUtils.d.ts +0 -12
- package/dist/author/markupUtils.js +0 -23
- package/dist/author/response-area.d.ts +0 -20
- package/dist/author/response-area.js +0 -32
- package/dist/author/utils.d.ts +0 -10
- package/dist/author/utils.js +0 -10
- package/dist/browser/Close-mCudNyrp.js +0 -9031
- package/dist/browser/Close-mCudNyrp.js.map +0 -1
- package/dist/browser/author/index.js +0 -46481
- package/dist/browser/author/index.js.map +0 -1
- package/dist/browser/controller/index.js +0 -196
- package/dist/browser/controller/index.js.map +0 -1
- package/dist/browser/delivery/index.js +0 -2714
- package/dist/browser/delivery/index.js.map +0 -1
- package/dist/browser/dist-Oyzav2lb.js +0 -137
- package/dist/browser/dist-Oyzav2lb.js.map +0 -1
- package/dist/browser/inline-dropdown.css +0 -2
- package/dist/controller/defaults.d.ts +0 -27
- package/dist/controller/defaults.js +0 -21
- package/dist/controller/index.d.ts +0 -54
- package/dist/controller/index.js +0 -124
- package/dist/controller/utils.d.ts +0 -12
- package/dist/controller/utils.js +0 -13
- package/dist/delivery/index.d.ts +0 -20
- package/dist/delivery/index.js +0 -60
- package/dist/delivery/inline-dropdown.d.ts +0 -38
- package/dist/delivery/inline-dropdown.js +0 -109
- package/dist/index.d.ts +0 -1
- package/dist/index.iife.d.ts +0 -8
- package/dist/index.iife.js +0 -148
- package/dist/index.js +0 -2
- package/dist/runtime-support.d.ts +0 -12
- package/dist/runtime-support.js +0 -12
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
alternateResponse: {},
|
|
9
|
+
choiceRationaleEnabled: true,
|
|
10
|
+
choices: {},
|
|
11
|
+
disabled: false,
|
|
12
|
+
displayType: 'block',
|
|
13
|
+
markup: '',
|
|
14
|
+
mode: 'gather',
|
|
15
|
+
prompt: '',
|
|
16
|
+
promptEnabled: true,
|
|
17
|
+
rationale: '',
|
|
18
|
+
rationaleEnabled: true,
|
|
19
|
+
shuffle: true,
|
|
20
|
+
studentInstructionsEnabled: true,
|
|
21
|
+
teacherInstructions: '',
|
|
22
|
+
teacherInstructionsEnabled: true,
|
|
23
|
+
toolbarEditorPosition: 'bottom'
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","names":["alternateResponse","choiceRationaleEnabled","choices","disabled","displayType","markup","mode","prompt","promptEnabled","rationale","rationaleEnabled","shuffle","studentInstructionsEnabled","teacherInstructions","teacherInstructionsEnabled","toolbarEditorPosition"],"sources":["../src/defaults.js"],"sourcesContent":["export default {\n alternateResponse: {},\n choiceRationaleEnabled: true,\n choices: {},\n disabled: false,\n displayType: 'block',\n markup: '',\n mode: 'gather',\n prompt: '',\n promptEnabled: true,\n rationale: '',\n rationaleEnabled: true,\n shuffle: true,\n studentInstructionsEnabled: true,\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n toolbarEditorPosition: 'bottom',\n};\n"],"mappings":";;;;;;iCAAe;EACbA,iBAAiB,EAAE,CAAC,CAAC;EACrBC,sBAAsB,EAAE,IAAI;EAC5BC,OAAO,EAAE,CAAC,CAAC;EACXC,QAAQ,EAAE,KAAK;EACfC,WAAW,EAAE,OAAO;EACpBC,MAAM,EAAE,EAAE;EACVC,IAAI,EAAE,QAAQ;EACdC,MAAM,EAAE,EAAE;EACVC,aAAa,EAAE,IAAI;EACnBC,SAAS,EAAE,EAAE;EACbC,gBAAgB,EAAE,IAAI;EACtBC,OAAO,EAAE,IAAI;EACbC,0BAA0B,EAAE,IAAI;EAChCC,mBAAmB,EAAE,EAAE;EACvBC,0BAA0B,EAAE,IAAI;EAChCC,qBAAqB,EAAE;AACzB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getScore = exports.getLogTrace = exports.createCorrectResponseSession = void 0;
|
|
8
|
+
exports.model = model;
|
|
9
|
+
exports.normalize = void 0;
|
|
10
|
+
exports.outcome = outcome;
|
|
11
|
+
exports.validate = void 0;
|
|
12
|
+
var _lodashEs = require("lodash-es");
|
|
13
|
+
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
14
|
+
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
15
|
+
var _utils = require("./utils");
|
|
16
|
+
const getFeedback = correct => {
|
|
17
|
+
if (correct) {
|
|
18
|
+
return 'correct';
|
|
19
|
+
}
|
|
20
|
+
return 'incorrect';
|
|
21
|
+
};
|
|
22
|
+
const normalize = question => ({
|
|
23
|
+
..._defaults.default,
|
|
24
|
+
...question
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param {*} question
|
|
30
|
+
* @param {*} session
|
|
31
|
+
* @param {*} env
|
|
32
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
33
|
+
*/
|
|
34
|
+
exports.normalize = normalize;
|
|
35
|
+
async function model(question, session, env, updateSession) {
|
|
36
|
+
const normalizedQuestion = normalize(question);
|
|
37
|
+
const {
|
|
38
|
+
value = {}
|
|
39
|
+
} = session || {};
|
|
40
|
+
let choices = (0, _lodashEs.reduce)(normalizedQuestion.choices, (obj, area, key) => {
|
|
41
|
+
obj[key] = (0, _lodashEs.map)(area, choice => choice);
|
|
42
|
+
return obj;
|
|
43
|
+
}, {});
|
|
44
|
+
let feedback = {};
|
|
45
|
+
if (env.mode === 'evaluate') {
|
|
46
|
+
const allCorrectResponses = (0, _utils.getAllCorrectResponses)(normalizedQuestion);
|
|
47
|
+
const respAreaLength = Object.keys(allCorrectResponses).length;
|
|
48
|
+
let correctResponses = 0;
|
|
49
|
+
for (let i = 0; i < respAreaLength; i++) {
|
|
50
|
+
const result = (0, _lodashEs.reduce)(allCorrectResponses, (obj, choices, key) => {
|
|
51
|
+
const answer = value && value[key] || '';
|
|
52
|
+
const correctChoice = choices[i] || '';
|
|
53
|
+
const isCorrect = answer && correctChoice && correctChoice === answer;
|
|
54
|
+
obj.feedback[key] = getFeedback(isCorrect);
|
|
55
|
+
if (isCorrect) {
|
|
56
|
+
obj.correctResponses += 1;
|
|
57
|
+
}
|
|
58
|
+
return obj;
|
|
59
|
+
}, {
|
|
60
|
+
correctResponses: 0,
|
|
61
|
+
feedback: {}
|
|
62
|
+
});
|
|
63
|
+
if (result.correctResponses >= correctResponses) {
|
|
64
|
+
correctResponses = result.correctResponses;
|
|
65
|
+
feedback = result.feedback;
|
|
66
|
+
}
|
|
67
|
+
if (result.correctResponses === respAreaLength) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
|
|
73
|
+
if (!lockChoiceOrder) {
|
|
74
|
+
const shuffledValues = {};
|
|
75
|
+
const keys = Object.keys(choices);
|
|
76
|
+
const us = part => (id, element, update) => {
|
|
77
|
+
return new Promise(resolve => {
|
|
78
|
+
shuffledValues[part] = update.shuffledValues;
|
|
79
|
+
resolve();
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
let i;
|
|
83
|
+
for (i = 0; i < keys.length; i++) {
|
|
84
|
+
const key = keys[i];
|
|
85
|
+
const storedValues = session?.shuffledValues?.[key];
|
|
86
|
+
choices[key] = await (0, _controllerUtils.getShuffledChoices)(choices[key],
|
|
87
|
+
// the shuffledValues structure was updated to an object like { choice_key: [] }
|
|
88
|
+
// and we need to override shuffledValues if it's not an array
|
|
89
|
+
{
|
|
90
|
+
shuffledValues: Array.isArray(storedValues) ? storedValues : []
|
|
91
|
+
}, us(key), 'value');
|
|
92
|
+
}
|
|
93
|
+
if (!(0, _lodashEs.isEmpty)(shuffledValues)) {
|
|
94
|
+
if (session && updateSession && typeof updateSession === 'function') {
|
|
95
|
+
updateSession(session.id, session.element, {
|
|
96
|
+
shuffledValues
|
|
97
|
+
}).catch(e => {
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.error('update session failed', e);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
let teacherInstructions = null;
|
|
105
|
+
let rationale = null;
|
|
106
|
+
const choicesWillNullRationales = (Object.keys(choices) || []).reduce((acc, currentValue) => {
|
|
107
|
+
acc[currentValue] = (choices[currentValue] || []).map(choice => ({
|
|
108
|
+
...choice,
|
|
109
|
+
rationale: null
|
|
110
|
+
}));
|
|
111
|
+
return acc;
|
|
112
|
+
}, {});
|
|
113
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
114
|
+
rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
115
|
+
teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
116
|
+
choices = normalizedQuestion.choiceRationaleEnabled ? normalizedQuestion.choices : choicesWillNullRationales;
|
|
117
|
+
} else {
|
|
118
|
+
rationale = null;
|
|
119
|
+
teacherInstructions = null;
|
|
120
|
+
choices = choicesWillNullRationales;
|
|
121
|
+
}
|
|
122
|
+
const out = {
|
|
123
|
+
disabled: env.mode !== 'gather',
|
|
124
|
+
mode: env.mode,
|
|
125
|
+
prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
|
|
126
|
+
displayType: normalizedQuestion.displayType,
|
|
127
|
+
markup: normalizedQuestion.markup,
|
|
128
|
+
choices,
|
|
129
|
+
feedback,
|
|
130
|
+
responseCorrect: env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined,
|
|
131
|
+
rationale,
|
|
132
|
+
teacherInstructions,
|
|
133
|
+
language: normalizedQuestion.language,
|
|
134
|
+
extraCSSRules: normalizedQuestion.extraCSSRules
|
|
135
|
+
};
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
const getScore = (config, session) => {
|
|
139
|
+
const {
|
|
140
|
+
value = {}
|
|
141
|
+
} = session || {};
|
|
142
|
+
const maxScore = config && config.choices ? Object.keys(config.choices).length : 0;
|
|
143
|
+
const allCorrectResponses = (0, _utils.getAllCorrectResponses)(config);
|
|
144
|
+
let correctCount = 0;
|
|
145
|
+
for (let i = 0; i < maxScore; i++) {
|
|
146
|
+
const result = (0, _lodashEs.reduce)(allCorrectResponses, (total, choices, key) => {
|
|
147
|
+
const answer = value && value[key] || '';
|
|
148
|
+
const correctChoice = choices[i] || '';
|
|
149
|
+
if (correctChoice && answer && correctChoice === answer) {
|
|
150
|
+
return total;
|
|
151
|
+
}
|
|
152
|
+
return total - 1;
|
|
153
|
+
}, maxScore);
|
|
154
|
+
if (result > correctCount) {
|
|
155
|
+
correctCount = result;
|
|
156
|
+
}
|
|
157
|
+
if (result === maxScore) {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const str = (correctCount / maxScore).toFixed(2);
|
|
162
|
+
return parseFloat(str);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Generates detailed trace log for scoring evaluation
|
|
167
|
+
* @param {Object} model - the question model
|
|
168
|
+
* @param {Object} session - the student session
|
|
169
|
+
* @param {Object} env - the environment
|
|
170
|
+
* @returns {Array} traceLog - array of trace messages
|
|
171
|
+
*/
|
|
172
|
+
exports.getScore = getScore;
|
|
173
|
+
const getLogTrace = (model, session, env) => {
|
|
174
|
+
const traceLog = [];
|
|
175
|
+
const {
|
|
176
|
+
value = {}
|
|
177
|
+
} = session || {};
|
|
178
|
+
const allCorrectResponses = (0, _utils.getAllCorrectResponses)(model);
|
|
179
|
+
const responseAreaKeys = Object.keys(allCorrectResponses);
|
|
180
|
+
const totalAreas = responseAreaKeys.length;
|
|
181
|
+
traceLog.push(`${totalAreas} dropdown response area(s) defined in this question.`);
|
|
182
|
+
if (value && Object.keys(value).length > 0) {
|
|
183
|
+
const selectedAreas = Object.entries(value).filter(([key, val]) => val && val.trim()).length;
|
|
184
|
+
traceLog.push(`Student selected options in ${selectedAreas} out of ${totalAreas} dropdown(s).`);
|
|
185
|
+
responseAreaKeys.forEach(areaKey => {
|
|
186
|
+
const studentSelection = value && value[areaKey] || '';
|
|
187
|
+
const correctOptions = allCorrectResponses[areaKey] || [];
|
|
188
|
+
if (studentSelection.trim()) {
|
|
189
|
+
traceLog.push(`Dropdown ${parseInt(areaKey) + 1}: student selected '${studentSelection}' (correct options: [${correctOptions.map(opt => `'${opt}'`).join(', ')}]).`);
|
|
190
|
+
} else {
|
|
191
|
+
traceLog.push(`Dropdown ${parseInt(areaKey) + 1}: no selection made (correct options: [${correctOptions.map(opt => `'${opt}'`).join(', ')}]).`);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
} else {
|
|
195
|
+
traceLog.push('Student did not make any selections in the dropdowns.');
|
|
196
|
+
}
|
|
197
|
+
const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
|
|
198
|
+
traceLog.push(`Scoring method: ${partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring'}.`);
|
|
199
|
+
const score = getScore(model, session);
|
|
200
|
+
traceLog.push(`Final score: ${score}.`);
|
|
201
|
+
return traceLog;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* The score is partial by default for checkbox mode, allOrNothing for radio mode.
|
|
207
|
+
* To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =
|
|
208
|
+
* false. the value in `env` will override the value in `model`.
|
|
209
|
+
* @param {Object} model - the main model
|
|
210
|
+
* @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)
|
|
211
|
+
* @param {*} session
|
|
212
|
+
* @param {Object} env
|
|
213
|
+
* @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides
|
|
214
|
+
* `model.partialScoring`.
|
|
215
|
+
*/
|
|
216
|
+
exports.getLogTrace = getLogTrace;
|
|
217
|
+
function outcome(model, session, env = {}) {
|
|
218
|
+
return new Promise(resolve => {
|
|
219
|
+
if (!session || (0, _lodashEs.isEmpty)(session)) {
|
|
220
|
+
resolve({
|
|
221
|
+
score: 0,
|
|
222
|
+
empty: true,
|
|
223
|
+
traceLog: ['Student did not make any selections in the dropdowns. Score is 0.']
|
|
224
|
+
});
|
|
225
|
+
} else {
|
|
226
|
+
const traceLog = getLogTrace(model, session, env);
|
|
227
|
+
const score = getScore(model, session);
|
|
228
|
+
const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
|
|
229
|
+
resolve({
|
|
230
|
+
score: partialScoringEnabled ? score : Math.floor(score),
|
|
231
|
+
empty: false,
|
|
232
|
+
traceLog
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const createCorrectResponseSession = (question, env) => {
|
|
238
|
+
return new Promise(resolve => {
|
|
239
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
240
|
+
const {
|
|
241
|
+
choices
|
|
242
|
+
} = question;
|
|
243
|
+
const value = {};
|
|
244
|
+
if (choices) {
|
|
245
|
+
Object.keys(choices).forEach((key, i) => {
|
|
246
|
+
const correctChoices = choices[key] && choices[key].filter(c => c.correct);
|
|
247
|
+
value[i] = correctChoices && correctChoices[0].value;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
resolve({
|
|
251
|
+
id: '1',
|
|
252
|
+
value
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
resolve(null);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// remove all html tags
|
|
261
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
262
|
+
const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
263
|
+
|
|
264
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
265
|
+
const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
266
|
+
const validate = (model = {}, config = {}) => {
|
|
267
|
+
const {
|
|
268
|
+
markup,
|
|
269
|
+
choices
|
|
270
|
+
} = model;
|
|
271
|
+
const {
|
|
272
|
+
maxResponseAreas,
|
|
273
|
+
maxResponseAreaChoices
|
|
274
|
+
} = config;
|
|
275
|
+
const errors = {};
|
|
276
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
|
|
277
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
278
|
+
errors[field] = 'This field is required.';
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
const nbOfResponseAreas = ((markup || '').match(/\{\{(\d+)\}\}/g) || []).length;
|
|
282
|
+
if (nbOfResponseAreas > maxResponseAreas) {
|
|
283
|
+
errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;
|
|
284
|
+
} else if (nbOfResponseAreas < 1) {
|
|
285
|
+
errors.responseAreasError = 'There should be defined at least 1 response area.';
|
|
286
|
+
}
|
|
287
|
+
(Object.keys(choices) || []).forEach(choiceKey => {
|
|
288
|
+
if (choices[choiceKey] && choices[choiceKey].length > maxResponseAreaChoices) {
|
|
289
|
+
errors.responseAreaChoicesError = `No more than ${maxResponseAreaChoices} choices per response area should be defined.`;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
return errors;
|
|
293
|
+
};
|
|
294
|
+
exports.validate = validate;
|
|
295
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_lodashEs","require","_controllerUtils","_defaults","_interopRequireDefault","_utils","getFeedback","correct","normalize","question","defaults","exports","model","session","env","updateSession","normalizedQuestion","value","choices","reduce","obj","area","key","map","choice","feedback","mode","allCorrectResponses","getAllCorrectResponses","respAreaLength","Object","keys","length","correctResponses","i","result","answer","correctChoice","isCorrect","lockChoiceOrder","lockChoices","shuffledValues","us","part","id","element","update","Promise","resolve","storedValues","getShuffledChoices","Array","isArray","isEmpty","catch","e","console","error","teacherInstructions","rationale","choicesWillNullRationales","acc","currentValue","role","rationaleEnabled","teacherInstructionsEnabled","choiceRationaleEnabled","out","disabled","prompt","promptEnabled","displayType","markup","responseCorrect","getScore","undefined","language","extraCSSRules","config","maxScore","correctCount","total","str","toFixed","parseFloat","getLogTrace","traceLog","responseAreaKeys","totalAreas","push","selectedAreas","entries","filter","val","trim","forEach","areaKey","studentSelection","correctOptions","parseInt","opt","join","partialScoringEnabled","partialScoring","enabled","score","outcome","empty","Math","floor","createCorrectResponseSession","correctChoices","c","getInnerText","html","replaceAll","getContent","replace","validate","maxResponseAreas","maxResponseAreaChoices","errors","field","required","nbOfResponseAreas","match","responseAreasError","choiceKey","responseAreaChoicesError"],"sources":["../src/index.js"],"sourcesContent":["import { isEmpty, map, reduce } from 'lodash-es';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport defaults from './defaults';\n\nimport { getAllCorrectResponses } from './utils';\n\nconst getFeedback = (correct) => {\n if (correct) {\n return 'correct';\n }\n\n return 'incorrect';\n};\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n const normalizedQuestion = normalize(question);\n const { value = {} } = session || {};\n let choices = reduce(\n normalizedQuestion.choices,\n (obj, area, key) => {\n obj[key] = map(area, (choice) => choice);\n\n return obj;\n },\n {},\n );\n\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n const respAreaLength = Object.keys(allCorrectResponses).length;\n let correctResponses = 0;\n\n for (let i = 0; i < respAreaLength; i++) {\n const result = reduce(\n allCorrectResponses,\n (obj, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n const isCorrect = answer && correctChoice && correctChoice === answer;\n\n obj.feedback[key] = getFeedback(isCorrect);\n\n if (isCorrect) {\n obj.correctResponses += 1;\n }\n\n return obj;\n },\n { correctResponses: 0, feedback: {} },\n );\n\n if (result.correctResponses >= correctResponses) {\n correctResponses = result.correctResponses;\n feedback = result.feedback;\n }\n\n if (result.correctResponses === respAreaLength) {\n break;\n }\n }\n }\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n const shuffledValues = {};\n const keys = Object.keys(choices);\n\n const us = (part) => (id, element, update) => {\n return new Promise((resolve) => {\n shuffledValues[part] = update.shuffledValues;\n resolve();\n });\n };\n\n let i;\n\n for (i = 0; i < keys.length; i++) {\n const key = keys[i];\n const storedValues = session?.shuffledValues?.[key];\n\n choices[key] = await getShuffledChoices(\n choices[key],\n // the shuffledValues structure was updated to an object like { choice_key: [] }\n // and we need to override shuffledValues if it's not an array\n { shuffledValues: Array.isArray(storedValues) ? storedValues : [] },\n us(key),\n 'value',\n );\n }\n\n if (!isEmpty(shuffledValues)) {\n if (session && updateSession && typeof updateSession === 'function') {\n updateSession(session.id, session.element, {\n shuffledValues,\n }).catch((e) => {\n // eslint-disable-next-line no-console\n console.error('update session failed', e);\n });\n }\n }\n }\n\n let teacherInstructions = null;\n let rationale = null;\n\n const choicesWillNullRationales = (Object.keys(choices) || []).reduce((acc, currentValue) => {\n acc[currentValue] = (choices[currentValue] || []).map((choice) => ({\n ...choice,\n rationale: null,\n }));\n\n return acc;\n }, {});\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;\n\n choices = normalizedQuestion.choiceRationaleEnabled ? normalizedQuestion.choices : choicesWillNullRationales;\n } else {\n rationale = null;\n teacherInstructions = null;\n choices = choicesWillNullRationales;\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n displayType: normalizedQuestion.displayType,\n markup: normalizedQuestion.markup,\n choices,\n feedback,\n\n responseCorrect: env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined,\n rationale,\n teacherInstructions,\n language: normalizedQuestion.language,\n extraCSSRules: normalizedQuestion.extraCSSRules,\n };\n\n return out;\n}\n\nexport const getScore = (config, session) => {\n const { value = {} } = session || {};\n const maxScore = config && config.choices ? Object.keys(config.choices).length : 0;\n const allCorrectResponses = getAllCorrectResponses(config);\n let correctCount = 0;\n\n for (let i = 0; i < maxScore; i++) {\n const result = reduce(\n allCorrectResponses,\n (total, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n\n if (correctChoice && answer && correctChoice === answer) {\n return total;\n }\n\n return total - 1;\n },\n maxScore,\n );\n\n if (result > correctCount) {\n correctCount = result;\n }\n\n if (result === maxScore) {\n break;\n }\n }\n\n const str = (correctCount / maxScore).toFixed(2);\n\n return parseFloat(str);\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 { value = {} } = session || {};\n const allCorrectResponses = getAllCorrectResponses(model);\n const responseAreaKeys = Object.keys(allCorrectResponses);\n const totalAreas = responseAreaKeys.length;\n \n traceLog.push(`${totalAreas} dropdown response area(s) defined in this question.`);\n \n if (value && Object.keys(value).length > 0) {\n const selectedAreas = Object.entries(value).filter(([key, val]) => val && val.trim()).length;\n traceLog.push(`Student selected options in ${selectedAreas} out of ${totalAreas} dropdown(s).`);\n \n responseAreaKeys.forEach((areaKey) => {\n const studentSelection = (value && value[areaKey]) || '';\n const correctOptions = allCorrectResponses[areaKey] || [];\n \n if (studentSelection.trim()) {\n traceLog.push(`Dropdown ${parseInt(areaKey) + 1}: student selected '${studentSelection}' (correct options: [${correctOptions.map(opt => `'${opt}'`).join(', ')}]).`);\n } else {\n traceLog.push(`Dropdown ${parseInt(areaKey) + 1}: no selection made (correct options: [${correctOptions.map(opt => `'${opt}'`).join(', ')}]).`);\n }\n });\n } else {\n traceLog.push('Student did not make any selections in the dropdowns.');\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env);\n traceLog.push(\n `Scoring method: ${\n partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring'\n }.`\n );\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 =\n * false. the value in `env` will override the value in `model`.\n * @param {Object} model - the main model\n * @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)\n * @param {*} session\n * @param {Object} env\n * @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides\n * `model.partialScoring`.\n */\nexport function outcome(model, session, env = {}) {\n return new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ \n score: 0, \n empty: true, \n traceLog: ['Student did not make any selections in the dropdowns. Score is 0.'] \n });\n } else {\n const traceLog = getLogTrace(model, session, env);\n const score = getScore(model, session);\n const partialScoringEnabled = partialScoring.enabled(model, env);\n\n resolve({\n score: partialScoringEnabled ? score : Math.floor(score),\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;\n const value = {};\n\n if (choices) {\n Object.keys(choices).forEach((key, i) => {\n const correctChoices = choices[key] && choices[key].filter((c) => c.correct);\n\n value[i] = correctChoices && correctChoices[0].value;\n });\n }\n\n resolve({\n id: '1',\n 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 { markup, choices } = model;\n const { maxResponseAreas, maxResponseAreaChoices } = config;\n const errors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n const nbOfResponseAreas = ((markup || '').match(/\\{\\{(\\d+)\\}\\}/g) || []).length;\n\n if (nbOfResponseAreas > maxResponseAreas) {\n errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;\n } else if (nbOfResponseAreas < 1) {\n errors.responseAreasError = 'There should be defined at least 1 response area.';\n }\n\n (Object.keys(choices) || []).forEach((choiceKey) => {\n if (choices[choiceKey] && choices[choiceKey].length > maxResponseAreaChoices) {\n errors.responseAreaChoicesError = `No more than ${maxResponseAreaChoices} choices per response area should be defined.`;\n }\n });\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,MAAMK,WAAW,GAAIC,OAAO,IAAK;EAC/B,IAAIA,OAAO,EAAE;IACX,OAAO,SAAS;EAClB;EAEA,OAAO,WAAW;AACpB,CAAC;AAEM,MAAMC,SAAS,GAAIC,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4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAllCorrectResponses = void 0;
|
|
7
|
+
var _lodashEs = require("lodash-es");
|
|
8
|
+
const getAllCorrectResponses = ({
|
|
9
|
+
choices,
|
|
10
|
+
alternateResponse
|
|
11
|
+
}) => {
|
|
12
|
+
alternateResponse = alternateResponse || {};
|
|
13
|
+
const correctAnswers = {};
|
|
14
|
+
(0, _lodashEs.forEach)(choices, (respArea, key) => {
|
|
15
|
+
if (!correctAnswers[key]) {
|
|
16
|
+
correctAnswers[key] = [];
|
|
17
|
+
}
|
|
18
|
+
if (respArea) {
|
|
19
|
+
respArea.forEach(choice => {
|
|
20
|
+
if (choice.correct) {
|
|
21
|
+
correctAnswers[key].push(choice.value);
|
|
22
|
+
if (alternateResponse[key]) {
|
|
23
|
+
correctAnswers[key] = [...correctAnswers[key], ...alternateResponse[key]];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return correctAnswers;
|
|
30
|
+
};
|
|
31
|
+
exports.getAllCorrectResponses = getAllCorrectResponses;
|
|
32
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_lodashEs","require","getAllCorrectResponses","choices","alternateResponse","correctAnswers","forEach","respArea","key","choice","correct","push","value","exports"],"sources":["../src/utils.js"],"sourcesContent":["import { forEach } from 'lodash-es';\n\nexport const getAllCorrectResponses = ({ choices, alternateResponse }) => {\n alternateResponse = alternateResponse || {};\n const correctAnswers = {};\n\n forEach(choices, (respArea, key) => {\n if (!correctAnswers[key]) {\n correctAnswers[key] = [];\n }\n\n if (respArea) {\n respArea.forEach((choice) => {\n if (choice.correct) {\n correctAnswers[key].push(choice.value);\n\n if (alternateResponse[key]) {\n correctAnswers[key] = [...correctAnswers[key], ...alternateResponse[key]];\n }\n }\n });\n }\n });\n\n return correctAnswers;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEO,MAAMC,sBAAsB,GAAGA,CAAC;EAAEC,OAAO;EAAEC;AAAkB,CAAC,KAAK;EACxEA,iBAAiB,GAAGA,iBAAiB,IAAI,CAAC,CAAC;EAC3C,MAAMC,cAAc,GAAG,CAAC,CAAC;EAEzB,IAAAC,iBAAO,EAACH,OAAO,EAAE,CAACI,QAAQ,EAAEC,GAAG,KAAK;IAClC,IAAI,CAACH,cAAc,CAACG,GAAG,CAAC,EAAE;MACxBH,cAAc,CAACG,GAAG,CAAC,GAAG,EAAE;IAC1B;IAEA,IAAID,QAAQ,EAAE;MACZA,QAAQ,CAACD,OAAO,CAAEG,MAAM,IAAK;QAC3B,IAAIA,MAAM,CAACC,OAAO,EAAE;UAClBL,cAAc,CAACG,GAAG,CAAC,CAACG,IAAI,CAACF,MAAM,CAACG,KAAK,CAAC;UAEtC,IAAIR,iBAAiB,CAACI,GAAG,CAAC,EAAE;YAC1BH,cAAc,CAACG,GAAG,CAAC,GAAG,CAAC,GAAGH,cAAc,CAACG,GAAG,CAAC,EAAE,GAAGJ,iBAAiB,CAACI,GAAG,CAAC,CAAC;UAC3E;QACF;MACF,CAAC,CAAC;IACJ;EACF,CAAC,CAAC;EAEF,OAAOH,cAAc;AACvB,CAAC;AAACQ,OAAA,CAAAX,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-element/inline-dropdown-controller",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "9.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
|
+
"type-of": "^2.0.1"
|
|
15
|
+
}
|
|
16
|
+
}
|