@pie-element/explicit-constructed-response 3.12.2 → 3.12.3

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","prepareChoice","mode","defaultFeedback","choice","out","label","value","correct","feedbackType","feedback","type","getFeedback","getAdjustedLength","length","normalize","question","rationaleEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","model","session","env","Promise","resolve","choices","Object","keys","forEach","key","map","item","index","normalizedQuestion","assign","incorrect","preparChoiceFn","obj","area","respArea","chosenValue","val","c","prepareVal","showNote","values","maxLengthPerChoice","maxLengthPerChoiceEnabled","undefinedLengths","labelLengthsArr","Math","max","disabled","prompt","markup","note","displayType","responseCorrect","getScore","undefined","role","rationale","teacherInstructions","getTextFromHTML","html","replace","trim","config","responseAreas","match","maxScore","correctCount","total","str","toFixed","parseFloat","outcome","partialScoringEnabled","partialScoring","enabled","score","empty","createCorrectResponseSession","i","id"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,0CAAN,CAAZ;;AAEO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACC,IAAD,EAAOC,eAAP;AAAA,SAA2B,UAAAC,MAAM,EAAI;AAChE,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEF,MAAM,CAACE,KADJ;AAEVC,MAAAA,KAAK,EAAEH,MAAM,CAACG;AAFJ,KAAZ;;AAKA,QAAIL,IAAI,KAAK,UAAb,EAAyB;AACvBG,MAAAA,GAAG,CAACG,OAAJ,GAAc,IAAd;AAEA,UAAMC,YAAY,GAAIL,MAAM,CAACM,QAAP,IAAmBN,MAAM,CAACM,QAAP,CAAgBC,IAApC,IAA6C,MAAlE;;AAEA,UAAIF,YAAY,KAAK,SAArB,EAAgC;AAC9BJ,QAAAA,GAAG,CAACK,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+B,CAACnE,QAAD,EAAWO,GAAX,EAAmB;AAC7D,SAAO,IAAIC,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAC5B,QAAIF,GAAG,CAACrB,IAAJ,KAAa,UAAb,IAA2BqB,GAAG,CAACsC,IAAJ,KAAa,YAA5C,EAA0D;AACxD,UAAQnC,OAAR,GAAoBV,QAApB,CAAQU,OAAR;AACA,UAAMnB,KAAK,GAAG,EAAd;AAEAoB,MAAAA,MAAM,CAACC,IAAP,CAAYF,OAAZ,EAAqBG,OAArB,CAA6B,UAACC,GAAD,EAAMsD,CAAN,EAAY;AACvC7E,QAAAA,KAAK,CAAC6E,CAAD,CAAL,GAAW1D,OAAO,CAACI,GAAD,CAAP,CAAa,CAAb,EAAgBxB,KAA3B;AACD,OAFD;AAIAmB,MAAAA,OAAO,CAAC;AACN4D,QAAAA,EAAE,EAAE,GADE;AAEN9E,QAAAA,KAAK,EAALA;AAFM,OAAD,CAAP;AAID,KAZD,MAYO;AACLkB,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAhBM,CAAP;AAiBD,CAlBM","sourcesContent":["import map from 'lodash/map';\nimport reduce from 'lodash/reduce';\nimport find from 'lodash/find';\nimport isEmpty from 'lodash/isEmpty';\nimport debug from 'debug';\nimport { partialScoring } from '@pie-lib/controller-utils';\n\nconst log = debug('explicit-constructed-response:controller');\n\nexport const prepareChoice = (mode, defaultFeedback) => choice => {\n const out = {\n label: choice.label,\n value: choice.value\n };\n\n if (mode === 'evaluate') {\n out.correct = true;\n\n const feedbackType = (choice.feedback && choice.feedback.type) || 'none';\n\n if (feedbackType === 'default') {\n out.feedback = defaultFeedback['correct'];\n } else if (feedbackType === 'custom') {\n out.feedback = choice.feedback.value;\n }\n }\n\n return out;\n};\n\nconst getFeedback = value => {\n if (value) {\n return 'correct';\n }\n\n return 'incorrect';\n};\n\n// also used in configure/src/markupUtils.js\nconst getAdjustedLength = length => {\n if (length <= 2) {\n return length + 2;\n }\n\n if (length <= 4) {\n return length + 3;\n }\n\n if (length <= 6) {\n return length + 4;\n }\n\n return length + 5;\n};\n\nexport const normalize = question => ({\n rationaleEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n // this was added to treat an exception, when the model has choices without the \"value\" property\n // like: { label: 'test' }\n if (question.choices) {\n Object.keys(question.choices).forEach(key => {\n question.choices[key] = (question.choices[key] || []).map((item, index) => {\n if (!item.value) {\n log('Choice does not contain \"value\" property, which is required.', item);\n return { value: `${index}`, ...item };\n }\n\n return item;\n })\n });\n }\n\n const normalizedQuestion = normalize(question);\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n normalizedQuestion.defaultFeedback\n );\n\n const { value = {} } = session || {};\n\n const preparChoiceFn = prepareChoice(env.mode, defaultFeedback);\n\n let choices = reduce(\n normalizedQuestion.choices,\n (obj, area, key) => {\n obj[key] = map(area, preparChoiceFn);\n\n return obj;\n },\n {}\n );\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n feedback = reduce(normalizedQuestion.choices, (obj, respArea, key) => {\n const chosenValue = value && value[key];\n const val = !isEmpty(chosenValue) && find(respArea, c => prepareVal(c.label) === prepareVal(chosenValue));\n\n obj[key] = getFeedback(val);\n\n return obj;\n }, {});\n }\n\n let showNote = false;\n // check if a choice has an alternate\n Object.values(choices).forEach(choice => {\n if (choice && choice.length > 1) {\n showNote = true;\n }\n });\n\n const { maxLengthPerChoice = [], maxLengthPerChoiceEnabled } = normalizedQuestion;\n const undefinedLengths = !maxLengthPerChoice.length;\n\n // calculate maxLengthPerChoice array if it is not defined or defined incorrectly\n Object.values(choices).forEach((choice, index) => {\n const labelLengthsArr = (choice || []).map(choice => (choice.label || '').length);\n const length = getAdjustedLength(Math.max(...labelLengthsArr));\n\n if (undefinedLengths || !maxLengthPerChoice[index] || maxLengthPerChoice[index] < length) {\n maxLengthPerChoice[index] = length;\n }\n });\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n markup: normalizedQuestion.markup,\n choices,\n feedback,\n env,\n note: normalizedQuestion.note,\n showNote,\n maxLengthPerChoice,\n maxLengthPerChoiceEnabled,\n displayType: normalizedQuestion.displayType,\n responseCorrect:\n env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined\n };\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n}\n\nconst getTextFromHTML = (html) => {\n return (html || '').replace(/<\\/?[^>]+(>|$)/g, '');\n};\n\nexport const prepareVal = html => {\n const value = getTextFromHTML(html);\n\n return value.trim();\n};\n\nexport const getScore = (config, session) => {\n const { value } = session || {};\n\n if (!session || isEmpty(session) || !value) {\n return 0;\n }\n\n const responseAreas = config.markup && config.markup.match(/\\{\\{(.)\\}\\}/g);\n const maxScore = responseAreas ? responseAreas.length : 0;\n const correctCount = reduce(config.choices, (total, respArea, key) => {\n const chosenValue = value && value[key];\n\n if (isEmpty(chosenValue) || !find(respArea, c => prepareVal(c.label) === prepareVal(chosenValue))) {\n return total;\n }\n\n return total + 1;\n }, 0);\n\n const str = maxScore ? (correctCount / maxScore).toFixed(2) : 0;\n\n return parseFloat(str);\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =\n * false. the value in `env` will override the value in `model`.\n * @param {Object} model - the main model\n * @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)\n * @param {*} session\n * @param {Object} env\n * @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides\n * `model.partialScoring`.\n */\nexport function outcome(model, session, env = {}) {\n return new Promise(resolve => {\n const partialScoringEnabled = partialScoring.enabled(model, env);\n const score = getScore(model, session);\n\n resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: isEmpty(session) });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question;\n const value = {};\n\n Object.keys(choices).forEach((key, i) => {\n value[i] = choices[key][0].label;\n });\n\n resolve({\n id: '1',\n value\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","prepareChoice","mode","defaultFeedback","choice","out","label","value","correct","feedbackType","feedback","type","getFeedback","getAdjustedLength","length","normalize","question","rationaleEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","model","session","env","Promise","resolve","choices","Object","keys","forEach","key","map","item","index","normalizedQuestion","assign","incorrect","preparChoiceFn","obj","area","respArea","chosenValue","val","c","prepareVal","showNote","values","maxLengthPerChoice","maxLengthPerChoiceEnabled","undefinedLengths","labelLengthsArr","Math","max","disabled","prompt","markup","note","displayType","responseCorrect","getScore","undefined","role","rationale","teacherInstructions","getTextFromHTML","html","replace","trim","config","responseAreas","match","maxScore","correctCount","total","str","toFixed","parseFloat","outcome","partialScoringEnabled","partialScoring","enabled","score","empty","createCorrectResponseSession","i","id"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,0CAAN,CAAZ;;AAEO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACC,IAAD,EAAOC,eAAP;AAAA,SAA2B,UAAAC,MAAM,EAAI;AAChE,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEF,MAAM,CA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gCAAeC,OAAf,CAAuB3D,KAAvB,EAA8BE,GAA9B,CAA9B;;AACA,QAAM0D,KAAK,GAAGtB,QAAQ,CAACtC,KAAD,EAAQC,OAAR,CAAtB;AAEAG,IAAAA,OAAO,CAAC;AAAEwD,MAAAA,KAAK,EAAEH,qBAAqB,GAAGG,KAAH,GAAWA,KAAK,KAAK,CAAV,GAAc,CAAd,GAAkB,CAA3D;AAA8DC,MAAAA,KAAK,EAAE,yBAAQ5D,OAAR;AAArE,KAAD,CAAP;AACD,GALM,CAAP;AAMD;;AAEM,IAAM6D,4BAA4B,GAAG,SAA/BA,4BAA+B,CAACnE,QAAD,EAAWO,GAAX,EAAmB;AAC7D,SAAO,IAAIC,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAC5B,QAAIF,GAAG,CAACrB,IAAJ,KAAa,UAAb,IAA2BqB,GAAG,CAACsC,IAAJ,KAAa,YAA5C,EAA0D;AACxD,UAAQnC,OAAR,GAAoBV,QAApB,CAAQU,OAAR;AACA,UAAMnB,KAAK,GAAG,EAAd;AAEAoB,MAAAA,MAAM,CAACC,IAAP,CAAYF,OAAZ,EAAqBG,OAArB,CAA6B,UAACC,GAAD,EAAMsD,CAAN,EAAY;AACvC7E,QAAAA,KAAK,CAAC6E,CAAD,CAAL,GAAW1D,OAAO,CAACI,GAAD,CAAP,CAAa,CAAb,EAAgBxB,KAA3B;AACD,OAFD;AAIAmB,MAAAA,OAAO,CAAC;AACN4D,QAAAA,EAAE,EAAE,GADE;AAEN9E,QAAAA,KAAK,EAALA;AAFM,OAAD,CAAP;AAID,KAZD,MAYO;AACLkB,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAhBM,CAAP;AAiBD,CAlBM","sourcesContent":["import map from 'lodash/map';\nimport reduce from 'lodash/reduce';\nimport find from 'lodash/find';\nimport isEmpty from 'lodash/isEmpty';\nimport debug from 'debug';\nimport { partialScoring } from '@pie-lib/controller-utils';\n\nconst log = debug('explicit-constructed-response:controller');\n\nexport const prepareChoice = (mode, defaultFeedback) => choice => {\n const out = {\n label: choice.label,\n value: choice.value\n };\n\n if (mode === 'evaluate') {\n out.correct = true;\n\n const feedbackType = (choice.feedback && choice.feedback.type) || 'none';\n\n if (feedbackType === 'default') {\n out.feedback = defaultFeedback['correct'];\n } else if (feedbackType === 'custom') {\n out.feedback = choice.feedback.value;\n }\n }\n\n return out;\n};\n\nconst getFeedback = value => {\n if (value) {\n return 'correct';\n }\n\n return 'incorrect';\n};\n\n// also used in configure/src/markupUtils.js\nconst getAdjustedLength = length => {\n if (length <= 2) {\n return length + 2;\n }\n\n if (length <= 4) {\n return length + 3;\n }\n\n if (length <= 6) {\n return length + 4;\n }\n\n return length + 5;\n};\n\nexport const normalize = question => ({\n rationaleEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n // this was added to treat an exception, when the model has choices without the \"value\" property\n // like: { label: 'test' }\n if (question.choices) {\n Object.keys(question.choices).forEach(key => {\n question.choices[key] = (question.choices[key] || []).map((item, index) => {\n if (!item.value) {\n log('Choice does not contain \"value\" property, which is required.', item);\n return { value: `${index}`, ...item };\n }\n\n return item;\n })\n });\n }\n\n const normalizedQuestion = normalize(question);\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n normalizedQuestion.defaultFeedback\n );\n\n const { value = {} } = session || {};\n\n const preparChoiceFn = prepareChoice(env.mode, defaultFeedback);\n\n let choices = reduce(\n normalizedQuestion.choices,\n (obj, area, key) => {\n obj[key] = map(area, preparChoiceFn);\n\n return obj;\n },\n {}\n );\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n feedback = reduce(normalizedQuestion.choices, (obj, respArea, key) => {\n const chosenValue = value && value[key];\n const val = !isEmpty(chosenValue) && find(respArea, c => prepareVal(c.label) === prepareVal(chosenValue));\n\n obj[key] = getFeedback(val);\n\n return obj;\n }, {});\n }\n\n let showNote = false;\n // check if a choice has an alternate\n Object.values(choices).forEach(choice => {\n if (choice && choice.length > 1) {\n showNote = true;\n }\n });\n\n const { maxLengthPerChoice = [], maxLengthPerChoiceEnabled } = normalizedQuestion;\n const undefinedLengths = !maxLengthPerChoice.length;\n\n // calculate maxLengthPerChoice array if it is not defined or defined incorrectly\n Object.values(choices).forEach((choice, index) => {\n const labelLengthsArr = (choice || []).map(choice => (choice.label || '').length);\n const length = Math.max(...labelLengthsArr);\n\n if (\n undefinedLengths\n || !maxLengthPerChoice[index]\n || maxLengthPerChoice[index] < length\n || maxLengthPerChoice[index] > length + 10\n ) {\n maxLengthPerChoice[index] = getAdjustedLength(length);\n }\n });\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n markup: normalizedQuestion.markup,\n choices,\n feedback,\n env,\n note: normalizedQuestion.note,\n showNote,\n maxLengthPerChoice,\n maxLengthPerChoiceEnabled,\n displayType: normalizedQuestion.displayType,\n responseCorrect:\n env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined\n };\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n}\n\nconst getTextFromHTML = (html) => {\n return (html || '').replace(/<\\/?[^>]+(>|$)/g, '');\n};\n\nexport const prepareVal = html => {\n const value = getTextFromHTML(html);\n\n return value.trim();\n};\n\nexport const getScore = (config, session) => {\n const { value } = session || {};\n\n if (!session || isEmpty(session) || !value) {\n return 0;\n }\n\n const responseAreas = config.markup && config.markup.match(/\\{\\{(.)\\}\\}/g);\n const maxScore = responseAreas ? responseAreas.length : 0;\n const correctCount = reduce(config.choices, (total, respArea, key) => {\n const chosenValue = value && value[key];\n\n if (isEmpty(chosenValue) || !find(respArea, c => prepareVal(c.label) === prepareVal(chosenValue))) {\n return total;\n }\n\n return total + 1;\n }, 0);\n\n const str = maxScore ? (correctCount / maxScore).toFixed(2) : 0;\n\n return parseFloat(str);\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =\n * false. the value in `env` will override the value in `model`.\n * @param {Object} model - the main model\n * @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)\n * @param {*} session\n * @param {Object} env\n * @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides\n * `model.partialScoring`.\n */\nexport function outcome(model, session, env = {}) {\n return new Promise(resolve => {\n const partialScoringEnabled = partialScoring.enabled(model, env);\n const score = getScore(model, session);\n\n resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: isEmpty(session) });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question;\n const value = {};\n\n Object.keys(choices).forEach((key, i) => {\n value[i] = choices[key][0].label;\n });\n\n resolve({\n id: '1',\n value\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/explicit-constructed-response-controller",
3
3
  "private": true,
4
- "version": "3.4.6",
4
+ "version": "3.4.7",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
@@ -12,7 +12,7 @@ exports.model = (id, element) => ({
12
12
  1: [choice('over', '0'), choice('past', '1'), choice('beyond', '2')],
13
13
  2: [choice('moon', '0')]
14
14
  },
15
- maxLengthPerChoice: [10, 11, 7],
15
+ maxLengthPerChoice: [7, 10, 4],
16
16
  prompt: 'Complete the sentence',
17
17
  note: 'The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.',
18
18
  promptEnabled: true,
@@ -1,6 +1,6 @@
1
- import {_dll_react, _dll_prop_types, _dll_material_ui__core, _dll_material_ui__core_styles, _dll_lodash, _dll_material_ui__icons, _dll_react_dom, _dll_debug} from "../../../@pie-lib/shared-module@^1.3.1/module/index.js";
2
- import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.0.22/module/index.js";
3
- import {_dll_pie_lib__config_ui} from "../../../@pie-lib/config-module@^1.0.22/module/index.js";
1
+ import {_dll_react, _dll_prop_types, _dll_material_ui__core, _dll_material_ui__core_styles, _dll_lodash, _dll_material_ui__icons, _dll_react_dom, _dll_debug} from "../../../@pie-lib/shared-module@^1.4.1/module/index.js";
2
+ import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.2.0/module/index.js";
3
+ import {_dll_pie_lib__config_ui} from "../../../@pie-lib/config-module@^1.0.24/module/index.js";
4
4
  function getDefaultExportFromCjs(x) {
5
5
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
6
6
  }
@@ -494,7 +494,9 @@ const {OutlinedInput: require$$11$4} = _dll_material_ui__core;
494
494
  args[_key] = arguments[_key];
495
495
  }
496
496
  _this = _super.call.apply(_super, [this].concat(args));
497
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {});
497
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
498
+ markup: ''
499
+ });
498
500
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDone", function () {
499
501
  var newValue = _this.state.markup;
