@pie-element/math-inline 5.8.11 → 5.9.2

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,1208 @@
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.3.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.20/module/index.js";
3
+ import {_dll_pie_lib__math_rendering} from "../../../@pie-lib/math-rendering-module@^1.0.24/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
+ }),
592
+ __self: this,
593
+ __source: {
594
+ fileName: _jsxFileName,
595
+ lineNumber: 442
596
+ }
597
+ }, React$1.createElement(Tooltip, {
598
+ ref: ref => this.setTooltipRef(ref),
599
+ interactive: true,
600
+ open: !!activeAnswerBlock,
601
+ classes: {
602
+ tooltip: classes.keypadTooltip,
603
+ popper: classes.keypadTooltipPopper
604
+ },
605
+ title: Object.keys(session.answers).map(answerId => answerId === activeAnswerBlock && !(showCorrect || disabled) && React$1.createElement('div', {
606
+ 'data-keypad': true,
607
+ key: answerId,
608
+ className: classes.responseContainer,
609
+ style: {
610
+ width: getKeyPadWidth(additionalKeys, equationEditor)
611
+ },
612
+ __self: this,
613
+ __source: {
614
+ fileName: _jsxFileName,
615
+ lineNumber: 462
616
+ }
617
+ }, React$1.createElement(HorizontalKeypad, {
618
+ additionalKeys: additionalKeys,
619
+ mode: equationEditor || DEFAULT_KEYPAD_VARIANT,
620
+ onClick: this.onClick,
621
+ __self: this,
622
+ __source: {
623
+ fileName: _jsxFileName,
624
+ lineNumber: 471
625
+ }
626
+ })) || null),
627
+ __self: this,
628
+ __source: {
629
+ fileName: _jsxFileName,
630
+ lineNumber: 450
631
+ }
632
+ }, React$1.createElement(mq.Static, {
633
+ ref: mqStatic => this.mqStatic = mqStatic || this.mqStatic,
634
+ latex: staticLatex,
635
+ onSubFieldChange: this.subFieldChanged,
636
+ getFieldName: this.getFieldName,
637
+ setInput: this.setInput,
638
+ onSubFieldFocus: this.onSubFieldFocus,
639
+ onBlur: this.onBlur,
640
+ __self: this,
641
+ __source: {
642
+ fileName: _jsxFileName,
643
+ lineNumber: 481
644
+ }
645
+ }))))), viewMode && teacherInstructions && hasText(teacherInstructions) && React$1.createElement(React$1.Fragment, {
646
+ __self: this,
647
+ __source: {
648
+ fileName: _jsxFileName,
649
+ lineNumber: 497
650
+ }
651
+ }, !animationsDisabled ? React$1.createElement(Collapsible, {
652
+ labels: {
653
+ hidden: 'Show Teacher Instructions',
654
+ visible: 'Hide Teacher Instructions'
655
+ },
656
+ __self: this,
657
+ __source: {
658
+ fileName: _jsxFileName,
659
+ lineNumber: 498
660
+ }
661
+ }, React$1.createElement('div', {
662
+ dangerouslySetInnerHTML: {
663
+ __html: teacherInstructions
664
+ },
665
+ __self: this,
666
+ __source: {
667
+ fileName: _jsxFileName,
668
+ lineNumber: 501
669
+ }
670
+ })) : React$1.createElement('div', {
671
+ dangerouslySetInnerHTML: {
672
+ __html: teacherInstructions
673
+ },
674
+ __self: this,
675
+ __source: {
676
+ fileName: _jsxFileName,
677
+ lineNumber: 502
678
+ }
679
+ }), React$1.createElement('br', {
680
+ __self: this,
681
+ __source: {
682
+ fileName: _jsxFileName,
683
+ lineNumber: 503
684
+ }
685
+ })), viewMode && rationale && hasText(rationale) && React$1.createElement(React$1.Fragment, {
686
+ __self: this,
687
+ __source: {
688
+ fileName: _jsxFileName,
689
+ lineNumber: 509
690
+ }
691
+ }, !animationsDisabled ? React$1.createElement(Collapsible, {
692
+ labels: {
693
+ hidden: 'Show Rationale',
694
+ visible: 'Hide Rationale'
695
+ },
696
+ __self: this,
697
+ __source: {
698
+ fileName: _jsxFileName,
699
+ lineNumber: 510
700
+ }
701
+ }, React$1.createElement('div', {
702
+ dangerouslySetInnerHTML: {
703
+ __html: rationale
704
+ },
705
+ __self: this,
706
+ __source: {
707
+ fileName: _jsxFileName,
708
+ lineNumber: 513
709
+ }
710
+ })) : React$1.createElement('div', {
711
+ dangerouslySetInnerHTML: {
712
+ __html: rationale
713
+ },
714
+ __self: this,
715
+ __source: {
716
+ fileName: _jsxFileName,
717
+ lineNumber: 514
718
+ }
719
+ })), displayNote && React$1.createElement('div', {
720
+ className: classes.note,
721
+ dangerouslySetInnerHTML: {
722
+ __html: `<strong>Note:</strong> ${note}`
723
+ },
724
+ __self: this,
725
+ __source: {
726
+ fileName: _jsxFileName,
727
+ lineNumber: 519
728
+ }
729
+ }));
730
+ if (tooltipModeEnabled && (showCorrectAnswerToggle || teacherInstructions || rationale || feedback)) {
731
+ return React$1.createElement(Tooltip, {
732
+ interactive: true,
733
+ classes: {
734
+ tooltip: classes.tooltip,
735
+ popper: classes.tooltipPopper
736
+ },
737
+ title: React$1.createElement('div', {
738
+ __self: this,
739
+ __source: {
740
+ fileName: _jsxFileName,
741
+ lineNumber: 536
742
+ }
743
+ }, React$1.createElement('div', {
744
+ className: classes.main,
745
+ __self: this,
746
+ __source: {
747
+ fileName: _jsxFileName,
748
+ lineNumber: 537
749
+ }
750
+ }, showCorrectAnswerToggle && React$1.createElement(CorrectAnswerToggle, {
751
+ className: classes.toggle,
752
+ show: true,
753
+ toggled: showCorrect,
754
+ onToggle: this.toggleShowCorrect,
755
+ __self: this,
756
+ __source: {
757
+ fileName: _jsxFileName,
758
+ lineNumber: 539
759
+ }
760
+ })), teacherInstructions && hasText(teacherInstructions) && [React$1.createElement(Collapsible, {
761
+ key: "collapsible",
762
+ labels: {
763
+ hidden: 'Show Teacher Instructions',
764
+ visible: 'Hide Teacher Instructions'
765
+ },
766
+ className: classes.collapsible,
767
+ __self: this,
768
+ __source: {
769
+ fileName: _jsxFileName,
770
+ lineNumber: 548
771
+ }
772
+ }, React$1.createElement(PreviewPrompt, {
773
+ prompt: teacherInstructions,
774
+ __self: this,
775
+ __source: {
776
+ fileName: _jsxFileName,
777
+ lineNumber: 556
778
+ }
779
+ })), React$1.createElement('br', {
780
+ key: "br",
781
+ __self: this,
782
+ __source: {
783
+ fileName: _jsxFileName,
784
+ lineNumber: 558
785
+ }
786
+ })], rationale && hasText(rationale) && [React$1.createElement(Collapsible, {
787
+ key: "collapsible",
788
+ labels: {
789
+ hidden: 'Show Rationale',
790
+ visible: 'Hide Rationale'
791
+ },
792
+ __self: this,
793
+ __source: {
794
+ fileName: _jsxFileName,
795
+ lineNumber: 561
796
+ }
797
+ }, React$1.createElement(PreviewPrompt, {
798
+ prompt: rationale,
799
+ __self: this,
800
+ __source: {
801
+ fileName: _jsxFileName,
802
+ lineNumber: 568
803
+ }
804
+ })), React$1.createElement('br', {
805
+ key: "br",
806
+ __self: this,
807
+ __source: {
808
+ fileName: _jsxFileName,
809
+ lineNumber: 570
810
+ }
811
+ })], feedback && React$1.createElement(Feedback, {
812
+ correctness: correctness.correctness,
813
+ feedback: feedback,
814
+ __self: this,
815
+ __source: {
816
+ fileName: _jsxFileName,
817
+ lineNumber: 573
818
+ }
819
+ })),
820
+ __self: this,
821
+ __source: {
822
+ fileName: _jsxFileName,
823
+ lineNumber: 529
824
+ }
825
+ }, React$1.createElement('div', {
826
+ className: classes.mainContainer,
827
+ ref: r => this.root = r || this.root,
828
+ __self: this,
829
+ __source: {
830
+ fileName: _jsxFileName,
831
+ lineNumber: 581
832
+ }
833
+ }, midContent));
834
+ }
835
+ return React$1.createElement('div', {
836
+ className: classes.mainContainer,
837
+ ref: r => this.root = r || this.root,
838
+ __self: this,
839
+ __source: {
840
+ fileName: _jsxFileName,
841
+ lineNumber: 591
842
+ }
843
+ }, midContent);
844
+ }
845
+ }
846
+ Main.__initStatic();
847
+ const styles = theme => ({
848
+ mainContainer: {
849
+ display: 'inline-block'
850
+ },
851
+ tooltip: {
852
+ background: `${color.primaryLight()} !important`,
853
+ color: color.text(),
854
+ padding: theme.spacing.unit * 2,
855
+ border: `1px solid ${color.secondary()}`,
856
+ fontSize: '16px',
857
+ '& :not(.MathJax) > table tr': {
858
+ '&:nth-child(2n)': {
859
+ backgroundColor: 'unset !important'
860
+ }
861
+ }
862
+ },
863
+ tooltipPopper: {
864
+ opacity: 1
865
+ },
866
+ keypadTooltip: {
867
+ fontSize: 'initial',
868
+ background: 'transparent',
869
+ width: '600px',
870
+ marginTop: 0,
871
+ paddingTop: 0
872
+ },
873
+ keypadTooltipPopper: {
874
+ background: 'transparent',
875
+ width: '650px',
876
+ opacity: 1
877
+ },
878
+ main: {
879
+ width: '100%',
880
+ position: 'relative',
881
+ padding: theme.spacing.unit / 2,
882
+ backgroundColor: color.background(),
883
+ color: color.text()
884
+ },
885
+ title: {
886
+ fontSize: '1.1rem',
887
+ display: 'block',
888
+ marginTop: theme.spacing.unit * 2,
889
+ marginBottom: theme.spacing.unit
890
+ },
891
+ content: {
892
+ marginTop: theme.spacing.unit * 2
893
+ },
894
+ note: {
895
+ paddingTop: '15px'
896
+ },
897
+ collapsible: {
898
+ marginTop: theme.spacing.unit * 2
899
+ },
900
+ responseContainer: {
901
+ zIndex: 10,
902
+ minWidth: '400px',
903
+ marginTop: theme.spacing.unit * 2
904
+ },
905
+ expression: {
906
+ maxWidth: 'fit-content',
907
+ '& > .mq-math-mode': {
908
+ '& > .mq-root-block': {
909
+ '& > .mq-editable-field': {
910
+ minWidth: '10px',
911
+ margin: theme.spacing.unit * 2 / 3,
912
+ padding: theme.spacing.unit / 4
913
+ }
914
+ },
915
+ '& sup': {
916
+ top: 0
917
+ }
918
+ }
919
+ },
920
+ inputAndKeypadContainer: {
921
+ position: 'relative',
922
+ '& .mq-overarrow-inner': {
923
+ border: 'none !important',
924
+ padding: '0 !important'
925
+ },
926
+ '& .mq-overarrow-inner-right': {
927
+ display: 'none !important'
928
+ },
929
+ '& .mq-overarrow-inner-left': {
930
+ display: 'none !important'
931
+ },
932
+ '& .mq-overarrow.mq-arrow-both': {
933
+ minWidth: '1.23em',
934
+ '& *': {
935
+ lineHeight: '1 !important'
936
+ },
937
+ '&:before': {
938
+ top: '-0.4em',
939
+ left: '-1px'
940
+ },
941
+ '&:after': {
942
+ top: '-2.4em',
943
+ right: '-1px'
944
+ },
945
+ '&.mq-empty:after': {
946
+ top: '-0.45em'
947
+ }
948
+ },
949
+ '& .mq-overarrow.mq-arrow-right': {
950
+ '&:before': {
951
+ top: '-0.4em',
952
+ right: '-1px'
953
+ }
954
+ },
955
+ '& .mq-longdiv-inner': {
956
+ borderTop: '1px solid !important',
957
+ paddingTop: '1.5px !important'
958
+ },
959
+ '& .mq-parallelogram': {
960
+ lineHeight: 0.85
961
+ }
962
+ },
963
+ showCorrectness: {
964
+ border: '2px solid'
965
+ },
966
+ correctAnswerShown: {
967
+ padding: theme.spacing.unit,
968
+ letterSpacing: '0.5px'
969
+ },
970
+ correct: {
971
+ borderColor: `${color.correct()} !important`
972
+ },
973
+ incorrect: {
974
+ borderColor: `${color.incorrect()} !important`
975
+ },
976
+ blockContainer: {
977
+ margin: `${theme.spacing.unit}px !important`,
978
+ display: 'inline-flex',
979
+ border: '2px solid grey !important'
980
+ },
981
+ blockResponse: {
982
+ flex: 2,
983
+ color: 'grey',
984
+ background: 'lightgrey',
985
+ fontSize: '0.8rem !important',
986
+ padding: `${theme.spacing.unit / 2}px !important`,
987
+ display: 'flex',
988
+ alignItems: 'center',
989
+ justifyContent: 'center',
990
+ borderRight: `2px solid ${color.disabled()} !important`
991
+ },
992
+ toggle: {
993
+ color: color.text()
994
+ },
995
+ blockMath: {
996
+ color: color.text(),
997
+ backgroundColor: color.background(),
998
+ padding: `${theme.spacing.unit / 2}px !important`,
999
+ display: 'flex',
1000
+ alignItems: 'center',
1001
+ justifyContent: 'center',
1002
+ flex: 8,
1003
+ '& > .mq-math-mode': {
1004
+ '& > .mq-hasCursor': {
1005
+ '& > .mq-cursor': {
1006
+ display: 'none'
1007
+ }
1008
+ }
1009
+ }
1010
+ },
1011
+ printContainer: {
1012
+ marginBottom: '10px',
1013
+ pointerEvents: 'none'
1014
+ }
1015
+ });
1016
+ var Main$1 = withStyles(styles)(Main);
1017
+ function getDefaultExportFromCjs(x) {
1018
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1019
+ }
1020
+ var lib = {};
1021
+ Object.defineProperty(lib, "__esModule", {
1022
+ value: true
1023
+ });
1024
+ class ModelSetEvent extends CustomEvent {
1025
+ constructor(component, complete, hasModel) {
1026
+ super(ModelSetEvent.TYPE, {
1027
+ bubbles: true,
1028
+ composed: true,
1029
+ detail: {
1030
+ complete,
1031
+ component,
1032
+ hasModel
1033
+ }
1034
+ });
1035
+ this.component = component;
1036
+ this.complete = complete;
1037
+ }
1038
+ }
1039
+ ModelSetEvent.TYPE = 'model-set';
1040
+ var ModelSetEvent_1 = lib.ModelSetEvent = ModelSetEvent;
1041
+ class SessionChangedEvent extends CustomEvent {
1042
+ constructor(component, complete) {
1043
+ super(SessionChangedEvent.TYPE, {
1044
+ bubbles: true,
1045
+ composed: true,
1046
+ detail: {
1047
+ complete,
1048
+ component
1049
+ }
1050
+ });
1051
+ this.component = component;
1052
+ this.complete = complete;
1053
+ }
1054
+ }
1055
+ SessionChangedEvent.TYPE = 'session-changed';
1056
+ var SessionChangedEvent_1 = lib.SessionChangedEvent = SessionChangedEvent;
1057
+ var defaults$1 = {};
1058
+ var utils = {};
1059
+ Object.defineProperty(utils, "__esModule", {
1060
+ value: true
1061
+ });
1062
+ utils.ResponseTypes = void 0;
1063
+ var ResponseTypes = {
1064
+ advanced: 'Advanced Multi',
1065
+ simple: 'Simple'
1066
+ };
1067
+ utils.ResponseTypes = ResponseTypes;
1068
+ (function (exports) {
1069
+ Object.defineProperty(exports, "__esModule", {
1070
+ value: true
1071
+ });
1072
+ exports["default"] = void 0;
1073
+ var _utils = utils;
1074
+ var _default = {
1075
+ model: {
1076
+ partialScoring: true,
1077
+ responseType: _utils.ResponseTypes.advanced,
1078
+ element: 'math-inline',
1079
+ feedback: {
1080
+ correct: {
1081
+ "default": 'Correct',
1082
+ type: 'none'
1083
+ },
1084
+ incorrect: {
1085
+ "default": 'Incorrect',
1086
+ type: 'none'
1087
+ },
1088
+ partial: {
1089
+ "default": 'Nearly',
1090
+ type: 'none'
1091
+ }
1092
+ },
1093
+ equationEditor: '8',
1094
+ expression: '',
1095
+ rationale: 'Rationale goes here.',
1096
+ 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.',
1097
+ prompt: '',
1098
+ responses: [],
1099
+ customKeys: [],
1100
+ scoringType: 'auto',
1101
+ feedbackEnabled: true,
1102
+ promptEnabled: true,
1103
+ rationaleEnabled: true,
1104
+ teacherInstructionsEnabled: true,
1105
+ studentInstructionsEnabled: true,
1106
+ toolbarEditorPosition: 'bottom',
1107
+ validationDefault: 'literal',
1108
+ ignoreOrderDefault: false,
1109
+ allowTrailingZerosDefault: false
1110
+ },
1111
+ configuration: {
1112
+ prompt: {
1113
+ settings: true,
1114
+ label: 'Prompt'
1115
+ },
1116
+ feedback: {
1117
+ settings: true,
1118
+ label: 'Feedback'
1119
+ },
1120
+ responseType: {
1121
+ settings: true,
1122
+ label: 'Response type'
1123
+ },
1124
+ rationale: {
1125
+ settings: true,
1126
+ label: 'Rationale'
1127
+ },
1128
+ scoringType: {
1129
+ settings: false,
1130
+ label: 'Scoring Type'
1131
+ },
1132
+ studentInstructions: {
1133
+ settings: false,
1134
+ label: 'Student Instructions'
1135
+ },
1136
+ teacherInstructions: {
1137
+ settings: true,
1138
+ label: 'Teacher Instructions'
1139
+ },
1140
+ partialScoring: {
1141
+ settings: false,
1142
+ label: 'Allow Partial Scoring'
1143
+ },
1144
+ ignoreOrder: {
1145
+ settings: false,
1146
+ label: 'Ignore Order',
1147
+ enabled: true
1148
+ },
1149
+ allowTrailingZeros: {
1150
+ settings: false,
1151
+ label: 'Allow Trailing Zeros',
1152
+ enabled: true
1153
+ }
1154
+ }
1155
+ };
1156
+ exports["default"] = _default;
1157
+ })(defaults$1);
1158
+ var defaults = getDefaultExportFromCjs(defaults$1);
1159
+ const React = _dll_react;
1160
+ const ReactDOM = _dll_react_dom;
1161
+ const debug = _dll_debug;
1162
+ const _ = _dll_lodash;
1163
+ const log = debug('pie-ui:math-inline');
1164
+ class MathInline extends HTMLElement {
1165
+ constructor() {
1166
+ super();
1167
+ this._configuration = defaults.configuration;
1168
+ this.sessionChangedEventCaller = _.debounce(session => {
1169
+ this.dispatchEvent(new SessionChangedEvent_1(session, true));
1170
+ }, 1000);
1171
+ }
1172
+ set model(m) {
1173
+ this._model = m;
1174
+ this.dispatchEvent(new ModelSetEvent_1(this._model, true, !!this._model));
1175
+ this._render();
1176
+ }
1177
+ set session(s) {
1178
+ this._session = s;
1179
+ this._render();
1180
+ }
1181
+ set configuration(c) {
1182
+ this._configuration = c;
1183
+ this._render();
1184
+ }
1185
+ sessionChanged(s) {
1186
+ Object.keys(s).map(key => {
1187
+ this._session[key] = s[key];
1188
+ });
1189
+ this.sessionChangedEventCaller(this._session);
1190
+ log('session: ', this._session);
1191
+ }
1192
+ connectedCallback() {
1193
+ this._render();
1194
+ }
1195
+ _render() {
1196
+ if (!this._model || !this._session) {
1197
+ return;
1198
+ }
1199
+ const el = React.createElement(Main$1, {
1200
+ model: this._model,
1201
+ session: this._session,
1202
+ configuration: this._configuration,
1203
+ onSessionChange: this.sessionChanged.bind(this)
1204
+ });
1205
+ ReactDOM.render(el, this);
1206
+ }
1207
+ }
1208
+ export {Main$1 as Component, MathInline as default};