@atlaskit/editor-plugin-table 7.2.2 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/commands/column-resize.js +115 -45
  3. package/dist/cjs/commands/go-to-next-cell.js +7 -11
  4. package/dist/cjs/commands/misc.js +3 -2
  5. package/dist/cjs/commands/selection.js +3 -3
  6. package/dist/cjs/event-handlers.js +38 -25
  7. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  8. package/dist/cjs/pm-plugins/keymap.js +1 -0
  9. package/dist/cjs/pm-plugins/main.js +43 -9
  10. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
  11. package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
  12. package/dist/cjs/reducer.js +5 -2
  13. package/dist/cjs/utils/drag-menu.js +37 -23
  14. package/dist/cjs/utils/merged-cells.js +66 -1
  15. package/dist/es2019/commands/column-resize.js +100 -35
  16. package/dist/es2019/commands/go-to-next-cell.js +7 -9
  17. package/dist/es2019/commands/misc.js +3 -2
  18. package/dist/es2019/commands/selection.js +5 -5
  19. package/dist/es2019/event-handlers.js +17 -3
  20. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  21. package/dist/es2019/pm-plugins/keymap.js +3 -2
  22. package/dist/es2019/pm-plugins/main.js +41 -5
  23. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
  24. package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
  25. package/dist/es2019/reducer.js +5 -2
  26. package/dist/es2019/utils/drag-menu.js +38 -14
  27. package/dist/es2019/utils/merged-cells.js +73 -0
  28. package/dist/esm/commands/column-resize.js +105 -35
  29. package/dist/esm/commands/go-to-next-cell.js +7 -11
  30. package/dist/esm/commands/misc.js +3 -2
  31. package/dist/esm/commands/selection.js +5 -5
  32. package/dist/esm/event-handlers.js +38 -25
  33. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  34. package/dist/esm/pm-plugins/keymap.js +3 -2
  35. package/dist/esm/pm-plugins/main.js +38 -4
  36. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
  37. package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
  38. package/dist/esm/reducer.js +5 -2
  39. package/dist/esm/utils/drag-menu.js +36 -22
  40. package/dist/esm/utils/merged-cells.js +65 -0
  41. package/dist/types/commands/column-resize.d.ts +2 -0
  42. package/dist/types/commands/misc.d.ts +1 -1
  43. package/dist/types/types.d.ts +16 -0
  44. package/dist/types/utils/drag-menu.d.ts +4 -1
  45. package/dist/types/utils/merged-cells.d.ts +2 -0
  46. package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
  47. package/dist/types-ts4.5/commands/misc.d.ts +1 -1
  48. package/dist/types-ts4.5/types.d.ts +16 -0
  49. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  50. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  51. package/package.json +10 -17
  52. package/src/commands/column-resize.ts +155 -40
  53. package/src/commands/go-to-next-cell.ts +6 -15
  54. package/src/commands/misc.ts +2 -0
  55. package/src/commands/selection.ts +5 -5
  56. package/src/event-handlers.ts +21 -4
  57. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  58. package/src/pm-plugins/keymap.ts +3 -0
  59. package/src/pm-plugins/main.ts +47 -2
  60. package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
  61. package/src/pm-plugins/table-resizing/plugin.ts +18 -1
  62. package/src/reducer.ts +5 -2
  63. package/src/types.ts +16 -0
  64. package/src/utils/drag-menu.ts +94 -20
  65. package/src/utils/merged-cells.ts +78 -0
  66. package/tsconfig.dev.json +0 -69
  67. package/tsconfig.json +2 -877
  68. package/examples/99-testing.tsx +0 -140
  69. package/examples/config.jsonc +0 -14
  70. package/src/__tests__/unit/analytics.ts +0 -888
  71. package/src/__tests__/unit/collab.ts +0 -93
  72. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  73. package/src/__tests__/unit/commands/insert.ts +0 -137
  74. package/src/__tests__/unit/commands/misc.ts +0 -185
  75. package/src/__tests__/unit/commands/sort.ts +0 -128
  76. package/src/__tests__/unit/commands.ts +0 -745
  77. package/src/__tests__/unit/copy-button.ts +0 -22
  78. package/src/__tests__/unit/copy-paste.ts +0 -677
  79. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  80. package/src/__tests__/unit/event-handlers.ts +0 -296
  81. package/src/__tests__/unit/fix-tables.ts +0 -164
  82. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  83. package/src/__tests__/unit/handlers.ts +0 -98
  84. package/src/__tests__/unit/hover-selection.ts +0 -230
  85. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  86. package/src/__tests__/unit/index.ts +0 -912
  87. package/src/__tests__/unit/layout.ts +0 -146
  88. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  89. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  90. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  91. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  92. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  93. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  94. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  95. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  96. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  97. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  98. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  99. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  100. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  101. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  102. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  103. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  104. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  105. package/src/__tests__/unit/sort-column.ts +0 -399
  106. package/src/__tests__/unit/toolbar.ts +0 -512
  107. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  108. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  109. package/src/__tests__/unit/transforms/merging.ts +0 -392
  110. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  111. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  112. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  113. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  114. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  115. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  116. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  117. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  118. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  119. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  120. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  121. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  122. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  123. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  124. package/src/__tests__/unit/undo-redo.ts +0 -220
  125. package/src/__tests__/unit/utils/analytics.ts +0 -98
  126. package/src/__tests__/unit/utils/collapse.ts +0 -57
  127. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  128. package/src/__tests__/unit/utils/dom.ts +0 -180
  129. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  130. package/src/__tests__/unit/utils/nodes.ts +0 -79
  131. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  132. package/src/__tests__/unit/utils/table.ts +0 -96
  133. package/src/__tests__/unit/utils.ts +0 -670
  134. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  135. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  136. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-should-remove-the-table-column-on-click-1-snap.png +0 -3
  137. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-visual-hints-should-be-added-to-the-table-column-on-hover-1-snap.png +0 -3
  138. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-should-remove-the-table-row-on-click-1-snap.png +0 -3
  139. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-visual-hints-should-be-added-to-the-table-row-on-hover-1-snap.png +0 -3
  140. package/src/__tests__/visual-regression/__image_snapshots__/copy-button-ts-floating-toolbar-copy-button-table-target-node-displays-blue-border-when-copy-button-is-hovered-1-snap.png +0 -3
  141. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-1-snap.png +0 -3
  142. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-2-snap.png +0 -3
  143. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-3-snap.png +0 -3
  144. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +0 -3
  145. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +0 -3
  146. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  147. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  148. package/src/__tests__/visual-regression/index.ts +0 -62
  149. package/src/__tests__/visual-regression/sticky-header.ts +0 -61
