@pie-element/ebsr 7.0.24-next.1 → 7.0.24-next.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.
Files changed (148) hide show
  1. package/configure/lib/defaults.js +125 -0
  2. package/configure/lib/defaults.js.map +1 -0
  3. package/configure/lib/index.js +207 -0
  4. package/configure/lib/index.js.map +1 -0
  5. package/configure/lib/main.js +284 -0
  6. package/configure/lib/main.js.map +1 -0
  7. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
  8. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +1793 -0
  9. package/configure/node_modules/@pie-element/multiple-choice/LICENSE.md +5 -0
  10. package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
  11. package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
  12. package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
  13. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
  14. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +1334 -0
  15. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +104 -0
  16. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
  17. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +198 -0
  18. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
  19. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +599 -0
  20. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
  21. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
  22. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
  23. package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +20 -0
  24. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
  25. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +768 -0
  26. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +18 -0
  27. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
  28. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +305 -0
  29. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
  30. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +36 -0
  31. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
  32. package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
  33. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +353 -0
  34. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +277 -0
  35. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
  36. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +52 -0
  37. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
  38. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
  39. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +338 -0
  40. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +274 -0
  41. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +298 -0
  42. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
  43. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +157 -0
  44. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
  45. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +174 -0
  46. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
  47. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +151 -0
  48. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
  49. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +97 -0
  50. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
  51. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +254 -0
  52. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
  53. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +129 -0
  54. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
  55. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +35 -0
  56. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
  57. package/configure/node_modules/@pie-element/multiple-choice/module/configure.js +843 -0
  58. package/configure/node_modules/@pie-element/multiple-choice/module/controller.js +20686 -0
  59. package/configure/node_modules/@pie-element/multiple-choice/module/demo.js +77 -0
  60. package/configure/node_modules/@pie-element/multiple-choice/module/element.js +2019 -0
  61. package/configure/node_modules/@pie-element/multiple-choice/module/index.html +21 -0
  62. package/configure/node_modules/@pie-element/multiple-choice/module/manifest.json +14 -0
  63. package/configure/node_modules/@pie-element/multiple-choice/module/print-demo.js +115 -0
  64. package/configure/node_modules/@pie-element/multiple-choice/module/print.html +18 -0
  65. package/configure/node_modules/@pie-element/multiple-choice/module/print.js +1983 -0
  66. package/configure/node_modules/@pie-element/multiple-choice/package.json +34 -0
  67. package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.json +672 -0
  68. package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.md +427 -0
  69. package/configure/node_modules/@pie-lib/math-rendering/LICENSE.md +5 -0
  70. package/configure/node_modules/@pie-lib/math-rendering/lib/index.js +30 -0
  71. package/configure/node_modules/@pie-lib/math-rendering/lib/index.js.map +1 -0
  72. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js +316 -0
  73. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js.map +1 -0
  74. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js +23 -0
  75. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js.map +1 -0
  76. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js +123 -0
  77. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js.map +1 -0
  78. package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js +103 -0
  79. package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js.map +1 -0
  80. package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js +275 -0
  81. package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js.map +1 -0
  82. package/configure/node_modules/@pie-lib/math-rendering/package.json +19 -0
  83. package/configure/node_modules/@pie-lib/math-rendering/playground/demo.html +872 -0
  84. package/configure/node_modules/@pie-lib/math-rendering/playground/demo.js +108 -0
  85. package/configure/node_modules/@pie-lib/math-rendering/playground/main.html +156 -0
  86. package/configure/node_modules/@pie-lib/math-rendering/playground/main.js +16 -0
  87. package/configure/node_modules/@pie-lib/math-rendering/playground/webpack.config.js +29 -0
  88. package/configure/node_modules/@pie-lib/math-rendering/src/index.js +4 -0
  89. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/chtml.js +215 -0
  90. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/index.js +13 -0
  91. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/mml.js +24 -0
  92. package/configure/node_modules/@pie-lib/math-rendering/src/normalization.js +69 -0
  93. package/configure/node_modules/@pie-lib/math-rendering/src/render-math.js +234 -0
  94. package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.json +937 -0
  95. package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.md +602 -0
  96. package/configure/node_modules/@pie-lib/render-ui/LICENSE.md +5 -0
  97. package/configure/node_modules/@pie-lib/render-ui/README.md +33 -0
  98. package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js +146 -0
  99. package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js.map +1 -0
  100. package/configure/node_modules/@pie-lib/render-ui/lib/color.js +134 -0
  101. package/configure/node_modules/@pie-lib/render-ui/lib/color.js.map +1 -0
  102. package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js +160 -0
  103. package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js.map +1 -0
  104. package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js +24 -0
  105. package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js.map +1 -0
  106. package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js +102 -0
  107. package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js.map +1 -0
  108. package/configure/node_modules/@pie-lib/render-ui/lib/index.js +104 -0
  109. package/configure/node_modules/@pie-lib/render-ui/lib/index.js.map +1 -0
  110. package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js +60 -0
  111. package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js.map +1 -0
  112. package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js +133 -0
  113. package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js.map +1 -0
  114. package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js +162 -0
  115. package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js.map +1 -0
  116. package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js +28 -0
  117. package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js.map +1 -0
  118. package/configure/node_modules/@pie-lib/render-ui/lib/readable.js +28 -0
  119. package/configure/node_modules/@pie-lib/render-ui/lib/readable.js.map +1 -0
  120. package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js +160 -0
  121. package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js.map +1 -0
  122. package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js +206 -0
  123. package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js.map +1 -0
  124. package/configure/node_modules/@pie-lib/render-ui/package.json +30 -0
  125. package/configure/node_modules/@pie-lib/render-ui/src/collapsible/index.jsx +68 -0
  126. package/configure/node_modules/@pie-lib/render-ui/src/color.js +48 -0
  127. package/configure/node_modules/@pie-lib/render-ui/src/feedback.jsx +100 -0
  128. package/configure/node_modules/@pie-lib/render-ui/src/has-text.js +14 -0
  129. package/configure/node_modules/@pie-lib/render-ui/src/html-and-math.js +40 -0
  130. package/configure/node_modules/@pie-lib/render-ui/src/index.js +27 -0
  131. package/configure/node_modules/@pie-lib/render-ui/src/input-container.jsx +41 -0
  132. package/configure/node_modules/@pie-lib/render-ui/src/preview-layout.jsx +77 -0
  133. package/configure/node_modules/@pie-lib/render-ui/src/preview-prompt.jsx +90 -0
  134. package/configure/node_modules/@pie-lib/render-ui/src/purpose.jsx +19 -0
  135. package/configure/node_modules/@pie-lib/render-ui/src/readable.jsx +19 -0
  136. package/configure/node_modules/@pie-lib/render-ui/src/response-indicators.jsx +89 -0
  137. package/configure/node_modules/@pie-lib/render-ui/src/withUndoReset.jsx +118 -0
  138. package/controller/lib/defaults.js +28 -0
  139. package/controller/lib/defaults.js.map +1 -0
  140. package/controller/lib/index.js +471 -0
  141. package/controller/lib/index.js.map +1 -0
  142. package/controller/lib/utils.js +33 -0
  143. package/controller/lib/utils.js.map +1 -0
  144. package/lib/index.js +202 -0
  145. package/lib/index.js.map +1 -0
  146. package/lib/print.js +243 -0
  147. package/lib/print.js.map +1 -0
  148. package/package.json +1 -1
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { renderMath } from '@pie-lib/math-rendering';
3
+ import PropTypes from 'prop-types';
4
+
5
+ export default class HtmlAndMath extends React.Component {
6
+ static propTypes = {
7
+ tag: PropTypes.string,
8
+ className: PropTypes.string,
9
+ html: PropTypes.string
10
+ };
11
+
12
+ static defaultProps = {
13
+ tag: 'div',
14
+ html: ''
15
+ };
16
+
17
+ componentDidMount() {
18
+ if (this.node) {
19
+ renderMath(this.node);
20
+ }
21
+ }
22
+
23
+ componentDidUpdate() {
24
+ if (this.node) {
25
+ renderMath(this.node);
26
+ }
27
+ }
28
+
29
+ render() {
30
+ const { tag, className, html } = this.props;
31
+ const Tag = tag || 'div';
32
+ return (
33
+ <Tag
34
+ ref={r => (this.node = r)}
35
+ className={className}
36
+ dangerouslySetInnerHTML={{ __html: html }}
37
+ />
38
+ );
39
+ }
40
+ }
@@ -0,0 +1,27 @@
1
+ import * as indicators from './response-indicators';
2
+ import Feedback from './feedback';
3
+ import Collapsible from './collapsible';
4
+ import withUndoReset from './withUndoReset';
5
+ import PreviewLayout from './preview-layout';
6
+ import HtmlAndMath from './html-and-math';
7
+ import InputContainer from './input-container';
8
+ import PreviewPrompt from './preview-prompt';
9
+ import Readable from './readable';
10
+ import Purpose from './purpose';
11
+ import * as color from './color';
12
+ import { hasText } from './has-text';
13
+
14
+ export {
15
+ HtmlAndMath,
16
+ indicators,
17
+ withUndoReset,
18
+ Feedback,
19
+ PreviewLayout,
20
+ Collapsible,
21
+ InputContainer,
22
+ PreviewPrompt,
23
+ color,
24
+ Readable,
25
+ Purpose,
26
+ hasText
27
+ };
@@ -0,0 +1,41 @@
1
+ import InputLabel from '@material-ui/core/InputLabel';
2
+ import PropTypes from 'prop-types';
3
+ import React from 'react';
4
+ import classNames from 'classnames';
5
+ import { withStyles } from '@material-ui/core/styles';
6
+ import FormControl from '@material-ui/core/FormControl';
7
+
8
+ const RawInputContainer = props => {
9
+ const { label, className, children, classes } = props;
10
+ const names = classNames(classes.formControl, className);
11
+
12
+ return (
13
+ <FormControl className={names}>
14
+ <InputLabel className={classes.label} shrink={true}>
15
+ {label}
16
+ </InputLabel>
17
+ {children}
18
+ </FormControl>
19
+ );
20
+ };
21
+
22
+ RawInputContainer.propTypes = {
23
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
24
+ className: PropTypes.string,
25
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
26
+ classes: PropTypes.object.isRequired
27
+ };
28
+
29
+ export default withStyles(theme => ({
30
+ formControl: {
31
+ marginLeft: 0,
32
+ marginRight: theme.spacing.unit,
33
+ paddingBottom: theme.spacing.unit,
34
+ flex: '1 0 auto',
35
+ minWidth: theme.spacing.unit * 4
36
+ },
37
+ label: {
38
+ fontSize: 'inherit',
39
+ whiteSpace: 'nowrap'
40
+ }
41
+ }))(RawInputContainer);
@@ -0,0 +1,77 @@
1
+ import React from 'react';
2
+ import { withStyles, createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
3
+ import PropTypes from 'prop-types';
4
+
5
+ class PreviewLayout extends React.Component {
6
+ static propTypes = {
7
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
8
+ classes: PropTypes.object
9
+ };
10
+
11
+ render() {
12
+ const { children, classes } = this.props;
13
+
14
+ return <div className={classes.container}>{children}</div>;
15
+ }
16
+ }
17
+
18
+ const styles = () => ({
19
+ container: {
20
+ display: 'flex',
21
+ flexDirection: 'column',
22
+ position: 'relative'
23
+ }
24
+ });
25
+
26
+ const theme = createMuiTheme({
27
+ typography: {
28
+ useNextVariants: true
29
+ },
30
+ palette: {
31
+ action: {
32
+ disabled: 'rgba(0, 0, 0, 0.54);'
33
+ }
34
+ },
35
+ overrides: {
36
+ MuiRadio: {
37
+ root: {
38
+ '&$checked': {
39
+ color: '#3f51b5 !important'
40
+ }
41
+ }
42
+ },
43
+ MuiCheckbox: {
44
+ root: {
45
+ '&$checked': {
46
+ color: '#3f51b5 !important'
47
+ }
48
+ }
49
+ },
50
+ MuiTabs: {
51
+ root: {
52
+ borderBottom: '1px solid #eee'
53
+ }
54
+ },
55
+ MuiSwitch: {
56
+ root: {
57
+ '&$checked': {
58
+ color: '#3f51b5 !important',
59
+ '& + $bar': {
60
+ backgroundColor: '#3f51b5 !important',
61
+ opacity: 0.5
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ });
68
+
69
+ const Styled = withStyles(styles)(PreviewLayout);
70
+
71
+ const RootElem = props => (
72
+ <MuiThemeProvider theme={theme}>
73
+ <Styled {...props} />
74
+ </MuiThemeProvider>
75
+ );
76
+
77
+ export default RootElem;
@@ -0,0 +1,90 @@
1
+ import React, { Component } from 'react';
2
+ import { withStyles } from '@material-ui/core/styles';
3
+ import PropTypes from 'prop-types';
4
+ import * as color from './color';
5
+
6
+ //Used these below to replace \\embed{newLine} with \\newline from prompt which will get parsed in MathJax
7
+ const NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
8
+ const NEWLINE_LATEX = '\\newline ';
9
+
10
+ export class PreviewPrompt extends Component {
11
+ static propTypes = {
12
+ classes: PropTypes.object,
13
+ prompt: PropTypes.string,
14
+ tagName: PropTypes.string,
15
+ className: PropTypes.string,
16
+ onClick: PropTypes.func,
17
+ defaultClassName: PropTypes.string
18
+ };
19
+
20
+ static defaultProps = {
21
+ onClick: () => {}
22
+ };
23
+
24
+ parsedText = text => {
25
+ // fix imported audio content for Safari PD-1419
26
+ const div = document.createElement('div');
27
+ div.innerHTML = text;
28
+
29
+ const audio = div.querySelector('audio');
30
+ if (audio) {
31
+ const source = document.createElement('source');
32
+
33
+ source.setAttribute('type', 'audio/mp3');
34
+ source.setAttribute('src', audio.getAttribute('src'));
35
+
36
+ audio.removeAttribute('src');
37
+ audio.appendChild(source);
38
+ }
39
+
40
+ return div.innerHTML;
41
+ };
42
+
43
+ render() {
44
+ const { prompt, classes, tagName, className, onClick, defaultClassName } = this.props;
45
+ const CustomTag = tagName || 'div';
46
+ const customClasses = `${classes.promptTable} ${classes[className] || ''} ${defaultClassName ||
47
+ ''}`;
48
+
49
+ return (
50
+ <CustomTag
51
+ onClick={onClick}
52
+ className={customClasses}
53
+ dangerouslySetInnerHTML={{
54
+ __html: this.parsedText(prompt || '').replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX)
55
+ }}
56
+ />
57
+ );
58
+ }
59
+ }
60
+
61
+ const styles = theme => ({
62
+ prompt: {
63
+ verticalAlign: 'middle',
64
+ color: color.text()
65
+ },
66
+ rationale: {
67
+ paddingLeft: theme.spacing.unit * 16
68
+ },
69
+ label: {
70
+ color: `${color.text()} !important`, //'var(--choice-input-color, black)',
71
+ display: 'inline-block',
72
+ verticalAlign: 'middle',
73
+ cursor: 'pointer'
74
+ },
75
+ promptTable: {
76
+ '&:not(.MathJax) > table': {
77
+ borderCollapse: 'collapse'
78
+ },
79
+ '&:not(.MathJax) > table tr': {
80
+ '&:nth-child(2n)': {
81
+ backgroundColor: '#f6f8fa'
82
+ }
83
+ },
84
+ '&:not(.MathJax) > table td, &:not(.MathJax) > table th': {
85
+ padding: '.6em 1em',
86
+ textAlign: 'center'
87
+ }
88
+ }
89
+ });
90
+ export default withStyles(styles)(PreviewPrompt);
@@ -0,0 +1,19 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+
4
+ const Purpose = props => {
5
+ return (
6
+ <>
7
+ {React.Children.map(props.children, child =>
8
+ React.cloneElement(child, { 'data-pie-purpose': props.purpose })
9
+ )}
10
+ </>
11
+ );
12
+ };
13
+
14
+ Purpose.propTypes = {
15
+ children: PropTypes.node,
16
+ purpose: PropTypes.string
17
+ };
18
+
19
+ export default Purpose;
@@ -0,0 +1,19 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+
4
+ const Readable = props => {
5
+ return (
6
+ <>
7
+ {React.Children.map(props.children, child =>
8
+ React.cloneElement(child, { 'data-pie-readable': props.false === undefined })
9
+ )}
10
+ </>
11
+ );
12
+ };
13
+
14
+ Readable.propTypes = {
15
+ children: PropTypes.node,
16
+ false: PropTypes.bool
17
+ };
18
+
19
+ export default Readable;
@@ -0,0 +1,89 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import * as icons from '@pie-lib/icons';
4
+ import Popover from '@material-ui/core/Popover';
5
+ import { withStyles } from '@material-ui/core/styles';
6
+ import Feedback from './feedback';
7
+ import debug from 'debug';
8
+
9
+ const log = debug('pie-libs:render-ui:response-indicators');
10
+
11
+ const styles = () => ({
12
+ responseIndicator: {
13
+ cursor: 'pointer'
14
+ },
15
+ paper: {
16
+ padding: '0',
17
+ borderRadius: '4px'
18
+ },
19
+ popover: {
20
+ cursor: 'pointer'
21
+ },
22
+ popperClose: {
23
+ cursor: 'pointer'
24
+ }
25
+ });
26
+
27
+ const BuildIndicator = (Icon, correctness) => {
28
+ class RawIndicator extends React.Component {
29
+ constructor(props) {
30
+ super(props);
31
+ this.state = {};
32
+ }
33
+
34
+ handlePopoverOpen = event => {
35
+ log('[handlePopoverOpen]', event.target);
36
+ this.setState({ anchorEl: event.target });
37
+ };
38
+
39
+ handlePopoverClose = () => {
40
+ this.setState({ anchorEl: null });
41
+ };
42
+
43
+ render() {
44
+ const { feedback, classes } = this.props;
45
+ const { anchorEl } = this.state;
46
+ return (
47
+ <div className={feedback && classes.responseIndicator}>
48
+ <span ref={r => (this.icon = r)} onClick={this.handlePopoverOpen}>
49
+ <Icon />
50
+ </span>
51
+
52
+ {feedback && (
53
+ <Popover
54
+ className={classes.popover}
55
+ classes={{
56
+ paper: classes.paper
57
+ }}
58
+ open={!!anchorEl}
59
+ anchorEl={anchorEl}
60
+ anchorOrigin={{
61
+ vertical: 'bottom',
62
+ horizontal: 'left'
63
+ }}
64
+ transformOrigin={{
65
+ vertical: 'top',
66
+ horizontal: 'left'
67
+ }}
68
+ onClose={this.handlePopoverClose}
69
+ >
70
+ <Feedback feedback={feedback} correctness={correctness} />
71
+ </Popover>
72
+ )}
73
+ </div>
74
+ );
75
+ }
76
+ }
77
+
78
+ RawIndicator.propTypes = {
79
+ feedback: PropTypes.string,
80
+ classes: PropTypes.object.isRequired
81
+ };
82
+
83
+ return withStyles(styles)(RawIndicator);
84
+ };
85
+
86
+ export const Correct = BuildIndicator(icons.Correct, 'correct');
87
+ export const Incorrect = BuildIndicator(icons.Incorrect, 'incorrect');
88
+ export const PartiallyCorrect = BuildIndicator(icons.PartiallyCorrect, 'partially-correct');
89
+ export const NothingSubmitted = BuildIndicator(icons.NothingSubmitted, 'nothing-submitted');
@@ -0,0 +1,118 @@
1
+ import * as React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Button from '@material-ui/core/Button';
4
+ import { withStyles } from '@material-ui/core/styles';
5
+ import Restore from '@material-ui/icons/Restore';
6
+ import Undo from '@material-ui/icons/Undo';
7
+
8
+ const styles = theme => ({
9
+ wrapper: {
10
+ display: 'flex',
11
+ flexDirection: 'column'
12
+ },
13
+ resetUndoContainer: {
14
+ display: 'flex',
15
+ alignItems: 'center',
16
+ justifyContent: 'center'
17
+ },
18
+ icon: {
19
+ width: '24px',
20
+ height: '24px',
21
+ color: 'gray',
22
+ marginRight: theme.spacing.unit
23
+ },
24
+ buttonContainer: {
25
+ display: 'flex',
26
+ alignItems: 'center',
27
+ marginLeft: theme.spacing.unit * 3,
28
+ marginRight: theme.spacing.unit * 3
29
+ }
30
+ });
31
+
32
+ /**
33
+ * HOC that adds undo and reset functionality for session values
34
+ */
35
+ const withUndoReset = WrappedComponent => {
36
+ class WithUndoReset extends React.Component {
37
+ static propTypes = {
38
+ classes: PropTypes.object,
39
+ session: PropTypes.object,
40
+ onSessionChange: PropTypes.func
41
+ };
42
+
43
+ constructor(props) {
44
+ super(props);
45
+
46
+ this.state = {
47
+ sessionInitialValues: JSON.parse(JSON.stringify(props.session)),
48
+ session: props.session,
49
+ changes: []
50
+ };
51
+ }
52
+
53
+ onSessionChange = session => {
54
+ this.setState(
55
+ state => ({ session, changes: [...state.changes, session] }),
56
+ () => this.props.onSessionChange(session)
57
+ );
58
+ };
59
+
60
+ onUndo = () => {
61
+ this.setState(
62
+ state => {
63
+ const newChanges = [...state.changes];
64
+
65
+ newChanges.pop();
66
+
67
+ return {
68
+ changes: newChanges,
69
+ session: newChanges.length
70
+ ? newChanges[newChanges.length - 1]
71
+ : state.sessionInitialValues
72
+ };
73
+ },
74
+ () => this.props.onSessionChange(this.state.session)
75
+ );
76
+ };
77
+
78
+ onReset = () => {
79
+ this.setState(
80
+ state => ({ session: state.sessionInitialValues, changes: [] }),
81
+ () => this.props.onSessionChange(this.state.sessionInitialValues)
82
+ );
83
+ };
84
+
85
+ render() {
86
+ const { classes, ...rest } = this.props;
87
+ const { changes, session } = this.state;
88
+
89
+ return (
90
+ <div className={classes.wrapper}>
91
+ <div className={classes.resetUndoContainer}>
92
+ <Button
93
+ className={classes.buttonContainer}
94
+ color="primary"
95
+ disabled={changes.length === 0}
96
+ onClick={this.onUndo}
97
+ >
98
+ <Undo className={classes.icon} /> Undo
99
+ </Button>
100
+ <Button
101
+ className={classes.buttonContainer}
102
+ color="primary"
103
+ disabled={changes.length === 0}
104
+ onClick={this.onReset}
105
+ >
106
+ <Restore className={classes.icon} /> Start Over
107
+ </Button>
108
+ </div>
109
+ <WrappedComponent {...rest} session={session} onSessionChange={this.onSessionChange} />
110
+ </div>
111
+ );
112
+ }
113
+ }
114
+
115
+ return withStyles(styles)(WithUndoReset);
116
+ };
117
+
118
+ export default withUndoReset;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _default = {
8
+ partA: {
9
+ choicePrefix: 'letters',
10
+ choices: [{
11
+ value: 'a',
12
+ label: 'label a'
13
+ }],
14
+ prompt: 'prompt a',
15
+ disabled: false
16
+ },
17
+ partB: {
18
+ choicePrefix: 'letters',
19
+ choices: [{
20
+ value: 'b',
21
+ label: 'label b'
22
+ }],
23
+ prompt: 'prompt b',
24
+ disabled: false
25
+ }
26
+ };
27
+ exports["default"] = _default;
28
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["partA","choicePrefix","choices","value","label","prompt","disabled","partB"],"mappings":";;;;;;eAAe;AACbA,EAAAA,KAAK,EAAE;AACLC,IAAAA,YAAY,EAAE,SADT;AAELC,IAAAA,OAAO,EAAE,CACP;AACEC,MAAAA,KAAK,EAAE,GADT;AAEEC,MAAAA,KAAK,EAAE;AAFT,KADO,CAFJ;AAQLC,IAAAA,MAAM,EAAE,UARH;AASLC,IAAAA,QAAQ,EAAE;AATL,GADM;AAYbC,EAAAA,KAAK,EAAE;AACLN,IAAAA,YAAY,EAAE,SADT;AAELC,IAAAA,OAAO,EAAE,CACP;AACEC,MAAAA,KAAK,EAAE,GADT;AAEEC,MAAAA,KAAK,EAAE;AAFT,KADO,CAFJ;AAQLC,IAAAA,MAAM,EAAE,UARH;AASLC,IAAAA,QAAQ,EAAE;AATL;AAZM,C","sourcesContent":["export default {\n partA: {\n choicePrefix: 'letters',\n choices: [\n {\n value: 'a',\n label: 'label a',\n }\n ],\n prompt: 'prompt a',\n disabled: false,\n },\n partB: {\n choicePrefix: 'letters',\n choices: [\n {\n value: 'b',\n label: 'label b',\n },\n ],\n prompt: 'prompt b',\n disabled: false,\n },\n};\n"],"file":"defaults.js"}