quill-table-up 3.2.0 → 3.2.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quill-table-up",
3
3
  "type": "module",
4
- "version": "3.2.0",
4
+ "version": "3.2.1",
5
5
  "packageManager": "pnpm@10.20.0",
6
6
  "description": "A table module for quill2.x",
7
7
  "author": "zzxming",
@@ -410,18 +410,25 @@ extendTest.describe('TableSelection keyboard handler', () => {
410
410
  const tableUp = window.quills[0].getModule('table-up') as TableUp;
411
411
  const tableSelection = tableUp.getModule<TableSelection>('table-selection')!;
412
412
  const doms = document.querySelectorAll('#container1 td .ql-table-cell-inner');
413
- const cells = Array.from(doms).map(dom => (window as any).Quill.find(dom)) as TableCellInnerFormat[];
413
+ const cells = Array.from(doms).map(dom => window.Quill.find(dom)) as TableCellInnerFormat[];
414
414
  tableSelection.setSelectedTds([cells[0], cells[1], cells[3]]);
415
415
  tableSelection.updateWithSelectedTds();
416
416
  });
417
+ await page.waitForTimeout(1000);
417
418
 
418
419
  const tableSelection = page.locator('#container1 .table-up-toolbox .table-up-selection__line');
419
420
  await expect(tableSelection).toBeVisible();
420
421
 
421
422
  await editorPage.blur();
422
423
  await page.keyboard.press('Control+c');
424
+
425
+ const cellText = await page.evaluate(() => {
426
+ const tableUp = window.quills[0].getModule('table-up') as TableUp;
427
+ const tds = tableUp.getModule<TableSelection>('table-selection')!.selectedTds;
428
+ return tableUp.getTextByCell(tds);
429
+ });
423
430
  const copiedText = await page.evaluate(() => navigator.clipboard.readText());
424
- expect(copiedText.replaceAll('\r', '')).toEqual(`1\n2\n4\n5\n`);
431
+ expect(copiedText.replaceAll('\r', '')).toEqual(cellText);
425
432
  });
426
433
 
