@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,597 +0,0 @@
|
|
|
1
|
-
import { uuid } from '@atlaskit/adf-schema';
|
|
2
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
3
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
4
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
5
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
6
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
7
|
-
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
8
|
-
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
9
|
-
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
10
|
-
import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
11
|
-
import type { Rect } from '@atlaskit/editor-tables/table-map';
|
|
12
|
-
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
13
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
14
|
-
import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
15
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
16
|
-
import {
|
|
17
|
-
createProsemirrorEditorFactory,
|
|
18
|
-
Preset,
|
|
19
|
-
} 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
|
-
doc,
|
|
23
|
-
p,
|
|
24
|
-
table,
|
|
25
|
-
td,
|
|
26
|
-
tdCursor,
|
|
27
|
-
tdEmpty,
|
|
28
|
-
tr,
|
|
29
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
30
|
-
|
|
31
|
-
import tablePlugin from '../../../plugin';
|
|
32
|
-
import { pluginKey } from '../../../pm-plugins/plugin-key';
|
|
33
|
-
import { deleteColumns } from '../../../transforms';
|
|
34
|
-
import type { TablePluginState } from '../../../types';
|
|
35
|
-
|
|
36
|
-
const colsToRect = (cols: Array<number>, noOfRows: number): Rect => ({
|
|
37
|
-
left: Math.min(...cols),
|
|
38
|
-
right: Math.max(...cols) + 1,
|
|
39
|
-
top: 0,
|
|
40
|
-
bottom: noOfRows,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const TABLE_LOCAL_ID = 'test-table-local-id';
|
|
44
|
-
|
|
45
|
-
describe('table plugin -> transforms -> delete columns', () => {
|
|
46
|
-
const originalClientWidth = Object.getOwnPropertyDescriptor(
|
|
47
|
-
HTMLElement.prototype,
|
|
48
|
-
'clientWidth',
|
|
49
|
-
);
|
|
50
|
-
beforeAll(() => {
|
|
51
|
-
uuid.setStatic(TABLE_LOCAL_ID);
|
|
52
|
-
|
|
53
|
-
Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
|
|
54
|
-
get() {
|
|
55
|
-
return 760;
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
afterAll(() => {
|
|
61
|
-
uuid.setStatic(false);
|
|
62
|
-
Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
|
|
63
|
-
get() {
|
|
64
|
-
return originalClientWidth;
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
70
|
-
const preset = new Preset<LightEditorPlugin>()
|
|
71
|
-
.add([featureFlagsPlugin, {}])
|
|
72
|
-
.add([analyticsPlugin, {}])
|
|
73
|
-
.add(contentInsertionPlugin)
|
|
74
|
-
.add(widthPlugin)
|
|
75
|
-
.add(guidelinePlugin)
|
|
76
|
-
.add(selectionPlugin)
|
|
77
|
-
.add(tablePlugin);
|
|
78
|
-
|
|
79
|
-
const editor = (doc: DocBuilder) =>
|
|
80
|
-
createEditor<TablePluginState, PluginKey, typeof preset>({
|
|
81
|
-
doc,
|
|
82
|
-
preset,
|
|
83
|
-
pluginKey,
|
|
84
|
-
attachTo: document.body,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('when selection rect is given', () => {
|
|
88
|
-
describe('when the first column is deleted', () => {
|
|
89
|
-
it('should delete the column and move cursor to the first column', () => {
|
|
90
|
-
const {
|
|
91
|
-
editorView,
|
|
92
|
-
refs: { nextCursorPos },
|
|
93
|
-
} = editor(
|
|
94
|
-
doc(
|
|
95
|
-
p('text'),
|
|
96
|
-
table()(
|
|
97
|
-
tr(
|
|
98
|
-
td({})(p('{nextCursorPos}')),
|
|
99
|
-
td({})(p('c2')),
|
|
100
|
-
td({})(p('c3')),
|
|
101
|
-
),
|
|
102
|
-
),
|
|
103
|
-
),
|
|
104
|
-
);
|
|
105
|
-
const { state, dispatch } = editorView;
|
|
106
|
-
dispatch(deleteColumns(colsToRect([0], 1), true)(state.tr));
|
|
107
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
108
|
-
doc(
|
|
109
|
-
p('text'),
|
|
110
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
111
|
-
tr(td({})(p('c2')), td()(p('c3'))),
|
|
112
|
-
),
|
|
113
|
-
),
|
|
114
|
-
);
|
|
115
|
-
expect(editorView.state.selection.from).toEqual(nextCursorPos);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('when middle column is deleted', () => {
|
|
120
|
-
it('should delete the column and move cursor to the previous column', () => {
|
|
121
|
-
const {
|
|
122
|
-
editorView,
|
|
123
|
-
refs: { nextCursorPos },
|
|
124
|
-
} = editor(
|
|
125
|
-
doc(
|
|
126
|
-
p('text'),
|
|
127
|
-
table()(
|
|
128
|
-
tr(
|
|
129
|
-
td({})(p('{nextCursorPos}')),
|
|
130
|
-
td({})(p('c2')),
|
|
131
|
-
td({})(p('c3')),
|
|
132
|
-
),
|
|
133
|
-
),
|
|
134
|
-
),
|
|
135
|
-
);
|
|
136
|
-
const { state, dispatch } = editorView;
|
|
137
|
-
dispatch(deleteColumns(colsToRect([1], 1), true)(state.tr));
|
|
138
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
139
|
-
doc(
|
|
140
|
-
p('text'),
|
|
141
|
-
table({ localId: TABLE_LOCAL_ID })(tr(tdEmpty, td()(p('c3')))),
|
|
142
|
-
),
|
|
143
|
-
);
|
|
144
|
-
expect(editorView.state.selection.from).toEqual(nextCursorPos);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('when multiple rows are selected', () => {
|
|
149
|
-
it('should delete these columns', () => {
|
|
150
|
-
const { editorView } = editor(
|
|
151
|
-
doc(
|
|
152
|
-
p('text'),
|
|
153
|
-
table()(tr(tdCursor, td({})(p('c1')), td({})(p('c2')))),
|
|
154
|
-
),
|
|
155
|
-
);
|
|
156
|
-
const { state, dispatch } = editorView;
|
|
157
|
-
dispatch(deleteColumns(colsToRect([0, 1], 1), true)(state.tr));
|
|
158
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
159
|
-
doc(p('text'), table({ localId: TABLE_LOCAL_ID })(tr(td()(p('c2'))))),
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
describe('when one column is selected', () => {
|
|
166
|
-
it('should delete the column', () => {
|
|
167
|
-
const { editorView } = editor(
|
|
168
|
-
doc(
|
|
169
|
-
p('text'),
|
|
170
|
-
table()(
|
|
171
|
-
tr(td({})(p('a1')), td({})(p('{<cell}a2')), td({})(p('a3'))),
|
|
172
|
-
tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
|
|
173
|
-
),
|
|
174
|
-
),
|
|
175
|
-
);
|
|
176
|
-
const { state, dispatch } = editorView;
|
|
177
|
-
dispatch(
|
|
178
|
-
deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
|
|
179
|
-
);
|
|
180
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
181
|
-
doc(
|
|
182
|
-
p('text'),
|
|
183
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
184
|
-
tr(td({})(p('a1')), td({})(p('a3'))),
|
|
185
|
-
tr(td({})(p('b1')), td({})(p('b3'))),
|
|
186
|
-
),
|
|
187
|
-
),
|
|
188
|
-
);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('should update each cells colWidth', () => {
|
|
192
|
-
const { editorView } = editor(
|
|
193
|
-
doc(
|
|
194
|
-
table({ localId: TABLE_LOCAL_ID, layout: 'default', width: 760 })(
|
|
195
|
-
tr(
|
|
196
|
-
td({ colwidth: [401] })(p('{<>}')),
|
|
197
|
-
td({ colwidth: [105] })(p('')),
|
|
198
|
-
td({ colwidth: [253] })(p('')),
|
|
199
|
-
),
|
|
200
|
-
),
|
|
201
|
-
),
|
|
202
|
-
);
|
|
203
|
-
const { dispatch, state } = editorView;
|
|
204
|
-
dispatch(deleteColumns(colsToRect([1], 1), true, editorView)(state.tr));
|
|
205
|
-
|
|
206
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
207
|
-
doc(
|
|
208
|
-
table({ localId: TABLE_LOCAL_ID, width: 760 })(
|
|
209
|
-
tr(td({ colwidth: [460] })(p('')), td({ colwidth: [290] })(p(''))),
|
|
210
|
-
),
|
|
211
|
-
),
|
|
212
|
-
);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
describe('when multiple columns are selected', () => {
|
|
217
|
-
it('should delete these column', () => {
|
|
218
|
-
const { editorView } = editor(
|
|
219
|
-
doc(
|
|
220
|
-
p('text'),
|
|
221
|
-
table()(
|
|
222
|
-
tr(td({})(p('{<cell}a1')), td({})(p('a2')), td({})(p('a3'))),
|
|
223
|
-
tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
|
|
224
|
-
),
|
|
225
|
-
),
|
|
226
|
-
);
|
|
227
|
-
const { state, dispatch } = editorView;
|
|
228
|
-
dispatch(
|
|
229
|
-
deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
|
|
230
|
-
);
|
|
231
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
232
|
-
doc(
|
|
233
|
-
p('text'),
|
|
234
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
235
|
-
tr(td({})(p('a3'))),
|
|
236
|
-
tr(td({})(p('b3'))),
|
|
237
|
-
),
|
|
238
|
-
),
|
|
239
|
-
);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('should update each cells colWidth', () => {
|
|
243
|
-
const { editorView } = editor(
|
|
244
|
-
doc(
|
|
245
|
-
table({ localId: TABLE_LOCAL_ID, layout: 'default', width: 760 })(
|
|
246
|
-
tr(
|
|
247
|
-
td({ colwidth: [401] })(p('{<cell}')),
|
|
248
|
-
td({ colwidth: [105] })(p('{cell>}')),
|
|
249
|
-
td({ colwidth: [253] })(p('')),
|
|
250
|
-
),
|
|
251
|
-
),
|
|
252
|
-
),
|
|
253
|
-
);
|
|
254
|
-
const { dispatch, state } = editorView;
|
|
255
|
-
dispatch(
|
|
256
|
-
deleteColumns(
|
|
257
|
-
getSelectionRect(state.selection)!,
|
|
258
|
-
true,
|
|
259
|
-
editorView,
|
|
260
|
-
)(state.tr),
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
264
|
-
doc(
|
|
265
|
-
table({ localId: TABLE_LOCAL_ID, width: 760 })(
|
|
266
|
-
tr(td({ colwidth: [750] })(p(''))),
|
|
267
|
-
),
|
|
268
|
-
),
|
|
269
|
-
);
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
describe('when some of the columns are merged', () => {
|
|
274
|
-
it('should delete columns and update colspans of cells DOM nodes', () => {
|
|
275
|
-
const { editorView } = editor(
|
|
276
|
-
doc(
|
|
277
|
-
p('text'),
|
|
278
|
-
table()(
|
|
279
|
-
tr(td({ colspan: 2 })(p('{<cell}c1')), td({})(p('c2'))),
|
|
280
|
-
tr(td({})(p('{cell>}c3')), td({})(p('c4')), td({})(p('c5'))),
|
|
281
|
-
),
|
|
282
|
-
),
|
|
283
|
-
);
|
|
284
|
-
const { state, dispatch } = editorView;
|
|
285
|
-
dispatch(
|
|
286
|
-
deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
|
|
287
|
-
);
|
|
288
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
289
|
-
doc(
|
|
290
|
-
p('text'),
|
|
291
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
292
|
-
tr(td({ colspan: 1 })(p('c2'))),
|
|
293
|
-
tr(td({ colspan: 1 })(p('c5'))),
|
|
294
|
-
),
|
|
295
|
-
),
|
|
296
|
-
);
|
|
297
|
-
const cells = editorView.dom.querySelectorAll('td');
|
|
298
|
-
for (let i = 0, count = cells.length; i < count; i++) {
|
|
299
|
-
const cell = cells[i] as HTMLElement;
|
|
300
|
-
expect(cell.getAttribute('colspan')).not.toEqual('2');
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
describe('when after deleting the last column table has rows where cells have rowspans > 1 in each column', () => {
|
|
305
|
-
it('should decrement rowspans of these cells', () => {
|
|
306
|
-
const { editorView } = editor(
|
|
307
|
-
doc(
|
|
308
|
-
p('text'),
|
|
309
|
-
table()(
|
|
310
|
-
tr(tdEmpty, tdEmpty, td({})(p('{<cell}a3'))),
|
|
311
|
-
tr(
|
|
312
|
-
td({ rowspan: 2 })(p('b1')),
|
|
313
|
-
td({ rowspan: 2 })(p('b2')),
|
|
314
|
-
tdEmpty,
|
|
315
|
-
),
|
|
316
|
-
tr(td({})(p('{cell>}c3'))),
|
|
317
|
-
),
|
|
318
|
-
),
|
|
319
|
-
);
|
|
320
|
-
const { state, dispatch } = editorView;
|
|
321
|
-
dispatch(
|
|
322
|
-
deleteColumns(getSelectionRect(state.selection)!, false)(state.tr),
|
|
323
|
-
);
|
|
324
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
325
|
-
doc(
|
|
326
|
-
p('text'),
|
|
327
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
328
|
-
tr(tdEmpty, tdEmpty),
|
|
329
|
-
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
330
|
-
),
|
|
331
|
-
),
|
|
332
|
-
);
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
describe('when after deleting the first column table has rows where cells have rowspans > 1 in each column', () => {
|
|
337
|
-
it('should decrement rowspans of these cells', () => {
|
|
338
|
-
const { editorView } = editor(
|
|
339
|
-
doc(
|
|
340
|
-
p('text'),
|
|
341
|
-
table()(
|
|
342
|
-
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
343
|
-
tr(
|
|
344
|
-
tdEmpty,
|
|
345
|
-
td({ rowspan: 2 })(p('b2')),
|
|
346
|
-
td({ rowspan: 2 })(p('b3')),
|
|
347
|
-
),
|
|
348
|
-
tr(td({})(p('{cell>}c1'))),
|
|
349
|
-
),
|
|
350
|
-
),
|
|
351
|
-
);
|
|
352
|
-
const { state, dispatch } = editorView;
|
|
353
|
-
dispatch(
|
|
354
|
-
deleteColumns(getSelectionRect(state.selection)!, false)(state.tr),
|
|
355
|
-
);
|
|
356
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
357
|
-
doc(
|
|
358
|
-
p('text'),
|
|
359
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
360
|
-
tr(tdEmpty, tdEmpty),
|
|
361
|
-
tr(td({})(p('b2')), td({})(p('b3'))),
|
|
362
|
-
),
|
|
363
|
-
),
|
|
364
|
-
);
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
describe('when a column-spanning cell is deleted', () => {
|
|
369
|
-
describe('when this cell has rowspan = 1', () => {
|
|
370
|
-
it('should append missing cells to the column(s) to the right from the deleted column', () => {
|
|
371
|
-
const { editorView } = editor(
|
|
372
|
-
doc(
|
|
373
|
-
table()(
|
|
374
|
-
tr(
|
|
375
|
-
td({ colwidth: [110] })(p('a1')),
|
|
376
|
-
td({ colwidth: [120] })(p('a2')),
|
|
377
|
-
td({ colwidth: [130] })(p('a3')),
|
|
378
|
-
),
|
|
379
|
-
tr(td({ colwidth: [110, 120, 130], colspan: 3 })(p('b1'))),
|
|
380
|
-
tr(
|
|
381
|
-
td({ colwidth: [110] })(p('c1')),
|
|
382
|
-
td({ colwidth: [120] })(p('c2')),
|
|
383
|
-
td({ colwidth: [130] })(p('c3')),
|
|
384
|
-
),
|
|
385
|
-
),
|
|
386
|
-
),
|
|
387
|
-
);
|
|
388
|
-
const { state, dispatch } = editorView;
|
|
389
|
-
dispatch(deleteColumns(colsToRect([0], 3), true)(state.tr));
|
|
390
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
391
|
-
doc(
|
|
392
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
393
|
-
tr(
|
|
394
|
-
td({ colwidth: [120] })(p('a2')),
|
|
395
|
-
td({ colwidth: [130] })(p('a3')),
|
|
396
|
-
),
|
|
397
|
-
tr(
|
|
398
|
-
td({ colwidth: [120] })(p('')),
|
|
399
|
-
td({ colwidth: [130] })(p('')),
|
|
400
|
-
),
|
|
401
|
-
tr(
|
|
402
|
-
td({ colwidth: [120] })(p('c2')),
|
|
403
|
-
td({ colwidth: [130] })(p('c3')),
|
|
404
|
-
),
|
|
405
|
-
),
|
|
406
|
-
),
|
|
407
|
-
);
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
describe('when this cell has rowspan > 1', () => {
|
|
412
|
-
it('should append missing cells to the column(s) to the right from the deleted column', () => {
|
|
413
|
-
const { editorView } = editor(
|
|
414
|
-
doc(
|
|
415
|
-
table()(
|
|
416
|
-
tr(
|
|
417
|
-
td({ colwidth: [110] })(p('a1')),
|
|
418
|
-
td({ colwidth: [120] })(p('a2')),
|
|
419
|
-
td({ colwidth: [130] })(p('a3')),
|
|
420
|
-
td({ colwidth: [140] })(p('a4')),
|
|
421
|
-
),
|
|
422
|
-
tr(
|
|
423
|
-
td({ colwidth: [110, 120, 130], colspan: 3, rowspan: 2 })(
|
|
424
|
-
p('b1'),
|
|
425
|
-
),
|
|
426
|
-
td({ colwidth: [140] })(p('b4')),
|
|
427
|
-
),
|
|
428
|
-
tr(td({ colwidth: [140] })(p('c4'))),
|
|
429
|
-
tr(
|
|
430
|
-
td({ colwidth: [110] })(p('d1')),
|
|
431
|
-
td({ colwidth: [120] })(p('d2')),
|
|
432
|
-
td({ colwidth: [130] })(p('d3')),
|
|
433
|
-
td({ colwidth: [140] })(p('d4')),
|
|
434
|
-
),
|
|
435
|
-
),
|
|
436
|
-
),
|
|
437
|
-
);
|
|
438
|
-
const { state, dispatch } = editorView;
|
|
439
|
-
dispatch(deleteColumns(colsToRect([0], 4), true)(state.tr));
|
|
440
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
441
|
-
doc(
|
|
442
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
443
|
-
tr(
|
|
444
|
-
td({ colwidth: [120] })(p('a2')),
|
|
445
|
-
td({ colwidth: [130] })(p('a3')),
|
|
446
|
-
td({ colwidth: [140] })(p('a4')),
|
|
447
|
-
),
|
|
448
|
-
tr(
|
|
449
|
-
td({ colwidth: [120] })(p('')),
|
|
450
|
-
td({ colwidth: [130] })(p('')),
|
|
451
|
-
td({ colwidth: [140] })(p('b4')),
|
|
452
|
-
),
|
|
453
|
-
tr(
|
|
454
|
-
td({ colwidth: [120] })(p('')),
|
|
455
|
-
td({ colwidth: [130] })(p('')),
|
|
456
|
-
td({ colwidth: [140] })(p('c4')),
|
|
457
|
-
),
|
|
458
|
-
tr(
|
|
459
|
-
td({ colwidth: [120] })(p('d2')),
|
|
460
|
-
td({ colwidth: [130] })(p('d3')),
|
|
461
|
-
td({ colwidth: [140] })(p('d4')),
|
|
462
|
-
),
|
|
463
|
-
),
|
|
464
|
-
),
|
|
465
|
-
);
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
describe('when a column-spanning cell overlaps deleted column from the left', () => {
|
|
471
|
-
describe('when this cell has rowspan = 1', () => {
|
|
472
|
-
it('should decrement the colspan of that cell', () => {
|
|
473
|
-
const { editorView } = editor(
|
|
474
|
-
doc(
|
|
475
|
-
table()(
|
|
476
|
-
tr(
|
|
477
|
-
td({ colwidth: [110] })(p('a1')),
|
|
478
|
-
td({ colwidth: [120] })(p('a2')),
|
|
479
|
-
td({ colwidth: [130] })(p('a3')),
|
|
480
|
-
),
|
|
481
|
-
tr(td({ colwidth: [110, 120, 130], colspan: 3 })(p('b1'))),
|
|
482
|
-
tr(
|
|
483
|
-
td({ colwidth: [110] })(p('c1')),
|
|
484
|
-
td({ colwidth: [120] })(p('c2')),
|
|
485
|
-
td({ colwidth: [130] })(p('c3')),
|
|
486
|
-
),
|
|
487
|
-
),
|
|
488
|
-
),
|
|
489
|
-
);
|
|
490
|
-
const { state, dispatch } = editorView;
|
|
491
|
-
dispatch(deleteColumns(colsToRect([1], 3), true)(state.tr));
|
|
492
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
493
|
-
doc(
|
|
494
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
495
|
-
tr(
|
|
496
|
-
td({ colwidth: [110] })(p('a1')),
|
|
497
|
-
td({ colwidth: [130] })(p('a3')),
|
|
498
|
-
),
|
|
499
|
-
tr(td({ colwidth: [110, 130], colspan: 2 })(p('b1'))),
|
|
500
|
-
tr(
|
|
501
|
-
td({ colwidth: [110] })(p('c1')),
|
|
502
|
-
td({ colwidth: [130] })(p('c3')),
|
|
503
|
-
),
|
|
504
|
-
),
|
|
505
|
-
),
|
|
506
|
-
);
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
describe('when this cell has rowspan > 1', () => {
|
|
511
|
-
it('should decrement the colspan of that cell', () => {
|
|
512
|
-
const { editorView } = editor(
|
|
513
|
-
doc(
|
|
514
|
-
table()(
|
|
515
|
-
tr(
|
|
516
|
-
td({ colwidth: [110] })(p('a1')),
|
|
517
|
-
td({ colwidth: [120] })(p('a2')),
|
|
518
|
-
td({ colwidth: [130] })(p('a3')),
|
|
519
|
-
td({ colwidth: [140] })(p('a4')),
|
|
520
|
-
),
|
|
521
|
-
tr(
|
|
522
|
-
td({ colwidth: [110, 120, 130], colspan: 3, rowspan: 2 })(
|
|
523
|
-
p('b1'),
|
|
524
|
-
),
|
|
525
|
-
td({ colwidth: [140] })(p('b4')),
|
|
526
|
-
),
|
|
527
|
-
tr(td({ colwidth: [140] })(p('c4'))),
|
|
528
|
-
tr(
|
|
529
|
-
td({ colwidth: [110] })(p('d1')),
|
|
530
|
-
td({ colwidth: [120] })(p('d2')),
|
|
531
|
-
td({ colwidth: [130] })(p('d3')),
|
|
532
|
-
td({ colwidth: [140] })(p('d4')),
|
|
533
|
-
),
|
|
534
|
-
),
|
|
535
|
-
),
|
|
536
|
-
);
|
|
537
|
-
const { state, dispatch } = editorView;
|
|
538
|
-
dispatch(deleteColumns(colsToRect([1], 4), true)(state.tr));
|
|
539
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
540
|
-
doc(
|
|
541
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
542
|
-
tr(
|
|
543
|
-
td({ colwidth: [110] })(p('a1')),
|
|
544
|
-
td({ colwidth: [130] })(p('a3')),
|
|
545
|
-
td({ colwidth: [140] })(p('a4')),
|
|
546
|
-
),
|
|
547
|
-
tr(
|
|
548
|
-
td({ colwidth: [110, 130], colspan: 2, rowspan: 2 })(p('b1')),
|
|
549
|
-
td({ colwidth: [140] })(p('b4')),
|
|
550
|
-
),
|
|
551
|
-
tr(td({ colwidth: [140] })(p('c4'))),
|
|
552
|
-
tr(
|
|
553
|
-
td({ colwidth: [110] })(p('d1')),
|
|
554
|
-
td({ colwidth: [130] })(p('d3')),
|
|
555
|
-
td({ colwidth: [140] })(p('d4')),
|
|
556
|
-
),
|
|
557
|
-
),
|
|
558
|
-
),
|
|
559
|
-
);
|
|
560
|
-
});
|
|
561
|
-
});
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
describe('when a column-spanning cell overlaps two deleted columns from the left', () => {
|
|
565
|
-
it('should decrement the colspan of that cell twice', () => {
|
|
566
|
-
const { editorView } = editor(
|
|
567
|
-
doc(
|
|
568
|
-
table()(
|
|
569
|
-
tr(
|
|
570
|
-
td({ colwidth: [110] })(p('a1')),
|
|
571
|
-
td({ colwidth: [120] })(p('a2')),
|
|
572
|
-
td({ colwidth: [130] })(p('a3')),
|
|
573
|
-
),
|
|
574
|
-
tr(td({ colwidth: [110, 120, 130], colspan: 3 })(p('b1'))),
|
|
575
|
-
tr(
|
|
576
|
-
td({ colwidth: [110] })(p('c1')),
|
|
577
|
-
td({ colwidth: [120] })(p('c2')),
|
|
578
|
-
td({ colwidth: [130] })(p('c3')),
|
|
579
|
-
),
|
|
580
|
-
),
|
|
581
|
-
),
|
|
582
|
-
);
|
|
583
|
-
const { state, dispatch } = editorView;
|
|
584
|
-
dispatch(deleteColumns(colsToRect([1, 2], 3), true)(state.tr));
|
|
585
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
586
|
-
doc(
|
|
587
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
588
|
-
tr(td({ colwidth: [110] })(p('a1'))),
|
|
589
|
-
tr(td({ colwidth: [110] })(p('b1'))),
|
|
590
|
-
tr(td({ colwidth: [110] })(p('c1'))),
|
|
591
|
-
),
|
|
592
|
-
),
|
|
593
|
-
);
|
|
594
|
-
});
|
|
595
|
-
});
|
|
596
|
-
});
|
|
597
|
-
});
|