@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.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/nodeviews/TableContainer.js +5 -2
- package/dist/cjs/nodeviews/TableResizer.js +9 -6
- package/dist/cjs/plugin.js +3 -3
- package/dist/cjs/pm-plugins/keymap.js +4 -6
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +40 -12
- package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +5 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +99 -51
- package/dist/cjs/pm-plugins/table-width.js +2 -2
- package/dist/cjs/utils/alignment.js +1 -1
- package/dist/es2019/nodeviews/TableContainer.js +6 -3
- package/dist/es2019/nodeviews/TableResizer.js +10 -7
- package/dist/es2019/plugin.js +3 -3
- package/dist/es2019/pm-plugins/keymap.js +4 -6
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +41 -13
- package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +4 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +97 -48
- package/dist/es2019/pm-plugins/table-width.js +2 -2
- package/dist/es2019/utils/alignment.js +1 -1
- package/dist/esm/nodeviews/TableContainer.js +6 -3
- package/dist/esm/nodeviews/TableResizer.js +10 -7
- package/dist/esm/plugin.js +3 -3
- package/dist/esm/pm-plugins/keymap.js +4 -6
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +40 -12
- package/dist/esm/pm-plugins/table-resizing/utils/consts.js +4 -1
- package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +99 -51
- package/dist/esm/pm-plugins/table-width.js +2 -2
- package/dist/esm/utils/alignment.js +1 -1
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +23 -1
- package/dist/types/pm-plugins/table-width.d.ts +1 -1
- package/dist/types/utils/alignment.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +23 -1
- package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -1
- package/dist/types-ts4.5/utils/alignment.d.ts +1 -1
- package/package.json +2 -5
- package/src/nodeviews/TableContainer.tsx +8 -4
- package/src/nodeviews/TableResizer.tsx +19 -3
- package/src/plugin.tsx +4 -2
- package/src/pm-plugins/keymap.ts +30 -32
- package/src/pm-plugins/table-resizing/event-handlers.ts +37 -25
- package/src/pm-plugins/table-resizing/utils/consts.ts +4 -0
- package/src/pm-plugins/table-resizing/utils/index.ts +1 -0
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +142 -70
- package/src/pm-plugins/table-width.ts +2 -1
- package/src/utils/alignment.ts +8 -6
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
resizeColumnAndTable,
|
|
39
39
|
updateControls,
|
|
40
40
|
} from './utils';
|
|
41
|
+
import { scaleResizeState } from './utils/resize-column';
|
|
41
42
|
|
|
42
43
|
export const handleMouseDown = (
|
|
43
44
|
view: EditorView,
|
|
@@ -53,7 +54,7 @@ export const handleMouseDown = (
|
|
|
53
54
|
const { state, dispatch } = view;
|
|
54
55
|
const editorDisabled = !view.editable;
|
|
55
56
|
const domAtPos = view.domAtPos.bind(view);
|
|
56
|
-
const { lineLength } = getEditorContainerWidth();
|
|
57
|
+
const { lineLength, width: editorWidth } = getEditorContainerWidth();
|
|
57
58
|
|
|
58
59
|
if (
|
|
59
60
|
editorDisabled ||
|
|
@@ -102,7 +103,7 @@ export const handleMouseDown = (
|
|
|
102
103
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
let resizeState = getResizeState({
|
|
106
107
|
minWidth: tableCellMinWidth,
|
|
107
108
|
maxSize,
|
|
108
109
|
table: originalTable,
|
|
@@ -135,6 +136,17 @@ export const handleMouseDown = (
|
|
|
135
136
|
// unnecessary tooltips being displayed during drag.
|
|
136
137
|
updateResizeHandleDecorations(undefined, undefined, false)(state, dispatch);
|
|
137
138
|
|
|
139
|
+
// for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
|
|
140
|
+
// implication: the scaled version of the table becomes the source of truth
|
|
141
|
+
if (isNewColumnResizingEnabled && shouldScale) {
|
|
142
|
+
resizeState = scaleResizeState({
|
|
143
|
+
resizeState,
|
|
144
|
+
tableRef: dom,
|
|
145
|
+
tableNode: originalTable,
|
|
146
|
+
editorWidth,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
138
150
|
function finish(event: MouseEvent) {
|
|
139
151
|
window.removeEventListener('mouseup', finish);
|
|
140
152
|
window.removeEventListener('mousemove', move);
|
|
@@ -201,20 +213,19 @@ export const handleMouseDown = (
|
|
|
201
213
|
const shouldUseIncreasedScalingPercent =
|
|
202
214
|
isTableScalingWithFixedColumnWidthsOptionEnabled &&
|
|
203
215
|
fg('platform.editor.table.use-increased-scaling-percent');
|
|
216
|
+
|
|
204
217
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
205
|
-
const newResizeState = resizeColumnAndTable(
|
|
218
|
+
const newResizeState = resizeColumnAndTable({
|
|
206
219
|
resizeState,
|
|
207
220
|
colIndex,
|
|
208
|
-
resizedDelta,
|
|
209
|
-
dom,
|
|
210
|
-
originalTable,
|
|
211
|
-
|
|
212
|
-
shouldScale, // isTableScalingEnabled
|
|
213
|
-
undefined, // originalTableWidth
|
|
214
|
-
shouldUseIncreasedScalingPercent,
|
|
221
|
+
amount: resizedDelta,
|
|
222
|
+
tableRef: dom,
|
|
223
|
+
tableNode: originalTable,
|
|
224
|
+
width: editorWidth,
|
|
215
225
|
lineLength,
|
|
216
226
|
isTableAlignmentEnabled,
|
|
217
|
-
);
|
|
227
|
+
});
|
|
228
|
+
|
|
218
229
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
219
230
|
|
|
220
231
|
// 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
|
|
@@ -222,12 +233,13 @@ export const handleMouseDown = (
|
|
|
222
233
|
isTableAlignmentEnabled,
|
|
223
234
|
originalTable,
|
|
224
235
|
lineLength,
|
|
225
|
-
newResizeState.
|
|
236
|
+
newResizeState.maxSize,
|
|
226
237
|
);
|
|
238
|
+
|
|
227
239
|
if (shouldChangeAlignment) {
|
|
228
240
|
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, {
|
|
229
241
|
...table.attrs,
|
|
230
|
-
width: newResizeState.
|
|
242
|
+
width: newResizeState.maxSize,
|
|
231
243
|
layout: ALIGN_CENTER,
|
|
232
244
|
});
|
|
233
245
|
|
|
@@ -236,7 +248,7 @@ export const handleMouseDown = (
|
|
|
236
248
|
actionSubject: ACTION_SUBJECT.TABLE,
|
|
237
249
|
actionSubjectId: null,
|
|
238
250
|
attributes: {
|
|
239
|
-
tableWidth: newResizeState.
|
|
251
|
+
tableWidth: newResizeState.maxSize,
|
|
240
252
|
newAlignment: ALIGN_CENTER,
|
|
241
253
|
previousAlignment: ALIGN_START,
|
|
242
254
|
totalRowCount: totalRowCount,
|
|
@@ -247,7 +259,7 @@ export const handleMouseDown = (
|
|
|
247
259
|
eventType: EVENT_TYPE.TRACK,
|
|
248
260
|
})(tr);
|
|
249
261
|
} else {
|
|
250
|
-
tr.setNodeAttribute(start - 1, 'width', newResizeState.
|
|
262
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.maxSize);
|
|
251
263
|
}
|
|
252
264
|
} else {
|
|
253
265
|
const newResizeState = resizeColumn(
|
|
@@ -335,29 +347,29 @@ export const handleMouseDown = (
|
|
|
335
347
|
const shouldUseIncreasedScalingPercent =
|
|
336
348
|
isTableScalingWithFixedColumnWidthsOptionEnabled &&
|
|
337
349
|
fg('platform.editor.table.use-increased-scaling-percent');
|
|
350
|
+
|
|
338
351
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
339
352
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
340
353
|
}
|
|
341
354
|
|
|
355
|
+
const resizedDelta = clientX - dragging.startX;
|
|
356
|
+
|
|
342
357
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
343
|
-
resizeColumnAndTable(
|
|
358
|
+
resizeColumnAndTable({
|
|
344
359
|
resizeState,
|
|
345
360
|
colIndex,
|
|
346
|
-
|
|
347
|
-
dom,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
shouldScale,
|
|
351
|
-
undefined,
|
|
352
|
-
shouldUseIncreasedScalingPercent,
|
|
361
|
+
amount: resizedDelta,
|
|
362
|
+
tableRef: dom,
|
|
363
|
+
tableNode: originalTable,
|
|
364
|
+
width: editorWidth,
|
|
353
365
|
lineLength,
|
|
354
366
|
isTableAlignmentEnabled,
|
|
355
|
-
);
|
|
367
|
+
});
|
|
356
368
|
} else {
|
|
357
369
|
resizeColumn(
|
|
358
370
|
resizeState,
|
|
359
371
|
colIndex,
|
|
360
|
-
|
|
372
|
+
resizedDelta,
|
|
361
373
|
dom,
|
|
362
374
|
table,
|
|
363
375
|
undefined,
|
|
@@ -6,3 +6,7 @@ export const MAX_SCALING_PERCENT = 0.3;
|
|
|
6
6
|
export const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
7
7
|
// Used to calculate the width of a table using the Editor width
|
|
8
8
|
export const TABLE_EDITOR_MARGIN = 76;
|
|
9
|
+
const COMMENT_AK_EDITOR_CONTENT_AREA_PADDING = 20;
|
|
10
|
+
const COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN = 12;
|
|
11
|
+
export const TABLE_OFFSET_IN_COMMENT_EDITOR =
|
|
12
|
+
2 * (COMMENT_AK_EDITOR_CONTENT_AREA_PADDING + COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN);
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
|
+
import { type EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
import {
|
|
5
|
+
akEditorFullWidthLayoutWidth,
|
|
6
|
+
akEditorGutterPaddingDynamic,
|
|
7
|
+
} from '@atlaskit/editor-shared-styles';
|
|
3
8
|
|
|
4
|
-
import {
|
|
9
|
+
import { TableCssClassName as ClassName } from '../../../types';
|
|
5
10
|
import {
|
|
6
11
|
ALIGN_CENTER,
|
|
7
12
|
ALIGN_START,
|
|
8
13
|
shouldChangeAlignmentToCenterResized,
|
|
9
14
|
} from '../../../utils/alignment';
|
|
10
15
|
|
|
11
|
-
import {
|
|
16
|
+
import { getTableScalingPercent } from './misc';
|
|
12
17
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
13
18
|
import { updateColgroup } from './resize-state';
|
|
14
19
|
import type { ResizeState } from './types';
|
|
@@ -49,97 +54,164 @@ export const resizeColumn = (
|
|
|
49
54
|
return newState;
|
|
50
55
|
};
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
isTableAlignmentEnabled
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
57
|
+
type ResizeInformation = {
|
|
58
|
+
resizeState: ResizeState;
|
|
59
|
+
colIndex: number;
|
|
60
|
+
amount: number;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type TableReferences = {
|
|
64
|
+
tableRef: HTMLElement;
|
|
65
|
+
tableNode: PmNode;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type TableResizingPluginOptions = {
|
|
69
|
+
isTableAlignmentEnabled?: boolean;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type ResizeColumnAndTable = ResizeInformation &
|
|
73
|
+
TableResizingPluginOptions &
|
|
74
|
+
TableReferences &
|
|
75
|
+
EditorContainerWidth;
|
|
76
|
+
|
|
77
|
+
export const resizeColumnAndTable = ({
|
|
78
|
+
resizeState,
|
|
79
|
+
colIndex,
|
|
80
|
+
amount,
|
|
81
|
+
tableRef,
|
|
82
|
+
tableNode,
|
|
83
|
+
lineLength,
|
|
84
|
+
width: editorWidth,
|
|
85
|
+
isTableAlignmentEnabled,
|
|
86
|
+
}: ResizeColumnAndTable): ResizeState => {
|
|
87
|
+
const editorContainerWidth = getEditorContainerWidth(editorWidth);
|
|
88
|
+
const isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
|
|
89
|
+
let resizeAmount = isTableLeftAligned ? amount : amount * 2;
|
|
90
|
+
|
|
91
|
+
const willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
|
|
92
|
+
|
|
93
|
+
const willResizedTableStayInOverflow =
|
|
94
|
+
resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
|
|
95
|
+
|
|
96
|
+
// STEP 1: Update col width
|
|
97
|
+
if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
|
|
98
|
+
const tableContainerWidth = tableRef.closest('.pm-table-container')?.clientWidth;
|
|
86
99
|
resizeAmount =
|
|
87
100
|
amount < 0
|
|
88
101
|
? amount
|
|
89
|
-
: resizeAmount - (
|
|
102
|
+
: resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth!) / 2;
|
|
90
103
|
}
|
|
91
104
|
|
|
92
|
-
|
|
105
|
+
if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
|
|
106
|
+
const diff = -(resizeState.tableWidth - resizeState.maxSize);
|
|
107
|
+
const rest = amount - diff;
|
|
108
|
+
const final = isTableLeftAligned ? diff + rest : diff + rest * 2;
|
|
109
|
+
resizeAmount = final;
|
|
110
|
+
}
|
|
93
111
|
|
|
94
|
-
|
|
95
|
-
// todo: change isScalingEnabled to true when reimplementing scaling
|
|
96
|
-
updateColgroup(newState, tableRef, tableNode, false, shouldUseIncreasedScalingPercent);
|
|
112
|
+
let newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
97
113
|
|
|
98
|
-
//
|
|
114
|
+
// STEP 2: Update table container width
|
|
115
|
+
// columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
|
|
99
116
|
const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
100
117
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
newState.maxSize = Math.round(
|
|
119
|
+
resizeState.overflow
|
|
120
|
+
? willResizedTableStayInOverflow
|
|
121
|
+
? // CASE 1A: table will stay in overflow
|
|
122
|
+
// do not grow the table because resize is happening in the overflow region
|
|
123
|
+
// and the overall table container needs to be retained
|
|
124
|
+
resizeState.maxSize
|
|
125
|
+
: // CASE 1B: table will no longer be in overflow, so adjust container width
|
|
126
|
+
// ensure the table is resized without any 'big jumps' by working out
|
|
127
|
+
// the difference between the new table width and the max size and adding the resize
|
|
128
|
+
resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta)
|
|
129
|
+
: willTableHitEditorEdge
|
|
130
|
+
? // CASE 2: table will hit editor edge
|
|
131
|
+
editorContainerWidth
|
|
132
|
+
: // CASE 3: table is being resized from a non-overflow state
|
|
133
|
+
resizeState.maxSize + delta,
|
|
134
|
+
);
|
|
109
135
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
136
|
+
// do not apply scaling logic because resize state is already scaled
|
|
137
|
+
updateColgroup(newState, tableRef, tableNode, false, false);
|
|
138
|
+
|
|
139
|
+
if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
|
|
140
|
+
updateTablePreview(
|
|
141
|
+
tableRef,
|
|
142
|
+
newState.maxSize,
|
|
143
|
+
shouldChangeAlignmentToCenterResized(
|
|
144
|
+
isTableAlignmentEnabled,
|
|
145
|
+
tableNode,
|
|
146
|
+
lineLength,
|
|
147
|
+
newState.maxSize,
|
|
148
|
+
),
|
|
149
|
+
);
|
|
113
150
|
}
|
|
114
151
|
|
|
115
|
-
return
|
|
116
|
-
...newState,
|
|
117
|
-
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
118
|
-
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta,
|
|
119
|
-
};
|
|
152
|
+
return newState;
|
|
120
153
|
};
|
|
121
154
|
|
|
122
155
|
const updateTablePreview = (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
tableAligment?: AlignmentOptions,
|
|
156
|
+
tableRef: HTMLElement,
|
|
157
|
+
newTableWidth: number,
|
|
158
|
+
shouldChangeAlignment?: boolean,
|
|
127
159
|
) => {
|
|
128
|
-
const
|
|
129
|
-
const resizingContainer = tableRef?.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
160
|
+
const resizingContainer = tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
130
161
|
const resizingItem = resizingContainer?.querySelector('.resizer-item');
|
|
131
162
|
const alignmentContainer = resizingContainer?.parentElement;
|
|
132
163
|
|
|
133
164
|
if (resizingItem) {
|
|
134
|
-
const newWidth = `${
|
|
135
|
-
if (tableRef) {
|
|
136
|
-
tableRef.style.width = newWidth;
|
|
137
|
-
}
|
|
165
|
+
const newWidth = `${newTableWidth}px`;
|
|
138
166
|
(resizingContainer as HTMLElement).style.width = newWidth;
|
|
139
167
|
(resizingItem as HTMLElement).style.width = newWidth;
|
|
140
168
|
|
|
141
|
-
if (
|
|
142
|
-
alignmentContainer.style.justifyContent =
|
|
169
|
+
if (shouldChangeAlignment && alignmentContainer) {
|
|
170
|
+
alignmentContainer.style.justifyContent = ALIGN_CENTER;
|
|
143
171
|
}
|
|
144
172
|
}
|
|
145
173
|
};
|
|
174
|
+
|
|
175
|
+
const getEditorContainerWidth = (editorWidth: number) =>
|
|
176
|
+
Math.min(editorWidth - akEditorGutterPaddingDynamic() * 2, akEditorFullWidthLayoutWidth);
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Apply a scaling factor to resize state
|
|
180
|
+
*/
|
|
181
|
+
export const scaleResizeState = ({
|
|
182
|
+
resizeState,
|
|
183
|
+
tableRef,
|
|
184
|
+
tableNode,
|
|
185
|
+
editorWidth,
|
|
186
|
+
}: TableReferences & { resizeState: ResizeState; editorWidth: number }): ResizeState => {
|
|
187
|
+
// check if table is scaled, if not then avoid applying scaling values down
|
|
188
|
+
if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
|
|
189
|
+
return resizeState;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
193
|
+
let cols = resizeState.cols.map((col) => ({
|
|
194
|
+
...col,
|
|
195
|
+
width: Math.round(Math.max(col.width * scalePercent, col.minWidth)),
|
|
196
|
+
}));
|
|
197
|
+
|
|
198
|
+
const scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
199
|
+
const calculatedTableWidth = cols.reduce((prev, curr) => prev + curr.width, 0);
|
|
200
|
+
|
|
201
|
+
// using Math.round can cause the sum of col widths to be larger than the table width
|
|
202
|
+
// distribute the difference to the smallest column
|
|
203
|
+
if (calculatedTableWidth > scaledTableWidth) {
|
|
204
|
+
const diff = calculatedTableWidth - scaledTableWidth;
|
|
205
|
+
cols = cols.map((col) => {
|
|
206
|
+
return col.width - diff >= col.minWidth ? { ...col, width: col.width - diff } : col;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
...resizeState,
|
|
212
|
+
widths: cols.map((col) => col.width),
|
|
213
|
+
tableWidth: scaledTableWidth,
|
|
214
|
+
maxSize: Math.round(resizeState.maxSize * scalePercent),
|
|
215
|
+
cols,
|
|
216
|
+
};
|
|
217
|
+
};
|
|
@@ -47,6 +47,7 @@ const createPlugin = (
|
|
|
47
47
|
fullWidthEnabled: boolean,
|
|
48
48
|
isTableScalingEnabled: boolean,
|
|
49
49
|
isTableAlignmentEnabled: boolean,
|
|
50
|
+
isCommentEditor: boolean,
|
|
50
51
|
) => {
|
|
51
52
|
return new SafePlugin({
|
|
52
53
|
key: pluginKey,
|
|
@@ -158,7 +159,7 @@ const createPlugin = (
|
|
|
158
159
|
});
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
if (isReplaceDocumentOperation) {
|
|
162
|
+
if (isReplaceDocumentOperation && !isCommentEditor) {
|
|
162
163
|
newState.doc.forEach((node, offset) => {
|
|
163
164
|
if (node.type === table) {
|
|
164
165
|
const width = node.attrs.width;
|
package/src/utils/alignment.ts
CHANGED
|
@@ -23,9 +23,11 @@ export const shouldChangeAlignmentToCenterResized = (
|
|
|
23
23
|
lineLength: number | undefined,
|
|
24
24
|
updatedTableWidth: number,
|
|
25
25
|
) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
Boolean(
|
|
27
|
+
isTableAlignmentEnabled &&
|
|
28
|
+
tableNode &&
|
|
29
|
+
tableNode.attrs.layout === ALIGN_START &&
|
|
30
|
+
lineLength &&
|
|
31
|
+
updatedTableWidth > lineLength &&
|
|
32
|
+
lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH,
|
|
33
|
+
);
|