@atlaskit/editor-plugin-table 5.3.9 → 5.3.11
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 +12 -0
- package/dist/cjs/plugins/table/commands/hover.js +4 -2
- package/dist/cjs/plugins/table/event-handlers.js +7 -4
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +3 -2
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +11 -25
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +59 -22
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +15 -27
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +68 -18
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +47 -29
- package/dist/cjs/plugins/table/ui/common-styles.js +2 -2
- package/dist/cjs/plugins/table/ui/icons/DragHandleIcon.js +11 -52
- package/dist/es2019/plugins/table/commands/hover.js +4 -2
- package/dist/es2019/plugins/table/event-handlers.js +7 -4
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +3 -2
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +10 -24
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +61 -18
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
- package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +4 -20
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +69 -17
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +24 -2
- package/dist/es2019/plugins/table/ui/common-styles.js +64 -4
- package/dist/es2019/plugins/table/ui/icons/DragHandleIcon.js +11 -52
- package/dist/esm/plugins/table/commands/hover.js +4 -2
- package/dist/esm/plugins/table/event-handlers.js +7 -4
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +3 -2
- package/dist/esm/plugins/table/ui/DragHandle/index.js +11 -25
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +56 -21
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
- package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +16 -28
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +67 -19
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +48 -30
- package/dist/esm/plugins/table/ui/common-styles.js +2 -2
- package/dist/esm/plugins/table/ui/icons/DragHandleIcon.js +11 -51
- package/dist/types/plugins/table/commands/hover.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +8 -4
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +3 -3
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +6 -5
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +3 -2
- package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +1 -1
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +6 -4
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types/plugins/table/ui/icons/DragHandleIcon.d.ts +1 -6
- package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +8 -4
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +3 -3
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +6 -5
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +6 -4
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/ui/icons/DragHandleIcon.d.ts +1 -6
- package/package.json +1 -1
- package/src/__tests__/unit/event-handlers.ts +4 -1
- package/src/__tests__/unit/ui/NumberColumn.tsx +5 -8
- package/src/__tests__/unit/ui/RowDragControls.tsx +6 -0
- package/src/plugins/table/commands/hover.ts +7 -2
- package/src/plugins/table/event-handlers.ts +18 -4
- package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
- package/src/plugins/table/types.ts +13 -4
- package/src/plugins/table/ui/DragHandle/index.tsx +10 -26
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +90 -39
- package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +5 -2
- package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +10 -15
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +97 -28
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +19 -3
- package/src/plugins/table/ui/common-styles.ts +67 -4
- package/src/plugins/table/ui/icons/DragHandleIcon.tsx +5 -69
|
@@ -7,6 +7,7 @@ export interface Props {
|
|
|
7
7
|
hoverRows: (rows: number[], danger?: boolean) => void;
|
|
8
8
|
hoveredRows?: number[];
|
|
9
9
|
selectRow: (row: number, expand: boolean) => void;
|
|
10
|
+
updateCellHoverLocation: (rowIndex: number) => void;
|
|
10
11
|
hasHeaderRow?: boolean;
|
|
11
12
|
isInDanger?: boolean;
|
|
12
13
|
isResizing?: boolean;
|
|
@@ -18,7 +19,6 @@ export default class NumberColumn extends Component<Props, any> {
|
|
|
18
19
|
private hoverRows;
|
|
19
20
|
private selectRow;
|
|
20
21
|
private clearHoverSelection;
|
|
21
|
-
private updateDragHandleLocation;
|
|
22
22
|
private getCellStyles;
|
|
23
23
|
private getClassNames;
|
|
24
24
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import type {
|
|
4
|
+
import type { CellHoverMeta } from '../../../types';
|
|
5
5
|
type DragControlsProps = {
|
|
6
6
|
editorView: EditorView;
|
|
7
7
|
tableRef: HTMLTableElement;
|
|
8
8
|
tableActive?: boolean;
|
|
9
|
-
hoveredCell?:
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
hoveredCell?: CellHoverMeta;
|
|
10
|
+
isInDanger?: boolean;
|
|
11
|
+
hoverRows: (rows: number[], danger?: boolean) => void;
|
|
12
|
+
selectRow: (row: number, expand: boolean) => void;
|
|
13
|
+
updateCellHoverLocation: (rowIndex: number) => void;
|
|
12
14
|
};
|
|
13
15
|
export declare const DragControls: React.FC<import("react-intl-next").WithIntlProps<DragControlsProps & WrappedComponentProps<"intl">>> & {
|
|
14
16
|
WrappedComponent: React.ComponentType<DragControlsProps & WrappedComponentProps<"intl">>;
|
|
@@ -3,7 +3,7 @@ import type { TableColumnOrdering } from '@atlaskit/custom-steps';
|
|
|
3
3
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
import type { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
6
|
-
import type {
|
|
6
|
+
import type { CellHoverMeta } from '../../types';
|
|
7
7
|
export interface Props {
|
|
8
8
|
editorView: EditorView;
|
|
9
9
|
selection?: Selection;
|
|
@@ -18,7 +18,7 @@ export interface Props {
|
|
|
18
18
|
hasHeaderRow?: boolean;
|
|
19
19
|
headerRowHeight?: number;
|
|
20
20
|
hoveredRows?: number[];
|
|
21
|
-
hoveredCell?:
|
|
21
|
+
hoveredCell?: CellHoverMeta;
|
|
22
22
|
ordering?: TableColumnOrdering;
|
|
23
23
|
stickyHeader?: RowStickyState;
|
|
24
24
|
}
|
|
@@ -36,5 +36,6 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
36
36
|
render(): JSX.Element | null;
|
|
37
37
|
private selectRow;
|
|
38
38
|
private hoverRows;
|
|
39
|
+
private updateCellHoverLocation;
|
|
39
40
|
}
|
|
40
41
|
export {};
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
backgroundColor?: string;
|
|
4
|
-
foregroundColor?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const DragHandleIcon: ({ backgroundColor, foregroundColor, }: DragHandleIconProps) => JSX.Element;
|
|
7
|
-
export {};
|
|
2
|
+
export declare const DragHandleIcon: () => JSX.Element;
|
|
@@ -6,4 +6,4 @@ export declare const hoverTable: (isInDanger?: boolean, isSelected?: boolean) =>
|
|
|
6
6
|
export declare const clearHoverSelection: () => import("@atlaskit/editor-common/types").Command;
|
|
7
7
|
export declare const showResizeHandleLine: (cellColumnPositioning: CellColumnPositioning) => import("@atlaskit/editor-common/types").Command;
|
|
8
8
|
export declare const hideResizeHandleLine: () => import("@atlaskit/editor-common/types").Command;
|
|
9
|
-
export declare const hoverCell: (rowIndex?: number, colIndex?: number) => import("@atlaskit/editor-common/types").Command;
|
|
9
|
+
export declare const hoverCell: (rowIndex?: number, colIndex?: number, colWidth?: number, colHeight?: number) => import("@atlaskit/editor-common/types").Command;
|
|
@@ -44,15 +44,17 @@ export interface PluginConfig {
|
|
|
44
44
|
}
|
|
45
45
|
export type { ColumnResizingPluginState } from '@atlaskit/editor-common/types';
|
|
46
46
|
export type CellColumnPositioning = Pick<Rect, 'right' | 'left'>;
|
|
47
|
-
export
|
|
47
|
+
export interface CellHoverMeta {
|
|
48
48
|
colIndex?: number;
|
|
49
49
|
rowIndex?: number;
|
|
50
|
-
|
|
50
|
+
colWidth?: number;
|
|
51
|
+
colHeight?: number;
|
|
52
|
+
}
|
|
51
53
|
export interface TablePluginState {
|
|
52
54
|
editorHasFocus?: boolean;
|
|
53
55
|
hoveredColumns: number[];
|
|
54
56
|
hoveredRows: number[];
|
|
55
|
-
hoveredCell:
|
|
57
|
+
hoveredCell: CellHoverMeta;
|
|
56
58
|
pluginConfig: PluginConfig;
|
|
57
59
|
isHeaderColumnEnabled: boolean;
|
|
58
60
|
isHeaderRowEnabled: boolean;
|
|
@@ -170,7 +172,9 @@ export type TablePluginAction = {
|
|
|
170
172
|
};
|
|
171
173
|
} | {
|
|
172
174
|
type: 'HOVER_CELL';
|
|
173
|
-
data:
|
|
175
|
+
data: {
|
|
176
|
+
hoveredCell: CellHoverMeta;
|
|
177
|
+
};
|
|
174
178
|
} | {
|
|
175
179
|
type: 'SET_TARGET_CELL_POSITION';
|
|
176
180
|
data: {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { MouseEventHandler } from 'react';
|
|
2
|
-
type
|
|
2
|
+
type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
|
|
3
3
|
type DragHandleProps = {
|
|
4
4
|
tableLocalId: string;
|
|
5
5
|
indexes: number[];
|
|
6
6
|
previewWidth?: number;
|
|
7
7
|
previewHeight?: number;
|
|
8
8
|
direction?: 'column' | 'row';
|
|
9
|
-
|
|
9
|
+
appearance?: DragHandleAppearance;
|
|
10
10
|
onClick?: MouseEventHandler;
|
|
11
11
|
onMouseOver?: MouseEventHandler;
|
|
12
12
|
onMouseOut?: MouseEventHandler;
|
|
13
13
|
};
|
|
14
|
-
export declare const DragHandle: ({ tableLocalId, direction,
|
|
14
|
+
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onClick, }: DragHandleProps) => JSX.Element;
|
|
15
15
|
export {};
|
package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import type {
|
|
4
|
-
export interface
|
|
3
|
+
import type { CellHoverMeta } from '../../../types';
|
|
4
|
+
export interface ColumnControlsProps {
|
|
5
5
|
editorView: EditorView;
|
|
6
6
|
tableActive?: boolean;
|
|
7
|
+
isInDanger?: boolean;
|
|
7
8
|
tableRef: HTMLTableElement;
|
|
8
|
-
hoveredCell?:
|
|
9
|
+
hoveredCell?: CellHoverMeta;
|
|
9
10
|
isResizing?: boolean;
|
|
10
11
|
stickyTop?: number;
|
|
11
12
|
localId?: string;
|
|
12
13
|
rowHeights?: number[];
|
|
13
14
|
colWidths?: (number | undefined)[];
|
|
14
15
|
}
|
|
15
|
-
export declare const ColumnControls:
|
|
16
|
+
export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, }: ColumnControlsProps) => JSX.Element;
|
|
16
17
|
export default ColumnControls;
|
|
@@ -5,7 +5,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
5
5
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
6
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
7
|
import type { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
8
|
-
import type {
|
|
8
|
+
import type { CellHoverMeta } from '../../types';
|
|
9
9
|
export interface Props {
|
|
10
10
|
editorView: EditorView;
|
|
11
11
|
getEditorFeatureFlags: GetEditorFeatureFlags;
|
|
@@ -13,10 +13,11 @@ export interface Props {
|
|
|
13
13
|
tableRef?: HTMLTableElement;
|
|
14
14
|
getNode: () => PmNode;
|
|
15
15
|
tableActive?: boolean;
|
|
16
|
+
isInDanger?: boolean;
|
|
16
17
|
hasHeaderRow?: boolean;
|
|
17
18
|
headerRowHeight?: number;
|
|
18
19
|
hoveredRows?: number[];
|
|
19
|
-
hoveredCell?:
|
|
20
|
+
hoveredCell?: CellHoverMeta;
|
|
20
21
|
isResizing?: boolean;
|
|
21
22
|
ordering?: TableColumnOrdering;
|
|
22
23
|
stickyHeader?: RowStickyState;
|
|
@@ -7,6 +7,7 @@ export interface Props {
|
|
|
7
7
|
hoverRows: (rows: number[], danger?: boolean) => void;
|
|
8
8
|
hoveredRows?: number[];
|
|
9
9
|
selectRow: (row: number, expand: boolean) => void;
|
|
10
|
+
updateCellHoverLocation: (rowIndex: number) => void;
|
|
10
11
|
hasHeaderRow?: boolean;
|
|
11
12
|
isInDanger?: boolean;
|
|
12
13
|
isResizing?: boolean;
|
|
@@ -18,7 +19,6 @@ export default class NumberColumn extends Component<Props, any> {
|
|
|
18
19
|
private hoverRows;
|
|
19
20
|
private selectRow;
|
|
20
21
|
private clearHoverSelection;
|
|
21
|
-
private updateDragHandleLocation;
|
|
22
22
|
private getCellStyles;
|
|
23
23
|
private getClassNames;
|
|
24
24
|
}
|
package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import type {
|
|
4
|
+
import type { CellHoverMeta } from '../../../types';
|
|
5
5
|
type DragControlsProps = {
|
|
6
6
|
editorView: EditorView;
|
|
7
7
|
tableRef: HTMLTableElement;
|
|
8
8
|
tableActive?: boolean;
|
|
9
|
-
hoveredCell?:
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
hoveredCell?: CellHoverMeta;
|
|
10
|
+
isInDanger?: boolean;
|
|
11
|
+
hoverRows: (rows: number[], danger?: boolean) => void;
|
|
12
|
+
selectRow: (row: number, expand: boolean) => void;
|
|
13
|
+
updateCellHoverLocation: (rowIndex: number) => void;
|
|
12
14
|
};
|
|
13
15
|
export declare const DragControls: React.FC<import("react-intl-next").WithIntlProps<DragControlsProps & WrappedComponentProps<"intl">>> & {
|
|
14
16
|
WrappedComponent: React.ComponentType<DragControlsProps & WrappedComponentProps<"intl">>;
|
|
@@ -3,7 +3,7 @@ import type { TableColumnOrdering } from '@atlaskit/custom-steps';
|
|
|
3
3
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
import type { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
6
|
-
import type {
|
|
6
|
+
import type { CellHoverMeta } from '../../types';
|
|
7
7
|
export interface Props {
|
|
8
8
|
editorView: EditorView;
|
|
9
9
|
selection?: Selection;
|
|
@@ -18,7 +18,7 @@ export interface Props {
|
|
|
18
18
|
hasHeaderRow?: boolean;
|
|
19
19
|
headerRowHeight?: number;
|
|
20
20
|
hoveredRows?: number[];
|
|
21
|
-
hoveredCell?:
|
|
21
|
+
hoveredCell?: CellHoverMeta;
|
|
22
22
|
ordering?: TableColumnOrdering;
|
|
23
23
|
stickyHeader?: RowStickyState;
|
|
24
24
|
}
|
|
@@ -36,5 +36,6 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
36
36
|
render(): JSX.Element | null;
|
|
37
37
|
private selectRow;
|
|
38
38
|
private hoverRows;
|
|
39
|
+
private updateCellHoverLocation;
|
|
39
40
|
}
|
|
40
41
|
export {};
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
backgroundColor?: string;
|
|
4
|
-
foregroundColor?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const DragHandleIcon: ({ backgroundColor, foregroundColor, }: DragHandleIconProps) => JSX.Element;
|
|
7
|
-
export {};
|
|
2
|
+
export declare const DragHandleIcon: () => JSX.Element;
|
package/package.json
CHANGED
|
@@ -301,7 +301,10 @@ describe('withCellTracking', () => {
|
|
|
301
301
|
withCellTracking(jest.fn())(editorView, event as any);
|
|
302
302
|
|
|
303
303
|
const pluginState = getPluginState(editorView.state);
|
|
304
|
-
expect(pluginState.hoveredCell).toEqual({
|
|
304
|
+
expect(pluginState.hoveredCell).toEqual({
|
|
305
|
+
colIndex: undefined,
|
|
306
|
+
rowIndex: undefined,
|
|
307
|
+
});
|
|
305
308
|
});
|
|
306
309
|
});
|
|
307
310
|
});
|
|
@@ -27,9 +27,7 @@ import {
|
|
|
27
27
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
28
28
|
|
|
29
29
|
import tablePlugin from '../../../plugins/table-plugin';
|
|
30
|
-
import { getPluginState } from '../../../plugins/table/pm-plugins/plugin-factory';
|
|
31
30
|
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
32
|
-
// import type { TablePluginState } from '../../../plugins/table/types';
|
|
33
31
|
import { TableCssClassName as ClassName } from '../../../plugins/table/types';
|
|
34
32
|
import NumberColumn from '../../../plugins/table/ui/TableFloatingControls/NumberColumn';
|
|
35
33
|
|
|
@@ -55,6 +53,7 @@ describe('NumberColumn', () => {
|
|
|
55
53
|
doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
|
|
56
54
|
{ dragAndDropEnabled: true },
|
|
57
55
|
);
|
|
56
|
+
const hoverCellLocationMock = jest.fn();
|
|
58
57
|
const ref = editorView.dom.querySelector('table');
|
|
59
58
|
|
|
60
59
|
const { container } = render(
|
|
@@ -65,6 +64,7 @@ describe('NumberColumn', () => {
|
|
|
65
64
|
editorView={editorView}
|
|
66
65
|
hoverRows={jest.fn()}
|
|
67
66
|
selectRow={jest.fn()}
|
|
67
|
+
updateCellHoverLocation={hoverCellLocationMock}
|
|
68
68
|
isDragAndDropEnabled
|
|
69
69
|
/>
|
|
70
70
|
</IntlProvider>,
|
|
@@ -76,12 +76,7 @@ describe('NumberColumn', () => {
|
|
|
76
76
|
|
|
77
77
|
fireEvent.mouseOver(firstNumberedCell!);
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
// colIndex is not defined yet, keep undefined
|
|
81
|
-
expect(pluginState.hoveredCell).toEqual({
|
|
82
|
-
colIndex: undefined,
|
|
83
|
-
rowIndex: 0,
|
|
84
|
-
});
|
|
79
|
+
expect(hoverCellLocationMock).toHaveBeenCalledWith(0);
|
|
85
80
|
});
|
|
86
81
|
|
|
87
82
|
it('should render button disabled numbered column cells - when drag and drop is enabled', () => {
|
|
@@ -99,6 +94,7 @@ describe('NumberColumn', () => {
|
|
|
99
94
|
editorView={editorView}
|
|
100
95
|
hoverRows={jest.fn()}
|
|
101
96
|
selectRow={jest.fn()}
|
|
97
|
+
updateCellHoverLocation={jest.fn()}
|
|
102
98
|
isDragAndDropEnabled
|
|
103
99
|
/>
|
|
104
100
|
</IntlProvider>,
|
|
@@ -130,6 +126,7 @@ describe('NumberColumn', () => {
|
|
|
130
126
|
editorView={editorView}
|
|
131
127
|
hoverRows={jest.fn()}
|
|
132
128
|
selectRow={jest.fn()}
|
|
129
|
+
updateCellHoverLocation={jest.fn()}
|
|
133
130
|
isDragAndDropEnabled={false}
|
|
134
131
|
/>
|
|
135
132
|
</IntlProvider>,
|
|
@@ -70,6 +70,9 @@ describe('NumberColumn', () => {
|
|
|
70
70
|
tableActive
|
|
71
71
|
editorView={editorView}
|
|
72
72
|
hoveredCell={{ rowIndex: 1, colIndex: 1 }}
|
|
73
|
+
hoverRows={jest.fn()}
|
|
74
|
+
selectRow={jest.fn()}
|
|
75
|
+
updateCellHoverLocation={jest.fn()}
|
|
73
76
|
/>
|
|
74
77
|
</IntlProvider>,
|
|
75
78
|
);
|
|
@@ -105,6 +108,9 @@ describe('NumberColumn', () => {
|
|
|
105
108
|
colIndex: undefined,
|
|
106
109
|
rowIndex: undefined,
|
|
107
110
|
}}
|
|
111
|
+
hoverRows={jest.fn()}
|
|
112
|
+
selectRow={jest.fn()}
|
|
113
|
+
updateCellHoverLocation={jest.fn()}
|
|
108
114
|
/>
|
|
109
115
|
</IntlProvider>,
|
|
110
116
|
);
|
|
@@ -191,13 +191,18 @@ export const hideResizeHandleLine = () =>
|
|
|
191
191
|
},
|
|
192
192
|
}));
|
|
193
193
|
|
|
194
|
-
export const hoverCell = (
|
|
194
|
+
export const hoverCell = (
|
|
195
|
+
rowIndex?: number,
|
|
196
|
+
colIndex?: number,
|
|
197
|
+
colWidth?: number,
|
|
198
|
+
colHeight?: number,
|
|
199
|
+
) =>
|
|
195
200
|
createCommand(
|
|
196
201
|
() => {
|
|
197
202
|
return {
|
|
198
203
|
type: 'HOVER_CELL',
|
|
199
204
|
data: {
|
|
200
|
-
hoveredCell: { rowIndex, colIndex },
|
|
205
|
+
hoveredCell: { rowIndex, colIndex, colWidth, colHeight },
|
|
201
206
|
},
|
|
202
207
|
};
|
|
203
208
|
},
|
|
@@ -288,7 +288,7 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
|
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
if (isDragAndDropEnabled) {
|
|
291
|
-
hoverCell(
|
|
291
|
+
hoverCell()(state, dispatch);
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
if (
|
|
@@ -512,8 +512,9 @@ const trackCellLocation = (view: EditorView, mouseEvent: Event) => {
|
|
|
512
512
|
const maybeTableCell = isElementInTableCell(
|
|
513
513
|
target as HTMLElement,
|
|
514
514
|
) as HTMLTableCellElement | null;
|
|
515
|
+
const tableRef = getPluginState(view.state).tableRef;
|
|
515
516
|
|
|
516
|
-
if (!maybeTableCell) {
|
|
517
|
+
if (!maybeTableCell || !tableRef) {
|
|
517
518
|
return;
|
|
518
519
|
}
|
|
519
520
|
|
|
@@ -525,8 +526,21 @@ const trackCellLocation = (view: EditorView, mouseEvent: Event) => {
|
|
|
525
526
|
const rowIndex = rowElement && rowElement.rowIndex;
|
|
526
527
|
const { hoveredCell } = getPluginState(view.state);
|
|
527
528
|
|
|
528
|
-
|
|
529
|
-
|
|
529
|
+
const colHeight = tableRef.offsetHeight;
|
|
530
|
+
const colWidth = maybeTableCell.offsetWidth;
|
|
531
|
+
|
|
532
|
+
if (
|
|
533
|
+
hoveredCell.colIndex !== colIndex ||
|
|
534
|
+
hoveredCell.rowIndex !== rowIndex ||
|
|
535
|
+
hoveredCell.colWidth !== colWidth ||
|
|
536
|
+
hoveredCell.colHeight !== colHeight
|
|
537
|
+
) {
|
|
538
|
+
hoverCell(
|
|
539
|
+
rowIndex,
|
|
540
|
+
colIndex,
|
|
541
|
+
colWidth,
|
|
542
|
+
colHeight,
|
|
543
|
+
)(view.state, view.dispatch);
|
|
530
544
|
}
|
|
531
545
|
};
|
|
532
546
|
|
|
@@ -435,12 +435,13 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
435
435
|
</div>
|
|
436
436
|
);
|
|
437
437
|
|
|
438
|
-
const colControls = (
|
|
438
|
+
const colControls = isDragAndDropEnabled ? (
|
|
439
439
|
<TableFloatingColumnControls
|
|
440
440
|
editorView={view}
|
|
441
441
|
tableRef={tableRef}
|
|
442
442
|
getNode={getNode}
|
|
443
443
|
tableActive={tableActive}
|
|
444
|
+
isInDanger={isInDanger}
|
|
444
445
|
hoveredRows={hoveredRows}
|
|
445
446
|
hoveredCell={hoveredCell}
|
|
446
447
|
isResizing={isResizing}
|
|
@@ -452,7 +453,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
452
453
|
stickyHeader={this.state.stickyHeader}
|
|
453
454
|
getEditorFeatureFlags={this.props.getEditorFeatureFlags}
|
|
454
455
|
/>
|
|
455
|
-
);
|
|
456
|
+
) : null;
|
|
456
457
|
|
|
457
458
|
const shadowPadding =
|
|
458
459
|
allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
|
|
@@ -85,14 +85,18 @@ export type { ColumnResizingPluginState } from '@atlaskit/editor-common/types';
|
|
|
85
85
|
*
|
|
86
86
|
*/
|
|
87
87
|
export type CellColumnPositioning = Pick<Rect, 'right' | 'left'>;
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
export interface CellHoverMeta {
|
|
89
|
+
colIndex?: number;
|
|
90
|
+
rowIndex?: number;
|
|
91
|
+
colWidth?: number;
|
|
92
|
+
colHeight?: number;
|
|
93
|
+
}
|
|
90
94
|
|
|
91
95
|
export interface TablePluginState {
|
|
92
96
|
editorHasFocus?: boolean;
|
|
93
97
|
hoveredColumns: number[];
|
|
94
98
|
hoveredRows: number[];
|
|
95
|
-
hoveredCell:
|
|
99
|
+
hoveredCell: CellHoverMeta;
|
|
96
100
|
pluginConfig: PluginConfig;
|
|
97
101
|
isHeaderColumnEnabled: boolean;
|
|
98
102
|
isHeaderRowEnabled: boolean;
|
|
@@ -200,7 +204,12 @@ export type TablePluginAction =
|
|
|
200
204
|
| { type: 'CLEAR_HOVER_SELECTION'; data: { decorationSet: DecorationSet } }
|
|
201
205
|
| { type: 'SHOW_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
|
|
202
206
|
| { type: 'HIDE_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
|
|
203
|
-
| {
|
|
207
|
+
| {
|
|
208
|
+
type: 'HOVER_CELL';
|
|
209
|
+
data: {
|
|
210
|
+
hoveredCell: CellHoverMeta;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
204
213
|
| { type: 'SET_TARGET_CELL_POSITION'; data: { targetCellPosition?: number } }
|
|
205
214
|
| {
|
|
206
215
|
type: 'SELECT_COLUMN';
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type { MouseEventHandler } from 'react';
|
|
2
2
|
import React, { useEffect, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
|
+
import classnames from 'classnames';
|
|
4
5
|
import ReactDOM from 'react-dom';
|
|
5
6
|
|
|
6
7
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
7
8
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
8
|
-
import { N200, N700 } from '@atlaskit/theme/colors';
|
|
9
|
-
import { token } from '@atlaskit/tokens';
|
|
10
9
|
|
|
11
10
|
import { TableCssClassName as ClassName } from '../../types';
|
|
12
11
|
import { DragPreview } from '../DragPreview';
|
|
13
12
|
import { DragHandleIcon } from '../icons';
|
|
14
13
|
|
|
15
|
-
type
|
|
14
|
+
type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
|
|
16
15
|
|
|
17
16
|
type DragHandleProps = {
|
|
18
17
|
tableLocalId: string;
|
|
@@ -20,39 +19,24 @@ type DragHandleProps = {
|
|
|
20
19
|
previewWidth?: number;
|
|
21
20
|
previewHeight?: number;
|
|
22
21
|
direction?: 'column' | 'row';
|
|
23
|
-
|
|
22
|
+
appearance?: DragHandleAppearance;
|
|
24
23
|
onClick?: MouseEventHandler;
|
|
25
24
|
onMouseOver?: MouseEventHandler;
|
|
26
25
|
onMouseOut?: MouseEventHandler;
|
|
27
26
|
};
|
|
28
27
|
|
|
29
|
-
const mapStateToProps = (state: DragHandleState) => {
|
|
30
|
-
switch (state) {
|
|
31
|
-
case 'danger':
|
|
32
|
-
case 'disabled':
|
|
33
|
-
case 'selected':
|
|
34
|
-
case 'default':
|
|
35
|
-
default:
|
|
36
|
-
return {
|
|
37
|
-
backgroundColor: token('color.background.accent.gray.subtlest', N200),
|
|
38
|
-
foregroundColor: token('color.icon.subtle', N700),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
28
|
export const DragHandle = ({
|
|
44
29
|
tableLocalId,
|
|
45
30
|
direction = 'row',
|
|
46
|
-
|
|
31
|
+
appearance = 'default',
|
|
47
32
|
indexes,
|
|
48
33
|
previewWidth,
|
|
49
34
|
previewHeight,
|
|
50
|
-
onClick,
|
|
51
35
|
onMouseOver,
|
|
52
36
|
onMouseOut,
|
|
37
|
+
onClick,
|
|
53
38
|
}: DragHandleProps) => {
|
|
54
39
|
const dragHandleDivRef = useRef<HTMLButtonElement>(null);
|
|
55
|
-
const iconProps = mapStateToProps(state);
|
|
56
40
|
const [previewContainer, setPreviewContainer] = useState<HTMLElement | null>(
|
|
57
41
|
null,
|
|
58
42
|
);
|
|
@@ -92,18 +76,18 @@ export const DragHandle = ({
|
|
|
92
76
|
|
|
93
77
|
return (
|
|
94
78
|
<button
|
|
95
|
-
className={ClassName.DRAG_HANDLE_BUTTON_CONTAINER}
|
|
79
|
+
className={classnames(ClassName.DRAG_HANDLE_BUTTON_CONTAINER, appearance)}
|
|
96
80
|
ref={dragHandleDivRef}
|
|
97
81
|
style={{
|
|
98
|
-
backgroundColor: `${token('elevation.surface', 'white')}`,
|
|
99
|
-
borderRadius: '4px',
|
|
100
|
-
border: `2px solid ${token('elevation.surface', 'white')}`,
|
|
101
82
|
transform: direction === 'column' ? 'none' : 'rotate(90deg)',
|
|
102
83
|
pointerEvents: 'auto',
|
|
103
84
|
}}
|
|
104
85
|
data-testid="table-floating-column-controls-drag-handle"
|
|
86
|
+
onMouseOver={onMouseOver}
|
|
87
|
+
onMouseOut={onMouseOut}
|
|
88
|
+
onClick={onClick}
|
|
105
89
|
>
|
|
106
|
-
<DragHandleIcon
|
|
90
|
+
<DragHandleIcon />
|
|
107
91
|
{previewContainer &&
|
|
108
92
|
previewWidth !== undefined &&
|
|
109
93
|
previewHeight !== undefined &&
|