@atlaskit/editor-plugin-table 2.8.2 → 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.
Files changed (29) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +23 -22
  3. package/dist/cjs/plugins/table/ui/consts.js +4 -2
  4. package/dist/cjs/plugins/table/utils/guidelines.js +5 -13
  5. package/dist/cjs/plugins/table/utils/snapping.js +21 -2
  6. package/dist/cjs/version.json +1 -1
  7. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +24 -23
  8. package/dist/es2019/plugins/table/ui/consts.js +2 -1
  9. package/dist/es2019/plugins/table/utils/guidelines.js +5 -11
  10. package/dist/es2019/plugins/table/utils/snapping.js +8 -2
  11. package/dist/es2019/version.json +1 -1
  12. package/dist/esm/plugins/table/nodeviews/TableResizer.js +26 -25
  13. package/dist/esm/plugins/table/ui/consts.js +2 -1
  14. package/dist/esm/plugins/table/utils/guidelines.js +5 -11
  15. package/dist/esm/plugins/table/utils/snapping.js +16 -1
  16. package/dist/esm/version.json +1 -1
  17. package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +5 -5
  18. package/dist/types/plugins/table/ui/consts.d.ts +1 -0
  19. package/dist/types/plugins/table/utils/guidelines.d.ts +0 -1
  20. package/dist/types/plugins/table/utils/snapping.d.ts +3 -1
  21. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +5 -5
  22. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
  23. package/dist/types-ts4.5/plugins/table/utils/guidelines.d.ts +0 -1
  24. package/dist/types-ts4.5/plugins/table/utils/snapping.d.ts +3 -1
  25. package/package.json +3 -3
  26. package/src/plugins/table/nodeviews/TableResizer.tsx +65 -63
  27. package/src/plugins/table/ui/consts.ts +1 -0
  28. package/src/plugins/table/utils/guidelines.ts +7 -26
  29. 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.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
+
9
+ ## 2.8.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`77b74847baa`](https://bitbucket.org/atlassian/atlassian-frontend/commits/77b74847baa) - ED-19152 Cancels scheduled resize to avoid handleResize being called after handleResizeStop.
14
+
3
15
  ## 2.8.2
4
16
 
5
17
  ### 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 () {
@@ -96,6 +96,26 @@ var TableResizer = function TableResizer(_ref) {
96
96
  }));
97
97
  setSnappingEnabled(displayGuideline(_guidelines.defaultGuidelines));
98
98
  }, [displayGuideline, editorView, startMeasure]);
