@pie-element/drag-in-the-blank 3.9.0 → 3.9.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.
@@ -5,9 +5,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.getScore = exports.createCorrectResponseSession = void 0;
8
9
  exports.model = model;
10
+ exports.normalize = void 0;
9
11
  exports.outcome = outcome;
10
- exports.createCorrectResponseSession = exports.getScore = exports.normalize = void 0;
12
+ exports.validate = void 0;
11
13
 
12
14
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
15
 
@@ -23,9 +25,9 @@ var _utils = require("./utils");
23
25
 
24
26
  var _controllerUtils = require("@pie-lib/controller-utils");
25
27
 
26
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
28
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
27
29
 
28
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
30
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
29
31
 
30
32
  var normalize = function normalize(question) {
31
33
  return _objectSpread({
@@ -232,4 +234,44 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
232
234
  };
233
235
 
234
236
  exports.createCorrectResponseSession = createCorrectResponseSession;
237
+
238
+ var validate = function validate() {
239
+ var _Object$values;
240
+
241
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
242
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
243
+ var choices = model.choices,
244
+ correctResponse = model.correctResponse,
245
+ markup = model.markup;
246
+ var _config$minChoices = config.minChoices,
247
+ minChoices = _config$minChoices === void 0 ? 2 : _config$minChoices,
248
+ maxChoices = config.maxChoices,
249
+ maxResponseAreas = config.maxResponseAreas;
250
+ var errors = {};
251
+ var nbOfResponseAreas = ((markup || '').match(/\{\{(\d+)\}\}/g) || []).length;
252
+ var nbOfChoices = (choices || []).length;
253
+ var emptyResponseAreas = (_Object$values = Object.values(correctResponse)) === null || _Object$values === void 0 ? void 0 : _Object$values.filter(function (response) {
254
+ return !response;
255
+ });
256
+
257
+ if (emptyResponseAreas.length) {
258
+ errors.correctResponseError = 'There should be a choice defined for each response area.';
259
+ }
260
+
261
+ if (nbOfResponseAreas > maxResponseAreas) {
262
+ errors.responseAreasError = "No more than ".concat(maxResponseAreas, " response areas should be defined.");
263
+ } else if (nbOfResponseAreas < 1) {
264
+ errors.responseAreasError = 'There should be at least 1 response area defined.';
265
+ }
266
+
267
+ if (nbOfChoices < minChoices) {
268
+ errors.choicesError = "There should be at least ".concat(minChoices, " tokens defined.");
269
+ } else if (nbOfChoices > maxChoices) {
270
+ errors.choicesError = "No more than ".concat(maxChoices, " tokens should be defined.");
271
+ }
272
+
273
+ return errors;
274
+ };
275
+
276
+ exports.validate = validate;
235
277
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["normalize","question","rationaleEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","model","session","env","updateSession","Promise","resolve","normalizedQuestion","feedback","mode","responses","allCorrectResponses","possibleResponses","numberOfPossibleResponses","correctResponses","undefined","value","i","result","obj","choices","key","answer","filter","choice","lockChoiceOrder","out","prompt","disabled","responseCorrect","getScore","role","rationale","teacherInstructions","config","maxScore","Object","keys","correctResponse","length","correctCount","total","str","toFixed","parseFloat","outcome","partialScoringEnabled","partialScoring","enabled","score","empty","createCorrectResponseSession","id"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;AAEO,IAAMA,SAAS,GAAG,SAAZA,SAAY,CAAAC,QAAQ;AAAA;AAC/BC,IAAAA,gBAAgB,EAAE,IADa;AAE/BC,IAAAA,aAAa,EAAE,IAFgB;AAG/BC,IAAAA,0BAA0B,EAAE,IAHG;AAI/BC,IAAAA,0BAA0B,EAAE;AAJG,KAK5BJ,QAL4B;AAAA,CAA1B;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASK,KAAT,CAAeL,QAAf,EAAyBM,OAAzB,EAAkCC,GAAlC,EAAuCC,aAAvC,EAAsD;AAC3D,SAAO,IAAIC,OAAJ;AAAA,6FAAY,iBAAMC,OAAN;AAAA;AAAA;AAAA;AAAA;AAAA;AACXC,cAAAA,kBADW,GACUZ,SAAS,CAACC,QAAD,CADnB;AAEbY,cAAAA,QAFa,GAEF,EAFE;;AAIjB,kBAAIL,GAAG,CAACM,IAAJ,KAAa,UAAjB,EAA6B;AAAA;AAC3B,sBAAMC,SAAS,GAAG,mCAAuBH,kBAAvB,KAA8C,EAAhE;AACA,sBAAMI,mBAAmB,GAA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AACF,GATM,CAAP;AAUD,CAXM","sourcesContent":["import reduce from 'lodash/reduce';\nimport isEmpty from 'lodash/isEmpty';\nimport { getAllCorrectResponses, choiceIsEmpty } from './utils';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\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 * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport function model(question, session, env, updateSession) {\n return new Promise(async resolve => {\n const normalizedQuestion = normalize(question);\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n const responses = getAllCorrectResponses(normalizedQuestion) || {};\n const allCorrectResponses = responses.possibleResponses;\n const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;\n let correctResponses = undefined;\n const { value } = session || {};\n\n for (let i = 0; i < numberOfPossibleResponses; i++) {\n const result = reduce(allCorrectResponses, (obj, choices, key) => {\n const answer = (value && value[key]) || '';\n\n obj.feedback[key] = choices[i] === answer;\n\n if (obj.feedback[key]) {\n obj.correctResponses += 1;\n }\n\n return obj;\n }, { correctResponses: 0, feedback: {} });\n\n if (correctResponses === undefined || result.correctResponses > correctResponses) {\n correctResponses = result.correctResponses;\n feedback = result.feedback;\n }\n\n if (result.correctResponses === numberOfPossibleResponses) {\n break;\n }\n }\n }\n\n let choices = normalizedQuestion.choices && normalizedQuestion.choices.filter(choice => !choiceIsEmpty(choice));\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'id');\n }\n\n const out = {\n ...normalizedQuestion,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n choices,\n feedback,\n mode: env.mode,\n disabled: env.mode !== 'gather',\n responseCorrect:\n env.mode === 'evaluate'\n ? getScore(normalizedQuestion, session) === 1\n : 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\nexport const getScore = (config, session) => {\n const responses = getAllCorrectResponses(config);\n const allCorrectResponses = responses.possibleResponses;\n const maxScore = Object.keys(config.correctResponse).length;\n const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;\n let correctCount = 0;\n const { value } = session || {};\n\n for (let i = 0; i < numberOfPossibleResponses; i++) {\n const result = reduce(allCorrectResponses, (total, choices, key) => {\n const answer = (value && value[key]) || '';\n\n if (choices[i] === answer) {\n return total;\n }\n\n return total - 1;\n }, maxScore);\n\n if (result > correctCount) {\n correctCount = result;\n }\n\n if (result === maxScore) {\n break;\n }\n }\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({\n score: partialScoringEnabled ? score : score === 1 ? 1 : 0,\n empty: !session || isEmpty(session)\n });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n value: question.correctResponse,\n id: '1'\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["normalize","question","rationaleEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","model","session","env","updateSession","Promise","resolve","normalizedQuestion","feedback","mode","responses","allCorrectResponses","possibleResponses","numberOfPossibleResponses","correctResponses","undefined","value","i","result","obj","choices","key","answer","filter","choice","lockChoiceOrder","out","prompt","disabled","responseCorrect","getScore","role","rationale","teacherInstructions","config","maxScore","Object","keys","correctResponse","length","correctCount","total","str","toFixed","parseFloat","outcome","partialScoringEnabled","partialScoring","enabled","score","empty","createCorrectResponseSession","id","validate","markup","minChoices","maxChoices","maxResponseAreas","errors","nbOfResponseAreas","match","nbOfChoices","emptyResponseAreas","values","response","correctResponseError","responseAreasError","choicesError"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;AAEO,IAAMA,SAAS,GAAG,SAAZA,SAAY,CAACC,QAAD;AAAA;AACvBC,IAAAA,gBAAgB,EAAE,IADK;AAEvBC,IAAAA,aAAa,EAAE,IAFQ;AAGvBC,IAAAA,0BAA0B,EAAE,IAHL;AAIvBC,IAAAA,0BAA0B,EAAE;AAJL,KAKpBJ,QALoB;AAAA,CAAlB;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASK,KAAT,CAAeL,QAAf,EAAyBM,OAAzB,EAAkCC,GAAlC,EAAuCC,aAAvC,EAAsD;AAC3D,SAAO,IAAIC,OAAJ;AAAA,6FAAY,iBAAOC,OAAP;AAAA;AAAA;AAAA;AAAA;AAAA;AACXC,cAAAA,kBADW,GACUZ,SAAS,CAACC,QAAD,CADnB;AAEbY,cAAAA,QAFa,GAEF,EAFE;;AAIjB,kBAAIL,GAAG,CAACM,IAAJ,KAAa,UAAjB,EAA6B;AAAA;AAC3B,sBAAMC,SAAS,GAAG,mCAAuBH,kBAAvB,KAA8C,EAAhE;AACA,sBAAMI,mBAAmB,GAAGD,SAAS,CAAC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,CAACS,YAAP,sCAAkDZ,UAAlD;AACD,GAFD,MAEO,IAAIM,WAAW,GAAGL,UAAlB,EAA8B;AACnCE,IAAAA,MAAM,CAACS,YAAP,0BAAsCX,UAAtC;AACD;;AAED,SAAOE,MAAP;AACD,CA1BM","sourcesContent":["import reduce from 'lodash/reduce';\nimport isEmpty from 'lodash/isEmpty';\nimport { getAllCorrectResponses, choiceIsEmpty } from './utils';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\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 * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport function model(question, session, env, updateSession) {\n return new Promise(async (resolve) => {\n const normalizedQuestion = normalize(question);\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n const responses = getAllCorrectResponses(normalizedQuestion) || {};\n const allCorrectResponses = responses.possibleResponses;\n const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;\n let correctResponses = undefined;\n const { value } = session || {};\n\n for (let i = 0; i < numberOfPossibleResponses; i++) {\n const result = reduce(\n allCorrectResponses,\n (obj, choices, key) => {\n const answer = (value && value[key]) || '';\n\n obj.feedback[key] = choices[i] === answer;\n\n if (obj.feedback[key]) {\n obj.correctResponses += 1;\n }\n\n return obj;\n },\n { correctResponses: 0, feedback: {} },\n );\n\n if (correctResponses === undefined || result.correctResponses > correctResponses) {\n correctResponses = result.correctResponses;\n feedback = result.feedback;\n }\n\n if (result.correctResponses === numberOfPossibleResponses) {\n break;\n }\n }\n }\n\n let choices = normalizedQuestion.choices && normalizedQuestion.choices.filter((choice) => !choiceIsEmpty(choice));\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'id');\n }\n\n const out = {\n ...normalizedQuestion,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n choices,\n feedback,\n mode: env.mode,\n disabled: env.mode !== 'gather',\n responseCorrect: env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined,\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 }\n\n resolve(out);\n });\n}\n\nexport const getScore = (config, session) => {\n const responses = getAllCorrectResponses(config);\n const allCorrectResponses = responses.possibleResponses;\n const maxScore = Object.keys(config.correctResponse).length;\n const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;\n let correctCount = 0;\n const { value } = session || {};\n\n for (let i = 0; i < numberOfPossibleResponses; i++) {\n const result = reduce(\n allCorrectResponses,\n (total, choices, key) => {\n const answer = (value && value[key]) || '';\n\n if (choices[i] === answer) {\n return total;\n }\n\n return total - 1;\n },\n maxScore,\n );\n\n if (result > correctCount) {\n correctCount = result;\n }\n\n if (result === maxScore) {\n break;\n }\n }\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({\n score: partialScoringEnabled ? score : score === 1 ? 1 : 0,\n empty: !session || isEmpty(session),\n });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n value: question.correctResponse,\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { choices, correctResponse, markup } = model;\n const { minChoices = 2, maxChoices, maxResponseAreas } = config;\n const errors = {};\n\n const nbOfResponseAreas = ((markup || '').match(/\\{\\{(\\d+)\\}\\}/g) || []).length;\n const nbOfChoices = (choices || []).length;\n const emptyResponseAreas = Object.values(correctResponse)?.filter((response) => !response);\n\n if (emptyResponseAreas.length) {\n errors.correctResponseError = 'There should be a choice defined for each response area.';\n }\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 if (nbOfChoices < minChoices) {\n errors.choicesError = `There should be at least ${minChoices} tokens defined.`;\n } else if (nbOfChoices > maxChoices) {\n errors.choicesError = `No more than ${maxChoices} tokens should be defined.`;\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.choiceIsEmpty = exports.getAllCorrectResponses = void 0;
8
+ exports.getAllCorrectResponses = exports.choiceIsEmpty = void 0;
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["replaceHtmlRegex","getAllCorrectResponses","correctResponse","alternateResponses","obj","val","key","possibleResponses","numberOfPossibleResponses","undefined","length","choiceIsEmpty","choice","value","withoutEmptyTags","replace","trim"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA,IAA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AACD,CATM","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\nimport reduce from 'lodash/reduce';\n\nconst replaceHtmlRegex = /<(?!img)[^>]*>?/gm;\n\nexport const getAllCorrectResponses = ({ correctResponse, alternateResponses }) => {\n return reduce(correctResponse || {}, (obj, val, key) => {\n obj.possibleResponses[key] = [val];\n\n if (alternateResponses && alternateResponses[key]) {\n obj.possibleResponses[key] = [\n ...obj.possibleResponses[key],\n ...cloneDeep(alternateResponses[key])\n ];\n }\n\n if (\n (obj.numberOfPossibleResponses === undefined) ||\n (obj.numberOfPossibleResponses > obj.possibleResponses[key].length)\n ) {\n obj.numberOfPossibleResponses = obj.possibleResponses[key].length;\n }\n\n return obj;\n }, {\n possibleResponses: {},\n numberOfPossibleResponses: undefined\n });\n};\n\nexport const choiceIsEmpty = choice => {\n if (choice) {\n const { value = '' } = choice;\n const withoutEmptyTags = value.replace(replaceHtmlRegex, '') || '';\n\n return withoutEmptyTags.trim() === '';\n }\n\n return false;\n};\n"],"file":"utils.js"}
1
+ {"version":3,"sources":["../src/utils.js"],"names":["replaceHtmlRegex","getAllCorrectResponses","correctResponse","alternateResponses","obj","val","key","possibleResponses","numberOfPossibleResponses","undefined","length","choiceIsEmpty","choice","value","withoutEmptyTags","replace","trim"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA,IAAMA,gBAAgB,GAAG,mBAAzB;;AAEO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,OAA6C;AAAA,MAA1CC,eAA0C,QAA1CA,eAA0C;AAAA,MAAzBC,kBAAyB,QAAzBA,kBAAyB;AACjF,SAAO,wBACLD,eAAe,IAAI,EADd,EAEL,UAACE,GAAD,EAAMC,GAAN,EAAWC,GAAX,EAAmB;AACjBF,IAAAA,GAAG,CAACG,iBAAJ,CAAsBD,GAAtB,IAA6B,CAACD,GAAD,CAA7B;;AAEA,QAAIF,kBAAkB,IAAIA,kBAAkB,CAACG,GAAD,CAA5C,EAAmD;AACjDF,MAAAA,GAAG,CAACG,iBAAJ,CAAsBD,GAAtB,kDAAiCF,GAAG,CAACG,iBAAJ,CAAsBD,GAAtB,CAAjC,uCAAgE,2BAAUH,kBAAkB,CAACG,GAAD,CAA5B,CAAhE;AACD;;AAED,QACEF,GAAG,CAACI,yBAAJ,KAAkCC,SAAlC,IACAL,GAAG,CAACI,yBAAJ,GAAgCJ,GAAG,CAACG,iBAAJ,CAAsBD,GAAtB,EAA2BI,MAF7D,EAGE;AACAN,MAAAA,GAAG,CAACI,yBAAJ,GAAgCJ,GAAG,CAACG,iBAAJ,CAAsBD,GAAtB,EAA2BI,MAA3D;AACD;;AAED,WAAON,GAAP;AACD,GAjBI,EAkBL;AACEG,IAAAA,iBAAiB,EAAE,EADrB;AAEEC,IAAAA,yBAAyB,EAAEC;AAF7B,GAlBK,CAAP;AAuBD,CAxBM;;;;AA0BA,IAAME,aAAa,GAAG,SAAhBA,aAAgB,CAACC,MAAD,EAAY;AACvC,MAAIA,MAAJ,EAAY;AACV,wBAAuBA,MAAvB,CAAQC,KAAR;AAAA,QAAQA,KAAR,8BAAgB,EAAhB;AACA,QAAMC,gBAAgB,GAAGD,KAAK,CAACE,OAAN,CAAcf,gBAAd,EAAgC,EAAhC,KAAuC,EAAhE;AAEA,WAAOc,gBAAgB,CAACE,IAAjB,OAA4B,EAAnC;AACD;;AAED,SAAO,KAAP;AACD,CATM","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\nimport reduce from 'lodash/reduce';\n\nconst replaceHtmlRegex = /<(?!img)[^>]*>?/gm;\n\nexport const getAllCorrectResponses = ({ correctResponse, alternateResponses }) => {\n return reduce(\n correctResponse || {},\n (obj, val, key) => {\n obj.possibleResponses[key] = [val];\n\n if (alternateResponses && alternateResponses[key]) {\n obj.possibleResponses[key] = [...obj.possibleResponses[key], ...cloneDeep(alternateResponses[key])];\n }\n\n if (\n obj.numberOfPossibleResponses === undefined ||\n obj.numberOfPossibleResponses > obj.possibleResponses[key].length\n ) {\n obj.numberOfPossibleResponses = obj.possibleResponses[key].length;\n }\n\n return obj;\n },\n {\n possibleResponses: {},\n numberOfPossibleResponses: undefined,\n },\n );\n};\n\nexport const choiceIsEmpty = (choice) => {\n if (choice) {\n const { value = '' } = choice;\n const withoutEmptyTags = value.replace(replaceHtmlRegex, '') || '';\n\n return withoutEmptyTags.trim() === '';\n }\n\n return false;\n};\n"],"file":"utils.js"}
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@pie-element/drag-in-the-blank-controller",
3
3
  "private": true,
4
- "version": "3.3.13",
4
+ "version": "4.0.3",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
- "@pie-lib/controller-utils": "^0.2.24",
11
+ "@pie-lib/controller-utils": "^0.2.42",
12
12
  "debug": "^3.1.0",
13
13
  "lodash": "^4.17.15",
14
14
  "type-of": "^2.0.1"
@@ -51,6 +51,27 @@
51
51
  }
52
52
  }
53
53
  },
54
+ "settingsPanelDisabled": {
55
+ "description": "Indicates if the settings panel is not available",
56
+ "type": "boolean",
57
+ "title": "settingsPanelDisabled"
58
+ },
59
+ "spellCheck": {
60
+ "title": "ConfigureProp",
61
+ "type": "object",
62
+ "properties": {
63
+ "settings": {
64
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
65
+ "type": "boolean",
66
+ "title": "settings"
67
+ },
68
+ "label": {
69
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
70
+ "type": "string",
71
+ "title": "label"
72
+ }
73
+ }
74
+ },
54
75
  "rationale": {
55
76
  "title": "ConfigureProp",
56
77
  "type": "object",
@@ -115,6 +136,79 @@
115
136
  }
116
137
  }
117
138
  },
139
+ "minChoices": {
140
+ "description": "Minimum number of choices",
141
+ "type": "number",
142
+ "title": "minChoices"
143
+ },
144
+ "maxChoices": {
145
+ "description": "Maximum number of choices",
146
+ "type": "number",
147
+ "title": "maxChoices"
148
+ },
149
+ "maxResponseAreas": {
150
+ "description": "Maximum number of response areas",
151
+ "type": "number",
152
+ "title": "maxResponseAreas"
153
+ },
154
+ "maxImageWidth": {
155
+ "title": "ConfigureMaxImageDimensionsProp",
156
+ "type": "object",
157
+ "properties": {
158
+ "teacherInstructions": {
159
+ "description": "Indicates the max dimension for images in teacher instructions",
160
+ "type": "number",
161
+ "title": "teacherInstructions"
162
+ },
163
+ "prompt": {
164
+ "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",
165
+ "type": "number",
166
+ "title": "prompt"
167
+ },
168
+ "rationale": {
169
+ "description": "Indicates the max dimension for images in rationale",
170
+ "type": "number",
171
+ "title": "rationale"
172
+ }
173
+ }
174
+ },
175
+ "maxImageHeight": {
176
+ "title": "ConfigureMaxImageDimensionsProp",
177
+ "type": "object",
178
+ "properties": {
179
+ "teacherInstructions": {
180
+ "description": "Indicates the max dimension for images in teacher instructions",
181
+ "type": "number",
182
+ "title": "teacherInstructions"
183
+ },
184
+ "prompt": {
185
+ "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",
186
+ "type": "number",
187
+ "title": "prompt"
188
+ },
189
+ "rationale": {
190
+ "description": "Indicates the max dimension for images in rationale",
191
+ "type": "number",
192
+ "title": "rationale"
193
+ }
194
+ }
195
+ },
196
+ "withRubric": {
197
+ "title": "ConfigureProp",
198
+ "type": "object",
199
+ "properties": {
200
+ "settings": {
201
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
202
+ "type": "boolean",
203
+ "title": "settings"
204
+ },
205
+ "label": {
206
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
207
+ "type": "string",
208
+ "title": "label"
209
+ }
210
+ }
211
+ },
118
212
  "showPrompt": {
119
213
  "description": "Determines whether prompt field will be displayed or not",
120
214
  "default": true,
@@ -150,6 +244,27 @@
150
244
  "title": "label"
151
245
  }
152
246
  }
247
+ },
248
+ "ConfigureMaxImageDimensionsProp": {
249
+ "title": "ConfigureMaxImageDimensionsProp",
250
+ "type": "object",
251
+ "properties": {
252
+ "teacherInstructions": {
253
+ "description": "Indicates the max dimension for images in teacher instructions",
254
+ "type": "number",
255
+ "title": "teacherInstructions"
256
+ },
257
+ "prompt": {
258
+ "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",
259
+ "type": "number",
260
+ "title": "prompt"
261
+ },
262
+ "rationale": {
263
+ "description": "Indicates the max dimension for images in rationale",
264
+ "type": "number",
265
+ "title": "rationale"
266
+ }
267
+ }
153
268
  }
154
269
  },
