@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.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
- package/dist/cjs/utils/drag-menu.js +37 -23
- package/dist/cjs/utils/merged-cells.js +66 -1
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/es2019/utils/drag-menu.js +38 -14
- package/dist/es2019/utils/merged-cells.js +73 -0
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/esm/utils/drag-menu.js +36 -22
- package/dist/esm/utils/merged-cells.js +65 -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/utils/drag-menu.d.ts +4 -1
- package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
- package/package.json +9 -16
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
- 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,217 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { cleanup, render, screen } from '@testing-library/react';
|
|
4
|
-
import { createPortal } from 'react-dom';
|
|
5
|
-
|
|
6
|
-
import { akEditorTableCellOnStickyHeaderZIndex } from '@atlaskit/editor-shared-styles';
|
|
7
|
-
|
|
8
|
-
import FixedButton, {
|
|
9
|
-
BUTTON_WIDTH,
|
|
10
|
-
calcLeftPos,
|
|
11
|
-
calcObserverTargetMargin,
|
|
12
|
-
} from '../../../ui/FloatingContextualButton/FixedButton';
|
|
13
|
-
|
|
14
|
-
jest.mock('react-dom', () => ({
|
|
15
|
-
createPortal: jest.fn((node: React.ReactNode) => node),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
describe('calcLeftPos()', () => {
|
|
19
|
-
it('should calculate left position', () => {
|
|
20
|
-
let result = calcLeftPos({
|
|
21
|
-
buttonWidth: 0,
|
|
22
|
-
cellRectLeft: 0,
|
|
23
|
-
cellRefWidth: 0,
|
|
24
|
-
offset: 0,
|
|
25
|
-
});
|
|
26
|
-
expect(result).toEqual(0);
|
|
27
|
-
result = calcLeftPos({
|
|
28
|
-
buttonWidth: 20,
|
|
29
|
-
cellRectLeft: 400,
|
|
30
|
-
cellRefWidth: 250,
|
|
31
|
-
offset: 3,
|
|
32
|
-
});
|
|
33
|
-
expect(result).toEqual(627);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('calcObserverTargetMargin()', () => {
|
|
38
|
-
it('should calculate the margin', () => {
|
|
39
|
-
const mockTableWrapper = document.createElement('div');
|
|
40
|
-
mockTableWrapper.scrollLeft = 50;
|
|
41
|
-
const tableSpy = jest.spyOn(mockTableWrapper, 'getBoundingClientRect');
|
|
42
|
-
tableSpy.mockImplementation(() => ({ left: 800 } as DOMRect));
|
|
43
|
-
|
|
44
|
-
const mockButton = document.createElement('div');
|
|
45
|
-
const buttonSpy = jest.spyOn(mockButton, 'getBoundingClientRect');
|
|
46
|
-
buttonSpy.mockImplementation(() => ({ left: 1200 } as DOMRect));
|
|
47
|
-
|
|
48
|
-
const result = calcObserverTargetMargin(mockTableWrapper, mockButton);
|
|
49
|
-
expect(result).toEqual(450);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('<FixedButton />', () => {
|
|
54
|
-
const targetCellRef = document.createElement('div');
|
|
55
|
-
const fixedButtonRef = {
|
|
56
|
-
current: document.createElement('div'),
|
|
57
|
-
};
|
|
58
|
-
const observerTargetRef = {
|
|
59
|
-
current: document.createElement('div'),
|
|
60
|
-
};
|
|
61
|
-
const props = {
|
|
62
|
-
offset: 10,
|
|
63
|
-
stickyHeader: {
|
|
64
|
-
pos: 0,
|
|
65
|
-
top: 0,
|
|
66
|
-
padding: 0,
|
|
67
|
-
sticky: true,
|
|
68
|
-
},
|
|
69
|
-
targetCellPosition: 0,
|
|
70
|
-
targetCellRef,
|
|
71
|
-
mountTo: document.createElement('div'),
|
|
72
|
-
tableWrapper: document.createElement('div'),
|
|
73
|
-
fixedButtonRef,
|
|
74
|
-
observerTargetRef,
|
|
75
|
-
isContextualMenuOpen: false,
|
|
76
|
-
};
|
|
77
|
-
const MockChildren = () => <div data-testid="mock-children" />;
|
|
78
|
-
|
|
79
|
-
it('should render children', () => {
|
|
80
|
-
render(
|
|
81
|
-
<FixedButton {...props}>
|
|
82
|
-
<MockChildren />
|
|
83
|
-
</FixedButton>,
|
|
84
|
-
);
|
|
85
|
-
expect(screen.getByTestId('mock-children')).toBeInTheDocument();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should render using createPortal', () => {
|
|
89
|
-
render(
|
|
90
|
-
<FixedButton {...props}>
|
|
91
|
-
<MockChildren />
|
|
92
|
-
</FixedButton>,
|
|
93
|
-
);
|
|
94
|
-
expect(createPortal).toBeCalled();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('observerTargetRef', () => {
|
|
98
|
-
it('should have correct inital styles', () => {
|
|
99
|
-
const { container } = render(
|
|
100
|
-
<FixedButton {...props}>
|
|
101
|
-
<MockChildren />
|
|
102
|
-
</FixedButton>,
|
|
103
|
-
);
|
|
104
|
-
expect(container.firstChild).toHaveStyle(
|
|
105
|
-
`top: 0px; left: 0px; position: absolute; width: ${BUTTON_WIDTH}px; height: ${BUTTON_WIDTH}px`,
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should have correct "margin-left" style', () => {
|
|
110
|
-
const mockTableWrapper = document.createElement('div');
|
|
111
|
-
mockTableWrapper.scrollLeft = 123;
|
|
112
|
-
const { container } = render(
|
|
113
|
-
<FixedButton {...props} tableWrapper={mockTableWrapper}>
|
|
114
|
-
<MockChildren />
|
|
115
|
-
</FixedButton>,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect(container.firstChild).toHaveStyle(`margin-left: 123px;`);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('fixedButtonRef', () => {
|
|
123
|
-
it('should have correct "top" style', () => {
|
|
124
|
-
const { container, rerender } = render(
|
|
125
|
-
<FixedButton {...props} offset={10}>
|
|
126
|
-
<MockChildren />
|
|
127
|
-
</FixedButton>,
|
|
128
|
-
);
|
|
129
|
-
expect(container.firstChild?.firstChild).toHaveStyle(`top: 20px;`);
|
|
130
|
-
|
|
131
|
-
rerender(
|
|
132
|
-
<FixedButton
|
|
133
|
-
{...props}
|
|
134
|
-
stickyHeader={{ pos: 0, top: 3, padding: 0, sticky: true }}
|
|
135
|
-
>
|
|
136
|
-
<MockChildren />
|
|
137
|
-
</FixedButton>,
|
|
138
|
-
);
|
|
139
|
-
expect(container.firstChild?.firstChild).toHaveStyle(`top: 23px;`);
|
|
140
|
-
|
|
141
|
-
rerender(
|
|
142
|
-
<FixedButton
|
|
143
|
-
{...props}
|
|
144
|
-
stickyHeader={{ pos: 0, top: 0, padding: 2, sticky: true }}
|
|
145
|
-
>
|
|
146
|
-
<MockChildren />
|
|
147
|
-
</FixedButton>,
|
|
148
|
-
);
|
|
149
|
-
expect(container.firstChild?.firstChild).toHaveStyle(`top: 22px;`);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('should have correct "left" style', () => {
|
|
153
|
-
const mockRef = document.createElement('div');
|
|
154
|
-
const mockRefSpy = jest.spyOn(mockRef, 'getBoundingClientRect');
|
|
155
|
-
mockRefSpy.mockImplementation(() => ({ left: 3 } as DOMRect));
|
|
156
|
-
|
|
157
|
-
const { container } = render(
|
|
158
|
-
<FixedButton {...props} targetCellRef={mockRef}>
|
|
159
|
-
<MockChildren />
|
|
160
|
-
</FixedButton>,
|
|
161
|
-
);
|
|
162
|
-
expect(container.firstChild?.firstChild).toHaveStyle(`left: -27px;`);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should have correct "z-index" style', () => {
|
|
166
|
-
const { container } = render(
|
|
167
|
-
<FixedButton {...props}>
|
|
168
|
-
<MockChildren />
|
|
169
|
-
</FixedButton>,
|
|
170
|
-
);
|
|
171
|
-
expect(container.firstChild?.firstChild).toHaveStyle(
|
|
172
|
-
`z-index: ${akEditorTableCellOnStickyHeaderZIndex}`,
|
|
173
|
-
);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe('useEffect()', () => {
|
|
178
|
-
const observe = jest.fn();
|
|
179
|
-
const unobserve = jest.fn();
|
|
180
|
-
|
|
181
|
-
window.IntersectionObserver = jest.fn((callback) => {
|
|
182
|
-
callback([{ isIntersecting: true }]);
|
|
183
|
-
return {
|
|
184
|
-
observe,
|
|
185
|
-
unobserve,
|
|
186
|
-
};
|
|
187
|
-
}) as any;
|
|
188
|
-
|
|
189
|
-
it('should add / remove event listener to the table wrapper', () => {
|
|
190
|
-
const mockTableWrapper = document.createElement('div');
|
|
191
|
-
const addSpy = jest.spyOn(mockTableWrapper, 'addEventListener');
|
|
192
|
-
const removeSpy = jest.spyOn(mockTableWrapper, 'removeEventListener');
|
|
193
|
-
|
|
194
|
-
render(
|
|
195
|
-
<FixedButton {...props} tableWrapper={mockTableWrapper}>
|
|
196
|
-
<MockChildren />
|
|
197
|
-
</FixedButton>,
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
expect(addSpy).toBeCalled();
|
|
201
|
-
cleanup();
|
|
202
|
-
expect(removeSpy).toBeCalled();
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('should observe / unobserve an InterSectionObserver', () => {
|
|
206
|
-
render(
|
|
207
|
-
<FixedButton {...props}>
|
|
208
|
-
<MockChildren />
|
|
209
|
-
</FixedButton>,
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
expect(observe).toHaveBeenCalled();
|
|
213
|
-
cleanup();
|
|
214
|
-
expect(unobserve).toHaveBeenCalled();
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|
|
@@ -1,123 +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 { UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
7
|
-
import type { DocBuilder } 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 { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
16
|
-
import * as prosemirrorUtils from '@atlaskit/editor-prosemirror/utils';
|
|
17
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
18
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
19
|
-
import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
20
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
21
|
-
import {
|
|
22
|
-
createProsemirrorEditorFactory,
|
|
23
|
-
Preset,
|
|
24
|
-
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
25
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
26
|
-
import {
|
|
27
|
-
doc,
|
|
28
|
-
table,
|
|
29
|
-
tdCursor,
|
|
30
|
-
tdEmpty,
|
|
31
|
-
thEmpty,
|
|
32
|
-
tr,
|
|
33
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
34
|
-
|
|
35
|
-
import tablePlugin from '../../../plugin';
|
|
36
|
-
import type { Props as FloatingContextualButtonProps } from '../../../ui/FloatingContextualButton';
|
|
37
|
-
import FloatingContextualButton from '../../../ui/FloatingContextualButton';
|
|
38
|
-
|
|
39
|
-
jest.mock('@atlaskit/editor-prosemirror/utils', () => {
|
|
40
|
-
// Unblock prosemirror bump:
|
|
41
|
-
// Workaround to enable spy on prosemirror-utils cjs bundle
|
|
42
|
-
const originalModule = jest.requireActual(
|
|
43
|
-
'@atlaskit/editor-prosemirror/utils',
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
__esModule: true,
|
|
48
|
-
...originalModule,
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
53
|
-
let createAnalyticsEvent = jest.fn(() => ({ fire() {} } as UIAnalyticsEvent));
|
|
54
|
-
const editor = (doc: DocBuilder) =>
|
|
55
|
-
createEditor({
|
|
56
|
-
doc,
|
|
57
|
-
preset: new Preset<LightEditorPlugin>()
|
|
58
|
-
.add([featureFlagsPlugin, {}])
|
|
59
|
-
.add([analyticsPlugin, {}])
|
|
60
|
-
.add(contentInsertionPlugin)
|
|
61
|
-
.add(widthPlugin)
|
|
62
|
-
.add(guidelinePlugin)
|
|
63
|
-
.add(selectionPlugin)
|
|
64
|
-
.add(tablePlugin),
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('Floating Contextual Button', () => {
|
|
68
|
-
let editorView: EditorView;
|
|
69
|
-
let refs: { [name: string]: number };
|
|
70
|
-
let tableNode: ContentNodeWithPos | undefined;
|
|
71
|
-
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
({ editorView, refs } = editor(
|
|
74
|
-
doc(
|
|
75
|
-
table()(
|
|
76
|
-
tr('{firstCell}', thEmpty, thEmpty, thEmpty),
|
|
77
|
-
tr(tdCursor, tdEmpty, tdEmpty),
|
|
78
|
-
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
79
|
-
),
|
|
80
|
-
),
|
|
81
|
-
));
|
|
82
|
-
|
|
83
|
-
tableNode = prosemirrorUtils.findParentNodeOfTypeClosestToPos(
|
|
84
|
-
editorView.state.selection.$from,
|
|
85
|
-
editorView.state.schema.nodes.table,
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const component = (props: FloatingContextualButtonProps) =>
|
|
90
|
-
render(
|
|
91
|
-
<IntlProvider locale="en">
|
|
92
|
-
<FloatingContextualButton
|
|
93
|
-
tableNode={tableNode && tableNode.node}
|
|
94
|
-
dispatchAnalyticsEvent={createAnalyticsEvent}
|
|
95
|
-
{...props}
|
|
96
|
-
/>
|
|
97
|
-
</IntlProvider>,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
describe('when an error is thrown in the component', () => {
|
|
101
|
-
it('renders', () => {
|
|
102
|
-
component({
|
|
103
|
-
editorView,
|
|
104
|
-
targetCellPosition: refs.firstCell,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
expect(screen.getByLabelText('Cell options')).toBeInTheDocument();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('dispatches an analytics event', () => {
|
|
111
|
-
const mock = jest.spyOn(prosemirrorUtils, 'findDomRefAtPos');
|
|
112
|
-
mock.mockImplementation(() => {
|
|
113
|
-
throw new Error('Error message from mock');
|
|
114
|
-
});
|
|
115
|
-
component({
|
|
116
|
-
editorView,
|
|
117
|
-
targetCellPosition: refs.firstCell,
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
expect(createAnalyticsEvent).toHaveBeenCalled();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1,68 +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
|
-
// 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 { getPluginState } from '../../../pm-plugins/plugin-factory';
|
|
34
|
-
import FloatingContextualMenu from '../../../ui/FloatingContextualMenu';
|
|
35
|
-
|
|
36
|
-
describe('FloatingContextualMenu', () => {
|
|
37
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
38
|
-
describe('with right 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),
|
|
51
|
-
}));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should render floating contextual menu when no tableCellPosition is passed but exist on editor state ', () => {
|
|
55
|
-
render(
|
|
56
|
-
<IntlProvider locale="en">
|
|
57
|
-
<FloatingContextualMenu
|
|
58
|
-
editorView={editorView}
|
|
59
|
-
isOpen
|
|
60
|
-
pluginConfig={getPluginState(editorView.state).pluginConfig}
|
|
61
|
-
getEditorContainerWidth={jest.fn()}
|
|
62
|
-
/>
|
|
63
|
-
</IntlProvider>,
|
|
64
|
-
);
|
|
65
|
-
expect(screen.getAllByLabelText('Popup').length).toBeGreaterThan(0);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,178 +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 type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
-
import { getCellsInColumn, selectTable } from '@atlaskit/editor-tables/utils';
|
|
9
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
10
|
-
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
11
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
12
|
-
import {
|
|
13
|
-
doc,
|
|
14
|
-
table,
|
|
15
|
-
tdCursor,
|
|
16
|
-
tdEmpty,
|
|
17
|
-
thEmpty,
|
|
18
|
-
tr,
|
|
19
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
20
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
21
|
-
import { selectColumns, selectRows } from '@atlaskit/editor-test-helpers/table';
|
|
22
|
-
|
|
23
|
-
import tablePlugin from '../../../plugin';
|
|
24
|
-
import { pluginKey } from '../../../pm-plugins/plugin-key';
|
|
25
|
-
import type { TablePluginState } from '../../../types';
|
|
26
|
-
import { TableCssClassName } from '../../../types';
|
|
27
|
-
import type { Props as FloatingDeleteButtonProps } from '../../../ui/FloatingDeleteButton';
|
|
28
|
-
import FloatingDeleteButton from '../../../ui/FloatingDeleteButton';
|
|
29
|
-
import * as tableColumnControlsUtils from '../../../utils/column-controls';
|
|
30
|
-
|
|
31
|
-
describe('Floating Delete Button', () => {
|
|
32
|
-
const createEditor = createEditorFactory<TablePluginState>();
|
|
33
|
-
|
|
34
|
-
const editor = (doc: DocBuilder) =>
|
|
35
|
-
createEditor({
|
|
36
|
-
doc,
|
|
37
|
-
editorProps: {
|
|
38
|
-
allowTables: false,
|
|
39
|
-
dangerouslyAppendPlugins: {
|
|
40
|
-
__plugins: [tablePlugin({ config: undefined })],
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
pluginKey,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
let editorView: EditorView;
|
|
47
|
-
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
({ editorView } = editor(
|
|
50
|
-
doc(
|
|
51
|
-
table()(
|
|
52
|
-
tr(thEmpty, thEmpty, thEmpty),
|
|
53
|
-
tr(tdCursor, tdEmpty, tdEmpty),
|
|
54
|
-
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
55
|
-
),
|
|
56
|
-
),
|
|
57
|
-
));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const component = (props: FloatingDeleteButtonProps) =>
|
|
61
|
-
render(
|
|
62
|
-
<IntlProvider locale="en">
|
|
63
|
-
<FloatingDeleteButton
|
|
64
|
-
tableRef={editorView.dom.querySelector('table')!}
|
|
65
|
-
{...props}
|
|
66
|
-
/>
|
|
67
|
-
</IntlProvider>,
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
it('should not render a delete button with no selection', () => {
|
|
71
|
-
component({ selection: editorView.state.selection, editorView });
|
|
72
|
-
|
|
73
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should not render a delete button with whole table selected', () => {
|
|
77
|
-
// selects the whole table
|
|
78
|
-
editorView.dispatch(selectTable(editorView.state.tr));
|
|
79
|
-
|
|
80
|
-
component({ selection: editorView.state.selection, editorView });
|
|
81
|
-
|
|
82
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('Columns', () => {
|
|
86
|
-
beforeEach(() => {
|
|
87
|
-
const COLUMN_WIDTH = 33;
|
|
88
|
-
const tableWrapper = document.querySelector(
|
|
89
|
-
`.${TableCssClassName.TABLE_NODE_WRAPPER}`,
|
|
90
|
-
);
|
|
91
|
-
jest.spyOn(tableWrapper!, 'getBoundingClientRect').mockReturnValue({
|
|
92
|
-
width: COLUMN_WIDTH * 3,
|
|
93
|
-
} as DOMRect);
|
|
94
|
-
tableWrapper!.scrollLeft = 0;
|
|
95
|
-
jest
|
|
96
|
-
.spyOn(tableColumnControlsUtils, 'getColumnsWidths')
|
|
97
|
-
.mockReturnValue([COLUMN_WIDTH, COLUMN_WIDTH, COLUMN_WIDTH]);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test.each([[1], [2], [3]])(
|
|
101
|
-
'should renders a delete button with column %d selected',
|
|
102
|
-
(column) => {
|
|
103
|
-
// Select columns start from 0
|
|
104
|
-
selectColumns([column - 1])(editorView.state, editorView.dispatch);
|
|
105
|
-
|
|
106
|
-
component({ selection: editorView.state.selection, editorView });
|
|
107
|
-
|
|
108
|
-
expect(screen.getAllByLabelText('Delete column').length).toBe(1);
|
|
109
|
-
},
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
it('should render a single delete button over multiple column selections', () => {
|
|
113
|
-
selectColumns([0, 1])(editorView.state, editorView.dispatch);
|
|
114
|
-
|
|
115
|
-
component({ selection: editorView.state.selection, editorView });
|
|
116
|
-
|
|
117
|
-
expect(screen.getAllByLabelText('Delete column').length).toBe(1);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('Rows', () => {
|
|
122
|
-
test.each([[1], [2], [3]])(
|
|
123
|
-
'renders a delete button with row %d selected',
|
|
124
|
-
(row) => {
|
|
125
|
-
selectRows([row - 1])(editorView.state, editorView.dispatch);
|
|
126
|
-
|
|
127
|
-
component({ selection: editorView.state.selection, editorView });
|
|
128
|
-
|
|
129
|
-
expect(screen.getAllByLabelText('Delete row').length).toBe(1);
|
|
130
|
-
},
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
it('only renders a single delete button over multiple row selections', () => {
|
|
134
|
-
selectRows([0, 1])(editorView.state, editorView.dispatch);
|
|
135
|
-
|
|
136
|
-
// selecting the row mutates the editor state (which is inside editorView)
|
|
137
|
-
component({ selection: editorView.state.selection, editorView });
|
|
138
|
-
|
|
139
|
-
expect(screen.getAllByLabelText('Delete row').length).toBe(1);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe('when deleting with the delete button', () => {
|
|
144
|
-
describe('Columns', () => {
|
|
145
|
-
it('should move cursor within the table after delete', () => {
|
|
146
|
-
selectColumns([0, 1])(editorView.state, editorView.dispatch);
|
|
147
|
-
component({ selection: editorView.state.selection, editorView });
|
|
148
|
-
|
|
149
|
-
const { tr } = editorView.state;
|
|
150
|
-
const { pos } = getCellsInColumn(2)(tr.selection)![2];
|
|
151
|
-
const lastCellPos = tr.doc.resolve(pos).pos + 1;
|
|
152
|
-
|
|
153
|
-
fireEvent.click(screen.getByLabelText('Delete column'));
|
|
154
|
-
|
|
155
|
-
expect(editorView.state.selection.from).toBeLessThanOrEqual(
|
|
156
|
-
lastCellPos,
|
|
157
|
-
);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('Rows', () => {
|
|
162
|
-
it('should move cursor within the table after delete', () => {
|
|
163
|
-
selectRows([0, 1])(editorView.state, editorView.dispatch);
|
|
164
|
-
component({ selection: editorView.state.selection, editorView });
|
|
165
|
-
|
|
166
|
-
const { tr } = editorView.state;
|
|
167
|
-
const { pos } = getCellsInColumn(2)(tr.selection)![2];
|
|
168
|
-
const lastCellPos = tr.doc.resolve(pos).pos + 1;
|
|
169
|
-
|
|
170
|
-
fireEvent.click(screen.getByLabelText('Delete row'));
|
|
171
|
-
|
|
172
|
-
expect(editorView.state.selection.from).toBeLessThanOrEqual(
|
|
173
|
-
lastCellPos,
|
|
174
|
-
);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
});
|