@pie-element/inline-dropdown 3.8.0 → 3.8.3-next.1014

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
 
@@ -25,9 +27,9 @@ var _controllerUtils = require("@pie-lib/controller-utils");
25
27
 
26
28
  var _utils = require("./utils");
27
29
 
28
- 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; }
30
+ 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; }
29
31
 
30
- 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; }
32
+ 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; }
31
33
 
32
34
  var getFeedback = function getFeedback(correct) {
33
35
  if (correct) {
@@ -42,7 +44,8 @@ var normalize = function normalize(question) {
42
44
  promptEnabled: true,
43
45
  rationaleEnabled: true,
44
46
  teacherInstructionsEnabled: true,
45
- studentInstructionsEnabled: true
47
+ studentInstructionsEnabled: true,
48
+ choiceRationaleEnabled: true
46
49
  }, question);
47
50
  };
48
51
  /**
@@ -59,7 +62,7 @@ exports.normalize = normalize;
59
62
  function model(question, session, env, updateSession) {
60
63
  return new Promise( /*#__PURE__*/function () {
61
64
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
62
- var normalizedQuestion, _ref2, _ref2$value, value, choices, feedback, allCorrectResponses, respAreaLength, correctResponses, _loop, i, _ret, lockChoiceOrder, keys, _i, key, teacherInstructions, rationale, out;
65
+ var normalizedQuestion, _ref2, _ref2$value, value, choices, feedback, allCorrectResponses, respAreaLength, correctResponses, _loop, i, _ret, lockChoiceOrder, keys, _i, key, teacherInstructions, rationale, choicesWillNullRationales, out;
63
66
 
64
67
  return _regenerator["default"].wrap(function _callee$(_context) {
65
68
  while (1) {
@@ -165,19 +168,30 @@ function model(question, session, env, updateSession) {
165
168
  case 29:
166
169
  teacherInstructions = null;
167
170
  rationale = null;
171
+ choicesWillNullRationales = (Object.keys(choices) || []).reduce(function (acc, currentValue) {
172
+ acc[currentValue] = (choices[currentValue] || []).map(function (choice) {
173
+ return _objectSpread(_objectSpread({}, choice), {}, {
174
+ rationale: null
175
+ });
176
+ });
177
+ return acc;
178
+ }, {});
168
179
 
169
180
  if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
170
181
  rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
171
182
  teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
183
+ choices = normalizedQuestion.choiceRationaleEnabled ? normalizedQuestion.choices : choicesWillNullRationales;
172
184
  } else {
173
185
  rationale = null;
174
186
  teacherInstructions = null;
187
+ choices = choicesWillNullRationales;
175
188
  }
176
189
 
177
190
  out = {
178
191
  disabled: env.mode !== 'gather',
179
192
  mode: env.mode,
180
193
  prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
194
+ displayType: normalizedQuestion.displayType,
181
195
  markup: normalizedQuestion.markup,
182
196
  choices: choices,
183
197
  feedback: feedback,
@@ -187,7 +201,7 @@ function model(question, session, env, updateSession) {
187
201
  };
188
202
  resolve(out);
189
203
 
190
- case 34:
204
+ case 35:
191
205
  case "end":
192
206
  return _context.stop();
193
207
  }
@@ -302,4 +316,23 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
302
316
  };
303
317
 
304
318
  exports.createCorrectResponseSession = createCorrectResponseSession;
319
+
320
+ var validate = function validate() {
321
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
322
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
323
+ var markup = model.markup;
324
+ var maxResponseAreas = config.maxResponseAreas;
325
+ var errors = {};
326
+ var nbOfResponseAreas = ((markup || '').match(/\{\{(\d+)\}\}/g) || []).length;
327
+
328
+ if (nbOfResponseAreas > maxResponseAreas) {
329
+ errors.responseAreasError = "No more than ".concat(maxResponseAreas, " response areas should be defined.");
330
+ } else if (nbOfResponseAreas < 1) {
331
+ errors.responseAreasError = 'There should be defined at least 1 response area.';
332
+ }
333
+
334
+ return errors;
335
+ };
336
+
337
+ exports.validate = validate;
305
338
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["getFeedback","correct","normalize","question","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","model","session","env","updateSession","Promise","resolve","normalizedQuestion","value","choices","obj","area","key","choice","feedback","mode","allCorrectResponses","respAreaLength","Object","keys","length","correctResponses","i","result","answer","correctChoice","isCorrect","lockChoiceOrder","teacherInstructions","rationale","role","out","disabled","prompt","markup","responseCorrect","getScore","undefined","config","maxScore","correctCount","total","str","toFixed","parseFloat","outcome","score","empty","partialScoringEnabled","partialScoring","enabled","Math","floor","createCorrectResponseSession","forEach","correctChoices","filter","c","id"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMA;;;;;;AAEA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,OAAD,EAAa;AAC/B,MAAIA,OAAJ,EAAa;AACX,WAAO,SAAP;AACD;;AAED,SAAO,WAAP;AACD,CAND;;AAQO,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,QAAD;AAAA;AACvBC,IAAAA,aAAa,EAAE,IADQ;AAEvBC,IAAAA,gBAAgB,EAAE,IAFK;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;AAAA,sBAEMM,OAAO,IAAI,EAFjB,sBAETM,KAFS,EAETA,KAFS,4BAED,EAFC;AAGbC,cAAAA,OAHa,GAGH,wBACZF,kBAAkB,CAACE,OADP,EAEZ,UAACC,GAAD,EAAMC,IAAN,EAAYC,GAAZ,EAAoB;AAClBF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AsBD,CAvBM","sourcesContent":["import map from 'lodash/map';\nimport reduce from 'lodash/reduce';\nimport isEmpty from 'lodash/isEmpty';\nimport {\n lockChoices,\n getShuffledChoices,\n partialScoring,\n} from '@pie-lib/controller-utils';\n\nimport { getAllCorrectResponses } from './utils';\n\nconst getFeedback = (correct) => {\n if (correct) {\n return 'correct';\n }\n\n return 'incorrect';\n};\n\nexport const normalize = (question) => ({\n promptEnabled: true,\n rationaleEnabled: 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 const { value = {} } = session || {};\n let choices = reduce(\n normalizedQuestion.choices,\n (obj, area, key) => {\n obj[key] = map(area, (choice) => choice);\n\n return obj;\n },\n {}\n );\n\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n const respAreaLength = Object.keys(allCorrectResponses).length;\n let correctResponses = 0;\n\n for (let i = 0; i < respAreaLength; i++) {\n const result = reduce(\n allCorrectResponses,\n (obj, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n const isCorrect =\n answer && correctChoice && correctChoice === answer;\n\n obj.feedback[key] = getFeedback(isCorrect);\n\n if (isCorrect) {\n obj.correctResponses += 1;\n }\n\n return obj;\n },\n { correctResponses: 0, feedback: {} }\n );\n\n if (result.correctResponses >= correctResponses) {\n correctResponses = result.correctResponses;\n feedback = result.feedback;\n }\n\n if (result.correctResponses === respAreaLength) {\n break;\n }\n }\n }\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n const keys = Object.keys(choices);\n let i;\n\n for (i = 0; i < keys.length; i++) {\n const key = keys[i];\n\n choices[key] = await getShuffledChoices(\n choices[key],\n session,\n updateSession,\n 'value'\n );\n }\n }\n\n let teacherInstructions = null;\n let rationale = null;\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n rationale = null;\n teacherInstructions = null;\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null,\n markup: normalizedQuestion.markup,\n choices,\n feedback,\n\n responseCorrect:\n env.mode === 'evaluate'\n ? getScore(normalizedQuestion, session) === 1\n : undefined,\n rationale,\n teacherInstructions,\n };\n\n resolve(out);\n });\n}\n\nexport const getScore = (config, session) => {\n const { value = {} } = session || {};\n const maxScore =\n config && config.choices ? Object.keys(config.choices).length : 0;\n const allCorrectResponses = getAllCorrectResponses(config);\n let correctCount = 0;\n\n for (let i = 0; i < maxScore; i++) {\n const result = reduce(\n allCorrectResponses,\n (total, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n\n if (correctChoice && answer && correctChoice === 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 = (correctCount / maxScore).toFixed(2);\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 if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env);\n const score = getScore(model, session);\n\n resolve({\n score: partialScoringEnabled ? score : Math.floor(score),\n empty: false,\n });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question;\n const value = {};\n\n if (choices) {\n Object.keys(choices).forEach((key, i) => {\n const correctChoices =\n choices[key] && choices[key].filter((c) => c.correct);\n\n value[i] = correctChoices && correctChoices[0].value;\n });\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":["getFeedback","correct","normalize","question","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","choiceRationaleEnabled","model","session","env","updateSession","Promise","resolve","normalizedQuestion","value","choices","obj","area","key","choice","feedback","mode","allCorrectResponses","respAreaLength","Object","keys","length","correctResponses","i","result","answer","correctChoice","isCorrect","lockChoiceOrder","teacherInstructions","rationale","choicesWillNullRationales","reduce","acc","currentValue","map","role","out","disabled","prompt","displayType","markup","responseCorrect","getScore","undefined","config","maxScore","correctCount","total","str","toFixed","parseFloat","outcome","score","empty","partialScoringEnabled","partialScoring","enabled","Math","floor","createCorrectResponseSession","forEach","correctChoices","filter","c","id","validate","maxResponseAreas","errors","nbOfResponseAreas","match","responseAreasError"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMA;;;;;;AAEA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,OAAD,EAAa;AAC/B,MAAIA,OAAJ,EAAa;AACX,WAAO,SAAP;AACD;;AAED,SAAO,WAAP;AACD,CAND;;AAQO,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,QAAD;AAAA;AACvBC,IAAAA,aAAa,EAAE,IADQ;AAEvBC,IAAAA,gBAAgB,EAAE,IAF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A,MAA5BhE,KAA4B,uEAApB,EAAoB;AAAA,MAAhB2C,MAAgB,uEAAP,EAAO;AACnD,MAAQJ,MAAR,GAAmBvC,KAAnB,CAAQuC,MAAR;AACA,MAAQ0B,gBAAR,GAA6BtB,MAA7B,CAAQsB,gBAAR;AACA,MAAMC,MAAM,GAAG,EAAf;AAEA,MAAMC,iBAAiB,GAAG,CAAC,CAAC5B,MAAM,IAAI,EAAX,EAAe6B,KAAf,CAAqB,gBAArB,KAA0C,EAA3C,EAA+CjD,MAAzE;;AAEA,MAAIgD,iBAAiB,GAAGF,gBAAxB,EAA0C;AACxCC,IAAAA,MAAM,CAACG,kBAAP,0BAA4CJ,gBAA5C;AACD,GAFD,MAEO,IAAIE,iBAAiB,GAAG,CAAxB,EAA2B;AAChCD,IAAAA,MAAM,CAACG,kBAAP,GAA4B,mDAA5B;AACD;;AAED,SAAOH,MAAP;AACD,CAdM","sourcesContent":["import map from 'lodash/map';\nimport reduce from 'lodash/reduce';\nimport isEmpty from 'lodash/isEmpty';\nimport {\n lockChoices,\n getShuffledChoices,\n partialScoring,\n} from '@pie-lib/controller-utils';\n\nimport { getAllCorrectResponses } from './utils';\n\nconst getFeedback = (correct) => {\n if (correct) {\n return 'correct';\n }\n\n return 'incorrect';\n};\n\nexport const normalize = (question) => ({\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n choiceRationaleEnabled: 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 const { value = {} } = session || {};\n let choices = reduce(\n normalizedQuestion.choices,\n (obj, area, key) => {\n obj[key] = map(area, (choice) => choice);\n\n return obj;\n },\n {}\n );\n\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n const respAreaLength = Object.keys(allCorrectResponses).length;\n let correctResponses = 0;\n\n for (let i = 0; i < respAreaLength; i++) {\n const result = reduce(\n allCorrectResponses,\n (obj, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n const isCorrect =\n answer && correctChoice && correctChoice === answer;\n\n obj.feedback[key] = getFeedback(isCorrect);\n\n if (isCorrect) {\n obj.correctResponses += 1;\n }\n\n return obj;\n },\n { correctResponses: 0, feedback: {} }\n );\n\n if (result.correctResponses >= correctResponses) {\n correctResponses = result.correctResponses;\n feedback = result.feedback;\n }\n\n if (result.correctResponses === respAreaLength) {\n break;\n }\n }\n }\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n const keys = Object.keys(choices);\n let i;\n\n for (i = 0; i < keys.length; i++) {\n const key = keys[i];\n\n choices[key] = await getShuffledChoices(\n choices[key],\n session,\n updateSession,\n 'value'\n );\n }\n }\n\n let teacherInstructions = null;\n let rationale = null;\n\n const choicesWillNullRationales = (Object.keys(choices) || []).reduce(\n (acc, currentValue) => {\n acc[currentValue] = (choices[currentValue] || []).map((choice) => ({\n ...choice,\n rationale: null,\n }));\n\n return acc;\n },\n {}\n );\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n\n choices = normalizedQuestion.choiceRationaleEnabled\n ? normalizedQuestion.choices\n : choicesWillNullRationales;\n } else {\n rationale = null;\n teacherInstructions = null;\n choices = choicesWillNullRationales;\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null,\n displayType: normalizedQuestion.displayType,\n markup: normalizedQuestion.markup,\n choices,\n feedback,\n\n responseCorrect:\n env.mode === 'evaluate'\n ? getScore(normalizedQuestion, session) === 1\n : undefined,\n rationale,\n teacherInstructions,\n };\n\n resolve(out);\n });\n}\n\nexport const getScore = (config, session) => {\n const { value = {} } = session || {};\n const maxScore =\n config && config.choices ? Object.keys(config.choices).length : 0;\n const allCorrectResponses = getAllCorrectResponses(config);\n let correctCount = 0;\n\n for (let i = 0; i < maxScore; i++) {\n const result = reduce(\n allCorrectResponses,\n (total, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n\n if (correctChoice && answer && correctChoice === 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 = (correctCount / maxScore).toFixed(2);\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 if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env);\n const score = getScore(model, session);\n\n resolve({\n score: partialScoringEnabled ? score : Math.floor(score),\n empty: false,\n });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question;\n const value = {};\n\n if (choices) {\n Object.keys(choices).forEach((key, i) => {\n const correctChoices =\n choices[key] && choices[key].filter((c) => c.correct);\n\n value[i] = correctChoices && correctChoices[0].value;\n });\n }\n\n resolve({\n id: '1',\n value,\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { markup } = model;\n const { maxResponseAreas } = config;\n const errors = {};\n\n const nbOfResponseAreas = ((markup || '').match(/\\{\\{(\\d+)\\}\\}/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 defined at least 1 response area.';\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/inline-dropdown-controller",
3
3
  "private": true,
4
- "version": "3.2.15",
4
+ "version": "3.3.5",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
@@ -83,6 +83,38 @@
83
83
  }
84
84
  }
85
85
  },
86
+ "spellCheck": {
87
+ "title": "ConfigureProp",
88
+ "type": "object",
89
+ "properties": {
90
+ "settings": {
91
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
92
+ "type": "boolean",
93
+ "title": "settings"
94
+ },
95
+ "label": {
96
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
97
+ "type": "string",
98
+ "title": "label"
99
+ }
100
+ }
101
+ },
102
+ "choiceRationale": {
103
+ "title": "ConfigureProp",
104
+ "type": "object",
105
+ "properties": {
106
+ "settings": {
107
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
108
+ "type": "boolean",
109
+ "title": "settings"
110
+ },
111
+ "label": {
112
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
113
+ "type": "string",
114
+ "title": "label"
115
+ }
116
+ }
117
+ },
86
118
  "scoringType": {
87
119
  "title": "ConfigureProp",
88
120
  "type": "object",
@@ -131,6 +163,53 @@
131
163
  }
132
164
  }
133
165
  },
166
+ "maxResponseAreas": {
167
+ "description": "Maximum number of response areas",
168
+ "type": "number",
169
+ "title": "maxResponseAreas"
170
+ },
171
+ "maxImageWidth": {
172
+ "title": "ConfigureMaxImageDimensionsProp",
173
+ "type": "object",
174
+ "properties": {
175
+ "teacherInstructions": {
176
+ "description": "Indicates the max dimension for images in teacher instructions",
177
+ "type": "number",
178
+ "title": "teacherInstructions"
179
+ },
180
+ "prompt": {
181
+ "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",
182
+ "type": "number",
183
+ "title": "prompt"
184
+ },
185
+ "rationale": {
186
+ "description": "Indicates the max dimension for images in rationale",
187
+ "type": "number",
188
+ "title": "rationale"
189
+ }
190
+ }
191
+ },
192
+ "maxImageHeight": {
193
+ "title": "ConfigureMaxImageDimensionsProp",
194
+ "type": "object",
195
+ "properties": {
196
+ "teacherInstructions": {
197
+ "description": "Indicates the max dimension for images in teacher instructions",
198
+ "type": "number",
199
+ "title": "teacherInstructions"
200
+ },
201
+ "prompt": {
202
+ "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",
203
+ "type": "number",
204
+ "title": "prompt"
205
+ },
206
+ "rationale": {
207
+ "description": "Indicates the max dimension for images in rationale",
208
+ "type": "number",
209
+ "title": "rationale"
210
+ }
211
+ }
212
+ },
134
213
  "showPrompt": {
135
214
  "description": "Determines whether prompt field will be displayed or not",
136
215
  "default": true,
@@ -166,6 +245,27 @@
166
245
  "title": "label"
167
246
  }
168
247
  }
