@pie-element/inline-dropdown 3.8.2 → 3.8.3-next.1008

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.
@@ -1,1338 +0,0 @@
1
- import {_dll_pie_lib__editable_html, _dll_pie_lib__config_ui, _dll_pie_framework__pie_configure_events} from "../../shared-config@^1.8.13/module/index.js";
2
- import {_dll_react, _dll_react_dom, _dll_prop_types, _dll_pie_lib__math_rendering, _dll_material_ui__core_styles, _dll_lodash, _dll_material_ui__core} from "../../../@pie-ui/shared-lib@^4.3.3/module/index.js";
3
- function createCommonjsModule(fn, module) {
4
- return (module = {
5
- exports: {}
6
- }, fn(module, module.exports), module.exports);
7
- }
8
- var classnames = createCommonjsModule(function (module) {
9
- (function () {
10
- var hasOwn = ({}).hasOwnProperty;
11
- function classNames() {
12
- var classes = [];
13
- for (var i = 0; i < arguments.length; i++) {
14
- var arg = arguments[i];
15
- if (!arg) continue;
16
- var argType = typeof arg;
17
- if (argType === 'string' || argType === 'number') {
18
- classes.push(arg);
19
- } else if (Array.isArray(arg) && arg.length) {
20
- var inner = classNames.apply(null, arg);
21
- if (inner) {
22
- classes.push(inner);
23
- }
24
- } else if (argType === 'object') {
25
- for (var key in arg) {
26
- if (hasOwn.call(arg, key) && arg[key]) {
27
- classes.push(key);
28
- }
29
- }
30
- }
31
- }
32
- return classes.join(' ');
33
- }
34
- if (module.exports) {
35
- classNames.default = classNames;
36
- module.exports = classNames;
37
- } else {
38
- window.classNames = classNames;
39
- }
40
- })();
41
- });
42
- const React = _dll_react;
43
- const ReactDOM = _dll_react_dom;
44
- const PropTypes = _dll_prop_types;
45
- const {renderMath: renderMath} = _dll_pie_lib__math_rendering;
46
- const {withStyles: withStyles} = _dll_material_ui__core_styles;
47
- const {isEqual: isEqual} = _dll_lodash;
48
- const {isEmpty: isEmpty} = _dll_lodash;
49
- const EditableHtml = _dll_pie_lib__editable_html;
50
- const _jsxFileName = "/home/ede/dev/github/pie-framework/pie-elements/packages/inline-dropdown/configure/src/inline-dropdown-toolbar.jsx";
51
- class MenuItemComp extends React.Component {
52
- constructor(...args) {
53
- super(...args);
54
- MenuItemComp.prototype.__init.call(this);
55
- }
56
- static __initStatic() {
57
- this.propTypes = {
58
- classes: PropTypes.object.isRequired,
59
- correct: PropTypes.bool.isRequired,
60
- onClick: PropTypes.func.isRequired,
61
- onRemoveChoice: PropTypes.func.isRequired,
62
- value: PropTypes.string.isRequired
63
- };
64
- }
65
- __init() {
66
- this.onRemoveClick = e => {
67
- const {onRemoveChoice} = this.props;
68
- e.preventDefault();
69
- e.stopPropagation();
70
- onRemoveChoice();
71
- };
72
- }
73
- render() {
74
- const {classes, correct, onClick, value} = this.props;
75
- return React.createElement('div', {
76
- className: classnames(classes.wrapper, {
77
- [classes.correct]: correct
78
- }),
79
- onClick: onClick,
80
- __self: this,
81
- __source: {
82
- fileName: _jsxFileName,
83
- lineNumber: 33
84
- }
85
- }, React.createElement('div', {
86
- className: classes.valueHolder,
87
- dangerouslySetInnerHTML: {
88
- __html: value
89
- },
90
- __self: this,
91
- __source: {
92
- fileName: _jsxFileName,
93
- lineNumber: 34
94
- }
95
- }), React.createElement('i', {
96
- className: classes.removeIcon,
97
- onClick: this.onRemoveClick,
98
- __self: this,
99
- __source: {
100
- fileName: _jsxFileName,
101
- lineNumber: 40
102
- }
103
- }, "x"));
104
- }
105
- }
106
- MenuItemComp.__initStatic();
107
- const MenuItem = withStyles({
108
- wrapper: {
109
- background: '#fff',
110
- borderBottom: '1px solid black',
111
- boxSizing: 'border-box',
112
- display: 'block',
113
- cursor: 'pointer',
114
- lineHeight: '30px',
115
- padding: '10px 25px 10px 10px',
116
- position: 'relative'
117
- },
118
- correct: {
119
- background: '#C4DCFA'
120
- },
121
- removeIcon: {
122
- cursor: 'pointer',
123
- fontSize: '20px',
124
- fontStyle: 'normal',
125
- position: 'absolute',
126
- transform: 'translate(0, -50%)',
127
- top: '50%',
128
- right: '5px',
129
- zIndex: 3
130
- },
131
- valueHolder: {
132
- wordBreak: 'break-all'
133
- }
134
- })(MenuItemComp);
135
- const findSlateNode = key => {
136
- return window.document.querySelector('[data-key="' + key + '"]');
137
- };
138
- const createElementFromHTML = htmlString => {
139
- const div = document.createElement('div');
140
- div.innerHTML = (htmlString || '').trim();
141
- return div;
142
- };
143
- class RespAreaToolbar extends React.Component {
144
- constructor(...args2) {
145
- super(...args2);
146
- RespAreaToolbar.prototype.__init2.call(this);
147
- RespAreaToolbar.prototype.__init3.call(this);
148
- RespAreaToolbar.prototype.__init4.call(this);
149
- RespAreaToolbar.prototype.__init5.call(this);
150
- RespAreaToolbar.prototype.__init6.call(this);
151
- RespAreaToolbar.prototype.__init7.call(this);
152
- RespAreaToolbar.prototype.__init8.call(this);
153
- }
154
- static __initStatic2() {
155
- this.propTypes = {
156
- classes: PropTypes.object,
157
- node: PropTypes.object,
158
- onDone: PropTypes.func,
159
- choices: PropTypes.array,
160
- onAddChoice: PropTypes.func.isRequired,
161
- onRemoveChoice: PropTypes.func.isRequired,
162
- onSelectChoice: PropTypes.func.isRequired,
163
- onToolbarDone: PropTypes.func.isRequired,
164
- value: PropTypes.shape({
165
- change: PropTypes.func.isRequired,
166
- document: PropTypes.shape({
167
- getNextText: PropTypes.func.isRequired
168
- })
169
- })
170
- };
171
- }
172
- __init2() {
173
- this.state = {
174
- respAreaMarkup: ''
175
- };
176
- }
177
- componentDidMount() {
178
- const {node} = this.props;
179
- const domNode = findSlateNode(node.key);
180
- if (domNode) {
181
- const domNodeRect = domNode.getBoundingClientRect();
182
- const editor = domNode.closest('[data-slate-editor]');
183
- const editorRect = editor.getBoundingClientRect();
184
- const top = domNodeRect.top - editorRect.top;
185
- const left = domNodeRect.left - editorRect.left;
186
- this.setState({
187
- toolbarStyle: {
188
- position: 'absolute',
189
- top: `${top + domNodeRect.height + 60}px`,
190
- left: `${left + 25}px`,
191
- width: domNodeRect.width
192
- }
193
- });
194
- }
195
- }
196
- componentDidUpdate() {
197
- const domNode = ReactDOM.findDOMNode(this);
198
- renderMath(domNode);
199
- }
200
- __init3() {
201
- this.onRespAreaChange = respAreaMarkup => {
202
- this.setState({
203
- respAreaMarkup
204
- });
205
- };
206
- }
207
- __init4() {
208
- this.onAddChoice = () => {
209
- if (this.editorRef) {
210
- this.editorRef.finishEditing();
211
- }
212
- };
213
- }
214
- __init5() {
215
- this.onDone = val => {
216
- const {node, onAddChoice} = this.props;
217
- const onlyText = createElementFromHTML(val).textContent;
218
- if (!isEmpty(onlyText)) {
219
- onAddChoice(node.data.get('index'), val);
220
- }
221
- };
222
- }
223
- __init6() {
224
- this.onSelectChoice = (newValue, index) => {
225
- const {node, value, onToolbarDone, onSelectChoice} = this.props;
226
- const update = {
227
- ...node.data.toJSON(),
228
- value: newValue
229
- };
230
- const change = value.change().setNodeByKey(node.key, {
231
- data: update
232
- });
233
- const nextText = value.document.getNextText(node.key);
234
- change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);
235
- onToolbarDone(change, false);
236
- onSelectChoice(index);
237
- };
238
- }
239
- __init7() {
240
- this.onRemoveChoice = (val, index) => {
241
- const {node, value, onToolbarDone, onRemoveChoice} = this.props;
242
- if (isEqual(val, node.data.get('value'))) {
243
- const update = {
244
- ...node.data.toJSON(),
245
- value: null
246
- };
247
- const change = value.change().setNodeByKey(node.key, {
248
- data: update
249
- });
250
- onToolbarDone(change, false);
251
- }
252
- onRemoveChoice(index);
253
- };
254
- }
255
- __init8() {
256
- this.onKeyDown = event => {
257
- if (event.key === 'Enter') {
258
- this.onAddChoice();
259
- return false;
260
- }
261
- };
262
- }
263
- render() {
264
- const {classes, choices} = this.props;
265
- const {respAreaMarkup, toolbarStyle} = this.state;
266
- if (!toolbarStyle) {
267
- return null;
268
- }
269
- return React.createElement('div', {
270
- style: {
271
- ...toolbarStyle,
272
- backgroundColor: '#E0E1E6'
273
- },
274
- __self: this,
275
- __source: {
276
- fileName: _jsxFileName,
277
- lineNumber: 205
278
- }
279
- }, React.createElement('div', {
280
- className: classes.itemBuilder,
281
- __self: this,
282
- __source: {
283
- fileName: _jsxFileName,
284
- lineNumber: 211
285
- }
286
- }, React.createElement(EditableHtml, {
287
- ref: ref => {
288
- if (ref) {
289
- this.editorRef = ref;
290
- }
291
- },
292
- autoFocus: true,
293
- autoSave: true,
294
- className: classes.respArea,
295
- toolbarOpts: {
296
- position: 'top',
297
- alwaysVisible: false,
298
- showDone: false,
299
- doneOn: 'custom'
300
- },
301
- markup: respAreaMarkup,
302
- onKeyDown: this.onKeyDown,
303
- onChange: this.onRespAreaChange,
304
- onDone: this.onDone,
305
- placeholder: "Add Choice",
306
- __self: this,
307
- __source: {
308
- fileName: _jsxFileName,
309
- lineNumber: 212
310
- }
311
- }), React.createElement('i', {
312
- style: {
313
- cursor: 'pointer',
314
- fontSize: '20px',
315
- fontStyle: 'normal',
316
- position: 'absolute',
317
- top: '50%',
318
- right: '15px',
319
- transform: 'translate(0, -50%)'
320
- },
321
- contentEditable: false,
322
- onMouseDown: () => this.onAddChoice(),
323
- __self: this,
324
- __source: {
325
- fileName: _jsxFileName,
326
- lineNumber: 233
327
- }
328
- }, "+")), choices && React.createElement('div', {
329
- className: classes.choicesHolder,
330
- __self: this,
331
- __source: {
332
- fileName: _jsxFileName,
333
- lineNumber: 250
334
- }
335
- }, choices.map(({label, correct}, index) => React.createElement(MenuItem, {
336
- key: index,
337
- onClick: () => this.onSelectChoice(label, index),
338
- onRemoveChoice: () => this.onRemoveChoice(label, index),
339
- value: label,
340
- correct: correct,
341
- __self: this,
342
- __source: {
343
- fileName: _jsxFileName,
344
- lineNumber: 252
345
- }
346
- }))));
347
- }
348
- }
349
- RespAreaToolbar.__initStatic2();
350
- const StyledRespAreaToolbar = withStyles({
351
- respArea: {
352
- backgroundColor: '#fff',
353
- '& [data-slate-editor="true"]': {
354
- minHeight: 'initial !important'
355
- }
356
- },
357
- choicesHolder: {
358
- display: 'flex',
359
- flexDirection: 'column',
360
- '& > div:last-child': {
361
- border: 'none'
362
- }
363
- },
364
- itemBuilder: {
365
- padding: '8px',
366
- position: 'relative'
367
- }
368
- })(RespAreaToolbar);
369
- const React$1 = _dll_react;
370
- const ReactDOM$1 = _dll_react_dom;
371
- const PropTypes$1 = _dll_prop_types;
372
- const {renderMath: renderMath$1} = _dll_pie_lib__math_rendering;
373
- const {cloneDeep: cloneDeep} = _dll_lodash;
374
- const {isEqual: isEqual$1} = _dll_lodash;
375
- const {isUndefined: isUndefined} = _dll_lodash;
376
- const {isEmpty: isEmpty$1} = _dll_lodash;
377
- const {reduce: reduce} = _dll_lodash;
378
- const {max: max} = _dll_lodash;
379
- const {withStyles: withStyles$1} = _dll_material_ui__core_styles;
380
- const {Button: Button} = _dll_material_ui__core;
381
- const {Dialog: Dialog} = _dll_material_ui__core;
382
- const {DialogTitle: DialogTitle} = _dll_material_ui__core;
383
- const {DialogActions: DialogActions} = _dll_material_ui__core;
384
- const {Typography: Typography} = _dll_material_ui__core;
385
- const EditableHtml$1 = _dll_pie_lib__editable_html;
386
- const {ALL_PLUGINS: ALL_PLUGINS} = _dll_pie_lib__editable_html;
387
- const {InputContainer: InputContainer} = _dll_pie_lib__config_ui;
388
- const {layout: layout} = _dll_pie_lib__config_ui;
389
- const {settings: settings} = _dll_pie_lib__config_ui;
390
- const _jsxFileName$1 = "/home/ede/dev/github/pie-framework/pie-elements/packages/inline-dropdown/configure/src/main.jsx";
391
- const {toggle, Panel} = settings;
392
- const InfoDialog = ({open, onCancel, onOk, title}) => React$1.createElement(Dialog, {
393
- open: open,
394
- __self: undefined,
395
- __source: {
396
- fileName: _jsxFileName$1,
397
- lineNumber: 25
398
- }
399
- }, React$1.createElement(DialogTitle, {
400
- __self: undefined,
401
- __source: {
402
- fileName: _jsxFileName$1,
403
- lineNumber: 26
404
- }
405
- }, title), React$1.createElement(DialogActions, {
406
- __self: undefined,
407
- __source: {
408
- fileName: _jsxFileName$1,
409
- lineNumber: 27
410
- }
411
- }, onOk && React$1.createElement(Button, {
412
- onClick: onOk,
413
- color: "primary",
414
- __self: undefined,
415
- __source: {
416
- fileName: _jsxFileName$1,
417
- lineNumber: 29
418
- }
419
- }, "OK"), onCancel && React$1.createElement(Button, {
420
- onClick: onCancel,
421
- color: "primary",
422
- __self: undefined,
423
- __source: {
424
- fileName: _jsxFileName$1,
425
- lineNumber: 34
426
- }
427
- }, "Cancel")));
428
- InfoDialog.propTypes = {
429
- open: PropTypes$1.bool,
430
- onCancel: PropTypes$1.func,
431
- onOk: PropTypes$1.func,
432
- title: PropTypes$1.string
433
- };
434
- const styles = theme => ({
435
- promptHolder: {
436
- width: '100%',
437
- paddingBottom: theme.spacing.unit * 2,
438
- marginBottom: theme.spacing.unit * 2
439
- },
440
- prompt: {
441
- paddingTop: theme.spacing.unit * 2,
442
- width: '100%'
443
- },
444
- markup: {
445
- minHeight: '100px',
446
- paddingTop: theme.spacing.unit * 2,
447
- width: '100%',
448
- '& [data-slate-editor="true"]': {
449
- minHeight: '100px'
450
- }
451
- },
452
- design: {
453
- paddingTop: theme.spacing.unit * 3
454
- },
455
- choiceConfiguration: {
456
- paddingTop: theme.spacing.unit * 2,
457
- paddingBottom: theme.spacing.unit * 2
458
- },
459
- switchElement: {
460
- justifyContent: 'space-between',
461
- margin: 0
462
- },
463
- addButton: {
464
- float: 'right'
465
- },
466
- text: {
467
- fontFamily: 'Cerebri Sans',
468
- fontSize: '16px',
469
- lineHeight: '19px',
470
- color: '#495B8F'
471
- }
472
- });
473
- const createElementFromHTML$1 = htmlString => {
474
- const div = document.createElement('div');
475
- div.innerHTML = htmlString.trim();
476
- return div;
477
- };
478
- const prepareVal = html => {
479
- const tmp = document.createElement('DIV');
480
- tmp.innerHTML = html;
481
- const value = tmp.textContent || tmp.innerText || '';
482
- return value.trim();
483
- };
484
- class Main extends React$1.Component {
485
- constructor(...args) {
486
- super(...args);
487
- Main.prototype.__init.call(this);
488
- Main.prototype.__init2.call(this);
489
- Main.prototype.__init3.call(this);
490
- Main.prototype.__init4.call(this);
491
- Main.prototype.__init5.call(this);
492
- Main.prototype.__init6.call(this);
493
- Main.prototype.__init7.call(this);
494
- Main.prototype.__init8.call(this);
495
- Main.prototype.__init9.call(this);
496
- Main.prototype.__init10.call(this);
497
- }
498
- static __initStatic() {
499
- this.propTypes = {
500
- configuration: PropTypes$1.object.isRequired,
501
- model: PropTypes$1.object.isRequired,
502
- disableSidePanel: PropTypes$1.bool,
503
- onModelChanged: PropTypes$1.func.isRequired,
504
- onConfigurationChanged: PropTypes$1.func.isRequired,
505
- classes: PropTypes$1.object.isRequired,
506
- imageSupport: PropTypes$1.shape({
507
- add: PropTypes$1.func.isRequired,
508
- delete: PropTypes$1.func.isRequired
509
- })
510
- };
511
- }
512
- __init() {
513
- this.state = {
514
- dialog: {
515
- open: false
516
- }
517
- };
518
- }
519
- componentDidMount() {
520
- const {model: {choices}} = this.props;
521
- this.setState({
522
- respAreaChoices: cloneDeep(choices)
523
- });
524
- }
525
- UNSAFE_componentWillReceiveProps(nProps) {
526
- const newState = {};
527
- if (!isEqual$1(nProps.model.choices, this.props.model.choices) || !isEqual$1(nProps.model.choices, this.state.respAreaChoices)) {
528
- newState.respAreaChoices = cloneDeep(nProps.model.choices);
529
- }
530
- if (!isEmpty$1(newState)) {
531
- this.setState(newState);
532
- }
533
- }
534
- componentDidUpdate() {
535
- const domNode = ReactDOM$1.findDOMNode(this);
536
- renderMath$1(domNode);
537
- }
538
- __init2() {
539
- this.onModelChange = newVal => {
540
- this.props.onModelChanged({
541
- ...this.props.model,
542
- ...newVal
543
- });
544
- };
545
- }
546
- __init3() {
547
- this.onPromptChanged = prompt => {
548
- this.onModelChange({
549
- prompt
550
- });
551
- };
552
- }
553
- __init4() {
554
- this.onRationaleChanged = rationale => {
555
- this.onModelChange({
556
- rationale
557
- });
558
- };
559
- }
560
- __init5() {
561
- this.onTeacherInstructionsChanged = teacherInstructions => {
562
- this.onModelChange({
563
- teacherInstructions
564
- });
565
- };
566
- }
567
- __init6() {
568
- this.onMarkupChanged = slateMarkup => {
569
- this.onModelChange({
570
- slateMarkup
571
- });
572
- };
573
- }
574
- __init7() {
575
- this.onChange = markup => {
576
- const {respAreaChoices} = this.state;
577
- const domMarkup = createElementFromHTML$1(markup);
578
- const allRespAreas = domMarkup.querySelectorAll('[data-type="inline_dropdown"]');
579
- const allChoices = {};
580
- allRespAreas.forEach(el => {
581
- allChoices[el.dataset.index] = el.dataset.value || '';
582
- });
583
- const existingRespAreaChoices = reduce(respAreaChoices, (obj, choices, key) => {
584
- if (!isUndefined(allChoices[key])) {
585
- obj[key] = respAreaChoices[key];
586
- }
587
- return obj;
588
- }, {});
589
- const newRespAreaChoices = {};
590
- let shouldWarn = false;
591
- allRespAreas.forEach((el, index) => {
592
- const newChoices = existingRespAreaChoices[el.dataset.index] || [];
593
- if (newChoices.length < 2 || !newChoices.find(c => c.correct)) {
594
- el.remove();
595
- shouldWarn = true;
596
- } else {
597
- newRespAreaChoices[index] = existingRespAreaChoices[el.dataset.index] || [];
598
- el.dataset.index = index;
599
- }
600
- });
601
- if (shouldWarn) {
602
- this.setState({
603
- dialog: {
604
- open: true,
605
- message: 'Response areas with under 2 options or with no correct answers will be discarded',
606
- onOk: () => {
607
- this.setState({
608
- dialog: {
609
- open: false
610
- }
611
- }, () => this.onModelChange({
612
- choices: cloneDeep(newRespAreaChoices),
613
- slateMarkup: domMarkup.innerHTML
614
- }));
615
- },
616
- onCancel: () => this.setState({
617
- dialog: {
618
- open: false
619
- }
620
- })
621
- }
622
- });
623
- } else {
624
- this.onModelChange({
625
- choices: cloneDeep(newRespAreaChoices),
626
- slateMarkup: domMarkup.innerHTML
627
- });
628
- }
629
- };
630
- }
631
- __init8() {
632
- this.onAddChoice = (index, label) => {
633
- const {respAreaChoices} = this.state;
634
- if (!respAreaChoices[index]) {
635
- respAreaChoices[index] = [];
636
- }
637
- if ((respAreaChoices[index] || []).find(r => prepareVal(r.label) === prepareVal(label))) {
638
- this.setState({
639
- dialog: {
640
- open: true,
641
- message: 'Duplicate answers are not allowed.',
642
- onOk: () => {
643
- this.setState({
644
- dialog: {
645
- open: false
646
- }
647
- });
648
- }
649
- }
650
- });
651
- return;
652
- }
653
- const value = respAreaChoices[index] && max(respAreaChoices[index].map(c => parseInt(c.value)).filter(val => !isNaN(val))) || 0;
654
- respAreaChoices[index].push({
655
- label,
656
- value: `${value + 1}`,
657
- correct: false
658
- });
659
- this.onModelChange({
660
- choices: cloneDeep(respAreaChoices)
661
- });
662
- };
663
- }
664
- __init9() {
665
- this.onRemoveChoice = (respIndex, index) => {
666
- const {respAreaChoices} = this.state;
667
- respAreaChoices[respIndex].splice(index, 1);
668
- this.onModelChange({
669
- choices: cloneDeep(respAreaChoices)
670
- });
671
- };
672
- }
673
- __init10() {
674
- this.onSelectChoice = (respIndex, selectedIndex) => {
675
- const {respAreaChoices} = this.state;
676
- respAreaChoices[respIndex] = respAreaChoices[respIndex].map((ch, index) => ({
677
- ...ch,
678
- correct: index === selectedIndex
679
- }));
680
- this.onModelChange({
681
- choices: cloneDeep(respAreaChoices)
682
- });
683
- };
684
- }
685
- render() {
686
- const {dialog} = this.state;
687
- const {classes, model, configuration, onConfigurationChanged, imageSupport} = this.props;
688
- const {prompt = {}, partialScoring = {}, lockChoiceOrder = {}, rationale = {}, teacherInstructions = {}} = configuration || ({});
689
- const {rationaleEnabled, promptEnabled, teacherInstructionsEnabled} = model || ({});
690
- return React$1.createElement('div', {
691
- className: classes.design,
692
- __self: this,
693
- __source: {
694
- fileName: _jsxFileName$1,
695
- lineNumber: 335
696
- }
697
- }, React$1.createElement(layout.ConfigLayout, {
698
- settings: React$1.createElement(Panel, {
699
- model: model,
700
- configuration: configuration,
701
- onChangeModel: model => this.onModelChange(model),
702
- onChangeConfiguration: configuration => onConfigurationChanged(configuration, true),
703
- groups: {
704
- Settings: {
705
- partialScoring: partialScoring.settings && toggle(partialScoring.label),
706
- lockChoiceOrder: lockChoiceOrder.settings && toggle(lockChoiceOrder.label)
707
- },
708
- Properties: {
709
- teacherInstructionsEnabled: teacherInstructions.settings && toggle(teacherInstructions.label),
710
- rationaleEnabled: rationale.settings && toggle(rationale.label),
711
- promptEnabled: prompt.settings && toggle(prompt.label)
712
- }
713
- },
714
- __self: this,
715
- __source: {
716
- fileName: _jsxFileName$1,
717
- lineNumber: 338
718
- }
719
- }),
720
- __self: this,
721
- __source: {
722
- fileName: _jsxFileName$1,
723
- lineNumber: 336
724
- }
725
- }, React$1.createElement('div', {
726
- __self: this,
727
- __source: {
728
- fileName: _jsxFileName$1,
729
- lineNumber: 364
730
- }
731
- }, teacherInstructionsEnabled && React$1.createElement(InputContainer, {
732
- label: teacherInstructions.label,
733
- className: classes.promptHolder,
734
- __self: this,
735
- __source: {
736
- fileName: _jsxFileName$1,
737
- lineNumber: 366
738
- }
739
- }, React$1.createElement(EditableHtml$1, {
740
- className: classes.prompt,
741
- markup: model.teacherInstructions || '',
742
- onChange: this.onTeacherInstructionsChanged,
743
- imageSupport: imageSupport,
744
- nonEmpty: false,
745
- __self: this,
746
- __source: {
747
- fileName: _jsxFileName$1,
748
- lineNumber: 370
749
- }
750
- })), promptEnabled && React$1.createElement(InputContainer, {
751
- label: prompt.label,
752
- className: classes.promptHolder,
753
- __self: this,
754
- __source: {
755
- fileName: _jsxFileName$1,
756
- lineNumber: 381
757
- }
758
- }, React$1.createElement(EditableHtml$1, {
759
- className: classes.prompt,
760
- markup: model.prompt,
761
- onChange: this.onPromptChanged,
762
- imageSupport: imageSupport,
763
- nonEmpty: false,
764
- disableUnderline: true,
765
- __self: this,
766
- __source: {
767
- fileName: _jsxFileName$1,
768
- lineNumber: 385
769
- }
770
- })), rationaleEnabled && React$1.createElement(InputContainer, {
771
- label: rationale.label,
772
- className: classes.promptHolder,
773
- __self: this,
774
- __source: {
775
- fileName: _jsxFileName$1,
776
- lineNumber: 397
777
- }
778
- }, React$1.createElement(EditableHtml$1, {
779
- className: classes.prompt,
780
- markup: model.rationale || '',
781
- onChange: this.onRationaleChanged,
782
- imageSupport: imageSupport,
783
- __self: this,
784
- __source: {
785
- fileName: _jsxFileName$1,
786
- lineNumber: 401
787
- }
788
- })), React$1.createElement(Typography, {
789
- className: classes.text,
790
- __self: this,
791
- __source: {
792
- fileName: _jsxFileName$1,
793
- lineNumber: 410
794
- }
795
- }, "Define Template, Choices, and Correct Responses"), React$1.createElement(InfoDialog, {
796
- open: dialog.open,
797
- title: dialog.message,
798
- onCancel: dialog.onCancel,
799
- onOk: dialog.onOk,
800
- __self: this,
801
- __source: {
802
- fileName: _jsxFileName$1,
803
- lineNumber: 413
804
- }
805
- }), React$1.createElement(EditableHtml$1, {
806
- activePlugins: ALL_PLUGINS,
807
- toolbarOpts: {
808
- position: 'top'
809
- },
810
- responseAreaProps: {
811
- type: 'inline-dropdown',
812
- options: {
813
- duplicates: true
814
- },
815
- respAreaToolbar: (node, value, onToolbarDone) => {
816
- const {respAreaChoices} = this.state;
817
- return () => React$1.createElement(StyledRespAreaToolbar, {
818
- onAddChoice: this.onAddChoice,
819
- onRemoveChoice: index => this.onRemoveChoice(node.data.get('index'), index),
820
- onSelectChoice: index => this.onSelectChoice(node.data.get('index'), index),
821
- node: node,
822
- value: value,
823
- onToolbarDone: onToolbarDone,
824
- choices: respAreaChoices[node.data.get('index')],
825
- __self: this,
826
- __source: {
827
- fileName: _jsxFileName$1,
828
- lineNumber: 431
829
- }
830
- });
831
- }
832
- },
833
- className: classes.markup,
834
- markup: model.slateMarkup || '',
835
- onChange: this.onChange,
836
- imageSupport: imageSupport,
837
- onBlur: this.onBlur,
838
- disabled: false,
839
- highlightShape: false,
840
- __self: this,
841
- __source: {
842
- fileName: _jsxFileName$1,
843
- lineNumber: 419
844
- }
845
- }))));
846
- }
847
- }
848
- Main.__initStatic();
849
- const Styled = withStyles$1(styles)(Main);
850
- var s = 1000;
851
- var m = s * 60;
852
- var h = m * 60;
853
- var d = h * 24;
854
- var w = d * 7;
855
- var y = d * 365.25;
856
- var ms = function (val, options) {
857
- options = options || ({});
858
- var type = typeof val;
859
- if (type === 'string' && val.length > 0) {
860
- return parse(val);
861
- } else if (type === 'number' && isFinite(val)) {
862
- return options.long ? fmtLong(val) : fmtShort(val);
863
- }
864
- throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
865
- };
866
- function parse(str) {
867
- str = String(str);
868
- if (str.length > 100) {
869
- return;
870
- }
871
- var match = (/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i).exec(str);
872
- if (!match) {
873
- return;
874
- }
875
- var n = parseFloat(match[1]);
876
- var type = (match[2] || 'ms').toLowerCase();
877
- switch (type) {
878
- case 'years':
879
- case 'year':
880
- case 'yrs':
881
- case 'yr':
882
- case 'y':
883
- return n * y;
884
- case 'weeks':
885
- case 'week':
886
- case 'w':
887
- return n * w;
888
- case 'days':
889
- case 'day':
890
- case 'd':
891
- return n * d;
892
- case 'hours':
893
- case 'hour':
894
- case 'hrs':
895
- case 'hr':
896
- case 'h':
897
- return n * h;
898
- case 'minutes':
899
- case 'minute':
900
- case 'mins':
901
- case 'min':
902
- case 'm':
903
- return n * m;
904
- case 'seconds':
905
- case 'second':
906
- case 'secs':
907
- case 'sec':
908
- case 's':
909
- return n * s;
910
- case 'milliseconds':
911
- case 'millisecond':
912
- case 'msecs':
913
- case 'msec':
914
- case 'ms':
915
- return n;
916
- default:
917
- return undefined;
918
- }
919
- }
920
- function fmtShort(ms) {
921
- var msAbs = Math.abs(ms);
922
- if (msAbs >= d) {
923
- return Math.round(ms / d) + 'd';
924
- }
925
- if (msAbs >= h) {
926
- return Math.round(ms / h) + 'h';
927
- }
928
- if (msAbs >= m) {
929
- return Math.round(ms / m) + 'm';
930
- }
931
- if (msAbs >= s) {
932
- return Math.round(ms / s) + 's';
933
- }
934
- return ms + 'ms';
935
- }
936
- function fmtLong(ms) {
937
- var msAbs = Math.abs(ms);
938
- if (msAbs >= d) {
939
- return plural(ms, msAbs, d, 'day');
940
- }
941
- if (msAbs >= h) {
942
- return plural(ms, msAbs, h, 'hour');
943
- }
944
- if (msAbs >= m) {
945
- return plural(ms, msAbs, m, 'minute');
946
- }
947
- if (msAbs >= s) {
948
- return plural(ms, msAbs, s, 'second');
949
- }
950
- return ms + ' ms';
951
- }
952
- function plural(ms, msAbs, n, name) {
953
- var isPlural = msAbs >= n * 1.5;
954
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
955
- }
956
- function setup(env) {
957
- createDebug.debug = createDebug;
958
- createDebug.default = createDebug;
959
- createDebug.coerce = coerce;
960
- createDebug.disable = disable;
961
- createDebug.enable = enable;
962
- createDebug.enabled = enabled;
963
- createDebug.humanize = ms;
964
- Object.keys(env).forEach(function (key) {
965
- createDebug[key] = env[key];
966
- });
967
- createDebug.instances = [];
968
- createDebug.names = [];
969
- createDebug.skips = [];
970
- createDebug.formatters = {};
971
- function selectColor(namespace) {
972
- var hash = 0;
973
- for (var i = 0; i < namespace.length; i++) {
974
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
975
- hash |= 0;
976
- }
977
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
978
- }
979
- createDebug.selectColor = selectColor;
980
- function createDebug(namespace) {
981
- var prevTime;
982
- function debug() {
983
- if (!debug.enabled) {
984
- return;
985
- }
986
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
987
- args[_key] = arguments[_key];
988
- }
989
- var self = debug;
990
- var curr = Number(new Date());
991
- var ms = curr - (prevTime || curr);
992
- self.diff = ms;
993
- self.prev = prevTime;
994
- self.curr = curr;
995
- prevTime = curr;
996
- args[0] = createDebug.coerce(args[0]);
997
- if (typeof args[0] !== 'string') {
998
- args.unshift('%O');
999
- }
1000
- var index = 0;
1001
- args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
1002
- if (match === '%%') {
1003
- return match;
1004
- }
1005
- index++;
1006
- var formatter = createDebug.formatters[format];
1007
- if (typeof formatter === 'function') {
1008
- var val = args[index];
1009
- match = formatter.call(self, val);
1010
- args.splice(index, 1);
1011
- index--;
1012
- }
1013
- return match;
1014
- });
1015
- createDebug.formatArgs.call(self, args);
1016
- var logFn = self.log || createDebug.log;
1017
- logFn.apply(self, args);
1018
- }
1019
- debug.namespace = namespace;
1020
- debug.enabled = createDebug.enabled(namespace);
1021
- debug.useColors = createDebug.useColors();
1022
- debug.color = selectColor(namespace);
1023
- debug.destroy = destroy;
1024
- debug.extend = extend;
1025
- if (typeof createDebug.init === 'function') {
1026
- createDebug.init(debug);
1027
- }
1028
- createDebug.instances.push(debug);
1029
- return debug;
1030
- }
1031
- function destroy() {
1032
- var index = createDebug.instances.indexOf(this);
1033
- if (index !== -1) {
1034
- createDebug.instances.splice(index, 1);
1035
- return true;
1036
- }
1037
- return false;
1038
- }
1039
- function extend(namespace, delimiter) {
1040
- return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
1041
- }
1042
- function enable(namespaces) {
1043
- createDebug.save(namespaces);
1044
- createDebug.names = [];
1045
- createDebug.skips = [];
1046
- var i;
1047
- var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
1048
- var len = split.length;
1049
- for (i = 0; i < len; i++) {
1050
- if (!split[i]) {
1051
- continue;
1052
- }
1053
- namespaces = split[i].replace(/\*/g, '.*?');
1054
- if (namespaces[0] === '-') {
1055
- createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
1056
- } else {
1057
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
1058
- }
1059
- }
1060
- for (i = 0; i < createDebug.instances.length; i++) {
1061
- var instance = createDebug.instances[i];
1062
- instance.enabled = createDebug.enabled(instance.namespace);
1063
- }
1064
- }
1065
- function disable() {
1066
- createDebug.enable('');
1067
- }
1068
- function enabled(name) {
1069
- if (name[name.length - 1] === '*') {
1070
- return true;
1071
- }
1072
- var i;
1073
- var len;
1074
- for ((i = 0, len = createDebug.skips.length); i < len; i++) {
1075
- if (createDebug.skips[i].test(name)) {
1076
- return false;
1077
- }
1078
- }
1079
- for ((i = 0, len = createDebug.names.length); i < len; i++) {
1080
- if (createDebug.names[i].test(name)) {
1081
- return true;
1082
- }
1083
- }
1084
- return false;
1085
- }
1086
- function coerce(val) {
1087
- if (val instanceof Error) {
1088
- return val.stack || val.message;
1089
- }
1090
- return val;
1091
- }
1092
- createDebug.enable(createDebug.load());
1093
- return createDebug;
1094
- }
1095
- var common = setup;
1096
- var browser = createCommonjsModule(function (module, exports) {
1097
- function _typeof(obj) {
1098
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
1099
- _typeof = function _typeof(obj) {
1100
- return typeof obj;
1101
- };
1102
- } else {
1103
- _typeof = function _typeof(obj) {
1104
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
1105
- };
1106
- }
1107
- return _typeof(obj);
1108
- }
1109
- exports.log = log;
1110
- exports.formatArgs = formatArgs;
1111
- exports.save = save;
1112
- exports.load = load;
1113
- exports.useColors = useColors;
1114
- exports.storage = localstorage();
1115
- exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
1116
- function useColors() {
1117
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
1118
- return true;
1119
- }
1120
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
1121
- return false;
1122
- }
1123
- return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
1124
- }
1125
- function formatArgs(args) {
1126
- args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
1127
- if (!this.useColors) {
1128
- return;
1129
- }
1130
- var c = 'color: ' + this.color;
1131
- args.splice(1, 0, c, 'color: inherit');
1132
- var index = 0;
1133
- var lastC = 0;
1134
- args[0].replace(/%[a-zA-Z%]/g, function (match) {
1135
- if (match === '%%') {
1136
- return;
1137
- }
1138
- index++;
1139
- if (match === '%c') {
1140
- lastC = index;
1141
- }
1142
- });
1143
- args.splice(lastC, 0, c);
1144
- }
1145
- function log() {
1146
- var _console;
1147
- return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
1148
- }
1149
- function save(namespaces) {
1150
- try {
1151
- if (namespaces) {
1152
- exports.storage.setItem('debug', namespaces);
1153
- } else {
1154
- exports.storage.removeItem('debug');
1155
- }
1156
- } catch (error) {}
1157
- }
1158
- function load() {
1159
- var r;
1160
- try {
1161
- r = exports.storage.getItem('debug');
1162
- } catch (error) {}
1163
- if (!r && typeof process !== 'undefined' && ('env' in process)) {
1164
- r = process.env.DEBUG;
1165
- }
1166
- return r;
1167
- }
1168
- function localstorage() {
1169
- try {
1170
- return localStorage;
1171
- } catch (error) {}
1172
- }
1173
- module.exports = common(exports);
1174
- var formatters = module.exports.formatters;
1175
- formatters.j = function (v) {
1176
- try {
1177
- return JSON.stringify(v);
1178
- } catch (error) {
1179
- return '[UnexpectedJSONParseError]: ' + error.message;
1180
- }
1181
- };
1182
- });
1183
- browser.log;
1184
- browser.formatArgs;
1185
- browser.save;
1186
- browser.load;
1187
- browser.useColors;
1188
- browser.storage;
1189
- browser.colors;
1190
- var sensibleDefaults = {
1191
- model: {
1192
- disabled: false,
1193
- mode: 'gather',
1194
- prompt: 'Use the dropdowns to complete the sentence',
1195
- shuffle: true,
1196
- markup: '',
1197
- choices: {},
1198
- alternateResponse: {},
1199
- promptEnabled: true,
1200
- rationaleEnabled: true,
1201
- teacherInstructionsEnabled: true,
1202
- studentInstructionsEnabled: true
1203
- },
1204
- configuration: {
1205
- prompt: {
1206
- settings: true,
1207
- label: 'Prompt'
1208
- },
1209
- lockChoiceOrder: {
1210
- settings: true,
1211
- label: 'Lock Choice Order'
1212
- },
1213
- partialScoring: {
1214
- settings: false,
1215
- label: 'Allow Partial Scoring'
1216
- },
1217
- rationale: {
1218
- settings: true,
1219
- label: 'Rationale'
1220
- },
1221
- teacherInstructions: {
1222
- settings: true,
1223
- label: 'Teacher Instructions'
1224
- }
1225
- }
1226
- };
1227
- const {escape: escape} = _dll_lodash;
1228
- const removeUnwantedCharacters = markup => markup.replace(/(\t+(?!imes))|(\n)|(\\t+(?!imes))|(\\n)/g, '').replace(/\\"/g, '"').replace(/\\\//g, '/');
1229
- const createElementFromHTML$2 = htmlString => {
1230
- const div = document.createElement('div');
1231
- div.innerHTML = htmlString.trim();
1232
- return div;
1233
- };
1234
- const processMarkup = markup => {
1235
- const newMarkup = removeUnwantedCharacters(markup);
1236
- const slateMarkup = createElementFromHTML$2(newMarkup);
1237
- slateMarkup.querySelectorAll('[data-type="inline_dropdown"]').forEach(s => {
1238
- s.replaceWith(`{{${s.dataset.index}}}`);
1239
- });
1240
- return slateMarkup.innerHTML;
1241
- };
1242
- const REGEX = /\{\{(\d+)\}\}/g;
1243
- const createSlateMarkup = (markup, choices) => {
1244
- const newMarkup = removeUnwantedCharacters(markup);
1245
- const createSelect = index => {
1246
- let correctChoice = choices[index] && choices[index].find(c => c.correct);
1247
- if (!correctChoice || !correctChoice.value) {
1248
- correctChoice = {
1249
- id: '',
1250
- value: '',
1251
- label: ''
1252
- };
1253
- }
1254
- return `<span data-type="inline_dropdown" data-index="${index}" data-value="${escape(correctChoice.label)}"></span>`;
1255
- };
1256
- return newMarkup.replace(REGEX, (match, g) => {
1257
- return createSelect(g);
1258
- });
1259
- };
1260
- const {DeleteImageEvent: DeleteImageEvent} = _dll_pie_framework__pie_configure_events;
1261
- const {InsertImageEvent: InsertImageEvent} = _dll_pie_framework__pie_configure_events;
1262
- const {ModelUpdatedEvent: ModelUpdatedEvent} = _dll_pie_framework__pie_configure_events;
1263
- const React$2 = _dll_react;
1264
- const ReactDOM$2 = _dll_react_dom;
1265
- const {defaults: defaults} = _dll_lodash;
1266
- const log = browser('multiple-choice:configure');
1267
- class InlineDropdown extends HTMLElement {
1268
- static __initStatic() {
1269
- this.prepareModel = (model = {}) => {
1270
- const currModal = {
1271
- ...sensibleDefaults.model,
1272
- ...model
1273
- };
1274
- const slateMarkup = model.slateMarkup || createSlateMarkup(currModal.markup, currModal.choices);
1275
- const markup = processMarkup(slateMarkup);
1276
- return {
1277
- ...currModal,
1278
- slateMarkup,
1279
- markup
1280
- };
1281
- };
1282
- }
1283
- constructor() {
1284
- super();
1285
- this._model = InlineDropdown.prepareModel();
1286
- this._configuration = sensibleDefaults.configuration;
1287
- this.onModelChanged = this.onModelChanged.bind(this);
1288
- this.onConfigurationChanged = this.onConfigurationChanged.bind(this);
1289
- }
1290
- set model(s) {
1291
- this._model = InlineDropdown.prepareModel(s);
1292
- this._render();
1293
- }
1294
- set configuration(c) {
1295
- this._configuration = defaults(c, sensibleDefaults.configuration);
1296
- this._render();
1297
- }
1298
- set disableSidePanel(s) {
1299
- this._disableSidePanel = s;
1300
- this._render();
1301
- }
1302
- dispatchModelUpdated(reset) {
1303
- const resetValue = !!reset;
1304
- this.dispatchEvent(new ModelUpdatedEvent(this._model, resetValue));
1305
- }
1306
- onModelChanged(m, reset) {
1307
- this._model = InlineDropdown.prepareModel(m);
1308
- this._render();
1309
- this.dispatchModelUpdated(reset);
1310
- }
1311
- onConfigurationChanged(c) {
1312
- this._configuration = c;
1313
- this._render();
1314
- }
1315
- insertImage(handler) {
1316
- this.dispatchEvent(new InsertImageEvent(handler));
1317
- }
1318
- onDeleteImage(src, done) {
1319
- this.dispatchEvent(new DeleteImageEvent(src, done));
1320
- }
1321
- _render() {
1322
- log('_render');
1323
- let element = React$2.createElement(Styled, {
1324
- model: this._model,
1325
- configuration: this._configuration,
1326
- onModelChanged: this.onModelChanged,
1327
- onConfigurationChanged: this.onConfigurationChanged,
1328
- disableSidePanel: this._disableSidePanel,
1329
- imageSupport: {
1330
- add: this.insertImage.bind(this),
1331
- delete: this.onDeleteImage.bind(this)
1332
- }
1333
- });
1334
- ReactDOM$2.render(element, this);
1335
- }
1336
- }
1337
- InlineDropdown.__initStatic();
1338
- export default InlineDropdown;