@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
|
@@ -23,12 +23,10 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
|
|
|
23
23
|
bindKeymapWithCommand(addRowAfter.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
24
24
|
bindKeymapWithCommand(addColumnBefore.common, addColumnBeforeCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
25
25
|
bindKeymapWithCommand(addColumnAfter.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
bindKeymapWithCommand(addColumnAfterVO.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
31
|
-
}
|
|
26
|
+
bindKeymapWithCommand(addRowBeforeVO.common, addRowAroundSelection(editorAnalyticsAPI)('TOP'), list);
|
|
27
|
+
bindKeymapWithCommand(addRowAfterVO.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
28
|
+
bindKeymapWithCommand(addColumnBeforeVO.common, addColumnBeforeCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
29
|
+
bindKeymapWithCommand(addColumnAfterVO.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
32
30
|
if (dragAndDropEnabled) {
|
|
33
31
|
// Move row/column shortcuts
|
|
34
32
|
/**
|
|
@@ -13,6 +13,7 @@ import { META_KEYS } from '../table-analytics';
|
|
|
13
13
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
14
14
|
import { getPluginState } from './plugin-factory';
|
|
15
15
|
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
16
|
+
import { scaleResizeState } from './utils/resize-column';
|
|
16
17
|
export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) => {
|
|
17
18
|
const {
|
|
18
19
|
state,
|
|
@@ -21,7 +22,8 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
21
22
|
const editorDisabled = !view.editable;
|
|
22
23
|
const domAtPos = view.domAtPos.bind(view);
|
|
23
24
|
const {
|
|
24
|
-
lineLength
|
|
25
|
+
lineLength,
|
|
26
|
+
width: editorWidth
|
|
25
27
|
} = getEditorContainerWidth();
|
|
26
28
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
27
29
|
return false;
|
|
@@ -61,7 +63,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
61
63
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
62
64
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
63
65
|
}
|
|
64
|
-
|
|
66
|
+
let resizeState = getResizeState({
|
|
65
67
|
minWidth: tableCellMinWidth,
|
|
66
68
|
maxSize,
|
|
67
69
|
table: originalTable,
|
|
@@ -89,6 +91,17 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
89
91
|
// When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
|
|
90
92
|
// unnecessary tooltips being displayed during drag.
|
|
91
93
|
updateResizeHandleDecorations(undefined, undefined, false)(state, dispatch);
|
|
94
|
+
|
|
95
|
+
// for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
|
|
96
|
+
// implication: the scaled version of the table becomes the source of truth
|
|
97
|
+
if (isNewColumnResizingEnabled && shouldScale) {
|
|
98
|
+
resizeState = scaleResizeState({
|
|
99
|
+
resizeState,
|
|
100
|
+
tableRef: dom,
|
|
101
|
+
tableNode: originalTable,
|
|
102
|
+
editorWidth
|
|
103
|
+
});
|
|
104
|
+
}
|
|
92
105
|
function finish(event) {
|
|
93
106
|
window.removeEventListener('mouseup', finish);
|
|
94
107
|
window.removeEventListener('mousemove', move);
|
|
@@ -158,19 +171,24 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
158
171
|
const resizedDelta = clientX - startX;
|
|
159
172
|
const shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled && fg('platform.editor.table.use-increased-scaling-percent');
|
|
160
173
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
161
|
-
const newResizeState = resizeColumnAndTable(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
const newResizeState = resizeColumnAndTable({
|
|
175
|
+
resizeState,
|
|
176
|
+
colIndex,
|
|
177
|
+
amount: resizedDelta,
|
|
178
|
+
tableRef: dom,
|
|
179
|
+
tableNode: originalTable,
|
|
180
|
+
width: editorWidth,
|
|
181
|
+
lineLength,
|
|
182
|
+
isTableAlignmentEnabled
|
|
183
|
+
});
|
|
166
184
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
167
185
|
|
|
168
186
|
// 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
|
|
169
|
-
const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.
|
|
187
|
+
const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.maxSize);
|
|
170
188
|
if (shouldChangeAlignment) {
|
|
171
189
|
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, {
|
|
172
190
|
...table.attrs,
|
|
173
|
-
width: newResizeState.
|
|
191
|
+
width: newResizeState.maxSize,
|
|
174
192
|
layout: ALIGN_CENTER
|
|
175
193
|
});
|
|
176
194
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
@@ -178,7 +196,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
178
196
|
actionSubject: ACTION_SUBJECT.TABLE,
|
|
179
197
|
actionSubjectId: null,
|
|
180
198
|
attributes: {
|
|
181
|
-
tableWidth: newResizeState.
|
|
199
|
+
tableWidth: newResizeState.maxSize,
|
|
182
200
|
newAlignment: ALIGN_CENTER,
|
|
183
201
|
previousAlignment: ALIGN_START,
|
|
184
202
|
totalRowCount: totalRowCount,
|
|
@@ -189,7 +207,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
189
207
|
eventType: EVENT_TYPE.TRACK
|
|
190
208
|
})(tr);
|
|
191
209
|
} else {
|
|
192
|
-
tr.setNodeAttribute(start - 1, 'width', newResizeState.
|
|
210
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.maxSize);
|
|
193
211
|
}
|
|
194
212
|
} else {
|
|
195
213
|
const newResizeState = resizeColumn(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
@@ -267,10 +285,20 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
267
285
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
268
286
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
269
287
|
}
|
|
288
|
+
const resizedDelta = clientX - dragging.startX;
|
|
270
289
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
271
|
-
resizeColumnAndTable(
|
|
290
|
+
resizeColumnAndTable({
|
|
291
|
+
resizeState,
|
|
292
|
+
colIndex,
|
|
293
|
+
amount: resizedDelta,
|
|
294
|
+
tableRef: dom,
|
|
295
|
+
tableNode: originalTable,
|
|
296
|
+
width: editorWidth,
|
|
297
|
+
lineLength,
|
|
298
|
+
isTableAlignmentEnabled
|
|
299
|
+
});
|
|
272
300
|
} else {
|
|
273
|
-
resizeColumn(resizeState, colIndex,
|
|
301
|
+
resizeColumn(resizeState, colIndex, resizedDelta, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
274
302
|
}
|
|
275
303
|
updateControls()(state);
|
|
276
304
|
}
|
|
@@ -5,4 +5,7 @@ export const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
|
5
5
|
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
|
-
export const TABLE_EDITOR_MARGIN = 76;
|
|
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 = 2 * (COMMENT_AK_EDITOR_CONTENT_AREA_PADDING + COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN);
|
|
@@ -7,4 +7,4 @@ export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth,
|
|
|
7
7
|
export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
8
8
|
export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
|
|
9
9
|
export { resizeColumn, resizeColumnAndTable } from './resize-column';
|
|
10
|
-
export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT, MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION } from './consts';
|
|
10
|
+
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,8 +1,9 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
|
|
3
|
+
import { akEditorFullWidthLayoutWidth, akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
|
|
3
4
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
4
5
|
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
|
|
5
|
-
import {
|
|
6
|
+
import { getTableScalingPercent } from './misc';
|
|
6
7
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
7
8
|
import { updateColgroup } from './resize-state';
|
|
8
9
|
export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false, shouldUseIncreasedScalingPercent = false) => {
|
|
@@ -16,64 +17,112 @@ export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode,
|
|
|
16
17
|
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled, shouldUseIncreasedScalingPercent);
|
|
17
18
|
return newState;
|
|
18
19
|
};
|
|
20
|
+
export const resizeColumnAndTable = ({
|
|
21
|
+
resizeState,
|
|
22
|
+
colIndex,
|
|
23
|
+
amount,
|
|
24
|
+
tableRef,
|
|
25
|
+
tableNode,
|
|
26
|
+
lineLength,
|
|
27
|
+
width: editorWidth,
|
|
28
|
+
isTableAlignmentEnabled
|
|
29
|
+
}) => {
|
|
30
|
+
const editorContainerWidth = getEditorContainerWidth(editorWidth);
|
|
31
|
+
const isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
|
|
32
|
+
let resizeAmount = isTableLeftAligned ? amount : amount * 2;
|
|
33
|
+
const willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
|
|
34
|
+
const willResizedTableStayInOverflow = resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
|
|
19
35
|
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
26
|
-
const isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
27
|
-
let resizeAmount = tableNode.attrs.layout === ALIGN_START && !isOverflowed ? amount : amount * 2;
|
|
28
|
-
|
|
29
|
-
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
30
|
-
// let scalePercent = 1;
|
|
31
|
-
// if (isTableScalingEnabled) {
|
|
32
|
-
// import from ./misc
|
|
33
|
-
// scalePercent = getStaticTableScalingPercent(
|
|
34
|
-
// tableNode,
|
|
35
|
-
// originalTableWidth || resizeState.maxSize,
|
|
36
|
-
// );
|
|
37
|
-
// resizeAmount = amount / scalePercent;
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
|
-
// need to look at the resize amount and try to adjust the colgroups
|
|
41
|
-
if (isOverflowed) {
|
|
42
|
-
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
36
|
+
// STEP 1: Update col width
|
|
37
|
+
if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
|
|
38
|
+
var _tableRef$closest;
|
|
39
|
+
const tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
40
|
+
resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
|
|
43
|
+
const diff = -(resizeState.tableWidth - resizeState.maxSize);
|
|
44
|
+
const rest = amount - diff;
|
|
45
|
+
const final = isTableLeftAligned ? diff + rest : diff + rest * 2;
|
|
46
|
+
resizeAmount = final;
|
|
47
|
+
}
|
|
48
|
+
let newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
49
49
|
|
|
50
|
-
//
|
|
50
|
+
// STEP 2: Update table container width
|
|
51
|
+
// columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
|
|
51
52
|
const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
newState.maxSize = Math.round(resizeState.overflow ? willResizedTableStayInOverflow ?
|
|
54
|
+
// CASE 1A: table will stay in overflow
|
|
55
|
+
// do not grow the table because resize is happening in the overflow region
|
|
56
|
+
// and the overall table container needs to be retained
|
|
57
|
+
resizeState.maxSize :
|
|
58
|
+
// CASE 1B: table will no longer be in overflow, so adjust container width
|
|
59
|
+
// ensure the table is resized without any 'big jumps' by working out
|
|
60
|
+
// the difference between the new table width and the max size and adding the resize
|
|
61
|
+
resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
|
|
62
|
+
// CASE 2: table will hit editor edge
|
|
63
|
+
editorContainerWidth :
|
|
64
|
+
// CASE 3: table is being resized from a non-overflow state
|
|
65
|
+
resizeState.maxSize + delta);
|
|
66
|
+
|
|
67
|
+
// do not apply scaling logic because resize state is already scaled
|
|
68
|
+
updateColgroup(newState, tableRef, tableNode, false, false);
|
|
69
|
+
if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
|
|
70
|
+
updateTablePreview(tableRef, newState.maxSize, shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
|
|
56
71
|
}
|
|
57
|
-
return
|
|
58
|
-
...newState,
|
|
59
|
-
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
60
|
-
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
61
|
-
};
|
|
72
|
+
return newState;
|
|
62
73
|
};
|
|
63
|
-
const updateTablePreview = (
|
|
64
|
-
const
|
|
65
|
-
const resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
74
|
+
const updateTablePreview = (tableRef, newTableWidth, shouldChangeAlignment) => {
|
|
75
|
+
const resizingContainer = tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
66
76
|
const resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
67
77
|
const alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
68
78
|
if (resizingItem) {
|
|
69
|
-
const newWidth = `${
|
|
70
|
-
if (tableRef) {
|
|
71
|
-
tableRef.style.width = newWidth;
|
|
72
|
-
}
|
|
79
|
+
const newWidth = `${newTableWidth}px`;
|
|
73
80
|
resizingContainer.style.width = newWidth;
|
|
74
81
|
resizingItem.style.width = newWidth;
|
|
75
|
-
if (
|
|
76
|
-
alignmentContainer.style.justifyContent =
|
|
82
|
+
if (shouldChangeAlignment && alignmentContainer) {
|
|
83
|
+
alignmentContainer.style.justifyContent = ALIGN_CENTER;
|
|
77
84
|
}
|
|
78
85
|
}
|
|
86
|
+
};
|
|
87
|
+
const getEditorContainerWidth = editorWidth => Math.min(editorWidth - akEditorGutterPaddingDynamic() * 2, akEditorFullWidthLayoutWidth);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Apply a scaling factor to resize state
|
|
91
|
+
*/
|
|
92
|
+
export const scaleResizeState = ({
|
|
93
|
+
resizeState,
|
|
94
|
+
tableRef,
|
|
95
|
+
tableNode,
|
|
96
|
+
editorWidth
|
|
97
|
+
}) => {
|
|
98
|
+
// check if table is scaled, if not then avoid applying scaling values down
|
|
99
|
+
if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
|
|
100
|
+
return resizeState;
|
|
101
|
+
}
|
|
102
|
+
const scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
103
|
+
let cols = resizeState.cols.map(col => ({
|
|
104
|
+
...col,
|
|
105
|
+
width: Math.round(Math.max(col.width * scalePercent, col.minWidth))
|
|
106
|
+
}));
|
|
107
|
+
const scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
108
|
+
const calculatedTableWidth = cols.reduce((prev, curr) => prev + curr.width, 0);
|
|
109
|
+
|
|
110
|
+
// using Math.round can cause the sum of col widths to be larger than the table width
|
|
111
|
+
// distribute the difference to the smallest column
|
|
112
|
+
if (calculatedTableWidth > scaledTableWidth) {
|
|
113
|
+
const diff = calculatedTableWidth - scaledTableWidth;
|
|
114
|
+
cols = cols.map(col => {
|
|
115
|
+
return col.width - diff >= col.minWidth ? {
|
|
116
|
+
...col,
|
|
117
|
+
width: col.width - diff
|
|
118
|
+
} : col;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
...resizeState,
|
|
123
|
+
widths: cols.map(col => col.width),
|
|
124
|
+
tableWidth: scaledTableWidth,
|
|
125
|
+
maxSize: Math.round(resizeState.maxSize * scalePercent),
|
|
126
|
+
cols
|
|
127
|
+
};
|
|
79
128
|
};
|
|
@@ -14,7 +14,7 @@ import { findTable } from '@atlaskit/editor-tables/utils';
|
|
|
14
14
|
import { ALIGN_START } from '../utils/alignment';
|
|
15
15
|
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
16
16
|
export const pluginKey = new PluginKey('tableWidthPlugin');
|
|
17
|
-
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled) => {
|
|
17
|
+
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled, isCommentEditor) => {
|
|
18
18
|
return new SafePlugin({
|
|
19
19
|
key: pluginKey,
|
|
20
20
|
state: {
|
|
@@ -114,7 +114,7 @@ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTabl
|
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
if (isReplaceDocumentOperation) {
|
|
117
|
+
if (isReplaceDocumentOperation && !isCommentEditor) {
|
|
118
118
|
newState.doc.forEach((node, offset) => {
|
|
119
119
|
if (node.type === table) {
|
|
120
120
|
const width = node.attrs.width;
|
|
@@ -11,4 +11,4 @@ export const normaliseAlignment = layout => layout === ALIGN_CENTER || layout ==
|
|
|
11
11
|
/**
|
|
12
12
|
* We don't want to switch alignment in Full-width editor
|
|
13
13
|
*/
|
|
14
|
-
export const shouldChangeAlignmentToCenterResized = (isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) => isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH;
|
|
14
|
+
export const shouldChangeAlignmentToCenterResized = (isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) => Boolean(isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH);
|
|
@@ -6,7 +6,7 @@ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
|
6
6
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
7
7
|
import { akEditorDefaultLayoutWidth, akEditorGutterPaddingDynamic, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
|
|
8
8
|
import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../commands-with-analytics';
|
|
9
|
-
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
9
|
+
import { TABLE_MAX_WIDTH, TABLE_OFFSET_IN_COMMENT_EDITOR } from '../pm-plugins/table-resizing/utils';
|
|
10
10
|
import { TableCssClassName as ClassName } from '../types';
|
|
11
11
|
import { ALIGN_CENTER, ALIGN_START } from '../utils/alignment';
|
|
12
12
|
import { TableResizer } from './TableResizer';
|
|
@@ -197,12 +197,14 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
|
|
|
197
197
|
// When: Always -> containerWidth = akEditorGutterPadding * 2 + lineLength + scrollbarWidth;
|
|
198
198
|
// scrollbarWidth can vary. Values can be 14, 15, 16 and up to 20px;
|
|
199
199
|
responsiveContainerWidth = isTableScalingEnabled ? lineLength : containerWidth - akEditorGutterPaddingDynamic() * 2 - resizeHandleSpacing;
|
|
200
|
+
} else if (isCommentEditor) {
|
|
201
|
+
responsiveContainerWidth = containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR;
|
|
200
202
|
} else {
|
|
201
203
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
202
204
|
// containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
|
|
203
205
|
// a DIV with className="ak-editor-content-area". This DIV has padding left and padding right.
|
|
204
206
|
// padding left = padding right = akEditorGutterPadding = 32
|
|
205
|
-
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - akEditorGutterPaddingDynamic() * 2 : containerWidth - akEditorGutterPaddingDynamic() * 2 -
|
|
207
|
+
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - akEditorGutterPaddingDynamic() * 2 : containerWidth - akEditorGutterPaddingDynamic() * 2 - resizeHandleSpacing;
|
|
206
208
|
}
|
|
207
209
|
var width = !node.attrs.width && isCommentEditor ? responsiveContainerWidth : Math.min(tableWidth, responsiveContainerWidth);
|
|
208
210
|
if (!isResizing) {
|
|
@@ -230,7 +232,8 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
|
|
|
230
232
|
shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent,
|
|
231
233
|
pluginInjectionApi: pluginInjectionApi,
|
|
232
234
|
onResizeStart: onResizeStart,
|
|
233
|
-
onResizeStop: onResizeStop
|
|
235
|
+
onResizeStop: onResizeStop,
|
|
236
|
+
isCommentEditor: isCommentEditor
|
|
234
237
|
};
|
|
235
238
|
var isLivePageViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
|
|
236
239
|
return /*#__PURE__*/React.createElement(AlignmentTableContainerWrapper, {
|
|
@@ -19,7 +19,7 @@ import { findTable } from '@atlaskit/editor-tables/utils';
|
|
|
19
19
|
import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../commands-with-analytics';
|
|
20
20
|
import { updateWidthToWidest } from '../commands/misc';
|
|
21
21
|
import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
22
|
-
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
22
|
+
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH, TABLE_OFFSET_IN_COMMENT_EDITOR } from '../pm-plugins/table-resizing/utils';
|
|
23
23
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
24
24
|
import { TABLE_GUIDELINE_VISIBLE_ADJUSTMENT, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
|
|
25
25
|
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment, shouldChangeAlignmentToCenterResized } from '../utils/alignment';
|
|
@@ -114,7 +114,8 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
114
114
|
isWholeTableInDanger = _ref.isWholeTableInDanger,
|
|
115
115
|
shouldUseIncreasedScalingPercent = _ref.shouldUseIncreasedScalingPercent,
|
|
116
116
|
pluginInjectionApi = _ref.pluginInjectionApi,
|
|
117
|
-
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled
|
|
117
|
+
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled,
|
|
118
|
+
isCommentEditor = _ref.isCommentEditor;
|
|
118
119
|
var currentGap = useRef(0);
|
|
119
120
|
// track resizing state - use ref over state to avoid re-render
|
|
120
121
|
var isResizing = useRef(false);
|
|
@@ -267,13 +268,14 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
267
268
|
return guideline.isFullWidth;
|
|
268
269
|
})[0];
|
|
269
270
|
var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
270
|
-
var
|
|
271
|
+
var tableMaxWidth = isCommentEditor ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR : TABLE_MAX_WIDTH;
|
|
272
|
+
var shouldUpdateWidthToWidest = isCommentEditor && tableMaxWidth === newWidth || !!isTableScalingEnabled && isFullWidthGuidelineActive;
|
|
271
273
|
chainCommands(function (state, dispatch) {
|
|
272
274
|
return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
|
|
273
275
|
}, updateWidthToWidest(_defineProperty({}, currentTableNodeLocalId, shouldUpdateWidthToWidest)))(state, dispatch);
|
|
274
|
-
updateWidth(shouldUpdateWidthToWidest ?
|
|
276
|
+
updateWidth(shouldUpdateWidthToWidest ? tableMaxWidth : newWidth);
|
|
275
277
|
return newWidth;
|
|
276
|
-
}, [countFrames, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
278
|
+
}, [countFrames, isCommentEditor, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
277
279
|
var scheduleResize = useMemo(function () {
|
|
278
280
|
return rafSchd(handleResize);
|
|
279
281
|
}, [handleResize]);
|
|
@@ -285,7 +287,8 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
285
287
|
dispatch = editorView.dispatch;
|
|
286
288
|
var pos = getPos();
|
|
287
289
|
var currentTableNodeLocalId = (_node$attrs$localId2 = node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.localId) !== null && _node$attrs$localId2 !== void 0 ? _node$attrs$localId2 : '';
|
|
288
|
-
|
|
290
|
+
var tableMaxWidth = isCommentEditor ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR : TABLE_MAX_WIDTH;
|
|
291
|
+
newWidth = widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId] ? tableMaxWidth : newWidth;
|
|
289
292
|
var tr = state.tr.setMeta(tableWidthPluginKey, {
|
|
290
293
|
resizing: false,
|
|
291
294
|
tableLocalId: '',
|
|
@@ -344,7 +347,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
344
347
|
onResizeStop();
|
|
345
348
|
}
|
|
346
349
|
return newWidth;
|
|
347
|
-
}, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop, isTableScalingEnabled, shouldUseIncreasedScalingPercent, widthToWidest, formatMessage, pluginInjectionApi]);
|
|
350
|
+
}, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, containerWidth, attachAnalyticsEvent, endMeasure, onResizeStop, isTableScalingEnabled, shouldUseIncreasedScalingPercent, widthToWidest, formatMessage, pluginInjectionApi, isCommentEditor]);
|
|
348
351
|
var handleTableSizeChangeOnKeypress = useCallback(function (step) {
|
|
349
352
|
var newWidth = width + step;
|
|
350
353
|
if (newWidth > maxWidth || newWidth < resizerMinWidth) {
|
package/dist/esm/plugin.js
CHANGED
|
@@ -300,10 +300,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
300
300
|
}, {
|
|
301
301
|
name: 'tableWidth',
|
|
302
302
|
plugin: function plugin(_ref14) {
|
|
303
|
-
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign;
|
|
303
|
+
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign, _options$isCommentEdi;
|
|
304
304
|
var dispatchAnalyticsEvent = _ref14.dispatchAnalyticsEvent,
|
|
305
305
|
dispatch = _ref14.dispatch;
|
|
306
|
-
return options !== null && options !== void 0 && options.tableResizingEnabled
|
|
306
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false, (_options$isCommentEdi = options === null || options === void 0 ? void 0 : options.isCommentEditor) !== null && _options$isCommentEdi !== void 0 ? _options$isCommentEdi : false) : undefined;
|
|
307
307
|
}
|
|
308
308
|
},
|
|
309
309
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -465,7 +465,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
465
465
|
stickyHeaders: stickyHeader,
|
|
466
466
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
467
467
|
editorAnalyticsAPI: editorAnalyticsAPI
|
|
468
|
-
}), (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/React.createElement(FloatingToolbarLabel, {
|
|
468
|
+
}), ((options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) || (options === null || options === void 0 ? void 0 : options.tableResizingEnabled) && options.isCommentEditor) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/React.createElement(FloatingToolbarLabel, {
|
|
469
469
|
target: resizingTableRef,
|
|
470
470
|
content: /*#__PURE__*/React.createElement(FullWidthDisplay, null),
|
|
471
471
|
alignX: 'center',
|
|
@@ -33,12 +33,10 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAn
|
|
|
33
33
|
bindKeymapWithCommand(addRowAfter.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
34
34
|
bindKeymapWithCommand(addColumnBefore.common, addColumnBeforeCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
35
35
|
bindKeymapWithCommand(addColumnAfter.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
bindKeymapWithCommand(addColumnAfterVO.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
41
|
-
}
|
|
36
|
+
bindKeymapWithCommand(addRowBeforeVO.common, addRowAroundSelection(editorAnalyticsAPI)('TOP'), list);
|
|
37
|
+
bindKeymapWithCommand(addRowAfterVO.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
38
|
+
bindKeymapWithCommand(addColumnBeforeVO.common, addColumnBeforeCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
39
|
+
bindKeymapWithCommand(addColumnAfterVO.common, addColumnAfterCommand(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
42
40
|
if (dragAndDropEnabled) {
|
|
43
41
|
// Move row/column shortcuts
|
|
44
42
|
/**
|
|
@@ -16,13 +16,15 @@ import { META_KEYS } from '../table-analytics';
|
|
|
16
16
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
17
17
|
import { getPluginState } from './plugin-factory';
|
|
18
18
|
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
19
|
+
import { scaleResizeState } from './utils/resize-column';
|
|
19
20
|
export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
20
21
|
var state = view.state,
|
|
21
22
|
dispatch = view.dispatch;
|
|
22
23
|
var editorDisabled = !view.editable;
|
|
23
24
|
var domAtPos = view.domAtPos.bind(view);
|
|
24
25
|
var _getEditorContainerWi = getEditorContainerWidth(),
|
|
25
|
-
lineLength = _getEditorContainerWi.lineLength
|
|
26
|
+
lineLength = _getEditorContainerWi.lineLength,
|
|
27
|
+
editorWidth = _getEditorContainerWi.width;
|
|
26
28
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
27
29
|
return false;
|
|
28
30
|
}
|
|
@@ -88,6 +90,17 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
88
90
|
// When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
|
|
89
91
|
// unnecessary tooltips being displayed during drag.
|
|
90
92
|
updateResizeHandleDecorations(undefined, undefined, false)(state, dispatch);
|
|
93
|
+
|
|
94
|
+
// for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
|
|
95
|
+
// implication: the scaled version of the table becomes the source of truth
|
|
96
|
+
if (isNewColumnResizingEnabled && shouldScale) {
|
|
97
|
+
resizeState = scaleResizeState({
|
|
98
|
+
resizeState: resizeState,
|
|
99
|
+
tableRef: dom,
|
|
100
|
+
tableNode: originalTable,
|
|
101
|
+
editorWidth: editorWidth
|
|
102
|
+
});
|
|
103
|
+
}
|
|
91
104
|
function finish(event) {
|
|
92
105
|
window.removeEventListener('mouseup', finish);
|
|
93
106
|
window.removeEventListener('mousemove', move);
|
|
@@ -147,18 +160,23 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
147
160
|
var resizedDelta = clientX - startX;
|
|
148
161
|
var shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled && fg('platform.editor.table.use-increased-scaling-percent');
|
|
149
162
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
150
|
-
var newResizeState = resizeColumnAndTable(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
163
|
+
var newResizeState = resizeColumnAndTable({
|
|
164
|
+
resizeState: resizeState,
|
|
165
|
+
colIndex: colIndex,
|
|
166
|
+
amount: resizedDelta,
|
|
167
|
+
tableRef: dom,
|
|
168
|
+
tableNode: originalTable,
|
|
169
|
+
width: editorWidth,
|
|
170
|
+
lineLength: lineLength,
|
|
171
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled
|
|
172
|
+
});
|
|
155
173
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
156
174
|
|
|
157
175
|
// 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
|
|
158
|
-
var shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.
|
|
176
|
+
var shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.maxSize);
|
|
159
177
|
if (shouldChangeAlignment) {
|
|
160
178
|
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, _objectSpread(_objectSpread({}, table.attrs), {}, {
|
|
161
|
-
width: newResizeState.
|
|
179
|
+
width: newResizeState.maxSize,
|
|
162
180
|
layout: ALIGN_CENTER
|
|
163
181
|
}));
|
|
164
182
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
@@ -166,7 +184,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
166
184
|
actionSubject: ACTION_SUBJECT.TABLE,
|
|
167
185
|
actionSubjectId: null,
|
|
168
186
|
attributes: {
|
|
169
|
-
tableWidth: newResizeState.
|
|
187
|
+
tableWidth: newResizeState.maxSize,
|
|
170
188
|
newAlignment: ALIGN_CENTER,
|
|
171
189
|
previousAlignment: ALIGN_START,
|
|
172
190
|
totalRowCount: totalRowCount,
|
|
@@ -177,7 +195,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
177
195
|
eventType: EVENT_TYPE.TRACK
|
|
178
196
|
})(tr);
|
|
179
197
|
} else {
|
|
180
|
-
tr.setNodeAttribute(start - 1, 'width', newResizeState.
|
|
198
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.maxSize);
|
|
181
199
|
}
|
|
182
200
|
} else {
|
|
183
201
|
var _newResizeState = resizeColumn(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale, shouldUseIncreasedScalingPercent);
|
|
@@ -249,10 +267,20 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
249
267
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
250
268
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
251
269
|
}
|
|
270
|
+
var resizedDelta = clientX - dragging.startX;
|
|
252
271
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
253
|
-
resizeColumnAndTable(
|
|
272
|
+
resizeColumnAndTable({
|
|
273
|
+
resizeState: resizeState,
|
|
274
|
+
colIndex: colIndex,
|
|
275
|
+
amount: resizedDelta,
|
|
276
|
+
tableRef: dom,
|
|
277
|
+
tableNode: originalTable,
|
|
278
|
+
width: editorWidth,
|
|
279
|
+
lineLength: lineLength,
|
|
280
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled
|
|
281
|
+
});
|
|
254
282
|
} else {
|
|
255
|
-
resizeColumn(resizeState, colIndex,
|
|
283
|
+
resizeColumn(resizeState, colIndex, resizedDelta, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
256
284
|
}
|
|
257
285
|
updateControls()(state);
|
|
258
286
|
}
|
|
@@ -5,4 +5,7 @@ export var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
|
5
5
|
export var MAX_SCALING_PERCENT = 0.3;
|
|
6
6
|
export var 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
|
-
export var TABLE_EDITOR_MARGIN = 76;
|
|
8
|
+
export var TABLE_EDITOR_MARGIN = 76;
|
|
9
|
+
var COMMENT_AK_EDITOR_CONTENT_AREA_PADDING = 20;
|
|
10
|
+
var COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN = 12;
|
|
11
|
+
export var TABLE_OFFSET_IN_COMMENT_EDITOR = 2 * (COMMENT_AK_EDITOR_CONTENT_AREA_PADDING + COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN);
|
|
@@ -7,4 +7,4 @@ export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth,
|
|
|
7
7
|
export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
8
8
|
export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
|
|
9
9
|
export { resizeColumn, resizeColumnAndTable } from './resize-column';
|
|
10
|
-
export { COLUMN_MIN_WIDTH, TABLE_MAX_WIDTH, TABLE_DEFAULT_WIDTH, MAX_SCALING_PERCENT, MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION } from './consts';
|
|
10
|
+
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';
|