@pie-element/math-inline 10.3.4-next.3 → 11.0.0-beta.0

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 +161 -239
  2. package/configure/lib/configure.js.map +1 -1
  3. package/configure/lib/defaults.js +5 -8
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/general-config-block.js +445 -561
  6. package/configure/lib/general-config-block.js.map +1 -1
  7. package/configure/lib/index.js +110 -175
  8. package/configure/lib/index.js.map +1 -1
  9. package/configure/lib/response.js +330 -388
  10. package/configure/lib/response.js.map +1 -1
  11. package/configure/lib/utils.js +15 -30
  12. package/configure/lib/utils.js.map +1 -1
  13. package/configure/package.json +13 -11
  14. package/controller/lib/defaults.js +5 -8
  15. package/controller/lib/defaults.js.map +1 -1
  16. package/controller/lib/index.js +188 -277
  17. package/controller/lib/index.js.map +1 -1
  18. package/controller/lib/utils.js +1 -2
  19. package/controller/lib/utils.js.map +1 -1
  20. package/controller/package.json +5 -5
  21. package/lib/index.js +70 -123
  22. package/lib/index.js.map +1 -1
  23. package/lib/main.js +783 -890
  24. package/lib/main.js.map +1 -1
  25. package/lib/print.js +42 -83
  26. package/lib/print.js.map +1 -1
  27. package/lib/simple-question-block.js +125 -162
  28. package/lib/simple-question-block.js.map +1 -1
  29. package/lib/utils.js +1 -2
  30. package/lib/utils.js.map +1 -1
  31. package/package.json +15 -16
  32. package/module/configure.js +0 -1
  33. package/module/controller.js +0 -4278
  34. package/module/demo.js +0 -66
  35. package/module/element.js +0 -1
  36. package/module/index.html +0 -21
  37. package/module/manifest.json +0 -18
  38. package/module/print-demo.js +0 -104
  39. package/module/print.html +0 -18
  40. package/module/print.js +0 -1
package/lib/main.js CHANGED
@@ -1,342 +1,262 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
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
-
7
+ exports.default = exports.Main = void 0;
22
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
-
24
9
  var _react = _interopRequireDefault(require("react"));
25
-
26
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
27
-
28
11
  var _correctAnswerToggle = _interopRequireDefault(require("@pie-lib/correct-answer-toggle"));
29
-
30
12
  var _mathInput = require("@pie-lib/math-input");
31
-
32
13
  var _renderUi = require("@pie-lib/render-ui");
33
-
34
14
  var _mathRendering = require("@pie-lib/math-rendering");
35
-
36
- var _styles = require("@material-ui/core/styles");
37
-
38
- var _Tooltip = _interopRequireDefault(require("@material-ui/core/Tooltip"));
39
-
15
+ var _styles = require("@mui/material/styles");
16
+ var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
40
17
  var _utils = require("./utils");
41
-
42
18
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
43
-
44
- var _classnames = _interopRequireDefault(require("classnames"));
45
-
46
19
  var _simpleQuestionBlock = _interopRequireDefault(require("./simple-question-block"));
47
-
48
20
  var _mathquill = _interopRequireDefault(require("@pie-framework/mathquill"));
49
-
50
21
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
51
-
52
22
  var _translator = _interopRequireDefault(require("@pie-lib/translator"));
53
-
54
23
  var _reactDom = _interopRequireDefault(require("react-dom"));
55
-
56
- 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; }
57
-
58
- 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; }
59
-
60
- 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); }; }
61
-
62
- 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; } }
63
-
64
- var translator = _translator["default"].translator;
65
- var registered = false;
66
- var NEWLINE_LATEX = /\\newline/g;
67
- var REGEX = /{{response}}/gm;
68
- 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
24
+ const {
25
+ translator
26
+ } = _translator.default;
27
+ let registered = false;
28
+ const NEWLINE_LATEX = /\\newline/g;
29
+ const REGEX = /{{response}}/gm;
30
+ const DEFAULT_KEYPAD_VARIANT = 6;
31
+
32
+ // !!! If you're using Chrome but have selected the "iPad" device in Chrome Developer Tools, the navigator.userAgent string may still report as
69
33
  // Safari because Chrome on iOS actually uses the Safari rendering engine under the hood due to Apple's restrictions on third-party browser engines.
70
34
  // 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.
71
35
  // Therefore, even though you're using Chrome, the user agent string will resemble that of Safari on an iPad.
72
36
  // Since the regular expression /^((?!chrome|android).)*safari/i checks for the presence of "safari" in the user agent string while excluding "chrome" and "android",
73
37
  // it will return true in this case because "safari" is present in the user agent string emulated by Chrome when in iPad mode.
