@atlaskit/editor-plugin-table 5.3.8 → 5.3.9
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/nodeviews/TableComponent.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +6 -4
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +9 -19
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +70 -0
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +12 -77
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +45 -20
- package/dist/cjs/plugins/table/ui/icons/index.js +19 -0
- package/dist/cjs/plugins/table/ui/ui-styles.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +5 -3
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -15
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +62 -0
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +8 -74
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +45 -19
- package/dist/es2019/plugins/table/ui/icons/index.js +2 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +0 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
- package/dist/esm/plugins/table/ui/DragHandle/index.js +5 -3
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +8 -16
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +61 -0
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +9 -72
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +45 -20
- package/dist/esm/plugins/table/ui/icons/index.js +2 -0
- package/dist/esm/plugins/table/ui/ui-styles.js +1 -1
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/index.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +2 -0
- package/package.json +2 -1
- package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +58 -12
- package/src/plugins/table/nodeviews/TableComponent.tsx +2 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +1 -4
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -2
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +5 -0
- package/src/plugins/table/types.ts +1 -0
- package/src/plugins/table/ui/DragHandle/index.tsx +3 -1
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +9 -17
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +74 -0
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -80
- package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +61 -31
- package/src/plugins/table/ui/icons/index.ts +2 -0
- package/src/plugins/table/ui/ui-styles.ts +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
|
|
3
|
+
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
4
|
+
export const ColumnDropTarget = ({
|
|
5
|
+
index,
|
|
6
|
+
localId,
|
|
7
|
+
width,
|
|
8
|
+
height,
|
|
9
|
+
marginTop
|
|
10
|
+
}) => {
|
|
11
|
+
const dropTargetRef = useRef(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!dropTargetRef.current) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return dropTargetForElements({
|
|
17
|
+
element: dropTargetRef.current,
|
|
18
|
+
canDrop({
|
|
19
|
+
source
|
|
20
|
+
}) {
|
|
21
|
+
var _data$indexes, _data$indexes2;
|
|
22
|
+
const data = source.data;
|
|
23
|
+
return (
|
|
24
|
+
// Only draggables of row type can be dropped on this target
|
|
25
|
+
data.type === 'table-column' &&
|
|
26
|
+
// Only draggables which came from the same table can be dropped on this target
|
|
27
|
+
data.localId === localId &&
|
|
28
|
+
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
29
|
+
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
|
|
30
|
+
);
|
|
31
|
+
},
|
|
32
|
+
getIsSticky: () => true,
|
|
33
|
+
getData({
|
|
34
|
+
input,
|
|
35
|
+
element
|
|
36
|
+
}) {
|
|
37
|
+
const data = {
|
|
38
|
+
localId,
|
|
39
|
+
type: 'table-column',
|
|
40
|
+
targetIndex: index
|
|
41
|
+
};
|
|
42
|
+
return attachClosestEdge(data, {
|
|
43
|
+
input,
|
|
44
|
+
element,
|
|
45
|
+
allowedEdges: ['left', 'right']
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}, [index, localId]);
|
|
50
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
51
|
+
ref: dropTargetRef,
|
|
52
|
+
style: {
|
|
53
|
+
width: width && `${width - 1}px`,
|
|
54
|
+
height: height && `${height}px`,
|
|
55
|
+
marginTop: marginTop && `${marginTop}px`,
|
|
56
|
+
pointerEvents: 'auto'
|
|
57
|
+
},
|
|
58
|
+
"data-drop-target-index": index,
|
|
59
|
+
"data-drop-target-localid": localId,
|
|
60
|
+
"data-testid": "table-floating-column-controls-drop-target"
|
|
61
|
+
});
|
|
62
|
+
};
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
|
|
3
|
-
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
1
|
+
import React from 'react';
|
|
4
2
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
5
|
-
import {
|
|
3
|
+
import { ColumnDropTarget } from './ColumnDropTarget';
|
|
6
4
|
export const ColumnDropTargets = ({
|
|
7
|
-
editorView,
|
|
8
5
|
tableRef,
|
|
9
6
|
tableHeight,
|
|
10
7
|
stickyTop,
|
|
11
|
-
localId
|
|
8
|
+
localId,
|
|
9
|
+
rowHeights,
|
|
10
|
+
colWidths
|
|
12
11
|
}) => {
|
|
13
12
|
var _rowHeights$;
|
|
14
|
-
const colWidths = getColumnsWidths(editorView);
|
|
15
|
-
const rowHeights = useMemo(() => {
|
|
16
|
-
// NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
|
|
17
|
-
if (tableRef && !!tableHeight) {
|
|
18
|
-
return getRowHeights(tableRef);
|
|
19
|
-
}
|
|
20
|
-
return [0];
|
|
21
|
-
}, [tableRef, tableHeight]);
|
|
22
13
|
if (!tableRef) {
|
|
23
14
|
return null;
|
|
24
15
|
}
|
|
@@ -26,11 +17,12 @@ export const ColumnDropTargets = ({
|
|
|
26
17
|
const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
27
18
|
const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
28
19
|
return /*#__PURE__*/React.createElement("div", {
|
|
29
|
-
className: ClassName.COLUMN_DROP_TARGET_CONTROLS
|
|
20
|
+
className: ClassName.COLUMN_DROP_TARGET_CONTROLS,
|
|
21
|
+
contentEditable: false
|
|
30
22
|
}, /*#__PURE__*/React.createElement("div", {
|
|
31
23
|
className: ClassName.COLUMN_CONTROLS_INNER,
|
|
32
24
|
"data-testid": "table-floating-column-controls-drop-targets"
|
|
33
|
-
}, colWidths.map((width, index) => {
|
|
25
|
+
}, colWidths === null || colWidths === void 0 ? void 0 : colWidths.map((width, index) => {
|
|
34
26
|
return /*#__PURE__*/React.createElement(ColumnDropTarget, {
|
|
35
27
|
key: index,
|
|
36
28
|
index: index,
|
|
@@ -40,62 +32,4 @@ export const ColumnDropTargets = ({
|
|
|
40
32
|
marginTop: marginTop
|
|
41
33
|
});
|
|
42
34
|
})));
|
|
43
|
-
};
|
|
44
|
-
export default ColumnDropTargets;
|
|
45
|
-
const ColumnDropTarget = ({
|
|
46
|
-
index,
|
|
47
|
-
localId,
|
|
48
|
-
width,
|
|
49
|
-
height,
|
|
50
|
-
marginTop
|
|
51
|
-
}) => {
|
|
52
|
-
const dropTargetRef = useRef(null);
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (!dropTargetRef.current) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
return dropTargetForElements({
|
|
58
|
-
element: dropTargetRef.current,
|
|
59
|
-
canDrop({
|
|
60
|
-
source
|
|
61
|
-
}) {
|
|
62
|
-
var _data$indexes, _data$indexes2;
|
|
63
|
-
const data = source.data;
|
|
64
|
-
return (
|
|
65
|
-
// Only draggables of row type can be dropped on this target
|
|
66
|
-
data.type === 'table-column' &&
|
|
67
|
-
// Only draggables which came from the same table can be dropped on this target
|
|
68
|
-
data.localId === localId &&
|
|
69
|
-
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
70
|
-
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
|
|
71
|
-
);
|
|
72
|
-
},
|
|
73
|
-
getData({
|
|
74
|
-
input,
|
|
75
|
-
element
|
|
76
|
-
}) {
|
|
77
|
-
const data = {
|
|
78
|
-
localId,
|
|
79
|
-
type: 'table-column',
|
|
80
|
-
targetIndex: index
|
|
81
|
-
};
|
|
82
|
-
return attachClosestEdge(data, {
|
|
83
|
-
input,
|
|
84
|
-
element,
|
|
85
|
-
allowedEdges: ['left', 'right']
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}, [index, localId]);
|
|
90
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
91
|
-
ref: dropTargetRef,
|
|
92
|
-
style: {
|
|
93
|
-
width: width && `${width - 1}px`,
|
|
94
|
-
height: height && `${height}px`,
|
|
95
|
-
marginTop: marginTop && `${marginTop}px`
|
|
96
|
-
},
|
|
97
|
-
"data-drop-target-index": index,
|
|
98
|
-
"data-drop-target-localid": localId,
|
|
99
|
-
"data-testid": "table-floating-column-controls-drop-target"
|
|
100
|
-
});
|
|
101
35
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
|
-
import {
|
|
3
|
+
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
4
4
|
import { TableCssClassName as ClassName } from '../../types';
|
|
5
|
+
import { getColumnsWidths, getRowHeights } from '../../utils';
|
|
5
6
|
import { ColumnControls } from './ColumnControls';
|
|
6
7
|
import { ColumnDropTargets } from './ColumnDropTargets';
|
|
7
8
|
export const TableFloatingColumnControls = ({
|
|
8
9
|
editorView,
|
|
9
10
|
tableRef,
|
|
11
|
+
getNode,
|
|
10
12
|
tableActive,
|
|
11
13
|
hasHeaderRow,
|
|
12
14
|
hoveredCell,
|
|
@@ -18,6 +20,9 @@ export const TableFloatingColumnControls = ({
|
|
|
18
20
|
width: 0,
|
|
19
21
|
height: 0
|
|
20
22
|
});
|
|
23
|
+
const [hasDropTargets, setHasDropTargets] = useState(false);
|
|
24
|
+
const node = getNode();
|
|
25
|
+
const currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
|
|
21
26
|
useEffect(() => {
|
|
22
27
|
var _window;
|
|
23
28
|
if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
|
|
@@ -37,25 +42,44 @@ export const TableFloatingColumnControls = ({
|
|
|
37
42
|
};
|
|
38
43
|
}
|
|
39
44
|
}, [tableRef]);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
return monitorForElements({
|
|
47
|
+
canMonitor({
|
|
48
|
+
source
|
|
49
|
+
}) {
|
|
50
|
+
const {
|
|
51
|
+
type,
|
|
52
|
+
localId,
|
|
53
|
+
indexes
|
|
54
|
+
} = source.data;
|
|
55
|
+
return type === 'table-column' && !!(indexes !== null && indexes !== void 0 && indexes.length) && localId === currentNodeLocalId;
|
|
56
|
+
},
|
|
57
|
+
onDragStart() {
|
|
58
|
+
setHasDropTargets(true);
|
|
59
|
+
},
|
|
60
|
+
onDrop() {
|
|
61
|
+
setHasDropTargets(false);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}, [editorView, currentNodeLocalId]);
|
|
65
|
+
const rowHeights = useMemo(() => {
|
|
66
|
+
// NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
|
|
67
|
+
if (tableRef && !!tableRect.height) {
|
|
68
|
+
return getRowHeights(tableRef);
|
|
47
69
|
}
|
|
48
|
-
return
|
|
49
|
-
}, [
|
|
70
|
+
return [0];
|
|
71
|
+
}, [tableRef, tableRect.height]);
|
|
50
72
|
if (!tableRef) {
|
|
51
73
|
return null;
|
|
52
74
|
}
|
|
75
|
+
const colWidths = getColumnsWidths(editorView);
|
|
53
76
|
const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
54
77
|
const mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
|
|
55
78
|
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement("div", {
|
|
56
|
-
className: ClassName.COLUMN_CONTROLS_WRAPPER
|
|
57
|
-
|
|
58
|
-
|
|
79
|
+
className: ClassName.COLUMN_CONTROLS_WRAPPER,
|
|
80
|
+
style: {
|
|
81
|
+
pointerEvents: 'none'
|
|
82
|
+
},
|
|
59
83
|
"data-testid": "table-floating-column-controls-wrapper"
|
|
60
84
|
}, /*#__PURE__*/React.createElement(ColumnControls, {
|
|
61
85
|
editorView: editorView,
|
|
@@ -64,14 +88,16 @@ export const TableFloatingColumnControls = ({
|
|
|
64
88
|
isResizing: isResizing,
|
|
65
89
|
tableActive: tableActive,
|
|
66
90
|
stickyTop: tableActive ? stickyTop : undefined,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
localId: currentNodeLocalId,
|
|
92
|
+
rowHeights: rowHeights,
|
|
93
|
+
colWidths: colWidths
|
|
94
|
+
}), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
|
|
71
95
|
tableRef: tableRef,
|
|
72
96
|
stickyTop: tableActive ? stickyTop : undefined,
|
|
73
97
|
tableHeight: tableRect.height,
|
|
74
|
-
localId:
|
|
75
|
-
|
|
98
|
+
localId: currentNodeLocalId,
|
|
99
|
+
rowHeights: rowHeights,
|
|
100
|
+
colWidths: colWidths
|
|
101
|
+
})), mountTo);
|
|
76
102
|
};
|
|
77
103
|
export default TableFloatingColumnControls;
|
|
@@ -492,13 +492,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
492
492
|
var colControls = /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
|
|
493
493
|
editorView: view,
|
|
494
494
|
tableRef: tableRef,
|
|
495
|
+
getNode: getNode,
|
|
495
496
|
tableActive: tableActive,
|
|
496
497
|
hoveredRows: hoveredRows,
|
|
497
498
|
hoveredCell: hoveredCell,
|
|
498
499
|
isResizing: isResizing,
|
|
499
500
|
ordering: ordering,
|
|
500
501
|
hasHeaderRow: hasHeaderRow
|
|
501
|
-
// pass `selection`
|
|
502
|
+
// pass `selection` to control re-render
|
|
502
503
|
,
|
|
503
504
|
selection: view.state.selection,
|
|
504
505
|
headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
|
|
@@ -72,6 +72,6 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
|
|
|
72
72
|
return tr.setMeta('addToHistory', false);
|
|
73
73
|
}
|
|
74
74
|
var move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
75
|
-
return move(sourceIndex, targetIndex
|
|
75
|
+
return move(sourceIndex, targetIndex)(tr);
|
|
76
76
|
});
|
|
77
77
|
};
|
|
@@ -69,7 +69,8 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
69
69
|
}
|
|
70
70
|
var sourceType = data.sourceType,
|
|
71
71
|
sourceIndexes = data.sourceIndexes,
|
|
72
|
-
targetAdjustedIndex = data.targetAdjustedIndex
|
|
72
|
+
targetAdjustedIndex = data.targetAdjustedIndex,
|
|
73
|
+
direction = data.direction;
|
|
73
74
|
|
|
74
75
|
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
75
76
|
var hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
@@ -79,7 +80,7 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
79
80
|
}
|
|
80
81
|
var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
|
|
81
82
|
sourceIndex = _sourceIndexes[0];
|
|
82
|
-
moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
83
|
+
moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
|
|
83
84
|
}
|
|
84
85
|
})
|
|
85
86
|
};
|
|
@@ -40,6 +40,10 @@ export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref)
|
|
|
40
40
|
// This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
|
|
41
41
|
// the new target index to be 1 index higher.
|
|
42
42
|
var targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
|
|
43
|
+
|
|
44
|
+
// since only consecutive rows/cols can be moved we can assume that if the first index is greater then
|
|
45
|
+
// the target index, the then the direction of the DnD is decreasing
|
|
46
|
+
var direction = sourceIndexes[0] > targetIndex ? -1 : 1;
|
|
43
47
|
return {
|
|
44
48
|
sourceType: sourceType,
|
|
45
49
|
sourceLocalId: sourceLocalId,
|
|
@@ -48,6 +52,7 @@ export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref)
|
|
|
48
52
|
targetLocalId: targetLocalId,
|
|
49
53
|
targetIndex: targetIndex,
|
|
50
54
|
targetAdjustedIndex: targetIndex + targetOffset,
|
|
51
|
-
targetClosestEdge: targetClosestEdge
|
|
55
|
+
targetClosestEdge: targetClosestEdge,
|
|
56
|
+
direction: direction
|
|
52
57
|
};
|
|
53
58
|
};
|
|
@@ -6,7 +6,7 @@ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/ut
|
|
|
6
6
|
import { N200, N700 } from '@atlaskit/theme/colors';
|
|
7
7
|
import { TableCssClassName as ClassName } from '../../types';
|
|
8
8
|
import { DragPreview } from '../DragPreview';
|
|
9
|
-
import { DragHandleIcon } from '../icons
|
|
9
|
+
import { DragHandleIcon } from '../icons';
|
|
10
10
|
var mapStateToProps = function mapStateToProps(state) {
|
|
11
11
|
switch (state) {
|
|
12
12
|
case 'danger':
|
|
@@ -88,8 +88,10 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
88
88
|
backgroundColor: "var(--ds-surface, white)",
|
|
89
89
|
borderRadius: '4px',
|
|
90
90
|
border: "2px solid ".concat("var(--ds-surface, white)"),
|
|
91
|
-
transform: direction === 'column' ? 'none' : 'rotate(90deg)'
|
|
92
|
-
|
|
91
|
+
transform: direction === 'column' ? 'none' : 'rotate(90deg)',
|
|
92
|
+
pointerEvents: 'auto'
|
|
93
|
+
},
|
|
94
|
+
"data-testid": "table-floating-column-controls-drag-handle"
|
|
93
95
|
}, /*#__PURE__*/React.createElement(DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
|
|
94
96
|
direction: direction,
|
|
95
97
|
width: previewWidth,
|
|
@@ -1,34 +1,26 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
3
|
-
import { getColumnsWidths, getRowHeights } from '../../../utils';
|
|
4
3
|
import { DragHandle } from '../../DragHandle';
|
|
5
4
|
export var ColumnControls = function ColumnControls(_ref) {
|
|
6
|
-
var _rowHeights
|
|
5
|
+
var _rowHeights$, _colWidths$map$join;
|
|
7
6
|
var editorView = _ref.editorView,
|
|
8
7
|
tableActive = _ref.tableActive,
|
|
9
8
|
tableRef = _ref.tableRef,
|
|
10
9
|
hoveredCell = _ref.hoveredCell,
|
|
11
10
|
isResizing = _ref.isResizing,
|
|
12
|
-
tableHeight = _ref.tableHeight,
|
|
13
11
|
stickyTop = _ref.stickyTop,
|
|
14
|
-
localId = _ref.localId
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (tableRef && !!tableHeight) {
|
|
18
|
-
return getRowHeights(tableRef);
|
|
19
|
-
}
|
|
20
|
-
return [0];
|
|
21
|
-
}, [tableRef, tableHeight]);
|
|
12
|
+
localId = _ref.localId,
|
|
13
|
+
rowHeights = _ref.rowHeights,
|
|
14
|
+
colWidths = _ref.colWidths;
|
|
22
15
|
if (!tableRef) {
|
|
23
16
|
return null;
|
|
24
17
|
}
|
|
25
18
|
var firstRow = tableRef.querySelector('tr');
|
|
26
19
|
var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
27
20
|
var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
28
|
-
var
|
|
29
|
-
var widths = colWidths.map(function (width) {
|
|
21
|
+
var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
|
|
30
22
|
return width ? "".concat(width - 1, "px") : '0px';
|
|
31
|
-
}).join(' ');
|
|
23
|
+
}).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
|
|
32
24
|
var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
|
|
33
25
|
var _onClick = function onClick(index, event) {};
|
|
34
26
|
var onMouseOver = function onMouseOver() {};
|
|
@@ -51,7 +43,7 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
51
43
|
"data-testid": "table-floating-column-control"
|
|
52
44
|
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
53
45
|
direction: "column",
|
|
54
|
-
indexes: [],
|
|
46
|
+
indexes: [colIndex],
|
|
55
47
|
onClick: function onClick(event) {
|
|
56
48
|
return _onClick(colIndex, event);
|
|
57
49
|
},
|
package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
|
|
3
|
+
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
4
|
+
export var ColumnDropTarget = function ColumnDropTarget(_ref) {
|
|
5
|
+
var index = _ref.index,
|
|
6
|
+
localId = _ref.localId,
|
|
7
|
+
width = _ref.width,
|
|
8
|
+
height = _ref.height,
|
|
9
|
+
marginTop = _ref.marginTop;
|
|
10
|
+
var dropTargetRef = useRef(null);
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
if (!dropTargetRef.current) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
return dropTargetForElements({
|
|
16
|
+
element: dropTargetRef.current,
|
|
17
|
+
canDrop: function canDrop(_ref2) {
|
|
18
|
+
var _data$indexes, _data$indexes2;
|
|
19
|
+
var source = _ref2.source;
|
|
20
|
+
var data = source.data;
|
|
21
|
+
return (
|
|
22
|
+
// Only draggables of row type can be dropped on this target
|
|
23
|
+
data.type === 'table-column' &&
|
|
24
|
+
// Only draggables which came from the same table can be dropped on this target
|
|
25
|
+
data.localId === localId &&
|
|
26
|
+
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
27
|
+
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
getIsSticky: function getIsSticky() {
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
getData: function getData(_ref3) {
|
|
34
|
+
var input = _ref3.input,
|
|
35
|
+
element = _ref3.element;
|
|
36
|
+
var data = {
|
|
37
|
+
localId: localId,
|
|
38
|
+
type: 'table-column',
|
|
39
|
+
targetIndex: index
|
|
40
|
+
};
|
|
41
|
+
return attachClosestEdge(data, {
|
|
42
|
+
input: input,
|
|
43
|
+
element: element,
|
|
44
|
+
allowedEdges: ['left', 'right']
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}, [index, localId]);
|
|
49
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
50
|
+
ref: dropTargetRef,
|
|
51
|
+
style: {
|
|
52
|
+
width: width && "".concat(width - 1, "px"),
|
|
53
|
+
height: height && "".concat(height, "px"),
|
|
54
|
+
marginTop: marginTop && "".concat(marginTop, "px"),
|
|
55
|
+
pointerEvents: 'auto'
|
|
56
|
+
},
|
|
57
|
+
"data-drop-target-index": index,
|
|
58
|
+
"data-drop-target-localid": localId,
|
|
59
|
+
"data-testid": "table-floating-column-controls-drop-target"
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
|
|
3
|
-
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
1
|
+
import React from 'react';
|
|
4
2
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
5
|
-
import {
|
|
3
|
+
import { ColumnDropTarget } from './ColumnDropTarget';
|
|
6
4
|
export var ColumnDropTargets = function ColumnDropTargets(_ref) {
|
|
7
5
|
var _rowHeights$;
|
|
8
|
-
var
|
|
9
|
-
tableRef = _ref.tableRef,
|
|
6
|
+
var tableRef = _ref.tableRef,
|
|
10
7
|
tableHeight = _ref.tableHeight,
|
|
11
8
|
stickyTop = _ref.stickyTop,
|
|
12
|
-
localId = _ref.localId
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
|
|
16
|
-
if (tableRef && !!tableHeight) {
|
|
17
|
-
return getRowHeights(tableRef);
|
|
18
|
-
}
|
|
19
|
-
return [0];
|
|
20
|
-
}, [tableRef, tableHeight]);
|
|
9
|
+
localId = _ref.localId,
|
|
10
|
+
rowHeights = _ref.rowHeights,
|
|
11
|
+
colWidths = _ref.colWidths;
|
|
21
12
|
if (!tableRef) {
|
|
22
13
|
return null;
|
|
23
14
|
}
|
|
@@ -25,11 +16,12 @@ export var ColumnDropTargets = function ColumnDropTargets(_ref) {
|
|
|
25
16
|
var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
26
17
|
var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
27
18
|
return /*#__PURE__*/React.createElement("div", {
|
|
28
|
-
className: ClassName.COLUMN_DROP_TARGET_CONTROLS
|
|
19
|
+
className: ClassName.COLUMN_DROP_TARGET_CONTROLS,
|
|
20
|
+
contentEditable: false
|
|
29
21
|
}, /*#__PURE__*/React.createElement("div", {
|
|
30
22
|
className: ClassName.COLUMN_CONTROLS_INNER,
|
|
31
23
|
"data-testid": "table-floating-column-controls-drop-targets"
|
|
32
|
-
}, colWidths.map(function (width, index) {
|
|
24
|
+
}, colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width, index) {
|
|
33
25
|
return /*#__PURE__*/React.createElement(ColumnDropTarget, {
|
|
34
26
|
key: index,
|
|
35
27
|
index: index,
|
|
@@ -39,59 +31,4 @@ export var ColumnDropTargets = function ColumnDropTargets(_ref) {
|
|
|
39
31
|
marginTop: marginTop
|
|
40
32
|
});
|
|
41
33
|
})));
|
|
42
|
-
};
|
|
43
|
-
export default ColumnDropTargets;
|
|
44
|
-
var ColumnDropTarget = function ColumnDropTarget(_ref2) {
|
|
45
|
-
var index = _ref2.index,
|
|
46
|
-
localId = _ref2.localId,
|
|
47
|
-
width = _ref2.width,
|
|
48
|
-
height = _ref2.height,
|
|
49
|
-
marginTop = _ref2.marginTop;
|
|
50
|
-
var dropTargetRef = useRef(null);
|
|
51
|
-
useEffect(function () {
|
|
52
|
-
if (!dropTargetRef.current) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
return dropTargetForElements({
|
|
56
|
-
element: dropTargetRef.current,
|
|
57
|
-
canDrop: function canDrop(_ref3) {
|
|
58
|
-
var _data$indexes, _data$indexes2;
|
|
59
|
-
var source = _ref3.source;
|
|
60
|
-
var data = source.data;
|
|
61
|
-
return (
|
|
62
|
-
// Only draggables of row type can be dropped on this target
|
|
63
|
-
data.type === 'table-column' &&
|
|
64
|
-
// Only draggables which came from the same table can be dropped on this target
|
|
65
|
-
data.localId === localId &&
|
|
66
|
-
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
67
|
-
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
|
|
68
|
-
);
|
|
69
|
-
},
|
|
70
|
-
getData: function getData(_ref4) {
|
|
71
|
-
var input = _ref4.input,
|
|
72
|
-
element = _ref4.element;
|
|
73
|
-
var data = {
|
|
74
|
-
localId: localId,
|
|
75
|
-
type: 'table-column',
|
|
76
|
-
targetIndex: index
|
|
77
|
-
};
|
|
78
|
-
return attachClosestEdge(data, {
|
|
79
|
-
input: input,
|
|
80
|
-
element: element,
|
|
81
|
-
allowedEdges: ['left', 'right']
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}, [index, localId]);
|
|
86
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
87
|
-
ref: dropTargetRef,
|
|
88
|
-
style: {
|
|
89
|
-
width: width && "".concat(width - 1, "px"),
|
|
90
|
-
height: height && "".concat(height, "px"),
|
|
91
|
-
marginTop: marginTop && "".concat(marginTop, "px")
|
|
92
|
-
},
|
|
93
|
-
"data-drop-target-index": index,
|
|
94
|
-
"data-drop-target-localid": localId,
|
|
95
|
-
"data-testid": "table-floating-column-controls-drop-target"
|
|
96
|
-
});
|
|
97
34
|
};
|