@atlaskit/editor-plugin-table 5.3.10 → 5.3.12

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 (58) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +3 -2
  3. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +5 -2
  4. package/dist/cjs/plugins/table/ui/DragHandle/index.js +11 -25
  5. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +56 -20
  6. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  7. package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +15 -27
  8. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +68 -18
  9. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +47 -29
  10. package/dist/cjs/plugins/table/ui/common-styles.js +2 -2
  11. package/dist/cjs/plugins/table/ui/icons/DragHandleIcon.js +11 -52
  12. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +3 -2
  13. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +6 -3
  14. package/dist/es2019/plugins/table/ui/DragHandle/index.js +10 -24
  15. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +57 -15
  16. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  17. package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +4 -20
  18. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +69 -17
  19. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +24 -2
  20. package/dist/es2019/plugins/table/ui/common-styles.js +64 -4
  21. package/dist/es2019/plugins/table/ui/icons/DragHandleIcon.js +11 -52
  22. package/dist/esm/plugins/table/nodeviews/TableComponent.js +3 -2
  23. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +6 -3
  24. package/dist/esm/plugins/table/ui/DragHandle/index.js +11 -25
  25. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +53 -19
  26. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  27. package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +16 -28
  28. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +67 -19
  29. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +48 -30
  30. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  31. package/dist/esm/plugins/table/ui/icons/DragHandleIcon.js +11 -51
  32. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +3 -3
  33. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +4 -3
  34. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  35. package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +1 -1
  36. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +4 -2
  37. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  38. package/dist/types/plugins/table/ui/icons/DragHandleIcon.d.ts +1 -6
  39. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +3 -3
  40. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +4 -3
  41. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  42. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +1 -1
  43. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +4 -2
  44. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  45. package/dist/types-ts4.5/plugins/table/ui/icons/DragHandleIcon.d.ts +1 -6
  46. package/package.json +2 -2
  47. package/src/__tests__/unit/ui/NumberColumn.tsx +5 -8
  48. package/src/__tests__/unit/ui/RowDragControls.tsx +6 -0
  49. package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
  50. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +11 -3
  51. package/src/plugins/table/ui/DragHandle/index.tsx +10 -26
  52. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +69 -23
  53. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +3 -0
  54. package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +10 -15
  55. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +95 -26
  56. package/src/plugins/table/ui/TableFloatingControls/index.tsx +17 -1
  57. package/src/plugins/table/ui/common-styles.ts +67 -4
  58. package/src/plugins/table/ui/icons/DragHandleIcon.tsx +5 -69
@@ -1,7 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React, { Component } from 'react';
3
3
  import { browser } from '@atlaskit/editor-common/utils';
4
- import { hoverRows, selectRow } from '../../commands';
4
+ import { hoverCell, hoverRows, selectRow } from '../../commands';
5
+ import { getPluginState } from '../../pm-plugins/plugin-factory';
5
6
  import { isSelectionUpdated } from '../../utils';
6
7
  import { CornerControls } from './CornerControls';
7
8
  import NumberColumn from './NumberColumn';
@@ -30,6 +31,23 @@ export default class TableFloatingControls extends Component {
30
31
  } = this.props.editorView;
31
32
  hoverRows(rows, danger)(state, dispatch);
32
33
  });
34
+ // re-use across numbered columns and row controls
35
+ _defineProperty(this, "updateCellHoverLocation", rowIndex => {
36
+ const {
37
+ editorView,
38
+ tableActive
39
+ } = this.props;
40
+ const {
41
+ state,
42
+ dispatch
43
+ } = editorView;
44
+ const {
45
+ hoveredCell
46
+ } = getPluginState(state);
47
+ if (tableActive && hoveredCell.rowIndex !== rowIndex) {
48
+ hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
49
+ }
50
+ });
33
51
  }
