@atlaskit/editor-plugin-table 5.3.6 → 5.3.7

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 (26) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/table/ui/DragHandle/index.js +49 -3
  3. package/dist/cjs/plugins/table/ui/DragPreview/index.js +1 -1
  4. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -2
  5. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +1 -1
  6. package/dist/es2019/plugins/table/ui/DragHandle/index.js +46 -4
  7. package/dist/es2019/plugins/table/ui/DragPreview/index.js +1 -1
  8. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -2
  9. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +1 -1
  10. package/dist/esm/plugins/table/ui/DragHandle/index.js +49 -4
  11. package/dist/esm/plugins/table/ui/DragPreview/index.js +1 -1
  12. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -2
  13. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +1 -1
  14. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +3 -1
  15. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +3 -1
  16. package/package.json +2 -2
  17. package/src/plugins/table/ui/DragHandle/index.tsx +44 -2
  18. package/src/plugins/table/ui/DragPreview/index.tsx +1 -1
  19. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +5 -2
  20. package/src/plugins/table/ui/TableFloatingControls/index.tsx +1 -1
  21. /package/dist/cjs/plugins/table/ui/{Icons → icons}/DragInMotionIcon.js +0 -0
  22. /package/dist/es2019/plugins/table/ui/{Icons → icons}/DragInMotionIcon.js +0 -0
  23. /package/dist/esm/plugins/table/ui/{Icons → icons}/DragInMotionIcon.js +0 -0
  24. /package/dist/types/plugins/table/ui/{Icons → icons}/DragInMotionIcon.d.ts +0 -0
  25. /package/dist/types-ts4.5/plugins/table/ui/{Icons → icons}/DragInMotionIcon.d.ts +0 -0
  26. /package/src/plugins/table/ui/{Icons → icons}/DragInMotionIcon.tsx +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.3.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#41918](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41918) [`a82ee707d1d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a82ee707d1d) - [ux] ED-20495: Added table row drag preview
8
+
3
9
  ## 5.3.6
4
10
 
5
11
  ### Patch Changes
@@ -1,14 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.DragHandle = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
8
10
  var _react = _interopRequireWildcard(require("react"));
11
+ var _reactDom = _interopRequireDefault(require("react-dom"));
9
12
  var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
13
+ var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview");
10
14
  var _colors = require("@atlaskit/theme/colors");
11
15
  var _types = require("../../types");
16
+ var _DragPreview = require("../DragPreview");
12
17
  var _DragHandleIcon = require("../icons/DragHandleIcon");
13
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
19
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -32,11 +37,17 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
32
37
  _ref$state = _ref.state,
33
38
  state = _ref$state === void 0 ? 'default' : _ref$state,
34
39
  indexes = _ref.indexes,
40
+ previewWidth = _ref.previewWidth,
41
+ previewHeight = _ref.previewHeight,
35
42
  onClick = _ref.onClick,
36
43
  onMouseOver = _ref.onMouseOver,
37
44
  onMouseOut = _ref.onMouseOut;
38
45
  var dragHandleDivRef = (0, _react.useRef)(null);
39
46
  var iconProps = mapStateToProps(state);
47
+ var _useState = (0, _react.useState)(null),
48
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
49
+ previewContainer = _useState2[0],
50
+ setPreviewContainer = _useState2[1];
40
51
  (0, _react.useEffect)(function () {
41
52
  var dragHandleDivRefCurrent = dragHandleDivRef.current;
42
53
  if (dragHandleDivRefCurrent) {
@@ -48,15 +59,50 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
48
59
  type: "table-".concat(direction),
49
60
  indexes: indexes
50
61
  };
62
+ },
63
+ onGenerateDragPreview: function onGenerateDragPreview(_ref2) {
64
+ var nativeSetDragImage = _ref2.nativeSetDragImage;
65
+ (0, _setCustomNativeDragPreview.setCustomNativeDragPreview)({
66
+ getOffset: function getOffset(_ref3) {
67
+ var container = _ref3.container;
68
+ var rect = container.getBoundingClientRect();
69
+ if (direction === 'row') {
70
+ return {
71
+ x: 16,
72
+ y: 16
73
+ };
74
+ } else {
75
+ return {
76
+ x: rect.width / 2 + 16,
77
+ y: 16
78
+ };
79
+ }
80
+ },
81
+ render: function render(_ref4) {
82
+ var container = _ref4.container;
83
+ setPreviewContainer(container);
84
+ return function () {
85
+ return setPreviewContainer(null);
86
+ };
87
+ },
88
+ nativeSetDragImage: nativeSetDragImage
89
+ });
51
90
  }
52
91
  });
