sheet-happens 0.0.39 → 0.0.40

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.
@@ -23,3 +23,4 @@ export declare const isPointInsideSelection: (selection: Rectangle, point: XY) =
23
23
  export declare const validateSelection: (selection: Rectangle) => Rectangle;
24
24
  export declare const normalizeSelection: (selection: Rectangle) => Rectangle;
25
25
  export declare const orientSelection: (normalized: Rectangle, to: Rectangle) => Rectangle;
26
+ export declare const clipSelection: (selection: Rectangle, max: XY) => Rectangle;
package/dist/index.js CHANGED
@@ -351,6 +351,11 @@ var orientSelection = function orientSelection(normalized, to) {
351
351
  var swapY = (ay - hy || 1) * (bottom - top || 1) < 0;
352
352
  return [[swapX ? right : left, swapY ? bottom : top], [swapX ? left : right, swapY ? top : bottom]];
353
353
  };
354
+ var clipSelection = function clipSelection(selection, max) {
355
+ var anchor = selection[0],
356
+ head = selection[1];
357
+ return [minXY(anchor, max), minXY(head, max)];
358
+ };
354
359
 
355
360
  var LIMIT = 1000;
356
361
 
@@ -1487,17 +1492,25 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
1487
1492
  }
1488
1493
  }, [cellLayout, onOffsetChange, onMaxScrollChange]);
1489
1494
  };
1490
- var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxScroll, cellLayout, callback) {
1495
+ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxCells, maxScroll, cellLayout, callback) {
1491
1496
  var x = cell[0],
1492
1497
  y = cell[1];
1493
1498
  var w = view[0],
1494
1499
  h = view[1];
1495
1500
  var offsetX = offset[0],
1496
1501
  offsetY = offset[1];
1502
+ var maxColumns = maxCells[0],
1503
+ maxRows = maxCells[1];
1497
1504
  var cellToAbsolute = cellLayout.cellToAbsolute,
1498
1505
  cellToPixel = cellLayout.cellToPixel,
1499
1506
  columnToPixel = cellLayout.columnToPixel,
1500
- rowToPixel = cellLayout.rowToPixel;
1507
+ rowToPixel = cellLayout.rowToPixel,
1508
+ absoluteToColumn = cellLayout.absoluteToColumn,
1509
+ columnToAbsolute = cellLayout.columnToAbsolute,
1510
+ absoluteToRow = cellLayout.absoluteToRow,
1511
+ rowToAbsolute = cellLayout.rowToAbsolute,
1512
+ getIndentX = cellLayout.getIndentX,
1513
+ getIndentY = cellLayout.getIndentY;
1501
1514
 
1502
1515
  var _cellToAbsolute2 = cellToAbsolute(freeze),
1503
1516
  frozenX = _cellToAbsolute2[0],
@@ -1516,10 +1529,25 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1516
1529
 
1517
1530
  if (left <= frozenX) {
1518
1531
  newX = x - freeze[0];
1532
+ var scrollW = w - frozenX - getIndentX();
1533
+ var rightEdge = absoluteToColumn(columnToAbsolute(newX) + scrollW);
1534
+
1535
+ if (rightEdge > maxColumns) {
1536
+ var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX);
1537
+ newX = absoluteToColumn(columnToAbsolute(newX) - scrollW + remainder) + 1;
1538
+ }
1519
1539
  }
1520
1540
 
1521
1541
  if (top <= frozenY) {
1522
1542
  newY = y - freeze[1];
1543
+ var scrollH = h - frozenY - getIndentY();
1544
+ var bottomEdge = absoluteToRow(rowToAbsolute(newY) + scrollH);
1545
+
1546
+ if (bottomEdge > maxRows) {
1547
+ var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY);
1548
+
1549
+ newY = absoluteToRow(rowToAbsolute(newY) - scrollH + _remainder) + 1;
1550
+ }
1523
1551
  }
1524
1552
 
1525
1553
  if (right > w) {
@@ -3025,7 +3053,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3025
3053
  if (scrollTo) {
3026
3054
  var anchor = newSelection[0],
3027
3055
  head = newSelection[1];
3028
- scrollToCell(overlay, toHead ? head : anchor, [canvasWidth, canvasHeight], [freezeColumns, freezeRows], dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
3056
+ scrollToCell(overlay, toHead ? head : anchor, [canvasWidth, canvasHeight], [freezeColumns, freezeRows], dataOffset, [maxColumns, maxRows], maxScroll, cellLayout, function (dataOffset, maxScroll) {
3029
3057
  setDataOffset(dataOffset);
3030
3058
  setMaxScroll(maxScroll);
3031
3059
  });
@@ -3083,6 +3111,22 @@ var Sheet = React.forwardRef(function (props, ref) {
3083
3111
  setLastEditKey(editKeys.apply(void 0, editCell));
3084
3112
  };
3085
3113
 
3114
+ var _props$maxColumns = props.maxColumns,
3115
+ maxColumns = _props$maxColumns === void 0 ? Infinity : _props$maxColumns,
3116
+ _props$maxRows = props.maxRows,
3117
+ maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
3118
+ React.useLayoutEffect(function () {
3119
+ var _normalizeSelection2 = normalizeSelection(selection),
3120
+ _normalizeSelection2$ = _normalizeSelection2[1],
3121
+ maxX = _normalizeSelection2$[0],
3122
+ maxY = _normalizeSelection2$[1];
3123
+
3124
+ var overflowX = maxX > maxColumns;
3125
+ var overflowY = maxY > maxRows;
3126
+ if (!overflowX && !overflowY) return;
3127
+ var corner = [maxColumns - 1, maxRows - 1];
3128
+ changeSelection(clipSelection(selection, corner), true);
3129
+ }, [maxRows, maxColumns]);
3086
3130
  var hitmapRef = React.useRef(NO_CLICKABLES);
3087
3131
  var textAreaRef = React.useRef(null);
3088
3132
  useClipboardCopy(textAreaRef, selection, editMode, editData);
@@ -3148,13 +3192,13 @@ var Sheet = React.forwardRef(function (props, ref) {
3148
3192
  }
3149
3193
 
3150
3194
  if (e.key === 'Backspace' || e.key === 'Delete') {
3151
- var _normalizeSelection2 = normalizeSelection(selection),
3152
- _normalizeSelection2$ = _normalizeSelection2[0],
3153
- x1 = _normalizeSelection2$[0],
3154
- y1 = _normalizeSelection2$[1],
3155
- _normalizeSelection2$2 = _normalizeSelection2[1],
3156
- x2 = _normalizeSelection2$2[0],
3157
- y2 = _normalizeSelection2$2[1];
3195
+ var _normalizeSelection3 = normalizeSelection(selection),
3196
+ _normalizeSelection3$ = _normalizeSelection3[0],
3197
+ x1 = _normalizeSelection3$[0],
3198
+ y1 = _normalizeSelection3$[1],
3199
+ _normalizeSelection3$2 = _normalizeSelection3[1],
3200
+ x2 = _normalizeSelection3$2[0],
3201
+ y2 = _normalizeSelection3$2[1];
3158
3202
 
3159
3203
  if (isRowSelection(selection)) {
3160
3204
  x1 = 0;