@pie-element/multiple-choice 14.0.4-next.20261011174919 → 14.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -77,13 +77,13 @@ function p(e, t, n) {
77
77
  //#endregion
78
78
  //#region src/controller/index.ts
79
79
  var m = (e, t, n) => (r) => {
80
- let { role: i, mode: a } = t || {}, o = {
80
+ let i = t?.role, a = t?.mode, o = {
81
81
  label: r.label,
82
82
  value: r.value
83
83
  };
84
84
  if (i === "instructor" && (a === "view" || a === "evaluate") ? o.rationale = e.rationaleEnabled ? r.rationale : null : o.rationale = null, a === "evaluate" && (o.correct = !!r.correct, e.feedbackEnabled)) {
85
85
  let e = r.feedback && r.feedback.type || "none";
86
- e === "default" ? o.feedback = n[r.correct ? "correct" : "incorrect"] : e === "custom" && (o.feedback = r.feedback.value);
86
+ e === "default" ? o.feedback = n[r.correct ? "correct" : "incorrect"] : e === "custom" && (o.feedback = r.feedback?.value);
87
87
  }
88
88
  return o;
89
89
  };
@@ -107,7 +107,8 @@ async function _(e, t, n, i) {
107
107
  incorrect: "Incorrect"
108
108
  }, a.defaultFeedback), s = (a.choices || []).map(m(a, n, o));
109
109
  d(a, t, n) || (s = await u(s, t, i, "value"));
110
- let c = {
110
+ let { role: c, mode: l } = n;
111
+ return {
111
112
  disabled: n.mode !== "gather",
112
113
  mode: n.mode,
113
114
  prompt: a.promptEnabled ? a.prompt : null,
@@ -132,13 +133,13 @@ async function _(e, t, n, i) {
132
133
  keyboardEventsEnabled: a.keyboardEventsEnabled,
133
134
  autoplayAudioEnabled: a.autoplayAudioEnabled,
134
135
  completeAudioEnabled: a.completeAudioEnabled,
135
- customAudioButton: a.customAudioButton
136
- }, { role: l, mode: f } = n || {};
137
- return l === "instructor" && (f === "view" || f === "evaluate") ? c.teacherInstructions = a.teacherInstructionsEnabled ? a.teacherInstructions : null : c.teacherInstructions = null, c;
136
+ customAudioButton: a.customAudioButton,
137
+ teacherInstructions: c === "instructor" && (l === "view" || l === "evaluate") && a.teacherInstructionsEnabled ? a.teacherInstructions : null
138
+ };
138
139
  }
139
140
  var v = (e, n) => {
140
141
  if (!n || t(n)) return 0;
141
- let r = n.value || [], i = (e.choices || []).filter((e) => e.correct), a = r.reduce((e, t) => e + +!!i.find((e) => e.value === t), 0);
142
+ let r = n?.value || [], i = (e.choices || []).filter((e) => e.correct), a = r.reduce((e, t) => e + +!!i.find((e) => e.value === t), 0);
142
143
  i.length < r.length && (a -= r.length - i.length, a < 0 && (a = 0));
143
144
  let o = i.length ? a / i.length : 0;
144
145
  return parseFloat(o.toFixed(2));
@@ -191,7 +192,7 @@ var x = (e, t) => new Promise((n) => {
191
192
  r && (u = !0, d++), S(a) ? o.slice(t + 1).some((e) => e.label === a) && (s[i] = "Content should be unique.") : s[i] = "Content should not be empty.", n.rationale?.required && !S(l) && (c[i] = "This field is required.");
192
193
  });
193
194
  let f = (r || []).length;
194
- if (f < i ? l.answerChoices = `There should be at least ${i} choices defined.` : f > a && (l.answerChoices = `No more than ${a} choices should be defined.`), !u) l.correctResponse = "No correct response defined.";
195
+ if (f < i ? l.answerChoices = `There should be at least ${i} choices defined.` : a !== void 0 && f > a && (l.answerChoices = `No more than ${a} choices should be defined.`), !u) l.correctResponse = "No correct response defined.";
195
196
  else {
196
197
  let { maxSelections: t, choiceMode: n } = e;
197
198
  n !== "radio" && t != null && d > t && (l.correctResponse = `The number of correct answers (${d}) exceeds max selections (${t}). Students won't be able to select all correct answers.`);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/controller/utils.ts","../../../../src/controller/defaults.ts","../../../../../../shared/controller-utils/dist/index.js","../../../../src/controller/index.ts"],"sourcesContent":["// @ts-nocheck\n\nimport { isEqual } from '@pie-element/shared-lodash';\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","// @ts-nocheck\n\nexport 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","//#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;\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}`) : 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}\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;\n}\n//#endregion\nexport { a as getShuffledChoices, o as lockChoices, s as partialScoring };\n","// @ts-nocheck\n\n/* eslint-disable no-console */\nimport { isEmpty } from '@pie-element/shared-lodash';\nimport { isResponseCorrect } from './utils.js';\nimport defaults from './defaults.js';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-element/shared-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":";;AAIA,IAAa,KAAsB,MACjC,EACG,QAAQ,MAAM,EAAE,OAAO,CAAC,CACxB,KAAK,MAAM,EAAE,KAAK,CAAC,CACnB,KAAK,GAEG,KAAqB,GAAU,MAAY;CACtD,IAAI,IAAkB,EAAmB,EAAS,OAAO;CACzD,OAAO,KAAW,GAAS,EAAQ,SAAS,CAAC,EAAA,CAAG,KAAK,GAAG,CAAe;AACzE,GCXA,IAAe;CACb,YAAY;CACZ,cAAc;CACd,SAAS,CAAC;CACV,eAAe;CACf,iBAAiB;CACjB,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M,EAAE,eAAY,GACd,EAAE,sBAAmB,GAAG,wBAAqB,GAC7C,IAAkB,CAAC,GAAI,KAAW,CAAC,CAAE,CAAC,CAAC,QAAQ,GAC/C,IAAgB,CAAC,GACjB,IAAkB,CAAC,GACnB,IAAS,CAAC;CAEhB,CAAC,uBAAuB,QAAQ,CAAC,CAAC,SAAS,MAAU;EACnD,AAAI,EAAO,EAAM,EAAE,YAAY,CAAC,EAAW,EAAM,EAAM,MACrD,EAAO,KAAS;CAEpB,CAAC;CAED,IAAI,IAAqB,IACrB,IAAe;CAEnB,EAAgB,SAAS,GAAQ,MAAU;EACzC,IAAM,EAAE,YAAS,UAAO,UAAO,iBAAc;EAiB7C,AAfI,MACF,IAAqB,IACrB,MAGG,EAAW,CAAK,IAGK,EAAgB,MAAM,IAAQ,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,UAAU,CAE7E,MACF,EAAc,KAAS,+BALzB,EAAc,KAAS,gCASrB,EAAO,WAAW,YAAY,CAAC,EAAW,CAAS,MACrD,EAAgB,KAAS;CAE7B,CAAC;CAED,IAAM,KAAe,KAAW,CAAC,EAAA,CAAG;CAQpC,IANI,IAAc,IAChB,EAAO,gBAAgB,4BAA4B,EAAiB,qBAC3D,IAAc,MACvB,EAAO,gBAAgB,gBAAgB,EAAiB,+BAGtD,CAAC,GACH,EAAO,kBAAkB;MACpB;EACL,IAAM,EAAE,kBAAe,kBAAe;EAEtC,AAAI,MAAe,WAAW,KAAiB,QAAQ,IAAe,MACpE,EAAO,kBAAkB,kCAAkC,EAAa,4BAA4B,EAAc;CAEtH;CAUA,OARK,EAAQ,CAAa,MACxB,EAAO,UAAU,IAGd,EAAQ,CAAe,MAC1B,EAAO,YAAY,IAGd;AACT"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/controller/utils.ts","../../../../src/controller/defaults.ts","../../../../../../shared/controller-utils/dist/index.js","../../../../src/controller/index.ts"],"sourcesContent":["import { isEqual } from '@pie-element/shared-lodash';\nimport type { Choice, MultipleChoiceModel, MultipleChoiceSession } from '../types.js';\n\nexport const getCorrectResponse = (choices: Choice[]) =>\n choices\n .filter((c) => c.correct)\n .map((c) => c.value)\n .sort();\n\nexport const isResponseCorrect = (question: MultipleChoiceModel, session: MultipleChoiceSession | undefined) => {\n let correctResponse = getCorrectResponse(question.choices);\n return session && isEqual((session.value || []).sort(), correctResponse);\n};\n","import type { MultipleChoiceModel } from '../types.js';\n\nexport 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} satisfies Omit<MultipleChoiceModel, 'id' | 'element'>;\n","//#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;\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}`) : 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}\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;\n}\n//#endregion\nexport { a as getShuffledChoices, o as lockChoices, s as partialScoring };\n","/* eslint-disable no-console */\nimport { isEmpty } from '@pie-element/shared-lodash';\nimport type { PieEnvironment, PieUpdateSession } from '@pie-element/shared-types';\nimport { isResponseCorrect } from './utils.js';\nimport defaults from './defaults.js';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-element/shared-controller-utils';\nimport type {\n Choice,\n MultipleChoiceConfiguration,\n MultipleChoiceModel,\n MultipleChoiceSession,\n} from '../types.js';\n\ntype DefaultFeedback = { correct: string; incorrect: string };\n\n/** A choice as the delivery view receives it. */\ntype ChoiceView = {\n label: string;\n value: string;\n rationale?: string | null;\n correct?: boolean;\n feedback?: string;\n};\n\n/** Errors `validate()` reports, keyed by field; `choices` and `rationale` are keyed by choice value. */\nexport type MultipleChoiceValidationErrors = {\n teacherInstructions?: string;\n prompt?: string;\n answerChoices?: string;\n correctResponse?: string;\n choices?: Record<string, string>;\n rationale?: Record<string, string>;\n};\n\nconst prepareChoice =\n (model: MultipleChoiceModel, env: PieEnvironment | undefined, defaultFeedback: DefaultFeedback) =>\n (choice: Choice): ChoiceView => {\n const role = env?.role;\n const mode = env?.mode;\n const out: ChoiceView = {\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: Partial<MultipleChoiceModel> = {}) {\n return new Promise<Partial<MultipleChoiceModel>>((resolve) => resolve({ ...defaults, ...model }));\n}\n\nexport const normalize = (question: MultipleChoiceModel) => {\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(\n question: MultipleChoiceModel,\n session: MultipleChoiceSession | undefined,\n env: PieEnvironment,\n updateSession?: PieUpdateSession,\n) {\n const normalizedQuestion = normalize(question);\n\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n normalizedQuestion.defaultFeedback,\n );\n\n let choices: ChoiceView[] | undefined = (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 { role, mode } = env;\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 teacherInstructions:\n role === 'instructor' && (mode === 'view' || mode === 'evaluate') && normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null,\n };\n\n return out;\n}\n\nexport const getScore = (config: MultipleChoiceModel, session: MultipleChoiceSession | undefined) => {\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 = (\n model: MultipleChoiceModel,\n session: MultipleChoiceSession | undefined,\n env: PieEnvironment,\n) => {\n const traceLog: string[] = [];\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: MultipleChoiceModel, session: MultipleChoiceSession | undefined, env: PieEnvironment) {\n return new Promise<{ score: number; empty: boolean; traceLog: string[] }>((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: MultipleChoiceModel, env: PieEnvironment) => {\n return new Promise<MultipleChoiceSession | null>((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 except img, iframe and source tag for audio\nconst getContent = (html: string | undefined) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (\n model: Partial<MultipleChoiceModel> = {},\n config: MultipleChoiceConfiguration = {},\n): MultipleChoiceValidationErrors => {\n const { choices } = model;\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n const reversedChoices = [...(choices || [])].reverse();\n const choicesErrors: Record<string, string> = {};\n const rationaleErrors: Record<string, string> = {};\n const errors: MultipleChoiceValidationErrors = {};\n\n (['teacherInstructions', 'prompt'] as const).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 (maxAnswerChoices !== undefined && 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":";;AAGA,IAAa,KAAsB,MACjC,EACG,QAAQ,MAAM,EAAE,OAAO,CAAC,CACxB,KAAK,MAAM,EAAE,KAAK,CAAC,CACnB,KAAK,GAEG,KAAqB,GAA+B,MAA+C;CAC9G,IAAI,IAAkB,EAAmB,EAAS,OAAO;CACzD,OAAO,KAAW,GAAS,EAAQ,SAAS,CAAC,EAAA,CAAG,KAAK,GAAG,CAAe;AACzE,GCVA,IAAe;CACb,YAAY;CACZ,cAAc;CACd,SAAS,CAAC;CACV,eAAe;CACf,iBAAiB;CACjB,aAAa;CACb,iBAAiB;CACjB,gBAAgB;CAChB,QAAQ;CACR,eAAe;CACf,WAAW;CACX,kBAAkB;CAClB,aAAa;CACb,4BAA4B;CAC5B,qBAAqB;CACrB,4BAA4B;CAC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QAAQ,CAAC,CAAW,SAAS,MAAU;EAC9D,AAAI,EAAO,EAAM,EAAE,YAAY,CAAC,EAAW,EAAM,EAAM,MACrD,EAAO,KAAS;CAEpB,CAAC;CAED,IAAI,IAAqB,IACrB,IAAe;CAEnB,EAAgB,SAAS,GAAQ,MAAU;EACzC,IAAM,EAAE,YAAS,UAAO,UAAO,iBAAc;EAiB7C,AAfI,MACF,IAAqB,IACrB,MAGG,EAAW,CAAK,IAGK,EAAgB,MAAM,IAAQ,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,UAAU,CAE7E,MACF,EAAc,KAAS,+BALzB,EAAc,KAAS,gCASrB,EAAO,WAAW,YAAY,CAAC,EAAW,CAAS,MACrD,EAAgB,KAAS;CAE7B,CAAC;CAED,IAAM,KAAe,KAAW,CAAC,EAAA,CAAG;CAQpC,IANI,IAAc,IAChB,EAAO,gBAAgB,4BAA4B,EAAiB,qBAC3D,MAAqB,KAAA,KAAa,IAAc,MACzD,EAAO,gBAAgB,gBAAgB,EAAiB,+BAGtD,CAAC,GACH,EAAO,kBAAkB;MACpB;EACL,IAAM,EAAE,kBAAe,kBAAe;EAEtC,AAAI,MAAe,WAAW,KAAiB,QAAQ,IAAe,MACpE,EAAO,kBAAkB,kCAAkC,EAAa,4BAA4B,EAAc;CAEtH;CAUA,OARK,EAAQ,CAAa,MACxB,EAAO,UAAU,IAGd,EAAQ,CAAe,MAC1B,EAAO,YAAY,IAGd;AACT"}
@@ -1,27 +1,27 @@
1
1
  declare const _default: {
2
- choiceMode: string;
3
- choicePrefix: string;
2
+ choiceMode: "checkbox";
3
+ choicePrefix: "letters";
4
4
  choices: never[];
5
- choicesLayout: string;
6
- feedbackEnabled: boolean;
5
+ choicesLayout: "vertical";
6
+ feedbackEnabled: false;
7
7
  gridColumns: number;
8
- lockChoiceOrder: boolean;
9
- partialScoring: boolean;
8
+ lockChoiceOrder: true;
9
+ partialScoring: true;
10
10
  prompt: string;
11
- promptEnabled: boolean;
11
+ promptEnabled: true;
12
12
  rationale: string;
13
- rationaleEnabled: boolean;
14
- scoringType: string;
15
- studentInstructionsEnabled: boolean;
13
+ rationaleEnabled: true;
14
+ scoringType: "auto";
15
+ studentInstructionsEnabled: true;
16
16
  teacherInstructions: string;
17
- teacherInstructionsEnabled: boolean;
18
- toolbarEditorPosition: string;
17
+ teacherInstructionsEnabled: true;
18
+ toolbarEditorPosition: "bottom";
19
19
  selectedAnswerBackgroundColor: string;
20
20
  selectedAnswerStrokeColor: string;
21
21
  selectedAnswerStrokeWidth: string;
22
22
  hoverAnswerBackgroundColor: string;
23
23
  hoverAnswerStrokeColor: string;
24
24
  hoverAnswerStrokeWidth: string;
25
- keyboardEventsEnabled: boolean;
25
+ keyboardEventsEnabled: false;
26
26
  };
27
27
  export default _default;
@@ -1,5 +1,70 @@
1
- export declare function createDefaultModel(model?: {}): Promise<unknown>;
2
- export declare const normalize: (question: any) => any;
1
+ import type { PieEnvironment, PieUpdateSession } from '@pie-element/shared-types';
2
+ import type { Choice, MultipleChoiceConfiguration, MultipleChoiceModel, MultipleChoiceSession } from '../types.js';
3
+ /** A choice as the delivery view receives it. */
4
+ type ChoiceView = {
5
+ label: string;
6
+ value: string;
7
+ rationale?: string | null;
8
+ correct?: boolean;
9
+ feedback?: string;
10
+ };
11
+ /** Errors `validate()` reports, keyed by field; `choices` and `rationale` are keyed by choice value. */
12
+ export type MultipleChoiceValidationErrors = {
13
+ teacherInstructions?: string;
14
+ prompt?: string;
15
+ answerChoices?: string;
16
+ correctResponse?: string;
17
+ choices?: Record<string, string>;
18
+ rationale?: Record<string, string>;
19
+ };
20
+ export declare function createDefaultModel(model?: Partial<MultipleChoiceModel>): Promise<Partial<MultipleChoiceModel>>;
21
+ export declare const normalize: (question: MultipleChoiceModel) => {
22
+ choicesLayout: "grid" | "horizontal" | "vertical";
23
+ choiceMode: "checkbox" | "radio";
24
+ choicePrefix: "letters" | "numbers" | "none";
25
+ choices: Choice[];
26
+ prompt: string;
27
+ promptEnabled: boolean;
28
+ gridColumns: number;
29
+ toolbarEditorPosition: "bottom" | "top";
30
+ selectedAnswerBackgroundColor: string;
31
+ selectedAnswerStrokeColor: string;
32
+ selectedAnswerStrokeWidth: string;
33
+ hoverAnswerBackgroundColor: string;
34
+ hoverAnswerStrokeColor: string;
35
+ hoverAnswerStrokeWidth: string;
36
+ lockChoiceOrder: boolean;
37
+ minSelections?: number;
38
+ maxSelections?: number;
39
+ partialScoring: boolean;
40
+ scoringType: "auto" | "rubric";
41
+ studentInstructions?: string;
42
+ teacherInstructions: string;
43
+ feedbackEnabled: boolean;
44
+ defaultFeedback?: {
45
+ correct?: string;
46
+ incorrect?: string;
47
+ };
48
+ rationaleEnabled: boolean;
49
+ rationale: string;
50
+ spellCheckEnabled?: boolean;
51
+ studentInstructionsEnabled: boolean;
52
+ teacherInstructionsEnabled: boolean;
53
+ accessibilityLabelsEnabled?: boolean;
54
+ rubricEnabled?: boolean;
55
+ language?: string;
56
+ isSelectionButtonBelow?: boolean;
57
+ fontSizeFactor?: number;
58
+ autoplayAudioEnabled?: boolean;
59
+ completeAudioEnabled?: boolean;
60
+ customAudioButton?: import("@pie-element/shared-types").CustomAudioButton;
61
+ keyboardEventsEnabled: boolean;
62
+ extraCSSRules?: import("@pie-element/shared-types").ExtraCSSRules;
63
+ limitChoicesNumber?: boolean;
64
+ id: string;
65
+ element: string;
66
+ accessibilityCatalogs?: import("@pie-element/shared-types").AccessibilityCatalog[];
67
+ };
3
68
  /**
4
69
  *
5
70
  * @param {*} question
@@ -7,34 +72,35 @@ export declare const normalize: (question: any) => any;
7
72
  * @param {*} env
8
73
  * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
9
74
  */
10
- export declare function model(question: any, session: any, env: any, updateSession: any): Promise<{
75
+ export declare function model(question: MultipleChoiceModel, session: MultipleChoiceSession | undefined, env: PieEnvironment, updateSession?: PieUpdateSession): Promise<{
11
76
  disabled: boolean;
12
- mode: any;
13
- prompt: any;
14
- choicesLayout: any;
15
- gridColumns: any;
16
- choiceMode: any;
17
- keyMode: any;
18
- choices: any;
19
- responseCorrect: any;
20
- language: any;
21
- extraCSSRules: any;
22
- fontSizeFactor: any;
23
- isSelectionButtonBelow: any;
24
- selectedAnswerBackgroundColor: any;
25
- selectedAnswerStrokeColor: any;
26
- selectedAnswerStrokeWidth: any;
27
- hoverAnswerBackgroundColor: any;
28
- hoverAnswerStrokeColor: any;
29
- hoverAnswerStrokeWidth: any;
30
- minSelections: any;
31
- maxSelections: any;
32
- keyboardEventsEnabled: any;
33
- autoplayAudioEnabled: any;
34
- completeAudioEnabled: any;
35
- customAudioButton: any;
77
+ mode: "gather" | "view" | "evaluate";
78
+ prompt: string | null;
79
+ choicesLayout: "grid" | "horizontal" | "vertical";
80
+ gridColumns: number;
81
+ choiceMode: "checkbox" | "radio";
82
+ keyMode: "none" | "letters" | "numbers";
83
+ choices: ChoiceView[] | undefined;
84
+ responseCorrect: boolean | undefined;
85
+ language: string | undefined;
86
+ extraCSSRules: import("@pie-element/shared-types").ExtraCSSRules | undefined;
87
+ fontSizeFactor: number | undefined;
88
+ isSelectionButtonBelow: boolean | undefined;
89
+ selectedAnswerBackgroundColor: string;
90
+ selectedAnswerStrokeColor: string;
91
+ selectedAnswerStrokeWidth: string;
92
+ hoverAnswerBackgroundColor: string;
93
+ hoverAnswerStrokeColor: string;
94
+ hoverAnswerStrokeWidth: string;
95
+ minSelections: number | undefined;
96
+ maxSelections: number | undefined;
97
+ keyboardEventsEnabled: boolean;
98
+ autoplayAudioEnabled: boolean | undefined;
99
+ completeAudioEnabled: boolean | undefined;
100
+ customAudioButton: import("@pie-element/shared-types").CustomAudioButton | undefined;
101
+ teacherInstructions: string | null;
36
102
  }>;
37
- export declare const getScore: (config: any, session: any) => number;
103
+ export declare const getScore: (config: MultipleChoiceModel, session: MultipleChoiceSession | undefined) => number;
38
104
  /**
39
105
  * Generates detailed trace log for scoring evaluation
40
106
  * @param {Object} model - the question model
@@ -42,7 +108,7 @@ export declare const getScore: (config: any, session: any) => number;
42
108
  * @param {Object} env - the environment
43
109
  * @returns {Array} traceLog - array of trace messages
44
110
  */
45
- export declare const getLogTrace: (model: any, session: any, env: any) => string[];
111
+ export declare const getLogTrace: (model: MultipleChoiceModel, session: MultipleChoiceSession | undefined, env: PieEnvironment) => string[];
46
112
  /**
47
113
  *
48
114
  * The score is partial by default for checkbox mode, allOrNothing for radio mode.
@@ -52,6 +118,11 @@ export declare const getLogTrace: (model: any, session: any, env: any) => string
52
118
  * @param {*} session
53
119
  * @param {Object} env
54
120
  */
55
- export declare function outcome(model: any, session: any, env: any): Promise<unknown>;
56
- export declare const createCorrectResponseSession: (question: any, env: any) => Promise<unknown>;
57
- export declare const validate: (model?: {}, config?: {}) => {};
121
+ export declare function outcome(model: MultipleChoiceModel, session: MultipleChoiceSession | undefined, env: PieEnvironment): Promise<{
122
+ score: number;
123
+ empty: boolean;
124
+ traceLog: string[];
125
+ }>;
126
+ export declare const createCorrectResponseSession: (question: MultipleChoiceModel, env: PieEnvironment) => Promise<MultipleChoiceSession | null>;
127
+ export declare const validate: (model?: Partial<MultipleChoiceModel>, config?: MultipleChoiceConfiguration) => MultipleChoiceValidationErrors;
128
+ export {};
@@ -4,13 +4,13 @@ import { isEmpty as n } from "@pie-element/shared-lodash";
4
4
  import { getShuffledChoices as r, lockChoices as i, partialScoring as a } from "@pie-element/shared-controller-utils";
5
5
  //#region src/controller/index.ts
6
6
  var o = (e, t, n) => (r) => {
7
- let { role: i, mode: a } = t || {}, o = {
7
+ let i = t?.role, a = t?.mode, o = {
8
8
  label: r.label,
9
9
  value: r.value
10
10
  };
11
11
  if (i === "instructor" && (a === "view" || a === "evaluate") ? o.rationale = e.rationaleEnabled ? r.rationale : null : o.rationale = null, a === "evaluate" && (o.correct = !!r.correct, e.feedbackEnabled)) {
12
12
  let e = r.feedback && r.feedback.type || "none";
13
- e === "default" ? o.feedback = n[r.correct ? "correct" : "incorrect"] : e === "custom" && (o.feedback = r.feedback.value);
13
+ e === "default" ? o.feedback = n[r.correct ? "correct" : "incorrect"] : e === "custom" && (o.feedback = r.feedback?.value);
14
14
  }
15
15
  return o;
16
16
  };
@@ -34,7 +34,8 @@ async function l(t, n, a, s) {
34
34
  incorrect: "Incorrect"
35
35
  }, l.defaultFeedback), d = (l.choices || []).map(o(l, a, u));
36
36
  i(l, n, a) || (d = await r(d, n, s, "value"));
37
- let f = {
37
+ let { role: f, mode: p } = a;
38
+ return {
38
39
  disabled: a.mode !== "gather",
39
40
  mode: a.mode,
40
41
  prompt: l.promptEnabled ? l.prompt : null,
@@ -59,13 +60,13 @@ async function l(t, n, a, s) {
59
60
  keyboardEventsEnabled: l.keyboardEventsEnabled,
60
61
  autoplayAudioEnabled: l.autoplayAudioEnabled,
61
62
  completeAudioEnabled: l.completeAudioEnabled,
62
- customAudioButton: l.customAudioButton
63
- }, { role: p, mode: m } = a || {};
64
- return p === "instructor" && (m === "view" || m === "evaluate") ? f.teacherInstructions = l.teacherInstructionsEnabled ? l.teacherInstructions : null : f.teacherInstructions = null, f;
63
+ customAudioButton: l.customAudioButton,
64
+ teacherInstructions: f === "instructor" && (p === "view" || p === "evaluate") && l.teacherInstructionsEnabled ? l.teacherInstructions : null
65
+ };
65
66
  }
66
67
  var u = (e, t) => {
67
68
  if (!t || n(t)) return 0;
68
- let r = t.value || [], i = (e.choices || []).filter((e) => e.correct), a = r.reduce((e, t) => e + +!!i.find((e) => e.value === t), 0);
69
+ let r = t?.value || [], i = (e.choices || []).filter((e) => e.correct), a = r.reduce((e, t) => e + +!!i.find((e) => e.value === t), 0);
69
70
  i.length < r.length && (a -= r.length - i.length, a < 0 && (a = 0));
70
71
  let o = i.length ? a / i.length : 0;
71
72
  return parseFloat(o.toFixed(2));
@@ -118,7 +119,7 @@ var p = (e, t) => new Promise((n) => {
118
119
  r && (u = !0, d++), m(a) ? o.slice(n + 1).some((e) => e.label === a) && (s[i] = "Content should be unique.") : s[i] = "Content should not be empty.", t.rationale?.required && !m(l) && (c[i] = "This field is required.");
119
120
  });
120
121
  let f = (r || []).length;
121
- if (f < i ? l.answerChoices = `There should be at least ${i} choices defined.` : f > a && (l.answerChoices = `No more than ${a} choices should be defined.`), !u) l.correctResponse = "No correct response defined.";
122
+ if (f < i ? l.answerChoices = `There should be at least ${i} choices defined.` : a !== void 0 && f > a && (l.answerChoices = `No more than ${a} choices should be defined.`), !u) l.correctResponse = "No correct response defined.";
122
123
  else {
123
124
  let { maxSelections: t, choiceMode: n } = e;
124
125
  n !== "radio" && t != null && d > t && (l.correctResponse = `The number of correct answers (${d}) exceeds max selections (${t}). Students won't be able to select all correct answers.`);
@@ -1,2 +1,3 @@
1
- export declare const getCorrectResponse: (choices: any) => any;
2
- export declare const isResponseCorrect: (question: any, session: any) => any;
1
+ import type { Choice, MultipleChoiceModel, MultipleChoiceSession } from '../types.js';
2
+ export declare const getCorrectResponse: (choices: Choice[]) => string[];
3
+ export declare const isResponseCorrect: (question: MultipleChoiceModel, session: MultipleChoiceSession | undefined) => boolean | undefined;
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { default } from './delivery/index.js';
2
+ export type * from './types.js';