500
502
  var _this$props = _this.props, node = _this$props.node, value = _this$props.value, onToolbarDone = _this$props.onToolbarDone, onChangeResponse = _this$props.onChangeResponse;
@@ -506,7 +508,7 @@ const {OutlinedInput: require$$11$4} = _dll_material_ui__core;
506
508
  });
507
509
  var nextText = value.document.getNextText(node.key);
508
510
  change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);
509
- onToolbarDone(change, false);
511
+ onToolbarDone(change, true);
510
512
  onChangeResponse(newValue);
511
513
  });
512
514
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (e) {
@@ -559,7 +561,7 @@ const {OutlinedInput: require$$11$4} = _dll_material_ui__core;
559
561
  },
560
562
  onChange: this.onChange,
561
563
  onBlur: this.onDone,
562
- value: markup
564
+ value: markup || ''
563
565
  }));
564
566
  }
565
567
  }]);
@@ -595,73 +597,17 @@ const {OutlinedInput: require$$11$4} = _dll_material_ui__core;
595
597
  getDefaultExportFromCjs(ecrToolbar);
596
598
  var alternateResponses = {};
597
599
  var alternateSection = {};
598
- var markupUtils = {};
599
- const {escape: require$$1} = _dll_lodash;
600
- var _interopRequireDefault = interopRequireDefault.exports;
601
- Object.defineProperty(markupUtils, "__esModule", {
602
- value: true
603
- });
604
- markupUtils.getAdjustedLength = markupUtils.createSlateMarkup = markupUtils.processMarkup = markupUtils.removeUnwantedCharacters = void 0;
605
- var _escape = _interopRequireDefault(require$$1);
606
- var tSymbols = 'imes|riangle|an|heta|herefore';
607
- var nSymbols = 'throot|parallel|cong|approx|eq|e|sim';
608
- var matchTabAndNewLine = new RegExp(("(\\t(?!").concat(tSymbols, "))|(\\n(?!").concat(nSymbols, "))|(\\\\t(?!").concat(tSymbols, "))|(\\\\n(?!").concat(nSymbols, "))"), 'g');
609
- var removeUnwantedCharacters = function removeUnwantedCharacters(markup) {
610
- return markup.replace(matchTabAndNewLine, '').replace(/\\"/g, '"').replace(/\\\//g, '/');
611
- };
612
- markupUtils.removeUnwantedCharacters = removeUnwantedCharacters;
613
- var createElementFromHTML = function createElementFromHTML() {
614
- var htmlString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
615
- var div = document.createElement('div');
616
- div.innerHTML = htmlString.trim();
617
- return div;
618
- };
619
- var processMarkup = function processMarkup(markup) {
620
- var newMarkup = removeUnwantedCharacters(markup || '');
621
- var slateMarkup = createElementFromHTML(newMarkup || '');
622
- var index = 0;
623
- slateMarkup.querySelectorAll('[data-type="explicit_constructed_response"]').forEach(function (s) {
624
- s.replaceWith(("{{").concat(index++, "}}"));
625
- });
626
- return slateMarkup.innerHTML;
627
- };
628
- markupUtils.processMarkup = processMarkup;
629
- var REGEX = /\{\{(\d+)\}\}/g;
630
- var createSlateMarkup = function createSlateMarkup(markup, choices) {
631
- if (!markup) {
632
- return '';
633
- }
634
- var newMarkup = removeUnwantedCharacters(markup);
635
- return newMarkup.replace(REGEX, function (match, g) {
636
- var label = choices[g][0].label || '';
637
- return ("<span data-type=\"explicit_constructed_response\" data-index=\"").concat(g, "\" data-value=\"").concat((0, _escape["default"])(label), "\"></span>");
638
- });
639
- };
640
- markupUtils.createSlateMarkup = createSlateMarkup;
641
- var getAdjustedLength = function getAdjustedLength(length) {
642
- if (length <= 2) {
643
- return length + 2;
644
- }
645
- if (length <= 4) {
646
- return length + 3;
647
- }
648
- if (length <= 6) {
649
- return length + 4;
650
- }
651
- return length + 5;
652
- };
653
- markupUtils.getAdjustedLength = getAdjustedLength;
654
600
  const require$$9$2 = _dll_react;
655
601
  const require$$10$3 = _dll_prop_types;
656
602
  const {debounce: require$$11$3} = _dll_lodash;
657
603
  const {isEqual: require$$12$3} = _dll_lodash;
658
- const {max: require$$22} = _dll_lodash;
604
+ const {max: require$$21} = _dll_lodash;
659
605
  const {OutlinedInput: require$$13$3} = _dll_material_ui__core;
660
606
  const {Button: require$$14$2} = _dll_material_ui__core;
661
607
  const {IconButton: require$$16$1} = _dll_material_ui__core;
662
608
  const {MenuItem: require$$17$1} = _dll_material_ui__core;
663
- const {Select: require$$18} = _dll_material_ui__core;
664
- const {TextField: require$$19} = _dll_material_ui__core;
609
+ const {Select: require$$18$1} = _dll_material_ui__core;
610
+ const {TextField: require$$19$1} = _dll_material_ui__core;
665
611
  const {Delete: require$$15$1} = _dll_material_ui__icons;
666
612
  const require$$20 = _dll_material_ui__core_styles;
667
613
  (function (exports) {
@@ -687,11 +633,10 @@ const require$$20 = _dll_material_ui__core_styles;
687
633
  var _Delete = _interopRequireDefault(require$$15$1);
688
634
  var _IconButton = _interopRequireDefault(require$$16$1);
689
635
  var _MenuItem = _interopRequireDefault(require$$17$1);
690
- var _Select = _interopRequireDefault(require$$18);
691
- var _TextField = _interopRequireDefault(require$$19);
636
+ var _Select = _interopRequireDefault(require$$18$1);
637
+ var _TextField = _interopRequireDefault(require$$19$1);
692
638
  var _styles = require$$20;
693
- var _markupUtils = markupUtils;
694
- var _max = _interopRequireDefault(require$$22);
639
+ var _max = _interopRequireDefault(require$$21);
695
640
  function ownKeys(object, enumerableOnly) {
696
641
  var keys = Object.keys(object);
697
642
  if (Object.getOwnPropertySymbols) {
@@ -828,8 +773,7 @@ const require$$20 = _dll_material_ui__core_styles;
828
773
  className: classes.choice,
829
774
  value: value,
830
775
  onChange: this.onChange,
831
- labelWidth: 0,
832
- disableUnderline: true
776
+ labelWidth: 0
833
777
  }), _react["default"].createElement(_IconButton["default"], {
834
778
  "aria-label": "delete",
835
779
  className: classes.deleteBtn,
@@ -894,11 +838,11 @@ const require$$20 = _dll_material_ui__core_styles;
894
838
  return (choice.label || '').length;
895
839
  });
896
840
  labelLengthsArr[index] = value.length;
897
- var newLength = (0, _markupUtils.getAdjustedLength)(Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr)));
841
+ var newLength = Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr));
898
842
  choiceChanged(_objectSpread(_objectSpread({}, choice), {}, {
899
843
  label: value
900
844
  }));
