quill-table-up 3.1.2 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +15 -8
  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 +20 -4
  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 +8 -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 +713 -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 +915 -926
  29. package/src/__tests__/unit/table-redo-undo.test.ts +2429 -2429
  30. package/src/__tests__/unit/table-remove.test.ts +313 -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 +1363 -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
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "quill-table-up",
3
3
  "type": "module",
4
- "version": "3.1.2",
5
- "packageManager": "pnpm@10.17.1",
4
+ "version": "3.2.1",
5
+ "packageManager": "pnpm@10.20.0",
6
6
  "description": "A table module for quill2.x",
7
7
  "author": "zzxming",
8
8
  "license": "MIT",
@@ -30,15 +30,12 @@
30
30
  "src"
31
31
  ],
32
32
  "scripts": {
33
- "lint": "eslint . --cache",
34
- "lint:fix": "eslint . --fix",
33
+ "lint": "eslint",
35
34
  "build": "tsx ./scripts/build.ts",
36
35
  "dev": "tsx ./scripts/build.ts watch",
37
36
  "server": "tsx ./scripts/start-server.ts",
38
37
  "test:unit": "vitest",
39
- "test:unit-ui": "vitest --ui",
40
- "test:e2e": "playwright test",
41
- "test:e2e-ui": "playwright test --ui"
38
+ "test:e2e": "playwright test"
42
39
  },
43
40
  "peerDependencies": {
44
41
  "quill": "^2.0.3"
@@ -47,38 +44,39 @@
47
44
  "@floating-ui/dom": "^1.7.4"
48
45
  },
49
46
  "devDependencies": {
50
- "@babel/preset-env": "^7.28.3",
51
- "@oxc-project/runtime": "^0.92.0",
52
- "@playwright/test": "^1.55.1",
47
+ "@babel/preset-env": "^7.28.5",
48
+ "@oxc-project/runtime": "^0.96.0",
49
+ "@playwright/test": "^1.56.1",
53
50
  "@prettier/plugin-xml": "^3.4.2",
54
- "@rollup/plugin-babel": "^6.0.4",
55
- "@rollup/plugin-typescript": "^12.1.4",
56
- "@types/gulp": "^4.0.17",
51
+ "@rollup/plugin-babel": "^6.1.0",
52
+ "@rollup/plugin-typescript": "^12.3.0",
53
+ "@types/gulp": "^4.0.18",
57
54
  "@types/gulp-clean-css": "^4.3.4",
58
55
  "@types/gulp-less": "^0.0.36",
59
56
  "@types/gulp-postcss": "^8.0.6",
60
- "@types/node": "^24.5.2",
57
+ "@types/node": "^24.9.2",
61
58
  "@types/postcss-pxtorem": "^6.1.0",
62
- "@typescript-eslint/eslint-plugin": "^8.44.1",
63
- "@typescript-eslint/parser": "^8.44.1",
64
- "@vitest/coverage-v8": "^3.2.4",
65
- "@vitest/ui": "^3.2.4",
66
- "@zzxming/eslint-config": "0.5.8",
59
+ "@types/ws": "^8.18.1",
60
+ "@typescript-eslint/eslint-plugin": "^8.46.2",
61
+ "@typescript-eslint/parser": "^8.46.2",
62
+ "@vitest/coverage-v8": "^4.0.6",
63
+ "@vitest/ui": "^4.0.6",
64
+ "@zzxming/eslint-config": "0.6.0",
67
65
  "autoprefixer": "^10.4.21",
68
- "eslint": "^9.36.0",
66
+ "eslint": "^9.39.0",
69
67
  "gulp": "^5.0.1",
70
68
  "gulp-clean-css": "^4.3.0",
71
69
  "gulp-less": "^5.0.0",
72
70
  "gulp-postcss": "^10.0.0",
73
- "jsdom": "^27.0.0",
71
+ "jsdom": "^27.1.0",
74
72
  "parchment": "^3.0.0",
75
73
  "postcss-pxtorem": "^6.1.0",
76
74
  "resize-observer-polyfill": "^1.5.1",
77
- "tsdown": "^0.15.5",
75
+ "tsdown": "^0.15.12",
78
76
  "tslib": "^2.8.1",
79
77
  "tsx": "^4.20.6",
80
- "typescript": "~5.9.2",
81
- "vitest": "^3.2.4",
78
+ "typescript": "~5.9.3",
79
+ "vitest": "^4.0.6",
82
80
  "ws": "^8.18.3"
83
81
  }
