@atlaskit/editor-plugin-table 5.4.6 → 5.4.8

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 (135) 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 +63 -13
  4. package/dist/cjs/plugins/table/index.js +46 -35
  5. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +14 -20
  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/decorations/plugin.js +9 -3
  17. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  18. package/dist/cjs/plugins/table/pm-plugins/main.js +1 -1
  19. package/dist/cjs/plugins/table/pm-plugins/table-analytics.js +1 -1
  20. package/dist/cjs/plugins/table/types.js +2 -1
  21. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -1
  22. package/dist/cjs/plugins/table/ui/common-styles.js +6 -9
  23. package/dist/cjs/plugins/table/ui/ui-styles.js +12 -16
  24. package/dist/cjs/plugins/table/utils/decoration.js +20 -25
  25. package/dist/es2019/plugins/table/commands/insert.js +12 -3
  26. package/dist/es2019/plugins/table/commands/misc.js +54 -4
  27. package/dist/es2019/plugins/table/index.js +14 -4
  28. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +15 -21
  29. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +1 -1
  30. package/dist/es2019/plugins/table/nodeviews/table.js +3 -1
  31. package/dist/es2019/plugins/table/pm-plugins/analytics/actions.js +8 -0
  32. package/dist/es2019/plugins/table/pm-plugins/analytics/commands.js +33 -0
  33. package/dist/es2019/plugins/table/pm-plugins/analytics/plugin-factory.js +8 -0
  34. package/dist/es2019/plugins/table/pm-plugins/analytics/plugin-key.js +2 -0
  35. package/dist/es2019/plugins/table/pm-plugins/analytics/plugin.js +72 -0
  36. package/dist/es2019/plugins/table/pm-plugins/analytics/reducer.js +21 -0
  37. package/dist/es2019/plugins/table/pm-plugins/analytics/types.js +7 -0
  38. package/dist/es2019/plugins/table/pm-plugins/analytics/utils/moved-event.js +30 -0
  39. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +9 -3
  40. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  41. package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
  42. package/dist/es2019/plugins/table/pm-plugins/table-analytics.js +1 -1
  43. package/dist/es2019/plugins/table/types.js +2 -1
  44. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +4 -1
  45. package/dist/es2019/plugins/table/ui/common-styles.js +20 -20
  46. package/dist/es2019/plugins/table/ui/ui-styles.js +18 -21
  47. package/dist/es2019/plugins/table/utils/decoration.js +20 -25
  48. package/dist/esm/plugins/table/commands/insert.js +12 -3
  49. package/dist/esm/plugins/table/commands/misc.js +61 -13
  50. package/dist/esm/plugins/table/index.js +43 -32
  51. package/dist/esm/plugins/table/nodeviews/TableComponent.js +15 -21
  52. package/dist/esm/plugins/table/nodeviews/TableResizer.js +1 -1
  53. package/dist/esm/plugins/table/nodeviews/table.js +3 -1
  54. package/dist/esm/plugins/table/pm-plugins/analytics/actions.js +8 -0
  55. package/dist/esm/plugins/table/pm-plugins/analytics/commands.js +39 -0
  56. package/dist/esm/plugins/table/pm-plugins/analytics/plugin-factory.js +8 -0
  57. package/dist/esm/plugins/table/pm-plugins/analytics/plugin-key.js +2 -0
  58. package/dist/esm/plugins/table/pm-plugins/analytics/plugin.js +68 -0
  59. package/dist/esm/plugins/table/pm-plugins/analytics/reducer.js +19 -0
  60. package/dist/esm/plugins/table/pm-plugins/analytics/types.js +7 -0
  61. package/dist/esm/plugins/table/pm-plugins/analytics/utils/moved-event.js +31 -0
  62. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +9 -3
  63. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  64. package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
  65. package/dist/esm/plugins/table/pm-plugins/table-analytics.js +1 -1
  66. package/dist/esm/plugins/table/types.js +2 -1
  67. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +4 -1
  68. package/dist/esm/plugins/table/ui/common-styles.js +6 -9
  69. package/dist/esm/plugins/table/ui/ui-styles.js +12 -16
  70. package/dist/esm/plugins/table/utils/decoration.js +20 -25
  71. package/dist/types/plugins/table/commands/misc.d.ts +5 -1
  72. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +2 -0
  73. package/dist/types/plugins/table/nodeviews/table.d.ts +2 -1
  74. package/dist/types/plugins/table/nodeviews/types.d.ts +2 -0
  75. package/dist/types/plugins/table/pm-plugins/analytics/actions.d.ts +17 -0
  76. package/dist/types/plugins/table/pm-plugins/analytics/commands.d.ts +5 -0
  77. package/dist/types/plugins/table/pm-plugins/analytics/plugin-factory.d.ts +1 -0
  78. package/dist/types/plugins/table/pm-plugins/analytics/plugin-key.d.ts +3 -0
  79. package/dist/types/plugins/table/pm-plugins/analytics/plugin.d.ts +4 -0
  80. package/dist/types/plugins/table/pm-plugins/analytics/reducer.d.ts +3 -0
  81. package/dist/types/plugins/table/pm-plugins/analytics/types.d.ts +11 -0
  82. package/dist/types/plugins/table/pm-plugins/analytics/utils/moved-event.d.ts +6 -0
  83. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
  84. package/dist/types/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
  85. package/dist/types/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
  86. package/dist/types/plugins/table/types.d.ts +2 -1
  87. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +5 -1
  88. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +2 -0
  89. package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +2 -1
  90. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +2 -0
  91. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/actions.d.ts +17 -0
  92. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/commands.d.ts +5 -0
  93. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin-factory.d.ts +1 -0
  94. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin-key.d.ts +3 -0
  95. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin.d.ts +4 -0
  96. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/reducer.d.ts +3 -0
  97. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/types.d.ts +11 -0
  98. package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/utils/moved-event.d.ts +6 -0
  99. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
  100. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
  101. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
  102. package/dist/types-ts4.5/plugins/table/types.d.ts +2 -1
  103. package/package.json +4 -1
  104. package/src/__tests__/unit/event-handlers.ts +37 -38
  105. package/src/__tests__/unit/index-with-fake-timers.ts +1 -0
  106. package/src/__tests__/unit/nodeviews/table.ts +1 -0
  107. package/src/__tests__/unit/pm-plugins/analytics.ts +327 -0
  108. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +46 -36
  109. package/src/plugins/table/commands/insert.ts +23 -2
  110. package/src/plugins/table/commands/misc.ts +93 -8
  111. package/src/plugins/table/index.tsx +13 -6
  112. package/src/plugins/table/nodeviews/TableComponent.tsx +35 -44
  113. package/src/plugins/table/nodeviews/TableResizer.tsx +1 -2
  114. package/src/plugins/table/nodeviews/table.tsx +4 -0
  115. package/src/plugins/table/nodeviews/types.ts +2 -0
  116. package/src/plugins/table/pm-plugins/analytics/actions.ts +23 -0
  117. package/src/plugins/table/pm-plugins/analytics/commands.ts +53 -0
  118. package/src/plugins/table/pm-plugins/analytics/plugin-factory.ts +7 -0
  119. package/src/plugins/table/pm-plugins/analytics/plugin-key.ts +7 -0
  120. package/src/plugins/table/pm-plugins/analytics/plugin.ts +98 -0
  121. package/src/plugins/table/pm-plugins/analytics/reducer.ts +27 -0
  122. package/src/plugins/table/pm-plugins/analytics/types.ts +20 -0
  123. package/src/plugins/table/pm-plugins/analytics/utils/moved-event.ts +51 -0
  124. package/src/plugins/table/pm-plugins/decorations/plugin.ts +7 -2
  125. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +20 -11
  126. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +2 -4
  127. package/src/plugins/table/pm-plugins/decorations/utils/types.ts +14 -7
  128. package/src/plugins/table/pm-plugins/main.ts +1 -0
  129. package/src/plugins/table/pm-plugins/table-analytics.ts +1 -1
  130. package/src/plugins/table/types.ts +2 -1
  131. package/src/plugins/table/ui/TableFloatingControls/index.tsx +73 -67
  132. package/src/plugins/table/ui/common-styles.ts +20 -23
  133. package/src/plugins/table/ui/ui-styles.ts +18 -21
  134. package/src/plugins/table/utils/decoration.ts +27 -32
  135. package/tsconfig.dev.json +3 -0
