@pie-lib/mask-markup 1.13.46 → 1.14.1-beta.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/CHANGELOG.md +15 -56
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +9 -5
- package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +316 -0
- package/src/__tests__/__snapshots__/mask.test.js.snap +55 -0
- package/src/__tests__/__snapshots__/with-mask.test.js.snap +62 -0
- package/src/__tests__/drag-in-the-blank.test.js +71 -0
- package/src/__tests__/index.test.js +39 -0
- package/src/__tests__/mask.test.js +152 -0
- package/src/__tests__/serialization.test.js +54 -0
- package/src/__tests__/utils.js +1 -0
- package/src/__tests__/with-mask.test.js +51 -0
- package/src/choices/__tests__/__snapshots__/index.test.js.snap +209 -0
- package/src/choices/__tests__/index.test.js +62 -0
- package/src/choices/choice.jsx +60 -6
- package/src/choices/index.jsx +2 -2
- package/src/components/__tests__/__snapshots__/blank.test.js.snap +111 -0
- package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +64 -0
- package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +133 -0
- package/src/components/__tests__/__snapshots__/input.test.js.snap +34 -0
- package/src/components/__tests__/blank.test.js +202 -0
- package/src/components/__tests__/correct-input.test.js +49 -0
- package/src/components/__tests__/dropdown.test.js +51 -0
- package/src/components/__tests__/input.test.js +50 -0
- package/src/components/blank.jsx +139 -28
- package/src/components/correct-input.jsx +6 -1
- package/src/components/dropdown.jsx +192 -71
- package/src/constructed-response.jsx +76 -18
- package/src/customizable.jsx +35 -0
- package/src/drag-in-the-blank.jsx +26 -3
- package/src/index.js +10 -1
- package/src/inline-dropdown.jsx +2 -0
- package/src/mask.jsx +30 -5
- package/src/with-mask.jsx +39 -2
- package/README.md +0 -14
- package/lib/choices/choice.js +0 -158
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -127
- package/lib/choices/index.js.map +0 -1
- package/lib/componentize.js +0 -25
- package/lib/componentize.js.map +0 -1
- package/lib/components/blank.js +0 -303
- package/lib/components/blank.js.map +0 -1
- package/lib/components/correct-input.js +0 -113
- package/lib/components/correct-input.js.map +0 -1
- package/lib/components/dropdown.js +0 -216
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/input.js +0 -57
- package/lib/components/input.js.map +0 -1
- package/lib/constructed-response.js +0 -52
- package/lib/constructed-response.js.map +0 -1
- package/lib/drag-in-the-blank.js +0 -191
- package/lib/drag-in-the-blank.js.map +0 -1
- package/lib/index.js +0 -54
- package/lib/index.js.map +0 -1
- package/lib/inline-dropdown.js +0 -46
- package/lib/inline-dropdown.js.map +0 -1
- package/lib/mask.js +0 -215
- package/lib/mask.js.map +0 -1
- package/lib/serialization.js +0 -207
- package/lib/serialization.js.map +0 -1
- package/lib/with-mask.js +0 -93
- package/lib/with-mask.js.map +0 -1
|
@@ -1,34 +1,92 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
|
|
5
|
+
import { color } from '@pie-lib/render-ui';
|
|
6
|
+
import EditableHtml from '@pie-lib/editable-html';
|
|
3
7
|
import { withMask } from './with-mask';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const styles = () => ({
|
|
10
|
+
editableHtmlCustom: {
|
|
11
|
+
display: 'inline-block',
|
|
12
|
+
verticalAlign: 'middle',
|
|
13
|
+
margin: '4px',
|
|
14
|
+
borderRadius: '4px',
|
|
15
|
+
border: `1px solid ${color.black()}`,
|
|
16
|
+
},
|
|
17
|
+
correct: {
|
|
18
|
+
border: `1px solid ${color.correct()}`,
|
|
19
|
+
},
|
|
20
|
+
incorrect: {
|
|
21
|
+
border: `1px solid ${color.incorrect()}`,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
11
24
|
|
|
12
|
-
|
|
13
|
-
|
|
25
|
+
const MaskedInput = (props) => (node, data) => {
|
|
26
|
+
const {
|
|
27
|
+
adjustedLimit,
|
|
28
|
+
disabled,
|
|
29
|
+
feedback,
|
|
30
|
+
showCorrectAnswer,
|
|
31
|
+
maxLength,
|
|
32
|
+
spellCheck,
|
|
33
|
+
classes,
|
|
34
|
+
pluginProps,
|
|
35
|
+
onChange,
|
|
36
|
+
} = props;
|
|
37
|
+
const dataset = node.data?.dataset || {};
|
|
38
|
+
|
|
39
|
+
if (dataset.component === 'input') {
|
|
14
40
|
const correctAnswer = ((props.choices && dataset && props.choices[dataset.id]) || [])[0];
|
|
15
41
|
const finalValue = showCorrectAnswer ? correctAnswer && correctAnswer.label : data[dataset.id] || '';
|
|
16
42
|
const width = maxLength && maxLength[dataset.id];
|
|
43
|
+
const feedbackStatus = feedback && feedback[dataset.id];
|
|
44
|
+
const isCorrect = showCorrectAnswer || feedbackStatus === 'correct';
|
|
45
|
+
const isIncorrect = !showCorrectAnswer && feedbackStatus === 'incorrect';
|
|
46
|
+
|
|
47
|
+
const handleInputChange = (newValue) => {
|
|
48
|
+
const updatedValue = {
|
|
49
|
+
...data,
|
|
50
|
+
[dataset.id]: newValue,
|
|
51
|
+
};
|
|
52
|
+
onChange(updatedValue);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleKeyDown = (event) => {
|
|
56
|
+
// the keyCode value for the Enter/Return key is 13
|
|
57
|
+
if (event.key === 'Enter' || event.keyCode === 13) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
17
61
|
|
|
18
62
|
return (
|
|
19
|
-
<
|
|
63
|
+
<EditableHtml
|
|
64
|
+
id={dataset.id}
|
|
20
65
|
key={`${node.type}-input-${dataset.id}`}
|
|
21
|
-
correct={feedback && feedback[dataset.id] && feedback[dataset.id] === 'correct'}
|
|
22
66
|
disabled={showCorrectAnswer || disabled}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
showCorrectAnswer={showCorrectAnswer}
|
|
27
|
-
width={width}
|
|
67
|
+
disableUnderline
|
|
68
|
+
onChange={handleInputChange}
|
|
69
|
+
markup={finalValue || ''}
|
|
28
70
|
charactersLimit={adjustedLimit ? width : 25}
|
|
29
|
-
|
|
71
|
+
activePlugins={['languageCharacters']}
|
|
72
|
+
pluginProps={pluginProps}
|
|
73
|
+
languageCharactersProps={[{ language: 'spanish' }]}
|
|
30
74
|
spellCheck={spellCheck}
|
|
75
|
+
width={`calc(${width}em + 42px)`} // added 42px for left and right padding of editable-html
|
|
76
|
+
onKeyDown={handleKeyDown}
|
|
77
|
+
autoWidthToolbar
|
|
78
|
+
toolbarOpts={{
|
|
79
|
+
minWidth: 'auto',
|
|
80
|
+
noBorder: true,
|
|
81
|
+
isHidden: !!pluginProps?.characters?.disabled,
|
|
82
|
+
}}
|
|
83
|
+
className={classnames(classes.editableHtmlCustom, {
|
|
84
|
+
[classes.correct]: isCorrect,
|
|
85
|
+
[classes.incorrect]: isIncorrect,
|
|
86
|
+
})}
|
|
31
87
|
/>
|
|
32
88
|
);
|
|
33
89
|
}
|
|
34
|
-
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default withStyles(styles)(withMask('input', MaskedInput));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
// import Input from './components/input';
|
|
3
|
+
import { withMask } from './with-mask';
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line react/display-name
|
|
6
|
+
export default withMask('input', (props) => (node, data, onChange) => {
|
|
7
|
+
const dataset = node.data ? node.data.dataset || {} : {};
|
|
8
|
+
if (dataset.component === 'input') {
|
|
9
|
+
// eslint-disable-next-line react/prop-types
|
|
10
|
+
// const { adjustedLimit, disabled, feedback, showCorrectAnswer, maxLength, spellCheck } = props;
|
|
11
|
+
|
|
12
|
+
// the first answer is the correct one
|
|
13
|
+
// eslint-disable-next-line react/prop-types
|
|
14
|
+
// const correctAnswer = ((props.choices && dataset && props.choices[dataset.id]) || [])[0];
|
|
15
|
+
// const finalValue = showCorrectAnswer ? correctAnswer && correctAnswer.label : data[dataset.id] || '';
|
|
16
|
+
// const width = maxLength && maxLength[dataset.id];
|
|
17
|
+
|
|
18
|
+
return props.customMarkMarkupComponent(dataset.id);
|
|
19
|
+
// return (
|
|
20
|
+
// <Input
|
|
21
|
+
// key={`${node.type}-input-${dataset.id}`}
|
|
22
|
+
// correct={feedback && feedback[dataset.id] && feedback[dataset.id] === 'correct'}
|
|
23
|
+
// disabled={showCorrectAnswer || disabled}
|
|
24
|
+
// value={finalValue}
|
|
25
|
+
// id={dataset.id}
|
|
26
|
+
// onChange={onChange}
|
|
27
|
+
// showCorrectAnswer={showCorrectAnswer}
|
|
28
|
+
// width={width}
|
|
29
|
+
// charactersLimit={adjustedLimit ? width : 25}
|
|
30
|
+
// isConstructedResponse={true}
|
|
31
|
+
// spellCheck={spellCheck}
|
|
32
|
+
// />
|
|
33
|
+
// );
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -10,7 +10,15 @@ const Masked = withMask('blank', (props) => (node, data, onChange) => {
|
|
|
10
10
|
const dataset = node.data ? node.data.dataset || {} : {};
|
|
11
11
|
if (dataset.component === 'blank') {
|
|
12
12
|
// eslint-disable-next-line react/prop-types
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
disabled,
|
|
15
|
+
duplicates,
|
|
16
|
+
correctResponse,
|
|
17
|
+
feedback,
|
|
18
|
+
showCorrectAnswer,
|
|
19
|
+
emptyResponseAreaWidth,
|
|
20
|
+
emptyResponseAreaHeight,
|
|
21
|
+
} = props;
|
|
14
22
|
const choiceId = showCorrectAnswer ? correctResponse[dataset.id] : data[dataset.id];
|
|
15
23
|
// eslint-disable-next-line react/prop-types
|
|
16
24
|
const choice = choiceId && props.choices.find((c) => c.id === choiceId);
|
|
@@ -23,6 +31,8 @@ const Masked = withMask('blank', (props) => (node, data, onChange) => {
|
|
|
23
31
|
duplicates={duplicates}
|
|
24
32
|
choice={choice}
|
|
25
33
|
id={dataset.id}
|
|
34
|
+
emptyResponseAreaWidth={emptyResponseAreaWidth}
|
|
35
|
+
emptyResponseAreaHeight={emptyResponseAreaHeight}
|
|
26
36
|
onChange={onChange}
|
|
27
37
|
/>
|
|
28
38
|
);
|
|
@@ -42,6 +52,8 @@ export default class DragInTheBlank extends React.Component {
|
|
|
42
52
|
feedback: PropTypes.object,
|
|
43
53
|
correctResponse: PropTypes.object,
|
|
44
54
|
showCorrectAnswer: PropTypes.bool,
|
|
55
|
+
emptyResponseAreaWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
56
|
+
emptyResponseAreaHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
45
57
|
};
|
|
46
58
|
|
|
47
59
|
UNSAFE_componentWillReceiveProps() {
|
|
@@ -56,13 +68,18 @@ export default class DragInTheBlank extends React.Component {
|
|
|
56
68
|
|
|
57
69
|
getPositionDirection = (choicePosition) => {
|
|
58
70
|
let flexDirection;
|
|
71
|
+
let justifyContent;
|
|
72
|
+
let alignItems;
|
|
59
73
|
|
|
60
74
|
switch (choicePosition) {
|
|
61
75
|
case 'left':
|
|
62
76
|
flexDirection = 'row';
|
|
77
|
+
alignItems = 'center';
|
|
63
78
|
break;
|
|
64
79
|
case 'right':
|
|
65
80
|
flexDirection = 'row-reverse';
|
|
81
|
+
justifyContent = 'flex-end';
|
|
82
|
+
alignItems = 'center';
|
|
66
83
|
break;
|
|
67
84
|
case 'below':
|
|
68
85
|
flexDirection = 'column-reverse';
|
|
@@ -73,7 +90,7 @@ export default class DragInTheBlank extends React.Component {
|
|
|
73
90
|
break;
|
|
74
91
|
}
|
|
75
92
|
|
|
76
|
-
return flexDirection;
|
|
93
|
+
return { flexDirection, justifyContent, alignItems };
|
|
77
94
|
};
|
|
78
95
|
|
|
79
96
|
render() {
|
|
@@ -89,12 +106,15 @@ export default class DragInTheBlank extends React.Component {
|
|
|
89
106
|
disabled,
|
|
90
107
|
feedback,
|
|
91
108
|
showCorrectAnswer,
|
|
109
|
+
emptyResponseAreaWidth,
|
|
110
|
+
emptyResponseAreaHeight,
|
|
92
111
|
} = this.props;
|
|
93
112
|
|
|
94
113
|
const choicePosition = choicesPosition || 'below';
|
|
95
114
|
const style = {
|
|
96
115
|
display: 'flex',
|
|
97
|
-
|
|
116
|
+
minWidth: '100px',
|
|
117
|
+
...this.getPositionDirection(choicePosition),
|
|
98
118
|
};
|
|
99
119
|
|
|
100
120
|
return (
|
|
@@ -107,6 +127,7 @@ export default class DragInTheBlank extends React.Component {
|
|
|
107
127
|
disabled={disabled}
|
|
108
128
|
/>
|
|
109
129
|
<Masked
|
|
130
|
+
elementType={'drag-in-the-blank'}
|
|
110
131
|
markup={markup}
|
|
111
132
|
layout={layout}
|
|
112
133
|
value={value}
|
|
@@ -117,6 +138,8 @@ export default class DragInTheBlank extends React.Component {
|
|
|
117
138
|
feedback={feedback}
|
|
118
139
|
correctResponse={correctResponse}
|
|
119
140
|
showCorrectAnswer={showCorrectAnswer}
|
|
141
|
+
emptyResponseAreaWidth={emptyResponseAreaWidth}
|
|
142
|
+
emptyResponseAreaHeight={emptyResponseAreaHeight}
|
|
120
143
|
/>
|
|
121
144
|
</div>
|
|
122
145
|
);
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { withMask, buildLayoutFromMarkup } from './with-mask';
|
|
2
2
|
import DragInTheBlank from './drag-in-the-blank';
|
|
3
3
|
import ConstructedResponse from './constructed-response';
|
|
4
|
+
import Customizable from './customizable';
|
|
4
5
|
import InlineDropdown from './inline-dropdown';
|
|
5
6
|
import componentize from './componentize';
|
|
6
7
|
|
|
7
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
withMask,
|
|
10
|
+
buildLayoutFromMarkup,
|
|
11
|
+
DragInTheBlank,
|
|
12
|
+
ConstructedResponse,
|
|
13
|
+
InlineDropdown,
|
|
14
|
+
componentize,
|
|
15
|
+
Customizable,
|
|
16
|
+
};
|
package/src/inline-dropdown.jsx
CHANGED
|
@@ -17,10 +17,12 @@ export default withMask('dropdown', (props) => (node, data, onChange) => {
|
|
|
17
17
|
correct={feedback && feedback[dataset.id] && feedback[dataset.id] === 'correct'}
|
|
18
18
|
disabled={disabled || showCorrectAnswer}
|
|
19
19
|
value={finalChoice}
|
|
20
|
+
correctValue={showCorrectAnswer ? correctAnswer && correctAnswer.label : undefined}
|
|
20
21
|
id={dataset.id}
|
|
21
22
|
onChange={onChange}
|
|
22
23
|
choices={choices[dataset.id]}
|
|
23
24
|
showCorrectAnswer={showCorrectAnswer}
|
|
25
|
+
singleQuery={Object.keys(choices).length == 1}
|
|
24
26
|
/>
|
|
25
27
|
);
|
|
26
28
|
}
|
package/src/mask.jsx
CHANGED
|
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import { withStyles } from '@material-ui/core/styles';
|
|
5
5
|
import { MARK_TAGS } from './serialization';
|
|
6
|
+
import cx from 'classnames';
|
|
6
7
|
|
|
7
8
|
const Paragraph = withStyles((theme) => ({
|
|
8
9
|
para: {
|
|
@@ -11,6 +12,13 @@ const Paragraph = withStyles((theme) => ({
|
|
|
11
12
|
},
|
|
12
13
|
}))((props) => <div className={props.classes.para}>{props.children}</div>);
|
|
13
14
|
|
|
15
|
+
const Spacer = withStyles(() => ({
|
|
16
|
+
spacer: {
|
|
17
|
+
display: 'inline-block',
|
|
18
|
+
width: '.75em',
|
|
19
|
+
},
|
|
20
|
+
}))((props) => <span className={props.classes.spacer} />);
|
|
21
|
+
|
|
14
22
|
const restrictWhitespaceTypes = ['tbody', 'tr'];
|
|
15
23
|
|
|
16
24
|
const addText = (parentNode, text) => {
|
|
@@ -34,7 +42,7 @@ const getMark = (n) => {
|
|
|
34
42
|
return null;
|
|
35
43
|
};
|
|
36
44
|
|
|
37
|
-
export const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode) => {
|
|
45
|
+
export const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode, elementType) => {
|
|
38
46
|
if (!value) {
|
|
39
47
|
return null;
|
|
40
48
|
}
|
|
@@ -59,6 +67,9 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
|
|
|
59
67
|
const c = rootRenderChildren(n, value, onChange);
|
|
60
68
|
if (c) {
|
|
61
69
|
children.push(c);
|
|
70
|
+
if (parentNode?.type !== 'td' && elementType === 'drag-in-the-blank') {
|
|
71
|
+
children.push(<Spacer key={`spacer-${index}`} />);
|
|
72
|
+
}
|
|
62
73
|
return;
|
|
63
74
|
}
|
|
64
75
|
}
|
|
@@ -84,9 +95,12 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
|
|
|
84
95
|
}
|
|
85
96
|
} else if (content.length > 0) {
|
|
86
97
|
children.push(content);
|
|
98
|
+
if (parentNode?.type !== 'td' && elementType === 'drag-in-the-blank') {
|
|
99
|
+
children.push(<Spacer key={`spacer-${index}`} />);
|
|
100
|
+
}
|
|
87
101
|
}
|
|
88
102
|
} else {
|
|
89
|
-
const subNodes = renderChildren(n, value, onChange, rootRenderChildren, n);
|
|
103
|
+
const subNodes = renderChildren(n, value, onChange, rootRenderChildren, n, elementType);
|
|
90
104
|
if (n.type === 'p' || n.type === 'paragraph') {
|
|
91
105
|
children.push(<Paragraph key={key}>{subNodes}</Paragraph>);
|
|
92
106
|
} else {
|
|
@@ -110,7 +124,17 @@ const MaskContainer = withStyles(() => ({
|
|
|
110
124
|
main: {
|
|
111
125
|
display: 'initial',
|
|
112
126
|
},
|
|
113
|
-
|
|
127
|
+
tableStyle: {
|
|
128
|
+
'&:not(.MathJax) table': {
|
|
129
|
+
borderCollapse: 'collapse',
|
|
130
|
+
},
|
|
131
|
+
// align table content to left as per STAR requirement PD-3687
|
|
132
|
+
'&:not(.MathJax) table td, &:not(.MathJax) table th': {
|
|
133
|
+
padding: '8px 12px',
|
|
134
|
+
textAlign: 'left',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
}))((props) => <div className={cx(props.classes.main, props.classes.tableStyle)}>{props.children}</div>);
|
|
114
138
|
|
|
115
139
|
/**
|
|
116
140
|
* Renders a layout that uses the slate.js Value model structure.
|
|
@@ -121,6 +145,7 @@ export default class Mask extends React.Component {
|
|
|
121
145
|
layout: PropTypes.object,
|
|
122
146
|
value: PropTypes.object,
|
|
123
147
|
onChange: PropTypes.func,
|
|
148
|
+
elementType: PropTypes.string,
|
|
124
149
|
};
|
|
125
150
|
|
|
126
151
|
handleChange = (id, value) => {
|
|
@@ -129,8 +154,8 @@ export default class Mask extends React.Component {
|
|
|
129
154
|
};
|
|
130
155
|
|
|
131
156
|
render() {
|
|
132
|
-
const { value, layout } = this.props;
|
|
133
|
-
const children = renderChildren(layout, value, this.handleChange, this.props.renderChildren);
|
|
157
|
+
const { value, layout, elementType } = this.props;
|
|
158
|
+
const children = renderChildren(layout, value, this.handleChange, this.props.renderChildren, null, elementType);
|
|
134
159
|
|
|
135
160
|
return <MaskContainer>{children}</MaskContainer>;
|
|
136
161
|
}
|
package/src/with-mask.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import Mask from './mask';
|
|
4
5
|
import componentize from './componentize';
|
|
@@ -23,13 +24,49 @@ export const withMask = (type, renderChildren) => {
|
|
|
23
24
|
layout: PropTypes.object,
|
|
24
25
|
value: PropTypes.object,
|
|
25
26
|
onChange: PropTypes.func,
|
|
27
|
+
customMarkMarkupComponent: PropTypes.func,
|
|
28
|
+
elementType: PropTypes.string,
|
|
26
29
|
};
|
|
27
30
|
|
|
31
|
+
componentDidUpdate(prevProps) {
|
|
32
|
+
if (this.props.markup !== prevProps.markup) {
|
|
33
|
+
// eslint-disable-next-line
|
|
34
|
+
const domNode = ReactDOM.findDOMNode(this);
|
|
35
|
+
// Query all elements that may contain outdated MathJax renderings
|
|
36
|
+
const mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled="true"]');
|
|
37
|
+
|
|
38
|
+
// Clean up for fresh MathJax processing
|
|
39
|
+
(mathElements || []).forEach((el) => {
|
|
40
|
+
// Remove the MathJax container to allow for clean updates
|
|
41
|
+
const mjxContainer = el.querySelector('mjx-container');
|
|
42
|
+
|
|
43
|
+
if (mjxContainer) {
|
|
44
|
+
el.removeChild(mjxContainer);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly
|
|
48
|
+
const latexCode = el.getAttribute('data-raw');
|
|
49
|
+
el.innerHTML = latexCode;
|
|
50
|
+
|
|
51
|
+
// Remove the attribute to signal that MathJax should reprocess this element
|
|
52
|
+
el.removeAttribute('data-math-handled');
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
28
57
|
render() {
|
|
29
|
-
const { markup, layout, value, onChange } = this.props;
|
|
58
|
+
const { markup, layout, value, onChange, elementType } = this.props;
|
|
30
59
|
|
|
31
60
|
const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
|
|
32
|
-
return
|
|
61
|
+
return (
|
|
62
|
+
<Mask
|
|
63
|
+
elementType={elementType}
|
|
64
|
+
layout={maskLayout}
|
|
65
|
+
value={value}
|
|
66
|
+
onChange={onChange}
|
|
67
|
+
renderChildren={renderChildren(this.props)}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
33
70
|
}
|
|
34
71
|
};
|
|
35
72
|
};
|
package/README.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# mask-markup
|
|
2
|
-
|
|
3
|
-
## issues
|
|
4
|
-
|
|
5
|
-
- dnd
|
|
6
|
-
- simple approach loses context due to stepping out of react tree to run a ReactDOM.render().
|
|
7
|
-
- Would need to pass drag parts as props (no context)
|
|
8
|
-
- Or do the entire tree render in react - like a simple slate
|
|
9
|
-
- HTML5Backend - ? going to be a an issue w/ multiple items using dnd?
|
|
10
|
-
|
|
11
|
-
* hey diddle sample
|
|
12
|
-
* add feedback
|
|
13
|
-
* check perf
|
|
14
|
-
* more complex html
|
package/lib/choices/choice.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = exports.DRAG_TYPE = exports.BlankContent = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
|
|
16
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
-
|
|
18
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
-
|
|
20
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
-
|
|
22
|
-
var _react = _interopRequireDefault(require("react"));
|
|
23
|
-
|
|
24
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
25
|
-
|
|
26
|
-
var _drag = require("@pie-lib/drag");
|
|
27
|
-
|
|
28
|
-
var _styles = require("@material-ui/core/styles");
|
|
29
|
-
|
|
30
|
-
var _Chip = _interopRequireDefault(require("@material-ui/core/Chip"));
|
|
31
|
-
|
|
32
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
33
|
-
|
|
34
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
35
|
-
|
|
36
|
-
var _mathRendering = require("@pie-lib/math-rendering");
|
|
37
|
-
|
|
38
|
-
var _renderUi = require("@pie-lib/render-ui");
|
|
39
|
-
|
|
40
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
41
|
-
|
|
42
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
43
|
-
|
|
44
|
-
var DRAG_TYPE = 'MaskBlank';
|
|
45
|
-
exports.DRAG_TYPE = DRAG_TYPE;
|
|
46
|
-
|
|
47
|
-
var BlankContentComp = /*#__PURE__*/function (_React$Component) {
|
|
48
|
-
(0, _inherits2["default"])(BlankContentComp, _React$Component);
|
|
49
|
-
|
|
50
|
-
var _super = _createSuper(BlankContentComp);
|
|
51
|
-
|
|
52
|
-
function BlankContentComp() {
|
|
53
|
-
(0, _classCallCheck2["default"])(this, BlankContentComp);
|
|
54
|
-
return _super.apply(this, arguments);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
(0, _createClass2["default"])(BlankContentComp, [{
|
|
58
|
-
key: "componentDidUpdate",
|
|
59
|
-
value: function componentDidUpdate() {
|
|
60
|
-
(0, _mathRendering.renderMath)(this.rootRef);
|
|
61
|
-
}
|
|
62
|
-
}, {
|
|
63
|
-
key: "render",
|
|
64
|
-
value: function render() {
|
|
65
|
-
var _this = this;
|
|
66
|
-
|
|
67
|
-
var _this$props = this.props,
|
|
68
|
-
connectDragSource = _this$props.connectDragSource,
|
|
69
|
-
choice = _this$props.choice,
|
|
70
|
-
classes = _this$props.classes,
|
|
71
|
-
disabled = _this$props.disabled; // TODO the Chip element is causing drag problems on touch devices. Avoid using Chip and consider refactoring the code. Keep in mind that Chip is a span with a button role, which interferes with seamless touch device dragging.
|
|
72
|
-
|
|
73
|
-
return connectDragSource( /*#__PURE__*/_react["default"].createElement("span", {
|
|
74
|
-
className: (0, _classnames["default"])(classes.choice, disabled && classes.disabled)
|
|
75
|
-
}, /*#__PURE__*/_react["default"].createElement(_Chip["default"], {
|
|
76
|
-
clickable: false,
|
|
77
|
-
disabled: true,
|
|
78
|
-
ref: function ref(_ref2) {
|
|
79
|
-
//eslint-disable-next-line
|
|
80
|
-
_this.rootRef = _reactDom["default"].findDOMNode(_ref2);
|
|
81
|
-
},
|
|
82
|
-
className: classes.chip,
|
|
83
|
-
label: /*#__PURE__*/_react["default"].createElement("span", {
|
|
84
|
-
className: classes.chipLabel,
|
|
85
|
-
ref: function ref(_ref) {
|
|
86
|
-
if (_ref) {
|
|
87
|
-
_ref.innerHTML = choice.value || ' ';
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, ' '),
|
|
91
|
-
variant: disabled ? 'outlined' : undefined
|
|
92
|
-
})), {});
|
|
93
|
-
}
|
|
94
|
-
}]);
|
|
95
|
-
return BlankContentComp;
|
|
96
|
-
}(_react["default"].Component);
|
|
97
|
-
|
|
98
|
-
(0, _defineProperty2["default"])(BlankContentComp, "propTypes", {
|
|
99
|
-
disabled: _propTypes["default"].bool,
|
|
100
|
-
choice: _propTypes["default"].object,
|
|
101
|
-
classes: _propTypes["default"].object,
|
|
102
|
-
connectDragSource: _propTypes["default"].func
|
|
103
|
-
});
|
|
104
|
-
var BlankContent = (0, _styles.withStyles)(function (theme) {
|
|
105
|
-
return {
|
|
106
|
-
choice: {
|
|
107
|
-
border: "solid 0px ".concat(theme.palette.primary.main),
|
|
108
|
-
borderRadius: theme.spacing.unit * 2,
|
|
109
|
-
margin: theme.spacing.unit / 2,
|
|
110
|
-
transform: 'translate(0, 0)'
|
|
111
|
-
},
|
|
112
|
-
chip: {
|
|
113
|
-
backgroundColor: _renderUi.color.background(),
|
|
114
|
-
border: "1px solid ".concat(_renderUi.color.text()),
|
|
115
|
-
color: _renderUi.color.text(),
|
|
116
|
-
alignItems: 'center',
|
|
117
|
-
display: 'inline-flex',
|
|
118
|
-
height: 'initial',
|
|
119
|
-
minHeight: '32px',
|
|
120
|
-
fontSize: 'inherit',
|
|
121
|
-
whiteSpace: 'pre-wrap',
|
|
122
|
-
maxWidth: '374px',
|
|
123
|
-
// Added for touch devices, for image content.
|
|
124
|
-
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
125
|
-
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
126
|
-
pointerEvents: 'none'
|
|
127
|
-
},
|
|
128
|
-
chipLabel: {
|
|
129
|
-
whiteSpace: 'pre-wrap',
|
|
130
|
-
'& img': {
|
|
131
|
-
display: 'block',
|
|
132
|
-
padding: '2px 0'
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
disabled: {}
|
|
136
|
-
};
|
|
137
|
-
})(BlankContentComp);
|
|
138
|
-
exports.BlankContent = BlankContent;
|
|
139
|
-
var tileSource = {
|
|
140
|
-
canDrag: function canDrag(props) {
|
|
141
|
-
return !props.disabled;
|
|
142
|
-
},
|
|
143
|
-
beginDrag: function beginDrag(props) {
|
|
144
|
-
return {
|
|
145
|
-
choice: props.choice,
|
|
146
|
-
instanceId: props.instanceId
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
var DragDropTile = (0, _drag.DragSource)(DRAG_TYPE, tileSource, function (connect, monitor) {
|
|
151
|
-
return {
|
|
152
|
-
connectDragSource: connect.dragSource(),
|
|
153
|
-
isDragging: monitor.isDragging()
|
|
154
|
-
};
|
|
155
|
-
})(BlankContent);
|
|
156
|
-
var _default = DragDropTile;
|
|
157
|
-
exports["default"] = _default;
|
|
158
|
-
//# sourceMappingURL=choice.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/choices/choice.jsx"],"names":["DRAG_TYPE","BlankContentComp","rootRef","props","connectDragSource","choice","classes","disabled","ref","ReactDOM","findDOMNode","chip","chipLabel","innerHTML","value","undefined","React","Component","PropTypes","bool","object","func","BlankContent","theme","border","palette","primary","main","borderRadius","spacing","unit","margin","transform","backgroundColor","color","background","text","alignItems","display","height","minHeight","fontSize","whiteSpace","maxWidth","pointerEvents","padding","tileSource","canDrag","beginDrag","instanceId","DragDropTile","connect","monitor","dragSource","isDragging"],"mappings":"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","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { DragSource } from '@pie-lib/drag';\nimport { withStyles } from '@material-ui/core/styles';\nimport Chip from '@material-ui/core/Chip';\nimport classnames from 'classnames';\nimport ReactDOM from 'react-dom';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { color } from '@pie-lib/render-ui';\n\nexport const DRAG_TYPE = 'MaskBlank';\n\nclass BlankContentComp extends React.Component {\n static propTypes = {\n disabled: PropTypes.bool,\n choice: PropTypes.object,\n classes: PropTypes.object,\n connectDragSource: PropTypes.func,\n };\n\n componentDidUpdate() {\n renderMath(this.rootRef);\n }\n\n render() {\n const { connectDragSource, choice, classes, disabled } = this.props;\n\n // TODO the Chip element is causing drag problems on touch devices. Avoid using Chip and consider refactoring the code. Keep in mind that Chip is a span with a button role, which interferes with seamless touch device dragging.\n\n return connectDragSource(\n <span className={classnames(classes.choice, disabled && classes.disabled)}>\n <Chip\n clickable={false}\n disabled={true}\n ref={(ref) => {\n //eslint-disable-next-line\n this.rootRef = ReactDOM.findDOMNode(ref);\n }}\n className={classes.chip}\n label={\n <span\n className={classes.chipLabel}\n ref={(ref) => {\n if (ref) {\n ref.innerHTML = choice.value || ' ';\n }\n }}\n >\n {' '}\n </span>\n }\n variant={disabled ? 'outlined' : undefined}\n />\n </span>,\n {},\n );\n }\n}\n\nexport const BlankContent = withStyles((theme) => ({\n choice: {\n border: `solid 0px ${theme.palette.primary.main}`,\n borderRadius: theme.spacing.unit * 2,\n margin: theme.spacing.unit / 2,\n transform: 'translate(0, 0)',\n },\n chip: {\n backgroundColor: color.background(),\n border: `1px solid ${color.text()}`,\n color: color.text(),\n alignItems: 'center',\n display: 'inline-flex',\n height: 'initial',\n minHeight: '32px',\n fontSize: 'inherit',\n whiteSpace: 'pre-wrap',\n maxWidth: '374px',\n // Added for touch devices, for image content.\n // This will prevent the context menu from appearing and not allowing other interactions with the image.\n // If interactions with the image in the token will be requested we should handle only the context Menu.\n pointerEvents: 'none',\n },\n chipLabel: {\n whiteSpace: 'pre-wrap',\n '& img': {\n display: 'block',\n padding: '2px 0',\n },\n },\n disabled: {},\n}))(BlankContentComp);\n\nconst tileSource = {\n canDrag(props) {\n return !props.disabled;\n },\n beginDrag(props) {\n return {\n choice: props.choice,\n instanceId: props.instanceId,\n };\n },\n};\n\nconst DragDropTile = DragSource(DRAG_TYPE, tileSource, (connect, monitor) => ({\n connectDragSource: connect.dragSource(),\n isDragging: monitor.isDragging(),\n}))(BlankContent);\n\nexport default DragDropTile;\n"],"file":"choice.js"}
|