@pie-element/explicit-constructed-response 4.6.1-beta.1 → 4.6.1-beta.4

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.
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.removeUnwantedCharacters = exports.processMarkup = exports.getAdjustedLength = exports.createSlateMarkup = void 0;
8
+ var _escape = _interopRequireDefault(require("lodash/escape"));
9
+ // do not remove \t from \times, \triangle, \tan, \theta or \therefore
10
+ var tSymbols = 'imes|riangle|an|heta|herefore';
11
+ // do not remove \n from \nthroot, \nparallel, \ncong, \napprox, \neq, \ne or \nsim
12
+ var nSymbols = 'throot|parallel|cong|approx|eq|e|sim';
13
+ // match all \t and \n that are not part of math symbols that starts with \t or \n
14
+ var matchTabAndNewLine = new RegExp("(\\t(?!".concat(tSymbols, "))|(\\n(?!").concat(nSymbols, "))|(\\\\t(?!").concat(tSymbols, "))|(\\\\n(?!").concat(nSymbols, "))"), 'g');
15
+ var removeUnwantedCharacters = function removeUnwantedCharacters(markup) {
16
+ return markup.replace(matchTabAndNewLine, '').replace(/\\"/g, '"').replace(/\\\//g, '/');
17
+ };
18
+ exports.removeUnwantedCharacters = removeUnwantedCharacters;
19
+ var createElementFromHTML = function createElementFromHTML() {
20
+ var htmlString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
21
+ var div = document.createElement('div');
22
+ div.innerHTML = htmlString.trim();
23
+ return div;
24
+ };
25
+ var processMarkup = function processMarkup(markup) {
26
+ var newMarkup = removeUnwantedCharacters(markup || '');
27
+ var slateMarkup = createElementFromHTML(newMarkup || '');
28
+ var index = 0;
29
+ slateMarkup.querySelectorAll('[data-type="explicit_constructed_response"]').forEach(function (s) {
30
+ s.replaceWith("{{".concat(index++, "}}"));
31
+ });
32
+ return slateMarkup.innerHTML;
33
+ };
34
+ exports.processMarkup = processMarkup;
35
+ var REGEX = /\{\{(\d+)\}\}/g;
36
+ var createSlateMarkup = function createSlateMarkup(markup, choices) {
37
+ if (!markup) {
38
+ return '';
39
+ }
40
+ var newMarkup = removeUnwantedCharacters(markup);
41
+ return newMarkup.replace(REGEX, function (match, g) {
42
+ var label = choices[g][0].label || '';
43
+ return "<span data-type=\"explicit_constructed_response\" data-index=\"".concat(g, "\" data-value=\"").concat((0, _escape["default"])(label), "\"></span>");
44
+ });
45
+ };
46
+
47
+ // also used in controller/src/index.js
48
+ exports.createSlateMarkup = createSlateMarkup;
49
+ var getAdjustedLength = function getAdjustedLength(length) {
50
+ if (length <= 2) {
51
+ return length + 2;
52
+ }
53
+ if (length <= 4) {
54
+ return length + 3;
55
+ }
56
+ if (length <= 6) {
57
+ return length + 4;
58
+ }
59
+ return length + 5;
60
+ };
61
+ exports.getAdjustedLength = getAdjustedLength;
62
+ //# sourceMappingURL=markupUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markupUtils.js","names":["_escape","_interopRequireDefault","require","tSymbols","nSymbols","matchTabAndNewLine","RegExp","concat","removeUnwantedCharacters","markup","replace","exports","createElementFromHTML","htmlString","arguments","length","undefined","div","document","createElement","innerHTML","trim","processMarkup","newMarkup","slateMarkup","index","querySelectorAll","forEach","s","replaceWith","REGEX","createSlateMarkup","choices","match","g","label","escape","getAdjustedLength"],"sources":["../src/markupUtils.js"],"sourcesContent":["import escape from 'lodash/escape';\n\n// do not remove \\t from \\times, \\triangle, \\tan, \\theta or \\therefore\nconst tSymbols = 'imes|riangle|an|heta|herefore';\n// do not remove \\n from \\nthroot, \\nparallel, \\ncong, \\napprox, \\neq, \\ne or \\nsim\nconst nSymbols = 'throot|parallel|cong|approx|eq|e|sim';\n// match all \\t and \\n that are not part of math symbols that starts with \\t or \\n\nconst matchTabAndNewLine = new RegExp(\n `(\\\\t(?!${tSymbols}))|(\\\\n(?!${nSymbols}))|(\\\\\\\\t(?!${tSymbols}))|(\\\\\\\\n(?!${nSymbols}))`,\n 'g',\n);\n\nexport const removeUnwantedCharacters = (markup) =>\n markup.replace(matchTabAndNewLine, '').replace(/\\\\\"/g, '\"').replace(/\\\\\\//g, '/');\n\nconst createElementFromHTML = (htmlString = '') => {\n const div = document.createElement('div');\n\n div.innerHTML = htmlString.trim();\n\n return div;\n};\n\nexport const processMarkup = (markup) => {\n const newMarkup = removeUnwantedCharacters(markup || '');\n const slateMarkup = createElementFromHTML(newMarkup || '');\n let index = 0;\n\n slateMarkup.querySelectorAll('[data-type=\"explicit_constructed_response\"]').forEach((s) => {\n s.replaceWith(`{{${index++}}}`);\n });\n\n return slateMarkup.innerHTML;\n};\n\nconst REGEX = /\\{\\{(\\d+)\\}\\}/g;\n\nexport const createSlateMarkup = (markup, choices) => {\n if (!markup) {\n return '';\n }\n\n const newMarkup = removeUnwantedCharacters(markup);\n\n return newMarkup.replace(REGEX, (match, g) => {\n const label = choices[g][0].label || '';\n\n return `<span data-type=\"explicit_constructed_response\" data-index=\"${g}\" data-value=\"${escape(label)}\"></span>`;\n });\n};\n\n// also used in controller/src/index.js\nexport const 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"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA;AACA,IAAMC,QAAQ,GAAG,+BAA+B;AAChD;AACA,IAAMC,QAAQ,GAAG,sCAAsC;AACvD;AACA,IAAMC,kBAAkB,GAAG,IAAIC,MAAM,WAAAC,MAAA,CACzBJ,QAAQ,gBAAAI,MAAA,CAAaH,QAAQ,kBAAAG,MAAA,CAAeJ,QAAQ,kBAAAI,MAAA,CAAeH,QAAQ,SACrF,GACF,CAAC;AAEM,IAAMI,wBAAwB,GAAG,SAA3BA,wBAAwBA,CAAIC,MAAM;EAAA,OAC7CA,MAAM,CAACC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,KAAK,EAAE,UAACG,KAAK,EAAEC,CAAC,EAAK;IAC5C,IAAMC,KAAK,GAAGH,OAAO,CAACE,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,KAAK,IAAI,EAAE;IAEvC,yEAAA5B,MAAA,CAAsE2B,CAAC,sBAAA3B,MAAA,CAAiB,IAAA6B,kBAAM,EAACD,KAAK,CAAC;EACvG,CAAC,CAAC;AACJ,CAAC;;AAED;AAAAxB,OAAA,CAAAoB,iBAAA,GAAAA,iBAAA;AACO,IAAMM,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAItB,MAAM,EAAK;EAC3C,IAAIA,MAAM,IAAI,CAAC,EAAE;IACf,OAAOA,MAAM,GAAG,CAAC;EACnB;EAEA,IAAIA,MAAM,IAAI,CAAC,EAAE;IACf,OAAOA,MAAM,GAAG,CAAC;EACnB;EAEA,IAAIA,MAAM,IAAI,CAAC,EAAE;IACf,OAAOA,MAAM,GAAG,CAAC;EACnB;EAEA,OAAOA,MAAM,GAAG,CAAC;AACnB,CAAC;AAACJ,OAAA,CAAA0B,iBAAA,GAAAA,iBAAA"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateValidationMessage = void 0;
7
+ var generateValidationMessage = function generateValidationMessage(config) {
8
+ var maxResponseAreas = config.maxResponseAreas;
9
+ var responseAreasMessage = '\nCorrect answers should not be blank.' + '\nEach answer defined for a response area should be unique.' + '\nThere should be at least 1 ' + (maxResponseAreas ? "and at most ".concat(maxResponseAreas, " ") : '') + 'response area' + (maxResponseAreas ? 's' : '') + ' defined.';
10
+ return 'Validation requirements:' + responseAreasMessage;
11
+ };
12
+ exports.generateValidationMessage = generateValidationMessage;
13
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["generateValidationMessage","config","maxResponseAreas","responseAreasMessage","concat","exports"],"sources":["../src/utils.js"],"sourcesContent":["export const generateValidationMessage = (config) => {\n const { maxResponseAreas } = config;\n\n const responseAreasMessage =\n '\\nCorrect answers should not be blank.' +\n '\\nEach answer defined for a response area should be unique.' +\n '\\nThere should be at least 1 ' +\n (maxResponseAreas ? `and at most ${maxResponseAreas} ` : '') +\n 'response area' +\n (maxResponseAreas ? 's' : '') +\n ' defined.';\n\n return 'Validation requirements:' + responseAreasMessage;\n};\n"],"mappings":";;;;;;AAAO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAAyBA,CAAIC,MAAM,EAAK;EACnD,IAAQC,gBAAgB,GAAKD,MAAM,CAA3BC,gBAAgB;EAExB,IAAMC,oBAAoB,GACxB,wCAAwC,GACxC,6DAA6D,GAC7D,+BAA+B,IAC9BD,gBAAgB,kBAAAE,MAAA,CAAkBF,gBAAgB,SAAM,EAAE,CAAC,GAC5D,eAAe,IACdA,gBAAgB,GAAG,GAAG,GAAG,EAAE,CAAC,GAC7B,WAAW;EAEb,OAAO,0BAA0B,GAAGC,oBAAoB;AAC1D,CAAC;AAACE,OAAA,CAAAL,yBAAA,GAAAA,yBAAA"}
@@ -9,8 +9,8 @@
9
9
  "@material-ui/core": "^3.9.2",
