@atlaskit/editor-plugin-table 5.5.13 → 5.6.1

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 (43) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/plugins/table/index.js +5 -3
  3. package/dist/cjs/plugins/table/nodeviews/TableStickyScrollbar.js +2 -5
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.js +72 -0
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +14 -5
  6. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  7. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  8. package/dist/cjs/plugins/table/utils/drag-menu.js +6 -5
  9. package/dist/es2019/plugins/table/index.js +5 -3
  10. package/dist/es2019/plugins/table/nodeviews/TableStickyScrollbar.js +2 -5
  11. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.js +66 -0
  12. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +15 -6
  13. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  14. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  15. package/dist/es2019/plugins/table/utils/drag-menu.js +4 -3
  16. package/dist/esm/plugins/table/index.js +5 -3
  17. package/dist/esm/plugins/table/nodeviews/TableStickyScrollbar.js +2 -5
  18. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.js +66 -0
  19. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +15 -6
  20. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
  21. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +4 -2
  22. package/dist/esm/plugins/table/utils/drag-menu.js +4 -3
  23. package/dist/types/plugins/table/nodeviews/TableStickyScrollbar.d.ts +0 -1
  24. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +6 -0
  25. package/dist/types/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
  26. package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +3 -1
  27. package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  28. package/dist/types/plugins/table/utils/drag-menu.d.ts +2 -1
  29. package/dist/types-ts4.5/plugins/table/nodeviews/TableStickyScrollbar.d.ts +0 -1
  30. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +6 -0
  31. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
  32. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +3 -1
  33. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  34. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +2 -1
  35. package/package.json +2 -2
  36. package/src/__tests__/unit/analytics.ts +107 -3
  37. package/src/plugins/table/index.tsx +7 -2
  38. package/src/plugins/table/nodeviews/TableStickyScrollbar.ts +2 -7
  39. package/src/plugins/table/pm-plugins/drag-and-drop/commands-with-analytics.ts +100 -0
  40. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +30 -9
  41. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +4 -0
  42. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +4 -0
  43. package/src/plugins/table/utils/drag-menu.ts +7 -3
@@ -0,0 +1,66 @@
1
+ import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
2
+ import { getSelectedTableInfo } from '../../utils';
3
+ import { withEditorAnalyticsAPI } from '../../utils/analytics';
4
+ import { clearDropTarget, moveSource } from './commands';
5
+ export var clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(editorAnalyticsAPI) {
6
+ return function (inputMethod, sourceType, status, tr) {
7
+ return withEditorAnalyticsAPI(function (_ref) {
8
+ var selection = _ref.selection;
9
+ var _getSelectedTableInfo = getSelectedTableInfo(selection),
10
+ totalRowCount = _getSelectedTableInfo.totalRowCount,
11
+ totalColumnCount = _getSelectedTableInfo.totalColumnCount;
12
+ return {
13
+ action: sourceType === 'table-row' ? TABLE_ACTION.MOVED_ROW : TABLE_ACTION.MOVED_COLUMN,
14
+ actionSubject: ACTION_SUBJECT.TABLE,
15
+ actionSubjectId: null,
16
+ attributes: {
17
+ inputMethod: inputMethod,
18
+ // TODO: When multiple sources can be moved we need to update this count to be the amount of sources which are being moved.
19
+ count: 1,
20
+ distance: 0,
21
+ status: status,
22
+ totalRowCount: totalRowCount,
23
+ totalColumnCount: totalColumnCount
24
+ },
25
+ eventType: EVENT_TYPE.TRACK
26
+ };
27
+ })(editorAnalyticsAPI)(function (state, dispatch) {
28
+ if (dispatch) {
29
+ clearDropTarget(tr)(state, dispatch);
30
+ }
31
+ return true;
32
+ });
33
+ };
34
+ };
35
+ export var moveSourceWithAnalytics = function moveSourceWithAnalytics(editorAnalyticsAPI) {
36
+ return function (inputMethod, sourceType, sourceIndex, targetIndex, tr) {
37
+ return withEditorAnalyticsAPI(function (_ref2) {
38
+ var selection = _ref2.selection;
39
+ var _getSelectedTableInfo2 = getSelectedTableInfo(selection),
40
+ totalRowCount = _getSelectedTableInfo2.totalRowCount,
41
+ totalColumnCount = _getSelectedTableInfo2.totalColumnCount;
42
+ return {
43
+ action: sourceType === 'table-row' ? TABLE_ACTION.MOVED_ROW : TABLE_ACTION.MOVED_COLUMN,
44
+ actionSubject: ACTION_SUBJECT.TABLE,
45
+ actionSubjectId: null,
46
+ attributes: {
47
+ inputMethod: inputMethod,
48
+ // TODO: When multiple sources can be moved we need to update this count to be the amount of sources which are being moved.
49
+ count: 1,
50
+ // This identifies the total amount of row/cols the move operation covered
51
+ distance: targetIndex - sourceIndex,
52
+ // If a drop doesn't actually change anything then we're going to mark the event as cancelled.
53
+ status: sourceIndex === targetIndex ? TABLE_STATUS.CANCELLED : TABLE_STATUS.SUCCESS,
54
+ totalRowCount: totalRowCount,
55
+ totalColumnCount: totalColumnCount
56
+ },
57
+ eventType: EVENT_TYPE.TRACK
58
+ };
59
+ })(editorAnalyticsAPI)(function (state, dispatch) {
60
+ if (dispatch) {
61
+ moveSource(sourceType, sourceIndex, targetIndex, tr)(state, dispatch);
62
+ }
63
+ return true;
64
+ });
65
+ };
66
+ };
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
5
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
8
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
@@ -12,12 +13,13 @@ import { getPluginState as getTablePluginState } from '../plugin-factory';
12
13
  import { pluginKey as tablePluginKey } from '../plugin-key';
