@atlaskit/editor-plugin-table 5.3.8 → 5.3.10

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 (77) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/commands/hover.js +4 -2
  3. package/dist/cjs/plugins/table/event-handlers.js +7 -4
  4. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
  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/ui/DragHandle/index.js +6 -4
  9. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +16 -25
  10. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +70 -0
  11. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +12 -77
  12. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +45 -20
  13. package/dist/cjs/plugins/table/ui/icons/index.js +19 -0
  14. package/dist/cjs/plugins/table/ui/ui-styles.js +1 -1
  15. package/dist/es2019/plugins/table/commands/hover.js +4 -2
  16. package/dist/es2019/plugins/table/event-handlers.js +7 -4
  17. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
  18. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  19. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  20. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  21. package/dist/es2019/plugins/table/ui/DragHandle/index.js +5 -3
  22. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +14 -21
  23. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +62 -0
  24. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +8 -74
  25. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +45 -19
  26. package/dist/es2019/plugins/table/ui/icons/index.js +2 -0
  27. package/dist/es2019/plugins/table/ui/ui-styles.js +0 -1
  28. package/dist/esm/plugins/table/commands/hover.js +4 -2
  29. package/dist/esm/plugins/table/event-handlers.js +7 -4
  30. package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
  31. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  32. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  33. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  34. package/dist/esm/plugins/table/ui/DragHandle/index.js +5 -3
  35. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +15 -22
  36. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +61 -0
  37. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +9 -72
  38. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +45 -20
  39. package/dist/esm/plugins/table/ui/icons/index.js +2 -0
  40. package/dist/esm/plugins/table/ui/ui-styles.js +1 -1
  41. package/dist/types/plugins/table/commands/hover.d.ts +1 -1
  42. package/dist/types/plugins/table/types.d.ts +9 -4
  43. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +4 -3
  44. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
  45. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
  46. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +4 -2
  47. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -2
  48. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +2 -2
  49. package/dist/types/plugins/table/ui/icons/index.d.ts +2 -0
  50. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +1 -1
  51. package/dist/types-ts4.5/plugins/table/types.d.ts +9 -4
  52. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +4 -3
  53. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
  54. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
  55. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +4 -2
  56. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -2
  57. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +2 -2
  58. package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +2 -0
  59. package/package.json +2 -1
  60. package/src/__tests__/unit/event-handlers.ts +4 -1
  61. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +58 -12
  62. package/src/plugins/table/commands/hover.ts +7 -2
  63. package/src/plugins/table/event-handlers.ts +18 -4
  64. package/src/plugins/table/nodeviews/TableComponent.tsx +2 -1
  65. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +1 -4
  66. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -2
  67. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +5 -0
  68. package/src/plugins/table/types.ts +14 -4
  69. package/src/plugins/table/ui/DragHandle/index.tsx +3 -1
  70. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +36 -39
  71. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +74 -0
  72. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -80
  73. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +62 -32
  74. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +2 -2
  75. package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -2
  76. package/src/plugins/table/ui/icons/index.ts +2 -0
  77. package/src/plugins/table/ui/ui-styles.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.3.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#42000](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/42000) [`62e03b45cf6`](https://bitbucket.org/atlassian/atlassian-frontend/commits/62e03b45cf6) - Updated the column drag handle to display the drag preview correctly
8
+
9
+ ## 5.3.9
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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
14
+
3
15
  ## 5.3.8
4
16
 
5
17
  ### Patch Changes
@@ -138,14 +138,16 @@ var hideResizeHandleLine = exports.hideResizeHandleLine = function hideResizeHan
138
138
  };
139
139
  });
140
140
  };
