@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,22 +0,0 @@
1
- export {};
2
-
3
- it.skip('TODO; restore unit', () => {});
4
-
5
- // import { _getCopyButtonTestSuite } from '../../../copy-button/__tests__/unit/_getCopyButtonTestSuite';
6
- // import {
7
- // doc,
8
- // p,
9
- // table,
10
- // tr,
11
- // td,
12
- // } from '@atlaskit/editor-test-helpers/doc-builder';
13
-
14
- // _getCopyButtonTestSuite({
15
- // nodeType: 'table',
16
- // editorOptions: {
17
- // allowTables: {
18
- // advanced: true,
19
- // },
20
- // },
21
- // doc: doc(table()(tr(td({})(p())), tr(td({})(p())), tr(td({})(p())))),
22
- // });
@@ -1,677 +0,0 @@
1
- // @ts-ignore
2
-
3
- import { uuid } from '@atlaskit/adf-schema';
4
- import { transformSliceToRemoveOpenExpand } from '@atlaskit/editor-common/transforms';
5
- import type { DocBuilder } from '@atlaskit/editor-common/types';
6
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
7
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
8
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
9
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
10
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
11
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
12
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
13
- import type {
14
- Node as ProsemirrorNode,
15
- Schema,
16
- } from '@atlaskit/editor-prosemirror/model';
17
- import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
18
- import type {
19
- PluginKey,
20
- Transaction,
21
- } from '@atlaskit/editor-prosemirror/state';
22
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
23
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
24
- import { __serializeForClipboard } from '@atlaskit/editor-prosemirror/view';
25
- import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
26
- import {
27
- getCellsInTable,
28
- selectColumn,
29
- selectTable,
30
- } from '@atlaskit/editor-tables/utils';
31
- // eslint-disable-next-line import/no-extraneous-dependencies
32
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
33
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
34
- import {
35
- createProsemirrorEditorFactory,
36
- Preset,
37
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
38
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
39
- import dispatchPasteEvent from '@atlaskit/editor-test-helpers/dispatch-paste-event';
40
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
41
- import {
42
- br,
43
- code_block,
44
- doc,
45
- expand,
46
- p,
47
- panel,
48
- table,
49
- td,
50
- th,
51
- tr,
52
- } from '@atlaskit/editor-test-helpers/doc-builder';
53
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
54
- import defaultSchema from '@atlaskit/editor-test-helpers/schema';
55
-
56
- import tablePlugin from '../../plugin';
57
- import { pluginKey as tablePluginKey } from '../../pm-plugins/plugin-key';
58
- import type { PluginConfig, TablePluginState } from '../../types';
59
- import {
60
- removeTableFromFirstChild,
61
- removeTableFromLastChild,
62
- transformSliceToFixHardBreakProblemOnCopyFromCell,
63
- transformSliceToRemoveOpenTable,
64
- unwrapContentFromTable,
65
- } from '../../utils/paste';
66
-
67
- const TABLE_LOCAL_ID = 'test-table-local-id';
68
- const array = (...args: any): Node[] => args.map((i: any) => i(defaultSchema));
69
- const fragment = (...args: any) =>
70
- Fragment.from(args.map((i: any) => i(defaultSchema)));
71
-
72
- const selectCell =
73
- (cell: { pos: number; start: number; node: ProsemirrorNode }) =>
74
- (tr: Transaction) => {
75
- const $anchor = tr.doc.resolve(cell.pos);
76
- return tr.setSelection(new CellSelection($anchor, $anchor) as any);
77
- };
78
-
79
- const copySelectionAndPasteAtPos = ({
80
- editorView,
81
- pasteStartPos,
82
- pasteEndPos,
83
- }: {
84
- editorView: EditorView;
85
- pasteStartPos: number;
86
- pasteEndPos: number;
87
- }) => {
88
- // collect the content that would have been serialized to clipboard on copy
89
- const { dom, text } = __serializeForClipboard(
90
- editorView,
91
- editorView.state.selection.content(),
92
- );
93
-
94
- // move selection to intended paste location
95
- const $startPos = editorView.state.doc.resolve(pasteStartPos);
96
- const $endPos = editorView.state.doc.resolve(pasteEndPos);
97
- editorView.dispatch(
98
- editorView.state.tr.setSelection(new TextSelection($startPos, $endPos)),
99
- );
100
-
101
- // paste the clipboard-serialized content
102
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
103
- };
104
-
105
- describe('table plugin', () => {
106
- beforeAll(() => {
107
- uuid.setStatic(TABLE_LOCAL_ID);
108
- });
109
-
110
- afterAll(() => {
111
- uuid.setStatic(false);
112
- });
113
- const createEditor = createProsemirrorEditorFactory();
114
-
115
- const tableOptions = {
116
- allowNumberColumn: true,
117
- allowHeaderRow: true,
118
- allowHeaderColumn: true,
119
- allowBackgroundColor: true,
120
- permittedLayouts: 'all',
121
- } as PluginConfig;
122
-
123
- const preset = new Preset<LightEditorPlugin>()
124
- .add([featureFlagsPlugin, {}])
125
- .add([analyticsPlugin, {}])
126
- .add(contentInsertionPlugin)
127
- .add(widthPlugin)
128
- .add(guidelinePlugin)
129
- .add(selectionPlugin)
130
- .add([tablePlugin, { tableOptions }]);
131
-
132
- const editor = (doc: DocBuilder) => {
133
- return createEditor<TablePluginState, PluginKey, typeof preset>({
134
- doc,
135
- preset,
136
- pluginKey: tablePluginKey,
137
- });
138
- };
139
-
140
- describe('TableView', () => {
141
- describe('copy paste', () => {
142
- it('copies one cell onto another', () => {
143
- const { editorView } = editor(
144
- doc(
145
- table()(
146
- tr(th()(p('{<>}1')), th()(p('2')), th()(p('3'))),
147
- tr(td()(p('4')), td()(p('5')), td()(p('6'))),
148
- tr(td()(p('7')), td()(p('8')), td()(p('9'))),
149
- ),
150
- ),
151
- );
152
-
153
- let { state } = editorView;
154
-
155
- // select first cell
156
- const cells = getCellsInTable(state.selection);
157
- expect(cells![0].node.textContent).toEqual('1');
158
- state = state.apply(selectCell(cells![0])(state.tr));
159
-
160
- // copy it
161
- const { dom, text } = __serializeForClipboard(
162
- editorView,
163
- state.selection.content(),
164
- );
165
-
166
- // select the destination cell, which is 8
167
- const targetCell = cells![cells!.length - 2];
168
- expect(targetCell.node.textContent).toEqual('8');
169
- state = state.apply(selectCell(targetCell)(state.tr));
170
-
171
- // apply local state to view before paste
172
- editorView.updateState(state);
173
-
174
- // paste the first cell over the top of it
175
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
176
-
177
- expect(editorView.state.doc).toEqualDocument(
178
- doc(
179
- table({ localId: TABLE_LOCAL_ID })(
180
- tr(th()(p('1')), th()(p('2')), th()(p('3'))),
181
- tr(td()(p('4')), td()(p('5')), td()(p('6'))),
182
- tr(td()(p('7')), td()(p('1')), td()(p('9'))),
183
- ),
184
- ),
185
- );
186
- });
187
-
188
- it('copies one column onto another', () => {
189
- const {
190
- editorView,
191
- refs: { nextPos },
192
- } = editor(
193
- doc(
194
- table()(
195
- tr(th()(p('{<>}1')), th()(p('2')), th()(p('3{nextPos}'))),
196
- tr(td()(p('4')), td()(p('5')), td()(p('6'))),
197
- tr(td()(p('7')), td()(p('8')), td()(p('9'))),
198
- ),
199
- ),
200
- );
201
-
202
- let { state } = editorView;
203
-
204
- // select second column
205
- state = state.apply(selectColumn(1)(state.tr));
206
-
207
- // copy it
208
- const { dom, text } = __serializeForClipboard(
209
- editorView,
210
- state.selection.content(),
211
- );
212
-
213
- // move cursor to the 3rd column
214
- const $pos = state.doc.resolve(nextPos);
215
- state = state.apply(
216
- state.tr.setSelection(new TextSelection($pos, $pos)),
217
- );
218
-
219
- // apply local state to view before paste
220
- editorView.updateState(state);
221
-
222
- // paste the column
223
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
224
-
225
- expect(editorView.state.doc).toEqualDocument(
226
- doc(
227
- table({ localId: TABLE_LOCAL_ID })(
228
- tr(th()(p('1')), th()(p('2')), th()(p('2'))),
229
- tr(td()(p('4')), td()(p('5')), td()(p('5'))),
230
- tr(td()(p('7')), td()(p('8')), td()(p('8'))),
231
- ),
232
- ),
233
- );
234
- });
235
-
236
- it('copies a table with all attributes', () => {
237
- const {
238
- editorView,
239
- refs: { nextPos },
240
- } = editor(
241
- doc(
242
- table({
243
- layout: 'wide',
244
- localId: TABLE_LOCAL_ID,
245
- })(
246
- tr(th()(p('{<>}1')), th()(p('2')), th()(p('3'))),
247
- tr(
248
- td({ background: '#fffcf2' })(p('4')),
249
- td({ background: '#fffcf7' })(p('5')),
250
- td()(p('6')),
251
- ),
252
- tr(td()(p('7')), td()(p('8')), td()(p('9'))),
253
- ),
254
- p('{nextPos}'),
255
- ),
256
- );
257
-
258
- let { state } = editorView;
259
- state = state.apply(selectTable(state.tr));
260
-
261
- const { dom, text } = __serializeForClipboard(
262
- editorView,
263
- state.selection.content(),
264
- );
265
-
266
- // move cursor to the 3rd column
267
- const $pos = state.doc.resolve(nextPos);
268
- state = state.apply(
269
- state.tr.setSelection(new TextSelection($pos, $pos)),
270
- );
271
-
272
- editorView.updateState(state);
273
-
274
- // paste the column
275
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
276
-
277
- expect(editorView.state.doc).toEqualDocument(
278
- doc(
279
- table({ layout: 'wide', localId: TABLE_LOCAL_ID })(
280
- tr(th()(p('1')), th()(p('2')), th()(p('3'))),
281
- tr(
282
- td({ background: '#fffcf2' })(p('4')),
283
- td({ background: '#fffcf7' })(p('5')),
284
- td()(p('6')),
285
- ),
286
- tr(td()(p('7')), td()(p('8')), td()(p('9'))),
287
- ),
288
- table({ layout: 'wide', localId: TABLE_LOCAL_ID })(
289
- tr(th()(p('1')), th()(p('2')), th()(p('3'))),
290
- tr(
291
- td({ background: '#fffcf2' })(p('4')),
292
- td({ background: '#fffcf7' })(p('5')),
293
- td()(p('6')),
294
- ),
295
- tr(td()(p('7')), td()(p('8')), td()(p('9'))),
296
- ),
297
- ),
298
- );
299
- });
300
- });
301
- });
302
-
303
- describe('copying-pasting a partial table', () => {
304
- describe('when copying from text outside table to text inside a table cell and then pasting', () => {
305
- let editorView: EditorView;
306
- beforeEach(() => {
307
- const editorInstance = editor(
308
- doc(
309
- p('{<}hello'),
310
- table()(
311
- tr(th()(p()), th()(p()), th()(p())),
312
- tr(td()(p()), td()(p('world{>}')), td()(p())),
313
- tr(td()(p()), td()(p()), td()(p())),
314
- ),
315
- p('{pasteStartPos}'),
316
- ),
317
- );
318
-
319
- copySelectionAndPasteAtPos({
320
- editorView: editorInstance.editorView,
321
- pasteStartPos: editorInstance.refs.pasteStartPos,
322
- pasteEndPos: editorInstance.refs.pasteStartPos,
323
- });
324
-
325
- editorView = editorInstance.editorView;
326
- });
327
-
328
- it('should copy-paste a complete table', () => {
329
- expect(editorView.state).toEqualDocumentAndSelection(
330
- doc(
331
- p('hello'),
332
- table({ localId: TABLE_LOCAL_ID })(
333
- tr(th()(p()), th()(p()), th()(p())),
334
- tr(td()(p()), td()(p('world')), td()(p())),
335
- tr(td()(p()), td()(p()), td()(p())),
336
- ),
337
- p('hello'),
338
- table({ localId: TABLE_LOCAL_ID })(
339
- tr(th()(p()), th()(p()), th()(p())),
340
- tr(td()(p()), td()(p('world{<>}')), td()(p())),
341
- ),
342
- ),
343
- );
344
- });
345
- });
346
-
347
- describe('when copying from text inside a table cell to text outside table and then pasting', () => {
348
- let editorView: EditorView;
349
- beforeEach(() => {
350
- const editorInstance = editor(
351
- doc(
352
- table()(
353
- tr(th()(p()), th()(p()), th()(p())),
354
- tr(td()(p()), td()(p('{<}hello')), td()(p('more'))),
355
- tr(td()(p()), td()(p()), td()(p())),
356
- ),
357
- p('world{>}'),
358
- p('{pasteStartPos}'),
359
- ),
360
- );
361
-
362
- copySelectionAndPasteAtPos({
363
- editorView: editorInstance.editorView,
364
- pasteStartPos: editorInstance.refs.pasteStartPos,
365
- pasteEndPos: editorInstance.refs.pasteStartPos,
366
- });
367
-
368
- editorView = editorInstance.editorView;
369
- });
370
-
371
- it('should copy-paste a complete table and the text outside', () => {
372
- expect(editorView.state).toEqualDocumentAndSelection(
373
- doc(
374
- table({ localId: TABLE_LOCAL_ID })(
375
- tr(th()(p()), th()(p()), th()(p())),
376
- tr(td()(p()), td()(p('hello')), td()(p('more'))),
377
- tr(td()(p()), td()(p()), td()(p())),
378
- ),
379
- p('world'),
380
- table({ localId: TABLE_LOCAL_ID })(
381
- tr(td()(p()), td()(p('hello')), td()(p('more'))),
382
- tr(td()(p()), td()(p()), td()(p())),
383
- ),
384
- p('world{<>}'),
385
- ),
386
- );
387
- });
388
- });
389
- });
390
-
391
- describe('copy-pasting content inside expand', () => {
392
- describe('transformSliceToRemoveOpenExpand()', () => {
393
- it('should unwrap expand if it is the only top level node and not a part of copied content', () => {
394
- const slice = new Slice(fragment(expand()(p('text'))), 2, 2);
395
- const expectedSlice = new Slice(fragment(p('text')), 1, 1);
396
-
397
- expect(transformSliceToRemoveOpenExpand(slice, defaultSchema)).toEqual(
398
- expectedSlice,
399
- );
400
- });
401
-
402
- it('should ignore the process if top expand is a part of the copied content', () => {
403
- const slice = new Slice(fragment(expand()(p('text'))), 1, 1);
404
-
405
- expect(transformSliceToRemoveOpenExpand(slice, defaultSchema)).toEqual(
406
- slice,
407
- );
408
- });
409
-
410
- it('should ignore the process if have multiple top level nodes', () => {
411
- const slice = new Slice(fragment(p('text'), expand()(p('text'))), 2, 2);
412
-
413
- expect(transformSliceToRemoveOpenExpand(slice, defaultSchema)).toEqual(
414
- slice,
415
- );
416
- });
417
-
418
- it('should ignore the process if top level node is not an expand', () => {
419
- const slice = new Slice(fragment(panel()(p('text'))), 2, 2);
420
-
421
- expect(transformSliceToRemoveOpenExpand(slice, defaultSchema)).toEqual(
422
- slice,
423
- );
424
- });
425
- });
426
- });
427
-
428
- describe('copy-pasting table content', () => {
429
- describe('unwrapContentFromTable()', () => {
430
- it('should ignore any node that is not a table', () => {
431
- const tableNode = p('text')(defaultSchema);
432
- expect(unwrapContentFromTable(tableNode)).toBe(tableNode);
433
- });
434
-
435
- it('should unwrap any content inside a table', () => {
436
- const tableNode = table()(
437
- tr(th()(p('1')), th()(p('2'))),
438
- tr(td()(code_block()('3')), td()(p('4'))),
439
- )(defaultSchema);
440
-
441
- const expected = array(p('1'), p('2'), code_block()('3'), p('4'));
442
- expect(unwrapContentFromTable(tableNode)).toEqual(expected);
443
- });
444
- });
445
-
446
- describe('removeTableFromFirstChild()', () => {
447
- it('should unwrap the table when it is the first child of a node', () => {
448
- const tableNode = table()(
449
- tr(th()(p('1')), th()(p('2'))),
450
- tr(td()(code_block()('3')), td()(p('4'))),
451
- )(defaultSchema);
452
-
453
- const expected = array(p('1'), p('2'), code_block()('3'), p('4'));
454
- expect(removeTableFromFirstChild(tableNode, 0)).toEqual(expected);
455
- });
456
-
457
- it('should do nothing when the table is not the first child of a node', () => {
458
- const tableNode = table()(
459
- tr(th()(p('1')), th()(p('2'))),
460
- tr(td()(code_block()('3')), td()(p('4'))),
461
- )(defaultSchema);
462
- expect(removeTableFromFirstChild(tableNode, 1)).toEqual(tableNode);
463
- });
464
- });
465
-
466
- describe('removeTableFromLastChild()', () => {
467
- it('should unwrap the table when it is the last child of a node', () => {
468
- const tableNode = table()(
469
- tr(th()(p('1')), th()(p('2'))),
470
- tr(td()(code_block()('3')), td()(p('4'))),
471
- );
472
- const sliceFragment = fragment(p('Start'), tableNode);
473
-
474
- const expected = array(p('1'), p('2'), code_block()('3'), p('4'));
475
- expect(
476
- removeTableFromLastChild(
477
- sliceFragment.lastChild!,
478
- sliceFragment.childCount - 1,
479
- sliceFragment,
480
- ),
481
- ).toEqual(expected);
482
- });
483
-
484
- it('should do nothing when the table is not the last child of a node', () => {
485
- const tableNode = table()(
486
- tr(th()(p('1')), th()(p('2'))),
487
- tr(td()(code_block()('3')), td()(p('4'))),
488
- );
489
- const sliceFragment = fragment(p('Start'), tableNode, p('End'));
490
-
491
- expect(
492
- removeTableFromLastChild(sliceFragment.child(1), 1, sliceFragment),
493
- ).toEqualDocument(tableNode);
494
- });
495
- });
496
-
497
- describe('transformSliceToFixHardBreakProblemOnCopyFromCell()', () => {
498
- describe('when a slice contains a hardBreak after a table with only one cell', () => {
499
- it('should return only the content', () => {
500
- const slice = new Slice(
501
- fragment(table()(tr(th()(p('1')))), p(br())),
502
- 0,
503
- 1,
504
- );
505
-
506
- expect(
507
- transformSliceToFixHardBreakProblemOnCopyFromCell(
508
- slice,
509
- defaultSchema,
510
- ),
511
- ).toEqual(new Slice(fragment(p('1')), 0, 1));
512
- });
513
- });
514
- });
515
-
516
- describe('transformSliceToRemoveOpenTable()', () => {
517
- describe('when a slice contains only one table', () => {
518
- it('should ignore the table if the node is closed', () => {
519
- const slice = new Slice(
520
- fragment(
521
- table()(
522
- tr(th()(p('1')), th()(p('2'))),
523
- tr(td()(code_block()('3')), td()(p('4'))),
524
- ),
525
- ),
526
- 0,
527
- 0,
528
- );
529
- expect(transformSliceToRemoveOpenTable(slice, defaultSchema)).toBe(
530
- slice,
531
- );
532
- });
533
-
534
- it('should unwrap the table if the node is open', () => {
535
- const slice = new Slice(
536
- fragment(
537
- table()(
538
- tr(th()(p('1')), th()(p('2'))),
539
- tr(td()(code_block()('3')), td()(p('4'))),
540
- ),
541
- ),
542
- 4,
543
- 4,
544
- );
545
- expect(transformSliceToRemoveOpenTable(slice, defaultSchema)).toEqual(
546
- new Slice(
547
- fragment(p('1'), p('2'), code_block()('3'), p('4')),
548
- 1,
549
- 1,
550
- ),
551
- );
552
- });
553
- });
554
-
555
- describe('when a slice begins with a table', () => {
556
- it('should ignore the table if the node is closed', () => {
557
- const slice = new Slice(
558
- fragment(
559
- table()(
560
- tr(th()(p('1')), th()(p('2'))),
561
- tr(td()(code_block()('3')), td()(p('4'))),
562
- ),
563
- p('End'),
564
- ),
565
- 0,
566
- 0,
567
- );
568
- expect(transformSliceToRemoveOpenTable(slice, defaultSchema)).toBe(
569
- slice,
570
- );
571
- });
572
-
573
- it('should repointer the openStart depth of the table if the node is open', () => {
574
- const slice = new Slice(
575
- fragment(
576
- table()(
577
- tr(th()(p('1')), th()(p('2'))),
578
- tr(td()(code_block()('3')), td()(p('4'))),
579
- ),
580
- p('End'),
581
- ),
582
- 4,
583
- 0,
584
- );
585
- expect(transformSliceToRemoveOpenTable(slice, defaultSchema)).toEqual(
586
- new Slice(
587
- fragment(
588
- table()(
589
- tr(th()(p('1')), th()(p('2'))),
590
- tr(td()(code_block()('3')), td()(p('4'))),
591
- ),
592
- p('End'),
593
- ),
594
- 1,
595
- 0,
596
- ),
597
- );
598
- });
599
- });
600
-
601
- describe('when a slice ends with a table', () => {
602
- it('should ignore the table if the node is closed', () => {
603
- const slice = new Slice(
604
- fragment(
605
- p('Start'),
606
- table()(
607
- tr(th()(p('1')), th()(p('2'))),
608
- tr(td()(code_block()('3')), td()(p('4'))),
609
- ),
610
- ),
611
- 0,
612
- 0,
613
- );
614
- expect(transformSliceToRemoveOpenTable(slice, defaultSchema)).toBe(
615
- slice,
616
- );
617
- });
618
-
619
- it('should ignore the table if the node is open', () => {
620
- const slice = new Slice(
621
- fragment(
622
- p('Start'),
623
- table()(
624
- tr(th()(p('1')), th()(p('2'))),
625
- tr(td()(code_block()('3')), td()(p('4'))),
626
- ),
627
- ),
628
- 0,
629
- 4,
630
- );
631
- expect(transformSliceToRemoveOpenTable(slice, defaultSchema)).toEqual(
632
- slice,
633
- );
634
- });
635
- });
636
-
637
- describe('when a slice starts in one table and ends in another', () => {
638
- it('should ignore the table if the slice is closed', () => {
639
- const tableNode = table()(
640
- tr(th()(p('1')), th()(p('2'))),
641
- tr(td()(code_block()('3')), td()(p('4'))),
642
- );
643
- const slice = new Slice(
644
- fragment(tableNode, p('Middle'), tableNode),
645
- 0,
646
- 0,
647
- );
648
- expect(transformSliceToRemoveOpenTable(slice, defaultSchema)).toBe(
649
- slice,
650
- );
651
- });
652
- });
653
-
654
- describe('when a slice has nested tables by coping multiple paragraphs in a table cell', () => {
655
- it('should unwrap with correct openStart and openEnd', () => {
656
- const slice = new Slice(
657
- // Creating invalid fragment which is same as clipboard content
658
- fragment(
659
- table()((schema: Schema) =>
660
- schema.nodes.tableRow.create(
661
- null,
662
- fragment(table()(tr(th()(p('1'), p('2'))))),
663
- ),
664
- ),
665
- ),
666
- 6,
667
- 6,
668
- );
669
- const expected = new Slice(fragment(p('1'), p('2')), 1, 1);
670
- expect(
671
- transformSliceToRemoveOpenTable(slice, defaultSchema),
672
- ).toStrictEqual(expected);
673
- });
674
- });
675
- });
676
- });
677
- });