@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,118 +0,0 @@
1
- import React from 'react';
2
-
3
- import { render, screen } from '@testing-library/react';
4
- import { IntlProvider } from 'react-intl-next';
5
-
6
- import type { DocBuilder } from '@atlaskit/editor-common/types';
7
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
8
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
9
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
10
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
11
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
12
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
13
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
14
- import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
15
- // eslint-disable-next-line import/no-extraneous-dependencies
16
- import type { LightEditorPlugin } 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
- createProsemirrorEditorFactory,
20
- Preset,
21
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
22
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
23
- import {
24
- doc,
25
- p,
26
- table,
27
- tdCursor,
28
- tdEmpty,
29
- tr,
30
- } from '@atlaskit/editor-test-helpers/doc-builder';
31
-
32
- import { hoverTable } from '../../../commands';
33
- import tablePlugin from '../../../plugin';
34
- import { getDecorations } from '../../../pm-plugins/decorations/plugin';
35
- import { pluginKey } from '../../../pm-plugins/plugin-key';
36
- import type { TablePluginState } from '../../../types';
37
- import TableFloatingControls from '../../../ui/TableFloatingControls';
38
-
39
- describe('TableFloatingControls', () => {
40
- const createEditor = createProsemirrorEditorFactory();
41
-
42
- const preset = new Preset<LightEditorPlugin>()
43
- .add([featureFlagsPlugin, {}])
44
- .add([analyticsPlugin, {}])
45
- .add(contentInsertionPlugin)
46
- .add(widthPlugin)
47
- .add(guidelinePlugin)
48
- .add(selectionPlugin)
49
- .add([
50
- tablePlugin,
51
- { tableOptions: { advanced: true }, dragAndDropEnabled: false },
52
- ]);
53
-
54
- const editor = (doc: DocBuilder) =>
55
- createEditor<TablePluginState, PluginKey, typeof preset>({
56
- doc,
57
- preset,
58
- pluginKey: pluginKey,
59
- });
60
-
61
- describe('when tableRef is undefined', () => {
62
- it('should not render table header', () => {
63
- const { editorView } = editor(
64
- doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
65
- );
66
- const { container } = render(
67
- <TableFloatingControls
68
- editorView={editorView}
69
- isDragAndDropEnabled={false}
70
- />,
71
- );
72
- expect(container.innerHTML).toEqual('');
73
- });
74
- });
75
-
76
- describe('when tableRef is defined', () => {
77
- it('should render CornerControls and RowControls', () => {
78
- const { editorView } = editor(
79
- doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
80
- );
81
- const ref = editorView.dom.querySelector('table') || undefined;
82
-
83
- render(
84
- <IntlProvider locale="en">
85
- <TableFloatingControls
86
- tableRef={ref}
87
- tableActive={true}
88
- editorView={editorView}
89
- isDragAndDropEnabled={false}
90
- selection={editorView.state.selection}
91
- />
92
- </IntlProvider>,
93
- );
94
-
95
- expect(screen.getByLabelText('Highlight row')).toBeTruthy();
96
- expect(screen.getByLabelText('Highlight table')).toBeTruthy();
97
- });
98
- });
99
-
100
- describe('when delete icon is hovered', () => {
101
- it('should add a node decoration to table nodeView with class="danger"', () => {
102
- const { editorView } = editor(
103
- doc(
104
- p('text'),
105
- table()(
106
- tr(tdCursor, tdEmpty),
107
- tr(tdEmpty, tdEmpty),
108
- tr(tdEmpty, tdEmpty),
109
- ),
110
- ),
111
- );
112
- hoverTable(true)(editorView.state, editorView.dispatch);
113
- const decorationSet = getDecorations(editorView.state);
114
- const decoration = decorationSet.find()[0] as any;
115
- expect(decoration.type.attrs.class.indexOf('danger')).toBeGreaterThan(-1);
116
- });
117
- });
118
- });
@@ -1,220 +0,0 @@
1
- import clone from 'lodash/clone';
2
-
3
- import type { DocBuilder } from '@atlaskit/editor-common/types';
4
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
5
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
6
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
7
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
8
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
9
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
10
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
11
- import { redo, undo } from '@atlaskit/editor-prosemirror/history';
12
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
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
- tdCursor,
27
- tdEmpty,
28
- th,
29
- thEmpty,
30
- tr,
31
- } from '@atlaskit/editor-test-helpers/doc-builder';
32
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
33
- import sendKeyToPm from '@atlaskit/editor-test-helpers/send-key-to-pm';
34
-
35
- import { insertColumn } from '../../commands';
36
- import tablePlugin from '../../plugin';
37
- import { pluginKey as tablePluginKey } from '../../pm-plugins/plugin-key';
38
- import { deleteColumns } from '../../transforms';
39
- import { colsToRect } from '../../utils/table';
40
-
41
- const TABLE_LOCAL_ID = 'test-table-local-id';
42
-
43
- const getEditorContainerWidth = () => {
44
- return {
45
- width: 500,
46
- };
47
- };
48
- // HELPERS
49
- const INSERT_COLUMN = (editorView: EditorView) =>
50
- insertColumn(getEditorContainerWidth)(1)(
51
- editorView.state,
52
- editorView.dispatch,
53
- editorView,
54
- );
55
- const DELETE_COLUMN = (editorView: EditorView) => {
56
- const { state, dispatch } = editorView;
57
- dispatch(deleteColumns(colsToRect([0], 1), true, editorView)(state.tr));
58
- };
59
- const SHORTCUT_ADD_COLUMN_BEFORE = (editorView: EditorView) =>
60
- sendKeyToPm(editorView, 'Ctrl-Alt-ArrowLeft');
61
- const SHORTCUT_ADD_COLUMN_AFTER = (editorView: EditorView) =>
62
- sendKeyToPm(editorView, 'Ctrl-Alt-ArrowRight');
63
-
64
- describe('undo/redo with tables', () => {
65
- const createEditor = createProsemirrorEditorFactory();
66
- const editor = (doc: DocBuilder) => {
67
- const tableOptions = {
68
- advanced: true,
69
- allowColumnSorting: true,
70
- };
71
- return createEditor({
72
- doc,
73
- preset: new Preset<LightEditorPlugin>()
74
- .add([featureFlagsPlugin, {}])
75
- .add([analyticsPlugin, {}])
76
- .add(contentInsertionPlugin)
77
- .add(widthPlugin)
78
- .add(guidelinePlugin)
79
- .add(selectionPlugin)
80
- .add([tablePlugin, { tableOptions }]),
81
- pluginKey: tablePluginKey,
82
- });
83
- };
84
- type TestCase = [
85
- string,
86
- {
87
- before: DocBuilder;
88
- action: Function;
89
- },
90
- ];
91
-
92
- const case01: TestCase = [
93
- 'when table has colwidth attribute and new col has been inserted',
94
- {
95
- before: doc(
96
- table({
97
- localId: TABLE_LOCAL_ID,
98
- })(tr(th({ colwidth: [285] })(p('')), th({ colwidth: [1310] })(p('')))),
99
- ),
100
- action: INSERT_COLUMN,
101
- },
102
- ];
103
-
104
- const case02: TestCase = [
105
- 'when table has colwidth attribute and deleting a col',
106
- {
107
- before: doc(
108
- table({
109
- localId: TABLE_LOCAL_ID,
110
- })(tr(th({ colwidth: [285] })(p('')), th({ colwidth: [1310] })(p('')))),
111
- ),
112
- action: DELETE_COLUMN,
113
- },
114
- ];
115
-
116
- const case03: TestCase = [
117
- 'when table has no colwidth attribute and new col is inserted',
118
- {
119
- before: doc(
120
- table({
121
- localId: TABLE_LOCAL_ID,
122
- })(tr(thEmpty, thEmpty)),
123
- ),
124
- action: INSERT_COLUMN,
125
- },
126
- ];
127
-
128
- const case04: TestCase = [
129
- 'when table has no colwidth attribute and col is deleted',
130
- {
131
- before: doc(
132
- table({
133
- localId: TABLE_LOCAL_ID,
134
- })(tr(thEmpty, thEmpty)),
135
- ),
136
- action: DELETE_COLUMN,
137
- },
138
- ];
139
-
140
- const case05: TestCase = [
141
- 'when table has colwidth attribute and col is inserted after selection via shortcuts',
142
- {
143
- before: doc(
144
- table({
145
- localId: TABLE_LOCAL_ID,
146
- })(
147
- tr(
148
- td({ colwidth: [194] })(p('{<>}')),
149
- td({ colwidth: [564] })(p('')),
150
- ),
151
- ),
152
- ),
153
- action: SHORTCUT_ADD_COLUMN_AFTER,
154
- },
155
- ];
156
-
157
- const case06: TestCase = [
158
- 'when table has colwidth attribute and col is inserted before selection via shortcuts',
159
- {
160
- before: doc(
161
- table({
162
- localId: TABLE_LOCAL_ID,
163
- })(
164
- tr(
165
- td({ colwidth: [194] })(p('{<>}')),
166
- td({ colwidth: [564] })(p('')),
167
- ),
168
- ),
169
- ),
170
- action: SHORTCUT_ADD_COLUMN_BEFORE,
171
- },
172
- ];
173
-
174
- const case07: TestCase = [
175
- 'when table has no colwidth attribute and col is inserted before selection via shortcuts',
176
- {
177
- before: doc(
178
- table({
179
- localId: TABLE_LOCAL_ID,
180
- })(tr(tdCursor, tdEmpty)),
181
- ),
182
- action: SHORTCUT_ADD_COLUMN_BEFORE,
183
- },
184
- ];
185
-
186
- const case08: TestCase = [
187
- 'when table has no colwidth attribute and col is inserted after selection via shortcuts',
188
- {
189
- before: doc(
190
- table({
191
- localId: TABLE_LOCAL_ID,
192
- })(tr(tdCursor, tdEmpty)),
193
- ),
194
- action: SHORTCUT_ADD_COLUMN_BEFORE,
195
- },
196
- ];
197
-
198
- describe.each<TestCase>([
199
- case01,
200
- case02,
201
- case03,
202
- case04,
203
- case05,
204
- case06,
205
- case07,
206
- case08,
207
- ])('[case%#] %s', (_description, testCase) => {
208
- it('should be able to undo/redo', () => {
209
- const { editorView } = editor(testCase.before);
210
- const docAtStart = clone(editorView.state.doc);
211
- testCase.action(editorView);
212
- expect(editorView.state.doc).not.toEqualDocument(docAtStart);
213
- const docAfterAction = clone(editorView.state.doc);
214
- undo(editorView.state, editorView.dispatch);
215
- expect(editorView.state.doc).toEqualDocument(docAtStart);
216
- redo(editorView.state, editorView.dispatch);
217
- expect(editorView.state.doc).toEqualDocument(docAfterAction);
218
- });
219
- });
220
- });
@@ -1,98 +0,0 @@
1
- import { renderHook } from '@testing-library/react-hooks';
2
-
3
- import {
4
- ACTION_SUBJECT,
5
- EVENT_TYPE,
6
- TABLE_ACTION,
7
- } from '@atlaskit/editor-common/analytics';
8
-
9
- import {
10
- generateResizeFrameRatePayloads,
11
- reduceResizeFrameRateSamples,
12
- useMeasureFramerate,
13
- } from '../../../utils/analytics';
14
-
15
- describe('reduceResizeFrameRateSamples()', () => {
16
- it('should return the same array if it has only one element', () => {
17
- expect(reduceResizeFrameRateSamples([1])).toEqual([1]);
18
- });
19
-
20
- it('should return the first element and the average of the array if length > 1', () => {
21
- expect(reduceResizeFrameRateSamples([3, 2, 4, 6])).toEqual([3, 4]);
22
- });
23
- });
24
-
25
- describe('generateResizeFrameRatePayloads()', () => {
26
- it('should return an empty array if the array is empty', () => {
27
- expect(
28
- generateResizeFrameRatePayloads({
29
- docSize: 10,
30
- frameRateSamples: [],
31
- originalNode: { nodeSize: 5 } as any,
32
- }),
33
- ).toEqual([]);
34
- });
35
-
36
- it('should return an array of payloads with the correct attributes', () => {
37
- expect(
38
- generateResizeFrameRatePayloads({
39
- docSize: 10,
40
- frameRateSamples: [3, 2, 4, 6],
41
- originalNode: { nodeSize: 5 } as any,
42
- }),
43
- ).toEqual([
44
- {
45
- action: TABLE_ACTION.RESIZE_PERF_SAMPLING,
46
- actionSubject: ACTION_SUBJECT.TABLE,
47
- eventType: EVENT_TYPE.OPERATIONAL,
48
- attributes: {
49
- frameRate: 3,
50
- nodeSize: 5,
51
- docSize: 10,
52
- isInitialSample: true,
53
- },
54
- },
55
- {
56
- action: TABLE_ACTION.RESIZE_PERF_SAMPLING,
57
- actionSubject: ACTION_SUBJECT.TABLE,
58
- eventType: EVENT_TYPE.OPERATIONAL,
59
- attributes: {
60
- frameRate: 4,
61
- nodeSize: 5,
62
- docSize: 10,
63
- isInitialSample: false,
64
- },
65
- },
66
- ]);
67
- });
68
- });
69
-
70
- describe('useMeasureFramerate()', () => {
71
- jest.useFakeTimers('modern');
72
-
73
- it('should return the correct handlers', () => {
74
- const { result } = renderHook(() => useMeasureFramerate());
75
- const { startMeasure, endMeasure, countFrames } = result.current;
76
-
77
- expect(startMeasure).toBeInstanceOf(Function);
78
- expect(endMeasure).toBeInstanceOf(Function);
79
- expect(countFrames).toBeInstanceOf(Function);
80
- });
81
-
82
- it('should return the correct frame rate sample', async () => {
83
- const { result } = renderHook(() =>
84
- useMeasureFramerate({ minTimeMs: 0, minFrames: 0, sampleRateMs: 0 }),
85
- );
86
-
87
- const { startMeasure, endMeasure, countFrames } = result.current;
88
- jest.advanceTimersByTime(100);
89
- startMeasure();
90
- jest.advanceTimersByTime(100);
91
- countFrames();
92
- const samples = endMeasure();
93
-
94
- expect(samples).toEqual([10]);
95
-
96
- jest.useRealTimers();
97
- });
98
- });
@@ -1,57 +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
- table,
20
- tdEmpty,
21
- tr,
22
- } from '@atlaskit/editor-test-helpers/doc-builder';
23
-
24
- import tablePlugin from '../../../plugin';
25
- import { isTableCollapsible } from '../../../utils/collapse';
26
-
27
- describe('collapse', () => {
28
- const createEditor = createProsemirrorEditorFactory();
29
-
30
- const editor = (doc: DocBuilder) => {
31
- const preset = new Preset<LightEditorPlugin>()
32
- .add([featureFlagsPlugin, {}])
33
- .add([analyticsPlugin, {}])
34
- .add(contentInsertionPlugin)
35
- .add(widthPlugin)
36
- .add(guidelinePlugin)
37
- .add(selectionPlugin)
38
- .add(tablePlugin);
39
-
40
- return createEditor({ doc, preset });
41
- };
42
-
43
- describe('isTableCollapsible', () => {
44
- it('should not mutate a transaction when using isTableCollapsible', () => {
45
- const editorData = editor(doc(table()(tr(tdEmpty, tdEmpty))));
46
- const editorView = editorData.editorView;
47
- const newTr = editorView.state.tr;
48
-
49
- expect(newTr.steps.length).toEqual(0);
50
-
51
- const isTableCollapsibleRes = isTableCollapsible(newTr);
52
-
53
- expect(newTr.steps.length).toEqual(0);
54
- expect(isTableCollapsibleRes.tableIsCollapsible).toEqual(false);
55
- });
56
- });
57
- });
@@ -1,205 +0,0 @@
1
- import type { TableMap } from '@atlaskit/editor-tables';
2
-
3
- import {
4
- colWidthsForRow,
5
- convertHTMLCellIndexToColumnIndex,
6
- getColumnIndexMappedToColumnIndexInFirstRow,
7
- } from '../../../utils/column-controls';
8
-
9
- const createRow = (colCount: number, childType = 'td') => {
10
- const tr = document.createElement('tr');
11
- for (let i = 0; i < colCount; i++) {
12
- const child = document.createElement(childType);
13
- child.innerText = `Cell ${i}`;
14
- tr.appendChild(child);
15
- }
16
-
17
- return tr;
18
- };
19
-
20
- describe('table utilities', () => {
21
- let table: HTMLTableElement;
22
- let tbody: HTMLElement;
23
- let colgroup: HTMLTableColElement;
24
-
25
- beforeEach(() => {
26
- table = document.createElement('table');
27
-
28
- tbody = document.createElement('tbody');
29
- table.appendChild(tbody);
30
-
31
- colgroup = document.createElement('colgroup');
32
- table.appendChild(colgroup);
33
- });
34
-
35
- afterEach(() => {
36
- table.remove();
37
- });
38
-
39
- describe('pctWidthsForRow', () => {
40
- it('returns nothing for an empty table and empty row', () => {
41
- expect(colWidthsForRow(createRow(0))).toEqual('');
42
- });
43
-
44
- describe('unresized table/no colgroup', () => {
45
- it('returns 100% for single cell', () => {
46
- expect(colWidthsForRow(createRow(1))).toEqual('100%');
47
- });
48
-
49
- it('returns split 50% for two cells', () => {
50
- expect(colWidthsForRow(createRow(2))).toEqual('50% 50%');
51
- });
52
-
53
- it('works for merged cells', () => {
54
- const rowWithColspan = createRow(2);
55
-
56
- // first column should spans 3
57
- rowWithColspan.children[0].setAttribute('colspan', '3');
58
-
59
- // last row should still span 1 row
60
- // giving 4 visual rows, and only 2 in DOM
61
-
62
- // colgroup is still empty
63
- expect(colWidthsForRow(rowWithColspan)).toEqual('75% 25%');
64
- });
65
- });
66
- });
67
- });
68
-
69
- describe('table utilities - convertHTMLCellIndexToColumnIndex', () => {
70
- /*
71
- Table looks like this:
72
- ___ _______ ___ ___ ___
73
- |___| |_A_|___|___|
74
- |___| |___| |___|
75
- |___|_______|_B_| |___|
76
- |___|___|___|___| |___|
77
- |___________|___|___|___|
78
- |___________|___|_C_|___|
79
- |___________|___|___|___|
80
- |___|___|___|_D_|___|___|
81
- |___|___|_E_____________|
82
- */
83
- const tableMap = {
84
- width: 6,
85
- height: 9,
86
- map: [
87
- 1, 5, 5, 9, 13, 17, 23, 5, 5, 27, 31, 35, 41, 5, 5, 45, 31, 49, 55, 59,
88
- 63, 67, 31, 71, 77, 77, 77, 81, 31, 85, 91, 91, 91, 95, 99, 103, 109, 109,
89
- 109, 113, 117, 121, 127, 131, 135, 139, 143, 147, 153, 157, 161, 161, 161,
90
- 161,
91
- ],
92
- } as TableMap;
93
-
94
- const testCases = [
95
- [
96
- 'case A: when hovered cell is in the first row and first row has merged cells',
97
- 2, // htmlColIndex
98
- 0, // htmlRowIndex
99
- 3, // expected
100
- ],
101
- [
102
- 'case B: when hoverd cell is not in the first row, but the row has merged cells',
103
- 1,
104
- 2,
105
- 3,
106
- ],
107
- [
108
- 'case C: when a cell that is in the row above and to the left of current cell is merged',
109
- 3,
110
- 5,
111
- 5,
112
- ],
113
- [
114
- 'case D: when first row has merged cell and hovered cell is below merged area',
115
- 2,
116
- 7,
117
- 2,
118
- ],
119
- [
120
- 'case E: when first row has merged cell and hovered cell is below merged area and is part of merged area',
121
- 2,
122
- 8,
123
- 2,
124
- ],
125
- ];
126
-
127
- describe('should convert cellIndex into colIndex correctly', () => {
128
- test.each(testCases)(
129
- '%s',
130
- (message, htmlColIndex, htmlRowIndex, expected) => {
131
- expect(
132
- convertHTMLCellIndexToColumnIndex(
133
- htmlColIndex as number,
134
- htmlRowIndex as number,
135
- tableMap,
136
- ),
137
- ).toEqual(expected);
138
- },
139
- );
140
- });
141
- });
142
-
143
- describe('tableUtilities - getColumnIndexMappedToColumnIndexInFirstRow', () => {
144
- /*
145
- Table used for this tests looks like this:
146
- ___ _______ ___ ___ ___ ___ ___ ___________ ___
147
- |___|_______|___|___|___|___|___|___________|_D_|
148
- |___|_A_|_B_|___|___|___|___|___|___|_E_|___|___|
149
- |___|___|_______|___|_____C_|___|___|___|___|___|
150
- |___|___|___|___|___|___|___|___|___|___|___|___|
151
- */
152
-
153
- const tableMap = {
154
- width: 12,
155
- height: 4,
156
- map: [
157
- 1, 5, 5, 9, 13, 17, 21, 25, 29, 29, 29, 33, 39, 43, 47, 51, 55, 59, 63,
158
- 67, 71, 75, 79, 83, 89, 93, 97, 97, 101, 105, 105, 109, 113, 117, 121,
159
- 125, 131, 135, 139, 143, 147, 151, 155, 159, 163, 167, 171, 175,
160
- ],
161
- } as TableMap;
162
-
163
- const testCases = [
164
- [
165
- 'case A: mouse is on a cell located below merged area of the first row closer to its start',
166
- 2, // convertedColIndex
167
- 1, // htmlRowIndex
168
- 1, // expected
169
- ],
170
- [
171
- 'case B: mouse is on a cell located below merged area of the first row close to its end',
172
- 1,
173
- 1,
174
- 1,
175
- ],
176
- [
177
- 'case E: mouse is on a cell located below merged area of the first row in the middle of the merged area',
178
- 9,
179
- 1,
180
- 8,
181
- ],
182
- ['case C: mouse is on a merged cell located below the first row', 5, 2, 5],
183
- [
184
- 'case D: mouse is on a cell in the first row that is next to a merged cell',
185
- 11,
186
- 1,
187
- 11,
188
- ],
189
- ];
190
-
191
- describe('should adapt converted colIndex when first row has merged cells', () => {
192
- test.each(testCases)(
193
- '%s',
194
- (message, convertedColIndex, htmlRowIndex, expected) => {
195
- expect(
196
- getColumnIndexMappedToColumnIndexInFirstRow(
197
- convertedColIndex as number,
198
- htmlRowIndex as number,
199
- tableMap,
200
- ),
201
- ).toEqual(expected);
202
- },
203
- );
204
- });
205
- });