34
52
  componentDidMount() {
35
53
  this.tryInitResizeObserver();
@@ -115,14 +133,18 @@ export default class TableFloatingControls extends Component {
115
133
  isInDanger: isInDanger,
116
134
  isResizing: isResizing,
117
135
  selectRow: this.selectRow,
136
+ updateCellHoverLocation: this.updateCellHoverLocation,
118
137
  stickyTop: stickyTop,
119
138
  isDragAndDropEnabled: isDragAndDropEnabled
120
139
  }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(DragControls, {
121
140
  tableRef: tableRef,
122
141
  hoveredCell: hoveredCell,
123
142
  editorView: editorView,
143
+ tableActive: tableActive,
144
+ isInDanger: isInDanger,
124
145
  hoverRows: this.hoverRows,
125
- selectRow: this.selectRow
146
+ selectRow: this.selectRow,
147
+ updateCellHoverLocation: this.updateCellHoverLocation
126
148
  }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
127
149
  editorView: editorView,
128
150
  tableRef: tableRef,
@@ -164,7 +164,7 @@ const tableRowControlStyles = () => {
164
164
  position: absolute;
165
165
  margin-top: ${tableMarginTop}px;
166
166
  left: -${tableToolbarSize + 1}px;
167
- z-index: ${rowControlsZIndex};
167
+ z-index: ${rowControlsZIndex + 4};
168
168
  }
169
169
  ` : css`
170
170
  .${ClassName.ROW_CONTROLS_WRAPPER} {
@@ -607,14 +607,74 @@ export const tableStyles = props => {
607
607
  align-items: center;
608
608
  position: absolute;
609
609
  left: -4px;
610
+ z-index: ${akEditorUnitZIndex};
610
611
  }
611
612
 
612
613
  .${ClassName.DRAG_HANDLE_BUTTON_CONTAINER} {
613
614
  cursor: grab;
614
- width: max-content;
615
615
  padding: 0;
616
- border: none;
617
- background: none;
616
+
617
+ border-radius: 6px;
618
+ width: max-content;
619
+ height: max-content;
620
+ border: 2px solid ${`var(--ds-surface, ${N0})`};
621
+ display: flex;
622
+ justify-content: center;
623
+ align-items: center;
624
+
625
+ svg {
626
+ rect {
627
+ //
628
+ fill: ${"var(--ds-background-accent-gray-subtlest, #F1F2F4)"};
629
+ }
630
+ g {
631
+ fill: ${"var(--ds-icon-subtle, #626F86)"};
632
+ }
633
+ }
634
+
635
+ &:hover {
636
+ svg {
637
+ rect {
638
+ fill: ${"var(--ds-background-accent-blue-subtle, #579DFF)"};
639
+ }
640
+ g {
641
+ fill: ${"var(--ds-icon-inverse, #FFF)"};
642
+ }
643
+ }
644
+ }
645
+
646
+ &.selected {
647
+ svg {
648
+ rect {
649
+ fill: ${"var(--ds-background-accent-blue-subtle, #579DFF)"};
650
+ }
651
+ g {
652
+ fill: ${"var(--ds-icon-inverse, #FFF)"};
653
+ }
654
+ }
655
+ }
656
+
657
+ &.danger {
658
+ svg {
659
+ rect {
660
+ fill: ${"var(--ds-background-accent-red-subtler-pressed, #F87462)"};
661
+ }
662
+ g {
663
+ fill: ${"var(--ds-border-inverse, #FFF)"};
664
+ }
665
+ }
666
+ }
667
+
668
+ &.disabled {
669
+ svg {
670
+ rect {
671
+ fill: ${"var(--ds-background-accent-gray-subtlest, #F1F2F4)"};
672
+ }
673
+ g {
674
+ fill: ${"var(--ds-border-inverse, #FFF)"};
675
+ }
676
+ }
677
+ }
618
678
  }
619
679
 
620
680
  ${floatingColumnControls(props)}
@@ -1,54 +1,13 @@
1
- /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
2
1
  import React from 'react';
3
- export const DragHandleIcon = ({
4
- backgroundColor,
5
- foregroundColor
6
- }) => /*#__PURE__*/React.createElement("svg", {
7
- width: "28",
8
- height: "20",
9
- viewBox: "0 0 28 20",
10
- fill: "none",
11
- xmlns: "http://www.w3.org/2000/svg"
2
+ export const DragHandleIcon = () => /*#__PURE__*/React.createElement("svg", {
3
+ xmlns: "http://www.w3.org/2000/svg",
4
+ width: "24",
5
+ height: "16",
6
+ fill: "none"
12
7
  }, /*#__PURE__*/React.createElement("rect", {
13
- x: "1",
14
- y: "1",
15
- width: "26",
16
- height: "18",
17
- rx: "5",
18
- fill: backgroundColor || '#F1F2F4'
19
- }), /*#__PURE__*/React.createElement("g", {
20
- clipPath: "url(#clip0_125_45007)"
21
- }, /*#__PURE__*/React.createElement("path", {
22
- d: "M11 12C11 11.4477 10.5523 11 10 11C9.44772 11 9 11.4477 9 12C9 12.5523 9.44772 13 10 13C10.5523 13 11 12.5523 11 12Z",
23
- fill: foregroundColor || '#626F86'
24
- }), /*#__PURE__*/React.createElement("path", {
25
- d: "M11 8C11 7.44772 10.5523 7 10 7C9.44772 7 9 7.44772 9 8C9 8.55228 9.44772 9 10 9C10.5523 9 11 8.55228 11 8Z",
26
- fill: foregroundColor || '#626F86'
27
- }), /*#__PURE__*/React.createElement("path", {
28
- d: "M19 12C19 11.4477 18.5523 11 18 11C17.4477 11 17 11.4477 17 12C17 12.5523 17.4477 13 18 13C18.5523 13 19 12.5523 19 12Z",
29
- fill: foregroundColor || '#626F86'
30
- }), /*#__PURE__*/React.createElement("path", {
31
- d: "M19 8C19 7.44772 18.5523 7 18 7C17.4477 7 17 7.44772 17 8C17 8.55228 17.4477 9 18 9C18.5523 9 19 8.55228 19 8Z",
32
- fill: foregroundColor || '#626F86'
33
- }), /*#__PURE__*/React.createElement("path", {
34
- d: "M15 12C15 11.4477 14.5523 11 14 11C13.4477 11 13 11.4477 13 12C13 12.5523 13.4477 13 14 13C14.5523 13 15 12.5523 15 12Z",
35
- fill: foregroundColor || '#626F86'
36
- }), /*#__PURE__*/React.createElement("path", {
37
- d: "M15 8C15 7.44772 14.5523 7 14 7C13.4477 7 13 7.44772 13 8C13 8.55228 13.4477 9 14 9C14.5523 9 15 8.55228 15 8Z",
38
- fill: foregroundColor || '#626F86'
39
- })), /*#__PURE__*/React.createElement("rect", {
40
- x: "1",
41
- y: "1",
42
- width: "26",
43
- height: "18",
44
- rx: "5",
45
- stroke: "white",
46
- strokeWidth: "2"
47
- }), /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
48
- id: "clip0_125_45007"
49
- }, /*#__PURE__*/React.createElement("rect", {
50
- width: "16",
51
- height: "24",
52
- fill: "white",
53
- transform: "matrix(0 -1 1 0 2 18)"
54
- }))));
8
+ width: "24",
9
+ height: "16",
10
+ rx: "4"
11
+ }), /*#__PURE__*/React.createElement("g", null, /*#__PURE__*/React.createElement("path", {
12
+ d: "M9 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM9 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM17 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM17 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM13 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM13 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z"
13
+ })));
@@ -489,11 +489,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
489
489
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
490
490
  stickyHeader: this.state.stickyHeader