53
92
  }
54
93
  }, [tableLocalId, direction, indexes]);
55
94
  return /*#__PURE__*/_react.default.createElement("button", {
56
95
  className: _types.TableCssClassName.DRAG_HANDLE_BUTTON_CONTAINER,
96
+ ref: dragHandleDivRef,
57
97
  style: {
98
+ backgroundColor: "var(--ds-surface, white)",
99
+ borderRadius: '4px',
100
+ border: "2px solid ".concat("var(--ds-surface, white)"),
58
101
  transform: direction === 'column' ? 'none' : 'rotate(90deg)'
59
- },
60
- ref: dragHandleDivRef
61
- }, /*#__PURE__*/_react.default.createElement(_DragHandleIcon.DragHandleIcon, iconProps));
102
+ }
103
+ }, /*#__PURE__*/_react.default.createElement(_DragHandleIcon.DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/_react.default.createElement(_DragPreview.DragPreview, {
104
+ direction: direction,
105
+ width: previewWidth,
106
+ height: previewHeight
107
+ }), previewContainer));
62
108
  };
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.DragPreview = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _primitives = require("@atlaskit/primitives");
10
- var _DragInMotionIcon = require("../Icons/DragInMotionIcon");
10
+ var _DragInMotionIcon = require("../icons/DragInMotionIcon");
11
11
  var boxStyles = (0, _primitives.xcss)({
12
12
  borderColor: 'color.border.focused',
13
13
  borderStyle: 'solid',
@@ -22,6 +22,7 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
22
22
  var heights = rowHeights.map(function (height, index) {
23
23
  return "".concat(height - 1, "px");
24
24
  }).join(' ');
25
+ var rowWidth = tableRef.offsetWidth;
25
26
  var _onClick = function onClick(index, event) {};
26
27
  var onMouseOver = function onMouseOver() {};
27
28
  var onMouseOut = function onMouseOut() {};
@@ -36,7 +37,7 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
36
37
  style: {
37
38
  gridTemplateRows: heights
38
39
  }
39
- }, Number.isFinite(rowIndex) && /*#__PURE__*/_react.default.createElement("div", {
40
+ }, rowIndex !== undefined && Number.isFinite(rowIndex) && /*#__PURE__*/_react.default.createElement("div", {
40
41
  style: {
41
42
  gridRow: "".concat(rowIndex + 1, " / span 1"),
42
43
  display: 'flex'
@@ -48,7 +49,9 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
48
49
  onMouseOver: onMouseOver,
49
50
  onMouseOut: onMouseOut,
50
51
  tableLocalId: getLocalId(),
51
- indexes: []
52
+ indexes: [rowIndex],
53
+ previewWidth: rowWidth,
54
+ previewHeight: rowHeights[rowIndex]
52
55
  })));
53
56
  };
54
57
  var DragControls = exports.DragControls = (0, _reactIntlNext.injectIntl)(DragControlsComponent);
@@ -147,7 +147,7 @@ var TableFloatingControls = exports.default = /*#__PURE__*/function (_Component)
147
147
  var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
