@atlaskit/editor-plugin-table 7.19.0 → 7.19.2
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 +18 -0
- package/dist/cjs/nodeviews/TableComponent.js +7 -2
- 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/TableComponent.js +7 -3
- 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/TableComponent.js +7 -2
- 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 +2 -2
- package/src/nodeviews/TableComponent.tsx +18 -7
- 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,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.19.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#115086](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/115086)
|
|
8
|
+
[`e22c1261d6b17`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e22c1261d6b17) -
|
|
9
|
+
Add a tint to table transactions that are not created by users to avoid issues for view only live
|
|
10
|
+
pages
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 7.19.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [`0c728cec893a0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0c728cec893a0) -
|
|
18
|
+
ED-23730: Change table to align center when column resizing makes table width wider than
|
|
19
|
+
linelength
|
|
20
|
+
|
|
3
21
|
## 7.19.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -19,6 +19,7 @@ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
|
19
19
|
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
20
20
|
var _reactIntlNext = require("react-intl-next");
|
|
21
21
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
22
|
+
var _collab = require("@atlaskit/editor-common/collab");
|
|
22
23
|
var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
23
24
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
24
25
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
@@ -164,7 +165,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
164
165
|
if (shouldScaleTable) {
|
|
165
166
|
_this.scaleTable({
|
|
166
167
|
parentWidth: parentWidth
|
|
167
|
-
});
|
|
168
|
+
}, hasNumberedColumnChanged);
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
@@ -172,7 +173,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
172
173
|
if (!(0, _colgroup.hasTableBeenResized)(prevNode)) {
|
|
173
174
|
_this.scaleTable({
|
|
174
175
|
parentWidth: node.attrs.width
|
|
175
|
-
});
|
|
176
|
+
}, true);
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
_this.updateParentWidth(parentWidth);
|
|
@@ -183,6 +184,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
183
184
|
});
|
|
184
185
|
// Function gets called when table is nested.
|
|
185
186
|
(0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "scaleTable", function (scaleOptions) {
|
|
187
|
+
var isUserTriggered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
186
188
|
var _this$props2 = _this.props,
|
|
187
189
|
view = _this$props2.view,
|
|
188
190
|
getNode = _this$props2.getNode,
|
|
@@ -209,6 +211,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
209
211
|
// isTableScalingEnabled doesn't change the behavior of nested tables
|
|
210
212
|
false // shouldUseIncreasedScalingPercent set to false for nested tables
|
|
211
213
|
)(state.tr);
|
|
214
|
+
if (!isUserTriggered) {
|
|
215
|
+
(0, _collab.tintDirtyTransaction)(tr);
|
|
216
|
+
}
|
|
212
217
|
dispatch(tr);
|
|
213
218
|
});
|
|
214
219
|
(0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "setTimerToSendInitialOverflowCaptured", function (isOverflowing) {
|
|
@@ -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
|
};
|
|
@@ -5,6 +5,7 @@ import memoizeOne from 'memoize-one';
|
|
|
5
5
|
import rafSchedule from 'raf-schd';
|
|
6
6
|
import { injectIntl } from 'react-intl-next';
|
|
7
7
|
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
8
|
+
import { tintDirtyTransaction } from '@atlaskit/editor-common/collab';
|
|
8
9
|
import { getParentNodeWidth, getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
9
10
|
import { tableMarginSides } from '@atlaskit/editor-common/styles';
|
|
10
11
|
import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
|
|
@@ -148,7 +149,7 @@ class TableComponent extends React.Component {
|
|
|
148
149
|
if (shouldScaleTable) {
|
|
149
150
|
this.scaleTable({
|
|
150
151
|
parentWidth
|
|
151
|
-
});
|
|
152
|
+
}, hasNumberedColumnChanged);
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
@@ -156,7 +157,7 @@ class TableComponent extends React.Component {
|
|
|
156
157
|
if (!hasTableBeenResized(prevNode)) {
|
|
157
158
|
this.scaleTable({
|
|
158
159
|
parentWidth: node.attrs.width
|
|
159
|
-
});
|
|
160
|
+
}, true);
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
this.updateParentWidth(parentWidth);
|
|
@@ -166,7 +167,7 @@ class TableComponent extends React.Component {
|
|
|
166
167
|
this.layoutSize = layoutSize;
|
|
167
168
|
});
|
|
168
169
|
// Function gets called when table is nested.
|
|
169
|
-
_defineProperty(this, "scaleTable", scaleOptions => {
|
|
170
|
+
_defineProperty(this, "scaleTable", (scaleOptions, isUserTriggered = false) => {
|
|
170
171
|
const {
|
|
171
172
|
view,
|
|
172
173
|
getNode,
|
|
@@ -200,6 +201,9 @@ class TableComponent extends React.Component {
|
|
|
200
201
|
// isTableScalingEnabled doesn't change the behavior of nested tables
|
|
201
202
|
false // shouldUseIncreasedScalingPercent set to false for nested tables
|
|
202
203
|
)(state.tr);
|
|
204
|
+
if (!isUserTriggered) {
|
|
205
|
+
tintDirtyTransaction(tr);
|
|
206
|
+
}
|
|
203
207
|
dispatch(tr);
|
|
204
208
|
});
|
|
205
209
|
_defineProperty(this, "setTimerToSendInitialOverflowCaptured", isOverflowing => {
|
|
@@ -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;
|