@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.21.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#123311](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/123311)
|
|
8
|
+
[`ea5eb60bfc2f9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ea5eb60bfc2f9) -
|
|
9
|
+
[ux] Displays full-width tooltip when table resized to the width of the Comment editor when table
|
|
10
|
+
resizing is enabled.
|
|
11
|
+
|
|
12
|
+
## 7.21.5
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#122514](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/122514)
|
|
17
|
+
[`91276c81ef8a8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/91276c81ef8a8) -
|
|
18
|
+
[ED-24019] This change is cleaning up the feature flag
|
|
19
|
+
'platform.editor.a11y-help-dialog-shortcut-keys-position_aghfg' which was introduced for new
|
|
20
|
+
keyboard shortcuts for inserting columns and rows to a table.
|
|
21
|
+
- [#122054](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/122054)
|
|
22
|
+
[`2ead5fa12242d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2ead5fa12242d) -
|
|
23
|
+
Use scaled amounts for new column resizing, and update logic to cater for more scenarios
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
|
|
3
26
|
## 7.21.4
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -207,12 +207,14 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
|
|
|
207
207
|
// When: Always -> containerWidth = akEditorGutterPadding * 2 + lineLength + scrollbarWidth;
|
|
208
208
|
// scrollbarWidth can vary. Values can be 14, 15, 16 and up to 20px;
|
|
209
209
|
responsiveContainerWidth = isTableScalingEnabled ? lineLength : containerWidth - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2 - resizeHandleSpacing;
|
|
210
|
+
} else if (isCommentEditor) {
|
|
211
|
+
responsiveContainerWidth = containerWidth - _utils.TABLE_OFFSET_IN_COMMENT_EDITOR;
|
|
210
212
|
} else {
|
|
211
213
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
212
214
|
// containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
|
|
213
215
|
// a DIV with className="ak-editor-content-area". This DIV has padding left and padding right.
|
|
214
216
|
// padding left = padding right = akEditorGutterPadding = 32
|
|
215
|
-
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2 : containerWidth - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2 -
|
|
217
|
+
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2 : containerWidth - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2 - resizeHandleSpacing;
|
|
216
218
|
}
|
|
217
219
|
var width = !node.attrs.width && isCommentEditor ? responsiveContainerWidth : Math.min(tableWidth, responsiveContainerWidth);
|
|
218
220
|
if (!isResizing) {
|
|
@@ -240,7 +242,8 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
|
|
|
240
242
|
shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent,
|
|
241
243
|
pluginInjectionApi: pluginInjectionApi,
|
|
242
244
|
onResizeStart: onResizeStart,
|
|
243
|
-
onResizeStop: onResizeStop
|
|
245
|
+
onResizeStop: onResizeStop,
|
|
246
|
+
isCommentEditor: isCommentEditor
|
|
244
247
|
};
|
|
245
248
|
var isLivePageViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
|
|
246
249
|
return /*#__PURE__*/_react.default.createElement(AlignmentTableContainerWrapper, {
|
|
@@ -124,7 +124,8 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
124
124
|
isWholeTableInDanger = _ref.isWholeTableInDanger,
|
|
125
125
|
shouldUseIncreasedScalingPercent = _ref.shouldUseIncreasedScalingPercent,
|
|
126
126
|
pluginInjectionApi = _ref.pluginInjectionApi,
|
|
127
|
-
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled
|
|
127
|
+
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled,
|
|
128
|
+
isCommentEditor = _ref.isCommentEditor;
|
|
128
129
|
var currentGap = (0, _react.useRef)(0);
|
|
129
130
|
// track resizing state - use ref over state to avoid re-render
|
|
130
131
|
var isResizing = (0, _react.useRef)(false);
|
|
@@ -277,13 +278,14 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
277
278
|
return guideline.isFullWidth;
|
|
278
279
|
})[0];
|
|
279
280
|
var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
280
|
-
var
|
|
281
|
+
var tableMaxWidth = isCommentEditor ? containerWidth - _utils3.TABLE_OFFSET_IN_COMMENT_EDITOR : _utils3.TABLE_MAX_WIDTH;
|
|
282
|
+
var shouldUpdateWidthToWidest = isCommentEditor && tableMaxWidth === newWidth || !!isTableScalingEnabled && isFullWidthGuidelineActive;
|
|
281
283
|
(0, _commands.chainCommands)(function (state, dispatch) {
|
|
282
284
|
return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
|
|
283
285
|
}, (0, _misc.updateWidthToWidest)((0, _defineProperty2.default)({}, currentTableNodeLocalId, shouldUpdateWidthToWidest)))(state, dispatch);
|
|
284
|
-
updateWidth(shouldUpdateWidthToWidest ?
|
|
286
|
+
updateWidth(shouldUpdateWidthToWidest ? tableMaxWidth : newWidth);
|
|
285
287
|
return newWidth;
|
|
286
|
-
}, [countFrames, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
288
|
+
}, [countFrames, isCommentEditor, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
287
289
|
var scheduleResize = (0, _react.useMemo)(function () {
|
|
288
290
|
return (0, _rafSchd.default)(handleResize);
|
|
289
291
|
}, [handleResize]);
|
|
@@ -295,7 +297,8 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
295
297
|
dispatch = editorView.dispatch;
|
|
296
298
|
var pos = getPos();
|
|
297
299
|
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 : '';
|
|
298
|
-
|
|
300
|
+
var tableMaxWidth = isCommentEditor ? containerWidth - _utils3.TABLE_OFFSET_IN_COMMENT_EDITOR : _utils3.TABLE_MAX_WIDTH;
|
|
301
|
+
newWidth = widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId] ? tableMaxWidth : newWidth;
|
|
299
302
|
var tr = state.tr.setMeta(_tableWidth.pluginKey, {
|
|
300
303
|
resizing: false,
|
|
301
304
|
tableLocalId: '',
|
|
@@ -354,7 +357,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
354
357
|
onResizeStop();
|
|
355
358
|
}
|
|
356
359
|
return newWidth;
|
|
357
|
-
}, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop, isTableScalingEnabled, shouldUseIncreasedScalingPercent, widthToWidest, formatMessage, pluginInjectionApi]);
|
|
360
|
+
}, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, containerWidth, attachAnalyticsEvent, endMeasure, onResizeStop, isTableScalingEnabled, shouldUseIncreasedScalingPercent, widthToWidest, formatMessage, pluginInjectionApi, isCommentEditor]);
|
|
358
361
|
var handleTableSizeChangeOnKeypress = (0, _react.useCallback)(function (step) {
|
|
359
362
|
var newWidth = width + step;
|
|
360
363
|
if (newWidth > maxWidth || newWidth < resizerMinWidth) {
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -307,10 +307,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
307
307
|
}, {
|
|
308
308
|
name: 'tableWidth',
|
|
309
309
|
plugin: function plugin(_ref14) {
|
|
310
|
-
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign;
|
|
310
|
+
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign, _options$isCommentEdi;
|
|
311
311
|
var dispatchAnalyticsEvent = _ref14.dispatchAnalyticsEvent,
|
|
312
312
|
dispatch = _ref14.dispatch;
|
|
313
|
-
return options !== null && options !== void 0 && options.tableResizingEnabled
|
|
313
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(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;
|
|
314
314
|
}
|
|
315
315
|
},
|
|
316
316
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -472,7 +472,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
472
472
|
stickyHeaders: stickyHeader,
|
|
473
473
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
474
474
|
editorAnalyticsAPI: editorAnalyticsAPI
|
|
475
|
-
}), (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/_react.default.createElement(_FloatingToolbarLabel.FloatingToolbarLabel, {
|
|
475
|
+
}), ((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.default.createElement(_FloatingToolbarLabel.FloatingToolbarLabel, {
|
|
476
476
|
target: resizingTableRef,
|
|
477
477
|
content: /*#__PURE__*/_react.default.createElement(_TableFullWidthLabel.FullWidthDisplay, null),
|
|
478
478
|
alignX: 'center',
|
|
@@ -40,12 +40,10 @@ function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEn
|
|
|
40
40
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addRowAfter.common, (0, _commandsWithAnalytics.addRowAroundSelection)(editorAnalyticsAPI)('BOTTOM'), list);
|
|
41
41
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnBefore.common, (0, _insert.addColumnBefore)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
42
42
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnAfter.common, (0, _insert.addColumnAfter)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnAfterVO.common, (0, _insert.addColumnAfter)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
48
|
-
}
|
|
43
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addRowBeforeVO.common, (0, _commandsWithAnalytics.addRowAroundSelection)(editorAnalyticsAPI)('TOP'), list);
|
|
44
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addRowAfterVO.common, (0, _commandsWithAnalytics.addRowAroundSelection)(editorAnalyticsAPI)('BOTTOM'), list);
|
|
45
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnBeforeVO.common, (0, _insert.addColumnBefore)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
46
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnAfterVO.common, (0, _insert.addColumnAfter)(isTableScalingEnabled, isCellBackgroundDuplicated, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
49
47
|
if (dragAndDropEnabled) {
|
|
50
48
|
// Move row/column shortcuts
|
|
51
49
|
/**
|
|
@@ -21,6 +21,7 @@ var _tableAnalytics = require("../table-analytics");
|
|
|
21
21
|
var _commands = require("./commands");
|
|
22
22
|
var _pluginFactory2 = require("./plugin-factory");
|
|
23
23
|
var _utils3 = require("./utils");
|
|
24
|
+
var _resizeColumn = require("./utils/resize-column");
|
|
24
25
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
26
|
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) { (0, _defineProperty2.default)(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; }
|
|
26
27
|
var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
@@ -29,7 +30,8 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
29
30
|
var editorDisabled = !view.editable;
|
|
30
31
|
var domAtPos = view.domAtPos.bind(view);
|
|
31
32
|
var _getEditorContainerWi = getEditorContainerWidth(),
|
|
32
|
-
lineLength = _getEditorContainerWi.lineLength
|
|
33
|
+
lineLength = _getEditorContainerWi.lineLength,
|
|
34
|
+
editorWidth = _getEditorContainerWi.width;
|
|
33
35
|
if (editorDisabled || localResizeHandlePos === null || !(0, _utils3.pointsAtCell)(state.doc.resolve(localResizeHandlePos))) {
|
|
34
36
|
return false;
|
|
35
37
|
}
|
|
@@ -95,6 +97,17 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
95
97
|
// When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
|
|
96
98
|
// unnecessary tooltips being displayed during drag.
|
|
97
99
|
(0, _misc.updateResizeHandleDecorations)(undefined, undefined, false)(state, dispatch);
|
|
100
|
+
|
|
101
|
+
// for new column resizing, take the current scaled version of table widths and use those as the basis for resizing
|
|
102
|
+
// implication: the scaled version of the table becomes the source of truth
|
|
103
|
+
if (isNewColumnResizingEnabled && shouldScale) {
|
|
104
|
+
resizeState = (0, _resizeColumn.scaleResizeState)({
|
|
105
|
+
resizeState: resizeState,
|
|
106
|
+
tableRef: dom,
|
|
107
|
+
tableNode: originalTable,
|
|
108
|
+
editorWidth: editorWidth
|
|
109
|
+
});
|
|
110
|
+
}
|
|
98
111
|
function finish(event) {
|
|
99
112
|
window.removeEventListener('mouseup', finish);
|
|
100
113
|
window.removeEventListener('mousemove', move);
|
|
@@ -154,18 +167,23 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
154
167
|
var resizedDelta = clientX - startX;
|
|
155
168
|
var shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled && (0, _platformFeatureFlags.fg)('platform.editor.table.use-increased-scaling-percent');
|
|
156
169
|
if (isNewColumnResizingEnabled && !(0, _utils2.isTableNested)(state, tablePos)) {
|
|
157
|
-
var newResizeState = (0, _utils3.resizeColumnAndTable)(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
var newResizeState = (0, _utils3.resizeColumnAndTable)({
|
|
171
|
+
resizeState: resizeState,
|
|
172
|
+
colIndex: colIndex,
|
|
173
|
+
amount: resizedDelta,
|
|
174
|
+
tableRef: dom,
|
|
175
|
+
tableNode: originalTable,
|
|
176
|
+
width: editorWidth,
|
|
177
|
+
lineLength: lineLength,
|
|
178
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled
|
|
179
|
+
});
|
|
162
180
|
tr = (0, _transforms.updateColumnWidths)(newResizeState, table, start)(tr);
|
|
163
181
|
|
|
164
182
|
// 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
|
|
165
|
-
var shouldChangeAlignment = (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.
|
|
183
|
+
var shouldChangeAlignment = (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.maxSize);
|
|
166
184
|
if (shouldChangeAlignment) {
|
|
167
185
|
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, _objectSpread(_objectSpread({}, table.attrs), {}, {
|
|
168
|
-
width: newResizeState.
|
|
186
|
+
width: newResizeState.maxSize,
|
|
169
187
|
layout: _alignment.ALIGN_CENTER
|
|
170
188
|
}));
|
|
171
189
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
@@ -173,7 +191,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
173
191
|
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
|
|
174
192
|
actionSubjectId: null,
|
|
175
193
|
attributes: {
|
|
176
|
-
tableWidth: newResizeState.
|
|
194
|
+
tableWidth: newResizeState.maxSize,
|
|
177
195
|
newAlignment: _alignment.ALIGN_CENTER,
|
|
178
196
|
previousAlignment: _alignment.ALIGN_START,
|
|
179
197
|
totalRowCount: totalRowCount,
|
|
@@ -184,7 +202,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
184
202
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
185
203
|
})(tr);
|
|
186
204
|
} else {
|
|
187
|
-
tr.setNodeAttribute(start - 1, 'width', newResizeState.
|
|
205
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.maxSize);
|
|
188
206
|
}
|
|
189
207
|
} else {
|
|
190
208
|
var _newResizeState = (0, _utils3.resizeColumn)(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale, shouldUseIncreasedScalingPercent);
|
|
@@ -256,10 +274,20 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
256
274
|
if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
|
|
257
275
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
258
276
|
}
|
|
277
|
+
var resizedDelta = clientX - dragging.startX;
|
|
259
278
|
if (isNewColumnResizingEnabled && !(0, _utils2.isTableNested)(state, tablePos)) {
|
|
260
|
-
(0, _utils3.resizeColumnAndTable)(
|
|
279
|
+
(0, _utils3.resizeColumnAndTable)({
|
|
280
|
+
resizeState: resizeState,
|
|
281
|
+
colIndex: colIndex,
|
|
282
|
+
amount: resizedDelta,
|
|
283
|
+
tableRef: dom,
|
|
284
|
+
tableNode: originalTable,
|
|
285
|
+
width: editorWidth,
|
|
286
|
+
lineLength: lineLength,
|
|
287
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled
|
|
288
|
+
});
|
|
261
289
|
} else {
|
|
262
|
-
(0, _utils3.resizeColumn)(resizeState, colIndex,
|
|
290
|
+
(0, _utils3.resizeColumn)(resizeState, colIndex, resizedDelta, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
263
291
|
}
|
|
264
292
|
(0, _utils3.updateControls)()(state);
|
|
265
293
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TABLE_MAX_WIDTH = exports.TABLE_EDITOR_MARGIN = exports.TABLE_DEFAULT_WIDTH = exports.MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = exports.MAX_SCALING_PERCENT = exports.FULL_WIDTH_EDITOR_CONTENT_WIDTH = exports.COLUMN_MIN_WIDTH = void 0;
|
|
6
|
+
exports.TABLE_OFFSET_IN_COMMENT_EDITOR = exports.TABLE_MAX_WIDTH = exports.TABLE_EDITOR_MARGIN = exports.TABLE_DEFAULT_WIDTH = exports.MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = exports.MAX_SCALING_PERCENT = exports.FULL_WIDTH_EDITOR_CONTENT_WIDTH = exports.COLUMN_MIN_WIDTH = void 0;
|
|
7
7
|
var COLUMN_MIN_WIDTH = exports.COLUMN_MIN_WIDTH = 48;
|
|
8
8
|
var TABLE_DEFAULT_WIDTH = exports.TABLE_DEFAULT_WIDTH = 760;
|
|
9
9
|
var TABLE_MAX_WIDTH = exports.TABLE_MAX_WIDTH = 1800;
|
|
@@ -11,4 +11,7 @@ var FULL_WIDTH_EDITOR_CONTENT_WIDTH = exports.FULL_WIDTH_EDITOR_CONTENT_WIDTH =
|
|
|
11
11
|
var MAX_SCALING_PERCENT = exports.MAX_SCALING_PERCENT = 0.3;
|
|
12
12
|
var MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = exports.MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
13
13
|
// Used to calculate the width of a table using the Editor width
|
|
14
|
-
var TABLE_EDITOR_MARGIN = exports.TABLE_EDITOR_MARGIN = 76;
|
|
14
|
+
var TABLE_EDITOR_MARGIN = exports.TABLE_EDITOR_MARGIN = 76;
|
|
15
|
+
var COMMENT_AK_EDITOR_CONTENT_AREA_PADDING = 20;
|
|
16
|
+
var COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN = 12;
|
|
17
|
+
var TABLE_OFFSET_IN_COMMENT_EDITOR = exports.TABLE_OFFSET_IN_COMMENT_EDITOR = 2 * (COMMENT_AK_EDITOR_CONTENT_AREA_PADDING + COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN);
|
|
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "TABLE_MAX_WIDTH", {
|
|
|
33
33
|
return _consts.TABLE_MAX_WIDTH;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "TABLE_OFFSET_IN_COMMENT_EDITOR", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _consts.TABLE_OFFSET_IN_COMMENT_EDITOR;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
36
42
|
Object.defineProperty(exports, "addContainerLeftRightPadding", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
get: function get() {
|
|
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.resizeColumnAndTable = exports.resizeColumn = void 0;
|
|
7
|
+
exports.scaleResizeState = exports.resizeColumnAndTable = exports.resizeColumn = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
9
10
|
var _types = require("../../../types");
|
|
10
11
|
var _alignment = require("../../../utils/alignment");
|
|
11
12
|
var _misc = require("./misc");
|
|
@@ -26,68 +27,115 @@ var resizeColumn = exports.resizeColumn = function resizeColumn(resizeState, col
|
|
|
26
27
|
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, isTableScalingEnabled, shouldUseIncreasedScalingPercent);
|
|
27
28
|
return newState;
|
|
28
29
|
};
|
|
30
|
+
var resizeColumnAndTable = exports.resizeColumnAndTable = function resizeColumnAndTable(_ref) {
|
|
31
|
+
var resizeState = _ref.resizeState,
|
|
32
|
+
colIndex = _ref.colIndex,
|
|
33
|
+
amount = _ref.amount,
|
|
34
|
+
tableRef = _ref.tableRef,
|
|
35
|
+
tableNode = _ref.tableNode,
|
|
36
|
+
lineLength = _ref.lineLength,
|
|
37
|
+
editorWidth = _ref.width,
|
|
38
|
+
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled;
|
|
39
|
+
var editorContainerWidth = getEditorContainerWidth(editorWidth);
|
|
40
|
+
var isTableLeftAligned = tableNode.attrs.layout === _alignment.ALIGN_START;
|
|
41
|
+
var resizeAmount = isTableLeftAligned ? amount : amount * 2;
|
|
42
|
+
var willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
|
|
43
|
+
var willResizedTableStayInOverflow = resizeState.overflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
|
|
29
44
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
|
|
42
|
-
var resizeAmount = tableNode.attrs.layout === _alignment.ALIGN_START && !isOverflowed ? amount : amount * 2;
|
|
43
|
-
|
|
44
|
-
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
45
|
-
// let scalePercent = 1;
|
|
46
|
-
// if (isTableScalingEnabled) {
|
|
47
|
-
// import from ./misc
|
|
48
|
-
// scalePercent = getStaticTableScalingPercent(
|
|
49
|
-
// tableNode,
|
|
50
|
-
// originalTableWidth || resizeState.maxSize,
|
|
51
|
-
// );
|
|
52
|
-
// resizeAmount = amount / scalePercent;
|
|
53
|
-
// }
|
|
54
|
-
|
|
55
|
-
// need to look at the resize amount and try to adjust the colgroups
|
|
56
|
-
if (isOverflowed) {
|
|
57
|
-
resizeAmount = amount < 0 ? amount : resizeAmount - (tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
45
|
+
// STEP 1: Update col width
|
|
46
|
+
if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
|
|
47
|
+
var _tableRef$closest;
|
|
48
|
+
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
49
|
+
resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
|
|
50
|
+
}
|
|
51
|
+
if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
|
|
52
|
+
var diff = -(resizeState.tableWidth - resizeState.maxSize);
|
|
53
|
+
var rest = amount - diff;
|
|
54
|
+
var final = isTableLeftAligned ? diff + rest : diff + rest * 2;
|
|
55
|
+
resizeAmount = final;
|
|
58
56
|
}
|
|
59
57
|
var newState = (0, _resizeLogic.updateAffectedColumn)(resizeState, colIndex, resizeAmount);
|
|
60
58
|
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, false, shouldUseIncreasedScalingPercent);
|
|
64
|
-
|
|
65
|
-
// use the difference in width from affected column to update overall table width
|
|
59
|
+
// STEP 2: Update table container width
|
|
60
|
+
// columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
|
|
66
61
|
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
newState.maxSize = Math.round(resizeState.overflow ? willResizedTableStayInOverflow ?
|
|
63
|
+
// CASE 1A: table will stay in overflow
|
|
64
|
+
// do not grow the table because resize is happening in the overflow region
|
|
65
|
+
// and the overall table container needs to be retained
|
|
66
|
+
resizeState.maxSize :
|
|
67
|
+
// CASE 1B: table will no longer be in overflow, so adjust container width
|
|
68
|
+
// ensure the table is resized without any 'big jumps' by working out
|
|
69
|
+
// the difference between the new table width and the max size and adding the resize
|
|
70
|
+
resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
|
|
71
|
+
// CASE 2: table will hit editor edge
|
|
72
|
+
editorContainerWidth :
|
|
73
|
+
// CASE 3: table is being resized from a non-overflow state
|
|
74
|
+
resizeState.maxSize + delta);
|
|
75
|
+
|
|
76
|
+
// do not apply scaling logic because resize state is already scaled
|
|
77
|
+
(0, _resizeState.updateColgroup)(newState, tableRef, tableNode, false, false);
|
|
78
|
+
if (!willTableHitEditorEdge && !willResizedTableStayInOverflow) {
|
|
79
|
+
updateTablePreview(tableRef, newState.maxSize, (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
|
|
71
80
|
}
|
|
72
|
-
return
|
|
73
|
-
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
74
|
-
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
75
|
-
});
|
|
81
|
+
return newState;
|
|
76
82
|
};
|
|
77
|
-
var updateTablePreview = function updateTablePreview(
|
|
78
|
-
var
|
|
79
|
-
var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(_types.TableCssClassName.TABLE_RESIZER_CONTAINER));
|
|
83
|
+
var updateTablePreview = function updateTablePreview(tableRef, newTableWidth, shouldChangeAlignment) {
|
|
84
|
+
var resizingContainer = tableRef.closest(".".concat(_types.TableCssClassName.TABLE_RESIZER_CONTAINER));
|
|
80
85
|
var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
81
86
|
var alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
82
87
|
if (resizingItem) {
|
|
83
|
-
var newWidth = "".concat(
|
|
84
|
-
if (tableRef) {
|
|
85
|
-
tableRef.style.width = newWidth;
|
|
86
|
-
}
|
|
88
|
+
var newWidth = "".concat(newTableWidth, "px");
|
|
87
89
|
resizingContainer.style.width = newWidth;
|
|
88
90
|
resizingItem.style.width = newWidth;
|
|
89
|
-
if (
|
|
90
|
-
alignmentContainer.style.justifyContent =
|
|
91
|
+
if (shouldChangeAlignment && alignmentContainer) {
|
|
92
|
+
alignmentContainer.style.justifyContent = _alignment.ALIGN_CENTER;
|
|
91
93
|
}
|
|
92
94
|
}
|
|
95
|
+
};
|
|
96
|
+
var getEditorContainerWidth = function getEditorContainerWidth(editorWidth) {
|
|
97
|
+
return Math.min(editorWidth - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2, _editorSharedStyles.akEditorFullWidthLayoutWidth);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Apply a scaling factor to resize state
|
|
102
|
+
*/
|
|
103
|
+
var scaleResizeState = exports.scaleResizeState = function scaleResizeState(_ref2) {
|
|
104
|
+
var resizeState = _ref2.resizeState,
|
|
105
|
+
tableRef = _ref2.tableRef,
|
|
106
|
+
tableNode = _ref2.tableNode,
|
|
107
|
+
editorWidth = _ref2.editorWidth;
|
|
108
|
+
// check if table is scaled, if not then avoid applying scaling values down
|
|
109
|
+
if (resizeState.maxSize < getEditorContainerWidth(editorWidth)) {
|
|
110
|
+
return resizeState;
|
|
111
|
+
}
|
|
112
|
+
var scalePercent = (0, _misc.getTableScalingPercent)(tableNode, tableRef);
|
|
113
|
+
var cols = resizeState.cols.map(function (col) {
|
|
114
|
+
return _objectSpread(_objectSpread({}, col), {}, {
|
|
115
|
+
width: Math.round(Math.max(col.width * scalePercent, col.minWidth))
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
var scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
119
|
+
var calculatedTableWidth = cols.reduce(function (prev, curr) {
|
|
120
|
+
return prev + curr.width;
|
|
121
|
+
}, 0);
|
|
122
|
+
|
|
123
|
+
// using Math.round can cause the sum of col widths to be larger than the table width
|
|
124
|
+
// distribute the difference to the smallest column
|
|
125
|
+
if (calculatedTableWidth > scaledTableWidth) {
|
|
126
|
+
var diff = calculatedTableWidth - scaledTableWidth;
|
|
127
|
+
cols = cols.map(function (col) {
|
|
128
|
+
return col.width - diff >= col.minWidth ? _objectSpread(_objectSpread({}, col), {}, {
|
|
129
|
+
width: col.width - diff
|
|
130
|
+
}) : col;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return _objectSpread(_objectSpread({}, resizeState), {}, {
|
|
134
|
+
widths: cols.map(function (col) {
|
|
135
|
+
return col.width;
|
|
136
|
+
}),
|
|
137
|
+
tableWidth: scaledTableWidth,
|
|
138
|
+
maxSize: Math.round(resizeState.maxSize * scalePercent),
|
|
139
|
+
cols: cols
|
|
140
|
+
});
|
|
93
141
|
};
|
|
@@ -24,7 +24,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
24
24
|
* Also holds resizing state to hide / show table controls
|
|
25
25
|
*/
|
|
26
26
|
var pluginKey = exports.pluginKey = new _state.PluginKey('tableWidthPlugin');
|
|
27
|
-
var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled) {
|
|
27
|
+
var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled, isCommentEditor) {
|
|
28
28
|
return new _safePlugin.SafePlugin({
|
|
29
29
|
key: pluginKey,
|
|
30
30
|
state: {
|
|
@@ -121,7 +121,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
|
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
|
-
if (isReplaceDocumentOperation) {
|
|
124
|
+
if (isReplaceDocumentOperation && !isCommentEditor) {
|
|
125
125
|
newState.doc.forEach(function (node, offset) {
|
|
126
126
|
if (node.type === table) {
|
|
127
127
|
var width = node.attrs.width;
|
|
@@ -20,5 +20,5 @@ var normaliseAlignment = exports.normaliseAlignment = function normaliseAlignmen
|
|
|
20
20
|
* We don't want to switch alignment in Full-width editor
|
|
21
21
|
*/
|
|
22
22
|
var shouldChangeAlignmentToCenterResized = exports.shouldChangeAlignmentToCenterResized = function shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) {
|
|
23
|
-
return isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < _consts.FULL_WIDTH_EDITOR_CONTENT_WIDTH;
|
|
23
|
+
return Boolean(isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < _consts.FULL_WIDTH_EDITOR_CONTENT_WIDTH);
|
|
24
24
|
};
|
|
@@ -5,7 +5,7 @@ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
|
5
5
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
6
6
|
import { akEditorDefaultLayoutWidth, akEditorGutterPaddingDynamic, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
|
|
7
7
|
import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../commands-with-analytics';
|
|
8
|
-
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
8
|
+
import { TABLE_MAX_WIDTH, TABLE_OFFSET_IN_COMMENT_EDITOR } from '../pm-plugins/table-resizing/utils';
|
|
9
9
|
import { TableCssClassName as ClassName } from '../types';
|
|
10
10
|
import { ALIGN_CENTER, ALIGN_START } from '../utils/alignment';
|
|
11
11
|
import { TableResizer } from './TableResizer';
|
|
@@ -205,12 +205,14 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
205
205
|
// When: Always -> containerWidth = akEditorGutterPadding * 2 + lineLength + scrollbarWidth;
|
|
206
206
|
// scrollbarWidth can vary. Values can be 14, 15, 16 and up to 20px;
|
|
207
207
|
responsiveContainerWidth = isTableScalingEnabled ? lineLength : containerWidth - akEditorGutterPaddingDynamic() * 2 - resizeHandleSpacing;
|
|
208
|
+
} else if (isCommentEditor) {
|
|
209
|
+
responsiveContainerWidth = containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR;
|
|
208
210
|
} else {
|
|
209
211
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
210
212
|
// containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
|
|
211
213
|
// a DIV with className="ak-editor-content-area". This DIV has padding left and padding right.
|
|
212
214
|
// padding left = padding right = akEditorGutterPadding = 32
|
|
213
|
-
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - akEditorGutterPaddingDynamic() * 2 : containerWidth - akEditorGutterPaddingDynamic() * 2 -
|
|
215
|
+
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - akEditorGutterPaddingDynamic() * 2 : containerWidth - akEditorGutterPaddingDynamic() * 2 - resizeHandleSpacing;
|
|
214
216
|
}
|
|
215
217
|
let width = !node.attrs.width && isCommentEditor ? responsiveContainerWidth : Math.min(tableWidth, responsiveContainerWidth);
|
|
216
218
|
if (!isResizing) {
|
|
@@ -238,7 +240,8 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
238
240
|
shouldUseIncreasedScalingPercent,
|
|
239
241
|
pluginInjectionApi,
|
|
240
242
|
onResizeStart,
|
|
241
|
-
onResizeStop
|
|
243
|
+
onResizeStop,
|
|
244
|
+
isCommentEditor
|
|
242
245
|
};
|
|
243
246
|
const isLivePageViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
|
|
244
247
|
return /*#__PURE__*/React.createElement(AlignmentTableContainerWrapper, {
|
|
@@ -15,7 +15,7 @@ import { findTable } from '@atlaskit/editor-tables/utils';
|
|
|
15
15
|
import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../commands-with-analytics';
|
|
16
16
|
import { updateWidthToWidest } from '../commands/misc';
|
|
17
17
|
import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
18
|
-
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
18
|
+
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH, TABLE_OFFSET_IN_COMMENT_EDITOR } from '../pm-plugins/table-resizing/utils';
|
|
19
19
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
20
20
|
import { TABLE_GUIDELINE_VISIBLE_ADJUSTMENT, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
|
|
21
21
|
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment, shouldChangeAlignmentToCenterResized } from '../utils/alignment';
|
|
@@ -109,7 +109,8 @@ export const TableResizer = ({
|
|
|
109
109
|
isWholeTableInDanger,
|
|
110
110
|
shouldUseIncreasedScalingPercent,
|
|
111
111
|
pluginInjectionApi,
|
|
112
|
-
isFullWidthModeEnabled
|
|
112
|
+
isFullWidthModeEnabled,
|
|
113
|
+
isCommentEditor
|
|
113
114
|
}) => {
|
|
114
115
|
var _editorView$state, _pluginInjectionApi$a2;
|
|
115
116
|
const currentGap = useRef(0);
|
|
@@ -270,15 +271,16 @@ export const TableResizer = ({
|
|
|
270
271
|
const currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
|
|
271
272
|
const fullWidthGuideline = defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig).filter(guideline => guideline.isFullWidth)[0];
|
|
272
273
|
const isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
273
|
-
const
|
|
274
|
+
const tableMaxWidth = isCommentEditor ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR : TABLE_MAX_WIDTH;
|
|
275
|
+
const shouldUpdateWidthToWidest = isCommentEditor && tableMaxWidth === newWidth || !!isTableScalingEnabled && isFullWidthGuidelineActive;
|
|
274
276
|
chainCommands((state, dispatch) => {
|
|
275
277
|
return switchToCenterAlignment(pos, node, newWidth, state, dispatch);
|
|
276
278
|
}, updateWidthToWidest({
|
|
277
279
|
[currentTableNodeLocalId]: shouldUpdateWidthToWidest
|
|
278
280
|
}))(state, dispatch);
|
|
279
|
-
updateWidth(shouldUpdateWidthToWidest ?
|
|
281
|
+
updateWidth(shouldUpdateWidthToWidest ? tableMaxWidth : newWidth);
|
|
280
282
|
return newWidth;
|
|
281
|
-
}, [countFrames, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
283
|
+
}, [countFrames, isCommentEditor, isTableScalingEnabled, isTableWithFixedColumnWidthsOptionEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
282
284
|
const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
|
|
283
285
|
const handleResizeStop = useCallback((originalState, delta) => {
|
|
284
286
|
var _node$attrs$localId2, _node$attrs2;
|
|
@@ -290,7 +292,8 @@ export const TableResizer = ({
|
|
|
290
292
|
} = editorView;
|
|
291
293
|
const pos = getPos();
|
|
292
294
|
const currentTableNodeLocalId = (_node$attrs$localId2 = node === null || node === void 0 ? 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 : '';
|
|
293
|
-
|
|
295
|
+
const tableMaxWidth = isCommentEditor ? containerWidth - TABLE_OFFSET_IN_COMMENT_EDITOR : TABLE_MAX_WIDTH;
|
|
296
|
+
newWidth = widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId] ? tableMaxWidth : newWidth;
|
|
294
297
|
let tr = state.tr.setMeta(tableWidthPluginKey, {
|
|
295
298
|
resizing: false,
|
|
296
299
|
tableLocalId: '',
|
|
@@ -350,7 +353,7 @@ export const TableResizer = ({
|
|
|
350
353
|
onResizeStop();
|
|
351
354
|
}
|
|
352
355
|
return newWidth;
|
|
353
|
-
}, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop, isTableScalingEnabled, shouldUseIncreasedScalingPercent, widthToWidest, formatMessage, pluginInjectionApi]);
|
|
356
|
+
}, [displayGapCursor, updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, containerWidth, attachAnalyticsEvent, endMeasure, onResizeStop, isTableScalingEnabled, shouldUseIncreasedScalingPercent, widthToWidest, formatMessage, pluginInjectionApi, isCommentEditor]);
|
|
354
357
|
const handleTableSizeChangeOnKeypress = useCallback(step => {
|
|
355
358
|
const newWidth = width + step;
|
|
356
359
|
if (newWidth > maxWidth || newWidth < resizerMinWidth) {
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -298,8 +298,8 @@ const tablesPlugin = ({
|
|
|
298
298
|
dispatchAnalyticsEvent,
|
|
299
299
|
dispatch
|
|
300
300
|
}) => {
|
|
301
|
-
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign;
|
|
302
|
-
return options !== null && options !== void 0 && options.tableResizingEnabled
|
|
301
|
+
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign, _options$isCommentEdi;
|
|
302
|
+
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;
|
|
303
303
|
}
|
|
304
304
|
},
|
|
305
305
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -466,7 +466,7 @@ const tablesPlugin = ({
|
|
|
466
466
|
stickyHeaders: stickyHeader,
|
|
467
467
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
468
468
|
editorAnalyticsAPI: editorAnalyticsAPI
|
|
469
|
-
}), (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/React.createElement(FloatingToolbarLabel, {
|
|
469
|
+
}), ((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, {
|
|
470
470
|
target: resizingTableRef,
|
|
471
471
|
content: /*#__PURE__*/React.createElement(FullWidthDisplay, null),
|
|
472
472
|
alignX: 'center',
|