@atlaskit/editor-plugin-table 5.5.13 → 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 (37) hide show
  1. package/CHANGELOG.md +10 -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/FloatingDragMenu/DragMenu.js +3 -2
  6. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  7. package/dist/cjs/plugins/table/utils/drag-menu.js +6 -5
  8. package/dist/es2019/plugins/table/index.js +5 -3
  9. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.js +66 -0
  10. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +15 -6
  11. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  12. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  13. package/dist/es2019/plugins/table/utils/drag-menu.js +4 -3
  14. package/dist/esm/plugins/table/index.js +5 -3
  15. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.js +66 -0
  16. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +15 -6
  17. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  18. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  19. package/dist/esm/plugins/table/utils/drag-menu.js +4 -3
  20. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +6 -0
  21. package/dist/types/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
  22. package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +3 -1
  23. package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  24. package/dist/types/plugins/table/utils/drag-menu.d.ts +2 -1
  25. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +6 -0
  26. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
  27. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +3 -1
  28. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  29. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +2 -1
  30. package/package.json +2 -2
  31. package/src/__tests__/unit/analytics.ts +107 -3
  32. package/src/plugins/table/index.tsx +7 -2
  33. package/src/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.ts +100 -0
  34. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +30 -9
  35. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +4 -0
  36. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +4 -0
  37. package/src/plugins/table/utils/drag-menu.ts +7 -3
@@ -68,7 +68,8 @@ export var DragMenu = function DragMenu(_ref) {
68
68
  scrollableElement = _ref.scrollableElement,
69
69
  targetCellPosition = _ref.targetCellPosition,
70
70
  getEditorContainerWidth = _ref.getEditorContainerWidth,
71
- canDrag = _ref.canDrag;
71
+ canDrag = _ref.canDrag,
72
+ editorAnalyticsAPI = _ref.editorAnalyticsAPI;
72
73
  var tableMap = tableNode ? TableMap.get(tableNode) : undefined;
73
74
  var state = editorView.state,
74
75
  dispatch = editorView.dispatch;
@@ -77,7 +78,7 @@ export var DragMenu = function DragMenu(_ref) {
77
78
  var hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
78
79
  var shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
79
80
  var hasMergedCellsInTable = getMergedCellsPositions(state.tr).length > 0;
80
- var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect);
81
+ var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI);
81
82
  var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
82
83
  menuItems = _convertToDropdownIte.menuItems,
83
84
  menuCallback = _convertToDropdownIte.menuCallback;
@@ -15,7 +15,8 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
15
15
  index = _ref.index,
16
16
  targetCellPosition = _ref.targetCellPosition,
17
17
  getEditorContainerWidth = _ref.getEditorContainerWidth,
18
- canDrag = _ref.canDrag;
18
+ canDrag = _ref.canDrag,
19
+ editorAnalyticsAPI = _ref.editorAnalyticsAPI;
19
20
  if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
20
21
  return null;
21
22
  }
@@ -50,7 +51,8 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
50
51
  index: index,
51
52
  targetCellPosition: targetCellPosition,
52
53
  getEditorContainerWidth: getEditorContainerWidth,
53
- canDrag: canDrag
54
+ canDrag: canDrag,
55
+ editorAnalyticsAPI: editorAnalyticsAPI
54
56
  }));
55
57
  };
56
58
  FloatingDragMenu.displayName = 'FloatingDragMenu';
@@ -1,5 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
4
  import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
4
5
  import ArrowDownIcon from '@atlaskit/icon/glyph/arrow-down';
5
6
  import ArrowLeftIcon from '@atlaskit/icon/glyph/arrow-left';
@@ -12,7 +13,7 @@ import HipchatChevronDoubleDownIcon from '@atlaskit/icon/glyph/hipchat/chevron-d
12
13
  import HipchatChevronDoubleUpIcon from '@atlaskit/icon/glyph/hipchat/chevron-double-up';