248
+ },
249
+ "ConfigureMaxImageDimensionsProp": {
250
+ "title": "ConfigureMaxImageDimensionsProp",
251
+ "type": "object",
252
+ "properties": {
253
+ "teacherInstructions": {
254
+ "description": "Indicates the max dimension for images in teacher instructions",
255
+ "type": "number",
256
+ "title": "teacherInstructions"
257
+ },
258
+ "prompt": {
259
+ "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",
260
+ "type": "number",
261
+ "title": "prompt"
262
+ },
263
+ "rationale": {
264
+ "description": "Indicates the max dimension for images in rationale",
265
+ "type": "number",
266
+ "title": "rationale"
267
+ }
268
+ }
169
269
  }
170
270
  },
171
271
  "$schema": "http://json-schema.org/draft-07/schema#"
@@ -62,6 +62,30 @@ Indicates if the item has to be displayed in the Settings Panel
62
62
 
63
63
  Indicates the label for the item that has to be displayed in the Settings Panel
64
64
 
65
+ # `spellCheck` (object)
66
+
67
+ Properties of the `spellCheck` object:
68
+
69
+ ## `settings` (boolean)
70
+
71
+ Indicates if the item has to be displayed in the Settings Panel
72
+
73
+ ## `label` (string)
74
+
75
+ Indicates the label for the item that has to be displayed in the Settings Panel
76
+
77
+ # `choiceRationale` (object)
78
+
79
+ Properties of the `choiceRationale` object:
80
+
81
+ ## `settings` (boolean)
82
+
83
+ Indicates if the item has to be displayed in the Settings Panel
84
+
85
+ ## `label` (string)
86
+
87
+ Indicates the label for the item that has to be displayed in the Settings Panel
88
+
65
89
  # `scoringType` (object)
