@atlaskit/editor-plugin-table 7.13.0 → 7.13.2

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 (74) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/commands/insert.js +6 -4
  3. package/dist/cjs/commands-with-analytics.js +4 -2
  4. package/dist/cjs/plugin.js +4 -2
  5. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +10 -3
  6. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
  7. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +8 -1
  8. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +51 -34
  9. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +11 -7
  10. package/dist/cjs/ui/FloatingContextualMenu/index.js +4 -2
  11. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +3 -2
  12. package/dist/cjs/ui/FloatingDragMenu/index.js +7 -2
  13. package/dist/cjs/ui/FloatingInsertButton/index.js +10 -4
  14. package/dist/cjs/utils/drag-menu.js +3 -2
  15. package/dist/es2019/commands/insert.js +6 -6
  16. package/dist/es2019/commands-with-analytics.js +4 -4
  17. package/dist/es2019/plugin.js +4 -2
  18. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +11 -4
  19. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
  20. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +7 -0
  21. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +49 -34
  22. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +7 -3
  23. package/dist/es2019/ui/FloatingContextualMenu/index.js +4 -2
  24. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +3 -2
  25. package/dist/es2019/ui/FloatingDragMenu/index.js +7 -2
  26. package/dist/es2019/ui/FloatingInsertButton/index.js +10 -4
  27. package/dist/es2019/utils/drag-menu.js +3 -3
  28. package/dist/esm/commands/insert.js +6 -4
  29. package/dist/esm/commands-with-analytics.js +4 -2
  30. package/dist/esm/plugin.js +4 -2
  31. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +11 -4
  32. package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
  33. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +7 -0
  34. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +50 -33
  35. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +11 -7
  36. package/dist/esm/ui/FloatingContextualMenu/index.js +4 -2
  37. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +3 -2
  38. package/dist/esm/ui/FloatingDragMenu/index.js +7 -2
  39. package/dist/esm/ui/FloatingInsertButton/index.js +10 -4
  40. package/dist/esm/utils/drag-menu.js +3 -2
  41. package/dist/types/commands/insert.d.ts +3 -3
  42. package/dist/types/commands-with-analytics.d.ts +2 -2
  43. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  44. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
  45. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -0
  46. package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
  47. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  48. package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
  49. package/dist/types/ui/FloatingInsertButton/index.d.ts +2 -1
  50. package/dist/types/utils/drag-menu.d.ts +1 -1
  51. package/dist/types-ts4.5/commands/insert.d.ts +3 -3
  52. package/dist/types-ts4.5/commands-with-analytics.d.ts +2 -2
  53. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  54. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
  55. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -0
  56. package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
  57. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  58. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +3 -2
  59. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +2 -1
  60. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  61. package/package.json +2 -2
  62. package/src/commands/insert.ts +16 -6
  63. package/src/commands-with-analytics.ts +13 -3
  64. package/src/plugin.tsx +8 -0
  65. package/src/pm-plugins/table-resizing/event-handlers.ts +43 -21
  66. package/src/pm-plugins/table-resizing/utils/index.ts +1 -1
  67. package/src/pm-plugins/table-resizing/utils/misc.ts +11 -0
  68. package/src/pm-plugins/table-resizing/utils/resize-column.ts +85 -65
  69. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +21 -8
  70. package/src/ui/FloatingContextualMenu/index.tsx +2 -0
  71. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -0
  72. package/src/ui/FloatingDragMenu/index.tsx +11 -1
  73. package/src/ui/FloatingInsertButton/index.tsx +38 -11
  74. package/src/utils/drag-menu.ts +17 -11
@@ -11,7 +11,7 @@ import { getPluginState as getTablePluginState } from '../plugin-factory';
11
11
  import { META_KEYS } from '../table-analytics';
12
12
  import { evenColumns, setDragging, stopResizing } from './commands';
13
13
  import { getPluginState } from './plugin-factory';
