@atlaskit/editor-plugin-table 5.3.7 → 5.3.9

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 (97) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +6 -5
  3. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +3 -2
  4. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -2
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  7. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  8. package/dist/cjs/plugins/table/types.js +1 -1
  9. package/dist/cjs/plugins/table/ui/DragHandle/index.js +6 -4
  10. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +62 -0
  11. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +70 -0
  12. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +12 -77
  13. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +58 -16
  14. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  15. package/dist/cjs/plugins/table/ui/icons/index.js +19 -0
  16. package/dist/cjs/plugins/table/ui/ui-styles.js +19 -15
  17. package/dist/cjs/plugins/table/utils/decoration.js +3 -24
  18. package/dist/cjs/plugins/table/utils/dom.js +1 -4
  19. package/dist/cjs/plugins/table/utils/index.js +0 -6
  20. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +6 -5
  21. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +3 -2
  22. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -2
  23. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  24. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  25. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  26. package/dist/es2019/plugins/table/types.js +1 -1
  27. package/dist/es2019/plugins/table/ui/DragHandle/index.js +5 -3
  28. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +52 -0
  29. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +62 -0
  30. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +8 -74
  31. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +58 -15
  32. package/dist/es2019/plugins/table/ui/common-styles.js +2 -5
  33. package/dist/es2019/plugins/table/ui/icons/index.js +2 -0
  34. package/dist/es2019/plugins/table/ui/ui-styles.js +28 -30
  35. package/dist/es2019/plugins/table/utils/decoration.js +3 -24
  36. package/dist/es2019/plugins/table/utils/dom.js +0 -1
  37. package/dist/es2019/plugins/table/utils/index.js +1 -1
  38. package/dist/esm/plugins/table/nodeviews/TableComponent.js +6 -5
  39. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +3 -2
  40. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -2
  41. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  42. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  43. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  44. package/dist/esm/plugins/table/types.js +1 -1
  45. package/dist/esm/plugins/table/ui/DragHandle/index.js +5 -3
  46. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +55 -0
  47. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +61 -0
  48. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +9 -72
  49. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +58 -16
  50. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  51. package/dist/esm/plugins/table/ui/icons/index.js +2 -0
  52. package/dist/esm/plugins/table/ui/ui-styles.js +18 -14
  53. package/dist/esm/plugins/table/utils/decoration.js +3 -24
  54. package/dist/esm/plugins/table/utils/dom.js +0 -3
  55. package/dist/esm/plugins/table/utils/index.js +1 -1
  56. package/dist/types/plugins/table/types.d.ts +2 -1
  57. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +16 -0
  58. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
  59. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
  60. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +5 -0
  61. package/dist/types/plugins/table/ui/icons/index.d.ts +2 -0
  62. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  63. package/dist/types/plugins/table/utils/decoration.d.ts +2 -2
  64. package/dist/types/plugins/table/utils/dom.d.ts +0 -1
  65. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  66. package/dist/types-ts4.5/plugins/table/types.d.ts +2 -1
  67. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +16 -0
  68. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
  69. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
  70. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +5 -0
  71. package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +2 -0
  72. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  73. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -2
  74. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +0 -1
  75. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  76. package/package.json +2 -1
  77. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +2 -2
  78. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +84 -34
  79. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +61 -12
  80. package/src/plugins/table/nodeviews/TableComponent.tsx +16 -15
  81. package/src/plugins/table/pm-plugins/decorations/plugin.ts +3 -2
  82. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -1
  83. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +1 -4
  84. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -2
  85. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +5 -0
  86. package/src/plugins/table/types.ts +2 -1
  87. package/src/plugins/table/ui/DragHandle/index.tsx +3 -1
  88. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +92 -0
  89. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +74 -0
  90. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -80
  91. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +69 -17
  92. package/src/plugins/table/ui/common-styles.ts +2 -4
  93. package/src/plugins/table/ui/icons/index.ts +2 -0
  94. package/src/plugins/table/ui/ui-styles.ts +29 -30
  95. package/src/plugins/table/utils/decoration.ts +3 -45
  96. package/src/plugins/table/utils/dom.ts +0 -4
  97. package/src/plugins/table/utils/index.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.3.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#41924](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41924) [`71cb328c202`](https://bitbucket.org/atlassian/atlassian-frontend/commits/71cb328c202) - Fixed the column controls drag and drop targets. The monitor was not responding to the targets due to there layering and pointer value. The targets are now added/removed on demand when the user starts/stop dragging
