@atlaskit/editor-plugin-table 5.5.12 → 5.6.0

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 (52) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/plugins/table/index.js +5 -3
  3. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.js +72 -0
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +14 -5
  5. package/dist/cjs/plugins/table/ui/DragHandle/index.js +4 -1
  6. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  7. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +12 -13
  8. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -1
  9. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  10. package/dist/cjs/plugins/table/utils/drag-menu.js +6 -5
  11. package/dist/es2019/plugins/table/index.js +5 -3
  12. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.js +66 -0
  13. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +15 -6
  14. package/dist/es2019/plugins/table/ui/DragHandle/index.js +3 -0
  15. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  16. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +12 -13
  17. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -1
  18. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  19. package/dist/es2019/plugins/table/utils/drag-menu.js +4 -3
  20. package/dist/esm/plugins/table/index.js +5 -3
  21. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.js +66 -0
  22. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +15 -6
  23. package/dist/esm/plugins/table/ui/DragHandle/index.js +4 -1
  24. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  25. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +12 -13
  26. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -1
  27. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  28. package/dist/esm/plugins/table/utils/drag-menu.js +4 -3
  29. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +6 -0
  30. package/dist/types/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
  31. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +2 -1
  32. package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +3 -1
  33. package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  34. package/dist/types/plugins/table/utils/drag-menu.d.ts +2 -1
  35. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +6 -0
  36. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
  37. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +2 -1
  38. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +3 -1
  39. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  40. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +2 -1
  41. package/package.json +2 -2
  42. package/src/__tests__/unit/analytics.ts +107 -3
  43. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +10 -13
  44. package/src/plugins/table/index.tsx +7 -2
  45. package/src/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.ts +100 -0
  46. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +30 -9
  47. package/src/plugins/table/ui/DragHandle/index.tsx +8 -0
  48. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +4 -0
  49. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +20 -16
  50. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +2 -5
  51. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +2 -5
  52. package/src/plugins/table/utils/drag-menu.ts +7 -3
@@ -1,5 +1,5 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
3
3
  import type { DocBuilder } from '@atlaskit/editor-common/types';
4
4
  // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
5
5
  import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
@@ -8,6 +8,7 @@ import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
8
8
  import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
9
9
  import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
10
10
  import { widthPlugin } from '@atlaskit/editor-plugin-width';
11
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
11
12
  import type { Rect } from '@atlaskit/editor-tables/table-map';
12
13
  // eslint-disable-next-line import/no-extraneous-dependencies
13
14
  import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
@@ -49,6 +50,11 @@ import {
49
50
  toggleTableLayoutWithAnalytics,
50
51
  } from '../../plugins/table/commands-with-analytics';
51
52
  import { handleCut } from '../../plugins/table/event-handlers';
53
+ import { setDropTarget } from '../../plugins/table/pm-plugins/drag-and-drop/commands';
54
+ import {
55
+ clearDropTargetWithAnalytics,
56
+ moveSourceWithAnalytics,
57
+ } from '../../plugins/table/pm-plugins/drag-and-drop/commands-with-analytics';
52
58
  import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
53
59
  import { replaceSelectedTable } from '../../plugins/table/transforms';
54
60
  import type { PluginConfig } from '../../plugins/table/types';
