@pie-element/passage 5.0.2-esm.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/configure.js DELETED
@@ -1,708 +0,0 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom';
3
- import { ModelUpdatedEvent, InsertImageEvent, DeleteImageEvent, InsertSoundEvent, DeleteSoundEvent } from '@pie-framework/pie-configure-events';
4
- import PropTypes from 'prop-types';
5
- import { InputContainer, layout, settings } from '@pie-lib/config-ui';
6
- import { withStyles } from '@material-ui/core/styles';
7
- import Typography from '@material-ui/core/Typography';
8
- import { Button } from '@material-ui/core';
9
- import RemoveCircleIcon from '@material-ui/icons/RemoveCircle';
10
- import AddCircleIcon from '@material-ui/icons/AddCircle';
11
- import Dialog from '@material-ui/core/Dialog';
12
- import DialogTitle from '@material-ui/core/DialogTitle';
13
- import DialogContent from '@material-ui/core/DialogContent';
14
- import DialogContentText from '@material-ui/core/DialogContentText';
15
- import DialogActions from '@material-ui/core/DialogActions';
16
- import EditableHtml, { ALL_PLUGINS } from '@pie-lib/editable-html';
17
-
18
- function _extends() {
19
- _extends = Object.assign || function (target) {
20
- for (var i = 1; i < arguments.length; i++) {
21
- var source = arguments[i];
22
-
23
- for (var key in source) {
24
- if (Object.prototype.hasOwnProperty.call(source, key)) {
25
- target[key] = source[key];
26
- }
27
- }
28
- }
29
-
30
- return target;
31
- };
32
-
33
- return _extends.apply(this, arguments);
34
- }
35
-
36
- const RemoveAddButton = ({
37
- classes,
38
- label,
39
- type: _type = 'add',
40
- onClick
41
- }) => {
42
- const Tag = _type === 'add' ? AddCircleIcon : RemoveCircleIcon;
43
- return /*#__PURE__*/React.createElement(Button, {
44
- color: "primary",
45
- size: "small",
46
- className: classes.root,
47
- onClick: onClick
48
- }, /*#__PURE__*/React.createElement(Tag, {
49
- fontSize: 'small',
50
- color: 'primary',
51
- className: classes.icon
52
- }), label);
53
- };
54
- const PassageButton = withStyles(theme => ({
55
- root: {
56
- textDecoration: 'underline',
57
- '&:hover': {
58
- textDecoration: 'underline',
59
- backgroundColor: 'transparent'
60
- }
61
- },
62
- label: {
63
- display: 'flex',
64
- alignItems: 'center'
65
- },
66
- icon: {
67
- marginRight: theme.spacing.unit / 2
68
- }
69
- }))(RemoveAddButton);
70
- const ConfimationDialog = ({
71
- content,
72
- cancel,
73
- title,
74
- ok,
75
- open,
76
- onOk,
77
- onCancel
78
- }) => /*#__PURE__*/React.createElement(Dialog, {
79
- open: open
80
- }, /*#__PURE__*/React.createElement(DialogTitle, null, title), /*#__PURE__*/React.createElement(DialogContent, null, /*#__PURE__*/React.createElement(DialogContentText, null, content)), /*#__PURE__*/React.createElement(DialogActions, null, onOk && /*#__PURE__*/React.createElement(Button, {
81
- onClick: onOk,
82
- color: "primary"
83
- }, ok), onCancel && /*#__PURE__*/React.createElement(Button, {
84
- onClick: onCancel,
85
- color: "primary"
86
- }, cancel)));
87
- ConfimationDialog.propTypes = {
88
- content: PropTypes.string.isRequired,
89
- title: PropTypes.string.isRequired,
90
- cancel: PropTypes.string.isRequired,
91
- ok: PropTypes.string.isRequired,
92
- open: PropTypes.bool.isRequired,
93
- onCancel: PropTypes.func.isRequired,
94
- onOk: PropTypes.func.isRequired
95
- };
96
-
97
- class PassageComponent extends React.Component {
98
- constructor(props) {
99
- super(props);
100
-
101
- this.handleChange = (fieldName, value) => {
102
- const {
103
- model,
104
- onModelChanged,
105
- passageIndex
106
- } = this.props;
107
-
108
- if (!model.passages || passageIndex < 0 || passageIndex >= model.passages.length) {
109
- return;
110
- }
111
-
112
- const updatedPassages = [...model.passages];
113
- updatedPassages[passageIndex] = _extends({}, updatedPassages[passageIndex], {
114
- [fieldName]: value
115
- });
116
- onModelChanged(_extends({}, model, {
117
- passages: updatedPassages
118
- }));
119
- };
120
- }
121
-
122
- render() {
123
- const {
124
- model,
125
- classes,
126
- configuration,
127
- imageSupport,
128
- passageIndex,
129
- uploadSoundSupport
130
- } = this.props;
131
- const {
132
- maxImageWidth = {},
133
- maxImageHeight = {},
134
- mathMlOptions = {},
135
- baseInputConfiguration = {},
136
- teacherInstructions = {},
137
- title = {},
138
- subtitle = {},
139
- text = {},
140
- author = {}
141
- } = configuration || {};
142
- const {
143
- errors = {},
144
- passages = [],
145
- teacherInstructionsEnabled,
146
- titleEnabled,
147
- subtitleEnabled,
148
- authorEnabled,
149
- textEnabled
150
- } = model || {};
151
- const {
152
- passages: passagesErrors
153
- } = errors || {};
154
- const {
155
- teacherInstructions: teacherInstructionsError,
156
- title: titleError,
157
- subtitle: subtitleError,
158
- author: authorError,
159
- text: textError
160
- } = passagesErrors && passagesErrors[passageIndex] || {};
161
- const defaultImageMaxWidth = maxImageWidth && maxImageWidth.prompt;
162
- const defaultImageMaxHeight = maxImageHeight && maxImageHeight.prompt;
163
-
164
- const getPluginProps = customConfiguration => _extends({}, baseInputConfiguration, customConfiguration);
165
-
166
- return /*#__PURE__*/React.createElement(React.Fragment, null, teacherInstructionsEnabled && /*#__PURE__*/React.createElement(InputContainer, {
167
- label: teacherInstructions.label,
168
- className: classes.inputContainer
169
- }, /*#__PURE__*/React.createElement(EditableHtml, {
170
- activePlugins: ALL_PLUGINS,
171
- markup: passages[passageIndex].teacherInstructions || '',
172
- onChange: value => this.handleChange('teacherInstructions', value),
173
- nonEmpty: false,
174
- error: teacherInstructionsError,
175
- maxImageWidth: maxImageWidth && maxImageWidth.teacherInstructions || defaultImageMaxWidth,
176
- maxImageHeight: maxImageHeight && maxImageHeight.teacherInstructions || defaultImageMaxHeight,
177
- mathMlOptions: mathMlOptions,
178
- languageCharactersProps: [{
179
- language: 'spanish'
180
- }, {
181
- language: 'special'
182
- }],
183
- pluginProps: getPluginProps(teacherInstructions == null ? void 0 : teacherInstructions.inputConfiguration)
184
- }), teacherInstructionsError && /*#__PURE__*/React.createElement("div", {
185
- className: classes.errorText
186
- }, teacherInstructionsError)), titleEnabled && /*#__PURE__*/React.createElement(InputContainer, {
187
- label: title.label,
188
- className: classes.inputContainer
189
- }, /*#__PURE__*/React.createElement(EditableHtml, {
190
- activePlugins: ALL_PLUGINS,
191
- markup: passages[passageIndex].title || '',
192
- onChange: value => this.handleChange('title', value),
193
- nonEmpty: false,
194
- error: titleError,
195
- mathMlOptions: mathMlOptions,
196
- languageCharactersProps: [{
197
- language: 'spanish'
198
- }, {
199
- language: 'special'
200
- }],
201
- pluginProps: getPluginProps(title == null ? void 0 : title.inputConfiguration)
202
- }), titleError && /*#__PURE__*/React.createElement("div", {
203
- className: classes.errorText
204
- }, titleError)), subtitleEnabled && /*#__PURE__*/React.createElement(InputContainer, {
205
- label: subtitle.label,
206
- className: classes.inputContainer
207
- }, /*#__PURE__*/React.createElement(EditableHtml, {
208
- activePlugins: ALL_PLUGINS,
209
- markup: passages[passageIndex].subtitle || '',
210
- onChange: value => this.handleChange('subtitle', value),
211
- nonEmpty: false,
212
- error: subtitleError,
213
- mathMlOptions: mathMlOptions,
214
- languageCharactersProps: [{
215
- language: 'spanish'
216
- }, {
217
- language: 'special'
218
- }],
219
- pluginProps: getPluginProps(subtitle == null ? void 0 : subtitle.inputConfiguration)
220
- }), subtitleError && /*#__PURE__*/React.createElement("div", {
221
- className: classes.errorText
222
- }, subtitleError)), authorEnabled && /*#__PURE__*/React.createElement(InputContainer, {
223
- label: author.label,
224
- className: classes.inputContainer
225
- }, /*#__PURE__*/React.createElement(EditableHtml, {
226
- activePlugins: ALL_PLUGINS,
227
- markup: passages[passageIndex].author || '',
228
- onChange: value => this.handleChange('author', value),
229
- nonEmpty: false,
230
- error: authorError,
231
- mathMlOptions: mathMlOptions,
232
- languageCharactersProps: [{
233
- language: 'spanish'
234
- }, {
235
- language: 'special'
236
- }],
237
- pluginProps: getPluginProps(author == null ? void 0 : author.inputConfiguration)
238
- }), authorError && /*#__PURE__*/React.createElement("div", {
239
- className: classes.errorText
240
- }, authorError)), textEnabled && /*#__PURE__*/React.createElement(InputContainer, {
241
- label: text.label,
242
- className: classes.inputContainer
243
- }, /*#__PURE__*/React.createElement(EditableHtml, {
244
- activePlugins: ALL_PLUGINS,
245
- markup: passages[passageIndex].text || '',
246
- onChange: value => this.handleChange('text', value),
247
- imageSupport: imageSupport,
248
- uploadSoundSupport: uploadSoundSupport,
249
- nonEmpty: false,
250
- error: textError,
251
- maxImageWidth: maxImageWidth && maxImageWidth.text || defaultImageMaxWidth,
252
- maxImageHeight: maxImageHeight && maxImageHeight.text || defaultImageMaxHeight,
253
- mathMlOptions: mathMlOptions,
254
- languageCharactersProps: [{
255
- language: 'spanish'
256
- }, {
257
- language: 'special'
258
- }],
259
- pluginProps: getPluginProps(text == null ? void 0 : text.inputConfiguration)
260
- }), textError && /*#__PURE__*/React.createElement("div", {
261
- className: classes.errorText
262
- }, textError)));
263
- }
264
-
265
- }
266
- PassageComponent.propTypes = {
267
- classes: PropTypes.object,
268
- onModelChanged: PropTypes.func.isRequired,
269
- model: PropTypes.object.isRequired,
270
- configuration: PropTypes.object.isRequired,
271
- imageSupport: PropTypes.object.isRequired,
272
- passageIndex: PropTypes.number.isRequired,
273
- uploadSoundSupport: PropTypes.object.isRequired
274
- };
275
- PassageComponent.defaultProps = {
276
- passageIndex: 0
277
- };
278
- var Passage = withStyles(theme => ({
279
- inputContainer: {
280
- paddingTop: theme.spacing.unit * 2,
281
- marginBottom: theme.spacing.unit * 2,
282
- width: '100%'
283
- },
284
- errorText: {
285
- fontSize: theme.typography.fontSize - 2,
286
- color: theme.palette.error.main,
287
- paddingTop: theme.spacing.unit
288
- }
289
- }))(PassageComponent);
290
-
291
- const {
292
- Panel,
293
- toggle,
294
- dropdown
295
- } = settings;
296
- class Main extends React.Component {
297
- constructor(props) {
298
- super(props);
299
-
300
- this.getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
301
-
302
- this.onDelete = (model, indexToRemove, onModelChanged) => {
303
- let updatedPassages = model.passages;
304
- updatedPassages.splice(indexToRemove, 1);
305
- onModelChanged(_extends({}, model, {
306
- passages: updatedPassages
307
- }));
308
- this.setState({
309
- showConfirmationDialog: false,
310
- indexToRemove: -1
311
- });
312
- };
313
-
314
- this.removeAdditionalPassage = indexToRemove => {
315
- const {
316
- model = {},
317
- onModelChanged
318
- } = this.props;
319
- const {
320
- passages = []
321
- } = model;
322
- const {
323
- teacherInstructions = '',
324
- title = '',
325
- subtitle = '',
326
- author = '',
327
- text = ''
328
- } = passages[indexToRemove];
329
-
330
- if (this.getInnerText(teacherInstructions).trim() || this.getInnerText(title).trim() || this.getInnerText(subtitle).trim() || this.getInnerText(author).trim() || this.getInnerText(text).trim()) {
331
- this.setState({
332
- showConfirmationDialog: true,
333
- indexToRemove
334
- });
335
- } else {
336
- this.onDelete(model, indexToRemove, onModelChanged);
337
- }
338
- };
339
-
340
- this.addAdditionalPassage = () => {
341
- const {
342
- model,
343
- onModelChanged
344
- } = this.props;
345
- const updatedPassages = [...model.passages, {
346
- teacherInstructions: '',
347
- title: '',
348
- subtitle: '',
349
- author: '',
350
- text: ''
351
- }];
352
- onModelChanged(_extends({}, model, {
353
- passages: updatedPassages
354
- }));
355
- };
356
-
357
- this.state = {
358
- showConfirmationDialog: false,
359
- indexToRemove: -1
360
- };
361
- }
362
-
363
- render() {
364
- const {
365
- classes,
366
- model,
367
- configuration,
368
- imageSupport,
369
- onConfigurationChanged,
370
- onModelChanged,
371
- uploadSoundSupport
372
- } = this.props;
373
- const {
374
- settingsPanelDisabled,
375
- language = {},
376
- languageChoices = {},
377
- teacherInstructions = {},
378
- title = {},
379
- subtitle = {},
380
- text = {},
381
- author = {},
382
- additionalPassage = {}
383
- } = configuration || {};
384
- const {
385
- extraCSSRules,
386
- passages
387
- } = model || {};
388
- const panelSettings = {
389
- titleEnabled: title && title.settings && toggle(title.label),
390
- subtitleEnabled: subtitle && subtitle.settings && toggle(subtitle.label),
391
- authorEnabled: author && author.settings && toggle(author.label),
392
- textEnabled: text && text.settings && toggle(text.label),
393
- 'additionalPassage.enabled': additionalPassage && additionalPassage.settings && toggle(additionalPassage.label, true)
394
- };
395
- const panelProperties = {
396
- teacherInstructionsEnabled: teacherInstructions && teacherInstructions.settings && toggle(teacherInstructions.label),
397
- 'language.enabled': language && language.settings && toggle(language.label, true),
398
- language: language && language.settings && language.enabled && dropdown(languageChoices.label, languageChoices.options)
399
- };
400
- const confirmationDialogContent = `${additionalPassage.label} will be deleted`;
401
- const {
402
- indexToRemove,
403
- showConfirmationDialog
404
- } = this.state;
405
- return /*#__PURE__*/React.createElement(layout.ConfigLayout, {
406
- extraCSSRules: extraCSSRules,
407
- hideSettings: settingsPanelDisabled,
408
- settings: /*#__PURE__*/React.createElement(Panel, {
409
- model: model,
410
- configuration: configuration,
411
- onChangeModel: model => onModelChanged(model),
412
- onChangeConfiguration: config => onConfigurationChanged(config),
413
- groups: {
414
- Settings: panelSettings,
415
- Properties: panelProperties
416
- }
417
- })
418
- }, passages.map((passage, passageIndex) => /*#__PURE__*/React.createElement(React.Fragment, {
419
- key: passageIndex
420
- }, passageIndex > 0 && /*#__PURE__*/React.createElement(Typography, {
421
- variant: "h5",
422
- className: classes.additionalPassageHeading
423
- }, additionalPassage.label), /*#__PURE__*/React.createElement(Passage, {
424
- imageSupport: imageSupport,
425
- uploadSoundSupport: uploadSoundSupport,
426
- model: model,
427
- configuration: configuration,
428
- passageIndex: passageIndex,
429
- onModelChanged: onModelChanged
430
- }), passageIndex > 0 && additionalPassage.enabled && /*#__PURE__*/React.createElement(PassageButton, {
431
- type: 'remove',
432
- label: `Remove ${additionalPassage.label}`,
433
- onClick: () => this.removeAdditionalPassage(passageIndex)
434
- }), passageIndex === 0 && additionalPassage.enabled && passages.length < 2 && /*#__PURE__*/React.createElement(PassageButton, {
435
- label: `Add ${additionalPassage.label}`,
436
- onClick: this.addAdditionalPassage
437
- }))), /*#__PURE__*/React.createElement(ConfimationDialog, {
438
- open: showConfirmationDialog,
439
- title: 'Warning',
440
- content: confirmationDialogContent,
441
- cancel: 'Cancel',
442
- ok: 'Ok',
443
- onCancel: () => this.setState({
444
- showConfirmationDialog: false
445
- }),
446
- onOk: () => this.onDelete(model, indexToRemove, onModelChanged)
447
- }));
448
- }
449
-
450
- }
451
- Main.propTypes = {
452
- onModelChanged: PropTypes.func.isRequired,
453
- onConfigurationChanged: PropTypes.func,
454
- model: PropTypes.object.isRequired,
455
- configuration: PropTypes.object.isRequired,
456
- imageSupport: PropTypes.object.isRequired,
457
- uploadSoundSupport: PropTypes.object.isRequired,
458
- classes: PropTypes.object.isRequired
459
- };
460
- var Main$1 = withStyles(theme => ({
461
- additionalPassageHeading: {
462
- paddingTop: theme.spacing.unit * 2,
463
- marginBottom: theme.spacing.unit * 2
464
- }
465
- }))(Main);
466
-
467
- // TODO: also update '../../controller/src/defaults.js' and '../../src/print.js' when updating defaults
468
- var defaultValues = {
469
- model: {
470
- authorEnabled: true,
471
- passages: [{
472
- teacherInstructions: '',
473
- title: '',
474
- subtitle: '',
475
- author: '',
476
- text: ''
477
- }],
478
- subtitleEnabled: true,
479
- teacherInstructionsEnabled: true,
480
- textEnabled: true,
481
- titleEnabled: true
482
- },
483
- configuration: {
484
- baseInputConfiguration: {
485
- audio: {
486
- disabled: false
487
- },
488
- video: {
489
- disabled: false
490
- },
491
- image: {
492
- disabled: false
493
- },
494
- h3: {
495
- disabled: true
496
- },
497
- blockquote: {
498
- disabled: true
499
- },
500
- textAlign: {
501
- disabled: true
502
- },
503
- showParagraphs: {
504
- disabled: false
505
- },
506
- separateParagraphs: {
507
- disabled: true
508
- }
509
- },
510
- settingsPanelDisabled: false,
511
- title: {
512
- settings: true,
513
- label: 'Title',
514
- inputConfiguration: {
515
- audio: {
516
- disabled: true
517
- },
518
- video: {
519
- disabled: true
520
- },
521
- image: {
522
- disabled: true
523
- },
524
- textAlign: {
525
- disabled: false
526
- }
527
- },
528
- required: true
529
- },
530
- subtitle: {
531
- settings: true,
532
- label: 'Subtitle',
533
- inputConfiguration: {
534
- audio: {
535
- disabled: true
536
- },
537
- video: {
538
- disabled: true
539
- },
540
- image: {
541
- disabled: true
542
- },
543
- textAlign: {
544
- disabled: false
545
- }
546
- },
547
- required: false
548
- },
549
- author: {
550
- settings: true,
551
- label: 'Author',
552
- inputConfiguration: {
553
- audio: {
554
- disabled: true
555
- },
556
- video: {
557
- disabled: true
558
- },
559
- image: {
560
- disabled: true
561
- }
562
- },
563
- required: false
564
- },
565
- text: {
566
- settings: true,
567
- label: 'Text',
568
- inputConfiguration: {
569
- audio: {
570
- disabled: false
571
- },
572
- video: {
573
- disabled: false
574
- },
575
- image: {
576
- disabled: false
577
- },
578
- h3: {
579
- disabled: false
580
- },
581
- blockquote: {
582
- disabled: false
583
- },
584
- textAlign: {
585
- disabled: false
586
- }
587
- },
588
- required: true
589
- },
590
- teacherInstructions: {
591
- settings: true,
592
- label: 'Teacher Instructions',
593
- inputConfiguration: {
594
- audio: {
595
- disabled: false
596
- },
597
- video: {
598
- disabled: false
599
- },
600
- image: {
601
- disabled: false
602
- }
603
- },
604
- required: false
605
- },
606
- maxImageWidth: {
607
- teacherInstructions: 300,
608
- text: 300
609
- },
610
- maxImageHeight: {
611
- teacherInstructions: 300,
612
- text: 300
613
- },
614
- mathMlOptions: {
615
- mmlOutput: false,
616
- mmlEditing: false
617
- },
618
- language: {
619
- settings: false,
620
- label: 'Specify Language',
621
- enabled: false
622
- },
623
- languageChoices: {
624
- label: 'Language Choices',
625
- options: []
626
- },
627
- additionalPassage: {
628
- settings: true,
629
- label: 'Additional Passage',
630
- enabled: false
631
- }
632
- }
633
- };
634
-
635
- class PassageConfigure extends HTMLElement {
636
- constructor() {
637
- super();
638
- this._model = PassageConfigure.createDefaultModel();
639
- this._configuration = defaultValues.configuration;
640
- }
641
-
642
- set model(m) {
643
- this._model = PassageConfigure.createDefaultModel(m);
644
- this.render();
645
- }
646
-
647
- set configuration(c) {
648
- this._configuration = c;
649
- this.render();
650
- }
651
-
652
- connectedCallback() {
653
- this.render();
654
- }
655
-
656
- modelChanged(m) {
657
- this._model = m;
658
- this.dispatchEvent(new ModelUpdatedEvent(this._model), true);
659
- this.render();
660
- }
661
-
662
- onConfigurationChanged(c) {
663
- this._configuration = c;
664
- this.render();
665
- }
666
-
667
- insertImage(handler) {
668
- this.dispatchEvent(new InsertImageEvent(handler));
669
- }
670
-
671
- onDeleteImage(src, done) {
672
- this.dispatchEvent(new DeleteImageEvent(src, done));
673
- }
674
-
675
- insertSound(handler) {
676
- this.dispatchEvent(new InsertSoundEvent(handler));
677
- }
678
-
679
- onDeleteSound(src, done) {
680
- this.dispatchEvent(new DeleteSoundEvent(src, done));
681
- }
682
-
683
- render() {
684
- if (this._model) {
685
- const el = /*#__PURE__*/React.createElement(Main$1, {
686
- model: this._model,
687
- configuration: this._configuration,
688
- onModelChanged: this.modelChanged.bind(this),
689
- onConfigurationChanged: this.onConfigurationChanged.bind(this),
690
- imageSupport: {
691
- add: this.insertImage.bind(this),
692
- delete: this.onDeleteImage.bind(this)
693
- },
694
- uploadSoundSupport: {
695
- add: this.insertSound.bind(this),
696
- delete: this.onDeleteSound.bind(this)
697
- }
698
- });
699
- ReactDOM.render(el, this);
700
- }
701
- }
702
-
703
- }
704
-
705
- PassageConfigure.createDefaultModel = (model = {}) => _extends({}, defaultValues.model, model);
706
-
707
- export { PassageConfigure as default };
708
- //# sourceMappingURL=configure.js.map