10
10
  "@material-ui/icons": "^3.0.1",
11
11
  "@pie-framework/pie-configure-events": "^1.3.0",
12
- "@pie-lib/config-ui": "12.0.0-beta.4",
13
- "@pie-lib/editable-html": "10.0.0-beta.5",
12
+ "@pie-lib/config-ui": "12.0.0-beta.5",
13
+ "@pie-lib/editable-html": "10.0.0-beta.7",
14
14
  "@types/is-hotkey": "^0.1.1",
15
15
  "@types/lodash": "^4.14.149",
16
16
  "classnames": "^2.2.6",
@@ -23,7 +23,7 @@
23
23
  "react": "^16.8.1",
24
24
  "react-dom": "^16.8.1",
25
25
  "scroll-into-view-if-needed": "^2.2.20",
26
- "slate": "^0.82.1",
26
+ "slate": "^0.94.1",
27
27
  "slate-dev-environment": "^0.2.5",
28
28
  "slate-edit-list": "^0.12.1",
29
29
  "slate-edit-table": "^0.18.0",
@@ -32,7 +32,7 @@
32
32
  "slate-hyperscript": "^0.77.0",
33
33
  "slate-plain-serializer": "^0.7.13",
34
34
  "slate-prop-types": "^0.5.44",
35
- "slate-react": "0.92.0",
35
+ "slate-react": "0.97.2",
36
36
  "tiny-invariant": "1.0.6"
