@atlaskit/editor-plugin-table 7.2.2 → 7.3.0
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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/commands/column-resize.js +115 -45
- package/dist/cjs/commands/go-to-next-cell.js +7 -11
- package/dist/cjs/commands/misc.js +3 -2
- package/dist/cjs/commands/selection.js +3 -3
- package/dist/cjs/event-handlers.js +38 -25
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
- package/dist/cjs/pm-plugins/keymap.js +1 -0
- package/dist/cjs/pm-plugins/main.js +43 -9
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
- package/dist/cjs/reducer.js +5 -2
- package/dist/cjs/utils/drag-menu.js +37 -23
- package/dist/cjs/utils/merged-cells.js +66 -1
- package/dist/es2019/commands/column-resize.js +100 -35
- package/dist/es2019/commands/go-to-next-cell.js +7 -9
- package/dist/es2019/commands/misc.js +3 -2
- package/dist/es2019/commands/selection.js +5 -5
- package/dist/es2019/event-handlers.js +17 -3
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/es2019/pm-plugins/keymap.js +3 -2
- package/dist/es2019/pm-plugins/main.js +41 -5
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
- package/dist/es2019/reducer.js +5 -2
- package/dist/es2019/utils/drag-menu.js +38 -14
- package/dist/es2019/utils/merged-cells.js +73 -0
- package/dist/esm/commands/column-resize.js +105 -35
- package/dist/esm/commands/go-to-next-cell.js +7 -11
- package/dist/esm/commands/misc.js +3 -2
- package/dist/esm/commands/selection.js +5 -5
- package/dist/esm/event-handlers.js +38 -25
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/esm/pm-plugins/keymap.js +3 -2
- package/dist/esm/pm-plugins/main.js +38 -4
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
- package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
- package/dist/esm/reducer.js +5 -2
- package/dist/esm/utils/drag-menu.js +36 -22
- package/dist/esm/utils/merged-cells.js +65 -0
- package/dist/types/commands/column-resize.d.ts +2 -0
- package/dist/types/commands/misc.d.ts +1 -1
- package/dist/types/types.d.ts +16 -0
- package/dist/types/utils/drag-menu.d.ts +4 -1
- package/dist/types/utils/merged-cells.d.ts +2 -0
- package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
- package/dist/types-ts4.5/commands/misc.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +16 -0
- package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
- package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
- package/package.json +10 -17
- package/src/commands/column-resize.ts +155 -40
- package/src/commands/go-to-next-cell.ts +6 -15
- package/src/commands/misc.ts +2 -0
- package/src/commands/selection.ts +5 -5
- package/src/event-handlers.ts +21 -4
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
- package/src/pm-plugins/keymap.ts +3 -0
- package/src/pm-plugins/main.ts +47 -2
- package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
- package/src/pm-plugins/table-resizing/plugin.ts +18 -1
- package/src/reducer.ts +5 -2
- package/src/types.ts +16 -0
- package/src/utils/drag-menu.ts +94 -20
- package/src/utils/merged-cells.ts +78 -0
- package/tsconfig.dev.json +0 -69
- package/tsconfig.json +2 -877
- package/examples/99-testing.tsx +0 -140
- package/examples/config.jsonc +0 -14
- package/src/__tests__/unit/analytics.ts +0 -888
- package/src/__tests__/unit/collab.ts +0 -93
- package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
- package/src/__tests__/unit/commands/insert.ts +0 -137
- package/src/__tests__/unit/commands/misc.ts +0 -185
- package/src/__tests__/unit/commands/sort.ts +0 -128
- package/src/__tests__/unit/commands.ts +0 -745
- package/src/__tests__/unit/copy-button.ts +0 -22
- package/src/__tests__/unit/copy-paste.ts +0 -677
- package/src/__tests__/unit/event-handlers/index.ts +0 -125
- package/src/__tests__/unit/event-handlers.ts +0 -296
- package/src/__tests__/unit/fix-tables.ts +0 -164
- package/src/__tests__/unit/get-toolbar-config.ts +0 -127
- package/src/__tests__/unit/handlers.ts +0 -98
- package/src/__tests__/unit/hover-selection.ts +0 -230
- package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
- package/src/__tests__/unit/index.ts +0 -912
- package/src/__tests__/unit/layout.ts +0 -146
- package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
- package/src/__tests__/unit/nodeviews/cell.ts +0 -132
- package/src/__tests__/unit/nodeviews/table.ts +0 -129
- package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
- package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
- package/src/__tests__/unit/pm-plugins/main.ts +0 -214
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
- package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
- package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
- package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
- package/src/__tests__/unit/sort-column.ts +0 -399
- package/src/__tests__/unit/toolbar.ts +0 -512
- package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
- package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
- package/src/__tests__/unit/transforms/merging.ts +0 -392
- package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
- package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
- package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
- package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
- package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
- package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
- package/src/__tests__/unit/ui/RowControls.tsx +0 -294
- package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
- package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
- package/src/__tests__/unit/undo-redo.ts +0 -220
- package/src/__tests__/unit/utils/analytics.ts +0 -98
- package/src/__tests__/unit/utils/collapse.ts +0 -57
- package/src/__tests__/unit/utils/column-controls.ts +0 -205
- package/src/__tests__/unit/utils/dom.ts +0 -180
- package/src/__tests__/unit/utils/merged-cells.ts +0 -156
- package/src/__tests__/unit/utils/nodes.ts +0 -79
- package/src/__tests__/unit/utils/row-controls.ts +0 -195
- package/src/__tests__/unit/utils/table.ts +0 -96
- package/src/__tests__/unit/utils.ts +0 -670
- package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
- package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
- package/src/__tests__/visual-regression/copy-button.ts +0 -181
- package/src/__tests__/visual-regression/index.ts +0 -62
- package/src/__tests__/visual-regression/sticky-header.ts +0 -61
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
2
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
3
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
5
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
6
|
-
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
7
|
-
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
8
|
-
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
9
|
-
import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
10
|
-
// 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
|
-
table,
|
|
21
|
-
tdCursor,
|
|
22
|
-
tdEmpty,
|
|
23
|
-
tr,
|
|
24
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
25
|
-
|
|
26
|
-
import { whenTableInFocus } from '../../../event-handlers';
|
|
27
|
-
import tablePlugin from '../../../plugin';
|
|
28
|
-
import { pluginKey } from '../../../pm-plugins/plugin-key';
|
|
29
|
-
import { setDragging } from '../../../pm-plugins/table-resizing/commands';
|
|
30
|
-
import type { TablePluginState } from '../../../types';
|
|
31
|
-
|
|
32
|
-
describe('event-handlers', () => {
|
|
33
|
-
let editor: any;
|
|
34
|
-
|
|
35
|
-
describe('#whenTableInFocus', () => {
|
|
36
|
-
describe('when allowColumnResizing is false', () => {
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
39
|
-
const preset = new Preset<LightEditorPlugin>()
|
|
40
|
-
.add([featureFlagsPlugin, {}])
|
|
41
|
-
.add([analyticsPlugin, {}])
|
|
42
|
-
.add(contentInsertionPlugin)
|
|
43
|
-
.add(widthPlugin)
|
|
44
|
-
.add(guidelinePlugin)
|
|
45
|
-
.add(selectionPlugin)
|
|
46
|
-
.add([tablePlugin, { tableOptions: { allowColumnResizing: false } }]);
|
|
47
|
-
editor = (doc: DocBuilder) =>
|
|
48
|
-
createEditor<TablePluginState, PluginKey, typeof preset>({
|
|
49
|
-
doc,
|
|
50
|
-
preset,
|
|
51
|
-
pluginKey,
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should not return false', () => {
|
|
56
|
-
const { editorView: view } = editor(
|
|
57
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
58
|
-
);
|
|
59
|
-
const fakeHandler = jest.fn();
|
|
60
|
-
fakeHandler.mockReturnValue(true);
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
const fakeMouseEvent = jest.fn() as Event;
|
|
63
|
-
|
|
64
|
-
const result = whenTableInFocus(fakeHandler);
|
|
65
|
-
|
|
66
|
-
expect(result(view, fakeMouseEvent)).not.toBeFalsy();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('when allowColumnResizing is true', () => {
|
|
71
|
-
beforeEach(() => {
|
|
72
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
73
|
-
const 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: { allowColumnResizing: false } }]);
|
|
81
|
-
editor = (doc: DocBuilder) =>
|
|
82
|
-
createEditor<TablePluginState, PluginKey, typeof preset>({
|
|
83
|
-
doc,
|
|
84
|
-
preset,
|
|
85
|
-
pluginKey,
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('when dragging exists', () => {
|
|
90
|
-
it('should return false', () => {
|
|
91
|
-
const { editorView: view } = editor(
|
|
92
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
93
|
-
);
|
|
94
|
-
const fakeHandler = jest.fn();
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
const fakeMouseEvent = jest.fn() as Event;
|
|
97
|
-
|
|
98
|
-
setDragging({ startX: 0, startWidth: 0 })(view.state, view.dispatch);
|
|
99
|
-
|
|
100
|
-
const result = whenTableInFocus(fakeHandler);
|
|
101
|
-
|
|
102
|
-
expect(result(view, fakeMouseEvent)).toBeFalsy();
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe('when dragging is null', () => {
|
|
107
|
-
it('should not return false', () => {
|
|
108
|
-
const { editorView: view } = editor(
|
|
109
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
110
|
-
);
|
|
111
|
-
const fakeHandler = jest.fn();
|
|
112
|
-
fakeHandler.mockReturnValue(true);
|
|
113
|
-
// @ts-ignore
|
|
114
|
-
const fakeMouseEvent = jest.fn() as Event;
|
|
115
|
-
|
|
116
|
-
setDragging(null)(view.state, view.dispatch);
|
|
117
|
-
|
|
118
|
-
const result = whenTableInFocus(fakeHandler);
|
|
119
|
-
|
|
120
|
-
expect(result(view, fakeMouseEvent)).not.toBeFalsy();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,296 +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 { gridPlugin } from '@atlaskit/editor-plugin-grid';
|
|
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 { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
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
|
-
tdCursor,
|
|
26
|
-
tdEmpty,
|
|
27
|
-
tr,
|
|
28
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
29
|
-
|
|
30
|
-
import {
|
|
31
|
-
addResizeHandleDecorations,
|
|
32
|
-
showInsertColumnButton,
|
|
33
|
-
} from '../../commands';
|
|
34
|
-
import {
|
|
35
|
-
handleMouseDown,
|
|
36
|
-
handleMouseMove,
|
|
37
|
-
handleMouseOut,
|
|
38
|
-
handleMouseOver,
|
|
39
|
-
withCellTracking,
|
|
40
|
-
} from '../../event-handlers';
|
|
41
|
-
import tablePlugin from '../../plugin';
|
|
42
|
-
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
43
|
-
import { pluginKey } from '../../pm-plugins/plugin-key';
|
|
44
|
-
import { TableCssClassName as ClassName } from '../../types';
|
|
45
|
-
|
|
46
|
-
describe('table plugin: decorations', () => {
|
|
47
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
48
|
-
const editor = (doc: DocBuilder) =>
|
|
49
|
-
createEditor({
|
|
50
|
-
doc,
|
|
51
|
-
preset: new Preset<LightEditorPlugin>()
|
|
52
|
-
.add([featureFlagsPlugin, {}])
|
|
53
|
-
.add([analyticsPlugin, {}])
|
|
54
|
-
.add(contentInsertionPlugin)
|
|
55
|
-
.add(widthPlugin)
|
|
56
|
-
.add(guidelinePlugin)
|
|
57
|
-
.add(selectionPlugin)
|
|
58
|
-
.add(tablePlugin),
|
|
59
|
-
pluginKey,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('#handleMouseDown', () => {
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
jest.resetAllMocks();
|
|
65
|
-
});
|
|
66
|
-
it('should return true & prevent default behaviour for table wrappers: pm-table-container', () => {
|
|
67
|
-
const { editorView } = editor(
|
|
68
|
-
doc(table()(tr(td({})(p())), tr(td({})(p())), tr(td({})(p())))),
|
|
69
|
-
);
|
|
70
|
-
const tableContainer = document.createElement('div');
|
|
71
|
-
tableContainer.className = 'pm-table-container';
|
|
72
|
-
const event = new MouseEvent('mousedown');
|
|
73
|
-
Object.defineProperty(event, 'target', { value: tableContainer });
|
|
74
|
-
const preventDefaultSpy = jest.spyOn(
|
|
75
|
-
MouseEvent.prototype,
|
|
76
|
-
'preventDefault',
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
expect(handleMouseDown(editorView, event)).toEqual(true);
|
|
80
|
-
expect(preventDefaultSpy).toHaveBeenCalledTimes(1);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should return true & prevent default behaviour for table wrappers: pm-table-wrapper', () => {
|
|
84
|
-
const { editorView } = editor(
|
|
85
|
-
doc(table()(tr(td({})(p())), tr(td({})(p())), tr(td({})(p())))),
|
|
86
|
-
);
|
|
87
|
-
const tableContainer = document.createElement('div');
|
|
88
|
-
tableContainer.className = 'pm-table-wrapper';
|
|
89
|
-
const event = new MouseEvent('mousedown');
|
|
90
|
-
Object.defineProperty(event, 'target', { value: tableContainer });
|
|
91
|
-
const preventDefaultSpy = jest.spyOn(
|
|
92
|
-
MouseEvent.prototype,
|
|
93
|
-
'preventDefault',
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
expect(handleMouseDown(editorView, event)).toEqual(true);
|
|
97
|
-
expect(preventDefaultSpy).toHaveBeenCalledTimes(1);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should return false & not prevent default behaviour for editor content area: ak-editor-content-area', () => {
|
|
101
|
-
const { editorView } = editor(
|
|
102
|
-
doc(table()(tr(td({})(p())), tr(td({})(p())), tr(td({})(p())))),
|
|
103
|
-
);
|
|
104
|
-
const editorContentArea = document.createElement('div');
|
|
105
|
-
editorContentArea.className = 'ak-editor-content-area';
|
|
106
|
-
const event = new MouseEvent('mousedown');
|
|
107
|
-
Object.defineProperty(event, 'target', { value: editorContentArea });
|
|
108
|
-
const preventDefaultSpy = jest.spyOn(
|
|
109
|
-
MouseEvent.prototype,
|
|
110
|
-
'preventDefault',
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
expect(handleMouseDown(editorView, event)).toEqual(false);
|
|
114
|
-
expect(preventDefaultSpy).toHaveBeenCalledTimes(0);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('#handleMouseOut', () => {
|
|
119
|
-
describe('when the target is a resize handle column', () => {
|
|
120
|
-
it('should return true', () => {
|
|
121
|
-
const { editorView } = editor(
|
|
122
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(td()(p('{o}')), tdEmpty))),
|
|
123
|
-
);
|
|
124
|
-
const firstCell = document.createElement('div');
|
|
125
|
-
firstCell.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
|
|
126
|
-
|
|
127
|
-
const spy = jest
|
|
128
|
-
.spyOn(MouseEvent.prototype, 'target', 'get')
|
|
129
|
-
.mockReturnValue(firstCell);
|
|
130
|
-
|
|
131
|
-
const event = new MouseEvent('opa');
|
|
132
|
-
|
|
133
|
-
expect(handleMouseOut(editorView, event)).toEqual(true);
|
|
134
|
-
spy.mockRestore();
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('when the relatedTarget is a resize handle column too', () => {
|
|
139
|
-
it('should return false', () => {
|
|
140
|
-
const { editorView } = editor(
|
|
141
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(td()(p('{o}')), tdEmpty))),
|
|
142
|
-
);
|
|
143
|
-
const firstCell = document.createElement('div');
|
|
144
|
-
firstCell.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
|
|
145
|
-
const secondCell = document.createElement('div');
|
|
146
|
-
secondCell.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
|
|
147
|
-
|
|
148
|
-
const spy = jest
|
|
149
|
-
.spyOn(MouseEvent.prototype, 'target', 'get')
|
|
150
|
-
.mockReturnValue(secondCell);
|
|
151
|
-
|
|
152
|
-
const event = new MouseEvent('opa', {
|
|
153
|
-
relatedTarget: firstCell,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
expect(handleMouseOut(editorView, event)).toEqual(false);
|
|
157
|
-
spy.mockRestore();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe('table event handlers', () => {
|
|
164
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
165
|
-
const editor = (doc: DocBuilder) =>
|
|
166
|
-
createEditor({
|
|
167
|
-
doc,
|
|
168
|
-
attachTo: document.body,
|
|
169
|
-
preset: new Preset<LightEditorPlugin>()
|
|
170
|
-
.add([featureFlagsPlugin, {}])
|
|
171
|
-
.add([analyticsPlugin, {}])
|
|
172
|
-
.add(contentInsertionPlugin)
|
|
173
|
-
.add(decorationsPlugin)
|
|
174
|
-
.add(widthPlugin)
|
|
175
|
-
.add(guidelinePlugin)
|
|
176
|
-
.add(gridPlugin)
|
|
177
|
-
.add(selectionPlugin)
|
|
178
|
-
.add(tablePlugin),
|
|
179
|
-
pluginKey,
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('#handleMouseOver', () => {
|
|
183
|
-
describe('when insert col/row button is hidden', () => {
|
|
184
|
-
it('should set table as hovered', () => {
|
|
185
|
-
const { editorView } = editor(
|
|
186
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
187
|
-
);
|
|
188
|
-
const { state } = editorView;
|
|
189
|
-
const cursorPos = 8;
|
|
190
|
-
editorView.dispatch(
|
|
191
|
-
state.tr.setSelection(
|
|
192
|
-
new TextSelection(state.doc.resolve(cursorPos)),
|
|
193
|
-
),
|
|
194
|
-
);
|
|
195
|
-
const event = {
|
|
196
|
-
target: editorView.dom.querySelector('td'),
|
|
197
|
-
};
|
|
198
|
-
expect(handleMouseOver(editorView, event as MouseEvent)).toEqual(true);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe('when insert col/row button is visible', () => {
|
|
203
|
-
it('should call hideInsertColumnOrRowButton when moving to the first cell', () => {
|
|
204
|
-
const { editorView, refs } = editor(
|
|
205
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
showInsertColumnButton(0)(editorView.state, editorView.dispatch);
|
|
209
|
-
|
|
210
|
-
const firstCell = editorView.domAtPos(refs['<>']);
|
|
211
|
-
const event = {
|
|
212
|
-
target: firstCell.node,
|
|
213
|
-
};
|
|
214
|
-
expect(handleMouseOver(editorView, event as any)).toEqual(true);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe('#handleMouseMove', () => {
|
|
220
|
-
describe('when resize decoration has been set', () => {
|
|
221
|
-
it('should return false', () => {
|
|
222
|
-
const { editorView, refs } = editor(
|
|
223
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
224
|
-
);
|
|
225
|
-
const { state, dispatch } = editorView;
|
|
226
|
-
|
|
227
|
-
addResizeHandleDecorations(0, 0, false)(state, dispatch);
|
|
228
|
-
|
|
229
|
-
const firstCell = editorView.domAtPos(refs['<>']);
|
|
230
|
-
const event = {
|
|
231
|
-
target: firstCell.node,
|
|
232
|
-
};
|
|
233
|
-
expect(handleMouseMove(editorView, event as any)).toEqual(false);
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe('withCellTracking', () => {
|
|
240
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
241
|
-
const editor = (doc: DocBuilder, isDragAndDropEnabled = false) =>
|
|
242
|
-
createEditor({
|
|
243
|
-
doc,
|
|
244
|
-
attachTo: document.body,
|
|
245
|
-
featureFlags: {
|
|
246
|
-
tableDragAndDrop: isDragAndDropEnabled,
|
|
247
|
-
},
|
|
248
|
-
preset: new Preset<LightEditorPlugin>()
|
|
249
|
-
.add([featureFlagsPlugin, {}])
|
|
250
|
-
.add([analyticsPlugin, {}])
|
|
251
|
-
.add(contentInsertionPlugin)
|
|
252
|
-
.add(decorationsPlugin)
|
|
253
|
-
.add(widthPlugin)
|
|
254
|
-
.add(guidelinePlugin)
|
|
255
|
-
.add(gridPlugin)
|
|
256
|
-
.add(selectionPlugin)
|
|
257
|
-
.add([
|
|
258
|
-
tablePlugin,
|
|
259
|
-
{
|
|
260
|
-
tableOptions: { advanced: true },
|
|
261
|
-
},
|
|
262
|
-
]),
|
|
263
|
-
pluginKey,
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
describe('should fire event handler passed in', () => {
|
|
267
|
-
const { editorView } = editor(
|
|
268
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
269
|
-
true,
|
|
270
|
-
);
|
|
271
|
-
const eventHandlerSpy = jest.fn();
|
|
272
|
-
withCellTracking(eventHandlerSpy)(editorView, {} as any);
|
|
273
|
-
|
|
274
|
-
expect(eventHandlerSpy).toHaveBeenCalled();
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('should correctly set table cell coordinates based on mouse location', () => {
|
|
278
|
-
const { editorView, refs } = editor(
|
|
279
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
280
|
-
true,
|
|
281
|
-
);
|
|
282
|
-
const firstCell = editorView.domAtPos(refs['<>']);
|
|
283
|
-
|
|
284
|
-
const event = {
|
|
285
|
-
target: firstCell.node,
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
withCellTracking(jest.fn())(editorView, event as any);
|
|
289
|
-
|
|
290
|
-
const pluginState = getPluginState(editorView.state);
|
|
291
|
-
expect(pluginState.hoveredCell).toEqual({
|
|
292
|
-
colIndex: undefined,
|
|
293
|
-
rowIndex: undefined,
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
});
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
2
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
3
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
5
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
6
|
-
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
7
|
-
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
8
|
-
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
9
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
10
|
-
import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
11
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
12
|
-
import {
|
|
13
|
-
createProsemirrorEditorFactory,
|
|
14
|
-
Preset,
|
|
15
|
-
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
16
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
17
|
-
import {
|
|
18
|
-
doc,
|
|
19
|
-
p,
|
|
20
|
-
table,
|
|
21
|
-
td,
|
|
22
|
-
th,
|
|
23
|
-
tr,
|
|
24
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
25
|
-
|
|
26
|
-
import tablePlugin from '../../plugin';
|
|
27
|
-
import { pluginKey as tablePluginKey } from '../../pm-plugins/plugin-key';
|
|
28
|
-
import type { PluginConfig } from '../../types';
|
|
29
|
-
|
|
30
|
-
const TABLE_LOCAL_ID = 'test-table-local-id';
|
|
31
|
-
|
|
32
|
-
describe('fix tables', () => {
|
|
33
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
global['fetch'] = jest.fn();
|
|
36
|
-
|
|
37
|
-
const editor = (doc: DocBuilder) => {
|
|
38
|
-
const tableOptions = {
|
|
39
|
-
allowNumberColumn: true,
|
|
40
|
-
allowHeaderRow: true,
|
|
41
|
-
allowHeaderColumn: true,
|
|
42
|
-
permittedLayouts: 'all',
|
|
43
|
-
allowColumnResizing: true,
|
|
44
|
-
} as PluginConfig;
|
|
45
|
-
|
|
46
|
-
return createEditor({
|
|
47
|
-
doc,
|
|
48
|
-
attachTo: document.body,
|
|
49
|
-
preset: new Preset<LightEditorPlugin>()
|
|
50
|
-
.add([featureFlagsPlugin, {}])
|
|
51
|
-
.add([analyticsPlugin, {}])
|
|
52
|
-
.add(contentInsertionPlugin)
|
|
53
|
-
.add(widthPlugin)
|
|
54
|
-
.add(guidelinePlugin)
|
|
55
|
-
.add(selectionPlugin)
|
|
56
|
-
.add([tablePlugin, { tableOptions }]),
|
|
57
|
-
pluginKey: tablePluginKey,
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
describe('removeExtraneousColumnWidths', () => {
|
|
62
|
-
it('removes unnecessary column widths', () => {
|
|
63
|
-
const { editorView } = editor(
|
|
64
|
-
doc(
|
|
65
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
66
|
-
tr(
|
|
67
|
-
th({ colwidth: [100, 100] })(p('{<>}1')),
|
|
68
|
-
th({ colwidth: [100, 100] })(p('2')),
|
|
69
|
-
th({ colwidth: [480] })(p('3')),
|
|
70
|
-
),
|
|
71
|
-
tr(
|
|
72
|
-
td({ colwidth: [100, 100] })(p('4')),
|
|
73
|
-
td({ colwidth: [100, 100] })(p('5')),
|
|
74
|
-
td({ colwidth: [480] })(p('6')),
|
|
75
|
-
),
|
|
76
|
-
),
|
|
77
|
-
),
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
81
|
-
doc(
|
|
82
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
83
|
-
tr(
|
|
84
|
-
th({ colwidth: [100] })(p('1')),
|
|
85
|
-
th({ colwidth: [100] })(p('2')),
|
|
86
|
-
th({ colwidth: [480] })(p('3')),
|
|
87
|
-
),
|
|
88
|
-
tr(
|
|
89
|
-
td({ colwidth: [100] })(p('4')),
|
|
90
|
-
td({ colwidth: [100] })(p('5')),
|
|
91
|
-
td({ colwidth: [480] })(p('6')),
|
|
92
|
-
),
|
|
93
|
-
),
|
|
94
|
-
),
|
|
95
|
-
);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('cells with negative rowSpan', () => {
|
|
100
|
-
const TABLE_LOCAL_ID = 'test-table-2';
|
|
101
|
-
const SPAN_VALUE = -2;
|
|
102
|
-
it('should fire v3 analytics', () => {
|
|
103
|
-
const { dispatchAnalyticsEvent } = editor(
|
|
104
|
-
doc(
|
|
105
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
106
|
-
tr(
|
|
107
|
-
td({ rowspan: SPAN_VALUE })(p('')),
|
|
108
|
-
td({})(p('')),
|
|
109
|
-
td({})(p('')),
|
|
110
|
-
),
|
|
111
|
-
tr(td({})(p('')), td({})(p('')), td({})(p(''))),
|
|
112
|
-
),
|
|
113
|
-
),
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
expect(dispatchAnalyticsEvent).toHaveBeenCalledWith(
|
|
117
|
-
expect.objectContaining({
|
|
118
|
-
action: 'invalidDocumentEncountered',
|
|
119
|
-
actionSubject: 'editor',
|
|
120
|
-
attributes: expect.objectContaining({
|
|
121
|
-
nodeType: 'tableCell',
|
|
122
|
-
reason: 'rowspan: negative value',
|
|
123
|
-
tableLocalId: TABLE_LOCAL_ID,
|
|
124
|
-
spanValue: SPAN_VALUE,
|
|
125
|
-
}),
|
|
126
|
-
eventType: 'operational',
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('cells with negative colSpan', () => {
|
|
133
|
-
const TABLE_LOCAL_ID = 'test-table-3';
|
|
134
|
-
const SPAN_VALUE = -2;
|
|
135
|
-
it('should fire v3 analytics', () => {
|
|
136
|
-
const { dispatchAnalyticsEvent } = editor(
|
|
137
|
-
doc(
|
|
138
|
-
table({ localId: TABLE_LOCAL_ID })(
|
|
139
|
-
tr(
|
|
140
|
-
td({ colspan: SPAN_VALUE })(p('')),
|
|
141
|
-
td({})(p('')),
|
|
142
|
-
td({})(p('')),
|
|
143
|
-
),
|
|
144
|
-
tr(td({})(p('')), td({})(p('')), td({})(p(''))),
|
|
145
|
-
),
|
|
146
|
-
),
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
expect(dispatchAnalyticsEvent).toHaveBeenCalledWith(
|
|
150
|
-
expect.objectContaining({
|
|
151
|
-
action: 'invalidDocumentEncountered',
|
|
152
|
-
actionSubject: 'editor',
|
|
153
|
-
attributes: expect.objectContaining({
|
|
154
|
-
nodeType: 'tableCell',
|
|
155
|
-
reason: 'colspan: negative value',
|
|
156
|
-
tableLocalId: TABLE_LOCAL_ID,
|
|
157
|
-
spanValue: SPAN_VALUE,
|
|
158
|
-
}),
|
|
159
|
-
eventType: 'operational',
|
|
160
|
-
}),
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
});
|