@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.
Files changed (105) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/plugins/table/index.js +15 -2
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +27 -3
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +43 -7
  7. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +6 -0
  8. package/dist/cjs/plugins/table/ui/DragHandle/index.js +2 -0
  9. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +80 -0
  10. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +60 -0
  11. package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
  12. package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
  13. package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +1 -1
  14. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +9 -7
  15. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +2 -0
  16. package/dist/cjs/plugins/table/ui/consts.js +3 -2
  17. package/dist/cjs/plugins/table/utils/drag-menu.js +59 -0
  18. package/dist/es2019/plugins/table/index.js +15 -2
  19. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
  20. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  21. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +26 -3
  22. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +42 -3
  23. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +7 -0
  24. package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -0
  25. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +77 -0
  26. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +54 -0
  27. package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
  28. package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
  29. package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +1 -1
  30. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +10 -8
  31. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -0
  32. package/dist/es2019/plugins/table/ui/consts.js +2 -1
  33. package/dist/es2019/plugins/table/utils/drag-menu.js +44 -0
  34. package/dist/esm/plugins/table/index.js +15 -2
  35. package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
  36. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  37. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +27 -3
  38. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +43 -7
  39. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +6 -0
  40. package/dist/esm/plugins/table/ui/DragHandle/index.js +2 -0
  41. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +73 -0
  42. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +53 -0
  43. package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
  44. package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
  45. package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +1 -1
  46. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +10 -8
  47. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -0
  48. package/dist/esm/plugins/table/ui/consts.js +2 -1
  49. package/dist/esm/plugins/table/utils/drag-menu.js +52 -0
  50. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +8 -1
  51. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +2 -1
  52. package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +4 -0
  53. package/dist/types/plugins/table/types.d.ts +1 -0
  54. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +4 -2
  55. package/dist/types/plugins/table/ui/DragPreview/index.d.ts +2 -1
  56. package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +2 -1
  57. package/dist/types/plugins/table/ui/FloatingDeleteButton/types.d.ts +2 -1
  58. package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +19 -0
  59. package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +21 -0
  60. package/dist/types/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +2 -1
  61. package/dist/types/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +2 -1
  62. package/dist/types/plugins/table/ui/FloatingInsertButton/index.d.ts +4 -5
  63. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
  64. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -0
  65. package/dist/types/plugins/table/ui/consts.d.ts +1 -0
  66. package/dist/types/plugins/table/utils/drag-menu.d.ts +7 -0
  67. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +8 -1
  68. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +2 -1
  69. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +4 -0
  70. package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
  71. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +4 -2
  72. package/dist/types-ts4.5/plugins/table/ui/DragPreview/index.d.ts +2 -1
  73. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +2 -1
  74. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/types.d.ts +2 -1
  75. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +19 -0
  76. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +21 -0
  77. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +2 -1
  78. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +2 -1
  79. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +4 -5
  80. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
  81. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -0
  82. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
  83. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +7 -0
  84. package/package.json +3 -3
  85. package/src/plugins/table/index.tsx +16 -0
  86. package/src/plugins/table/nodeviews/TableComponent.tsx +2 -1
  87. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +14 -1
  88. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +43 -4
  89. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +41 -2
  90. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +7 -0
  91. package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +5 -0
  92. package/src/plugins/table/types.ts +2 -0
  93. package/src/plugins/table/ui/DragHandle/index.tsx +5 -1
  94. package/src/plugins/table/ui/DragPreview/index.tsx +2 -1
  95. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +2 -1
  96. package/src/plugins/table/ui/FloatingDeleteButton/types.ts +3 -1
  97. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +99 -0
  98. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +84 -0
  99. package/src/plugins/table/ui/FloatingInsertButton/InsertButton.tsx +8 -7
  100. package/src/plugins/table/ui/FloatingInsertButton/getPopupOptions.ts +3 -2
  101. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +10 -7
  102. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +16 -7
  103. package/src/plugins/table/ui/TableFloatingControls/index.tsx +5 -0
  104. package/src/plugins/table/ui/consts.ts +2 -0
  105. package/src/plugins/table/utils/drag-menu.ts +65 -0
@@ -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;
@@ -50,3 +50,4 @@ export declare const TABLE_SNAP_GAP = 9;
50
50
  export declare const TABLE_HIGHLIGHT_GAP = 10;
51
51
  export declare const TABLE_HIGHLIGHT_TOLERANCE = 2;
52
52
  export declare const STICKY_HEADER_TOGGLE_TOLERANCE_MS = 5;
