@atlaskit/editor-plugin-table 7.21.4 → 7.21.6

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 (54) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/nodeviews/TableContainer.js +5 -2
  3. package/dist/cjs/nodeviews/TableResizer.js +9 -6
  4. package/dist/cjs/plugin.js +3 -3
  5. package/dist/cjs/pm-plugins/keymap.js +4 -6
  6. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +40 -12
  7. package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +5 -2
  8. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
  9. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +99 -51
  10. package/dist/cjs/pm-plugins/table-width.js +2 -2
  11. package/dist/cjs/utils/alignment.js +1 -1
  12. package/dist/es2019/nodeviews/TableContainer.js +6 -3
  13. package/dist/es2019/nodeviews/TableResizer.js +10 -7
  14. package/dist/es2019/plugin.js +3 -3
  15. package/dist/es2019/pm-plugins/keymap.js +4 -6
  16. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +41 -13
  17. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +4 -1
  18. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
  19. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +97 -48
  20. package/dist/es2019/pm-plugins/table-width.js +2 -2
  21. package/dist/es2019/utils/alignment.js +1 -1
  22. package/dist/esm/nodeviews/TableContainer.js +6 -3
  23. package/dist/esm/nodeviews/TableResizer.js +10 -7
  24. package/dist/esm/plugin.js +3 -3
  25. package/dist/esm/pm-plugins/keymap.js +4 -6
  26. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +40 -12
  27. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +4 -1
  28. package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
  29. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +99 -51
  30. package/dist/esm/pm-plugins/table-width.js +2 -2
  31. package/dist/esm/utils/alignment.js +1 -1
  32. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  33. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  34. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  35. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +23 -1
  36. package/dist/types/pm-plugins/table-width.d.ts +1 -1
  37. package/dist/types/utils/alignment.d.ts +1 -1
  38. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  39. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  40. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  41. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +23 -1
  42. package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -1
  43. package/dist/types-ts4.5/utils/alignment.d.ts +1 -1
  44. package/package.json +2 -5
  45. package/src/nodeviews/TableContainer.tsx +8 -4
  46. package/src/nodeviews/TableResizer.tsx +19 -3
  47. package/src/plugin.tsx +4 -2
  48. package/src/pm-plugins/keymap.ts +30 -32
  49. package/src/pm-plugins/table-resizing/event-handlers.ts +37 -25
  50. package/src/pm-plugins/table-resizing/utils/consts.ts +4 -0
  51. package/src/pm-plugins/table-resizing/utils/index.ts +1 -0
  52. package/src/pm-plugins/table-resizing/utils/resize-column.ts +142 -70
  53. package/src/pm-plugins/table-width.ts +2 -1
  54. package/src/utils/alignment.ts +8 -6
@@ -3,9 +3,10 @@ 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 { akEditorFullWidthLayoutWidth, akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
6
7
  import { TableCssClassName as ClassName } from '../../../types';
7
8
  import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
8
- import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
9
+ import { getTableScalingPercent } from './misc';
9
10
  import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
10
11
  import { updateColgroup } from './resize-state';
11
12
  export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
@@ -21,68 +22,115 @@ export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, t
21
22
  updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled, shouldUseIncreasedScalingPercent);
22
23
  return newState;
23
24
  };