37
37
  }
38
38
  }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _default = {
8
+ prompt: 'Which of these northern European countries are EU members?',
9
+ 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.',
10
+ choiceMode: 'checkbox',
11
+ choicePrefix: 'numbers',
12
+ choices: [{
13
+ value: 'sweden',
14
+ label: 'Sweden'
15
+ }, {
16
+ value: 'iceland',
17
+ label: 'Iceland'
18
+ }]
19
+ };
20
+ exports["default"] = _default;
21
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","names":["prompt","note","choiceMode","choicePrefix","choices","value","label","exports","_default"],"sources":["../src/defaults.js"],"sourcesContent":["export default {\n prompt: 'Which of these northern European countries are EU members?',\n 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.',\n choiceMode: 'checkbox',\n choicePrefix: 'numbers',\n choices: [\n {\n value: 'sweden',\n label: 'Sweden',\n },\n {\n value: 'iceland',\n label: 'Iceland',\n },\n ],\n};\n"],"mappings":";;;;;;eAAe;EACbA,MAAM,EAAE,4DAA4D;EACpEC,IAAI,EAAE,0KAA0K;EAChLC,UAAU,EAAE,UAAU;EACtBC,YAAY,EAAE,SAAS;EACvBC,OAAO,EAAE,CACP;IACEC,KAAK,EAAE,QAAQ;IACfC,KAAK,EAAE;EACT,CAAC,EACD;IACED,KAAK,EAAE,SAAS;IAChBC,KAAK,EAAE;EACT,CAAC;AAEL,CAAC;AAAAC,OAAA,cAAAC,QAAA"}
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getScore = exports.createCorrectResponseSession = void 0;
8
+ exports.model = model;
9
+ exports.normalize = void 0;
10
+ exports.outcome = outcome;
11
+ exports.validate = exports.prepareVal = exports.prepareChoice = void 0;
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
14
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+ var _map = _interopRequireDefault(require("lodash/map"));
18
+ var _reduce = _interopRequireDefault(require("lodash/reduce"));
19
+ var _find = _interopRequireDefault(require("lodash/find"));
20
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
21
+ var _debug = _interopRequireDefault(require("debug"));
22
+ var _controllerUtils = require("@pie-lib/controller-utils");
23
+ 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; }
24
+ 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; }
25
+ var log = (0, _debug["default"])('explicit-constructed-response:controller');
26
+ var prepareChoice = function prepareChoice(mode, defaultFeedback) {
27
+ return function (choice) {
28
+ var out = {
29
+ label: choice.label,
30
+ value: choice.value
31
+ };
32
+ if (mode === 'evaluate') {
33
+ out.correct = true;
34
+ var feedbackType = choice.feedback && choice.feedback.type || 'none';
35
+ if (feedbackType === 'default') {
36
+ out.feedback = defaultFeedback['correct'];
37
+ } else if (feedbackType === 'custom') {
38
+ out.feedback = choice.feedback.value;
39
+ }
40
+ }
41
+ return out;
42
+ };
43
+ };
44
+ exports.prepareChoice = prepareChoice;
45
+ var getFeedback = function getFeedback(value) {
46
+ if (value) {
47
+ return 'correct';
48
+ }
49
+ return 'incorrect';
50
+ };
51
+
52
+ // also used in configure/src/markupUtils.js
53
+ var getAdjustedLength = function getAdjustedLength(length) {
54
+ if (length <= 2) {
55
+ return length + 2;
56
+ }
57
+ if (length <= 4) {
58
+ return length + 3;
59
+ }
60
+ if (length <= 6) {
61
+ return length + 4;
62
+ }
63
+ return length + 5;
64
+ };
65
+ var normalize = function normalize(question) {
66
+ return _objectSpread({
67
+ rationaleEnabled: true,
68
+ promptEnabled: true,
69
+ teacherInstructionsEnabled: true,
70
+ studentInstructionsEnabled: true
71
+ }, question);
72
+ };
73
+
74
+ /**
75
+ *
76
+ * @param {*} question
77
+ * @param {*} session
78
+ * @param {*} env
79
+ */
80
+ exports.normalize = normalize;
81
+ function model(question, session, env) {
82
+ return new Promise( /*#__PURE__*/function () {
83
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
84
+ var normalizedQuestion, defaultFeedback, _ref2, _ref2$value, value, preparChoiceFn, choices, feedback, showNote, _normalizedQuestion$m, maxLengthPerChoice, maxLengthPerChoiceEnabled, undefinedLengths, out;
85
+ return _regenerator["default"].wrap(function _callee$(_context) {
86
+ while (1) switch (_context.prev = _context.next) {
87
+ case 0:
88
+ // this was added to treat an exception, when the model has choices without the "value" property
89
+ // like: { label: 'test' }
90
+ if (question.choices) {
91
+ Object.keys(question.choices).forEach(function (key) {
92
+ question.choices[key] = (question.choices[key] || []).map(function (item, index) {
93
+ if (!item.value) {
94
+ log('Choice does not contain "value" property, which is required.', item);
95
+ return _objectSpread({
96
+ value: "".concat(index)
97
+ }, item);
98
+ }
99
+ return item;
100
+ });
101
+ });
102
+ }
103
+ normalizedQuestion = normalize(question);
104
+ defaultFeedback = Object.assign({
105
+ correct: 'Correct',
106
+ incorrect: 'Incorrect'
107
+ }, normalizedQuestion.defaultFeedback);
108
+ _ref2 = session || {}, _ref2$value = _ref2.value, value = _ref2$value === void 0 ? {} : _ref2$value;
109
+ preparChoiceFn = prepareChoice(env.mode, defaultFeedback);
110
+ choices = (0, _reduce["default"])(normalizedQuestion.choices, function (obj, area, key) {
111
+ obj[key] = (0, _map["default"])(area, preparChoiceFn);
112
+ return obj;
113
+ }, {});
114
+ feedback = {};
115
+ if (env.mode === 'evaluate') {
116
+ feedback = (0, _reduce["default"])(normalizedQuestion.choices, function (obj, respArea, key) {
117
+ var chosenValue = value && value[key];
118
+ var val = !(0, _isEmpty["default"])(chosenValue) && (0, _find["default"])(respArea, function (c) {
119
+ return prepareVal(c.label) === prepareVal(chosenValue);
120
+ });
121
+ obj[key] = getFeedback(val);
122
+ return obj;
123
+ }, {});
124
+ }
125
+ showNote = false; // check if a choice has an alternate
126
+ Object.values(choices).forEach(function (choice) {
127
+ if (choice && choice.length > 1) {
128
+ showNote = true;
129
+ }
130
+ });
131
+ _normalizedQuestion$m = normalizedQuestion.maxLengthPerChoice, maxLengthPerChoice = _normalizedQuestion$m === void 0 ? [] : _normalizedQuestion$m, maxLengthPerChoiceEnabled = normalizedQuestion.maxLengthPerChoiceEnabled;
132
+ undefinedLengths = !maxLengthPerChoice.length; // calculate maxLengthPerChoice array if it is not defined or defined incorrectly
133
+ Object.values(choices).forEach(function (choice, index) {
134
+ var labelLengthsArr = (choice || []).map(function (choice) {
135
+ return (choice.label || '').length;
136
+ });
137
+ var length = Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr));
138
+ if (undefinedLengths || !maxLengthPerChoice[index] || maxLengthPerChoice[index] < length || maxLengthPerChoice[index] > length + 10) {
139
+ maxLengthPerChoice[index] = getAdjustedLength(length);
140
+ }
141
+ });
142
+ out = {
143
+ disabled: env.mode !== 'gather',
144
+ mode: env.mode,
145
+ prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
146
+ markup: normalizedQuestion.markup,
147
+ choices: choices,
148
+ feedback: feedback,
149
+ env: env,
150
+ note: normalizedQuestion.note,
151
+ showNote: showNote,
152
+ maxLengthPerChoice: maxLengthPerChoice,
153
+ maxLengthPerChoiceEnabled: maxLengthPerChoiceEnabled,
154
+ displayType: normalizedQuestion.displayType,
155
+ playerSpellCheckEnabled: normalizedQuestion.playerSpellCheckEnabled,
156
+ responseCorrect: env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined
157
+ };
158
+ if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
159
+ out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
160
+ out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
161
+ } else {
162
+ out.rationale = null;
163
+ out.teacherInstructions = null;
164
+ }
165
+ resolve(out);
166
+ case 16:
167
+ case "end":
168
+ return _context.stop();
169
+ }
170
+ }, _callee);
171
+ }));
172
+ return function (_x) {
173
+ return _ref.apply(this, arguments);
174
+ };
175
+ }());
176
+ }
177
+ var getTextFromHTML = function getTextFromHTML(html) {
178
+ return (html || '').replace(/<\/?[^>]+(>|$)/g, '');
179
+ };
180
+ var prepareVal = function prepareVal(html) {
181
+ var value = getTextFromHTML(html);
182
+ return value.trim();
183
+ };
184
+ exports.prepareVal = prepareVal;
185
+ var getScore = function getScore(config, session) {
186
+ var _ref3 = session || {},
187
+ value = _ref3.value;
188
+ if (!session || (0, _isEmpty["default"])(session) || !value) {
189
+ return 0;
190
+ }
191
+ var responseAreas = config.markup && config.markup.match(/\{\{(.)\}\}/g);
192
+ var maxScore = responseAreas ? responseAreas.length : 0;
193
+ var correctCount = (0, _reduce["default"])(config.choices, function (total, respArea, key) {
194
+ var chosenValue = value && value[key];
195
+ if ((0, _isEmpty["default"])(chosenValue) || !(0, _find["default"])(respArea, function (c) {
196
+ return prepareVal(c.label) === prepareVal(chosenValue);
197
+ })) {
198
+ return total;
199
+ }
200
+ return total + 1;
201
+ }, 0);
202
+ var str = maxScore ? (correctCount / maxScore).toFixed(2) : 0;
203
+ return parseFloat(str);
204
+ };
205
+
206
+ /**
207
+ *
208
+ * The score is partial by default for checkbox mode, allOrNothing for radio mode.
209
+ * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =
210
+ * false. the value in `env` will override the value in `model`.
211
+ * @param {Object} model - the main model
212
+ * @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)
213
+ * @param {*} session
214
+ * @param {Object} env
215
+ * @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides
216
+ * `model.partialScoring`.
217
+ */
218
+ exports.getScore = getScore;
219
+ function outcome(model, session) {
220
+ var env = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
221
+ return new Promise(function (resolve) {
222
+ var partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
223
+ var score = getScore(model, session);
224
+ resolve({
225
+ score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
226
+ empty: (0, _isEmpty["default"])(session)
227
+ });
228
+ });
229
+ }
230
+ var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
231
+ return new Promise(function (resolve) {
232
+ if (env.mode !== 'evaluate' && env.role === 'instructor') {
233
+ var choices = question.choices;
234
+ var value = {};
235
+ Object.keys(choices).forEach(function (key, i) {
236
+ value[i] = choices[key][0].label;
237
+ });
238
+ resolve({
239
+ id: '1',
240
+ value: value
241
+ });
242
+ } else {
243
+ resolve(null);
244
+ }
245
+ });
246
+ };
247
+ exports.createCorrectResponseSession = createCorrectResponseSession;
248
+ var validate = function validate() {
249
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
250
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
251
+ var choices = model.choices,
252
+ markup = model.markup;
253
+ var maxResponseAreas = config.maxResponseAreas;
254
+ var allChoicesErrors = {};
255
+ Object.entries(choices || {}).forEach(function (_ref4) {
256
+ var _ref5 = (0, _slicedToArray2["default"])(_ref4, 2),
257
+ key = _ref5[0],
258
+ values = _ref5[1];
259
+ var reversedChoices = (0, _toConsumableArray2["default"])(values || []).reverse();
260
+ var choicesErrors = {};
261
+ reversedChoices.forEach(function (choice, index) {
262
+ var value = choice.value,
263
+ label = choice.label;
264
+ if (label === '' || label === '<div></div>') {
265
+ choicesErrors[value] = 'Content should not be empty.';
266
+ } else {
267
+ var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
268
+ return c.label === label;
269
+ });
270
+ if (identicalAnswer) {
271
+ choicesErrors[value] = 'Content should be unique.';
272
+ }
273
+ }
274
+ });
275
+ if (!(0, _isEmpty["default"])(choicesErrors)) {
276
+ allChoicesErrors[key] = choicesErrors;
277
+ }
278
+ });
279
+ var errors = {};
280
+ var nbOfResponseAreas = (markup.match(/\{\{(\d+)\}\}/g) || []).length;
281
+ if (nbOfResponseAreas > maxResponseAreas) {
282
+ errors.responseAreasError = "No more than ".concat(maxResponseAreas, " response areas should be defined.");
283
+ } else if (nbOfResponseAreas < 1) {
284
+ errors.responseAreasError = 'There should be at least 1 response area defined.';
285
+ }
286
+ if (!(0, _isEmpty["default"])(allChoicesErrors)) {
287
+ errors.choicesErrors = allChoicesErrors;
288
+ }
289
+ return errors;
290
+ };
291
+ exports.validate = validate;
292
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_map","_interopRequireDefault","require","_reduce","_find","_isEmpty","_debug","_controllerUtils","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","log","debug","prepareChoice","mode","defaultFeedback","choice","out","label","value","correct","feedbackType","feedback","type","exports","getFeedback","getAdjustedLength","normalize","question","rationaleEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","model","session","env","Promise","_ref","_asyncToGenerator2","_regenerator","mark","_callee","resolve","normalizedQuestion","_ref2","_ref2$value","preparChoiceFn","choices","showNote","_normalizedQuestion$m","maxLengthPerChoice","maxLengthPerChoiceEnabled","undefinedLengths","wrap","_callee$","_context","prev","next","map","item","index","concat","assign","incorrect","reduce","obj","area","respArea","chosenValue","val","isEmpty","find","c","prepareVal","values","labelLengthsArr","Math","max","_toConsumableArray2","disabled","prompt","markup","note","displayType","playerSpellCheckEnabled","responseCorrect","getScore","undefined","role","rationale","teacherInstructions","stop","_x","getTextFromHTML","html","replace","trim","config","_ref3","responseAreas","match","maxScore","correctCount","total","str","toFixed","parseFloat","outcome","partialScoringEnabled","partialScoring","enabled","score","empty","createCorrectResponseSession","id","validate","maxResponseAreas","allChoicesErrors","entries","_ref4","_ref5","_slicedToArray2","reversedChoices","reverse","choicesErrors","identicalAnswer","slice","some","errors","nbOfResponseAreas","responseAreasError"],"sources":["../src/index.js"],"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(\n normalizedQuestion.choices,\n (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 }\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 playerSpellCheckEnabled: normalizedQuestion.playerSpellCheckEnabled,\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\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(\n config.choices,\n (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 },\n 0,\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({ 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\nexport const validate = (model = {}, config = {}) => {\n const { choices, markup } = model;\n const { maxResponseAreas } = config;\n const allChoicesErrors = {};\n\n Object.entries(choices || {}).forEach(([key, values]) => {\n const reversedChoices = [...(values || [])].reverse();\n const choicesErrors = {};\n\n reversedChoices.forEach((choice, index) => {\n const { value, label } = choice;\n\n if (label === '' || label === '<div></div>') {\n choicesErrors[value] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[value] = 'Content should be unique.';\n }\n }\n });\n\n if (!isEmpty(choicesErrors)) {\n allChoicesErrors[key] = choicesErrors;\n }\n });\n\n const errors = {};\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 at least 1 response area defined.';\n }\n\n if (!isEmpty(allChoicesErrors)) {\n errors.choicesErrors = allChoicesErrors;\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AAA2D,SAAAM,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,UAAAG,MAAA,WAAAF,SAAA,CAAAD,CAAA,IAAAC,SAAA,CAAAD,CAAA,QAAAA,CAAA,OAAAf,OAAA,CAAAI,MAAA,CAAAc,MAAA,OAAAC,OAAA,WAAAC,GAAA,QAAAC,gBAAA,aAAAP,MAAA,EAAAM,GAAA,EAAAF,MAAA,CAAAE,GAAA,SAAAhB,MAAA,CAAAkB,yBAAA,GAAAlB,MAA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AAiB,GAAGb,gBAAgB,EAAE;IACxCY,MAAM,CAACE,kBAAkB,mBAAArE,MAAA,CAAmBuD,gBAAgB,uCAAoC;EAClG,CAAC,MAAM,IAAIa,iBAAiB,GAAG,CAAC,EAAE;IAChCD,MAAM,CAACE,kBAAkB,GAAG,mDAAmD;EACjF;EAEA,IAAI,CAAC,IAAA5D,mBAAO,EAAC+C,gBAAgB,CAAC,EAAE;IAC9BW,MAAM,CAACJ,aAAa,GAAGP,gBAAgB;EACzC;EAEA,OAAOW,MAAM;AACf,CAAC;AAACxG,OAAA,CAAA2F,QAAA,GAAAA,QAAA"}
package/lib/index.js ADDED
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
11
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
+ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+ var _react = _interopRequireDefault(require("react"));
17
+ var _reactDom = _interopRequireDefault(require("react-dom"));
18
+ var _piePlayerEvents = require("@pie-framework/pie-player-events");
19
+ var _mathRendering = require("@pie-lib/math-rendering");
20
+ var _main = _interopRequireDefault(require("./main"));
21
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
22
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
23
+ var InlineDropdown = /*#__PURE__*/function (_HTMLElement) {
24
+ (0, _inherits2["default"])(InlineDropdown, _HTMLElement);
25
+ var _super = _createSuper(InlineDropdown);
26
+ function InlineDropdown() {
27
+ var _this;
28
+ (0, _classCallCheck2["default"])(this, InlineDropdown);
29
+ _this = _super.call(this);
30
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_render", function () {
31
+ if (_this._model && _this._session) {
32
+ var elem = /*#__PURE__*/_react["default"].createElement(_main["default"], {
33
+ teacherInstructions: _this._model.teacherInstructions,
34
+ prompt: _this._model.prompt,
35
+ note: _this._model.note,
36
+ showNote: _this._model.showNote,
37
+ env: _this._model.env,
38
+ rationale: _this._model.rationale,
39
+ disabled: _this._model.disabled,
40
+ choices: _this._model.choices,
41
+ markup: _this._model.markup,
42
+ mode: _this._model.mode,
43
+ maxLengthPerChoice: _this._model.maxLengthPerChoice,
44
+ maxLengthPerChoiceEnabled: _this._model.maxLengthPerChoiceEnabled,
45
+ playerSpellCheckEnabled: _this._model.playerSpellCheckEnabled,
46
+ value: _this._session.value,
47
+ feedback: _this._model.feedback,
48
+ displayType: _this._model.displayType,
49
+ onChange: _this.changeSession
50
+ });
51
+ _reactDom["default"].render(elem, (0, _assertThisInitialized2["default"])(_this), function () {
52
+ (0, _mathRendering.renderMath)((0, _assertThisInitialized2["default"])(_this));
53
+ });
54
+ }
55
+ });
56
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "dispatchChangedEvent", function () {
57
+ _this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(_this.tagName.toLowerCase(), _this.session && !!_this.session.value));
58
+ });
59
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeSession", function (value) {
60
+ _this.session.value = value;
61
+ _this.dispatchChangedEvent();
62
+ _this._render();
63
+ });
64
+ _this._model = null;
65
+ _this._session = null;
66
+ return _this;
67
+ }
68
+ (0, _createClass2["default"])(InlineDropdown, [{
69
+ key: "model",
70
+ set: function set(m) {
71
+ this._model = m;
72
+ this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(this.tagName.toLowerCase(), this.session && !!this.session.value, !!this._model));
73
+ this._render();
74
+ }
75
+ }, {
76
+ key: "session",
77
+ get: function get() {
78
+ return this._session;
79
+ },
80
+ set: function set(s) {
81
+ this._session = s;
82
+ this._render();
83
+ }
84
+ }, {
85
+ key: "connectedCallback",
86
+ value: function connectedCallback() {
87
+ this._render();
88
+ }
89
+ }]);
90
+ return InlineDropdown;
91
+ }( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
92
+ exports["default"] = InlineDropdown;
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_reactDom","_piePlayerEvents","_mathRendering","_main","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","result","NewTarget","constructor","Reflect","construct","arguments","apply","_possibleConstructorReturn2","sham","Proxy","Boolean","prototype","valueOf","call","e","InlineDropdown","_HTMLElement","_inherits2","_super","_this","_classCallCheck2","_defineProperty2","_assertThisInitialized2","_model","_session","elem","React","createElement","Main","teacherInstructions","prompt","note","showNote","env","rationale","disabled","choices","markup","mode","maxLengthPerChoice","maxLengthPerChoiceEnabled","playerSpellCheckEnabled","value","feedback","displayType","onChange","changeSession","ReactDOM","render","renderMath","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","session","dispatchChangedEvent","_render","_createClass2","key","set","m","ModelSetEvent","get","s","connectedCallback","_wrapNativeSuper2","HTMLElement","exports"],"sources":["../src/index.js"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { ModelSetEvent, SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport { renderMath } from '@pie-lib/math-rendering';\n\nimport Main from './main';\n\nexport default class InlineDropdown extends HTMLElement {\n constructor() {\n super();\n this._model = null;\n this._session = null;\n }\n\n set model(m) {\n this._model = m;\n this.dispatchEvent(\n new ModelSetEvent(this.tagName.toLowerCase(), this.session && !!this.session.value, !!this._model),\n );\n\n this._render();\n }\n\n set session(s) {\n this._session = s;\n this._render();\n }\n\n get session() {\n return this._session;\n }\n\n _render = () => {\n if (this._model && this._session) {\n let elem = React.createElement(Main, {\n teacherInstructions: this._model.teacherInstructions,\n prompt: this._model.prompt,\n note: this._model.note,\n showNote: this._model.showNote,\n env: this._model.env,\n rationale: this._model.rationale,\n disabled: this._model.disabled,\n choices: this._model.choices,\n markup: this._model.markup,\n mode: this._model.mode,\n maxLengthPerChoice: this._model.maxLengthPerChoice,\n maxLengthPerChoiceEnabled: this._model.maxLengthPerChoiceEnabled,\n playerSpellCheckEnabled: this._model.playerSpellCheckEnabled,\n value: this._session.value,\n feedback: this._model.feedback,\n displayType: this._model.displayType,\n onChange: this.changeSession,\n });\n\n ReactDOM.render(elem, this, () => {\n renderMath(this);\n });\n }\n };\n\n dispatchChangedEvent = () => {\n this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), this.session && !!this.session.value));\n };\n\n changeSession = (value) => {\n this.session.value = value;\n this.dispatchChangedEvent();\n this._render();\n };\n\n connectedCallback() {\n this._render();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;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