@atlaskit/editor-plugin-table 0.0.5 → 0.0.7

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/plugins/table/commands-with-analytics.js +6 -0
  3. package/dist/cjs/plugins/table/event-handlers.js +7 -6
  4. package/dist/cjs/plugins/table/nodeviews/tableCell.js +4 -4
  5. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  6. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  7. package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
  8. package/dist/cjs/version.json +1 -1
  9. package/dist/es2019/plugins/table/commands-with-analytics.js +6 -0
  10. package/dist/es2019/plugins/table/event-handlers.js +8 -7
  11. package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -4
  12. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  13. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  14. package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
  15. package/dist/es2019/version.json +1 -1
  16. package/dist/esm/plugins/table/commands-with-analytics.js +6 -0
  17. package/dist/esm/plugins/table/event-handlers.js +8 -7
  18. package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -4
  19. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  20. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  21. package/dist/esm/plugins/table/utils/column-controls.js +1 -1
  22. package/dist/esm/version.json +1 -1
  23. package/package.json +9 -7
  24. package/report.api.md +13 -6
  25. package/src/__tests__/unit/analytics.ts +737 -0
  26. package/src/__tests__/unit/collab.ts +76 -0
  27. package/src/__tests__/unit/commands/sort.ts +230 -0
  28. package/src/__tests__/unit/copy-paste.ts +686 -0
  29. package/src/__tests__/unit/event-handlers/index.ts +106 -0
  30. package/src/__tests__/unit/event-handlers.ts +202 -0
  31. package/src/__tests__/unit/fix-tables.ts +156 -0
  32. package/src/__tests__/unit/floating-toolbar.ts +95 -0
  33. package/src/__tests__/unit/handlers.ts +81 -0
  34. package/src/__tests__/unit/hover-selection.ts +277 -0
  35. package/src/__tests__/unit/index-with-fake-timers.ts +106 -0
  36. package/src/__tests__/unit/index.ts +986 -0
  37. package/src/__tests__/unit/keymap.ts +602 -0
  38. package/src/__tests__/unit/layout.ts +196 -0
  39. package/src/__tests__/unit/nodeviews/cell.ts +167 -0
  40. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +33 -0
  41. package/src/__tests__/unit/sort-column.ts +512 -0
  42. package/src/__tests__/unit/transforms/delete-columns.ts +499 -0
  43. package/src/__tests__/unit/transforms/delete-rows.ts +557 -0
  44. package/src/__tests__/unit/transforms/merging.ts +374 -0
  45. package/src/__tests__/unit/ui/CornerControls.tsx +80 -0
  46. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +95 -0
  47. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +175 -0
  48. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +266 -0
  49. package/src/__tests__/unit/ui/RowControls.tsx +301 -0
  50. package/src/__tests__/unit/ui/TableFloatingControls.tsx +93 -0
  51. package/src/__tests__/unit/undo-redo.ts +202 -0
  52. package/src/__tests__/unit/utils/dom.ts +286 -0
  53. package/src/__tests__/unit/utils/nodes.ts +59 -0
  54. package/src/__tests__/unit/utils/row-controls.ts +176 -0
  55. package/src/__tests__/unit/utils/table.ts +93 -0
  56. package/src/__tests__/unit/utils.ts +652 -0
  57. package/src/plugins/table/commands-with-analytics.ts +3 -0
  58. package/src/plugins/table/event-handlers.ts +5 -6
  59. package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
  60. package/src/plugins/table/pm-plugins/table-resizing/utils/column-state.ts +1 -1
  61. package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +6 -2
  62. package/src/plugins/table/utils/column-controls.ts +1 -1
  63. package/tmp/api-report-tmp.d.ts +91 -0
