@atlaskit/editor-plugin-table 7.16.12 → 7.16.13
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 +8 -0
- package/dist/cjs/nodeviews/TableContainer.js +44 -23
- package/dist/cjs/nodeviews/TableResizer.js +33 -12
- package/dist/cjs/utils/guidelines.js +7 -4
- package/dist/cjs/utils/snapping.js +7 -8
- package/dist/es2019/nodeviews/TableContainer.js +27 -4
- package/dist/es2019/nodeviews/TableResizer.js +35 -14
- package/dist/es2019/utils/guidelines.js +5 -2
- package/dist/es2019/utils/snapping.js +5 -6
- package/dist/esm/nodeviews/TableContainer.js +45 -24
- package/dist/esm/nodeviews/TableResizer.js +35 -14
- package/dist/esm/utils/guidelines.js +6 -3
- package/dist/esm/utils/snapping.js +6 -7
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/utils/guidelines.d.ts +2 -1
- package/dist/types/utils/snapping.d.ts +3 -2
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/utils/guidelines.d.ts +2 -1
- package/dist/types-ts4.5/utils/snapping.d.ts +3 -2
- package/package.json +2 -2
- package/src/nodeviews/TableContainer.tsx +27 -7
- package/src/nodeviews/TableResizer.tsx +93 -12
- package/src/utils/guidelines.ts +7 -1
- package/src/utils/snapping.ts +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.16.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#104756](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/104756)
|
|
8
|
+
[`bf2f24fa1ffa`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bf2f24fa1ffa) -
|
|
9
|
+
[ux] Fix table container position on resize in full-width editor on smaller screens.
|
|
10
|
+
|
|
3
11
|
## 7.16.12
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -131,6 +131,10 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
|
|
|
131
131
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
132
132
|
resizing = _useState2[0],
|
|
133
133
|
setIsResizing = _useState2[1];
|
|
134
|
+
var _useSharedPluginState2 = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['table']),
|
|
135
|
+
tableState = _useSharedPluginState2.tableState;
|
|
136
|
+
var _ref5 = tableState,
|
|
137
|
+
isFullWidthModeEnabled = _ref5.isFullWidthModeEnabled;
|
|
134
138
|
var updateContainerHeight = (0, _react.useCallback)(function (height) {
|
|
135
139
|
var _containerRef$current;
|
|
136
140
|
// current StickyHeader State is not stable to be fetch.
|
|
@@ -184,11 +188,27 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
|
|
|
184
188
|
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;
|
|
185
189
|
}, [pluginInjectionApi]);
|
|
186
190
|
var tableWidth = (0, _nodeWidth.getTableContainerWidth)(node);
|
|
187
|
-
var
|
|
188
|
-
editorViewModeState =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
var _useSharedPluginState3 = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['editorViewMode']),
|
|
192
|
+
editorViewModeState = _useSharedPluginState3.editorViewModeState;
|
|
193
|
+
var responsiveContainerWidth = 0;
|
|
194
|
+
var resizeHandleSpacing = 12;
|
|
195
|
+
// When Full width editor enabled, a Mac OS user can change "ak-editor-content-area" width by
|
|
196
|
+
// updating Settings -> Appearance -> Show scroll bars from "When scrolling" to "Always". It causes
|
|
197
|
+
// issues when viwport width is less than full width Editor's width. To detect avoid them
|
|
198
|
+
// we need to use lineLength to defined responsiveWidth instead of containerWidth
|
|
199
|
+
// (which does not get updated when Mac setting changes) in Full-width editor.
|
|
200
|
+
if (isFullWidthModeEnabled) {
|
|
201
|
+
// When: Show scroll bars -> containerWidth = akEditorGutterPadding * 2 + lineLength;
|
|
202
|
+
// When: Always -> containerWidth = akEditorGutterPadding * 2 + lineLength + scrollbarWidth;
|
|
203
|
+
// scrollbarWidth can vary. Values can be 14, 15, 16 and up to 20px;
|
|
204
|
+
responsiveContainerWidth = isTableScalingEnabled ? lineLength : containerWidth - _editorSharedStyles.akEditorGutterPadding * 2 - resizeHandleSpacing;
|
|
205
|
+
} else {
|
|
206
|
+
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
207
|
+
// containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
|
|
208
|
+
// a DIV with className="ak-editor-content-area". This DIV has padding left and padding right.
|
|
209
|
+
// padding left = padding right = akEditorGutterPadding = 32
|
|
210
|
+
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - _editorSharedStyles.akEditorGutterPadding * 2 : containerWidth - _editorSharedStyles.akEditorGutterPadding * 2 - resizeHandleSpacing;
|
|
211
|
+
}
|
|
192
212
|
var width = Math.min(tableWidth, responsiveContainerWidth);
|
|
193
213
|
if (!isResizing) {
|
|
194
214
|
tableWidthRef.current = width;
|
|
@@ -208,6 +228,7 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
|
|
|
208
228
|
attachAnalyticsEvent: attachAnalyticsEvent,
|
|
209
229
|
displayGapCursor: displayGapCursor,
|
|
210
230
|
isTableAlignmentEnabled: isTableAlignmentEnabled,
|
|
231
|
+
isFullWidthModeEnabled: isFullWidthModeEnabled,
|
|
211
232
|
isTableScalingEnabled: isTableScalingEnabled,
|
|
212
233
|
isWholeTableInDanger: isWholeTableInDanger,
|
|
213
234
|
pluginInjectionApi: pluginInjectionApi,
|
|
@@ -246,24 +267,24 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
|
|
|
246
267
|
node: node
|
|
247
268
|
}, children))));
|
|
248
269
|
});
|
|
249
|
-
var TableContainer = exports.TableContainer = function TableContainer(
|
|
250
|
-
var children =
|
|
251
|
-
node =
|
|
252
|
-
className =
|
|
253
|
-
|
|
254
|
-
editorWidth =
|
|
255
|
-
lineLength =
|
|
256
|
-
editorView =
|
|
257
|
-
getPos =
|
|
258
|
-
tableRef =
|
|
259
|
-
isNested =
|
|
260
|
-
tableWrapperHeight =
|
|
261
|
-
isResizing =
|
|
262
|
-
pluginInjectionApi =
|
|
263
|
-
isWholeTableInDanger =
|
|
264
|
-
isTableResizingEnabled =
|
|
265
|
-
isTableScalingEnabled =
|
|
266
|
-
isTableAlignmentEnabled =
|
|
270
|
+
var TableContainer = exports.TableContainer = function TableContainer(_ref6) {
|
|
271
|
+
var children = _ref6.children,
|
|
272
|
+
node = _ref6.node,
|
|
273
|
+
className = _ref6.className,
|
|
274
|
+
_ref6$containerWidth = _ref6.containerWidth,
|
|
275
|
+
editorWidth = _ref6$containerWidth.width,
|
|
276
|
+
lineLength = _ref6$containerWidth.lineLength,
|
|
277
|
+
editorView = _ref6.editorView,
|
|
278
|
+
getPos = _ref6.getPos,
|
|
279
|
+
tableRef = _ref6.tableRef,
|
|
280
|
+
isNested = _ref6.isNested,
|
|
281
|
+
tableWrapperHeight = _ref6.tableWrapperHeight,
|
|
282
|
+
isResizing = _ref6.isResizing,
|
|
283
|
+
pluginInjectionApi = _ref6.pluginInjectionApi,
|
|
284
|
+
isWholeTableInDanger = _ref6.isWholeTableInDanger,
|
|
285
|
+
isTableResizingEnabled = _ref6.isTableResizingEnabled,
|
|
286
|
+
isTableScalingEnabled = _ref6.isTableScalingEnabled,
|
|
287
|
+
isTableAlignmentEnabled = _ref6.isTableAlignmentEnabled;
|
|
267
288
|
if (isTableResizingEnabled && !isNested) {
|
|
268
289
|
return /*#__PURE__*/_react.default.createElement(ResizableTableContainer
|
|
269
290
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
@@ -19,6 +19,7 @@ var _messages = require("@atlaskit/editor-common/messages");
|
|
|
19
19
|
var _resizer = require("@atlaskit/editor-common/resizer");
|
|
20
20
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
21
21
|
var _commands = require("@atlaskit/editor-prosemirror/commands");
|
|
22
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
22
23
|
var _utils2 = require("@atlaskit/editor-tables/utils");
|
|
23
24
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
24
25
|
var _misc = require("../commands/misc");
|
|
@@ -78,10 +79,26 @@ var getResizerMinWidth = function getResizerMinWidth(node) {
|
|
|
78
79
|
* So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
|
|
79
80
|
* @param guidelines
|
|
80
81
|
* @param containerWidth editorWidth
|
|
82
|
+
* @param lineLength
|
|
83
|
+
* @param isTableScalingEnabled
|
|
84
|
+
* @param isFullWidthModeEnabled
|
|
81
85
|
*/
|
|
82
|
-
var getVisibleGuidelines = function getVisibleGuidelines(guidelines, containerWidth) {
|
|
86
|
+
var getVisibleGuidelines = function getVisibleGuidelines(guidelines, containerWidth, lineLength, isTableScalingEnabled, isFullWidthModeEnabled) {
|
|
87
|
+
var guidelineVisibleAdjustment = _consts.TABLE_GUIDELINE_VISIBLE_ADJUSTMENT;
|
|
88
|
+
if (isTableScalingEnabled) {
|
|
89
|
+
// Notes:
|
|
90
|
+
// Example: containerWidth = 1244, lineLength = 1180 (used for when editor full width mode is enabled)
|
|
91
|
+
// Full width/dynamic x coordinate can be float number.
|
|
92
|
+
// Ex: guideline.position.x can be 590.5. So 590.5 * 2 = 1181 (not 1180).
|
|
93
|
+
// For PTW we need to ensure that dynamic guideline never gets excluded: 1181 should be > width + guidelineVisibleAdjustment
|
|
94
|
+
// guidelineVisibleAdjustment is set as a negative value, so we making it positive and adding + 1
|
|
95
|
+
var preserve_table_widths_adjustment = -1 * _guidelines.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET + 1;
|
|
96
|
+
guidelineVisibleAdjustment = isFullWidthModeEnabled ? preserve_table_widths_adjustment // guidelineVisibleAdjustment = -2, if lineLength = 1180, 1181 < 1180 + 2 is true.
|
|
97
|
+
: -2 * _editorSharedStyles.akEditorGutterPadding + preserve_table_widths_adjustment; // guidelineVisibleAdjustment = -62, if containerWidth is 1244, 1181 < 1244 - 62 = 1182 is true.
|
|
98
|
+
}
|
|
99
|
+
var width = isTableScalingEnabled && isFullWidthModeEnabled ? lineLength : containerWidth;
|
|
83
100
|
return guidelines.filter(function (guideline) {
|
|
84
|
-
return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) <
|
|
101
|
+
return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) < width + guidelineVisibleAdjustment;
|
|
85
102
|
});
|
|
86
103
|
};
|
|
87
104
|
var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
@@ -104,7 +121,8 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
104
121
|
isTableScalingEnabled = _ref.isTableScalingEnabled,
|
|
105
122
|
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled,
|
|
106
123
|
isWholeTableInDanger = _ref.isWholeTableInDanger,
|
|
107
|
-
pluginInjectionApi = _ref.pluginInjectionApi
|
|
124
|
+
pluginInjectionApi = _ref.pluginInjectionApi,
|
|
125
|
+
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled;
|
|
108
126
|
var currentGap = (0, _react.useRef)(0);
|
|
109
127
|
// track resizing state - use ref over state to avoid re-render
|
|
110
128
|
var isResizing = (0, _react.useRef)(false);
|
|
@@ -141,15 +159,17 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
141
159
|
keys = _ref3.keys;
|
|
142
160
|
if (gap !== currentGap.current) {
|
|
143
161
|
currentGap.current = gap;
|
|
144
|
-
var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth, excludeGuidelineConfig) : _guidelines.defaultGuidelines, containerWidth);
|
|
162
|
+
var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(_guidelines.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, isFullWidthModeEnabled ? lineLength + 2 * _editorSharedStyles.akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : _guidelines.defaultGuidelines, containerWidth, lineLength, Boolean(isTableScalingEnabled), Boolean(isFullWidthModeEnabled));
|
|
145
163
|
displayGuideline((0, _guideline.getGuidelinesWithHighlights)(gap, _consts.TABLE_SNAP_GAP, keys, visibleGuidelines));
|
|
146
164
|
}
|
|
147
|
-
}, [isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline]);
|
|
165
|
+
}, [isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline, lineLength, isFullWidthModeEnabled]);
|
|
148
166
|
var guidelineSnaps = (0, _react.useMemo)(function () {
|
|
149
167
|
return snappingEnabled ? {
|
|
150
|
-
x: isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(
|
|
168
|
+
x: isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(_snapping.PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET,
|
|
169
|
+
// was hardcoded to 0, using PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
|
|
170
|
+
isFullWidthModeEnabled ? lineLength + 2 * _editorSharedStyles.akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : _snapping.defaultSnappingWidths
|
|
151
171
|
} : undefined;
|
|
152
|
-
}, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth]);
|
|
172
|
+
}, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, isFullWidthModeEnabled]);
|
|
153
173
|
var switchToCenterAlignment = (0, _react.useCallback)(function (pos, node, newWidth, state, dispatch) {
|
|
154
174
|
if (isTableAlignmentEnabled && node && node.attrs.layout === _alignment.ALIGN_START && newWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH &&
|
|
155
175
|
// We don't want to switch alignment in Full-width editor
|
|
@@ -199,12 +219,12 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
199
219
|
name: _analytics.TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
|
|
200
220
|
});
|
|
201
221
|
dispatch(tr);
|
|
202
|
-
var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(containerWidth, excludeGuidelineConfig) : _guidelines.defaultGuidelines, containerWidth);
|
|
222
|
+
var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(_guidelines.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, isFullWidthModeEnabled ? lineLength + 2 * _editorSharedStyles.akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : _guidelines.defaultGuidelines, containerWidth, lineLength, Boolean(isTableScalingEnabled), Boolean(isFullWidthModeEnabled));
|
|
203
223
|
setSnappingEnabled(displayGuideline(visibleGuidelines));
|
|
204
224
|
if (onResizeStart) {
|
|
205
225
|
onResizeStart();
|
|
206
226
|
}
|
|
207
|
-
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline, onResizeStart]);
|
|
227
|
+
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, displayGuideline, onResizeStart, isFullWidthModeEnabled]);
|
|
208
228
|
var handleResize = (0, _react.useCallback)(function (originalState, delta) {
|
|
209
229
|
var _node$attrs$localId, _node$attrs;
|
|
210
230
|
countFrames();
|
|
@@ -224,14 +244,15 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
224
244
|
start: pos + 1,
|
|
225
245
|
parentWidth: newWidth
|
|
226
246
|
}, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
|
|
227
|
-
var
|
|
247
|
+
var editorContainerWidth = isFullWidthModeEnabled ? lineLength + 2 * _editorSharedStyles.akEditorGutterPadding : containerWidth;
|
|
248
|
+
var closestSnap = (0, _snapping.findClosestSnap)(newWidth, isTableScalingEnabled ? (0, _snapping.defaultTablePreserveSnappingWidths)(_snapping.PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : _snapping.defaultSnappingWidths, isTableScalingEnabled ? (0, _guidelines.defaultGuidelinesForPreserveTable)(_guidelines.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE);
|
|
228
249
|
updateActiveGuidelines(closestSnap);
|
|
229
250
|
|
|
230
251
|
// When snapping to the full width guideline, resize the table to be 1800px
|
|
231
252
|
var state = editorView.state,
|
|
232
253
|
dispatch = editorView.dispatch;
|
|
233
254
|
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 : '';
|
|
234
|
-
var fullWidthGuideline = (0, _guidelines.defaultGuidelinesForPreserveTable)(
|
|
255
|
+
var fullWidthGuideline = (0, _guidelines.defaultGuidelinesForPreserveTable)(_guidelines.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig).filter(function (guideline) {
|
|
235
256
|
return guideline.isFullWidth;
|
|
236
257
|
})[0];
|
|
237
258
|
var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
@@ -241,7 +262,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
241
262
|
}, (0, _misc.updateWidthToWidest)((0, _defineProperty2.default)({}, currentTableNodeLocalId, shouldUpdateWidthToWidest)))(state, dispatch);
|
|
242
263
|
updateWidth(shouldUpdateWidthToWidest ? _utils3.TABLE_MAX_WIDTH : newWidth);
|
|
243
264
|
return newWidth;
|
|
244
|
-
}, [countFrames, isTableScalingEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos, switchToCenterAlignment]);
|
|
265
|
+
}, [countFrames, isTableScalingEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
245
266
|
var scheduleResize = (0, _react.useMemo)(function () {
|
|
246
267
|
return (0, _rafSchd.default)(handleResize);
|
|
247
268
|
}, [handleResize]);
|
|
@@ -4,18 +4,21 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.defaultGuidelinesForPreserveTable = exports.defaultGuidelines = void 0;
|
|
7
|
+
exports.defaultGuidelinesForPreserveTable = exports.defaultGuidelines = exports.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _guideline = require("@atlaskit/editor-common/guideline");
|
|
10
10
|
var _snapping = require("./snapping");
|
|
11
11
|
// NOTE: We have to take 1 pixel off every length due to the fact that the tbody is 1px smaller then the table container.
|
|
12
12
|
// If we don't do this then the guidelines will not align correctly to the edge of the table
|
|
13
13
|
var defaultGuidelines = exports.defaultGuidelines = (0, _guideline.createFixedGuidelinesFromLengths)([0].concat((0, _toConsumableArray2.default)((0, _snapping.calculateDefaultSnappings)(-1))));
|
|
14
|
-
var
|
|
15
|
-
|
|
14
|
+
var PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET = exports.PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET = -1;
|
|
15
|
+
var defaultGuidelinesForPreserveTable = exports.defaultGuidelinesForPreserveTable = function defaultGuidelinesForPreserveTable(lengthOffset, editorContainerWidth) {
|
|
16
|
+
var exclude = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
16
17
|
innerGuidelines: false,
|
|
17
18
|
breakoutPoints: false
|
|
18
19
|
};
|
|
19
|
-
var lengths = (0, _snapping.calculateDefaultTablePreserveSnappings)(
|
|
20
|
+
var lengths = (0, _snapping.calculateDefaultTablePreserveSnappings)(lengthOffset,
|
|
21
|
+
// was hardcoded to -1 here, created PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET instead.
|
|
22
|
+
editorContainerWidth, exclude);
|
|
20
23
|
return (0, _guideline.createFixedGuidelinesFromLengths)(lengths, undefined, true);
|
|
21
24
|
};
|
|
@@ -4,11 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.findClosestSnap = exports.defaultTablePreserveSnappingWidths = exports.defaultSnappingWidths = exports.calculateDefaultTablePreserveSnappings = exports.calculateDefaultSnappings = void 0;
|
|
7
|
+
exports.findClosestSnap = exports.defaultTablePreserveSnappingWidths = exports.defaultSnappingWidths = exports.calculateDefaultTablePreserveSnappings = exports.calculateDefaultSnappings = exports.PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _guideline = require("@atlaskit/editor-common/guideline");
|
|
10
10
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
11
|
-
var _consts = require("../ui/consts");
|
|
12
11
|
var numberOfLanesInDefaultLayoutWidth = 12;
|
|
13
12
|
var calculateSubSnappingWidths = function calculateSubSnappingWidths(totalLanes, totalWidth) {
|
|
14
13
|
return new Array(Math.round(totalLanes / 2) - 1).fill(totalWidth / totalLanes).map(function (v, i) {
|
|
@@ -27,7 +26,7 @@ var calculateDefaultTablePreserveSnappings = exports.calculateDefaultTablePreser
|
|
|
27
26
|
innerGuidelines: false,
|
|
28
27
|
breakoutPoints: false
|
|
29
28
|
};
|
|
30
|
-
var dynamicFullWidthLine = editorContainerWith - _editorSharedStyles.akEditorGutterPadding * 2 >= _editorSharedStyles.akEditorFullWidthLayoutWidth ? _editorSharedStyles.akEditorFullWidthLayoutWidth : editorContainerWith - _editorSharedStyles.akEditorGutterPadding * 2
|
|
29
|
+
var dynamicFullWidthLine = editorContainerWith - _editorSharedStyles.akEditorGutterPadding * 2 >= _editorSharedStyles.akEditorFullWidthLayoutWidth ? _editorSharedStyles.akEditorFullWidthLayoutWidth : editorContainerWith - _editorSharedStyles.akEditorGutterPadding * 2;
|
|
31
30
|
var guides = [dynamicFullWidthLine - lengthOffset];
|
|
32
31
|
if (!exclude.breakoutPoints) {
|
|
33
32
|
guides.unshift(_editorSharedStyles.akEditorDefaultLayoutWidth + lengthOffset, _editorSharedStyles.akEditorCalculatedWideLayoutWidth + lengthOffset);
|
|
@@ -38,18 +37,18 @@ var calculateDefaultTablePreserveSnappings = exports.calculateDefaultTablePreser
|
|
|
38
37
|
return guides;
|
|
39
38
|
};
|
|
40
39
|
var defaultSnappingWidths = exports.defaultSnappingWidths = calculateDefaultSnappings();
|
|
41
|
-
|
|
40
|
+
var PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = exports.PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = 0;
|
|
42
41
|
// FF TablePreserve for defaultSnappingWidths
|
|
43
|
-
var defaultTablePreserveSnappingWidths = exports.defaultTablePreserveSnappingWidths = function defaultTablePreserveSnappingWidths(editorContainerWidth) {
|
|
44
|
-
var exclude = arguments.length >
|
|
42
|
+
var defaultTablePreserveSnappingWidths = exports.defaultTablePreserveSnappingWidths = function defaultTablePreserveSnappingWidths(lengthOffset, editorContainerWidth) {
|
|
43
|
+
var exclude = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
45
44
|
innerGuidelines: false,
|
|
46
45
|
breakoutPoints: false
|
|
47
46
|
};
|
|
48
|
-
return editorContainerWidth - _editorSharedStyles.akEditorGutterPadding * 2 > _editorSharedStyles.akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(
|
|
47
|
+
return editorContainerWidth - _editorSharedStyles.akEditorGutterPadding * 2 > _editorSharedStyles.akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(lengthOffset, editorContainerWidth, exclude); // lengthOffset was hardcoded 0 here, created PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
/**
|
|
52
|
-
* Returns keys of guidelines that are closest to the table and
|
|
51
|
+
* Returns keys of guidelines that are closest to the table and within the snapGap
|
|
53
52
|
*/
|
|
54
53
|
var findClosestSnap = exports.findClosestSnap = function findClosestSnap(currentWidth, snapWidths, guidelines) {
|
|
55
54
|
var snapGap = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
@@ -2,7 +2,7 @@ import React, { forwardRef, useCallback, useEffect, useMemo, useRef, useState }
|
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
5
|
-
import { akEditorDefaultLayoutWidth, akEditorGutterPadding,
|
|
5
|
+
import { akEditorDefaultLayoutWidth, akEditorGutterPadding, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
|
|
6
6
|
import { setTableAlignmentWithTableContentWithPos } from '../commands/misc';
|
|
7
7
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
8
8
|
import { TableCssClassName as ClassName } from '../types';
|
|
@@ -124,6 +124,12 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
124
124
|
const containerRef = useRef(null);
|
|
125
125
|
const tableWidthRef = useRef(akEditorDefaultLayoutWidth);
|
|
126
126
|
const [resizing, setIsResizing] = useState(false);
|
|
127
|
+
const {
|
|
128
|
+
tableState
|
|
129
|
+
} = useSharedPluginState(pluginInjectionApi, ['table']);
|
|
130
|
+
const {
|
|
131
|
+
isFullWidthModeEnabled
|
|
132
|
+
} = tableState;
|
|
127
133
|
const updateContainerHeight = useCallback(height => {
|
|
128
134
|
var _containerRef$current;
|
|
129
135
|
// current StickyHeader State is not stable to be fetch.
|
|
@@ -180,9 +186,25 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
180
186
|
const {
|
|
181
187
|
editorViewModeState
|
|
182
188
|
} = useSharedPluginState(pluginInjectionApi, ['editorViewMode']);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
let responsiveContainerWidth = 0;
|
|
190
|
+
const resizeHandleSpacing = 12;
|
|
191
|
+
// When Full width editor enabled, a Mac OS user can change "ak-editor-content-area" width by
|
|
192
|
+
// updating Settings -> Appearance -> Show scroll bars from "When scrolling" to "Always". It causes
|
|
193
|
+
// issues when viwport width is less than full width Editor's width. To detect avoid them
|
|
194
|
+
// we need to use lineLength to defined responsiveWidth instead of containerWidth
|
|
195
|
+
// (which does not get updated when Mac setting changes) in Full-width editor.
|
|
196
|
+
if (isFullWidthModeEnabled) {
|
|
197
|
+
// When: Show scroll bars -> containerWidth = akEditorGutterPadding * 2 + lineLength;
|
|
198
|
+
// When: Always -> containerWidth = akEditorGutterPadding * 2 + lineLength + scrollbarWidth;
|
|
199
|
+
// scrollbarWidth can vary. Values can be 14, 15, 16 and up to 20px;
|
|
200
|
+
responsiveContainerWidth = isTableScalingEnabled ? lineLength : containerWidth - akEditorGutterPadding * 2 - resizeHandleSpacing;
|
|
201
|
+
} else {
|
|
202
|
+
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
203
|
+
// containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
|
|
204
|
+
// a DIV with className="ak-editor-content-area". This DIV has padding left and padding right.
|
|
205
|
+
// padding left = padding right = akEditorGutterPadding = 32
|
|
206
|
+
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - akEditorGutterPadding * 2 : containerWidth - akEditorGutterPadding * 2 - resizeHandleSpacing;
|
|
207
|
+
}
|
|
186
208
|
let width = Math.min(tableWidth, responsiveContainerWidth);
|
|
187
209
|
if (!isResizing) {
|
|
188
210
|
tableWidthRef.current = width;
|
|
@@ -202,6 +224,7 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
202
224
|
attachAnalyticsEvent,
|
|
203
225
|
displayGapCursor,
|
|
204
226
|
isTableAlignmentEnabled,
|
|
227
|
+
isFullWidthModeEnabled,
|
|
205
228
|
isTableScalingEnabled,
|
|
206
229
|
isWholeTableInDanger,
|
|
207
230
|
pluginInjectionApi,
|
|
@@ -9,6 +9,7 @@ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
|
9
9
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
10
10
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
11
11
|
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
12
|
+
import { akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
12
13
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
13
14
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
15
|
import { setTableAlignmentWithTableContentWithPos, updateWidthToWidest } from '../commands/misc';
|
|
@@ -18,8 +19,8 @@ import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
|
18
19
|
import { TABLE_GUIDELINE_VISIBLE_ADJUSTMENT, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
|
|
19
20
|
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment } from '../utils/alignment';
|
|
20
21
|
import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
|
|
21
|
-
import { defaultGuidelines, defaultGuidelinesForPreserveTable } from '../utils/guidelines';
|
|
22
|
-
import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap } from '../utils/snapping';
|
|
22
|
+
import { defaultGuidelines, defaultGuidelinesForPreserveTable, PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET } from '../utils/guidelines';
|
|
23
|
+
import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap, PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET } from '../utils/snapping';
|
|
23
24
|
const RESIZE_STEP_VALUE = 10;
|
|
24
25
|
const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
25
26
|
const handles = {
|
|
@@ -64,10 +65,26 @@ const getResizerMinWidth = node => {
|
|
|
64
65
|
* So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
|
|
65
66
|
* @param guidelines
|
|
66
67
|
* @param containerWidth editorWidth
|
|
68
|
+
* @param lineLength
|
|
69
|
+
* @param isTableScalingEnabled
|
|
70
|
+
* @param isFullWidthModeEnabled
|
|
67
71
|
*/
|
|
68
|
-
const getVisibleGuidelines = (guidelines, containerWidth) => {
|
|
72
|
+
const getVisibleGuidelines = (guidelines, containerWidth, lineLength, isTableScalingEnabled, isFullWidthModeEnabled) => {
|
|
73
|
+
let guidelineVisibleAdjustment = TABLE_GUIDELINE_VISIBLE_ADJUSTMENT;
|
|
74
|
+
if (isTableScalingEnabled) {
|
|
75
|
+
// Notes:
|
|
76
|
+
// Example: containerWidth = 1244, lineLength = 1180 (used for when editor full width mode is enabled)
|
|
77
|
+
// Full width/dynamic x coordinate can be float number.
|
|
78
|
+
// Ex: guideline.position.x can be 590.5. So 590.5 * 2 = 1181 (not 1180).
|
|
79
|
+
// For PTW we need to ensure that dynamic guideline never gets excluded: 1181 should be > width + guidelineVisibleAdjustment
|
|
80
|
+
// guidelineVisibleAdjustment is set as a negative value, so we making it positive and adding + 1
|
|
81
|
+
const preserve_table_widths_adjustment = -1 * PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET + 1;
|
|
82
|
+
guidelineVisibleAdjustment = isFullWidthModeEnabled ? preserve_table_widths_adjustment // guidelineVisibleAdjustment = -2, if lineLength = 1180, 1181 < 1180 + 2 is true.
|
|
83
|
+
: -2 * akEditorGutterPadding + preserve_table_widths_adjustment; // guidelineVisibleAdjustment = -62, if containerWidth is 1244, 1181 < 1244 - 62 = 1182 is true.
|
|
84
|
+
}
|
|
85
|
+
const width = isTableScalingEnabled && isFullWidthModeEnabled ? lineLength : containerWidth;
|
|
69
86
|
return guidelines.filter(guideline => {
|
|
70
|
-
return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) <
|
|
87
|
+
return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) < width + guidelineVisibleAdjustment;
|
|
71
88
|
});
|
|
72
89
|
};
|
|
73
90
|
export const TableResizer = ({
|
|
@@ -89,7 +106,8 @@ export const TableResizer = ({
|
|
|
89
106
|
isTableScalingEnabled,
|
|
90
107
|
isTableAlignmentEnabled,
|
|
91
108
|
isWholeTableInDanger,
|
|
92
|
-
pluginInjectionApi
|
|
109
|
+
pluginInjectionApi,
|
|
110
|
+
isFullWidthModeEnabled
|
|
93
111
|
}) => {
|
|
94
112
|
var _findTable, _editorView$state;
|
|
95
113
|
const currentGap = useRef(0);
|
|
@@ -128,13 +146,15 @@ export const TableResizer = ({
|
|
|
128
146
|
}) => {
|
|
129
147
|
if (gap !== currentGap.current) {
|
|
130
148
|
currentGap.current = gap;
|
|
131
|
-
const visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth);
|
|
149
|
+
const visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth, lineLength, Boolean(isTableScalingEnabled), Boolean(isFullWidthModeEnabled));
|
|
132
150
|
displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
|
|
133
151
|
}
|
|
134
|
-
}, [isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline]);
|
|
152
|
+
}, [isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline, lineLength, isFullWidthModeEnabled]);
|
|
135
153
|
const guidelineSnaps = useMemo(() => snappingEnabled ? {
|
|
136
|
-
x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(
|
|
137
|
-
|
|
154
|
+
x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET,
|
|
155
|
+
// was hardcoded to 0, using PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
|
|
156
|
+
isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : defaultSnappingWidths
|
|
157
|
+
} : undefined, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, isFullWidthModeEnabled]);
|
|
138
158
|
const switchToCenterAlignment = useCallback((pos, node, newWidth, state, dispatch) => {
|
|
139
159
|
if (isTableAlignmentEnabled && node && node.attrs.layout === ALIGN_START && newWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH &&
|
|
140
160
|
// We don't want to switch alignment in Full-width editor
|
|
@@ -192,12 +212,12 @@ export const TableResizer = ({
|
|
|
192
212
|
name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
|
|
193
213
|
});
|
|
194
214
|
dispatch(tr);
|
|
195
|
-
const visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth);
|
|
215
|
+
const visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth, lineLength, Boolean(isTableScalingEnabled), Boolean(isFullWidthModeEnabled));
|
|
196
216
|
setSnappingEnabled(displayGuideline(visibleGuidelines));
|
|
197
217
|
if (onResizeStart) {
|
|
198
218
|
onResizeStart();
|
|
199
219
|
}
|
|
200
|
-
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline, onResizeStart]);
|
|
220
|
+
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, displayGuideline, onResizeStart, isFullWidthModeEnabled]);
|
|
201
221
|
const handleResize = useCallback((originalState, delta) => {
|
|
202
222
|
var _node$attrs$localId, _node$attrs;
|
|
203
223
|
countFrames();
|
|
@@ -217,7 +237,8 @@ export const TableResizer = ({
|
|
|
217
237
|
start: pos + 1,
|
|
218
238
|
parentWidth: newWidth
|
|
219
239
|
}, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
|
|
220
|
-
const
|
|
240
|
+
const editorContainerWidth = isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth;
|
|
241
|
+
const closestSnap = findClosestSnap(newWidth, isTableScalingEnabled ? defaultTablePreserveSnappingWidths(PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultSnappingWidths, isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig) : defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE);
|
|
221
242
|
updateActiveGuidelines(closestSnap);
|
|
222
243
|
|
|
223
244
|
// When snapping to the full width guideline, resize the table to be 1800px
|
|
@@ -226,7 +247,7 @@ export const TableResizer = ({
|
|
|
226
247
|
dispatch
|
|
227
248
|
} = editorView;
|
|
228
249
|
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 : '';
|
|
229
|
-
const fullWidthGuideline = defaultGuidelinesForPreserveTable(
|
|
250
|
+
const fullWidthGuideline = defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig).filter(guideline => guideline.isFullWidth)[0];
|
|
230
251
|
const isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
231
252
|
const shouldUpdateWidthToWidest = !!isTableScalingEnabled && isFullWidthGuidelineActive;
|
|
232
253
|
chainCommands((state, dispatch) => {
|
|
@@ -236,7 +257,7 @@ export const TableResizer = ({
|
|
|
236
257
|
}))(state, dispatch);
|
|
237
258
|
updateWidth(shouldUpdateWidthToWidest ? TABLE_MAX_WIDTH : newWidth);
|
|
238
259
|
return newWidth;
|
|
239
|
-
}, [countFrames, isTableScalingEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos, switchToCenterAlignment]);
|
|
260
|
+
}, [countFrames, isTableScalingEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
240
261
|
const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
|
|
241
262
|
const handleResizeStop = useCallback((originalState, delta) => {
|
|
242
263
|
var _node$attrs$localId2, _node$attrs2;
|
|
@@ -4,10 +4,13 @@ import { calculateDefaultSnappings, calculateDefaultTablePreserveSnappings } fro
|
|
|
4
4
|
// NOTE: We have to take 1 pixel off every length due to the fact that the tbody is 1px smaller then the table container.
|
|
5
5
|
// If we don't do this then the guidelines will not align correctly to the edge of the table
|
|
6
6
|
export const defaultGuidelines = createFixedGuidelinesFromLengths([0, ...calculateDefaultSnappings(-1)]);
|
|
7
|
-
export const
|
|
7
|
+
export const PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET = -1;
|
|
8
|
+
export const defaultGuidelinesForPreserveTable = (lengthOffset, editorContainerWidth, exclude = {
|
|
8
9
|
innerGuidelines: false,
|
|
9
10
|
breakoutPoints: false
|
|
10
11
|
}) => {
|
|
11
|
-
const lengths = calculateDefaultTablePreserveSnappings(
|
|
12
|
+
const lengths = calculateDefaultTablePreserveSnappings(lengthOffset,
|
|
13
|
+
// was hardcoded to -1 here, created PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET instead.
|
|
14
|
+
editorContainerWidth, exclude);
|
|
12
15
|
return createFixedGuidelinesFromLengths(lengths, undefined, true);
|
|
13
16
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
|
|
2
2
|
import { akEditorCalculatedWideLayoutWidth, akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
3
|
-
import { tableResizerWidth } from '../ui/consts';
|
|
4
3
|
const numberOfLanesInDefaultLayoutWidth = 12;
|
|
5
4
|
const calculateSubSnappingWidths = (totalLanes, totalWidth) => new Array(Math.round(totalLanes / 2) - 1).fill(totalWidth / totalLanes).map((v, i) => v * (i + 1) * 2);
|
|
6
5
|
export const calculateDefaultSnappings = (lengthOffset = 0) => [...calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, akEditorDefaultLayoutWidth + lengthOffset), akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, akEditorFullWidthLayoutWidth + lengthOffset];
|
|
@@ -9,7 +8,7 @@ export const calculateDefaultTablePreserveSnappings = (lengthOffset = 0, editorC
|
|
|
9
8
|
innerGuidelines: false,
|
|
10
9
|
breakoutPoints: false
|
|
11
10
|
}) => {
|
|
12
|
-
const dynamicFullWidthLine = editorContainerWith - akEditorGutterPadding * 2 >= akEditorFullWidthLayoutWidth ? akEditorFullWidthLayoutWidth : editorContainerWith - akEditorGutterPadding * 2
|
|
11
|
+
const dynamicFullWidthLine = editorContainerWith - akEditorGutterPadding * 2 >= akEditorFullWidthLayoutWidth ? akEditorFullWidthLayoutWidth : editorContainerWith - akEditorGutterPadding * 2;
|
|
13
12
|
const guides = [dynamicFullWidthLine - lengthOffset];
|
|
14
13
|
if (!exclude.breakoutPoints) {
|
|
15
14
|
guides.unshift(akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset);
|
|
@@ -20,17 +19,17 @@ export const calculateDefaultTablePreserveSnappings = (lengthOffset = 0, editorC
|
|
|
20
19
|
return guides;
|
|
21
20
|
};
|
|
22
21
|
export const defaultSnappingWidths = calculateDefaultSnappings();
|
|
23
|
-
|
|
22
|
+
export const PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = 0;
|
|
24
23
|
// FF TablePreserve for defaultSnappingWidths
|
|
25
|
-
export const defaultTablePreserveSnappingWidths = (editorContainerWidth, exclude = {
|
|
24
|
+
export const defaultTablePreserveSnappingWidths = (lengthOffset, editorContainerWidth, exclude = {
|
|
26
25
|
innerGuidelines: false,
|
|
27
26
|
breakoutPoints: false
|
|
28
27
|
}) => {
|
|
29
|
-
return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(
|
|
28
|
+
return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(lengthOffset, editorContainerWidth, exclude); // lengthOffset was hardcoded 0 here, created PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
|
-
* Returns keys of guidelines that are closest to the table and
|
|
32
|
+
* Returns keys of guidelines that are closest to the table and within the snapGap
|
|
34
33
|
*/
|
|
35
34
|
export const findClosestSnap = (currentWidth, snapWidths, guidelines, snapGap = 0, tolerance = 0) => {
|
|
36
35
|
const closestGapIndex = snapWidths.reduce((prev, curr, index) => Math.abs(curr - currentWidth) < Math.abs(snapWidths[prev] - currentWidth) ? index : prev, 0);
|