@pie-lib/editable-html-tip-tap 1.2.0-next.8 → 2.0.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 +178 -0
- package/lib/components/CharacterPicker.js +1 -0
- package/lib/components/CharacterPicker.js.map +1 -1
- package/lib/components/EditableHtml.js +84 -43
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +74 -43
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/TiptapContainer.js +9 -8
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/icons/TextAlign.js +2 -2
- package/lib/components/icons/TextAlign.js.map +1 -1
- package/lib/components/image/InsertImageHandler.js +10 -13
- package/lib/components/image/InsertImageHandler.js.map +1 -1
- package/lib/components/media/MediaDialog.js.map +1 -1
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +6 -1
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -1
- package/lib/components/respArea/DragInTheBlank/choice.js +15 -7
- package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -1
- package/lib/components/respArea/ExplicitConstructedResponse.js +29 -11
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -1
- package/lib/components/respArea/InlineDropdown.js +35 -6
- 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/extensions/custom-toolbar-wrapper.js +3 -2
- package/lib/extensions/custom-toolbar-wrapper.js.map +1 -1
- package/lib/extensions/div-node.js +83 -0
- package/lib/extensions/div-node.js.map +1 -0
- package/lib/extensions/ensure-empty-root-div.js +48 -0
- package/lib/extensions/ensure-empty-root-div.js.map +1 -0
- package/lib/extensions/ensure-list-item-content-is-div.js +64 -0
- package/lib/extensions/ensure-list-item-content-is-div.js.map +1 -0
- package/lib/extensions/extended-list-item.js +15 -0
- package/lib/extensions/extended-list-item.js.map +1 -0
- package/lib/extensions/extended-table-cell.js +22 -0
- package/lib/extensions/extended-table-cell.js.map +1 -0
- package/lib/extensions/extended-table.js +50 -1
- package/lib/extensions/extended-table.js.map +1 -1
- package/lib/extensions/image-component.js +102 -51
- package/lib/extensions/image-component.js.map +1 -1
- package/lib/extensions/image.js +51 -2
- package/lib/extensions/image.js.map +1 -1
- package/lib/extensions/math.js +50 -9
- package/lib/extensions/math.js.map +1 -1
- package/lib/extensions/media.js +3 -1
- package/lib/extensions/media.js.map +1 -1
- package/lib/extensions/responseArea.js +22 -13
- package/lib/extensions/responseArea.js.map +1 -1
- package/lib/styles/editorContainerStyles.js +5 -4
- package/lib/styles/editorContainerStyles.js.map +1 -1
- package/lib/utils/helper.js +17 -0
- package/lib/utils/helper.js.map +1 -0
- package/package.json +8 -8
- package/src/__tests__/EditableHtml.test.jsx +93 -7
- package/src/__tests__/index.test.jsx +11 -3
- package/src/components/CharacterPicker.jsx +1 -0
- package/src/components/EditableHtml.jsx +93 -41
- package/src/components/MenuBar.jsx +57 -24
- package/src/components/TiptapContainer.jsx +10 -8
- package/src/components/__tests__/CharacterPicker.test.jsx +22 -0
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +55 -12
- package/src/components/__tests__/InlineDropdown.test.jsx +203 -10
- package/src/components/__tests__/InsertImageHandler.test.js +28 -21
- package/src/components/__tests__/MenuBar.test.jsx +32 -0
- package/src/components/icons/TextAlign.jsx +1 -1
- package/src/components/image/InsertImageHandler.js +9 -13
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.jsx +6 -1
- package/src/components/respArea/DragInTheBlank/choice.jsx +32 -4
- package/src/components/respArea/ExplicitConstructedResponse.jsx +33 -10
- package/src/components/respArea/InlineDropdown.jsx +45 -10
- 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__/ensure-empty-root-div.test.js +57 -0
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +44 -0
- package/src/extensions/__tests__/extended-list-item.test.js +13 -0
- package/src/extensions/__tests__/extended-table-cell.test.js +22 -0
- package/src/extensions/__tests__/extended-table.test.js +98 -1
- package/src/extensions/__tests__/image-component.test.jsx +105 -9
- package/src/extensions/__tests__/image.test.js +109 -8
- package/src/extensions/__tests__/math.test.js +348 -0
- package/src/extensions/__tests__/media-node-view.test.jsx +10 -8
- package/src/extensions/__tests__/responseArea.test.js +291 -0
- package/src/extensions/custom-toolbar-wrapper.jsx +2 -2
- package/src/extensions/div-node.js +86 -0
- package/src/extensions/ensure-empty-root-div.js +47 -0
- package/src/extensions/ensure-list-item-content-is-div.js +62 -0
- package/src/extensions/extended-list-item.js +10 -0
- package/src/extensions/extended-table-cell.js +19 -0
- package/src/extensions/extended-table.js +37 -1
- package/src/extensions/image-component.jsx +114 -69
- package/src/extensions/image.js +56 -1
- package/src/extensions/math.js +62 -10
- package/src/extensions/media.js +1 -1
- package/src/extensions/responseArea.js +15 -12
- package/src/styles/editorContainerStyles.js +5 -4
- package/src/utils/helper.js +17 -0
- /package/src/components/media/{MediaDialog.js → MediaDialog.jsx} +0 -0
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Editor } from '@tiptap/core';
|
|
2
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
3
|
+
import { DivNode } from '../div-node';
|
|
4
|
+
import { EnsureEmptyRootIsDiv } from '../ensure-empty-root-div';
|
|
5
|
+
|
|
6
|
+
/** Match EditableHtml so TrailingNode does not add a second empty block next to an empty paragraph. */
|
|
7
|
+
const starterKitConfigured = StarterKit.configure({
|
|
8
|
+
trailingNode: {
|
|
9
|
+
node: 'paragraph',
|
|
10
|
+
notAfter: ['paragraph', 'div'],
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('EnsureEmptyRootIsDiv', () => {
|
|
15
|
+
const extensions = [starterKitConfigured, DivNode, EnsureEmptyRootIsDiv];
|
|
16
|
+
|
|
17
|
+
let editor;
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
if (editor) {
|
|
21
|
+
editor.destroy();
|
|
22
|
+
editor = null;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('replaces a lone root paragraph with an empty div after select-all and delete (full delete flow)', () => {
|
|
27
|
+
editor = new Editor({
|
|
28
|
+
extensions,
|
|
29
|
+
content: '<p>hello</p>',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
editor.chain().focus().selectAll().deleteSelection().run();
|
|
33
|
+
|
|
34
|
+
expect(editor.state.doc.childCount).toBe(1);
|
|
35
|
+
expect(editor.state.doc.firstChild.type.name).toBe('div');
|
|
36
|
+
expect(editor.state.doc.firstChild.textContent).toBe('');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('does not replace a root paragraph that still has text', () => {
|
|
40
|
+
editor = new Editor({
|
|
41
|
+
extensions,
|
|
42
|
+
content: '<p>x</p>',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(editor.state.doc.firstChild.type.name).toBe('paragraph');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('does not run when there is more than one top-level block', () => {
|
|
49
|
+
editor = new Editor({
|
|
50
|
+
extensions,
|
|
51
|
+
content: '<p>a</p><p>b</p>',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(editor.state.doc.childCount).toBe(2);
|
|
55
|
+
expect(editor.state.doc.firstChild.type.name).toBe('paragraph');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EnsureListItemContentIsDiv } from '../ensure-list-item-content-is-div';
|
|
2
|
+
|
|
3
|
+
describe('EnsureListItemContentIsDiv', () => {
|
|
4
|
+
it('registers a ProseMirror plugin that rewrites listItem paragraph children to div', () => {
|
|
5
|
+
const plugins = EnsureListItemContentIsDiv.config.addProseMirrorPlugins();
|
|
6
|
+
expect(Array.isArray(plugins)).toBe(true);
|
|
7
|
+
expect(plugins).toHaveLength(1);
|
|
8
|
+
|
|
9
|
+
const plugin = plugins[0];
|
|
10
|
+
const divType = { name: 'div' };
|
|
11
|
+
const tr = { setNodeMarkup: jest.fn() };
|
|
12
|
+
|
|
13
|
+
const paragraphChild = {
|
|
14
|
+
type: { name: 'paragraph' },
|
|
15
|
+
attrs: { class: 'x' },
|
|
16
|
+
nodeSize: 6,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const listItemNode = {
|
|
20
|
+
type: { name: 'listItem' },
|
|
21
|
+
forEach: (cb) => cb(paragraphChild),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const newState = {
|
|
25
|
+
schema: { nodes: { div: divType } },
|
|
26
|
+
tr,
|
|
27
|
+
doc: {
|
|
28
|
+
descendants: (cb) => cb(listItemNode, 10),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const result = plugin.spec.appendTransaction([{ docChanged: true }], {}, newState);
|
|
33
|
+
|
|
34
|
+
expect(tr.setNodeMarkup).toHaveBeenCalledWith(11, divType, paragraphChild.attrs);
|
|
35
|
+
expect(result).toBe(tr);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns null when there is no document change', () => {
|
|
39
|
+
const plugin = EnsureListItemContentIsDiv.config.addProseMirrorPlugins()[0];
|
|
40
|
+
|
|
41
|
+
const result = plugin.spec.appendTransaction([{ docChanged: false }], {}, {});
|
|
42
|
+
expect(result).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExtendedListItem } from '../extended-list-item';
|
|
2
|
+
|
|
3
|
+
describe('ExtendedListItem', () => {
|
|
4
|
+
it('extends listItem and prefers div over paragraph in content spec', () => {
|
|
5
|
+
expect(ExtendedListItem.name).toBe('listItem');
|
|
6
|
+
|
|
7
|
+
const content =
|
|
8
|
+
ExtendedListItem.options?.content ?? ExtendedListItem.config?.content ?? ExtendedListItem.extendOptions?.content;
|
|
9
|
+
|
|
10
|
+
expect(String(content)).toMatch(/^\(div \| paragraph/);
|
|
11
|
+
expect(String(content)).toContain('imageUploadNode');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ExtendedTableCell, ExtendedTableHeader } from '../extended-table-cell';
|
|
2
|
+
|
|
3
|
+
describe('ExtendedTableCell / ExtendedTableHeader', () => {
|
|
4
|
+
it('exports cell and header extensions with div preferred over paragraph in content spec', () => {
|
|
5
|
+
expect(ExtendedTableCell.name).toBe('tableCell');
|
|
6
|
+
expect(ExtendedTableHeader.name).toBe('tableHeader');
|
|
7
|
+
|
|
8
|
+
const cellContent =
|
|
9
|
+
ExtendedTableCell.options?.content ??
|
|
10
|
+
ExtendedTableCell.config?.content ??
|
|
11
|
+
ExtendedTableCell.extendOptions?.content;
|
|
12
|
+
|
|
13
|
+
expect(String(cellContent)).toMatch(/^\(div \| paragraph/);
|
|
14
|
+
|
|
15
|
+
const headerContent =
|
|
16
|
+
ExtendedTableHeader.options?.content ??
|
|
17
|
+
ExtendedTableHeader.config?.content ??
|
|
18
|
+
ExtendedTableHeader.extendOptions?.content;
|
|
19
|
+
|
|
20
|
+
expect(headerContent).toBe(cellContent);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -1,12 +1,109 @@
|
|
|
1
|
-
import ExtendedTable from '../extended-table';
|
|
1
|
+
import ExtendedTable, { applyPresentationToTableElement, ExtendedTableView } from '../extended-table';
|
|
2
|
+
|
|
3
|
+
const mockTableViewState = { updateReturns: true };
|
|
2
4
|
|
|
3
5
|
jest.mock('@tiptap/extension-table', () => ({
|
|
4
6
|
Table: {
|
|
5
7
|
extend: jest.fn((config) => config),
|
|
6
8
|
},
|
|
9
|
+
TableView: class TableView {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.table = {
|
|
12
|
+
style: { setProperty: jest.fn() },
|
|
13
|
+
setAttribute: jest.fn(),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
update() {
|
|
18
|
+
return mockTableViewState.updateReturns;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
7
21
|
}));
|
|
8
22
|
|
|
9
23
|
describe('ExtendedTable', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
mockTableViewState.updateReturns = true;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('applyPresentationToTableElement', () => {
|
|
29
|
+
it('sets default border and theme styles', () => {
|
|
30
|
+
const table = document.createElement('table');
|
|
31
|
+
const setProperty = jest.spyOn(table.style, 'setProperty');
|
|
32
|
+
|
|
33
|
+
applyPresentationToTableElement(table, {});
|
|
34
|
+
|
|
35
|
+
expect(table.getAttribute('border')).toBe('1');
|
|
36
|
+
expect(setProperty).toHaveBeenCalledWith('color', 'var(--pie-text, black)');
|
|
37
|
+
expect(setProperty).toHaveBeenCalledWith('background-color', 'var(--pie-background, rgba(255, 255, 255))');
|
|
38
|
+
setProperty.mockRestore();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('uses explicit border from attrs', () => {
|
|
42
|
+
const table = document.createElement('table');
|
|
43
|
+
applyPresentationToTableElement(table, { border: '0' });
|
|
44
|
+
|
|
45
|
+
expect(table.getAttribute('border')).toBe('0');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('treats empty border as default', () => {
|
|
49
|
+
const table = document.createElement('table');
|
|
50
|
+
applyPresentationToTableElement(table, { border: '' });
|
|
51
|
+
|
|
52
|
+
expect(table.getAttribute('border')).toBe('1');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('ExtendedTableView', () => {
|
|
57
|
+
it('applies presentation after construction', () => {
|
|
58
|
+
const node = { attrs: { border: '2' } };
|
|
59
|
+
const view = new ExtendedTableView(node, 25);
|
|
60
|
+
|
|
61
|
+
expect(view.table.setAttribute).toHaveBeenCalledWith('border', '2');
|
|
62
|
+
expect(view.table.style.setProperty).toHaveBeenCalledWith('color', 'var(--pie-text, black)');
|
|
63
|
+
expect(view.table.style.setProperty).toHaveBeenCalledWith(
|
|
64
|
+
'background-color',
|
|
65
|
+
'var(--pie-background, rgba(255, 255, 255))',
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('reapplies presentation when super.update returns true', () => {
|
|
70
|
+
const view = new ExtendedTableView({ attrs: { border: '1' } }, 25);
|
|
71
|
+
view.table.setAttribute.mockClear();
|
|
72
|
+
view.table.style.setProperty.mockClear();
|
|
73
|
+
|
|
74
|
+
view.update({ attrs: { border: '0' } });
|
|
75
|
+
|
|
76
|
+
expect(view.table.setAttribute).toHaveBeenCalledWith('border', '0');
|
|
77
|
+
expect(view.table.style.setProperty).toHaveBeenCalledWith('color', 'var(--pie-text, black)');
|
|
78
|
+
expect(view.table.style.setProperty).toHaveBeenCalledWith(
|
|
79
|
+
'background-color',
|
|
80
|
+
'var(--pie-background, rgba(255, 255, 255))',
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('does not reapply presentation when super.update returns false', () => {
|
|
85
|
+
mockTableViewState.updateReturns = false;
|
|
86
|
+
const view = new ExtendedTableView({ attrs: { border: '1' } }, 25);
|
|
87
|
+
view.table.setAttribute.mockClear();
|
|
88
|
+
view.table.style.setProperty.mockClear();
|
|
89
|
+
|
|
90
|
+
const ok = view.update({ attrs: { border: '0' } });
|
|
91
|
+
|
|
92
|
+
expect(ok).toBe(false);
|
|
93
|
+
expect(view.table.setAttribute).not.toHaveBeenCalled();
|
|
94
|
+
expect(view.table.style.setProperty).not.toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('addOptions', () => {
|
|
99
|
+
it('enables resizable table view with zero handle width for colgroup sync', () => {
|
|
100
|
+
const options = ExtendedTable.addOptions();
|
|
101
|
+
expect(options.resizable).toBe(true);
|
|
102
|
+
expect(options.handleWidth).toBe(0);
|
|
103
|
+
expect(options.View).toBe(ExtendedTableView);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
10
107
|
describe('addAttributes', () => {
|
|
11
108
|
it('returns border attribute with default value', () => {
|
|
12
109
|
const attributes = ExtendedTable.addAttributes();
|