@atlaskit/editor-plugin-table 7.2.1 → 7.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +11 -7
  3. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  4. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +11 -25
  5. package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +13 -3
  6. package/dist/cjs/ui/TableFloatingColumnControls/index.js +7 -3
  7. package/dist/cjs/utils/drag-menu.js +37 -23
  8. package/dist/cjs/utils/merged-cells.js +66 -1
  9. package/dist/es2019/nodeviews/TableComponent.js +9 -5
  10. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  11. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
  12. package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
  13. package/dist/es2019/ui/TableFloatingColumnControls/index.js +7 -3
  14. package/dist/es2019/utils/drag-menu.js +38 -14
  15. package/dist/es2019/utils/merged-cells.js +73 -0
  16. package/dist/esm/nodeviews/TableComponent.js +11 -7
  17. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  18. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
  19. package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
  20. package/dist/esm/ui/TableFloatingColumnControls/index.js +7 -3
  21. package/dist/esm/utils/drag-menu.js +36 -22
  22. package/dist/esm/utils/merged-cells.js +65 -0
  23. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  24. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
  25. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +1 -0
  26. package/dist/types/utils/drag-menu.d.ts +4 -1
  27. package/dist/types/utils/merged-cells.d.ts +2 -0
  28. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  29. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
  30. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +1 -0
  31. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  32. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  33. package/package.json +9 -16
  34. package/src/nodeviews/TableComponent.tsx +1 -0
  35. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  36. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +6 -27
  37. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -1
  38. package/src/ui/TableFloatingColumnControls/index.tsx +5 -0
  39. package/src/utils/drag-menu.ts +94 -20
  40. package/src/utils/merged-cells.ts +78 -0
  41. package/tsconfig.dev.json +0 -69
  42. package/tsconfig.json +2 -871
  43. package/examples/99-testing.tsx +0 -140
  44. package/examples/config.jsonc +0 -14
  45. package/src/__tests__/unit/analytics.ts +0 -888
  46. package/src/__tests__/unit/collab.ts +0 -93
  47. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  48. package/src/__tests__/unit/commands/insert.ts +0 -137
  49. package/src/__tests__/unit/commands/misc.ts +0 -185
  50. package/src/__tests__/unit/commands/sort.ts +0 -128
  51. package/src/__tests__/unit/commands.ts +0 -745
  52. package/src/__tests__/unit/copy-button.ts +0 -22
  53. package/src/__tests__/unit/copy-paste.ts +0 -677
  54. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  55. package/src/__tests__/unit/event-handlers.ts +0 -296
  56. package/src/__tests__/unit/fix-tables.ts +0 -164
  57. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  58. package/src/__tests__/unit/handlers.ts +0 -98
  59. package/src/__tests__/unit/hover-selection.ts +0 -230
  60. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  61. package/src/__tests__/unit/index.ts +0 -912
  62. package/src/__tests__/unit/layout.ts +0 -146
  63. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  64. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  65. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  66. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  67. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  68. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  69. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  70. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  71. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  72. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  73. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  74. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  75. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  76. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  77. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  78. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  79. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  80. package/src/__tests__/unit/sort-column.ts +0 -399
  81. package/src/__tests__/unit/toolbar.ts +0 -512
  82. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  83. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  84. package/src/__tests__/unit/transforms/merging.ts +0 -392
  85. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  86. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  87. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  88. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  89. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  90. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  91. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  92. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  93. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  94. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  95. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  96. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  97. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  98. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  99. package/src/__tests__/unit/undo-redo.ts +0 -220
  100. package/src/__tests__/unit/utils/analytics.ts +0 -98
  101. package/src/__tests__/unit/utils/collapse.ts +0 -57
  102. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  103. package/src/__tests__/unit/utils/dom.ts +0 -180
  104. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  105. package/src/__tests__/unit/utils/nodes.ts +0 -79
  106. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  107. package/src/__tests__/unit/utils/table.ts +0 -96
  108. package/src/__tests__/unit/utils.ts +0 -670
  109. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  110. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  111. 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
  112. 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
  113. 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
  114. 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
  115. 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
  116. 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
  117. 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
  118. 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
  119. 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
  120. 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
  121. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  122. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  123. package/src/__tests__/visual-regression/index.ts +0 -62
  124. package/src/__tests__/visual-regression/sticky-header.ts +0 -61