148
148
  return /*#__PURE__*/_react.default.createElement("div", {
149
149
  onMouseDown: function onMouseDown(e) {
150
- return e.preventDefault();
150
+ return !isDragAndDropEnabled && e.preventDefault();
151
151
  }
152
152
  }, isNumberColumnEnabled ? /*#__PURE__*/_react.default.createElement(_NumberColumn.default, {
153
153
  editorView: editorView,
@@ -1,7 +1,10 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import ReactDOM from 'react-dom';
2
3
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
3
5
  import { N200, N700 } from '@atlaskit/theme/colors';
4
6
  import { TableCssClassName as ClassName } from '../../types';
7
+ import { DragPreview } from '../DragPreview';
5
8
  import { DragHandleIcon } from '../icons/DragHandleIcon';
6
9
  const mapStateToProps = state => {
7
10
  switch (state) {
@@ -21,12 +24,15 @@ export const DragHandle = ({
21
24
  direction = 'row',
22
25
  state = 'default',
23
26
  indexes,
27
+ previewWidth,
28
+ previewHeight,
24
29
  onClick,
25
30
  onMouseOver,
26
31
  onMouseOut
27
32
  }) => {
28
33
  const dragHandleDivRef = useRef(null);
29
34
  const iconProps = mapStateToProps(state);
35
+ const [previewContainer, setPreviewContainer] = useState(null);
30
36
  useEffect(() => {
31
37
  const dragHandleDivRefCurrent = dragHandleDivRef.current;
32
38
  if (dragHandleDivRefCurrent) {
@@ -38,15 +44,51 @@ export const DragHandle = ({
38
44
  type: `table-${direction}`,
39
45
  indexes
40
46
  };
47
+ },
48
+ onGenerateDragPreview: ({
49
+ nativeSetDragImage
50
+ }) => {
51
+ setCustomNativeDragPreview({
52
+ getOffset: ({
53
+ container
54
+ }) => {
55
+ const rect = container.getBoundingClientRect();
56
+ if (direction === 'row') {
57
+ return {
58
+ x: 16,
59
+ y: 16
60
+ };
61
+ } else {
62
+ return {
63
+ x: rect.width / 2 + 16,
64
+ y: 16
65
+ };
66
+ }
67
+ },
68
+ render: function render({
69
+ container
70
+ }) {
71
+ setPreviewContainer(container);
72
+ return () => setPreviewContainer(null);
73
+ },
74
+ nativeSetDragImage
75
+ });
41
76
  }
42
77
  });
43
78
  }
44
79
  }, [tableLocalId, direction, indexes]);
45
80
  return /*#__PURE__*/React.createElement("button", {
46
81
  className: ClassName.DRAG_HANDLE_BUTTON_CONTAINER,
82
+ ref: dragHandleDivRef,
47
83
  style: {
84
+ backgroundColor: `${"var(--ds-surface, white)"}`,
85
+ borderRadius: '4px',
86
+ border: `2px solid ${"var(--ds-surface, white)"}`,
48
87
  transform: direction === 'column' ? 'none' : 'rotate(90deg)'
49
- },
50
- ref: dragHandleDivRef
51
- }, /*#__PURE__*/React.createElement(DragHandleIcon, iconProps));
88
+ }
89
+ }, /*#__PURE__*/React.createElement(DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
90
+ direction: direction,
91
+ width: previewWidth,
92
+ height: previewHeight
93
+ }), previewContainer));
52
94
  };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Box, xcss } from '@atlaskit/primitives';