8
+
9
+ ## 5.3.8
10
+
11
+ ### Patch Changes
12
+
13
+ - [#41909](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41909) [`b122e4659bc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b122e4659bc) - Use floating column control buttons insetead of column controls implemented as decorations
14
+
3
15
  ## 5.3.7
4
16
 
5
17
  ### Patch Changes
@@ -496,22 +496,23 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
496
496
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
497
497
  stickyHeader: this.state.stickyHeader
498
498
  }));
499
- var colControls = /*#__PURE__*/_react.default.createElement("div", {
500
- className: _types.TableCssClassName.COLUMN_CONTROLS_WRAPPER
501
- }, /*#__PURE__*/_react.default.createElement(_TableFloatingColumnControls.default, {
499
+ var colControls = /*#__PURE__*/_react.default.createElement(_TableFloatingColumnControls.default, {
502
500
  editorView: view,
503
501
  tableRef: tableRef,
502
+ getNode: getNode,
504
503
  tableActive: tableActive,
505
504
  hoveredRows: hoveredRows,
505
+ hoveredCell: hoveredCell,
506
+ isResizing: isResizing,
506
507
  ordering: ordering,
507
508
  hasHeaderRow: hasHeaderRow
508
- // pass `selection` and `tableHeight` to control re-render
509
+ // pass `selection` to control re-render
509
510
  ,
510
511
  selection: view.state.selection,
511
512
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
512
513
  stickyHeader: this.state.stickyHeader,
513
514
  getEditorFeatureFlags: this.props.getEditorFeatureFlags
514
- }));
515
+ });
515
516
  var shadowPadding = allowControls && tableActive ? -_editorSharedStyles.akEditorTableToolbarSize : _styles.tableMarginSides;