@@ -1,507 +0,0 @@
1
- // @ts-ignore
2
- import { replaceRaf } from 'raf-stub';
3
-
4
- import { uuid } from '@atlaskit/adf-schema';
5
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
6
- import type { DocBuilder } from '@atlaskit/editor-common/types';
7
- import {
8
- NodeSelection,
9
- TextSelection,
10
- } from '@atlaskit/editor-prosemirror/state';
11
- import { __serializeForClipboard } from '@atlaskit/editor-prosemirror/view';
12
- import { CellSelection } from '@atlaskit/editor-tables';
13
- import { selectTable } from '@atlaskit/editor-tables/utils';
14
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
15
- import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
16
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
17
- import dispatchPasteEvent from '@atlaskit/editor-test-helpers/dispatch-paste-event';
18
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
19
- import {
20
- doc,
21
- expand,
22
- layoutColumn,
23
- layoutSection,
24
- p,
25
- table,
26
- td,
27
- th,
28
- tr,
29
- } from '@atlaskit/editor-test-helpers/doc-builder';
30
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
31
- import { insertText } from '@atlaskit/editor-test-helpers/transactions';
32
-
33
- import { handleCut } from '../../../event-handlers';
34
- import { pluginKey as tablePluginKey } from '../../../pm-plugins/plugin-key';
35
- import type { PluginConfig, TablePluginState } from '../../../types';
36
-
37
- replaceRaf();
38
- const requestAnimationFrame = window.requestAnimationFrame as any;
39
-
40
- const mockUuidGenerated = 'a-mock-uuid';
41
- const mockUuidGenerate = jest.fn().mockReturnValue(mockUuidGenerated);
42
-
43
- jest.mock('@atlaskit/adf-schema', () => ({
44
- ...jest.requireActual<Object>('@atlaskit/adf-schema'),
45
- uuid: {
46
- generate: () => mockUuidGenerate(),
47
- },
48
- }));
49
-
50
- describe('table local id plugin', () => {
51
- // Won't use `createProsemirrorEditorFactory` here, to also cover editorprops
52
- const createEditor = createEditorFactory<TablePluginState>();
53
-
54
- const editor = (
55
- doc: DocBuilder,
56
- options: {
57
- skipRefs: boolean;
58
- defaultValue: any;
59
- } = {
60
- skipRefs: false,
61
- defaultValue: undefined,
62
- },
63
- ) => {
64
- const { skipRefs, defaultValue } = options;
65
- const tableOptions = {
66
- allowNumberColumn: true,
67
- allowHeaderRow: true,
68
- allowHeaderColumn: true,
69
- allowBackgroundColor: true,
70
- permittedLayouts: 'all',
71
- } as PluginConfig;
72
- return createEditor({
73
- doc,
74
- editorProps: {
75
- allowExpand: true,
76
- allowLayouts: true,
77
- allowTables: tableOptions,
78
- defaultValue,
79
- },
80
- pluginKey: tablePluginKey,
81
- skipRefs,
82
- });
83
- };
84
-
85
- const localIdString = 'mochi-is-fluffy';
86
- const localIdString2 = 'neko-is-hungry';
87
- const flooFirst = 'floo-the-first';
88
- const flooSecond = 'floo-the-second';
89
- const flooThird = 'floo-the-third';
90
-
91
- const generateTableWithLocalId = (localId: string) =>
92
- table({ localId: localId })(
93
- tr(th()(p('1')), th()(p('2')), th()(p('3'))),
94
- tr(td()(p('4')), td()(p('5')), td()(p('6'))),
95
- tr(td()(p('7')), td()(p('8')), td()(p('9'))),
96
- );
97
-
98
- afterEach(() => {
99
- jest.restoreAllMocks();
100
- });
101
-
102
- describe('Table localId duplication plugin', () => {
103
- describe('table initialisation', () => {
104
- it('should generate IDs on multiple tables without IDs', () => {
105
- const spy = jest
106
- .spyOn(uuid, 'generate')
107
- .mockReturnValueOnce(flooFirst)
108
- .mockReturnValueOnce(flooSecond);
109
- /**
110
- * We need to feed in a defaultValue here and skip the ref logic in
111
- * createEditor as that setSelection fires off some transaction
112
- * which inadvertently triggers our usual "a table is added" checks.
113
- *
114
- * We want to check that this flow can happen:
115
- * 1. load document with pre-existing non-local-id table
116
- * 2. immediately use it for charts (without adding a new table to
117
- * trigger our "check all table IDs" logic in appendTransaction)
118
- */
119
-
120
- const tableAsDefaultValue = {
121
- version: 1,
122
- type: 'doc',
123
- content: [
124
- {
125
- type: 'table',
126
- attrs: {
127
- isNumberColumnEnabled: false,
128
- layout: 'default',
129
- localId: undefined,
130
- },
131
- content: [
132
- {
133
- type: 'tableRow',
134
- content: [
135
- {
136
- type: 'tableHeader',
137
- content: [
138
- {
139
- type: 'paragraph',
140
- content: [
141
- {
142
- type: 'text',
143
- text: '1',
144
- },
145
- ],
146
- },
147
- ],
148
- },
149
- ],
150
- },
151
- ],
152
- },
153
- {
154
- type: 'table',
155
- attrs: {
156
- isNumberColumnEnabled: false,
157
- layout: 'default',
158
- localId: undefined,
159
- },
160
- content: [
161
- {
162
- type: 'tableRow',
163
- content: [
164
- {
165
- type: 'tableHeader',
166
- content: [
167
- {
168
- type: 'paragraph',
169
- content: [
170
- {
171
- type: 'text',
172
- text: '1',
173
- },
174
- ],
175
- },
176
- ],
177
- },
178
- ],
179
- },
180
- ],
181
- },
182
- {
183
- type: 'paragraph',
184
- content: [],
185
- },
186
- ],
187
- };
188
- const { editorView } = editor(doc(), {
189
- skipRefs: true,
190
- defaultValue: tableAsDefaultValue,
191
- });
192
- // Ensure we actually initialised with no ID
193
- expect(editorView.state.doc).toEqualDocument(
194
- doc(
195
- table({ localId: '' })(tr(th()(p('1')))),
196
- table({ localId: '' })(tr(th()(p('1')))),
197
- p(''),
198
- ),
199
- );
200
- expect(spy).toBeCalledTimes(0);
201
-
202
- // Check we add IDs for existing tables
203
- let { state } = editorView;
204
- editorView.updateState(state);
205
- requestAnimationFrame.step();
206
- /**
207
- * This one is really only needed if we use the "remove the
208
- * `checkIsAddingTable` solution". But who doesn't want to feed the cats
209
- */
210
- insertText(editorView, 'feed the cats', state.doc.nodeSize - 3);
211
-
212
- expect(editorView.state.doc).toEqualDocument(
213
- doc(
214
- table({ localId: flooFirst })(tr(th()(p('1')))),
215
- table({ localId: flooSecond })(tr(th()(p('1')))),
216
- p('feed the cats'),
217
- ),
218
- );
219
- expect(spy).toBeCalledTimes(2);
220
- });
221
- });
222
- describe('basic editing of a table', () => {
223
- it('should NOT touch/overwrite localIds if inserting text inside a table', () => {
224
- const { editorView, sel } = editor(
225
- doc(
226
- table({ localId: localIdString })(tr(th()(p('{<>}1')))),
227
- table({ localId: localIdString2 })(tr(th()(p('2')))),
228
- p(''),
229
- ),
230
- );
231
- let { state } = editorView;
232
- editorView.updateState(state);
233
- insertText(editorView, 'feed the cats', sel);
234
- expect(editorView.state.doc).toEqualDocument(
235
- doc(
236
- table({ localId: localIdString })(tr(th()(p('feed the cats1')))),
237
- table({ localId: localIdString2 })(tr(th()(p('2')))),
238
- p(''),
239
- ),
240
- );
241
- });
242
- });
243
- describe('basic copy paste', () => {
244
- it('generates a new ID when encountering a duplicate', () => {
245
- const spy = jest.spyOn(uuid, 'generate').mockReturnValueOnce(flooFirst);
246
- const {
247
- editorView,
248
- refs: { paragraphPos },
249
- } = editor(
250
- doc(
251
- table({ localId: localIdString })(tr(th()(p('{<>}1')))),
252
- p('{paragraphPos}'),
253
- ),
254
- );
255
-
256
- let { state } = editorView;
257
- // select table
258
- state = state.apply(selectTable(state.tr));
259
-
260
- // copy table
261
- const { dom, text } = __serializeForClipboard(
262
- editorView,
263
- state.selection.content(),
264
- );
265
-
266
- // move to paragraph
267
- const $paraPos = state.doc.resolve(paragraphPos);
268
- state = state.apply(
269
- state.tr.setSelection(new TextSelection($paraPos, $paraPos)),
270
- );
271
-
272
- editorView.updateState(state);
273
-
274
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
275
-
276
- expect(editorView.state.doc).toEqualDocument(
277
- doc(
278
- table({ localId: localIdString })(tr(th()(p('1')))),
279
- table({ localId: flooFirst })(tr(th()(p('1')))),
280
- ),
281
- );
282
- expect(spy).toBeCalledTimes(1);
283
- });
284
- });
285
- describe('cut & multiple pastes', () => {
286
- it('detects duplicates inside expand & tables', () => {
287
- const spy = jest
288
- .spyOn(uuid, 'generate')
289
- .mockReturnValueOnce(flooSecond)
290
- .mockReturnValueOnce(flooThird);
291
-
292
- const {
293
- editorView,
294
- refs: { from, to, insideExpandPos, insideLayoutPos },
295
- } = editor(
296
- doc(
297
- expand({ title: '' })(p('{insideExpandPos}')),
298
- layoutSection(
299
- layoutColumn({ width: 50 })(
300
- table({ localId: flooFirst })(
301
- tr(th()(p('{from}1')), th()(p('2')), th()(p('3'))),
302
- tr(td()(p('4')), td()(p('5')), td()(p('6'))),
303
- tr(td()(p('7')), td()(p('8')), td()(p('{to}9'))),
304
- ),
305
- ),
306
- layoutColumn({ width: 50 })(p('{insideLayoutPos}')),
307
- ),
308
- p(''),
309
- ),
310
- );
311
-
312
- let { state } = editorView;
313
- // select table
314
- const sel = new CellSelection(
315
- state.doc.resolve(from - 2),
316
- state.doc.resolve(to - 2),
317
- );
318
- editorView.dispatch(state.tr.setSelection(sel as any));
319
-
320
- // "copy" table
321
- const { dom, text } = __serializeForClipboard(
322
- editorView,
323
- sel.content(),
324
- );
325
- let state2 = editorView.state;
326
- const insideLayout = state2.doc.resolve(insideLayoutPos);
327
- // Move cursor inside layout
328
- state2 = state2.apply(
329
- state2.tr.setSelection(new TextSelection(insideLayout)),
330
- );
331
- editorView.updateState(state2);
332
-
333
- // paste into layout, expect new ID
334
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
335
- expect(editorView.state.doc).toEqualDocument(
336
- doc(
337
- expand({ title: '' })(p('')),
338
- layoutSection(
339
- layoutColumn({ width: 50 })(generateTableWithLocalId(flooFirst)),
340
- layoutColumn({ width: 50 })(generateTableWithLocalId(flooSecond)),
341
- ),
342
- p(),
343
- ),
344
- );
345
- expect(spy).toBeCalledTimes(1);
346
-
347
- let state3 = editorView.state;
348
- const insideExpand = state3.doc.resolve(insideExpandPos);
349
- // Move cursor inside layout
350
- state3 = state3.apply(
351
- state3.tr.setSelection(new TextSelection(insideExpand)),
352
- );
353
- editorView.updateState(state3);
354
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
355
-
356
- expect(editorView.state.doc).toEqualDocument(
357
- doc(
358
- expand({ title: '' })(generateTableWithLocalId(flooThird)),
359
- layoutSection(
360
- layoutColumn({ width: 50 })(generateTableWithLocalId(flooFirst)),
361
- layoutColumn({ width: 50 })(generateTableWithLocalId(flooSecond)),
362
- ),
363
- p(),
364
- ),
365
- );
366
- expect(spy).toBeCalledTimes(2);
367
- });
368
- it('generates a new ID when pasting a table with an existing ID', () => {
369
- const spy = jest
370
- .spyOn(uuid, 'generate')
371
- .mockReturnValueOnce(flooFirst)
372
- .mockReturnValueOnce(flooSecond);
373
-
374
- const editorAnalyticsAPIFake: EditorAnalyticsAPI = {
375
- attachAnalyticsEvent: jest.fn().mockReturnValue(() => jest.fn()),
376
- fireAnalyticsEvent: jest.fn(),
377
- };
378
-
379
- const {
380
- editorView,
381
- refs: { from, to },
382
- } = editor(
383
- doc(
384
- table({ localId: localIdString })(
385
- tr(th()(p('{from}1')), th()(p('2')), th()(p('3'))),
386
- tr(td()(p('4')), td()(p('5')), td()(p('6'))),
387
- tr(td()(p('7')), td()(p('8')), td()(p('{to}9'))),
388
- ),
389
- p('{paragraphPos}'),
390
- ),
391
- );
392
-
393
- let { state } = editorView;
394
- // select table
395
- const sel = new CellSelection(
396
- state.doc.resolve(from - 2),
397
- state.doc.resolve(to - 2),
398
- );
399
- editorView.dispatch(state.tr.setSelection(sel as any));
400
-
401
- // "copy" table
402
- const { dom, text } = __serializeForClipboard(
403
- editorView,
404
- sel.content(),
405
- );
406
- const oldState = editorView.state;
407
- const newTr = handleCut(
408
- oldState.tr,
409
- oldState,
410
- editorView.state,
411
- editorAnalyticsAPIFake,
412
- );
413
-
414
- // Ensure table is "cut"/removed
415
- expect(newTr.doc).toEqualDocument(doc(p('')));
416
- editorView.dispatch(newTr);
417
-
418
- expect(
419
- editorAnalyticsAPIFake.attachAnalyticsEvent,
420
- ).toHaveBeenCalledWith({
421
- action: 'cut',
422
- actionSubject: 'table',
423
- actionSubjectId: null,
424
- attributes: {
425
- horizontalCells: 3,
426
- totalCells: 9,
427
- totalColumnCount: 3,
428
- totalRowCount: 3,
429
- verticalCells: 3,
430
- },
431
- eventType: 'track',
432
- });
433
-
434
- // Paste it & ensure we retain the same ID
435
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
436
- expect(editorView.state.doc).toEqualDocument(
437
- doc(generateTableWithLocalId(localIdString)),
438
- );
439
-
440
- /** Paste twice, observe for two new generated IDs */
441
- let state2 = editorView.state;
442
- const endOfDoc2 = state2.doc.resolve(state2.doc.nodeSize - 2);
443
- // Move cursor to end of doc, to avoid pasting more cells into existing table
444
- state2 = state2.apply(
445
- state2.tr.setSelection(new TextSelection(endOfDoc2)),
446
- );
447
- editorView.updateState(state2);
448
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
449
-
450
- // Second paste
451
- let state3 = editorView.state;
452
- const endOfDoc3 = state3.doc.resolve(state3.doc.nodeSize - 2);
453
- // Move cursor to end of doc, to avoid pasting more cells into existing table
454
- state3 = state3.apply(
455
- state3.tr.setSelection(new TextSelection(endOfDoc3)),
456
- );
457
- editorView.updateState(state3);
458
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
459
-
460
- expect(editorView.state.doc).toEqualDocument(
461
- doc(
462
- generateTableWithLocalId(localIdString),
463
- generateTableWithLocalId(flooFirst),
464
- generateTableWithLocalId(flooSecond),
465
- ),
466
- );
467
- expect(spy).toBeCalledTimes(2);
468
- });
469
- it('_retains_ IDs when pasting the same table IDs over existing IDs', () => {
470
- const spy = jest
471
- .spyOn(uuid, 'generate')
472
- .mockReturnValueOnce(flooFirst)
473
- .mockReturnValueOnce(flooSecond);
474
-
475
- const localIdString = 'mochi-is-fluffy';
476
- const { editorView } = editor(
477
- doc(
478
- table({ localId: localIdString })(
479
- tr(th()(p('1')), th()(p('2')), th()(p('3'))),
480
- tr(td()(p('4')), td()(p('5')), td()(p('6'))),
481
- tr(td()(p('7')), td()(p('8')), td()(p('9'))),
482
- ),
483
- p(''),
484
- ),
485
- );
486
-
487
- let { state } = editorView;
488
- // select doc
489
- const sel = NodeSelection.create(state.doc, 0);
490
- editorView.dispatch(state.tr.setSelection(sel));
491
-
492
- // "copy" entire doc
493
- const { dom, text } = __serializeForClipboard(
494
- editorView,
495
- sel.content(),
496
- );
497
-
498
- // Paste it & ensure we retain the same ID
499
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
500
- expect(editorView.state.doc).toEqualDocument(
501
- doc(generateTableWithLocalId(localIdString), p('')),
502
- );
503
- expect(spy).not.toBeCalled();
504
- });
505
- });
506
- });
507
- });