@@ -77,9 +83,10 @@ const analyticsPluginFake = () => ({
77
83
 
78
84
  describe('Table analytic events', () => {
79
85
  let editorAnalyticsAPIFake: EditorAnalyticsAPI;
80
- const analyticFireMock = jest.fn().mockReturnValue(jest.fn());
86
+ let analyticFireMock: jest.Mock;
81
87
 
82
88
  beforeEach(() => {
89
+ analyticFireMock = jest.fn().mockReturnValue(jest.fn());
83
90
  editorAnalyticsAPIFake = {
84
91
  attachAnalyticsEvent: analyticFireMock,
85
92
  fireAnalyticsEvent: jest.fn(),
@@ -108,7 +115,7 @@ describe('Table analytic events', () => {
108
115
  .add(widthPlugin)
109
116
  .add(guidelinePlugin)
110
117
  .add(selectionPlugin)
111
- .add([tablePlugin, { tableOptions }]),
118
+ .add([tablePlugin, { tableOptions, dragAndDropEnabled: true }]),
112
119
  pluginKey,
113
120
  });
114
121
 
@@ -741,4 +748,101 @@ describe('Table analytic events', () => {
741
748
  });
742
749
  });
743
750
  });
751
+
752
+ describe('track moved', () => {
753
+ it.each([
754
+ ['Column', INPUT_METHOD.TABLE_CONTEXT_MENU, 0, 1, TABLE_STATUS.SUCCESS],
755
+ ['Column', INPUT_METHOD.TABLE_CONTEXT_MENU, 2, 0, TABLE_STATUS.SUCCESS],
756
+ ['Column', INPUT_METHOD.TABLE_CONTEXT_MENU, 2, 2, TABLE_STATUS.CANCELLED],
757
+
758
+ ['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, 0, 1, TABLE_STATUS.SUCCESS],
759
+ ['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, 2, 0, TABLE_STATUS.SUCCESS],
760
+ ['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, 2, 2, TABLE_STATUS.CANCELLED],
761
+
762
+ ['Column', INPUT_METHOD.DRAG_AND_DROP, 0, 1, TABLE_STATUS.SUCCESS],
763
+ ['Column', INPUT_METHOD.DRAG_AND_DROP, 2, 0, TABLE_STATUS.SUCCESS],
764
+ ['Column', INPUT_METHOD.DRAG_AND_DROP, 2, 2, TABLE_STATUS.CANCELLED],
765
+
766
+ ['Row', INPUT_METHOD.DRAG_AND_DROP, 0, 1, TABLE_STATUS.SUCCESS],
767
+ ['Row', INPUT_METHOD.DRAG_AND_DROP, 2, 0, TABLE_STATUS.SUCCESS],
768
+ ['Row', INPUT_METHOD.DRAG_AND_DROP, 2, 2, TABLE_STATUS.CANCELLED],
769
+ ])(
770
+ 'should fire v3 analytics for %s using input %s moving index from %i to %i with status %s',
771
+ (type, inputMethod, sourceIndex, targetIndex, status) => {
772
+ const { editorView } = editor(defaultTableDoc);
773
+ moveSourceWithAnalytics(editorAnalyticsAPIFake)(
774
+ inputMethod as
775
+ | INPUT_METHOD.TABLE_CONTEXT_MENU
776
+ | INPUT_METHOD.DRAG_AND_DROP,
777
+ type === 'Row' ? 'table-row' : 'table-column',
778
+ sourceIndex,
779
+ targetIndex,
780
+ )(editorView.state, editorView.dispatch);
781
+
782
+ expect(analyticFireMock).toHaveBeenCalledWith({
783
+ action: `moved${type}`,
784
+ actionSubject: 'table',
785
+ actionSubjectId: null,
786
+ attributes: expect.objectContaining({
787
+ inputMethod,
788
+ count: 1,
789
+ distance: targetIndex - sourceIndex,
790
+ status,
791
+ totalRowCount: 3,
792
+ totalColumnCount: 3,
793
+ }),
794
+ eventType: 'track',
795
+ });
796
+ },
797
+ );
798
+
799
+ describe('track moved', () => {
800
+ let editorView: EditorView;
801
+
802
+ beforeEach(() => {
803
+ editorView = editor(defaultTableDoc).editorView;
804
+ // Note: we cannot clean a drop target, util one has been set.
805
+ setDropTarget('column', 0)(editorView.state, editorView.dispatch);
806
+ });
807
+
808
+ it.each([
809
+ ['Column', INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_STATUS.CANCELLED],
810
+ ['Column', INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_STATUS.INVALID],
811
+ ['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_STATUS.CANCELLED],
812
+ ['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_STATUS.INVALID],
813
+
814
+ ['Column', INPUT_METHOD.DRAG_AND_DROP, TABLE_STATUS.CANCELLED],
815
+ ['Column', INPUT_METHOD.DRAG_AND_DROP, TABLE_STATUS.INVALID],
816
+ ['Row', INPUT_METHOD.DRAG_AND_DROP, TABLE_STATUS.CANCELLED],
817
+ ['Row', INPUT_METHOD.DRAG_AND_DROP, TABLE_STATUS.INVALID],
818
+ ])(
819
+ 'should fire v3 analytics for %s using input %s with status %s',
820
+ (type, inputMethod, status) => {
821
+ // const { editorView } = editor(defaultTableDoc);
822
+ clearDropTargetWithAnalytics(editorAnalyticsAPIFake)(
823
+ inputMethod as
824
+ | INPUT_METHOD.TABLE_CONTEXT_MENU
825
+ | INPUT_METHOD.DRAG_AND_DROP,
826
+ type === 'Row' ? 'table-row' : 'table-column',
827
+ status as TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID,
828
+ )(editorView.state, editorView.dispatch);
829
+
830
+ expect(analyticFireMock).toHaveBeenCalledWith({
831
+ action: `moved${type}`,
832
+ actionSubject: 'table',
833
+ actionSubjectId: null,
834
+ attributes: expect.objectContaining({
835
+ inputMethod,
836
+ count: 1,
837
+ distance: 0,
838
+ status,
839
+ totalRowCount: 3,
840
+ totalColumnCount: 3,
841
+ }),
842
+ eventType: 'track',
843
+ });
844
+ },
845
+ );
846
+ });
847
+ });
744
848
  });
@@ -33,7 +33,7 @@ import {
33
33
  import { ffTest } from '@atlassian/feature-flags-test-utils';
34
34
 
35
35
  import tablePlugin from '../../../plugins/table-plugin';
36
- import FloatingDragMenu from '../../../plugins/table/ui/FloatingDragMenu';
36
+ import { DragMenu } from '../../../plugins/table/ui/FloatingDragMenu/DragMenu';
37
37
 
38
38
  describe('FloatingDragMenu', () => {
39
39
  const createEditor = createProsemirrorEditorFactory();
@@ -72,14 +72,13 @@ describe('FloatingDragMenu', () => {
72
72
  editorRef,
73
73
  }}
74
74
  >
75
- <FloatingDragMenu
75
+ <DragMenu
76
76
  editorView={editorView}
77
- isOpen
77
+ isOpen={true}
78
78
  getEditorContainerWidth={jest.fn()}
79
79
  tableRef={tableRef as HTMLTableElement}
80
80
  tableNode={tableNode?.node}
81
81
  direction="row"
82
- targetCellPosition={1}
83
82
  />
84
83
  </ReactEditorViewContext.Provider>,
85
84
  );
@@ -98,14 +97,13 @@ describe('FloatingDragMenu', () => {
98
97
  editorRef,
99
98
  }}
100
99
  >
101
- <FloatingDragMenu
100
+ <DragMenu
102
101
  editorView={editorView}
103
- isOpen
102
+ isOpen={true}
104
103
  getEditorContainerWidth={jest.fn()}
105
104
  tableRef={tableRef as HTMLTableElement}
106
105
  tableNode={tableNode?.node}
107
106
  direction="row"
108
- targetCellPosition={1}
109
107
  />
110
108
  </ReactEditorViewContext.Provider>,
111
109
  );
@@ -127,14 +125,14 @@ describe('FloatingDragMenu', () => {
127
125
  editorRef,
128
126
  }}
129
127
  >
130
- <FloatingDragMenu
128
+ <div id="drag-handle-button-row">dragmenu anchor</div>
129
+ <DragMenu
131
130
  editorView={editorView}
132
- isOpen
131
+ isOpen={true}
133
132
  getEditorContainerWidth={jest.fn()}
134
133
  tableRef={tableRef as HTMLTableElement}
135
134
  tableNode={tableNode?.node}
136
135
  direction="row"
137
- targetCellPosition={1}
138
136
  />
139
137
  </ReactEditorViewContext.Provider>,
140
138
  );
@@ -163,14 +161,13 @@ describe('FloatingDragMenu', () => {
163
161
  editorRef,
164
162
  }}
165
163
  >
166
- <FloatingDragMenu
164
+ <DragMenu
167
165
  editorView={editorView}
168
- isOpen
166
+ isOpen={true}
169
167
  getEditorContainerWidth={jest.fn()}
170
168
  tableRef={tableRef as HTMLTableElement}
171
169
  tableNode={tableNode?.node}
172
170
  direction="column"
173
- targetCellPosition={1}
174
171
  />
175
172
  </ReactEditorViewContext.Provider>,
176
173
  );
@@ -295,9 +295,13 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
295
295
  },
296
296
  {
297
297
  name: 'tableDragAndDrop',
298
- plugin: ({ dispatch, eventDispatcher }) =>
298
+ plugin: ({ dispatch, eventDispatcher, dispatchAnalyticsEvent }) =>
299
299
  options?.dragAndDropEnabled
300
- ? createDragAndDropPlugin(dispatch, eventDispatcher)
300
+ ? createDragAndDropPlugin(
301
+ dispatch,
302
+ eventDispatcher,
303
+ editorAnalyticsAPI,
304
+ )
301
305
  : undefined,
302
306
  },
303
307
  {
@@ -510,6 +514,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
510
514
  isOpen={!!dragAndDropState?.isDragMenuOpen && !isResizing}
511
515
  canDrag={dragAndDropState?.canDrag}
512
516
  getEditorContainerWidth={defaultGetEditorContainerWidth}
517
+ editorAnalyticsAPI={editorAnalyticsAPI}
513
518
  />
514
519
  )}
515
520
  {allowControls && !isDragAndDropEnabled && !isResizing && (
@@ -0,0 +1,100 @@
1
+ import {
2
+ ACTION_SUBJECT,
3
+ EVENT_TYPE,
4
+ TABLE_ACTION,
5
+ TABLE_STATUS,
6
+ } from '@atlaskit/editor-common/analytics';
7
+ import type {
8
+ EditorAnalyticsAPI,
9
+ INPUT_METHOD,
10
+ } from '@atlaskit/editor-common/analytics';
11
+ import type {
12
+ EditorState,
13
+ Transaction,
14
+ } from '@atlaskit/editor-prosemirror/state';
15
+
16
+ import type { DraggableType } from '../../types';
17
+ import { getSelectedTableInfo } from '../../utils';
18
+ import { withEditorAnalyticsAPI } from '../../utils/analytics';
19
+
20
+ import { clearDropTarget, moveSource } from './commands';
21
+
22
+ export const clearDropTargetWithAnalytics =
23
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
24
+ (
25
+ inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP,
26
+ sourceType: DraggableType,
27
+ status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID,
28
+ tr?: Transaction,
29
+ ) => {
30
+ return withEditorAnalyticsAPI(({ selection }: EditorState) => {
31
+ const { totalRowCount, totalColumnCount } =
32
+ getSelectedTableInfo(selection);
33
+ return {
34
+ action:
35
+ sourceType === 'table-row'
36
+ ? TABLE_ACTION.MOVED_ROW
37
+ : TABLE_ACTION.MOVED_COLUMN,
38
+ actionSubject: ACTION_SUBJECT.TABLE,
39
+ actionSubjectId: null,
40
+ attributes: {
41
+ inputMethod,
42
+ // TODO: When multiple sources can be moved we need to update this count to be the amount of sources which are being moved.
43
+ count: 1,
44
+ distance: 0,
45
+ status,
46
+ totalRowCount,
47
+ totalColumnCount,
48
+ },
49
+ eventType: EVENT_TYPE.TRACK,
50
+ };
51
+ })(editorAnalyticsAPI)((state, dispatch) => {
52
+ if (dispatch) {
53
+ clearDropTarget(tr)(state, dispatch);
54
+ }
55
+ return true;
56
+ });
57
+ };
58
+
59
+ export const moveSourceWithAnalytics =
60
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
61
+ (
62
+ inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP,
63
+ sourceType: DraggableType,
64
+ sourceIndex: number,
65
+ targetIndex: number,
66
+ tr?: Transaction,
67
+ ) => {
68
+ return withEditorAnalyticsAPI(({ selection }: EditorState) => {
69
+ const { totalRowCount, totalColumnCount } =
70
+ getSelectedTableInfo(selection);
71
+ return {
72
+ action:
73
+ sourceType === 'table-row'
74
+ ? TABLE_ACTION.MOVED_ROW
75
+ : TABLE_ACTION.MOVED_COLUMN,
76
+ actionSubject: ACTION_SUBJECT.TABLE,
77
+ actionSubjectId: null,
78
+ attributes: {
79
+ inputMethod,
80
+ // TODO: When multiple sources can be moved we need to update this count to be the amount of sources which are being moved.
81
+ count: 1,
82
+ // This identifies the total amount of row/cols the move operation covered
83
+ distance: targetIndex - sourceIndex,
84
+ // If a drop doesn't actually change anything then we're going to mark the event as cancelled.
85
+ status:
86
+ sourceIndex === targetIndex
87
+ ? TABLE_STATUS.CANCELLED
88
+ : TABLE_STATUS.SUCCESS,
89
+ totalRowCount,
90
+ totalColumnCount,
91
+ },
92
+ eventType: EVENT_TYPE.TRACK,
93
+ };
94
+ })(editorAnalyticsAPI)((state, dispatch) => {
95
+ if (dispatch) {
96
+ moveSource(sourceType, sourceIndex, targetIndex, tr)(state, dispatch);
97
+ }
98
+ return true;
99
+ });
100
+ };
@@ -1,3 +1,5 @@
1
+ import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
1
3
  import type {
2
4
  Dispatch,
3
5
  EventDispatcher,
@@ -19,12 +21,11 @@ import { pluginKey as tablePluginKey } from '../plugin-key';
19
21
  import { insertColgroupFromNode } from '../table-resizing/utils';
20
22
 
21
23
  import { DragAndDropActionType } from './actions';
24
+ import { clearDropTarget, setDropTarget, toggleDragMenu } from './commands';
22
25
  import {
23
- clearDropTarget,
24
- moveSource,
25
- setDropTarget,
26
- toggleDragMenu,
27
- } from './commands';
26
+ clearDropTargetWithAnalytics,
27
+ moveSourceWithAnalytics,
28
+ } from './commands-with-analytics';
28
29
  import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
29
30
  import { createPluginState, getPluginState } from './plugin-factory';
30
31
  import { pluginKey } from './plugin-key';
@@ -34,6 +35,7 @@ import { getDraggableDataFromEvent } from './utils/monitor';
34
35
  export const createPlugin = (
35
36
  dispatch: Dispatch,
36
37
  eventDispatcher: EventDispatcher,
38
+ editorAnalyticsAPI?: EditorAnalyticsAPI,
37
39
  ) => {
38
40
  return new SafePlugin({
39
41
  state: createPluginState(dispatch, (state) => ({
@@ -195,8 +197,20 @@ export const createPlugin = (
195
197
 
196
198
  // If no data can be found then it's most like we do not want to perform any drop action
197
199
  if (!data) {
198
- clearDropTarget(tr)(editorView.state, editorView.dispatch);
199
- return;
200
+ // If we're able to determine the source type of the dropped element then we should report to analytics that
201
+ // the drop event was cancelled. Otherwise we will cancel silently.
202
+ if (
203
+ event?.source?.data?.type === 'table-row' ||
204
+ event?.source?.data?.type === 'table-column'
205
+ ) {
206
+ return clearDropTargetWithAnalytics(editorAnalyticsAPI)(
207
+ INPUT_METHOD.DRAG_AND_DROP,
208
+ event.source.data.type,
209
+ TABLE_STATUS.CANCELLED,
210
+ tr,
211
+ )(editorView.state, editorView.dispatch);
212
+ }
213
+ return clearDropTarget(tr)(editorView.state, editorView.dispatch);
200
214
  }
201
215
 
202
216
  const {
@@ -223,14 +237,21 @@ export const createPlugin = (
223
237
  : DropTargetType.COLUMN,
224
238
  )(editorView.state.selection)
225
239
  ) {
226
- clearDropTarget(tr)(editorView.state, editorView.dispatch);
240
+ clearDropTargetWithAnalytics(editorAnalyticsAPI)(
241
+ INPUT_METHOD.DRAG_AND_DROP,
242
+ sourceType,
243
+ // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
244
+ TABLE_STATUS.INVALID,
245
+ tr,
246
+ )(editorView.state, editorView.dispatch);
227
247
  return;
228
248
  }
229
249
 
230
250
  const [sourceIndex] = sourceIndexes;
231
251
 
232
252
  requestAnimationFrame(() => {
233
- moveSource(
253
+ moveSourceWithAnalytics(editorAnalyticsAPI)(
254
+ INPUT_METHOD.DRAG_AND_DROP,
234
255
  sourceType,
235
256
  sourceIndex,
236
257
  targetAdjustedIndex + (direction === -1 ? 0 : -1),
@@ -33,9 +33,11 @@ type DragHandleProps = {
33
33
  onMouseUp?: MouseEventHandler;
34
34
  editorView: EditorView;
35
35
  canDrag?: boolean;
36
+ isDragMenuTarget: boolean; // this is identify which current handle component is
36
37
  };
37
38
 
38
39
  export const DragHandle = ({
40
+ isDragMenuTarget,
39
41
  tableLocalId,
40
42
  direction = 'row',
41
43
  appearance = 'default',
@@ -131,9 +133,15 @@ export const DragHandle = ({
131
133
  canDrag,
132
134
  ]);
133
135
 
136
+ const showDragMenuAnchorId =
137
+ direction === 'row'
138
+ ? 'drag-handle-button-row'
139
+ : 'drag-handle-button-column';
140
+
134
141
  return (
135
142
  <>
136
143
  <button
144
+ id={isDragMenuTarget ? showDragMenuAnchorId : undefined}
137
145
  className={classnames(
138
146
  ClassName.DRAG_HANDLE_BUTTON_CONTAINER,
139
147
  appearance,
@@ -1,6 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
3
 
4
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
5
  import type {
5
6
  Command,
6
7
  GetEditorContainerWidth,
@@ -51,6 +52,7 @@ type DragMenuProps = {
51
52
  pluginConfig?: PluginConfig;
52
53
  getEditorContainerWidth: GetEditorContainerWidth;
53
54
  canDrag?: boolean;
55
+ editorAnalyticsAPI?: EditorAnalyticsAPI;
54
56
  };
55
57
 
56
58
  const groupedDragMenuConfig = [
@@ -122,6 +124,7 @@ export const DragMenu = ({
122
124
  targetCellPosition,
123
125
  getEditorContainerWidth,
124
126
  canDrag,
127
+ editorAnalyticsAPI,
125
128
  }: DragMenuProps) => {
126
129
  const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
127
130
 
@@ -149,6 +152,7 @@ export const DragMenu = ({
149
152
  index,
150
153
  targetCellPosition,
151
154
  selectionRect,
155
+ editorAnalyticsAPI,
152
156
  );
153
157
 
154
158
  const { menuItems, menuCallback } = convertToDropdownItems(dragMenuConfig);
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
 
3
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
4
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
4
5
  import { Popup } from '@atlaskit/editor-common/ui';
5
6
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
6
- import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
8
  import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
9
- import { TableMap } from '@atlaskit/editor-tables/table-map';
9
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
10
10
 
11
11
  import type { TableDirection } from '../../types';
12
12
  import { dragMenuDropdownWidth } from '../consts';
@@ -26,6 +26,7 @@ export interface Props {
26
26
  targetCellPosition?: number;
27
27
  getEditorContainerWidth: GetEditorContainerWidth;
28
28
  canDrag?: boolean;
29
+ editorAnalyticsAPI?: EditorAnalyticsAPI;
29
30
  }
30
31
 
31
32
  const FloatingDragMenu = ({
@@ -34,13 +35,13 @@ const FloatingDragMenu = ({
34
35
  scrollableElement,
35
36
  editorView,
36
37
  isOpen,
37
- tableRef,
38
38
  tableNode,
39
39
  direction,
40
40
  index,
41
41
  targetCellPosition,
42
42
  getEditorContainerWidth,
43
43
  canDrag,
44
+ editorAnalyticsAPI,
44
45
  }: Props) => {
45
46
  if (
46
47
  !isOpen ||
@@ -50,24 +51,26 @@ const FloatingDragMenu = ({
50
51
  return null;
51
52
  }
52
53
 
53
- const domAtPos = editorView.domAtPos.bind(editorView);
54
- const targetCellRef = findDomRefAtPos(targetCellPosition, domAtPos);
55
- if (!targetCellRef) {
54
+ const targetHandleRef =
55
+ direction === 'row'
56
+ ? document.querySelector('#drag-handle-button-row')
57
+ : document.querySelector('#drag-handle-button-column');
58
+
59
+ if (
60
+ !targetHandleRef ||
61
+ !(editorView.state.selection instanceof CellSelection)
62
+ ) {
56
63
  return null;
57
64
  }
58
- const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
59
- const offset =
60
- direction === 'row'
61
- ? [7, 0]
62
- : index === (tableMap?.width || 1) - 1
63
- ? [14, 0]
64
- : [-14, 0];
65
+
66
+ const offset = direction === 'row' ? [-9, 6] : [0, -7];
67
+
65
68
  // TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
66
69
  return (
67
70
  <Popup
68
- alignX={direction === 'row' ? 'left' : 'center'}
69
- alignY="top"
70
- target={targetCellRef as HTMLElement}
71
+ alignX={direction === 'row' ? 'right' : undefined}
72
+ alignY={direction === 'row' ? 'start' : undefined}
73
+ target={targetHandleRef as HTMLElement}
71
74
  mountTo={mountPoint}
72
75
  boundariesElement={boundariesElement}
73
76
  scrollableElement={scrollableElement}
@@ -89,6 +92,7 @@ const FloatingDragMenu = ({
89
92
  targetCellPosition={targetCellPosition}
90
93
  getEditorContainerWidth={getEditorContainerWidth}
91
94
  canDrag={canDrag}
95
+ editorAnalyticsAPI={editorAnalyticsAPI}
92
96
  />
93
97
  </Popup>
94
98
  );
@@ -217,13 +217,10 @@ export const ColumnControls = ({
217
217
  zIndex: 99,
218
218
  }}
219
219
  data-column-control-index={hoveredCell.colIndex}
220
- data-testid={
221
- isHover
222
- ? 'table-floating-column-control-hover'
223
- : 'table-floating-column-control'
224
- }
220
+ data-testid={'table-floating-column-control'}
225
221
  >
226
222
  <DragHandle
223
+ isDragMenuTarget={!isHover}
227
224
  direction="column"
228
225
  tableLocalId={localId || ''}
229
226
  indexes={indexes}
@@ -239,13 +239,10 @@ const DragControlsComponent = ({
239
239
  position: 'relative',
240
240
  right: '-0.5px',
241
241
  }}
242
- data-testid={
243
- isHover
244
- ? 'table-floating-row-drag-handle-hover'
245
- : 'table-floating-row-drag-handle'
246
- }
242
+ data-testid={'table-floating-row-drag-handle'}
247
243
  >
248
244
  <DragHandle
245
+ isDragMenuTarget={!isHover}
249
246
  direction="row"
250
247
  tableLocalId={currentNodeLocalId}
251
248
  indexes={indexes}
@@ -1,4 +1,6 @@
1
1
  import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
2
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
4
  import {
3
5
  addColumnAfter,
4
6
  addColumnBefore,
@@ -34,7 +36,7 @@ import {
34
36
  sortByColumn,
35
37
  } from '../commands';
36
38
  import { deleteColumnsCommand } from '../commands/delete';
37
- import { moveSource } from '../pm-plugins/drag-and-drop/commands';
39
+ import { moveSourceWithAnalytics } from '../pm-plugins/drag-and-drop/commands-with-analytics';
38
40
  import { distributeColumnsWidths } from '../pm-plugins/table-resizing/commands';
39
41
  import { getNewResizeStateFromSelectedColumns } from '../pm-plugins/table-resizing/utils/resize-state';
40
42
  import { getClosestSelectionRect } from '../toolbar';
@@ -79,6 +81,7 @@ export const getDragMenuConfig = (
79
81
  index?: number,
80
82
  targetCellPosition?: number,
81
83
  selectionRect?: Rect,
84
+ editorAnalyticsAPI?: EditorAnalyticsAPI,
82
85
  ): DragMenuConfig[] => {
83
86
  const addOptions =
84
87
  direction === 'row'
@@ -234,11 +237,12 @@ export const getDragMenuConfig = (
234
237
  onClick: (state: EditorState, dispatch?: CommandDispatch) => {
235
238
  if (canMove(index)) {
236
239
  requestAnimationFrame(() => {
237
- moveSource(
240
+ moveSourceWithAnalytics(editorAnalyticsAPI)(
241
+ INPUT_METHOD.TABLE_CONTEXT_MENU,
238
242
  `table-${direction}`,
239
243
  index!,
240
244
  index! + offset,
241
- )(state, dispatch);
245
+ )(editorView.state, editorView.dispatch);
242
246
  });
243
247
  return true;
244
248
  }