@atlaskit/editor-plugin-table 5.4.15 → 5.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -5
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +3 -0
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +62 -33
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +62 -31
- package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -5
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +63 -33
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +61 -29
- package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -5
- package/dist/esm/plugins/table/ui/DragHandle/index.js +3 -0
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +62 -33
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +60 -29
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +1 -0
- 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 +1 -0
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/plugins/table/types.ts +2 -0
- package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +10 -9
- package/src/plugins/table/ui/DragHandle/index.tsx +4 -0
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +118 -48
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +126 -41
|
@@ -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,
|
|
@@ -20,9 +21,14 @@ import { token } from '@atlaskit/tokens';
|
|
|
20
21
|
|
|
21
22
|
import { clearHoverSelection } from '../../../commands';
|
|
22
23
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
24
|
+
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
23
25
|
import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
|
|
24
26
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
25
|
-
import type {
|
|
27
|
+
import type {
|
|
28
|
+
CellHoverMeta,
|
|
29
|
+
DraggableSourceData,
|
|
30
|
+
HandleTypes,
|
|
31
|
+
} from '../../../types';
|
|
26
32
|
import {
|
|
27
33
|
getRowHeights,
|
|
28
34
|
getRowsParams,
|
|
@@ -114,14 +120,6 @@ const DragControlsComponent = ({
|
|
|
114
120
|
|
|
115
121
|
const rowIndex = hoveredCell?.rowIndex;
|
|
116
122
|
|
|
117
|
-
const gridRowPosition = useMemo(() => {
|
|
118
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
119
|
-
if (selectedRowIndexes.includes(rowIndex!)) {
|
|
120
|
-
return `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
|
|
121
|
-
}
|
|
122
|
-
return `${rowIndex! + 1} / span 1`;
|
|
123
|
-
}, [rowIndex, selectedRowIndexes]);
|
|
124
|
-
|
|
125
123
|
const handleMouseOut = useCallback(() => {
|
|
126
124
|
if (tableActive) {
|
|
127
125
|
const { state, dispatch } = editorView;
|
|
@@ -163,6 +161,124 @@ const DragControlsComponent = ({
|
|
|
163
161
|
[rowIndex, selectRow],
|
|
164
162
|
);
|
|
165
163
|
|
|
164
|
+
const generateHandleByType = useCallback(
|
|
165
|
+
(type: HandleTypes): JSX.Element | null => {
|
|
166
|
+
if (!hoveredCell) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const { isDragMenuOpen, dragMenuIndex, dragMenuDirection } =
|
|
170
|
+
getDragDropPluginState(editorView.state);
|
|
171
|
+
const isHover = type === 'hover';
|
|
172
|
+
|
|
173
|
+
const isHoveredOnSelectedRow =
|
|
174
|
+
isDragMenuOpen &&
|
|
175
|
+
dragMenuDirection === 'row' &&
|
|
176
|
+
dragMenuIndex === rowIndex;
|
|
177
|
+
|
|
178
|
+
const showCondition = isHover
|
|
179
|
+
? !isHoveredOnSelectedRow &&
|
|
180
|
+
!selectedRowIndexes.includes(rowIndex!) &&
|
|
181
|
+
Number.isFinite(hoveredCell?.colIndex)
|
|
182
|
+
: isDragMenuOpen &&
|
|
183
|
+
dragMenuDirection === 'row' &&
|
|
184
|
+
Number.isFinite(hoveredCell?.colIndex);
|
|
185
|
+
|
|
186
|
+
if (!showCondition) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const gridRowPosition =
|
|
191
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
192
|
+
selectedRowIndexes.includes(rowIndex!)
|
|
193
|
+
? `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`
|
|
194
|
+
: `${rowIndex! + 1} / span 1`;
|
|
195
|
+
|
|
196
|
+
const selectedRowPosition = `${dragMenuIndex + 1} / span ${
|
|
197
|
+
selectedRowIndexes.length
|
|
198
|
+
}`;
|
|
199
|
+
|
|
200
|
+
const selectedApprearance = isInDanger ? 'danger' : 'selected';
|
|
201
|
+
const hoveredAppearance = selectedRowIndexes.includes(rowIndex!)
|
|
202
|
+
? isInDanger
|
|
203
|
+
? 'danger'
|
|
204
|
+
: 'selected'
|
|
205
|
+
: 'default';
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
showCondition && (
|
|
209
|
+
<div
|
|
210
|
+
key={type}
|
|
211
|
+
style={{
|
|
212
|
+
gridRow: isHover ? gridRowPosition : selectedRowPosition,
|
|
213
|
+
gridColumn: '2',
|
|
214
|
+
display: 'flex',
|
|
215
|
+
height: '100%',
|
|
216
|
+
alignItems: 'center',
|
|
217
|
+
justifyContent: 'center',
|
|
218
|
+
}}
|
|
219
|
+
data-testid={
|
|
220
|
+
isHover
|
|
221
|
+
? 'table-floating-row-drag-handle'
|
|
222
|
+
: 'table-floating-row-control-selected'
|
|
223
|
+
}
|
|
224
|
+
>
|
|
225
|
+
<DragHandle
|
|
226
|
+
direction="row"
|
|
227
|
+
tableLocalId={currentNodeLocalId}
|
|
228
|
+
indexes={isHover ? rowIndexes : selectedRowIndexes}
|
|
229
|
+
forceDefaultHandle={!isHover}
|
|
230
|
+
previewWidth={tableWidth}
|
|
231
|
+
previewHeight={rowHeights[rowIndex!]}
|
|
232
|
+
appearance={isHover ? hoveredAppearance : selectedApprearance}
|
|
233
|
+
onClick={handleClick}
|
|
234
|
+
onMouseOver={handleMouseOver}
|
|
235
|
+
onMouseOut={handleMouseOut}
|
|
236
|
+
onMouseUp={onMouseUp}
|
|
237
|
+
editorView={editorView}
|
|
238
|
+
/>
|
|
239
|
+
</div>
|
|
240
|
+
)
|
|
241
|
+
);
|
|
242
|
+
},
|
|
243
|
+
[
|
|
244
|
+
currentNodeLocalId,
|
|
245
|
+
editorView,
|
|
246
|
+
handleClick,
|
|
247
|
+
handleMouseOut,
|
|
248
|
+
handleMouseOver,
|
|
249
|
+
hoveredCell,
|
|
250
|
+
isInDanger,
|
|
251
|
+
onMouseUp,
|
|
252
|
+
rowHeights,
|
|
253
|
+
rowIndex,
|
|
254
|
+
rowIndexes,
|
|
255
|
+
selectedRowIndexes,
|
|
256
|
+
tableWidth,
|
|
257
|
+
],
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const rowHandles = useCallback(
|
|
261
|
+
(hoveredCell: CellHoverMeta | undefined) => {
|
|
262
|
+
if (!hoveredCell) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (hoveredCell.rowIndex === undefined) {
|
|
267
|
+
return generateHandleByType('selected');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const sortedHandles = [
|
|
271
|
+
generateHandleByType('hover'),
|
|
272
|
+
generateHandleByType('selected'),
|
|
273
|
+
];
|
|
274
|
+
|
|
275
|
+
return hoveredCell.rowIndex < selectedRowIndexes[0]
|
|
276
|
+
? sortedHandles
|
|
277
|
+
: sortedHandles.reverse();
|
|
278
|
+
},
|
|
279
|
+
[generateHandleByType, selectedRowIndexes],
|
|
280
|
+
);
|
|
281
|
+
|
|
166
282
|
return (
|
|
167
283
|
<div
|
|
168
284
|
className={ClassName.DRAG_ROW_CONTROLS}
|
|
@@ -219,38 +335,7 @@ const DragControlsComponent = ({
|
|
|
219
335
|
)}
|
|
220
336
|
</Fragment>
|
|
221
337
|
))}
|
|
222
|
-
{!isResizing &&
|
|
223
|
-
<div
|
|
224
|
-
style={{
|
|
225
|
-
gridRow: gridRowPosition,
|
|
226
|
-
gridColumn: '2',
|
|
227
|
-
display: 'flex',
|
|
228
|
-
height: '100%',
|
|
229
|
-
alignItems: 'center',
|
|
230
|
-
justifyContent: 'center',
|
|
231
|
-
}}
|
|
232
|
-
data-testid="table-floating-row-drag-handle"
|
|
233
|
-
>
|
|
234
|
-
<DragHandle
|
|
235
|
-
tableLocalId={currentNodeLocalId}
|
|
236
|
-
indexes={rowIndexes}
|
|
237
|
-
previewWidth={tableWidth}
|
|
238
|
-
previewHeight={rowHeights[rowIndex!]}
|
|
239
|
-
appearance={
|
|
240
|
-
selectedRowIndexes.includes(rowIndex!)
|
|
241
|
-
? isInDanger
|
|
242
|
-
? 'danger'
|
|
243
|
-
: 'selected'
|
|
244
|
-
: 'default'
|
|
245
|
-
}
|
|
246
|
-
onClick={handleClick}
|
|
247
|
-
onMouseOver={handleMouseOver}
|
|
248
|
-
onMouseOut={handleMouseOut}
|
|
249
|
-
onMouseUp={onMouseUp}
|
|
250
|
-
editorView={editorView}
|
|
251
|
-
/>
|
|
252
|
-
</div>
|
|
253
|
-
)}
|
|
338
|
+
{!isResizing && Number.isFinite(rowIndex) && rowHandles(hoveredCell)}
|
|
254
339
|
</div>
|
|
255
340
|
);
|
|
256
341
|
};
|