@atlaskit/editor-plugin-table 7.2.2 → 7.2.3

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 (102) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  3. package/dist/cjs/utils/drag-menu.js +37 -23
  4. package/dist/cjs/utils/merged-cells.js +66 -1
  5. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  6. package/dist/es2019/utils/drag-menu.js +38 -14
  7. package/dist/es2019/utils/merged-cells.js +73 -0
  8. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  9. package/dist/esm/utils/drag-menu.js +36 -22
  10. package/dist/esm/utils/merged-cells.js +65 -0
  11. package/dist/types/utils/drag-menu.d.ts +4 -1
  12. package/dist/types/utils/merged-cells.d.ts +2 -0
  13. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  14. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  15. package/package.json +9 -16
  16. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  17. package/src/utils/drag-menu.ts +94 -20
  18. package/src/utils/merged-cells.ts +78 -0
  19. package/tsconfig.dev.json +0 -69
  20. package/tsconfig.json +2 -877
  21. package/examples/99-testing.tsx +0 -140
  22. package/examples/config.jsonc +0 -14
  23. package/src/__tests__/unit/analytics.ts +0 -888
  24. package/src/__tests__/unit/collab.ts +0 -93
  25. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  26. package/src/__tests__/unit/commands/insert.ts +0 -137
  27. package/src/__tests__/unit/commands/misc.ts +0 -185
  28. package/src/__tests__/unit/commands/sort.ts +0 -128
  29. package/src/__tests__/unit/commands.ts +0 -745
  30. package/src/__tests__/unit/copy-button.ts +0 -22
  31. package/src/__tests__/unit/copy-paste.ts +0 -677
  32. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  33. package/src/__tests__/unit/event-handlers.ts +0 -296
  34. package/src/__tests__/unit/fix-tables.ts +0 -164
  35. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  36. package/src/__tests__/unit/handlers.ts +0 -98
  37. package/src/__tests__/unit/hover-selection.ts +0 -230
  38. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  39. package/src/__tests__/unit/index.ts +0 -912
  40. package/src/__tests__/unit/layout.ts +0 -146
  41. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  42. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  43. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  44. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  45. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  46. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  47. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  48. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  49. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  50. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  51. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  52. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  53. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  54. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  55. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  56. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  57. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  58. package/src/__tests__/unit/sort-column.ts +0 -399
  59. package/src/__tests__/unit/toolbar.ts +0 -512
  60. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  61. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  62. package/src/__tests__/unit/transforms/merging.ts +0 -392
  63. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  64. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  65. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  66. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  67. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  68. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  69. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  70. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  71. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  72. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  73. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  74. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  75. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  76. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  77. package/src/__tests__/unit/undo-redo.ts +0 -220
  78. package/src/__tests__/unit/utils/analytics.ts +0 -98
  79. package/src/__tests__/unit/utils/collapse.ts +0 -57
  80. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  81. package/src/__tests__/unit/utils/dom.ts +0 -180
  82. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  83. package/src/__tests__/unit/utils/nodes.ts +0 -79
  84. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  85. package/src/__tests__/unit/utils/table.ts +0 -96
  86. package/src/__tests__/unit/utils.ts +0 -670
  87. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  88. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  89. 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
  90. 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
  91. 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
  92. 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
  93. 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
  94. 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
  95. 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
  96. 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
  97. 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
  98. 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
  99. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  100. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  101. package/src/__tests__/visual-regression/index.ts +0 -62
  102. package/src/__tests__/visual-regression/sticky-header.ts +0 -61
