@atlaskit/editor-plugin-table 5.5.1 → 5.5.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 +13 -0
- package/dist/cjs/plugins/table/index.js +1 -1
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +22 -26
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -7
- package/dist/cjs/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -15
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +8 -19
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +62 -34
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +58 -30
- package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
- package/dist/es2019/plugins/table/index.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +25 -29
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -7
- package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -15
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +5 -18
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +62 -34
- package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +3 -1
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +58 -30
- package/dist/es2019/plugins/table/ui/common-styles.js +2 -1
- package/dist/esm/plugins/table/index.js +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +22 -26
- package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -7
- package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -15
- package/dist/esm/plugins/table/ui/DragHandle/index.js +6 -17
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +62 -34
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +58 -30
- package/dist/esm/plugins/table/ui/common-styles.js +1 -1
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +2 -7
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +2 -7
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +2 -1
- package/package.json +1 -4
- package/src/plugins/table/index.tsx +5 -7
- package/src/plugins/table/nodeviews/TableComponent.tsx +31 -38
- package/src/plugins/table/pm-plugins/table-resizing/event-handlers.ts +5 -7
- package/src/plugins/table/types.ts +2 -0
- package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +5 -30
- package/src/plugins/table/ui/DragHandle/index.tsx +6 -23
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +112 -47
- package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +3 -3
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +116 -42
- package/src/plugins/table/ui/common-styles.ts +2 -1
|
@@ -395,10 +395,8 @@ class TableComponent extends React.Component {
|
|
|
395
395
|
this.onStickyState(currentStickyState);
|
|
396
396
|
}
|
|
397
397
|
eventDispatcher.on(stickyHeadersPluginKey.key, this.onStickyState);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
|
|
401
|
-
}
|
|
398
|
+
const initialIsOveflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
399
|
+
this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
|
|
402
400
|
}
|
|
403
401
|
componentWillUnmount() {
|
|
404
402
|
const {
|
|
@@ -487,31 +485,29 @@ class TableComponent extends React.Component {
|
|
|
487
485
|
}
|
|
488
486
|
this.handleTableResizingDebounced();
|
|
489
487
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}));
|
|
514
|
-
}
|
|
488
|
+
const newIsOverflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
489
|
+
const prevIsOverflowing = prevState[ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
490
|
+
if (this.initialOverflowCaptureTimerId) {
|
|
491
|
+
clearTimeout(this.initialOverflowCaptureTimerId);
|
|
492
|
+
}
|
|
493
|
+
if (!this.isInitialOverflowSent) {
|
|
494
|
+
this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
|
|
495
|
+
}
|
|
496
|
+
if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
|
|
497
|
+
var _this$state2;
|
|
498
|
+
const {
|
|
499
|
+
dispatch,
|
|
500
|
+
state: {
|
|
501
|
+
tr
|
|
502
|
+
}
|
|
503
|
+
} = this.props.view;
|
|
504
|
+
dispatch(tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
|
|
505
|
+
isOverflowing: newIsOverflowing,
|
|
506
|
+
wasOverflowing: prevIsOverflowing,
|
|
507
|
+
editorWidth: this.props.containerWidth.width || 0,
|
|
508
|
+
width: this.node.attrs.width || 0,
|
|
509
|
+
parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
|
|
510
|
+
}));
|
|
515
511
|
}
|
|
516
512
|
}
|
|
517
513
|
render() {
|
|
@@ -23,13 +23,11 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
event.preventDefault();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
dispatch(tr);
|
|
32
|
-
}
|
|
26
|
+
const tr = view.state.tr;
|
|
27
|
+
tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
28
|
+
name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED_COLUMN
|
|
29
|
+
});
|
|
30
|
+
dispatch(tr);
|
|
33
31
|
const mouseDownTime = event.timeStamp;
|
|
34
32
|
const cell = state.doc.nodeAt(localResizeHandlePos);
|
|
35
33
|
const $cell = state.doc.resolve(localResizeHandlePos);
|
|
@@ -2,25 +2,14 @@ import React from 'react';
|
|
|
2
2
|
import { DragHandleDisabledIcon, DragHandleIcon, MinimisedHandleIcon } from '../icons';
|
|
3
3
|
export const HandleIconComponent = props => {
|
|
4
4
|
const {
|
|
5
|
-
|
|
6
|
-
direction,
|
|
7
|
-
isDragMenuOpen,
|
|
5
|
+
forceDefaultHandle,
|
|
8
6
|
isRowHandleHovered,
|
|
9
7
|
isColumnHandleHovered,
|
|
10
|
-
hasMergedCells
|
|
11
|
-
isCurrentRowSelected,
|
|
12
|
-
isCurrentColumnSelected,
|
|
13
|
-
dragMenuDirection
|
|
8
|
+
hasMergedCells
|
|
14
9
|
} = props;
|
|
15
10
|
const isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const isDragPossible = canDrag && !hasMergedCells;
|
|
19
|
-
const showNormalHandle = !isDragPossible ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
|
|
20
|
-
|
|
21
|
-
// hoverred handle or open drag menu
|
|
22
|
-
if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
23
|
-
return showNormalHandle;
|
|
11
|
+
if (isHandleHovered || forceDefaultHandle) {
|
|
12
|
+
return hasMergedCells ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
|
|
24
13
|
}
|
|
25
14
|
return /*#__PURE__*/React.createElement(MinimisedHandleIcon, null);
|
|
26
15
|
};
|
|
@@ -4,7 +4,6 @@ import ReactDOM from 'react-dom';
|
|
|
4
4
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
5
5
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
6
6
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
7
|
-
import { getPluginState as getDragDropPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
8
7
|
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
9
8
|
import { TableCssClassName as ClassName } from '../../types';
|
|
10
9
|
import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
@@ -15,6 +14,7 @@ export const DragHandle = ({
|
|
|
15
14
|
direction = 'row',
|
|
16
15
|
appearance = 'default',
|
|
17
16
|
indexes,
|
|
17
|
+
forceDefaultHandle = false,
|
|
18
18
|
previewWidth,
|
|
19
19
|
previewHeight,
|
|
20
20
|
onMouseOver,
|
|
@@ -28,32 +28,19 @@ export const DragHandle = ({
|
|
|
28
28
|
const [previewContainer, setPreviewContainer] = useState(null);
|
|
29
29
|
const {
|
|
30
30
|
hoveredColumns,
|
|
31
|
-
hoveredRows
|
|
32
|
-
hoveredCell
|
|
31
|
+
hoveredRows
|
|
33
32
|
} = getPluginState(editorView.state);
|
|
34
|
-
const {
|
|
35
|
-
dragMenuDirection,
|
|
36
|
-
isDragMenuOpen,
|
|
37
|
-
dragMenuIndex
|
|
38
|
-
} = getDragDropPluginState(editorView.state);
|
|
39
33
|
const {
|
|
40
34
|
selection
|
|
41
35
|
} = editorView.state;
|
|
42
|
-
const isCurrentRowSelected = isDragMenuOpen && direction === 'row' && hoveredCell.rowIndex === dragMenuIndex;
|
|
43
|
-
const isCurrentColumnSelected = isDragMenuOpen && direction === 'column' && hoveredCell.colIndex === dragMenuIndex;
|
|
44
36
|
const isRowHandleHovered = direction === 'row' && hoveredRows.length > 0;
|
|
45
37
|
const isColumnHandleHovered = direction === 'column' && hoveredColumns.length > 0;
|
|
46
38
|
const hasMergedCells = useMemo(() => direction === 'row' ? hasMergedCellsInRow(indexes[0])(selection) : hasMergedCellsInColumn(indexes[0])(selection), [indexes, direction, selection]);
|
|
47
39
|
const handleIconProps = {
|
|
48
|
-
|
|
49
|
-
hasMergedCells,
|
|
50
|
-
direction,
|
|
51
|
-
isDragMenuOpen,
|
|
52
|
-
isRowHandleHovered,
|
|
40
|
+
forceDefaultHandle,
|
|
53
41
|
isColumnHandleHovered,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
dragMenuDirection
|
|
42
|
+
isRowHandleHovered,
|
|
43
|
+
hasMergedCells
|
|
57
44
|
};
|
|
58
45
|
useEffect(() => {
|
|
59
46
|
const dragHandleDivRefCurrent = dragHandleDivRef.current;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
+
|
|
1
3
|
import React, { useCallback, useMemo } from 'react';
|
|
2
4
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
3
5
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
@@ -32,19 +34,12 @@ export const ColumnControls = ({
|
|
|
32
34
|
isTableHovered,
|
|
33
35
|
canDrag
|
|
34
36
|
}) => {
|
|
35
|
-
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce
|
|
37
|
+
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
|
|
36
38
|
const widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(width => width ? `${width - 1}px` : '0px').join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
|
|
37
39
|
// TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
|
|
38
40
|
const columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
|
|
39
41
|
const colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
|
|
40
42
|
const selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
41
|
-
const gridColumnPosition = useMemo(() => {
|
|
42
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
43
|
-
if (selectedColIndexes.includes(colIndex)) {
|
|
44
|
-
return `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`;
|
|
45
|
-
}
|
|
46
|
-
return `${colIndex + 1} / span 1`;
|
|
47
|
-
}, [colIndex, selectedColIndexes]);
|
|
48
43
|
const firstRow = tableRef.querySelector('tr');
|
|
49
44
|
const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
50
45
|
const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
@@ -104,6 +99,64 @@ export const ColumnControls = ({
|
|
|
104
99
|
return [colIndex];
|
|
105
100
|
}, [colIndex]);
|
|
106
101
|
const previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce((sum, cur) => sum + cur, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
|
|
102
|
+
const generateHandleByType = type => {
|
|
103
|
+
var _colWidths;
|
|
104
|
+
if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const isHover = type === 'hover';
|
|
108
|
+
const isColumnsSelected = selectedColIndexes.length > 0;
|
|
109
|
+
const showCondition = isHover ? isColumnsSelected && !selectedColIndexes.includes(colIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : selectedColIndexes.length < (colWidths === null || colWidths === void 0 ? void 0 : colWidths.length) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
|
|
110
|
+
if (!showCondition) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const gridColumnPosition = `${colIndex + 1} / span 1`;
|
|
114
|
+
const selectedColumnPosition = `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`;
|
|
115
|
+
const hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
|
|
116
|
+
const currentSelectionApprearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
|
|
117
|
+
const istSelecting = isColumnsSelected && !isHover;
|
|
118
|
+
|
|
119
|
+
// this indexes are used to calculate the drag and drop source
|
|
120
|
+
const indexes = isColumnsSelected ? isHover ? colIndexes : selectedColIndexes : colIndexes;
|
|
121
|
+
return showCondition && /*#__PURE__*/React.createElement("div", {
|
|
122
|
+
key: type,
|
|
123
|
+
style: {
|
|
124
|
+
gridColumn: istSelecting ? selectedColumnPosition : gridColumnPosition,
|
|
125
|
+
display: 'flex',
|
|
126
|
+
justifyContent: 'center',
|
|
127
|
+
alignItems: 'center',
|
|
128
|
+
height: 'fit-content',
|
|
129
|
+
placeSelf: 'center',
|
|
130
|
+
zIndex: 99
|
|
131
|
+
},
|
|
132
|
+
"data-column-control-index": hoveredCell.colIndex,
|
|
133
|
+
"data-testid": isHover ? 'table-floating-column-control-hover' : 'table-floating-column-control'
|
|
134
|
+
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
135
|
+
direction: "column",
|
|
136
|
+
tableLocalId: localId || '',
|
|
137
|
+
indexes: indexes,
|
|
138
|
+
forceDefaultHandle: isHover ? false : isColumnsSelected,
|
|
139
|
+
previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
|
|
140
|
+
previewHeight: previewHeight,
|
|
141
|
+
appearance: istSelecting ? currentSelectionApprearance : hoveredAppearance,
|
|
142
|
+
onClick: handleClick,
|
|
143
|
+
onMouseOver: handleMouseOver,
|
|
144
|
+
onMouseOut: handleMouseOut,
|
|
145
|
+
onMouseUp: handleMouseUp,
|
|
146
|
+
editorView: editorView,
|
|
147
|
+
canDrag: canDrag
|
|
148
|
+
}));
|
|
149
|
+
};
|
|
150
|
+
const columnHandles = hoveredCell => {
|
|
151
|
+
if (!hoveredCell) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (hoveredCell.colIndex === undefined) {
|
|
155
|
+
return generateHandleByType('selected');
|
|
156
|
+
}
|
|
157
|
+
const sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
|
|
158
|
+
return hoveredCell.colIndex < selectedColIndexes[0] ? sortedHandles : sortedHandles.reverse();
|
|
159
|
+
};
|
|
107
160
|
return /*#__PURE__*/React.createElement("div", {
|
|
108
161
|
className: ClassName.DRAG_COLUMN_CONTROLS,
|
|
109
162
|
onMouseMove: handleMouseMove
|
|
@@ -131,31 +184,6 @@ export const ColumnControls = ({
|
|
|
131
184
|
style: columnParams.length - 1 === index ? {
|
|
132
185
|
right: '0'
|
|
133
186
|
} : {}
|
|
134
|
-
}))), tableActive &&
|
|
135
|
-
style: {
|
|
136
|
-
gridColumn: gridColumnPosition,
|
|
137
|
-
display: 'flex',
|
|
138
|
-
justifyContent: 'center',
|
|
139
|
-
alignItems: 'center',
|
|
140
|
-
height: 'fit-content',
|
|
141
|
-
placeSelf: 'center',
|
|
142
|
-
zIndex: 99
|
|
143
|
-
},
|
|
144
|
-
"data-column-control-index": hoveredCell.colIndex,
|
|
145
|
-
"data-testid": "table-floating-column-control"
|
|
146
|
-
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
147
|
-
direction: "column",
|
|
148
|
-
tableLocalId: localId || '',
|
|
149
|
-
indexes: colIndexes,
|
|
150
|
-
previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
|
|
151
|
-
previewHeight: previewHeight,
|
|
152
|
-
appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
153
|
-
onClick: handleClick,
|
|
154
|
-
onMouseOver: handleMouseOver,
|
|
155
|
-
onMouseOut: handleMouseOut,
|
|
156
|
-
onMouseUp: handleMouseUp,
|
|
157
|
-
editorView: editorView,
|
|
158
|
-
canDrag: canDrag
|
|
159
|
-
}))));
|
|
187
|
+
}))), tableActive && isTableHovered && !isResizing && columnHandles(hoveredCell)));
|
|
160
188
|
};
|
|
161
189
|
export default ColumnControls;
|
|
@@ -10,7 +10,9 @@ import { tableBorderColor } from '../../consts';
|
|
|
10
10
|
export default class NumberColumn extends Component {
|
|
11
11
|
constructor(...args) {
|
|
12
12
|
super(...args);
|
|
13
|
-
_defineProperty(this, "hoverRows", index =>
|
|
13
|
+
_defineProperty(this, "hoverRows", index => {
|
|
14
|
+
return this.props.tableActive ? this.props.hoverRows([index]) : null;
|
|
15
|
+
});
|
|
14
16
|
_defineProperty(this, "selectRow", (index, event) => {
|
|
15
17
|
const {
|
|
16
18
|
tableActive,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
+
|
|
1
3
|
import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
4
|
import { injectIntl } from 'react-intl-next';
|
|
3
5
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
@@ -75,13 +77,6 @@ const DragControlsComponent = ({
|
|
|
75
77
|
toggleDragMenu(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex)(editorView.state, editorView.dispatch);
|
|
76
78
|
}, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex]);
|
|
77
79
|
const rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
|
|
78
|
-
const gridRowPosition = useMemo(() => {
|
|
79
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
80
|
-
if (selectedRowIndexes.includes(rowIndex)) {
|
|
81
|
-
return `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
|
|
82
|
-
}
|
|
83
|
-
return `${rowIndex + 1} / span 1`;
|
|
84
|
-
}, [rowIndex, selectedRowIndexes]);
|
|
85
80
|
const handleMouseOut = useCallback(() => {
|
|
86
81
|
if (tableActive) {
|
|
87
82
|
const {
|
|
@@ -110,6 +105,61 @@ const DragControlsComponent = ({
|
|
|
110
105
|
const handleClick = useCallback(e => {
|
|
111
106
|
selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
|
|
112
107
|
}, [rowIndex, selectRow]);
|
|
108
|
+
const generateHandleByType = type => {
|
|
109
|
+
if (!hoveredCell) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const isHover = type === 'hover';
|
|
113
|
+
const isRowsSelected = selectedRowIndexes.length > 0;
|
|
114
|
+
const showCondition = isHover ? isRowsSelected && !selectedRowIndexes.includes(rowIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : selectedRowIndexes.length < rowHeights.length && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
|
|
115
|
+
if (!showCondition) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const gridRowPosition = `${rowIndex + 1} / span 1`;
|
|
119
|
+
|
|
120
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
121
|
+
const selectedRowPosition = `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
|
|
122
|
+
const hoveredAppearance = selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
|
|
123
|
+
const currentSelectionAppearance = isRowsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
|
|
124
|
+
const isSelecting = isRowsSelected && !isHover;
|
|
125
|
+
const indexes = isRowsSelected ? isHover ? rowIndexes : selectedRowIndexes : rowIndexes;
|
|
126
|
+
return showCondition && /*#__PURE__*/React.createElement("div", {
|
|
127
|
+
key: type,
|
|
128
|
+
style: {
|
|
129
|
+
gridRow: isSelecting ? selectedRowPosition : gridRowPosition,
|
|
130
|
+
gridColumn: '2',
|
|
131
|
+
// DragHandle uses `transform: rotate(90)`, which doesn't affect its parent (this div) causing the width of this element to be the true height of the drag handle
|
|
132
|
+
width: '9px',
|
|
133
|
+
position: 'relative',
|
|
134
|
+
right: '-0.5px'
|
|
135
|
+
},
|
|
136
|
+
"data-testid": isHover ? 'table-floating-row-drag-handle-hover' : 'table-floating-row-drag-handle'
|
|
137
|
+
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
138
|
+
direction: "row",
|
|
139
|
+
tableLocalId: currentNodeLocalId,
|
|
140
|
+
indexes: indexes,
|
|
141
|
+
forceDefaultHandle: isHover ? false : isRowsSelected,
|
|
142
|
+
previewWidth: tableWidth,
|
|
143
|
+
previewHeight: rowHeights[rowIndex],
|
|
144
|
+
appearance: isSelecting ? currentSelectionAppearance : hoveredAppearance,
|
|
145
|
+
onClick: handleClick,
|
|
146
|
+
onMouseOver: handleMouseOver,
|
|
147
|
+
onMouseOut: handleMouseOut,
|
|
148
|
+
onMouseUp: onMouseUp,
|
|
149
|
+
editorView: editorView,
|
|
150
|
+
canDrag: canDrag
|
|
151
|
+
}));
|
|
152
|
+
};
|
|
153
|
+
const rowHandles = hoveredCell => {
|
|
154
|
+
if (!hoveredCell) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
if (hoveredCell.rowIndex === undefined) {
|
|
158
|
+
return generateHandleByType('selected');
|
|
159
|
+
}
|
|
160
|
+
const sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
|
|
161
|
+
return hoveredCell.rowIndex < selectedRowIndexes[0] ? sortedHandles : sortedHandles.reverse();
|
|
162
|
+
};
|
|
113
163
|
return /*#__PURE__*/React.createElement("div", {
|
|
114
164
|
className: ClassName.DRAG_ROW_CONTROLS,
|
|
115
165
|
style: {
|
|
@@ -148,28 +198,6 @@ const DragControlsComponent = ({
|
|
|
148
198
|
position: 'relative',
|
|
149
199
|
left: "var(--ds-space-negative-100, -8px)"
|
|
150
200
|
}
|
|
151
|
-
}))),
|
|
152
|
-
style: {
|
|
153
|
-
gridRow: gridRowPosition,
|
|
154
|
-
gridColumn: '2',
|
|
155
|
-
// DragHandle uses `transform: rotate(90)`, which doesn't affect its parent (this div) causing the width of this element to be the true height of the drag handle
|
|
156
|
-
width: '9px',
|
|
157
|
-
position: 'relative',
|
|
158
|
-
right: '-0.5px'
|
|
159
|
-
},
|
|
160
|
-
"data-testid": "table-floating-row-drag-handle"
|
|
161
|
-
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
162
|
-
tableLocalId: currentNodeLocalId,
|
|
163
|
-
indexes: rowIndexes,
|
|
164
|
-
previewWidth: tableWidth,
|
|
165
|
-
previewHeight: rowHeights[rowIndex],
|
|
166
|
-
appearance: selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
167
|
-
onClick: handleClick,
|
|
168
|
-
onMouseOver: handleMouseOver,
|
|
169
|
-
onMouseOut: handleMouseOut,
|
|
170
|
-
onMouseUp: onMouseUp,
|
|
171
|
-
editorView: editorView,
|
|
172
|
-
canDrag: canDrag
|
|
173
|
-
})));
|
|
201
|
+
}))), tableActive && isTableHovered && !isResizing && Number.isFinite(rowIndex) && rowHandles(hoveredCell));
|
|
174
202
|
};
|
|
175
203
|
export const DragControls = injectIntl(DragControlsComponent);
|
|
@@ -614,9 +614,10 @@ export const tableStyles = props => {
|
|
|
614
614
|
z-index: ${akEditorUnitZIndex};
|
|
615
615
|
|
|
616
616
|
.${ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER} {
|
|
617
|
-
position:
|
|
617
|
+
position: absolute;
|
|
618
618
|
align-self: end;
|
|
619
619
|
height: 100%;
|
|
620
|
+
width: 18px;
|
|
620
621
|
}
|
|
621
622
|
|
|
622
623
|
.${ClassName.DRAG_ROW_FLOATING_INSERT_DOT} {
|
|
@@ -204,7 +204,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
204
204
|
var _options$tableResizin;
|
|
205
205
|
var dispatch = _ref12.dispatch,
|
|
206
206
|
dispatchAnalyticsEvent = _ref12.dispatchAnalyticsEvent;
|
|
207
|
-
return
|
|
207
|
+
return createTableOverflowAnalyticsPlugin(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
|
|
208
208
|
}
|
|
209
209
|
}, {
|
|
210
210
|
name: 'tableAnalyticsPlugin',
|
|
@@ -386,10 +386,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
386
386
|
this.onStickyState(currentStickyState);
|
|
387
387
|
}
|
|
388
388
|
eventDispatcher.on(stickyHeadersPluginKey.key, this.onStickyState);
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
|
|
392
|
-
}
|
|
389
|
+
var initialIsOveflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
390
|
+
this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
|
|
393
391
|
}
|
|
394
392
|
}, {
|
|
395
393
|
key: "componentWillUnmount",
|
|
@@ -476,28 +474,26 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
476
474
|
}
|
|
477
475
|
this.handleTableResizingDebounced();
|
|
478
476
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}));
|
|
500
|
-
}
|
|
477
|
+
var newIsOverflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
478
|
+
var prevIsOverflowing = prevState[ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
479
|
+
if (this.initialOverflowCaptureTimerId) {
|
|
480
|
+
clearTimeout(this.initialOverflowCaptureTimerId);
|
|
481
|
+
}
|
|
482
|
+
if (!this.isInitialOverflowSent) {
|
|
483
|
+
this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
|
|
484
|
+
}
|
|
485
|
+
if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
|
|
486
|
+
var _this$state2;
|
|
487
|
+
var _this$props$view = this.props.view,
|
|
488
|
+
dispatch = _this$props$view.dispatch,
|
|
489
|
+
tr = _this$props$view.state.tr;
|
|
490
|
+
dispatch(tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
|
|
491
|
+
isOverflowing: newIsOverflowing,
|
|
492
|
+
wasOverflowing: prevIsOverflowing,
|
|
493
|
+
editorWidth: this.props.containerWidth.width || 0,
|
|
494
|
+
width: this.node.attrs.width || 0,
|
|
495
|
+
parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
|
|
496
|
+
}));
|
|
501
497
|
}
|
|
502
498
|
}
|
|
503
499
|
}, {
|
|
@@ -21,13 +21,11 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
event.preventDefault();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
dispatch(tr);
|
|
30
|
-
}
|
|
24
|
+
var tr = view.state.tr;
|
|
25
|
+
tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
26
|
+
name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED_COLUMN
|
|
27
|
+
});
|
|
28
|
+
dispatch(tr);
|
|
31
29
|
var mouseDownTime = event.timeStamp;
|
|
32
30
|
var cell = state.doc.nodeAt(localResizeHandlePos);
|
|
33
31
|
var $cell = state.doc.resolve(localResizeHandlePos);
|
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DragHandleDisabledIcon, DragHandleIcon, MinimisedHandleIcon } from '../icons';
|
|
3
3
|
export var HandleIconComponent = function HandleIconComponent(props) {
|
|
4
|
-
var
|
|
5
|
-
direction = props.direction,
|
|
6
|
-
isDragMenuOpen = props.isDragMenuOpen,
|
|
4
|
+
var forceDefaultHandle = props.forceDefaultHandle,
|
|
7
5
|
isRowHandleHovered = props.isRowHandleHovered,
|
|
8
6
|
isColumnHandleHovered = props.isColumnHandleHovered,
|
|
9
|
-
hasMergedCells = props.hasMergedCells
|
|
10
|
-
isCurrentRowSelected = props.isCurrentRowSelected,
|
|
11
|
-
isCurrentColumnSelected = props.isCurrentColumnSelected,
|
|
12
|
-
dragMenuDirection = props.dragMenuDirection;
|
|
7
|
+
hasMergedCells = props.hasMergedCells;
|
|
13
8
|
var isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var isDragPossible = canDrag && !hasMergedCells;
|
|
17
|
-
var showNormalHandle = !isDragPossible ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
|
|
18
|
-
|
|
19
|
-
// hoverred handle or open drag menu
|
|
20
|
-
if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
21
|
-
return showNormalHandle;
|
|
9
|
+
if (isHandleHovered || forceDefaultHandle) {
|
|
10
|
+
return hasMergedCells ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
|
|
22
11
|
}
|
|
23
12
|
return /*#__PURE__*/React.createElement(MinimisedHandleIcon, null);
|
|
24
13
|
};
|
|
@@ -6,7 +6,6 @@ import ReactDOM from 'react-dom';
|
|
|
6
6
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
7
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
8
8
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
9
|
-
import { getPluginState as getDragDropPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
10
9
|
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
11
10
|
import { TableCssClassName as ClassName } from '../../types';
|
|
12
11
|
import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
@@ -19,6 +18,8 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
19
18
|
_ref$appearance = _ref.appearance,
|
|
20
19
|
appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
|
|
21
20
|
indexes = _ref.indexes,
|
|
21
|
+
_ref$forceDefaultHand = _ref.forceDefaultHandle,
|
|
22
|
+
forceDefaultHandle = _ref$forceDefaultHand === void 0 ? false : _ref$forceDefaultHand,
|
|
22
23
|
previewWidth = _ref.previewWidth,
|
|
23
24
|
previewHeight = _ref.previewHeight,
|
|
24
25
|
onMouseOver = _ref.onMouseOver,
|
|
@@ -35,30 +36,18 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
35
36
|
setPreviewContainer = _useState2[1];
|
|
36
37
|
var _getPluginState = getPluginState(editorView.state),
|
|
37
38
|
hoveredColumns = _getPluginState.hoveredColumns,
|
|
38
|
-
hoveredRows = _getPluginState.hoveredRows
|
|
39
|
-
hoveredCell = _getPluginState.hoveredCell;
|
|
40
|
-
var _getDragDropPluginSta = getDragDropPluginState(editorView.state),
|
|
41
|
-
dragMenuDirection = _getDragDropPluginSta.dragMenuDirection,
|
|
42
|
-
isDragMenuOpen = _getDragDropPluginSta.isDragMenuOpen,
|
|
43
|
-
dragMenuIndex = _getDragDropPluginSta.dragMenuIndex;
|
|
39
|
+
hoveredRows = _getPluginState.hoveredRows;
|
|
44
40
|
var selection = editorView.state.selection;
|
|
45
|
-
var isCurrentRowSelected = isDragMenuOpen && direction === 'row' && hoveredCell.rowIndex === dragMenuIndex;
|
|
46
|
-
var isCurrentColumnSelected = isDragMenuOpen && direction === 'column' && hoveredCell.colIndex === dragMenuIndex;
|
|
47
41
|
var isRowHandleHovered = direction === 'row' && hoveredRows.length > 0;
|
|
48
42
|
var isColumnHandleHovered = direction === 'column' && hoveredColumns.length > 0;
|
|
49
43
|
var hasMergedCells = useMemo(function () {
|
|
50
44
|
return direction === 'row' ? hasMergedCellsInRow(indexes[0])(selection) : hasMergedCellsInColumn(indexes[0])(selection);
|
|
51
45
|
}, [indexes, direction, selection]);
|
|
52
46
|
var handleIconProps = {
|
|
53
|
-
|
|
54
|
-
hasMergedCells: hasMergedCells,
|
|
55
|
-
direction: direction,
|
|
56
|
-
isDragMenuOpen: isDragMenuOpen,
|
|
57
|
-
isRowHandleHovered: isRowHandleHovered,
|
|
47
|
+
forceDefaultHandle: forceDefaultHandle,
|
|
58
48
|
isColumnHandleHovered: isColumnHandleHovered,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
dragMenuDirection: dragMenuDirection
|
|
49
|
+
isRowHandleHovered: isRowHandleHovered,
|
|
50
|
+
hasMergedCells: hasMergedCells
|
|
62
51
|
};
|
|
63
52
|
useEffect(function () {
|
|
64
53
|
var dragHandleDivRefCurrent = dragHandleDivRef.current;
|