@atlaskit/editor-plugin-table 7.2.1 → 7.2.2

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 (25) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +11 -7
  3. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +11 -25
  4. package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +13 -3
  5. package/dist/cjs/ui/TableFloatingColumnControls/index.js +7 -3
  6. package/dist/es2019/nodeviews/TableComponent.js +9 -5
  7. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
  8. package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
  9. package/dist/es2019/ui/TableFloatingColumnControls/index.js +7 -3
  10. package/dist/esm/nodeviews/TableComponent.js +11 -7
  11. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
  12. package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
  13. package/dist/esm/ui/TableFloatingColumnControls/index.js +7 -3
  14. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  15. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
  16. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +1 -0
  17. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  18. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
  19. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +1 -0
  20. package/package.json +2 -2
  21. package/src/nodeviews/TableComponent.tsx +1 -0
  22. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +6 -27
  23. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -1
  24. package/src/ui/TableFloatingColumnControls/index.tsx +5 -0
  25. package/tsconfig.json +6 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#70342](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70342) [`6862cba17f31`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6862cba17f31) - Fix drop functionality when dragging in overflown table
8
+
3
9
  ## 7.2.1
4
10
 
5
11
  ### Patch Changes
@@ -471,8 +471,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
471
471
  }, {
472
472
  key: "render",
473
473
  value: function render() {
474
- var _classnames,
475
- _this3 = this;
474
+ var _this3 = this,
475
+ _classnames;
476
476
  var _this$props10 = this.props,
477
477
  view = _this$props10.view,
478
478
  getNode = _this$props10.getNode,
@@ -544,7 +544,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
544
544
  stickyHeader: this.state.stickyHeader,
545
545
  getEditorFeatureFlags: getEditorFeatureFlags,
546
546
  tableContainerWidth: tableContainerWidth,
547
- isNumberColumnEnabled: node.attrs.isNumberColumnEnabled
547
+ isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
548
+ getScrollOffset: function getScrollOffset() {
549
+ var _this3$wrapper;
550
+ return ((_this3$wrapper = _this3.wrapper) === null || _this3$wrapper === void 0 ? void 0 : _this3$wrapper.scrollLeft) || 0;
551
+ }
548
552
  }) : null;
549
553
  var shadowPadding = allowControls && tableActive ? -_editorSharedStyles.akEditorTableToolbarSize : _styles.tableMarginSides;
550
554
  var shadowStyle = (0, _memoizeOne.default)(function (visible) {
@@ -592,12 +596,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
592
596
  editorView: view,
593
597
  node: node,
594
598
  getScrollOffset: function getScrollOffset() {
595
- var _this3$wrapper;
596
- return ((_this3$wrapper = _this3.wrapper) === null || _this3$wrapper === void 0 ? void 0 : _this3$wrapper.scrollLeft) || 0;
599
+ var _this3$wrapper2;
600
+ return ((_this3$wrapper2 = _this3.wrapper) === null || _this3$wrapper2 === void 0 ? void 0 : _this3$wrapper2.scrollLeft) || 0;
597
601
  },
598
602
  getTableWrapperWidth: function getTableWrapperWidth() {
599
- var _this3$wrapper2;
600
- return ((_this3$wrapper2 = _this3.wrapper) === null || _this3$wrapper2 === void 0 ? void 0 : _this3$wrapper2.clientWidth) || 760;
603
+ var _this3$wrapper3;
604
+ return ((_this3$wrapper3 = _this3.wrapper) === null || _this3$wrapper3 === void 0 ? void 0 : _this3$wrapper3.clientWidth) || 760;
601
605
  }
602
606
  }), /*#__PURE__*/_react.default.createElement("div", {
603
607
  style: shadowStyle(showBeforeShadow),
@@ -7,14 +7,13 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = exports.ColumnControls = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _styles = require("@atlaskit/editor-common/styles");
10
- var _utils = require("@atlaskit/editor-common/utils");
11
10
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
11
  var _editorTables = require("@atlaskit/editor-tables");
13
- var _utils2 = require("@atlaskit/editor-tables/utils");
12
+ var _utils = require("@atlaskit/editor-tables/utils");
14
13
  var _commands = require("../../../commands");
15
14
  var _commands2 = require("../../../pm-plugins/drag-and-drop/commands");
16
15
  var _types = require("../../../types");
17
- var _utils3 = require("../../../utils");
16
+ var _utils2 = require("../../../utils");
18
17
  var _DragHandle = require("../../DragHandle");
19
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); }
20
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; }
@@ -22,11 +21,11 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
22
21
 