66
90
 
67
91
  Properties of the `scoringType` object:
@@ -98,6 +122,42 @@ Indicates if the item has to be displayed in the Settings Panel
98
122
 
99
123
  Indicates the label for the item that has to be displayed in the Settings Panel
100
124
 
125
+ # `maxResponseAreas` (number)
126
+
127
+ Maximum number of response areas
128
+
129
+ # `maxImageWidth` (object)
130
+
131
+ Properties of the `maxImageWidth` object:
132
+
133
+ ## `teacherInstructions` (number)
134
+
135
+ Indicates the max dimension for images in teacher instructions
136
+
137
+ ## `prompt` (number)
138
+
139
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
140
+
141
+ ## `rationale` (number)
142
+
143
+ Indicates the max dimension for images in rationale
144
+
145
+ # `maxImageHeight` (object)
146
+
147
+ Properties of the `maxImageHeight` object:
148
+
149
+ ## `teacherInstructions` (number)
150
+
151
+ Indicates the max dimension for images in teacher instructions
152
+
153
+ ## `prompt` (number)
154
+
155
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
156
+
157
+ ## `rationale` (number)
158
+
159
+ Indicates the max dimension for images in rationale
160
+
101
161
  # `showPrompt` (boolean)
102
162
 
103
163
  Determines whether prompt field will be displayed or not