155
270
  "$schema": "http://json-schema.org/draft-07/schema#"
@@ -38,6 +38,22 @@ Indicates if the item has to be displayed in the Settings Panel
38
38
 
39
39
  Indicates the label for the item that has to be displayed in the Settings Panel
40
40
 
41
+ # `settingsPanelDisabled` (boolean)
42
+
43
+ Indicates if the settings panel is not available
44
+
45
+ # `spellCheck` (object)
46
+
47
+ Properties of the `spellCheck` object:
48
+
49
+ ## `settings` (boolean)
50
+
51
+ Indicates if the item has to be displayed in the Settings Panel
52
+
53
+ ## `label` (string)
54
+
55
+ Indicates the label for the item that has to be displayed in the Settings Panel
56
+
41
57
  # `rationale` (object)
42
58
 
43
59
  Properties of the `rationale` object:
@@ -86,6 +102,62 @@ 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
+ # `minChoices` (number)
106
+
107
+ Minimum number of choices
108
+
109
+ # `maxChoices` (number)
110
+
111
+ Maximum number of choices
112
+
113
+ # `maxResponseAreas` (number)
114
+
115
+ Maximum number of response areas
116
+
117
+ # `maxImageWidth` (object)
118
+
119
+ Properties of the `maxImageWidth` object:
120
+
121
+ ## `teacherInstructions` (number)
122
+
123
+ Indicates the max dimension for images in teacher instructions
124
+
125
+ ## `prompt` (number)
126
+
127
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
128
+
129
+ ## `rationale` (number)
130
+
131
+ Indicates the max dimension for images in rationale
132
+
133
+ # `maxImageHeight` (object)
134
+
135
+ Properties of the `maxImageHeight` object:
136
+
137
+ ## `teacherInstructions` (number)
138
+
139
+ Indicates the max dimension for images in teacher instructions
140
+
141
+ ## `prompt` (number)
142
+
143
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
144
+
145
+ ## `rationale` (number)
146
+
147
+ Indicates the max dimension for images in rationale
148
+
149
+ # `withRubric` (object)
150
+
151
+ Properties of the `withRubric` object:
152
+
153
+ ## `settings` (boolean)
154
+
155
+ Indicates if the item has to be displayed in the Settings Panel
156
+
157
+ ## `label` (string)
158
+
159
+ Indicates the label for the item that has to be displayed in the Settings Panel
160
+
89
161
  # `showPrompt` (boolean)
