@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,146 +0,0 @@
1
- import type { TableLayout } from '@atlaskit/adf-schema';
2
- import type { DocBuilder } from '@atlaskit/editor-common/types';
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 { findTable } 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 { toggleTableLayout } from '../../commands';
29
- import tablePlugin from '../../plugin';
30
- import { getPluginState } from '../../pm-plugins/plugin-factory';
31
- import { pluginKey as tablePluginKey } from '../../pm-plugins/plugin-key';
32
- import type { PermittedLayoutsDescriptor, TablePluginState } from '../../types';
33
-
34
- describe('table toolbar', () => {
35
- const tableOptions = {
36
- allowNumberColumn: true,
37
- allowHeaderRow: true,
38
- allowHeaderColumn: true,
39
- permittedLayouts: 'all' as PermittedLayoutsDescriptor,
40
- };
41
-
42
- const createEditor = createProsemirrorEditorFactory();
43
- const preset = new Preset<LightEditorPlugin>()
44
- .add([featureFlagsPlugin, {}])
45
- .add([analyticsPlugin, {}])
46
- .add(contentInsertionPlugin)
47
- .add(decorationsPlugin)
48
- .add(widthPlugin)
49
- .add(guidelinePlugin)
50
- .add(selectionPlugin)
51
- .add([tablePlugin, { tableOptions }]);
52
-
53
- const editor = (doc: DocBuilder) => {
54
- return createEditor<TablePluginState, PluginKey, typeof preset>({
55
- doc,
56
- preset,
57
- pluginKey: tablePluginKey,
58
- });
59
- };
60
-
61
- describe('table layouts', () => {
62
- it('should update the table node layout attribute', () => {
63
- const { editorView } = editor(
64
- doc(table()(tr(tdCursor, tdEmpty, tdEmpty))),
65
- );
66
-
67
- const nodeInitial = findTable(editorView.state.selection)!.node;
68
- expect(nodeInitial).toBeDefined();
69
- expect(nodeInitial!.attrs.layout).toBe('default');
70
-
71
- toggleTableLayout(editorView.state, editorView.dispatch);
72
-
73
- const { node } = findTable(editorView.state.selection)!;
74
-
75
- expect(node).toBeDefined();
76
- expect(node!.attrs.layout).toBe('wide');
77
- });
78
-
79
- it('can set the data-layout attribute on the table DOM element', () => {
80
- const { editorView } = editor(
81
- doc(table()(tr(tdCursor, tdEmpty, tdEmpty))),
82
- );
83
-
84
- let tableElement = editorView.dom.querySelector('table');
85
- expect(tableElement!.getAttribute('data-layout')).toBe('default');
86
-
87
- toggleTableLayout(editorView.state, editorView.dispatch);
88
- tableElement = editorView.dom.querySelector('table');
89
- expect(tableElement!.getAttribute('data-layout')).toBe('wide');
90
- });
91
-
92
- it('applies the initial data-layout attribute on the table DOM element', () => {
93
- const { editorView } = editor(
94
- doc(table({ layout: 'full-width' })(tr(tdCursor, tdEmpty, tdEmpty))),
95
- );
96
-
97
- const tables = editorView.dom.getElementsByTagName('table');
98
- expect(tables.length).toBe(1);
99
- const tableElement = tables[0];
100
-
101
- expect(tableElement.getAttribute('data-layout')).toBe('full-width');
102
- });
103
-
104
- ['default', 'wide', 'full-width'].forEach((currentLayout) => {
105
- describe(`#toggleTableLayout`, () => {
106
- it('should toggle table layout attribute', () => {
107
- const { editorView } = editor(
108
- doc(
109
- table({ layout: currentLayout as TableLayout })(
110
- tr(tdCursor, tdEmpty, tdEmpty),
111
- ),
112
- ),
113
- );
114
- toggleTableLayout(editorView.state, editorView.dispatch);
115
- const { tableNode } = getPluginState(editorView.state);
116
- let nextLayout;
117
- switch (currentLayout) {
118
- case 'default':
119
- nextLayout = 'wide';
120
- break;
121
- case 'wide':
122
- nextLayout = 'full-width';
123
- break;
124
- case 'full-width':
125
- nextLayout = 'default';
126
- break;
127
- }
128
- expect(tableNode).toBeDefined();
129
- expect(tableNode!.attrs.layout).toBe(nextLayout);
130
- });
131
- });
132
- });
133
-
134
- it('applies the initial data-layout attribute on the table DOM element', () => {
135
- const { editorView } = editor(
136
- doc(table({ layout: 'full-width' })(tr(tdCursor, tdEmpty, tdEmpty))),
137
- );
138
-
139
- const tables = editorView.dom.getElementsByTagName('table');
140
- expect(tables.length).toBe(1);
141
- const tableElement = tables[0];
142
-
143
- expect(tableElement.getAttribute('data-layout')).toBe('full-width');
144
- });
145
- });
146
- });
@@ -1,162 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
2
- import { MockIntersectionObserver } from '@atlaskit/editor-test-helpers/mock-intersection-observer';
3
-
4
- import { OverflowShadowsObserver } from '../../../nodeviews/OverflowShadowsObserver';
5
- import { TableCssClassName as className, ShadowEvent } from '../../../types';
6
-
7
- describe('OverflowShadowsObserver', () => {
8
- let table: HTMLTableElement;
9
- let td1: HTMLTableDataCellElement;
10
- let td2: HTMLTableDataCellElement;
11
- let shadowSentinelLeft: HTMLDivElement;
12
- let shadowSentinelRight: HTMLDivElement;
13
- let wrapper: HTMLDivElement;
14
- const updateSpy = jest.fn();
15
- const observeSpy = jest.fn();
16
- const disconnectSpy = jest.fn();
17
- let overflowShadowsObserver: OverflowShadowsObserver;
18
-
19
- const mockObserver = new MockIntersectionObserver();
20
-
21
- beforeEach(() => {
22
- overflowShadowsObserver = new OverflowShadowsObserver(
23
- updateSpy,
24
- table,
25
- wrapper,
26
- );
27
- });
28
-
29
- afterEach(() => {
30
- jest.clearAllMocks();
31
- });
32
-
33
- beforeAll(() => {
34
- buildTable();
35
- mockObserver.setup({ observe: observeSpy, disconnect: disconnectSpy });
36
- });
37
-
38
- afterAll(() => {
39
- mockObserver.cleanup();
40
- });
41
-
42
- it('observes on first and last table cells', () => {
43
- overflowShadowsObserver.observeShadowSentinels();
44
- expect(observeSpy).toHaveBeenCalledWith(shadowSentinelLeft);
45
- expect(observeSpy).toHaveBeenCalledWith(shadowSentinelRight);
46
- });
47
-
48
- it('does not re-observe if shadow sentinels are already observed', () => {
49
- overflowShadowsObserver.observeShadowSentinels();
50
- observeSpy.mockClear();
51
- overflowShadowsObserver.observeShadowSentinels();
52
- expect(observeSpy).not.toHaveBeenCalled();
53
- });
54
-
55
- it('disconnects intersection observer on dispose', () => {
56
- const overflowShadowsObserver = new OverflowShadowsObserver(
57
- updateSpy,
58
- table,
59
- wrapper,
60
- );
61
- overflowShadowsObserver.dispose();
62
- expect(disconnectSpy).toHaveBeenCalled();
63
- });
64
-
65
- describe('calls the provided update function when intersecting', () => {
66
- beforeEach(() => {
67
- overflowShadowsObserver.observeShadowSentinels();
68
- });
69
-
70
- it.each([
71
- [
72
- 'hides first shadow when first cell fully intersects',
73
- {
74
- getTarget: () => shadowSentinelLeft,
75
- intersectionRatio: 1,
76
- isIntersecting: true,
77
- expectedShadow: ShadowEvent.SHOW_BEFORE_SHADOW,
78
- expectedShow: false,
79
- },
80
- ],
81
- [
82
- 'hides last shadow when last cell fully intersects',
83
- {
84
- getTarget: () => shadowSentinelRight,
85
- intersectionRatio: 1,
86
- isIntersecting: true,
87
- expectedShadow: ShadowEvent.SHOW_AFTER_SHADOW,
88
- expectedShow: false,
89
- },
90
- ],
91
- [
92
- 'shows first shadow when first cell partially intersects',
93
- {
94
- getTarget: () => shadowSentinelLeft,
95
- intersectionRatio: 0,
96
- isIntersecting: true,
97
- expectedShadow: ShadowEvent.SHOW_BEFORE_SHADOW,
98
- expectedShow: true,
99
- },
100
- ],
101
- [
102
- 'shows last shadow when last cell partially intersects',
103
- {
104
- getTarget: () => shadowSentinelRight,
105
- intersectionRatio: 0,
106
- isIntersecting: true,
107
- expectedShadow: ShadowEvent.SHOW_AFTER_SHADOW,
108
- expectedShow: true,
109
- },
110
- ],
111
- ])(
112
- '%s',
113
- (
114
- _name,
115
- {
116
- getTarget,
117
- intersectionRatio,
118
- isIntersecting,
119
- expectedShadow,
120
- expectedShow,
121
- },
122
- ) => {
123
- mockObserver.triggerIntersect({
124
- boundingClientRect: {
125
- height: 10,
126
- width: 10,
127
- },
128
- rootBounds: {
129
- height: 100,
130
- width: 100,
131
- },
132
- intersectionRatio,
133
- target: getTarget(),
134
- isIntersecting,
135
- });
136
- expect(updateSpy).toHaveBeenCalledWith(expectedShadow, expectedShow);
137
- },
138
- );
139
- });
140
-
141
- // helpers
142
-
143
- function buildTable() {
144
- wrapper = document.createElement('div');
145
- table = document.createElement('table');
146
- shadowSentinelLeft = document.createElement('div');
147
- shadowSentinelLeft.className = className.TABLE_SHADOW_SENTINEL_LEFT;
148
- shadowSentinelRight = document.createElement('div');
149
- shadowSentinelRight.className = className.TABLE_SHADOW_SENTINEL_RIGHT;
150
- table.prepend(shadowSentinelLeft);
151
- table.prepend(shadowSentinelRight);
152
- wrapper.appendChild(table);
153
- const tbody = document.createElement('tbody');
154
- table.appendChild(tbody);
155
- const tr = document.createElement('tr');
156
- tbody.appendChild(tr);
157
- td1 = document.createElement('td');
158
- td2 = document.createElement('td');
159
- tr.appendChild(td1);
160
- tr.appendChild(td2);
161
- }
162
- });
@@ -1,280 +0,0 @@
1
- import React from 'react';
2
-
3
- import { render } from '@testing-library/react';
4
- import { replaceRaf } from 'raf-stub';
5
-
6
- import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
7
- import type { Command, DocBuilder } from '@atlaskit/editor-common/types';
8
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
9
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
10
- import {
11
- findTable,
12
- findTableClosestToPos,
13
- selectTable,
14
- selectTableClosestToPos,
15
- } from '@atlaskit/editor-tables/utils';
16
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
17
- import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-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
- thEmpty,
27
- tr,
28
- } from '@atlaskit/editor-test-helpers/doc-builder';
29
-
30
- import * as commands from '../../../commands';
31
- import { hoverTable, toggleNumberColumn } from '../../../commands';
32
- import TableComponent from '../../../nodeviews/TableComponent';
33
- import tablePlugin from '../../../plugin';
34
- import { pluginKey } from '../../../pm-plugins/plugin-key';
35
- import type { TablePluginState } from '../../../types';
36
- import { TableCssClassName as ClassName } from '../../../types';
37
-
38
- jest.mock('../../../utils/nodes', () =>
39
- Object.assign({}, jest.requireActual('../../../utils/nodes'), {
40
- tablesHaveDifferentColumnWidths: jest.fn(),
41
- }),
42
- );
43
-
44
- jest.mock('../../../commands', () =>
45
- Object.assign({}, jest.requireActual('../../../commands'), {
46
- clearHoverSelection: jest.fn(),
47
- }),
48
- );
49
-
50
- replaceRaf();
51
- const requestAnimationFrame = window.requestAnimationFrame as any;
52
-
53
- describe('table -> nodeviews -> TableComponent.tsx', () => {
54
- const createEditor = createEditorFactory<TablePluginState>();
55
- const getEditorFeatureFlags = jest.fn();
56
- const editor = (
57
- doc: DocBuilder,
58
- featureFlags?: { [featureFlag: string]: string | boolean },
59
- ) => {
60
- getEditorFeatureFlags.mockReturnValue(featureFlags || {});
61
- return createEditor({
62
- doc,
63
- editorProps: {
64
- allowTables: false,
65
- dangerouslyAppendPlugins: {
66
- __plugins: [tablePlugin({ config: undefined })],
67
- },
68
- featureFlags,
69
- },
70
- pluginKey,
71
- });
72
- };
73
- const getTableComponent = (editorView: EditorView, props: any = {}) => {
74
- const tableF = findTable(editorView.state.selection);
75
- const getNode = () => tableF!.node;
76
- return (
77
- <TableComponent
78
- view={editorView}
79
- eventDispatcher={
80
- { on: () => {}, off: () => {} } as any as EventDispatcher
81
- }
82
- // @ts-ignore
83
- containerWidth={{}}
84
- // @ts-ignore
85
- getNode={getNode}
86
- getEditorFeatureFlags={getEditorFeatureFlags}
87
- allowControls
88
- contentDOM={(wrapper: HTMLElement | null) => {
89
- const node = editorView.dom.getElementsByTagName('table')[0];
90
- if (!wrapper?.firstChild) {
91
- wrapper?.appendChild(node);
92
- }
93
- }}
94
- getPos={jest.fn()}
95
- {...props}
96
- />
97
- );
98
- };
99
-
100
- afterEach(() => {
101
- jest.clearAllMocks();
102
- });
103
-
104
- describe('when a table is selected', () => {
105
- it('should add table selected css class to the selected table', () => {
106
- const { editorView } = editor(
107
- doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdCursor))),
108
- );
109
- const { state, dispatch } = editorView;
110
- dispatch(selectTable(state.tr));
111
- const { container } = render(getTableComponent(editorView));
112
- const tableContainer = container.querySelector(
113
- `.${ClassName.TABLE_CONTAINER}`,
114
- );
115
- expect(
116
- tableContainer!.classList.contains(ClassName.TABLE_SELECTED),
117
- ).toBeTruthy();
118
- });
119
-
120
- it('should not clear the editor state hover selection when changing selection to another table', () => {
121
- const clearHoverSelectionSpy = jest
122
- .spyOn(commands, 'clearHoverSelection')
123
- .mockImplementation(() => (() => {}) as any as Command);
124
-
125
- const { editorView } = editor(
126
- doc(
127
- p('text'),
128
- table()(tr(thEmpty, thEmpty, thEmpty)),
129
- table()(tr(thEmpty, thEmpty, thEmpty)),
130
- ),
131
- );
132
- const { state, dispatch } = editorView;
133
-
134
- const isInDanger = true;
135
- hoverTable(isInDanger)(state, dispatch);
136
-
137
- const selectSecondTableTr = selectTableClosestToPos(
138
- state.tr,
139
- state.doc.resolve(26),
140
- );
141
- dispatch(selectSecondTableTr);
142
- const secondTable = findTableClosestToPos(state.doc.resolve(26));
143
-
144
- const selectFirstTableTr = selectTableClosestToPos(
145
- state.tr,
146
- state.doc.resolve(8),
147
- );
148
- dispatch(selectFirstTableTr);
149
- const firstTable = findTableClosestToPos(state.doc.resolve(8));
150
-
151
- const getTableNode = (index: number) => () =>
152
- index === 1 ? firstTable!.node : secondTable!.node;
153
-
154
- render(
155
- <div>
156
- {getTableComponent(editorView, {
157
- getNode: getTableNode(1),
158
- })}
159
- {getTableComponent(editorView, {
160
- getNode: getTableNode(2),
161
- })}
162
- </div>,
163
- );
164
- expect(clearHoverSelectionSpy).not.toBeCalled();
165
- });
166
- });
167
-
168
- describe('when there are no tables in selection', () => {
169
- it('clears the editor state hover selection if the editor state is in danger flag is set', () => {
170
- const clearHoverSelectionSpy = jest
171
- .spyOn(commands, 'clearHoverSelection')
172
- .mockImplementation(() => (() => {}) as any as Command);
173
-
174
- const { editorView } = editor(
175
- doc(p('text'), table()(tr(thEmpty, thEmpty, thEmpty))),
176
- );
177
-
178
- const { state, dispatch } = editorView;
179
- const isInDanger = true;
180
- hoverTable(isInDanger)(state, dispatch);
181
- dispatch(selectTable(state.tr));
182
-
183
- const tableF = findTable(state.selection);
184
- const getNode = () => tableF!.node;
185
-
186
- const { rerender } = render(
187
- getTableComponent(editorView, {
188
- getNode,
189
- }),
190
- );
191
-
192
- const newTr = state.tr.setSelection(TextSelection.create(state.doc, 0));
193
- dispatch(newTr);
194
-
195
- rerender(
196
- getTableComponent(editorView, {
197
- getNode,
198
- }),
199
- );
200
- expect(clearHoverSelectionSpy).toBeCalledTimes(1);
201
- });
202
- });
203
-
204
- describe('when the numbered column attribute is changed', () => {
205
- it('should not resize the columns', () => {
206
- const { editorView } = editor(
207
- doc(
208
- table({ isNumberColumnEnabled: false, layout: 'default' })(
209
- tr(
210
- td({ colwidth: [1400] })(p('{<>}')),
211
- td({ colwidth: [48] })(p()),
212
- td({ colwidth: [48] })(p()),
213
- ),
214
- ),
215
- ),
216
- );
217
- const { state, dispatch } = editorView;
218
- const tableCell = state.schema.nodes.tableCell;
219
- const columnWidths: number[][] = [];
220
-
221
- toggleNumberColumn(state, dispatch);
222
- requestAnimationFrame.step();
223
-
224
- editorView.state.doc.nodesBetween(3, 14, (node) => {
225
- if (node.type === tableCell) {
226
- columnWidths.push(node.attrs.colwidth);
227
- }
228
-
229
- return node.type !== tableCell;
230
- });
231
-
232
- expect(columnWidths).toEqual([[1400], [48], [48]]);
233
- });
234
- });
235
-
236
- describe('WITH_CONTROLS css class', () => {
237
- it.each<[string, object, boolean]>([
238
- [
239
- 'is added when allowControls is set',
240
- {
241
- allowControls: true,
242
- tableActive: true,
243
- },
244
- true,
245
- ],
246
- [
247
- 'is added by default when allowControls is not provided',
248
- {
249
- tableActive: true,
250
- },
251
- true,
252
- ],
253
- [
254
- 'is not added when allowControls is false',
255
- {
256
- allowControls: false,
257
- tableActive: true,
258
- },
259
- false,
260
- ],
261
- [
262
- 'is not added when table is not active',
263
- {
264
- allowControls: true,
265
- tableActive: false,
266
- },
267
- false,
268
- ],
269
- ])('%s', (_, props, expected) => {
270
- const { editorView: view } = editor(
271
- doc(p('text'), table()(tr(td()(p('{<>}text')), tdEmpty, tdEmpty))),
272
- );
273
- const { container } = render(getTableComponent(view, props));
274
- const controlsContainer = container.querySelector(
275
- `.${ClassName.WITH_CONTROLS}`,
276
- );
277
- expect(!!controlsContainer).toBe(expected);
278
- });
279
- });
280
- });