25
+ export var resizeColumnAndTable = function resizeColumnAndTable(_ref) {
26
+ var resizeState = _ref.resizeState,
27
+ colIndex = _ref.colIndex,
28
+ amount = _ref.amount,
29
+ tableRef = _ref.tableRef,
30
+ tableNode = _ref.tableNode,
31
+ lineLength = _ref.lineLength,
32
+ editorWidth = _ref.width,
33
+ isTableAlignmentEnabled = _ref.isTableAlignmentEnabled;
34
+ var editorContainerWidth = getEditorContainerWidth(editorWidth);
35
+ var isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
36
+ var resizeAmount = isTableLeftAligned ? amount : amount * 2;
37
+ var willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
38
+ var willResizedTableStayInOverflow = resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
24
39
 
25
- // try not scale table during resize
26
- export var resizeColumnAndTable = function resizeColumnAndTable(resizeState, colIndex, amount, tableRef, tableNode, selectedColumns) {
27
- var _tableRef$closest;
28
- var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
29
- var originalTableWidth = arguments.length > 7 ? arguments[7] : undefined;
30
- var shouldUseIncreasedScalingPercent = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
31
- var lineLength = arguments.length > 9 ? arguments[9] : undefined;
32
- var isTableAlignmentEnabled = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false;
33
- // TODO: can we use document state, and apply scaling factor?
34
- var tableWidth = tableRef.clientWidth;
35
- var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
36
- var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
37
- var resizeAmount = tableNode.attrs.layout === ALIGN_START && !isOverflowed ? amount : amount * 2;
38
-
39
- // todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
40
- // let scalePercent = 1;
41
- // if (isTableScalingEnabled) {
42
- // import from ./misc
43
- // scalePercent = getStaticTableScalingPercent(
44
- // tableNode,
45
- // originalTableWidth || resizeState.maxSize,
46
- // );
47
- // resizeAmount = amount / scalePercent;
48
- // }
49
-
50
- // need to look at the resize amount and try to adjust the colgroups
51
- if (isOverflowed) {
52
- resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
40
+ // STEP 1: Update col width
41
+ if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
42
+ var _tableRef$closest;
43
+ var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
44
+ resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
45
+ }
46
+ if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
47
+ var diff = -(resizeState.tableWidth - resizeState.maxSize);
48
+ var rest = amount - diff;
49
+ var final = isTableLeftAligned ? diff + rest : diff + rest * 2;
50
+ resizeAmount = final;
53
51
  }
54
52
  var newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
55
53
 
56
- // this function only updates the colgroup in DOM, it reverses the scalePercent
57
- // todo: change isScalingEnabled to true when reimplementing scaling
58
- updateColgroup(newState, tableRef, tableNode, false, shouldUseIncreasedScalingPercent);
59
-
60
- // use the difference in width from affected column to update overall table width
54
+ // STEP 2: Update table container width
55
+ // columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
61
56
  var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
62
- if (!isOverflowed) {
63
- // If the table is aligned to the start and the table width is greater than the line length, we should change the alignment to center
64
- var shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.tableWidth + delta);
65
- shouldChangeAlignment ? updateTablePreview(delta, tableRef, tableNode, ALIGN_CENTER) : updateTablePreview(delta, tableRef, tableNode);
57
+ newState.maxSize = Math.round(resizeState.overflow ? willResizedTableStayInOverflow ?
58
+ // CASE 1A: table will stay in overflow
59
+ // do not grow the table because resize is happening in the overflow region
60
+ // and the overall table container needs to be retained
61
+ resizeState.maxSize :
62
+ // CASE 1B: table will no longer be in overflow, so adjust container width
63
+ // ensure the table is resized without any 'big jumps' by working out
64
+ // the difference between the new table width and the max size and adding the resize
65
+ resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
66
+ // CASE 2: table will hit editor edge
67
+ editorContainerWidth :
68
+ // CASE 3: table is being resized from a non-overflow state
69
+ resizeState.maxSize + delta);
70
+
71
+ // do not apply scaling logic because resize state is already scaled
72
+ updateColgroup(newState, tableRef, tableNode, false, false);
73
+ if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
74
+ updateTablePreview(tableRef, newState.maxSize, shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
66
75
  }
67
- return _objectSpread(_objectSpread({}, newState), {}, {
68
- // resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
69
- tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
70
- });
76
+ return newState;
71
77
  };
