@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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/commands/column-resize.js +115 -45
- package/dist/cjs/commands/go-to-next-cell.js +7 -11
- package/dist/cjs/commands/misc.js +3 -2
- package/dist/cjs/commands/selection.js +3 -3
- package/dist/cjs/event-handlers.js +38 -25
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
- package/dist/cjs/pm-plugins/keymap.js +1 -0
- package/dist/cjs/pm-plugins/main.js +43 -9
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
- package/dist/cjs/reducer.js +5 -2
- package/dist/cjs/utils/drag-menu.js +37 -23
- package/dist/cjs/utils/merged-cells.js +66 -1
- package/dist/es2019/commands/column-resize.js +100 -35
- package/dist/es2019/commands/go-to-next-cell.js +7 -9
- package/dist/es2019/commands/misc.js +3 -2
- package/dist/es2019/commands/selection.js +5 -5
- package/dist/es2019/event-handlers.js +17 -3
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/es2019/pm-plugins/keymap.js +3 -2
- package/dist/es2019/pm-plugins/main.js +41 -5
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
- package/dist/es2019/reducer.js +5 -2
- package/dist/es2019/utils/drag-menu.js +38 -14
- package/dist/es2019/utils/merged-cells.js +73 -0
- package/dist/esm/commands/column-resize.js +105 -35
- package/dist/esm/commands/go-to-next-cell.js +7 -11
- package/dist/esm/commands/misc.js +3 -2
- package/dist/esm/commands/selection.js +5 -5
- package/dist/esm/event-handlers.js +38 -25
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/esm/pm-plugins/keymap.js +3 -2
- package/dist/esm/pm-plugins/main.js +38 -4
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
- package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
- package/dist/esm/reducer.js +5 -2
- package/dist/esm/utils/drag-menu.js +36 -22
- package/dist/esm/utils/merged-cells.js +65 -0
- package/dist/types/commands/column-resize.d.ts +2 -0
- package/dist/types/commands/misc.d.ts +1 -1
- package/dist/types/types.d.ts +16 -0
- package/dist/types/utils/drag-menu.d.ts +4 -1
- package/dist/types/utils/merged-cells.d.ts +2 -0
- package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
- package/dist/types-ts4.5/commands/misc.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +16 -0
- package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
- package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
- package/package.json +10 -17
- package/src/commands/column-resize.ts +155 -40
- package/src/commands/go-to-next-cell.ts +6 -15
- package/src/commands/misc.ts +2 -0
- package/src/commands/selection.ts +5 -5
- package/src/event-handlers.ts +21 -4
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
- package/src/pm-plugins/keymap.ts +3 -0
- package/src/pm-plugins/main.ts +47 -2
- package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
- package/src/pm-plugins/table-resizing/plugin.ts +18 -1
- package/src/reducer.ts +5 -2
- package/src/types.ts +16 -0
- package/src/utils/drag-menu.ts +94 -20
- package/src/utils/merged-cells.ts +78 -0
- package/tsconfig.dev.json +0 -69
- package/tsconfig.json +2 -877
- package/examples/99-testing.tsx +0 -140
- package/examples/config.jsonc +0 -14
- package/src/__tests__/unit/analytics.ts +0 -888
- package/src/__tests__/unit/collab.ts +0 -93
- package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
- package/src/__tests__/unit/commands/insert.ts +0 -137
- package/src/__tests__/unit/commands/misc.ts +0 -185
- package/src/__tests__/unit/commands/sort.ts +0 -128
- package/src/__tests__/unit/commands.ts +0 -745
- package/src/__tests__/unit/copy-button.ts +0 -22
- package/src/__tests__/unit/copy-paste.ts +0 -677
- package/src/__tests__/unit/event-handlers/index.ts +0 -125
- package/src/__tests__/unit/event-handlers.ts +0 -296
- package/src/__tests__/unit/fix-tables.ts +0 -164
- package/src/__tests__/unit/get-toolbar-config.ts +0 -127
- package/src/__tests__/unit/handlers.ts +0 -98
- package/src/__tests__/unit/hover-selection.ts +0 -230
- package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
- package/src/__tests__/unit/index.ts +0 -912
- package/src/__tests__/unit/layout.ts +0 -146
- package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
- package/src/__tests__/unit/nodeviews/cell.ts +0 -132
- package/src/__tests__/unit/nodeviews/table.ts +0 -129
- package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
- package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
- package/src/__tests__/unit/pm-plugins/main.ts +0 -214
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
- package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
- package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
- package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
- package/src/__tests__/unit/sort-column.ts +0 -399
- package/src/__tests__/unit/toolbar.ts +0 -512
- package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
- package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
- package/src/__tests__/unit/transforms/merging.ts +0 -392
- package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
- package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
- package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
- package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
- package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
- package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
- package/src/__tests__/unit/ui/RowControls.tsx +0 -294
- package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
- package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
- package/src/__tests__/unit/undo-redo.ts +0 -220
- package/src/__tests__/unit/utils/analytics.ts +0 -98
- package/src/__tests__/unit/utils/collapse.ts +0 -57
- package/src/__tests__/unit/utils/column-controls.ts +0 -205
- package/src/__tests__/unit/utils/dom.ts +0 -180
- package/src/__tests__/unit/utils/merged-cells.ts +0 -156
- package/src/__tests__/unit/utils/nodes.ts +0 -79
- package/src/__tests__/unit/utils/row-controls.ts +0 -195
- package/src/__tests__/unit/utils/table.ts +0 -96
- package/src/__tests__/unit/utils.ts +0 -670
- package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
- package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
- package/src/__tests__/visual-regression/copy-button.ts +0 -181
- package/src/__tests__/visual-regression/index.ts +0 -62
- 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
|
-
});
|