90
162
 
91
163
  Determines whether prompt field will be displayed or not
@@ -120,4 +192,20 @@ Indicates if the item has to be displayed in the Settings Panel
120
192
 
121
193
  ### `label` (string)
122
194
 
123
- Indicates the label for the item that has to be displayed in the Settings Panel
195
+ Indicates the label for the item that has to be displayed in the Settings Panel
196
+
197
+ ## `ConfigureMaxImageDimensionsProp` (object)
198
+
199
+ Properties of the `ConfigureMaxImageDimensionsProp` object:
200
+
201
+ ### `teacherInstructions` (number)
202
+
203
+ Indicates the max dimension for images in teacher instructions
204
+
205
+ ### `prompt` (number)
206
+
207
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
208
+
209
+ ### `rationale` (number)
210
+
211
+ Indicates the max dimension for images in rationale
@@ -2,7 +2,7 @@ const { model } = require('./generate');
2
2
 
3
3
  module.exports = {
4
4
  elements: {
5
- 'drag-in-the-blank': '../..'
5
+ 'drag-in-the-blank': '../..',
6
6
  },
7
- models: [model('1', 'drag-in-the-blank')]
7
+ models: [model('1', 'drag-in-the-blank')],
8
8
  };
@@ -1,38 +1,41 @@
1
1
  exports.model = (id, element) => ({
2
2
  id,
3
3
  element,
4
- 'rationaleEnabled': true,
5
- 'promptEnabled': true,
6
- 'teacherInstructionsEnabled': true,
7
- 'studentInstructionsEnabled': true,
8
- 'rationale': null,
9
- 'prompt': '<p>Drag and drop the correct array into the box next to the matching word problem.</p>',
10
- 'lockChoiceOrder': true,
11
- 'choicesPosition': 'below',
12
- 'partialScoring': true,
13
- 'choices': [
4
+ rationaleEnabled: true,
5
+ promptEnabled: true,
6
+ teacherInstructionsEnabled: true,
7
+ studentInstructionsEnabled: true,
8
+ rationale: null,
9
+ prompt: '<p>Drag and drop the correct array into the box next to the matching word problem.</p>',
10
+ lockChoiceOrder: true,
11
+ choicesPosition: 'below',
12
+ partialScoring: true,
13
+ choices: [
14
14
  {
15
- 'id':'0',
16
- 'value':'<img alt="" src="https://app.fluence.net/ia/image/3099cb73d5fe400b91b72f2606d1211c" />'
15
+ id: '0',
16
+ value: '<img alt="" src="https://app.fluence.net/ia/image/3099cb73d5fe400b91b72f2606d1211c" />',
17
17
  },
18
18
  {
19
- 'id':'1',
20
- 'value':'<img alt="" src="https://app.fluence.net/ia/image/cc6e862dad4749d4a1ae6540ea775179" />'
19
+ id: '1',
20
+ value: '<img alt="" src="https://app.fluence.net/ia/image/cc6e862dad4749d4a1ae6540ea775179" />',
21
21
  },
22
22
  {
23
- 'id':'2',
24
- 'value':'<img alt="" src="https://app.fluence.net/ia/image/ab3e342a466941a1a608f65eb7ec1c68" />'
25
- }
23
+ id: '2',
24
+ value: '<img alt="" src="https://app.fluence.net/ia/image/ab3e342a466941a1a608f65eb7ec1c68" />',
25
+ },
26
26
  ],
27
- 'markup': '<table class="table table-bordered table-striped">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td class="text-center"><strong>Word Problem</strong></td>\n\t\t\t<td class="text-center"><strong>Array</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p>Jamie is buying color pencils for an art project. There are 8 colored pencils in each pack. She buys 3 packs of colored pencils. How many colored pencils did she buy for her art project?</p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>{{0}}</p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p>Mark has 36 jelly beans to split between 9 friends. How many jelly beans will each friend get?</p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>{{1}}</p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p>Mr. Smith drinks 5 bottles of water each day. If there are 7 days in a week, how many bottles of water does Mr. Smith drink in 1 week?</p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>{{2}}</p>\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n',
28
- 'correctResponse': {
29
- '0': '1',
30
- '1': '0',
31
- '2': '2'
27
+ markup:
28
+ '<table class="table table-bordered table-striped">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td class="text-center"><strong>Word Problem</strong></td>\n\t\t\t<td class="text-center"><strong>Array</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p>Jamie is buying color pencils for an art project. There are 8 colored pencils in each pack. She buys 3 packs of colored pencils. How many colored pencils did she buy for her art project?</p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>{{0}}</p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p>Mark has 36 jelly beans to split between 9 friends. How many jelly beans will each friend get?</p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>{{1}}</p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p>Mr. Smith drinks 5 bottles of water each day. If there are 7 days in a week, how many bottles of water does Mr. Smith drink in 1 week?</p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>{{2}}</p>\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n',
29
+ correctResponse: {
30
+ 0: '1',
31
+ 1: '0',
32
+ 2: '2',
32
33
  },
33
- 'duplicates': false,
34
- 'feedback': {},
35
- 'mode': 'gather',
36
- 'disabled': false,
37
- 'teacherInstructions': null
34
+ duplicates: false,
35
+ feedback: {},
36
+ mode: 'gather',
37
+ disabled: false,
38
+ teacherInstructions: null,
39
+ toolbarEditorPosition: 'bottom',
40
+ rubricEnabled: false,
38
41
  });
@@ -75,6 +75,11 @@
75
75
  "type": "string",
76
76
  "title": "markup"
77
77
  },