23
22
  var getSelectedColumns = function getSelectedColumns(selection) {
24
23
  if (selection instanceof _editorTables.CellSelection && selection.isColSelection()) {
25
- var rect = (0, _utils2.getSelectionRect)(selection);
24
+ var rect = (0, _utils.getSelectionRect)(selection);
26
25
  if (!rect) {
27
26
  return [];
28
27
  }
29
- return (0, _utils3.getSelectedColumnIndexes)(rect);
28
+ return (0, _utils2.getSelectedColumnIndexes)(rect);
30
29
  }
31
30
  return [];
32
31
  };
@@ -46,7 +45,8 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
46
45
  isTableHovered = _ref.isTableHovered,
47
46
  tableContainerWidth = _ref.tableContainerWidth,
48
47
  isNumberColumnEnabled = _ref.isNumberColumnEnabled,
49
- isDragging = _ref.isDragging;
48
+ isDragging = _ref.isDragging,
49
+ getScrollOffset = _ref.getScrollOffset;
50
50
  var columnControlsRef = (0, _react.useRef)(null);
51
51
  var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
52
52
  return (
@@ -56,7 +56,7 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
56
56
  );
57
57
  }).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
58
58
  // TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
59
- var columnParams = (0, _utils3.getRowsParams)(colWidths !== null && colWidths !== void 0 ? colWidths : []);
59
+ var columnParams = (0, _utils2.getRowsParams)(colWidths !== null && colWidths !== void 0 ? colWidths : []);
60
60
  var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
61
61
  var selectedColIndexes = getSelectedColumns(editorView.state.selection);
62
62
  var firstRow = tableRef.querySelector('tr');
@@ -116,24 +116,10 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
116
116
  var colIndexes = (0, _react.useMemo)(function () {
117
117
  return [colIndex];
118
118
  }, [colIndex]);
119
- var tableWrapper = (0, _utils.closestElement)(tableRef, ".".concat(_types.TableCssClassName.TABLE_NODE_WRAPPER));
120
- var handleScroll = (0, _react.useCallback)(function (event) {
121
- if (stickyTop) {
122
- if (columnControlsRef && columnControlsRef.current) {
123
- var _tableWrapper$scrollL;
124
- columnControlsRef.current.scrollLeft = (_tableWrapper$scrollL = tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.scrollLeft) !== null && _tableWrapper$scrollL !== void 0 ? _tableWrapper$scrollL : 0;
125
- }
126
- }
127
- }, [stickyTop, tableWrapper]);
128
- (0, _react.useEffect)(function () {
129
- handleScroll();
130
- }, [handleScroll]);
131
- (0, _react.useEffect)(function () {
132
- tableWrapper === null || tableWrapper === void 0 || tableWrapper.addEventListener('scroll', handleScroll);
133
- return function () {
134
- tableWrapper === null || tableWrapper === void 0 || tableWrapper.removeEventListener('scroll', handleScroll);
135
- };
136
- }, [tableWrapper, handleScroll]);
119
+ if (stickyTop && columnControlsRef.current) {
120
+ var _getScrollOffset;
121
+ columnControlsRef.current.scrollLeft = (_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0;
122
+ }
137
123
  var generateHandleByType = function generateHandleByType(type) {
138
124
  var _rowHeights$reduce, _colWidths$reduce;
139
125
  if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
@@ -1,22 +1,32 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.ColumnDropTargets = void 0;
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
  var _types = require("../../../types");
10
10
  var _ColumnDropTarget = require("./ColumnDropTarget");
11
+ 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); }
12
+ 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; }
11
13
  var ColumnDropTargets = exports.ColumnDropTargets = function ColumnDropTargets(_ref) {
12
14
  var tableRef = _ref.tableRef,
13
15
  tableHeight = _ref.tableHeight,
14
16
  localId = _ref.localId,
15
- colWidths = _ref.colWidths;
17
+ colWidths = _ref.colWidths,
18
+ isHeaderSticky = _ref.isHeaderSticky,
19
+ getScrollOffset = _ref.getScrollOffset;
20
+ var dropTargetRef = (0, _react.useRef)(null);
16
21
  if (!tableRef) {
17
22
  return null;
18
23
  }
24
+ if (isHeaderSticky && dropTargetRef.current) {
25
+ var _getScrollOffset;
26
+ dropTargetRef.current.style.marginLeft = "-".concat((_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0, "px");
27
+ }
19
28
  return /*#__PURE__*/_react.default.createElement("div", {
29
+ ref: dropTargetRef,
20
30
  className: _types.TableCssClassName.DRAG_COLUMN_DROP_TARGET_CONTROLS,
21
31
  contentEditable: false
22
32
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -31,7 +31,8 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
31
31
  isInDanger = _ref.isInDanger,
32
32
  isTableHovered = _ref.isTableHovered,
33
33
  tableContainerWidth = _ref.tableContainerWidth,
34
- isNumberColumnEnabled = _ref.isNumberColumnEnabled;
34
+ isNumberColumnEnabled = _ref.isNumberColumnEnabled,
35
+ getScrollOffset = _ref.getScrollOffset;
35
36
  var _useState = (0, _react.useState)({
36
37
  width: 0,
37
38
  height: 0
@@ -136,12 +137,15 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
136
137
  hasHeaderColumn: hasHeaderColumn,
137
138
  tableContainerWidth: tableContainerWidth,
138
139
  isNumberColumnEnabled: isNumberColumnEnabled,
139
- isDragging: isDragging
140
+ isDragging: isDragging,
141
+ getScrollOffset: getScrollOffset
140
142
  }), isDragging && /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
141
143
  tableRef: tableRef,
144
+ isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
142
145
  tableHeight: tableRect.height,
143
146
  localId: currentNodeLocalId,
144
- colWidths: colWidths
147
+ colWidths: colWidths,
148
+ getScrollOffset: getScrollOffset
145
149
  }));
146
150
  };
