@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,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
  );
@@ -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
  }