@atlaskit/editor-plugin-table 0.0.6 → 0.0.8
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 +17 -0
- package/dist/cjs/plugins/table/event-handlers.js +7 -6
- package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
- package/dist/cjs/plugins/table/nodeviews/tableCell.js +4 -4
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/cjs/plugins/table/toolbar.js +0 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/index.js +23 -10
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +23 -10
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -4
- package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/event-handlers.js +8 -7
- package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
- package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -4
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/es2019/plugins/table/toolbar.js +1 -2
- package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/index.js +18 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +18 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -2
- package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/event-handlers.js +8 -7
- package/dist/esm/plugins/table/nodeviews/table.js +4 -2
- package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -4
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/esm/plugins/table/toolbar.js +1 -2
- package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/index.js +19 -9
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +19 -9
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -2
- package/dist/esm/plugins/table/utils/column-controls.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +5 -8
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +5 -5
- package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +1 -0
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +5 -8
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +5 -5
- package/package.json +10 -3
- package/src/__tests__/unit/analytics.ts +737 -0
- package/src/__tests__/unit/collab.ts +76 -0
- package/src/__tests__/unit/commands/sort.ts +230 -0
- package/src/__tests__/unit/copy-paste.ts +686 -0
- package/src/__tests__/unit/event-handlers/index.ts +106 -0
- package/src/__tests__/unit/event-handlers.ts +202 -0
- package/src/__tests__/unit/fix-tables.ts +156 -0
- package/src/__tests__/unit/floating-toolbar.ts +95 -0
- package/src/__tests__/unit/handlers.ts +81 -0
- package/src/__tests__/unit/hover-selection.ts +277 -0
- package/src/__tests__/unit/index-with-fake-timers.ts +107 -0
- package/src/__tests__/unit/index.ts +986 -0
- package/src/__tests__/unit/keymap.ts +602 -0
- package/src/__tests__/unit/layout.ts +196 -0
- package/src/__tests__/unit/nodeviews/cell.ts +167 -0
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +33 -0
- package/src/__tests__/unit/sort-column.ts +512 -0
- package/src/__tests__/unit/transforms/delete-columns.ts +499 -0
- package/src/__tests__/unit/transforms/delete-rows.ts +557 -0
- package/src/__tests__/unit/transforms/merging.ts +374 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +80 -0
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +95 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +175 -0
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +266 -0
- package/src/__tests__/unit/ui/RowControls.tsx +301 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +93 -0
- package/src/__tests__/unit/undo-redo.ts +202 -0
- package/src/__tests__/unit/utils/dom.ts +286 -0
- package/src/__tests__/unit/utils/nodes.ts +59 -0
- package/src/__tests__/unit/utils/row-controls.ts +176 -0
- package/src/__tests__/unit/utils/table.ts +93 -0
- package/src/__tests__/unit/utils.ts +652 -0
- package/src/plugins/table/__tests__/unit/commands/insert.ts +2 -2
- package/src/plugins/table/__tests__/unit/commands.ts +2 -2
- package/src/plugins/table/__tests__/unit/nodeviews/TableComponent.tsx +2 -2
- package/src/plugins/table/__tests__/unit/nodeviews/table.ts +1 -0
- package/src/plugins/table/event-handlers.ts +5 -6
- package/src/plugins/table/nodeviews/table.tsx +7 -0
- package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
- package/src/plugins/table/nodeviews/types.ts +1 -0
- package/src/plugins/table/pm-plugins/table-resizing/utils/column-state.ts +1 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +6 -2
- package/src/plugins/table/toolbar.ts +0 -1
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/TableFloatingControls/CornerControls/index.tsx +19 -1
- package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +16 -1
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -2
- package/src/plugins/table/utils/column-controls.ts +1 -1
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProsemirrorEditorFactory,
|
|
3
|
+
Preset,
|
|
4
|
+
LightEditorPlugin,
|
|
5
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
6
|
+
import {
|
|
7
|
+
DocBuilder,
|
|
8
|
+
doc,
|
|
9
|
+
p,
|
|
10
|
+
table,
|
|
11
|
+
tr,
|
|
12
|
+
td,
|
|
13
|
+
tdEmpty,
|
|
14
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
15
|
+
import { uuid } from '@atlaskit/adf-schema';
|
|
16
|
+
import { TablePluginState } from '../../../plugins/table/types';
|
|
17
|
+
import { mergeCells } from '../../../plugins/table/transforms';
|
|
18
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
19
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
20
|
+
import { PluginKey } from 'prosemirror-state';
|
|
21
|
+
|
|
22
|
+
const TABLE_LOCAL_ID = 'test-table-local-id';
|
|
23
|
+
|
|
24
|
+
describe('table plugin -> transforms -> merge cells', () => {
|
|
25
|
+
beforeAll(() => {
|
|
26
|
+
uuid.setStatic(TABLE_LOCAL_ID);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterAll(() => {
|
|
30
|
+
uuid.setStatic(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
34
|
+
const preset = new Preset<LightEditorPlugin>().add(tablePlugin);
|
|
35
|
+
|
|
36
|
+
const editor = (doc: DocBuilder) =>
|
|
37
|
+
createEditor<TablePluginState, PluginKey>({
|
|
38
|
+
doc,
|
|
39
|
+
preset,
|
|
40
|
+
pluginKey,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('#mergeCells', () => {
|
|
44
|
+
it('should merge columns and rows', () => {
|
|
45
|
+
const { editorView } = editor(
|
|
46
|
+
doc(
|
|
47
|
+
p('text'),
|
|
48
|
+
table()(
|
|
49
|
+
tr(td({})(p('{<cell}')), tdEmpty, tdEmpty),
|
|
50
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
51
|
+
tr(tdEmpty, td({})(p('{cell>}')), tdEmpty),
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
const { state, dispatch } = editorView;
|
|
56
|
+
dispatch(mergeCells(state.tr));
|
|
57
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
58
|
+
doc(
|
|
59
|
+
p('text'),
|
|
60
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
61
|
+
tr(td({ rowspan: 3 })(p('')), tdEmpty),
|
|
62
|
+
tr(tdEmpty),
|
|
63
|
+
tr(tdEmpty),
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('when two rows gets merged column by column', () => {
|
|
70
|
+
describe('when last non-merged cell gets merged from the end of the row', () => {
|
|
71
|
+
it('should delete an empty row that gets created as a result', () => {
|
|
72
|
+
const { editorView } = editor(
|
|
73
|
+
doc(
|
|
74
|
+
p('text'),
|
|
75
|
+
table()(
|
|
76
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
77
|
+
tr(
|
|
78
|
+
td({ rowspan: 2 })(p('b1')),
|
|
79
|
+
td({ rowspan: 2 })(p('b2')),
|
|
80
|
+
td({})(p('{<cell}b3')),
|
|
81
|
+
),
|
|
82
|
+
tr(td({})(p('{cell>}c3'))),
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
const { state, dispatch } = editorView;
|
|
87
|
+
dispatch(mergeCells(state.tr));
|
|
88
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
89
|
+
doc(
|
|
90
|
+
p('text'),
|
|
91
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
92
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
93
|
+
tr(td({})(p('b1')), td({})(p('b2')), td({})(p('b3'), p('c3'))),
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('when last non-merged cell gets merged from the start of the row', () => {
|
|
100
|
+
it('should delete an empty row that gets created as a result', () => {
|
|
101
|
+
const { editorView } = editor(
|
|
102
|
+
doc(
|
|
103
|
+
p('text'),
|
|
104
|
+
table()(
|
|
105
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
106
|
+
tr(
|
|
107
|
+
td({})(p('{<cell}b1')),
|
|
108
|
+
td({ rowspan: 2 })(p('b2')),
|
|
109
|
+
td({ rowspan: 2 })(p('b3')),
|
|
110
|
+
),
|
|
111
|
+
tr(td({})(p('{cell>}c1'))),
|
|
112
|
+
),
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
const { state, dispatch } = editorView;
|
|
116
|
+
dispatch(mergeCells(state.tr));
|
|
117
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
118
|
+
doc(
|
|
119
|
+
p('text'),
|
|
120
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
121
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
122
|
+
tr(td({})(p('b1'), p('c1')), td({})(p('b2')), td({})(p('b3'))),
|
|
123
|
+
),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('when more than two rows gets merged', () => {
|
|
131
|
+
describe('when last non-merged cell gets merged from the end of the row', () => {
|
|
132
|
+
it('should delete an empty row that gets created as a result', () => {
|
|
133
|
+
const { editorView } = editor(
|
|
134
|
+
doc(
|
|
135
|
+
p('text'),
|
|
136
|
+
table()(
|
|
137
|
+
tr(td({ rowspan: 4 })(p('a1')), td({})(p('{<cell}a2'))),
|
|
138
|
+
tr(tdEmpty),
|
|
139
|
+
tr(td({})(p('{cell>}c2'))),
|
|
140
|
+
tr(tdEmpty),
|
|
141
|
+
tr(tdEmpty, tdEmpty),
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
);
|
|
145
|
+
const { state, dispatch } = editorView;
|
|
146
|
+
dispatch(mergeCells(state.tr));
|
|
147
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
148
|
+
doc(
|
|
149
|
+
p('text'),
|
|
150
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
151
|
+
tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'), p('c2'))),
|
|
152
|
+
tr(tdEmpty),
|
|
153
|
+
tr(tdEmpty, tdEmpty),
|
|
154
|
+
),
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('when rows from the first columns get merged', () => {
|
|
162
|
+
describe('and table has merged rows in the next column', () => {
|
|
163
|
+
it('should delete an empty row and decrement rowspan of the next column', () => {
|
|
164
|
+
const { editorView } = editor(
|
|
165
|
+
doc(
|
|
166
|
+
p('text'),
|
|
167
|
+
table()(
|
|
168
|
+
tr(td({})(p('{<cell}a1')), td({ rowspan: 3 })(p('a2'))),
|
|
169
|
+
tr(td({})(p('{cell>}'))),
|
|
170
|
+
tr(tdEmpty),
|
|
171
|
+
),
|
|
172
|
+
),
|
|
173
|
+
);
|
|
174
|
+
const { state, dispatch } = editorView;
|
|
175
|
+
dispatch(mergeCells(state.tr));
|
|
176
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
177
|
+
doc(
|
|
178
|
+
p('text'),
|
|
179
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
180
|
+
tr(td({})(p('a1')), td({ rowspan: 2 })(p('a2'))),
|
|
181
|
+
tr(tdEmpty),
|
|
182
|
+
),
|
|
183
|
+
),
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('when rows from the last columns get merged', () => {
|
|
190
|
+
describe('and table has merged rows in the previous column', () => {
|
|
191
|
+
it('should delete an empty row and decrement rowspan of the previous column', () => {
|
|
192
|
+
const { editorView } = editor(
|
|
193
|
+
doc(
|
|
194
|
+
p('text'),
|
|
195
|
+
table()(
|
|
196
|
+
tr(td({ rowspan: 3 })(p('a1')), td({})(p('{<cell}a2'))),
|
|
197
|
+
tr(td({})(p('{cell>}'))),
|
|
198
|
+
tr(tdEmpty),
|
|
199
|
+
),
|
|
200
|
+
),
|
|
201
|
+
);
|
|
202
|
+
const { state, dispatch } = editorView;
|
|
203
|
+
dispatch(mergeCells(state.tr));
|
|
204
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
205
|
+
doc(
|
|
206
|
+
p('text'),
|
|
207
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
208
|
+
tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'))),
|
|
209
|
+
tr(tdEmpty),
|
|
210
|
+
),
|
|
211
|
+
),
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('when two empty cells are merged', () => {
|
|
218
|
+
it('should fill the merged cell with a paragraph', () => {
|
|
219
|
+
const { editorView } = editor(
|
|
220
|
+
doc(
|
|
221
|
+
p('text'),
|
|
222
|
+
table()(
|
|
223
|
+
tr(td({})(p('{<cell}')), td({})(p('{cell>}'))),
|
|
224
|
+
tr(tdEmpty, tdEmpty),
|
|
225
|
+
),
|
|
226
|
+
),
|
|
227
|
+
);
|
|
228
|
+
const { state, dispatch } = editorView;
|
|
229
|
+
dispatch(mergeCells(state.tr));
|
|
230
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
231
|
+
doc(
|
|
232
|
+
p('text'),
|
|
233
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
234
|
+
tr(td({ colspan: 2 })(p(''))),
|
|
235
|
+
tr(tdEmpty, tdEmpty),
|
|
236
|
+
),
|
|
237
|
+
),
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe('when next column is invisible', () => {
|
|
243
|
+
it('should decrement colspans of the preceeding column', () => {
|
|
244
|
+
const { editorView } = editor(
|
|
245
|
+
doc(
|
|
246
|
+
p('text'),
|
|
247
|
+
table()(
|
|
248
|
+
tr(tdEmpty, td({})(p('{<cell}')), tdEmpty, td({})(p('{cell>}'))),
|
|
249
|
+
tr(tdEmpty, td({ colspan: 3 })(p(''))),
|
|
250
|
+
tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
|
|
251
|
+
),
|
|
252
|
+
),
|
|
253
|
+
);
|
|
254
|
+
const { state, dispatch } = editorView;
|
|
255
|
+
dispatch(mergeCells(state.tr));
|
|
256
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
257
|
+
doc(
|
|
258
|
+
p('text'),
|
|
259
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
260
|
+
tr(tdEmpty, td({ colspan: 2 })(p(''))),
|
|
261
|
+
tr(tdEmpty, td({ colspan: 2 })(p(''))),
|
|
262
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
263
|
+
),
|
|
264
|
+
),
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('when next column is not invisible', () => {
|
|
270
|
+
it('should not decrement colspans of the preceeding column', () => {
|
|
271
|
+
const { editorView } = editor(
|
|
272
|
+
doc(
|
|
273
|
+
p('text'),
|
|
274
|
+
table()(
|
|
275
|
+
tr(tdEmpty, td({})(p('{<cell}')), tdEmpty, td({})(p('{cell>}'))),
|
|
276
|
+
tr(tdEmpty, td({ colspan: 3 })(p(''))),
|
|
277
|
+
tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
|
|
278
|
+
tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
|
|
279
|
+
),
|
|
280
|
+
),
|
|
281
|
+
);
|
|
282
|
+
const { state, dispatch } = editorView;
|
|
283
|
+
dispatch(mergeCells(state.tr));
|
|
284
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
285
|
+
doc(
|
|
286
|
+
p('text'),
|
|
287
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
288
|
+
tr(tdEmpty, td({ colspan: 3 })(p(''))),
|
|
289
|
+
tr(tdEmpty, td({ colspan: 3 })(p(''))),
|
|
290
|
+
tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
|
|
291
|
+
tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
|
|
292
|
+
),
|
|
293
|
+
),
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe('when empty cells and cells with content are merged together', () => {
|
|
299
|
+
it('should copy content from merged cells dropping empty cells', () => {
|
|
300
|
+
const { editorView } = editor(
|
|
301
|
+
doc(
|
|
302
|
+
p('text'),
|
|
303
|
+
table()(
|
|
304
|
+
tr(td({})(p('1')), td({})(p('2'))),
|
|
305
|
+
tr(td({ colspan: 2 })(p('{<cell}'))),
|
|
306
|
+
tr(td({})(p('1')), td({})(p('2{cell>}'))),
|
|
307
|
+
),
|
|
308
|
+
),
|
|
309
|
+
);
|
|
310
|
+
const { state, dispatch } = editorView;
|
|
311
|
+
dispatch(mergeCells(state.tr));
|
|
312
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
313
|
+
doc(
|
|
314
|
+
p('text'),
|
|
315
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
316
|
+
tr(td({})(p('1')), td({})(p('2'))),
|
|
317
|
+
tr(td({ colspan: 2 })(p('1'), p('2'))),
|
|
318
|
+
),
|
|
319
|
+
),
|
|
320
|
+
);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe('when table has columns where all cells have colspan > 1', () => {
|
|
325
|
+
it('should delete an empty column', () => {
|
|
326
|
+
const { editorView } = editor(
|
|
327
|
+
doc(
|
|
328
|
+
p('text'),
|
|
329
|
+
table()(
|
|
330
|
+
tr(
|
|
331
|
+
td({})(p('1')),
|
|
332
|
+
td({})(p('2')),
|
|
333
|
+
td({ colspan: 2, rowspan: 2 })(p('3')),
|
|
334
|
+
td({})(p('5')),
|
|
335
|
+
td({})(p('6')),
|
|
336
|
+
),
|
|
337
|
+
tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
|
|
338
|
+
tr(
|
|
339
|
+
td({})(p('1')),
|
|
340
|
+
td({})(p('{<cell}2')),
|
|
341
|
+
td({})(p('3')),
|
|
342
|
+
td({})(p('4')),
|
|
343
|
+
td({})(p('5{cell>}')),
|
|
344
|
+
td({})(p('6')),
|
|
345
|
+
),
|
|
346
|
+
),
|
|
347
|
+
),
|
|
348
|
+
);
|
|
349
|
+
const { state, dispatch } = editorView;
|
|
350
|
+
dispatch(mergeCells(state.tr));
|
|
351
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
352
|
+
doc(
|
|
353
|
+
p('text'),
|
|
354
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
355
|
+
tr(
|
|
356
|
+
td({})(p('1')),
|
|
357
|
+
td({})(p('2')),
|
|
358
|
+
td({ rowspan: 2 })(p('3')),
|
|
359
|
+
td({})(p('5')),
|
|
360
|
+
td({})(p('6')),
|
|
361
|
+
),
|
|
362
|
+
tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
|
|
363
|
+
tr(
|
|
364
|
+
td({})(p('1')),
|
|
365
|
+
td({ colspan: 3 })(p('2'), p('3'), p('4'), p('5')),
|
|
366
|
+
td({})(p('6')),
|
|
367
|
+
),
|
|
368
|
+
),
|
|
369
|
+
),
|
|
370
|
+
);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import { IntlProvider } from 'react-intl-next';
|
|
4
|
+
import { isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
5
|
+
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
6
|
+
import {
|
|
7
|
+
doc,
|
|
8
|
+
table,
|
|
9
|
+
tr,
|
|
10
|
+
thEmpty,
|
|
11
|
+
DocBuilder,
|
|
12
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
13
|
+
|
|
14
|
+
import { TablePluginState } from '../../../plugins/table/types';
|
|
15
|
+
import { CornerControls } from '../../../plugins/table/ui/TableFloatingControls/CornerControls';
|
|
16
|
+
import { getPluginState } from '../../../plugins/table/pm-plugins/plugin-factory';
|
|
17
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
18
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
19
|
+
|
|
20
|
+
describe('CornerControls', () => {
|
|
21
|
+
const createEditor = createEditorFactory<TablePluginState>();
|
|
22
|
+
|
|
23
|
+
const editor = (doc: DocBuilder) =>
|
|
24
|
+
createEditor({
|
|
25
|
+
doc,
|
|
26
|
+
editorProps: {
|
|
27
|
+
allowTables: false,
|
|
28
|
+
dangerouslyAppendPlugins: { __plugins: [tablePlugin()] },
|
|
29
|
+
},
|
|
30
|
+
pluginKey,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('when button is clicked', () => {
|
|
34
|
+
it('should select the table', () => {
|
|
35
|
+
const { editorView } = editor(
|
|
36
|
+
doc(table()(tr(thEmpty, thEmpty, thEmpty))),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const ref = editorView.dom.querySelector('table') || undefined;
|
|
40
|
+
|
|
41
|
+
render(
|
|
42
|
+
<IntlProvider locale="en">
|
|
43
|
+
<CornerControls tableRef={ref} editorView={editorView} />
|
|
44
|
+
</IntlProvider>,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const cornerControl = screen.getByLabelText('Highlight table');
|
|
48
|
+
|
|
49
|
+
fireEvent.click(cornerControl);
|
|
50
|
+
|
|
51
|
+
expect(isTableSelected(editorView.state.selection)).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('when button is hovered', () => {
|
|
56
|
+
it('should highlight the table with hover decoration', () => {
|
|
57
|
+
const { editorView } = editor(
|
|
58
|
+
doc(
|
|
59
|
+
table()(tr(thEmpty, thEmpty, thEmpty), tr(thEmpty, thEmpty, thEmpty)),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const ref = editorView.dom.querySelector('table') || undefined;
|
|
64
|
+
|
|
65
|
+
render(
|
|
66
|
+
<IntlProvider locale="en">
|
|
67
|
+
<CornerControls tableRef={ref} editorView={editorView} />
|
|
68
|
+
</IntlProvider>,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const cornerControl = screen.getByLabelText('Highlight table');
|
|
72
|
+
|
|
73
|
+
fireEvent.mouseOver(cornerControl);
|
|
74
|
+
|
|
75
|
+
const { hoveredColumns, hoveredRows } = getPluginState(editorView.state);
|
|
76
|
+
expect(hoveredColumns).toEqual([0, 1, 2]);
|
|
77
|
+
expect(hoveredRows).toEqual([0, 1]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ReactWrapper } from 'enzyme';
|
|
2
|
+
import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
|
|
3
|
+
import { EditorView } from 'prosemirror-view';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
6
|
+
import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
|
|
7
|
+
import {
|
|
8
|
+
doc,
|
|
9
|
+
table,
|
|
10
|
+
tdCursor,
|
|
11
|
+
tdEmpty,
|
|
12
|
+
thEmpty,
|
|
13
|
+
tr,
|
|
14
|
+
DocBuilder,
|
|
15
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
16
|
+
import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
17
|
+
import { TablePluginState } from '../../../plugins/table/types';
|
|
18
|
+
import FloatingContextualButton, {
|
|
19
|
+
Props as FloatingContextualButtonProps,
|
|
20
|
+
FloatingContextualButtonInner,
|
|
21
|
+
} from '../../../plugins/table/ui/FloatingContextualButton';
|
|
22
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
23
|
+
|
|
24
|
+
describe('Floating Contextual Button', () => {
|
|
25
|
+
const createEditor = createEditorFactory<TablePluginState>();
|
|
26
|
+
let createAnalyticsEvent = jest.fn(() => ({ fire() {} } as UIAnalyticsEvent));
|
|
27
|
+
const editor = (doc: DocBuilder) =>
|
|
28
|
+
createEditor({
|
|
29
|
+
doc,
|
|
30
|
+
editorProps: {
|
|
31
|
+
allowTables: false,
|
|
32
|
+
dangerouslyAppendPlugins: { __plugins: [tablePlugin()] },
|
|
33
|
+
},
|
|
34
|
+
createAnalyticsEvent,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
let wrapper: ReactWrapper<FloatingContextualButtonProps>;
|
|
38
|
+
let editorView: EditorView;
|
|
39
|
+
let refs: { [name: string]: number };
|
|
40
|
+
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
({ editorView, refs } = editor(
|
|
43
|
+
doc(
|
|
44
|
+
table()(
|
|
45
|
+
tr('{firstCell}', thEmpty, thEmpty, thEmpty),
|
|
46
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
47
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
48
|
+
),
|
|
49
|
+
),
|
|
50
|
+
));
|
|
51
|
+
|
|
52
|
+
const tableNode = findParentNodeOfTypeClosestToPos(
|
|
53
|
+
editorView.state.selection.$from,
|
|
54
|
+
editorView.state.schema.nodes.table,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
wrapper = mountWithIntl(
|
|
58
|
+
<FloatingContextualButton
|
|
59
|
+
editorView={editorView}
|
|
60
|
+
tableNode={tableNode && tableNode.node}
|
|
61
|
+
targetCellPosition={refs.firstCell}
|
|
62
|
+
dispatchAnalyticsEvent={createAnalyticsEvent}
|
|
63
|
+
/>,
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('when an error is thrown in the component', () => {
|
|
68
|
+
it('handles it gracefully', () => {
|
|
69
|
+
const buttonWrapper = wrapper.find(FloatingContextualButtonInner);
|
|
70
|
+
expect(() =>
|
|
71
|
+
buttonWrapper.simulateError(new Error('Oh no!')),
|
|
72
|
+
).not.toThrow();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('dispatches an analytics event', () => {
|
|
76
|
+
wrapper
|
|
77
|
+
.find(FloatingContextualButtonInner)
|
|
78
|
+
.simulateError(new Error('Oh no!'));
|
|
79
|
+
expect(createAnalyticsEvent).toHaveBeenCalledWith({
|
|
80
|
+
action: 'unhandledErrorCaught',
|
|
81
|
+
actionSubject: 'floatingContextualButton',
|
|
82
|
+
eventType: 'operational',
|
|
83
|
+
attributes: {
|
|
84
|
+
error: new Error('Oh no!'),
|
|
85
|
+
errorInfo: expect.objectContaining({
|
|
86
|
+
componentStack: expect.stringContaining(
|
|
87
|
+
'in FloatingContextualButton',
|
|
88
|
+
),
|
|
89
|
+
}),
|
|
90
|
+
errorRethrown: false,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|