@atlaskit/editor-plugin-table 7.2.2 → 7.3.0

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 (149) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/commands/column-resize.js +115 -45
  3. package/dist/cjs/commands/go-to-next-cell.js +7 -11
  4. package/dist/cjs/commands/misc.js +3 -2
  5. package/dist/cjs/commands/selection.js +3 -3
  6. package/dist/cjs/event-handlers.js +38 -25
  7. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  8. package/dist/cjs/pm-plugins/keymap.js +1 -0
  9. package/dist/cjs/pm-plugins/main.js +43 -9
  10. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
  11. package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
  12. package/dist/cjs/reducer.js +5 -2
  13. package/dist/cjs/utils/drag-menu.js +37 -23
  14. package/dist/cjs/utils/merged-cells.js +66 -1
  15. package/dist/es2019/commands/column-resize.js +100 -35
  16. package/dist/es2019/commands/go-to-next-cell.js +7 -9
  17. package/dist/es2019/commands/misc.js +3 -2
  18. package/dist/es2019/commands/selection.js +5 -5
  19. package/dist/es2019/event-handlers.js +17 -3
  20. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  21. package/dist/es2019/pm-plugins/keymap.js +3 -2
  22. package/dist/es2019/pm-plugins/main.js +41 -5
  23. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
  24. package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
  25. package/dist/es2019/reducer.js +5 -2
  26. package/dist/es2019/utils/drag-menu.js +38 -14
  27. package/dist/es2019/utils/merged-cells.js +73 -0
  28. package/dist/esm/commands/column-resize.js +105 -35
  29. package/dist/esm/commands/go-to-next-cell.js +7 -11
  30. package/dist/esm/commands/misc.js +3 -2
  31. package/dist/esm/commands/selection.js +5 -5
  32. package/dist/esm/event-handlers.js +38 -25
  33. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  34. package/dist/esm/pm-plugins/keymap.js +3 -2
  35. package/dist/esm/pm-plugins/main.js +38 -4
  36. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
  37. package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
  38. package/dist/esm/reducer.js +5 -2
  39. package/dist/esm/utils/drag-menu.js +36 -22
  40. package/dist/esm/utils/merged-cells.js +65 -0
  41. package/dist/types/commands/column-resize.d.ts +2 -0
  42. package/dist/types/commands/misc.d.ts +1 -1
  43. package/dist/types/types.d.ts +16 -0
  44. package/dist/types/utils/drag-menu.d.ts +4 -1
  45. package/dist/types/utils/merged-cells.d.ts +2 -0
  46. package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
  47. package/dist/types-ts4.5/commands/misc.d.ts +1 -1
  48. package/dist/types-ts4.5/types.d.ts +16 -0
  49. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  50. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  51. package/package.json +10 -17
  52. package/src/commands/column-resize.ts +155 -40
  53. package/src/commands/go-to-next-cell.ts +6 -15
  54. package/src/commands/misc.ts +2 -0
  55. package/src/commands/selection.ts +5 -5
  56. package/src/event-handlers.ts +21 -4
  57. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  58. package/src/pm-plugins/keymap.ts +3 -0
  59. package/src/pm-plugins/main.ts +47 -2
  60. package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
  61. package/src/pm-plugins/table-resizing/plugin.ts +18 -1
  62. package/src/reducer.ts +5 -2
  63. package/src/types.ts +16 -0
  64. package/src/utils/drag-menu.ts +94 -20
  65. package/src/utils/merged-cells.ts +78 -0
  66. package/tsconfig.dev.json +0 -69
  67. package/tsconfig.json +2 -877
  68. package/examples/99-testing.tsx +0 -140
  69. package/examples/config.jsonc +0 -14
  70. package/src/__tests__/unit/analytics.ts +0 -888
  71. package/src/__tests__/unit/collab.ts +0 -93
  72. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  73. package/src/__tests__/unit/commands/insert.ts +0 -137
  74. package/src/__tests__/unit/commands/misc.ts +0 -185
  75. package/src/__tests__/unit/commands/sort.ts +0 -128
  76. package/src/__tests__/unit/commands.ts +0 -745
  77. package/src/__tests__/unit/copy-button.ts +0 -22
  78. package/src/__tests__/unit/copy-paste.ts +0 -677
  79. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  80. package/src/__tests__/unit/event-handlers.ts +0 -296
  81. package/src/__tests__/unit/fix-tables.ts +0 -164
  82. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  83. package/src/__tests__/unit/handlers.ts +0 -98
  84. package/src/__tests__/unit/hover-selection.ts +0 -230
  85. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  86. package/src/__tests__/unit/index.ts +0 -912
  87. package/src/__tests__/unit/layout.ts +0 -146
  88. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  89. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  90. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  91. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  92. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  93. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  94. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  95. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  96. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  97. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  98. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  99. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  100. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  101. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  102. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  103. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  104. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  105. package/src/__tests__/unit/sort-column.ts +0 -399
  106. package/src/__tests__/unit/toolbar.ts +0 -512
  107. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  108. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  109. package/src/__tests__/unit/transforms/merging.ts +0 -392
  110. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  111. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  112. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  113. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  114. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  115. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  116. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  117. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  118. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  119. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  120. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  121. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  122. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  123. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  124. package/src/__tests__/unit/undo-redo.ts +0 -220
  125. package/src/__tests__/unit/utils/analytics.ts +0 -98
  126. package/src/__tests__/unit/utils/collapse.ts +0 -57
  127. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  128. package/src/__tests__/unit/utils/dom.ts +0 -180
  129. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  130. package/src/__tests__/unit/utils/nodes.ts +0 -79
  131. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  132. package/src/__tests__/unit/utils/table.ts +0 -96
  133. package/src/__tests__/unit/utils.ts +0 -670
  134. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  135. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  136. 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
  137. 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
  138. 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
  139. 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
  140. 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
  141. 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
  142. 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
  143. 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
  144. 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
  145. 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
  146. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  147. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  148. package/src/__tests__/visual-regression/index.ts +0 -62
  149. package/src/__tests__/visual-regression/sticky-header.ts +0 -61
