quill-table-up 3.0.2 → 3.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/README.md +5 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -13
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +27 -26
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/unit/table-blots.test.ts +341 -2
- package/src/__tests__/unit/table-clipboard.test.ts +187 -21
- package/src/__tests__/unit/table-redo-undo.test.ts +54 -2
- package/src/__tests__/unit/utils.ts +13 -6
- package/src/modules/table-clipboard.ts +24 -9
- package/src/modules/table-menu/constants.ts +24 -0
- package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/src/table-up.ts +55 -5
- package/src/utils/is.ts +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quill-table-up",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.3",
|
|
5
5
|
"packageManager": "pnpm@10.15.0",
|
|
6
6
|
"description": "A table module for quill2.x",
|
|
7
7
|
"author": "zzxming",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@typescript-eslint/parser": "^8.41.0",
|
|
60
60
|
"@vitest/coverage-v8": "^3.2.4",
|
|
61
61
|
"@vitest/ui": "^3.2.4",
|
|
62
|
-
"@zzxming/eslint-config": "0.5.
|
|
62
|
+
"@zzxming/eslint-config": "0.5.7",
|
|
63
63
|
"autoprefixer": "^10.4.21",
|
|
64
64
|
"eslint": "^9.34.0",
|
|
65
65
|
"gulp": "^5.0.1",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { ToolOption } from '../../utils';
|
|
1
2
|
import Quill from 'quill';
|
|
2
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import { TableCellFormat } from '../../formats';
|
|
4
|
+
import { TableCellFormat, TableCellInnerFormat } from '../../formats';
|
|
5
|
+
import { tableMenuTools } from '../../modules';
|
|
4
6
|
import { TableUp } from '../../table-up';
|
|
5
|
-
import { createQuillWithTableModule, createTableBodyHTML, createTableCaptionHTML, createTableDeltaOps, createTaleColHTML, expectDelta } from './utils';
|
|
7
|
+
import { createQuillWithTableModule, createTable, createTableBodyHTML, createTableCaptionHTML, createTableDeltaOps, createTaleColHTML, datasetWrapTag, expectDelta, replaceAttrEmptyRow } from './utils';
|
|
6
8
|
|
|
7
9
|
const Delta = Quill.import('delta');
|
|
8
10
|
|
|
@@ -379,3 +381,340 @@ describe('test table around line', () => {
|
|
|
379
381
|
);
|
|
380
382
|
});
|
|
381
383
|
});
|
|
384
|
+
|
|
385
|
+
describe('test table body convert', () => {
|
|
386
|
+
it('table convert body should work correctly', async () => {
|
|
387
|
+
const quill = await createTable(3, 3, { full: false }, {}, { isEmpty: false });
|
|
388
|
+
const table = quill.root.querySelector('table')!;
|
|
389
|
+
const tableModule = quill.getModule(TableUp.moduleName) as TableUp;
|
|
390
|
+
const tds = quill.scroll.descendants(TableCellInnerFormat, 0);
|
|
391
|
+
(tableMenuTools.ConvertTothead as ToolOption).handle.call({ quill, table } as any, tableModule, tds.slice(0, 1), null);
|
|
392
|
+
await vi.runAllTimersAsync();
|
|
393
|
+
|
|
394
|
+
expectDelta(
|
|
395
|
+
quill.getContents(),
|
|
396
|
+
new Delta([
|
|
397
|
+
{ insert: '\n' },
|
|
398
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: false, width: 100 } } },
|
|
399
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', full: false, width: 100 } } },
|
|
400
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '3', full: false, width: 100 } } },
|
|
401
|
+
{ insert: '1' },
|
|
402
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'thead' } }, insert: '\n' },
|
|
403
|
+
{ insert: '2' },
|
|
404
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '2', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'thead' } }, insert: '\n' },
|
|
405
|
+
{ insert: '3' },
|
|
406
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '3', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'thead' } }, insert: '\n' },
|
|
407
|
+
{ insert: '4' },
|
|
408
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
409
|
+
{ insert: '5' },
|
|
410
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '2', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
411
|
+
{ insert: '6' },
|
|
412
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '3', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
413
|
+
{ insert: '7' },
|
|
414
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
415
|
+
{ insert: '8' },
|
|
416
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '2', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
417
|
+
{ insert: '9' },
|
|
418
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '3', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
419
|
+
{ insert: '\n' },
|
|
420
|
+
]),
|
|
421
|
+
);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it('table convert body with multi body', async () => {
|
|
425
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
426
|
+
quill.setContents([
|
|
427
|
+
{ insert: '\n' },
|
|
428
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', width: 100 } } },
|
|
429
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', width: 100 } } },
|
|
430
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '3', width: 100 } } },
|
|
431
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '4', width: 100 } } },
|
|
432
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '5', width: 100 } } },
|
|
433
|
+
{ insert: '1' },
|
|
434
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', wrapTag: 'thead', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
435
|
+
{ insert: '2' },
|
|
436
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', wrapTag: 'thead', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
437
|
+
{ insert: '3' },
|
|
438
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', wrapTag: 'thead', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
439
|
+
{ insert: '4' },
|
|
440
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', wrapTag: 'thead', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
441
|
+
{ insert: '5' },
|
|
442
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', wrapTag: 'thead', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
443
|
+
{ insert: '6' },
|
|
444
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', wrapTag: 'thead', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
445
|
+
{ insert: '7' },
|
|
446
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', wrapTag: 'thead', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
447
|
+
{ insert: '8' },
|
|
448
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', wrapTag: 'thead', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
449
|
+
{ insert: '9' },
|
|
450
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', wrapTag: 'thead', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
451
|
+
{ insert: '10' },
|
|
452
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', wrapTag: 'thead', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
453
|
+
{ insert: '11' },
|
|
454
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
455
|
+
{ insert: '12' },
|
|
456
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
457
|
+
{ insert: '13' },
|
|
458
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
459
|
+
{ insert: '14' },
|
|
460
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
461
|
+
{ insert: '15' },
|
|
462
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
463
|
+
{ insert: '16' },
|
|
464
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', wrapTag: 'tfoot', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
465
|
+
{ insert: '17' },
|
|
466
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', wrapTag: 'tfoot', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
467
|
+
{ insert: '18' },
|
|
468
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', wrapTag: 'tfoot', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
469
|
+
{ insert: '19' },
|
|
470
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', wrapTag: 'tfoot', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
471
|
+
{ insert: '20' },
|
|
472
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', wrapTag: 'tfoot', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
473
|
+
{ insert: '21' },
|
|
474
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', wrapTag: 'tfoot', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
475
|
+
{ insert: '22' },
|
|
476
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', wrapTag: 'tfoot', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
477
|
+
{ insert: '23' },
|
|
478
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', wrapTag: 'tfoot', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
479
|
+
{ insert: '24' },
|
|
480
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', wrapTag: 'tfoot', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
481
|
+
{ insert: '25' },
|
|
482
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', wrapTag: 'tfoot', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
483
|
+
{ insert: '\n' },
|
|
484
|
+
]);
|
|
485
|
+
await vi.runAllTimersAsync();
|
|
486
|
+
|
|
487
|
+
const table = quill.root.querySelector('table')!;
|
|
488
|
+
const tableModule = quill.getModule(TableUp.moduleName) as TableUp;
|
|
489
|
+
const tds = quill.scroll.descendants(TableCellInnerFormat, 0);
|
|
490
|
+
(tableMenuTools.ConvertTothead as ToolOption).handle.call({ quill, table } as any, tableModule, tds.slice(5, 20), null);
|
|
491
|
+
await vi.runAllTimersAsync();
|
|
492
|
+
|
|
493
|
+
expectDelta(
|
|
494
|
+
quill.getContents(),
|
|
495
|
+
new Delta([
|
|
496
|
+
{ insert: '\n' },
|
|
497
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: false, width: 100 } } },
|
|
498
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', full: false, width: 100 } } },
|
|
499
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '3', full: false, width: 100 } } },
|
|
500
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '4', full: false, width: 100 } } },
|
|
501
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '5', full: false, width: 100 } } },
|
|
502
|
+
{ insert: '1' },
|
|
503
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', tag: 'td', wrapTag: 'thead', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
504
|
+
{ insert: '2' },
|
|
505
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', tag: 'td', wrapTag: 'thead', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
506
|
+
{ insert: '3' },
|
|
507
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', tag: 'td', wrapTag: 'thead', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
508
|
+
{ insert: '4' },
|
|
509
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', tag: 'td', wrapTag: 'thead', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
510
|
+
{ insert: '5' },
|
|
511
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', tag: 'td', wrapTag: 'thead', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
512
|
+
{ insert: '6' },
|
|
513
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', tag: 'td', wrapTag: 'thead', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
514
|
+
{ insert: '7' },
|
|
515
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', tag: 'td', wrapTag: 'thead', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
516
|
+
{ insert: '8' },
|
|
517
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', tag: 'td', wrapTag: 'thead', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
518
|
+
{ insert: '9' },
|
|
519
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', tag: 'td', wrapTag: 'thead', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
520
|
+
{ insert: '10' },
|
|
521
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', tag: 'td', wrapTag: 'thead', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
522
|
+
{ insert: '11' },
|
|
523
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', tag: 'td', wrapTag: 'thead', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
524
|
+
{ insert: '12' },
|
|
525
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', tag: 'td', wrapTag: 'thead', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
526
|
+
{ insert: '13' },
|
|
527
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', tag: 'td', wrapTag: 'thead', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
528
|
+
{ insert: '14' },
|
|
529
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', tag: 'td', wrapTag: 'thead', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
530
|
+
{ insert: '15' },
|
|
531
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', tag: 'td', wrapTag: 'thead', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
532
|
+
{ insert: '16' },
|
|
533
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', tag: 'td', wrapTag: 'thead', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
534
|
+
{ insert: '17' },
|
|
535
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', tag: 'td', wrapTag: 'thead', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
536
|
+
{ insert: '18' },
|
|
537
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', tag: 'td', wrapTag: 'thead', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
538
|
+
{ insert: '19' },
|
|
539
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', tag: 'td', wrapTag: 'thead', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
540
|
+
{ insert: '20' },
|
|
541
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '4', tag: 'td', wrapTag: 'thead', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
542
|
+
{ insert: '21' },
|
|
543
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', tag: 'td', wrapTag: 'tfoot', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
544
|
+
{ insert: '22' },
|
|
545
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', tag: 'td', wrapTag: 'tfoot', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
546
|
+
{ insert: '23' },
|
|
547
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', tag: 'td', wrapTag: 'tfoot', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
548
|
+
{ insert: '24' },
|
|
549
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', tag: 'td', wrapTag: 'tfoot', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
550
|
+
{ insert: '25' },
|
|
551
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', tag: 'td', wrapTag: 'tfoot', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
552
|
+
{ insert: '\n' },
|
|
553
|
+
]),
|
|
554
|
+
);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('table convert body with emptyRow', async () => {
|
|
558
|
+
const quill = createQuillWithTableModule(`<p><br></p>`, { autoMergeCell: false });
|
|
559
|
+
quill.setContents([
|
|
560
|
+
{ insert: '\n' },
|
|
561
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: false, width: 100 } } },
|
|
562
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', full: false, width: 100 } } },
|
|
563
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '3', full: false, width: 100 } } },
|
|
564
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '4', full: false, width: 100 } } },
|
|
565
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '5', full: false, width: 100 } } },
|
|
566
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 5, colspan: 5, emptyRow: ['2', '3', '4', '5'] } }, insert: '\n' },
|
|
567
|
+
{ insert: '\n' },
|
|
568
|
+
]);
|
|
569
|
+
await vi.runAllTimersAsync();
|
|
570
|
+
|
|
571
|
+
const table = quill.root.querySelector('table')!;
|
|
572
|
+
const tableModule = quill.getModule(TableUp.moduleName) as TableUp;
|
|
573
|
+
const tds = quill.scroll.descendants(TableCellInnerFormat, 0);
|
|
574
|
+
(tableMenuTools.ConvertTothead as ToolOption).handle.call({ quill, table } as any, tableModule, tds.slice(0, 1), null);
|
|
575
|
+
await vi.runAllTimersAsync();
|
|
576
|
+
|
|
577
|
+
expectDelta(
|
|
578
|
+
quill.getContents(),
|
|
579
|
+
new Delta([
|
|
580
|
+
{ insert: '\n' },
|
|
581
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: false, width: 100 } } },
|
|
582
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', full: false, width: 100 } } },
|
|
583
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '3', full: false, width: 100 } } },
|
|
584
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '4', full: false, width: 100 } } },
|
|
585
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '5', full: false, width: 100 } } },
|
|
586
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 5, colspan: 5, tag: 'td', wrapTag: 'thead', emptyRow: ['2', '3', '4', '5'] } }, insert: '\n' },
|
|
587
|
+
{ insert: '\n' },
|
|
588
|
+
]),
|
|
589
|
+
);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it('table convert body with next emptyRow', async () => {
|
|
593
|
+
const quill = createQuillWithTableModule(`<p><br></p>`, { autoMergeCell: false });
|
|
594
|
+
quill.setContents([
|
|
595
|
+
{ insert: '\n' },
|
|
596
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: false, width: 100 } } },
|
|
597
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', full: false, width: 100 } } },
|
|
598
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '3', full: false, width: 100 } } },
|
|
599
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '4', full: false, width: 100 } } },
|
|
600
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '5', full: false, width: 100 } } },
|
|
601
|
+
{ insert: '1' },
|
|
602
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
603
|
+
{ insert: '2' },
|
|
604
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
605
|
+
{ insert: '3' },
|
|
606
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
607
|
+
{ insert: '4' },
|
|
608
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
609
|
+
{ insert: '5' },
|
|
610
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
611
|
+
{ insert: 'merge' },
|
|
612
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '1', rowspan: 3, colspan: 5, emptyRow: ['3', '4'] } }, insert: '\n' },
|
|
613
|
+
{ insert: '6' },
|
|
614
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
615
|
+
{ insert: '7' },
|
|
616
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
617
|
+
{ insert: '8' },
|
|
618
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
619
|
+
{ insert: '9' },
|
|
620
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '4', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
621
|
+
{ insert: '10' },
|
|
622
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '5', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
623
|
+
{ insert: '\n' },
|
|
624
|
+
]);
|
|
625
|
+
await vi.runAllTimersAsync();
|
|
626
|
+
|
|
627
|
+
const table = quill.root.querySelector('table')!;
|
|
628
|
+
const tableModule = quill.getModule(TableUp.moduleName) as TableUp;
|
|
629
|
+
const tds = quill.scroll.descendants(TableCellInnerFormat, 0);
|
|
630
|
+
(tableMenuTools.ConvertTothead as ToolOption).handle.call({ quill, table } as any, tableModule, tds.slice(0, 6), null);
|
|
631
|
+
await vi.runAllTimersAsync();
|
|
632
|
+
|
|
633
|
+
expect(quill.root).toEqualHTML(
|
|
634
|
+
`
|
|
635
|
+
<p><br></p>
|
|
636
|
+
<div>
|
|
637
|
+
<table cellpadding="0" cellspacing="0" style="margin-right: auto; width: 500px;">
|
|
638
|
+
${createTaleColHTML(5, { full: false, width: 100 })}
|
|
639
|
+
<thead>
|
|
640
|
+
<tr ${datasetWrapTag('thead')}>
|
|
641
|
+
${
|
|
642
|
+
new Array(5).fill(0).map((_, i) => `<td rowspan="1" colspan="1" ${datasetWrapTag('thead')}>
|
|
643
|
+
<div ${datasetWrapTag('thead')}>
|
|
644
|
+
<p>
|
|
645
|
+
${i + 1}
|
|
646
|
+
</p>
|
|
647
|
+
</div>
|
|
648
|
+
</td>`).join('\n')
|
|
649
|
+
}
|
|
650
|
+
</tr>
|
|
651
|
+
<tr ${datasetWrapTag('thead')}>
|
|
652
|
+
<td rowspan="3" colspan="5" ${datasetWrapTag('thead')} data-empty-row="length:2">
|
|
653
|
+
<div ${datasetWrapTag('thead')} data-empty-row="length:2">
|
|
654
|
+
<p>merge</p>
|
|
655
|
+
</div>
|
|
656
|
+
</td>
|
|
657
|
+
</tr>
|
|
658
|
+
<tr ${datasetWrapTag('thead')}></tr>
|
|
659
|
+
<tr ${datasetWrapTag('thead')}></tr>
|
|
660
|
+
</thead>
|
|
661
|
+
<tbody>
|
|
662
|
+
<tr ${datasetWrapTag('tbody')}>
|
|
663
|
+
${
|
|
664
|
+
new Array(5).fill(0).map((_, i) => `<td rowspan="1" colspan="1" ${datasetWrapTag('tbody')}>
|
|
665
|
+
<div ${datasetWrapTag('tbody')}>
|
|
666
|
+
<p>
|
|
667
|
+
${5 + i + 1}
|
|
668
|
+
</p>
|
|
669
|
+
</div>
|
|
670
|
+
</td>`).join('\n')
|
|
671
|
+
}
|
|
672
|
+
</tr>
|
|
673
|
+
</tbody>
|
|
674
|
+
</table>
|
|
675
|
+
</div>
|
|
676
|
+
<p><br></p>
|
|
677
|
+
`,
|
|
678
|
+
{
|
|
679
|
+
ignoreAttrs: ['data-tag', 'class', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'],
|
|
680
|
+
replaceAttrs: {
|
|
681
|
+
'data-empty-row': replaceAttrEmptyRow,
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
);
|
|
685
|
+
expectDelta(
|
|
686
|
+
quill.getContents(),
|
|
687
|
+
new Delta([
|
|
688
|
+
{ insert: '\n' },
|
|
689
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', full: false, width: 100 } } },
|
|
690
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', full: false, width: 100 } } },
|
|
691
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '3', full: false, width: 100 } } },
|
|
692
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '4', full: false, width: 100 } } },
|
|
693
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '5', full: false, width: 100 } } },
|
|
694
|
+
{ insert: '1' },
|
|
695
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'thead' } }, insert: '\n' },
|
|
696
|
+
{ insert: '2' },
|
|
697
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '2', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'thead' } }, insert: '\n' },
|
|
698
|
+
{ insert: '3' },
|
|
699
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '3', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'thead' } }, insert: '\n' },
|
|
700
|
+
{ insert: '4' },
|
|
701
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '4', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'thead' } }, insert: '\n' },
|
|
702
|
+
{ insert: '5' },
|
|
703
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '5', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'thead' } }, insert: '\n' },
|
|
704
|
+
{ insert: 'merge' },
|
|
705
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '1', rowspan: 3, colspan: 5, tag: 'td', wrapTag: 'thead', emptyRow: ['3', '4'] } }, insert: '\n' },
|
|
706
|
+
{ insert: '6' },
|
|
707
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '1', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
708
|
+
{ insert: '7' },
|
|
709
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '2', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
710
|
+
{ insert: '8' },
|
|
711
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '3', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
712
|
+
{ insert: '9' },
|
|
713
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '4', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
714
|
+
{ insert: '10' },
|
|
715
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '5', colId: '5', rowspan: 1, colspan: 1, tag: 'td', wrapTag: 'tbody' } }, insert: '\n' },
|
|
716
|
+
{ insert: '\n' },
|
|
717
|
+
]),
|
|
718
|
+
);
|
|
719
|
+
});
|
|
720
|
+
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Quill from 'quill';
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { TableCellInnerFormat } from '../../formats';
|
|
3
4
|
import { TableUp } from '../../table-up';
|
|
4
|
-
import { createQuillWithTableModule, createTableBodyHTML, createTableCaptionHTML, createTableDeltaOps, createTableHTML, createTaleColHTML, datasetTag, expectDelta, simulatePasteHTML } from './utils';
|
|
5
|
+
import { createQuillWithTableModule, createTableBodyHTML, createTableCaptionHTML, createTableDeltaOps, createTableHTML, createTaleColHTML, datasetTag, expectDelta, replaceAttrEmptyRow, simulatePasteHTML } from './utils';
|
|
5
6
|
|
|
6
7
|
const Delta = Quill.import('delta');
|
|
7
8
|
|
|
@@ -956,14 +957,172 @@ describe('clipboard cell structure', () => {
|
|
|
956
957
|
);
|
|
957
958
|
});
|
|
958
959
|
|
|
959
|
-
it('clipboard convert empty tr to `emptyRow`', async () => {
|
|
960
|
+
it('clipboard convert empty multiple tr to `emptyRow`', async () => {
|
|
961
|
+
const quill = createQuillWithTableModule('<p><br></p>', { autoMergeCell: false });
|
|
962
|
+
quill.setContents(
|
|
963
|
+
quill.clipboard.convert({
|
|
964
|
+
html: `<table><tbody><tr><td rowspan="3" colspan="3">1</td></tr><tr></tr><tr></tr><tr><td>2</td><td>3</td><td>4</td></tr></tbody></table>`,
|
|
965
|
+
}),
|
|
966
|
+
);
|
|
967
|
+
await vi.runAllTimersAsync();
|
|
968
|
+
|
|
969
|
+
expect(quill.root).toEqualHTML(
|
|
970
|
+
`
|
|
971
|
+
<p><br></p>
|
|
972
|
+
<div>
|
|
973
|
+
<table cellpadding="0" cellspacing="0">
|
|
974
|
+
${createTaleColHTML(3, { full: false, width: 100 })}
|
|
975
|
+
<tbody>
|
|
976
|
+
<tr>
|
|
977
|
+
<td rowspan="3" colspan="3" data-empty-row="length:2">
|
|
978
|
+
<div data-empty-row="length:2"><p>1</p></div>
|
|
979
|
+
</td>
|
|
980
|
+
</tr>
|
|
981
|
+
<tr>
|
|
982
|
+
</tr>
|
|
983
|
+
<tr>
|
|
984
|
+
</tr>
|
|
985
|
+
<tr>
|
|
986
|
+
<td rowspan="1" colspan="1">
|
|
987
|
+
<div><p>2</p></div>
|
|
988
|
+
</td>
|
|
989
|
+
<td rowspan="1" colspan="1">
|
|
990
|
+
<div><p>3</p></div>
|
|
991
|
+
</td>
|
|
992
|
+
<td rowspan="1" colspan="1">
|
|
993
|
+
<div><p>4</p></div>
|
|
994
|
+
</td>
|
|
995
|
+
</tr>
|
|
996
|
+
</tbody>
|
|
997
|
+
</table>
|
|
998
|
+
</div>
|
|
999
|
+
<p><br></p>
|
|
1000
|
+
`,
|
|
1001
|
+
{
|
|
1002
|
+
ignoreAttrs: ['data-wrap-tag', 'data-tag', 'class', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'data-style', 'style', 'contenteditable'],
|
|
1003
|
+
replaceAttrs: {
|
|
1004
|
+
'data-empty-row': replaceAttrEmptyRow,
|
|
1005
|
+
},
|
|
1006
|
+
},
|
|
1007
|
+
);
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
it('clipboard convert `emptyRow` cell', async () => {
|
|
1011
|
+
const quill = createQuillWithTableModule('<p><br></p>', { autoMergeCell: false });
|
|
1012
|
+
quill.setContents(
|
|
1013
|
+
quill.clipboard.convert({
|
|
1014
|
+
html: `<div class="ql-table-wrapper" data-table-id="4rxokyjlh63" contenteditable="false"><table class="ql-table" data-table-id="4rxokyjlh63" cellpadding="0" cellspacing="0" style="margin-right: auto; width: 300px;"><colgroup data-table-id="4rxokyjlh63" contenteditable="false"><col width="100px" data-table-id="4rxokyjlh63" data-col-id="y5a4z42ufdr"><col width="100px" data-table-id="4rxokyjlh63" data-col-id="ukr081pgksl"><col width="100px" data-table-id="4rxokyjlh63" data-col-id="0kg1x92lxzv"></colgroup><tbody data-table-id="4rxokyjlh63"><tr class="ql-table-row" data-table-id="4rxokyjlh63" data-row-id="uezdr0no6w8" data-wrap-tag="tbody"><td class="ql-table-cell" data-table-id="4rxokyjlh63" data-row-id="uezdr0no6w8" data-col-id="y5a4z42ufdr" data-wrap-tag="tbody" rowspan="3" colspan="3" data-empty-row="["xghllrjrcar","j2cc6owtd9l"]"><div class="ql-table-cell-inner" data-table-id="4rxokyjlh63" data-row-id="uezdr0no6w8" data-col-id="y5a4z42ufdr" data-rowspan="3" data-colspan="3" data-tag="td" data-wrap-tag="tbody" data-empty-row="["xghllrjrcar","j2cc6owtd9l"]" contenteditable="true"><p><span>1</span></p></div></td></tr><tr class="ql-table-row" data-table-id="4rxokyjlh63" data-row-id="j2cc6owtd9l" data-wrap-tag="tbody"></tr><tr class="ql-table-row" data-table-id="4rxokyjlh63" data-row-id="xghllrjrcar" data-wrap-tag="tbody"></tr><tr class="ql-table-row" data-table-id="4rxokyjlh63" data-row-id="afwfmtyccci" data-wrap-tag="tbody"><td class="ql-table-cell" data-table-id="4rxokyjlh63" data-row-id="afwfmtyccci" data-col-id="y5a4z42ufdr" data-wrap-tag="tbody" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="4rxokyjlh63" data-row-id="afwfmtyccci" data-col-id="y5a4z42ufdr" data-rowspan="1" data-colspan="1" data-tag="td" data-wrap-tag="tbody" contenteditable="true"><p><span>2</span></p></div></td><td class="ql-table-cell" data-table-id="4rxokyjlh63" data-row-id="afwfmtyccci" data-col-id="ukr081pgksl" data-wrap-tag="tbody" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="4rxokyjlh63" data-row-id="afwfmtyccci" data-col-id="ukr081pgksl" data-rowspan="1" data-colspan="1" data-tag="td" data-wrap-tag="tbody" contenteditable="true"><p><span>3</span></p></div></td><td class="ql-table-cell" data-table-id="4rxokyjlh63" data-row-id="afwfmtyccci" data-col-id="0kg1x92lxzv" data-wrap-tag="tbody" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="4rxokyjlh63" data-row-id="afwfmtyccci" data-col-id="0kg1x92lxzv" data-rowspan="1" data-colspan="1" data-tag="td" data-wrap-tag="tbody" contenteditable="true"><p><span>4</span></p></div></td></tr></tbody></table></div>`,
|
|
1015
|
+
}),
|
|
1016
|
+
);
|
|
1017
|
+
await vi.runAllTimersAsync();
|
|
1018
|
+
|
|
1019
|
+
expect(quill.root).toEqualHTML(
|
|
1020
|
+
`
|
|
1021
|
+
<p><br></p>
|
|
1022
|
+
<div>
|
|
1023
|
+
<table cellpadding="0" cellspacing="0">
|
|
1024
|
+
${createTaleColHTML(3, { full: false, width: 100 })}
|
|
1025
|
+
<tbody>
|
|
1026
|
+
<tr>
|
|
1027
|
+
<td rowspan="3" colspan="3" data-empty-row="length:2">
|
|
1028
|
+
<div data-empty-row="length:2"><p>1</p></div>
|
|
1029
|
+
</td>
|
|
1030
|
+
</tr>
|
|
1031
|
+
<tr>
|
|
1032
|
+
</tr>
|
|
1033
|
+
<tr>
|
|
1034
|
+
</tr>
|
|
1035
|
+
<tr>
|
|
1036
|
+
<td rowspan="1" colspan="1">
|
|
1037
|
+
<div><p>2</p></div>
|
|
1038
|
+
</td>
|
|
1039
|
+
<td rowspan="1" colspan="1">
|
|
1040
|
+
<div><p>3</p></div>
|
|
1041
|
+
</td>
|
|
1042
|
+
<td rowspan="1" colspan="1">
|
|
1043
|
+
<div><p>4</p></div>
|
|
1044
|
+
</td>
|
|
1045
|
+
</tr>
|
|
1046
|
+
</tbody>
|
|
1047
|
+
</table>
|
|
1048
|
+
</div>
|
|
1049
|
+
<p><br></p>
|
|
1050
|
+
`,
|
|
1051
|
+
{
|
|
1052
|
+
ignoreAttrs: ['data-wrap-tag', 'data-tag', 'class', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'data-style', 'style', 'contenteditable'],
|
|
1053
|
+
replaceAttrs: {
|
|
1054
|
+
'data-empty-row': replaceAttrEmptyRow,
|
|
1055
|
+
},
|
|
1056
|
+
},
|
|
1057
|
+
);
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1060
|
+
it('clipboard convert continuous `emptyRow`', async () => {
|
|
1061
|
+
const quill = createQuillWithTableModule('<p><br></p>', { autoMergeCell: false });
|
|
1062
|
+
quill.setContents(
|
|
1063
|
+
quill.clipboard.convert({
|
|
1064
|
+
html: `<div class="ql-table-wrapper" data-table-id="c0o77jksufl" contenteditable="false"><table class="ql-table" data-table-id="c0o77jksufl" cellpadding="0" cellspacing="0" style="margin-right: auto; width: 300px;"><colgroup data-table-id="c0o77jksufl" contenteditable="false"><col width="100px" data-table-id="c0o77jksufl" data-col-id="a49uy7ts9x"><col width="100px" data-table-id="c0o77jksufl" data-col-id="9rvrf9ve5dp"><col width="100px" data-table-id="c0o77jksufl" data-col-id="vi4hyjmdii"></colgroup><tbody data-table-id="c0o77jksufl"><tr class="ql-table-row" data-table-id="c0o77jksufl" data-row-id="0oi5ud6p8jne" data-wrap-tag="tbody"><td class="ql-table-cell" data-table-id="c0o77jksufl" data-row-id="0oi5ud6p8jne" data-col-id="a49uy7ts9x" data-wrap-tag="tbody" rowspan="3" colspan="3" data-empty-row="["xdpparkt6l","ghbvv1sg1pu"]"><div class="ql-table-cell-inner" data-table-id="c0o77jksufl" data-row-id="0oi5ud6p8jne" data-col-id="a49uy7ts9x" data-rowspan="3" data-colspan="3" data-tag="td" data-wrap-tag="tbody" data-empty-row="["xdpparkt6l","ghbvv1sg1pu"]" contenteditable="true"><p><span>1</span></p></div></td></tr><tr class="ql-table-row" data-table-id="c0o77jksufl" data-row-id="ghbvv1sg1pu" data-wrap-tag="tbody"></tr><tr class="ql-table-row" data-table-id="c0o77jksufl" data-row-id="xdpparkt6l" data-wrap-tag="tbody"></tr><tr class="ql-table-row" data-table-id="c0o77jksufl" data-row-id="3mnrj0uu4rh" data-wrap-tag="tbody"><td class="ql-table-cell" data-table-id="c0o77jksufl" data-row-id="3mnrj0uu4rh" data-col-id="a49uy7ts9x" data-wrap-tag="tbody" rowspan="3" colspan="3" data-empty-row="["7au43sfdyh2","a2u11wlu63"]"><div class="ql-table-cell-inner" data-table-id="c0o77jksufl" data-row-id="3mnrj0uu4rh" data-col-id="a49uy7ts9x" data-rowspan="3" data-colspan="3" data-tag="td" data-wrap-tag="tbody" data-empty-row="["7au43sfdyh2","a2u11wlu63"]" contenteditable="true"><p><span>1</span></p></div></td></tr><tr class="ql-table-row" data-table-id="c0o77jksufl" data-row-id="a2u11wlu63" data-wrap-tag="tbody"></tr><tr class="ql-table-row" data-table-id="c0o77jksufl" data-row-id="7au43sfdyh2" data-wrap-tag="tbody"></tr><tr class="ql-table-row" data-table-id="c0o77jksufl" data-row-id="qhrdlqjpdeq" data-wrap-tag="tbody"><td class="ql-table-cell" data-table-id="c0o77jksufl" data-row-id="qhrdlqjpdeq" data-col-id="a49uy7ts9x" data-wrap-tag="tbody" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="c0o77jksufl" data-row-id="qhrdlqjpdeq" data-col-id="a49uy7ts9x" data-rowspan="1" data-colspan="1" data-tag="td" data-wrap-tag="tbody" contenteditable="true"><p><span>2</span></p></div></td><td class="ql-table-cell" data-table-id="c0o77jksufl" data-row-id="qhrdlqjpdeq" data-col-id="9rvrf9ve5dp" data-wrap-tag="tbody" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="c0o77jksufl" data-row-id="qhrdlqjpdeq" data-col-id="9rvrf9ve5dp" data-rowspan="1" data-colspan="1" data-tag="td" data-wrap-tag="tbody" contenteditable="true"><p><span>3</span></p></div></td><td class="ql-table-cell" data-table-id="c0o77jksufl" data-row-id="qhrdlqjpdeq" data-col-id="vi4hyjmdii" data-wrap-tag="tbody" rowspan="1" colspan="1"><div class="ql-table-cell-inner" data-table-id="c0o77jksufl" data-row-id="qhrdlqjpdeq" data-col-id="vi4hyjmdii" data-rowspan="1" data-colspan="1" data-tag="td" data-wrap-tag="tbody" contenteditable="true"><p><span>4</span></p></div></td></tr></tbody></table></div>`,
|
|
1065
|
+
}),
|
|
1066
|
+
);
|
|
1067
|
+
await vi.runAllTimersAsync();
|
|
1068
|
+
|
|
1069
|
+
expect(quill.root).toEqualHTML(
|
|
1070
|
+
`
|
|
1071
|
+
<p><br></p>
|
|
1072
|
+
<div>
|
|
1073
|
+
<table cellpadding="0" cellspacing="0">
|
|
1074
|
+
${createTaleColHTML(3, { full: false, width: 100 })}
|
|
1075
|
+
<tbody>
|
|
1076
|
+
<tr>
|
|
1077
|
+
<td rowspan="3" colspan="3" data-empty-row="length:2">
|
|
1078
|
+
<div data-empty-row="length:2"><p>1</p></div>
|
|
1079
|
+
</td>
|
|
1080
|
+
</tr>
|
|
1081
|
+
<tr>
|
|
1082
|
+
</tr>
|
|
1083
|
+
<tr>
|
|
1084
|
+
</tr>
|
|
1085
|
+
<tr>
|
|
1086
|
+
<td rowspan="3" colspan="3" data-empty-row="length:2">
|
|
1087
|
+
<div data-empty-row="length:2"><p>1</p></div>
|
|
1088
|
+
</td>
|
|
1089
|
+
</tr>
|
|
1090
|
+
<tr>
|
|
1091
|
+
</tr>
|
|
1092
|
+
<tr>
|
|
1093
|
+
</tr>
|
|
1094
|
+
<tr>
|
|
1095
|
+
<td rowspan="1" colspan="1">
|
|
1096
|
+
<div><p>2</p></div>
|
|
1097
|
+
</td>
|
|
1098
|
+
<td rowspan="1" colspan="1">
|
|
1099
|
+
<div><p>3</p></div>
|
|
1100
|
+
</td>
|
|
1101
|
+
<td rowspan="1" colspan="1">
|
|
1102
|
+
<div><p>4</p></div>
|
|
1103
|
+
</td>
|
|
1104
|
+
</tr>
|
|
1105
|
+
</tbody>
|
|
1106
|
+
</table>
|
|
1107
|
+
</div>
|
|
1108
|
+
<p><br></p>
|
|
1109
|
+
`,
|
|
1110
|
+
{
|
|
1111
|
+
ignoreAttrs: ['data-wrap-tag', 'data-tag', 'class', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'data-style', 'style', 'contenteditable'],
|
|
1112
|
+
replaceAttrs: {
|
|
1113
|
+
'data-empty-row': replaceAttrEmptyRow,
|
|
1114
|
+
},
|
|
1115
|
+
},
|
|
1116
|
+
);
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
it('clipboard convert empty tr to `emptyRow` in thead', async () => {
|
|
960
1120
|
const quill = createQuillWithTableModule(`<p><br></p>`, { autoMergeCell: false });
|
|
961
1121
|
quill.setContents(
|
|
962
1122
|
quill.clipboard.convert({
|
|
963
1123
|
html: `<table><thead><tr><td rowspan="2" colspan="2">1</td></tr><tr></tr></thead><tbody><tr><td>1</td><td>2</td></tr><tr><td>1</td><td>2</td></tr></tbody></table>`,
|
|
964
1124
|
}),
|
|
965
1125
|
);
|
|
966
|
-
|
|
967
1126
|
await vi.runAllTimersAsync();
|
|
968
1127
|
|
|
969
1128
|
expect(quill.root).toEqualHTML(
|
|
@@ -1006,15 +1165,7 @@ describe('clipboard cell structure', () => {
|
|
|
1006
1165
|
{
|
|
1007
1166
|
ignoreAttrs: ['data-wrap-tag', 'data-tag', 'class', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'data-style', 'style', 'contenteditable'],
|
|
1008
1167
|
replaceAttrs: {
|
|
1009
|
-
'data-empty-row':
|
|
1010
|
-
try {
|
|
1011
|
-
const emptyRow = JSON.parse(value);
|
|
1012
|
-
return `length:${emptyRow.length}`;
|
|
1013
|
-
}
|
|
1014
|
-
catch {
|
|
1015
|
-
return value;
|
|
1016
|
-
}
|
|
1017
|
-
},
|
|
1168
|
+
'data-empty-row': replaceAttrEmptyRow,
|
|
1018
1169
|
},
|
|
1019
1170
|
},
|
|
1020
1171
|
);
|
|
@@ -1112,15 +1263,7 @@ describe('clipboard cell structure', () => {
|
|
|
1112
1263
|
{
|
|
1113
1264
|
ignoreAttrs: ['data-wrap-tag', 'data-tag', 'class', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'data-style', 'style', 'contenteditable'],
|
|
1114
1265
|
replaceAttrs: {
|
|
1115
|
-
'data-empty-row':
|
|
1116
|
-
try {
|
|
1117
|
-
const emptyRow = JSON.parse(value);
|
|
1118
|
-
return `length:${emptyRow.length}`;
|
|
1119
|
-
}
|
|
1120
|
-
catch {
|
|
1121
|
-
return value;
|
|
1122
|
-
}
|
|
1123
|
-
},
|
|
1266
|
+
'data-empty-row': replaceAttrEmptyRow,
|
|
1124
1267
|
},
|
|
1125
1268
|
},
|
|
1126
1269
|
);
|
|
@@ -2008,3 +2151,26 @@ describe('clipboard cell in cell', () => {
|
|
|
2008
2151
|
);
|
|
2009
2152
|
});
|
|
2010
2153
|
});
|
|
2154
|
+
|
|
2155
|
+
describe('test TableUp `getHTMLByCell`', () => {
|
|
2156
|
+
it('getHTMLByCell return cell html', async () => {
|
|
2157
|
+
const quill = createQuillWithTableModule(`<p><br></p>`);
|
|
2158
|
+
quill.setContents(createTableDeltaOps(4, 4, { full: true }, {}, { isEmpty: false }));
|
|
2159
|
+
|
|
2160
|
+
const tableModule = quill.getModule(TableUp.moduleName) as TableUp;
|
|
2161
|
+
const tds = quill.scroll.descendants(TableCellInnerFormat, 0);
|
|
2162
|
+
tableModule.mergeCells([tds[0], tds[1], tds[4], tds[5]]);
|
|
2163
|
+
await vi.runAllTimersAsync();
|
|
2164
|
+
|
|
2165
|
+
const html = tableModule.getHTMLByCell([tds[0], tds[2], tds[6]]);
|
|
2166
|
+
const parser = new DOMParser();
|
|
2167
|
+
const doc = parser.parseFromString(html, 'text/html');
|
|
2168
|
+
const htmlCols = Array.from(doc.querySelectorAll('col'));
|
|
2169
|
+
const htmlTds = Array.from(doc.querySelectorAll('td'));
|
|
2170
|
+
expect(htmlCols.length).toBe(3);
|
|
2171
|
+
expect(htmlTds.length).toBe(3);
|
|
2172
|
+
for (const col of htmlCols) {
|
|
2173
|
+
expect(col.getAttribute('width')).toBe('33%');
|
|
2174
|
+
}
|
|
2175
|
+
});
|
|
2176
|
+
});
|