@@ -132,4 +192,20 @@ Indicates if the item has to be displayed in the Settings Panel
132
192
 
133
193
  ### `label` (string)
134
194
 
135
- 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
@@ -5,6 +5,7 @@ exports.model = (id, element) => ({
5
5
  mode: 'gather',
6
6
  prompt: 'Use the dropdowns to complete the sentence',
7
7
  promptEnabled: true,
8
+ toolbarEditorPosition: 'bottom',
8
9
  shuffle: true,
9
10
  markup: '<div><p>The {{0}} jumped {{1}} the {{2}}</p></div>',
10
11
  choices: {
@@ -12,55 +13,65 @@ exports.model = (id, element) => ({
12
13
  {
13
14
  label: 'cow ',
14
15
  value: '0',
15
- correct: true
16
+ correct: true,
17
+ rationale: 'rationale cow'
16
18
  },
17
19
  {
18
20
  label: 'dog ',
19
21
  value: '1',
20
- correct: false
22
+ correct: false,
23
+ rationale: 'rationale dog'
21
24
  },
22
25
  {
23
26
  label: 'cat ',
24
27
  value: '2',
25
- correct: false
28
+ correct: false,
29
+ rationale: 'rationale car'
26
30
  }
27
31
  ],
28
32
  '1': [
29
33
  {
30
34
  label: 'over ',
31
35
  value: '0',
32
- correct: true
36
+ correct: true,
37
+ rationale: 'rationale over'
33
38
  },
34
39
  {
35
40
  label: 'under ',
36
41
  value: '1',
37
- correct: false
42
+ correct: false,
43
+ rationale: 'rationale under'
38
44
  },
39
45
  {
40
46
  label: 'across ',
41
47
  value: '2',
42
- correct: false
48
+ correct: false,
49
+ rationale: 'rationale across'
43
50
  }
44
51
  ],
45
52
  '2': [
46
53
  {
47
54
  label: 'moon ',
48
55
  value: '0',
49
- correct: true
56
+ correct: true,
57
+ rationale: 'rationale moon'
50
58
  },
51
59
  {
52
60
  label: 'sun',
53
61
  value: '2',
54
- correct: false
62
+ correct: false,
63
+ rationale: 'rationale sun'
55
64
  },
56
65
  {
57
66
  label: 'house ',
58
67
  value: '3',
59
- correct: false
68
+ correct: false,
69
+ rationale: 'rationale house'
60
70
  }
61
71
  ]
62
72
  },
63
73
  alternateResponse: {
64
74
  '2': ['2']
65
- }
75
+ },
76
+ choiceRationaleEnabled: false
66
77
  });
