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.
- package/README.md +7 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +168 -146
- package/dist/index.js +47 -47
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +52 -52
- package/dist/index.umd.js.map +1 -1
- package/package.json +22 -24
- package/src/__tests__/e2e/custom-creator.test.ts +44 -44
- package/src/__tests__/e2e/editor-page.ts +77 -77
- package/src/__tests__/e2e/table-align.test.ts +104 -104
- package/src/__tests__/e2e/table-blots.test.ts +169 -169
- package/src/__tests__/e2e/table-caption.test.ts +134 -134
- package/src/__tests__/e2e/table-clipboard.test.ts +20 -20
- package/src/__tests__/e2e/table-hack.test.ts +151 -151
- package/src/__tests__/e2e/table-keyboard-handler.test.ts +12 -3
- package/src/__tests__/e2e/table-menu.test.ts +172 -172
- package/src/__tests__/e2e/table-resize.test.ts +654 -9
- package/src/__tests__/e2e/table-scrollbar.test.ts +144 -144
- package/src/__tests__/e2e/table-selection.test.ts +563 -563
- package/src/__tests__/e2e/types.d.ts +7 -7
- package/src/__tests__/e2e/utils.ts +52 -52
- package/src/__tests__/unit/table-blots.test.ts +720 -720
- package/src/__tests__/unit/table-caption.test.ts +234 -234
- package/src/__tests__/unit/table-cell-merge.test.ts +724 -724
- package/src/__tests__/unit/table-clipboard.test.ts +2176 -2176
- package/src/__tests__/unit/table-hack.test.ts +1014 -1014
- package/src/__tests__/unit/table-insert.test.ts +926 -926
- package/src/__tests__/unit/table-redo-undo.test.ts +2429 -2429
- package/src/__tests__/unit/table-remove.test.ts +343 -343
- package/src/__tests__/unit/utils.test-d.ts +49 -49
- package/src/__tests__/unit/utils.test.ts +711 -711
- package/src/__tests__/unit/utils.ts +307 -307
- package/src/__tests__/unit/vitest.d.ts +14 -14
- package/src/formats/container-format.ts +107 -107
- package/src/formats/overrides/block-embed.ts +72 -72
- package/src/formats/overrides/block.ts +95 -95
- package/src/formats/overrides/index.ts +3 -3
- package/src/formats/overrides/scroll.ts +70 -70
- package/src/formats/table-body-format.ts +52 -52
- package/src/formats/table-caption-format.ts +116 -116
- package/src/formats/table-cell-format.ts +304 -304
- package/src/formats/table-cell-inner-format.ts +403 -398
- package/src/formats/table-colgroup-format.ts +136 -136
- package/src/formats/table-foot-format.ts +7 -7
- package/src/formats/table-head-format.ts +7 -7
- package/src/formats/table-main-format.ts +1 -1
- package/src/formats/table-row-format.ts +218 -210
- package/src/formats/utils.ts +6 -6
- package/src/index.ts +19 -19
- package/src/modules/index.ts +7 -7
- package/src/modules/table-align.ts +131 -131
- package/src/modules/table-clipboard/table-clipboard.ts +6 -8
- package/src/modules/table-dom-selector.ts +33 -33
- package/src/modules/table-menu/constants.ts +223 -223
- package/src/modules/table-menu/index.ts +4 -4
- package/src/modules/table-menu/table-menu-common.ts +330 -329
- package/src/modules/table-menu/table-menu-contextmenu.ts +111 -118
- package/src/modules/table-menu/table-menu-select.ts +96 -94
- package/src/modules/table-resize/index.ts +5 -5
- package/src/modules/table-resize/table-resize-box.ts +714 -363
- package/src/modules/table-resize/table-resize-common.ts +246 -382
- package/src/modules/table-resize/table-resize-drag.ts +241 -0
- package/src/modules/table-resize/table-resize-line.ts +244 -182
- package/src/modules/table-resize/table-resize-scale.ts +174 -173
- package/src/modules/table-resize/utils.ts +84 -3
- package/src/modules/table-scrollbar.ts +292 -292
- package/src/modules/table-selection.ts +613 -669
- package/src/style/button.less +45 -45
- package/src/style/color-picker.less +136 -136
- package/src/style/dialog.less +53 -53
- package/src/style/functions.less +9 -9
- package/src/style/index.less +120 -120
- package/src/style/input.less +64 -64
- package/src/style/select-box.less +52 -52
- package/src/style/table-creator.less +56 -56
- package/src/style/table-menu.less +125 -125
- package/src/style/table-resize-scale.less +31 -31
- package/src/style/table-resize.less +249 -202
- package/src/style/table-scrollbar.less +49 -49
- package/src/style/table-selection.less +23 -23
- package/src/style/tooltip.less +19 -19
- package/src/style/variables.less +1 -1
- package/src/svg/arrow-up-down.svg +11 -11
- package/src/svg/convert-cell.svg +7 -7
- package/src/table-up.ts +1360 -1360
- package/src/types.d.ts +4 -4
- package/src/utils/bem.ts +23 -23
- package/src/utils/blot-helper.ts +101 -105
- package/src/utils/color.ts +109 -109
- package/src/utils/components/button.ts +22 -22
- package/src/utils/components/color-picker.ts +236 -236
- package/src/utils/components/dialog.ts +83 -41
- package/src/utils/components/index.ts +6 -6
- package/src/utils/components/input.ts +74 -74
- package/src/utils/components/table/creator.ts +89 -89
- package/src/utils/components/table/index.ts +2 -2
- package/src/utils/components/table/select-box.ts +78 -78
- package/src/utils/components/tooltip.ts +179 -189
- package/src/utils/constants.ts +125 -124
- package/src/utils/drag-helper.ts +112 -0
- package/src/utils/index.ts +15 -14
- package/src/utils/is.ts +9 -9
- package/src/utils/position.ts +60 -60
- package/src/utils/resize-observer-helper.ts +47 -47
- package/src/utils/scroll.ts +145 -47
- package/src/utils/style-helper.ts +47 -47
- package/src/utils/transformer.ts +10 -10
- package/src/utils/transition-event-helper.ts +8 -8
- package/src/utils/types.ts +156 -157
- 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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.root
|
|
163
|
-
this.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.
|
|
170
|
-
this.
|
|
171
|
-
|
|
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
|
+
}
|