901
- if (newLength > maxLength || newLength + 10 < maxLength) {
845
+ if (newLength > maxLength || newLength + 10 <= maxLength) {
902
846
  lengthChanged(newLength);
903
847
  }
904
848
  });
@@ -914,7 +858,7 @@ const require$$20 = _dll_material_ui__core_styles;
914
858
  var labelLengthsArr = choices.map(function (choice) {
915
859
  return (choice.label || '').length;
916
860
  });
917
- return (0, _markupUtils.getAdjustedLength)(Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr)));
861
+ return Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr));
918
862
  });
919
863
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "changeLength", function (event) {
920
864
  var lengthChanged = _this2.props.lengthChanged;
@@ -1259,14 +1203,72 @@ const {cloneDeep: require$$14$1} = _dll_lodash;
1259
1203
  exports["default"] = _default;
1260
1204
  })(alternateResponses);
1261
1205
  getDefaultExportFromCjs(alternateResponses);
1206
+ var markupUtils = {};
1207
+ const {escape: require$$1} = _dll_lodash;
1208
+ var _interopRequireDefault = interopRequireDefault.exports;
1209
+ Object.defineProperty(markupUtils, "__esModule", {
1210
+ value: true
1211
+ });
1212
+ markupUtils.getAdjustedLength = markupUtils.createSlateMarkup = markupUtils.processMarkup = markupUtils.removeUnwantedCharacters = void 0;
1213
+ var _escape = _interopRequireDefault(require$$1);
1214
+ var tSymbols = 'imes|riangle|an|heta|herefore';
1215
+ var nSymbols = 'throot|parallel|cong|approx|eq|e|sim';
1216
+ var matchTabAndNewLine = new RegExp(("(\\t(?!").concat(tSymbols, "))|(\\n(?!").concat(nSymbols, "))|(\\\\t(?!").concat(tSymbols, "))|(\\\\n(?!").concat(nSymbols, "))"), 'g');
1217
+ var removeUnwantedCharacters = function removeUnwantedCharacters(markup) {
1218
+ return markup.replace(matchTabAndNewLine, '').replace(/\\"/g, '"').replace(/\\\//g, '/');
1219
+ };
1220
+ markupUtils.removeUnwantedCharacters = removeUnwantedCharacters;
1221
+ var createElementFromHTML = function createElementFromHTML() {
1222
+ var htmlString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
1223
+ var div = document.createElement('div');
1224
+ div.innerHTML = htmlString.trim();
1225
+ return div;
1226
+ };
1227
+ var processMarkup = function processMarkup(markup) {
1228
+ var newMarkup = removeUnwantedCharacters(markup || '');
1229
+ var slateMarkup = createElementFromHTML(newMarkup || '');
1230
+ var index = 0;
1231
+ slateMarkup.querySelectorAll('[data-type="explicit_constructed_response"]').forEach(function (s) {
1232
+ s.replaceWith(("{{").concat(index++, "}}"));
1233
+ });
1234
+ return slateMarkup.innerHTML;
1235
+ };
1236
+ markupUtils.processMarkup = processMarkup;
1237
+ var REGEX = /\{\{(\d+)\}\}/g;
1238
+ var createSlateMarkup = function createSlateMarkup(markup, choices) {
1239
+ if (!markup) {
1240
+ return '';
1241
+ }
1242
+ var newMarkup = removeUnwantedCharacters(markup);
1243
+ return newMarkup.replace(REGEX, function (match, g) {
1244
+ var label = choices[g][0].label || '';
1245
+ return ("<span data-type=\"explicit_constructed_response\" data-index=\"").concat(g, "\" data-value=\"").concat((0, _escape["default"])(label), "\"></span>");
1246
+ });
1247
+ };
1248
+ markupUtils.createSlateMarkup = createSlateMarkup;
1249
+ var getAdjustedLength = function getAdjustedLength(length) {
1250
+ if (length <= 2) {
1251
+ return length + 2;
1252
+ }
1253
+ if (length <= 4) {
1254
+ return length + 3;
1255
+ }
1256
+ if (length <= 6) {
1257
+ return length + 4;
1258
+ }
1259
+ return length + 5;
1260
+ };
1261
+ markupUtils.getAdjustedLength = getAdjustedLength;
1262
1262
  const require$$10$1 = _dll_react;
1263
1263
  const require$$11$1 = _dll_prop_types;
1264
1264
  const {cloneDeep: require$$12$1} = _dll_lodash;
1265
1265
  const {isEmpty: require$$13$1} = _dll_lodash;
1266
- const require$$16 = _dll_material_ui__core_styles;
1267
- const {Typography: require$$17} = _dll_material_ui__core;
1268
- const require$$14 = _dll_pie_lib__editable_html;
1269
- const require$$15 = _dll_pie_lib__config_ui;
1266
+ const {pick: require$$14} = _dll_lodash;
1267
+ const {throttle: require$$15} = _dll_lodash;
1268
+ const require$$18 = _dll_material_ui__core_styles;
1269
+ const {Typography: require$$19} = _dll_material_ui__core;
1270
+ const require$$16 = _dll_pie_lib__editable_html;
1271
+ const require$$17 = _dll_pie_lib__config_ui;
1270
1272
  (function (exports) {
1271
1273
  var _interopRequireDefault = interopRequireDefault.exports;
1272
1274
  var _typeof$1 = _typeof.exports;
@@ -1286,10 +1288,12 @@ const require$$15 = _dll_pie_lib__config_ui;
1286
1288
  var _propTypes = _interopRequireDefault(require$$11$1);
1287
1289
  var _cloneDeep = _interopRequireDefault(require$$12$1);
1288
1290
  var _isEmpty = _interopRequireDefault(require$$13$1);
1289
- var _editableHtml = _interopRequireWildcard(require$$14);
1290
- var _configUi = require$$15;
1291
- var _styles = require$$16;
1292
- var _Typography = _interopRequireDefault(require$$17);
1291
+ var _pick = _interopRequireDefault(require$$14);
1292
+ var _throttle = _interopRequireDefault(require$$15);
1293
+ var _editableHtml = _interopRequireWildcard(require$$16);
1294
+ var _configUi = require$$17;
1295
+ var _styles = require$$18;
1296
+ var _Typography = _interopRequireDefault(require$$19);
1293
1297
  var _ecrToolbar = _interopRequireDefault(ecrToolbar);
1294
1298
  var _alternateResponses = _interopRequireDefault(alternateResponses);
1295
1299
  var _markupUtils = markupUtils;
@@ -1483,7 +1487,7 @@ const require$$15 = _dll_pie_lib__config_ui;
1483
1487
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChangeResponse", function (index, newVal) {
1484
1488
  var _this$props3 = _this.props, model = _this$props3.model, onModelChanged = _this$props3.onModelChanged;
1485
1489
  var choices = model.choices, maxLengthPerChoice = model.maxLengthPerChoice;
1486
- var newValLength = (0, _markupUtils.getAdjustedLength)((newVal || '').length);
1490
+ var newValLength = (newVal || '').length;
1487
1491
  if (!choices[index]) {
1488
1492
  choices[index] = [{
1489
1493
  label: '',
@@ -1501,7 +1505,7 @@ const require$$15 = _dll_pie_lib__config_ui;
1501
1505
  }));
1502
1506
  });
1503
1507
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (markup) {
1504
- var _this$props$model = _this.props.model, choices = _this$props$model.choices, maxLengthPerChoice = _this$props$model.maxLengthPerChoice;
1508
+ var _this$props4 = _this.props, _this$props4$model = _this$props4.model, choices = _this$props4$model.choices, maxLengthPerChoice = _this$props4$model.maxLengthPerChoice, onModelChanged = _this$props4.onModelChanged;
1505
1509
  var domMarkup = createElementFromHTML(markup);
1506
1510
  var allRespAreas = domMarkup.querySelectorAll('[data-type="explicit_constructed_response"]');
1507
1511
  var allChoices = {};
@@ -1518,18 +1522,57 @@ const require$$15 = _dll_pie_lib__config_ui;
1518
1522
  allChoices[index] = newChoices;
1519
1523
  el.dataset.index = index;
1520
1524
  });
