@atlaskit/editor-plugin-table 7.3.0 → 7.3.2
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/afm-cc/tsconfig.json +3 -0
- package/dist/cjs/commands/misc.js +4 -2
- package/dist/cjs/commands/selection.js +4 -2
- package/dist/cjs/pm-plugins/drag-and-drop/commands.js +3 -1
- package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +33 -1
- package/dist/cjs/pm-plugins/drag-and-drop/reducer.js +2 -1
- package/dist/cjs/pm-plugins/table-selection-keymap.js +2 -2
- package/dist/cjs/ui/DragHandle/HandleIconComponent.js +1 -3
- package/dist/cjs/ui/DragHandle/index.js +24 -10
- package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +75 -33
- package/dist/cjs/ui/FloatingDragMenu/DropdownMenu.js +123 -0
- package/dist/cjs/ui/FloatingDragMenu/index.js +2 -2
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
- package/dist/cjs/ui/TableFloatingColumnControls/index.js +1 -2
- package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
- package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
- package/dist/cjs/ui/common-styles.js +1 -1
- package/dist/cjs/ui/consts.js +3 -2
- package/dist/es2019/commands/misc.js +4 -4
- package/dist/es2019/commands/selection.js +4 -4
- package/dist/es2019/pm-plugins/drag-and-drop/commands.js +3 -3
- package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +34 -1
- package/dist/es2019/pm-plugins/drag-and-drop/reducer.js +2 -1
- package/dist/es2019/pm-plugins/table-selection-keymap.js +2 -2
- package/dist/es2019/ui/DragHandle/HandleIconComponent.js +1 -3
- package/dist/es2019/ui/DragHandle/index.js +27 -10
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +72 -32
- package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +109 -0
- package/dist/es2019/ui/FloatingDragMenu/index.js +2 -2
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
- package/dist/es2019/ui/TableFloatingColumnControls/index.js +1 -2
- package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
- package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
- package/dist/es2019/ui/common-styles.js +11 -1
- package/dist/es2019/ui/consts.js +2 -1
- package/dist/esm/commands/misc.js +4 -2
- package/dist/esm/commands/selection.js +4 -2
- package/dist/esm/pm-plugins/drag-and-drop/commands.js +3 -2
- package/dist/esm/pm-plugins/drag-and-drop/plugin.js +33 -1
- package/dist/esm/pm-plugins/drag-and-drop/reducer.js +2 -1
- package/dist/esm/pm-plugins/table-selection-keymap.js +2 -2
- package/dist/esm/ui/DragHandle/HandleIconComponent.js +1 -3
- package/dist/esm/ui/DragHandle/index.js +23 -9
- package/dist/esm/ui/FloatingDragMenu/DragMenu.js +74 -35
- package/dist/esm/ui/FloatingDragMenu/DropdownMenu.js +116 -0
- package/dist/esm/ui/FloatingDragMenu/index.js +2 -2
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +24 -35
- package/dist/esm/ui/TableFloatingColumnControls/index.js +1 -2
- package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +4 -0
- package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +26 -33
- package/dist/esm/ui/common-styles.js +1 -1
- package/dist/esm/ui/consts.js +2 -1
- package/dist/types/commands/misc.d.ts +2 -2
- package/dist/types/commands/selection.d.ts +2 -2
- package/dist/types/pm-plugins/drag-and-drop/actions.d.ts +1 -0
- package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +2 -1
- package/dist/types/pm-plugins/drag-and-drop/types.d.ts +2 -0
- package/dist/types/ui/DragHandle/HandleIconComponent.d.ts +1 -2
- package/dist/types/ui/DragHandle/index.d.ts +3 -2
- package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +7 -8
- package/dist/types/ui/FloatingDragMenu/DropdownMenu.d.ts +30 -0
- package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -2
- package/dist/types/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -1
- package/dist/types/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/commands/misc.d.ts +2 -2
- package/dist/types-ts4.5/commands/selection.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/actions.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/types.d.ts +2 -0
- package/dist/types-ts4.5/ui/DragHandle/HandleIconComponent.d.ts +1 -2
- package/dist/types-ts4.5/ui/DragHandle/index.d.ts +3 -2
- package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +7 -8
- package/dist/types-ts4.5/ui/FloatingDragMenu/DropdownMenu.d.ts +30 -0
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -2
- package/dist/types-ts4.5/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -1
- package/dist/types-ts4.5/ui/consts.d.ts +1 -0
- package/package.json +3 -2
- package/src/commands/misc.ts +17 -4
- package/src/commands/selection.ts +12 -4
- package/src/pm-plugins/drag-and-drop/actions.ts +1 -0
- package/src/pm-plugins/drag-and-drop/commands.ts +3 -0
- package/src/pm-plugins/drag-and-drop/plugin.ts +47 -0
- package/src/pm-plugins/drag-and-drop/reducer.ts +1 -0
- package/src/pm-plugins/drag-and-drop/types.ts +3 -0
- package/src/pm-plugins/table-selection-keymap.ts +2 -2
- package/src/ui/DragHandle/HandleIconComponent.tsx +2 -9
- package/src/ui/DragHandle/index.tsx +39 -16
- package/src/ui/FloatingDragMenu/DragMenu.tsx +362 -310
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +150 -0
- package/src/ui/FloatingDragMenu/index.tsx +3 -3
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +72 -91
- package/src/ui/TableFloatingColumnControls/index.tsx +1 -2
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +5 -0
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +89 -104
- package/src/ui/common-styles.ts +11 -1
- package/src/ui/consts.ts +1 -0
- package/tsconfig.app.json +3 -0
|
@@ -7,7 +7,6 @@ export interface ColumnControlsProps {
|
|
|
7
7
|
isInDanger?: boolean;
|
|
8
8
|
tableRef: HTMLTableElement;
|
|
9
9
|
hoveredCell?: CellHoverMeta;
|
|
10
|
-
isResizing?: boolean;
|
|
11
10
|
stickyTop?: number;
|
|
12
11
|
localId?: string;
|
|
13
12
|
rowHeights?: number[];
|
|
@@ -19,5 +18,5 @@ export interface ColumnControlsProps {
|
|
|
19
18
|
isDragging?: boolean;
|
|
20
19
|
getScrollOffset?: () => number;
|
|
21
20
|
}
|
|
22
|
-
export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell,
|
|
21
|
+
export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, tableContainerWidth, isNumberColumnEnabled, isDragging, getScrollOffset, }: ColumnControlsProps) => JSX.Element;
|
|
23
22
|
export default ColumnControls;
|
|
@@ -11,8 +11,8 @@ type DragControlsProps = {
|
|
|
11
11
|
tableActive?: boolean;
|
|
12
12
|
hoveredCell?: CellHoverMeta;
|
|
13
13
|
isInDanger?: boolean;
|
|
14
|
-
isResizing?: boolean;
|
|
15
14
|
isTableHovered?: boolean;
|
|
15
|
+
isResizing?: boolean;
|
|
16
16
|
hoverRows: (rows: number[], danger?: boolean) => void;
|
|
17
17
|
selectRow: (row: number, expand: boolean) => void;
|
|
18
18
|
selectRows: (rowIndexes: number[]) => void;
|
|
@@ -56,3 +56,4 @@ export declare const TABLE_GUIDELINE_VISIBLE_ADJUSTMENT = -68;
|
|
|
56
56
|
export declare const dragMenuDropdownWidth = 250;
|
|
57
57
|
export declare const dragTableInsertColumnButtonSize = 16;
|
|
58
58
|
export declare const dropTargetExtendedWidth = 150;
|
|
59
|
+
export declare const colorPalletteColumns = 7;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.2",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^35.5.1",
|
|
32
32
|
"@atlaskit/custom-steps": "^0.0.13",
|
|
33
|
-
"@atlaskit/editor-common": "^77.
|
|
33
|
+
"@atlaskit/editor-common": "^77.4.0",
|
|
34
34
|
"@atlaskit/editor-palette": "1.5.2",
|
|
35
35
|
"@atlaskit/editor-plugin-analytics": "^0.4.0",
|
|
36
36
|
"@atlaskit/editor-plugin-content-insertion": "^0.1.0",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@atlaskit/editor-shared-styles": "^2.9.0",
|
|
42
42
|
"@atlaskit/editor-tables": "^2.5.0",
|
|
43
43
|
"@atlaskit/icon": "^22.0.0",
|
|
44
|
+
"@atlaskit/menu": "^2.1.5",
|
|
44
45
|
"@atlaskit/platform-feature-flags": "^0.2.1",
|
|
45
46
|
"@atlaskit/pragmatic-drag-and-drop": "^0.25.0",
|
|
46
47
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^0.8.0",
|
package/src/commands/misc.ts
CHANGED
|
@@ -463,7 +463,11 @@ export const setMultipleCellAttrs =
|
|
|
463
463
|
return false;
|
|
464
464
|
};
|
|
465
465
|
|
|
466
|
-
export const selectColumn = (
|
|
466
|
+
export const selectColumn = (
|
|
467
|
+
column: number,
|
|
468
|
+
expand?: boolean,
|
|
469
|
+
triggeredByKeyboard = false,
|
|
470
|
+
) =>
|
|
467
471
|
createCommand(
|
|
468
472
|
(state) => {
|
|
469
473
|
const cells = getCellsInColumn(column)(state.tr.selection);
|
|
@@ -487,7 +491,9 @@ export const selectColumn = (column: number, expand?: boolean) =>
|
|
|
487
491
|
};
|
|
488
492
|
},
|
|
489
493
|
(tr: Transaction) =>
|
|
490
|
-
selectColumnTransform(column, expand)(tr)
|
|
494
|
+
selectColumnTransform(column, expand)(tr)
|
|
495
|
+
.setMeta('addToHistory', false)
|
|
496
|
+
.setMeta('selectedColumnViaKeyboard', triggeredByKeyboard),
|
|
491
497
|
);
|
|
492
498
|
|
|
493
499
|
export const selectColumns = (columnIndexes: number[]) =>
|
|
@@ -537,7 +543,11 @@ export const selectColumns = (columnIndexes: number[]) =>
|
|
|
537
543
|
},
|
|
538
544
|
);
|
|
539
545
|
|
|
540
|
-
export const selectRow = (
|
|
546
|
+
export const selectRow = (
|
|
547
|
+
row: number,
|
|
548
|
+
expand?: boolean,
|
|
549
|
+
triggeredByKeyboard = false,
|
|
550
|
+
) =>
|
|
541
551
|
createCommand(
|
|
542
552
|
(state) => {
|
|
543
553
|
let targetCellPosition;
|
|
@@ -548,7 +558,10 @@ export const selectRow = (row: number, expand?: boolean) =>
|
|
|
548
558
|
|
|
549
559
|
return { type: 'SET_TARGET_CELL_POSITION', data: { targetCellPosition } };
|
|
550
560
|
},
|
|
551
|
-
(tr) =>
|
|
561
|
+
(tr) =>
|
|
562
|
+
selectRowTransform(row, expand)(tr)
|
|
563
|
+
.setMeta('addToHistory', false)
|
|
564
|
+
.setMeta('selectedRowViaKeyboard', triggeredByKeyboard),
|
|
552
565
|
);
|
|
553
566
|
|
|
554
567
|
export const selectRows = (rowIndexes: number[]) =>
|
|
@@ -157,7 +157,7 @@ export const selectColumns =
|
|
|
157
157
|
| ExtractInjectionAPI<typeof tablePlugin>['selection']
|
|
158
158
|
| undefined,
|
|
159
159
|
) =>
|
|
160
|
-
(): Command =>
|
|
160
|
+
(triggeredByKeyboard = false): Command =>
|
|
161
161
|
(state, dispatch) => {
|
|
162
162
|
const { selection } = state;
|
|
163
163
|
const table = findTable(selection);
|
|
@@ -170,7 +170,11 @@ export const selectColumns =
|
|
|
170
170
|
})(state, dispatch);
|
|
171
171
|
}
|
|
172
172
|
if (table && rect) {
|
|
173
|
-
return selectColumn(
|
|
173
|
+
return selectColumn(
|
|
174
|
+
rect.left,
|
|
175
|
+
undefined,
|
|
176
|
+
triggeredByKeyboard,
|
|
177
|
+
)(state, dispatch);
|
|
174
178
|
}
|
|
175
179
|
return false;
|
|
176
180
|
};
|
|
@@ -181,7 +185,7 @@ export const selectRows =
|
|
|
181
185
|
| ExtractInjectionAPI<typeof tablePlugin>['selection']
|
|
182
186
|
| undefined,
|
|
183
187
|
) =>
|
|
184
|
-
(): Command =>
|
|
188
|
+
(triggeredByKeyboard = false): Command =>
|
|
185
189
|
(state, dispatch) => {
|
|
186
190
|
const { selection } = state;
|
|
187
191
|
const table = findTable(selection);
|
|
@@ -194,7 +198,11 @@ export const selectRows =
|
|
|
194
198
|
})(state, dispatch);
|
|
195
199
|
}
|
|
196
200
|
if (table && rect) {
|
|
197
|
-
return selectRow(
|
|
201
|
+
return selectRow(
|
|
202
|
+
rect.top,
|
|
203
|
+
undefined,
|
|
204
|
+
triggeredByKeyboard,
|
|
205
|
+
)(state, dispatch);
|
|
198
206
|
}
|
|
199
207
|
return false;
|
|
200
208
|
};
|
|
@@ -18,6 +18,7 @@ import { DragAndDropActionType } from './actions';
|
|
|
18
18
|
import { DropTargetType } from './consts';
|
|
19
19
|
import { createCommand, getPluginState } from './plugin-factory';
|
|
20
20
|
import { pluginKey } from './plugin-key';
|
|
21
|
+
import type { TriggerType } from './types';
|
|
21
22
|
|
|
22
23
|
// TODO: This command is a placeholder example. Please replace this if required.
|
|
23
24
|
export const getDecorations = (state: EditorState): DecorationSet => {
|
|
@@ -122,6 +123,7 @@ export const toggleDragMenu = (
|
|
|
122
123
|
isDragMenuOpen: boolean | undefined,
|
|
123
124
|
direction?: TableDirection,
|
|
124
125
|
index?: number,
|
|
126
|
+
trigger: TriggerType = 'mouse',
|
|
125
127
|
) =>
|
|
126
128
|
createCommand(
|
|
127
129
|
(state) => {
|
|
@@ -165,6 +167,7 @@ export const toggleDragMenu = (
|
|
|
165
167
|
isDragMenuOpen: updatedMenuOpenState,
|
|
166
168
|
direction: direction ?? previousDragMenuDirection,
|
|
167
169
|
index: index ?? previousDragMenuIndex,
|
|
170
|
+
isKeyboardModeActive: updatedMenuOpenState && trigger === 'keyboard',
|
|
168
171
|
},
|
|
169
172
|
};
|
|
170
173
|
},
|
|
@@ -242,6 +242,7 @@ export const createPlugin = (
|
|
|
242
242
|
isDragMenuOpen: false,
|
|
243
243
|
dragMenuIndex: 0,
|
|
244
244
|
isDragging: false,
|
|
245
|
+
isKeyboardModeActive: false,
|
|
245
246
|
})),
|
|
246
247
|
key: pluginKey,
|
|
247
248
|
appendTransaction: (transactions, oldState, newState) => {
|
|
@@ -251,6 +252,21 @@ export const createPlugin = (
|
|
|
251
252
|
getTablePluginState(newState);
|
|
252
253
|
const { isDragMenuOpen, dragMenuIndex } = getPluginState(newState);
|
|
253
254
|
|
|
255
|
+
transactions.forEach((transaction) => {
|
|
256
|
+
if (transaction.getMeta('selectedRowViaKeyboard')) {
|
|
257
|
+
const button = document.querySelector('#drag-handle-button-row');
|
|
258
|
+
if (button) {
|
|
259
|
+
(button as HTMLButtonElement).focus();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (transaction.getMeta('selectedColumnViaKeyboard')) {
|
|
263
|
+
const button = document.querySelector('#drag-handle-button-column');
|
|
264
|
+
if (button) {
|
|
265
|
+
(button as HTMLButtonElement).focus();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
|
|
254
270
|
// What's happening here? you asked... In a nutshell;
|
|
255
271
|
// If the target cell position changes while the drag menu is open then we want to close the drag menu if it has been opened.
|
|
256
272
|
// This will stop the drag menu from moving around the screen to different row/cols. Too achieve this we need
|
|
@@ -296,6 +312,37 @@ export const createPlugin = (
|
|
|
296
312
|
const { decorationSet } = getPluginState(state);
|
|
297
313
|
return decorationSet;
|
|
298
314
|
},
|
|
315
|
+
handleKeyDown: (view, event) => {
|
|
316
|
+
const isDragHandleFocused = [
|
|
317
|
+
'drag-handle-button-row',
|
|
318
|
+
'drag-handle-button-column',
|
|
319
|
+
].includes(((event.target as HTMLElement) || null)?.id);
|
|
320
|
+
const keysToTrap = ['Enter', ' '];
|
|
321
|
+
const keysToTrapWhen = [
|
|
322
|
+
'ArrowUp',
|
|
323
|
+
'ArrowDown',
|
|
324
|
+
'ArrowLeft',
|
|
325
|
+
'ArrowRight',
|
|
326
|
+
];
|
|
327
|
+
const { isDragMenuOpen } = getPluginState(view.state);
|
|
328
|
+
|
|
329
|
+
// drag handle is focused, and user presses any key return them back to editing
|
|
330
|
+
if (
|
|
331
|
+
isDragHandleFocused &&
|
|
332
|
+
!isDragMenuOpen &&
|
|
333
|
+
!keysToTrap.includes(event.key)
|
|
334
|
+
) {
|
|
335
|
+
view.dom.focus();
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (
|
|
340
|
+
(isDragHandleFocused && keysToTrap.includes(event.key)) ||
|
|
341
|
+
(isDragMenuOpen && keysToTrapWhen.includes(event.key))
|
|
342
|
+
) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
},
|
|
299
346
|
},
|
|
300
347
|
});
|
|
301
348
|
};
|
|
@@ -43,13 +43,13 @@ export function tableSelectionKeymapPlugin(
|
|
|
43
43
|
if (getBooleanFF('platform.editor.a11y.table-selection_9uv33')) {
|
|
44
44
|
bindKeymapArrayWithCommand(
|
|
45
45
|
selectColumn,
|
|
46
|
-
selectColumns(editorSelectionAPI)(),
|
|
46
|
+
selectColumns(editorSelectionAPI)(true),
|
|
47
47
|
list,
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
bindKeymapArrayWithCommand(
|
|
51
51
|
selectRow,
|
|
52
|
-
selectRows(editorSelectionAPI)(),
|
|
52
|
+
selectRows(editorSelectionAPI)(true),
|
|
53
53
|
list,
|
|
54
54
|
);
|
|
55
55
|
}
|
|
@@ -8,19 +8,12 @@ import {
|
|
|
8
8
|
|
|
9
9
|
type HandleIconProps = {
|
|
10
10
|
forceDefaultHandle: boolean;
|
|
11
|
-
|
|
12
|
-
isColumnHandleHovered: boolean;
|
|
11
|
+
isHandleHovered: boolean;
|
|
13
12
|
hasMergedCells: boolean;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
export const HandleIconComponent = (props: HandleIconProps) => {
|
|
17
|
-
const {
|
|
18
|
-
forceDefaultHandle,
|
|
19
|
-
isRowHandleHovered,
|
|
20
|
-
isColumnHandleHovered,
|
|
21
|
-
hasMergedCells,
|
|
22
|
-
} = props;
|
|
23
|
-
const isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
|
|
16
|
+
const { forceDefaultHandle, isHandleHovered, hasMergedCells } = props;
|
|
24
17
|
|
|
25
18
|
if (isHandleHovered || forceDefaultHandle) {
|
|
26
19
|
return hasMergedCells ? <DragHandleDisabledIcon /> : <DragHandleIcon />;
|
|
@@ -13,6 +13,8 @@ import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
|
13
13
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
14
14
|
import { token } from '@atlaskit/tokens';
|
|
15
15
|
|
|
16
|
+
import { getPluginState as getDnDPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
17
|
+
import type { TriggerType } from '../../pm-plugins/drag-and-drop/types';
|
|
16
18
|
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
17
19
|
import type { TableDirection } from '../../types';
|
|
18
20
|
import { TableCssClassName as ClassName } from '../../types';
|
|
@@ -22,7 +24,12 @@ import { DragPreview } from '../DragPreview';
|
|
|
22
24
|
|
|
23
25
|
import { HandleIconComponent } from './HandleIconComponent';
|
|
24
26
|
|
|
25
|
-
type DragHandleAppearance =
|
|
27
|
+
export type DragHandleAppearance =
|
|
28
|
+
| 'default'
|
|
29
|
+
| 'selected'
|
|
30
|
+
| 'disabled'
|
|
31
|
+
| 'danger'
|
|
32
|
+
| 'placeholder';
|
|
26
33
|
|
|
27
34
|
type DragHandleProps = {
|
|
28
35
|
tableLocalId: string;
|
|
@@ -35,7 +42,10 @@ type DragHandleProps = {
|
|
|
35
42
|
onClick?: MouseEventHandler;
|
|
36
43
|
onMouseOver?: MouseEventHandler;
|
|
37
44
|
onMouseOut?: MouseEventHandler;
|
|
38
|
-
|
|
45
|
+
toggleDragMenu?: (
|
|
46
|
+
trigger: TriggerType,
|
|
47
|
+
event?: React.MouseEvent<HTMLButtonElement, MouseEvent>,
|
|
48
|
+
) => void;
|
|
39
49
|
editorView: EditorView;
|
|
40
50
|
isDragMenuTarget: boolean; // this is identify which current handle component is
|
|
41
51
|
};
|
|
@@ -51,7 +61,7 @@ const DragHandleComponent = ({
|
|
|
51
61
|
previewHeight,
|
|
52
62
|
onMouseOver,
|
|
53
63
|
onMouseOut,
|
|
54
|
-
|
|
64
|
+
toggleDragMenu,
|
|
55
65
|
onClick,
|
|
56
66
|
editorView,
|
|
57
67
|
intl: { formatMessage },
|
|
@@ -60,10 +70,13 @@ const DragHandleComponent = ({
|
|
|
60
70
|
const [previewContainer, setPreviewContainer] = useState<HTMLElement | null>(
|
|
61
71
|
null,
|
|
62
72
|
);
|
|
73
|
+
const {
|
|
74
|
+
state,
|
|
75
|
+
state: { selection },
|
|
76
|
+
} = editorView;
|
|
77
|
+
const { hoveredColumns, hoveredRows } = getPluginState(state);
|
|
78
|
+
const { isDragMenuOpen } = getDnDPluginState(state);
|
|
63
79
|
|
|
64
|
-
const { hoveredColumns, hoveredRows } = getPluginState(editorView.state);
|
|
65
|
-
|
|
66
|
-
const { selection } = editorView.state;
|
|
67
80
|
const isRow = direction === 'row';
|
|
68
81
|
const isColumn = direction === 'column';
|
|
69
82
|
|
|
@@ -80,8 +93,7 @@ const DragHandleComponent = ({
|
|
|
80
93
|
|
|
81
94
|
const handleIconProps = {
|
|
82
95
|
forceDefaultHandle,
|
|
83
|
-
isColumnHandleHovered,
|
|
84
|
-
isRowHandleHovered,
|
|
96
|
+
isHandleHovered: isColumnHandleHovered || isRowHandleHovered,
|
|
85
97
|
hasMergedCells,
|
|
86
98
|
};
|
|
87
99
|
|
|
@@ -145,6 +157,7 @@ const DragHandleComponent = ({
|
|
|
145
157
|
return (
|
|
146
158
|
<>
|
|
147
159
|
<button
|
|
160
|
+
type="button"
|
|
148
161
|
className={ClassName.DRAG_HANDLE_BUTTON_CLICKABLE_ZONE}
|
|
149
162
|
data-testid="table-drag-handle-clickable-zone-button"
|
|
150
163
|
style={{
|
|
@@ -162,6 +175,7 @@ const DragHandleComponent = ({
|
|
|
162
175
|
onClick={onClick}
|
|
163
176
|
/>
|
|
164
177
|
<button
|
|
178
|
+
type="button"
|
|
165
179
|
id={isDragMenuTarget ? showDragMenuAnchorId : undefined}
|
|
166
180
|
className={classnames(
|
|
167
181
|
ClassName.DRAG_HANDLE_BUTTON_CONTAINER,
|
|
@@ -179,24 +193,33 @@ const DragHandleComponent = ({
|
|
|
179
193
|
aria-label={formatMessage(
|
|
180
194
|
isRow ? messages.rowDragHandle : messages.columnDragHandle,
|
|
181
195
|
)}
|
|
196
|
+
aria-expanded={isDragMenuOpen && isDragMenuTarget ? 'true' : 'false'}
|
|
197
|
+
aria-haspopup="menu"
|
|
182
198
|
onMouseOver={onMouseOver}
|
|
183
199
|
onMouseOut={onMouseOut}
|
|
184
200
|
onMouseUp={(e) => {
|
|
185
201
|
// return focus to editor so copying table selections whilst still works, i cannot call e.preventDefault in a mousemove event as this stops dragstart events from firing
|
|
186
202
|
// -> this is bad for a11y but is the current standard new copy/paste keyboard shortcuts should be introduced instead
|
|
187
203
|
editorView.focus();
|
|
188
|
-
|
|
204
|
+
toggleDragMenu && toggleDragMenu('mouse', e);
|
|
189
205
|
}}
|
|
190
206
|
onClick={onClick}
|
|
207
|
+
onKeyDown={(e) => {
|
|
208
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
209
|
+
toggleDragMenu && toggleDragMenu('keyboard');
|
|
210
|
+
}
|
|
211
|
+
}}
|
|
191
212
|
>
|
|
192
|
-
{
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
) : (
|
|
196
|
-
<span style={{ pointerEvents: 'none' }}>
|
|
213
|
+
{appearance !== 'placeholder' ? (
|
|
214
|
+
// cannot block pointer events in Firefox as it breaks Dragging functionality
|
|
215
|
+
browser.gecko ? (
|
|
197
216
|
<HandleIconComponent {...handleIconProps} />
|
|
198
|
-
|
|
199
|
-
|
|
217
|
+
) : (
|
|
218
|
+
<span style={{ pointerEvents: 'none' }}>
|
|
219
|
+
<HandleIconComponent {...handleIconProps} />
|
|
220
|
+
</span>
|
|
221
|
+
)
|
|
222
|
+
) : null}
|
|
200
223
|
</button>
|
|
201
224
|
{previewContainer &&
|
|
202
225
|
previewWidth !== undefined &&
|