@atlaskit/editor-plugin-table 5.3.13 → 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 (95) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/plugins/table/event-handlers.js +6 -3
  3. package/dist/cjs/plugins/table/index.js +4 -3
  4. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  5. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -0
  7. package/dist/cjs/plugins/table/types.js +9 -2
  8. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +5 -3
  9. package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +57 -9
  10. package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
  11. package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +13 -4
  12. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +44 -5
  13. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +6 -4
  14. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +35 -13
  15. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +2 -0
  16. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  17. package/dist/cjs/plugins/table/ui/ui-styles.js +27 -24
  18. package/dist/cjs/plugins/table/utils/dom.js +12 -4
  19. package/dist/cjs/plugins/table/utils/index.js +12 -0
  20. package/dist/es2019/plugins/table/event-handlers.js +5 -4
  21. package/dist/es2019/plugins/table/index.js +4 -3
  22. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  23. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  24. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +12 -0
  25. package/dist/es2019/plugins/table/types.js +9 -2
  26. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +5 -3
  27. package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +58 -7
  28. package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
  29. package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +10 -4
  30. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +46 -6
  31. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
  32. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +35 -14
  33. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -0
  34. package/dist/es2019/plugins/table/ui/common-styles.js +51 -3
  35. package/dist/es2019/plugins/table/ui/ui-styles.js +23 -1
  36. package/dist/es2019/plugins/table/utils/dom.js +5 -1
  37. package/dist/es2019/plugins/table/utils/index.js +1 -1
  38. package/dist/esm/plugins/table/event-handlers.js +7 -4
  39. package/dist/esm/plugins/table/index.js +4 -3
  40. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +3 -7
  41. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  42. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -0
  43. package/dist/esm/plugins/table/types.js +9 -2
  44. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +5 -3
  45. package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +56 -8
  46. package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
  47. package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +10 -4
  48. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +45 -6
  49. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
  50. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +36 -14
  51. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -0
  52. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  53. package/dist/esm/plugins/table/ui/ui-styles.js +26 -23
  54. package/dist/esm/plugins/table/utils/dom.js +11 -3
  55. package/dist/esm/plugins/table/utils/index.js +1 -1
  56. package/dist/types/plugins/table/types.d.ts +9 -2
  57. package/dist/types/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +5 -1
  58. package/dist/types/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
  59. package/dist/types/plugins/table/ui/FloatingInsertButton/index.d.ts +1 -0
  60. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  61. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
  62. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  63. package/dist/types/plugins/table/utils/dom.d.ts +4 -1
  64. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  65. package/dist/types-ts4.5/plugins/table/types.d.ts +9 -2
  66. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +5 -1
  67. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
  68. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +1 -0
  69. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  70. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
  71. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  72. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +4 -1
  73. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  74. package/package.json +2 -1
  75. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +40 -194
  76. package/src/__tests__/unit/ui/RowDragControls.tsx +9 -11
  77. package/src/plugins/table/event-handlers.ts +15 -3
  78. package/src/plugins/table/index.tsx +3 -2
  79. package/src/plugins/table/pm-plugins/decorations/plugin.ts +2 -9
  80. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -3
  81. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +9 -0
  82. package/src/plugins/table/types.ts +12 -2
  83. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +10 -3
  84. package/src/plugins/table/ui/FloatingInsertButton/InsertButton.tsx +82 -8
  85. package/src/plugins/table/ui/FloatingInsertButton/getPopupOptions.ts +28 -5
  86. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +19 -7
  87. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +47 -3
  88. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +11 -4
  89. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +49 -18
  90. package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -0
  91. package/src/plugins/table/ui/common-styles.ts +57 -2
  92. package/src/plugins/table/ui/ui-styles.ts +27 -1
  93. package/src/plugins/table/utils/dom.ts +11 -4
  94. package/src/plugins/table/utils/index.ts +2 -0
  95. package/tsconfig.app.json +3 -0