@@ -28,6 +28,11 @@
28
28
  "description": "Indicates if choice is correct",
29
29
  "type": "boolean",
30
30
  "title": "correct"
31
+ },
32
+ "rationale": {
33
+ "description": "Rationale for the choice",
34
+ "type": "string",
35
+ "title": "rationale"
31
36
  }
32
37
  },
33
38
  "required": [
@@ -107,6 +112,16 @@
107
112
  "type": "boolean",
108
113
  "title": "rationaleEnabled"
109
114
  },
115
+ "spellCheckEnabled": {
116
+ "description": "Indicates if spellcheck is enabled for the author. Default value is true",
117
+ "type": "boolean",
118
+ "title": "spellCheckEnabled"
119
+ },
120
+ "choiceRationaleEnabled": {
121
+ "description": "Indicates if Choice Level Rationales are enabled",
122
+ "type": "boolean",
123
+ "title": "choiceRationaleEnabled"
124
+ },
110
125
  "studentInstructionsEnabled": {
111
126
  "description": "Indicates if Student Instructions are enabled",
112
127
  "type": "boolean",
@@ -117,6 +132,21 @@
117
132
  "type": "boolean",
118
133
  "title": "teacherInstructionsEnabled"
119
134
  },
135
+ "displayType": {
136
+ "description": "Indicates display type for the container of the pie-ui element",
137
+ "type": "string",
138
+ "title": "displayType"
139
+ },
140
+ "toolbarEditorPosition": {
141
+ "description": "Indicates the editor's toolbar position which can be 'bottom' or 'top'",
142
+ "default": ": 'bottom'",
143
+ "enum": [
144
+ "bottom",
145
+ "top"
146
+ ],
147
+ "type": "string",
148
+ "title": "toolbarEditorPosition"
149
+ },
120
150
  "id": {
121
151
  "description": "Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.",
122
152
  "type": "string",
@@ -130,7 +160,9 @@
130
160
  },