1521
- _this.props.onModelChanged(_objectSpread(_objectSpread({}, _this.props.model), {}, {
1522
- choices: allChoices,
1523
- slateMarkup: domMarkup.innerHTML,
1524
- maxLengthPerChoice: updatedMaxLengthPerChoice
1525
- }));
1525
+ var callback = function callback() {
1526
+ return onModelChanged(_objectSpread(_objectSpread({}, _this.props.model), {}, {
1527
+ choices: allChoices,
1528
+ slateMarkup: domMarkup.innerHTML,
1529
+ maxLengthPerChoice: updatedMaxLengthPerChoice
1530
+ }));
1531
+ };
1532
+ _this.setState({
1533
+ cachedChoices: undefined
1534
+ }, callback);
1526
1535
  });
1536
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onHandleAreaChange", (0, _throttle["default"])(function (nodes) {
1537
+ var _this$props5 = _this.props, choices = _this$props5.model.choices, onModelChanged = _this$props5.onModelChanged;
1538
+ var cachedChoices = _this.state.cachedChoices;
1539
+ if (!nodes) {
1540
+ return;
1541
+ }
1542
+ var newChoices = choices ? (0, _cloneDeep["default"])(choices) : {};
1543
+ var newCachedChoices = cachedChoices ? (0, _cloneDeep["default"])(cachedChoices) : {};
1544
+ nodes.forEach(function (node) {
1545
+ var keyForNode = node.data.get('index');
1546
+ if (!newChoices[keyForNode] && newCachedChoices[keyForNode]) {
1547
+ Object.assign(newChoices, (0, _pick["default"])(newCachedChoices, keyForNode));
1548
+ if (newCachedChoices.hasOwnProperty(keyForNode)) {
1549
+ delete newCachedChoices[keyForNode];
1550
+ }
1551
+ } else {
1552
+ Object.assign(newCachedChoices, (0, _pick["default"])(newChoices, keyForNode));
1553
+ if (newChoices.hasOwnProperty(keyForNode)) {
1554
+ delete newChoices[keyForNode];
1555
+ }
1556
+ }
1557
+ });
1558
+ var callback = function callback() {
1559
+ return onModelChanged(_objectSpread(_objectSpread({}, _this.props.model), {}, {
1560
+ choices: newChoices
1561
+ }));
1562
+ };
1563
+ _this.setState({
1564
+ cachedChoices: newCachedChoices
1565
+ }, callback);
1566
+ }, 500, {
1567
+ trailing: false,
1568
+ leading: true
1569
+ }));
1527
1570
  return _this;
