@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,127 +0,0 @@
|
|
|
1
|
-
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import type {
|
|
3
|
-
DocBuilder,
|
|
4
|
-
FloatingToolbarButton,
|
|
5
|
-
FloatingToolbarItem,
|
|
6
|
-
GetEditorFeatureFlags,
|
|
7
|
-
} from '@atlaskit/editor-common/types';
|
|
8
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
9
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
10
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
11
|
-
import { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
12
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
13
|
-
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
14
|
-
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
15
|
-
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
16
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
17
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
18
|
-
import type { LightEditorPlugin } 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
|
-
createProsemirrorEditorFactory,
|
|
22
|
-
Preset,
|
|
23
|
-
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
24
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
25
|
-
import {
|
|
26
|
-
doc,
|
|
27
|
-
p,
|
|
28
|
-
table,
|
|
29
|
-
tdCursor,
|
|
30
|
-
tdEmpty,
|
|
31
|
-
tr,
|
|
32
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
33
|
-
|
|
34
|
-
import { setEditorFocus, setTableRef } from '../../commands';
|
|
35
|
-
import tablePlugin from '../../plugin';
|
|
36
|
-
import { getToolbarConfig } from '../../toolbar';
|
|
37
|
-
|
|
38
|
-
const formatMessage: (t: { id: string }) => string = (message) =>
|
|
39
|
-
`${message.id}`;
|
|
40
|
-
|
|
41
|
-
describe('getToolbarConfig', () => {
|
|
42
|
-
const getEditorContainerWidth = () => ({ width: 500 });
|
|
43
|
-
const editorAnalyticsAPIFake: EditorAnalyticsAPI = {
|
|
44
|
-
attachAnalyticsEvent: jest.fn().mockReturnValue(() => jest.fn()),
|
|
45
|
-
fireAnalyticsEvent: jest.fn(),
|
|
46
|
-
};
|
|
47
|
-
const getEditorFeatureFlags: GetEditorFeatureFlags = jest
|
|
48
|
-
.fn()
|
|
49
|
-
.mockReturnValue({});
|
|
50
|
-
const getButton = (editorView: EditorView) => {
|
|
51
|
-
const { state } = editorView;
|
|
52
|
-
const config = getToolbarConfig(
|
|
53
|
-
getEditorContainerWidth,
|
|
54
|
-
editorAnalyticsAPIFake,
|
|
55
|
-
getEditorFeatureFlags,
|
|
56
|
-
() => editorView,
|
|
57
|
-
)({})(state, { formatMessage } as any, {} as any)!;
|
|
58
|
-
//
|
|
59
|
-
expect(config).not.toBeUndefined();
|
|
60
|
-
expect(Array.isArray(config.items)).toBeTruthy();
|
|
61
|
-
|
|
62
|
-
const items =
|
|
63
|
-
typeof config.items === 'function'
|
|
64
|
-
? config.items(state.doc.firstChild!)
|
|
65
|
-
: config.items;
|
|
66
|
-
|
|
67
|
-
const button = items.find(
|
|
68
|
-
(item: FloatingToolbarItem<any>) =>
|
|
69
|
-
item.type === 'button' && item.id === 'editor.table.delete',
|
|
70
|
-
)! as FloatingToolbarButton<any>;
|
|
71
|
-
|
|
72
|
-
expect(button).not.toBeUndefined();
|
|
73
|
-
return button;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const createEditorFn = createProsemirrorEditorFactory();
|
|
77
|
-
const createEditor = (doc: DocBuilder) => {
|
|
78
|
-
const output = createEditorFn({
|
|
79
|
-
doc,
|
|
80
|
-
|
|
81
|
-
attachTo: document.body,
|
|
82
|
-
preset: new Preset<LightEditorPlugin>()
|
|
83
|
-
.add([featureFlagsPlugin, {}])
|
|
84
|
-
.add([analyticsPlugin, {}])
|
|
85
|
-
.add(contentInsertionPlugin)
|
|
86
|
-
.add(decorationsPlugin)
|
|
87
|
-
.add(widthPlugin)
|
|
88
|
-
.add(guidelinePlugin)
|
|
89
|
-
.add(selectionPlugin)
|
|
90
|
-
.add(tablePlugin),
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Prep the table plugin state a little
|
|
94
|
-
const { editorView } = output;
|
|
95
|
-
const { dispatch } = editorView;
|
|
96
|
-
const tableRef = document.querySelector(
|
|
97
|
-
'.ProseMirror table',
|
|
98
|
-
) as HTMLTableElement;
|
|
99
|
-
setEditorFocus(true)(output.editorView.state, dispatch);
|
|
100
|
-
setTableRef(tableRef)(output.editorView.state, dispatch);
|
|
101
|
-
|
|
102
|
-
return output;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
describe('should not add confirmDialog to delete button', () => {
|
|
106
|
-
it('if no localId', () => {
|
|
107
|
-
const { editorView } = createEditor(
|
|
108
|
-
doc(p('text'), table()(tr(tdCursor, tdEmpty))),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
const button = getButton(editorView);
|
|
112
|
-
expect(button.confirmDialog).toBeUndefined();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('if localId defined but not referenced', () => {
|
|
116
|
-
const { editorView } = createEditor(
|
|
117
|
-
doc(
|
|
118
|
-
p('text'),
|
|
119
|
-
table({ localId: 'unreferenced' })(tr(tdCursor, tdEmpty)),
|
|
120
|
-
),
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
const button = getButton(editorView);
|
|
124
|
-
expect(button.confirmDialog).toBeUndefined();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
4
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
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 type { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
9
|
-
import { TextSelection } 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 { handleDocOrSelectionChanged } from '../../handlers';
|
|
27
|
-
import tablePlugin from '../../plugin';
|
|
28
|
-
import { defaultTableSelection } from '../../pm-plugins/default-table-selection';
|
|
29
|
-
import { pluginKey } from '../../pm-plugins/plugin-key';
|
|
30
|
-
import type { TablePluginState } from '../../types';
|
|
31
|
-
|
|
32
|
-
describe('table action handlers', () => {
|
|
33
|
-
let editor: any;
|
|
34
|
-
let defaultPluginState: any;
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
38
|
-
const preset = new Preset<LightEditorPlugin>()
|
|
39
|
-
.add([featureFlagsPlugin, {}])
|
|
40
|
-
.add([analyticsPlugin, {}])
|
|
41
|
-
.add(contentInsertionPlugin)
|
|
42
|
-
.add(widthPlugin)
|
|
43
|
-
.add(guidelinePlugin)
|
|
44
|
-
.add(selectionPlugin)
|
|
45
|
-
.add(tablePlugin);
|
|
46
|
-
|
|
47
|
-
editor = (doc: DocBuilder) =>
|
|
48
|
-
createEditor<TablePluginState, PluginKey, typeof preset>({
|
|
49
|
-
doc,
|
|
50
|
-
preset,
|
|
51
|
-
pluginKey,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
defaultPluginState = {
|
|
55
|
-
...defaultTableSelection,
|
|
56
|
-
pluginConfig: {},
|
|
57
|
-
editorHasFocus: true,
|
|
58
|
-
isNumberColumnEnabled: false,
|
|
59
|
-
isHeaderColumnEnabled: false,
|
|
60
|
-
isHeaderRowEnabled: false,
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('#handleDocOrSelectionChanged', () => {
|
|
65
|
-
it('should return a new state with updated tableNode prop and reset selection', () => {
|
|
66
|
-
const pluginState = {
|
|
67
|
-
...defaultPluginState,
|
|
68
|
-
hoveredColumns: [1, 2, 3],
|
|
69
|
-
hoveredRows: [1, 2, 3],
|
|
70
|
-
isInDanger: true,
|
|
71
|
-
tableNode: undefined,
|
|
72
|
-
targetCellPosition: undefined,
|
|
73
|
-
ordering: undefined,
|
|
74
|
-
resizeHandleColumnIndex: undefined,
|
|
75
|
-
};
|
|
76
|
-
const { editorView } = editor(
|
|
77
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
78
|
-
);
|
|
79
|
-
const { state } = editorView;
|
|
80
|
-
const cursorPos = 8;
|
|
81
|
-
editorView.dispatch(
|
|
82
|
-
state.tr.setSelection(new TextSelection(state.doc.resolve(cursorPos))),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const newState = handleDocOrSelectionChanged(
|
|
86
|
-
editorView.state.tr,
|
|
87
|
-
pluginState,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
expect(newState).toEqual({
|
|
91
|
-
...pluginState,
|
|
92
|
-
...defaultTableSelection,
|
|
93
|
-
tableNode: editorView.state.doc.firstChild,
|
|
94
|
-
targetCellPosition: cursorPos - 2,
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
4
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
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 type { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
9
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
10
|
-
import {
|
|
11
|
-
getCellsInColumn,
|
|
12
|
-
getCellsInRow,
|
|
13
|
-
getCellsInTable,
|
|
14
|
-
} from '@atlaskit/editor-tables/utils';
|
|
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
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
32
|
-
import { selectColumns } from '@atlaskit/editor-test-helpers/table';
|
|
33
|
-
|
|
34
|
-
import {
|
|
35
|
-
clearHoverSelection,
|
|
36
|
-
hoverColumns,
|
|
37
|
-
hoverRows,
|
|
38
|
-
hoverTable,
|
|
39
|
-
} from '../../commands';
|
|
40
|
-
import tablePlugin from '../../plugin';
|
|
41
|
-
import { getDecorations } from '../../pm-plugins/decorations/plugin';
|
|
42
|
-
import { pluginKey } from '../../pm-plugins/plugin-key';
|
|
43
|
-
import type { TablePluginState } from '../../types';
|
|
44
|
-
import { TableDecorations } from '../../types';
|
|
45
|
-
|
|
46
|
-
describe('table hover selection plugin', () => {
|
|
47
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
48
|
-
const preset = new Preset<LightEditorPlugin>()
|
|
49
|
-
.add([featureFlagsPlugin, {}])
|
|
50
|
-
.add([analyticsPlugin, {}])
|
|
51
|
-
.add(contentInsertionPlugin)
|
|
52
|
-
.add(widthPlugin)
|
|
53
|
-
.add(guidelinePlugin)
|
|
54
|
-
.add(selectionPlugin)
|
|
55
|
-
.add(tablePlugin);
|
|
56
|
-
|
|
57
|
-
const editor = (doc: DocBuilder) =>
|
|
58
|
-
createEditor<TablePluginState, PluginKey, typeof preset>({
|
|
59
|
-
doc,
|
|
60
|
-
preset,
|
|
61
|
-
pluginKey,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const getTableDecorations = (
|
|
65
|
-
editorView: EditorView,
|
|
66
|
-
cells: Array<{ pos: number }>,
|
|
67
|
-
key?: TableDecorations,
|
|
68
|
-
) => {
|
|
69
|
-
const decorationSet = getDecorations(editorView.state);
|
|
70
|
-
|
|
71
|
-
if (key) {
|
|
72
|
-
return decorationSet.find(
|
|
73
|
-
cells[0].pos,
|
|
74
|
-
cells[cells.length - 1].pos,
|
|
75
|
-
(spec) => spec.key.indexOf(key) > -1,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return decorationSet.find(cells[0].pos, cells[cells.length - 1].pos);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
describe('when table has 3 columns/2 rows', () => {
|
|
83
|
-
let editorView: EditorView;
|
|
84
|
-
beforeEach(() => {
|
|
85
|
-
const mountedEditor = editor(
|
|
86
|
-
doc(
|
|
87
|
-
p('text'),
|
|
88
|
-
table()(
|
|
89
|
-
tr(tdCursor, tdEmpty, tdEmpty),
|
|
90
|
-
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
91
|
-
),
|
|
92
|
-
),
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
editorView = mountedEditor.editorView;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('selectColumn(1)', () => {
|
|
99
|
-
const column = 1;
|
|
100
|
-
beforeEach(() => {
|
|
101
|
-
selectColumns([column])(editorView.state, editorView.dispatch);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should add decoration', () => {
|
|
105
|
-
const cells = getCellsInColumn(column)(editorView.state.selection)!;
|
|
106
|
-
|
|
107
|
-
const decor = getTableDecorations(
|
|
108
|
-
editorView,
|
|
109
|
-
cells,
|
|
110
|
-
TableDecorations.COLUMN_SELECTED,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
expect(decor).toHaveLength(2);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe('hoverColumn(number)', () => {
|
|
118
|
-
it('can create a hover selection over multiple columns', () => {
|
|
119
|
-
hoverColumns([0, 1])(editorView.state, editorView.dispatch);
|
|
120
|
-
const cells = getCellsInColumn(0)(editorView.state.selection)!.concat(
|
|
121
|
-
getCellsInColumn(1)(editorView.state.selection)!,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
expect(
|
|
125
|
-
getTableDecorations(
|
|
126
|
-
editorView,
|
|
127
|
-
cells,
|
|
128
|
-
TableDecorations.ALL_CONTROLS_HOVER,
|
|
129
|
-
),
|
|
130
|
-
).toHaveLength(4);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe.each([0, 1, 2])(
|
|
134
|
-
'when called hoverColumns with [%d]',
|
|
135
|
-
(column) => {
|
|
136
|
-
it('should create a hover selection of column', () => {
|
|
137
|
-
hoverColumns([column])(editorView.state, editorView.dispatch);
|
|
138
|
-
const decos = getTableDecorations(
|
|
139
|
-
editorView,
|
|
140
|
-
getCellsInColumn(column)(editorView.state.selection)!,
|
|
141
|
-
TableDecorations.ALL_CONTROLS_HOVER,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
// selection spans 2 cells in the selected column (because we have 2 rows in the table)
|
|
145
|
-
expect(decos).toHaveLength(2);
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('hoverRow(number)', () => {
|
|
153
|
-
describe('when table has 3 rows', () => {
|
|
154
|
-
let editorView: EditorView;
|
|
155
|
-
beforeEach(() => {
|
|
156
|
-
const mountedEditor = editor(
|
|
157
|
-
doc(
|
|
158
|
-
p('text'),
|
|
159
|
-
table()(
|
|
160
|
-
tr(tdCursor, tdEmpty),
|
|
161
|
-
tr(tdEmpty, tdEmpty),
|
|
162
|
-
tr(tdEmpty, tdEmpty),
|
|
163
|
-
),
|
|
164
|
-
),
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
editorView = mountedEditor.editorView;
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('can create a hover selection over multiple rows', () => {
|
|
171
|
-
hoverRows([0, 1])(editorView.state, editorView.dispatch);
|
|
172
|
-
const cells = getCellsInRow(0)(editorView.state.selection)!.concat(
|
|
173
|
-
getCellsInRow(1)(editorView.state.selection)!,
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
expect(
|
|
177
|
-
getTableDecorations(
|
|
178
|
-
editorView,
|
|
179
|
-
cells,
|
|
180
|
-
TableDecorations.ALL_CONTROLS_HOVER,
|
|
181
|
-
),
|
|
182
|
-
).toHaveLength(4);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
describe.each([0, 1, 2])('when called hoverRows with [%d]', (row) => {
|
|
186
|
-
it('should create a hover selection of row', () => {
|
|
187
|
-
hoverRows([row])(editorView.state, editorView.dispatch);
|
|
188
|
-
expect(
|
|
189
|
-
getTableDecorations(
|
|
190
|
-
editorView,
|
|
191
|
-
getCellsInRow(row)(editorView.state.selection)!,
|
|
192
|
-
TableDecorations.ALL_CONTROLS_HOVER,
|
|
193
|
-
),
|
|
194
|
-
).toHaveLength(2);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe('hovertable()', () => {
|
|
201
|
-
describe('when table has 3 rows', () => {
|
|
202
|
-
it('should create a hover selection of the whole table', () => {
|
|
203
|
-
const { editorView } = editor(
|
|
204
|
-
doc(
|
|
205
|
-
p('text'),
|
|
206
|
-
table()(
|
|
207
|
-
tr(tdCursor, tdEmpty),
|
|
208
|
-
tr(tdEmpty, tdEmpty),
|
|
209
|
-
tr(tdEmpty, tdEmpty),
|
|
210
|
-
),
|
|
211
|
-
),
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
hoverTable()(editorView.state, editorView.dispatch);
|
|
215
|
-
|
|
216
|
-
// selection should span all 6 cells
|
|
217
|
-
expect(
|
|
218
|
-
getTableDecorations(
|
|
219
|
-
editorView,
|
|
220
|
-
getCellsInTable(editorView.state.selection)!,
|
|
221
|
-
TableDecorations.ALL_CONTROLS_HOVER,
|
|
222
|
-
),
|
|
223
|
-
).toHaveLength(6);
|
|
224
|
-
|
|
225
|
-
// reset hover selection plugin to an empty DecorationSet
|
|
226
|
-
clearHoverSelection()(editorView.state, editorView.dispatch);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// TODO: ensure this works as I have removed sinon here
|
|
2
|
-
import { defaultSchema } from '@atlaskit/adf-schema/schema-default';
|
|
3
|
-
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
4
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
5
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
6
|
-
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
7
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
8
|
-
import {
|
|
9
|
-
doc,
|
|
10
|
-
p,
|
|
11
|
-
table,
|
|
12
|
-
tdCursor,
|
|
13
|
-
tdEmpty,
|
|
14
|
-
tr,
|
|
15
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
16
|
-
|
|
17
|
-
import TableView from '../../nodeviews/table';
|
|
18
|
-
import { pluginKey } from '../../pm-plugins/plugin-key';
|
|
19
|
-
import type { PluginConfig, TablePluginState } from '../../types';
|
|
20
|
-
|
|
21
|
-
// TODO: this doesn't work
|
|
22
|
-
describe.skip('TableView', () => {
|
|
23
|
-
const createEditor = createEditorFactory<TablePluginState>();
|
|
24
|
-
const getEditorContainerWidth = () => ({ width: 500 });
|
|
25
|
-
const fakeGetEditorFeatureFlags = () => ({});
|
|
26
|
-
const originalHandleRef = (TableView.prototype as any).handleRef;
|
|
27
|
-
const handleRefInnerMock = jest.fn(originalHandleRef);
|
|
28
|
-
let handleRefMock: jest.SpyInstance;
|
|
29
|
-
|
|
30
|
-
const editor = (doc: DocBuilder) => {
|
|
31
|
-
const tableOptions = {
|
|
32
|
-
allowNumberColumn: true,
|
|
33
|
-
allowHeaderRow: true,
|
|
34
|
-
allowHeaderColumn: true,
|
|
35
|
-
permittedLayouts: 'all',
|
|
36
|
-
} as PluginConfig;
|
|
37
|
-
return createEditor({
|
|
38
|
-
doc,
|
|
39
|
-
editorProps: {
|
|
40
|
-
allowTables: tableOptions,
|
|
41
|
-
media: {
|
|
42
|
-
allowMediaSingle: true,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
pluginKey,
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// beforeEach(() => {
|
|
50
|
-
// handleRefMock = jest
|
|
51
|
-
// .spyOn(Object.getPrototypeOf(TableView), 'handleRef')
|
|
52
|
-
// .mockImplementation(() => {
|
|
53
|
-
// console.log('getting called?');
|
|
54
|
-
// // window.setTimeout(() => handleRefInnerMock.call(this, ref), 0);
|
|
55
|
-
// });
|
|
56
|
-
// });
|
|
57
|
-
// previous regression involved PM trying to render child DOM elements,
|
|
58
|
-
// but the NodeView had an undefined contentDOM after the React render finishes
|
|
59
|
-
// (since render is not synchronous)
|
|
60
|
-
it('always provides a content DOM', function (this: any) {
|
|
61
|
-
jest.useFakeTimers();
|
|
62
|
-
|
|
63
|
-
// in the tests, handleRef gets called immediately (due to event loop ordering)
|
|
64
|
-
// however, the ref callback function can be called async from React after
|
|
65
|
-
// calling render, which can often occur in the browser
|
|
66
|
-
//
|
|
67
|
-
// to simulate this, we add a callback to force it to run out-of-order
|
|
68
|
-
// const handleRefMock = sinon
|
|
69
|
-
// // @ts-ignore
|
|
70
|
-
// .stub(TableView.prototype, '_handleRef')
|
|
71
|
-
// .callsFake((ref: HTMLElement) => {
|
|
72
|
-
// window.setTimeout(() => handleRefInnerMock.call(this, ref), 0);
|
|
73
|
-
// });
|
|
74
|
-
|
|
75
|
-
// create the NodeView
|
|
76
|
-
const node = table()(tr(tdCursor, tdEmpty, tdEmpty))(defaultSchema);
|
|
77
|
-
const { editorView, portalProviderAPI } = editor(doc(p()));
|
|
78
|
-
const eventDispatcher = { on: () => {} } as unknown as EventDispatcher;
|
|
79
|
-
const tableView = new TableView({
|
|
80
|
-
node,
|
|
81
|
-
allowColumnResizing: false,
|
|
82
|
-
view: editorView,
|
|
83
|
-
portalProviderAPI,
|
|
84
|
-
eventDispatcher,
|
|
85
|
-
getPos: () => 1,
|
|
86
|
-
getEditorContainerWidth,
|
|
87
|
-
getEditorFeatureFlags: fakeGetEditorFeatureFlags,
|
|
88
|
-
hasIntlContext: true,
|
|
89
|
-
dispatchAnalyticsEvent: jest.fn(),
|
|
90
|
-
}).init();
|
|
91
|
-
|
|
92
|
-
// we expect to have a contentDOM after instanciating the NodeView so that
|
|
93
|
-
// ProseMirror will render the node's children into the element
|
|
94
|
-
expect(tableView.contentDOM).toBeDefined();
|
|
95
|
-
|
|
96
|
-
// we shouldn't have called the mock yet, since it's behind the window.setTimeout
|
|
97
|
-
expect(handleRefInnerMock).not.toBeCalled();
|
|
98
|
-
|
|
99
|
-
// run the timers through
|
|
100
|
-
jest.runAllTimers();
|
|
101
|
-
|
|
102
|
-
// the timer should have expired now
|
|
103
|
-
expect(handleRefInnerMock).toBeCalled();
|
|
104
|
-
|
|
105
|
-
// ensure we still have a contentDOM
|
|
106
|
-
expect(tableView.contentDOM).toBeDefined();
|
|
107
|
-
|
|
108
|
-
// reset the mock
|
|
109
|
-
handleRefMock.mockClear();
|
|
110
|
-
});
|
|
111
|
-
});
|