sheet-happens 0.0.16 → 0.0.18

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.d.ts CHANGED
@@ -45,6 +45,7 @@ export interface SheetProps {
45
45
  displayData?: CellProperty<CellContentType>;
46
46
  editData?: CellProperty<string>;
47
47
  editKeys?: CellProperty<string>;
48
+ hideGridlines?: boolean;
48
49
  inputComponent?: (x: number, y: number, props: SheetInputProps, commitEditingCell?: () => void) => ReactElement | undefined;
49
50
  onSelectionChanged?: (x1: number, y1: number, x2: number, y2: number) => void;
50
51
  onRightClick?: (e: SheetMouseEvent) => void;
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ var scrollSpeed = 30;
84
84
  var resizeColumnRowMouseThreshold = 4;
85
85
  var minimumColumnWidth = 50;
86
86
  var minimumRowHeight = 22;
87
- var rowColHeaderSelectionColor = '#AAAAAA';
87
+ var rowColHeaderSelectionColor = '#cccccc';
88
88
  var maxSearchableRowOrCol = 65536;
89
89
  var defaultCellStyle = {
90
90
  textAlign: 'left',
@@ -114,14 +114,7 @@ function resizeCanvas(canvas) {
114
114
  width = _canvas$getBoundingCl.width,
115
115
  height = _canvas$getBoundingCl.height;
116
116
 
117
- var _window = window,
118
- _window$devicePixelRa = _window.devicePixelRatio,
119
- ratio = _window$devicePixelRa === void 0 ? 1 : _window$devicePixelRa;
120
-
121
- if (ratio < 1) {
122
- ratio = 1;
123
- }
124
-
117
+ var ratio = 2;
125
118
  var newCanvasWidth = Math.round(width * ratio);
126
119
  var newCanvasHeight = Math.round(height * ratio);
127
120
 
@@ -503,7 +496,7 @@ function findInDisplayData(displayData, start, direction) {
503
496
  return i;
504
497
  }
505
498
 
506
- function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates) {
499
+ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates, hideGridlines) {
507
500
  resizeCanvas(context.canvas);
508
501
  context.clearRect(0, 0, context.canvas.width, context.canvas.height);
509
502
  context.fillStyle = 'white';
@@ -580,15 +573,19 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
580
573
 
581
574
  if (selectionActive) {
582
575
  context.fillStyle = selBackColor;
583
- var p1x = Math.max(-100, p1.x);
584
- var p1y = Math.max(-100, p1.y);
585
576
 
586
577
  if (rowSelectionActive) {
578
+ var p1x = Math.max(-100, p1.x);
579
+ var p1y = Math.max(-100, p1.y);
587
580
  context.fillRect(p1x, p1y, 100000, p2.y - p1.y);
588
581
  } else if (colSelectionActive) {
589
- context.fillRect(p1x, p1y, p2.x - p1.x, 100000);
582
+ var _p1x = Math.max(-100, p1.x);
583
+
584
+ var _p1y = Math.max(-100, p1.y);
585
+
586
+ context.fillRect(_p1x, _p1y, p2.x - p1.x, 100000);
590
587
  } else {
591
- context.fillRect(p1x, p1y, p2.x - p1.x, p2.y - p1.y);
588
+ context.fillRect(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
592
589
  }
593
590
  }
594
591
 
@@ -611,23 +608,41 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
611
608
  context.strokeStyle = gridColor;
612
609
  context.lineWidth = 1;
613
610
  var startX = rowHeaderWidth;
611
+ var startY = columnHeaderHeight;
612
+ var xGridlineEnd = hideGridlines ? rowHeaderWidth : context.canvas.width;
613
+ var yGridlineEnd = hideGridlines ? columnHeaderHeight : context.canvas.height;
614
+ var first = true;
614
615
 
615
616
  for (var _iterator3 = _createForOfIteratorHelperLoose(columnSizes.index), _step3; !(_step3 = _iterator3()).done;) {
616
617
  var col = _step3.value;
617
618
  context.beginPath();
618
619
  context.moveTo(startX, 0);
619
- context.lineTo(startX, context.canvas.height);
620
+
621
+ if (first) {
622
+ context.lineTo(startX, context.canvas.height);
623
+ first = false;
624
+ } else {
625
+ context.lineTo(startX, yGridlineEnd);
626
+ }
627
+
620
628
  context.stroke();
621
629
  startX += cellWidth(col);
622
630
  }
623
631
 
624
- var startY = columnHeaderHeight;
632
+ first = true;
625
633
 
626
634
  for (var _iterator4 = _createForOfIteratorHelperLoose(rowSizes.index), _step4; !(_step4 = _iterator4()).done;) {
627
635
  var row = _step4.value;
628
636
  context.beginPath();
629
637
  context.moveTo(0, startY);
630
- context.lineTo(context.canvas.width, startY);
638
+
639
+ if (first) {
640
+ context.lineTo(context.canvas.width, startY);
641
+ first = false;
642
+ } else {
643
+ context.lineTo(xGridlineEnd, startY);
644
+ }
645
+
631
646
  context.stroke();
632
647
  startY += cellHeight(row);
633
648
  }
@@ -678,19 +693,22 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
678
693
  if (selectionActive) {
679
694
  context.strokeStyle = selBorderColor;
680
695
  context.lineWidth = 1;
681
-
682
- var _p1x = Math.max(-100, p1.x);
683
-
684
- var _p1y = Math.max(-100, p1.y);
685
-
686
696
  context.beginPath();
687
697
 
688
698
  if (rowSelectionActive) {
689
- context.rect(_p1x, _p1y, 100000, p2.y - p1.y);
699
+ var _p1x2 = Math.max(-100, p1.x);
700
+
701
+ var _p1y2 = Math.max(-100, p1.y);
702
+
703
+ context.rect(_p1x2, _p1y2, 100000, p2.y - p1.y);
690
704
  } else if (colSelectionActive) {
691
- context.rect(_p1x, _p1y, p2.x - p1.x, 100000);
705
+ var _p1x3 = Math.max(-100, p1.x);
706
+
707
+ var _p1y3 = Math.max(-100, p1.y);
708
+
709
+ context.rect(_p1x3, _p1y3, p2.x - p1.x, 100000);
692
710
  } else {
693
- context.rect(_p1x, _p1y, p2.x - p1.x, p2.y - p1.y);
711
+ context.rect(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
694
712
  }
695
713
 
696
714
  context.stroke();
@@ -1237,12 +1255,12 @@ function Sheet(props) {
1237
1255
  }
1238
1256
 
1239
1257
  var animationFrameId = window.requestAnimationFrame(function () {
1240
- renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates);
1258
+ renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates, props.hideGridlines || false);
1241
1259
  });
1242
1260
  return function () {
1243
1261
  window.cancelAnimationFrame(animationFrameId);
1244
1262
  };
1245
- }, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates]);
1263
+ }, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates, props.hideGridlines]);
1246
1264
 
1247
1265
  var setFocusToTextArea = function setFocusToTextArea() {
1248
1266
  if (copyPasteTextAreaRef.current) {
@@ -1809,8 +1827,9 @@ function Sheet(props) {
1809
1827
  }
1810
1828
 
1811
1829
  if (fx1 === -1 && fx2 === -1) {
1830
+ var max = findApproxMaxEditDataIndex(editData);
1812
1831
  fx1 = 0;
1813
- fx2 = maxSearchableRowOrCol;
1832
+ fx2 = max.x;
1814
1833
  }
1815
1834
 
1816
1835
  var srcY = sy1;
@@ -1839,8 +1858,10 @@ function Sheet(props) {
1839
1858
  }
1840
1859
 
1841
1860
  if (fy1 === -1 && fy2 === -1) {
1861
+ var _max3 = findApproxMaxEditDataIndex(editData);
1862
+
1842
1863
  fy1 = 0;
1843
- fy2 = maxSearchableRowOrCol;
1864
+ fy2 = _max3.y;
1844
1865
  }
1845
1866
 
1846
1867
  var srcX = sx1;