@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
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import { TableCssClassName as ClassName } from '../../../types';
3
+ import { DragHandle } from '../../DragHandle';
4
+ export const ColumnControls = ({
5
+ editorView,
6
+ tableActive,
7
+ tableRef,
8
+ hoveredCell,
9
+ isResizing,
10
+ stickyTop,
11
+ localId,
12
+ rowHeights,
13
+ colWidths
14
+ }) => {
15
+ var _rowHeights$, _colWidths$map$join;
16
+ if (!tableRef) {
17
+ return null;
18
+ }
19
+ const firstRow = tableRef.querySelector('tr');
20
+ const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
21
+ const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
22
+ const widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(width => width ? `${width - 1}px` : '0px').join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
23
+ const colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
24
+ const onClick = (index, event) => {};
25
+ const onMouseOver = () => {};
26
+ const onMouseOut = () => {};
27
+ return /*#__PURE__*/React.createElement("div", {
28
+ className: ClassName.COLUMN_CONTROLS_WITH_DRAG
29
+ }, /*#__PURE__*/React.createElement("div", {
30
+ className: ClassName.COLUMN_CONTROLS_INNER,
31
+ "data-testid": "table-floating-column-controls",
32
+ style: {
33
+ gridTemplateColumns: widths,
34
+ marginTop
35
+ }
36
+ }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/React.createElement("div", {
37
+ style: {
38
+ gridColumn: `${colIndex + 1} / span 1`,
39
+ marginTop: `-15px`
40
+ },
41
+ "data-column-control-index": colIndex,
42
+ "data-testid": "table-floating-column-control"
43
+ }, /*#__PURE__*/React.createElement(DragHandle, {
44
+ direction: "column",
45
+ indexes: [colIndex],
46
+ onClick: event => onClick(colIndex, event),
47
+ onMouseOver: onMouseOver,
48
+ onMouseOut: onMouseOut,
49
+ tableLocalId: localId || ''
50
+ }))));
51
+ };
52
+ export default ColumnControls;
@@ -0,0 +1,62 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
3
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
+ export const ColumnDropTarget = ({
5
+ index,
6
+ localId,
7
+ width,
8
+ height,
9
+ marginTop
10
+ }) => {
11
+ const dropTargetRef = useRef(null);
12
+ useEffect(() => {
13
+ if (!dropTargetRef.current) {
14
+ return;
15
+ }
16
+ return dropTargetForElements({
17
+ element: dropTargetRef.current,
18
+ canDrop({
19
+ source
20
+ }) {
21
+ var _data$indexes, _data$indexes2;
22
+ const data = source.data;
23
+ return (
24
+ // Only draggables of row type can be dropped on this target
25
+ data.type === 'table-column' &&
26
+ // Only draggables which came from the same table can be dropped on this target
27
+ data.localId === localId &&
28
+ // Only draggables which DO NOT include this drop targets index can be dropped
29
+ !!((_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
30
+ );
31
+ },
32
+ getIsSticky: () => true,
33
+ getData({
34
+ input,
35
+ element
36
+ }) {
37
+ const data = {
38
+ localId,
39
+ type: 'table-column',
40
+ targetIndex: index
41
+ };
42
+ return attachClosestEdge(data, {
43
+ input,
44
+ element,
45
+ allowedEdges: ['left', 'right']
46
+ });
47
+ }
48
+ });
49
+ }, [index, localId]);
50
+ return /*#__PURE__*/React.createElement("div", {
51
+ ref: dropTargetRef,
52
+ style: {
53
+ width: width && `${width - 1}px`,
54
+ height: height && `${height}px`,
55
+ marginTop: marginTop && `${marginTop}px`,
56
+ pointerEvents: 'auto'
57
+ },
58
+ "data-drop-target-index": index,
59
+ "data-drop-target-localid": localId,
60
+ "data-testid": "table-floating-column-controls-drop-target"
61
+ });
62
+ };
@@ -1,24 +1,15 @@
1
- import React, { useEffect, useMemo, useRef } from 'react';
2
- import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
3
- import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
1
+ import React from 'react';
4
2
  import { TableCssClassName as ClassName } from '../../../types';
5
- import { getColumnsWidths, getRowHeights } from '../../../utils';
3
+ import { ColumnDropTarget } from './ColumnDropTarget';
6
4
  export const ColumnDropTargets = ({
7
- editorView,
8
5
  tableRef,
9
6
  tableHeight,
10
7
  stickyTop,
11
- localId
8
+ localId,
9
+ rowHeights,
10
+ colWidths
12
11
  }) => {
13
12
  var _rowHeights$;
14
- const colWidths = getColumnsWidths(editorView);
15
- const rowHeights = useMemo(() => {
16
- // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
17
- if (tableRef && !!tableHeight) {
18
- return getRowHeights(tableRef);
19
- }
20
- return [0];
21
- }, [tableRef, tableHeight]);
22
13
  if (!tableRef) {
23
14
  return null;
24
15
  }
@@ -26,11 +17,12 @@ export const ColumnDropTargets = ({
26
17
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
27
18
  const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
28
19
  return /*#__PURE__*/React.createElement("div", {
29
- className: ClassName.COLUMN_DROP_TARGET_CONTROLS
20
+ className: ClassName.COLUMN_DROP_TARGET_CONTROLS,
21
+ contentEditable: false
30
22
  }, /*#__PURE__*/React.createElement("div", {
31
23
  className: ClassName.COLUMN_CONTROLS_INNER,
32
24
  "data-testid": "table-floating-column-controls-drop-targets"
33
- }, colWidths.map((width, index) => {
25
+ }, colWidths === null || colWidths === void 0 ? void 0 : colWidths.map((width, index) => {
34
26
  return /*#__PURE__*/React.createElement(ColumnDropTarget, {
35
27
  key: index,
36
28
  index: index,
@@ -40,62 +32,4 @@ export const ColumnDropTargets = ({
40
32
  marginTop: marginTop
41
33
  });
42
34
  })));
43
- };
44
- export default ColumnDropTargets;
45
- const ColumnDropTarget = ({
46
- index,
47
- localId,
48
- width,
49
- height,
50
- marginTop
51
- }) => {
52
- const dropTargetRef = useRef(null);
53
- useEffect(() => {
54
- if (!dropTargetRef.current) {
55
- return;
56
- }
57
- return dropTargetForElements({
58
- element: dropTargetRef.current,
59
- canDrop({
60
- source
61
- }) {
62
- var _data$indexes, _data$indexes2;
63
- const data = source.data;
64
- return (
65
- // Only draggables of row type can be dropped on this target
66
- data.type === 'table-column' &&
67
- // Only draggables which came from the same table can be dropped on this target
68
- data.localId === localId &&
69
- // Only draggables which DO NOT include this drop targets index can be dropped
70
- !!((_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
71
- );
72
- },
73
- getData({
74
- input,
75
- element
76
- }) {
77
- const data = {
78
- localId,
79
- type: 'table-column',
80
- targetIndex: index
81
- };
82
- return attachClosestEdge(data, {
83
- input,
84
- element,
85
- allowedEdges: ['left', 'right']
86
- });
87
- }
88
- });
89
- }, [index, localId]);
90
- return /*#__PURE__*/React.createElement("div", {
91
- ref: dropTargetRef,
92
- style: {
93
- width: width && `${width - 1}px`,
94
- height: height && `${height}px`,
95
- marginTop: marginTop && `${marginTop}px`
96
- },
97
- "data-drop-target-index": index,
98
- "data-drop-target-localid": localId,
99
- "data-testid": "table-floating-column-controls-drop-target"
100
- });
101
35
  };
@@ -1,11 +1,18 @@
1
1
  import React, { useEffect, useMemo, useState } from 'react';
2
- import { findTable } from '@atlaskit/editor-tables';
2
+ import ReactDOM from 'react-dom';
3
+ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
+ import { TableCssClassName as ClassName } from '../../types';
5
+ import { getColumnsWidths, getRowHeights } from '../../utils';
6
+ import { ColumnControls } from './ColumnControls';
3
7
  import { ColumnDropTargets } from './ColumnDropTargets';
4
8
  export const TableFloatingColumnControls = ({
5
9
  editorView,
6
10
  tableRef,
11
+ getNode,
7
12
  tableActive,
8
13
  hasHeaderRow,
14
+ hoveredCell,
15
+ isResizing,
9
16
  stickyHeader,
10
17
  selection
11
18
  }) => {
@@ -13,6 +20,9 @@ export const TableFloatingColumnControls = ({
13
20
  width: 0,
14
21
  height: 0
15
22
  });
23
+ const [hasDropTargets, setHasDropTargets] = useState(false);
24
+ const node = getNode();
25
+ const currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
16
26
  useEffect(() => {
17
27
  var _window;
18
28
  if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
@@ -32,29 +42,62 @@ export const TableFloatingColumnControls = ({
32
42
  };
33
43
  }
34
44
  }, [tableRef]);
35
- const selectedLocalId = useMemo(() => {
36
- if (!selection) {
37
- return undefined;
38
- }
39
- const tableNode = findTable(selection);
40
- if (!tableNode) {
41
- return undefined;
45
+ useEffect(() => {
46
+ return monitorForElements({
47
+ canMonitor({
48
+ source
49
+ }) {
50
+ const {
51
+ type,
52
+ localId,
53
+ indexes
54
+ } = source.data;
55
+ return type === 'table-column' && !!(indexes !== null && indexes !== void 0 && indexes.length) && localId === currentNodeLocalId;
56
+ },
57
+ onDragStart() {
58
+ setHasDropTargets(true);
59
+ },
60
+ onDrop() {
61
+ setHasDropTargets(false);
62
+ }
63
+ });
64
+ }, [editorView, currentNodeLocalId]);
65
+ const rowHeights = useMemo(() => {
66
+ // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
67
+ if (tableRef && !!tableRect.height) {
68
+ return getRowHeights(tableRef);
42
69
  }
43
- return tableNode.node.attrs.localId;
44
- }, [selection]);
70
+ return [0];
71
+ }, [tableRef, tableRect.height]);
45
72
  if (!tableRef) {
46
73
  return null;
47
74
  }
75
+ const colWidths = getColumnsWidths(editorView);
48
76
  const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
49
- return /*#__PURE__*/React.createElement("div", {
50
- onMouseDown: e => e.preventDefault(),
77
+ const mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
78
+ return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement("div", {
79
+ className: ClassName.COLUMN_CONTROLS_WRAPPER,
80
+ style: {
81
+ pointerEvents: 'none'
82
+ },
51
83
  "data-testid": "table-floating-column-controls-wrapper"
52
- }, tableActive && /*#__PURE__*/React.createElement(ColumnDropTargets, {
84
+ }, /*#__PURE__*/React.createElement(ColumnControls, {
53
85
  editorView: editorView,
86
+ hoveredCell: hoveredCell,
87
+ tableRef: tableRef,
88
+ isResizing: isResizing,
89
+ tableActive: tableActive,
90
+ stickyTop: tableActive ? stickyTop : undefined,
91
+ localId: currentNodeLocalId,
92
+ rowHeights: rowHeights,
93
+ colWidths: colWidths
94
+ }), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
54
95
  tableRef: tableRef,
55
96
  stickyTop: tableActive ? stickyTop : undefined,
56
97
  tableHeight: tableRect.height,
57
- localId: selectedLocalId
58
- }));
98
+ localId: currentNodeLocalId,
99
+ rowHeights: rowHeights,
100
+ colWidths: colWidths
101
+ })), mountTo);
59
102
  };
60
103
  export default TableFloatingColumnControls;
@@ -7,7 +7,7 @@ import { B300, N0, N20A, N300, N40A, R500 } from '@atlaskit/theme/colors';
7
7
  import { fontSize } from '@atlaskit/theme/constants';
8
8
  import { TableCssClassName as ClassName } from '../types';
9
9
  import { columnControlsDecorationHeight, resizeHandlerAreaWidth, resizeLineWidth, rowControlsZIndex, stickyHeaderBorderBottomWidth, stickyRowOffsetTop, tableBorderColor, tableBorderDeleteColor, tableBorderRadiusSize, tableBorderSelectedColor, tableCellBackgroundColor, tableCellDeleteColor, tableCellSelectedColor, tableControlsSpacing, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableOverflowShadowWidth, tablePadding, tableScrollbarOffset, tableTextColor, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
10
- import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, insertLine, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle } from './ui-styles';
10
+ import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, insertLine, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle, rowControlsWrapperDotStyle } from './ui-styles';
11
11
  const cornerControlHeight = tableToolbarSize + 1;
12
12
 
13
13
  /*
@@ -487,6 +487,7 @@ export const tableStyles = props => {
487
487
  ${breakoutWidthStyling()}
488
488
 
489
489
  ${columnControlsDecoration(props)};
490
+ ${rowControlsWrapperDotStyle(props)};
490
491
 
491
492
  /* Corner controls */
492
493
  .${ClassName.CORNER_CONTROLS} {
@@ -730,10 +731,6 @@ export const tableStyles = props => {
730
731
  margin-top: 0;
731
732
  }
732
733
 
733
- .${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} + * {
734
- margin-top: 0;
735
- }
736
-
737
734
  /*
738
735
  * Headings have a top margin by default, but we don't want this on the
739
736
  * first heading within table header cells.
@@ -0,0 +1,2 @@
1
+ export { DragHandleIcon } from './DragHandleIcon';
2
+ export { DragInMotionIcon } from './DragInMotionIcon';
@@ -291,26 +291,48 @@ export const floatingColumnControls = props => {
291
291
  .${ClassName.COLUMN_DROP_TARGET_CONTROLS} {
292
292
  box-sizing: border-box;
293
293
  position: absolute;
294
+ top: 0;
294
295
 
295
296
  .${ClassName.COLUMN_CONTROLS_INNER} {
296
297
  display: flex;
297
298
  flex-direction: row;
298
299
  }
299
300
  }
301
+
302
+ .${ClassName.COLUMN_CONTROLS_WITH_DRAG} {
303
+ box-sizing: border-box;
304
+
305
+ .${ClassName.COLUMN_CONTROLS_INNER} {
306
+ display: grid;
307
+ justify-items: center;
308
+ }
309
+ }
300
310
  `;
301
311
  };
302
- export const columnControlsDecoration = props => {
312
+ export const rowControlsWrapperDotStyle = props => {
303
313
  if (getBooleanFF('platform.editor.table.drag-and-drop')) {
304
314
  return css`
305
- .${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} {
315
+ div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
316
+ display: none;
317
+ }
318
+ `;
319
+ } else {
320
+ return css`
321
+ div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
322
+ content: ' ';
323
+ background-color: ${tableBorderColor(props)};
306
324
  position: absolute;
307
- // kinda a hacky way to center an element with absolute positioning inside a relative element
308
- top: 25%;
309
- left: 50%;
310
- transform: translate(-50%, -100%);
325
+ height: ${lineMarkerSize}px;
326
+ width: ${lineMarkerSize}px;
327
+ border-radius: 50%;
328
+ pointer-events: none;
329
+ top: -${tableToolbarSize + tableCellBorderWidth}px;
330
+ right: -1px;
311
331
  }
312
332
  `;
313
333
  }
334
+ };
335
+ export const columnControlsDecoration = props => {
314
336
  if (getBooleanFF('platform.editor.table.column-controls-styles-updated')) {
315
337
  return css`
316
338
  .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
@@ -355,18 +377,6 @@ export const columnControlsDecoration = props => {
355
377
  // floating dot for adding column button - overriding style on last column to avoid scroll
356
378
  ${getFloatingDotOverrides(props)}
357
379
 
358
- div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
359
- content: ' ';
360
- background-color: ${tableBorderColor(props)};
361
- position: absolute;
362
- height: ${lineMarkerSize}px;
363
- width: ${lineMarkerSize}px;
364
- border-radius: 50%;
365
- pointer-events: none;
366
- top: -${tableToolbarSize + tableCellBorderWidth}px;
367
- right: -1px;
368
- }
369
-
370
380
  .${ClassName.WITH_CONTROLS} .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
371
381
  display: block;
372
382
  }
@@ -470,18 +480,6 @@ export const columnControlsDecoration = props => {
470
480
  // floating dot for adding column button - overriding style on last column to avoid scroll
471
481
  ${getFloatingDotOverrides(props)}
472
482
 
473
- div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
474
- content: ' ';
475
- background-color: ${tableBorderColor(props)};
476
- position: absolute;
477
- height: ${lineMarkerSize}px;
478
- width: ${lineMarkerSize}px;
479
- border-radius: 50%;
480
- pointer-events: none;
481
- top: -${tableToolbarSize + tableCellBorderWidth}px;
482
- right: -1px;
483
- }
484
-
485
483
  .${ClassName.WITH_CONTROLS} .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
486
484
  display: block;
487
485
  }
@@ -11,7 +11,6 @@ import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tab
11
11
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
12
  import { TableCssClassName as ClassName, TableDecorations } from '../types';
13
13
  import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
14
- import { DragHandle } from '../ui/DragHandle';
15
14
  const filterDecorationByKey = (key, decorationSet) => decorationSet.find(undefined, undefined, spec => spec.key.indexOf(key) > -1);
16
15
  export const findColumnControlSelectedDecoration = decorationSet => filterDecorationByKey(TableDecorations.COLUMN_SELECTED, decorationSet);
17
16
  export const findControlsHoverDecoration = decorationSet => filterDecorationByKey(TableDecorations.ALL_CONTROLS_HOVER, decorationSet);
@@ -130,30 +129,10 @@ export const createColumnSelectedDecoration = tr => {
130
129
  });
131
130
  });
132
131
  };
133
- export const createColumnControlsDecoration = (selection, hoverLocation) => {
134
- // todo: issue here where table may not be selected yet
132
+ export const createColumnControlsDecoration = selection => {
135
133
  const cells = getCellsInRow(0)(selection) || [];
136
- const table = findTable(selection);
137
- if (getBooleanFF('platform.editor.table.drag-and-drop') && hoverLocation && !Number.isNaN(hoverLocation === null || hoverLocation === void 0 ? void 0 : hoverLocation.colIndex) && table) {
138
- const colIndex = hoverLocation.colIndex;
139
- const cell = cells[colIndex];
140
- return [Decoration.widget(cell.pos + 1, () => {
141
- const element = document.createElement('div');
142
- element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG);
143
- ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
144
- tableLocalId: table.node.attrs.localId,
145
- direction: 'column',
146
- indexes: [colIndex]
147
- }), element);
148
- return element;
149
- }, {
150
- key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${colIndex}`,
151
- // this decoration should be the first one, even before gap cursor.
152
- side: -100,
153
- destroy: node => {
154
- ReactDOM.unmountComponentAtNode(node);
155
- }
156
- })];
134
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
135
+ return [];
157
136
  } else {
158
137
  let index = 0;
159
138
  return cells.map(cell => {
@@ -9,7 +9,6 @@ export const isCornerButton = node => containsClassName(node, ClassName.CONTROLS
9
9
  export const isInsertRowButton = node => containsClassName(node, ClassName.CONTROLS_INSERT_ROW) || closestElement(node, `.${ClassName.CONTROLS_INSERT_ROW}`) || containsClassName(node, ClassName.CONTROLS_BUTTON_OVERLAY) && closestElement(node, `.${ClassName.ROW_CONTROLS}`);
10
10
  export const getColumnOrRowIndex = target => [parseInt(target.getAttribute('data-start-index') || '-1', 10), parseInt(target.getAttribute('data-end-index') || '-1', 10)];
11
11
  export const isColumnControlsDecorations = node => containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS);
12
- export const isColumnDragControlsDecorations = node => containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG) || closestElement(node, `.${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG}`);
13
12
  export const isRowControlsButton = node => containsClassName(node, ClassName.ROW_CONTROLS_BUTTON) || containsClassName(node, ClassName.NUMBERED_COLUMN_BUTTON);
14
13
  export const isRowDragControlsButton = node => containsClassName(node, ClassName.ROW_CONTROLS_WITH_DRAG) || closestElement(node, `.${ClassName.ROW_CONTROLS_WITH_DRAG}`);
15
14
  export const isResizeHandleDecoration = node => containsClassName(node, ClassName.RESIZE_HANDLE_DECORATION);
@@ -2,7 +2,7 @@ export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, is
2
2
  export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnInsertLine, createColumnLineResize, createRowInsertLine } from './decoration';
3
3
  export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell } from './paste';
5
- export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isColumnDragControlsDecorations, isRowDragControlsButton, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler } from './dom';
5
+ export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowDragControlsButton, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler } from './dom';
6
6
  export { getColumnsWidths, isColumnDeleteButtonVisible, getColumnDeleteButtonParams, getColumnClassNames } from './column-controls';
7
7
  export { getRowHeights, isRowDeleteButtonVisible, getRowDeleteButtonParams, getRowsParams, getRowClassNames, copyPreviousRow } from './row-controls';
8
8
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
@@ -489,22 +489,23 @@ 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("div", {
493
- className: ClassName.COLUMN_CONTROLS_WRAPPER
494
- }, /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
492
+ var colControls = /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
495
493
  editorView: view,
496
494
  tableRef: tableRef,
495
+ getNode: getNode,
497
496
  tableActive: tableActive,
498
497
  hoveredRows: hoveredRows,
498
+ hoveredCell: hoveredCell,
499
+ isResizing: isResizing,
499
500
  ordering: ordering,
500
501
  hasHeaderRow: hasHeaderRow
501
- // pass `selection` and `tableHeight` to control re-render
502
+ // pass `selection` to control re-render
502
503
  ,
503
504
  selection: view.state.selection,
504
505
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
505
506
  stickyHeader: this.state.stickyHeader,
506
507
  getEditorFeatureFlags: this.props.getEditorFeatureFlags
507
- }));
508
+ });
508
509
  var shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
509
510
  var shadowStyle = memoizeOne(function (visible) {
510
511
  return {
@@ -2,6 +2,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
6
  import { pluginKey as tablePluginKey } from '../plugin-key';
6
7
  import { pluginKey as tableWidthPluginKey } from '../table-width';
7
8
  import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
@@ -15,8 +16,8 @@ export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr
15
16
  var wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
16
17
  var changedResizing = isResizing !== wasResizing;
17
18
 
18
- // Remove column controls when resizing
19
- if (isResizing) {
19
+ // Remove column controls when resizing and don't add column decoration controls when DnD enabled
20
+ if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
20
21
  return DecorationSet.empty;
21
22
  } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing || ((_tr$getMeta = tr.getMeta(tablePluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type) === 'HOVER_CELL') {
22
23
  return buildColumnControlsDecorations({
@@ -24,7 +24,6 @@ var maybeUpdateColumnSelectedDecoration = function maybeUpdateColumnSelectedDeco
24
24
  return updateDecorations(tr.doc, decorationSet, createColumnSelectedDecoration(tr), TableDecorations.COLUMN_SELECTED);
25
25
  };
26
26
  var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDecoration(_ref3) {
27
- var _meta$data;
28
27
  var decorationSet = _ref3.decorationSet,
29
28
  tr = _ref3.tr;
30
29
  var table = findTable(tr.selection);
@@ -34,7 +33,7 @@ var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDeco
34
33
  if (!table && (meta === null || meta === void 0 ? void 0 : meta.type) !== 'HOVER_CELL') {
35
34
  return decorationSet;
36
35
  }
37
- return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection, meta === null || meta === void 0 || (_meta$data = meta.data) === null || _meta$data === void 0 ? void 0 : _meta$data.hoveredCell), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
36
+ return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
38
37
  };
39
38
 
40
39
  // @see: https://product-fabric.atlassian.net/browse/ED-7304
@@ -72,6 +72,6 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
72
72
  return tr.setMeta('addToHistory', false);
73
73
  }
74
74
  var move = sourceType === 'table-row' ? moveRow : moveColumn;
75
- return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
75
+ return move(sourceIndex, targetIndex)(tr);
76
76
  });
77
77
  };
@@ -69,7 +69,8 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
69
69
  }
70
70
  var sourceType = data.sourceType,
71
71
  sourceIndexes = data.sourceIndexes,
72
- targetAdjustedIndex = data.targetAdjustedIndex;
72
+ targetAdjustedIndex = data.targetAdjustedIndex,
73
+ direction = data.direction;
73
74
 
74
75
  // If the drop target index contains merged cells then we should not allow the drop to occur.
75
76
  var hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
@@ -79,7 +80,7 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
79
80
  }
80
81
  var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
81
82
  sourceIndex = _sourceIndexes[0];
82
- moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
83
+ moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
83
84
  }
84
85
  })
85
86
  };
@@ -40,6 +40,10 @@ export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref)
40
40
  // This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
41
41
  // the new target index to be 1 index higher.
42
42
  var targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
43
+
44
+ // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
45
+ // the target index, the then the direction of the DnD is decreasing
46
+ var direction = sourceIndexes[0] > targetIndex ? -1 : 1;
43
47
  return {
44
48
  sourceType: sourceType,
45
49
  sourceLocalId: sourceLocalId,
@@ -48,6 +52,7 @@ export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref)
48
52
  targetLocalId: targetLocalId,
49
53
  targetIndex: targetIndex,
50
54
  targetAdjustedIndex: targetIndex + targetOffset,
51
- targetClosestEdge: targetClosestEdge
55
+ targetClosestEdge: targetClosestEdge,
56
+ direction: direction
52
57
  };
53
58
  };
@@ -80,7 +80,7 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
80
80
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-column-marker"),
81
81
  CONTROLS_CORNER_BUTTON: "".concat(tablePrefixSelector, "-corner-button"),
82
82
  /** Controls with drag handle */
83
- COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: "".concat(tablePrefixSelector, "-column-controls-decoration-with-drag"),
83
+ COLUMN_CONTROLS_WITH_DRAG: "".concat(tablePrefixSelector, "-column-controls-with-drag"),
84
84
  ROW_CONTROLS_WITH_DRAG: "".concat(tablePrefixSelector, "-row-controls-with-drag"),
85
85
  DRAG_HANDLE_BUTTON_CONTAINER: "".concat(tablePrefixSelector, "-drag-handle-button-container"),
86
86
  /** Other classes */