@atlaskit/editor-plugin-table 5.3.14 → 5.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/table/index.js +2 -1
  3. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +49 -11
  4. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +5 -2
  5. package/dist/cjs/plugins/table/ui/icons/AddColLeftIcon.js +44 -0
  6. package/dist/cjs/plugins/table/ui/icons/AddColRightIcon.js +44 -0
  7. package/dist/cjs/plugins/table/ui/icons/AddRowAboveIcon.js +45 -0
  8. package/dist/cjs/plugins/table/ui/icons/AddRowBelowIcon.js +40 -0
  9. package/dist/cjs/plugins/table/ui/icons/index.js +29 -1
  10. package/dist/cjs/plugins/table/utils/drag-menu.js +122 -10
  11. package/dist/es2019/plugins/table/index.js +2 -1
  12. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +52 -8
  13. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +5 -2
  14. package/dist/es2019/plugins/table/ui/icons/AddColLeftIcon.js +35 -0
  15. package/dist/es2019/plugins/table/ui/icons/AddColRightIcon.js +35 -0
  16. package/dist/es2019/plugins/table/ui/icons/AddRowAboveIcon.js +36 -0
  17. package/dist/es2019/plugins/table/ui/icons/AddRowBelowIcon.js +31 -0
  18. package/dist/es2019/plugins/table/ui/icons/index.js +5 -1
  19. package/dist/es2019/plugins/table/utils/drag-menu.js +118 -8
  20. package/dist/esm/plugins/table/index.js +2 -1
  21. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +46 -8
  22. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +5 -2
  23. package/dist/esm/plugins/table/ui/icons/AddColLeftIcon.js +37 -0
  24. package/dist/esm/plugins/table/ui/icons/AddColRightIcon.js +37 -0
  25. package/dist/esm/plugins/table/ui/icons/AddRowAboveIcon.js +38 -0
  26. package/dist/esm/plugins/table/ui/icons/AddRowBelowIcon.js +33 -0
  27. package/dist/esm/plugins/table/ui/icons/index.js +5 -1
  28. package/dist/esm/plugins/table/utils/drag-menu.js +120 -8
  29. package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +5 -2
  30. package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  31. package/dist/types/plugins/table/ui/icons/AddColLeftIcon.d.ts +2 -0
  32. package/dist/types/plugins/table/ui/icons/AddColRightIcon.d.ts +2 -0
  33. package/dist/types/plugins/table/ui/icons/AddRowAboveIcon.d.ts +2 -0
  34. package/dist/types/plugins/table/ui/icons/AddRowBelowIcon.d.ts +2 -0
  35. package/dist/types/plugins/table/ui/icons/index.d.ts +4 -0
  36. package/dist/types/plugins/table/utils/drag-menu.d.ts +6 -3
  37. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +5 -2
  38. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  39. package/dist/types-ts4.5/plugins/table/ui/icons/AddColLeftIcon.d.ts +2 -0
  40. package/dist/types-ts4.5/plugins/table/ui/icons/AddColRightIcon.d.ts +2 -0
  41. package/dist/types-ts4.5/plugins/table/ui/icons/AddRowAboveIcon.d.ts +2 -0
  42. package/dist/types-ts4.5/plugins/table/ui/icons/AddRowBelowIcon.d.ts +2 -0
  43. package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +4 -0
  44. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +6 -3
  45. package/package.json +1 -1
  46. package/src/plugins/table/index.tsx +1 -0
  47. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +73 -6
  48. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +5 -0
  49. package/src/plugins/table/ui/icons/AddColLeftIcon.tsx +43 -0
  50. package/src/plugins/table/ui/icons/AddColRightIcon.tsx +43 -0
  51. package/src/plugins/table/ui/icons/AddRowAboveIcon.tsx +42 -0
  52. package/src/plugins/table/ui/icons/AddRowBelowIcon.tsx +36 -0
  53. package/src/plugins/table/ui/icons/index.ts +4 -0
  54. package/src/plugins/table/utils/drag-menu.ts +158 -5
@@ -1,5 +1,20 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
3
+ import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
4
+ import ArrowDownIcon from '@atlaskit/icon/glyph/arrow-down';
5
+ import ArrowLeftIcon from '@atlaskit/icon/glyph/arrow-left';
6
+ import ArrowRightIcon from '@atlaskit/icon/glyph/arrow-right';
7
+ import ArrowUpIcon from '@atlaskit/icon/glyph/arrow-up';
8
+ import CrossCircleIcon from '@atlaskit/icon/glyph/cross-circle';
9
+ import EditorLayoutThreeEqualIcon from '@atlaskit/icon/glyph/editor/layout-three-equal';
10
+ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
11
+ import HipchatChevronDoubleDownIcon from '@atlaskit/icon/glyph/hipchat/chevron-double-down';
12
+ import HipchatChevronDoubleUpIcon from '@atlaskit/icon/glyph/hipchat/chevron-double-up';
13
+ import { clearMultipleCells, insertColumn, insertRow, sortByColumn } from '../commands';
14
+ import { deleteColumnsCommand } from '../commands/delete';
2
15
  import { moveSource } from '../pm-plugins/drag-and-drop/commands';
16
+ import { deleteRows } from '../transforms';
17
+ import { AddColLeftIcon, AddColRightIcon, AddRowAboveIcon, AddRowBelowIcon } from '../ui/icons';
3
18
  var canDecrease = function canDecrease(index) {
4
19
  var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
5
20
  return index !== undefined && index > min;
@@ -8,38 +23,122 @@ var canIncrease = function canIncrease(index) {
8
23
  var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
9
24
  return index !== undefined && index < max;
10
25
  };
11
- export var getDragMenuConfig = function getDragMenuConfig(direction, tableMap, index) {
26
+ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect) {
27
+ var addOptions = direction === 'row' ? [{
28
+ label: 'above',
29
+ offset: 0,
30
+ icon: AddRowAboveIcon,
31
+ keymap: addRowBefore
32
+ }, {
33
+ label: 'below',
34
+ offset: 1,
35
+ icon: AddRowBelowIcon,
36
+ keymap: addRowAfter
37
+ }] : [{
38
+ label: 'left',
39
+ offset: 0,
40
+ icon: AddColLeftIcon,
41
+ keymap: addColumnBefore
42
+ }, {
43
+ label: 'right',
44
+ offset: 1,
45
+ icon: AddColRightIcon,
46
+ keymap: addColumnAfter
47
+ }];
12
48
  var moveOptions = direction === 'row' ? [{
13
49
  label: 'up',
14
50
  offset: -1,
15
- canMove: canDecrease
51
+ canMove: canDecrease,
52
+ icon: ArrowUpIcon
16
53
  }, {
17
54
  label: 'down',
18
55
  offset: 1,
19
56
  canMove: function canMove(index) {
20
57
  var _tableMap$height;
21
58
  return canIncrease(index, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
22
- }
59
+ },
60
+ icon: ArrowDownIcon
23
61
  }] : [{
24
62
  label: 'left',
25
63
  offset: -1,
26
- canMove: canDecrease
64
+ canMove: canDecrease,
65
+ icon: ArrowLeftIcon
27
66
  }, {
28
67
  label: 'right',
29
68
  offset: 1,
30
69
  canMove: function canMove(index) {
31
70
  var _tableMap$width;
32
71
  return canIncrease(index, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
33
- }
72
+ },
73
+ icon: ArrowRightIcon
34
74
  }];
35
- return _toConsumableArray(moveOptions.map(function (_ref) {
75
+ var sortOptions = direction === 'column' ? [{
76
+ label: 'increasing',
77
+ order: SortOrder.ASC,
78
+ icon: HipchatChevronDoubleUpIcon
79
+ }, {
80
+ label: 'decreasing',
81
+ order: SortOrder.DESC,
82
+ icon: HipchatChevronDoubleDownIcon
83
+ }] : [];
84
+ return [].concat(_toConsumableArray(addOptions.map(function (_ref) {
36
85
  var label = _ref.label,
37
86
  offset = _ref.offset,
38
- canMove = _ref.canMove;
87
+ icon = _ref.icon,
88
+ keymap = _ref.keymap;
89
+ return {
90
+ id: "add_".concat(direction, "_").concat(label),
91
+ title: "Add ".concat(direction, " ").concat(label),
92
+ icon: icon,
93
+ onClick: function onClick(state, dispatch) {
94
+ if (direction === 'row') {
95
+ insertRow(index + offset, true)(state, dispatch);
96
+ } else {
97
+ insertColumn(getEditorContainerWidth)(index + offset)(state, dispatch);
98
+ }
99
+ return true;
100
+ },
101
+ keymap: keymap && tooltip(keymap)
102
+ };
103
+ })), [direction === 'column' ? {
104
+ id: 'distribute_columns',
105
+ title: 'Distribute columns',
106
+ disabled: true,
107
+ onClick: function onClick() {
108
+ return false;
109
+ },
110
+ icon: EditorLayoutThreeEqualIcon
111
+ } : undefined, {
112
+ id: 'clear_cells',
113
+ title: 'Clear cells',
114
+ onClick: function onClick(state, dispatch) {
115
+ clearMultipleCells(targetCellPosition)(state, dispatch);
116
+ return true;
117
+ },
118
+ icon: CrossCircleIcon,
119
+ keymap: tooltip(backspace)
120
+ }, {
121
+ id: "delete_".concat(direction),
122
+ title: "Delete ".concat(direction),
123
+ onClick: function onClick(state, dispatch) {
124
+ if (direction === 'row') {
125
+ dispatch === null || dispatch === void 0 || dispatch(deleteRows(selectionRect, false)(state.tr));
126
+ } else {
127
+ deleteColumnsCommand(selectionRect)(state, dispatch);
128
+ }
129
+ return true;
130
+ },
131
+ icon: RemoveIcon
132
+ }], _toConsumableArray(moveOptions.map(function (_ref2) {
133
+ var label = _ref2.label,
134
+ offset = _ref2.offset,
135
+ canMove = _ref2.canMove,
136
+ icon = _ref2.icon;
39
137
  return {
40
138
  id: "move_".concat(direction, "_").concat(label),
41
139
  title: "Move ".concat(direction, " ").concat(label),
42
140
  disabled: !canMove(index),
141
+ icon: icon,
43
142
  onClick: function onClick(state, dispatch) {
44
143
  if (canMove(index)) {
45
144
  moveSource("table-".concat(direction), index, index + offset)(state, dispatch);
@@ -48,5 +147,18 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, tableMap, i
48
147
  return false;
49
148
  }
50
149
  };
51
- }));
150
+ })), _toConsumableArray(sortOptions.map(function (_ref3) {
151
+ var label = _ref3.label,
152
+ order = _ref3.order,
153
+ icon = _ref3.icon;
154
+ return {
155
+ id: "sort_column_".concat(order),
156
+ title: "Sort ".concat(label),
157
+ icon: icon,
158
+ onClick: function onClick(state, dispatch) {
159
+ sortByColumn(index, order)(state, dispatch);
160
+ return true;
161
+ }
162
+ };
163
+ }))).filter(Boolean);
52
164
  };
@@ -1,4 +1,6 @@
1
- /// <reference types="react" />
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
2
4
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
6
  import type { PluginConfig, TableDirection } from '../../types';
@@ -14,6 +16,7 @@ type DragMenuProps = {
14
16
  boundariesElement?: HTMLElement;
15
17
  scrollableElement?: HTMLElement;
16
18
  pluginConfig?: PluginConfig;
19
+ getEditorContainerWidth: GetEditorContainerWidth;
17
20
  };
18
- export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, }: DragMenuProps) => JSX.Element | null;
21
+ export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, }: DragMenuProps) => jsx.JSX.Element | null;
19
22
  export {};
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
2
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 { TableDirection } from '../../types';
@@ -13,9 +14,10 @@ export interface Props {
13
14
  direction?: TableDirection;
14
15
  index?: number;
15
16
  targetCellPosition?: number;
17
+ getEditorContainerWidth: GetEditorContainerWidth;
16
18
  }
17
19
  declare const FloatingDragMenu: {
18
- ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, }: Props): JSX.Element | null;
20
+ ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, }: Props): JSX.Element | null;
19
21
  displayName: string;
20
22
  };
21
23
  export default FloatingDragMenu;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const AddColLeftIcon: () => JSX.Element;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const AddColRightIcon: () => JSX.Element;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const AddRowAboveIcon: () => JSX.Element;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const AddRowBelowIcon: () => JSX.Element;
@@ -1,2 +1,6 @@
1
1
  export { DragHandleIcon } from './DragHandleIcon';
2
2
  export { DragInMotionIcon } from './DragInMotionIcon';
3
+ export { AddRowAboveIcon } from './AddRowAboveIcon';
4
+ export { AddRowBelowIcon } from './AddRowBelowIcon';
5
+ export { AddColLeftIcon } from './AddColLeftIcon';
6
+ export { AddColRightIcon } from './AddColRightIcon';
@@ -1,7 +1,10 @@
1
- import type { Command, DropdownOptionT } from '@atlaskit/editor-common/types';
2
- import type { TableMap } from '@atlaskit/editor-tables/table-map';
1
+ /// <reference types="react" />
2
+ import type { Command, DropdownOptionT, GetEditorContainerWidth, IconProps } from '@atlaskit/editor-common/types';
3
+ import type { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
3
4
  import type { TableDirection } from '../types';
4
5
  export interface DragMenuConfig extends DropdownOptionT<Command> {
5
6
  id: string;
7
+ icon?: React.ComponentType<IconProps>;
8
+ keymap?: string;
6
9
  }
7
- export declare const getDragMenuConfig: (direction: TableDirection, tableMap?: TableMap, index?: number) => DragMenuConfig[];
10
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
@@ -1,4 +1,6 @@
1
- /// <reference types="react" />
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
2
4
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
6
  import type { PluginConfig, TableDirection } from '../../types';
@@ -14,6 +16,7 @@ type DragMenuProps = {
14
16
  boundariesElement?: HTMLElement;
15
17
  scrollableElement?: HTMLElement;
16
18
  pluginConfig?: PluginConfig;
19
+ getEditorContainerWidth: GetEditorContainerWidth;
17
20
  };
18
- export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, }: DragMenuProps) => JSX.Element | null;
21
+ export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, }: DragMenuProps) => jsx.JSX.Element | null;
19
22
  export {};
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
2
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 { TableDirection } from '../../types';
@@ -13,9 +14,10 @@ export interface Props {
13
14
  direction?: TableDirection;
14
15
  index?: number;
15
16
  targetCellPosition?: number;
17
+ getEditorContainerWidth: GetEditorContainerWidth;
16
18
  }
17
19
  declare const FloatingDragMenu: {
18
- ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, }: Props): JSX.Element | null;
20
+ ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableRef, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, }: Props): JSX.Element | null;
19
21
  displayName: string;
20
22
  };
21
23
  export default FloatingDragMenu;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const AddColLeftIcon: () => JSX.Element;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const AddColRightIcon: () => JSX.Element;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const AddRowAboveIcon: () => JSX.Element;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const AddRowBelowIcon: () => JSX.Element;
@@ -1,2 +1,6 @@
1
1
  export { DragHandleIcon } from './DragHandleIcon';
2
2
  export { DragInMotionIcon } from './DragInMotionIcon';
3
+ export { AddRowAboveIcon } from './AddRowAboveIcon';
4
+ export { AddRowBelowIcon } from './AddRowBelowIcon';
5
+ export { AddColLeftIcon } from './AddColLeftIcon';
6
+ export { AddColRightIcon } from './AddColRightIcon';
@@ -1,7 +1,10 @@
1
- import type { Command, DropdownOptionT } from '@atlaskit/editor-common/types';
2
- import type { TableMap } from '@atlaskit/editor-tables/table-map';
1
+ /// <reference types="react" />
2
+ import type { Command, DropdownOptionT, GetEditorContainerWidth, IconProps } from '@atlaskit/editor-common/types';
3
+ import type { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
3
4
  import type { TableDirection } from '../types';
4
5
  export interface DragMenuConfig extends DropdownOptionT<Command> {
5
6
  id: string;
7
+ icon?: React.ComponentType<IconProps>;
8
+ keymap?: string;
6
9
  }
7
- export declare const getDragMenuConfig: (direction: TableDirection, tableMap?: TableMap, index?: number) => DragMenuConfig[];
10
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.14",
3
+ "version": "5.3.15",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -482,6 +482,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
482
482
  direction={dragAndDropState?.dragMenuDirection}
483
483
  index={dragAndDropState?.dragMenuIndex}
484
484
  isOpen={!!dragAndDropState?.isDragMenuOpen && !isResizing}
485
+ getEditorContainerWidth={defaultGetEditorContainerWidth}
485
486
  />
486
487
  )}