427
434
  extendTest('paste cells with struct(colspan)', async ({ page, browserName, editorPage }) => {
@@ -3,5 +3,6 @@ import type Quill from 'quill';
3
3
  declare global {
4
4
  interface Window {
5
5
  quills: Quill[];
6
+ Quill: InstanceType<Quill>;
6
7
  }
7
8
  }
@@ -38,9 +38,6 @@ describe('merge and split cell', () => {
38
38
  <td rowspan="2" colspan="2">
39
39
  <div>
40
40
  <p><br></p>
41
- <p><br></p>
42
- <p><br></p>
43
- <p><br></p>
44
41
  </div>
45
42
  </td>
46
43
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
@@ -81,11 +78,6 @@ describe('merge and split cell', () => {
81
78
  <td rowspan="2" colspan="1">
82
79
  <div>
83
80
  <p><br></p>
84
- <p><br></p>
85
- <p><br></p>
86
- <p><br></p>
87
- <p><br></p>
88
- <p><br></p>
89
81
  </div>
90
82
  </td>
91
83
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
@@ -130,7 +122,7 @@ describe('merge and split cell', () => {
130
122
  ${new Array(3).fill(0).map(() => `<td rowspan="1" colspan="1"><div><p><br></p></div></td>`).join('\n')}
131
123
  <td rowspan="3" colspan="2">
132
124
  <div>
133
- ${new Array(9).fill(0).map(() => `<p><br></p>`).join('\n')}
125
+ <p><br></p>
134
126
  </div>
135
127
  </td>
136
128
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
@@ -138,7 +130,7 @@ describe('merge and split cell', () => {
138
130
  <tr>
139
131
  <td rowspan="3" colspan="3">
140
132
  <div>
141
- ${new Array(9).fill(0).map(() => `<p><br></p>`).join('\n')}
133
+ <p><br></p>
142
134
  </div>
143
135
  </td>
144
136
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
@@ -150,7 +142,7 @@ describe('merge and split cell', () => {
150
142
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
151
143
  <td rowspan="3" colspan="2">
152
144
  <div>
153
- ${new Array(9).fill(0).map(() => `<p><br></p>`).join('\n')}
145
+ <p><br></p>
154
146
  </div>
155
147
  </td>
156
148
  </tr>
@@ -193,9 +185,6 @@ describe('merge and split cell', () => {
193
185
  <td rowspan="1" colspan="1">
194
186
  <div>
195
187
  <p><br></p>
196
- <p><br></p>
197
- <p><br></p>
198
- <p><br></p>
199
188
  </div>
200
189
  </td>
201
190
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
@@ -510,11 +510,6 @@ describe('insert row into table', () => {
510
510
  <td rowspan="3" colspan="3">
511
511
  <div>
512
512
  <p><br></p>
513
- <p><br></p>
514
- <p><br></p>
515
- <p><br></p>
516
- <p><br></p>
517
- <p><br></p>
518
513
  </div>
519
514
  </td>
520
515
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
@@ -529,7 +524,6 @@ describe('insert row into table', () => {
529
524
  <td rowspan="2" colspan="1">
530
525
  <div>
531
526
  <p><br></p>
532
- <p><br></p>
533
527
  </div>
534
528
  </td>
535
529
  </tr>
@@ -607,11 +601,6 @@ describe('insert row into table', () => {
607
601
  <td rowspan="3" colspan="1">
608
602
  <div>
609
603
  <p><br></p>
610
- <p><br></p>
611
- <p><br></p>
612
- <p><br></p>
613
- <p><br></p>
614
- <p><br></p>
615
604
  </div>
616
605
  </td>
617
606
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
@@ -780,7 +769,7 @@ describe('set cell attribute', () => {
780
769
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '4', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody', style: 'border-bottom-color: red;' } }, insert: '\n' },
781
770
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '5', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
782
771
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody', style: 'border-right-color: red;' } }, insert: '\n' },
783
- { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '2', rowspan: 3, colspan: 3, tag: 'td', wrapTag: 'tbody', style: 'border-color: red;' } }, insert: '\n\n\n\n\n\n\n\n\n' },
772
+ { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '2', rowspan: 3, colspan: 3, tag: 'td', wrapTag: 'tbody', style: 'border-color: red;' } }, insert: '\n' },
784
773
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '5', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
785
774
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody', style: 'border-right-color: red;' } }, insert: '\n' },
786
775
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '5', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
@@ -822,7 +811,7 @@ describe('set cell attribute', () => {
822
811
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '3', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
823
812
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '4', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
824
813
 
825
- { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '1', rowspan: 2, colspan: 2, tag: 'td', wrapTag: 'tbody' } }, insert: '\n\n\n\n' },
814
+ { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '1', rowspan: 2, colspan: 2, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
826
815
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '3', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
827
816
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '4', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
828
817
 
@@ -830,7 +819,7 @@ describe('set cell attribute', () => {
830
819
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '4', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
831
820
 
832
821
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody', style: 'border-right-color: red;' } }, insert: '\n' },
833
- { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', colId: '2', rowspan: 2, colspan: 2, tag: 'td', wrapTag: 'tbody', style: 'border-color: red;' } }, insert: '\n\n\n\n' },
822
+ { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', colId: '2', rowspan: 2, colspan: 2, tag: 'td', wrapTag: 'tbody', style: 'border-color: red;' } }, insert: '\n' },
834
823
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', colId: '4', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
835
824
 
836
825
  { attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody', style: 'border-right-color: red;' } }, insert: '\n' },
@@ -104,11 +104,6 @@ describe('remove column from table', () => {
104
104
  <td rowspan="2" colspan="1">
105
105
  <div>
106
106
  <p><br></p>
107
- <p><br></p>
108
- <p><br></p>
109
- <p><br></p>
110
- <p><br></p>
111
- <p><br></p>
112
107
  </div>
113
108
  </td>
114
109
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
@@ -121,8 +116,6 @@ describe('remove column from table', () => {
121
116
  <td rowspan="1" colspan="1">
122
117
  <div>
123
118
  <p><br></p>
124
- <p><br></p>
125
- <p><br></p>
126
119
  </div>
127
120
  </td>
128
121
  </tr>
@@ -232,7 +225,7 @@ describe('unusual delete', () => {
232
225
  await vi.runAllTimersAsync();
233
226
  tableModule.mergeCells([tds[17], tds[18], tds[22], tds[23]]);
234
227
  await vi.runAllTimersAsync();
235
- quill.deleteText(18, 8);
228
+ quill.deleteText(9, 5);
236
229
  await vi.runAllTimersAsync();
237
230
  expect(quill.root).toEqualHTML(
238
231
  `
@@ -246,33 +239,21 @@ describe('unusual delete', () => {
246
239
  </colgroup>
247
240
  <tbody>
248
241
  <tr>
249
- <td rowspan="3" colspan="1">
242
+ <td rowspan="2" colspan="1">
250
243
  <div>
251
244
  <p><br></p>
252
- <p><br></p>
253
- <p><br></p>
254
- <p><br></p>
255
- <p><br></p>
256
- <p><br></p>
257
- <p><br></p>
258
- <p><br></p>
259
- <p><br></p>
260
245
  </div>
261
246
  </td>
262
247
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
263
- <td rowspan="3" colspan="1">
248
+ <td rowspan="2" colspan="1">
264
249
  <div>
265
250
  <p><br></p>
266
- <p><br></p>
267
251
  </div>
268
252
  </td>
269
253
  </tr>
270
254
  <tr>
271
255
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
272
256
  </tr>
273
- <tr>
274
- <td rowspan="1" colspan="1"><div><p><br></p></div></td>
275
- </tr>
276
257
  </tbody>
277
258
  </table>
278
259
  </div>
@@ -292,7 +273,7 @@ describe('unusual delete', () => {
292
273
  tableModule.mergeCells([tds[4], tds[9], tds[14], tds[19]]);
293
274
  tableModule.mergeCells([tds[17], tds[18], tds[22], tds[23]]);
294
275
  await vi.runAllTimersAsync();
295
- quill.deleteText(21, 3);
276
+ quill.deleteText(10, 3);
296
277
  await vi.runAllTimersAsync();
297
278
  expect(quill.root).toEqualHTML(
298
279
  `
@@ -307,23 +288,12 @@ describe('unusual delete', () => {
307
288
  <td rowspan="3" colspan="3">
308
289
  <div>
309
290
  <p><br></p>
310
- <p><br></p>
311
- <p><br></p>
312
- <p><br></p>
313
- <p><br></p>
314
- <p><br></p>
315
- <p><br></p>
316
- <p><br></p>
317
- <p><br></p>
318
291
  </div>
319
292
  </td>
320
293
  <td rowspan="1" colspan="1"><div><p><br></p></div></td>
321
294
  <td rowspan="4" colspan="1">
322
295
  <div>
323
296
  <p><br></p>
324
- <p><br></p>
325
- <p><br></p>
326
- <p><br></p>
327
297
  </div>
328
298
  </td>
329
299
  </tr>
package/src/table-up.ts CHANGED
@@ -1247,7 +1247,10 @@ export class TableUp {
1247
1247
  pre[1][rowId] += selectTd.colspan;
1248
1248
  // merge select cell
1249
1249
  if (index !== 0) {
1250
- selectTd.moveChildren(pre[2]);
1250
+ // remove empty \n
1251
+ if (selectTd.length() > 1) {
1252
+ selectTd.moveChildren(pre[2]);
1253
+ }
1251
1254
  selectTd.parent.remove();
1252
1255
  }
1253
1256
  return pre;