@atlaskit/editor-plugin-table 5.5.2 → 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 +7 -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/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/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/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
|
@@ -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);
|
|
@@ -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;
|
|
@@ -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';
|
|
@@ -18,7 +20,7 @@ var getSelectedColumns = function getSelectedColumns(selection) {
|
|
|
18
20
|
return [];
|
|
19
21
|
};
|
|
20
22
|
export var ColumnControls = function ColumnControls(_ref) {
|
|
21
|
-
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce
|
|
23
|
+
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
|
|
22
24
|
var editorView = _ref.editorView,
|
|
23
25
|
tableActive = _ref.tableActive,
|
|
24
26
|
tableRef = _ref.tableRef,
|
|
@@ -39,13 +41,6 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
39
41
|
var columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
|
|
40
42
|
var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
|
|
41
43
|
var selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
42
|
-
var gridColumnPosition = useMemo(function () {
|
|
43
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
44
|
-
if (selectedColIndexes.includes(colIndex)) {
|
|
45
|
-
return "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
|
|
46
|
-
}
|
|
47
|
-
return "".concat(colIndex + 1, " / span 1");
|
|
48
|
-
}, [colIndex, selectedColIndexes]);
|
|
49
44
|
var firstRow = tableRef.querySelector('tr');
|
|
50
45
|
var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
51
46
|
var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
@@ -97,6 +92,64 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
97
92
|
var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
|
|
98
93
|
return sum + cur;
|
|
99
94
|
}, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
|
|
95
|
+
var generateHandleByType = function generateHandleByType(type) {
|
|
96
|
+
var _colWidths;
|
|
97
|
+
if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
var isHover = type === 'hover';
|
|
101
|
+
var isColumnsSelected = selectedColIndexes.length > 0;
|
|
102
|
+
var 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);
|
|
103
|
+
if (!showCondition) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
var gridColumnPosition = "".concat(colIndex + 1, " / span 1");
|
|
107
|
+
var selectedColumnPosition = "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
|
|
108
|
+
var hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
|
|
109
|
+
var currentSelectionApprearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
|
|
110
|
+
var istSelecting = isColumnsSelected && !isHover;
|
|
111
|
+
|
|
112
|
+
// this indexes are used to calculate the drag and drop source
|
|
113
|
+
var indexes = isColumnsSelected ? isHover ? colIndexes : selectedColIndexes : colIndexes;
|
|
114
|
+
return showCondition && /*#__PURE__*/React.createElement("div", {
|
|
115
|
+
key: type,
|
|
116
|
+
style: {
|
|
117
|
+
gridColumn: istSelecting ? selectedColumnPosition : gridColumnPosition,
|
|
118
|
+
display: 'flex',
|
|
119
|
+
justifyContent: 'center',
|
|
120
|
+
alignItems: 'center',
|
|
121
|
+
height: 'fit-content',
|
|
122
|
+
placeSelf: 'center',
|
|
123
|
+
zIndex: 99
|
|
124
|
+
},
|
|
125
|
+
"data-column-control-index": hoveredCell.colIndex,
|
|
126
|
+
"data-testid": isHover ? 'table-floating-column-control-hover' : 'table-floating-column-control'
|
|
127
|
+
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
128
|
+
direction: "column",
|
|
129
|
+
tableLocalId: localId || '',
|
|
130
|
+
indexes: indexes,
|
|
131
|
+
forceDefaultHandle: isHover ? false : isColumnsSelected,
|
|
132
|
+
previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
|
|
133
|
+
previewHeight: previewHeight,
|
|
134
|
+
appearance: istSelecting ? currentSelectionApprearance : hoveredAppearance,
|
|
135
|
+
onClick: handleClick,
|
|
136
|
+
onMouseOver: handleMouseOver,
|
|
137
|
+
onMouseOut: handleMouseOut,
|
|
138
|
+
onMouseUp: handleMouseUp,
|
|
139
|
+
editorView: editorView,
|
|
140
|
+
canDrag: canDrag
|
|
141
|
+
}));
|
|
142
|
+
};
|
|
143
|
+
var columnHandles = function columnHandles(hoveredCell) {
|
|
144
|
+
if (!hoveredCell) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
if (hoveredCell.colIndex === undefined) {
|
|
148
|
+
return generateHandleByType('selected');
|
|
149
|
+
}
|
|
150
|
+
var sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
|
|
151
|
+
return hoveredCell.colIndex < selectedColIndexes[0] ? sortedHandles : sortedHandles.reverse();
|
|
152
|
+
};
|
|
100
153
|
return /*#__PURE__*/React.createElement("div", {
|
|
101
154
|
className: ClassName.DRAG_COLUMN_CONTROLS,
|
|
102
155
|
onMouseMove: handleMouseMove
|
|
@@ -125,31 +178,6 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
125
178
|
right: '0'
|
|
126
179
|
} : {}
|
|
127
180
|
}));
|
|
128
|
-
}), tableActive &&
|
|
129
|
-
style: {
|
|
130
|
-
gridColumn: gridColumnPosition,
|
|
131
|
-
display: 'flex',
|
|
132
|
-
justifyContent: 'center',
|
|
133
|
-
alignItems: 'center',
|
|
134
|
-
height: 'fit-content',
|
|
135
|
-
placeSelf: 'center',
|
|
136
|
-
zIndex: 99
|
|
137
|
-
},
|
|
138
|
-
"data-column-control-index": hoveredCell.colIndex,
|
|
139
|
-
"data-testid": "table-floating-column-control"
|
|
140
|
-
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
141
|
-
direction: "column",
|
|
142
|
-
tableLocalId: localId || '',
|
|
143
|
-
indexes: colIndexes,
|
|
144
|
-
previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
|
|
145
|
-
previewHeight: previewHeight,
|
|
146
|
-
appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
147
|
-
onClick: handleClick,
|
|
148
|
-
onMouseOver: handleMouseOver,
|
|
149
|
-
onMouseOut: handleMouseOut,
|
|
150
|
-
onMouseUp: handleMouseUp,
|
|
151
|
-
editorView: editorView,
|
|
152
|
-
canDrag: canDrag
|
|
153
|
-
}))));
|
|
181
|
+
}), tableActive && isTableHovered && !isResizing && columnHandles(hoveredCell)));
|
|
154
182
|
};
|
|
155
183
|
export default ColumnControls;
|