78
+ "lockChoiceOrder": {
79
+ "description": "Indicates if the choices are presented in a fixed order",
80
+ "type": "boolean",
81
+ "title": "lockChoiceOrder"
82
+ },
78
83
  "prompt": {
79
84
  "description": "The item stem for the question",
80
85
  "type": "string",
@@ -110,6 +115,11 @@
110
115
  "type": "boolean",
111
116
  "title": "rationaleEnabled"
112
117
  },
118
+ "spellCheckEnabled": {
119
+ "description": "Indicates if spellcheck is enabled for the author. Default value is true",
120
+ "type": "boolean",
121
+ "title": "spellCheckEnabled"
122
+ },
113
123
  "studentInstructionsEnabled": {
114
124
  "description": "Indicates if Student Instructions are enabled",
115
125
  "type": "boolean",
@@ -120,6 +130,21 @@
120
130
  "type": "boolean",
121
131
  "title": "teacherInstructionsEnabled"
122
132
  },
133
+ "toolbarEditorPosition": {
134
+ "description": "Indicates the editor's toolbar position which can be 'bottom' or 'top'",
135
+ "default": ": 'bottom'",
136
+ "enum": [
137
+ "bottom",
138
+ "top"
139
+ ],
140
+ "type": "string",
141
+ "title": "toolbarEditorPosition"
142
+ },
143
+ "rubricEnabled": {
144
+ "description": "Indicates if Rubric is enabled",
145
+ "type": "boolean",
146
+ "title": "rubricEnabled"
147
+ },
123
148
  "id": {
124
149
  "description": "Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.",
125
150
  "type": "string",
@@ -136,10 +161,13 @@
136
161
  "correctResponse",
137
162
  "element",
138
163
  "id",
164
+ "lockChoiceOrder",
139
165
  "markup",
140
166
  "rationale",
141
167
  "rationaleEnabled",
142
168
  "rubric",
169
+ "rubricEnabled",
170
+ "spellCheckEnabled",
143
171
  "studentInstructionsEnabled",
144
172
  "teacherInstructionsEnabled"
145
173
  ],
