quill-table-up 3.2.1 → 3.2.2
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 +16 -3
- package/dist/index.d.ts +30 -33
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +6 -6
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/e2e/table-resize.test.ts +109 -60
- package/src/__tests__/unit/utils.ts +1 -2
- package/src/formats/container-format.ts +2 -2
- package/src/formats/table-body-format.ts +1 -1
- package/src/formats/table-caption-format.ts +1 -1
- package/src/modules/table-clipboard/paste-cell-into-cell.ts +2 -2
- package/src/modules/table-resize/table-resize-line.ts +12 -0
- package/src/modules/table-resize/table-resize-scale.ts +32 -52
- package/src/modules/table-scrollbar.ts +25 -31
- package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/src/style/table-selection.less +0 -5
- package/src/utils/types.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.2.
|
|
4
|
+
"version": "3.2.2",
|
|
5
5
|
"packageManager": "pnpm@10.20.0",
|
|
6
6
|
"description": "A table module for quill2.x",
|
|
7
7
|
"author": "zzxming",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@typescript-eslint/parser": "^8.46.2",
|
|
62
62
|
"@vitest/coverage-v8": "^4.0.6",
|
|
63
63
|
"@vitest/ui": "^4.0.6",
|
|
64
|
-
"@zzxming/eslint-config": "0.6.
|
|
64
|
+
"@zzxming/eslint-config": "0.6.2",
|
|
65
65
|
"autoprefixer": "^10.4.21",
|
|
66
66
|
"eslint": "^9.39.0",
|
|
67
67
|
"gulp": "^5.0.1",
|
|
@@ -169,73 +169,122 @@ extendTest('TableResize on full width should not outer 100%', async ({ page, edi
|
|
|
169
169
|
expect(width).toBeCloseTo(100, 3);
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
extendTest('test TableResizeBox and TableResizeScale should update when text change', async ({ page, editorPage }) => {
|
|
196
|
-
editorPage.index = 1;
|
|
197
|
-
await createTableBySelect(page, 'container2', 3, 3);
|
|
198
|
-
|
|
199
|
-
const lineBound = (await page.locator('#editor2 .ql-editor > p').first().boundingBox())!;
|
|
200
|
-
expect(lineBound).not.toBeNull();
|
|
201
|
-
await page.locator('#editor2 .ql-table .ql-table-cell').nth(0).click();
|
|
202
|
-
const scale = page.locator('#container2 .table-up-scale');
|
|
203
|
-
const boxTop = await page.locator('#container2 .table-up-resize-box').evaluate((element) => {
|
|
204
|
-
return Number.parseFloat(window.getComputedStyle(element).top);
|
|
205
|
-
});
|
|
206
|
-
const scaleTop = await scale.evaluate((element) => {
|
|
207
|
-
return Number.parseFloat(window.getComputedStyle(element).top);
|
|
172
|
+
extendTest.describe('TableResizeScale functional', () => {
|
|
173
|
+
extendTest('test TableResizeScale functional', async ({ page }) => {
|
|
174
|
+
await createTableBySelect(page, 'container1', 3, 3);
|
|
175
|
+
const centerCell = page.locator('#editor1').getByRole('cell').nth(4);
|
|
176
|
+
await centerCell.click();
|
|
177
|
+
const cellBounding = (await centerCell.boundingBox())!;
|
|
178
|
+
const scaleBtnBounding = (await page.locator('#editor1 .table-up-scale__block').boundingBox())!;
|
|
179
|
+
expect(cellBounding).not.toBeNull();
|
|
180
|
+
expect(scaleBtnBounding).not.toBeNull();
|
|
181
|
+
await page.mouse.move(scaleBtnBounding.x + scaleBtnBounding.width / 2, scaleBtnBounding.y + scaleBtnBounding.height / 2);
|
|
182
|
+
await page.mouse.down();
|
|
183
|
+
await page.mouse.move(scaleBtnBounding.x + scaleBtnBounding.width / 2 - 90, scaleBtnBounding.y + scaleBtnBounding.height / 2 + 90);
|
|
184
|
+
await page.mouse.up();
|
|
185
|
+
const cols = page.locator('#editor1 .ql-table-wrapper col');
|
|
186
|
+
for (const col of await cols.all()) {
|
|
187
|
+
await expect(col).toHaveAttribute('width', `${Math.floor(cellBounding.width - 30)}px`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const cells = page.locator('#editor1 .ql-table-wrapper td');
|
|
191
|
+
for (const cell of await cells.all()) {
|
|
192
|
+
await expect(cell).toHaveCSS('height', `${Math.floor(cellBounding.height + 30)}px`);
|
|
193
|
+
}
|
|
208
194
|
});
|
|
209
|
-
await expect(scale).toBeVisible();
|
|
210
|
-
await expect(page.locator('#container2 .table-up-resize-box .table-up-resize-box__corner')).toBeVisible();
|
|
211
195
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
196
|
+
extendTest('test TableResizeBox and TableResizeScale should update when text change', async ({ page, editorPage }) => {
|
|
197
|
+
editorPage.index = 1;
|
|
198
|
+
await createTableBySelect(page, 'container2', 3, 3);
|
|
199
|
+
|
|
200
|
+
const lineBound = (await page.locator('#editor2 .ql-editor > p').first().boundingBox())!;
|
|
201
|
+
expect(lineBound).not.toBeNull();
|
|
202
|
+
await page.locator('#editor2 .ql-table .ql-table-cell').nth(0).click();
|
|
203
|
+
const scale = page.locator('#container2 .table-up-scale');
|
|
204
|
+
const boxTop = await page.locator('#container2 .table-up-resize-box').evaluate((element) => {
|
|
205
|
+
return Number.parseFloat(window.getComputedStyle(element).top);
|
|
206
|
+
});
|
|
207
|
+
const scaleTop = await scale.evaluate((element) => {
|
|
208
|
+
return Number.parseFloat(window.getComputedStyle(element).top);
|
|
209
|
+
});
|
|
210
|
+
await expect(scale).toBeVisible();
|
|
211
|
+
await expect(page.locator('#container2 .table-up-resize-box .table-up-resize-box__corner')).toBeVisible();
|
|
212
|
+
|
|
213
|
+
await editorPage.updateContents([{ insert: '12345\n12345\n12345' }], 'user');
|
|
214
|
+
await page.evaluate(() => {
|
|
215
|
+
window.scrollTo(0, 0);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
await expect(scale).toBeVisible();
|
|
219
|
+
await expect(page.locator('#container2 .table-up-resize-box .table-up-resize-box__corner')).toBeVisible();
|
|
220
|
+
const newScaleTop = await scale.evaluate((element) => {
|
|
221
|
+
return Number.parseFloat(window.getComputedStyle(element).top);
|
|
222
|
+
});
|
|
223
|
+
expect(newScaleTop).toBeCloseTo(scaleTop + lineBound.height * 2, 4);
|
|
224
|
+
const newBoxTop = await page.locator('#container2 .table-up-resize-box').evaluate((element) => {
|
|
225
|
+
return Number.parseFloat(window.getComputedStyle(element).top);
|
|
226
|
+
});
|
|
227
|
+
expect(newBoxTop).toBeCloseTo(boxTop + lineBound.height * 2, 4);
|
|
215
228
|
});
|
|
216
229
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const newScaleTop = await scale.evaluate((element) => {
|
|
220
|
-
return Number.parseFloat(window.getComputedStyle(element).top);
|
|
221
|
-
});
|
|
222
|
-
expect(newScaleTop).toBeCloseTo(scaleTop + lineBound.height * 2, 4);
|
|
223
|
-
const newBoxTop = await page.locator('#container2 .table-up-resize-box').evaluate((element) => {
|
|
224
|
-
return Number.parseFloat(window.getComputedStyle(element).top);
|
|
225
|
-
});
|
|
226
|
-
expect(newBoxTop).toBeCloseTo(boxTop + lineBound.height * 2, 4);
|
|
227
|
-
});
|
|
230
|
+
extendTest('test TableResizeScale should hide when table width switch full', async ({ page }) => {
|
|
231
|
+
await createTableBySelect(page, 'container1', 3, 3);
|
|
228
232
|
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
const cell = page.locator('#editor1 .ql-editor .ql-table td').nth(0);
|
|
234
|
+
await cell.click();
|
|
235
|
+
await expect(page.locator('#container1 .table-up-scale')).toBeVisible();
|
|
236
|
+
|
|
237
|
+
await cell.click({ button: 'right' });
|
|
238
|
+
await page.locator('.table-up-menu.is-contextmenu .table-up-menu__item').filter({ hasText: 'Switch table width' }).first().click();
|
|
239
|
+
await expect(page.locator('#container1 .table-up-scale')).not.toBeVisible();
|
|
240
|
+
});
|
|
231
241
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
242
|
+
extendTest('TableResizeScale block should scroll with table wrapper', async ({ page, editorPage }) => {
|
|
243
|
+
editorPage.index = 0;
|
|
244
|
+
await editorPage.setContents([
|
|
245
|
+
{ insert: '\n' },
|
|
246
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '1', width: 500 } } },
|
|
247
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '2', width: 500 } } },
|
|
248
|
+
{ insert: { 'table-up-col': { tableId: '1', colId: '3', width: 500 } } },
|
|
249
|
+
{ insert: '1' },
|
|
250
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
251
|
+
{ insert: '2' },
|
|
252
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
253
|
+
{ insert: '3' },
|
|
254
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '1', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
255
|
+
{ insert: '4' },
|
|
256
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
257
|
+
{ insert: '5' },
|
|
258
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
259
|
+
{ insert: '6' },
|
|
260
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '2', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
261
|
+
{ insert: '7' },
|
|
262
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '1', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
263
|
+
{ insert: '8' },
|
|
264
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '2', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
265
|
+
{ insert: '9' },
|
|
266
|
+
{ attributes: { 'table-up-cell-inner': { tableId: '1', rowId: '3', colId: '3', rowspan: 1, colspan: 1 } }, insert: '\n' },
|
|
267
|
+
{ insert: '\n' },
|
|
268
|
+
]);
|
|
235
269
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
270
|
+
const cell = page.locator('#container1 .ql-editor .ql-table td').nth(0);
|
|
271
|
+
await cell.click();
|
|
272
|
+
|
|
273
|
+
const scaleWrapper = page.locator('#container1 .table-up-scale');
|
|
274
|
+
const block = page.locator('#container1 .table-up-scale .table-up-scale__block');
|
|
275
|
+
await expect(block).toBeVisible();
|
|
276
|
+
const scaleWrapperBounding = (await scaleWrapper.boundingBox())!;
|
|
277
|
+
const blockBounding = (await block.boundingBox())!;
|
|
278
|
+
expect(scaleWrapperBounding).not.toBeNull();
|
|
279
|
+
expect(blockBounding).not.toBeNull();
|
|
280
|
+
expect(blockBounding.x + blockBounding.width).toBeGreaterThan(scaleWrapperBounding.x + scaleWrapperBounding.width);
|
|
281
|
+
|
|
282
|
+
await page.locator('#editor1 .ql-table-wrapper').evaluate((el) => {
|
|
283
|
+
el.scrollLeft = el.scrollWidth;
|
|
284
|
+
});
|
|
285
|
+
const scrollBlockBounding = (await block.boundingBox())!;
|
|
286
|
+
expect(scrollBlockBounding.x + scrollBlockBounding.width).toBeLessThanOrEqual(scaleWrapperBounding.x + scaleWrapperBounding.width);
|
|
287
|
+
});
|
|
239
288
|
});
|
|
240
289
|
|
|
241
290
|
extendTest('test TableResizeBox head click and shift click (column)', async ({ page }) => {
|
|
@@ -187,8 +187,7 @@ export function createTableDeltaOps(row: number, col: number, colOptions?: ColOp
|
|
|
187
187
|
);
|
|
188
188
|
}
|
|
189
189
|
for (const [i, _] of new Array(col).fill(0).entries()) {
|
|
190
|
-
const value: TableColDeltaValue = { tableId, colId: `${i + 1}`, width: 1 / col * 100 };
|
|
191
|
-
value.full = full;
|
|
190
|
+
const value: TableColDeltaValue = { tableId, colId: `${i + 1}`, width: 1 / col * 100, full };
|
|
192
191
|
if (!full) {
|
|
193
192
|
value.width = width;
|
|
194
193
|
}
|
|
@@ -15,8 +15,8 @@ export class ContainerFormat extends Container {
|
|
|
15
15
|
static requiredContainer: TypeParchment.BlotConstructor;
|
|
16
16
|
static defaultChild?: TypeParchment.BlotConstructor;
|
|
17
17
|
|
|
18
|
-
static allowAttrs = new Set<string>(
|
|
19
|
-
static allowDataAttrs = new Set<string>(
|
|
18
|
+
static allowAttrs = new Set<string>();
|
|
19
|
+
static allowDataAttrs = new Set<string>();
|
|
20
20
|
// handle the attribute change when use `setFormatValue`
|
|
21
21
|
static allowDataAttrsChangeHandler: Record<string, string> = {};
|
|
22
22
|
|
|
@@ -31,7 +31,7 @@ export class TableCaptionFormat extends BlockOverride {
|
|
|
31
31
|
static formats(domNode: HTMLElement) {
|
|
32
32
|
const { tableId } = domNode.dataset;
|
|
33
33
|
const value: TableCaptionValue = {
|
|
34
|
-
tableId:
|
|
34
|
+
tableId: tableId!,
|
|
35
35
|
side: domNode.style.captionSide === 'bottom' ? 'bottom' : 'top',
|
|
36
36
|
};
|
|
37
37
|
return value;
|
|
@@ -137,6 +137,12 @@ export class TableResizeLine extends TableResizeCommon {
|
|
|
137
137
|
},
|
|
138
138
|
onEnd: ({ position }) => {
|
|
139
139
|
this.dragging = false;
|
|
140
|
+
// update the resizer position to the final position
|
|
141
|
+
if (this.colResizer) {
|
|
142
|
+
const resultX = this.dragXCommon.limitRange(this.tableBlot, position.x, true);
|
|
143
|
+
const rootRect = this.quill.root.getBoundingClientRect();
|
|
144
|
+
this.colResizer.style.left = `${resultX - rootRect.x}px`;
|
|
145
|
+
}
|
|
140
146
|
|
|
141
147
|
this.updateTableCol(position.x);
|
|
142
148
|
this.removeBreak();
|
|
@@ -198,6 +204,12 @@ export class TableResizeLine extends TableResizeCommon {
|
|
|
198
204
|
},
|
|
199
205
|
onEnd: ({ position }) => {
|
|
200
206
|
this.dragging = false;
|
|
207
|
+
// update the resizer position to the final position
|
|
208
|
+
if (this.rowResizer) {
|
|
209
|
+
const resultY = this.dragYCommon.limitRange(this.tableBlot, position.y, true);
|
|
210
|
+
const rootRect = this.quill.root.getBoundingClientRect();
|
|
211
|
+
this.rowResizer.style.left = `${resultY - rootRect.y}px`;
|
|
212
|
+
}
|
|
201
213
|
|
|
202
214
|
this.updateTableRow(position.y);
|
|
203
215
|
this.removeBreak();
|
|
@@ -3,7 +3,7 @@ import type { TableUp } from '../../table-up';
|
|
|
3
3
|
import type { TableResizeScaleOptions } from '../../utils';
|
|
4
4
|
import Quill from 'quill';
|
|
5
5
|
import { getTableMainRect } from '../../formats';
|
|
6
|
-
import { addScrollEvent, clearScrollEvent, createBEM, tableUpSize } from '../../utils';
|
|
6
|
+
import { addScrollEvent, clearScrollEvent, createBEM, dragElement, tableUpSize } from '../../utils';
|
|
7
7
|
import { TableDomSelector } from '../table-dom-selector';
|
|
8
8
|
import { isTableAlignRight } from './utils';
|
|
9
9
|
|
|
@@ -14,9 +14,6 @@ export class TableResizeScale extends TableDomSelector {
|
|
|
14
14
|
tableMainBlot?: TableMainFormat;
|
|
15
15
|
tableWrapperBlot?: TableWrapperFormat;
|
|
16
16
|
bem = createBEM('scale');
|
|
17
|
-
startX: number = 0;
|
|
18
|
-
startY: number = 0;
|
|
19
|
-
offset: number = 6;
|
|
20
17
|
options: TableResizeScaleOptions;
|
|
21
18
|
root?: HTMLElement;
|
|
22
19
|
block?: HTMLElement;
|
|
@@ -42,6 +39,7 @@ export class TableResizeScale extends TableDomSelector {
|
|
|
42
39
|
resolveOptions(options: Partial<TableResizeScaleOptions>) {
|
|
43
40
|
return Object.assign({
|
|
44
41
|
blockSize: 12,
|
|
42
|
+
offset: 6,
|
|
45
43
|
}, options);
|
|
46
44
|
}
|
|
47
45
|
|
|
@@ -58,57 +56,38 @@ export class TableResizeScale extends TableDomSelector {
|
|
|
58
56
|
|
|
59
57
|
let originColWidth: { blot: TableColFormat; width: number }[] = [];
|
|
60
58
|
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
59
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
60
|
+
dragElement(this.block, {
|
|
61
|
+
onStart: () => {
|
|
62
|
+
if (!this.tableMainBlot) return;
|
|
63
|
+
// save the origin width and height to calculate result width and height
|
|
64
|
+
originColWidth = this.tableMainBlot.getCols().map(col => ({ blot: col, width: Math.floor(col.width) }));
|
|
65
|
+
originRowHeight = this.tableMainBlot.getRows().map(row => ({ blot: row, height: Math.floor(row.domNode.getBoundingClientRect().height) }));
|
|
66
|
+
},
|
|
67
|
+
onMove: ({ movePosition }) => {
|
|
68
|
+
if (!this.tableMainBlot) return;
|
|
69
|
+
// divide equally by col count/row count
|
|
70
|
+
const isRight = isTableAlignRight(this.tableMainBlot) ? -1 : 1;
|
|
71
|
+
const diffX = movePosition.x * isRight;
|
|
72
|
+
const diffY = movePosition.y;
|
|
73
|
+
const itemWidth = Math.floor(diffX / originColWidth.length);
|
|
74
|
+
const itemHeight = Math.floor(diffY / originRowHeight.length);
|
|
75
|
+
|
|
76
|
+
for (const { blot, width } of originColWidth) {
|
|
77
|
+
blot.width = Math.max(width + itemWidth, tableUpSize.colMinWidthPx);
|
|
78
|
+
}
|
|
79
|
+
for (const { blot, height } of originRowHeight) {
|
|
80
|
+
blot.setHeight(`${Math.max(height + itemHeight, tableUpSize.rowMinHeightPx)}px`);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
onEnd: () => {
|
|
84
|
+
originColWidth = [];
|
|
85
|
+
originRowHeight = [];
|
|
86
|
+
},
|
|
92
87
|
});
|
|
93
88
|
this.block.addEventListener('dragstart', e => e.preventDefault());
|
|
94
89
|
}
|
|
95
90
|
|
|
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
91
|
update() {
|
|
113
92
|
if (!this.block || !this.root || !this.tableMainBlot || !this.tableWrapperBlot) return;
|
|
114
93
|
if (this.tableMainBlot.full) {
|
|
@@ -120,7 +99,7 @@ export class TableResizeScale extends TableDomSelector {
|
|
|
120
99
|
const tableWrapperRect = this.tableWrapperBlot.domNode.getBoundingClientRect();
|
|
121
100
|
const editorRect = this.quill.root.getBoundingClientRect();
|
|
122
101
|
const { scrollTop, scrollLeft } = this.tableWrapperBlot.domNode;
|
|
123
|
-
const blockSize = this.options.blockSize * 2 + this.offset;
|
|
102
|
+
const blockSize = this.options.blockSize * 2 + this.options.offset;
|
|
124
103
|
const rootWidth = Math.min(tableRect.width, tableWrapperRect.width) + blockSize;
|
|
125
104
|
const rootHeight = Math.min(tableRect.height, tableWrapperRect.height) + blockSize;
|
|
126
105
|
Object.assign(this.root.style, {
|
|
@@ -151,6 +130,7 @@ export class TableResizeScale extends TableDomSelector {
|
|
|
151
130
|
|
|
152
131
|
this.resizeobserver.observe(this.tableMainBlot.domNode);
|
|
153
132
|
addScrollEvent.call(this, this.quill.root, () => this.update());
|
|
133
|
+
addScrollEvent.call(this, this.tableWrapperBlot.domNode, () => this.update());
|
|
154
134
|
}
|
|
155
135
|
this.buildResizer();
|
|
156
136
|
}
|
|
@@ -163,12 +143,12 @@ export class TableResizeScale extends TableDomSelector {
|
|
|
163
143
|
this.root = undefined;
|
|
164
144
|
this.block = undefined;
|
|
165
145
|
}
|
|
146
|
+
clearScrollEvent.call(this);
|
|
166
147
|
}
|
|
167
148
|
|
|
168
149
|
destroy() {
|
|
169
150
|
this.hide();
|
|
170
151
|
this.quill.off(Quill.events.TEXT_CHANGE, this.updateWhenTextChange);
|
|
171
152
|
this.resizeobserver.disconnect();
|
|
172
|
-
clearScrollEvent.call(this);
|
|
173
153
|
}
|
|
174
154
|
}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import type { TableMainFormat } from '../formats';
|
|
2
2
|
import type { TableUp } from '../table-up';
|
|
3
|
+
import type { Position } from '../utils';
|
|
3
4
|
import Quill from 'quill';
|
|
4
5
|
import { getTableMainRect } from '../formats';
|
|
5
6
|
import { addScrollEvent, clearScrollEvent, createBEM, debounce } from '../utils';
|
|
6
7
|
import { TableDomSelector } from './table-dom-selector';
|
|
7
8
|
|
|
9
|
+
const propertyMapY = {
|
|
10
|
+
size: 'height',
|
|
11
|
+
offset: 'offsetHeight',
|
|
12
|
+
scrollDirection: 'scrollTop',
|
|
13
|
+
scrollSize: 'scrollHeight',
|
|
14
|
+
axis: 'y',
|
|
15
|
+
direction: 'top',
|
|
16
|
+
client: 'clientY',
|
|
17
|
+
} as const;
|
|
18
|
+
const propertyMapX = {
|
|
19
|
+
size: 'width',
|
|
20
|
+
offset: 'offsetWidth',
|
|
21
|
+
scrollDirection: 'scrollLeft',
|
|
22
|
+
scrollSize: 'scrollWidth',
|
|
23
|
+
axis: 'x',
|
|
24
|
+
direction: 'left',
|
|
25
|
+
client: 'clientX',
|
|
26
|
+
} as const;
|
|
8
27
|
export class Scrollbar {
|
|
9
28
|
minSize: number = 20;
|
|
10
29
|
gap: number = 4;
|
|
@@ -16,22 +35,15 @@ export class Scrollbar {
|
|
|
16
35
|
sizeWidth: string = '';
|
|
17
36
|
sizeHeight: string = '';
|
|
18
37
|
size: string = '';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Y: number;
|
|
22
|
-
} = {
|
|
23
|
-
X: 0,
|
|
24
|
-
Y: 0,
|
|
25
|
-
};
|
|
26
|
-
|
|
38
|
+
bem = createBEM('scrollbar');
|
|
39
|
+
tableMainBlot: TableMainFormat;
|
|
27
40
|
ob: ResizeObserver;
|
|
28
41
|
container: HTMLElement;
|
|
29
42
|
scrollbar: HTMLElement;
|
|
30
43
|
thumb: HTMLElement = document.createElement('div');
|
|
31
44
|
scrollHandler: [HTMLElement, (e: Event) => void][] = [];
|
|
32
|
-
propertyMap:
|
|
33
|
-
|
|
34
|
-
tableMainBlot: TableMainFormat;
|
|
45
|
+
propertyMap: typeof propertyMapY | typeof propertyMapX;
|
|
46
|
+
thumbState: Position = { x: 0, y: 0 };
|
|
35
47
|
|
|
36
48
|
get isVertical() {
|
|
37
49
|
return this.options.isVertical;
|
|
@@ -40,25 +52,7 @@ export class Scrollbar {
|
|
|
40
52
|
constructor(public quill: Quill, public table: HTMLElement, public options: { isVertical: boolean }) {
|
|
41
53
|
this.tableMainBlot = Quill.find(this.table) as TableMainFormat;
|
|
42
54
|
this.container = table.parentElement!;
|
|
43
|
-
this.propertyMap = this.isVertical
|
|
44
|
-
? {
|
|
45
|
-
size: 'height',
|
|
46
|
-
offset: 'offsetHeight',
|
|
47
|
-
scrollDirection: 'scrollTop',
|
|
48
|
-
scrollSize: 'scrollHeight',
|
|
49
|
-
axis: 'Y',
|
|
50
|
-
direction: 'top',
|
|
51
|
-
client: 'clientY',
|
|
52
|
-
} as const
|
|
53
|
-
: {
|
|
54
|
-
size: 'width',
|
|
55
|
-
offset: 'offsetWidth',
|
|
56
|
-
scrollDirection: 'scrollLeft',
|
|
57
|
-
scrollSize: 'scrollWidth',
|
|
58
|
-
axis: 'X',
|
|
59
|
-
direction: 'left',
|
|
60
|
-
client: 'clientX',
|
|
61
|
-
} as const;
|
|
55
|
+
this.propertyMap = this.isVertical ? propertyMapY : propertyMapX;
|
|
62
56
|
this.calculateSize();
|
|
63
57
|
this.ob = new ResizeObserver(() => this.update());
|
|
64
58
|
this.ob.observe(table);
|
|
@@ -189,7 +183,7 @@ export class Scrollbar {
|
|
|
189
183
|
this.move = wrap[this.propertyMap.scrollDirection] * 100 / offset * (this.isVertical ? this.ratioY : this.ratioX);
|
|
190
184
|
Object.assign(this.thumb.style, {
|
|
191
185
|
[this.propertyMap.size]: this.size,
|
|
192
|
-
transform: `translate${this.propertyMap.axis}(${this.move}%)`,
|
|
186
|
+
transform: `translate${this.propertyMap.axis.toUpperCase()}(${this.move}%)`,
|
|
193
187
|
});
|
|
194
188
|
}
|
|
195
189
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"3.2.3","results":[[":__tests__/unit/utils.test-d.ts",{"duration":0,"failed":false}],[":__tests__/unit/table-clipboard.test.ts",{"duration":5764.352499999999,"failed":true}],[":__tests__/unit/table-redo-undo.test.ts",{"duration":7413.697700000001,"failed":true}],[":__tests__/unit/table-hack.test.ts",{"duration":2512.8070000000002,"failed":false}],[":__tests__/unit/table-cell-merge.test.ts",{"duration":3206.3629,"failed":false}],[":__tests__/unit/table-insert.test.ts",{"duration":4597.281199999999,"failed":true}],[":__tests__/unit/table-blots.test.ts",{"duration":2687.4262,"failed":true}],[":__tests__/unit/utils.test.ts",{"duration":732.1670999999997,"failed":false}],[":__tests__/unit/table-caption.test.ts",{"duration":
|
|
1
|
+
{"version":"3.2.3","results":[[":__tests__/unit/utils.test-d.ts",{"duration":0,"failed":false}],[":__tests__/unit/table-clipboard.test.ts",{"duration":5764.352499999999,"failed":true}],[":__tests__/unit/table-redo-undo.test.ts",{"duration":7413.697700000001,"failed":true}],[":__tests__/unit/table-hack.test.ts",{"duration":2512.8070000000002,"failed":false}],[":__tests__/unit/table-cell-merge.test.ts",{"duration":3206.3629,"failed":false}],[":__tests__/unit/table-insert.test.ts",{"duration":4597.281199999999,"failed":true}],[":__tests__/unit/table-blots.test.ts",{"duration":2687.4262,"failed":true}],[":__tests__/unit/utils.test.ts",{"duration":732.1670999999997,"failed":false}],[":__tests__/unit/table-caption.test.ts",{"duration":0,"failed":true}],[":__tests__/unit/table-remove.test.ts",{"duration":2594.6331,"failed":true}]]}
|