@atlaskit/editor-plugin-table 5.4.6 → 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 (95) hide show
  1. package/CHANGELOG.md +6 -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 +4 -1
  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 -0
@@ -5,13 +5,12 @@ import { Selection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
7
  import { addColumnAt as addColumnAtPMUtils, addRowAt, createTable as createTableNode, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
8
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
+ import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
8
10
  import { META_KEYS } from '../pm-plugins/table-analytics';
9
11
  import { rescaleColumns } from '../transforms/column-width';
10
12
  import { checkIfHeaderRowEnabled, copyPreviousRow } from '../utils';
11
13
  import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
12
-
13
- // #endregion
14
-
15
14
  function addColumnAtCustomStep(column) {
16
15
  return tr => {
17
16
  const table = findTable(tr.selection);
@@ -35,6 +34,11 @@ export function addColumnAt(getEditorContainerWidth) {
35
34
  // [ED-8288] Update colwidths manually to avoid multiple dispatch in TableComponent
36
35
  updatedTr = rescaleColumns(getEditorContainerWidth)(table, view)(updatedTr);
37
36
  }
37
+ if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event') && view) {
38
+ updatedTr = updateRowOrColumnMovedTransform({
39
+ type: 'column'
40
+ }, 'addRowOrColumn')(view.state, updatedTr);
41
+ }
38
42
  updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
39
43
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.ADDED_COLUMN
40
44
  });
@@ -111,6 +115,11 @@ export const insertRow = (row, moveCursorToTheNewRow) => (state, dispatch) => {
111
115
  } else {
112
116
  tr.setSelection(selection.map(tr.doc, tr.mapping));
113
117
  }
118
+ if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event')) {
119
+ updateRowOrColumnMovedTransform({
120
+ type: 'row'
121
+ }, 'addRowOrColumn')(state, tr);
122
+ }
114
123
  dispatch(tr);
115
124
  }
116
125
  return true;
@@ -159,6 +159,55 @@ export const transformSliceToRemoveColumnsWidths = (slice, schema) => {
159
159
  return maybeCell;
160
160
  });
161
161
  };
