@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 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: _guidelines.defaultGuidelineWidths
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, _guidelines.defaultGuidelineWidths, _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP));
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 = exports.defaultGuidelineWidths = void 0;
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 _editorSharedStyles = require("@atlaskit/editor-shared-styles");
11
- var numberOfLanesInDefaultLayoutWidth = 12;
12
- var calculateGuidelineWidthsInDefaultLayoutWidth = function calculateGuidelineWidthsInDefaultLayoutWidth() {
13
- var widths = [];
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
- if ((0, _guideline.isVerticalPosition)(guideline.position) && Math.round(Math.abs(guideline.position.x) * 2) === snappingWidth) {
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;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "sideEffects": false
5
5
  }
@@ -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, defaultGuidelineWidths } from '../utils/guidelines';
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: defaultGuidelineWidths
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, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
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 { akEditorCalculatedWideLayoutWidth, akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
3
- const numberOfLanesInDefaultLayoutWidth = 12;
4
- const calculateGuidelineWidthsInDefaultLayoutWidth = () => {
5
- let widths = [];
6
- for (let i = 0; i <= numberOfLanesInDefaultLayoutWidth / 2; i++) {
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
- if (isVerticalPosition(guideline.position) && Math.round(Math.abs(guideline.position.x) * 2) === snappingWidth) {
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;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "sideEffects": false
5
5
  }
@@ -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, defaultGuidelineWidths } from '../utils/guidelines';
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: defaultGuidelineWidths
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, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
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 { akEditorCalculatedWideLayoutWidth, akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
4
- var numberOfLanesInDefaultLayoutWidth = 12;
5
- var calculateGuidelineWidthsInDefaultLayoutWidth = function calculateGuidelineWidthsInDefaultLayoutWidth() {
6
- var widths = [];
7
- for (var i = 0; i <= numberOfLanesInDefaultLayoutWidth / 2; i++) {
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
- if (isVerticalPosition(guideline.position) && Math.round(Math.abs(guideline.position.x) * 2) === snappingWidth) {
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;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "sideEffects": false
5
5
  }
@@ -44,3 +44,4 @@ export declare const stickyRowOffsetTop = 8;
44
44
  export declare const stickyHeaderBorderBottomWidth = 1;
45
45
  export declare const TABLE_SNAP_GAP = 9;
46
46
  export declare const TABLE_HIGHLIGHT_GAP = 10;
47
+ export declare const TABLE_HIGHLIGHT_TOLERANCE = 2;
@@ -1,3 +1,2 @@
1
1
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
2
- export declare const defaultGuidelineWidths: number[];
3
2
  export declare const defaultGuidelines: GuidelineConfig[];
@@ -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
  };
@@ -44,3 +44,4 @@ export declare const stickyRowOffsetTop = 8;
44
44
  export declare const stickyHeaderBorderBottomWidth = 1;
45
45
  export declare const TABLE_SNAP_GAP = 9;
46
46
  export declare const TABLE_HIGHLIGHT_GAP = 10;
47
+ export declare const TABLE_HIGHLIGHT_TOLERANCE = 2;
@@ -1,3 +1,2 @@
1
1
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
2
- export declare const defaultGuidelineWidths: number[];
3
2
  export declare const defaultGuidelines: GuidelineConfig[];
@@ -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",
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.44.0",
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.10.0",
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 { TABLE_HIGHLIGHT_GAP, TABLE_SNAP_GAP } from '../ui/consts';
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, defaultGuidelineWidths } from '../utils/guidelines';
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: defaultGuidelineWidths,
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
- defaultGuidelineWidths,
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
  >
@@ -133,3 +133,4 @@ export const stickyHeaderBorderBottomWidth = 1;
133
133
 
134
134
  export const TABLE_SNAP_GAP = 9;
135
135
  export const TABLE_HIGHLIGHT_GAP = 10;
136
+ export const TABLE_HIGHLIGHT_TOLERANCE = 2;
@@ -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
- const numberOfLanesInDefaultLayoutWidth = 12;
4
+ import { calculateDefaultSnappings } from './snapping';
10
5
 
11
- const calculateGuidelineWidthsInDefaultLayoutWidth = () => {
12
- let widths: number[] = [];
13
- for (let i = 0; i <= numberOfLanesInDefaultLayoutWidth / 2; i++) {
14
- widths.push(
15
- (akEditorDefaultLayoutWidth / numberOfLanesInDefaultLayoutWidth) * i * 2,
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
- isVerticalPosition(guideline.position) &&
31
- Math.round(Math.abs(guideline.position.x) * 2) === snappingWidth
62
+ snappingWidth >= length - tolerance &&
63
+ snappingWidth <= length + tolerance
32
64
  ) {
33
65
  acc.push(guideline.key);
34
66
  }