@atlaskit/editor-plugin-table 5.3.0 → 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 (186) hide show
  1. package/CHANGELOG.md +13 -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/drag-and-drop/commands.js +36 -7
  13. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -7
  14. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  15. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
  16. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
  17. package/dist/cjs/plugins/table/pm-plugins/main.js +5 -5
  18. package/dist/cjs/plugins/table/reducer.js +2 -1
  19. package/dist/cjs/plugins/table/types.js +14 -1
  20. package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -0
  21. package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +53 -14
  22. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +114 -0
  23. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +53 -0
  24. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +11 -106
  25. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +16 -6
  26. package/dist/cjs/plugins/table/ui/common-styles.js +9 -6
  27. package/dist/cjs/plugins/table/ui/consts.js +3 -1
  28. package/dist/cjs/plugins/table/ui/ui-styles.js +21 -9
  29. package/dist/cjs/plugins/table/utils/decoration.js +111 -19
  30. package/dist/cjs/plugins/table/utils/dom.js +7 -1
  31. package/dist/cjs/plugins/table/utils/index.js +38 -1
  32. package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
  33. package/dist/es2019/plugins/table/commands/hover.js +12 -8
  34. package/dist/es2019/plugins/table/commands/index.js +1 -1
  35. package/dist/es2019/plugins/table/commands/misc.js +1 -7
  36. package/dist/es2019/plugins/table/event-handlers.js +28 -2
  37. package/dist/es2019/plugins/table/index.js +1 -1
  38. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -3
  39. package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
  40. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +8 -6
  41. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  42. package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +13 -0
  43. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
  44. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -4
  45. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  46. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  47. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
  48. package/dist/es2019/plugins/table/pm-plugins/main.js +6 -5
  49. package/dist/es2019/plugins/table/reducer.js +2 -1
  50. package/dist/es2019/plugins/table/types.js +14 -1
  51. package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -0
  52. package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -10
  53. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +86 -0
  54. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +43 -0
  55. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -88
  56. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +17 -7
  57. package/dist/es2019/plugins/table/ui/common-styles.js +49 -13
  58. package/dist/es2019/plugins/table/ui/consts.js +2 -0
  59. package/dist/es2019/plugins/table/ui/ui-styles.js +171 -15
  60. package/dist/es2019/plugins/table/utils/decoration.js +106 -18
  61. package/dist/es2019/plugins/table/utils/dom.js +2 -0
  62. package/dist/es2019/plugins/table/utils/index.js +4 -3
  63. package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
  64. package/dist/esm/plugins/table/commands/hover.js +16 -8
  65. package/dist/esm/plugins/table/commands/index.js +1 -1
  66. package/dist/esm/plugins/table/commands/misc.js +1 -7
  67. package/dist/esm/plugins/table/event-handlers.js +29 -2
  68. package/dist/esm/plugins/table/index.js +1 -1
  69. package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -3
  70. package/dist/esm/plugins/table/nodeviews/table.js +4 -2
  71. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +8 -6
  72. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  73. package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +13 -0
  74. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  75. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +65 -4
  76. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  77. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  78. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
  79. package/dist/esm/plugins/table/pm-plugins/main.js +7 -7
  80. package/dist/esm/plugins/table/reducer.js +2 -1
  81. package/dist/esm/plugins/table/types.js +14 -1
  82. package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -0
  83. package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -15
  84. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +104 -0
  85. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -0
  86. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -104
  87. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +17 -7
  88. package/dist/esm/plugins/table/ui/common-styles.js +11 -8
  89. package/dist/esm/plugins/table/ui/consts.js +2 -0
  90. package/dist/esm/plugins/table/ui/ui-styles.js +21 -9
  91. package/dist/esm/plugins/table/utils/decoration.js +110 -18
  92. package/dist/esm/plugins/table/utils/dom.js +6 -0
  93. package/dist/esm/plugins/table/utils/index.js +4 -3
  94. package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
  95. package/dist/types/plugins/table/commands/hover.d.ts +2 -1
  96. package/dist/types/plugins/table/commands/index.d.ts +1 -1
  97. package/dist/types/plugins/table/event-handlers.d.ts +1 -0
  98. package/dist/types/plugins/table/nodeviews/types.d.ts +4 -3
  99. package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
  100. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
  101. package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
  102. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  103. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  104. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  105. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  106. package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
  107. package/dist/types/plugins/table/types.d.ts +35 -2
  108. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -0
  109. package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
  110. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
  111. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
  112. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
  113. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  114. package/dist/types/plugins/table/ui/consts.d.ts +2 -0
  115. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  116. package/dist/types/plugins/table/utils/decoration.d.ts +4 -2
  117. package/dist/types/plugins/table/utils/dom.d.ts +2 -0
  118. package/dist/types/plugins/table/utils/index.d.ts +3 -2
  119. package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
  120. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
  121. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  122. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -0
  123. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +4 -3
  124. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
  125. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
  126. package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
  127. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  128. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  129. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  130. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  131. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
  132. package/dist/types-ts4.5/plugins/table/types.d.ts +35 -2
  133. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -0
  134. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
  135. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
  136. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
  137. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
  138. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  139. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +2 -0
  140. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  141. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +4 -2
  142. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +2 -0
  143. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +3 -2
  144. package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
  145. package/package.json +6 -2
  146. package/src/__tests__/unit/event-handlers.ts +74 -1
  147. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +35 -15
  148. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +146 -42
  149. package/src/__tests__/unit/ui/NumberColumn.tsx +148 -0
  150. package/src/__tests__/unit/ui/RowControls.tsx +4 -4
  151. package/src/__tests__/unit/ui/RowDragControls.tsx +118 -0
  152. package/src/__tests__/unit/ui/TableFloatingControls.tsx +9 -5
  153. package/src/plugins/table/commands/hover.ts +16 -7
  154. package/src/plugins/table/commands/index.ts +1 -0
  155. package/src/plugins/table/commands/misc.ts +0 -5
  156. package/src/plugins/table/event-handlers.ts +49 -2
  157. package/src/plugins/table/index.tsx +1 -1
  158. package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
  159. package/src/plugins/table/nodeviews/table.tsx +2 -0
  160. package/src/plugins/table/nodeviews/types.ts +4 -3
  161. package/src/plugins/table/pm-plugins/decorations/plugin.ts +13 -4
  162. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +10 -5
  163. package/src/plugins/table/pm-plugins/default-table-selection.ts +10 -0
  164. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
  165. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
  166. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +77 -4
  167. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
  168. package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
  169. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
  170. package/src/plugins/table/pm-plugins/main.ts +9 -4
  171. package/src/plugins/table/reducer.ts +2 -1
  172. package/src/plugins/table/types.ts +37 -3
  173. package/src/plugins/table/ui/DragHandle/index.tsx +57 -0
  174. package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +68 -30
  175. package/src/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.tsx +129 -0
  176. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +75 -0
  177. package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +2 -135
  178. package/src/plugins/table/ui/TableFloatingControls/index.tsx +43 -24
  179. package/src/plugins/table/ui/common-styles.ts +54 -11
  180. package/src/plugins/table/ui/consts.ts +2 -0
  181. package/src/plugins/table/ui/ui-styles.ts +173 -14
  182. package/src/plugins/table/utils/decoration.ts +176 -27
  183. package/src/plugins/table/utils/dom.ts +8 -0
  184. package/src/plugins/table/utils/index.ts +5 -0
  185. package/src/plugins/table/utils/merged-cells.ts +67 -0
  186. package/tsconfig.app.json +3 -0
