@pie-element/inline-dropdown 10.1.2-next.1 → 10.1.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.
- package/CHANGELOG.json +1082 -0
- package/CHANGELOG.md +2192 -0
- package/LICENSE.md +5 -0
- package/README.md +1 -0
- package/configure/CHANGELOG.json +647 -0
- package/configure/CHANGELOG.md +1949 -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 -86
- 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-CMvmRhfL.js +0 -9024
- package/dist/browser/Close-CMvmRhfL.js.map +0 -1
- package/dist/browser/author/index.js +0 -40578
- 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-CAsDMEWi.js +0 -133
- package/dist/browser/dist-CAsDMEWi.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
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { l as e, o as t, r as n, s as r } from "../dist-CAsDMEWi.js";
|
|
2
|
-
//#region ../../shared/controller-utils/dist/index.js
|
|
3
|
-
var i = Object.defineProperty, a = (e, t) => {
|
|
4
|
-
let n = {};
|
|
5
|
-
for (var r in e) i(n, r, {
|
|
6
|
-
get: e[r],
|
|
7
|
-
enumerable: !0
|
|
8
|
-
});
|
|
9
|
-
return t || i(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
10
|
-
};
|
|
11
|
-
function o(e) {
|
|
12
|
-
return Array.isArray(e) ? e.filter((e) => e != null) : [];
|
|
13
|
-
}
|
|
14
|
-
function s(e) {
|
|
15
|
-
let t = [...e];
|
|
16
|
-
for (let e = t.length - 1; e > 0; e--) {
|
|
17
|
-
let n = Math.floor(Math.random() * (e + 1));
|
|
18
|
-
[t[e], t[n]] = [t[n], t[e]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
}
|
|
22
|
-
function c(e) {
|
|
23
|
-
return e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == "object" ? Object.keys(e).length === 0 : !1;
|
|
24
|
-
}
|
|
25
|
-
async function l(e, t, n, r = "value") {
|
|
26
|
-
let i = o(t?.data?.shuffledValues ?? t?.shuffledValues ?? []);
|
|
27
|
-
if (!t) {
|
|
28
|
-
console.warn("Unable to save shuffled choices because there's no session.");
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (!c(i)) return o(i.map((t) => e.find((e) => e[r] === t)));
|
|
32
|
-
let a = s(e);
|
|
33
|
-
if (n && typeof n == "function") try {
|
|
34
|
-
let e = o(a.map((e) => e[r]));
|
|
35
|
-
c(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(a)}, key: ${r}`) : t.id && t.element && await n(t.id, t.element, { shuffledValues: e });
|
|
36
|
-
} catch (e) {
|
|
37
|
-
console.warn("Unable to save shuffled order for choices"), console.error(e);
|
|
38
|
-
}
|
|
39
|
-
else console.warn("Unable to save shuffled choices, shuffle will happen every time.");
|
|
40
|
-
return a;
|
|
41
|
-
}
|
|
42
|
-
function u(e, t, n) {
|
|
43
|
-
return !!(e.lockChoiceOrder || n["@pie-element"]?.lockChoiceOrder || (n.role ?? "student") === "instructor");
|
|
44
|
-
}
|
|
45
|
-
var d = /* @__PURE__ */ a({ enabled: () => f });
|
|
46
|
-
function f(e, t, n) {
|
|
47
|
-
return e?.partialScoring === !1 || t?.partialScoring === !1 ? !1 : typeof n == "boolean" ? n : !0;
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/controller/defaults.ts
|
|
51
|
-
var p = {
|
|
52
|
-
alternateResponse: {},
|
|
53
|
-
choiceRationaleEnabled: !0,
|
|
54
|
-
choices: {},
|
|
55
|
-
disabled: !1,
|
|
56
|
-
displayType: "block",
|
|
57
|
-
markup: "",
|
|
58
|
-
mode: "gather",
|
|
59
|
-
prompt: "",
|
|
60
|
-
promptEnabled: !0,
|
|
61
|
-
rationale: "",
|
|
62
|
-
rationaleEnabled: !0,
|
|
63
|
-
shuffle: !0,
|
|
64
|
-
studentInstructionsEnabled: !0,
|
|
65
|
-
teacherInstructions: "",
|
|
66
|
-
teacherInstructionsEnabled: !0,
|
|
67
|
-
toolbarEditorPosition: "bottom"
|
|
68
|
-
}, m = ({ choices: t, alternateResponse: n }) => {
|
|
69
|
-
n ||= {};
|
|
70
|
-
let r = {};
|
|
71
|
-
return e(t, (e, t) => {
|
|
72
|
-
r[t] || (r[t] = []), e && e.forEach((e) => {
|
|
73
|
-
e.correct && (r[t].push(e.value), n[t] && (r[t] = [...r[t], ...n[t]]));
|
|
74
|
-
});
|
|
75
|
-
}), r;
|
|
76
|
-
}, h = (e) => e ? "correct" : "incorrect", g = (e) => ({
|
|
77
|
-
...p,
|
|
78
|
-
...e
|
|
79
|
-
});
|
|
80
|
-
async function _(e, i, a, o) {
|
|
81
|
-
let s = g(e), { value: c = {} } = i || {}, d = n(s.choices, (e, t, n) => (e[n] = r(t, (e) => e), e), {}), f = {};
|
|
82
|
-
if (a.mode === "evaluate") {
|
|
83
|
-
let e = m(s), t = Object.keys(e).length, r = 0;
|
|
84
|
-
for (let i = 0; i < t; i++) {
|
|
85
|
-
let a = n(e, (e, t, n) => {
|
|
86
|
-
let r = c && c[n] || "", a = t[i] || "", o = r && a && a === r;
|
|
87
|
-
return e.feedback[n] = h(o), o && (e.correctResponses += 1), e;
|
|
88
|
-
}, {
|
|
89
|
-
correctResponses: 0,
|
|
90
|
-
feedback: {}
|
|
91
|
-
});
|
|
92
|
-
if (a.correctResponses >= r && (r = a.correctResponses, f = a.feedback), a.correctResponses === t) break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (!u(s, i, a)) {
|
|
96
|
-
let e = {}, n = Object.keys(d), r = (t) => (n, r, i) => new Promise((n) => {
|
|
97
|
-
e[t] = i.shuffledValues, n();
|
|
98
|
-
}), a;
|
|
99
|
-
for (a = 0; a < n.length; a++) {
|
|
100
|
-
let e = n[a], t = i?.shuffledValues?.[e];
|
|
101
|
-
d[e] = await l(d[e], { shuffledValues: Array.isArray(t) ? t : [] }, r(e), "value");
|
|
102
|
-
}
|
|
103
|
-
t(e) || i && o && typeof o == "function" && o(i.id, i.element, { shuffledValues: e }).catch((e) => {
|
|
104
|
-
console.error("update session failed", e);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
let p = null, _ = null, y = (Object.keys(d) || []).reduce((e, t) => (e[t] = (d[t] || []).map((e) => ({
|
|
108
|
-
...e,
|
|
109
|
-
rationale: null
|
|
110
|
-
})), e), {});
|
|
111
|
-
return a.role === "instructor" && (a.mode === "view" || a.mode === "evaluate") ? (_ = s.rationaleEnabled ? s.rationale : null, p = s.teacherInstructionsEnabled ? s.teacherInstructions : null, d = s.choiceRationaleEnabled ? s.choices : y) : (_ = null, p = null, d = y), {
|
|
112
|
-
disabled: a.mode !== "gather",
|
|
113
|
-
mode: a.mode,
|
|
114
|
-
prompt: s.promptEnabled ? s.prompt : null,
|
|
115
|
-
displayType: s.displayType,
|
|
116
|
-
markup: s.markup,
|
|
117
|
-
choices: d,
|
|
118
|
-
feedback: f,
|
|
119
|
-
responseCorrect: a.mode === "evaluate" ? v(s, i) === 1 : void 0,
|
|
120
|
-
rationale: _,
|
|
121
|
-
teacherInstructions: p,
|
|
122
|
-
language: s.language,
|
|
123
|
-
extraCSSRules: s.extraCSSRules
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
var v = (e, t) => {
|
|
127
|
-
let { value: r = {} } = t || {}, i = e && e.choices ? Object.keys(e.choices).length : 0, a = m(e), o = 0;
|
|
128
|
-
for (let e = 0; e < i; e++) {
|
|
129
|
-
let t = n(a, (t, n, i) => {
|
|
130
|
-
let a = r && r[i] || "", o = n[e] || "";
|
|
131
|
-
return o && a && o === a ? t : t - 1;
|
|
132
|
-
}, i);
|
|
133
|
-
if (t > o && (o = t), t === i) break;
|
|
134
|
-
}
|
|
135
|
-
let s = (o / i).toFixed(2);
|
|
136
|
-
return parseFloat(s);
|
|
137
|
-
}, y = (e, t, n) => {
|
|
138
|
-
let r = [], { value: i = {} } = t || {}, a = m(e), o = Object.keys(a), s = o.length;
|
|
139
|
-
if (r.push(`${s} dropdown response area(s) defined in this question.`), i && Object.keys(i).length > 0) {
|
|
140
|
-
let e = Object.entries(i).filter(([e, t]) => t && t.trim()).length;
|
|
141
|
-
r.push(`Student selected options in ${e} out of ${s} dropdown(s).`), o.forEach((e) => {
|
|
142
|
-
let t = i && i[e] || "", n = a[e] || [];
|
|
143
|
-
t.trim() ? r.push(`Dropdown ${parseInt(e) + 1}: student selected '${t}' (correct options: [${n.map((e) => `'${e}'`).join(", ")}]).`) : r.push(`Dropdown ${parseInt(e) + 1}: no selection made (correct options: [${n.map((e) => `'${e}'`).join(", ")}]).`);
|
|
144
|
-
});
|
|
145
|
-
} else r.push("Student did not make any selections in the dropdowns.");
|
|
146
|
-
let c = d.enabled(e, n);
|
|
147
|
-
r.push(`Scoring method: ${c ? "partial scoring" : "all-or-nothing scoring"}.`);
|
|
148
|
-
let l = v(e, t);
|
|
149
|
-
return r.push(`Final score: ${l}.`), r;
|
|
150
|
-
};
|
|
151
|
-
function b(e, n, r = {}) {
|
|
152
|
-
return new Promise((i) => {
|
|
153
|
-
if (!n || t(n)) i({
|
|
154
|
-
score: 0,
|
|
155
|
-
empty: !0,
|
|
156
|
-
traceLog: ["Student did not make any selections in the dropdowns. Score is 0."]
|
|
157
|
-
});
|
|
158
|
-
else {
|
|
159
|
-
let t = y(e, n, r), a = v(e, n);
|
|
160
|
-
i({
|
|
161
|
-
score: d.enabled(e, r) ? a : Math.floor(a),
|
|
162
|
-
empty: !1,
|
|
163
|
-
traceLog: t
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
var x = (e, t) => new Promise((n) => {
|
|
169
|
-
if (t.mode !== "evaluate" && t.role === "instructor") {
|
|
170
|
-
let { choices: t } = e, r = {};
|
|
171
|
-
t && Object.keys(t).forEach((e, n) => {
|
|
172
|
-
let i = t[e] && t[e].filter((e) => e.correct);
|
|
173
|
-
r[n] = i && i[0].value;
|
|
174
|
-
}), n({
|
|
175
|
-
id: "1",
|
|
176
|
-
value: r
|
|
177
|
-
});
|
|
178
|
-
} else n(null);
|
|
179
|
-
}), S = (e) => (e || "").replace(/(<(?!img|iframe|source)([^>]+)>)/gi, ""), C = (e = {}, t = {}) => {
|
|
180
|
-
let { markup: n, choices: r } = e, { maxResponseAreas: i, maxResponseAreaChoices: a } = t, o = {};
|
|
181
|
-
[
|
|
182
|
-
"teacherInstructions",
|
|
183
|
-
"prompt",
|
|
184
|
-
"rationale"
|
|
185
|
-
].forEach((n) => {
|
|
186
|
-
t[n]?.required && !S(e[n]) && (o[n] = "This field is required.");
|
|
187
|
-
});
|
|
188
|
-
let s = ((n || "").match(/\{\{(\d+)\}\}/g) || []).length;
|
|
189
|
-
return s > i ? o.responseAreasError = `No more than ${i} response areas should be defined.` : s < 1 && (o.responseAreasError = "There should be defined at least 1 response area."), (Object.keys(r) || []).forEach((e) => {
|
|
190
|
-
r[e] && r[e].length > a && (o.responseAreaChoicesError = `No more than ${a} choices per response area should be defined.`);
|
|
191
|
-
}), o;
|
|
192
|
-
};
|
|
193
|
-
//#endregion
|
|
194
|
-
export { x as createCorrectResponseSession, y as getLogTrace, v as getScore, _ as model, g as normalize, b as outcome, C as validate };
|
|
195
|
-
|
|
196
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../shared/controller-utils/dist/index.js","../../../src/controller/defaults.ts","../../../src/controller/utils.ts","../../../src/controller/index.ts"],"sourcesContent":["//#region \\0rolldown/runtime.js\nvar e = Object.defineProperty, t = (t, n) => {\n\tlet r = {};\n\tfor (var i in t) e(r, i, {\n\t\tget: t[i],\n\t\tenumerable: !0\n\t});\n\treturn n || e(r, Symbol.toStringTag, { value: \"Module\" }), r;\n};\n//#endregion\n//#region src/persistence.ts\nfunction n(e) {\n\treturn Array.isArray(e) ? e.filter((e) => e != null) : [];\n}\nfunction r(e) {\n\tlet t = [...e];\n\tfor (let e = t.length - 1; e > 0; e--) {\n\t\tlet n = Math.floor(Math.random() * (e + 1));\n\t\t[t[e], t[n]] = [t[n], t[e]];\n\t}\n\treturn t;\n}\nfunction i(e) {\n\treturn e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == \"object\" ? Object.keys(e).length === 0 : !1;\n}\nasync function a(e, t, a, o = \"value\") {\n\tlet s = n(t?.data?.shuffledValues ?? t?.shuffledValues ?? []);\n\tif (!t) {\n\t\tconsole.warn(\"Unable to save shuffled choices because there's no session.\");\n\t\treturn;\n\t}\n\tif (!i(s)) return n(s.map((t) => e.find((e) => e[o] === t)));\n\tlet c = r(e);\n\tif (a && typeof a == \"function\") try {\n\t\tlet e = n(c.map((e) => e[o]));\n\t\ti(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(c)}, key: ${o}`) : t.id && t.element && await a(t.id, t.element, { shuffledValues: e });\n\t} catch (e) {\n\t\tconsole.warn(\"Unable to save shuffled order for choices\"), console.error(e);\n\t}\n\telse console.warn(\"Unable to save shuffled choices, shuffle will happen every time.\");\n\treturn c;\n}\nfunction o(e, t, n) {\n\treturn !!(e.lockChoiceOrder || n[\"@pie-element\"]?.lockChoiceOrder || (n.role ?? \"student\") === \"instructor\");\n}\n//#endregion\n//#region src/partial-scoring.ts\nvar s = /* @__PURE__ */ t({ enabled: () => c });\nfunction c(e, t, n) {\n\treturn e?.partialScoring === !1 || t?.partialScoring === !1 ? !1 : typeof n == \"boolean\" ? n : !0;\n}\n//#endregion\nexport { a as getShuffledChoices, o as lockChoices, s as partialScoring };\n","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/inline-dropdown/controller/src/defaults.js\n * @auto-generated\n *\n * This file is automatically synced from pie-elements and converted to TypeScript.\n * Manual edits will be overwritten on next sync.\n * To make changes, edit the upstream JavaScript file and run sync again.\n */\n\nexport 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","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/inline-dropdown/controller/src/utils.js\n * @auto-generated\n *\n * This file is automatically synced from pie-elements and converted to TypeScript.\n * Manual edits will be overwritten on next sync.\n * To make changes, edit the upstream JavaScript file and run sync again.\n */\n\nimport { forEach } from '@pie-element/shared-lodash';\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","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/inline-dropdown/controller/src/index.js\n * @auto-generated\n *\n * This file is automatically synced from pie-elements and converted to TypeScript.\n * Manual edits will be overwritten on next sync.\n * To make changes, edit the upstream JavaScript file and run sync again.\n */\n\nimport { isEmpty, map, reduce } from '@pie-element/shared-lodash';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-element/shared-controller-utils';\nimport defaults from './defaults.js';\n\nimport { getAllCorrectResponses } from './utils.js';\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":";;AACA,IAAI,IAAI,OAAO,gBAAgB,KAAK,GAAG,MAAM;CAC5C,IAAI,IAAI,CAAC;CACT,KAAK,IAAI,KAAK,GAAG,EAAE,GAAG,GAAG;EACxB,KAAK,EAAE;EACP,YAAY,CAAC;CACd,CAAC;CACD,OAAO,KAAK,EAAE,GAAG,OAAO,aAAa,EAAE,OAAO,SAAS,CAAC,GAAG;AAC5D;AAGA,SAAS,EAAE,GAAG;CACb,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,QAAQ,MAAM,KAAK,IAAI,IAAI,CAAC;AACzD;AACA,SAAS,EAAE,GAAG;CACb,IAAI,IAAI,CAAC,GAAG,CAAC;CACb,KAAK,IAAI,IAAI,EAAE,SAAS,GAAG,IAAI,GAAG,KAAK;EACtC,IAAI,IAAI,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,EAAE;EAC1C,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE;CAC3B;CACA,OAAO;AACR;AACA,SAAS,EAAE,GAAG;CACb,OAAO,KAAK,OAAO,CAAC,IAAI,MAAM,QAAQ,CAAC,IAAI,EAAE,WAAW,IAAI,OAAO,KAAK,WAAW,OAAO,KAAK,CAAC,EAAE,WAAW,IAAI,CAAC;AACnH;AACA,eAAe,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS;CACtC,IAAI,IAAI,EAAE,GAAG,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,CAAC;CAC5D,IAAI,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