@@ -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
 
@@ -487,28 +483,26 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
487
483
 
488
484
  const hasHeaderRow = containsHeaderRow(node);
489
485
  const rowControls = (
490
- <div className={ClassName.ROW_CONTROLS_WRAPPER}>
491
- <TableFloatingControls
492
- editorView={view}
493
- tableRef={tableRef}
494
- tableNode={node}
495
- tableActive={tableActive}
496
- hoveredRows={hoveredRows}
497
- hoveredCell={hoveredCell}
498
- isInDanger={isInDanger}
499
- isResizing={isResizing}
500
- isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
501
- isHeaderRowEnabled={isHeaderRowEnabled}
502
- isDragAndDropEnabled={isDragAndDropEnabled}
503
- ordering={ordering}
504
- isHeaderColumnEnabled={isHeaderColumnEnabled}
505
- hasHeaderRow={hasHeaderRow}
506
- // pass `selection` and `tableHeight` to control re-render
507
- selection={view.state.selection}
508
- headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
509
- stickyHeader={this.state.stickyHeader}
510
- />
511
- </div>
486
+ <TableFloatingControls
487
+ editorView={view}
488
+ tableRef={tableRef}
489
+ tableNode={node}
490
+ tableActive={tableActive}
491
+ hoveredRows={hoveredRows}
492
+ hoveredCell={hoveredCell}
493
+ isInDanger={isInDanger}
494
+ isResizing={isResizing}
495
+ isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
496
+ isHeaderRowEnabled={isHeaderRowEnabled}
497
+ isDragAndDropEnabled={isDragAndDropEnabled}
498
+ ordering={ordering}
499
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
500
+ hasHeaderRow={hasHeaderRow}
501
+ // pass `selection` and `tableHeight` to control re-render
502
+ selection={view.state.selection}
503
+ headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
504
+ stickyHeader={this.state.stickyHeader}
505
+ />
512
506
  );
