@pie-element/categorize 11.3.4-next.0 → 12.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/configure/lib/defaults.js +2 -5
  2. package/configure/lib/defaults.js.map +1 -1
  3. package/configure/lib/design/builder.js +15 -33
  4. package/configure/lib/design/builder.js.map +1 -1
  5. package/configure/lib/design/buttons.js +41 -95
  6. package/configure/lib/design/buttons.js.map +1 -1
  7. package/configure/lib/design/categories/RowLabel.js +32 -45
  8. package/configure/lib/design/categories/RowLabel.js.map +1 -1
  9. package/configure/lib/design/categories/alternateResponses.js +96 -251
  10. package/configure/lib/design/categories/alternateResponses.js.map +1 -1
  11. package/configure/lib/design/categories/category.js +135 -208
  12. package/configure/lib/design/categories/category.js.map +1 -1
  13. package/configure/lib/design/categories/choice-preview.js +61 -126
  14. package/configure/lib/design/categories/choice-preview.js.map +1 -1
  15. package/configure/lib/design/categories/droppable-placeholder.js +73 -165
  16. package/configure/lib/design/categories/droppable-placeholder.js.map +1 -1
  17. package/configure/lib/design/categories/index.js +195 -384
  18. package/configure/lib/design/categories/index.js.map +1 -1
  19. package/configure/lib/design/choices/choice.js +155 -264
  20. package/configure/lib/design/choices/choice.js.map +1 -1
  21. package/configure/lib/design/choices/config.js +42 -98
  22. package/configure/lib/design/choices/config.js.map +1 -1
  23. package/configure/lib/design/choices/index.js +148 -236
  24. package/configure/lib/design/choices/index.js.map +1 -1
  25. package/configure/lib/design/header.js +57 -111
  26. package/configure/lib/design/header.js.map +1 -1
  27. package/configure/lib/design/index.js +631 -476
  28. package/configure/lib/design/index.js.map +1 -1
  29. package/configure/lib/design/input-header.js +93 -149
  30. package/configure/lib/design/input-header.js.map +1 -1
  31. package/configure/lib/design/utils.js +4 -15
  32. package/configure/lib/design/utils.js.map +1 -1
  33. package/configure/lib/index.js +120 -183
  34. package/configure/lib/index.js.map +1 -1
  35. package/configure/lib/main.js +30 -74
  36. package/configure/lib/main.js.map +1 -1
  37. package/configure/lib/utils.js +22 -32
  38. package/configure/lib/utils.js.map +1 -1
  39. package/configure/package.json +15 -15
  40. package/controller/lib/defaults.js +2 -5
  41. package/controller/lib/defaults.js.map +1 -1
  42. package/controller/lib/index.js +237 -318
  43. package/controller/lib/index.js.map +1 -1
  44. package/controller/lib/utils.js +28 -65
  45. package/controller/lib/utils.js.map +1 -1
  46. package/controller/package.json +5 -5
  47. package/lib/categorize/categories.js +106 -164
  48. package/lib/categorize/categories.js.map +1 -1
  49. package/lib/categorize/category.js +73 -123
  50. package/lib/categorize/category.js.map +1 -1
  51. package/lib/categorize/choice.js +118 -245
  52. package/lib/categorize/choice.js.map +1 -1
  53. package/lib/categorize/choices.js +66 -131
  54. package/lib/categorize/choices.js.map +1 -1
  55. package/lib/categorize/droppable-placeholder.js +46 -103
  56. package/lib/categorize/droppable-placeholder.js.map +1 -1
  57. package/lib/categorize/grid-content.js +39 -87
  58. package/lib/categorize/grid-content.js.map +1 -1
  59. package/lib/categorize/index.js +341 -317
  60. package/lib/categorize/index.js.map +1 -1
  61. package/lib/index.js +285 -306
  62. package/lib/index.js.map +1 -1
  63. package/package.json +16 -14
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["translator","Translator","getPartialScore","correctResponse","builtCategories","reduce","acc","choices","placements","length","score","filter","ch","correct","maxScore","extraPlacements","totalScore","parseFloat","toFixed","getAlternates","map","c","alternateResponses","alternate","getTotalScore","question","session","env","Object","keys","categories","answers","alternates","enabled","partialScoring","getCorrectness","Promise","resolve","mode","undefined","createDefaultModel","model","defaults","normalize","updateSession","normalizedQuestion","answerCorrectness","role","categoriesPerRow","choicesLabel","choicesPosition","feedback","feedbackEnabled","promptEnabled","prompt","rowLabels","rationaleEnabled","rationale","teacherInstructionsEnabled","teacherInstructions","language","maxChoicesPerCategory","extraCSSRules","minRowHeight","fontSizeFactor","autoplayAudioEnabled","completeAudioEnabled","customAudioButton","note","lockChoiceOrder","filteredCorrectResponse","response","filteredChoices","choice","fb","t","lng","allowAlternateEnabled","responseAreasToBeFilled","possibleResponses","hasUnplacedChoices","out","correctness","disabled","showNote","outcome","reject","Error","empty","createCorrectResponseSession","id","getInnerText","html","replaceAll","getContent","replace","validate","config","maxAnswerChoices","minChoices","minCategories","maxCategories","maxLengthPerChoice","maxLengthPerCategory","reversedChoices","reverse","errors","choicesErrors","categoriesErrors","forEach","field","required","category","label","index","content","identicalAnswer","slice","some","nbOfCategories","nbOfChoices","categoriesError","choicesError","hasAssociations","duplicateAlternateIndex","duplicateCategory","duplicateAlternate","associationError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;;;;;AAFA,IAAQA,UAAR,GAAuBC,sBAAvB,CAAQD,UAAR;;AAQO,IAAME,eAAe,GAAG,SAAlBA,eAAkB,CAACC,eAAD,EAAkBC,eAAlB,EAAsC;AACnE;AACA;AACA,8BAA8BA,eAAe,CAACC,MAAhB,CAC5B,UAACC,GAAD;AAAA,4BAAQC,OAAR;AAAA,QAAQA,OAAR,6BAAkB,EAAlB;AAAA,WAA4B;AAC1BC,MAAAA,UAAU,EAAEF,GAAG,CAACE,UAAJ,GAAiBD,OAAO,CAACE,MADX;AAE1BC,MAAAA,KAAK,EAAEJ,GAAG,CAACI,KAAJ,GAAYH,OAAO,CAACI,MAAR,CAAe,UAACC,EAAD;AAAA,eAAQA,EAAE,CAACC,OAAX;AAAA,OAAf,EAAmCJ;AAF5B,KAA5B;AAAA,GAD4B,EAK5B;AAAED,IAAAA,UAAU,EAAE,CAAd;AAAiBE,IAAAA,KAAK,EAAE;AAAxB,GAL4B,CAA9B;AAAA,MAAQF,UAAR,yBAAQA,UAAR;AAAA,MAAoBE,KAApB,yBAAoBA,KAApB,CAHmE,CAWnE;;;AACA,8BAAqBP,eAAe,CAACE,MAAhB,CACnB,UAACC,GAAD;AAAA,QAAQC,OAAR,SAAQA,OAAR;AAAA,WAAuB;AAC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B;AAAA,mCAA4DgE,QAA5D,CAAsBjD,kBAAtB;AAAA,UAAsBA,kBAAtB,uCAA2C,EAA3C;AAAA,UAA+C0F,QAA/C,GAA4DzC,QAA5D,CAA+CyC,QAA/C;;AAEA,UAAIY,uBAAuB,KAAK,CAAC,CAAjC,EAAoC;AAClCA,QAAAA,uBAAuB,GAAG,wCAA4BrH,OAA5B,EAAqCe,kBAArC,CAA1B;;AAEA,YAAIsG,uBAAuB,KAAK,CAAC,CAAjC,EAAoC;AAClCA,UAAAA,uBAAuB,GAAG,kCAAsBtG,kBAAtB,CAA1B;AACD;;AAEDuG,QAAAA,iBAAiB,GAAGb,QAApB;AACD;AACF,KAZD;;AAcA,QAAIY,uBAAuB,GAAG,CAAC,CAA/B,EAAkC;AAChClB,MAAAA,MAAM,CAACoB,kBAAP,GAA4B;AAAEZ,QAAAA,KAAK,EAAEU,uBAAT;AAAkCZ,QAAAA,QAAQ,EAAEa;AAA5C,OAA5B;AACD;;AAED,QAAI,CAACF,eAAL,EAAsB;AACpBjB,MAAAA,MAAM,CAACqB,gBAAP,GAA0B,iEAA1B;AACD;AACF;;AAED,MAAI,CAAC,yBAAQpB,aAAR,CAAL,EAA6B;AAC3BD,IAAAA,MAAM,CAACC,aAAP,GAAuBA,aAAvB;AACD;;AAED,MAAI,CAAC,yBAAQC,gBAAR,CAAL,EAAgC;AAC9BF,IAAAA,MAAM,CAACE,gBAAP,GAA0BA,gBAA1B;AACD;;AAED,SAAOF,MAAP;AACD,CAhHM","sourcesContent":["import isEmpty from 'lodash/isEmpty';\nimport { buildState, score } from '@pie-lib/categorize';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport Translator from '@pie-lib/translator';\n\nconst { translator } = Translator;\nimport defaults from './defaults';\nimport { getCompleteResponseDetails, isAlternateDuplicated, isCorrectResponseDuplicated } from './utils';\n\n// eslint-disable-next-line no-console\n\nexport { score };\n\nexport const getPartialScore = (correctResponse, builtCategories) => {\n // in the resulted best scenario we make a sum with all the correct responses\n // and all the placements\n const { placements, score } = builtCategories.reduce(\n (acc, { choices = [] }) => ({\n placements: acc.placements + choices.length,\n score: acc.score + choices.filter((ch) => ch.correct).length,\n }),\n { placements: 0, score: 0 },\n );\n\n // in the correct response, we make a sum of the max possible score\n const { maxScore } = correctResponse.reduce(\n (acc, { choices }) => ({\n maxScore: acc.maxScore + choices.length,\n }),\n { maxScore: 0 },\n );\n\n // if there are any extra placements, we subtract from the obtained score\n const extraPlacements = placements > maxScore ? placements - maxScore : 0;\n const totalScore = (score - extraPlacements) / maxScore;\n\n return totalScore < 0 ? 0 : parseFloat(totalScore.toFixed(2));\n};\n\nconst getAlternates = (correctResponse) =>\n correctResponse.map((c) => c.alternateResponses).filter((alternate) => alternate);\n\nexport const getTotalScore = (question, session, env) => {\n if (!session) {\n return 0;\n }\n\n if (Object.keys(session).length === 0) {\n return 0;\n }\n const { categories, choices } = question || {};\n let { correctResponse } = question || {};\n let { answers } = session || {};\n answers = answers || [];\n correctResponse = correctResponse || [];\n\n // this function is used in pie-ui/categorize as well, in order to get the best scenario\n // so we get the best scenario and calculate the score\n const { categories: builtCategories, correct } = buildState(categories, choices, answers, correctResponse);\n\n const alternates = getAlternates(correctResponse);\n const enabled = partialScoring.enabled(question, env);\n\n // if there are any alternates, there will be no partial scoring!\n if (enabled && !alternates.length) {\n // we apply partial scoring\n return getPartialScore(correctResponse, builtCategories);\n }\n\n // else we apply dichotomous\n return correct ? 1 : 0;\n};\n\nexport const getCorrectness = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode === 'evaluate') {\n const score = getTotalScore(question, session, env);\n if (score === 1) {\n resolve('correct');\n } else if (score === 0) {\n resolve('incorrect');\n } else {\n resolve('partially-correct');\n }\n } else {\n resolve(undefined);\n }\n });\n};\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport const model = (question, session, env, updateSession) =>\n new Promise(async (resolve) => {\n const normalizedQuestion = normalize(question);\n const answerCorrectness = await getCorrectness(normalizedQuestion, session, env);\n\n const { mode, role } = env || {};\n\n const {\n categories,\n categoriesPerRow,\n choicesLabel,\n choicesPosition,\n correctResponse,\n feedback,\n feedbackEnabled,\n promptEnabled,\n prompt,\n rowLabels,\n rationaleEnabled,\n rationale,\n teacherInstructionsEnabled,\n teacherInstructions,\n language,\n maxChoicesPerCategory,\n extraCSSRules,\n minRowHeight,\n fontSizeFactor,\n autoplayAudioEnabled,\n completeAudioEnabled,\n customAudioButton,\n } = normalizedQuestion;\n let { choices, note } = normalizedQuestion;\n let fb;\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n const filteredCorrectResponse = correctResponse.map((response) => {\n const filteredChoices = (response.choices || []).filter((choice) => choice !== 'null');\n return { ...response, choices: filteredChoices };\n });\n\n if (mode === 'evaluate' && feedbackEnabled) {\n fb = await getFeedbackForCorrectness(answerCorrectness, feedback);\n }\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'id');\n }\n\n if (!note) {\n note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: language });\n }\n\n const alternates = getAlternates(filteredCorrectResponse);\n const { responseAreasToBeFilled, possibleResponses, hasUnplacedChoices } = getCompleteResponseDetails(\n filteredCorrectResponse,\n normalizedQuestion.allowAlternateEnabled ? alternates : [],\n normalizedQuestion.choices,\n );\n const out = {\n categories: categories || [],\n categoriesPerRow: categoriesPerRow || 2,\n maxChoicesPerCategory,\n correctness: answerCorrectness,\n choices: choices || [],\n choicesLabel: choicesLabel || '',\n choicesPosition,\n disabled: mode !== 'gather',\n feedback: fb,\n lockChoiceOrder,\n prompt: promptEnabled ? prompt : null,\n rowLabels,\n note,\n env,\n showNote: alternates && alternates.length > 0,\n correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined,\n language,\n extraCSSRules,\n fontSizeFactor,\n minRowHeight: minRowHeight,\n autoplayAudioEnabled,\n completeAudioEnabled,\n customAudioButton,\n possibleResponses,\n responseAreasToBeFilled,\n hasUnplacedChoices,\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = rationaleEnabled ? rationale : null;\n out.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n\nexport const outcome = (question, session, env) => {\n if (env.mode !== 'evaluate') {\n return Promise.reject(new Error('Can not call outcome when mode is not evaluate'));\n } else {\n return new Promise((resolve) => {\n resolve({\n score: getTotalScore(question, session, env),\n empty: !session || isEmpty(session),\n });\n });\n }\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n const { mode, role } = env || {};\n\n if (mode !== 'evaluate' && role === 'instructor') {\n const { correctResponse } = question;\n\n resolve({ answers: correctResponse, id: 1 });\n } else {\n return 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 { categories, choices, correctResponse, maxAnswerChoices } = model;\n const {\n minChoices = 1,\n minCategories = 1,\n maxCategories = 12,\n maxLengthPerChoice = 300,\n maxLengthPerCategory = 150,\n } = config;\n const reversedChoices = [...(choices || [])].reverse();\n const errors = {};\n const choicesErrors = {};\n const categoriesErrors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n (categories || []).forEach((category) => {\n const { id, label } = category;\n\n if (getInnerText(label).length > maxLengthPerCategory) {\n categoriesErrors[id] = `Category labels should be no more than ${maxLengthPerCategory} characters long.`;\n }\n });\n\n (reversedChoices || []).forEach((choice, index) => {\n const { id, content } = choice;\n\n if (getInnerText(content).length > maxLengthPerChoice) {\n choicesErrors[id] = `Tokens should be no more than ${maxLengthPerChoice} characters long.`;\n }\n\n if (!getContent(content)) {\n choicesErrors[id] = 'Tokens should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.content === content);\n\n if (identicalAnswer) {\n choicesErrors[id] = 'Tokens content should be unique.';\n }\n }\n });\n\n const nbOfCategories = (categories || []).length;\n const nbOfChoices = (choices || []).length;\n\n if (nbOfCategories > maxCategories) {\n errors.categoriesError = `No more than ${maxCategories} categories should be defined.`;\n } else if (nbOfCategories < minCategories) {\n errors.categoriesError = `There should be at least ${minCategories} category defined.`;\n }\n\n if (nbOfChoices < minChoices) {\n errors.choicesError = `There should be at least ${minChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.choicesError = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (nbOfChoices && nbOfCategories) {\n let hasAssociations = false;\n\n (correctResponse || []).forEach((response) => {\n const { choices = [], alternateResponses = [] } = response;\n\n if (choices.length) {\n hasAssociations = true;\n } else {\n alternateResponses.forEach((alternate) => {\n if ((alternate || []).length) {\n hasAssociations = true;\n }\n });\n }\n });\n\n let duplicateAlternateIndex = -1;\n let duplicateCategory = '';\n (correctResponse || []).forEach((response) => {\n const { choices = [], alternateResponses = [], category } = response;\n\n if (duplicateAlternateIndex === -1) {\n duplicateAlternateIndex = isCorrectResponseDuplicated(choices, alternateResponses);\n\n if (duplicateAlternateIndex === -1) {\n duplicateAlternateIndex = isAlternateDuplicated(alternateResponses);\n }\n\n duplicateCategory = category;\n }\n });\n\n if (duplicateAlternateIndex > -1) {\n errors.duplicateAlternate = { index: duplicateAlternateIndex, category: duplicateCategory };\n }\n\n if (!hasAssociations) {\n errors.associationError = 'At least one token should be assigned to at least one category.';\n }\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n if (!isEmpty(categoriesErrors)) {\n errors.categoriesErrors = categoriesErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":["_isEmpty","_interopRequireDefault","require","_categorize","_feedback","_controllerUtils","_translator","_defaults","_utils","translator","Translator","getPartialScore","correctResponse","builtCategories","placements","score","reduce","acc","choices","length","filter","ch","correct","maxScore","extraPlacements","totalScore","parseFloat","toFixed","exports","getAlternates","map","c","alternateResponses","alternate","getTotalScore","question","session","env","Object","keys","categories","answers","buildState","alternates","enabled","partialScoring","getCorrectness","Promise","resolve","mode","undefined","createDefaultModel","model","defaults","normalize","updateSession","normalizedQuestion","answerCorrectness","role","categoriesPerRow","choicesLabel","choicesPosition","feedback","feedbackEnabled","promptEnabled","prompt","rowLabels","rationaleEnabled","rationale","teacherInstructionsEnabled","teacherInstructions","language","maxChoicesPerCategory","extraCSSRules","minRowHeight","fontSizeFactor","autoplayAudioEnabled","completeAudioEnabled","customAudioButton","note","fb","lockChoiceOrder","lockChoices","filteredCorrectResponse","response","filteredChoices","choice","getFeedbackForCorrectness","getShuffledChoices","t","lng","responseAreasToBeFilled","possibleResponses","hasUnplacedChoices","getCompleteResponseDetails","allowAlternateEnabled","out","correctness","disabled","showNote","outcome","reject","Error","empty","isEmpty","createCorrectResponseSession","id","getInnerText","html","replaceAll","getContent","replace","validate","config","maxAnswerChoices","minChoices","minCategories","maxCategories","maxLengthPerChoice","maxLengthPerCategory","reversedChoices","reverse","errors","choicesErrors","categoriesErrors","forEach","field","required","category","label","index","content","identicalAnswer","slice","some","nbOfCategories","nbOfChoices","categoriesError","choicesError","hasAssociations","duplicateAlternateIndex","duplicateCategory","isCorrectResponseDuplicated","isAlternateDuplicated","duplicateAlternate","associationError"],"sources":["../src/index.js"],"sourcesContent":["import isEmpty from 'lodash/isEmpty';\nimport { buildState, score } from '@pie-lib/categorize';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport Translator from '@pie-lib/translator';\n\nconst { translator } = Translator;\nimport defaults from './defaults';\nimport { getCompleteResponseDetails, isAlternateDuplicated, isCorrectResponseDuplicated } from './utils';\n\n// eslint-disable-next-line no-console\n\nexport { score };\n\nexport const getPartialScore = (correctResponse, builtCategories) => {\n // in the resulted best scenario we make a sum with all the correct responses\n // and all the placements\n const { placements, score } = builtCategories.reduce(\n (acc, { choices = [] }) => ({\n placements: acc.placements + choices.length,\n score: acc.score + choices.filter((ch) => ch.correct).length,\n }),\n { placements: 0, score: 0 },\n );\n\n // in the correct response, we make a sum of the max possible score\n const { maxScore } = correctResponse.reduce(\n (acc, { choices }) => ({\n maxScore: acc.maxScore + choices.length,\n }),\n { maxScore: 0 },\n );\n\n // if there are any extra placements, we subtract from the obtained score\n const extraPlacements = placements > maxScore ? placements - maxScore : 0;\n const totalScore = (score - extraPlacements) / maxScore;\n\n return totalScore < 0 ? 0 : parseFloat(totalScore.toFixed(2));\n};\n\nconst getAlternates = (correctResponse) =>\n correctResponse.map((c) => c.alternateResponses).filter((alternate) => alternate);\n\nexport const getTotalScore = (question, session, env) => {\n if (!session) {\n return 0;\n }\n\n if (Object.keys(session).length === 0) {\n return 0;\n }\n const { categories, choices } = question || {};\n let { correctResponse } = question || {};\n let { answers } = session || {};\n answers = answers || [];\n correctResponse = correctResponse || [];\n\n // this function is used in pie-ui/categorize as well, in order to get the best scenario\n // so we get the best scenario and calculate the score\n const { categories: builtCategories, correct } = buildState(categories, choices, answers, correctResponse);\n\n const alternates = getAlternates(correctResponse);\n const enabled = partialScoring.enabled(question, env);\n\n // if there are any alternates, there will be no partial scoring!\n if (enabled && !alternates.length) {\n // we apply partial scoring\n return getPartialScore(correctResponse, builtCategories);\n }\n\n // else we apply dichotomous\n return correct ? 1 : 0;\n};\n\nexport const getCorrectness = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode === 'evaluate') {\n const score = getTotalScore(question, session, env);\n if (score === 1) {\n resolve('correct');\n } else if (score === 0) {\n resolve('incorrect');\n } else {\n resolve('partially-correct');\n }\n } else {\n resolve(undefined);\n }\n });\n};\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport const model = async (question, session, env, updateSession) => {\n const normalizedQuestion = normalize(question);\n const answerCorrectness = await getCorrectness(normalizedQuestion, session, env);\n\n const { mode, role } = env || {};\n\n const {\n categories,\n categoriesPerRow,\n choicesLabel,\n choicesPosition,\n correctResponse,\n feedback,\n feedbackEnabled,\n promptEnabled,\n prompt,\n rowLabels,\n rationaleEnabled,\n rationale,\n teacherInstructionsEnabled,\n teacherInstructions,\n language,\n maxChoicesPerCategory,\n extraCSSRules,\n minRowHeight,\n fontSizeFactor,\n autoplayAudioEnabled,\n completeAudioEnabled,\n customAudioButton,\n } = normalizedQuestion;\n let { choices, note } = normalizedQuestion;\n let fb;\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n const filteredCorrectResponse = correctResponse.map((response) => {\n const filteredChoices = (response.choices || []).filter((choice) => choice !== 'null');\n return { ...response, choices: filteredChoices };\n });\n\n if (mode === 'evaluate' && feedbackEnabled) {\n fb = await getFeedbackForCorrectness(answerCorrectness, feedback);\n }\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'id');\n }\n\n if (!note) {\n note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: language });\n }\n\n const alternates = getAlternates(filteredCorrectResponse);\n const { responseAreasToBeFilled, possibleResponses, hasUnplacedChoices } = getCompleteResponseDetails(\n filteredCorrectResponse,\n normalizedQuestion.allowAlternateEnabled ? alternates : [],\n normalizedQuestion.choices,\n );\n const out = {\n categories: categories || [],\n categoriesPerRow: categoriesPerRow || 2,\n maxChoicesPerCategory,\n correctness: answerCorrectness,\n choices: choices || [],\n choicesLabel: choicesLabel || '',\n choicesPosition,\n disabled: mode !== 'gather',\n feedback: fb,\n lockChoiceOrder,\n prompt: promptEnabled ? prompt : null,\n rowLabels,\n note,\n env,\n showNote: alternates && alternates.length > 0,\n correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined,\n language,\n extraCSSRules,\n fontSizeFactor,\n minRowHeight: minRowHeight,\n autoplayAudioEnabled,\n completeAudioEnabled,\n customAudioButton,\n possibleResponses,\n responseAreasToBeFilled,\n hasUnplacedChoices,\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = rationaleEnabled ? rationale : null;\n out.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n return out;\n};\n\nexport const outcome = (question, session, env) => {\n if (env.mode !== 'evaluate') {\n return Promise.reject(new Error('Can not call outcome when mode is not evaluate'));\n } else {\n return new Promise((resolve) => {\n resolve({\n score: getTotalScore(question, session, env),\n empty: !session || isEmpty(session),\n });\n });\n }\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n const { mode, role } = env || {};\n\n if (mode !== 'evaluate' && role === 'instructor') {\n const { correctResponse } = question;\n\n resolve({ answers: correctResponse, id: 1 });\n } else {\n return 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 { categories, choices, correctResponse, maxAnswerChoices } = model;\n const {\n minChoices = 1,\n minCategories = 1,\n maxCategories = 12,\n maxLengthPerChoice = 300,\n maxLengthPerCategory = 150,\n } = config;\n const reversedChoices = [...(choices || [])].reverse();\n const errors = {};\n const choicesErrors = {};\n const categoriesErrors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n (categories || []).forEach((category) => {\n const { id, label } = category;\n\n if (getInnerText(label).length > maxLengthPerCategory) {\n categoriesErrors[id] = `Category labels should be no more than ${maxLengthPerCategory} characters long.`;\n }\n });\n\n (reversedChoices || []).forEach((choice, index) => {\n const { id, content } = choice;\n\n if (getInnerText(content).length > maxLengthPerChoice) {\n choicesErrors[id] = `Tokens should be no more than ${maxLengthPerChoice} characters long.`;\n }\n\n if (!getContent(content)) {\n choicesErrors[id] = 'Tokens should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.content === content);\n\n if (identicalAnswer) {\n choicesErrors[id] = 'Tokens content should be unique.';\n }\n }\n });\n\n const nbOfCategories = (categories || []).length;\n const nbOfChoices = (choices || []).length;\n\n if (nbOfCategories > maxCategories) {\n errors.categoriesError = `No more than ${maxCategories} categories should be defined.`;\n } else if (nbOfCategories < minCategories) {\n errors.categoriesError = `There should be at least ${minCategories} category defined.`;\n }\n\n if (nbOfChoices < minChoices) {\n errors.choicesError = `There should be at least ${minChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.choicesError = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (nbOfChoices && nbOfCategories) {\n let hasAssociations = false;\n\n (correctResponse || []).forEach((response) => {\n const { choices = [], alternateResponses = [] } = response;\n\n if (choices.length) {\n hasAssociations = true;\n } else {\n alternateResponses.forEach((alternate) => {\n if ((alternate || []).length) {\n hasAssociations = true;\n }\n });\n }\n });\n\n let duplicateAlternateIndex = -1;\n let duplicateCategory = '';\n (correctResponse || []).forEach((response) => {\n const { choices = [], alternateResponses = [], category } = response;\n\n if (duplicateAlternateIndex === -1) {\n duplicateAlternateIndex = isCorrectResponseDuplicated(choices, alternateResponses);\n\n if (duplicateAlternateIndex === -1) {\n duplicateAlternateIndex = isAlternateDuplicated(alternateResponses);\n }\n\n duplicateCategory = category;\n }\n });\n\n if (duplicateAlternateIndex > -1) {\n errors.duplicateAlternate = { index: duplicateAlternateIndex, category: duplicateCategory };\n }\n\n if (!hasAssociations) {\n errors.associationError = 'At least one token should be assigned to at least one category.';\n }\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n if (!isEmpty(categoriesErrors)) {\n errors.categoriesErrors = categoriesErrors;\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAL,sBAAA,CAAAC,OAAA;AAGA,IAAAK,SAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAFA,MAAM;EAAEO;AAAW,CAAC,GAAGC,mBAAU;;AAIjC;;AAIO,MAAMC,eAAe,GAAGA,CAACC,eAAe,EAAEC,eAAe,KAAK;EACnE;EACA;EACA,MAAM;IAAEC,UAAU;IAAEC;EAAM,CAAC,GAAGF,eAAe,CAACG,MAAM,CAClD,CAACC,GAAG,EAAE;IAAEC,OAAO,GAAG;EAAG,CAAC,MAAM;IAC1BJ,UAAU,EAAEG,GAAG,CAACH,UAAU,GAAGI,OAAO,CAACC,MAAM;IAC3CJ,KAAK,EAAEE,GAAG,CAACF,KAAK,GAAGG,OAAO,CAACE,MAAM,CAAEC,EAAE,IAAKA,EAAE,CAACC,OAAO,CAAC,CAACH;EACxD,CAAC,CAAC,EACF;IAAEL,UAAU,EAAE,CAAC;IAAEC,KAAK,EAAE;EAAE,CAC5B,CAAC;;EAED;EACA,MAAM;IAAEQ;EAAS,CAAC,GAAGX,eAAe,CAACI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,OAAO,GAAG,EAAE;QAAEc,kBAAkB,GAAG,EAAE;QAAEgG;MAAS,CAAC,GAAG5C,QAAQ;MAEpE,IAAIwD,uBAAuB,KAAK,CAAC,CAAC,EAAE;QAClCA,uBAAuB,GAAG,IAAAE,kCAA2B,EAAC5H,OAAO,EAAEc,kBAAkB,CAAC;QAElF,IAAI4G,uBAAuB,KAAK,CAAC,CAAC,EAAE;UAClCA,uBAAuB,GAAG,IAAAG,4BAAqB,EAAC/G,kBAAkB,CAAC;QACrE;QAEA6G,iBAAiB,GAAGb,QAAQ;MAC9B;IACF,CAAC,CAAC;IAEF,IAAIY,uBAAuB,GAAG,CAAC,CAAC,EAAE;MAChClB,MAAM,CAACsB,kBAAkB,GAAG;QAAEd,KAAK,EAAEU,uBAAuB;QAAEZ,QAAQ,EAAEa;MAAkB,CAAC;IAC7F;IAEA,IAAI,CAACF,eAAe,EAAE;MACpBjB,MAAM,CAACuB,gBAAgB,GAAG,iEAAiE;IAC7F;EACF;EAEA,IAAI,CAAC,IAAAzC,gBAAO,EAACmB,aAAa,CAAC,EAAE;IAC3BD,MAAM,CAACC,aAAa,GAAGA,aAAa;EACtC;EAEA,IAAI,CAAC,IAAAnB,gBAAO,EAACoB,gBAAgB,CAAC,EAAE;IAC9BF,MAAM,CAACE,gBAAgB,GAAGA,gBAAgB;EAC5C;EAEA,OAAOF,MAAM;AACf,CAAC;AAAC9F,OAAA,CAAAoF,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -1,106 +1,69 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.multiplePlacements = exports.isCorrectResponseDuplicated = exports.isAlternateDuplicated = exports.getCompleteResponseDetails = void 0;
9
-
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
7
  // used in configure too, for consistency modify it there too
13
- var multiplePlacements = {
8
+ const multiplePlacements = exports.multiplePlacements = {
14
9
  enabled: 'Yes',
15
10
  disabled: 'No',
16
11
  perChoice: 'Set Per Choice'
17
- }; // used to validate the config
18
-
19
- exports.multiplePlacements = multiplePlacements;
12
+ };
20
13
 
21
- var isCorrectResponseDuplicated = function isCorrectResponseDuplicated(choices, alternate) {
14
+ // used to validate the config
15
+ const isCorrectResponseDuplicated = (choices, alternate) => {
22
16
  if (choices.length < 1 || alternate.length < 1) {
23
17
  return -1;
24
18
  }
25
-
26
- var stringChoices = JSON.stringify(choices.sort());
27
- var stringAlternate = alternate.reduce(function (total, current) {
28
- return current.length > 0 ? [].concat((0, _toConsumableArray2["default"])(total), [JSON.stringify(current.sort())]) : total;
29
- }, []);
30
- var foundIndexDuplicate = stringAlternate.findIndex(function (alternate) {
31
- return alternate.length && alternate === stringChoices;
32
- });
19
+ const stringChoices = JSON.stringify(choices.sort());
20
+ const stringAlternate = alternate.reduce((total, current) => current.length > 0 ? [...total, JSON.stringify(current.sort())] : total, []);
21
+ const foundIndexDuplicate = stringAlternate.findIndex(alternate => alternate.length && alternate === stringChoices);
33
22
  return foundIndexDuplicate;
34
23
  };
35
-
36
24
  exports.isCorrectResponseDuplicated = isCorrectResponseDuplicated;
37
-
38
- var isAlternateDuplicated = function isAlternateDuplicated(alternate) {
25
+ const isAlternateDuplicated = alternate => {
39
26
  if (alternate.length <= 1) {
40
27
  return -1;
41
28
  }
42
-
43
- var elementSet = new Set();
44
- var stringAlternate = alternate.reduce(function (total, current) {
45
- return current.length > 0 ? [].concat((0, _toConsumableArray2["default"])(total), [JSON.stringify(current.sort())]) : total;
46
- }, []);
47
-
48
- for (var i = 0; i < stringAlternate.length; i++) {
29
+ const elementSet = new Set();
30
+ const stringAlternate = alternate.reduce((total, current) => current.length > 0 ? [...total, JSON.stringify(current.sort())] : total, []);
31
+ for (let i = 0; i < stringAlternate.length; i++) {
49
32
  if (elementSet.has(stringAlternate[i]) && stringAlternate[i]) {
50
33
  return i;
51
34
  }
52
-
53
35
  elementSet.add(stringAlternate[i]);
54
36
  }
55
-
56
37
  return -1;
57
- }; // calculate the minimum number of populated response areas (categories) in the correct answer or alternates
58
- // and create an array with the possible responses ids
59
-
38
+ };
60
39
 
40
+ // calculate the minimum number of populated response areas (categories) in the correct answer or alternates
41
+ // and create an array with the possible responses ids
61
42
  exports.isAlternateDuplicated = isAlternateDuplicated;
62
-
63
- var getCompleteResponseDetails = function getCompleteResponseDetails(correctResponse, alternates, allChoices) {
64
- var choicesPerCategory = correctResponse.map(function (category) {
65
- return category.choices;
66
- });
67
- var possibleResponses = [choicesPerCategory.flat()];
68
- var responseAreasToBeFilled = choicesPerCategory.filter(function (choices) {
69
- return choices.length;
70
- }).length;
71
-
43
+ const getCompleteResponseDetails = (correctResponse, alternates, allChoices) => {
44
+ const choicesPerCategory = correctResponse.map(category => category.choices);
45
+ const possibleResponses = [choicesPerCategory.flat()];
46
+ let responseAreasToBeFilled = choicesPerCategory.filter(choices => choices.length).length;
72
47
  if (alternates.length) {
73
- var _alternates$;
48
+ const alternatesPerChoice = alternates[0]?.length || 0; // number of alternates
74
49
 
75
- var alternatesPerChoice = ((_alternates$ = alternates[0]) === null || _alternates$ === void 0 ? void 0 : _alternates$.length) || 0; // number of alternates
76
-
77
- (0, _toConsumableArray2["default"])(Array(alternatesPerChoice).keys()).forEach(function (index) {
78
- var alternatesPerResponse = alternates.map(function (alternate) {
79
- return alternate[index];
80
- });
81
- var filledCategories = alternatesPerResponse.filter(function (category) {
82
- return category === null || category === void 0 ? void 0 : category.length;
83
- }).length;
50
+ [...Array(alternatesPerChoice).keys()].forEach(index => {
51
+ const alternatesPerResponse = alternates.map(alternate => alternate[index]);
52
+ const filledCategories = alternatesPerResponse.filter(category => category?.length).length;
84
53
  possibleResponses.push(alternatesPerResponse.flat());
85
-
86
54
  if (filledCategories < responseAreasToBeFilled) {
87
55
  responseAreasToBeFilled = filledCategories;
88
56
  }
89
57
  });
90
- } // check if any correct answer have any unplaced answer choices
91
-
58
+ }
92
59
 
93
- var hasUnplacedChoices = possibleResponses.some(function (response) {
94
- return !allChoices.every(function (val) {
95
- return response.includes(val === null || val === void 0 ? void 0 : val.id);
96
- });
97
- });
60
+ // check if any correct answer have any unplaced answer choices
61
+ const hasUnplacedChoices = possibleResponses.some(response => !allChoices.every(val => response.includes(val?.id)));
98
62
  return {
99
- responseAreasToBeFilled: responseAreasToBeFilled,
100
- possibleResponses: possibleResponses,
101
- hasUnplacedChoices: hasUnplacedChoices
63
+ responseAreasToBeFilled,
64
+ possibleResponses,
65
+ hasUnplacedChoices
102
66
  };
103
67
  };
104
-
105
68
  exports.getCompleteResponseDetails = getCompleteResponseDetails;
106
69
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["multiplePlacements","enabled","disabled","perChoice","isCorrectResponseDuplicated","choices","alternate","length","stringChoices","JSON","stringify","sort","stringAlternate","reduce","total","current","foundIndexDuplicate","findIndex","isAlternateDuplicated","elementSet","Set","i","has","add","getCompleteResponseDetails","correctResponse","alternates","allChoices","choicesPerCategory","map","category","possibleResponses","flat","responseAreasToBeFilled","filter","alternatesPerChoice","Array","keys","forEach","index","alternatesPerResponse","filledCategories","push","hasUnplacedChoices","some","response","every","val","includes","id"],"mappings":";;;;;;;;;;;AAAA;AACO,IAAMA,kBAAkB,GAAG;AAAEC,EAAAA,OAAO,EAAE,KAAX;AAAkBC,EAAAA,QAAQ,EAAE,IAA5B;AAAkCC,EAAAA,SAAS,EAAE;AAA7C,CAA3B,C,CAEP;;;;AACO,IAAMC,2BAA2B,GAAG,SAA9BA,2BAA8B,CAACC,OAAD,EAAUC,SAAV,EAAwB;AACjE,MAAID,OAAO,CAACE,MAAR,GAAiB,CAAjB,IAAsBD,SAAS,CAACC,MAAV,GAAmB,CAA7C,EAAgD;AAC9C,WAAO,CAAC,CAAR;AACD;;AAED,MAAMC,aAAa,GAAGC,IAAI,CAACC,SAAL,CAAeL,O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iB,CAACa,IAAlB,CACzB,UAACC,QAAD;AAAA,WAAc,CAAClB,UAAU,CAACmB,KAAX,CAAiB,UAACC,GAAD;AAAA,aAASF,QAAQ,CAACG,QAAT,CAAkBD,GAAlB,aAAkBA,GAAlB,uBAAkBA,GAAG,CAAEE,EAAvB,CAAT;AAAA,KAAjB,CAAf;AAAA,GADyB,CAA3B;AAIA,SAAO;AAAEhB,IAAAA,uBAAuB,EAAvBA,uBAAF;AAA2BF,IAAAA,iBAAiB,EAAjBA,iBAA3B;AAA8CY,IAAAA,kBAAkB,EAAlBA;AAA9C,GAAP;AACD,CAzBM","sourcesContent":["// used in configure too, for consistency modify it there too\nexport const multiplePlacements = { enabled: 'Yes', disabled: 'No', perChoice: 'Set Per Choice' };\n\n// used to validate the config\nexport const isCorrectResponseDuplicated = (choices, alternate) => {\n if (choices.length < 1 || alternate.length < 1) {\n return -1;\n }\n\n const stringChoices = JSON.stringify(choices.sort());\n const stringAlternate = alternate.reduce(\n (total, current) => (current.length > 0 ? [...total, JSON.stringify(current.sort())] : total),\n [],\n );\n const foundIndexDuplicate = stringAlternate.findIndex((alternate) => alternate.length && alternate === stringChoices);\n\n return foundIndexDuplicate;\n};\n\nexport const isAlternateDuplicated = (alternate) => {\n if (alternate.length <= 1) {\n return -1;\n }\n\n const elementSet = new Set();\n const stringAlternate = alternate.reduce(\n (total, current) => (current.length > 0 ? [...total, JSON.stringify(current.sort())] : total),\n [],\n );\n\n for (let i = 0; i < stringAlternate.length; i++) {\n if (elementSet.has(stringAlternate[i]) && stringAlternate[i]) {\n return i;\n }\n\n elementSet.add(stringAlternate[i]);\n }\n\n return -1;\n};\n\n// calculate the minimum number of populated response areas (categories) in the correct answer or alternates\n// and create an array with the possible responses ids\nexport const getCompleteResponseDetails = (correctResponse, alternates, allChoices) => {\n const choicesPerCategory = correctResponse.map((category) => category.choices);\n const possibleResponses = [choicesPerCategory.flat()];\n let responseAreasToBeFilled = choicesPerCategory.filter((choices) => choices.length).length;\n\n if (alternates.length) {\n const alternatesPerChoice = alternates[0]?.length || 0; // number of alternates\n\n [...Array(alternatesPerChoice).keys()].forEach((index) => {\n const alternatesPerResponse = alternates.map((alternate) => alternate[index]);\n const filledCategories = alternatesPerResponse.filter((category) => category?.length).length;\n possibleResponses.push(alternatesPerResponse.flat());\n\n if (filledCategories < responseAreasToBeFilled) {\n responseAreasToBeFilled = filledCategories;\n }\n });\n }\n\n // check if any correct answer have any unplaced answer choices\n const hasUnplacedChoices = possibleResponses.some(\n (response) => !allChoices.every((val) => response.includes(val?.id)),\n );\n\n return { responseAreasToBeFilled, possibleResponses, hasUnplacedChoices };\n};\n"],"file":"utils.js"}
1
+ {"version":3,"file":"utils.js","names":["multiplePlacements","exports","enabled","disabled","perChoice","isCorrectResponseDuplicated","choices","alternate","length","stringChoices","JSON","stringify","sort","stringAlternate","reduce","total","current","foundIndexDuplicate","findIndex","isAlternateDuplicated","elementSet","Set","i","has","add","getCompleteResponseDetails","correctResponse","alternates","allChoices","choicesPerCategory","map","category","possibleResponses","flat","responseAreasToBeFilled","filter","alternatesPerChoice","Array","keys","forEach","index","alternatesPerResponse","filledCategories","push","hasUnplacedChoices","some","response","every","val","includes","id"],"sources":["../src/utils.js"],"sourcesContent":["// used in configure too, for consistency modify it there too\nexport const multiplePlacements = { enabled: 'Yes', disabled: 'No', perChoice: 'Set Per Choice' };\n\n// used to validate the config\nexport const isCorrectResponseDuplicated = (choices, alternate) => {\n if (choices.length < 1 || alternate.length < 1) {\n return -1;\n }\n\n const stringChoices = JSON.stringify(choices.sort());\n const stringAlternate = alternate.reduce(\n (total, current) => (current.length > 0 ? [...total, JSON.stringify(current.sort())] : total),\n [],\n );\n const foundIndexDuplicate = stringAlternate.findIndex((alternate) => alternate.length && alternate === stringChoices);\n\n return foundIndexDuplicate;\n};\n\nexport const isAlternateDuplicated = (alternate) => {\n if (alternate.length <= 1) {\n return -1;\n }\n\n const elementSet = new Set();\n const stringAlternate = alternate.reduce(\n (total, current) => (current.length > 0 ? [...total, JSON.stringify(current.sort())] : total),\n [],\n );\n\n for (let i = 0; i < stringAlternate.length; i++) {\n if (elementSet.has(stringAlternate[i]) && stringAlternate[i]) {\n return i;\n }\n\n elementSet.add(stringAlternate[i]);\n }\n\n return -1;\n};\n\n// calculate the minimum number of populated response areas (categories) in the correct answer or alternates\n// and create an array with the possible responses ids\nexport const getCompleteResponseDetails = (correctResponse, alternates, allChoices) => {\n const choicesPerCategory = correctResponse.map((category) => category.choices);\n const possibleResponses = [choicesPerCategory.flat()];\n let responseAreasToBeFilled = choicesPerCategory.filter((choices) => choices.length).length;\n\n if (alternates.length) {\n const alternatesPerChoice = alternates[0]?.length || 0; // number of alternates\n\n [...Array(alternatesPerChoice).keys()].forEach((index) => {\n const alternatesPerResponse = alternates.map((alternate) => alternate[index]);\n const filledCategories = alternatesPerResponse.filter((category) => category?.length).length;\n possibleResponses.push(alternatesPerResponse.flat());\n\n if (filledCategories < responseAreasToBeFilled) {\n responseAreasToBeFilled = filledCategories;\n }\n });\n }\n\n // check if any correct answer have any unplaced answer choices\n const hasUnplacedChoices = possibleResponses.some(\n (response) => !allChoices.every((val) => response.includes(val?.id)),\n );\n\n return { responseAreasToBeFilled, possibleResponses, hasUnplacedChoices };\n};\n"],"mappings":";;;;;;AAAA;AACO,MAAMA,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAG;EAAEE,OAAO,EAAE,KAAK;EAAEC,QAAQ,EAAE,IAAI;EAAEC,SAAS,EAAE;AAAiB,CAAC;;AAEjG;AACO,MAAMC,2BAA2B,GAAGA,CAACC,OAAO,EAAEC,SAAS,KAAK;EACjE,IAAID,OAAO,CAACE,MAAM,GAAG,CAAC,IAAID,SAAS,CAACC,MAAM,GAAG,CAAC,EAAE;IAC9C,OAAO,CAAC,CAAC;EACX;EAEA,MAAMC,aAAa,GAAGC,IAAI,CAACC,SAAS,CAACL,OAAO,CAACM,IAAI,CAAC,CAAC,CAAC;EACpD,MAAMC,eAAe,GAAGN,SAAS,C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C,OAAA,CAAAwB,0BAAA,GAAAA,0BAAA","ignoreList":[]}
@@ -2,13 +2,13 @@
2
2
  "name": "@pie-element/categorize-controller",
3
3
  "private": true,
4
4
  "dependencies": {
5
- "@pie-lib/categorize": "0.28.1",
6
- "@pie-lib/controller-utils": "0.22.2",
7
- "@pie-lib/feedback": "0.24.1",
8
- "@pie-lib/translator": "2.23.1",
5
+ "@pie-lib/categorize": "0.28.3-next.0",
6
+ "@pie-lib/controller-utils": "0.22.4-next.0",
7
+ "@pie-lib/feedback": "0.24.3-next.0",
8
+ "@pie-lib/translator": "2.23.3-next.0",
9
9
  "lodash": "^4.17.15"
10
10
  },
11
- "version": "8.3.3",
11
+ "version": "9.0.0-beta.0",
12
12
  "description": "",
13
13
  "scripts": {},
14
14
  "main": "lib/index.js",
@@ -1,193 +1,135 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
4
  Object.defineProperty(exports, "__esModule", {
8
5
  value: true
9
6
  });
10
7
  exports.Categories = void 0;
11
8
  Object.defineProperty(exports, "CategoryType", {
12
9
  enumerable: true,
13
- get: function get() {
10
+ get: function () {
14
11
  return _category.CategoryType;
15
12
  }
16
13
  });
17
- exports["default"] = void 0;
18
-
14
+ exports.default = void 0;
19
15
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
20
-
21
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
22
-
23
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
24
-
25
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
26
-
27
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
28
-
29
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
30
-
31
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
32
-
33
17
  var _react = _interopRequireDefault(require("react"));
34
-
35
18
  var _propTypes = _interopRequireDefault(require("prop-types"));
36
-
37
- var _styles = require("@material-ui/core/styles");
38
-
19
+ var _styles = require("@mui/material/styles");
39
20
  var _renderUi = require("@pie-lib/render-ui");
40
-
41
21
  var _gridContent = _interopRequireDefault(require("./grid-content"));
42
-
43
22
  var _category = _interopRequireWildcard(require("./category"));
44
-
45
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
46
-
47
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
48
-
49
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
50
-
51
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
52
-
53
- var Categories = /*#__PURE__*/function (_React$Component) {
54
- (0, _inherits2["default"])(Categories, _React$Component);
55
-
56
- var _super = _createSuper(Categories);
57
-
58
- function Categories() {
59
- (0, _classCallCheck2["default"])(this, Categories);
60
- return _super.apply(this, arguments);
61
- }
62
-
63
- (0, _createClass2["default"])(Categories, [{
64
- key: "render",
65
- value: function render() {
66
- var _this$props = this.props,
67
- classes = _this$props.classes,
68
- categories = _this$props.categories,
69
- model = _this$props.model,
70
- disabled = _this$props.disabled,
71
- _onDropChoice = _this$props.onDropChoice,
72
- onRemoveChoice = _this$props.onRemoveChoice,
73
- rowLabels = _this$props.rowLabels;
74
- var categoriesPerRow = model.categoriesPerRow,
75
- minRowHeight = model.minRowHeight; // split categories into an array of arrays (inner array),
76
- // where each inner array represents how many categories should be displayed on one row
77
-
78
- var chunkedCategories = [];
79
- var cats = categories || [];
80
-
81
- for (var i = 0; i < cats.length; i += categoriesPerRow) {
82
- chunkedCategories.push(cats.slice(i, i + categoriesPerRow));
23
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
24
+ class Categories extends _react.default.Component {
25
+ render() {
26
+ const {
27
+ categories,
28
+ model,
29
+ disabled,
30
+ onDropChoice,
31
+ onRemoveChoice,
32
+ rowLabels
33
+ } = this.props;
34
+ const {
35
+ categoriesPerRow,
36
+ minRowHeight
37
+ } = model;
38
+
39
+ // split categories into an array of arrays (inner array),
40
+ // where each inner array represents how many categories should be displayed on one row
41
+ const chunkedCategories = [];
42
+ const cats = categories || [];
43
+ for (let i = 0; i < cats.length; i += categoriesPerRow) {
44
+ chunkedCategories.push(cats.slice(i, i + categoriesPerRow));
45
+ }
46
+ const hasNonEmptyString = array => {
47
+ let found = false;
48
+ (array || []).forEach(element => {
49
+ if (typeof element === 'string' && element.trim() !== '' && element.trim() !== '<div></div>') {
50
+ found = true;
51
+ }
52
+ });
53
+ return found;
54
+ };
55
+ return /*#__PURE__*/_react.default.createElement(_gridContent.default, {
56
+ columns: categoriesPerRow,
57
+ rows: Math.ceil(categories.length / categoriesPerRow) * 2,
58
+ extraStyle: {
59
+ flex: 1
83
60
  }
84
-
85
- var hasNonEmptyString = function hasNonEmptyString(array) {
86
- var found = false;
87
- (array || []).forEach(function (element) {
88
- if (typeof element === 'string' && element.trim() !== '' && element.trim() !== '<div></div>') {
89
- found = true;
61
+ }, chunkedCategories.map((cat, rowIndex) => {
62
+ let items = [];
63
+
64
+ // for each inner array of categories, create a row with category titles
65
+ // first cell of row has to be the row label
66
+ cat.forEach((c, columnIndex) => {
67
+ items.push(/*#__PURE__*/_react.default.createElement("div", {
68
+ style: {
69
+ display: 'flex'
90
70
  }
91
- });
92
- return found;
93
- };
94
-
95
- return /*#__PURE__*/_react["default"].createElement(_gridContent["default"], {
96
- columns: categoriesPerRow,
97
- className: classes.categories,
98
- rows: Math.ceil(categories.length / categoriesPerRow) * 2
99
- }, chunkedCategories.map(function (cat, rowIndex) {
100
- var items = []; // for each inner array of categories, create a row with category titles
101
- // first cell of row has to be the row label
102
-
103
- cat.forEach(function (c, columnIndex) {
104
- items.push( /*#__PURE__*/_react["default"].createElement("div", {
105
- style: {
106
- display: 'flex'
107
- }
108
- }, columnIndex === 0 && hasNonEmptyString(rowLabels) ? /*#__PURE__*/_react["default"].createElement("div", {
109
- key: rowIndex,
110
- className: classes.rowLabel,
111
- dangerouslySetInnerHTML: {
112
- __html: rowLabels[rowIndex] || ''
113
- }
114
- }) : null, /*#__PURE__*/_react["default"].createElement("div", {
115
- className: classes.categoryWrapper
116
- }, /*#__PURE__*/_react["default"].createElement("div", {
117
- className: classes.label,
118
- key: "category-label-".concat(rowIndex, "-").concat(columnIndex),
119
- dangerouslySetInnerHTML: {
120
- __html: c.label
121
- }
122
- }), /*#__PURE__*/_react["default"].createElement(_category["default"], (0, _extends2["default"])({
123
- minRowHeight: minRowHeight,
124
- onDropChoice: function onDropChoice(h) {
125
- return _onDropChoice(c.id, h);
126
- },
127
- onRemoveChoice: onRemoveChoice,
128
- disabled: disabled,
129
- className: classes.category,
130
- key: "category-element-".concat(rowIndex, "-").concat(columnIndex)
131
- }, c)))));
132
- }); // if the last row has fewer categories than max on a row, fill the spaces with divs
133
-
134
- items = items.concat(Array(categoriesPerRow - cat.length).fill( /*#__PURE__*/_react["default"].createElement("div", null)).map(function (value, index) {
135
- return /*#__PURE__*/_react["default"].createElement("div", {
136
- key: "fill-space-final-".concat(index)
137
- });
138
- }));
139
- return items;
140
- }));
141
- }
142
- }]);
143
- return Categories;
144
- }(_react["default"].Component);
145
-
71
+ }, columnIndex === 0 && hasNonEmptyString(rowLabels) ? /*#__PURE__*/_react.default.createElement(StyledRowLabel, {
72
+ key: rowIndex,
73
+ dangerouslySetInnerHTML: {
74
+ __html: rowLabels[rowIndex] || ''
75
+ }
76
+ }) : null, /*#__PURE__*/_react.default.createElement(StyledCategoryWrapper, null, /*#__PURE__*/_react.default.createElement(StyledLabel, {
77
+ key: `category-label-${rowIndex}-${columnIndex}`,
78
+ dangerouslySetInnerHTML: {
79
+ __html: c.label
80
+ }
81
+ }), /*#__PURE__*/_react.default.createElement(_category.default, (0, _extends2.default)({
82
+ minRowHeight: minRowHeight,
83
+ onDropChoice: h => onDropChoice(c.id, h),
84
+ onRemoveChoice: onRemoveChoice,
85
+ disabled: disabled,
86
+ key: `category-element-${rowIndex}-${columnIndex}`
87
+ }, c)))));
88
+ });
89
+
90
+ // if the last row has fewer categories than max on a row, fill the spaces with divs
91
+ items = items.concat(Array(categoriesPerRow - cat.length).fill(/*#__PURE__*/_react.default.createElement("div", null)).map((value, index) => /*#__PURE__*/_react.default.createElement("div", {
92
+ key: `fill-space-final-${index}`
93
+ })));
94
+ return items;
95
+ }));
96
+ }
97
+ }
146
98
  exports.Categories = Categories;
147
- (0, _defineProperty2["default"])(Categories, "propTypes", {
148
- classes: _propTypes["default"].object.isRequired,
149
- categories: _propTypes["default"].arrayOf(_propTypes["default"].shape(_category.CategoryType)),
150
- model: _propTypes["default"].shape({
151
- categoriesPerRow: _propTypes["default"].number
99
+ (0, _defineProperty2.default)(Categories, "propTypes", {
100
+ categories: _propTypes.default.arrayOf(_propTypes.default.shape(_category.CategoryType)),
101
+ model: _propTypes.default.shape({
102
+ categoriesPerRow: _propTypes.default.number
152
103
  }),
153
- disabled: _propTypes["default"].bool,
154
- onDropChoice: _propTypes["default"].func.isRequired,
155
- onRemoveChoice: _propTypes["default"].func.isRequired,
156
- rowLabels: _propTypes["default"].array
104
+ disabled: _propTypes.default.bool,
105
+ onDropChoice: _propTypes.default.func.isRequired,
106
+ onRemoveChoice: _propTypes.default.func.isRequired,
107
+ rowLabels: _propTypes.default.array
157
108
  });
158
- (0, _defineProperty2["default"])(Categories, "defaultProps", {
109
+ (0, _defineProperty2.default)(Categories, "defaultProps", {
159
110
  model: {
160
111
  categoriesPerRow: 1
161
112
  }
162
113
  });
163
-
164
- var styles = function styles(theme) {
165
- return {
166
- categories: {
167
- flex: 1
168
- },
169
- label: {
170
- color: _renderUi.color.text(),
171
- backgroundColor: _renderUi.color.background(),
172
- textAlign: 'center',
173
- paddingTop: theme.spacing.unit
174
- },
175
- rowLabel: {
176
- alignItems: 'center',
177
- display: 'flex',
178
- justifyContent: 'center',
179
- flex: 0.5,
180
- marginRight: '12px'
181
- },
182
- categoryWrapper: {
183
- display: 'flex',
184
- flex: '2',
185
- flexDirection: 'column'
186
- }
187
- };
188
- };
189
-
190
- var _default = (0, _styles.withStyles)(styles)(Categories);
191
-
192
- exports["default"] = _default;
114
+ const StyledLabel = (0, _styles.styled)('div')(({
115
+ theme
116
+ }) => ({
117
+ color: _renderUi.color.text(),
118
+ backgroundColor: _renderUi.color.background(),
119
+ textAlign: 'center',
120
+ paddingTop: theme.spacing(1)
121
+ }));
122
+ const StyledRowLabel = (0, _styles.styled)('div')({
123
+ alignItems: 'center',
124
+ display: 'flex',
125
+ justifyContent: 'center',
126
+ flex: 0.5,
127
+ marginRight: '12px'
128
+ });
129
+ const StyledCategoryWrapper = (0, _styles.styled)('div')({
130
+ display: 'flex',
131
+ flex: '2',
132
+ flexDirection: 'column'
133
+ });
134
+ var _default = exports.default = Categories;
193
135
  //# sourceMappingURL=categories.js.map