@atlaskit/editor-plugin-table 5.4.5 → 5.4.7

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 (115) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/commands/insert.js +12 -2
  3. package/dist/cjs/plugins/table/commands/misc.js +49 -1
  4. package/dist/cjs/plugins/table/index.js +46 -35
  5. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +12 -16
  6. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +1 -1
  7. package/dist/cjs/plugins/table/nodeviews/table.js +3 -1
  8. package/dist/cjs/plugins/table/pm-plugins/analytics/actions.js +14 -0
  9. package/dist/cjs/plugins/table/pm-plugins/analytics/commands.js +45 -0
  10. package/dist/cjs/plugins/table/pm-plugins/analytics/plugin-factory.js +13 -0
  11. package/dist/cjs/plugins/table/pm-plugins/analytics/plugin-key.js +8 -0
  12. package/dist/cjs/plugins/table/pm-plugins/analytics/plugin.js +74 -0
  13. package/dist/cjs/plugins/table/pm-plugins/analytics/reducer.js +26 -0
  14. package/dist/cjs/plugins/table/pm-plugins/analytics/types.js +13 -0
  15. package/dist/cjs/plugins/table/pm-plugins/analytics/utils/moved-event.js +38 -0
  16. package/dist/cjs/plugins/table/pm-plugins/main.js +1 -1
  17. package/dist/cjs/plugins/table/pm-plugins/table-analytics.js +1 -1
  18. package/dist/es2019/plugins/table/commands/insert.js +12 -3
  19. package/dist/es2019/plugins/table/commands/misc.js +49 -0
  20. package/dist/es2019/plugins/table/index.js +14 -4
  21. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +13 -17
  22. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +1 -1
  23. package/dist/es2019/plugins/table/nodeviews/table.js +3 -1
  24. package/dist/es2019/plugins/table/pm-plugins/analytics/actions.js +8 -0
  25. package/dist/es2019/plugins/table/pm-plugins/analytics/commands.js +33 -0
  26. package/dist/es2019/plugins/table/pm-plugins/analytics/plugin-factory.js +8 -0
  27. package/dist/es2019/plugins/table/pm-plugins/analytics/plugin-key.js +2 -0
  28. package/dist/es2019/plugins/table/pm-plugins/analytics/plugin.js +72 -0
  29. package/dist/es2019/plugins/table/pm-plugins/analytics/reducer.js +21 -0
  30. package/dist/es2019/plugins/table/pm-plugins/analytics/types.js +7 -0
  31. package/dist/es2019/plugins/table/pm-plugins/analytics/utils/moved-event.js +30 -0
  32. package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
  33. package/dist/es2019/plugins/table/pm-plugins/table-analytics.js +1 -1
  34. package/dist/esm/plugins/table/commands/insert.js +12 -3
  35. package/dist/esm/plugins/table/commands/misc.js +48 -0
  36. package/dist/esm/plugins/table/index.js +43 -32
  37. package/dist/esm/plugins/table/nodeviews/TableComponent.js +13 -17
  38. package/dist/esm/plugins/table/nodeviews/TableResizer.js +1 -1
  39. package/dist/esm/plugins/table/nodeviews/table.js +3 -1
  40. package/dist/esm/plugins/table/pm-plugins/analytics/actions.js +8 -0
  41. package/dist/esm/plugins/table/pm-plugins/analytics/commands.js +39 -0
  42. package/dist/esm/plugins/table/pm-plugins/analytics/plugin-factory.js +8 -0
  43. package/dist/esm/plugins/table/pm-plugins/analytics/plugin-key.js +2 -0
  44. package/dist/esm/plugins/table/pm-plugins/analytics/plugin.js +68 -0
  45. package/dist/esm/plugins/table/pm-plugins/analytics/reducer.js +19 -0
  46. package/dist/esm/plugins/table/pm-plugins/analytics/types.js +7 -0
  47. package/dist/esm/plugins/table/pm-plugins/analytics/utils/moved-event.js +31 -0
  48. package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
  49. package/dist/esm/plugins/table/pm-plugins/table-analytics.js +1 -1
  50. package/dist/types/plugins/table/commands/misc.d.ts +5 -1
  51. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +2 -0
  52. package/dist/types/plugins/table/nodeviews/table.d.ts +2 -1
  53. package/dist/types/plugins/table/nodeviews/types.d.ts +2 -0
  54. package/dist/types/plugins/table/pm-plugins/analytics/actions.d.ts +17 -0
  55. package/dist/types/plugins/table/pm-plugins/analytics/commands.d.ts +5 -0
  56. package/dist/types/plugins/table/pm-plugins/analytics/plugin-factory.d.ts +1 -0
  57. package/dist/types/plugins/table/pm-plugins/analytics/plugin-key.d.ts +3 -0
  58. package/dist/types/plugins/table/pm-plugins/analytics/plugin.d.ts +4 -0
  59. package/dist/types/plugins/table/pm-plugins/analytics/reducer.d.ts +3 -0
  60. package/dist/types/plugins/table/pm-plugins/analytics/types.d.ts +11 -0
  61. package/dist/types/plugins/table/pm-plugins/analytics/utils/moved-event.d.ts +6 -0
  62. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +5 -1
  63. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +2 -0
  64. package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +2 -1
  65. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +2 -0
  66. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/actions.d.ts +17 -0
  67. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/commands.d.ts +5 -0
  68. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin-factory.d.ts +1 -0
  69. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin-key.d.ts +3 -0
  70. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin.d.ts +4 -0
  71. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/reducer.d.ts +3 -0
  72. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/types.d.ts +11 -0
  73. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/utils/moved-event.d.ts +6 -0
  74. package/package.json +7 -4
  75. package/src/__tests__/unit/index-with-fake-timers.ts +1 -0
  76. package/src/__tests__/unit/nodeviews/table.ts +1 -0
  77. package/src/__tests__/unit/pm-plugins/analytics.ts +327 -0
  78. package/src/plugins/table/commands/insert.ts +23 -2
  79. package/src/plugins/table/commands/misc.ts +84 -1
  80. package/src/plugins/table/index.tsx +13 -6
  81. package/src/plugins/table/nodeviews/TableComponent.tsx +15 -22
  82. package/src/plugins/table/nodeviews/TableResizer.tsx +1 -2
  83. package/src/plugins/table/nodeviews/table.tsx +4 -0
  84. package/src/plugins/table/nodeviews/types.ts +2 -0
  85. package/src/plugins/table/pm-plugins/analytics/actions.ts +23 -0
  86. package/src/plugins/table/pm-plugins/analytics/commands.ts +53 -0
  87. package/src/plugins/table/pm-plugins/analytics/plugin-factory.ts +7 -0
  88. package/src/plugins/table/pm-plugins/analytics/plugin-key.ts +7 -0
  89. package/src/plugins/table/pm-plugins/analytics/plugin.ts +98 -0
  90. package/src/plugins/table/pm-plugins/analytics/reducer.ts +27 -0
  91. package/src/plugins/table/pm-plugins/analytics/types.ts +20 -0
  92. package/src/plugins/table/pm-plugins/analytics/utils/moved-event.ts +51 -0
  93. package/src/plugins/table/pm-plugins/main.ts +1 -0
  94. package/src/plugins/table/pm-plugins/table-analytics.ts +1 -1
  95. package/tsconfig.dev.json +3 -3
  96. package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +0 -434
  97. package/src/__tests__/integration/__fixtures__/basic-table-with-merged-cell.ts +0 -112
  98. package/src/__tests__/integration/__fixtures__/basic-table.ts +0 -120
  99. package/src/__tests__/integration/__fixtures__/empty-layout.ts +0 -35
  100. package/src/__tests__/integration/__fixtures__/empty-paragraph-underneath-table.ts +0 -396
  101. package/src/__tests__/integration/__fixtures__/even-columns.ts +0 -493
  102. package/src/__tests__/integration/__fixtures__/layout-documents.ts +0 -606
  103. package/src/__tests__/integration/__fixtures__/merged-rows-and-cols-document.ts +0 -343
  104. package/src/__tests__/integration/__fixtures__/nested-in-expand.ts +0 -129
  105. package/src/__tests__/integration/__fixtures__/nested-in-extension.ts +0 -163
  106. package/src/__tests__/integration/__fixtures__/paragraph-and-table-adf.ts +0 -132
  107. package/src/__tests__/integration/__fixtures__/resize-documents.ts +0 -1605
  108. package/src/__tests__/integration/__fixtures__/scale.ts +0 -825
  109. package/src/__tests__/integration/__fixtures__/table-inside-layout.ts +0 -145
  110. package/src/__tests__/integration/__fixtures__/table-with-min-width-columns-document.ts +0 -175
  111. package/src/__tests__/integration/__fixtures__/table-with-multiline-date.adf.json +0 -168
  112. package/src/__tests__/integration/__fixtures__/table-with-text-and-empty-row.ts +0 -216
  113. package/src/__tests__/integration/__snapshots__/copy-button.ts.snap +0 -423
  114. package/src/__tests__/integration/copy-button.ts +0 -179
  115. package/src/__tests__/integration/table-controls-selection.ts +0 -71
