@atlaskit/editor-plugin-table 5.3.9 → 5.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/plugins/table/commands/hover.js +4 -2
- package/dist/cjs/plugins/table/event-handlers.js +7 -4
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +3 -2
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +11 -25
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +59 -22
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +15 -27
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +68 -18
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +47 -29
- package/dist/cjs/plugins/table/ui/common-styles.js +2 -2
- package/dist/cjs/plugins/table/ui/icons/DragHandleIcon.js +11 -52
- package/dist/es2019/plugins/table/commands/hover.js +4 -2
- package/dist/es2019/plugins/table/event-handlers.js +7 -4
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +3 -2
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +10 -24
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +61 -18
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
- package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +4 -20
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +69 -17
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +24 -2
- package/dist/es2019/plugins/table/ui/common-styles.js +64 -4
- package/dist/es2019/plugins/table/ui/icons/DragHandleIcon.js +11 -52
- package/dist/esm/plugins/table/commands/hover.js +4 -2
- package/dist/esm/plugins/table/event-handlers.js +7 -4
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +3 -2
- package/dist/esm/plugins/table/ui/DragHandle/index.js +11 -25
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +56 -21
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
- package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +16 -28
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +67 -19
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +48 -30
- package/dist/esm/plugins/table/ui/common-styles.js +2 -2
- package/dist/esm/plugins/table/ui/icons/DragHandleIcon.js +11 -51
- package/dist/types/plugins/table/commands/hover.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +8 -4
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +3 -3
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +6 -5
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +3 -2
- package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +1 -1
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +6 -4
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types/plugins/table/ui/icons/DragHandleIcon.d.ts +1 -6
- package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +8 -4
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +3 -3
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +6 -5
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +6 -4
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/ui/icons/DragHandleIcon.d.ts +1 -6
- package/package.json +1 -1
- package/src/__tests__/unit/event-handlers.ts +4 -1
- package/src/__tests__/unit/ui/NumberColumn.tsx +5 -8
- package/src/__tests__/unit/ui/RowDragControls.tsx +6 -0
- package/src/plugins/table/commands/hover.ts +7 -2
- package/src/plugins/table/event-handlers.ts +18 -4
- package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
- package/src/plugins/table/types.ts +13 -4
- package/src/plugins/table/ui/DragHandle/index.tsx +10 -26
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +90 -39
- package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +5 -2
- package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +10 -15
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +97 -28
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +19 -3
- package/src/plugins/table/ui/common-styles.ts +67 -4
- package/src/plugins/table/ui/icons/DragHandleIcon.tsx +5 -69
|
@@ -1,47 +1,99 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useCallback, useMemo } from 'react';
|
|
2
2
|
import { injectIntl } from 'react-intl-next';
|
|
3
|
-
import {
|
|
3
|
+
import { CellSelection } from '@atlaskit/editor-tables';
|
|
4
|
+
import { findTable, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
5
|
+
import { clearHoverSelection } from '../../../commands';
|
|
4
6
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
5
|
-
import { getRowHeights } from '../../../utils';
|
|
7
|
+
import { getRowHeights, getSelectedRowIndexes } from '../../../utils';
|
|
6
8
|
import { DragHandle } from '../../DragHandle';
|
|
9
|
+
const getSelectedRows = selection => {
|
|
10
|
+
if (selection instanceof CellSelection && selection.isRowSelection()) {
|
|
11
|
+
const rect = getSelectionRect(selection);
|
|
12
|
+
if (!rect) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
return getSelectedRowIndexes(rect);
|
|
16
|
+
}
|
|
17
|
+
return [];
|
|
18
|
+
};
|
|
7
19
|
const DragControlsComponent = ({
|
|
8
20
|
tableRef,
|
|
9
21
|
hoveredCell,
|
|
22
|
+
tableActive,
|
|
23
|
+
editorView,
|
|
24
|
+
isInDanger,
|
|
10
25
|
hoverRows,
|
|
11
26
|
selectRow,
|
|
12
|
-
|
|
13
|
-
editorView
|
|
27
|
+
updateCellHoverLocation
|
|
14
28
|
}) => {
|
|
15
29
|
const rowHeights = getRowHeights(tableRef);
|
|
16
|
-
const heights = rowHeights.map(
|
|
30
|
+
const heights = rowHeights.map(height => `${height - 1}px`).join(' ');
|
|
31
|
+
const selectedRowIndexes = getSelectedRows(editorView.state.selection);
|
|
17
32
|
const rowWidth = tableRef.offsetWidth;
|
|
18
|
-
const onClick = (index, event) => {};
|
|
19
|
-
const onMouseOver = () => {};
|
|
20
|
-
const onMouseOut = () => {};
|
|
21
33
|
const rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
|
|
34
|
+
const gridRowPosition = useMemo(() => {
|
|
35
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
36
|
+
if (selectedRowIndexes.includes(rowIndex)) {
|
|
37
|
+
return `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
|
|
38
|
+
}
|
|
39
|
+
return `${rowIndex + 1} / span 1`;
|
|
40
|
+
}, [rowIndex, selectedRowIndexes]);
|
|
22
41
|
const getLocalId = () => {
|
|
23
42
|
var _tableNode$node, _tableNode$node$attrs;
|
|
24
43
|
const tableNode = findTable(editorView.state.selection);
|
|
25
44
|
return (tableNode === null || tableNode === void 0 ? void 0 : (_tableNode$node = tableNode.node) === null || _tableNode$node === void 0 ? void 0 : (_tableNode$node$attrs = _tableNode$node.attrs) === null || _tableNode$node$attrs === void 0 ? void 0 : _tableNode$node$attrs.localId) || '';
|
|
26
45
|
};
|
|
46
|
+
const handleMouseOut = useCallback(() => {
|
|
47
|
+
if (tableActive) {
|
|
48
|
+
const {
|
|
49
|
+
state,
|
|
50
|
+
dispatch
|
|
51
|
+
} = editorView;
|
|
52
|
+
clearHoverSelection()(state, dispatch);
|
|
53
|
+
}
|
|
54
|
+
}, [editorView, tableActive]);
|
|
55
|
+
const handleMouseMove = useCallback(e => {
|
|
56
|
+
// avoid updating if event target is drag handle
|
|
57
|
+
if (!e.nativeEvent.target.classList.contains(ClassName.ROW_CONTROLS_WITH_DRAG)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const hoverHeight = e.nativeEvent.offsetY;
|
|
61
|
+
let totalHeight = 0;
|
|
62
|
+
const rowIndex = rowHeights.findIndex(row => {
|
|
63
|
+
totalHeight += row;
|
|
64
|
+
return hoverHeight <= totalHeight;
|
|
65
|
+
});
|
|
66
|
+
updateCellHoverLocation(rowIndex);
|
|
67
|
+
}, [updateCellHoverLocation, rowHeights]);
|
|
68
|
+
const handleMouseOver = useCallback(() => {
|
|
69
|
+
hoverRows([rowIndex]);
|
|
70
|
+
}, [hoverRows, rowIndex]);
|
|
71
|
+
const handleClick = useCallback(e => {
|
|
72
|
+
selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
|
|
73
|
+
}, [rowIndex, selectRow]);
|
|
27
74
|
return /*#__PURE__*/React.createElement("div", {
|
|
28
75
|
className: ClassName.ROW_CONTROLS_WITH_DRAG,
|
|
29
76
|
style: {
|
|
30
77
|
gridTemplateRows: heights
|
|
31
|
-
}
|
|
32
|
-
|
|
78
|
+
},
|
|
79
|
+
onMouseMove: handleMouseMove
|
|
80
|
+
}, Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
|
|
33
81
|
style: {
|
|
34
|
-
gridRow:
|
|
35
|
-
display: 'flex'
|
|
82
|
+
gridRow: gridRowPosition,
|
|
83
|
+
display: 'flex',
|
|
84
|
+
height: '100%',
|
|
85
|
+
alignItems: 'center',
|
|
86
|
+
justifyContent: 'center'
|
|
36
87
|
}
|
|
37
88
|
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
38
|
-
onClick: event => onClick(rowIndex, event),
|
|
39
|
-
onMouseOver: onMouseOver,
|
|
40
|
-
onMouseOut: onMouseOut,
|
|
41
89
|
tableLocalId: getLocalId(),
|
|
42
90
|
indexes: [rowIndex],
|
|
43
91
|
previewWidth: rowWidth,
|
|
44
|
-
previewHeight: rowHeights[rowIndex]
|
|
92
|
+
previewHeight: rowHeights[rowIndex],
|
|
93
|
+
appearance: selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
94
|
+
onClick: handleClick,
|
|
95
|
+
onMouseOver: handleMouseOver,
|
|
96
|
+
onMouseOut: handleMouseOut
|
|
45
97
|
})));
|
|
46
98
|
};
|
|
47
99
|
export const DragControls = injectIntl(DragControlsComponent);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import React, { Component } from 'react';
|
|
3
3
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
4
|
-
import { hoverRows, selectRow } from '../../commands';
|
|
4
|
+
import { hoverCell, hoverRows, selectRow } from '../../commands';
|
|
5
|
+
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
5
6
|
import { isSelectionUpdated } from '../../utils';
|
|
6
7
|
import { CornerControls } from './CornerControls';
|
|
7
8
|
import NumberColumn from './NumberColumn';
|
|
@@ -30,6 +31,23 @@ export default class TableFloatingControls extends Component {
|
|
|
30
31
|
} = this.props.editorView;
|
|
31
32
|
hoverRows(rows, danger)(state, dispatch);
|
|
32
33
|
});
|
|
34
|
+
// re-use across numbered columns and row controls
|
|
35
|
+
_defineProperty(this, "updateCellHoverLocation", rowIndex => {
|
|
36
|
+
const {
|
|
37
|
+
editorView,
|
|
38
|
+
tableActive
|
|
39
|
+
} = this.props;
|
|
40
|
+
const {
|
|
41
|
+
state,
|
|
42
|
+
dispatch
|
|
43
|
+
} = editorView;
|
|
44
|
+
const {
|
|
45
|
+
hoveredCell
|
|
46
|
+
} = getPluginState(state);
|
|
47
|
+
if (tableActive && hoveredCell.rowIndex !== rowIndex) {
|
|
48
|
+
hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
33
51
|
}
|
|
34
52
|
componentDidMount() {
|
|
35
53
|
this.tryInitResizeObserver();
|
|
@@ -115,14 +133,18 @@ export default class TableFloatingControls extends Component {
|
|
|
115
133
|
isInDanger: isInDanger,
|
|
116
134
|
isResizing: isResizing,
|
|
117
135
|
selectRow: this.selectRow,
|
|
136
|
+
updateCellHoverLocation: this.updateCellHoverLocation,
|
|
118
137
|
stickyTop: stickyTop,
|
|
119
138
|
isDragAndDropEnabled: isDragAndDropEnabled
|
|
120
139
|
}) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(DragControls, {
|
|
121
140
|
tableRef: tableRef,
|
|
122
141
|
hoveredCell: hoveredCell,
|
|
123
142
|
editorView: editorView,
|
|
143
|
+
tableActive: tableActive,
|
|
144
|
+
isInDanger: isInDanger,
|
|
124
145
|
hoverRows: this.hoverRows,
|
|
125
|
-
selectRow: this.selectRow
|
|
146
|
+
selectRow: this.selectRow,
|
|
147
|
+
updateCellHoverLocation: this.updateCellHoverLocation
|
|
126
148
|
}) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
|
|
127
149
|
editorView: editorView,
|
|
128
150
|
tableRef: tableRef,
|
|
@@ -164,7 +164,7 @@ const tableRowControlStyles = () => {
|
|
|
164
164
|
position: absolute;
|
|
165
165
|
margin-top: ${tableMarginTop}px;
|
|
166
166
|
left: -${tableToolbarSize + 1}px;
|
|
167
|
-
z-index: ${rowControlsZIndex};
|
|
167
|
+
z-index: ${rowControlsZIndex + 4};
|
|
168
168
|
}
|
|
169
169
|
` : css`
|
|
170
170
|
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
@@ -607,14 +607,74 @@ export const tableStyles = props => {
|
|
|
607
607
|
align-items: center;
|
|
608
608
|
position: absolute;
|
|
609
609
|
left: -4px;
|
|
610
|
+
z-index: ${akEditorUnitZIndex};
|
|
610
611
|
}
|
|
611
612
|
|
|
612
613
|
.${ClassName.DRAG_HANDLE_BUTTON_CONTAINER} {
|
|
613
614
|
cursor: grab;
|
|
614
|
-
width: max-content;
|
|
615
615
|
padding: 0;
|
|
616
|
-
|
|
617
|
-
|
|
616
|
+
|
|
617
|
+
border-radius: 6px;
|
|
618
|
+
width: max-content;
|
|
619
|
+
height: max-content;
|
|
620
|
+
border: 2px solid ${`var(--ds-surface, ${N0})`};
|
|
621
|
+
display: flex;
|
|
622
|
+
justify-content: center;
|
|
623
|
+
align-items: center;
|
|
624
|
+
|
|
625
|
+
svg {
|
|
626
|
+
rect {
|
|
627
|
+
//
|
|
628
|
+
fill: ${"var(--ds-background-accent-gray-subtlest, #F1F2F4)"};
|
|
629
|
+
}
|
|
630
|
+
g {
|
|
631
|
+
fill: ${"var(--ds-icon-subtle, #626F86)"};
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
&:hover {
|
|
636
|
+
svg {
|
|
637
|
+
rect {
|
|
638
|
+
fill: ${"var(--ds-background-accent-blue-subtle, #579DFF)"};
|
|
639
|
+
}
|
|
640
|
+
g {
|
|
641
|
+
fill: ${"var(--ds-icon-inverse, #FFF)"};
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
&.selected {
|
|
647
|
+
svg {
|
|
648
|
+
rect {
|
|
649
|
+
fill: ${"var(--ds-background-accent-blue-subtle, #579DFF)"};
|
|
650
|
+
}
|
|
651
|
+
g {
|
|
652
|
+
fill: ${"var(--ds-icon-inverse, #FFF)"};
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
&.danger {
|
|
658
|
+
svg {
|
|
659
|
+
rect {
|
|
660
|
+
fill: ${"var(--ds-background-accent-red-subtler-pressed, #F87462)"};
|
|
661
|
+
}
|
|
662
|
+
g {
|
|
663
|
+
fill: ${"var(--ds-border-inverse, #FFF)"};
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
&.disabled {
|
|
669
|
+
svg {
|
|
670
|
+
rect {
|
|
671
|
+
fill: ${"var(--ds-background-accent-gray-subtlest, #F1F2F4)"};
|
|
672
|
+
}
|
|
673
|
+
g {
|
|
674
|
+
fill: ${"var(--ds-border-inverse, #FFF)"};
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
618
678
|
}
|
|
619
679
|
|
|
620
680
|
${floatingColumnControls(props)}
|
|
@@ -1,54 +1,13 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
2
1
|
import React from 'react';
|
|
3
|
-
export const DragHandleIcon = ({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
height: "20",
|
|
9
|
-
viewBox: "0 0 28 20",
|
|
10
|
-
fill: "none",
|
|
11
|
-
xmlns: "http://www.w3.org/2000/svg"
|
|
2
|
+
export const DragHandleIcon = () => /*#__PURE__*/React.createElement("svg", {
|
|
3
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
4
|
+
width: "24",
|
|
5
|
+
height: "16",
|
|
6
|
+
fill: "none"
|
|
12
7
|
}, /*#__PURE__*/React.createElement("rect", {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}), /*#__PURE__*/React.createElement("g", {
|
|
20
|
-
clipPath: "url(#clip0_125_45007)"
|
|
21
|
-
}, /*#__PURE__*/React.createElement("path", {
|
|
22
|
-
d: "M11 12C11 11.4477 10.5523 11 10 11C9.44772 11 9 11.4477 9 12C9 12.5523 9.44772 13 10 13C10.5523 13 11 12.5523 11 12Z",
|
|
23
|
-
fill: foregroundColor || '#626F86'
|
|
24
|
-
}), /*#__PURE__*/React.createElement("path", {
|
|
25
|
-
d: "M11 8C11 7.44772 10.5523 7 10 7C9.44772 7 9 7.44772 9 8C9 8.55228 9.44772 9 10 9C10.5523 9 11 8.55228 11 8Z",
|
|
26
|
-
fill: foregroundColor || '#626F86'
|
|
27
|
-
}), /*#__PURE__*/React.createElement("path", {
|
|
28
|
-
d: "M19 12C19 11.4477 18.5523 11 18 11C17.4477 11 17 11.4477 17 12C17 12.5523 17.4477 13 18 13C18.5523 13 19 12.5523 19 12Z",
|
|
29
|
-
fill: foregroundColor || '#626F86'
|
|
30
|
-
}), /*#__PURE__*/React.createElement("path", {
|
|
31
|
-
d: "M19 8C19 7.44772 18.5523 7 18 7C17.4477 7 17 7.44772 17 8C17 8.55228 17.4477 9 18 9C18.5523 9 19 8.55228 19 8Z",
|
|
32
|
-
fill: foregroundColor || '#626F86'
|
|
33
|
-
}), /*#__PURE__*/React.createElement("path", {
|
|
34
|
-
d: "M15 12C15 11.4477 14.5523 11 14 11C13.4477 11 13 11.4477 13 12C13 12.5523 13.4477 13 14 13C14.5523 13 15 12.5523 15 12Z",
|
|
35
|
-
fill: foregroundColor || '#626F86'
|
|
36
|
-
}), /*#__PURE__*/React.createElement("path", {
|
|
37
|
-
d: "M15 8C15 7.44772 14.5523 7 14 7C13.4477 7 13 7.44772 13 8C13 8.55228 13.4477 9 14 9C14.5523 9 15 8.55228 15 8Z",
|
|
38
|
-
fill: foregroundColor || '#626F86'
|
|
39
|
-
})), /*#__PURE__*/React.createElement("rect", {
|
|
40
|
-
x: "1",
|
|
41
|
-
y: "1",
|
|
42
|
-
width: "26",
|
|
43
|
-
height: "18",
|
|
44
|
-
rx: "5",
|
|
45
|
-
stroke: "white",
|
|
46
|
-
strokeWidth: "2"
|
|
47
|
-
}), /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
|
|
48
|
-
id: "clip0_125_45007"
|
|
49
|
-
}, /*#__PURE__*/React.createElement("rect", {
|
|
50
|
-
width: "16",
|
|
51
|
-
height: "24",
|
|
52
|
-
fill: "white",
|
|
53
|
-
transform: "matrix(0 -1 1 0 2 18)"
|
|
54
|
-
}))));
|
|
8
|
+
width: "24",
|
|
9
|
+
height: "16",
|
|
10
|
+
rx: "4"
|
|
11
|
+
}), /*#__PURE__*/React.createElement("g", null, /*#__PURE__*/React.createElement("path", {
|
|
12
|
+
d: "M9 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM9 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM17 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM17 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM13 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM13 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z"
|
|
13
|
+
})));
|
|
@@ -131,14 +131,16 @@ export var hideResizeHandleLine = function hideResizeHandleLine() {
|
|
|
131
131
|
};
|
|
132
132
|
});
|
|
133
133
|
};
|
|
134
|
-
export var hoverCell = function hoverCell(rowIndex, colIndex) {
|
|
134
|
+
export var hoverCell = function hoverCell(rowIndex, colIndex, colWidth, colHeight) {
|
|
135
135
|
return createCommand(function () {
|
|
136
136
|
return {
|
|
137
137
|
type: 'HOVER_CELL',
|
|
138
138
|
data: {
|
|
139
139
|
hoveredCell: {
|
|
140
140
|
rowIndex: rowIndex,
|
|
141
|
-
colIndex: colIndex
|
|
141
|
+
colIndex: colIndex,
|
|
142
|
+
colWidth: colWidth,
|
|
143
|
+
colHeight: colHeight
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
};
|
|
@@ -171,7 +171,7 @@ export var handleMouseLeave = function handleMouseLeave(view, event) {
|
|
|
171
171
|
return true;
|
|
172
172
|
}
|
|
173
173
|
if (isDragAndDropEnabled) {
|
|
174
|
-
hoverCell(
|
|
174
|
+
hoverCell()(state, dispatch);
|
|
175
175
|
}
|
|
176
176
|
if ((typeof insertColumnButtonIndex !== 'undefined' || typeof insertRowButtonIndex !== 'undefined') && hideInsertColumnOrRowButton()(state, dispatch)) {
|
|
177
177
|
return true;
|
|
@@ -317,7 +317,8 @@ export var whenTableInFocus = function whenTableInFocus(eventHandler, elementCon
|
|
|
317
317
|
var trackCellLocation = function trackCellLocation(view, mouseEvent) {
|
|
318
318
|
var target = mouseEvent.target;
|
|
319
319
|
var maybeTableCell = isElementInTableCell(target);
|
|
320
|
-
|
|
320
|
+
var tableRef = getPluginState(view.state).tableRef;
|
|
321
|
+
if (!maybeTableCell || !tableRef) {
|
|
321
322
|
return;
|
|
322
323
|
}
|
|
323
324
|
var colIndex = maybeTableCell.cellIndex;
|
|
@@ -325,8 +326,10 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
|
|
|
325
326
|
var rowIndex = rowElement && rowElement.rowIndex;
|
|
326
327
|
var _getPluginState8 = getPluginState(view.state),
|
|
327
328
|
hoveredCell = _getPluginState8.hoveredCell;
|
|
328
|
-
|
|
329
|
-
|
|
329
|
+
var colHeight = tableRef.offsetHeight;
|
|
330
|
+
var colWidth = maybeTableCell.offsetWidth;
|
|
331
|
+
if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex || hoveredCell.colWidth !== colWidth || hoveredCell.colHeight !== colHeight) {
|
|
332
|
+
hoverCell(rowIndex, colIndex, colWidth, colHeight)(view.state, view.dispatch);
|
|
330
333
|
}
|
|
331
334
|
};
|
|
332
335
|
export var withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
|
|
@@ -489,11 +489,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
489
489
|
headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
|
|
490
490
|
stickyHeader: this.state.stickyHeader
|
|
491
491
|
}));
|
|
492
|
-
var colControls = /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
|
|
492
|
+
var colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
|
|
493
493
|
editorView: view,
|
|
494
494
|
tableRef: tableRef,
|
|
495
495
|
getNode: getNode,
|
|
496
496
|
tableActive: tableActive,
|
|
497
|
+
isInDanger: isInDanger,
|
|
497
498
|
hoveredRows: hoveredRows,
|
|
498
499
|
hoveredCell: hoveredCell,
|
|
499
500
|
isResizing: isResizing,
|
|
@@ -505,7 +506,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
505
506
|
headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
|
|
506
507
|
stickyHeader: this.state.stickyHeader,
|
|
507
508
|
getEditorFeatureFlags: this.props.getEditorFeatureFlags
|
|
508
|
-
});
|
|
509
|
+
}) : null;
|
|
509
510
|
var shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
|
|
510
511
|
var shadowStyle = memoizeOne(function (visible) {
|
|
511
512
|
return {
|
|
@@ -1,39 +1,25 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import classnames from 'classnames';
|
|
3
4
|
import ReactDOM from 'react-dom';
|
|
4
5
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
5
6
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
6
|
-
import { N200, N700 } from '@atlaskit/theme/colors';
|
|
7
7
|
import { TableCssClassName as ClassName } from '../../types';
|
|
8
8
|
import { DragPreview } from '../DragPreview';
|
|
9
9
|
import { DragHandleIcon } from '../icons';
|
|
10
|
-
var mapStateToProps = function mapStateToProps(state) {
|
|
11
|
-
switch (state) {
|
|
12
|
-
case 'danger':
|
|
13
|
-
case 'disabled':
|
|
14
|
-
case 'selected':
|
|
15
|
-
case 'default':
|
|
16
|
-
default:
|
|
17
|
-
return {
|
|
18
|
-
backgroundColor: "var(--ds-background-accent-gray-subtlest, ".concat(N200, ")"),
|
|
19
|
-
foregroundColor: "var(--ds-icon-subtle, ".concat(N700, ")")
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
10
|
export var DragHandle = function DragHandle(_ref) {
|
|
24
11
|
var tableLocalId = _ref.tableLocalId,
|
|
25
12
|
_ref$direction = _ref.direction,
|
|
26
13
|
direction = _ref$direction === void 0 ? 'row' : _ref$direction,
|
|
27
|
-
_ref$
|
|
28
|
-
|
|
14
|
+
_ref$appearance = _ref.appearance,
|
|
15
|
+
appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
|
|
29
16
|
indexes = _ref.indexes,
|
|
30
17
|
previewWidth = _ref.previewWidth,
|
|
31
18
|
previewHeight = _ref.previewHeight,
|
|
32
|
-
onClick = _ref.onClick,
|
|
33
19
|
onMouseOver = _ref.onMouseOver,
|
|
34
|
-
onMouseOut = _ref.onMouseOut
|
|
20
|
+
onMouseOut = _ref.onMouseOut,
|
|
21
|
+
onClick = _ref.onClick;
|
|
35
22
|
var dragHandleDivRef = useRef(null);
|
|
36
|
-
var iconProps = mapStateToProps(state);
|
|
37
23
|
var _useState = useState(null),
|
|
38
24
|
_useState2 = _slicedToArray(_useState, 2),
|
|
39
25
|
previewContainer = _useState2[0],
|
|
@@ -82,17 +68,17 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
82
68
|
}
|
|
83
69
|
}, [tableLocalId, direction, indexes]);
|
|
84
70
|
return /*#__PURE__*/React.createElement("button", {
|
|
85
|
-
className: ClassName.DRAG_HANDLE_BUTTON_CONTAINER,
|
|
71
|
+
className: classnames(ClassName.DRAG_HANDLE_BUTTON_CONTAINER, appearance),
|
|
86
72
|
ref: dragHandleDivRef,
|
|
87
73
|
style: {
|
|
88
|
-
backgroundColor: "var(--ds-surface, white)",
|
|
89
|
-
borderRadius: '4px',
|
|
90
|
-
border: "2px solid ".concat("var(--ds-surface, white)"),
|
|
91
74
|
transform: direction === 'column' ? 'none' : 'rotate(90deg)',
|
|
92
75
|
pointerEvents: 'auto'
|
|
93
76
|
},
|
|
94
|
-
"data-testid": "table-floating-column-controls-drag-handle"
|
|
95
|
-
|
|
77
|
+
"data-testid": "table-floating-column-controls-drag-handle",
|
|
78
|
+
onMouseOver: onMouseOver,
|
|
79
|
+
onMouseOut: onMouseOut,
|
|
80
|
+
onClick: onClick
|
|
81
|
+
}, /*#__PURE__*/React.createElement(DragHandleIcon, null), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
|
|
96
82
|
direction: direction,
|
|
97
83
|
width: previewWidth,
|
|
98
84
|
height: previewHeight
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useCallback, useMemo } from 'react';
|
|
2
|
+
import { CellSelection } from '@atlaskit/editor-tables';
|
|
3
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
4
|
+
import { clearHoverSelection, hoverColumns, selectColumn } from '../../../commands';
|
|
2
5
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
6
|
+
import { getSelectedColumnIndexes } from '../../../utils';
|
|
3
7
|
import { DragHandle } from '../../DragHandle';
|
|
8
|
+
var getSelectedColumns = function getSelectedColumns(selection) {
|
|
9
|
+
if (selection instanceof CellSelection && selection.isColSelection()) {
|
|
10
|
+
var rect = getSelectionRect(selection);
|
|
11
|
+
if (!rect) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return getSelectedColumnIndexes(rect);
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
};
|
|
4
18
|
export var ColumnControls = function ColumnControls(_ref) {
|
|
5
|
-
var
|
|
19
|
+
var _colWidths$map$join, _rowHeights$;
|
|
6
20
|
var editorView = _ref.editorView,
|
|
7
21
|
tableActive = _ref.tableActive,
|
|
8
22
|
tableRef = _ref.tableRef,
|
|
@@ -10,21 +24,41 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
10
24
|
isResizing = _ref.isResizing,
|
|
11
25
|
stickyTop = _ref.stickyTop,
|
|
12
26
|
localId = _ref.localId,
|
|
27
|
+
isInDanger = _ref.isInDanger,
|
|
13
28
|
rowHeights = _ref.rowHeights,
|
|
14
29
|
colWidths = _ref.colWidths;
|
|
15
|
-
if (!tableRef) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
var firstRow = tableRef.querySelector('tr');
|
|
19
|
-
var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
20
|
-
var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
21
30
|
var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
|
|
22
31
|
return width ? "".concat(width - 1, "px") : '0px';
|
|
23
32
|
}).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
|
|
24
33
|
var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
|
|
34
|
+
var selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
35
|
+
var gridColumnPosition = useMemo(function () {
|
|
36
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
37
|
+
if (selectedColIndexes.includes(colIndex)) {
|
|
38
|
+
return "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
|
|
39
|
+
}
|
|
40
|
+
return "".concat(colIndex + 1, " / span 1");
|
|
41
|
+
}, [colIndex, selectedColIndexes]);
|
|
42
|
+
var firstRow = tableRef.querySelector('tr');
|
|
43
|
+
var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
44
|
+
var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
45
|
+
var handleClick = useCallback(function (event) {
|
|
46
|
+
var state = editorView.state,
|
|
47
|
+
dispatch = editorView.dispatch;
|
|
48
|
+
selectColumn(colIndex, event.shiftKey)(state, dispatch);
|
|
49
|
+
}, [colIndex, editorView]);
|
|
50
|
+
var handleMouseOver = useCallback(function () {
|
|
51
|
+
var state = editorView.state,
|
|
52
|
+
dispatch = editorView.dispatch;
|
|
53
|
+
hoverColumns([colIndex])(state, dispatch);
|
|
54
|
+
}, [colIndex, editorView]);
|
|
55
|
+
var handleMouseOut = useCallback(function () {
|
|
56
|
+
if (tableActive) {
|
|
57
|
+
var state = editorView.state,
|
|
58
|
+
dispatch = editorView.dispatch;
|
|
59
|
+
clearHoverSelection()(state, dispatch);
|
|
60
|
+
}
|
|
61
|
+
}, [editorView, tableActive]);
|
|
28
62
|
return /*#__PURE__*/React.createElement("div", {
|
|
29
63
|
className: ClassName.COLUMN_CONTROLS_WITH_DRAG
|
|
30
64
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -34,22 +68,23 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
34
68
|
gridTemplateColumns: widths,
|
|
35
69
|
marginTop: marginTop
|
|
36
70
|
}
|
|
37
|
-
}, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/React.createElement("div", {
|
|
71
|
+
}, tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
|
|
38
72
|
style: {
|
|
39
|
-
gridColumn:
|
|
73
|
+
gridColumn: gridColumnPosition,
|
|
40
74
|
marginTop: "-15px"
|
|
41
75
|
},
|
|
42
|
-
"data-column-control-index": colIndex,
|
|
76
|
+
"data-column-control-index": hoveredCell.colIndex,
|
|
43
77
|
"data-testid": "table-floating-column-control"
|
|
44
78
|
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
45
79
|
direction: "column",
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
80
|
+
tableLocalId: localId || '',
|
|
81
|
+
indexes: [hoveredCell.colIndex],
|
|
82
|
+
previewWidth: hoveredCell.colWidth,
|
|
83
|
+
previewHeight: hoveredCell.colHeight,
|
|
84
|
+
appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
85
|
+
onClick: handleClick,
|
|
86
|
+
onMouseOver: handleMouseOver,
|
|
87
|
+
onMouseOut: handleMouseOut
|
|
53
88
|
}))));
|
|
54
89
|
};
|
|
55
90
|
export default ColumnControls;
|
|
@@ -18,7 +18,8 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
|
|
|
18
18
|
hoveredCell = _ref.hoveredCell,
|
|
19
19
|
isResizing = _ref.isResizing,
|
|
20
20
|
stickyHeader = _ref.stickyHeader,
|
|
21
|
-
selection = _ref.selection
|
|
21
|
+
selection = _ref.selection,
|
|
22
|
+
isInDanger = _ref.isInDanger;
|
|
22
23
|
var _useState = useState({
|
|
23
24
|
width: 0,
|
|
24
25
|
height: 0
|
|
@@ -108,6 +109,7 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
|
|
|
108
109
|
tableActive: tableActive,
|
|
109
110
|
stickyTop: tableActive ? stickyTop : undefined,
|
|
110
111
|
localId: currentNodeLocalId,
|
|
112
|
+
isInDanger: isInDanger,
|
|
111
113
|
rowHeights: rowHeights,
|
|
112
114
|
colWidths: colWidths
|
|
113
115
|
}), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
|