@pie-element/math-inline 5.6.0 → 5.6.1-beta.587
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +509 -0
- package/configure/CHANGELOG.md +471 -0
- package/configure/lib/configure.js +73 -31
- package/configure/lib/configure.js.map +1 -1
- package/configure/lib/defaults.js +37 -2
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/general-config-block.js +123 -29
- package/configure/lib/general-config-block.js.map +1 -1
- package/configure/lib/index.js +31 -3
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/response.js +90 -37
- package/configure/lib/response.js.map +1 -1
- package/configure/lib/utils.js +18 -1
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +7 -8
- package/controller/CHANGELOG.md +145 -0
- package/controller/lib/defaults.js +2 -1
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +148 -131
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +4 -4
- package/docs/config-schema.json +168 -0
- package/docs/config-schema.json.md +132 -1
- package/docs/demo/config.js +2 -2
- package/docs/demo/generate.js +20 -16
- package/docs/demo/session.js +1 -1
- package/docs/pie-schema.json +128 -3
- package/docs/pie-schema.json.md +107 -3
- package/lib/index.js +7 -4
- package/lib/index.js.map +1 -1
- package/lib/main.js +230 -55
- package/lib/main.js.map +1 -1
- package/lib/print.js +133 -0
- package/lib/print.js.map +1 -0
- package/lib/simple-question-block.js +50 -38
- package/lib/simple-question-block.js.map +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +13 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["log","decimalRegex","decimalCommaRegex","textRegex","decimalWithThousandSeparatorNumberRegex","noNumbers","processAnswerItem","answerItem","isLiteral","newAnswerItem","replace","containsDecimal","validExpressionWithThousandSeparator","stripForStringCompare","expression","match","getResponseCorrectness","model","isOutcome","correctResponses","responses","isAdvanced","responseType","ResponseTypes","advanced","correctness","score","correct","isAnswerCorrect","getIsAnswerCorrect","slice","correctnessObject","stripTargets","answer","numericValues","split","i","length","test","stripped","forEach","stripTarget","handleStringBasedCheck","acceptedValues","answerValueToUse","answerCorrect","acceptedValueToUse","correctResponseItem","correctResponse","concat","Object","keys","alternates","map","alternateId","validation","isLatex","allowThousandsSeparator","e","getCorrectness","question","env","session","mode","completeAnswer","response","createDefaultModel","Promise","resolve","config","defaults","outcome","undefined","completed","empty","normalize","feedbackEnabled","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","simple","fb","feedback","then","base","disabled","view","out","assign","role","rationale","teacherInstructions","prompt","escape","string","simpleSessionResponse","id","advancedSessionResponse","reject","RESPONSE_TOKEN","o","to","t","tt","join","m","RegExp","count","answers","console","shift","value","trim","error","toString","createCorrectResponseSession","toLowerCase"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,qCAAN,CAAZ;AACA,IAAMC,YAAY,GAAG,OAArB;AACA,IAAMC,iBAAiB,GAAG,IAA1B;AACA,IAAMC,SAAS,GAAG,qBAAlB;AACA,IAAMC,uCAAuC,GAAG,iEAAhD;AACA,IAAMC,SAAS,GAAG,YAAlB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASC,iBAAT,GAAuD;AAAA,MAA5BC,UAA4B,uEAAf,EAAe;AAAA,MAAXC,SAAW;AACrD;AACA;AACA,MAAIC,aAAa,GAAGF,UAAU,CAACG,OAAX,CAAmB,GAAnB,EAAwB,GAAxB,CAApB;AAEAD,EAAAA,aAAa,GAAGA,aAAa,CAACC,OAAd,CAAsB,SAAtB,EAAiC,SAAjC,CAAhB,CALqD,CAOrD;;AAEAD,EAAAA,aAAa,GAAGA,aAAa,CAACC,OAAd,CAAsBP,SAAtB,EAAi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AAJ,KAAa,UAAb,IAA2BF,GAAG,CAAC8B,IAAJ,KAAa,YAA5C,EAA0D;AACxD;AACAoB,IAAAA,OAAO,CAACI,KAAR,CACE,uFADF;AAIA,WAAOhD,OAAO,CAACC,OAAR,CAAgB,IAAhB,CAAP;AACD;;AAED,MAAI,CAACR,QAAQ,CAACtC,YAAT,IAAyB,EAA1B,EAA8BgG,WAA9B,OAAgD,QAApD,EAA8D;AAC5D,WAAOrB,qBAAqB,CAACrC,QAAD,EAAWC,GAAX,CAA5B;AACD,GAFD,MAEO;AACL,WAAOsC,uBAAuB,CAACvC,QAAD,EAAWC,GAAX,CAA9B;AACD;AACF,CAfM","sourcesContent":["import debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport areValuesEqual from '@pie-lib/math-evaluator';\nimport { ResponseTypes } from './utils';\n\nimport defaults from './defaults';\n\nconst log = debug('@pie-element:math-inline:controller');\nconst decimalRegex = /\\.|,/g;\nconst decimalCommaRegex = /,/g;\nconst textRegex = /\\\\text\\{([^{}]+)\\}/g;\nconst decimalWithThousandSeparatorNumberRegex = /^(?!0+\\.00)(?=.{1,9}(\\.|$))(?!0(?!\\.))\\d{1,3}(,\\d{3})*(\\.\\d+)?$/;\nconst noNumbers = /[^0-9.,]+/g;\n\n/**\n * TODO:\n *\n * We have `stringCheck` which if true disabled 'literal' and 'symbolic' so really it should be a validation method. And if it is what's the difference between it and 'literal'?\n *\n * We should support a equivalence option per correct response like:\n * responses: [ { answer: '..', validation: 'symbolic', alternates: [{ value: '..', validation: 'stringCompare'}, 'abc'] } ]\n *\n * if option is a string it is turned into an object w/ inherited opts.\n *\n * This would override any shared setting at the root.\n */\n\nfunction processAnswerItem(answerItem = '', isLiteral) {\n // looks confusing, but we're replacing U+002D and U+2212 (minus and hyphen) so we have the same symbol everywhere consistently\n // further processing is to be added here if needed\n let newAnswerItem = answerItem.replace('−', '-');\n\n newAnswerItem = newAnswerItem.replace(/\\\\cdot/g, '\\\\times');\n\n // also ignore text nodes, just swap out with empty string\n\n newAnswerItem = newAnswerItem.replace(textRegex, '');\n if (\n containsDecimal(newAnswerItem) && validExpressionWithThousandSeparator(newAnswerItem)\n ) {\n newAnswerItem = newAnswerItem.replace(decimalCommaRegex, '');\n }\n\n newAnswerItem = newAnswerItem.replace(/\\\\ /g, '').replace(/ /g, '');\n\n // eslint-disable-next-line no-useless-escape\n newAnswerItem = newAnswerItem\n .replace(/\\\\%/g, '')\n .replace(/%/g, '');\n\n return isLiteral ? stripForStringCompare(newAnswerItem) : newAnswerItem;\n}\n\nfunction containsDecimal(expression = '') {\n return expression.match(decimalRegex);\n}\n\nconst getResponseCorrectness = (model, answerItem, isOutcome) => {\n const correctResponses = model.responses;\n const isAdvanced = model.responseType === ResponseTypes.advanced;\n\n if (!answerItem) {\n return {\n correctness: 'unanswered',\n score: isOutcome ? 0 : '0%',\n correct: false\n };\n }\n\n const isAnswerCorrect = getIsAnswerCorrect(\n isAdvanced ? correctResponses : correctResponses.slice(0, 1),\n answerItem\n );\n const correctnessObject = {\n correctness: 'incorrect',\n score: isOutcome ? 0 : '0%',\n correct: false\n };\n\n if (isAnswerCorrect) {\n correctnessObject.correctness = 'correct';\n correctnessObject.score = isOutcome ? 1 : '100%';\n correctnessObject.correct = true;\n }\n\n return correctnessObject;\n};\n\nconst stripTargets = [\n /{/g,\n /}/g,\n /\\[/g,\n /]/g,\n /\\\\ /g,\n /\\\\/g,\n /\\\\s/g,\n /left/g,\n /right/g,\n / /g\n];\n\nconst validExpressionWithThousandSeparator = (answer) => {\n const numericValues = answer.split(noNumbers);\n\n for (let i = 0; i < numericValues.length; i++) {\n if (numericValues[i] != '' && containsDecimal(numericValues[i]) && !decimalWithThousandSeparatorNumberRegex.test(numericValues[i])) {\n\n return false;\n }\n }\n\n return true\n}\n\nfunction stripForStringCompare(answer = '') {\n let stripped = answer;\n\n stripTargets.forEach(stripTarget => {\n return (stripped = stripped.replace(stripTarget, ''));\n });\n\n return stripped;\n}\n\nfunction handleStringBasedCheck(acceptedValues, answerItem) {\n let answerValueToUse = processAnswerItem(answerItem, true);\n let answerCorrect = false;\n\n for (let i = 0; i < acceptedValues.length; i++) {\n let acceptedValueToUse = processAnswerItem(acceptedValues[i], true);\n\n answerCorrect = answerValueToUse === acceptedValueToUse;\n\n if (answerCorrect === true) {\n break;\n }\n }\n\n return answerCorrect;\n}\n\nfunction getIsAnswerCorrect(correctResponseItem, answerItem) {\n let answerCorrect = false;\n\n correctResponseItem.forEach(correctResponse => {\n // if not already deemed correct for one of the correct responses\n if (!answerCorrect) {\n const acceptedValues = [correctResponse.answer].concat(\n Object.keys(correctResponse.alternates || {}).map(\n alternateId => correctResponse.alternates[alternateId]\n )\n );\n\n if (correctResponse.validation === 'literal') {\n for (let i = 0; i < acceptedValues.length; i++) {\n let answerValueToUse = processAnswerItem(answerItem, true);\n let acceptedValueToUse = processAnswerItem(acceptedValues[i], true);\n\n if (acceptedValueToUse === answerValueToUse) {\n answerCorrect = true;\n break;\n }\n }\n } else {\n try {\n for (let i = 0; i < acceptedValues.length; i++) {\n // let answerValueToUse = processAnswerItem(answerItem);\n // let acceptedValueToUse = processAnswerItem(acceptedValues[i]);\n\n answerCorrect = areValuesEqual(\n processAnswerItem(acceptedValues[i]),\n processAnswerItem(answerItem),\n {\n isLatex: true,\n allowThousandsSeparator: correctResponse.allowThousandsSeparator\n }\n );\n if (answerCorrect) {\n break;\n }\n }\n } catch (e) {\n log(\n 'Parse failure when evaluating math',\n e,\n correctResponse,\n answerItem\n );\n // try to string check compare, last resort?\n // once invalid models have been weeded out, this'll get removed.\n answerCorrect = handleStringBasedCheck(acceptedValues, answerItem);\n }\n }\n }\n });\n\n return answerCorrect;\n}\n\nconst getCorrectness = (question, env, session, isOutcome) => {\n if (env.mode === 'evaluate') {\n return getResponseCorrectness(\n question,\n question.responseType === ResponseTypes.advanced\n ? (session && session.completeAnswer) || ''\n : session && session.response,\n isOutcome\n );\n }\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => {\n resolve({\n config: {\n ...defaults,\n ...model\n }\n });\n });\n}\n\nexport const outcome = (question, session, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined });\n } else {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n } else {\n const correctness = getCorrectness(question, env, session, true);\n\n resolve({ score: correctness.score });\n }\n }\n });\n};\n\nexport const normalize = question => ({\n feedbackEnabled: true,\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question\n});\n\nexport function model(question, session, env) {\n return new Promise(resolve => {\n const normalizedQuestion = normalize(question);\n const correctness = getCorrectness(normalizedQuestion, env, session);\n const correctResponse = {};\n const { responses, ...config } = normalizedQuestion;\n\n if (config.responseType === ResponseTypes.simple) {\n config.responses = responses.slice(0, 1);\n } else {\n config.responses = responses;\n }\n\n const fb =\n env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then(feedback => {\n const base = {\n config,\n correctness,\n feedback,\n disabled: env.mode !== 'gather',\n view: env.mode === 'view'\n };\n\n let out;\n\n if (env.mode === 'evaluate') {\n out = Object.assign(base, {\n correctResponse\n });\n } else {\n out = base;\n\n out.config.responses = [];\n }\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n out.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n out.config.rationale = null;\n out.config.teacherInstructions = null;\n }\n\n out.config.prompt = normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null;\n\n log('out: ', out);\n resolve(out);\n });\n });\n}\n\nconst escape = string => string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'); // $& means the whole matched string\n\nconst simpleSessionResponse = question =>\n new Promise(resolve => {\n const { responses } = question;\n const { answer } = responses ? responses[0] : {};\n resolve({\n id: question.id,\n response: answer,\n completeAnswer: answer\n });\n });\n\nconst advancedSessionResponse = question =>\n new Promise((resolve, reject) => {\n const { responses } = question;\n const { answer } = responses ? responses[0] : {};\n\n try {\n const e = question.expression;\n const RESPONSE_TOKEN = /\\\\{\\\\{\\s*response\\s*\\\\}\\\\}/g;\n\n const o = escape(e).split(RESPONSE_TOKEN);\n const to = o.map(t => (t === '' ? t : t.replace(/\\s+/g, () => ('\\\\s*'))));\n const tt = to.join('(.*)');\n\n const m = answer.match(new RegExp(tt));\n\n const count = o.length - 1;\n\n if (!m) {\n resolve({\n answers: {},\n completeAnswer: answer,\n id: question.id\n });\n\n console.log(`can not find match: ${o} in ${answer}`);\n\n return;\n }\n\n m.shift();\n\n const answers = {};\n\n for (var i = 0; i < count; i++) {\n answers[`r${i + 1}`] = { value: m[i].trim() };\n }\n\n resolve({\n answers,\n completeAnswer: answer,\n id: question.id\n });\n } catch (e) {\n resolve({\n answers: {},\n completeAnswer: answer,\n id: question.id\n });\n\n console.error(e.toString());\n }\n });\n\n\nexport const createCorrectResponseSession = (question, env) => {\n if (env.mode === 'evaluate' || env.role !== 'instructor') {\n // eslint-disable-next-line no-console\n console.error(\n 'can not create correct response session if mode is evaluate or role is not instructor'\n );\n\n return Promise.resolve(null);\n }\n\n if ((question.responseType || '').toLowerCase() === 'simple') {\n return simpleSessionResponse(question, env);\n } else {\n return advancedSessionResponse(question, env);\n }\n};\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["log","getResponseCorrectness","model","answerItem","isOutcome","correctResponses","responses","isAdvanced","responseType","ResponseTypes","advanced","correctness","score","correct","isAnswerCorrect","getIsAnswerCorrect","slice","correctnessObject","correctResponseItem","answerCorrect","forEach","correctResponse","opts","mode","validation","defaults","validationDefault","literal","allowTrailingZeros","ignoreOrder","acceptedValues","answer","concat","Object","keys","alternates","map","alternateId","i","length","mv","latexEqual","e","getCorrectness","question","env","session","completeAnswer","response","createDefaultModel","Promise","resolve","config","outcome","undefined","completed","empty","normalize","allowTrailingZerosDefault","ignoreOrderDefault","feedbackEnabled","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","simple","customKeys","fb","feedback","then","base","disabled","view","out","showNote","role","rationale","teacherInstructions","prompt","escape","string","replace","simpleSessionResponse","id","advancedSessionResponse","reject","answers","expression","RESPONSE_TOKEN","o","split","to","t","tt","join","m","match","RegExp","count","console","shift","value","trim","error","toString","createCorrectResponseSession","toLowerCase","validate","maxResponseAreas","responsesErrors","index","reversedAlternates","entries","reverse","alternatesErrors","responseError","key","identicalAnswer","some","val","errors","nbOfResponseAreas","responseAreasError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,qCAAN,CAAZ;;AAEA,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,CAACC,KAAD,EAAQC,UAAR,EAAoBC,SAApB,EAAkC;AAC/D,MAAMC,gBAAgB,GAAGH,KAAK,CAACI,SAA/B;AACA,MAAMC,UAAU,GAAGL,KAAK,CAACM,YAAN,KAAuBC,qBAAcC,QAAxD;;AAEA,MAAI,CAACP,UAAL,EAAiB;AACf,WAAO;AACLQ,MAAAA,WAAW,EAAE,YADR;AAELC,MAAAA,KAAK,EAAER,SAAS,GAAG,CAAH,GAAO,IAFlB;AAGLS,MAAAA,OAAO,EAAE;AAHJ,KAAP;AAKD;;AAED,MAAMC,eAAe,GAAGC,kBAAkB,CAACR,UAAU,GAAGF,gBAAH,GAAsBA,gBAAgB,CAACW,KAAjB,CAAuB,CAAvB,EAA0B,CAA1B,CAAjC,EAA+Db,UAA/D,CAA1C;AAEA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,IAApC,CAAyC;AAAA;AAAA,cAAIC,GAAJ;;AAAA,iBAAaA,GAAG,KAAKlB,KAArB;AAAA,SAAzC,CADtB;;AAGA,YAAIgB,eAAJ,EAAqB;AACnBH,UAAAA,gBAAgB,CAACE,GAAD,CAAhB,GAAwB,2BAAxB;AACD;AACF;AACF,KAXD;;AAaA,QAAI,CAAC,yBAAQD,aAAR,CAAD,IAA2B,CAAC,yBAAQD,gBAAR,CAAhC,EAA2D;AACzDL,MAAAA,eAAe,CAACC,KAAD,CAAf,mCAA8BK,aAA9B,GAAgDD,gBAAhD;AACD;AACF,GA1BD;AA4BA,MAAMM,MAAM,GAAG,EAAf;;AAEA,MAAIjH,YAAY,KAAK,gBAArB,EAAuC;AACrC,QAAMkH,iBAAiB,GAAG,CAAClC,UAAU,CAACS,KAAX,CAAiB,mBAAjB,KAAyC,EAA1C,EAA8C1D,MAAxE;;AAEA,QAAImF,iBAAiB,GAAGb,gBAAxB,EAA0C;AACxCY,MAAAA,MAAM,CAACE,kBAAP,0BAA4Cd,gBAA5C;AACD,KAFD,MAEO,IAAIa,iBAAiB,GAAG,CAAxB,EAA2B;AAChCD,MAAAA,MAAM,CAACE,kBAAP,GAA4B,mDAA5B;AACD;AACF;;AAED,MAAI,CAAC,yBAAQb,eAAR,CAAL,EAA+B;AAC7BW,IAAAA,MAAM,CAACX,eAAP,GAAyBA,eAAzB;AACD;;AAED,SAAOW,MAAP;AACD,CAlDM","sourcesContent":["import debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { ResponseTypes } from './utils';\n\nimport defaults from './defaults';\n\nimport * as mv from '@pie-framework/math-validation';\n\nconst log = debug('@pie-element:math-inline:controller');\n\nconst getResponseCorrectness = (model, answerItem, isOutcome) => {\n const correctResponses = model.responses;\n const isAdvanced = model.responseType === ResponseTypes.advanced;\n\n if (!answerItem) {\n return {\n correctness: 'unanswered',\n score: isOutcome ? 0 : '0%',\n correct: false,\n };\n }\n\n const isAnswerCorrect = getIsAnswerCorrect(isAdvanced ? correctResponses : correctResponses.slice(0, 1), answerItem);\n\n const correctnessObject = {\n correctness: 'incorrect',\n score: isOutcome ? 0 : '0%',\n correct: false,\n };\n\n if (isAnswerCorrect) {\n correctnessObject.correctness = 'correct';\n correctnessObject.score = isOutcome ? 1 : '100%';\n correctnessObject.correct = true;\n }\n\n return correctnessObject;\n};\n\nfunction getIsAnswerCorrect(correctResponseItem, answerItem) {\n let answerCorrect = false;\n\n (correctResponseItem || []).forEach((correctResponse) => {\n let opts = {\n mode: correctResponse.validation || defaults.validationDefault,\n };\n\n if (opts.mode == 'literal') {\n opts.literal = {\n allowTrailingZeros: correctResponse.allowTrailingZeros || false,\n ignoreOrder: correctResponse.ignoreOrder || false,\n };\n }\n\n if (!answerCorrect) {\n const acceptedValues =\n [correctResponse.answer].concat(\n Object.keys(correctResponse.alternates || {}).map((alternateId) => correctResponse.alternates[alternateId]),\n ) || [];\n\n try {\n for (let i = 0; i < acceptedValues.length; i++) {\n answerCorrect = mv.latexEqual(answerItem, acceptedValues[i], opts);\n\n if (answerCorrect) {\n break;\n }\n }\n } catch (e) {\n log('Parse failure when evaluating math', e, correctResponse, answerItem);\n\n answerCorrect = false;\n }\n }\n });\n\n return answerCorrect;\n}\n\nconst getCorrectness = (question, env, session, isOutcome) => {\n if (env.mode === 'evaluate') {\n return getResponseCorrectness(\n question,\n question.responseType === ResponseTypes.advanced\n ? (session && session.completeAnswer) || ''\n : session && session.response,\n isOutcome,\n );\n }\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({\n config: {\n ...defaults,\n ...model,\n },\n });\n });\n}\n\nexport const outcome = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined });\n } else {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n } else {\n const correctness = getCorrectness(question, env, session, true);\n\n resolve({ score: correctness.score });\n }\n }\n });\n};\n\nexport const normalize = (question) => {\n // making sure that defaults are set\n if (!isEmpty(question.responses)) {\n question.responses = question.responses.map((correctResponse) => ({\n ...correctResponse,\n validation: correctResponse.validation || question.validationDefault,\n allowTrailingZeros: correctResponse.allowTrailingZeros || question.allowTrailingZerosDefault,\n ignoreOrder: correctResponse.ignoreOrder || question.ignoreOrderDefault,\n }));\n }\n\n return {\n ...defaults,\n feedbackEnabled: true,\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n };\n};\n\nexport function model(question, session, env) {\n return new Promise((resolve) => {\n const normalizedQuestion = normalize(question);\n const correctness = getCorrectness(normalizedQuestion, env, session);\n const { responses, ...config } = normalizedQuestion;\n\n if (config.responseType === ResponseTypes.simple) {\n config.responses = responses.slice(0, 1);\n } else {\n config.responses = responses;\n config.customKeys = [];\n }\n\n const fb =\n env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then((feedback) => {\n const base = {\n config,\n correctness,\n feedback,\n disabled: env.mode !== 'gather',\n view: env.mode === 'view',\n };\n\n const out = base;\n let showNote = false;\n\n ((config && config.responses) || []).forEach((response) => {\n if (response.validation === 'symbolic' || Object.keys(response.alternates || {}).length > 0) {\n showNote = true;\n return;\n }\n });\n\n if (env.mode === 'evaluate') {\n out.correctResponse = {};\n out.config.showNote = showNote;\n } else {\n out.config.responses = [];\n out.config.showNote = false;\n }\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n out.config.rationale = null;\n out.config.teacherInstructions = null;\n }\n\n out.config.env = env;\n out.config.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;\n\n log('out: ', out);\n resolve(out);\n });\n });\n}\n\nconst escape = (string) => string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'); // $& means the whole matched string\n\nconst simpleSessionResponse = (question) =>\n new Promise((resolve) => {\n const { responses, id } = question;\n const { answer } = responses && responses.length ? responses[0] : {};\n\n resolve({\n id,\n response: answer || '',\n completeAnswer: answer || '',\n });\n });\n\nconst advancedSessionResponse = (question) =>\n new Promise((resolve, reject) => {\n const { responses, id } = question;\n const { answer } = responses && responses.length ? responses[0] : {};\n\n if (!answer) {\n resolve({\n id,\n answers: {},\n completeAnswer: '',\n });\n\n return;\n }\n\n try {\n const e = question.expression;\n const RESPONSE_TOKEN = /\\\\{\\\\{\\s*response\\s*\\\\}\\\\}/g;\n\n const o = escape(e).split(RESPONSE_TOKEN);\n const to = o.map((t) => (t === '' ? t : t.replace(/\\s+/g, () => '\\\\s*')));\n const tt = to.join('(.*)');\n\n const m = answer.match(new RegExp(tt));\n\n const count = o.length - 1;\n\n if (!m) {\n resolve({\n id,\n answers: {},\n completeAnswer: answer,\n });\n\n console.log(`can not find match: ${o} in ${answer}`);\n\n return;\n }\n\n m.shift();\n\n const answers = {};\n\n for (var i = 0; i < count; i++) {\n answers[`r${i + 1}`] = { value: m[i].trim() };\n }\n\n resolve({\n id,\n answers,\n completeAnswer: answer,\n });\n } catch (e) {\n resolve({\n id,\n answers: {},\n completeAnswer: answer,\n });\n\n console.error(e.toString());\n }\n });\n\nexport const createCorrectResponseSession = (question, env) => {\n if (env.mode === 'evaluate' || env.role !== 'instructor') {\n // eslint-disable-next-line no-console\n console.error('can not create correct response session if mode is evaluate or role is not instructor');\n\n return Promise.resolve(null);\n }\n\n if ((question.responseType || '').toLowerCase() === 'simple') {\n return simpleSessionResponse(question, env);\n } else {\n return advancedSessionResponse(question, env);\n }\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { expression = '', responses, responseType } = model;\n const { maxResponseAreas } = config;\n const responsesErrors = {};\n\n (responses || []).forEach((response, index) => {\n const { answer } = response;\n const reversedAlternates = [...Object.entries(response.alternates || {})].reverse();\n const alternatesErrors = {};\n const responseError = {};\n\n if (answer === '') {\n responseError.answer = 'Content should not be empty.';\n }\n\n reversedAlternates.forEach(([key, value], index) => {\n if (value === '') {\n alternatesErrors[key] = 'Content should not be empty.';\n } else {\n const identicalAnswer =\n answer === value || reversedAlternates.slice(index + 1).some(([, val]) => val === value);\n\n if (identicalAnswer) {\n alternatesErrors[key] = 'Content should be unique.';\n }\n }\n });\n\n if (!isEmpty(responseError) || !isEmpty(alternatesErrors)) {\n responsesErrors[index] = { ...responseError, ...alternatesErrors };\n }\n });\n\n const errors = {};\n\n if (responseType === 'Advanced Multi') {\n const nbOfResponseAreas = (expression.match(/\\{\\{response\\}\\}/g) || []).length;\n\n if (nbOfResponseAreas > maxResponseAreas) {\n errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;\n } else if (nbOfResponseAreas < 1) {\n errors.responseAreasError = 'There should be at least 1 response area defined.';\n }\n }\n\n if (!isEmpty(responsesErrors)) {\n errors.responsesErrors = responsesErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.js"],"names":["ResponseTypes","advanced","simple"],"mappings":";;;;;;AAAO,IAAMA,aAAa,GAAG;AAC3BC,EAAAA,QAAQ,EAAE,gBADiB;AAE3BC,EAAAA,MAAM,EAAE;AAFmB,CAAtB","sourcesContent":["export const ResponseTypes = {\n advanced: 'Advanced Multi',\n simple: 'Simple'
|
|
1
|
+
{"version":3,"sources":["../src/utils.js"],"names":["ResponseTypes","advanced","simple"],"mappings":";;;;;;AAAO,IAAMA,aAAa,GAAG;AAC3BC,EAAAA,QAAQ,EAAE,gBADiB;AAE3BC,EAAAA,MAAM,EAAE;AAFmB,CAAtB","sourcesContent":["export const ResponseTypes = {\n advanced: 'Advanced Multi',\n simple: 'Simple',\n};\n"],"file":"utils.js"}
|
package/controller/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/math-inline-controller",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.7.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "src/index.js",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"test": "./node_modules/.bin/jest"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@pie-
|
|
13
|
-
"@pie-lib/
|
|
14
|
-
"@pie-lib/
|
|
12
|
+
"@pie-framework/math-validation": "^1.2.2",
|
|
13
|
+
"@pie-lib/controller-utils": "^0.2.42",
|
|
14
|
+
"@pie-lib/feedback": "^0.4.42",
|
|
15
15
|
"debug": "^3.1.0",
|
|
16
16
|
"lodash": "^4.17.15"
|
|
17
17
|
},
|
package/docs/config-schema.json
CHANGED
|
@@ -67,6 +67,27 @@
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
+
"settingsPanelDisabled": {
|
|
71
|
+
"description": "Indicates if the settings panel is not available",
|
|
72
|
+
"type": "boolean",
|
|
73
|
+
"title": "settingsPanelDisabled"
|
|
74
|
+
},
|
|
75
|
+
"spellCheck": {
|
|
76
|
+
"title": "ConfigureProp",
|
|
77
|
+
"type": "object",
|
|
78
|
+
"properties": {
|
|
79
|
+
"settings": {
|
|
80
|
+
"description": "Indicates if the item has to be displayed in the Settings Panel",
|
|
81
|
+
"type": "boolean",
|
|
82
|
+
"title": "settings"
|
|
83
|
+
},
|
|
84
|
+
"label": {
|
|
85
|
+
"description": "Indicates the label for the item that has to be displayed in the Settings Panel",
|
|
86
|
+
"type": "string",
|
|
87
|
+
"title": "label"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
70
91
|
"scoringType": {
|
|
71
92
|
"title": "ConfigureProp",
|
|
72
93
|
"type": "object",
|
|
@@ -115,6 +136,111 @@
|
|
|
115
136
|
}
|
|
116
137
|
}
|
|
117
138
|
},
|
|
139
|
+
"ignoreOrder": {
|
|
140
|
+
"title": "ConfigurePropWithEnabled",
|
|
141
|
+
"type": "object",
|
|
142
|
+
"properties": {
|
|
143
|
+
"settings": {
|
|
144
|
+
"description": "Indicates if the item has to be displayed in the Settings Panel",
|
|
145
|
+
"type": "boolean",
|
|
146
|
+
"title": "settings"
|
|
147
|
+
},
|
|
148
|
+
"label": {
|
|
149
|
+
"description": "Indicates the label for the item that has to be displayed in the Settings Panel",
|
|
150
|
+
"type": "string",
|
|
151
|
+
"title": "label"
|
|
152
|
+
},
|
|
153
|
+
"enabled": {
|
|
154
|
+
"description": "Indicates the value of the item if it affects config-ui\n(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)",
|
|
155
|
+
"type": "boolean",
|
|
156
|
+
"title": "enabled"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
"allowTrailingZeros": {
|
|
161
|
+
"title": "ConfigurePropWithEnabled",
|
|
162
|
+
"type": "object",
|
|
163
|
+
"properties": {
|
|
164
|
+
"settings": {
|
|
165
|
+
"description": "Indicates if the item has to be displayed in the Settings Panel",
|
|
166
|
+
"type": "boolean",
|
|
167
|
+
"title": "settings"
|
|
168
|
+
},
|
|
169
|
+
"label": {
|
|
170
|
+
"description": "Indicates the label for the item that has to be displayed in the Settings Panel",
|
|
171
|
+
"type": "string",
|
|
172
|
+
"title": "label"
|
|
173
|
+
},
|
|
174
|
+
"enabled": {
|
|
175
|
+
"description": "Indicates the value of the item if it affects config-ui\n(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)",
|
|
176
|
+
"type": "boolean",
|
|
177
|
+
"title": "enabled"
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"maxResponseAreas": {
|
|
182
|
+
"description": "Maximum number of response areas",
|
|
183
|
+
"type": "number",
|
|
184
|
+
"title": "maxResponseAreas"
|
|
185
|
+
},
|
|
186
|
+
"maxImageWidth": {
|
|
187
|
+
"title": "ConfigureMaxImageDimensionsProp",
|
|
188
|
+
"type": "object",
|
|
189
|
+
"properties": {
|
|
190
|
+
"teacherInstructions": {
|
|
191
|
+
"description": "Indicates the max dimension for images in teacher instructions",
|
|
192
|
+
"type": "number",
|
|
193
|
+
"title": "teacherInstructions"
|
|
194
|
+
},
|
|
195
|
+
"prompt": {
|
|
196
|
+
"description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
|
|
197
|
+
"type": "number",
|
|
198
|
+
"title": "prompt"
|
|
199
|
+
},
|
|
200
|
+
"rationale": {
|
|
201
|
+
"description": "Indicates the max dimension for images in rationale",
|
|
202
|
+
"type": "number",
|
|
203
|
+
"title": "rationale"
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
"maxImageHeight": {
|
|
208
|
+
"title": "ConfigureMaxImageDimensionsProp",
|
|
209
|
+
"type": "object",
|
|
210
|
+
"properties": {
|
|
211
|
+
"teacherInstructions": {
|
|
212
|
+
"description": "Indicates the max dimension for images in teacher instructions",
|
|
213
|
+
"type": "number",
|
|
214
|
+
"title": "teacherInstructions"
|
|
215
|
+
},
|
|
216
|
+
"prompt": {
|
|
217
|
+
"description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
|
|
218
|
+
"type": "number",
|
|
219
|
+
"title": "prompt"
|
|
220
|
+
},
|
|
221
|
+
"rationale": {
|
|
222
|
+
"description": "Indicates the max dimension for images in rationale",
|
|
223
|
+
"type": "number",
|
|
224
|
+
"title": "rationale"
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
"withRubric": {
|
|
229
|
+
"title": "ConfigureProp",
|
|
230
|
+
"type": "object",
|
|
231
|
+
"properties": {
|
|
232
|
+
"settings": {
|
|
233
|
+
"description": "Indicates if the item has to be displayed in the Settings Panel",
|
|
234
|
+
"type": "boolean",
|
|
235
|
+
"title": "settings"
|
|
236
|
+
},
|
|
237
|
+
"label": {
|
|
238
|
+
"description": "Indicates the label for the item that has to be displayed in the Settings Panel",
|
|
239
|
+
"type": "string",
|
|
240
|
+
"title": "label"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
118
244
|
"showPrompt": {
|
|
119
245
|
"description": "Determines whether prompt field will be displayed or not",
|
|
120
246
|
"default": true,
|
|
@@ -150,6 +276,48 @@
|
|
|
150
276
|
"title": "label"
|
|
151
277
|
}
|
|
152
278
|
}
|
|
279
|
+
},
|
|
280
|
+
"ConfigurePropWithEnabled": {
|
|
281
|
+
"title": "ConfigurePropWithEnabled",
|
|
282
|
+
"type": "object",
|
|
283
|
+
"properties": {
|
|
284
|
+
"settings": {
|
|
285
|
+
"description": "Indicates if the item has to be displayed in the Settings Panel",
|
|
286
|
+
"type": "boolean",
|
|
287
|
+
"title": "settings"
|
|
288
|
+
},
|
|
289
|
+
"label": {
|
|
290
|
+
"description": "Indicates the label for the item that has to be displayed in the Settings Panel",
|
|
291
|
+
"type": "string",
|
|
292
|
+
"title": "label"
|
|
293
|
+
},
|
|
294
|
+
"enabled": {
|
|
295
|
+
"description": "Indicates the value of the item if it affects config-ui\n(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)",
|
|
296
|
+
"type": "boolean",
|
|
297
|
+
"title": "enabled"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
"ConfigureMaxImageDimensionsProp": {
|
|
302
|
+
"title": "ConfigureMaxImageDimensionsProp",
|
|
303
|
+
"type": "object",
|
|
304
|
+
"properties": {
|
|
305
|
+
"teacherInstructions": {
|
|
306
|
+
"description": "Indicates the max dimension for images in teacher instructions",
|
|
307
|
+
"type": "number",
|
|
308
|
+
"title": "teacherInstructions"
|
|
309
|
+
},
|
|
310
|
+
"prompt": {
|
|
311
|
+
"description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
|
|
312
|
+
"type": "number",
|
|
313
|
+
"title": "prompt"
|
|
314
|
+
},
|
|
315
|
+
"rationale": {
|
|
316
|
+
"description": "Indicates the max dimension for images in rationale",
|
|
317
|
+
"type": "number",
|
|
318
|
+
"title": "rationale"
|
|
319
|
+
}
|
|
320
|
+
}
|
|
153
321
|
}
|
|
154
322
|
},
|
|
155
323
|
"$schema": "http://json-schema.org/draft-07/schema#"
|
|
@@ -50,6 +50,22 @@ Indicates if the item has to be displayed in the Settings Panel
|
|
|
50
50
|
|
|
51
51
|
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
52
52
|
|
|
53
|
+
# `settingsPanelDisabled` (boolean)
|
|
54
|
+
|
|
55
|
+
Indicates if the settings panel is not available
|
|
56
|
+
|
|
57
|
+
# `spellCheck` (object)
|
|
58
|
+
|
|
59
|
+
Properties of the `spellCheck` object:
|
|
60
|
+
|
|
61
|
+
## `settings` (boolean)
|
|
62
|
+
|
|
63
|
+
Indicates if the item has to be displayed in the Settings Panel
|
|
64
|
+
|
|
65
|
+
## `label` (string)
|
|
66
|
+
|
|
67
|
+
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
68
|
+
|
|
53
69
|
# `scoringType` (object)
|
|
54
70
|
|
|
55
71
|
Properties of the `scoringType` object:
|
|
@@ -86,6 +102,88 @@ Indicates if the item has to be displayed in the Settings Panel
|
|
|
86
102
|
|
|
87
103
|
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
88
104
|
|
|
105
|
+
# `ignoreOrder` (object)
|
|
106
|
+
|
|
107
|
+
Properties of the `ignoreOrder` object:
|
|
108
|
+
|
|
109
|
+
## `settings` (boolean)
|
|
110
|
+
|
|
111
|
+
Indicates if the item has to be displayed in the Settings Panel
|
|
112
|
+
|
|
113
|
+
## `label` (string)
|
|
114
|
+
|
|
115
|
+
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
116
|
+
|
|
117
|
+
## `enabled` (boolean)
|
|
118
|
+
|
|
119
|
+
Indicates the value of the item if it affects config-ui
|
|
120
|
+
(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)
|
|
121
|
+
|
|
122
|
+
# `allowTrailingZeros` (object)
|
|
123
|
+
|
|
124
|
+
Properties of the `allowTrailingZeros` object:
|
|
125
|
+
|
|
126
|
+
## `settings` (boolean)
|
|
127
|
+
|
|
128
|
+
Indicates if the item has to be displayed in the Settings Panel
|
|
129
|
+
|
|
130
|
+
## `label` (string)
|
|
131
|
+
|
|
132
|
+
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
133
|
+
|
|
134
|
+
## `enabled` (boolean)
|
|
135
|
+
|
|
136
|
+
Indicates the value of the item if it affects config-ui
|
|
137
|
+
(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)
|
|
138
|
+
|
|
139
|
+
# `maxResponseAreas` (number)
|
|
140
|
+
|
|
141
|
+
Maximum number of response areas
|
|
142
|
+
|
|
143
|
+
# `maxImageWidth` (object)
|
|
144
|
+
|
|
145
|
+
Properties of the `maxImageWidth` object:
|
|
146
|
+
|
|
147
|
+
## `teacherInstructions` (number)
|
|
148
|
+
|
|
149
|
+
Indicates the max dimension for images in teacher instructions
|
|
150
|
+
|
|
151
|
+
## `prompt` (number)
|
|
152
|
+
|
|
153
|
+
Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
|
|
154
|
+
|
|
155
|
+
## `rationale` (number)
|
|
156
|
+
|
|
157
|
+
Indicates the max dimension for images in rationale
|
|
158
|
+
|
|
159
|
+
# `maxImageHeight` (object)
|
|
160
|
+
|
|
161
|
+
Properties of the `maxImageHeight` object:
|
|
162
|
+
|
|
163
|
+
## `teacherInstructions` (number)
|
|
164
|
+
|
|
165
|
+
Indicates the max dimension for images in teacher instructions
|
|
166
|
+
|
|
167
|
+
## `prompt` (number)
|
|
168
|
+
|
|
169
|
+
Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
|
|
170
|
+
|
|
171
|
+
## `rationale` (number)
|
|
172
|
+
|
|
173
|
+
Indicates the max dimension for images in rationale
|
|
174
|
+
|
|
175
|
+
# `withRubric` (object)
|
|
176
|
+
|
|
177
|
+
Properties of the `withRubric` object:
|
|
178
|
+
|
|
179
|
+
## `settings` (boolean)
|
|
180
|
+
|
|
181
|
+
Indicates if the item has to be displayed in the Settings Panel
|
|
182
|
+
|
|
183
|
+
## `label` (string)
|
|
184
|
+
|
|
185
|
+
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
186
|
+
|
|
89
187
|
# `showPrompt` (boolean)
|
|
90
188
|
|
|
91
189
|
Determines whether prompt field will be displayed or not
|
|
@@ -120,4 +218,37 @@ Indicates if the item has to be displayed in the Settings Panel
|
|
|
120
218
|
|
|
121
219
|
### `label` (string)
|
|
122
220
|
|
|
123
|
-
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
221
|
+
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
222
|
+
|
|
223
|
+
## `ConfigurePropWithEnabled` (object)
|
|
224
|
+
|
|
225
|
+
Properties of the `ConfigurePropWithEnabled` object:
|
|
226
|
+
|
|
227
|
+
### `settings` (boolean)
|
|
228
|
+
|
|
229
|
+
Indicates if the item has to be displayed in the Settings Panel
|
|
230
|
+
|
|
231
|
+
### `label` (string)
|
|
232
|
+
|
|
233
|
+
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
234
|
+
|
|
235
|
+
### `enabled` (boolean)
|
|
236
|
+
|
|
237
|
+
Indicates the value of the item if it affects config-ui
|
|
238
|
+
(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)
|
|
239
|
+
|
|
240
|
+
## `ConfigureMaxImageDimensionsProp` (object)
|
|
241
|
+
|
|
242
|
+
Properties of the `ConfigureMaxImageDimensionsProp` object:
|
|
243
|
+
|
|
244
|
+
### `teacherInstructions` (number)
|
|
245
|
+
|
|
246
|
+
Indicates the max dimension for images in teacher instructions
|
|
247
|
+
|
|
248
|
+
### `prompt` (number)
|
|
249
|
+
|
|
250
|
+
Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
|
|
251
|
+
|
|
252
|
+
### `rationale` (number)
|
|
253
|
+
|
|
254
|
+
Indicates the max dimension for images in rationale
|
package/docs/demo/config.js
CHANGED
package/docs/demo/generate.js
CHANGED
|
@@ -8,31 +8,35 @@ const initialModel = {
|
|
|
8
8
|
answer: 'r=\\sqrt{\\frac{V}{7\\pi}}',
|
|
9
9
|
id: '1',
|
|
10
10
|
alternates: {},
|
|
11
|
-
validation: 'literal'
|
|
12
|
-
}
|
|
11
|
+
validation: 'literal',
|
|
12
|
+
},
|
|
13
13
|
],
|
|
14
|
+
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.',
|
|
14
15
|
rationale:
|
|
15
16
|
'<p>The correct answer is:</p><ul><li><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>r</mi><mo>=</mo><msqrt><mfrac><mi>V</mi><mrow><mn>7</mn><mi>π</mi></mrow></mfrac></msqrt></math></li></ul>',
|
|
16
|
-
}
|
|
17
|
+
};
|
|
17
18
|
|
|
18
19
|
const E262456 = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
equationEditor: 3,
|
|
21
|
+
toolbarEditorPosition: 'bottom',
|
|
22
|
+
prompt:
|
|
23
|
+
'<p><strong>B.</strong> Find the value of the expression that you wrote in part A to find how much money the band members made.</p>\n\n<p>Use the on-screen keyboard to type your answer in the box below.</p>\n',
|
|
24
|
+
expression: '${{response}}',
|
|
25
|
+
responses: [
|
|
23
26
|
{
|
|
24
|
-
|
|
25
|
-
'validation': 'symbolic',
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
27
|
+
allowSpaces: true,
|
|
28
|
+
// 'validation': 'symbolic',
|
|
29
|
+
answer: '$410',
|
|
30
|
+
id: '1',
|
|
31
|
+
},
|
|
29
32
|
],
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
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.',
|
|
34
|
+
responseType: 'Advanced Multi',
|
|
35
|
+
};
|
|
33
36
|
|
|
34
37
|
exports.model = (id, element) => ({
|
|
35
38
|
id,
|
|
36
39
|
element,
|
|
37
|
-
...E262456
|
|
40
|
+
...E262456,
|
|
41
|
+
rubricEnabled: false,
|
|
38
42
|
});
|
package/docs/demo/session.js
CHANGED