@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
@@ -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;
@@ -1,5 +1,3 @@
1
- // #region Imports
2
-
3
1
  import { closestElement, isParagraph, isTextSelection, mapSlice } from '@atlaskit/editor-common/utils';
4
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
5
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
@@ -26,7 +24,9 @@ export const setTableRef = ref => createCommand(state => {
26
24
  const tablePos = ref && foundTable ? foundTable.pos : undefined;
27
25
  const tableWrapperTarget = closestElement(tableRef, `.${ClassName.TABLE_NODE_WRAPPER}`) || undefined;
28
26
  const layout = tableNode ? tableNode.attrs.layout : undefined;
29
- const decorationSet = updatePluginStateDecorations(state, createColumnControlsDecoration(state.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
27
+ const {
28
+ isDragAndDropEnabled
29
+ } = getPluginState(state);
30
30
  return {
31
31
  type: 'SET_TABLE_REF',
32
32
  data: {
@@ -38,7 +38,8 @@ export const setTableRef = ref => createCommand(state => {
38
38
  isNumberColumnEnabled: checkIfNumberColumnEnabled(state.selection),
39
39
  isHeaderRowEnabled: checkIfHeaderRowEnabled(state.selection),
40
40
  isHeaderColumnEnabled: checkIfHeaderColumnEnabled(state.selection),
41
- decorationSet,
41
+ // decoration set is drawn by the decoration plugin, skip this for DnD as all controls are floating
42
+ decorationSet: !isDragAndDropEnabled ? updatePluginStateDecorations(state, createColumnControlsDecoration(state.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS) : undefined,
42
43
  resizeHandleRowIndex: undefined,
43
44
  resizeHandleColumnIndex: undefined
44
45
  }
@@ -159,6 +160,55 @@ export const transformSliceToRemoveColumnsWidths = (slice, schema) => {
159
160
  return maybeCell;
160
161
  });
161
162
  };
163
+ export const countCellsInSlice = (slice, schema, type) => {
164
+ const {
165
+ tableHeader,
166
+ tableCell
167
+ } = schema.nodes;
168
+ let count = 0;
169
+ if (!type) {
170
+ return count;
171
+ }
172
+ slice.content.descendants(maybeCell => {
173
+ if (maybeCell.type === tableCell || maybeCell.type === tableHeader) {
174
+ count += type === 'row' ? maybeCell.attrs.colspan : maybeCell.attrs.rowspan;
175
+ return false;
176
+ }
177
+ });
178
+ return count;
179
+ };
180
+ export const getTableSelectionType = selection => {
181
+ if (selection instanceof CellSelection) {
182
+ return selection.isRowSelection() ? 'row' : selection.isColSelection() ? 'column' : undefined;
183
+ }
184
+ };
185
+ export const getTableElementMoveTypeBySlice = (slice, state) => {
186
+ if (!slice.content.firstChild) {
187
+ return;
188
+ }
189
+ const {
190
+ schema
191
+ } = state;
192
+
193
+ // if the slice only contains one table row, assume it's a row
194
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
195
+ return 'row';
196
+ }
197
+ const table = findTable(state.tr.selection);
198
+ const map = TableMap.get(table.node);
199
+ const slicedMap = TableMap.get(slice.content.firstChild);
200
+ return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
201
+ };
202
+ export const isInsideFirstCellOfRowOrColumn = (selection, type) => {
203
+ const table = findTable(selection);
204
+ if (!table || !type) {
205
+ return;
206
+ }
207
+ const map = TableMap.get(table.node);
208
+ const cell = selectionCell(selection);
209
+ const index = map.map.findIndex(value => value === cell.pos - 1);
210
+ return type === 'row' ? index % map.width === 0 : index < map.width;
211
+ };
162
212
  export const deleteTable = (state, dispatch) => {
163
213
  if (dispatch) {
164
214
  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;
@@ -537,9 +533,7 @@ class TableComponent extends React.Component {
537
533
  const tableRef = this.table || undefined;
538
534
  const headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
539
535
  const hasHeaderRow = containsHeaderRow(node);
540
- const rowControls = /*#__PURE__*/React.createElement("div", {
541
- className: ClassName.ROW_CONTROLS_WRAPPER
542
- }, /*#__PURE__*/React.createElement(TableFloatingControls, {
536
+ const rowControls = /*#__PURE__*/React.createElement(TableFloatingControls, {
543
537
  editorView: view,
544
538
  tableRef: tableRef,
545
539
  tableNode: node,
@@ -559,7 +553,7 @@ class TableComponent extends React.Component {
559
553
  selection: view.state.selection,
560
554
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
561
555
  stickyHeader: this.state.stickyHeader
562
- }));
556
+ });
563
557
  const colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
564
558
  editorView: view,
565
559
  tableRef: tableRef,
@@ -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
+ };
@@ -2,7 +2,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
5
  import { pluginKey as tablePluginKey } from '../plugin-key';
7
6
  import { pluginKey as tableWidthPluginKey } from '../table-width';
8
7
  import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
@@ -12,15 +11,21 @@ export const handleDocOrSelectionChanged = (tr, decorationSet, oldState, newStat
12
11
  var _tableWidthPluginKey$, _tableWidthPluginKey$2;
13
12
  const isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
14
13
  const wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
14
+ const {
15
+ isDragAndDropEnabled = false
16
+ } = tablePluginKey.getState(newState) || {};
15
17
  const changedResizing = isResizing !== wasResizing;
16
18
 
17
19
  // Remove column controls when resizing and don't add column decoration controls when DnD enabled
18
- if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
20
+ if (isResizing) {
19
21
  return DecorationSet.empty;
20
22
  } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
21
23
  return buildColumnControlsDecorations({
22
24
  decorationSet,
23
- tr
25
+ tr,
26
+ options: {
27
+ isDragAndDropEnabled
28
+ }
24
29
  });
25
30
  } else if (tr.selectionSet) {
26
31
  const isTransactionFromMouseClick = !tr.docChanged && tr.selectionSet && tr.getMeta('pointer');
@@ -39,6 +44,7 @@ export const createPlugin = () => {
39
44
  init: () => DecorationSet.empty,
40
45
  apply: (tr, decorationSet, oldState, newState) => {
41
46
  let pluginState = decorationSet;
47
+ // main table plugin --->
42
48
  const meta = tr.getMeta(tablePluginKey);
43
49
  if (meta && meta.data && meta.data.decorationSet) {
44
50
  pluginState = meta.data.decorationSet;
@@ -25,8 +25,6 @@ const maybeUpdateColumnControlsDecoration = ({
25
25
  tr
26
26
  }) => {
27
27
  const table = findTable(tr.selection);
28
-
29
- // avoid re-drawing state if dnd decorations don't need to be updated
30
28
  if (!table) {
31
29
  return decorationSet;
32
30
  }
@@ -52,8 +50,15 @@ export const maybeUpdateColumnControlsSelectedDecoration = ({
52
50
  };
53
51
  export const buildColumnControlsDecorations = ({
54
52
  decorationSet,
55
- tr
53
+ tr,
54
+ options
56
55
  }) => {
56
+ if (options.isDragAndDropEnabled) {
57
+ return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration])({
58
+ decorationSet,
59
+ tr
60
+ });
61
+ }
57
62
  return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration, maybeUpdateColumnControlsDecoration])({
58
63
  decorationSet,
59
64
  tr
@@ -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'
@@ -79,7 +79,8 @@ export const TableCssClassName = {
79
79
  CORNER_CONTROLS_INSERT_ROW_MARKER: `${tablePrefixSelector}-corner-controls__insert-row-marker`,
80
80
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
81
81
  CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
82
- /** Controls with drag handle */
82
+ /** drag and drop controls */
83
+ DRAG_ROW_CONTROLS_WRAPPER: `${tablePrefixSelector}-drag-row-controls-wrapper`,
83
84
  DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
84
85
  DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
85
86
  DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,
@@ -128,7 +128,10 @@ export default class TableFloatingControls extends Component {
128
128
  return null;
129
129
  }
130
130
  const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
131
+ const wrapperClassName = isDragAndDropEnabled ? ClassName.DRAG_ROW_CONTROLS_WRAPPER : ClassName.ROW_CONTROLS_WRAPPER;
131
132
  return /*#__PURE__*/React.createElement("div", {
133
+ className: wrapperClassName
134
+ }, /*#__PURE__*/React.createElement("div", {
132
135
  onMouseDown: e => !isDragAndDropEnabled && e.preventDefault()
133
136
  }, isNumberColumnEnabled ? /*#__PURE__*/React.createElement(NumberColumn, {
134
137
  editorView: editorView,
@@ -178,7 +181,7 @@ export default class TableFloatingControls extends Component {
178
181
  isResizing: isResizing,
179
182
  selectRow: this.selectRow,
180
183
  stickyTop: tableActive ? stickyTop : undefined
181
- }))));
184
+ })))));
182
185
  }
183
186
  }
184
187
  _defineProperty(TableFloatingControls, "displayName", 'TableFloatingControls');
@@ -173,23 +173,6 @@ const tableStickyHeaderFirefoxFixStyle = props => {
173
173
  `;
174
174
  }
175
175
  };
176
- const tableRowControlStyles = () => {
177
- return getBooleanFF('platform.editor.table.drag-and-drop') ? css`
178
- .${ClassName.ROW_CONTROLS_WRAPPER} {
179
- position: absolute;
180
- margin-top: ${tableMarginTop}px;
181
- left: -${tableToolbarSize + 1}px;
182
- z-index: ${rowControlsZIndex + 4};
183
- }
184
- ` : css`
185
- .${ClassName.ROW_CONTROLS_WRAPPER} {
186
- position: absolute;
187
- /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
188
- top: ${tableMarginTop - cornerControlHeight + 1}px;
189
- left: -${tableToolbarSize}px;
190
- }
191
- `;
192
- };
193
176
  const tableWrapperStyles = () => {
194
177
  if (getBooleanFF('platform.editor.custom-table-width')) {
195
178
  return css`
@@ -463,7 +446,8 @@ export const tableStyles = props => {
463
446
  .less-padding {
464
447
  padding: 0 ${tablePadding}px;
465
448
 
466
- .${ClassName.ROW_CONTROLS_WRAPPER} {
449
+ .${ClassName.DRAG_ROW_CONTROLS_WRAPPER},
450
+ .${ClassName.ROW_CONTROLS_WRAPPER} {
467
451
  padding: 0 ${tablePadding}px;
468
452
 
469
453
  // https://product-fabric.atlassian.net/browse/ED-16386
@@ -935,8 +919,24 @@ export const tableStyles = props => {
935
919
  }
936
920
  }
937
921
  }
938
- ${tableRowControlStyles()}
939
- .${ClassName.ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW} {
922
+
923
+ // override for DnD controls
924
+ .${ClassName.DRAG_ROW_CONTROLS_WRAPPER} {
925
+ position: absolute;
926
+ margin-top: ${tableMarginTop}px;
927
+ left: -${tableToolbarSize + 1}px;
928
+ z-index: ${rowControlsZIndex + 4};
929
+ }
930
+
931
+ .${ClassName.ROW_CONTROLS_WRAPPER} {
932
+ position: absolute;
933
+ /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
934
+ top: ${tableMarginTop - cornerControlHeight + 1}px;
935
+ left: -${tableToolbarSize}px;
936
+ }
937
+
938
+ .${ClassName.DRAG_ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW},
939
+ .${ClassName.ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW} {
940
940
  z-index: ${akEditorUnitZIndex};
941
941
  }
942
942