491
491
  }));
492
- var colControls = /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
492
+ var colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
493
493
  editorView: view,
494
494
  tableRef: tableRef,
495
495
  getNode: getNode,
496
496
  tableActive: tableActive,
497
+ isInDanger: isInDanger,
497
498
  hoveredRows: hoveredRows,
498
499
  hoveredCell: hoveredCell,
499
500
  isResizing: isResizing,
@@ -505,7 +506,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
505
506
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
506
507
  stickyHeader: this.state.stickyHeader,
507
508
  getEditorFeatureFlags: this.props.getEditorFeatureFlags
508
- });
509
+ }) : null;
509
510
  var shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
510
511
  var shadowStyle = memoizeOne(function (visible) {
511
512
  return {
@@ -1,5 +1,5 @@
1
1
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
- import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
2
+ import { moveColumn, moveRow, selectColumn, selectRow } from '@atlaskit/editor-tables/utils';
3
3
  import { TableDecorations } from '../../types';
4
4
  import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
5
5
  import { DragAndDropActionType } from './actions';
@@ -71,7 +71,10 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
71
71
  if (sourceIndex === targetIndex) {
72
72
  return tr.setMeta('addToHistory', false);
73
73
  }
74
- var move = sourceType === 'table-row' ? moveRow : moveColumn;
75
- return move(sourceIndex, targetIndex)(tr);
74
+ var isTableRow = sourceType === 'table-row';
75
+ var move = isTableRow ? moveRow : moveColumn;
76
+ var newTr = move(sourceIndex, targetIndex)(tr);
77
+ var select = isTableRow ? selectRow : selectColumn;
78
+ return select(targetIndex)(newTr);
76
79
  });
77
80
  };
