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
@@ -1,118 +1,111 @@
1
- import type Quill from 'quill';
2
- import type { TableUp } from '../../table-up';
3
- import type { InternalTableSelectionModule, TableMenuOptions, ToolTipOptions } from '../../utils';
4
- import type { TableSelection } from '../table-selection';
5
- import { limitDomInViewPort, tableUpEvent } from '../../utils';
6
- import { menuColorSelectClassName } from './constants';
7
- import { TableMenuCommon } from './table-menu-common';
8
-
9
- type TableMenuOptionsInput = Partial<Omit<TableMenuOptions, 'texts'>>;
10
- export class TableMenuContextmenu extends TableMenuCommon {
11
- colorChooseTooltipOption: ToolTipOptions = {
12
- direction: 'right',
13
- };
14
-
15
- constructor(public tableModule: TableUp, public quill: Quill, options: TableMenuOptionsInput) {
16
- super(tableModule, quill, options);
17
-
18
- this.quill.root.addEventListener('contextmenu', this.listenContextmenu);
19
- this.quill.on(tableUpEvent.TABLE_SELECTION_CHANGE, this.tableSelectioChange);
20
- this.quill.on(tableUpEvent.TABLE_SELECTION_DISPLAY_CHANGE, this.tableSelectioChange);
21
- }
22
-
23
- tableSelectioChange = (tableSelection: InternalTableSelectionModule) => {
24
- if (tableSelection.selectedTds.length <= 0) {
25
- this.hide();
26
- }
27
- };
28
-
29
- listenContextmenu = (e: MouseEvent) => {
30
- e.preventDefault();
31
-
32
- const path = e.composedPath() as HTMLElement[];
33
- if (!path || path.length <= 0) return;
34
-
35
- const tableNode = path.find(node => node.tagName && node.tagName.toUpperCase() === 'TABLE' && node.classList.contains('ql-table'));
36
-
37
- const tableSelection = this.tableModule.getModule<TableSelection>('table-selection');
38
- if (tableNode && tableSelection?.selectedTds?.length) {
39
- if (!this.menu) {
40
- this.menu = this.buildTools();
41
- }
42
- // manual call menu show
43
- Object.assign(this.menu.style, { display: 'flex' });
44
- this.isMenuDisplay = true;
45
-
46
- this.update({ x: e.clientX, y: e.clientY });
47
- document.addEventListener('click', () => {
48
- this.hide();
49
- }, { once: true });
50
- }
51
- else {
52
- this.hide();
53
- }
54
- };
55
-
56
- buildTools(): HTMLElement {
57
- const menu = super.buildTools();
58
- menu.classList.add(this.bem.is('contextmenu'));
59
- const items = menu.getElementsByClassName(menuColorSelectClassName);
60
- for (const item of Array.from(items)) {
61
- item.addEventListener('click', e => e.stopPropagation());
62
- }
63
- document.body.appendChild(menu);
64
- return menu;
65
- }
66
-
67
- createTipText(item: HTMLElement, text: string): void {
68
- const tipTextDom = document.createElement('span');
69
- tipTextDom.textContent = text;
70
- item.appendChild(tipTextDom);
71
- }
72
-
73
- // override show. because TableSelection will call tableMenu.show() after select td
74
- show() {}
75
-
76
- update(position?: { x: number; y: number }) {
77
- super.update();
78
- const tableSelection = this.tableModule.getModule<TableSelection>('table-selection');
79
- if (!this.table || !this.isMenuDisplay || !this.menu) {
80
- this.hide();
81
- return;
82
- }
83
- if (!position || !tableSelection?.isDisplaySelection) {
84
- return;
85
- }
86
-
87
- const style: Record<string, any> = {
88
- display: 'flex',
89
- left: 0,
90
- top: 0,
91
- };
92
-
93
- const { x, y } = position;
94
- style.left = x;
95
- style.top = y;
96
-
97
- Object.assign(this.menu.style, {
98
- ...style,
99
- left: `${style.left + window.scrollX}px`,
100
- top: `${style.top + window.scrollY}px`,
101
- });
102
-
103
- // limit menu in viewport
104
- const menuRect = this.menu.getBoundingClientRect();
105
- const { left: limitLeft, top: limitTop } = limitDomInViewPort(menuRect);
106
- Object.assign(this.menu.style, {
107
- left: `${limitLeft + window.scrollX}px`,
108
- top: `${limitTop + window.scrollY}px`,
109
- });
110
- }
111
-
112
- destroy() {
113
- this.quill.root.removeEventListener('contextmenu', this.listenContextmenu);
114
- super.destroy();
115
- this.quill.off(tableUpEvent.TABLE_SELECTION_CHANGE, this.tableSelectioChange);
116
- this.quill.off(tableUpEvent.TABLE_SELECTION_DISPLAY_CHANGE, this.tableSelectioChange);
117
- }
118
- }
1
+ import type Quill from 'quill';
2
+ import type { TableUp } from '../../table-up';
3
+ import type { InternalTableSelectionModule, Position, TableMenuOptions } from '../../utils';
4
+ import type { TableSelection } from '../table-selection';
5
+ import { addScrollEvent, clearScrollEvent, limitDomInViewPort, tableUpEvent, tableUpInternal } from '../../utils';
6
+ import { menuColorSelectClassName } from './constants';
7
+ import { TableMenuCommon } from './table-menu-common';
8
+
9
+ type TableMenuOptionsInput = Partial<Omit<TableMenuOptions, 'texts'>>;
10
+ export class TableMenuContextmenu extends TableMenuCommon {
11
+ static moduleName = 'table-menu-contextmenu';
12
+
13
+ scrollHandler: [HTMLElement, (e: Event) => void][] = [];
14
+
15
+ constructor(public tableModule: TableUp, public quill: Quill, options: TableMenuOptionsInput) {
16
+ super(tableModule, quill, options);
17
+
18
+ this.quill.root.addEventListener('contextmenu', this.listenContextmenu);
19
+ this.quill.on(tableUpEvent.TABLE_SELECTION_CHANGE, this.tableSelectioChange);
20
+ this.quill.on(tableUpEvent.TABLE_SELECTION_DISPLAY_CHANGE, this.tableSelectioChange);
21
+ }
22
+
23
+ tableSelectioChange = (tableSelection: InternalTableSelectionModule) => {
24
+ if (tableSelection.selectedTds.length <= 0) {
25
+ this.hide();
26
+ }
27
+ };
28
+
29
+ listenContextmenu = (e: MouseEvent) => {
30
+ e.preventDefault();
31
+
32
+ const path = e.composedPath() as HTMLElement[];
33
+ if (!path || path.length <= 0) return;
34
+
35
+ const tableNode = path.find(node => node.tagName && node.tagName.toUpperCase() === 'TABLE' && node.classList.contains('ql-table'));
36
+
37
+ const tableSelection = this.tableModule.getModule<TableSelection>(tableUpInternal.tableSelectionName);
38
+ if (tableNode && tableSelection?.selectedTds?.length) {
39
+ if (!this.menu) {
40
+ this.menu = this.buildTools();
41
+ }
42
+ // manual call menu show
43
+ this.isMenuDisplay = true;
44
+ this.update({ x: e.clientX, y: e.clientY });
45
+ const tempHide = () => {
46
+ this.hide();
47
+ clearScrollEvent.call(this);
48
+ };
49
+ addScrollEvent.call(this, this.quill.root, tempHide);
50
+ document.addEventListener('click', tempHide, { once: true });
51
+ }
52
+ else {
53
+ this.hide();
54
+ }
55
+ };
56
+
57
+ buildTools(): HTMLElement {
58
+ const menu = super.buildTools();
59
+ menu.classList.add(this.bem.is('contextmenu'));
60
+ const items = menu.getElementsByClassName(menuColorSelectClassName);
61
+ for (const item of Array.from(items)) {
62
+ item.addEventListener('click', e => e.stopPropagation());
63
+ }
64
+ this.quill.container.appendChild(menu);
65
+ return menu;
66
+ }
67
+
68
+ createTipText(item: HTMLElement, text: string): void {
69
+ const tipTextDom = document.createElement('span');
70
+ tipTextDom.textContent = text;
71
+ item.appendChild(tipTextDom);
72
+ }
73
+
74
+ // override show. because TableSelection will call tableMenu.show() after select td
75
+ show() {}
76
+
77
+ update(position?: Position) {
78
+ super.update();
79
+ const tableSelection = this.tableModule.getModule<TableSelection>(tableUpInternal.tableSelectionName);
80
+ if (!this.table || !this.isMenuDisplay || !this.menu) {
81
+ this.hide();
82
+ return;
83
+ }
84
+ if (!position || !tableSelection?.isDisplaySelection) {
85
+ return;
86
+ }
87
+
88
+ const rootRect = this.quill.container.getBoundingClientRect();
89
+ Object.assign(this.menu.style, {
90
+ left: `${position.x - rootRect.x}px`,
91
+ top: `${position.y - rootRect.y}px`,
92
+ });
93
+
94
+ // limit menu in viewport
95
+ const menuRect = this.menu.getBoundingClientRect();
96
+ const { left: limitLeft, top: limitTop } = limitDomInViewPort(menuRect);
97
+ const diffX = menuRect.left - limitLeft;
98
+ const diffY = menuRect.top - limitTop;
99
+ Object.assign(this.menu.style, {
100
+ left: `${position.x - rootRect.x - diffX}px`,
101
+ top: `${position.y - rootRect.y - diffY}px`,
102
+ });
103
+ }
104
+
105
+ destroy() {
106
+ this.quill.root.removeEventListener('contextmenu', this.listenContextmenu);
107
+ super.destroy();
108
+ this.quill.off(tableUpEvent.TABLE_SELECTION_CHANGE, this.tableSelectioChange);
109
+ this.quill.off(tableUpEvent.TABLE_SELECTION_DISPLAY_CHANGE, this.tableSelectioChange);
110
+ }
111
+ }
@@ -1,94 +1,96 @@
1
- import type Quill from 'quill';
2
- import type { TableCellInnerFormat } from '../../formats';
3
- import type { TableUp } from '../../table-up';
4
- import type { InternalTableSelectionModule } from '../../utils';
5
- import type { TableSelection } from '../table-selection';
6
- import type { TableMenuOptionsInput } from './table-menu-common';
7
- import { computePosition, flip, limitShift, offset, shift } from '@floating-ui/dom';
8
- import { tableUpEvent } from '../../utils';
9
- import { TableMenuCommon } from './table-menu-common';
10
-
11
- export class TableMenuSelect extends TableMenuCommon {
12
- constructor(public tableModule: TableUp, public quill: Quill, options: TableMenuOptionsInput) {
13
- super(tableModule, quill, options);
14
-
15
- this.quill.on(tableUpEvent.TABLE_SELECTION_DRAG_START, this.tableSelectionDragStart);
16
- this.quill.on(tableUpEvent.TABLE_SELECTION_DRAG_END, this.tableSelectionDragEnd);
17
- this.quill.on(tableUpEvent.TABLE_SELECTION_CHANGE, this.tableSelectioChange);
18
- this.quill.on(tableUpEvent.TABLE_SELECTION_DISPLAY_CHANGE, this.tableSelectionDisplayChange);
19
- }
20
-
21
- tableSelectionDragStart = () => {
22
- this.hide();
23
- };
24
-
25
- tableSelectionDragEnd = (tableSelection: InternalTableSelectionModule) => {
26
- if (tableSelection.selectedTds.length > 0) {
27
- this.show();
28
- }
29
- };
30
-
31
- tableSelectioChange = (tableSelection: InternalTableSelectionModule, selectedTds: TableCellInnerFormat[]) => {
32
- if (selectedTds.length <= 0) {
33
- this.hide();
34
- }
35
- };
36
-
37
- tableSelectionDisplayChange = (tableSelection: InternalTableSelectionModule) => {
38
- if (!tableSelection.dragging) {
39
- this.update();
40
- }
41
- };
42
-
43
- buildTools(): HTMLElement {
44
- const menu = super.buildTools();
45
- this.tableModule.addContainer(menu);
46
- return menu;
47
- }
48
-
49
- show() {
50
- super.show();
51
- this.update();
52
- }
53
-
54
- update() {
55
- super.update();
56
- if (!this.menu && this.table) {
57
- this.show();
58
- return;
59
- }
60
- const selectedTds = this.getSelectedTds();
61
- if (!this.menu || !this.table || selectedTds.length === 0) {
62
- if (this.menu || !this.table) {
63
- this.isMenuDisplay = false;
64
- this.menu && this.menu.classList.add(this.bem.is('hidden'));
65
- this.hide();
66
- }
67
- return;
68
- }
69
- this.isMenuDisplay = true;
70
- this.menu.classList.remove(this.bem.is('hidden'));
71
-
72
- const tableSelection = this.tableModule.getModule<TableSelection>('table-selection');
73
- if (tableSelection?.isDisplaySelection) {
74
- computePosition(tableSelection.cellSelect, this.menu, {
75
- placement: 'bottom',
76
- middleware: [flip(), shift({ limiter: limitShift() }), offset(20)],
77
- }).then(({ x, y }) => {
78
- if (this.menu) {
79
- Object.assign(this.menu.style, {
80
- left: `${x}px`,
81
- top: `${y}px`,
82
- });
83
- }
84
- });
85
- }
86
- }
87
-
88
- destroy(): void {
89
- super.destroy();
90
-
91
- this.quill.off(tableUpEvent.TABLE_SELECTION_DRAG_START, this.tableSelectionDragStart);
92
- this.quill.off(tableUpEvent.TABLE_SELECTION_DRAG_END, this.tableSelectionDragEnd);
93
- }
94
- }
1
+ import type Quill from 'quill';
2
+ import type { TableCellInnerFormat } from '../../formats';
3
+ import type { TableUp } from '../../table-up';
4
+ import type { InternalTableSelectionModule } from '../../utils';
5
+ import type { TableSelection } from '../table-selection';
6
+ import type { TableMenuOptionsInput } from './table-menu-common';
7
+ import { computePosition, flip, limitShift, offset, shift } from '@floating-ui/dom';
8
+ import { tableUpEvent, tableUpInternal } from '../../utils';
9
+ import { TableMenuCommon } from './table-menu-common';
10
+
11
+ export class TableMenuSelect extends TableMenuCommon {
12
+ static moduleName = 'table-menu-select';
13
+
14
+ constructor(public tableModule: TableUp, public quill: Quill, options: TableMenuOptionsInput) {
15
+ super(tableModule, quill, options);
16
+
17
+ this.quill.on(tableUpEvent.TABLE_SELECTION_DRAG_START, this.tableSelectionDragStart);
18
+ this.quill.on(tableUpEvent.TABLE_SELECTION_DRAG_END, this.tableSelectionDragEnd);
19
+ this.quill.on(tableUpEvent.TABLE_SELECTION_CHANGE, this.tableSelectioChange);
20
+ this.quill.on(tableUpEvent.TABLE_SELECTION_DISPLAY_CHANGE, this.tableSelectionDisplayChange);
21
+ }
22
+
23
+ tableSelectionDragStart = () => {
24
+ this.hide();
25
+ };
26
+
27
+ tableSelectionDragEnd = (tableSelection: InternalTableSelectionModule) => {
28
+ if (tableSelection.selectedTds.length > 0) {
29
+ this.show();
30
+ }
31
+ };
32
+
33
+ tableSelectioChange = (tableSelection: InternalTableSelectionModule, selectedTds: TableCellInnerFormat[]) => {
34
+ if (selectedTds.length <= 0) {
35
+ this.hide();
36
+ }
37
+ };
38
+
39
+ tableSelectionDisplayChange = (tableSelection: InternalTableSelectionModule) => {
40
+ if (!tableSelection.dragging) {
41
+ this.update();
42
+ }
43
+ };
44
+
45
+ buildTools(): HTMLElement {
46
+ const menu = super.buildTools();
47
+ this.tableModule.addContainer(menu);
48
+ return menu;
49
+ }
50
+
51
+ show() {
52
+ super.show();
53
+ this.update();
54
+ }
55
+
56
+ update() {
57
+ super.update();
58
+ if (!this.menu && this.table) {
59
+ this.show();
60
+ return;
61
+ }
62
+ const selectedTds = this.getSelectedTds();
63
+ if (!this.menu || !this.table || selectedTds.length === 0) {
64
+ if (this.menu || !this.table) {
65
+ this.isMenuDisplay = false;
66
+ this.menu?.classList.add(this.bem.is('hidden'));
67
+ this.hide();
68
+ }
69
+ return;
70
+ }
71
+ this.isMenuDisplay = true;
72
+ this.menu.classList.remove(this.bem.is('hidden'));
73
+
74
+ const tableSelection = this.tableModule.getModule<TableSelection>(tableUpInternal.tableSelectionName);
75
+ if (tableSelection?.isDisplaySelection) {
76
+ computePosition(tableSelection.cellSelect, this.menu, {
77
+ placement: 'bottom',
78
+ middleware: [flip(), shift({ limiter: limitShift() }), offset(20)],
79
+ }).then(({ x, y }) => {
80
+ if (this.menu) {
81
+ Object.assign(this.menu.style, {
82
+ left: `${x}px`,
83
+ top: `${y}px`,
84
+ });
85
+ }
86
+ });
87
+ }
88
+ }
89
+
90
+ destroy(): void {
91
+ super.destroy();
92
+
93
+ this.quill.off(tableUpEvent.TABLE_SELECTION_DRAG_START, this.tableSelectionDragStart);
94
+ this.quill.off(tableUpEvent.TABLE_SELECTION_DRAG_END, this.tableSelectionDragEnd);
95
+ }
96
+ }
@@ -1,5 +1,5 @@
1
- export * from './table-resize-box';
2
- export * from './table-resize-common';
3
- export * from './table-resize-line';
4
- export * from './table-resize-scale';
5
- export * from './utils';
1
+ export * from './table-resize-box';
2
+ export * from './table-resize-common';
3
+ export * from './table-resize-line';
4
+ export * from './table-resize-scale';
5
+ export * from './utils';