@atlaskit/editor-plugin-table 5.3.12 → 5.3.14

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 (155) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/plugins/table/event-handlers.js +6 -3
  3. package/dist/cjs/plugins/table/index.js +16 -2
  4. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
  5. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  6. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  7. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  8. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +22 -1
  9. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +54 -7
  10. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +6 -0
  11. package/dist/cjs/plugins/table/types.js +9 -2
  12. package/dist/cjs/plugins/table/ui/DragHandle/index.js +2 -0
  13. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +80 -0
  14. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +62 -0
  15. package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +52 -4
  16. package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +10 -8
  17. package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +12 -3
  18. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +44 -5
  19. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +6 -4
  20. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +44 -20
  21. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -0
  22. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  23. package/dist/cjs/plugins/table/ui/consts.js +3 -2
  24. package/dist/cjs/plugins/table/ui/ui-styles.js +27 -24
  25. package/dist/cjs/plugins/table/utils/dom.js +12 -4
  26. package/dist/cjs/plugins/table/utils/drag-menu.js +59 -0
  27. package/dist/cjs/plugins/table/utils/index.js +12 -0
  28. package/dist/es2019/plugins/table/event-handlers.js +5 -4
  29. package/dist/es2019/plugins/table/index.js +16 -2
  30. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
  31. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  32. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  33. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  34. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +20 -0
  35. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +54 -3
  36. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +7 -0
  37. package/dist/es2019/plugins/table/types.js +9 -2
  38. package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -0
  39. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +77 -0
  40. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +56 -0
  41. package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +53 -2
  42. package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +10 -8
  43. package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +9 -3
  44. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +46 -6
  45. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
  46. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +45 -22
  47. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +4 -0
  48. package/dist/es2019/plugins/table/ui/common-styles.js +51 -3
  49. package/dist/es2019/plugins/table/ui/consts.js +2 -1
  50. package/dist/es2019/plugins/table/ui/ui-styles.js +23 -1
  51. package/dist/es2019/plugins/table/utils/dom.js +5 -1
  52. package/dist/es2019/plugins/table/utils/drag-menu.js +44 -0
  53. package/dist/es2019/plugins/table/utils/index.js +1 -1
  54. package/dist/esm/plugins/table/event-handlers.js +7 -4
  55. package/dist/esm/plugins/table/index.js +16 -2
  56. package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
  57. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  58. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  59. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
  60. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +21 -0
  61. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +54 -7
  62. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +6 -0
  63. package/dist/esm/plugins/table/types.js +9 -2
  64. package/dist/esm/plugins/table/ui/DragHandle/index.js +2 -0
  65. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +73 -0
  66. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +55 -0
  67. package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +51 -3
  68. package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +10 -8
  69. package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +9 -3
  70. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +45 -6
  71. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
  72. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -22
  73. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +4 -0
  74. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  75. package/dist/esm/plugins/table/ui/consts.js +2 -1
  76. package/dist/esm/plugins/table/ui/ui-styles.js +26 -23
  77. package/dist/esm/plugins/table/utils/dom.js +11 -3
  78. package/dist/esm/plugins/table/utils/drag-menu.js +52 -0
  79. package/dist/esm/plugins/table/utils/index.js +1 -1
  80. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +8 -1
  81. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +2 -1
  82. package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +4 -0
  83. package/dist/types/plugins/table/types.d.ts +10 -2
  84. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +4 -2
  85. package/dist/types/plugins/table/ui/DragPreview/index.d.ts +2 -1
  86. package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +2 -1
  87. package/dist/types/plugins/table/ui/FloatingDeleteButton/types.d.ts +2 -1
  88. package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +19 -0
  89. package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +21 -0
  90. package/dist/types/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +6 -1
  91. package/dist/types/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +2 -1
  92. package/dist/types/plugins/table/ui/FloatingInsertButton/index.d.ts +5 -5
  93. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  94. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +4 -0
  95. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -0
  96. package/dist/types/plugins/table/ui/consts.d.ts +1 -0
  97. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  98. package/dist/types/plugins/table/utils/dom.d.ts +4 -1
  99. package/dist/types/plugins/table/utils/drag-menu.d.ts +7 -0
  100. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  101. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +8 -1
  102. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +2 -1
  103. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +4 -0
  104. package/dist/types-ts4.5/plugins/table/types.d.ts +10 -2
  105. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +4 -2
  106. package/dist/types-ts4.5/plugins/table/ui/DragPreview/index.d.ts +2 -1
  107. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +2 -1
  108. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/types.d.ts +2 -1
  109. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +19 -0
  110. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +21 -0
  111. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +6 -1
  112. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +2 -1
  113. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +5 -5
  114. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  115. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +4 -0
  116. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -0
  117. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
  118. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  119. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +4 -1
  120. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +7 -0
  121. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  122. package/package.json +3 -2
  123. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +40 -194
  124. package/src/__tests__/unit/ui/RowDragControls.tsx +9 -11
  125. package/src/plugins/table/event-handlers.ts +15 -3
  126. package/src/plugins/table/index.tsx +18 -1
  127. package/src/plugins/table/nodeviews/TableComponent.tsx +2 -1
  128. package/src/plugins/table/pm-plugins/decorations/plugin.ts +2 -9
  129. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -3
  130. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +14 -1
  131. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +32 -1
  132. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +50 -2
  133. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +7 -0
  134. package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +5 -0
  135. package/src/plugins/table/types.ts +14 -2
  136. package/src/plugins/table/ui/DragHandle/index.tsx +5 -1
  137. package/src/plugins/table/ui/DragPreview/index.tsx +2 -1
  138. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +2 -1
  139. package/src/plugins/table/ui/FloatingDeleteButton/types.ts +3 -1
  140. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +99 -0
  141. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +91 -0
  142. package/src/plugins/table/ui/FloatingInsertButton/InsertButton.tsx +79 -4
  143. package/src/plugins/table/ui/FloatingInsertButton/getPopupOptions.ts +31 -7
  144. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +28 -13
  145. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +47 -3
  146. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +11 -4
  147. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +65 -25
  148. package/src/plugins/table/ui/TableFloatingControls/index.tsx +7 -0
  149. package/src/plugins/table/ui/common-styles.ts +57 -2
  150. package/src/plugins/table/ui/consts.ts +2 -0
  151. package/src/plugins/table/ui/ui-styles.ts +27 -1
  152. package/src/plugins/table/utils/dom.ts +11 -4
  153. package/src/plugins/table/utils/drag-menu.ts +65 -0
  154. package/src/plugins/table/utils/index.ts +2 -0
  155. package/tsconfig.app.json +3 -0