162
+ export const countCellsInSlice = (slice, schema, type) => {
163
+ const {
164
+ tableHeader,
165
+ tableCell
166
+ } = schema.nodes;
167
+ let count = 0;
168
+ if (!type) {
169
+ return count;
170
+ }
171
+ slice.content.descendants(maybeCell => {
172
+ if (maybeCell.type === tableCell || maybeCell.type === tableHeader) {
173
+ count += type === 'row' ? maybeCell.attrs.colspan : maybeCell.attrs.rowspan;
174
+ return false;
175
+ }
176
+ });
177
+ return count;
178
+ };
179
+ export const getTableSelectionType = selection => {
180
+ if (selection instanceof CellSelection) {
181
+ return selection.isRowSelection() ? 'row' : selection.isColSelection() ? 'column' : undefined;
182
+ }
183
+ };
184
+ export const getTableElementMoveTypeBySlice = (slice, state) => {
185
+ if (!slice.content.firstChild) {
186
+ return;
187
+ }
188
+ const {
189
+ schema
190
+ } = state;
191
+
192
+ // if the slice only contains one table row, assume it's a row
193
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
194
+ return 'row';
195
+ }
196
+ const table = findTable(state.tr.selection);
197
+ const map = TableMap.get(table.node);
198
+ const slicedMap = TableMap.get(slice.content.firstChild);
199
+ return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
200
+ };
201
+ export const isInsideFirstCellOfRowOrColumn = (selection, type) => {
202
+ const table = findTable(selection);
203
+ if (!table || !type) {
204
+ return;
205
+ }
206
+ const map = TableMap.get(table.node);
207
+ const cell = selectionCell(selection);
208
+ const index = map.map.findIndex(value => value === cell.pos - 1);
209
+ return type === 'row' ? index % map.width === 0 : index < map.width;
210
+ };
162
211
  export const deleteTable = (state, dispatch) => {
163
212
  if (dispatch) {
164
213
  dispatch(removeTable(state.tr));
@@ -12,6 +12,8 @@ import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
12
12
  import { createTable } from '@atlaskit/editor-tables/utils';
13
13
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
14
  import { pluginConfig } from './create-plugin-config';
15
+ import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analytics/plugin';
16
+ import { pluginKey as tableAnalyticsPluginKey } from './pm-plugins/analytics/plugin-key';
15
17
  import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
16
18
  import { createPlugin as createDragAndDropPlugin, pluginKey as dragAndDropPluginKey } from './pm-plugins/drag-and-drop';
17
19
  import { keymapPlugin } from './pm-plugins/keymap';
@@ -19,7 +21,7 @@ import { createPlugin } from './pm-plugins/main';
19
21
  import { pluginKey } from './pm-plugins/plugin-key';
20
22
  import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
21
23
  import { createPlugin as createStickyHeadersPlugin, findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from './pm-plugins/sticky-headers';
22
- import { createPlugin as createTableAnalyticsPlugin, pluginKey as tableAnalyticsPluginKey } from './pm-plugins/table-analytics';
24
+ import { createPlugin as createTableOverflowAnalyticsPlugin } from './pm-plugins/table-analytics';
23
25
  import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
24
26
  import { createPlugin as createFlexiResizingPlugin, pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
25
27
  import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
@@ -182,15 +184,23 @@ const tablesPlugin = ({
182
184
  var _options$fullWidthEna;
183
185
  return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
184
186
  }
185
- }, {
186
- name: 'tableAnalyticsPlugin',
187
+ },
188
+ // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
189
+ {
190
+ name: 'tableOverflowAnalyticsPlugin',
187
191
  plugin: ({
188
192
  dispatch,
189
193
  dispatchAnalyticsEvent
190
194
  }) => {
191
195
  var _options$tableResizin;
192
- return getBooleanFF('platform.editor.table.overflow-state-analytics') ? createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false) : undefined;
196
+ return getBooleanFF('platform.editor.table.overflow-state-analytics') ? createTableOverflowAnalyticsPlugin(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false) : undefined;
193
197
  }
198
+ }, {
199
+ name: 'tableAnalyticsPlugin',
200
+ plugin: ({
201
+ dispatch,
202
+ dispatchAnalyticsEvent
203
+ }) => getBooleanFF('platform.editor.table.analytics-plugin-moved-event') ? createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent) : undefined
194
204
  }, {
195
205
  name: 'tableGetEditorViewReferencePlugin',
196
206
  plugin: () => {
@@ -4,10 +4,9 @@ import classnames from 'classnames';
4
4
  import memoizeOne from 'memoize-one';
5
5
  import rafSchedule from 'raf-schd';
6
6
  import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
7
- import { createDispatch } from '@atlaskit/editor-common/event-dispatcher';
8
7
  import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
9
8
  import { tableMarginSides } from '@atlaskit/editor-common/styles';
10
- import { analyticsEventKey, browser, isValidPosition } from '@atlaskit/editor-common/utils';
9
+ import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
11
10
  import { MAX_BROWSER_SCROLLBAR_HEIGHT, akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
12
11
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
13
12
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
@@ -189,26 +188,23 @@ class TableComponent extends React.Component {
189
188
  _defineProperty(this, "setTimerToSendInitialOverflowCaptured", isOverflowing => {
190
189
  var _this$state;
191
190
  const {
192
- eventDispatcher,
191
+ dispatchAnalyticsEvent,
193
192
  containerWidth,
194
193
  options
195
194
  } = this.props;
196
- const dispatch = createDispatch(eventDispatcher);
197
195
  const parentWidth = ((_this$state = this.state) === null || _this$state === void 0 ? void 0 : _this$state.parentWidth) || 0;
198
196
  this.initialOverflowCaptureTimerId = setTimeout(() => {
199
- dispatch(analyticsEventKey, {
200
- payload: {
201
- action: TABLE_ACTION.INITIAL_OVERFLOW_CAPTURED,
202
- actionSubject: ACTION_SUBJECT.TABLE,
203
- actionSubjectId: null,
204
- eventType: EVENT_TYPE.TRACK,
205
- attributes: {
206
- editorWidth: containerWidth.width || 0,
207
- isOverflowing,
208
- tableResizingEnabled: (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) || false,
209
- width: this.node.attrs.width || 0,
210
- parentWidth
211
- }
197
+ dispatchAnalyticsEvent({
198
+ action: TABLE_ACTION.INITIAL_OVERFLOW_CAPTURED,
199
+ actionSubject: ACTION_SUBJECT.TABLE,
200
+ actionSubjectId: null,
201
+ eventType: EVENT_TYPE.TRACK,
202
+ attributes: {
203
+ editorWidth: containerWidth.width || 0,
204
+ isOverflowing,
205
+ tableResizingEnabled: (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) || false,
206
+ width: this.node.attrs.width || 0,
207
+ parentWidth
212
208
  }
213
209
  });
214
210
  this.isInitialOverflowSent = true;
@@ -139,10 +139,10 @@ export const TableResizer = ({
139
139
  tr
140
140
  }
141
141
  } = editorView;
142
+ displayGapCursor(false);
142
143
  tr.setMeta(tableWidthPluginKey, {
143
144
  resizing: true
144
145
  });
145
- displayGapCursor(false);
146
146
  tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
147
147
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
148
148
  });
@@ -156,6 +156,7 @@ export default class TableView extends ReactNodeView {
156
156
  containerWidth: containerWidth,
157
157
  contentDOM: forwardRef,
158
158
  getEditorFeatureFlags: props.getEditorFeatureFlags,
159
+ dispatchAnalyticsEvent: props.dispatchAnalyticsEvent,
159
160
  pluginInjectionApi: props.pluginInjectionApi
160
161
  });
161
162
  }
@@ -217,7 +218,7 @@ export default class TableView extends ReactNodeView {
217
218
  super.destroy();
218
219
  }
219
220
  }
220
- export const createTableView = (node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, pluginInjectionApi) => {
221
+ export const createTableView = (node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, dispatchAnalyticsEvent, pluginInjectionApi) => {
221
222
  const {
222
223
  pluginConfig,
223
224
  isBreakoutEnabled,
@@ -246,6 +247,7 @@ export const createTableView = (node, view, getPos, portalProviderAPI, eventDisp
246
247
  },
247
248
  getEditorContainerWidth,
248
249
  getEditorFeatureFlags,
250
+ dispatchAnalyticsEvent,
249
251
  hasIntlContext,
250
252
  pluginInjectionApi
251
253
  }).init();
@@ -0,0 +1,8 @@
1
+ export let AnalyticPluginTypes = /*#__PURE__*/function (AnalyticPluginTypes) {
2
+ AnalyticPluginTypes[AnalyticPluginTypes["UpdateOverflowTriggerNameAction"] = 0] = "UpdateOverflowTriggerNameAction";
3
+ AnalyticPluginTypes[AnalyticPluginTypes["UpdateRowOrColumnMovedAction"] = 1] = "UpdateRowOrColumnMovedAction";
4
+ AnalyticPluginTypes[AnalyticPluginTypes["RemoveRowOrColumnMovedAction"] = 2] = "RemoveRowOrColumnMovedAction";
5
+ AnalyticPluginTypes[AnalyticPluginTypes["RemoveOverFlowTriggerNameAction"] = 3] = "RemoveOverFlowTriggerNameAction";
6
+ AnalyticPluginTypes[AnalyticPluginTypes["UpdateRowOrColumnMovedAndOverflowTrigger"] = 4] = "UpdateRowOrColumnMovedAndOverflowTrigger";
7
+ return AnalyticPluginTypes;
8
+ }({});
@@ -0,0 +1,33 @@
1
+ import { AnalyticPluginTypes } from './actions';
2
+ import { createCommand, getPluginState } from './plugin-factory';
3
+ import { pluginKey } from './plugin-key';
4
+ import { getMovedPayload } from './utils/moved-event';
5
+ export const updateRowOrColumnMoved = (nextState, nextAction) => createCommand(state => {
6
+ const {
7
+ rowOrColumnMoved
8
+ } = getPluginState(state);
9
+ const data = getMovedPayload(nextState, nextAction, rowOrColumnMoved);
10
+ return {
11
+ type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction,
12
+ data
13
+ };
14
+ }, tr => tr.setMeta('addToHistory', false));
15
+
16
+ // --- transforms, prefer these over commands to avoid an extra 'dispatch'
17
+ export const resetRowOrColumnMovedTransform = () => tr => {
18
+ const payload = {
19
+ type: AnalyticPluginTypes.RemoveRowOrColumnMovedAction
20
+ };
21
+ return tr.setMeta(pluginKey, payload);
22
+ };
23
+ export const updateRowOrColumnMovedTransform = (nextState, nextAction) => (state, tr) => {
24
+ const {
25
+ rowOrColumnMoved
26
+ } = getPluginState(state);
27
+ const data = getMovedPayload(nextState, nextAction, rowOrColumnMoved);
28
+ const payload = {
29
+ type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction,
30
+ data
31
+ };
32
+ return tr.setMeta(pluginKey, payload);
33
+ };
@@ -0,0 +1,8 @@
1
+ import { pluginFactory } from '@atlaskit/editor-common/utils';
2
+ import { pluginKey } from './plugin-key';
3
+ import { reducer } from './reducer';
4
+ export const {
5
+ createPluginState,
6
+ createCommand,
7
+ getPluginState
8
+ } = pluginFactory(pluginKey, reducer);
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export const pluginKey = new PluginKey('tableAnalyticPlugin');
@@ -0,0 +1,72 @@
1
+ import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
+ import { countCellsInSlice, getTableElementMoveTypeBySlice, getTableSelectionType, isInsideFirstCellOfRowOrColumn } from '../../commands/misc';
5
+ import { resetRowOrColumnMovedTransform, updateRowOrColumnMoved } from './commands';
6
+ import { createPluginState } from './plugin-factory';
7
+ import { pluginKey } from './plugin-key';
8
+ import { defaultState } from './types';
9
+ export const createPlugin = (dispatch, dispatchAnalyticsEvent) => new SafePlugin({
10
+ key: pluginKey,
11
+ state: createPluginState(dispatch, defaultState),
12
+ appendTransaction: (transactions, oldState, newState) => {
13
+ const tr = transactions.find(tr => {
14
+ var _tr$getMeta, _tr$getMeta$data, _tr$getMeta$data$curr;
15
+ return (_tr$getMeta = tr.getMeta(pluginKey)) === null || _tr$getMeta === void 0 ? void 0 : (_tr$getMeta$data = _tr$getMeta.data) === null || _tr$getMeta$data === void 0 ? void 0 : (_tr$getMeta$data$curr = _tr$getMeta$data.currentActions) === null || _tr$getMeta$data$curr === void 0 ? void 0 : _tr$getMeta$data$curr.includes('pasted');
16
+ });
17
+ if (tr) {
18
+ var _tr$getMeta2, _tr$getMeta2$data;
19
+ dispatchAnalyticsEvent({
20
+ action: TABLE_ACTION.ROW_OR_COLUMN_MOVED,
21
+ actionSubject: ACTION_SUBJECT.TABLE,
22
+ actionSubjectId: null,
23
+ eventType: EVENT_TYPE.TRACK,
24
+ attributes: {
25
+ type: (_tr$getMeta2 = tr.getMeta(pluginKey)) === null || _tr$getMeta2 === void 0 ? void 0 : (_tr$getMeta2$data = _tr$getMeta2.data) === null || _tr$getMeta2$data === void 0 ? void 0 : _tr$getMeta2$data.type
26
+ }
27
+ });
28
+ return resetRowOrColumnMovedTransform()(tr);
29
+ }
30
+ return undefined;
31
+ },
32
+ props: {
33
+ handlePaste: ({
34
+ state,
35
+ dispatch
36
+ }, event, slice) => {
37
+ if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event')) {
38
+ const {
39
+ schema
40
+ } = state;
41
+ const type = getTableElementMoveTypeBySlice(slice, state);
42
+
43
+ // if the selection wasn't in the first cell of a row or column, don't count it
44
+ if (!isInsideFirstCellOfRowOrColumn(state.selection, type)) {
45
+ return;
46
+ }
47
+ const count = countCellsInSlice(slice, schema, type);
48
+ updateRowOrColumnMoved({
49
+ numberOfCells: count,
50
+ type
51
+ }, 'pasted')(state, dispatch);
52
+ }
53
+ },
54
+ transformCopied: (slice, {
55
+ state,
56
+ dispatch
57
+ }) => {
58
+ if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event')) {
59
+ const {
60
+ schema
61
+ } = state;
62
+ const type = getTableSelectionType(state.selection);
63
+ const count = countCellsInSlice(slice, schema, type);
64
+ updateRowOrColumnMoved({
65
+ numberOfCells: count,
66
+ type
67
+ }, 'copyOrCut')(state, dispatch);
68
+ }
69
+ return slice;
70
+ }
71
+ }
72
+ });
@@ -0,0 +1,21 @@
1
+ import { AnalyticPluginTypes } from './actions';
2
+ import { defaultState } from './types';
3
+ export const reducer = (state, action) => {
4
+ switch (action.type) {
5
+ case AnalyticPluginTypes.UpdateRowOrColumnMovedAction:
6
+ return {
7
+ ...state,
8
+ rowOrColumnMoved: {
9
+ ...state.rowOrColumnMoved,
10
+ ...action.data
11
+ }
12
+ };
13
+ case AnalyticPluginTypes.RemoveRowOrColumnMovedAction:
14
+ return {
15
+ ...state,
16
+ rowOrColumnMoved: defaultState.rowOrColumnMoved
17
+ };
18
+ default:
19
+ return state;
20
+ }
21
+ };
@@ -0,0 +1,7 @@
1
+ export const defaultState = {
2
+ rowOrColumnMoved: {
3
+ type: undefined,
4
+ numberOfCells: undefined,
5
+ currentActions: []
6
+ }
7
+ };
@@ -0,0 +1,30 @@
1
+ import { defaultState } from '../types';
2
+ const getNextActionType = (nextState, nextAction, prevState) => {
3
+ if (nextAction === 'pasted') {
4
+ if (prevState && prevState.currentActions.includes('copyOrCut') && prevState.currentActions.includes('addRowOrColumn') && prevState.numberOfCells === nextState.numberOfCells && prevState.type === nextState.type) {
5
+ return 'pasted';
6
+ }
7
+ return 'none';
8
+ }
9
+ return nextAction;
10
+ };
11
+ export const getMovedPayload = (nextState, nextAction, prevState) => {
12
+ const nextActionType = getNextActionType(nextState, nextAction, prevState);
13
+ if (nextActionType === 'none') {
14
+ return defaultState.rowOrColumnMoved;
15
+ }
16
+
17
+ // a new workflow has started in the opposite axis (e.g. inserted a row, but copied a column) remove old state
18
+ if (prevState.type !== nextState.type) {
19
+ return {
20
+ currentActions: [nextActionType],
21
+ numberOfCells: nextState === null || nextState === void 0 ? void 0 : nextState.numberOfCells,
22
+ type: nextState.type
23
+ };
24
+ }
25
+ return {
26
+ currentActions: prevState.currentActions.includes(nextActionType) ? prevState.currentActions : [...prevState.currentActions, nextActionType],
27
+ numberOfCells: (nextState === null || nextState === void 0 ? void 0 : nextState.numberOfCells) || prevState.numberOfCells,
28
+ type: nextState === null || nextState === void 0 ? void 0 : nextState.type
29
+ };
30
+ };
@@ -227,7 +227,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
227
227
  return false;
228
228
  },
229
229
  nodeViews: {
230
- table: (node, view, getPos) => createTableView(node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, pluginInjectionApi),
230
+ table: (node, view, getPos) => createTableView(node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, dispatchAnalyticsEvent, pluginInjectionApi),
231
231
  tableRow: (node, view, getPos) => new TableRow(node, view, getPos, eventDispatcher),
232
232
  tableCell: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher, observer),
233
233
  tableHeader: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher, observer)
@@ -4,7 +4,7 @@
4
4
  import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
7
- export const pluginKey = new PluginKey('tableAnalyticsPlugin');
7
+ export const pluginKey = new PluginKey('tableOverflowAnalyticsPlugin');
8
8
  export const META_KEYS = {
9
9
  OVERFLOW_TRIGGER: 'tableOverflowTrigger',
10
10
  OVERFLOW_STATE_CHANGED: 'tableOverflowStateChanged'
@@ -5,13 +5,12 @@ import { Selection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
7
  import { addColumnAt as addColumnAtPMUtils, addRowAt, createTable as createTableNode, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
8
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
+ import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
8
10
  import { META_KEYS } from '../pm-plugins/table-analytics';
9
11
  import { rescaleColumns } from '../transforms/column-width';
10
12
  import { checkIfHeaderRowEnabled, copyPreviousRow } from '../utils';
11
13
  import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
12
-
13
- // #endregion
14
-
15
14
  function addColumnAtCustomStep(column) {
16
15
  return function (tr) {
17
16
  var table = findTable(tr.selection);
@@ -37,6 +36,11 @@ export function addColumnAt(getEditorContainerWidth) {
37
36
  // [ED-8288] Update colwidths manually to avoid multiple dispatch in TableComponent
38
37
  updatedTr = rescaleColumns(getEditorContainerWidth)(table, view)(updatedTr);
39
38
  }
39
+ if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event') && view) {
40
+ updatedTr = updateRowOrColumnMovedTransform({
41
+ type: 'column'
42
+ }, 'addRowOrColumn')(view.state, updatedTr);
43
+ }
40
44
  updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
41
45
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.ADDED_COLUMN
42
46
  });
@@ -120,6 +124,11 @@ export var insertRow = function insertRow(row, moveCursorToTheNewRow) {
120
124
  } else {
121
125
  tr.setSelection(selection.map(tr.doc, tr.mapping));
122
126
  }
127
+ if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event')) {
128
+ updateRowOrColumnMovedTransform({
129
+ type: 'row'
130
+ }, 'addRowOrColumn')(state, tr);
131
+ }
123
132
  dispatch(tr);
124
133
  }
125
134
  return true;
@@ -152,6 +152,54 @@ export var transformSliceToRemoveColumnsWidths = function transformSliceToRemove
152
152
  return maybeCell;
153
153
  });
154
154
  };
155
+ export var countCellsInSlice = function countCellsInSlice(slice, schema, type) {
156
+ var _schema$nodes4 = schema.nodes,
157
+ tableHeader = _schema$nodes4.tableHeader,
158
+ tableCell = _schema$nodes4.tableCell;
159
+ var count = 0;
160
+ if (!type) {
161
+ return count;
162
+ }
163
+ slice.content.descendants(function (maybeCell) {
164
+ if (maybeCell.type === tableCell || maybeCell.type === tableHeader) {
165
+ count += type === 'row' ? maybeCell.attrs.colspan : maybeCell.attrs.rowspan;
166
+ return false;
167
+ }
168
+ });
169
+ return count;
170
+ };
171
+ export var getTableSelectionType = function getTableSelectionType(selection) {
172
+ if (selection instanceof CellSelection) {
173
+ return selection.isRowSelection() ? 'row' : selection.isColSelection() ? 'column' : undefined;
174
+ }
175
+ };
176
+ export var getTableElementMoveTypeBySlice = function getTableElementMoveTypeBySlice(slice, state) {
177
+ if (!slice.content.firstChild) {
178
+ return;
179
+ }
180
+ var schema = state.schema;
181
+
182
+ // if the slice only contains one table row, assume it's a row
183
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
184
+ return 'row';
185
+ }
186
+ var table = findTable(state.tr.selection);
187
+ var map = TableMap.get(table.node);
188
+ var slicedMap = TableMap.get(slice.content.firstChild);
189
+ return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
190
+ };
191
+ export var isInsideFirstCellOfRowOrColumn = function isInsideFirstCellOfRowOrColumn(selection, type) {
192
+ var table = findTable(selection);
193
+ if (!table || !type) {
194
+ return;
195
+ }
196
+ var map = TableMap.get(table.node);
197
+ var cell = selectionCell(selection);
198
+ var index = map.map.findIndex(function (value) {
199
+ return value === cell.pos - 1;
200
+ });
201
+ return type === 'row' ? index % map.width === 0 : index < map.width;
202
+ };
155
203
  export var deleteTable = function deleteTable(state, dispatch) {
156
204
  if (dispatch) {
157
205
  dispatch(removeTable(state.tr));