1528
1571
  }
1529
1572
  (0, _createClass2["default"])(Main, [{
1530
1573
  key: "componentDidMount",
1531
1574
  value: function componentDidMount() {
1532
- var _this$props4 = this.props, _this$props4$model = _this$props4.model, slateMarkup = _this$props4$model.slateMarkup, choices = _this$props4$model.choices, _this$props4$model$ma = _this$props4$model.maxLengthPerChoice, maxLengthPerChoice = _this$props4$model$ma === void 0 ? [] : _this$props4$model$ma, onModelChanged = _this$props4.onModelChanged;
1575
+ var _this$props6 = this.props, _this$props6$model = _this$props6.model, slateMarkup = _this$props6$model.slateMarkup, choices = _this$props6$model.choices, _this$props6$model$ma = _this$props6$model.maxLengthPerChoice, maxLengthPerChoice = _this$props6$model$ma === void 0 ? [] : _this$props6$model$ma, onModelChanged = _this$props6.onModelChanged;
1533
1576
  var undefinedLengths = !maxLengthPerChoice.length;
1534
1577
  this.setState({
1535
1578
  markup: slateMarkup
@@ -1538,9 +1581,9 @@ const require$$15 = _dll_pie_lib__config_ui;
1538
1581
  var labelLengthsArr = (choice || []).map(function (choice) {
1539
1582
  return (choice.label || '').length;
1540
1583
  });
1541
- var length = (0, _markupUtils.getAdjustedLength)(Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr)));
1542
- if (undefinedLengths || !maxLengthPerChoice[index] || maxLengthPerChoice[index] < length) {
1543
- maxLengthPerChoice[index] = length;
1584
+ var length = Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr));
1585
+ if (undefinedLengths || !maxLengthPerChoice[index] || maxLengthPerChoice[index] < length || maxLengthPerChoice[index] > length + 10) {
1586
+ maxLengthPerChoice[index] = (0, _markupUtils.getAdjustedLength)(length);
1544
1587
  }
1545
1588
  });
1546
1589
  onModelChanged(_objectSpread(_objectSpread({}, this.props.model), {}, {
@@ -1551,7 +1594,7 @@ const require$$15 = _dll_pie_lib__config_ui;
1551
1594
  key: "render",
1552
1595
  value: function render() {
1553
1596
  var _this2 = this;
1554
- var _this$props5 = this.props, classes = _this$props5.classes, model = _this$props5.model, configuration = _this$props5.configuration, onConfigurationChanged = _this$props5.onConfigurationChanged, imageSupport = _this$props5.imageSupport;
1597
+ var _this$props7 = this.props, classes = _this$props7.classes, model = _this$props7.model, configuration = _this$props7.configuration, onConfigurationChanged = _this$props7.onConfigurationChanged, imageSupport = _this$props7.imageSupport;
1555
1598
  var _ref = configuration || ({}), _ref$prompt = _ref.prompt, prompt = _ref$prompt === void 0 ? {} : _ref$prompt, _ref$partialScoring = _ref.partialScoring, partialScoring = _ref$partialScoring === void 0 ? {} : _ref$partialScoring, _ref$rationale = _ref.rationale, rationale = _ref$rationale === void 0 ? {} : _ref$rationale, _ref$teacherInstructi = _ref.teacherInstructions, teacherInstructions = _ref$teacherInstructi === void 0 ? {} : _ref$teacherInstructi, _ref$maxLengthPerChoi = _ref.maxLengthPerChoice, maxLengthPerChoice = _ref$maxLengthPerChoi === void 0 ? {} : _ref$maxLengthPerChoi;
1556
1599
  var _ref2 = model || ({}), teacherInstructionsEnabled = _ref2.teacherInstructionsEnabled, promptEnabled = _ref2.promptEnabled, rationaleEnabled = _ref2.rationaleEnabled, maxLengthPerChoiceEnabled = _ref2.maxLengthPerChoiceEnabled;
1557
1600
  var toolbarOpts = {};
@@ -1634,7 +1677,8 @@ const require$$15 = _dll_pie_lib__config_ui;
1634
1677
  correctChoice: correctChoice
1635
1678
  });
1636
1679
  };
1637
- }
1680
+ },
1681
+ onHandleAreaChange: this.onHandleAreaChange
1638
1682
  },
