@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,562 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import type { Stub } from 'raf-stub';
|
|
5
|
-
import createStub from 'raf-stub';
|
|
6
|
-
|
|
7
|
-
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
8
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
9
|
-
import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
10
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
11
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
12
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
13
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
14
|
-
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
15
|
-
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
16
|
-
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
17
|
-
import type { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
|
|
18
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
19
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
20
|
-
import type { LightEditorPlugin } 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
|
-
createProsemirrorEditorFactory,
|
|
24
|
-
Preset,
|
|
25
|
-
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
26
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
27
|
-
import {
|
|
28
|
-
doc,
|
|
29
|
-
table,
|
|
30
|
-
tdEmpty,
|
|
31
|
-
thEmpty,
|
|
32
|
-
tr,
|
|
33
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
34
|
-
|
|
35
|
-
import TableComponent from '../../../../nodeviews/TableComponent';
|
|
36
|
-
import TableRow from '../../../../nodeviews/TableRow';
|
|
37
|
-
import tablePlugin from '../../../../plugin';
|
|
38
|
-
import { pluginKey } from '../../../../pm-plugins/plugin-key';
|
|
39
|
-
import { updateStickyState } from '../../../../pm-plugins/sticky-headers/commands';
|
|
40
|
-
import { TableCssClassName } from '../../../../types';
|
|
41
|
-
import type { PluginConfig } from '../../../../types';
|
|
42
|
-
import {
|
|
43
|
-
stickyRowOffsetTop,
|
|
44
|
-
tableScrollbarOffset,
|
|
45
|
-
} from '../../../../ui/consts';
|
|
46
|
-
|
|
47
|
-
jest.mock('../../../../pm-plugins/sticky-headers/commands', () => ({
|
|
48
|
-
...jest.requireActual<Object>(
|
|
49
|
-
'../../../../pm-plugins/sticky-headers/commands',
|
|
50
|
-
),
|
|
51
|
-
updateStickyState: jest.fn(() => jest.fn()),
|
|
52
|
-
}));
|
|
53
|
-
jest.mock('@atlaskit/editor-common/ui', () => ({
|
|
54
|
-
...jest.requireActual<Object>('@atlaskit/editor-common/ui'),
|
|
55
|
-
findOverflowScrollParent: jest.fn(() => jest.fn()),
|
|
56
|
-
}));
|
|
57
|
-
|
|
58
|
-
describe('TableRow', () => {
|
|
59
|
-
const tableOptions = {
|
|
60
|
-
allowNumberColumn: true,
|
|
61
|
-
allowHeaderRow: true,
|
|
62
|
-
allowHeaderColumn: true,
|
|
63
|
-
permittedLayouts: 'all',
|
|
64
|
-
allowColumnResizing: true,
|
|
65
|
-
stickyHeaders: true,
|
|
66
|
-
} as PluginConfig;
|
|
67
|
-
|
|
68
|
-
let tableRowNodeView: TableRow;
|
|
69
|
-
const fakeGetEditorFeatureFlags = jest.fn(() => ({}));
|
|
70
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
71
|
-
const editor = (doc: DocBuilder) => {
|
|
72
|
-
const featureFlags = {};
|
|
73
|
-
fakeGetEditorFeatureFlags.mockReturnValue(featureFlags);
|
|
74
|
-
return createEditor({
|
|
75
|
-
doc,
|
|
76
|
-
preset: new Preset<LightEditorPlugin>()
|
|
77
|
-
.add([featureFlagsPlugin, {}])
|
|
78
|
-
.add([analyticsPlugin, {}])
|
|
79
|
-
.add(contentInsertionPlugin)
|
|
80
|
-
.add(widthPlugin)
|
|
81
|
-
.add(guidelinePlugin)
|
|
82
|
-
.add(selectionPlugin)
|
|
83
|
-
.add([
|
|
84
|
-
tablePlugin,
|
|
85
|
-
{
|
|
86
|
-
tableOptions,
|
|
87
|
-
},
|
|
88
|
-
]),
|
|
89
|
-
pluginKey,
|
|
90
|
-
attachTo: document.body,
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
let editorView: EditorView;
|
|
94
|
-
let eventDispatcher: EventDispatcher;
|
|
95
|
-
let tableRowNode: ProseMirrorNode;
|
|
96
|
-
let tableRowDom: HTMLTableRowElement;
|
|
97
|
-
|
|
98
|
-
const baseBoundingRect = {
|
|
99
|
-
width: 100,
|
|
100
|
-
height: 100,
|
|
101
|
-
top: 0,
|
|
102
|
-
bottom: 0,
|
|
103
|
-
left: 0,
|
|
104
|
-
right: 0,
|
|
105
|
-
x: 0,
|
|
106
|
-
y: 0,
|
|
107
|
-
toJSON: jest.fn(),
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
describe('ignoreMutation', () => {
|
|
111
|
-
beforeEach(() => {
|
|
112
|
-
const editorData = editor(
|
|
113
|
-
doc(table({ localId: '' })(tr(tdEmpty, tdEmpty))),
|
|
114
|
-
);
|
|
115
|
-
editorView = editorData.editorView;
|
|
116
|
-
eventDispatcher = editorData.eventDispatcher;
|
|
117
|
-
tableRowNode = editorView.state.doc.firstChild!.firstChild!;
|
|
118
|
-
tableRowNodeView = new TableRow(
|
|
119
|
-
tableRowNode,
|
|
120
|
-
editorView,
|
|
121
|
-
() => 0,
|
|
122
|
-
eventDispatcher,
|
|
123
|
-
);
|
|
124
|
-
tableRowDom = editorView.dom.getElementsByTagName('tr')[0];
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
afterEach(() => {
|
|
128
|
-
jest.clearAllMocks();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('ignores attributes changes to row element', () => {
|
|
132
|
-
const mutationRecord = {
|
|
133
|
-
target: tableRowDom,
|
|
134
|
-
type: 'attributes',
|
|
135
|
-
} as any;
|
|
136
|
-
expect(tableRowNodeView.ignoreMutation(mutationRecord as any)).toBe(true);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// These insertion mutations occur when using some language inputs in Safari
|
|
140
|
-
// (ie. Pinyin, Hiragana)
|
|
141
|
-
it('does not ignore insertion changes to row element', () => {
|
|
142
|
-
const mutationRecord = {
|
|
143
|
-
target: tableRowDom,
|
|
144
|
-
type: 'childList',
|
|
145
|
-
// The implementation is not opinionated about the type of the addedNodes.
|
|
146
|
-
addedNodes: [''],
|
|
147
|
-
} as any;
|
|
148
|
-
expect(tableRowNodeView.ignoreMutation(mutationRecord as any)).toBe(
|
|
149
|
-
false,
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('does not ignore selection changes to row element', () => {
|
|
154
|
-
const mutationRecord = {
|
|
155
|
-
target: tableRowDom,
|
|
156
|
-
type: 'selection',
|
|
157
|
-
} as any;
|
|
158
|
-
expect(tableRowNodeView.ignoreMutation(mutationRecord as any)).toBe(
|
|
159
|
-
false,
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe('sticky headers', () => {
|
|
165
|
-
let rafStub: Stub;
|
|
166
|
-
let originalIntersectionObserver: object;
|
|
167
|
-
let originalResizeObserver: object;
|
|
168
|
-
let offsetHeightSpy: jest.SpyInstance;
|
|
169
|
-
let scrollContainer: HTMLElement;
|
|
170
|
-
|
|
171
|
-
let triggerElementResize = (
|
|
172
|
-
element: HTMLElement,
|
|
173
|
-
height: number,
|
|
174
|
-
contentRectSupported: boolean,
|
|
175
|
-
) => {
|
|
176
|
-
if (offsetHeightSpy) {
|
|
177
|
-
offsetHeightSpy.mockClear();
|
|
178
|
-
}
|
|
179
|
-
offsetHeightSpy = jest
|
|
180
|
-
.spyOn(element, 'offsetHeight', 'get')
|
|
181
|
-
.mockImplementation(() => height);
|
|
182
|
-
|
|
183
|
-
const entries = [
|
|
184
|
-
{
|
|
185
|
-
target: element,
|
|
186
|
-
contentRect: contentRectSupported ? { height } : undefined,
|
|
187
|
-
},
|
|
188
|
-
];
|
|
189
|
-
resizeCallback(entries);
|
|
190
|
-
};
|
|
191
|
-
let triggerElementIntersect = ({
|
|
192
|
-
target,
|
|
193
|
-
isIntersecting,
|
|
194
|
-
boundingClientRect,
|
|
195
|
-
rootBounds,
|
|
196
|
-
}: {
|
|
197
|
-
target: HTMLElement;
|
|
198
|
-
isIntersecting: boolean;
|
|
199
|
-
rootBounds: {
|
|
200
|
-
bottom: number;
|
|
201
|
-
top: number;
|
|
202
|
-
height?: number;
|
|
203
|
-
};
|
|
204
|
-
boundingClientRect: {
|
|
205
|
-
bottom: number;
|
|
206
|
-
top: number;
|
|
207
|
-
};
|
|
208
|
-
}) => {
|
|
209
|
-
const entries = [
|
|
210
|
-
{
|
|
211
|
-
target,
|
|
212
|
-
rootBounds,
|
|
213
|
-
boundingClientRect,
|
|
214
|
-
isIntersecting,
|
|
215
|
-
},
|
|
216
|
-
];
|
|
217
|
-
intersectCallback(entries);
|
|
218
|
-
};
|
|
219
|
-
let intersectCallback: (entries: any[]) => {};
|
|
220
|
-
let resizeCallback: (entries: any[]) => {};
|
|
221
|
-
|
|
222
|
-
beforeAll(() => {
|
|
223
|
-
originalIntersectionObserver = (window as any).IntersectionObserver;
|
|
224
|
-
(window as any).IntersectionObserver = function intersectionObserverMock(
|
|
225
|
-
callback: () => {},
|
|
226
|
-
) {
|
|
227
|
-
this.disconnect = jest.fn();
|
|
228
|
-
this.observe = jest.fn();
|
|
229
|
-
this.unobserve = jest.fn();
|
|
230
|
-
intersectCallback = callback;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
originalResizeObserver = (window as any).ResizeObserver;
|
|
234
|
-
(window as any).ResizeObserver = function resizeObserverMock(
|
|
235
|
-
callback: () => {},
|
|
236
|
-
) {
|
|
237
|
-
this.disconnect = jest.fn();
|
|
238
|
-
this.observe = jest.fn();
|
|
239
|
-
this.unobserve = jest.fn();
|
|
240
|
-
resizeCallback = callback;
|
|
241
|
-
};
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
afterAll(() => {
|
|
245
|
-
(window as any).IntersectionObserver = originalIntersectionObserver;
|
|
246
|
-
(window as any).ResizeObserver = originalResizeObserver;
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
beforeEach(() => {
|
|
250
|
-
rafStub = createStub();
|
|
251
|
-
jest
|
|
252
|
-
.spyOn(window, 'requestAnimationFrame')
|
|
253
|
-
.mockImplementation(rafStub.add);
|
|
254
|
-
|
|
255
|
-
const editorData = editor(
|
|
256
|
-
doc(table()(tr(thEmpty, thEmpty), tr(tdEmpty, tdEmpty))),
|
|
257
|
-
);
|
|
258
|
-
editorView = editorData.editorView;
|
|
259
|
-
eventDispatcher = editorData.eventDispatcher;
|
|
260
|
-
tableRowNode = editorView.state.doc.firstChild!.firstChild!;
|
|
261
|
-
tableRowDom = editorView.dom.getElementsByTagName('tr')[0];
|
|
262
|
-
scrollContainer = mockScrollPositions(tableRowDom)!;
|
|
263
|
-
|
|
264
|
-
tableRowNodeView = new TableRow(
|
|
265
|
-
tableRowNode,
|
|
266
|
-
editorView,
|
|
267
|
-
() => 0,
|
|
268
|
-
eventDispatcher,
|
|
269
|
-
);
|
|
270
|
-
tableRowNodeView.dom = tableRowDom;
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
afterEach(() => {
|
|
274
|
-
jest.clearAllMocks();
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
function getTableElements(tableRowDom: HTMLTableRowElement) {
|
|
278
|
-
const tableWrapper = tableRowDom.closest(
|
|
279
|
-
`.${TableCssClassName.NODEVIEW_WRAPPER}`,
|
|
280
|
-
);
|
|
281
|
-
const tableElement = tableRowDom.closest('table');
|
|
282
|
-
const tableParent = tableElement?.parentElement;
|
|
283
|
-
const scrollContainer = tableWrapper?.parentElement;
|
|
284
|
-
return { tableWrapper, tableElement, tableParent, scrollContainer };
|
|
285
|
-
}
|
|
286
|
-
function mockScrollPositions(tableRowDom: HTMLTableRowElement) {
|
|
287
|
-
const { tableWrapper, tableParent, scrollContainer } =
|
|
288
|
-
getTableElements(tableRowDom);
|
|
289
|
-
(findOverflowScrollParent as unknown as jest.SpyInstance).mockReturnValue(
|
|
290
|
-
scrollContainer,
|
|
291
|
-
);
|
|
292
|
-
jest
|
|
293
|
-
.spyOn(scrollContainer as HTMLElement, 'getBoundingClientRect')
|
|
294
|
-
.mockImplementationOnce(() => ({
|
|
295
|
-
...baseBoundingRect,
|
|
296
|
-
top: -50,
|
|
297
|
-
}));
|
|
298
|
-
jest
|
|
299
|
-
.spyOn(tableParent as HTMLElement, 'getBoundingClientRect')
|
|
300
|
-
.mockImplementationOnce(() => ({
|
|
301
|
-
...baseBoundingRect,
|
|
302
|
-
}));
|
|
303
|
-
jest
|
|
304
|
-
.spyOn(tableWrapper as HTMLElement, 'getBoundingClientRect')
|
|
305
|
-
.mockImplementationOnce(() => ({
|
|
306
|
-
...baseBoundingRect,
|
|
307
|
-
top: -100,
|
|
308
|
-
}));
|
|
309
|
-
return scrollContainer;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function renderTableComponent({
|
|
313
|
-
disableContentDomMock,
|
|
314
|
-
}: {
|
|
315
|
-
disableContentDomMock?: true;
|
|
316
|
-
} = {}) {
|
|
317
|
-
const getNode = () => editorView.state.doc.firstChild;
|
|
318
|
-
return render(
|
|
319
|
-
<TableComponent
|
|
320
|
-
view={editorView}
|
|
321
|
-
eventDispatcher={eventDispatcher}
|
|
322
|
-
getEditorFeatureFlags={fakeGetEditorFeatureFlags}
|
|
323
|
-
// @ts-ignore
|
|
324
|
-
containerWidth={{}}
|
|
325
|
-
// @ts-ignore
|
|
326
|
-
getNode={getNode}
|
|
327
|
-
contentDOM={
|
|
328
|
-
disableContentDomMock
|
|
329
|
-
? jest.fn()
|
|
330
|
-
: (table: HTMLElement | null) => {
|
|
331
|
-
const node = editorView.dom.getElementsByTagName('table')[0];
|
|
332
|
-
|
|
333
|
-
if (!table?.firstChild) {
|
|
334
|
-
table?.appendChild(node);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
getPos={jest.fn()}
|
|
339
|
-
/>,
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
it('does not update sticky headers on scroll', () => {
|
|
344
|
-
const event = new Event('scroll');
|
|
345
|
-
scrollContainer!.dispatchEvent(event);
|
|
346
|
-
|
|
347
|
-
rafStub.flush();
|
|
348
|
-
|
|
349
|
-
expect(updateStickyState).not.toHaveBeenCalled();
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
it('sentinel elements are rendered inside table component', () => {
|
|
353
|
-
renderTableComponent();
|
|
354
|
-
const sentinelTop = screen.getByTestId('sticky-sentinel-top');
|
|
355
|
-
const sentinelBottom = screen.getByTestId('sticky-sentinel-bottom');
|
|
356
|
-
|
|
357
|
-
expect(sentinelTop).toBeTruthy();
|
|
358
|
-
expect(sentinelBottom).toBeTruthy();
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
describe('updates sticky header', () => {
|
|
362
|
-
it('does not update sticky header if trigger is sentinel top in confluence preview mode', () => {
|
|
363
|
-
renderTableComponent();
|
|
364
|
-
const sentinelTop = screen.getByTestId('sticky-sentinel-top');
|
|
365
|
-
|
|
366
|
-
triggerElementIntersect({
|
|
367
|
-
target: sentinelTop as HTMLElement,
|
|
368
|
-
isIntersecting: false,
|
|
369
|
-
rootBounds: { bottom: 0, top: 0, height: 0 },
|
|
370
|
-
boundingClientRect: { bottom: 0, top: 0 },
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
expect(updateStickyState).not.toHaveBeenCalled();
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it('does not update sticky header if trigger is sentinel bottom in confluence preview mode', () => {
|
|
377
|
-
renderTableComponent();
|
|
378
|
-
const sentinelBottom = screen.getByTestId('sticky-sentinel-bottom');
|
|
379
|
-
triggerElementIntersect({
|
|
380
|
-
target: sentinelBottom as HTMLElement,
|
|
381
|
-
isIntersecting: false,
|
|
382
|
-
rootBounds: { bottom: 0, top: 0, height: 0 },
|
|
383
|
-
boundingClientRect: { bottom: 0, top: 0 },
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
expect(updateStickyState).not.toHaveBeenCalled();
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it('updates sticky header when sentinel is below scroll area', () => {
|
|
390
|
-
renderTableComponent();
|
|
391
|
-
const sentinelTop = screen.getByTestId('sticky-sentinel-top');
|
|
392
|
-
|
|
393
|
-
triggerElementIntersect({
|
|
394
|
-
target: sentinelTop,
|
|
395
|
-
isIntersecting: false,
|
|
396
|
-
rootBounds: { bottom: 0, top: 56 },
|
|
397
|
-
boundingClientRect: { bottom: 0, top: 0 },
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// sets to sticky when top sentinel is above scrolled container bottom
|
|
401
|
-
expect(updateStickyState).toHaveBeenCalledWith(
|
|
402
|
-
expect.objectContaining({
|
|
403
|
-
sticky: true,
|
|
404
|
-
}),
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
(updateStickyState as jest.Mock).mockClear();
|
|
408
|
-
|
|
409
|
-
triggerElementIntersect({
|
|
410
|
-
target: sentinelTop,
|
|
411
|
-
isIntersecting: false,
|
|
412
|
-
rootBounds: { bottom: 0, top: 0 },
|
|
413
|
-
boundingClientRect: { bottom: 100, top: 0 },
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
// sets to not sticky when top sentinel is below scrolled container bottom
|
|
417
|
-
expect(updateStickyState).toHaveBeenCalledWith(
|
|
418
|
-
expect.objectContaining({
|
|
419
|
-
sticky: false,
|
|
420
|
-
}),
|
|
421
|
-
);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it('updates sticky header when sentinel is above scroll area', async () => {
|
|
425
|
-
renderTableComponent();
|
|
426
|
-
const sentinelBottom = screen.getByTestId('sticky-sentinel-bottom');
|
|
427
|
-
|
|
428
|
-
triggerElementIntersect({
|
|
429
|
-
target: sentinelBottom,
|
|
430
|
-
isIntersecting: true,
|
|
431
|
-
rootBounds: { bottom: 0, top: 56 },
|
|
432
|
-
boundingClientRect: { bottom: 0, top: -100 },
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
// sets to sticky when bottom sentinel is within scroll area
|
|
436
|
-
// and above scroll container top by more than header height
|
|
437
|
-
expect(updateStickyState).toHaveBeenCalledWith(
|
|
438
|
-
expect.objectContaining({
|
|
439
|
-
sticky: true,
|
|
440
|
-
}),
|
|
441
|
-
);
|
|
442
|
-
await new Promise((r) => setTimeout(r, 100));
|
|
443
|
-
|
|
444
|
-
(updateStickyState as jest.Mock).mockClear();
|
|
445
|
-
triggerElementIntersect({
|
|
446
|
-
target: sentinelBottom,
|
|
447
|
-
isIntersecting: false,
|
|
448
|
-
rootBounds: { bottom: 0, top: 0 },
|
|
449
|
-
boundingClientRect: { bottom: 0, top: -100 },
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
// sets to not sticky when bottom sentinel is outside scroll area
|
|
453
|
-
// and above scroll container top by more than header height
|
|
454
|
-
expect(updateStickyState).toHaveBeenCalledWith(
|
|
455
|
-
expect.objectContaining({
|
|
456
|
-
sticky: false,
|
|
457
|
-
}),
|
|
458
|
-
);
|
|
459
|
-
});
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
it.each([
|
|
463
|
-
['with contentRect supported', true],
|
|
464
|
-
['with contentRect not supported', false],
|
|
465
|
-
])(
|
|
466
|
-
'updates sentinel position when header height changes %s',
|
|
467
|
-
(_, contentRectSupported: boolean) => {
|
|
468
|
-
const { tableWrapper } = getTableElements(tableRowDom);
|
|
469
|
-
// disabled due to editorView dom being cleared by use of contentDom mocks
|
|
470
|
-
renderTableComponent({
|
|
471
|
-
disableContentDomMock: true,
|
|
472
|
-
});
|
|
473
|
-
const sentinelBottom = screen.getByTestId('sticky-sentinel-bottom');
|
|
474
|
-
tableWrapper?.appendChild(sentinelBottom);
|
|
475
|
-
rafStub.flush();
|
|
476
|
-
|
|
477
|
-
expect(sentinelBottom.style.bottom).toBe('');
|
|
478
|
-
|
|
479
|
-
const newHeight = 10;
|
|
480
|
-
triggerElementResize(tableRowDom, newHeight, contentRectSupported);
|
|
481
|
-
|
|
482
|
-
expect(sentinelBottom.style.bottom).toBe(
|
|
483
|
-
`${newHeight + tableScrollbarOffset + stickyRowOffsetTop}px`,
|
|
484
|
-
);
|
|
485
|
-
},
|
|
486
|
-
);
|
|
487
|
-
|
|
488
|
-
it('marks sentinels as unobserved when isHeaderRowEnabled is set to false', () => {
|
|
489
|
-
const { tableWrapper } = getTableElements(tableRowDom);
|
|
490
|
-
// disabled due to editorView dom being cleared by use of contentDom mocks
|
|
491
|
-
renderTableComponent({
|
|
492
|
-
disableContentDomMock: true,
|
|
493
|
-
});
|
|
494
|
-
const sentinelBottom = screen.getByTestId('sticky-sentinel-bottom');
|
|
495
|
-
tableWrapper?.appendChild(sentinelBottom);
|
|
496
|
-
rafStub.flush();
|
|
497
|
-
expect(sentinelBottom.dataset.isObserved).toBeDefined();
|
|
498
|
-
eventDispatcher.emit((pluginKey as any).key, {
|
|
499
|
-
isHeaderRowEnabled: false,
|
|
500
|
-
});
|
|
501
|
-
expect(sentinelBottom.dataset.isObserved).toBeUndefined();
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
describe('makeRowHeaderNotSticky', () => {
|
|
506
|
-
let makeRowHeaderNotStickySpy: jest.SpyInstance;
|
|
507
|
-
let tableRef: HTMLElement;
|
|
508
|
-
beforeEach(() => {
|
|
509
|
-
const editorData = editor(
|
|
510
|
-
doc(table()(tr(thEmpty, thEmpty), tr(tdEmpty, tdEmpty))),
|
|
511
|
-
);
|
|
512
|
-
editorView = editorData.editorView;
|
|
513
|
-
eventDispatcher = editorData.eventDispatcher;
|
|
514
|
-
tableRowNode = editorView.state.doc.firstChild!.firstChild!;
|
|
515
|
-
tableRowDom = editorView.dom.getElementsByTagName('tr')[0];
|
|
516
|
-
|
|
517
|
-
tableRowNodeView = new TableRow(
|
|
518
|
-
tableRowNode,
|
|
519
|
-
editorView,
|
|
520
|
-
() => 0,
|
|
521
|
-
eventDispatcher,
|
|
522
|
-
);
|
|
523
|
-
tableRowNodeView.dom = tableRowDom;
|
|
524
|
-
|
|
525
|
-
makeRowHeaderNotStickySpy = jest.spyOn(
|
|
526
|
-
tableRowNodeView as any,
|
|
527
|
-
'makeRowHeaderNotSticky',
|
|
528
|
-
);
|
|
529
|
-
tableRef = document.querySelector(
|
|
530
|
-
'.ProseMirror table',
|
|
531
|
-
) as HTMLTableElement;
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
afterEach(() => {
|
|
535
|
-
jest.clearAllMocks();
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
it('should not be called if table is not selected', () => {
|
|
539
|
-
eventDispatcher.emit((pluginKey as any).key, {
|
|
540
|
-
isHeaderRowEnabled: false,
|
|
541
|
-
tableRef: null,
|
|
542
|
-
});
|
|
543
|
-
expect(makeRowHeaderNotStickySpy).not.toHaveBeenCalled();
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
it('should not be called if header row is enabled', () => {
|
|
547
|
-
eventDispatcher.emit((pluginKey as any).key, {
|
|
548
|
-
isHeaderRowEnabled: true,
|
|
549
|
-
tableRef,
|
|
550
|
-
});
|
|
551
|
-
expect(makeRowHeaderNotStickySpy).not.toHaveBeenCalled();
|
|
552
|
-
});
|
|
553
|
-
|
|
554
|
-
it('should be called if header row is disabled and table is selected', () => {
|
|
555
|
-
eventDispatcher.emit((pluginKey as any).key, {
|
|
556
|
-
isHeaderRowEnabled: false,
|
|
557
|
-
tableRef,
|
|
558
|
-
});
|
|
559
|
-
expect(makeRowHeaderNotStickySpy).toHaveBeenCalled();
|
|
560
|
-
});
|
|
561
|
-
});
|
|
562
|
-
});
|