@@ -0,0 +1,129 @@
1
+ import React, { Component } from 'react';
2
+
3
+ import type { WrappedComponentProps } from 'react-intl-next';
4
+ import { defineMessages, injectIntl } from 'react-intl-next';
5
+
6
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
+
8
+ import { clearHoverSelection } from '../../../commands';
9
+ import { TableCssClassName as ClassName } from '../../../types';
10
+ import type { RowParams } from '../../../utils';
11
+ import { getRowClassNames, getRowHeights, getRowsParams } from '../../../utils';
12
+ import { tableControlsSpacing, tableToolbarSize } from '../../consts';
13
+
14
+ const messages = defineMessages({
15
+ rowControl: {
16
+ id: 'fabric.editor.rowControl',
17
+ defaultMessage: 'Highlight row',
18
+ description:
19
+ '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.',
20
+ },
21
+ });
22
+
23
+ export interface Props {
24
+ editorView: EditorView;
25
+ tableRef: HTMLTableElement;
26
+ selectRow: (row: number, expand: boolean) => void;
27
+ hoverRows: (rows: number[], danger?: boolean) => void;
28
+ hoveredRows?: number[];
29
+ isInDanger?: boolean;
30
+ isResizing?: boolean;
31
+ insertRowButtonIndex?: number;
32
+ stickyTop?: number;
33
+ }
34
+
35
+ class RowControlsComponent extends Component<Props & WrappedComponentProps> {
36
+ render() {
37
+ const {
38
+ editorView,
39
+ tableRef,
40
+ hoveredRows,
41
+ isInDanger,
42
+ isResizing,
43
+ intl: { formatMessage },
44
+ } = this.props;
45
+ if (!tableRef) {
46
+ return null;
47
+ }
48
+ const { selection } = editorView.state;
49
+ const rowHeights = getRowHeights(tableRef);
50
+ const rowsParams = getRowsParams(rowHeights);
51
+
52
+ const firstRow = tableRef.querySelector('tr');
53
+ const hasHeaderRow = firstRow
54
+ ? firstRow.getAttribute('data-header-row')
55
+ : false;
56
+
57
+ return (
58
+ <div className={ClassName.ROW_CONTROLS}>
59
+ <div className={ClassName.ROW_CONTROLS_INNER}>
60
+ {rowsParams.map(
61
+ ({ startIndex, endIndex, height }: RowParams, index) => {
62
+ // if previous row was header row, add its height to our margin
63
+ let marginTop = -1;
64
+ if (
65
+ index === 1 &&
66
+ hasHeaderRow &&
67
+ this.props.stickyTop !== undefined
68
+ ) {
69
+ marginTop += rowHeights[index - 1] + tableToolbarSize;
70
+ }
71
+
72
+ const thisRowSticky =
73
+ this.props.stickyTop !== undefined &&
74
+ index === 0 &&
75
+ hasHeaderRow;
76
+
77
+ return (
78
+ <div
79
+ className={`${
80
+ ClassName.ROW_CONTROLS_BUTTON_WRAP
81
+ } ${getRowClassNames(
82
+ startIndex,
83
+ selection,
84
+ hoveredRows,
85
+ isInDanger,
86
+ isResizing,
87
+ )} ${thisRowSticky ? 'sticky' : ''}`}
88
+ key={startIndex}
89
+ style={{
90
+ height: height,
91
+ marginTop: `${marginTop}px`,
92
+ top: thisRowSticky
93
+ ? `${this.props.stickyTop! + 3}px`
94
+ : undefined,
95
+ paddingTop: thisRowSticky
96
+ ? `${tableControlsSpacing}px`
97
+ : undefined,
98
+ }}
99
+ >
100
+ <button
101
+ aria-label={formatMessage(messages.rowControl)}
102
+ type="button"
103
+ className={`${ClassName.ROW_CONTROLS_BUTTON} ${ClassName.CONTROLS_BUTTON}`}
104
+ onClick={(event) =>
105
+ this.props.selectRow(startIndex, event.shiftKey)
106
+ }
107
+ onMouseOver={() => this.props.hoverRows([startIndex])}
108
+ onMouseOut={this.clearHoverSelection}
109
+ data-start-index={startIndex}
110
+ data-end-index={endIndex}
111
+ />
112
+
113
+ <div className={ClassName.CONTROLS_INSERT_MARKER} />
114
+ </div>
115
+ );
116
+ },
117
+ )}
118
+ </div>
119
+ </div>
120
+ );
121
+ }
122
+
123
+ private clearHoverSelection = () => {
124
+ const { state, dispatch } = this.props.editorView;
125
+ clearHoverSelection()(state, dispatch);
126
+ };
127
+ }
128
+
129
+ export const RowControls = injectIntl(RowControlsComponent);
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+
3
+ import { injectIntl } from 'react-intl-next';
4
+ import type { WrappedComponentProps } from 'react-intl-next';
5
+
6
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
+ import { findTable } from '@atlaskit/editor-tables/utils';
8
+
9
+ import type { CellHoverCoordinates } from '../../../types';
10
+ import { TableCssClassName as ClassName } from '../../../types';
11
+ import { getRowHeights } from '../../../utils';
12
+ import { DragHandle } from '../../DragHandle';
13
+
14
+ type DragControlsProps = {
15
+ editorView: EditorView;
16
+ tableRef: HTMLTableElement;
17
+ tableActive?: boolean;
18
+ hoveredCell?: CellHoverCoordinates;
19
+ hoverRows?: (rows: number[], danger?: boolean) => void;
20
+ selectRow?: (row: number, expand: boolean) => void;
21
+ };
22
+
23
+ const DragControlsComponent = ({
24
+ tableRef,
25
+ hoveredCell,
26
+ hoverRows,
27
+ selectRow,
28
+ tableActive,
29
+ editorView,
30
+ }: DragControlsProps & WrappedComponentProps) => {
31
+ const rowHeights = getRowHeights(tableRef);
32
+ const heights = rowHeights.map((height) => `${height - 1}px`).join(' ');
33
+
34
+ const onClick = (
35
+ index: number,
36
+ event: React.MouseEvent<Element, MouseEvent>,
37
+ ) => {};
38
+
39
+ const onMouseOver = () => {};
40
+ const onMouseOut = () => {};
41
+
42
+ const rowIndex = hoveredCell?.rowIndex;
43
+
44
+ const getLocalId = () => {
45
+ const tableNode = findTable(editorView.state.selection);
46
+ return tableNode?.node?.attrs?.localId || '';
47
+ };
48
+
49
+ return (
50
+ <div
51
+ className={ClassName.ROW_CONTROLS_WITH_DRAG}
52
+ style={{
53
+ gridTemplateRows: heights,
54
+ }}
55
+ >
56
+ {Number.isFinite(rowIndex) && (
57
+ <div
58
+ style={{
59
+ gridRow: `${(rowIndex as number) + 1} / span 1`,
60
+ }}
61
+ >
62
+ <DragHandle
63
+ onClick={(event) => onClick(rowIndex as number, event)}
64
+ onMouseOver={onMouseOver}
65
+ onMouseOut={onMouseOut}
66
+ tableLocalId={getLocalId()}
67
+ indexes={[]}
68
+ />
69
+ </div>
70
+ )}
71
+ </div>
72
+ );
73
+ };
74
+
75
+ export const DragControls = injectIntl(DragControlsComponent);
@@ -1,135 +1,2 @@
1
- import React, { Component } from 'react';
2
-
3
- import type { WrappedComponentProps } from 'react-intl-next';
4
- import { defineMessages, injectIntl } from 'react-intl-next';
5
-
6
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
7
-
8
- import { clearHoverSelection } from '../../../commands';
9
- import { TableCssClassName as ClassName } from '../../../types';
10
- import {
11
- getRowClassNames,
12
- getRowHeights,
13
- getRowsParams,
14
- RowParams,
15
- } from '../../../utils';
16
- import { tableControlsSpacing, tableToolbarSize } from '../../consts';
17
-
18
- const messages = defineMessages({
19
- rowControl: {
20
- id: 'fabric.editor.rowControl',
21
- defaultMessage: 'Highlight row',
22
- description:
23
- '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.',
24
- },
25
- });
26
-
27
- export interface Props {
28
- editorView: EditorView;
29
- tableRef: HTMLTableElement;
30
- selectRow: (row: number, expand: boolean) => void;
31
- hoverRows: (rows: number[], danger?: boolean) => void;
32
- hoveredRows?: number[];
33
- isInDanger?: boolean;
34
- isResizing?: boolean;
35
- insertRowButtonIndex?: number;
36
- stickyTop?: number;
37
- }
38
-
39
- class RowControlsComponent extends Component<Props & WrappedComponentProps> {
40
- render() {
41
- const {
42
- editorView,
43
- tableRef,
44
- hoveredRows,
45
- isInDanger,
46
- isResizing,
47
- intl: { formatMessage },
48
- } = this.props;
49
- if (!tableRef) {
50
- return null;
51
- }
52
- const { selection } = editorView.state;
53
- const rowHeights = getRowHeights(tableRef);
54
- const rowsParams = getRowsParams(rowHeights);
55
-
56
- const firstRow = tableRef.querySelector('tr');
57
- const hasHeaderRow = firstRow
58
- ? firstRow.getAttribute('data-header-row')
59
- : false;
60
-
61
- return (
62
- <div className={ClassName.ROW_CONTROLS}>
63
- <div className={ClassName.ROW_CONTROLS_INNER}>
64
- {rowsParams.map(
65
- ({ startIndex, endIndex, height }: RowParams, index) => {
66
- // if previous row was header row, add its height to our margin
67
- let marginTop = -1;
68
- if (
69
- index === 1 &&
70
- hasHeaderRow &&
71
- this.props.stickyTop !== undefined
72
- ) {
73
- marginTop += rowHeights[index - 1] + tableToolbarSize;
74
- }
75
-
76
- const thisRowSticky =
77
- this.props.stickyTop !== undefined &&
78
- index === 0 &&
79
- hasHeaderRow;
80
-
81
- return (
82
- <div
83
- className={`${
84
- ClassName.ROW_CONTROLS_BUTTON_WRAP
85
- } ${getRowClassNames(
86
- startIndex,
87
- selection,
88
- hoveredRows,
89
- isInDanger,
90
- isResizing,
91
- )} ${thisRowSticky ? 'sticky' : ''}`}
92
- key={startIndex}
93
- style={{
94
- height: height,
95
- marginTop: `${marginTop}px`,
96
- top: thisRowSticky
97
- ? `${this.props.stickyTop! + 3}px`
98
- : undefined,
99
- paddingTop: thisRowSticky
100
- ? `${tableControlsSpacing}px`
101
- : undefined,
102
- }}
103
- >
104
- <button
105
- aria-label={formatMessage(messages.rowControl)}
106
- type="button"
107
- className={`${ClassName.ROW_CONTROLS_BUTTON}
108
- ${ClassName.CONTROLS_BUTTON}
109
- `}
110
- onClick={(event) =>
111
- this.props.selectRow(startIndex, event.shiftKey)
112
- }
113
- onMouseOver={() => this.props.hoverRows([startIndex])}
114
- onMouseOut={this.clearHoverSelection}
115
- data-start-index={startIndex}
116
- data-end-index={endIndex}
117
- />
118
-
119
- <div className={ClassName.CONTROLS_INSERT_MARKER} />
120
- </div>
121
- );
122
- },
123
- )}
124
- </div>
125
- </div>
126
- );
127
- }
128
-
129
- private clearHoverSelection = () => {
130
- const { state, dispatch } = this.props.editorView;
131
- clearHoverSelection()(state, dispatch);
132
- };
133
- }
134
-
135
- export const RowControls = injectIntl(RowControlsComponent);
1
+ export { RowControls } from './ClassicControls';
2
+ export { DragControls } from './DragControls';
@@ -1,22 +1,21 @@
1
1
  import React, { Component } from 'react';