516
517
  var shadowStyle = (0, _memoizeOne.default)(function (visible) {
517
518
  return {
@@ -8,6 +8,7 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _view = require("@atlaskit/editor-prosemirror/view");
10
10
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var _pluginKey = require("../plugin-key");
12
13
  var _tableWidth = require("../table-width");
13
14
  var _utils = require("./utils");
@@ -21,8 +22,8 @@ var handleDocOrSelectionChanged = exports.handleDocOrSelectionChanged = function
21
22
  var wasResizing = (_tableWidthPluginKey$2 = _tableWidth.pluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
22
23
  var changedResizing = isResizing !== wasResizing;
23
24
 
24
- // Remove column controls when resizing
25
- if (isResizing) {
25
+ // Remove column controls when resizing and don't add column decoration controls when DnD enabled
26
+ if (isResizing || (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.drag-and-drop')) {
26
27
  return _view.DecorationSet.empty;
27
28
  } else if (tr.docChanged || tr.selection instanceof _cellSelection.CellSelection || changedResizing || ((_tr$getMeta = tr.getMeta(_pluginKey.pluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type) === 'HOVER_CELL') {
28
29
  return (0, _utils.buildColumnControlsDecorations)({
@@ -30,7 +30,6 @@ var maybeUpdateColumnSelectedDecoration = function maybeUpdateColumnSelectedDeco
30
30
  return (0, _decoration.updateDecorations)(tr.doc, decorationSet, (0, _decoration.createColumnSelectedDecoration)(tr), _types.TableDecorations.COLUMN_SELECTED);
31
31
  };
32
32
  var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDecoration(_ref3) {
33
- var _meta$data;
34
33
  var decorationSet = _ref3.decorationSet,
35
34
  tr = _ref3.tr;
36
35
  var table = (0, _utils.findTable)(tr.selection);
@@ -40,7 +39,7 @@ var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDeco
40
39
  if (!table && (meta === null || meta === void 0 ? void 0 : meta.type) !== 'HOVER_CELL') {
41
40
  return decorationSet;
42
41
  }
43
- return (0, _decoration.updateDecorations)(tr.doc, decorationSet, (0, _decoration.createColumnControlsDecoration)(tr.selection, meta === null || meta === void 0 || (_meta$data = meta.data) === null || _meta$data === void 0 ? void 0 : _meta$data.hoveredCell), _types.TableDecorations.COLUMN_CONTROLS_DECORATIONS);
42
+ return (0, _decoration.updateDecorations)(tr.doc, decorationSet, (0, _decoration.createColumnControlsDecoration)(tr.selection), _types.TableDecorations.COLUMN_CONTROLS_DECORATIONS);
44
43
  };
45
44
 
46
45
  // @see: https://product-fabric.atlassian.net/browse/ED-7304
@@ -77,6 +77,6 @@ var moveSource = exports.moveSource = function moveSource(sourceType, sourceInde
77
77
  return tr.setMeta('addToHistory', false);
78
78
  }
79
79
  var move = sourceType === 'table-row' ? _utils.moveRow : _utils.moveColumn;
80
- return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
80
+ return move(sourceIndex, targetIndex)(tr);
81
81
  });
82
82
  };
@@ -76,7 +76,8 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
76
76
  }
77
77
  var sourceType = data.sourceType,
78
78
  sourceIndexes = data.sourceIndexes,
79
- targetAdjustedIndex = data.targetAdjustedIndex;
79
+ targetAdjustedIndex = data.targetAdjustedIndex,
80
+ direction = data.direction;
80
81
 
81
82
  // If the drop target index contains merged cells then we should not allow the drop to occur.
82
83
  var hasMergedCells = sourceType === 'table-row' ? _mergedCells.hasMergedCellsInRow : _mergedCells.hasMergedCellsInColumn;
@@ -86,7 +87,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
86
87
  }
87
88
  var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
88
89
  sourceIndex = _sourceIndexes[0];
89
- (0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
90
+ (0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
90
91
  }
91
92
  })
92
93
  };
@@ -46,6 +46,10 @@ var getDraggableDataFromEvent = exports.getDraggableDataFromEvent = function get
46
46
  // This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
47
47
  // the new target index to be 1 index higher.
48
48
  var targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
49
+
50
+ // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
51
+ // the target index, the then the direction of the DnD is decreasing
52
+ var direction = sourceIndexes[0] > targetIndex ? -1 : 1;
49
53
  return {
50
54
  sourceType: sourceType,
51
55
  sourceLocalId: sourceLocalId,
@@ -54,6 +58,7 @@ var getDraggableDataFromEvent = exports.getDraggableDataFromEvent = function get
54
58
  targetLocalId: targetLocalId,
55
59
  targetIndex: targetIndex,
56
60
  targetAdjustedIndex: targetIndex + targetOffset,
57
- targetClosestEdge: targetClosestEdge
61
+ targetClosestEdge: targetClosestEdge,
62
+ direction: direction
58
63
  };
59
64
  };
@@ -86,7 +86,7 @@ var TableCssClassName = exports.TableCssClassName = _objectSpread(_objectSpread(
86
86
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: "".concat(_adfSchema.tablePrefixSelector, "-corner-controls__insert-column-marker"),
87
87
  CONTROLS_CORNER_BUTTON: "".concat(_adfSchema.tablePrefixSelector, "-corner-button"),
88
88
  /** Controls with drag handle */
89
- COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: "".concat(_adfSchema.tablePrefixSelector, "-column-controls-decoration-with-drag"),
89
+ COLUMN_CONTROLS_WITH_DRAG: "".concat(_adfSchema.tablePrefixSelector, "-column-controls-with-drag"),
90
90
  ROW_CONTROLS_WITH_DRAG: "".concat(_adfSchema.tablePrefixSelector, "-row-controls-with-drag"),
91
91
  DRAG_HANDLE_BUTTON_CONTAINER: "".concat(_adfSchema.tablePrefixSelector, "-drag-handle-button-container"),
92
92
  /** Other classes */
@@ -14,7 +14,7 @@ var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/uti
14
14
  var _colors = require("@atlaskit/theme/colors");
15
15
  var _types = require("../../types");
16
16
  var _DragPreview = require("../DragPreview");
17
- var _DragHandleIcon = require("../icons/DragHandleIcon");
17
+ var _icons = require("../icons");
18
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); }
19
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; }
20
20
  var mapStateToProps = function mapStateToProps(state) {
@@ -98,9 +98,11 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
98
98
  backgroundColor: "var(--ds-surface, white)",
99
99
  borderRadius: '4px',
100
100
  border: "2px solid ".concat("var(--ds-surface, white)"),
101
- transform: direction === 'column' ? 'none' : 'rotate(90deg)'
102
- }
103
- }, /*#__PURE__*/_react.default.createElement(_DragHandleIcon.DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/_react.default.createElement(_DragPreview.DragPreview, {
101
+ transform: direction === 'column' ? 'none' : 'rotate(90deg)',
102
+ pointerEvents: 'auto'
103
+ },
104
+ "data-testid": "table-floating-column-controls-drag-handle"
105
+ }, /*#__PURE__*/_react.default.createElement(_icons.DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/_react.default.createElement(_DragPreview.DragPreview, {
104
106
  direction: direction,
105
107
  width: previewWidth,
106
108
  height: previewHeight
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.ColumnControls = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _types = require("../../../types");
10
+ var _DragHandle = require("../../DragHandle");
11
+ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
12
+ var _rowHeights$, _colWidths$map$join;
13
+ var editorView = _ref.editorView,
14
+ tableActive = _ref.tableActive,
15
+ tableRef = _ref.tableRef,
16
+ hoveredCell = _ref.hoveredCell,
17
+ isResizing = _ref.isResizing,
18
+ stickyTop = _ref.stickyTop,
19
+ localId = _ref.localId,
20
+ rowHeights = _ref.rowHeights,
21
+ colWidths = _ref.colWidths;
22
+ if (!tableRef) {
23
+ return null;
24
+ }
25
+ var firstRow = tableRef.querySelector('tr');
26
+ var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
27
+ var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
28
+ var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
29
+ return width ? "".concat(width - 1, "px") : '0px';
30
+ }).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
31
+ var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
32
+ var _onClick = function onClick(index, event) {};
33
+ var onMouseOver = function onMouseOver() {};
34
+ var onMouseOut = function onMouseOut() {};
35
+ return /*#__PURE__*/_react.default.createElement("div", {
36
+ className: _types.TableCssClassName.COLUMN_CONTROLS_WITH_DRAG
37
+ }, /*#__PURE__*/_react.default.createElement("div", {
38
+ className: _types.TableCssClassName.COLUMN_CONTROLS_INNER,
39
+ "data-testid": "table-floating-column-controls",
40
+ style: {
41
+ gridTemplateColumns: widths,
42
+ marginTop: marginTop
43
+ }
44
+ }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/_react.default.createElement("div", {
45
+ style: {
46
+ gridColumn: "".concat(colIndex + 1, " / span 1"),
47
+ marginTop: "-15px"
48
+ },
49
+ "data-column-control-index": colIndex,
50
+ "data-testid": "table-floating-column-control"
51
+ }, /*#__PURE__*/_react.default.createElement(_DragHandle.DragHandle, {
52
+ direction: "column",
53
+ indexes: [colIndex],
54
+ onClick: function onClick(event) {
55
+ return _onClick(colIndex, event);
56
+ },
57
+ onMouseOver: onMouseOver,
58
+ onMouseOut: onMouseOut,
59
+ tableLocalId: localId || ''
60
+ }))));
61
+ };
62
+ var _default = exports.default = ColumnControls;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ColumnDropTarget = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _closestEdge = require("@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge");
10
+ var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
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; }
13
+ var ColumnDropTarget = exports.ColumnDropTarget = function ColumnDropTarget(_ref) {
14
+ var index = _ref.index,
15
+ localId = _ref.localId,
16
+ width = _ref.width,
17
+ height = _ref.height,
18
+ marginTop = _ref.marginTop;
19
+ var dropTargetRef = (0, _react.useRef)(null);
20
+ (0, _react.useEffect)(function () {
21
+ if (!dropTargetRef.current) {
22
+ return;
23
+ }
24
+ return (0, _element.dropTargetForElements)({
25
+ element: dropTargetRef.current,
26
+ canDrop: function canDrop(_ref2) {
27
+ var _data$indexes, _data$indexes2;
28
+ var source = _ref2.source;
29
+ var data = source.data;
30
+ return (
31
+ // Only draggables of row type can be dropped on this target
32
+ data.type === 'table-column' &&
33
+ // Only draggables which came from the same table can be dropped on this target
34
+ data.localId === localId &&
35
+ // Only draggables which DO NOT include this drop targets index can be dropped
36
+ !!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
37
+ );
38
+ },
39
+ getIsSticky: function getIsSticky() {
40
+ return true;
41
+ },
42
+ getData: function getData(_ref3) {
43
+ var input = _ref3.input,
44
+ element = _ref3.element;
45
+ var data = {
46
+ localId: localId,
47
+ type: 'table-column',
48
+ targetIndex: index
49
+ };
50
+ return (0, _closestEdge.attachClosestEdge)(data, {
51
+ input: input,
52
+ element: element,
53
+ allowedEdges: ['left', 'right']
54
+ });
55
+ }
56
+ });
57
+ }, [index, localId]);
58
+ return /*#__PURE__*/_react.default.createElement("div", {
59
+ ref: dropTargetRef,
60
+ style: {
61
+ width: width && "".concat(width - 1, "px"),
62
+ height: height && "".concat(height, "px"),
63
+ marginTop: marginTop && "".concat(marginTop, "px"),
64
+ pointerEvents: 'auto'
65
+ },
66
+ "data-drop-target-index": index,
67
+ "data-drop-target-localid": localId,
68
+ "data-testid": "table-floating-column-controls-drop-target"
69
+ });
70
+ };
@@ -1,32 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _typeof = require("@babel/runtime/helpers/typeof");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = exports.ColumnDropTargets = void 0;
8
- var _react = _interopRequireWildcard(require("react"));
9
- var _closestEdge = require("@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge");
10
- var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
7
+ exports.ColumnDropTargets = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
11
9
  var _types = require("../../../types");
