@atlaskit/editor-plugin-table 5.7.3 → 5.7.4

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.
@@ -27,7 +27,6 @@ import {
27
27
  tdEmpty,
28
28
  tr,
29
29
  } from '@atlaskit/editor-test-helpers/doc-builder';
30
- import { ffTest } from '@atlassian/feature-flags-test-utils';
31
30
 
32
31
  import tablePlugin from '../../../plugin';
33
32
  import { pluginKey } from '../../../pm-plugins/plugin-key';
@@ -87,406 +86,186 @@ describe('table plugin -> transforms -> delete columns', () => {
87
86
 
88
87
  describe('when selection rect is given', () => {
89
88
  describe('when the first column is deleted', () => {
90
- describe('should delete the column and move cursor to the first column', () => {
91
- ffTest(
92
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
93
- () => {
94
- const {
95
- editorView,
96
- refs: { nextCursorPos },
97
- } = editor(
98
- doc(
99
- p('text'),
100
- table()(
101
- tr(
102
- td({})(p('{nextCursorPos}')),
103
- td({})(p('c2')),
104
- td({})(p('c3')),
105
- ),
106
- ),
107
- ),
108
- );
109
- const { state, dispatch } = editorView;
110
- dispatch(deleteColumns(colsToRect([0], 1), true)(state.tr));
111
- expect(editorView.state.doc).toEqualDocument(
112
- doc(
113
- p('text'),
114
- table({ localId: TABLE_LOCAL_ID })(
115
- tr(td({})(p('c2')), td()(p('c3'))),
116
- ),
117
- ),
118
- );
119
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
120
- },
121
- () => {
122
- const {
123
- editorView,
124
- refs: { nextCursorPos },
125
- } = editor(
126
- doc(
127
- p('text'),
128
- table()(
129
- tr(
130
- td({})(p('{nextCursorPos}')),
131
- td({})(p('c2')),
132
- td({})(p('c3')),
133
- ),
134
- ),
135
- ),
136
- );
137
- const { state, dispatch } = editorView;
138
- dispatch(deleteColumns(colsToRect([0], 1), true)(state.tr));
139
- expect(editorView.state.doc).toEqualDocument(
140
- doc(
141
- p('text'),
142
- table({ localId: TABLE_LOCAL_ID })(
143
- tr(td({})(p('c2')), td()(p('c3'))),
144
- ),
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')),
145
101
  ),
146
- );
147
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
148
- },
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
+ ),
149
114
  );
115
+ expect(editorView.state.selection.from).toEqual(nextCursorPos);
150
116
  });
151
117
  });
152
118
 
153
119
  describe('when middle column is deleted', () => {
154
- describe('should delete the column and move cursor to the previous column', () => {
155
- ffTest(
156
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
157
- () => {
158
- const {
159
- editorView,
160
- refs: { nextCursorPos },
161
- } = editor(
162
- doc(
163
- p('text'),
164
- table()(
165
- tr(
166
- td({})(p('{nextCursorPos}')),
167
- td({})(p('c2')),
168
- td({})(p('c3')),
169
- ),
170
- ),
171
- ),
172
- );
173
- const { state, dispatch } = editorView;
174
- dispatch(deleteColumns(colsToRect([1], 1), true)(state.tr));
175
- expect(editorView.state.doc).toEqualDocument(
176
- doc(
177
- p('text'),
178
- table({ localId: TABLE_LOCAL_ID })(tr(tdEmpty, td()(p('c3')))),
179
- ),
180
- );
181
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
182
- },
183
- () => {
184
- const {
185
- editorView,
186
- refs: { nextCursorPos },
187
- } = editor(
188
- doc(
189
- p('text'),
190
- table()(
191
- tr(
192
- td({})(p('{nextCursorPos}')),
193
- td({})(p('c2')),
194
- td({})(p('c3')),
195
- ),
196
- ),
197
- ),
198
- );
199
- const { state, dispatch } = editorView;
200
- dispatch(deleteColumns(colsToRect([1], 1), true)(state.tr));
201
- expect(editorView.state.doc).toEqualDocument(
202
- doc(
203
- p('text'),
204
- table({ localId: TABLE_LOCAL_ID })(tr(tdEmpty, td()(p('c3')))),
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')),
205
132
  ),
206
- );
207
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
208
- },
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
+ ),
209
143
  );
144
+ expect(editorView.state.selection.from).toEqual(nextCursorPos);
210
145
  });
211
146
  });
212
147
 
213
148
  describe('when multiple rows are selected', () => {
214
- describe('should delete these columns', () => {
215
- ffTest(
216
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
217
- () => {
218
- const { editorView } = editor(
219
- doc(
220
- p('text'),
221
- table()(tr(tdCursor, td({})(p('c1')), td({})(p('c2')))),
222
- ),
223
- );
224
- const { state, dispatch } = editorView;
225
- dispatch(deleteColumns(colsToRect([0, 1], 1), true)(state.tr));
226
- expect(editorView.state.doc).toEqualDocument(
227
- doc(
228
- p('text'),
229
- table({ localId: TABLE_LOCAL_ID })(tr(td()(p('c2')))),
230
- ),
231
- );
232
- },
233
- () => {
234
- const { editorView } = editor(
235
- doc(
236
- p('text'),
237
- table()(tr(tdCursor, td({})(p('c1')), td({})(p('c2')))),
238
- ),
239
- );
240
- const { state, dispatch } = editorView;
241
- dispatch(deleteColumns(colsToRect([0, 1], 1), true)(state.tr));
242
- expect(editorView.state.doc).toEqualDocument(
243
- doc(
244
- p('text'),
245
- table({ localId: TABLE_LOCAL_ID })(tr(td()(p('c2')))),
246
- ),
247
- );
248
- },
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'))))),
249
160
  );
250
161
  });
251
162
  });
252
163
  });
