@atlaskit/editor-plugin-table 7.2.2 → 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 (102) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  3. package/dist/cjs/utils/drag-menu.js +37 -23
  4. package/dist/cjs/utils/merged-cells.js +66 -1
  5. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  6. package/dist/es2019/utils/drag-menu.js +38 -14
  7. package/dist/es2019/utils/merged-cells.js +73 -0
  8. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  9. package/dist/esm/utils/drag-menu.js +36 -22
  10. package/dist/esm/utils/merged-cells.js +65 -0
  11. package/dist/types/utils/drag-menu.d.ts +4 -1
  12. package/dist/types/utils/merged-cells.d.ts +2 -0
  13. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  14. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  15. package/package.json +9 -16
  16. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  17. package/src/utils/drag-menu.ts +94 -20
  18. package/src/utils/merged-cells.ts +78 -0
  19. package/tsconfig.dev.json +0 -69
  20. package/tsconfig.json +2 -877
  21. package/examples/99-testing.tsx +0 -140
  22. package/examples/config.jsonc +0 -14
  23. package/src/__tests__/unit/analytics.ts +0 -888
  24. package/src/__tests__/unit/collab.ts +0 -93
  25. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  26. package/src/__tests__/unit/commands/insert.ts +0 -137
  27. package/src/__tests__/unit/commands/misc.ts +0 -185
  28. package/src/__tests__/unit/commands/sort.ts +0 -128
  29. package/src/__tests__/unit/commands.ts +0 -745
  30. package/src/__tests__/unit/copy-button.ts +0 -22
  31. package/src/__tests__/unit/copy-paste.ts +0 -677
  32. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  33. package/src/__tests__/unit/event-handlers.ts +0 -296
  34. package/src/__tests__/unit/fix-tables.ts +0 -164
  35. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  36. package/src/__tests__/unit/handlers.ts +0 -98
  37. package/src/__tests__/unit/hover-selection.ts +0 -230
  38. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  39. package/src/__tests__/unit/index.ts +0 -912
  40. package/src/__tests__/unit/layout.ts +0 -146
  41. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  42. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  43. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  44. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  45. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  46. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  47. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  48. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  49. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  50. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  51. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  52. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  53. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  54. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  55. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  56. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  57. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  58. package/src/__tests__/unit/sort-column.ts +0 -399
  59. package/src/__tests__/unit/toolbar.ts +0 -512
  60. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  61. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  62. package/src/__tests__/unit/transforms/merging.ts +0 -392
  63. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  64. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  65. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  66. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  67. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  68. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  69. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  70. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  71. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  72. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  73. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  74. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  75. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  76. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  77. package/src/__tests__/unit/undo-redo.ts +0 -220
  78. package/src/__tests__/unit/utils/analytics.ts +0 -98
  79. package/src/__tests__/unit/utils/collapse.ts +0 -57
  80. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  81. package/src/__tests__/unit/utils/dom.ts +0 -180
  82. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  83. package/src/__tests__/unit/utils/nodes.ts +0 -79
  84. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  85. package/src/__tests__/unit/utils/table.ts +0 -96
  86. package/src/__tests__/unit/utils.ts +0 -670
  87. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  88. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  89. 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
  90. 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
  91. 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
  92. 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
  93. 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
  94. 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
  95. 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
  96. 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
  97. 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
  98. 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
  99. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  100. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  101. package/src/__tests__/visual-regression/index.ts +0 -62
  102. package/src/__tests__/visual-regression/sticky-header.ts +0 -61