72
- var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode, tableAligment) {
73
- var currentWidth = getTableContainerElementWidth(tableNode);
74
- var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
78
+ var updateTablePreview = function updateTablePreview(tableRef, newTableWidth, shouldChangeAlignment) {
79
+ var resizingContainer = tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
75
80
  var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
76
81
  var alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
77
82
  if (resizingItem) {
78
- var newWidth = "".concat(currentWidth + resizeAmount, "px");
79
- if (tableRef) {
80
- tableRef.style.width = newWidth;
81
- }
83
+ var newWidth = "".concat(newTableWidth, "px");
82
84
  resizingContainer.style.width = newWidth;
83
85
  resizingItem.style.width = newWidth;
84
- if (tableAligment && alignmentContainer) {
85
- alignmentContainer.style.justifyContent = tableAligment;
86
+ if (shouldChangeAlignment && alignmentContainer) {
87
+ alignmentContainer.style.justifyContent = ALIGN_CENTER;
86
88
  }
87
89
  }
90
+ };
91
+ var getEditorContainerWidth = function getEditorContainerWidth(editorWidth) {
92
+ return Math.min(editorWidth - akEditorGutterPaddingDynamic() * 2, akEditorFullWidthLayoutWidth);
93
+ };
94
+
95
+ /**
96
+ * Apply a scaling factor to resize state
97
+ */
98
+ export var scaleResizeState = function scaleResizeState(_ref2) {
99
+ var resizeState = _ref2.resizeState,
100
+ tableRef = _ref2.tableRef,
101
+ tableNode = _ref2.tableNode,
102
+ editorWidth = _ref2.editorWidth;
103
+ // check if table is scaled, if not then avoid applying scaling values down
104
+ if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
105
+ return resizeState;
106
+ }
107
+ var scalePercent = getTableScalingPercent(tableNode, tableRef);
108
+ var cols = resizeState.cols.map(function (col) {
109
+ return _objectSpread(_objectSpread({}, col), {}, {
110
+ width: Math.round(Math.max(col.width * scalePercent, col.minWidth))
111
+ });
112
+ });
113
+ var scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
114
+ var calculatedTableWidth = cols.reduce(function (prev, curr) {
115
+ return prev + curr.width;
116
+ }, 0);
117
+
118
+ // using Math.round can cause the sum of col widths to be larger than the table width
119
+ // distribute the difference to the smallest column
120
+ if (calculatedTableWidth > scaledTableWidth) {
121
+ var diff = calculatedTableWidth - scaledTableWidth;
122
+ cols = cols.map(function (col) {
123
+ return col.width - diff >= col.minWidth ? _objectSpread(_objectSpread({}, col), {}, {
124
+ width: col.width - diff
125
+ }) : col;
126
+ });
127
+ }
128
+ return _objectSpread(_objectSpread({}, resizeState), {}, {
129
+ widths: cols.map(function (col) {
130
+ return col.width;
131
+ }),
132
+ tableWidth: scaledTableWidth,
133
+ maxSize: Math.round(resizeState.maxSize * scalePercent),
134
+ cols: cols
135
+ });
88
136
  };
@@ -19,7 +19,7 @@ import { findTable } from '@atlaskit/editor-tables/utils';
19
19
  import { ALIGN_START } from '../utils/alignment';
20
20
  import { TABLE_MAX_WIDTH } from './table-resizing/utils';
21
21
  export var pluginKey = new PluginKey('tableWidthPlugin');
22
- var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled) {
22
+ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled, isCommentEditor) {
23
23
  return new SafePlugin({
24
24
  key: pluginKey,
25
25
  state: {
@@ -116,7 +116,7 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
116
116
  }
117
117
  });
118
118
  }
