@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,180 +0,0 @@
1
- import {
2
- getMousePositionHorizontalRelativeByElement,
3
- getMousePositionVerticalRelativeByElement,
4
- } from '../../../utils/dom';
5
-
6
- describe('table plugin: utils/dom.js', () => {
7
- let element: HTMLElement;
8
- let elementContentRects: any;
9
- const elementRect: DOMRect = {
10
- width: 100,
11
- left: 50,
12
- height: 100,
13
- top: 50,
14
- bottom: 0,
15
- right: 0,
16
- x: 0,
17
- y: 0,
18
- toJSON() {
19
- return JSON.stringify(this);
20
- },
21
- };
22
- beforeAll(() => {
23
- jest.spyOn(HTMLElement.prototype, 'closest').mockImplementation(() => {
24
- return {
25
- id: 'table-cell-id',
26
- } as Element;
27
- });
28
- });
29
-
30
- beforeEach(() => {
31
- element = document.createElement('div');
32
- element.getBoundingClientRect = () => elementRect;
33
- });
34
-
35
- describe('#getMousePositionHorizontalRelativeByElement', () => {
36
- describe('when there is a gap of 30px', () => {
37
- const GAP = 30;
38
-
39
- describe('and when the mouse is outside of the gap', () => {
40
- describe('for 1px on the left', () => {
41
- it('should return null', () => {
42
- const event = {
43
- target: element,
44
- offsetX: GAP + 1,
45
- };
46
-
47
- elementContentRects = { 'table-cell-id': { width: 100 } };
48
-
49
- expect(
50
- getMousePositionHorizontalRelativeByElement(
51
- // @ts-ignore
52
- event,
53
- elementContentRects,
54
- GAP,
55
- ),
56
- ).toBeNull();
57
- });
58
- });
59
-
60
- describe('for 1px on the right', () => {
61
- it('should return null', () => {
62
- const event = {
63
- target: element,
64
- offsetX: elementRect.width - GAP - 1,
65
- };
66
-
67
- elementContentRects = { 'table-cell-id': { width: 100 } };
68
-
69
- expect(
70
- getMousePositionHorizontalRelativeByElement(
71
- // @ts-ignore
72
- event,
73
- elementContentRects,
74
- GAP,
75
- ),
76
- ).toBeNull();
77
- });
78
- });
79
- });
80
-
81
- describe('and when the mouse is inside of the gap', () => {
82
- it('should return left', () => {
83
- const event = {
84
- target: element,
85
- offsetX: GAP,
86
- };
87
-
88
- elementContentRects = { 'table-cell-id': { width: 100 } };
89
-
90
- expect(
91
- getMousePositionHorizontalRelativeByElement(
92
- // @ts-ignore
93
- event,
94
- elementContentRects,
95
- GAP,
96
- ),
97
- ).toBe('left');
98
- });
99
-
100
- it('should return right', () => {
101
- const event = {
102
- target: element,
103
- offsetX: elementRect.width - GAP,
104
- };
105
-
106
- elementContentRects = { 'table-cell-id': { width: 100 } };
107
-
108
- expect(
109
- getMousePositionHorizontalRelativeByElement(
110
- // @ts-ignore
111
- event,
112
- elementContentRects,
113
- GAP,
114
- ),
115
- ).toBe('right');
116
- });
117
- });
118
- });
119
-
120
- it('should return left when the mouse is positioned before half of the element', () => {
121
- const event = {
122
- target: element,
123
- offsetX: 50,
124
- };
125
-
126
- elementContentRects = { 'table-cell-id': { width: 100 } };
127
-
128
- expect(
129
- getMousePositionHorizontalRelativeByElement(
130
- // @ts-ignore
131
- event,
132
- elementContentRects,
133
- ),
134
- ).toBe('left');
135
- });
136
-
137
- it('should return right when the mouse is positioned after half of the element', () => {
138
- const event = {
139
- target: element,
140
- offsetX: 101,
141
- };
142
-
143
- elementContentRects = { 'table-cell-id': { width: 100 } };
144
-
145
- expect(
146
- getMousePositionHorizontalRelativeByElement(
147
- // @ts-ignore
148
- event,
149
- elementContentRects,
150
- ),
151
- ).toBe('right');
152
- });
153
- });
154
-
155
- describe('#getMousePositionVerticalRelativeByElement', () => {
156
- it('should return top when the mouse is positioned before half of the element', () => {
157
- const event = {
158
- target: element,
159
- clientY: 50,
160
- };
161
-
162
- expect(
163
- // @ts-ignore
164
- getMousePositionVerticalRelativeByElement(event),
165
- ).toBe('top');
166
- });
167
-
168
- it('should return bottom when the mouse is positioned before half of the element', () => {
169
- const event = {
170
- target: element,
171
- clientY: 101,
172
- };
173
-
174
- expect(
175
- // @ts-ignore
176
- getMousePositionVerticalRelativeByElement(event),
177
- ).toBe('bottom');
178
- });
179
- });
180
- });
@@ -1,156 +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 { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
6
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
7
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
8
- // eslint-disable-next-line import/no-extraneous-dependencies
9
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
10
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
11
- import {
12
- createProsemirrorEditorFactory,
13
- Preset,
14
- } 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
- doc,
18
- p,
19
- table,
20
- td,
21
- tdEmpty,
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
- import { hasMergedCellsInBetween } from '../../../utils';
28
-
29
- describe('table merge cells logic', () => {
30
- const createEditor = createProsemirrorEditorFactory();
31
-
32
- const editor = (doc: DocBuilder) =>
33
- createEditor({
34
- doc,
35
- preset: new Preset<LightEditorPlugin>()
36
- .add([analyticsPlugin, {}])
37
- .add(contentInsertionPlugin)
38
- .add(widthPlugin)
39
- .add(guidelinePlugin)
40
- .add(selectionPlugin)
41
- .add(tablePlugin),
42
- pluginKey,
43
- });
44
-
45
- describe('#hasMergedCellsInBetween', () => {
46
- describe('when first and second columns are merged', () => {
47
- const { editorView } = editor(
48
- doc(
49
- table()(
50
- tr(td({ colspan: 2 })(p('')), tdEmpty, tdEmpty),
51
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
52
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
53
- ),
54
- ),
55
- );
56
-
57
- it('should return false when pass indexs [-1, 0]', () => {
58
- expect(
59
- hasMergedCellsInBetween(
60
- [-1, 0],
61
- 'column',
62
- )(editorView.state.selection),
63
- ).toEqual(false);
64
- });
65
-
66
- it('should return true when pass indexs [0,1]', () => {
67
- expect(
68
- hasMergedCellsInBetween([0, 1], 'column')(editorView.state.selection),
69
- ).toEqual(true);
70
- });
71
-
72
- it('should return false when pass indexs [1,2]', () => {
73
- expect(
74
- hasMergedCellsInBetween([1, 2], 'column')(editorView.state.selection),
75
- ).toEqual(false);
76
- });
77
- });
78
-
79
- describe('when second and third columns are merged', () => {
80
- const { editorView } = editor(
81
- doc(
82
- table()(
83
- tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
84
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
85
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
86
- ),
87
- ),
88
- );
89
- it('should return false when pass indexs [0,1]', () => {
90
- expect(
91
- hasMergedCellsInBetween([0, 1], 'column')(editorView.state.selection),
92
- ).toEqual(false);
93
- });
94
-
95
- it('should return true when pass indexs [1,2]', () => {
96
- expect(
97
- hasMergedCellsInBetween([1, 2], 'column')(editorView.state.selection),
98
- ).toEqual(true);
99
- });
100
- });
101
-
102
- describe('when first and second rows are merged', () => {
103
- const { editorView } = editor(
104
- doc(
105
- table()(
106
- tr(td({ rowspan: 2 })(p('')), tdEmpty, tdEmpty, tdEmpty),
107
- tr(tdEmpty, tdEmpty, tdEmpty),
108
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
109
- ),
110
- ),
111
- );
112
-
113
- it('should return false when pass indexs [-1, 0]', () => {
114
- expect(
115
- hasMergedCellsInBetween([-1, 0], 'row')(editorView.state.selection),
116
- ).toEqual(false);
117
- });
118
-
119
- it('should return true when pass indexs [0,1]', () => {
120
- expect(
121
- hasMergedCellsInBetween([0, 1], 'row')(editorView.state.selection),
122
- ).toEqual(true);
123
- });
124
-
125
- it('should return false when pass indexs [1,2]', () => {
126
- expect(
127
- hasMergedCellsInBetween([1, 2], 'row')(editorView.state.selection),
128
- ).toEqual(false);
129
- });
130
- });
131
-
132
- describe('when second and third rows are merged', () => {
133
- const { editorView } = editor(
134
- doc(
135
- table()(
136
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
137
- tr(td({ rowspan: 2 })(p('')), tdEmpty, tdEmpty),
138
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
139
- ),
140
- ),
141
- );
142
-
143
- it('should return false when pass indexs [0,1]', () => {
144
- expect(
145
- hasMergedCellsInBetween([0, 1], 'row')(editorView.state.selection),
146
- ).toEqual(false);
147
- });
148
-
149
- it('should return true when pass indexs [1,2]', () => {
150
- expect(
151
- hasMergedCellsInBetween([1, 2], 'row')(editorView.state.selection),
152
- ).toEqual(true);
153
- });
154
- });
155
- });
156
- });
@@ -1,79 +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 { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
6
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
7
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
8
- import { findTable } from '@atlaskit/editor-tables/utils';
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
- tdCursor,
22
- tdEmpty,
23
- th,
24
- thEmpty,
25
- tr,
26
- } from '@atlaskit/editor-test-helpers/doc-builder';
27
-
28
- import tablePlugin from '../../../plugin';
29
- import { pluginKey } from '../../../pm-plugins/plugin-key';
30
- import { containsHeaderColumn } from '../../../utils/nodes';
31
-
32
- describe('table merging logic', () => {
33
- const createEditor = createProsemirrorEditorFactory();
34
-
35
- const editor = (doc: DocBuilder) =>
36
- createEditor({
37
- doc,
38
- preset: new Preset<LightEditorPlugin>()
39
- .add([analyticsPlugin, {}])
40
- .add(contentInsertionPlugin)
41
- .add(widthPlugin)
42
- .add(guidelinePlugin)
43
- .add(selectionPlugin)
44
- .add(tablePlugin),
45
- pluginKey,
46
- });
47
-
48
- describe('#containsHeaderColumn', () => {
49
- it('should return true when first col is all tableHeaders', () => {
50
- const { editorView } = editor(
51
- doc(
52
- table()(
53
- tr(thEmpty, tdCursor, tdEmpty),
54
- tr(thEmpty, tdEmpty, tdEmpty),
55
- tr(thEmpty, tdEmpty, tdEmpty),
56
- ),
57
- ),
58
- );
59
-
60
- const TableWithPos = findTable(editorView.state.selection)!;
61
- expect(containsHeaderColumn(TableWithPos.node)).toEqual(true);
62
- });
63
-
64
- it('should return true when first col has a rowspan', () => {
65
- const { editorView } = editor(
66
- doc(
67
- table()(
68
- tr(thEmpty, tdCursor, tdEmpty),
69
- tr(th({ rowspan: 2 })(p()), tdEmpty, tdEmpty),
70
- tr(tdEmpty, tdEmpty),
71
- ),
72
- ),
73
- );
74
-
75
- const TableWithPos = findTable(editorView.state.selection)!;
76
- expect(containsHeaderColumn(TableWithPos.node)).toEqual(true);
77
- });
78
- });
79
- });
@@ -1,195 +0,0 @@
1
- import { uuid } 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 { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
7
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
8
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
9
- import { TableMap } from '@atlaskit/editor-tables/table-map';
10
- import { findTable } from '@atlaskit/editor-tables/utils';
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
- tr as row,
23
- table,
24
- td,
25
- th,
26
- } from '@atlaskit/editor-test-helpers/doc-builder';
27
-
28
- import tablePlugin from '../../../plugin';
29
- import { pluginKey } from '../../../pm-plugins/plugin-key';
30
- import { copyPreviousRow } from '../../../utils/row-controls';
31
-
32
- const TABLE_LOCAL_ID = 'test-table-local-id';
33
-
34
- describe('table plugin: utils/row-controls.js', () => {
35
- beforeAll(() => {
36
- uuid.setStatic(TABLE_LOCAL_ID);
37
- });
38
-
39
- afterAll(() => {
40
- uuid.setStatic(false);
41
- });
42
-
43
- const createEditor = createProsemirrorEditorFactory();
44
- const editor = (doc: DocBuilder) =>
45
- createEditor({
46
- doc,
47
- preset: new Preset<LightEditorPlugin>()
48
- .add([analyticsPlugin, {}])
49
- .add(contentInsertionPlugin)
50
- .add(widthPlugin)
51
- .add(guidelinePlugin)
52
- .add(selectionPlugin)
53
- .add(tablePlugin),
54
- pluginKey,
55
- });
56
-
57
- describe('#copyPreviousRow', () => {
58
- describe('complex table', () => {
59
- it('should accept rowIndex zero', () => {
60
- const { editorView } = editor(
61
- doc(
62
- table()(
63
- row(th()(p('{<>}a1')), th()(p('a2')), th()(p('a3'))),
64
- row(th()(p('b1')), td()(p('b3')), td()(p('b3'))),
65
- ),
66
- ),
67
- );
68
- const { state } = editorView;
69
- expect(() => {
70
- copyPreviousRow(state.schema)(0)(state.tr);
71
- }).toThrow(
72
- /Row Index less or equal 0 isn't not allowed since there is not a previous to copy/,
73
- );
74
- });
75
-
76
- it('should copy column header', () => {
77
- const { editorView } = editor(
78
- doc(
79
- table()(
80
- row(th()(p('{<>}a1')), th()(p('a2')), th()(p('a3'))),
81
- row(th()(p('b1')), td()(p('b3')), td()(p('b3'))),
82
- ),
83
- ),
84
- );
85
- const { state } = editorView;
86
- const newTr = copyPreviousRow(state.schema)(2)(state.tr);
87
- expect(newTr.doc).toEqualDocument(
88
- doc(
89
- table({ localId: TABLE_LOCAL_ID })(
90
- row(th()(p('{<>}a1')), th()(p('a2')), th()(p('a3'))),
91
- row(th()(p('b1')), td()(p('b3')), td()(p('b3'))),
92
- row(th()(p('')), td()(p('')), td()(p(''))),
93
- ),
94
- ),
95
- );
96
- });
97
-
98
- it('should copy column header with colspan', () => {
99
- const { editorView } = editor(
100
- doc(
101
- table()(
102
- row(th()(p('{<>}a1')), th()(p('a2')), th()(p('a3'))),
103
- row(th({ colspan: 2 })(p('b1')), td()(p('b3'))),
104
- ),
105
- ),
106
- );
107
- const { state } = editorView;
108
- const newTr = copyPreviousRow(state.schema)(2)(state.tr);
109
- expect(newTr.doc).toEqualDocument(
110
- doc(
111
- table({ localId: TABLE_LOCAL_ID })(
112
- row(th()(p('{<>}a1')), th()(p('a2')), th()(p('a3'))),
113
- row(th({ colspan: 2 })(p('b1')), td()(p('b3'))),
114
- row(th({ colspan: 2 })(p('')), td()(p(''))),
115
- ),
116
- ),
117
- );
118
- });
119
-
120
- it('should keep colspan', () => {
121
- const { editorView } = editor(
122
- doc(
123
- table()(
124
- row(th()(p('{<>}a1')), th()(p('a2')), th()(p('a3'))),
125
- row(td({ colspan: 2 })(p('b1')), td()(p('b3'))),
126
- ),
127
- ),
128
- );
129
-
130
- const { state } = editorView;
131
- const newTr = copyPreviousRow(state.schema)(2)(state.tr);
132
- expect(newTr.doc).toEqualDocument(
133
- doc(
134
- table({ localId: TABLE_LOCAL_ID })(
135
- row(th()(p('{<>}a1')), th()(p('a2')), th()(p('a3'))),
136
- row(td({ colspan: 2 })(p('b1')), td()(p('b3'))),
137
- row(td({ colspan: 2 })(p('')), td()(p(''))),
138
- ),
139
- ),
140
- );
141
- });
142
-
143
- it('should copy background colors and does not expand previous rowspan', () => {
144
- const { editorView } = editor(
145
- doc(
146
- table()(
147
- row(th()(p('{<>}a1')), th()(p('a2')), th()(p('a3'))),
148
- row(
149
- td()(p('b1')),
150
- td()(p('b2')),
151
- td({ background: '#eeeaaa', rowspan: 4 })(p('b3')),
152
- ),
153
- row(td()(p('c1')), td()(p('c2'))),
154
- row(
155
- td()(p('d1')),
156
- td({ background: '#fffaaa', rowspan: 3 })(p('d2')),
157
- ),
158
- row(td()(p('XXXX'))),
159
- row(td()(p('e1')), td()(p('e2'))),
160
- row(td()(p('f1')), td()(p('f2')), td()(p('f3'))),
161
- ),
162
- ),
163
- );
164
- const { state } = editorView;
165
-
166
- const newTr = copyPreviousRow(state.schema)(5)(state.tr);
167
-
168
- const newTable = findTable(newTr.selection);
169
- const map = TableMap.get(newTable!.node);
170
- expect(map.problems).toBeNull();
171
- expect(newTr.doc).toEqualDocument(
172
- doc(
173
- table({ localId: TABLE_LOCAL_ID })(
174
- row(th()(p('a1')), th()(p('a2')), th()(p('a3'))),
175
- row(
176
- td()(p('b1')),
177
- td()(p('b2')),
178
- td({ background: '#eeeaaa', rowspan: 4 })(p('b3')),
179
- ),
180
- row(td()(p('c1')), td()(p('c2'))),
181
- row(
182
- td()(p('d1')),
183
- td({ background: '#fffaaa', rowspan: 4 })(p('d2')),
184
- ),
185
- row(td()(p('XXXX'))),
186
- row(td()(p('')), td({ background: '#eeeaaa' })(p(''))),
187
- row(td()(p('e1')), td()(p('e2'))),
188
- row(td()(p('f1')), td()(p('f2')), td()(p('f3'))),
189
- ),
190
- ),
191
- );
192
- });
193
- });
194
- });
195
- });
@@ -1,96 +0,0 @@
1
- import { getCellsInRow } from '@atlaskit/editor-tables/utils';
2
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
3
- import { createEditorState } from '@atlaskit/editor-test-helpers/create-editor-state';
4
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
5
- import {
6
- doc,
7
- p,
8
- tr as row,
9
- table,
10
- td,
11
- tdEmpty,
12
- th,
13
- } from '@atlaskit/editor-test-helpers/doc-builder';
14
-
15
- import { getMergedCellsPositions } from '../../../utils';
16
-
17
- describe('table utils', () => {
18
- describe('#getMergedCellsPositions', () => {
19
- describe('when the table has not merged cells', () => {
20
- it('should returns an emppty array', () => {
21
- const { tr } = createEditorState(
22
- doc(
23
- table()(
24
- row(th({})(p('Number{<>}'))),
25
- row(td({})(p('10{<>}'))),
26
- row(td({})(p('0'))),
27
- row(td({})(p('5'))),
28
- ),
29
- ),
30
- );
31
-
32
- expect(getMergedCellsPositions(tr)).toHaveLength(0);
33
- });
34
- });
35
-
36
- describe('when the table has merged cells in columns', () => {
37
- it('should returns the positions', () => {
38
- const { tr } = createEditorState(
39
- doc(
40
- table()(
41
- row(
42
- th({})(p('Number{<>}')),
43
- td({})(p('10{<>}')),
44
- tdEmpty,
45
- tdEmpty,
46
- ),
47
- row(td({})(p('10{<>}')), td({})(p('10{<>}')), tdEmpty, tdEmpty),
48
- row(td({ colspan: 2 })(p('0')), td({ colspan: 2 })(p('1'))),
49
- row(td({})(p('5')), td({})(p('10{<>}')), tdEmpty, tdEmpty),
50
- ),
51
- ),
52
- );
53
- const cells = getCellsInRow(2)(tr.selection)!;
54
- const tableStart = 1;
55
-
56
- expect(getMergedCellsPositions(tr)).toEqual([
57
- cells[0].pos - tableStart,
58
- cells[1].pos - tableStart,
59
- ]);
60
- });
61
- });
62
-
63
- describe('when the table has merged cells in rows', () => {
64
- it('should returns the positions', () => {
65
- const { tr } = createEditorState(
66
- doc(
67
- table()(
68
- row(
69
- th({})(p('Number{<>}')),
70
- td({})(p('10{<>}')),
71
- tdEmpty,
72
- tdEmpty,
73
- ),
74
- row(td({})(p('10{<>}')), td({})(p('10{<>}')), tdEmpty, tdEmpty),
75
- row(
76
- td({ rowspan: 2 })(p('0')),
77
- tdEmpty,
78
- tdEmpty,
79
- td({ rowspan: 2 })(p('1')),
80
- ),
81
- row(tdEmpty, tdEmpty),
82
- ),
83
- ),
84
- );
85
-
86
- const cells = getCellsInRow(2)(tr.selection)!;
87
- const tableStart = 1;
88
-
89
- expect(getMergedCellsPositions(tr)).toEqual([
90
- cells[0].pos - tableStart,
91
- cells[3].pos - tableStart,
92
- ]);
93
- });
94
- });
95
- });
96
- });