1639
1683
  className: classes.markup,
1640
1684
  markup: model.slateMarkup,
@@ -21223,10 +21223,15 @@ function model(question, session, env) {
21223
21223
  // calculate maxLengthPerChoice array if it is not defined or defined incorrectly
21224
21224
  Object.values(choices).forEach((choice, index) => {
21225
21225
  const labelLengthsArr = (choice || []).map(choice => (choice.label || '').length);
21226
- const length = getAdjustedLength(Math.max(...labelLengthsArr));
21227
-
21228
- if (undefinedLengths || !maxLengthPerChoice[index] || maxLengthPerChoice[index] < length) {
21229
- maxLengthPerChoice[index] = length;
21226
+ const length = Math.max(...labelLengthsArr);
21227
+
21228
+ if (
21229
+ undefinedLengths
21230
+ || !maxLengthPerChoice[index]
21231
+ || maxLengthPerChoice[index] < length
21232
+ || maxLengthPerChoice[index] > length + 10
21233
+ ) {
21234
+ maxLengthPerChoice[index] = getAdjustedLength(length);
21230
21235
  }
21231
21236
  });
21232
21237
 
package/module/demo.js CHANGED
@@ -18,7 +18,7 @@ generate.model = (id, element) => ({
18
18
  1: [choice('over', '0'), choice('past', '1'), choice('beyond', '2')],
19
19
  2: [choice('moon', '0')]
20
20
  },
21
- maxLengthPerChoice: [10, 11, 7],
21
+ maxLengthPerChoice: [7, 10, 4],
22
22
  prompt: 'Complete the sentence',
23
23
  note: 'The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.',
24
24
  promptEnabled: true,
package/module/element.js CHANGED
@@ -1,6 +1,6 @@
1
- import {_dll_debug, _dll_lodash, _dll_react, _dll_react_dom_server, _dll_prop_types, _dll_material_ui__core_styles, _dll_material_ui__core, _dll_classnames, _dll_react_dom, _dll_pie_lib__render_ui, _dll_pie_lib__correct_answer_toggle} from "../../../@pie-lib/shared-module@^1.3.1/module/index.js";
2
- import {_dll_pie_lib__math_rendering} from "../../../@pie-lib/math-rendering-module@^1.0.24/module/index.js";
3
- import {_dll_pie_lib__drag} from "../../../@pie-lib/drag-module@^1.0.22/module/index.js";
1
+ import {_dll_debug, _dll_lodash, _dll_react, _dll_react_dom_server, _dll_prop_types, _dll_material_ui__core_styles, _dll_material_ui__core, _dll_classnames, _dll_react_dom, _dll_pie_lib__render_ui, _dll_pie_lib__correct_answer_toggle} from "../../../@pie-lib/shared-module@^1.4.1/module/index.js";
2
+ import {_dll_pie_lib__math_rendering} from "../../../@pie-lib/math-rendering-module@^1.0.26/module/index.js";
3
+ import {_dll_pie_lib__drag} from "../../../@pie-lib/drag-module@^1.0.24/module/index.js";
4
4
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
5
5
  var lib$1 = {};
6
6
  Object.defineProperty(lib$1, "__esModule", {
@@ -12976,6 +12976,12 @@ const rules = [marks, {
12976
12976
  ...normalAttrs
12977
12977
  });
12978
12978
  const object = getObject(type);
12979
+ if (el.tagName.toLowerCase() === 'math') {
12980
+ return {
12981
+ isMath: true,
12982
+ nodes: [el]
12983
+ };
12984
+ }
12979
12985
  return {
12980
12986
  object,
12981
12987
  type,
@@ -13040,6 +13046,19 @@ const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode)
13040
13046
  const children = [];
13041
13047
  (layout.nodes || []).forEach((n, index) => {
13042
13048
  const key = `${n.type}-${index}`;
13049
+ if (n.isMath) {
13050
+ children.push(React$c.createElement('span', {
13051
+ dangerouslySetInnerHTML: {
13052
+ __html: `<math>${n.nodes[0].innerHTML}</math>`
13053
+ },
13054
+ __self: undefined,
13055
+ __source: {
13056
+ fileName: _jsxFileName$b,
13057
+ lineNumber: 49
13058
+ }
13059
+ }));
13060
+ return children;
13061
+ }
13043
13062
  if (rootRenderChildren) {
13044
13063
  const c = rootRenderChildren(n, value, onChange);
13045
13064
  if (c) {
@@ -13063,7 +13082,7 @@ const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode)
13063
13082
  __self: undefined,
13064
13083
  __source: {
13065
13084
  fileName: _jsxFileName$b,
13066
- lineNumber: 70
13085
+ lineNumber: 77
13067
13086
  }
13068
13087
  }, content));
13069
13088
  break;
@@ -13080,7 +13099,7 @@ const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode)
13080
13099
  __self: undefined,
13081
13100
  __source: {
13082
13101
  fileName: _jsxFileName$b,
13083
- lineNumber: 80
13102
+ lineNumber: 87
13084
13103
  }
13085
13104
  }, subNodes));
13086
13105
  } else {
@@ -13092,7 +13111,7 @@ const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode)
13092
13111
  __self: undefined,
