quill-table-up 2.0.1 → 2.0.3
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/dist/index.d.ts +5 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/table-creator.css +1 -1
- package/package.json +9 -14
- package/src/__tests__/e2e/custom-creator.test.ts +44 -0
- package/src/__tests__/e2e/table-align.test.ts +39 -0
- package/src/__tests__/e2e/table-resize.test.ts +152 -0
- package/src/__tests__/e2e/table-scrollbar.test.ts +31 -0
- package/src/__tests__/e2e/table-selection.test.ts +83 -0
- package/src/__tests__/e2e/utils.ts +6 -0
- package/src/__tests__/unit/table-insert-blot.test.ts +464 -0
- package/src/__tests__/unit/table-insert-remove-merge.test.ts +1270 -0
- package/src/__tests__/unit/table-redo-undo.test.ts +909 -0
- package/src/__tests__/unit/utils.test-d.ts +49 -0
- package/src/__tests__/unit/utils.test.ts +715 -0
- package/src/__tests__/unit/utils.ts +216 -0
- package/src/__tests__/unit/vitest.d.ts +12 -0
- package/src/formats/container-format.ts +52 -0
- package/src/formats/index.ts +10 -0
- package/src/formats/overrides/block.ts +93 -0
- package/src/formats/overrides/blockquote.ts +8 -0
- package/src/formats/overrides/code.ts +8 -0
- package/src/formats/overrides/header.ts +8 -0
- package/src/formats/overrides/index.ts +6 -0
- package/src/formats/overrides/list.ts +10 -0
- package/src/formats/overrides/scroll.ts +51 -0
- package/src/formats/table-body-format.ts +92 -0
- package/src/formats/table-cell-format.ts +139 -0
- package/src/formats/table-cell-inner-format.ts +251 -0
- package/src/formats/table-col-format.ts +174 -0
- package/src/formats/table-colgroup-format.ts +133 -0
- package/src/formats/table-main-format.ts +143 -0
- package/src/formats/table-row-format.ts +147 -0
- package/src/formats/table-wrapper-format.ts +55 -0
- package/src/formats/utils.ts +3 -0
- package/src/index.ts +1157 -0
- package/src/modules/index.ts +5 -0
- package/src/modules/table-align.ts +116 -0
- package/src/modules/table-menu/constants.ts +140 -0
- package/src/modules/table-menu/index.ts +3 -0
- package/src/modules/table-menu/table-menu-common.ts +249 -0
- package/src/modules/table-menu/table-menu-contextmenu.ts +94 -0
- package/src/modules/table-menu/table-menu-select.ts +28 -0
- package/src/modules/table-resize/index.ts +5 -0
- package/src/modules/table-resize/table-resize-box.ts +293 -0
- package/src/modules/table-resize/table-resize-common.ts +343 -0
- package/src/modules/table-resize/table-resize-line.ts +163 -0
- package/src/modules/table-resize/table-resize-scale.ts +154 -0
- package/src/modules/table-resize/utils.ts +3 -0
- package/src/modules/table-scrollbar.ts +255 -0
- package/src/modules/table-selection.ts +262 -0
- package/src/style/button.less +45 -0
- package/src/style/color-picker.less +134 -0
- package/src/style/dialog.less +53 -0
- package/src/style/functions.less +9 -0
- package/src/style/index.less +89 -0
- package/src/style/input.less +64 -0
- package/src/style/select-box.less +51 -0
- package/src/style/table-creator.less +68 -0
- package/src/style/table-menu.less +122 -0
- package/src/style/table-resize-scale.less +31 -0
- package/src/style/table-resize.less +183 -0
- package/src/style/table-scrollbar.less +49 -0
- package/src/style/table-selection.less +15 -0
- package/src/style/tooltip.less +19 -0
- package/src/style/variables.less +1 -0
- package/src/svg/background.svg +1 -0
- package/src/svg/border.svg +1 -0
- package/src/svg/color.svg +1 -0
- package/src/svg/insert-bottom.svg +1 -0
- package/src/svg/insert-left.svg +1 -0
- package/src/svg/insert-right.svg +1 -0
- package/src/svg/insert-top.svg +1 -0
- package/src/svg/merge-cell.svg +1 -0
- package/src/svg/remove-column.svg +1 -0
- package/src/svg/remove-row.svg +1 -0
- package/src/svg/remove-table.svg +1 -0
- package/src/svg/split-cell.svg +1 -0
- package/src/types.d.ts +4 -0
- package/src/utils/bem.ts +23 -0
- package/src/utils/color.ts +109 -0
- package/src/utils/components/button.ts +22 -0
- package/src/utils/components/color-picker.ts +236 -0
- package/src/utils/components/dialog.ts +41 -0
- package/src/utils/components/index.ts +6 -0
- package/src/utils/components/input.ts +74 -0
- package/src/utils/components/table/creator.ts +86 -0
- package/src/utils/components/table/index.ts +2 -0
- package/src/utils/components/table/select-box.ts +83 -0
- package/src/utils/components/tooltip.ts +186 -0
- package/src/utils/constants.ts +99 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/is.ts +6 -0
- package/src/utils/position.ts +21 -0
- package/src/utils/types.ts +131 -0
- package/src/utils/utils.ts +139 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import TableUp, { TableCellInnerFormat } from '../..';
|
|
3
|
+
import { createQuillWithTableModule, createTable, createTableDeltaOps, createTableHTML } from './utils';
|
|
4
|
+
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
vi.useFakeTimers();
|
|
7
|
+
});
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
vi.useRealTimers();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('insert embed blot', () => {
|
|
13
|
+
it('insert image', async () => {
|
|
14
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
15
|
+
quill.setContents([
|
|
16
|
+
{ insert: '\n' },
|
|
17
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: 'true', width: 100 } } },
|
|
18
|
+
{ insert: { image: 'https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/img/favicon144.png' } },
|
|
19
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
20
|
+
{ insert: '\n' },
|
|
21
|
+
]);
|
|
22
|
+
await vi.runAllTimersAsync();
|
|
23
|
+
expect(quill.root).toEqualHTML(
|
|
24
|
+
`
|
|
25
|
+
<p><br></p>
|
|
26
|
+
<div>
|
|
27
|
+
<table cellpadding="0" cellspacing="0" data-full="true">
|
|
28
|
+
<colgroup data-full="true">
|
|
29
|
+
<col width="100%" data-full="true" />
|
|
30
|
+
</colgroup>
|
|
31
|
+
<tbody>
|
|
32
|
+
<tr>
|
|
33
|
+
<td rowspan="1" colspan="1">
|
|
34
|
+
<div>
|
|
35
|
+
<p><img src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/img/favicon144.png" /></p>
|
|
36
|
+
</div>
|
|
37
|
+
</td>
|
|
38
|
+
</tr>
|
|
39
|
+
</tbody>
|
|
40
|
+
</table>
|
|
41
|
+
</div>
|
|
42
|
+
<p><br></p>
|
|
43
|
+
`,
|
|
44
|
+
{ ignoreAttrs: ['class', 'style', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('insert block blot', () => {
|
|
50
|
+
it('insert list', async () => {
|
|
51
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
52
|
+
quill.setContents([
|
|
53
|
+
{ insert: '\n' },
|
|
54
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: 'true', width: 100 } } },
|
|
55
|
+
{ insert: 'text' },
|
|
56
|
+
{ attributes: { 'list': 'bullet', 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
57
|
+
{ insert: '\n' },
|
|
58
|
+
]);
|
|
59
|
+
await vi.runAllTimersAsync();
|
|
60
|
+
expect(quill.root).toEqualHTML(
|
|
61
|
+
`
|
|
62
|
+
<p><br></p>
|
|
63
|
+
<div>
|
|
64
|
+
<table cellpadding="0" cellspacing="0" data-full="true">
|
|
65
|
+
<colgroup data-full="true">
|
|
66
|
+
<col width="100%" data-full="true" />
|
|
67
|
+
</colgroup>
|
|
68
|
+
<tbody>
|
|
69
|
+
<tr>
|
|
70
|
+
<td rowspan="1" colspan="1">
|
|
71
|
+
<div>
|
|
72
|
+
<ol>
|
|
73
|
+
<li data-list="bullet">text</li>
|
|
74
|
+
</ol>
|
|
75
|
+
</div>
|
|
76
|
+
</td>
|
|
77
|
+
</tr>
|
|
78
|
+
</tbody>
|
|
79
|
+
</table>
|
|
80
|
+
</div>
|
|
81
|
+
<p><br></p>
|
|
82
|
+
`,
|
|
83
|
+
{ ignoreAttrs: ['class', 'style', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('insert header', async () => {
|
|
88
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
89
|
+
quill.setContents([
|
|
90
|
+
{ insert: '\n' },
|
|
91
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: 'true', width: 100 } } },
|
|
92
|
+
{ insert: 'text' },
|
|
93
|
+
{ attributes: { 'header': 2, 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
94
|
+
{ insert: '\n' },
|
|
95
|
+
]);
|
|
96
|
+
await vi.runAllTimersAsync();
|
|
97
|
+
expect(quill.root).toEqualHTML(
|
|
98
|
+
`
|
|
99
|
+
<p><br></p>
|
|
100
|
+
<div>
|
|
101
|
+
<table cellpadding="0" cellspacing="0" data-full="true">
|
|
102
|
+
<colgroup data-full="true">
|
|
103
|
+
<col width="100%" data-full="true" />
|
|
104
|
+
</colgroup>
|
|
105
|
+
<tbody>
|
|
106
|
+
<tr>
|
|
107
|
+
<td rowspan="1" colspan="1">
|
|
108
|
+
<div>
|
|
109
|
+
<h2>text</h2>
|
|
110
|
+
</div>
|
|
111
|
+
</td>
|
|
112
|
+
</tr>
|
|
113
|
+
</tbody>
|
|
114
|
+
</table>
|
|
115
|
+
</div>
|
|
116
|
+
<p><br></p>
|
|
117
|
+
`,
|
|
118
|
+
{ ignoreAttrs: ['class', 'style', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('insert blockquote', async () => {
|
|
123
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
124
|
+
quill.setContents([
|
|
125
|
+
{ insert: '\n' },
|
|
126
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: 'true', width: 100 } } },
|
|
127
|
+
{ insert: 'text' },
|
|
128
|
+
{ attributes: { 'blockquote': true, 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
129
|
+
{ insert: '\n' },
|
|
130
|
+
]);
|
|
131
|
+
await vi.runAllTimersAsync();
|
|
132
|
+
expect(quill.root).toEqualHTML(
|
|
133
|
+
`
|
|
134
|
+
<p><br></p>
|
|
135
|
+
<div>
|
|
136
|
+
<table cellpadding="0" cellspacing="0" data-full="true">
|
|
137
|
+
<colgroup data-full="true">
|
|
138
|
+
<col width="100%" data-full="true" />
|
|
139
|
+
</colgroup>
|
|
140
|
+
<tbody>
|
|
141
|
+
<tr>
|
|
142
|
+
<td rowspan="1" colspan="1">
|
|
143
|
+
<div>
|
|
144
|
+
<blockquote>text</blockquote>
|
|
145
|
+
</div>
|
|
146
|
+
</td>
|
|
147
|
+
</tr>
|
|
148
|
+
</tbody>
|
|
149
|
+
</table>
|
|
150
|
+
</div>
|
|
151
|
+
<p><br></p>
|
|
152
|
+
`,
|
|
153
|
+
{ ignoreAttrs: ['class', 'style', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('insert code-block', async () => {
|
|
158
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
159
|
+
quill.setContents([
|
|
160
|
+
{ insert: '\n' },
|
|
161
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: 'true', width: 100 } } },
|
|
162
|
+
{ insert: 'text' },
|
|
163
|
+
{ attributes: { 'code-block': 'plain', 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
164
|
+
{ insert: 'br' },
|
|
165
|
+
{ attributes: { 'code-block': 'plain', 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
166
|
+
{ insert: '\n' },
|
|
167
|
+
]);
|
|
168
|
+
await vi.runAllTimersAsync();
|
|
169
|
+
expect(quill.root).toEqualHTML(
|
|
170
|
+
`
|
|
171
|
+
<p><br></p>
|
|
172
|
+
<div>
|
|
173
|
+
<table cellpadding="0" cellspacing="0" data-full="true">
|
|
174
|
+
<colgroup data-full="true">
|
|
175
|
+
<col width="100%" data-full="true" />
|
|
176
|
+
</colgroup>
|
|
177
|
+
<tbody>
|
|
178
|
+
<tr>
|
|
179
|
+
<td rowspan="1" colspan="1">
|
|
180
|
+
<div>
|
|
181
|
+
<div spellcheck="false">
|
|
182
|
+
<div data-language="plain">text</div>
|
|
183
|
+
<div data-language="plain">br</div>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
</td>
|
|
187
|
+
</tr>
|
|
188
|
+
</tbody>
|
|
189
|
+
</table>
|
|
190
|
+
</div>
|
|
191
|
+
<p><br></p>
|
|
192
|
+
`,
|
|
193
|
+
{ ignoreAttrs: ['class', 'style', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe('insert block embed blot', () => {
|
|
199
|
+
it('insert video', async () => {
|
|
200
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
201
|
+
quill.setContents([
|
|
202
|
+
{ insert: '\n' },
|
|
203
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: 'true', width: 100 } } },
|
|
204
|
+
{ insert: { video: 'https://quilljs.com/' } },
|
|
205
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
206
|
+
{ insert: '\n' },
|
|
207
|
+
]);
|
|
208
|
+
await vi.runAllTimersAsync();
|
|
209
|
+
expect(quill.root).toEqualHTML(
|
|
210
|
+
`
|
|
211
|
+
<p><br></p>
|
|
212
|
+
<div>
|
|
213
|
+
<table cellpadding="0" cellspacing="0" data-full="true">
|
|
214
|
+
<colgroup data-full="true">
|
|
215
|
+
<col width="100%" data-full="true" />
|
|
216
|
+
</colgroup>
|
|
217
|
+
<tbody>
|
|
218
|
+
<tr>
|
|
219
|
+
<td rowspan="1" colspan="1">
|
|
220
|
+
<div>
|
|
221
|
+
<iframe src="https://quilljs.com/" frameborder="0" allowfullscreen="true"></iframe>
|
|
222
|
+
<p><br></p>
|
|
223
|
+
</div>
|
|
224
|
+
</td>
|
|
225
|
+
</tr>
|
|
226
|
+
</tbody>
|
|
227
|
+
</table>
|
|
228
|
+
</div>
|
|
229
|
+
<p><br></p>
|
|
230
|
+
`,
|
|
231
|
+
{ ignoreAttrs: ['class', 'style', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
|
|
232
|
+
);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('set contents', () => {
|
|
237
|
+
it('should optimize correctly', async () => {
|
|
238
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
239
|
+
quill.setContents(createTableDeltaOps(3, 3));
|
|
240
|
+
await vi.runAllTimersAsync();
|
|
241
|
+
expect(quill.root).toEqualHTML(
|
|
242
|
+
`
|
|
243
|
+
<p><br></p>
|
|
244
|
+
${createTableHTML(3, 3)}
|
|
245
|
+
<p><br></p>
|
|
246
|
+
`,
|
|
247
|
+
{ ignoreAttrs: ['class', 'style', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
|
|
248
|
+
);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('should get correct prop', async () => {
|
|
252
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
253
|
+
quill.setContents(createTableDeltaOps(3, 3, { full: false, width: 200, align: 'center' }));
|
|
254
|
+
await vi.runAllTimersAsync();
|
|
255
|
+
expect(quill.root).toEqualHTML(
|
|
256
|
+
`
|
|
257
|
+
<p><br></p>
|
|
258
|
+
${createTableHTML(3, 3, { full: false, width: 200, align: 'center' })}
|
|
259
|
+
<p><br></p>
|
|
260
|
+
`,
|
|
261
|
+
{ ignoreAttrs: ['class', 'contenteditable'] },
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('should display an empty table', async () => {
|
|
266
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
267
|
+
quill.setContents(createTableDeltaOps(2, 2, {}, { isEmpty: true }));
|
|
268
|
+
await vi.runAllTimersAsync();
|
|
269
|
+
expect(quill.root).toEqualHTML(
|
|
270
|
+
`
|
|
271
|
+
<p><br></p>
|
|
272
|
+
${createTableHTML(2, 2, {}, { isEmpty: true })}
|
|
273
|
+
<p><br></p>
|
|
274
|
+
`,
|
|
275
|
+
{ ignoreAttrs: ['class', 'style', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
|
|
276
|
+
);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('delta should render save construct', async () => {
|
|
280
|
+
const quill = await createTable(3, 2);
|
|
281
|
+
const tableModule = quill.getModule(TableUp.moduleName) as TableUp;
|
|
282
|
+
const tds = quill.scroll.descendants(TableCellInnerFormat, 0);
|
|
283
|
+
tableModule.setCellAttrs([tds[0], tds[1]], 'background-color', 'red', true);
|
|
284
|
+
tableModule.setCellAttrs([tds[2], tds[3]], 'border-color', 'red', true);
|
|
285
|
+
tableModule.setCellAttrs([tds[4], tds[5]], 'height', '50px', true);
|
|
286
|
+
await vi.runAllTimersAsync();
|
|
287
|
+
const delta = quill.getContents();
|
|
288
|
+
const insertGetHTML = quill.root.innerHTML;
|
|
289
|
+
expect(delta.ops).toEqual([
|
|
290
|
+
{ insert: '\n' },
|
|
291
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: true, width: 50 } } },
|
|
292
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', full: true, width: 50 } } },
|
|
293
|
+
{ insert: '1' },
|
|
294
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1, style: 'background-color: red;' } }, insert: '\n' },
|
|
295
|
+
{ insert: '2' },
|
|
296
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '2', rowspan: 1, colspan: 1, style: 'background-color: red;' } }, insert: '\n' },
|
|
297
|
+
{ insert: '3' },
|
|
298
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '1', rowspan: 1, colspan: 1, style: 'border-color: red;' } }, insert: '\n' },
|
|
299
|
+
{ insert: '4' },
|
|
300
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '2', rowspan: 1, colspan: 1, style: 'border-color: red;' } }, insert: '\n' },
|
|
301
|
+
{ insert: '5' },
|
|
302
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '1', rowspan: 1, colspan: 1, style: 'height: 50px;' } }, insert: '\n' },
|
|
303
|
+
{ insert: '6' },
|
|
304
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '2', rowspan: 1, colspan: 1, style: 'height: 50px;' } }, insert: '\n' },
|
|
305
|
+
{ insert: '\n' },
|
|
306
|
+
]);
|
|
307
|
+
quill.setContents([{ insert: '\n' }]);
|
|
308
|
+
quill.setContents(delta);
|
|
309
|
+
await vi.runAllTimersAsync();
|
|
310
|
+
expect(quill.root.innerHTML).toBe(insertGetHTML);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe('column width calculate', () => {
|
|
315
|
+
it('should calculate correct width', async () => {
|
|
316
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
317
|
+
quill.setContents(createTableDeltaOps(3, 3, { full: false }));
|
|
318
|
+
await vi.runAllTimersAsync();
|
|
319
|
+
expect(quill.root.querySelectorAll('table')[0].style.width).toBe('300px');
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe('html convert', () => {
|
|
324
|
+
it('should convert html code-block correctly', async () => {
|
|
325
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
326
|
+
quill.setContents(
|
|
327
|
+
quill.clipboard.convert({ html: '<div class="ql-table-wrapper" data-table-id="1"><table data-table-id="1" class="ql-table" cellpadding="0" cellspacing="0" style="margin-right: auto; width: 363px;"><colgroup data-table-id="1" contenteditable="false"><col width="121px" data-table-id="1" data-col-id="1"><col width="121px" data-table-id="1" data-col-id="2"><col width="121px" data-table-id="1" data-col-id="3"></colgroup><tbody data-table-id="1"><tr class="ql-table-row" data-table-id="1" data-row-id="1"><td class="ql-table-cell" data-table-id="1" data-row-id="1" data-col-id="1" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="1" data-col-id="1" data-rowspan="1" data-colspan="1"><p>1</p></div></td><td class="ql-table-cell" data-table-id="1" data-row-id="1" data-col-id="2" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="1" data-col-id="2" data-rowspan="1" data-colspan="1"><p>2</p></div></td><td class="ql-table-cell" data-table-id="1" data-row-id="1" data-col-id="3" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="1" data-col-id="3" data-rowspan="1" data-colspan="1"><p>3</p></div></td></tr><tr class="ql-table-row" data-table-id="1" data-row-id="2"><td class="ql-table-cell" data-table-id="1" data-row-id="2" data-col-id="1" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="2" data-col-id="1" data-rowspan="1" data-colspan="1"><p>4</p></div></td><td class="ql-table-cell" data-table-id="1" data-row-id="2" data-col-id="2" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="2" data-col-id="2" data-rowspan="1" data-colspan="1"><div class="ql-code-block-container" spellcheck="false"><div class="ql-code-block" data-language="plain">5</div><div class="ql-code-block" data-language="plain">5</div><div class="ql-code-block" data-language="plain">5</div></div><p>5</p><p>5</p><p>5</p></div></td><td class="ql-table-cell" data-table-id="1" data-row-id="2" data-col-id="3" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="2" data-col-id="3" data-rowspan="1" data-colspan="1"><p>6</p></div></td></tr><tr class="ql-table-row" data-table-id="1" data-row-id="3"><td class="ql-table-cell" data-table-id="1" data-row-id="3" data-col-id="1" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="3" data-col-id="1" data-rowspan="1" data-colspan="1"><p>7</p></div></td><td class="ql-table-cell" data-table-id="1" data-row-id="3" data-col-id="2" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="3" data-col-id="2" data-rowspan="1" data-colspan="1"><p>8</p></div></td><td class="ql-table-cell" data-table-id="1" data-row-id="3" data-col-id="3" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="3" data-col-id="3" data-rowspan="1" data-colspan="1"><p>9</p></div></td></tr></tbody></table></div>' }),
|
|
328
|
+
);
|
|
329
|
+
await vi.runAllTimersAsync();
|
|
330
|
+
|
|
331
|
+
const ops = quill.getContents().ops;
|
|
332
|
+
const resultOps = [
|
|
333
|
+
{ insert: '\n' },
|
|
334
|
+
{ insert: { 'table-up-col': { full: false, width: 121 } } },
|
|
335
|
+
{ insert: { 'table-up-col': { full: false, width: 121 } } },
|
|
336
|
+
{ insert: { 'table-up-col': { full: false, width: 121 } } },
|
|
337
|
+
{ insert: '1' },
|
|
338
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
339
|
+
{ insert: '2' },
|
|
340
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
341
|
+
{ insert: '3' },
|
|
342
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
343
|
+
{ insert: '4' },
|
|
344
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
345
|
+
{ insert: '5' },
|
|
346
|
+
{ attributes: { 'code-block': 'plain', 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
347
|
+
{ insert: '5' },
|
|
348
|
+
{ attributes: { 'code-block': 'plain', 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
349
|
+
{ insert: '5' },
|
|
350
|
+
{ attributes: { 'code-block': 'plain', 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
351
|
+
{ insert: '5' },
|
|
352
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
353
|
+
{ insert: '5' },
|
|
354
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
355
|
+
{ insert: '5' },
|
|
356
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
357
|
+
{ insert: '6' },
|
|
358
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
359
|
+
{ insert: '7' },
|
|
360
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
361
|
+
{ insert: '8' },
|
|
362
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
363
|
+
{ insert: '9' },
|
|
364
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
365
|
+
{ insert: '\n' },
|
|
366
|
+
];
|
|
367
|
+
for (const [i, op] of ops.entries()) {
|
|
368
|
+
expect(op).toMatchObject(resultOps[i]);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('should convert html header correctly', async () => {
|
|
373
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
374
|
+
quill.setContents(
|
|
375
|
+
quill.clipboard.convert({ html: '<div class="ql-table-wrapper" data-table-id="rlabchug06i"><table data-table-id="rlabchug06i" class="ql-table" cellpadding="0" cellspacing="0" style="margin-right: auto; width: 1166px;"><colgroup data-table-id="rlabchug06i" contenteditable="false"><col width="583px" data-table-id="rlabchug06i" data-col-id="ss993p1sqx"><col width="583px" data-table-id="rlabchug06i" data-col-id="2ixexk4mapx"></colgroup><tbody data-table-id="rlabchug06i"><tr class="ql-table-row" data-table-id="rlabchug06i" data-row-id="fvvkgpv86zw"><td class="ql-table-cell" data-table-id="rlabchug06i" data-row-id="fvvkgpv86zw" data-col-id="ss993p1sqx" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="rlabchug06i" data-row-id="fvvkgpv86zw" data-col-id="ss993p1sqx" data-rowspan="1" data-colspan="1"><h1>header1</h1></div></td><td class="ql-table-cell" data-table-id="rlabchug06i" data-row-id="fvvkgpv86zw" data-col-id="2ixexk4mapx" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="rlabchug06i" data-row-id="fvvkgpv86zw" data-col-id="2ixexk4mapx" data-rowspan="1" data-colspan="1"><h3>header3</h3></div></td></tr></tbody></table></div>' }),
|
|
376
|
+
);
|
|
377
|
+
await vi.runAllTimersAsync();
|
|
378
|
+
|
|
379
|
+
const ops = quill.getContents().ops;
|
|
380
|
+
const resultOps = [
|
|
381
|
+
{ insert: '\n' },
|
|
382
|
+
{ insert: { 'table-up-col': { full: false, width: 583 } } },
|
|
383
|
+
{ insert: { 'table-up-col': { full: false, width: 583 } } },
|
|
384
|
+
{ insert: 'header1' },
|
|
385
|
+
{ attributes: { 'header': 1, 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
386
|
+
{ insert: 'header3' },
|
|
387
|
+
{ attributes: { 'header': 3, 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
388
|
+
{ insert: '\n' },
|
|
389
|
+
];
|
|
390
|
+
for (const [i, op] of ops.entries()) {
|
|
391
|
+
expect(op).toMatchObject(resultOps[i]);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('should convert html image correctly', async () => {
|
|
396
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
397
|
+
quill.setContents(
|
|
398
|
+
quill.clipboard.convert({ html: '<div class="ql-table-wrapper" data-table-id="7oymehdtx0k"><table data-table-id="7oymehdtx0k" data-full="true" class="ql-table" cellpadding="0" cellspacing="0" style="margin-right: auto;"><colgroup data-table-id="7oymehdtx0k" data-full="true" contenteditable="false"><col width="100%" data-full="true" data-table-id="7oymehdtx0k" data-col-id="hr7qo4t2dus"></colgroup><tbody data-table-id="7oymehdtx0k"><tr class="ql-table-row" data-table-id="7oymehdtx0k" data-row-id="69gog08ow04"><td class="ql-table-cell" data-table-id="7oymehdtx0k" data-row-id="69gog08ow04" data-col-id="hr7qo4t2dus" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="7oymehdtx0k" data-row-id="69gog08ow04" data-col-id="hr7qo4t2dus" data-rowspan="1" data-colspan="1"><p><img src="https://upload-bbs.miyoushe.com/upload/2024/06/18/5556092/73b7bae28fded7a72d93a35d5559b24c_3979852353547906724.png"></p></div></td></tr></tbody></table></div>' }),
|
|
399
|
+
);
|
|
400
|
+
await vi.runAllTimersAsync();
|
|
401
|
+
|
|
402
|
+
const ops = quill.getContents().ops;
|
|
403
|
+
const resultOps = [
|
|
404
|
+
{ insert: '\n' },
|
|
405
|
+
{ insert: { 'table-up-col': { full: true, width: 100 } } },
|
|
406
|
+
{ insert: { image: 'https://upload-bbs.miyoushe.com/upload/2024/06/18/5556092/73b7bae28fded7a72d93a35d5559b24c_3979852353547906724.png' } },
|
|
407
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
408
|
+
{ insert: '\n' },
|
|
409
|
+
];
|
|
410
|
+
for (const [i, op] of ops.entries()) {
|
|
411
|
+
expect(op).toMatchObject(resultOps[i]);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('should convert html video correctly', async () => {
|
|
416
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
417
|
+
quill.setContents(
|
|
418
|
+
quill.clipboard.convert({ html: '<div class="ql-table-wrapper" data-table-id="1"><table data-table-id="1" data-full="true" class="ql-table" cellpadding="0" cellspacing="0" style="margin-right: auto;"><colgroup data-table-id="1" data-full="true" contenteditable="false"><col width="100%" data-full="true" data-table-id="1" data-col-id="1"></colgroup><tbody data-table-id="1"><tr class="ql-table-row" data-table-id="1" data-row-id="1"><td class="ql-table-cell" data-table-id="1" data-row-id="1" data-col-id="1" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="1" data-row-id="1" data-col-id="1" data-rowspan="1" data-colspan="1"><iframe class="ql-video" frameborder="0" allowfullscreen="true" src="http://127.0.0.1:5500/docs/index.html"></iframe><p><br></p></div></td></tr></tbody></table></div>' }),
|
|
419
|
+
);
|
|
420
|
+
await vi.runAllTimersAsync();
|
|
421
|
+
|
|
422
|
+
const ops = quill.getContents().ops;
|
|
423
|
+
const resultOps = [
|
|
424
|
+
{ insert: '\n' },
|
|
425
|
+
{ insert: { 'table-up-col': { full: true, width: 100 } } },
|
|
426
|
+
{ insert: { video: 'http://127.0.0.1:5500/docs/index.html' } },
|
|
427
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
428
|
+
{ insert: '\n' },
|
|
429
|
+
];
|
|
430
|
+
for (const [i, op] of ops.entries()) {
|
|
431
|
+
expect(op).toMatchObject(resultOps[i]);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('should convert html list correctly', async () => {
|
|
436
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
437
|
+
quill.setContents(
|
|
438
|
+
quill.clipboard.convert({ html: '<div class="ql-table-wrapper" data-table-id="ls2bw9dtr6m"><table data-table-id="ls2bw9dtr6m" class="ql-table" cellpadding="0" cellspacing="0" style="margin-right: auto; width: 1166px;"><colgroup data-table-id="ls2bw9dtr6m" contenteditable="false"><col width="583px" data-table-id="ls2bw9dtr6m" data-col-id="p3imc1n7xlo"><col width="583px" data-table-id="ls2bw9dtr6m" data-col-id="ndvtber87yq"></colgroup><tbody data-table-id="ls2bw9dtr6m"><tr class="ql-table-row" data-table-id="ls2bw9dtr6m" data-row-id="bztm23s128n"><td class="ql-table-cell" data-table-id="ls2bw9dtr6m" data-row-id="bztm23s128n" data-col-id="p3imc1n7xlo" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="ls2bw9dtr6m" data-row-id="bztm23s128n" data-col-id="p3imc1n7xlo" data-rowspan="1" data-colspan="1"><ol><li data-list="ordered"><span class="ql-ui" contenteditable="false"></span>list order</li><li data-list="ordered" class="ql-indent-1"><span class="ql-ui" contenteditable="false"></span>aaa</li></ol></div></td><td class="ql-table-cell" data-table-id="ls2bw9dtr6m" data-row-id="bztm23s128n" data-col-id="ndvtber87yq" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="ls2bw9dtr6m" data-row-id="bztm23s128n" data-col-id="ndvtber87yq" data-rowspan="1" data-colspan="1"><ol><li data-list="bullet"><span class="ql-ui" contenteditable="false"></span>list bullet</li></ol></div></td></tr><tr class="ql-table-row" data-table-id="ls2bw9dtr6m" data-row-id="3kx2tsgoao5"><td class="ql-table-cell" data-table-id="ls2bw9dtr6m" data-row-id="3kx2tsgoao5" data-col-id="p3imc1n7xlo" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="ls2bw9dtr6m" data-row-id="3kx2tsgoao5" data-col-id="p3imc1n7xlo" data-rowspan="1" data-colspan="1"><ol><li data-list="unchecked"><span class="ql-ui" contenteditable="false"></span>list checkbox</li><li data-list="checked"><span class="ql-ui" contenteditable="false"></span>checkbox checked</li></ol></div></td><td class="ql-table-cell" data-table-id="ls2bw9dtr6m" data-row-id="3kx2tsgoao5" data-col-id="ndvtber87yq" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="ls2bw9dtr6m" data-row-id="3kx2tsgoao5" data-col-id="ndvtber87yq" data-rowspan="1" data-colspan="1"><p><br></p></div></td></tr></tbody></table></div>' }),
|
|
439
|
+
);
|
|
440
|
+
await vi.runAllTimersAsync();
|
|
441
|
+
|
|
442
|
+
const ops = quill.getContents().ops;
|
|
443
|
+
const resultOps = [
|
|
444
|
+
{ insert: '\n' },
|
|
445
|
+
{ insert: { 'table-up-col': { full: false, width: 583 } } },
|
|
446
|
+
{ insert: { 'table-up-col': { full: false, width: 583 } } },
|
|
447
|
+
{ insert: 'list order' },
|
|
448
|
+
{ attributes: { 'list': 'ordered', 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
449
|
+
{ insert: 'aaa' },
|
|
450
|
+
{ attributes: { 'indent': 1, 'list': 'ordered', 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
451
|
+
{ insert: 'list bullet' },
|
|
452
|
+
{ attributes: { 'list': 'bullet', 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
453
|
+
{ insert: 'list checkbox' },
|
|
454
|
+
{ attributes: { 'list': 'unchecked', 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
455
|
+
{ insert: 'checkbox checked' },
|
|
456
|
+
{ attributes: { 'list': 'checked', 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
457
|
+
{ attributes: { 'table-up-cell-inner': { rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
458
|
+
{ insert: '\n' },
|
|
459
|
+
];
|
|
460
|
+
for (const [i, op] of ops.entries()) {
|
|
461
|
+
expect(op).toMatchObject(resultOps[i]);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
});
|