@pie-element/multiple-choice 9.9.2-next.0 → 9.9.2-next.12

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.
@@ -8,7 +8,7 @@
8
8
  "@material-ui/core": "^3.9.2",
9
9
  "@material-ui/icons": "^3.0.1",
10
10
  "@pie-framework/pie-configure-events": "^1.3.0",
11
- "@pie-lib/pie-toolbox": "2.8.0",
11
+ "@pie-lib/pie-toolbox": "2.9.0",
12
12
  "debug": "^3.1.0",
13
13
  "lodash": "^4.17.15",
14
14
  "prop-types": "^15.6.2",
@@ -151,7 +151,8 @@ function _model() {
151
151
  selectedAnswerBackgroundColor: normalizedQuestion.selectedAnswerBackgroundColor || 'initial',
152
152
  minSelections: normalizedQuestion.minSelections,
153
153
  maxSelections: normalizedQuestion.maxSelections,
154
- autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled
154
+ autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled,
155
+ completeAudioEnabled: normalizedQuestion.completeAudioEnabled
155
156
  };
156
157
  _ref4 = env || {}, role = _ref4.role, mode = _ref4.mode;
157
158
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["prepareChoice","model","env","defaultFeedback","choice","role","mode","out","label","value","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","createDefaultModel","Promise","resolve","defaults","normalize","question","verticalMode","choicesLayout","questionProps","session","updateSession","normalizedQuestion","Object","assign","incorrect","choices","map","lockChoiceOrder","disabled","prompt","promptEnabled","gridColumns","choiceMode","keyMode","choicePrefix","responseCorrect","undefined","language","extraCSSRules","fontSizeFactor","isSelectionButtonBelow","selectedAnswerBackgroundColor","minSelections","maxSelections","autoplayAudioEnabled","teacherInstructions","teacherInstructionsEnabled","getScore","config","selectedChoices","correctChoices","filter","ch","score","reduce","acc","selectedChoice","find","length","str","parseFloat","toFixed","outcome","empty","partialScoringEnabled","partialScoring","enabled","createCorrectResponseSession","id","c","getInnerText","html","replaceAll","getContent","replace","validate","minAnswerChoices","maxAnswerChoices","reversedChoices","reverse","choicesErrors","rationaleErrors","errors","forEach","field","required","hasCorrectResponse","index","identicalAnswer","slice","some","nbOfChoices","answerChoices","correctResponse"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAQC,GAAR,EAAaC,eAAb;AAAA,SAAiC,UAACC,MAAD,EAAY;AACjE,eAAuBF,GAAG,IAAI,EAA9B;AAAA,QAAQG,IAAR,QAAQA,IAAR;AAAA,QAAcC,IAAd,QAAcA,IAAd;;AACA,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KADJ;AAEVC,MAAAA,KAAK,EAAEL,MAAM,CAACK;AAFJ,KAAZ;;AAKA,QAAIJ,IAAI,KAAK,YAAT,KAA0BC,IAAI,KAAK,MAAT,IAAmBA,IAAI,KAAK,UAAtD,CAAJ,EAAuE;AACrEC,MAAAA,GAAG,CAACG,SAAJ,GAAgBT,KAAK,CAACU,gBAAN,GAAyBP,MAAM,CAACM,SAAhC,GAA4C,IAA5D;AACD,KAFD,MAEO;AACLH,MAAAA,GAAG,CAACG,SAAJ,GAAgB,IAAhB;AACD;;AAED,QAAIJ,IAAI,KAAK,UAAb,EAAyB;AACvBC,MAAAA,GAAG,CAACK,OAAJ,GAAc,CAAC,CAACR,MAAM,CAACQ,OAAvB;;AAEA,UAAIX,KAAK,CAACY,eAAV,EAA2B;AACzB,YAAMC,YAAY,GAAIV,MAAM,CAACW,QAAP,IAAmBX,MAAM,CAACW,QAAP,CAAgBC,IAApC,IAA6C,MAAlE;;AAEA,YAAIF,YAAY,KAAK,SAArB,EAAgC;AAC9BP,UAAAA,GAAG,CAACQ,QAAJ,GAAeZ,eAAe,CAACC,MAAM,CAACQ,OAAP,GAAiB,SAAjB,GAA6B,WAA9B,CAA9B;A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C,SAAP,gEAAkBkF,QAAlB,IAA8B,CAACZ,UAAU,CAACtE,SAAD,CAA7C,EAA0D;AACxD8E,MAAAA,eAAe,CAAC/E,KAAD,CAAf,GAAyB,yBAAzB;AACD;AACF,GApBD;AAsBA,MAAMyF,WAAW,GAAG,CAAClE,OAAO,IAAI,EAAZ,EAAgBiC,MAApC;;AAEA,MAAIiC,WAAW,GAAGf,gBAAlB,EAAoC;AAClCM,IAAAA,MAAM,CAACU,aAAP,sCAAmDhB,gBAAnD;AACD,GAFD,MAEO,IAAIe,WAAW,GAAGd,gBAAlB,EAAoC;AACzCK,IAAAA,MAAM,CAACU,aAAP,0BAAuCf,gBAAvC;AACD;;AAED,MAAI,CAACS,kBAAL,EAAyB;AACvBJ,IAAAA,MAAM,CAACW,eAAP,GAAyB,8BAAzB;AACD;;AAED,MAAI,CAAC,yBAAQb,aAAR,CAAL,EAA6B;AAC3BE,IAAAA,MAAM,CAACzD,OAAP,GAAiBuD,aAAjB;AACD;;AAED,MAAI,CAAC,yBAAQC,eAAR,CAAL,EAA+B;AAC7BC,IAAAA,MAAM,CAAC/E,SAAP,GAAmB8E,eAAnB;AACD;;AAED,SAAOC,MAAP;AACD,CA3DM","sourcesContent":["/* eslint-disable no-console */\nimport isEmpty from 'lodash/isEmpty';\nimport { isResponseCorrect } from './utils';\nimport defaults from './defaults';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-lib/pie-toolbox/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 minSelections: normalizedQuestion.minSelections,\n maxSelections: normalizedQuestion.maxSelections,\n autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled,\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 *\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 });\n } else {\n const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n const score = getScore(model, session);\n\n resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });\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 and iframe\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { choices } = model;\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n const reversedChoices = [...(choices || [])].reverse();\n const choicesErrors = {};\n const rationaleErrors = {};\n const errors = {};\n\n ['teacherInstructions', 'prompt'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n let hasCorrectResponse = false;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label, rationale } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n }\n\n if (!getContent(label)) {\n choicesErrors[value] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[value] = 'Content should be unique.';\n }\n }\n\n if (config.rationale?.required && !getContent(rationale)) {\n rationaleErrors[value] = 'This field is required.';\n }\n });\n\n const nbOfChoices = (choices || []).length;\n\n if (nbOfChoices < minAnswerChoices) {\n errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (!hasCorrectResponse) {\n errors.correctResponse = 'No correct response defined.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choices = choicesErrors;\n }\n\n if (!isEmpty(rationaleErrors)) {\n errors.rationale = rationaleErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["prepareChoice","model","env","defaultFeedback","choice","role","mode","out","label","value","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","createDefaultModel","Promise","resolve","defaults","normalize","question","verticalMode","choicesLayout","questionProps","session","updateSession","normalizedQuestion","Object","assign","incorrect","choices","map","lockChoiceOrder","disabled","prompt","promptEnabled","gridColumns","choiceMode","keyMode","choicePrefix","responseCorrect","undefined","language","extraCSSRules","fontSizeFactor","isSelectionButtonBelow","selectedAnswerBackgroundColor","minSelections","maxSelections","autoplayAudioEnabled","completeAudioEnabled","teacherInstructions","teacherInstructionsEnabled","getScore","config","selectedChoices","correctChoices","filter","ch","score","reduce","acc","selectedChoice","find","length","str","parseFloat","toFixed","outcome","empty","partialScoringEnabled","partialScoring","enabled","createCorrectResponseSession","id","c","getInnerText","html","replaceAll","getContent","replace","validate","minAnswerChoices","maxAnswerChoices","reversedChoices","reverse","choicesErrors","rationaleErrors","errors","forEach","field","required","hasCorrectResponse","index","identicalAnswer","slice","some","nbOfChoices","answerChoices","correctResponse"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAQC,GAAR,EAAaC,eAAb;AAAA,SAAiC,UAACC,MAAD,EAAY;AACjE,eAAuBF,GAAG,IAAI,EAA9B;AAAA,QAAQG,IAAR,QAAQA,IAAR;AAAA,QAAcC,IAAd,QAAcA,IAAd;;AACA,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KADJ;AAEVC,MAAAA,KAAK,EAAEL,MAAM,CAACK;AAFJ,KAAZ;;AAKA,QAAIJ,IAAI,KAAK,YAAT,KAA0BC,IAAI,KAAK,MAAT,IAAmBA,IAAI,KAAK,UAAtD,CAAJ,EAAuE;AACrEC,MAAAA,GAAG,CAACG,SAAJ,GAAgBT,KAAK,CAACU,gBAAN,GAAyBP,MAAM,CAACM,SAAhC,GAA4C,IAA5D;AACD,KAFD,MAEO;AACLH,MAAAA,GAAG,CAACG,SAAJ,GAAgB,IAAhB;AACD;;AAED,QAAIJ,IAAI,KAAK,UAAb,EAAyB;AACvBC,MAAAA,GAAG,CAACK,OAAJ,GAAc,CAAC,CAACR,MAAM,CAACQ,OAAvB;;AAEA,UAAIX,KAAK,CAACY,eAAV,EAA2B;AACzB,YAAMC,YAAY,GAAIV,MAAM,CA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AACW,KAAhB,CAAsBF,KAAK,GAAG,CAA9B,EAAiCG,IAAjC,CAAsC,UAACrB,CAAD;AAAA,eAAOA,CAAC,CAACrE,KAAF,KAAYA,KAAnB;AAAA,OAAtC,CAAxB;;AAEA,UAAIwF,eAAJ,EAAqB;AACnBR,QAAAA,aAAa,CAAC/E,KAAD,CAAb,GAAuB,2BAAvB;AACD;AACF;;AAED,QAAI,qBAAA+C,MAAM,CAAC9C,SAAP,gEAAkBmF,QAAlB,IAA8B,CAACZ,UAAU,CAACvE,SAAD,CAA7C,EAA0D;AACxD+E,MAAAA,eAAe,CAAChF,KAAD,CAAf,GAAyB,yBAAzB;AACD;AACF,GApBD;AAsBA,MAAM0F,WAAW,GAAG,CAACnE,OAAO,IAAI,EAAZ,EAAgBkC,MAApC;;AAEA,MAAIiC,WAAW,GAAGf,gBAAlB,EAAoC;AAClCM,IAAAA,MAAM,CAACU,aAAP,sCAAmDhB,gBAAnD;AACD,GAFD,MAEO,IAAIe,WAAW,GAAGd,gBAAlB,EAAoC;AACzCK,IAAAA,MAAM,CAACU,aAAP,0BAAuCf,gBAAvC;AACD;;AAED,MAAI,CAACS,kBAAL,EAAyB;AACvBJ,IAAAA,MAAM,CAACW,eAAP,GAAyB,8BAAzB;AACD;;AAED,MAAI,CAAC,yBAAQb,aAAR,CAAL,EAA6B;AAC3BE,IAAAA,MAAM,CAAC1D,OAAP,GAAiBwD,aAAjB;AACD;;AAED,MAAI,CAAC,yBAAQC,eAAR,CAAL,EAA+B;AAC7BC,IAAAA,MAAM,CAAChF,SAAP,GAAmB+E,eAAnB;AACD;;AAED,SAAOC,MAAP;AACD,CA3DM","sourcesContent":["/* eslint-disable no-console */\nimport isEmpty from 'lodash/isEmpty';\nimport { isResponseCorrect } from './utils';\nimport defaults from './defaults';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-lib/pie-toolbox/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 minSelections: normalizedQuestion.minSelections,\n maxSelections: normalizedQuestion.maxSelections,\n autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled,\n completeAudioEnabled: normalizedQuestion.completeAudioEnabled,\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 *\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 });\n } else {\n const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n const score = getScore(model, session);\n\n resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });\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 and iframe\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { choices } = model;\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n const reversedChoices = [...(choices || [])].reverse();\n const choicesErrors = {};\n const rationaleErrors = {};\n const errors = {};\n\n ['teacherInstructions', 'prompt'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n let hasCorrectResponse = false;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label, rationale } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n }\n\n if (!getContent(label)) {\n choicesErrors[value] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[value] = 'Content should be unique.';\n }\n }\n\n if (config.rationale?.required && !getContent(rationale)) {\n rationaleErrors[value] = 'This field is required.';\n }\n });\n\n const nbOfChoices = (choices || []).length;\n\n if (nbOfChoices < minAnswerChoices) {\n errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (!hasCorrectResponse) {\n errors.correctResponse = 'No correct response defined.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choices = choicesErrors;\n }\n\n if (!isEmpty(rationaleErrors)) {\n errors.rationale = rationaleErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -8,7 +8,7 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
- "@pie-lib/pie-toolbox": "2.8.0",
11
+ "@pie-lib/pie-toolbox": "2.9.0",
12
12
  "debug": "^3.1.0",
13
13
  "lodash": "^4.17.15"
14
14
  }
@@ -224,6 +224,11 @@
224
224
  "type": "boolean",
225
225
  "title": "autoplayAudioEnabled"
226
226
  },