119
- if (isReplaceDocumentOperation) {
119
+ if (isReplaceDocumentOperation && !isCommentEditor) {
120
120
  newState.doc.forEach(function (node, offset) {
121
121
  if (node.type === table) {
122
122
  var width = node.attrs.width;
@@ -14,5 +14,5 @@ export var normaliseAlignment = function normaliseAlignment(layout) {
14
14
  * We don't want to switch alignment in Full-width editor
15
15
  */
16
16
  export var shouldChangeAlignmentToCenterResized = function shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) {
17
- return isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH;
17
+ return Boolean(isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH);
18
18
  };
@@ -25,10 +25,11 @@ interface TableResizerProps {
25
25
  isWholeTableInDanger?: boolean;
26
26
  isFullWidthModeEnabled?: boolean;
27
27
  shouldUseIncreasedScalingPercent?: boolean;
28
+ isCommentEditor?: boolean;
28
29
  }
29
30
  export interface TableResizerImprovementProps extends TableResizerProps {
30
31
  onResizeStop?: () => void;
31
32
  onResizeStart?: () => void;
32
33
  }
33
- export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isTableAlignmentEnabled, isWholeTableInDanger, shouldUseIncreasedScalingPercent, pluginInjectionApi, isFullWidthModeEnabled, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
34
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isTableAlignmentEnabled, isWholeTableInDanger, shouldUseIncreasedScalingPercent, pluginInjectionApi, isFullWidthModeEnabled, isCommentEditor, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
34
35
  export {};
@@ -5,3 +5,4 @@ export declare const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
5
5
  export declare const MAX_SCALING_PERCENT = 0.3;
6
6
  export declare const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
7
7
  export declare const TABLE_EDITOR_MARGIN = 76;
8
+ export declare const TABLE_OFFSET_IN_COMMENT_EDITOR: number;
@@ -10,4 +10,4 @@ export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-t
10
10
  export type { ScaleOptions } from './scale-table';
11
11
  export type { ResizeState, ResizeStateWithAnalytics } from './types';
12
12
  export { resizeColumn, resizeColumnAndTable } from './resize-column';
13
- export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT, MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION, } from './consts';
13
+ export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT, MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION, TABLE_OFFSET_IN_COMMENT_EDITOR, } from './consts';
@@ -1,4 +1,26 @@
1
+ import { type EditorContainerWidth } from '@atlaskit/editor-common/types';
1
2
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
3
  import type { ResizeState } from './types';
3
4
  export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
4
- export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean, lineLength?: number, isTableAlignmentEnabled?: boolean) => ResizeState;
5
+ type ResizeInformation = {
6
+ resizeState: ResizeState;
7
+ colIndex: number;
8
+ amount: number;
9
+ };
10
+ type TableReferences = {
11
+ tableRef: HTMLElement;
12
+ tableNode: PmNode;
13
+ };
14
+ type TableResizingPluginOptions = {
15
+ isTableAlignmentEnabled?: boolean;
16
+ };
17
+ type ResizeColumnAndTable = ResizeInformation & TableResizingPluginOptions & TableReferences & EditorContainerWidth;
18
+ export declare const resizeColumnAndTable: ({ resizeState, colIndex, amount, tableRef, tableNode, lineLength, width: editorWidth, isTableAlignmentEnabled, }: ResizeColumnAndTable) => ResizeState;
19
+ /**
20
+ * Apply a scaling factor to resize state
21
+ */
22
+ export declare const scaleResizeState: ({ resizeState, tableRef, tableNode, editorWidth, }: TableReferences & {
23
+ resizeState: ResizeState;
24
+ editorWidth: number;
25
+ }) => ResizeState;
26
+ export {};
@@ -13,7 +13,7 @@ type TableWidthPluginState = {
13
13
  tableRef: HTMLTableElement | null;
14
14
  };
15
15
  export declare const pluginKey: PluginKey<TableWidthPluginState>;
16
- declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean, isTableAlignmentEnabled: boolean) => SafePlugin<{
16
+ declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean, isTableAlignmentEnabled: boolean, isCommentEditor: boolean) => SafePlugin<{
17
17
  resizing: boolean;
18
18
  tableLocalId: string;
19
19
  tableRef: null;
@@ -11,4 +11,4 @@ export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptio
11
11
  /**
12
12
  * We don't want to switch alignment in Full-width editor
13
13
  */
14
- export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean | 0 | undefined;
14
+ export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean;
@@ -25,10 +25,11 @@ interface TableResizerProps {
25
25
  isWholeTableInDanger?: boolean;
26
26
  isFullWidthModeEnabled?: boolean;
27
27
  shouldUseIncreasedScalingPercent?: boolean;
28
+ isCommentEditor?: boolean;
28
29
  }
29
30
  export interface TableResizerImprovementProps extends TableResizerProps {
30
31
  onResizeStop?: () => void;
31
32
  onResizeStart?: () => void;
32
33
  }
33
- export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isTableAlignmentEnabled, isWholeTableInDanger, shouldUseIncreasedScalingPercent, pluginInjectionApi, isFullWidthModeEnabled, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
34
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isTableAlignmentEnabled, isWholeTableInDanger, shouldUseIncreasedScalingPercent, pluginInjectionApi, isFullWidthModeEnabled, isCommentEditor, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
34
35
  export {};
@@ -5,3 +5,4 @@ export declare const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
5
5
  export declare const MAX_SCALING_PERCENT = 0.3;
6
6
  export declare const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
7
7
  export declare const TABLE_EDITOR_MARGIN = 76;
8
+ export declare const TABLE_OFFSET_IN_COMMENT_EDITOR: number;
@@ -10,4 +10,4 @@ export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-t
10
10
  export type { ScaleOptions } from './scale-table';
11
11
  export type { ResizeState, ResizeStateWithAnalytics } from './types';
12
12
  export { resizeColumn, resizeColumnAndTable } from './resize-column';
13
- export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT, MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION, } from './consts';
13
+ export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT, MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION, TABLE_OFFSET_IN_COMMENT_EDITOR, } from './consts';
@@ -1,4 +1,26 @@
1
+ import { type EditorContainerWidth } from '@atlaskit/editor-common/types';
1
2
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
3
  import type { ResizeState } from './types';
