@pie-element/math-inline 7.6.1-next.11 → 7.6.1-next.12

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