@@ -1,269 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
2
- import {
3
- p,
4
- table,
5
- td,
6
- th,
7
- tr,
8
- } from '@atlaskit/editor-test-helpers/doc-builder';
9
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
10
- import defaultSchema from '@atlaskit/editor-test-helpers/schema';
11
- import { ffTest } from '@atlassian/feature-flags-test-utils';
12
-
13
- import {
14
- generateColgroup,
15
- getColgroupChildrenLength,
16
- } from '../../../../pm-plugins/table-resizing/utils';
17
- import { isMinCellWidthTable } from '../../../../pm-plugins/table-resizing/utils/colgroup';
18
-
19
- describe('table-resizing/colgroup', () => {
20
- describe('#generateColgroup', () => {
21
- describe('creates col with correct widths', () => {
22
- describe('based on colwidth cell attributes', () => {
23
- ffTest(
24
- 'platform.editor.custom-table-width',
25
- () => {
26
- const result = generateColgroup(
27
- getTable([
28
- {
29
- colwidth: [10],
30
- colspan: 1,
31
- },
32
- {
33
- colwidth: [20],
34
- colspan: 1,
35
- },
36
- ]),
37
- );
38
-
39
- expect(result).toEqual([
40
- ['col', { style: 'width: 47.5px;' }],
41
- ['col', { style: 'width: 47.5px;' }],
42
- ]);
43
- },
44
- () => {
45
- const result = generateColgroup(
46
- getTable([
47
- {
48
- colwidth: [10],
49
- colspan: 1,
50
- },
51
- {
52
- colwidth: [20],
53
- colspan: 1,
54
- },
55
- ]),
56
- );
57
-
58
- expect(result).toEqual([
59
- ['col', { style: 'width: 10px;' }],
60
- ['col', { style: 'width: 20px;' }],
61
- ]);
62
- },
63
- );
64
- });
65
-
66
- describe('when colwidth is not an array', () => {
67
- ffTest(
68
- 'platform.editor.custom-table-width',
69
- () => {
70
- const result = generateColgroup(
71
- getTable([
72
- {
73
- colwidth: 10,
74
- colspan: 1,
75
- },
76
- {
77
- colwidth: null,
78
- colspan: 1,
79
- },
80
- {
81
- colwidth: undefined,
82
- colspan: 1,
83
- },
84
- ]),
85
- );
86
-
87
- expect(result).toEqual([
88
- ['col', { style: 'width: 48px;' }],
89
- ['col', { style: 'width: 48px;' }],
90
- ['col', { style: 'width: 48px;' }],
91
- ]);
92
- },
93
- () => {
94
- const result = generateColgroup(
95
- getTable([
96
- {
97
- colwidth: 10,
98
- colspan: 1,
99
- },
100
- {
101
- colwidth: null,
102
- colspan: 1,
103
- },
104
- {
105
- colwidth: undefined,
106
- colspan: 1,
107
- },
108
- ]),
109
- );
110
-
111
- expect(result).toEqual([
112
- ['col', {}],
113
- ['col', {}],
114
- ['col', {}],
115
- ]);
116
- },
117
- );
118
- });
119
-
120
- describe('when colwidth has falsy values', () => {
121
- ffTest(
122
- 'platform.editor.custom-table-width',
123
- () => {
124
- const result = generateColgroup(
125
- getTable([
126
- {
127
- colwidth: [0],
128
- colspan: 1,
129
- },
130
- {
131
- colwidth: [null],
132
- colspan: 1,
133
- },
134
- {
135
- colwidth: [undefined],
136
- colspan: 1,
137
- },
138
- ]),
139
- );
140
-
141
- expect(result).toEqual(
142
- expect.arrayContaining([
143
- // (.666*) -> match unknown number of 6's
144
- // (.?) -> match rounding errors e.g. 47.6666664px
145
- [
146
- 'col',
147
- { style: expect.stringMatching(/^width: 47.666*.?px/) },
148
- ],
149
- [
150
- 'col',
151
- { style: expect.stringMatching(/^width: 47.666*.?px/) },
152
- ],
153
- [
154
- 'col',
155
- { style: expect.stringMatching(/^width: 47.666*.?px/) },
156
- ],
157
- ]),
158
- );
159
- },
160
- () => {
161
- const result = generateColgroup(
162
- getTable([
163
- {
164
- colwidth: [0],
165
- colspan: 1,
166
- },
167
- {
168
- colwidth: [null],
169
- colspan: 1,
170
- },
171
- {
172
- colwidth: [undefined],
173
- colspan: 1,
174
- },
175
- ]),
176
- );
177
- expect(result).toEqual([
178
- ['col', {}],
179
- ['col', {}],
180
- ['col', {}],
181
- ]);
182
- },
183
- );
184
- });
185
-
186
- function getTable(cellAttributes: { [key: string]: any }[]) {
187
- return table({
188
- isNumberColumnEnabled: true,
189
- })(tr(...cellAttributes.map((attrs) => td(attrs)(p('text')))))(
190
- defaultSchema,
191
- );
192
- }
193
- });
194
- });
195
-
196
- //isMinCellWidthTable function test
197
- describe('#isMinCellWidthTable', () => {
198
- describe('check if a table has all the columns with minimum width', () => {
199
- it('when input table has all columns in minimum width', () => {
200
- const result = isMinCellWidthTable(getMinCellWidthTable());
201
-
202
- expect(result).toEqual(true);
203
- });
204
-
205
- it('when input table has a column that is not minimum width', () => {
206
- const result = isMinCellWidthTable(getNonMinCellWidthTable());
207
-
208
- expect(result).toEqual(false);
209
- });
210
-
211
- function getMinCellWidthTable() {
212
- return table()(
213
- tr(
214
- td({ colwidth: [48] })(p('')),
215
- td({ colwidth: [48] })(p('')),
216
- td({ colwidth: [48] })(p('')),
217
- ),
218
- )(defaultSchema);
219
- }
220
-
221
- function getNonMinCellWidthTable() {
222
- return table()(
223
- tr(
224
- td({ colwidth: [200] })(p('')),
225
- td({ colwidth: [200] })(p('')),
226
- td({ colwidth: [48] })(p('')),
227
- ),
228
- )(defaultSchema);
229
- }
230
- });
231
- });
232
-
233
- describe('#getColgroupChildrenLength', () => {
234
- it('returns 1 when table only have 1 column', () => {
235
- expect(
236
- getColgroupChildrenLength(table()(tr(td()(p(''))))(defaultSchema)),
237
- ).toBe(1);
238
- });
239
-
240
- it('returns 3 when table have 3 column', () => {
241
- expect(
242
- getColgroupChildrenLength(
243
- table()(tr(td()(p('')), td()(p('')), td()(p(''))))(defaultSchema),
244
- ),
245
- ).toBe(3);
246
- });
247
-
248
- it('returns 5 when table have 5 column', () => {
249
- expect(
250
- getColgroupChildrenLength(
251
- table()(
252
- tr(td()(p('')), td()(p('')), td()(p('')), td()(p('')), td()(p(''))),
253
- )(defaultSchema),
254
- ),
255
- ).toBe(5);
256
- });
257
-
258
- it('returns correct number when table have merged header column', () => {
259
- expect(
260
- getColgroupChildrenLength(
261
- table()(
262
- tr(th({ colspan: 2 })(p('')), th()(p(''))),
263
- tr(td()(p('')), td()(p('')), td()(p(''))),
264
- )(defaultSchema),
265
- ),
266
- ).toBe(3);
267
- });
268
- });
269
- });
@@ -1,192 +0,0 @@
1
- import {
2
- ACTION_SUBJECT,
3
- EVENT_TYPE,
4
- TABLE_ACTION,
5
- } from '@atlaskit/editor-common/analytics';
6
- import type { DocBuilder } from '@atlaskit/editor-common/types';
7
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
8
- import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
9
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
10
- import { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
11
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
12
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
13
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
14
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
15
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
16
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
17
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
18
- import {
19
- akEditorDefaultLayoutWidth,
20
- akEditorFullPageMaxWidth,
21
- } from '@atlaskit/editor-shared-styles/consts';
22
- // eslint-disable-next-line import/no-extraneous-dependencies
23
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
24
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
25
- import {
26
- createProsemirrorEditorFactory,
27
- Preset,
28
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
29
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
30
- import {
31
- doc,
32
- p,
33
- table,
34
- td,
35
- tr,
36
- } from '@atlaskit/editor-test-helpers/doc-builder';
37
-
38
- import tablePlugin from '../../../../plugin';
39
- import { pluginKey } from '../../../../pm-plugins/plugin-key';
40
- import { setResizeHandlePos } from '../../../../pm-plugins/table-resizing/commands';
41
-
42
- // We don't need to test if the analytics implementation works (tested elsewhere)
43
- // We just want to know if the action is called.
44
- const mockAttachPayload = jest.fn();
45
- const analyticsPluginFake = () => ({
46
- name: 'analytics',
47
- actions: {
48
- attachAnalyticsEvent: mockAttachPayload.mockImplementation(() => () => {}),
49
- },
50
- });
51
-
52
- describe('table-resizing/event-handlers', () => {
53
- let editor: any;
54
- beforeEach(() => {
55
- const createEditor = createProsemirrorEditorFactory();
56
- editor = (doc: DocBuilder) =>
57
- createEditor({
58
- doc,
59
- attachTo: document.body,
60
- preset: new Preset<LightEditorPlugin>()
61
- .add([featureFlagsPlugin, {}])
62
- .add([analyticsPluginFake as unknown as typeof analyticsPlugin, {}])
63
- .add(contentInsertionPlugin)
64
- .add(decorationsPlugin)
65
- .add(widthPlugin)
66
- .add(guidelinePlugin)
67
- .add(selectionPlugin)
68
- .add([
69
- tablePlugin,
70
- {
71
- tableOptions: { allowColumnResizing: true },
72
- },
73
- ]),
74
- pluginKey,
75
- });
76
- });
77
-
78
- describe('#handleMouseDown', () => {
79
- it('should dispatch analytics event on last column resizing attempt', async () => {
80
- const { editorView: view } = editor(
81
- doc(table()(tr(td()(p('1')), td()(p('2')), td()(p('3{<>}'))))),
82
- );
83
-
84
- resizeColumn(view, 12, 150, 250);
85
-
86
- expect(mockAttachPayload).toHaveBeenCalledWith(
87
- expect.objectContaining({
88
- action: TABLE_ACTION.ATTEMPTED_TABLE_WIDTH_CHANGE,
89
- actionSubject: ACTION_SUBJECT.TABLE,
90
- actionSubjectId: null,
91
- eventType: EVENT_TYPE.UI,
92
- attributes: expect.objectContaining({
93
- delta: 100,
94
- position: 'right',
95
- type: 'table-border',
96
- }),
97
- }),
98
- );
99
- });
100
-
101
- it('should shrink last column until table is no longer overflowing', async () => {
102
- const { editorView: view } = editor(
103
- doc(table()(tr(td()(p('1')), td()(p('2')), td()(p('3{<>}'))))),
104
- );
105
-
106
- // Increase column to overflow
107
- resizeColumn(view, 7, 50, 500);
108
-
109
- expect(getTotalTableWidth(view.state as EditorState)).toBeGreaterThan(
110
- akEditorFullPageMaxWidth,
111
- );
112
-
113
- resizeColumn(view, 12, 3000, 700);
114
-
115
- // No matter how large we try to resize the result should equal the width (within 1 pt)
116
- expect(getTotalTableWidth(view.state as EditorState)).toBeLessThanOrEqual(
117
- akEditorDefaultLayoutWidth,
118
- );
119
- expect(
120
- getTotalTableWidth(view.state as EditorState),
121
- ).toBeGreaterThanOrEqual(akEditorFullPageMaxWidth - 1);
122
- });
123
-
124
- it('should not resize the last column to grow', async () => {
125
- const { editorView: view } = editor(
126
- doc(table()(tr(td()(p('1')), td()(p('2')), td()(p('3{<>}'))))),
127
- );
128
-
129
- // Increase column to overflow
130
- resizeColumn(view, 7, 50, 500);
131
-
132
- const overflowingTableWidth = getTotalTableWidth(
133
- view.state as EditorState,
134
- );
135
- expect(overflowingTableWidth).toBeGreaterThan(akEditorFullPageMaxWidth);
136
-
137
- resizeColumn(view, 12, 400, 3000);
138
-
139
- // Width should be unchanged
140
- expect(getTotalTableWidth(view.state as EditorState)).toBe(
141
- overflowingTableWidth,
142
- );
143
- });
144
-
145
- it('should restore text selection after replacing the table', async () => {
146
- const { editorView: view } = editor(
147
- doc(table()(tr(td()(p('1')), td()(p('2')), td()(p('3{<>}'))))),
148
- );
149
-
150
- const currentSelection = view.state.tr.selection;
151
- expect(currentSelection instanceof TextSelection).toBeTruthy();
152
- expect(currentSelection.$cursor.pos).toBe(15);
153
-
154
- resizeColumn(view, 12, 150, 250);
155
-
156
- expect(currentSelection instanceof TextSelection).toBeTruthy();
157
- expect(currentSelection.$cursor.pos).toBe(15);
158
- });
159
- });
160
- });
161
-
162
- function getTotalTableWidth(state: EditorState) {
163
- let totalWidth = 0;
164
- state.doc.descendants((node) => {
165
- if (node.type.name === 'tableCell') {
166
- totalWidth += node.attrs.colwidth[0];
167
- return false;
168
- }
169
- return true;
170
- });
171
- return totalWidth;
172
- }
173
-
174
- function resizeColumn(
175
- view: EditorView,
176
- pos: number,
177
- start: number,
178
- end: number,
179
- ) {
180
- setResizeHandlePos(pos)(view.state, view.dispatch);
181
-
182
- const firstmousedownEvent = new MouseEvent('mousedown', {
183
- clientX: start,
184
- });
185
-
186
- view.dom.dispatchEvent(firstmousedownEvent);
187
-
188
- const firstmouseupEvent = new MouseEvent('mouseup', {
189
- clientX: end,
190
- });
191
- window.dispatchEvent(firstmouseupEvent);
192
- }
@@ -1,33 +0,0 @@
1
- import { updateColgroup } from '../../../../../pm-plugins/table-resizing/utils/resize-state';
2
- import type { ResizeState } from '../../../../../pm-plugins/table-resizing/utils/types';
3
-
4
- describe('table-resizing/utils/resize-state', () => {
5
- describe('#updateColgroup', () => {
6
- it('should not throw exception when the dom cols does not exist', () => {
7
- const state = {
8
- cols: [{ width: 100 }],
9
- };
10
- const tableRef = document.createElement('div');
11
-
12
- const func = () => {
13
- updateColgroup(state as ResizeState, tableRef);
14
- };
15
-
16
- expect(func).not.toThrow();
17
- });
18
-
19
- it('should not throw exception when the column is null', () => {
20
- const state = {
21
- cols: [null],
22
- };
23
- const tableRef = document.createElement('div');
24
-
25
- const func = () => {
26
- // @ts-ignore
27
- updateColgroup(state, tableRef);
28
- };
29
-
30
- expect(func).not.toThrow();
31
- });
32
- });
33
- });