@atlaskit/editor-plugin-table 5.3.11 → 5.3.13
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 +14 -0
- package/dist/cjs/plugins/table/index.js +15 -2
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +27 -3
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +43 -7
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +6 -0
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +80 -0
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +60 -0
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +1 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +9 -7
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/cjs/plugins/table/ui/consts.js +3 -2
- package/dist/cjs/plugins/table/utils/drag-menu.js +59 -0
- package/dist/es2019/plugins/table/index.js +15 -2
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +26 -3
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +42 -3
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +7 -0
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +77 -0
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +54 -0
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +1 -1
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +10 -8
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/es2019/plugins/table/ui/consts.js +2 -1
- package/dist/es2019/plugins/table/utils/drag-menu.js +44 -0
- package/dist/esm/plugins/table/index.js +15 -2
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +27 -3
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +43 -7
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +6 -0
- package/dist/esm/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +73 -0
- package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +53 -0
- package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
- package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
- package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +1 -1
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +10 -8
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/esm/plugins/table/ui/consts.js +2 -1
- package/dist/esm/plugins/table/utils/drag-menu.js +52 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +8 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +2 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +4 -0
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +4 -2
- package/dist/types/plugins/table/ui/DragPreview/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingDeleteButton/types.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +19 -0
- package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +21 -0
- package/dist/types/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/index.d.ts +4 -5
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -0
- package/dist/types/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types/plugins/table/utils/drag-menu.d.ts +7 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +8 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +4 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +4 -2
- package/dist/types-ts4.5/plugins/table/ui/DragPreview/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/types.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +19 -0
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +21 -0
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +4 -5
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +7 -0
- package/package.json +3 -3
- package/src/plugins/table/index.tsx +16 -0
- package/src/plugins/table/nodeviews/TableComponent.tsx +2 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +14 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +43 -4
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +41 -2
- package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +7 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +5 -0
- package/src/plugins/table/types.ts +2 -0
- package/src/plugins/table/ui/DragHandle/index.tsx +5 -1
- package/src/plugins/table/ui/DragPreview/index.tsx +2 -1
- package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +2 -1
- package/src/plugins/table/ui/FloatingDeleteButton/types.ts +3 -1
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +99 -0
- package/src/plugins/table/ui/FloatingDragMenu/index.tsx +84 -0
- package/src/plugins/table/ui/FloatingInsertButton/InsertButton.tsx +8 -7
- package/src/plugins/table/ui/FloatingInsertButton/getPopupOptions.ts +3 -2
- package/src/plugins/table/ui/FloatingInsertButton/index.tsx +10 -7
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +16 -7
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +5 -0
- package/src/plugins/table/ui/consts.ts +2 -0
- package/src/plugins/table/utils/drag-menu.ts +65 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
|
+
import {
|
|
5
|
+
ArrowKeyNavigationType,
|
|
6
|
+
DropdownMenu,
|
|
7
|
+
} from '@atlaskit/editor-common/ui-menu';
|
|
8
|
+
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
9
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
10
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
11
|
+
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
12
|
+
|
|
13
|
+
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
14
|
+
import type { PluginConfig, TableDirection } from '../../types';
|
|
15
|
+
import type { DragMenuConfig } from '../../utils/drag-menu';
|
|
16
|
+
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
17
|
+
import { dragMenuDropdownWidth } from '../consts';
|
|
18
|
+
|
|
19
|
+
type DragMenuProps = {
|
|
20
|
+
direction?: TableDirection;
|
|
21
|
+
index?: number;
|
|
22
|
+
tableRef?: HTMLTableElement;
|
|
23
|
+
tableNode?: PmNode;
|
|
24
|
+
editorView: EditorView;
|
|
25
|
+
isOpen?: boolean;
|
|
26
|
+
targetCellPosition?: number;
|
|
27
|
+
mountPoint?: HTMLElement;
|
|
28
|
+
boundariesElement?: HTMLElement;
|
|
29
|
+
scrollableElement?: HTMLElement;
|
|
30
|
+
pluginConfig?: PluginConfig;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const convertToDropdownItems = (dragMenuConfig: DragMenuConfig[]) => {
|
|
34
|
+
let menuItems: MenuItem[] = [];
|
|
35
|
+
let menuCallback: { [key: string]: Command } = {};
|
|
36
|
+
dragMenuConfig.forEach((item) => {
|
|
37
|
+
menuItems.push({
|
|
38
|
+
key: item.id,
|
|
39
|
+
content: item.title,
|
|
40
|
+
value: { name: item.id },
|
|
41
|
+
isDisabled: item.disabled,
|
|
42
|
+
});
|
|
43
|
+
item.onClick && (menuCallback[item.id] = item.onClick);
|
|
44
|
+
});
|
|
45
|
+
return { menuItems, menuCallback };
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const DragMenu = ({
|
|
49
|
+
direction = 'row',
|
|
50
|
+
index,
|
|
51
|
+
isOpen,
|
|
52
|
+
editorView,
|
|
53
|
+
tableNode,
|
|
54
|
+
mountPoint,
|
|
55
|
+
boundariesElement,
|
|
56
|
+
scrollableElement,
|
|
57
|
+
}: DragMenuProps) => {
|
|
58
|
+
const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
|
|
59
|
+
|
|
60
|
+
const dragMenuConfig = getDragMenuConfig(direction, tableMap, index);
|
|
61
|
+
|
|
62
|
+
const { menuItems, menuCallback } = convertToDropdownItems(dragMenuConfig);
|
|
63
|
+
|
|
64
|
+
const closeMenu = () => {
|
|
65
|
+
const { state, dispatch } = editorView;
|
|
66
|
+
toggleDragMenu(false)(state, dispatch);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const onMenuItemActivated = ({ item }: { item: MenuItem }) => {
|
|
70
|
+
menuCallback[item.value.name]?.(editorView.state, editorView.dispatch);
|
|
71
|
+
closeMenu();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (!menuItems) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<DropdownMenu
|
|
80
|
+
mountTo={mountPoint}
|
|
81
|
+
//This needs be removed when the a11y is completely handled
|
|
82
|
+
//Disabling key navigation now as it works only partially
|
|
83
|
+
arrowKeyNavigationProviderOptions={{
|
|
84
|
+
type: ArrowKeyNavigationType.MENU,
|
|
85
|
+
disableArrowKeyNavigation: true,
|
|
86
|
+
}}
|
|
87
|
+
items={[
|
|
88
|
+
{
|
|
89
|
+
items: menuItems,
|
|
90
|
+
},
|
|
91
|
+
]}
|
|
92
|
+
isOpen={isOpen}
|
|
93
|
+
onOpenChange={closeMenu}
|
|
94
|
+
onItemActivated={onMenuItemActivated}
|
|
95
|
+
fitWidth={dragMenuDropdownWidth}
|
|
96
|
+
boundariesElement={boundariesElement}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
4
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
8
|
+
|
|
9
|
+
import type { TableDirection } from '../../types';
|
|
10
|
+
import { dragMenuDropdownWidth } from '../consts';
|
|
11
|
+
|
|
12
|
+
import { DragMenu } from './DragMenu';
|
|
13
|
+
|
|
14
|
+
export interface Props {
|
|
15
|
+
editorView: EditorView;
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
tableRef?: HTMLTableElement;
|
|
18
|
+
tableNode?: PmNode;
|
|
19
|
+
mountPoint?: HTMLElement;
|
|
20
|
+
boundariesElement?: HTMLElement;
|
|
21
|
+
scrollableElement?: HTMLElement;
|
|
22
|
+
direction?: TableDirection;
|
|
23
|
+
index?: number;
|
|
24
|
+
targetCellPosition?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const FloatingDragMenu = ({
|
|
28
|
+
mountPoint,
|
|
29
|
+
boundariesElement,
|
|
30
|
+
scrollableElement,
|
|
31
|
+
editorView,
|
|
32
|
+
isOpen,
|
|
33
|
+
tableRef,
|
|
34
|
+
tableNode,
|
|
35
|
+
direction,
|
|
36
|
+
index,
|
|
37
|
+
targetCellPosition,
|
|
38
|
+
}: Props) => {
|
|
39
|
+
if (
|
|
40
|
+
!isOpen ||
|
|
41
|
+
!targetCellPosition ||
|
|
42
|
+
editorView.state.doc.nodeSize <= targetCellPosition
|
|
43
|
+
) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
48
|
+
const targetCellRef = findDomRefAtPos(targetCellPosition, domAtPos);
|
|
49
|
+
if (!targetCellRef) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
|
|
54
|
+
return (
|
|
55
|
+
<Popup
|
|
56
|
+
alignX="left"
|
|
57
|
+
alignY="top"
|
|
58
|
+
target={targetCellRef as HTMLElement}
|
|
59
|
+
mountTo={mountPoint}
|
|
60
|
+
boundariesElement={boundariesElement}
|
|
61
|
+
scrollableElement={scrollableElement}
|
|
62
|
+
fitWidth={dragMenuDropdownWidth}
|
|
63
|
+
// z-index value below is to ensure that this menu is above other floating menu
|
|
64
|
+
// in table, but below floating dialogs like typeaheads, pickers, etc.
|
|
65
|
+
zIndex={akEditorFloatingOverlapPanelZIndex}
|
|
66
|
+
forcePlacement={true}
|
|
67
|
+
offset={[7, 0]}
|
|
68
|
+
stick={true}
|
|
69
|
+
>
|
|
70
|
+
<DragMenu
|
|
71
|
+
editorView={editorView}
|
|
72
|
+
isOpen={isOpen}
|
|
73
|
+
boundariesElement={boundariesElement}
|
|
74
|
+
tableNode={tableNode}
|
|
75
|
+
direction={direction}
|
|
76
|
+
index={index}
|
|
77
|
+
/>
|
|
78
|
+
</Popup>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
FloatingDragMenu.displayName = 'FloatingDragMenu';
|
|
83
|
+
|
|
84
|
+
export default FloatingDragMenu;
|
|
@@ -14,12 +14,13 @@ import { closestElement } from '@atlaskit/editor-common/utils';
|
|
|
14
14
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
15
15
|
import Tooltip from '@atlaskit/tooltip';
|
|
16
16
|
|
|
17
|
+
import type { TableDirection } from '../../types';
|
|
17
18
|
import { TableCssClassName as ClassName } from '../../types';
|
|
18
19
|
import { tableToolbarSize } from '../consts';
|
|
19
20
|
import tableMessages from '../messages';
|
|
20
21
|
|
|
21
22
|
export interface ButtonProps {
|
|
22
|
-
|
|
23
|
+
direction: TableDirection;
|
|
23
24
|
tableRef: HTMLElement;
|
|
24
25
|
onMouseDown: (event: SyntheticEvent<HTMLButtonElement>) => void;
|
|
25
26
|
hasStickyHeaders: boolean;
|
|
@@ -69,14 +70,14 @@ const getInsertLineWidth = (tableRef: HTMLElement) => {
|
|
|
69
70
|
);
|
|
70
71
|
};
|
|
71
72
|
|
|
72
|
-
const tooltipMessageByType = (type:
|
|
73
|
+
const tooltipMessageByType = (type: TableDirection) => {
|
|
73
74
|
return type === 'row' ? tableMessages.insertRow : tableMessages.insertColumn;
|
|
74
75
|
};
|
|
75
76
|
|
|
76
77
|
const InsertButton = ({
|
|
77
78
|
onMouseDown,
|
|
78
79
|
tableRef,
|
|
79
|
-
|
|
80
|
+
direction,
|
|
80
81
|
intl: { formatMessage },
|
|
81
82
|
hasStickyHeaders,
|
|
82
83
|
}: ButtonProps & WrappedComponentProps) => {
|
|
@@ -84,8 +85,8 @@ const InsertButton = ({
|
|
|
84
85
|
<Tooltip
|
|
85
86
|
content={
|
|
86
87
|
<ToolTipContent
|
|
87
|
-
description={formatMessage(tooltipMessageByType(
|
|
88
|
-
keymap={
|
|
88
|
+
description={formatMessage(tooltipMessageByType(direction))}
|
|
89
|
+
keymap={direction === 'row' ? addRowAfter : addColumnAfter}
|
|
89
90
|
/>
|
|
90
91
|
}
|
|
91
92
|
position="top"
|
|
@@ -109,7 +110,7 @@ const InsertButton = ({
|
|
|
109
110
|
<div
|
|
110
111
|
className={ClassName.CONTROLS_INSERT_LINE}
|
|
111
112
|
style={
|
|
112
|
-
|
|
113
|
+
direction === 'row'
|
|
113
114
|
? { width: getInsertLineWidth(tableRef) }
|
|
114
115
|
: { height: getInsertLineHeight(tableRef, hasStickyHeaders) }
|
|
115
116
|
}
|
|
@@ -119,7 +120,7 @@ const InsertButton = ({
|
|
|
119
120
|
);
|
|
120
121
|
|
|
121
122
|
const floatingButtonClassName =
|
|
122
|
-
|
|
123
|
+
direction === 'column'
|
|
123
124
|
? ClassName.CONTROLS_FLOATING_BUTTON_COLUMN
|
|
124
125
|
: ClassName.CONTROLS_FLOATING_BUTTON_ROW;
|
|
125
126
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PopupProps } from '@atlaskit/editor-common/ui';
|
|
2
2
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
3
3
|
|
|
4
|
+
import type { TableDirection } from '../../types';
|
|
4
5
|
import {
|
|
5
6
|
tableInsertColumnButtonOffset,
|
|
6
7
|
tableInsertColumnButtonSize,
|
|
@@ -104,12 +105,12 @@ function getColumnOptions(
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
function getPopupOptions(
|
|
107
|
-
|
|
108
|
+
direction: TableDirection,
|
|
108
109
|
index: number,
|
|
109
110
|
hasNumberedColumns: boolean,
|
|
110
111
|
tableContainer: HTMLElement | null,
|
|
111
112
|
): Partial<PopupProps> {
|
|
112
|
-
switch (
|
|
113
|
+
switch (direction) {
|
|
113
114
|
case 'column':
|
|
114
115
|
return getColumnOptions(index, tableContainer, hasNumberedColumns);
|
|
115
116
|
case 'row':
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import { injectIntl } from 'react-intl-next';
|
|
4
5
|
|
|
5
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
AnalyticsEventPayload,
|
|
8
|
+
DispatchAnalyticsEvent,
|
|
9
|
+
EditorAnalyticsAPI,
|
|
10
|
+
} from '@atlaskit/editor-common/analytics';
|
|
6
11
|
import {
|
|
7
12
|
ACTION,
|
|
8
13
|
ACTION_SUBJECT,
|
|
9
|
-
AnalyticsEventPayload,
|
|
10
14
|
CONTENT_COMPONENT,
|
|
11
|
-
DispatchAnalyticsEvent,
|
|
12
15
|
EVENT_TYPE,
|
|
13
16
|
INPUT_METHOD,
|
|
14
17
|
} from '@atlaskit/editor-common/analytics';
|
|
15
18
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
16
19
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
17
20
|
import { closestElement } from '@atlaskit/editor-common/utils';
|
|
18
|
-
import { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
21
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
19
22
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
20
|
-
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
23
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
21
24
|
import { akEditorTableCellOnStickyHeaderZIndex } from '@atlaskit/editor-shared-styles';
|
|
22
25
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
23
26
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
@@ -201,7 +204,7 @@ export class FloatingInsertButton extends React.Component<
|
|
|
201
204
|
zIndex={zIndex}
|
|
202
205
|
>
|
|
203
206
|
<InsertButton
|
|
204
|
-
|
|
207
|
+
direction={type}
|
|
205
208
|
tableRef={tableRef}
|
|
206
209
|
onMouseDown={type === 'column' ? this.insertColumn : this.insertRow}
|
|
207
210
|
hasStickyHeaders={this.props.hasStickyHeaders || false}
|
|
@@ -4,12 +4,14 @@ import React, { useCallback, useMemo } from 'react';
|
|
|
4
4
|
import { injectIntl } from 'react-intl-next';
|
|
5
5
|
import type { WrappedComponentProps } from 'react-intl-next';
|
|
6
6
|
|
|
7
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
8
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
8
9
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
9
10
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
10
|
-
import {
|
|
11
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
11
12
|
|
|
12
13
|
import { clearHoverSelection } from '../../../commands';
|
|
14
|
+
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
13
15
|
import type { CellHoverMeta } from '../../../types';
|
|
14
16
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
15
17
|
import { getRowHeights, getSelectedRowIndexes } from '../../../utils';
|
|
@@ -18,6 +20,7 @@ import { DragHandle } from '../../DragHandle';
|
|
|
18
20
|
type DragControlsProps = {
|
|
19
21
|
editorView: EditorView;
|
|
20
22
|
tableRef: HTMLTableElement;
|
|
23
|
+
tableNode?: PmNode;
|
|
21
24
|
tableActive?: boolean;
|
|
22
25
|
hoveredCell?: CellHoverMeta;
|
|
23
26
|
isInDanger?: boolean;
|
|
@@ -39,6 +42,7 @@ const getSelectedRows = (selection: Selection) => {
|
|
|
39
42
|
|
|
40
43
|
const DragControlsComponent = ({
|
|
41
44
|
tableRef,
|
|
45
|
+
tableNode,
|
|
42
46
|
hoveredCell,
|
|
43
47
|
tableActive,
|
|
44
48
|
editorView,
|
|
@@ -51,6 +55,15 @@ const DragControlsComponent = ({
|
|
|
51
55
|
const heights = rowHeights.map((height) => `${height - 1}px`).join(' ');
|
|
52
56
|
const selectedRowIndexes = getSelectedRows(editorView.state.selection);
|
|
53
57
|
const rowWidth = tableRef.offsetWidth;
|
|
58
|
+
|
|
59
|
+
const onMouseUp = useCallback(() => {
|
|
60
|
+
toggleDragMenu(
|
|
61
|
+
undefined,
|
|
62
|
+
'row',
|
|
63
|
+
hoveredCell?.rowIndex,
|
|
64
|
+
)(editorView.state, editorView.dispatch);
|
|
65
|
+
}, [editorView, hoveredCell?.rowIndex]);
|
|
66
|
+
|
|
54
67
|
const rowIndex = hoveredCell?.rowIndex;
|
|
55
68
|
|
|
56
69
|
const gridRowPosition = useMemo(() => {
|
|
@@ -61,11 +74,6 @@ const DragControlsComponent = ({
|
|
|
61
74
|
return `${rowIndex! + 1} / span 1`;
|
|
62
75
|
}, [rowIndex, selectedRowIndexes]);
|
|
63
76
|
|
|
64
|
-
const getLocalId = () => {
|
|
65
|
-
const tableNode = findTable(editorView.state.selection);
|
|
66
|
-
return tableNode?.node?.attrs?.localId || '';
|
|
67
|
-
};
|
|
68
|
-
|
|
69
77
|
const handleMouseOut = useCallback(() => {
|
|
70
78
|
if (tableActive) {
|
|
71
79
|
const { state, dispatch } = editorView;
|
|
@@ -126,7 +134,7 @@ const DragControlsComponent = ({
|
|
|
126
134
|
}}
|
|
127
135
|
>
|
|
128
136
|
<DragHandle
|
|
129
|
-
tableLocalId={
|
|
137
|
+
tableLocalId={tableNode?.attrs?.localId ?? ''}
|
|
130
138
|
indexes={[rowIndex!]}
|
|
131
139
|
previewWidth={rowWidth}
|
|
132
140
|
previewHeight={rowHeights[rowIndex!]}
|
|
@@ -140,6 +148,7 @@ const DragControlsComponent = ({
|
|
|
140
148
|
onClick={handleClick}
|
|
141
149
|
onMouseOver={handleMouseOver}
|
|
142
150
|
onMouseOut={handleMouseOut}
|
|
151
|
+
onMouseUp={onMouseUp}
|
|
143
152
|
/>
|
|
144
153
|
</div>
|
|
145
154
|
)}
|
|
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import type { TableColumnOrdering } from '@atlaskit/custom-steps';
|
|
4
4
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
5
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
6
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
6
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
8
|
|
|
@@ -19,6 +20,7 @@ export interface Props {
|
|
|
19
20
|
editorView: EditorView;
|
|
20
21
|
selection?: Selection;
|
|
21
22
|
tableRef?: HTMLTableElement;
|
|
23
|
+
tableNode?: PmNode;
|
|
22
24
|
tableActive?: boolean;
|
|
23
25
|
isInDanger?: boolean;
|
|
24
26
|
isResizing?: boolean;
|
|
@@ -32,6 +34,7 @@ export interface Props {
|
|
|
32
34
|
hoveredCell?: CellHoverMeta;
|
|
33
35
|
ordering?: TableColumnOrdering;
|
|
34
36
|
stickyHeader?: RowStickyState;
|
|
37
|
+
insertRowButtonIndex?: number;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
interface State {
|
|
@@ -111,6 +114,7 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
111
114
|
const {
|
|
112
115
|
editorView,
|
|
113
116
|
tableRef,
|
|
117
|
+
tableNode,
|
|
114
118
|
isInDanger,
|
|
115
119
|
isResizing,
|
|
116
120
|
isNumberColumnEnabled,
|
|
@@ -157,6 +161,7 @@ export default class TableFloatingControls extends Component<Props, State> {
|
|
|
157
161
|
{isDragAndDropEnabled ? (
|
|
158
162
|
<DragControls
|
|
159
163
|
tableRef={tableRef}
|
|
164
|
+
tableNode={tableNode}
|
|
160
165
|
hoveredCell={hoveredCell}
|
|
161
166
|
editorView={editorView}
|
|
162
167
|
tableActive={tableActive}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Command,
|
|
3
|
+
CommandDispatch,
|
|
4
|
+
DropdownOptionT,
|
|
5
|
+
} from '@atlaskit/editor-common/types';
|
|
6
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import type { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
8
|
+
|
|
9
|
+
import { moveSource } from '../pm-plugins/drag-and-drop/commands';
|
|
10
|
+
import type { TableDirection } from '../types';
|
|
11
|
+
|
|
12
|
+
const canDecrease = (index?: number, min: number = 0) =>
|
|
13
|
+
index !== undefined && index > min;
|
|
14
|
+
const canIncrease = (index?: number, max: number = 0) =>
|
|
15
|
+
index !== undefined && index < max;
|
|
16
|
+
|
|
17
|
+
export interface DragMenuConfig extends DropdownOptionT<Command> {
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const getDragMenuConfig = (
|
|
22
|
+
direction: TableDirection,
|
|
23
|
+
tableMap?: TableMap,
|
|
24
|
+
index?: number,
|
|
25
|
+
): DragMenuConfig[] => {
|
|
26
|
+
const moveOptions =
|
|
27
|
+
direction === 'row'
|
|
28
|
+
? [
|
|
29
|
+
{ label: 'up', offset: -1, canMove: canDecrease },
|
|
30
|
+
{
|
|
31
|
+
label: 'down',
|
|
32
|
+
offset: 1,
|
|
33
|
+
canMove: (index?: number) =>
|
|
34
|
+
canIncrease(index, (tableMap?.height ?? 0) - 1),
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
: [
|
|
38
|
+
{ label: 'left', offset: -1, canMove: canDecrease },
|
|
39
|
+
{
|
|
40
|
+
label: 'right',
|
|
41
|
+
offset: 1,
|
|
42
|
+
canMove: (index?: number) =>
|
|
43
|
+
canIncrease(index, (tableMap?.width ?? 0) - 1),
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
return [
|
|
48
|
+
...moveOptions.map(({ label, offset, canMove }) => ({
|
|
49
|
+
id: `move_${direction}_${label}`,
|
|
50
|
+
title: `Move ${direction} ${label}`,
|
|
51
|
+
disabled: !canMove(index),
|
|
52
|
+
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
53
|
+
if (canMove(index)) {
|
|
54
|
+
moveSource(
|
|
55
|
+
`table-${direction}`,
|
|
56
|
+
index!,
|
|
57
|
+
index! + offset,
|
|
58
|
+
)(state, dispatch);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
},
|
|
63
|
+
})),
|
|
64
|
+
];
|
|
65
|
+
};
|