@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
@@ -5,10 +5,20 @@ import type {
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
+ import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
9
+ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
10
+
11
+ import type { DraggableSourceData } from '../../types';
12
+ import {
13
+ hasMergedCellsInColumn,
14
+ hasMergedCellsInRow,
15
+ } from '../../utils/merged-cells';
16
+ import { getPluginState as getTablePluginState } from '../plugin-factory';
8
17
 
9
18
  import { DropTargetType } from './consts';
10
19
  import { createPluginState, getPluginState } from './plugin-factory';
11
20
  import { pluginKey } from './plugin-key';
21
+ import { getDraggableDataFromEvent } from './utils/monitor';
12
22
 
13
23
  export const createPlugin = (
14
24
  dispatch: Dispatch,
@@ -24,11 +34,74 @@ export const createPlugin = (
24
34
  })),
25
35
  key: pluginKey,
26
36
  view: (editorView: EditorView) => {
27
- // TODO: Add Pragmatic DnD monitor when the view is constructed.
28
-
29
37
  return {
30
- // TODO: Cleanup monitor instance
31
- // destroy: cleanup,
38
+ destroy: monitorForElements({
39
+ canMonitor({ source }) {
40
+ const { type, localId, indexes } =
41
+ source.data as Partial<DraggableSourceData>;
42
+
43
+ // First; Perform any quick checks so we can abort early.
44
+ if (
45
+ !indexes ||
46
+ !localId ||
47
+ // FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
48
+ // of more then 1 item.
49
+ indexes.length !== 1 ||
50
+ !(type === 'table-row' || type === 'table-column')
51
+ ) {
52
+ return false;
53
+ }
54
+
55
+ const { tableNode } = getTablePluginState(editorView.state);
56
+ // If the draggable localId is the same as the current selected table localId then we will allow the monitor
57
+ // watch for changes
58
+ return localId === tableNode?.attrs.localId;
59
+ },
60
+ onDrag(event) {
61
+ const data = getDraggableDataFromEvent(event);
62
+
63
+ // If no data can be found then it's most like we do not want to perform any drag actions
64
+ if (!data) {
65
+ return;
66
+ }
67
+
68
+ // TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
69
+ // insert location as to where the draggable will most likely be go. For example;
70
+ // const { sourceType, targetAdjustedIndex } = data;
71
+ // const highlight = sourceType === 'table-row' ? highlightRow : highlightColumn;
72
+ // return editorView.dispatch(
73
+ // highlight(targetAdjustedIndex)(editorView.state.tr),
74
+ // );
75
+ },
76
+ onDrop(event) {
77
+ const data = getDraggableDataFromEvent(event);
78
+
79
+ // If no data can be found then it's most like we do not want to perform any drop action
80
+ if (!data) {
81
+ return;
82
+ }
83
+
84
+ const { sourceType, sourceIndexes, targetAdjustedIndex } = data;
85
+
86
+ // If the drop target index contains merged cells then we should not allow the drop to occur.
87
+ const hasMergedCells =
88
+ sourceType === 'table-row'
89
+ ? hasMergedCellsInRow
90
+ : hasMergedCellsInColumn;
91
+ if (
92
+ hasMergedCells(targetAdjustedIndex)(editorView.state.selection)
93
+ ) {
94
+ return;
95
+ }
96
+
97
+ const move = sourceType === 'table-row' ? moveRow : moveColumn;
98
+
99
+ const [sourceIndex] = sourceIndexes;
100
+ return editorView.dispatch(
101
+ move(sourceIndex, targetAdjustedIndex)(editorView.state.tr),
102
+ );
103
+ },
104
+ }),
32
105
  };
33
106
  },
