@atlaskit/editor-plugin-table 7.2.1 → 7.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/nodeviews/TableComponent.js +11 -7
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +11 -25
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +13 -3
- package/dist/cjs/ui/TableFloatingColumnControls/index.js +7 -3
- package/dist/cjs/utils/drag-menu.js +37 -23
- package/dist/cjs/utils/merged-cells.js +66 -1
- package/dist/es2019/nodeviews/TableComponent.js +9 -5
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
- package/dist/es2019/ui/TableFloatingColumnControls/index.js +7 -3
- package/dist/es2019/utils/drag-menu.js +38 -14
- package/dist/es2019/utils/merged-cells.js +73 -0
- package/dist/esm/nodeviews/TableComponent.js +11 -7
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
- package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
- package/dist/esm/ui/TableFloatingColumnControls/index.js +7 -3
- package/dist/esm/utils/drag-menu.js +36 -22
- package/dist/esm/utils/merged-cells.js +65 -0
- package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
- package/dist/types/ui/TableFloatingColumnControls/index.d.ts +1 -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/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +1 -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/nodeviews/TableComponent.tsx +1 -0
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +6 -27
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -1
- package/src/ui/TableFloatingColumnControls/index.tsx +5 -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 -871
- 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,525 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
4
|
-
|
|
5
|
-
import type { TableAttributes } from '@atlaskit/adf-schema';
|
|
6
|
-
import {
|
|
7
|
-
ACTION_SUBJECT,
|
|
8
|
-
EVENT_TYPE,
|
|
9
|
-
TABLE_ACTION,
|
|
10
|
-
} from '@atlaskit/editor-common/analytics';
|
|
11
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
12
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
13
|
-
import { akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
14
|
-
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
15
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
16
|
-
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
17
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
18
|
-
import {
|
|
19
|
-
doc,
|
|
20
|
-
p,
|
|
21
|
-
table,
|
|
22
|
-
td,
|
|
23
|
-
tdEmpty,
|
|
24
|
-
tr,
|
|
25
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
26
|
-
import { ffTest } from '@atlassian/feature-flags-test-utils';
|
|
27
|
-
|
|
28
|
-
import {
|
|
29
|
-
ResizableTableContainer,
|
|
30
|
-
TableContainer,
|
|
31
|
-
} from '../../../nodeviews/TableContainer';
|
|
32
|
-
import tablePlugin from '../../../plugin';
|
|
33
|
-
import { pluginKey } from '../../../pm-plugins/plugin-key';
|
|
34
|
-
import { pluginKey as tableResizingPluginKey } from '../../../pm-plugins/table-width';
|
|
35
|
-
import type { TablePluginState } from '../../../types';
|
|
36
|
-
|
|
37
|
-
const mockStartMeasure = jest.fn();
|
|
38
|
-
const mockEndMeasure = jest.fn(() => {
|
|
39
|
-
return [51, 52, 53, 54];
|
|
40
|
-
});
|
|
41
|
-
const mockCountFrames = jest.fn();
|
|
42
|
-
|
|
43
|
-
jest.mock('../../../utils/analytics', () => ({
|
|
44
|
-
...jest.requireActual('../../../utils/analytics'),
|
|
45
|
-
useMeasureFramerate: () => {
|
|
46
|
-
return {
|
|
47
|
-
startMeasure: mockStartMeasure,
|
|
48
|
-
endMeasure: mockEndMeasure,
|
|
49
|
-
countFrames: mockCountFrames,
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
jest.mock('react-intl-next', () => {
|
|
55
|
-
return {
|
|
56
|
-
...(jest.requireActual('react-intl-next') as any),
|
|
57
|
-
useIntl: jest.fn().mockReturnValue({
|
|
58
|
-
formatMessage: (descriptor: any) => descriptor.defaultMessage,
|
|
59
|
-
}),
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
64
|
-
const createEditor = createEditorFactory<TablePluginState>();
|
|
65
|
-
const editor = (
|
|
66
|
-
doc: DocBuilder,
|
|
67
|
-
featureFlags?: { [featureFlag: string]: string | boolean },
|
|
68
|
-
) => {
|
|
69
|
-
return createEditor({
|
|
70
|
-
doc,
|
|
71
|
-
editorProps: {
|
|
72
|
-
appearance: 'full-page',
|
|
73
|
-
allowTables: false,
|
|
74
|
-
dangerouslyAppendPlugins: {
|
|
75
|
-
__plugins: [
|
|
76
|
-
tablePlugin({
|
|
77
|
-
config: { tableResizingEnabled: true, tableOptions: {} },
|
|
78
|
-
}),
|
|
79
|
-
],
|
|
80
|
-
},
|
|
81
|
-
featureFlags,
|
|
82
|
-
},
|
|
83
|
-
pluginKey,
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
const createNode = (attrs?: TableAttributes) => {
|
|
87
|
-
const { editorView } = editor(
|
|
88
|
-
doc(table(attrs)(tr(td()(p('{<>}text')), tdEmpty, tdEmpty))),
|
|
89
|
-
);
|
|
90
|
-
const resolvedTable = findTable(editorView.state.selection);
|
|
91
|
-
|
|
92
|
-
return { table: resolvedTable!.node, editorView };
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
describe('show correct table container', () => {
|
|
96
|
-
const buildContainer = (
|
|
97
|
-
isTableResizingEnabled: boolean,
|
|
98
|
-
isBreakoutEnabled: boolean = true,
|
|
99
|
-
) => {
|
|
100
|
-
const { table, editorView } = createNode();
|
|
101
|
-
|
|
102
|
-
const { container } = render(
|
|
103
|
-
<TableContainer
|
|
104
|
-
containerWidth={{
|
|
105
|
-
width: 1800,
|
|
106
|
-
lineLength: 720,
|
|
107
|
-
}}
|
|
108
|
-
node={table}
|
|
109
|
-
isTableResizingEnabled={isTableResizingEnabled}
|
|
110
|
-
isBreakoutEnabled={isBreakoutEnabled}
|
|
111
|
-
className={''}
|
|
112
|
-
editorView={editorView}
|
|
113
|
-
getPos={() => 1}
|
|
114
|
-
tableRef={{} as any}
|
|
115
|
-
isNested={false}
|
|
116
|
-
/>,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
return container;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
test('should wrap table in resizer when isTableResizingEnabled is true', () => {
|
|
123
|
-
const container = buildContainer(true);
|
|
124
|
-
expect(!!container.querySelector('.resizer-item')).toBeTruthy();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('should not wrap table in resizer when isTableResizingEnabled is false', () => {
|
|
128
|
-
const container = buildContainer(false);
|
|
129
|
-
expect(!!container.querySelector('.resizer-item')).toBeFalsy();
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe('should focus resize handle thumb after Cmd + Opt + R key comibnation is pressed', () => {
|
|
134
|
-
let originalScrollBy: typeof window.scrollBy;
|
|
135
|
-
let originalScrollIntoView: typeof window.HTMLElement.prototype.scrollIntoView;
|
|
136
|
-
|
|
137
|
-
beforeEach(() => {
|
|
138
|
-
originalScrollBy = window.scrollBy;
|
|
139
|
-
originalScrollIntoView = window.HTMLElement.prototype.scrollIntoView;
|
|
140
|
-
|
|
141
|
-
window.scrollBy = jest.fn();
|
|
142
|
-
window.HTMLElement.prototype.scrollIntoView = jest.fn();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
afterEach(() => {
|
|
146
|
-
window.scrollBy = originalScrollBy;
|
|
147
|
-
window.HTMLElement.prototype.scrollIntoView = originalScrollIntoView;
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const buildContainer = (
|
|
151
|
-
isTableResizingEnabled: boolean,
|
|
152
|
-
isBreakoutEnabled: boolean = true,
|
|
153
|
-
) => {
|
|
154
|
-
const { table, editorView } = createNode();
|
|
155
|
-
|
|
156
|
-
const { container } = render(
|
|
157
|
-
<TableContainer
|
|
158
|
-
containerWidth={{
|
|
159
|
-
width: 1800,
|
|
160
|
-
lineLength: 720,
|
|
161
|
-
}}
|
|
162
|
-
node={table}
|
|
163
|
-
isTableResizingEnabled={isTableResizingEnabled}
|
|
164
|
-
isBreakoutEnabled={isBreakoutEnabled}
|
|
165
|
-
className={''}
|
|
166
|
-
editorView={editorView}
|
|
167
|
-
getPos={() => 1}
|
|
168
|
-
tableRef={{} as any}
|
|
169
|
-
isNested={false}
|
|
170
|
-
/>,
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
return container;
|
|
174
|
-
};
|
|
175
|
-
ffTest(
|
|
176
|
-
'platform.editor.a11y-table-resizing_uapcv',
|
|
177
|
-
() => {
|
|
178
|
-
const { editorView } = createNode();
|
|
179
|
-
const container = buildContainer(true);
|
|
180
|
-
const resizerThumbHandle = container.querySelector(
|
|
181
|
-
'[data-testid="resizer-handle-right-thumb"',
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
fireEvent.keyDown(editorView.dom, {
|
|
185
|
-
key: 'R',
|
|
186
|
-
code: 'KeyR',
|
|
187
|
-
altKey: true,
|
|
188
|
-
metaKey: browser.mac,
|
|
189
|
-
shiftKey: true,
|
|
190
|
-
ctrlKey: !browser.mac,
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
expect(resizerThumbHandle).toStrictEqual(document.activeElement);
|
|
194
|
-
},
|
|
195
|
-
() => {
|
|
196
|
-
const { editorView } = createNode();
|
|
197
|
-
const container = buildContainer(true);
|
|
198
|
-
const resizerThumbHandle = container.querySelector(
|
|
199
|
-
'[data-testid="resizer-handle-right-thumb"',
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
fireEvent.keyDown(editorView.dom, {
|
|
203
|
-
key: 'R',
|
|
204
|
-
code: 'KeyR',
|
|
205
|
-
altKey: true,
|
|
206
|
-
metaKey: browser.mac,
|
|
207
|
-
shiftKey: true,
|
|
208
|
-
ctrlKey: !browser.mac,
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
expect(resizerThumbHandle).not.toStrictEqual(document.activeElement);
|
|
212
|
-
},
|
|
213
|
-
);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
describe('when table is nested', () => {
|
|
217
|
-
const buildContainer = (
|
|
218
|
-
isTableResizingEnabled: boolean,
|
|
219
|
-
isBreakoutEnabled: boolean = true,
|
|
220
|
-
) => {
|
|
221
|
-
const { table, editorView } = createNode();
|
|
222
|
-
|
|
223
|
-
const { container } = render(
|
|
224
|
-
<TableContainer
|
|
225
|
-
containerWidth={{
|
|
226
|
-
width: 1800,
|
|
227
|
-
lineLength: 720,
|
|
228
|
-
}}
|
|
229
|
-
node={table}
|
|
230
|
-
isTableResizingEnabled={isTableResizingEnabled}
|
|
231
|
-
isBreakoutEnabled={isBreakoutEnabled}
|
|
232
|
-
className={''}
|
|
233
|
-
editorView={editorView}
|
|
234
|
-
getPos={() => 1}
|
|
235
|
-
tableRef={{} as any}
|
|
236
|
-
isNested={true}
|
|
237
|
-
/>,
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
return container;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
test('should not render resizer when isTableResizingEnabled is true', () => {
|
|
244
|
-
const container = buildContainer(true);
|
|
245
|
-
expect(!!container.querySelector('.resizer-item')).toBeFalsy();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
test('should not render resizer when isTableResizingEnabled is false', () => {
|
|
249
|
-
const container = buildContainer(false);
|
|
250
|
-
expect(!!container.querySelector('.resizer-item')).toBeFalsy();
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
describe('sets width and margin correctly for resizable container', () => {
|
|
255
|
-
const buildContainer = (attrs: TableAttributes) => {
|
|
256
|
-
const { table, editorView } = createNode(attrs);
|
|
257
|
-
|
|
258
|
-
const { container } = render(
|
|
259
|
-
<ResizableTableContainer
|
|
260
|
-
containerWidth={1800}
|
|
261
|
-
node={table}
|
|
262
|
-
className={''}
|
|
263
|
-
editorView={editorView}
|
|
264
|
-
getPos={() => 1}
|
|
265
|
-
tableRef={{} as any}
|
|
266
|
-
/>,
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
return container;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
test('when width attribute is not set', () => {
|
|
273
|
-
const container = buildContainer({ layout: 'wide' });
|
|
274
|
-
const style = window.getComputedStyle(
|
|
275
|
-
container.firstChild?.firstChild as Element,
|
|
276
|
-
);
|
|
277
|
-
expect(style.width).toBe(`${akEditorWideLayoutWidth}px`);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
describe('analytics', () => {
|
|
282
|
-
const buildContainer = (attrs: TableAttributes) => {
|
|
283
|
-
const { table, editorView } = createNode(attrs);
|
|
284
|
-
const analyticsMock = jest.fn();
|
|
285
|
-
|
|
286
|
-
const { container } = render(
|
|
287
|
-
<ResizableTableContainer
|
|
288
|
-
containerWidth={1800}
|
|
289
|
-
node={table}
|
|
290
|
-
className={''}
|
|
291
|
-
editorView={editorView}
|
|
292
|
-
getPos={() => 0}
|
|
293
|
-
tableRef={
|
|
294
|
-
{
|
|
295
|
-
querySelector: () => null,
|
|
296
|
-
insertBefore: () => {},
|
|
297
|
-
style: {},
|
|
298
|
-
} as any
|
|
299
|
-
}
|
|
300
|
-
pluginInjectionApi={
|
|
301
|
-
{
|
|
302
|
-
analytics: { actions: { attachAnalyticsEvent: analyticsMock } },
|
|
303
|
-
} as any
|
|
304
|
-
}
|
|
305
|
-
tableResizePerformance={true}
|
|
306
|
-
/>,
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
return { container, analyticsMock };
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
test('fires when resizing is finished', async () => {
|
|
313
|
-
const { container, analyticsMock } = buildContainer({ layout: 'wide' });
|
|
314
|
-
|
|
315
|
-
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
316
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
317
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
318
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
319
|
-
fireEvent.mouseUp(container.querySelector('.resizer-handle.right')!);
|
|
320
|
-
|
|
321
|
-
expect(analyticsMock).toHaveBeenNthCalledWith(1, {
|
|
322
|
-
action: TABLE_ACTION.RESIZE_PERF_SAMPLING,
|
|
323
|
-
actionSubject: ACTION_SUBJECT.TABLE,
|
|
324
|
-
eventType: EVENT_TYPE.OPERATIONAL,
|
|
325
|
-
attributes: {
|
|
326
|
-
docSize: 22,
|
|
327
|
-
frameRate: 51,
|
|
328
|
-
isInitialSample: true,
|
|
329
|
-
nodeSize: 20,
|
|
330
|
-
experiments: {
|
|
331
|
-
tableResizePerformance: true,
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
expect(analyticsMock).toHaveBeenNthCalledWith(2, {
|
|
337
|
-
action: TABLE_ACTION.RESIZE_PERF_SAMPLING,
|
|
338
|
-
actionSubject: ACTION_SUBJECT.TABLE,
|
|
339
|
-
eventType: EVENT_TYPE.OPERATIONAL,
|
|
340
|
-
attributes: {
|
|
341
|
-
docSize: 22,
|
|
342
|
-
frameRate: 53,
|
|
343
|
-
isInitialSample: false,
|
|
344
|
-
nodeSize: 20,
|
|
345
|
-
experiments: {
|
|
346
|
-
tableResizePerformance: true,
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
expect(analyticsMock).toHaveBeenNthCalledWith(3, {
|
|
352
|
-
action: TABLE_ACTION.RESIZED,
|
|
353
|
-
actionSubject: ACTION_SUBJECT.TABLE,
|
|
354
|
-
eventType: EVENT_TYPE.TRACK,
|
|
355
|
-
attributes: {
|
|
356
|
-
newWidth: 0, // Can't get the events right to trigger re-resizeable
|
|
357
|
-
prevWidth: 960,
|
|
358
|
-
nodeSize: 20,
|
|
359
|
-
totalTableWidth: null,
|
|
360
|
-
totalRowCount: 1,
|
|
361
|
-
totalColumnCount: 3,
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
analyticsMock.mockReset();
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
test('calls useMeasureFramerate handlers', async () => {
|
|
369
|
-
const { container } = buildContainer({ layout: 'wide' });
|
|
370
|
-
|
|
371
|
-
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
372
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!, {
|
|
373
|
-
clientX: 100,
|
|
374
|
-
});
|
|
375
|
-
fireEvent.mouseUp(container.querySelector('.resizer-handle.right')!);
|
|
376
|
-
|
|
377
|
-
expect(mockStartMeasure).toHaveBeenCalled();
|
|
378
|
-
expect(mockEndMeasure).toHaveBeenCalled();
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
describe('selection', () => {
|
|
383
|
-
const selectionActionMock = jest.fn().mockReturnValue(() => {});
|
|
384
|
-
|
|
385
|
-
const buildContainer = (attrs: TableAttributes) => {
|
|
386
|
-
const { table, editorView } = createNode(attrs);
|
|
387
|
-
|
|
388
|
-
const { container } = render(
|
|
389
|
-
<ResizableTableContainer
|
|
390
|
-
containerWidth={1800}
|
|
391
|
-
node={table}
|
|
392
|
-
className={''}
|
|
393
|
-
editorView={editorView}
|
|
394
|
-
getPos={() => 0}
|
|
395
|
-
tableRef={
|
|
396
|
-
{
|
|
397
|
-
querySelector: () => null,
|
|
398
|
-
insertBefore: () => {},
|
|
399
|
-
style: {},
|
|
400
|
-
} as any
|
|
401
|
-
}
|
|
402
|
-
pluginInjectionApi={
|
|
403
|
-
{
|
|
404
|
-
selection: {
|
|
405
|
-
commands: { displayGapCursor: selectionActionMock },
|
|
406
|
-
},
|
|
407
|
-
// mock core so the selection command will execute
|
|
408
|
-
core: { actions: { execute: jest.fn() } },
|
|
409
|
-
} as any
|
|
410
|
-
}
|
|
411
|
-
/>,
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
return { container, selectionActionMock };
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
afterEach(() => {
|
|
418
|
-
selectionActionMock.mockRestore();
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it('fires selection action to hide gap cursor when present', () => {
|
|
422
|
-
const { container, selectionActionMock } = buildContainer({
|
|
423
|
-
layout: 'wide',
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
427
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
428
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
429
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
430
|
-
fireEvent.mouseUp(container.querySelector('.resizer-handle.right')!);
|
|
431
|
-
|
|
432
|
-
// when resize starts - call to hide gap cursor
|
|
433
|
-
expect(selectionActionMock).toHaveBeenNthCalledWith(1, false);
|
|
434
|
-
// when resize finishes - call to display gap cursor
|
|
435
|
-
expect(selectionActionMock).toHaveBeenNthCalledWith(2, true);
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
describe('deletion', () => {
|
|
440
|
-
const selectionActionMock = jest.fn().mockReturnValue(() => {});
|
|
441
|
-
const actualGuidelineMock = jest.fn();
|
|
442
|
-
const guidelineActionMock = jest.fn().mockReturnValue(actualGuidelineMock);
|
|
443
|
-
const buildContainer = (attrs: TableAttributes) => {
|
|
444
|
-
const { table, editorView } = createNode(attrs);
|
|
445
|
-
|
|
446
|
-
const { container, unmount } = render(
|
|
447
|
-
<ResizableTableContainer
|
|
448
|
-
containerWidth={1800}
|
|
449
|
-
node={table}
|
|
450
|
-
className={''}
|
|
451
|
-
editorView={editorView}
|
|
452
|
-
getPos={() => 0}
|
|
453
|
-
tableRef={
|
|
454
|
-
{
|
|
455
|
-
querySelector: () => null,
|
|
456
|
-
insertBefore: () => {},
|
|
457
|
-
style: {},
|
|
458
|
-
} as any
|
|
459
|
-
}
|
|
460
|
-
pluginInjectionApi={
|
|
461
|
-
{
|
|
462
|
-
selection: {
|
|
463
|
-
commands: { displayGapCursor: selectionActionMock },
|
|
464
|
-
},
|
|
465
|
-
guideline: {
|
|
466
|
-
actions: { displayGuideline: guidelineActionMock },
|
|
467
|
-
},
|
|
468
|
-
// mock core so the selection command will execute
|
|
469
|
-
core: { actions: { execute: jest.fn() } },
|
|
470
|
-
} as any
|
|
471
|
-
}
|
|
472
|
-
/>,
|
|
473
|
-
);
|
|
474
|
-
|
|
475
|
-
return {
|
|
476
|
-
container,
|
|
477
|
-
unmount,
|
|
478
|
-
editorView,
|
|
479
|
-
selectionActionMock,
|
|
480
|
-
actualGuidelineMock,
|
|
481
|
-
};
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
afterEach(() => {
|
|
485
|
-
selectionActionMock.mockClear();
|
|
486
|
-
actualGuidelineMock.mockClear();
|
|
487
|
-
guidelineActionMock.mockClear();
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
// this is testing logic inside TableResizer, targeting the clean up in the useEffect
|
|
491
|
-
it('should call selection plugin action to display gapcursor when removed', () => {
|
|
492
|
-
const { container, unmount, selectionActionMock } = buildContainer({});
|
|
493
|
-
|
|
494
|
-
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
495
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
496
|
-
|
|
497
|
-
unmount();
|
|
498
|
-
expect(selectionActionMock).toHaveBeenCalledWith(true);
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
// this is testing logic inside TableResizer, targeting the clean up in the useEffect
|
|
502
|
-
it('should call guideline plugin action to remove guidelines when removed', () => {
|
|
503
|
-
const { container, unmount, actualGuidelineMock } = buildContainer({});
|
|
504
|
-
|
|
505
|
-
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
506
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
507
|
-
|
|
508
|
-
unmount();
|
|
509
|
-
expect(actualGuidelineMock).toHaveBeenCalledWith({ guidelines: [] });
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
// this is testing logic inside TableResizer, targeting the clean up in the useEffect
|
|
513
|
-
it('should call restore resizing plugin state when removed', () => {
|
|
514
|
-
const { container, unmount, editorView } = buildContainer({});
|
|
515
|
-
|
|
516
|
-
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
517
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
518
|
-
|
|
519
|
-
unmount();
|
|
520
|
-
expect(tableResizingPluginKey.getState(editorView.state)).toStrictEqual({
|
|
521
|
-
resizing: false,
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
});
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
rgbToHex,
|
|
3
|
-
tableBackgroundColorNames,
|
|
4
|
-
uuid,
|
|
5
|
-
} from '@atlaskit/adf-schema';
|
|
6
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
7
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
8
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
9
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
10
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
11
|
-
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
12
|
-
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
13
|
-
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
14
|
-
import {
|
|
15
|
-
findCellClosestToPos,
|
|
16
|
-
setCellAttrs,
|
|
17
|
-
} from '@atlaskit/editor-tables/utils';
|
|
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
|
-
p,
|
|
29
|
-
table,
|
|
30
|
-
td,
|
|
31
|
-
tdEmpty,
|
|
32
|
-
tr,
|
|
33
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
34
|
-
|
|
35
|
-
import TableCell from '../../../nodeviews/TableCell';
|
|
36
|
-
import tablePlugin from '../../../plugin';
|
|
37
|
-
import { pluginKey } from '../../../pm-plugins/plugin-key';
|
|
38
|
-
import type { PluginConfig } from '../../../types';
|
|
39
|
-
|
|
40
|
-
jest.mock('@atlaskit/editor-common/utils', () => ({
|
|
41
|
-
...jest.requireActual<Object>('@atlaskit/editor-common/utils'),
|
|
42
|
-
browser: {
|
|
43
|
-
chrome: false,
|
|
44
|
-
},
|
|
45
|
-
}));
|
|
46
|
-
|
|
47
|
-
describe('table -> nodeviews -> tableCell.tsx', () => {
|
|
48
|
-
const TABLE_LOCAL_ID = 'test-table-local-id';
|
|
49
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
50
|
-
|
|
51
|
-
const editor = (doc: DocBuilder, props?: PluginConfig) =>
|
|
52
|
-
createEditor({
|
|
53
|
-
doc,
|
|
54
|
-
attachTo: document.body,
|
|
55
|
-
preset: new Preset<LightEditorPlugin>()
|
|
56
|
-
.add([featureFlagsPlugin, {}])
|
|
57
|
-
.add([analyticsPlugin, {}])
|
|
58
|
-
.add(contentInsertionPlugin)
|
|
59
|
-
.add(widthPlugin)
|
|
60
|
-
.add(guidelinePlugin)
|
|
61
|
-
.add(selectionPlugin)
|
|
62
|
-
.add([tablePlugin, { tableOptions: { advanced: true, ...props } }]),
|
|
63
|
-
pluginKey,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('when background color is set to "red"', () => {
|
|
67
|
-
beforeAll(() => {
|
|
68
|
-
uuid.setStatic(TABLE_LOCAL_ID);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
beforeEach(() => {
|
|
72
|
-
jest.clearAllMocks();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should update cell DOM node style attribute with the new color', () => {
|
|
76
|
-
const {
|
|
77
|
-
editorView,
|
|
78
|
-
refs: { pos },
|
|
79
|
-
} = editor(
|
|
80
|
-
doc(p('text'), table()(tr(td()(p('{pos}text')), tdEmpty, tdEmpty))),
|
|
81
|
-
);
|
|
82
|
-
const { state, dispatch } = editorView;
|
|
83
|
-
const cell = findCellClosestToPos(state.doc.resolve(pos))!;
|
|
84
|
-
const background = tableBackgroundColorNames.get('red');
|
|
85
|
-
dispatch(setCellAttrs(cell, { background })(state.tr));
|
|
86
|
-
const cellDomNode = document.querySelector('td')!;
|
|
87
|
-
expect(rgbToHex(cellDomNode.style.backgroundColor!)).toEqual(background);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('when background color is set to "white"', () => {
|
|
92
|
-
it('should remove backgroundColor style attribute from cell DOM node ', () => {
|
|
93
|
-
const {
|
|
94
|
-
editorView,
|
|
95
|
-
refs: { pos },
|
|
96
|
-
} = editor(
|
|
97
|
-
doc(
|
|
98
|
-
p('text'),
|
|
99
|
-
table()(
|
|
100
|
-
tr(td({ background: 'red' })(p('{pos}text')), tdEmpty, tdEmpty),
|
|
101
|
-
),
|
|
102
|
-
),
|
|
103
|
-
);
|
|
104
|
-
const { state, dispatch } = editorView;
|
|
105
|
-
const cell = findCellClosestToPos(state.doc.resolve(pos))!;
|
|
106
|
-
const background = tableBackgroundColorNames.get('white');
|
|
107
|
-
dispatch(setCellAttrs(cell, { background })(state.tr));
|
|
108
|
-
const cellDomNode = document.querySelector('td')!;
|
|
109
|
-
expect(cellDomNode.style.backgroundColor).toEqual('');
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('nodeview update', () => {
|
|
114
|
-
it('should not recreate nodeviews on attrs update', () => {
|
|
115
|
-
const {
|
|
116
|
-
editorView,
|
|
117
|
-
refs: { pos },
|
|
118
|
-
} = editor(
|
|
119
|
-
doc(p('text'), table()(tr(td()(p('{pos}text')), tdEmpty, tdEmpty))),
|
|
120
|
-
{},
|
|
121
|
-
);
|
|
122
|
-
const { state, dispatch } = editorView;
|
|
123
|
-
const cell = findCellClosestToPos(state.doc.resolve(pos))!;
|
|
124
|
-
const background = tableBackgroundColorNames.get('red');
|
|
125
|
-
const updateSpy = jest.spyOn(TableCell.prototype, 'update');
|
|
126
|
-
dispatch(setCellAttrs(cell, { background })(state.tr));
|
|
127
|
-
expect(updateSpy).toHaveReturnedWith(true);
|
|
128
|
-
const cellDomNode = document.querySelector('td')!;
|
|
129
|
-
expect(rgbToHex(cellDomNode.style.backgroundColor!)).toEqual(background);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|