@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,292 +0,0 @@
1
- import type { DocBuilder } from '@atlaskit/editor-common/types';
2
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
3
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
5
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
6
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
7
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
8
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
9
- import { undo } from '@atlaskit/editor-prosemirror/history';
10
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
11
- // eslint-disable-next-line import/no-extraneous-dependencies
12
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
13
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
14
- import {
15
- createProsemirrorEditorFactory,
16
- Preset,
17
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
18
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
19
- import {
20
- doc,
21
- p,
22
- table,
23
- td,
24
- tdEmpty,
25
- tr,
26
- } from '@atlaskit/editor-test-helpers/doc-builder';
27
-
28
- import tablePlugin from '../../../plugin';
29
- import { pluginKey as tablePluginKey } from '../../../pm-plugins/plugin-key';
30
-
31
- const createDoc = (attrs: any) =>
32
- doc(
33
- table(attrs)(
34
- tr(tdEmpty, tdEmpty, tdEmpty),
35
- tr(tdEmpty, tdEmpty, tdEmpty),
36
- tr(tdEmpty, tdEmpty, tdEmpty),
37
- ),
38
- );
39
-
40
- const expectedDocuments = {
41
- fullWidthAppearanceLayoutDefault: createDoc({
42
- localId: 'localId',
43
- isNumberColumnEnabled: false,
44
- layout: 'default',
45
- width: 1800,
46
- }),
47
- fixedWidthAppearanceLayoutDefault: createDoc({
48
- localId: 'localId',
49
- isNumberColumnEnabled: false,
50
- layout: 'default',
51
- width: 760,
52
- }),
53
- fixedWidthAppearanceLayoutWide: createDoc({
54
- localId: 'localId',
55
- isNumberColumnEnabled: false,
56
- layout: 'wide',
57
- width: 960,
58
- }),
59
- fixedWidthAppearanceLayoutFullWidth: createDoc({
60
- localId: 'localId',
61
- isNumberColumnEnabled: false,
62
- layout: 'full-width',
63
- width: 1800,
64
- }),
65
- };
66
-
67
- describe('table width', () => {
68
- const createEditor = createProsemirrorEditorFactory();
69
-
70
- beforeAll(() => {
71
- // @ts-ignore
72
- global['fetch'] = jest.fn();
73
- });
74
-
75
- const editor = (doc: DocBuilder, isFullWidthEnabled = false) => {
76
- return createEditor({
77
- doc,
78
- attachTo: document.body,
79
- preset: new Preset<LightEditorPlugin>()
80
- .add([featureFlagsPlugin, {}])
81
- .add([analyticsPlugin, {}])
82
- .add(contentInsertionPlugin)
83
- .add(widthPlugin)
84
- .add(guidelinePlugin)
85
- .add(selectionPlugin)
86
- .add([
87
- tablePlugin,
88
- {
89
- fullWidthEnabled: isFullWidthEnabled,
90
- tableResizingEnabled: true, // so table-width plugin is enabled
91
- tableOptions: {
92
- advanced: true,
93
- },
94
- },
95
- ]),
96
- pluginKey: tablePluginKey,
97
- });
98
- };
99
-
100
- describe('move selection from outside table to inside table should fire analytics', () => {
101
- const TABLE_LOCAL_ID = 'test-table-1';
102
- it('should fire v3 analytics', () => {
103
- // create editor with a table and a paragraph below
104
- // mouse cursor is at the end of the parapgraph
105
- const {
106
- dispatchAnalyticsEvent,
107
- editorView,
108
- refs: { inTablePos },
109
- } = editor(
110
- doc(
111
- table({ localId: TABLE_LOCAL_ID })(
112
- tr(td({})(p('{inTablePos}in cell')), tdEmpty, tdEmpty),
113
- tr(tdEmpty, tdEmpty, tdEmpty),
114
- ),
115
- p('hello cursor is here initially{<>}'),
116
- ),
117
- );
118
-
119
- // move cursor to where ths inTablePos is
120
- const $inTablePos = editorView.state.doc.resolve(inTablePos);
121
- editorView.dispatch(
122
- editorView.state.tr.setSelection(
123
- new TextSelection($inTablePos, $inTablePos),
124
- ),
125
- );
126
-
127
- // analytics event should be fired
128
- expect(dispatchAnalyticsEvent).toHaveBeenCalledWith(
129
- expect.objectContaining({
130
- action: 'selected',
131
- actionSubject: 'document',
132
- actionSubjectId: 'table',
133
- attributes: expect.objectContaining({
134
- localId: TABLE_LOCAL_ID,
135
- }),
136
- eventType: 'track',
137
- }),
138
- );
139
- });
140
- });
141
-
142
- describe('Load an existing table with width attr equal null', () => {
143
- describe('full-width editor appearance', () => {
144
- it('should translate table width attr to 1800', () => {
145
- const { editorView } = editor(
146
- doc(
147
- // @ts-ignore
148
- table({ localId: 'localId', layout: 'default', width: null })(
149
- tr(tdEmpty, tdEmpty, tdEmpty),
150
- tr(tdEmpty, tdEmpty, tdEmpty),
151
- tr(tdEmpty, tdEmpty, tdEmpty),
152
- ),
153
- ),
154
- true,
155
- );
156
-
157
- // create `replaceDocument` step
158
- editorView.dispatch(
159
- editorView.state.tr.setMeta('replaceDocument', true),
160
- );
161
-
162
- expect(editorView.state.doc).toEqualDocument(
163
- expectedDocuments.fullWidthAppearanceLayoutDefault,
164
- );
165
- });
166
-
167
- it('should not remove width when undo is sent', () => {
168
- const { editorView } = editor(
169
- doc(
170
- // @ts-ignore
171
- table({ localId: 'localId', layout: 'default', width: null })(
172
- tr(tdEmpty, tdEmpty, tdEmpty),
173
- tr(tdEmpty, tdEmpty, tdEmpty),
174
- tr(tdEmpty, tdEmpty, tdEmpty),
175
- ),
176
- ),
177
- true,
178
- );
179
-
180
- // create `replaceDocument` step
181
- editorView.dispatch(
182
- editorView.state.tr.setMeta('replaceDocument', true),
183
- );
184
-
185
- expect(editorView.state.doc).toEqualDocument(
186
- expectedDocuments.fullWidthAppearanceLayoutDefault,
187
- );
188
-
189
- undo(editorView.state, editorView.dispatch);
190
-
191
- expect(editorView.state.doc).toEqualDocument(
192
- expectedDocuments.fullWidthAppearanceLayoutDefault,
193
- );
194
- });
195
- });
196
- describe('fixed-width editor appearance', () => {
197
- it('should translate table width attr to 760 for default layout', () => {
198
- const { editorView } = editor(
199
- doc(
200
- // @ts-ignore
201
- table({ localId: 'localId', layout: 'default', width: null })(
202
- tr(tdEmpty, tdEmpty, tdEmpty),
203
- tr(tdEmpty, tdEmpty, tdEmpty),
204
- tr(tdEmpty, tdEmpty, tdEmpty),
205
- ),
206
- ),
207
- );
208
-
209
- // create `replaceDocument` step
210
- editorView.dispatch(
211
- editorView.state.tr.setMeta('replaceDocument', true),
212
- );
213
-
214
- expect(editorView.state.doc).toEqualDocument(
215
- expectedDocuments.fixedWidthAppearanceLayoutDefault,
216
- );
217
- });
218
-
219
- it('should not remove width when undo is sent', () => {
220
- const { editorView } = editor(
221
- doc(
222
- // @ts-ignore
223
- table({ localId: 'localId', layout: 'default', width: null })(
224
- tr(tdEmpty, tdEmpty, tdEmpty),
225
- tr(tdEmpty, tdEmpty, tdEmpty),
226
- tr(tdEmpty, tdEmpty, tdEmpty),
227
- ),
228
- ),
229
- );
230
-
231
- // create `replaceDocument` step
232
- editorView.dispatch(
233
- editorView.state.tr.setMeta('replaceDocument', true),
234
- );
235
-
236
- expect(editorView.state.doc).toEqualDocument(
237
- expectedDocuments.fixedWidthAppearanceLayoutDefault,
238
- );
239
-
240
- undo(editorView.state, editorView.dispatch);
241
-
242
- expect(editorView.state.doc).toEqualDocument(
243
- expectedDocuments.fixedWidthAppearanceLayoutDefault,
244
- );
245
- });
246
-
247
- it('should translate table width attr to 960 for wide layout', () => {
248
- const { editorView } = editor(
249
- doc(
250
- // @ts-ignore
251
- table({ localId: 'localId', layout: 'wide', width: null })(
252
- tr(tdEmpty, tdEmpty, tdEmpty),
253
- tr(tdEmpty, tdEmpty, tdEmpty),
254
- tr(tdEmpty, tdEmpty, tdEmpty),
255
- ),
256
- ),
257
- );
258
-
259
- // create `replaceDocument` step
260
- editorView.dispatch(
261
- editorView.state.tr.setMeta('replaceDocument', true),
262
- );
263
-
264
- expect(editorView.state.doc).toEqualDocument(
265
- expectedDocuments.fixedWidthAppearanceLayoutWide,
266
- );
267
- });
268
-
269
- it('should translate table width attr to 1800 for full-width layout', () => {
270
- const { editorView } = editor(
271
- doc(
272
- // @ts-ignore
273
- table({ localId: 'localId', layout: 'full-width', width: null })(
274
- tr(tdEmpty, tdEmpty, tdEmpty),
275
- tr(tdEmpty, tdEmpty, tdEmpty),
276
- tr(tdEmpty, tdEmpty, tdEmpty),
277
- ),
278
- ),
279
- );
280
-
281
- // create `replaceDocument` step
282
- editorView.dispatch(
283
- editorView.state.tr.setMeta('replaceDocument', true),
284
- );
285
-
286
- expect(editorView.state.doc).toEqualDocument(
287
- expectedDocuments.fixedWidthAppearanceLayoutFullWidth,
288
- );
289
- });
290
- });
291
- });
292
- });
@@ -1,399 +0,0 @@
1
- import { uuid } from '@atlaskit/adf-schema';
2
- import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
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 { 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 { PluginKey } from '@atlaskit/editor-prosemirror/state';
12
- // eslint-disable-next-line import/no-extraneous-dependencies
13
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
14
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
15
- import {
16
- createProsemirrorEditorFactory,
17
- Preset,
18
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
19
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
20
- import {
21
- doc,
22
- p,
23
- table,
24
- td,
25
- th,
26
- tr,
27
- } from '@atlaskit/editor-test-helpers/doc-builder';
28
-
29
- import { sortByColumn } from '../../commands';
30
- import tablePlugin from '../../plugin';
31
- import { pluginKey as tablePluginKey } from '../../pm-plugins/plugin-key';
32
- import type { PermittedLayoutsDescriptor, TablePluginState } from '../../types';
33
-
34
- const TABLE_LOCAL_ID = 'test-table-local-id';
35
-
36
- describe('table plugin', () => {
37
- beforeEach(() => {
38
- uuid.setStatic(TABLE_LOCAL_ID);
39
- });
40
-
41
- afterEach(() => {
42
- uuid.setStatic(false);
43
- });
44
-
45
- const createEditor = createProsemirrorEditorFactory();
46
- const tableOptions = {
47
- allowNumberColumn: true,
48
- allowHeaderRow: true,
49
- allowHeaderColumn: true,
50
- allowBackgroundColor: true,
51
- permittedLayouts: 'all' as PermittedLayoutsDescriptor,
52
- allowColumnSorting: true,
53
- };
54
- const preset = new Preset<LightEditorPlugin>()
55
- .add([featureFlagsPlugin, {}])
56
- .add([analyticsPlugin, {}])
57
- .add(contentInsertionPlugin)
58
- .add(widthPlugin)
59
- .add(guidelinePlugin)
60
- .add(selectionPlugin)
61
- .add([tablePlugin, { tableOptions }]);
62
-
63
- const editor = (doc: DocBuilder) => {
64
- return createEditor<TablePluginState, PluginKey, typeof preset>({
65
- doc,
66
- preset,
67
- pluginKey: tablePluginKey,
68
- });
69
- };
70
-
71
- describe('TableView', () => {
72
- describe('Sort Columns in given order', () => {
73
- it('sorts the given column in ascending order', () => {
74
- const { editorView } = editor(
75
- doc(
76
- table({ isNumberColumnEnabled: false, layout: 'default' })(
77
- tr(
78
- th({})(p('1')),
79
- th({})(p('2')),
80
- th({})(p('3')),
81
- th({})(p('4')),
82
- th({})(p('5')),
83
- ),
84
- tr(
85
- td({})(p('c')),
86
- td({})(p('c')),
87
- td({})(p()),
88
- td({})(p('c')),
89
- td({})(p()),
90
- ),
91
- tr(
92
- td({})(p('b')),
93
- td({})(p()),
94
- td({})(p('d')),
95
- td({})(p()),
96
- td({})(p('c')),
97
- ),
98
- tr(
99
- td({})(p()),
100
- td({})(p('z')),
101
- td({})(p()),
102
- td({})(p()),
103
- td({})(p('f')),
104
- ),
105
- tr(
106
- td({})(p('2')),
107
- td({})(p()),
108
- td({})(p()),
109
- td({})(p()),
110
- td({})(p()),
111
- ),
112
- tr(
113
- td({})(p('1')),
114
- td({})(p()),
115
- td({})(p('c')),
116
- td({})(p()),
117
- td({})(p()),
118
- ),
119
- tr(
120
- td({})(p('a')),
121
- td({})(p()),
122
- td({})(p()),
123
- td({})(p()),
124
- td({})(p()),
125
- ),
126
- ),
127
- ),
128
- );
129
-
130
- const sortByColumnCommand = sortByColumn(0, SortOrder.ASC);
131
-
132
- sortByColumnCommand(editorView.state, editorView.dispatch);
133
-
134
- expect(editorView.state.doc).toEqualDocument(
135
- doc(
136
- table({
137
- isNumberColumnEnabled: false,
138
- layout: 'default',
139
- localId: TABLE_LOCAL_ID,
140
- })(
141
- tr(
142
- th({})(p('1')),
143
- th({})(p('2')),
144
- th({})(p('3')),
145
- th({})(p('4')),
146
- th({})(p('5')),
147
- ),
148
- tr(
149
- td({})(p('1')),
150
- td({})(p()),
151
- td({})(p('c')),
152
- td({})(p()),
153
- td({})(p()),
154
- ),
155
- tr(
156
- td({})(p('2')),
157
- td({})(p()),
158
- td({})(p()),
159
- td({})(p()),
160
- td({})(p()),
161
- ),
162
- tr(
163
- td({})(p('a')),
164
- td({})(p()),
165
- td({})(p()),
166
- td({})(p()),
167
- td({})(p()),
168
- ),
169
- tr(
170
- td({})(p('b')),
171
- td({})(p()),
172
- td({})(p('d')),
173
- td({})(p()),
174
- td({})(p('c')),
175
- ),
176
- tr(
177
- td({})(p('c')),
178
- td({})(p('c')),
179
- td({})(p()),
180
- td({})(p('c')),
181
- td({})(p()),
182
- ),
183
- tr(
184
- td({})(p()),
185
- td({})(p('z')),
186
- td({})(p()),
187
- td({})(p()),
188
- td({})(p('f')),
189
- ),
190
- ),
191
- ),
192
- );
193
- });
194
- it('sorts the given column in descending order', () => {
195
- const { editorView } = editor(
196
- doc(
197
- table({ isNumberColumnEnabled: false, layout: 'default' })(
198
- tr(
199
- th({})(p('1')),
200
- th({})(p('2')),
201
- th({})(p('3')),
202
- th({})(p('4')),
203
- th({})(p('5')),
204
- ),
205
- tr(
206
- td({})(p('c')),
207
- td({})(p('c')),
208
- td({})(p()),
209
- td({})(p('c')),
210
- td({})(p()),
211
- ),
212
- tr(
213
- td({})(p('b')),
214
- td({})(p()),
215
- td({})(p('d')),
216
- td({})(p()),
217
- td({})(p('c')),
218
- ),
219
- tr(
220
- td({})(p()),
221
- td({})(p('z')),
222
- td({})(p()),
223
- td({})(p()),
224
- td({})(p('f')),
225
- ),
226
- tr(
227
- td({})(p('2')),
228
- td({})(p()),
229
- td({})(p()),
230
- td({})(p()),
231
- td({})(p()),
232
- ),
233
- tr(
234
- td({})(p('1')),
235
- td({})(p()),
236
- td({})(p('c')),
237
- td({})(p()),
238
- td({})(p()),
239
- ),
240
- tr(
241
- td({})(p('a')),
242
- td({})(p()),
243
- td({})(p()),
244
- td({})(p()),
245
- td({})(p()),
246
- ),
247
- ),
248
- ),
249
- );
250
-
251
- const sortByColumnCommand = sortByColumn(0, SortOrder.DESC);
252
-
253
- sortByColumnCommand(editorView.state, editorView.dispatch);
254
-
255
- expect(editorView.state.doc).toEqualDocument(
256
- doc(
257
- table({
258
- isNumberColumnEnabled: false,
259
- layout: 'default',
260
- localId: TABLE_LOCAL_ID,
261
- })(
262
- tr(
263
- th({})(p('1')),
264
- th({})(p('2')),
265
- th({})(p('3')),
266
- th({})(p('4')),
267
- th({})(p('5')),
268
- ),
269
- tr(
270
- td({})(p('c')),
271
- td({})(p('c')),
272
- td({})(p()),
273
- td({})(p('c')),
274
- td({})(p()),
275
- ),
276
- tr(
277
- td({})(p('b')),
278
- td({})(p()),
279
- td({})(p('d')),
280
- td({})(p()),
281
- td({})(p('c')),
282
- ),
283
- tr(
284
- td({})(p('a')),
285
- td({})(p()),
286
- td({})(p()),
287
- td({})(p()),
288
- td({})(p()),
289
- ),
290
- tr(
291
- td({})(p('2')),
292
- td({})(p()),
293
- td({})(p()),
294
- td({})(p()),
295
- td({})(p()),
296
- ),
297
- tr(
298
- td({})(p('1')),
299
- td({})(p()),
300
- td({})(p('c')),
301
- td({})(p()),
302
- td({})(p()),
303
- ),
304
- tr(
305
- td({})(p()),
306
- td({})(p('z')),
307
- td({})(p()),
308
- td({})(p()),
309
- td({})(p('f')),
310
- ),
311
- ),
312
- ),
313
- );
314
- });
315
-
316
- describe('case sensitivity', () => {
317
- describe('ascending order', () => {
318
- it('sorts the given column', () => {
319
- const { editorView } = editor(
320
- doc(
321
- table({ isNumberColumnEnabled: false, layout: 'default' })(
322
- tr(th({})(p()), th({})(p())),
323
- tr(td({})(p('A')), td({})(p('1'))),
324
- tr(td({})(p('a')), td({})(p('2'))),
325
- tr(td({})(p('b')), td({})(p('3'))),
326
- tr(td({})(p('B')), td({})(p('4'))),
327
- tr(td({})(p('bb')), td({})(p('5'))),
328
- tr(td({})(p('Bb')), td({})(p('6'))),
329
- ),
330
- ),
331
- );
332
-
333
- const sortByColumnCommand = sortByColumn(0, SortOrder.ASC);
334
-
335
- sortByColumnCommand(editorView.state, editorView.dispatch);
336
-
337
- expect(editorView.state.doc).toEqualDocument(
338
- doc(
339
- table({
340
- isNumberColumnEnabled: false,
341
- layout: 'default',
342
- localId: TABLE_LOCAL_ID,
343
- })(
344
- tr(th({})(p()), th({})(p())),
345
- tr(td({})(p('A')), td({})(p('1'))),
346
- tr(td({})(p('a')), td({})(p('2'))),
347
- tr(td({})(p('B')), td({})(p('4'))),
348
- tr(td({})(p('b')), td({})(p('3'))),
349
- tr(td({})(p('Bb')), td({})(p('6'))),
350
- tr(td({})(p('bb')), td({})(p('5'))),
351
- ),
352
- ),
353
- );
354
- });
355
- });
356
-
357
- describe('descending order', () => {
358
- it('sorts the given column', () => {
359
- const { editorView } = editor(
360
- doc(
361
- table({ isNumberColumnEnabled: false, layout: 'default' })(
362
- tr(th({})(p()), th({})(p())),
363
- tr(td({})(p('A')), td({})(p('1'))),
364
- tr(td({})(p('a')), td({})(p('2'))),
365
- tr(td({})(p('b')), td({})(p('3'))),
366
- tr(td({})(p('B')), td({})(p('4'))),
367
- tr(td({})(p('bb')), td({})(p('5'))),
368
- tr(td({})(p('Bb')), td({})(p('6'))),
369
- ),
370
- ),
371
- );
372
-
373
- const sortByColumnCommand = sortByColumn(0, SortOrder.DESC);
374
-
375
- sortByColumnCommand(editorView.state, editorView.dispatch);
376
-
377
- expect(editorView.state.doc).toEqualDocument(
378
- doc(
379
- table({
380
- isNumberColumnEnabled: false,
381
- layout: 'default',
382
- localId: TABLE_LOCAL_ID,
383
- })(
384
- tr(th({})(p()), th({})(p())),
385
- tr(td({})(p('bb')), td({})(p('5'))),
386
- tr(td({})(p('Bb')), td({})(p('6'))),
387
- tr(td({})(p('b')), td({})(p('3'))),
388
- tr(td({})(p('B')), td({})(p('4'))),
389
- tr(td({})(p('a')), td({})(p('2'))),
390
- tr(td({})(p('A')), td({})(p('1'))),
391
- ),
392
- ),
393
- );
394
- });
395
- });
396
- });
397
- });
398
- });
399
- });