253
164
 
254
165
  describe('when one column is selected', () => {
255
- describe('should delete the column', () => {
256
- ffTest(
257
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
258
- () => {
259
- const { editorView } = editor(
260
- doc(
261
- p('text'),
262
- table()(
263
- tr(td({})(p('a1')), td({})(p('{<cell}a2')), td({})(p('a3'))),
264
- tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
265
- ),
266
- ),
267
- );
268
- const { state, dispatch } = editorView;
269
- dispatch(
270
- deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
271
- );
272
- expect(editorView.state.doc).toEqualDocument(
273
- doc(
274
- p('text'),
275
- table({ localId: TABLE_LOCAL_ID })(
276
- tr(td({})(p('a1')), td({})(p('a3'))),
277
- tr(td({})(p('b1')), td({})(p('b3'))),
278
- ),
279
- ),
280
- );
281
- },
282
- () => {
283
- const { editorView } = editor(
284
- doc(
285
- p('text'),
286
- table()(
287
- tr(td({})(p('a1')), td({})(p('{<cell}a2')), td({})(p('a3'))),
288
- tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
289
- ),
290
- ),
291
- );
292
- const { state, dispatch } = editorView;
293
- dispatch(
294
- deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
295
- );
296
- expect(editorView.state.doc).toEqualDocument(
297
- doc(
298
- p('text'),
299
- table({ localId: TABLE_LOCAL_ID })(
300
- tr(td({})(p('a1')), td({})(p('a3'))),
301
- tr(td({})(p('b1')), td({})(p('b3'))),
302
- ),
303
- ),
304
- );
305
- },
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
+ ),
306
188
  );
307
189
  });
308
190
 
309
- describe('should update each cells colWidth', () => {
310
- ffTest(
311
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
312
- () => {
313
- const { editorView } = editor(
314
- doc(
315
- table({ localId: TABLE_LOCAL_ID, layout: 'default', width: 760 })(
316
- tr(
317
- td({ colwidth: [401] })(p('{<>}')),
318
- td({ colwidth: [105] })(p('')),
319
- td({ colwidth: [253] })(p('')),
320
- ),
321
- ),
322
- ),
323
- );
324
- const { dispatch, state } = editorView;
325
- dispatch(
326
- deleteColumns(colsToRect([1], 1), true, editorView)(state.tr),
327
- );
328
-
329
- expect(editorView.state.doc).toEqualDocument(
330
- doc(
331
- table({ localId: TABLE_LOCAL_ID, width: 760 })(
332
- tr(
333
- td({ colwidth: [460] })(p('')),
334
- td({ colwidth: [289] })(p('')),
335
- ),
336
- ),
337
- ),
338
- );
339
- },
340
- () => {
341
- const { editorView } = editor(
342
- doc(
343
- table({ localId: TABLE_LOCAL_ID, width: 691 })(
344
- tr(
345
- td({ colwidth: [230] })(p('')),
346
- td({ colwidth: [230] })(p('')),
347
- td({ colwidth: [230] })(p('')),
348
- ),
349
- ),
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('')),
350
199
  ),
351
- );
352
- const { dispatch, state } = editorView;
353
-
354
- dispatch(
355
- deleteColumns(colsToRect([1], 1), true, editorView)(state.tr),
356
- );
200
+ ),
201
+ ),
202
+ );
203
+ const { dispatch, state } = editorView;
204
+ dispatch(deleteColumns(colsToRect([1], 1), true, editorView)(state.tr));
357
205
 
358
- expect(editorView.state.doc).toEqualDocument(
359
- doc(
360
- table({ localId: TABLE_LOCAL_ID, width: 691 })(
361
- tr(
362
- td({ colwidth: [230] })(p('')),
363
- td({ colwidth: [230] })(p('')),
364
- ),
365
- ),
366
- ),
367
- );
368
- },
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
+ ),
369
212
  );