141
- var hoverCell = exports.hoverCell = function hoverCell(rowIndex, colIndex) {
141
+ var hoverCell = exports.hoverCell = function hoverCell(rowIndex, colIndex, colWidth, colHeight) {
142
142
  return (0, _pluginFactory.createCommand)(function () {
143
143
  return {
144
144
  type: 'HOVER_CELL',
145
145
  data: {
146
146
  hoveredCell: {
147
147
  rowIndex: rowIndex,
148
- colIndex: colIndex
148
+ colIndex: colIndex,
149
+ colWidth: colWidth,
150
+ colHeight: colHeight
149
151
  }
150
152
  }
151
153
  };
@@ -180,7 +180,7 @@ var handleMouseLeave = exports.handleMouseLeave = function handleMouseLeave(view
180
180
  return true;
181
181
  }
182
182
  if (isDragAndDropEnabled) {
183
- (0, _commands.hoverCell)(undefined, undefined)(state, dispatch);
183
+ (0, _commands.hoverCell)()(state, dispatch);
184
184
  }
185
185
  if ((typeof insertColumnButtonIndex !== 'undefined' || typeof insertRowButtonIndex !== 'undefined') && (0, _commands.hideInsertColumnOrRowButton)()(state, dispatch)) {
186
186
  return true;
@@ -326,7 +326,8 @@ var whenTableInFocus = exports.whenTableInFocus = function whenTableInFocus(even
326
326
  var trackCellLocation = function trackCellLocation(view, mouseEvent) {
327
327
  var target = mouseEvent.target;
328
328
  var maybeTableCell = (0, _utils.isElementInTableCell)(target);
329
- if (!maybeTableCell) {
329
+ var tableRef = (0, _pluginFactory.getPluginState)(view.state).tableRef;
330
+ if (!maybeTableCell || !tableRef) {
330
331
  return;
331
332
  }
332
333
  var colIndex = maybeTableCell.cellIndex;
@@ -334,8 +335,10 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
334
335
  var rowIndex = rowElement && rowElement.rowIndex;
335
336
  var _getPluginState8 = (0, _pluginFactory.getPluginState)(view.state),
336
337
  hoveredCell = _getPluginState8.hoveredCell;
337
- if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex) {
338
- (0, _commands.hoverCell)(rowIndex, colIndex)(view.state, view.dispatch);
338
+ var colHeight = tableRef.offsetHeight;
339
+ var colWidth = maybeTableCell.offsetWidth;
340
+ if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex || hoveredCell.colWidth !== colWidth || hoveredCell.colHeight !== colHeight) {
341
+ (0, _commands.hoverCell)(rowIndex, colIndex, colWidth, colHeight)(view.state, view.dispatch);
339
342
  }
340
343
  };
341
344
  var withCellTracking = exports.withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
@@ -499,13 +499,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
499
499
  var colControls = /*#__PURE__*/_react.default.createElement(_TableFloatingColumnControls.default, {
500
500
  editorView: view,
501
501
  tableRef: tableRef,
502
+ getNode: getNode,
502
503
  tableActive: tableActive,
503
504
  hoveredRows: hoveredRows,
504
505
  hoveredCell: hoveredCell,
505
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,
@@ -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
  };
@@ -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
@@ -1,44 +1,33 @@
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
7
  exports.default = exports.ColumnControls = void 0;
8
- var _react = _interopRequireWildcard(require("react"));
8
+ var _react = _interopRequireDefault(require("react"));
9
9
  var _types = require("../../../types");
10
- var _utils = require("../../../utils");
11
10
  var _DragHandle = require("../../DragHandle");
12
- 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); }
13
- 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; }
14
11
  var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
15
- var _rowHeights$;
12
+ var _rowHeights$, _colWidths$map$join;
16
13
  var editorView = _ref.editorView,
17
14
  tableActive = _ref.tableActive,
18
15
  tableRef = _ref.tableRef,
19
16
  hoveredCell = _ref.hoveredCell,
20
17
  isResizing = _ref.isResizing,
21
- tableHeight = _ref.tableHeight,
22
18
  stickyTop = _ref.stickyTop,
23
- localId = _ref.localId;
24
- var rowHeights = (0, _react.useMemo)(function () {
25
- // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
26
- if (tableRef && !!tableHeight) {
27
- return (0, _utils.getRowHeights)(tableRef);
28
- }
29
- return [0];
30
- }, [tableRef, tableHeight]);
19
+ localId = _ref.localId,
20
+ rowHeights = _ref.rowHeights,
21
+ colWidths = _ref.colWidths;
31
22
  if (!tableRef) {
32
23
  return null;
33
24
  }
34
25
  var firstRow = tableRef.querySelector('tr');
35
26
  var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
36
27
  var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
37
- var colWidths = (0, _utils.getColumnsWidths)(editorView);
38
- var widths = colWidths.map(function (width) {
28
+ var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
39
29
  return width ? "".concat(width - 1, "px") : '0px';
40
- }).join(' ');
41
- var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
30
+ }).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
42
31
  var _onClick = function onClick(index, event) {};
43
32
  var onMouseOver = function onMouseOver() {};
44
33
  var onMouseOut = function onMouseOut() {};
@@ -51,22 +40,24 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
51
40
  gridTemplateColumns: widths,
52
41
  marginTop: marginTop
53
42
  }
54
- }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/_react.default.createElement("div", {
43
+ }, tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/_react.default.createElement("div", {
55
44
  style: {
56
- gridColumn: "".concat(colIndex + 1, " / span 1"),
45
+ gridColumn: "".concat(hoveredCell.colIndex + 1, " / span 1"),
57
46
  marginTop: "-15px"
58
47
  },
59
- "data-column-control-index": colIndex,
48
+ "data-column-control-index": hoveredCell.colIndex,
60
49
  "data-testid": "table-floating-column-control"
61
50
  }, /*#__PURE__*/_react.default.createElement(_DragHandle.DragHandle, {
62
51
  direction: "column",
63
- indexes: [],
52
+ indexes: [hoveredCell.colIndex],
64
53
  onClick: function onClick(event) {
65
- return _onClick(colIndex, event);
54
+ return _onClick(hoveredCell.colIndex, event);
66
55
  },
67
56
  onMouseOver: onMouseOver,
68
57
  onMouseOut: onMouseOut,
69
- tableLocalId: localId || ''
58
+ tableLocalId: localId || '',
59
+ previewWidth: hoveredCell.colWidth,
60
+ previewHeight: hoveredCell.colHeight
70
61
  }))));