@@ -1,39 +1,25 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import React, { useEffect, useRef, useState } from 'react';
3
+ import classnames from 'classnames';
3
4
  import ReactDOM from 'react-dom';
4
5
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
5
6
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
6
- import { N200, N700 } from '@atlaskit/theme/colors';
7
7
  import { TableCssClassName as ClassName } from '../../types';
8
8
  import { DragPreview } from '../DragPreview';
9
9
  import { DragHandleIcon } from '../icons';
10
- var mapStateToProps = function mapStateToProps(state) {
11
- switch (state) {
12
- case 'danger':
13
- case 'disabled':
14
- case 'selected':
15
- case 'default':
16
- default:
17
- return {
18
- backgroundColor: "var(--ds-background-accent-gray-subtlest, ".concat(N200, ")"),
19
- foregroundColor: "var(--ds-icon-subtle, ".concat(N700, ")")
20
- };
21
- }
22
- };
23
10
  export var DragHandle = function DragHandle(_ref) {
24
11
  var tableLocalId = _ref.tableLocalId,
25
12
  _ref$direction = _ref.direction,
26
13
  direction = _ref$direction === void 0 ? 'row' : _ref$direction,
27
- _ref$state = _ref.state,
28
- state = _ref$state === void 0 ? 'default' : _ref$state,
14
+ _ref$appearance = _ref.appearance,
15
+ appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
29
16
  indexes = _ref.indexes,
30
17
  previewWidth = _ref.previewWidth,
31
18
  previewHeight = _ref.previewHeight,
32
- onClick = _ref.onClick,
33
19
  onMouseOver = _ref.onMouseOver,
34
- onMouseOut = _ref.onMouseOut;
20
+ onMouseOut = _ref.onMouseOut,
21
+ onClick = _ref.onClick;
35
22
  var dragHandleDivRef = useRef(null);
36
- var iconProps = mapStateToProps(state);
37
23
  var _useState = useState(null),
38
24
  _useState2 = _slicedToArray(_useState, 2),
39
25
  previewContainer = _useState2[0],
@@ -82,17 +68,17 @@ export var DragHandle = function DragHandle(_ref) {
82
68
  }
83
69
  }, [tableLocalId, direction, indexes]);
