@atlaskit/editor-plugin-table 5.3.13 → 5.3.15
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 +16 -0
- package/dist/cjs/plugins/table/event-handlers.js +6 -3
- package/dist/cjs/plugins/table/index.js +6 -4
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +3 -7
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -0
- package/dist/cjs/plugins/table/types.js +9 -2
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +49 -11
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +10 -5
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +57 -9
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +13 -4
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +44 -5
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +6 -4
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +35 -13
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
- package/dist/cjs/plugins/table/ui/icons/AddColLeftIcon.js +44 -0
- package/dist/cjs/plugins/table/ui/icons/AddColRightIcon.js +44 -0
- package/dist/cjs/plugins/table/ui/icons/AddRowAboveIcon.js +45 -0
- package/dist/cjs/plugins/table/ui/icons/AddRowBelowIcon.js +40 -0
- package/dist/cjs/plugins/table/ui/icons/index.js +29 -1
- package/dist/cjs/plugins/table/ui/ui-styles.js +27 -24
- package/dist/cjs/plugins/table/utils/dom.js +12 -4
- package/dist/cjs/plugins/table/utils/drag-menu.js +122 -10
- package/dist/cjs/plugins/table/utils/index.js +12 -0
- package/dist/es2019/plugins/table/event-handlers.js +5 -4
- package/dist/es2019/plugins/table/index.js +6 -4
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +3 -7
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +12 -0
- package/dist/es2019/plugins/table/types.js +9 -2
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +52 -8
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +10 -5
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +58 -7
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +10 -4
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +46 -6
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +35 -14
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/es2019/plugins/table/ui/common-styles.js +51 -3
- package/dist/es2019/plugins/table/ui/icons/AddColLeftIcon.js +35 -0
- package/dist/es2019/plugins/table/ui/icons/AddColRightIcon.js +35 -0
- package/dist/es2019/plugins/table/ui/icons/AddRowAboveIcon.js +36 -0
- package/dist/es2019/plugins/table/ui/icons/AddRowBelowIcon.js +31 -0
- package/dist/es2019/plugins/table/ui/icons/index.js +5 -1
- package/dist/es2019/plugins/table/ui/ui-styles.js +23 -1
- package/dist/es2019/plugins/table/utils/dom.js +5 -1
- package/dist/es2019/plugins/table/utils/drag-menu.js +118 -8
- package/dist/es2019/plugins/table/utils/index.js +1 -1
- package/dist/esm/plugins/table/event-handlers.js +7 -4
- package/dist/esm/plugins/table/index.js +6 -4
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +3 -7
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -0
- package/dist/esm/plugins/table/types.js +9 -2
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +46 -8
- package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +10 -5
- package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +56 -8
- package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
- package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +10 -4
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +45 -6
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +36 -14
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/esm/plugins/table/ui/common-styles.js +2 -2
- package/dist/esm/plugins/table/ui/icons/AddColLeftIcon.js +37 -0
- package/dist/esm/plugins/table/ui/icons/AddColRightIcon.js +37 -0
- package/dist/esm/plugins/table/ui/icons/AddRowAboveIcon.js +38 -0
- package/dist/esm/plugins/table/ui/icons/AddRowBelowIcon.js +33 -0
- package/dist/esm/plugins/table/ui/icons/index.js +5 -1
- package/dist/esm/plugins/table/ui/ui-styles.js +26 -23
- package/dist/esm/plugins/table/utils/dom.js +11 -3
- package/dist/esm/plugins/table/utils/drag-menu.js +120 -8
- package/dist/esm/plugins/table/utils/index.js +1 -1
- package/dist/types/plugins/table/types.d.ts +9 -2
- package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +5 -2
- package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +5 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/index.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/AddColLeftIcon.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/AddColRightIcon.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/AddRowAboveIcon.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/AddRowBelowIcon.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/index.d.ts +4 -0
- package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
- package/dist/types/plugins/table/utils/dom.d.ts +4 -1
- package/dist/types/plugins/table/utils/drag-menu.d.ts +6 -3
- package/dist/types/plugins/table/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +9 -2
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +5 -2
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/AddColLeftIcon.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/AddColRightIcon.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/AddRowAboveIcon.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/AddRowBelowIcon.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +4 -0
- package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +4 -1
- package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +6 -3
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
- package/package.json +2 -1
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +40 -194
- package/src/__tests__/unit/ui/RowDragControls.tsx +9 -11
- package/src/plugins/table/event-handlers.ts +15 -3
- package/src/plugins/table/index.tsx +4 -2
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +2 -9
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -3
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +9 -0
- package/src/plugins/table/types.ts +12 -2
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +73 -6
- package/src/plugins/table/ui/FloatingDragMenu/index.tsx +15 -3
- package/src/plugins/table/ui/FloatingInsertButton/InsertButton.tsx +82 -8
- package/src/plugins/table/ui/FloatingInsertButton/getPopupOptions.ts +28 -5
- package/src/plugins/table/ui/FloatingInsertButton/index.tsx +19 -7
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +47 -3
- package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +11 -4
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +49 -18
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -0
- package/src/plugins/table/ui/common-styles.ts +57 -2
- package/src/plugins/table/ui/icons/AddColLeftIcon.tsx +43 -0
- package/src/plugins/table/ui/icons/AddColRightIcon.tsx +43 -0
- package/src/plugins/table/ui/icons/AddRowAboveIcon.tsx +42 -0
- package/src/plugins/table/ui/icons/AddRowBelowIcon.tsx +36 -0
- package/src/plugins/table/ui/icons/index.ts +4 -0
- package/src/plugins/table/ui/ui-styles.ts +27 -1
- package/src/plugins/table/utils/dom.ts +11 -4
- package/src/plugins/table/utils/drag-menu.ts +158 -5
- package/src/plugins/table/utils/index.ts +2 -0
- package/tsconfig.app.json +3 -0
|
@@ -68,6 +68,9 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
|
|
|
68
68
|
CONTROLS_INSERT_LINE: "".concat(tablePrefixSelector, "-controls__insert-line"),
|
|
69
69
|
CONTROLS_BUTTON_OVERLAY: "".concat(tablePrefixSelector, "-controls__button-overlay"),
|
|
70
70
|
LAYOUT_BUTTON: "".concat(tablePrefixSelector, "-layout-button"),
|
|
71
|
+
DRAG_CONTROLS_INSERT_BUTTON: "".concat(tablePrefixSelector, "-controls__drag-insert-button"),
|
|
72
|
+
DRAG_CONTROLS_INSERT_BUTTON_INNER: "".concat(tablePrefixSelector, "-controls__drag-insert-button-inner"),
|
|
73
|
+
DRAG_CONTROLS_INSERT_BUTTON_WRAP: "".concat(tablePrefixSelector, "-controls__drag-insert-button-wrap"),
|
|
71
74
|
CONTROLS_INSERT_MARKER: "".concat(tablePrefixSelector, "-controls__insert-marker"),
|
|
72
75
|
CONTROLS_INSERT_COLUMN: "".concat(tablePrefixSelector, "-controls__insert-column"),
|
|
73
76
|
CONTROLS_INSERT_ROW: "".concat(tablePrefixSelector, "-controls__insert-row"),
|
|
@@ -80,8 +83,12 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
|
|
|
80
83
|
CORNER_CONTROLS_INSERT_COLUMN_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-column-marker"),
|
|
81
84
|
CONTROLS_CORNER_BUTTON: "".concat(tablePrefixSelector, "-corner-button"),
|
|
82
85
|
/** Controls with drag handle */
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
DRAG_ROW_CONTROLS: "".concat(tablePrefixSelector, "-drag-row-controls"),
|
|
87
|
+
DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: "".concat(tablePrefixSelector, "-drag-row-floating-insert-dot-wrapper"),
|
|
88
|
+
DRAG_ROW_FLOATING_INSERT_DOT: "".concat(tablePrefixSelector, "-drag-row-floating-insert-dot"),
|
|
89
|
+
DRAG_COLUMN_CONTROLS: "".concat(tablePrefixSelector, "-drag-column-controls"),
|
|
90
|
+
DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER: "".concat(tablePrefixSelector, "-drag-columns-floating-insert-dot-wrapper"),
|
|
91
|
+
DRAG_COLUMN_FLOATING_INSERT_DOT: "".concat(tablePrefixSelector, "-drag-columns-floating-insert-dot"),
|
|
85
92
|
DRAG_HANDLE_BUTTON_CONTAINER: "".concat(tablePrefixSelector, "-drag-handle-button-container"),
|
|
86
93
|
/** Other classes */
|
|
87
94
|
NUMBERED_COLUMN: "".concat(tablePrefixSelector, "-numbered-column"),
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react';
|
|
2
3
|
import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
3
5
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
|
+
import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@atlaskit/editor-tables/utils';
|
|
7
|
+
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
4
8
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
9
|
+
import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
|
|
5
10
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
6
11
|
import { dragMenuDropdownWidth } from '../consts';
|
|
7
12
|
var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig) {
|
|
@@ -14,7 +19,18 @@ var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig) {
|
|
|
14
19
|
value: {
|
|
15
20
|
name: item.id
|
|
16
21
|
},
|
|
17
|
-
isDisabled: item.disabled
|
|
22
|
+
isDisabled: item.disabled,
|
|
23
|
+
elemBefore: item.icon ? jsx("div", {
|
|
24
|
+
style: {
|
|
25
|
+
marginRight: "var(--ds-space-negative-075, -6px)",
|
|
26
|
+
display: 'flex'
|
|
27
|
+
}
|
|
28
|
+
}, jsx(item.icon, {
|
|
29
|
+
label: item.title
|
|
30
|
+
})) : undefined,
|
|
31
|
+
elemAfter: item.keymap ? jsx("div", {
|
|
32
|
+
css: shortcutStyle
|
|
33
|
+
}, item.keymap) : undefined
|
|
18
34
|
});
|
|
19
35
|
item.onClick && (menuCallback[item.id] = item.onClick);
|
|
20
36
|
});
|
|
@@ -32,9 +48,15 @@ export var DragMenu = function DragMenu(_ref) {
|
|
|
32
48
|
tableNode = _ref.tableNode,
|
|
33
49
|
mountPoint = _ref.mountPoint,
|
|
34
50
|
boundariesElement = _ref.boundariesElement,
|
|
35
|
-
scrollableElement = _ref.scrollableElement
|
|
51
|
+
scrollableElement = _ref.scrollableElement,
|
|
52
|
+
targetCellPosition = _ref.targetCellPosition,
|
|
53
|
+
getEditorContainerWidth = _ref.getEditorContainerWidth;
|
|
36
54
|
var tableMap = tableNode ? TableMap.get(tableNode) : undefined;
|
|
37
|
-
var
|
|
55
|
+
var state = editorView.state,
|
|
56
|
+
dispatch = editorView.dispatch;
|
|
57
|
+
var selection = state.selection;
|
|
58
|
+
var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
59
|
+
var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect);
|
|
38
60
|
var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
|
|
39
61
|
menuItems = _convertToDropdownIte.menuItems,
|
|
40
62
|
menuCallback = _convertToDropdownIte.menuCallback;
|
|
@@ -43,16 +65,30 @@ export var DragMenu = function DragMenu(_ref) {
|
|
|
43
65
|
dispatch = editorView.dispatch;
|
|
44
66
|
toggleDragMenu(false)(state, dispatch);
|
|
45
67
|
};
|
|
46
|
-
var
|
|
68
|
+
var handleMenuItemActivated = function handleMenuItemActivated(_ref2) {
|
|
47
69
|
var _menuCallback$item$va;
|
|
48
70
|
var item = _ref2.item;
|
|
49
|
-
(_menuCallback$item$va = menuCallback[item.value.name]) === null || _menuCallback$item$va === void 0 || _menuCallback$item$va.call(menuCallback,
|
|
71
|
+
(_menuCallback$item$va = menuCallback[item.value.name]) === null || _menuCallback$item$va === void 0 || _menuCallback$item$va.call(menuCallback, state, dispatch);
|
|
50
72
|
closeMenu();
|
|
51
73
|
};
|
|
74
|
+
var handleItemMouseEnter = function handleItemMouseEnter(_ref3) {
|
|
75
|
+
var _item$value$name;
|
|
76
|
+
var item = _ref3.item;
|
|
77
|
+
if (!selectionRect || !((_item$value$name = item.value.name) !== null && _item$value$name !== void 0 && _item$value$name.startsWith('delete'))) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
(item.value.name === 'delete_column' ? hoverColumns(getSelectedColumnIndexes(selectionRect), true) : hoverRows(getSelectedRowIndexes(selectionRect), true))(state, dispatch);
|
|
81
|
+
};
|
|
82
|
+
var handleItemMouseLeave = function handleItemMouseLeave(_ref4) {
|
|
83
|
+
var item = _ref4.item;
|
|
84
|
+
if (['sort_column_asc', 'sort_column_desc', 'delete_column', 'delete_row'].indexOf(item.value.name) > -1) {
|
|
85
|
+
clearHoverSelection()(state, dispatch);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
52
88
|
if (!menuItems) {
|
|
53
89
|
return null;
|
|
54
90
|
}
|
|
55
|
-
return
|
|
91
|
+
return jsx(DropdownMenu, {
|
|
56
92
|
mountTo: mountPoint
|
|
57
93
|
//This needs be removed when the a11y is completely handled
|
|
58
94
|
//Disabling key navigation now as it works only partially
|
|
@@ -66,7 +102,9 @@ export var DragMenu = function DragMenu(_ref) {
|
|
|
66
102
|
}],
|
|
67
103
|
isOpen: isOpen,
|
|
68
104
|
onOpenChange: closeMenu,
|
|
69
|
-
onItemActivated:
|
|
105
|
+
onItemActivated: handleMenuItemActivated,
|
|
106
|
+
onMouseEnter: handleItemMouseEnter,
|
|
107
|
+
onMouseLeave: handleItemMouseLeave,
|
|
70
108
|
fitWidth: dragMenuDropdownWidth,
|
|
71
109
|
boundariesElement: boundariesElement
|
|
72
110
|
});
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
3
3
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
4
4
|
import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
5
|
+
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
6
|
import { dragMenuDropdownWidth } from '../consts';
|
|
6
7
|
import { DragMenu } from './DragMenu';
|
|
7
8
|
var FloatingDragMenu = function FloatingDragMenu(_ref) {
|
|
@@ -14,7 +15,8 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
|
|
|
14
15
|
tableNode = _ref.tableNode,
|
|
15
16
|
direction = _ref.direction,
|
|
16
17
|
index = _ref.index,
|
|
17
|
-
targetCellPosition = _ref.targetCellPosition
|
|
18
|
+
targetCellPosition = _ref.targetCellPosition,
|
|
19
|
+
getEditorContainerWidth = _ref.getEditorContainerWidth;
|
|
18
20
|
if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
|
|
19
21
|
return null;
|
|
20
22
|
}
|
|
@@ -23,10 +25,11 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
|
|
|
23
25
|
if (!targetCellRef) {
|
|
24
26
|
return null;
|
|
25
27
|
}
|
|
26
|
-
|
|
28
|
+
var tableMap = tableNode ? TableMap.get(tableNode) : undefined;
|
|
29
|
+
var offset = direction === 'row' ? [7, 0] : index === ((tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) || 1) - 1 ? [14, 0] : [-14, 0];
|
|
27
30
|
// TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
|
|
28
31
|
return /*#__PURE__*/React.createElement(Popup, {
|
|
29
|
-
alignX:
|
|
32
|
+
alignX: direction === 'row' ? 'left' : 'center',
|
|
30
33
|
alignY: "top",
|
|
31
34
|
target: targetCellRef,
|
|
32
35
|
mountTo: mountPoint,
|
|
@@ -38,7 +41,7 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
|
|
|
38
41
|
,
|
|
39
42
|
zIndex: akEditorFloatingOverlapPanelZIndex,
|
|
40
43
|
forcePlacement: true,
|
|
41
|
-
offset:
|
|
44
|
+
offset: offset,
|
|
42
45
|
stick: true
|
|
43
46
|
}, /*#__PURE__*/React.createElement(DragMenu, {
|
|
44
47
|
editorView: editorView,
|
|
@@ -46,7 +49,9 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
|
|
|
46
49
|
boundariesElement: boundariesElement,
|
|
47
50
|
tableNode: tableNode,
|
|
48
51
|
direction: direction,
|
|
49
|
-
index: index
|
|
52
|
+
index: index,
|
|
53
|
+
targetCellPosition: targetCellPosition,
|
|
54
|
+
getEditorContainerWidth: getEditorContainerWidth
|
|
50
55
|
}));
|
|
51
56
|
};
|
|
52
57
|
FloatingDragMenu.displayName = 'FloatingDragMenu';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
2
|
+
|
|
1
3
|
import React from 'react';
|
|
2
4
|
import { injectIntl } from 'react-intl-next';
|
|
3
5
|
import { addColumnAfter, addRowAfter, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
@@ -23,7 +25,7 @@ var getToolbarSize = function getToolbarSize(tableRef) {
|
|
|
23
25
|
}
|
|
24
26
|
return tableToolbarSize;
|
|
25
27
|
};
|
|
26
|
-
var getInsertLineWidth = function getInsertLineWidth(tableRef) {
|
|
28
|
+
var getInsertLineWidth = function getInsertLineWidth(tableRef, isDragAndDropEnabled) {
|
|
27
29
|
// The line gets width 100% from the table,
|
|
28
30
|
// but since we have an overflow on the left,
|
|
29
31
|
// we should add an offset to make up for it.
|
|
@@ -34,22 +36,68 @@ var getInsertLineWidth = function getInsertLineWidth(tableRef) {
|
|
|
34
36
|
var _ref = parentElement,
|
|
35
37
|
scrollLeft = _ref.scrollLeft;
|
|
36
38
|
var diff = offsetWidth - parentOffsetWidth;
|
|
37
|
-
var toolbarSize = getToolbarSize(tableRef);
|
|
39
|
+
var toolbarSize = isDragAndDropEnabled ? 0 : getToolbarSize(tableRef);
|
|
38
40
|
return Math.min(offsetWidth + toolbarSize, parentOffsetWidth + toolbarSize - Math.max(scrollLeft - diff, 0)) + LINE_OFFSET;
|
|
39
41
|
};
|
|
40
42
|
var tooltipMessageByType = function tooltipMessageByType(type) {
|
|
41
43
|
return type === 'row' ? tableMessages.insertRow : tableMessages.insertColumn;
|
|
42
44
|
};
|
|
43
|
-
var
|
|
45
|
+
export var InsertButtonForDragAndDrop = function InsertButtonForDragAndDrop(_ref2) {
|
|
44
46
|
var onMouseDown = _ref2.onMouseDown,
|
|
45
47
|
tableRef = _ref2.tableRef,
|
|
46
|
-
|
|
48
|
+
type = _ref2.type,
|
|
47
49
|
formatMessage = _ref2.intl.formatMessage,
|
|
48
50
|
hasStickyHeaders = _ref2.hasStickyHeaders;
|
|
49
51
|
var content = /*#__PURE__*/React.createElement(Tooltip, {
|
|
50
52
|
content: /*#__PURE__*/React.createElement(ToolTipContent, {
|
|
51
|
-
description: formatMessage(tooltipMessageByType(
|
|
52
|
-
keymap:
|
|
53
|
+
description: formatMessage(tooltipMessageByType(type)),
|
|
54
|
+
keymap: type === 'row' ? addRowAfter : addColumnAfter
|
|
55
|
+
}),
|
|
56
|
+
position: "top"
|
|
57
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
58
|
+
className: ClassName.DRAG_CONTROLS_INSERT_BUTTON_INNER
|
|
59
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
60
|
+
type: "button",
|
|
61
|
+
className: ClassName.DRAG_CONTROLS_INSERT_BUTTON,
|
|
62
|
+
onMouseDown: onMouseDown
|
|
63
|
+
}, /*#__PURE__*/React.createElement("svg", {
|
|
64
|
+
width: "10",
|
|
65
|
+
height: "10",
|
|
66
|
+
viewBox: "0 0 10 10",
|
|
67
|
+
fill: "none",
|
|
68
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
69
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
70
|
+
fillRule: "evenodd",
|
|
71
|
+
clipRule: "evenodd",
|
|
72
|
+
d: "M5.41667 4.58333V2.91667C5.41667 2.80616 5.37277 2.70018 5.29463 2.62204C5.21649 2.5439 5.11051 2.5 5 2.5C4.88949 2.5 4.78351 2.5439 4.70537 2.62204C4.62723 2.70018 4.58333 2.80616 4.58333 2.91667V4.58333H2.91667C2.80616 4.58333 2.70018 4.62723 2.62204 4.70537C2.5439 4.78351 2.5 4.88949 2.5 5C2.5 5.11051 2.5439 5.21649 2.62204 5.29463C2.70018 5.37277 2.80616 5.41667 2.91667 5.41667H4.58333V7.08333C4.58333 7.19384 4.62723 7.29982 4.70537 7.37796C4.78351 7.4561 4.88949 7.5 5 7.5C5.11051 7.5 5.21649 7.4561 5.29463 7.37796C5.37277 7.29982 5.41667 7.19384 5.41667 7.08333V5.41667H7.08333C7.19384 5.41667 7.29982 5.37277 7.37796 5.29463C7.4561 5.21649 7.5 5.11051 7.5 5C7.5 4.88949 7.4561 4.78351 7.37796 4.70537C7.29982 4.62723 7.19384 4.58333 7.08333 4.58333H5.41667Z",
|
|
73
|
+
fill: "currentColor"
|
|
74
|
+
})))), /*#__PURE__*/React.createElement("div", {
|
|
75
|
+
className: ClassName.CONTROLS_INSERT_LINE,
|
|
76
|
+
style: type === 'row' ? {
|
|
77
|
+
width: getInsertLineWidth(tableRef, true),
|
|
78
|
+
left: '14px'
|
|
79
|
+
} : {
|
|
80
|
+
height: getInsertLineHeight(tableRef, hasStickyHeaders) - 11
|
|
81
|
+
}
|
|
82
|
+
})));
|
|
83
|
+
var floatingButtonClassName = type === 'column' ? ClassName.CONTROLS_FLOATING_BUTTON_COLUMN : ClassName.CONTROLS_FLOATING_BUTTON_ROW;
|
|
84
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
85
|
+
className: floatingButtonClassName
|
|
86
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
87
|
+
className: "".concat(ClassName.CONTROLS_INSERT_BUTTON_WRAP, " ").concat(ClassName.CONTROLS_INSERT_ROW)
|
|
88
|
+
}, content));
|
|
89
|
+
};
|
|
90
|
+
export var DragAndDropInsertButton = injectIntl(InsertButtonForDragAndDrop);
|
|
91
|
+
var InsertButton = function InsertButton(_ref3) {
|
|
92
|
+
var onMouseDown = _ref3.onMouseDown,
|
|
93
|
+
tableRef = _ref3.tableRef,
|
|
94
|
+
type = _ref3.type,
|
|
95
|
+
formatMessage = _ref3.intl.formatMessage,
|
|
96
|
+
hasStickyHeaders = _ref3.hasStickyHeaders;
|
|
97
|
+
var content = /*#__PURE__*/React.createElement(Tooltip, {
|
|
98
|
+
content: /*#__PURE__*/React.createElement(ToolTipContent, {
|
|
99
|
+
description: formatMessage(tooltipMessageByType(type)),
|
|
100
|
+
keymap: type === 'row' ? addRowAfter : addColumnAfter
|
|
53
101
|
}),
|
|
54
102
|
position: "top"
|
|
55
103
|
}, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
@@ -66,13 +114,13 @@ var InsertButton = function InsertButton(_ref2) {
|
|
|
66
114
|
fillRule: "evenodd"
|
|
67
115
|
})))), /*#__PURE__*/React.createElement("div", {
|
|
68
116
|
className: ClassName.CONTROLS_INSERT_LINE,
|
|
69
|
-
style:
|
|
117
|
+
style: type === 'row' ? {
|
|
70
118
|
width: getInsertLineWidth(tableRef)
|
|
71
119
|
} : {
|
|
72
120
|
height: getInsertLineHeight(tableRef, hasStickyHeaders)
|
|
73
121
|
}
|
|
74
122
|
})));
|
|
75
|
-
var floatingButtonClassName =
|
|
123
|
+
var floatingButtonClassName = type === 'column' ? ClassName.CONTROLS_FLOATING_BUTTON_COLUMN : ClassName.CONTROLS_FLOATING_BUTTON_ROW;
|
|
76
124
|
return /*#__PURE__*/React.createElement("div", {
|
|
77
125
|
className: floatingButtonClassName
|
|
78
126
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -6,9 +6,11 @@ import { tableInsertColumnButtonOffset, tableInsertColumnButtonSize, tableToolba
|
|
|
6
6
|
var HORIZONTAL_ALIGN_COLUMN_BUTTON = -(tableInsertColumnButtonSize / 2);
|
|
7
7
|
var HORIZONTAL_ALIGN_NUMBERED_COLUMN_BUTTON = HORIZONTAL_ALIGN_COLUMN_BUTTON + akEditorTableNumberColumnWidth;
|
|
8
8
|
var VERTICAL_ALIGN_COLUMN_BUTTON = tableToolbarSize + tableInsertColumnButtonOffset;
|
|
9
|
+
var VERTICAL_ALIGN_COLUMN_BUTTON_DRAG = tableInsertColumnButtonOffset;
|
|
9
10
|
var HORIZONTAL_ALIGN_ROW_BUTTON = -(tableToolbarSize + tableInsertColumnButtonOffset + tableInsertColumnButtonSize);
|
|
11
|
+
var HORIZONTAL_ALIGN_ROW_BUTTON_DRAG = -18;
|
|
10
12
|
var VERTICAL_ALIGN_ROW_BUTTON = tableInsertColumnButtonSize / 2;
|
|
11
|
-
function getRowOptions(index) {
|
|
13
|
+
function getRowOptions(index, isDragAndDropEnabled) {
|
|
12
14
|
var defaultOptions = {
|
|
13
15
|
alignX: 'left',
|
|
14
16
|
alignY: 'bottom',
|
|
@@ -25,16 +27,16 @@ function getRowOptions(index) {
|
|
|
25
27
|
onPositionCalculated: function onPositionCalculated(position) {
|
|
26
28
|
return _objectSpread(_objectSpread({}, position), {}, {
|
|
27
29
|
// Left position should be always the offset (To place in the correct position even if the table has overflow).
|
|
28
|
-
left: HORIZONTAL_ALIGN_ROW_BUTTON
|
|
30
|
+
left: isDragAndDropEnabled ? HORIZONTAL_ALIGN_ROW_BUTTON_DRAG : HORIZONTAL_ALIGN_ROW_BUTTON
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
|
-
function getColumnOptions(index, tableContainer, hasNumberedColumns) {
|
|
35
|
+
function getColumnOptions(index, tableContainer, hasNumberedColumns, isDragAndDropEnabled) {
|
|
34
36
|
var options = {
|
|
35
37
|
alignX: 'end',
|
|
36
38
|
alignY: 'top',
|
|
37
|
-
offset: [HORIZONTAL_ALIGN_COLUMN_BUTTON, VERTICAL_ALIGN_COLUMN_BUTTON],
|
|
39
|
+
offset: [HORIZONTAL_ALIGN_COLUMN_BUTTON, isDragAndDropEnabled ? VERTICAL_ALIGN_COLUMN_BUTTON_DRAG : VERTICAL_ALIGN_COLUMN_BUTTON],
|
|
38
40
|
// :: (position: PopupPosition) -> PopupPosition
|
|
39
41
|
// Limit the InsertButton position to the table container
|
|
40
42
|
// if the left position starts before it
|
|
@@ -70,12 +72,12 @@ function getColumnOptions(index, tableContainer, hasNumberedColumns) {
|
|
|
70
72
|
}
|
|
71
73
|
return options;
|
|
72
74
|
}
|
|
73
|
-
function getPopupOptions(direction, index, hasNumberedColumns, tableContainer) {
|
|
75
|
+
function getPopupOptions(direction, index, hasNumberedColumns, isDragAndDropEnabled, tableContainer) {
|
|
74
76
|
switch (direction) {
|
|
75
77
|
case 'column':
|
|
76
|
-
return getColumnOptions(index, tableContainer, hasNumberedColumns);
|
|
78
|
+
return getColumnOptions(index, tableContainer, hasNumberedColumns, isDragAndDropEnabled);
|
|
77
79
|
case 'row':
|
|
78
|
-
return getRowOptions(index);
|
|
80
|
+
return getRowOptions(index, isDragAndDropEnabled);
|
|
79
81
|
default:
|
|
80
82
|
return {};
|
|
81
83
|
}
|
|
@@ -22,7 +22,7 @@ import { insertColumnWithAnalytics, insertRowWithAnalytics } from '../../command
|
|
|
22
22
|
import { TableCssClassName as ClassName } from '../../types';
|
|
23
23
|
import { checkIfNumberColumnEnabled } from '../../utils';
|
|
24
24
|
import getPopupOptions from './getPopupOptions';
|
|
25
|
-
import InsertButton from './InsertButton';
|
|
25
|
+
import InsertButton, { DragAndDropInsertButton } from './InsertButton';
|
|
26
26
|
export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
|
|
27
27
|
_inherits(FloatingInsertButton, _React$Component);
|
|
28
28
|
var _super = _createSuper(FloatingInsertButton);
|
|
@@ -47,6 +47,7 @@ export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
|
|
|
47
47
|
boundariesElement = _this$props.boundariesElement,
|
|
48
48
|
isHeaderColumnEnabled = _this$props.isHeaderColumnEnabled,
|
|
49
49
|
isHeaderRowEnabled = _this$props.isHeaderRowEnabled,
|
|
50
|
+
isDragAndDropEnabled = _this$props.isDragAndDropEnabled,
|
|
50
51
|
dispatchAnalyticsEvent = _this$props.dispatchAnalyticsEvent;
|
|
51
52
|
var type = typeof insertColumnButtonIndex !== 'undefined' ? 'column' : typeof insertRowButtonIndex !== 'undefined' ? 'row' : null;
|
|
52
53
|
if (!tableNode || !tableRef || !type) {
|
|
@@ -121,10 +122,15 @@ export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
|
|
|
121
122
|
scrollableElement: tableWrapper,
|
|
122
123
|
forcePlacement: true,
|
|
123
124
|
allowOutOfBounds: true
|
|
124
|
-
}, getPopupOptions(type, index, hasNumberedColumns, tableContainerWrapper), {
|
|
125
|
+
}, getPopupOptions(type, index, hasNumberedColumns, !!isDragAndDropEnabled, tableContainerWrapper), {
|
|
125
126
|
zIndex: zIndex
|
|
126
|
-
}), /*#__PURE__*/React.createElement(
|
|
127
|
-
|
|
127
|
+
}), isDragAndDropEnabled ? /*#__PURE__*/React.createElement(DragAndDropInsertButton, {
|
|
128
|
+
type: type,
|
|
129
|
+
tableRef: tableRef,
|
|
130
|
+
onMouseDown: type === 'column' ? this.insertColumn : this.insertRow,
|
|
131
|
+
hasStickyHeaders: this.props.hasStickyHeaders || false
|
|
132
|
+
}) : /*#__PURE__*/React.createElement(InsertButton, {
|
|
133
|
+
type: type,
|
|
128
134
|
tableRef: tableRef,
|
|
129
135
|
onMouseDown: type === 'column' ? this.insertColumn : this.insertRow,
|
|
130
136
|
hasStickyHeaders: this.props.hasStickyHeaders || false
|
|
@@ -2,8 +2,9 @@ import React, { useCallback, useMemo } from 'react';
|
|
|
2
2
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
3
3
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
4
4
|
import { clearHoverSelection, hoverColumns, selectColumn } from '../../../commands';
|
|
5
|
+
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
5
6
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
6
|
-
import { getSelectedColumnIndexes } from '../../../utils';
|
|
7
|
+
import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
|
|
7
8
|
import { DragHandle } from '../../DragHandle';
|
|
8
9
|
var getSelectedColumns = function getSelectedColumns(selection) {
|
|
9
10
|
if (selection instanceof CellSelection && selection.isColSelection()) {
|
|
@@ -26,10 +27,13 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
26
27
|
localId = _ref.localId,
|
|
27
28
|
isInDanger = _ref.isInDanger,
|
|
28
29
|
rowHeights = _ref.rowHeights,
|
|
29
|
-
colWidths = _ref.colWidths
|
|
30
|
+
colWidths = _ref.colWidths,
|
|
31
|
+
hasHeaderColumn = _ref.hasHeaderColumn;
|
|
30
32
|
var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
|
|
31
33
|
return width ? "".concat(width - 1, "px") : '0px';
|
|
32
34
|
}).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
|
|
35
|
+
// TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
|
|
36
|
+
var columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
|
|
33
37
|
var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
|
|
34
38
|
var selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
35
39
|
var gridColumnPosition = useMemo(function () {
|
|
@@ -59,8 +63,13 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
59
63
|
clearHoverSelection()(state, dispatch);
|
|
60
64
|
}
|
|
61
65
|
}, [editorView, tableActive]);
|
|
66
|
+
var handleMouseUp = useCallback(function () {
|
|
67
|
+
var state = editorView.state,
|
|
68
|
+
dispatch = editorView.dispatch;
|
|
69
|
+
toggleDragMenu(undefined, 'column', colIndex)(state, dispatch);
|
|
70
|
+
}, [editorView, colIndex]);
|
|
62
71
|
return /*#__PURE__*/React.createElement("div", {
|
|
63
|
-
className: ClassName.
|
|
72
|
+
className: ClassName.DRAG_COLUMN_CONTROLS
|
|
64
73
|
}, /*#__PURE__*/React.createElement("div", {
|
|
65
74
|
className: ClassName.COLUMN_CONTROLS_INNER,
|
|
66
75
|
"data-testid": "table-floating-column-controls",
|
|
@@ -68,10 +77,39 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
68
77
|
gridTemplateColumns: widths,
|
|
69
78
|
marginTop: marginTop
|
|
70
79
|
}
|
|
71
|
-
},
|
|
80
|
+
}, !isResizing && columnParams.map(function (_ref2, index) {
|
|
81
|
+
var startIndex = _ref2.startIndex,
|
|
82
|
+
endIndex = _ref2.endIndex;
|
|
83
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
84
|
+
style: {
|
|
85
|
+
gridColumn: "".concat(index + 1, " / span 1")
|
|
86
|
+
},
|
|
87
|
+
"data-start-index": startIndex,
|
|
88
|
+
"data-end-index": endIndex,
|
|
89
|
+
className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER,
|
|
90
|
+
contentEditable: false,
|
|
91
|
+
key: index
|
|
92
|
+
}, !hasHeaderColumn && index === 0 && /*#__PURE__*/React.createElement("div", {
|
|
93
|
+
style: {
|
|
94
|
+
left: '0px',
|
|
95
|
+
right: 'unset'
|
|
96
|
+
},
|
|
97
|
+
className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT
|
|
98
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
99
|
+
className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT,
|
|
100
|
+
style: columnParams.length - 1 === index ? {
|
|
101
|
+
right: '0'
|
|
102
|
+
} : {}
|
|
103
|
+
}));
|
|
104
|
+
}), tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
|
|
72
105
|
style: {
|
|
73
106
|
gridColumn: gridColumnPosition,
|
|
74
|
-
|
|
107
|
+
zIndex: 99,
|
|
108
|
+
display: 'flex',
|
|
109
|
+
width: '100%',
|
|
110
|
+
justifyContent: 'center',
|
|
111
|
+
alignItems: 'center',
|
|
112
|
+
marginTop: "var(--ds-space-negative-025, -2px)"
|
|
75
113
|
},
|
|
76
114
|
"data-column-control-index": hoveredCell.colIndex,
|
|
77
115
|
"data-testid": "table-floating-column-control"
|
|
@@ -84,7 +122,8 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
84
122
|
appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
85
123
|
onClick: handleClick,
|
|
86
124
|
onMouseOver: handleMouseOver,
|
|
87
|
-
onMouseOut: handleMouseOut
|
|
125
|
+
onMouseOut: handleMouseOut,
|
|
126
|
+
onMouseUp: handleMouseUp
|
|
88
127
|
}))));
|
|
89
128
|
};
|
|
90
129
|
export default ColumnControls;
|
|
@@ -6,7 +6,7 @@ import React, { useEffect, useMemo, useState } from 'react';
|
|
|
6
6
|
import ReactDOM from 'react-dom';
|
|
7
7
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
8
8
|
import { TableCssClassName as ClassName } from '../../types';
|
|
9
|
-
import { getColumnsWidths, getRowHeights } from '../../utils';
|
|
9
|
+
import { containsHeaderColumn, getColumnsWidths, getRowHeights } from '../../utils';
|
|
10
10
|
import { ColumnControls } from './ColumnControls';
|
|
11
11
|
import { ColumnDropTargets } from './ColumnDropTargets';
|
|
12
12
|
export var TableFloatingColumnControls = function TableFloatingColumnControls(_ref) {
|
|
@@ -33,6 +33,7 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
|
|
|
33
33
|
setHasDropTargets = _useState4[1];
|
|
34
34
|
var node = getNode();
|
|
35
35
|
var currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
|
|
36
|
+
var hasHeaderColumn = containsHeaderColumn(node);
|
|
36
37
|
useEffect(function () {
|
|
37
38
|
var _window;
|
|
38
39
|
if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
|
|
@@ -95,11 +96,11 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
|
|
|
95
96
|
var colWidths = getColumnsWidths(editorView);
|
|
96
97
|
var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
97
98
|
var mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
|
|
99
|
+
if (!tableActive) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
98
102
|
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement("div", {
|
|
99
103
|
className: ClassName.COLUMN_CONTROLS_WRAPPER,
|
|
100
|
-
style: {
|
|
101
|
-
pointerEvents: 'none'
|
|
102
|
-
},
|
|
103
104
|
"data-testid": "table-floating-column-controls-wrapper"
|
|
104
105
|
}, /*#__PURE__*/React.createElement(ColumnControls, {
|
|
105
106
|
editorView: editorView,
|
|
@@ -111,7 +112,8 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
|
|
|
111
112
|
localId: currentNodeLocalId,
|
|
112
113
|
isInDanger: isInDanger,
|
|
113
114
|
rowHeights: rowHeights,
|
|
114
|
-
colWidths: colWidths
|
|
115
|
+
colWidths: colWidths,
|
|
116
|
+
hasHeaderColumn: hasHeaderColumn
|
|
115
117
|
}), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
|
|
116
118
|
tableRef: tableRef,
|
|
117
119
|
stickyTop: tableActive ? stickyTop : undefined,
|
|
@@ -5,7 +5,7 @@ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
|
5
5
|
import { clearHoverSelection } from '../../../commands';
|
|
6
6
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
7
7
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
8
|
-
import { getRowHeights, getSelectedRowIndexes } from '../../../utils';
|
|
8
|
+
import { getRowHeights, getRowsParams, getSelectedRowIndexes } from '../../../utils';
|
|
9
9
|
import { DragHandle } from '../../DragHandle';
|
|
10
10
|
var getSelectedRows = function getSelectedRows(selection) {
|
|
11
11
|
if (selection instanceof CellSelection && selection.isRowSelection()) {
|
|
@@ -25,10 +25,13 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
25
25
|
tableActive = _ref.tableActive,
|
|
26
26
|
editorView = _ref.editorView,
|
|
27
27
|
isInDanger = _ref.isInDanger,
|
|
28
|
+
isResizing = _ref.isResizing,
|
|
29
|
+
hasHeaderRow = _ref.hasHeaderRow,
|
|
28
30
|
hoverRows = _ref.hoverRows,
|
|
29
31
|
selectRow = _ref.selectRow,
|
|
30
32
|
updateCellHoverLocation = _ref.updateCellHoverLocation;
|
|
31
33
|
var rowHeights = getRowHeights(tableRef);
|
|
34
|
+
var rowsParams = getRowsParams(rowHeights);
|
|
32
35
|
var heights = rowHeights.map(function (height) {
|
|
33
36
|
return "".concat(height - 1, "px");
|
|
34
37
|
}).join(' ');
|
|
@@ -53,18 +56,15 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
53
56
|
}
|
|
54
57
|
}, [editorView, tableActive]);
|
|
55
58
|
var handleMouseMove = useCallback(function (e) {
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
var isParentDragControls = e.nativeEvent.target.closest(".".concat(ClassName.DRAG_ROW_CONTROLS));
|
|
60
|
+
var rowIndex = e.nativeEvent.target.getAttribute('data-start-index');
|
|
61
|
+
|
|
62
|
+
// avoid updating if event target is not related
|
|
63
|
+
if (!isParentDragControls || !rowIndex) {
|
|
58
64
|
return;
|
|
59
65
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var rowIndex = rowHeights.findIndex(function (row) {
|
|
63
|
-
totalHeight += row;
|
|
64
|
-
return hoverHeight <= totalHeight;
|
|
65
|
-
});
|
|
66
|
-
updateCellHoverLocation(rowIndex);
|
|
67
|
-
}, [updateCellHoverLocation, rowHeights]);
|
|
66
|
+
updateCellHoverLocation(Number(rowIndex));
|
|
67
|
+
}, [updateCellHoverLocation]);
|
|
68
68
|
var handleMouseOver = useCallback(function () {
|
|
69
69
|
hoverRows([rowIndex]);
|
|
70
70
|
}, [hoverRows, rowIndex]);
|
|
@@ -72,19 +72,41 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
72
72
|
selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
|
|
73
73
|
}, [rowIndex, selectRow]);
|
|
74
74
|
return /*#__PURE__*/React.createElement("div", {
|
|
75
|
-
className: ClassName.
|
|
75
|
+
className: ClassName.DRAG_ROW_CONTROLS,
|
|
76
76
|
style: {
|
|
77
77
|
gridTemplateRows: heights
|
|
78
78
|
},
|
|
79
79
|
onMouseMove: handleMouseMove
|
|
80
|
-
},
|
|
80
|
+
}, !isResizing && rowsParams.map(function (_ref2, index) {
|
|
81
|
+
var startIndex = _ref2.startIndex,
|
|
82
|
+
endIndex = _ref2.endIndex;
|
|
83
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
84
|
+
style: {
|
|
85
|
+
gridRow: "".concat(index + 1, " / span 1")
|
|
86
|
+
},
|
|
87
|
+
"data-start-index": startIndex,
|
|
88
|
+
"data-end-index": endIndex,
|
|
89
|
+
className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER,
|
|
90
|
+
contentEditable: false,
|
|
91
|
+
key: index
|
|
92
|
+
}, !hasHeaderRow && index === 0 && /*#__PURE__*/React.createElement("div", {
|
|
93
|
+
style: {
|
|
94
|
+
top: '0px',
|
|
95
|
+
left: "var(--ds-space-075, 6px)"
|
|
96
|
+
},
|
|
97
|
+
className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT
|
|
98
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
99
|
+
className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT
|
|
100
|
+
}));
|
|
101
|
+
}), !isResizing && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
|
|
81
102
|
style: {
|
|
82
103
|
gridRow: gridRowPosition,
|
|
83
104
|
display: 'flex',
|
|
84
105
|
height: '100%',
|
|
85
106
|
alignItems: 'center',
|
|
86
107
|
justifyContent: 'center'
|
|
87
|
-
}
|
|
108
|
+
},
|
|
109
|
+
"data-testid": "table-floating-row-drag-handle"
|
|
88
110
|
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
89
111
|
tableLocalId: (_tableNode$attrs$loca = tableNode === null || tableNode === void 0 || (_tableNode$attrs = tableNode.attrs) === null || _tableNode$attrs === void 0 ? void 0 : _tableNode$attrs.localId) !== null && _tableNode$attrs$loca !== void 0 ? _tableNode$attrs$loca : '',
|
|
90
112
|
indexes: [rowIndex],
|
|
@@ -174,6 +174,8 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
|
|
|
174
174
|
editorView: editorView,
|
|
175
175
|
tableActive: tableActive,
|
|
176
176
|
isInDanger: isInDanger,
|
|
177
|
+
isResizing: isResizing,
|
|
178
|
+
hasHeaderRow: hasHeaderRow,
|
|
177
179
|
hoverRows: this.hoverRows,
|
|
178
180
|
selectRow: this.selectRow,
|
|
179
181
|
updateCellHoverLocation: this.updateCellHoverLocation
|