@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
|
@@ -3,7 +3,7 @@ import React, { forwardRef, useCallback, useEffect, useMemo, useRef, useState }
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
5
5
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
6
|
-
import { akEditorDefaultLayoutWidth, akEditorGutterPadding,
|
|
6
|
+
import { akEditorDefaultLayoutWidth, akEditorGutterPadding, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
|
|
7
7
|
import { setTableAlignmentWithTableContentWithPos } from '../commands/misc';
|
|
8
8
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
9
9
|
import { TableCssClassName as ClassName } from '../types';
|
|
@@ -121,6 +121,10 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
|
|
|
121
121
|
_useState2 = _slicedToArray(_useState, 2),
|
|
122
122
|
resizing = _useState2[0],
|
|
123
123
|
setIsResizing = _useState2[1];
|
|
124
|
+
var _useSharedPluginState2 = useSharedPluginState(pluginInjectionApi, ['table']),
|
|
125
|
+
tableState = _useSharedPluginState2.tableState;
|
|
126
|
+
var _ref5 = tableState,
|
|
127
|
+
isFullWidthModeEnabled = _ref5.isFullWidthModeEnabled;
|
|
124
128
|
var updateContainerHeight = useCallback(function (height) {
|
|
125
129
|
var _containerRef$current;
|
|
126
130
|
// current StickyHeader State is not stable to be fetch.
|
|
@@ -174,11 +178,27 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
|
|
|
174
178
|
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;
|
|
175
179
|
}, [pluginInjectionApi]);
|
|
176
180
|
var tableWidth = getTableContainerWidth(node);
|
|
177
|
-
var
|
|
178
|
-
editorViewModeState =
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
var _useSharedPluginState3 = useSharedPluginState(pluginInjectionApi, ['editorViewMode']),
|
|
182
|
+
editorViewModeState = _useSharedPluginState3.editorViewModeState;
|
|
183
|
+
var responsiveContainerWidth = 0;
|
|
184
|
+
var resizeHandleSpacing = 12;
|
|
185
|
+
// When Full width editor enabled, a Mac OS user can change "ak-editor-content-area" width by
|
|
186
|
+
// updating Settings -> Appearance -> Show scroll bars from "When scrolling" to "Always". It causes
|
|
187
|
+
// issues when viwport width is less than full width Editor's width. To detect avoid them
|
|
188
|
+
// we need to use lineLength to defined responsiveWidth instead of containerWidth
|
|
189
|
+
// (which does not get updated when Mac setting changes) in Full-width editor.
|
|
190
|
+
if (isFullWidthModeEnabled) {
|
|
191
|
+
// When: Show scroll bars -> containerWidth = akEditorGutterPadding * 2 + lineLength;
|
|
192
|
+
// When: Always -> containerWidth = akEditorGutterPadding * 2 + lineLength + scrollbarWidth;
|
|
193
|
+
// scrollbarWidth can vary. Values can be 14, 15, 16 and up to 20px;
|
|
194
|
+
responsiveContainerWidth = isTableScalingEnabled ? lineLength : containerWidth - akEditorGutterPadding * 2 - resizeHandleSpacing;
|
|
195
|
+
} else {
|
|
196
|
+
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
197
|
+
// containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
|
|
198
|
+
// a DIV with className="ak-editor-content-area". This DIV has padding left and padding right.
|
|
199
|
+
// padding left = padding right = akEditorGutterPadding = 32
|
|
200
|
+
responsiveContainerWidth = isTableScalingEnabled ? containerWidth - akEditorGutterPadding * 2 : containerWidth - akEditorGutterPadding * 2 - resizeHandleSpacing;
|
|
201
|
+
}
|
|
182
202
|
var width = Math.min(tableWidth, responsiveContainerWidth);
|
|
183
203
|
if (!isResizing) {
|
|
184
204
|
tableWidthRef.current = width;
|
|
@@ -198,6 +218,7 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
|
|
|
198
218
|
attachAnalyticsEvent: attachAnalyticsEvent,
|
|
199
219
|
displayGapCursor: displayGapCursor,
|
|
200
220
|
isTableAlignmentEnabled: isTableAlignmentEnabled,
|
|
221
|
+
isFullWidthModeEnabled: isFullWidthModeEnabled,
|
|
201
222
|
isTableScalingEnabled: isTableScalingEnabled,
|
|
202
223
|
isWholeTableInDanger: isWholeTableInDanger,
|
|
203
224
|
pluginInjectionApi: pluginInjectionApi,
|
|
@@ -236,24 +257,24 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
|
|
|
236
257
|
node: node
|
|
237
258
|
}, children))));
|
|
238
259
|
});
|
|
239
|
-
export var TableContainer = function TableContainer(
|
|
240
|
-
var children =
|
|
241
|
-
node =
|
|
242
|
-
className =
|
|
243
|
-
|
|
244
|
-
editorWidth =
|
|
245
|
-
lineLength =
|
|
246
|
-
editorView =
|
|
247
|
-
getPos =
|
|
248
|
-
tableRef =
|
|
249
|
-
isNested =
|
|
250
|
-
tableWrapperHeight =
|
|
251
|
-
isResizing =
|
|
252
|
-
pluginInjectionApi =
|
|
253
|
-
isWholeTableInDanger =
|
|
254
|
-
isTableResizingEnabled =
|
|
255
|
-
isTableScalingEnabled =
|
|
256
|
-
isTableAlignmentEnabled =
|
|
260
|
+
export var TableContainer = function TableContainer(_ref6) {
|
|
261
|
+
var children = _ref6.children,
|
|
262
|
+
node = _ref6.node,
|
|
263
|
+
className = _ref6.className,
|
|
264
|
+
_ref6$containerWidth = _ref6.containerWidth,
|
|
265
|
+
editorWidth = _ref6$containerWidth.width,
|
|
266
|
+
lineLength = _ref6$containerWidth.lineLength,
|
|
267
|
+
editorView = _ref6.editorView,
|
|
268
|
+
getPos = _ref6.getPos,
|
|
269
|
+
tableRef = _ref6.tableRef,
|
|
270
|
+
isNested = _ref6.isNested,
|
|
271
|
+
tableWrapperHeight = _ref6.tableWrapperHeight,
|
|
272
|
+
isResizing = _ref6.isResizing,
|
|
273
|
+
pluginInjectionApi = _ref6.pluginInjectionApi,
|
|
274
|
+
isWholeTableInDanger = _ref6.isWholeTableInDanger,
|
|
275
|
+
isTableResizingEnabled = _ref6.isTableResizingEnabled,
|
|
276
|
+
isTableScalingEnabled = _ref6.isTableScalingEnabled,
|
|
277
|
+
isTableAlignmentEnabled = _ref6.isTableAlignmentEnabled;
|
|
257
278
|
if (isTableResizingEnabled && !isNested) {
|
|
258
279
|
return /*#__PURE__*/React.createElement(ResizableTableContainer
|
|
259
280
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
@@ -13,6 +13,7 @@ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
|
13
13
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
14
14
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
15
15
|
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
16
|
+
import { akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
16
17
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
17
18
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
18
19
|
import { setTableAlignmentWithTableContentWithPos, updateWidthToWidest } from '../commands/misc';
|
|
@@ -22,8 +23,8 @@ import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
|
22
23
|
import { TABLE_GUIDELINE_VISIBLE_ADJUSTMENT, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
|
|
23
24
|
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment } from '../utils/alignment';
|
|
24
25
|
import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
|
|
25
|
-
import { defaultGuidelines, defaultGuidelinesForPreserveTable } from '../utils/guidelines';
|
|
26
|
-
import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap } from '../utils/snapping';
|
|
26
|
+
import { defaultGuidelines, defaultGuidelinesForPreserveTable, PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET } from '../utils/guidelines';
|
|
27
|
+
import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap, PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET } from '../utils/snapping';
|
|
27
28
|
var RESIZE_STEP_VALUE = 10;
|
|
28
29
|
var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
29
30
|
var handles = {
|
|
@@ -68,10 +69,26 @@ var getResizerMinWidth = function getResizerMinWidth(node) {
|
|
|
68
69
|
* So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
|
|
69
70
|
* @param guidelines
|
|
70
71
|
* @param containerWidth editorWidth
|
|
72
|
+
* @param lineLength
|
|
73
|
+
* @param isTableScalingEnabled
|
|
74
|
+
* @param isFullWidthModeEnabled
|
|
71
75
|
*/
|
|
72
|
-
var getVisibleGuidelines = function getVisibleGuidelines(guidelines, containerWidth) {
|
|
76
|
+
var getVisibleGuidelines = function getVisibleGuidelines(guidelines, containerWidth, lineLength, isTableScalingEnabled, isFullWidthModeEnabled) {
|
|
77
|
+
var guidelineVisibleAdjustment = TABLE_GUIDELINE_VISIBLE_ADJUSTMENT;
|
|
78
|
+
if (isTableScalingEnabled) {
|
|
79
|
+
// Notes:
|
|
80
|
+
// Example: containerWidth = 1244, lineLength = 1180 (used for when editor full width mode is enabled)
|
|
81
|
+
// Full width/dynamic x coordinate can be float number.
|
|
82
|
+
// Ex: guideline.position.x can be 590.5. So 590.5 * 2 = 1181 (not 1180).
|
|
83
|
+
// For PTW we need to ensure that dynamic guideline never gets excluded: 1181 should be > width + guidelineVisibleAdjustment
|
|
84
|
+
// guidelineVisibleAdjustment is set as a negative value, so we making it positive and adding + 1
|
|
85
|
+
var preserve_table_widths_adjustment = -1 * PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET + 1;
|
|
86
|
+
guidelineVisibleAdjustment = isFullWidthModeEnabled ? preserve_table_widths_adjustment // guidelineVisibleAdjustment = -2, if lineLength = 1180, 1181 < 1180 + 2 is true.
|
|
87
|
+
: -2 * akEditorGutterPadding + preserve_table_widths_adjustment; // guidelineVisibleAdjustment = -62, if containerWidth is 1244, 1181 < 1244 - 62 = 1182 is true.
|
|
88
|
+
}
|
|
89
|
+
var width = isTableScalingEnabled && isFullWidthModeEnabled ? lineLength : containerWidth;
|
|
73
90
|
return guidelines.filter(function (guideline) {
|
|
74
|
-
return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) <
|
|
91
|
+
return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) < width + guidelineVisibleAdjustment;
|
|
75
92
|
});
|
|
76
93
|
};
|
|
77
94
|
export var TableResizer = function TableResizer(_ref) {
|
|
@@ -94,7 +111,8 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
94
111
|
isTableScalingEnabled = _ref.isTableScalingEnabled,
|
|
95
112
|
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled,
|
|
96
113
|
isWholeTableInDanger = _ref.isWholeTableInDanger,
|
|
97
|
-
pluginInjectionApi = _ref.pluginInjectionApi
|
|
114
|
+
pluginInjectionApi = _ref.pluginInjectionApi,
|
|
115
|
+
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled;
|
|
98
116
|
var currentGap = useRef(0);
|
|
99
117
|
// track resizing state - use ref over state to avoid re-render
|
|
100
118
|
var isResizing = useRef(false);
|
|
@@ -131,15 +149,17 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
131
149
|
keys = _ref3.keys;
|
|
132
150
|
if (gap !== currentGap.current) {
|
|
133
151
|
currentGap.current = gap;
|
|
134
|
-
var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth);
|
|
152
|
+
var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth, lineLength, Boolean(isTableScalingEnabled), Boolean(isFullWidthModeEnabled));
|
|
135
153
|
displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
|
|
136
154
|
}
|
|
137
|
-
}, [isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline]);
|
|
155
|
+
}, [isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline, lineLength, isFullWidthModeEnabled]);
|
|
138
156
|
var guidelineSnaps = useMemo(function () {
|
|
139
157
|
return snappingEnabled ? {
|
|
140
|
-
x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(
|
|
158
|
+
x: isTableScalingEnabled ? defaultTablePreserveSnappingWidths(PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET,
|
|
159
|
+
// was hardcoded to 0, using PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
|
|
160
|
+
isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : defaultSnappingWidths
|
|
141
161
|
} : undefined;
|
|
142
|
-
}, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth]);
|
|
162
|
+
}, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, isFullWidthModeEnabled]);
|
|
143
163
|
var switchToCenterAlignment = useCallback(function (pos, node, newWidth, state, dispatch) {
|
|
144
164
|
if (isTableAlignmentEnabled && node && node.attrs.layout === ALIGN_START && newWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH &&
|
|
145
165
|
// We don't want to switch alignment in Full-width editor
|
|
@@ -189,12 +209,12 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
189
209
|
name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
|
|
190
210
|
});
|
|
191
211
|
dispatch(tr);
|
|
192
|
-
var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth);
|
|
212
|
+
var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth, lineLength, Boolean(isTableScalingEnabled), Boolean(isFullWidthModeEnabled));
|
|
193
213
|
setSnappingEnabled(displayGuideline(visibleGuidelines));
|
|
194
214
|
if (onResizeStart) {
|
|
195
215
|
onResizeStart();
|
|
196
216
|
}
|
|
197
|
-
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, displayGuideline, onResizeStart]);
|
|
217
|
+
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, displayGuideline, onResizeStart, isFullWidthModeEnabled]);
|
|
198
218
|
var handleResize = useCallback(function (originalState, delta) {
|
|
199
219
|
var _node$attrs$localId, _node$attrs;
|
|
200
220
|
countFrames();
|
|
@@ -214,14 +234,15 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
214
234
|
start: pos + 1,
|
|
215
235
|
parentWidth: newWidth
|
|
216
236
|
}, editorView.domAtPos.bind(editorView), isTableScalingEnabled);
|
|
217
|
-
var
|
|
237
|
+
var editorContainerWidth = isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth;
|
|
238
|
+
var 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);
|
|
218
239
|
updateActiveGuidelines(closestSnap);
|
|
219
240
|
|
|
220
241
|
// When snapping to the full width guideline, resize the table to be 1800px
|
|
221
242
|
var state = editorView.state,
|
|
222
243
|
dispatch = editorView.dispatch;
|
|
223
244
|
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 : '';
|
|
224
|
-
var fullWidthGuideline = defaultGuidelinesForPreserveTable(
|
|
245
|
+
var fullWidthGuideline = defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, editorContainerWidth, excludeGuidelineConfig).filter(function (guideline) {
|
|
225
246
|
return guideline.isFullWidth;
|
|
226
247
|
})[0];
|
|
227
248
|
var isFullWidthGuidelineActive = closestSnap.keys.includes(fullWidthGuideline.key);
|
|
@@ -231,7 +252,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
231
252
|
}, updateWidthToWidest(_defineProperty({}, currentTableNodeLocalId, shouldUpdateWidthToWidest)))(state, dispatch);
|
|
232
253
|
updateWidth(shouldUpdateWidthToWidest ? TABLE_MAX_WIDTH : newWidth);
|
|
233
254
|
return newWidth;
|
|
234
|
-
}, [countFrames, isTableScalingEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, updateWidth, getPos, switchToCenterAlignment]);
|
|
255
|
+
}, [countFrames, isTableScalingEnabled, isFullWidthModeEnabled, excludeGuidelineConfig, tableRef, node, editorView, updateActiveGuidelines, containerWidth, lineLength, updateWidth, getPos, switchToCenterAlignment]);
|
|
235
256
|
var scheduleResize = useMemo(function () {
|
|
236
257
|
return rafSchd(handleResize);
|
|
237
258
|
}, [handleResize]);
|
|
@@ -5,11 +5,14 @@ import { calculateDefaultSnappings, calculateDefaultTablePreserveSnappings } fro
|
|
|
5
5
|
// NOTE: We have to take 1 pixel off every length due to the fact that the tbody is 1px smaller then the table container.
|
|
6
6
|
// If we don't do this then the guidelines will not align correctly to the edge of the table
|
|
7
7
|
export var defaultGuidelines = createFixedGuidelinesFromLengths([0].concat(_toConsumableArray(calculateDefaultSnappings(-1))));
|
|
8
|
-
export var
|
|
9
|
-
|
|
8
|
+
export var PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET = -1;
|
|
9
|
+
export var defaultGuidelinesForPreserveTable = function defaultGuidelinesForPreserveTable(lengthOffset, editorContainerWidth) {
|
|
10
|
+
var exclude = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
10
11
|
innerGuidelines: false,
|
|
11
12
|
breakoutPoints: false
|
|
12
13
|
};
|
|
13
|
-
var lengths = calculateDefaultTablePreserveSnappings(
|
|
14
|
+
var lengths = calculateDefaultTablePreserveSnappings(lengthOffset,
|
|
15
|
+
// was hardcoded to -1 here, created PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET instead.
|
|
16
|
+
editorContainerWidth, exclude);
|
|
14
17
|
return createFixedGuidelinesFromLengths(lengths, undefined, true);
|
|
15
18
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
|
|
3
3
|
import { akEditorCalculatedWideLayoutWidth, akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
4
|
-
import { tableResizerWidth } from '../ui/consts';
|
|
5
4
|
var numberOfLanesInDefaultLayoutWidth = 12;
|
|
6
5
|
var calculateSubSnappingWidths = function calculateSubSnappingWidths(totalLanes, totalWidth) {
|
|
7
6
|
return new Array(Math.round(totalLanes / 2) - 1).fill(totalWidth / totalLanes).map(function (v, i) {
|
|
@@ -20,7 +19,7 @@ export var calculateDefaultTablePreserveSnappings = function calculateDefaultTab
|
|
|
20
19
|
innerGuidelines: false,
|
|
21
20
|
breakoutPoints: false
|
|
22
21
|
};
|
|
23
|
-
var dynamicFullWidthLine = editorContainerWith - akEditorGutterPadding * 2 >= akEditorFullWidthLayoutWidth ? akEditorFullWidthLayoutWidth : editorContainerWith - akEditorGutterPadding * 2
|
|
22
|
+
var dynamicFullWidthLine = editorContainerWith - akEditorGutterPadding * 2 >= akEditorFullWidthLayoutWidth ? akEditorFullWidthLayoutWidth : editorContainerWith - akEditorGutterPadding * 2;
|
|
24
23
|
var guides = [dynamicFullWidthLine - lengthOffset];
|
|
25
24
|
if (!exclude.breakoutPoints) {
|
|
26
25
|
guides.unshift(akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset);
|
|
@@ -31,18 +30,18 @@ export var calculateDefaultTablePreserveSnappings = function calculateDefaultTab
|
|
|
31
30
|
return guides;
|
|
32
31
|
};
|
|
33
32
|
export var defaultSnappingWidths = calculateDefaultSnappings();
|
|
34
|
-
|
|
33
|
+
export var PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = 0;
|
|
35
34
|
// FF TablePreserve for defaultSnappingWidths
|
|
36
|
-
export var defaultTablePreserveSnappingWidths = function defaultTablePreserveSnappingWidths(editorContainerWidth) {
|
|
37
|
-
var exclude = arguments.length >
|
|
35
|
+
export var defaultTablePreserveSnappingWidths = function defaultTablePreserveSnappingWidths(lengthOffset, editorContainerWidth) {
|
|
36
|
+
var exclude = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
38
37
|
innerGuidelines: false,
|
|
39
38
|
breakoutPoints: false
|
|
40
39
|
};
|
|
41
|
-
return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(
|
|
40
|
+
return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth ? calculateDefaultSnappings() : calculateDefaultTablePreserveSnappings(lengthOffset, editorContainerWidth, exclude); // lengthOffset was hardcoded 0 here, created PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
|
-
* Returns keys of guidelines that are closest to the table and
|
|
44
|
+
* Returns keys of guidelines that are closest to the table and within the snapGap
|
|
46
45
|
*/
|
|
47
46
|
export var findClosestSnap = function findClosestSnap(currentWidth, snapWidths, guidelines) {
|
|
48
47
|
var snapGap = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
@@ -22,10 +22,11 @@ interface TableResizerProps {
|
|
|
22
22
|
isTableScalingEnabled?: boolean;
|
|
23
23
|
isTableAlignmentEnabled?: boolean;
|
|
24
24
|
isWholeTableInDanger?: boolean;
|
|
25
|
+
isFullWidthModeEnabled?: boolean;
|
|
25
26
|
}
|
|
26
27
|
export interface TableResizerImprovementProps extends TableResizerProps {
|
|
27
28
|
onResizeStop?: () => void;
|
|
28
29
|
onResizeStart?: () => void;
|
|
29
30
|
}
|
|
30
|
-
export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableAlignmentEnabled, isWholeTableInDanger, pluginInjectionApi, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
|
|
31
|
+
export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableAlignmentEnabled, isWholeTableInDanger, pluginInjectionApi, isFullWidthModeEnabled, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
|
|
31
32
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
|
|
2
2
|
import type { GuidelineExcludeConfig } from './snapping';
|
|
3
3
|
export declare const defaultGuidelines: GuidelineConfig[];
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET = -1;
|
|
5
|
+
export declare const defaultGuidelinesForPreserveTable: (lengthOffset: number, editorContainerWidth: number, exclude?: GuidelineExcludeConfig) => GuidelineConfig[];
|
|
@@ -6,9 +6,10 @@ export type GuidelineExcludeConfig = {
|
|
|
6
6
|
};
|
|
7
7
|
export declare const calculateDefaultTablePreserveSnappings: (lengthOffset?: number, editorContainerWith?: number, exclude?: GuidelineExcludeConfig) => number[];
|
|
8
8
|
export declare const defaultSnappingWidths: number[];
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = 0;
|
|
10
|
+
export declare const defaultTablePreserveSnappingWidths: (lengthOffset: number, editorContainerWidth: number, exclude?: GuidelineExcludeConfig) => number[];
|
|
10
11
|
/**
|
|
11
|
-
* Returns keys of guidelines that are closest to the table and
|
|
12
|
+
* Returns keys of guidelines that are closest to the table and within the snapGap
|
|
12
13
|
*/
|
|
13
14
|
export declare const findClosestSnap: (currentWidth: number, snapWidths: number[], guidelines: GuidelineConfig[], snapGap?: number, tolerance?: number) => {
|
|
14
15
|
gap: number;
|
|
@@ -22,10 +22,11 @@ interface TableResizerProps {
|
|
|
22
22
|
isTableScalingEnabled?: boolean;
|
|
23
23
|
isTableAlignmentEnabled?: boolean;
|
|
24
24
|
isWholeTableInDanger?: boolean;
|
|
25
|
+
isFullWidthModeEnabled?: boolean;
|
|
25
26
|
}
|
|
26
27
|
export interface TableResizerImprovementProps extends TableResizerProps {
|
|
27
28
|
onResizeStop?: () => void;
|
|
28
29
|
onResizeStart?: () => void;
|
|
29
30
|
}
|
|
30
|
-
export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableAlignmentEnabled, isWholeTableInDanger, pluginInjectionApi, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
|
|
31
|
+
export declare const TableResizer: ({ children, width, maxWidth, containerWidth, lineLength, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, displayGapCursor, isTableScalingEnabled, isTableAlignmentEnabled, isWholeTableInDanger, pluginInjectionApi, isFullWidthModeEnabled, }: PropsWithChildren<TableResizerImprovementProps>) => JSX.Element;
|
|
31
32
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
|
|
2
2
|
import type { GuidelineExcludeConfig } from './snapping';
|
|
3
3
|
export declare const defaultGuidelines: GuidelineConfig[];
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET = -1;
|
|
5
|
+
export declare const defaultGuidelinesForPreserveTable: (lengthOffset: number, editorContainerWidth: number, exclude?: GuidelineExcludeConfig) => GuidelineConfig[];
|
|
@@ -6,9 +6,10 @@ export type GuidelineExcludeConfig = {
|
|
|
6
6
|
};
|
|
7
7
|
export declare const calculateDefaultTablePreserveSnappings: (lengthOffset?: number, editorContainerWith?: number, exclude?: GuidelineExcludeConfig) => number[];
|
|
8
8
|
export declare const defaultSnappingWidths: number[];
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = 0;
|
|
10
|
+
export declare const defaultTablePreserveSnappingWidths: (lengthOffset: number, editorContainerWidth: number, exclude?: GuidelineExcludeConfig) => number[];
|
|
10
11
|
/**
|
|
11
|
-
* Returns keys of guidelines that are closest to the table and
|
|
12
|
+
* Returns keys of guidelines that are closest to the table and within the snapGap
|
|
12
13
|
*/
|
|
13
14
|
export declare const findClosestSnap: (currentWidth: number, snapWidths: number[], guidelines: GuidelineConfig[], snapGap?: number, tolerance?: number) => {
|
|
14
15
|
gap: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.16.
|
|
3
|
+
"version": "7.16.13",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@atlaskit/adf-schema": "^36.10.7",
|
|
32
32
|
"@atlaskit/button": "^17.17.0",
|
|
33
33
|
"@atlaskit/custom-steps": "^0.2.0",
|
|
34
|
-
"@atlaskit/editor-common": "^81.
|
|
34
|
+
"@atlaskit/editor-common": "^81.2.0",
|
|
35
35
|
"@atlaskit/editor-palette": "1.6.0",
|
|
36
36
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.2.0",
|
|
@@ -13,13 +13,12 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
|
13
13
|
import {
|
|
14
14
|
akEditorDefaultLayoutWidth,
|
|
15
15
|
akEditorGutterPadding,
|
|
16
|
-
akEditorMediaResizeHandlerPaddingWide,
|
|
17
16
|
akEditorMobileBreakoutPoint,
|
|
18
17
|
} from '@atlaskit/editor-shared-styles';
|
|
19
18
|
|
|
20
19
|
import { setTableAlignmentWithTableContentWithPos } from '../commands/misc';
|
|
21
20
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
22
|
-
import type { PluginInjectionAPI } from '../types';
|
|
21
|
+
import type { PluginInjectionAPI, TableSharedState } from '../types';
|
|
23
22
|
import { TableCssClassName as ClassName } from '../types';
|
|
24
23
|
|
|
25
24
|
import { TableResizer } from './TableResizer';
|
|
@@ -185,6 +184,8 @@ export const ResizableTableContainer = React.memo(
|
|
|
185
184
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
186
185
|
const tableWidthRef = useRef<number>(akEditorDefaultLayoutWidth);
|
|
187
186
|
const [resizing, setIsResizing] = useState(false);
|
|
187
|
+
const { tableState } = useSharedPluginState(pluginInjectionApi, ['table']);
|
|
188
|
+
const { isFullWidthModeEnabled } = tableState as TableSharedState;
|
|
188
189
|
|
|
189
190
|
const updateContainerHeight = useCallback((height: number | 'auto') => {
|
|
190
191
|
// current StickyHeader State is not stable to be fetch.
|
|
@@ -260,11 +261,29 @@ export const ResizableTableContainer = React.memo(
|
|
|
260
261
|
const tableWidth = getTableContainerWidth(node);
|
|
261
262
|
const { editorViewModeState } = useSharedPluginState(pluginInjectionApi, ['editorViewMode']);
|
|
262
263
|
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
264
|
+
let responsiveContainerWidth = 0;
|
|
265
|
+
const resizeHandleSpacing = 12;
|
|
266
|
+
// When Full width editor enabled, a Mac OS user can change "ak-editor-content-area" width by
|
|
267
|
+
// updating Settings -> Appearance -> Show scroll bars from "When scrolling" to "Always". It causes
|
|
268
|
+
// issues when viwport width is less than full width Editor's width. To detect avoid them
|
|
269
|
+
// we need to use lineLength to defined responsiveWidth instead of containerWidth
|
|
270
|
+
// (which does not get updated when Mac setting changes) in Full-width editor.
|
|
271
|
+
if (isFullWidthModeEnabled) {
|
|
272
|
+
// When: Show scroll bars -> containerWidth = akEditorGutterPadding * 2 + lineLength;
|
|
273
|
+
// When: Always -> containerWidth = akEditorGutterPadding * 2 + lineLength + scrollbarWidth;
|
|
274
|
+
// scrollbarWidth can vary. Values can be 14, 15, 16 and up to 20px;
|
|
275
|
+
responsiveContainerWidth = isTableScalingEnabled
|
|
276
|
+
? lineLength
|
|
277
|
+
: containerWidth - akEditorGutterPadding * 2 - resizeHandleSpacing;
|
|
278
|
+
} else {
|
|
279
|
+
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
280
|
+
// containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
|
|
281
|
+
// a DIV with className="ak-editor-content-area". This DIV has padding left and padding right.
|
|
282
|
+
// padding left = padding right = akEditorGutterPadding = 32
|
|
283
|
+
responsiveContainerWidth = isTableScalingEnabled
|
|
284
|
+
? containerWidth - akEditorGutterPadding * 2
|
|
285
|
+
: containerWidth - akEditorGutterPadding * 2 - resizeHandleSpacing;
|
|
286
|
+
}
|
|
268
287
|
let width = Math.min(tableWidth, responsiveContainerWidth);
|
|
269
288
|
|
|
270
289
|
if (!isResizing) {
|
|
@@ -286,6 +305,7 @@ export const ResizableTableContainer = React.memo(
|
|
|
286
305
|
attachAnalyticsEvent,
|
|
287
306
|
displayGapCursor,
|
|
288
307
|
isTableAlignmentEnabled,
|
|
308
|
+
isFullWidthModeEnabled,
|
|
289
309
|
isTableScalingEnabled,
|
|
290
310
|
isWholeTableInDanger,
|
|
291
311
|
pluginInjectionApi,
|