@atlaskit/editor-plugin-table 5.3.1 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/table/commands/hover.js +17 -8
  3. package/dist/cjs/plugins/table/commands/index.js +6 -0
  4. package/dist/cjs/plugins/table/commands/misc.js +1 -7
  5. package/dist/cjs/plugins/table/event-handlers.js +29 -2
  6. package/dist/cjs/plugins/table/index.js +1 -1
  7. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -3
  8. package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
  9. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +7 -3
  10. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  11. package/dist/cjs/plugins/table/pm-plugins/default-table-selection.js +14 -1
  12. package/dist/cjs/plugins/table/pm-plugins/main.js +5 -5
  13. package/dist/cjs/plugins/table/reducer.js +2 -1
  14. package/dist/cjs/plugins/table/types.js +6 -0
  15. package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -0
  16. package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +53 -14
  17. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +114 -0
  18. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +53 -0
  19. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +11 -106
  20. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +16 -6
  21. package/dist/cjs/plugins/table/ui/common-styles.js +9 -6
  22. package/dist/cjs/plugins/table/ui/consts.js +2 -1
  23. package/dist/cjs/plugins/table/ui/ui-styles.js +18 -9
  24. package/dist/cjs/plugins/table/utils/decoration.js +44 -18
  25. package/dist/cjs/plugins/table/utils/dom.js +7 -1
  26. package/dist/cjs/plugins/table/utils/index.js +12 -0
  27. package/dist/es2019/plugins/table/commands/hover.js +12 -8
  28. package/dist/es2019/plugins/table/commands/index.js +1 -1
  29. package/dist/es2019/plugins/table/commands/misc.js +1 -7
  30. package/dist/es2019/plugins/table/event-handlers.js +28 -2
  31. package/dist/es2019/plugins/table/index.js +1 -1
  32. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -3
  33. package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
  34. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +8 -6
  35. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  36. package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +13 -0
  37. package/dist/es2019/plugins/table/pm-plugins/main.js +6 -5
  38. package/dist/es2019/plugins/table/reducer.js +2 -1
  39. package/dist/es2019/plugins/table/types.js +6 -0
  40. package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -0
  41. package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -10
  42. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +86 -0
  43. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +43 -0
  44. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -88
  45. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +17 -7
  46. package/dist/es2019/plugins/table/ui/common-styles.js +47 -12
  47. package/dist/es2019/plugins/table/ui/consts.js +1 -0
  48. package/dist/es2019/plugins/table/ui/ui-styles.js +57 -14
  49. package/dist/es2019/plugins/table/utils/decoration.js +44 -18
  50. package/dist/es2019/plugins/table/utils/dom.js +2 -0
  51. package/dist/es2019/plugins/table/utils/index.js +1 -1
  52. package/dist/esm/plugins/table/commands/hover.js +16 -8
  53. package/dist/esm/plugins/table/commands/index.js +1 -1
  54. package/dist/esm/plugins/table/commands/misc.js +1 -7
  55. package/dist/esm/plugins/table/event-handlers.js +29 -2
  56. package/dist/esm/plugins/table/index.js +1 -1
  57. package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -3
  58. package/dist/esm/plugins/table/nodeviews/table.js +4 -2
  59. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +8 -6
  60. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  61. package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +13 -0
  62. package/dist/esm/plugins/table/pm-plugins/main.js +7 -7
  63. package/dist/esm/plugins/table/reducer.js +2 -1
  64. package/dist/esm/plugins/table/types.js +6 -0
  65. package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -0
  66. package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -15
  67. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +104 -0
  68. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -0
  69. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -104
  70. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +17 -7
  71. package/dist/esm/plugins/table/ui/common-styles.js +10 -7
  72. package/dist/esm/plugins/table/ui/consts.js +1 -0
  73. package/dist/esm/plugins/table/ui/ui-styles.js +18 -9
  74. package/dist/esm/plugins/table/utils/decoration.js +44 -18
  75. package/dist/esm/plugins/table/utils/dom.js +6 -0
  76. package/dist/esm/plugins/table/utils/index.js +1 -1
  77. package/dist/types/plugins/table/commands/hover.d.ts +2 -1
  78. package/dist/types/plugins/table/commands/index.d.ts +1 -1
  79. package/dist/types/plugins/table/event-handlers.d.ts +1 -0
  80. package/dist/types/plugins/table/nodeviews/types.d.ts +4 -3
  81. package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
  82. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
  83. package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
  84. package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
  85. package/dist/types/plugins/table/types.d.ts +16 -1
  86. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -0
  87. package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
  88. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
  89. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
  90. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
  91. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  92. package/dist/types/plugins/table/ui/consts.d.ts +1 -0
  93. package/dist/types/plugins/table/utils/decoration.d.ts +2 -2
  94. package/dist/types/plugins/table/utils/dom.d.ts +2 -0
  95. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  96. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
  97. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  98. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -0
  99. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +4 -3
  100. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
  101. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
  102. package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
  103. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
  104. package/dist/types-ts4.5/plugins/table/types.d.ts +16 -1
  105. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -0
  106. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
  107. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
  108. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
  109. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
  110. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  111. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
  112. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -2
  113. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +2 -0
  114. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  115. package/package.json +3 -2
  116. package/src/__tests__/unit/event-handlers.ts +74 -1
  117. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +35 -15
  118. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +146 -42
  119. package/src/__tests__/unit/ui/NumberColumn.tsx +148 -0
  120. package/src/__tests__/unit/ui/RowControls.tsx +4 -4
  121. package/src/__tests__/unit/ui/RowDragControls.tsx +118 -0
  122. package/src/__tests__/unit/ui/TableFloatingControls.tsx +9 -5
  123. package/src/plugins/table/commands/hover.ts +16 -7
  124. package/src/plugins/table/commands/index.ts +1 -0
  125. package/src/plugins/table/commands/misc.ts +0 -5
  126. package/src/plugins/table/event-handlers.ts +49 -2
  127. package/src/plugins/table/index.tsx +1 -1
  128. package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
  129. package/src/plugins/table/nodeviews/table.tsx +2 -0
  130. package/src/plugins/table/nodeviews/types.ts +4 -3
  131. package/src/plugins/table/pm-plugins/decorations/plugin.ts +13 -4
  132. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +10 -5
  133. package/src/plugins/table/pm-plugins/default-table-selection.ts +10 -0
  134. package/src/plugins/table/pm-plugins/main.ts +9 -4
  135. package/src/plugins/table/reducer.ts +2 -1
  136. package/src/plugins/table/types.ts +14 -2
  137. package/src/plugins/table/ui/DragHandle/index.tsx +57 -0
  138. package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +68 -30
  139. package/src/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.tsx +129 -0
  140. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +75 -0
  141. package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +2 -135
  142. package/src/plugins/table/ui/TableFloatingControls/index.tsx +43 -24
  143. package/src/plugins/table/ui/common-styles.ts +52 -11
  144. package/src/plugins/table/ui/consts.ts +1 -0
  145. package/src/plugins/table/ui/ui-styles.ts +58 -14
  146. package/src/plugins/table/utils/decoration.ts +75 -27
  147. package/src/plugins/table/utils/dom.ts +8 -0
  148. package/src/plugins/table/utils/index.ts +2 -0
  149. package/tsconfig.app.json +3 -0
