@atlaskit/editor-plugin-table 5.3.1 → 5.3.2
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 +6 -0
- package/dist/cjs/plugins/table/commands/hover.js +17 -8
- package/dist/cjs/plugins/table/commands/index.js +6 -0
- package/dist/cjs/plugins/table/commands/misc.js +1 -7
- package/dist/cjs/plugins/table/event-handlers.js +29 -2
- package/dist/cjs/plugins/table/index.js +1 -1
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +7 -3
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/cjs/plugins/table/pm-plugins/default-table-selection.js +14 -1
- package/dist/cjs/plugins/table/pm-plugins/main.js +5 -5
- package/dist/cjs/plugins/table/reducer.js +2 -1
- package/dist/cjs/plugins/table/types.js +6 -0
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +53 -14
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +114 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +53 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +11 -106
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +16 -6
- package/dist/cjs/plugins/table/ui/common-styles.js +9 -6
- package/dist/cjs/plugins/table/ui/consts.js +2 -1
- package/dist/cjs/plugins/table/ui/ui-styles.js +18 -9
- package/dist/cjs/plugins/table/utils/decoration.js +44 -18
- package/dist/cjs/plugins/table/utils/dom.js +7 -1
- package/dist/cjs/plugins/table/utils/index.js +12 -0
- package/dist/es2019/plugins/table/commands/hover.js +12 -8
- package/dist/es2019/plugins/table/commands/index.js +1 -1
- package/dist/es2019/plugins/table/commands/misc.js +1 -7
- package/dist/es2019/plugins/table/event-handlers.js +28 -2
- package/dist/es2019/plugins/table/index.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +8 -6
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +13 -0
- package/dist/es2019/plugins/table/pm-plugins/main.js +6 -5
- package/dist/es2019/plugins/table/reducer.js +2 -1
- package/dist/es2019/plugins/table/types.js +6 -0
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -10
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +86 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +43 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -88
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +17 -7
- package/dist/es2019/plugins/table/ui/common-styles.js +47 -12
- package/dist/es2019/plugins/table/ui/consts.js +1 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +57 -14
- package/dist/es2019/plugins/table/utils/decoration.js +44 -18
- package/dist/es2019/plugins/table/utils/dom.js +2 -0
- package/dist/es2019/plugins/table/utils/index.js +1 -1
- package/dist/esm/plugins/table/commands/hover.js +16 -8
- package/dist/esm/plugins/table/commands/index.js +1 -1
- package/dist/esm/plugins/table/commands/misc.js +1 -7
- package/dist/esm/plugins/table/event-handlers.js +29 -2
- package/dist/esm/plugins/table/index.js +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/esm/plugins/table/nodeviews/table.js +4 -2
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +8 -6
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +13 -0
- package/dist/esm/plugins/table/pm-plugins/main.js +7 -7
- package/dist/esm/plugins/table/reducer.js +2 -1
- package/dist/esm/plugins/table/types.js +6 -0
- package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -15
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +104 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -104
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +17 -7
- package/dist/esm/plugins/table/ui/common-styles.js +10 -7
- package/dist/esm/plugins/table/ui/consts.js +1 -0
- package/dist/esm/plugins/table/ui/ui-styles.js +18 -9
- package/dist/esm/plugins/table/utils/decoration.js +44 -18
- package/dist/esm/plugins/table/utils/dom.js +6 -0
- package/dist/esm/plugins/table/utils/index.js +1 -1
- package/dist/types/plugins/table/commands/hover.d.ts +2 -1
- package/dist/types/plugins/table/commands/index.d.ts +1 -1
- package/dist/types/plugins/table/event-handlers.d.ts +1 -0
- package/dist/types/plugins/table/nodeviews/types.d.ts +4 -3
- package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
- package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
- package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +16 -1
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types/plugins/table/utils/decoration.d.ts +2 -2
- package/dist/types/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types/plugins/table/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +4 -3
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +16 -1
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -2
- package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
- package/package.json +3 -2
- package/src/__tests__/unit/event-handlers.ts +74 -1
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +35 -15
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +146 -42
- package/src/__tests__/unit/ui/NumberColumn.tsx +148 -0
- package/src/__tests__/unit/ui/RowControls.tsx +4 -4
- package/src/__tests__/unit/ui/RowDragControls.tsx +118 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +9 -5
- package/src/plugins/table/commands/hover.ts +16 -7
- package/src/plugins/table/commands/index.ts +1 -0
- package/src/plugins/table/commands/misc.ts +0 -5
- package/src/plugins/table/event-handlers.ts +49 -2
- package/src/plugins/table/index.tsx +1 -1
- package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
- package/src/plugins/table/nodeviews/table.tsx +2 -0
- package/src/plugins/table/nodeviews/types.ts +4 -3
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +13 -4
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +10 -5
- package/src/plugins/table/pm-plugins/default-table-selection.ts +10 -0
- package/src/plugins/table/pm-plugins/main.ts +9 -4
- package/src/plugins/table/reducer.ts +2 -1
- package/src/plugins/table/types.ts +14 -2
- package/src/plugins/table/ui/DragHandle/index.tsx +57 -0
- package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +68 -30
- package/src/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.tsx +129 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +75 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +2 -135
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +43 -24
- package/src/plugins/table/ui/common-styles.ts +52 -11
- package/src/plugins/table/ui/consts.ts +1 -0
- package/src/plugins/table/ui/ui-styles.ts +58 -14
- package/src/plugins/table/utils/decoration.ts +75 -27
- package/src/plugins/table/utils/dom.ts +8 -0
- package/src/plugins/table/utils/index.ts +2 -0
- package/tsconfig.app.json +3 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
5
|
+
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
|
|
8
|
+
import { clearHoverSelection } from '../../../commands';
|
|
9
|
+
import { TableCssClassName as ClassName } from '../../../types';
|
|
10
|
+
import type { RowParams } from '../../../utils';
|
|
11
|
+
import { getRowClassNames, getRowHeights, getRowsParams } from '../../../utils';
|
|
12
|
+
import { tableControlsSpacing, tableToolbarSize } from '../../consts';
|
|
13
|
+
|
|
14
|
+
const messages = defineMessages({
|
|
15
|
+
rowControl: {
|
|
16
|
+
id: 'fabric.editor.rowControl',
|
|
17
|
+
defaultMessage: 'Highlight row',
|
|
18
|
+
description:
|
|
19
|
+
'A button on the left of each row that shows up when the table is in focus. Clicking on it will select the entire row.',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export interface Props {
|
|
24
|
+
editorView: EditorView;
|
|
25
|
+
tableRef: HTMLTableElement;
|
|
26
|
+
selectRow: (row: number, expand: boolean) => void;
|
|
27
|
+
hoverRows: (rows: number[], danger?: boolean) => void;
|
|
28
|
+
hoveredRows?: number[];
|
|
29
|
+
isInDanger?: boolean;
|
|
30
|
+
isResizing?: boolean;
|
|
31
|
+
insertRowButtonIndex?: number;
|
|
32
|
+
stickyTop?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class RowControlsComponent extends Component<Props & WrappedComponentProps> {
|
|
36
|
+
render() {
|
|
37
|
+
const {
|
|
38
|
+
editorView,
|
|
39
|
+
tableRef,
|
|
40
|
+
hoveredRows,
|
|
41
|
+
isInDanger,
|
|
42
|
+
isResizing,
|
|
43
|
+
intl: { formatMessage },
|
|
44
|
+
} = this.props;
|
|
45
|
+
if (!tableRef) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const { selection } = editorView.state;
|
|
49
|
+
const rowHeights = getRowHeights(tableRef);
|
|
50
|
+
const rowsParams = getRowsParams(rowHeights);
|
|
51
|
+
|
|
52
|
+
const firstRow = tableRef.querySelector('tr');
|
|
53
|
+
const hasHeaderRow = firstRow
|
|
54
|
+
? firstRow.getAttribute('data-header-row')
|
|
55
|
+
: false;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div className={ClassName.ROW_CONTROLS}>
|
|
59
|
+
<div className={ClassName.ROW_CONTROLS_INNER}>
|
|
60
|
+
{rowsParams.map(
|
|
61
|
+
({ startIndex, endIndex, height }: RowParams, index) => {
|
|
62
|
+
// if previous row was header row, add its height to our margin
|
|
63
|
+
let marginTop = -1;
|
|
64
|
+
if (
|
|
65
|
+
index === 1 &&
|
|
66
|
+
hasHeaderRow &&
|
|
67
|
+
this.props.stickyTop !== undefined
|
|
68
|
+
) {
|
|
69
|
+
marginTop += rowHeights[index - 1] + tableToolbarSize;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const thisRowSticky =
|
|
73
|
+
this.props.stickyTop !== undefined &&
|
|
74
|
+
index === 0 &&
|
|
75
|
+
hasHeaderRow;
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div
|
|
79
|
+
className={`${
|
|
80
|
+
ClassName.ROW_CONTROLS_BUTTON_WRAP
|
|
81
|
+
} ${getRowClassNames(
|
|
82
|
+
startIndex,
|
|
83
|
+
selection,
|
|
84
|
+
hoveredRows,
|
|
85
|
+
isInDanger,
|
|
86
|
+
isResizing,
|
|
87
|
+
)} ${thisRowSticky ? 'sticky' : ''}`}
|
|
88
|
+
key={startIndex}
|
|
89
|
+
style={{
|
|
90
|
+
height: height,
|
|
91
|
+
marginTop: `${marginTop}px`,
|
|
92
|
+
top: thisRowSticky
|
|
93
|
+
? `${this.props.stickyTop! + 3}px`
|
|
94
|
+
: undefined,
|
|
95
|
+
paddingTop: thisRowSticky
|
|
96
|
+
? `${tableControlsSpacing}px`
|
|
97
|
+
: undefined,
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<button
|
|
101
|
+
aria-label={formatMessage(messages.rowControl)}
|
|
102
|
+
type="button"
|
|
103
|
+
className={`${ClassName.ROW_CONTROLS_BUTTON} ${ClassName.CONTROLS_BUTTON}`}
|
|
104
|
+
onClick={(event) =>
|
|
105
|
+
this.props.selectRow(startIndex, event.shiftKey)
|
|
106
|
+
}
|
|
107
|
+
onMouseOver={() => this.props.hoverRows([startIndex])}
|
|
108
|
+
onMouseOut={this.clearHoverSelection}
|
|
109
|
+
data-start-index={startIndex}
|
|
110
|
+
data-end-index={endIndex}
|
|
111
|
+
/>
|
|
112
|
+
|
|
113
|
+
<div className={ClassName.CONTROLS_INSERT_MARKER} />
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
},
|
|
117
|
+
)}
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private clearHoverSelection = () => {
|
|
124
|
+
const { state, dispatch } = this.props.editorView;
|
|
125
|
+
clearHoverSelection()(state, dispatch);
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const RowControls = injectIntl(RowControlsComponent);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { injectIntl } from 'react-intl-next';
|
|
4
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
5
|
+
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
8
|
+
|
|
9
|
+
import type { CellHoverCoordinates } from '../../../types';
|
|
10
|
+
import { TableCssClassName as ClassName } from '../../../types';
|
|
11
|
+
import { getRowHeights } from '../../../utils';
|
|
12
|
+
import { DragHandle } from '../../DragHandle';
|
|
13
|
+
|
|
14
|
+
type DragControlsProps = {
|
|
15
|
+
editorView: EditorView;
|
|
16
|
+
tableRef: HTMLTableElement;
|
|
17
|
+
tableActive?: boolean;
|
|
18
|
+
hoveredCell?: CellHoverCoordinates;
|
|
19
|
+
hoverRows?: (rows: number[], danger?: boolean) => void;
|
|
20
|
+
selectRow?: (row: number, expand: boolean) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const DragControlsComponent = ({
|
|
24
|
+
tableRef,
|
|
25
|
+
hoveredCell,
|
|
26
|
+
hoverRows,
|
|
27
|
+
selectRow,
|
|
28
|
+
tableActive,
|
|
29
|
+
editorView,
|
|
30
|
+
}: DragControlsProps & WrappedComponentProps) => {
|
|
31
|
+
const rowHeights = getRowHeights(tableRef);
|
|
32
|
+
const heights = rowHeights.map((height) => `${height - 1}px`).join(' ');
|
|
33
|
+
|
|
34
|
+
const onClick = (
|
|
35
|
+
index: number,
|
|
36
|
+
event: React.MouseEvent<Element, MouseEvent>,
|
|
37
|
+
) => {};
|
|
38
|
+
|
|
39
|
+
const onMouseOver = () => {};
|
|
40
|
+
const onMouseOut = () => {};
|
|
41
|
+
|
|
42
|
+
const rowIndex = hoveredCell?.rowIndex;
|
|
43
|
+
|
|
44
|
+
const getLocalId = () => {
|
|
45
|
+
const tableNode = findTable(editorView.state.selection);
|
|
46
|
+
return tableNode?.node?.attrs?.localId || '';
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div
|
|
51
|
+
className={ClassName.ROW_CONTROLS_WITH_DRAG}
|
|
52
|
+
style={{
|
|
53
|
+
gridTemplateRows: heights,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{Number.isFinite(rowIndex) && (
|
|
57
|
+
<div
|
|
58
|
+
style={{
|
|
59
|
+
gridRow: `${(rowIndex as number) + 1} / span 1`,
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<DragHandle
|
|
63
|
+
onClick={(event) => onClick(rowIndex as number, event)}
|
|
64
|
+
onMouseOver={onMouseOver}
|
|
65
|
+
onMouseOut={onMouseOut}
|
|
66
|
+
tableLocalId={getLocalId()}
|
|
67
|
+
indexes={[]}
|
|
68
|
+
/>
|
|
69
|
+
</div>
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const DragControls = injectIntl(DragControlsComponent);
|
|
@@ -1,135 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
-
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
5
|
-
|
|
6
|
-
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
-
|
|
8
|
-
import { clearHoverSelection } from '../../../commands';
|
|
9
|
-
import { TableCssClassName as ClassName } from '../../../types';
|
|
10
|
-
import {
|
|
11
|
-
getRowClassNames,
|
|
12
|
-
getRowHeights,
|
|
13
|
-
getRowsParams,
|
|
14
|
-
RowParams,
|
|
15
|
-
} from '../../../utils';
|
|
16
|
-
import { tableControlsSpacing, tableToolbarSize } from '../../consts';
|
|
17
|
-
|
|
18
|
-
const messages = defineMessages({
|
|
19
|
-
rowControl: {
|
|
20
|
-
id: 'fabric.editor.rowControl',
|
|
21
|
-
defaultMessage: 'Highlight row',
|
|
22
|
-
description:
|
|
23
|
-
'A button on the left of each row that shows up when the table is in focus. Clicking on it will select the entire row.',
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
export interface Props {
|
|
28
|
-
editorView: EditorView;
|
|
29
|
-
tableRef: HTMLTableElement;
|
|
30
|
-
selectRow: (row: number, expand: boolean) => void;
|
|
31
|
-
hoverRows: (rows: number[], danger?: boolean) => void;
|
|
32
|
-
hoveredRows?: number[];
|
|
33
|
-
isInDanger?: boolean;
|
|
34
|
-
isResizing?: boolean;
|
|
35
|
-
insertRowButtonIndex?: number;
|
|
36
|
-
stickyTop?: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
class RowControlsComponent extends Component<Props & WrappedComponentProps> {
|
|
40
|
-
render() {
|
|
41
|
-
const {
|
|
42
|
-
editorView,
|
|
43
|
-
tableRef,
|
|
44
|
-
hoveredRows,
|
|
45
|
-
isInDanger,
|
|
46
|
-
isResizing,
|
|
47
|
-
intl: { formatMessage },
|
|
48
|
-
} = this.props;
|
|
49
|
-
if (!tableRef) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
const { selection } = editorView.state;
|
|
53
|
-
const rowHeights = getRowHeights(tableRef);
|
|
54
|
-
const rowsParams = getRowsParams(rowHeights);
|
|
55
|
-
|
|
56
|
-
const firstRow = tableRef.querySelector('tr');
|
|
57
|
-
const hasHeaderRow = firstRow
|
|
58
|
-
? firstRow.getAttribute('data-header-row')
|
|
59
|
-
: false;
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<div className={ClassName.ROW_CONTROLS}>
|
|
63
|
-
<div className={ClassName.ROW_CONTROLS_INNER}>
|
|
64
|
-
{rowsParams.map(
|
|
65
|
-
({ startIndex, endIndex, height }: RowParams, index) => {
|
|
66
|
-
// if previous row was header row, add its height to our margin
|
|
67
|
-
let marginTop = -1;
|
|
68
|
-
if (
|
|
69
|
-
index === 1 &&
|
|
70
|
-
hasHeaderRow &&
|
|
71
|
-
this.props.stickyTop !== undefined
|
|
72
|
-
) {
|
|
73
|
-
marginTop += rowHeights[index - 1] + tableToolbarSize;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const thisRowSticky =
|
|
77
|
-
this.props.stickyTop !== undefined &&
|
|
78
|
-
index === 0 &&
|
|
79
|
-
hasHeaderRow;
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<div
|
|
83
|
-
className={`${
|
|
84
|
-
ClassName.ROW_CONTROLS_BUTTON_WRAP
|
|
85
|
-
} ${getRowClassNames(
|
|
86
|
-
startIndex,
|
|
87
|
-
selection,
|
|
88
|
-
hoveredRows,
|
|
89
|
-
isInDanger,
|
|
90
|
-
isResizing,
|
|
91
|
-
)} ${thisRowSticky ? 'sticky' : ''}`}
|
|
92
|
-
key={startIndex}
|
|
93
|
-
style={{
|
|
94
|
-
height: height,
|
|
95
|
-
marginTop: `${marginTop}px`,
|
|
96
|
-
top: thisRowSticky
|
|
97
|
-
? `${this.props.stickyTop! + 3}px`
|
|
98
|
-
: undefined,
|
|
99
|
-
paddingTop: thisRowSticky
|
|
100
|
-
? `${tableControlsSpacing}px`
|
|
101
|
-
: undefined,
|
|
102
|
-
}}
|
|
103
|
-
>
|
|
104
|
-
<button
|
|
105
|
-
aria-label={formatMessage(messages.rowControl)}
|
|
106
|
-
type="button"
|
|
107
|
-
className={`${ClassName.ROW_CONTROLS_BUTTON}
|
|
108
|
-
${ClassName.CONTROLS_BUTTON}
|
|
109
|
-
`}
|
|
110
|
-
onClick={(event) =>
|
|
111
|
-
this.props.selectRow(startIndex, event.shiftKey)
|
|
112
|
-
}
|
|
113
|
-
onMouseOver={() => this.props.hoverRows([startIndex])}
|
|
114
|
-
onMouseOut={this.clearHoverSelection}
|
|
115
|
-
data-start-index={startIndex}
|
|
116
|
-
data-end-index={endIndex}
|
|
117
|
-
/>
|
|
118
|
-
|
|
119
|
-
<div className={ClassName.CONTROLS_INSERT_MARKER} />
|
|
120
|
-
</div>
|
|
121
|
-
);
|
|
122
|
-
},
|
|
123
|
-
)}
|
|
124
|
-
</div>
|
|
125
|
-
</div>
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private clearHoverSelection = () => {
|
|
130
|
-
const { state, dispatch } = this.props.editorView;
|
|
131
|
-
clearHoverSelection()(state, dispatch);
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export const RowControls = injectIntl(RowControlsComponent);
|
|
1
|
+
export { RowControls } from './ClassicControls';
|
|
2
|
+
export { DragControls } from './DragControls';
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
2
|
|
|
3
3
|
import type { TableColumnOrdering } from '@atlaskit/custom-steps';
|
|
4
|
-
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
4
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
6
5
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
7
|
|
|
9
8
|
import { hoverRows, selectRow } from '../../commands';
|
|
10
9
|
import type { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
10
|
+
import type { CellHoverCoordinates } from '../../types';
|
|
11
11
|
import { isSelectionUpdated } from '../../utils';
|
|
12
12
|
|
|
13
13
|
import { CornerControls } from './CornerControls';
|
|
14
14
|
import NumberColumn from './NumberColumn';
|
|
15
|
-
import { RowControls } from './RowControls';
|
|
15
|
+
import { DragControls, RowControls } from './RowControls';
|
|
16
16
|
|
|
17
17
|
export interface Props {
|
|
18
18
|
editorView: EditorView;
|
|
19
|
-
getEditorFeatureFlags: GetEditorFeatureFlags;
|
|
20
19
|
selection?: Selection;
|
|
21
20
|
tableRef?: HTMLTableElement;
|
|
22
21
|
tableActive?: boolean;
|
|
@@ -25,9 +24,11 @@ export interface Props {
|
|
|
25
24
|
isHeaderRowEnabled?: boolean;
|
|
26
25
|
isHeaderColumnEnabled?: boolean;
|
|
27
26
|
isNumberColumnEnabled?: boolean;
|
|
27
|
+
isDragAndDropEnabled?: boolean;
|
|
28
28
|
hasHeaderRow?: boolean;
|
|
29
29
|
headerRowHeight?: number;
|
|
30
30
|
hoveredRows?: number[];
|
|
31
|
+
hoveredCell?: CellHoverCoordinates;
|
|
31
32
|
ordering?: TableColumnOrdering;
|
|
32
33
|
stickyHeader?: RowStickyState;
|
|
33
34
|
}
|
|
@@ -77,6 +78,7 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
77
78
|
ordering,
|
|
78
79
|
headerRowHeight,
|
|
79
80
|
stickyHeader,
|
|
81
|
+
hoveredCell,
|
|
80
82
|
} = this.props;
|
|
81
83
|
const tableHeight = this.state?.tableHeight;
|
|
82
84
|
const nextTableHeight = nextState?.tableHeight;
|
|
@@ -93,7 +95,8 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
93
95
|
isNumberColumnEnabled !== nextProps.isNumberColumnEnabled ||
|
|
94
96
|
isSelectionUpdated(selection!, nextProps.selection) ||
|
|
95
97
|
headerRowHeight !== nextProps.headerRowHeight ||
|
|
96
|
-
stickyHeader !== nextProps.stickyHeader
|
|
98
|
+
stickyHeader !== nextProps.stickyHeader ||
|
|
99
|
+
hoveredCell !== nextProps.hoveredCell
|
|
97
100
|
);
|
|
98
101
|
}
|
|
99
102
|
|
|
@@ -116,6 +119,8 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
116
119
|
hasHeaderRow,
|
|
117
120
|
hoveredRows,
|
|
118
121
|
stickyHeader,
|
|
122
|
+
isDragAndDropEnabled,
|
|
123
|
+
hoveredCell,
|
|
119
124
|
} = this.props;
|
|
120
125
|
|
|
121
126
|
if (!tableRef) {
|
|
@@ -126,6 +131,7 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
126
131
|
stickyHeader && stickyHeader.sticky && hasHeaderRow
|
|
127
132
|
? stickyHeader.top
|
|
128
133
|
: undefined;
|
|
134
|
+
|
|
129
135
|
return (
|
|
130
136
|
<div onMouseDown={(e) => e.preventDefault()}>
|
|
131
137
|
{isNumberColumnEnabled ? (
|
|
@@ -140,31 +146,44 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
140
146
|
isResizing={isResizing}
|
|
141
147
|
selectRow={this.selectRow}
|
|
142
148
|
stickyTop={stickyTop}
|
|
149
|
+
isDragAndDropEnabled={isDragAndDropEnabled}
|
|
143
150
|
/>
|
|
144
151
|
) : null}
|
|
145
152
|
|
|
146
153
|
{tableActive && (
|
|
147
154
|
<>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
155
|
+
{isDragAndDropEnabled ? (
|
|
156
|
+
<DragControls
|
|
157
|
+
tableRef={tableRef}
|
|
158
|
+
hoveredCell={hoveredCell}
|
|
159
|
+
editorView={editorView}
|
|
160
|
+
hoverRows={this.hoverRows}
|
|
161
|
+
selectRow={this.selectRow}
|
|
162
|
+
/>
|
|
163
|
+
) : (
|
|
164
|
+
<>
|
|
165
|
+
<CornerControls
|
|
166
|
+
editorView={editorView}
|
|
167
|
+
tableRef={tableRef}
|
|
168
|
+
isInDanger={isInDanger}
|
|
169
|
+
isResizing={isResizing}
|
|
170
|
+
isHeaderRowEnabled={isHeaderRowEnabled}
|
|
171
|
+
isHeaderColumnEnabled={isHeaderColumnEnabled}
|
|
172
|
+
hoveredRows={hoveredRows}
|
|
173
|
+
stickyTop={tableActive ? stickyTop : undefined}
|
|
174
|
+
/>
|
|
175
|
+
<RowControls
|
|
176
|
+
editorView={editorView}
|
|
177
|
+
tableRef={tableRef}
|
|
178
|
+
hoverRows={this.hoverRows}
|
|
179
|
+
hoveredRows={hoveredRows}
|
|
180
|
+
isInDanger={isInDanger}
|
|
181
|
+
isResizing={isResizing}
|
|
182
|
+
selectRow={this.selectRow}
|
|
183
|
+
stickyTop={tableActive ? stickyTop : undefined}
|
|
184
|
+
/>
|
|
185
|
+
</>
|
|
186
|
+
)}
|
|
168
187
|
</>
|
|
169
188
|
)}
|
|
170
189
|
</div>
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
columnControlsDecorationHeight,
|
|
32
32
|
resizeHandlerAreaWidth,
|
|
33
33
|
resizeLineWidth,
|
|
34
|
+
rowControlsZIndex,
|
|
34
35
|
stickyHeaderBorderBottomWidth,
|
|
35
36
|
stickyRowOffsetTop,
|
|
36
37
|
tableBorderColor,
|
|
@@ -240,6 +241,26 @@ const tableStickyHeaderColumnControlsDecorationsStyle = (
|
|
|
240
241
|
}
|
|
241
242
|
};
|
|
242
243
|
|
|
244
|
+
const tableRowControlStyles = () => {
|
|
245
|
+
return getBooleanFF('platform.editor.table.drag-and-drop')
|
|
246
|
+
? css`
|
|
247
|
+
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
248
|
+
position: absolute;
|
|
249
|
+
margin-top: ${tableMarginTop}px;
|
|
250
|
+
left: -${tableToolbarSize + 1}px;
|
|
251
|
+
z-index: ${rowControlsZIndex};
|
|
252
|
+
}
|
|
253
|
+
`
|
|
254
|
+
: css`
|
|
255
|
+
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
256
|
+
position: absolute;
|
|
257
|
+
/* top of corner control is table margin top - corner control height + 1 pixel of table border. */
|
|
258
|
+
top: ${tableMarginTop - cornerControlHeight + 1}px;
|
|
259
|
+
left: -${tableToolbarSize}px;
|
|
260
|
+
}
|
|
261
|
+
`;
|
|
262
|
+
};
|
|
263
|
+
|
|
243
264
|
const tableWrapperStyles = () => {
|
|
244
265
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
245
266
|
return css`
|
|
@@ -677,6 +698,12 @@ export const tableStyles = (
|
|
|
677
698
|
)}
|
|
678
699
|
}
|
|
679
700
|
|
|
701
|
+
.${ClassName.ROW_CONTROLS_WITH_DRAG} {
|
|
702
|
+
display: grid;
|
|
703
|
+
align-items: center;
|
|
704
|
+
position: absolute;
|
|
705
|
+
}
|
|
706
|
+
|
|
680
707
|
${floatingColumnControls(props)}
|
|
681
708
|
|
|
682
709
|
:not(.${ClassName.IS_RESIZING}) .${ClassName.ROW_CONTROLS} {
|
|
@@ -691,7 +718,9 @@ export const tableStyles = (
|
|
|
691
718
|
margin-left: ${getBooleanFF('platform.editor.custom-table-width')
|
|
692
719
|
? akEditorTableToolbarSize
|
|
693
720
|
: akEditorTableToolbarSize - 1}px;
|
|
694
|
-
top: ${
|
|
721
|
+
top: ${getBooleanFF('platform.editor.table.drag-and-drop')
|
|
722
|
+
? 0
|
|
723
|
+
: akEditorTableToolbarSize}px;
|
|
695
724
|
width: ${akEditorTableNumberColumnWidth + 1}px;
|
|
696
725
|
box-sizing: border-box;
|
|
697
726
|
}
|
|
@@ -717,6 +746,21 @@ export const tableStyles = (
|
|
|
717
746
|
}
|
|
718
747
|
}
|
|
719
748
|
|
|
749
|
+
// add a background above the first numbered column cell when sticky header is engaged
|
|
750
|
+
// which hides the table when scrolling
|
|
751
|
+
.${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}:first-of-type::after {
|
|
752
|
+
content: '';
|
|
753
|
+
display: block;
|
|
754
|
+
height: 33px;
|
|
755
|
+
width: 100%;
|
|
756
|
+
background-color: ${token('elevation.surface', 'white')};
|
|
757
|
+
position: absolute;
|
|
758
|
+
|
|
759
|
+
// the extra pixel is accounting for borders
|
|
760
|
+
top: -34px;
|
|
761
|
+
left: -1px;
|
|
762
|
+
}
|
|
763
|
+
|
|
720
764
|
.${ClassName.WITH_CONTROLS} {
|
|
721
765
|
.${ClassName.CORNER_CONTROLS}, .${ClassName.ROW_CONTROLS} {
|
|
722
766
|
display: block;
|
|
@@ -741,10 +785,10 @@ export const tableStyles = (
|
|
|
741
785
|
}
|
|
742
786
|
}
|
|
743
787
|
:not(.${ClassName.IS_RESIZING}) .${ClassName.WITH_CONTROLS} {
|
|
744
|
-
.${ClassName.NUMBERED_COLUMN_BUTTON} {
|
|
788
|
+
.${ClassName.NUMBERED_COLUMN_BUTTON}:not(.${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}) {
|
|
745
789
|
cursor: pointer;
|
|
746
790
|
}
|
|
747
|
-
.${ClassName.NUMBERED_COLUMN_BUTTON}:hover {
|
|
791
|
+
.${ClassName.NUMBERED_COLUMN_BUTTON}:not(.${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}):hover {
|
|
748
792
|
border-bottom: 1px solid ${tableBorderSelectedColor(props)};
|
|
749
793
|
border-color: ${tableBorderSelectedColor(props)};
|
|
750
794
|
background-color: ${tableToolbarSelectedColor(props)};
|
|
@@ -780,6 +824,10 @@ export const tableStyles = (
|
|
|
780
824
|
margin-top: 0;
|
|
781
825
|
}
|
|
782
826
|
|
|
827
|
+
.${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} + * {
|
|
828
|
+
margin-top: 0;
|
|
829
|
+
}
|
|
830
|
+
|
|
783
831
|
/*
|
|
784
832
|
* Headings have a top margin by default, but we don't want this on the
|
|
785
833
|
* first heading within table header cells.
|
|
@@ -853,17 +901,10 @@ export const tableStyles = (
|
|
|
853
901
|
}
|
|
854
902
|
}
|
|
855
903
|
}
|
|
856
|
-
|
|
857
|
-
position: absolute;
|
|
858
|
-
/* top of corner control is table margin top - corner control height + 1 pixel of table border. */
|
|
859
|
-
top: ${tableMarginTop - cornerControlHeight + 1}px;
|
|
860
|
-
}
|
|
904
|
+
${tableRowControlStyles()}
|
|
861
905
|
.${ClassName.ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW} {
|
|
862
906
|
z-index: ${akEditorUnitZIndex};
|
|
863
907
|
}
|
|
864
|
-
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
865
|
-
left: -${tableToolbarSize}px;
|
|
866
|
-
}
|
|
867
908
|
|
|
868
909
|
.${ClassName.COLUMN_CONTROLS_WRAPPER} {
|
|
869
910
|
position: absolute;
|
|
@@ -130,6 +130,7 @@ export const lineMarkerSize = 4;
|
|
|
130
130
|
export const columnControlsDecorationHeight = 25;
|
|
131
131
|
export const columnControlsZIndex = akEditorUnitZIndex * 10;
|
|
132
132
|
export const columnControlsSelectedZIndex = columnControlsZIndex + 1;
|
|
133
|
+
export const rowControlsZIndex = akEditorUnitZIndex * 10;
|
|
133
134
|
export const columnResizeHandleZIndex = columnControlsSelectedZIndex + 1;
|
|
134
135
|
export const insertLineWidth = 3;
|
|
135
136
|
export const resizeHandlerAreaWidth = RESIZE_HANDLE_AREA_DECORATION_GAP / 3;
|