147
151
  var _default = exports.default = TableFloatingColumnControls;
@@ -543,7 +543,11 @@ class TableComponent extends React.Component {
543
543
  stickyHeader: this.state.stickyHeader,
544
544
  getEditorFeatureFlags: getEditorFeatureFlags,
545
545
  tableContainerWidth: tableContainerWidth,
546
- isNumberColumnEnabled: node.attrs.isNumberColumnEnabled
546
+ isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
547
+ getScrollOffset: () => {
548
+ var _this$wrapper2;
549
+ return ((_this$wrapper2 = this.wrapper) === null || _this$wrapper2 === void 0 ? void 0 : _this$wrapper2.scrollLeft) || 0;
550
+ }
547
551
  }) : null;
548
552
  const shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
549
553
  const shadowStyle = memoizeOne(visible => ({
@@ -595,12 +599,12 @@ class TableComponent extends React.Component {
595
599
  editorView: view,
596
600
  node: node,
597
601
  getScrollOffset: () => {
598
- var _this$wrapper2;
599
- return ((_this$wrapper2 = this.wrapper) === null || _this$wrapper2 === void 0 ? void 0 : _this$wrapper2.scrollLeft) || 0;
602
+ var _this$wrapper3;
603
+ return ((_this$wrapper3 = this.wrapper) === null || _this$wrapper3 === void 0 ? void 0 : _this$wrapper3.scrollLeft) || 0;
600
604
  },
601
605
  getTableWrapperWidth: () => {
602
- var _this$wrapper3;
603
- return ((_this$wrapper3 = this.wrapper) === null || _this$wrapper3 === void 0 ? void 0 : _this$wrapper3.clientWidth) || 760;
606
+ var _this$wrapper4;
607
+ return ((_this$wrapper4 = this.wrapper) === null || _this$wrapper4 === void 0 ? void 0 : _this$wrapper4.clientWidth) || 760;
604
608
  }
605
609
  }), /*#__PURE__*/React.createElement("div", {
606
610
  style: shadowStyle(showBeforeShadow),
@@ -1,8 +1,7 @@
1
1
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
2
 
3
- import React, { useCallback, useEffect, useMemo, useRef } from 'react';
3
+ import React, { useCallback, useMemo, useRef } from 'react';
4
4
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
- import { closestElement } from '@atlaskit/editor-common/utils';
6
5
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
7
6
  import { CellSelection } from '@atlaskit/editor-tables';
8
7
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
@@ -36,7 +35,8 @@ export const ColumnControls = ({
36
35
  isTableHovered,
37
36
  tableContainerWidth,
38
37
  isNumberColumnEnabled,
39
- isDragging
38
+ isDragging,
39
+ getScrollOffset
40
40
  }) => {
41
41
  var _colWidths$map$join, _rowHeights$;
42
42
  const columnControlsRef = useRef(null);
@@ -115,24 +115,10 @@ export const ColumnControls = ({
115
115
  const colIndexes = useMemo(() => {
116
116
  return [colIndex];
117
117
  }, [colIndex]);
118
- const tableWrapper = closestElement(tableRef, `.${ClassName.TABLE_NODE_WRAPPER}`);
119
- const handleScroll = useCallback(event => {
120
- if (stickyTop) {
121
- if (columnControlsRef && columnControlsRef.current) {
122
- var _tableWrapper$scrollL;
123
- columnControlsRef.current.scrollLeft = (_tableWrapper$scrollL = tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.scrollLeft) !== null && _tableWrapper$scrollL !== void 0 ? _tableWrapper$scrollL : 0;
124
- }
125
- }
126
- }, [stickyTop, tableWrapper]);
127
- useEffect(() => {
128
- handleScroll();
129
- }, [handleScroll]);
130
- useEffect(() => {
131
- tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.addEventListener('scroll', handleScroll);
132
- return () => {
133
- tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.removeEventListener('scroll', handleScroll);
134
- };
135
- }, [tableWrapper, handleScroll]);
118
+ if (stickyTop && columnControlsRef.current) {
119
+ var _getScrollOffset;
120
+ columnControlsRef.current.scrollLeft = (_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0;
121
+ }
136
122
  const generateHandleByType = type => {
137
123
  var _rowHeights$reduce, _colWidths$reduce;
138
124
  if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
@@ -1,16 +1,24 @@
1
- import React from 'react';
1
+ import React, { useRef } from 'react';
2
2
  import { TableCssClassName as ClassName } from '../../../types';
3
3
  import { ColumnDropTarget } from './ColumnDropTarget';
4
4
  export const ColumnDropTargets = ({
5
5
  tableRef,
6
6
  tableHeight,
7
7
  localId,
8
- colWidths
8
+ colWidths,
9
+ isHeaderSticky,
10
+ getScrollOffset
9
11
  }) => {
12
+ const dropTargetRef = useRef(null);
10
13
  if (!tableRef) {
11
14
  return null;
12
15
  }
16
+ if (isHeaderSticky && dropTargetRef.current) {
17
+ var _getScrollOffset;
18
+ dropTargetRef.current.style.marginLeft = `-${(_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0}px`;
19
+ }
13
20
  return /*#__PURE__*/React.createElement("div", {
21
+ ref: dropTargetRef,
14
22
  className: ClassName.DRAG_COLUMN_DROP_TARGET_CONTROLS,
15
23
  contentEditable: false
16
24
  }, /*#__PURE__*/React.createElement("div", {
@@ -17,7 +17,8 @@ export const TableFloatingColumnControls = ({
17
17
  isInDanger,
18
18
  isTableHovered,
19
19
  tableContainerWidth,
20
- isNumberColumnEnabled
20
+ isNumberColumnEnabled,
21
+ getScrollOffset
21
22
  }) => {
22
23
  const [tableRect, setTableRect] = useState({
23
24
  width: 0,
@@ -107,12 +108,15 @@ export const TableFloatingColumnControls = ({
107
108
  hasHeaderColumn: hasHeaderColumn,
108
109
  tableContainerWidth: tableContainerWidth,
109
110
  isNumberColumnEnabled: isNumberColumnEnabled,
110
- isDragging: isDragging
111
+ isDragging: isDragging,
112
+ getScrollOffset: getScrollOffset
111
113
  }), isDragging && /*#__PURE__*/React.createElement(ColumnDropTargets, {
112
114
  tableRef: tableRef,
115
+ isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
113
116
  tableHeight: tableRect.height,
114
117
  localId: currentNodeLocalId,
115
- colWidths: colWidths
118
+ colWidths: colWidths,
119
+ getScrollOffset: getScrollOffset
116
120
  }));
117
121
  };
118
122
  export default TableFloatingColumnControls;
@@ -464,8 +464,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
464
464
  }, {
465
465
  key: "render",
466
466
  value: function render() {
467
- var _classnames,
468
- _this3 = this;
467
+ var _this3 = this,
468
+ _classnames;
469
469
  var _this$props10 = this.props,
470
470
  view = _this$props10.view,
471
471
  getNode = _this$props10.getNode,
@@ -537,7 +537,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
537
537
  stickyHeader: this.state.stickyHeader,
538
538
  getEditorFeatureFlags: getEditorFeatureFlags,
539
539
  tableContainerWidth: tableContainerWidth,
540
- isNumberColumnEnabled: node.attrs.isNumberColumnEnabled
540
+ isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
541
+ getScrollOffset: function getScrollOffset() {
542
+ var _this3$wrapper;
543
+ return ((_this3$wrapper = _this3.wrapper) === null || _this3$wrapper === void 0 ? void 0 : _this3$wrapper.scrollLeft) || 0;
544
+ }
541
545
  }) : null;
542
546
  var shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
543
547
  var shadowStyle = memoizeOne(function (visible) {
@@ -585,12 +589,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
585
589
  editorView: view,
586
590
  node: node,
587
591
  getScrollOffset: function getScrollOffset() {
588
- var _this3$wrapper;
589
- return ((_this3$wrapper = _this3.wrapper) === null || _this3$wrapper === void 0 ? void 0 : _this3$wrapper.scrollLeft) || 0;
592
+ var _this3$wrapper2;
593
+ return ((_this3$wrapper2 = _this3.wrapper) === null || _this3$wrapper2 === void 0 ? void 0 : _this3$wrapper2.scrollLeft) || 0;
590
594
  },
591
595
  getTableWrapperWidth: function getTableWrapperWidth() {
592
- var _this3$wrapper2;
593
- return ((_this3$wrapper2 = _this3.wrapper) === null || _this3$wrapper2 === void 0 ? void 0 : _this3$wrapper2.clientWidth) || 760;
596
+ var _this3$wrapper3;
597
+ return ((_this3$wrapper3 = _this3.wrapper) === null || _this3$wrapper3 === void 0 ? void 0 : _this3$wrapper3.clientWidth) || 760;
594
598
  }
595
599
  }), /*#__PURE__*/React.createElement("div", {
596
600
  style: shadowStyle(showBeforeShadow),
@@ -1,8 +1,7 @@
1
1
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
2
 
3
- import React, { useCallback, useEffect, useMemo, useRef } from 'react';
3
+ import React, { useCallback, useMemo, useRef } from 'react';
4
4
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
- import { closestElement } from '@atlaskit/editor-common/utils';
6
5
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
7
6
  import { CellSelection } from '@atlaskit/editor-tables';
8
7
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
@@ -37,7 +36,8 @@ export var ColumnControls = function ColumnControls(_ref) {
37
36
  isTableHovered = _ref.isTableHovered,
38
37
  tableContainerWidth = _ref.tableContainerWidth,
39
38
  isNumberColumnEnabled = _ref.isNumberColumnEnabled,
40
- isDragging = _ref.isDragging;
39
+ isDragging = _ref.isDragging,
40
+ getScrollOffset = _ref.getScrollOffset;
41
41
  var columnControlsRef = useRef(null);
42
42
  var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
43
43
  return (
@@ -107,24 +107,10 @@ export var ColumnControls = function ColumnControls(_ref) {
107
107
  var colIndexes = useMemo(function () {
108
108
  return [colIndex];
109
109
  }, [colIndex]);
110
- var tableWrapper = closestElement(tableRef, ".".concat(ClassName.TABLE_NODE_WRAPPER));
111
- var handleScroll = useCallback(function (event) {
112
- if (stickyTop) {
113
- if (columnControlsRef && columnControlsRef.current) {
114
- var _tableWrapper$scrollL;
115
- columnControlsRef.current.scrollLeft = (_tableWrapper$scrollL = tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.scrollLeft) !== null && _tableWrapper$scrollL !== void 0 ? _tableWrapper$scrollL : 0;
116
- }
117
- }
118
- }, [stickyTop, tableWrapper]);
119
- useEffect(function () {
120
- handleScroll();
121
- }, [handleScroll]);
122
- useEffect(function () {
123
- tableWrapper === null || tableWrapper === void 0 || tableWrapper.addEventListener('scroll', handleScroll);
124
- return function () {
125
- tableWrapper === null || tableWrapper === void 0 || tableWrapper.removeEventListener('scroll', handleScroll);
126
- };
127
- }, [tableWrapper, handleScroll]);
110
+ if (stickyTop && columnControlsRef.current) {
111
+ var _getScrollOffset;
112
+ columnControlsRef.current.scrollLeft = (_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0;
113
+ }
128
114
  var generateHandleByType = function generateHandleByType(type) {
129
115
  var _rowHeights$reduce, _colWidths$reduce;
130
116
  if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
@@ -1,15 +1,23 @@
1
- import React from 'react';
1
+ import React, { useRef } from 'react';
2
2
  import { TableCssClassName as ClassName } from '../../../types';
3
3
  import { ColumnDropTarget } from './ColumnDropTarget';
4
4
  export var ColumnDropTargets = function ColumnDropTargets(_ref) {
5
5
  var tableRef = _ref.tableRef,
6
6
  tableHeight = _ref.tableHeight,
7
7
  localId = _ref.localId,
8
- colWidths = _ref.colWidths;
8
+ colWidths = _ref.colWidths,
9
+ isHeaderSticky = _ref.isHeaderSticky,
10
+ getScrollOffset = _ref.getScrollOffset;
11
+ var dropTargetRef = useRef(null);
9
12
  if (!tableRef) {
10
13
  return null;
11
14
  }
15
+ if (isHeaderSticky && dropTargetRef.current) {
16
+ var _getScrollOffset;
17
+ dropTargetRef.current.style.marginLeft = "-".concat((_getScrollOffset = getScrollOffset === null || getScrollOffset === void 0 ? void 0 : getScrollOffset()) !== null && _getScrollOffset !== void 0 ? _getScrollOffset : 0, "px");
18
+ }
12
19
  return /*#__PURE__*/React.createElement("div", {
20
+ ref: dropTargetRef,
13
21
  className: ClassName.DRAG_COLUMN_DROP_TARGET_CONTROLS,
14
22
  contentEditable: false
15
23
  }, /*#__PURE__*/React.createElement("div", {
@@ -21,7 +21,8 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
21
21
  isInDanger = _ref.isInDanger,
22
22
  isTableHovered = _ref.isTableHovered,
23
23
  tableContainerWidth = _ref.tableContainerWidth,
24
- isNumberColumnEnabled = _ref.isNumberColumnEnabled;
24
+ isNumberColumnEnabled = _ref.isNumberColumnEnabled,
25
+ getScrollOffset = _ref.getScrollOffset;
25
26
  var _useState = useState({
26
27
  width: 0,
27
28
  height: 0
@@ -126,12 +127,15 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
126
127
  hasHeaderColumn: hasHeaderColumn,
127
128
  tableContainerWidth: tableContainerWidth,
128
129
  isNumberColumnEnabled: isNumberColumnEnabled,
129
- isDragging: isDragging
130
+ isDragging: isDragging,
131
+ getScrollOffset: getScrollOffset
130
132
  }), isDragging && /*#__PURE__*/React.createElement(ColumnDropTargets, {
131
133
  tableRef: tableRef,
134
+ isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
132
135
  tableHeight: tableRect.height,
133
136
  localId: currentNodeLocalId,
134
- colWidths: colWidths
137
+ colWidths: colWidths,
138
+ getScrollOffset: getScrollOffset
135
139
  }));
136
140
  };
137
141
  export default TableFloatingColumnControls;
@@ -17,6 +17,7 @@ export interface ColumnControlsProps {
17
17
  tableContainerWidth?: number;
18
18
  isNumberColumnEnabled?: boolean;
19
19
  isDragging?: boolean;
20
+ getScrollOffset?: () => number;
20
21
  }
21
- export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, tableContainerWidth, isNumberColumnEnabled, isDragging, }: ColumnControlsProps) => JSX.Element;
22
+ export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, tableContainerWidth, isNumberColumnEnabled, isDragging, getScrollOffset, }: ColumnControlsProps) => JSX.Element;
22
23
  export default ColumnControls;
@@ -4,5 +4,7 @@ export interface Props {
4
4
  tableHeight?: number;
5
5
  localId?: string;
6
6
  colWidths?: (number | undefined)[];
7
+ isHeaderSticky?: boolean;
8
+ getScrollOffset?: () => number;
7
9
  }
8
10
  export declare const ColumnDropTargets: React.FC<Props>;
@@ -24,6 +24,7 @@ export interface Props {
24
24
  isTableHovered?: boolean;
25
25
  tableContainerWidth?: number;
26
26
  isNumberColumnEnabled?: boolean;
27
+ getScrollOffset?: () => number;
27
28
  }
28
29
  export declare const TableFloatingColumnControls: React.FC<Props>;
29
30
  export default TableFloatingColumnControls;
@@ -17,6 +17,7 @@ export interface ColumnControlsProps {
17
17
  tableContainerWidth?: number;
18
18
  isNumberColumnEnabled?: boolean;
19
19
  isDragging?: boolean;
20
+ getScrollOffset?: () => number;
20
21
  }
21
- export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, tableContainerWidth, isNumberColumnEnabled, isDragging, }: ColumnControlsProps) => JSX.Element;
22
+ export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, tableContainerWidth, isNumberColumnEnabled, isDragging, getScrollOffset, }: ColumnControlsProps) => JSX.Element;
22
23
  export default ColumnControls;
@@ -4,5 +4,7 @@ export interface Props {
4
4
  tableHeight?: number;
5
5
  localId?: string;
6
6
  colWidths?: (number | undefined)[];
7
+ isHeaderSticky?: boolean;
8
+ getScrollOffset?: () => number;
7
9
  }
8
10
  export declare const ColumnDropTargets: React.FC<Props>;
@@ -24,6 +24,7 @@ export interface Props {
24
24
  isTableHovered?: boolean;
25
25
  tableContainerWidth?: number;
26
26
  isNumberColumnEnabled?: boolean;
27
+ getScrollOffset?: () => number;
27
28
  }
28
29
  export declare const TableFloatingColumnControls: React.FC<Props>;
29
30
  export default TableFloatingColumnControls;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.2.1",
3
+ "version": "7.2.2",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -69,7 +69,7 @@
69
69
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
70
70
  "@atlaskit/editor-plugin-grid": "^0.3.0",
71
71
  "@atlaskit/editor-plugin-hyperlink": "^0.8.0",
72
- "@atlaskit/editor-test-helpers": "^18.15.0",
72
+ "@atlaskit/editor-test-helpers": "^18.16.0",
73
73
  "@atlaskit/visual-regression": "*",
74
74
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
75
75
  "@atlassian/feature-flags-test-utils": "^0.2.0",
@@ -500,6 +500,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
500
500
  getEditorFeatureFlags={getEditorFeatureFlags}
501
501
  tableContainerWidth={tableContainerWidth}
502
502
  isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
503
+ getScrollOffset={() => this.wrapper?.scrollLeft || 0}
503
504
  />
504
505
  ) : null;
505
506
 
@@ -1,9 +1,8 @@
1
1
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
2
  import type { MouseEvent } from 'react';
3
- import React, { useCallback, useEffect, useMemo, useRef } from 'react';
3
+ import React, { useCallback, useMemo, useRef } from 'react';
4
4
 
5
5
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
6
- import { closestElement } from '@atlaskit/editor-common/utils';
7
6
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
8
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
8
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
@@ -39,6 +38,7 @@ export interface ColumnControlsProps {
39
38
  tableContainerWidth?: number;
40
39
  isNumberColumnEnabled?: boolean;
41
40
  isDragging?: boolean;
41
+ getScrollOffset?: () => number;
42
42
  }
43
43
 
44
44
  const getSelectedColumns = (selection: Selection) => {
@@ -68,6 +68,7 @@ export const ColumnControls = ({
68
68
  tableContainerWidth,
69
69
  isNumberColumnEnabled,
70
70
  isDragging,
71
+ getScrollOffset,
71
72
  }: ColumnControlsProps) => {
72
73
  const columnControlsRef = useRef<HTMLDivElement>(null);
73
74
  const widths =
@@ -172,32 +173,10 @@ export const ColumnControls = ({
172
173
  const colIndexes = useMemo(() => {
173
174
  return [colIndex!];
174
175
  }, [colIndex]);
175
- const tableWrapper = closestElement(
176
- tableRef,
177
- `.${ClassName.TABLE_NODE_WRAPPER}`,
178
- );
179
- const handleScroll = useCallback(
180
- (event?: Event) => {
181
- if (stickyTop) {
182
- if (columnControlsRef && columnControlsRef.current) {
183
- columnControlsRef.current.scrollLeft = tableWrapper?.scrollLeft ?? 0;
184
- }
185
- }
186
- },
187
- [stickyTop, tableWrapper],
188
- );
189
176
 
190
- useEffect(() => {
191
- handleScroll();
192
- }, [handleScroll]);
193
-
194
- useEffect(() => {
195
- tableWrapper?.addEventListener('scroll', handleScroll);
196
-
197
- return () => {
198
- tableWrapper?.removeEventListener('scroll', handleScroll);
199
- };
200
- }, [tableWrapper, handleScroll]);
177
+ if (stickyTop && columnControlsRef.current) {
178
+ columnControlsRef.current.scrollLeft = getScrollOffset?.() ?? 0;
179
+ }
201
180
 
202
181
  const generateHandleByType = (type: HandleTypes): JSX.Element | null => {
203
182
  if (!hoveredCell || !colWidths?.length) {
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useRef } from 'react';
2
2
 
3
3
  import { TableCssClassName as ClassName } from '../../../types';
4
4
 
@@ -9,6 +9,8 @@ export interface Props {
9
9
  tableHeight?: number;
10
10
  localId?: string;
11
11
  colWidths?: (number | undefined)[];
12
+ isHeaderSticky?: boolean;
13
+ getScrollOffset?: () => number;
12
14
  }
13
15
 
14
16
  export const ColumnDropTargets: React.FC<Props> = ({
@@ -16,13 +18,22 @@ export const ColumnDropTargets: React.FC<Props> = ({
16
18
  tableHeight,
17
19
  localId,
18
20
  colWidths,
21
+ isHeaderSticky,
22
+ getScrollOffset,
19
23
  }) => {
24
+ const dropTargetRef = useRef<HTMLDivElement>(null);
25
+
20
26
  if (!tableRef) {
21
27
  return null;
22
28
  }
23
29
 
30
+ if (isHeaderSticky && dropTargetRef.current) {
31
+ dropTargetRef.current.style.marginLeft = `-${getScrollOffset?.() ?? 0}px`;
32
+ }
33
+
24
34
  return (
25
35
  <div
36
+ ref={dropTargetRef}
26
37
  className={ClassName.DRAG_COLUMN_DROP_TARGET_CONTROLS}
27
38
  contentEditable={false}
28
39
  >
@@ -37,6 +37,7 @@ export interface Props {
37
37
  isTableHovered?: boolean;
38
38
  tableContainerWidth?: number;
39
39
  isNumberColumnEnabled?: boolean;
40
+ getScrollOffset?: () => number;
40
41
  }
41
42
 
42
43
  export const TableFloatingColumnControls: React.FC<Props> = ({
@@ -53,6 +54,7 @@ export const TableFloatingColumnControls: React.FC<Props> = ({
53
54
  isTableHovered,
54
55
  tableContainerWidth,
55
56
  isNumberColumnEnabled,
57
+ getScrollOffset,
56
58
  }) => {
57
59
  const [tableRect, setTableRect] = useState<{ width: number; height: number }>(
58
60
  { width: 0, height: 0 },
@@ -158,13 +160,16 @@ export const TableFloatingColumnControls: React.FC<Props> = ({
158
160
  tableContainerWidth={tableContainerWidth}
159
161
  isNumberColumnEnabled={isNumberColumnEnabled}
160
162
  isDragging={isDragging}
163
+ getScrollOffset={getScrollOffset}
161
164
  />
162
165
  {isDragging && (
163
166
  <ColumnDropTargets
164
167
  tableRef={tableRef}
168
+ isHeaderSticky={stickyHeader?.sticky && hasHeaderRow}
165
169
  tableHeight={tableRect.height}
166
170
  localId={currentNodeLocalId}
167
171
  colWidths={colWidths}
172
+ getScrollOffset={getScrollOffset}
168
173
  />
169
174
  )}
170
175
  </div>
package/tsconfig.json CHANGED
@@ -851,6 +851,12 @@
851
851
  "@atlaskit/editor-test-helpers/annotation": [
852
852
  "../editor-test-helpers/src/annotation.ts"
853
853
  ],
854
+ "@atlaskit/editor-test-helpers/integration/components/99-testing": [
855
+ "../editor-test-helpers/src/integration/components/99-testing.tsx"
856
+ ],
857
+ "@atlaskit/editor-test-helpers/example-helpers": [
858
+ "../editor-test-helpers/src/integration/components/example-helpers/index.ts"
859
+ ],
854
860
  "@atlaskit/editor-test-helpers": [
855
861
  "../editor-test-helpers/src"
856
862
  ],