@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,129 +0,0 @@
1
- import type { TableAttributes } from '@atlaskit/adf-schema';
2
- import type { DocBuilder } from '@atlaskit/editor-common/types';
3
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
4
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
6
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
7
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
8
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
9
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
10
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
11
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
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
- tdCursor,
26
- tdEmpty,
27
- tr,
28
- } from '@atlaskit/editor-test-helpers/doc-builder';
29
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
30
- import defaultSchema from '@atlaskit/editor-test-helpers/schema';
31
-
32
- import { hoverRows } from '../../../commands';
33
- import TableView from '../../../nodeviews/table';
34
- import tablePlugin from '../../../plugin';
35
- import { pluginKey } from '../../../pm-plugins/plugin-key';
36
-
37
- describe('table -> nodeviews -> table.tsx', () => {
38
- const createEditor = createProsemirrorEditorFactory();
39
- const createTableNode =
40
- (attrs?: TableAttributes) =>
41
- (...args: any) =>
42
- table(attrs)(...args)(defaultSchema);
43
-
44
- describe('TableView', () => {
45
- const editor = (doc: DocBuilder) =>
46
- createEditor({
47
- doc,
48
- preset: new Preset<LightEditorPlugin>()
49
- .add([featureFlagsPlugin, {}])
50
- .add([analyticsPlugin, {}])
51
- .add(contentInsertionPlugin)
52
- .add(widthPlugin)
53
- .add(guidelinePlugin)
54
- .add(selectionPlugin)
55
- .add([
56
- tablePlugin,
57
- {
58
- tableOptions: {},
59
- },
60
- ]),
61
- pluginKey,
62
- });
63
-
64
- describe('on view update', () => {
65
- let tableNode: PMNode,
66
- tableNodeView: TableView,
67
- renderSpy: jest.SpyInstance,
68
- view: EditorView;
69
- beforeEach(() => {
70
- tableNode = createTableNode({
71
- isNumberColumnEnabled: true,
72
- })(tr(td()(p('{<>}text')), tdEmpty, tdEmpty));
73
- const { editorView, portalProviderAPI, eventDispatcher } = editor(
74
- doc(p('text'), table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
75
- );
76
- view = editorView;
77
- tableNodeView = new TableView({
78
- node: tableNode,
79
- allowColumnResizing: false,
80
- view: editorView,
81
- portalProviderAPI,
82
- eventDispatcher,
83
- getPos: () => 1,
84
- getEditorContainerWidth: () => ({ width: 500 }),
85
- getEditorFeatureFlags: () => ({}),
86
- hasIntlContext: true,
87
- dispatchAnalyticsEvent: jest.fn(),
88
- }).init();
89
-
90
- renderSpy = jest.spyOn(tableNodeView, 'render');
91
- });
92
-
93
- it('does not rerender if attributes or table width did not change', () => {
94
- const newNodeWithUnchangedAttributesOrWidth = createTableNode({
95
- isNumberColumnEnabled: true,
96
- })(tr(td()(p('{<>}text1')), tdEmpty, tdEmpty));
97
- tableNodeView.update(newNodeWithUnchangedAttributesOrWidth, []);
98
- expect(renderSpy).not.toHaveBeenCalled();
99
- });
100
-
101
- it('rerenders when table width changes', () => {
102
- const newNodeWithUnchangedAttributesAndExtraColumn = createTableNode({
103
- isNumberColumnEnabled: true,
104
- })(tr(td()(p('{<>}text1')), tdEmpty, tdEmpty, tdEmpty));
105
- tableNodeView.update(newNodeWithUnchangedAttributesAndExtraColumn, []);
106
- expect(renderSpy).toHaveBeenCalled();
107
- });
108
-
109
- it('rerenders when attributes change', () => {
110
- const newNodeWithChangedAttributes = createTableNode({
111
- isNumberColumnEnabled: false,
112
- })(tr(td()(p('{<>}text1')), tdEmpty));
113
-
114
- tableNodeView.update(newNodeWithChangedAttributes, []);
115
- expect(renderSpy).toHaveBeenCalled();
116
- });
117
-
118
- it('rerenders when hovered rows change but attributes dont change', () => {
119
- const newNodeWithUnchangedAttributes = createTableNode({
120
- isNumberColumnEnabled: true,
121
- })(tr(td()(p('{<>}text1')), tdEmpty));
122
-
123
- hoverRows([1])(view.state, view.dispatch);
124
- tableNodeView.update(newNodeWithUnchangedAttributes, []);
125
- expect(renderSpy).toHaveBeenCalled();
126
- });
127
- });
128
- });
129
- });
@@ -1,327 +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
- // eslint-disable-next-line import/no-extraneous-dependencies
10
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
11
- import { __serializeForClipboard } from '@atlaskit/editor-prosemirror/view';
12
- // eslint-disable-next-line import/no-extraneous-dependencies
13
- import {
14
- createProsemirrorEditorFactory,
15
- Preset,
16
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
17
- // eslint-disable-next-line import/no-extraneous-dependencies
18
- import type { LightEditorPlugin } 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 dispatchPasteEvent from '@atlaskit/editor-test-helpers/dispatch-paste-event';
21
- // eslint-disable-next-line import/no-extraneous-dependencies
22
- import {
23
- doc,
24
- p,
25
- table,
26
- td,
27
- tr,
28
- } from '@atlaskit/editor-test-helpers/doc-builder';
29
- import { ffTest } from '@atlassian/feature-flags-test-utils';
30
-
31
- // eslint-disable-next-line @atlassian/tangerine/import/no-relative-package-imports
32
- import {
33
- insertColumn,
34
- insertRow,
35
- selectColumn,
36
- selectRow,
37
- } from '../../../commands';
38
- import tablePlugin from '../../../plugin';
39
- import { pluginKey } from '../../../pm-plugins/analytics/plugin-key';
40
-
41
- jest.mock('@atlaskit/platform-feature-flags', () => ({
42
- getBooleanFF: jest.fn().mockImplementation(() => false),
43
- }));
44
-
45
- describe('analytics', () => {
46
- const createEditor = createProsemirrorEditorFactory();
47
- const editor = (doc: DocBuilder) => {
48
- return createEditor({
49
- doc,
50
- preset: new Preset<LightEditorPlugin>()
51
- .add([featureFlagsPlugin, {}])
52
- .add([analyticsPlugin, {}])
53
- .add(contentInsertionPlugin)
54
- .add(widthPlugin)
55
- .add(guidelinePlugin)
56
- .add(selectionPlugin)
57
- .add([
58
- tablePlugin,
59
- {
60
- tableOptions: {
61
- allowHeaderRow: true,
62
- allowMergeCells: true,
63
- },
64
- },
65
- ]),
66
- pluginKey,
67
- attachTo: document.body,
68
- });
69
- };
70
-
71
- describe('rowOrColumnMoved', () => {
72
- describe('should update plugin state when row is copied', () => {
73
- ffTest(
74
- 'platform.editor.table.analytics-plugin-moved-event',
75
- () => {
76
- const { editorView } = editor(
77
- doc(
78
- table()(
79
- tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
80
- tr(td({})(p('b1')), td({})(p('b2'))),
81
- ),
82
- ),
83
- );
84
-
85
- __serializeForClipboard(
86
- editorView,
87
- editorView.state.selection.content(),
88
- );
89
-
90
- const { rowOrColumnMoved } =
91
- pluginKey.getState(editorView.state) || {};
92
-
93
- expect(rowOrColumnMoved).toEqual({
94
- type: 'row',
95
- numberOfCells: 2,
96
- currentActions: ['copyOrCut'],
97
- });
98
- },
99
- () => {
100
- const { editorView } = editor(
101
- doc(
102
- table()(
103
- tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
104
- tr(td({})(p('b1')), td({})(p('b2'))),
105
- ),
106
- ),
107
- );
108
-
109
- __serializeForClipboard(
110
- editorView,
111
- editorView.state.selection.content(),
112
- );
113
-
114
- const { rowOrColumnMoved } =
115
- pluginKey.getState(editorView.state) || {};
116
-
117
- expect(rowOrColumnMoved).toEqual(undefined);
118
- },
119
- );
120
- });
121
-
122
- describe('should update plugin state when column is copied', () => {
123
- ffTest(
124
- 'platform.editor.table.analytics-plugin-moved-event',
125
- () => {
126
- const { editorView } = editor(
127
- doc(
128
- table()(
129
- tr(td({})(p('{<cell}a1')), td({})(p('a2'))),
130
- tr(td({})(p('b1{cell>}')), td({})(p('b2'))),
131
- ),
132
- ),
133
- );
134
-
135
- __serializeForClipboard(
136
- editorView,
137
- editorView.state.selection.content(),
138
- );
139
-
140
- const { rowOrColumnMoved } =
141
- pluginKey.getState(editorView.state) || {};
142
-
143
- expect(rowOrColumnMoved).toEqual({
144
- type: 'column',
145
- numberOfCells: 2,
146
- currentActions: ['copyOrCut'],
147
- });
148
- },
149
- () => {
150
- const { editorView } = editor(
151
- doc(
152
- table()(
153
- tr(td({})(p('{<cell}a1')), td({})(p('a2'))),
154
- tr(td({})(p('b1{cell>}')), td({})(p('b2'))),
155
- ),
156
- ),
157
- );
158
-
159
- __serializeForClipboard(
160
- editorView,
161
- editorView.state.selection.content(),
162
- );
163
-
164
- const { rowOrColumnMoved } =
165
- pluginKey.getState(editorView.state) || {};
166
-
167
- expect(rowOrColumnMoved).toEqual(undefined);
168
- },
169
- );
170
- });
171
-
172
- describe('should update plugin state when row is inserted and then copied', () => {
173
- ffTest(
174
- 'platform.editor.table.analytics-plugin-moved-event',
175
- () => {
176
- const { editorView } = editor(
177
- doc(
178
- table()(
179
- tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
180
- tr(td({})(p('b1')), td({})(p('b2'))),
181
- ),
182
- ),
183
- );
184
-
185
- insertRow(0, false)(editorView.state, editorView.dispatch);
186
- selectRow(0)(editorView.state, editorView.dispatch);
187
-
188
- __serializeForClipboard(
189
- editorView,
190
- editorView.state.selection.content(),
191
- );
192
-
193
- const { rowOrColumnMoved } =
194
- pluginKey.getState(editorView.state) || {};
195
-
196
- expect(rowOrColumnMoved).toEqual({
197
- type: 'row',
198
- numberOfCells: 2,
199
- currentActions: ['addRowOrColumn', 'copyOrCut'],
200
- });
201
- },
202
- () => {
203
- const { editorView } = editor(
204
- doc(
205
- table()(
206
- tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
207
- tr(td({})(p('b1')), td({})(p('b2'))),
208
- ),
209
- ),
210
- );
211
-
212
- const { rowOrColumnMoved } =
213
- pluginKey.getState(editorView.state) || {};
214
- expect(rowOrColumnMoved).toEqual(undefined);
215
- },
216
- );
217
- });
218
-
219
- describe('should update plugin state when column is inserted and then copied', () => {
220
- ffTest(
221
- 'platform.editor.table.analytics-plugin-moved-event',
222
- () => {
223
- const { editorView } = editor(
224
- doc(
225
- table()(
226
- tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
227
- tr(td({})(p('b1')), td({})(p('b2'))),
228
- ),
229
- ),
230
- );
231
-
232
- insertColumn(
233
- jest.fn().mockReturnValue({ containerWidth: { width: 760 } }),
234
- )(0)(editorView.state, editorView.dispatch, editorView);
235
- selectColumn(0)(editorView.state, editorView.dispatch);
236
-
237
- __serializeForClipboard(
238
- editorView,
239
- editorView.state.selection.content(),
240
- );
241
-
242
- const { rowOrColumnMoved } =
243
- pluginKey.getState(editorView.state) || {};
244
-
245
- expect(rowOrColumnMoved).toEqual({
246
- type: 'column',
247
- numberOfCells: 2,
248
- currentActions: ['addRowOrColumn', 'copyOrCut'],
249
- });
250
- },
251
- () => {
252
- const { editorView } = editor(
253
- doc(
254
- table()(
255
- tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
256
- tr(td({})(p('b1')), td({})(p('b2'))),
257
- ),
258
- ),
259
- );
260
-
261
- const { rowOrColumnMoved } =
262
- pluginKey.getState(editorView.state) || {};
263
- expect(rowOrColumnMoved).toEqual(undefined);
264
- },
265
- );
266
- });
267
-
268
- describe('should remove plugin state when row is inserted and then copied and pasted', () => {
269
- ffTest(
270
- 'platform.editor.table.analytics-plugin-moved-event',
271
- () => {
272
- const { editorView } = editor(
273
- doc(
274
- table()(
275
- tr(td({})(p('a1')), td({})(p('a2'))),
276
- tr(td({})(p('b1')), td({})(p('b2'))),
277
- ),
278
- ),
279
- );
280
-
281
- insertRow(0, false)(editorView.state, editorView.dispatch);
282
- selectRow(0)(editorView.state, editorView.dispatch);
283
-
284
- const { dom, text } = __serializeForClipboard(
285
- editorView,
286
- editorView.state.selection.content(),
287
- );
288
-
289
- // place cursor in first cell
290
- editorView.dispatch(
291
- editorView.state.tr.setSelection(
292
- new TextSelection(
293
- editorView.state.doc.resolve(4),
294
- editorView.state.doc.resolve(4),
295
- ),
296
- ),
297
- );
298
-
299
- dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
300
-
301
- const { rowOrColumnMoved } =
302
- pluginKey.getState(editorView.state) || {};
303
-
304
- expect(rowOrColumnMoved).toEqual({
305
- type: undefined,
306
- numberOfCells: undefined,
307
- currentActions: [],
308
- });
309
- },
310
- () => {
311
- const { editorView } = editor(
312
- doc(
313
- table()(
314
- tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
315
- tr(td({})(p('b1')), td({})(p('b2'))),
316
- ),
317
- ),
318
- );
319
-
320
- const { rowOrColumnMoved } =
321
- pluginKey.getState(editorView.state) || {};
322
- expect(rowOrColumnMoved).toEqual(undefined);
323
- },
324
- );
325
- });
326
- });
327
- });
@@ -1,94 +0,0 @@
1
- import type { DocBuilder } from '@atlaskit/editor-common/types';
2
- import type { LightEditorPlugin } from '@atlaskit/editor-core/src/create-editor/get-plugins';
3
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
5
- import { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
7
- import { gridPlugin } from '@atlaskit/editor-plugin-grid';
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 { DecorationSet } from '@atlaskit/editor-prosemirror/view';
12
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
13
- import {
14
- createProsemirrorEditorFactory,
15
- Preset,
16
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
17
- import {
18
- doc,
19
- table,
20
- tdCursor,
21
- tdEmpty,
22
- tr,
23
- } from '@atlaskit/editor-test-helpers/doc-builder';
24
-
25
- import tablePlugin from '../../../../plugin';
26
- import { buildColumnControlsDecorations } from '../../../../pm-plugins/decorations/utils';
27
- import { pluginKey } from '../../../../pm-plugins/plugin-key';
28
- import { TableDecorations } from '../../../../types';
29
-
30
- describe('tables: column controls decorations', () => {
31
- const createEditor = createProsemirrorEditorFactory();
32
- const editor = (doc: DocBuilder, isDragAndDropEnabled = false) =>
33
- createEditor({
34
- doc,
35
- attachTo: document.body,
36
- featureFlags: {
37
- tableDragAndDrop: isDragAndDropEnabled,
38
- },
39
- preset: new Preset<LightEditorPlugin>()
40
- .add([featureFlagsPlugin, {}])
41
- .add([analyticsPlugin, {}])
42
- .add(contentInsertionPlugin)
43
- .add(decorationsPlugin)
44
- .add(widthPlugin)
45
- .add(guidelinePlugin)
46
- .add(gridPlugin)
47
- .add(selectionPlugin)
48
- .add([
49
- tablePlugin,
50
- {
51
- tableOptions: { advanced: true },
52
- },
53
- ]),
54
- pluginKey,
55
- });
56
-
57
- it(`should return an empty decorationSet ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop is enabled`, () => {
58
- const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
59
- const editorInstance = editor(doc(table()(tr(tdCursor, tdEmpty))), true);
60
- const state = editorInstance.editorView.state;
61
- const nextDecorationSet = buildColumnControlsDecorations({
62
- decorationSet: DecorationSet.empty,
63
- tr: state.tr,
64
- options: { isDragAndDropEnabled: true },
65
- });
66
-
67
- const decorations = nextDecorationSet.find(
68
- undefined,
69
- undefined,
70
- (spec: any) => spec.key.indexOf(decorationKey) > -1,
71
- );
72
-
73
- expect(decorations).toHaveLength(0);
74
- });
75
-
76
- it(`should return an empty decorationSet ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop is disabled`, () => {
77
- const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
78
- const editorInstance = editor(doc(table()(tr(tdCursor, tdEmpty))), false);
79
- const state = editorInstance.editorView.state;
80
- const nextDecorationSet = buildColumnControlsDecorations({
81
- decorationSet: DecorationSet.empty,
82
- tr: state.tr,
83
- options: { isDragAndDropEnabled: false },
84
- });
85
-
86
- const decorations = nextDecorationSet.find(
87
- undefined,
88
- undefined,
89
- (spec: any) => spec.key.indexOf(decorationKey) > -1,
90
- );
91
-
92
- expect(decorations).toHaveLength(2);
93
- });
94
- });