@atlaskit/editor-plugin-table 7.18.4 → 7.19.1
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 +20 -0
- package/dist/cjs/nodeviews/TableResizer.js +1 -4
- package/dist/cjs/plugin.js +3 -2
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +38 -4
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +2 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +10 -2
- package/dist/cjs/toolbar.js +4 -1
- package/dist/cjs/utils/alignment.js +9 -1
- package/dist/es2019/nodeviews/TableResizer.js +2 -5
- package/dist/es2019/plugin.js +3 -2
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -5
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +1 -0
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +10 -4
- package/dist/es2019/toolbar.js +4 -1
- package/dist/es2019/utils/alignment.js +7 -1
- package/dist/esm/nodeviews/TableResizer.js +2 -5
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +38 -5
- package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/esm/pm-plugins/table-resizing/utils/consts.js +1 -0
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +11 -3
- package/dist/esm/toolbar.js +4 -1
- package/dist/esm/utils/alignment.js +8 -0
- package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/plugin.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types/utils/alignment.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +1 -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/resize-column.d.ts +1 -1
- package/dist/types-ts4.5/utils/alignment.d.ts +5 -0
- package/package.json +6 -6
- package/src/nodeviews/TableResizer.tsx +7 -8
- package/src/plugin.tsx +2 -0
- package/src/pm-plugins/table-resizing/event-handlers.ts +47 -1
- package/src/pm-plugins/table-resizing/plugin.ts +2 -0
- package/src/pm-plugins/table-resizing/utils/consts.ts +1 -0
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +25 -3
- package/src/toolbar.tsx +11 -1
- package/src/utils/alignment.ts +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.19.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`0c728cec893a0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0c728cec893a0) -
|
|
8
|
+
ED-23730: Change table to align center when column resizing makes table width wider than
|
|
9
|
+
linelength
|
|
10
|
+
|
|
11
|
+
## 7.19.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#115247](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/115247)
|
|
16
|
+
[`251d23ff9e6c8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/251d23ff9e6c8) -
|
|
17
|
+
upgrade adf-schema version to 38.0.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
3
23
|
## 7.18.4
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -37,7 +37,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
37
37
|
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; }
|
|
38
38
|
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; }
|
|
39
39
|
var RESIZE_STEP_VALUE = 10;
|
|
40
|
-
var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
41
40
|
var handles = {
|
|
42
41
|
right: true
|
|
43
42
|
};
|
|
@@ -174,9 +173,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
174
173
|
} : undefined;
|
|
175
174
|
}, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, isFullWidthModeEnabled]);
|
|
176
175
|
var switchToCenterAlignment = (0, _react.useCallback)(function (pos, node, newWidth, state, dispatch) {
|
|
177
|
-
if (isTableAlignmentEnabled
|
|
178
|
-
// We don't want to switch alignment in Full-width editor
|
|
179
|
-
isResizing.current) {
|
|
176
|
+
if ((0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, node, lineLength, newWidth) && isResizing.current) {
|
|
180
177
|
var _pluginInjectionApi$a;
|
|
181
178
|
var tableNodeWithPos = {
|
|
182
179
|
pos: pos,
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -178,12 +178,13 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
178
178
|
tableOptions = _ref5.tableOptions,
|
|
179
179
|
getEditorFeatureFlags = _ref5.getEditorFeatureFlags,
|
|
180
180
|
isTableScalingEnabled = _ref5.isTableScalingEnabled,
|
|
181
|
-
isNewColumnResizingEnabled = _ref5.isNewColumnResizingEnabled
|
|
181
|
+
isNewColumnResizingEnabled = _ref5.isNewColumnResizingEnabled,
|
|
182
|
+
isTableAlignmentEnabled = _ref5.isTableAlignmentEnabled;
|
|
182
183
|
var _pluginConfig = (0, _createPluginConfig.pluginConfig)(tableOptions),
|
|
183
184
|
allowColumnResizing = _pluginConfig.allowColumnResizing;
|
|
184
185
|
return allowColumnResizing ? (0, _tableResizing.createPlugin)(dispatch, {
|
|
185
186
|
lastColumnResizable: !fullWidthEnabled
|
|
186
|
-
}, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false, isNewColumnResizingEnabled) : undefined;
|
|
187
|
+
}, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false, isNewColumnResizingEnabled, isTableAlignmentEnabled) : undefined;
|
|
187
188
|
}
|
|
188
189
|
}, {
|
|
189
190
|
name: 'tableEditing',
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.handleMouseDown = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
10
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
9
11
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
@@ -13,16 +15,21 @@ var _columnResize = require("../../commands/column-resize");
|
|
|
13
15
|
var _misc = require("../../commands/misc");
|
|
14
16
|
var _transforms = require("../../transforms");
|
|
15
17
|
var _utils2 = require("../../utils");
|
|
18
|
+
var _alignment = require("../../utils/alignment");
|
|
16
19
|
var _pluginFactory = require("../plugin-factory");
|
|
17
20
|
var _tableAnalytics = require("../table-analytics");
|
|
18
21
|
var _commands = require("./commands");
|
|
19
22
|
var _pluginFactory2 = require("./plugin-factory");
|
|
20
23
|
var _utils3 = require("./utils");
|
|
21
|
-
var
|
|
24
|
+
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
|
+
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
|
+
var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
22
27
|
var state = view.state,
|
|
23
28
|
dispatch = view.dispatch;
|
|
24
29
|
var editorDisabled = !view.editable;
|
|
25
30
|
var domAtPos = view.domAtPos.bind(view);
|
|
31
|
+
var _getEditorContainerWi = getEditorContainerWidth(),
|
|
32
|
+
lineLength = _getEditorContainerWi.lineLength;
|
|
26
33
|
if (editorDisabled || localResizeHandlePos === null || !(0, _utils3.pointsAtCell)(state.doc.resolve(localResizeHandlePos))) {
|
|
27
34
|
return false;
|
|
28
35
|
}
|
|
@@ -133,6 +140,8 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
133
140
|
// There may be a more elegant solution to this, to avoid a jarring experience.
|
|
134
141
|
if (table.eq(originalTable)) {
|
|
135
142
|
var map = _tableMap.TableMap.get(table);
|
|
143
|
+
var totalRowCount = map.height;
|
|
144
|
+
var totalColumnCount = map.width;
|
|
136
145
|
var colIndex = map.colCount($cell.pos - start) + ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) - 1;
|
|
137
146
|
var selectionRect = (0, _utils.getSelectionRect)(state.selection);
|
|
138
147
|
var selectedColumns = selectionRect ? (0, _utils2.getSelectedColumnIndexes)(selectionRect) : [];
|
|
@@ -149,9 +158,34 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
149
158
|
// isTableScalingEnabled
|
|
150
159
|
undefined,
|
|
151
160
|
// originalTableWidth
|
|
152
|
-
shouldUseIncreasedScalingPercent);
|
|
161
|
+
shouldUseIncreasedScalingPercent, lineLength, isTableAlignmentEnabled);
|
|
153
162
|
tr = (0, _transforms.updateColumnWidths)(newResizeState, table, start)(tr);
|
|
154
|
-
|
|
163
|
+
|
|
164
|
+
// 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.tableWidth);
|
|
166
|
+
if (shouldChangeAlignment) {
|
|
167
|
+
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, _objectSpread(_objectSpread({}, table.attrs), {}, {
|
|
168
|
+
width: newResizeState.tableWidth,
|
|
169
|
+
layout: _alignment.ALIGN_CENTER
|
|
170
|
+
}));
|
|
171
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
172
|
+
action: _analytics.TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
173
|
+
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
|
|
174
|
+
actionSubjectId: null,
|
|
175
|
+
attributes: {
|
|
176
|
+
tableWidth: newResizeState.tableWidth,
|
|
177
|
+
newAlignment: _alignment.ALIGN_CENTER,
|
|
178
|
+
previousAlignment: _alignment.ALIGN_START,
|
|
179
|
+
totalRowCount: totalRowCount,
|
|
180
|
+
totalColumnCount: totalColumnCount,
|
|
181
|
+
inputMethod: _analytics.INPUT_METHOD.AUTO,
|
|
182
|
+
reason: _analytics.CHANGE_ALIGNMENT_REASON.TABLE_COLUMN_RESIZED
|
|
183
|
+
},
|
|
184
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
185
|
+
})(tr);
|
|
186
|
+
} else {
|
|
187
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
188
|
+
}
|
|
155
189
|
} else {
|
|
156
190
|
var _newResizeState = (0, _utils3.resizeColumn)(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale, shouldUseIncreasedScalingPercent);
|
|
157
191
|
tr = (0, _transforms.updateColumnWidths)(_newResizeState, table, start)(tr);
|
|
@@ -222,7 +256,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(view, e
|
|
|
222
256
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
223
257
|
}
|
|
224
258
|
if (isNewColumnResizingEnabled && !(0, _utils2.isTableNested)(state, tablePos)) {
|
|
225
|
-
(0, _utils3.resizeColumnAndTable)(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, undefined, shouldUseIncreasedScalingPercent);
|
|
259
|
+
(0, _utils3.resizeColumnAndTable)(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, undefined, shouldUseIncreasedScalingPercent, lineLength, isTableAlignmentEnabled);
|
|
226
260
|
} else {
|
|
227
261
|
(0, _utils3.resizeColumn)(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
228
262
|
}
|
|
@@ -15,7 +15,7 @@ var _eventHandlers = require("./event-handlers");
|
|
|
15
15
|
var _pluginFactory2 = require("./plugin-factory");
|
|
16
16
|
var _pluginKey = require("./plugin-key");
|
|
17
17
|
var _utils = require("./utils");
|
|
18
|
-
function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled) {
|
|
18
|
+
function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
19
19
|
var _ref$lastColumnResiza = _ref.lastColumnResizable,
|
|
20
20
|
lastColumnResizable = _ref$lastColumnResiza === void 0 ? true : _ref$lastColumnResiza;
|
|
21
21
|
return new _safePlugin.SafePlugin({
|
|
@@ -53,7 +53,7 @@ function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorFeatureF
|
|
|
53
53
|
isColumnKeyboardResizeStarted = isKeyboardResize;
|
|
54
54
|
}
|
|
55
55
|
if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
|
|
56
|
-
if ((0, _eventHandlers.handleMouseDown)(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI, isNewColumnResizingEnabled)) {
|
|
56
|
+
if ((0, _eventHandlers.handleMouseDown)(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled)) {
|
|
57
57
|
var _state = view.state,
|
|
58
58
|
_dispatch = view.dispatch;
|
|
59
59
|
return (0, _commands.setResizeHandlePos)(resizeHandlePos)(_state, _dispatch);
|
|
@@ -3,10 +3,11 @@
|
|
|
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.COLUMN_MIN_WIDTH = void 0;
|
|
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;
|
|
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;
|
|
10
|
+
var FULL_WIDTH_EDITOR_CONTENT_WIDTH = exports.FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
10
11
|
var MAX_SCALING_PERCENT = exports.MAX_SCALING_PERCENT = 0.3;
|
|
11
12
|
var MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = exports.MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
12
13
|
// Used to calculate the width of a table using the Editor width
|
|
@@ -33,6 +33,8 @@ var resizeColumnAndTable = exports.resizeColumnAndTable = function resizeColumnA
|
|
|
33
33
|
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
34
34
|
var originalTableWidth = arguments.length > 7 ? arguments[7] : undefined;
|
|
35
35
|
var shouldUseIncreasedScalingPercent = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
36
|
+
var lineLength = arguments.length > 9 ? arguments[9] : undefined;
|
|
37
|
+
var isTableAlignmentEnabled = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false;
|
|
36
38
|
// TODO: can we use document state, and apply scaling factor?
|
|
37
39
|
var tableWidth = tableRef.clientWidth;
|
|
38
40
|
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
@@ -63,17 +65,20 @@ var resizeColumnAndTable = exports.resizeColumnAndTable = function resizeColumnA
|
|
|
63
65
|
// use the difference in width from affected column to update overall table width
|
|
64
66
|
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
65
67
|
if (!isOverflowed) {
|
|
66
|
-
|
|
68
|
+
// 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
|
|
69
|
+
var shouldChangeAlignment = (0, _alignment.shouldChangeAlignmentToCenterResized)(isTableAlignmentEnabled, tableNode, lineLength, newState.tableWidth + delta);
|
|
70
|
+
shouldChangeAlignment ? updateTablePreview(delta, tableRef, tableNode, _alignment.ALIGN_CENTER) : updateTablePreview(delta, tableRef, tableNode);
|
|
67
71
|
}
|
|
68
72
|
return _objectSpread(_objectSpread({}, newState), {}, {
|
|
69
73
|
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
70
74
|
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
71
75
|
});
|
|
72
76
|
};
|
|
73
|
-
var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode) {
|
|
77
|
+
var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode, tableAligment) {
|
|
74
78
|
var currentWidth = (0, _misc.getTableContainerElementWidth)(tableNode);
|
|
75
79
|
var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(_types.TableCssClassName.TABLE_RESIZER_CONTAINER));
|
|
76
80
|
var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
81
|
+
var alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
77
82
|
if (resizingItem) {
|
|
78
83
|
var newWidth = "".concat(currentWidth + resizeAmount, "px");
|
|
79
84
|
if (tableRef) {
|
|
@@ -81,5 +86,8 @@ var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tab
|
|
|
81
86
|
}
|
|
82
87
|
resizingContainer.style.width = newWidth;
|
|
83
88
|
resizingItem.style.width = newWidth;
|
|
89
|
+
if (tableAligment && alignmentContainer) {
|
|
90
|
+
alignmentContainer.style.justifyContent = tableAligment;
|
|
91
|
+
}
|
|
84
92
|
}
|
|
85
93
|
};
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -350,7 +350,10 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
|
|
|
350
350
|
|
|
351
351
|
// We don't want to show floating toolbar while resizing the table
|
|
352
352
|
var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
353
|
-
|
|
353
|
+
|
|
354
|
+
// Hide floating toolbar when resizing column and internal column width is on
|
|
355
|
+
var shouldHideToolbarForInternalColumnWidth = Boolean((options === null || options === void 0 ? void 0 : options.isNewColumnResizingEnabled) && resizeState && resizeState.dragging);
|
|
356
|
+
if (tableObject && pluginState.editorHasFocus && !isWidthResizing && !shouldHideToolbarForInternalColumnWidth) {
|
|
354
357
|
var nodeType = state.schema.nodes.table;
|
|
355
358
|
var isNested = pluginState.tablePos && (0, _utils4.isTableNested)(state, pluginState.tablePos);
|
|
356
359
|
var isTableScalingWithFixedColumnWidthsOptionShown = isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && !isNested;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.normaliseAlignment = exports.ALIGN_START = exports.ALIGN_CENTER = void 0;
|
|
6
|
+
exports.shouldChangeAlignmentToCenterResized = exports.normaliseAlignment = exports.ALIGN_START = exports.ALIGN_CENTER = void 0;
|
|
7
|
+
var _consts = require("../pm-plugins/table-resizing/utils/consts");
|
|
7
8
|
var ALIGN_START = exports.ALIGN_START = 'align-start';
|
|
8
9
|
var ALIGN_CENTER = exports.ALIGN_CENTER = 'center';
|
|
9
10
|
|
|
@@ -13,4 +14,11 @@ var ALIGN_CENTER = exports.ALIGN_CENTER = 'center';
|
|
|
13
14
|
*/
|
|
14
15
|
var normaliseAlignment = exports.normaliseAlignment = function normaliseAlignment(layout) {
|
|
15
16
|
return layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* We don't want to switch alignment in Full-width editor
|
|
21
|
+
*/
|
|
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;
|
|
16
24
|
};
|
|
@@ -18,12 +18,11 @@ import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
|
18
18
|
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH } 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
|
-
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment } from '../utils/alignment';
|
|
21
|
+
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment, shouldChangeAlignmentToCenterResized } from '../utils/alignment';
|
|
22
22
|
import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
|
|
23
23
|
import { defaultGuidelines, defaultGuidelinesForPreserveTable, PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET } from '../utils/guidelines';
|
|
24
24
|
import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap, PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET } from '../utils/snapping';
|
|
25
25
|
const RESIZE_STEP_VALUE = 10;
|
|
26
|
-
const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
27
26
|
const handles = {
|
|
28
27
|
right: true
|
|
29
28
|
};
|
|
@@ -159,9 +158,7 @@ export const TableResizer = ({
|
|
|
159
158
|
isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPaddingDynamic() : containerWidth, excludeGuidelineConfig) : defaultSnappingWidths
|
|
160
159
|
} : undefined, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, isFullWidthModeEnabled]);
|
|
161
160
|
const switchToCenterAlignment = useCallback((pos, node, newWidth, state, dispatch) => {
|
|
162
|
-
if (isTableAlignmentEnabled
|
|
163
|
-
// We don't want to switch alignment in Full-width editor
|
|
164
|
-
isResizing.current) {
|
|
161
|
+
if (shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, node, lineLength, newWidth) && isResizing.current) {
|
|
165
162
|
var _pluginInjectionApi$a;
|
|
166
163
|
const tableNodeWithPos = {
|
|
167
164
|
pos,
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -170,14 +170,15 @@ const tablesPlugin = ({
|
|
|
170
170
|
tableOptions,
|
|
171
171
|
getEditorFeatureFlags,
|
|
172
172
|
isTableScalingEnabled,
|
|
173
|
-
isNewColumnResizingEnabled
|
|
173
|
+
isNewColumnResizingEnabled,
|
|
174
|
+
isTableAlignmentEnabled
|
|
174
175
|
} = options || {};
|
|
175
176
|
const {
|
|
176
177
|
allowColumnResizing
|
|
177
178
|
} = pluginConfig(tableOptions);
|
|
178
179
|
return allowColumnResizing ? createFlexiResizingPlugin(dispatch, {
|
|
179
180
|
lastColumnResizable: !fullWidthEnabled
|
|
180
|
-
}, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false, isNewColumnResizingEnabled) : undefined;
|
|
181
|
+
}, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false, isNewColumnResizingEnabled, isTableAlignmentEnabled) : undefined;
|
|
181
182
|
}
|
|
182
183
|
}, {
|
|
183
184
|
name: 'tableEditing',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
|
|
1
|
+
import { ACTION_SUBJECT, CHANGE_ALIGNMENT_REASON, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
3
3
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
4
4
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
@@ -7,18 +7,22 @@ import { stopKeyboardColumnResizing } from '../../commands/column-resize';
|
|
|
7
7
|
import { updateResizeHandleDecorations } from '../../commands/misc';
|
|
8
8
|
import { updateColumnWidths } from '../../transforms';
|
|
9
9
|
import { getSelectedColumnIndexes, isTableNested } from '../../utils';
|
|
10
|
+
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../utils/alignment';
|
|
10
11
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
11
12
|
import { META_KEYS } from '../table-analytics';
|
|
12
13
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
13
14
|
import { getPluginState } from './plugin-factory';
|
|
14
15
|
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
15
|
-
export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled) => {
|
|
16
|
+
export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) => {
|
|
16
17
|
const {
|
|
17
18
|
state,
|
|
18
19
|
dispatch
|
|
19
20
|
} = view;
|
|
20
21
|
const editorDisabled = !view.editable;
|
|
21
22
|
const domAtPos = view.domAtPos.bind(view);
|
|
23
|
+
const {
|
|
24
|
+
lineLength
|
|
25
|
+
} = getEditorContainerWidth();
|
|
22
26
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
23
27
|
return false;
|
|
24
28
|
}
|
|
@@ -140,6 +144,8 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
140
144
|
// There may be a more elegant solution to this, to avoid a jarring experience.
|
|
141
145
|
if (table.eq(originalTable)) {
|
|
142
146
|
const map = TableMap.get(table);
|
|
147
|
+
const totalRowCount = map.height;
|
|
148
|
+
const totalColumnCount = map.width;
|
|
143
149
|
const colIndex = map.colCount($cell.pos - start) + ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) - 1;
|
|
144
150
|
const selectionRect = getSelectionRect(state.selection);
|
|
145
151
|
const selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
|
|
@@ -156,9 +162,35 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
156
162
|
// isTableScalingEnabled
|
|
157
163
|
undefined,
|
|
158
164
|
// originalTableWidth
|
|
159
|
-
shouldUseIncreasedScalingPercent);
|
|
165
|
+
shouldUseIncreasedScalingPercent, lineLength, isTableAlignmentEnabled);
|
|
160
166
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
161
|
-
|
|
167
|
+
|
|
168
|
+
// 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.tableWidth);
|
|
170
|
+
if (shouldChangeAlignment) {
|
|
171
|
+
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, {
|
|
172
|
+
...table.attrs,
|
|
173
|
+
width: newResizeState.tableWidth,
|
|
174
|
+
layout: ALIGN_CENTER
|
|
175
|
+
});
|
|
176
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
177
|
+
action: TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
178
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
179
|
+
actionSubjectId: null,
|
|
180
|
+
attributes: {
|
|
181
|
+
tableWidth: newResizeState.tableWidth,
|
|
182
|
+
newAlignment: ALIGN_CENTER,
|
|
183
|
+
previousAlignment: ALIGN_START,
|
|
184
|
+
totalRowCount: totalRowCount,
|
|
185
|
+
totalColumnCount: totalColumnCount,
|
|
186
|
+
inputMethod: INPUT_METHOD.AUTO,
|
|
187
|
+
reason: CHANGE_ALIGNMENT_REASON.TABLE_COLUMN_RESIZED
|
|
188
|
+
},
|
|
189
|
+
eventType: EVENT_TYPE.TRACK
|
|
190
|
+
})(tr);
|
|
191
|
+
} else {
|
|
192
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
193
|
+
}
|
|
162
194
|
} else {
|
|
163
195
|
const newResizeState = resizeColumn(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
164
196
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
@@ -235,7 +267,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
235
267
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
236
268
|
}
|
|
237
269
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
238
|
-
resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, undefined, shouldUseIncreasedScalingPercent);
|
|
270
|
+
resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, undefined, shouldUseIncreasedScalingPercent, lineLength, isTableAlignmentEnabled);
|
|
239
271
|
} else {
|
|
240
272
|
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
241
273
|
}
|
|
@@ -9,7 +9,7 @@ import { pluginKey } from './plugin-key';
|
|
|
9
9
|
import { getResizeCellPos } from './utils';
|
|
10
10
|
export function createPlugin(dispatch, {
|
|
11
11
|
lastColumnResizable = true
|
|
12
|
-
}, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled) {
|
|
12
|
+
}, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
13
13
|
return new SafePlugin({
|
|
14
14
|
key: pluginKey,
|
|
15
15
|
state: createPluginState(dispatch, {
|
|
@@ -51,7 +51,7 @@ export function createPlugin(dispatch, {
|
|
|
51
51
|
isColumnKeyboardResizeStarted = isKeyboardResize;
|
|
52
52
|
}
|
|
53
53
|
if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
|
|
54
|
-
if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI, isNewColumnResizingEnabled)) {
|
|
54
|
+
if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled)) {
|
|
55
55
|
const {
|
|
56
56
|
state,
|
|
57
57
|
dispatch
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export const TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export const TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export const MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
// Used to calculate the width of a table using the Editor width
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
|
|
3
3
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
4
|
-
import { ALIGN_START } from '../../../utils/alignment';
|
|
4
|
+
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
|
|
5
5
|
import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
|
|
6
6
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
7
7
|
import { updateColgroup } from './resize-state';
|
|
@@ -18,7 +18,7 @@ export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode,
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
// try not scale table during resize
|
|
21
|
-
export const resizeColumnAndTable = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false, originalTableWidth, shouldUseIncreasedScalingPercent = false) => {
|
|
21
|
+
export const resizeColumnAndTable = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false, originalTableWidth, shouldUseIncreasedScalingPercent = false, lineLength, isTableAlignmentEnabled = false) => {
|
|
22
22
|
var _tableRef$closest;
|
|
23
23
|
// TODO: can we use document state, and apply scaling factor?
|
|
24
24
|
const tableWidth = tableRef.clientWidth;
|
|
@@ -50,7 +50,9 @@ export const resizeColumnAndTable = (resizeState, colIndex, amount, tableRef, ta
|
|
|
50
50
|
// use the difference in width from affected column to update overall table width
|
|
51
51
|
const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
52
52
|
if (!isOverflowed) {
|
|
53
|
-
|
|
53
|
+
// 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
|
|
54
|
+
const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.tableWidth + delta);
|
|
55
|
+
shouldChangeAlignment ? updateTablePreview(delta, tableRef, tableNode, ALIGN_CENTER) : updateTablePreview(delta, tableRef, tableNode);
|
|
54
56
|
}
|
|
55
57
|
return {
|
|
56
58
|
...newState,
|
|
@@ -58,10 +60,11 @@ export const resizeColumnAndTable = (resizeState, colIndex, amount, tableRef, ta
|
|
|
58
60
|
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
59
61
|
};
|
|
60
62
|
};
|
|
61
|
-
const updateTablePreview = (resizeAmount, tableRef, tableNode) => {
|
|
63
|
+
const updateTablePreview = (resizeAmount, tableRef, tableNode, tableAligment) => {
|
|
62
64
|
const currentWidth = getTableContainerElementWidth(tableNode);
|
|
63
65
|
const resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
64
66
|
const resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
67
|
+
const alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
65
68
|
if (resizingItem) {
|
|
66
69
|
const newWidth = `${currentWidth + resizeAmount}px`;
|
|
67
70
|
if (tableRef) {
|
|
@@ -69,5 +72,8 @@ const updateTablePreview = (resizeAmount, tableRef, tableNode) => {
|
|
|
69
72
|
}
|
|
70
73
|
resizingContainer.style.width = newWidth;
|
|
71
74
|
resizingItem.style.width = newWidth;
|
|
75
|
+
if (tableAligment && alignmentContainer) {
|
|
76
|
+
alignmentContainer.style.justifyContent = tableAligment;
|
|
77
|
+
}
|
|
72
78
|
}
|
|
73
79
|
};
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -329,7 +329,10 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
|
|
|
329
329
|
|
|
330
330
|
// We don't want to show floating toolbar while resizing the table
|
|
331
331
|
const isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
332
|
-
|
|
332
|
+
|
|
333
|
+
// Hide floating toolbar when resizing column and internal column width is on
|
|
334
|
+
const shouldHideToolbarForInternalColumnWidth = Boolean((options === null || options === void 0 ? void 0 : options.isNewColumnResizingEnabled) && resizeState && resizeState.dragging);
|
|
335
|
+
if (tableObject && pluginState.editorHasFocus && !isWidthResizing && !shouldHideToolbarForInternalColumnWidth) {
|
|
333
336
|
const nodeType = state.schema.nodes.table;
|
|
334
337
|
const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
335
338
|
const isTableScalingWithFixedColumnWidthsOptionShown = isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && !isNested;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FULL_WIDTH_EDITOR_CONTENT_WIDTH } from '../pm-plugins/table-resizing/utils/consts';
|
|
1
2
|
export const ALIGN_START = 'align-start';
|
|
2
3
|
export const ALIGN_CENTER = 'center';
|
|
3
4
|
|
|
@@ -5,4 +6,9 @@ export const ALIGN_CENTER = 'center';
|
|
|
5
6
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
6
7
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
7
8
|
*/
|
|
8
|
-
export const normaliseAlignment = layout => layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
9
|
+
export const normaliseAlignment = layout => layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* We don't want to switch alignment in Full-width editor
|
|
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;
|
|
@@ -22,12 +22,11 @@ import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
|
22
22
|
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH } 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
|
-
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment } from '../utils/alignment';
|
|
25
|
+
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment, shouldChangeAlignmentToCenterResized } from '../utils/alignment';
|
|
26
26
|
import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
|
|
27
27
|
import { defaultGuidelines, defaultGuidelinesForPreserveTable, PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET } from '../utils/guidelines';
|
|
28
28
|
import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap, PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET } from '../utils/snapping';
|
|
29
29
|
var RESIZE_STEP_VALUE = 10;
|
|
30
|
-
var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
31
30
|
var handles = {
|
|
32
31
|
right: true
|
|
33
32
|
};
|
|
@@ -164,9 +163,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
164
163
|
} : undefined;
|
|
165
164
|
}, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, isFullWidthModeEnabled]);
|
|
166
165
|
var switchToCenterAlignment = useCallback(function (pos, node, newWidth, state, dispatch) {
|
|
167
|
-
if (isTableAlignmentEnabled
|
|
168
|
-
// We don't want to switch alignment in Full-width editor
|
|
169
|
-
isResizing.current) {
|
|
166
|
+
if (shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, node, lineLength, newWidth) && isResizing.current) {
|
|
170
167
|
var _pluginInjectionApi$a;
|
|
171
168
|
var tableNodeWithPos = {
|
|
172
169
|
pos: pos,
|
package/dist/esm/plugin.js
CHANGED
|
@@ -171,12 +171,13 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
171
171
|
tableOptions = _ref5.tableOptions,
|
|
172
172
|
getEditorFeatureFlags = _ref5.getEditorFeatureFlags,
|
|
173
173
|
isTableScalingEnabled = _ref5.isTableScalingEnabled,
|
|
174
|
-
isNewColumnResizingEnabled = _ref5.isNewColumnResizingEnabled
|
|
174
|
+
isNewColumnResizingEnabled = _ref5.isNewColumnResizingEnabled,
|
|
175
|
+
isTableAlignmentEnabled = _ref5.isTableAlignmentEnabled;
|
|
175
176
|
var _pluginConfig = pluginConfig(tableOptions),
|
|
176
177
|
allowColumnResizing = _pluginConfig.allowColumnResizing;
|
|
177
178
|
return allowColumnResizing ? createFlexiResizingPlugin(dispatch, {
|
|
178
179
|
lastColumnResizable: !fullWidthEnabled
|
|
179
|
-
}, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false, isNewColumnResizingEnabled) : undefined;
|
|
180
|
+
}, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false, isNewColumnResizingEnabled, isTableAlignmentEnabled) : undefined;
|
|
180
181
|
}
|
|
181
182
|
}, {
|
|
182
183
|
name: 'tableEditing',
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { ACTION_SUBJECT, CHANGE_ALIGNMENT_REASON, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
|
|
2
5
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
3
6
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
4
7
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
@@ -7,16 +10,19 @@ import { stopKeyboardColumnResizing } from '../../commands/column-resize';
|
|
|
7
10
|
import { updateResizeHandleDecorations } from '../../commands/misc';
|
|
8
11
|
import { updateColumnWidths } from '../../transforms';
|
|
9
12
|
import { getSelectedColumnIndexes, isTableNested } from '../../utils';
|
|
13
|
+
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../utils/alignment';
|
|
10
14
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
11
15
|
import { META_KEYS } from '../table-analytics';
|
|
12
16
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
13
17
|
import { getPluginState } from './plugin-factory';
|
|
14
18
|
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
15
|
-
export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled) {
|
|
19
|
+
export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
16
20
|
var state = view.state,
|
|
17
21
|
dispatch = view.dispatch;
|
|
18
22
|
var editorDisabled = !view.editable;
|
|
19
23
|
var domAtPos = view.domAtPos.bind(view);
|
|
24
|
+
var _getEditorContainerWi = getEditorContainerWidth(),
|
|
25
|
+
lineLength = _getEditorContainerWi.lineLength;
|
|
20
26
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
21
27
|
return false;
|
|
22
28
|
}
|
|
@@ -127,6 +133,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
127
133
|
// There may be a more elegant solution to this, to avoid a jarring experience.
|
|
128
134
|
if (table.eq(originalTable)) {
|
|
129
135
|
var map = TableMap.get(table);
|
|
136
|
+
var totalRowCount = map.height;
|
|
137
|
+
var totalColumnCount = map.width;
|
|
130
138
|
var colIndex = map.colCount($cell.pos - start) + ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) - 1;
|
|
131
139
|
var selectionRect = getSelectionRect(state.selection);
|
|
132
140
|
var selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
|
|
@@ -143,9 +151,34 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
143
151
|
// isTableScalingEnabled
|
|
144
152
|
undefined,
|
|
145
153
|
// originalTableWidth
|
|
146
|
-
shouldUseIncreasedScalingPercent);
|
|
154
|
+
shouldUseIncreasedScalingPercent, lineLength, isTableAlignmentEnabled);
|
|
147
155
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
148
|
-
|
|
156
|
+
|
|
157
|
+
// 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.tableWidth);
|
|
159
|
+
if (shouldChangeAlignment) {
|
|
160
|
+
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, _objectSpread(_objectSpread({}, table.attrs), {}, {
|
|
161
|
+
width: newResizeState.tableWidth,
|
|
162
|
+
layout: ALIGN_CENTER
|
|
163
|
+
}));
|
|
164
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
165
|
+
action: TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
166
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
167
|
+
actionSubjectId: null,
|
|
168
|
+
attributes: {
|
|
169
|
+
tableWidth: newResizeState.tableWidth,
|
|
170
|
+
newAlignment: ALIGN_CENTER,
|
|
171
|
+
previousAlignment: ALIGN_START,
|
|
172
|
+
totalRowCount: totalRowCount,
|
|
173
|
+
totalColumnCount: totalColumnCount,
|
|
174
|
+
inputMethod: INPUT_METHOD.AUTO,
|
|
175
|
+
reason: CHANGE_ALIGNMENT_REASON.TABLE_COLUMN_RESIZED
|
|
176
|
+
},
|
|
177
|
+
eventType: EVENT_TYPE.TRACK
|
|
178
|
+
})(tr);
|
|
179
|
+
} else {
|
|
180
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
181
|
+
}
|
|
149
182
|
} else {
|
|
150
183
|
var _newResizeState = resizeColumn(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale, shouldUseIncreasedScalingPercent);
|
|
151
184
|
tr = updateColumnWidths(_newResizeState, table, start)(tr);
|
|
@@ -216,7 +249,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
216
249
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
217
250
|
}
|
|
218
251
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
219
|
-
resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, undefined, shouldUseIncreasedScalingPercent);
|
|
252
|
+
resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, undefined, shouldUseIncreasedScalingPercent, lineLength, isTableAlignmentEnabled);
|
|
220
253
|
} else {
|
|
221
254
|
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
222
255
|
}
|
|
@@ -8,7 +8,7 @@ import { handleMouseDown } from './event-handlers';
|
|
|
8
8
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
9
9
|
import { pluginKey } from './plugin-key';
|
|
10
10
|
import { getResizeCellPos } from './utils';
|
|
11
|
-
export function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled) {
|
|
11
|
+
export function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
12
12
|
var _ref$lastColumnResiza = _ref.lastColumnResizable,
|
|
13
13
|
lastColumnResizable = _ref$lastColumnResiza === void 0 ? true : _ref$lastColumnResiza;
|
|
14
14
|
return new SafePlugin({
|
|
@@ -46,7 +46,7 @@ export function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorF
|
|
|
46
46
|
isColumnKeyboardResizeStarted = isKeyboardResize;
|
|
47
47
|
}
|
|
48
48
|
if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
|
|
49
|
-
if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI, isNewColumnResizingEnabled)) {
|
|
49
|
+
if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled)) {
|
|
50
50
|
var _state = view.state,
|
|
51
51
|
_dispatch = view.dispatch;
|
|
52
52
|
return setResizeHandlePos(resizeHandlePos)(_state, _dispatch);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export var COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export var TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export var TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export var MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export var MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
// Used to calculate the width of a table using the Editor width
|
|
@@ -4,7 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
// Resize a given column by an amount from the current state
|
|
5
5
|
|
|
6
6
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
7
|
-
import { ALIGN_START } from '../../../utils/alignment';
|
|
7
|
+
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
|
|
8
8
|
import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
|
|
9
9
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
10
10
|
import { updateColgroup } from './resize-state';
|
|
@@ -28,6 +28,8 @@ export var resizeColumnAndTable = function resizeColumnAndTable(resizeState, col
|
|
|
28
28
|
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
29
29
|
var originalTableWidth = arguments.length > 7 ? arguments[7] : undefined;
|
|
30
30
|
var shouldUseIncreasedScalingPercent = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
31
|
+
var lineLength = arguments.length > 9 ? arguments[9] : undefined;
|
|
32
|
+
var isTableAlignmentEnabled = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false;
|
|
31
33
|
// TODO: can we use document state, and apply scaling factor?
|
|
32
34
|
var tableWidth = tableRef.clientWidth;
|
|
33
35
|
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
@@ -58,17 +60,20 @@ export var resizeColumnAndTable = function resizeColumnAndTable(resizeState, col
|
|
|
58
60
|
// use the difference in width from affected column to update overall table width
|
|
59
61
|
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
60
62
|
if (!isOverflowed) {
|
|
61
|
-
|
|
63
|
+
// If the table is aligned to the start and the table width is greater than the line length, we should change the alignment to center
|
|
64
|
+
var shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.tableWidth + delta);
|
|
65
|
+
shouldChangeAlignment ? updateTablePreview(delta, tableRef, tableNode, ALIGN_CENTER) : updateTablePreview(delta, tableRef, tableNode);
|
|
62
66
|
}
|
|
63
67
|
return _objectSpread(_objectSpread({}, newState), {}, {
|
|
64
68
|
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
65
69
|
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
66
70
|
});
|
|
67
71
|
};
|
|
68
|
-
var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode) {
|
|
72
|
+
var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode, tableAligment) {
|
|
69
73
|
var currentWidth = getTableContainerElementWidth(tableNode);
|
|
70
74
|
var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
|
|
71
75
|
var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
76
|
+
var alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
72
77
|
if (resizingItem) {
|
|
73
78
|
var newWidth = "".concat(currentWidth + resizeAmount, "px");
|
|
74
79
|
if (tableRef) {
|
|
@@ -76,5 +81,8 @@ var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tab
|
|
|
76
81
|
}
|
|
77
82
|
resizingContainer.style.width = newWidth;
|
|
78
83
|
resizingItem.style.width = newWidth;
|
|
84
|
+
if (tableAligment && alignmentContainer) {
|
|
85
|
+
alignmentContainer.style.justifyContent = tableAligment;
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
88
|
};
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -342,7 +342,10 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
342
342
|
|
|
343
343
|
// We don't want to show floating toolbar while resizing the table
|
|
344
344
|
var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
345
|
-
|
|
345
|
+
|
|
346
|
+
// Hide floating toolbar when resizing column and internal column width is on
|
|
347
|
+
var shouldHideToolbarForInternalColumnWidth = Boolean((options === null || options === void 0 ? void 0 : options.isNewColumnResizingEnabled) && resizeState && resizeState.dragging);
|
|
348
|
+
if (tableObject && pluginState.editorHasFocus && !isWidthResizing && !shouldHideToolbarForInternalColumnWidth) {
|
|
346
349
|
var nodeType = state.schema.nodes.table;
|
|
347
350
|
var isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
348
351
|
var isTableScalingWithFixedColumnWidthsOptionShown = isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && !isNested;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FULL_WIDTH_EDITOR_CONTENT_WIDTH } from '../pm-plugins/table-resizing/utils/consts';
|
|
1
2
|
export var ALIGN_START = 'align-start';
|
|
2
3
|
export var ALIGN_CENTER = 'center';
|
|
3
4
|
|
|
@@ -7,4 +8,11 @@ export var ALIGN_CENTER = 'center';
|
|
|
7
8
|
*/
|
|
8
9
|
export var normaliseAlignment = function normaliseAlignment(layout) {
|
|
9
10
|
return layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* We don't want to switch alignment in Full-width editor
|
|
15
|
+
*/
|
|
16
|
+
export var shouldChangeAlignmentToCenterResized = function shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) {
|
|
17
|
+
return isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH;
|
|
10
18
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
export declare const handleMouseDown: (view: EditorView, event: MouseEvent, localResizeHandlePos: number, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, isTableScalingEnabled: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, isNewColumnResizingEnabled?: boolean) => boolean;
|
|
4
|
+
export declare const handleMouseDown: (view: EditorView, event: MouseEvent, localResizeHandlePos: number, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, isTableScalingEnabled: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, isNewColumnResizingEnabled?: boolean, isTableAlignmentEnabled?: boolean) => boolean;
|
|
@@ -3,4 +3,4 @@ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
5
|
import type { ColumnResizingPluginState } from '../../types';
|
|
6
|
-
export declare function createPlugin(dispatch: Dispatch<ColumnResizingPluginState>, { lastColumnResizable }: ColumnResizingPluginState, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI, isTableScalingEnabled?: boolean, isNewColumnResizingEnabled?: boolean): SafePlugin<ColumnResizingPluginState>;
|
|
6
|
+
export declare function createPlugin(dispatch: Dispatch<ColumnResizingPluginState>, { lastColumnResizable }: ColumnResizingPluginState, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI, isTableScalingEnabled?: boolean, isNewColumnResizingEnabled?: boolean, isTableAlignmentEnabled?: boolean): SafePlugin<ColumnResizingPluginState>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export declare const TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export declare const TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export declare const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export declare const MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export declare const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
export declare const TABLE_EDITOR_MARGIN = 76;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { ResizeState } from './types';
|
|
3
3
|
export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
-
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
+
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean, lineLength?: number, isTableAlignmentEnabled?: boolean) => ResizeState;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { AlignmentOptions } from '../types';
|
|
3
4
|
export declare const ALIGN_START = "align-start";
|
|
4
5
|
export declare const ALIGN_CENTER = "center";
|
|
@@ -7,3 +8,7 @@ export declare const ALIGN_CENTER = "center";
|
|
|
7
8
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
8
9
|
*/
|
|
9
10
|
export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptions;
|
|
11
|
+
/**
|
|
12
|
+
* We don't want to switch alignment in Full-width editor
|
|
13
|
+
*/
|
|
14
|
+
export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean | 0 | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
export declare const handleMouseDown: (view: EditorView, event: MouseEvent, localResizeHandlePos: number, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, isTableScalingEnabled: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, isNewColumnResizingEnabled?: boolean) => boolean;
|
|
4
|
+
export declare const handleMouseDown: (view: EditorView, event: MouseEvent, localResizeHandlePos: number, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, isTableScalingEnabled: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, isNewColumnResizingEnabled?: boolean, isTableAlignmentEnabled?: boolean) => boolean;
|
|
@@ -3,4 +3,4 @@ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
5
|
import type { ColumnResizingPluginState } from '../../types';
|
|
6
|
-
export declare function createPlugin(dispatch: Dispatch<ColumnResizingPluginState>, { lastColumnResizable }: ColumnResizingPluginState, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI, isTableScalingEnabled?: boolean, isNewColumnResizingEnabled?: boolean): SafePlugin<ColumnResizingPluginState>;
|
|
6
|
+
export declare function createPlugin(dispatch: Dispatch<ColumnResizingPluginState>, { lastColumnResizable }: ColumnResizingPluginState, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI, isTableScalingEnabled?: boolean, isNewColumnResizingEnabled?: boolean, isTableAlignmentEnabled?: boolean): SafePlugin<ColumnResizingPluginState>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export declare const TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export declare const TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export declare const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export declare const MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export declare const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
export declare const TABLE_EDITOR_MARGIN = 76;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { ResizeState } from './types';
|
|
3
3
|
export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
-
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
+
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean, lineLength?: number, isTableAlignmentEnabled?: boolean) => ResizeState;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { AlignmentOptions } from '../types';
|
|
3
4
|
export declare const ALIGN_START = "align-start";
|
|
4
5
|
export declare const ALIGN_CENTER = "center";
|
|
@@ -7,3 +8,7 @@ export declare const ALIGN_CENTER = "center";
|
|
|
7
8
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
8
9
|
*/
|
|
9
10
|
export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptions;
|
|
11
|
+
/**
|
|
12
|
+
* We don't want to switch alignment in Full-width editor
|
|
13
|
+
*/
|
|
14
|
+
export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean | 0 | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.19.1",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"runReact18": false
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@atlaskit/adf-schema": "^
|
|
31
|
+
"@atlaskit/adf-schema": "^38.0.0",
|
|
32
32
|
"@atlaskit/button": "^18.0.0",
|
|
33
|
-
"@atlaskit/custom-steps": "^0.
|
|
34
|
-
"@atlaskit/editor-common": "^83.
|
|
33
|
+
"@atlaskit/custom-steps": "^0.4.0",
|
|
34
|
+
"@atlaskit/editor-common": "^83.3.0",
|
|
35
35
|
"@atlaskit/editor-palette": "1.6.0",
|
|
36
36
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
|
|
37
|
-
"@atlaskit/editor-plugin-analytics": "^1.
|
|
38
|
-
"@atlaskit/editor-plugin-content-insertion": "^1.
|
|
37
|
+
"@atlaskit/editor-plugin-analytics": "^1.4.0",
|
|
38
|
+
"@atlaskit/editor-plugin-content-insertion": "^1.4.0",
|
|
39
39
|
"@atlaskit/editor-plugin-editor-viewmode": "^2.0.0",
|
|
40
40
|
"@atlaskit/editor-plugin-guideline": "^1.1.0",
|
|
41
41
|
"@atlaskit/editor-plugin-selection": "^1.2.0",
|
|
@@ -45,7 +45,12 @@ import {
|
|
|
45
45
|
TABLE_HIGHLIGHT_TOLERANCE,
|
|
46
46
|
TABLE_SNAP_GAP,
|
|
47
47
|
} from '../ui/consts';
|
|
48
|
-
import {
|
|
48
|
+
import {
|
|
49
|
+
ALIGN_CENTER,
|
|
50
|
+
ALIGN_START,
|
|
51
|
+
normaliseAlignment,
|
|
52
|
+
shouldChangeAlignmentToCenterResized,
|
|
53
|
+
} from '../utils/alignment';
|
|
49
54
|
import {
|
|
50
55
|
generateResizedPayload,
|
|
51
56
|
generateResizeFrameRatePayloads,
|
|
@@ -94,8 +99,6 @@ type ResizerNextHandler = React.ElementRef<typeof ResizerNext>;
|
|
|
94
99
|
|
|
95
100
|
const RESIZE_STEP_VALUE = 10;
|
|
96
101
|
|
|
97
|
-
const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
98
|
-
|
|
99
102
|
const handles = { right: true };
|
|
100
103
|
const handleStyles = {
|
|
101
104
|
right: {
|
|
@@ -296,11 +299,7 @@ export const TableResizer = ({
|
|
|
296
299
|
dispatch: ((tr: Transaction) => void) | undefined,
|
|
297
300
|
) => {
|
|
298
301
|
if (
|
|
299
|
-
isTableAlignmentEnabled &&
|
|
300
|
-
node &&
|
|
301
|
-
node.attrs.layout === ALIGN_START &&
|
|
302
|
-
newWidth > lineLength &&
|
|
303
|
-
lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH && // We don't want to switch alignment in Full-width editor
|
|
302
|
+
shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, node, lineLength, newWidth) &&
|
|
304
303
|
isResizing.current
|
|
305
304
|
) {
|
|
306
305
|
const tableNodeWithPos = { pos, node };
|
package/src/plugin.tsx
CHANGED
|
@@ -303,6 +303,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
303
303
|
getEditorFeatureFlags,
|
|
304
304
|
isTableScalingEnabled,
|
|
305
305
|
isNewColumnResizingEnabled,
|
|
306
|
+
isTableAlignmentEnabled,
|
|
306
307
|
} = options || ({} as TablePluginOptions);
|
|
307
308
|
const { allowColumnResizing } = pluginConfig(tableOptions);
|
|
308
309
|
return allowColumnResizing
|
|
@@ -316,6 +317,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
316
317
|
editorAnalyticsAPI,
|
|
317
318
|
isTableScalingEnabled || false,
|
|
318
319
|
isNewColumnResizingEnabled,
|
|
320
|
+
isTableAlignmentEnabled,
|
|
319
321
|
)
|
|
320
322
|
: undefined;
|
|
321
323
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CellAttributes } from '@atlaskit/adf-schema';
|
|
2
2
|
import {
|
|
3
3
|
ACTION_SUBJECT,
|
|
4
|
+
CHANGE_ALIGNMENT_REASON,
|
|
4
5
|
EVENT_TYPE,
|
|
5
6
|
INPUT_METHOD,
|
|
6
7
|
TABLE_ACTION,
|
|
@@ -18,6 +19,11 @@ import { stopKeyboardColumnResizing } from '../../commands/column-resize';
|
|
|
18
19
|
import { updateResizeHandleDecorations } from '../../commands/misc';
|
|
19
20
|
import { updateColumnWidths } from '../../transforms';
|
|
20
21
|
import { getSelectedColumnIndexes, isTableNested } from '../../utils';
|
|
22
|
+
import {
|
|
23
|
+
ALIGN_CENTER,
|
|
24
|
+
ALIGN_START,
|
|
25
|
+
shouldChangeAlignmentToCenterResized,
|
|
26
|
+
} from '../../utils/alignment';
|
|
21
27
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
22
28
|
import { META_KEYS } from '../table-analytics';
|
|
23
29
|
|
|
@@ -42,10 +48,12 @@ export const handleMouseDown = (
|
|
|
42
48
|
isTableScalingEnabled: boolean,
|
|
43
49
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
44
50
|
isNewColumnResizingEnabled?: boolean,
|
|
51
|
+
isTableAlignmentEnabled?: boolean,
|
|
45
52
|
): boolean => {
|
|
46
53
|
const { state, dispatch } = view;
|
|
47
54
|
const editorDisabled = !view.editable;
|
|
48
55
|
const domAtPos = view.domAtPos.bind(view);
|
|
56
|
+
const { lineLength } = getEditorContainerWidth();
|
|
49
57
|
|
|
50
58
|
if (
|
|
51
59
|
editorDisabled ||
|
|
@@ -171,6 +179,8 @@ export const handleMouseDown = (
|
|
|
171
179
|
// There may be a more elegant solution to this, to avoid a jarring experience.
|
|
172
180
|
if (table.eq(originalTable)) {
|
|
173
181
|
const map = TableMap.get(table);
|
|
182
|
+
const totalRowCount = map.height;
|
|
183
|
+
const totalColumnCount = map.width;
|
|
174
184
|
const colIndex =
|
|
175
185
|
map.colCount($cell.pos - start) +
|
|
176
186
|
($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) -
|
|
@@ -202,9 +212,43 @@ export const handleMouseDown = (
|
|
|
202
212
|
shouldScale, // isTableScalingEnabled
|
|
203
213
|
undefined, // originalTableWidth
|
|
204
214
|
shouldUseIncreasedScalingPercent,
|
|
215
|
+
lineLength,
|
|
216
|
+
isTableAlignmentEnabled,
|
|
205
217
|
);
|
|
206
218
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
207
|
-
|
|
219
|
+
|
|
220
|
+
// 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
|
|
221
|
+
const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(
|
|
222
|
+
isTableAlignmentEnabled,
|
|
223
|
+
originalTable,
|
|
224
|
+
lineLength,
|
|
225
|
+
newResizeState.tableWidth,
|
|
226
|
+
);
|
|
227
|
+
if (shouldChangeAlignment) {
|
|
228
|
+
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, {
|
|
229
|
+
...table.attrs,
|
|
230
|
+
width: newResizeState.tableWidth,
|
|
231
|
+
layout: ALIGN_CENTER,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
editorAnalyticsAPI?.attachAnalyticsEvent({
|
|
235
|
+
action: TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
236
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
237
|
+
actionSubjectId: null,
|
|
238
|
+
attributes: {
|
|
239
|
+
tableWidth: newResizeState.tableWidth,
|
|
240
|
+
newAlignment: ALIGN_CENTER,
|
|
241
|
+
previousAlignment: ALIGN_START,
|
|
242
|
+
totalRowCount: totalRowCount,
|
|
243
|
+
totalColumnCount: totalColumnCount,
|
|
244
|
+
inputMethod: INPUT_METHOD.AUTO,
|
|
245
|
+
reason: CHANGE_ALIGNMENT_REASON.TABLE_COLUMN_RESIZED,
|
|
246
|
+
},
|
|
247
|
+
eventType: EVENT_TYPE.TRACK,
|
|
248
|
+
})(tr);
|
|
249
|
+
} else {
|
|
250
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
251
|
+
}
|
|
208
252
|
} else {
|
|
209
253
|
const newResizeState = resizeColumn(
|
|
210
254
|
resizeState,
|
|
@@ -304,6 +348,8 @@ export const handleMouseDown = (
|
|
|
304
348
|
shouldScale,
|
|
305
349
|
undefined,
|
|
306
350
|
shouldUseIncreasedScalingPercent,
|
|
351
|
+
lineLength,
|
|
352
|
+
isTableAlignmentEnabled,
|
|
307
353
|
);
|
|
308
354
|
} else {
|
|
309
355
|
resizeColumn(
|
|
@@ -23,6 +23,7 @@ export function createPlugin(
|
|
|
23
23
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
24
24
|
isTableScalingEnabled?: boolean,
|
|
25
25
|
isNewColumnResizingEnabled?: boolean,
|
|
26
|
+
isTableAlignmentEnabled?: boolean,
|
|
26
27
|
) {
|
|
27
28
|
return new SafePlugin({
|
|
28
29
|
key: pluginKey,
|
|
@@ -74,6 +75,7 @@ export function createPlugin(
|
|
|
74
75
|
isTableScalingEnabled || false,
|
|
75
76
|
editorAnalyticsAPI,
|
|
76
77
|
isNewColumnResizingEnabled,
|
|
78
|
+
isTableAlignmentEnabled,
|
|
77
79
|
)
|
|
78
80
|
) {
|
|
79
81
|
const { state, dispatch } = view;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export const TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export const TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export const MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
// Used to calculate the width of a table using the Editor width
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
|
|
4
|
-
import { TableCssClassName as ClassName } from '../../../types';
|
|
5
|
-
import {
|
|
4
|
+
import { type AlignmentOptions, TableCssClassName as ClassName } from '../../../types';
|
|
5
|
+
import {
|
|
6
|
+
ALIGN_CENTER,
|
|
7
|
+
ALIGN_START,
|
|
8
|
+
shouldChangeAlignmentToCenterResized,
|
|
9
|
+
} from '../../../utils/alignment';
|
|
6
10
|
|
|
7
11
|
import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
|
|
8
12
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
@@ -56,6 +60,8 @@ export const resizeColumnAndTable = (
|
|
|
56
60
|
isTableScalingEnabled = false,
|
|
57
61
|
originalTableWidth?: number,
|
|
58
62
|
shouldUseIncreasedScalingPercent = false,
|
|
63
|
+
lineLength?: number,
|
|
64
|
+
isTableAlignmentEnabled = false,
|
|
59
65
|
): ResizeState => {
|
|
60
66
|
// TODO: can we use document state, and apply scaling factor?
|
|
61
67
|
const tableWidth = tableRef.clientWidth;
|
|
@@ -93,7 +99,17 @@ export const resizeColumnAndTable = (
|
|
|
93
99
|
const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
94
100
|
|
|
95
101
|
if (!isOverflowed) {
|
|
96
|
-
|
|
102
|
+
// 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
|
|
103
|
+
const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(
|
|
104
|
+
isTableAlignmentEnabled,
|
|
105
|
+
tableNode,
|
|
106
|
+
lineLength,
|
|
107
|
+
newState.tableWidth + delta,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
shouldChangeAlignment
|
|
111
|
+
? updateTablePreview(delta, tableRef, tableNode, ALIGN_CENTER)
|
|
112
|
+
: updateTablePreview(delta, tableRef, tableNode);
|
|
97
113
|
}
|
|
98
114
|
|
|
99
115
|
return {
|
|
@@ -107,10 +123,12 @@ const updateTablePreview = (
|
|
|
107
123
|
resizeAmount: number,
|
|
108
124
|
tableRef: HTMLElement | null,
|
|
109
125
|
tableNode: PmNode,
|
|
126
|
+
tableAligment?: AlignmentOptions,
|
|
110
127
|
) => {
|
|
111
128
|
const currentWidth = getTableContainerElementWidth(tableNode);
|
|
112
129
|
const resizingContainer = tableRef?.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
|
|
113
130
|
const resizingItem = resizingContainer?.querySelector('.resizer-item');
|
|
131
|
+
const alignmentContainer = resizingContainer?.parentElement;
|
|
114
132
|
|
|
115
133
|
if (resizingItem) {
|
|
116
134
|
const newWidth = `${currentWidth + resizeAmount}px`;
|
|
@@ -119,5 +137,9 @@ const updateTablePreview = (
|
|
|
119
137
|
}
|
|
120
138
|
(resizingContainer as HTMLElement).style.width = newWidth;
|
|
121
139
|
(resizingItem as HTMLElement).style.width = newWidth;
|
|
140
|
+
|
|
141
|
+
if (tableAligment && alignmentContainer) {
|
|
142
|
+
alignmentContainer.style.justifyContent = tableAligment;
|
|
143
|
+
}
|
|
122
144
|
}
|
|
123
145
|
};
|
package/src/toolbar.tsx
CHANGED
|
@@ -468,7 +468,17 @@ export const getToolbarConfig =
|
|
|
468
468
|
// We don't want to show floating toolbar while resizing the table
|
|
469
469
|
const isWidthResizing = tableWidthState?.resizing;
|
|
470
470
|
|
|
471
|
-
|
|
471
|
+
// Hide floating toolbar when resizing column and internal column width is on
|
|
472
|
+
const shouldHideToolbarForInternalColumnWidth = Boolean(
|
|
473
|
+
options?.isNewColumnResizingEnabled && resizeState && resizeState.dragging,
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
if (
|
|
477
|
+
tableObject &&
|
|
478
|
+
pluginState.editorHasFocus &&
|
|
479
|
+
!isWidthResizing &&
|
|
480
|
+
!shouldHideToolbarForInternalColumnWidth
|
|
481
|
+
) {
|
|
472
482
|
const nodeType = state.schema.nodes.table;
|
|
473
483
|
const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
474
484
|
const isTableScalingWithFixedColumnWidthsOptionShown =
|
package/src/utils/alignment.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
|
|
4
|
+
import { FULL_WIDTH_EDITOR_CONTENT_WIDTH } from '../pm-plugins/table-resizing/utils/consts';
|
|
3
5
|
import type { AlignmentOptions } from '../types';
|
|
4
6
|
|
|
5
7
|
export const ALIGN_START = 'align-start';
|
|
@@ -11,3 +13,19 @@ export const ALIGN_CENTER = 'center';
|
|
|
11
13
|
*/
|
|
12
14
|
export const normaliseAlignment = (layout: TableLayout): AlignmentOptions =>
|
|
13
15
|
layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* We don't want to switch alignment in Full-width editor
|
|
19
|
+
*/
|
|
20
|
+
export const shouldChangeAlignmentToCenterResized = (
|
|
21
|
+
isTableAlignmentEnabled: boolean | undefined,
|
|
22
|
+
tableNode: PmNode,
|
|
23
|
+
lineLength: number | undefined,
|
|
24
|
+
updatedTableWidth: number,
|
|
25
|
+
) =>
|
|
26
|
+
isTableAlignmentEnabled &&
|
|
27
|
+
tableNode &&
|
|
28
|
+
tableNode.attrs.layout === ALIGN_START &&
|
|
29
|
+
lineLength &&
|
|
30
|
+
updatedTableWidth > lineLength &&
|
|
31
|
+
lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH;
|