3
- import { DragInMotionIcon } from '../Icons/DragInMotionIcon';
3
+ import { DragInMotionIcon } from '../icons/DragInMotionIcon';
4
4
  const boxStyles = xcss({
5
5
  borderColor: 'color.border.focused',
6
6
  borderStyle: 'solid',
@@ -14,6 +14,7 @@ const DragControlsComponent = ({
14
14
  }) => {
15
15
  const rowHeights = getRowHeights(tableRef);
16
16
  const heights = rowHeights.map((height, index) => `${height - 1}px`).join(' ');
17
+ const rowWidth = tableRef.offsetWidth;
17
18
  const onClick = (index, event) => {};
18
19
  const onMouseOver = () => {};
19
20
  const onMouseOut = () => {};
@@ -28,7 +29,7 @@ const DragControlsComponent = ({
28
29
  style: {
29
30
  gridTemplateRows: heights
30
31
  }
31
- }, Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
32
+ }, rowIndex !== undefined && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
32
33
  style: {
33
34
  gridRow: `${rowIndex + 1} / span 1`,
34
35
  display: 'flex'
@@ -38,7 +39,9 @@ const DragControlsComponent = ({
38
39
  onMouseOver: onMouseOver,
39
40
  onMouseOut: onMouseOut,
40
41
  tableLocalId: getLocalId(),
41
- indexes: []
42
+ indexes: [rowIndex],
43
+ previewWidth: rowWidth,
44
+ previewHeight: rowHeights[rowIndex]
42
45
  })));
43
46
  };
44
47
  export const DragControls = injectIntl(DragControlsComponent);
@@ -104,7 +104,7 @@ export default class TableFloatingControls extends Component {
104
104
  }
105
105
  const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
106
106
  return /*#__PURE__*/React.createElement("div", {
107
- onMouseDown: e => e.preventDefault()
107
+ onMouseDown: e => !isDragAndDropEnabled && e.preventDefault()
108
108
  }, isNumberColumnEnabled ? /*#__PURE__*/React.createElement(NumberColumn, {
109
109
  editorView: editorView,
110
110
  hoverRows: this.hoverRows,
@@ -1,7 +1,11 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import ReactDOM from 'react-dom';
2
4
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
5
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
3
6
  import { N200, N700 } from '@atlaskit/theme/colors';
4
7
  import { TableCssClassName as ClassName } from '../../types';
8
+ import { DragPreview } from '../DragPreview';
5
9
  import { DragHandleIcon } from '../icons/DragHandleIcon';
6
10
  var mapStateToProps = function mapStateToProps(state) {
7
11
  switch (state) {
@@ -23,11 +27,17 @@ export var DragHandle = function DragHandle(_ref) {
23
27
  _ref$state = _ref.state,
24
28
  state = _ref$state === void 0 ? 'default' : _ref$state,
25
29
  indexes = _ref.indexes,
30
+ previewWidth = _ref.previewWidth,
31
+ previewHeight = _ref.previewHeight,
26
32
  onClick = _ref.onClick,
27
33
  onMouseOver = _ref.onMouseOver,
28
34
  onMouseOut = _ref.onMouseOut;
29
35
  var dragHandleDivRef = useRef(null);
30
36
  var iconProps = mapStateToProps(state);
37
+ var _useState = useState(null),
38
+ _useState2 = _slicedToArray(_useState, 2),
39
+ previewContainer = _useState2[0],
40
+ setPreviewContainer = _useState2[1];
31
41
  useEffect(function () {
32
42
  var dragHandleDivRefCurrent = dragHandleDivRef.current;
33
43
  if (dragHandleDivRefCurrent) {
@@ -39,15 +49,50 @@ export var DragHandle = function DragHandle(_ref) {
39
49
  type: "table-".concat(direction),
40
50
  indexes: indexes
41
51
  };
52
+ },
53
+ onGenerateDragPreview: function onGenerateDragPreview(_ref2) {
54
+ var nativeSetDragImage = _ref2.nativeSetDragImage;
55
+ setCustomNativeDragPreview({
56
+ getOffset: function getOffset(_ref3) {
57
+ var container = _ref3.container;
58
+ var rect = container.getBoundingClientRect();
59
+ if (direction === 'row') {
60
+ return {
61
+ x: 16,
62
+ y: 16
63
+ };
64
+ } else {
65
+ return {
66
+ x: rect.width / 2 + 16,
67
+ y: 16
68
+ };
69
+ }
70
+ },
71
+ render: function render(_ref4) {
72
+ var container = _ref4.container;
73
+ setPreviewContainer(container);
74
+ return function () {
75
+ return setPreviewContainer(null);
76
+ };
77
+ },
78
+ nativeSetDragImage: nativeSetDragImage
79
+ });
42
80
  }
43
81
  });
44
82
  }
45
83
  }, [tableLocalId, direction, indexes]);
46
84
  return /*#__PURE__*/React.createElement("button", {
47
85
  className: ClassName.DRAG_HANDLE_BUTTON_CONTAINER,
86
+ ref: dragHandleDivRef,
48
87
  style: {
88
+ backgroundColor: "var(--ds-surface, white)",
89
+ borderRadius: '4px',
90
+ border: "2px solid ".concat("var(--ds-surface, white)"),
49
91
  transform: direction === 'column' ? 'none' : 'rotate(90deg)'
50
- },
51
- ref: dragHandleDivRef
52
- }, /*#__PURE__*/React.createElement(DragHandleIcon, iconProps));
92
+ }
93
+ }, /*#__PURE__*/React.createElement(DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
94
+ direction: direction,
95
+ width: previewWidth,
96
+ height: previewHeight
97
+ }), previewContainer));
53
98
  };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Box, xcss } from '@atlaskit/primitives';