3
4
  export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
4
- export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean, lineLength?: number, isTableAlignmentEnabled?: boolean) => ResizeState;
5
+ type ResizeInformation = {
6
+ resizeState: ResizeState;
7
+ colIndex: number;
8
+ amount: number;
9
+ };
10
+ type TableReferences = {
11
+ tableRef: HTMLElement;
12
+ tableNode: PmNode;
13
+ };
14
+ type TableResizingPluginOptions = {
15
+ isTableAlignmentEnabled?: boolean;
16
+ };
17
+ type ResizeColumnAndTable = ResizeInformation & TableResizingPluginOptions & TableReferences & EditorContainerWidth;
18
+ export declare const resizeColumnAndTable: ({ resizeState, colIndex, amount, tableRef, tableNode, lineLength, width: editorWidth, isTableAlignmentEnabled, }: ResizeColumnAndTable) => ResizeState;
19
+ /**
20
+ * Apply a scaling factor to resize state
21
+ */
22
+ export declare const scaleResizeState: ({ resizeState, tableRef, tableNode, editorWidth, }: TableReferences & {
23
+ resizeState: ResizeState;
24
+ editorWidth: number;
25
+ }) => ResizeState;
26
+ export {};
@@ -13,7 +13,7 @@ type TableWidthPluginState = {
13
13
  tableRef: HTMLTableElement | null;
14
14
  };
15
15
  export declare const pluginKey: PluginKey<TableWidthPluginState>;