53
+ export declare const dragMenuDropdownWidth = 240;
@@ -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[];
@@ -1,4 +1,5 @@
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 DragAndDropAction<T, D> {
4
5
  type: T;
@@ -7,6 +8,7 @@ export interface DragAndDropAction<T, D> {
7
8
  export declare const DragAndDropActionType: {
8
9
  readonly SET_DROP_TARGET: "SET_DROP_TARGET";
9
10
  readonly CLEAR_DROP_TARGET: "CLEAR_DROP_TARGET";
11
+ readonly TOGGLE_DRAG_MENU: "TOGGLE_DRAG_MENU";
10
12
  };
11
13
  export type DragAndDropSetDropTargetAction = DragAndDropAction<typeof DragAndDropActionType.SET_DROP_TARGET, {
12
14
  type: DropTargetType;
@@ -16,4 +18,9 @@ export type DragAndDropSetDropTargetAction = DragAndDropAction<typeof DragAndDro
16
18
  export type DragAndDropClearDropTargetAction = DragAndDropAction<typeof DragAndDropActionType.CLEAR_DROP_TARGET, {
17
19
  decorationSet: DecorationSet;
18
20
  }>;
19
- export type DragAndDropPluginAction = DragAndDropSetDropTargetAction | DragAndDropClearDropTargetAction;
21
+ export type DragAndDropToggleDragMenuAction = DragAndDropAction<typeof DragAndDropActionType.TOGGLE_DRAG_MENU, {
22
+ isDragMenuOpen: boolean;
23
+ direction: TableDirection;
24
+ index: number;
25
+ }>;
26
+ export type DragAndDropPluginAction = DragAndDropSetDropTargetAction | DragAndDropClearDropTargetAction | DragAndDropToggleDragMenuAction;
@@ -1,7 +1,7 @@
1
1
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  import type { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import type { DraggableType } from '../../types';
4
+ import type { DraggableType, TableDirection } from '../../types';
5
5
  import { TableDecorations } from '../../types';
6
6
  import { DropTargetType } from './consts';
7
7
  export declare const getDecorations: (state: EditorState) => DecorationSet;
@@ -9,3 +9,4 @@ export declare const updatePluginStateDecorations: (state: EditorState, decorati
9
9
  export declare const setDropTarget: (type: DropTargetType, index: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
10
10
  export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
11
11
  export declare const moveSource: (sourceType: DraggableType, sourceIndex: number, targetIndex: number) => import("@atlaskit/editor-common/types").Command;
12
+ export declare const toggleDragMenu: (isDragMenuOpen: boolean | undefined, direction?: TableDirection, index?: number) => import("@atlaskit/editor-common/types").Command;
@@ -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
  }
@@ -373,6 +373,7 @@ export type InvalidNodeAttr = {
373
373
  spanValue: number;
374
374
  tableLocalId: string;
375
375
  };
376
+ export type TableDirection = 'row' | 'column';
376
377
  /**
377
378
  * Drag and Drop interfaces
378
379
  */
@@ -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?: 'column' | 'row';
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: 'column' | 'row';
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): 'column' | 'row' | undefined;
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
- export type CellSelectionType = 'column' | 'row' | undefined;
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
- type: 'row' | 'column';
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
- declare function getPopupOptions(type: 'column' | 'row', index: number, hasNumberedColumns: boolean, tableContainer: HTMLElement | null): Partial<PopupProps>;
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;
@@ -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;
@@ -50,3 +50,4 @@ export declare const TABLE_SNAP_GAP = 9;
50
50
  export declare const TABLE_HIGHLIGHT_GAP = 10;
51
51
  export declare const TABLE_HIGHLIGHT_TOLERANCE = 2;
52
52
  export declare const STICKY_HEADER_TOGGLE_TOLERANCE_MS = 5;
53
+ export declare const dragMenuDropdownWidth = 240;
@@ -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.11",
3
+ "version": "5.3.13",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^32.0.0",
31
31
  "@atlaskit/custom-steps": "^0.0.2",
32
- "@atlaskit/editor-common": "^76.13.0",
32
+ "@atlaskit/editor-common": "^76.15.0",
33
33
  "@atlaskit/editor-palette": "1.5.1",
34
34
  "@atlaskit/editor-plugin-analytics": "^0.2.0",
35
35
  "@atlaskit/editor-plugin-content-insertion": "^0.1.0",
@@ -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.6.7",
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={options?.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;
@@ -4,9 +4,14 @@ import type {
4
4
  } from '@atlaskit/editor-prosemirror/state';
5
5
  import type { Decoration } from '@atlaskit/editor-prosemirror/view';
6
6
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
- import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
7
+ import {
8
+ moveColumn,
9
+ moveRow,
10
+ selectColumn,
11
+ selectRow,
12
+ } from '@atlaskit/editor-tables/utils';
8
13
 
9
- import type { DraggableType } from '../../types';
14
+ import type { DraggableType, TableDirection } from '../../types';
10
15
  import { TableDecorations } from '../../types';
11
16
  import {
12
17
  createColumnInsertLine,
@@ -109,7 +114,41 @@ export const moveSource = (
109
114
  return tr.setMeta('addToHistory', false);
110
115
  }
111
116
 
112
- const move = sourceType === 'table-row' ? moveRow : moveColumn;
113
- return move(sourceIndex, targetIndex)(tr);
117
+ const isTableRow = sourceType === 'table-row';
118
+ const move = isTableRow ? moveRow : moveColumn;
119
+ const newTr = move(sourceIndex, targetIndex)(tr);
120
+ const select = isTableRow ? selectRow : selectColumn;
121
+ return select(targetIndex)(newTr);
122
+ },
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);
114
153
  },
115
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
  }
@@ -405,6 +405,8 @@ export type InvalidNodeAttr = {
405
405
  tableLocalId: string;
406
406
  };
407
407
 
408
+ export type TableDirection = 'row' | 'column';
409
+
408
410
  /**
409
411
  * Drag and Drop interfaces
410
412
  */
@@ -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?: 'column' | 'row';
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: 'column' | 'row';
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
- ): 'column' | 'row' | undefined {
64
+ ): TableDirection | undefined {
64
65
  if (!isTableSelected(selection) && selection instanceof CellSelection) {
65
66
  if (selection.isRowSelection()) {
66
67
  return 'row';