@@ -160,6 +188,27 @@
160
188
  }
161
189
  }
162
190
  },
191
+ "ConfigureMaxImageDimensionsProp": {
192
+ "title": "ConfigureMaxImageDimensionsProp",
193
+ "type": "object",
194
+ "properties": {
195
+ "teacherInstructions": {
196
+ "description": "Indicates the max dimension for images in teacher instructions",
197
+ "type": "number",
198
+ "title": "teacherInstructions"
199
+ },
200
+ "prompt": {
201
+ "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",
202
+ "type": "number",
203
+ "title": "prompt"
204
+ },
205
+ "rationale": {
206
+ "description": "Indicates the max dimension for images in rationale",
207
+ "type": "number",
208
+ "title": "rationale"
209
+ }
210
+ }
211
+ },
163
212
  "Choice": {
164
213
  "title": "Choice",
165
214
  "type": "object",
@@ -49,6 +49,10 @@ Indicates if duplicates are enabled
49
49
 
50
50
  The markup for the pie-ui element
51
51
 
52
+ # `lockChoiceOrder` (boolean, required)
53
+
54
+ Indicates if the choices are presented in a fixed order
55
+
52
56
  # `prompt` (string)
53
57
 
54
58
  The item stem for the question
@@ -77,6 +81,10 @@ Indicates value for rubric
77
81
 
78
82
  Indicates if Rationale are enabled
79
83
 
84
+ # `spellCheckEnabled` (boolean, required)
85
+
86
+ Indicates if spellcheck is enabled for the author. Default value is true
87
+
80
88
  # `studentInstructionsEnabled` (boolean, required)
81
89
 
82
90
  Indicates if Student Instructions are enabled
@@ -85,6 +93,21 @@ Indicates if Student Instructions are enabled
85
93
 
86
94
  Indicates if Teacher Instructions are enabled
87
95
 
96
+ # `toolbarEditorPosition` (string, enum)
97
+
98
+ Indicates the editor's toolbar position which can be 'bottom' or 'top'
99
+
100
+ This element must be one of the following enum values:
101
+
102
+ * `bottom`
103
+ * `top`
104
+
105
+ Default: `": 'bottom'"`
106
+
107
+ # `rubricEnabled` (boolean, required)
108
+
109
+ Indicates if Rubric is enabled
110
+
88
111
  # `id` (string, required)
89
112
 
90
113
  Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.
@@ -111,6 +134,22 @@ Indicates if the item has to be displayed in the Settings Panel
111
134
 
112
135
  Indicates the label for the item that has to be displayed in the Settings Panel
113
136
 
137
+ ## `ConfigureMaxImageDimensionsProp` (object)
138
+
139
+ Properties of the `ConfigureMaxImageDimensionsProp` object:
140
+
141
+ ### `teacherInstructions` (number)
142
+
143
+ Indicates the max dimension for images in teacher instructions
144
+
145
+ ### `prompt` (number)
146
+
147
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
148
+
149
+ ### `rationale` (number)
150
+
151
+ Indicates the max dimension for images in rationale
152
+
114
153
  ## `Choice` (object)
115
154
 
116
155
  Properties of the `Choice` object: