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