370
213
  });
371
214
  });
372
215
 
373
216
  describe('when multiple columns are selected', () => {
374
- describe('should delete these column', () => {
375
- ffTest(
376
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
377
- () => {
378
- const { editorView } = editor(
379
- doc(
380
- p('text'),
381
- table()(
382
- tr(td({})(p('{<cell}a1')), td({})(p('a2')), td({})(p('a3'))),
383
- tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
384
- ),
385
- ),
386
- );
387
- const { state, dispatch } = editorView;
388
- dispatch(
389
- deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
390
- );
391
- expect(editorView.state.doc).toEqualDocument(
392
- doc(
393
- p('text'),
394
- table({ localId: TABLE_LOCAL_ID })(
395
- tr(td({})(p('a3'))),
396
- tr(td({})(p('b3'))),
397
- ),
398
- ),
399
- );
400
- },
401
- () => {
402
- const { editorView } = editor(
403
- doc(
404
- p('text'),
405
- table()(
406
- tr(td({})(p('{<cell}a1')), td({})(p('a2')), td({})(p('a3'))),
407
- tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
408
- ),
409
- ),
410
- );
411
- const { state, dispatch } = editorView;
412
- dispatch(
413
- deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
414
- );
415
- expect(editorView.state.doc).toEqualDocument(
416
- doc(
417
- p('text'),
418
- table({ localId: TABLE_LOCAL_ID })(
419
- tr(td({})(p('a3'))),
420
- tr(td({})(p('b3'))),
421
- ),
422
- ),
423
- );
424
- },
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
+ ),
425
239
  );
426
240
  });
427
241
 
428
- describe('should update each cells colWidth', () => {
429
- ffTest(
430
- 'platform.editor.table-update-colwidths-after-column-is-deleted',
431
- () => {
432
- const { editorView } = editor(
433
- doc(
434
- table({ localId: TABLE_LOCAL_ID, layout: 'default', width: 760 })(
435
- tr(
436
- td({ colwidth: [401] })(p('{<cell}')),
437
- td({ colwidth: [105] })(p('{cell>}')),
438
- td({ colwidth: [253] })(p('')),
439
- ),
440
- ),
441
- ),
442
- );
443
- const { dispatch, state } = editorView;
444
- dispatch(
445
- deleteColumns(
446
- getSelectionRect(state.selection)!,
447
- true,
448
- editorView,
449
- )(state.tr),
450
- );
451
-
452
- expect(editorView.state.doc).toEqualDocument(
453
- doc(
454
- table({ localId: TABLE_LOCAL_ID, width: 760 })(
455
- tr(td({ colwidth: [749] })(p(''))),
456
- ),
457
- ),
458
- );
459
- },
460
- () => {
461
- const { editorView } = editor(
462
- doc(
463
- table({ localId: TABLE_LOCAL_ID, width: 691 })(
464
- tr(
465
- td({ colwidth: [401] })(p('{<cell}')),
466
- td({ colwidth: [105] })(p('{cell>}')),
467
- td({ colwidth: [253] })(p('')),
468
- ),
469
- ),
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('')),
470
250
  ),
471
- );
472
- const { dispatch, state } = editorView;
473
-
474
- dispatch(
475
- deleteColumns(
476
- getSelectionRect(state.selection)!,
477
- true,
478
- editorView,
479
- )(state.tr),
480
- );
251
+ ),
252
+ ),
253
+ );
254
+ const { dispatch, state } = editorView;
255
+ dispatch(
256
+ deleteColumns(
257
+ getSelectionRect(state.selection)!,
258
+ true,
259
+ editorView,
260
+ )(state.tr),
261
+ );
481
262
 
482
- expect(editorView.state.doc).toEqualDocument(
483
- doc(
484
- table({ localId: TABLE_LOCAL_ID, width: 691 })(
485
- tr(td({ colwidth: [253] })(p(''))),
486
- ),
487
- ),
488
- );
489
- },
263
+ expect(editorView.state.doc).toEqualDocument(
264
+ doc(
265
+ table({ localId: TABLE_LOCAL_ID, width: 760 })(
266
+ tr(td({ colwidth: [750] })(p(''))),
267
+ ),
268
+ ),
490
269
  );
491
270
  });
492
271
  });
@@ -56,9 +56,7 @@ export function addColumnAt(getEditorContainerWidth: GetEditorContainerWidth) {
56
56
  const table = findTable(updatedTr.selection);
57
57
  if (table) {
58
58
  // [ED-8288] Update colwidths manually to avoid multiple dispatch in TableComponent
59
- updatedTr = rescaleColumns(getEditorContainerWidth)(table, view)(
60
- updatedTr,
61
- );
59
+ updatedTr = rescaleColumns()(table, view)(updatedTr);
62
60
  }
63
61
 
64
62
  if (