@@ -264,8 +264,8 @@ const tablesPlugin = ({
264
264
  insertRowButtonIndex,
265
265
  isHeaderColumnEnabled,
266
266
  isHeaderRowEnabled,
267
- tableWrapperTarget,
268
- isDragAndDropEnabled
267
+ isDragAndDropEnabled,
268
+ tableWrapperTarget
269
269
  } = tablePluginState;
270
270
  const {
271
271
  allowControls
@@ -301,6 +301,7 @@ const tablesPlugin = ({
301
301
  insertRowButtonIndex: insertRowButtonIndex,
302
302
  isHeaderColumnEnabled: isHeaderColumnEnabled,
303
303
  isHeaderRowEnabled: isHeaderRowEnabled,
304
+ isDragAndDropEnabled: isDragAndDropEnabled,
304
305
  editorView: editorView,
305
306
  mountPoint: popupsMountPoint,
306
307
  boundariesElement: popupsBoundariesElement,
@@ -329,7 +330,7 @@ const tablesPlugin = ({
329
330
  direction: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuDirection,
330
331
  index: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuIndex,
331
332
  isOpen: !!(dragAndDropState !== null && dragAndDropState !== void 0 && dragAndDropState.isDragMenuOpen) && !isResizing
332
- }), allowControls && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
333
+ }), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
333
334
  editorView: editorView,
334
335
  selection: editorView.state.selection,
335
336
  tableRef: tableRef,
@@ -9,7 +9,7 @@ import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecora
9
9
  export const pluginKey = new PluginKey('tableDecorationsPlugin');
10
10
  export const getDecorations = state => pluginKey.getState(state);
11
11
  export const handleDocOrSelectionChanged = (tr, decorationSet, oldState, newState) => {
12
- var _tableWidthPluginKey$, _tableWidthPluginKey$2, _tr$getMeta;
12
+ var _tableWidthPluginKey$, _tableWidthPluginKey$2;
13
13
  const isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
14
14
  const wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
15
15
  const changedResizing = isResizing !== wasResizing;
@@ -17,7 +17,7 @@ export const handleDocOrSelectionChanged = (tr, decorationSet, oldState, newStat
17
17
  // Remove column controls when resizing and don't add column decoration controls when DnD enabled
18
18
  if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
19
19
  return DecorationSet.empty;
20
- } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing || ((_tr$getMeta = tr.getMeta(tablePluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type) === 'HOVER_CELL') {
20
+ } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
21
21
  return buildColumnControlsDecorations({
22
22
  decorationSet,
23
23
  tr
@@ -38,16 +38,12 @@ export const createPlugin = () => {
38
38
  state: {
39
39
  init: () => DecorationSet.empty,
40
40
  apply: (tr, decorationSet, oldState, newState) => {
41
- var _tablePluginKey$getSt, _tablePluginKey$getSt2;
42
41
  let pluginState = decorationSet;
43
42
  const meta = tr.getMeta(tablePluginKey);
44
- const previousHover = (_tablePluginKey$getSt = tablePluginKey.getState(oldState)) === null || _tablePluginKey$getSt === void 0 ? void 0 : _tablePluginKey$getSt.hoveredCell;
45
- const newHover = (_tablePluginKey$getSt2 = tablePluginKey.getState(newState)) === null || _tablePluginKey$getSt2 === void 0 ? void 0 : _tablePluginKey$getSt2.hoveredCell;
46
- const changedCellHover = (previousHover === null || previousHover === void 0 ? void 0 : previousHover.colIndex) !== (newHover === null || newHover === void 0 ? void 0 : newHover.colIndex) || (previousHover === null || previousHover === void 0 ? void 0 : previousHover.rowIndex) !== (newHover === null || newHover === void 0 ? void 0 : newHover.rowIndex);
47
43
  if (meta && meta.data && meta.data.decorationSet) {
48
44
  pluginState = meta.data.decorationSet;
49
45
  }
50
- if (tr.docChanged || tr.selectionSet || tr.getMeta(tableWidthPluginKey) || changedCellHover) {
46
+ if (tr.docChanged || tr.selectionSet || tr.getMeta(tableWidthPluginKey)) {
51
47
  pluginState = pluginState.map(tr.mapping, tr.doc);
52
48
  return handleDocOrSelectionChanged(tr, pluginState, oldState, newState);
53
49
  }
@@ -4,7 +4,6 @@ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
4
  import { findTable } from '@atlaskit/editor-tables/utils';
5
5
  import { TableDecorations } from '../../../types';
6
6
  import { createColumnControlsDecoration, createColumnSelectedDecoration, findColumnControlSelectedDecoration, findControlsHoverDecoration, updateDecorations } from '../../../utils/decoration';
7
- import { pluginKey as tablePluginKey } from '../../plugin-key';
8
7
  import { composeDecorations } from './compose-decorations';
9
8
  const isColumnSelected = tr => tr.selection instanceof CellSelection && tr.selection.isColSelection();
10
9
 
@@ -26,10 +25,9 @@ const maybeUpdateColumnControlsDecoration = ({
26
25
  tr
27
26
  }) => {
28
27
  const table = findTable(tr.selection);
29
- const meta = tr.getMeta(tablePluginKey);
30
28
 
31
29
  // avoid re-drawing state if dnd decorations don't need to be updated
32
- if (!table && (meta === null || meta === void 0 ? void 0 : meta.type) !== 'HOVER_CELL') {
30
+ if (!table) {
33
31
  return decorationSet;
34
32
  }
35
33
  return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
@@ -1,6 +1,7 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
3
  import { getCellsInRow } from '@atlaskit/editor-tables/utils';
4
+ import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
4
5
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
5
6
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
6
7
  import { getPluginState as getTablePluginState } from '../plugin-factory';
@@ -83,7 +84,17 @@ export const createPlugin = (dispatch, eventDispatcher) => {
83
84
  // watch for changes
84
85
  return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
85
86
  },
87
+ onDragStart: ({
88
+ location
89
+ }) => {
90
+ autoScroller.start({
91
+ input: location.current.input
92
+ });
93
+ },
86
94
  onDrag(event) {
95
+ autoScroller.updateInput({
96
+ input: event.location.current.input
97
+ });
87
98
  const data = getDraggableDataFromEvent(event);
88
99
  // If no data can be found then it's most like we do not want to perform any drag actions
89
100
  if (!data) {
@@ -101,6 +112,7 @@ export const createPlugin = (dispatch, eventDispatcher) => {
101
112
  setDropTarget(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
102
113
  },
103
114
  onDrop(event) {
115
+ autoScroller.stop();
104
116
  const data = getDraggableDataFromEvent(event);
105
117
 
106
118
  // If no data can be found then it's most like we do not want to perform any drop action
@@ -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`,
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { Popup } from '@atlaskit/editor-common/ui';
3
3
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
4
  import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
5
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
5
6
  import { dragMenuDropdownWidth } from '../consts';
6
7
  import { DragMenu } from './DragMenu';
7
8
  const FloatingDragMenu = ({
@@ -24,10 +25,11 @@ const FloatingDragMenu = ({
24
25
  if (!targetCellRef) {
25
26
  return null;
26
27
  }
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];
28
30
  // TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
29
31
  return /*#__PURE__*/React.createElement(Popup, {
30
- alignX: "left",
32
+ alignX: direction === 'row' ? 'left' : 'center',
31
33
  alignY: "top",
32
34
  target: targetCellRef,
33
35
  mountTo: mountPoint,
@@ -39,7 +41,7 @@ const FloatingDragMenu = ({
39
41
  ,
40
42
  zIndex: akEditorFloatingOverlapPanelZIndex,
41
43
  forcePlacement: true,
42
- offset: [7, 0],
44
+ offset: offset,
43
45
  stick: true
44
46
  }, /*#__PURE__*/React.createElement(DragMenu, {
45
47
  editorView: editorView,
@@ -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,16 +39,65 @@ 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,
49
- direction,
100
+ type,
50
101
  intl: {
51
102
  formatMessage
52
103
  },
@@ -54,8 +105,8 @@ const InsertButton = ({
54
105
  }) => {
55
106
  const content = /*#__PURE__*/React.createElement(Tooltip, {
56
107
  content: /*#__PURE__*/React.createElement(ToolTipContent, {
57
- description: formatMessage(tooltipMessageByType(direction)),
58
- keymap: direction === 'row' ? addRowAfter : addColumnAfter
108
+ description: formatMessage(tooltipMessageByType(type)),
109
+ keymap: type === 'row' ? addRowAfter : addColumnAfter
59
110
  }),
60
111
  position: "top"
61
112
  }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
@@ -72,13 +123,13 @@ const InsertButton = ({
72
123
  fillRule: "evenodd"
73
124
  })))), /*#__PURE__*/React.createElement("div", {
74
125
  className: ClassName.CONTROLS_INSERT_LINE,
75
- style: direction === 'row' ? {
126
+ style: type === 'row' ? {
76
127
  width: getInsertLineWidth(tableRef)
77
128
  } : {
78
129
  height: getInsertLineHeight(tableRef, hasStickyHeaders)
79
130
  }
80
131
  })));
81
- const floatingButtonClassName = direction === 'column' ? ClassName.CONTROLS_FLOATING_BUTTON_COLUMN : ClassName.CONTROLS_FLOATING_BUTTON_ROW;
132
+ const floatingButtonClassName = type === 'column' ? ClassName.CONTROLS_FLOATING_BUTTON_COLUMN : ClassName.CONTROLS_FLOATING_BUTTON_ROW;
82
133
  return /*#__PURE__*/React.createElement("div", {
83
134
  className: floatingButtonClassName
84
135
  }, /*#__PURE__*/React.createElement("div", {
@@ -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(direction, index, hasNumberedColumns, tableContainer) {
80
+ function getPopupOptions(direction, index, hasNumberedColumns, isDragAndDropEnabled, tableContainer) {
79
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,10 +112,15 @@ 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
- direction: type,
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, {
123
+ type: type,
118
124
  tableRef: tableRef,
119
125
  onMouseDown: type === 'column' ? this.insertColumn : this.insertRow,
120
126
  hasStickyHeaders: this.props.hasStickyHeaders || false
@@ -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,
@@ -5,7 +5,7 @@ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
5
5
  import { clearHoverSelection } from '../../../commands';
6
6
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
7
7
  import { TableCssClassName as ClassName } from '../../../types';
8
- import { getRowHeights, getSelectedRowIndexes } from '../../../utils';
8
+ import { getRowHeights, getRowsParams, getSelectedRowIndexes } from '../../../utils';
9
9
  import { DragHandle } from '../../DragHandle';
10
10
  const getSelectedRows = selection => {
11
11
  if (selection instanceof CellSelection && selection.isRowSelection()) {
@@ -24,12 +24,15 @@ const DragControlsComponent = ({
24
24
  tableActive,
25
25
  editorView,
26
26
  isInDanger,
27
+ isResizing,
28
+ hasHeaderRow,
27
29
  hoverRows,
28
30
  selectRow,
29
31
  updateCellHoverLocation
30
32
  }) => {
31
33
  var _tableNode$attrs$loca, _tableNode$attrs;
32
34
  const rowHeights = getRowHeights(tableRef);
35
+ const rowsParams = getRowsParams(rowHeights);
33
36
  const heights = rowHeights.map(height => `${height - 1}px`).join(' ');
34
37
  const selectedRowIndexes = getSelectedRows(editorView.state.selection);
35
38
  const rowWidth = tableRef.offsetWidth;
@@ -54,18 +57,15 @@ const DragControlsComponent = ({
54
57
  }
55
58
  }, [editorView, tableActive]);
56
59
  const handleMouseMove = useCallback(e => {
57
- // avoid updating if event target is drag handle
58
- if (!e.nativeEvent.target.classList.contains(ClassName.ROW_CONTROLS_WITH_DRAG)) {
60
+ const isParentDragControls = e.nativeEvent.target.closest(`.${ClassName.DRAG_ROW_CONTROLS}`);
61
+ const rowIndex = e.nativeEvent.target.getAttribute('data-start-index');
62
+
63
+ // avoid updating if event target is not related
64
+ if (!isParentDragControls || !rowIndex) {
59
65
  return;
60
66
  }
61
- const hoverHeight = e.nativeEvent.offsetY;
62
- let totalHeight = 0;
63
- const rowIndex = rowHeights.findIndex(row => {
64
- totalHeight += row;
65
- return hoverHeight <= totalHeight;
66
- });
67
- updateCellHoverLocation(rowIndex);
68
- }, [updateCellHoverLocation, rowHeights]);
67
+ updateCellHoverLocation(Number(rowIndex));
68
+ }, [updateCellHoverLocation]);
69
69
  const handleMouseOver = useCallback(() => {
70
70
  hoverRows([rowIndex]);
71
71
  }, [hoverRows, rowIndex]);
@@ -73,19 +73,40 @@ const DragControlsComponent = ({
73
73
  selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
74
74
  }, [rowIndex, selectRow]);
75
75
  return /*#__PURE__*/React.createElement("div", {
76
- className: ClassName.ROW_CONTROLS_WITH_DRAG,
76
+ className: ClassName.DRAG_ROW_CONTROLS,
77
77
  style: {
78
78
  gridTemplateRows: heights
79
79
  },
80
80
  onMouseMove: handleMouseMove
81
- }, Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
81
+ }, !isResizing && rowsParams.map(({
82
+ startIndex,
83
+ endIndex
84
+ }, index) => /*#__PURE__*/React.createElement("div", {
85
+ style: {
86
+ gridRow: `${index + 1} / span 1`
87
+ },
88
+ "data-start-index": startIndex,
89
+ "data-end-index": endIndex,
90
+ className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER,
91
+ contentEditable: false,
92
+ key: index
93
+ }, !hasHeaderRow && index === 0 && /*#__PURE__*/React.createElement("div", {
94
+ style: {
95
+ top: '0px',
96
+ left: "var(--ds-space-075, 6px)"
97
+ },
98
+ className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT
99
+ }), /*#__PURE__*/React.createElement("div", {
100
+ className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT
101
+ }))), !isResizing && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
82
102
  style: {
83
103
  gridRow: gridRowPosition,
84
104
  display: 'flex',
85
105
  height: '100%',
86
106
  alignItems: 'center',
87
107
  justifyContent: 'center'
88
- }
108
+ },
109
+ "data-testid": "table-floating-row-drag-handle"
89
110
  }, /*#__PURE__*/React.createElement(DragHandle, {
90
111
  tableLocalId: (_tableNode$attrs$loca = tableNode === null || tableNode === void 0 ? void 0 : (_tableNode$attrs = tableNode.attrs) === null || _tableNode$attrs === void 0 ? void 0 : _tableNode$attrs.localId) !== null && _tableNode$attrs$loca !== void 0 ? _tableNode$attrs$loca : '',
91
112
  indexes: [rowIndex],
@@ -144,6 +144,8 @@ export default class TableFloatingControls extends Component {
144
144
  editorView: editorView,
145
145
  tableActive: tableActive,
146
146
  isInDanger: isInDanger,
147
+ isResizing: isResizing,
148
+ hasHeaderRow: hasHeaderRow,
147
149
  hoverRows: this.hoverRows,
148
150
  selectRow: this.selectRow,
149
151
  updateCellHoverLocation: this.updateCellHoverLocation