quill-table-up 3.1.2 → 3.2.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.
Files changed (111) hide show
  1. package/README.md +7 -0
  2. package/dist/index.css +1 -1
  3. package/dist/index.d.ts +168 -146
  4. package/dist/index.js +47 -47
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.umd.js +52 -52
  7. package/dist/index.umd.js.map +1 -1
  8. package/package.json +22 -24
  9. package/src/__tests__/e2e/custom-creator.test.ts +44 -44
  10. package/src/__tests__/e2e/editor-page.ts +77 -77
  11. package/src/__tests__/e2e/table-align.test.ts +104 -104
  12. package/src/__tests__/e2e/table-blots.test.ts +169 -169
  13. package/src/__tests__/e2e/table-caption.test.ts +134 -134
  14. package/src/__tests__/e2e/table-clipboard.test.ts +20 -20
  15. package/src/__tests__/e2e/table-hack.test.ts +151 -151
  16. package/src/__tests__/e2e/table-keyboard-handler.test.ts +12 -3
  17. package/src/__tests__/e2e/table-menu.test.ts +172 -172
  18. package/src/__tests__/e2e/table-resize.test.ts +654 -9
  19. package/src/__tests__/e2e/table-scrollbar.test.ts +144 -144
  20. package/src/__tests__/e2e/table-selection.test.ts +563 -563
  21. package/src/__tests__/e2e/types.d.ts +7 -7
  22. package/src/__tests__/e2e/utils.ts +52 -52
  23. package/src/__tests__/unit/table-blots.test.ts +720 -720
  24. package/src/__tests__/unit/table-caption.test.ts +234 -234
  25. package/src/__tests__/unit/table-cell-merge.test.ts +724 -724
  26. package/src/__tests__/unit/table-clipboard.test.ts +2176 -2176
  27. package/src/__tests__/unit/table-hack.test.ts +1014 -1014
  28. package/src/__tests__/unit/table-insert.test.ts +926 -926
  29. package/src/__tests__/unit/table-redo-undo.test.ts +2429 -2429
  30. package/src/__tests__/unit/table-remove.test.ts +343 -343
  31. package/src/__tests__/unit/utils.test-d.ts +49 -49
  32. package/src/__tests__/unit/utils.test.ts +711 -711
  33. package/src/__tests__/unit/utils.ts +307 -307
  34. package/src/__tests__/unit/vitest.d.ts +14 -14
  35. package/src/formats/container-format.ts +107 -107
  36. package/src/formats/overrides/block-embed.ts +72 -72
  37. package/src/formats/overrides/block.ts +95 -95
  38. package/src/formats/overrides/index.ts +3 -3
  39. package/src/formats/overrides/scroll.ts +70 -70
  40. package/src/formats/table-body-format.ts +52 -52
  41. package/src/formats/table-caption-format.ts +116 -116
  42. package/src/formats/table-cell-format.ts +304 -304
  43. package/src/formats/table-cell-inner-format.ts +403 -398
  44. package/src/formats/table-colgroup-format.ts +136 -136
  45. package/src/formats/table-foot-format.ts +7 -7
  46. package/src/formats/table-head-format.ts +7 -7
  47. package/src/formats/table-main-format.ts +1 -1
  48. package/src/formats/table-row-format.ts +218 -210
  49. package/src/formats/utils.ts +6 -6
  50. package/src/index.ts +19 -19
  51. package/src/modules/index.ts +7 -7
  52. package/src/modules/table-align.ts +131 -131
  53. package/src/modules/table-clipboard/table-clipboard.ts +6 -8
  54. package/src/modules/table-dom-selector.ts +33 -33
  55. package/src/modules/table-menu/constants.ts +223 -223
  56. package/src/modules/table-menu/index.ts +4 -4
  57. package/src/modules/table-menu/table-menu-common.ts +330 -329
  58. package/src/modules/table-menu/table-menu-contextmenu.ts +111 -118
  59. package/src/modules/table-menu/table-menu-select.ts +96 -94
  60. package/src/modules/table-resize/index.ts +5 -5
  61. package/src/modules/table-resize/table-resize-box.ts +714 -363
  62. package/src/modules/table-resize/table-resize-common.ts +246 -382
  63. package/src/modules/table-resize/table-resize-drag.ts +241 -0
  64. package/src/modules/table-resize/table-resize-line.ts +244 -182
  65. package/src/modules/table-resize/table-resize-scale.ts +174 -173
  66. package/src/modules/table-resize/utils.ts +84 -3
  67. package/src/modules/table-scrollbar.ts +292 -292
  68. package/src/modules/table-selection.ts +613 -669
  69. package/src/style/button.less +45 -45
  70. package/src/style/color-picker.less +136 -136
  71. package/src/style/dialog.less +53 -53
  72. package/src/style/functions.less +9 -9
  73. package/src/style/index.less +120 -120
  74. package/src/style/input.less +64 -64
  75. package/src/style/select-box.less +52 -52
  76. package/src/style/table-creator.less +56 -56
  77. package/src/style/table-menu.less +125 -125
  78. package/src/style/table-resize-scale.less +31 -31
  79. package/src/style/table-resize.less +249 -202
  80. package/src/style/table-scrollbar.less +49 -49
  81. package/src/style/table-selection.less +23 -23
  82. package/src/style/tooltip.less +19 -19
  83. package/src/style/variables.less +1 -1
  84. package/src/svg/arrow-up-down.svg +11 -11
  85. package/src/svg/convert-cell.svg +7 -7
  86. package/src/table-up.ts +1360 -1360
  87. package/src/types.d.ts +4 -4
  88. package/src/utils/bem.ts +23 -23
  89. package/src/utils/blot-helper.ts +101 -105
  90. package/src/utils/color.ts +109 -109
  91. package/src/utils/components/button.ts +22 -22
  92. package/src/utils/components/color-picker.ts +236 -236
  93. package/src/utils/components/dialog.ts +83 -41
  94. package/src/utils/components/index.ts +6 -6
  95. package/src/utils/components/input.ts +74 -74
  96. package/src/utils/components/table/creator.ts +89 -89
  97. package/src/utils/components/table/index.ts +2 -2
  98. package/src/utils/components/table/select-box.ts +78 -78
  99. package/src/utils/components/tooltip.ts +179 -189
  100. package/src/utils/constants.ts +125 -124
  101. package/src/utils/drag-helper.ts +112 -0
  102. package/src/utils/index.ts +15 -14
  103. package/src/utils/is.ts +9 -9
  104. package/src/utils/position.ts +60 -60
  105. package/src/utils/resize-observer-helper.ts +47 -47
  106. package/src/utils/scroll.ts +145 -47
  107. package/src/utils/style-helper.ts +47 -47
  108. package/src/utils/transformer.ts +10 -10
  109. package/src/utils/transition-event-helper.ts +8 -8
  110. package/src/utils/types.ts +156 -157
  111. package/src/utils/utils.ts +12 -12