71
62
  };
72
63
  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
  };
@@ -9,8 +9,9 @@ exports.default = exports.TableFloatingColumnControls = void 0;
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
  var _reactDom = _interopRequireDefault(require("react-dom"));
12
- var _editorTables = require("@atlaskit/editor-tables");
12
+ var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
13
13
  var _types = require("../../types");
14
+ var _utils = require("../../utils");
14
15
  var _ColumnControls = require("./ColumnControls");
15
16
  var _ColumnDropTargets = require("./ColumnDropTargets");
16
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); }
@@ -21,6 +22,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
21
22
  var TableFloatingColumnControls = exports.TableFloatingColumnControls = function TableFloatingColumnControls(_ref) {
22
23
  var editorView = _ref.editorView,
23
24
  tableRef = _ref.tableRef,
25
+ getNode = _ref.getNode,
24
26
  tableActive = _ref.tableActive,
25
27
  hasHeaderRow = _ref.hasHeaderRow,
26
28
  hoveredCell = _ref.hoveredCell,
@@ -34,6 +36,12 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
34
36
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
35
37
  tableRect = _useState2[0],
36
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;
37
45
  (0, _react.useEffect)(function () {
38
46
  var _window;
39
47
  if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
@@ -65,26 +73,41 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
65
73
  };
66
74
  }
67
75
  }, [tableRef]);