84
70
  return /*#__PURE__*/React.createElement("button", {
85
- className: ClassName.DRAG_HANDLE_BUTTON_CONTAINER,
71
+ className: classnames(ClassName.DRAG_HANDLE_BUTTON_CONTAINER, appearance),
86
72
  ref: dragHandleDivRef,
87
73
  style: {
88
- backgroundColor: "var(--ds-surface, white)",
89
- borderRadius: '4px',
90
- border: "2px solid ".concat("var(--ds-surface, white)"),
91
74
  transform: direction === 'column' ? 'none' : 'rotate(90deg)',
92
75
  pointerEvents: 'auto'
93
76
  },
94
- "data-testid": "table-floating-column-controls-drag-handle"
95
- }, /*#__PURE__*/React.createElement(DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
77
+ "data-testid": "table-floating-column-controls-drag-handle",
78
+ onMouseOver: onMouseOver,
79
+ onMouseOut: onMouseOut,
80
+ onClick: onClick
81
+ }, /*#__PURE__*/React.createElement(DragHandleIcon, null), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
96
82
  direction: direction,
97
83
  width: previewWidth,
98
84
  height: previewHeight
@@ -1,8 +1,22 @@
1
- import React from 'react';
1
+ import React, { useCallback, useMemo } from 'react';
2
+ import { CellSelection } from '@atlaskit/editor-tables';
3
+ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
4
+ import { clearHoverSelection, hoverColumns, selectColumn } from '../../../commands';
2
5
  import { TableCssClassName as ClassName } from '../../../types';
6
+ import { getSelectedColumnIndexes } from '../../../utils';
3
7
  import { DragHandle } from '../../DragHandle';
8
+ var getSelectedColumns = function getSelectedColumns(selection) {
9
+ if (selection instanceof CellSelection && selection.isColSelection()) {
10
+ var rect = getSelectionRect(selection);
11
+ if (!rect) {
12
+ return [];
13
+ }
14
+ return getSelectedColumnIndexes(rect);
15
+ }
16
+ return [];
17
+ };
4
18
  export var ColumnControls = function ColumnControls(_ref) {
5
- var _rowHeights$, _colWidths$map$join;
19
+ var _colWidths$map$join, _rowHeights$;
6
20
  var editorView = _ref.editorView,
7
21
  tableActive = _ref.tableActive,
8
22
  tableRef = _ref.tableRef,
@@ -10,20 +24,41 @@ export var ColumnControls = function ColumnControls(_ref) {
10
24
  isResizing = _ref.isResizing,
11
25
  stickyTop = _ref.stickyTop,
12
26
  localId = _ref.localId,
27
+ isInDanger = _ref.isInDanger,
13
28
  rowHeights = _ref.rowHeights,
14
29
  colWidths = _ref.colWidths;
15
- if (!tableRef) {
16
- return null;
17
- }
18
- var firstRow = tableRef.querySelector('tr');
19
- var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
20
- var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
21
30
  var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
22
31
  return width ? "".concat(width - 1, "px") : '0px';
23
32
  }).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
24
- var _onClick = function onClick(index, event) {};
25
- var onMouseOver = function onMouseOver() {};
26
- var onMouseOut = function onMouseOut() {};
33
+ var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
34
+ var selectedColIndexes = getSelectedColumns(editorView.state.selection);
35
+ var gridColumnPosition = useMemo(function () {
36
+ // if more than one row is selected, ensure the handle spans over the selected range
37
+ if (selectedColIndexes.includes(colIndex)) {
38
+ return "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
39
+ }
40
+ return "".concat(colIndex + 1, " / span 1");
41
+ }, [colIndex, selectedColIndexes]);
42
+ var firstRow = tableRef.querySelector('tr');
43
+ var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
44
+ var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
45
+ var handleClick = useCallback(function (event) {
46
+ var state = editorView.state,
47
+ dispatch = editorView.dispatch;
48
+ selectColumn(colIndex, event.shiftKey)(state, dispatch);
49
+ }, [colIndex, editorView]);
50
+ var handleMouseOver = useCallback(function () {
51
+ var state = editorView.state,
52
+ dispatch = editorView.dispatch;
53
+ hoverColumns([colIndex])(state, dispatch);
54
+ }, [colIndex, editorView]);
55
+ var handleMouseOut = useCallback(function () {
56
+ if (tableActive) {
57
+ var state = editorView.state,
58
+ dispatch = editorView.dispatch;
59
+ clearHoverSelection()(state, dispatch);
60
+ }
61
+ }, [editorView, tableActive]);
27
62
  return /*#__PURE__*/React.createElement("div", {
28
63
  className: ClassName.COLUMN_CONTROLS_WITH_DRAG
29
64
  }, /*#__PURE__*/React.createElement("div", {
@@ -35,22 +70,21 @@ export var ColumnControls = function ColumnControls(_ref) {
35
70
  }
36
71
  }, tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
37
72
  style: {
38
- gridColumn: "".concat(hoveredCell.colIndex + 1, " / span 1"),
73
+ gridColumn: gridColumnPosition,
39
74
  marginTop: "-15px"
40
75
  },
41
76
  "data-column-control-index": hoveredCell.colIndex,
42
77
  "data-testid": "table-floating-column-control"
43
78
  }, /*#__PURE__*/React.createElement(DragHandle, {
44
79
  direction: "column",
45
- indexes: [hoveredCell.colIndex],
46
- onClick: function onClick(event) {
47
- return _onClick(hoveredCell.colIndex, event);
48
- },
49
- onMouseOver: onMouseOver,
50
- onMouseOut: onMouseOut,
51
80
  tableLocalId: localId || '',
81
+ indexes: [hoveredCell.colIndex],
52
82
  previewWidth: hoveredCell.colWidth,
53
- previewHeight: hoveredCell.colHeight
83
+ previewHeight: hoveredCell.colHeight,
84
+ appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
85
+ onClick: handleClick,
86
+ onMouseOver: handleMouseOver,
87
+ onMouseOut: handleMouseOut
54
88
  }))));