12
- var _utils = require("../../../utils");
13
- 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
- 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; }
10
+ var _ColumnDropTarget = require("./ColumnDropTarget");
15
11
  var ColumnDropTargets = exports.ColumnDropTargets = function ColumnDropTargets(_ref) {
16
12
  var _rowHeights$;
17
- var editorView = _ref.editorView,
18
- tableRef = _ref.tableRef,
13
+ var tableRef = _ref.tableRef,
19
14
  tableHeight = _ref.tableHeight,
20
15
  stickyTop = _ref.stickyTop,
21
- localId = _ref.localId;
22
- var colWidths = (0, _utils.getColumnsWidths)(editorView);
23
- var rowHeights = (0, _react.useMemo)(function () {
24
- // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
25
- if (tableRef && !!tableHeight) {
26
- return (0, _utils.getRowHeights)(tableRef);
27
- }
28
- return [0];
29
- }, [tableRef, tableHeight]);
16
+ localId = _ref.localId,
17
+ rowHeights = _ref.rowHeights,
18
+ colWidths = _ref.colWidths;
30
19
  if (!tableRef) {
31
20
  return null;
32
21
  }
@@ -34,12 +23,13 @@ var ColumnDropTargets = exports.ColumnDropTargets = function ColumnDropTargets(_
34
23
  var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
35
24
  var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
36
25
  return /*#__PURE__*/_react.default.createElement("div", {
37
- className: _types.TableCssClassName.COLUMN_DROP_TARGET_CONTROLS
26
+ className: _types.TableCssClassName.COLUMN_DROP_TARGET_CONTROLS,
27
+ contentEditable: false
38
28
  }, /*#__PURE__*/_react.default.createElement("div", {
39
29
  className: _types.TableCssClassName.COLUMN_CONTROLS_INNER,
40
30
  "data-testid": "table-floating-column-controls-drop-targets"
41
- }, colWidths.map(function (width, index) {
42
- return /*#__PURE__*/_react.default.createElement(ColumnDropTarget, {
31
+ }, colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width, index) {
32
+ return /*#__PURE__*/_react.default.createElement(_ColumnDropTarget.ColumnDropTarget, {
43
33
  key: index,
44
34
  index: index,
45
35
  localId: localId,
@@ -48,59 +38,4 @@ var ColumnDropTargets = exports.ColumnDropTargets = function ColumnDropTargets(_
48
38
  marginTop: marginTop
49
39
  });
50
40
  })));
51
- };
52
- var _default = exports.default = ColumnDropTargets;
53
- var ColumnDropTarget = function ColumnDropTarget(_ref2) {
54
- var index = _ref2.index,
55
- localId = _ref2.localId,
56
- width = _ref2.width,
57
- height = _ref2.height,
58
- marginTop = _ref2.marginTop;
59
- var dropTargetRef = (0, _react.useRef)(null);
60
- (0, _react.useEffect)(function () {
61
- if (!dropTargetRef.current) {
62
- return;
63
- }
64
- return (0, _element.dropTargetForElements)({
65
- element: dropTargetRef.current,
66
- canDrop: function canDrop(_ref3) {
67
- var _data$indexes, _data$indexes2;
68
- var source = _ref3.source;
69
- var data = source.data;
70
- return (
71
- // Only draggables of row type can be dropped on this target
72
- data.type === 'table-column' &&
73
- // Only draggables which came from the same table can be dropped on this target
74
- data.localId === localId &&
75
- // Only draggables which DO NOT include this drop targets index can be dropped
76
- !!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
77
- );
78
- },
79
- getData: function getData(_ref4) {
80
- var input = _ref4.input,
81
- element = _ref4.element;
82
- var data = {
83
- localId: localId,
84
- type: 'table-column',
85
- targetIndex: index
86
- };
87
- return (0, _closestEdge.attachClosestEdge)(data, {
88
- input: input,
89
- element: element,
90
- allowedEdges: ['left', 'right']
91
- });
92
- }
93
- });
94
- }, [index, localId]);
95
- return /*#__PURE__*/_react.default.createElement("div", {
96
- ref: dropTargetRef,
97
- style: {
98
- width: width && "".concat(width - 1, "px"),
99
- height: height && "".concat(height, "px"),
100
- marginTop: marginTop && "".concat(marginTop, "px")
101
- },
102
- "data-drop-target-index": index,
103
- "data-drop-target-localid": localId,
104
- "data-testid": "table-floating-column-controls-drop-target"
105
- });
106
41
  };
@@ -8,7 +8,11 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = exports.TableFloatingColumnControls = void 0;
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _react = _interopRequireWildcard(require("react"));
11
- var _editorTables = require("@atlaskit/editor-tables");
11
+ var _reactDom = _interopRequireDefault(require("react-dom"));
12
+ var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
13
+ var _types = require("../../types");
14
+ var _utils = require("../../utils");
15
+ var _ColumnControls = require("./ColumnControls");
12
16
  var _ColumnDropTargets = require("./ColumnDropTargets");
13
17
  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
18
  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; }
@@ -18,8 +22,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
18
22
  var TableFloatingColumnControls = exports.TableFloatingColumnControls = function TableFloatingColumnControls(_ref) {
19
23
  var editorView = _ref.editorView,
20
24
  tableRef = _ref.tableRef,
25
+ getNode = _ref.getNode,
21
26
  tableActive = _ref.tableActive,
22
27
  hasHeaderRow = _ref.hasHeaderRow,
28
+ hoveredCell = _ref.hoveredCell,
29
+ isResizing = _ref.isResizing,
23
30
  stickyHeader = _ref.stickyHeader,
24
31
  selection = _ref.selection;
25
32
  var _useState = (0, _react.useState)({
@@ -29,6 +36,12 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
29
36
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
30
37
  tableRect = _useState2[0],
31
38
  setTableRect = _useState2[1];
39
+ var _useState3 = (0, _react.useState)(false),
40
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
41
+ hasDropTargets = _useState4[0],
42
+ setHasDropTargets = _useState4[1];
43
+ var node = getNode();
44
+ var currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
32
45
  (0, _react.useEffect)(function () {
33
46
  var _window;
34
47
  if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
@@ -60,31 +73,60 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
60
73
  };
61
74
  }
62
75
  }, [tableRef]);
63
- var selectedLocalId = (0, _react.useMemo)(function () {
64
- if (!selection) {
65
- return undefined;
66
- }
67
- var tableNode = (0, _editorTables.findTable)(selection);
68
- if (!tableNode) {
69
- return undefined;
76
+ (0, _react.useEffect)(function () {
77
+ return (0, _element.monitorForElements)({
78
+ canMonitor: function canMonitor(_ref2) {
79
+ var source = _ref2.source;
80
+ var _ref3 = source.data,
81
+ type = _ref3.type,
82
+ localId = _ref3.localId,
83
+ indexes = _ref3.indexes;
84
+ return type === 'table-column' && !!(indexes !== null && indexes !== void 0 && indexes.length) && localId === currentNodeLocalId;
85
+ },
86
+ onDragStart: function onDragStart() {
87
+ setHasDropTargets(true);
88
+ },
89
+ onDrop: function onDrop() {
90
+ setHasDropTargets(false);
91
+ }
92
+ });
93
+ }, [editorView, currentNodeLocalId]);
94
+ var rowHeights = (0, _react.useMemo)(function () {
95
+ // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
96
+ if (tableRef && !!tableRect.height) {
97
+ return (0, _utils.getRowHeights)(tableRef);
70
98
  }
71
- return tableNode.node.attrs.localId;
72
- }, [selection]);
99
+ return [0];
100
+ }, [tableRef, tableRect.height]);
73
101
  if (!tableRef) {
74
102
  return null;
75
103
  }
104
+ var colWidths = (0, _utils.getColumnsWidths)(editorView);
76
105
  var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
77
- return /*#__PURE__*/_react.default.createElement("div", {
78
- onMouseDown: function onMouseDown(e) {
79
- return e.preventDefault();
106
+ var mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
107
+ return /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/_react.default.createElement("div", {
108
+ className: _types.TableCssClassName.COLUMN_CONTROLS_WRAPPER,
109
+ style: {
110
+ pointerEvents: 'none'
80
111
  },
81
112
  "data-testid": "table-floating-column-controls-wrapper"
82
- }, tableActive && /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
113
+ }, /*#__PURE__*/_react.default.createElement(_ColumnControls.ColumnControls, {
83
114
  editorView: editorView,
115
+ hoveredCell: hoveredCell,
116
+ tableRef: tableRef,
117
+ isResizing: isResizing,
118
+ tableActive: tableActive,
119
+ stickyTop: tableActive ? stickyTop : undefined,
120
+ localId: currentNodeLocalId,
121
+ rowHeights: rowHeights,
122
+ colWidths: colWidths
123
+ }), hasDropTargets && /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
84
124
  tableRef: tableRef,
85
125
  stickyTop: tableActive ? stickyTop : undefined,
86
126
  tableHeight: tableRect.height,
87
- localId: selectedLocalId
88
- }));
127
+ localId: currentNodeLocalId,
128
+ rowHeights: rowHeights,
129
+ colWidths: colWidths
130
+ })), mountTo);
89
131
  };
90
132
  var _default = exports.default = TableFloatingColumnControls;