2
2
 
3
3
  import type { TableColumnOrdering } from '@atlaskit/custom-steps';
4
- import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
5
4
  import { browser } from '@atlaskit/editor-common/utils';
6
5
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
7
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
7
 
9
8
  import { hoverRows, selectRow } from '../../commands';
10
9
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
10
+ import type { CellHoverCoordinates } from '../../types';
11
11
  import { isSelectionUpdated } from '../../utils';
12
12
 
13
13
  import { CornerControls } from './CornerControls';
14
14
  import NumberColumn from './NumberColumn';
15
- import { RowControls } from './RowControls';
15
+ import { DragControls, RowControls } from './RowControls';
16
16
 
17
17
  export interface Props {
18
18
  editorView: EditorView;
19
- getEditorFeatureFlags: GetEditorFeatureFlags;
20
19
  selection?: Selection;
21
20
  tableRef?: HTMLTableElement;
22
21
  tableActive?: boolean;
@@ -25,9 +24,11 @@ export interface Props {
25
24
  isHeaderRowEnabled?: boolean;
26
25
  isHeaderColumnEnabled?: boolean;
27
26
  isNumberColumnEnabled?: boolean;
27
+ isDragAndDropEnabled?: boolean;
28
28
  hasHeaderRow?: boolean;
29
29
  headerRowHeight?: number;
30
30
  hoveredRows?: number[];
31
+ hoveredCell?: CellHoverCoordinates;
31
32
  ordering?: TableColumnOrdering;
32
33
  stickyHeader?: RowStickyState;
33
34
  }
@@ -77,6 +78,7 @@ export default class TableFloatingControls extends Component<Props, State> {
77
78
  ordering,
78
79
  headerRowHeight,
79
80
  stickyHeader,
81
+ hoveredCell,
80
82
  } = this.props;
81
83
  const tableHeight = this.state?.tableHeight;
82
84
  const nextTableHeight = nextState?.tableHeight;
@@ -93,7 +95,8 @@ export default class TableFloatingControls extends Component<Props, State> {
93
95
  isNumberColumnEnabled !== nextProps.isNumberColumnEnabled ||
94
96
  isSelectionUpdated(selection!, nextProps.selection) ||
95
97
  headerRowHeight !== nextProps.headerRowHeight ||
96
- stickyHeader !== nextProps.stickyHeader
98
+ stickyHeader !== nextProps.stickyHeader ||
99
+ hoveredCell !== nextProps.hoveredCell
97
100
  );
98
101
  }