13093
13112
  __source: {
13094
13113
  fileName: _jsxFileName$b,
13095
- lineNumber: 85
13114
+ lineNumber: 92
13096
13115
  }
13097
13116
  }, subNodes));
13098
13117
  } else {
@@ -13102,7 +13121,7 @@ const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode)
13102
13121
  __self: undefined,
13103
13122
  __source: {
13104
13123
  fileName: _jsxFileName$b,
13105
- lineNumber: 90
13124
+ lineNumber: 97
13106
13125
  }
13107
13126
  }));
13108
13127
  }
@@ -13120,7 +13139,7 @@ const MaskContainer = withStyles$5(() => ({
13120
13139
  __self: undefined,
13121
13140
  __source: {
13122
13141
  fileName: _jsxFileName$b,
13123
- lineNumber: 102
13142
+ lineNumber: 109
13124
13143
  }
13125
13144
  }, props.children));
13126
13145
  class Mask extends React$c.Component {
@@ -13152,7 +13171,7 @@ class Mask extends React$c.Component {
13152
13171
  __self: this,
13153
13172
  __source: {
13154
13173
  fileName: _jsxFileName$b,
13155
- lineNumber: 124
13174
+ lineNumber: 131
13156
13175
  }
13157
13176
  }, children);
13158
13177
  }