55
89
  };
56
90
  export default ColumnControls;
@@ -18,7 +18,8 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
18
18
  hoveredCell = _ref.hoveredCell,
19
19
  isResizing = _ref.isResizing,
20
20
  stickyHeader = _ref.stickyHeader,
21
- selection = _ref.selection;
21
+ selection = _ref.selection,
22
+ isInDanger = _ref.isInDanger;
22
23
  var _useState = useState({
23
24
  width: 0,
24
25
  height: 0
@@ -108,6 +109,7 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
108
109
  tableActive: tableActive,
109
110
  stickyTop: tableActive ? stickyTop : undefined,
110
111
  localId: currentNodeLocalId,
112
+ isInDanger: isInDanger,
111
113
  rowHeights: rowHeights,
112
114
  colWidths: colWidths
113
115
  }), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
@@ -11,8 +11,7 @@ import React, { Component } from 'react';
11
11
  import classnames from 'classnames';
12
12
  import { Selection } from '@atlaskit/editor-prosemirror/state';
13
13
  import { isRowSelected } from '@atlaskit/editor-tables/utils';
14
- import { clearHoverSelection, hoverCell } from '../../../commands';
15
- import { getPluginState } from '../../../pm-plugins/plugin-factory';
14
+ import { clearHoverSelection } from '../../../commands';
16
15
  import { TableCssClassName as ClassName } from '../../../types';
17
16
  import { getRowHeights } from '../../../utils';
18
17
  import { tableBorderColor } from '../../consts';
@@ -62,22 +61,10 @@ var NumberColumn = /*#__PURE__*/function (_Component) {
62
61
  clearHoverSelection()(state, dispatch);
63
62
  }
64
63
  });