68
- var selectedLocalId = (0, _react.useMemo)(function () {
69
- if (!selection) {
70
- return undefined;
71
- }
72
- var tableNode = (0, _editorTables.findTable)(selection);
73
- if (!tableNode) {
74
- 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);
75
98
  }
76
- return tableNode.node.attrs.localId;
77
- }, [selection]);
99
+ return [0];
100
+ }, [tableRef, tableRect.height]);
78
101
  if (!tableRef) {
79
102
  return null;
80
103
  }
104
+ var colWidths = (0, _utils.getColumnsWidths)(editorView);
81
105
  var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
82
106
  var mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
83
107
  return /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/_react.default.createElement("div", {
84
- className: _types.TableCssClassName.COLUMN_CONTROLS_WRAPPER
85
- }, /*#__PURE__*/_react.default.createElement("div", {
86
- onMouseDown: function onMouseDown(e) {
87
- return e.preventDefault();
108
+ className: _types.TableCssClassName.COLUMN_CONTROLS_WRAPPER,
109
+ style: {
110
+ pointerEvents: 'none'
88
111
  },
89
112
  "data-testid": "table-floating-column-controls-wrapper"
90
113
  }, /*#__PURE__*/_react.default.createElement(_ColumnControls.ColumnControls, {
@@ -94,14 +117,16 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
94
117
  isResizing: isResizing,
95
118
  tableActive: tableActive,
96
119
  stickyTop: tableActive ? stickyTop : undefined,
97
- tableHeight: tableRect.height,
98
- localId: selectedLocalId
99
- }), /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
100
- editorView: editorView,
120
+ localId: currentNodeLocalId,
121
+ rowHeights: rowHeights,
122
+ colWidths: colWidths
123
+ }), hasDropTargets && /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
101
124
  tableRef: tableRef,
102
125
  stickyTop: tableActive ? stickyTop : undefined,
103
126
  tableHeight: tableRect.height,
104
- localId: selectedLocalId
105
- }))), mountTo);
127
+ localId: currentNodeLocalId,
128
+ rowHeights: rowHeights,
129
+ colWidths: colWidths
130
+ })), mountTo);
106
131
  };
107
132
  var _default = exports.default = TableFloatingColumnControls;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "DragHandleIcon", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _DragHandleIcon.DragHandleIcon;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "DragInMotionIcon", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _DragInMotionIcon.DragInMotionIcon;
16
+ }
17
+ });
18
+ var _DragHandleIcon = require("./DragHandleIcon");
19
+ var _DragInMotionIcon = require("./DragInMotionIcon");
@@ -71,7 +71,7 @@ var getFloatingDotOverrides = function getFloatingDotOverrides(props) {
71
71
  return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? (0, _react.css)(_templateObject18 || (_templateObject18 = (0, _taggedTemplateLiteral2.default)(["\n tr\n th:last-child\n .", "::before,\n tr\n td:last-child\n .", "::before {\n content: '';\n background-color: ", ";\n position: absolute;\n height: ", "px;\n width: ", "px;\n border-radius: 50%;\n pointer-events: none;\n top: ", ";\n right: 0px;\n }\n "])), _types.TableCssClassName.COLUMN_CONTROLS_DECORATIONS, _types.TableCssClassName.COLUMN_CONTROLS_DECORATIONS, (0, _consts.tableBorderColor)(props), _consts.lineMarkerSize, _consts.lineMarkerSize, "var(--ds-space-025, 2px)") : '';
72
72
  };