34
107
  props: {
@@ -11,12 +11,14 @@ export default (
11
11
  case DragAndDropActionType.SET_DROP_TARGET:
12
12
  return {
13
13
  ...pluginState,
14
+ decorationSet: action.data.decorationSet,
14
15
  dropTargetType: action.data.type,
15
16
  dropTargetIndex: action.data.index,
16
17
  };
17
18
  case DragAndDropActionType.CLEAR_DROP_TARGET:
18
19
  return {
19
20
  ...pluginState,
21
+ decorationSet: action.data.decorationSet,
20
22
  dropTargetType: DropTargetType.NONE,
21
23
  dropTargetIndex: 0,
22
24
  };
@@ -0,0 +1 @@
1
+ export { getDraggableDataFromEvent } from './monitor';
@@ -0,0 +1,72 @@
1
+ import { extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
2
+ import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
3
+ import type { ElementEventBasePayload } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
+
5
+ import type {
6
+ DraggableData,
7
+ DraggableSourceData,
8
+ DraggableTargetData,
9
+ } from '../../../types';
10
+
11
+ export const getDraggableDataFromEvent = ({
12
+ location,
13
+ source,
14
+ }: ElementEventBasePayload): DraggableData | undefined => {
15
+ const destination = location.current.dropTargets.at(0);
16
+ // If no target exists at the current location, then the current draggable is not over a target or the target doesn't support
17
+ // the current draggable.
18
+ if (!destination) {
19
+ return undefined;
20
+ }
21
+
22
+ // This is the draggable elements data
23
+ const {
24
+ indexes: sourceIndexes,
25
+ type: sourceType,
26
+ localId: sourceLocalId,
27
+ } = source.data as DraggableSourceData;
28
+
29
+ // This is the drop target's data
30
+ const {
31
+ targetIndex,
32
+ type: targetType,
33
+ localId: targetLocalId,
34
+ } = destination.data as DraggableTargetData;
35
+
36
+ // Some basic check to abort early with...
37
+ if (
38
+ !sourceIndexes ||
39
+ targetIndex < 0 ||
40
+ // abort if the type of the draggable is different to the target, for eg. rows cannot be dropped onto column targets.
41
+ sourceType !== targetType ||
42
+ // abort if the draggable is coming from a different table that the target is on.
43
+ sourceLocalId !== targetLocalId
44
+ ) {
45
+ return undefined;
46
+ }
47
+
48
+ // FIXME: currently we only support a single row/col index being moved, remove this clause when this is no longer the case.
49
+ if (sourceIndexes.length > 1) {
50
+ return undefined;
51
+ }
52
+
53
+ const targetClosestEdge =
54
+ extractClosestEdge(destination.data) ??
55
+ ((targetType === 'table-row' ? 'top' : 'left') as Edge);
56
+ // NOTE: By default we always insert row/cols at the target index to the top/left (retrospectively of row/cols).
57
+ // This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
58
+ // the new target index to be 1 index higher.
59
+ const targetOffset =
60
+ targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
61
+
62
+ return {
63
+ sourceType,
64
+ sourceLocalId,
65
+ sourceIndexes,
66
+ targetType,
67
+ targetLocalId,
68
+ targetIndex,
69
+ targetAdjustedIndex: targetIndex + targetOffset,
70
+ targetClosestEdge,
71
+ };
72
+ };
@@ -63,6 +63,7 @@ import {
63
63
  handleMouseOver,
64
64
  handleTripleClick,
65
65
  whenTableInFocus,
66
+ withCellTracking,
66
67
  } from '../event-handlers';
67
68
  import { createTableView } from '../nodeviews/table';
68
69
  import TableCell from '../nodeviews/TableCell';
@@ -85,7 +86,10 @@ import {
85
86
  } from '../utils';
86
87
  import { isHeaderRowRequired } from '../utils/paste';
87
88
 
88
- import { defaultTableSelection } from './default-table-selection';
89
+ import {
90
+ defaultHoveredCell,
91
+ defaultTableSelection,
92
+ } from './default-table-selection';
89
93
  import { createPluginState, getPluginState } from './plugin-factory';
90
94
  import { pluginKey } from './plugin-key';
91
95
 
@@ -99,8 +103,8 @@ export const createPlugin = (
99
103
  getEditorFeatureFlags: GetEditorFeatureFlags,
100
104
  getIntl: () => IntlShape,
101
105
  breakoutEnabled?: boolean,
102
- fullWidthModeEnabled?: boolean,
103
106
  tableResizingEnabled?: boolean,
107
+ fullWidthModeEnabled?: boolean,
104
108
  previousFullWidthModeEnabled?: boolean,
105
109
  dragAndDropEnabled?: boolean,
106
110
  editorAnalyticsAPI?: EditorAnalyticsAPI,
@@ -117,6 +121,7 @@ export const createPlugin = (
117
121
  isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
118
122
  isHeaderColumnEnabled: false,
119
123
  isDragAndDropEnabled: dragAndDropEnabled,
124
+ ...defaultHoveredCell,
120
125
  ...defaultTableSelection,
121
126
  getIntl,
122
127
  });
@@ -375,8 +380,8 @@ export const createPlugin = (
375
380
  handleDOMEvents: {
376
381
  focus: handleFocus,
377
382
  blur: handleBlur,
378
- mousedown: handleMouseDown,
379
- mouseover: whenTableInFocus(handleMouseOver),
383
+ mousedown: withCellTracking(handleMouseDown),
384
+ mouseover: whenTableInFocus(withCellTracking(handleMouseOver)),
380
385
  mouseleave: whenTableInFocus(handleMouseLeave),
381
386
  mouseout: whenTableInFocus(handleMouseOut),
382
387
  mousemove: whenTableInFocus(handleMouseMove, elementContentRects),
@@ -145,7 +145,8 @@ export default (
145
145
  case 'HOVER_ROWS':
146
146
  case 'HOVER_COLUMNS':
147
147
  case 'HOVER_TABLE':
148
- case 'HOVER_CELLS':
148
+ case 'HOVER_MERGED_CELLS':
149
+ case 'HOVER_CELL':
149
150
  case 'SHOW_RESIZE_HANDLE_LINE':
150
151
  case 'SET_EDITOR_FOCUS':
151
152
  return { ...pluginState, ...action.data };
@@ -14,6 +14,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
14
14
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
15
15
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
16
16
  import type { Rect } from '@atlaskit/editor-tables/table-map';
17
+ import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
17
18
 
18
19
  import type tablePlugin from './index';
19
20
 
@@ -85,10 +86,13 @@ export type { ColumnResizingPluginState } from '@atlaskit/editor-common/types';
85
86
  */
86
87
  export type CellColumnPositioning = Pick<Rect, 'right' | 'left'>;
87
88
 
89
+ export type CellHoverCoordinates = { colIndex?: number; rowIndex?: number };
90
+
88
91
  export interface TablePluginState {
89
92
  editorHasFocus?: boolean;
90
93
  hoveredColumns: number[];
91
94
  hoveredRows: number[];
95
+ hoveredCell: CellHoverCoordinates;
92
96
  pluginConfig: PluginConfig;
93
97
  isHeaderColumnEnabled: boolean;
94
98
  isHeaderRowEnabled: boolean;
@@ -121,7 +125,6 @@ export interface TablePluginState {
121
125
  isBreakoutEnabled?: boolean;
122
126
  wasFullWidthModeEnabled?: boolean;
123
127
  isTableResizingEnabled?: boolean;
124
-
125
128
  isDragAndDropEnabled?: boolean;
126
129
  }
127
130
 
@@ -150,7 +153,7 @@ export type TablePluginAction =
150
153
  };
151
154
  }
152
155
  | {
153
- type: 'HOVER_CELLS';
156
+ type: 'HOVER_MERGED_CELLS';
154
157
  data: {
155
158
  decorationSet: DecorationSet;
156
159
  };
@@ -197,6 +200,7 @@ export type TablePluginAction =
197
200
  | { type: 'CLEAR_HOVER_SELECTION'; data: { decorationSet: DecorationSet } }
198
201
  | { type: 'SHOW_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
199
202
  | { type: 'HIDE_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
203
+ | { type: 'HOVER_CELL'; data: CellHoverCoordinates }
200
204
  | { type: 'SET_TARGET_CELL_POSITION'; data: { targetCellPosition?: number } }
201
205
  | {
202
206
  type: 'SELECT_COLUMN';
@@ -232,6 +236,7 @@ export type ColumnResizingPluginAction =
232
236
  };
233
237
 
234
238
  export enum TableDecorations {
239
+ /** Classic controls */
235
240
  ALL_CONTROLS_HOVER = 'CONTROLS_HOVER',
236
241
  ROW_CONTROLS_HOVER = 'ROW_CONTROLS_HOVER',
237
242
  COLUMN_CONTROLS_HOVER = 'COLUMN_CONTROLS_HOVER',
@@ -245,12 +250,16 @@ export enum TableDecorations {
245
250
  COLUMN_RESIZING_HANDLE_WIDGET = 'COLUMN_RESIZING_HANDLE_WIDGET',
246
251
  COLUMN_RESIZING_HANDLE_LINE = 'COLUMN_RESIZING_HANDLE_LINE',
247
252
 
253
+ COLUMN_INSERT_LINE = 'COLUMN_INSERT_LINE',
254
+ ROW_INSERT_LINE = 'ROW_INSERT_LINE',
255
+
248
256
  LAST_CELL_ELEMENT = 'LAST_CELL_ELEMENT',
249
257
  }
250
258
 
251
259
  export const TableCssClassName = {
252
260
  ...TableSharedCssClassName,
253
261
 
262
+ /** Classic controls */
254
263
  COLUMN_CONTROLS: `${tablePrefixSelector}-column-controls`,
255
264
  COLUMN_CONTROLS_DECORATIONS: `${tablePrefixSelector}-column-controls-decoration`,
256
265
  COLUMN_SELECTED: `${tablePrefixSelector}-column__selected`,
@@ -289,8 +298,15 @@ export const TableCssClassName = {
289
298
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
290
299
  CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
291
300
 
301
+ /** Controls with drag handle */
302
+ COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: `${tablePrefixSelector}-column-controls-decoration-with-drag`,
303
+
304
+ ROW_CONTROLS_WITH_DRAG: `${tablePrefixSelector}-row-controls-with-drag`,
305
+
306
+ /** Other classes */
292
307
  NUMBERED_COLUMN: `${tablePrefixSelector}-numbered-column`,
293
308
  NUMBERED_COLUMN_BUTTON: `${tablePrefixSelector}-numbered-column__button`,
309
+ NUMBERED_COLUMN_BUTTON_DISABLED: `${tablePrefixSelector}-numbered-column__button-disabled`,
294
310
 
295
311
  HOVERED_COLUMN: `${tablePrefixSelector}-hovered-column`,
296
312
  HOVERED_ROW: `${tablePrefixSelector}-hovered-row`,
@@ -329,8 +345,15 @@ export const TableCssClassName = {
329
345
  TOP_LEFT_CELL: 'table > tbody > tr:nth-child(2) > td:nth-child(1)',
330
346
  LAST_ITEM_IN_CELL: `${tablePrefixSelector}-last-item-in-cell`,
331
347
 
348
+ WITH_COLUMN_INSERT_LINE: `${tablePrefixSelector}-column-insert-line`,
349
+ WITH_FIRST_COLUMN_INSERT_LINE: `${tablePrefixSelector}-first-column-insert-line`,
350
+ WITH_LAST_COLUMN_INSERT_LINE: `${tablePrefixSelector}-last-column-insert-line`,
351
+
332
352
  WITH_RESIZE_LINE: `${tablePrefixSelector}-column-resize-line`,
333
353
  WITH_RESIZE_LINE_LAST_COLUMN: `${tablePrefixSelector}-column-resize-line-last-column`,
354
+
355
+ WITH_ROW_INSERT_LINE: `${tablePrefixSelector}-row-insert-line`,
356
+ WITH_LAST_ROW_INSERT_LINE: `${tablePrefixSelector}-last-row-insert-line`,
334
357
  };
335
358
 
336
359
  export interface ToolbarMenuConfig {
@@ -383,8 +406,19 @@ export interface DraggableSourceData extends Record<string, unknown> {
383
406
  indexes: number[];
384
407
  }
385
408
 
386
- export interface DraggableTargetData extends Record<string, unknown> {
409
+ export interface DraggableTargetData extends Record<string | symbol, unknown> {
387
410
  type: DraggableType;
388
411
  localId: string;
389
412
  targetIndex: number;
390
413
  }
414
+
415
+ export interface DraggableData {
416
+ sourceType: DraggableType;
417
+ sourceLocalId: string;
418
+ sourceIndexes: number[];
419
+ targetType: DraggableType;
420
+ targetLocalId: string;
421
+ targetIndex: number;
422
+ targetAdjustedIndex: number;
423
+ targetClosestEdge: Edge;
424
+ }
@@ -0,0 +1,57 @@
1
+ import type { MouseEventHandler } from 'react';
2
+ import React, { useEffect, useRef } from 'react';
3
+
4
+ import { DragHandleButton } from '@atlaskit/pragmatic-drag-and-drop-react-accessibility/drag-handle-button';
5
+ import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
6
+ import { token } from '@atlaskit/tokens';
7
+
8
+ type DragHandleProps = {
9
+ tableLocalId: string;
10
+ indexes: number[];
11
+ direction?: 'column' | 'row';
12
+ onClick?: MouseEventHandler;
13
+ onMouseOver?: MouseEventHandler;
14
+ onMouseOut?: MouseEventHandler;
15
+ };
16
+
17
+ // TODO: use for now, in future replace with custom @atlaskit/icon/glyph/drag-handler
18
+ // width is too large (24px), should be 16px
19
+ export const DragHandle = ({
20
+ tableLocalId,
21
+ direction = 'row',
22
+ indexes,
23
+ onClick,
24
+ onMouseOver,
25
+ onMouseOut,
26
+ }: DragHandleProps) => {
27
+ const dragHandleDivRef = useRef<HTMLDivElement>(null);
28
+
29
+ useEffect(() => {
30
+ const dragHandleDivRefCurrent = dragHandleDivRef.current;
31
+ if (dragHandleDivRefCurrent) {
32
+ return draggable({
33
+ element: dragHandleDivRefCurrent,
34
+ getInitialData() {
35
+ return {
36
+ localId: tableLocalId,
37
+ type: `table-${direction}`,
38
+ indexes,
39
+ };
40
+ },
41
+ });
42
+ }
43
+ }, [tableLocalId, direction, indexes]);
44
+ return (
45
+ <div
46
+ ref={dragHandleDivRef}
47
+ style={{
48
+ backgroundColor: `${token('elevation.surface', 'white')}`,
49
+ borderRadius: '4px',
50
+ border: `2px solid ${token('elevation.surface', 'white')}`,
51
+ transform: direction === 'column' ? 'rotate(90deg)' : 'none',
52
+ }}
53
+ >
54
+ <DragHandleButton label="blah" />
55
+ </div>
56
+ );
57
+ };
@@ -1,12 +1,16 @@
1
1
  import React, { Component } from 'react';
2
2
 
3
+ import classnames from 'classnames';
4
+
3
5
  import { Selection } from '@atlaskit/editor-prosemirror/state';
4
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
7
  import { isRowSelected } from '@atlaskit/editor-tables/utils';
6
8
 
7
- import { clearHoverSelection } from '../../../commands';
9
+ import { clearHoverSelection, hoverCell } from '../../../commands';
10
+ import { getPluginState } from '../../../pm-plugins/plugin-factory';
8
11
  import { TableCssClassName as ClassName } from '../../../types';
9
12
  import { getRowHeights } from '../../../utils';
13
+ import { tableBorderColor } from '../../consts';
10
14
 
11
15
  export interface Props {
12
16
  editorView: EditorView;
@@ -19,11 +23,13 @@ export interface Props {
19
23
  isInDanger?: boolean;
20
24
  isResizing?: boolean;
21
25
  stickyTop?: number;
26
+ isDragAndDropEnabled?: boolean;
22
27
  }
23
28
 
24
29
  export default class NumberColumn extends Component<Props, any> {
25
30
  render() {
26
- const { tableRef, hasHeaderRow } = this.props;
31
+ const { tableRef, hasHeaderRow, isDragAndDropEnabled, tableActive } =
32
+ this.props;
27
33
  const rowHeights = getRowHeights(tableRef);
28
34
 
29
35
  return (
@@ -34,30 +40,38 @@ export default class NumberColumn extends Component<Props, any> {
34
40
  hasHeaderRow && this.props.stickyTop !== undefined
35
41
  ? rowHeights[0]
36
42
  : undefined,
43
+ borderLeft:
44
+ isDragAndDropEnabled && tableActive
45
+ ? `1px solid ${tableBorderColor()}`
46
+ : undefined,
37
47
  }}
38
48
  contentEditable={false}
39
49
  >
40
- {rowHeights.map((rowHeight, index) => (
41
- <div
42
- key={`wrapper-${index}`}
43
- className={this.getClassNames(index)}
44
- data-index={index}
45
- style={{
46
- height: rowHeight,
47
- top:
48
- this.props.stickyTop !== undefined &&
49
- hasHeaderRow &&
50
- index === 0
51
- ? `${this.props.stickyTop}px`
52
- : undefined,
53
- }}
54
- onClick={(event) => this.selectRow(index, event)}
55
- onMouseOver={() => this.hoverRows(index)}
56
- onMouseOut={this.clearHoverSelection}
57
- >
58
- {hasHeaderRow ? (index > 0 ? index : null) : index + 1}
59
- </div>
60
- ))}
50
+ {rowHeights.map((rowHeight, index) =>
51
+ isDragAndDropEnabled ? (
52
+ <div
53
+ key={`wrapper-${index}`}
54
+ className={this.getClassNames(index, true)}
55
+ data-index={index}
56
+ style={this.getCellStyles(index, rowHeight)}
57
+ onMouseOver={() => this.updateDragHandleLocation(index)}
58
+ >
59
+ {hasHeaderRow ? (index > 0 ? index : null) : index + 1}
60
+ </div>
61
+ ) : (
62
+ <div
63
+ key={`wrapper-${index}`}
64
+ className={this.getClassNames(index)}
65
+ data-index={index}
66
+ style={this.getCellStyles(index, rowHeight)}
67
+ onClick={(event) => this.selectRow(index, event)}
68
+ onMouseOver={() => this.hoverRows(index)}
69
+ onMouseOut={this.clearHoverSelection}
70
+ >
71
+ {hasHeaderRow ? (index > 0 ? index : null) : index + 1}
72
+ </div>
73
+ ),
74
+ )}
61
75
  </div>
62
76
  );
63
77
  }
@@ -95,15 +109,39 @@ export default class NumberColumn extends Component<Props, any> {
95
109
  }
96
110
  };
97
111
 
98
- private getClassNames = (index: number) => {
112
+ private updateDragHandleLocation = (rowIndex: number) => {
113
+ const { editorView, tableActive } = this.props;
114
+ const { state, dispatch } = editorView;
115
+ const { hoveredCell } = getPluginState(state);
116
+
117
+ if (tableActive && hoveredCell.rowIndex !== rowIndex) {
118
+ hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
119
+ }
120
+ };
121
+
122
+ private getCellStyles = (index: number, rowHeight: number) => {
123
+ const { stickyTop, hasHeaderRow } = this.props;
124
+ if (stickyTop && hasHeaderRow && index === 0) {
125
+ return {
126
+ height: rowHeight,
127
+ top: `${stickyTop}px`,
128
+ };
129
+ }
130
+ return {
131
+ height: rowHeight,
132
+ };
133
+ };
134
+
135
+ private getClassNames = (index: number, isButtonDisabled = false) => {
99
136
  const { hoveredRows, editorView, isInDanger, isResizing } = this.props;
100
137
  const isActive =
101
138
  isRowSelected(index)(editorView.state.selection) ||
102
139
  ((hoveredRows || []).indexOf(index) !== -1 && !isResizing);
103
- return [
104
- ClassName.NUMBERED_COLUMN_BUTTON,
105
- isActive ? ClassName.HOVERED_CELL_ACTIVE : '',
106
- isActive && isInDanger ? ClassName.HOVERED_CELL_IN_DANGER : '',
107
- ].join(' ');
140
+
141
+ return classnames(ClassName.NUMBERED_COLUMN_BUTTON, {
142
+ [ClassName.NUMBERED_COLUMN_BUTTON_DISABLED]: isButtonDisabled,
143
+ [ClassName.HOVERED_CELL_IN_DANGER]: isActive && isInDanger,
144
+ [ClassName.HOVERED_CELL_ACTIVE]: isActive,
145
+ });
108
146
  };
109
147
  }