@pie-element/math-templated 2.11.2-next.7000

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.
Files changed (48) hide show
  1. package/CHANGELOG.json +1 -0
  2. package/CHANGELOG.md +528 -0
  3. package/LICENSE.md +5 -0
  4. package/README.md +0 -0
  5. package/configure/CHANGELOG.json +1 -0
  6. package/configure/CHANGELOG.md +486 -0
  7. package/configure/lib/defaults.js +158 -0
  8. package/configure/lib/defaults.js.map +1 -0
  9. package/configure/lib/design.js +597 -0
  10. package/configure/lib/design.js.map +1 -0
  11. package/configure/lib/index.js +227 -0
  12. package/configure/lib/index.js.map +1 -0
  13. package/configure/lib/markupUtils.js +51 -0
  14. package/configure/lib/markupUtils.js.map +1 -0
  15. package/configure/lib/response.js +442 -0
  16. package/configure/lib/response.js.map +1 -0
  17. package/configure/package.json +20 -0
  18. package/controller/CHANGELOG.json +1 -0
  19. package/controller/CHANGELOG.md +391 -0
  20. package/controller/lib/defaults.js +21 -0
  21. package/controller/lib/defaults.js.map +1 -0
  22. package/controller/lib/index.js +302 -0
  23. package/controller/lib/index.js.map +1 -0
  24. package/controller/package.json +19 -0
  25. package/docs/config-schema.json +104 -0
  26. package/docs/config-schema.json.md +85 -0
  27. package/docs/demo/config.js +8 -0
  28. package/docs/demo/generate.js +42 -0
  29. package/docs/demo/index.html +1 -0
  30. package/docs/demo/session.js +14 -0
  31. package/docs/pie-schema.json +51 -0
  32. package/docs/pie-schema.json.md +37 -0
  33. package/lib/index.js +121 -0
  34. package/lib/index.js.map +1 -0
  35. package/lib/main.js +843 -0
  36. package/lib/main.js.map +1 -0
  37. package/lib/print.js +130 -0
  38. package/lib/print.js.map +1 -0
  39. package/module/configure.js +106458 -0
  40. package/module/controller.js +23132 -0
  41. package/module/demo.js +67 -0
  42. package/module/element.js +127550 -0
  43. package/module/index.html +21 -0
  44. package/module/manifest.json +14 -0
  45. package/module/print-demo.js +105 -0
  46. package/module/print.html +18 -0
  47. package/module/print.js +127498 -0
  48. package/package.json +29 -0