14
- import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, updateControls } from './utils';
14
+ import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
15
15
  export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI) => {
16
16
  const {
17
17
  state,
@@ -148,11 +148,14 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
148
148
  if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
149
149
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
150
150
  }
151
- const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale);
152
151
  const resizedDelta = clientX - startX;
153
- tr = updateColumnWidths(newResizeState, table, start)(tr);
154
152
  if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
153
+ const newResizeState = resizeColumnAndTable(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale);
154
+ tr = updateColumnWidths(newResizeState, table, start)(tr);
155
155
  tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
156
+ } else {
157
+ const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale);
158
+ tr = updateColumnWidths(newResizeState, table, start)(tr);
156
159
  }
157
160
  if (colIndex === map.width - 1) {
158
161
  const mouseUpTime = event.timeStamp;
@@ -228,7 +231,11 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
228
231
  if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
229
232
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
230
233
  }
231
- resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
234
+ if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
235
+ resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
236
+ } else {
237
+ resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
238
+ }
232
239
  updateControls()(state);
233
240
  }
234
241
  window.addEventListener('mouseup', finish);
@@ -6,5 +6,5 @@ export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bu
6
6
  export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth, getTableElementWidth, getTableContainerElementWidth } from './misc';
7
7
  export { updateControls, isClickNear, getResizeCellPos } from './dom';
8
8
  export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
9
- export { resizeColumn } from './resize-column';
9
+ export { resizeColumn, resizeColumnAndTable } from './resize-column';
10
10
  export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT } from './consts';
@@ -98,4 +98,11 @@ export const getTableScalingPercent = (table, tableRef) => {
98
98
  let scalePercent = (renderWidth - 1) / tableWidth;
99
99
  scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
100
100
  return Math.min(scalePercent, 1);
101
+ };
102
+ export const getStaticTableScalingPercent = (table, tableRenderWidth) => {
103
+ const tableWidth = getTableContainerElementWidth(table);
104
+ // minus 1 here to avoid any 1px scroll in Firefox
105
+ let scalePercent = (tableRenderWidth - 1) / tableWidth;
106
+ scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
107
+ return Math.min(scalePercent, 1);
101
108
  };
@@ -1,53 +1,68 @@
1
1
  // Resize a given column by an amount from the current state
2
2
 
3
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
3
  import { TableCssClassName as ClassName } from '../../../types';
5
4
  import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
6
5
  import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
7
6
  import { updateColgroup } from './resize-state';
8
7
  export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false) => {
9
- // If table resize to show overflowed content, we need to re calculate the resize amount because now offset = amount amount instead of amount * 2
10
8
  let scalePercent = 1;
11
- let resizeAmount;
12
- if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
13
- var _tableRef$closest;
14
- // when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
15
- const tableWidth = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth;
16
- const tableContainerWidth = tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
17
- const isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
18
- resizeAmount = amount * 2;
19
- if (isOverflowed) {
20
- resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
21
- } else {
22
- resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
23
- }
24
- } else {
25
- resizeAmount = amount;
26
- }
27
-
28
- // This need to be clean up if clean up the FF, we will not need this scale logic because now full table width changed/updated in resizeColumn
29
- if (isTableScalingEnabled && !getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
9
+ let resizeAmount = amount;
10
+ if (isTableScalingEnabled) {
30
11
  scalePercent = getTableScalingPercent(tableNode, tableRef);
31
12
  resizeAmount = amount / scalePercent;
32
13
  }
33
- const newState = getBooleanFF('platform.editor.table.colum-resizing-improvements') ? updateAffectedColumn(resizeState, colIndex, resizeAmount) : resizeAmount > 0 ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
34
- getBooleanFF('platform.editor.table.colum-resizing-improvements') ? updateColgroup(newState, tableRef, tableNode, false) : updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
35
- if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
36
- // use the difference in width from affected column to update overall table width
37
- const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
38
- updateTable(delta, tableRef, tableNode);
39
- return {
40
- ...newState,
41
- tableWidth: resizeState.tableWidth + delta
42
- };
43
- }
14
+ const newState = resizeAmount > 0 ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
15
+ updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
44
16
  return newState;