227
+ "completeAudioEnabled": {
228
+ "description": "Indicates if the audio should reach the end before the item can be marked as 'complete'",
229
+ "type": "boolean",
230
+ "title": "completeAudioEnabled"
231
+ },
227
232
  "id": {
228
233
  "description": "Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.",
229
234
  "type": "string",
@@ -195,6 +195,10 @@ Indicates font size adjustment factor
195
195
 
196
196
  Indicates if the audio for the prompt should autoplay
197
197
 
198
+ # `completeAudioEnabled` (boolean)
199
+
200
+ Indicates if the audio should reach the end before the item can be marked as 'complete'
201
+
198
202
  # `id` (string, required)
199
203
 
200
204
  Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.
package/lib/index.js CHANGED
@@ -46,7 +46,11 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
46
46
  var log = (0, _debug["default"])('pie-ui:multiple-choice');
47
47
 
48
48
  var isComplete = function isComplete(session, model, audioComplete) {
49
- if (model.autoplayAudioEnabled && !audioComplete) {
49
+ var _ref = model || {},
50
+ autoplayAudioEnabled = _ref.autoplayAudioEnabled,
51
+ completeAudioEnabled = _ref.completeAudioEnabled;
52
+
53
+ if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {
50
54
  return false;
51
55
  }
52
56
 
@@ -54,11 +58,11 @@ var isComplete = function isComplete(session, model, audioComplete) {
54
58
  return false;
55
59
  }
56
60
 
57
- var _ref = model || {},
58
- choiceMode = _ref.choiceMode,
59
- _ref$minSelections = _ref.minSelections,
60
- minSelections = _ref$minSelections === void 0 ? 1 : _ref$minSelections,
61
- maxSelections = _ref.maxSelections;
61
+ var _ref2 = model || {},
62
+ choiceMode = _ref2.choiceMode,
63
+ _ref2$minSelections = _ref2.minSelections,
64
+ minSelections = _ref2$minSelections === void 0 ? 1 : _ref2$minSelections,
65
+ maxSelections = _ref2.maxSelections;
62
66
 
63
67
  var selections = session.value.length || 0;
64
68
 
@@ -219,17 +223,17 @@ var MultipleChoice = /*#__PURE__*/function (_HTMLElement) {
219
223
 
220
224
  document.removeEventListener('click', enableAudio);
221
225
  }; // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play
226
+ // FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked
222
227
 
223
228
 
224
- if (audio.paused && !_this2.querySelector('#play-audio-info')) {
225
- // add info message as a toast to enable audio playback
226
- _this2.appendChild(info);
227
-
228
- document.addEventListener('click', enableAudio);
229
- } else {
230
- document.removeEventListener('click', enableAudio);
231
- } // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering
229
+ setTimeout(function () {
230
+ if (audio.paused && !_this2.querySelector('#play-audio-info')) {
231
+ // add info message as a toast to enable audio playback
232
+ _this2.appendChild(info);
232
233
 
234
+ document.addEventListener('click', enableAudio);
235
+ }
236
+ }, 500); // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering
233
237
 
234
238
  var handlePlaying = function handlePlaying() {
235
239
  var info = _this2.querySelector('#play-audio-info');
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","isComplete","session","model","audioComplete","autoplayAudioEnabled","value","choiceMode","minSelections","maxSelections","selections","length","MultipleChoice","_model","_session","_rerender","element","React","createElement","Main","onChoiceChanged","_onChange","bind","onShowCorrectToggle","setAttribute","setLangAttribute","ReactDOM","render","leading","trailing","_dispatchResponseChanged","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","_dispatchModelSet","ModelSetEvent","undefined","language","lang","slice","s","data","info","document","id","innerHTML","Object","assign","style","position","bottom","left","transform","backgroundColor","color","padding","borderRadius","boxShadow","zIndex","observer","MutationObserver","mutationsList","forEach","mutation","type","audio","querySelector","_createAudioInfoToast","enableAudio","play","removeChild","removeEventListener","paused","appendChild","addEventListener","handlePlaying","handleEnded","disconnect","observe","childList","subtree","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,wBAAN,CAAZ;;AAEO,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,OAAD,EAAUC,KAAV,EAAiBC,aAAjB,EAAmC;AAC3D,MAAID,KAAK,CAACE,oBAAN,IAA8B,CAACD,aAAnC,EAAkD;AAChD,WAAO,KAAP;AACD;;AAED,MAAI,CAACF,OAAD,IAAY,CAACA,OAAO,CAACI,KAAzB,EAAgC;AAC9B,WAAO,KAAP;AACD;;AAED,aAAyDH,KAAK,IAAI,EAAlE;AAAA,MAAQI,UAAR,QAAQA,UAAR;AAAA,gCAAoBC,aAApB;AAAA,MAAoBA,aAApB,mCAAoC,CAApC;AAAA,MAAuCC,aAAvC,QAAuCA,aAAvC;;AACA,MAAMC,UAAU,GAAGR,OAAO,CAACI,KAAR,CAAcK,MAAd,IAAwB,CAA3C;;AAEA,MAAIJ,UAAU,KAAK,OAAnB,EAA4B;AAC1B,WAAO,CAAC,CAACG,UAAT;AACD;;AAED,MAAIA,UAAU,GAAGF,aAAb,IAA8BE,UAAU,GAAGD,aAA/C,EAA8D;AAC5D,WAAO,KAAP;AACD;;AAED,SAAO,IAAP;AACD,CArBM;;;;IAuBcG,c;;;;;AACnB,4BAAc;AAAA;;AAAA;AACZ;AACA,UAAKC,MAAL,GAAc,IAAd;AACA,UAAKC,QAAL,GAAgB,IAAhB;AACA,UAAKV,aAAL,GAAqB,KAArB;AAEA,UAAKW,SAAL,GAAiB,0BACf,YAAM;AACJ,UAAI,MAAKF,MAAL,IAAe,MAAKC,QAAxB,EAAkC;AAChC,YAAIE,OAAO,gBAAGC,kBAAMC,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,MAIO;AACLzB,cAAAA,QAAQ,CAAC4B,mBAAT,CAA6B,OAA7B,EAAsCH,WAAtC;AACD,aAtBgC,CAwBjC;;;AACA,gBAAMO,aAAa,GAAG,SAAhBA,aAAgB,GAAM;AAC1B,kBAAMjC,IAAI,GAAG,MAAI,CAACwB,aAAL,CAAmB,kBAAnB,CAAb;;AAEA,kBAAIxB,IAAJ,EAAU;AACR,gBAAA,MAAI,CAAC4B,WAAL,CAAiB5B,IAAjB;AACD;;AAEDuB,cAAAA,KAAK,CAACM,mBAAN,CAA0B,SAA1B,EAAqCI,aAArC;AACD,aARD;;AAUAV,YAAAA,KAAK,CAACS,gBAAN,CAAuB,SAAvB,EAAkCC,aAAlC,EAnCiC,CAqCjC;;AACA,gBAAMC,WAAW,GAAG,SAAdA,WAAc,GAAM;AACxB,cAAA,MAAI,CAACzE,aAAL,GAAqB,IAArB;;AACA,cAAA,MAAI,CAAC0B,wBAAL;;AACAoC,cAAAA,KAAK,CAACM,mBAAN,CAA0B,OAA1B,EAAmCK,WAAnC;AACD,aAJD;;AAMAX,YAAAA,KAAK,CAACS,gBAAN,CAAuB,OAAvB,EAAgCE,WAAhC;AAEAjB,YAAAA,QAAQ,CAACkB,UAAT;AACD;AACF,SAjDD;AAkDD,OAnDgB,CAAjB;AAqDAlB,MAAAA,QAAQ,CAACmB,OAAT,CAAiB,IAAjB,EAAuB;AAAEC,QAAAA,SAAS,EAAE,IAAb;AAAmBC,QAAAA,OAAO,EAAE;AAA5B,OAAvB;AACD;;;kDA7KyCC,W","sourcesContent":["import Main from './main';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport debounce from 'lodash/debounce';\nimport debug from 'debug';\nimport { ModelSetEvent, SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport { renderMath } from '@pie-lib/pie-toolbox/math-rendering';\nimport { updateSessionValue } from './session-updater';\n\nconst log = debug('pie-ui:multiple-choice');\n\nexport const isComplete = (session, model, audioComplete) => {\n if (model.autoplayAudioEnabled && !audioComplete) {\n return false;\n }\n\n if (!session || !session.value) {\n return false;\n }\n\n const { choiceMode, minSelections = 1, maxSelections } = model || {};\n const selections = session.value.length || 0;\n\n if (choiceMode === 'radio') {\n return !!selections;\n }\n\n if (selections < minSelections || selections > maxSelections) {\n return false;\n }\n\n return true;\n};\n\nexport default class MultipleChoice extends HTMLElement {\n constructor() {\n super();\n this._model = null;\n this._session = null;\n this.audioComplete = false;\n\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n var element = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onChoiceChanged: this._onChange.bind(this),\n onShowCorrectToggle: this.onShowCorrectToggle.bind(this),\n });\n\n //TODO: aria-label is set in the _rerender because we need to change it when the model.choiceMode is updated. Consider revisiting the placement of the aria-label setting in the _rerender\n this.setAttribute(\n 'aria-label',\n this._model.choiceMode === 'radio' ? 'Multiple Choice Question' : 'Multiple Correct Answer Question',\n );\n this.setAttribute('role', 'region');\n this.setLangAttribute();\n\n ReactDOM.render(element, this, () => {\n log('render complete - render math');\n renderMath(this);\n });\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n\n this._dispatchResponseChanged = debounce(() => {\n this.dispatchEvent(\n new SessionChangedEvent(this.tagName.toLowerCase(), isComplete(this._session, this._model, this.audioComplete)),\n );\n });\n\n this._dispatchModelSet = debounce(\n () => {\n this.dispatchEvent(\n new ModelSetEvent(\n this.tagName.toLowerCase(),\n isComplete(this._session, this._model),\n this._model !== undefined,\n ),\n );\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n\n onShowCorrectToggle() {\n renderMath(this);\n }\n\n setLangAttribute() {\n const language = this._model && typeof this._model.language ? this._model.language : '';\n const lang = language ? language.slice(0, 2) : 'en';\n this.setAttribute('lang', lang);\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n this._dispatchModelSet();\n }\n\n get session() {\n return this._session;\n }\n\n set session(s) {\n this._session = s;\n this._rerender();\n //TODO: remove this session-changed should only be emit on user change\n this._dispatchResponseChanged();\n }\n\n _onChange(data) {\n updateSessionValue(this._session, this._model.choiceMode, data);\n this._dispatchResponseChanged();\n this._rerender();\n }\n\n _createAudioInfoToast() {\n const info = document.createElement('div');\n info.id = 'play-audio-info';\n info.innerHTML =\n 'Click anywhere to enable audio autoplay. Browser restrictions require user interaction to play audio.';\n Object.assign(info.style, {\n position: 'fixed',\n bottom: '20px',\n left: '50%',\n transform: 'translateX(-50%)',\n backgroundColor: '#333',\n color: '#fff',\n padding: '10px 20px',\n borderRadius: '5px',\n boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',\n zIndex: '1000',\n });\n\n return info;\n }\n\n connectedCallback() {\n this._rerender();\n\n if (this._model && !this._model.autoplayAudioEnabled) {\n return;\n }\n\n const observer = new MutationObserver((mutationsList, observer) => {\n mutationsList.forEach((mutation) => {\n if (mutation.type === 'childList') {\n const audio = this.querySelector('audio[autoplay]');\n\n if (!audio) return;\n\n const info = this._createAudioInfoToast();\n const enableAudio = () => {\n if (this.querySelector('#play-audio-info')) {\n audio.play();\n this.removeChild(info);\n }\n\n document.removeEventListener('click', enableAudio);\n };\n\n // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play\n if (audio.paused && !this.querySelector('#play-audio-info')) {\n // add info message as a toast to enable audio playback\n this.appendChild(info);\n document.addEventListener('click', enableAudio);\n } else {\n document.removeEventListener('click', enableAudio);\n }\n\n // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering\n const handlePlaying = () => {\n const info = this.querySelector('#play-audio-info');\n\n if (info) {\n this.removeChild(info);\n }\n\n audio.removeEventListener('playing', handlePlaying);\n };\n\n audio.addEventListener('playing', handlePlaying);\n\n // we need to listen for the ended event to update the isComplete state\n const handleEnded = () => {\n this.audioComplete = true;\n this._dispatchResponseChanged();\n audio.removeEventListener('ended', handleEnded);\n };\n\n audio.addEventListener('ended', handleEnded);\n\n observer.disconnect();\n }\n });\n });\n\n observer.observe(this, { childList: true, subtree: true });\n }\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","isComplete","session","model","audioComplete","autoplayAudioEnabled","completeAudioEnabled","value","choiceMode","minSelections","maxSelections","selections","length","MultipleChoice","_model","_session","_rerender","element","React","createElement","Main","onChoiceChanged","_onChange","bind","onShowCorrectToggle","setAttribute","setLangAttribute","ReactDOM","render","leading","trailing","_dispatchResponseChanged","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","_dispatchModelSet","ModelSetEvent","undefined","language","lang","slice","s","data","info","document","id","innerHTML","Object","assign","style","position","bottom","left","transform","backgroundColor","color","padding","borderRadius","boxShadow","zIndex","observer","MutationObserver","mutationsList","forEach","mutation","type","audio","querySelector","_createAudioInfoToast","enableAudio","play","removeChild","removeEventListener","setTimeout","paused","appendChild","addEventListener","handlePlaying","handleEnded","disconnect","observe","childList","subtree","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,wBAAN,CAAZ;;AAEO,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,OAAD,EAAUC,KAAV,EAAiBC,aAAjB,EAAmC;AAC3D,aAAuDD,KAAK,IAAI,EAAhE;AAAA,MAAQE,oBAAR,QAAQA,oBAAR;AAAA,MAA8BC,oBAA9B,QAA8BA,oBAA9B;;AAEA,MAAID,oBAAoB,IAAIC,oBAAxB,IAAgD,CAACF,aAArD,EAAoE;AAClE,WAAO,KAAP;AACD;;AAED,MAAI,CAACF,OAAD,IAAY,CAACA,OAAO,CAACK,KAAzB,EAAgC;AAC9B,WAAO,KAAP;AACD;;AAED,cAAyDJ,KAAK,IAAI,EAAlE;AAAA,MAAQK,UAAR,SAAQA,UAAR;AAAA,kCAAoBC,aAApB;AAAA,MAAoBA,aAApB,oCAAoC,CAApC;AAAA,MAAuCC,aAAvC,SAAuCA,aAAvC;;AACA,MAAMC,UAAU,GAAGT,OAAO,CAACK,KA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,CAACmB,UAAT;AACD;AACF,SAlDD;AAmDD,OApDgB,CAAjB;AAsDAnB,MAAAA,QAAQ,CAACoB,OAAT,CAAiB,IAAjB,EAAuB;AAAEC,QAAAA,SAAS,EAAE,IAAb;AAAmBC,QAAAA,OAAO,EAAE;AAA5B,OAAvB;AACD;;;kDA9KyCC,W","sourcesContent":["import Main from './main';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport debounce from 'lodash/debounce';\nimport debug from 'debug';\nimport { ModelSetEvent, SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport { renderMath } from '@pie-lib/pie-toolbox/math-rendering';\nimport { updateSessionValue } from './session-updater';\n\nconst log = debug('pie-ui:multiple-choice');\n\nexport const isComplete = (session, model, audioComplete) => {\n const { autoplayAudioEnabled, completeAudioEnabled } = model || {};\n\n if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {\n return false;\n }\n\n if (!session || !session.value) {\n return false;\n }\n\n const { choiceMode, minSelections = 1, maxSelections } = model || {};\n const selections = session.value.length || 0;\n\n if (choiceMode === 'radio') {\n return !!selections;\n }\n\n if (selections < minSelections || selections > maxSelections) {\n return false;\n }\n\n return true;\n};\n\nexport default class MultipleChoice extends HTMLElement {\n constructor() {\n super();\n this._model = null;\n this._session = null;\n this.audioComplete = false;\n\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n var element = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onChoiceChanged: this._onChange.bind(this),\n onShowCorrectToggle: this.onShowCorrectToggle.bind(this),\n });\n\n //TODO: aria-label is set in the _rerender because we need to change it when the model.choiceMode is updated. Consider revisiting the placement of the aria-label setting in the _rerender\n this.setAttribute(\n 'aria-label',\n this._model.choiceMode === 'radio' ? 'Multiple Choice Question' : 'Multiple Correct Answer Question',\n );\n this.setAttribute('role', 'region');\n this.setLangAttribute();\n\n ReactDOM.render(element, this, () => {\n log('render complete - render math');\n renderMath(this);\n });\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n\n this._dispatchResponseChanged = debounce(() => {\n this.dispatchEvent(\n new SessionChangedEvent(this.tagName.toLowerCase(), isComplete(this._session, this._model, this.audioComplete)),\n );\n });\n\n this._dispatchModelSet = debounce(\n () => {\n this.dispatchEvent(\n new ModelSetEvent(\n this.tagName.toLowerCase(),\n isComplete(this._session, this._model),\n this._model !== undefined,\n ),\n );\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n\n onShowCorrectToggle() {\n renderMath(this);\n }\n\n setLangAttribute() {\n const language = this._model && typeof this._model.language ? this._model.language : '';\n const lang = language ? language.slice(0, 2) : 'en';\n this.setAttribute('lang', lang);\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n this._dispatchModelSet();\n }\n\n get session() {\n return this._session;\n }\n\n set session(s) {\n this._session = s;\n this._rerender();\n //TODO: remove this session-changed should only be emit on user change\n this._dispatchResponseChanged();\n }\n\n _onChange(data) {\n updateSessionValue(this._session, this._model.choiceMode, data);\n this._dispatchResponseChanged();\n this._rerender();\n }\n\n _createAudioInfoToast() {\n const info = document.createElement('div');\n info.id = 'play-audio-info';\n info.innerHTML =\n 'Click anywhere to enable audio autoplay. Browser restrictions require user interaction to play audio.';\n Object.assign(info.style, {\n position: 'fixed',\n bottom: '20px',\n left: '50%',\n transform: 'translateX(-50%)',\n backgroundColor: '#333',\n color: '#fff',\n padding: '10px 20px',\n borderRadius: '5px',\n boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',\n zIndex: '1000',\n });\n\n return info;\n }\n\n connectedCallback() {\n this._rerender();\n\n if (this._model && !this._model.autoplayAudioEnabled) {\n return;\n }\n\n const observer = new MutationObserver((mutationsList, observer) => {\n mutationsList.forEach((mutation) => {\n if (mutation.type === 'childList') {\n const audio = this.querySelector('audio[autoplay]');\n\n if (!audio) return;\n\n const info = this._createAudioInfoToast();\n const enableAudio = () => {\n if (this.querySelector('#play-audio-info')) {\n audio.play();\n this.removeChild(info);\n }\n\n document.removeEventListener('click', enableAudio);\n };\n\n // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play\n // FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked\n setTimeout(() => {\n if (audio.paused && !this.querySelector('#play-audio-info')) {\n // add info message as a toast to enable audio playback\n this.appendChild(info);\n document.addEventListener('click', enableAudio);\n }\n }, 500);\n\n // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering\n const handlePlaying = () => {\n const info = this.querySelector('#play-audio-info');\n\n if (info) {\n this.removeChild(info);\n }\n\n audio.removeEventListener('playing', handlePlaying);\n };\n\n audio.addEventListener('playing', handlePlaying);\n\n // we need to listen for the ended event to update the isComplete state\n const handleEnded = () => {\n this.audioComplete = true;\n this._dispatchResponseChanged();\n audio.removeEventListener('ended', handleEnded);\n };\n\n audio.addEventListener('ended', handleEnded);\n\n observer.disconnect();\n }\n });\n });\n\n observer.observe(this, { childList: true, subtree: true });\n }\n}\n"],"file":"index.js"}
@@ -293,6 +293,28 @@ var MultipleChoice = /*#__PURE__*/function (_React$Component) {
293
293
  prompt: teacherInstructions
294
294
  });
295
295
 
296
+ var getMultipleChoiceMinSelectionErrorMessage = function getMultipleChoiceMinSelectionErrorMessage() {
297
+ if (minSelections && maxSelections) {
298
+ return minSelections === maxSelections ? translator.t('translation:multipleChoice:minmaxSelections_equal', {
299
+ lng: language,
300
+ minSelections: minSelections
301
+ }) : translator.t('translation:multipleChoice:minmaxSelections_range', {
302
+ lng: language,
303
+ minSelections: minSelections,
304
+ maxSelections: maxSelections
305
+ });
306
+ }
307
+
308
+ if (minSelections) {
309
+ return translator.t('translation:multipleChoice:minSelections', {
310
+ lng: language,
311
+ minSelections: minSelections
312
+ });
313
+ }
314
+
315
+ return '';
316
+ };
317
+
296
318
  return /*#__PURE__*/_react["default"].createElement("div", {
297
319
  className: (0, _classnames["default"])(classes.main, className, 'multiple-choice')
298
320
  }, partLabel && /*#__PURE__*/_react["default"].createElement("h3", {
@@ -342,10 +364,7 @@ var MultipleChoice = /*#__PURE__*/function (_React$Component) {
342
364
  });
343
365
  }))), choiceMode === 'checkbox' && selections < minSelections && /*#__PURE__*/_react["default"].createElement("div", {
344
366
  className: classes.errorText
345
- }, translator.t("translation:multipleChoice:minSelections_".concat(minSelections === 1 ? 'one' : 'other'), {
346
- lng: language,
347
- minSelections: minSelections
348
- })), choiceMode === 'checkbox' && maxSelectionsErrorState && /*#__PURE__*/_react["default"].createElement("div", {
367
+ }, getMultipleChoiceMinSelectionErrorMessage()), choiceMode === 'checkbox' && maxSelectionsErrorState && /*#__PURE__*/_react["default"].createElement("div", {
349
368
  className: classes.errorText
350
369
  }, translator.t("translation:multipleChoice:maxSelections_".concat(maxSelections === 1 ? 'one' : 'other'), {
351
370
  lng: language,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/multiple-choice.jsx"],"names":["translator","Translator","styles","theme","main","color","text","backgroundColor","background","partLabel","display","fontSize","margin","fontWeight","paddingBottom","spacing","unit","teacherInstructions","marginBottom","horizontalLayout","flexDirection","flexWrap","gridLayout","fieldset","border","padding","minWidth","srOnly","position","left","top","width","height","overflow","errorText","typography","palette","error","paddingTop","MultipleChoice","props","event","target","value","checked","maxSelections","onChoiceChanged","session","length","setState","maxSelectionsErrorState","selected","mode","showCorrect","state","onShowCorrectToggle","choice","isCorrect","correct","isChecked","isSelected","undefined","alwaysShowCorrect","onToggle","bind","sessionValue","indexOf","nextProps","correctResponse","index","keyMode","String","fromCharCode","toUpperCase","choiceMode","classes","disabled","className","choices","gridColumns","prompt","responseCorrect","animationsDisabled","language","isSelectionButtonBelow","minSelections","autoplayAudioEnabled","isEvaluateMode","showCorrectAnswerToggle","columnsStyle","gridTemplateColumns","selections","teacherInstructionsDiv","renderHeading","hidden","visible","choicesLayout","map","selectedAnswerBackgroundColor","handleChange","hideTick","getChecked","getCorrectness","indexToSymbol","t","lng","React","Component","PropTypes","string","oneOf","array","object","bool","func","isRequired","number","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAC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EY,sBAAUE,KAAV,CAAgB,CAAC,UAAD,EAAa,MAAb,EAAqB,YAArB,CAAhB,CAfE;AAgBjB/B,EAAAA,WAAW,EAAE6B,sBAAUC,MAhBN;AAiBjB/C,EAAAA,iBAAiB,EAAE8C,sBAAUK,IAjBZ;AAkBjB/B,EAAAA,kBAAkB,EAAE0B,sBAAUK,IAlBb;AAmBjB9B,EAAAA,QAAQ,EAAEyB,sBAAUC,MAnBH;AAoBjBX,EAAAA,6BAA6B,EAAEU,sBAAUC,MApBxB;AAqBjBtD,EAAAA,mBAAmB,EAAEqD,sBAAUM,IArBd;AAsBjB9B,EAAAA,sBAAsB,EAAEwB,sBAAUK,IAtBjB;AAuBjB5B,EAAAA,aAAa,EAAEuB,sBAAUQ,MAvBR;AAwBjBvE,EAAAA,aAAa,EAAE+D,sBAAUQ,MAxBR;AAyBjB9B,EAAAA,oBAAoB,EAAEsB,sBAAUK;AAzBf,C;AA2RrB1E,cAAc,CAAC8E,YAAf,GAA8B;AAC5BtE,EAAAA,OAAO,EAAE;AACPJ,IAAAA,KAAK,EAAE;AADA;AADmB,CAA9B;;eAMe,wBAAWzC,MAAX,EAAmBqC,cAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { CorrectAnswerToggle } from '@pie-lib/pie-toolbox/correct-answer-toggle';\nimport classNames from 'classnames';\nimport { withStyles } from '@material-ui/core/styles';\nimport { color, Collapsible, PreviewPrompt } from '@pie-lib/pie-toolbox/render-ui';\nimport Translator from '@pie-lib/pie-toolbox/translator';\n\nimport StyledChoice from './choice';\n\n// MultipleChoice\n\nconst { translator } = Translator;\n\nconst styles = (theme) => ({\n main: {\n color: color.text(),\n backgroundColor: color.background(),\n '& *': {\n '-webkit-font-smoothing': 'antialiased',\n },\n },\n partLabel: {\n display: 'block',\n fontSize: 'inherit',\n margin: '0',\n fontWeight: 'normal',\n paddingBottom: theme.spacing.unit * 2,\n },\n teacherInstructions: {\n marginBottom: theme.spacing.unit * 2,\n },\n horizontalLayout: {\n display: 'flex',\n flexDirection: 'row',\n flexWrap: 'wrap',\n },\n gridLayout: {\n display: 'grid',\n },\n fieldset: {\n border: '0px',\n padding: '0.01em 0 0 0',\n margin: '0px',\n minWidth: '0px',\n },\n srOnly: {\n position: 'absolute',\n left: '-10000px',\n top: 'auto',\n width: '1px',\n height: '1px',\n overflow: 'hidden',\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingTop: theme.spacing.unit,\n },\n});\n\nexport class MultipleChoice extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n mode: PropTypes.oneOf(['gather', 'view', 'evaluate']),\n choiceMode: PropTypes.oneOf(['radio', 'checkbox']),\n keyMode: PropTypes.oneOf(['numbers', 'letters', 'none']),\n choices: PropTypes.array,\n partLabel: PropTypes.string,\n prompt: PropTypes.string,\n teacherInstructions: PropTypes.string,\n session: PropTypes.object,\n disabled: PropTypes.bool,\n onChoiceChanged: PropTypes.func,\n responseCorrect: PropTypes.bool,\n classes: PropTypes.object.isRequired,\n correctResponse: PropTypes.array,\n choicesLayout: PropTypes.oneOf(['vertical', 'grid', 'horizontal']),\n gridColumns: PropTypes.string,\n alwaysShowCorrect: PropTypes.bool,\n animationsDisabled: PropTypes.bool,\n language: PropTypes.string,\n selectedAnswerBackgroundColor: PropTypes.string,\n onShowCorrectToggle: PropTypes.func,\n isSelectionButtonBelow: PropTypes.bool,\n minSelections: PropTypes.number,\n maxSelections: PropTypes.number,\n autoplayAudioEnabled: PropTypes.bool,\n };\n\n constructor(props) {\n super(props);\n\n this.state = {\n showCorrect: this.props.alwaysShowCorrect || false,\n maxSelectionsErrorState: false,\n };\n\n this.onToggle = this.onToggle.bind(this);\n }\n\n isSelected(value) {\n const sessionValue = this.props.session && this.props.session.value;\n\n return sessionValue && sessionValue.indexOf && sessionValue.indexOf(value) >= 0;\n }\n\n // handleChange was added for accessibility. Please see comments and videos from PD-2441.\n handleChange = (event) => {\n const { value, checked } = event.target;\n const { maxSelections, onChoiceChanged, session } = this.props;\n\n if (session.value && session.value.length >= maxSelections) {\n // show/hide max selections error when user select/deselect an answer\n this.setState({ maxSelectionsErrorState: checked });\n\n if (checked) {\n // prevent selecting more answers\n return;\n }\n }\n\n onChoiceChanged({ value, selected: checked });\n };\n\n onToggle = () => {\n if (this.props.mode === 'evaluate') {\n this.setState({ showCorrect: !this.state.showCorrect }, () => {\n if (this.props.onShowCorrectToggle) {\n this.props.onShowCorrectToggle();\n }\n });\n }\n };\n\n UNSAFE_componentWillReceiveProps(nextProps) {\n if (!nextProps.correctResponse && this.state.showCorrect !== false) {\n this.setState({ showCorrect: false }, () => {\n if (this.props.onShowCorrectToggle) {\n this.props.onShowCorrectToggle();\n }\n });\n }\n\n if (nextProps.alwaysShowCorrect && this.state.showCorrect !== true) {\n this.setState({ showCorrect: true }, () => {\n if (this.props.onShowCorrectToggle) {\n this.props.onShowCorrectToggle();\n }\n });\n }\n }\n\n indexToSymbol(index) {\n if (this.props.keyMode === 'numbers') {\n return `${index + 1}`;\n }\n\n if (this.props.keyMode === 'letters') {\n return String.fromCharCode(97 + index).toUpperCase();\n }\n\n return '';\n }\n\n getCorrectness = (choice = {}) => {\n const isCorrect = choice.correct;\n const isChecked = this.isSelected(choice.value);\n\n if (this.state.showCorrect) {\n return isCorrect ? 'correct' : undefined;\n }\n\n if (isCorrect) {\n if (isChecked) {\n // A correct answer is selected: marked with a green checkmark\n return 'correct';\n } else {\n // A correct answer is NOT selected: marked with an orange X\n return 'incorrect';\n }\n } else {\n if (isChecked) {\n // An incorrect answer is selected: marked with an orange X\n return 'incorrect';\n } else {\n // An incorrect answer is NOT selected: not marked\n return undefined;\n }\n }\n };\n\n getChecked(choice) {\n if (this.state.showCorrect) {\n return choice.correct || false;\n }\n\n return this.isSelected(choice.value);\n }\n\n // renderHeading function was added for accessibility.\n renderHeading() {\n const { mode, choiceMode, classes } = this.props;\n\n if (mode !== 'gather') {\n return null;\n }\n\n return choiceMode === 'radio' ? (\n <h2 className={classes.srOnly}>Multiple Choice Question</h2>\n ) : (\n <h2 className={classes.srOnly}>Multiple Select Question</h2>\n );\n }\n\n render() {\n const {\n mode,\n disabled,\n className,\n choices = [],\n choiceMode,\n gridColumns,\n partLabel,\n prompt,\n responseCorrect,\n teacherInstructions,\n classes,\n alwaysShowCorrect,\n animationsDisabled,\n language,\n isSelectionButtonBelow,\n minSelections,\n maxSelections,\n autoplayAudioEnabled,\n session,\n } = this.props;\n const { showCorrect, maxSelectionsErrorState } = this.state;\n const isEvaluateMode = mode === 'evaluate';\n const showCorrectAnswerToggle = isEvaluateMode && !responseCorrect;\n const columnsStyle = gridColumns > 1 ? { gridTemplateColumns: `repeat(${gridColumns}, 1fr)` } : undefined;\n const selections = (session.value && session.value.length) || 0;\n\n const teacherInstructionsDiv = (\n <PreviewPrompt\n tagName=\"div\"\n className=\"prompt\"\n defaultClassName=\"teacher-instructions\"\n prompt={teacherInstructions}\n />\n );\n\n return (\n <div className={classNames(classes.main, className, 'multiple-choice')}>\n {partLabel && <h3 className={classes.partLabel}>{partLabel}</h3>}\n\n {this.renderHeading()}\n\n {teacherInstructions && (\n <div className={classes.teacherInstructions}>\n {!animationsDisabled ? (\n <Collapsible\n labels={{\n hidden: 'Show Teacher Instructions',\n visible: 'Hide Teacher Instructions',\n }}\n >\n {teacherInstructionsDiv}\n </Collapsible>\n ) : (\n teacherInstructionsDiv\n )}\n </div>\n )}\n\n <fieldset className={classes.fieldset}>\n <PreviewPrompt\n className=\"prompt\"\n defaultClassName=\"prompt\"\n prompt={prompt}\n tagName={'legend'}\n autoplayAudioEnabled={autoplayAudioEnabled}\n />\n\n {!alwaysShowCorrect && (\n <CorrectAnswerToggle\n show={showCorrectAnswerToggle}\n toggled={showCorrect}\n onToggle={this.onToggle.bind(this)}\n language={language}\n />\n )}\n\n <div\n className={classNames({\n [classes.gridLayout]: this.props.choicesLayout === 'grid',\n [classes.horizontalLayout]: this.props.choicesLayout === 'horizontal',\n })}\n style={columnsStyle}\n >\n {choices.map((choice, index) => (\n <StyledChoice\n choicesLayout={this.props.choicesLayout}\n selectedAnswerBackgroundColor={this.props.selectedAnswerBackgroundColor}\n gridColumns={gridColumns}\n key={`choice-${index}`}\n choice={choice}\n index={index}\n choicesLength={choices.length}\n showCorrect={showCorrect}\n isEvaluateMode={isEvaluateMode}\n choiceMode={choiceMode}\n disabled={disabled}\n onChoiceChanged={this.handleChange}\n hideTick={choice.hideTick}\n checked={this.getChecked(choice)}\n correctness={isEvaluateMode ? this.getCorrectness(choice) : undefined}\n displayKey={this.indexToSymbol(index)}\n isSelectionButtonBelow={isSelectionButtonBelow}\n />\n ))}\n </div>\n </fieldset>\n\n {choiceMode === 'checkbox' && selections < minSelections && (\n <div className={classes.errorText}>\n {translator.t(`translation:multipleChoice:minSelections_${minSelections === 1 ? 'one' : 'other'}`, {\n lng: language,\n minSelections,\n })}\n </div>\n )}\n {choiceMode === 'checkbox' && maxSelectionsErrorState && (\n <div className={classes.errorText}>\n {translator.t(`translation:multipleChoice:maxSelections_${maxSelections === 1 ? 'one' : 'other'}`, {\n lng: language,\n maxSelections,\n })}\n </div>\n )}\n </div>\n );\n }\n}\n\nMultipleChoice.defaultProps = {\n session: {\n value: [],\n },\n};\n\nexport default withStyles(styles)(MultipleChoice);\n"],"file":"multiple-choice.js"}
1
+ {"version":3,"sources":["../src/multiple-choice.jsx"],"names":["translator","Translator","styles","theme","main","color","text","backgroundColor","background","partLabel","display","fontSize","margin","fontWeight","paddingBottom","spacing","unit","teacherInstructions","marginBottom","horizontalLayout","flexDirection","flexWrap","gridLayout","fieldset","border","padding","minWidth","srOnly","position","left","top","width","height","overflow","errorText","typography","palette","error","paddingTop","MultipleChoice","props","event","target","value","checked","maxSelections","onChoiceChanged","session","length","setState","maxSelectionsErrorState","selected","mode","showCorrect","state","onShowCorrectToggle","choice","isCorrect","correct","isChecked","isSelected","undefined","alwaysShowCorrect","onToggle","bind","sessionValue","indexOf","nextProps","correctResponse","index","keyMode","String","fromCharCode","toUpperCase","choiceMode","classes","disabled","className","choices","gridColumns","prompt","responseCorrect","animationsDisabled","language","isSelectionButtonBelow","minSelections","autoplayAudioEnabled","isEvaluateMode","showCorrectAnswerToggle","columnsStyle","gridTemplateColumns","selections","teacherInstructionsDiv","getMultipleChoiceMinSelectionErrorMessage","t","lng","renderHeading","hidden","visible","choicesLayout","map","selectedAnswerBackgroundColor","handleChange","hideTick","getChecked","getCorrectness","indexToSymbol","React","Component","PropTypes","string","oneOf","array","object","bool","func","isRequired","number","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAEA;AAEA,IAAQA,UAAR,GAAuBC,sBAAvB,CAAQD,UAAR;;AAEA,IAAME,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,IAAI,EAAE;AACJC,MAAAA,KAAK,EAAEA,gBAAMC,IAAN,EADH;AAEJC,MAAAA,eAAe,EAAEF,gBAAMG,UAAN,EAFb;AAGJ,aAAO;AACL,kCAA0B;AADrB;AAHH,KADmB;AAQzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,OAAO,EAAE,OADA;AAETC,MAAAA,QAAQ,EAAE,SAFD;AAGTC,MAAAA,MAAM,EAAE,GAHC;AAITC,MAAAA,UAAU,EAAE,QAJH;AAKTC,MAAAA,aAAa,EAAEX,KAAK,CAACY,OAAN,CAAcC,IAAd,GAAqB;AAL3B,KARc;AAezBC,IAAAA,mBAAmB,EAAE;AACnBC,MAAAA,YAAY,EAAEf,KAAK,CAACY,OAAN,CAAcC,IAAd,GAAqB;AADhB,KAfI;AAkBzBG,IAAAA,gBAAgB,EAAE;AAChBT,MAAAA,OAAO,EAAE,MADO;AAEhBU,MAAAA,aAAa,EAAE,KAFC;AAGhBC,MAAAA,QAAQ,EAAE;AAHM,KAlBO;AAuBzBC,IAAAA,UAAU,EAAE;AACVZ,MAAAA,OAAO,EAAE;A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,EAAEsD,sBAAUM,IArBd;AAsBjB/B,EAAAA,sBAAsB,EAAEyB,sBAAUK,IAtBjB;AAuBjB7B,EAAAA,aAAa,EAAEwB,sBAAUQ,MAvBR;AAwBjBxE,EAAAA,aAAa,EAAEgE,sBAAUQ,MAxBR;AAyBjB/B,EAAAA,oBAAoB,EAAEuB,sBAAUK;AAzBf,C;AAsSrB3E,cAAc,CAAC+E,YAAf,GAA8B;AAC5BvE,EAAAA,OAAO,EAAE;AACPJ,IAAAA,KAAK,EAAE;AADA;AADmB,CAA9B;;eAMe,wBAAWzC,MAAX,EAAmBqC,cAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { CorrectAnswerToggle } from '@pie-lib/pie-toolbox/correct-answer-toggle';\nimport classNames from 'classnames';\nimport { withStyles } from '@material-ui/core/styles';\nimport { color, Collapsible, PreviewPrompt } from '@pie-lib/pie-toolbox/render-ui';\nimport Translator from '@pie-lib/pie-toolbox/translator';\n\nimport StyledChoice from './choice';\n\n// MultipleChoice\n\nconst { translator } = Translator;\n\nconst styles = (theme) => ({\n main: {\n color: color.text(),\n backgroundColor: color.background(),\n '& *': {\n '-webkit-font-smoothing': 'antialiased',\n },\n },\n partLabel: {\n display: 'block',\n fontSize: 'inherit',\n margin: '0',\n fontWeight: 'normal',\n paddingBottom: theme.spacing.unit * 2,\n },\n teacherInstructions: {\n marginBottom: theme.spacing.unit * 2,\n },\n horizontalLayout: {\n display: 'flex',\n flexDirection: 'row',\n flexWrap: 'wrap',\n },\n gridLayout: {\n display: 'grid',\n },\n fieldset: {\n border: '0px',\n padding: '0.01em 0 0 0',\n margin: '0px',\n minWidth: '0px',\n },\n srOnly: {\n position: 'absolute',\n left: '-10000px',\n top: 'auto',\n width: '1px',\n height: '1px',\n overflow: 'hidden',\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingTop: theme.spacing.unit,\n },\n});\n\nexport class MultipleChoice extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n mode: PropTypes.oneOf(['gather', 'view', 'evaluate']),\n choiceMode: PropTypes.oneOf(['radio', 'checkbox']),\n keyMode: PropTypes.oneOf(['numbers', 'letters', 'none']),\n choices: PropTypes.array,\n partLabel: PropTypes.string,\n prompt: PropTypes.string,\n teacherInstructions: PropTypes.string,\n session: PropTypes.object,\n disabled: PropTypes.bool,\n onChoiceChanged: PropTypes.func,\n responseCorrect: PropTypes.bool,\n classes: PropTypes.object.isRequired,\n correctResponse: PropTypes.array,\n choicesLayout: PropTypes.oneOf(['vertical', 'grid', 'horizontal']),\n gridColumns: PropTypes.string,\n alwaysShowCorrect: PropTypes.bool,\n animationsDisabled: PropTypes.bool,\n language: PropTypes.string,\n selectedAnswerBackgroundColor: PropTypes.string,\n onShowCorrectToggle: PropTypes.func,\n isSelectionButtonBelow: PropTypes.bool,\n minSelections: PropTypes.number,\n maxSelections: PropTypes.number,\n autoplayAudioEnabled: PropTypes.bool,\n };\n\n constructor(props) {\n super(props);\n\n this.state = {\n showCorrect: this.props.alwaysShowCorrect || false,\n maxSelectionsErrorState: false,\n };\n\n this.onToggle = this.onToggle.bind(this);\n }\n\n isSelected(value) {\n const sessionValue = this.props.session && this.props.session.value;\n\n return sessionValue && sessionValue.indexOf && sessionValue.indexOf(value) >= 0;\n }\n\n // handleChange was added for accessibility. Please see comments and videos from PD-2441.\n handleChange = (event) => {\n const { value, checked } = event.target;\n const { maxSelections, onChoiceChanged, session } = this.props;\n\n if (session.value && session.value.length >= maxSelections) {\n // show/hide max selections error when user select/deselect an answer\n this.setState({ maxSelectionsErrorState: checked });\n\n if (checked) {\n // prevent selecting more answers\n return;\n }\n }\n\n onChoiceChanged({ value, selected: checked });\n };\n\n onToggle = () => {\n if (this.props.mode === 'evaluate') {\n this.setState({ showCorrect: !this.state.showCorrect }, () => {\n if (this.props.onShowCorrectToggle) {\n this.props.onShowCorrectToggle();\n }\n });\n }\n };\n\n UNSAFE_componentWillReceiveProps(nextProps) {\n if (!nextProps.correctResponse && this.state.showCorrect !== false) {\n this.setState({ showCorrect: false }, () => {\n if (this.props.onShowCorrectToggle) {\n this.props.onShowCorrectToggle();\n }\n });\n }\n\n if (nextProps.alwaysShowCorrect && this.state.showCorrect !== true) {\n this.setState({ showCorrect: true }, () => {\n if (this.props.onShowCorrectToggle) {\n this.props.onShowCorrectToggle();\n }\n });\n }\n }\n\n indexToSymbol(index) {\n if (this.props.keyMode === 'numbers') {\n return `${index + 1}`;\n }\n\n if (this.props.keyMode === 'letters') {\n return String.fromCharCode(97 + index).toUpperCase();\n }\n\n return '';\n }\n\n getCorrectness = (choice = {}) => {\n const isCorrect = choice.correct;\n const isChecked = this.isSelected(choice.value);\n\n if (this.state.showCorrect) {\n return isCorrect ? 'correct' : undefined;\n }\n\n if (isCorrect) {\n if (isChecked) {\n // A correct answer is selected: marked with a green checkmark\n return 'correct';\n } else {\n // A correct answer is NOT selected: marked with an orange X\n return 'incorrect';\n }\n } else {\n if (isChecked) {\n // An incorrect answer is selected: marked with an orange X\n return 'incorrect';\n } else {\n // An incorrect answer is NOT selected: not marked\n return undefined;\n }\n }\n };\n\n getChecked(choice) {\n if (this.state.showCorrect) {\n return choice.correct || false;\n }\n\n return this.isSelected(choice.value);\n }\n\n // renderHeading function was added for accessibility.\n renderHeading() {\n const { mode, choiceMode, classes } = this.props;\n\n if (mode !== 'gather') {\n return null;\n }\n\n return choiceMode === 'radio' ? (\n <h2 className={classes.srOnly}>Multiple Choice Question</h2>\n ) : (\n <h2 className={classes.srOnly}>Multiple Select Question</h2>\n );\n }\n\n render() {\n const {\n mode,\n disabled,\n className,\n choices = [],\n choiceMode,\n gridColumns,\n partLabel,\n prompt,\n responseCorrect,\n teacherInstructions,\n classes,\n alwaysShowCorrect,\n animationsDisabled,\n language,\n isSelectionButtonBelow,\n minSelections,\n maxSelections,\n autoplayAudioEnabled,\n session,\n } = this.props;\n const { showCorrect, maxSelectionsErrorState } = this.state;\n const isEvaluateMode = mode === 'evaluate';\n const showCorrectAnswerToggle = isEvaluateMode && !responseCorrect;\n const columnsStyle = gridColumns > 1 ? { gridTemplateColumns: `repeat(${gridColumns}, 1fr)` } : undefined;\n const selections = (session.value && session.value.length) || 0;\n\n const teacherInstructionsDiv = (\n <PreviewPrompt\n tagName=\"div\"\n className=\"prompt\"\n defaultClassName=\"teacher-instructions\"\n prompt={teacherInstructions}\n />\n );\n\n const getMultipleChoiceMinSelectionErrorMessage = () => {\n if (minSelections && maxSelections) {\n return minSelections === maxSelections\n ? translator.t('translation:multipleChoice:minmaxSelections_equal', { lng: language, minSelections })\n : translator.t('translation:multipleChoice:minmaxSelections_range', { lng: language, minSelections, maxSelections });\n }\n\n if (minSelections) {\n return translator.t('translation:multipleChoice:minSelections', { lng: language, minSelections });\n }\n\n return '';\n };\n\n return (\n <div className={classNames(classes.main, className, 'multiple-choice')}>\n {partLabel && <h3 className={classes.partLabel}>{partLabel}</h3>}\n\n {this.renderHeading()}\n\n {teacherInstructions && (\n <div className={classes.teacherInstructions}>\n {!animationsDisabled ? (\n <Collapsible\n labels={{\n hidden: 'Show Teacher Instructions',\n visible: 'Hide Teacher Instructions',\n }}\n >\n {teacherInstructionsDiv}\n </Collapsible>\n ) : (\n teacherInstructionsDiv\n )}\n </div>\n )}\n\n <fieldset className={classes.fieldset}>\n <PreviewPrompt\n className=\"prompt\"\n defaultClassName=\"prompt\"\n prompt={prompt}\n tagName={'legend'}\n autoplayAudioEnabled={autoplayAudioEnabled}\n />\n\n {!alwaysShowCorrect && (\n <CorrectAnswerToggle\n show={showCorrectAnswerToggle}\n toggled={showCorrect}\n onToggle={this.onToggle.bind(this)}\n language={language}\n />\n )}\n\n <div\n className={classNames({\n [classes.gridLayout]: this.props.choicesLayout === 'grid',\n [classes.horizontalLayout]: this.props.choicesLayout === 'horizontal',\n })}\n style={columnsStyle}\n >\n {choices.map((choice, index) => (\n <StyledChoice\n choicesLayout={this.props.choicesLayout}\n selectedAnswerBackgroundColor={this.props.selectedAnswerBackgroundColor}\n gridColumns={gridColumns}\n key={`choice-${index}`}\n choice={choice}\n index={index}\n choicesLength={choices.length}\n showCorrect={showCorrect}\n isEvaluateMode={isEvaluateMode}\n choiceMode={choiceMode}\n disabled={disabled}\n onChoiceChanged={this.handleChange}\n hideTick={choice.hideTick}\n checked={this.getChecked(choice)}\n correctness={isEvaluateMode ? this.getCorrectness(choice) : undefined}\n displayKey={this.indexToSymbol(index)}\n isSelectionButtonBelow={isSelectionButtonBelow}\n />\n ))}\n </div>\n </fieldset>\n\n {choiceMode === 'checkbox' && (selections < minSelections) && (\n <div className={classes.errorText}>\n {getMultipleChoiceMinSelectionErrorMessage()}\n </div>\n )}\n {choiceMode === 'checkbox' && maxSelectionsErrorState && (\n <div className={classes.errorText}>\n {translator.t(`translation:multipleChoice:maxSelections_${maxSelections === 1 ? 'one' : 'other'}`, {\n lng: language,\n maxSelections,\n })}\n </div>\n )}\n </div>\n );\n }\n}\n\nMultipleChoice.defaultProps = {\n session: {\n value: [],\n },\n};\n\nexport default withStyles(styles)(MultipleChoice);\n"],"file":"multiple-choice.js"}
@@ -1,5 +1,5 @@
1
- import {_dll_react, _dll_prop_types, _dll_react_dom, _dll_classnames, _dll_lodash, _dll_debug} from "../../../@pie-lib/pie-toolbox-math-rendering-module@3.1.1/module/index.js";
2
- import {_dll_pie_lib__pie_toolbox_editable_html, _dll_pie_lib__pie_toolbox_config_ui, _dll_pie_lib__pie_toolbox_render_ui} from "../../../@pie-lib/pie-toolbox-module@5.8.1/module/index.js";
1
+ import {_dll_react, _dll_prop_types, _dll_react_dom, _dll_classnames, _dll_lodash, _dll_debug} from "../../../@pie-lib/pie-toolbox-math-rendering-module@3.2.0/module/index.js";
2
+ import {_dll_pie_lib__pie_toolbox_editable_html, _dll_pie_lib__pie_toolbox_config_ui, _dll_pie_lib__pie_toolbox_render_ui} from "../../../@pie-lib/pie-toolbox-module@5.9.0/module/index.js";
3
3
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
4
4
  function getDefaultExportFromCjs(x) {
5
5
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -20705,6 +20705,7 @@ async function model(question, session, env, updateSession) {
20705
20705
  minSelections: normalizedQuestion.minSelections,
20706
20706
  maxSelections: normalizedQuestion.maxSelections,
20707
20707
  autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled,
20708
+ completeAudioEnabled: normalizedQuestion.completeAudioEnabled,
20708
20709
  };
20709
20710
 
20710
20711
  const { role, mode } = env || {};
package/module/element.js CHANGED
@@ -1,5 +1,5 @@
1
- import {_dll_react, _dll_prop_types, _dll_classnames, _dll_react_dom, _dll_lodash, _dll_debug, _dll_pie_lib__pie_toolbox_math_rendering} from "../../../@pie-lib/pie-toolbox-math-rendering-module@3.1.1/module/index.js";
2
- import {_dll_pie_lib__pie_toolbox_render_ui, _dll_pie_lib__pie_toolbox_correct_answer_toggle} from "../../../@pie-lib/pie-toolbox-module@5.8.1/module/index.js";
1
+ import {_dll_react, _dll_prop_types, _dll_classnames, _dll_react_dom, _dll_lodash, _dll_debug, _dll_pie_lib__pie_toolbox_math_rendering} from "../../../@pie-lib/pie-toolbox-math-rendering-module@3.2.0/module/index.js";
2
+ import {_dll_pie_lib__pie_toolbox_render_ui, _dll_pie_lib__pie_toolbox_correct_answer_toggle} from "../../../@pie-lib/pie-toolbox-module@5.9.0/module/index.js";
3
3
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
4
4
  function getDefaultExportFromCjs(x) {
5
5
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -8457,10 +8457,11 @@ var en = {};
8457
8457
  primaryCorrectWithAlternates: 'Note: The answer shown above is the primary correct answer specified by the author for this item, but other answers may also be recognized as correct.'
8458
8458
  },
8459
8459
  multipleChoice: {
8460
- minSelections_one: 'This question requires at least {{minSelections}} answer.',
8461
- minSelections_other: 'This question requires at least {{minSelections}} answers.',
8460
+ minSelections: 'Select at least {{minSelections}}.',
8462
8461
  maxSelections_one: 'Only {{maxSelections}} answer is allowed.',
8463
- maxSelections_other: 'Only {{maxSelections}} answers are allowed.'
8462
+ maxSelections_other: 'Only {{maxSelections}} answers are allowed.',
8463
+ minmaxSelections_equal: 'Select {{minSelections}}.',
8464
+ minmaxSelections_range: 'Select between {{minSelections}} and {{maxSelections}}.'
8464
8465
  },
8465
8466
  selectText: {
8466
8467
  correctAnswerSelected: 'Correct answer selected',
@@ -8550,10 +8551,11 @@ var es = {};
8550
8551
  primaryCorrectWithAlternates: 'Nota: La respuesta que se muestra arriba es la respuesta correcta principal especificada por el autor para esta pregunta, pero también se pueden reconocer otras respuestas como correctas.'
8551
8552
  },
8552
8553
  multipleChoice: {
8553
- minSelections_one: 'Esta pregunta requiere al menos {{minSelections}} respuesta.',
8554
- minSelections_other: 'Esta pregunta requiere al menos {{minSelections}} respuestas.',
8554
+ minSelections: 'Seleccione al menos {{minSelections}}.',
8555
8555
  maxSelections_one: 'Sólo se permite {{maxSelections}} respuesta.',
8556
- maxSelections_other: 'Sólo se permiten {{maxSelections}} respuestas.'
8556
+ maxSelections_other: 'Sólo se permiten {{maxSelections}} respuestas.',
8557
+ minmaxSelections_equal: 'Seleccione {{minSelections}}.',
8558
+ minmaxSelections_range: 'Seleccione entre {{minSelections}} y {{maxSelections}}.'
8557
8559
  },
8558
8560
  selectText: {
8559
8561
  correctAnswerSelected: 'Respuesta correcta seleccionada',
@@ -12805,26 +12807,45 @@ class MultipleChoice$1 extends React$2.Component {
12805
12807
  lineNumber: 245
12806
12808
  }
12807
12809
  });
12810
+ const getMultipleChoiceMinSelectionErrorMessage = () => {
12811
+ if (minSelections && maxSelections) {
12812
+ return minSelections === maxSelections ? translator.t('translation:multipleChoice:minmaxSelections_equal', {
12813
+ lng: language,
12814
+ minSelections
12815
+ }) : translator.t('translation:multipleChoice:minmaxSelections_range', {
12816
+ lng: language,
12817
+ minSelections,
12818
+ maxSelections
12819
+ });
12820
+ }
12821
+ if (minSelections) {
12822
+ return translator.t('translation:multipleChoice:minSelections', {
12823
+ lng: language,
12824
+ minSelections
12825
+ });
12826
+ }
12827
+ return '';
12828
+ };
12808
12829
  return React$2.createElement('div', {
12809
12830
  className: classNames(classes.main, className, 'multiple-choice'),
12810
12831
  __self: this,
12811
12832
  __source: {
12812
12833
  fileName: _jsxFileName$1,
12813
- lineNumber: 254
12834
+ lineNumber: 268
12814
12835
  }
12815
12836
  }, partLabel && React$2.createElement('h3', {
12816
12837
  className: classes.partLabel,
12817
12838
  __self: this,
12818
12839
  __source: {
12819
12840
  fileName: _jsxFileName$1,
12820
- lineNumber: 255
12841
+ lineNumber: 269
12821
12842
  }
12822
12843
  }, partLabel), this.renderHeading(), teacherInstructions && React$2.createElement('div', {
12823
12844
  className: classes.teacherInstructions,
12824
12845
  __self: this,
12825
12846
  __source: {
12826
12847
  fileName: _jsxFileName$1,
12827
- lineNumber: 260
12848
+ lineNumber: 274
12828
12849
  }
12829
12850
  }, !animationsDisabled ? React$2.createElement(Collapsible, {
12830
12851
  labels: {
@@ -12834,14 +12855,14 @@ class MultipleChoice$1 extends React$2.Component {
12834
12855
  __self: this,
12835
12856
  __source: {
12836
12857
  fileName: _jsxFileName$1,
12837
- lineNumber: 262
12858
+ lineNumber: 276
12838
12859
  }
12839
12860
  }, teacherInstructionsDiv) : teacherInstructionsDiv), React$2.createElement('fieldset', {
12840
12861
  className: classes.fieldset,
12841
12862
  __self: this,
12842
12863
  __source: {
12843
12864
  fileName: _jsxFileName$1,
12844
- lineNumber: 276
12865
+ lineNumber: 290
12845
12866
  }
12846
12867
  }, React$2.createElement(PreviewPrompt, {
12847
12868
  className: "prompt",
@@ -12852,7 +12873,7 @@ class MultipleChoice$1 extends React$2.Component {
12852
12873
  __self: this,
12853
12874
  __source: {
12854
12875
  fileName: _jsxFileName$1,
12855
- lineNumber: 277
12876
+ lineNumber: 291
12856
12877
  }
12857
12878
  }), !alwaysShowCorrect && React$2.createElement(CorrectAnswerToggle, {
12858
12879
  show: showCorrectAnswerToggle,
@@ -12862,7 +12883,7 @@ class MultipleChoice$1 extends React$2.Component {
12862
12883
  __self: this,
12863
12884
  __source: {
12864
12885
  fileName: _jsxFileName$1,
12865
- lineNumber: 286
12886
+ lineNumber: 300
12866
12887
  }
12867
12888
  }), React$2.createElement('div', {
12868
12889
  className: classNames({
@@ -12873,7 +12894,7 @@ class MultipleChoice$1 extends React$2.Component {
12873
12894
  __self: this,
12874
12895
  __source: {
12875
12896
  fileName: _jsxFileName$1,
12876
- lineNumber: 294
12897
+ lineNumber: 308
12877
12898
  }
12878
12899
  }, choices.map((choice, index) => React$2.createElement(StyledChoice, {
12879
12900
  choicesLayout: this.props.choicesLayout,
@@ -12896,24 +12917,21 @@ class MultipleChoice$1 extends React$2.Component {
12896
12917
  __self: this,
12897
12918
  __source: {
12898
12919
  fileName: _jsxFileName$1,
12899
- lineNumber: 302
12920
+ lineNumber: 316
12900
12921
  }
12901
12922
  })))), choiceMode === 'checkbox' && selections < minSelections && React$2.createElement('div', {
12902
12923
  className: classes.errorText,
12903
12924
  __self: this,
12904
12925
  __source: {
12905
12926
  fileName: _jsxFileName$1,
12906
- lineNumber: 326
12927
+ lineNumber: 340
12907
12928
  }
12908
- }, translator.t(`translation:multipleChoice:minSelections_${minSelections === 1 ? 'one' : 'other'}`, {
12909
- lng: language,
12910
- minSelections
12911
- })), choiceMode === 'checkbox' && maxSelectionsErrorState && React$2.createElement('div', {
12929
+ }, getMultipleChoiceMinSelectionErrorMessage()), choiceMode === 'checkbox' && maxSelectionsErrorState && React$2.createElement('div', {
12912
12930
  className: classes.errorText,
12913
12931
  __self: this,
12914
12932
  __source: {
12915
12933
  fileName: _jsxFileName$1,
12916
- lineNumber: 334
12934
+ lineNumber: 345
12917
12935
  }
12918
12936
  }, translator.t(`translation:multipleChoice:maxSelections_${maxSelections === 1 ? 'one' : 'other'}`, {
12919
12937
  lng: language,
@@ -13069,7 +13087,8 @@ const debug = _dll_debug;
13069
13087
  const {renderMath: renderMath} = _dll_pie_lib__pie_toolbox_math_rendering;
13070
13088
  const log = debug('pie-ui:multiple-choice');
13071
13089
  const isComplete = (session, model, audioComplete) => {
13072
- if (model.autoplayAudioEnabled && !audioComplete) {
13090
+ const {autoplayAudioEnabled, completeAudioEnabled} = model || ({});
13091
+ if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {
13073
13092
  return false;
13074
13093
  }
13075
13094
  if (!session || !session.value) {
@@ -13185,12 +13204,12 @@ class MultipleChoice extends HTMLElement {
13185
13204
  }
13186
13205
  document.removeEventListener('click', enableAudio);
13187
13206
  };
13188
- if (audio.paused && !this.querySelector('#play-audio-info')) {
13189
- this.appendChild(info);
13190
- document.addEventListener('click', enableAudio);
13191
- } else {
13192
- document.removeEventListener('click', enableAudio);
13193
- }
13207
+ setTimeout(() => {
13208
+ if (audio.paused && !this.querySelector('#play-audio-info')) {
13209
+ this.appendChild(info);
13210
+ document.addEventListener('click', enableAudio);
13211
+ }
13212
+ }, 500);
13194
13213
  const handlePlaying = () => {
13195
13214
  const info = this.querySelector('#play-audio-info');
13196
13215
  if (info) {
@@ -4,11 +4,11 @@
4
4
  "modules": [
5
5
  {
6
6
  "name": "@pie-lib/pie-toolbox-math-rendering-module",
7
- "version": "3.1.1"
7
+ "version": "3.2.0"
8
8
  },
9
9
  {
10
10
  "name": "@pie-lib/pie-toolbox-module",
11
- "version": "5.8.1"
11
+ "version": "5.9.0"
12
12
  }
13
13
  ]
14
14
  }
package/module/print.js CHANGED
@@ -1,5 +1,5 @@
1
- import {_dll_react, _dll_prop_types, _dll_classnames, _dll_react_dom, _dll_lodash, _dll_pie_lib__pie_toolbox_math_rendering, _dll_debug} from "../../../@pie-lib/pie-toolbox-math-rendering-module@3.1.1/module/index.js";
2
- import {_dll_pie_lib__pie_toolbox_render_ui, _dll_pie_lib__pie_toolbox_correct_answer_toggle} from "../../../@pie-lib/pie-toolbox-module@5.8.1/module/index.js";
1
+ import {_dll_react, _dll_prop_types, _dll_classnames, _dll_react_dom, _dll_lodash, _dll_pie_lib__pie_toolbox_math_rendering, _dll_debug} from "../../../@pie-lib/pie-toolbox-math-rendering-module@3.2.0/module/index.js";
2
+ import {_dll_pie_lib__pie_toolbox_render_ui, _dll_pie_lib__pie_toolbox_correct_answer_toggle} from "../../../@pie-lib/pie-toolbox-module@5.9.0/module/index.js";
3
3
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
4
4
  function getDefaultExportFromCjs(x) {
5
5
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -8457,10 +8457,11 @@ var en = {};
8457
8457
  primaryCorrectWithAlternates: 'Note: The answer shown above is the primary correct answer specified by the author for this item, but other answers may also be recognized as correct.'
8458
8458
  },
8459
8459
  multipleChoice: {
8460
- minSelections_one: 'This question requires at least {{minSelections}} answer.',
8461
- minSelections_other: 'This question requires at least {{minSelections}} answers.',
8460
+ minSelections: 'Select at least {{minSelections}}.',
8462
8461
  maxSelections_one: 'Only {{maxSelections}} answer is allowed.',
8463
- maxSelections_other: 'Only {{maxSelections}} answers are allowed.'
8462
+ maxSelections_other: 'Only {{maxSelections}} answers are allowed.',
8463
+ minmaxSelections_equal: 'Select {{minSelections}}.',
8464
+ minmaxSelections_range: 'Select between {{minSelections}} and {{maxSelections}}.'
8464
8465
  },
8465
8466
  selectText: {
8466
8467
  correctAnswerSelected: 'Correct answer selected',
@@ -8550,10 +8551,11 @@ var es = {};
8550
8551
  primaryCorrectWithAlternates: 'Nota: La respuesta que se muestra arriba es la respuesta correcta principal especificada por el autor para esta pregunta, pero también se pueden reconocer otras respuestas como correctas.'
8551
8552
  },
8552
8553
  multipleChoice: {
8553
- minSelections_one: 'Esta pregunta requiere al menos {{minSelections}} respuesta.',
8554
- minSelections_other: 'Esta pregunta requiere al menos {{minSelections}} respuestas.',
8554
+ minSelections: 'Seleccione al menos {{minSelections}}.',
8555
8555
  maxSelections_one: 'Sólo se permite {{maxSelections}} respuesta.',
8556
- maxSelections_other: 'Sólo se permiten {{maxSelections}} respuestas.'
8556
+ maxSelections_other: 'Sólo se permiten {{maxSelections}} respuestas.',
8557
+ minmaxSelections_equal: 'Seleccione {{minSelections}}.',
8558
+ minmaxSelections_range: 'Seleccione entre {{minSelections}} y {{maxSelections}}.'
8557
8559
  },
8558
8560
  selectText: {
8559
8561
  correctAnswerSelected: 'Respuesta correcta seleccionada',
@@ -12805,26 +12807,45 @@ class MultipleChoice extends React$2.Component {
12805
12807
  lineNumber: 245
12806
12808
  }
12807
12809
  });
12810
+ const getMultipleChoiceMinSelectionErrorMessage = () => {
12811
+ if (minSelections && maxSelections) {
12812
+ return minSelections === maxSelections ? translator.t('translation:multipleChoice:minmaxSelections_equal', {
12813
+ lng: language,
12814
+ minSelections
12815
+ }) : translator.t('translation:multipleChoice:minmaxSelections_range', {
12816
+ lng: language,
12817
+ minSelections,
12818
+ maxSelections
12819
+ });
12820
+ }
12821
+ if (minSelections) {
12822
+ return translator.t('translation:multipleChoice:minSelections', {
12823
+ lng: language,
12824
+ minSelections
12825
+ });
12826
+ }
12827
+ return '';
12828
+ };
12808
12829
  return React$2.createElement('div', {
12809
12830
  className: classNames(classes.main, className, 'multiple-choice'),
12810
12831
  __self: this,
12811
12832
  __source: {
12812
12833
  fileName: _jsxFileName$1,
12813
- lineNumber: 254
12834
+ lineNumber: 268
12814
12835
  }
12815
12836
  }, partLabel && React$2.createElement('h3', {
12816
12837
  className: classes.partLabel,
12817
12838
  __self: this,
12818
12839
  __source: {
12819
12840
  fileName: _jsxFileName$1,
12820
- lineNumber: 255
12841
+ lineNumber: 269
12821
12842
  }
12822
12843
  }, partLabel), this.renderHeading(), teacherInstructions && React$2.createElement('div', {
12823
12844
  className: classes.teacherInstructions,
12824
12845
  __self: this,
12825
12846
  __source: {
12826
12847
  fileName: _jsxFileName$1,
12827
- lineNumber: 260
12848
+ lineNumber: 274
12828
12849
  }
12829
12850
  }, !animationsDisabled ? React$2.createElement(Collapsible, {
12830
12851
  labels: {
@@ -12834,14 +12855,14 @@ class MultipleChoice extends React$2.Component {
12834
12855
  __self: this,
12835
12856
  __source: {
12836
12857
  fileName: _jsxFileName$1,
12837
- lineNumber: 262
12858
+ lineNumber: 276
12838
12859
  }
12839
12860
  }, teacherInstructionsDiv) : teacherInstructionsDiv), React$2.createElement('fieldset', {
12840
12861
  className: classes.fieldset,
12841
12862
  __self: this,
12842
12863
  __source: {
12843
12864
  fileName: _jsxFileName$1,
12844
- lineNumber: 276
12865
+ lineNumber: 290
12845
12866
  }
12846
12867
  }, React$2.createElement(PreviewPrompt, {
12847
12868
  className: "prompt",
@@ -12852,7 +12873,7 @@ class MultipleChoice extends React$2.Component {
12852
12873
  __self: this,
12853
12874
  __source: {
12854
12875
  fileName: _jsxFileName$1,
12855
- lineNumber: 277
12876
+ lineNumber: 291
12856
12877
  }
12857
12878
  }), !alwaysShowCorrect && React$2.createElement(CorrectAnswerToggle, {
12858
12879
  show: showCorrectAnswerToggle,
@@ -12862,7 +12883,7 @@ class MultipleChoice extends React$2.Component {
12862
12883
  __self: this,
12863
12884
  __source: {
12864
12885
  fileName: _jsxFileName$1,
12865
- lineNumber: 286
12886
+ lineNumber: 300
12866
12887
  }
12867
12888
  }), React$2.createElement('div', {
12868
12889
  className: classNames({
@@ -12873,7 +12894,7 @@ class MultipleChoice extends React$2.Component {
12873
12894
  __self: this,
12874
12895
  __source: {
12875
12896
  fileName: _jsxFileName$1,
12876
- lineNumber: 294
12897
+ lineNumber: 308
12877
12898
  }
12878
12899
  }, choices.map((choice, index) => React$2.createElement(StyledChoice, {
12879
12900
  choicesLayout: this.props.choicesLayout,
@@ -12896,24 +12917,21 @@ class MultipleChoice extends React$2.Component {
12896
12917
  __self: this,
12897
12918
  __source: {
12898
12919
  fileName: _jsxFileName$1,
12899
- lineNumber: 302
12920
+ lineNumber: 316
12900
12921
  }
12901
12922
  })))), choiceMode === 'checkbox' && selections < minSelections && React$2.createElement('div', {
12902
12923
  className: classes.errorText,
12903
12924
  __self: this,
12904
12925
  __source: {
12905
12926
  fileName: _jsxFileName$1,
12906
- lineNumber: 326
12927
+ lineNumber: 340
12907
12928
  }
12908
- }, translator.t(`translation:multipleChoice:minSelections_${minSelections === 1 ? 'one' : 'other'}`, {
12909
- lng: language,
12910
- minSelections
12911
- })), choiceMode === 'checkbox' && maxSelectionsErrorState && React$2.createElement('div', {
12929
+ }, getMultipleChoiceMinSelectionErrorMessage()), choiceMode === 'checkbox' && maxSelectionsErrorState && React$2.createElement('div', {
12912
12930
  className: classes.errorText,
12913
12931
  __self: this,
12914
12932
  __source: {
12915
12933
  fileName: _jsxFileName$1,
12916
- lineNumber: 334
12934
+ lineNumber: 345
12917
12935
  }
12918
12936
  }, translator.t(`translation:multipleChoice:maxSelections_${maxSelections === 1 ? 'one' : 'other'}`, {
12919
12937
  lng: language,
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@pie-element/multiple-choice",
3
3
  "repository": "pie-framework/pie-elements",
4
- "version": "9.9.2-next.0+05d92c29d",
4
+ "version": "9.9.2-next.12+87b282e00",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "dependencies": {
9
9
  "@material-ui/core": "^3.9.2",
10
10
  "@pie-framework/pie-player-events": "^0.1.0",
11
- "@pie-lib/pie-toolbox": "2.8.0",
11
+ "@pie-lib/pie-toolbox": "2.9.0",
12
12
  "classnames": "^2.2.5",
13
13
  "debug": "^4.1.1",
14
14
  "enzyme-to-json": "^3.3.3",
@@ -19,7 +19,7 @@
19
19
  "react-test-renderer": "^16.3.2",
20
20
  "react-transition-group": "^2.3.1"
21
21
  },
22
- "gitHead": "05d92c29de17495a5cf359fe895ac379b457ca3f",
22
+ "gitHead": "87b282e0032de66385a8d361264a31d2b18a72ae",
23
23
  "scripts": {
24
24
  "postpublish": "../../scripts/postpublish"
25
25
  },