@@ -1,173 +1,174 @@
1
- import type { TableColFormat, TableMainFormat, TableRowFormat, TableWrapperFormat } from '../../formats';
2
- import type { TableUp } from '../../table-up';
3
- import type { TableResizeScaleOptions } from '../../utils';
4
- import Quill from 'quill';
5
- import { getTableMainRect } from '../../formats';
6
- import { addScrollEvent, clearScrollEvent, createBEM, tableUpSize } from '../../utils';
7
- import { TableDomSelector } from '../table-dom-selector';
8
- import { isTableAlignRight } from './utils';
9
-
10
- export class TableResizeScale extends TableDomSelector {
11
- scrollHandler: [HTMLElement, (e: Event) => void][] = [];
12
- tableMainBlot?: TableMainFormat;
13
- tableWrapperBlot?: TableWrapperFormat;
14
- bem = createBEM('scale');
15
- startX: number = 0;
16
- startY: number = 0;
17
- offset: number = 6;
18
- options: TableResizeScaleOptions;
19
- root?: HTMLElement;
20
- block?: HTMLElement;
21
- resizeobserver: ResizeObserver = new ResizeObserver(() => this.update());
22
- constructor(public tableModule: TableUp, public quill: Quill, options: Partial<TableResizeScaleOptions>) {
23
- super(tableModule, quill);
24
- this.options = this.resolveOptions(options);
25
-
26
- this.quill.on(Quill.events.EDITOR_CHANGE, this.updateWhenTextChange);
27
- }
28
-
29
- updateWhenTextChange = (eventName: string) => {
30
- if (eventName === Quill.events.TEXT_CHANGE) {
31
- if (this.table && !this.quill.root.contains(this.table)) {
32
- this.setSelectionTable(undefined);
33
- }
34
- else {
35
- this.update();
36
- }
37
- }
38
- };
39
-
40
- resolveOptions(options: Partial<TableResizeScaleOptions>) {
41
- return Object.assign({
42
- blockSize: 12,
43
- }, options);
44
- }
45
-
46
- buildResizer() {
47
- if (!this.tableMainBlot || !this.tableWrapperBlot) return;
48
- this.root = this.tableModule.addContainer(this.bem.b());
49
- this.block = document.createElement('div');
50
- this.block.classList.add(this.bem.be('block'));
51
- Object.assign(this.block.style, {
52
- width: `${this.options.blockSize}px`,
53
- height: `${this.options.blockSize}px`,
54
- });
55
- this.root.appendChild(this.block);
56
-
57
- let originColWidth: { blot: TableColFormat; width: number }[] = [];
58
- let originRowHeight: { blot: TableRowFormat; height: number }[] = [];
59
- const handleMouseMove = (e: MouseEvent) => {
60
- if (!this.tableMainBlot) return;
61
- // divide equally by col count/row count
62
- const isRight = isTableAlignRight(this.tableMainBlot) ? -1 : 1;
63
- const diffX = (e.clientX - this.startX) * isRight;
64
- const diffY = e.clientY - this.startY;
65
- const itemWidth = Math.floor(diffX / originColWidth.length);
66
- const itemHeight = Math.floor(diffY / originRowHeight.length);
67
-
68
- for (const { blot, width } of originColWidth) {
69
- blot.width = Math.max(width + itemWidth, tableUpSize.colMinWidthPx);
70
- }
71
- for (const { blot, height } of originRowHeight) {
72
- blot.setHeight(`${Math.max(height + itemHeight, tableUpSize.rowMinHeightPx)}px`);
73
- }
74
- };
75
- const handleMouseUp = () => {
76
- originColWidth = [];
77
- originRowHeight = [];
78
- document.removeEventListener('mousemove', handleMouseMove);
79
- document.removeEventListener('mouseup', handleMouseUp);
80
- };
81
- this.block.addEventListener('mousedown', (e) => {
82
- if (!this.tableMainBlot || this.isTableOutofEditor()) return;
83
- this.startX = e.clientX;
84
- this.startY = e.clientY;
85
- // save the origin width and height to calculate result width and height
86
- originColWidth = this.tableMainBlot.getCols().map(col => ({ blot: col, width: Math.floor(col.width) }));
87
- originRowHeight = this.tableMainBlot.getRows().map(row => ({ blot: row, height: Math.floor(row.domNode.getBoundingClientRect().height) }));
88
- document.addEventListener('mousemove', handleMouseMove);
89
- document.addEventListener('mouseup', handleMouseUp);
90
- });
91
- this.block.addEventListener('dragstart', e => e.preventDefault());
92
- }
93
-
94
- isTableOutofEditor(): boolean {
95
- if (!this.tableMainBlot || !this.tableWrapperBlot || this.tableMainBlot.full) return false;
96
- // if tableMain width larger than tableWrapper. reset tableMain width equal editor width
97
- const tableRect = this.tableMainBlot.domNode.getBoundingClientRect();
98
- const tableWrapperRect = this.tableWrapperBlot.domNode.getBoundingClientRect();
99
- // equal scale
100
- if (tableRect.width > tableWrapperRect.width) {
101
- for (const col of this.tableMainBlot.getCols()) {
102
- col.width = Math.floor((col.width / tableRect.width) * tableWrapperRect.width);
103
- }
104
- this.tableMainBlot.colWidthFillTable();
105
- return true;
106
- }
107
- return false;
108
- }
109
-
110
- update() {
111
- if (!this.block || !this.root || !this.tableMainBlot || !this.tableWrapperBlot) return;
112
- if (this.tableMainBlot.full) {
113
- this.hide();
114
- return;
115
- }
116
- const { rect: tableRect } = getTableMainRect(this.tableMainBlot);
117
- if (!tableRect) return;
118
- const tableWrapperRect = this.tableWrapperBlot.domNode.getBoundingClientRect();
119
- const editorRect = this.quill.root.getBoundingClientRect();
120
- const { scrollTop, scrollLeft } = this.tableWrapperBlot.domNode;
121
- const blockSize = this.options.blockSize * 2 + this.offset;
122
- const rootWidth = Math.min(tableRect.width, tableWrapperRect.width) + blockSize;
123
- const rootHeight = Math.min(tableRect.height, tableWrapperRect.height) + blockSize;
124
- Object.assign(this.root.style, {
125
- width: `${rootWidth}px`,
126
- height: `${rootHeight}px`,
127
- left: `${Math.max(tableRect.x, tableWrapperRect.x) - editorRect.x - this.options.blockSize}px`,
128
- top: `${Math.max(tableRect.y, tableWrapperRect.y) - editorRect.y - this.options.blockSize}px`,
129
- });
130
- const blockStyle = {
131
- left: `${tableRect.width + blockSize - scrollLeft}px`,
132
- top: `${rootHeight - scrollTop}px`,
133
- };
134
- if (isTableAlignRight(this.tableMainBlot)) {
135
- this.root.classList.add(this.bem.is('align-right'));
136
- blockStyle.left = `${this.options.blockSize + -1 * scrollLeft}px`;
137
- }
138
- else {
139
- this.root.classList.remove(this.bem.is('align-right'));
140
- }
141
- Object.assign(this.block.style, blockStyle);
142
- }
143
-
144
- show() {
145
- if (!this.table) return;
146
- this.tableMainBlot = Quill.find(this.table) as TableMainFormat;
147
- if (this.tableMainBlot && !this.tableMainBlot.full) {
148
- this.tableWrapperBlot = this.tableMainBlot.parent as TableWrapperFormat;
149
-
150
- this.resizeobserver.observe(this.tableMainBlot.domNode);
151
- addScrollEvent.call(this, this.quill.root, () => this.update());
152
- addScrollEvent.call(this, this.tableWrapperBlot.domNode, () => this.update());
153
- }
154
- this.buildResizer();
155
- }
156
-
157
- hide() {
158
- this.tableMainBlot = undefined;
159
- this.tableWrapperBlot = undefined;
160
- if (this.root) {
161
- this.root.remove();
162
- this.root = undefined;
163
- this.block = undefined;
164
- }
165
- }
166
-
167
- destroy() {
168
- this.hide();
169
- this.quill.off(Quill.events.TEXT_CHANGE, this.updateWhenTextChange);
170
- this.resizeobserver.disconnect();
171
- clearScrollEvent.call(this);
172
- }
173
- }
1
+ import type { TableColFormat, TableMainFormat, TableRowFormat, TableWrapperFormat } from '../../formats';
2
+ import type { TableUp } from '../../table-up';
3
+ import type { TableResizeScaleOptions } from '../../utils';
4
+ import Quill from 'quill';
5
+ import { getTableMainRect } from '../../formats';
6
+ import { addScrollEvent, clearScrollEvent, createBEM, tableUpSize } from '../../utils';
7
+ import { TableDomSelector } from '../table-dom-selector';
8
+ import { isTableAlignRight } from './utils';
9
+
10
+ export class TableResizeScale extends TableDomSelector {
11
+ static moduleName = 'table-resize-scale';
12
+
13
+ scrollHandler: [HTMLElement, (e: Event) => void][] = [];
14
+ tableMainBlot?: TableMainFormat;
15
+ tableWrapperBlot?: TableWrapperFormat;
16
+ bem = createBEM('scale');
17
+ startX: number = 0;
18
+ startY: number = 0;
19
+ offset: number = 6;
20
+ options: TableResizeScaleOptions;
21
+ root?: HTMLElement;
22
+ block?: HTMLElement;
23
+ resizeobserver: ResizeObserver = new ResizeObserver(() => this.update());
24
+ constructor(public tableModule: TableUp, public quill: Quill, options: Partial<TableResizeScaleOptions>) {
25
+ super(tableModule, quill);
26
+ this.options = this.resolveOptions(options);
27
+
28
+ this.quill.on(Quill.events.EDITOR_CHANGE, this.updateWhenTextChange);
29
+ }
30
+
31
+ updateWhenTextChange = (eventName: string) => {
32
+ if (eventName === Quill.events.TEXT_CHANGE) {
33
+ if (this.table && !this.quill.root.contains(this.table)) {
34
+ this.setSelectionTable(undefined);
35
+ }
36
+ else {
37
+ this.update();
38
+ }
39
+ }
40
+ };
41
+
42
+ resolveOptions(options: Partial<TableResizeScaleOptions>) {
43
+ return Object.assign({
44
+ blockSize: 12,
45
+ }, options);
46
+ }
47
+
48
+ buildResizer() {
49
+ if (!this.tableMainBlot || !this.tableWrapperBlot) return;
50
+ this.root = this.tableModule.addContainer(this.bem.b());
51
+ this.block = document.createElement('div');
52
+ this.block.classList.add(this.bem.be('block'));
53
+ Object.assign(this.block.style, {
54
+ width: `${this.options.blockSize}px`,
55
+ height: `${this.options.blockSize}px`,
56
+ });
57
+ this.root.appendChild(this.block);
58
+
59
+ let originColWidth: { blot: TableColFormat; width: number }[] = [];
60
+ let originRowHeight: { blot: TableRowFormat; height: number }[] = [];
61
+ const handleMouseMove = (e: MouseEvent) => {
62
+ if (!this.tableMainBlot) return;
63
+ // divide equally by col count/row count
64
+ const isRight = isTableAlignRight(this.tableMainBlot) ? -1 : 1;
65
+ const diffX = (e.clientX - this.startX) * isRight;
66
+ const diffY = e.clientY - this.startY;
67
+ const itemWidth = Math.floor(diffX / originColWidth.length);
68
+ const itemHeight = Math.floor(diffY / originRowHeight.length);
69
+
70
+ for (const { blot, width } of originColWidth) {
71
+ blot.width = Math.max(width + itemWidth, tableUpSize.colMinWidthPx);
72
+ }
73
+ for (const { blot, height } of originRowHeight) {
74
+ blot.setHeight(`${Math.max(height + itemHeight, tableUpSize.rowMinHeightPx)}px`);
75
+ }
76
+ };
77
+ const handleMouseUp = () => {
78
+ originColWidth = [];
79
+ originRowHeight = [];
80
+ document.removeEventListener('mousemove', handleMouseMove);
81
+ document.removeEventListener('mouseup', handleMouseUp);
82
+ };
83
+ this.block.addEventListener('mousedown', (e) => {
84
+ if (!this.tableMainBlot || this.isTableOutofEditor()) return;
85
+ this.startX = e.clientX;
86
+ this.startY = e.clientY;
87
+ // save the origin width and height to calculate result width and height
88
+ originColWidth = this.tableMainBlot.getCols().map(col => ({ blot: col, width: Math.floor(col.width) }));
89
+ originRowHeight = this.tableMainBlot.getRows().map(row => ({ blot: row, height: Math.floor(row.domNode.getBoundingClientRect().height) }));
90
+ document.addEventListener('mousemove', handleMouseMove);
91
+ document.addEventListener('mouseup', handleMouseUp);
92
+ });
93
+ this.block.addEventListener('dragstart', e => e.preventDefault());
94
+ }
95
+
96
+ isTableOutofEditor(): boolean {
97
+ if (!this.tableMainBlot || !this.tableWrapperBlot || this.tableMainBlot.full) return false;
98
+ // if tableMain width larger than tableWrapper. reset tableMain width equal editor width
99
+ const tableRect = this.tableMainBlot.domNode.getBoundingClientRect();
100
+ const tableWrapperRect = this.tableWrapperBlot.domNode.getBoundingClientRect();
101
+ // equal scale
102
+ if (tableRect.width > tableWrapperRect.width) {
103
+ for (const col of this.tableMainBlot.getCols()) {
104
+ col.width = Math.floor((col.width / tableRect.width) * tableWrapperRect.width);
105
+ }
106
+ this.tableMainBlot.colWidthFillTable();
107
+ return true;
108
+ }
109
+ return false;
110
+ }
111
+
112
+ update() {
113
+ if (!this.block || !this.root || !this.tableMainBlot || !this.tableWrapperBlot) return;
114
+ if (this.tableMainBlot.full) {
115
+ this.hide();
116
+ return;
117
+ }
118
+ const { rect: tableRect } = getTableMainRect(this.tableMainBlot);
119
+ if (!tableRect) return;
120
+ const tableWrapperRect = this.tableWrapperBlot.domNode.getBoundingClientRect();
121
+ const editorRect = this.quill.root.getBoundingClientRect();
122
+ const { scrollTop, scrollLeft } = this.tableWrapperBlot.domNode;
123
+ const blockSize = this.options.blockSize * 2 + this.offset;
124
+ const rootWidth = Math.min(tableRect.width, tableWrapperRect.width) + blockSize;
125
+ const rootHeight = Math.min(tableRect.height, tableWrapperRect.height) + blockSize;
126
+ Object.assign(this.root.style, {
127
+ width: `${rootWidth}px`,
128
+ height: `${rootHeight}px`,
129
+ left: `${Math.max(tableRect.x, tableWrapperRect.x) - editorRect.x - this.options.blockSize}px`,
130
+ top: `${Math.max(tableRect.y, tableWrapperRect.y) - editorRect.y - this.options.blockSize}px`,
131
+ });
132
+ const blockStyle = {
133
+ left: `${tableRect.width + blockSize - scrollLeft}px`,
134
+ top: `${rootHeight - scrollTop}px`,
135
+ };
136
+ if (isTableAlignRight(this.tableMainBlot)) {
137
+ this.root.classList.add(this.bem.is('align-right'));
138
+ blockStyle.left = `${this.options.blockSize + -1 * scrollLeft}px`;
139
+ }
140
+ else {
141
+ this.root.classList.remove(this.bem.is('align-right'));
142
+ }
143
+ Object.assign(this.block.style, blockStyle);
144
+ }
145
+
146
+ show() {
147
+ if (!this.table) return;
148
+ this.tableMainBlot = Quill.find(this.table) as TableMainFormat;
149
+ if (this.tableMainBlot && !this.tableMainBlot.full) {
150
+ this.tableWrapperBlot = this.tableMainBlot.parent as TableWrapperFormat;
151
+
152
+ this.resizeobserver.observe(this.tableMainBlot.domNode);
153
+ addScrollEvent.call(this, this.quill.root, () => this.update());
154
+ }
155
+ this.buildResizer();
156
+ }
157
+
158
+ hide() {
159
+ this.tableMainBlot = undefined;
160
+ this.tableWrapperBlot = undefined;
161
+ if (this.root) {
162
+ this.root.remove();
163
+ this.root = undefined;
164
+ this.block = undefined;
165
+ }
166
+ }
167
+
168
+ destroy() {
169
+ this.hide();
170
+ this.quill.off(Quill.events.TEXT_CHANGE, this.updateWhenTextChange);
171
+ this.resizeobserver.disconnect();
172
+ clearScrollEvent.call(this);
173
+ }
174
+ }
@@ -1,3 +1,84 @@
1
- import type { TableMainFormat } from '../../formats';
2
-
3
- export const isTableAlignRight = (tableMainBlot: TableMainFormat) => !tableMainBlot.full && tableMainBlot.align === 'right';
1
+ import type { TableCellInnerFormat, TableColFormat, TableMainFormat } from '../../formats';
2
+
3
+ export const isTableAlignRight = (tableMainBlot: TableMainFormat) => !tableMainBlot.full && tableMainBlot.align === 'right';
4
+ export function getColRect(cols: TableColFormat[], columnIndex: number) {
5
+ // fix browser compatibility, get column rect left/x inaccurate
6
+ if (columnIndex < 0 || columnIndex >= cols.length) return null;
7
+
8
+ // calculate column position
9
+ let left = cols[0].domNode.getBoundingClientRect().left;
10
+ for (let i = 0; i < columnIndex; i++) {
11
+ const colRect = cols[i].domNode.getBoundingClientRect();
12
+ left += colRect.width;
13
+ }
14
+
15
+ const currentCol = cols[columnIndex];
16
+ const colWidth = currentCol.domNode.getBoundingClientRect().width;
17
+
18
+ return {
19
+ left,
20
+ right: left + colWidth,
21
+ width: colWidth,
22
+ };
23
+ }
24
+
25
+ export function isCellsSpan(isX: boolean, tableBlot: TableMainFormat, cells: TableCellInnerFormat[]) {
26
+ if (isX) {
27
+ // if cells have span all rows
28
+ const cols = tableBlot.getCols();
29
+ const colIds = cols.map(col => col.colId);
30
+ const countColIds = new Set<string>();
31
+ const countRowspan = new Map<string, number>(colIds.map(id => [id, 0]));
32
+ const cellIndex = new Set<number>();
33
+ for (const cell of cells) {
34
+ countColIds.add(cell.colId);
35
+ const colIndex = colIds.indexOf(cell.colId);
36
+ if (colIndex === -1) continue;
37
+ for (let i = colIndex; i < colIndex + cell.colspan && i < colIds.length; i++) {
38
+ cellIndex.add(i);
39
+ const id = colIds[i];
40
+ countRowspan.set(id, (countRowspan.get(id) || 0) + cell.rowspan);
41
+ }
42
+ cellIndex.add(Math.min(colIndex + cell.colspan, colIds.length));
43
+ }
44
+ const rowCount = tableBlot.getRows()?.length || 0;
45
+ for (const [id, count] of countRowspan.entries()) {
46
+ if (count >= rowCount) {
47
+ countColIds.delete(id);
48
+ }
49
+ }
50
+ return {
51
+ cellIndex,
52
+ isSpan: countColIds.size <= 0,
53
+ };
54
+ }
55
+ else {
56
+ // if cells have span all columns
57
+ const rows = tableBlot.getRows();
58
+ const rowIds = rows.map(row => row.rowId);
59
+ const countRowIds = new Set<string>();
60
+ const countRowspan = new Map<string, number>(rowIds.map(id => [id, 0]));
61
+ const cellIndex = new Set<number>();
62
+ for (const cell of cells) {
63
+ countRowIds.add(cell.rowId);
64
+ const rowIndex = rowIds.indexOf(cell.rowId);
65
+ if (rowIndex === -1) continue;
66
+ for (let i = rowIndex; i < rowIndex + cell.rowspan && i < rowIds.length; i++) {
67
+ cellIndex.add(i);
68
+ const id = rowIds[i];
69
+ countRowspan.set(id, (countRowspan.get(id) || 0) + cell.colspan);
70
+ }
71
+ cellIndex.add(Math.min(rowIndex + cell.rowspan, rowIds.length));
72
+ }
73
+ const colCount = tableBlot.getCols()?.length || 0;
74
+ for (const [id, count] of countRowspan.entries()) {
75
+ if (count >= colCount) {
76
+ countRowIds.delete(id);
77
+ }
78
+ }
79
+ return {
80
+ cellIndex,
81
+ isSpan: countRowIds.size <= 0,
82
+ };
83
+ }
84
+ }