45
17
  };
46
- const updateTable = (resizeAmount, tableRef, tableNode) => {
18
+
19
+ // try not scale table during resize
20
+ export const resizeColumnAndTable = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false, originalTableWidth) => {
21
+ var _tableRef$closest;
22
+ // TODO: can we use document state, and apply scaling factor?
23
+ const tableWidth = tableRef.clientWidth;
24
+ const tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
25
+ const isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
26
+ let resizeAmount = amount * 2;
27
+
28
+ // todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
29
+ // let scalePercent = 1;
30
+ // if (isTableScalingEnabled) {
31
+ // import from ./misc
32
+ // scalePercent = getStaticTableScalingPercent(
33
+ // tableNode,
34
+ // originalTableWidth || resizeState.maxSize,
35
+ // );
36
+ // resizeAmount = amount / scalePercent;
37
+ // }
38
+
39
+ // need to look at the resize amount and try to adjust the colgroups
40
+ if (isOverflowed) {
41
+ resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
42
+ } else {
43
+ resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
44
+ }
45
+ const newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
46
+
47
+ // this function only updates the colgroup in DOM, it reverses the scalePercent
48
+ // todo: change isScalingEnabled to true when reimplementing scaling
49
+ updateColgroup(newState, tableRef, tableNode, false);
50
+
51
+ // use the difference in width from affected column to update overall table width
52
+ const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
53
+ if (!isOverflowed) {
54
+ updateTablePreview(delta, tableRef, tableNode);
55
+ }
56
+ return {
57
+ ...newState,
58
+ tableWidth: isOverflowed ? tableContainerWidth : resizeState.tableWidth + delta
59
+ };
60
+ };
61
+ const updateTablePreview = (resizeAmount, tableRef, tableNode) => {
47
62
  const currentWidth = getTableContainerElementWidth(tableNode);
48
63
  const resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
49
64
  const resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
50
- if (resizingContainer && resizingItem) {
65
+ if (resizingItem) {
51
66
  const newWidth = `${currentWidth + resizeAmount}px`;
52
67
  if (tableRef) {
53
68
  tableRef.style.width = newWidth;
@@ -399,7 +399,8 @@ export class ContextualMenu extends Component {
399
399
  editorView,
400
400
  selectionRect,
401
401
  editorAnalyticsAPI,
402
- getEditorContainerWidth
402
+ getEditorContainerWidth,
403
+ getEditorFeatureFlags
403
404
  } = this.props;
404
405
  // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
405
406
  const {
@@ -410,6 +411,9 @@ export class ContextualMenu extends Component {
410
411
  targetCellPosition,
411
412
  isTableScalingEnabled = false
412
413
  } = getPluginState(state);
414
+ const {
415
+ tableDuplicateCellColouring = false
416
+ } = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
413
417
  switch (item.value.name) {
414
418
  case 'sort_column_desc':
415
419
  sortColumnWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, selectionRect.left, SortOrder.DESC)(state, dispatch);
@@ -439,11 +443,11 @@ export class ContextualMenu extends Component {
439
443
  this.toggleOpen();
440
444
  break;
441
445
  case 'insert_column':
442
- insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(state, dispatch, editorView);
446
+ insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled, tableDuplicateCellColouring)(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(state, dispatch, editorView);
443
447
  this.toggleOpen();
444
448
  break;
445
449
  case 'insert_row':
446
- insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.CONTEXT_MENU, {
450
+ insertRowWithAnalytics(editorAnalyticsAPI, tableDuplicateCellColouring)(INPUT_METHOD.CONTEXT_MENU, {
447
451
  index: selectionRect.bottom,
448
452
  moveCursorToInsertedRow: true
449
453
  })(state, dispatch);
@@ -16,7 +16,8 @@ const FloatingContextualMenu = ({
16
16
  isOpen,
17
17
  pluginConfig,
18
18
  editorAnalyticsAPI,
19
- getEditorContainerWidth
19
+ getEditorContainerWidth,
20
+ getEditorFeatureFlags
20
21
  }) => {
21
22
  // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
22
23
  const {
@@ -68,7 +69,8 @@ const FloatingContextualMenu = ({
68
69
  selectionRect: selectionRect,
69
70
  boundariesElement: boundariesElement,
70
71
  editorAnalyticsAPI: editorAnalyticsAPI,
71
- getEditorContainerWidth: getEditorContainerWidth
72
+ getEditorContainerWidth: getEditorContainerWidth,
73
+ getEditorFeatureFlags: getEditorFeatureFlags
72
74
  })));
73
75
  };
74
76
  FloatingContextualMenu.displayName = 'FloatingContextualMenu';
@@ -176,7 +176,8 @@ export const DragMenu = /*#__PURE__*/React.memo(({
176
176
  mountPoint,
177
177
  scrollableElement,
178
178
  boundariesElement,
179
- isTableScalingEnabled
179
+ isTableScalingEnabled,
180
+ tableDuplicateCellColouring
180
181
  }) => {
181
182
  var _pluginConfig$allowBa;
182
183
  const {
@@ -204,7 +205,7 @@ export const DragMenu = /*#__PURE__*/React.memo(({
204
205
  hasMergedCellsInTable = getMergedCellsPositions(state.tr).length > 0;
205
206
  }
206
207
  const allowBackgroundColor = (_pluginConfig$allowBa = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.allowBackgroundColor) !== null && _pluginConfig$allowBa !== void 0 ? _pluginConfig$allowBa : false;
207
- const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.isHeaderRowRequired, isTableScalingEnabled);
208
+ const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.isHeaderRowRequired, isTableScalingEnabled, tableDuplicateCellColouring);
208
209
  const {
209
210
  menuItems,
210
211
  menuCallback
@@ -18,7 +18,8 @@ const FloatingDragMenu = ({
18
18
  editorAnalyticsAPI,
19
19
  stickyHeaders,
20
20
  pluginConfig,
21
- isTableScalingEnabled
21
+ isTableScalingEnabled,
22
+ getEditorFeatureFlags
22
23
  }) => {
23
24
  if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
24
25
  return null;
@@ -29,6 +30,9 @@ const FloatingDragMenu = ({
29
30
  if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
30
31
  return null;
31
32
  }
33
+ const {
34
+ tableDuplicateCellColouring = false
35
+ } = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
32
36
  return /*#__PURE__*/React.createElement(Popup, {
33
37
  alignX: direction === 'row' ? 'right' : undefined,
34
38
  alignY: direction === 'row' ? 'start' : undefined,
@@ -62,7 +66,8 @@ const FloatingDragMenu = ({
62
66
  mountPoint: mountPoint,
63
67
  boundariesElement: boundariesElement,
64
68
  scrollableElement: scrollableElement,
65
- isTableScalingEnabled: isTableScalingEnabled
69
+ isTableScalingEnabled: isTableScalingEnabled,
70
+ tableDuplicateCellColouring: tableDuplicateCellColouring
66
71
  }));
67
72
  };
68
73
  FloatingDragMenu.displayName = 'FloatingDragMenu';
@@ -156,7 +156,8 @@ export class FloatingInsertButton extends React.Component {
156
156
  const {
157
157
  editorView,
158
158
  insertRowButtonIndex,
159
- editorAnalyticsAPI
159
+ editorAnalyticsAPI,
160
+ getEditorFeatureFlags
160
161
  } = this.props;
161
162
  if (typeof insertRowButtonIndex !== 'undefined') {
162
163
  event.preventDefault();
@@ -164,7 +165,8 @@ export class FloatingInsertButton extends React.Component {
164
165
  state,
165
166
  dispatch
166
167
  } = editorView;
167
- insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.BUTTON, {
168
+ const featureFlags = !!getEditorFeatureFlags && getEditorFeatureFlags();
169
+ insertRowWithAnalytics(editorAnalyticsAPI, featureFlags && featureFlags.tableDuplicateCellColouring)(INPUT_METHOD.BUTTON, {
168
170
  index: insertRowButtonIndex,
169
171
  moveCursorToInsertedRow: true
170
172
  })(state, dispatch);
@@ -174,18 +176,22 @@ export class FloatingInsertButton extends React.Component {
174
176
  const {
175
177
  editorView,
176
178
  insertColumnButtonIndex,
177
- editorAnalyticsAPI
179
+ editorAnalyticsAPI,
180
+ getEditorFeatureFlags
178
181
  } = this.props;
179
182
  if (typeof insertColumnButtonIndex !== 'undefined') {
180
183
  event.preventDefault();
181
184
  const {
182
185
  isTableScalingEnabled = false
183
186
  } = getPluginState(editorView.state);
187
+ const {
188
+ tableDuplicateCellColouring = false
189
+ } = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
184
190
  const {
185
191
  state,
186
192
  dispatch
187
193
  } = editorView;
188
- insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(INPUT_METHOD.BUTTON, insertColumnButtonIndex)(state, dispatch, editorView);
194
+ insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled, tableDuplicateCellColouring)(INPUT_METHOD.BUTTON, insertColumnButtonIndex)(state, dispatch, editorView);
189
195
  }
190
196
  }
191
197
  }
@@ -65,7 +65,7 @@ const defaultSelectionRect = {
65
65
  right: 0,
66
66
  bottom: 0
67
67
  };
68
- export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, isHeaderRowRequired, isTableScalingEnabled = false) => {
68
+ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI, isHeaderRowRequired, isTableScalingEnabled = false, tableDuplicateCellColouring = false) => {
69
69
  var _tableMap$height, _tableMap$height2, _tableMap$width, _tableMap$width2;
70
70
  const addOptions = direction === 'row' ? [{
71
71
  label: 'above',
@@ -140,12 +140,12 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, h
140
140
  icon,
141
141
  onClick: (state, dispatch) => {
142
142
  if (direction === 'row') {
143
- insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, {
143
+ insertRowWithAnalytics(editorAnalyticsAPI, tableDuplicateCellColouring)(INPUT_METHOD.TABLE_CONTEXT_MENU, {
144
144
  index: (index !== null && index !== void 0 ? index : 0) + offset,
145
145
  moveCursorToInsertedRow: true
146
146
  })(state, dispatch);
147
147
  } else {
148
- insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(INPUT_METHOD.TABLE_CONTEXT_MENU, (index !== null && index !== void 0 ? index : 0) + offset)(state, dispatch, editorView);
148
+ insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled, tableDuplicateCellColouring)(INPUT_METHOD.TABLE_CONTEXT_MENU, (index !== null && index !== void 0 ? index : 0) + offset)(state, dispatch, editorView);
149
149
  }
150
150
  return true;
151
151
  },
@@ -21,6 +21,7 @@ function addColumnAtCustomStep(column) {
21
21
  }
22
22
  export function addColumnAt() {
23
23
  var isTableScalingEnabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
24
+ var isCellBackgroundDuplicated = arguments.length > 1 ? arguments[1] : undefined;
24
25
  return function (column) {
25
26
  var allowAddColumnCustomStep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
26
27
  var view = arguments.length > 2 ? arguments[2] : undefined;
@@ -29,7 +30,7 @@ export function addColumnAt() {
29
30
  if (allowAddColumnCustomStep) {
30
31
  updatedTr = addColumnAtCustomStep(column)(updatedTr);
31
32
  } else {
32
- updatedTr = addColumnAtPMUtils(column)(updatedTr);
33
+ updatedTr = addColumnAtPMUtils(column, isCellBackgroundDuplicated)(updatedTr);
33
34
  }
34
35
  var table = findTable(updatedTr.selection);
35
36
  if (table) {
@@ -83,9 +84,10 @@ export var addColumnAfter = function addColumnAfter(isTableScalingEnabled) {
83
84
  };
84
85
  export var insertColumn = function insertColumn() {
85
86
  var isTableScalingEnabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
87
+ var isCellBackgroundDuplicated = arguments.length > 1 ? arguments[1] : undefined;
86
88
  return function (column) {
87
89
  return function (state, dispatch, view) {
88
- var tr = addColumnAt(isTableScalingEnabled)(column, getAllowAddColumnCustomStep(state), view)(state.tr);
90
+ var tr = addColumnAt(isTableScalingEnabled, isCellBackgroundDuplicated)(column, getAllowAddColumnCustomStep(state), view)(state.tr);
89
91
  var table = findTable(tr.selection);
90
92
  if (!table) {
91
93
  return false;
@@ -99,7 +101,7 @@ export var insertColumn = function insertColumn() {
99
101
  };
100
102
  };
101
103
  };
102
- export var insertRow = function insertRow(row, moveCursorToTheNewRow) {
104
+ export var insertRow = function insertRow(row, moveCursorToTheNewRow, isCellBackgroundDuplicated) {
103
105
  return function (state, dispatch) {
104
106
  // Don't clone the header row
105
107
  var headerRowEnabled = checkIfHeaderRowEnabled(state.selection);
@@ -110,7 +112,7 @@ export var insertRow = function insertRow(row, moveCursorToTheNewRow) {
110
112
  if (row === 0 && headerRowEnabled) {
111
113
  return false;
112
114
  }
113
- var tr = clonePreviousRow ? copyPreviousRow(state.schema)(row)(state.tr) : addRowAt(row)(state.tr);
115
+ var tr = clonePreviousRow ? copyPreviousRow(state.schema)(row)(state.tr) : addRowAt(row, undefined, isCellBackgroundDuplicated)(state.tr);
114
116
  var table = findTable(tr.selection);
115
117
  if (!table) {
116
118
  return false;
@@ -165,6 +165,7 @@ export var addRowAroundSelection = function addRowAroundSelection(editorAnalytic
165
165
  };
166
166
  };
167
167
  export var insertRowWithAnalytics = function insertRowWithAnalytics(editorAnalyticsAPI) {
168
+ var isCellbackgroundDuplicated = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
168
169
  return function (inputMethod, options) {
169
170
  return withEditorAnalyticsAPI(function (state) {
170
171
  var _getSelectedTableInfo = getSelectedTableInfo(state.selection),
@@ -182,7 +183,7 @@ export var insertRowWithAnalytics = function insertRowWithAnalytics(editorAnalyt
182
183
  },
183
184
  eventType: EVENT_TYPE.TRACK
184
185
  };
185
- })(editorAnalyticsAPI)(insertRow(options.index, options.moveCursorToInsertedRow));
186
+ })(editorAnalyticsAPI)(insertRow(options.index, options.moveCursorToInsertedRow, isCellbackgroundDuplicated));
186
187
  };
187
188
  };
188
189
  export var changeColumnWidthByStepWithAnalytics = function changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI) {
@@ -219,6 +220,7 @@ export var changeColumnWidthByStepWithAnalytics = function changeColumnWidthBySt
219
220
  };
220
221
  export var insertColumnWithAnalytics = function insertColumnWithAnalytics(editorAnalyticsAPI) {
221
222
  var isTableScalingEnabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
223
+ var isCellbackgroundDuplicated = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
222
224
  return function (inputMethod, position) {
223
225
  return withEditorAnalyticsAPI(function (state) {
224
226
  var _getSelectedTableInfo3 = getSelectedTableInfo(state.selection),
@@ -236,7 +238,7 @@ export var insertColumnWithAnalytics = function insertColumnWithAnalytics(editor
236
238
  },
237
239
  eventType: EVENT_TYPE.TRACK
238
240
  };
239
- })(editorAnalyticsAPI)(insertColumn(isTableScalingEnabled)(position));
241
+ })(editorAnalyticsAPI)(insertColumn(isTableScalingEnabled, isCellbackgroundDuplicated)(position));
240
242
  };
241
243
  };
242
244
  export var deleteRowsWithAnalytics = function deleteRowsWithAnalytics(editorAnalyticsAPI) {
@@ -361,7 +361,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
361
361
  hasStickyHeaders: stickyHeader && stickyHeader.sticky,
362
362
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
363
363
  editorAnalyticsAPI: editorAnalyticsAPI,
364
- getEditorContainerWidth: defaultGetEditorContainerWidth
364
+ getEditorContainerWidth: defaultGetEditorContainerWidth,
365
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
365
366
  }), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/React.createElement(FloatingContextualMenu, {
366
367
  editorView: editorView,
367
368
  mountPoint: popupsMountPoint,
@@ -386,7 +387,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
386
387
  editorAnalyticsAPI: editorAnalyticsAPI,
387
388
  stickyHeaders: stickyHeader,
388
389
  pluginConfig: pluginConfig,
389
- isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled
390
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
391
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
390
392
  }), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
391
393
  editorView: editorView,
392
394
  selection: editorView.state.selection,
@@ -11,7 +11,7 @@ import { getPluginState as getTablePluginState } from '../plugin-factory';
11
11
  import { META_KEYS } from '../table-analytics';
12
12
  import { evenColumns, setDragging, stopResizing } from './commands';
13
13
  import { getPluginState } from './plugin-factory';
14
- import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, updateControls } from './utils';
14
+ import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
15
15
  export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI) {
16
16
  var state = view.state,
17
17
  dispatch = view.dispatch;
@@ -135,11 +135,14 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
135
135
  if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
136
136
  _shouldScale = _shouldScale && originalTable.attrs.displayMode !== 'fixed';
137
137
  }
138
- var newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
139
138
  var resizedDelta = clientX - startX;
140
- tr = updateColumnWidths(newResizeState, table, start)(tr);
141
139
  if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
140
+ var newResizeState = resizeColumnAndTable(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
141
+ tr = updateColumnWidths(newResizeState, table, start)(tr);
142
142
  tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
143
+ } else {
144
+ var _newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale);
145
+ tr = updateColumnWidths(_newResizeState, table, start)(tr);
143
146
  }
144
147
  if (colIndex === map.width - 1) {
145
148
  var mouseUpTime = event.timeStamp;
@@ -209,7 +212,11 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
209
212
  if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
210
213
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
211
214
  }
212
- resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
215
+ if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
216
+ resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
217
+ } else {
218
+ resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
219
+ }
213
220
  updateControls()(state);
214
221
  }
215
222
  window.addEventListener('mouseup', finish);
@@ -6,5 +6,5 @@ export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bu
6
6
  export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth, getTableElementWidth, getTableContainerElementWidth } from './misc';
7
7
  export { updateControls, isClickNear, getResizeCellPos } from './dom';
8
8
  export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
9
- export { resizeColumn } from './resize-column';
9
+ export { resizeColumn, resizeColumnAndTable } from './resize-column';
10
10
  export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT } from './consts';
@@ -98,4 +98,11 @@ export var getTableScalingPercent = function getTableScalingPercent(table, table
98
98
  var scalePercent = (renderWidth - 1) / tableWidth;
99
99
  scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
100
100
  return Math.min(scalePercent, 1);
101
+ };
102
+ export var getStaticTableScalingPercent = function getStaticTableScalingPercent(table, tableRenderWidth) {
103
+ var tableWidth = getTableContainerElementWidth(table);
104
+ // minus 1 here to avoid any 1px scroll in Firefox
105
+ var scalePercent = (tableRenderWidth - 1) / tableWidth;
106
+ scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
107
+ return Math.min(scalePercent, 1);
101
108
  };
@@ -3,54 +3,71 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  // Resize a given column by an amount from the current state
5
5
 
6
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
6
  import { TableCssClassName as ClassName } from '../../../types';
8
7
  import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
9
8
  import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
10
9
  import { updateColgroup } from './resize-state';
11
10
  export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
12
11
  var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
13
- // If table resize to show overflowed content, we need to re calculate the resize amount because now offset = amount amount instead of amount * 2
14
12
  var scalePercent = 1;
15
- var resizeAmount;
16
- if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
17
- var _tableRef$closest;
18
- // when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
19
- var tableWidth = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth;
20
- var tableContainerWidth = tableRef === null || tableRef === void 0 || (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
21
- var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
22
- resizeAmount = amount * 2;
23
- if (isOverflowed) {
24
- resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
25
- } else {
26
- resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
27
- }
28
- } else {
29
- resizeAmount = amount;
30
- }
31
-
32
- // This need to be clean up if clean up the FF, we will not need this scale logic because now full table width changed/updated in resizeColumn
33
- if (isTableScalingEnabled && !getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
13
+ var resizeAmount = amount;
14
+ if (isTableScalingEnabled) {
34
15
  scalePercent = getTableScalingPercent(tableNode, tableRef);
35
16
  resizeAmount = amount / scalePercent;
36
17
  }
37
- var newState = getBooleanFF('platform.editor.table.colum-resizing-improvements') ? updateAffectedColumn(resizeState, colIndex, resizeAmount) : resizeAmount > 0 ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
38
- getBooleanFF('platform.editor.table.colum-resizing-improvements') ? updateColgroup(newState, tableRef, tableNode, false) : updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
39
- if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
40
- // use the difference in width from affected column to update overall table width
41
- var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
42
- updateTable(delta, tableRef, tableNode);
43
- return _objectSpread(_objectSpread({}, newState), {}, {
44
- tableWidth: resizeState.tableWidth + delta
45
- });
46
- }
18
+ var newState = resizeAmount > 0 ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeAmount < 0 ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns) : resizeState;
19
+ updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
47
20
  return newState;
48
21
  };
49
- var updateTable = function updateTable(resizeAmount, tableRef, tableNode) {
22
+
23
+ // try not scale table during resize
24
+ export var resizeColumnAndTable = function resizeColumnAndTable(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
25
+ var _tableRef$closest;
26
+ var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
27
+ var originalTableWidth = arguments.length > 7 ? arguments[7] : undefined;
28
+ // TODO: can we use document state, and apply scaling factor?
29
+ var tableWidth = tableRef.clientWidth;
30
+ var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
31
+ var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
32
+ var resizeAmount = amount * 2;
33
+
34
+ // todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
35
+ // let scalePercent = 1;
36
+ // if (isTableScalingEnabled) {
37
+ // import from ./misc
38
+ // scalePercent = getStaticTableScalingPercent(
39
+ // tableNode,
40
+ // originalTableWidth || resizeState.maxSize,
41
+ // );
42
+ // resizeAmount = amount / scalePercent;
43
+ // }
44
+
45
+ // need to look at the resize amount and try to adjust the colgroups
46
+ if (isOverflowed) {
47
+ resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
48
+ } else {
49
+ resizeAmount = amount > 0 && tableContainerWidth ? resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2 : resizeAmount;
50
+ }
51
+ var newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
52
+
53
+ // this function only updates the colgroup in DOM, it reverses the scalePercent
54
+ // todo: change isScalingEnabled to true when reimplementing scaling
55
+ updateColgroup(newState, tableRef, tableNode, false);
56
+
57
+ // use the difference in width from affected column to update overall table width
58
+ var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
59
+ if (!isOverflowed) {
60
+ updateTablePreview(delta, tableRef, tableNode);
61
+ }
62
+ return _objectSpread(_objectSpread({}, newState), {}, {
63
+ tableWidth: isOverflowed ? tableContainerWidth : resizeState.tableWidth + delta
64
+ });
65
+ };
66
+ var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode) {
50
67
  var currentWidth = getTableContainerElementWidth(tableNode);
51
68
  var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
52
69
  var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
53
- if (resizingContainer && resizingItem) {
70
+ if (resizingItem) {
54
71
  var newWidth = "".concat(currentWidth + resizeAmount, "px");
55
72
  if (tableRef) {
56
73
  tableRef.style.width = newWidth;