131
161
  "required": [
132
162
  "alternateResponses",
163
+ "choiceRationaleEnabled",
133
164
  "choices",
165
+ "displayType",
134
166
  "element",
135
167
  "id",
136
168
  "lockChoiceOrder",
@@ -139,6 +171,7 @@
139
171
  "rationale",
140
172
  "rationaleEnabled",
141
173
  "scoringType",
174
+ "spellCheckEnabled",
142
175
  "studentInstructionsEnabled",
143
176
  "teacherInstructionsEnabled"
144
177
  ],
@@ -159,6 +192,27 @@
159
192
  }
160
193
  }
161
194
  },
195
+ "ConfigureMaxImageDimensionsProp": {
196
+ "title": "ConfigureMaxImageDimensionsProp",
197
+ "type": "object",
198
+ "properties": {
199
+ "teacherInstructions": {
200
+ "description": "Indicates the max dimension for images in teacher instructions",
201
+ "type": "number",
202
+ "title": "teacherInstructions"
203
+ },
204
+ "prompt": {
205
+ "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",
206
+ "type": "number",
207
+ "title": "prompt"
208
+ },
209
+ "rationale": {
210
+ "description": "Indicates the max dimension for images in rationale",
211
+ "type": "number",
212
+ "title": "rationale"
213
+ }
214
+ }
215
+ },
162
216
  "Choice": {
163
217
  "title": "Choice",
164
218
  "type": "object",
@@ -177,6 +231,11 @@
177
231
  "description": "Indicates if choice is correct",
178
232
  "type": "boolean",
179
233
  "title": "correct"
234
+ },
235
+ "rationale": {
236
+ "description": "Rationale for the choice",
237
+ "type": "string",
238
+ "title": "rationale"
180
239
  }
