@atlaskit/editor-plugin-table 5.4.17 → 5.4.18
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/ui/DragHandle/HandleIconComponent.js +5 -3
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +4 -6
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +33 -62
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +31 -62
- package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +5 -3
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -3
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +33 -63
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +29 -61
- package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +5 -3
- package/dist/esm/plugins/table/ui/DragHandle/index.js +2 -4
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +33 -62
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +29 -60
- package/dist/types/plugins/table/types.d.ts +0 -1
- package/dist/types/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +0 -1
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +1 -2
- package/dist/types-ts4.5/plugins/table/types.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +1 -2
- package/package.json +1 -1
- package/src/plugins/table/types.ts +0 -2
- package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +9 -10
- package/src/plugins/table/ui/DragHandle/index.tsx +8 -6
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +48 -118
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +41 -126
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
1
|
import type { MouseEvent } from 'react';
|
|
3
2
|
import React, { useCallback, useMemo } from 'react';
|
|
4
3
|
|
|
@@ -14,8 +13,7 @@ import {
|
|
|
14
13
|
selectColumn,
|
|
15
14
|
} from '../../../commands';
|
|
16
15
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
17
|
-
import {
|
|
18
|
-
import type { CellHoverMeta, HandleTypes } from '../../../types';
|
|
16
|
+
import type { CellHoverMeta } from '../../../types';
|
|
19
17
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
20
18
|
import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
|
|
21
19
|
import { DragHandle } from '../../DragHandle';
|
|
@@ -68,6 +66,14 @@ export const ColumnControls = ({
|
|
|
68
66
|
const colIndex = hoveredCell?.colIndex;
|
|
69
67
|
const selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
70
68
|
|
|
69
|
+
const gridColumnPosition = useMemo(() => {
|
|
70
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
71
|
+
if (selectedColIndexes.includes(colIndex!)) {
|
|
72
|
+
return `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`;
|
|
73
|
+
}
|
|
74
|
+
return `${colIndex! + 1} / span 1`;
|
|
75
|
+
}, [colIndex, selectedColIndexes]);
|
|
76
|
+
|
|
71
77
|
const firstRow = tableRef.querySelector('tr');
|
|
72
78
|
const hasHeaderRow = firstRow
|
|
73
79
|
? firstRow.getAttribute('data-header-row')
|
|
@@ -134,120 +140,6 @@ export const ColumnControls = ({
|
|
|
134
140
|
|
|
135
141
|
const previewHeight = rowHeights?.reduce((sum, cur) => sum + cur, 0) ?? 0;
|
|
136
142
|
|
|
137
|
-
const generateHandleByType = useCallback(
|
|
138
|
-
(type: HandleTypes): JSX.Element | null => {
|
|
139
|
-
if (!hoveredCell) {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
const { isDragMenuOpen, dragMenuIndex, dragMenuDirection } =
|
|
143
|
-
getDragDropPluginState(editorView.state);
|
|
144
|
-
const isHover = type === 'hover';
|
|
145
|
-
|
|
146
|
-
const isHoveredOnSelectedColumn =
|
|
147
|
-
isDragMenuOpen &&
|
|
148
|
-
dragMenuDirection === 'column' &&
|
|
149
|
-
dragMenuIndex === colIndex;
|
|
150
|
-
|
|
151
|
-
const showCondition = isHover
|
|
152
|
-
? !isHoveredOnSelectedColumn && Number.isFinite(hoveredCell?.colIndex)
|
|
153
|
-
: isDragMenuOpen && dragMenuDirection === 'column';
|
|
154
|
-
|
|
155
|
-
if (!showCondition) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const selectedColumnPosition = `${dragMenuIndex + 1} / span ${
|
|
160
|
-
selectedColIndexes.length
|
|
161
|
-
}`;
|
|
162
|
-
|
|
163
|
-
const gridColumnPosition = selectedColIndexes.includes(colIndex!)
|
|
164
|
-
? `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`
|
|
165
|
-
: `${colIndex! + 1} / span 1`;
|
|
166
|
-
|
|
167
|
-
const selectedApprearance = isInDanger ? 'danger' : 'selected';
|
|
168
|
-
const hoveredAppearance = selectedColIndexes.includes(colIndex!)
|
|
169
|
-
? isInDanger
|
|
170
|
-
? 'danger'
|
|
171
|
-
: 'selected'
|
|
172
|
-
: 'default';
|
|
173
|
-
|
|
174
|
-
return (
|
|
175
|
-
showCondition && (
|
|
176
|
-
<div
|
|
177
|
-
key={type}
|
|
178
|
-
style={{
|
|
179
|
-
gridColumn: isHover ? gridColumnPosition : selectedColumnPosition,
|
|
180
|
-
display: 'flex',
|
|
181
|
-
justifyContent: 'center',
|
|
182
|
-
alignItems: 'center',
|
|
183
|
-
height: 'fit-content',
|
|
184
|
-
placeSelf: 'center',
|
|
185
|
-
zIndex: 99,
|
|
186
|
-
}}
|
|
187
|
-
data-column-control-index={hoveredCell.colIndex}
|
|
188
|
-
data-testid={
|
|
189
|
-
isHover
|
|
190
|
-
? 'table-floating-column-control'
|
|
191
|
-
: 'table-floating-column-control-selected'
|
|
192
|
-
}
|
|
193
|
-
>
|
|
194
|
-
<DragHandle
|
|
195
|
-
direction="column"
|
|
196
|
-
tableLocalId={localId || ''}
|
|
197
|
-
indexes={isHover ? colIndexes : selectedColIndexes}
|
|
198
|
-
forceDefaultHandle={!isHover}
|
|
199
|
-
previewWidth={colWidths?.[colIndex!] ?? 48}
|
|
200
|
-
previewHeight={previewHeight}
|
|
201
|
-
appearance={isHover ? hoveredAppearance : selectedApprearance}
|
|
202
|
-
onClick={handleClick}
|
|
203
|
-
onMouseOver={handleMouseOver}
|
|
204
|
-
onMouseOut={handleMouseOut}
|
|
205
|
-
onMouseUp={handleMouseUp}
|
|
206
|
-
editorView={editorView}
|
|
207
|
-
/>
|
|
208
|
-
</div>
|
|
209
|
-
)
|
|
210
|
-
);
|
|
211
|
-
},
|
|
212
|
-
[
|
|
213
|
-
colIndex,
|
|
214
|
-
previewHeight,
|
|
215
|
-
colWidths,
|
|
216
|
-
colIndexes,
|
|
217
|
-
editorView,
|
|
218
|
-
handleClick,
|
|
219
|
-
handleMouseOut,
|
|
220
|
-
handleMouseOver,
|
|
221
|
-
handleMouseUp,
|
|
222
|
-
hoveredCell,
|
|
223
|
-
isInDanger,
|
|
224
|
-
localId,
|
|
225
|
-
selectedColIndexes,
|
|
226
|
-
],
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
const columnHandles = useCallback(
|
|
230
|
-
(hoveredCell: CellHoverMeta | undefined) => {
|
|
231
|
-
if (!hoveredCell) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (hoveredCell.colIndex === undefined) {
|
|
236
|
-
return generateHandleByType('selected');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const sortedHandles = [
|
|
240
|
-
generateHandleByType('hover'),
|
|
241
|
-
generateHandleByType('selected'),
|
|
242
|
-
];
|
|
243
|
-
|
|
244
|
-
return hoveredCell.colIndex < selectedColIndexes[0]
|
|
245
|
-
? sortedHandles
|
|
246
|
-
: sortedHandles.reverse();
|
|
247
|
-
},
|
|
248
|
-
[generateHandleByType, selectedColIndexes],
|
|
249
|
-
);
|
|
250
|
-
|
|
251
143
|
return (
|
|
252
144
|
<div
|
|
253
145
|
className={ClassName.DRAG_COLUMN_CONTROLS}
|
|
@@ -289,7 +181,45 @@ export const ColumnControls = ({
|
|
|
289
181
|
/>
|
|
290
182
|
</div>
|
|
291
183
|
))}
|
|
292
|
-
{tableActive &&
|
|
184
|
+
{tableActive &&
|
|
185
|
+
!isResizing &&
|
|
186
|
+
isTableHovered &&
|
|
187
|
+
!!hoveredCell &&
|
|
188
|
+
Number.isFinite(hoveredCell.colIndex) && (
|
|
189
|
+
<div
|
|
190
|
+
style={{
|
|
191
|
+
gridColumn: gridColumnPosition,
|
|
192
|
+
display: 'flex',
|
|
193
|
+
justifyContent: 'center',
|
|
194
|
+
alignItems: 'center',
|
|
195
|
+
height: 'fit-content',
|
|
196
|
+
placeSelf: 'center',
|
|
197
|
+
zIndex: 99,
|
|
198
|
+
}}
|
|
199
|
+
data-column-control-index={hoveredCell.colIndex}
|
|
200
|
+
data-testid="table-floating-column-control"
|
|
201
|
+
>
|
|
202
|
+
<DragHandle
|
|
203
|
+
direction="column"
|
|
204
|
+
tableLocalId={localId || ''}
|
|
205
|
+
indexes={colIndexes}
|
|
206
|
+
previewWidth={colWidths?.[colIndex!] ?? 48}
|
|
207
|
+
previewHeight={previewHeight}
|
|
208
|
+
appearance={
|
|
209
|
+
selectedColIndexes.includes(hoveredCell.colIndex!)
|
|
210
|
+
? isInDanger
|
|
211
|
+
? 'danger'
|
|
212
|
+
: 'selected'
|
|
213
|
+
: 'default'
|
|
214
|
+
}
|
|
215
|
+
onClick={handleClick}
|
|
216
|
+
onMouseOver={handleMouseOver}
|
|
217
|
+
onMouseOut={handleMouseOut}
|
|
218
|
+
onMouseUp={handleMouseUp}
|
|
219
|
+
editorView={editorView}
|
|
220
|
+
/>
|
|
221
|
+
</div>
|
|
222
|
+
)}
|
|
293
223
|
</div>
|
|
294
224
|
</div>
|
|
295
225
|
);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
1
|
import type { MouseEvent } from 'react';
|
|
3
2
|
import React, {
|
|
4
3
|
Fragment,
|
|
@@ -21,14 +20,9 @@ import { token } from '@atlaskit/tokens';
|
|
|
21
20
|
|
|
22
21
|
import { clearHoverSelection } from '../../../commands';
|
|
23
22
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
24
|
-
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
25
23
|
import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
|
|
26
24
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
27
|
-
import type {
|
|
28
|
-
CellHoverMeta,
|
|
29
|
-
DraggableSourceData,
|
|
30
|
-
HandleTypes,
|
|
31
|
-
} from '../../../types';
|
|
25
|
+
import type { CellHoverMeta, DraggableSourceData } from '../../../types';
|
|
32
26
|
import {
|
|
33
27
|
getRowHeights,
|
|
34
28
|
getRowsParams,
|
|
@@ -120,6 +114,14 @@ const DragControlsComponent = ({
|
|
|
120
114
|
|
|
121
115
|
const rowIndex = hoveredCell?.rowIndex;
|
|
122
116
|
|
|
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
|
+
|
|
123
125
|
const handleMouseOut = useCallback(() => {
|
|
124
126
|
if (tableActive) {
|
|
125
127
|
const { state, dispatch } = editorView;
|
|
@@ -161,124 +163,6 @@ const DragControlsComponent = ({
|
|
|
161
163
|
[rowIndex, selectRow],
|
|
162
164
|
);
|
|
163
165
|
|
|
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
|
-
|
|
282
166
|
return (
|
|
283
167
|
<div
|
|
284
168
|
className={ClassName.DRAG_ROW_CONTROLS}
|
|
@@ -335,7 +219,38 @@ const DragControlsComponent = ({
|
|
|
335
219
|
)}
|
|
336
220
|
</Fragment>
|
|
337
221
|
))}
|
|
338
|
-
{!isResizing && Number.isFinite(rowIndex) &&
|
|
222
|
+
{!isResizing && isTableHovered && Number.isFinite(rowIndex) && (
|
|
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
|
+
)}
|
|
339
254
|
</div>
|
|
340
255
|
);
|
|
341
256
|
};
|