package/module/index.html CHANGED
@@ -2,7 +2,7 @@
2
2
  <!doctype html>
3
3
  <html>
4
4
  <head>
5
- <title>@pie-element/explicit-constructed-response@3.12.1</title>
5
+ <title>@pie-element/explicit-constructed-response@3.12.2</title>
6
6
  <script
7
7
  type="module"
8
8
  src="https://cdn.jsdelivr.net/npm/@pslb/demo-el@^1.0.0/dist/demo-el/demo-el.esm.js"></script>
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@pie-element/explicit-constructed-response",
3
- "version": "3.12.1",
3
+ "version": "3.12.2",
4
4
  "modules": [
5
5
  {
6
6
  "name": "@pie-lib/shared-module",
7
- "version": "^1.3.1"
7
+ "version": "^1.4.1"
8
8
  },
9
9
  {
10
10
  "name": "@pie-lib/math-rendering-module",
11
- "version": "^1.0.24"
11
+ "version": "^1.0.26"
12
12
  },
13
13
  {
14
14
  "name": "@pie-lib/drag-module",
15
- "version": "^1.0.22"
15
+ "version": "^1.0.24"
16
16
  }
17
17
  ]
18
18
  }
@@ -16,7 +16,7 @@ generate.model = (id, element) => ({
16
16
  1: [choice('over', '0'), choice('past', '1'), choice('beyond', '2')],
17
17
  2: [choice('moon', '0')]
18
18
  },
19
- maxLengthPerChoice: [10, 11, 7],
19
+ maxLengthPerChoice: [7, 10, 4],
20
20
  prompt: 'Complete the sentence',
21
21
  note: 'The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.',
22
22
  promptEnabled: true,