13
14
  import { clearMultipleCells, insertColumn, insertRow, sortByColumn } from '../commands';
14
15
  import { deleteColumnsCommand } from '../commands/delete';
15
- import { moveSource } from '../pm-plugins/drag-and-drop/commands';
16
+ import { moveSourceWithAnalytics } from '../pm-plugins/drag-and-drop/commands-with-analytics';
16
17
  import { distributeColumnsWidths } from '../pm-plugins/table-resizing/commands';
17
18
  import { getNewResizeStateFromSelectedColumns } from '../pm-plugins/table-resizing/utils/resize-state';
18
19
  import { getClosestSelectionRect } from '../toolbar';
@@ -35,7 +36,7 @@ var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
35
36
  }
36
37
  return false;
37
38
  };
38
- export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect) {
39
+ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI) {
39
40
  var addOptions = direction === 'row' ? [{
40
41
  label: 'above',
41
42
  offset: 0,
@@ -169,7 +170,7 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
169
170
  onClick: function onClick(state, dispatch) {
170
171
  if (canMove(index)) {
171
172
  requestAnimationFrame(function () {
172
- moveSource("table-".concat(direction), index, index + offset)(state, dispatch);
173
+ moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, "table-".concat(direction), index, index + offset)(editorView.state, editorView.dispatch);
173
174
  });
174
175
  return true;
175
176
  }
@@ -0,0 +1,6 @@
1
+ import { TABLE_STATUS } from '@atlaskit/editor-common/analytics';
2
+ import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import type { DraggableType } from '../../types';
5
+ export declare const clearDropTargetWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
6
+ export declare const moveSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, sourceIndex: number, targetIndex: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
@@ -1,4 +1,5 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
1
2
  import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
4
  import type { DragAndDropPluginState } from './types';
4
- export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher) => SafePlugin<DragAndDropPluginState>;
5
+ export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher, editorAnalyticsAPI?: EditorAnalyticsAPI) => SafePlugin<DragAndDropPluginState>;
@@ -1,5 +1,6 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
4
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
4
5
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
5
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -18,6 +19,7 @@ type DragMenuProps = {
18
19
  pluginConfig?: PluginConfig;
19
20
  getEditorContainerWidth: GetEditorContainerWidth;
20
21
  canDrag?: boolean;
22
+ editorAnalyticsAPI?: EditorAnalyticsAPI;
21
23
  };
22
- export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, canDrag, }: DragMenuProps) => jsx.JSX.Element | null;
24
+ export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, canDrag, editorAnalyticsAPI, }: DragMenuProps) => jsx.JSX.Element | null;
23
25
  export {};
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
3
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
3
4
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
4
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -16,9 +17,10 @@ export interface Props {
16
17
  targetCellPosition?: number;
17
18
  getEditorContainerWidth: GetEditorContainerWidth;
18
19
  canDrag?: boolean;
20
+ editorAnalyticsAPI?: EditorAnalyticsAPI;
19
21
  }
20
22
  declare const FloatingDragMenu: {
21
- ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, canDrag, }: Props): JSX.Element | null;
23
+ ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, canDrag, editorAnalyticsAPI, }: Props): JSX.Element | null;
22
24
  displayName: string;
23
25
  };
24
26
  export default FloatingDragMenu;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
3
  import type { Command, DropdownOptionT, GetEditorContainerWidth, IconProps } from '@atlaskit/editor-common/types';
3
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
5
  import type { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
@@ -8,4 +9,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
8
9
  icon?: React.ComponentType<IconProps>;
9
10
  keymap?: string;
10
11
  }