487
488
  {allowControls && !isDragAndDropEnabled && !isResizing && (
@@ -1,6 +1,10 @@
1
- import React from 'react';
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
2
3
 
3
- import type { Command } from '@atlaskit/editor-common/types';
4
+ import type {
5
+ Command,
6
+ GetEditorContainerWidth,
7
+ } from '@atlaskit/editor-common/types';
4
8
  import {
5
9
  ArrowKeyNavigationType,
6
10
  DropdownMenu,
@@ -8,10 +12,19 @@ import {
8
12
  import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
9
13
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
10
14
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
15
+ import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
11
16
  import { TableMap } from '@atlaskit/editor-tables/table-map';
17
+ import {
18
+ findCellRectClosestToPos,
19
+ getSelectionRect,
20
+ isSelectionType,
21
+ } from '@atlaskit/editor-tables/utils';
22
+ import { token } from '@atlaskit/tokens';
12
23
 
24
+ import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
13
25
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
14
26
  import type { PluginConfig, TableDirection } from '../../types';
27
+ import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
15
28
  import type { DragMenuConfig } from '../../utils/drag-menu';
16
29
  import { getDragMenuConfig } from '../../utils/drag-menu';
17
30
  import { dragMenuDropdownWidth } from '../consts';
@@ -28,6 +41,7 @@ type DragMenuProps = {
28
41
  boundariesElement?: HTMLElement;
29
42
  scrollableElement?: HTMLElement;
30
43
  pluginConfig?: PluginConfig;
44
+ getEditorContainerWidth: GetEditorContainerWidth;
31
45
  };
32
46
 
33
47
  const convertToDropdownItems = (dragMenuConfig: DragMenuConfig[]) => {
@@ -39,6 +53,19 @@ const convertToDropdownItems = (dragMenuConfig: DragMenuConfig[]) => {
39
53
  content: item.title,
40
54
  value: { name: item.id },
41
55
  isDisabled: item.disabled,
56
+ elemBefore: item.icon ? (
57
+ <div
58
+ style={{
59
+ marginRight: token('space.negative.075', '-6px'),
60
+ display: 'flex',
61
+ }}
62
+ >
63
+ <item.icon label={item.title} />
64
+ </div>
65
+ ) : undefined,
66
+ elemAfter: item.keymap ? (
67
+ <div css={shortcutStyle}>{item.keymap}</div>
68
+ ) : undefined,
42
69
  });
43
70
  item.onClick && (menuCallback[item.id] = item.onClick);
44
71
  });
@@ -54,10 +81,25 @@ export const DragMenu = ({
54
81
  mountPoint,
55
82
  boundariesElement,
56
83
  scrollableElement,
84
+ targetCellPosition,
85
+ getEditorContainerWidth,
57
86
  }: DragMenuProps) => {
58
87
  const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
59
88
 
60
- const dragMenuConfig = getDragMenuConfig(direction, tableMap, index);
89
+ const { state, dispatch } = editorView;
90
+ const { selection } = state;
91
+ const selectionRect = isSelectionType(selection, 'cell')
92
+ ? getSelectionRect(selection)!
93
+ : findCellRectClosestToPos(selection.$from);
94
+
95
+ const dragMenuConfig = getDragMenuConfig(
96
+ direction,
97
+ getEditorContainerWidth,
98
+ tableMap,
99
+ index,
100
+ targetCellPosition,
101
+ selectionRect,
102
+ );
61
103
 
62
104
  const { menuItems, menuCallback } = convertToDropdownItems(dragMenuConfig);
63
105
 
@@ -66,11 +108,34 @@ export const DragMenu = ({
66
108
  toggleDragMenu(false)(state, dispatch);
67
109
  };
68
110
 
69
- const onMenuItemActivated = ({ item }: { item: MenuItem }) => {
70
- menuCallback[item.value.name]?.(editorView.state, editorView.dispatch);
111
+ const handleMenuItemActivated = ({ item }: { item: MenuItem }) => {
112
+ menuCallback[item.value.name]?.(state, dispatch);
71
113
  closeMenu();
72
114
  };
73
115
 
116
+ const handleItemMouseEnter = ({ item }: { item: MenuItem }) => {
117
+ if (!selectionRect || !item.value.name?.startsWith('delete')) {
118
+ return;
119
+ }
120
+
121
+ (item.value.name === 'delete_column'
122
+ ? hoverColumns(getSelectedColumnIndexes(selectionRect), true)
123
+ : hoverRows(getSelectedRowIndexes(selectionRect), true))(state, dispatch);
124
+ };
125
+
126
+ const handleItemMouseLeave = ({ item }: { item: any }) => {
127
+ if (
128
+ [
129
+ 'sort_column_asc',
130
+ 'sort_column_desc',
131
+ 'delete_column',
132
+ 'delete_row',
133
+ ].indexOf(item.value.name) > -1
134
+ ) {
135
+ clearHoverSelection()(state, dispatch);
136
+ }
137
+ };
138
+
74
139
  if (!menuItems) {
75
140
  return null;
76
141
  }
@@ -91,7 +156,9 @@ export const DragMenu = ({
91
156
  ]}
92
157
  isOpen={isOpen}
93
158
  onOpenChange={closeMenu}
94
- onItemActivated={onMenuItemActivated}
159
+ onItemActivated={handleMenuItemActivated}
160
+ onMouseEnter={handleItemMouseEnter}
161
+ onMouseLeave={handleItemMouseLeave}
95
162
  fitWidth={dragMenuDropdownWidth}
96
163
  boundariesElement={boundariesElement}
97
164
  />
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
3
4
  import { Popup } from '@atlaskit/editor-common/ui';
4
5
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
5
6
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
@@ -23,6 +24,7 @@ export interface Props {
23
24
  direction?: TableDirection;
24
25
  index?: number;
25
26
  targetCellPosition?: number;
27
+ getEditorContainerWidth: GetEditorContainerWidth;
26
28
  }
27
29
 
28
30
  const FloatingDragMenu = ({
@@ -36,6 +38,7 @@ const FloatingDragMenu = ({
36
38
  direction,
37
39
  index,
38
40
  targetCellPosition,
41
+ getEditorContainerWidth,
39
42
  }: Props) => {
40
43
  if (
41
44
  !isOpen ||
@@ -81,6 +84,8 @@ const FloatingDragMenu = ({
81
84
  tableNode={tableNode}
82
85
  direction={direction}
83
86
  index={index}
87
+ targetCellPosition={targetCellPosition}
88
+ getEditorContainerWidth={getEditorContainerWidth}
84
89
  />
85
90
  </Popup>
86
91
  );
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+
3
+ export const AddColLeftIcon = () => (
4
+ <svg
5
+ width="24"
6
+ height="24"
7
+ viewBox="0 0 24 24"
8
+ fill="currentColor"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ >
11
+ <rect
12
+ width="24"
13
+ height="24"
14
+ transform="matrix(0 -1 1 0 0 24)"
15
+ fill="none"
16
+ fillOpacity="0.01"
17
+ />
18
+ <rect
19
+ x="12"
20
+ y="18"
21
+ width="12"
22
+ height="3"
23
+ rx="0.5"
24
+ transform="rotate(-90 12 18)"
25
+ fill="currentColor"
26
+ />
27
+ <rect
28
+ x="16"
29
+ y="18"
30
+ width="12"
31
+ height="3"
32
+ rx="0.5"
33
+ transform="rotate(-90 16 18)"
34
+ fill="currentColor"
35
+ />
36
+ <path
37
+ fillRule="evenodd"
38
+ clipRule="evenodd"
39
+ d="M7 11H5.99C5.72652 11.0026 5.47473 11.1092 5.28935 11.2964C5.10397 11.4837 4.99999 11.7365 5 12C5 12.556 5.444 13 5.99 13H7V14C7 14.2652 7.10536 14.5196 7.29289 14.7071C7.48043 14.8946 7.73478 15 8 15C8.26522 15 8.51957 14.8946 8.70711 14.7071C8.89464 14.5196 9 14.2652 9 14V13H10.01C10.2735 12.9974 10.5253 12.8908 10.7107 12.7036C10.896 12.5163 11 12.2635 11 12C11 11.444 10.556 11 10.01 11H9V10C9 9.73478 8.89464 9.48043 8.70711 9.29289C8.51957 9.10536 8.26522 9 8 9C7.73478 9 7.48043 9.10536 7.29289 9.29289C7.10536 9.48043 7 9.73478 7 10V11Z"
40
+ fill="currentColor"
41
+ />
42
+ </svg>
43
+ );
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+
3
+ export const AddColRightIcon = () => (
4
+ <svg
5
+ width="24"
6
+ height="24"
7
+ viewBox="0 0 24 24"
8
+ fill="none"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ >
11
+ <rect
12
+ width="24"
13
+ height="24"
14
+ transform="translate(0 24) rotate(-90)"
15
+ fill="none"
16
+ fillOpacity="0.01"
17
+ />
18
+ <rect
19
+ x="9"
20
+ y="18"
21
+ width="12"
22
+ height="3"
23
+ rx="0.5"
24
+ transform="rotate(-90 9 18)"
25
+ fill="currentColor"
26
+ />
27
+ <rect
28
+ x="5"
29
+ y="18"
30
+ width="12"
31
+ height="3"
32
+ rx="0.5"
33
+ transform="rotate(-90 5 18)"
34
+ fill="currentColor"
35
+ />
36
+ <path
37
+ fillRule="evenodd"
38
+ clipRule="evenodd"
39
+ d="M15 11L13.99 11C13.7265 11.0026 13.4747 11.1092 13.2893 11.2964C13.104 11.4837 13 11.7365 13 12C13 12.556 13.444 13 13.99 13L15 13L15 14C15 14.2652 15.1054 14.5196 15.2929 14.7071C15.4804 14.8946 15.7348 15 16 15C16.2652 15 16.5196 14.8946 16.7071 14.7071C16.8946 14.5196 17 14.2652 17 14L17 13L18.01 13C18.2735 12.9974 18.5253 12.8908 18.7107 12.7036C18.896 12.5163 19 12.2635 19 12C19 11.444 18.556 11 18.01 11L17 11L17 10C17 9.73478 16.8946 9.48043 16.7071 9.29289C16.5196 9.10536 16.2652 9 16 9C15.7348 9 15.4804 9.10536 15.2929 9.29289C15.1054 9.48043 15 9.73478 15 10L15 11Z"
40
+ fill="currentColor"
41
+ />
42
+ </svg>
43
+ );
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+
3
+ import { token } from '@atlaskit/tokens';
4
+
5
+ export const AddRowAboveIcon = () => (
6
+ <svg
7
+ width="24"
8
+ height="24"
9
+ viewBox="0 0 24 24"
10
+ fill="none"
11
+ xmlns="http://www.w3.org/2000/svg"
12
+ >
13
+ <rect
14
+ width="24"
15
+ height="24"
16
+ fill={token('color.border.inverse', '#FFFFFF')}
17
+ fillOpacity="0.01"
18
+ />
19
+ <mask
20
+ id="path-1-inside-1_896_17822"
21
+ fill={token('color.border.inverse', '#FFFFFF')}
22
+ >
23
+ <rect x="6" y="12" width="12" height="8" rx="0.5" />
24
+ </mask>
25
+ <rect
26
+ x="6"
27
+ y="12"
28
+ width="12"
29
+ height="8"
30
+ rx="0.5"
31
+ stroke="currentColor"
32
+ strokeWidth="4"
33
+ mask="url(#path-1-inside-1_896_17822)"
34
+ />
35
+ <path
36
+ fillRule="evenodd"
37
+ clipRule="evenodd"
38
+ d="M13 7V5.99C12.9974 5.72652 12.8908 5.47473 12.7036 5.28935C12.5163 5.10397 12.2635 4.99999 12 5C11.444 5 11 5.444 11 5.99V7H10C9.73478 7 9.48043 7.10536 9.29289 7.29289C9.10536 7.48043 9 7.73478 9 8C9 8.26522 9.10536 8.51957 9.29289 8.70711C9.48043 8.89464 9.73478 9 10 9H11V10.01C11.0026 10.2735 11.1092 10.5253 11.2964 10.7107C11.4837 10.896 11.7365 11 12 11C12.556 11 13 10.556 13 10.01V9H14C14.2652 9 14.5196 8.89464 14.7071 8.70711C14.8946 8.51957 15 8.26522 15 8C15 7.73478 14.8946 7.48043 14.7071 7.29289C14.5196 7.10536 14.2652 7 14 7H13Z"
39
+ fill="currentColor"
40
+ />
41
+ </svg>
42
+ );