@atlaskit/editor-plugin-table 7.2.1 → 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 (124) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +11 -7
  3. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  4. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +11 -25
  5. package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +13 -3
  6. package/dist/cjs/ui/TableFloatingColumnControls/index.js +7 -3
  7. package/dist/cjs/utils/drag-menu.js +37 -23
  8. package/dist/cjs/utils/merged-cells.js +66 -1
  9. package/dist/es2019/nodeviews/TableComponent.js +9 -5
  10. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  11. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
  12. package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
  13. package/dist/es2019/ui/TableFloatingColumnControls/index.js +7 -3
  14. package/dist/es2019/utils/drag-menu.js +38 -14
  15. package/dist/es2019/utils/merged-cells.js +73 -0
  16. package/dist/esm/nodeviews/TableComponent.js +11 -7
  17. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  18. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
  19. package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
  20. package/dist/esm/ui/TableFloatingColumnControls/index.js +7 -3
  21. package/dist/esm/utils/drag-menu.js +36 -22
  22. package/dist/esm/utils/merged-cells.js +65 -0
  23. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  24. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
  25. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +1 -0
  26. package/dist/types/utils/drag-menu.d.ts +4 -1
  27. package/dist/types/utils/merged-cells.d.ts +2 -0
  28. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  29. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
  30. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +1 -0
  31. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  32. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  33. package/package.json +9 -16
  34. package/src/nodeviews/TableComponent.tsx +1 -0
  35. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  36. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +6 -27
  37. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -1
  38. package/src/ui/TableFloatingColumnControls/index.tsx +5 -0
  39. package/src/utils/drag-menu.ts +94 -20
  40. package/src/utils/merged-cells.ts +78 -0
  41. package/tsconfig.dev.json +0 -69
  42. package/tsconfig.json +2 -871
  43. package/examples/99-testing.tsx +0 -140
  44. package/examples/config.jsonc +0 -14
  45. package/src/__tests__/unit/analytics.ts +0 -888
  46. package/src/__tests__/unit/collab.ts +0 -93
  47. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  48. package/src/__tests__/unit/commands/insert.ts +0 -137
  49. package/src/__tests__/unit/commands/misc.ts +0 -185
  50. package/src/__tests__/unit/commands/sort.ts +0 -128
  51. package/src/__tests__/unit/commands.ts +0 -745
  52. package/src/__tests__/unit/copy-button.ts +0 -22
  53. package/src/__tests__/unit/copy-paste.ts +0 -677
  54. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  55. package/src/__tests__/unit/event-handlers.ts +0 -296
  56. package/src/__tests__/unit/fix-tables.ts +0 -164
  57. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  58. package/src/__tests__/unit/handlers.ts +0 -98
  59. package/src/__tests__/unit/hover-selection.ts +0 -230
  60. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  61. package/src/__tests__/unit/index.ts +0 -912
  62. package/src/__tests__/unit/layout.ts +0 -146
  63. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  64. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  65. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  66. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  67. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  68. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  69. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  70. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  71. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  72. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  73. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  74. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  75. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  76. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  77. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  78. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  79. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  80. package/src/__tests__/unit/sort-column.ts +0 -399
  81. package/src/__tests__/unit/toolbar.ts +0 -512
  82. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  83. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  84. package/src/__tests__/unit/transforms/merging.ts +0 -392
  85. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  86. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  87. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  88. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  89. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  90. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  91. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  92. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  93. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  94. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  95. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  96. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  97. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  98. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  99. package/src/__tests__/unit/undo-redo.ts +0 -220
  100. package/src/__tests__/unit/utils/analytics.ts +0 -98
  101. package/src/__tests__/unit/utils/collapse.ts +0 -57
  102. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  103. package/src/__tests__/unit/utils/dom.ts +0 -180
  104. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  105. package/src/__tests__/unit/utils/nodes.ts +0 -79
  106. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  107. package/src/__tests__/unit/utils/table.ts +0 -96
  108. package/src/__tests__/unit/utils.ts +0 -670
  109. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  110. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  111. 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
  112. 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
  113. 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
  114. 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
  115. 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
  116. 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
  117. 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
  118. 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
  119. 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
  120. 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
  121. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  122. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  123. package/src/__tests__/visual-regression/index.ts +0 -62
  124. package/src/__tests__/visual-regression/sticky-header.ts +0 -61