@@ -0,0 +1,652 @@
1
+ import {
2
+ createProsemirrorEditorFactory,
3
+ Preset,
4
+ LightEditorPlugin,
5
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
6
+ import {
7
+ doc,
8
+ p,
9
+ table,
10
+ tr,
11
+ td,
12
+ tdCursor,
13
+ tdEmpty,
14
+ DocBuilder,
15
+ } from '@atlaskit/editor-test-helpers/doc-builder';
16
+ import { TablePluginState } from '../../plugins/table/types';
17
+ import {
18
+ getRowHeights,
19
+ isColumnDeleteButtonVisible,
20
+ isRowDeleteButtonVisible,
21
+ getColumnDeleteButtonParams,
22
+ getRowDeleteButtonParams,
23
+ getRowsParams,
24
+ getColumnClassNames,
25
+ getRowClassNames,
26
+ } from '../../plugins/table/utils';
27
+ import { getColumnsWidths } from '../../plugins/table/utils/column-controls';
28
+ import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
29
+ import tablePlugin from '../../plugins/table';
30
+ import { PluginKey } from 'prosemirror-state';
31
+
32
+ describe('table plugin: utils', () => {
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('#getColumnsWidths', () => {
44
+ describe('when columns are not merged', () => {
45
+ it('should return an array of widths of all columns', () => {
46
+ const { editorView } = editor(
47
+ doc(
48
+ p('text'),
49
+ table()(
50
+ tr(td({})(p('a1')), td({})(p('a2'))),
51
+ tr(td({})(p('b1')), td({})(p('b2'))),
52
+ ),
53
+ ),
54
+ );
55
+ const columnsWidths = getColumnsWidths(editorView);
56
+ columnsWidths.forEach((width) => {
57
+ expect(typeof width).toEqual('number');
58
+ expect(width && width > 0).toBe(true);
59
+ });
60
+ });
61
+ });
62
+
63
+ describe('when columns are merged', () => {
64
+ describe('when merged column has cells', () => {
65
+ it('should return an array of widths of all columns', () => {
66
+ const { editorView } = editor(
67
+ doc(
68
+ p('text'),
69
+ table()(
70
+ tr(td({ colspan: 2 })(p('a1')), td({})(p('a3'))),
71
+ tr(td({})(p('b1')), td({})(p('b2')), td({})(p('b3'))),
72
+ ),
73
+ ),
74
+ );
75
+ const columnsWidths = getColumnsWidths(editorView);
76
+ expect(columnsWidths).toEqual([1, undefined, 1]);
77
+ });
78
+ });
79
+ });
80
+ });
81
+
82
+ describe('#getRowHeights', () => {
83
+ describe('when rows are not merged', () => {
84
+ it('should return an array of heights of all rows', () => {
85
+ const { editorView } = editor(
86
+ doc(
87
+ p('text'),
88
+ table()(
89
+ tr(td({})(p('a1')), td({})(p('a2'))),
90
+ tr(td({})(p('b1')), td({})(p('b2'))),
91
+ ),
92
+ ),
93
+ );
94
+ const tableRef = editorView.dom.querySelector('table')!;
95
+ const rowHeights = getRowHeights(tableRef);
96
+ rowHeights.forEach((height) => {
97
+ expect(typeof height).toEqual('number');
98
+ expect(height > 0).toBe(true);
99
+ });
100
+ });
101
+ });
102
+
103
+ describe('when rows are merged', () => {
104
+ describe('when merged row has cells', () => {
105
+ it('should return an array of heights of all rows', () => {
106
+ const { editorView } = editor(
107
+ doc(
108
+ p('text'),
109
+ table()(
110
+ tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'))),
111
+ tr(td({})(p('b2'))),
112
+ ),
113
+ ),
114
+ );
115
+ const tableRef = editorView.dom.querySelector('table')!;
116
+ const rowHeights = getRowHeights(tableRef);
117
+
118
+ rowHeights.forEach((height) => {
119
+ expect(typeof height).toEqual('number');
120
+ expect(height > 0).toBe(true);
121
+ });
122
+ });
123
+ });
124
+ });
125
+ });
126
+
127
+ describe('#isColumnDeleteButtonVisible', () => {
128
+ describe('when selection is a TextSelection', () => {
129
+ it('should return false', () => {
130
+ const { editorView } = editor(
131
+ doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
132
+ );
133
+ expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
134
+ false,
135
+ );
136
+ });
137
+ });
138
+ describe('when selection is a CellSelection', () => {
139
+ describe('when no columns are fully selected', () => {
140
+ it('should return false', () => {
141
+ const { editorView } = editor(
142
+ doc(
143
+ p('text'),
144
+ table()(
145
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
146
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}b3'))),
147
+ tr(tdEmpty, tdEmpty, tdEmpty),
148
+ ),
149
+ ),
150
+ );
151
+
152
+ expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
153
+ false,
154
+ );
155
+ });
156
+ });
157
+ describe('when a column is selected', () => {
158
+ it('should return true', () => {
159
+ const { editorView } = editor(
160
+ doc(
161
+ p('text'),
162
+ table()(
163
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
164
+ tr(tdEmpty, tdEmpty, tdEmpty),
165
+ tr(td({})(p('{cell>}c1')), tdEmpty, tdEmpty),
166
+ ),
167
+ ),
168
+ );
169
+
170
+ expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
171
+ true,
172
+ );
173
+ });
174
+ });
175
+ describe('when table is selected', () => {
176
+ it('should return false', () => {
177
+ const { editorView } = editor(
178
+ doc(
179
+ p('text'),
180
+ table()(
181
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
182
+ tr(tdEmpty, tdEmpty, tdEmpty),
183
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
184
+ ),
185
+ ),
186
+ );
187
+
188
+ expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
189
+ false,
190
+ );
191
+ });
192
+ });
193
+ });
194
+ });
195
+
196
+ describe('#isRowDeleteButtonVisible', () => {
197
+ describe('when selection is a TextSelection', () => {
198
+ it('should return false', () => {
199
+ const { editorView } = editor(
200
+ doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
201
+ );
202
+ expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
203
+ false,
204
+ );
205
+ });
206
+ });
207
+ describe('when selection is a CellSelection', () => {
208
+ describe('when no rows are fully selected', () => {
209
+ it('should return false', () => {
210
+ const { editorView } = editor(
211
+ doc(
212
+ p('text'),
213
+ table()(
214
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
215
+ tr(tdEmpty, td({})(p('{cell>}b3')), tdEmpty),
216
+ tr(tdEmpty, tdEmpty, tdEmpty),
217
+ ),
218
+ ),
219
+ );
220
+
221
+ expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
222
+ false,
223
+ );
224
+ });
225
+ });
226
+ describe('when a row is selected', () => {
227
+ it('should return true', () => {
228
+ const { editorView } = editor(
229
+ doc(
230
+ p('text'),
231
+ table()(
232
+ tr(td({})(p('{<cell}a1')), tdEmpty, td({})(p('{cell>}a1'))),
233
+ tr(tdEmpty, tdEmpty, tdEmpty),
234
+ tr(tdEmpty, tdEmpty, tdEmpty),
235
+ ),
236
+ ),
237
+ );
238
+
239
+ expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
240
+ true,
241
+ );
242
+ });
243
+ });
244
+ describe('when table is selected', () => {
245
+ it('should return false', () => {
246
+ const { editorView } = editor(
247
+ doc(
248
+ p('text'),
249
+ table()(
250
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
251
+ tr(tdEmpty, tdEmpty, tdEmpty),
252
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
253
+ ),
254
+ ),
255
+ );
256
+
257
+ expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
258
+ false,
259
+ );
260
+ });
261
+ });
262
+ });
263
+ });
264
+
265
+ describe('#getColumnDeleteButtonParams', () => {
266
+ describe('when selection is a TextSelection', () => {
267
+ it('should return null', () => {
268
+ const { editorView } = editor(
269
+ doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
270
+ );
271
+ const columnsWidths = [100, 150, 200];
272
+ expect(
273
+ getColumnDeleteButtonParams(
274
+ columnsWidths,
275
+ editorView.state.selection,
276
+ ),
277
+ ).toBe(null);
278
+ });
279
+ });
280
+ describe('when selection is a CellSelection and 3 columns are selected', () => {
281
+ describe('columnsWidths = [100, 150, 200]', () => {
282
+ it('should return indexes = [0, 1, 2]', () => {
283
+ const { editorView } = editor(
284
+ doc(
285
+ p('text'),
286
+ table()(
287
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty, tdEmpty),
288
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
289
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3')), tdEmpty),
290
+ ),
291
+ ),
292
+ );
293
+
294
+ const columnsWidths = [100, 150, 200];
295
+ const { indexes, left } = getColumnDeleteButtonParams(
296
+ columnsWidths,
297
+ editorView.state.selection,
298
+ )!;
299
+ expect(indexes).toEqual([0, 1, 2]);
300
+ expect(left > 0).toBe(true);
301
+ });
302
+ });
303
+ });
304
+ });
305
+
306
+ describe('#getRowDeleteButtonParams', () => {
307
+ describe('when selection is a TextSelection', () => {
308
+ it('should return null', () => {
309
+ const { editorView } = editor(
310
+ doc(
311
+ p('text'),
312
+ table()(
313
+ tr(tdCursor, tdEmpty, tdEmpty),
314
+ tr(tdEmpty, tdEmpty, tdEmpty),
315
+ tr(tdEmpty, tdEmpty, tdEmpty),
316
+ ),
317
+ ),
318
+ );
319
+ const rowsHeights = [100, 150, 200];
320
+ expect(
321
+ getRowDeleteButtonParams(rowsHeights, editorView.state.selection),
322
+ ).toBe(null);
323
+ });
324
+ });
325
+ describe('when selection is a CellSelection and 3 rows are selected', () => {
326
+ describe('rowsHeights = [100, 150, 200]', () => {
327
+ it('should return indexes = [0, 1, 2]', () => {
328
+ const { editorView } = editor(
329
+ doc(
330
+ p('text'),
331
+ table()(
332
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
333
+ tr(tdEmpty, tdEmpty, tdEmpty),
334
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
335
+ tr(tdEmpty, tdEmpty, tdEmpty),
336
+ ),
337
+ ),
338
+ );
339
+
340
+ const rowsHeights = [100, 150, 200];
341
+ const { indexes, top } = getRowDeleteButtonParams(
342
+ rowsHeights,
343
+ editorView.state.selection,
344
+ )!;
345
+ expect(indexes).toEqual([0, 1, 2]);
346
+ expect(top > 0).toBe(true);
347
+ });
348
+ });
349
+ describe('rowsHeights = [100, ,150, ,200]', () => {
350
+ it('should return indexes = [0, 1, 2]', () => {
351
+ const { editorView } = editor(
352
+ doc(
353
+ p('text'),
354
+ table()(
355
+ tr(
356
+ td({ rowspan: 2 })(p('{<cell}a1')),
357
+ td({ rowspan: 2 })(p('a2')),
358
+ td({ rowspan: 2 })(p('a3')),
359
+ ),
360
+ tr(
361
+ td({ rowspan: 2 })(p('c1')),
362
+ td({ rowspan: 2 })(p('c2')),
363
+ td({ rowspan: 2 })(p('{cell>}c3')),
364
+ ),
365
+ tr(tdEmpty, tdEmpty, tdEmpty),
366
+ ),
367
+ ),
368
+ );
369
+
370
+ const rowsHeights = [100, , 150, , 200];
371
+ const { indexes, top } = getRowDeleteButtonParams(
372
+ rowsHeights,
373
+ editorView.state.selection,
374
+ )!;
375
+ expect(indexes).toEqual([0, 2]);
376
+ expect(top > 0).toBe(true);
377
+ });
378
+ });
379
+ });
380
+ });
381
+
382
+ describe('#getRowsParams', () => {
383
+ describe('rowHeights = [100, 150, 200]', () => {
384
+ it('should return consecutive indexes', () => {
385
+ const rowHeights = [100, 150, 200];
386
+ const rows = getRowsParams(rowHeights);
387
+ rows.forEach((row, index) => {
388
+ expect(row.startIndex).toEqual(index);
389
+ expect(row.endIndex).toEqual(index + 1);
390
+ expect(row.height).toEqual(rowHeights[index]);
391
+ });
392
+ });
393
+ });
394
+ describe('rowHeights = [100, ,150, ,200]', () => {
395
+ it('should return correct indexes', () => {
396
+ const rowHeights = [100, , 150, , 200];
397
+ const rows = getRowsParams(rowHeights);
398
+ const expectedIndexes = [0, 2, 4, 5];
399
+ for (let i = 0, count = rows.length; i < count; i++) {
400
+ const row = rows[i];
401
+ expect(row.startIndex).toEqual(expectedIndexes[i]);
402
+ expect(row.endIndex).toEqual(expectedIndexes[i + 1]);
403
+ expect(row.height).toEqual(rowHeights[expectedIndexes[i]]);
404
+ }
405
+ });
406
+ });
407
+ });
408
+
409
+ describe('#getColumnClassNames', () => {
410
+ describe('when selection is a TextSelection', () => {
411
+ [[0], [1], [2], [0, 1], [1, 2], [0, 2]].forEach((hoveredColumns) => {
412
+ describe(`when hoveredColumns = ${hoveredColumns}`, () => {
413
+ it('return a string containing "active" substring', () => {
414
+ const { editorView } = editor(
415
+ doc(
416
+ p('text'),
417
+ table()(
418
+ tr(tdCursor, tdEmpty, tdEmpty),
419
+ tr(tdEmpty, tdEmpty, tdEmpty),
420
+ tr(tdEmpty, tdEmpty, tdEmpty),
421
+ ),
422
+ ),
423
+ );
424
+ const isInDanger = false;
425
+ const classNames = getColumnClassNames(
426
+ hoveredColumns[0],
427
+ editorView.state.selection,
428
+ hoveredColumns,
429
+ isInDanger,
430
+ );
431
+ expect(classNames.indexOf('active') > -1).toBe(true);
432
+ });
433
+ describe('when isInDanger = true', () => {
434
+ it('return a string containing "danger" substring', () => {
435
+ const { editorView } = editor(
436
+ doc(
437
+ p('text'),
438
+ table()(
439
+ tr(tdCursor, tdEmpty, tdEmpty),
440
+ tr(tdEmpty, tdEmpty, tdEmpty),
441
+ tr(tdEmpty, tdEmpty, tdEmpty),
442
+ ),
443
+ ),
444
+ );
445
+ const isInDanger = true;
446
+ const classNames = getColumnClassNames(
447
+ hoveredColumns[0],
448
+ editorView.state.selection,
449
+ hoveredColumns,
450
+ isInDanger,
451
+ );
452
+ expect(classNames.indexOf('danger') > -1).toBe(true);
453
+ });
454
+ });
455
+ });
456
+ });
457
+ });
458
+ describe('when selection is a CellSelection', () => {
459
+ describe('when no columns are fully selected', () => {
460
+ it('should return an empty string', () => {
461
+ const { editorView } = editor(
462
+ doc(
463
+ p('text'),
464
+ table()(
465
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
466
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}b3'))),
467
+ tr(tdEmpty, tdEmpty, tdEmpty),
468
+ ),
469
+ ),
470
+ );
471
+
472
+ const classNames = getColumnClassNames(
473
+ 0,
474
+ editorView.state.selection,
475
+ [],
476
+ false,
477
+ );
478
+ expect(classNames).toBe('');
479
+ });
480
+ });
481
+ describe('when a column is selected', () => {
482
+ it('return a string containing "active" substring', () => {
483
+ const { editorView } = editor(
484
+ doc(
485
+ p('text'),
486
+ table()(
487
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
488
+ tr(tdEmpty, tdEmpty, tdEmpty),
489
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
490
+ ),
491
+ ),
492
+ );
493
+
494
+ [0, 1, 2].forEach((index) => {
495
+ const classNames = getColumnClassNames(
496
+ index,
497
+ editorView.state.selection,
498
+ [],
499
+ false,
500
+ );
501
+ expect(classNames.indexOf('active') > -1).toBe(true);
502
+ });
503
+ });
504
+ describe('when isInDanger = true', () => {
505
+ it('return a string containing "danger" substring', () => {
506
+ const { editorView } = editor(
507
+ doc(
508
+ p('text'),
509
+ table()(
510
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
511
+ tr(tdEmpty, tdEmpty, tdEmpty),
512
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
513
+ ),
514
+ ),
515
+ );
516
+ [0, 1, 2].forEach((index) => {
517
+ const classNames = getColumnClassNames(
518
+ index,
519
+ editorView.state.selection,
520
+ [],
521
+ true,
522
+ );
523
+ expect(classNames.indexOf('danger') > -1).toBe(true);
524
+ });
525
+ });
526
+ });
527
+ });
528
+ });
529
+ });
530
+
531
+ describe('#getRowClassNames', () => {
532
+ describe('when selection is a TextSelection', () => {
533
+ [[0], [1], [2], [0, 1], [1, 2], [0, 2]].forEach((hoveredRows) => {
534
+ describe(`when hoveredRows = ${hoveredRows}`, () => {
535
+ it('return a string containing "active" substring', () => {
536
+ const { editorView } = editor(
537
+ doc(
538
+ p('text'),
539
+ table()(
540
+ tr(tdCursor, tdEmpty, tdEmpty),
541
+ tr(tdEmpty, tdEmpty, tdEmpty),
542
+ tr(tdEmpty, tdEmpty, tdEmpty),
543
+ ),
544
+ ),
545
+ );
546
+ const isInDanger = false;
547
+ const classNames = getRowClassNames(
548
+ hoveredRows[0],
549
+ editorView.state.selection,
550
+ hoveredRows,
551
+ isInDanger,
552
+ );
553
+ expect(classNames.indexOf('active') > -1).toBe(true);
554
+ });
555
+ describe('when isInDanger = true', () => {
556
+ it('return a string containing "danger" substring', () => {
557
+ const { editorView } = editor(
558
+ doc(
559
+ p('text'),
560
+ table()(
561
+ tr(tdCursor, tdEmpty, tdEmpty),
562
+ tr(tdEmpty, tdEmpty, tdEmpty),
563
+ tr(tdEmpty, tdEmpty, tdEmpty),
564
+ ),
565
+ ),
566
+ );
567
+ const isInDanger = true;
568
+ const classNames = getRowClassNames(
569
+ hoveredRows[0],
570
+ editorView.state.selection,
571
+ hoveredRows,
572
+ isInDanger,
573
+ );
574
+ expect(classNames.indexOf('danger') > -1).toBe(true);
575
+ });
576
+ });
577
+ });
578
+ });
579
+ });
580
+ describe('when selection is a CellSelection', () => {
581
+ describe('when no rows are fully selected', () => {
582
+ it('should return an empty string', () => {
583
+ const { editorView } = editor(
584
+ doc(
585
+ p('text'),
586
+ table()(
587
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
588
+ tr(tdEmpty, tdEmpty, tdEmpty),
589
+ tr(tdEmpty, td({})(p('{cell>}c3')), tdEmpty),
590
+ ),
591
+ ),
592
+ );
593
+
594
+ const classNames = getRowClassNames(
595
+ 0,
596
+ editorView.state.selection,
597
+ [],
598
+ false,
599
+ );
600
+ expect(classNames).toBe('');
601
+ });
602
+ });
603
+ describe('when a row is selected', () => {
604
+ it('return a string containing "active" substring', () => {
605
+ const { editorView } = editor(
606
+ doc(
607
+ p('text'),
608
+ table()(
609
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
610
+ tr(tdEmpty, tdEmpty, tdEmpty),
611
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
612
+ ),
613
+ ),
614
+ );
615
+
616
+ [0, 1, 2].forEach((index) => {
617
+ const classNames = getRowClassNames(
618
+ index,
619
+ editorView.state.selection,
620
+ [],
621
+ false,
622
+ );
623
+ expect(classNames.indexOf('active') > -1).toBe(true);
624
+ });
625
+ });
626
+ describe('when isInDanger = true', () => {
627
+ it('return a string containing "danger" substring', () => {
628
+ const { editorView } = editor(
629
+ doc(
630
+ p('text'),
631
+ table()(
632
+ tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
633
+ tr(tdEmpty, tdEmpty, tdEmpty),
634
+ tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
635
+ ),
636
+ ),
637
+ );
638
+ [0, 1, 2].forEach((index) => {
639
+ const classNames = getRowClassNames(
640
+ index,
641
+ editorView.state.selection,
642
+ [],
643
+ true,
644
+ );
645
+ expect(classNames.indexOf('danger') > -1).toBe(true);
646
+ });
647
+ });
648
+ });
649
+ });
650
+ });
651
+ });
652
+ });
@@ -111,6 +111,7 @@ export const mergeCellsWithAnalytics = (
111
111
  actionSubject: ACTION_SUBJECT.TABLE,
112
112
  actionSubjectId: null,
113
113
  attributes: {
114
+ inputMethod: INPUT_METHOD.CONTEXT_MENU, // TODO: merge with floating toolbar once command is updated
114
115
  horizontalCells,
115
116
  verticalCells,
116
117
  totalCells,
@@ -143,6 +144,7 @@ export const splitCellWithAnalytics = (
143
144
  actionSubject: ACTION_SUBJECT.TABLE,
144
145
  actionSubjectId: null,
145
146
  attributes: {
147
+ inputMethod: INPUT_METHOD.CONTEXT_MENU, // TODO: merge with floating toolbar once command is updated
146
148
  horizontalCells,
147
149
  verticalCells,
148
150
  totalCells: horizontalCells * verticalCells,
@@ -172,6 +174,7 @@ export const setColorWithAnalytics = (
172
174
  actionSubject: ACTION_SUBJECT.TABLE,
173
175
  actionSubjectId: null,
174
176
  attributes: {
177
+ inputMethod: INPUT_METHOD.CONTEXT_MENU, // TODO: merge with floating toolbar once command is updated
175
178
  cellColor: (
176
179
  tableBackgroundColorPalette.get(cellColor.toLowerCase()) || cellColor
177
180
  ).toLowerCase(),
@@ -18,11 +18,6 @@ import { EditorView } from 'prosemirror-view';
18
18
 
19
19
  import { browser } from '@atlaskit/editor-common/utils';
20
20
 
21
- // import {
22
- // isElementInTableCell,
23
- // isLastItemMediaGroup,
24
- // setNodeSelection,
25
- // } from '@atlaskit/editor-core/src/utils';
26
21
  import {
27
22
  isElementInTableCell,
28
23
  isLastItemMediaGroup,
@@ -160,8 +155,12 @@ export const handleClick = (view: EditorView, event: Event): boolean => {
160
155
  },
161
156
  },
162
157
  } = view;
163
- const editorElement = table.node.nodeAt(map.map[cellIndex]) as PmNode;
158
+ const cellPos = map.map[cellIndex];
159
+ if (isNaN(cellPos) || cellPos === undefined || typeof cellPos !== 'number') {
160
+ return false;
161
+ }
164
162
 
163
+ const editorElement = table.node.nodeAt(cellPos) as PmNode;
165
164
  /** Only if the last item is media group, insert a paragraph */
166
165
  if (isLastItemMediaGroup(editorElement)) {
167
166
  const posInTable = map.map[cellIndex] + editorElement.nodeSize;