84
82
  }
@@ -1,44 +1,44 @@
1
- import { expect, test } from '@playwright/test';
2
- import { createTableBySelect } from './utils';
3
-
4
- test.beforeEach(async ({ page }) => {
5
- await page.goto('http://127.0.0.1:5500/docs/test.html');
6
- page.locator('#editor1.ql-container.ql-snow');
7
- });
8
-
9
- test('custom selecor should work', async ({ page }) => {
10
- await createTableBySelect(page, 'container1', 3, 3);
11
-
12
- const isVisible = await page.locator('#editor1.ql-container .ql-table-wrapper').isVisible();
13
- expect(isVisible).toBe(true);
14
- const colCount = await page.locator('#editor1.ql-container .ql-table-wrapper col').count();
15
- expect(colCount).toBe(3);
16
- const rowCount = await page.locator('#editor1.ql-container .ql-table-wrapper tr').count();
17
- expect(rowCount).toBe(3);
18
- const cellCount = await page.locator('#editor1.ql-container .ql-table-wrapper td').count();
19
- expect(cellCount).toBe(9);
20
- });
21
-
22
- test('custom button should work', async ({ page }) => {
23
- await page.locator('#container1 .ql-toolbar .ql-table-up > .ql-picker-label').first().click();
24
- await page.locator('#container1 .ql-toolbar .ql-table-up .ql-custom-select').getByText('Custom').click();
25
-
26
- await page.locator('.table-up-dialog .table-up-button.confirm').click();
27
- const rowInput = page.locator('.table-up-dialog .table-up-input__input').first();
28
- expect(rowInput).toHaveClass(/error/);
29
- const errorText = await page.locator('.table-up-dialog .table-up-input__input').first().locator('.table-up-input__error-tip').textContent();
30
- expect(errorText).toBe('Please enter a positive integer');
31
-
32
- await page.locator('.table-up-input__item').nth(0).locator('input').fill('3');
33
- await page.locator('.table-up-input__item').nth(1).locator('input').fill('3');
34
- await page.getByRole('button', { name: 'Confirm' }).click();
35
-
36
- const isVisible = await page.locator('#editor1.ql-container .ql-table-wrapper').isVisible();
37
- expect(isVisible).toBe(true);
38
- const colCount = await page.locator('#editor1.ql-container .ql-table-wrapper col').count();
39
- expect(colCount).toBe(3);
40
- const rowCount = await page.locator('#editor1.ql-container .ql-table-wrapper tr').count();
41
- expect(rowCount).toBe(3);
42
- const cellCount = await page.locator('#editor1.ql-container .ql-table-wrapper td').count();
43
- expect(cellCount).toBe(9);
44
- });
1
+ import { expect, test } from '@playwright/test';
2
+ import { createTableBySelect } from './utils';
3
+
4
+ test.beforeEach(async ({ page }) => {
5
+ await page.goto('http://127.0.0.1:5500/docs/test.html');
6
+ page.locator('#editor1.ql-container.ql-snow');
7
+ });
8
+
9
+ test('custom selecor should work', async ({ page }) => {
10
+ await createTableBySelect(page, 'container1', 3, 3);
11
+
12
+ const isVisible = await page.locator('#editor1.ql-container .ql-table-wrapper').isVisible();
13
+ expect(isVisible).toBe(true);
14
+ const colCount = await page.locator('#editor1.ql-container .ql-table-wrapper col').count();
15
+ expect(colCount).toBe(3);
16
+ const rowCount = await page.locator('#editor1.ql-container .ql-table-wrapper tr').count();
17
+ expect(rowCount).toBe(3);
18
+ const cellCount = await page.locator('#editor1.ql-container .ql-table-wrapper td').count();
19
+ expect(cellCount).toBe(9);
20
+ });
21
+
22
+ test('custom button should work', async ({ page }) => {
23
+ await page.locator('#container1 .ql-toolbar .ql-table-up > .ql-picker-label').first().click();
24
+ await page.locator('#container1 .ql-toolbar .ql-table-up .ql-custom-select').getByText('Custom').click();
25
+
26
+ await page.locator('.table-up-dialog .table-up-button.confirm').click();
27
+ const rowInput = page.locator('.table-up-dialog .table-up-input__input').first();
28
+ expect(rowInput).toHaveClass(/error/);
29
+ const errorText = await page.locator('.table-up-dialog .table-up-input__input').first().locator('.table-up-input__error-tip').textContent();
30
+ expect(errorText).toBe('Please enter a positive integer');
31
+
32
+ await page.locator('.table-up-input__item').nth(0).locator('input').fill('3');
33
+ await page.locator('.table-up-input__item').nth(1).locator('input').fill('3');
34
+ await page.getByRole('button', { name: 'Confirm' }).click();
35
+
36
+ const isVisible = await page.locator('#editor1.ql-container .ql-table-wrapper').isVisible();
37
+ expect(isVisible).toBe(true);
38
+ const colCount = await page.locator('#editor1.ql-container .ql-table-wrapper col').count();
39
+ expect(colCount).toBe(3);
40
+ const rowCount = await page.locator('#editor1.ql-container .ql-table-wrapper tr').count();
41
+ expect(rowCount).toBe(3);
42
+ const cellCount = await page.locator('#editor1.ql-container .ql-table-wrapper td').count();
43
+ expect(cellCount).toBe(9);
44
+ });
@@ -1,77 +1,77 @@
1
- import type { Page } from '@playwright/test';
2
- import type { Delta, Op } from 'quill';
3
-
4
- // Specify the index of the editor before use.
5
- export class EditorPage {
6
- public index: number = 0;
7
- constructor(public page: Page) {}
8
-
9
- get root() {
10
- return this.page.locator('.ql-editor');
11
- }
12
-
13
- async html(content: string) {
14
- await this.page.evaluate(({ index, content: html }) => {
15
- const contents = window.quills[index].clipboard.convert({ html, text: '\n' });
16
- return window.quills[index].setContents(contents);
17
- }, { index: this.index, content });
18
- }
19
-
20
- getSelection() {
21
- return this.page.evaluate(({ index }) => {
22
- return window.quills[index].getSelection();
23
- }, { index: this.index });
24
- }
25
-
26
- async setSelection(index: null): Promise<void>;
27
- async setSelection(index: number, length: number): Promise<void>;
28
- async setSelection(range: { index: number; length: number }): Promise<void>;
29
- async setSelection(
30
- range: { index: number; length: number } | number | null,
31
- length?: number,
32
- ) {
33
- await this.page.evaluate(
34
- ({ index, range }) => window.quills[index].setSelection(range),
35
- { index: this.index, range: typeof range === 'number' ? { index: range, length: length || 0 } : range },
36
- );
37
- }
38
-
39
- async updateContents(delta: Op[], source: 'api' | 'user' = 'api') {
40
- await this.page.evaluate(
41
- ({ index, delta, source }) => {
42
- window.quills[index].updateContents(delta, source);
43
- },
44
- { index: this.index, delta, source },
45
- );
46
- }
47
-
48
- async setContents(delta: Op[]) {
49
- await this.page.evaluate(({ index, delta }) => {
50
- window.quills[index].setContents(delta);
51
- }, { index: this.index, delta });
52
- }
53
-
54
- getContents(): Promise<Delta> {
55
- return this.page.evaluate(({ index }) => {
56
- return window.quills[index].getContents();
57
- }, { index: this.index });
58
- }
59
-
60
- focus(): Promise<void> {
61
- return this.page.evaluate(({ index }) => {
62
- return window.quills[index].focus();
63
- }, { index: this.index });
64
- }
65
-
66
- blur(): Promise<void> {
67
- return this.page.evaluate(({ index }) => {
68
- return window.quills[index].blur();
69
- }, { index: this.index });
70
- }
71
-
72
- enable(enabled: boolean) {
73
- return this.page.evaluate(({ index, enabled }) => {
74
- return window.quills[index].enable(enabled);
75
- }, { index: this.index, enabled });
76
- }
77
- }
1
+ import type { Page } from '@playwright/test';
2
+ import type { Delta, Op } from 'quill';
3
+
4
+ // Specify the index of the editor before use.
5
+ export class EditorPage {
6
+ public index: number = 0;
7
+ constructor(public page: Page) {}
8
+
9
+ get root() {
10
+ return this.page.locator('.ql-editor');
11
+ }
12
+
13
+ async html(content: string) {
14
+ await this.page.evaluate(({ index, content: html }) => {
15
+ const contents = window.quills[index].clipboard.convert({ html, text: '\n' });
16
+ return window.quills[index].setContents(contents);
17
+ }, { index: this.index, content });
18
+ }
19
+
20
+ getSelection() {
21
+ return this.page.evaluate(({ index }) => {
22
+ return window.quills[index].getSelection();
23
+ }, { index: this.index });
24
+ }
25
+
26
+ async setSelection(index: null): Promise<void>;
27
+ async setSelection(index: number, length: number): Promise<void>;
28
+ async setSelection(range: { index: number; length: number }): Promise<void>;
29
+ async setSelection(
30
+ range: { index: number; length: number } | number | null,
31
+ length?: number,
32
+ ) {
33
+ await this.page.evaluate(
34
+ ({ index, range }) => window.quills[index].setSelection(range),
35
+ { index: this.index, range: typeof range === 'number' ? { index: range, length: length || 0 } : range },
36
+ );
37
+ }
38
+
39
+ async updateContents(delta: Op[], source: 'api' | 'user' = 'api') {
40
+ await this.page.evaluate(
41
+ ({ index, delta, source }) => {
42
+ window.quills[index].updateContents(delta, source);
43
+ },
44
+ { index: this.index, delta, source },
45
+ );
46
+ }
47
+
48
+ async setContents(delta: Op[]) {
49
+ await this.page.evaluate(({ index, delta }) => {
50
+ window.quills[index].setContents(delta);
51
+ }, { index: this.index, delta });
52
+ }
53
+
54
+ getContents(): Promise<Delta> {
55
+ return this.page.evaluate(({ index }) => {
56
+ return window.quills[index].getContents();
57
+ }, { index: this.index });
58
+ }
59
+
60
+ focus(): Promise<void> {
61
+ return this.page.evaluate(({ index }) => {
62
+ return window.quills[index].focus();
63
+ }, { index: this.index });
64
+ }
65
+
66
+ blur(): Promise<void> {
67
+ return this.page.evaluate(({ index }) => {
68
+ return window.quills[index].blur();
69
+ }, { index: this.index });
70
+ }
71
+
72
+ enable(enabled: boolean) {
73
+ return this.page.evaluate(({ index, enabled }) => {
74
+ return window.quills[index].enable(enabled);
75
+ }, { index: this.index, enabled });
76
+ }
77
+ }
@@ -1,104 +1,104 @@
1
- import { expect, test } from '@playwright/test';
2
- import { createTableBySelect, extendTest } from './utils';
3
-
4
- test.beforeEach(async ({ page }) => {
5
- await page.goto('http://127.0.0.1:5500/docs/test.html');
6
- page.locator('.ql-container.ql-snow');
7
- });
8
-
9
- extendTest('test TableAlign should functional', async ({ page }) => {
10
- await createTableBySelect(page, 'container1', 3, 3);
11
- const centerCell = page.locator('#editor1').getByRole('cell').nth(4);
12
- await centerCell.click();
13
- const cellBounding = (await centerCell.boundingBox())!;
14
- expect(cellBounding).not.toBeNull();
15
- await page.mouse.move(cellBounding.x, cellBounding.y);
16
- const colBoundingBox = (await page.locator('#editor1 .table-up-resize-line__col').boundingBox())!;
17
- expect(colBoundingBox).not.toBeNull();
18
- await page.mouse.move(colBoundingBox.x + colBoundingBox.width / 2, colBoundingBox.y + colBoundingBox.height / 2);
19
- await page.mouse.down();
20
- await page.mouse.move(colBoundingBox.x + colBoundingBox.width / 2 - 200, colBoundingBox.y + colBoundingBox.height / 2);
21
- await page.mouse.up();
22
-
23
- expect(await page.locator('#editor1 .table-up-align').isVisible()).toBeTruthy();
24
-
25
- const table = page.locator('#editor1 .ql-editor .ql-table');
26
- await page.locator('#editor1 .table-up-align .table-up-align__item[data-align="center"]').click();
27
- await expect(table).toHaveCSS('margin-left', `100px`);
28
- await expect(table).toHaveCSS('margin-right', `100px`);
29
-
30
- await page.locator('#editor1 .table-up-align .table-up-align__item[data-align="right"]').click();
31
- await expect(table).toHaveCSS('margin-left', `200px`);
32
- await expect(table).toHaveCSS('margin-right', '0px');
33
-
34
- await page.locator('#editor1 .table-up-align .table-up-align__item[data-align="left"]').click();
35
- await expect(table).toHaveCSS('margin-left', '0px');
36
- await expect(table).toHaveCSS('margin-right', '200px');
37
- });
38
-
39
- extendTest('test TableAlign should update after resize', async ({ page }) => {
40
- await createTableBySelect(page, 'container1', 3, 3);
41
- const centerCell = page.locator('#editor1').getByRole('cell').nth(4);
42
- await centerCell.click();
43
- const cellBounding = (await centerCell.boundingBox())!;
44
- expect(cellBounding).not.toBeNull();
45
- const alignToolbar = page.locator('#editor1 .table-up-align');
46
- expect(await alignToolbar.isVisible()).toBeTruthy();
47
- const alignToolbarBoundingBox = (await alignToolbar.boundingBox())!;
48
- expect(alignToolbarBoundingBox).not.toBeNull();
49
-
50
- await page.mouse.move(cellBounding.x + cellBounding.width / 2, cellBounding.y + cellBounding.height / 2);
51
- const rowBoundingBox = (await page.locator('#editor1 .table-up-resize-line__row').boundingBox())!;
52
- expect(rowBoundingBox).not.toBeNull();
53
-
54
- await page.mouse.move(rowBoundingBox.x + rowBoundingBox.width / 2, rowBoundingBox.y + rowBoundingBox.height / 2);
55
- await page.mouse.down();
56
- await page.mouse.move(rowBoundingBox.x + rowBoundingBox.width / 2, rowBoundingBox.y + rowBoundingBox.height / 2 + 200);
57
- await page.mouse.up();
58
-
59
- expect(await alignToolbar.isVisible()).toBeTruthy();
60
- const newAlignToolbarBoundingBox = (await alignToolbar.boundingBox())!;
61
- expect(newAlignToolbarBoundingBox).not.toBeNull();
62
- // resize used Math.round, numDigits is 1 but not 0.1
63
- expect(newAlignToolbarBoundingBox.y - alignToolbarBoundingBox.y).toBeCloseTo(200, -1);
64
- });
65
-
66
- extendTest('test TableAlign should update when text change', async ({ page, editorPage }) => {
67
- editorPage.index = 0;
68
- await editorPage.setContents([
69
- { insert: '\n' },
70
- { insert: '\n' },
71
- { insert: '\n' },
72
- { insert: '\n' },
73
- { insert: '\n' },
74
- { insert: { 'table-up-col': { tableId: '2y50yzsqukx', colId: '7jwlegz1wcx', full: false, width: 50 } } },
75
- { insert: { 'table-up-col': { tableId: '2y50yzsqukx', colId: 'jzkt5xg4uoe', full: false, width: 50 } } },
76
- { insert: { 'table-up-col': { tableId: '2y50yzsqukx', colId: 'ya1np2wbu5f', full: false, width: 50 } } },
77
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'q5927gxiii', colId: '7jwlegz1wcx', rowspan: 1, colspan: 1 } }, insert: '\n' },
78
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'q5927gxiii', colId: 'jzkt5xg4uoe', rowspan: 1, colspan: 1 } }, insert: '\n' },
79
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'q5927gxiii', colId: 'ya1np2wbu5f', rowspan: 1, colspan: 1 } }, insert: '\n' },
80
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: '269nnst8unz', colId: '7jwlegz1wcx', rowspan: 1, colspan: 1 } }, insert: '\n' },
81
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: '269nnst8unz', colId: 'jzkt5xg4uoe', rowspan: 1, colspan: 1 } }, insert: '\n' },
82
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: '269nnst8unz', colId: 'ya1np2wbu5f', rowspan: 1, colspan: 1 } }, insert: '\n' },
83
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'xpwngzum4e', colId: '7jwlegz1wcx', rowspan: 1, colspan: 1 } }, insert: '\n' },
84
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'xpwngzum4e', colId: 'jzkt5xg4uoe', rowspan: 1, colspan: 1 } }, insert: '\n' },
85
- { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'xpwngzum4e', colId: 'ya1np2wbu5f', rowspan: 1, colspan: 1 } }, insert: '\n' },
86
- { insert: '\n' },
87
- ]);
88
-
89
- const lineBound = (await page.locator('#editor1 .ql-editor > p').first().boundingBox())!;
90
- expect(lineBound).not.toBeNull();
91
- await page.locator('#editor1 .ql-table .ql-table-cell').nth(0).click();
92
- const alignToolbar = page.locator('#container1 .table-up-align');
93
- await expect(alignToolbar).toBeVisible();
94
- const toolbarBound = (await alignToolbar.boundingBox())!;
95
- expect(toolbarBound).not.toBeNull();
96
-
97
- await editorPage.updateContents([{ insert: '12345\n12345' }], 'user');
98
-
99
- await expect(alignToolbar).toBeVisible();
100
- const newToolbarBound = (await alignToolbar.boundingBox())!;
101
- expect(toolbarBound).not.toBeNull();
102
-
103
- expect(newToolbarBound.y - toolbarBound.y).toBeCloseTo(lineBound.height, 5);
104
- });
1
+ import { expect, test } from '@playwright/test';
2
+ import { createTableBySelect, extendTest } from './utils';
3
+
4
+ test.beforeEach(async ({ page }) => {
5
+ await page.goto('http://127.0.0.1:5500/docs/test.html');
6
+ page.locator('.ql-container.ql-snow');
7
+ });
8
+
9
+ extendTest('test TableAlign should functional', async ({ page }) => {
10
+ await createTableBySelect(page, 'container1', 3, 3);
11
+ const centerCell = page.locator('#editor1').getByRole('cell').nth(4);
12
+ await centerCell.click();
13
+ const cellBounding = (await centerCell.boundingBox())!;
14
+ expect(cellBounding).not.toBeNull();
15
+ await page.mouse.move(cellBounding.x, cellBounding.y);
16
+ const colBoundingBox = (await page.locator('#editor1 .table-up-resize-line__col').boundingBox())!;
17
+ expect(colBoundingBox).not.toBeNull();
18
+ await page.mouse.move(colBoundingBox.x + colBoundingBox.width / 2, colBoundingBox.y + colBoundingBox.height / 2);
19
+ await page.mouse.down();
20
+ await page.mouse.move(colBoundingBox.x + colBoundingBox.width / 2 - 200, colBoundingBox.y + colBoundingBox.height / 2);
21
+ await page.mouse.up();
22
+
23
+ expect(await page.locator('#editor1 .table-up-align').isVisible()).toBeTruthy();
24
+
25
+ const table = page.locator('#editor1 .ql-editor .ql-table');
26
+ await page.locator('#editor1 .table-up-align .table-up-align__item[data-align="center"]').click();
27
+ await expect(table).toHaveCSS('margin-left', `100px`);
28
+ await expect(table).toHaveCSS('margin-right', `100px`);
29
+
30
+ await page.locator('#editor1 .table-up-align .table-up-align__item[data-align="right"]').click();
31
+ await expect(table).toHaveCSS('margin-left', `200px`);
32
+ await expect(table).toHaveCSS('margin-right', '0px');
33
+
34
+ await page.locator('#editor1 .table-up-align .table-up-align__item[data-align="left"]').click();
35
+ await expect(table).toHaveCSS('margin-left', '0px');
36
+ await expect(table).toHaveCSS('margin-right', '200px');
37
+ });
38
+
39
+ extendTest('test TableAlign should update after resize', async ({ page }) => {
40
+ await createTableBySelect(page, 'container1', 3, 3);
41
+ const centerCell = page.locator('#editor1').getByRole('cell').nth(4);
42
+ await centerCell.click();
43
+ const cellBounding = (await centerCell.boundingBox())!;
44
+ expect(cellBounding).not.toBeNull();
45
+ const alignToolbar = page.locator('#editor1 .table-up-align');
46
+ expect(await alignToolbar.isVisible()).toBeTruthy();
47
+ const alignToolbarBoundingBox = (await alignToolbar.boundingBox())!;
48
+ expect(alignToolbarBoundingBox).not.toBeNull();
49
+
50
+ await page.mouse.move(cellBounding.x + cellBounding.width / 2, cellBounding.y + cellBounding.height / 2);
51
+ const rowBoundingBox = (await page.locator('#editor1 .table-up-resize-line__row').boundingBox())!;
52
+ expect(rowBoundingBox).not.toBeNull();
53
+
54
+ await page.mouse.move(rowBoundingBox.x + rowBoundingBox.width / 2, rowBoundingBox.y + rowBoundingBox.height / 2);
55
+ await page.mouse.down();
56
+ await page.mouse.move(rowBoundingBox.x + rowBoundingBox.width / 2, rowBoundingBox.y + rowBoundingBox.height / 2 + 200);
57
+ await page.mouse.up();
58
+
59
+ expect(await alignToolbar.isVisible()).toBeTruthy();
60
+ const newAlignToolbarBoundingBox = (await alignToolbar.boundingBox())!;
61
+ expect(newAlignToolbarBoundingBox).not.toBeNull();
62
+ // resize used Math.round, numDigits is 1 but not 0.1
63
+ expect(newAlignToolbarBoundingBox.y - alignToolbarBoundingBox.y).toBeCloseTo(200, -1);
64
+ });
65
+
66
+ extendTest('test TableAlign should update when text change', async ({ page, editorPage }) => {
67
+ editorPage.index = 0;
68
+ await editorPage.setContents([
69
+ { insert: '\n' },
70
+ { insert: '\n' },
71
+ { insert: '\n' },
72
+ { insert: '\n' },
73
+ { insert: '\n' },
74
+ { insert: { 'table-up-col': { tableId: '2y50yzsqukx', colId: '7jwlegz1wcx', full: false, width: 50 } } },
75
+ { insert: { 'table-up-col': { tableId: '2y50yzsqukx', colId: 'jzkt5xg4uoe', full: false, width: 50 } } },
76
+ { insert: { 'table-up-col': { tableId: '2y50yzsqukx', colId: 'ya1np2wbu5f', full: false, width: 50 } } },
77
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'q5927gxiii', colId: '7jwlegz1wcx', rowspan: 1, colspan: 1 } }, insert: '\n' },
78
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'q5927gxiii', colId: 'jzkt5xg4uoe', rowspan: 1, colspan: 1 } }, insert: '\n' },
79
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'q5927gxiii', colId: 'ya1np2wbu5f', rowspan: 1, colspan: 1 } }, insert: '\n' },
80
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: '269nnst8unz', colId: '7jwlegz1wcx', rowspan: 1, colspan: 1 } }, insert: '\n' },
81
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: '269nnst8unz', colId: 'jzkt5xg4uoe', rowspan: 1, colspan: 1 } }, insert: '\n' },
82
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: '269nnst8unz', colId: 'ya1np2wbu5f', rowspan: 1, colspan: 1 } }, insert: '\n' },
83
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'xpwngzum4e', colId: '7jwlegz1wcx', rowspan: 1, colspan: 1 } }, insert: '\n' },
84
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'xpwngzum4e', colId: 'jzkt5xg4uoe', rowspan: 1, colspan: 1 } }, insert: '\n' },
85
+ { attributes: { 'table-up-cell-inner': { tableId: '2y50yzsqukx', rowId: 'xpwngzum4e', colId: 'ya1np2wbu5f', rowspan: 1, colspan: 1 } }, insert: '\n' },
86
+ { insert: '\n' },
87
+ ]);
88
+
89
+ const lineBound = (await page.locator('#editor1 .ql-editor > p').first().boundingBox())!;
90
+ expect(lineBound).not.toBeNull();
91
+ await page.locator('#editor1 .ql-table .ql-table-cell').nth(0).click();
92
+ const alignToolbar = page.locator('#container1 .table-up-align');
93
+ await expect(alignToolbar).toBeVisible();
94
+ const toolbarBound = (await alignToolbar.boundingBox())!;
95
+ expect(toolbarBound).not.toBeNull();
96
+
97
+ await editorPage.updateContents([{ insert: '12345\n12345' }], 'user');
98
+
99
+ await expect(alignToolbar).toBeVisible();
100
+ const newToolbarBound = (await alignToolbar.boundingBox())!;
101
+ expect(toolbarBound).not.toBeNull();
102
+
103
+ expect(newToolbarBound.y - toolbarBound.y).toBeCloseTo(lineBound.height, 5);
104
+ });