@@ -1,888 +0,0 @@
1
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
- import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
3
- import type { DocBuilder } from '@atlaskit/editor-common/types';
4
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
5
- import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
6
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
7
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
8
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
9
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
10
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
11
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
12
- import type { Rect } from '@atlaskit/editor-tables/table-map';
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
- thEmpty,
29
- tr,
30
- } from '@atlaskit/editor-test-helpers/doc-builder';
31
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
32
- import sendKeyToPm from '@atlaskit/editor-test-helpers/send-key-to-pm';
33
- import { B50 } from '@atlaskit/theme/colors';
34
-
35
- import {
36
- deleteColumnsWithAnalytics,
37
- deleteRowsWithAnalytics,
38
- deleteTableIfSelectedWithAnalytics,
39
- deleteTableWithAnalytics,
40
- emptyMultipleCellsWithAnalytics,
41
- insertColumnWithAnalytics,
42
- insertRowWithAnalytics,
43
- mergeCellsWithAnalytics,
44
- setColorWithAnalytics,
45
- splitCellWithAnalytics,
46
- toggleHeaderColumnWithAnalytics,
47
- toggleHeaderRowWithAnalytics,
48
- toggleNumberColumnWithAnalytics,
49
- toggleTableLayoutWithAnalytics,
50
- } from '../../commands-with-analytics';
51
- import { handleCut } from '../../event-handlers';
52
- import tablePlugin from '../../plugin';
53
- import { setDropTarget } from '../../pm-plugins/drag-and-drop';
54
- import {
55
- clearDropTargetWithAnalytics,
56
- moveSourceWithAnalytics,
57
- } from '../../pm-plugins/drag-and-drop/commands-with-analytics';
58
- import { pluginKey } from '../../pm-plugins/plugin-key';
59
- import { replaceSelectedTable } from '../../transforms';
60
- import type { PluginConfig } from '../../types';
61
-
62
- const defaultTableDoc = doc(
63
- table()(
64
- tr(thEmpty, thEmpty, thEmpty),
65
- tr(tdEmpty, tdEmpty, tdEmpty),
66
- tr(tdEmpty, tdEmpty, tdCursor),
67
- ),
68
- );
69
-
70
- const secondRow: Rect = { left: 0, top: 1, bottom: 2, right: 3 };
71
- const secondColumn: Rect = { left: 1, top: 0, bottom: 3, right: 2 };
72
-
73
- // We don't need to test if the analytics implementation works (tested elsewhere)
74
- // We just want to know if the action is called.
75
- const mockAttachPayload = jest.fn();
76
- const analyticsPluginFake = () => ({
77
- name: 'analytics',
78
- actions: {
79
- attachAnalyticsEvent: mockAttachPayload.mockImplementation(() => () => {}),
80
- fireAnalyticsEvent: jest.fn(),
81
- },
82
- });
83
-
84
- describe('Table analytic events', () => {
85
- let editorAnalyticsAPIFake: EditorAnalyticsAPI;
86
- let analyticFireMock: jest.Mock;
87
-
88
- beforeEach(() => {
89
- analyticFireMock = jest.fn().mockReturnValue(jest.fn());
90
- editorAnalyticsAPIFake = {
91
- attachAnalyticsEvent: analyticFireMock,
92
- fireAnalyticsEvent: jest.fn(),
93
- };
94
- });
95
-
96
- const createEditor = createProsemirrorEditorFactory();
97
-
98
- const editor = (doc: DocBuilder) => {
99
- const tableOptions = {
100
- allowNumberColumn: true,
101
- allowHeaderRow: true,
102
- allowHeaderColumn: true,
103
- permittedLayouts: 'all',
104
- } as PluginConfig;
105
-
106
- const _editor = createEditor({
107
- doc,
108
- preset: new Preset<LightEditorPlugin>()
109
- .add([featureFlagsPlugin, {}])
110
- .add([
111
- analyticsPluginFake as unknown as typeof analyticsPlugin,
112
- { createAnalyticsEvent: jest.fn() },
113
- ])
114
- .add(contentInsertionPlugin)
115
- .add(widthPlugin)
116
- .add(guidelinePlugin)
117
- .add(selectionPlugin)
118
- .add([tablePlugin, { tableOptions, dragAndDropEnabled: true }]),
119
- pluginKey,
120
- });
121
-
122
- return _editor;
123
- };
124
-
125
- describe('table deleted', () => {
126
- beforeEach(() => {
127
- const { editorView } = editor(defaultTableDoc);
128
- deleteTableWithAnalytics(editorAnalyticsAPIFake)(
129
- editorView.state,
130
- editorView.dispatch,
131
- );
132
- });
133
-
134
- it('should fire v3 analytics', () => {
135
- expect(analyticFireMock).toHaveBeenCalledWith({
136
- action: 'deleted',
137
- actionSubject: 'table',
138
- attributes: expect.objectContaining({
139
- inputMethod: 'floatingToolbar',
140
- totalRowCount: 3,
141
- totalColumnCount: 3,
142
- }),
143
- eventType: 'track',
144
- });
145
- });
146
- });
147
-
148
- describe('table deleted if selected', () => {
149
- beforeEach(() => {
150
- const { editorView } = editor(
151
- doc(
152
- table()(
153
- tr(td()(p('{<cell}1')), td()(p('2'))),
154
- tr(td()(p('3')), td()(p('4{cell>}'))),
155
- ),
156
- ),
157
- );
158
- deleteTableIfSelectedWithAnalytics(editorAnalyticsAPIFake)(
159
- INPUT_METHOD.KEYBOARD,
160
- )(editorView.state, editorView.dispatch);
161
- });
162
-
163
- it('should fire v3 analytics', () => {
164
- expect(analyticFireMock).toHaveBeenCalledWith({
165
- action: 'deleted',
166
- actionSubject: 'table',
167
- attributes: expect.objectContaining({
168
- inputMethod: 'keyboard',
169
- totalRowCount: 2,
170
- totalColumnCount: 2,
171
- }),
172
- eventType: 'track',
173
- });
174
- });
175
- });
176
-
177
- describe('table cleared', () => {
178
- describe('context menu', () => {
179
- beforeEach(() => {
180
- const { editorView } = editor(
181
- doc(
182
- table()(
183
- tr(thEmpty, td()(p('{<cell}Hello')), thEmpty),
184
- tr(td()(p('Hello')), tdEmpty, tdEmpty),
185
- tr(tdEmpty, td()(p('{cell>}')), tdEmpty),
186
- ),
187
- ),
188
- );
189
-
190
- emptyMultipleCellsWithAnalytics(editorAnalyticsAPIFake)(
191
- INPUT_METHOD.CONTEXT_MENU,
192
- )(editorView.state, editorView.dispatch);
193
- });
194
-
195
- it('should fire v3 analytics', () => {
196
- expect(analyticFireMock).toHaveBeenCalledWith({
197
- action: 'cleared',
198
- actionSubject: 'table',
199
- actionSubjectId: null,
200
- attributes: expect.objectContaining({
201
- inputMethod: 'contextMenu',
202
- verticalCells: 3,
203
- horizontalCells: 1,
204
- totalRowCount: 3,
205
- totalColumnCount: 3,
206
- }),
207
- eventType: 'track',
208
- });
209
- });
210
- });
211
-
212
- describe('keyboard - Backspace', () => {
213
- beforeEach(() => {
214
- const { editorView } = editor(
215
- doc(
216
- table()(
217
- tr(thEmpty, td()(p('Hello')), thEmpty),
218
- tr(td()(p('{<cell}Hello')), tdEmpty, td()(p('{cell>}'))),
219
- tr(tdEmpty, tdEmpty, tdEmpty),
220
- ),
221
- ),
222
- );
223
-
224
- sendKeyToPm(editorView, 'Backspace');
225
- });
226
-
227
- it('should fire v3 analytics', () => {
228
- expect(mockAttachPayload).toHaveBeenCalledWith({
229
- action: 'cleared',
230
- actionSubject: 'table',
231
- actionSubjectId: null,
232
- attributes: expect.objectContaining({
233
- inputMethod: 'keyboard',
234
- verticalCells: 1,
235
- horizontalCells: 3,
236
- totalRowCount: 3,
237
- totalColumnCount: 3,
238
- }),
239
- eventType: 'track',
240
- });
241
- });
242
- });
243
- });
244
-
245
- describe('cells merged', () => {
246
- beforeEach(() => {
247
- const { editorView } = editor(
248
- doc(
249
- table()(
250
- tr(thEmpty, td()(p('{<cell}Hello')), thEmpty),
251
- tr(td()(p('Hello')), tdEmpty, tdEmpty),
252
- tr(tdEmpty, td()(p('{cell>}')), tdEmpty),
253
- ),
254
- ),
255
- );
256
-
257
- mergeCellsWithAnalytics(editorAnalyticsAPIFake)(
258
- INPUT_METHOD.CONTEXT_MENU,
259
- )(editorView.state, editorView.dispatch);
260
- });
261
-
262
- it('should fire v3 analytics', () => {
263
- expect(analyticFireMock).toHaveBeenCalledWith({
264
- action: 'merged',
265
- actionSubject: 'table',
266
- actionSubjectId: null,
267
- attributes: expect.objectContaining({
268
- verticalCells: 3,
269
- horizontalCells: 1,
270
- totalCells: 3,
271
- totalRowCount: 3,
272
- totalColumnCount: 3,
273
- }),
274
- eventType: 'track',
275
- });
276
- });
277
- });
278
-
279
- describe('cell split', () => {
280
- beforeEach(() => {
281
- const { editorView } = editor(
282
- doc(
283
- table()(
284
- tr(thEmpty, thEmpty, thEmpty),
285
- tr(td({ colspan: 3 })(p('{<>}'))),
286
- tr(tdEmpty, tdEmpty, tdEmpty),
287
- ),
288
- ),
289
- );
290
-
291
- splitCellWithAnalytics(editorAnalyticsAPIFake)(INPUT_METHOD.CONTEXT_MENU)(
292
- editorView.state,
293
- editorView.dispatch,
294
- );
295
- });
296
-
297
- it('should fire v3 analytics', () => {
298
- expect(analyticFireMock).toHaveBeenCalledWith({
299
- action: 'split',
300
- actionSubject: 'table',
301
- actionSubjectId: null,
302
- attributes: expect.objectContaining({
303
- verticalCells: 1,
304
- horizontalCells: 3,
305
- totalCells: 3,
306
- totalRowCount: 3,
307
- totalColumnCount: 3,
308
- }),
309
- eventType: 'track',
310
- });
311
- });
312
- });
313
-
314
- describe('cells colored', () => {
315
- beforeEach(() => {
316
- const { editorView } = editor(
317
- doc(
318
- table()(
319
- tr(thEmpty, td()(p('Hello')), thEmpty),
320
- tr(td()(p('{<cell}Hello')), tdEmpty, td()(p('{cell>}'))),
321
- tr(tdEmpty, tdEmpty, tdEmpty),
322
- ),
323
- ),
324
- );
325
-
326
- setColorWithAnalytics(editorAnalyticsAPIFake)(
327
- INPUT_METHOD.CONTEXT_MENU,
328
- B50,
329
- )(editorView.state, editorView.dispatch);
330
- });
331
-
332
- it('should fire v3 analytics', () => {
333
- expect(analyticFireMock).toHaveBeenCalledWith({
334
- action: 'colored',
335
- actionSubject: 'table',
336
- actionSubjectId: null,
337
- attributes: expect.objectContaining({
338
- cellColor: 'light blue',
339
- verticalCells: 1,
340
- horizontalCells: 3,
341
- totalCells: 3,
342
- totalRowCount: 3,
343
- totalColumnCount: 3,
344
- }),
345
- eventType: 'track',
346
- });
347
- });
348
- });
349
-
350
- describe('header row toggled', () => {
351
- beforeEach(() => {
352
- const { editorView } = editor(defaultTableDoc);
353
- toggleHeaderRowWithAnalytics(editorAnalyticsAPIFake)(
354
- editorView.state,
355
- editorView.dispatch,
356
- );
357
- });
358
-
359
- it('should fire v3 analytics', () => {
360
- expect(analyticFireMock).toHaveBeenCalledWith({
361
- action: 'toggledHeaderRow',
362
- actionSubject: 'table',
363
- actionSubjectId: null,
364
- attributes: expect.objectContaining({
365
- newState: false,
366
- totalRowCount: 3,
367
- totalColumnCount: 3,
368
- }),
369
- eventType: 'track',
370
- });
371
- });
372
- });
373
-
374
- describe('header column toggled', () => {
375
- beforeEach(() => {
376
- const { editorView } = editor(defaultTableDoc);
377
- toggleHeaderColumnWithAnalytics(editorAnalyticsAPIFake)(
378
- editorView.state,
379
- editorView.dispatch,
380
- );
381
- });
382
-
383
- it('should fire v3 analytics', () => {
384
- expect(analyticFireMock).toHaveBeenCalledWith({
385
- action: 'toggledHeaderColumn',
386
- actionSubject: 'table',
387
- actionSubjectId: null,
388
- attributes: expect.objectContaining({
389
- newState: true,
390
- totalRowCount: 3,
391
- totalColumnCount: 3,
392
- }),
393
- eventType: 'track',
394
- });
395
- });
396
- });
397
-
398
- describe('number column toggled', () => {
399
- beforeEach(() => {
400
- const { editorView } = editor(defaultTableDoc);
401
- toggleNumberColumnWithAnalytics(editorAnalyticsAPIFake)(
402
- editorView.state,
403
- editorView.dispatch,
404
- );
405
- });
406
-
407
- it('should fire v3 analytics', () => {
408
- expect(analyticFireMock).toHaveBeenCalledWith({
409
- action: 'toggledNumberColumn',
410
- actionSubject: 'table',
411
- actionSubjectId: null,
412
- attributes: expect.objectContaining({
413
- newState: true,
414
- totalRowCount: 3,
415
- totalColumnCount: 3,
416
- }),
417
- eventType: 'track',
418
- });
419
- });
420
- });
421
-
422
- describe('layout changed', () => {
423
- describe('normal', () => {
424
- it('should fire v3 analytics', () => {
425
- const { editorView } = editor(defaultTableDoc);
426
- toggleTableLayoutWithAnalytics(editorAnalyticsAPIFake)(
427
- editorView.state,
428
- editorView.dispatch,
429
- );
430
-
431
- expect(analyticFireMock).toHaveBeenCalledWith({
432
- action: 'changedBreakoutMode',
433
- actionSubject: 'table',
434
- actionSubjectId: null,
435
- attributes: expect.objectContaining({
436
- newBreakoutMode: 'wide',
437
- previousBreakoutMode: 'normal',
438
- totalRowCount: 3,
439
- totalColumnCount: 3,
440
- }),
441
- eventType: 'track',
442
- });
443
- });
444
- });
445
-
446
- describe('wide', () => {
447
- it('should fire v3 analytics', () => {
448
- const { editorView } = editor(
449
- doc(
450
- table({
451
- layout: 'wide',
452
- })(
453
- tr(thEmpty, thEmpty, thEmpty),
454
- tr(tdEmpty, tdEmpty, tdEmpty),
455
- tr(tdEmpty, tdEmpty, tdCursor),
456
- ),
457
- ),
458
- );
459
- toggleTableLayoutWithAnalytics(editorAnalyticsAPIFake)(
460
- editorView.state,
461
- editorView.dispatch,
462
- );
463
-
464
- expect(analyticFireMock).toHaveBeenCalledWith({
465
- action: 'changedBreakoutMode',
466
- actionSubject: 'table',
467
- actionSubjectId: null,
468
- attributes: expect.objectContaining({
469
- newBreakoutMode: 'fullWidth',
470
- previousBreakoutMode: 'wide',
471
- totalRowCount: 3,
472
- totalColumnCount: 3,
473
- }),
474
- eventType: 'track',
475
- });
476
- });
477
- });
478
-
479
- describe('fullWidth', () => {
480
- it('should fire v3 analytics', () => {
481
- const { editorView } = editor(
482
- doc(
483
- table({ layout: 'full-width' })(
484
- tr(thEmpty, thEmpty, thEmpty),
485
- tr(tdEmpty, tdEmpty, tdEmpty),
486
- tr(tdEmpty, tdEmpty, tdCursor),
487
- ),
488
- ),
489
- );
490
-
491
- toggleTableLayoutWithAnalytics(editorAnalyticsAPIFake)(
492
- editorView.state,
493
- editorView.dispatch,
494
- );
495
-
496
- expect(analyticFireMock).toHaveBeenCalledWith({
497
- action: 'changedBreakoutMode',
498
- actionSubject: 'table',
499
- actionSubjectId: null,
500
- attributes: expect.objectContaining({
501
- newBreakoutMode: 'normal',
502
- previousBreakoutMode: 'fullWidth',
503
- totalRowCount: 3,
504
- totalColumnCount: 3,
505
- }),
506
- eventType: 'track',
507
- });
508
- });
509
- });
510
- });
511
-
512
- describe('cut something from table', () => {
513
- beforeEach(() => {
514
- const { editorView } = editor(
515
- doc(
516
- table()(
517
- tr(thEmpty, td()(p('Hello')), thEmpty),
518
- tr(td()(p('{<cell}Hello')), tdEmpty, td()(p('{cell>}'))),
519
- tr(tdEmpty, tdEmpty, tdEmpty),
520
- ),
521
- ),
522
- );
523
-
524
- editorView.dispatch(
525
- handleCut(
526
- editorView.state.tr,
527
- editorView.state,
528
- editorView.state,
529
- editorAnalyticsAPIFake,
530
- ),
531
- );
532
- });
533
-
534
- it('should fire v3 analytics', () => {
535
- expect(analyticFireMock).toHaveBeenCalledWith({
536
- action: 'cut',
537
- actionSubject: 'table',
538
- actionSubjectId: null,
539
- attributes: expect.objectContaining({
540
- verticalCells: 1,
541
- horizontalCells: 3,
542
- totalCells: 3,
543
- totalRowCount: 3,
544
- totalColumnCount: 3,
545
- }),
546
- eventType: 'track',
547
- });
548
- });
549
- });
550
-
551
- describe('row added', () => {
552
- describe('context menu', () => {
553
- beforeEach(() => {
554
- const { editorView } = editor(defaultTableDoc);
555
- insertRowWithAnalytics(editorAnalyticsAPIFake)(
556
- INPUT_METHOD.CONTEXT_MENU,
557
- {
558
- index: 2,
559
- moveCursorToInsertedRow: false,
560
- },
561
- )(editorView.state, editorView.dispatch);
562
- });
563
-
564
- it('should fire v3 analytics', () => {
565
- expect(analyticFireMock).toHaveBeenCalledWith({
566
- action: 'addedRow',
567
- actionSubject: 'table',
568
- actionSubjectId: null,
569
- attributes: expect.objectContaining({
570
- inputMethod: 'contextMenu',
571
- position: 2,
572
- totalRowCount: 3,
573
- totalColumnCount: 3,
574
- }),
575
- eventType: 'track',
576
- });
577
- });
578
- });
579
-
580
- describe('keyboard', () => {
581
- describe('Tab', () => {
582
- beforeEach(() => {
583
- const { editorView } = editor(defaultTableDoc);
584
- sendKeyToPm(editorView, 'Tab');
585
- });
586
-
587
- it('should fire v3 analytics', () => {
588
- expect(mockAttachPayload).toHaveBeenCalledWith({
589
- action: 'addedRow',
590
- actionSubject: 'table',
591
- actionSubjectId: null,
592
- attributes: expect.objectContaining({
593
- inputMethod: 'keyboard',
594
- position: 3,
595
- totalRowCount: 3,
596
- totalColumnCount: 3,
597
- }),
598
- eventType: 'track',
599
- });
600
- });
601
- });
602
-
603
- describe('Shift-Tab', () => {
604
- beforeEach(() => {
605
- const { editorView } = editor(
606
- doc(
607
- table()(
608
- tr(tdCursor, tdEmpty, tdEmpty),
609
- tr(tdEmpty, tdEmpty, tdEmpty),
610
- tr(tdEmpty, tdEmpty, tdEmpty),
611
- ),
612
- ),
613
- );
614
- sendKeyToPm(editorView, 'Shift-Tab');
615
- });
616
-
617
- it('should fire v3 analytics', () => {
618
- expect(mockAttachPayload).toHaveBeenCalledWith({
619
- action: 'addedRow',
620
- actionSubject: 'table',
621
- actionSubjectId: null,
622
- attributes: expect.objectContaining({
623
- inputMethod: 'keyboard',
624
- position: 0,
625
- totalRowCount: 3,
626
- totalColumnCount: 3,
627
- }),
628
- eventType: 'track',
629
- });
630
- });
631
- });
632
- });
633
- });
634
-
635
- describe('column added', () => {
636
- const getEditorContainerWidth = () => {
637
- return { width: 500 };
638
- };
639
- beforeEach(() => {
640
- const { editorView } = editor(defaultTableDoc);
641
- insertColumnWithAnalytics(
642
- getEditorContainerWidth,
643
- editorAnalyticsAPIFake,
644
- )(INPUT_METHOD.CONTEXT_MENU, 2)(
645
- editorView.state,
646
- editorView.dispatch,
647
- editorView,
648
- );
649
- });
650
-
651
- it('should fire v3 analytics', () => {
652
- expect(analyticFireMock).toHaveBeenCalledWith({
653
- action: 'addedColumn',
654
- actionSubject: 'table',
655
- actionSubjectId: null,
656
- attributes: expect.objectContaining({
657
- inputMethod: 'contextMenu',
658
- position: 2,
659
- totalRowCount: 3,
660
- totalColumnCount: 3,
661
- }),
662
- eventType: 'track',
663
- });
664
- });
665
- });
666
-
667
- describe('row deleted', () => {
668
- beforeEach(() => {
669
- const { editorView } = editor(defaultTableDoc);
670
- deleteRowsWithAnalytics(editorAnalyticsAPIFake)(
671
- INPUT_METHOD.CONTEXT_MENU,
672
- secondRow,
673
- true,
674
- )(editorView.state, editorView.dispatch);
675
- });
676
-
677
- it('should fire v3 analytics', () => {
678
- expect(analyticFireMock).toHaveBeenCalledWith({
679
- action: 'deletedRow',
680
- actionSubject: 'table',
681
- actionSubjectId: null,
682
- attributes: expect.objectContaining({
683
- inputMethod: 'contextMenu',
684
- position: 1,
685
- count: 1,
686
- totalRowCount: 3,
687
- totalColumnCount: 3,
688
- }),
689
- eventType: 'track',
690
- });
691
- });
692
- });
693
-
694
- describe('column deleted', () => {
695
- beforeEach(() => {
696
- const { editorView } = editor(defaultTableDoc);
697
- deleteColumnsWithAnalytics(editorAnalyticsAPIFake)(
698
- INPUT_METHOD.CONTEXT_MENU,
699
- secondColumn,
700
- )(editorView.state, editorView.dispatch);
701
- });
702
-
703
- it('should fire v3 analytics', () => {
704
- expect(analyticFireMock).toHaveBeenCalledWith({
705
- action: 'deletedColumn',
706
- actionSubject: 'table',
707
- actionSubjectId: null,
708
- attributes: expect.objectContaining({
709
- inputMethod: 'contextMenu',
710
- position: 1,
711
- count: 1,
712
- totalRowCount: 3,
713
- totalColumnCount: 3,
714
- }),
715
- eventType: 'track',
716
- });
717
- });
718
- });
719
-
720
- describe('table replaced', () => {
721
- it('should fire v3 analytics', () => {
722
- const { editorView } = editor(
723
- doc(
724
- table()(
725
- tr(td()(p('{<cell}1')), td()(p('2'))),
726
- tr(td()(p('3')), td()(p('4{cell>}'))),
727
- ),
728
- ),
729
- );
730
- editorView.dispatch(
731
- replaceSelectedTable(
732
- editorView.state,
733
- 'text',
734
- INPUT_METHOD.KEYBOARD,
735
- editorAnalyticsAPIFake,
736
- ),
737
- );
738
-
739
- expect(analyticFireMock).toHaveBeenCalledWith({
740
- action: 'replaced',
741
- actionSubject: 'table',
742
- attributes: expect.objectContaining({
743
- totalRowCount: 2,
744
- totalColumnCount: 2,
745
- inputMethod: 'keyboard',
746
- }),
747
- eventType: 'track',
748
- });
749
- });
750
- });
751
-
752
- describe('track moved', () => {
753
- it.each([
754
- [
755
- 'Column',
756
- INPUT_METHOD.TABLE_CONTEXT_MENU,
757
- [0],
758
- 1,
759
- TABLE_STATUS.SUCCESS,
760
- 1,
761
- ],
762
- [
763
- 'Column',
764
- INPUT_METHOD.TABLE_CONTEXT_MENU,
765
- [2],
766
- 0,
767
- TABLE_STATUS.SUCCESS,
768
- -2,
769
- ],
770
- [
771
- 'Column',
772
- INPUT_METHOD.TABLE_CONTEXT_MENU,
773
- [2],
774
- 2,
775
- TABLE_STATUS.CANCELLED,
776
- 0,
777
- ],
778
-
779
- ['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, [0], 1, TABLE_STATUS.SUCCESS, 1],
780
- [
781
- 'Row',
782
- INPUT_METHOD.TABLE_CONTEXT_MENU,
783
- [2],
784
- 0,
785
- TABLE_STATUS.SUCCESS,
786
- -2,
787
- ],
788
- [
789
- 'Row',
790
- INPUT_METHOD.TABLE_CONTEXT_MENU,
791
- [2],
792
- 2,
793
- TABLE_STATUS.CANCELLED,
794
- 0,
795
- ],
796
-
797
- ['Column', INPUT_METHOD.DRAG_AND_DROP, [0], 1, TABLE_STATUS.SUCCESS, 1],
798
- ['Column', INPUT_METHOD.DRAG_AND_DROP, [2], 0, TABLE_STATUS.SUCCESS, -2],
799
- ['Column', INPUT_METHOD.DRAG_AND_DROP, [2], 2, TABLE_STATUS.CANCELLED, 0],
800
-
801
- ['Row', INPUT_METHOD.DRAG_AND_DROP, [0], 1, TABLE_STATUS.SUCCESS, 1],
802
- ['Row', INPUT_METHOD.DRAG_AND_DROP, [2], 0, TABLE_STATUS.SUCCESS, -2],
803
- ['Row', INPUT_METHOD.DRAG_AND_DROP, [2], 2, TABLE_STATUS.CANCELLED, 0],
804
- ])(
805
- 'should fire v3 analytics for %s using input %s moving index from %i to %i with status %s',
806
- (type, inputMethod, sourceIndex, targetIndex, status, distance) => {
807
- const { editorView } = editor(defaultTableDoc);
808
- moveSourceWithAnalytics(editorAnalyticsAPIFake)(
809
- inputMethod as
810
- | INPUT_METHOD.TABLE_CONTEXT_MENU
811
- | INPUT_METHOD.DRAG_AND_DROP,
812
- type === 'Row' ? 'table-row' : 'table-column',
813
- sourceIndex,
814
- targetIndex,
815
- )(editorView.state, editorView.dispatch);
816
-
817
- expect(analyticFireMock).toHaveBeenCalledWith({
818
- action: `moved${type}`,
819
- actionSubject: 'table',
820
- actionSubjectId: null,
821
- attributes: expect.objectContaining({
822
- inputMethod,
823
- count: 1,
824
- distance,
825
- status,
826
- totalRowCount: 3,
827
- totalColumnCount: 3,
828
- }),
829
- eventType: 'track',
830
- });
831
- },
832
- );
833
-
834
- describe('track moved', () => {
835
- let editorView: EditorView;
836
-
837
- beforeEach(() => {
838
- editorView = editor(defaultTableDoc).editorView;
839
- // Note: we cannot clean a drop target, util one has been set.
840
- setDropTarget(
841
- 'column',
842
- 0,
843
- false,
844
- )(editorView.state, editorView.dispatch);
845
- });
846
-
847
- it.each([
848
- ['Column', INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_STATUS.CANCELLED],
849
- ['Column', INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_STATUS.INVALID],
850
- ['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_STATUS.CANCELLED],
851
- ['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_STATUS.INVALID],
852
-
853
- ['Column', INPUT_METHOD.DRAG_AND_DROP, TABLE_STATUS.CANCELLED],
854
- ['Column', INPUT_METHOD.DRAG_AND_DROP, TABLE_STATUS.INVALID],
855
- ['Row', INPUT_METHOD.DRAG_AND_DROP, TABLE_STATUS.CANCELLED],
856
- ['Row', INPUT_METHOD.DRAG_AND_DROP, TABLE_STATUS.INVALID],
857
- ])(
858
- 'should fire v3 analytics for %s using input %s with status %s',
859
- (type, inputMethod, status) => {
860
- // const { editorView } = editor(defaultTableDoc);
861
- clearDropTargetWithAnalytics(editorAnalyticsAPIFake)(
862
- inputMethod as
863
- | INPUT_METHOD.TABLE_CONTEXT_MENU
864
- | INPUT_METHOD.DRAG_AND_DROP,
865
- type === 'Row' ? 'table-row' : 'table-column',
866
- [0],
867
- status as TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID,
868
- )(editorView.state, editorView.dispatch);
869
-
870
- expect(analyticFireMock).toHaveBeenCalledWith({
871
- action: `moved${type}`,
872
- actionSubject: 'table',
873
- actionSubjectId: null,
874
- attributes: expect.objectContaining({
875
- inputMethod,
876
- count: 1,
877
- distance: 0,
878
- status,
879
- totalRowCount: 3,
880
- totalColumnCount: 3,
881
- }),
882
- eventType: 'track',
883
- });
884
- },
885
- );
886
- });
887
- });
888
- });