package/lib/main.js ADDED
@@ -0,0 +1,843 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = exports.Main = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
+
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
+
24
+ var _react = _interopRequireDefault(require("react"));
25
+
26
+ var _propTypes = _interopRequireDefault(require("prop-types"));
27
+
28
+ var _classnames = _interopRequireDefault(require("classnames"));
29
+
30
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
31
+
32
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
33
+
34
+ var _styles = require("@material-ui/core/styles");
35
+
36
+ var _Tooltip = _interopRequireDefault(require("@material-ui/core/Tooltip"));
37
+
38
+ var _mathInput = require("@pie-lib/pie-toolbox/math-input");
39
+
40
+ var _renderUi = require("@pie-lib/pie-toolbox/render-ui");
41
+
42
+ var _mathRenderingAccessible = require("@pie-lib/pie-toolbox/math-rendering-accessible");
43
+
44
+ var _mathquill = _interopRequireDefault(require("@pie-framework/mathquill"));
45
+
46
+ var _maskMarkup = require("@pie-lib/pie-toolbox/mask-markup");
47
+
48
+ var _correctAnswerToggle = require("@pie-lib/pie-toolbox/correct-answer-toggle");
49
+
50
+ 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); }; }
51
+
52
+ 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; } }
53
+
54
+ 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; }
55
+
56
+ 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; }
57
+
58
+ var registered = false; // Define a regex pattern to match {{number}}
59
+
60
+ var REGEX = /(\{\{\d+\}\})/gm;
61
+ var DEFAULT_KEYPAD_VARIANT = 6; // !!! If you're using Chrome but have selected the "iPad" device in Chrome Developer Tools, the navigator.userAgent string may still report as
62
+ // Safari because Chrome on iOS actually uses the Safari rendering engine under the hood due to Apple's restrictions on third-party browser engines.
63
+ // When you select the "iPad" device in Chrome Developer Tools, you're essentially emulating the behavior of Safari on an iPad, including the user agent string.
64
+ // Therefore, even though you're using Chrome, the user agent string will resemble that of Safari on an iPad.
65
+ // Since the regular expression /^((?!chrome|android).)*safari/i checks for the presence of "safari" in the user agent string while excluding "chrome" and "android",
66
+ // it will return true in this case because "safari" is present in the user agent string emulated by Chrome when in iPad mode.
67
+
68
+ var IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
69
+
70
+ function generateAdditionalKeys() {
71
+ var keyData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
72
+ return keyData.map(function (key) {
73
+ return {
74
+ name: key,
75
+ latex: key,
76
+ write: key,
77
+ label: key
78
+ };
79
+ });
80
+ }
81
+
82
+ function getKeyPadWidth() {
83
+ var additionalKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
84
+ var equationEditor = arguments.length > 1 ? arguments[1] : undefined;
85
+ return Math.floor(additionalKeys.length / 5) * 30 + (equationEditor === 'miscellaneous' ? 600 : 500);
86
+ }
87
+
88
+ function splitByParts(text) {
89
+ // Use the regex pattern to split the text
90
+ var parts = text.split(REGEX); // Filter out empty strings that might result from splitting
91
+
92
+ return parts.filter(function (part) {
93
+ return part;
94
+ });
95
+ }
96
+
97
+ function prepareForStatic(model, state) {
98
+ var _ref = model || {},
99
+ responses = _ref.responses,
100
+ disabled = _ref.disabled,
101
+ markup = _ref.markup,
102
+ printMode = _ref.printMode,
103
+ alwaysShowCorrect = _ref.alwaysShowCorrect;
104
+
105
+ if (markup) {
106
+ if (state.showCorrect) {
107
+ return Object.keys(responses || {}).reduce(function (acc, responseKey) {
108
+ var _responses$responseKe;
109
+
110
+ acc[responseKey] = responses === null || responses === void 0 ? void 0 : (_responses$responseKe = responses[responseKey]) === null || _responses$responseKe === void 0 ? void 0 : _responses$responseKe.answer;
111
+ return acc;
112
+ }, {});
113
+ }
114
+
115
+ var splitted = splitByParts(markup);
116
+ return splitted.reduce(function (acc, split) {
117
+ if (split.match(REGEX)) {
118
+ var responseKey = Main.getResponseKey(split);
119
+ var answer = state.session.answers["r".concat(responseKey)];
120
+
121
+ if (printMode && !alwaysShowCorrect) {
122
+ var blankSpace = '\\ \\ '.repeat(30) + '\\embed{newLine}[] ';
123
+ return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2["default"])({}, responseKey, "\\MathQuillMathField[r".concat(responseKey, "]{").concat(blankSpace.repeat(3), "}")));
124
+ }
125
+
126
+ if (disabled) {
127
+ return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2["default"])({}, responseKey, "\\embed{answerBlock}[r".concat(responseKey, "]")));
128
+ }
129
+
130
+ return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2["default"])({}, responseKey, "\\MathQuillMathField[r".concat(responseKey, "]{").concat(answer && answer.value || '', "}")));
131
+ }
132
+
133
+ return acc;
134
+ }, {});
135
+ }
136
+ }
137
+
138
+ var Main = /*#__PURE__*/function (_React$Component) {
139
+ (0, _inherits2["default"])(Main, _React$Component);
140
+
141
+ var _super = _createSuper(Main);
142
+
143
+ // removes {{ and }} and returns only key response. Eg: {{0}} => 0
144
+ function Main(props) {
145
+ var _this;
146
+
147
+ (0, _classCallCheck2["default"])(this, Main);
148
+ _this = _super.call(this, props);
149
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleAnswerBlockDomUpdate", function () {
150
+ var _this$props = _this.props,
151
+ model = _this$props.model,
152
+ classes = _this$props.classes;
153
+ var _this$state = _this.state,
154
+ session = _this$state.session,
155
+ showCorrect = _this$state.showCorrect;
156
+ var answers = session.answers;
157
+
158
+ if (_this.root && model.disabled && !showCorrect) {
159
+ Object.keys(answers).forEach(function (answerId) {
160
+ var el = _this.root.querySelector("#".concat(answerId));
161
+
162
+ var indexEl = _this.root.querySelector("#".concat(answerId, "Index"));
163
+
164
+ if (el) {
165
+ var MQ = _mathquill["default"].getInterface(2);
166
+
167
+ var answer = answers[answerId];
168
+ el.textContent = answer && answer.value || '';
169
+
170
+ if (model.view) {
171
+ el.parentElement.parentElement.classList.remove(classes.correct);
172
+ el.parentElement.parentElement.classList.remove(classes.incorrect);
173
+ }
174
+
175
+ MQ.StaticMath(el);
176
+ indexEl.textContent = 'R';
177
+ }
178
+ });
179
+ }
180
+
181
+ (0, _mathRenderingAccessible.renderMath)(_this.root);
182
+ });
183
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSubFieldFocus", function (id) {
184
+ _this.setState({
185
+ activeAnswerBlock: id
186
+ });
187
+ });
188
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toNodeData", function (data) {
189
+ if (!data) {
190
+ return;
191
+ }
192
+
193
+ var type = data.type,
194
+ value = data.value;
195
+ if (type === 'command' || type === 'cursor') return data;
196
+ if (type === 'answer') return _objectSpread({
197
+ type: 'answer'
198
+ }, data);
199
+ if (value === 'clear') return {
200
+ type: 'clear'
201
+ };
202
+ return {
203
+ type: 'write',
204
+ value: value
205
+ };
206
+ });
207
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setInput", function (input) {
208
+ _this.input = input;
209
+ });
210
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onClick", function (data) {
211
+ var c = _this.toNodeData(data);
212
+
213
+ if (c.type === 'clear') {
214
+ _this.input.clear();
215
+ } else if (c.type === 'command') {
216
+ if (Array.isArray(c.value)) {
217
+ c.value.forEach(function (vv) {
218
+ _this.input.cmd(vv);
219
+ });
220
+ } else {
221
+ _this.input.cmd(c.value);
222
+ }
223
+ } else if (c.type === 'cursor') {
224
+ _this.input.keystroke(c.value);
225
+ } else {
226
+ _this.input.write(c.value);
227
+ }
228
+
229
+ _this.input.focus();
230
+ });
231
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "callOnSessionChange", function () {
232
+ var onSessionChange = _this.props.onSessionChange;
233
+
234
+ if (onSessionChange) {
235
+ onSessionChange(_this.state.session);
236
+ }
237
+ });
238
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toggleShowCorrect", function (show) {
239
+ _this.setState({
240
+ showCorrect: show
241
+ }, _this.handleAnswerBlockDomUpdate);
242
+ });
243
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "subFieldChanged", function (name, subfieldValue) {
244
+ (0, _mathInput.updateSpans)();
245
+
246
+ if (name) {
247
+ _this.setState(function (state) {
248
+ return {
249
+ session: _objectSpread(_objectSpread({}, state.session), {}, {
250
+ answers: _objectSpread(_objectSpread({}, state.session.answers), {}, (0, _defineProperty2["default"])({}, name, {
251
+ value: subfieldValue
252
+ }))
253
+ })
254
+ };
255
+ }, _this.callOnSessionChange);
256
+ }
257
+ });
258
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getFieldName", function (changeField, fields) {
259
+ var answers = _this.state.session.answers;
260
+
261
+ if (Object.keys(answers || {}).length) {
262
+ var keys = Object.keys(answers);
263
+ return keys.find(function (k) {
264
+ var tf = fields[k];
265
+ return tf && tf.id == changeField.id;
266
+ });
267
+ }
268
+ });
269
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onBlur", function (e) {
270
+ var _ref2 = e || {},
271
+ relatedTarget = _ref2.relatedTarget,
272
+ currentTarget = _ref2.currentTarget;
273
+
274
+ function getParentWithRoleTooltip(element) {
275
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
276
+ // only run this max 16 times
277
+ if (!element || depth >= 16) return null;
278
+ var parent = element.offsetParent;
279
+ if (!parent) return null;
280
+
281
+ if (parent.getAttribute('role') === 'tooltip') {
282
+ return parent;
283
+ }
284
+
285
+ return getParentWithRoleTooltip(parent, depth + 1);
286
+ }
287
+
288
+ function getDeepChildDataKeypad(element) {
289
+ var _element$children;
290
+
291
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
292
+ // only run this max 4 times
293
+ if (!element || depth >= 4) return null;
294
+ var child = element === null || element === void 0 ? void 0 : (_element$children = element.children) === null || _element$children === void 0 ? void 0 : _element$children[0];
295
+ if (!child) return null;
296
+
297
+ if (child.attributes && child.attributes['data-keypad']) {
298
+ return child;
299
+ }
300
+
301
+ return getDeepChildDataKeypad(child, depth + 1);
302
+ }
303
+
304
+ var parentWithTooltipRole = getParentWithRoleTooltip(relatedTarget);
305
+ var childWithDataKeypad = parentWithTooltipRole ? getDeepChildDataKeypad(parentWithTooltipRole) : null;
306
+
307
+ if (!relatedTarget || !currentTarget || !(childWithDataKeypad !== null && childWithDataKeypad !== void 0 && childWithDataKeypad.attributes['data-keypad'])) {
308
+ _this.setState({
309
+ activeAnswerBlock: ''
310
+ });
311
+ }
312
+ });
313
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "renderTeacherInstructions", function () {
314
+ var _this$props2 = _this.props,
315
+ model = _this$props2.model,
316
+ classes = _this$props2.classes;
317
+
318
+ var _ref3 = model || {},
319
+ teacherInstructions = _ref3.teacherInstructions,
320
+ animationsDisabled = _ref3.animationsDisabled;
321
+
322
+ var teacherInstructionsDiv = /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
323
+ defaultClassName: "teacher-instructions",
324
+ prompt: teacherInstructions
325
+ });
326
+
327
+ return teacherInstructions && (0, _renderUi.hasText)(teacherInstructions) && /*#__PURE__*/_react["default"].createElement("div", {
328
+ className: classes.collapsible
329
+ }, !animationsDisabled ? /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
330
+ labels: {
331
+ hidden: 'Show Teacher Instructions',
332
+ visible: 'Hide Teacher Instructions'
333
+ }
334
+ }, teacherInstructionsDiv) : teacherInstructionsDiv);
335
+ });
336
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "renderRationale", function () {
337
+ var _this$props3 = _this.props,
338
+ model = _this$props3.model,
339
+ classes = _this$props3.classes;
340
+
341
+ var _ref4 = model || {},
342
+ rationale = _ref4.rationale,
343
+ animationsDisabled = _ref4.animationsDisabled;
344
+
345
+ var rationaleDiv = /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
346
+ prompt: rationale
347
+ });
348
+
349
+ return rationale && (0, _renderUi.hasText)(rationale) && /*#__PURE__*/_react["default"].createElement("div", {
350
+ className: classes.collapsible
351
+ }, !animationsDisabled ? /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
352
+ labels: {
353
+ hidden: 'Show Rationale',
354
+ visible: 'Hide Rationale'
355
+ }
356
+ }, rationaleDiv) : rationaleDiv);
357
+ });
358
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "renderPlayerContent", function () {
359
+ var _this$props4 = _this.props,
360
+ model = _this$props4.model,
361
+ classes = _this$props4.classes;
362
+ var _this$state2 = _this.state,
363
+ activeAnswerBlock = _this$state2.activeAnswerBlock,
364
+ showCorrect = _this$state2.showCorrect,
365
+ session = _this$state2.session;
366
+
367
+ var _ref5 = model || {},
368
+ correctness = _ref5.correctness,
369
+ disabled = _ref5.disabled,
370
+ view = _ref5.view,
371
+ responses = _ref5.responses,
372
+ equationEditor = _ref5.equationEditor,
373
+ customKeys = _ref5.customKeys,
374
+ feedback = _ref5.feedback,
375
+ _ref5$env = _ref5.env;
376
+
377
+ _ref5$env = _ref5$env === void 0 ? {} : _ref5$env;
378
+ var mode = _ref5$env.mode,
379
+ printMode = _ref5.printMode,
380
+ alwaysShowCorrect = _ref5.alwaysShowCorrect;
381
+ var emptyResponse = (0, _isEmpty["default"])(responses);
382
+ var additionalKeys = generateAdditionalKeys(customKeys);
383
+ var statics = prepareForStatic(model, _this.state) || '';
384
+ var studentPrintMode = printMode && !alwaysShowCorrect;
385
+ return /*#__PURE__*/_react["default"].createElement("div", {
386
+ className: classes.inputAndKeypadContainer
387
+ }, /*#__PURE__*/_react["default"].createElement(_maskMarkup.Customizable, {
388
+ disabled: disabled,
389
+ markup: model.markup // TODO remove the need of value?
390
+ ,
391
+ value: {},
392
+ customMarkMarkupComponent: function customMarkMarkupComponent(id) {
393
+ var _cx;
394
+
395
+ var responseIsCorrect = mode === 'evaluate' && feedback[id];
396
+
397
+ var MQStatic = /*#__PURE__*/_react["default"].createElement(_mathInput.mq.Static, {
398
+ className: classes["static"],
399
+ ref: function ref(mqStatic) {
400
+ _this.mqStatic = mqStatic || _this.mqStatic;
401
+ },
402
+ latex: statics[id],
403
+ onSubFieldChange: _this.subFieldChanged,
404
+ getFieldName: _this.getFieldName,
405
+ setInput: _this.setInput,
406
+ onSubFieldFocus: _this.onSubFieldFocus,
407
+ onBlur: _this.onBlur
408
+ });
409
+
410
+ return /*#__PURE__*/_react["default"].createElement("div", {
411
+ className: (0, _classnames["default"])(classes.expression, (_cx = {}, (0, _defineProperty2["default"])(_cx, classes.incorrect, !emptyResponse && !responseIsCorrect && !showCorrect), (0, _defineProperty2["default"])(_cx, classes.correct, !emptyResponse && (responseIsCorrect || showCorrect)), (0, _defineProperty2["default"])(_cx, classes.showCorrectness, !emptyResponse && disabled && correctness && !view), (0, _defineProperty2["default"])(_cx, classes.correctAnswerShown, showCorrect), _cx))
412
+ }, /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
413
+ ref: function ref(_ref6) {
414
+ return _this.setTooltipRef(_ref6);
415
+ },
416
+ enterTouchDelay: 0,
417
+ interactive: true,
418
+ open: activeAnswerBlock === "r".concat(id),
419
+ classes: {
420
+ tooltip: classes.keypadTooltip,
421
+ popper: classes.keypadTooltipPopper
422
+ },
423
+ title: Object.keys(session.answers).map(function (answerId) {
424
+ return answerId === activeAnswerBlock && !(showCorrect || disabled) && /*#__PURE__*/_react["default"].createElement("div", {
425
+ "data-keypad": true,
426
+ key: answerId,
427
+ className: classes.responseContainer,
428
+ style: {
429
+ width: getKeyPadWidth(additionalKeys, equationEditor)
430
+ }
431
+ }, /*#__PURE__*/_react["default"].createElement(_mathInput.HorizontalKeypad, {
432
+ additionalKeys: additionalKeys,
433
+ mode: equationEditor || DEFAULT_KEYPAD_VARIANT,
434
+ onClick: _this.onClick
435
+ })) || null;
436
+ })
437
+ }, studentPrintMode ? /*#__PURE__*/_react["default"].createElement("div", {
438
+ className: classes.printContainer
439
+ }, MQStatic) : MQStatic));
440
+ }
441
+ }));
442
+ });
443
+ var _answers = {};
444
+
445
+ var _ref7 = props || {},
446
+ _model = _ref7.model,
447
+ _session = _ref7.session;
448
+
449
+ var _ref8 = _model || {},
450
+ markup = _ref8.markup,
451
+ _alwaysShowCorrect = _ref8.alwaysShowCorrect;
452
+
453
+ var _ref9 = _session || {},
454
+ sessionAnswers = _ref9.answers;
455
+
456
+ if (markup) {
457
+ // build out local state model using responses declared in markup
458
+ (markup || '').replace(REGEX, function (response) {
459
+ var responseKey = Main.getResponseKey(response);
460
+ var sessionAnswerForResponse = sessionAnswers && sessionAnswers["r".concat(responseKey)];
461
+ _answers["r".concat(responseKey)] = {
462
+ value: (sessionAnswerForResponse === null || sessionAnswerForResponse === void 0 ? void 0 : sessionAnswerForResponse.value) || ''
463
+ };
464
+ });
465
+ }
466
+
467
+ _this.state = {
468
+ session: _objectSpread(_objectSpread({}, props.session), {}, {
469
+ answers: _answers
470
+ }),
471
+ activeAnswerBlock: '',
472
+ showCorrect: _alwaysShowCorrect || false
473
+ };
474
+ return _this;
475
+ }
476
+
477
+ (0, _createClass2["default"])(Main, [{
478
+ key: "UNSAFE_componentWillMount",
479
+ value: function UNSAFE_componentWillMount() {
480
+ var classes = this.props.classes;
481
+
482
+ if (typeof window !== 'undefined') {
483
+ var MQ = _mathquill["default"].getInterface(2);
484
+
485
+ if (!registered) {
486
+ MQ.registerEmbed('answerBlock', function (data) {
487
+ return {
488
+ htmlString: "<div class=\"".concat(classes.blockContainer, "\">\n <div class=\"").concat(classes.blockResponse, "\" id=\"").concat(data, "Index\">R</div>\n <div class=\"").concat(classes.blockMath, "\">\n <span id=\"").concat(data, "\"></span>\n </div>\n </div>"),
489
+ text: function text() {
490
+ return 'text';
491
+ },
492
+ latex: function latex() {
493
+ return "\\embed{answerBlock}[".concat(data, "]");
494
+ }
495
+ };
496
+ });
497
+ registered = true;
498
+ }
499
+ }
500
+ }
501
+ }, {
502
+ key: "UNSAFE_componentWillReceiveProps",
503
+ value: function UNSAFE_componentWillReceiveProps(nextProps) {
504
+ var _this2 = this;
505
+
506
+ var markup = this.props.model.markup;
507
+
508
+ var _ref10 = nextProps.model || {},
509
+ nextMarkup = _ref10.markup;
510
+
511
+ var matches = markup.match(REGEX);
512
+ var nextMatches = nextMarkup.match(REGEX); // If markup changed, and we no longer have the same response area, the session needs to be updated
513
+
514
+ if (!(0, _isEqual["default"])(matches, nextMatches)) {
515
+ var newAnswers = {};
516
+ var answers = this.state.session.answers;
517
+ (nextMatches || []).forEach(function (nextMatch) {
518
+ var responseKey = Main.getResponseKey(nextMatch);
519
+ var sessionAnswerForResponse = answers && answers["r".concat(responseKey)]; // build out local state model using responses declared in markup
520
+
521
+ newAnswers["r".concat(responseKey)] = {
522
+ value: (sessionAnswerForResponse === null || sessionAnswerForResponse === void 0 ? void 0 : sessionAnswerForResponse.value) || ''
523
+ };
524
+ });
525
+ this.setState(function (state) {
526
+ return {
527
+ session: _objectSpread(_objectSpread({}, state.session), {}, {
528
+ answers: newAnswers
529
+ })
530
+ };
531
+ }, function () {
532
+ _this2.props.onSessionChange(_this2.state.session);
533
+
534
+ _this2.handleAnswerBlockDomUpdate();
535
+ });
536
+ }
537
+ }
538
+ }, {
539
+ key: "shouldComponentUpdate",
540
+ value: function shouldComponentUpdate(nextProps, nextState) {
541
+ var sameModel = (0, _isEqual["default"])(this.props.model, nextProps.model);
542
+ var sameState = (0, _isEqual["default"])(this.state, nextState);
543
+ return !sameModel || !sameState;
544
+ }
545
+ }, {
546
+ key: "componentDidMount",
547
+ value: function componentDidMount() {
548
+ var _this3 = this;
549
+
550
+ this.handleAnswerBlockDomUpdate();
551
+ setTimeout(function () {
552
+ return (0, _mathRenderingAccessible.renderMath)(_this3.root);
553
+ }, 100);
554
+ }
555
+ }, {
556
+ key: "componentDidUpdate",
557
+ value: function componentDidUpdate() {
558
+ this.handleAnswerBlockDomUpdate();
559
+ }
560
+ }, {
561
+ key: "setTooltipRef",
562
+ value: // function for tooltip
563
+ function setTooltipRef(ref) {
564
+ // Safari Hack: https://stackoverflow.com/a/42764495/5757635
565
+ setTimeout(function () {
566
+ if (ref && IS_SAFARI) {
567
+ var div = document.querySelector('[role=\'tooltip\']');
568
+
569
+ if (div) {
570
+ var el = div.firstChild;
571
+ el.setAttribute('tabindex', '-1');
572
+ }
573
+ }
574
+ }, 1);
575
+ }
576
+ }, {
577
+ key: "render",
578
+ value: function render() {
579
+ var _this4 = this;
580
+
581
+ var _this$props5 = this.props,
582
+ model = _this$props5.model,
583
+ classes = _this$props5.classes;
584
+ var showCorrect = this.state.showCorrect;
585
+
586
+ var _ref11 = model || {},
587
+ prompt = _ref11.prompt,
588
+ _ref11$env = _ref11.env;
589
+
590
+ _ref11$env = _ref11$env === void 0 ? {} : _ref11$env;
591
+ var mode = _ref11$env.mode,
592
+ role = _ref11$env.role,
593
+ correctness = _ref11.correctness,
594
+ responses = _ref11.responses,
595
+ language = _ref11.language,
596
+ showNote = _ref11.showNote,
597
+ note = _ref11.note;
598
+ var emptyResponse = (0, _isEmpty["default"])(responses);
599
+ var showCorrectAnswerToggle = !emptyResponse && correctness && correctness.correctness !== 'correct';
600
+ var displayNote = (showCorrect || mode === 'view' && role === 'instructor') && showNote && note;
601
+ return /*#__PURE__*/_react["default"].createElement("div", {
602
+ className: classes.mainContainer,
603
+ ref: function ref(r) {
604
+ return _this4.root = r || _this4.root;
605
+ }
606
+ }, /*#__PURE__*/_react["default"].createElement("div", {
607
+ className: classes.main
608
+ }, mode === 'gather' && /*#__PURE__*/_react["default"].createElement("h2", {
609
+ className: classes.srOnly
610
+ }, "Math Equation Response Question"), /*#__PURE__*/_react["default"].createElement("div", {
611
+ className: classes.main
612
+ }, showCorrectAnswerToggle && /*#__PURE__*/_react["default"].createElement(_correctAnswerToggle.CorrectAnswerToggle, {
613
+ language: language,
614
+ className: classes.toggle,
615
+ show: true,
616
+ toggled: showCorrect,
617
+ onToggle: this.toggleShowCorrect
618
+ })), this.renderTeacherInstructions(), prompt && /*#__PURE__*/_react["default"].createElement("div", {
619
+ className: classes.promptContainer
620
+ }, /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
621
+ prompt: prompt
622
+ })), /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
623
+ "false": true
624
+ }, this.renderPlayerContent()), displayNote && /*#__PURE__*/_react["default"].createElement("div", {
625
+ className: (0, _classnames["default"])(classes.note, 'note'),
626
+ dangerouslySetInnerHTML: {
627
+ __html: note
628
+ }
629
+ }), this.renderRationale()));
630
+ }
631
+ }]);
632
+ return Main;
633
+ }(_react["default"].Component);
634
+
635
+ exports.Main = Main;
636
+ (0, _defineProperty2["default"])(Main, "getResponseKey", function (response) {
637
+ return (response || '').replaceAll('{{', '').replaceAll('}}', '');
638
+ });
639
+ (0, _defineProperty2["default"])(Main, "propTypes", {
640
+ classes: _propTypes["default"].object,
641
+ session: _propTypes["default"].object.isRequired,
642
+ onSessionChange: _propTypes["default"].func,
643
+ model: _propTypes["default"].object.isRequired
644
+ });
645
+
646
+ var styles = function styles(theme) {
647
+ return {
648
+ mainContainer: {
649
+ color: _renderUi.color.text(),
650
+ backgroundColor: _renderUi.color.background(),
651
+ display: 'inline-block'
652
+ },
653
+ tooltip: {
654
+ background: "".concat(_renderUi.color.primaryLight(), " !important"),
655
+ color: _renderUi.color.text(),
656
+ padding: theme.spacing.unit * 2,
657
+ border: "1px solid ".concat(_renderUi.color.secondary()),
658
+ fontSize: '16px',
659
+ '& :not(.MathJax) > table tr': {
660
+ '&:nth-child(2n)': {
661
+ backgroundColor: 'unset !important'
662
+ }
663
+ }
664
+ },
665
+ tooltipPopper: {
666
+ opacity: 1
667
+ },
668
+ keypadTooltip: {
669
+ fontSize: 'initial',
670
+ background: 'transparent',
671
+ width: '600px',
672
+ marginTop: 0,
673
+ paddingTop: 0
674
+ },
675
+ keypadTooltipPopper: {
676
+ background: 'transparent',
677
+ width: '650px',
678
+ opacity: 1
679
+ },
680
+ promptContainer: {
681
+ marginBottom: theme.spacing.unit * 2
682
+ },
683
+ main: {
684
+ width: '100%',
685
+ position: 'relative',
686
+ backgroundColor: _renderUi.color.background(),
687
+ color: _renderUi.color.text()
688
+ },
689
+ title: {
690
+ fontSize: '1.1rem',
691
+ display: 'block',
692
+ marginTop: theme.spacing.unit * 2,
693
+ marginBottom: theme.spacing.unit
694
+ },
695
+ collapsible: {
696
+ marginBottom: theme.spacing.unit * 2
697
+ },
698
+ responseContainer: {
699
+ zIndex: 10,
700
+ minWidth: '400px',
701
+ marginTop: theme.spacing.unit * 2
702
+ },
703
+ expression: {
704
+ maxWidth: 'fit-content',
705
+ '& > .mq-math-mode': {
706
+ '& > .mq-root-block': {
707
+ '& > .mq-editable-field': {
708
+ minWidth: '10px',
709
+ margin: theme.spacing.unit * 2 / 3,
710
+ padding: theme.spacing.unit / 4
711
+ }
712
+ },
713
+ '& sup': {
714
+ top: 0
715
+ }
716
+ }
717
+ },
718
+ "static": {
719
+ '& > .mq-root-block': {
720
+ '& > .mq-editable-field': {
721
+ borderColor: _renderUi.color.text()
722
+ }
723
+ }
724
+ },
725
+ inputAndKeypadContainer: {
726
+ position: 'relative',
727
+ '& > div > div': {
728
+ display: 'flex',
729
+ alignItems: 'baseline',
730
+ flexWrap: 'wrap'
731
+ },
732
+ '& .mq-overarrow-inner': {
733
+ border: 'none !important',
734
+ padding: '0 !important'
735
+ },
736
+ '& .mq-overarrow-inner-right': {
737
+ display: 'none !important'
738
+ },
739
+ '& .mq-overarrow-inner-left': {
740
+ display: 'none !important'
741
+ },
742
+ '& .mq-overarrow.mq-arrow-both': {
743
+ minWidth: '1.23em',
744
+ '& *': {
745
+ lineHeight: '1 !important'
746
+ },
747
+ '&:before': {
748
+ top: '-0.4em',
749
+ left: '-1px'
750
+ },
751
+ '&:after': {
752
+ top: '-2.4em',
753
+ right: '-1px'
754
+ },
755
+ '&.mq-empty:after': {
756
+ top: '-0.45em'
757
+ }
758
+ },
759
+ '& .mq-overarrow.mq-arrow-right': {
760
+ '&:before': {
761
+ top: '-0.4em',
762
+ right: '-1px'
763
+ }
764
+ },
765
+ '& .mq-longdiv-inner': {
766
+ borderTop: '1px solid !important',
767
+ paddingTop: '1.5px !important'
768
+ },
769
+ '& .mq-parallelogram': {
770
+ lineHeight: 0.85
771
+ }
772
+ },
773
+ showCorrectness: {
774
+ border: '2px solid'
775
+ },
776
+ correctAnswerShown: {
777
+ padding: theme.spacing.unit,
778
+ letterSpacing: '0.5px'
779
+ },
780
+ correct: {
781
+ borderColor: "".concat(_renderUi.color.correct(), " !important")
782
+ },
783
+ incorrect: {
784
+ borderColor: "".concat(_renderUi.color.incorrect(), " !important")
785
+ },
786
+ blockContainer: {
787
+ margin: "".concat(theme.spacing.unit, "px !important"),
788
+ display: 'inline-flex',
789
+ border: '2px solid grey !important'
790
+ },
791
+ blockResponse: {
792
+ flex: 2,
793
+ color: 'grey',
794
+ background: theme.palette.grey['A100'],
795
+ fontSize: '0.8rem !important',
796
+ padding: "".concat(theme.spacing.unit / 2, "px !important"),
797
+ display: 'flex',
798
+ alignItems: 'center',
799
+ justifyContent: 'center',
800
+ borderRight: "2px solid ".concat(_renderUi.color.disabled(), " !important")
801
+ },
802
+ toggle: {
803
+ color: _renderUi.color.text(),
804
+ marginBottom: theme.spacing.unit * 2
805
+ },
806
+ blockMath: {
807
+ color: _renderUi.color.text(),
808
+ backgroundColor: _renderUi.color.background(),
809
+ padding: "".concat(theme.spacing.unit / 2, "px !important"),
810
+ display: 'flex',
811
+ alignItems: 'center',
812
+ justifyContent: 'center',
813
+ flex: 8,
814
+ '& > .mq-math-mode': {
815
+ '& > .mq-hasCursor': {
816
+ '& > .mq-cursor': {
817
+ display: 'none'
818
+ }
819
+ }
820
+ }
821
+ },
822
+ printContainer: {
823
+ marginBottom: theme.spacing.unit,
824
+ pointerEvents: 'none'
825
+ },
826
+ srOnly: {
827
+ position: 'absolute',
828
+ left: '-10000px',
829
+ top: 'auto',
830
+ width: '1px',
831
+ height: '1px',
832
+ overflow: 'hidden'
833
+ },
834
+ note: {
835
+ marginBottom: theme.spacing.unit * 2
836
+ }
837
+ };
838
+ };
839
+
840
+ var _default = (0, _styles.withStyles)(styles)(Main);
841
+
842
+ exports["default"] = _default;
843
+ //# sourceMappingURL=main.js.map