@@ -1,176 +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 type { PluginKey } from '@atlaskit/editor-prosemirror/state';
10
- import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
11
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
12
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
13
- import { getCellsInColumn } from '@atlaskit/editor-tables/utils';
14
- // eslint-disable-next-line import/no-extraneous-dependencies
15
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
16
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
17
- import {
18
- createProsemirrorEditorFactory,
19
- Preset,
20
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
21
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
22
- import {
23
- doc,
24
- p,
25
- table,
26
- td,
27
- tdCursor,
28
- tdEmpty,
29
- tr,
30
- } from '@atlaskit/editor-test-helpers/doc-builder';
31
-
32
- import {
33
- hideResizeHandleLine,
34
- showResizeHandleLine,
35
- } from '../../../../commands/hover';
36
- import tablePlugin from '../../../../plugin';
37
- import { getDecorations } from '../../../../pm-plugins/decorations/plugin';
38
- import { buildColumnResizingDecorations } from '../../../../pm-plugins/decorations/utils';
39
- import { pluginKey } from '../../../../pm-plugins/plugin-key';
40
- import type { TablePluginState } from '../../../../types';
41
- import { TableDecorations } from '../../../../types';
42
-
43
- describe('tables: column resizing decorations', () => {
44
- const createEditor = createProsemirrorEditorFactory();
45
- const getEditorFeatureFlags = () => ({});
46
- const preset = new Preset<LightEditorPlugin>()
47
- .add([featureFlagsPlugin, {}])
48
- .add([analyticsPlugin, {}])
49
- .add(contentInsertionPlugin)
50
- .add(widthPlugin)
51
- .add(guidelinePlugin)
52
- .add(selectionPlugin)
53
- .add([
54
- tablePlugin,
55
- {
56
- tableOptions: { allowColumnResizing: true },
57
- getEditorFeatureFlags,
58
- },
59
- ]);
60
- const editor = (doc: DocBuilder) =>
61
- createEditor<TablePluginState, PluginKey, typeof preset>({
62
- doc,
63
- preset,
64
- pluginKey,
65
- });
66
-
67
- const getTableDecorations = (
68
- editorView: EditorView,
69
- cells: Array<ContentNodeWithPos>,
70
- key?: TableDecorations,
71
- ) => {
72
- const decorationSet = getDecorations(editorView.state);
73
- if (key) {
74
- const lastCell = cells[cells.length - 1];
75
- return decorationSet.find(
76
- cells[0].pos,
77
- lastCell.pos + lastCell.node.nodeSize,
78
- (spec) => spec.key.indexOf(key) > -1,
79
- );
80
- }
81
-
82
- return decorationSet.find(cells[0].pos, cells[cells.length - 1].pos);
83
- };
84
-
85
- describe('#buildColumnResizingDecorations', () => {
86
- describe.each([
87
- [0, -1, TableDecorations.COLUMN_RESIZING_HANDLE, 0],
88
- [0, 0, TableDecorations.COLUMN_RESIZING_HANDLE, 0],
89
- [0, 1, TableDecorations.COLUMN_RESIZING_HANDLE, 1],
90
- ])(
91
- 'when columnEndIndex is %i',
92
- (rowEndIndex, columnEndIndex, decorationKey, expectedDecorations) => {
93
- it(`should return a decorationSet with ${expectedDecorations} ${decorationKey} type`, () => {
94
- const {
95
- editorView: { state },
96
- } = editor(doc(table()(tr(tdCursor, tdEmpty))));
97
- const nextDecorationSet = buildColumnResizingDecorations(
98
- rowEndIndex,
99
- columnEndIndex,
100
- false,
101
- () => ({} as any),
102
- )({
103
- decorationSet: DecorationSet.empty,
104
- tr: state.tr,
105
- });
106
-
107
- const decorations = nextDecorationSet.find(
108
- undefined,
109
- undefined,
110
- (spec) => spec.key.indexOf(decorationKey) > -1,
111
- );
112
-
113
- expect(decorations).toHaveLength(expectedDecorations);
114
- });
115
- },
116
- );
117
- });
118
-
119
- describe('when the table has merged cells on first row', () => {
120
- let editorView: EditorView;
121
-
122
- beforeEach(() => {
123
- const mountedEditor = editor(
124
- doc(
125
- p('text'),
126
- table()(
127
- tr(tdCursor, td({ colspan: 2 })(p(''))),
128
- tr(td()(p('a1')), tdEmpty, tdEmpty),
129
- tr(td()(p('a2')), tdEmpty, tdEmpty),
130
- ),
131
- ),
132
- );
133
-
134
- editorView = mountedEditor.editorView;
135
- });
136
-
137
- describe('when the showResizeHandleLine is dispatched', () => {
138
- beforeEach(() => {
139
- showResizeHandleLine({ left: 1, right: 2 })(
140
- editorView.state,
141
- editorView.dispatch,
142
- );
143
- });
144
-
145
- it('should add resizer line decoration', () => {
146
- const cells = getCellsInColumn(1)(editorView.state.selection)!;
147
-
148
- const decor = getTableDecorations(
149
- editorView,
150
- cells,
151
- TableDecorations.COLUMN_RESIZING_HANDLE_LINE,
152
- );
153
-
154
- expect(decor).toHaveLength(2);
155
- });
156
-
157
- describe('when the hideResizeHandleLine is dispatched', () => {
158
- beforeEach(() => {
159
- hideResizeHandleLine()(editorView.state, editorView.dispatch);
160
- });
161
-
162
- it('should remove resizer line decoration', () => {
163
- const cells = getCellsInColumn(1)(editorView.state.selection)!;
164
-
165
- const decor = getTableDecorations(
166
- editorView,
167
- cells,
168
- TableDecorations.COLUMN_RESIZING_HANDLE_LINE,
169
- );
170
-
171
- expect(decor).toHaveLength(0);
172
- });
173
- });
174
- });
175
- });
176
- });
@@ -1,211 +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 { Selection } from '@atlaskit/editor-prosemirror/state';
10
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
11
- import { addColumnAt } from '@atlaskit/editor-tables/utils';
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
- table,
23
- tdCursor,
24
- tdEmpty,
25
- tr,
26
- } from '@atlaskit/editor-test-helpers/doc-builder';
27
-
28
- import { selectColumn } from '../../../../commands';
29
- import tablePlugin from '../../../../plugin';
30
- import {
31
- getDecorations,
32
- handleDocOrSelectionChanged,
33
- } from '../../../../pm-plugins/decorations/plugin';
34
- import { pluginKey } from '../../../../pm-plugins/plugin-key';
35
- import { pluginKey as tableWidthPluginKey } from '../../../../pm-plugins/table-width';
36
- import { TableDecorations } from '../../../../types';
37
-
38
- describe('decorations plugin', () => {
39
- const createEditor = createProsemirrorEditorFactory();
40
- const editor = (doc: DocBuilder) =>
41
- createEditor({
42
- doc,
43
- attachTo: document.body,
44
- preset: new Preset<LightEditorPlugin>()
45
- .add([featureFlagsPlugin, {}])
46
- .add([analyticsPlugin, {}])
47
- .add(contentInsertionPlugin)
48
- .add(widthPlugin)
49
- .add(guidelinePlugin)
50
- .add(selectionPlugin)
51
- .add(tablePlugin),
52
- pluginKey,
53
- });
54
-
55
- // ED-8457
56
- describe('when there is a selection pointer set', () => {
57
- describe('should remove the column selected decorations', () => {
58
- const { editorView } = editor(
59
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
60
- );
61
-
62
- selectColumn(1)(editorView.state, editorView.dispatch);
63
-
64
- const { tr: transaction } = editorView.state;
65
-
66
- transaction.setMeta('pointer', true);
67
- transaction.setSelection(Selection.atStart(transaction.doc));
68
- editorView.dispatch(transaction);
69
-
70
- const decorationSet = getDecorations(editorView.state);
71
-
72
- const columnSelectedDecorations = decorationSet.find(
73
- undefined,
74
- undefined,
75
- (spec) => spec.key.indexOf(TableDecorations.COLUMN_SELECTED) > -1,
76
- );
77
-
78
- expect(columnSelectedDecorations).toHaveLength(0);
79
- });
80
- });
81
-
82
- describe('when the doc did not changed', () => {
83
- it('should not re-create the decorations', () => {
84
- const pluginState = DecorationSet.empty;
85
- const { editorView } = editor(
86
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
87
- );
88
-
89
- const oldState = handleDocOrSelectionChanged(
90
- editorView.state.tr,
91
- pluginState,
92
- editorView.state,
93
- editorView.state,
94
- );
95
-
96
- const newState = handleDocOrSelectionChanged(
97
- editorView.state.tr,
98
- oldState,
99
- editorView.state,
100
- editorView.state,
101
- );
102
-
103
- expect(newState).toEqual(oldState);
104
- });
105
- });
106
-
107
- describe('when the table changed', () => {
108
- describe('should not re-create the column controls decorations', () => {
109
- const { editorView } = editor(
110
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
111
- );
112
- const { state } = editorView;
113
-
114
- const nextPluginState = handleDocOrSelectionChanged(
115
- editorView.state.tr,
116
- DecorationSet.empty,
117
- editorView.state,
118
- state,
119
- );
120
-
121
- const { tr: transaction } = state;
122
- editorView.dispatch(addColumnAt(2)(transaction));
123
-
124
- const newState = handleDocOrSelectionChanged(
125
- transaction,
126
- nextPluginState,
127
- editorView.state,
128
- state,
129
- );
130
- const expectedDecorationSet = newState;
131
- const decorations = expectedDecorationSet.find(
132
- undefined,
133
- undefined,
134
- (spec) =>
135
- spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) > -1,
136
- );
137
-
138
- expect(decorations).toHaveLength(3);
139
- });
140
- });
141
-
142
- describe('when nothing changed', () => {
143
- it('should not re-create the column controls decorations', () => {
144
- const { editorView } = editor(
145
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
146
- );
147
- const oldPluginState = handleDocOrSelectionChanged(
148
- editorView.state.tr,
149
- DecorationSet.empty,
150
- editorView.state,
151
- editorView.state,
152
- );
153
-
154
- const newPluginState = handleDocOrSelectionChanged(
155
- editorView.state.tr,
156
- oldPluginState,
157
- editorView.state,
158
- editorView.state,
159
- );
160
- expect(oldPluginState).toEqual(newPluginState);
161
- });
162
- });
163
-
164
- describe('table width resizing', () => {
165
- const editor = (doc: DocBuilder) =>
166
- createEditor({
167
- doc,
168
- attachTo: document.body,
169
- preset: new Preset<LightEditorPlugin>()
170
- .add([featureFlagsPlugin, {}])
171
- .add([analyticsPlugin, {}])
172
- .add(contentInsertionPlugin)
173
- .add(widthPlugin)
174
- .add(guidelinePlugin)
175
- .add(selectionPlugin)
176
- .add([
177
- tablePlugin,
178
- {
179
- tableResizingEnabled: true,
180
- tableOptions: {
181
- advanced: true,
182
- },
183
- },
184
- ]),
185
- pluginKey,
186
- });
187
-
188
- it('should remove column controls when resizing starts and add back when it ends when customTableWidth is enabled', () => {
189
- const { editorView } = editor(
190
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
191
- );
192
-
193
- const startTransaction = editorView.state.tr.setMeta(
194
- tableWidthPluginKey,
195
- {
196
- resizing: true,
197
- },
198
- );
199
- editorView.dispatch(startTransaction);
200
- const startDecorationSet = getDecorations(editorView.state);
201
- expect(startDecorationSet).toEqual(DecorationSet.empty);
202
-
203
- const endTransaction = editorView.state.tr.setMeta(tableWidthPluginKey, {
204
- resizing: false,
205
- });
206
- editorView.dispatch(endTransaction);
207
- const endDecorationSet = getDecorations(editorView.state);
208
- expect(endDecorationSet).not.toEqual(DecorationSet.empty);
209
- });
210
- });
211
- });
@@ -1,214 +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 type { NodeType } from '@atlaskit/editor-prosemirror/model';
11
- import type { Selection } from '@atlaskit/editor-prosemirror/state';
12
- import * as pmUtils from '@atlaskit/editor-prosemirror/utils';
13
- // eslint-disable-next-line import/no-extraneous-dependencies
14
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
15
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
16
- import {
17
- createProsemirrorEditorFactory,
18
- Preset,
19
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
20
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
21
- import {
22
- doc,
23
- p,
24
- table,
25
- tdCursor,
26
- tdEmpty,
27
- tr,
28
- } from '@atlaskit/editor-test-helpers/doc-builder';
29
-
30
- import {
31
- toggleHeaderColumn,
32
- toggleHeaderRow,
33
- toggleNumberColumn,
34
- } from '../../../commands';
35
- import { setEditorFocus } from '../../../commands/misc';
36
- import * as miscCommands from '../../../commands/misc';
37
- import tablePlugin from '../../../plugin';
38
- import { getPluginState } from '../../../pm-plugins/plugin-factory';
39
- import { pluginKey } from '../../../pm-plugins/plugin-key';
40
-
41
- jest.mock('@atlaskit/editor-prosemirror/utils', () => {
42
- // Unblock prosemirror bump:
43
- // Workaround to enable spy on prosemirror-utils cjs bundle
44
- const originalModule = jest.requireActual(
45
- '@atlaskit/editor-prosemirror/utils',
46
- );
47
-
48
- return {
49
- __esModule: true,
50
- ...originalModule,
51
- };
52
- });
53
-
54
- describe('tables: main plugin', () => {
55
- const createEditor = createProsemirrorEditorFactory();
56
- const editor = (doc: DocBuilder) =>
57
- createEditor({
58
- doc,
59
- preset: new Preset<LightEditorPlugin>()
60
- .add([featureFlagsPlugin, {}])
61
- .add([analyticsPlugin, {}])
62
- .add(contentInsertionPlugin)
63
- .add(widthPlugin)
64
- .add(guidelinePlugin)
65
- .add(selectionPlugin)
66
- .add(tablePlugin),
67
- pluginKey,
68
- });
69
- const tablePluginKey = (pluginKey as any).key;
70
-
71
- it('should not call emit when typing inside a table cell', async () => {
72
- const { editorView, eventDispatcher } = editor(
73
- doc(table()(tr(tdCursor, tdEmpty))),
74
- );
75
- const emitMock = jest.spyOn(eventDispatcher, 'emit');
76
- editorView.dispatch(editorView.state.tr.insertText('a'));
77
- editorView.dispatch(editorView.state.tr.insertText('b'));
78
- editorView.dispatch(editorView.state.tr.insertText('c'));
79
-
80
- expect(
81
- emitMock.mock.calls.filter(([e, _]) => e === tablePluginKey).length,
82
- ).toEqual(0);
83
-
84
- emitMock.mockClear();
85
- });
86
-
87
- it('should not call emit when typing anywhere in the document', async () => {
88
- const { editorView, eventDispatcher } = editor(doc(p('{pos}')));
89
-
90
- const emitMock = jest.spyOn(eventDispatcher, 'emit');
91
- editorView.dispatch(editorView.state.tr.insertText('a'));
92
- editorView.dispatch(editorView.state.tr.insertText('b'));
93
- editorView.dispatch(editorView.state.tr.insertText('c'));
94
-
95
- expect(
96
- emitMock.mock.calls.filter(([e, _]) => e === tablePluginKey).length,
97
- ).toEqual(0);
98
-
99
- emitMock.mockClear();
100
- });
101
-
102
- it('should call setTableRef() if it can find a table at the current position', async () => {
103
- const spied = jest.spyOn(miscCommands, 'setTableRef');
104
-
105
- const { editorView } = editor(doc(table()(tr(tdCursor, tdEmpty))));
106
- setEditorFocus(true)(editorView.state, editorView.dispatch);
107
-
108
- expect(spied).toBeCalled();
109
-
110
- spied.mockClear();
111
- });
112
-
113
- it('should not call setTableRef() if it cannot find a table at the current position', async () => {
114
- const spied = jest.spyOn(miscCommands, 'setTableRef');
115
-
116
- const findParentDomRefOfTypeMock = jest
117
- .spyOn(pmUtils, 'findParentDomRefOfType')
118
- // (nodeType: NodeType | NodeType[], domAtPos: DomAtPos):
119
- // (selection: Selection)
120
- // => Node | undefined
121
- .mockImplementation(
122
- (
123
- nodeType: NodeType | NodeType[],
124
- domAtPos: pmUtils.DomAtPos,
125
- ): ((selection: Selection) => Node | undefined) => {
126
- const parent = document.createElement('p');
127
- parent.querySelector = () => null;
128
- return () => parent;
129
- },
130
- );
131
-
132
- const { editorView } = editor(doc(table()(tr(tdCursor, tdEmpty))));
133
- setEditorFocus(true)(editorView.state, editorView.dispatch);
134
-
135
- expect(spied).not.toBeCalled();
136
-
137
- spied.mockClear();
138
- findParentDomRefOfTypeMock.mockClear();
139
- });
140
-
141
- describe('Toggle table options', () => {
142
- it('should update plugin state when we undo enabling of a header column option ', () => {
143
- const { editorView } = editor(doc(table()(tr(tdCursor, tdEmpty))));
144
- setEditorFocus(true)(editorView.state, editorView.dispatch);
145
- expect(getPluginState(editorView.state).isHeaderRowEnabled).toBe(false);
146
- expect(getPluginState(editorView.state).isHeaderColumnEnabled).toBe(
147
- false,
148
- );
149
- expect(getPluginState(editorView.state).isNumberColumnEnabled).toBe(
150
- false,
151
- );
152
-
153
- toggleHeaderColumn(editorView.state, editorView.dispatch);
154
- expect(getPluginState(editorView.state).isHeaderColumnEnabled).toBe(true);
155
-
156
- undo(editorView.state, editorView.dispatch);
157
- expect(getPluginState(editorView.state).isHeaderRowEnabled).toBe(false);
158
- expect(getPluginState(editorView.state).isHeaderColumnEnabled).toBe(
159
- false,
160
- );
161
- expect(getPluginState(editorView.state).isNumberColumnEnabled).toBe(
162
- false,
163
- );
164
- });
165
-
166
- it('should update plugin state when we undo enabling of a header row option ', () => {
167
- const { editorView } = editor(doc(table()(tr(tdCursor, tdEmpty))));
168
- setEditorFocus(true)(editorView.state, editorView.dispatch);
169
- expect(getPluginState(editorView.state).isHeaderRowEnabled).toBe(false);
170
- expect(getPluginState(editorView.state).isHeaderColumnEnabled).toBe(
171
- false,
172
- );
173
- expect(getPluginState(editorView.state).isNumberColumnEnabled).toBe(
174
- false,
175
- );
176
-
177
- toggleHeaderRow(editorView.state, editorView.dispatch);
178
- expect(getPluginState(editorView.state).isHeaderRowEnabled).toBe(true);
179
-
180
- undo(editorView.state, editorView.dispatch);
181
- expect(getPluginState(editorView.state).isHeaderRowEnabled).toBe(false);
182
- expect(getPluginState(editorView.state).isHeaderColumnEnabled).toBe(
183
- false,
184
- );
185
- expect(getPluginState(editorView.state).isNumberColumnEnabled).toBe(
186
- false,
187
- );
188
- });
189
-
190
- it('should update plugin state when we undo enabling of a numbered column option ', () => {
191
- const { editorView } = editor(doc(table()(tr(tdCursor, tdEmpty))));
192
- setEditorFocus(true)(editorView.state, editorView.dispatch);
193
- expect(getPluginState(editorView.state).isHeaderRowEnabled).toBe(false);
194
- expect(getPluginState(editorView.state).isHeaderColumnEnabled).toBe(
195
- false,
196
- );
197
- expect(getPluginState(editorView.state).isNumberColumnEnabled).toBe(
198
- false,
199
- );
200
-
201
- toggleNumberColumn(editorView.state, editorView.dispatch);
202
- expect(getPluginState(editorView.state).isNumberColumnEnabled).toBe(true);
203
-
204
- undo(editorView.state, editorView.dispatch);
205
- expect(getPluginState(editorView.state).isHeaderRowEnabled).toBe(false);
206
- expect(getPluginState(editorView.state).isHeaderColumnEnabled).toBe(
207
- false,
208
- );
209
- expect(getPluginState(editorView.state).isNumberColumnEnabled).toBe(
210
- false,
211
- );
212
- });
213
- });
214
- });
@@ -1,101 +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 type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
11
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
12
- import {
13
- createProsemirrorEditorFactory,
14
- Preset,
15
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
16
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
17
- import {
18
- doc,
19
- p,
20
- table,
21
- td,
22
- tr,
23
- } from '@atlaskit/editor-test-helpers/doc-builder';
24
-
25
- import tablePlugin from '../../../plugin';
26
- import { pluginKey } from '../../../pm-plugins/plugin-key';
27
-
28
- describe('table/safari-delete-composition-text-issue-workaround', () => {
29
- let editor: any;
30
- beforeEach(() => {
31
- const createEditor = createProsemirrorEditorFactory();
32
- editor = (doc: DocBuilder) =>
33
- createEditor({
34
- doc,
35
- preset: new Preset<LightEditorPlugin>()
36
- .add([featureFlagsPlugin, {}])
37
- .add([analyticsPlugin, {}])
38
- .add(contentInsertionPlugin)
39
- .add(widthPlugin)
40
- .add(guidelinePlugin)
41
- .add(selectionPlugin)
42
- .add([tablePlugin, { tableOptions: { allowColumnResizing: true } }]),
43
- pluginKey,
44
- });
45
- });
46
-
47
- beforeAll(() => {
48
- const container = document.createTextNode('');
49
- //@ts-ignore
50
- jest.spyOn(window, 'getSelection').mockImplementation(() => ({
51
- type: 'Range',
52
- rangeCount: 1,
53
- getRangeAt: () => ({
54
- startContainer: container,
55
- endContainer: container,
56
- endOffset: 0,
57
- startOffset: 0,
58
- }),
59
- }));
60
- });
61
-
62
- afterAll(() => {
63
- (window.getSelection as jest.Mock).mockRestore();
64
- });
65
-
66
- it('should render empty span on beforeinput then remove it on input on safari', async () => {
67
- const { editorView: view } = editor(
68
- doc(table()(tr(td()(p('{<>}')), td()(p()), td()(p())))),
69
- );
70
-
71
- const beforeinputEvent = new InputEvent('beforeinput', {
72
- data: 'あああ',
73
- isComposing: true,
74
- inputType: 'deleteCompositionText',
75
- });
76
-
77
- view.dom.dispatchEvent(beforeinputEvent);
78
-
79
- const spanElement = view.dom.querySelector(
80
- 'table tr td:nth-of-type(1) span',
81
- );
82
-
83
- expect(spanElement).toBeTruthy();
84
- expect(spanElement.tagName).toBe('SPAN');
85
- expect(spanElement.textContent).toBeFalsy();
86
-
87
- const inputEvent = new InputEvent('input', {
88
- data: 'あああ',
89
- isComposing: true,
90
- inputType: 'deleteCompositionText',
91
- });
92
-
93
- view.dom.dispatchEvent(inputEvent);
94
-
95
- const emptyElement = view.dom.querySelector(
96
- 'table tr td:nth-of-type(1) span',
97
- );
98
-
99
- expect(emptyElement).toBeNull();
100
- });
101
- });