73
73
  var floatingColumnControls = exports.floatingColumnControls = function floatingColumnControls(props) {
74
- return (0, _react.css)(_templateObject19 || (_templateObject19 = (0, _taggedTemplateLiteral2.default)(["\n .", " {\n box-sizing: border-box;\n position: absolute;\n top: 0;\n z-index: -1;\n\n .", " {\n display: flex;\n flex-direction: row;\n }\n }\n\n .", " {\n box-sizing: border-box;\n\n .", " {\n display: grid;\n justify-items: center;\n }\n }\n "])), _types.TableCssClassName.COLUMN_DROP_TARGET_CONTROLS, _types.TableCssClassName.COLUMN_CONTROLS_INNER, _types.TableCssClassName.COLUMN_CONTROLS_WITH_DRAG, _types.TableCssClassName.COLUMN_CONTROLS_INNER);
74
+ return (0, _react.css)(_templateObject19 || (_templateObject19 = (0, _taggedTemplateLiteral2.default)(["\n .", " {\n box-sizing: border-box;\n position: absolute;\n top: 0;\n\n .", " {\n display: flex;\n flex-direction: row;\n }\n }\n\n .", " {\n box-sizing: border-box;\n\n .", " {\n display: grid;\n justify-items: center;\n }\n }\n "])), _types.TableCssClassName.COLUMN_DROP_TARGET_CONTROLS, _types.TableCssClassName.COLUMN_CONTROLS_INNER, _types.TableCssClassName.COLUMN_CONTROLS_WITH_DRAG, _types.TableCssClassName.COLUMN_CONTROLS_INNER);
75
75
  };
76
76
  var rowControlsWrapperDotStyle = exports.rowControlsWrapperDotStyle = function rowControlsWrapperDotStyle(props) {
77
77
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.drag-and-drop')) {
@@ -99,13 +99,15 @@ export const hideResizeHandleLine = () => createCommand(state => ({
99
99
  decorationSet: updatePluginStateDecorations(state, [], TableDecorations.COLUMN_RESIZING_HANDLE_LINE)
100
100
  }
101
101
  }));
102
- export const hoverCell = (rowIndex, colIndex) => createCommand(() => {
102
+ export const hoverCell = (rowIndex, colIndex, colWidth, colHeight) => createCommand(() => {
103
103
  return {
104
104
  type: 'HOVER_CELL',
105
105
  data: {
106
106
  hoveredCell: {
107
107
  rowIndex,
108
- colIndex
108
+ colIndex,
109
+ colWidth,
110
+ colHeight
109
111
  }
110
112
  }
111
113
  };
@@ -179,7 +179,7 @@ export const handleMouseLeave = (view, event) => {
179
179
  return true;
180
180
  }
181
181
  if (isDragAndDropEnabled) {
182
- hoverCell(undefined, undefined)(state, dispatch);
182
+ hoverCell()(state, dispatch);
183
183
  }
184
184
  if ((typeof insertColumnButtonIndex !== 'undefined' || typeof insertRowButtonIndex !== 'undefined') && hideInsertColumnOrRowButton()(state, dispatch)) {
185
185
  return true;
@@ -334,7 +334,8 @@ export const whenTableInFocus = (eventHandler, elementContentRects) => (view, mo
334
334
  const trackCellLocation = (view, mouseEvent) => {
335
335
  const target = mouseEvent.target;
336
336
  const maybeTableCell = isElementInTableCell(target);
337
- if (!maybeTableCell) {
337
+ const tableRef = getPluginState(view.state).tableRef;
338
+ if (!maybeTableCell || !tableRef) {
338
339
  return;
339
340
  }
340
341
  const colIndex = maybeTableCell.cellIndex;
@@ -343,8 +344,10 @@ const trackCellLocation = (view, mouseEvent) => {
343
344
  const {
344
345
  hoveredCell
345
346
  } = getPluginState(view.state);
346
- if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex) {
347
- hoverCell(rowIndex, colIndex)(view.state, view.dispatch);
347
+ const colHeight = tableRef.offsetHeight;
348
+ const colWidth = maybeTableCell.offsetWidth;
349
+ if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex || hoveredCell.colWidth !== colWidth || hoveredCell.colHeight !== colHeight) {
350
+ hoverCell(rowIndex, colIndex, colWidth, colHeight)(view.state, view.dispatch);
348
351
  }
349
352
  };
350
353
  export const withCellTracking = (eventHandler, elementContentRects) => (view, mouseEvent) => {