99
+ var handleResize = (0, _react.useCallback)(function (originalState, delta) {
100
+ countFrames();
101
+ var newWidth = originalState.width + delta.width;
102
+ var pos = getPos();
103
+ if (typeof pos !== 'number') {
104
+ return;
105
+ }
106
+ (0, _utils2.previewScaleTable)(tableRef, {
107
+ node: node,
108
+ prevNode: node,
109
+ start: pos + 1,
110
+ parentWidth: newWidth
111
+ }, editorView.domAtPos.bind(editorView));
112
+ updateActiveGuidelines((0, _snapping.findClosestSnap)(newWidth, _snapping.defaultSnappingWidths, _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP, _consts.TABLE_HIGHLIGHT_TOLERANCE));
113
+ updateWidth(newWidth);
114
+ return newWidth;
115
+ }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
116
+ var scheduleResize = (0, _react.useMemo)(function () {
117
+ return (0, _rafSchd.default)(handleResize);
118
+ }, [handleResize]);
99
119
  var handleResizeStop = (0, _react.useCallback)(function (originalState, delta) {
100
120
  var newWidth = originalState.width + delta.width;
101
121
  var state = editorView.state,
@@ -139,28 +159,9 @@ var TableResizer = function TableResizer(_ref) {
139
159
  // Hide guidelines when resizing stops
140
160
  displayGuideline([]);
141
161
  updateWidth(newWidth);
162
+ scheduleResize.cancel();
142
163
  return newWidth;
143
- }, [updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, endMeasure]);
144
- var handleResize = (0, _react.useCallback)(function (originalState, delta) {
145
- countFrames();
146
- var newWidth = originalState.width + delta.width;
147
- var pos = getPos();
148
- if (typeof pos !== 'number') {
149
- return;
150
- }
151
- (0, _utils2.previewScaleTable)(tableRef, {
152
- node: node,
153
- prevNode: node,
154
- start: pos + 1,
155
- parentWidth: newWidth
156
- }, editorView.domAtPos.bind(editorView));
157
- updateActiveGuidelines((0, _snapping.findClosestSnap)(newWidth, _guidelines.defaultGuidelineWidths, _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP));
158
- updateWidth(newWidth);
159
- return newWidth;
160
- }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
161
- var scheduleResize = (0, _react.useMemo)(function () {
162
- return (0, _rafSchd.default)(handleResize);
163
- }, [handleResize]);
164
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
164
165
  var handleComponent = (0, _react.useMemo)(function () {
165
166
  return {
166
167
  left: /*#__PURE__*/_react.default.createElement("div", {
@@ -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.2",
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();
@@ -84,6 +84,24 @@ export const TableResizer = ({
84
84
  }));
85
85
  setSnappingEnabled(displayGuideline(defaultGuidelines));
86
86
  }, [displayGuideline, editorView, startMeasure]);
87
+ const handleResize = useCallback((originalState, delta) => {
88
+ countFrames();
89
+ const newWidth = originalState.width + delta.width;
90
+ const pos = getPos();
91
+ if (typeof pos !== 'number') {
92
+ return;
93
+ }
94
+ previewScaleTable(tableRef, {
95
+ node,
96
+ prevNode: node,
97
+ start: pos + 1,
98
+ parentWidth: newWidth
99
+ }, editorView.domAtPos.bind(editorView));
100
+ updateActiveGuidelines(findClosestSnap(newWidth, defaultSnappingWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE));
101
+ updateWidth(newWidth);
102
+ return newWidth;
103
+ }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
104
+ const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
87
105
  const handleResizeStop = useCallback((originalState, delta) => {
88
106
  const newWidth = originalState.width + delta.width;
89
107
  const {
@@ -130,26 +148,9 @@ export const TableResizer = ({
130
148
  // Hide guidelines when resizing stops
131
149
  displayGuideline([]);
132
150
  updateWidth(newWidth);
151
+ scheduleResize.cancel();
133
152
  return newWidth;
134
- }, [updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, endMeasure]);
135
- const handleResize = useCallback((originalState, delta) => {
136
- countFrames();
137
- const newWidth = originalState.width + delta.width;
138
- const pos = getPos();
139
- if (typeof pos !== 'number') {
140
- return;
141
- }
142
- previewScaleTable(tableRef, {
143
- node,
144
- prevNode: node,
145
- start: pos + 1,
146
- parentWidth: newWidth
147
- }, editorView.domAtPos.bind(editorView));
148
- updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
149
- updateWidth(newWidth);
150
- return newWidth;
151
- }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
152
- const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
153
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
153
154
  const handleComponent = useMemo(() => ({
154
155
  left: /*#__PURE__*/React.createElement("div", {
155
156
  className: resizerHandleShadowClassName,
@@ -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.2",
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 () {
@@ -86,6 +86,26 @@ export var TableResizer = function TableResizer(_ref) {
86
86
  }));
87
87
  setSnappingEnabled(displayGuideline(defaultGuidelines));
88
88
  }, [displayGuideline, editorView, startMeasure]);
89
+ var handleResize = useCallback(function (originalState, delta) {
90
+ countFrames();
91
+ var newWidth = originalState.width + delta.width;
92
+ var pos = getPos();
93
+ if (typeof pos !== 'number') {
94
+ return;
95
+ }
96
+ previewScaleTable(tableRef, {
97
+ node: node,
98
+ prevNode: node,
99
+ start: pos + 1,
100
+ parentWidth: newWidth
101
+ }, editorView.domAtPos.bind(editorView));
102
+ updateActiveGuidelines(findClosestSnap(newWidth, defaultSnappingWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE));
103
+ updateWidth(newWidth);
104
+ return newWidth;
105
+ }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
106
+ var scheduleResize = useMemo(function () {
107
+ return rafSchd(handleResize);
108
+ }, [handleResize]);
89
109
  var handleResizeStop = useCallback(function (originalState, delta) {
90
110
  var newWidth = originalState.width + delta.width;
91
111
  var state = editorView.state,
@@ -129,28 +149,9 @@ export var TableResizer = function TableResizer(_ref) {
129
149
  // Hide guidelines when resizing stops
130
150
  displayGuideline([]);
131
151
  updateWidth(newWidth);
152
+ scheduleResize.cancel();
132
153
  return newWidth;
133
- }, [updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, endMeasure]);
134
- var handleResize = useCallback(function (originalState, delta) {
135
- countFrames();
136
- var newWidth = originalState.width + delta.width;
137
- var pos = getPos();
138
- if (typeof pos !== 'number') {
139
- return;
140
- }
141
- previewScaleTable(tableRef, {
142
- node: node,
143
- prevNode: node,
144
- start: pos + 1,
145
- parentWidth: newWidth
146
- }, editorView.domAtPos.bind(editorView));
147
- updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
148
- updateWidth(newWidth);
149
- return newWidth;
150
- }, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines, countFrames]);
151
- var scheduleResize = useMemo(function () {
152
- return rafSchd(handleResize);
153
- }, [handleResize]);
154
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
154
155
  var handleComponent = useMemo(function () {
155
156
  return {
156
157
  left: /*#__PURE__*/React.createElement("div", {
@@ -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.2",
3
+ "version": "2.8.4",
4
4
  "sideEffects": false
5
5
  }
@@ -1,9 +1,9 @@
1
- import { PropsWithChildren } from 'react';
2
- import { TableEventPayload } from '@atlaskit/editor-common/analytics';
1
+ import type { PropsWithChildren } from 'react';
2
+ import type { TableEventPayload } from '@atlaskit/editor-common/analytics';
3
3
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
4
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
6
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
6
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  interface TableResizerProps {
8
8
  width: number;
9
9
  maxWidth: number;
@@ -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
  };
@@ -1,9 +1,9 @@
1
- import { PropsWithChildren } from 'react';
2
- import { TableEventPayload } from '@atlaskit/editor-common/analytics';
1
+ import type { PropsWithChildren } from 'react';
2
+ import type { TableEventPayload } from '@atlaskit/editor-common/analytics';
3
3
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
4
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
6
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
6
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  interface TableResizerProps {
8
8
  width: number;
9
9
  maxWidth: number;
@@ -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.2",
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.42.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",
@@ -1,25 +1,20 @@
1
- import React, {
2
- PropsWithChildren,
3
- useCallback,
4
- useMemo,
5
- useRef,
6
- useState,
7
- } from 'react';
1
+ import type { PropsWithChildren } from 'react';
2
+ import React, { useCallback, useMemo, useRef, useState } from 'react';
8
3
 
9
4
  import rafSchd from 'raf-schd';
10
5
 
11
- import { TableEventPayload } from '@atlaskit/editor-common/analytics';
6
+ import type { TableEventPayload } from '@atlaskit/editor-common/analytics';
12
7
  import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
13
8
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
14
- import {
9
+ import type {
15
10
  HandleHeightSizeType,
16
11
  HandleResize,
17
- ResizerNext,
18
12
  } from '@atlaskit/editor-common/resizer';
13
+ import { ResizerNext } from '@atlaskit/editor-common/resizer';
19
14
  import { resizerHandleShadowClassName } from '@atlaskit/editor-common/styles';
20
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
21
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
22
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
15
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
16
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
17
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
23
18
  import { findTable } from '@atlaskit/editor-tables/utils';
24
19
 
25
20
  import {
@@ -29,14 +24,18 @@ import {
29
24
  scaleTable,
30
25
  } from '../pm-plugins/table-resizing/utils';
31
26
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
32
- 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';
33
32
  import {
34
33
  generateResizedPayload,
35
34
  generateResizeFrameRatePayloads,
36
35
  useMeasureFramerate,
37
36
  } from '../utils/analytics';
38
- import { defaultGuidelines, defaultGuidelineWidths } from '../utils/guidelines';
39
- import { findClosestSnap } from '../utils/snapping';
37
+ import { defaultGuidelines } from '../utils/guidelines';
38
+ import { defaultSnappingWidths, findClosestSnap } from '../utils/snapping';
40
39
 
41
40
  interface TableResizerProps {
42
41
  width: number;
@@ -127,7 +126,7 @@ export const TableResizer = ({
127
126
  () =>
128
127
  snappingEnabled
129
128
  ? {
130
- x: defaultGuidelineWidths,
129
+ x: defaultSnappingWidths,
131
130
  }
132
131
  : undefined,
133
132
  [snappingEnabled],
@@ -146,6 +145,53 @@ export const TableResizer = ({
146
145
  setSnappingEnabled(displayGuideline(defaultGuidelines));
147
146
  }, [displayGuideline, editorView, startMeasure]);
148
147
 
148
+ const handleResize = useCallback(
149
+ (originalState, delta) => {
150
+ countFrames();
151
+ const newWidth = originalState.width + delta.width;
152
+ const pos = getPos();
153
+ if (typeof pos !== 'number') {
154
+ return;
155
+ }
156
+
157
+ previewScaleTable(
158
+ tableRef,
159
+ {
160
+ node,
161
+ prevNode: node,
162
+ start: pos + 1,
163
+ parentWidth: newWidth,
164
+ },
165
+ editorView.domAtPos.bind(editorView),
166
+ );
167
+
168
+ updateActiveGuidelines(
169
+ findClosestSnap(
170
+ newWidth,
171
+ defaultSnappingWidths,
172
+ defaultGuidelines,
173
+ TABLE_HIGHLIGHT_GAP,
174
+ TABLE_HIGHLIGHT_TOLERANCE,
175
+ ),
176
+ );
177
+
178
+ updateWidth(newWidth);
179
+
180
+ return newWidth;
181
+ },
182
+ [
183
+ editorView,
184
+ getPos,
185
+ node,
186
+ tableRef,
187
+ updateWidth,
188
+ updateActiveGuidelines,
189
+ countFrames,
190
+ ],
191
+ );
192
+
193
+ const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
194
+
149
195
  const handleResizeStop = useCallback<HandleResize>(
150
196
  (originalState, delta) => {
151
197
  const newWidth = originalState.width + delta.width;
@@ -199,6 +245,7 @@ export const TableResizer = ({
199
245
  // Hide guidelines when resizing stops
200
246
  displayGuideline([]);
201
247
  updateWidth(newWidth);
248
+ scheduleResize.cancel();
202
249
 
203
250
  return newWidth;
204
251
  },
@@ -208,58 +255,13 @@ export const TableResizer = ({
208
255
  getPos,
209
256
  node,
210
257
  tableRef,
258
+ scheduleResize,
211
259
  displayGuideline,
212
260
  attachAnalyticsEvent,
213
261
  endMeasure,
214
262
  ],
215
263
  );
216
264
 
217
- const handleResize = useCallback(
218
- (originalState, delta) => {
219
- countFrames();
220
- const newWidth = originalState.width + delta.width;
221
- const pos = getPos();
222
- if (typeof pos !== 'number') {
223
- return;
224
- }
225
-
226
- previewScaleTable(
227
- tableRef,
228
- {
229
- node,
230
- prevNode: node,
231
- start: pos + 1,
232
- parentWidth: newWidth,
233
- },
234
- editorView.domAtPos.bind(editorView),
235
- );
236
-
237
- updateActiveGuidelines(
238
- findClosestSnap(
239
- newWidth,
240
- defaultGuidelineWidths,
241
- defaultGuidelines,
242
- TABLE_HIGHLIGHT_GAP,
243
- ),
244
- );
245
-
246
- updateWidth(newWidth);
247
-
248
- return newWidth;
249
- },
250
- [
251
- editorView,
252
- getPos,
253
- node,
254
- tableRef,
255
- updateWidth,
256
- updateActiveGuidelines,
257
- countFrames,
258
- ],
259
- );
260
-
261
- const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
262
-
263
265
  const handleComponent = useMemo(
264
266
  () => ({
265
267
  left: (
@@ -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
  }