@atlaskit/editor-plugin-table 5.3.1 → 5.3.3
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 +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/DragPreview/index.js +39 -0
- package/dist/cjs/plugins/table/ui/Icons/DragInMotionIcon.js +55 -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/DragPreview/index.js +33 -0
- package/dist/es2019/plugins/table/ui/Icons/DragInMotionIcon.js +47 -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/DragPreview/index.js +32 -0
- package/dist/esm/plugins/table/ui/Icons/DragInMotionIcon.js +48 -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/DragPreview/index.d.ts +6 -0
- package/dist/types/plugins/table/ui/Icons/DragInMotionIcon.d.ts +6 -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/DragPreview/index.d.ts +6 -0
- package/dist/types-ts4.5/plugins/table/ui/Icons/DragInMotionIcon.d.ts +6 -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 +5 -3
- 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/DragPreview/index.tsx +45 -0
- package/src/plugins/table/ui/Icons/DragInMotionIcon.tsx +60 -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 +6 -0
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
2
|
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
|
|
3
5
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
7
|
import { isRowSelected } from '@atlaskit/editor-tables/utils';
|
|
6
8
|
|
|
7
|
-
import { clearHoverSelection } from '../../../commands';
|
|
9
|
+
import { clearHoverSelection, hoverCell } from '../../../commands';
|
|
10
|
+
import { getPluginState } from '../../../pm-plugins/plugin-factory';
|
|
8
11
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
9
12
|
import { getRowHeights } from '../../../utils';
|
|
13
|
+
import { tableBorderColor } from '../../consts';
|
|
10
14
|
|
|
11
15
|
export interface Props {
|
|
12
16
|
editorView: EditorView;
|
|
@@ -19,11 +23,13 @@ export interface Props {
|
|
|
19
23
|
isInDanger?: boolean;
|
|
20
24
|
isResizing?: boolean;
|
|
21
25
|
stickyTop?: number;
|
|
26
|
+
isDragAndDropEnabled?: boolean;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export default class NumberColumn extends Component<Props, any> {
|
|
25
30
|
render() {
|
|
26
|
-
const { tableRef, hasHeaderRow } =
|
|
31
|
+
const { tableRef, hasHeaderRow, isDragAndDropEnabled, tableActive } =
|
|
32
|
+
this.props;
|
|
27
33
|
const rowHeights = getRowHeights(tableRef);
|
|
28
34
|
|
|
29
35
|
return (
|
|
@@ -34,30 +40,38 @@ export default class NumberColumn extends Component<Props, any> {
|
|
|
34
40
|
hasHeaderRow && this.props.stickyTop !== undefined
|
|
35
41
|
? rowHeights[0]
|
|
36
42
|
: undefined,
|
|
43
|
+
borderLeft:
|
|
44
|
+
isDragAndDropEnabled && tableActive
|
|
45
|
+
? `1px solid ${tableBorderColor()}`
|
|
46
|
+
: undefined,
|
|
37
47
|
}}
|
|
38
48
|
contentEditable={false}
|
|
39
49
|
>
|
|
40
|
-
{rowHeights.map((rowHeight, index) =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
{rowHeights.map((rowHeight, index) =>
|
|
51
|
+
isDragAndDropEnabled ? (
|
|
52
|
+
<div
|
|
53
|
+
key={`wrapper-${index}`}
|
|
54
|
+
className={this.getClassNames(index, true)}
|
|
55
|
+
data-index={index}
|
|
56
|
+
style={this.getCellStyles(index, rowHeight)}
|
|
57
|
+
onMouseOver={() => this.updateDragHandleLocation(index)}
|
|
58
|
+
>
|
|
59
|
+
{hasHeaderRow ? (index > 0 ? index : null) : index + 1}
|
|
60
|
+
</div>
|
|
61
|
+
) : (
|
|
62
|
+
<div
|
|
63
|
+
key={`wrapper-${index}`}
|
|
64
|
+
className={this.getClassNames(index)}
|
|
65
|
+
data-index={index}
|
|
66
|
+
style={this.getCellStyles(index, rowHeight)}
|
|
67
|
+
onClick={(event) => this.selectRow(index, event)}
|
|
68
|
+
onMouseOver={() => this.hoverRows(index)}
|
|
69
|
+
onMouseOut={this.clearHoverSelection}
|
|
70
|
+
>
|
|
71
|
+
{hasHeaderRow ? (index > 0 ? index : null) : index + 1}
|
|
72
|
+
</div>
|
|
73
|
+
),
|
|
74
|
+
)}
|
|
61
75
|
</div>
|
|
62
76
|
);
|
|
63
77
|
}
|
|
@@ -95,15 +109,39 @@ export default class NumberColumn extends Component<Props, any> {
|
|
|
95
109
|
}
|
|
96
110
|
};
|
|
97
111
|
|
|
98
|
-
private
|
|
112
|
+
private updateDragHandleLocation = (rowIndex: number) => {
|
|
113
|
+
const { editorView, tableActive } = this.props;
|
|
114
|
+
const { state, dispatch } = editorView;
|
|
115
|
+
const { hoveredCell } = getPluginState(state);
|
|
116
|
+
|
|
117
|
+
if (tableActive && hoveredCell.rowIndex !== rowIndex) {
|
|
118
|
+
hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
private getCellStyles = (index: number, rowHeight: number) => {
|
|
123
|
+
const { stickyTop, hasHeaderRow } = this.props;
|
|
124
|
+
if (stickyTop && hasHeaderRow && index === 0) {
|
|
125
|
+
return {
|
|
126
|
+
height: rowHeight,
|
|
127
|
+
top: `${stickyTop}px`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
height: rowHeight,
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
private getClassNames = (index: number, isButtonDisabled = false) => {
|
|
99
136
|
const { hoveredRows, editorView, isInDanger, isResizing } = this.props;
|
|
100
137
|
const isActive =
|
|
101
138
|
isRowSelected(index)(editorView.state.selection) ||
|
|
102
139
|
((hoveredRows || []).indexOf(index) !== -1 && !isResizing);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
isActive && isInDanger
|
|
107
|
-
|
|
140
|
+
|
|
141
|
+
return classnames(ClassName.NUMBERED_COLUMN_BUTTON, {
|
|
142
|
+
[ClassName.NUMBERED_COLUMN_BUTTON_DISABLED]: isButtonDisabled,
|
|
143
|
+
[ClassName.HOVERED_CELL_IN_DANGER]: isActive && isInDanger,
|
|
144
|
+
[ClassName.HOVERED_CELL_ACTIVE]: isActive,
|
|
145
|
+
});
|
|
108
146
|
};
|
|
109
147
|
}
|
|
@@ -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>
|