@@ -1,392 +0,0 @@
1
- import { uuid } from '@atlaskit/adf-schema';
2
- import type { DocBuilder } from '@atlaskit/editor-common/types';
3
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
4
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
6
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
7
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
8
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
9
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
10
- import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
11
- // eslint-disable-next-line import/no-extraneous-dependencies
12
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
13
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
14
- import {
15
- createProsemirrorEditorFactory,
16
- Preset,
17
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
18
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
19
- import {
20
- doc,
21
- p,
22
- table,
23
- td,
24
- tdEmpty,
25
- tr,
26
- } from '@atlaskit/editor-test-helpers/doc-builder';
27
-
28
- import tablePlugin from '../../../plugin';
29
- import { pluginKey } from '../../../pm-plugins/plugin-key';
30
- import { mergeCells } from '../../../transforms';
31
- import type { TablePluginState } from '../../../types';
32
-
33
- const TABLE_LOCAL_ID = 'test-table-local-id';
34
-
35
- describe('table plugin -> transforms -> merge cells', () => {
36
- beforeAll(() => {
37
- uuid.setStatic(TABLE_LOCAL_ID);
38
- });
39
-
40
- afterAll(() => {
41
- uuid.setStatic(false);
42
- });
43
-
44
- const createEditor = createProsemirrorEditorFactory();
45
- const preset = new Preset<LightEditorPlugin>()
46
- .add([featureFlagsPlugin, {}])
47
- .add([analyticsPlugin, {}])
48
- .add(contentInsertionPlugin)
49
- .add(widthPlugin)
50
- .add(guidelinePlugin)
51
- .add(selectionPlugin)
52
- .add(tablePlugin);
53
-
54
- const editor = (doc: DocBuilder) =>
55
- createEditor<TablePluginState, PluginKey, typeof preset>({
56
- doc,
57
- preset,
58
- pluginKey,
59
- });
60
-
61
- describe('#mergeCells', () => {
62
- it('should merge columns and rows', () => {
63
- const { editorView } = editor(
64
- doc(
65
- p('text'),
66
- table()(
67
- tr(td({})(p('{<cell}')), tdEmpty, tdEmpty),
68
- tr(tdEmpty, tdEmpty, tdEmpty),
69
- tr(tdEmpty, td({})(p('{cell>}')), tdEmpty),
70
- ),
71
- ),
72
- );
73
- const { state, dispatch } = editorView;
74
- dispatch(mergeCells(state.tr));
75
- expect(editorView.state.doc).toEqualDocument(
76
- doc(
77
- p('text'),
78
- table({ localId: TABLE_LOCAL_ID })(
79
- tr(td({ rowspan: 3 })(p('')), tdEmpty),
80
- tr(tdEmpty),
81
- tr(tdEmpty),
82
- ),
83
- ),
84
- );
85
- });
86
-
87
- describe('when two rows gets merged column by column', () => {
88
- describe('when last non-merged cell gets merged from the end of the row', () => {
89
- it('should delete an empty row that gets created as a result', () => {
90
- const { editorView } = editor(
91
- doc(
92
- p('text'),
93
- table()(
94
- tr(tdEmpty, tdEmpty, tdEmpty),
95
- tr(
96
- td({ rowspan: 2 })(p('b1')),
97
- td({ rowspan: 2 })(p('b2')),
98
- td({})(p('{<cell}b3')),
99
- ),
100
- tr(td({})(p('{cell>}c3'))),
101
- ),
102
- ),
103
- );
104
- const { state, dispatch } = editorView;
105
- dispatch(mergeCells(state.tr));
106
- expect(editorView.state.doc).toEqualDocument(
107
- doc(
108
- p('text'),
109
- table({ localId: TABLE_LOCAL_ID })(
110
- tr(tdEmpty, tdEmpty, tdEmpty),
111
- tr(td({})(p('b1')), td({})(p('b2')), td({})(p('b3'), p('c3'))),
112
- ),
113
- ),
114
- );
115
- });
116
- });
117
- describe('when last non-merged cell gets merged from the start of the row', () => {
118
- it('should delete an empty row that gets created as a result', () => {
119
- const { editorView } = editor(
120
- doc(
121
- p('text'),
122
- table()(
123
- tr(tdEmpty, tdEmpty, tdEmpty),
124
- tr(
125
- td({})(p('{<cell}b1')),
126
- td({ rowspan: 2 })(p('b2')),
127
- td({ rowspan: 2 })(p('b3')),
128
- ),
129
- tr(td({})(p('{cell>}c1'))),
130
- ),
131
- ),
132
- );
133
- const { state, dispatch } = editorView;
134
- dispatch(mergeCells(state.tr));
135
- expect(editorView.state.doc).toEqualDocument(
136
- doc(
137
- p('text'),
138
- table({ localId: TABLE_LOCAL_ID })(
139
- tr(tdEmpty, tdEmpty, tdEmpty),
140
- tr(td({})(p('b1'), p('c1')), td({})(p('b2')), td({})(p('b3'))),
141
- ),
142
- ),
143
- );
144
- });
145
- });
146
- });
147
-
148
- describe('when more than two rows gets merged', () => {
149
- describe('when last non-merged cell gets merged from the end of the row', () => {
150
- it('should delete an empty row that gets created as a result', () => {
151
- const { editorView } = editor(
152
- doc(
153
- p('text'),
154
- table()(
155
- tr(td({ rowspan: 4 })(p('a1')), td({})(p('{<cell}a2'))),
156
- tr(tdEmpty),
157
- tr(td({})(p('{cell>}c2'))),
158
- tr(tdEmpty),
159
- tr(tdEmpty, tdEmpty),
160
- ),
161
- ),
162
- );
163
- const { state, dispatch } = editorView;
164
- dispatch(mergeCells(state.tr));
165
- expect(editorView.state.doc).toEqualDocument(
166
- doc(
167
- p('text'),
168
- table({ localId: TABLE_LOCAL_ID })(
169
- tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'), p('c2'))),
170
- tr(tdEmpty),
171
- tr(tdEmpty, tdEmpty),
172
- ),
173
- ),
174
- );
175
- });
176
- });
177
- });
178
-
179
- describe('when rows from the first columns get merged', () => {
180
- describe('and table has merged rows in the next column', () => {
181
- it('should delete an empty row and decrement rowspan of the next column', () => {
182
- const { editorView } = editor(
183
- doc(
184
- p('text'),
185
- table()(
186
- tr(td({})(p('{<cell}a1')), td({ rowspan: 3 })(p('a2'))),
187
- tr(td({})(p('{cell>}'))),
188
- tr(tdEmpty),
189
- ),
190
- ),
191
- );
192
- const { state, dispatch } = editorView;
193
- dispatch(mergeCells(state.tr));
194
- expect(editorView.state.doc).toEqualDocument(
195
- doc(
196
- p('text'),
197
- table({ localId: TABLE_LOCAL_ID })(
198
- tr(td({})(p('a1')), td({ rowspan: 2 })(p('a2'))),
199
- tr(tdEmpty),
200
- ),
201
- ),
202
- );
203
- });
204
- });
205
- });
206
-
207
- describe('when rows from the last columns get merged', () => {
208
- describe('and table has merged rows in the previous column', () => {
209
- it('should delete an empty row and decrement rowspan of the previous column', () => {
210
- const { editorView } = editor(
211
- doc(
212
- p('text'),
213
- table()(
214
- tr(td({ rowspan: 3 })(p('a1')), td({})(p('{<cell}a2'))),
215
- tr(td({})(p('{cell>}'))),
216
- tr(tdEmpty),
217
- ),
218
- ),
219
- );
220
- const { state, dispatch } = editorView;
221
- dispatch(mergeCells(state.tr));
222
- expect(editorView.state.doc).toEqualDocument(
223
- doc(
224
- p('text'),
225
- table({ localId: TABLE_LOCAL_ID })(
226
- tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'))),
227
- tr(tdEmpty),
228
- ),
229
- ),
230
- );
231
- });
232
- });
233
- });
234
-
235
- describe('when two empty cells are merged', () => {
236
- it('should fill the merged cell with a paragraph', () => {
237
- const { editorView } = editor(
238
- doc(
239
- p('text'),
240
- table()(
241
- tr(td({})(p('{<cell}')), td({})(p('{cell>}'))),
242
- tr(tdEmpty, tdEmpty),
243
- ),
244
- ),
245
- );
246
- const { state, dispatch } = editorView;
247
- dispatch(mergeCells(state.tr));
248
- expect(editorView.state.doc).toEqualDocument(
249
- doc(
250
- p('text'),
251
- table({ localId: TABLE_LOCAL_ID })(
252
- tr(td({ colspan: 2 })(p(''))),
253
- tr(tdEmpty, tdEmpty),
254
- ),
255
- ),
256
- );
257
- });
258
- });
259
-
260
- describe('when next column is invisible', () => {
261
- it('should decrement colspans of the preceeding column', () => {
262
- const { editorView } = editor(
263
- doc(
264
- p('text'),
265
- table()(
266
- tr(tdEmpty, td({})(p('{<cell}')), tdEmpty, td({})(p('{cell>}'))),
267
- tr(tdEmpty, td({ colspan: 3 })(p(''))),
268
- tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
269
- ),
270
- ),
271
- );
272
- const { state, dispatch } = editorView;
273
- dispatch(mergeCells(state.tr));
274
- expect(editorView.state.doc).toEqualDocument(
275
- doc(
276
- p('text'),
277
- table({ localId: TABLE_LOCAL_ID })(
278
- tr(tdEmpty, td({ colspan: 2 })(p(''))),
279
- tr(tdEmpty, td({ colspan: 2 })(p(''))),
280
- tr(tdEmpty, tdEmpty, tdEmpty),
281
- ),
282
- ),
283
- );
284
- });
285
- });
286
-
287
- describe('when next column is not invisible', () => {
288
- it('should not decrement colspans of the preceeding column', () => {
289
- const { editorView } = editor(
290
- doc(
291
- p('text'),
292
- table()(
293
- tr(tdEmpty, td({})(p('{<cell}')), tdEmpty, td({})(p('{cell>}'))),
294
- tr(tdEmpty, td({ colspan: 3 })(p(''))),
295
- tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
296
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
297
- ),
298
- ),
299
- );
300
- const { state, dispatch } = editorView;
301
- dispatch(mergeCells(state.tr));
302
- expect(editorView.state.doc).toEqualDocument(
303
- doc(
304
- p('text'),
305
- table({ localId: TABLE_LOCAL_ID })(
306
- tr(tdEmpty, td({ colspan: 3 })(p(''))),
307
- tr(tdEmpty, td({ colspan: 3 })(p(''))),
308
- tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
309
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
310
- ),
311
- ),
312
- );
313
- });
314
- });
315
-
316
- describe('when empty cells and cells with content are merged together', () => {
317
- it('should copy content from merged cells dropping empty cells', () => {
318
- const { editorView } = editor(
319
- doc(
320
- p('text'),
321
- table()(
322
- tr(td({})(p('1')), td({})(p('2'))),
323
- tr(td({ colspan: 2 })(p('{<cell}'))),
324
- tr(td({})(p('1')), td({})(p('2{cell>}'))),
325
- ),
326
- ),
327
- );
328
- const { state, dispatch } = editorView;
329
- dispatch(mergeCells(state.tr));
330
- expect(editorView.state.doc).toEqualDocument(
331
- doc(
332
- p('text'),
333
- table({ localId: TABLE_LOCAL_ID })(
334
- tr(td({})(p('1')), td({})(p('2'))),
335
- tr(td({ colspan: 2 })(p('1'), p('2'))),
336
- ),
337
- ),
338
- );
339
- });
340
- });
341
-
342
- describe('when table has columns where all cells have colspan > 1', () => {
343
- it('should delete an empty column', () => {
344
- const { editorView } = editor(
345
- doc(
346
- p('text'),
347
- table()(
348
- tr(
349
- td({})(p('1')),
350
- td({})(p('2')),
351
- td({ colspan: 2, rowspan: 2 })(p('3')),
352
- td({})(p('5')),
353
- td({})(p('6')),
354
- ),
355
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
356
- tr(
357
- td({})(p('1')),
358
- td({})(p('{<cell}2')),
359
- td({})(p('3')),
360
- td({})(p('4')),
361
- td({})(p('5{cell>}')),
362
- td({})(p('6')),
363
- ),
364
- ),
365
- ),
366
- );
367
- const { state, dispatch } = editorView;
368
- dispatch(mergeCells(state.tr));
369
- expect(editorView.state.doc).toEqualDocument(
370
- doc(
371
- p('text'),
372
- table({ localId: TABLE_LOCAL_ID })(
373
- tr(
374
- td({})(p('1')),
375
- td({})(p('2')),
376
- td({ rowspan: 2 })(p('3')),
377
- td({})(p('5')),
378
- td({})(p('6')),
379
- ),
380
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
381
- tr(
382
- td({})(p('1')),
383
- td({ colspan: 3 })(p('2'), p('3'), p('4'), p('5')),
384
- td({})(p('6')),
385
- ),
386
- ),
387
- ),
388
- );
389
- });
390
- });
391
- });
392
- });
@@ -1,71 +0,0 @@
1
- import React from 'react';
2
-
3
- import { render, screen } from '@testing-library/react';
4
- import { createIntl } from 'react-intl-next';
5
-
6
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
7
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
8
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
9
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
10
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
11
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
12
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
13
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
14
- // eslint-disable-next-line import/no-extraneous-dependencies
15
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
16
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
17
- import {
18
- createProsemirrorEditorFactory,
19
- Preset,
20
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
21
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
22
- import {
23
- doc,
24
- p,
25
- table,
26
- tdCursor,
27
- tdEmpty,
28
- th,
29
- tr,
30
- } from '@atlaskit/editor-test-helpers/doc-builder';
31
-
32
- import tablePlugin from '../../../plugin';
33
- import { ContextualMenu } from '../../../ui/FloatingContextualMenu/ContextualMenu';
34
-
35
- describe('ContextualMenu', () => {
36
- const getEditorContainerWidth = () => ({ width: 500 });
37
- const createEditor = createProsemirrorEditorFactory();
38
- describe('with right table cell position in plugin state', () => {
39
- let editorView: EditorView;
40
- beforeEach(() => {
41
- ({ editorView } = createEditor({
42
- doc: doc(table()(tr(th()(p('')), th()(p(''))), tr(tdCursor, tdEmpty))),
43
- preset: new Preset<LightEditorPlugin>()
44
- .add([featureFlagsPlugin, {}])
45
- .add([analyticsPlugin, {}])
46
- .add(contentInsertionPlugin)
47
- .add(widthPlugin)
48
- .add(guidelinePlugin)
49
- .add(selectionPlugin)
50
- .add([tablePlugin, { tableOptions: { advanced: true } }]),
51
- }));
52
- });
53
-
54
- it('should render contextual menu when no tableCellPosition is passed but exist on editor state ', () => {
55
- const intl = createIntl({ locale: 'en' });
56
- render(
57
- <ContextualMenu
58
- intl={intl}
59
- editorView={editorView}
60
- isOpen
61
- selectionRect={{ bottom: 0, left: 0, right: 0, top: 0 }}
62
- getEditorContainerWidth={getEditorContainerWidth}
63
- />,
64
- );
65
-
66
- expect(
67
- screen.getByTestId('table-cell-contextual-menu'),
68
- ).toBeInTheDocument();
69
- });
70
- });
71
- });
@@ -1,99 +0,0 @@
1
- import React from 'react';
2
-
3
- import { fireEvent, render, screen } from '@testing-library/react';
4
- import { IntlProvider } from 'react-intl-next';
5
-
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 { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
9
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
10
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
11
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
12
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
13
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
14
- import { isTableSelected } from '@atlaskit/editor-tables/utils';
15
- // eslint-disable-next-line import/no-extraneous-dependencies
16
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
17
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
18
- import {
19
- createProsemirrorEditorFactory,
20
- Preset,
21
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
22
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
23
- import {
24
- doc,
25
- table,
26
- thEmpty,
27
- tr,
28
- } from '@atlaskit/editor-test-helpers/doc-builder';
29
-
30
- import tablePlugin from '../../../plugin';
31
- import { getPluginState } from '../../../pm-plugins/plugin-factory';
32
- import { pluginKey } from '../../../pm-plugins/plugin-key';
33
- import { CornerControls } from '../../../ui/TableFloatingControls/CornerControls';
34
-
35
- describe('CornerControls', () => {
36
- const createEditor = createProsemirrorEditorFactory();
37
-
38
- const editor = (doc: DocBuilder) =>
39
- createEditor({
40
- doc,
41
- preset: new Preset<LightEditorPlugin>()
42
- .add([featureFlagsPlugin, {}])
43
- .add([analyticsPlugin, {}])
44
- .add(contentInsertionPlugin)
45
- .add(widthPlugin)
46
- .add(guidelinePlugin)
47
- .add(selectionPlugin)
48
- .add(tablePlugin),
49
- pluginKey,
50
- });
51
-
52
- describe('when button is clicked', () => {
53
- it('should select the table', () => {
54
- const { editorView } = editor(
55
- doc(table()(tr(thEmpty, thEmpty, thEmpty))),
56
- );
57
-
58
- const ref = editorView.dom.querySelector('table') || undefined;
59
-
60
- render(
61
- <IntlProvider locale="en">
62
- <CornerControls tableRef={ref} editorView={editorView} />
63
- </IntlProvider>,
64
- );
65
-
66
- const cornerControl = screen.getByLabelText('Highlight table');
67
-
68
- fireEvent.click(cornerControl);
69
-
70
- expect(isTableSelected(editorView.state.selection)).toBe(true);
71
- });
72
- });
73
-
74
- describe('when button is hovered', () => {
75
- it('should highlight the table with hover decoration', () => {
76
- const { editorView } = editor(
77
- doc(
78
- table()(tr(thEmpty, thEmpty, thEmpty), tr(thEmpty, thEmpty, thEmpty)),
79
- ),
80
- );
81
-
82
- const ref = editorView.dom.querySelector('table') || undefined;
83
-
84
- render(
85
- <IntlProvider locale="en">
86
- <CornerControls tableRef={ref} editorView={editorView} />
87
- </IntlProvider>,
88
- );
89
-
90
- const cornerControl = screen.getByLabelText('Highlight table');
91
-
92
- fireEvent.mouseOver(cornerControl);
93
-
94
- const { hoveredColumns, hoveredRows } = getPluginState(editorView.state);
95
- expect(hoveredColumns).toEqual([0, 1, 2]);
96
- expect(hoveredRows).toEqual([0, 1]);
97
- });
98
- });
99
- });
@@ -1,38 +0,0 @@
1
- import React from 'react';
2
-
3
- import { fireEvent, render, screen } from '@testing-library/react';
4
- import { IntlProvider } from 'react-intl-next';
5
-
6
- import { tableMessages as messages } from '@atlaskit/editor-common/messages';
7
-
8
- import DeleteButton from '../../../ui/FloatingDeleteButton/DeleteButton';
9
-
10
- describe('<DeleteButton />', () => {
11
- it('should fire the onMouseEnter callback', () => {
12
- const onMouseEnter = jest.fn();
13
- render(
14
- <IntlProvider locale="en">
15
- <DeleteButton
16
- removeLabel={messages.removeColumns}
17
- onMouseEnter={onMouseEnter}
18
- />
19
- </IntlProvider>,
20
- );
21
- fireEvent.mouseEnter(screen.getByLabelText('Delete column'));
22
- expect(onMouseEnter).toHaveBeenCalled();
23
- });
24
-
25
- it('should fire the onMouseLeave callback', () => {
26
- const onMouseLeave = jest.fn();
27
- render(
28
- <IntlProvider locale="en">
29
- <DeleteButton
30
- removeLabel={messages.removeColumns}
31
- onMouseLeave={onMouseLeave}
32
- />
33
- </IntlProvider>,
34
- );
35
- fireEvent.mouseLeave(screen.getByLabelText('Delete column'));
36
- expect(onMouseLeave).toHaveBeenCalled();
37
- });
38
- });