74
-
75
- var IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
76
-
77
- function generateAdditionalKeys() {
78
- var keyData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
79
- return keyData.map(function (key) {
80
- return {
81
- name: key,
82
- latex: key,
83
- write: key,
84
- label: key
85
- };
86
- });
38
+ const IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
39
+ function generateAdditionalKeys(keyData = []) {
40
+ return keyData.map(key => ({
41
+ name: key,
42
+ latex: key,
43
+ write: key,
44
+ label: key
45
+ }));
87
46
  }
88
-
89
47
  function isChildOfCurrentPieElement(child, parent) {
90
- var node = child;
91
-
48
+ let node = child;
92
49
  while (node !== null) {
93
50
  if (parent && node === parent) {
94
51
  return true;
95
52
  }
96
-
97
53
  node = node.parentNode;
98
54
  }
99
-
100
55
  return false;
101
56
  }
102
-
103
- function getKeyPadWidth() {
104
- var additionalKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
105
- var equationEditor = arguments.length > 1 ? arguments[1] : undefined;
57
+ function getKeyPadWidth(additionalKeys = [], equationEditor) {
106
58
  return Math.floor(additionalKeys.length / 5) * 30 + (equationEditor === 'miscellaneous' ? 600 : 500);
107
59
  }
108
-
109
60
  function prepareForStatic(model, state) {
110
- var _ref = model || {},
111
- config = _ref.config,
112
- disabled = _ref.disabled;
113
-
114
- var _ref2 = config || {},
115
- expression = _ref2.expression,
116
- responses = _ref2.responses,
117
- printMode = _ref2.printMode,
118
- alwaysShowCorrect = _ref2.alwaysShowCorrect;
119
-
61
+ const {
62
+ config,
63
+ disabled
64
+ } = model || {};
65
+ const {
66
+ expression,
67
+ responses,
68
+ printMode,
69
+ alwaysShowCorrect
70
+ } = config || {};
120
71
  if (config && expression) {
121
- var modelExpression = expression;
122
-
72
+ const modelExpression = expression;
123
73
  if (state.showCorrect) {
124
74
  return responses && responses.length && responses[0].answer;
125
75
  }
126
-
127
- var answerBlocks = 1; // assume one at least
76
+ let answerBlocks = 1; // assume one at least
128
77
  // build out local state model using responses declared in expression
129
78
 
130
79
  return (modelExpression || '').replace(REGEX, function () {
131
- var answer = state.session.answers["r".concat(answerBlocks)];
132
-
80
+ const answer = state.session.answers[`r${answerBlocks}`];
133
81
  if (printMode && !alwaysShowCorrect) {
134
- var blankSpace = '\\ \\ '.repeat(30) + '\\newline ';
135
- return "\\MathQuillMathField[r".concat(answerBlocks++, "]{").concat(blankSpace.repeat(3), "}");
82
+ const blankSpace = '\\ \\ '.repeat(30) + '\\newline ';
83
+ return `\\MathQuillMathField[r${answerBlocks++}]{${blankSpace.repeat(3)}}`;
136
84
  }
137
-
138
85
  if (disabled) {
139
- return "\\embed{answerBlock}[r".concat(answerBlocks++, "]");
86
+ return `\\embed{answerBlock}[r${answerBlocks++}]`;
140
87
  }
141
-
142
- return "\\MathQuillMathField[r".concat(answerBlocks++, "]{").concat(answer && answer.value || '', "}");
88
+ return `\\MathQuillMathField[r${answerBlocks++}]{${answer && answer.value || ''}}`;
143
89
  }).replace(NEWLINE_LATEX, '\\embed{newLine}[]');
144
90
  }
145
91
  }
146
-
147
92
  function parseAnswers(session, model) {
148
- var answers = {};
149
-
93
+ const answers = {};
150
94
  if (model.config && model.config.expression) {
151
- var answerBlocks = 1; // assume one at least
95
+ let answerBlocks = 1; // assume one at least
152
96
  // build out local state model using responses declared in expression
153
97
 
154
- (model.config.expression || '').replace(REGEX, function () {
155
- answers["r".concat(answerBlocks)] = {
156
- value: session && session.answers && session.answers["r".concat(answerBlocks)] && session.answers["r".concat(answerBlocks)].value || ''
98
+ (model.config.expression || '').replace(REGEX, () => {
99
+ answers[`r${answerBlocks}`] = {
100
+ value: session && session.answers && session.answers[`r${answerBlocks}`] && session.answers[`r${answerBlocks}`].value || ''
157
101
  };
158
102
  answerBlocks += 1;
159
103
  });
160
104
  }
161
-
162
105
  return answers;
163
106
  }
164
-
165
- var Main = /*#__PURE__*/function (_React$Component) {
166
- (0, _inherits2["default"])(Main, _React$Component);
167
-
168
- var _super = _createSuper(Main);
169
-
170
- function Main(props) {
171
- var _this;
172
-
173
- (0, _classCallCheck2["default"])(this, Main);
174
- _this = _super.call(this, props);
175
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleAnswerBlockDomUpdate", function () {
176
- var _this$props = _this.props,
177
- model = _this$props.model,
178
- classes = _this$props.classes;
179
- var _this$state = _this.state,
180
- session = _this$state.session,
181
- showCorrect = _this$state.showCorrect;
182
- var answers = session.answers;
183
-
184
- if (_this.root && model.disabled && !showCorrect) {
185
- Object.keys(answers).forEach(function (answerId) {
186
- var el = _this.root.querySelector("#".concat(answerId));
187
-
188
- var indexEl = _this.root.querySelector("#".concat(answerId, "Index")); // const correct = model.correctness && model.correctness.correct;
189
-
107
+ class Main extends _react.default.Component {
108
+ constructor(props) {
109
+ super(props);
110
+ (0, _defineProperty2.default)(this, "handleAnswerBlockDomUpdate", () => {
111
+ const {
112
+ model
113
+ } = this.props;
114
+ const {
115
+ session,
116
+ showCorrect
117
+ } = this.state;
118
+ const answers = session.answers;
119
+ if (this.root && model.disabled && !showCorrect) {
120
+ Object.keys(answers).forEach(answerId => {
121
+ const el = this.root.querySelector(`#${answerId}`);
122
+ const indexEl = this.root.querySelector(`#${answerId}Index`);
123
+ // const correct = model.correctness && model.correctness.correct;
190
124
 
191
125
  if (el) {
192
- var MQ = _mathquill["default"].getInterface(2);
193
-
194
- var answer = answers[answerId];
126
+ let MQ = _mathquill.default.getInterface(2);
127
+ const answer = answers[answerId];
195
128
  el.textContent = answer && answer.value || '';
196
-
197
- if (!model.view) {// for now, we're not going to be showing individual response correctness
129
+ if (!model.view) {
130
+ // for now, we're not going to be showing individual response correctness
198
131
  // TODO re-attach the classes once we are
199
132
  // el.parentElement.parentElement.classList.add(
200
- // correct ? classes.correct : classes.incorrect
133
+ // correct ? 'correct' : 'incorrect'
201
134
  // );
202
135
  } else {
203
- el.parentElement.parentElement.classList.remove(classes.correct);
204
- el.parentElement.parentElement.classList.remove(classes.incorrect);
136
+ el.parentElement.parentElement.classList.remove('correct');
137
+ el.parentElement.parentElement.classList.remove('incorrect');
205
138
  }
139
+ MQ.StaticMath(el);
206
140
 
207
- MQ.StaticMath(el); // For now, we're not going to be indexing response blocks
141
+ // For now, we're not going to be indexing response blocks
208
142
  // TODO go back to indexing once we support individual response correctness
209
143
  // indexEl.textContent = `R${idx + 1}`;
210
-
211
144
  indexEl.textContent = 'R';
212
145
  }
213
146
  });
214
147
  }
215
-
216
- (0, _mathRendering.renderMath)(_this.root);
148
+ (0, _mathRendering.renderMath)(this.root);
217
149
  });
218
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateAria", function () {
219
- var classes = _this.props.classes;
220
-
221
- if (_this.root) {
150
+ (0, _defineProperty2.default)(this, "updateAria", () => {
151
+ if (this.root) {
222
152
  // Update aria-hidden for .mq-selectable elements
223
- var selectableElements = _this.root.querySelectorAll('.mq-selectable');
153
+ const selectableElements = this.root.querySelectorAll('.mq-selectable');
154
+ selectableElements.forEach(elem => elem.setAttribute('aria-hidden', 'true'));
224
155
 
225
- selectableElements.forEach(function (elem) {
226
- return elem.setAttribute('aria-hidden', 'true');
227
- }); // Update aria-label for textarea elements and add aria-describedby
156
+ // Update aria-label for textarea elements and add aria-describedby
157
+ const textareaElements = this.root.querySelectorAll('textarea');
158
+ textareaElements.forEach((elem, index) => {
159
+ elem.setAttribute('aria-label', 'Enter answer.');
228
160
 
229
- var textareaElements = _this.root.querySelectorAll('textarea');
230
-
231
- textareaElements.forEach(function (elem, index) {
232
- elem.setAttribute('aria-label', 'Enter answer.'); // Create a unique id for each instructions element
233
-
234
- var instructionsId = "instructions-".concat(index); // Find the parent element that contains the textarea
235
-
236
- var parent = elem.closest('.mq-textarea');
161
+ // Create a unique id for each instructions element
162
+ const instructionsId = `instructions-${index}`;
237
163
 
164
+ // Find the parent element that contains the textarea
165
+ const parent = elem.closest('.mq-textarea');
238
166
  if (parent) {
239
167
  // Create or find the instructions element within the parent
240
- var instructionsElement = parent.querySelector("#".concat(instructionsId));
241
-
168
+ let instructionsElement = parent.querySelector(`#${instructionsId}`);
242
169
  if (!instructionsElement) {
243
170
  instructionsElement = document.createElement('span');
244
171
  instructionsElement.id = instructionsId;
245
- instructionsElement.className = classes.srOnly;
172
+ instructionsElement.className = 'sr-only';
246
173
  instructionsElement.textContent = 'This field supports both keypad and keyboard input. Use the keyboard to access and interact with the on-screen math keypad, which accepts LaTeX markup. Use the down arrow key to open the keypad and navigate its buttons. Use the escape key to close the keypad and return to the input field.';
247
174
  parent.insertBefore(instructionsElement, elem);
248
175
  }
249
-
250
176
  elem.setAttribute('aria-describedby', instructionsId);
251
177
  }
252
178
  });
253
179
  }
254
180
  });
255
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "focusFirstKeypadElement", function () {
256
- setTimeout(function () {
257
- var keypadElement = document.querySelector('[data-keypad]');
258
-
181
+ (0, _defineProperty2.default)(this, "focusFirstKeypadElement", () => {
182
+ setTimeout(() => {
183
+ const keypadElement = document.querySelector('[data-keypad]');
259
184
  if (keypadElement) {
260
- var firstButton = keypadElement.querySelector("button, [role='button']");
261
-
185
+ const firstButton = keypadElement.querySelector("button, [role='button']");
262
186
  if (firstButton) {
263
187
  firstButton.focus();
264
188
  }
265
189
  }
266
190
  }, 0);
267
191
  });
268
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleKeyDown", function (event, id) {
269
- var _this$mqStatic$inputR, _this$mqStatic$inputR2, _document$activeEleme;
270
-
271
- var isTrigerredFromActualPieElement = isChildOfCurrentPieElement(event.target, _this.root);
272
- var isAnswerInputFocused = _this.mqStatic && (_this$mqStatic$inputR = _this.mqStatic.inputRef) !== null && _this$mqStatic$inputR !== void 0 && _this$mqStatic$inputR.current ? (_this$mqStatic$inputR2 = _this.mqStatic.inputRef) === null || _this$mqStatic$inputR2 === void 0 ? void 0 : _this$mqStatic$inputR2.current.contains(document.activeElement) : ((_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.getAttribute('aria-label')) === 'Enter answer.';
273
- var key = event.key,
274
- type = event.type;
275
- var isClickOrTouchEvent = type === 'click' || type === 'touchstart';
276
-
192
+ (0, _defineProperty2.default)(this, "handleKeyDown", (event, id) => {
193
+ const isTrigerredFromActualPieElement = isChildOfCurrentPieElement(event.target, this.root);
194
+ const isAnswerInputFocused = this.mqStatic && this.mqStatic.inputRef?.current ? this.mqStatic.inputRef?.current.contains(document.activeElement) : document.activeElement?.getAttribute('aria-label') === 'Enter answer.';
195
+ const {
196
+ key,
197
+ type
198
+ } = event;
199
+ const isClickOrTouchEvent = type === 'click' || type === 'touchstart';
277
200
  if (isAnswerInputFocused && (key === 'ArrowDown' || isClickOrTouchEvent)) {
278
- if (_this.state.activeAnswerBlock !== id && isTrigerredFromActualPieElement) {
279
- _this.cleanupKeyDownListener();
280
-
281
- _this.setState({
201
+ if (this.state.activeAnswerBlock !== id && isTrigerredFromActualPieElement) {
202
+ this.cleanupKeyDownListener();
203
+ this.setState({
282
204
  activeAnswerBlock: id
283
- }, function () {
284
- _this.onSubFieldFocus(id);
285
-
205
+ }, () => {
206
+ this.onSubFieldFocus(id);
286
207
  if (key === 'ArrowDown') {
287
- _this.focusFirstKeypadElement();
208
+ this.focusFirstKeypadElement();
288
209
  }
289
210
  });
290
211
  }
291
212
  } else if (event.key === 'Escape') {
292
- _this.setState({
213
+ this.setState({
293
214
  activeAnswerBlock: ''
294
215
  });
295
216
  }
296
217
  });
297
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSubFieldFocus", function (id) {
298
- if (!_this.handleEvent) {
299
- _this.handleEvent = function (event) {
300
- _this.handleKeyDown(event, id);
218
+ (0, _defineProperty2.default)(this, "onSubFieldFocus", id => {
219
+ if (!this.handleEvent) {
220
+ this.handleEvent = event => {
221
+ this.handleKeyDown(event, id);
301
222
  };
302
-
303
- document.addEventListener('keydown', _this.handleEvent);
304
- document.addEventListener('click', _this.handleEvent);
305
- document.addEventListener('touchstart', _this.handleEvent);
223
+ document.addEventListener('keydown', this.handleEvent);
224
+ document.addEventListener('click', this.handleEvent);
225
+ document.addEventListener('touchstart', this.handleEvent);
306
226
  }
307
227
  });
308
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "cleanupKeyDownListener", function () {
309
- if (_this.handleEvent) {
310
- document.removeEventListener('keydown', _this.handleEvent);
311
- document.removeEventListener('click', _this.handleEvent);
312
- document.removeEventListener('touchstart', _this.handleEvent);
313
- _this.handleEvent = null;
228
+ (0, _defineProperty2.default)(this, "cleanupKeyDownListener", () => {
229
+ if (this.handleEvent) {
230
+ document.removeEventListener('keydown', this.handleEvent);
231
+ document.removeEventListener('click', this.handleEvent);
232
+ document.removeEventListener('touchstart', this.handleEvent);
233
+ this.handleEvent = null;
314
234
  }
315
235
  });
316
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDone", function () {});
317
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSimpleResponseChange", function (response) {
318
- _this.setState(function (state) {
319
- return {
320
- session: _objectSpread(_objectSpread({}, state.session), {}, {
321
- response: response
322
- })
323
- };
324
- }, _this.callOnSessionChange);
236
+ (0, _defineProperty2.default)(this, "onDone", () => {});
237
+ (0, _defineProperty2.default)(this, "onSimpleResponseChange", response => {
238
+ this.setState(state => ({
239
+ session: {
240
+ ...state.session,
241
+ response
242
+ }
243
+ }), this.callOnSessionChange);
325
244
  });
326
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toNodeData", function (data) {
245
+ (0, _defineProperty2.default)(this, "toNodeData", data => {
327
246
  if (!data) {
328
247
  return;
329
248
  }
330
-
331
- var type = data.type,
332
- value = data.value;
333
-
249
+ const {
250
+ type,
251
+ value
252
+ } = data;
334
253
  if (type === 'command' || type === 'cursor') {
335
254
  return data;
336
255
  } else if (type === 'answer') {
337
- return _objectSpread({
338
- type: 'answer'
339
- }, data);
256
+ return {
257
+ type: 'answer',
258
+ ...data
259
+ };
340
260
  } else if (value === 'clear') {
341
261
  return {
342
262
  type: 'clear'
@@ -344,123 +264,114 @@ var Main = /*#__PURE__*/function (_React$Component) {
344
264
  } else {
345
265
  return {
346
266
  type: 'write',
347
- value: value
267
+ value
348
268
  };
349
269
  }
350
270
  });
351
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setInput", function (input) {
352
- _this.input = input;
271
+ (0, _defineProperty2.default)(this, "setInput", input => {
272
+ this.input = input;
353
273
  });
354
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onClick", function (data) {
355
- var c = _this.toNodeData(data);
356
-
274
+ (0, _defineProperty2.default)(this, "onClick", data => {
275
+ const c = this.toNodeData(data);
357
276
  if (c.type === 'clear') {
358
- _this.input.clear();
277
+ this.input.clear();
359
278
  } else if (c.type === 'command') {
360
279
  if (Array.isArray(c.value)) {
361
- c.value.forEach(function (vv) {
362
- _this.input.cmd(vv);
280
+ c.value.forEach(vv => {
281
+ this.input.cmd(vv);
363
282
  });
364
283
  } else {
365
- _this.input.cmd(c.value);
284
+ this.input.cmd(c.value);
366
285
  }
367
286
  } else if (c.type === 'cursor') {
368
- _this.input.keystroke(c.value);
287
+ this.input.keystroke(c.value);
369
288
  } else {
370
- _this.input.write(c.value);
289
+ this.input.write(c.value);
371
290
  }
372
-
373
- _this.input.focus();
291
+ this.input.focus();
374
292
  });
375
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "callOnSessionChange", function () {
376
- var onSessionChange = _this.props.onSessionChange;
377
-
293
+ (0, _defineProperty2.default)(this, "callOnSessionChange", () => {
294
+ const {
295
+ onSessionChange
296
+ } = this.props;
378
297
  if (onSessionChange) {
379
- onSessionChange(_this.state.session);
298
+ onSessionChange(this.state.session);
380
299
  }
381
300
  });
382
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toggleShowCorrect", function (show) {
383
- _this.setState({
301
+ (0, _defineProperty2.default)(this, "toggleShowCorrect", show => {
302
+ this.setState({
384
303
  showCorrect: show
385
- }, _this.handleAnswerBlockDomUpdate);
304
+ }, this.handleAnswerBlockDomUpdate);
386
305
  });
387
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "subFieldChanged", function (name, subfieldValue) {
306
+ (0, _defineProperty2.default)(this, "subFieldChanged", (name, subfieldValue) => {
388
307
  (0, _mathInput.updateSpans)();
389
-
390
308
  if (name) {
391
- _this.setState(function (state) {
392
- return {
393
- session: _objectSpread(_objectSpread({}, state.session), {}, {
394
- completeAnswer: _this.mqStatic && _this.mqStatic.mathField.latex(),
395
- answers: _objectSpread(_objectSpread({}, state.session.answers), {}, (0, _defineProperty2["default"])({}, name, {
309
+ this.setState(state => ({
310
+ session: {
311
+ ...state.session,
312
+ completeAnswer: this.mqStatic && this.mqStatic.mathField.latex(),
313
+ answers: {
314
+ ...state.session.answers,
315
+ [name]: {
396
316
  value: subfieldValue
397
- }))
398
- })
399
- };
400
- }, _this.callOnSessionChange);
317
+ }
318
+ }
319
+ }
320
+ }), this.callOnSessionChange);
401
321
  }
402
322
  });
403
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getFieldName", function (changeField, fields) {
404
- var answers = _this.state.session.answers;
405
-
323
+ (0, _defineProperty2.default)(this, "getFieldName", (changeField, fields) => {
324
+ const {
325
+ answers
326
+ } = this.state.session;
406
327
  if (Object.keys(answers || {}).length) {
407
- var keys = Object.keys(answers);
408
- return keys.find(function (k) {
409
- var tf = fields[k];
328
+ const keys = Object.keys(answers);
329
+ return keys.find(k => {
330
+ const tf = fields[k];
410
331
  return tf && tf.id == changeField.id;
411
332
  });
412
333
  }
413
334
  });
414
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onBlur", function (e) {
415
- var _ref3 = e || {},
416
- relatedTarget = _ref3.relatedTarget,
417
- currentTarget = _ref3.currentTarget; // our keypad is in tooltip
418
- // in this way we see if event was triggered from the keypad
419
-
420
-
421
- var isKeypadOpen = currentTarget && currentTarget.closest('[role=tooltip]');
335
+ (0, _defineProperty2.default)(this, "onBlur", e => {
336
+ const {
337
+ relatedTarget,
338
+ currentTarget
339
+ } = e || {};
422
340
 
423
- function getParentWithRoleTooltip(element) {
424
- var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
341
+ // our keypad is in tooltip
342
+ // in this way we see if event was triggered from the keypad
343
+ const isKeypadOpen = currentTarget && currentTarget.closest('[role=tooltip]');
344
+ function getParentWithRoleTooltip(element, depth = 0) {
425
345
  // only run this max 16 times
426
346
  if (!element || depth >= 16) return null;
427
- var parent = element.offsetParent;
347
+ const parent = element.offsetParent;
428
348
  if (!parent) return null;
429
-
430
349
  if (parent.getAttribute('role') === 'tooltip') {
431
350
  return parent;
432
351
  }
433
-
434
352
  return getParentWithRoleTooltip(parent, depth + 1);
435
353
  }
436
-
437
- function getDeepChildDataKeypad(element) {
438
- var _element$children;
439
-
440
- var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
354
+ function getDeepChildDataKeypad(element, depth = 0) {
441
355
  // only run this max 4 times
442
356
  if (!element || depth >= 4) return null;
443
- var child = element === null || element === void 0 ? void 0 : (_element$children = element.children) === null || _element$children === void 0 ? void 0 : _element$children[0];
357
+ const child = element?.children?.[0];
444
358
  if (!child) return null;
445
-
446
359
  if (child.attributes && child.attributes['data-keypad']) {
447
360
  return child;
448
361
  }
449
-
450
362
  return getDeepChildDataKeypad(child, depth + 1);
451
363
  }
452
-
453
- var parentWithTooltipRole = getParentWithRoleTooltip(relatedTarget);
454
- var childWithDataKeypad = parentWithTooltipRole ? getDeepChildDataKeypad(parentWithTooltipRole) : null;
455
-
456
- if (!relatedTarget || !currentTarget || !(childWithDataKeypad !== null && childWithDataKeypad !== void 0 && childWithDataKeypad.attributes['data-keypad'])) {
364
+ const parentWithTooltipRole = getParentWithRoleTooltip(relatedTarget);
365
+ const childWithDataKeypad = parentWithTooltipRole ? getDeepChildDataKeypad(parentWithTooltipRole) : null;
366
+ if (!relatedTarget || !currentTarget || !childWithDataKeypad?.attributes['data-keypad']) {
457
367
  // if event was trigered from the keypad, avoid closing the keypad
458
368
  if (!isKeypadOpen) {
459
- _this.setState({
369
+ this.setState({
460
370
  activeAnswerBlock: ''
461
371
  });
462
372
  }
463
- } // else {
373
+ }
374
+ // else {
464
375
  // // Just for debugging purpose:
465
376
  // console.log('\n\nNew childWithDataKeypad', childWithDataKeypad);
466
377
  //
@@ -472,655 +383,637 @@ var Main = /*#__PURE__*/function (_React$Component) {
472
383
  // console.log('What was being used', relatedTarget?.offsetParent?.children[0]);
473
384
  // }
474
385
  // }
475
-
476
386
  });
477
- var _model = props.model,
478
- _session = props.session;
479
-
480
- var _answers = parseAnswers(_session, _model);
481
-
482
- _this.state = {
483
- session: _objectSpread(_objectSpread({}, props.session), {}, {
387
+ const {
388
+ model: _model,
389
+ session: _session
390
+ } = props;
391
+ const _answers = parseAnswers(_session, _model);
392
+ this.state = {
393
+ session: {
394
+ ...props.session,
484
395
  answers: _answers
485
- }),
396
+ },
486
397
  activeAnswerBlock: '',
487
- showCorrect: _this.props.model.config.alwaysShowCorrect || false,
488
- tooltipContainerRef: /*#__PURE__*/_react["default"].createRef()
398
+ showCorrect: this.props.model.config.alwaysShowCorrect || false,
399
+ tooltipContainerRef: /*#__PURE__*/_react.default.createRef()
489
400
  };
490
- return _this;
491
401
  }
492
-
493
- (0, _createClass2["default"])(Main, [{
494
- key: "UNSAFE_componentWillMount",
495
- value: function UNSAFE_componentWillMount() {
496
- var classes = this.props.classes;
497
-
498
- if (typeof window !== 'undefined') {
499
- var MQ = _mathquill["default"].getInterface(2);
500
-
501
- if (!registered) {
502
- MQ.registerEmbed('answerBlock', function (data) {
503
- return {
504
- 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>"),
505
- text: function text() {
506
- return 'text';
507
- },
508
- latex: function latex() {
509
- return "\\embed{answerBlock}[".concat(data, "]");
510
- }
511
- };
512
- });
513
- registered = true;
514
- }
515
- }
516
- }
517
- }, {
518
- key: "countResponseOccurrences",
519
- value: function countResponseOccurrences(expression) {
520
- var pattern = /\{\{response\}\}/g;
521
- var matches = expression === null || expression === void 0 ? void 0 : expression.match(pattern);
522
- return matches ? matches.length : 0;
523
- }
524
- }, {
525
- key: "UNSAFE_componentWillReceiveProps",
526
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
527
- var _this2 = this;
528
-
529
- var config = this.props.model.config;
530
-
531
- var _ref4 = nextProps.model || {},
532
- _ref4$config = _ref4.config,
533
- nextConfig = _ref4$config === void 0 ? {} : _ref4$config;
534
-
535
- var session = this.props.session;
536
-
537
- var _ref5 = nextProps || {},
538
- _ref5$session = _ref5.session,
539
- nextSession = _ref5$session === void 0 ? {} : _ref5$session; // in case session props changed in parent, we need to catch this and update local state
540
- // example: when env is changing in pieoneer
541
-
542
-
543
- if (session && nextSession && !(0, _isEqual["default"])(session.answers, nextSession.answers)) {
544
- this.setState({
545
- session: _objectSpread(_objectSpread({}, nextSession), {}, {
546
- answers: parseAnswers(nextSession, this.props.model)
547
- })
548
- });
549
- } // check if the note is the default one for prev language and change to the default one for new language
550
- // this check is necessary in order to diferanciate between default and authour defined note
551
- // and only change between languages for default ones
552
-
553
-
554
- if (config.note && config.language && config.language !== nextConfig.language && config.note === translator.t('mathInline.primaryCorrectWithAlternates', {
555
- lng: config.language
556
- })) {
557
- config.note = translator.t('mathInline.primaryCorrectWithAlternates', {
558
- lng: nextConfig.language
559
- });
560
- }
561
-
562
- if (config.env && config.env.mode !== 'evaluate' || nextConfig.env && nextConfig.env.mode !== 'evaluate') {
563
- this.setState(_objectSpread(_objectSpread({}, this.state.session), {}, {
564
- showCorrect: false
565
- }));
566
- }
567
-
568
- if (nextConfig.alwaysShowCorrect) {
569
- this.setState({
570
- showCorrect: true
571
- });
572
- }
573
-
574
- if (this.countResponseOccurrences(config.expression) < this.countResponseOccurrences(nextConfig.expression)) {
575
- setTimeout(function () {
576
- return _this2.updateAria();
577
- }, 100);
578
- }
579
-
580
- if (config && config.responses && config.responses.length !== nextConfig.responses.length || !config && nextConfig && nextConfig.responses || config && nextConfig && config.expression !== nextConfig.expression) {
581
- var newAnswers = {};
582
- var answers = this.state.session.answers;
583
- var answerBlocks = 1; // assume one at least
584
- // build out local state model using responses declared in expression
585
-
586
- (nextConfig.expression || '').replace(REGEX, function () {
587
- newAnswers["r".concat(answerBlocks)] = {
588
- value: answers && answers["r".concat(answerBlocks)] && answers["r".concat(answerBlocks)].value || ''
589
- };
590
- answerBlocks++;
591
- });
592
- this.setState(function (state) {
402
+ UNSAFE_componentWillMount() {
403
+ if (typeof window !== 'undefined') {
404
+ let MQ = _mathquill.default.getInterface(2);
405
+ if (!registered) {
406
+ MQ.registerEmbed('answerBlock', data => {
407
+ const classNames = getBlockClassNames();
593
408
  return {
594
- session: _objectSpread(_objectSpread({}, state.session), {}, {
595
- completeAnswer: _this2.mqStatic && _this2.mqStatic.mathField.latex(),
596
- answers: newAnswers
597
- })
409
+ htmlString: `<div class="${classNames.blockContainer}">
410
+ <div class="${classNames.blockResponse}" id="${data}Index">R</div>
411
+ <div class="${classNames.blockMath}">
412
+ <span id="${data}"></span>
413
+ </div>
414
+ </div>`,
415
+ text: () => 'text',
416
+ latex: () => `\\embed{answerBlock}[${data}]`
598
417
  };
599
- }, this.handleAnswerBlockDomUpdate);
418
+ });
419
+ registered = true;
600
420
  }
601
421
  }
602
- }, {
603
- key: "shouldComponentUpdate",
604
- value: function shouldComponentUpdate(nextProps, nextState) {
605
- var sameModel = (0, _isEqual["default"])(this.props.model, nextProps.model);
606
- var sameState = (0, _isEqual["default"])(this.state, nextState);
607
- return !sameModel || !sameState;
422
+ }
423
+ countResponseOccurrences(expression) {
424
+ const pattern = /\{\{response\}\}/g;
425
+ const matches = expression?.match(pattern);
426
+ return matches ? matches.length : 0;
427
+ }
428
+ UNSAFE_componentWillReceiveProps(nextProps) {
429
+ const {
430
+ config
431
+ } = this.props.model;
432
+ const {
433
+ config: nextConfig = {}
434
+ } = nextProps.model || {};
435
+ const {
436
+ session
437
+ } = this.props;
438
+ const {
439
+ session: nextSession = {}
440
+ } = nextProps || {};
441
+
442
+ // in case session props changed in parent, we need to catch this and update local state
443
+ // example: when env is changing in pieoneer
444
+ if (session && nextSession && !(0, _isEqual.default)(session.answers, nextSession.answers)) {
445
+ this.setState({
446
+ session: {
447
+ ...nextSession,
448
+ answers: parseAnswers(nextSession, this.props.model)
449
+ }
450
+ });
608
451
  }
609
- }, {
610
- key: "componentDidMount",
611
- value: function componentDidMount() {
612
- var _this3 = this;
613
452
 
614
- this.handleAnswerBlockDomUpdate();
615
- this.updateAria();
616
- setTimeout(function () {
617
- return (0, _mathRendering.renderMath)(_this3.root);
618
- }, 100);
453
+ // check if the note is the default one for prev language and change to the default one for new language
454
+ // this check is necessary in order to diferanciate between default and authour defined note
455
+ // and only change between languages for default ones
456
+ if (config.note && config.language && config.language !== nextConfig.language && config.note === translator.t('mathInline.primaryCorrectWithAlternates', {
457
+ lng: config.language
458
+ })) {
459
+ config.note = translator.t('mathInline.primaryCorrectWithAlternates', {
460
+ lng: nextConfig.language
461
+ });
619
462
  }
620
- }, {
621
- key: "componentDidUpdate",
622
- value: function componentDidUpdate(prevProps, prevState) {
623
- var _prevProps$model, _prevProps$model$conf, _this$props$model, _this$props$model$con;
624
-
625
- this.handleAnswerBlockDomUpdate();
626
- var prevResponseType = (_prevProps$model = prevProps.model) === null || _prevProps$model === void 0 ? void 0 : (_prevProps$model$conf = _prevProps$model.config) === null || _prevProps$model$conf === void 0 ? void 0 : _prevProps$model$conf.responseType;
627
- var currentResponseType = (_this$props$model = this.props.model) === null || _this$props$model === void 0 ? void 0 : (_this$props$model$con = _this$props$model.config) === null || _this$props$model$con === void 0 ? void 0 : _this$props$model$con.responseType;
628
-
629
- if (prevResponseType !== currentResponseType) {
630
- this.updateAria();
631
- }
463
+ if (config.env && config.env.mode !== 'evaluate' || nextConfig.env && nextConfig.env.mode !== 'evaluate') {
464
+ this.setState({
465
+ ...this.state.session,
466
+ showCorrect: false
467
+ });
632
468
  }
633
- }, {
634
- key: "componentWillUnmount",
635
- value: function componentWillUnmount() {
636
- if (this.cleanupKeyDownListener) {
637
- this.cleanupKeyDownListener();
638
- }
469
+ if (nextConfig.alwaysShowCorrect) {
470
+ this.setState({
471
+ showCorrect: true
472
+ });
639
473
  }
640
- }, {
641
- key: "setTooltipRef",
642
- value: function setTooltipRef(ref) {
643
- // Safari Hack: https://stackoverflow.com/a/42764495/5757635
644
- setTimeout(function () {
645
- if (ref && IS_SAFARI) {
646
- var div = document.querySelector("[role='tooltip']");
647
-
648
- if (div) {
649
- var el = div.firstChild;
650
- el.setAttribute('tabindex', '-1');
651
- }
652
- }
653
- }, 1);
474
+ if (this.countResponseOccurrences(config.expression) < this.countResponseOccurrences(nextConfig.expression)) {
475
+ setTimeout(() => this.updateAria(), 100);
654
476
  }
655
- }, {
656
- key: "render",
657
- value: function render() {
658
- var _this4 = this,
659
- _cx;
660
-
661
- var _this$props2 = this.props,
662
- model = _this$props2.model,
663
- classes = _this$props2.classes;
664
- var _this$state2 = this.state,
665
- activeAnswerBlock = _this$state2.activeAnswerBlock,
666
- showCorrect = _this$state2.showCorrect,
667
- session = _this$state2.session,
668
- tooltipContainerRef = _this$state2.tooltipContainerRef;
669
-
670
- var _ref6 = model || {},
671
- config = _ref6.config,
672
- correctness = _ref6.correctness,
673
- disabled = _ref6.disabled,
674
- extraCSSRules = _ref6.extraCSSRules,
675
- view = _ref6.view,
676
- teacherInstructions = _ref6.teacherInstructions,
677
- rationale = _ref6.rationale,
678
- feedback = _ref6.feedback,
679
- animationsDisabled = _ref6.animationsDisabled,
680
- printMode = _ref6.printMode,
681
- alwaysShowCorrect = _ref6.alwaysShowCorrect,
682
- language = _ref6.language;
683
-
684
- if (!config) {
685
- return null;
686
- }
687
-
688
- var _ref7 = config || {},
689
- showNote = _ref7.showNote,
690
- note = _ref7.note,
691
- prompt = _ref7.prompt,
692
- responses = _ref7.responses,
693
- responseType = _ref7.responseType,
694
- equationEditor = _ref7.equationEditor,
695
- customKeys = _ref7.customKeys,
696
- id = _ref7.id,
697
- _ref7$env = _ref7.env;
698
-
699
- _ref7$env = _ref7$env === void 0 ? {} : _ref7$env;
700
- var mode = _ref7$env.mode,
701
- role = _ref7$env.role;
702
- var displayNote = (showCorrect || mode === 'view' && role === 'instructor') && showNote && note;
703
- var emptyResponse = (0, _isEmpty["default"])(responses);
704
- var showCorrectAnswerToggle = !emptyResponse && correctness && correctness.correctness !== 'correct';
705
- var tooltipModeEnabled = disabled && correctness;
706
- var additionalKeys = generateAdditionalKeys(customKeys);
707
- var correct = correctness && correctness.correct;
708
- var staticLatex = prepareForStatic(model, this.state) || '';
709
- var viewMode = disabled && !correctness;
710
- var studentPrintMode = printMode && !alwaysShowCorrect;
711
- var showRationale = rationale && ((0, _renderUi.hasText)(rationale) || (0, _renderUi.hasMedia)(rationale));
712
- var showTeacherInstructions = teacherInstructions && ((0, _renderUi.hasText)(teacherInstructions) || (0, _renderUi.hasMedia)(teacherInstructions));
713
-
714
- var printView = /*#__PURE__*/_react["default"].createElement("div", {
715
- className: classes.printContainer
716
- }, /*#__PURE__*/_react["default"].createElement(_mathInput.mq.Static, {
717
- className: classes["static"],
718
- ref: function ref(mqStatic) {
719
- if (mqStatic) _this4.mqStatic = mqStatic;
720
- },
721
- latex: staticLatex,
722
- onSubFieldChange: this.subFieldChanged,
723
- getFieldName: this.getFieldName,
724
- setInput: this.setInput,
725
- onSubFieldFocus: this.onSubFieldFocus,
726
- onBlur: this.onBlur
727
- }));
728
-
729
- var midContent = /*#__PURE__*/_react["default"].createElement("div", {
730
- className: classes.main
731
- }, mode === 'gather' && /*#__PURE__*/_react["default"].createElement("h2", {
732
- className: classes.srOnly
733
- }, "Math Equation Response Question"), viewMode && showTeacherInstructions && (!animationsDisabled ? /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
734
- className: classes.collapsible,
735
- labels: {
736
- hidden: 'Show Teacher Instructions',
737
- visible: 'Hide Teacher Instructions'
738
- }
739
- }, /*#__PURE__*/_react["default"].createElement("div", {
740
- dangerouslySetInnerHTML: {
741
- __html: teacherInstructions
477
+ if (config && config.responses && config.responses.length !== nextConfig.responses.length || !config && nextConfig && nextConfig.responses || config && nextConfig && config.expression !== nextConfig.expression) {
478
+ const newAnswers = {};
479
+ const answers = this.state.session.answers;
480
+ let answerBlocks = 1; // assume one at least
481
+
482
+ // build out local state model using responses declared in expression
483
+ (nextConfig.expression || '').replace(REGEX, () => {
484
+ newAnswers[`r${answerBlocks}`] = {
485
+ value: answers && answers[`r${answerBlocks}`] && answers[`r${answerBlocks}`].value || ''
486
+ };
487
+ answerBlocks++;
488
+ });
489
+ this.setState(state => ({
490
+ session: {
491
+ ...state.session,
492
+ completeAnswer: this.mqStatic && this.mqStatic.mathField.latex(),
493
+ answers: newAnswers
742
494
  }
743
- })) : /*#__PURE__*/_react["default"].createElement("div", {
744
- dangerouslySetInnerHTML: {
745
- __html: teacherInstructions
495
+ }), this.handleAnswerBlockDomUpdate);
496
+ }
497
+ }
498
+ shouldComponentUpdate(nextProps, nextState) {
499
+ const sameModel = (0, _isEqual.default)(this.props.model, nextProps.model);
500
+ const sameState = (0, _isEqual.default)(this.state, nextState);
501
+ return !sameModel || !sameState;
502
+ }
503
+ componentDidMount() {
504
+ this.handleAnswerBlockDomUpdate();
505
+ this.updateAria();
506
+ setTimeout(() => (0, _mathRendering.renderMath)(this.root), 100);
507
+ }
508
+ componentDidUpdate(prevProps, prevState) {
509
+ this.handleAnswerBlockDomUpdate();
510
+ const prevResponseType = prevProps.model?.config?.responseType;
511
+ const currentResponseType = this.props.model?.config?.responseType;
512
+ if (prevResponseType !== currentResponseType) {
513
+ this.updateAria();
514
+ }
515
+ }
516
+ componentWillUnmount() {
517
+ if (this.cleanupKeyDownListener) {
518
+ this.cleanupKeyDownListener();
519
+ }
520
+ }
521
+ setTooltipRef(ref) {
522
+ // Safari Hack: https://stackoverflow.com/a/42764495/5757635
523
+ setTimeout(() => {
524
+ if (ref && IS_SAFARI) {
525
+ const div = document.querySelector("[role='tooltip']");
526
+ if (div) {
527
+ const el = div.firstChild;
528
+ el.setAttribute('tabindex', '-1');
746
529
  }
747
- })), prompt && /*#__PURE__*/_react["default"].createElement("div", {
748
- className: classes.promptContainer
749
- }, /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
750
- prompt: prompt
751
- })), studentPrintMode ? printView : /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
752
- "false": true
753
- }, /*#__PURE__*/_react["default"].createElement("div", {
754
- className: classes.inputAndKeypadContainer,
755
- tabIndex: 0
756
- }, responseType === _utils.ResponseTypes.simple && /*#__PURE__*/_react["default"].createElement(_simpleQuestionBlock["default"], {
757
- onSimpleResponseChange: this.onSimpleResponseChange,
758
- showCorrect: showCorrect,
759
- emptyResponse: emptyResponse,
760
- model: model,
761
- session: session,
762
- onSubFieldFocus: this.onSubFieldFocus,
763
- showKeypad: !!activeAnswerBlock
764
- }), responseType === _utils.ResponseTypes.advanced && /*#__PURE__*/_react["default"].createElement("div", {
765
- ref: tooltipContainerRef,
766
- 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))
767
- }, /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
768
- ref: function ref(_ref8) {
769
- return _this4.setTooltipRef(_ref8);
770
- },
771
- enterTouchDelay: 0,
772
- interactive: true,
773
- open: !!activeAnswerBlock,
774
- classes: {
775
- tooltip: classes.keypadTooltip,
776
- popper: classes.keypadTooltipPopper
777
- },
778
- PopperProps: {
779
- container: (tooltipContainerRef === null || tooltipContainerRef === void 0 ? void 0 : tooltipContainerRef.current) || undefined,
530
+ }
531
+ }, 1);
532
+ }
533
+ render() {
534
+ const {
535
+ model
536
+ } = this.props;
537
+ const {
538
+ activeAnswerBlock,
539
+ showCorrect,
540
+ session,
541
+ tooltipContainerRef
542
+ } = this.state;
543
+ const {
544
+ config,
545
+ correctness,
546
+ disabled,
547
+ extraCSSRules,
548
+ view,
549
+ teacherInstructions,
550
+ rationale,
551
+ feedback,
552
+ animationsDisabled,
553
+ printMode,
554
+ alwaysShowCorrect,
555
+ language
556
+ } = model || {};
557
+ if (!config) {
558
+ return null;
559
+ }
560
+ const {
561
+ showNote,
562
+ note,
563
+ prompt,
564
+ responses,
565
+ responseType,
566
+ equationEditor,
567
+ customKeys,
568
+ id,
569
+ env: {
570
+ mode,
571
+ role
572
+ } = {}
573
+ } = config || {};
574
+ const displayNote = (showCorrect || mode === 'view' && role === 'instructor') && showNote && note;
575
+ const emptyResponse = (0, _isEmpty.default)(responses);
576
+ const showCorrectAnswerToggle = !emptyResponse && correctness && correctness.correctness !== 'correct';
577
+ const tooltipModeEnabled = disabled && correctness;
578
+ const additionalKeys = generateAdditionalKeys(customKeys);
579
+ const correct = correctness && correctness.correct;
580
+ const staticLatex = prepareForStatic(model, this.state) || '';
581
+ const viewMode = disabled && !correctness;
582
+ const studentPrintMode = printMode && !alwaysShowCorrect;
583
+ const showRationale = rationale && ((0, _renderUi.hasText)(rationale) || (0, _renderUi.hasMedia)(rationale));
584
+ const showTeacherInstructions = teacherInstructions && ((0, _renderUi.hasText)(teacherInstructions) || (0, _renderUi.hasMedia)(teacherInstructions));
585
+ const printView = /*#__PURE__*/_react.default.createElement(PrintContainer, null, /*#__PURE__*/_react.default.createElement(_mathInput.mq.Static, {
586
+ className: "static-math",
587
+ ref: mqStatic => {
588
+ if (mqStatic) this.mqStatic = mqStatic;
589
+ },
590
+ latex: staticLatex,
591
+ onSubFieldChange: this.subFieldChanged,
592
+ getFieldName: this.getFieldName,
593
+ setInput: this.setInput,
594
+ onSubFieldFocus: this.onSubFieldFocus,
595
+ onBlur: this.onBlur
596
+ }));
597
+ const midContent = /*#__PURE__*/_react.default.createElement(MainContent, null, mode === 'gather' && /*#__PURE__*/_react.default.createElement(SrOnly, null, "Math Equation Response Question"), viewMode && showTeacherInstructions && (!animationsDisabled ? /*#__PURE__*/_react.default.createElement(StyledCollapsible, {
598
+ labels: {
599
+ hidden: 'Show Teacher Instructions',
600
+ visible: 'Hide Teacher Instructions'
601
+ }
602
+ }, /*#__PURE__*/_react.default.createElement("div", {
603
+ dangerouslySetInnerHTML: {
604
+ __html: teacherInstructions
605
+ }
606
+ })) : /*#__PURE__*/_react.default.createElement("div", {
607
+ dangerouslySetInnerHTML: {
608
+ __html: teacherInstructions
609
+ }
610
+ })), prompt && /*#__PURE__*/_react.default.createElement(PromptContainer, null, /*#__PURE__*/_react.default.createElement(_renderUi.PreviewPrompt, {
611
+ prompt: prompt
612
+ })), studentPrintMode ? printView : /*#__PURE__*/_react.default.createElement(_renderUi.Readable, {
613
+ false: true
614
+ }, /*#__PURE__*/_react.default.createElement(InputAndKeypadContainer, {
615
+ tabIndex: 0
616
+ }, responseType === _utils.ResponseTypes.simple && /*#__PURE__*/_react.default.createElement(_simpleQuestionBlock.default, {
617
+ onSimpleResponseChange: this.onSimpleResponseChange,
618
+ showCorrect: showCorrect,
619
+ emptyResponse: emptyResponse,
620
+ model: model,
621
+ session: session,
622
+ onSubFieldFocus: this.onSubFieldFocus,
623
+ showKeypad: !!activeAnswerBlock
624
+ }), responseType === _utils.ResponseTypes.advanced && /*#__PURE__*/_react.default.createElement(Expression, {
625
+ ref: tooltipContainerRef,
626
+ isIncorrect: !emptyResponse && !correct && !showCorrect,
627
+ isCorrect: !emptyResponse && (correct || showCorrect),
628
+ showCorrectness: !emptyResponse && disabled && correctness && !view,
629
+ correctAnswerShown: showCorrect,
630
+ printCorrect: printMode && alwaysShowCorrect
631
+ }, /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
632
+ ref: ref => this.setTooltipRef(ref),
633
+ enterTouchDelay: 0,
634
+ interactive: true,
635
+ open: !!activeAnswerBlock,
636
+ slotProps: {
637
+ popper: {
638
+ container: tooltipContainerRef?.current || undefined,
780
639
  placement: 'bottom-start',
781
- modifiers: {
782
- preventOverflow: {
783
- enabled: true,
784
- boundariesElement: 'body'
785
- },
786
- flip: {
787
- enabled: false
640
+ sx: {
641
+ backgroundColor: 'transparent',
642
+ width: '650px',
643
+ opacity: 1,
644
+ '& .MuiTooltip-arrow': {
645
+ display: 'none'
788
646
  }
789
- }
790
- },
791
- title: Object.keys(session.answers).map(function (answerId) {
792
- return answerId === activeAnswerBlock && !(showCorrect || disabled) && /*#__PURE__*/_react["default"].createElement("div", {
793
- "data-keypad": true,
794
- key: answerId,
795
- className: classes.responseContainer,
796
- style: {
797
- // marginTop: this.mqStatic && this.mqStatic.input.offsetHeight - 20,
798
- width: getKeyPadWidth(additionalKeys, equationEditor)
799
- }
800
- }, /*#__PURE__*/_react["default"].createElement(_mathInput.HorizontalKeypad, {
801
- additionalKeys: additionalKeys,
802
- mode: equationEditor || DEFAULT_KEYPAD_VARIANT,
803
- onClick: _this4.onClick
804
- })) || null;
805
- })
806
- }, /*#__PURE__*/_react["default"].createElement(_mathInput.mq.Static, {
807
- className: classes["static"],
808
- ref: function ref(mqStatic) {
809
- if (mqStatic) _this4.mqStatic = mqStatic;
810
- },
811
- latex: staticLatex,
812
- onSubFieldChange: this.subFieldChanged,
813
- getFieldName: this.getFieldName,
814
- setInput: this.setInput,
815
- onSubFieldFocus: this.onSubFieldFocus,
816
- onBlur: this.onBlur
817
- }))))), viewMode && displayNote && /*#__PURE__*/_react["default"].createElement("div", {
818
- className: classes.note,
819
- dangerouslySetInnerHTML: {
820
- __html: "<strong>Note:</strong> ".concat(note)
821
- }
822
- }), viewMode && showRationale && (!animationsDisabled ? /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
823
- labels: {
824
- hidden: 'Show Rationale',
825
- visible: 'Hide Rationale'
826
- }
827
- }, /*#__PURE__*/_react["default"].createElement("div", {
828
- dangerouslySetInnerHTML: {
829
- __html: rationale
830
- }
831
- })) : /*#__PURE__*/_react["default"].createElement("div", {
832
- dangerouslySetInnerHTML: {
833
- __html: rationale
834
- }
835
- })));
836
-
837
- if (tooltipModeEnabled && (showCorrectAnswerToggle || showTeacherInstructions || showRationale || feedback)) {
838
- return /*#__PURE__*/_react["default"].createElement(_renderUi.UiLayout, {
839
- extraCSSRules: extraCSSRules
840
- }, /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
841
- interactive: true,
842
- enterTouchDelay: 0,
843
- classes: {
844
- tooltip: classes.tooltip,
845
- popper: classes.tooltipPopper
846
647
  },
847
- title: /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
848
- className: classes.main
849
- }, showCorrectAnswerToggle && /*#__PURE__*/_react["default"].createElement(_correctAnswerToggle["default"], {
850
- language: language,
851
- className: classes.toggle,
852
- show: true,
853
- toggled: showCorrect,
854
- onToggle: this.toggleShowCorrect
855
- })), showTeacherInstructions && /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
856
- className: classes.collapsible,
857
- key: "collapsible-teacher-instructions",
858
- labels: {
859
- hidden: 'Show Teacher Instructions',
860
- visible: 'Hide Teacher Instructions'
648
+ modifiers: [{
649
+ name: 'offset',
650
+ options: {
651
+ offset: [0, 8]
861
652
  }
862
- }, /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
863
- prompt: teacherInstructions
864
- })), displayNote && (0, _renderUi.hasText)(note) && /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
865
- className: classes.collapsible,
866
- key: "collapsible-note",
867
- labels: {
868
- hidden: translator.t('common:showNote', {
869
- lng: language
870
- }),
871
- visible: translator.t('common:hideNote', {
872
- lng: language
873
- })
653
+ }, {
654
+ name: 'preventOverflow',
655
+ enabled: true,
656
+ options: {
657
+ boundary: 'viewport',
658
+ padding: 8
874
659
  }
875
- }, /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
876
- prompt: note
877
- })), showRationale && /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
878
- className: classes.collapsible,
879
- key: "collapsible-rationale",
880
- labels: {
881
- hidden: 'Show Rationale',
882
- visible: 'Hide Rationale'
660
+ }, {
661
+ name: 'computeStyles',
662
+ options: {
663
+ adaptive: true,
664
+ gpuAcceleration: true
883
665
  }
884
- }, /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
885
- prompt: rationale
886
- })), feedback && /*#__PURE__*/_react["default"].createElement(_renderUi.Feedback, {
887
- correctness: correctness.correctness,
888
- feedback: feedback
889
- }))
890
- }, /*#__PURE__*/_react["default"].createElement("div", {
891
- className: classes.mainContainer,
892
- ref: function ref(r) {
893
- return _this4.root = r || _this4.root;
666
+ }, {
667
+ name: 'flip',
668
+ enabled: false
669
+ }]
670
+ },
671
+ tooltip: {
672
+ sx: {
673
+ fontSize: 'initial',
674
+ backgroundColor: 'transparent',
675
+ width: '600px',
676
+ marginTop: 0,
677
+ paddingTop: 0,
678
+ boxShadow: 'none'
894
679
  }
895
- }, midContent)));
896
- }
897
-
898
- return /*#__PURE__*/_react["default"].createElement(_renderUi.UiLayout, {
899
- id: id,
900
- extraCSSRules: extraCSSRules,
901
- className: classes.mainContainer,
902
- ref: function ref(r) {
903
- // eslint-disable-next-line react/no-find-dom-node
904
- var domNode = _reactDom["default"].findDOMNode(r);
905
-
906
- _this4.root = domNode || _this4.root;
907
680
  }
908
- }, midContent);
681
+ },
682
+ title: Object.keys(session.answers).map(answerId => answerId === activeAnswerBlock && !(showCorrect || disabled) && /*#__PURE__*/_react.default.createElement(ResponseContainer, {
683
+ "data-keypad": true,
684
+ key: answerId,
685
+ style: {
686
+ // marginTop: this.mqStatic && this.mqStatic.input.offsetHeight - 20,
687
+ width: getKeyPadWidth(additionalKeys, equationEditor)
688
+ }
689
+ }, /*#__PURE__*/_react.default.createElement(_mathInput.HorizontalKeypad, {
690
+ additionalKeys: additionalKeys,
691
+ mode: equationEditor || DEFAULT_KEYPAD_VARIANT,
692
+ onClick: this.onClick
693
+ })) || null)
694
+ }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_mathInput.mq.Static, {
695
+ className: "static-math",
696
+ ref: mqStatic => {
697
+ if (mqStatic) this.mqStatic = mqStatic;
698
+ },
699
+ latex: staticLatex,
700
+ onSubFieldChange: this.subFieldChanged,
701
+ getFieldName: this.getFieldName,
702
+ setInput: this.setInput,
703
+ onSubFieldFocus: this.onSubFieldFocus,
704
+ onBlur: this.onBlur
705
+ })))))), viewMode && displayNote && /*#__PURE__*/_react.default.createElement(Note, {
706
+ dangerouslySetInnerHTML: {
707
+ __html: `<strong>Note:</strong> ${note}`
708
+ }
709
+ }), viewMode && showRationale && (!animationsDisabled ? /*#__PURE__*/_react.default.createElement(_renderUi.Collapsible, {
710
+ labels: {
711
+ hidden: 'Show Rationale',
712
+ visible: 'Hide Rationale'
713
+ }
714
+ }, /*#__PURE__*/_react.default.createElement("div", {
715
+ dangerouslySetInnerHTML: {
716
+ __html: rationale
717
+ }
718
+ })) : /*#__PURE__*/_react.default.createElement("div", {
719
+ dangerouslySetInnerHTML: {
720
+ __html: rationale
721
+ }
722
+ })));
723
+ if (tooltipModeEnabled && (showCorrectAnswerToggle || showTeacherInstructions || showRationale || feedback)) {
724
+ return /*#__PURE__*/_react.default.createElement(_renderUi.UiLayout, {
725
+ extraCSSRules: extraCSSRules
726
+ }, /*#__PURE__*/_react.default.createElement(StyledTooltip, {
727
+ interactive: true,
728
+ enterTouchDelay: 0,
729
+ placement: "bottom-start",
730
+ slotProps: {
731
+ tooltip: {
732
+ sx: theme => ({
733
+ background: `${_renderUi.color.primaryLight()} !important`,
734
+ color: _renderUi.color.text(),
735
+ padding: theme.spacing(2),
736
+ border: `1px solid ${_renderUi.color.secondary()}`,
737
+ fontSize: '16px',
738
+ '& :not(.MathJax) > table tr': {
739
+ '&:nth-child(2n)': {
740
+ backgroundColor: 'unset !important'
741
+ }
742
+ }
743
+ })
744
+ },
745
+ popper: {
746
+ sx: {
747
+ opacity: 1
748
+ },
749
+ modifiers: [{
750
+ name: 'offset',
751
+ options: {
752
+ offset: [0, 2]
753
+ }
754
+ }]
755
+ }
756
+ },
757
+ title: /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(MainContent, null, showCorrectAnswerToggle && /*#__PURE__*/_react.default.createElement(StyledCorrectAnswerToggle, {
758
+ language: language,
759
+ show: true,
760
+ toggled: showCorrect,
761
+ onToggle: this.toggleShowCorrect
762
+ })), showTeacherInstructions && /*#__PURE__*/_react.default.createElement(StyledCollapsible, {
763
+ key: "collapsible-teacher-instructions",
764
+ labels: {
765
+ hidden: 'Show Teacher Instructions',
766
+ visible: 'Hide Teacher Instructions'
767
+ }
768
+ }, /*#__PURE__*/_react.default.createElement(_renderUi.PreviewPrompt, {
769
+ prompt: teacherInstructions
770
+ })), displayNote && (0, _renderUi.hasText)(note) && /*#__PURE__*/_react.default.createElement(StyledCollapsible, {
771
+ key: "collapsible-note",
772
+ labels: {
773
+ hidden: translator.t('common:showNote', {
774
+ lng: language
775
+ }),
776
+ visible: translator.t('common:hideNote', {
777
+ lng: language
778
+ })
779
+ }
780
+ }, /*#__PURE__*/_react.default.createElement(_renderUi.PreviewPrompt, {
781
+ prompt: note
782
+ })), showRationale && /*#__PURE__*/_react.default.createElement(StyledCollapsible, {
783
+ key: "collapsible-rationale",
784
+ labels: {
785
+ hidden: 'Show Rationale',
786
+ visible: 'Hide Rationale'
787
+ }
788
+ }, /*#__PURE__*/_react.default.createElement(_renderUi.PreviewPrompt, {
789
+ prompt: rationale
790
+ })), feedback && /*#__PURE__*/_react.default.createElement(_renderUi.Feedback, {
791
+ correctness: correctness.correctness,
792
+ feedback: feedback
793
+ }))
794
+ }, /*#__PURE__*/_react.default.createElement(MainContainer, {
795
+ ref: r => this.root = r || this.root
796
+ }, midContent)));
909
797
  }
910
- }]);
911
- return Main;
912
- }(_react["default"].Component);
798
+ return /*#__PURE__*/_react.default.createElement(_renderUi.UiLayout, {
799
+ id: id,
800
+ extraCSSRules: extraCSSRules,
801
+ ref: r => {
802
+ // eslint-disable-next-line react/no-find-dom-node
803
+ const domNode = _reactDom.default.findDOMNode(r);
804
+ this.root = domNode || this.root;
805
+ }
806
+ }, /*#__PURE__*/_react.default.createElement(MainContainer, null, midContent));
807
+ }
808
+ }
913
809
 
810
+ // Helper function to get class names for HTML string generation
914
811
  exports.Main = Main;
915
- (0, _defineProperty2["default"])(Main, "propTypes", {
916
- classes: _propTypes["default"].object,
917
- session: _propTypes["default"].object.isRequired,
918
- onSessionChange: _propTypes["default"].func,
919
- model: _propTypes["default"].object.isRequired
812
+ (0, _defineProperty2.default)(Main, "propTypes", {
813
+ session: _propTypes.default.object.isRequired,
814
+ onSessionChange: _propTypes.default.func,
815
+ model: _propTypes.default.object.isRequired
920
816
  });
921
-
922
- var styles = function styles(theme) {
817
+ const getBlockClassNames = () => {
923
818
  return {
924
- mainContainer: {
925
- color: _renderUi.color.text(),
926
- backgroundColor: _renderUi.color.background(),
927
- display: 'inline-block'
928
- },
929
- tooltip: {
930
- background: "".concat(_renderUi.color.primaryLight(), " !important"),
931
- color: _renderUi.color.text(),
932
- padding: theme.spacing.unit * 2,
933
- border: "1px solid ".concat(_renderUi.color.secondary()),
934
- fontSize: '16px',
935
- '& :not(.MathJax) > table tr': {
936
- '&:nth-child(2n)': {
937
- backgroundColor: 'unset !important'
938
- }
819
+ blockContainer: 'block-container',
820
+ blockResponse: 'block-response',
821
+ blockMath: 'block-math'
822
+ };
823
+ };
824
+
825
+ // CSS for block classes used in HTML string generation
826
+ if (typeof document !== 'undefined') {
827
+ const styleId = 'math-inline-block-styles';
828
+ if (!document.getElementById(styleId)) {
829
+ const style = document.createElement('style');
830
+ style.id = styleId;
831
+ style.textContent = `
832
+ .block-container {
833
+ margin: 8px !important;
834
+ display: inline-flex;
835
+ border: 2px solid grey !important;
939
836
  }
940
- },
941
- tooltipPopper: {
942
- opacity: 1
943
- },
944
- keypadTooltip: {
945
- fontSize: 'initial',
946
- background: 'transparent',
947
- width: '600px',
948
- marginTop: 0,
949
- paddingTop: 0
950
- },
951
- keypadTooltipPopper: {
952
- background: 'transparent',
953
- width: '650px',
954
- opacity: 1
955
- },
956
- promptContainer: {
957
- marginBottom: theme.spacing.unit * 2
958
- },
959
- main: {
960
- width: '100%',
961
- position: 'relative',
962
- backgroundColor: _renderUi.color.background(),
963
- color: _renderUi.color.text()
964
- },
965
- title: {
966
- fontSize: '1.1rem',
967
- display: 'block',
968
- marginTop: theme.spacing.unit * 2,
969
- marginBottom: theme.spacing.unit
970
- },
971
- note: {
972
- paddingBottom: theme.spacing.unit * 2
973
- },
974
- collapsible: {
975
- marginBottom: theme.spacing.unit * 2
976
- },
977
- responseContainer: {
978
- zIndex: 10,
979
- // position: 'absolute',
980
- // right: 0,
981
- minWidth: '400px',
982
- marginTop: theme.spacing.unit * 2
983
- },
984
- expression: {
985
- maxWidth: 'fit-content',
986
- padding: theme.spacing.unit / 4,
987
- '& > .mq-math-mode': {
988
- '& > .mq-root-block': {
989
- // PD-4803 unset padding as events are not correctly propagated in the proximity of math input
990
- paddingRight: '0 !important',
991
- paddingLeft: '0 !important',
992
- '& > .mq-editable-field': {
993
- minWidth: '10px',
994
- padding: theme.spacing.unit / 4
995
- }
996
- },
997
- '& sup': {
998
- top: 0
999
- }
837
+ .block-response {
838
+ color: grey;
839
+ background: #f5f5f5;
840
+ font-size: 0.8rem !important;
841
+ padding: 4px !important;
842
+ display: flex;
843
+ align-items: center;
844
+ justify-content: center;
845
+ border-right: 2px solid #bdbdbd !important;
846
+ flex-shrink: 0;
847
+ flex-grow: 0;
848
+ flex-basis: auto;
1000
849
  }
1001
- },
1002
- "static": {
850
+ .block-math {
851
+ color: ${_renderUi.color.text()};
852
+ background-color: ${_renderUi.color.background()};
853
+ padding: 4px !important;
854
+ display: flex;
855
+ align-items: center;
856
+ justify-content: center;
857
+ flex-grow: 1;
858
+ }
859
+ .block-math > .mq-math-mode > .mq-hasCursor > .mq-cursor {
860
+ display: none;
861
+ }
862
+ .sr-only {
863
+ position: absolute;
864
+ left: -10000px;
865
+ top: auto;
866
+ width: 1px;
867
+ height: 1px;
868
+ overflow: hidden;
869
+ }
870
+ .static-math > .mq-root-block > .mq-editable-field {
871
+ border-color: ${_renderUi.color.text()};
872
+ }
873
+ `;
874
+ document.head.appendChild(style);
875
+ }
876
+ }
877
+ const MainContainer = (0, _styles.styled)('div')({
878
+ color: _renderUi.color.text(),
879
+ backgroundColor: _renderUi.color.background(),
880
+ display: 'inline-block'
881
+ });
882
+ const StyledTooltip = (0, _styles.styled)(_Tooltip.default)({
883
+ // Styles applied via slotProps.sx below
884
+ });
885
+ const PromptContainer = (0, _styles.styled)('div')(({
886
+ theme
887
+ }) => ({
888
+ marginBottom: theme.spacing(2)
889
+ }));
890
+ const MainContent = (0, _styles.styled)('div')({
891
+ width: '100%',
892
+ position: 'relative',
893
+ backgroundColor: _renderUi.color.background(),
894
+ color: _renderUi.color.text()
895
+ });
896
+ const Note = (0, _styles.styled)('div')(({
897
+ theme
898
+ }) => ({
899
+ paddingBottom: theme.spacing(2)
900
+ }));
901
+ const StyledCollapsible = (0, _styles.styled)(_renderUi.Collapsible)(({
902
+ theme
903
+ }) => ({
904
+ marginBottom: theme.spacing(2)
905
+ }));
906
+ const ResponseContainer = (0, _styles.styled)('div')(({
907
+ theme
908
+ }) => ({
909
+ zIndex: 10,
910
+ minWidth: '400px',
911
+ marginTop: theme.spacing(2)
912
+ }));
913
+ const Expression = (0, _styles.styled)('div', {
914
+ shouldForwardProp: prop => !['isIncorrect', 'isCorrect', 'showCorrectness', 'correctAnswerShown', 'printCorrect'].includes(prop)
915
+ })(({
916
+ theme,
917
+ isIncorrect,
918
+ isCorrect,
919
+ showCorrectness,
920
+ correctAnswerShown,
921
+ printCorrect
922
+ }) => {
923
+ const borderColor = isIncorrect ? _renderUi.color.incorrect() : isCorrect ? _renderUi.color.correct() : undefined;
924
+ return {
925
+ maxWidth: 'fit-content',
926
+ padding: theme.spacing(0.25),
927
+ ...(showCorrectness && {
928
+ border: borderColor ? `2px solid ${borderColor} !important` : '2px solid'
929
+ }),
930
+ ...(!showCorrectness && borderColor && {
931
+ borderColor: `${borderColor} !important`
932
+ }),
933
+ ...(correctAnswerShown && {
934
+ padding: theme.spacing(1),
935
+ letterSpacing: '0.5px'
936
+ }),
937
+ ...(printCorrect && {
938
+ border: `2px solid ${_renderUi.color.correct()} !important`
939
+ }),
940
+ '& > .mq-math-mode': {
1003
941
  '& > .mq-root-block': {
942
+ paddingRight: '0 !important',
943
+ paddingLeft: '0 !important',
1004
944
  '& > .mq-editable-field': {
1005
- borderColor: _renderUi.color.text()
1006
- }
1007
- }
1008
- },
1009
- inputAndKeypadContainer: {
1010
- position: 'relative',
1011
- '& .mq-overarrow-inner': {
1012
- border: 'none !important',
1013
- padding: '0 !important'
1014
- },
1015
- '& .mq-overarrow-inner-right': {
1016
- display: 'none !important'
1017
- },
1018
- '& .mq-overarrow-inner-left': {
1019
- display: 'none !important'
1020
- },
1021
- '& .mq-overarrow.mq-arrow-both': {
1022
- minWidth: '1.23em',
1023
- '& *': {
1024
- lineHeight: '1 !important'
1025
- },
1026
- '&:before': {
1027
- top: '-0.4em',
1028
- left: '-1px'
1029
- },
1030
- '&:after': {
1031
- top: '-2.4em',
1032
- right: '-1px'
1033
- },
1034
- '&.mq-empty:after': {
1035
- top: '-0.45em'
945
+ minWidth: '10px',
946
+ padding: theme.spacing(0.25)
1036
947
  }
1037
948
  },
1038
- '& .mq-overarrow.mq-arrow-right': {
1039
- '&:before': {
1040
- top: '-0.4em',
1041
- right: '-1px'
1042
- }
1043
- },
1044
- '& .mq-longdiv-inner': {
1045
- borderTop: '1px solid !important',
1046
- paddingTop: '1.5px !important'
1047
- },
1048
- '& .mq-parallelogram': {
1049
- lineHeight: 0.85
949
+ '& sup': {
950
+ top: 0
1050
951
  }
952
+ }
953
+ };
954
+ });
955
+ const InputAndKeypadContainer = (0, _styles.styled)('div')({
956
+ position: 'relative',
957
+ '& .mq-overarrow-inner': {
958
+ border: 'none !important',
959
+ padding: '0 !important'
960
+ },
961
+ '& .mq-overarrow-inner-right': {
962
+ display: 'none !important'
963
+ },
964
+ '& .mq-overarrow-inner-left': {
965
+ display: 'none !important'
966
+ },
967
+ '& .mq-overarrow.mq-arrow-both': {
968
+ minWidth: '1.23em',
969
+ '& *': {
970
+ lineHeight: '1 !important'
1051
971
  },
1052
- showCorrectness: {
1053
- border: '2px solid'
1054
- },
1055
- correctAnswerShown: {
1056
- padding: theme.spacing.unit,
1057
- letterSpacing: '0.5px'
1058
- },
1059
- printCorrect: {
1060
- border: "2px solid ".concat(_renderUi.color.correct(), " !important")
1061
- },
1062
- correct: {
1063
- borderColor: "".concat(_renderUi.color.correct(), " !important")
1064
- },
1065
- incorrect: {
1066
- borderColor: "".concat(_renderUi.color.incorrect(), " !important")
1067
- },
1068
- blockContainer: {
1069
- margin: "".concat(theme.spacing.unit, "px !important"),
1070
- display: 'inline-flex',
1071
- border: '2px solid grey !important'
1072
- },
1073
- blockResponse: {
1074
- color: 'grey',
1075
- background: theme.palette.grey['A100'],
1076
- fontSize: '0.8rem !important',
1077
- padding: "".concat(theme.spacing.unit / 2, "px !important"),
1078
- display: 'flex',
1079
- alignItems: 'center',
1080
- justifyContent: 'center',
1081
- borderRight: "2px solid ".concat(_renderUi.color.disabled(), " !important"),
1082
- flexShrink: 0,
1083
- flexGrow: 0,
1084
- flexBasis: 'auto' // take only the space needed for content + padding
1085
-
1086
- },
1087
- toggle: {
1088
- color: _renderUi.color.text(),
1089
- marginBottom: theme.spacing.unit * 2
1090
- },
1091
- blockMath: {
1092
- color: _renderUi.color.text(),
1093
- backgroundColor: _renderUi.color.background(),
1094
- padding: "".concat(theme.spacing.unit / 2, "px !important"),
1095
- display: 'flex',
1096
- alignItems: 'center',
1097
- justifyContent: 'center',
1098
- flexGrow: 1,
1099
- // take all the remaining space
1100
- '& > .mq-math-mode': {
1101
- '& > .mq-hasCursor': {
1102
- '& > .mq-cursor': {
1103
- display: 'none'
1104
- }
1105
- }
1106
- }
972
+ '&:before': {
973
+ top: '-0.4em',
974
+ left: '-1px'
1107
975
  },
1108
- printContainer: {
1109
- marginBottom: theme.spacing.unit,
1110
- pointerEvents: 'none'
976
+ '&:after': {
977
+ top: '-2.4em',
978
+ right: '-1px'
1111
979
  },
1112
- srOnly: {
1113
- position: 'absolute',
1114
- left: '-10000px',
1115
- top: 'auto',
1116
- width: '1px',
1117
- height: '1px',
1118
- overflow: 'hidden'
980
+ '&.mq-empty:after': {
981
+ top: '-0.45em'
1119
982
  }
1120
- };
1121
- };
1122
-
1123
- var _default = (0, _styles.withStyles)(styles)(Main);
1124
-
1125
- exports["default"] = _default;
983
+ },
984
+ '& .mq-overarrow.mq-arrow-right': {
985
+ '&:before': {
986
+ top: '-0.4em',
987
+ right: '-1px'
988
+ }
989
+ },
990
+ '& .mq-longdiv-inner': {
991
+ borderTop: '1px solid !important',
992
+ paddingTop: '1.5px !important'
993
+ },
994
+ '& .mq-parallelogram': {
995
+ lineHeight: 0.85
996
+ }
997
+ });
998
+ const PrintContainer = (0, _styles.styled)('div')(({
999
+ theme
1000
+ }) => ({
1001
+ marginBottom: theme.spacing(1),
1002
+ pointerEvents: 'none'
1003
+ }));
1004
+ const SrOnly = (0, _styles.styled)('h2')({
1005
+ position: 'absolute',
1006
+ left: '-10000px',
1007
+ top: 'auto',
1008
+ width: '1px',
1009
+ height: '1px',
1010
+ overflow: 'hidden'
1011
+ });
1012
+ const StyledCorrectAnswerToggle = (0, _styles.styled)(_correctAnswerToggle.default)(({
1013
+ theme
1014
+ }) => ({
1015
+ color: _renderUi.color.text(),
1016
+ marginBottom: theme.spacing(2)
1017
+ }));
1018
+ var _default = exports.default = Main;
1126
1019
  //# sourceMappingURL=main.js.map