16
- declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean, isTableAlignmentEnabled: boolean) => SafePlugin<{
16
+ declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean, isTableAlignmentEnabled: boolean, isCommentEditor: boolean) => SafePlugin<{
17
17
  resizing: boolean;
18
18
  tableLocalId: string;
19
19
  tableRef: null;
@@ -11,4 +11,4 @@ export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptio
11
11
  /**
12
12
  * We don't want to switch alignment in Full-width editor
13
13
  */
14
- export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean | 0 | undefined;
14
+ export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.21.4",
3
+ "version": "7.21.6",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -31,7 +31,7 @@
31
31
  "@atlaskit/adf-schema": "^39.0.3",
32
32
  "@atlaskit/button": "^19.0.0",
33
33
  "@atlaskit/custom-steps": "^0.4.0",
34
- "@atlaskit/editor-common": "^86.4.0",
34
+ "@atlaskit/editor-common": "^86.5.0",
35
35
  "@atlaskit/editor-palette": "1.6.0",
36
36
  "@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^1.4.0",
@@ -105,9 +105,6 @@
105
105
  "platform_editor_lazy-node-views": {
106
106
  "type": "boolean"
107
107
  },
108
- "platform.editor.a11y-help-dialog-shortcut-keys-position_aghfg": {
109
- "type": "boolean"
110
- },
111
108
  "platform.editor.transform-slice-for-nested-expand": {
112
109
  "type": "boolean"
113
110
  },
@@ -21,7 +21,10 @@ import {
21
21
  } from '@atlaskit/editor-shared-styles';
22
22
 
23
23
  import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../commands-with-analytics';
24
- import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
24
+ import {
25
+ TABLE_MAX_WIDTH,
26
+ TABLE_OFFSET_IN_COMMENT_EDITOR,
27
+ } from '../pm-plugins/table-resizing/utils';
25
28
  import type { PluginInjectionAPI, TableSharedState } from '../types';
26
29
  import { TableCssClassName as ClassName } from '../types';
27
30
  import { ALIGN_CENTER, ALIGN_START } from '../utils/alignment';
@@ -291,6 +294,8 @@ export const ResizableTableContainer = React.memo(
291
294
  responsiveContainerWidth = isTableScalingEnabled
292
295
  ? lineLength
293
296
  : containerWidth - akEditorGutterPaddingDynamic() * 2 - resizeHandleSpacing;
297
+ } else if (isCommentEditor) {
298
+ responsiveContainerWidth = containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR;
294
299
  } else {
295
300
  // 76 is currently an accepted padding value considering the spacing for resizer handle
296
301
  // containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
@@ -298,9 +303,7 @@ export const ResizableTableContainer = React.memo(
298
303
  // padding left = padding right = akEditorGutterPadding = 32
299
304
  responsiveContainerWidth = isTableScalingEnabled
300
305
  ? containerWidth - akEditorGutterPaddingDynamic() * 2
301
- : containerWidth -
302
- akEditorGutterPaddingDynamic() * 2 -
303
- (isCommentEditor ? 0 : resizeHandleSpacing);
306
+ : containerWidth - akEditorGutterPaddingDynamic() * 2 - resizeHandleSpacing;
304
307
  }
305
308
  let width =
306
309
  !node.attrs.width && isCommentEditor
@@ -336,6 +339,7 @@ export const ResizableTableContainer = React.memo(
336
339
  pluginInjectionApi,
337
340
  onResizeStart,
338
341
  onResizeStop,
342
+ isCommentEditor,
339
343
  };
340
344
 
341
345
  const isLivePageViewMode = editorViewModeState?.mode === 'view';
@@ -36,6 +36,7 @@ import {
36
36
  previewScaleTable,
37
37
  scaleTable,
38
38
  TABLE_MAX_WIDTH,
39
+ TABLE_OFFSET_IN_COMMENT_EDITOR,
39
40
  } from '../pm-plugins/table-resizing/utils';
40
41
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
41
42
  import type { PluginInjectionAPI, TableSharedStateInternal } from '../types';
@@ -88,6 +89,7 @@ interface TableResizerProps {
88
89
  isWholeTableInDanger?: boolean;
89
90
  isFullWidthModeEnabled?: boolean;
90
91
  shouldUseIncreasedScalingPercent?: boolean;
92
+ isCommentEditor?: boolean;
91
93
  }
92
94
 
93
95
  export interface TableResizerImprovementProps extends TableResizerProps {
@@ -203,6 +205,7 @@ export const TableResizer = ({
203
205
  shouldUseIncreasedScalingPercent,
204
206
  pluginInjectionApi,
205
207
  isFullWidthModeEnabled,
208
+ isCommentEditor,
206
209
  }: PropsWithChildren<TableResizerImprovementProps>) => {
207
210
  const currentGap = useRef(0);
208
211
  // track resizing state - use ref over state to avoid re-render
@@ -486,7 +489,12 @@ export const TableResizer = ({
486
489
  ).filter((guideline) => guideline.isFullWidth)[0];
487
490
 
488
491
  const isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
489
- const shouldUpdateWidthToWidest = !!isTableScalingEnabled && isFullWidthGuidelineActive;
492
+ const tableMaxWidth = isCommentEditor
493
+ ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR
494
+ : TABLE_MAX_WIDTH;
495
+ const shouldUpdateWidthToWidest =
496
+ (isCommentEditor && tableMaxWidth === newWidth) ||
497
+ (!!isTableScalingEnabled && isFullWidthGuidelineActive);
490
498
 
491
499
  chainCommands(
492
500
  (state, dispatch) => {
@@ -497,12 +505,13 @@ export const TableResizer = ({
497
505
  }),
498
506
  )(state, dispatch);
499
507
 
500
- updateWidth(shouldUpdateWidthToWidest ? TABLE_MAX_WIDTH : newWidth);
508
+ updateWidth(shouldUpdateWidthToWidest ? tableMaxWidth : newWidth);
501
509
 
502
510
  return newWidth;
503
511
  },
504
512
  [
505
513
  countFrames,
514
+ isCommentEditor,
506
515
  isTableScalingEnabled,
507
516
  isTableWithFixedColumnWidthsOptionEnabled,
508
517
  isFullWidthModeEnabled,
@@ -528,9 +537,14 @@ export const TableResizer = ({
528
537
  const { state, dispatch } = editorView;
529
538
  const pos = getPos();
530
539
  const currentTableNodeLocalId = node?.attrs?.localId ?? '';
540
+
541
+ const tableMaxWidth = isCommentEditor
542
+ ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR
543
+ : TABLE_MAX_WIDTH;
544
+
531
545
  newWidth =
532
546
  widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId]
533
- ? TABLE_MAX_WIDTH
547
+ ? tableMaxWidth
534
548
  : newWidth;
535
549
 
536
550
  let tr = state.tr.setMeta(tableWidthPluginKey, {
@@ -618,6 +632,7 @@ export const TableResizer = ({
618
632
  tableRef,
619
633
  scheduleResize,
620
634
  displayGuideline,
635
+ containerWidth,
621
636
  attachAnalyticsEvent,
622
637
  endMeasure,
623
638
  onResizeStop,
@@ -626,6 +641,7 @@ export const TableResizer = ({
626
641
  widthToWidest,
627
642
  formatMessage,
628
643
  pluginInjectionApi,
644
+ isCommentEditor,
629
645
  ],
630
646
  );
631
647
 
package/src/plugin.tsx CHANGED
@@ -472,13 +472,14 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
472
472
  {
473
473
  name: 'tableWidth',
474
474
  plugin: ({ dispatchAnalyticsEvent, dispatch }) =>
475
- options?.tableResizingEnabled && !options?.isCommentEditor
475
+ options?.tableResizingEnabled
476
476
  ? createTableWidthPlugin(
477
477
  dispatch,
478
478
  dispatchAnalyticsEvent,
479
479
  options?.fullWidthEnabled ?? false,
480
480
  options?.isTableScalingEnabled ?? false,
481
481
  options?.isTableAlignmentEnabled ?? false,
482
+ options?.isCommentEditor ?? false,
482
483
  )
483
484
  : undefined,
484
485
  },
@@ -683,7 +684,8 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
683
684
  editorAnalyticsAPI={editorAnalyticsAPI}
684
685
  />
685
686
  )}
686
- {options?.isTableScalingEnabled &&
687
+ {(options?.isTableScalingEnabled ||
688
+ (options?.tableResizingEnabled && options.isCommentEditor)) &&
687
689
  isTableResizing &&
688
690
  widthToWidest &&
689
691
  resizingTableLocalId &&
@@ -143,41 +143,39 @@ export function keymapPlugin(
143
143
  list,
144
144
  );
145
145
 
146
- if (fg('platform.editor.a11y-help-dialog-shortcut-keys-position_aghfg')) {
147
- bindKeymapWithCommand(
148
- addRowBeforeVO.common!,
149
- addRowAroundSelection(editorAnalyticsAPI)('TOP'),
150
- list,
151
- );
146
+ bindKeymapWithCommand(
147
+ addRowBeforeVO.common!,
148
+ addRowAroundSelection(editorAnalyticsAPI)('TOP'),
149
+ list,
150
+ );
152
151
 
153
- bindKeymapWithCommand(
154
- addRowAfterVO.common!,
155
- addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'),
156
- list,
157
- );
152
+ bindKeymapWithCommand(
153
+ addRowAfterVO.common!,
154
+ addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'),
155
+ list,
156
+ );
158
157
 
159
- bindKeymapWithCommand(
160
- addColumnBeforeVO.common!,
161
- addColumnBeforeCommand(
162
- isTableScalingEnabled,
163
- isCellBackgroundDuplicated,
164
- isTableFixedColumnWidthsOptionEnabled,
165
- shouldUseIncreasedScalingPercent,
166
- ),
167
- list,
168
- );
158
+ bindKeymapWithCommand(
159
+ addColumnBeforeVO.common!,
160
+ addColumnBeforeCommand(
161
+ isTableScalingEnabled,
162
+ isCellBackgroundDuplicated,
163
+ isTableFixedColumnWidthsOptionEnabled,
164
+ shouldUseIncreasedScalingPercent,
165
+ ),
166
+ list,
167
+ );
169
168
 
170
- bindKeymapWithCommand(
171
- addColumnAfterVO.common!,
172
- addColumnAfterCommand(
173
- isTableScalingEnabled,
174
- isCellBackgroundDuplicated,
175
- isTableFixedColumnWidthsOptionEnabled,
176
- shouldUseIncreasedScalingPercent,
177
- ),
178
- list,
179
- );
180
- }
169
+ bindKeymapWithCommand(
170
+ addColumnAfterVO.common!,
171
+ addColumnAfterCommand(
172
+ isTableScalingEnabled,
173
+ isCellBackgroundDuplicated,
174
+ isTableFixedColumnWidthsOptionEnabled,
175
+ shouldUseIncreasedScalingPercent,
176
+ ),
177
+ list,
178
+ );
181
179
 
182
180
  if (dragAndDropEnabled) {
183
181
  // Move row/column shortcuts