@@ -1,8 +1,11 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
+ import { getCellsInRow } from '@atlaskit/editor-tables/utils';
4
+ import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
3
5
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
6
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
5
7
  import { getPluginState as getTablePluginState } from '../plugin-factory';
8
+ import { DragAndDropActionType } from './actions';
6
9
  import { clearDropTarget, moveSource, setDropTarget } from './commands';
7
10
  import { DropTargetType } from './consts';
8
11
  import { createPluginState, getPluginState } from './plugin-factory';
@@ -12,12 +15,49 @@ export const createPlugin = (dispatch, eventDispatcher) => {
12
15
  return new SafePlugin({
13
16
  state: createPluginState(dispatch, state => ({
14
17
  decorationSet: DecorationSet.empty,
15
- // TODO: This is example placeholder state. We could use this to track which row/col is currently set as the drop target
16
- // This would result in a blue highlight being displayed on the corrisponding row/column to single the drop target location.
17
18
  dropTargetType: DropTargetType.NONE,
18
- dropTargetIndex: 0
19
+ dropTargetIndex: 0,
20
+ isDragMenuOpen: false,
21
+ dragMenuIndex: 0
19
22
  })),
20
23
  key: pluginKey,
24
+ appendTransaction: (transactions, oldState, newState) => {
25
+ const {
26
+ targetCellPosition: oldTargetCellPosition
27
+ } = getTablePluginState(oldState);
28
+ const {
29
+ targetCellPosition: newTargetCellPosition
30
+ } = getTablePluginState(newState);
31
+ const {
32
+ isDragMenuOpen,
33
+ dragMenuIndex
34
+ } = getPluginState(newState);
35
+
36
+ // What's happening here? you asked... In a nutshell;
37
+ // 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.
38
+ // This will stop the drag menu from moving around the screen to different row/cols. Too achieve this we need
39
+ // to check if the new target cell position is pointed at a different cell than what the drag menu was opened on.
40
+ if (oldTargetCellPosition !== newTargetCellPosition) {
41
+ if (isDragMenuOpen) {
42
+ const tr = newState.tr;
43
+ const action = {
44
+ type: DragAndDropActionType.TOGGLE_DRAG_MENU,
45
+ data: {
46
+ isDragMenuOpen: false,
47
+ direction: undefined
48
+ }
49
+ };
50
+ if (newTargetCellPosition !== undefined) {
51
+ const cells = getCellsInRow(dragMenuIndex)(tr.selection);
52
+ if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition)) {
53
+ return tr.setMeta(pluginKey, action);
54
+ } // else NOP
55
+ } else {
56
+ return tr.setMeta(pluginKey, action);
57
+ }
58
+ }
59
+ }
60
+ },
21
61
  view: editorView => {
22
62
  return {
23
63
  destroy: monitorForElements({
@@ -44,7 +84,17 @@ export const createPlugin = (dispatch, eventDispatcher) => {
44
84
  // watch for changes
45
85
  return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
46
86
  },
87
+ onDragStart: ({
88
+ location
89
+ }) => {
90
+ autoScroller.start({
91
+ input: location.current.input
92
+ });
93
+ },
47
94
  onDrag(event) {
95
+ autoScroller.updateInput({
96
+ input: event.location.current.input
97
+ });
48
98
  const data = getDraggableDataFromEvent(event);
49
99
  // If no data can be found then it's most like we do not want to perform any drag actions
50
100
  if (!data) {
@@ -62,6 +112,7 @@ export const createPlugin = (dispatch, eventDispatcher) => {
62
112
  setDropTarget(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
63
113
  },
64
114
  onDrop(event) {
115
+ autoScroller.stop();
65
116
  const data = getDraggableDataFromEvent(event);
66
117
 
67
118
  // If no data can be found then it's most like we do not want to perform any drop action
@@ -16,6 +16,13 @@ export default ((pluginState, action) => {
16
16
  dropTargetType: DropTargetType.NONE,
17
17
  dropTargetIndex: 0
18
18
  };
19
+ case DragAndDropActionType.TOGGLE_DRAG_MENU:
20
+ return {
21
+ ...pluginState,
22
+ isDragMenuOpen: action.data.isDragMenuOpen,
23
+ dragMenuDirection: action.data.direction,
24
+ dragMenuIndex: action.data.index
25
+ };
19
26
  default:
20
27
  return pluginState;
21
28
  }
@@ -66,6 +66,9 @@ export const TableCssClassName = {
66
66
  CONTROLS_INSERT_LINE: `${tablePrefixSelector}-controls__insert-line`,
67
67
  CONTROLS_BUTTON_OVERLAY: `${tablePrefixSelector}-controls__button-overlay`,
68
68
  LAYOUT_BUTTON: `${tablePrefixSelector}-layout-button`,
69
+ DRAG_CONTROLS_INSERT_BUTTON: `${tablePrefixSelector}-controls__drag-insert-button`,
70
+ DRAG_CONTROLS_INSERT_BUTTON_INNER: `${tablePrefixSelector}-controls__drag-insert-button-inner`,
71
+ DRAG_CONTROLS_INSERT_BUTTON_WRAP: `${tablePrefixSelector}-controls__drag-insert-button-wrap`,
69
72
  CONTROLS_INSERT_MARKER: `${tablePrefixSelector}-controls__insert-marker`,
70
73
  CONTROLS_INSERT_COLUMN: `${tablePrefixSelector}-controls__insert-column`,
71
74
  CONTROLS_INSERT_ROW: `${tablePrefixSelector}-controls__insert-row`,
@@ -78,8 +81,12 @@ export const TableCssClassName = {
78
81
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
79
82
  CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
80
83
  /** Controls with drag handle */
81
- COLUMN_CONTROLS_WITH_DRAG: `${tablePrefixSelector}-column-controls-with-drag`,
82
- ROW_CONTROLS_WITH_DRAG: `${tablePrefixSelector}-row-controls-with-drag`,
84
+ DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
85
+ DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
86
+ DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,
87
+ DRAG_COLUMN_CONTROLS: `${tablePrefixSelector}-drag-column-controls`,
88
+ DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-columns-floating-insert-dot-wrapper`,
89
+ DRAG_COLUMN_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-columns-floating-insert-dot`,
83
90
  DRAG_HANDLE_BUTTON_CONTAINER: `${tablePrefixSelector}-drag-handle-button-container`,
84
91
  /** Other classes */
85
92
  NUMBERED_COLUMN: `${tablePrefixSelector}-numbered-column`,
@@ -15,6 +15,7 @@ export const DragHandle = ({
15
15
  previewHeight,
16
16
  onMouseOver,
17
17
  onMouseOut,
18
+ onMouseUp,
18
19
  onClick
19
20
  }) => {
20
21
  const dragHandleDivRef = useRef(null);
@@ -73,6 +74,7 @@ export const DragHandle = ({
73
74
  "data-testid": "table-floating-column-controls-drag-handle",
74
75
  onMouseOver: onMouseOver,
75
76
  onMouseOut: onMouseOut,
77
+ onMouseUp: onMouseUp,
76
78
  onClick: onClick
77
79
  }, /*#__PURE__*/React.createElement(DragHandleIcon, null), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
78
80
  direction: direction,
@@ -0,0 +1,77 @@
1
+ import React from 'react';
2
+ import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
3
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
4
+ import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
5
+ import { getDragMenuConfig } from '../../utils/drag-menu';
6
+ import { dragMenuDropdownWidth } from '../consts';
7
+ const convertToDropdownItems = dragMenuConfig => {
8
+ let menuItems = [];
9
+ let menuCallback = {};
10
+ dragMenuConfig.forEach(item => {
11
+ menuItems.push({
12
+ key: item.id,
13
+ content: item.title,
14
+ value: {
15
+ name: item.id
16
+ },
17
+ isDisabled: item.disabled
18
+ });
19
+ item.onClick && (menuCallback[item.id] = item.onClick);
20
+ });
21
+ return {
22
+ menuItems,
23
+ menuCallback
24
+ };
25
+ };
26
+ export const DragMenu = ({
27
+ direction = 'row',
28
+ index,
29
+ isOpen,
30
+ editorView,
31
+ tableNode,
32
+ mountPoint,
33
+ boundariesElement,
34
+ scrollableElement
35
+ }) => {
36
+ const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
37
+ const dragMenuConfig = getDragMenuConfig(direction, tableMap, index);
38
+ const {
39
+ menuItems,
40
+ menuCallback
41
+ } = convertToDropdownItems(dragMenuConfig);
42
+ const closeMenu = () => {
43
+ const {
44
+ state,
45
+ dispatch
46
+ } = editorView;
47
+ toggleDragMenu(false)(state, dispatch);
48
+ };
49
+ const onMenuItemActivated = ({
50
+ item
51
+ }) => {
52
+ var _menuCallback$item$va;
53
+ (_menuCallback$item$va = menuCallback[item.value.name]) === null || _menuCallback$item$va === void 0 ? void 0 : _menuCallback$item$va.call(menuCallback, editorView.state, editorView.dispatch);
54
+ closeMenu();
55
+ };
56
+ if (!menuItems) {
57
+ return null;
58
+ }
59
+ return /*#__PURE__*/React.createElement(DropdownMenu, {
60
+ mountTo: mountPoint
61
+ //This needs be removed when the a11y is completely handled
62
+ //Disabling key navigation now as it works only partially
63
+ ,
64
+ arrowKeyNavigationProviderOptions: {
65
+ type: ArrowKeyNavigationType.MENU,
66
+ disableArrowKeyNavigation: true
67
+ },
68
+ items: [{
69
+ items: menuItems
70
+ }],
71
+ isOpen: isOpen,
72
+ onOpenChange: closeMenu,
73
+ onItemActivated: onMenuItemActivated,
74
+ fitWidth: dragMenuDropdownWidth,
75
+ boundariesElement: boundariesElement
76
+ });
77
+ };
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import { Popup } from '@atlaskit/editor-common/ui';
3
+ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
+ import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
5
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
6
+ import { dragMenuDropdownWidth } from '../consts';
7
+ import { DragMenu } from './DragMenu';
8
+ const FloatingDragMenu = ({
9
+ mountPoint,
10
+ boundariesElement,
11
+ scrollableElement,
12
+ editorView,
13
+ isOpen,
14
+ tableRef,
15
+ tableNode,
16
+ direction,
17
+ index,
18
+ targetCellPosition
19
+ }) => {
20
+ if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
21
+ return null;
22
+ }
23
+ const domAtPos = editorView.domAtPos.bind(editorView);
24
+ const targetCellRef = findDomRefAtPos(targetCellPosition, domAtPos);
25
+ if (!targetCellRef) {
26
+ return null;
27
+ }
28
+ const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
29
+ const offset = direction === 'row' ? [7, 0] : index === ((tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) || 1) - 1 ? [14, 0] : [-14, 0];
30
+ // TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
31
+ return /*#__PURE__*/React.createElement(Popup, {
32
+ alignX: direction === 'row' ? 'left' : 'center',
33
+ alignY: "top",
34
+ target: targetCellRef,
35
+ mountTo: mountPoint,
36
+ boundariesElement: boundariesElement,
37
+ scrollableElement: scrollableElement,
38
+ fitWidth: dragMenuDropdownWidth
39
+ // z-index value below is to ensure that this menu is above other floating menu
40
+ // in table, but below floating dialogs like typeaheads, pickers, etc.
41
+ ,
42
+ zIndex: akEditorFloatingOverlapPanelZIndex,
43
+ forcePlacement: true,
44
+ offset: offset,
45
+ stick: true
46
+ }, /*#__PURE__*/React.createElement(DragMenu, {
47
+ editorView: editorView,
48
+ isOpen: isOpen,
49
+ boundariesElement: boundariesElement,
50
+ tableNode: tableNode,
51
+ direction: direction,
52
+ index: index
53
+ }));
54
+ };
55
+ FloatingDragMenu.displayName = 'FloatingDragMenu';
56
+ export default FloatingDragMenu;
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
2
+
1
3
  import React from 'react';
2
4
  import { injectIntl } from 'react-intl-next';
3
5
  import { addColumnAfter, addRowAfter, ToolTipContent } from '@atlaskit/editor-common/keymaps';
@@ -23,7 +25,7 @@ const getToolbarSize = tableRef => {
23
25
  }
24
26
  return tableToolbarSize;
25
27
  };
26
- const getInsertLineWidth = tableRef => {
28
+ const getInsertLineWidth = (tableRef, isDragAndDropEnabled) => {
27
29
  // The line gets width 100% from the table,
28
30
  // but since we have an overflow on the left,
29
31
  // we should add an offset to make up for it.
@@ -37,12 +39,61 @@ const getInsertLineWidth = tableRef => {
37
39
  scrollLeft
38
40
  } = parentElement;
39
41
  const diff = offsetWidth - parentOffsetWidth;
40
- const toolbarSize = getToolbarSize(tableRef);
42
+ const toolbarSize = isDragAndDropEnabled ? 0 : getToolbarSize(tableRef);
41
43
  return Math.min(offsetWidth + toolbarSize, parentOffsetWidth + toolbarSize - Math.max(scrollLeft - diff, 0)) + LINE_OFFSET;
42
44
  };
43
45
  const tooltipMessageByType = type => {
44
46
  return type === 'row' ? tableMessages.insertRow : tableMessages.insertColumn;
45
47
  };
48
+ export const InsertButtonForDragAndDrop = ({
49
+ onMouseDown,
50
+ tableRef,
51
+ type,
52
+ intl: {
53
+ formatMessage
54
+ },
55
+ hasStickyHeaders
56
+ }) => {
57
+ const content = /*#__PURE__*/React.createElement(Tooltip, {
58
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
59
+ description: formatMessage(tooltipMessageByType(type)),
60
+ keymap: type === 'row' ? addRowAfter : addColumnAfter
61
+ }),
62
+ position: "top"
63
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
64
+ className: ClassName.DRAG_CONTROLS_INSERT_BUTTON_INNER
65
+ }, /*#__PURE__*/React.createElement("button", {
66
+ type: "button",
67
+ className: ClassName.DRAG_CONTROLS_INSERT_BUTTON,
68
+ onMouseDown: onMouseDown
69
+ }, /*#__PURE__*/React.createElement("svg", {
70
+ width: "10",
71
+ height: "10",
72
+ viewBox: "0 0 10 10",
73
+ fill: "none",
74
+ xmlns: "http://www.w3.org/2000/svg"
75
+ }, /*#__PURE__*/React.createElement("path", {
76
+ fillRule: "evenodd",
77
+ clipRule: "evenodd",
78
+ d: "M5.41667 4.58333V2.91667C5.41667 2.80616 5.37277 2.70018 5.29463 2.62204C5.21649 2.5439 5.11051 2.5 5 2.5C4.88949 2.5 4.78351 2.5439 4.70537 2.62204C4.62723 2.70018 4.58333 2.80616 4.58333 2.91667V4.58333H2.91667C2.80616 4.58333 2.70018 4.62723 2.62204 4.70537C2.5439 4.78351 2.5 4.88949 2.5 5C2.5 5.11051 2.5439 5.21649 2.62204 5.29463C2.70018 5.37277 2.80616 5.41667 2.91667 5.41667H4.58333V7.08333C4.58333 7.19384 4.62723 7.29982 4.70537 7.37796C4.78351 7.4561 4.88949 7.5 5 7.5C5.11051 7.5 5.21649 7.4561 5.29463 7.37796C5.37277 7.29982 5.41667 7.19384 5.41667 7.08333V5.41667H7.08333C7.19384 5.41667 7.29982 5.37277 7.37796 5.29463C7.4561 5.21649 7.5 5.11051 7.5 5C7.5 4.88949 7.4561 4.78351 7.37796 4.70537C7.29982 4.62723 7.19384 4.58333 7.08333 4.58333H5.41667Z",
79
+ fill: "currentColor"
80
+ })))), /*#__PURE__*/React.createElement("div", {
81
+ className: ClassName.CONTROLS_INSERT_LINE,
82
+ style: type === 'row' ? {
83
+ width: getInsertLineWidth(tableRef, true),
84
+ left: '14px'
85
+ } : {
86
+ height: getInsertLineHeight(tableRef, hasStickyHeaders) - 11
87
+ }
88
+ })));
89
+ const floatingButtonClassName = type === 'column' ? ClassName.CONTROLS_FLOATING_BUTTON_COLUMN : ClassName.CONTROLS_FLOATING_BUTTON_ROW;
90
+ return /*#__PURE__*/React.createElement("div", {
91
+ className: floatingButtonClassName
92
+ }, /*#__PURE__*/React.createElement("div", {
93
+ className: `${ClassName.CONTROLS_INSERT_BUTTON_WRAP} ${ClassName.CONTROLS_INSERT_ROW}`
94
+ }, content));
95
+ };
96
+ export const DragAndDropInsertButton = injectIntl(InsertButtonForDragAndDrop);
46
97
  const InsertButton = ({
47
98
  onMouseDown,
48
99
  tableRef,
@@ -3,9 +3,11 @@ import { tableInsertColumnButtonOffset, tableInsertColumnButtonSize, tableToolba
3
3
  const HORIZONTAL_ALIGN_COLUMN_BUTTON = -(tableInsertColumnButtonSize / 2);
4
4
  const HORIZONTAL_ALIGN_NUMBERED_COLUMN_BUTTON = HORIZONTAL_ALIGN_COLUMN_BUTTON + akEditorTableNumberColumnWidth;
5
5
  const VERTICAL_ALIGN_COLUMN_BUTTON = tableToolbarSize + tableInsertColumnButtonOffset;
6
+ const VERTICAL_ALIGN_COLUMN_BUTTON_DRAG = tableInsertColumnButtonOffset;
6
7
  const HORIZONTAL_ALIGN_ROW_BUTTON = -(tableToolbarSize + tableInsertColumnButtonOffset + tableInsertColumnButtonSize);
8
+ const HORIZONTAL_ALIGN_ROW_BUTTON_DRAG = -18;
7
9
  const VERTICAL_ALIGN_ROW_BUTTON = tableInsertColumnButtonSize / 2;
8
- function getRowOptions(index) {
10
+ function getRowOptions(index, isDragAndDropEnabled) {
9
11
  let defaultOptions = {
10
12
  alignX: 'left',
11
13
  alignY: 'bottom',
@@ -25,16 +27,16 @@ function getRowOptions(index) {
25
27
  return {
26
28
  ...position,
27
29
  // Left position should be always the offset (To place in the correct position even if the table has overflow).
28
- left: HORIZONTAL_ALIGN_ROW_BUTTON
30
+ left: isDragAndDropEnabled ? HORIZONTAL_ALIGN_ROW_BUTTON_DRAG : HORIZONTAL_ALIGN_ROW_BUTTON
29
31
  };
30
32
  }
31
33
  };
32
34
  }
33
- function getColumnOptions(index, tableContainer, hasNumberedColumns) {
35
+ function getColumnOptions(index, tableContainer, hasNumberedColumns, isDragAndDropEnabled) {
34
36
  const options = {
35
37
  alignX: 'end',
36
38
  alignY: 'top',
37
- offset: [HORIZONTAL_ALIGN_COLUMN_BUTTON, VERTICAL_ALIGN_COLUMN_BUTTON],
39
+ offset: [HORIZONTAL_ALIGN_COLUMN_BUTTON, isDragAndDropEnabled ? VERTICAL_ALIGN_COLUMN_BUTTON_DRAG : VERTICAL_ALIGN_COLUMN_BUTTON],
38
40
  // :: (position: PopupPosition) -> PopupPosition
39
41
  // Limit the InsertButton position to the table container
40
42
  // if the left position starts before it
@@ -75,12 +77,12 @@ function getColumnOptions(index, tableContainer, hasNumberedColumns) {
75
77
  }
76
78
  return options;
77
79
  }
78
- function getPopupOptions(type, index, hasNumberedColumns, tableContainer) {
79
- switch (type) {
80
+ function getPopupOptions(direction, index, hasNumberedColumns, isDragAndDropEnabled, tableContainer) {
81
+ switch (direction) {
80
82
  case 'column':
81
- return getColumnOptions(index, tableContainer, hasNumberedColumns);
83
+ return getColumnOptions(index, tableContainer, hasNumberedColumns, isDragAndDropEnabled);
82
84
  case 'row':
83
- return getRowOptions(index);
85
+ return getRowOptions(index, isDragAndDropEnabled);
84
86
  default:
85
87
  return {};
86
88
  }
@@ -14,7 +14,7 @@ import { insertColumnWithAnalytics, insertRowWithAnalytics } from '../../command
14
14
  import { TableCssClassName as ClassName } from '../../types';
15
15
  import { checkIfNumberColumnEnabled } from '../../utils';
16
16
  import getPopupOptions from './getPopupOptions';
17
- import InsertButton from './InsertButton';
17
+ import InsertButton, { DragAndDropInsertButton } from './InsertButton';
18
18
  export class FloatingInsertButton extends React.Component {
19
19
  constructor(props) {
20
20
  super(props);
@@ -32,6 +32,7 @@ export class FloatingInsertButton extends React.Component {
32
32
  boundariesElement,
33
33
  isHeaderColumnEnabled,
34
34
  isHeaderRowEnabled,
35
+ isDragAndDropEnabled,
35
36
  dispatchAnalyticsEvent
36
37
  } = this.props;
37
38
  const type = typeof insertColumnButtonIndex !== 'undefined' ? 'column' : typeof insertRowButtonIndex !== 'undefined' ? 'row' : null;
@@ -111,9 +112,14 @@ export class FloatingInsertButton extends React.Component {
111
112
  scrollableElement: tableWrapper,
112
113
  forcePlacement: true,
113
114
  allowOutOfBounds: true
114
- }, getPopupOptions(type, index, hasNumberedColumns, tableContainerWrapper), {
115
+ }, getPopupOptions(type, index, hasNumberedColumns, !!isDragAndDropEnabled, tableContainerWrapper), {
115
116
  zIndex: zIndex
116
- }), /*#__PURE__*/React.createElement(InsertButton, {
117
+ }), isDragAndDropEnabled ? /*#__PURE__*/React.createElement(DragAndDropInsertButton, {
118
+ type: type,
119
+ tableRef: tableRef,
120
+ onMouseDown: type === 'column' ? this.insertColumn : this.insertRow,
121
+ hasStickyHeaders: this.props.hasStickyHeaders || false
122
+ }) : /*#__PURE__*/React.createElement(InsertButton, {
117
123
  type: type,
118
124
  tableRef: tableRef,
119
125
  onMouseDown: type === 'column' ? this.insertColumn : this.insertRow,
@@ -2,8 +2,9 @@ import React, { useCallback, useMemo } from 'react';
2
2
  import { CellSelection } from '@atlaskit/editor-tables';
3
3
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
4
4
  import { clearHoverSelection, hoverColumns, selectColumn } from '../../../commands';
5
+ import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
5
6
  import { TableCssClassName as ClassName } from '../../../types';
6
- import { getSelectedColumnIndexes } from '../../../utils';
7
+ import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
7
8
  import { DragHandle } from '../../DragHandle';
8
9
  const getSelectedColumns = selection => {
9
10
  if (selection instanceof CellSelection && selection.isColSelection()) {
@@ -25,10 +26,13 @@ export const ColumnControls = ({
25
26
  localId,
26
27
  isInDanger,
27
28
  rowHeights,
28
- colWidths
29
+ colWidths,
30
+ hasHeaderColumn
29
31
  }) => {
30
32
  var _colWidths$map$join, _rowHeights$;
31
33
  const widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(width => width ? `${width - 1}px` : '0px').join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
34
+ // TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
35
+ const columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
32
36
  const colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
33
37
  const selectedColIndexes = getSelectedColumns(editorView.state.selection);
34
38
  const gridColumnPosition = useMemo(() => {
@@ -64,8 +68,15 @@ export const ColumnControls = ({
64
68
  clearHoverSelection()(state, dispatch);
65
69
  }
66
70
  }, [editorView, tableActive]);
71
+ const handleMouseUp = useCallback(() => {
72
+ const {
73
+ state,
74
+ dispatch
75
+ } = editorView;
76
+ toggleDragMenu(undefined, 'column', colIndex)(state, dispatch);
77
+ }, [editorView, colIndex]);
67
78
  return /*#__PURE__*/React.createElement("div", {
68
- className: ClassName.COLUMN_CONTROLS_WITH_DRAG
79
+ className: ClassName.DRAG_COLUMN_CONTROLS
69
80
  }, /*#__PURE__*/React.createElement("div", {
70
81
  className: ClassName.COLUMN_CONTROLS_INNER,
71
82
  "data-testid": "table-floating-column-controls",
@@ -73,10 +84,38 @@ export const ColumnControls = ({
73
84
  gridTemplateColumns: widths,
74
85
  marginTop
75
86
  }
76
- }, tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
87
+ }, !isResizing && columnParams.map(({
88
+ startIndex,
89
+ endIndex
90
+ }, index) => /*#__PURE__*/React.createElement("div", {
91
+ style: {
92
+ gridColumn: `${index + 1} / span 1`
93
+ },
94
+ "data-start-index": startIndex,
95
+ "data-end-index": endIndex,
96
+ className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER,
97
+ contentEditable: false,
98
+ key: index
99
+ }, !hasHeaderColumn && index === 0 && /*#__PURE__*/React.createElement("div", {
100
+ style: {
101
+ left: '0px',
102
+ right: 'unset'
103
+ },
104
+ className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT
105
+ }), /*#__PURE__*/React.createElement("div", {
106
+ className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT,
107
+ style: columnParams.length - 1 === index ? {
108
+ right: '0'
109
+ } : {}
110
+ }))), tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
77
111
  style: {
78
112
  gridColumn: gridColumnPosition,
79
- marginTop: `-15px`
113
+ zIndex: 99,
114
+ display: 'flex',
115
+ width: '100%',
116
+ justifyContent: 'center',
117
+ alignItems: 'center',
118
+ marginTop: "var(--ds-space-negative-025, -2px)"
80
119
  },
81
120
  "data-column-control-index": hoveredCell.colIndex,
82
121
  "data-testid": "table-floating-column-control"
@@ -89,7 +128,8 @@ export const ColumnControls = ({
89
128
  appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
90
129
  onClick: handleClick,
91
130
  onMouseOver: handleMouseOver,
92
- onMouseOut: handleMouseOut
131
+ onMouseOut: handleMouseOut,
132
+ onMouseUp: handleMouseUp
93
133
  }))));
94
134
  };
95
135
  export default ColumnControls;
@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
4
  import { TableCssClassName as ClassName } from '../../types';
5
- import { getColumnsWidths, getRowHeights } from '../../utils';
5
+ import { containsHeaderColumn, getColumnsWidths, getRowHeights } from '../../utils';
6
6
  import { ColumnControls } from './ColumnControls';
7
7
  import { ColumnDropTargets } from './ColumnDropTargets';
8
8
  export const TableFloatingColumnControls = ({
@@ -24,6 +24,7 @@ export const TableFloatingColumnControls = ({
24
24
  const [hasDropTargets, setHasDropTargets] = useState(false);
25
25
  const node = getNode();
26
26
  const currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
27
+ const hasHeaderColumn = containsHeaderColumn(node);
27
28
  useEffect(() => {
28
29
  var _window;
29
30
  if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
@@ -76,11 +77,11 @@ export const TableFloatingColumnControls = ({
76
77
  const colWidths = getColumnsWidths(editorView);
77
78
  const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
78
79
  const mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
80
+ if (!tableActive) {
81
+ return null;
82
+ }
79
83
  return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement("div", {
80
84
  className: ClassName.COLUMN_CONTROLS_WRAPPER,
81
- style: {
82
- pointerEvents: 'none'
83
- },
84
85
  "data-testid": "table-floating-column-controls-wrapper"
85
86
  }, /*#__PURE__*/React.createElement(ColumnControls, {
86
87
  editorView: editorView,
@@ -92,7 +93,8 @@ export const TableFloatingColumnControls = ({
92
93
  localId: currentNodeLocalId,
93
94
  isInDanger: isInDanger,
94
95
  rowHeights: rowHeights,
95
- colWidths: colWidths
96
+ colWidths: colWidths,
97
+ hasHeaderColumn: hasHeaderColumn
96
98
  }), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
97
99
  tableRef: tableRef,
98
100
  stickyTop: tableActive ? stickyTop : undefined,