@atlaskit/editor-plugin-table 5.3.12 → 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 +8 -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 +22 -1
- 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 +20 -0
- 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 +21 -0
- 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 +2 -2
- 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 +32 -1
- 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
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
+
import type { TableDirection } from '../../types';
|
|
2
3
|
import type { DropTargetType } from './consts';
|
|
3
4
|
export interface DragAndDropPluginState {
|
|
4
5
|
decorationSet: DecorationSet;
|
|
5
6
|
dropTargetType: DropTargetType;
|
|
6
7
|
dropTargetIndex: number;
|
|
8
|
+
isDragMenuOpen: boolean;
|
|
9
|
+
dragMenuDirection?: TableDirection;
|
|
10
|
+
dragMenuIndex: number;
|
|
7
11
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { MouseEventHandler } from 'react';
|
|
2
|
+
import type { TableDirection } from '../../types';
|
|
2
3
|
type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
|
|
3
4
|
type DragHandleProps = {
|
|
4
5
|
tableLocalId: string;
|
|
5
6
|
indexes: number[];
|
|
6
7
|
previewWidth?: number;
|
|
7
8
|
previewHeight?: number;
|
|
8
|
-
direction?:
|
|
9
|
+
direction?: TableDirection;
|
|
9
10
|
appearance?: DragHandleAppearance;
|
|
10
11
|
onClick?: MouseEventHandler;
|
|
11
12
|
onMouseOver?: MouseEventHandler;
|
|
12
13
|
onMouseOut?: MouseEventHandler;
|
|
14
|
+
onMouseUp?: MouseEventHandler;
|
|
13
15
|
};
|
|
14
|
-
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onClick, }: DragHandleProps) => JSX.Element;
|
|
16
|
+
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, }: DragHandleProps) => JSX.Element;
|
|
15
17
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import type { TableDirection } from '../../types';
|
|
2
3
|
export declare const DragPreview: ({ direction, width, height, }: {
|
|
3
|
-
direction:
|
|
4
|
+
direction: TableDirection;
|
|
4
5
|
width: number;
|
|
5
6
|
height: number;
|
|
6
7
|
}) => JSX.Element;
|
|
@@ -3,6 +3,7 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
3
3
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
import type { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
6
|
+
import type { TableDirection } from '../../types';
|
|
6
7
|
import type { CellSelectionType } from './types';
|
|
7
8
|
export interface Props {
|
|
8
9
|
editorView: EditorView;
|
|
@@ -23,7 +24,7 @@ export interface State {
|
|
|
23
24
|
position?: string;
|
|
24
25
|
scrollLeft: number;
|
|
25
26
|
}
|
|
26
|
-
export declare function getSelectionType(selection: Selection):
|
|
27
|
+
export declare function getSelectionType(selection: Selection): TableDirection | undefined;
|
|
27
28
|
declare class FloatingDeleteButton extends Component<Props, State> {
|
|
28
29
|
static displayName: string;
|
|
29
30
|
wrapper: HTMLElement | null;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TableDirection } from '../../types';
|
|
2
|
+
export type CellSelectionType = TableDirection | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { PluginConfig, TableDirection } from '../../types';
|
|
5
|
+
type DragMenuProps = {
|
|
6
|
+
direction?: TableDirection;
|
|
7
|
+
index?: number;
|
|
8
|
+
tableRef?: HTMLTableElement;
|
|
9
|
+
tableNode?: PmNode;
|
|
10
|
+
editorView: EditorView;
|
|
11
|
+
isOpen?: boolean;
|
|
12
|
+
targetCellPosition?: number;
|
|
13
|
+
mountPoint?: HTMLElement;
|
|
14
|
+
boundariesElement?: HTMLElement;
|
|
15
|
+
scrollableElement?: HTMLElement;
|
|
16
|
+
pluginConfig?: PluginConfig;
|
|
17
|
+
};
|
|
18
|
+
export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, }: DragMenuProps) => JSX.Element | null;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { TableDirection } from '../../types';
|
|
5
|
+
export interface Props {
|
|
6
|
+
editorView: EditorView;
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
tableRef?: HTMLTableElement;
|
|
9
|
+
tableNode?: PmNode;
|
|
10
|
+
mountPoint?: HTMLElement;
|
|
11
|
+
boundariesElement?: HTMLElement;
|
|
12
|
+
scrollableElement?: HTMLElement;
|
|
13
|
+
direction?: TableDirection;
|
|
14
|
+
index?: number;
|
|
15
|
+
targetCellPosition?: number;
|
|
16
|
+
}
|
|
17
|
+
declare const FloatingDragMenu: {
|
|
18
|
+
({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, }: Props): JSX.Element | null;
|
|
19
|
+
displayName: string;
|
|
20
|
+
};
|
|
21
|
+
export default FloatingDragMenu;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { SyntheticEvent } from 'react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import type { TableDirection } from '../../types';
|
|
4
5
|
export interface ButtonProps {
|
|
5
|
-
|
|
6
|
+
direction: TableDirection;
|
|
6
7
|
tableRef: HTMLElement;
|
|
7
8
|
onMouseDown: (event: SyntheticEvent<HTMLButtonElement>) => void;
|
|
8
9
|
hasStickyHeaders: boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { PopupProps } from '@atlaskit/editor-common/ui';
|
|
2
|
-
|
|
2
|
+
import type { TableDirection } from '../../types';
|
|
3
|
+
declare function getPopupOptions(direction: TableDirection, index: number, hasNumberedColumns: boolean, tableContainer: HTMLElement | null): Partial<PopupProps>;
|
|
3
4
|
export default getPopupOptions;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
-
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import type { DispatchAnalyticsEvent, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
5
4
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
6
|
-
import { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
|
-
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
7
|
export interface Props {
|
|
9
8
|
editorView: EditorView;
|
|
10
9
|
getEditorContainerWidth: GetEditorContainerWidth;
|
package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
5
|
import type { CellHoverMeta } from '../../../types';
|
|
5
6
|
type DragControlsProps = {
|
|
6
7
|
editorView: EditorView;
|
|
7
8
|
tableRef: HTMLTableElement;
|
|
9
|
+
tableNode?: PmNode;
|
|
8
10
|
tableActive?: boolean;
|
|
9
11
|
hoveredCell?: CellHoverMeta;
|
|
10
12
|
isInDanger?: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Component } from 'react';
|
|
2
2
|
import type { TableColumnOrdering } from '@atlaskit/custom-steps';
|
|
3
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
6
|
import type { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
@@ -8,6 +9,7 @@ export interface Props {
|
|
|
8
9
|
editorView: EditorView;
|
|
9
10
|
selection?: Selection;
|
|
10
11
|
tableRef?: HTMLTableElement;
|
|
12
|
+
tableNode?: PmNode;
|
|
11
13
|
tableActive?: boolean;
|
|
12
14
|
isInDanger?: boolean;
|
|
13
15
|
isResizing?: boolean;
|
|
@@ -21,6 +23,7 @@ export interface Props {
|
|
|
21
23
|
hoveredCell?: CellHoverMeta;
|
|
22
24
|
ordering?: TableColumnOrdering;
|
|
23
25
|
stickyHeader?: RowStickyState;
|
|
26
|
+
insertRowButtonIndex?: number;
|
|
24
27
|
}
|
|
25
28
|
interface State {
|
|
26
29
|
tableHeight: number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Command, DropdownOptionT } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
3
|
+
import type { TableDirection } from '../types';
|
|
4
|
+
export interface DragMenuConfig extends DropdownOptionT<Command> {
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const getDragMenuConfig: (direction: TableDirection, tableMap?: TableMap, index?: number) => DragMenuConfig[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.13",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@atlaskit/platform-feature-flags": "^0.2.1",
|
|
41
41
|
"@atlaskit/pragmatic-drag-and-drop": "^0.23.0",
|
|
42
42
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.11.8",
|
|
43
|
-
"@atlaskit/primitives": "^1.
|
|
43
|
+
"@atlaskit/primitives": "^1.7.0",
|
|
44
44
|
"@atlaskit/theme": "^12.6.0",
|
|
45
45
|
"@atlaskit/tokens": "^1.28.0",
|
|
46
46
|
"@atlaskit/tooltip": "^17.8.0",
|
|
@@ -75,6 +75,7 @@ import type { ColumnResizingPluginState, PluginConfig } from './types';
|
|
|
75
75
|
import FloatingContextualButton from './ui/FloatingContextualButton';
|
|
76
76
|
import FloatingContextualMenu from './ui/FloatingContextualMenu';
|
|
77
77
|
import FloatingDeleteButton from './ui/FloatingDeleteButton';
|
|
78
|
+
import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
78
79
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
79
80
|
import LayoutButton from './ui/LayoutButton';
|
|
80
81
|
import { isLayoutSupported } from './utils';
|
|
@@ -363,6 +364,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
363
364
|
stickyHeadersState,
|
|
364
365
|
tablePluginState,
|
|
365
366
|
tableWidthPluginState,
|
|
367
|
+
dragAndDropState,
|
|
366
368
|
}) => {
|
|
367
369
|
const { state } = editorView;
|
|
368
370
|
const isColumnResizing = resizingPluginState?.dragging;
|
|
@@ -382,6 +384,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
382
384
|
isHeaderColumnEnabled,
|
|
383
385
|
isHeaderRowEnabled,
|
|
384
386
|
tableWrapperTarget,
|
|
387
|
+
isDragAndDropEnabled,
|
|
385
388
|
} = tablePluginState!;
|
|
386
389
|
|
|
387
390
|
const { allowControls } = pluginConfig;
|
|
@@ -467,6 +470,19 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
467
470
|
}
|
|
468
471
|
/>
|
|
469
472
|
)}
|
|
473
|
+
{isDragAndDropEnabled && (
|
|
474
|
+
<FloatingDragMenu
|
|
475
|
+
editorView={editorView}
|
|
476
|
+
mountPoint={popupsMountPoint}
|
|
477
|
+
boundariesElement={popupsBoundariesElement}
|
|
478
|
+
tableRef={tableRef as HTMLTableElement}
|
|
479
|
+
tableNode={tableNode}
|
|
480
|
+
targetCellPosition={targetCellPosition}
|
|
481
|
+
direction={dragAndDropState?.dragMenuDirection}
|
|
482
|
+
index={dragAndDropState?.dragMenuIndex}
|
|
483
|
+
isOpen={!!dragAndDropState?.isDragMenuOpen && !isResizing}
|
|
484
|
+
/>
|
|
485
|
+
)}
|
|
470
486
|
{allowControls && !isResizing && (
|
|
471
487
|
<FloatingDeleteButton
|
|
472
488
|
editorView={editorView}
|
|
@@ -416,6 +416,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
416
416
|
<TableFloatingControls
|
|
417
417
|
editorView={view}
|
|
418
418
|
tableRef={tableRef}
|
|
419
|
+
tableNode={node}
|
|
419
420
|
tableActive={tableActive}
|
|
420
421
|
hoveredRows={hoveredRows}
|
|
421
422
|
hoveredCell={hoveredCell}
|
|
@@ -423,7 +424,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
423
424
|
isResizing={isResizing}
|
|
424
425
|
isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
|
|
425
426
|
isHeaderRowEnabled={isHeaderRowEnabled}
|
|
426
|
-
isDragAndDropEnabled={
|
|
427
|
+
isDragAndDropEnabled={isDragAndDropEnabled}
|
|
427
428
|
ordering={ordering}
|
|
428
429
|
isHeaderColumnEnabled={isHeaderColumnEnabled}
|
|
429
430
|
hasHeaderRow={hasHeaderRow}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
2
|
|
|
3
|
+
import type { TableDirection } from '../../types';
|
|
4
|
+
|
|
3
5
|
import type { DropTargetType } from './consts';
|
|
4
6
|
|
|
5
7
|
export interface DragAndDropAction<T, D> {
|
|
@@ -10,6 +12,7 @@ export interface DragAndDropAction<T, D> {
|
|
|
10
12
|
export const DragAndDropActionType = {
|
|
11
13
|
SET_DROP_TARGET: 'SET_DROP_TARGET',
|
|
12
14
|
CLEAR_DROP_TARGET: 'CLEAR_DROP_TARGET',
|
|
15
|
+
TOGGLE_DRAG_MENU: 'TOGGLE_DRAG_MENU',
|
|
13
16
|
} as const;
|
|
14
17
|
|
|
15
18
|
export type DragAndDropSetDropTargetAction = DragAndDropAction<
|
|
@@ -28,7 +31,17 @@ export type DragAndDropClearDropTargetAction = DragAndDropAction<
|
|
|
28
31
|
}
|
|
29
32
|
>;
|
|
30
33
|
|
|
34
|
+
export type DragAndDropToggleDragMenuAction = DragAndDropAction<
|
|
35
|
+
typeof DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
36
|
+
{
|
|
37
|
+
isDragMenuOpen: boolean;
|
|
38
|
+
direction: TableDirection;
|
|
39
|
+
index: number;
|
|
40
|
+
}
|
|
41
|
+
>;
|
|
42
|
+
|
|
31
43
|
// NOTE: This should be a Union of all possible actions
|
|
32
44
|
export type DragAndDropPluginAction =
|
|
33
45
|
| DragAndDropSetDropTargetAction
|
|
34
|
-
| DragAndDropClearDropTargetAction
|
|
46
|
+
| DragAndDropClearDropTargetAction
|
|
47
|
+
| DragAndDropToggleDragMenuAction;
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
selectRow,
|
|
12
12
|
} from '@atlaskit/editor-tables/utils';
|
|
13
13
|
|
|
14
|
-
import type { DraggableType } from '../../types';
|
|
14
|
+
import type { DraggableType, TableDirection } from '../../types';
|
|
15
15
|
import { TableDecorations } from '../../types';
|
|
16
16
|
import {
|
|
17
17
|
createColumnInsertLine,
|
|
@@ -121,3 +121,34 @@ export const moveSource = (
|
|
|
121
121
|
return select(targetIndex)(newTr);
|
|
122
122
|
},
|
|
123
123
|
);
|
|
124
|
+
|
|
125
|
+
export const toggleDragMenu = (
|
|
126
|
+
isDragMenuOpen: boolean | undefined,
|
|
127
|
+
direction?: TableDirection,
|
|
128
|
+
index?: number,
|
|
129
|
+
) =>
|
|
130
|
+
createCommand(
|
|
131
|
+
(state) => {
|
|
132
|
+
let {
|
|
133
|
+
isDragMenuOpen: previousOpenState,
|
|
134
|
+
dragMenuDirection,
|
|
135
|
+
dragMenuIndex,
|
|
136
|
+
} = getPluginState(state);
|
|
137
|
+
if (previousOpenState === isDragMenuOpen) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
143
|
+
data: {
|
|
144
|
+
isDragMenuOpen:
|
|
145
|
+
isDragMenuOpen === undefined ? !previousOpenState : isDragMenuOpen,
|
|
146
|
+
direction: direction ?? dragMenuDirection,
|
|
147
|
+
index: index ?? dragMenuIndex,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
(tr: Transaction) => {
|
|
152
|
+
return tr.setMeta('addToHistory', false);
|
|
153
|
+
},
|
|
154
|
+
);
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
+
import { getCellsInRow } from '@atlaskit/editor-tables/utils';
|
|
8
9
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
9
10
|
|
|
10
11
|
import type { DraggableSourceData } from '../../types';
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
} from '../../utils/merged-cells';
|
|
15
16
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
16
17
|
|
|
18
|
+
import { DragAndDropActionType } from './actions';
|
|
17
19
|
import { clearDropTarget, moveSource, setDropTarget } from './commands';
|
|
18
20
|
import { DropTargetType } from './consts';
|
|
19
21
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
@@ -27,12 +29,49 @@ export const createPlugin = (
|
|
|
27
29
|
return new SafePlugin({
|
|
28
30
|
state: createPluginState(dispatch, (state) => ({
|
|
29
31
|
decorationSet: DecorationSet.empty,
|
|
30
|
-
// TODO: This is example placeholder state. We could use this to track which row/col is currently set as the drop target
|
|
31
|
-
// This would result in a blue highlight being displayed on the corrisponding row/column to single the drop target location.
|
|
32
32
|
dropTargetType: DropTargetType.NONE,
|
|
33
33
|
dropTargetIndex: 0,
|
|
34
|
+
isDragMenuOpen: false,
|
|
35
|
+
dragMenuIndex: 0,
|
|
34
36
|
})),
|
|
35
37
|
key: pluginKey,
|
|
38
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
39
|
+
const { targetCellPosition: oldTargetCellPosition } =
|
|
40
|
+
getTablePluginState(oldState);
|
|
41
|
+
const { targetCellPosition: newTargetCellPosition } =
|
|
42
|
+
getTablePluginState(newState);
|
|
43
|
+
const { isDragMenuOpen, dragMenuIndex } = getPluginState(newState);
|
|
44
|
+
|
|
45
|
+
// What's happening here? you asked... In a nutshell;
|
|
46
|
+
// 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.
|
|
47
|
+
// This will stop the drag menu from moving around the screen to different row/cols. Too achieve this we need
|
|
48
|
+
// to check if the new target cell position is pointed at a different cell than what the drag menu was opened on.
|
|
49
|
+
if (oldTargetCellPosition !== newTargetCellPosition) {
|
|
50
|
+
if (isDragMenuOpen) {
|
|
51
|
+
const tr = newState.tr;
|
|
52
|
+
const action = {
|
|
53
|
+
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
54
|
+
data: {
|
|
55
|
+
isDragMenuOpen: false,
|
|
56
|
+
direction: undefined,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (newTargetCellPosition !== undefined) {
|
|
61
|
+
const cells = getCellsInRow(dragMenuIndex)(tr.selection);
|
|
62
|
+
if (
|
|
63
|
+
cells &&
|
|
64
|
+
cells.length &&
|
|
65
|
+
cells[0].node !== tr.doc.nodeAt(newTargetCellPosition)
|
|
66
|
+
) {
|
|
67
|
+
return tr.setMeta(pluginKey, action);
|
|
68
|
+
} // else NOP
|
|
69
|
+
} else {
|
|
70
|
+
return tr.setMeta(pluginKey, action);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
36
75
|
view: (editorView: EditorView) => {
|
|
37
76
|
return {
|
|
38
77
|
destroy: monitorForElements({
|
|
@@ -22,6 +22,13 @@ export default (
|
|
|
22
22
|
dropTargetType: DropTargetType.NONE,
|
|
23
23
|
dropTargetIndex: 0,
|
|
24
24
|
};
|
|
25
|
+
case DragAndDropActionType.TOGGLE_DRAG_MENU:
|
|
26
|
+
return {
|
|
27
|
+
...pluginState,
|
|
28
|
+
isDragMenuOpen: action.data.isDragMenuOpen,
|
|
29
|
+
dragMenuDirection: action.data.direction,
|
|
30
|
+
dragMenuIndex: action.data.index,
|
|
31
|
+
};
|
|
25
32
|
default:
|
|
26
33
|
return pluginState;
|
|
27
34
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
2
|
|
|
3
|
+
import type { TableDirection } from '../../types';
|
|
4
|
+
|
|
3
5
|
import type { DropTargetType } from './consts';
|
|
4
6
|
|
|
5
7
|
export interface DragAndDropPluginState {
|
|
6
8
|
decorationSet: DecorationSet;
|
|
7
9
|
dropTargetType: DropTargetType;
|
|
8
10
|
dropTargetIndex: number;
|
|
11
|
+
isDragMenuOpen: boolean;
|
|
12
|
+
dragMenuDirection?: TableDirection;
|
|
13
|
+
dragMenuIndex: number;
|
|
9
14
|
}
|
|
@@ -7,6 +7,7 @@ import ReactDOM from 'react-dom';
|
|
|
7
7
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
8
8
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
9
9
|
|
|
10
|
+
import type { TableDirection } from '../../types';
|
|
10
11
|
import { TableCssClassName as ClassName } from '../../types';
|
|
11
12
|
import { DragPreview } from '../DragPreview';
|
|
12
13
|
import { DragHandleIcon } from '../icons';
|
|
@@ -18,11 +19,12 @@ type DragHandleProps = {
|
|
|
18
19
|
indexes: number[];
|
|
19
20
|
previewWidth?: number;
|
|
20
21
|
previewHeight?: number;
|
|
21
|
-
direction?:
|
|
22
|
+
direction?: TableDirection;
|
|
22
23
|
appearance?: DragHandleAppearance;
|
|
23
24
|
onClick?: MouseEventHandler;
|
|
24
25
|
onMouseOver?: MouseEventHandler;
|
|
25
26
|
onMouseOut?: MouseEventHandler;
|
|
27
|
+
onMouseUp?: MouseEventHandler;
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export const DragHandle = ({
|
|
@@ -34,6 +36,7 @@ export const DragHandle = ({
|
|
|
34
36
|
previewHeight,
|
|
35
37
|
onMouseOver,
|
|
36
38
|
onMouseOut,
|
|
39
|
+
onMouseUp,
|
|
37
40
|
onClick,
|
|
38
41
|
}: DragHandleProps) => {
|
|
39
42
|
const dragHandleDivRef = useRef<HTMLButtonElement>(null);
|
|
@@ -85,6 +88,7 @@ export const DragHandle = ({
|
|
|
85
88
|
data-testid="table-floating-column-controls-drag-handle"
|
|
86
89
|
onMouseOver={onMouseOver}
|
|
87
90
|
onMouseOut={onMouseOut}
|
|
91
|
+
onMouseUp={onMouseUp}
|
|
88
92
|
onClick={onClick}
|
|
89
93
|
>
|
|
90
94
|
<DragHandleIcon />
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { Box, xcss } from '@atlaskit/primitives';
|
|
4
4
|
|
|
5
|
+
import type { TableDirection } from '../../types';
|
|
5
6
|
import { DragInMotionIcon } from '../icons/DragInMotionIcon';
|
|
6
7
|
|
|
7
8
|
const boxStyles = xcss({
|
|
@@ -17,7 +18,7 @@ export const DragPreview = ({
|
|
|
17
18
|
width,
|
|
18
19
|
height,
|
|
19
20
|
}: {
|
|
20
|
-
direction:
|
|
21
|
+
direction: TableDirection;
|
|
21
22
|
width: number;
|
|
22
23
|
height: number;
|
|
23
24
|
}) => {
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from '../../commands-with-analytics';
|
|
24
24
|
import { getPluginState as getTablePluginState } from '../../pm-plugins/plugin-factory';
|
|
25
25
|
import type { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
26
|
+
import type { TableDirection } from '../../types';
|
|
26
27
|
import { TableCssClassName as ClassName } from '../../types';
|
|
27
28
|
import {
|
|
28
29
|
getColumnDeleteButtonParams,
|
|
@@ -60,7 +61,7 @@ export interface State {
|
|
|
60
61
|
|
|
61
62
|
export function getSelectionType(
|
|
62
63
|
selection: Selection,
|
|
63
|
-
):
|
|
64
|
+
): TableDirection | undefined {
|
|
64
65
|
if (!isTableSelected(selection) && selection instanceof CellSelection) {
|
|
65
66
|
if (selection.isRowSelection()) {
|
|
66
67
|
return 'row';
|
|
@@ -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
|
+
};
|