181
240
  },
182
241
  "required": [
@@ -56,6 +56,14 @@ Indicates teacher instructions
56
56
 
57
57
  Indicates if Rationale are enabled
58
58
 
59
+ # `spellCheckEnabled` (boolean, required)
60
+
61
+ Indicates if spellcheck is enabled for the author. Default value is true
62
+
63
+ # `choiceRationaleEnabled` (boolean, required)
64
+
65
+ Indicates if Choice Level Rationales are enabled
66
+
59
67
  # `studentInstructionsEnabled` (boolean, required)
60
68
 
61
69
  Indicates if Student Instructions are enabled
@@ -64,6 +72,21 @@ Indicates if Student Instructions are enabled
64
72
 
65
73
  Indicates if Teacher Instructions are enabled
66
74
 
75
+ # `displayType` (string, required)
76
+
77
+ Indicates display type for the container of the pie-ui element
78
+
79
+ # `toolbarEditorPosition` (string, enum)
80
+
81
+ Indicates the editor's toolbar position which can be 'bottom' or 'top'
82
+
83
+ This element must be one of the following enum values:
84
+
85
+ * `bottom`
86
+ * `top`
87
+
88
+ Default: `": 'bottom'"`
89
+
67
90
  # `id` (string, required)
68
91
 
69
92
  Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.
@@ -90,6 +113,22 @@ Indicates if the item has to be displayed in the Settings Panel
90
113
 
91
114
  Indicates the label for the item that has to be displayed in the Settings Panel
92
115
 
116
+ ## `ConfigureMaxImageDimensionsProp` (object)
117
+
118
+ Properties of the `ConfigureMaxImageDimensionsProp` object:
119
+
120
+ ### `teacherInstructions` (number)
121
+
122
+ Indicates the max dimension for images in teacher instructions
123
+
124
+ ### `prompt` (number)
125
+
126
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
127
+
128
+ ### `rationale` (number)
129
+
130
+ Indicates the max dimension for images in rationale
131
+
93
132
  ## `Choice` (object)
94
133
 
95
134
  Properties of the `Choice` object:
@@ -104,4 +143,8 @@ The label of the choice
104
143
 
105
144
  ### `correct` (boolean)
106
145
 
107
- Indicates if choice is correct
146
+ Indicates if choice is correct
147
+
148
+ ### `rationale` (string)
149
+
150
+ Rationale for the choice