99
102
 
@@ -116,6 +119,8 @@ export default class TableFloatingControls extends Component<Props, State> {
116
119
  hasHeaderRow,
117
120
  hoveredRows,
118
121
  stickyHeader,
122
+ isDragAndDropEnabled,
123
+ hoveredCell,
119
124
  } = this.props;
120
125
 
121
126
  if (!tableRef) {
@@ -126,6 +131,7 @@ export default class TableFloatingControls extends Component<Props, State> {
126
131
  stickyHeader && stickyHeader.sticky && hasHeaderRow
127
132
  ? stickyHeader.top
128
133
  : undefined;
134
+
129
135
  return (
130
136
  <div onMouseDown={(e) => e.preventDefault()}>
131
137
  {isNumberColumnEnabled ? (
@@ -140,31 +146,44 @@ export default class TableFloatingControls extends Component<Props, State> {
140
146
  isResizing={isResizing}
141
147
  selectRow={this.selectRow}
142
148
  stickyTop={stickyTop}
149
+ isDragAndDropEnabled={isDragAndDropEnabled}
143
150
  />
144
151
  ) : null}
145
152
 
146
153
  {tableActive && (
147
154
  <>
148
- <CornerControls
149
- editorView={editorView}
150
- tableRef={tableRef}
151
- isInDanger={isInDanger}
152
- isResizing={isResizing}
153
- isHeaderRowEnabled={isHeaderRowEnabled}
154
- isHeaderColumnEnabled={isHeaderColumnEnabled}
155
- hoveredRows={hoveredRows}
156
- stickyTop={tableActive ? stickyTop : undefined}
157
- />
158
- <RowControls
159
- editorView={editorView}
160
- tableRef={tableRef}
161
- hoverRows={this.hoverRows}
162
- hoveredRows={hoveredRows}
163
- isInDanger={isInDanger}
164
- isResizing={isResizing}
165
- selectRow={this.selectRow}
166
- stickyTop={tableActive ? stickyTop : undefined}
167
- />
155
+ {isDragAndDropEnabled ? (
156
+ <DragControls
157
+ tableRef={tableRef}
158
+ hoveredCell={hoveredCell}
159
+ editorView={editorView}
160
+ hoverRows={this.hoverRows}
161
+ selectRow={this.selectRow}
162
+ />
163
+ ) : (
164
+ <>
165
+ <CornerControls
166
+ editorView={editorView}
167
+ tableRef={tableRef}
168
+ isInDanger={isInDanger}
169
+ isResizing={isResizing}
170
+ isHeaderRowEnabled={isHeaderRowEnabled}
171
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
172
+ hoveredRows={hoveredRows}
173
+ stickyTop={tableActive ? stickyTop : undefined}
174
+ />
175
+ <RowControls
176
+ editorView={editorView}
177
+ tableRef={tableRef}
178
+ hoverRows={this.hoverRows}
179
+ hoveredRows={hoveredRows}
180
+ isInDanger={isInDanger}
181
+ isResizing={isResizing}
182
+ selectRow={this.selectRow}
183
+ stickyTop={tableActive ? stickyTop : undefined}
184
+ />
185
+ </>
186
+ )}
168
187
  </>
169
188
  )}
170
189
  </div>
@@ -31,6 +31,7 @@ import {
31
31
  columnControlsDecorationHeight,
32
32
  resizeHandlerAreaWidth,
33
33
  resizeLineWidth,
34
+ rowControlsZIndex,
34
35
  stickyHeaderBorderBottomWidth,
35
36
  stickyRowOffsetTop,
36
37
  tableBorderColor,
@@ -63,6 +64,7 @@ import {
63
64
  hoveredDeleteButton,
64
65
  hoveredWarningCell,
65
66
  insertColumnButtonWrapper,
67
+ insertLine,
66
68
  InsertMarker,
67
69
  insertRowButtonWrapper,
68
70
  OverflowShadow,
@@ -239,6 +241,26 @@ const tableStickyHeaderColumnControlsDecorationsStyle = (
239
241
  }
240
242
  };
241
243
 
244
+ const tableRowControlStyles = () => {
245
+ return getBooleanFF('platform.editor.table.drag-and-drop')
246
+ ? css`
247
+ .${ClassName.ROW_CONTROLS_WRAPPER} {
248
+ position: absolute;
249
+ margin-top: ${tableMarginTop}px;
250
+ left: -${tableToolbarSize + 1}px;
251
+ z-index: ${rowControlsZIndex};
252
+ }
253
+ `
254
+ : css`
255
+ .${ClassName.ROW_CONTROLS_WRAPPER} {
256
+ position: absolute;
257
+ /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
258
+ top: ${tableMarginTop - cornerControlHeight + 1}px;
259
+ left: -${tableToolbarSize}px;
260
+ }
261
+ `;
262
+ };
263
+
242
264
  const tableWrapperStyles = () => {
243
265
  if (getBooleanFF('platform.editor.custom-table-width')) {
244
266
  return css`
@@ -291,6 +313,7 @@ export const tableStyles = (
291
313
  ${hoveredDeleteButton(props)};
292
314
  ${hoveredCell(props)};
293
315
  ${hoveredWarningCell};
316
+ ${getBooleanFF('platform.editor.table.drag-and-drop') && insertLine(props)};
294
317
  ${resizeHandle(props)};
295
318
  ${rangeSelectionStyles};
296
319
 
@@ -675,6 +698,12 @@ export const tableStyles = (
675
698
  )}
676
699
  }
677
700
 
701
+ .${ClassName.ROW_CONTROLS_WITH_DRAG} {
702
+ display: grid;
703
+ align-items: center;
704
+ position: absolute;
705
+ }
706
+
678
707
  ${floatingColumnControls(props)}
679
708
 
680
709
  :not(.${ClassName.IS_RESIZING}) .${ClassName.ROW_CONTROLS} {
@@ -689,7 +718,9 @@ export const tableStyles = (
689
718
  margin-left: ${getBooleanFF('platform.editor.custom-table-width')
690
719
  ? akEditorTableToolbarSize
691
720
  : akEditorTableToolbarSize - 1}px;
692
- top: ${akEditorTableToolbarSize}px;
721
+ top: ${getBooleanFF('platform.editor.table.drag-and-drop')
722
+ ? 0
723
+ : akEditorTableToolbarSize}px;
693
724
  width: ${akEditorTableNumberColumnWidth + 1}px;
694
725
  box-sizing: border-box;
695
726
  }
@@ -715,6 +746,21 @@ export const tableStyles = (
715
746
  }
716
747
  }
717
748
 
749
+ // add a background above the first numbered column cell when sticky header is engaged
750
+ // which hides the table when scrolling
751
+ .${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}:first-of-type::after {
752
+ content: '';
753
+ display: block;
754
+ height: 33px;
755
+ width: 100%;
756
+ background-color: ${token('elevation.surface', 'white')};
757
+ position: absolute;
758
+
759
+ // the extra pixel is accounting for borders
760
+ top: -34px;
761
+ left: -1px;
762
+ }
763
+
718
764
  .${ClassName.WITH_CONTROLS} {
719
765
  .${ClassName.CORNER_CONTROLS}, .${ClassName.ROW_CONTROLS} {
720
766
  display: block;
@@ -739,10 +785,10 @@ export const tableStyles = (
739
785
  }
740
786
  }
741
787
  :not(.${ClassName.IS_RESIZING}) .${ClassName.WITH_CONTROLS} {
742
- .${ClassName.NUMBERED_COLUMN_BUTTON} {
788
+ .${ClassName.NUMBERED_COLUMN_BUTTON}:not(.${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}) {
743
789
  cursor: pointer;
744
790
  }
745
- .${ClassName.NUMBERED_COLUMN_BUTTON}:hover {
791
+ .${ClassName.NUMBERED_COLUMN_BUTTON}:not(.${ClassName.NUMBERED_COLUMN_BUTTON_DISABLED}):hover {
746
792
  border-bottom: 1px solid ${tableBorderSelectedColor(props)};
747
793
  border-color: ${tableBorderSelectedColor(props)};
748
794
  background-color: ${tableToolbarSelectedColor(props)};
@@ -778,6 +824,10 @@ export const tableStyles = (
778
824
  margin-top: 0;
779
825
  }
780
826
 
827
+ .${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} + * {
828
+ margin-top: 0;
829
+ }
830
+
781
831
  /*
782
832
  * Headings have a top margin by default, but we don't want this on the
783
833
  * first heading within table header cells.
@@ -851,17 +901,10 @@ export const tableStyles = (
851
901
  }
852
902
  }
853
903
  }
854
- .${ClassName.ROW_CONTROLS_WRAPPER} {
855
- position: absolute;
856
- /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
857
- top: ${tableMarginTop - cornerControlHeight + 1}px;
858
- }
904
+ ${tableRowControlStyles()}
859
905
  .${ClassName.ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW} {
860
906
  z-index: ${akEditorUnitZIndex};
861
907
  }
862
- .${ClassName.ROW_CONTROLS_WRAPPER} {
863
- left: -${tableToolbarSize}px;
864
- }
865
908
 
866
909
  .${ClassName.COLUMN_CONTROLS_WRAPPER} {
867
910
  position: absolute;
@@ -130,7 +130,9 @@ export const lineMarkerSize = 4;
130
130
  export const columnControlsDecorationHeight = 25;
131
131
  export const columnControlsZIndex = akEditorUnitZIndex * 10;
132
132
  export const columnControlsSelectedZIndex = columnControlsZIndex + 1;
133
+ export const rowControlsZIndex = akEditorUnitZIndex * 10;
133
134
  export const columnResizeHandleZIndex = columnControlsSelectedZIndex + 1;
135
+ export const insertLineWidth = 3;
134
136
  export const resizeHandlerAreaWidth = RESIZE_HANDLE_AREA_DECORATION_GAP / 3;
135
137
  export const resizeLineWidth = 2;
136
138
  export const resizeHandlerZIndex =