11
- export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, hasMergedCellsInTable: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
12
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, hasMergedCellsInTable: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect, editorAnalyticsAPI?: EditorAnalyticsAPI) => DragMenuConfig[];
@@ -0,0 +1,6 @@
1
+ import { TABLE_STATUS } from '@atlaskit/editor-common/analytics';
2
+ import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import type { DraggableType } from '../../types';
5
+ export declare const clearDropTargetWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
6
+ export declare const moveSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, sourceIndex: number, targetIndex: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
@@ -1,4 +1,5 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
1
2
  import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
4
  import type { DragAndDropPluginState } from './types';
4
- export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher) => SafePlugin<DragAndDropPluginState>;
5
+ export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher, editorAnalyticsAPI?: EditorAnalyticsAPI) => SafePlugin<DragAndDropPluginState>;
@@ -1,5 +1,6 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
4
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
4
5
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
5
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -18,6 +19,7 @@ type DragMenuProps = {
18
19
  pluginConfig?: PluginConfig;
19
20
  getEditorContainerWidth: GetEditorContainerWidth;
20
21
  canDrag?: boolean;
22
+ editorAnalyticsAPI?: EditorAnalyticsAPI;
21
23
  };
22
- export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, canDrag, }: DragMenuProps) => jsx.JSX.Element | null;
24
+ export declare const DragMenu: ({ direction, index, isOpen, editorView, tableNode, mountPoint, boundariesElement, scrollableElement, targetCellPosition, getEditorContainerWidth, canDrag, editorAnalyticsAPI, }: DragMenuProps) => jsx.JSX.Element | null;
23
25
  export {};
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
3
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
3
4
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
4
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -16,9 +17,10 @@ export interface Props {
16
17
  targetCellPosition?: number;
17
18
  getEditorContainerWidth: GetEditorContainerWidth;
18
19
  canDrag?: boolean;
20
+ editorAnalyticsAPI?: EditorAnalyticsAPI;
19
21
  }
20
22
  declare const FloatingDragMenu: {
21
- ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, canDrag, }: Props): JSX.Element | null;
23
+ ({ mountPoint, boundariesElement, scrollableElement, editorView, isOpen, tableNode, direction, index, targetCellPosition, getEditorContainerWidth, canDrag, editorAnalyticsAPI, }: Props): JSX.Element | null;
22
24
  displayName: string;
23
25
  };
24
26
  export default FloatingDragMenu;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
3
  import type { Command, DropdownOptionT, GetEditorContainerWidth, IconProps } from '@atlaskit/editor-common/types';
3
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
5
  import type { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
@@ -8,4 +9,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
8
9
  icon?: React.ComponentType<IconProps>;
9
10
  keymap?: string;
10
11
  }
11
- export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, hasMergedCellsInTable: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
12
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, hasMergedCellsInTable: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect, editorAnalyticsAPI?: EditorAnalyticsAPI) => DragMenuConfig[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.5.13",
3
+ "version": "5.6.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^35.1.1",
31
31
  "@atlaskit/custom-steps": "^0.0.9",
32
- "@atlaskit/editor-common": "^76.26.0",
32
+ "@atlaskit/editor-common": "^76.27.0",
33
33
  "@atlaskit/editor-palette": "1.5.2",
34
34
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
35
35
  "@atlaskit/editor-plugin-content-insertion": "^0.1.0",
@@ -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
  });
@@ -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),
@@ -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,5 +1,6 @@
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';
@@ -25,6 +26,7 @@ export interface Props {
25
26
  targetCellPosition?: number;
26
27
  getEditorContainerWidth: GetEditorContainerWidth;
27
28
  canDrag?: boolean;
29
+ editorAnalyticsAPI?: EditorAnalyticsAPI;
28
30
  }
29
31
 
30
32
  const FloatingDragMenu = ({
@@ -39,6 +41,7 @@ const FloatingDragMenu = ({
39
41
  targetCellPosition,
40
42
  getEditorContainerWidth,
41
43
  canDrag,
44
+ editorAnalyticsAPI,
42
45
  }: Props) => {
43
46
  if (
44
47
  !isOpen ||
@@ -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
  );