@atlaskit/editor-plugin-table 2.8.3 → 2.8.5
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/plugins/table/nodeviews/TableResizer.js +4 -2
- package/dist/cjs/plugins/table/ui/consts.js +4 -2
- package/dist/cjs/plugins/table/utils/guidelines.js +5 -13
- package/dist/cjs/plugins/table/utils/snapping.js +21 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +7 -5
- package/dist/es2019/plugins/table/ui/consts.js +2 -1
- package/dist/es2019/plugins/table/utils/guidelines.js +5 -11
- package/dist/es2019/plugins/table/utils/snapping.js +8 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +7 -5
- package/dist/esm/plugins/table/ui/consts.js +2 -1
- package/dist/esm/plugins/table/utils/guidelines.js +5 -11
- package/dist/esm/plugins/table/utils/snapping.js +16 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types/plugins/table/utils/guidelines.d.ts +0 -1
- package/dist/types/plugins/table/utils/snapping.d.ts +3 -1
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/guidelines.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/utils/snapping.d.ts +3 -1
- package/package.json +3 -3
- package/src/plugins/table/nodeviews/TableResizer.tsx +12 -5
- package/src/plugins/table/ui/consts.ts +1 -0
- package/src/plugins/table/utils/guidelines.ts +7 -26
- package/src/plugins/table/utils/snapping.ts +34 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 2.8.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`58fa188ef48`](https://bitbucket.org/atlassian/atlassian-frontend/commits/58fa188ef48) - [ux] [ED-19461] Reduce draggable zone of adjacent resize handle.
|
|
8
|
+
|
|
9
|
+
## 2.8.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`e73d62af335`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e73d62af335) - [ux] Adjusted the guidelines to be 1 pixel smaller then the snapping widths due to the fact that the tbody is 1 pixel smaller then the table. The table snaps to the snap widths and the guidelines align to the tbody cell borders
|
|
14
|
+
|
|
3
15
|
## 2.8.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -28,6 +28,7 @@ var handles = {
|
|
|
28
28
|
right: true
|
|
29
29
|
};
|
|
30
30
|
var tableHandleMarginTop = 12;
|
|
31
|
+
var tableHandlePosition = 14;
|
|
31
32
|
var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
|
|
32
33
|
var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
|
|
33
34
|
var handleHeightSize = 'small';
|
|
@@ -84,7 +85,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
84
85
|
}, [displayGuideline]);
|
|
85
86
|
var guidelineSnaps = (0, _react.useMemo)(function () {
|
|
86
87
|
return snappingEnabled ? {
|
|
87
|
-
x:
|
|
88
|
+
x: _snapping.defaultSnappingWidths
|
|
88
89
|
} : undefined;
|
|
89
90
|
}, [snappingEnabled]);
|
|
90
91
|
var handleResizeStart = (0, _react.useCallback)(function () {
|
|
@@ -109,7 +110,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
109
110
|
start: pos + 1,
|
|
110
111
|
parentWidth: newWidth
|
|
111
112
|
}, editorView.domAtPos.bind(editorView));
|
|
112
|
-
updateActiveGuidelines((0, _snapping.findClosestSnap)(newWidth,
|
|
113
|
+
updateActiveGuidelines((0, _snapping.findClosestSnap)(newWidth, _snapping.defaultSnappingWidths, _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE));
|
|
113
114
|
updateWidth(newWidth);
|
|
114
115
|
return newWidth;
|
|
115
116
|
}, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
|
|
@@ -193,6 +194,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
193
194
|
snapGap: _consts.TABLE_SNAP_GAP,
|
|
194
195
|
snap: guidelineSnaps,
|
|
195
196
|
handlePositioning: "adjacent",
|
|
197
|
+
innerPadding: tableHandlePosition,
|
|
196
198
|
isHandleVisible: ((_findTable = (0, _utils.findTable)((_editorView$state = editorView.state) === null || _editorView$state === void 0 ? void 0 : _editorView$state.selection)) === null || _findTable === void 0 ? void 0 : _findTable.pos) === getPos(),
|
|
197
199
|
handleComponent: handleComponent
|
|
198
200
|
}, children);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.tableToolbarSize = exports.tableToolbarSelectedColor = exports.tableToolbarDeleteColor = exports.tableToolbarColor = exports.tableTextColor = exports.tableScrollbarOffset = exports.tablePadding = exports.tableMarginFullWidthMode = exports.tableInsertColumnButtonSize = exports.tableInsertColumnButtonOffset = exports.tableHeaderCellBackgroundColor = exports.tableFloatingControlsColor = exports.tableDeleteButtonSize = exports.tableDeleteButtonOffset = exports.tableControlsSpacing = exports.tableCellSelectedDeleteIconColor = exports.tableCellSelectedDeleteIconBackground = exports.tableCellSelectedColor = exports.tableCellHoverDeleteIconColor = exports.tableCellHoverDeleteIconBackground = exports.tableCellDeleteColor = exports.tableCellBackgroundColor = exports.tableBorderSelectedColor = exports.tableBorderRadiusSize = exports.tableBorderDeleteColor = exports.tableBorderColor = exports.stickyRowZIndex = exports.stickyRowOffsetTop = exports.stickyHeaderBorderBottomWidth = exports.resizeLineWidth = exports.resizeHandlerZIndex = exports.resizeHandlerAreaWidth = exports.lineMarkerSize = exports.lineMarkerOffsetFromColumnControls = exports.layoutButtonSize = exports.contextualMenuTriggerSize = exports.contextualMenuDropdownWidth = exports.columnResizeHandleZIndex = exports.columnControlsZIndex = exports.columnControlsSelectedZIndex = exports.columnControlsDecorationHeight = exports.TABLE_SNAP_GAP = exports.TABLE_HIGHLIGHT_GAP = void 0;
|
|
6
|
+
exports.tableToolbarSize = exports.tableToolbarSelectedColor = exports.tableToolbarDeleteColor = exports.tableToolbarColor = exports.tableTextColor = exports.tableScrollbarOffset = exports.tablePadding = exports.tableMarginFullWidthMode = exports.tableInsertColumnButtonSize = exports.tableInsertColumnButtonOffset = exports.tableHeaderCellBackgroundColor = exports.tableFloatingControlsColor = exports.tableDeleteButtonSize = exports.tableDeleteButtonOffset = exports.tableControlsSpacing = exports.tableCellSelectedDeleteIconColor = exports.tableCellSelectedDeleteIconBackground = exports.tableCellSelectedColor = exports.tableCellHoverDeleteIconColor = exports.tableCellHoverDeleteIconBackground = exports.tableCellDeleteColor = exports.tableCellBackgroundColor = exports.tableBorderSelectedColor = exports.tableBorderRadiusSize = exports.tableBorderDeleteColor = exports.tableBorderColor = exports.stickyRowZIndex = exports.stickyRowOffsetTop = exports.stickyHeaderBorderBottomWidth = exports.resizeLineWidth = exports.resizeHandlerZIndex = exports.resizeHandlerAreaWidth = exports.lineMarkerSize = exports.lineMarkerOffsetFromColumnControls = exports.layoutButtonSize = exports.contextualMenuTriggerSize = exports.contextualMenuDropdownWidth = exports.columnResizeHandleZIndex = exports.columnControlsZIndex = exports.columnControlsSelectedZIndex = exports.columnControlsDecorationHeight = exports.TABLE_SNAP_GAP = exports.TABLE_HIGHLIGHT_TOLERANCE = exports.TABLE_HIGHLIGHT_GAP = void 0;
|
|
7
7
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
8
8
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
9
9
|
var _colors = require("@atlaskit/theme/colors");
|
|
@@ -146,4 +146,6 @@ exports.stickyHeaderBorderBottomWidth = stickyHeaderBorderBottomWidth;
|
|
|
146
146
|
var TABLE_SNAP_GAP = 9;
|
|
147
147
|
exports.TABLE_SNAP_GAP = TABLE_SNAP_GAP;
|
|
148
148
|
var TABLE_HIGHLIGHT_GAP = 10;
|
|
149
|
-
exports.TABLE_HIGHLIGHT_GAP = TABLE_HIGHLIGHT_GAP;
|
|
149
|
+
exports.TABLE_HIGHLIGHT_GAP = TABLE_HIGHLIGHT_GAP;
|
|
150
|
+
var TABLE_HIGHLIGHT_TOLERANCE = 2;
|
|
151
|
+
exports.TABLE_HIGHLIGHT_TOLERANCE = TABLE_HIGHLIGHT_TOLERANCE;
|
|
@@ -4,19 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.defaultGuidelines =
|
|
7
|
+
exports.defaultGuidelines = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _guideline = require("@atlaskit/editor-common/guideline");
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (var i = 0; i <= numberOfLanesInDefaultLayoutWidth / 2; i++) {
|
|
15
|
-
widths.push(_editorSharedStyles.akEditorDefaultLayoutWidth / numberOfLanesInDefaultLayoutWidth * i * 2);
|
|
16
|
-
}
|
|
17
|
-
return widths;
|
|
18
|
-
};
|
|
19
|
-
var defaultGuidelineWidths = [].concat((0, _toConsumableArray2.default)(calculateGuidelineWidthsInDefaultLayoutWidth()), [_editorSharedStyles.akEditorDefaultLayoutWidth, _editorSharedStyles.akEditorCalculatedWideLayoutWidth, _editorSharedStyles.akEditorFullWidthLayoutWidth]);
|
|
20
|
-
exports.defaultGuidelineWidths = defaultGuidelineWidths;
|
|
21
|
-
var defaultGuidelines = (0, _guideline.createFixedGuidelinesFromLengths)(defaultGuidelineWidths);
|
|
10
|
+
var _snapping = require("./snapping");
|
|
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
|
+
// If we don't do this then the guidelines will not align correctly to the edge of the table
|
|
13
|
+
var defaultGuidelines = (0, _guideline.createFixedGuidelinesFromLengths)([0].concat((0, _toConsumableArray2.default)((0, _snapping.calculateDefaultSnappings)(-1))));
|
|
22
14
|
exports.defaultGuidelines = defaultGuidelines;
|
|
@@ -1,15 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.findClosestSnap = void 0;
|
|
7
|
+
exports.findClosestSnap = exports.defaultSnappingWidths = exports.calculateDefaultSnappings = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _guideline = require("@atlaskit/editor-common/guideline");
|
|
10
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
11
|
+
var numberOfLanesInDefaultLayoutWidth = 12;
|
|
12
|
+
var calculateSubSnappingWidths = function calculateSubSnappingWidths(totalLanes, totalWidth) {
|
|
13
|
+
return new Array(Math.round(totalLanes / 2) - 1).fill(totalWidth / totalLanes).map(function (v, i) {
|
|
14
|
+
return v * (i + 1) * 2;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var calculateDefaultSnappings = function calculateDefaultSnappings() {
|
|
18
|
+
var lengthOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
19
|
+
return [].concat((0, _toConsumableArray2.default)(calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, _editorSharedStyles.akEditorDefaultLayoutWidth + lengthOffset)), [_editorSharedStyles.akEditorDefaultLayoutWidth + lengthOffset, _editorSharedStyles.akEditorCalculatedWideLayoutWidth + lengthOffset, _editorSharedStyles.akEditorFullWidthLayoutWidth + lengthOffset]);
|
|
20
|
+
};
|
|
21
|
+
exports.calculateDefaultSnappings = calculateDefaultSnappings;
|
|
22
|
+
var defaultSnappingWidths = calculateDefaultSnappings();
|
|
23
|
+
|
|
8
24
|
/**
|
|
9
25
|
* Returns keys of guidelines that are closest to the table and withthin the snapGap
|
|
10
26
|
*/
|
|
27
|
+
exports.defaultSnappingWidths = defaultSnappingWidths;
|
|
11
28
|
var findClosestSnap = function findClosestSnap(currentWidth, snapWidths, guidelines) {
|
|
12
29
|
var snapGap = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
30
|
+
var tolerance = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
13
31
|
var closestGapIndex = snapWidths.reduce(function (prev, curr, index) {
|
|
14
32
|
return Math.abs(curr - currentWidth) < Math.abs(snapWidths[prev] - currentWidth) ? index : prev;
|
|
15
33
|
}, 0);
|
|
@@ -20,7 +38,8 @@ var findClosestSnap = function findClosestSnap(currentWidth, snapWidths, guideli
|
|
|
20
38
|
// NOTE: The snap points are based on the guidelines, however their formatted as a length value whereas the guidelines
|
|
21
39
|
// are point based. The point base x coords are calculated by halving the lengths. This means we can convert the
|
|
22
40
|
// point base position to length by simply multiplying by 2.
|
|
23
|
-
|
|
41
|
+
var length = Math.round(Math.abs((0, _guideline.isVerticalPosition)(guideline.position) ? guideline.position.x : guideline.position.y) * 2);
|
|
42
|
+
if (snappingWidth >= length - tolerance && snappingWidth <= length + tolerance) {
|
|
24
43
|
acc.push(guideline.key);
|
|
25
44
|
}
|
|
26
45
|
return acc;
|
package/dist/cjs/version.json
CHANGED
|
@@ -6,14 +6,15 @@ import { resizerHandleShadowClassName } from '@atlaskit/editor-common/styles';
|
|
|
6
6
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
7
7
|
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable } from '../pm-plugins/table-resizing/utils';
|
|
8
8
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
9
|
-
import { TABLE_HIGHLIGHT_GAP, TABLE_SNAP_GAP } from '../ui/consts';
|
|
9
|
+
import { TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
|
|
10
10
|
import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
|
|
11
|
-
import { defaultGuidelines
|
|
12
|
-
import { findClosestSnap } from '../utils/snapping';
|
|
11
|
+
import { defaultGuidelines } from '../utils/guidelines';
|
|
12
|
+
import { defaultSnappingWidths, findClosestSnap } from '../utils/snapping';
|
|
13
13
|
const handles = {
|
|
14
14
|
right: true
|
|
15
15
|
};
|
|
16
16
|
const tableHandleMarginTop = 12;
|
|
17
|
+
const tableHandlePosition = 14;
|
|
17
18
|
const getResizerHandleHeight = tableRef => {
|
|
18
19
|
const tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
|
|
19
20
|
let handleHeightSize = 'small';
|
|
@@ -69,7 +70,7 @@ export const TableResizer = ({
|
|
|
69
70
|
}
|
|
70
71
|
}, [displayGuideline]);
|
|
71
72
|
const guidelineSnaps = useMemo(() => snappingEnabled ? {
|
|
72
|
-
x:
|
|
73
|
+
x: defaultSnappingWidths
|
|
73
74
|
} : undefined, [snappingEnabled]);
|
|
74
75
|
const handleResizeStart = useCallback(() => {
|
|
75
76
|
startMeasure();
|
|
@@ -97,7 +98,7 @@ export const TableResizer = ({
|
|
|
97
98
|
start: pos + 1,
|
|
98
99
|
parentWidth: newWidth
|
|
99
100
|
}, editorView.domAtPos.bind(editorView));
|
|
100
|
-
updateActiveGuidelines(findClosestSnap(newWidth,
|
|
101
|
+
updateActiveGuidelines(findClosestSnap(newWidth, defaultSnappingWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE));
|
|
101
102
|
updateWidth(newWidth);
|
|
102
103
|
return newWidth;
|
|
103
104
|
}, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
|
|
@@ -180,6 +181,7 @@ export const TableResizer = ({
|
|
|
180
181
|
snapGap: TABLE_SNAP_GAP,
|
|
181
182
|
snap: guidelineSnaps,
|
|
182
183
|
handlePositioning: "adjacent",
|
|
184
|
+
innerPadding: tableHandlePosition,
|
|
183
185
|
isHandleVisible: ((_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(),
|
|
184
186
|
handleComponent: handleComponent
|
|
185
187
|
}, children);
|
|
@@ -98,4 +98,5 @@ export const stickyRowZIndex = resizeHandlerZIndex + 2;
|
|
|
98
98
|
export const stickyRowOffsetTop = 8;
|
|
99
99
|
export const stickyHeaderBorderBottomWidth = 1;
|
|
100
100
|
export const TABLE_SNAP_GAP = 9;
|
|
101
|
-
export const TABLE_HIGHLIGHT_GAP = 10;
|
|
101
|
+
export const TABLE_HIGHLIGHT_GAP = 10;
|
|
102
|
+
export const TABLE_HIGHLIGHT_TOLERANCE = 2;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { createFixedGuidelinesFromLengths } from '@atlaskit/editor-common/guideline';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
widths.push(akEditorDefaultLayoutWidth / numberOfLanesInDefaultLayoutWidth * i * 2);
|
|
8
|
-
}
|
|
9
|
-
return widths;
|
|
10
|
-
};
|
|
11
|
-
export const defaultGuidelineWidths = [...calculateGuidelineWidthsInDefaultLayoutWidth(), akEditorDefaultLayoutWidth, akEditorCalculatedWideLayoutWidth, akEditorFullWidthLayoutWidth];
|
|
12
|
-
export const defaultGuidelines = createFixedGuidelinesFromLengths(defaultGuidelineWidths);
|
|
2
|
+
import { calculateDefaultSnappings } from './snapping';
|
|
3
|
+
|
|
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
|
+
// If we don't do this then the guidelines will not align correctly to the edge of the table
|
|
6
|
+
export const defaultGuidelines = createFixedGuidelinesFromLengths([0, ...calculateDefaultSnappings(-1)]);
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
|
|
2
|
+
import { akEditorCalculatedWideLayoutWidth, akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
3
|
+
const numberOfLanesInDefaultLayoutWidth = 12;
|
|
4
|
+
const calculateSubSnappingWidths = (totalLanes, totalWidth) => new Array(Math.round(totalLanes / 2) - 1).fill(totalWidth / totalLanes).map((v, i) => v * (i + 1) * 2);
|
|
5
|
+
export const calculateDefaultSnappings = (lengthOffset = 0) => [...calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, akEditorDefaultLayoutWidth + lengthOffset), akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, akEditorFullWidthLayoutWidth + lengthOffset];
|
|
6
|
+
export const defaultSnappingWidths = calculateDefaultSnappings();
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Returns keys of guidelines that are closest to the table and withthin the snapGap
|
|
5
10
|
*/
|
|
6
|
-
export const findClosestSnap = (currentWidth, snapWidths, guidelines, snapGap = 0) => {
|
|
11
|
+
export const findClosestSnap = (currentWidth, snapWidths, guidelines, snapGap = 0, tolerance = 0) => {
|
|
7
12
|
const closestGapIndex = snapWidths.reduce((prev, curr, index) => Math.abs(curr - currentWidth) < Math.abs(snapWidths[prev] - currentWidth) ? index : prev, 0);
|
|
8
13
|
const gap = Math.abs(snapWidths[closestGapIndex] - currentWidth);
|
|
9
14
|
if (gap < snapGap) {
|
|
@@ -12,7 +17,8 @@ export const findClosestSnap = (currentWidth, snapWidths, guidelines, snapGap =
|
|
|
12
17
|
// NOTE: The snap points are based on the guidelines, however their formatted as a length value whereas the guidelines
|
|
13
18
|
// are point based. The point base x coords are calculated by halving the lengths. This means we can convert the
|
|
14
19
|
// point base position to length by simply multiplying by 2.
|
|
15
|
-
|
|
20
|
+
const length = Math.round(Math.abs(isVerticalPosition(guideline.position) ? guideline.position.x : guideline.position.y) * 2);
|
|
21
|
+
if (snappingWidth >= length - tolerance && snappingWidth <= length + tolerance) {
|
|
16
22
|
acc.push(guideline.key);
|
|
17
23
|
}
|
|
18
24
|
return acc;
|
package/dist/es2019/version.json
CHANGED
|
@@ -10,14 +10,15 @@ import { resizerHandleShadowClassName } from '@atlaskit/editor-common/styles';
|
|
|
10
10
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
11
11
|
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable } from '../pm-plugins/table-resizing/utils';
|
|
12
12
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
13
|
-
import { TABLE_HIGHLIGHT_GAP, TABLE_SNAP_GAP } from '../ui/consts';
|
|
13
|
+
import { TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
|
|
14
14
|
import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
|
|
15
|
-
import { defaultGuidelines
|
|
16
|
-
import { findClosestSnap } from '../utils/snapping';
|
|
15
|
+
import { defaultGuidelines } from '../utils/guidelines';
|
|
16
|
+
import { defaultSnappingWidths, findClosestSnap } from '../utils/snapping';
|
|
17
17
|
var handles = {
|
|
18
18
|
right: true
|
|
19
19
|
};
|
|
20
20
|
var tableHandleMarginTop = 12;
|
|
21
|
+
var tableHandlePosition = 14;
|
|
21
22
|
var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
|
|
22
23
|
var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
|
|
23
24
|
var handleHeightSize = 'small';
|
|
@@ -74,7 +75,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
74
75
|
}, [displayGuideline]);
|
|
75
76
|
var guidelineSnaps = useMemo(function () {
|
|
76
77
|
return snappingEnabled ? {
|
|
77
|
-
x:
|
|
78
|
+
x: defaultSnappingWidths
|
|
78
79
|
} : undefined;
|
|
79
80
|
}, [snappingEnabled]);
|
|
80
81
|
var handleResizeStart = useCallback(function () {
|
|
@@ -99,7 +100,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
99
100
|
start: pos + 1,
|
|
100
101
|
parentWidth: newWidth
|
|
101
102
|
}, editorView.domAtPos.bind(editorView));
|
|
102
|
-
updateActiveGuidelines(findClosestSnap(newWidth,
|
|
103
|
+
updateActiveGuidelines(findClosestSnap(newWidth, defaultSnappingWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE));
|
|
103
104
|
updateWidth(newWidth);
|
|
104
105
|
return newWidth;
|
|
105
106
|
}, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
|
|
@@ -183,6 +184,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
183
184
|
snapGap: TABLE_SNAP_GAP,
|
|
184
185
|
snap: guidelineSnaps,
|
|
185
186
|
handlePositioning: "adjacent",
|
|
187
|
+
innerPadding: tableHandlePosition,
|
|
186
188
|
isHandleVisible: ((_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(),
|
|
187
189
|
handleComponent: handleComponent
|
|
188
190
|
}, children);
|
|
@@ -98,4 +98,5 @@ export var stickyRowZIndex = resizeHandlerZIndex + 2;
|
|
|
98
98
|
export var stickyRowOffsetTop = 8;
|
|
99
99
|
export var stickyHeaderBorderBottomWidth = 1;
|
|
100
100
|
export var TABLE_SNAP_GAP = 9;
|
|
101
|
-
export var TABLE_HIGHLIGHT_GAP = 10;
|
|
101
|
+
export var TABLE_HIGHLIGHT_GAP = 10;
|
|
102
|
+
export var TABLE_HIGHLIGHT_TOLERANCE = 2;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import { createFixedGuidelinesFromLengths } from '@atlaskit/editor-common/guideline';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
widths.push(akEditorDefaultLayoutWidth / numberOfLanesInDefaultLayoutWidth * i * 2);
|
|
9
|
-
}
|
|
10
|
-
return widths;
|
|
11
|
-
};
|
|
12
|
-
export var defaultGuidelineWidths = [].concat(_toConsumableArray(calculateGuidelineWidthsInDefaultLayoutWidth()), [akEditorDefaultLayoutWidth, akEditorCalculatedWideLayoutWidth, akEditorFullWidthLayoutWidth]);
|
|
13
|
-
export var defaultGuidelines = createFixedGuidelinesFromLengths(defaultGuidelineWidths);
|
|
3
|
+
import { calculateDefaultSnappings } from './snapping';
|
|
4
|
+
|
|
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
|
+
// If we don't do this then the guidelines will not align correctly to the edge of the table
|
|
7
|
+
export var defaultGuidelines = createFixedGuidelinesFromLengths([0].concat(_toConsumableArray(calculateDefaultSnappings(-1))));
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
|
|
3
|
+
import { akEditorCalculatedWideLayoutWidth, akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
4
|
+
var numberOfLanesInDefaultLayoutWidth = 12;
|
|
5
|
+
var calculateSubSnappingWidths = function calculateSubSnappingWidths(totalLanes, totalWidth) {
|
|
6
|
+
return new Array(Math.round(totalLanes / 2) - 1).fill(totalWidth / totalLanes).map(function (v, i) {
|
|
7
|
+
return v * (i + 1) * 2;
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export var calculateDefaultSnappings = function calculateDefaultSnappings() {
|
|
11
|
+
var lengthOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
12
|
+
return [].concat(_toConsumableArray(calculateSubSnappingWidths(numberOfLanesInDefaultLayoutWidth, akEditorDefaultLayoutWidth + lengthOffset)), [akEditorDefaultLayoutWidth + lengthOffset, akEditorCalculatedWideLayoutWidth + lengthOffset, akEditorFullWidthLayoutWidth + lengthOffset]);
|
|
13
|
+
};
|
|
14
|
+
export var defaultSnappingWidths = calculateDefaultSnappings();
|
|
2
15
|
|
|
3
16
|
/**
|
|
4
17
|
* Returns keys of guidelines that are closest to the table and withthin the snapGap
|
|
5
18
|
*/
|
|
6
19
|
export var findClosestSnap = function findClosestSnap(currentWidth, snapWidths, guidelines) {
|
|
7
20
|
var snapGap = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
21
|
+
var tolerance = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
8
22
|
var closestGapIndex = snapWidths.reduce(function (prev, curr, index) {
|
|
9
23
|
return Math.abs(curr - currentWidth) < Math.abs(snapWidths[prev] - currentWidth) ? index : prev;
|
|
10
24
|
}, 0);
|
|
@@ -15,7 +29,8 @@ export var findClosestSnap = function findClosestSnap(currentWidth, snapWidths,
|
|
|
15
29
|
// NOTE: The snap points are based on the guidelines, however their formatted as a length value whereas the guidelines
|
|
16
30
|
// are point based. The point base x coords are calculated by halving the lengths. This means we can convert the
|
|
17
31
|
// point base position to length by simply multiplying by 2.
|
|
18
|
-
|
|
32
|
+
var length = Math.round(Math.abs(isVerticalPosition(guideline.position) ? guideline.position.x : guideline.position.y) * 2);
|
|
33
|
+
if (snappingWidth >= length - tolerance && snappingWidth <= length + tolerance) {
|
|
19
34
|
acc.push(guideline.key);
|
|
20
35
|
}
|
|
21
36
|
return acc;
|
package/dist/esm/version.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type GuidelineConfig } from '@atlaskit/editor-common/guideline';
|
|
2
|
+
export declare const calculateDefaultSnappings: (lengthOffset?: number) => number[];
|
|
3
|
+
export declare const defaultSnappingWidths: number[];
|
|
2
4
|
/**
|
|
3
5
|
* Returns keys of guidelines that are closest to the table and withthin the snapGap
|
|
4
6
|
*/
|
|
5
|
-
export declare const findClosestSnap: (currentWidth: number, snapWidths: number[], guidelines: GuidelineConfig[], snapGap?: number) => {
|
|
7
|
+
export declare const findClosestSnap: (currentWidth: number, snapWidths: number[], guidelines: GuidelineConfig[], snapGap?: number, tolerance?: number) => {
|
|
6
8
|
gap: number;
|
|
7
9
|
keys: string[];
|
|
8
10
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type GuidelineConfig } from '@atlaskit/editor-common/guideline';
|
|
2
|
+
export declare const calculateDefaultSnappings: (lengthOffset?: number) => number[];
|
|
3
|
+
export declare const defaultSnappingWidths: number[];
|
|
2
4
|
/**
|
|
3
5
|
* Returns keys of guidelines that are closest to the table and withthin the snapGap
|
|
4
6
|
*/
|
|
5
|
-
export declare const findClosestSnap: (currentWidth: number, snapWidths: number[], guidelines: GuidelineConfig[], snapGap?: number) => {
|
|
7
|
+
export declare const findClosestSnap: (currentWidth: number, snapWidths: number[], guidelines: GuidelineConfig[], snapGap?: number, tolerance?: number) => {
|
|
6
8
|
gap: number;
|
|
7
9
|
keys: string[];
|
|
8
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.5",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/adf-schema": "^28.1.0",
|
|
31
|
-
"@atlaskit/editor-common": "^74.
|
|
31
|
+
"@atlaskit/editor-common": "^74.45.0",
|
|
32
32
|
"@atlaskit/editor-palette": "1.5.1",
|
|
33
33
|
"@atlaskit/editor-plugin-analytics": "^0.1.0",
|
|
34
34
|
"@atlaskit/editor-plugin-content-insertion": "^0.0.8",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@atlaskit/editor-plugin-guideline": "^0.3.4",
|
|
62
62
|
"@atlaskit/editor-plugin-hyperlink": "^0.3.0",
|
|
63
63
|
"@atlaskit/editor-plugin-width": "^0.1.0",
|
|
64
|
-
"@atlaskit/editor-test-helpers": "^18.
|
|
64
|
+
"@atlaskit/editor-test-helpers": "^18.11.0",
|
|
65
65
|
"@atlaskit/visual-regression": "*",
|
|
66
66
|
"@atlaskit/webdriver-runner": "*",
|
|
67
67
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
@@ -24,14 +24,18 @@ import {
|
|
|
24
24
|
scaleTable,
|
|
25
25
|
} from '../pm-plugins/table-resizing/utils';
|
|
26
26
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
TABLE_HIGHLIGHT_GAP,
|
|
29
|
+
TABLE_HIGHLIGHT_TOLERANCE,
|
|
30
|
+
TABLE_SNAP_GAP,
|
|
31
|
+
} from '../ui/consts';
|
|
28
32
|
import {
|
|
29
33
|
generateResizedPayload,
|
|
30
34
|
generateResizeFrameRatePayloads,
|
|
31
35
|
useMeasureFramerate,
|
|
32
36
|
} from '../utils/analytics';
|
|
33
|
-
import { defaultGuidelines
|
|
34
|
-
import { findClosestSnap } from '../utils/snapping';
|
|
37
|
+
import { defaultGuidelines } from '../utils/guidelines';
|
|
38
|
+
import { defaultSnappingWidths, findClosestSnap } from '../utils/snapping';
|
|
35
39
|
|
|
36
40
|
interface TableResizerProps {
|
|
37
41
|
width: number;
|
|
@@ -49,6 +53,7 @@ interface TableResizerProps {
|
|
|
49
53
|
|
|
50
54
|
const handles = { right: true };
|
|
51
55
|
const tableHandleMarginTop = 12;
|
|
56
|
+
const tableHandlePosition = 14;
|
|
52
57
|
|
|
53
58
|
const getResizerHandleHeight = (tableRef: HTMLTableElement) => {
|
|
54
59
|
const tableHeight = tableRef?.clientHeight;
|
|
@@ -122,7 +127,7 @@ export const TableResizer = ({
|
|
|
122
127
|
() =>
|
|
123
128
|
snappingEnabled
|
|
124
129
|
? {
|
|
125
|
-
x:
|
|
130
|
+
x: defaultSnappingWidths,
|
|
126
131
|
}
|
|
127
132
|
: undefined,
|
|
128
133
|
[snappingEnabled],
|
|
@@ -164,9 +169,10 @@ export const TableResizer = ({
|
|
|
164
169
|
updateActiveGuidelines(
|
|
165
170
|
findClosestSnap(
|
|
166
171
|
newWidth,
|
|
167
|
-
|
|
172
|
+
defaultSnappingWidths,
|
|
168
173
|
defaultGuidelines,
|
|
169
174
|
TABLE_HIGHLIGHT_GAP,
|
|
175
|
+
TABLE_HIGHLIGHT_TOLERANCE,
|
|
170
176
|
),
|
|
171
177
|
);
|
|
172
178
|
|
|
@@ -291,6 +297,7 @@ export const TableResizer = ({
|
|
|
291
297
|
snapGap={TABLE_SNAP_GAP}
|
|
292
298
|
snap={guidelineSnaps}
|
|
293
299
|
handlePositioning="adjacent"
|
|
300
|
+
innerPadding={tableHandlePosition}
|
|
294
301
|
isHandleVisible={findTable(editorView.state?.selection)?.pos === getPos()}
|
|
295
302
|
handleComponent={handleComponent}
|
|
296
303
|
>
|
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
import { createFixedGuidelinesFromLengths } from '@atlaskit/editor-common/guideline';
|
|
2
2
|
import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
|
|
3
|
-
import {
|
|
4
|
-
akEditorCalculatedWideLayoutWidth,
|
|
5
|
-
akEditorDefaultLayoutWidth,
|
|
6
|
-
akEditorFullWidthLayoutWidth,
|
|
7
|
-
} from '@atlaskit/editor-shared-styles';
|
|
8
3
|
|
|
9
|
-
|
|
4
|
+
import { calculateDefaultSnappings } from './snapping';
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
return widths;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const defaultGuidelineWidths = [
|
|
22
|
-
...calculateGuidelineWidthsInDefaultLayoutWidth(),
|
|
23
|
-
akEditorDefaultLayoutWidth,
|
|
24
|
-
akEditorCalculatedWideLayoutWidth,
|
|
25
|
-
akEditorFullWidthLayoutWidth,
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
export const defaultGuidelines = createFixedGuidelinesFromLengths(
|
|
29
|
-
defaultGuidelineWidths,
|
|
30
|
-
) as GuidelineConfig[];
|
|
6
|
+
// NOTE: We have to take 1 pixel off every length due to the fact that the tbody is 1px smaller then the table container.
|
|
7
|
+
// If we don't do this then the guidelines will not align correctly to the edge of the table
|
|
8
|
+
export const defaultGuidelines = createFixedGuidelinesFromLengths([
|
|
9
|
+
0,
|
|
10
|
+
...calculateDefaultSnappings(-1),
|
|
11
|
+
]) as GuidelineConfig[];
|
|
@@ -2,6 +2,30 @@ import {
|
|
|
2
2
|
type GuidelineConfig,
|
|
3
3
|
isVerticalPosition,
|
|
4
4
|
} from '@atlaskit/editor-common/guideline';
|
|
5
|
+
import {
|
|
6
|
+
akEditorCalculatedWideLayoutWidth,
|
|
7
|
+
akEditorDefaultLayoutWidth,
|
|
8
|
+
akEditorFullWidthLayoutWidth,
|
|
9
|
+
} from '@atlaskit/editor-shared-styles';
|
|
10
|
+
|
|
11
|
+
const numberOfLanesInDefaultLayoutWidth = 12;
|
|
12
|
+
|
|
13
|
+
const calculateSubSnappingWidths = (totalLanes: number, totalWidth: number) =>
|
|
14
|
+
new Array(Math.round(totalLanes / 2) - 1)
|
|
15
|
+
.fill(totalWidth / totalLanes)
|
|
16
|
+
.map((v, i) => v * (i + 1) * 2);
|
|
17
|
+
|
|
18
|
+
export const calculateDefaultSnappings = (lengthOffset: number = 0) => [
|
|
19
|
+
...calculateSubSnappingWidths(
|
|
20
|
+
numberOfLanesInDefaultLayoutWidth,
|
|
21
|
+
akEditorDefaultLayoutWidth + lengthOffset,
|
|
22
|
+
),
|
|
23
|
+
akEditorDefaultLayoutWidth + lengthOffset,
|
|
24
|
+
akEditorCalculatedWideLayoutWidth + lengthOffset,
|
|
25
|
+
akEditorFullWidthLayoutWidth + lengthOffset,
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export const defaultSnappingWidths = calculateDefaultSnappings();
|
|
5
29
|
|
|
6
30
|
/**
|
|
7
31
|
* Returns keys of guidelines that are closest to the table and withthin the snapGap
|
|
@@ -11,6 +35,7 @@ export const findClosestSnap = (
|
|
|
11
35
|
snapWidths: number[],
|
|
12
36
|
guidelines: GuidelineConfig[],
|
|
13
37
|
snapGap: number = 0,
|
|
38
|
+
tolerance: number = 0,
|
|
14
39
|
) => {
|
|
15
40
|
const closestGapIndex = snapWidths.reduce(
|
|
16
41
|
(prev, curr, index) =>
|
|
@@ -26,9 +51,16 @@ export const findClosestSnap = (
|
|
|
26
51
|
// NOTE: The snap points are based on the guidelines, however their formatted as a length value whereas the guidelines
|
|
27
52
|
// are point based. The point base x coords are calculated by halving the lengths. This means we can convert the
|
|
28
53
|
// point base position to length by simply multiplying by 2.
|
|
54
|
+
const length = Math.round(
|
|
55
|
+
Math.abs(
|
|
56
|
+
isVerticalPosition(guideline.position)
|
|
57
|
+
? guideline.position.x
|
|
58
|
+
: guideline.position.y,
|
|
59
|
+
) * 2,
|
|
60
|
+
);
|
|
29
61
|
if (
|
|
30
|
-
|
|
31
|
-
|
|
62
|
+
snappingWidth >= length - tolerance &&
|
|
63
|
+
snappingWidth <= length + tolerance
|
|
32
64
|
) {
|
|
33
65
|
acc.push(guideline.key);
|
|
34
66
|
}
|