@@ -46,6 +46,7 @@ export let TableDecorations = /*#__PURE__*/function (TableDecorations) {
46
46
  }({});
47
47
  export const TableCssClassName = {
48
48
  ...TableSharedCssClassName,
49
+ /** Classic controls */
49
50
  COLUMN_CONTROLS: `${tablePrefixSelector}-column-controls`,
50
51
  COLUMN_CONTROLS_DECORATIONS: `${tablePrefixSelector}-column-controls-decoration`,
51
52
  COLUMN_SELECTED: `${tablePrefixSelector}-column__selected`,
@@ -76,8 +77,13 @@ export const TableCssClassName = {
76
77
  CORNER_CONTROLS_INSERT_ROW_MARKER: `${tablePrefixSelector}-corner-controls__insert-row-marker`,
77
78
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
78
79
  CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
80
+ /** Controls with drag handle */
81
+ COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: `${tablePrefixSelector}-column-controls-decoration-with-drag`,
82
+ ROW_CONTROLS_WITH_DRAG: `${tablePrefixSelector}-row-controls-with-drag`,
83
+ /** Other classes */
79
84
  NUMBERED_COLUMN: `${tablePrefixSelector}-numbered-column`,
80
85
  NUMBERED_COLUMN_BUTTON: `${tablePrefixSelector}-numbered-column__button`,
86
+ NUMBERED_COLUMN_BUTTON_DISABLED: `${tablePrefixSelector}-numbered-column__button-disabled`,
81
87
  HOVERED_COLUMN: `${tablePrefixSelector}-hovered-column`,
82
88
  HOVERED_ROW: `${tablePrefixSelector}-hovered-row`,
83
89
  HOVERED_TABLE: `${tablePrefixSelector}-hovered-table`,
@@ -0,0 +1,41 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { DragHandleButton } from '@atlaskit/pragmatic-drag-and-drop-react-accessibility/drag-handle-button';
3
+ import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
+ // TODO: use for now, in future replace with custom @atlaskit/icon/glyph/drag-handler
5
+ // width is too large (24px), should be 16px
6
+ export const DragHandle = ({
7
+ tableLocalId,
8
+ direction = 'row',
9
+ indexes,
10
+ onClick,
11
+ onMouseOver,
12
+ onMouseOut
13
+ }) => {
14
+ const dragHandleDivRef = useRef(null);
15
+ useEffect(() => {
16
+ const dragHandleDivRefCurrent = dragHandleDivRef.current;
17
+ if (dragHandleDivRefCurrent) {
18
+ return draggable({
19
+ element: dragHandleDivRefCurrent,
20
+ getInitialData() {
21
+ return {
22
+ localId: tableLocalId,
23
+ type: `table-${direction}`,
24
+ indexes
25
+ };
26
+ }
27
+ });
28
+ }
29
+ }, [tableLocalId, direction, indexes]);
30
+ return /*#__PURE__*/React.createElement("div", {
31
+ ref: dragHandleDivRef,
32
+ style: {
33
+ backgroundColor: `${"var(--ds-surface, white)"}`,
34
+ borderRadius: '4px',
35
+ border: `2px solid ${"var(--ds-surface, white)"}`,
36
+ transform: direction === 'column' ? 'rotate(90deg)' : 'none'
37
+ }
38
+ }, /*#__PURE__*/React.createElement(DragHandleButton, {
39
+ label: "blah"
40
+ }));
41
+ };
@@ -1,10 +1,13 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React, { Component } from 'react';
3
+ import classnames from 'classnames';
3
4
  import { Selection } from '@atlaskit/editor-prosemirror/state';
4
5
  import { isRowSelected } from '@atlaskit/editor-tables/utils';
5
- import { clearHoverSelection } from '../../../commands';
6
+ import { clearHoverSelection, hoverCell } from '../../../commands';
7
+ import { getPluginState } from '../../../pm-plugins/plugin-factory';
6
8
  import { TableCssClassName as ClassName } from '../../../types';
7
9
  import { getRowHeights } from '../../../utils';
10
+ import { tableBorderColor } from '../../consts';
8
11
  export default class NumberColumn extends Component {
9
12
  constructor(...args) {
10
13
  super(...args);
@@ -47,7 +50,38 @@ export default class NumberColumn extends Component {
47
50
  clearHoverSelection()(state, dispatch);
48
51
  }
49
52
  });
50
- _defineProperty(this, "getClassNames", index => {
53
+ _defineProperty(this, "updateDragHandleLocation", rowIndex => {
54
+ const {
55
+ editorView,
56
+ tableActive
57
+ } = this.props;
58
+ const {
59
+ state,
60
+ dispatch
61
+ } = editorView;
62
+ const {
63
+ hoveredCell
64
+ } = getPluginState(state);
65
+ if (tableActive && hoveredCell.rowIndex !== rowIndex) {
66
+ hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
67
+ }
68
+ });
69
+ _defineProperty(this, "getCellStyles", (index, rowHeight) => {
70
+ const {
71
+ stickyTop,
72
+ hasHeaderRow
73
+ } = this.props;
74
+ if (stickyTop && hasHeaderRow && index === 0) {
75
+ return {
76
+ height: rowHeight,
77
+ top: `${stickyTop}px`
78
+ };
79
+ }
80
+ return {
81
+ height: rowHeight
82
+ };
83
+ });
84
+ _defineProperty(this, "getClassNames", (index, isButtonDisabled = false) => {
51
85
  const {
52
86
  hoveredRows,
53
87
  editorView,
@@ -55,29 +89,39 @@ export default class NumberColumn extends Component {
55
89
  isResizing
56
90
  } = this.props;
57
91
  const isActive = isRowSelected(index)(editorView.state.selection) || (hoveredRows || []).indexOf(index) !== -1 && !isResizing;
58
- return [ClassName.NUMBERED_COLUMN_BUTTON, isActive ? ClassName.HOVERED_CELL_ACTIVE : '', isActive && isInDanger ? ClassName.HOVERED_CELL_IN_DANGER : ''].join(' ');
92
+ return classnames(ClassName.NUMBERED_COLUMN_BUTTON, {
93
+ [ClassName.NUMBERED_COLUMN_BUTTON_DISABLED]: isButtonDisabled,
94
+ [ClassName.HOVERED_CELL_IN_DANGER]: isActive && isInDanger,
95
+ [ClassName.HOVERED_CELL_ACTIVE]: isActive
96
+ });
59
97
  });
60
98
  }
61
99
  render() {
62
100
  const {
63
101
  tableRef,
64
- hasHeaderRow
102
+ hasHeaderRow,
103
+ isDragAndDropEnabled,
104
+ tableActive
65
105
  } = this.props;
66
106
  const rowHeights = getRowHeights(tableRef);
67
107
  return /*#__PURE__*/React.createElement("div", {
68
108
  className: ClassName.NUMBERED_COLUMN,
69
109
  style: {
70
- marginTop: hasHeaderRow && this.props.stickyTop !== undefined ? rowHeights[0] : undefined
110
+ marginTop: hasHeaderRow && this.props.stickyTop !== undefined ? rowHeights[0] : undefined,
111
+ borderLeft: isDragAndDropEnabled && tableActive ? `1px solid ${tableBorderColor()}` : undefined
71
112
  },
72
113
  contentEditable: false
73
- }, rowHeights.map((rowHeight, index) => /*#__PURE__*/React.createElement("div", {
114
+ }, rowHeights.map((rowHeight, index) => isDragAndDropEnabled ? /*#__PURE__*/React.createElement("div", {
115
+ key: `wrapper-${index}`,
116
+ className: this.getClassNames(index, true),
117
+ "data-index": index,
118
+ style: this.getCellStyles(index, rowHeight),
119
+ onMouseOver: () => this.updateDragHandleLocation(index)
120
+ }, hasHeaderRow ? index > 0 ? index : null : index + 1) : /*#__PURE__*/React.createElement("div", {
74
121
  key: `wrapper-${index}`,
75
122
  className: this.getClassNames(index),
76
123
  "data-index": index,
77
- style: {
78
- height: rowHeight,
79
- top: this.props.stickyTop !== undefined && hasHeaderRow && index === 0 ? `${this.props.stickyTop}px` : undefined
80
- },
124
+ style: this.getCellStyles(index, rowHeight),
81
125
  onClick: event => this.selectRow(index, event),
82
126
  onMouseOver: () => this.hoverRows(index),
83
127
  onMouseOut: this.clearHoverSelection
@@ -0,0 +1,86 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import React, { Component } from 'react';
3
+ import { defineMessages, injectIntl } from 'react-intl-next';
4
+ import { clearHoverSelection } from '../../../commands';
5
+ import { TableCssClassName as ClassName } from '../../../types';
6
+ import { getRowClassNames, getRowHeights, getRowsParams } from '../../../utils';
7
+ import { tableControlsSpacing, tableToolbarSize } from '../../consts';
8
+ const messages = defineMessages({
9
+ rowControl: {
10
+ id: 'fabric.editor.rowControl',
11
+ defaultMessage: 'Highlight row',
12
+ description: 'A button on the left of each row that shows up when the table is in focus. Clicking on it will select the entire row.'
13
+ }
14
+ });
15
+ class RowControlsComponent extends Component {
16
+ constructor(...args) {
17
+ super(...args);
18
+ _defineProperty(this, "clearHoverSelection", () => {
19
+ const {
20
+ state,
21
+ dispatch
22
+ } = this.props.editorView;
23
+ clearHoverSelection()(state, dispatch);
24
+ });
25
+ }
26
+ render() {
27
+ const {
28
+ editorView,
29
+ tableRef,
30
+ hoveredRows,
31
+ isInDanger,
32
+ isResizing,
33
+ intl: {
34
+ formatMessage
35
+ }
36
+ } = this.props;
37
+ if (!tableRef) {
38
+ return null;
39
+ }
40
+ const {
41
+ selection
42
+ } = editorView.state;
43
+ const rowHeights = getRowHeights(tableRef);
44
+ const rowsParams = getRowsParams(rowHeights);
45
+ const firstRow = tableRef.querySelector('tr');
46
+ const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
47
+ return /*#__PURE__*/React.createElement("div", {
48
+ className: ClassName.ROW_CONTROLS
49
+ }, /*#__PURE__*/React.createElement("div", {
50
+ className: ClassName.ROW_CONTROLS_INNER
51
+ }, rowsParams.map(({
52
+ startIndex,
53
+ endIndex,
54
+ height
55
+ }, index) => {
56
+ // if previous row was header row, add its height to our margin
57
+ let marginTop = -1;
58
+ if (index === 1 && hasHeaderRow && this.props.stickyTop !== undefined) {
59
+ marginTop += rowHeights[index - 1] + tableToolbarSize;
60
+ }
61
+ const thisRowSticky = this.props.stickyTop !== undefined && index === 0 && hasHeaderRow;
62
+ return /*#__PURE__*/React.createElement("div", {
63
+ className: `${ClassName.ROW_CONTROLS_BUTTON_WRAP} ${getRowClassNames(startIndex, selection, hoveredRows, isInDanger, isResizing)} ${thisRowSticky ? 'sticky' : ''}`,
64
+ key: startIndex,
65
+ style: {
66
+ height: height,
67
+ marginTop: `${marginTop}px`,
68
+ top: thisRowSticky ? `${this.props.stickyTop + 3}px` : undefined,
69
+ paddingTop: thisRowSticky ? `${tableControlsSpacing}px` : undefined
70
+ }
71
+ }, /*#__PURE__*/React.createElement("button", {
72
+ "aria-label": formatMessage(messages.rowControl),
73
+ type: "button",
74
+ className: `${ClassName.ROW_CONTROLS_BUTTON} ${ClassName.CONTROLS_BUTTON}`,
75
+ onClick: event => this.props.selectRow(startIndex, event.shiftKey),
76
+ onMouseOver: () => this.props.hoverRows([startIndex]),
77
+ onMouseOut: this.clearHoverSelection,
78
+ "data-start-index": startIndex,
79
+ "data-end-index": endIndex
80
+ }), /*#__PURE__*/React.createElement("div", {
81
+ className: ClassName.CONTROLS_INSERT_MARKER
82
+ }));
83
+ })));
84
+ }
85
+ }
86
+ export const RowControls = injectIntl(RowControlsComponent);
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { injectIntl } from 'react-intl-next';
3
+ import { findTable } from '@atlaskit/editor-tables/utils';
4
+ import { TableCssClassName as ClassName } from '../../../types';
5
+ import { getRowHeights } from '../../../utils';
6
+ import { DragHandle } from '../../DragHandle';
7
+ const DragControlsComponent = ({
8
+ tableRef,
9
+ hoveredCell,
10
+ hoverRows,
11
+ selectRow,
12
+ tableActive,
13
+ editorView
14
+ }) => {
15
+ const rowHeights = getRowHeights(tableRef);
16
+ const heights = rowHeights.map(height => `${height - 1}px`).join(' ');
17
+ const onClick = (index, event) => {};
18
+ const onMouseOver = () => {};
19
+ const onMouseOut = () => {};
20
+ const rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
21
+ const getLocalId = () => {
22
+ var _tableNode$node, _tableNode$node$attrs;
23
+ const tableNode = findTable(editorView.state.selection);
24
+ return (tableNode === null || tableNode === void 0 ? void 0 : (_tableNode$node = tableNode.node) === null || _tableNode$node === void 0 ? void 0 : (_tableNode$node$attrs = _tableNode$node.attrs) === null || _tableNode$node$attrs === void 0 ? void 0 : _tableNode$node$attrs.localId) || '';
25
+ };
26
+ return /*#__PURE__*/React.createElement("div", {
27
+ className: ClassName.ROW_CONTROLS_WITH_DRAG,
28
+ style: {
29
+ gridTemplateRows: heights
30
+ }
31
+ }, Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
32
+ style: {
33
+ gridRow: `${rowIndex + 1} / span 1`
34
+ }
35
+ }, /*#__PURE__*/React.createElement(DragHandle, {
36
+ onClick: event => onClick(rowIndex, event),
37
+ onMouseOver: onMouseOver,
38
+ onMouseOut: onMouseOut,
39
+ tableLocalId: getLocalId(),
40
+ indexes: []
41
+ })));
42
+ };
43
+ export const DragControls = injectIntl(DragControlsComponent);
@@ -1,88 +1,2 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React, { Component } from 'react';
3
- import { defineMessages, injectIntl } from 'react-intl-next';
4
- import { clearHoverSelection } from '../../../commands';
5
- import { TableCssClassName as ClassName } from '../../../types';
6
- import { getRowClassNames, getRowHeights, getRowsParams } from '../../../utils';
7
- import { tableControlsSpacing, tableToolbarSize } from '../../consts';
8
- const messages = defineMessages({
9
- rowControl: {
10
- id: 'fabric.editor.rowControl',
11
- defaultMessage: 'Highlight row',
12
- description: 'A button on the left of each row that shows up when the table is in focus. Clicking on it will select the entire row.'
13
- }
14
- });
15
- class RowControlsComponent extends Component {
16
- constructor(...args) {
17
- super(...args);
18
- _defineProperty(this, "clearHoverSelection", () => {
19
- const {
20
- state,
21
- dispatch
22
- } = this.props.editorView;
23
- clearHoverSelection()(state, dispatch);
24
- });
25
- }
26
- render() {
27
- const {
28
- editorView,
29
- tableRef,
30
- hoveredRows,
31
- isInDanger,
32
- isResizing,
33
- intl: {
34
- formatMessage
35
- }
36
- } = this.props;
37
- if (!tableRef) {
38
- return null;
39
- }
40
- const {
41
- selection
42
- } = editorView.state;
43
- const rowHeights = getRowHeights(tableRef);
44
- const rowsParams = getRowsParams(rowHeights);
45
- const firstRow = tableRef.querySelector('tr');
46
- const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
47
- return /*#__PURE__*/React.createElement("div", {
48
- className: ClassName.ROW_CONTROLS
49
- }, /*#__PURE__*/React.createElement("div", {
50
- className: ClassName.ROW_CONTROLS_INNER
51
- }, rowsParams.map(({
52
- startIndex,
53
- endIndex,
54
- height
55
- }, index) => {
56
- // if previous row was header row, add its height to our margin
57
- let marginTop = -1;
58
- if (index === 1 && hasHeaderRow && this.props.stickyTop !== undefined) {
59
- marginTop += rowHeights[index - 1] + tableToolbarSize;
60
- }
61
- const thisRowSticky = this.props.stickyTop !== undefined && index === 0 && hasHeaderRow;
62
- return /*#__PURE__*/React.createElement("div", {
63
- className: `${ClassName.ROW_CONTROLS_BUTTON_WRAP} ${getRowClassNames(startIndex, selection, hoveredRows, isInDanger, isResizing)} ${thisRowSticky ? 'sticky' : ''}`,
64
- key: startIndex,
65
- style: {
66
- height: height,
67
- marginTop: `${marginTop}px`,
68
- top: thisRowSticky ? `${this.props.stickyTop + 3}px` : undefined,
69
- paddingTop: thisRowSticky ? `${tableControlsSpacing}px` : undefined
70
- }
71
- }, /*#__PURE__*/React.createElement("button", {
72
- "aria-label": formatMessage(messages.rowControl),
73
- type: "button",
74
- className: `${ClassName.ROW_CONTROLS_BUTTON}
75
- ${ClassName.CONTROLS_BUTTON}
76
- `,
77
- onClick: event => this.props.selectRow(startIndex, event.shiftKey),
78
- onMouseOver: () => this.props.hoverRows([startIndex]),
79
- onMouseOut: this.clearHoverSelection,
80
- "data-start-index": startIndex,
81
- "data-end-index": endIndex
82
- }), /*#__PURE__*/React.createElement("div", {
83
- className: ClassName.CONTROLS_INSERT_MARKER
84
- }));
85
- })));
86
- }
87
- }
88
- export const RowControls = injectIntl(RowControlsComponent);
1
+ export { RowControls } from './ClassicControls';
2
+ export { DragControls } from './DragControls';
@@ -5,7 +5,7 @@ import { hoverRows, selectRow } from '../../commands';
5
5
  import { isSelectionUpdated } from '../../utils';
6
6
  import { CornerControls } from './CornerControls';
7
7
  import NumberColumn from './NumberColumn';
8
- import { RowControls } from './RowControls';
8
+ import { DragControls, RowControls } from './RowControls';
9
9
  export default class TableFloatingControls extends Component {
10
10
  constructor(...args) {
11
11
  super(...args);
@@ -71,11 +71,12 @@ export default class TableFloatingControls extends Component {
71
71
  isHeaderColumnEnabled,
72
72
  ordering,
73
73
  headerRowHeight,
74
- stickyHeader
74
+ stickyHeader,
75
+ hoveredCell
75
76
  } = this.props;
76
77
  const tableHeight = (_this$state = this.state) === null || _this$state === void 0 ? void 0 : _this$state.tableHeight;
77
78
  const nextTableHeight = nextState === null || nextState === void 0 ? void 0 : nextState.tableHeight;
78
- return ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableHeight !== nextTableHeight || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader;
79
+ return ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableHeight !== nextTableHeight || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell;
79
80
  }
80
81
  componentWillUnmount() {
81
82
  if (this.resizeObserver) {
@@ -94,7 +95,9 @@ export default class TableFloatingControls extends Component {
94
95
  tableActive,
95
96
  hasHeaderRow,
96
97
  hoveredRows,
97
- stickyHeader
98
+ stickyHeader,
99
+ isDragAndDropEnabled,
100
+ hoveredCell
98
101
  } = this.props;
99
102
  if (!tableRef) {
100
103
  return null;
@@ -112,8 +115,15 @@ export default class TableFloatingControls extends Component {
112
115
  isInDanger: isInDanger,
113
116
  isResizing: isResizing,
114
117
  selectRow: this.selectRow,
115
- stickyTop: stickyTop
116
- }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
118
+ stickyTop: stickyTop,
119
+ isDragAndDropEnabled: isDragAndDropEnabled
120
+ }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(DragControls, {
121
+ tableRef: tableRef,
122
+ hoveredCell: hoveredCell,
123
+ editorView: editorView,
124
+ hoverRows: this.hoverRows,
125
+ selectRow: this.selectRow
126
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
117
127
  editorView: editorView,
118
128
  tableRef: tableRef,
119
129
  isInDanger: isInDanger,
@@ -131,7 +141,7 @@ export default class TableFloatingControls extends Component {
131
141
  isResizing: isResizing,
132
142
  selectRow: this.selectRow,
133
143
  stickyTop: tableActive ? stickyTop : undefined
134
- })));
144
+ }))));
135
145
  }
136
146
  }
137
147
  _defineProperty(TableFloatingControls, "displayName", 'TableFloatingControls');
@@ -6,7 +6,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
6
  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
- import { columnControlsDecorationHeight, resizeHandlerAreaWidth, resizeLineWidth, stickyHeaderBorderBottomWidth, stickyRowOffsetTop, tableBorderColor, tableBorderDeleteColor, tableBorderRadiusSize, tableBorderSelectedColor, tableCellBackgroundColor, tableCellDeleteColor, tableCellSelectedColor, tableControlsSpacing, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableOverflowShadowWidth, tablePadding, tableScrollbarOffset, tableTextColor, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
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
10
  import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, insertLine, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle } from './ui-styles';
11
11
  const cornerControlHeight = tableToolbarSize + 1;
12
12
 
@@ -158,6 +158,23 @@ const tableStickyHeaderColumnControlsDecorationsStyle = props => {
158
158
  `;
159
159
  }
160
160
  };
161
+ const tableRowControlStyles = () => {
162
+ return getBooleanFF('platform.editor.table.drag-and-drop') ? css`
163
+ .${ClassName.ROW_CONTROLS_WRAPPER} {
164
+ position: absolute;
165
+ margin-top: ${tableMarginTop}px;
166
+ left: -${tableToolbarSize + 1}px;
167
+ z-index: ${rowControlsZIndex};
168
+ }
169
+ ` : css`
170
+ .${ClassName.ROW_CONTROLS_WRAPPER} {
171
+ position: absolute;
172
+ /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
173
+ top: ${tableMarginTop - cornerControlHeight + 1}px;
174
+ left: -${tableToolbarSize}px;
175
+ }
176
+ `;
177
+ };
161
178
  const tableWrapperStyles = () => {
162
179
  if (getBooleanFF('platform.editor.custom-table-width')) {
163
180
  return css`
@@ -584,6 +601,12 @@ export const tableStyles = props => {
584
601
  `)}
585
602
  }
586
603
 
604
+ .${ClassName.ROW_CONTROLS_WITH_DRAG} {
605
+ display: grid;
606
+ align-items: center;
607
+ position: absolute;
608
+ }
609
+
587
610
  ${floatingColumnControls(props)}
588
611
 
589
612
  :not(.${ClassName.IS_RESIZING}) .${ClassName.ROW_CONTROLS} {
@@ -596,7 +619,7 @@ export const tableStyles = props => {
596
619
  position: relative;
597
620
  float: right;
598
621
  margin-left: ${getBooleanFF('platform.editor.custom-table-width') ? akEditorTableToolbarSize : akEditorTableToolbarSize - 1}px;
599
- top: ${akEditorTableToolbarSize}px;
622
+ top: ${getBooleanFF('platform.editor.table.drag-and-drop') ? 0 : akEditorTableToolbarSize}px;
600
623
  width: ${akEditorTableNumberColumnWidth + 1}px;
601
624
  box-sizing: border-box;
602
625
  }
@@ -622,6 +645,21 @@ export const tableStyles = props => {
622
645
  }
623
646
  }
624
647
 
648
+ // add a background above the first numbered column cell when sticky header is engaged
649
+ // which hides the table when scrolling
650
+ .${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}:first-of-type::after {
651
+ content: '';
652
+ display: block;
653
+ height: 33px;
654
+ width: 100%;
655
+ background-color: ${"var(--ds-surface, white)"};
656
+ position: absolute;
657
+
658
+ // the extra pixel is accounting for borders
659
+ top: -34px;
660
+ left: -1px;
661
+ }
662
+
625
663
  .${ClassName.WITH_CONTROLS} {
626
664
  .${ClassName.CORNER_CONTROLS}, .${ClassName.ROW_CONTROLS} {
627
665
  display: block;
@@ -644,10 +682,10 @@ export const tableStyles = props => {
644
682
  }
645
683
  }
646
684
  :not(.${ClassName.IS_RESIZING}) .${ClassName.WITH_CONTROLS} {
647
- .${ClassName.NUMBERED_COLUMN_BUTTON} {
685
+ .${ClassName.NUMBERED_COLUMN_BUTTON}:not(.${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}) {
648
686
  cursor: pointer;
649
687
  }
650
- .${ClassName.NUMBERED_COLUMN_BUTTON}:hover {
688
+ .${ClassName.NUMBERED_COLUMN_BUTTON}:not(.${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}):hover {
651
689
  border-bottom: 1px solid ${tableBorderSelectedColor(props)};
652
690
  border-color: ${tableBorderSelectedColor(props)};
653
691
  background-color: ${tableToolbarSelectedColor(props)};
@@ -683,6 +721,10 @@ export const tableStyles = props => {
683
721
  margin-top: 0;
684
722
  }
685
723
 
724
+ .${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} + * {
725
+ margin-top: 0;
726
+ }
727
+
686
728
  /*
687
729
  * Headings have a top margin by default, but we don't want this on the
688
730
  * first heading within table header cells.
@@ -756,17 +798,10 @@ export const tableStyles = props => {
756
798
  }
757
799
  }
758
800
  }
759
- .${ClassName.ROW_CONTROLS_WRAPPER} {
760
- position: absolute;
761
- /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
762
- top: ${tableMarginTop - cornerControlHeight + 1}px;
763
- }
801
+ ${tableRowControlStyles()}
764
802
  .${ClassName.ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW} {
765
803
  z-index: ${akEditorUnitZIndex};
766
804
  }
767
- .${ClassName.ROW_CONTROLS_WRAPPER} {
768
- left: -${tableToolbarSize}px;
769
- }
770
805
 
771
806
  .${ClassName.COLUMN_CONTROLS_WRAPPER} {
772
807
  position: absolute;
@@ -88,6 +88,7 @@ export const lineMarkerSize = 4;
88
88
  export const columnControlsDecorationHeight = 25;
89
89
  export const columnControlsZIndex = akEditorUnitZIndex * 10;
90
90
  export const columnControlsSelectedZIndex = columnControlsZIndex + 1;
91
+ export const rowControlsZIndex = akEditorUnitZIndex * 10;
91
92
  export const columnResizeHandleZIndex = columnControlsSelectedZIndex + 1;
92
93
  export const insertLineWidth = 3;
93
94
  export const resizeHandlerAreaWidth = RESIZE_HANDLE_AREA_DECORATION_GAP / 3;
@@ -300,6 +300,17 @@ export const floatingColumnControls = props => {
300
300
  `;
301
301
  };
302
302
  export const columnControlsDecoration = props => {
303
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
304
+ return css`
305
+ .${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} {
306
+ 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%);
311
+ }
312
+ `;
313
+ }
303
314
  if (getBooleanFF('platform.editor.table.column-controls-styles-updated')) {
304
315
  return css`
305
316
  .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
@@ -564,21 +575,35 @@ const getLastColumnResizerOverrides = () => {
564
575
  }
565
576
  ` : '';
566
577
  };
567
- export const resizeHandle = props => css`
568
- .${ClassName.TABLE_CONTAINER} {
569
- .${ClassName.RESIZE_HANDLE_DECORATION} {
570
- background-color: transparent;
571
- position: absolute;
572
- width: ${resizeHandlerAreaWidth}px;
573
- height: 100%;
574
- top: 0;
575
- right: -${resizeHandlerAreaWidth / 2}px;
576
- cursor: col-resize;
577
- z-index: ${resizeHandlerZIndex};
578
- }
579
-
580
- ${getLastColumnResizerOverrides()}
578
+ const resizeHandleOverrides = props => {
579
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
580
+ return css`
581
+ th.${ClassName.WITH_RESIZE_LINE}::before,
582
+ td.${ClassName.WITH_RESIZE_LINE}::before {
583
+ content: ' ';
584
+ position: absolute;
585
+ left: ${"var(--ds-space-negative-025, -2px)"};
586
+ top: -1px;
587
+ width: ${resizeLineWidth}px;
588
+ height: calc(100% + 2px);
589
+ background-color: ${tableBorderSelectedColor(props)};
590
+ z-index: ${columnControlsZIndex * 2};
591
+ }
581
592
 
593
+ th.${ClassName.WITH_RESIZE_LINE_LAST_COLUMN}::before,
594
+ td.${ClassName.WITH_RESIZE_LINE_LAST_COLUMN}::before {
595
+ content: ' ';
596
+ position: absolute;
597
+ right: -1px;
598
+ top: -1px;
599
+ width: ${resizeLineWidth}px;
600
+ height: calc(100% + 2px);
601
+ background-color: ${tableBorderSelectedColor(props)};
602
+ z-index: ${columnControlsZIndex * 2};
603
+ }
604
+ `;
605
+ }
606
+ return css`
582
607
  td.${ClassName.WITH_RESIZE_LINE}::before {
583
608
  content: ' ';
584
609
  position: absolute;
@@ -622,6 +647,24 @@ export const resizeHandle = props => css`
622
647
  z-index: ${columnControlsZIndex * 2};
623
648
  top: -${tableToolbarSize + tableCellBorderWidth}px;
624
649
  }
650
+ `;
651
+ };
652
+ export const resizeHandle = props => css`
653
+ .${ClassName.TABLE_CONTAINER} {
654
+ .${ClassName.RESIZE_HANDLE_DECORATION} {
655
+ background-color: transparent;
656
+ position: absolute;
657
+ width: ${resizeHandlerAreaWidth}px;
658
+ height: 100%;
659
+ top: 0;
660
+ right: -${resizeHandlerAreaWidth / 2}px;
661
+ cursor: col-resize;
662
+ z-index: ${resizeHandlerZIndex};
663
+ }
664
+
665
+ ${getLastColumnResizerOverrides()}
666
+
667
+ ${resizeHandleOverrides(props)}
625
668
 
626
669
  table
627
670
  tr:first-of-type