513
507
 
514
508
  const colControls = isDragAndDropEnabled ? (
@@ -830,24 +824,21 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
830
824
  };
831
825
 
832
826
  private setTimerToSendInitialOverflowCaptured = (isOverflowing: boolean) => {
833
- const { eventDispatcher, containerWidth, options } = this.props;
834
- const dispatch: AnalyticsDispatch = createDispatch(eventDispatcher);
827
+ const { dispatchAnalyticsEvent, containerWidth, options } = this.props;
835
828
  const parentWidth = this.state?.parentWidth || 0;
836
829
 
837
830
  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
- },
831
+ dispatchAnalyticsEvent({
832
+ action: TABLE_ACTION.INITIAL_OVERFLOW_CAPTURED,
833
+ actionSubject: ACTION_SUBJECT.TABLE,
834
+ actionSubjectId: null,
835
+ eventType: EVENT_TYPE.TRACK,
836
+ attributes: {
837
+ editorWidth: containerWidth.width || 0,
838
+ isOverflowing,
839
+ tableResizingEnabled: options?.isTableResizingEnabled || false,
840
+ width: this.node.attrs.width || 0,
841
+ parentWidth,
851
842
  },
852
843
  });
853
844
 
@@ -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
+ };
@@ -8,7 +8,6 @@ import type {
8
8
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
9
9
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
10
10
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
11
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
11
 
13
12
  import { pluginKey as tablePluginKey } from '../plugin-key';
14
13
  import { pluginKey as tableWidthPluginKey } from '../table-width';
@@ -31,11 +30,13 @@ export const handleDocOrSelectionChanged = (
31
30
  ): DecorationSet => {
32
31
  const isResizing = tableWidthPluginKey.getState(newState)?.resizing;
33
32
  const wasResizing = tableWidthPluginKey.getState(oldState)?.resizing;
33
+ const { isDragAndDropEnabled = false } =
34
+ tablePluginKey.getState(newState) || {};
34
35
 
35
36
  const changedResizing = isResizing !== wasResizing;
36
37
 
37
38
  // Remove column controls when resizing and don't add column decoration controls when DnD enabled
38
- if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
39
+ if (isResizing) {
39
40
  return DecorationSet.empty;
40
41
  } else if (
41
42
  tr.docChanged ||
@@ -45,6 +46,9 @@ export const handleDocOrSelectionChanged = (
45
46
  return buildColumnControlsDecorations({
46
47
  decorationSet,
47
48
  tr,
49
+ options: {
50
+ isDragAndDropEnabled,
51
+ },
48
52
  });
49
53
  } else if (tr.selectionSet) {
50
54
  const isTransactionFromMouseClick =
@@ -70,6 +74,7 @@ export const createPlugin = () => {
70
74
 
71
75
  apply: (tr, decorationSet, oldState, newState) => {
72
76
  let pluginState = decorationSet;
77
+ // main table plugin --->
73
78
  const meta = tr.getMeta(tablePluginKey);
74
79
 
75
80
  if (meta && meta.data && meta.data.decorationSet) {
@@ -17,7 +17,10 @@ import {
17
17
  } from '../../../utils/decoration';
18
18
 
19
19
  import { composeDecorations } from './compose-decorations';
20
- import type { DecorationTransformer } from './types';
20
+ import type {
21
+ BuildDecorationTransformerParams,
22
+ DecorationTransformer,
23
+ } from './types';
21
24
 
22
25
  const isColumnSelected = (tr: Transaction | ReadonlyTransaction): boolean =>
23
26
  tr.selection instanceof CellSelection && tr.selection.isColSelection();
@@ -25,13 +28,12 @@ const isColumnSelected = (tr: Transaction | ReadonlyTransaction): boolean =>
25
28
  // @see: https://product-fabric.atlassian.net/browse/ED-3796
26
29
  const removeControlsHoverDecoration: DecorationTransformer = ({
27
30
  decorationSet,
28
- }): DecorationSet =>
29
- decorationSet.remove(findControlsHoverDecoration(decorationSet));
31
+ }) => decorationSet.remove(findControlsHoverDecoration(decorationSet));
30
32
 
31
33
  const maybeUpdateColumnSelectedDecoration: DecorationTransformer = ({
32
34
  decorationSet,
33
35
  tr,
34
- }): DecorationSet => {
36
+ }) => {
35
37
  if (!isColumnSelected(tr)) {
36
38
  return decorationSet;
37
39
  }
@@ -47,10 +49,9 @@ const maybeUpdateColumnSelectedDecoration: DecorationTransformer = ({
47
49
  const maybeUpdateColumnControlsDecoration: DecorationTransformer = ({
48
50
  decorationSet,
49
51
  tr,
50
- }): DecorationSet => {
52
+ }) => {
51
53
  const table = findTable(tr.selection);
52
54
 
53
- // avoid re-drawing state if dnd decorations don't need to be updated
54
55
  if (!table) {
55
56
  return decorationSet;
56
57
  }
@@ -66,14 +67,13 @@ const maybeUpdateColumnControlsDecoration: DecorationTransformer = ({
66
67
  // @see: https://product-fabric.atlassian.net/browse/ED-7304
67
68
  const removeColumnControlsSelectedDecoration: DecorationTransformer = ({
68
69
  decorationSet,
69
- }): DecorationSet =>
70
- decorationSet.remove(findColumnControlSelectedDecoration(decorationSet));
70
+ }) => decorationSet.remove(findColumnControlSelectedDecoration(decorationSet));
71
71
 
72
72
  const hasColumnSelectedDecorations = (decorationSet: DecorationSet): boolean =>
73
73
  !!findColumnControlSelectedDecoration(decorationSet).length;
74
74
 
75
75
  export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer =
76
- ({ decorationSet, tr }): DecorationSet => {
76
+ ({ decorationSet, tr }) => {
77
77
  if (!hasColumnSelectedDecorations(decorationSet)) {
78
78
  return decorationSet;
79
79
  }
@@ -81,10 +81,19 @@ export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer
81
81
  return removeColumnControlsSelectedDecoration({ decorationSet, tr });
82
82
  };
83
83
 
84
- export const buildColumnControlsDecorations: DecorationTransformer = ({
84
+ export const buildColumnControlsDecorations = ({
85
85
  decorationSet,
86
86
  tr,
87
- }): DecorationSet => {
87
+ options,
88
+ }: BuildDecorationTransformerParams): DecorationSet => {
89
+ if (options.isDragAndDropEnabled) {
90
+ return composeDecorations([
91
+ removeColumnControlsSelectedDecoration,
92
+ removeControlsHoverDecoration,
93
+ maybeUpdateColumnSelectedDecoration,
94
+ ])({ decorationSet, tr });
95
+ }
96
+
88
97
  return composeDecorations([
89
98
  removeColumnControlsSelectedDecoration,
90
99
  removeControlsHoverDecoration,
@@ -1,10 +1,8 @@
1
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
-
3
- import { DecorationTransformer } from './types';
1
+ import type { DecorationTransformer } from './types';
4
2
 
5
3
  export const composeDecorations =
6
4
  (transformers: Array<DecorationTransformer>): DecorationTransformer =>
7
- ({ decorationSet, tr }): DecorationSet =>
5
+ ({ decorationSet, tr }) =>
8
6
  transformers.reduce(
9
7
  (decorationSet, transform) => transform({ decorationSet, tr }),
10
8
  decorationSet,
@@ -1,14 +1,21 @@
1
1
  // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
- import {
2
+ import type {
3
3
  ReadonlyTransaction,
4
4
  Transaction,
5
5
  } from '@atlaskit/editor-prosemirror/state';
6
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
7
 
8
- export type DecorationTransformer = ({
9
- decorationSet,
10
- tr,
11
- }: {
8
+ export type DecorationTransformer = (
9
+ params: DecorationTransformerParams,
10
+ ) => DecorationSet;
11
+
12
+ export type DecorationTransformerParams = {
12
13
  decorationSet: DecorationSet;
13
14
  tr: Transaction | ReadonlyTransaction;
14
- }) => DecorationSet;
15
+ };
16
+
17
+ export type BuildDecorationTransformerParams = DecorationTransformerParams & {
18
+ options: {
19
+ isDragAndDropEnabled: boolean;
20
+ };
21
+ };
@@ -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 = {
@@ -309,7 +309,8 @@ export const TableCssClassName = {
309
309
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
310
310
  CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
311
311
 
312
- /** Controls with drag handle */
312
+ /** drag and drop controls */
313
+ DRAG_ROW_CONTROLS_WRAPPER: `${tablePrefixSelector}-drag-row-controls-wrapper`,
313
314
  DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
314
315
  DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
315
316
  DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,