@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,269 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
2
|
-
import {
|
|
3
|
-
p,
|
|
4
|
-
table,
|
|
5
|
-
td,
|
|
6
|
-
th,
|
|
7
|
-
tr,
|
|
8
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
9
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
10
|
-
import defaultSchema from '@atlaskit/editor-test-helpers/schema';
|
|
11
|
-
import { ffTest } from '@atlassian/feature-flags-test-utils';
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
generateColgroup,
|
|
15
|
-
getColgroupChildrenLength,
|
|
16
|
-
} from '../../../../pm-plugins/table-resizing/utils';
|
|
17
|
-
import { isMinCellWidthTable } from '../../../../pm-plugins/table-resizing/utils/colgroup';
|
|
18
|
-
|
|
19
|
-
describe('table-resizing/colgroup', () => {
|
|
20
|
-
describe('#generateColgroup', () => {
|
|
21
|
-
describe('creates col with correct widths', () => {
|
|
22
|
-
describe('based on colwidth cell attributes', () => {
|
|
23
|
-
ffTest(
|
|
24
|
-
'platform.editor.custom-table-width',
|
|
25
|
-
() => {
|
|
26
|
-
const result = generateColgroup(
|
|
27
|
-
getTable([
|
|
28
|
-
{
|
|
29
|
-
colwidth: [10],
|
|
30
|
-
colspan: 1,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
colwidth: [20],
|
|
34
|
-
colspan: 1,
|
|
35
|
-
},
|
|
36
|
-
]),
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
expect(result).toEqual([
|
|
40
|
-
['col', { style: 'width: 47.5px;' }],
|
|
41
|
-
['col', { style: 'width: 47.5px;' }],
|
|
42
|
-
]);
|
|
43
|
-
},
|
|
44
|
-
() => {
|
|
45
|
-
const result = generateColgroup(
|
|
46
|
-
getTable([
|
|
47
|
-
{
|
|
48
|
-
colwidth: [10],
|
|
49
|
-
colspan: 1,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
colwidth: [20],
|
|
53
|
-
colspan: 1,
|
|
54
|
-
},
|
|
55
|
-
]),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
expect(result).toEqual([
|
|
59
|
-
['col', { style: 'width: 10px;' }],
|
|
60
|
-
['col', { style: 'width: 20px;' }],
|
|
61
|
-
]);
|
|
62
|
-
},
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('when colwidth is not an array', () => {
|
|
67
|
-
ffTest(
|
|
68
|
-
'platform.editor.custom-table-width',
|
|
69
|
-
() => {
|
|
70
|
-
const result = generateColgroup(
|
|
71
|
-
getTable([
|
|
72
|
-
{
|
|
73
|
-
colwidth: 10,
|
|
74
|
-
colspan: 1,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
colwidth: null,
|
|
78
|
-
colspan: 1,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
colwidth: undefined,
|
|
82
|
-
colspan: 1,
|
|
83
|
-
},
|
|
84
|
-
]),
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
expect(result).toEqual([
|
|
88
|
-
['col', { style: 'width: 48px;' }],
|
|
89
|
-
['col', { style: 'width: 48px;' }],
|
|
90
|
-
['col', { style: 'width: 48px;' }],
|
|
91
|
-
]);
|
|
92
|
-
},
|
|
93
|
-
() => {
|
|
94
|
-
const result = generateColgroup(
|
|
95
|
-
getTable([
|
|
96
|
-
{
|
|
97
|
-
colwidth: 10,
|
|
98
|
-
colspan: 1,
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
colwidth: null,
|
|
102
|
-
colspan: 1,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
colwidth: undefined,
|
|
106
|
-
colspan: 1,
|
|
107
|
-
},
|
|
108
|
-
]),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(result).toEqual([
|
|
112
|
-
['col', {}],
|
|
113
|
-
['col', {}],
|
|
114
|
-
['col', {}],
|
|
115
|
-
]);
|
|
116
|
-
},
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('when colwidth has falsy values', () => {
|
|
121
|
-
ffTest(
|
|
122
|
-
'platform.editor.custom-table-width',
|
|
123
|
-
() => {
|
|
124
|
-
const result = generateColgroup(
|
|
125
|
-
getTable([
|
|
126
|
-
{
|
|
127
|
-
colwidth: [0],
|
|
128
|
-
colspan: 1,
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
colwidth: [null],
|
|
132
|
-
colspan: 1,
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
colwidth: [undefined],
|
|
136
|
-
colspan: 1,
|
|
137
|
-
},
|
|
138
|
-
]),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
expect(result).toEqual(
|
|
142
|
-
expect.arrayContaining([
|
|
143
|
-
// (.666*) -> match unknown number of 6's
|
|
144
|
-
// (.?) -> match rounding errors e.g. 47.6666664px
|
|
145
|
-
[
|
|
146
|
-
'col',
|
|
147
|
-
{ style: expect.stringMatching(/^width: 47.666*.?px/) },
|
|
148
|
-
],
|
|
149
|
-
[
|
|
150
|
-
'col',
|
|
151
|
-
{ style: expect.stringMatching(/^width: 47.666*.?px/) },
|
|
152
|
-
],
|
|
153
|
-
[
|
|
154
|
-
'col',
|
|
155
|
-
{ style: expect.stringMatching(/^width: 47.666*.?px/) },
|
|
156
|
-
],
|
|
157
|
-
]),
|
|
158
|
-
);
|
|
159
|
-
},
|
|
160
|
-
() => {
|
|
161
|
-
const result = generateColgroup(
|
|
162
|
-
getTable([
|
|
163
|
-
{
|
|
164
|
-
colwidth: [0],
|
|
165
|
-
colspan: 1,
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
colwidth: [null],
|
|
169
|
-
colspan: 1,
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
colwidth: [undefined],
|
|
173
|
-
colspan: 1,
|
|
174
|
-
},
|
|
175
|
-
]),
|
|
176
|
-
);
|
|
177
|
-
expect(result).toEqual([
|
|
178
|
-
['col', {}],
|
|
179
|
-
['col', {}],
|
|
180
|
-
['col', {}],
|
|
181
|
-
]);
|
|
182
|
-
},
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
function getTable(cellAttributes: { [key: string]: any }[]) {
|
|
187
|
-
return table({
|
|
188
|
-
isNumberColumnEnabled: true,
|
|
189
|
-
})(tr(...cellAttributes.map((attrs) => td(attrs)(p('text')))))(
|
|
190
|
-
defaultSchema,
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
//isMinCellWidthTable function test
|
|
197
|
-
describe('#isMinCellWidthTable', () => {
|
|
198
|
-
describe('check if a table has all the columns with minimum width', () => {
|
|
199
|
-
it('when input table has all columns in minimum width', () => {
|
|
200
|
-
const result = isMinCellWidthTable(getMinCellWidthTable());
|
|
201
|
-
|
|
202
|
-
expect(result).toEqual(true);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('when input table has a column that is not minimum width', () => {
|
|
206
|
-
const result = isMinCellWidthTable(getNonMinCellWidthTable());
|
|
207
|
-
|
|
208
|
-
expect(result).toEqual(false);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
function getMinCellWidthTable() {
|
|
212
|
-
return table()(
|
|
213
|
-
tr(
|
|
214
|
-
td({ colwidth: [48] })(p('')),
|
|
215
|
-
td({ colwidth: [48] })(p('')),
|
|
216
|
-
td({ colwidth: [48] })(p('')),
|
|
217
|
-
),
|
|
218
|
-
)(defaultSchema);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function getNonMinCellWidthTable() {
|
|
222
|
-
return table()(
|
|
223
|
-
tr(
|
|
224
|
-
td({ colwidth: [200] })(p('')),
|
|
225
|
-
td({ colwidth: [200] })(p('')),
|
|
226
|
-
td({ colwidth: [48] })(p('')),
|
|
227
|
-
),
|
|
228
|
-
)(defaultSchema);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe('#getColgroupChildrenLength', () => {
|
|
234
|
-
it('returns 1 when table only have 1 column', () => {
|
|
235
|
-
expect(
|
|
236
|
-
getColgroupChildrenLength(table()(tr(td()(p(''))))(defaultSchema)),
|
|
237
|
-
).toBe(1);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('returns 3 when table have 3 column', () => {
|
|
241
|
-
expect(
|
|
242
|
-
getColgroupChildrenLength(
|
|
243
|
-
table()(tr(td()(p('')), td()(p('')), td()(p(''))))(defaultSchema),
|
|
244
|
-
),
|
|
245
|
-
).toBe(3);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('returns 5 when table have 5 column', () => {
|
|
249
|
-
expect(
|
|
250
|
-
getColgroupChildrenLength(
|
|
251
|
-
table()(
|
|
252
|
-
tr(td()(p('')), td()(p('')), td()(p('')), td()(p('')), td()(p(''))),
|
|
253
|
-
)(defaultSchema),
|
|
254
|
-
),
|
|
255
|
-
).toBe(5);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('returns correct number when table have merged header column', () => {
|
|
259
|
-
expect(
|
|
260
|
-
getColgroupChildrenLength(
|
|
261
|
-
table()(
|
|
262
|
-
tr(th({ colspan: 2 })(p('')), th()(p(''))),
|
|
263
|
-
tr(td()(p('')), td()(p('')), td()(p(''))),
|
|
264
|
-
)(defaultSchema),
|
|
265
|
-
),
|
|
266
|
-
).toBe(3);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
});
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ACTION_SUBJECT,
|
|
3
|
-
EVENT_TYPE,
|
|
4
|
-
TABLE_ACTION,
|
|
5
|
-
} from '@atlaskit/editor-common/analytics';
|
|
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 type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
9
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
10
|
-
import { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
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 { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
16
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
17
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
18
|
-
import {
|
|
19
|
-
akEditorDefaultLayoutWidth,
|
|
20
|
-
akEditorFullPageMaxWidth,
|
|
21
|
-
} from '@atlaskit/editor-shared-styles/consts';
|
|
22
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
23
|
-
import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
24
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
25
|
-
import {
|
|
26
|
-
createProsemirrorEditorFactory,
|
|
27
|
-
Preset,
|
|
28
|
-
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
29
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
30
|
-
import {
|
|
31
|
-
doc,
|
|
32
|
-
p,
|
|
33
|
-
table,
|
|
34
|
-
td,
|
|
35
|
-
tr,
|
|
36
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
37
|
-
|
|
38
|
-
import tablePlugin from '../../../../plugin';
|
|
39
|
-
import { pluginKey } from '../../../../pm-plugins/plugin-key';
|
|
40
|
-
import { setResizeHandlePos } from '../../../../pm-plugins/table-resizing/commands';
|
|
41
|
-
|
|
42
|
-
// We don't need to test if the analytics implementation works (tested elsewhere)
|
|
43
|
-
// We just want to know if the action is called.
|
|
44
|
-
const mockAttachPayload = jest.fn();
|
|
45
|
-
const analyticsPluginFake = () => ({
|
|
46
|
-
name: 'analytics',
|
|
47
|
-
actions: {
|
|
48
|
-
attachAnalyticsEvent: mockAttachPayload.mockImplementation(() => () => {}),
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('table-resizing/event-handlers', () => {
|
|
53
|
-
let editor: any;
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
56
|
-
editor = (doc: DocBuilder) =>
|
|
57
|
-
createEditor({
|
|
58
|
-
doc,
|
|
59
|
-
attachTo: document.body,
|
|
60
|
-
preset: new Preset<LightEditorPlugin>()
|
|
61
|
-
.add([featureFlagsPlugin, {}])
|
|
62
|
-
.add([analyticsPluginFake as unknown as typeof analyticsPlugin, {}])
|
|
63
|
-
.add(contentInsertionPlugin)
|
|
64
|
-
.add(decorationsPlugin)
|
|
65
|
-
.add(widthPlugin)
|
|
66
|
-
.add(guidelinePlugin)
|
|
67
|
-
.add(selectionPlugin)
|
|
68
|
-
.add([
|
|
69
|
-
tablePlugin,
|
|
70
|
-
{
|
|
71
|
-
tableOptions: { allowColumnResizing: true },
|
|
72
|
-
},
|
|
73
|
-
]),
|
|
74
|
-
pluginKey,
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('#handleMouseDown', () => {
|
|
79
|
-
it('should dispatch analytics event on last column resizing attempt', async () => {
|
|
80
|
-
const { editorView: view } = editor(
|
|
81
|
-
doc(table()(tr(td()(p('1')), td()(p('2')), td()(p('3{<>}'))))),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
resizeColumn(view, 12, 150, 250);
|
|
85
|
-
|
|
86
|
-
expect(mockAttachPayload).toHaveBeenCalledWith(
|
|
87
|
-
expect.objectContaining({
|
|
88
|
-
action: TABLE_ACTION.ATTEMPTED_TABLE_WIDTH_CHANGE,
|
|
89
|
-
actionSubject: ACTION_SUBJECT.TABLE,
|
|
90
|
-
actionSubjectId: null,
|
|
91
|
-
eventType: EVENT_TYPE.UI,
|
|
92
|
-
attributes: expect.objectContaining({
|
|
93
|
-
delta: 100,
|
|
94
|
-
position: 'right',
|
|
95
|
-
type: 'table-border',
|
|
96
|
-
}),
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should shrink last column until table is no longer overflowing', async () => {
|
|
102
|
-
const { editorView: view } = editor(
|
|
103
|
-
doc(table()(tr(td()(p('1')), td()(p('2')), td()(p('3{<>}'))))),
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Increase column to overflow
|
|
107
|
-
resizeColumn(view, 7, 50, 500);
|
|
108
|
-
|
|
109
|
-
expect(getTotalTableWidth(view.state as EditorState)).toBeGreaterThan(
|
|
110
|
-
akEditorFullPageMaxWidth,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
resizeColumn(view, 12, 3000, 700);
|
|
114
|
-
|
|
115
|
-
// No matter how large we try to resize the result should equal the width (within 1 pt)
|
|
116
|
-
expect(getTotalTableWidth(view.state as EditorState)).toBeLessThanOrEqual(
|
|
117
|
-
akEditorDefaultLayoutWidth,
|
|
118
|
-
);
|
|
119
|
-
expect(
|
|
120
|
-
getTotalTableWidth(view.state as EditorState),
|
|
121
|
-
).toBeGreaterThanOrEqual(akEditorFullPageMaxWidth - 1);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should not resize the last column to grow', async () => {
|
|
125
|
-
const { editorView: view } = editor(
|
|
126
|
-
doc(table()(tr(td()(p('1')), td()(p('2')), td()(p('3{<>}'))))),
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// Increase column to overflow
|
|
130
|
-
resizeColumn(view, 7, 50, 500);
|
|
131
|
-
|
|
132
|
-
const overflowingTableWidth = getTotalTableWidth(
|
|
133
|
-
view.state as EditorState,
|
|
134
|
-
);
|
|
135
|
-
expect(overflowingTableWidth).toBeGreaterThan(akEditorFullPageMaxWidth);
|
|
136
|
-
|
|
137
|
-
resizeColumn(view, 12, 400, 3000);
|
|
138
|
-
|
|
139
|
-
// Width should be unchanged
|
|
140
|
-
expect(getTotalTableWidth(view.state as EditorState)).toBe(
|
|
141
|
-
overflowingTableWidth,
|
|
142
|
-
);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('should restore text selection after replacing the table', async () => {
|
|
146
|
-
const { editorView: view } = editor(
|
|
147
|
-
doc(table()(tr(td()(p('1')), td()(p('2')), td()(p('3{<>}'))))),
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
const currentSelection = view.state.tr.selection;
|
|
151
|
-
expect(currentSelection instanceof TextSelection).toBeTruthy();
|
|
152
|
-
expect(currentSelection.$cursor.pos).toBe(15);
|
|
153
|
-
|
|
154
|
-
resizeColumn(view, 12, 150, 250);
|
|
155
|
-
|
|
156
|
-
expect(currentSelection instanceof TextSelection).toBeTruthy();
|
|
157
|
-
expect(currentSelection.$cursor.pos).toBe(15);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
function getTotalTableWidth(state: EditorState) {
|
|
163
|
-
let totalWidth = 0;
|
|
164
|
-
state.doc.descendants((node) => {
|
|
165
|
-
if (node.type.name === 'tableCell') {
|
|
166
|
-
totalWidth += node.attrs.colwidth[0];
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
return true;
|
|
170
|
-
});
|
|
171
|
-
return totalWidth;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function resizeColumn(
|
|
175
|
-
view: EditorView,
|
|
176
|
-
pos: number,
|
|
177
|
-
start: number,
|
|
178
|
-
end: number,
|
|
179
|
-
) {
|
|
180
|
-
setResizeHandlePos(pos)(view.state, view.dispatch);
|
|
181
|
-
|
|
182
|
-
const firstmousedownEvent = new MouseEvent('mousedown', {
|
|
183
|
-
clientX: start,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
view.dom.dispatchEvent(firstmousedownEvent);
|
|
187
|
-
|
|
188
|
-
const firstmouseupEvent = new MouseEvent('mouseup', {
|
|
189
|
-
clientX: end,
|
|
190
|
-
});
|
|
191
|
-
window.dispatchEvent(firstmouseupEvent);
|
|
192
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { updateColgroup } from '../../../../../pm-plugins/table-resizing/utils/resize-state';
|
|
2
|
-
import type { ResizeState } from '../../../../../pm-plugins/table-resizing/utils/types';
|
|
3
|
-
|
|
4
|
-
describe('table-resizing/utils/resize-state', () => {
|
|
5
|
-
describe('#updateColgroup', () => {
|
|
6
|
-
it('should not throw exception when the dom cols does not exist', () => {
|
|
7
|
-
const state = {
|
|
8
|
-
cols: [{ width: 100 }],
|
|
9
|
-
};
|
|
10
|
-
const tableRef = document.createElement('div');
|
|
11
|
-
|
|
12
|
-
const func = () => {
|
|
13
|
-
updateColgroup(state as ResizeState, tableRef);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
expect(func).not.toThrow();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should not throw exception when the column is null', () => {
|
|
20
|
-
const state = {
|
|
21
|
-
cols: [null],
|
|
22
|
-
};
|
|
23
|
-
const tableRef = document.createElement('div');
|
|
24
|
-
|
|
25
|
-
const func = () => {
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
updateColgroup(state, tableRef);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
expect(func).not.toThrow();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|