@pie-element/math-inline 5.6.4-next.571 → 5.6.4-next.576

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,1209 @@
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.2.18/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.17/module/index.js";
3
+ import {_dll_pie_lib__math_rendering} from "../../../@pie-lib/math-rendering-module@^1.0.21/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 showAsCorrect = !emptyResponse && (showCorrect || correct);
61
+ const showAsIncorrect = !emptyResponse && !correct && !showCorrect && !view;
62
+ const {responses, equationEditor} = config;
63
+ return React$2.createElement('div', {
64
+ className: classes.expression,
65
+ __self: this,
66
+ __source: {
67
+ fileName: _jsxFileName$1,
68
+ lineNumber: 54
69
+ }
70
+ }, showCorrect || disabled ? React$2.createElement('div', {
71
+ className: cx$1(classes.static, {
72
+ [classes.correct]: showAsCorrect,
73
+ [classes.incorrect]: showAsIncorrect
74
+ }),
75
+ __self: this,
76
+ __source: {
77
+ fileName: _jsxFileName$1,
78
+ lineNumber: 56
79
+ }
80
+ }, React$2.createElement(mq$1.Static, {
81
+ latex: showCorrect ? responses && responses.length && responses[0].answer : session.response || '',
82
+ __self: this,
83
+ __source: {
84
+ fileName: _jsxFileName$1,
85
+ lineNumber: 62
86
+ }
87
+ })) : React$2.createElement(MathToolbar, {
88
+ classNames: {
89
+ editor: classes.responseEditor
90
+ },
91
+ latex: session.response || '',
92
+ keypadMode: equationEditor,
93
+ onChange: onSimpleResponseChange,
94
+ onDone: () => {},
95
+ onFocus: this.onFocus,
96
+ onBlur: this.onBlur,
97
+ controlledKeypad: true,
98
+ showKeypad: this.state.showKeypad,
99
+ hideDoneButton: true,
100
+ __self: this,
101
+ __source: {
102
+ fileName: _jsxFileName$1,
103
+ lineNumber: 69
104
+ }
105
+ }));
106
+ }
107
+ }
108
+ SimpleQuestionBlockRaw.__initStatic();
109
+ const SimpleQuestionBlock = withStyles$1(theme => ({
110
+ responseEditor: {
111
+ display: 'flex',
112
+ justifyContent: 'center',
113
+ width: 'auto',
114
+ minWidth: '500px',
115
+ maxWidth: '900px',
116
+ height: 'auto',
117
+ textAlign: 'left',
118
+ padding: theme.spacing.unit,
119
+ '&.mq-math-mode': {
120
+ border: `1px solid ${color$1.primaryLight()}`
121
+ }
122
+ },
123
+ expression: {
124
+ marginTop: theme.spacing.unit * 2,
125
+ marginBottom: theme.spacing.unit * 2,
126
+ padding: theme.spacing.unit
127
+ },
128
+ static: {
129
+ color: color$1.text(),
130
+ background: color$1.background(),
131
+ border: `1px solid ${color$1.primaryLight()}`,
132
+ width: '100%',
133
+ fontSize: '1rem',
134
+ padding: theme.spacing.unit / 2,
135
+ '& > .mq-math-mode': {
136
+ '& > .mq-hasCursor': {
137
+ '& > .mq-cursor': {
138
+ display: 'none'
139
+ }
140
+ }
141
+ }
142
+ },
143
+ correct: {
144
+ color: color$1.correct(),
145
+ border: `1px solid ${color$1.correct()} !important`
146
+ },
147
+ incorrect: {
148
+ color: color$1.incorrect(),
149
+ border: `1px solid ${color$1.incorrect()} !important`
150
+ }
151
+ }))(SimpleQuestionBlockRaw);
152
+ const React$1 = _dll_react;
153
+ const PropTypes = _dll_prop_types;
154
+ const CorrectAnswerToggle = _dll_pie_lib__correct_answer_toggle;
155
+ const {Feedback: Feedback} = _dll_pie_lib__render_ui;
156
+ const {Collapsible: Collapsible} = _dll_pie_lib__render_ui;
157
+ const {Readable: Readable} = _dll_pie_lib__render_ui;
158
+ const {hasText: hasText} = _dll_pie_lib__render_ui;
159
+ const {PreviewPrompt: PreviewPrompt} = _dll_pie_lib__render_ui;
160
+ const {color: color} = _dll_pie_lib__render_ui;
161
+ const {withStyles: withStyles} = _dll_material_ui__core_styles;
162
+ const {Tooltip: Tooltip} = _dll_material_ui__core;
163
+ const {isEqual: isEqual} = _dll_lodash;
164
+ const {isEmpty: isEmpty} = _dll_lodash;
165
+ const cx = _dll_classnames;
166
+ const {mq: mq} = _dll_pie_lib__math_input;
167
+ const {HorizontalKeypad: HorizontalKeypad} = _dll_pie_lib__math_input;
168
+ const {updateSpans: updateSpans} = _dll_pie_lib__math_input;
169
+ const MathQuill = _dll_pie_framework__mathquill;
170
+ const {renderMath: renderMath} = _dll_pie_lib__math_rendering;
171
+ const _jsxFileName = "/home/circleci/repo/packages/math-inline/src/main.jsx";
172
+ function _optionalChain(ops) {
173
+ let lastAccessLHS = undefined;
174
+ let value = ops[0];
175
+ let i = 1;
176
+ while (i < ops.length) {
177
+ const op = ops[i];
178
+ const fn = ops[i + 1];
179
+ i += 2;
180
+ if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
181
+ return undefined;
182
+ }
183
+ if (op === 'access' || op === 'optionalAccess') {
184
+ lastAccessLHS = value;
185
+ value = fn(value);
186
+ } else if (op === 'call' || op === 'optionalCall') {
187
+ value = fn((...args) => value.call(lastAccessLHS, ...args));
188
+ lastAccessLHS = undefined;
189
+ }
190
+ }
191
+ return value;
192
+ }
193
+ let registered = false;
194
+ const NEWLINE_LATEX = /\\newline/g;
195
+ const REGEX = /{{response}}/gm;
196
+ const DEFAULT_KEYPAD_VARIANT = 6;
197
+ const IS_SAFARI = (/^((?!chrome|android).)*safari/i).test(navigator.userAgent);
198
+ function generateAdditionalKeys(keyData = []) {
199
+ return keyData.map(key => ({
200
+ name: key,
201
+ latex: key,
202
+ write: key,
203
+ label: key
204
+ }));
205
+ }
206
+ function getKeyPadWidth(additionalKeys = [], equationEditor) {
207
+ return Math.floor(additionalKeys.length / 5) * 30 + (equationEditor === 'miscellaneous' ? 600 : 500);
208
+ }
209
+ function prepareForStatic(model, state) {
210
+ const {config, disabled} = model || ({});
211
+ const {expression, responses, printMode, alwaysShowCorrect} = config || ({});
212
+ if (config && expression) {
213
+ const modelExpression = expression;
214
+ if (state.showCorrect) {
215
+ return responses && responses.length && responses[0].answer;
216
+ }
217
+ let answerBlocks = 1;
218
+ return (modelExpression || '').replace(REGEX, function () {
219
+ const answer = state.session.answers[`r${answerBlocks}`];
220
+ if (printMode && !alwaysShowCorrect) {
221
+ const blankSpace = ('\\ \\ ').repeat(30) + '\\newline ';
222
+ return `\\MathQuillMathField[r${answerBlocks++}]{${blankSpace.repeat(3)}}`;
223
+ }
224
+ if (disabled) {
225
+ return `\\embed{answerBlock}[r${answerBlocks++}]`;
226
+ }
227
+ return `\\MathQuillMathField[r${answerBlocks++}]{${answer && answer.value || ''}}`;
228
+ }).replace(NEWLINE_LATEX, '\\embed{newLine}[]');
229
+ }
230
+ }
231
+ class Main extends React$1.Component {
232
+ static __initStatic() {
233
+ this.propTypes = {
234
+ classes: PropTypes.object,
235
+ session: PropTypes.object.isRequired,
236
+ onSessionChange: PropTypes.func,
237
+ model: PropTypes.object.isRequired
238
+ };
239
+ }
240
+ constructor(props) {
241
+ super(props);
242
+ Main.prototype.__init.call(this);
243
+ Main.prototype.__init2.call(this);
244
+ Main.prototype.__init3.call(this);
245
+ Main.prototype.__init4.call(this);
246
+ Main.prototype.__init5.call(this);
247
+ Main.prototype.__init6.call(this);
248
+ Main.prototype.__init7.call(this);
249
+ Main.prototype.__init8.call(this);
250
+ Main.prototype.__init9.call(this);
251
+ Main.prototype.__init10.call(this);
252
+ Main.prototype.__init11.call(this);
253
+ Main.prototype.__init12.call(this);
254
+ const answers = {};
255
+ if (props.model.config && props.model.config.expression) {
256
+ let answerBlocks = 1;
257
+ (props.model.config.expression || '').replace(REGEX, () => {
258
+ answers[`r${answerBlocks}`] = {
259
+ value: props.session && props.session.answers && props.session.answers[`r${answerBlocks}`] && props.session.answers[`r${answerBlocks}`].value || ''
260
+ };
261
+ answerBlocks += 1;
262
+ });
263
+ }
264
+ this.state = {
265
+ session: {
266
+ ...props.session,
267
+ answers
268
+ },
269
+ activeAnswerBlock: '',
270
+ showCorrect: this.props.model.config.alwaysShowCorrect || false
271
+ };
272
+ }
273
+ UNSAFE_componentWillMount() {
274
+ const {classes} = this.props;
275
+ if (typeof window !== 'undefined') {
276
+ let MQ = MathQuill.getInterface(2);
277
+ if (!registered) {
278
+ MQ.registerEmbed('answerBlock', data => {
279
+ return {
280
+ htmlString: `<div class="${classes.blockContainer}">
281
+ <div class="${classes.blockResponse}" id="${data}Index">R</div>
282
+ <div class="${classes.blockMath}">
283
+ <span id="${data}"></span>
284
+ </div>
285
+ </div>`,
286
+ text: () => 'text',
287
+ latex: () => `\\embed{answerBlock}[${data}]`
288
+ };
289
+ });
290
+ registered = true;
291
+ }
292
+ }
293
+ }
294
+ __init() {
295
+ this.handleAnswerBlockDomUpdate = () => {
296
+ const {model, classes} = this.props;
297
+ const {session, showCorrect} = this.state;
298
+ const answers = session.answers;
299
+ if (this.root && model.disabled && !showCorrect) {
300
+ Object.keys(answers).forEach(answerId => {
301
+ const el = this.root.querySelector(`#${answerId}`);
302
+ const indexEl = this.root.querySelector(`#${answerId}Index`);
303
+ if (el) {
304
+ let MQ = MathQuill.getInterface(2);
305
+ const answer = answers[answerId];
306
+ el.textContent = answer && answer.value || '';
307
+ if (!model.view) ; else {
308
+ el.parentElement.parentElement.classList.remove(classes.correct);
309
+ el.parentElement.parentElement.classList.remove(classes.incorrect);
310
+ }
311
+ MQ.StaticMath(el);
312
+ indexEl.textContent = 'R';
313
+ }
314
+ });
315
+ }
316
+ renderMath(this.root);
317
+ };
318
+ }
319
+ componentDidUpdate() {
320
+ this.handleAnswerBlockDomUpdate();
321
+ }
322
+ UNSAFE_componentWillReceiveProps(nextProps) {
323
+ const {config} = this.props.model;
324
+ const {config: nextConfig = {}} = nextProps.model || ({});
325
+ if (config.env && config.env.mode !== 'evaluate' || nextConfig.env && nextConfig.env.mode !== 'evaluate') {
326
+ this.setState({
327
+ ...this.state.session,
328
+ showCorrect: false
329
+ });
330
+ }
331
+ if (nextConfig.alwaysShowCorrect) {
332
+ this.setState({
333
+ showCorrect: true
334
+ });
335
+ }
336
+ if (config && config.responses && config.responses.length !== nextConfig.responses.length || !config && nextConfig && nextConfig.responses || config && nextConfig && config.expression !== nextConfig.expression) {
337
+ const newAnswers = {};
338
+ const answers = this.state.session.answers;
339
+ let answerBlocks = 1;
340
+ (nextConfig.expression || '').replace(REGEX, () => {
341
+ newAnswers[`r${answerBlocks}`] = {
342
+ value: answers && answers[`r${answerBlocks}`] && answers[`r${answerBlocks}`].value || ''
343
+ };
344
+ answerBlocks++;
345
+ });
346
+ this.setState(state => ({
347
+ session: {
348
+ ...state.session,
349
+ completeAnswer: this.mqStatic && this.mqStatic.mathField.latex(),
350
+ answers: newAnswers
351
+ }
352
+ }), this.handleAnswerBlockDomUpdate);
353
+ }
354
+ }
355
+ shouldComponentUpdate(nextProps, nextState) {
356
+ const sameModel = isEqual(this.props.model, nextProps.model);
357
+ const sameState = isEqual(this.state, nextState);
358
+ return !sameModel || !sameState;
359
+ }
360
+ componentDidMount() {
361
+ this.handleAnswerBlockDomUpdate();
362
+ setTimeout(() => renderMath(this.root), 100);
363
+ }
364
+ __init2() {
365
+ this.onDone = () => {};
366
+ }
367
+ __init3() {
368
+ this.onSimpleResponseChange = response => {
369
+ this.setState(state => ({
370
+ session: {
371
+ ...state.session,
372
+ response
373
+ }
374
+ }), this.callOnSessionChange);
375
+ };
376
+ }
377
+ __init4() {
378
+ this.onSubFieldFocus = id => {
379
+ this.setState({
380
+ activeAnswerBlock: id
381
+ });
382
+ };
383
+ }
384
+ __init5() {
385
+ this.toNodeData = data => {
386
+ if (!data) {
387
+ return;
388
+ }
389
+ const {type, value} = data;
390
+ if (type === 'command' || type === 'cursor') {
391
+ return data;
392
+ } else if (type === 'answer') {
393
+ return {
394
+ type: 'answer',
395
+ ...data
396
+ };
397
+ } else if (value === 'clear') {
398
+ return {
399
+ type: 'clear'
400
+ };
401
+ } else {
402
+ return {
403
+ type: 'write',
404
+ value
405
+ };
406
+ }
407
+ };
408
+ }
409
+ __init6() {
410
+ this.setInput = input => {
411
+ this.input = input;
412
+ };
413
+ }
414
+ __init7() {
415
+ this.onClick = data => {
416
+ const c = this.toNodeData(data);
417
+ if (c.type === 'clear') {
418
+ this.input.clear();
419
+ } else if (c.type === 'command') {
420
+ if (Array.isArray(c.value)) {
421
+ c.value.forEach(vv => {
422
+ this.input.cmd(vv);
423
+ });
424
+ } else {
425
+ this.input.cmd(c.value);
426
+ }
427
+ } else if (c.type === 'cursor') {
428
+ this.input.keystroke(c.value);
429
+ } else {
430
+ this.input.write(c.value);
431
+ }
432
+ this.input.focus();
433
+ };
434
+ }
435
+ __init8() {
436
+ this.callOnSessionChange = () => {
437
+ const {onSessionChange} = this.props;
438
+ if (onSessionChange) {
439
+ onSessionChange(this.state.session);
440
+ }
441
+ };
442
+ }
443
+ __init9() {
444
+ this.toggleShowCorrect = show => {
445
+ this.setState({
446
+ showCorrect: show
447
+ }, this.handleAnswerBlockDomUpdate);
448
+ };
449
+ }
450
+ __init10() {
451
+ this.subFieldChanged = (name, subfieldValue) => {
452
+ updateSpans();
453
+ if (name) {
454
+ this.setState(state => ({
455
+ session: {
456
+ ...state.session,
457
+ completeAnswer: this.mqStatic && this.mqStatic.mathField.latex(),
458
+ answers: {
459
+ ...state.session.answers,
460
+ [name]: {
461
+ value: subfieldValue
462
+ }
463
+ }
464
+ }
465
+ }), this.callOnSessionChange);
466
+ }
467
+ };
468
+ }
469
+ __init11() {
470
+ this.getFieldName = (changeField, fields) => {
471
+ const {answers} = this.state.session;
472
+ if (Object.keys(answers || ({})).length) {
473
+ const keys = Object.keys(answers);
474
+ return keys.find(k => {
475
+ const tf = fields[k];
476
+ return tf && tf.id == changeField.id;
477
+ });
478
+ }
479
+ };
480
+ }
481
+ __init12() {
482
+ this.onBlur = e => {
483
+ const {relatedTarget, currentTarget} = e || ({});
484
+ 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']])) {
485
+ this.setState({
486
+ activeAnswerBlock: ''
487
+ });
488
+ }
489
+ };
490
+ }
491
+ setTooltipRef(ref) {
492
+ setTimeout(() => {
493
+ if (ref && IS_SAFARI) {
494
+ const div = document.querySelector('[role=\'tooltip\']');
495
+ if (div) {
496
+ const el = div.firstChild;
497
+ el.setAttribute('tabindex', '-1');
498
+ }
499
+ }
500
+ }, 1);
501
+ }
502
+ render() {
503
+ const {model, classes} = this.props;
504
+ const {activeAnswerBlock, showCorrect, session} = this.state;
505
+ const {config, correctness, disabled, view, teacherInstructions, rationale, feedback, animationsDisabled, printMode, alwaysShowCorrect} = model || ({});
506
+ if (!config) {
507
+ return null;
508
+ }
509
+ const {showNote, note, prompt, responses, responseType, equationEditor, customKeys, env: {mode, role} = {}} = config || ({});
510
+ const displayNote = (showCorrect || mode === 'view' && role === 'instructor') && showNote && note;
511
+ const emptyResponse = isEmpty(responses);
512
+ const showCorrectAnswerToggle = !emptyResponse && correctness && correctness.correctness !== 'correct';
513
+ const tooltipModeEnabled = disabled && correctness && responseType !== ResponseTypes$1.simple;
514
+ const additionalKeys = generateAdditionalKeys(customKeys);
515
+ const correct = correctness && correctness.correct;
516
+ const staticLatex = prepareForStatic(model, this.state) || '';
517
+ const viewMode = disabled && !correctness;
518
+ const studentPrintMode = printMode && !alwaysShowCorrect;
519
+ const printView = React$1.createElement('div', {
520
+ className: classes.printContainer,
521
+ __self: this,
522
+ __source: {
523
+ fileName: _jsxFileName,
524
+ lineNumber: 411
525
+ }
526
+ }, React$1.createElement(mq.Static, {
527
+ ref: mqStatic => this.mqStatic = mqStatic || this.mqStatic,
528
+ latex: staticLatex,
529
+ onSubFieldChange: this.subFieldChanged,
530
+ getFieldName: this.getFieldName,
531
+ setInput: this.setInput,
532
+ onSubFieldFocus: this.onSubFieldFocus,
533
+ onBlur: this.onBlur,
534
+ __self: this,
535
+ __source: {
536
+ fileName: _jsxFileName,
537
+ lineNumber: 412
538
+ }
539
+ }));
540
+ const midContent = React$1.createElement('div', {
541
+ className: classes.main,
542
+ __self: this,
543
+ __source: {
544
+ fileName: _jsxFileName,
545
+ lineNumber: 424
546
+ }
547
+ }, prompt && React$1.createElement('div', {
548
+ className: classes.content,
549
+ __self: this,
550
+ __source: {
551
+ fileName: _jsxFileName,
552
+ lineNumber: 426
553
+ }
554
+ }, React$1.createElement(PreviewPrompt, {
555
+ prompt: prompt,
556
+ __self: this,
557
+ __source: {
558
+ fileName: _jsxFileName,
559
+ lineNumber: 427
560
+ }
561
+ })), studentPrintMode ? printView : React$1.createElement(Readable, {
562
+ false: true,
563
+ __self: this,
564
+ __source: {
565
+ fileName: _jsxFileName,
566
+ lineNumber: 430
567
+ }
568
+ }, React$1.createElement('div', {
569
+ className: classes.inputAndKeypadContainer,
570
+ __self: this,
571
+ __source: {
572
+ fileName: _jsxFileName,
573
+ lineNumber: 431
574
+ }
575
+ }, responseType === ResponseTypes$1.simple && React$1.createElement(SimpleQuestionBlock, {
576
+ onSimpleResponseChange: this.onSimpleResponseChange,
577
+ showCorrect: showCorrect,
578
+ emptyResponse: emptyResponse,
579
+ model: model,
580
+ session: session,
581
+ __self: this,
582
+ __source: {
583
+ fileName: _jsxFileName,
584
+ lineNumber: 433
585
+ }
586
+ }), responseType === ResponseTypes$1.advanced && React$1.createElement('div', {
587
+ className: cx(classes.expression, {
588
+ [classes.incorrect]: !emptyResponse && !correct && !showCorrect,
589
+ [classes.correct]: !emptyResponse && (correct || showCorrect),
590
+ [classes.showCorrectness]: !emptyResponse && disabled && correctness && !view,
591
+ [classes.correctAnswerShown]: showCorrect
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: 462
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: 471
626
+ }
627
+ })) || null),
628
+ __self: this,
629
+ __source: {
630
+ fileName: _jsxFileName,
631
+ lineNumber: 450
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: 481
645
+ }
646
+ }))))), viewMode && teacherInstructions && hasText(teacherInstructions) && React$1.createElement(React$1.Fragment, {
647
+ __self: this,
648
+ __source: {
649
+ fileName: _jsxFileName,
650
+ lineNumber: 497
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: 498
661
+ }
662
+ }, React$1.createElement('div', {
663
+ dangerouslySetInnerHTML: {
664
+ __html: teacherInstructions
665
+ },
666
+ __self: this,
667
+ __source: {
668
+ fileName: _jsxFileName,
669
+ lineNumber: 501
670
+ }
671
+ })) : React$1.createElement('div', {
672
+ dangerouslySetInnerHTML: {
673
+ __html: teacherInstructions
674
+ },
675
+ __self: this,
676
+ __source: {
677
+ fileName: _jsxFileName,
678
+ lineNumber: 502
679
+ }
680
+ }), React$1.createElement('br', {
681
+ __self: this,
682
+ __source: {
683
+ fileName: _jsxFileName,
684
+ lineNumber: 503
685
+ }
686
+ })), viewMode && rationale && hasText(rationale) && React$1.createElement(React$1.Fragment, {
687
+ __self: this,
688
+ __source: {
689
+ fileName: _jsxFileName,
690
+ lineNumber: 509
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: 510
701
+ }
702
+ }, React$1.createElement('div', {
703
+ dangerouslySetInnerHTML: {
704
+ __html: rationale
705
+ },
706
+ __self: this,
707
+ __source: {
708
+ fileName: _jsxFileName,
709
+ lineNumber: 513
710
+ }
711
+ })) : React$1.createElement('div', {
712
+ dangerouslySetInnerHTML: {
713
+ __html: rationale
714
+ },
715
+ __self: this,
716
+ __source: {
717
+ fileName: _jsxFileName,
718
+ lineNumber: 514
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: 519
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: 536
743
+ }
744
+ }, React$1.createElement('div', {
745
+ className: classes.main,
746
+ __self: this,
747
+ __source: {
748
+ fileName: _jsxFileName,
749
+ lineNumber: 537
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: 539
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: 548
772
+ }
773
+ }, React$1.createElement(PreviewPrompt, {
774
+ prompt: teacherInstructions,
775
+ __self: this,
776
+ __source: {
777
+ fileName: _jsxFileName,
778
+ lineNumber: 556
779
+ }
780
+ })), React$1.createElement('br', {
781
+ key: "br",
782
+ __self: this,
783
+ __source: {
784
+ fileName: _jsxFileName,
785
+ lineNumber: 558
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: 561
797
+ }
798
+ }, React$1.createElement(PreviewPrompt, {
799
+ prompt: rationale,
800
+ __self: this,
801
+ __source: {
802
+ fileName: _jsxFileName,
803
+ lineNumber: 568
804
+ }
805
+ })), React$1.createElement('br', {
806
+ key: "br",
807
+ __self: this,
808
+ __source: {
809
+ fileName: _jsxFileName,
810
+ lineNumber: 570
811
+ }
812
+ })], feedback && React$1.createElement(Feedback, {
813
+ correctness: correctness.correctness,
814
+ feedback: feedback,
815
+ __self: this,
816
+ __source: {
817
+ fileName: _jsxFileName,
818
+ lineNumber: 573
819
+ }
820
+ })),
821
+ __self: this,
822
+ __source: {
823
+ fileName: _jsxFileName,
824
+ lineNumber: 529
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: 581
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: 591
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
+ correct: {
972
+ borderColor: `${color.correct()} !important`
973
+ },
974
+ incorrect: {
975
+ borderColor: `${color.incorrect()} !important`
976
+ },
977
+ blockContainer: {
978
+ margin: `${theme.spacing.unit}px !important`,
979
+ display: 'inline-flex',
980
+ border: '2px solid grey !important'
981
+ },
982
+ blockResponse: {
983
+ flex: 2,
984
+ color: 'grey',
985
+ background: 'lightgrey',
986
+ fontSize: '0.8rem !important',
987
+ padding: `${theme.spacing.unit / 2}px !important`,
988
+ display: 'flex',
989
+ alignItems: 'center',
990
+ justifyContent: 'center',
991
+ borderRight: `2px solid ${color.disabled()} !important`
992
+ },
993
+ toggle: {
994
+ color: color.text()
995
+ },
996
+ blockMath: {
997
+ color: color.text(),
998
+ backgroundColor: color.background(),
999
+ padding: `${theme.spacing.unit / 2}px !important`,
1000
+ display: 'flex',
1001
+ alignItems: 'center',
1002
+ justifyContent: 'center',
1003
+ flex: 8,
1004
+ '& > .mq-math-mode': {
1005
+ '& > .mq-hasCursor': {
1006
+ '& > .mq-cursor': {
1007
+ display: 'none'
1008
+ }
1009
+ }
1010
+ }
1011
+ },
1012
+ printContainer: {
1013
+ marginBottom: '10px',
1014
+ pointerEvents: 'none'
1015
+ }
1016
+ });
1017
+ var Main$1 = withStyles(styles)(Main);
1018
+ function getDefaultExportFromCjs(x) {
1019
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1020
+ }
1021
+ var lib = {};
1022
+ Object.defineProperty(lib, "__esModule", {
1023
+ value: true
1024
+ });
1025
+ class ModelSetEvent extends CustomEvent {
1026
+ constructor(component, complete, hasModel) {
1027
+ super(ModelSetEvent.TYPE, {
1028
+ bubbles: true,
1029
+ composed: true,
1030
+ detail: {
1031
+ complete,
1032
+ component,
1033
+ hasModel
1034
+ }
1035
+ });
1036
+ this.component = component;
1037
+ this.complete = complete;
1038
+ }
1039
+ }
1040
+ ModelSetEvent.TYPE = 'model-set';
1041
+ var ModelSetEvent_1 = lib.ModelSetEvent = ModelSetEvent;
1042
+ class SessionChangedEvent extends CustomEvent {
1043
+ constructor(component, complete) {
1044
+ super(SessionChangedEvent.TYPE, {
1045
+ bubbles: true,
1046
+ composed: true,
1047
+ detail: {
1048
+ complete,
1049
+ component
1050
+ }
1051
+ });
1052
+ this.component = component;
1053
+ this.complete = complete;
1054
+ }
1055
+ }
1056
+ SessionChangedEvent.TYPE = 'session-changed';
1057
+ var SessionChangedEvent_1 = lib.SessionChangedEvent = SessionChangedEvent;
1058
+ var defaults$1 = {};
1059
+ var utils = {};
1060
+ Object.defineProperty(utils, "__esModule", {
1061
+ value: true
1062
+ });
1063
+ utils.ResponseTypes = void 0;
1064
+ var ResponseTypes = {
1065
+ advanced: 'Advanced Multi',
1066
+ simple: 'Simple'
1067
+ };
1068
+ utils.ResponseTypes = ResponseTypes;
1069
+ (function (exports) {
1070
+ Object.defineProperty(exports, "__esModule", {
1071
+ value: true
1072
+ });
1073
+ exports["default"] = void 0;
1074
+ var _utils = utils;
1075
+ var _default = {
1076
+ model: {
1077
+ partialScoring: true,
1078
+ responseType: _utils.ResponseTypes.advanced,
1079
+ element: 'math-inline',
1080
+ feedback: {
1081
+ correct: {
1082
+ "default": 'Correct',
1083
+ type: 'none'
1084
+ },
1085
+ incorrect: {
1086
+ "default": 'Incorrect',
1087
+ type: 'none'
1088
+ },
1089
+ partial: {
1090
+ "default": 'Nearly',
1091
+ type: 'none'
1092
+ }
1093
+ },
1094
+ equationEditor: '8',
1095
+ expression: '',
1096
+ rationale: 'Rationale goes here.',
1097
+ 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.',
1098
+ prompt: '',
1099
+ responses: [],
1100
+ customKeys: [],
1101
+ scoringType: 'auto',
1102
+ feedbackEnabled: true,
1103
+ promptEnabled: true,
1104
+ rationaleEnabled: true,
1105
+ teacherInstructionsEnabled: true,
1106
+ studentInstructionsEnabled: true,
1107
+ toolbarEditorPosition: 'bottom',
1108
+ validationDefault: 'literal',
1109
+ ignoreOrderDefault: false,
1110
+ allowTrailingZerosDefault: false
1111
+ },
1112
+ configuration: {
1113
+ prompt: {
1114
+ settings: true,
1115
+ label: 'Prompt'
1116
+ },
1117
+ feedback: {
1118
+ settings: true,
1119
+ label: 'Feedback'
1120
+ },
1121
+ responseType: {
1122
+ settings: true,
1123
+ label: 'Response type'
1124
+ },
1125
+ rationale: {
1126
+ settings: true,
1127
+ label: 'Rationale'
1128
+ },
1129
+ scoringType: {
1130
+ settings: false,
1131
+ label: 'Scoring Type'
1132
+ },
1133
+ studentInstructions: {
1134
+ settings: false,
1135
+ label: 'Student Instructions'
1136
+ },
1137
+ teacherInstructions: {
1138
+ settings: true,
1139
+ label: 'Teacher Instructions'
1140
+ },
1141
+ partialScoring: {
1142
+ settings: false,
1143
+ label: 'Allow Partial Scoring'
1144
+ },
1145
+ ignoreOrder: {
1146
+ settings: false,
1147
+ label: 'Ignore Order',
1148
+ enabled: true
1149
+ },
1150
+ allowTrailingZeros: {
1151
+ settings: false,
1152
+ label: 'Allow Trailing Zeros',
1153
+ enabled: true
1154
+ }
1155
+ }
1156
+ };
1157
+ exports["default"] = _default;
1158
+ })(defaults$1);
1159
+ var defaults = getDefaultExportFromCjs(defaults$1);
1160
+ const React = _dll_react;
1161
+ const ReactDOM = _dll_react_dom;
1162
+ const debug = _dll_debug;
1163
+ const _ = _dll_lodash;
1164
+ const log = debug('pie-ui:math-inline');
1165
+ class MathInline extends HTMLElement {
1166
+ constructor() {
1167
+ super();
1168
+ this._configuration = defaults.configuration;
1169
+ this.sessionChangedEventCaller = _.debounce(session => {
1170
+ this.dispatchEvent(new SessionChangedEvent_1(session, true));
1171
+ }, 1000);
1172
+ }
1173
+ set model(m) {
1174
+ this._model = m;
1175
+ this.dispatchEvent(new ModelSetEvent_1(this._model, true, !!this._model));
1176
+ this._render();
1177
+ }
1178
+ set session(s) {
1179
+ this._session = s;
1180
+ this._render();
1181
+ }
1182
+ set configuration(c) {
1183
+ this._configuration = c;
1184
+ this._render();
1185
+ }
1186
+ sessionChanged(s) {
1187
+ Object.keys(s).map(key => {
1188
+ this._session[key] = s[key];
1189
+ });
1190
+ this.sessionChangedEventCaller(this._session);
1191
+ log('session: ', this._session);
1192
+ }
1193
+ connectedCallback() {
1194
+ this._render();
1195
+ }
1196
+ _render() {
1197
+ if (!this._model || !this._session) {
1198
+ return;
1199
+ }
1200
+ const el = React.createElement(Main$1, {
1201
+ model: this._model,
1202
+ session: this._session,
1203
+ configuration: this._configuration,
1204
+ onSessionChange: this.sessionChanged.bind(this)
1205
+ });
1206
+ ReactDOM.render(el, this);
1207
+ }
1208
+ }
1209
+ export {Main$1 as Component, MathInline as default};