@@ -1,294 +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
- import { setTextSelection } from '@atlaskit/editor-common/utils';
8
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
9
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
10
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
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 { getSelectionRect, selectRow } from '@atlaskit/editor-tables/utils';
16
- // eslint-disable-next-line import/no-extraneous-dependencies
17
- import type { LightEditorPlugin } 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
- createProsemirrorEditorFactory,
21
- Preset,
22
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
23
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
24
- import {
25
- doc,
26
- p,
27
- table,
28
- td,
29
- tdCursor,
30
- tdEmpty,
31
- thEmpty,
32
- tr,
33
- } from '@atlaskit/editor-test-helpers/doc-builder';
34
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
35
- import { selectRows } from '@atlaskit/editor-test-helpers/table';
36
-
37
- import { hoverRows } from '../../../commands';
38
- import tablePlugin from '../../../plugin';
39
- import { pluginKey } from '../../../pm-plugins/plugin-key';
40
- import TableFloatingControls from '../../../ui/TableFloatingControls';
41
- import { RowControls } from '../../../ui/TableFloatingControls/RowControls';
42
-
43
- describe('RowControls', () => {
44
- const createEditor = createProsemirrorEditorFactory();
45
- let originalResizeObserver: any;
46
-
47
- beforeAll(() => {
48
- originalResizeObserver = (window as any).ResizeObserver;
49
- (window as any).ResizeObserver = function resizeObserverMock(
50
- callback: () => {},
51
- ) {
52
- this.disconnect = jest.fn();
53
- this.observe = jest.fn();
54
- this.unobserve = jest.fn();
55
- };
56
- });
57
-
58
- afterAll(() => {
59
- (window as any).ResizeObserver = originalResizeObserver;
60
- });
61
-
62
- afterEach(() => {
63
- jest.clearAllMocks();
64
- });
65
-
66
- const editor = (doc: DocBuilder) => {
67
- return createEditor({
68
- doc,
69
- preset: new Preset<LightEditorPlugin>()
70
- .add([featureFlagsPlugin, {}])
71
- .add([analyticsPlugin, {}])
72
- .add(contentInsertionPlugin)
73
- .add(widthPlugin)
74
- .add(guidelinePlugin)
75
- .add(selectionPlugin)
76
- .add(tablePlugin),
77
- pluginKey,
78
- });
79
- };
80
-
81
- [1, 2, 3].forEach((row) => {
82
- describe(`when table has ${row} rows`, () => {
83
- it(`should render ${row} row header buttons`, () => {
84
- const rows = [tr(tdCursor)];
85
- for (let i = 1; i < row; i++) {
86
- rows.push(tr(tdEmpty));
87
- }
88
- const { editorView } = editor(doc(p('text'), table()(...rows)));
89
- const ref = editorView.dom.querySelector('table') || undefined;
90
-
91
- render(
92
- <IntlProvider locale="en">
93
- <TableFloatingControls
94
- tableRef={ref}
95
- tableActive
96
- editorView={editorView}
97
- isDragAndDropEnabled={false}
98
- selection={editorView.state.selection}
99
- />
100
- </IntlProvider>,
101
- );
102
-
103
- const rowControlButtons = screen.getAllByLabelText('Highlight row');
104
-
105
- expect(rowControlButtons).toHaveLength(row);
106
- });
107
- });
108
- });
109
-
110
- it('does not render rowControls if table is not active', () => {
111
- const { editorView } = editor(doc(p('text'), table()(tr(tdCursor))));
112
- const ref = editorView.dom.querySelector('table') || undefined;
113
-
114
- render(
115
- <IntlProvider locale="en">
116
- <TableFloatingControls
117
- tableRef={ref}
118
- tableActive={false}
119
- editorView={editorView}
120
- />
121
- </IntlProvider>,
122
- );
123
-
124
- expect(screen.queryByLabelText('Highlight row')).toBeFalsy();
125
- });
126
-
127
- [0, 1, 2].forEach((row) => {
128
- describe(`when HeaderButton in row ${row + 1} is clicked`, () => {
129
- it('should not move the cursor when hovering controls', () => {
130
- const { editorView, refs } = editor(
131
- doc(
132
- table()(
133
- tr(thEmpty, td({})(p('{nextPos}')), thEmpty),
134
- tr(tdCursor, tdEmpty, tdEmpty),
135
- tr(tdEmpty, tdEmpty, tdEmpty),
136
- ),
137
- ),
138
- );
139
-
140
- const ref = editorView.dom.querySelector('table') || undefined;
141
-
142
- render(
143
- <IntlProvider locale="en">
144
- <TableFloatingControls
145
- tableRef={ref}
146
- tableActive
147
- editorView={editorView}
148
- isDragAndDropEnabled={false}
149
- selection={editorView.state.selection}
150
- />
151
- </IntlProvider>,
152
- );
153
-
154
- // move to header row
155
- const { nextPos } = refs;
156
- setTextSelection(editorView, nextPos);
157
-
158
- // now hover the row
159
- const rowControls = screen.getAllByLabelText('Highlight row');
160
-
161
- fireEvent.mouseOver(rowControls[row]);
162
-
163
- // assert the cursor is still in same position
164
- expect(editorView.state.selection.$from.pos).toBe(nextPos);
165
- expect(editorView.state.selection.$to.pos).toBe(nextPos);
166
-
167
- // release the hover
168
- fireEvent.mouseOut(rowControls[row]);
169
-
170
- // assert the cursor is still in same position
171
- expect(editorView.state.selection.$from.pos).toBe(nextPos);
172
- expect(editorView.state.selection.$to.pos).toBe(nextPos);
173
- });
174
- });
175
- });
176
-
177
- it('applies the danger class to the row buttons', () => {
178
- const { editorView } = editor(
179
- doc(
180
- table()(
181
- tr(thEmpty, td({})(p()), thEmpty),
182
- tr(tdCursor, tdEmpty, tdEmpty),
183
- tr(tdEmpty, tdEmpty, tdEmpty),
184
- ),
185
- ),
186
- );
187
-
188
- const ref = editorView.dom.querySelector('table') || undefined;
189
-
190
- render(
191
- <IntlProvider locale="en">
192
- <RowControls
193
- tableRef={ref!}
194
- editorView={editorView}
195
- hoverRows={(rows, danger) => {
196
- hoverRows(rows, danger)(editorView.state, editorView.dispatch);
197
- }}
198
- hoveredRows={[0, 1]}
199
- isInDanger={true}
200
- selectRow={(row) => {
201
- editorView.dispatch(selectRow(row)(editorView.state.tr));
202
- }}
203
- />
204
- </IntlProvider>,
205
- );
206
-
207
- const rowControls = screen.getAllByLabelText('Highlight row');
208
- rowControls
209
- .slice(0, 2)
210
- .forEach((control) =>
211
- expect(
212
- control?.parentElement?.classList?.contains('danger'),
213
- ).toBeTruthy(),
214
- );
215
- });
216
-
217
- describe('row shift selection', () => {
218
- it('should be able to shift + click to select rows after the currently selected row', () => {
219
- const { editorView } = editor(
220
- doc(
221
- table()(
222
- tr(thEmpty, thEmpty, thEmpty),
223
- tr(tdEmpty, tdEmpty, tdEmpty),
224
- tr(tdEmpty, tdEmpty, tdEmpty),
225
- tr(tdEmpty, tdEmpty, tdEmpty),
226
- ),
227
- ),
228
- );
229
-
230
- selectRows([0])(editorView.state, editorView.dispatch);
231
-
232
- const ref = editorView.dom.querySelector('table');
233
-
234
- render(
235
- <IntlProvider locale="en">
236
- <RowControls
237
- tableRef={ref!}
238
- editorView={editorView}
239
- hoverRows={(rows, danger) => {
240
- hoverRows(rows, danger)(editorView.state, editorView.dispatch);
241
- }}
242
- selectRow={(row, expand) => {
243
- editorView.dispatch(selectRow(row, expand)(editorView.state.tr));
244
- }}
245
- />
246
- </IntlProvider>,
247
- );
248
-
249
- const rowControls = screen.getAllByLabelText('Highlight row');
250
- fireEvent.click(rowControls[2], { shiftKey: true });
251
-
252
- const rect = getSelectionRect(editorView.state.selection);
253
- expect(rect).toEqual({ left: 0, top: 0, right: 3, bottom: 3 });
254
- });
255
-
256
- it('should be able to shift + click to select rows before the currently selected row', () => {
257
- const { editorView } = editor(
258
- doc(
259
- table()(
260
- tr(thEmpty, thEmpty, thEmpty),
261
- tr(tdEmpty, tdEmpty, tdEmpty),
262
- tr(tdEmpty, tdEmpty, tdEmpty),
263
- tr(tdEmpty, tdEmpty, tdEmpty),
264
- ),
265
- ),
266
- );
267
-
268
- selectRows([2])(editorView.state, editorView.dispatch);
269
-
270
- const ref = editorView.dom.querySelector('table') || undefined;
271
-
272
- render(
273
- <IntlProvider locale="en">
274
- <RowControls
275
- tableRef={ref!}
276
- editorView={editorView}
277
- hoverRows={(rows, danger) => {
278
- hoverRows(rows, danger)(editorView.state, editorView.dispatch);
279
- }}
280
- selectRow={(row, expand) => {
281
- editorView.dispatch(selectRow(row, expand)(editorView.state.tr));
282
- }}
283
- />
284
- </IntlProvider>,
285
- );
286
-
287
- const rowControls = screen.getAllByLabelText('Highlight row');
288
- fireEvent.click(rowControls[0], { shiftKey: true });
289
-
290
- const rect = getSelectionRect(editorView.state.selection);
291
- expect(rect).toEqual({ left: 0, top: 0, right: 3, bottom: 3 });
292
- });
293
- });
294
- });
@@ -1,129 +0,0 @@
1
- import React from 'react';
2
-
3
- import { 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
- // 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
- td,
27
- tdEmpty,
28
- tr,
29
- } from '@atlaskit/editor-test-helpers/doc-builder';
30
-
31
- import tablePlugin from '../../../plugin';
32
- import { pluginKey } from '../../../pm-plugins/plugin-key';
33
- import { DragControls } from '../../../ui/TableFloatingControls/RowControls';
34
-
35
- describe('RowDragControls', () => {
36
- const createEditor = createProsemirrorEditorFactory();
37
-
38
- const editor = (doc: DocBuilder, tableOptions = {}) =>
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, { tableOptions, dragAndDropEnabled: true }]),
49
- pluginKey: pluginKey,
50
- });
51
-
52
- it('should only render one child container if hovered cell provided', () => {
53
- const { editorView } = editor(
54
- doc(
55
- p('text'),
56
- table()(
57
- tr(tdEmpty, tdEmpty, tdEmpty),
58
- tr(tdEmpty, tdEmpty, tdEmpty),
59
- tr(td({})(p('\n\n\n\n\n')), tdEmpty, tdEmpty),
60
- ),
61
- ),
62
- {},
63
- );
64
- const ref = editorView.dom.querySelector('table');
65
-
66
- render(
67
- <IntlProvider locale="en">
68
- <DragControls
69
- tableRef={ref!}
70
- tableActive
71
- editorView={editorView}
72
- hoveredCell={{ rowIndex: 1, colIndex: 1 }}
73
- isTableHovered={true}
74
- hoverRows={jest.fn()}
75
- selectRow={jest.fn()}
76
- selectRows={jest.fn()}
77
- updateCellHoverLocation={jest.fn()}
78
- tableWidth={760}
79
- />
80
- </IntlProvider>,
81
- );
82
-
83
- const dragHandle = screen.getAllByTestId(
84
- /^table-floating-row-\d-drag-handle$/,
85
- );
86
-
87
- expect(dragHandle.length).toBe(1);
88
- });
89
-
90
- it('should not render any drag handle containers if hoveredCell is undefined', () => {
91
- const { editorView } = editor(
92
- doc(
93
- p('text'),
94
- table()(
95
- tr(tdEmpty, tdEmpty, tdEmpty),
96
- tr(tdEmpty, tdEmpty, tdEmpty),
97
- tr(td({})(p('\n\n\n\n\n')), tdEmpty, tdEmpty),
98
- ),
99
- ),
100
- { dragAndDropEnabled: true },
101
- );
102
- const ref = editorView.dom.querySelector('table');
103
-
104
- render(
105
- <IntlProvider locale="en">
106
- <DragControls
107
- tableRef={ref!}
108
- tableActive
109
- editorView={editorView}
110
- hoveredCell={{
111
- colIndex: undefined,
112
- rowIndex: undefined,
113
- }}
114
- hoverRows={jest.fn()}
115
- selectRow={jest.fn()}
116
- selectRows={jest.fn()}
117
- updateCellHoverLocation={jest.fn()}
118
- tableWidth={760}
119
- />
120
- </IntlProvider>,
121
- );
122
-
123
- const dragHandle = screen.queryAllByTestId(
124
- /^table-floating-row-\d-drag-handle$/,
125
- );
126
-
127
- expect(dragHandle.length).toBe(0);
128
- });
129
- });
@@ -1,189 +0,0 @@
1
- import React from 'react';
2
-
3
- import { fireEvent } from '@testing-library/dom';
4
- import { render, screen } from '@testing-library/react';
5
- import { IntlProvider } from 'react-intl-next';
6
-
7
- import type { DocBuilder, Refs } from '@atlaskit/editor-common/types';
8
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
9
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
10
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
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 { PluginKey } from '@atlaskit/editor-prosemirror/state';
16
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
17
- // eslint-disable-next-line import/no-extraneous-dependencies
18
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
19
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
20
- import {
21
- createProsemirrorEditorFactory,
22
- Preset,
23
- } 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
- doc,
27
- p,
28
- table,
29
- tdEmpty,
30
- tr,
31
- } from '@atlaskit/editor-test-helpers/doc-builder';
32
-
33
- import tablePlugin from '../../../plugin';
34
- import { pluginKey } from '../../../pm-plugins/plugin-key';
35
- import type { TablePluginState } from '../../../types';
36
- import TableFloatingColumnControls from '../../../ui/TableFloatingColumnControls';
37
-
38
- describe('TableFloatingColumnControls', () => {
39
- const createEditor = createProsemirrorEditorFactory();
40
- const fakeGetEditorFeatureFlags = () => ({});
41
- const editor = (
42
- doc: DocBuilder,
43
- options?: {
44
- dragAndDropEnabled?: boolean;
45
- },
46
- ) => {
47
- const preset = new Preset<LightEditorPlugin>()
48
- .add([featureFlagsPlugin, {}])
49
- .add([analyticsPlugin, {}])
50
- .add(contentInsertionPlugin)
51
- .add(widthPlugin)
52
- .add(guidelinePlugin)
53
- .add(selectionPlugin)
54
- .add([tablePlugin, { ...options, tableOptions: {} }]);
55
- return createEditor<TablePluginState, PluginKey, typeof preset>({
56
- doc,
57
- preset,
58
- pluginKey: pluginKey,
59
- });
60
- };
61
-
62
- const getNodeFunc = (view: EditorView, refs: Refs) => () =>
63
- view.state.doc.nodeAt(refs['<node>'])!;
64
-
65
- afterEach(async () => {
66
- // cleanup any pending drags
67
- fireEvent.dragEnd(window);
68
- // Optional: unwind a post-drop browser bug fix
69
- // tick forward a micro task to flush a post-drag bug fix
70
- await 1;
71
- // this will trigger the fix to be released
72
- fireEvent.pointerMove(window);
73
- });
74
-
75
- it('should not render floating column controls when tableRef undefined and drag and drop is not enabled', () => {
76
- const { editorView, refs } = editor(
77
- doc(p('text'), '{<node>}', table()(tr(tdEmpty, tdEmpty, tdEmpty))),
78
- );
79
-
80
- const { container } = render(
81
- <TableFloatingColumnControls
82
- editorView={editorView}
83
- getNode={getNodeFunc(editorView, refs)}
84
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
85
- />,
86
- );
87
- expect(container.innerHTML).toEqual('');
88
- });
89
-
90
- it('should not render floating column controls when tableRef undefined and drag and drop is enabled', () => {
91
- const { editorView, refs } = editor(
92
- doc(p('text'), '{<node>}', table()(tr(tdEmpty, tdEmpty, tdEmpty))),
93
- {
94
- dragAndDropEnabled: true,
95
- },
96
- );
97
- const { container } = render(
98
- <TableFloatingColumnControls
99
- editorView={editorView}
100
- getNode={getNodeFunc(editorView, refs)}
101
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
102
- />,
103
- );
104
- expect(container.innerHTML).toEqual('');
105
- });
106
-
107
- it.todo('should not render drop target when no drag is active');
108
-
109
- it.todo(
110
- 'should render a drop target per column when dragging' /*, () => {
111
- const { editorView, refs } = editor(
112
- doc(
113
- p('text'),
114
- '{<node>}',
115
- table()(tr(tdEmpty, tdCursor, tdEmpty, tdEmpty, tdEmpty)),
116
- ),
117
- {
118
- dragAndDropEnabled: true,
119
- },
120
- );
121
- const ref = editorView.dom.querySelector('table') || undefined;
122
-
123
- render(
124
- <IntlProvider locale="en">
125
- <TableFloatingColumnControls
126
- getNode={getNodeFunc(editorView, refs)}
127
- tableRef={ref}
128
- tableActive={true}
129
- hoveredCell={{ colIndex: 1, rowIndex: 0}}
130
- editorView={editorView}
131
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
132
- />
133
- </IntlProvider>,
134
- );
135
-
136
- screen.debug();
137
-
138
- const dragHandle = screen.getByTestId(
139
- 'table-floating-column-controls-drag-handle',
140
- );
141
-
142
- fireEvent.dragStart(dragHandle);
143
-
144
- // ticking forward an animation frame will complete the lift
145
- // @ts-expect-error
146
- requestAnimationFrame.step();
147
-
148
- const dropTargets = screen.getAllByTestId(
149
- 'table-floating-column-controls-drop-target',
150
- );
151
-
152
- expect(dropTargets).toHaveLength(5);
153
- }*/,
154
- );
155
-
156
- // FIXME and unskp: presumably doesn't work becuase TableFloatingColumnControls are now mounted via ReactDOM.createPortal
157
- it.skip('should render a drop target per column regardless of row count', () => {
158
- const { editorView, refs } = editor(
159
- doc(
160
- p('text'),
161
- '{<node>}',
162
- table()(tr(tdEmpty), tr(tdEmpty), tr(tdEmpty)),
163
- ),
164
- {
165
- dragAndDropEnabled: true,
166
- },
167
- );
168
- const ref = editorView.dom.querySelector('table') || undefined;
169
-
170
- render(
171
- <IntlProvider locale="en">
172
- <TableFloatingColumnControls
173
- getNode={getNodeFunc(editorView, refs)}
174
- tableRef={ref}
175
- tableActive={true}
176
- editorView={editorView}
177
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
178
- />
179
- </IntlProvider>,
180
- );
181
-
182
- const dropTargets = screen.getAllByTestId(
183
- 'table-floating-column-controls-drop-target',
184
- );
185
- expect(dropTargets).toHaveLength(1);
186
- });
187
-
188
- it.todo('should remove column drop targets when dragging ends');
189
- });