sheet-happens 0.0.48 → 0.0.50

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/dist/index.js CHANGED
@@ -1203,7 +1203,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1203
1203
  var _getScrollPosition5 = getScrollPosition(e),
1204
1204
  currentScroll = _getScrollPosition5[0];
1205
1205
 
1206
- var newWidth = Math.max(size + x - anchor + scroll - currentScroll, SIZES.minimumWidth * indices.length);
1206
+ var newWidth = Math.round(Math.max(size + x - anchor + scroll - currentScroll, SIZES.minimumWidth * indices.length));
1207
1207
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(indices[0] - 1);
1208
1208
  onCellWidthChange(indices, indices.map(function (_) {
1209
1209
  return Math.round(newWidth / indices.length);
@@ -1223,7 +1223,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1223
1223
  var _getScrollPosition6 = getScrollPosition(e),
1224
1224
  _currentScroll = _getScrollPosition6[1];
1225
1225
 
1226
- var newHeight = Math.max(_size4 + y - _anchor + _scroll4 - _currentScroll, SIZES.minimumHeight * _indices5.length);
1226
+ var newHeight = Math.round(Math.max(_size4 + y - _anchor + _scroll4 - _currentScroll, SIZES.minimumHeight * _indices5.length));
1227
1227
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(_indices5[0] - 1);
1228
1228
  onCellHeightChange(_indices5, _indices5.map(function (_) {
1229
1229
  return newHeight / _indices5.length;
@@ -1644,6 +1644,7 @@ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadO
1644
1644
  return;
1645
1645
  }
1646
1646
 
1647
+ if (e.key === 'Enter') e.preventDefault();
1647
1648
  onEdit === null || onEdit === void 0 ? void 0 : onEdit(cell, e.key !== 'Enter');
1648
1649
  return;
1649
1650
  }
@@ -1758,18 +1759,18 @@ var clipDataOffset = function clipDataOffset(view, offset, freeze, maxCells, cel
1758
1759
 
1759
1760
  var _getViewExtent = getViewExtent(view, [newX, newY], freeze, cellLayout),
1760
1761
  _getViewExtent$edge = _getViewExtent.edge,
1761
- rightEdge = _getViewExtent$edge[0],
1762
- bottomEdge = _getViewExtent$edge[1],
1762
+ leftEdge = _getViewExtent$edge[0],
1763
+ topEdge = _getViewExtent$edge[1],
1763
1764
  _getViewExtent$viewpo = _getViewExtent.viewport,
1764
1765
  scrollW = _getViewExtent$viewpo[0],
1765
1766
  scrollH = _getViewExtent$viewpo[1];
1766
1767
 
1767
- if (rightEdge > maxColumns) {
1768
+ if (leftEdge >= maxColumns) {
1768
1769
  var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX + freezeX);
1769
1770
  newX = Math.max(0, absoluteToColumn(columnToAbsolute(newX + freezeX) - scrollW + remainder) - freezeX + 1);
1770
1771
  }
1771
1772
 
1772
- if (bottomEdge > maxRows) {
1773
+ if (topEdge >= maxRows) {
1773
1774
  var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY + freezeY);
1774
1775
 
1775
1776
  newY = Math.max(0, absoluteToRow(rowToAbsolute(newY + freezeY) - scrollH + _remainder) - freezeY + 1);
@@ -1779,10 +1780,6 @@ var clipDataOffset = function clipDataOffset(view, offset, freeze, maxCells, cel
1779
1780
  };
1780
1781
  var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
1781
1782
  var cellToAbsolute = cellLayout.cellToAbsolute,
1782
- absoluteToColumn = cellLayout.absoluteToColumn,
1783
- columnToAbsolute = cellLayout.columnToAbsolute,
1784
- absoluteToRow = cellLayout.absoluteToRow,
1785
- rowToAbsolute = cellLayout.rowToAbsolute,
1786
1783
  getIndentX = cellLayout.getIndentX,
1787
1784
  getIndentY = cellLayout.getIndentY;
1788
1785
  var x = offset[0],
@@ -1798,10 +1795,8 @@ var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
1798
1795
  var scrollH = h - frozenY - getIndentY();
1799
1796
  var leftEdge = x + freeze[0];
1800
1797
  var topEdge = y + freeze[1];
1801
- var rightEdge = absoluteToColumn(columnToAbsolute(leftEdge) + scrollW);
1802
- var bottomEdge = absoluteToRow(rowToAbsolute(topEdge) + scrollH);
1803
1798
  return {
1804
- edge: [rightEdge, bottomEdge],
1799
+ edge: [leftEdge, topEdge],
1805
1800
  viewport: [scrollW, scrollH]
1806
1801
  };
1807
1802
  };
@@ -2851,7 +2846,7 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2851
2846
  var clickables = [];
2852
2847
  var freeze = [freezeColumns, freezeRows];
2853
2848
  var indent = [rowHeaderWidth, columnHeaderHeight];
2854
- resizeCanvas(canvas);
2849
+ var pixelRatio = resizeCanvas(canvas);
2855
2850
  context.clearRect(0, 0, width, height);
2856
2851
  context.fillStyle = 'white';
2857
2852
  context.fillRect(0, 0, width, height);
@@ -2996,7 +2991,7 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2996
2991
 
2997
2992
  var _bottom2 = rowToPixel(row, 1);
2998
2993
 
2999
- clickables.push.apply(clickables, renderCell(context, content, resolvedStyle, 0, _top2, rowHeaderWidth, _bottom2 - _top2));
2994
+ clickables.push.apply(clickables, renderCell(context, content, resolvedStyle, 0, _top2, rowHeaderWidth, _bottom2 - _top2, pixelRatio));
3000
2995
  }
3001
2996
  }
3002
2997
 
@@ -3026,7 +3021,7 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
3026
3021
 
3027
3022
  var _content = (_columnHeaders = columnHeaders(column, _style)) != null ? _columnHeaders : excelHeaderString(column + 1);
3028
3023
 
3029
- clickables.push.apply(clickables, renderCell(context, _content, _style, _left2, 0, _right2 - _left2, columnHeaderHeight));
3024
+ clickables.push.apply(clickables, renderCell(context, _content, _style, _left2, 0, _right2 - _left2, columnHeaderHeight, pixelRatio));
3030
3025
  }
3031
3026
  }
3032
3027
 
@@ -3196,14 +3191,14 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
3196
3191
  var cellContent = displayData(_x, _y, _style2);
3197
3192
 
3198
3193
  if (cellContent !== null && cellContent !== undefined) {
3199
- clickables.push.apply(clickables, renderCell(context, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9));
3194
+ clickables.push.apply(clickables, renderCell(context, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9, pixelRatio));
3200
3195
  }
3201
3196
  }