@@ -11,20 +11,15 @@ import {
11
11
  EVENT_TYPE,
12
12
  TABLE_ACTION,
13
13
  } from '@atlaskit/editor-common/analytics';
14
- import type { AnalyticsDispatch } from '@atlaskit/editor-common/analytics';
14
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
15
15
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
16
- import { createDispatch } from '@atlaskit/editor-common/event-dispatcher';
17
16
  import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
18
17
  import { tableMarginSides } from '@atlaskit/editor-common/styles';
19
18
  import type {
20
19
  EditorContainerWidth,
21
20
  GetEditorFeatureFlags,
22
21
  } from '@atlaskit/editor-common/types';
23
- import {
24
- analyticsEventKey,
25
- browser,
26
- isValidPosition,
27
- } from '@atlaskit/editor-common/utils';
22
+ import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
28
23
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
29
24
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
30
25
  import {
@@ -106,6 +101,7 @@ export interface ComponentProps {
106
101
  ordering: TableColumnOrdering;
107
102
  isResizing?: boolean;
108
103
  getEditorFeatureFlags: GetEditorFeatureFlags;
104
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent;
109
105
  pluginInjectionApi?: PluginInjectionAPI;
110
106
  }
111
107
 
@@ -830,24 +826,21 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
830
826
  };
