@atlaskit/editor-plugin-table 4.1.0 → 4.2.0
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 +13 -0
- package/dist/cjs/plugins/table/commands/delete.js +18 -0
- package/dist/cjs/plugins/table/commands-with-analytics.js +2 -7
- package/dist/cjs/plugins/table/event-handlers.js +2 -2
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +27 -9
- package/dist/cjs/plugins/table/pm-plugins/main.js +1 -1
- package/dist/cjs/plugins/table/transforms/column-width.js +110 -5
- package/dist/cjs/plugins/table/transforms/delete-columns.js +16 -6
- package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
- package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
- package/dist/es2019/plugins/table/commands/delete.js +10 -0
- package/dist/es2019/plugins/table/commands-with-analytics.js +3 -8
- package/dist/es2019/plugins/table/event-handlers.js +2 -2
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +27 -9
- package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
- package/dist/es2019/plugins/table/transforms/column-width.js +105 -5
- package/dist/es2019/plugins/table/transforms/delete-columns.js +16 -5
- package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
- package/dist/es2019/plugins/table/ui/common-styles.js +0 -1
- package/dist/esm/plugins/table/commands/delete.js +12 -0
- package/dist/esm/plugins/table/commands-with-analytics.js +3 -8
- package/dist/esm/plugins/table/event-handlers.js +2 -2
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +27 -9
- package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
- package/dist/esm/plugins/table/transforms/column-width.js +111 -5
- package/dist/esm/plugins/table/transforms/delete-columns.js +16 -6
- package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
- package/dist/esm/plugins/table/ui/common-styles.js +1 -1
- package/dist/types/plugins/table/commands/delete.d.ts +3 -0
- package/dist/types/plugins/table/event-handlers.d.ts +1 -1
- package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +3 -3
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
- package/dist/types/plugins/table/transforms/column-width.d.ts +25 -6
- package/dist/types/plugins/table/transforms/delete-columns.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +4 -4
- package/dist/types-ts4.5/plugins/table/commands/delete.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +3 -3
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/transforms/column-width.d.ts +25 -6
- package/dist/types-ts4.5/plugins/table/transforms/delete-columns.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +4 -4
- package/package.json +8 -2
- package/src/__tests__/unit/commands.ts +1 -0
- package/src/__tests__/unit/transforms/delete-columns.ts +406 -105
- package/src/__tests__/unit/undo-redo.ts +1 -1
- package/src/plugins/table/commands/delete.ts +20 -0
- package/src/plugins/table/commands-with-analytics.ts +3 -10
- package/src/plugins/table/event-handlers.ts +6 -1
- package/src/plugins/table/nodeviews/TableContainer.tsx +189 -159
- package/src/plugins/table/pm-plugins/main.ts +7 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +1 -1
- package/src/plugins/table/transforms/column-width.ts +155 -15
- package/src/plugins/table/transforms/delete-columns.ts +23 -6
- package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +7 -6
- package/src/plugins/table/ui/common-styles.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 4.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#40780](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/40780) [`981ad6038e9`](https://bitbucket.org/atlassian/atlassian-frontend/commits/981ad6038e9) - Fixes a bug when deleting a table column will cause column resizing to become unresponsive and lag. Delete columns operation will now update the table column widths to avoid this, under a new feature flag.
|
|
8
|
+
|
|
9
|
+
## 4.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#41220](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41220) [`9e66f4b0610`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9e66f4b0610) - Add a new feature flag (platform.editor.table.update-table-resizer-styles) that uses display: flex; to center resizable tables in full page editor. This replaces the current method which uses margin to calculate an offset
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 4.1.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.deleteColumnsCommand = void 0;
|
|
7
|
+
var _deleteColumns = require("../transforms/delete-columns");
|
|
8
|
+
var _getAllowAddColumnCustomStep = require("../utils/get-allow-add-column-custom-step");
|
|
9
|
+
var deleteColumnsCommand = exports.deleteColumnsCommand = function deleteColumnsCommand(rect) {
|
|
10
|
+
return function (state, dispatch, view) {
|
|
11
|
+
var tr = (0, _deleteColumns.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(state), view)(state.tr);
|
|
12
|
+
if (dispatch) {
|
|
13
|
+
dispatch(tr);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -12,6 +12,7 @@ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
|
12
12
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
13
13
|
var _clear = require("./commands/clear");
|
|
14
14
|
var _collapse = require("./commands/collapse");
|
|
15
|
+
var _delete = require("./commands/delete");
|
|
15
16
|
var _insert = require("./commands/insert");
|
|
16
17
|
var _misc = require("./commands/misc");
|
|
17
18
|
var _sort = require("./commands/sort");
|
|
@@ -22,7 +23,6 @@ var _commands = require("./pm-plugins/table-resizing/commands");
|
|
|
22
23
|
var _transforms = require("./transforms");
|
|
23
24
|
var _utils2 = require("./utils");
|
|
24
25
|
var _analytics2 = require("./utils/analytics");
|
|
25
|
-
var _getAllowAddColumnCustomStep = require("./utils/get-allow-add-column-custom-step");
|
|
26
26
|
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; }
|
|
27
27
|
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; }
|
|
28
28
|
var TABLE_BREAKOUT_NAME_MAPPING = {
|
|
@@ -258,12 +258,7 @@ var deleteColumnsWithAnalytics = exports.deleteColumnsWithAnalytics = function d
|
|
|
258
258
|
},
|
|
259
259
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
260
260
|
};
|
|
261
|
-
})(editorAnalyticsAPI)(
|
|
262
|
-
if (dispatch) {
|
|
263
|
-
dispatch((0, _transforms.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(state))(state.tr));
|
|
264
|
-
}
|
|
265
|
-
return true;
|
|
266
|
-
});
|
|
261
|
+
})(editorAnalyticsAPI)((0, _delete.deleteColumnsCommand)(rect));
|
|
267
262
|
};
|
|
268
263
|
};
|
|
269
264
|
var getTableDeletedAnalytics = function getTableDeletedAnalytics(selection, inputMethod) {
|
|
@@ -259,7 +259,7 @@ function handleTripleClick(view, pos) {
|
|
|
259
259
|
}
|
|
260
260
|
return false;
|
|
261
261
|
}
|
|
262
|
-
var handleCut = exports.handleCut = function handleCut(oldTr, oldState, newState, editorAnalyticsAPI) {
|
|
262
|
+
var handleCut = exports.handleCut = function handleCut(oldTr, oldState, newState, editorAnalyticsAPI, editorView) {
|
|
263
263
|
var oldSelection = oldState.tr.selection;
|
|
264
264
|
var tr = newState.tr;
|
|
265
265
|
if (oldSelection instanceof _cellSelection.CellSelection) {
|
|
@@ -302,7 +302,7 @@ var handleCut = exports.handleCut = function handleCut(oldTr, oldState, newState
|
|
|
302
302
|
isHeaderRowRequired = _getPluginState6.pluginConfig.isHeaderRowRequired;
|
|
303
303
|
tr = (0, _transforms.deleteRows)(rect, isHeaderRowRequired)(tr);
|
|
304
304
|
} else if (tr.selection.isColSelection()) {
|
|
305
|
-
tr = (0, _transforms.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(oldState))(tr);
|
|
305
|
+
tr = (0, _transforms.deleteColumns)(rect, (0, _getAllowAddColumnCustomStep.getAllowAddColumnCustomStep)(oldState), editorView)(tr);
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
}
|
|
@@ -44,7 +44,7 @@ var InnerContainer = exports.InnerContainer = /*#__PURE__*/(0, _react.forwardRef
|
|
|
44
44
|
"data-test-id": "table-container"
|
|
45
45
|
}, children);
|
|
46
46
|
});
|
|
47
|
-
var ResizableTableContainer = exports.ResizableTableContainer = function
|
|
47
|
+
var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_react.default.memo(function (_ref2) {
|
|
48
48
|
var children = _ref2.children,
|
|
49
49
|
className = _ref2.className,
|
|
50
50
|
node = _ref2.node,
|
|
@@ -94,7 +94,6 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
|
|
|
94
94
|
if (!containerRef.current) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
var marginLeft = getMarginLeft(lineLength, width);
|
|
98
97
|
|
|
99
98
|
// make sure during resizing
|
|
100
99
|
// the pm-table-resizer-container width is the same as its child div resizer-item
|
|
@@ -103,10 +102,13 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
|
|
|
103
102
|
if (containerRef.current.style.width !== "".concat(width, "px")) {
|
|
104
103
|
containerRef.current.style.width = "".concat(width, "px");
|
|
105
104
|
}
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
105
|
+
if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.update-table-resizer-styles')) {
|
|
106
|
+
var marginLeft = getMarginLeft(lineLength, width);
|
|
107
|
+
if (marginLeftRef.current !== marginLeft) {
|
|
108
|
+
marginLeftRef.current = marginLeft;
|
|
109
|
+
if (Number.isFinite(marginLeft)) {
|
|
110
|
+
containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
|
|
111
|
+
}
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
}, [lineLength]);
|
|
@@ -130,7 +132,9 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
|
|
|
130
132
|
var width = Math.min(tableWidth, responsiveContainerWidth);
|
|
131
133
|
if (!isResizing) {
|
|
132
134
|
tableWidthRef.current = width;
|
|
133
|
-
|
|
135
|
+
if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.update-table-resizer-styles')) {
|
|
136
|
+
marginLeftRef.current = getMarginLeft(lineLength, width);
|
|
137
|
+
}
|
|
134
138
|
}
|
|
135
139
|
var maxResizerWidth = Math.min(responsiveContainerWidth, _utils.TABLE_MAX_WIDTH);
|
|
136
140
|
var tableResizerProps = {
|
|
@@ -152,7 +156,21 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
|
|
|
152
156
|
onResizeStop: onResizeStop
|
|
153
157
|
});
|
|
154
158
|
}
|
|
155
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
159
|
+
return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.update-table-resizer-styles') ? /*#__PURE__*/_react.default.createElement("div", {
|
|
160
|
+
style: {
|
|
161
|
+
display: 'flex',
|
|
162
|
+
justifyContent: 'center'
|
|
163
|
+
}
|
|
164
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
165
|
+
style: {
|
|
166
|
+
width: tableWidthRef.current
|
|
167
|
+
},
|
|
168
|
+
className: _types.TableCssClassName.TABLE_RESIZER_CONTAINER,
|
|
169
|
+
ref: containerRef
|
|
170
|
+
}, /*#__PURE__*/_react.default.createElement(_TableResizer.TableResizer, tableResizerProps, /*#__PURE__*/_react.default.createElement(InnerContainer, {
|
|
171
|
+
className: className,
|
|
172
|
+
node: node
|
|
173
|
+
}, children)))) : /*#__PURE__*/_react.default.createElement("div", {
|
|
156
174
|
style: {
|
|
157
175
|
marginLeft: marginLeftRef.current,
|
|
158
176
|
width: tableWidthRef.current
|
|
@@ -163,7 +181,7 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
|
|
|
163
181
|
className: className,
|
|
164
182
|
node: node
|
|
165
183
|
}, children)));
|
|
166
|
-
};
|
|
184
|
+
});
|
|
167
185
|
var TableContainer = exports.TableContainer = function TableContainer(_ref3) {
|
|
168
186
|
var children = _ref3.children,
|
|
169
187
|
node = _ref3.node,
|
|
@@ -100,7 +100,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
|
|
|
100
100
|
}
|
|
101
101
|
if (tr) {
|
|
102
102
|
// "fixTables" removes empty rows as we don't allow that in schema
|
|
103
|
-
var updatedTr = (0, _eventHandlers.handleCut)(tr, oldState, newState, editorAnalyticsAPI);
|
|
103
|
+
var updatedTr = (0, _eventHandlers.handleCut)(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
|
|
104
104
|
return (0, _transforms2.fixTables)(updatedTr) || updatedTr;
|
|
105
105
|
}
|
|
106
106
|
if (transactions.find(function (tr) {
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.updateColumnWidths = exports.rescaleColumns = void 0;
|
|
7
|
+
exports.updateColumnWidths = exports.rescaleColumnsOld = exports.rescaleColumnsNew = exports.rescaleColumns = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _steps = require("@atlaskit/adf-schema/steps");
|
|
10
10
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
@@ -19,6 +19,13 @@ var _scaleTable = require("../pm-plugins/table-resizing/utils/scale-table");
|
|
|
19
19
|
var _commonStyles = require("../ui/common-styles");
|
|
20
20
|
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; }
|
|
21
21
|
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; }
|
|
22
|
+
/**
|
|
23
|
+
* Given a new ResizeState object, create a transaction that replaces and updates the table node based on new state.
|
|
24
|
+
* @param resizeState
|
|
25
|
+
* @param table
|
|
26
|
+
* @param start
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
22
29
|
var updateColumnWidths = exports.updateColumnWidths = function updateColumnWidths(resizeState, table, start) {
|
|
23
30
|
return function (tr) {
|
|
24
31
|
var map = _tableMap.TableMap.get(table);
|
|
@@ -121,10 +128,102 @@ var updateColumnWidths = exports.updateColumnWidths = function updateColumnWidth
|
|
|
121
128
|
* @param view
|
|
122
129
|
* @returns Updated transaction with rescaled columns for a given table
|
|
123
130
|
*/
|
|
124
|
-
var
|
|
131
|
+
var rescaleColumnsNew = exports.rescaleColumnsNew = function rescaleColumnsNew() {
|
|
132
|
+
return function (table, view) {
|
|
133
|
+
return function (tr) {
|
|
134
|
+
var _tableRef$parentEleme, _tableRef$parentEleme2;
|
|
135
|
+
if (!view) {
|
|
136
|
+
return tr;
|
|
137
|
+
}
|
|
138
|
+
var newTable = tr.doc.nodeAt(table.pos);
|
|
139
|
+
var domAtPos = view.domAtPos.bind(view);
|
|
140
|
+
var maybeTable = domAtPos(table.start).node;
|
|
141
|
+
var tableRef = maybeTable.closest('table');
|
|
142
|
+
if (!tableRef || !newTable) {
|
|
143
|
+
return tr;
|
|
144
|
+
}
|
|
145
|
+
var isResized = (0, _utils.hasTableBeenResized)(table.node);
|
|
146
|
+
// get current table info
|
|
147
|
+
var previousTableInfo = {
|
|
148
|
+
// when table is resized the tableRef client width will be 1px larger than colGroup, which is used in calculations
|
|
149
|
+
width: isResized ? tableRef.clientWidth - 1 : tableRef.clientWidth,
|
|
150
|
+
/** the is the width the table can reach before overflowing */
|
|
151
|
+
possibleMaxWidth: (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0 : ((tableRef === null || tableRef === void 0 || (_tableRef$parentEleme2 = tableRef.parentElement) === null || _tableRef$parentEleme2 === void 0 ? void 0 : _tableRef$parentEleme2.clientWidth) || 0) - _commonStyles.insertColumnButtonOffset - 1,
|
|
152
|
+
isResized: isResized
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// determine the new table, based on new width
|
|
156
|
+
var newTableInfo = {
|
|
157
|
+
noOfColumns: _tableMap.TableMap.get(newTable).width
|
|
158
|
+
};
|
|
159
|
+
if (!newTableInfo.noOfColumns || newTableInfo.noOfColumns <= 0) {
|
|
160
|
+
return tr;
|
|
161
|
+
}
|
|
162
|
+
var averageColumnWidth = previousTableInfo.width / newTableInfo.noOfColumns;
|
|
163
|
+
|
|
164
|
+
// If the table has not been resized (i.e. all columns will have the same width) and every column width is bigger than the minimum column width
|
|
165
|
+
// we skip updating the size of columns here.
|
|
166
|
+
if (!previousTableInfo.isResized && averageColumnWidth > _styles.tableCellMinWidth) {
|
|
167
|
+
return tr;
|
|
168
|
+
}
|
|
169
|
+
var wasTableInOverflow = previousTableInfo.width > previousTableInfo.possibleMaxWidth;
|
|
170
|
+
|
|
171
|
+
// If the table has not been resized, and each column width is smaller than the minimum column width
|
|
172
|
+
// Or if the table has been resized, but each column width is either 48px or null
|
|
173
|
+
// we update the table to have 48px for each column
|
|
174
|
+
if (!previousTableInfo.isResized && averageColumnWidth <= _styles.tableCellMinWidth || previousTableInfo.isResized && (0, _colgroup.isMinCellWidthTable)(table.node)) {
|
|
175
|
+
var widths = new Array(newTableInfo.noOfColumns).fill(_styles.tableCellMinWidth);
|
|
176
|
+
var cols = widths.map(function (_, index) {
|
|
177
|
+
return {
|
|
178
|
+
width: _styles.tableCellMinWidth,
|
|
179
|
+
minWidth: _styles.tableCellMinWidth,
|
|
180
|
+
index: index
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
var minWidthResizeState = {
|
|
184
|
+
cols: cols,
|
|
185
|
+
widths: widths,
|
|
186
|
+
maxSize: previousTableInfo.possibleMaxWidth,
|
|
187
|
+
tableWidth: previousTableInfo.width,
|
|
188
|
+
overflow: wasTableInOverflow
|
|
189
|
+
};
|
|
190
|
+
return updateColumnWidths(minWidthResizeState, table.node, table.start)(tr);
|
|
191
|
+
}
|
|
192
|
+
var resizeState = (0, _resizeState.getResizeState)({
|
|
193
|
+
minWidth: _styles.tableCellMinWidth,
|
|
194
|
+
table: table.node,
|
|
195
|
+
start: table.start,
|
|
196
|
+
tableRef: tableRef,
|
|
197
|
+
domAtPos: domAtPos,
|
|
198
|
+
maxSize: previousTableInfo.possibleMaxWidth
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Two scenarios that require scaling:
|
|
202
|
+
// 1. If the new table width will result in the table going into overflow
|
|
203
|
+
// we resize the cells to avoid it (e.g. adding a column)
|
|
204
|
+
// 2. If the new table width will be shorter than the parent width, scale columns to fit parent
|
|
205
|
+
if (!wasTableInOverflow && resizeState.overflow || resizeState.tableWidth < resizeState.maxSize) {
|
|
206
|
+
resizeState = (0, _scaleTable.scaleTableTo)(resizeState, previousTableInfo.possibleMaxWidth);
|
|
207
|
+
}
|
|
208
|
+
return updateColumnWidths(resizeState, table.node, table.start)(tr);
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* This function is called when user inserts/deletes a column in a table to;
|
|
215
|
+
* - rescale all columns (if the table did not overflow before the insertion)
|
|
216
|
+
* - and update column widths.
|
|
217
|
+
*
|
|
218
|
+
* This is done manually to avoid a multi-dispatch in TableComponent. See [ED-8288].
|
|
219
|
+
* @param table
|
|
220
|
+
* @param view
|
|
221
|
+
* @returns Updated transaction with rescaled columns for a given table
|
|
222
|
+
*/
|
|
223
|
+
var rescaleColumnsOld = exports.rescaleColumnsOld = function rescaleColumnsOld(getEditorContainerWidth) {
|
|
125
224
|
return function (table, view) {
|
|
126
225
|
return function (tr) {
|
|
127
|
-
var _tableRef$
|
|
226
|
+
var _tableRef$parentEleme3;
|
|
128
227
|
if (!view) {
|
|
129
228
|
return tr;
|
|
130
229
|
}
|
|
@@ -147,7 +246,7 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorC
|
|
|
147
246
|
getEditorContainerWidth: getEditorContainerWidth
|
|
148
247
|
});
|
|
149
248
|
var tableWidth = tableRef.clientWidth || _editorSharedStyles.akEditorDefaultLayoutWidth;
|
|
150
|
-
var tableMaxWidth = (tableRef === null || tableRef === void 0 || (_tableRef$
|
|
249
|
+
var tableMaxWidth = (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme3 = tableRef.parentElement) === null || _tableRef$parentEleme3 === void 0 ? void 0 : _tableRef$parentEleme3.clientWidth) || 0;
|
|
151
250
|
tableMaxWidth -= _commonStyles.insertColumnButtonOffset;
|
|
152
251
|
var newTableMap = _tableMap.TableMap.get(newTable);
|
|
153
252
|
var noOfColumns = newTableMap.width;
|
|
@@ -192,7 +291,7 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorC
|
|
|
192
291
|
domAtPos: domAtPos,
|
|
193
292
|
maxSize: maxSize
|
|
194
293
|
});
|
|
195
|
-
var previousTableWidth = resizeState.tableWidth -
|
|
294
|
+
var previousTableWidth = resizeState.tableWidth - _tableMap.tableNewColumnMinWidth;
|
|
196
295
|
var tableDidntPreviouslyOverflow = previousTableWidth <= Math.max(maxSize, tableMaxWidth);
|
|
197
296
|
|
|
198
297
|
// If the new table width will result in the table going into an overflow state
|
|
@@ -203,4 +302,10 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorC
|
|
|
203
302
|
return updateColumnWidths(resizeState, table.node, table.start)(tr);
|
|
204
303
|
};
|
|
205
304
|
};
|
|
305
|
+
};
|
|
306
|
+
var rescaleColumns = exports.rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
|
|
307
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table-update-colwidths-after-column-is-deleted')) {
|
|
308
|
+
return rescaleColumnsNew();
|
|
309
|
+
}
|
|
310
|
+
return rescaleColumnsOld(getEditorContainerWidth);
|
|
206
311
|
};
|
|
@@ -12,7 +12,9 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
12
12
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
13
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
14
14
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
15
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
16
|
var _tableAnalytics = require("../pm-plugins/table-analytics");
|
|
17
|
+
var _columnWidth = require("./column-width");
|
|
16
18
|
var _split = require("./split");
|
|
17
19
|
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; }
|
|
18
20
|
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; }
|
|
@@ -210,15 +212,23 @@ function fixRowSpans(table) {
|
|
|
210
212
|
}
|
|
211
213
|
return table.type.createChecked(table.attrs, rows, table.marks);
|
|
212
214
|
}
|
|
213
|
-
var deleteColumns = exports.deleteColumns = function deleteColumns(rect) {
|
|
214
|
-
var allowAddColumnCustomStep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
215
|
+
var deleteColumns = exports.deleteColumns = function deleteColumns(rect, allowCustomStep, view) {
|
|
215
216
|
return function (tr) {
|
|
216
|
-
tr
|
|
217
|
+
var updatedTr = tr;
|
|
218
|
+
updatedTr.setMeta(_tableAnalytics.META_KEYS.OVERFLOW_TRIGGER, {
|
|
217
219
|
name: _analytics.TABLE_OVERFLOW_CHANGE_TRIGGER.DELETED_COLUMN
|
|
218
220
|
});
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
+
if (allowCustomStep) {
|
|
222
|
+
updatedTr = deleteColumnsCustomStep(rect)(updatedTr);
|
|
223
|
+
} else {
|
|
224
|
+
updatedTr = deleteColumnsLegacy(rect)(updatedTr);
|
|
225
|
+
}
|
|
226
|
+
var table = (0, _utils.findTable)(updatedTr.selection);
|
|
227
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table-update-colwidths-after-column-is-deleted')) {
|
|
228
|
+
if (table) {
|
|
229
|
+
updatedTr = (0, _columnWidth.rescaleColumns)()(table, view)(updatedTr);
|
|
230
|
+
}
|
|
221
231
|
}
|
|
222
|
-
return
|
|
232
|
+
return updatedTr;
|
|
223
233
|
};
|
|
224
234
|
};
|
|
@@ -304,7 +304,7 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
|
|
|
304
304
|
_this.toggleOpen();
|
|
305
305
|
break;
|
|
306
306
|
case 'delete_column':
|
|
307
|
-
(0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch);
|
|
307
|
+
(0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.CONTEXT_MENU, selectionRect)(state, dispatch, editorView);
|
|
308
308
|
_this.toggleOpen();
|
|
309
309
|
break;
|
|
310
310
|
case 'delete_row':
|
|
@@ -125,7 +125,7 @@ var FloatingDeleteButton = /*#__PURE__*/function (_Component) {
|
|
|
125
125
|
switch (_this.state.selectionType) {
|
|
126
126
|
case 'column':
|
|
127
127
|
{
|
|
128
|
-
(0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.BUTTON, rect)(state, dispatch);
|
|
128
|
+
(0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.BUTTON, rect)(state, dispatch, _this.props.editorView);
|
|
129
129
|
return;
|
|
130
130
|
}
|
|
131
131
|
case 'row':
|
|
@@ -56,7 +56,7 @@ var tableStickyHeaderColumnControlsDecorationsStyle = function tableStickyHeader
|
|
|
56
56
|
};
|
|
57
57
|
var tableWrapperStyles = function tableWrapperStyles() {
|
|
58
58
|
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
|
|
59
|
-
return (0, _react.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n .", " {\n padding-bottom: 0px;\n /* fixes gap cursor height */\n overflow: auto;\n overflow-y: hidden;\n position: relative;\n\n > table[data-number-column='true'] {\n
|
|
59
|
+
return (0, _react.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n .", " {\n padding-bottom: 0px;\n /* fixes gap cursor height */\n overflow: auto;\n overflow-y: hidden;\n position: relative;\n\n > table[data-number-column='true'] {\n width: calc(100% - 1px);\n }\n }\n "])), _types.TableCssClassName.TABLE_NODE_WRAPPER);
|
|
60
60
|
} else {
|
|
61
61
|
return (0, _react.css)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n .", " {\n padding-right: ", "px;\n margin-right: -", "px;\n padding-bottom: 0px;\n /* fixes gap cursor height */\n overflow: auto;\n overflow-y: hidden;\n position: relative;\n }\n "])), _types.TableCssClassName.TABLE_NODE_WRAPPER, insertColumnButtonOffset, insertColumnButtonOffset);
|
|
62
62
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { deleteColumns } from '../transforms/delete-columns';
|
|
2
|
+
import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
|
|
3
|
+
export const deleteColumnsCommand = rect => (state, dispatch, view) => {
|
|
4
|
+
const tr = deleteColumns(rect, getAllowAddColumnCustomStep(state), view)(state.tr);
|
|
5
|
+
if (dispatch) {
|
|
6
|
+
dispatch(tr);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
return false;
|
|
10
|
+
};
|
|
@@ -4,6 +4,7 @@ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
|
4
4
|
import { findCellClosestToPos, findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
5
5
|
import { clearMultipleCells } from './commands/clear';
|
|
6
6
|
import { wrapTableInExpand } from './commands/collapse';
|
|
7
|
+
import { deleteColumnsCommand } from './commands/delete';
|
|
7
8
|
import { insertColumn, insertRow } from './commands/insert';
|
|
8
9
|
import { deleteTable, deleteTableIfSelected, setMultipleCellAttrs } from './commands/misc';
|
|
9
10
|
import { sortByColumn } from './commands/sort';
|
|
@@ -11,10 +12,9 @@ import { splitCell } from './commands/split-cell';
|
|
|
11
12
|
import { getNextLayout, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './commands/toggle';
|
|
12
13
|
import { getPluginState } from './pm-plugins/plugin-factory';
|
|
13
14
|
import { distributeColumnsWidths } from './pm-plugins/table-resizing/commands';
|
|
14
|
-
import {
|
|
15
|
+
import { deleteRows, mergeCells } from './transforms';
|
|
15
16
|
import { checkIfNumberColumnEnabled, getSelectedCellInfo, getSelectedTableInfo } from './utils';
|
|
16
17
|
import { withEditorAnalyticsAPI } from './utils/analytics';
|
|
17
|
-
import { getAllowAddColumnCustomStep } from './utils/get-allow-add-column-custom-step';
|
|
18
18
|
const TABLE_BREAKOUT_NAME_MAPPING = {
|
|
19
19
|
default: TABLE_BREAKOUT.NORMAL,
|
|
20
20
|
wide: TABLE_BREAKOUT.WIDE,
|
|
@@ -231,12 +231,7 @@ export const deleteColumnsWithAnalytics = editorAnalyticsAPI => (inputMethod, re
|
|
|
231
231
|
},
|
|
232
232
|
eventType: EVENT_TYPE.TRACK
|
|
233
233
|
};
|
|
234
|
-
})(editorAnalyticsAPI)((
|
|
235
|
-
if (dispatch) {
|
|
236
|
-
dispatch(deleteColumns(rect, getAllowAddColumnCustomStep(state))(state.tr));
|
|
237
|
-
}
|
|
238
|
-
return true;
|
|
239
|
-
});
|
|
234
|
+
})(editorAnalyticsAPI)(deleteColumnsCommand(rect));
|
|
240
235
|
const getTableDeletedAnalytics = (selection, inputMethod) => {
|
|
241
236
|
const {
|
|
242
237
|
totalRowCount,
|
|
@@ -263,7 +263,7 @@ export function handleTripleClick(view, pos) {
|
|
|
263
263
|
}
|
|
264
264
|
return false;
|
|
265
265
|
}
|
|
266
|
-
export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI) => {
|
|
266
|
+
export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI, editorView) => {
|
|
267
267
|
const oldSelection = oldState.tr.selection;
|
|
268
268
|
let {
|
|
269
269
|
tr
|
|
@@ -312,7 +312,7 @@ export const handleCut = (oldTr, oldState, newState, editorAnalyticsAPI) => {
|
|
|
312
312
|
} = getPluginState(newState);
|
|
313
313
|
tr = deleteRows(rect, isHeaderRowRequired)(tr);
|
|
314
314
|
} else if (tr.selection.isColSelection()) {
|
|
315
|
-
tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState))(tr);
|
|
315
|
+
tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState), editorView)(tr);
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
}
|
|
@@ -32,7 +32,7 @@ export const InnerContainer = /*#__PURE__*/forwardRef(({
|
|
|
32
32
|
"data-test-id": "table-container"
|
|
33
33
|
}, children);
|
|
34
34
|
});
|
|
35
|
-
export const ResizableTableContainer = ({
|
|
35
|
+
export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
36
36
|
children,
|
|
37
37
|
className,
|
|
38
38
|
node,
|
|
@@ -83,7 +83,6 @@ export const ResizableTableContainer = ({
|
|
|
83
83
|
if (!containerRef.current) {
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
const marginLeft = getMarginLeft(lineLength, width);
|
|
87
86
|
|
|
88
87
|
// make sure during resizing
|
|
89
88
|
// the pm-table-resizer-container width is the same as its child div resizer-item
|
|
@@ -92,10 +91,13 @@ export const ResizableTableContainer = ({
|
|
|
92
91
|
if (containerRef.current.style.width !== `${width}px`) {
|
|
93
92
|
containerRef.current.style.width = `${width}px`;
|
|
94
93
|
}
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
94
|
+
if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
|
|
95
|
+
const marginLeft = getMarginLeft(lineLength, width);
|
|
96
|
+
if (marginLeftRef.current !== marginLeft) {
|
|
97
|
+
marginLeftRef.current = marginLeft;
|
|
98
|
+
if (Number.isFinite(marginLeft)) {
|
|
99
|
+
containerRef.current.style.marginLeft = `${marginLeft}px`;
|
|
100
|
+
}
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
}, [lineLength]);
|
|
@@ -119,7 +121,9 @@ export const ResizableTableContainer = ({
|
|
|
119
121
|
const width = Math.min(tableWidth, responsiveContainerWidth);
|
|
120
122
|
if (!isResizing) {
|
|
121
123
|
tableWidthRef.current = width;
|
|
122
|
-
|
|
124
|
+
if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
|
|
125
|
+
marginLeftRef.current = getMarginLeft(lineLength, width);
|
|
126
|
+
}
|
|
123
127
|
}
|
|
124
128
|
const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
|
|
125
129
|
let tableResizerProps = {
|
|
@@ -142,7 +146,21 @@ export const ResizableTableContainer = ({
|
|
|
142
146
|
onResizeStop: onResizeStop
|
|
143
147
|
};
|
|
144
148
|
}
|
|
145
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
149
|
+
return getBooleanFF('platform.editor.table.update-table-resizer-styles') ? /*#__PURE__*/React.createElement("div", {
|
|
150
|
+
style: {
|
|
151
|
+
display: 'flex',
|
|
152
|
+
justifyContent: 'center'
|
|
153
|
+
}
|
|
154
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
155
|
+
style: {
|
|
156
|
+
width: tableWidthRef.current
|
|
157
|
+
},
|
|
158
|
+
className: ClassName.TABLE_RESIZER_CONTAINER,
|
|
159
|
+
ref: containerRef
|
|
160
|
+
}, /*#__PURE__*/React.createElement(TableResizer, tableResizerProps, /*#__PURE__*/React.createElement(InnerContainer, {
|
|
161
|
+
className: className,
|
|
162
|
+
node: node
|
|
163
|
+
}, children)))) : /*#__PURE__*/React.createElement("div", {
|
|
146
164
|
style: {
|
|
147
165
|
marginLeft: marginLeftRef.current,
|
|
148
166
|
width: tableWidthRef.current
|
|
@@ -153,7 +171,7 @@ export const ResizableTableContainer = ({
|
|
|
153
171
|
className: className,
|
|
154
172
|
node: node
|
|
155
173
|
}, children)));
|
|
156
|
-
};
|
|
174
|
+
});
|
|
157
175
|
export const TableContainer = ({
|
|
158
176
|
children,
|
|
159
177
|
node,
|
|
@@ -82,7 +82,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
82
82
|
}
|
|
83
83
|
if (tr) {
|
|
84
84
|
// "fixTables" removes empty rows as we don't allow that in schema
|
|
85
|
-
const updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI);
|
|
85
|
+
const updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined);
|
|
86
86
|
return fixTables(updatedTr) || updatedTr;
|
|
87
87
|
}
|
|
88
88
|
if (transactions.find(tr => tr.docChanged)) {
|