@pie-lib/editable-html-tip-tap 1.2.0-next.2 → 1.2.0-next.21
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 +115 -21
- package/LICENSE.md +5 -0
- package/lib/components/CharacterPicker.js +2 -1
- package/lib/components/CharacterPicker.js.map +1 -1
- package/lib/components/EditableHtml.js +34 -17
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +77 -45
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/TiptapContainer.js +15 -9
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/characters/characterUtils.js +1 -1
- package/lib/components/characters/custom-popper.js +1 -1
- package/lib/components/common/done-button.js +1 -1
- package/lib/components/common/toolbar-buttons.js +1 -1
- package/lib/components/icons/CssIcon.js +1 -1
- package/lib/components/icons/RespArea.js +1 -1
- package/lib/components/icons/TableIcons.js +1 -1
- package/lib/components/icons/TextAlign.js +3 -3
- package/lib/components/icons/TextAlign.js.map +1 -1
- package/lib/components/image/AltDialog.js +1 -1
- package/lib/components/image/ImageToolbar.js +1 -1
- package/lib/components/image/InsertImageHandler.js +1 -1
- package/lib/components/media/MediaDialog.js +1 -1
- package/lib/components/media/MediaToolbar.js +1 -1
- package/lib/components/media/MediaWrapper.js +1 -1
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +7 -2
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -1
- package/lib/components/respArea/DragInTheBlank/choice.js +16 -8
- package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -1
- package/lib/components/respArea/ExplicitConstructedResponse.js +2 -2
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -1
- package/lib/components/respArea/InlineDropdown.js +11 -4
- package/lib/components/respArea/InlineDropdown.js.map +1 -1
- package/lib/components/respArea/MathTemplated.js +130 -0
- package/lib/components/respArea/MathTemplated.js.map +1 -0
- package/lib/components/respArea/ToolbarIcon.js +1 -1
- package/lib/constants.js +1 -1
- package/lib/extensions/css.js +1 -1
- package/lib/extensions/custom-toolbar-wrapper.js +1 -1
- package/lib/extensions/div-node.js +39 -0
- package/lib/extensions/div-node.js.map +1 -0
- package/lib/extensions/extended-table.js +1 -1
- package/lib/extensions/image-component.js +1 -1
- package/lib/extensions/image-component.js.map +1 -1
- package/lib/extensions/image.js +1 -1
- package/lib/extensions/index.js +4 -2
- package/lib/extensions/index.js.map +1 -1
- package/lib/extensions/math.js +7 -4
- package/lib/extensions/math.js.map +1 -1
- package/lib/extensions/media.js +15 -12
- package/lib/extensions/media.js.map +1 -1
- package/lib/extensions/responseArea.js +13 -10
- package/lib/extensions/responseArea.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/styles/editorContainerStyles.js +6 -5
- package/lib/styles/editorContainerStyles.js.map +1 -1
- package/lib/theme.js +1 -1
- package/lib/utils/helper.js +17 -0
- package/lib/utils/helper.js.map +1 -0
- package/lib/utils/size.js +1 -1
- package/package.json +11 -11
- package/src/__tests__/EditableHtml.test.jsx +41 -1
- package/src/__tests__/index.test.jsx +4 -1
- package/src/components/CharacterPicker.jsx +1 -0
- package/src/components/EditableHtml.jsx +40 -16
- package/src/components/MenuBar.jsx +66 -25
- package/src/components/TiptapContainer.jsx +10 -7
- package/src/components/__tests__/CharacterPicker.test.jsx +22 -0
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +1 -1
- package/src/components/__tests__/InlineDropdown.test.jsx +150 -1
- package/src/components/__tests__/MenuBar.test.jsx +32 -0
- package/src/components/icons/TextAlign.jsx +1 -1
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.jsx +6 -1
- package/src/components/respArea/DragInTheBlank/choice.jsx +32 -4
- package/src/components/respArea/ExplicitConstructedResponse.jsx +1 -1
- package/src/components/respArea/InlineDropdown.jsx +12 -2
- package/src/components/respArea/MathTemplated.jsx +124 -0
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +210 -0
- package/src/extensions/__tests__/divNode.test.js +87 -0
- package/src/extensions/__tests__/math.test.js +327 -0
- package/src/extensions/__tests__/media-node-view.test.jsx +296 -0
- package/src/extensions/__tests__/media.test.js +1 -0
- package/src/extensions/__tests__/responseArea.test.js +157 -0
- package/src/extensions/div-node.js +36 -0
- package/src/extensions/index.js +2 -0
- package/src/extensions/math.js +6 -3
- package/src/extensions/media.js +17 -14
- package/src/extensions/responseArea.js +4 -8
- package/src/styles/editorContainerStyles.js +5 -4
- package/src/utils/helper.js +17 -0
- package/lib/__tests__/EditableHtml.test.js +0 -377
- package/lib/__tests__/constants.test.js +0 -21
- package/lib/__tests__/extensions.test.js +0 -209
- package/lib/__tests__/index.test.js +0 -235
- package/lib/__tests__/size-utils.test.js +0 -57
- package/lib/__tests__/theme.test.js +0 -17
- package/lib/components/__tests__/AltDialog.test.js +0 -201
- package/lib/components/__tests__/CharacterPicker.test.js +0 -305
- package/lib/components/__tests__/CssIcon.test.js +0 -58
- package/lib/components/__tests__/DragInTheBlank.test.js +0 -295
- package/lib/components/__tests__/ExplicitConstructedResponse.test.js +0 -253
- package/lib/components/__tests__/ImageToolbar.test.js +0 -185
- package/lib/components/__tests__/InlineDropdown.test.js +0 -287
- package/lib/components/__tests__/InsertImageHandler.test.js +0 -162
- package/lib/components/__tests__/MediaDialog.test.js +0 -433
- package/lib/components/__tests__/MediaToolbar.test.js +0 -126
- package/lib/components/__tests__/MediaWrapper.test.js +0 -96
- package/lib/components/__tests__/MenuBar.test.js +0 -459
- package/lib/components/__tests__/RespArea.test.js +0 -171
- package/lib/components/__tests__/TableIcons.test.js +0 -153
- package/lib/components/__tests__/TextAlign.test.js +0 -209
- package/lib/components/__tests__/TiptapContainer.test.js +0 -196
- package/lib/components/__tests__/characterUtils.test.js +0 -178
- package/lib/components/__tests__/choice.test.js +0 -213
- package/lib/components/__tests__/custom-popper.test.js +0 -108
- package/lib/components/__tests__/done-button.test.js +0 -72
- package/lib/components/__tests__/toolbar-buttons.test.js +0 -277
- package/lib/extensions/__tests__/component.test.js +0 -314
- package/lib/extensions/__tests__/css.test.js +0 -214
- package/lib/extensions/__tests__/custom-toolbar-wrapper.test.js +0 -175
- package/lib/extensions/__tests__/extended-table.test.js +0 -92
- package/lib/extensions/__tests__/image-component.test.js +0 -305
- package/lib/extensions/__tests__/image.test.js +0 -164
- package/lib/extensions/__tests__/media.test.js +0 -292
- package/lib/extensions/__tests__/responseArea.test.js +0 -330
- package/lib/extensions/component.js +0 -305
|
@@ -11,10 +11,12 @@ const InlineDropdown = (props) => {
|
|
|
11
11
|
// TODO: Investigate
|
|
12
12
|
// Needed because items with values inside have different positioning for some reason
|
|
13
13
|
const html = value || '<div> </div>';
|
|
14
|
+
const pos = getPos();
|
|
14
15
|
const toolbarRef = useRef(null);
|
|
16
|
+
const toolbarEditor = useRef(null);
|
|
15
17
|
const [showToolbar, setShowToolbar] = useState(false);
|
|
16
18
|
const [position, setPosition] = useState({ top: 0, left: 0 });
|
|
17
|
-
const InlineDropdownToolbar = options.respAreaToolbar(node, editor, () => {});
|
|
19
|
+
const InlineDropdownToolbar = options.respAreaToolbar([node, pos], editor, () => {});
|
|
18
20
|
|
|
19
21
|
useEffect(() => {
|
|
20
22
|
const { selection } = editor.state;
|
|
@@ -41,7 +43,11 @@ const InlineDropdown = (props) => {
|
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
const handleClickOutside = (event) => {
|
|
46
|
+
const insideSomeEditor = event.target.closest('[data-toolbar-for]');
|
|
47
|
+
|
|
44
48
|
if (
|
|
49
|
+
(!insideSomeEditor || insideSomeEditor.dataset.toolbarFor !== toolbarEditor.current.instanceId) &&
|
|
50
|
+
!editor._toolbarOpened &&
|
|
45
51
|
toolbarRef.current &&
|
|
46
52
|
!toolbarRef.current.contains(event.target) &&
|
|
47
53
|
!event.target.closest('[data-inline-node]')
|
|
@@ -116,7 +122,11 @@ const InlineDropdown = (props) => {
|
|
|
116
122
|
{showToolbar &&
|
|
117
123
|
ReactDOM.createPortal(
|
|
118
124
|
<div ref={toolbarRef} style={{ zIndex: 1 }}>
|
|
119
|
-
<InlineDropdownToolbar
|
|
125
|
+
<InlineDropdownToolbar
|
|
126
|
+
editorCallback={(instance) => {
|
|
127
|
+
toolbarEditor.current = instance;
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
120
130
|
</div>,
|
|
121
131
|
document.body,
|
|
122
132
|
)}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { NodeViewWrapper } from '@tiptap/react';
|
|
4
|
+
import { mq } from '@pie-lib/math-input';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
|
|
7
|
+
const StyledSpanContainer = styled('span')(() => ({
|
|
8
|
+
display: 'inline-flex',
|
|
9
|
+
border: '1px solid #C0C3CF',
|
|
10
|
+
margin: '1px 5px',
|
|
11
|
+
cursor: 'pointer',
|
|
12
|
+
alignItems: 'center',
|
|
13
|
+
justifyContent: 'center',
|
|
14
|
+
minWidth: '50px',
|
|
15
|
+
minHeight: '36px',
|
|
16
|
+
height: 'fit-content',
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const StyledResponseBox = styled('div')(({ theme }) => ({
|
|
20
|
+
background: theme.palette.grey['A100'],
|
|
21
|
+
color: theme.palette.grey['A700'],
|
|
22
|
+
display: 'inline-flex',
|
|
23
|
+
borderRight: '2px solid #C0C3CF',
|
|
24
|
+
boxSizing: 'border-box',
|
|
25
|
+
overflow: 'hidden',
|
|
26
|
+
fontSize: '12px',
|
|
27
|
+
minHeight: '36px',
|
|
28
|
+
height: '100%',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
fontFamily: 'Symbola, Times New Roman, serif',
|
|
31
|
+
padding: '0 2px',
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
const StyledMathBlock = styled('div')(() => ({
|
|
35
|
+
flex: 8,
|
|
36
|
+
color: 'var(--pie-text, black)',
|
|
37
|
+
padding: '4px !important',
|
|
38
|
+
display: 'flex',
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
justifyContent: 'center',
|
|
41
|
+
backgroundColor: 'var(--pie-background, rgba(255, 255, 255, 0))',
|
|
42
|
+
'& > .mq-math-mode sup.mq-nthroot': {
|
|
43
|
+
fontSize: '70% !important',
|
|
44
|
+
verticalAlign: '1em !important',
|
|
45
|
+
},
|
|
46
|
+
'& > .mq-math-mode .mq-sqrt-stem': {
|
|
47
|
+
borderTop: '0.07em solid',
|
|
48
|
+
marginLeft: '-1.5px',
|
|
49
|
+
marginTop: '-2px !important',
|
|
50
|
+
paddingTop: '5px !important',
|
|
51
|
+
},
|
|
52
|
+
'& .mq-overarrow-inner': {
|
|
53
|
+
paddingTop: '0 !important',
|
|
54
|
+
border: 'none !important',
|
|
55
|
+
},
|
|
56
|
+
'& .mq-overarrow.mq-arrow-both': {
|
|
57
|
+
marginTop: '0px',
|
|
58
|
+
minWidth: '1.23em',
|
|
59
|
+
'& *': {
|
|
60
|
+
lineHeight: '1 !important',
|
|
61
|
+
},
|
|
62
|
+
'&:before': {
|
|
63
|
+
top: '-0.4em',
|
|
64
|
+
left: '-1px',
|
|
65
|
+
},
|
|
66
|
+
'&:after': {
|
|
67
|
+
top: '0px !important',
|
|
68
|
+
position: 'absolute !important',
|
|
69
|
+
right: '-2px',
|
|
70
|
+
},
|
|
71
|
+
'&.mq-empty:after': {
|
|
72
|
+
top: '-0.45em',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
'& .mq-overarrow.mq-arrow-right': {
|
|
76
|
+
'&:before': {
|
|
77
|
+
top: '-0.4em',
|
|
78
|
+
right: '-1px',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
'& .mq-overarrow-inner-right': {
|
|
82
|
+
display: 'none !important',
|
|
83
|
+
},
|
|
84
|
+
'& .mq-overarrow-inner-left': {
|
|
85
|
+
display: 'none !important',
|
|
86
|
+
},
|
|
87
|
+
}));
|
|
88
|
+
const MathTemplated = (props) => {
|
|
89
|
+
const { node, options, selected } = props;
|
|
90
|
+
const { attrs: attributes } = node;
|
|
91
|
+
const { value, index } = attributes;
|
|
92
|
+
|
|
93
|
+
// add 1 to index to display R 1 instead of R 0
|
|
94
|
+
const keyToDisplay = `R ${parseInt(index) + 1}`;
|
|
95
|
+
|
|
96
|
+
// console.log({nodeProps.children})
|
|
97
|
+
return (
|
|
98
|
+
<NodeViewWrapper
|
|
99
|
+
className="math-templated"
|
|
100
|
+
data-selected={selected}
|
|
101
|
+
style={{
|
|
102
|
+
display: 'inline-flex',
|
|
103
|
+
minHeight: '36px',
|
|
104
|
+
minWidth: '50px',
|
|
105
|
+
cursor: 'pointer',
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
<StyledSpanContainer {...attributes}>
|
|
109
|
+
<StyledResponseBox>{keyToDisplay}</StyledResponseBox>
|
|
110
|
+
<StyledMathBlock>
|
|
111
|
+
<mq.Static latex={value} />
|
|
112
|
+
</StyledMathBlock>
|
|
113
|
+
</StyledSpanContainer>
|
|
114
|
+
</NodeViewWrapper>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
MathTemplated.propTypes = {
|
|
119
|
+
attributes: PropTypes.object,
|
|
120
|
+
value: PropTypes.string,
|
|
121
|
+
keyToDisplay: PropTypes.string,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export default MathTemplated;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import MathTemplated from '../MathTemplated';
|
|
4
|
+
|
|
5
|
+
// Mock the dependencies
|
|
6
|
+
jest.mock('@tiptap/react', () => ({
|
|
7
|
+
NodeViewWrapper: ({ children, ...props }) => (
|
|
8
|
+
<div data-testid="node-view-wrapper" {...props}>
|
|
9
|
+
{children}
|
|
10
|
+
</div>
|
|
11
|
+
),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock('@pie-lib/math-input', () => ({
|
|
15
|
+
mq: {
|
|
16
|
+
Static: ({ latex }) => (
|
|
17
|
+
<div data-testid="mq-static" data-latex={latex}>
|
|
18
|
+
{latex}
|
|
19
|
+
</div>
|
|
20
|
+
),
|
|
21
|
+
},
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
describe('MathTemplated', () => {
|
|
25
|
+
const defaultProps = {
|
|
26
|
+
node: {
|
|
27
|
+
attrs: {
|
|
28
|
+
value: 'x^2 + y^2 = r^2',
|
|
29
|
+
index: 0,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
options: {},
|
|
33
|
+
selected: false,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
it('renders without crashing', () => {
|
|
37
|
+
const { container } = render(<MathTemplated {...defaultProps} />);
|
|
38
|
+
expect(container).toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('renders NodeViewWrapper with correct className', () => {
|
|
42
|
+
const { getByTestId } = render(<MathTemplated {...defaultProps} />);
|
|
43
|
+
const wrapper = getByTestId('node-view-wrapper');
|
|
44
|
+
expect(wrapper).toHaveClass('math-templated');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('displays correct response key for index 0', () => {
|
|
48
|
+
const { getByText } = render(<MathTemplated {...defaultProps} />);
|
|
49
|
+
expect(getByText('R 1')).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('displays correct response key for index 1', () => {
|
|
53
|
+
const props = {
|
|
54
|
+
...defaultProps,
|
|
55
|
+
node: {
|
|
56
|
+
attrs: {
|
|
57
|
+
value: 'a + b',
|
|
58
|
+
index: 1,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const { getByText } = render(<MathTemplated {...props} />);
|
|
63
|
+
expect(getByText('R 2')).toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('displays correct response key for index 5', () => {
|
|
67
|
+
const props = {
|
|
68
|
+
...defaultProps,
|
|
69
|
+
node: {
|
|
70
|
+
attrs: {
|
|
71
|
+
value: 'c = d',
|
|
72
|
+
index: 5,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const { getByText } = render(<MathTemplated {...props} />);
|
|
77
|
+
expect(getByText('R 6')).toBeInTheDocument();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('renders LaTeX value correctly', () => {
|
|
81
|
+
const { getByTestId } = render(<MathTemplated {...defaultProps} />);
|
|
82
|
+
const mqStatic = getByTestId('mq-static');
|
|
83
|
+
expect(mqStatic).toHaveAttribute('data-latex', 'x^2 + y^2 = r^2');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('renders different LaTeX value', () => {
|
|
87
|
+
const props = {
|
|
88
|
+
...defaultProps,
|
|
89
|
+
node: {
|
|
90
|
+
attrs: {
|
|
91
|
+
value: '\\frac{a}{b}',
|
|
92
|
+
index: 2,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
const { getByTestId } = render(<MathTemplated {...props} />);
|
|
97
|
+
const mqStatic = getByTestId('mq-static');
|
|
98
|
+
expect(mqStatic).toHaveAttribute('data-latex', '\\frac{a}{b}');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('passes selected prop to NodeViewWrapper', () => {
|
|
102
|
+
const props = {
|
|
103
|
+
...defaultProps,
|
|
104
|
+
selected: true,
|
|
105
|
+
};
|
|
106
|
+
const { getByTestId } = render(<MathTemplated {...props} />);
|
|
107
|
+
const wrapper = getByTestId('node-view-wrapper');
|
|
108
|
+
expect(wrapper).toHaveAttribute('data-selected', 'true');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('passes false selected prop to NodeViewWrapper', () => {
|
|
112
|
+
const { getByTestId } = render(<MathTemplated {...defaultProps} />);
|
|
113
|
+
const wrapper = getByTestId('node-view-wrapper');
|
|
114
|
+
expect(wrapper).toHaveAttribute('data-selected', 'false');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('applies correct inline styles to NodeViewWrapper', () => {
|
|
118
|
+
const { getByTestId } = render(<MathTemplated {...defaultProps} />);
|
|
119
|
+
const wrapper = getByTestId('node-view-wrapper');
|
|
120
|
+
expect(wrapper).toHaveStyle({
|
|
121
|
+
display: 'inline-flex',
|
|
122
|
+
minHeight: '36px',
|
|
123
|
+
minWidth: '50px',
|
|
124
|
+
cursor: 'pointer',
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('handles string index correctly', () => {
|
|
129
|
+
const props = {
|
|
130
|
+
...defaultProps,
|
|
131
|
+
node: {
|
|
132
|
+
attrs: {
|
|
133
|
+
value: 'test',
|
|
134
|
+
index: '3',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
const { getByText } = render(<MathTemplated {...props} />);
|
|
139
|
+
expect(getByText('R 4')).toBeInTheDocument();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('handles empty value', () => {
|
|
143
|
+
const props = {
|
|
144
|
+
...defaultProps,
|
|
145
|
+
node: {
|
|
146
|
+
attrs: {
|
|
147
|
+
value: '',
|
|
148
|
+
index: 0,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
const { getByTestId } = render(<MathTemplated {...props} />);
|
|
153
|
+
const mqStatic = getByTestId('mq-static');
|
|
154
|
+
expect(mqStatic).toHaveAttribute('data-latex', '');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('renders all styled components', () => {
|
|
158
|
+
const { container, getByText } = render(<MathTemplated {...defaultProps} />);
|
|
159
|
+
|
|
160
|
+
// Check for response box
|
|
161
|
+
expect(getByText('R 1')).toBeInTheDocument();
|
|
162
|
+
|
|
163
|
+
// Check for math block with LaTeX
|
|
164
|
+
const mqStatic = container.querySelector('[data-testid="mq-static"]');
|
|
165
|
+
expect(mqStatic).toBeInTheDocument();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('handles zero index', () => {
|
|
169
|
+
const props = {
|
|
170
|
+
...defaultProps,
|
|
171
|
+
node: {
|
|
172
|
+
attrs: {
|
|
173
|
+
value: 'x = 0',
|
|
174
|
+
index: 0,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const { getByText } = render(<MathTemplated {...props} />);
|
|
179
|
+
expect(getByText('R 1')).toBeInTheDocument();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('handles large index values', () => {
|
|
183
|
+
const props = {
|
|
184
|
+
...defaultProps,
|
|
185
|
+
node: {
|
|
186
|
+
attrs: {
|
|
187
|
+
value: 'x = 100',
|
|
188
|
+
index: 99,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
const { getByText } = render(<MathTemplated {...props} />);
|
|
193
|
+
expect(getByText('R 100')).toBeInTheDocument();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('renders with complex LaTeX expression', () => {
|
|
197
|
+
const props = {
|
|
198
|
+
...defaultProps,
|
|
199
|
+
node: {
|
|
200
|
+
attrs: {
|
|
201
|
+
value: '\\sqrt{x^2 + y^2}',
|
|
202
|
+
index: 0,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
const { getByTestId } = render(<MathTemplated {...props} />);
|
|
207
|
+
const mqStatic = getByTestId('mq-static');
|
|
208
|
+
expect(mqStatic).toHaveAttribute('data-latex', '\\sqrt{x^2 + y^2}');
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { DivNode } from '../div-node';
|
|
2
|
+
|
|
3
|
+
jest.mock('@tiptap/core', () => ({
|
|
4
|
+
Node: {
|
|
5
|
+
create: jest.fn((config) => config),
|
|
6
|
+
},
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe('DivNode', () => {
|
|
10
|
+
describe('configuration', () => {
|
|
11
|
+
it('has correct name', () => {
|
|
12
|
+
expect(DivNode.name).toBe('div');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('is block level', () => {
|
|
16
|
+
expect(DivNode.group).toBe('block');
|
|
17
|
+
expect(DivNode.content).toBe('inline*');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('parseHTML', () => {
|
|
22
|
+
it('parses <div> tags', () => {
|
|
23
|
+
const rules = DivNode.parseHTML();
|
|
24
|
+
|
|
25
|
+
expect(Array.isArray(rules)).toBe(true);
|
|
26
|
+
expect(rules).toHaveLength(1);
|
|
27
|
+
expect(rules[0]).toHaveProperty('tag', 'div');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('renderHTML', () => {
|
|
32
|
+
it('renders a <div> tag', () => {
|
|
33
|
+
const result = DivNode.renderHTML({ HTMLAttributes: { class: 'foo' } });
|
|
34
|
+
|
|
35
|
+
expect(result[0]).toBe('div');
|
|
36
|
+
expect(result[1]).toEqual({ class: 'foo' });
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('addKeyboardShortcuts', () => {
|
|
41
|
+
it('does nothing when current block is not div', () => {
|
|
42
|
+
const mockEditor = {
|
|
43
|
+
state: {
|
|
44
|
+
selection: {
|
|
45
|
+
$from: {
|
|
46
|
+
parent: { type: { name: 'paragraph' } },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const shortcuts = DivNode.addKeyboardShortcuts.call({ editor: mockEditor });
|
|
53
|
+
const handled = shortcuts.Enter();
|
|
54
|
+
|
|
55
|
+
expect(handled).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('turns div into paragraph and splits when Enter is pressed in a div', () => {
|
|
59
|
+
const chain = {
|
|
60
|
+
focus: jest.fn(() => chain),
|
|
61
|
+
setNode: jest.fn(() => chain),
|
|
62
|
+
splitBlock: jest.fn(() => chain),
|
|
63
|
+
run: jest.fn(() => true),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const mockEditor = {
|
|
67
|
+
state: {
|
|
68
|
+
selection: {
|
|
69
|
+
$from: {
|
|
70
|
+
parent: { type: { name: 'div' } },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
chain: () => chain,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const shortcuts = DivNode.addKeyboardShortcuts.call({ editor: mockEditor });
|
|
78
|
+
const handled = shortcuts.Enter();
|
|
79
|
+
|
|
80
|
+
expect(chain.focus).toHaveBeenCalled();
|
|
81
|
+
expect(chain.setNode).toHaveBeenCalledWith('paragraph');
|
|
82
|
+
expect(chain.splitBlock).toHaveBeenCalled();
|
|
83
|
+
expect(chain.run).toHaveBeenCalled();
|
|
84
|
+
expect(handled).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|