@atlaskit/editor-plugin-table 7.0.3 → 7.1.1
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 +26 -0
- package/dist/cjs/event-handlers.js +4 -1
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +9 -9
- package/dist/cjs/pm-plugins/drag-and-drop/commands.js +4 -11
- package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +1 -4
- package/dist/cjs/pm-plugins/drag-and-drop/utils/monitor.js +0 -5
- package/dist/cjs/pm-plugins/keymap.js +1 -1
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/ui/DragHandle/index.js +27 -9
- package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
- package/dist/cjs/ui/FloatingContextualMenu/index.js +4 -3
- package/dist/cjs/ui/FloatingContextualMenu/styles.js +3 -1
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -2
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +1 -7
- package/dist/cjs/ui/TableFloatingColumnControls/index.js +0 -2
- package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +7 -2
- package/dist/cjs/ui/common-styles.js +2 -1
- package/dist/cjs/ui/consts.js +3 -3
- package/dist/cjs/ui/icons/AddRowAboveIcon.js +8 -12
- package/dist/cjs/ui/icons/AddRowBelowIcon.js +19 -15
- package/dist/cjs/ui/ui-styles.js +8 -8
- package/dist/cjs/utils/drag-menu.js +42 -29
- package/dist/es2019/event-handlers.js +3 -2
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +8 -8
- package/dist/es2019/pm-plugins/drag-and-drop/commands.js +5 -10
- package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +1 -4
- package/dist/es2019/pm-plugins/drag-and-drop/utils/monitor.js +0 -5
- package/dist/es2019/pm-plugins/keymap.js +2 -2
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/DragHandle/index.js +26 -8
- package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
- package/dist/es2019/ui/FloatingContextualMenu/index.js +5 -4
- package/dist/es2019/ui/FloatingContextualMenu/styles.js +3 -3
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -2
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +1 -7
- package/dist/es2019/ui/TableFloatingColumnControls/index.js +0 -2
- package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +7 -2
- package/dist/es2019/ui/common-styles.js +24 -5
- package/dist/es2019/ui/consts.js +2 -2
- package/dist/es2019/ui/icons/AddRowAboveIcon.js +8 -12
- package/dist/es2019/ui/icons/AddRowBelowIcon.js +19 -15
- package/dist/es2019/ui/ui-styles.js +8 -8
- package/dist/es2019/utils/drag-menu.js +29 -24
- package/dist/esm/event-handlers.js +5 -2
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +9 -9
- package/dist/esm/pm-plugins/drag-and-drop/commands.js +5 -12
- package/dist/esm/pm-plugins/drag-and-drop/plugin.js +1 -4
- package/dist/esm/pm-plugins/drag-and-drop/utils/monitor.js +0 -5
- package/dist/esm/pm-plugins/keymap.js +2 -2
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/DragHandle/index.js +27 -9
- package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
- package/dist/esm/ui/FloatingContextualMenu/index.js +5 -4
- package/dist/esm/ui/FloatingContextualMenu/styles.js +4 -2
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -2
- package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +1 -7
- package/dist/esm/ui/TableFloatingColumnControls/index.js +0 -2
- package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +7 -2
- package/dist/esm/ui/common-styles.js +2 -1
- package/dist/esm/ui/consts.js +2 -2
- package/dist/esm/ui/icons/AddRowAboveIcon.js +8 -12
- package/dist/esm/ui/icons/AddRowBelowIcon.js +19 -15
- package/dist/esm/ui/ui-styles.js +8 -8
- package/dist/esm/utils/drag-menu.js +41 -28
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/ui/FloatingContextualMenu/styles.d.ts +1 -1
- package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +0 -2
- package/dist/types/ui/consts.d.ts +2 -1
- package/dist/types/ui/ui-styles.d.ts +2 -2
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +1 -0
- package/dist/types-ts4.5/ui/FloatingContextualMenu/styles.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +0 -2
- package/dist/types-ts4.5/ui/consts.d.ts +2 -1
- package/dist/types-ts4.5/ui/ui-styles.d.ts +2 -2
- package/package.json +6 -8
- package/src/__tests__/unit/event-handlers.ts +3 -17
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +46 -17
- package/src/event-handlers.ts +14 -2
- package/src/index.ts +1 -1
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -8
- package/src/pm-plugins/drag-and-drop/commands.ts +5 -33
- package/src/pm-plugins/drag-and-drop/plugin.ts +0 -3
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -5
- package/src/pm-plugins/keymap.ts +2 -7
- package/src/types.ts +1 -0
- package/src/ui/DragHandle/index.tsx +33 -14
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +9 -2
- package/src/ui/FloatingContextualMenu/index.tsx +10 -3
- package/src/ui/FloatingContextualMenu/styles.ts +10 -3
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +13 -4
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +1 -13
- package/src/ui/TableFloatingColumnControls/index.tsx +0 -2
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +17 -7
- package/src/ui/common-styles.ts +20 -4
- package/src/ui/consts.ts +2 -6
- package/src/ui/icons/AddRowAboveIcon.tsx +2 -16
- package/src/ui/icons/AddRowBelowIcon.tsx +21 -12
- package/src/ui/ui-styles.ts +12 -8
- package/src/utils/drag-menu.ts +48 -32
- package/tsconfig.json +273 -0
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface Props {
|
|
3
3
|
tableRef: HTMLTableElement;
|
|
4
|
-
stickyTop?: number;
|
|
5
4
|
tableHeight?: number;
|
|
6
5
|
localId?: string;
|
|
7
|
-
rowHeights?: number[];
|
|
8
6
|
colWidths?: (number | undefined)[];
|
|
9
7
|
}
|
|
10
8
|
export declare const ColumnDropTargets: React.FC<Props>;
|
|
@@ -40,7 +40,8 @@ export declare const resizeHandlerAreaWidth: number;
|
|
|
40
40
|
export declare const resizeLineWidth = 2;
|
|
41
41
|
export declare const resizeHandlerZIndex: number;
|
|
42
42
|
export declare const contextualMenuTriggerSize = 16;
|
|
43
|
-
export declare const contextualMenuDropdownWidth
|
|
43
|
+
export declare const contextualMenuDropdownWidth = 180;
|
|
44
|
+
export declare const contextualMenuDropdownWidthDnD = 250;
|
|
44
45
|
export declare const stickyRowZIndex: number;
|
|
45
46
|
export declare const stickyRowOffsetTop = 8;
|
|
46
47
|
export declare const stickyHeaderBorderBottomWidth = 1;
|
|
@@ -8,12 +8,12 @@ export declare const insertColumnButtonWrapper: () => import("@emotion/react").S
|
|
|
8
8
|
export declare const insertRowButtonWrapper: () => import("@emotion/react").SerializedStyles;
|
|
9
9
|
export declare const columnControlsLineMarker: () => import("@emotion/react").SerializedStyles;
|
|
10
10
|
export declare const DeleteButton: () => import("@emotion/react").SerializedStyles;
|
|
11
|
-
export declare const OverflowShadow: () => import("@emotion/react").SerializedStyles;
|
|
11
|
+
export declare const OverflowShadow: (isDragAndDropEnabled: boolean | undefined) => import("@emotion/react").SerializedStyles;
|
|
12
12
|
export declare const floatingColumnControls: () => import("@emotion/react").SerializedStyles;
|
|
13
13
|
export declare const rowControlsWrapperDotStyle: () => import("@emotion/react").SerializedStyles;
|
|
14
14
|
export declare const columnControlsDecoration: () => import("@emotion/react").SerializedStyles;
|
|
15
15
|
export declare const hoveredDeleteButton: () => import("@emotion/react").SerializedStyles;
|
|
16
16
|
export declare const hoveredCell: () => import("@emotion/react").SerializedStyles;
|
|
17
17
|
export declare const hoveredWarningCell: import("@emotion/react").SerializedStyles;
|
|
18
|
-
export declare const resizeHandle: () => import("@emotion/react").SerializedStyles;
|
|
18
|
+
export declare const resizeHandle: (isDragAndDropEnabled: boolean | undefined) => import("@emotion/react").SerializedStyles;
|
|
19
19
|
export declare const insertLine: () => import("@emotion/react").SerializedStyles;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as tablesPlugin } from './plugin';
|
|
2
|
-
export type { TablePlugin } from './plugin';
|
|
2
|
+
export type { TablePlugin, TablePluginOptions } from './plugin';
|
|
@@ -299,6 +299,7 @@ export declare const TableCssClassName: {
|
|
|
299
299
|
DRAG_COLUMN_DROP_TARGET_CONTROLS: string;
|
|
300
300
|
DRAG_COLUMN_CONTROLS_INNER: string;
|
|
301
301
|
DRAG_HANDLE_BUTTON_CONTAINER: string;
|
|
302
|
+
DRAG_HANDLE_BUTTON_CLICKABLE_ZONE: string;
|
|
302
303
|
DRAG_CORNER_BUTTON: string;
|
|
303
304
|
DRAG_CORNER_BUTTON_INNER: string;
|
|
304
305
|
/** disabled classes */
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const cellColourPreviewStyles: (selectedColor: string) => import("@emotion/react").SerializedStyles;
|
|
2
2
|
export declare const elementBeforeIconStyles: import("@emotion/react").SerializedStyles;
|
|
3
|
-
export declare const tablePopupStyles: import("@emotion/react").SerializedStyles;
|
|
3
|
+
export declare const tablePopupStyles: (isDragAndDropEnabled: boolean | undefined) => import("@emotion/react").SerializedStyles;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface Props {
|
|
3
3
|
tableRef: HTMLTableElement;
|
|
4
|
-
stickyTop?: number;
|
|
5
4
|
tableHeight?: number;
|
|
6
5
|
localId?: string;
|
|
7
|
-
rowHeights?: number[];
|
|
8
6
|
colWidths?: (number | undefined)[];
|
|
9
7
|
}
|
|
10
8
|
export declare const ColumnDropTargets: React.FC<Props>;
|
|
@@ -40,7 +40,8 @@ export declare const resizeHandlerAreaWidth: number;
|
|
|
40
40
|
export declare const resizeLineWidth = 2;
|
|
41
41
|
export declare const resizeHandlerZIndex: number;
|
|
42
42
|
export declare const contextualMenuTriggerSize = 16;
|
|
43
|
-
export declare const contextualMenuDropdownWidth
|
|
43
|
+
export declare const contextualMenuDropdownWidth = 180;
|
|
44
|
+
export declare const contextualMenuDropdownWidthDnD = 250;
|
|
44
45
|
export declare const stickyRowZIndex: number;
|
|
45
46
|
export declare const stickyRowOffsetTop = 8;
|
|
46
47
|
export declare const stickyHeaderBorderBottomWidth = 1;
|
|
@@ -8,12 +8,12 @@ export declare const insertColumnButtonWrapper: () => import("@emotion/react").S
|
|
|
8
8
|
export declare const insertRowButtonWrapper: () => import("@emotion/react").SerializedStyles;
|
|
9
9
|
export declare const columnControlsLineMarker: () => import("@emotion/react").SerializedStyles;
|
|
10
10
|
export declare const DeleteButton: () => import("@emotion/react").SerializedStyles;
|
|
11
|
-
export declare const OverflowShadow: () => import("@emotion/react").SerializedStyles;
|
|
11
|
+
export declare const OverflowShadow: (isDragAndDropEnabled: boolean | undefined) => import("@emotion/react").SerializedStyles;
|
|
12
12
|
export declare const floatingColumnControls: () => import("@emotion/react").SerializedStyles;
|
|
13
13
|
export declare const rowControlsWrapperDotStyle: () => import("@emotion/react").SerializedStyles;
|
|
14
14
|
export declare const columnControlsDecoration: () => import("@emotion/react").SerializedStyles;
|
|
15
15
|
export declare const hoveredDeleteButton: () => import("@emotion/react").SerializedStyles;
|
|
16
16
|
export declare const hoveredCell: () => import("@emotion/react").SerializedStyles;
|
|
17
17
|
export declare const hoveredWarningCell: import("@emotion/react").SerializedStyles;
|
|
18
|
-
export declare const resizeHandle: () => import("@emotion/react").SerializedStyles;
|
|
18
|
+
export declare const resizeHandle: (isDragAndDropEnabled: boolean | undefined) => import("@emotion/react").SerializedStyles;
|
|
19
19
|
export declare const insertLine: () => import("@emotion/react").SerializedStyles;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^35.3.0",
|
|
32
32
|
"@atlaskit/custom-steps": "^0.0.11",
|
|
33
|
-
"@atlaskit/editor-common": "^77.
|
|
33
|
+
"@atlaskit/editor-common": "^77.1.0",
|
|
34
34
|
"@atlaskit/editor-palette": "1.5.2",
|
|
35
35
|
"@atlaskit/editor-plugin-analytics": "^0.4.0",
|
|
36
36
|
"@atlaskit/editor-plugin-content-insertion": "^0.1.0",
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"@atlaskit/editor-plugin-width": "^0.2.0",
|
|
40
40
|
"@atlaskit/editor-prosemirror": "1.1.0",
|
|
41
41
|
"@atlaskit/editor-shared-styles": "^2.9.0",
|
|
42
|
-
"@atlaskit/editor-tables": "^2.
|
|
42
|
+
"@atlaskit/editor-tables": "^2.5.0",
|
|
43
43
|
"@atlaskit/icon": "^22.0.0",
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^0.2.1",
|
|
45
45
|
"@atlaskit/pragmatic-drag-and-drop": "^0.25.0",
|
|
46
46
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^0.8.0",
|
|
47
47
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.12.0",
|
|
48
|
-
"@atlaskit/primitives": "^
|
|
48
|
+
"@atlaskit/primitives": "^2.0.0",
|
|
49
49
|
"@atlaskit/theme": "^12.6.0",
|
|
50
50
|
"@atlaskit/toggle": "^13.0.0",
|
|
51
|
-
"@atlaskit/tokens": "^1.
|
|
51
|
+
"@atlaskit/tokens": "^1.35.0",
|
|
52
52
|
"@atlaskit/tooltip": "^18.1.0",
|
|
53
53
|
"@babel/runtime": "^7.0.0",
|
|
54
54
|
"@emotion/react": "^11.7.1",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"@atlaskit/editor-plugin-feature-flags": "^1.0.0",
|
|
70
70
|
"@atlaskit/editor-plugin-grid": "^0.3.0",
|
|
71
71
|
"@atlaskit/editor-plugin-hyperlink": "^0.8.0",
|
|
72
|
+
"@atlaskit/editor-test-helpers": "^18.15.0",
|
|
72
73
|
"@atlaskit/visual-regression": "*",
|
|
73
74
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
74
75
|
"@atlassian/feature-flags-test-utils": "^0.1.2",
|
|
@@ -110,9 +111,6 @@
|
|
|
110
111
|
"platform.editor.custom-table-width": {
|
|
111
112
|
"type": "boolean"
|
|
112
113
|
},
|
|
113
|
-
"platform.editor.table.drag-and-drop": {
|
|
114
|
-
"type": "boolean"
|
|
115
|
-
},
|
|
116
114
|
"platform.editor.table.column-controls-styles-updated": {
|
|
117
115
|
"type": "boolean"
|
|
118
116
|
},
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
tdEmpty,
|
|
27
27
|
tr,
|
|
28
28
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
29
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
30
29
|
|
|
31
30
|
import {
|
|
32
31
|
addResizeHandleDecorations,
|
|
@@ -44,15 +43,6 @@ import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
|
44
43
|
import { pluginKey } from '../../pm-plugins/plugin-key';
|
|
45
44
|
import { TableCssClassName as ClassName } from '../../types';
|
|
46
45
|
|
|
47
|
-
// Mock Feature flags instead of using ffTest because we don't use the feature flag directly
|
|
48
|
-
jest.mock('@atlaskit/platform-feature-flags', () => ({
|
|
49
|
-
getBooleanFF: jest.fn().mockImplementation(() => false),
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
afterEach(() => {
|
|
53
|
-
(getBooleanFF as jest.Mock).mockReset();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
46
|
describe('table plugin: decorations', () => {
|
|
57
47
|
const createEditor = createProsemirrorEditorFactory();
|
|
58
48
|
const editor = (doc: DocBuilder) =>
|
|
@@ -252,6 +242,9 @@ describe('withCellTracking', () => {
|
|
|
252
242
|
createEditor({
|
|
253
243
|
doc,
|
|
254
244
|
attachTo: document.body,
|
|
245
|
+
featureFlags: {
|
|
246
|
+
tableDragAndDrop: isDragAndDropEnabled,
|
|
247
|
+
},
|
|
255
248
|
preset: new Preset<LightEditorPlugin>()
|
|
256
249
|
.add([featureFlagsPlugin, {}])
|
|
257
250
|
.add([analyticsPlugin, {}])
|
|
@@ -264,7 +257,6 @@ describe('withCellTracking', () => {
|
|
|
264
257
|
.add([
|
|
265
258
|
tablePlugin,
|
|
266
259
|
{
|
|
267
|
-
dragAndDropEnabled: isDragAndDropEnabled,
|
|
268
260
|
tableOptions: { advanced: true },
|
|
269
261
|
},
|
|
270
262
|
]),
|
|
@@ -272,9 +264,6 @@ describe('withCellTracking', () => {
|
|
|
272
264
|
});
|
|
273
265
|
|
|
274
266
|
describe('should fire event handler passed in', () => {
|
|
275
|
-
(getBooleanFF as jest.Mock).mockImplementation(
|
|
276
|
-
(name) => name === 'platform.editor.table.drag-and-drop',
|
|
277
|
-
);
|
|
278
267
|
const { editorView } = editor(
|
|
279
268
|
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
280
269
|
true,
|
|
@@ -286,9 +275,6 @@ describe('withCellTracking', () => {
|
|
|
286
275
|
});
|
|
287
276
|
|
|
288
277
|
it('should correctly set table cell coordinates based on mouse location', () => {
|
|
289
|
-
(getBooleanFF as jest.Mock).mockImplementation(
|
|
290
|
-
(name) => name === 'platform.editor.table.drag-and-drop',
|
|
291
|
-
);
|
|
292
278
|
const { editorView, refs } = editor(
|
|
293
279
|
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
294
280
|
true,
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { LightEditorPlugin } from '@atlaskit/editor-core/src/create-editor/get-plugins';
|
|
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';
|
|
1
11
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
12
|
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
3
|
-
import {
|
|
4
|
-
|
|
13
|
+
import {
|
|
14
|
+
createProsemirrorEditorFactory,
|
|
15
|
+
Preset,
|
|
16
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
5
17
|
import {
|
|
6
18
|
doc,
|
|
7
19
|
table,
|
|
@@ -9,27 +21,43 @@ import {
|
|
|
9
21
|
tdEmpty,
|
|
10
22
|
tr,
|
|
11
23
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
12
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
13
24
|
|
|
25
|
+
import tablePlugin from '../../../../plugin';
|
|
14
26
|
import { buildColumnControlsDecorations } from '../../../../pm-plugins/decorations/utils';
|
|
27
|
+
import { pluginKey } from '../../../../pm-plugins/plugin-key';
|
|
15
28
|
import { TableDecorations } from '../../../../types';
|
|
16
29
|
|
|
17
|
-
// Mock Feature flags instead of using ffTest because we don't use the feature flag directly
|
|
18
|
-
jest.mock('@atlaskit/platform-feature-flags', () => ({
|
|
19
|
-
getBooleanFF: jest.fn().mockImplementation(() => false),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
(getBooleanFF as jest.Mock).mockReset();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
30
|
describe('tables: column controls decorations', () => {
|
|
31
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
32
|
+
const editor = (doc: DocBuilder, isDragAndDropEnabled = false) =>
|
|
33
|
+
createEditor({
|
|
34
|
+
doc,
|
|
35
|
+
attachTo: document.body,
|
|
36
|
+
featureFlags: {
|
|
37
|
+
tableDragAndDrop: isDragAndDropEnabled,
|
|
38
|
+
},
|
|
39
|
+
preset: new Preset<LightEditorPlugin>()
|
|
40
|
+
.add([featureFlagsPlugin, {}])
|
|
41
|
+
.add([analyticsPlugin, {}])
|
|
42
|
+
.add(contentInsertionPlugin)
|
|
43
|
+
.add(decorationsPlugin)
|
|
44
|
+
.add(widthPlugin)
|
|
45
|
+
.add(guidelinePlugin)
|
|
46
|
+
.add(gridPlugin)
|
|
47
|
+
.add(selectionPlugin)
|
|
48
|
+
.add([
|
|
49
|
+
tablePlugin,
|
|
50
|
+
{
|
|
51
|
+
tableOptions: { advanced: true },
|
|
52
|
+
},
|
|
53
|
+
]),
|
|
54
|
+
pluginKey,
|
|
55
|
+
});
|
|
56
|
+
|
|
27
57
|
it(`should return an empty decorationSet ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop is enabled`, () => {
|
|
28
|
-
(getBooleanFF as jest.Mock).mockImplementation(
|
|
29
|
-
(name) => name === 'platform.editor.table.drag-and-drop',
|
|
30
|
-
);
|
|
31
58
|
const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
|
|
32
|
-
const
|
|
59
|
+
const editorInstance = editor(doc(table()(tr(tdCursor, tdEmpty))), true);
|
|
60
|
+
const state = editorInstance.editorView.state;
|
|
33
61
|
const nextDecorationSet = buildColumnControlsDecorations({
|
|
34
62
|
decorationSet: DecorationSet.empty,
|
|
35
63
|
tr: state.tr,
|
|
@@ -47,7 +75,8 @@ describe('tables: column controls decorations', () => {
|
|
|
47
75
|
|
|
48
76
|
it(`should return an empty decorationSet ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop is disabled`, () => {
|
|
49
77
|
const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
|
|
50
|
-
const
|
|
78
|
+
const editorInstance = editor(doc(table()(tr(tdCursor, tdEmpty))), false);
|
|
79
|
+
const state = editorInstance.editorView.state;
|
|
51
80
|
const nextDecorationSet = buildColumnControlsDecorations({
|
|
52
81
|
decorationSet: DecorationSet.empty,
|
|
53
82
|
tr: state.tr,
|
package/src/event-handlers.ts
CHANGED
|
@@ -47,7 +47,10 @@ import { getPluginState } from './pm-plugins/plugin-factory';
|
|
|
47
47
|
import { getPluginState as getResizePluginState } from './pm-plugins/table-resizing/plugin-factory';
|
|
48
48
|
import { deleteColumns, deleteRows } from './transforms';
|
|
49
49
|
import type { ElementContentRects } from './types';
|
|
50
|
-
import {
|
|
50
|
+
import {
|
|
51
|
+
TableCssClassName as ClassName,
|
|
52
|
+
RESIZE_HANDLE_AREA_DECORATION_GAP,
|
|
53
|
+
} from './types';
|
|
51
54
|
import {
|
|
52
55
|
convertHTMLCellIndexToColumnIndex,
|
|
53
56
|
getColumnIndexMappedToColumnIndexInFirstRow,
|
|
@@ -91,6 +94,14 @@ const isFocusingDragHandles = (event: Event) =>
|
|
|
91
94
|
event.relatedTarget.closest('button') &&
|
|
92
95
|
event.relatedTarget.getAttribute('draggable') === 'true';
|
|
93
96
|
|
|
97
|
+
const isFocusingDragHandlesClickableZone = (event: Event) =>
|
|
98
|
+
event instanceof FocusEvent &&
|
|
99
|
+
event.relatedTarget instanceof HTMLElement &&
|
|
100
|
+
event.relatedTarget.closest('button') &&
|
|
101
|
+
event.relatedTarget.classList.contains(
|
|
102
|
+
ClassName.DRAG_HANDLE_BUTTON_CLICKABLE_ZONE,
|
|
103
|
+
);
|
|
104
|
+
|
|
94
105
|
export const handleBlur = (view: EditorView, event: Event): boolean => {
|
|
95
106
|
const { state, dispatch } = view;
|
|
96
107
|
// IE version check for ED-4665
|
|
@@ -100,7 +111,8 @@ export const handleBlur = (view: EditorView, event: Event): boolean => {
|
|
|
100
111
|
!isFocusingCalendar(event) &&
|
|
101
112
|
!isFocusingModal(event) &&
|
|
102
113
|
!isFocusingFloatingToolbar(event) &&
|
|
103
|
-
!isFocusingDragHandles(event)
|
|
114
|
+
!isFocusingDragHandles(event) &&
|
|
115
|
+
!isFocusingDragHandlesClickableZone(event)
|
|
104
116
|
) {
|
|
105
117
|
setEditorFocus(false)(state, dispatch);
|
|
106
118
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as tablesPlugin } from './plugin';
|
|
2
|
-
export type { TablePlugin } from './plugin';
|
|
2
|
+
export type { TablePlugin, TablePluginOptions } from './plugin';
|
|
@@ -79,6 +79,7 @@ export const moveSourceWithAnalytics =
|
|
|
79
79
|
tr?: Transaction,
|
|
80
80
|
) => {
|
|
81
81
|
return withEditorAnalyticsAPI(({ selection }: EditorState) => {
|
|
82
|
+
const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
|
|
82
83
|
const { totalRowCount, totalColumnCount } =
|
|
83
84
|
getSelectedTableInfo(selection);
|
|
84
85
|
return {
|
|
@@ -93,7 +94,9 @@ export const moveSourceWithAnalytics =
|
|
|
93
94
|
count: sourceIndexes.length,
|
|
94
95
|
// This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
|
|
95
96
|
// of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
|
|
96
|
-
distance:
|
|
97
|
+
distance:
|
|
98
|
+
Math.min(...sourceIndexes.map((v) => Math.abs(targetIndex - v))) *
|
|
99
|
+
direction,
|
|
97
100
|
// If a drop doesn't actually change anything then we're going to mark the event as cancelled.
|
|
98
101
|
status: sourceIndexes.includes(targetIndex)
|
|
99
102
|
? TABLE_STATUS.CANCELLED
|
|
@@ -130,15 +133,15 @@ export const moveSourceWithAnalyticsViaShortcut =
|
|
|
130
133
|
? getSelectedRowIndexes(selectionRect)
|
|
131
134
|
: getSelectedColumnIndexes(selectionRect);
|
|
132
135
|
|
|
133
|
-
|
|
134
|
-
if (selectedIndexes.length === 0 || selectedIndexes.length > 1) {
|
|
136
|
+
if (selectedIndexes.length === 0) {
|
|
135
137
|
return false;
|
|
136
138
|
}
|
|
137
139
|
|
|
138
|
-
const sourceIndex = selectedIndexes[0];
|
|
140
|
+
// const sourceIndex = selectedIndexes[0];
|
|
139
141
|
// we can move only by one row/column
|
|
140
142
|
// 'direction' can only be 1 (for right or down) or -1 (for left or up)
|
|
141
|
-
const targetIndex =
|
|
143
|
+
const targetIndex =
|
|
144
|
+
Math[direction < 0 ? 'min' : 'max'](...selectedIndexes) + direction;
|
|
142
145
|
|
|
143
146
|
// We can move only if targetIndex is a positive number and is not higher than the total number of rows/columns.
|
|
144
147
|
const { totalRowCount, totalColumnCount } = getSelectedTableInfo(selection);
|
|
@@ -155,8 +158,8 @@ export const moveSourceWithAnalyticsViaShortcut =
|
|
|
155
158
|
|
|
156
159
|
// We can move only if there are no merged cells in the source or target row/column
|
|
157
160
|
const hasMergedCellsInSource = isRow
|
|
158
|
-
? hasMergedCellsInRow(
|
|
159
|
-
: hasMergedCellsInColumn(
|
|
161
|
+
? hasMergedCellsInRow(selectedIndexes)(selection)
|
|
162
|
+
: hasMergedCellsInColumn(selectedIndexes)(selection);
|
|
160
163
|
if (hasMergedCellsInSource) {
|
|
161
164
|
return false;
|
|
162
165
|
}
|
|
@@ -171,7 +174,7 @@ export const moveSourceWithAnalyticsViaShortcut =
|
|
|
171
174
|
return moveSourceWithAnalytics(editorAnalyticsAPI)(
|
|
172
175
|
INPUT_METHOD.SHORTCUT,
|
|
173
176
|
sourceType,
|
|
174
|
-
|
|
177
|
+
selectedIndexes,
|
|
175
178
|
targetIndex,
|
|
176
179
|
)(state, dispatch);
|
|
177
180
|
};
|
|
@@ -2,15 +2,9 @@ import type {
|
|
|
2
2
|
EditorState,
|
|
3
3
|
Transaction,
|
|
4
4
|
} from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
5
|
import type { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
7
6
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
-
import {
|
|
9
|
-
moveColumn,
|
|
10
|
-
moveRow,
|
|
11
|
-
selectColumn,
|
|
12
|
-
selectRow,
|
|
13
|
-
} from '@atlaskit/editor-tables/utils';
|
|
7
|
+
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
14
8
|
|
|
15
9
|
import type { DraggableType, TableDirection } from '../../types';
|
|
16
10
|
import { TableDecorations } from '../../types';
|
|
@@ -19,7 +13,6 @@ import {
|
|
|
19
13
|
createRowInsertLine,
|
|
20
14
|
updateDecorations,
|
|
21
15
|
} from '../../utils';
|
|
22
|
-
import { combineTransforms } from '../../utils/transforms';
|
|
23
16
|
|
|
24
17
|
import { DragAndDropActionType } from './actions';
|
|
25
18
|
import { DropTargetType } from './consts';
|
|
@@ -118,31 +111,10 @@ export const moveSource = (
|
|
|
118
111
|
if (sourceIndexes.includes(targetIndex)) {
|
|
119
112
|
return nextTr.setMeta('addToHistory', false);
|
|
120
113
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const isTableRow = sourceType === 'table-row';
|
|
127
|
-
if (isTableRow) {
|
|
128
|
-
return combineTransforms(
|
|
129
|
-
[
|
|
130
|
-
moveRow(state, sourceIndexes, targetIndex),
|
|
131
|
-
selectStartOfTable,
|
|
132
|
-
selectRow(targetIndex),
|
|
133
|
-
],
|
|
134
|
-
nextTr,
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return combineTransforms(
|
|
139
|
-
[
|
|
140
|
-
moveColumn(sourceIndexes, targetIndex),
|
|
141
|
-
selectStartOfTable,
|
|
142
|
-
selectColumn(targetIndex),
|
|
143
|
-
],
|
|
144
|
-
nextTr,
|
|
145
|
-
);
|
|
114
|
+
const move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
115
|
+
return move(state, sourceIndexes, targetIndex, {
|
|
116
|
+
selectAfterMove: true,
|
|
117
|
+
})(nextTr);
|
|
146
118
|
},
|
|
147
119
|
);
|
|
148
120
|
|
|
@@ -82,9 +82,6 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
|
|
|
82
82
|
if (
|
|
83
83
|
!indexes ||
|
|
84
84
|
!localId ||
|
|
85
|
-
// FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
|
|
86
|
-
// of more then 1 item.
|
|
87
|
-
indexes.length !== 1 ||
|
|
88
85
|
!(type === 'table-row' || type === 'table-column')
|
|
89
86
|
) {
|
|
90
87
|
return false;
|
|
@@ -45,11 +45,6 @@ export const getDraggableDataFromEvent = ({
|
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// FIXME: currently we only support a single row/col index being moved, remove this clause when this is no longer the case.
|
|
49
|
-
if (sourceIndexes.length > 1) {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
48
|
const targetClosestEdge =
|
|
54
49
|
extractClosestEdge(destination.data) ??
|
|
55
50
|
((targetType === 'table-row' ? 'top' : 'left') as Edge);
|
package/src/pm-plugins/keymap.ts
CHANGED
|
@@ -34,12 +34,7 @@ import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
|
34
34
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
35
35
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
36
36
|
|
|
37
|
-
import {
|
|
38
|
-
createTable,
|
|
39
|
-
goToNextCell,
|
|
40
|
-
moveCursorBackward,
|
|
41
|
-
triggerUnlessTableHeader,
|
|
42
|
-
} from '../commands';
|
|
37
|
+
import { createTable, goToNextCell, moveCursorBackward } from '../commands';
|
|
43
38
|
import {
|
|
44
39
|
addRowAroundSelection,
|
|
45
40
|
deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut,
|
|
@@ -120,7 +115,7 @@ export function keymapPlugin(
|
|
|
120
115
|
|
|
121
116
|
bindKeymapWithCommand(
|
|
122
117
|
addColumnBefore.common!,
|
|
123
|
-
|
|
118
|
+
addColumnBeforeCommand(getEditorContainerWidth),
|
|
124
119
|
list,
|
|
125
120
|
);
|
|
126
121
|
|
package/src/types.ts
CHANGED
|
@@ -330,6 +330,7 @@ export const TableCssClassName = {
|
|
|
330
330
|
DRAG_COLUMN_CONTROLS_INNER: `${tablePrefixSelector}-col-controls__inner`,
|
|
331
331
|
|
|
332
332
|
DRAG_HANDLE_BUTTON_CONTAINER: `${tablePrefixSelector}-drag-handle-button-container`,
|
|
333
|
+
DRAG_HANDLE_BUTTON_CLICKABLE_ZONE: `${tablePrefixSelector}-drag-handle-button-clickable-zone`,
|
|
333
334
|
|
|
334
335
|
DRAG_CORNER_BUTTON: `${tablePrefixSelector}-drag-corner-button`,
|
|
335
336
|
DRAG_CORNER_BUTTON_INNER: `${tablePrefixSelector}-drag-corner-button-inner`,
|
|
@@ -11,11 +11,13 @@ import { browser } from '@atlaskit/editor-common/utils';
|
|
|
11
11
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
12
12
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
13
13
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
14
|
+
import { token } from '@atlaskit/tokens';
|
|
14
15
|
|
|
15
16
|
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
16
17
|
import type { TableDirection } from '../../types';
|
|
17
18
|
import { TableCssClassName as ClassName } from '../../types';
|
|
18
19
|
import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
20
|
+
import { dragTableInsertColumnButtonSize } from '../consts';
|
|
19
21
|
import { DragPreview } from '../DragPreview';
|
|
20
22
|
|
|
21
23
|
import { HandleIconComponent } from './HandleIconComponent';
|
|
@@ -64,17 +66,18 @@ const DragHandleComponent = ({
|
|
|
64
66
|
const { hoveredColumns, hoveredRows } = getPluginState(editorView.state);
|
|
65
67
|
|
|
66
68
|
const { selection } = editorView.state;
|
|
69
|
+
const isRow = direction === 'row';
|
|
70
|
+
const isColumn = direction === 'column';
|
|
67
71
|
|
|
68
|
-
const isRowHandleHovered =
|
|
69
|
-
const isColumnHandleHovered =
|
|
70
|
-
direction === 'column' && hoveredColumns.length > 0;
|
|
72
|
+
const isRowHandleHovered = isRow && hoveredRows.length > 0;
|
|
73
|
+
const isColumnHandleHovered = isColumn && hoveredColumns.length > 0;
|
|
71
74
|
|
|
72
75
|
const hasMergedCells = useMemo(
|
|
73
76
|
() =>
|
|
74
|
-
|
|
77
|
+
isRow
|
|
75
78
|
? hasMergedCellsInRow(indexes[0])(selection)
|
|
76
79
|
: hasMergedCellsInColumn(indexes[0])(selection),
|
|
77
|
-
[indexes,
|
|
80
|
+
[indexes, isRow, selection],
|
|
78
81
|
);
|
|
79
82
|
|
|
80
83
|
const handleIconProps = {
|
|
@@ -113,7 +116,7 @@ const DragHandleComponent = ({
|
|
|
113
116
|
// be generated.
|
|
114
117
|
container.style.left = `-${rect.width - 0.0001}px`;
|
|
115
118
|
}
|
|
116
|
-
if (
|
|
119
|
+
if (isRow) {
|
|
117
120
|
return { x: 12, y: rect.height / 2 };
|
|
118
121
|
} else {
|
|
119
122
|
return { x: rect.width / 2 + 4, y: 12 };
|
|
@@ -132,18 +135,35 @@ const DragHandleComponent = ({
|
|
|
132
135
|
tableLocalId,
|
|
133
136
|
direction,
|
|
134
137
|
indexes,
|
|
138
|
+
isRow,
|
|
135
139
|
editorView.state.selection,
|
|
136
140
|
hasMergedCells,
|
|
137
141
|
canDrag,
|
|
138
142
|
]);
|
|
139
143
|
|
|
140
|
-
const showDragMenuAnchorId =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
: 'drag-handle-button-column';
|
|
144
|
+
const showDragMenuAnchorId = isRow
|
|
145
|
+
? 'drag-handle-button-row'
|
|
146
|
+
: 'drag-handle-button-column';
|
|
144
147
|
|
|
145
148
|
return (
|
|
146
149
|
<>
|
|
150
|
+
<button
|
|
151
|
+
className={ClassName.DRAG_HANDLE_BUTTON_CLICKABLE_ZONE}
|
|
152
|
+
data-testid="table-drag-handle-clickable-zone-button"
|
|
153
|
+
style={{
|
|
154
|
+
height: isRow
|
|
155
|
+
? `calc(100% - ${dragTableInsertColumnButtonSize}px)`
|
|
156
|
+
: `${token('space.200', '16px')}`, // 16px here because it's the size of drag handle button's large side
|
|
157
|
+
width: isRow
|
|
158
|
+
? `${token('space.200', '16px')}` // 16px here because it's the size of drag handle button's large side
|
|
159
|
+
: `calc(100% - ${dragTableInsertColumnButtonSize}px)`,
|
|
160
|
+
left: isRow ? '3px' : undefined,
|
|
161
|
+
bottom: isColumn ? '0' : undefined,
|
|
162
|
+
alignSelf: isColumn ? 'none' : 'center',
|
|
163
|
+
zIndex: isColumn ? '-1' : 'auto',
|
|
164
|
+
}}
|
|
165
|
+
onClick={onClick}
|
|
166
|
+
/>
|
|
147
167
|
<button
|
|
148
168
|
id={isDragMenuTarget ? showDragMenuAnchorId : undefined}
|
|
149
169
|
className={classnames(
|
|
@@ -155,13 +175,12 @@ const DragHandleComponent = ({
|
|
|
155
175
|
)}
|
|
156
176
|
ref={dragHandleDivRef}
|
|
157
177
|
style={{
|
|
158
|
-
transform:
|
|
178
|
+
transform: isColumn ? 'none' : 'rotate(90deg)',
|
|
179
|
+
alignSelf: isColumn ? 'none' : 'center',
|
|
159
180
|
}}
|
|
160
181
|
data-testid="table-drag-handle-button"
|
|
161
182
|
aria-label={formatMessage(
|
|
162
|
-
|
|
163
|
-
? messages.rowDragHandle
|
|
164
|
-
: messages.columnDragHandle,
|
|
183
|
+
isRow ? messages.rowDragHandle : messages.columnDragHandle,
|
|
165
184
|
)}
|
|
166
185
|
onMouseOver={onMouseOver}
|
|
167
186
|
onMouseOut={onMouseOut}
|
|
@@ -73,7 +73,10 @@ import {
|
|
|
73
73
|
getSelectedColumnIndexes,
|
|
74
74
|
getSelectedRowIndexes,
|
|
75
75
|
} from '../../utils';
|
|
76
|
-
import {
|
|
76
|
+
import {
|
|
77
|
+
contextualMenuDropdownWidth,
|
|
78
|
+
contextualMenuDropdownWidthDnD,
|
|
79
|
+
} from '../consts';
|
|
77
80
|
import {
|
|
78
81
|
AddColRightIcon,
|
|
79
82
|
AddRowBelowIcon,
|
|
@@ -145,7 +148,11 @@ export class ContextualMenu extends Component<
|
|
|
145
148
|
onMouseEnter={this.handleItemMouseEnter}
|
|
146
149
|
onMouseLeave={this.handleItemMouseLeave}
|
|
147
150
|
fitHeight={188}
|
|
148
|
-
fitWidth={
|
|
151
|
+
fitWidth={
|
|
152
|
+
isDragAndDropEnabled
|
|
153
|
+
? contextualMenuDropdownWidthDnD
|
|
154
|
+
: contextualMenuDropdownWidth
|
|
155
|
+
}
|
|
149
156
|
boundariesElement={boundariesElement}
|
|
150
157
|
offset={offset}
|
|
151
158
|
section={
|