3
- import { DragInMotionIcon } from '../Icons/DragInMotionIcon';
3
+ import { DragInMotionIcon } from '../icons/DragInMotionIcon';
4
4
  var boxStyles = xcss({
5
5
  borderColor: 'color.border.focused',
6
6
  borderStyle: 'solid',
@@ -15,6 +15,7 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
15
15
  var heights = rowHeights.map(function (height, index) {
16
16
  return "".concat(height - 1, "px");
17
17
  }).join(' ');
18
+ var rowWidth = tableRef.offsetWidth;
18
19
  var _onClick = function onClick(index, event) {};
19
20
  var onMouseOver = function onMouseOver() {};
20
21
  var onMouseOut = function onMouseOut() {};
@@ -29,7 +30,7 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
29
30
  style: {
30
31
  gridTemplateRows: heights
31
32
  }
32
- }, Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
33
+ }, rowIndex !== undefined && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
33
34
  style: {
34
35
  gridRow: "".concat(rowIndex + 1, " / span 1"),
35
36
  display: 'flex'
@@ -41,7 +42,9 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
41
42
  onMouseOver: onMouseOver,
42
43
  onMouseOut: onMouseOut,
43
44
  tableLocalId: getLocalId(),
44
- indexes: []
45
+ indexes: [rowIndex],
46
+ previewWidth: rowWidth,
47
+ previewHeight: rowHeights[rowIndex]
45
48
  })));
46
49
  };
47
50
  export var DragControls = injectIntl(DragControlsComponent);
@@ -137,7 +137,7 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
137
137
  var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
