@atlaskit/editor-plugin-table 7.6.8 → 7.6.10
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 +12 -0
- package/dist/cjs/nodeviews/TableContainer.js +18 -28
- package/dist/cjs/nodeviews/TableResizer.js +12 -19
- package/dist/cjs/utils/decoration.js +7 -46
- package/dist/es2019/nodeviews/TableContainer.js +0 -12
- package/dist/es2019/nodeviews/TableResizer.js +8 -12
- package/dist/es2019/utils/decoration.js +8 -47
- package/dist/esm/nodeviews/TableContainer.js +18 -28
- package/dist/esm/nodeviews/TableResizer.js +12 -19
- package/dist/esm/utils/decoration.js +8 -47
- package/package.json +1 -4
- package/src/nodeviews/TableContainer.tsx +1 -14
- package/src/nodeviews/TableResizer.tsx +20 -29
- package/src/utils/decoration.ts +6 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.6.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#88096](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/88096) [`38f5046368e5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/38f5046368e5) - fix preserve table width undo / redo issue and show full width guide on small screens
|
|
8
|
+
|
|
9
|
+
## 7.6.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#87069](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87069) [`3c2cb323593e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3c2cb323593e) - remove feature flag in-danger-hover-merged-cells-fix
|
|
14
|
+
|
|
3
15
|
## 7.6.8
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -10,7 +10,6 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
12
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
-
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
14
13
|
var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
15
14
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
16
15
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
@@ -47,7 +46,6 @@ var InnerContainer = exports.InnerContainer = /*#__PURE__*/(0, _react.forwardRef
|
|
|
47
46
|
}, children);
|
|
48
47
|
});
|
|
49
48
|
var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_react.default.memo(function (_ref2) {
|
|
50
|
-
var _node$attrs$localId, _node$attrs;
|
|
51
49
|
var children = _ref2.children,
|
|
52
50
|
className = _ref2.className,
|
|
53
51
|
node = _ref2.node,
|
|
@@ -119,18 +117,10 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
|
|
|
119
117
|
return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.core) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$s = pluginInjectionApi.selection) === null || _pluginInjectionApi$s === void 0 ? void 0 : _pluginInjectionApi$s.commands.displayGapCursor(toggle))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
|
|
120
118
|
}, [pluginInjectionApi]);
|
|
121
119
|
var tableWidth = (0, _nodeWidth.getTableContainerWidth)(node);
|
|
122
|
-
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['table']),
|
|
123
|
-
tableState = _useSharedPluginState.tableState;
|
|
124
|
-
var _ref3 = tableState,
|
|
125
|
-
widthToWidest = _ref3.widthToWidest;
|
|
126
|
-
var currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
|
|
127
120
|
|
|
128
121
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
129
122
|
var responsiveContainerWidth = isTableScalingEnabled ? containerWidth - _editorSharedStyles.akEditorGutterPadding * 2 - _editorSharedStyles.akEditorMediaResizeHandlerPaddingWide / 2 : containerWidth - _editorSharedStyles.akEditorGutterPadding * 2 - _editorSharedStyles.akEditorMediaResizeHandlerPaddingWide;
|
|
130
123
|
var width = Math.min(tableWidth, responsiveContainerWidth);
|
|
131
|
-
if (isTableScalingEnabled && currentTableNodeLocalId && widthToWidest && widthToWidest[currentTableNodeLocalId]) {
|
|
132
|
-
width = _utils.TABLE_MAX_WIDTH;
|
|
133
|
-
}
|
|
134
124
|
if (!isResizing) {
|
|
135
125
|
tableWidthRef.current = width;
|
|
136
126
|
}
|
|
@@ -174,24 +164,24 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
|
|
|
174
164
|
node: node
|
|
175
165
|
}, children))));
|
|
176
166
|
});
|
|
177
|
-
var TableContainer = exports.TableContainer = function TableContainer(
|
|
178
|
-
var children =
|
|
179
|
-
node =
|
|
180
|
-
className =
|
|
181
|
-
|
|
182
|
-
lineLength =
|
|
183
|
-
editorWidth =
|
|
184
|
-
isTableResizingEnabled =
|
|
185
|
-
isBreakoutEnabled =
|
|
186
|
-
editorView =
|
|
187
|
-
getPos =
|
|
188
|
-
tableRef =
|
|
189
|
-
isNested =
|
|
190
|
-
tableWrapperHeight =
|
|
191
|
-
isResizing =
|
|
192
|
-
pluginInjectionApi =
|
|
193
|
-
isTableScalingEnabled =
|
|
194
|
-
isWholeTableInDanger =
|
|
167
|
+
var TableContainer = exports.TableContainer = function TableContainer(_ref3) {
|
|
168
|
+
var children = _ref3.children,
|
|
169
|
+
node = _ref3.node,
|
|
170
|
+
className = _ref3.className,
|
|
171
|
+
_ref3$containerWidth = _ref3.containerWidth,
|
|
172
|
+
lineLength = _ref3$containerWidth.lineLength,
|
|
173
|
+
editorWidth = _ref3$containerWidth.width,
|
|
174
|
+
isTableResizingEnabled = _ref3.isTableResizingEnabled,
|
|
175
|
+
isBreakoutEnabled = _ref3.isBreakoutEnabled,
|
|
176
|
+
editorView = _ref3.editorView,
|
|
177
|
+
getPos = _ref3.getPos,
|
|
178
|
+
tableRef = _ref3.tableRef,
|
|
179
|
+
isNested = _ref3.isNested,
|
|
180
|
+
tableWrapperHeight = _ref3.tableWrapperHeight,
|
|
181
|
+
isResizing = _ref3.isResizing,
|
|
182
|
+
pluginInjectionApi = _ref3.pluginInjectionApi,
|
|
183
|
+
isTableScalingEnabled = _ref3.isTableScalingEnabled,
|
|
184
|
+
isWholeTableInDanger = _ref3.isWholeTableInDanger;
|
|
195
185
|
if (isTableResizingEnabled && !isNested) {
|
|
196
186
|
return /*#__PURE__*/_react.default.createElement(ResizableTableContainer, {
|
|
197
187
|
className: className,
|
|
@@ -104,10 +104,6 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
104
104
|
// track resizing state - use ref over state to avoid re-render
|
|
105
105
|
var isResizing = (0, _react.useRef)(false);
|
|
106
106
|
var areResizeMetaKeysPressed = (0, _react.useRef)(false);
|
|
107
|
-
var _useState = (0, _react.useState)(width),
|
|
108
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
109
|
-
localTableWidth = _useState2[0],
|
|
110
|
-
setLocalTableWidth = _useState2[1];
|
|
111
107
|
var resizerRef = (0, _react.useRef)(null);
|
|
112
108
|
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['table']),
|
|
113
109
|
tableState = _useSharedPluginState.tableState;
|
|
@@ -116,10 +112,10 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
116
112
|
|
|
117
113
|
// used to reposition tooltip when table is resizing via keyboard
|
|
118
114
|
var updateTooltip = _react.default.useRef();
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
-
snappingEnabled =
|
|
122
|
-
setSnappingEnabled =
|
|
115
|
+
var _useState = (0, _react.useState)(false),
|
|
116
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
117
|
+
snappingEnabled = _useState2[0],
|
|
118
|
+
setSnappingEnabled = _useState2[1];
|
|
123
119
|
var _useIntl = (0, _reactIntlNext.useIntl)(),
|
|
124
120
|
formatMessage = _useIntl.formatMessage;
|
|
125
121
|
var isTableSelected = ((_findTable = (0, _utils2.findTable)((_editorView$state = editorView.state) === null || _editorView$state === void 0 ? void 0 : _editorView$state.selection)) === null || _findTable === void 0 ? void 0 : _findTable.pos) === getPos();
|
|
@@ -179,7 +175,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
179
175
|
}
|
|
180
176
|
}, [startMeasure, editorView, displayGapCursor, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
181
177
|
var handleResize = (0, _react.useCallback)(function (originalState, delta) {
|
|
182
|
-
var _node$attrs$localId, _node$attrs
|
|
178
|
+
var _node$attrs$localId, _node$attrs;
|
|
183
179
|
countFrames();
|
|
184
180
|
var newWidth = originalState.width + delta.width;
|
|
185
181
|
var pos;
|
|
@@ -197,20 +193,18 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
197
193
|
start: pos + 1,
|
|
198
194
|
parentWidth: newWidth
|
|
199
195
|
}, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
|
|
200
|
-
|
|
196
|
+
var closestSnap = (0, _snapping.findClosestSnap)(newWidth, isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(containerWidth) : _snapping.defaultSnappingWidths, isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth) : _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE);
|
|
197
|
+
updateActiveGuidelines(closestSnap);
|
|
201
198
|
|
|
202
|
-
//
|
|
203
|
-
// and a table is resized to fit the widest guideline when view port width is between 1011 and 1800
|
|
204
|
-
// set the width of the table to 1800 pixels.
|
|
199
|
+
// When snapping to the full width guideline, resize the table to be 1800px
|
|
205
200
|
var state = editorView.state,
|
|
206
201
|
dispatch = editorView.dispatch;
|
|
207
202
|
var currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
|
|
208
|
-
var
|
|
203
|
+
var fullWidthGuideline = (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth).filter(function (guideline) {
|
|
209
204
|
return guideline.isFullWidth;
|
|
210
205
|
})[0];
|
|
211
|
-
var
|
|
212
|
-
var shouldUpdateWidthToWidest = !!
|
|
213
|
-
shouldUpdateWidthToWidest ? setLocalTableWidth(_utils3.TABLE_MAX_WIDTH) : setLocalTableWidth(newWidth);
|
|
206
|
+
var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
207
|
+
var shouldUpdateWidthToWidest = !!isTableScalingEnabled && isFullWidthGuidelineActive;
|
|
214
208
|
(0, _misc.updateWidthToWidest)((0, _defineProperty2.default)({}, currentTableNodeLocalId, shouldUpdateWidthToWidest))(state, dispatch);
|
|
215
209
|
updateWidth(shouldUpdateWidthToWidest ? _utils3.TABLE_MAX_WIDTH : newWidth);
|
|
216
210
|
return newWidth;
|
|
@@ -290,7 +284,6 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
290
284
|
if (newWidth > maxWidth || newWidth < resizerMinWidth) {
|
|
291
285
|
return;
|
|
292
286
|
}
|
|
293
|
-
setLocalTableWidth(newWidth);
|
|
294
287
|
handleResizeStop({
|
|
295
288
|
width: width,
|
|
296
289
|
x: 0,
|
|
@@ -369,7 +362,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
369
362
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_resizer.ResizerNext, {
|
|
370
363
|
ref: resizerRef,
|
|
371
364
|
enable: handles,
|
|
372
|
-
width:
|
|
365
|
+
width: width,
|
|
373
366
|
handleAlignmentMethod: "sticky",
|
|
374
367
|
handleSize: handleSize,
|
|
375
368
|
handleStyles: handleStyles,
|
|
@@ -13,7 +13,6 @@ var _utils = require("@atlaskit/editor-common/utils");
|
|
|
13
13
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
14
14
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
15
15
|
var _utils2 = require("@atlaskit/editor-tables/utils");
|
|
16
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
16
|
var _types = require("../types");
|
|
18
17
|
var _ColumnResizeWidget = require("../ui/ColumnResizeWidget");
|
|
19
18
|
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
@@ -71,51 +70,13 @@ var createControlsHoverDecoration = exports.createControlsHoverDecoration = func
|
|
|
71
70
|
// So If the table cells are in danger we want to create a "rectangle" selection
|
|
72
71
|
// to match the "clicked" selection
|
|
73
72
|
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return x + _table.start;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
if (danger) {
|
|
87
|
-
// Find the bounding rectangle of all the given cells, also considering
|
|
88
|
-
// merged cells.
|
|
89
|
-
var _cells$reduce3 = cells.reduce(function (acc, cell) {
|
|
90
|
-
var _map$findCell = map.findCell(cell.pos - table.start),
|
|
91
|
-
left = _map$findCell.left,
|
|
92
|
-
right = _map$findCell.right,
|
|
93
|
-
bottom = _map$findCell.bottom,
|
|
94
|
-
top = _map$findCell.top;
|
|
95
|
-
// Finding the bounding rect requires finding the min left and top positions,
|
|
96
|
-
// and the max right and bottom positions of the cells
|
|
97
|
-
return {
|
|
98
|
-
recLeft: Math.min(acc.recLeft, left),
|
|
99
|
-
recTop: Math.min(acc.recTop, top),
|
|
100
|
-
recRight: Math.max(acc.recRight, right),
|
|
101
|
-
recBottom: Math.max(acc.recBottom, bottom)
|
|
102
|
-
};
|
|
103
|
-
},
|
|
104
|
-
// +-Infinity as initialisation vars which will always be overwritten
|
|
105
|
-
// by smaller/larger values respectively
|
|
106
|
-
{
|
|
107
|
-
recLeft: Infinity,
|
|
108
|
-
recTop: Infinity,
|
|
109
|
-
recRight: -Infinity,
|
|
110
|
-
recBottom: -Infinity
|
|
111
|
-
}),
|
|
112
|
-
recLeft = _cells$reduce3.recLeft,
|
|
113
|
-
recTop = _cells$reduce3.recTop,
|
|
114
|
-
recRight = _cells$reduce3.recRight,
|
|
115
|
-
recBottom = _cells$reduce3.recBottom;
|
|
116
|
-
var _rect = new _tableMap.Rect(recLeft, recTop, recRight, recBottom);
|
|
117
|
-
updatedCells = map.cellsInRect(_rect).map(function (x) {
|
|
118
|
-
return x + table.start;
|
|
73
|
+
if (danger && type !== 'table') {
|
|
74
|
+
var selection = tr.selection;
|
|
75
|
+
var _table = (0, _utils2.findTable)(selection);
|
|
76
|
+
var rect = (0, _utils2.getSelectionRect)(selection);
|
|
77
|
+
if (_table && rect) {
|
|
78
|
+
updatedCells = map.cellsInRect(rect).map(function (x) {
|
|
79
|
+
return x + _table.start;
|
|
119
80
|
});
|
|
120
81
|
}
|
|
121
82
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef, useCallback, useRef, useState } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
3
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
5
4
|
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
6
5
|
import { akEditorDefaultLayoutWidth, akEditorGutterPadding, akEditorMediaResizeHandlerPaddingWide, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
|
|
@@ -47,7 +46,6 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
47
46
|
tableWrapperHeight,
|
|
48
47
|
isWholeTableInDanger
|
|
49
48
|
}) => {
|
|
50
|
-
var _node$attrs$localId, _node$attrs;
|
|
51
49
|
const containerRef = useRef(null);
|
|
52
50
|
const tableWidthRef = useRef(akEditorDefaultLayoutWidth);
|
|
53
51
|
const [resizing, setIsResizing] = useState(false);
|
|
@@ -104,20 +102,10 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
104
102
|
return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c2 = pluginInjectionApi.core) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$s = pluginInjectionApi.selection) === null || _pluginInjectionApi$s === void 0 ? void 0 : _pluginInjectionApi$s.commands.displayGapCursor(toggle))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
|
|
105
103
|
}, [pluginInjectionApi]);
|
|
106
104
|
const tableWidth = getTableContainerWidth(node);
|
|
107
|
-
const {
|
|
108
|
-
tableState
|
|
109
|
-
} = useSharedPluginState(pluginInjectionApi, ['table']);
|
|
110
|
-
const {
|
|
111
|
-
widthToWidest
|
|
112
|
-
} = tableState;
|
|
113
|
-
const currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
|
|
114
105
|
|
|
115
106
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
116
107
|
const responsiveContainerWidth = isTableScalingEnabled ? containerWidth - akEditorGutterPadding * 2 - akEditorMediaResizeHandlerPaddingWide / 2 : containerWidth - akEditorGutterPadding * 2 - akEditorMediaResizeHandlerPaddingWide;
|
|
117
108
|
let width = Math.min(tableWidth, responsiveContainerWidth);
|
|
118
|
-
if (isTableScalingEnabled && currentTableNodeLocalId && widthToWidest && widthToWidest[currentTableNodeLocalId]) {
|
|
119
|
-
width = TABLE_MAX_WIDTH;
|
|
120
|
-
}
|
|
121
109
|
if (!isResizing) {
|
|
122
110
|
tableWidthRef.current = width;
|
|
123
111
|
}
|
|
@@ -91,7 +91,6 @@ export const TableResizer = ({
|
|
|
91
91
|
// track resizing state - use ref over state to avoid re-render
|
|
92
92
|
const isResizing = useRef(false);
|
|
93
93
|
const areResizeMetaKeysPressed = useRef(false);
|
|
94
|
-
const [localTableWidth, setLocalTableWidth] = useState(width);
|
|
95
94
|
const resizerRef = useRef(null);
|
|
96
95
|
const {
|
|
97
96
|
tableState
|
|
@@ -171,7 +170,7 @@ export const TableResizer = ({
|
|
|
171
170
|
}
|
|
172
171
|
}, [startMeasure, editorView, displayGapCursor, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
173
172
|
const handleResize = useCallback((originalState, delta) => {
|
|
174
|
-
var _node$attrs$localId, _node$attrs
|
|
173
|
+
var _node$attrs$localId, _node$attrs;
|
|
175
174
|
countFrames();
|
|
176
175
|
const newWidth = originalState.width + delta.width;
|
|
177
176
|
let pos;
|
|
@@ -189,20 +188,18 @@ export const TableResizer = ({
|
|
|
189
188
|
start: pos + 1,
|
|
190
189
|
parentWidth: newWidth
|
|
191
190
|
}, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
|
|
192
|
-
|
|
191
|
+
const closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
|
|
192
|
+
updateActiveGuidelines(closestSnap);
|
|
193
193
|
|
|
194
|
-
//
|
|
195
|
-
// and a table is resized to fit the widest guideline when view port width is between 1011 and 1800
|
|
196
|
-
// set the width of the table to 1800 pixels.
|
|
194
|
+
// When snapping to the full width guideline, resize the table to be 1800px
|
|
197
195
|
const {
|
|
198
196
|
state,
|
|
199
197
|
dispatch
|
|
200
198
|
} = editorView;
|
|
201
199
|
const currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const shouldUpdateWidthToWidest = !!
|
|
205
|
-
shouldUpdateWidthToWidest ? setLocalTableWidth(TABLE_MAX_WIDTH) : setLocalTableWidth(newWidth);
|
|
200
|
+
const fullWidthGuideline = defaultGuidelinesForPreserveTable(containerWidth).filter(guideline => guideline.isFullWidth)[0];
|
|
201
|
+
const isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
202
|
+
const shouldUpdateWidthToWidest = !!isTableScalingEnabled && isFullWidthGuidelineActive;
|
|
206
203
|
updateWidthToWidest({
|
|
207
204
|
[currentTableNodeLocalId]: shouldUpdateWidthToWidest
|
|
208
205
|
})(state, dispatch);
|
|
@@ -285,7 +282,6 @@ export const TableResizer = ({
|
|
|
285
282
|
if (newWidth > maxWidth || newWidth < resizerMinWidth) {
|
|
286
283
|
return;
|
|
287
284
|
}
|
|
288
|
-
setLocalTableWidth(newWidth);
|
|
289
285
|
handleResizeStop({
|
|
290
286
|
width: width,
|
|
291
287
|
x: 0,
|
|
@@ -364,7 +360,7 @@ export const TableResizer = ({
|
|
|
364
360
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ResizerNext, {
|
|
365
361
|
ref: resizerRef,
|
|
366
362
|
enable: handles,
|
|
367
|
-
width:
|
|
363
|
+
width: width,
|
|
368
364
|
handleAlignmentMethod: "sticky",
|
|
369
365
|
handleSize: handleSize,
|
|
370
366
|
handleStyles: handleStyles,
|
|
@@ -6,9 +6,8 @@ import { nonNullable } from '@atlaskit/editor-common/utils';
|
|
|
6
6
|
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
7
7
|
|
|
8
8
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
9
|
-
import {
|
|
9
|
+
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
10
10
|
import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
11
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
12
11
|
import { TableCssClassName as ClassName, TableDecorations } from '../types';
|
|
13
12
|
import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
|
|
14
13
|
const filterDecorationByKey = (key, decorationSet) => decorationSet.find(undefined, undefined, spec => spec.key.indexOf(key) > -1);
|
|
@@ -44,51 +43,13 @@ export const createControlsHoverDecoration = (cells, type, tr, isDragAndDropEnab
|
|
|
44
43
|
// So If the table cells are in danger we want to create a "rectangle" selection
|
|
45
44
|
// to match the "clicked" selection
|
|
46
45
|
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (table && rect) {
|
|
55
|
-
updatedCells = map.cellsInRect(rect).map(x => x + table.start);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
if (danger) {
|
|
60
|
-
// Find the bounding rectangle of all the given cells, also considering
|
|
61
|
-
// merged cells.
|
|
62
|
-
const {
|
|
63
|
-
recLeft,
|
|
64
|
-
recTop,
|
|
65
|
-
recRight,
|
|
66
|
-
recBottom
|
|
67
|
-
} = cells.reduce((acc, cell) => {
|
|
68
|
-
const {
|
|
69
|
-
left,
|
|
70
|
-
right,
|
|
71
|
-
bottom,
|
|
72
|
-
top
|
|
73
|
-
} = map.findCell(cell.pos - table.start);
|
|
74
|
-
// Finding the bounding rect requires finding the min left and top positions,
|
|
75
|
-
// and the max right and bottom positions of the cells
|
|
76
|
-
return {
|
|
77
|
-
recLeft: Math.min(acc.recLeft, left),
|
|
78
|
-
recTop: Math.min(acc.recTop, top),
|
|
79
|
-
recRight: Math.max(acc.recRight, right),
|
|
80
|
-
recBottom: Math.max(acc.recBottom, bottom)
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
// +-Infinity as initialisation vars which will always be overwritten
|
|
84
|
-
// by smaller/larger values respectively
|
|
85
|
-
{
|
|
86
|
-
recLeft: Infinity,
|
|
87
|
-
recTop: Infinity,
|
|
88
|
-
recRight: -Infinity,
|
|
89
|
-
recBottom: -Infinity
|
|
90
|
-
});
|
|
91
|
-
const rect = new Rect(recLeft, recTop, recRight, recBottom);
|
|
46
|
+
if (danger && type !== 'table') {
|
|
47
|
+
const {
|
|
48
|
+
selection
|
|
49
|
+
} = tr;
|
|
50
|
+
const table = findTable(selection);
|
|
51
|
+
const rect = getSelectionRect(selection);
|
|
52
|
+
if (table && rect) {
|
|
92
53
|
updatedCells = map.cellsInRect(rect).map(x => x + table.start);
|
|
93
54
|
}
|
|
94
55
|
}
|
|
@@ -4,7 +4,6 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
4
4
|
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; }
|
|
5
5
|
import React, { forwardRef, useCallback, useRef, useState } from 'react';
|
|
6
6
|
import classNames from 'classnames';
|
|
7
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
8
7
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
9
8
|
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
10
9
|
import { akEditorDefaultLayoutWidth, akEditorGutterPadding, akEditorMediaResizeHandlerPaddingWide, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
|
|
@@ -37,7 +36,6 @@ export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
37
36
|
}, children);
|
|
38
37
|
});
|
|
39
38
|
export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
|
|
40
|
-
var _node$attrs$localId, _node$attrs;
|
|
41
39
|
var children = _ref2.children,
|
|
42
40
|
className = _ref2.className,
|
|
43
41
|
node = _ref2.node,
|
|
@@ -109,18 +107,10 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
109
107
|
return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.core) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$s = pluginInjectionApi.selection) === null || _pluginInjectionApi$s === void 0 ? void 0 : _pluginInjectionApi$s.commands.displayGapCursor(toggle))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
|
|
110
108
|
}, [pluginInjectionApi]);
|
|
111
109
|
var tableWidth = getTableContainerWidth(node);
|
|
112
|
-
var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['table']),
|
|
113
|
-
tableState = _useSharedPluginState.tableState;
|
|
114
|
-
var _ref3 = tableState,
|
|
115
|
-
widthToWidest = _ref3.widthToWidest;
|
|
116
|
-
var currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
|
|
117
110
|
|
|
118
111
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
119
112
|
var responsiveContainerWidth = isTableScalingEnabled ? containerWidth - akEditorGutterPadding * 2 - akEditorMediaResizeHandlerPaddingWide / 2 : containerWidth - akEditorGutterPadding * 2 - akEditorMediaResizeHandlerPaddingWide;
|
|
120
113
|
var width = Math.min(tableWidth, responsiveContainerWidth);
|
|
121
|
-
if (isTableScalingEnabled && currentTableNodeLocalId && widthToWidest && widthToWidest[currentTableNodeLocalId]) {
|
|
122
|
-
width = TABLE_MAX_WIDTH;
|
|
123
|
-
}
|
|
124
114
|
if (!isResizing) {
|
|
125
115
|
tableWidthRef.current = width;
|
|
126
116
|
}
|
|
@@ -164,24 +154,24 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
164
154
|
node: node
|
|
165
155
|
}, children))));
|
|
166
156
|
});
|
|
167
|
-
export var TableContainer = function TableContainer(
|
|
168
|
-
var children =
|
|
169
|
-
node =
|
|
170
|
-
className =
|
|
171
|
-
|
|
172
|
-
lineLength =
|
|
173
|
-
editorWidth =
|
|
174
|
-
isTableResizingEnabled =
|
|
175
|
-
isBreakoutEnabled =
|
|
176
|
-
editorView =
|
|
177
|
-
getPos =
|
|
178
|
-
tableRef =
|
|
179
|
-
isNested =
|
|
180
|
-
tableWrapperHeight =
|
|
181
|
-
isResizing =
|
|
182
|
-
pluginInjectionApi =
|
|
183
|
-
isTableScalingEnabled =
|
|
184
|
-
isWholeTableInDanger =
|
|
157
|
+
export var TableContainer = function TableContainer(_ref3) {
|
|
158
|
+
var children = _ref3.children,
|
|
159
|
+
node = _ref3.node,
|
|
160
|
+
className = _ref3.className,
|
|
161
|
+
_ref3$containerWidth = _ref3.containerWidth,
|
|
162
|
+
lineLength = _ref3$containerWidth.lineLength,
|
|
163
|
+
editorWidth = _ref3$containerWidth.width,
|
|
164
|
+
isTableResizingEnabled = _ref3.isTableResizingEnabled,
|
|
165
|
+
isBreakoutEnabled = _ref3.isBreakoutEnabled,
|
|
166
|
+
editorView = _ref3.editorView,
|
|
167
|
+
getPos = _ref3.getPos,
|
|
168
|
+
tableRef = _ref3.tableRef,
|
|
169
|
+
isNested = _ref3.isNested,
|
|
170
|
+
tableWrapperHeight = _ref3.tableWrapperHeight,
|
|
171
|
+
isResizing = _ref3.isResizing,
|
|
172
|
+
pluginInjectionApi = _ref3.pluginInjectionApi,
|
|
173
|
+
isTableScalingEnabled = _ref3.isTableScalingEnabled,
|
|
174
|
+
isWholeTableInDanger = _ref3.isWholeTableInDanger;
|
|
185
175
|
if (isTableResizingEnabled && !isNested) {
|
|
186
176
|
return /*#__PURE__*/React.createElement(ResizableTableContainer, {
|
|
187
177
|
className: className,
|
|
@@ -94,10 +94,6 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
94
94
|
// track resizing state - use ref over state to avoid re-render
|
|
95
95
|
var isResizing = useRef(false);
|
|
96
96
|
var areResizeMetaKeysPressed = useRef(false);
|
|
97
|
-
var _useState = useState(width),
|
|
98
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
99
|
-
localTableWidth = _useState2[0],
|
|
100
|
-
setLocalTableWidth = _useState2[1];
|
|
101
97
|
var resizerRef = useRef(null);
|
|
102
98
|
var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['table']),
|
|
103
99
|
tableState = _useSharedPluginState.tableState;
|
|
@@ -106,10 +102,10 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
106
102
|
|
|
107
103
|
// used to reposition tooltip when table is resizing via keyboard
|
|
108
104
|
var updateTooltip = React.useRef();
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
snappingEnabled =
|
|
112
|
-
setSnappingEnabled =
|
|
105
|
+
var _useState = useState(false),
|
|
106
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
107
|
+
snappingEnabled = _useState2[0],
|
|
108
|
+
setSnappingEnabled = _useState2[1];
|
|
113
109
|
var _useIntl = useIntl(),
|
|
114
110
|
formatMessage = _useIntl.formatMessage;
|
|
115
111
|
var isTableSelected = ((_findTable = findTable((_editorView$state = editorView.state) === null || _editorView$state === void 0 ? void 0 : _editorView$state.selection)) === null || _findTable === void 0 ? void 0 : _findTable.pos) === getPos();
|
|
@@ -169,7 +165,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
169
165
|
}
|
|
170
166
|
}, [startMeasure, editorView, displayGapCursor, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
171
167
|
var handleResize = useCallback(function (originalState, delta) {
|
|
172
|
-
var _node$attrs$localId, _node$attrs
|
|
168
|
+
var _node$attrs$localId, _node$attrs;
|
|
173
169
|
countFrames();
|
|
174
170
|
var newWidth = originalState.width + delta.width;
|
|
175
171
|
var pos;
|
|
@@ -187,20 +183,18 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
187
183
|
start: pos + 1,
|
|
188
184
|
parentWidth: newWidth
|
|
189
185
|
}, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
|
|
190
|
-
|
|
186
|
+
var closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(containerWidth) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
|
|
187
|
+
updateActiveGuidelines(closestSnap);
|
|
191
188
|
|
|
192
|
-
//
|
|
193
|
-
// and a table is resized to fit the widest guideline when view port width is between 1011 and 1800
|
|
194
|
-
// set the width of the table to 1800 pixels.
|
|
189
|
+
// When snapping to the full width guideline, resize the table to be 1800px
|
|
195
190
|
var state = editorView.state,
|
|
196
191
|
dispatch = editorView.dispatch;
|
|
197
192
|
var currentTableNodeLocalId = (_node$attrs$localId = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '';
|
|
198
|
-
var
|
|
193
|
+
var fullWidthGuideline = defaultGuidelinesForPreserveTable(containerWidth).filter(function (guideline) {
|
|
199
194
|
return guideline.isFullWidth;
|
|
200
195
|
})[0];
|
|
201
|
-
var
|
|
202
|
-
var shouldUpdateWidthToWidest = !!
|
|
203
|
-
shouldUpdateWidthToWidest ? setLocalTableWidth(TABLE_MAX_WIDTH) : setLocalTableWidth(newWidth);
|
|
196
|
+
var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
197
|
+
var shouldUpdateWidthToWidest = !!isTableScalingEnabled && isFullWidthGuidelineActive;
|
|
204
198
|
updateWidthToWidest(_defineProperty({}, currentTableNodeLocalId, shouldUpdateWidthToWidest))(state, dispatch);
|
|
205
199
|
updateWidth(shouldUpdateWidthToWidest ? TABLE_MAX_WIDTH : newWidth);
|
|
206
200
|
return newWidth;
|
|
@@ -280,7 +274,6 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
280
274
|
if (newWidth > maxWidth || newWidth < resizerMinWidth) {
|
|
281
275
|
return;
|
|
282
276
|
}
|
|
283
|
-
setLocalTableWidth(newWidth);
|
|
284
277
|
handleResizeStop({
|
|
285
278
|
width: width,
|
|
286
279
|
x: 0,
|
|
@@ -359,7 +352,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
359
352
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ResizerNext, {
|
|
360
353
|
ref: resizerRef,
|
|
361
354
|
enable: handles,
|
|
362
|
-
width:
|
|
355
|
+
width: width,
|
|
363
356
|
handleAlignmentMethod: "sticky",
|
|
364
357
|
handleSize: handleSize,
|
|
365
358
|
handleStyles: handleStyles,
|
|
@@ -7,9 +7,8 @@ import { nonNullable } from '@atlaskit/editor-common/utils';
|
|
|
7
7
|
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
8
8
|
|
|
9
9
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
10
|
-
import {
|
|
10
|
+
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
11
11
|
import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
12
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
13
12
|
import { TableCssClassName as ClassName, TableDecorations } from '../types';
|
|
14
13
|
import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
|
|
15
14
|
var filterDecorationByKey = function filterDecorationByKey(key, decorationSet) {
|
|
@@ -65,51 +64,13 @@ export var createControlsHoverDecoration = function createControlsHoverDecoratio
|
|
|
65
64
|
// So If the table cells are in danger we want to create a "rectangle" selection
|
|
66
65
|
// to match the "clicked" selection
|
|
67
66
|
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return x + _table.start;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
if (danger) {
|
|
81
|
-
// Find the bounding rectangle of all the given cells, also considering
|
|
82
|
-
// merged cells.
|
|
83
|
-
var _cells$reduce3 = cells.reduce(function (acc, cell) {
|
|
84
|
-
var _map$findCell = map.findCell(cell.pos - table.start),
|
|
85
|
-
left = _map$findCell.left,
|
|
86
|
-
right = _map$findCell.right,
|
|
87
|
-
bottom = _map$findCell.bottom,
|
|
88
|
-
top = _map$findCell.top;
|
|
89
|
-
// Finding the bounding rect requires finding the min left and top positions,
|
|
90
|
-
// and the max right and bottom positions of the cells
|
|
91
|
-
return {
|
|
92
|
-
recLeft: Math.min(acc.recLeft, left),
|
|
93
|
-
recTop: Math.min(acc.recTop, top),
|
|
94
|
-
recRight: Math.max(acc.recRight, right),
|
|
95
|
-
recBottom: Math.max(acc.recBottom, bottom)
|
|
96
|
-
};
|
|
97
|
-
},
|
|
98
|
-
// +-Infinity as initialisation vars which will always be overwritten
|
|
99
|
-
// by smaller/larger values respectively
|
|
100
|
-
{
|
|
101
|
-
recLeft: Infinity,
|
|
102
|
-
recTop: Infinity,
|
|
103
|
-
recRight: -Infinity,
|
|
104
|
-
recBottom: -Infinity
|
|
105
|
-
}),
|
|
106
|
-
recLeft = _cells$reduce3.recLeft,
|
|
107
|
-
recTop = _cells$reduce3.recTop,
|
|
108
|
-
recRight = _cells$reduce3.recRight,
|
|
109
|
-
recBottom = _cells$reduce3.recBottom;
|
|
110
|
-
var _rect = new Rect(recLeft, recTop, recRight, recBottom);
|
|
111
|
-
updatedCells = map.cellsInRect(_rect).map(function (x) {
|
|
112
|
-
return x + table.start;
|
|
67
|
+
if (danger && type !== 'table') {
|
|
68
|
+
var selection = tr.selection;
|
|
69
|
+
var _table = findTable(selection);
|
|
70
|
+
var rect = getSelectionRect(selection);
|
|
71
|
+
if (_table && rect) {
|
|
72
|
+
updatedCells = map.cellsInRect(rect).map(function (x) {
|
|
73
|
+
return x + _table.start;
|
|
113
74
|
});
|
|
114
75
|
}
|
|
115
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.10",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -129,9 +129,6 @@
|
|
|
129
129
|
"platform.editor.menu.group-items": {
|
|
130
130
|
"type": "boolean"
|
|
131
131
|
},
|
|
132
|
-
"platform.editor.table.in-danger-hover-merged-cells-fix": {
|
|
133
|
-
"type": "boolean"
|
|
134
|
-
},
|
|
135
132
|
"platform.editor.a11y-column-resizing_emcvz": {
|
|
136
133
|
"type": "boolean"
|
|
137
134
|
},
|
|
@@ -5,7 +5,6 @@ import classNames from 'classnames';
|
|
|
5
5
|
|
|
6
6
|
import type { TableEventPayload } from '@atlaskit/editor-common/analytics';
|
|
7
7
|
import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
|
|
8
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
9
8
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
10
9
|
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
11
10
|
import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
@@ -20,7 +19,7 @@ import {
|
|
|
20
19
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
21
20
|
|
|
22
21
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
23
|
-
import type { PluginInjectionAPI
|
|
22
|
+
import type { PluginInjectionAPI } from '../types';
|
|
24
23
|
import { TableCssClassName as ClassName } from '../types';
|
|
25
24
|
|
|
26
25
|
import { TableResizer } from './TableResizer';
|
|
@@ -181,9 +180,6 @@ export const ResizableTableContainer = React.memo(
|
|
|
181
180
|
);
|
|
182
181
|
|
|
183
182
|
const tableWidth = getTableContainerWidth(node);
|
|
184
|
-
const { tableState } = useSharedPluginState(pluginInjectionApi, ['table']);
|
|
185
|
-
const { widthToWidest } = tableState as TableSharedStateInternal;
|
|
186
|
-
const currentTableNodeLocalId = node?.attrs?.localId ?? '';
|
|
187
183
|
|
|
188
184
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
189
185
|
const responsiveContainerWidth = isTableScalingEnabled
|
|
@@ -196,15 +192,6 @@ export const ResizableTableContainer = React.memo(
|
|
|
196
192
|
|
|
197
193
|
let width = Math.min(tableWidth, responsiveContainerWidth);
|
|
198
194
|
|
|
199
|
-
if (
|
|
200
|
-
isTableScalingEnabled &&
|
|
201
|
-
currentTableNodeLocalId &&
|
|
202
|
-
widthToWidest &&
|
|
203
|
-
widthToWidest[currentTableNodeLocalId]
|
|
204
|
-
) {
|
|
205
|
-
width = TABLE_MAX_WIDTH;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
195
|
if (!isResizing) {
|
|
209
196
|
tableWidthRef.current = width;
|
|
210
197
|
}
|
|
@@ -176,7 +176,6 @@ export const TableResizer = ({
|
|
|
176
176
|
// track resizing state - use ref over state to avoid re-render
|
|
177
177
|
const isResizing = useRef(false);
|
|
178
178
|
const areResizeMetaKeysPressed = useRef(false);
|
|
179
|
-
const [localTableWidth, setLocalTableWidth] = useState(width);
|
|
180
179
|
const resizerRef = useRef<ResizerNextHandler>(null);
|
|
181
180
|
const { tableState } = useSharedPluginState(pluginInjectionApi, ['table']);
|
|
182
181
|
const { widthToWidest } = tableState as TableSharedStateInternal;
|
|
@@ -313,40 +312,33 @@ export const TableResizer = ({
|
|
|
313
312
|
isTableScalingEnabled,
|
|
314
313
|
);
|
|
315
314
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
TABLE_HIGHLIGHT_TOLERANCE,
|
|
327
|
-
),
|
|
315
|
+
const closestSnap = findClosestSnap(
|
|
316
|
+
newWidth,
|
|
317
|
+
isTableScalingEnabled
|
|
318
|
+
? defaultTablePreserveSnappingWidths(containerWidth)
|
|
319
|
+
: defaultSnappingWidths,
|
|
320
|
+
isTableScalingEnabled
|
|
321
|
+
? defaultGuidelinesForPreserveTable(containerWidth)
|
|
322
|
+
: defaultGuidelines,
|
|
323
|
+
TABLE_HIGHLIGHT_GAP,
|
|
324
|
+
TABLE_HIGHLIGHT_TOLERANCE,
|
|
328
325
|
);
|
|
329
326
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
//
|
|
327
|
+
updateActiveGuidelines(closestSnap);
|
|
328
|
+
|
|
329
|
+
// When snapping to the full width guideline, resize the table to be 1800px
|
|
333
330
|
const { state, dispatch } = editorView;
|
|
334
331
|
const currentTableNodeLocalId = node?.attrs?.localId ?? '';
|
|
335
332
|
|
|
336
|
-
const
|
|
333
|
+
const fullWidthGuideline = defaultGuidelinesForPreserveTable(
|
|
337
334
|
containerWidth,
|
|
338
335
|
).filter((guideline) => guideline.isFullWidth)[0];
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const shouldUpdateWidthToWidest = !!(
|
|
343
|
-
isTableScalingEnabled &&
|
|
344
|
-
widestGuideLineWidth &&
|
|
345
|
-
Math.abs(widestGuideLineWidth - newWidth) <= 1
|
|
336
|
+
|
|
337
|
+
const isFullWidthGuidelineActive = closestSnap.keys.includes(
|
|
338
|
+
fullWidthGuideline.key,
|
|
346
339
|
);
|
|
347
|
-
shouldUpdateWidthToWidest
|
|
348
|
-
|
|
349
|
-
: setLocalTableWidth(newWidth);
|
|
340
|
+
const shouldUpdateWidthToWidest =
|
|
341
|
+
!!isTableScalingEnabled && isFullWidthGuidelineActive;
|
|
350
342
|
|
|
351
343
|
updateWidthToWidest({
|
|
352
344
|
[currentTableNodeLocalId]: shouldUpdateWidthToWidest,
|
|
@@ -486,7 +478,6 @@ export const TableResizer = ({
|
|
|
486
478
|
if (newWidth > maxWidth || newWidth < resizerMinWidth) {
|
|
487
479
|
return;
|
|
488
480
|
}
|
|
489
|
-
setLocalTableWidth(newWidth);
|
|
490
481
|
handleResizeStop(
|
|
491
482
|
{ width: width, x: 0, y: 0, height: 0 },
|
|
492
483
|
{ width: step, height: 0 },
|
|
@@ -599,7 +590,7 @@ export const TableResizer = ({
|
|
|
599
590
|
<ResizerNext
|
|
600
591
|
ref={resizerRef}
|
|
601
592
|
enable={handles}
|
|
602
|
-
width={
|
|
593
|
+
width={width}
|
|
603
594
|
handleAlignmentMethod="sticky"
|
|
604
595
|
handleSize={handleSize}
|
|
605
596
|
handleStyles={handleStyles}
|
package/src/utils/decoration.ts
CHANGED
|
@@ -16,13 +16,12 @@ import type {
|
|
|
16
16
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
17
17
|
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
18
18
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
19
|
-
import {
|
|
19
|
+
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
20
20
|
import {
|
|
21
21
|
findTable,
|
|
22
22
|
getCellsInRow,
|
|
23
23
|
getSelectionRect,
|
|
24
24
|
} from '@atlaskit/editor-tables/utils';
|
|
25
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
26
25
|
|
|
27
26
|
import type { Cell, CellColumnPositioning } from '../types';
|
|
28
27
|
import { TableCssClassName as ClassName, TableDecorations } from '../types';
|
|
@@ -102,44 +101,12 @@ export const createControlsHoverDecoration = (
|
|
|
102
101
|
// So If the table cells are in danger we want to create a "rectangle" selection
|
|
103
102
|
// to match the "clicked" selection
|
|
104
103
|
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const rect = getSelectionRect(selection);
|
|
104
|
+
if (danger && type !== 'table') {
|
|
105
|
+
const { selection } = tr;
|
|
106
|
+
const table = findTable(selection);
|
|
107
|
+
const rect = getSelectionRect(selection);
|
|
110
108
|
|
|
111
|
-
|
|
112
|
-
updatedCells = map.cellsInRect(rect).map((x) => x + table.start);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} else {
|
|
116
|
-
if (danger) {
|
|
117
|
-
// Find the bounding rectangle of all the given cells, also considering
|
|
118
|
-
// merged cells.
|
|
119
|
-
const { recLeft, recTop, recRight, recBottom } = cells.reduce(
|
|
120
|
-
(acc, cell) => {
|
|
121
|
-
const { left, right, bottom, top } = map.findCell(
|
|
122
|
-
cell.pos - table.start,
|
|
123
|
-
);
|
|
124
|
-
// Finding the bounding rect requires finding the min left and top positions,
|
|
125
|
-
// and the max right and bottom positions of the cells
|
|
126
|
-
return {
|
|
127
|
-
recLeft: Math.min(acc.recLeft, left),
|
|
128
|
-
recTop: Math.min(acc.recTop, top),
|
|
129
|
-
recRight: Math.max(acc.recRight, right),
|
|
130
|
-
recBottom: Math.max(acc.recBottom, bottom),
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
// +-Infinity as initialisation vars which will always be overwritten
|
|
134
|
-
// by smaller/larger values respectively
|
|
135
|
-
{
|
|
136
|
-
recLeft: Infinity,
|
|
137
|
-
recTop: Infinity,
|
|
138
|
-
recRight: -Infinity,
|
|
139
|
-
recBottom: -Infinity,
|
|
140
|
-
},
|
|
141
|
-
);
|
|
142
|
-
const rect = new Rect(recLeft, recTop, recRight, recBottom);
|
|
109
|
+
if (table && rect) {
|
|
143
110
|
updatedCells = map.cellsInRect(rect).map((x) => x + table.start);
|
|
144
111
|
}
|
|
145
112
|
}
|