@pie-element/math-inline 5.9.0 → 5.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1212 @@
1
+ import {_dll_react, _dll_classnames, _dll_material_ui__core_styles, _dll_prop_types, _dll_pie_lib__render_ui, _dll_pie_lib__correct_answer_toggle, _dll_material_ui__core, _dll_lodash, _dll_react_dom, _dll_debug} from "../../../@pie-lib/shared-module@^1.4.1/module/index.js";
2
+ import {_dll_pie_lib__math_toolbar, _dll_pie_lib__math_input, _dll_pie_framework__mathquill} from "../../../@pie-lib/math-edit-module@^1.1.22/module/index.js";
3
+ import {_dll_pie_lib__math_rendering} from "../../../@pie-lib/math-rendering-module@^1.0.26/module/index.js";
4
+ const ResponseTypes$1 = {
5
+ advanced: 'Advanced Multi',
6
+ simple: 'Simple'
7
+ };
8
+ const React$2 = _dll_react;
9
+ const cx$1 = _dll_classnames;
10
+ const {withStyles: withStyles$1} = _dll_material_ui__core_styles;
11
+ const PropTypes$1 = _dll_prop_types;
12
+ const {color: color$1} = _dll_pie_lib__render_ui;
13
+ const {MathToolbar: MathToolbar} = _dll_pie_lib__math_toolbar;
14
+ const {mq: mq$1} = _dll_pie_lib__math_input;
15
+ const _jsxFileName$1 = "/home/circleci/repo/packages/math-inline/src/simple-question-block.jsx";
16
+ class SimpleQuestionBlockRaw extends React$2.Component {
17
+ constructor(...args) {
18
+ super(...args);
19
+ SimpleQuestionBlockRaw.prototype.__init.call(this);
20
+ SimpleQuestionBlockRaw.prototype.__init2.call(this);
21
+ SimpleQuestionBlockRaw.prototype.__init3.call(this);
22
+ }
23
+ static __initStatic() {
24
+ this.propTypes = {
25
+ classes: PropTypes$1.object,
26
+ onSimpleResponseChange: PropTypes$1.func,
27
+ model: PropTypes$1.object.isRequired,
28
+ emptyResponse: PropTypes$1.bool,
29
+ session: PropTypes$1.object.isRequired,
30
+ showCorrect: PropTypes$1.bool
31
+ };
32
+ }
33
+ __init() {
34
+ this.state = {
35
+ showKeypad: true
36
+ };
37
+ }
38
+ __init2() {
39
+ this.onFocus = () => this.setState({
40
+ showKeypad: true
41
+ });
42
+ }
43
+ __init3() {
44
+ this.onBlur = e => {
45
+ const {relatedTarget, currentTarget} = e || ({});
46
+ if (!relatedTarget || !currentTarget || relatedTarget.offsetParent !== currentTarget.offsetParent) {
47
+ this.setState({
48
+ showKeypad: false
49
+ });
50
+ }
51
+ };
52
+ }
53
+ render() {
54
+ const {classes, model, showCorrect, session, emptyResponse, onSimpleResponseChange} = this.props;
55
+ const {config, disabled, correctness, view} = model || ({});
56
+ if (!config) {
57
+ return;
58
+ }
59
+ const correct = correctness && correctness.correct;
60
+ const {responses, equationEditor} = config;
61
+ return React$2.createElement('div', {
62
+ className: classes.expression,
63
+ __self: this,
64
+ __source: {
65
+ fileName: _jsxFileName$1,
66
+ lineNumber: 54
67
+ }
68
+ }, showCorrect || disabled ? React$2.createElement('div', {
69
+ className: cx$1(classes.static, {
70
+ [classes.incorrect]: !emptyResponse && !correct && !showCorrect,
71
+ [classes.correct]: !emptyResponse && (correct || showCorrect)
72
+ }),
73
+ __self: this,
74
+ __source: {
75
+ fileName: _jsxFileName$1,
76
+ lineNumber: 56
77
+ }
78
+ }, React$2.createElement(mq$1.Static, {
79
+ latex: showCorrect ? responses && responses.length && responses[0].answer : session.response || '',
80
+ __self: this,
81
+ __source: {
82
+ fileName: _jsxFileName$1,
83
+ lineNumber: 62
84
+ }
85
+ })) : React$2.createElement(MathToolbar, {
86
+ classNames: {
87
+ editor: classes.responseEditor
88
+ },
89
+ latex: session.response || '',
90
+ keypadMode: equationEditor,
91
+ onChange: onSimpleResponseChange,
92
+ onDone: () => {},
93
+ onFocus: this.onFocus,
94
+ onBlur: this.onBlur,
95
+ controlledKeypad: true,
96
+ showKeypad: this.state.showKeypad,
97
+ hideDoneButton: true,
98
+ __self: this,
99
+ __source: {
100
+ fileName: _jsxFileName$1,
101
+ lineNumber: 69
102
+ }
103
+ }));
104
+ }
105
+ }
106
+ SimpleQuestionBlockRaw.__initStatic();
107
+ const SimpleQuestionBlock = withStyles$1(theme => ({
108
+ responseEditor: {
109
+ display: 'flex',
110
+ justifyContent: 'center',
111
+ width: 'auto',
112
+ maxWidth: 'fit-content',
113
+ height: 'auto',
114
+ textAlign: 'left',
115
+ padding: theme.spacing.unit,
116
+ '&.mq-math-mode': {
117
+ border: `1px solid ${color$1.primaryLight()}`
118
+ }
119
+ },
120
+ expression: {
121
+ marginTop: theme.spacing.unit * 2,
122
+ marginBottom: theme.spacing.unit * 2,
123
+ padding: theme.spacing.unit
124
+ },
125
+ static: {
126
+ color: color$1.text(),
127
+ background: color$1.background(),
128
+ border: `1px solid ${color$1.primaryLight()}`,
129
+ width: 'fit-content',
130
+ fontSize: '1rem',
131
+ padding: theme.spacing.unit / 2,
132
+ '& > .mq-math-mode': {
133
+ '& > .mq-hasCursor': {
134
+ '& > .mq-cursor': {
135
+ display: 'none'
136
+ }
137
+ }
138
+ }
139
+ },
140
+ correct: {
141
+ border: `2px solid ${color$1.correct()} !important`,
142
+ padding: theme.spacing.unit,
143
+ letterSpacing: '0.5px'
144
+ },
145
+ incorrect: {
146
+ border: `2px solid ${color$1.incorrect()} !important`,
147
+ padding: theme.spacing.unit,
148
+ letterSpacing: '0.5px'
149
+ }
150
+ }))(SimpleQuestionBlockRaw);
151
+ const React$1 = _dll_react;
152
+ const PropTypes = _dll_prop_types;
153
+ const CorrectAnswerToggle = _dll_pie_lib__correct_answer_toggle;
154
+ const {Feedback: Feedback} = _dll_pie_lib__render_ui;
155
+ const {Collapsible: Collapsible} = _dll_pie_lib__render_ui;
156
+ const {Readable: Readable} = _dll_pie_lib__render_ui;
157
+ const {hasText: hasText} = _dll_pie_lib__render_ui;
158
+ const {PreviewPrompt: PreviewPrompt} = _dll_pie_lib__render_ui;
159
+ const {color: color} = _dll_pie_lib__render_ui;
160
+ const {withStyles: withStyles} = _dll_material_ui__core_styles;
161
+ const {Tooltip: Tooltip} = _dll_material_ui__core;
162
+ const {isEqual: isEqual} = _dll_lodash;
163
+ const {isEmpty: isEmpty} = _dll_lodash;
164
+ const cx = _dll_classnames;
165
+ const {mq: mq} = _dll_pie_lib__math_input;
166
+ const {HorizontalKeypad: HorizontalKeypad} = _dll_pie_lib__math_input;
167
+ const {updateSpans: updateSpans} = _dll_pie_lib__math_input;
168
+ const MathQuill = _dll_pie_framework__mathquill;
169
+ const {renderMath: renderMath} = _dll_pie_lib__math_rendering;
170
+ const _jsxFileName = "/home/circleci/repo/packages/math-inline/src/main.jsx";
171
+ function _optionalChain(ops) {
172
+ let lastAccessLHS = undefined;
173
+ let value = ops[0];
174
+ let i = 1;
175
+ while (i < ops.length) {
176
+ const op = ops[i];
177
+ const fn = ops[i + 1];
178
+ i += 2;
179
+ if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
180
+ return undefined;
181
+ }
182
+ if (op === 'access' || op === 'optionalAccess') {
183
+ lastAccessLHS = value;
184
+ value = fn(value);
185
+ } else if (op === 'call' || op === 'optionalCall') {
186
+ value = fn((...args) => value.call(lastAccessLHS, ...args));
187
+ lastAccessLHS = undefined;
188
+ }
189
+ }
190
+ return value;
191
+ }
192
+ let registered = false;
193
+ const NEWLINE_LATEX = /\\newline/g;
194
+ const REGEX = /{{response}}/gm;
195
+ const DEFAULT_KEYPAD_VARIANT = 6;
196
+ const IS_SAFARI = (/^((?!chrome|android).)*safari/i).test(navigator.userAgent);
197
+ function generateAdditionalKeys(keyData = []) {
198
+ return keyData.map(key => ({
199
+ name: key,
200
+ latex: key,
201
+ write: key,
202
+ label: key
203
+ }));
204
+ }
205
+ function getKeyPadWidth(additionalKeys = [], equationEditor) {
206
+ return Math.floor(additionalKeys.length / 5) * 30 + (equationEditor === 'miscellaneous' ? 600 : 500);
207
+ }
208
+ function prepareForStatic(model, state) {
209
+ const {config, disabled} = model || ({});
210
+ const {expression, responses, printMode, alwaysShowCorrect} = config || ({});
211
+ if (config && expression) {
212
+ const modelExpression = expression;
213
+ if (state.showCorrect) {
214
+ return responses && responses.length && responses[0].answer;
215
+ }
216
+ let answerBlocks = 1;
217
+ return (modelExpression || '').replace(REGEX, function () {
218
+ const answer = state.session.answers[`r${answerBlocks}`];
219
+ if (printMode && !alwaysShowCorrect) {
220
+ const blankSpace = ('\\ \\ ').repeat(30) + '\\newline ';
221
+ return `\\MathQuillMathField[r${answerBlocks++}]{${blankSpace.repeat(3)}}`;
222
+ }
223
+ if (disabled) {
224
+ return `\\embed{answerBlock}[r${answerBlocks++}]`;
225
+ }
226
+ return `\\MathQuillMathField[r${answerBlocks++}]{${answer && answer.value || ''}}`;
227
+ }).replace(NEWLINE_LATEX, '\\embed{newLine}[]');
228
+ }
229
+ }
230
+ class Main extends React$1.Component {
231
+ static __initStatic() {
232
+ this.propTypes = {
233
+ classes: PropTypes.object,
234
+ session: PropTypes.object.isRequired,
235
+ onSessionChange: PropTypes.func,
236
+ model: PropTypes.object.isRequired
237
+ };
238
+ }
239
+ constructor(props) {
240
+ super(props);
241
+ Main.prototype.__init.call(this);
242
+ Main.prototype.__init2.call(this);
243
+ Main.prototype.__init3.call(this);
244
+ Main.prototype.__init4.call(this);
245
+ Main.prototype.__init5.call(this);
246
+ Main.prototype.__init6.call(this);
247
+ Main.prototype.__init7.call(this);
248
+ Main.prototype.__init8.call(this);
249
+ Main.prototype.__init9.call(this);
250
+ Main.prototype.__init10.call(this);
251
+ Main.prototype.__init11.call(this);
252
+ Main.prototype.__init12.call(this);
253
+ const answers = {};
254
+ if (props.model.config && props.model.config.expression) {
255
+ let answerBlocks = 1;
256
+ (props.model.config.expression || '').replace(REGEX, () => {
257
+ answers[`r${answerBlocks}`] = {
258
+ value: props.session && props.session.answers && props.session.answers[`r${answerBlocks}`] && props.session.answers[`r${answerBlocks}`].value || ''
259
+ };
260
+ answerBlocks += 1;
261
+ });
262
+ }
263
+ this.state = {
264
+ session: {
265
+ ...props.session,
266
+ answers
267
+ },
268
+ activeAnswerBlock: '',
269
+ showCorrect: this.props.model.config.alwaysShowCorrect || false
270
+ };
271
+ }
272
+ UNSAFE_componentWillMount() {
273
+ const {classes} = this.props;
274
+ if (typeof window !== 'undefined') {
275
+ let MQ = MathQuill.getInterface(2);
276
+ if (!registered) {
277
+ MQ.registerEmbed('answerBlock', data => {
278
+ return {
279
+ htmlString: `<div class="${classes.blockContainer}">
280
+ <div class="${classes.blockResponse}" id="${data}Index">R</div>
281
+ <div class="${classes.blockMath}">
282
+ <span id="${data}"></span>
283
+ </div>
284
+ </div>`,
285
+ text: () => 'text',
286
+ latex: () => `\\embed{answerBlock}[${data}]`
287
+ };
288
+ });
289
+ registered = true;
290
+ }
291
+ }
292
+ }
293
+ __init() {
294
+ this.handleAnswerBlockDomUpdate = () => {
295
+ const {model, classes} = this.props;
296
+ const {session, showCorrect} = this.state;
297
+ const answers = session.answers;
298
+ if (this.root && model.disabled && !showCorrect) {
299
+ Object.keys(answers).forEach(answerId => {
300
+ const el = this.root.querySelector(`#${answerId}`);
301
+ const indexEl = this.root.querySelector(`#${answerId}Index`);
302
+ if (el) {
303
+ let MQ = MathQuill.getInterface(2);
304
+ const answer = answers[answerId];
305
+ el.textContent = answer && answer.value || '';
306
+ if (!model.view) ; else {
307
+ el.parentElement.parentElement.classList.remove(classes.correct);
308
+ el.parentElement.parentElement.classList.remove(classes.incorrect);
309
+ }
310
+ MQ.StaticMath(el);
311
+ indexEl.textContent = 'R';
312
+ }
313
+ });
314
+ }
315
+ renderMath(this.root);
316
+ };
317
+ }
318
+ componentDidUpdate() {
319
+ this.handleAnswerBlockDomUpdate();
320
+ }
321
+ UNSAFE_componentWillReceiveProps(nextProps) {
322
+ const {config} = this.props.model;
323
+ const {config: nextConfig = {}} = nextProps.model || ({});
324
+ if (config.env && config.env.mode !== 'evaluate' || nextConfig.env && nextConfig.env.mode !== 'evaluate') {
325
+ this.setState({
326
+ ...this.state.session,
327
+ showCorrect: false
328
+ });
329
+ }
330
+ if (nextConfig.alwaysShowCorrect) {
331
+ this.setState({
332
+ showCorrect: true
333
+ });
334
+ }
335
+ if (config && config.responses && config.responses.length !== nextConfig.responses.length || !config && nextConfig && nextConfig.responses || config && nextConfig && config.expression !== nextConfig.expression) {
336
+ const newAnswers = {};
337
+ const answers = this.state.session.answers;
338
+ let answerBlocks = 1;
339
+ (nextConfig.expression || '').replace(REGEX, () => {
340
+ newAnswers[`r${answerBlocks}`] = {
341
+ value: answers && answers[`r${answerBlocks}`] && answers[`r${answerBlocks}`].value || ''
342
+ };
343
+ answerBlocks++;
344
+ });
345
+ this.setState(state => ({
346
+ session: {
347
+ ...state.session,
348
+ completeAnswer: this.mqStatic && this.mqStatic.mathField.latex(),
349
+ answers: newAnswers
350
+ }
351
+ }), this.handleAnswerBlockDomUpdate);
352
+ }
353
+ }
354
+ shouldComponentUpdate(nextProps, nextState) {
355
+ const sameModel = isEqual(this.props.model, nextProps.model);
356
+ const sameState = isEqual(this.state, nextState);
357
+ return !sameModel || !sameState;
358
+ }
359
+ componentDidMount() {
360
+ this.handleAnswerBlockDomUpdate();
361
+ setTimeout(() => renderMath(this.root), 100);
362
+ }
363
+ __init2() {
364
+ this.onDone = () => {};
365
+ }
366
+ __init3() {
367
+ this.onSimpleResponseChange = response => {
368
+ this.setState(state => ({
369
+ session: {
370
+ ...state.session,
371
+ response
372
+ }
373
+ }), this.callOnSessionChange);
374
+ };
375
+ }
376
+ __init4() {
377
+ this.onSubFieldFocus = id => {
378
+ this.setState({
379
+ activeAnswerBlock: id
380
+ });
381
+ };
382
+ }
383
+ __init5() {
384
+ this.toNodeData = data => {
385
+ if (!data) {
386
+ return;
387
+ }
388
+ const {type, value} = data;
389
+ if (type === 'command' || type === 'cursor') {
390
+ return data;
391
+ } else if (type === 'answer') {
392
+ return {
393
+ type: 'answer',
394
+ ...data
395
+ };
396
+ } else if (value === 'clear') {
397
+ return {
398
+ type: 'clear'
399
+ };
400
+ } else {
401
+ return {
402
+ type: 'write',
403
+ value
404
+ };
405
+ }
406
+ };
407
+ }
408
+ __init6() {
409
+ this.setInput = input => {
410
+ this.input = input;
411
+ };
412
+ }
413
+ __init7() {
414
+ this.onClick = data => {
415
+ const c = this.toNodeData(data);
416
+ if (c.type === 'clear') {
417
+ this.input.clear();
418
+ } else if (c.type === 'command') {
419
+ if (Array.isArray(c.value)) {
420
+ c.value.forEach(vv => {
421
+ this.input.cmd(vv);
422
+ });
423
+ } else {
424
+ this.input.cmd(c.value);
425
+ }
426
+ } else if (c.type === 'cursor') {
427
+ this.input.keystroke(c.value);
428
+ } else {
429
+ this.input.write(c.value);
430
+ }
431
+ this.input.focus();
432
+ };
433
+ }
434
+ __init8() {
435
+ this.callOnSessionChange = () => {
436
+ const {onSessionChange} = this.props;
437
+ if (onSessionChange) {
438
+ onSessionChange(this.state.session);
439
+ }
440
+ };
441
+ }
442
+ __init9() {
443
+ this.toggleShowCorrect = show => {
444
+ this.setState({
445
+ showCorrect: show
446
+ }, this.handleAnswerBlockDomUpdate);
447
+ };
448
+ }
449
+ __init10() {
450
+ this.subFieldChanged = (name, subfieldValue) => {
451
+ updateSpans();
452
+ if (name) {
453
+ this.setState(state => ({
454
+ session: {
455
+ ...state.session,
456
+ completeAnswer: this.mqStatic && this.mqStatic.mathField.latex(),
457
+ answers: {
458
+ ...state.session.answers,
459
+ [name]: {
460
+ value: subfieldValue
461
+ }
462
+ }
463
+ }
464
+ }), this.callOnSessionChange);
465
+ }
466
+ };
467
+ }
468
+ __init11() {
469
+ this.getFieldName = (changeField, fields) => {
470
+ const {answers} = this.state.session;
471
+ if (Object.keys(answers || ({})).length) {
472
+ const keys = Object.keys(answers);
473
+ return keys.find(k => {
474
+ const tf = fields[k];
475
+ return tf && tf.id == changeField.id;
476
+ });
477
+ }
478
+ };
479
+ }
480
+ __init12() {
481
+ this.onBlur = e => {
482
+ const {relatedTarget, currentTarget} = e || ({});
483
+ if (!relatedTarget || !currentTarget || !IS_SAFARI && !_optionalChain([relatedTarget, 'optionalAccess', _13 => _13.offsetParent, 'optionalAccess', _14 => _14.children, 'access', _15 => _15[0], 'optionalAccess', _16 => _16.attributes, 'optionalAccess', _17 => _17['data-keypad']]) || IS_SAFARI && !_optionalChain([relatedTarget, 'optionalAccess', _18 => _18.offsetParent, 'optionalAccess', _19 => _19.children, 'access', _20 => _20[0], 'optionalAccess', _21 => _21.children, 'access', _22 => _22[0], 'optionalAccess', _23 => _23.attributes, 'optionalAccess', _24 => _24['data-keypad']])) {
484
+ this.setState({
485
+ activeAnswerBlock: ''
486
+ });
487
+ }
488
+ };
489
+ }
490
+ setTooltipRef(ref) {
491
+ setTimeout(() => {
492
+ if (ref && IS_SAFARI) {
493
+ const div = document.querySelector('[role=\'tooltip\']');
494
+ if (div) {
495
+ const el = div.firstChild;
496
+ el.setAttribute('tabindex', '-1');
497
+ }
498
+ }
499
+ }, 1);
500
+ }
501
+ render() {
502
+ const {model, classes} = this.props;
503
+ const {activeAnswerBlock, showCorrect, session} = this.state;
504
+ const {config, correctness, disabled, view, teacherInstructions, rationale, feedback, animationsDisabled, printMode, alwaysShowCorrect} = model || ({});
505
+ if (!config) {
506
+ return null;
507
+ }
508
+ const {showNote, note, prompt, responses, responseType, equationEditor, customKeys, env: {mode, role} = {}} = config || ({});
509
+ const displayNote = (showCorrect || mode === 'view' && role === 'instructor') && showNote && note;
510
+ const emptyResponse = isEmpty(responses);
511
+ const showCorrectAnswerToggle = !emptyResponse && correctness && correctness.correctness !== 'correct';
512
+ const tooltipModeEnabled = disabled && correctness;
513
+ const additionalKeys = generateAdditionalKeys(customKeys);
514
+ const correct = correctness && correctness.correct;
515
+ const staticLatex = prepareForStatic(model, this.state) || '';
516
+ const viewMode = disabled && !correctness;
517
+ const studentPrintMode = printMode && !alwaysShowCorrect;
518
+ const printView = React$1.createElement('div', {
519
+ className: classes.printContainer,
520
+ __self: this,
521
+ __source: {
522
+ fileName: _jsxFileName,
523
+ lineNumber: 411
524
+ }
525
+ }, React$1.createElement(mq.Static, {
526
+ ref: mqStatic => this.mqStatic = mqStatic || this.mqStatic,
527
+ latex: staticLatex,
528
+ onSubFieldChange: this.subFieldChanged,
529
+ getFieldName: this.getFieldName,
530
+ setInput: this.setInput,
531
+ onSubFieldFocus: this.onSubFieldFocus,
532
+ onBlur: this.onBlur,
533
+ __self: this,
534
+ __source: {
535
+ fileName: _jsxFileName,
536
+ lineNumber: 412
537
+ }
538
+ }));
539
+ const midContent = React$1.createElement('div', {
540
+ className: classes.main,
541
+ __self: this,
542
+ __source: {
543
+ fileName: _jsxFileName,
544
+ lineNumber: 424
545
+ }
546
+ }, prompt && React$1.createElement('div', {
547
+ className: classes.content,
548
+ __self: this,
549
+ __source: {
550
+ fileName: _jsxFileName,
551
+ lineNumber: 426
552
+ }
553
+ }, React$1.createElement(PreviewPrompt, {
554
+ prompt: prompt,
555
+ __self: this,
556
+ __source: {
557
+ fileName: _jsxFileName,
558
+ lineNumber: 427
559
+ }
560
+ })), studentPrintMode ? printView : React$1.createElement(Readable, {
561
+ false: true,
562
+ __self: this,
563
+ __source: {
564
+ fileName: _jsxFileName,
565
+ lineNumber: 430
566
+ }
567
+ }, React$1.createElement('div', {
568
+ className: classes.inputAndKeypadContainer,
569
+ __self: this,
570
+ __source: {
571
+ fileName: _jsxFileName,
572
+ lineNumber: 431
573
+ }
574
+ }, responseType === ResponseTypes$1.simple && React$1.createElement(SimpleQuestionBlock, {
575
+ onSimpleResponseChange: this.onSimpleResponseChange,
576
+ showCorrect: showCorrect,
577
+ emptyResponse: emptyResponse,
578
+ model: model,
579
+ session: session,
580
+ __self: this,
581
+ __source: {
582
+ fileName: _jsxFileName,
583
+ lineNumber: 433
584
+ }
585
+ }), responseType === ResponseTypes$1.advanced && React$1.createElement('div', {
586
+ className: cx(classes.expression, {
587
+ [classes.incorrect]: !emptyResponse && !correct && !showCorrect,
588
+ [classes.correct]: !emptyResponse && (correct || showCorrect),
589
+ [classes.showCorrectness]: !emptyResponse && disabled && correctness && !view,
590
+ [classes.correctAnswerShown]: showCorrect,
591
+ [classes.printCorrect]: printMode && alwaysShowCorrect
592
+ }),
593
+ __self: this,
594
+ __source: {
595
+ fileName: _jsxFileName,
596
+ lineNumber: 442
597
+ }
598
+ }, React$1.createElement(Tooltip, {
599
+ ref: ref => this.setTooltipRef(ref),
600
+ interactive: true,
601
+ open: !!activeAnswerBlock,
602
+ classes: {
603
+ tooltip: classes.keypadTooltip,
604
+ popper: classes.keypadTooltipPopper
605
+ },
606
+ title: Object.keys(session.answers).map(answerId => answerId === activeAnswerBlock && !(showCorrect || disabled) && React$1.createElement('div', {
607
+ 'data-keypad': true,
608
+ key: answerId,
609
+ className: classes.responseContainer,
610
+ style: {
611
+ width: getKeyPadWidth(additionalKeys, equationEditor)
612
+ },
613
+ __self: this,
614
+ __source: {
615
+ fileName: _jsxFileName,
616
+ lineNumber: 463
617
+ }
618
+ }, React$1.createElement(HorizontalKeypad, {
619
+ additionalKeys: additionalKeys,
620
+ mode: equationEditor || DEFAULT_KEYPAD_VARIANT,
621
+ onClick: this.onClick,
622
+ __self: this,
623
+ __source: {
624
+ fileName: _jsxFileName,
625
+ lineNumber: 472
626
+ }
627
+ })) || null),
628
+ __self: this,
629
+ __source: {
630
+ fileName: _jsxFileName,
631
+ lineNumber: 451
632
+ }
633
+ }, React$1.createElement(mq.Static, {
634
+ ref: mqStatic => this.mqStatic = mqStatic || this.mqStatic,
635
+ latex: staticLatex,
636
+ onSubFieldChange: this.subFieldChanged,
637
+ getFieldName: this.getFieldName,
638
+ setInput: this.setInput,
639
+ onSubFieldFocus: this.onSubFieldFocus,
640
+ onBlur: this.onBlur,
641
+ __self: this,
642
+ __source: {
643
+ fileName: _jsxFileName,
644
+ lineNumber: 482
645
+ }
646
+ }))))), viewMode && teacherInstructions && hasText(teacherInstructions) && React$1.createElement(React$1.Fragment, {
647
+ __self: this,
648
+ __source: {
649
+ fileName: _jsxFileName,
650
+ lineNumber: 498
651
+ }
652
+ }, !animationsDisabled ? React$1.createElement(Collapsible, {
653
+ labels: {
654
+ hidden: 'Show Teacher Instructions',
655
+ visible: 'Hide Teacher Instructions'
656
+ },
657
+ __self: this,
658
+ __source: {
659
+ fileName: _jsxFileName,
660
+ lineNumber: 499
661
+ }
662
+ }, React$1.createElement('div', {
663
+ dangerouslySetInnerHTML: {
664
+ __html: teacherInstructions
665
+ },
666
+ __self: this,
667
+ __source: {
668
+ fileName: _jsxFileName,
669
+ lineNumber: 502
670
+ }
671
+ })) : React$1.createElement('div', {
672
+ dangerouslySetInnerHTML: {
673
+ __html: teacherInstructions
674
+ },
675
+ __self: this,
676
+ __source: {
677
+ fileName: _jsxFileName,
678
+ lineNumber: 503
679
+ }
680
+ }), React$1.createElement('br', {
681
+ __self: this,
682
+ __source: {
683
+ fileName: _jsxFileName,
684
+ lineNumber: 504
685
+ }
686
+ })), viewMode && rationale && hasText(rationale) && React$1.createElement(React$1.Fragment, {
687
+ __self: this,
688
+ __source: {
689
+ fileName: _jsxFileName,
690
+ lineNumber: 510
691
+ }
692
+ }, !animationsDisabled ? React$1.createElement(Collapsible, {
693
+ labels: {
694
+ hidden: 'Show Rationale',
695
+ visible: 'Hide Rationale'
696
+ },
697
+ __self: this,
698
+ __source: {
699
+ fileName: _jsxFileName,
700
+ lineNumber: 511
701
+ }
702
+ }, React$1.createElement('div', {
703
+ dangerouslySetInnerHTML: {
704
+ __html: rationale
705
+ },
706
+ __self: this,
707
+ __source: {
708
+ fileName: _jsxFileName,
709
+ lineNumber: 514
710
+ }
711
+ })) : React$1.createElement('div', {
712
+ dangerouslySetInnerHTML: {
713
+ __html: rationale
714
+ },
715
+ __self: this,
716
+ __source: {
717
+ fileName: _jsxFileName,
718
+ lineNumber: 515
719
+ }
720
+ })), displayNote && React$1.createElement('div', {
721
+ className: classes.note,
722
+ dangerouslySetInnerHTML: {
723
+ __html: `<strong>Note:</strong> ${note}`
724
+ },
725
+ __self: this,
726
+ __source: {
727
+ fileName: _jsxFileName,
728
+ lineNumber: 520
729
+ }
730
+ }));
731
+ if (tooltipModeEnabled && (showCorrectAnswerToggle || teacherInstructions || rationale || feedback)) {
732
+ return React$1.createElement(Tooltip, {
733
+ interactive: true,
734
+ classes: {
735
+ tooltip: classes.tooltip,
736
+ popper: classes.tooltipPopper
737
+ },
738
+ title: React$1.createElement('div', {
739
+ __self: this,
740
+ __source: {
741
+ fileName: _jsxFileName,
742
+ lineNumber: 537
743
+ }
744
+ }, React$1.createElement('div', {
745
+ className: classes.main,
746
+ __self: this,
747
+ __source: {
748
+ fileName: _jsxFileName,
749
+ lineNumber: 538
750
+ }
751
+ }, showCorrectAnswerToggle && React$1.createElement(CorrectAnswerToggle, {
752
+ className: classes.toggle,
753
+ show: true,
754
+ toggled: showCorrect,
755
+ onToggle: this.toggleShowCorrect,
756
+ __self: this,
757
+ __source: {
758
+ fileName: _jsxFileName,
759
+ lineNumber: 540
760
+ }
761
+ })), teacherInstructions && hasText(teacherInstructions) && [React$1.createElement(Collapsible, {
762
+ key: "collapsible",
763
+ labels: {
764
+ hidden: 'Show Teacher Instructions',
765
+ visible: 'Hide Teacher Instructions'
766
+ },
767
+ className: classes.collapsible,
768
+ __self: this,
769
+ __source: {
770
+ fileName: _jsxFileName,
771
+ lineNumber: 549
772
+ }
773
+ }, React$1.createElement(PreviewPrompt, {
774
+ prompt: teacherInstructions,
775
+ __self: this,
776
+ __source: {
777
+ fileName: _jsxFileName,
778
+ lineNumber: 557
779
+ }
780
+ })), React$1.createElement('br', {
781
+ key: "br",
782
+ __self: this,
783
+ __source: {
784
+ fileName: _jsxFileName,
785
+ lineNumber: 559
786
+ }
787
+ })], rationale && hasText(rationale) && [React$1.createElement(Collapsible, {
788
+ key: "collapsible",
789
+ labels: {
790
+ hidden: 'Show Rationale',
791
+ visible: 'Hide Rationale'
792
+ },
793
+ __self: this,
794
+ __source: {
795
+ fileName: _jsxFileName,
796
+ lineNumber: 562
797
+ }
798
+ }, React$1.createElement(PreviewPrompt, {
799
+ prompt: rationale,
800
+ __self: this,
801
+ __source: {
802
+ fileName: _jsxFileName,
803
+ lineNumber: 569
804
+ }
805
+ })), React$1.createElement('br', {
806
+ key: "br",
807
+ __self: this,
808
+ __source: {
809
+ fileName: _jsxFileName,
810
+ lineNumber: 571
811
+ }
812
+ })], feedback && React$1.createElement(Feedback, {
813
+ correctness: correctness.correctness,
814
+ feedback: feedback,
815
+ __self: this,
816
+ __source: {
817
+ fileName: _jsxFileName,
818
+ lineNumber: 574
819
+ }
820
+ })),
821
+ __self: this,
822
+ __source: {
823
+ fileName: _jsxFileName,
824
+ lineNumber: 530
825
+ }
826
+ }, React$1.createElement('div', {
827
+ className: classes.mainContainer,
828
+ ref: r => this.root = r || this.root,
829
+ __self: this,
830
+ __source: {
831
+ fileName: _jsxFileName,
832
+ lineNumber: 582
833
+ }
834
+ }, midContent));
835
+ }
836
+ return React$1.createElement('div', {
837
+ className: classes.mainContainer,
838
+ ref: r => this.root = r || this.root,
839
+ __self: this,
840
+ __source: {
841
+ fileName: _jsxFileName,
842
+ lineNumber: 592
843
+ }
844
+ }, midContent);
845
+ }
846
+ }
847
+ Main.__initStatic();
848
+ const styles = theme => ({
849
+ mainContainer: {
850
+ display: 'inline-block'
851
+ },
852
+ tooltip: {
853
+ background: `${color.primaryLight()} !important`,
854
+ color: color.text(),
855
+ padding: theme.spacing.unit * 2,
856
+ border: `1px solid ${color.secondary()}`,
857
+ fontSize: '16px',
858
+ '& :not(.MathJax) > table tr': {
859
+ '&:nth-child(2n)': {
860
+ backgroundColor: 'unset !important'
861
+ }
862
+ }
863
+ },
864
+ tooltipPopper: {
865
+ opacity: 1
866
+ },
867
+ keypadTooltip: {
868
+ fontSize: 'initial',
869
+ background: 'transparent',
870
+ width: '600px',
871
+ marginTop: 0,
872
+ paddingTop: 0
873
+ },
874
+ keypadTooltipPopper: {
875
+ background: 'transparent',
876
+ width: '650px',
877
+ opacity: 1
878
+ },
879
+ main: {
880
+ width: '100%',
881
+ position: 'relative',
882
+ padding: theme.spacing.unit / 2,
883
+ backgroundColor: color.background(),
884
+ color: color.text()
885
+ },
886
+ title: {
887
+ fontSize: '1.1rem',
888
+ display: 'block',
889
+ marginTop: theme.spacing.unit * 2,
890
+ marginBottom: theme.spacing.unit
891
+ },
892
+ content: {
893
+ marginTop: theme.spacing.unit * 2
894
+ },
895
+ note: {
896
+ paddingTop: '15px'
897
+ },
898
+ collapsible: {
899
+ marginTop: theme.spacing.unit * 2
900
+ },
901
+ responseContainer: {
902
+ zIndex: 10,
903
+ minWidth: '400px',
904
+ marginTop: theme.spacing.unit * 2
905
+ },
906
+ expression: {
907
+ maxWidth: 'fit-content',
908
+ '& > .mq-math-mode': {
909
+ '& > .mq-root-block': {
910
+ '& > .mq-editable-field': {
911
+ minWidth: '10px',
912
+ margin: theme.spacing.unit * 2 / 3,
913
+ padding: theme.spacing.unit / 4
914
+ }
915
+ },
916
+ '& sup': {
917
+ top: 0
918
+ }
919
+ }
920
+ },
921
+ inputAndKeypadContainer: {
922
+ position: 'relative',
923
+ '& .mq-overarrow-inner': {
924
+ border: 'none !important',
925
+ padding: '0 !important'
926
+ },
927
+ '& .mq-overarrow-inner-right': {
928
+ display: 'none !important'
929
+ },
930
+ '& .mq-overarrow-inner-left': {
931
+ display: 'none !important'
932
+ },
933
+ '& .mq-overarrow.mq-arrow-both': {
934
+ minWidth: '1.23em',
935
+ '& *': {
936
+ lineHeight: '1 !important'
937
+ },
938
+ '&:before': {
939
+ top: '-0.4em',
940
+ left: '-1px'
941
+ },
942
+ '&:after': {
943
+ top: '-2.4em',
944
+ right: '-1px'
945
+ },
946
+ '&.mq-empty:after': {
947
+ top: '-0.45em'
948
+ }
949
+ },
950
+ '& .mq-overarrow.mq-arrow-right': {
951
+ '&:before': {
952
+ top: '-0.4em',
953
+ right: '-1px'
954
+ }
955
+ },
956
+ '& .mq-longdiv-inner': {
957
+ borderTop: '1px solid !important',
958
+ paddingTop: '1.5px !important'
959
+ },
960
+ '& .mq-parallelogram': {
961
+ lineHeight: 0.85
962
+ }
963
+ },
964
+ showCorrectness: {
965
+ border: '2px solid'
966
+ },
967
+ correctAnswerShown: {
968
+ padding: theme.spacing.unit,
969
+ letterSpacing: '0.5px'
970
+ },
971
+ printCorrect: {
972
+ border: `2px solid ${color.correct()} !important`
973
+ },
974
+ correct: {
975
+ borderColor: `${color.correct()} !important`
976
+ },
977
+ incorrect: {
978
+ borderColor: `${color.incorrect()} !important`
979
+ },
980
+ blockContainer: {
981
+ margin: `${theme.spacing.unit}px !important`,
982
+ display: 'inline-flex',
983
+ border: '2px solid grey !important'
984
+ },
985
+ blockResponse: {
986
+ flex: 2,
987
+ color: 'grey',
988
+ background: 'lightgrey',
989
+ fontSize: '0.8rem !important',
990
+ padding: `${theme.spacing.unit / 2}px !important`,
991
+ display: 'flex',
992
+ alignItems: 'center',
993
+ justifyContent: 'center',
994
+ borderRight: `2px solid ${color.disabled()} !important`
995
+ },
996
+ toggle: {
997
+ color: color.text()
998
+ },
999
+ blockMath: {
1000
+ color: color.text(),
1001
+ backgroundColor: color.background(),
1002
+ padding: `${theme.spacing.unit / 2}px !important`,
1003
+ display: 'flex',
1004
+ alignItems: 'center',
1005
+ justifyContent: 'center',
1006
+ flex: 8,
1007
+ '& > .mq-math-mode': {
1008
+ '& > .mq-hasCursor': {
1009
+ '& > .mq-cursor': {
1010
+ display: 'none'
1011
+ }
1012
+ }
1013
+ }
1014
+ },
1015
+ printContainer: {
1016
+ marginBottom: '10px',
1017
+ pointerEvents: 'none'
1018
+ }
1019
+ });
1020
+ var Main$1 = withStyles(styles)(Main);
1021
+ function getDefaultExportFromCjs(x) {
1022
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1023
+ }
1024
+ var lib = {};
1025
+ Object.defineProperty(lib, "__esModule", {
1026
+ value: true
1027
+ });
1028
+ class ModelSetEvent extends CustomEvent {
1029
+ constructor(component, complete, hasModel) {
1030
+ super(ModelSetEvent.TYPE, {
1031
+ bubbles: true,
1032
+ composed: true,
1033
+ detail: {
1034
+ complete,
1035
+ component,
1036
+ hasModel
1037
+ }
1038
+ });
1039
+ this.component = component;
1040
+ this.complete = complete;
1041
+ }
1042
+ }
1043
+ ModelSetEvent.TYPE = 'model-set';
1044
+ var ModelSetEvent_1 = lib.ModelSetEvent = ModelSetEvent;
1045
+ class SessionChangedEvent extends CustomEvent {
1046
+ constructor(component, complete) {
1047
+ super(SessionChangedEvent.TYPE, {
1048
+ bubbles: true,
1049
+ composed: true,
1050
+ detail: {
1051
+ complete,
1052
+ component
1053
+ }
1054
+ });
1055
+ this.component = component;
1056
+ this.complete = complete;
1057
+ }
1058
+ }
1059
+ SessionChangedEvent.TYPE = 'session-changed';
1060
+ var SessionChangedEvent_1 = lib.SessionChangedEvent = SessionChangedEvent;
1061
+ var defaults$1 = {};
1062
+ var utils = {};
1063
+ Object.defineProperty(utils, "__esModule", {
1064
+ value: true
1065
+ });
1066
+ utils.ResponseTypes = void 0;
1067
+ var ResponseTypes = {
1068
+ advanced: 'Advanced Multi',
1069
+ simple: 'Simple'
1070
+ };
1071
+ utils.ResponseTypes = ResponseTypes;
1072
+ (function (exports) {
1073
+ Object.defineProperty(exports, "__esModule", {
1074
+ value: true
1075
+ });
1076
+ exports["default"] = void 0;
1077
+ var _utils = utils;
1078
+ var _default = {
1079
+ model: {
1080
+ partialScoring: true,
1081
+ responseType: _utils.ResponseTypes.advanced,
1082
+ element: 'math-inline',
1083
+ feedback: {
1084
+ correct: {
1085
+ "default": 'Correct',
1086
+ type: 'none'
1087
+ },
1088
+ incorrect: {
1089
+ "default": 'Incorrect',
1090
+ type: 'none'
1091
+ },
1092
+ partial: {
1093
+ "default": 'Nearly',
1094
+ type: 'none'
1095
+ }
1096
+ },
1097
+ equationEditor: '8',
1098
+ expression: '',
1099
+ rationale: 'Rationale goes here.',
1100
+ note: 'The answer shown above is the primary correct answer specified by the author for this item, but other answers may also be recognized as correct.',
1101
+ prompt: '',
1102
+ responses: [],
1103
+ customKeys: [],
1104
+ scoringType: 'auto',
1105
+ feedbackEnabled: true,
1106
+ promptEnabled: true,
1107
+ rationaleEnabled: true,
1108
+ teacherInstructionsEnabled: true,
1109
+ studentInstructionsEnabled: true,
1110
+ toolbarEditorPosition: 'bottom',
1111
+ validationDefault: 'literal',
1112
+ ignoreOrderDefault: false,
1113
+ allowTrailingZerosDefault: false
1114
+ },
1115
+ configuration: {
1116
+ prompt: {
1117
+ settings: true,
1118
+ label: 'Prompt'
1119
+ },
1120
+ feedback: {
1121
+ settings: true,
1122
+ label: 'Feedback'
1123
+ },
1124
+ responseType: {
1125
+ settings: true,
1126
+ label: 'Response type'
1127
+ },
1128
+ rationale: {
1129
+ settings: true,
1130
+ label: 'Rationale'
1131
+ },
1132
+ scoringType: {
1133
+ settings: false,
1134
+ label: 'Scoring Type'
1135
+ },
1136
+ studentInstructions: {
1137
+ settings: false,
1138
+ label: 'Student Instructions'
1139
+ },
1140
+ teacherInstructions: {
1141
+ settings: true,
1142
+ label: 'Teacher Instructions'
1143
+ },
1144
+ partialScoring: {
1145
+ settings: false,
1146
+ label: 'Allow Partial Scoring'
1147
+ },
1148
+ ignoreOrder: {
1149
+ settings: false,
1150
+ label: 'Ignore Order',
1151
+ enabled: true
1152
+ },
1153
+ allowTrailingZeros: {
1154
+ settings: false,
1155
+ label: 'Allow Trailing Zeros',
1156
+ enabled: true
1157
+ }
1158
+ }
1159
+ };
1160
+ exports["default"] = _default;
1161
+ })(defaults$1);
1162
+ var defaults = getDefaultExportFromCjs(defaults$1);
1163
+ const React = _dll_react;
1164
+ const ReactDOM = _dll_react_dom;
1165
+ const debug = _dll_debug;
1166
+ const _ = _dll_lodash;
1167
+ const log = debug('pie-ui:math-inline');
1168
+ class MathInline extends HTMLElement {
1169
+ constructor() {
1170
+ super();
1171
+ this._configuration = defaults.configuration;
1172
+ this.sessionChangedEventCaller = _.debounce(session => {
1173
+ this.dispatchEvent(new SessionChangedEvent_1(session, true));
1174
+ }, 1000);
1175
+ }
1176
+ set model(m) {
1177
+ this._model = m;
1178
+ this.dispatchEvent(new ModelSetEvent_1(this._model, true, !!this._model));
1179
+ this._render();
1180
+ }
1181
+ set session(s) {
1182
+ this._session = s;
1183
+ this._render();
1184
+ }
1185
+ set configuration(c) {
1186
+ this._configuration = c;
1187
+ this._render();
1188
+ }
1189
+ sessionChanged(s) {
1190
+ Object.keys(s).map(key => {
1191
+ this._session[key] = s[key];
1192
+ });
1193
+ this.sessionChangedEventCaller(this._session);
1194
+ log('session: ', this._session);
1195
+ }
1196
+ connectedCallback() {
1197
+ this._render();
1198
+ }
1199
+ _render() {
1200
+ if (!this._model || !this._session) {
1201
+ return;
1202
+ }
1203
+ const el = React.createElement(Main$1, {
1204
+ model: this._model,
1205
+ session: this._session,
1206
+ configuration: this._configuration,
1207
+ onSessionChange: this.sessionChanged.bind(this)
1208
+ });
1209
+ ReactDOM.render(el, this);
1210
+ }
1211
+ }
1212
+ export {Main$1 as Component, MathInline as default};