138
138
  return /*#__PURE__*/React.createElement("div", {
139
139
  onMouseDown: function onMouseDown(e) {
140
- return e.preventDefault();
140
+ return !isDragAndDropEnabled && e.preventDefault();
141
141
  }
142
142
  }, isNumberColumnEnabled ? /*#__PURE__*/React.createElement(NumberColumn, {
143
143
  editorView: editorView,
@@ -3,11 +3,13 @@ type DragHandleState = 'default' | 'selected' | 'disabled' | 'danger';
3
3
  type DragHandleProps = {
4
4
  tableLocalId: string;
5
5
  indexes: number[];
6
+ previewWidth?: number;
7
+ previewHeight?: number;
6
8
  direction?: 'column' | 'row';
7
9
  state?: DragHandleState;
8
10
  onClick?: MouseEventHandler;
9
11
  onMouseOver?: MouseEventHandler;
10
12
  onMouseOut?: MouseEventHandler;
11
13
  };
12
- export declare const DragHandle: ({ tableLocalId, direction, state, indexes, onClick, onMouseOver, onMouseOut, }: DragHandleProps) => JSX.Element;
14
+ export declare const DragHandle: ({ tableLocalId, direction, state, indexes, previewWidth, previewHeight, onClick, onMouseOver, onMouseOut, }: DragHandleProps) => JSX.Element;
13
15
  export {};
@@ -3,11 +3,13 @@ type DragHandleState = 'default' | 'selected' | 'disabled' | 'danger';
3
3
  type DragHandleProps = {
4
4
  tableLocalId: string;
5
5
  indexes: number[];
6
+ previewWidth?: number;
7
+ previewHeight?: number;
6
8
  direction?: 'column' | 'row';
7
9
  state?: DragHandleState;
8
10
  onClick?: MouseEventHandler;
9
11
  onMouseOver?: MouseEventHandler;
10
12
  onMouseOut?: MouseEventHandler;
11
13
  };
12
- export declare const DragHandle: ({ tableLocalId, direction, state, indexes, onClick, onMouseOver, onMouseOut, }: DragHandleProps) => JSX.Element;
14
+ export declare const DragHandle: ({ tableLocalId, direction, state, indexes, previewWidth, previewHeight, onClick, onMouseOver, onMouseOut, }: DragHandleProps) => JSX.Element;
13
15
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.6",
3
+ "version": "5.3.7",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^32.0.0",
31
31
  "@atlaskit/custom-steps": "^0.0.2",
32
- "@atlaskit/editor-common": "^76.12.0",
32
+ "@atlaskit/editor-common": "^76.13.0",
33
33
  "@atlaskit/editor-palette": "1.5.1",
34
34
  "@atlaskit/editor-plugin-analytics": "^0.2.0",
35
35
  "@atlaskit/editor-plugin-content-insertion": "^0.1.0",
@@ -1,11 +1,15 @@
1
1
  import type { MouseEventHandler } from 'react';
2
- import React, { useEffect, useRef } from 'react';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+
4
+ import ReactDOM from 'react-dom';
3
5
 
4
6
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
7
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
5
8
  import { N200, N700 } from '@atlaskit/theme/colors';
6
9
  import { token } from '@atlaskit/tokens';
7
10
 
8
11
  import { TableCssClassName as ClassName } from '../../types';
12
+ import { DragPreview } from '../DragPreview';
9
13
  import { DragHandleIcon } from '../icons/DragHandleIcon';
10
14
 
11
15
  type DragHandleState = 'default' | 'selected' | 'disabled' | 'danger';
@@ -13,6 +17,8 @@ type DragHandleState = 'default' | 'selected' | 'disabled' | 'danger';
13
17
  type DragHandleProps = {
14
18
  tableLocalId: string;
15
19
  indexes: number[];
20
+ previewWidth?: number;
21
+ previewHeight?: number;
16
22
  direction?: 'column' | 'row';
17
23
  state?: DragHandleState;
18
24
  onClick?: MouseEventHandler;
@@ -39,12 +45,17 @@ export const DragHandle = ({
39
45
  direction = 'row',
40
46
  state = 'default',
41
47
  indexes,
48
+ previewWidth,
49
+ previewHeight,
42
50
  onClick,
43
51
  onMouseOver,
44
52
  onMouseOut,
45
53
  }: DragHandleProps) => {
46
54
  const dragHandleDivRef = useRef<HTMLButtonElement>(null);
47
55
  const iconProps = mapStateToProps(state);
56
+ const [previewContainer, setPreviewContainer] = useState<HTMLElement | null>(
57
+ null,
58
+ );
48
59
 
49
60
  useEffect(() => {
50
61
  const dragHandleDivRefCurrent = dragHandleDivRef.current;
@@ -58,6 +69,23 @@ export const DragHandle = ({
58
69
  indexes,
59
70
  };
60
71
  },
72
+ onGenerateDragPreview: ({ nativeSetDragImage }) => {
73
+ setCustomNativeDragPreview({
74
+ getOffset: ({ container }) => {
75
+ const rect = container.getBoundingClientRect();
76
+ if (direction === 'row') {
77
+ return { x: 16, y: 16 };
78
+ } else {
79
+ return { x: rect.width / 2 + 16, y: 16 };
80
+ }
81
+ },
82
+ render: function render({ container }) {
83
+ setPreviewContainer(container);
84
+ return () => setPreviewContainer(null);
85
+ },
86
+ nativeSetDragImage,
87
+ });
88
+ },
61
89
  });
62
90
  }
63
91
  }, [tableLocalId, direction, indexes]);
@@ -65,12 +93,26 @@ export const DragHandle = ({
65
93
  return (
66
94
  <button
67
95
  className={ClassName.DRAG_HANDLE_BUTTON_CONTAINER}
96
+ ref={dragHandleDivRef}
68
97
  style={{
98
+ backgroundColor: `${token('elevation.surface', 'white')}`,
99
+ borderRadius: '4px',
100
+ border: `2px solid ${token('elevation.surface', 'white')}`,
69
101
  transform: direction === 'column' ? 'none' : 'rotate(90deg)',
70
102
  }}
71
- ref={dragHandleDivRef}
72
103
  >
73
104
  <DragHandleIcon {...iconProps} />
105
+ {previewContainer &&
106
+ previewWidth !== undefined &&
107
+ previewHeight !== undefined &&
108
+ ReactDOM.createPortal(
109
+ <DragPreview
110
+ direction={direction}
111
+ width={previewWidth}
112
+ height={previewHeight}
113
+ />,
114
+ previewContainer,
115
+ )}
74
116
  </button>
75
117
  );
76
118
  };
@@ -2,7 +2,7 @@ import React from 'react';
2
2
 
3
3
  import { Box, xcss } from '@atlaskit/primitives';
4
4
 
5
- import { DragInMotionIcon } from '../Icons/DragInMotionIcon';
5
+ import { DragInMotionIcon } from '../icons/DragInMotionIcon';
6
6
 
7
7
  const boxStyles = xcss({
8
8
  borderColor: 'color.border.focused',
@@ -32,6 +32,7 @@ const DragControlsComponent = ({
32
32
  const heights = rowHeights
33
33
  .map((height, index) => `${height - 1}px`)
34
34
  .join(' ');
35
+ const rowWidth = tableRef.offsetWidth;
35
36
 
36
37
  const onClick = (
37
38
  index: number,
@@ -55,7 +56,7 @@ const DragControlsComponent = ({
55
56
  gridTemplateRows: heights,
56
57
  }}
57
58
  >
58
- {Number.isFinite(rowIndex) && (
59
+ {rowIndex !== undefined && Number.isFinite(rowIndex) && (
59
60
  <div
60
61
  style={{
61
62
  gridRow: `${(rowIndex as number) + 1} / span 1`,
@@ -67,7 +68,9 @@ const DragControlsComponent = ({
67
68
  onMouseOver={onMouseOver}
68
69
  onMouseOut={onMouseOut}
69
70
  tableLocalId={getLocalId()}
70
- indexes={[]}
71
+ indexes={[rowIndex]}
72
+ previewWidth={rowWidth}
73
+ previewHeight={rowHeights[rowIndex]}
71
74
  />
72
75
  </div>
73
76
  )}
@@ -133,7 +133,7 @@ export default class TableFloatingControls extends Component<Props, State> {
133
133
  : undefined;
134
134
 
135
135
  return (
136
- <div onMouseDown={(e) => e.preventDefault()}>
136
+ <div onMouseDown={(e) => !isDragAndDropEnabled && e.preventDefault()}>
137
137
  {isNumberColumnEnabled ? (
138
138
  <NumberColumn
139
139
  editorView={editorView}