@pie-lib/render-ui 4.35.3-next.0 → 4.35.3-next.155
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/CHANGELOG.md +9 -81
- package/esm/package.json +3 -0
- package/lib/append-css-rules.js +10 -37
- package/lib/append-css-rules.js.map +1 -1
- package/lib/assets/enableAudioAutoplayImage.js +1 -2
- package/lib/assets/enableAudioAutoplayImage.js.map +1 -1
- package/lib/collapsible/index.js +35 -65
- package/lib/collapsible/index.js.map +1 -1
- package/lib/color.js +57 -201
- package/lib/color.js.map +1 -1
- package/lib/feedback.js +71 -108
- package/lib/feedback.js.map +1 -1
- package/lib/has-media.js +2 -7
- package/lib/has-media.js.map +1 -1
- package/lib/has-text.js +1 -7
- package/lib/has-text.js.map +1 -1
- package/lib/html-and-math.js +10 -30
- package/lib/html-and-math.js.map +1 -1
- package/lib/index.js +1 -24
- package/lib/index.js.map +1 -1
- package/lib/input-container.js +43 -44
- package/lib/input-container.js.map +1 -1
- package/lib/preview-layout.js +22 -58
- package/lib/preview-layout.js.map +1 -1
- package/lib/preview-prompt.js +104 -131
- package/lib/preview-prompt.js.map +1 -1
- package/lib/purpose.js +1 -7
- package/lib/purpose.js.map +1 -1
- package/lib/readable.js +1 -7
- package/lib/readable.js.map +1 -1
- package/lib/response-indicators.js +37 -86
- package/lib/response-indicators.js.map +1 -1
- package/lib/ui-layout.js +53 -70
- package/lib/ui-layout.js.map +1 -1
- package/lib/withUndoReset.js +51 -97
- package/lib/withUndoReset.js.map +1 -1
- package/package.json +23 -13
- package/src/__tests__/html-and-math.test.js +26 -14
- package/src/__tests__/preview-prompt.test.jsx +43 -40
- package/src/__tests__/purpose.test.jsx +27 -23
- package/src/__tests__/readable.test.jsx +34 -29
- package/src/__tests__/response-indicators.test.jsx +104 -9
- package/src/__tests__/ui-layout.test.jsx +28 -12
- package/src/__tests__/withUndoReset.test.jsx +110 -188
- package/src/collapsible/__tests__/index.test.jsx +33 -7
- package/src/collapsible/index.jsx +17 -17
- package/src/color.js +1 -5
- package/src/feedback.jsx +59 -63
- package/src/input-container.jsx +41 -32
- package/src/preview-layout.jsx +11 -23
- package/src/preview-prompt.jsx +76 -58
- package/src/response-indicators.jsx +22 -29
- package/src/ui-layout.jsx +41 -28
- package/src/withUndoReset.jsx +48 -50
- package/src/__tests__/__snapshots__/html-and-math.test.js.snap +0 -11
- package/src/__tests__/__snapshots__/preview-prompt.test.jsx.snap +0 -37
- package/src/__tests__/__snapshots__/purpose.test.jsx.snap +0 -42
- package/src/__tests__/__snapshots__/readable.test.jsx.snap +0 -64
- package/src/__tests__/__snapshots__/response-indicators.test.jsx.snap +0 -27
- package/src/collapsible/__tests__/__snapshots__/index.test.jsx.snap +0 -18
|
@@ -1,13 +1,39 @@
|
|
|
1
|
-
import toJson from 'enzyme-to-json';
|
|
2
|
-
import { shallow } from 'enzyme/build';
|
|
3
|
-
import { Collapsible } from '../index';
|
|
4
1
|
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { Collapsible } from '../index';
|
|
5
5
|
|
|
6
6
|
describe('collapsible', () => {
|
|
7
|
-
describe('
|
|
8
|
-
it('renders', () => {
|
|
9
|
-
const
|
|
10
|
-
expect(
|
|
7
|
+
describe('rendering', () => {
|
|
8
|
+
it('renders collapsible component', () => {
|
|
9
|
+
const { container } = render(<Collapsible classes={{}} />);
|
|
10
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('renders with default collapsed state', () => {
|
|
14
|
+
render(<Collapsible classes={{}} labels={{ hidden: 'Show More', visible: 'Show Less' }} />);
|
|
15
|
+
// Should show "Show More" when collapsed
|
|
16
|
+
expect(screen.queryByText('Show More')).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('renders children when expanded', async () => {
|
|
20
|
+
const user = userEvent.setup();
|
|
21
|
+
render(
|
|
22
|
+
<Collapsible classes={{}}>
|
|
23
|
+
<div>Test Content</div>
|
|
24
|
+
</Collapsible>,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Initially collapsed, children not visible
|
|
28
|
+
expect(screen.queryByText('Test Content')).not.toBeInTheDocument();
|
|
29
|
+
|
|
30
|
+
// Click to expand
|
|
31
|
+
const toggleButton = screen.getByText('Show');
|
|
32
|
+
await user.click(toggleButton);
|
|
33
|
+
|
|
34
|
+
// Wait for expansion animation and check children are visible
|
|
35
|
+
await screen.findByText('Test Content');
|
|
36
|
+
expect(screen.getByText('Test Content')).toBeInTheDocument();
|
|
11
37
|
});
|
|
12
38
|
});
|
|
13
39
|
});
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import Collapse from '@material
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
|
+
import Collapse from '@mui/material/Collapse';
|
|
4
4
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
|
|
7
|
+
const Title = styled('span')(({ theme }) => ({
|
|
8
|
+
color: theme.palette.primary.light,
|
|
9
|
+
borderBottom: `1px dotted ${theme.palette.primary.light}`,
|
|
10
|
+
cursor: 'pointer',
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
const StyledCollapse = styled(Collapse)(({ theme }) => ({
|
|
14
|
+
paddingTop: theme.spacing(2),
|
|
15
|
+
}));
|
|
16
|
+
|
|
7
17
|
export class Collapsible extends React.Component {
|
|
8
18
|
static propTypes = {
|
|
9
|
-
classes: PropTypes.object.isRequired,
|
|
10
19
|
className: PropTypes.string,
|
|
11
20
|
children: PropTypes.object,
|
|
12
21
|
labels: PropTypes.shape({
|
|
@@ -36,29 +45,20 @@ export class Collapsible extends React.Component {
|
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
render() {
|
|
39
|
-
const {
|
|
48
|
+
const { labels, children, className } = this.props;
|
|
40
49
|
const title = this.state.expanded ? labels.visible || 'Hide' : labels.hidden || 'Show';
|
|
41
50
|
|
|
42
51
|
return (
|
|
43
52
|
<div className={className} ref={(r) => (this.root = r)}>
|
|
44
53
|
<div onClick={this.toggleExpanded}>
|
|
45
|
-
<
|
|
54
|
+
<Title>{title}</Title>
|
|
46
55
|
</div>
|
|
47
|
-
<
|
|
56
|
+
<StyledCollapse in={this.state.expanded} timeout={{ enter: 225, exit: 195 }} unmountOnExit>
|
|
48
57
|
{children}
|
|
49
|
-
</
|
|
58
|
+
</StyledCollapse>
|
|
50
59
|
</div>
|
|
51
60
|
);
|
|
52
61
|
}
|
|
53
62
|
}
|
|
54
63
|
|
|
55
|
-
export default
|
|
56
|
-
title: {
|
|
57
|
-
color: theme.palette.primary.light,
|
|
58
|
-
borderBottom: `1px dotted ${theme.palette.primary.light}`,
|
|
59
|
-
cursor: 'pointer',
|
|
60
|
-
},
|
|
61
|
-
collapsible: {
|
|
62
|
-
paddingTop: theme.spacing.unit * 2,
|
|
63
|
-
},
|
|
64
|
-
}))(Collapsible);
|
|
64
|
+
export default Collapsible;
|
package/src/color.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import green from '@material
|
|
2
|
-
import orange from '@material-ui/core/colors/orange';
|
|
3
|
-
import pink from '@material-ui/core/colors/pink';
|
|
4
|
-
import indigo from '@material-ui/core/colors/indigo';
|
|
5
|
-
import red from '@material-ui/core/colors/red';
|
|
1
|
+
import { green, orange, pink, indigo, red } from '@mui/material/colors';
|
|
6
2
|
|
|
7
3
|
export const defaults = {
|
|
8
4
|
TEXT: 'black',
|
package/src/feedback.jsx
CHANGED
|
@@ -1,98 +1,94 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lifted from multiple-choice - TODO: create a shared package for it.
|
|
3
|
-
*/
|
|
4
|
-
import { withStyles } from '@material-ui/core/styles';
|
|
5
|
-
|
|
6
1
|
import React from 'react';
|
|
7
|
-
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
8
|
-
import classNames from 'classnames';
|
|
9
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
10
5
|
import * as color from './color';
|
|
11
6
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
color: '#946202',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
content: {
|
|
23
|
-
'-webkit-font-smoothing': 'antialiased',
|
|
24
|
-
backgroundColor: `var(--feedback-bg-color, ${color.disabled()})`,
|
|
25
|
-
borderRadius: '4px',
|
|
26
|
-
lineHeight: '25px',
|
|
27
|
-
margin: '0px',
|
|
28
|
-
padding: '10px',
|
|
29
|
-
verticalAlign: 'middle',
|
|
30
|
-
color: 'var(--feedback-color, white)',
|
|
7
|
+
const FeedbackContainer = styled('div')({
|
|
8
|
+
transformOrigin: '0% 0px 0px',
|
|
9
|
+
width: '100%',
|
|
10
|
+
display: 'block',
|
|
11
|
+
overflow: 'hidden',
|
|
12
|
+
'&.incorrect': {
|
|
13
|
+
color: '#946202',
|
|
31
14
|
},
|
|
32
|
-
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const FeedbackContent = styled('div')({
|
|
18
|
+
WebkitFontSmoothing: 'antialiased',
|
|
19
|
+
backgroundColor: `var(--feedback-bg-color, ${color.disabled()})`,
|
|
20
|
+
borderRadius: '4px',
|
|
21
|
+
lineHeight: '25px',
|
|
22
|
+
margin: '0px',
|
|
23
|
+
padding: '10px',
|
|
24
|
+
verticalAlign: 'middle',
|
|
25
|
+
color: 'var(--feedback-color, white)',
|
|
26
|
+
'&.correct': {
|
|
33
27
|
backgroundColor: `var(--feedback-correct-bg-color, ${color.correct()})`,
|
|
34
28
|
},
|
|
35
|
-
incorrect: {
|
|
29
|
+
'&.incorrect': {
|
|
36
30
|
backgroundColor: `var(--feedback-incorrect-bg-color, ${color.incorrect()})`,
|
|
37
31
|
},
|
|
38
|
-
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const TransitionWrapper = styled('div')({
|
|
35
|
+
'&.feedback-enter': {
|
|
39
36
|
height: '1px',
|
|
40
37
|
},
|
|
41
|
-
|
|
38
|
+
'&.feedback-enter-active': {
|
|
42
39
|
height: '45px',
|
|
43
40
|
transition: 'height 500ms',
|
|
44
41
|
},
|
|
45
|
-
|
|
42
|
+
'&.feedback-exit': {
|
|
46
43
|
height: '45px',
|
|
47
44
|
},
|
|
48
|
-
|
|
45
|
+
'&.feedback-exit-active': {
|
|
49
46
|
height: '1px',
|
|
50
47
|
transition: 'height 200ms',
|
|
51
48
|
},
|
|
52
|
-
};
|
|
49
|
+
});
|
|
53
50
|
|
|
54
51
|
export class Feedback extends React.Component {
|
|
55
52
|
static propTypes = {
|
|
56
53
|
correctness: PropTypes.string,
|
|
57
54
|
feedback: PropTypes.string,
|
|
58
|
-
classes: PropTypes.object.isRequired,
|
|
59
55
|
};
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
const { correctness, feedback, classes } = this.props;
|
|
57
|
+
nodeRef = React.createRef();
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<CSSTransition
|
|
68
|
-
classNames={{
|
|
69
|
-
enter: classes.feedbackEnter,
|
|
70
|
-
enterActive: classes.feedbackEnterActive,
|
|
71
|
-
leave: classes.feedbackLeave,
|
|
72
|
-
leaveActive: classes.feedbackLeaveActive,
|
|
73
|
-
}}
|
|
74
|
-
key="hasFeedback"
|
|
75
|
-
timeout={{ enter: 500, exit: 300 }}
|
|
76
|
-
>
|
|
77
|
-
<div className={classes.corespringFeedback}>
|
|
78
|
-
<div
|
|
79
|
-
className={classNames(classes.content, classes[correctness])}
|
|
80
|
-
dangerouslySetInnerHTML={{ __html: feedback }}
|
|
81
|
-
/>
|
|
82
|
-
</div>
|
|
83
|
-
</CSSTransition>
|
|
84
|
-
);
|
|
85
|
-
} else {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
59
|
+
renderFeedback() {
|
|
60
|
+
const { correctness, feedback } = this.props;
|
|
89
61
|
|
|
62
|
+
if (!correctness || !feedback) return null;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<CSSTransition
|
|
66
|
+
key="hasFeedback"
|
|
67
|
+
nodeRef={this.nodeRef}
|
|
68
|
+
timeout={{ enter: 500, exit: 200 }}
|
|
69
|
+
classNames="feedback"
|
|
70
|
+
>
|
|
71
|
+
<TransitionWrapper ref={this.nodeRef}>
|
|
72
|
+
<FeedbackContainer>
|
|
73
|
+
<FeedbackContent
|
|
74
|
+
className={correctness}
|
|
75
|
+
dangerouslySetInnerHTML={{ __html: feedback }}
|
|
76
|
+
/>
|
|
77
|
+
</FeedbackContainer>
|
|
78
|
+
</TransitionWrapper>
|
|
79
|
+
</CSSTransition>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
render() {
|
|
90
84
|
return (
|
|
91
85
|
<div>
|
|
92
|
-
<TransitionGroup>
|
|
86
|
+
<TransitionGroup>
|
|
87
|
+
{this.renderFeedback()}
|
|
88
|
+
</TransitionGroup>
|
|
93
89
|
</div>
|
|
94
90
|
);
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
93
|
|
|
98
|
-
export default
|
|
94
|
+
export default Feedback;
|
package/src/input-container.jsx
CHANGED
|
@@ -1,41 +1,50 @@
|
|
|
1
|
-
import InputLabel from '@material
|
|
1
|
+
import InputLabel from '@mui/material/InputLabel';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import FormControl from '@material-ui/core/FormControl';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import FormControl from '@mui/material/FormControl';
|
|
7
6
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const StyledFormControl = styled(FormControl)(({ theme }) => ({
|
|
8
|
+
margin: 0,
|
|
9
|
+
padding: 0,
|
|
10
|
+
flex: '1 0 auto',
|
|
11
|
+
minWidth: theme.spacing(4),
|
|
12
|
+
}));
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const StyledInputLabel = styled(InputLabel)(() => ({
|
|
15
|
+
fontSize: 'inherit',
|
|
16
|
+
whiteSpace: 'nowrap',
|
|
17
|
+
margin: 0,
|
|
18
|
+
padding: 0,
|
|
19
|
+
alignSelf: 'flex-start',
|
|
20
|
+
position: 'absolute',
|
|
21
|
+
top: 0,
|
|
22
|
+
left: 0,
|
|
23
|
+
transformOrigin: 'top left',
|
|
24
|
+
pointerEvents: 'none',
|
|
25
|
+
// override MUI's default transform styles
|
|
26
|
+
'&.MuiInputLabel-shrink': {
|
|
27
|
+
transform: 'scale(0.75) translate(0, -0.75em)',
|
|
28
|
+
},
|
|
29
|
+
'&:not(.MuiInputLabel-shrink)': {
|
|
30
|
+
transform: 'translate(0, 0)',
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
21
33
|
|
|
22
|
-
|
|
34
|
+
const InputContainer = ({ label, className, children }) => (
|
|
35
|
+
<StyledFormControl className={className}>
|
|
36
|
+
<StyledInputLabel shrink>{label}</StyledInputLabel>
|
|
37
|
+
{children}
|
|
38
|
+
</StyledFormControl>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
InputContainer.propTypes = {
|
|
23
42
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
|
|
24
43
|
className: PropTypes.string,
|
|
25
|
-
children: PropTypes.oneOfType([
|
|
26
|
-
|
|
44
|
+
children: PropTypes.oneOfType([
|
|
45
|
+
PropTypes.arrayOf(PropTypes.node),
|
|
46
|
+
PropTypes.node,
|
|
47
|
+
]).isRequired,
|
|
27
48
|
};
|
|
28
49
|
|
|
29
|
-
export default
|
|
30
|
-
formControl: {
|
|
31
|
-
marginLeft: 0,
|
|
32
|
-
marginRight: 0,
|
|
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);
|
|
50
|
+
export default InputContainer;
|
package/src/preview-layout.jsx
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import UiLayout from './ui-layout';
|
|
5
5
|
|
|
6
|
+
const StyledUiLayout = styled(UiLayout)({
|
|
7
|
+
display: 'flex',
|
|
8
|
+
flexDirection: 'column',
|
|
9
|
+
position: 'relative',
|
|
10
|
+
});
|
|
11
|
+
|
|
6
12
|
class PreviewLayout extends React.Component {
|
|
7
13
|
static propTypes = {
|
|
8
14
|
ariaLabel: PropTypes.string,
|
|
9
15
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
10
|
-
classes: PropTypes.object,
|
|
11
16
|
role: PropTypes.string,
|
|
12
17
|
extraCSSRules: PropTypes.shape({
|
|
13
18
|
names: PropTypes.arrayOf(PropTypes.string),
|
|
@@ -17,32 +22,15 @@ class PreviewLayout extends React.Component {
|
|
|
17
22
|
};
|
|
18
23
|
|
|
19
24
|
render() {
|
|
20
|
-
const { children,
|
|
25
|
+
const { children, ariaLabel, role, extraCSSRules, fontSizeFactor, classes } = this.props;
|
|
21
26
|
const accessibility = ariaLabel ? { 'aria-label': ariaLabel, role } : {};
|
|
22
27
|
|
|
23
28
|
return (
|
|
24
|
-
<
|
|
25
|
-
className={classes.container}
|
|
26
|
-
{...accessibility}
|
|
27
|
-
extraCSSRules={extraCSSRules}
|
|
28
|
-
fontSizeFactor={fontSizeFactor}
|
|
29
|
-
>
|
|
29
|
+
<StyledUiLayout {...accessibility} extraCSSRules={extraCSSRules} fontSizeFactor={fontSizeFactor} classes={classes}>
|
|
30
30
|
{children}
|
|
31
|
-
</
|
|
31
|
+
</StyledUiLayout>
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
container: {
|
|
38
|
-
display: 'flex',
|
|
39
|
-
flexDirection: 'column',
|
|
40
|
-
position: 'relative',
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const Styled = withStyles(styles)(PreviewLayout);
|
|
45
|
-
|
|
46
|
-
const RootElem = (props) => <Styled {...props} />;
|
|
47
|
-
|
|
48
|
-
export default RootElem;
|
|
36
|
+
export default PreviewLayout;
|
package/src/preview-prompt.jsx
CHANGED
|
@@ -1,7 +1,58 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import * as color from './color';
|
|
5
|
+
import { renderMath } from '@pie-lib/math-rendering';
|
|
6
|
+
|
|
7
|
+
const StyledPromptContainer = styled('div')(({ theme, tagName }) => ({
|
|
8
|
+
// Base promptTable styles
|
|
9
|
+
'&:not(.MathJax) > table': {
|
|
10
|
+
borderCollapse: 'collapse',
|
|
11
|
+
},
|
|
12
|
+
// Apply vertical striping when first column is a header (th) and NOT mixed with td
|
|
13
|
+
'&:not(.MathJax) > table:has(tbody tr > th:first-child):not(:has(tbody tr > td:first-child)) tbody td:nth-child(even)': {
|
|
14
|
+
backgroundColor: '#f6f8fa',
|
|
15
|
+
color: theme.palette.common.black,
|
|
16
|
+
},
|
|
17
|
+
// Apply horizontal striping for tables where first element is a data cell (td)
|
|
18
|
+
'&:not(.MathJax) > table:has(tbody tr > td:first-child) tbody tr:nth-child(even) td': {
|
|
19
|
+
backgroundColor: '#f6f8fa',
|
|
20
|
+
color: theme.palette.common.black,
|
|
21
|
+
},
|
|
22
|
+
// align table content to left as per STAR requirement PD-3687
|
|
23
|
+
'&:not(.MathJax) table td, &:not(.MathJax) table th': {
|
|
24
|
+
padding: '.6em 1em',
|
|
25
|
+
textAlign: 'left',
|
|
26
|
+
},
|
|
27
|
+
// added this to fix alignment of text in prompt imported from studio (PD-3423)
|
|
28
|
+
'&:not(.MathJax) > table td > p.kds-indent': {
|
|
29
|
+
textAlign: 'initial',
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
// Conditional styles based on class names
|
|
33
|
+
'&.prompt': {
|
|
34
|
+
verticalAlign: 'middle',
|
|
35
|
+
color: color.text(),
|
|
36
|
+
},
|
|
37
|
+
'&.legend': {
|
|
38
|
+
width: '100%',
|
|
39
|
+
fontSize: 'inherit !important',
|
|
40
|
+
},
|
|
41
|
+
'&.rationale': {
|
|
42
|
+
paddingLeft: theme.spacing(4),
|
|
43
|
+
paddingBottom: theme.spacing(1),
|
|
44
|
+
},
|
|
45
|
+
'&.label': {
|
|
46
|
+
color: `${color.text()} !important`,
|
|
47
|
+
display: 'flex',
|
|
48
|
+
flexDirection: 'column',
|
|
49
|
+
verticalAlign: 'middle',
|
|
50
|
+
cursor: 'pointer',
|
|
51
|
+
'& > p': {
|
|
52
|
+
margin: '0 0 0 0 !important',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}));
|
|
5
56
|
|
|
6
57
|
//Used these below to replace \\embed{newLine} with \\newline from prompt which will get parsed in MathJax
|
|
7
58
|
const NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
|
|
@@ -9,7 +60,6 @@ const NEWLINE_LATEX = '\\newline ';
|
|
|
9
60
|
|
|
10
61
|
export class PreviewPrompt extends Component {
|
|
11
62
|
static propTypes = {
|
|
12
|
-
classes: PropTypes.object,
|
|
13
63
|
prompt: PropTypes.string,
|
|
14
64
|
tagName: PropTypes.string,
|
|
15
65
|
className: PropTypes.string,
|
|
@@ -141,16 +191,32 @@ export class PreviewPrompt extends Component {
|
|
|
141
191
|
componentDidMount() {
|
|
142
192
|
this.alignImages();
|
|
143
193
|
this.addCustomAudioButtonControls();
|
|
194
|
+
this.setupMathRendering();
|
|
144
195
|
}
|
|
145
196
|
|
|
146
|
-
componentDidUpdate() {
|
|
197
|
+
componentDidUpdate(prevProps) {
|
|
147
198
|
this.alignImages();
|
|
199
|
+
|
|
200
|
+
if (prevProps.prompt !== this.props.prompt) {
|
|
201
|
+
this.renderMathContent();
|
|
202
|
+
}
|
|
148
203
|
}
|
|
149
204
|
|
|
150
205
|
componentWillUnmount() {
|
|
151
206
|
this.removeCustomAudioButtonListeners();
|
|
152
207
|
}
|
|
153
208
|
|
|
209
|
+
setupMathRendering() {
|
|
210
|
+
this.renderMathContent();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
renderMathContent() {
|
|
214
|
+
const container = document.getElementById('preview-prompt');
|
|
215
|
+
if (container && typeof renderMath === 'function') {
|
|
216
|
+
renderMath(container);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
154
220
|
alignImages() {
|
|
155
221
|
const previewPrompts = document.querySelectorAll('#preview-prompt');
|
|
156
222
|
|
|
@@ -186,19 +252,18 @@ export class PreviewPrompt extends Component {
|
|
|
186
252
|
}
|
|
187
253
|
|
|
188
254
|
render() {
|
|
189
|
-
const { prompt,
|
|
190
|
-
|
|
191
|
-
// legend tag was added once with accessibility tasks, wee need extra style to make it work with images alignment
|
|
255
|
+
const { prompt, tagName, className, onClick, defaultClassName } = this.props;
|
|
256
|
+
// legend tag was added once with accessibility tasks, we need extra style to make it work with images alignment
|
|
192
257
|
const legendClass = tagName === 'legend' ? 'legend' : '';
|
|
193
|
-
const customClasses = `${
|
|
194
|
-
legendClass
|
|
195
|
-
] || ''}`;
|
|
258
|
+
const customClasses = `${className || ''} ${defaultClassName || ''} ${legendClass}`.trim();
|
|
196
259
|
|
|
197
260
|
return (
|
|
198
|
-
<
|
|
261
|
+
<StyledPromptContainer
|
|
262
|
+
as={tagName || 'div'}
|
|
199
263
|
id={'preview-prompt'}
|
|
200
264
|
onClick={onClick}
|
|
201
265
|
className={customClasses}
|
|
266
|
+
tagName={tagName}
|
|
202
267
|
dangerouslySetInnerHTML={{
|
|
203
268
|
__html: this.parsedText(prompt || '').replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX),
|
|
204
269
|
}}
|
|
@@ -207,51 +272,4 @@ export class PreviewPrompt extends Component {
|
|
|
207
272
|
}
|
|
208
273
|
}
|
|
209
274
|
|
|
210
|
-
|
|
211
|
-
prompt: {
|
|
212
|
-
verticalAlign: 'middle',
|
|
213
|
-
color: color.text(),
|
|
214
|
-
},
|
|
215
|
-
legend: {
|
|
216
|
-
width: '100%',
|
|
217
|
-
fontSize: 'inherit !important',
|
|
218
|
-
},
|
|
219
|
-
rationale: {
|
|
220
|
-
paddingLeft: theme.spacing.unit * 4,
|
|
221
|
-
paddingBottom: theme.spacing.unit,
|
|
222
|
-
},
|
|
223
|
-
label: {
|
|
224
|
-
color: `${color.text()} !important`, //'var(--choice-input-color, black)',
|
|
225
|
-
display: 'flex',
|
|
226
|
-
flexDirection: 'column',
|
|
227
|
-
verticalAlign: 'middle',
|
|
228
|
-
cursor: 'pointer',
|
|
229
|
-
'& > p': {
|
|
230
|
-
margin: '0 0 0 0 !important',
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
promptTable: {
|
|
234
|
-
'&:not(.MathJax) > table': {
|
|
235
|
-
borderCollapse: 'collapse',
|
|
236
|
-
},
|
|
237
|
-
'&:not(.MathJax) > table:has(tbody tr > th:first-child):not(:has(tbody tr > td:first-child)) tbody td:nth-child(even)': {
|
|
238
|
-
backgroundColor: '#f6f8fa',
|
|
239
|
-
color: theme.palette.common.black,
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
'&:not(.MathJax) > table:has(tbody tr > td:first-child) tbody tr:nth-child(even) td': {
|
|
243
|
-
backgroundColor: '#f6f8fa',
|
|
244
|
-
color: theme.palette.common.black,
|
|
245
|
-
},
|
|
246
|
-
// align table content to left as per STAR requirement PD-3687
|
|
247
|
-
'&:not(.MathJax) table td, &:not(.MathJax) table th': {
|
|
248
|
-
padding: '.6em 1em',
|
|
249
|
-
textAlign: 'left',
|
|
250
|
-
},
|
|
251
|
-
// added this to fix alignment of text in prompt imported from studio (PD-3423)
|
|
252
|
-
'&:not(.MathJax) > table td > p.kds-indent': {
|
|
253
|
-
textAlign: 'initial',
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
});
|
|
257
|
-
export default withStyles(styles)(PreviewPrompt);
|
|
275
|
+
export default PreviewPrompt;
|