@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,4 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
1
2
|
import type { MouseEvent } from 'react';
|
|
2
3
|
import React, {
|
|
3
4
|
Fragment,
|
|
@@ -22,7 +23,11 @@ import { clearHoverSelection } from '../../../commands';
|
|
|
22
23
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
23
24
|
import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
|
|
24
25
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
25
|
-
import type {
|
|
26
|
+
import type {
|
|
27
|
+
CellHoverMeta,
|
|
28
|
+
DraggableSourceData,
|
|
29
|
+
HandleTypes,
|
|
30
|
+
} from '../../../types';
|
|
26
31
|
import {
|
|
27
32
|
getRowHeights,
|
|
28
33
|
getRowsParams,
|
|
@@ -116,14 +121,6 @@ const DragControlsComponent = ({
|
|
|
116
121
|
|
|
117
122
|
const rowIndex = hoveredCell?.rowIndex;
|
|
118
123
|
|
|
119
|
-
const gridRowPosition = useMemo(() => {
|
|
120
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
121
|
-
if (selectedRowIndexes.includes(rowIndex!)) {
|
|
122
|
-
return `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
|
|
123
|
-
}
|
|
124
|
-
return `${rowIndex! + 1} / span 1`;
|
|
125
|
-
}, [rowIndex, selectedRowIndexes]);
|
|
126
|
-
|
|
127
124
|
const handleMouseOut = useCallback(() => {
|
|
128
125
|
if (tableActive) {
|
|
129
126
|
const { state, dispatch } = editorView;
|
|
@@ -165,6 +162,111 @@ const DragControlsComponent = ({
|
|
|
165
162
|
[rowIndex, selectRow],
|
|
166
163
|
);
|
|
167
164
|
|
|
165
|
+
const generateHandleByType = (type: HandleTypes): JSX.Element | null => {
|
|
166
|
+
if (!hoveredCell) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const isHover = type === 'hover';
|
|
170
|
+
|
|
171
|
+
const isRowsSelected = selectedRowIndexes.length > 0;
|
|
172
|
+
|
|
173
|
+
const showCondition = isHover
|
|
174
|
+
? isRowsSelected &&
|
|
175
|
+
!selectedRowIndexes.includes(rowIndex!) &&
|
|
176
|
+
Number.isFinite(hoveredCell?.colIndex)
|
|
177
|
+
: selectedRowIndexes.length < rowHeights.length &&
|
|
178
|
+
Number.isFinite(hoveredCell?.colIndex);
|
|
179
|
+
|
|
180
|
+
if (!showCondition) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const gridRowPosition = `${rowIndex! + 1} / span 1`;
|
|
185
|
+
|
|
186
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
187
|
+
const selectedRowPosition = `${selectedRowIndexes[0] + 1} / span ${
|
|
188
|
+
selectedRowIndexes.length
|
|
189
|
+
}`;
|
|
190
|
+
|
|
191
|
+
const hoveredAppearance = selectedRowIndexes.includes(rowIndex!)
|
|
192
|
+
? isInDanger
|
|
193
|
+
? 'danger'
|
|
194
|
+
: 'selected'
|
|
195
|
+
: 'default';
|
|
196
|
+
|
|
197
|
+
const currentSelectionAppearance = isRowsSelected
|
|
198
|
+
? isInDanger
|
|
199
|
+
? 'danger'
|
|
200
|
+
: 'selected'
|
|
201
|
+
: hoveredAppearance;
|
|
202
|
+
|
|
203
|
+
const isSelecting = isRowsSelected && !isHover;
|
|
204
|
+
|
|
205
|
+
const indexes = isRowsSelected
|
|
206
|
+
? isHover
|
|
207
|
+
? rowIndexes
|
|
208
|
+
: selectedRowIndexes
|
|
209
|
+
: rowIndexes;
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
showCondition && (
|
|
213
|
+
<div
|
|
214
|
+
key={type}
|
|
215
|
+
style={{
|
|
216
|
+
gridRow: isSelecting ? selectedRowPosition : gridRowPosition,
|
|
217
|
+
gridColumn: '2',
|
|
218
|
+
// 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
|
|
219
|
+
width: '9px',
|
|
220
|
+
position: 'relative',
|
|
221
|
+
right: '-0.5px',
|
|
222
|
+
}}
|
|
223
|
+
data-testid={
|
|
224
|
+
isHover
|
|
225
|
+
? 'table-floating-row-drag-handle-hover'
|
|
226
|
+
: 'table-floating-row-drag-handle'
|
|
227
|
+
}
|
|
228
|
+
>
|
|
229
|
+
<DragHandle
|
|
230
|
+
direction="row"
|
|
231
|
+
tableLocalId={currentNodeLocalId}
|
|
232
|
+
indexes={indexes}
|
|
233
|
+
forceDefaultHandle={isHover ? false : isRowsSelected}
|
|
234
|
+
previewWidth={tableWidth}
|
|
235
|
+
previewHeight={rowHeights[rowIndex!]}
|
|
236
|
+
appearance={
|
|
237
|
+
isSelecting ? currentSelectionAppearance : hoveredAppearance
|
|
238
|
+
}
|
|
239
|
+
onClick={handleClick}
|
|
240
|
+
onMouseOver={handleMouseOver}
|
|
241
|
+
onMouseOut={handleMouseOut}
|
|
242
|
+
onMouseUp={onMouseUp}
|
|
243
|
+
editorView={editorView}
|
|
244
|
+
canDrag={canDrag}
|
|
245
|
+
/>
|
|
246
|
+
</div>
|
|
247
|
+
)
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const rowHandles = (hoveredCell: CellHoverMeta | undefined) => {
|
|
252
|
+
if (!hoveredCell) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (hoveredCell.rowIndex === undefined) {
|
|
257
|
+
return generateHandleByType('selected');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const sortedHandles = [
|
|
261
|
+
generateHandleByType('hover'),
|
|
262
|
+
generateHandleByType('selected'),
|
|
263
|
+
];
|
|
264
|
+
|
|
265
|
+
return hoveredCell.rowIndex < selectedRowIndexes[0]
|
|
266
|
+
? sortedHandles
|
|
267
|
+
: sortedHandles.reverse();
|
|
268
|
+
};
|
|
269
|
+
|
|
168
270
|
return (
|
|
169
271
|
<div
|
|
170
272
|
className={ClassName.DRAG_ROW_CONTROLS}
|
|
@@ -221,39 +323,11 @@ const DragControlsComponent = ({
|
|
|
221
323
|
)}
|
|
222
324
|
</Fragment>
|
|
223
325
|
))}
|
|
224
|
-
{
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// 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
|
|
230
|
-
width: '9px',
|
|
231
|
-
position: 'relative',
|
|
232
|
-
right: '-0.5px',
|
|
233
|
-
}}
|
|
234
|
-
data-testid="table-floating-row-drag-handle"
|
|
235
|
-
>
|
|
236
|
-
<DragHandle
|
|
237
|
-
tableLocalId={currentNodeLocalId}
|
|
238
|
-
indexes={rowIndexes}
|
|
239
|
-
previewWidth={tableWidth}
|
|
240
|
-
previewHeight={rowHeights[rowIndex!]}
|
|
241
|
-
appearance={
|
|
242
|
-
selectedRowIndexes.includes(rowIndex!)
|
|
243
|
-
? isInDanger
|
|
244
|
-
? 'danger'
|
|
245
|
-
: 'selected'
|
|
246
|
-
: 'default'
|
|
247
|
-
}
|
|
248
|
-
onClick={handleClick}
|
|
249
|
-
onMouseOver={handleMouseOver}
|
|
250
|
-
onMouseOut={handleMouseOut}
|
|
251
|
-
onMouseUp={onMouseUp}
|
|
252
|
-
editorView={editorView}
|
|
253
|
-
canDrag={canDrag}
|
|
254
|
-
/>
|
|
255
|
-
</div>
|
|
256
|
-
)}
|
|
326
|
+
{tableActive &&
|
|
327
|
+
isTableHovered &&
|
|
328
|
+
!isResizing &&
|
|
329
|
+
Number.isFinite(rowIndex) &&
|
|
330
|
+
rowHandles(hoveredCell)}
|
|
257
331
|
</div>
|
|
258
332
|
);
|
|
259
333
|
};
|