65
- _defineProperty(_assertThisInitialized(_this), "updateDragHandleLocation", function (rowIndex) {
66
- var _this$props3 = _this.props,
67
- editorView = _this$props3.editorView,
68
- tableActive = _this$props3.tableActive;
69
- var state = editorView.state,
70
- dispatch = editorView.dispatch;
71
- var _getPluginState = getPluginState(state),
72
- hoveredCell = _getPluginState.hoveredCell;
73
- if (tableActive && hoveredCell.rowIndex !== rowIndex) {
74
- hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
75
- }
76
- });
77
64
  _defineProperty(_assertThisInitialized(_this), "getCellStyles", function (index, rowHeight) {
78
- var _this$props4 = _this.props,
79
- stickyTop = _this$props4.stickyTop,
80
- hasHeaderRow = _this$props4.hasHeaderRow;
65
+ var _this$props3 = _this.props,
66
+ stickyTop = _this$props3.stickyTop,
67
+ hasHeaderRow = _this$props3.hasHeaderRow;
81
68
  if (stickyTop && hasHeaderRow && index === 0) {
82
69
  return {
83
70
  height: rowHeight,
@@ -91,11 +78,11 @@ var NumberColumn = /*#__PURE__*/function (_Component) {
91
78
  _defineProperty(_assertThisInitialized(_this), "getClassNames", function (index) {
92
79
  var _classnames;
93
80
  var isButtonDisabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
94
- var _this$props5 = _this.props,
95
- hoveredRows = _this$props5.hoveredRows,
96
- editorView = _this$props5.editorView,
97
- isInDanger = _this$props5.isInDanger,
98
- isResizing = _this$props5.isResizing;
81
+ var _this$props4 = _this.props,
82
+ hoveredRows = _this$props4.hoveredRows,
83
+ editorView = _this$props4.editorView,
84
+ isInDanger = _this$props4.isInDanger,
85
+ isResizing = _this$props4.isResizing;
99
86
  var isActive = isRowSelected(index)(editorView.state.selection) || (hoveredRows || []).indexOf(index) !== -1 && !isResizing;
100
87
  return classnames(ClassName.NUMBERED_COLUMN_BUTTON, (_classnames = {}, _defineProperty(_classnames, ClassName.NUMBERED_COLUMN_BUTTON_DISABLED, isButtonDisabled), _defineProperty(_classnames, ClassName.HOVERED_CELL_IN_DANGER, isActive && isInDanger), _defineProperty(_classnames, ClassName.HOVERED_CELL_ACTIVE, isActive), _classnames));
101
88
  });
@@ -105,11 +92,12 @@ var NumberColumn = /*#__PURE__*/function (_Component) {
105
92
  key: "render",
106
93
  value: function render() {
107
94
  var _this2 = this;
108
- var _this$props6 = this.props,
109
- tableRef = _this$props6.tableRef,
110
- hasHeaderRow = _this$props6.hasHeaderRow,
111
- isDragAndDropEnabled = _this$props6.isDragAndDropEnabled,
112
- tableActive = _this$props6.tableActive;
95
+ var _this$props5 = this.props,
96
+ tableRef = _this$props5.tableRef,
97
+ hasHeaderRow = _this$props5.hasHeaderRow,
98
+ isDragAndDropEnabled = _this$props5.isDragAndDropEnabled,
99
+ tableActive = _this$props5.tableActive,
100
+ updateCellHoverLocation = _this$props5.updateCellHoverLocation;
113
101
  var rowHeights = getRowHeights(tableRef);
114
102
  return /*#__PURE__*/React.createElement("div", {
115
103
  className: ClassName.NUMBERED_COLUMN,
@@ -125,7 +113,7 @@ var NumberColumn = /*#__PURE__*/function (_Component) {
125
113
  "data-index": index,
126
114
  style: _this2.getCellStyles(index, rowHeight),
127
115
  onMouseOver: function onMouseOver() {
128
- return _this2.updateDragHandleLocation(index);
116
+ return updateCellHoverLocation(index);
129
117
  }
130
118
  }, hasHeaderRow ? index > 0 ? index : null : index + 1) : /*#__PURE__*/React.createElement("div", {
131
119
  key: "wrapper-".concat(index),
@@ -1,50 +1,98 @@
1
- import React from 'react';
1
+ import React, { useCallback, useMemo } from 'react';
2
2
  import { injectIntl } from 'react-intl-next';
3
- import { findTable } from '@atlaskit/editor-tables/utils';
3
+ import { CellSelection } from '@atlaskit/editor-tables';
4
+ import { findTable, getSelectionRect } from '@atlaskit/editor-tables/utils';
5
+ import { clearHoverSelection } from '../../../commands';
4
6
  import { TableCssClassName as ClassName } from '../../../types';
5
- import { getRowHeights } from '../../../utils';
7
+ import { getRowHeights, getSelectedRowIndexes } from '../../../utils';
6
8
  import { DragHandle } from '../../DragHandle';
9
+ var getSelectedRows = function getSelectedRows(selection) {
10
+ if (selection instanceof CellSelection && selection.isRowSelection()) {
11
+ var rect = getSelectionRect(selection);
12
+ if (!rect) {
13
+ return [];
14
+ }
15
+ return getSelectedRowIndexes(rect);
16
+ }
17
+ return [];
18
+ };
7
19
  var DragControlsComponent = function DragControlsComponent(_ref) {
8
20
  var tableRef = _ref.tableRef,
9
21
  hoveredCell = _ref.hoveredCell,
22
+ tableActive = _ref.tableActive,
23
+ editorView = _ref.editorView,
24
+ isInDanger = _ref.isInDanger,
10
25
  hoverRows = _ref.hoverRows,
11
26
  selectRow = _ref.selectRow,
12
- tableActive = _ref.tableActive,
13
- editorView = _ref.editorView;
27
+ updateCellHoverLocation = _ref.updateCellHoverLocation;
14
28
  var rowHeights = getRowHeights(tableRef);
15
- var heights = rowHeights.map(function (height, index) {
29
+ var heights = rowHeights.map(function (height) {
16
30
  return "".concat(height - 1, "px");
17
31
  }).join(' ');
32
+ var selectedRowIndexes = getSelectedRows(editorView.state.selection);
18
33
  var rowWidth = tableRef.offsetWidth;
19
- var _onClick = function onClick(index, event) {};
20
- var onMouseOver = function onMouseOver() {};
21
- var onMouseOut = function onMouseOut() {};
22
34
  var rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
35
+ var gridRowPosition = useMemo(function () {
36
+ // if more than one row is selected, ensure the handle spans over the selected range
37
+ if (selectedRowIndexes.includes(rowIndex)) {
38
+ return "".concat(selectedRowIndexes[0] + 1, " / span ").concat(selectedRowIndexes.length);
39
+ }
40
+ return "".concat(rowIndex + 1, " / span 1");
41
+ }, [rowIndex, selectedRowIndexes]);
23
42
  var getLocalId = function getLocalId() {
24
43
  var _tableNode$node;
25
44
  var tableNode = findTable(editorView.state.selection);
26
45
  return (tableNode === null || tableNode === void 0 || (_tableNode$node = tableNode.node) === null || _tableNode$node === void 0 || (_tableNode$node = _tableNode$node.attrs) === null || _tableNode$node === void 0 ? void 0 : _tableNode$node.localId) || '';
27
46
  };
47
+ var handleMouseOut = useCallback(function () {
48
+ if (tableActive) {
49
+ var state = editorView.state,
50
+ dispatch = editorView.dispatch;
51
+ clearHoverSelection()(state, dispatch);
52
+ }
53
+ }, [editorView, tableActive]);
54
+ var handleMouseMove = useCallback(function (e) {
55
+ // avoid updating if event target is drag handle
56
+ if (!e.nativeEvent.target.classList.contains(ClassName.ROW_CONTROLS_WITH_DRAG)) {
57
+ return;
58
+ }
59
+ var hoverHeight = e.nativeEvent.offsetY;
60
+ var totalHeight = 0;
61
+ var rowIndex = rowHeights.findIndex(function (row) {
62
+ totalHeight += row;
63
+ return hoverHeight <= totalHeight;
64
+ });
65
+ updateCellHoverLocation(rowIndex);
66
+ }, [updateCellHoverLocation, rowHeights]);
67
+ var handleMouseOver = useCallback(function () {
68
+ hoverRows([rowIndex]);
69
+ }, [hoverRows, rowIndex]);
70
+ var handleClick = useCallback(function (e) {
71
+ selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
72
+ }, [rowIndex, selectRow]);
28
73
  return /*#__PURE__*/React.createElement("div", {
29
74
  className: ClassName.ROW_CONTROLS_WITH_DRAG,
30
75
  style: {
31
76
  gridTemplateRows: heights
32
- }
33
- }, rowIndex !== undefined && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
77
+ },
78
+ onMouseMove: handleMouseMove
79
+ }, Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
34
80
  style: {
35
- gridRow: "".concat(rowIndex + 1, " / span 1"),
36
- display: 'flex'
81
+ gridRow: gridRowPosition,
82
+ display: 'flex',
83
+ height: '100%',
84
+ alignItems: 'center',
85
+ justifyContent: 'center'
37
86
  }
38
87
  }, /*#__PURE__*/React.createElement(DragHandle, {
39
- onClick: function onClick(event) {
40
- return _onClick(rowIndex, event);
41
- },
42
- onMouseOver: onMouseOver,
43
- onMouseOut: onMouseOut,
44
88
  tableLocalId: getLocalId(),
45
89
  indexes: [rowIndex],
46
90
  previewWidth: rowWidth,
47
- previewHeight: rowHeights[rowIndex]
91
+ previewHeight: rowHeights[rowIndex],
92
+ appearance: selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
93
+ onClick: handleClick,
94
+ onMouseOver: handleMouseOver,
95
+ onMouseOut: handleMouseOut
48
96
  })));
49
97
  };
50
98
  export var DragControls = injectIntl(DragControlsComponent);