13
14
  import { insertColgroupFromNode } from '../table-resizing/utils';
14
15
  import { DragAndDropActionType } from './actions';
15
- import { clearDropTarget, moveSource, setDropTarget, toggleDragMenu } from './commands';
16
+ import { clearDropTarget, setDropTarget, toggleDragMenu } from './commands';
17
+ import { clearDropTargetWithAnalytics, moveSourceWithAnalytics } from './commands-with-analytics';
16
18
  import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
17
19
  import { createPluginState, getPluginState } from './plugin-factory';
18
20
  import { pluginKey } from './plugin-key';
19
21
  import { getDraggableDataFromEvent } from './utils/monitor';
20
- export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
22
+ export var createPlugin = function createPlugin(dispatch, eventDispatcher, editorAnalyticsAPI) {
21
23
  return new SafePlugin({
22
24
  state: createPluginState(dispatch, function (state) {
23
25
  return {
@@ -158,8 +160,13 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
158
160
 
159
161
  // If no data can be found then it's most like we do not want to perform any drop action
160
162
  if (!data) {
161
- clearDropTarget(tr)(editorView.state, editorView.dispatch);
162
- return;
163
+ var _event$source, _event$source2;
164
+ // If we're able to determine the source type of the dropped element then we should report to analytics that
165
+ // the drop event was cancelled. Otherwise we will cancel silently.
166
+ if ((event === null || event === void 0 || (_event$source = event.source) === null || _event$source === void 0 || (_event$source = _event$source.data) === null || _event$source === void 0 ? void 0 : _event$source.type) === 'table-row' || (event === null || event === void 0 || (_event$source2 = event.source) === null || _event$source2 === void 0 || (_event$source2 = _event$source2.data) === null || _event$source2 === void 0 ? void 0 : _event$source2.type) === 'table-column') {
167
+ return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
168
+ }
169
+ return clearDropTarget(tr)(editorView.state, editorView.dispatch);
163
170
  }
164
171
  var sourceType = data.sourceType,
165
172
  sourceIndexes = data.sourceIndexes,
@@ -176,13 +183,15 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
176
183
 
177
184
  // If the drop target index contains merged cells then we should not allow the drop to occur.
178
185
  if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
179
- clearDropTarget(tr)(editorView.state, editorView.dispatch);
186
+ clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
187
+ // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
188
+ TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
180
189
  return;
181
190
  }
182
191
  var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
183
192
  sourceIndex = _sourceIndexes[0];
184
193
  requestAnimationFrame(function () {
185
- moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
194
+ moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
186
195
 
187
196
  // force a colgroup update here, otherwise dropped columns don't have
188
197
  // the correct width immediately after the drop
@@ -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
  }
@@ -20,5 +20,4 @@ export declare class TableStickyScrollbar {
20
20
  private hide;
21
21
  private show;
22
22
  private handleScroll;
23
- private handleScrollDebounced;
24
23
  }
@@ -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[];
@@ -20,5 +20,4 @@ export declare class TableStickyScrollbar {
20
20
  private hide;
21
21
  private show;
22
22
  private handleScroll;
23
- private handleScrollDebounced;
24
23
  }
@@ -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.1",
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 && (
@@ -1,5 +1,3 @@
1
- import rafSchedule from 'raf-schd';
2
-
3
1
  import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
4
2
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
3
 
@@ -33,9 +31,8 @@ export class TableStickyScrollbar {
33
31
  if (this.stickyScrollbarContainerElement) {
34
32
  this.stickyScrollbarContainerElement.removeEventListener(
35
33
  'scroll',
36
- this.handleScrollDebounced,
34
+ this.handleScroll,
37
35
  );
38
- this.handleScrollDebounced.cancel();
39
36
  }
40
37
 
41
38
  this.deleteIntersectionObserver();
@@ -60,7 +57,7 @@ export class TableStickyScrollbar {
60
57
  if (this.stickyScrollbarContainerElement) {
61
58
  this.stickyScrollbarContainerElement.addEventListener(
62
59
  'scroll',
63
- this.handleScrollDebounced,
60
+ this.handleScroll,
64
61
  { passive: true },
65
62
  );
66
63
  }
@@ -199,6 +196,4 @@ export class TableStickyScrollbar {
199
196
 
200
197
  this.wrapper.scrollLeft = this.stickyScrollbarContainerElement.scrollLeft;
201
198
  };
202
-
203
- private handleScrollDebounced = rafSchedule(this.handleScroll);
204
199
  }