sheet-happens 0.0.18 → 0.0.20
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 +8 -2
- package/dist/index.js +174 -138
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +174 -138
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -71,11 +71,11 @@ var selBackColor = '#e9f0fd';
|
|
|
71
71
|
var knobSize = 6;
|
|
72
72
|
var gridColor = '#e2e3e3';
|
|
73
73
|
var knobAreaBorderColor = '#707070';
|
|
74
|
-
var
|
|
74
|
+
var kRowHeaderWidth = 50;
|
|
75
75
|
var rowHeaderBackgroundColor = '#f8f9fa';
|
|
76
76
|
var rowHeaderTextColor = '#666666';
|
|
77
77
|
var rowHeaderSelectedBackgroundColor = '#e8eaed';
|
|
78
|
-
var
|
|
78
|
+
var kColumnHeaderHeight = 22;
|
|
79
79
|
var columnHeaderBackgroundColor = rowHeaderBackgroundColor;
|
|
80
80
|
var columnHeaderSelectedBackgroundColor = rowHeaderSelectedBackgroundColor;
|
|
81
81
|
var xBinSize = 10;
|
|
@@ -114,7 +114,14 @@ function resizeCanvas(canvas) {
|
|
|
114
114
|
width = _canvas$getBoundingCl.width,
|
|
115
115
|
height = _canvas$getBoundingCl.height;
|
|
116
116
|
|
|
117
|
-
var
|
|
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
|
+
|
|
118
125
|
var newCanvasWidth = Math.round(width * ratio);
|
|
119
126
|
var newCanvasHeight = Math.round(height * ratio);
|
|
120
127
|
|
|
@@ -328,8 +335,8 @@ function absCoordianteToCell(absX, absY, rowSizes, columnSizes) {
|
|
|
328
335
|
};
|
|
329
336
|
}
|
|
330
337
|
|
|
331
|
-
function cellToAbsCoordinate(cellX, cellY, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight) {
|
|
332
|
-
var absX = rowHeaderWidth;
|
|
338
|
+
function cellToAbsCoordinate(cellX, cellY, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle) {
|
|
339
|
+
var absX = sheetStyle.rowHeaderWidth;
|
|
333
340
|
var indX = columnSizes.index.findIndex(function (i) {
|
|
334
341
|
return i === cellX;
|
|
335
342
|
});
|
|
@@ -346,7 +353,7 @@ function cellToAbsCoordinate(cellX, cellY, rowSizes, columnSizes, dataOffset, ce
|
|
|
346
353
|
}
|
|
347
354
|
}
|
|
348
355
|
|
|
349
|
-
var absY = columnHeaderHeight;
|
|
356
|
+
var absY = sheetStyle.columnHeaderHeight;
|
|
350
357
|
var indY = rowSizes.index.findIndex(function (i) {
|
|
351
358
|
return i === cellY;
|
|
352
359
|
});
|
|
@@ -496,16 +503,16 @@ function findInDisplayData(displayData, start, direction) {
|
|
|
496
503
|
return i;
|
|
497
504
|
}
|
|
498
505
|
|
|
499
|
-
function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates,
|
|
506
|
+
function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates, sheetStyle) {
|
|
500
507
|
resizeCanvas(context.canvas);
|
|
501
508
|
context.clearRect(0, 0, context.canvas.width, context.canvas.height);
|
|
502
509
|
context.fillStyle = 'white';
|
|
503
510
|
context.fillRect(0, 0, context.canvas.width, context.canvas.height);
|
|
504
|
-
var yCoord1 = columnHeaderHeight;
|
|
511
|
+
var yCoord1 = sheetStyle.columnHeaderHeight;
|
|
505
512
|
|
|
506
513
|
for (var _iterator2 = _createForOfIteratorHelperLoose(rowSizes.index), _step2; !(_step2 = _iterator2()).done;) {
|
|
507
514
|
var y = _step2.value;
|
|
508
|
-
var xCoord1 = rowHeaderWidth;
|
|
515
|
+
var xCoord1 = sheetStyle.rowHeaderWidth;
|
|
509
516
|
|
|
510
517
|
for (var _iterator8 = _createForOfIteratorHelperLoose(columnSizes.index), _step8; !(_step8 = _iterator8()).done;) {
|
|
511
518
|
var x = _step8.value;
|
|
@@ -542,8 +549,8 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
542
549
|
var selectionActive = selx1 !== -1 && selx2 !== -1 || sely1 !== -1 && sely2 !== -1;
|
|
543
550
|
var rowSelectionActive = selx1 === -1 && selx2 === -1 && sely1 !== -1 && sely2 !== -1;
|
|
544
551
|
var colSelectionActive = selx1 !== -1 && selx2 !== -1 && sely1 === -1 && sely2 === -1;
|
|
545
|
-
var p1 = cellToAbsCoordinate(selx1, sely1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
546
|
-
var p2 = cellToAbsCoordinate(selx2, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
552
|
+
var p1 = cellToAbsCoordinate(selx1, sely1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
553
|
+
var p2 = cellToAbsCoordinate(selx2, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
547
554
|
p2.x += cellWidth(selx2);
|
|
548
555
|
p2.y += cellHeight(sely2);
|
|
549
556
|
|
|
@@ -576,118 +583,128 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
576
583
|
|
|
577
584
|
if (rowSelectionActive) {
|
|
578
585
|
var p1x = Math.max(-100, p1.x);
|
|
579
|
-
|
|
580
|
-
context.fillRect(p1x, p1y, 100000, p2.y - p1.y);
|
|
586
|
+
context.fillRect(p1x, p1.y, 100000, p2.y - p1.y);
|
|
581
587
|
} else if (colSelectionActive) {
|
|
582
|
-
var
|
|
583
|
-
|
|
584
|
-
var _p1y = Math.max(-100, p1.y);
|
|
585
|
-
|
|
586
|
-
context.fillRect(_p1x, _p1y, p2.x - p1.x, 100000);
|
|
588
|
+
var p1y = Math.max(0, p1.y);
|
|
589
|
+
context.fillRect(p1.x, p1y, p2.x - p1.x, 100000);
|
|
587
590
|
} else {
|
|
588
591
|
context.fillRect(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
|
|
589
592
|
}
|
|
590
593
|
}
|
|
591
594
|
|
|
592
|
-
|
|
593
|
-
|
|
595
|
+
if (!sheetStyle.hideRowHeaders) {
|
|
596
|
+
context.fillStyle = rowHeaderBackgroundColor;
|
|
597
|
+
context.fillRect(0, 0, sheetStyle.rowHeaderWidth, context.canvas.height);
|
|
594
598
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
599
|
+
if (selectionActive) {
|
|
600
|
+
context.fillStyle = rowHeaderSelectedBackgroundColor;
|
|
601
|
+
context.fillRect(0, p1.y, sheetStyle.rowHeaderWidth, p2.y - p1.y);
|
|
602
|
+
}
|
|
598
603
|
}
|
|
599
604
|
|
|
600
|
-
|
|
601
|
-
|
|
605
|
+
if (!sheetStyle.hideColumnHeaders) {
|
|
606
|
+
context.fillStyle = columnHeaderBackgroundColor;
|
|
607
|
+
context.fillRect(0, 0, context.canvas.width, sheetStyle.columnHeaderHeight);
|
|
602
608
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
609
|
+
if (selectionActive) {
|
|
610
|
+
context.fillStyle = columnHeaderSelectedBackgroundColor;
|
|
611
|
+
context.fillRect(p1.x, 0, p2.x - p1.x, sheetStyle.columnHeaderHeight);
|
|
612
|
+
}
|
|
606
613
|
}
|
|
607
614
|
|
|
608
615
|
context.strokeStyle = gridColor;
|
|
609
616
|
context.lineWidth = 1;
|
|
610
|
-
var startX = rowHeaderWidth;
|
|
611
|
-
var startY = columnHeaderHeight;
|
|
612
|
-
var xGridlineEnd = hideGridlines ? rowHeaderWidth : context.canvas.width;
|
|
613
|
-
var yGridlineEnd = hideGridlines ? columnHeaderHeight : context.canvas.height;
|
|
617
|
+
var startX = sheetStyle.rowHeaderWidth;
|
|
618
|
+
var startY = sheetStyle.columnHeaderHeight;
|
|
614
619
|
var first = true;
|
|
620
|
+
var yGridlineEnd = sheetStyle.hideGridlines ? sheetStyle.columnHeaderHeight : context.canvas.height;
|
|
615
621
|
|
|
616
622
|
for (var _iterator3 = _createForOfIteratorHelperLoose(columnSizes.index), _step3; !(_step3 = _iterator3()).done;) {
|
|
617
|
-
var
|
|
623
|
+
var _col = _step3.value;
|
|
618
624
|
context.beginPath();
|
|
619
625
|
context.moveTo(startX, 0);
|
|
620
626
|
|
|
621
627
|
if (first) {
|
|
622
|
-
|
|
628
|
+
if (!sheetStyle.hideRowHeaders) {
|
|
629
|
+
context.lineTo(startX, context.canvas.height);
|
|
630
|
+
}
|
|
631
|
+
|
|
623
632
|
first = false;
|
|
624
633
|
} else {
|
|
625
634
|
context.lineTo(startX, yGridlineEnd);
|
|
626
635
|
}
|
|
627
636
|
|
|
628
637
|
context.stroke();
|
|
629
|
-
startX += cellWidth(
|
|
638
|
+
startX += cellWidth(_col);
|
|
630
639
|
}
|
|
631
640
|
|
|
641
|
+
var xGridlineEnd = sheetStyle.hideGridlines ? sheetStyle.rowHeaderWidth : context.canvas.width;
|
|
632
642
|
first = true;
|
|
633
643
|
|
|
634
644
|
for (var _iterator4 = _createForOfIteratorHelperLoose(rowSizes.index), _step4; !(_step4 = _iterator4()).done;) {
|
|
635
|
-
var
|
|
645
|
+
var _row = _step4.value;
|
|
636
646
|
context.beginPath();
|
|
637
647
|
context.moveTo(0, startY);
|
|
638
648
|
|
|
639
649
|
if (first) {
|
|
640
|
-
|
|
650
|
+
if (!sheetStyle.hideColumnHeaders) {
|
|
651
|
+
context.lineTo(context.canvas.width, startY);
|
|
652
|
+
}
|
|
653
|
+
|
|
641
654
|
first = false;
|
|
642
655
|
} else {
|
|
643
656
|
context.lineTo(xGridlineEnd, startY);
|
|
644
657
|
}
|
|
645
658
|
|
|
646
659
|
context.stroke();
|
|
647
|
-
startY += cellHeight(
|
|
660
|
+
startY += cellHeight(_row);
|
|
648
661
|
}
|
|
649
662
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
var
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
663
|
+
if (!sheetStyle.hideRowHeaders) {
|
|
664
|
+
startY = sheetStyle.columnHeaderHeight;
|
|
665
|
+
context.textBaseline = 'middle';
|
|
666
|
+
context.textAlign = 'center';
|
|
667
|
+
context.font = defaultCellStyle.fontSize + 'px ' + defaultCellStyle.fontFamily;
|
|
668
|
+
context.fillStyle = rowHeaderTextColor;
|
|
669
|
+
|
|
670
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(rowSizes.index), _step5; !(_step5 = _iterator5()).done;) {
|
|
671
|
+
var row = _step5.value;
|
|
672
|
+
var cellContent = row + 1;
|
|
673
|
+
var chStyle = {};
|
|
674
|
+
|
|
675
|
+
if (rowSelectionActive && sely1 <= row && sely2 >= row) {
|
|
676
|
+
chStyle = _extends({}, chStyle, {
|
|
677
|
+
backgroundColor: rowColHeaderSelectionColor
|
|
678
|
+
});
|
|
679
|
+
}
|
|
666
680
|
|
|
667
|
-
|
|
668
|
-
|
|
681
|
+
drawCell(context, '' + cellContent, chStyle, defaultColumnHeaderStyle, 0, startY, sheetStyle.rowHeaderWidth, cellHeight(row));
|
|
682
|
+
startY += cellHeight(row);
|
|
683
|
+
}
|
|
669
684
|
}
|
|
670
685
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
686
|
+
if (!sheetStyle.hideColumnHeaders) {
|
|
687
|
+
startX = sheetStyle.rowHeaderWidth;
|
|
688
|
+
context.textBaseline = 'middle';
|
|
689
|
+
context.textAlign = 'center';
|
|
674
690
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
691
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(columnSizes.index), _step6; !(_step6 = _iterator6()).done;) {
|
|
692
|
+
var col = _step6.value;
|
|
693
|
+
var cw = cellWidth(col);
|
|
694
|
+
var ch = columnHeaders(col);
|
|
695
|
+
var chcontent = ch !== null ? ch : excelHeaderString(col + 1);
|
|
680
696
|
|
|
681
|
-
|
|
697
|
+
var _chStyle = columnHeaderStyle(col);
|
|
682
698
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
699
|
+
if (colSelectionActive && selx1 <= col && selx2 >= col) {
|
|
700
|
+
_chStyle = _extends({}, _chStyle, {
|
|
701
|
+
backgroundColor: rowColHeaderSelectionColor
|
|
702
|
+
});
|
|
703
|
+
}
|
|
688
704
|
|
|
689
|
-
|
|
690
|
-
|
|
705
|
+
drawCell(context, chcontent, _chStyle, defaultColumnHeaderStyle, startX, 0, cw, sheetStyle.columnHeaderHeight);
|
|
706
|
+
startX += cw;
|
|
707
|
+
}
|
|
691
708
|
}
|
|
692
709
|
|
|
693
710
|
if (selectionActive) {
|
|
@@ -696,17 +713,13 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
696
713
|
context.beginPath();
|
|
697
714
|
|
|
698
715
|
if (rowSelectionActive) {
|
|
699
|
-
var
|
|
700
|
-
|
|
701
|
-
var _p1y2 = Math.max(-100, p1.y);
|
|
716
|
+
var _p1x = Math.max(-100, p1.x);
|
|
702
717
|
|
|
703
|
-
context.rect(
|
|
718
|
+
context.rect(_p1x, p1.y, 100000, p2.y - p1.y);
|
|
704
719
|
} else if (colSelectionActive) {
|
|
705
|
-
var
|
|
706
|
-
|
|
707
|
-
var _p1y3 = Math.max(-100, p1.y);
|
|
720
|
+
var _p1y = Math.max(-100, p1.y);
|
|
708
721
|
|
|
709
|
-
context.rect(
|
|
722
|
+
context.rect(p1.x, _p1y, p2.x - p1.x, 100000);
|
|
710
723
|
} else {
|
|
711
724
|
context.rect(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
|
|
712
725
|
}
|
|
@@ -731,8 +744,8 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
731
744
|
ky2 = knobArea.y1;
|
|
732
745
|
}
|
|
733
746
|
|
|
734
|
-
var knobPoint1 = cellToAbsCoordinate(kx1, ky1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
735
|
-
var knobPoint2 = cellToAbsCoordinate(kx2 + 1, ky2 + 1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
747
|
+
var knobPoint1 = cellToAbsCoordinate(kx1, ky1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
748
|
+
var knobPoint2 = cellToAbsCoordinate(kx2 + 1, ky2 + 1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
736
749
|
context.strokeStyle = knobAreaBorderColor;
|
|
737
750
|
context.setLineDash([3, 3]);
|
|
738
751
|
context.lineWidth = 1;
|
|
@@ -756,11 +769,11 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
756
769
|
}
|
|
757
770
|
|
|
758
771
|
context.textBaseline = 'middle';
|
|
759
|
-
var yCoord = columnHeaderHeight;
|
|
772
|
+
var yCoord = sheetStyle.columnHeaderHeight;
|
|
760
773
|
|
|
761
774
|
for (var _iterator7 = _createForOfIteratorHelperLoose(rowSizes.index), _step7; !(_step7 = _iterator7()).done;) {
|
|
762
775
|
var _y = _step7.value;
|
|
763
|
-
var xCoord = rowHeaderWidth;
|
|
776
|
+
var xCoord = sheetStyle.rowHeaderWidth;
|
|
764
777
|
|
|
765
778
|
var _ch = cellHeight(_y);
|
|
766
779
|
|
|
@@ -785,7 +798,7 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
785
798
|
}
|
|
786
799
|
|
|
787
800
|
function Sheet(props) {
|
|
788
|
-
var _props$inputComponent;
|
|
801
|
+
var _props$sheetStyle9, _props$sheetStyle10, _props$sheetStyle11, _props$sheetStyle12, _props$sheetStyle13, _props$sheetStyle14, _props$inputComponent;
|
|
789
802
|
|
|
790
803
|
var canvasRef = React.useRef(null);
|
|
791
804
|
var overlayRef = React.useRef(null);
|
|
@@ -886,8 +899,6 @@ function Sheet(props) {
|
|
|
886
899
|
_useResizeObserver$he = _useResizeObserver.height,
|
|
887
900
|
canvasHeight = _useResizeObserver$he === void 0 ? 3000 : _useResizeObserver$he;
|
|
888
901
|
|
|
889
|
-
var freezeColumns = props.freezeColumns || 0;
|
|
890
|
-
var freezeRows = props.freezeRows || 0;
|
|
891
902
|
var cellWidth = React.useMemo(function () {
|
|
892
903
|
return createRowOrColumnPropFunction(props.cellWidth, 100);
|
|
893
904
|
}, [props.cellWidth]);
|
|
@@ -918,6 +929,20 @@ function Sheet(props) {
|
|
|
918
929
|
var cellStyle = React.useMemo(function () {
|
|
919
930
|
return createCellPropFunction(props.cellStyle, defaultCellStyle);
|
|
920
931
|
}, [props.cellStyle]);
|
|
932
|
+
var sheetStyle = React.useMemo(function () {
|
|
933
|
+
var _props$sheetStyle, _props$sheetStyle2, _props$sheetStyle3, _props$sheetStyle4, _props$sheetStyle5, _props$sheetStyle6, _props$sheetStyle7, _props$sheetStyle8;
|
|
934
|
+
|
|
935
|
+
return {
|
|
936
|
+
freezeColumns: ((_props$sheetStyle = props.sheetStyle) === null || _props$sheetStyle === void 0 ? void 0 : _props$sheetStyle.freezeColumns) || 0,
|
|
937
|
+
freezeRows: ((_props$sheetStyle2 = props.sheetStyle) === null || _props$sheetStyle2 === void 0 ? void 0 : _props$sheetStyle2.freezeRows) || 0,
|
|
938
|
+
hideColumnHeaders: ((_props$sheetStyle3 = props.sheetStyle) === null || _props$sheetStyle3 === void 0 ? void 0 : _props$sheetStyle3.hideColumnHeaders) || false,
|
|
939
|
+
hideRowHeaders: ((_props$sheetStyle4 = props.sheetStyle) === null || _props$sheetStyle4 === void 0 ? void 0 : _props$sheetStyle4.hideRowHeaders) || false,
|
|
940
|
+
hideGridlines: ((_props$sheetStyle5 = props.sheetStyle) === null || _props$sheetStyle5 === void 0 ? void 0 : _props$sheetStyle5.hideGridlines) || false,
|
|
941
|
+
columnHeaderHeight: (_props$sheetStyle6 = props.sheetStyle) !== null && _props$sheetStyle6 !== void 0 && _props$sheetStyle6.hideColumnHeaders ? 1 : kColumnHeaderHeight,
|
|
942
|
+
rowHeaderWidth: (_props$sheetStyle7 = props.sheetStyle) !== null && _props$sheetStyle7 !== void 0 && _props$sheetStyle7.hideRowHeaders ? 1 : kRowHeaderWidth,
|
|
943
|
+
hideScrollBars: ((_props$sheetStyle8 = props.sheetStyle) === null || _props$sheetStyle8 === void 0 ? void 0 : _props$sheetStyle8.hideScrollBars) || false
|
|
944
|
+
};
|
|
945
|
+
}, [(_props$sheetStyle9 = props.sheetStyle) === null || _props$sheetStyle9 === void 0 ? void 0 : _props$sheetStyle9.freezeColumns, (_props$sheetStyle10 = props.sheetStyle) === null || _props$sheetStyle10 === void 0 ? void 0 : _props$sheetStyle10.freezeRows, (_props$sheetStyle11 = props.sheetStyle) === null || _props$sheetStyle11 === void 0 ? void 0 : _props$sheetStyle11.hideColumnHeaders, (_props$sheetStyle12 = props.sheetStyle) === null || _props$sheetStyle12 === void 0 ? void 0 : _props$sheetStyle12.hideGridlines, (_props$sheetStyle13 = props.sheetStyle) === null || _props$sheetStyle13 === void 0 ? void 0 : _props$sheetStyle13.hideRowHeaders, (_props$sheetStyle14 = props.sheetStyle) === null || _props$sheetStyle14 === void 0 ? void 0 : _props$sheetStyle14.hideScrollBars]);
|
|
921
946
|
React.useEffect(function () {
|
|
922
947
|
var currEditKey = editKeys ? editKeys(editCell.x, editCell.y) : '';
|
|
923
948
|
|
|
@@ -930,11 +955,11 @@ function Sheet(props) {
|
|
|
930
955
|
}
|
|
931
956
|
}, [editKeys]);
|
|
932
957
|
var columnSizes = React.useMemo(function () {
|
|
933
|
-
return calculateRowsOrColsSizes(freezeColumns, cellWidth, rowHeaderWidth, dataOffset.x, canvasWidth);
|
|
934
|
-
}, [
|
|
958
|
+
return calculateRowsOrColsSizes(sheetStyle.freezeColumns, cellWidth, sheetStyle.rowHeaderWidth, dataOffset.x, canvasWidth);
|
|
959
|
+
}, [sheetStyle, cellWidth, dataOffset.x, canvasWidth]);
|
|
935
960
|
var rowSizes = React.useMemo(function () {
|
|
936
|
-
return calculateRowsOrColsSizes(freezeRows, cellHeight, columnHeaderHeight, dataOffset.y, canvasHeight);
|
|
937
|
-
}, [
|
|
961
|
+
return calculateRowsOrColsSizes(sheetStyle.freezeRows, cellHeight, sheetStyle.columnHeaderHeight, dataOffset.y, canvasHeight);
|
|
962
|
+
}, [sheetStyle, cellHeight, dataOffset.y, canvasHeight]);
|
|
938
963
|
|
|
939
964
|
var changeSelection = function changeSelection(x1, y1, x2, y2, scrollToP2) {
|
|
940
965
|
if (scrollToP2 === void 0) {
|
|
@@ -960,7 +985,7 @@ function Sheet(props) {
|
|
|
960
985
|
|
|
961
986
|
if (x2 !== -1 && (!columnSizes.index.includes(x2) || columnSizes.index[columnSizes.index.length - 1] === x2)) {
|
|
962
987
|
var lastVisibleColumnIndex = columnSizes.index[columnSizes.index.length - 1];
|
|
963
|
-
var firstVisibleColumnIndex = columnSizes.index[freezeColumns];
|
|
988
|
+
var firstVisibleColumnIndex = columnSizes.index[sheetStyle.freezeColumns];
|
|
964
989
|
var increment = 0;
|
|
965
990
|
|
|
966
991
|
if (x2 >= lastVisibleColumnIndex) {
|
|
@@ -969,13 +994,13 @@ function Sheet(props) {
|
|
|
969
994
|
increment = x2 - firstVisibleColumnIndex;
|
|
970
995
|
}
|
|
971
996
|
|
|
972
|
-
var newX = Math.max(dataOffset.x, freezeColumns) + increment;
|
|
997
|
+
var newX = Math.max(dataOffset.x, sheetStyle.freezeColumns) + increment;
|
|
973
998
|
newDataOffset.x = newX;
|
|
974
999
|
newScrollLeft = newX * scrollSpeed;
|
|
975
1000
|
}
|
|
976
1001
|
|
|
977
1002
|
if (y2 !== -1 && (!rowSizes.index.includes(y2) || rowSizes.index[rowSizes.index.length - 1] === y2)) {
|
|
978
|
-
var firstVisibleRowIndex = rowSizes.index[freezeRows];
|
|
1003
|
+
var firstVisibleRowIndex = rowSizes.index[sheetStyle.freezeRows];
|
|
979
1004
|
var lastVisibleRowIndex = rowSizes.index[rowSizes.index.length - 1];
|
|
980
1005
|
var _increment = 0;
|
|
981
1006
|
|
|
@@ -985,7 +1010,7 @@ function Sheet(props) {
|
|
|
985
1010
|
_increment = y2 - firstVisibleRowIndex;
|
|
986
1011
|
}
|
|
987
1012
|
|
|
988
|
-
var newY = Math.max(dataOffset.y, freezeRows) + _increment;
|
|
1013
|
+
var newY = Math.max(dataOffset.y, sheetStyle.freezeRows) + _increment;
|
|
989
1014
|
|
|
990
1015
|
newDataOffset.y = newY;
|
|
991
1016
|
newScrollTop = newY * scrollSpeed;
|
|
@@ -1044,7 +1069,7 @@ function Sheet(props) {
|
|
|
1044
1069
|
sely2 = selection.y1;
|
|
1045
1070
|
}
|
|
1046
1071
|
|
|
1047
|
-
var c = cellToAbsCoordinate(0, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1072
|
+
var c = cellToAbsCoordinate(0, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
1048
1073
|
return {
|
|
1049
1074
|
x: c.x + knobSize * 0.5,
|
|
1050
1075
|
y: c.y + cellHeight(sely2)
|
|
@@ -1058,7 +1083,7 @@ function Sheet(props) {
|
|
|
1058
1083
|
selx2 = selection.x1;
|
|
1059
1084
|
}
|
|
1060
1085
|
|
|
1061
|
-
var _c = cellToAbsCoordinate(selx2, 0, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1086
|
+
var _c = cellToAbsCoordinate(selx2, 0, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
1062
1087
|
|
|
1063
1088
|
return {
|
|
1064
1089
|
x: _c.x + cellWidth(selx2),
|
|
@@ -1079,7 +1104,7 @@ function Sheet(props) {
|
|
|
1079
1104
|
_sely = selection.y1;
|
|
1080
1105
|
}
|
|
1081
1106
|
|
|
1082
|
-
var _c2 = cellToAbsCoordinate(_selx, _sely, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1107
|
+
var _c2 = cellToAbsCoordinate(_selx, _sely, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
1083
1108
|
|
|
1084
1109
|
return {
|
|
1085
1110
|
x: _c2.x + cellWidth(_selx),
|
|
@@ -1091,7 +1116,7 @@ function Sheet(props) {
|
|
|
1091
1116
|
x: -1,
|
|
1092
1117
|
y: -1
|
|
1093
1118
|
};
|
|
1094
|
-
}, [selection, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight]);
|
|
1119
|
+
}, [selection, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle]);
|
|
1095
1120
|
var hitMap = React.useMemo(function () {
|
|
1096
1121
|
var hitM = {};
|
|
1097
1122
|
var canvas = canvasRef.current;
|
|
@@ -1101,8 +1126,8 @@ function Sheet(props) {
|
|
|
1101
1126
|
}
|
|
1102
1127
|
|
|
1103
1128
|
resizeCanvas(canvas);
|
|
1104
|
-
var yCoord = columnHeaderHeight;
|
|
1105
|
-
var xCoord = rowHeaderWidth;
|
|
1129
|
+
var yCoord = sheetStyle.columnHeaderHeight;
|
|
1130
|
+
var xCoord = sheetStyle.rowHeaderWidth;
|
|
1106
1131
|
|
|
1107
1132
|
for (var _iterator10 = _createForOfIteratorHelperLoose(columnSizes.index), _step10; !(_step10 = _iterator10()).done;) {
|
|
1108
1133
|
var x = _step10.value;
|
|
@@ -1122,7 +1147,7 @@ function Sheet(props) {
|
|
|
1122
1147
|
|
|
1123
1148
|
var w = obj.content instanceof HTMLImageElement ? obj.width || cellW : 0;
|
|
1124
1149
|
var absX1 = applyAlignment(xCoord, cellW, finalStyle, w, obj.horiozntalAlign) + obj.x;
|
|
1125
|
-
var absY1 = columnHeaderHeight * 0.5 + obj.y;
|
|
1150
|
+
var absY1 = sheetStyle.columnHeaderHeight * 0.5 + obj.y;
|
|
1126
1151
|
var absX2 = absX1 + (obj.width || 0);
|
|
1127
1152
|
var absY2 = absY1 + (obj.height || 0);
|
|
1128
1153
|
var hitTarget = {
|
|
@@ -1161,7 +1186,7 @@ function Sheet(props) {
|
|
|
1161
1186
|
|
|
1162
1187
|
for (var _iterator11 = _createForOfIteratorHelperLoose(rowSizes.index), _step11; !(_step11 = _iterator11()).done;) {
|
|
1163
1188
|
var y = _step11.value;
|
|
1164
|
-
xCoord = rowHeaderWidth;
|
|
1189
|
+
xCoord = sheetStyle.rowHeaderWidth;
|
|
1165
1190
|
|
|
1166
1191
|
for (var _iterator13 = _createForOfIteratorHelperLoose(columnSizes.index), _step13; !(_step13 = _iterator13()).done;) {
|
|
1167
1192
|
var _x2 = _step13.value;
|
|
@@ -1240,7 +1265,7 @@ function Sheet(props) {
|
|
|
1240
1265
|
}
|
|
1241
1266
|
|
|
1242
1267
|
return hitM;
|
|
1243
|
-
}, [displayData, props.cellWidth, props.cellHeight, canvasRef, columnSizes, rowSizes, dataOffset.x, dataOffset.y]);
|
|
1268
|
+
}, [displayData, props.cellWidth, props.cellHeight, canvasRef, columnSizes, rowSizes, dataOffset.x, dataOffset.y, sheetStyle]);
|
|
1244
1269
|
React.useEffect(function () {
|
|
1245
1270
|
var canvas = canvasRef.current;
|
|
1246
1271
|
|
|
@@ -1255,12 +1280,12 @@ function Sheet(props) {
|
|
|
1255
1280
|
}
|
|
1256
1281
|
|
|
1257
1282
|
var animationFrameId = window.requestAnimationFrame(function () {
|
|
1258
|
-
renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates,
|
|
1283
|
+
renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates, sheetStyle);
|
|
1259
1284
|
});
|
|
1260
1285
|
return function () {
|
|
1261
1286
|
window.cancelAnimationFrame(animationFrameId);
|
|
1262
1287
|
};
|
|
1263
|
-
}, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates,
|
|
1288
|
+
}, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates, sheetStyle]);
|
|
1264
1289
|
|
|
1265
1290
|
var setFocusToTextArea = function setFocusToTextArea() {
|
|
1266
1291
|
if (copyPasteTextAreaRef.current) {
|
|
@@ -1303,12 +1328,12 @@ function Sheet(props) {
|
|
|
1303
1328
|
var clipboardData = e.clipboardData || window.clipboardData;
|
|
1304
1329
|
var types = clipboardData.types;
|
|
1305
1330
|
|
|
1306
|
-
if (types.includes('text/
|
|
1307
|
-
var text = clipboardData.getData('text/plain');
|
|
1308
|
-
parsePastedText(text);
|
|
1309
|
-
} else if (types.includes('text/html')) {
|
|
1331
|
+
if (types.includes('text/html')) {
|
|
1310
1332
|
var pastedHtml = clipboardData.getData('text/html');
|
|
1311
1333
|
parsePastedHtml(pastedHtml);
|
|
1334
|
+
} else if (types.includes('text/plain')) {
|
|
1335
|
+
var text = clipboardData.getData('text/plain');
|
|
1336
|
+
parsePastedText(text);
|
|
1312
1337
|
}
|
|
1313
1338
|
};
|
|
1314
1339
|
|
|
@@ -1389,12 +1414,12 @@ function Sheet(props) {
|
|
|
1389
1414
|
var p = td.children[0];
|
|
1390
1415
|
|
|
1391
1416
|
if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
|
|
1392
|
-
str = p.children[0].
|
|
1417
|
+
str = p.children[0].textContent.trim();
|
|
1393
1418
|
} else {
|
|
1394
|
-
str = p.
|
|
1419
|
+
str = p.textContent.trim();
|
|
1395
1420
|
}
|
|
1396
1421
|
} else {
|
|
1397
|
-
str = td.
|
|
1422
|
+
str = td.textContent.trim();
|
|
1398
1423
|
}
|
|
1399
1424
|
|
|
1400
1425
|
str = str.replaceAll('\n', '');
|
|
@@ -1662,7 +1687,7 @@ function Sheet(props) {
|
|
|
1662
1687
|
}
|
|
1663
1688
|
}
|
|
1664
1689
|
|
|
1665
|
-
if (y < columnHeaderHeight) {
|
|
1690
|
+
if (!sheetStyle.hideColumnHeaders && y < sheetStyle.columnHeaderHeight) {
|
|
1666
1691
|
for (var colIdx = 0; colIdx < columnSizes.index.length; colIdx++) {
|
|
1667
1692
|
var start = columnSizes.start[colIdx];
|
|
1668
1693
|
var end = columnSizes.end[colIdx];
|
|
@@ -1695,7 +1720,7 @@ function Sheet(props) {
|
|
|
1695
1720
|
}
|
|
1696
1721
|
}
|
|
1697
1722
|
|
|
1698
|
-
if (x < rowHeaderWidth) {
|
|
1723
|
+
if (!sheetStyle.hideRowHeaders && x < sheetStyle.rowHeaderWidth) {
|
|
1699
1724
|
for (var rowIdx = 0; rowIdx < rowSizes.index.length; rowIdx++) {
|
|
1700
1725
|
var _start = rowSizes.start[rowIdx];
|
|
1701
1726
|
var _end = rowSizes.end[rowIdx];
|
|
@@ -1752,7 +1777,7 @@ function Sheet(props) {
|
|
|
1752
1777
|
|
|
1753
1778
|
var scrollToP2 = true;
|
|
1754
1779
|
|
|
1755
|
-
if (x < rowHeaderWidth) {
|
|
1780
|
+
if (!sheetStyle.hideRowHeaders && x < sheetStyle.rowHeaderWidth) {
|
|
1756
1781
|
scrollToP2 = false;
|
|
1757
1782
|
setRowSelectionInProgress(true);
|
|
1758
1783
|
sel1.x = -1;
|
|
@@ -1761,7 +1786,7 @@ function Sheet(props) {
|
|
|
1761
1786
|
setRowSelectionInProgress(false);
|
|
1762
1787
|
}
|
|
1763
1788
|
|
|
1764
|
-
if (y < columnHeaderHeight) {
|
|
1789
|
+
if (!sheetStyle.hideColumnHeaders && y < sheetStyle.columnHeaderHeight) {
|
|
1765
1790
|
scrollToP2 = false;
|
|
1766
1791
|
setColumnSelectionInProgress(true);
|
|
1767
1792
|
sel1.y = -1;
|
|
@@ -1953,8 +1978,8 @@ function Sheet(props) {
|
|
|
1953
1978
|
}
|
|
1954
1979
|
}
|
|
1955
1980
|
|
|
1956
|
-
if (props.onCellWidthChange && y < columnHeaderHeight) {
|
|
1957
|
-
var xx = rowHeaderWidth;
|
|
1981
|
+
if (!sheetStyle.hideColumnHeaders && props.onCellWidthChange && y < sheetStyle.columnHeaderHeight) {
|
|
1982
|
+
var xx = sheetStyle.rowHeaderWidth;
|
|
1958
1983
|
|
|
1959
1984
|
for (var _iterator21 = _createForOfIteratorHelperLoose(columnSizes.index), _step21; !(_step21 = _iterator21()).done;) {
|
|
1960
1985
|
var col = _step21.value;
|
|
@@ -1968,8 +1993,8 @@ function Sheet(props) {
|
|
|
1968
1993
|
}
|
|
1969
1994
|
}
|
|
1970
1995
|
|
|
1971
|
-
if (props.onCellHeightChange && x < rowHeaderWidth) {
|
|
1972
|
-
var yy = columnHeaderHeight;
|
|
1996
|
+
if (!sheetStyle.hideRowHeaders && props.onCellHeightChange && x < sheetStyle.rowHeaderWidth) {
|
|
1997
|
+
var yy = sheetStyle.columnHeaderHeight;
|
|
1973
1998
|
|
|
1974
1999
|
for (var _iterator22 = _createForOfIteratorHelperLoose(rowSizes.index), _step22; !(_step22 = _iterator22()).done;) {
|
|
1975
2000
|
var row = _step22.value;
|
|
@@ -2313,7 +2338,7 @@ function Sheet(props) {
|
|
|
2313
2338
|
y2 = _ref2[1];
|
|
2314
2339
|
}
|
|
2315
2340
|
|
|
2316
|
-
if (!(y > columnHeaderHeight && x > rowHeaderWidth)) {
|
|
2341
|
+
if (!(y > sheetStyle.columnHeaderHeight && x > sheetStyle.rowHeaderWidth)) {
|
|
2317
2342
|
return;
|
|
2318
2343
|
}
|
|
2319
2344
|
|
|
@@ -2341,7 +2366,7 @@ function Sheet(props) {
|
|
|
2341
2366
|
var editTextTextAlign = 'right';
|
|
2342
2367
|
|
|
2343
2368
|
if (editMode) {
|
|
2344
|
-
editTextPosition = cellToAbsCoordinate(editCell.x, editCell.y, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
2369
|
+
editTextPosition = cellToAbsCoordinate(editCell.x, editCell.y, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
2345
2370
|
var style = cellStyle(editCell.x, editCell.y);
|
|
2346
2371
|
editTextPosition.x += 1;
|
|
2347
2372
|
editTextPosition.y += 1;
|
|
@@ -2371,17 +2396,36 @@ function Sheet(props) {
|
|
|
2371
2396
|
var input = (_props$inputComponent = props.inputComponent) === null || _props$inputComponent === void 0 ? void 0 : _props$inputComponent.call(props, editCell.x, editCell.y, _extends({}, inputProps, {
|
|
2372
2397
|
onChange: setEditValue
|
|
2373
2398
|
}), commitEditingCell);
|
|
2399
|
+
var overlayDivClassName = styles.sheetscroll;
|
|
2400
|
+
var overlayDivStyles = {
|
|
2401
|
+
position: 'absolute',
|
|
2402
|
+
width: '100%',
|
|
2403
|
+
height: '100%',
|
|
2404
|
+
top: 0,
|
|
2405
|
+
left: 0,
|
|
2406
|
+
overflow: 'scroll',
|
|
2407
|
+
borderBottom: '1px solid #ddd'
|
|
2408
|
+
};
|
|
2409
|
+
var canvasStyles = {
|
|
2410
|
+
width: 'calc(100% - 14px)',
|
|
2411
|
+
height: 'calc(100% - 15px)',
|
|
2412
|
+
outline: '1px solid #ddd'
|
|
2413
|
+
};
|
|
2414
|
+
|
|
2415
|
+
if (sheetStyle.hideScrollBars) {
|
|
2416
|
+
delete canvasStyles['outline'];
|
|
2417
|
+
delete overlayDivStyles['borderBottom'];
|
|
2418
|
+
overlayDivClassName = '';
|
|
2419
|
+
canvasStyles.width = 'calc(100%)';
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2374
2422
|
return React__default.createElement("div", {
|
|
2375
2423
|
style: {
|
|
2376
2424
|
position: 'relative',
|
|
2377
2425
|
height: '100%'
|
|
2378
2426
|
}
|
|
2379
2427
|
}, React__default.createElement("canvas", {
|
|
2380
|
-
style:
|
|
2381
|
-
width: 'calc(100% - 14px)',
|
|
2382
|
-
height: 'calc(100% - 15px)',
|
|
2383
|
-
outline: '1px solid #ddd'
|
|
2384
|
-
},
|
|
2428
|
+
style: canvasStyles,
|
|
2385
2429
|
ref: canvasRef
|
|
2386
2430
|
}), React__default.createElement("div", {
|
|
2387
2431
|
ref: overlayRef,
|
|
@@ -2391,16 +2435,8 @@ function Sheet(props) {
|
|
|
2391
2435
|
onMouseLeave: onMouseLeave,
|
|
2392
2436
|
onContextMenu: onContextMenu,
|
|
2393
2437
|
onScroll: onScroll,
|
|
2394
|
-
className:
|
|
2395
|
-
style:
|
|
2396
|
-
position: 'absolute',
|
|
2397
|
-
width: '100%',
|
|
2398
|
-
height: '100%',
|
|
2399
|
-
top: 0,
|
|
2400
|
-
left: 0,
|
|
2401
|
-
overflow: 'scroll',
|
|
2402
|
-
borderBottom: '1px solid #ddd'
|
|
2403
|
-
}
|
|
2438
|
+
className: overlayDivClassName,
|
|
2439
|
+
style: overlayDivStyles
|
|
2404
2440
|
}, React__default.createElement("div", {
|
|
2405
2441
|
style: {
|
|
2406
2442
|
position: 'absolute',
|