@atlaskit/editor-plugin-table 2.8.3 → 2.8.4

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,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 2.8.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`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
8
+
3
9
  ## 2.8.3
4
10
 
5
11
  ### Patch Changes
@@ -84,7 +84,7 @@ var TableResizer = function TableResizer(_ref) {
84
84
  }, [displayGuideline]);
85
85
  var guidelineSnaps = (0, _react.useMemo)(function () {
86
86
  return snappingEnabled ? {
87
- x: _guidelines.defaultGuidelineWidths
87
+ x: _snapping.defaultSnappingWidths
88
88
  } : undefined;
89
89
  }, [snappingEnabled]);
90
90
  var handleResizeStart = (0, _react.useCallback)(function () {
@@ -109,7 +109,7 @@ var TableResizer = function TableResizer(_ref) {
109
109
  start: pos + 1,
110
110
  parentWidth: newWidth
111
111
  }, editorView.domAtPos.bind(editorView));
112
- updateActiveGuidelines((0, _snapping.findClosestSnap)(newWidth, _guidelines.defaultGuidelineWidths, _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP));
112
+ updateActiveGuidelines((0, _snapping.findClosestSnap)(newWidth, _snapping.defaultSnappingWidths, _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE));
113
113
  updateWidth(newWidth);
114
114
  return newWidth;
115
115
  }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
@@ -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.4",
4
4
  "sideEffects": false
5
5
  }
@@ -6,10 +6,10 @@ 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
  };
@@ -69,7 +69,7 @@ export const TableResizer = ({
69
69
  }
70
70
  }, [displayGuideline]);
71
71
  const guidelineSnaps = useMemo(() => snappingEnabled ? {
72
- x: defaultGuidelineWidths
72
+ x: defaultSnappingWidths
73
73
  } : undefined, [snappingEnabled]);
74
74
  const handleResizeStart = useCallback(() => {
75
75
  startMeasure();
@@ -97,7 +97,7 @@ export const TableResizer = ({
97
97
  start: pos + 1,
98
98
  parentWidth: newWidth
99
99
  }, editorView.domAtPos.bind(editorView));
100
- updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
100
+ updateActiveGuidelines(findClosestSnap(newWidth, defaultSnappingWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE));
101
101
  updateWidth(newWidth);
102
102
  return newWidth;
103
103
  }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
@@ -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.4",
4
4
  "sideEffects": false
5
5
  }
@@ -10,10 +10,10 @@ 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
  };
@@ -74,7 +74,7 @@ export var TableResizer = function TableResizer(_ref) {
74
74
  }, [displayGuideline]);
75
75
  var guidelineSnaps = useMemo(function () {
76
76
  return snappingEnabled ? {
77
- x: defaultGuidelineWidths
77
+ x: defaultSnappingWidths
78
78
  } : undefined;
79
79
  }, [snappingEnabled]);
80
80
  var handleResizeStart = useCallback(function () {
@@ -99,7 +99,7 @@ export var TableResizer = function TableResizer(_ref) {
99
99
  start: pos + 1,
100
100
  parentWidth: newWidth
101
101
  }, editorView.domAtPos.bind(editorView));
102
- updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
102
+ updateActiveGuidelines(findClosestSnap(newWidth, defaultSnappingWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE));
103
103
  updateWidth(newWidth);
104
104
  return newWidth;
105
105
  }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
@@ -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.4",
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.4",
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;
@@ -122,7 +126,7 @@ export const TableResizer = ({
122
126
  () =>
123
127
  snappingEnabled
124
128
  ? {
125
- x: defaultGuidelineWidths,
129
+ x: defaultSnappingWidths,
126
130
  }
127
131
  : undefined,
128
132
  [snappingEnabled],
@@ -164,9 +168,10 @@ export const TableResizer = ({
164
168
  updateActiveGuidelines(
165
169
  findClosestSnap(
166
170
  newWidth,
167
- defaultGuidelineWidths,
171
+ defaultSnappingWidths,
168
172
  defaultGuidelines,
169
173
  TABLE_HIGHLIGHT_GAP,
174
+ TABLE_HIGHLIGHT_TOLERANCE,
170
175
  ),
171
176
  );
172
177
 
@@ -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
  }