831
827
 
832
828
  private setTimerToSendInitialOverflowCaptured = (isOverflowing: boolean) => {
833
- const { eventDispatcher, containerWidth, options } = this.props;
834
- const dispatch: AnalyticsDispatch = createDispatch(eventDispatcher);
829
+ const { dispatchAnalyticsEvent, containerWidth, options } = this.props;
835
830
  const parentWidth = this.state?.parentWidth || 0;
836
831
 
837
832
  this.initialOverflowCaptureTimerId = setTimeout(() => {
838
- dispatch(analyticsEventKey, {
839
- payload: {
840
- action: TABLE_ACTION.INITIAL_OVERFLOW_CAPTURED,
841
- actionSubject: ACTION_SUBJECT.TABLE,
842
- actionSubjectId: null,
843
- eventType: EVENT_TYPE.TRACK,
844
- attributes: {
845
- editorWidth: containerWidth.width || 0,
846
- isOverflowing,
847
- tableResizingEnabled: options?.isTableResizingEnabled || false,
848
- width: this.node.attrs.width || 0,
849
- parentWidth,
850
- },
833
+ dispatchAnalyticsEvent({
834
+ action: TABLE_ACTION.INITIAL_OVERFLOW_CAPTURED,
835
+ actionSubject: ACTION_SUBJECT.TABLE,
836
+ actionSubjectId: null,
837
+ eventType: EVENT_TYPE.TRACK,
838
+ attributes: {
839
+ editorWidth: containerWidth.width || 0,
840
+ isOverflowing,
841
+ tableResizingEnabled: options?.isTableResizingEnabled || false,
842
+ width: this.node.attrs.width || 0,
843
+ parentWidth,
851
844
  },
852
845
  });
853
846
 
@@ -214,9 +214,8 @@ export const TableResizer = ({
214
214
  dispatch,
215
215
  state: { tr },
216
216
  } = editorView;
217
- tr.setMeta(tableWidthPluginKey, { resizing: true });
218
217
  displayGapCursor(false);
219
-
218
+ tr.setMeta(tableWidthPluginKey, { resizing: true });
220
219
  tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
221
220
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED,
222
221
  });
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import type { TableColumnOrdering } from '@atlaskit/custom-steps';
4
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
4
5
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
5
6
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
6
7
  import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
@@ -256,6 +257,7 @@ export default class TableView extends ReactNodeView<Props> {
256
257
  containerWidth={containerWidth!}
257
258
  contentDOM={forwardRef}
258
259
  getEditorFeatureFlags={props.getEditorFeatureFlags}
260
+ dispatchAnalyticsEvent={props.dispatchAnalyticsEvent}
259
261
  pluginInjectionApi={props.pluginInjectionApi}
260
262
  />
261
263
  );
@@ -344,6 +346,7 @@ export const createTableView = (
344
346
  eventDispatcher: EventDispatcher,
345
347
  getEditorContainerWidth: GetEditorContainerWidth,
346
348
  getEditorFeatureFlags: GetEditorFeatureFlags,
349
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent,
347
350
  pluginInjectionApi?: PluginInjectionAPI,
348
351
  ): NodeView => {
349
352
  const {
@@ -373,6 +376,7 @@ export const createTableView = (
373
376
  },
374
377
  getEditorContainerWidth,
375
378
  getEditorFeatureFlags,
379
+ dispatchAnalyticsEvent,
376
380
  hasIntlContext,
377
381
  pluginInjectionApi,
378
382
  }).init();
@@ -1,3 +1,4 @@
1
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
1
2
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
3
  import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
3
4
  import type {
@@ -28,6 +29,7 @@ export interface Props {
28
29
  options?: TableOptions;
29
30
  getEditorContainerWidth: GetEditorContainerWidth;
30
31
  getEditorFeatureFlags: GetEditorFeatureFlags;
32
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent;
31
33
  hasIntlContext: boolean;
32
34
  pluginInjectionApi?: PluginInjectionAPI;
33
35
  }
@@ -0,0 +1,23 @@
1
+ import type { RowOrColumnMovedState } from './types';
2
+
3
+ export enum AnalyticPluginTypes {
4
+ UpdateOverflowTriggerNameAction,
5
+ UpdateRowOrColumnMovedAction,
6
+ RemoveRowOrColumnMovedAction,
7
+ RemoveOverFlowTriggerNameAction,
8
+ UpdateRowOrColumnMovedAndOverflowTrigger,
9
+ }
10
+
11
+ export type UpdateRowOrColumnMovedAction = {
12
+ type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction;
13
+ data: RowOrColumnMovedState;
14
+ };
15
+
16
+ export type RemoveRowOrColumnMovedAction = {
17
+ type: AnalyticPluginTypes.RemoveRowOrColumnMovedAction;
18
+ data: undefined;
19
+ };
20
+
21
+ export type AnalyticPluginAction =
22
+ | UpdateRowOrColumnMovedAction
23
+ | RemoveRowOrColumnMovedAction;
@@ -0,0 +1,53 @@
1
+ import type {
2
+ EditorState,
3
+ Transaction,
4
+ } from '@atlaskit/editor-prosemirror/state';
5
+
6
+ import { AnalyticPluginTypes } from './actions';
7
+ import { createCommand, getPluginState } from './plugin-factory';
8
+ import { pluginKey } from './plugin-key';
9
+ import type { ActionType, RowOrColumnMovedState } from './types';
10
+ import { getMovedPayload } from './utils/moved-event';
11
+
12
+ export const updateRowOrColumnMoved = (
13
+ nextState: Omit<RowOrColumnMovedState, 'currentActions'>,
14
+ nextAction: ActionType,
15
+ ) =>
16
+ createCommand(
17
+ (state) => {
18
+ const { rowOrColumnMoved } = getPluginState(state);
19
+ const data = getMovedPayload(nextState, nextAction, rowOrColumnMoved);
20
+
21
+ return {
22
+ type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction,
23
+ data,
24
+ };
25
+ },
26
+ (tr) => tr.setMeta('addToHistory', false),
27
+ );
28
+
29
+ // --- transforms, prefer these over commands to avoid an extra 'dispatch'
30
+ export const resetRowOrColumnMovedTransform = () => (tr: Transaction) => {
31
+ const payload = {
32
+ type: AnalyticPluginTypes.RemoveRowOrColumnMovedAction,
33
+ };
34
+
35
+ return tr.setMeta(pluginKey, payload);
36
+ };
37
+
38
+ export const updateRowOrColumnMovedTransform =
39
+ (
40
+ nextState: Omit<RowOrColumnMovedState, 'currentActions'>,
41
+ nextAction: ActionType,
42
+ ) =>
43
+ (state: EditorState, tr: Transaction) => {
44
+ const { rowOrColumnMoved } = getPluginState(state);
45
+ const data = getMovedPayload(nextState, nextAction, rowOrColumnMoved);
46
+
47
+ const payload = {
48
+ type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction,
49
+ data,
50
+ };
51
+
52
+ return tr.setMeta(pluginKey, payload);
53
+ };
@@ -0,0 +1,7 @@
1
+ import { pluginFactory } from '@atlaskit/editor-common/utils';
2
+
3
+ import { pluginKey } from './plugin-key';
4
+ import { reducer } from './reducer';
5
+
6
+ export const { createPluginState, createCommand, getPluginState } =
7
+ pluginFactory(pluginKey, reducer);
@@ -0,0 +1,7 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+
3
+ import type { AnalyticPluginState } from './types';
4
+
5
+ export const pluginKey = new PluginKey<AnalyticPluginState>(
6
+ 'tableAnalyticPlugin',
7
+ );
@@ -0,0 +1,98 @@
1
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
+ import {
3
+ ACTION_SUBJECT,
4
+ EVENT_TYPE,
5
+ TABLE_ACTION,
6
+ } from '@atlaskit/editor-common/analytics';
7
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
8
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
10
+
11
+ import {
12
+ countCellsInSlice,
13
+ getTableElementMoveTypeBySlice,
14
+ getTableSelectionType,
15
+ isInsideFirstCellOfRowOrColumn,
16
+ } from '../../commands/misc';
17
+
18
+ import {
19
+ resetRowOrColumnMovedTransform,
20
+ updateRowOrColumnMoved,
21
+ } from './commands';
22
+ import { createPluginState } from './plugin-factory';
23
+ import { pluginKey } from './plugin-key';
24
+ import { defaultState } from './types';
25
+
26
+ export const createPlugin = (
27
+ dispatch: Dispatch,
28
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent,
29
+ ) =>
30
+ new SafePlugin({
31
+ key: pluginKey,
32
+ state: createPluginState(dispatch, defaultState),
33
+ appendTransaction: (transactions, oldState, newState) => {
34
+ const tr = transactions.find((tr) =>
35
+ tr.getMeta(pluginKey)?.data?.currentActions?.includes('pasted'),
36
+ );
37
+
38
+ if (tr) {
39
+ dispatchAnalyticsEvent({
40
+ action: TABLE_ACTION.ROW_OR_COLUMN_MOVED,
41
+ actionSubject: ACTION_SUBJECT.TABLE,
42
+ actionSubjectId: null,
43
+ eventType: EVENT_TYPE.TRACK,
44
+ attributes: {
45
+ type: tr.getMeta(pluginKey)?.data?.type,
46
+ },
47
+ });
48
+ return resetRowOrColumnMovedTransform()(tr);
49
+ }
50
+
51
+ return undefined;
52
+ },
53
+ props: {
54
+ handlePaste: ({ state, dispatch }, event, slice) => {
55
+ if (
56
+ getBooleanFF('platform.editor.table.analytics-plugin-moved-event')
57
+ ) {
58
+ const { schema } = state;
59
+ const type = getTableElementMoveTypeBySlice(slice, state);
60
+
61
+ // if the selection wasn't in the first cell of a row or column, don't count it
62
+ if (!isInsideFirstCellOfRowOrColumn(state.selection, type)) {
63
+ return;
64
+ }
65
+
66
+ const count = countCellsInSlice(slice, schema, type);
67
+
68
+ updateRowOrColumnMoved(
69
+ {
70
+ numberOfCells: count,
71
+ type,
72
+ },
73
+ 'pasted',
74
+ )(state, dispatch);
75
+ }
76
+ },
77
+ transformCopied: (slice, { state, dispatch }) => {
78
+ if (
79
+ getBooleanFF('platform.editor.table.analytics-plugin-moved-event')
80
+ ) {
81
+ const { schema } = state;
82
+
83
+ const type = getTableSelectionType(state.selection);
84
+ const count = countCellsInSlice(slice, schema, type);
85
+
86
+ updateRowOrColumnMoved(
87
+ {
88
+ numberOfCells: count,
89
+ type,
90
+ },
91
+ 'copyOrCut',
92
+ )(state, dispatch);
93
+ }
94
+
95
+ return slice;
96
+ },
97
+ },
98
+ });
@@ -0,0 +1,27 @@
1
+ import { AnalyticPluginTypes } from './actions';
2
+ import type { AnalyticPluginAction } from './actions';
3
+ import type { AnalyticPluginState } from './types';
4
+ import { defaultState } from './types';
5
+
6
+ export const reducer = (
7
+ state: AnalyticPluginState,
8
+ action: AnalyticPluginAction,
9
+ ): AnalyticPluginState => {
10
+ switch (action.type) {
11
+ case AnalyticPluginTypes.UpdateRowOrColumnMovedAction:
12
+ return {
13
+ ...state,
14
+ rowOrColumnMoved: {
15
+ ...state.rowOrColumnMoved,
16
+ ...action.data,
17
+ },
18
+ };
19
+ case AnalyticPluginTypes.RemoveRowOrColumnMovedAction:
20
+ return {
21
+ ...state,
22
+ rowOrColumnMoved: defaultState.rowOrColumnMoved,
23
+ };
24
+ default:
25
+ return state;
26
+ }
27
+ };
@@ -0,0 +1,20 @@
1
+ export type ActionType = 'none' | 'addRowOrColumn' | 'copyOrCut' | 'pasted';
2
+
3
+ export type RowOrColumnMovedState = {
4
+ type?: 'row' | 'column';
5
+ /** used to confirm if same number of cells was copied and pasted */
6
+ numberOfCells?: number;
7
+ currentActions: Array<ActionType>;
8
+ };
9
+
10
+ export type AnalyticPluginState = {
11
+ rowOrColumnMoved: RowOrColumnMovedState;
12
+ };
13
+
14
+ export const defaultState = {
15
+ rowOrColumnMoved: {
16
+ type: undefined,
17
+ numberOfCells: undefined,
18
+ currentActions: [],
19
+ },
20
+ } as AnalyticPluginState;
@@ -0,0 +1,51 @@
1
+ import type { ActionType, RowOrColumnMovedState } from '../types';
2
+ import { defaultState } from '../types';
3
+
4
+ const getNextActionType = (
5
+ nextState: Omit<RowOrColumnMovedState, 'currentActions'>,
6
+ nextAction: ActionType,
7
+ prevState?: RowOrColumnMovedState,
8
+ ) => {
9
+ if (nextAction === 'pasted') {
10
+ if (
11
+ prevState &&
12
+ prevState.currentActions.includes('copyOrCut') &&
13
+ prevState.currentActions.includes('addRowOrColumn') &&
14
+ prevState.numberOfCells === nextState.numberOfCells &&
15
+ prevState.type === nextState.type
16
+ ) {
17
+ return 'pasted';
18
+ }
19
+ return 'none';
20
+ }
21
+ return nextAction;
22
+ };
23
+
24
+ export const getMovedPayload = (
25
+ nextState: Omit<RowOrColumnMovedState, 'currentActions'>,
26
+ nextAction: ActionType,
27
+ prevState: RowOrColumnMovedState,
28
+ ) => {
29
+ const nextActionType = getNextActionType(nextState, nextAction, prevState);
30
+
31
+ if (nextActionType === 'none') {
32
+ return defaultState.rowOrColumnMoved;
33
+ }
34
+
35
+ // a new workflow has started in the opposite axis (e.g. inserted a row, but copied a column) remove old state
36
+ if (prevState.type !== nextState.type) {
37
+ return {
38
+ currentActions: [nextActionType],
39
+ numberOfCells: nextState?.numberOfCells,
40
+ type: nextState.type,
41
+ };
42
+ }
43
+
44
+ return {
45
+ currentActions: prevState.currentActions.includes(nextActionType)
46
+ ? prevState.currentActions
47
+ : [...prevState.currentActions, nextActionType],
48
+ numberOfCells: nextState?.numberOfCells || prevState.numberOfCells,
49
+ type: nextState?.type,
50
+ };
51
+ };
@@ -368,6 +368,7 @@ export const createPlugin = (
368
368
  eventDispatcher,
369
369
  getEditorContainerWidth,
370
370
  getEditorFeatureFlags,
371
+ dispatchAnalyticsEvent,
371
372
  pluginInjectionApi,
372
373
  ),
373
374
  tableRow: (node, view, getPos) =>
@@ -21,7 +21,7 @@ type TableAnalyticsPluginState = {
21
21
  };
22
22
 
23
23
  export const pluginKey = new PluginKey<TableAnalyticsPluginState>(
24
- 'tableAnalyticsPlugin',
24
+ 'tableOverflowAnalyticsPlugin',
25
25
  );
26
26
 
27
27
  export const META_KEYS = {
package/tsconfig.dev.json CHANGED
@@ -96,6 +96,9 @@
96
96
  {
97
97
  "path": "../../media/media-integration-test-helpers/tsconfig.app.json"
98
98
  },
99
+ {
100
+ "path": "../../platform/feature-flags/tsconfig.app.json"
101
+ },
99
102
  {
100
103
  "path": "../synchrony-test-helpers/tsconfig.app.json"
101
104
  },
@@ -108,9 +111,6 @@
108
111
  {
109
112
  "path": "../../../build/test-tooling/visual-regression/tsconfig.app.json"
110
113
  },
111
- {
112
- "path": "../../../build/test-tooling/webdriver-runner/tsconfig.app.json"
113
- },
114
114
  {
115
115
  "path": "../../platform/feature-flags-test-utils/tsconfig.app.json"
116
116
  }