@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,93 +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 { removeColumnAt } from '@atlaskit/editor-tables/utils';
10
- // eslint-disable-next-line import/no-extraneous-dependencies
11
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
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
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
18
- import {
19
- doc,
20
- p,
21
- table,
22
- td,
23
- th,
24
- tr,
25
- } from '@atlaskit/editor-test-helpers/doc-builder';
26
-
27
- import tablePlugin from '../../plugin';
28
- import { pluginKey as tablePluginKey } from '../../pm-plugins/plugin-key';
29
- import { setResizeHandlePos } from '../../pm-plugins/table-resizing/commands';
30
- import type { PluginConfig } from '../../types';
31
-
32
- const TABLE_LOCAL_ID = 'test-table-local-id';
33
-
34
- describe('Tables with Collab editing', () => {
35
- const createEditor = createProsemirrorEditorFactory();
36
- const tableOptions = {
37
- allowNumberColumn: true,
38
- allowHeaderRow: true,
39
- allowHeaderColumn: true,
40
- permittedLayouts: 'all',
41
- allowColumnResizing: true,
42
- } as PluginConfig;
43
-
44
- const editor = (doc: DocBuilder) => {
45
- return createEditor({
46
- doc,
47
- preset: new Preset<LightEditorPlugin>()
48
- .add([featureFlagsPlugin, {}])
49
- .add([analyticsPlugin, {}])
50
- .add(contentInsertionPlugin)
51
- .add(widthPlugin)
52
- .add(guidelinePlugin)
53
- .add(selectionPlugin)
54
- .add([tablePlugin, { tableOptions }]),
55
- pluginKey: tablePluginKey,
56
- });
57
- };
58
-
59
- it('applies colwidths to cells and sets autosize to false', () => {
60
- const { editorView: view } = editor(
61
- doc(
62
- table({ localId: TABLE_LOCAL_ID })(
63
- tr(th()(p('{<>}1')), th()(p('2')), th()(p('3'))),
64
- tr(td()(p('4')), td()(p('5')), td()(p('6'))),
65
- tr(td()(p('7')), td()(p('8')), td()(p('9'))),
66
- ),
67
- ),
68
- );
69
-
70
- // Trigger table resizing mouse down handlers.
71
- setResizeHandlePos(2)(view.state, view.dispatch);
72
- const mousedownEvent = new MouseEvent('mousedown', { clientX: 50 });
73
- view.dom.dispatchEvent(mousedownEvent);
74
-
75
- // Simulate collab change, delete col.
76
- const documentChangeTr = removeColumnAt(1)(view.state.tr);
77
- view.updateState(view.state.apply(documentChangeTr));
78
-
79
- // Trigger table resizing finish handlers
80
- const mouseupEvent = new MouseEvent('mouseup', { clientX: 150 });
81
- window.dispatchEvent(mouseupEvent);
82
-
83
- expect(view.state.doc).toEqualDocument(
84
- doc(
85
- table({ localId: TABLE_LOCAL_ID })(
86
- tr(th()(p('1')), th()(p('3'))),
87
- tr(td()(p('4')), td()(p('6'))),
88
- tr(td()(p('7')), td()(p('9'))),
89
- ),
90
- ),
91
- );
92
- });
93
- });
@@ -1,173 +0,0 @@
1
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
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 { PluginKey } 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
- tdCursor,
25
- tdEmpty,
26
- tr,
27
- } from '@atlaskit/editor-test-helpers/doc-builder';
28
-
29
- import { goToNextCell } from '../../../commands/go-to-next-cell';
30
- import tablePlugin from '../../../plugin';
31
- import { pluginKey } from '../../../pm-plugins/plugin-key';
32
- import type { TablePluginState } from '../../../types';
33
-
34
- const TABLE_LOCAL_ID = 'test-table-local-id';
35
-
36
- const tdNextFocus = td()(p('{nextFocus}'));
37
-
38
- describe('table plugin: goToNextCell', () => {
39
- const editorAnalyticsAPIFake: EditorAnalyticsAPI = {
40
- attachAnalyticsEvent: jest.fn().mockReturnValue(() => jest.fn()),
41
- fireAnalyticsEvent: jest.fn(),
42
- };
43
- const createEditor = createProsemirrorEditorFactory();
44
- const 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
- const editor = (doc: DocBuilder) =>
53
- createEditor<TablePluginState, PluginKey, typeof preset>({
54
- doc,
55
- preset,
56
- pluginKey,
57
- });
58
-
59
- it('should do nothing when focus is not on a table', () => {
60
- const { editorView } = editor(doc(p()));
61
- const {
62
- state,
63
- state: { doc: initialDoc },
64
- dispatch,
65
- } = editorView;
66
-
67
- const returnValue = goToNextCell(editorAnalyticsAPIFake)(1)(
68
- state,
69
- dispatch,
70
- );
71
-
72
- expect(returnValue).toBeFalsy();
73
- expect(editorView.state.doc).toEqual(initialDoc);
74
- });
75
-
76
- it('should tab to next cell if focus is in the middle', () => {
77
- const { editorView, refs } = editor(
78
- doc(
79
- table({ localId: TABLE_LOCAL_ID })(
80
- tr(tdEmpty, tdCursor, tdNextFocus),
81
- tr(tdEmpty, tdEmpty, tdEmpty),
82
- ),
83
- ),
84
- );
85
- const { state, dispatch } = editorView;
86
-
87
- const returnValue = goToNextCell(editorAnalyticsAPIFake)(1)(
88
- state,
89
- dispatch,
90
- );
91
-
92
- expect(returnValue).toBeTruthy();
93
- expect(editorView.state.selection.$anchor.pos).toEqual(refs.nextFocus);
94
- });
95
-
96
- it('should reverse tab to previous cell if focus is in the middle', () => {
97
- const { editorView, refs } = editor(
98
- doc(
99
- table({ localId: TABLE_LOCAL_ID })(
100
- tr(tdNextFocus, tdCursor, tdEmpty),
101
- tr(tdEmpty, tdEmpty, tdEmpty),
102
- ),
103
- ),
104
- );
105
- const { state, dispatch } = editorView;
106
-
107
- const returnValue = goToNextCell(editorAnalyticsAPIFake)(-1)(
108
- state,
109
- dispatch,
110
- );
111
-
112
- expect(returnValue).toBeTruthy();
113
- expect(editorView.state.selection.$anchor.pos).toEqual(refs.nextFocus);
114
- });
115
-
116
- it('should insert row at end of table when tabbed on last cell', () => {
117
- const { editorView } = editor(
118
- doc(
119
- table({ localId: TABLE_LOCAL_ID })(
120
- tr(tdEmpty, tdEmpty, tdEmpty),
121
- tr(tdEmpty, tdEmpty, tdCursor),
122
- ),
123
- ),
124
- );
125
- const { state, dispatch } = editorView;
126
-
127
- const expected = doc(
128
- table({ localId: TABLE_LOCAL_ID })(
129
- tr(tdEmpty, tdEmpty, tdEmpty),
130
- tr(tdEmpty, tdEmpty, tdEmpty),
131
- tr(tdNextFocus, tdEmpty, tdEmpty),
132
- ),
133
- )(state.schema);
134
-
135
- const returnValue = goToNextCell(editorAnalyticsAPIFake)(1)(
136
- state,
137
- dispatch,
138
- );
139
-
140
- expect(returnValue).toBeTruthy();
141
- expect(expected.eq(editorView.state.doc)).toBeTruthy();
142
- expect(editorView.state.selection.$anchor.pos).toEqual(32);
143
- });
144
-
145
- it('should insert row at start of table when reverse tabbed on first cell', () => {
146
- const { editorView } = editor(
147
- doc(
148
- table({ localId: TABLE_LOCAL_ID })(
149
- tr(tdCursor, tdEmpty, tdEmpty),
150
- tr(tdEmpty, tdEmpty, tdEmpty),
151
- ),
152
- ),
153
- );
154
- const { state, dispatch } = editorView;
155
-
156
- const expected = doc(
157
- table({ localId: TABLE_LOCAL_ID })(
158
- tr(tdNextFocus, tdEmpty, tdEmpty),
159
- tr(tdEmpty, tdEmpty, tdEmpty),
160
- tr(tdEmpty, tdEmpty, tdEmpty),
161
- ),
162
- )(state.schema);
163
-
164
- const returnValue = goToNextCell(editorAnalyticsAPIFake)(-1)(
165
- state,
166
- dispatch,
167
- );
168
-
169
- expect(returnValue).toBeTruthy();
170
- expect(expected.eq(editorView.state.doc)).toBeTruthy();
171
- expect(editorView.state.selection.$anchor.pos).toEqual(4);
172
- });
173
- });
@@ -1,137 +0,0 @@
1
- import type {
2
- DocBuilder,
3
- GetEditorContainerWidth,
4
- } from '@atlaskit/editor-common/types';
5
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
6
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
7
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
8
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
9
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
10
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
11
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
12
- import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
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
- td,
26
- tdEmpty,
27
- tr,
28
- } from '@atlaskit/editor-test-helpers/doc-builder';
29
-
30
- import { addColumnAt } from '../../../commands/insert';
31
- import tablePlugin from '../../../plugin';
32
- import { pluginKey } from '../../../pm-plugins/plugin-key';
33
- import type { TablePluginState } from '../../../types';
34
-
35
- const TABLE_LOCAL_ID = 'test-table-local-id';
36
-
37
- describe('table plugin: insert', () => {
38
- describe('addColumnAt', () => {
39
- // We override the body as the table resizing logic uses it via the width plugin
40
- // to calculate if a table should overflow
41
- const mockBodyOffsetWidth = 1000;
42
- const getEditorContainerWidth: GetEditorContainerWidth = () => {
43
- return {
44
- width: mockBodyOffsetWidth,
45
- };
46
- };
47
-
48
- const createEditor = createProsemirrorEditorFactory();
49
-
50
- const 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
- },
62
- ]);
63
-
64
- const editor = (doc: DocBuilder) =>
65
- createEditor<TablePluginState, PluginKey, typeof preset>({
66
- doc,
67
- preset,
68
- pluginKey,
69
- });
70
-
71
- it('does scale cells in tables which are not overflowing', () => {
72
- jest
73
- .spyOn(HTMLElement.prototype, 'clientWidth', 'get')
74
- .mockImplementationOnce(() => 760)
75
- .mockImplementationOnce(() => 770);
76
-
77
- const { editorView } = editor(
78
- doc(
79
- table({ localId: TABLE_LOCAL_ID })(
80
- tr(
81
- td({ colwidth: [230] })(p('')),
82
- td({ colwidth: [230] })(p('')),
83
- td({ colwidth: [230] })(p('')),
84
- ),
85
- ),
86
- ),
87
- );
88
- const { state } = editorView;
89
- const transaction = state.tr;
90
- const lastTableCellNode =
91
- transaction.doc.content.firstChild?.firstChild?.lastChild;
92
-
93
- const updatedTransaction = addColumnAt(getEditorContainerWidth)(
94
- 2,
95
- true,
96
- editorView,
97
- )(transaction);
98
-
99
- const updatedLastTableCellNode =
100
- updatedTransaction.doc.content.firstChild?.firstChild?.lastChild;
101
-
102
- expect(updatedLastTableCellNode?.attrs.colwidth[0]).not.toBe(
103
- lastTableCellNode?.attrs.colwidth[0],
104
- );
105
-
106
- jest.restoreAllMocks();
107
- });
108
-
109
- it('does not scale cells in tables which are overflowing', () => {
110
- const { editorView } = editor(
111
- doc(
112
- table({ localId: TABLE_LOCAL_ID })(
113
- tr(
114
- td({ colwidth: [mockBodyOffsetWidth] })(p('')),
115
- tdEmpty,
116
- tdEmpty,
117
- ),
118
- ),
119
- ),
120
- );
121
- const { state } = editorView;
122
- const transaction = state.tr;
123
-
124
- const updatedTransaction = addColumnAt(getEditorContainerWidth)(
125
- 2,
126
- true,
127
- editorView,
128
- )(transaction);
129
-
130
- const tablePMNode = updatedTransaction.doc.content.firstChild;
131
- const tableRowNode = tablePMNode?.firstChild;
132
- const firstTableCellNode = tableRowNode?.firstChild;
133
-
134
- expect(firstTableCellNode?.attrs.colwidth[0]).toBe(mockBodyOffsetWidth);
135
- });
136
- });
137
- });
@@ -1,185 +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 { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
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 { PluginKey } from '@atlaskit/editor-prosemirror/state';
11
- import { isColumnSelected } 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
- p,
23
- table,
24
- td,
25
- tdEmpty,
26
- tr,
27
- } from '@atlaskit/editor-test-helpers/doc-builder';
28
-
29
- import { moveCursorBackward, selectColumn } from '../../../commands';
30
- import tablePlugin from '../../../plugin';
31
- import { getDecorations } from '../../../pm-plugins/decorations/plugin';
32
- import { getPluginState } from '../../../pm-plugins/plugin-factory';
33
- import { pluginKey } from '../../../pm-plugins/plugin-key';
34
- import type { TablePluginState } from '../../../types';
35
- import { TableDecorations } from '../../../types';
36
-
37
- describe('table plugin: commands', () => {
38
- const createEditor = createProsemirrorEditorFactory();
39
- const preset = new Preset<LightEditorPlugin>()
40
- .add([featureFlagsPlugin, {}])
41
- .add([analyticsPlugin, {}])
42
- .add(decorationsPlugin)
43
- .add(contentInsertionPlugin)
44
- .add(widthPlugin)
45
- .add(guidelinePlugin)
46
- .add(selectionPlugin)
47
- .add([
48
- tablePlugin,
49
- {
50
- tableOptions: { allowHeaderColumn: true },
51
- },
52
- ]);
53
- const editor = (doc: DocBuilder) =>
54
- createEditor<TablePluginState, PluginKey, typeof preset>({
55
- doc,
56
- preset,
57
- pluginKey,
58
- });
59
-
60
- describe('#selectColumn', () => {
61
- it('should select a column and set targetCellPosition to point to the first cell', () => {
62
- const { editorView } = editor(doc(table()(tr(tdEmpty, tdEmpty))));
63
- const { state, dispatch } = editorView;
64
- selectColumn(1)(state, dispatch);
65
- const pluginState = getPluginState(editorView.state);
66
- expect(pluginState.targetCellPosition).toEqual(6);
67
- expect(isColumnSelected(1)(editorView.state.selection));
68
- });
69
-
70
- it('should create decorations to select the column', () => {
71
- const { editorView } = editor(doc(table()(tr(tdEmpty, tdEmpty))));
72
- const { state, dispatch } = editorView;
73
- selectColumn(1)(state, dispatch);
74
- const decorationSet = getDecorations(editorView.state);
75
- const columnSelectedDecorations = decorationSet.find(
76
- undefined,
77
- undefined,
78
- (spec) => spec.key.indexOf(TableDecorations.COLUMN_SELECTED) > -1,
79
- );
80
-
81
- expect(columnSelectedDecorations).toHaveLength(1);
82
- });
83
- });
84
-
85
- describe('#moveCursorBackwards', () => {
86
- describe(`press backspace in an empty paragraph`, () => {
87
- describe(`paragraph is not last node in document`, () => {
88
- it(`should delete the paragraph node and place the cursor inside the last table cell`, () => {
89
- const { editorView } = editor(
90
- doc(
91
- table({ localId: 'testId' })(
92
- tr(td({})(p()), td({})(p()), td({})(p())),
93
- ),
94
- p('{<>}'),
95
- p(),
96
- ),
97
- );
98
- const { state, dispatch } = editorView;
99
- moveCursorBackward(state, dispatch);
100
- const expectedDoc = doc(
101
- table({ localId: 'testId' })(
102
- tr(td({})(p()), td({})(p()), td({})(p('{<>}'))),
103
- ),
104
- p(),
105
- );
106
- expect(editorView.state).toEqualDocumentAndSelection(expectedDoc);
107
- });
108
- });
109
-
110
- describe(`paragraph is the last node in document`, () => {
111
- it(`should just place the cursor inside the last table cell`, () => {
112
- const { editorView } = editor(
113
- doc(
114
- table({ localId: 'testId' })(
115
- tr(td({})(p()), td({})(p()), td({})(p())),
116
- ),
117
- p('{<>}'),
118
- ),
119
- );
120
- const { state, dispatch } = editorView;
121
- moveCursorBackward(state, dispatch);
122
- const expectedDoc = doc(
123
- table({ localId: 'testId' })(
124
- tr(td({})(p()), td({})(p()), td({})(p('{<>}'))),
125
- ),
126
- p(),
127
- );
128
- expect(editorView.state).toEqualDocumentAndSelection(expectedDoc);
129
- });
130
- });
131
- });
132
-
133
- describe(`press backspace in paragraph with content`, () => {
134
- it(`should place cursor inside last table cell`, () => {
135
- const editorParagraphEnd = editor(
136
- doc(
137
- table({ localId: 'testId' })(
138
- tr(td({})(p()), td({})(p()), td({})(p())),
139
- ),
140
- p('{<>}hello there'),
141
- ),
142
- );
143
- const editorViewParagraphEnd = editorParagraphEnd.editorView;
144
- moveCursorBackward(
145
- editorViewParagraphEnd.state,
146
- editorViewParagraphEnd.dispatch,
147
- );
148
- const paragraphEndExpectedDoc = doc(
149
- table({ localId: 'testId' })(
150
- tr(td({})(p()), td({})(p()), td({})(p('{<>}'))),
151
- ),
152
- p('hello there'),
153
- );
154
- expect(editorViewParagraphEnd.state).toEqualDocumentAndSelection(
155
- paragraphEndExpectedDoc,
156
- );
157
-
158
- const editorParagraph = editor(
159
- doc(
160
- table({ localId: 'testId' })(
161
- tr(td({})(p()), td({})(p()), td({})(p())),
162
- ),
163
- p('{<>}hello there'),
164
- p('hello there'),
165
- ),
166
- );
167
- const editorViewParagraph = editorParagraph.editorView;
168
- moveCursorBackward(
169
- editorViewParagraph.state,
170
- editorViewParagraph.dispatch,
171
- );
172
- const paragraphExpectedDoc = doc(
173
- table({ localId: 'testId' })(
174
- tr(td({})(p()), td({})(p()), td({})(p('{<>}'))),
175
- ),
176
- p('hello there'),
177
- p('hello there'),
178
- );
179
- expect(editorViewParagraph.state).toEqualDocumentAndSelection(
180
- paragraphExpectedDoc,
181
- );
182
- });
183
- });
184
- });
185
- });