3202
3197
  }
3203
3198
 
3204
3199
  return clickables;
3205
3200
  };
3206
- var renderCell = function renderCell(context, cellContent, style, xCoord, yCoord, cellWidth, cellHeight) {
3201
+ var renderCell = function renderCell(context, cellContent, style, xCoord, yCoord, cellWidth, cellHeight, pixelRatio) {
3207
3202
  var clickables = [];
3208
3203
 
3209
3204
  if (cellContent === null) {
@@ -3213,7 +3208,7 @@ var renderCell = function renderCell(context, cellContent, style, xCoord, yCoord
3213
3208
  context.fillStyle = style.color;
3214
3209
  context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
3215
3210
  context.textAlign = style.textAlign;
3216
- var yy = Math.floor(yCoord + cellHeight * 0.5);
3211
+ var yy = Math.round((yCoord + cellHeight * 0.5) * pixelRatio) / pixelRatio;
3217
3212
  context.save();
3218
3213
  context.beginPath();
3219
3214
  context.rect(xCoord, yCoord, cellWidth, cellHeight);
@@ -3419,11 +3414,9 @@ var resizeCanvas = function resizeCanvas(canvas) {
3419
3414
  canvas.height = newCanvasHeight;
3420
3415
  context.scale(ratio, ratio);
3421
3416
  }
3422
-
3423
- return true;
3424
3417
  }
3425
3418
 
3426
- return false;
3419
+ return ratio;
3427
3420
  };
3428
3421
 
3429
3422
  var excelHeaderString = function excelHeaderString(num) {