sheet-happens 0.0.18 → 0.0.19
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 +160 -116
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +160 -116
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -32,9 +32,15 @@ export interface SheetMouseEvent extends MouseEvent {
|
|
|
32
32
|
cellX: number;
|
|
33
33
|
cellY: number;
|
|
34
34
|
}
|
|
35
|
-
export interface
|
|
35
|
+
export interface SheetStyle {
|
|
36
|
+
hideGridlines?: boolean;
|
|
37
|
+
hideColumnHeaders?: boolean;
|
|
38
|
+
hideRowHeaders?: boolean;
|
|
36
39
|
freezeColumns?: number;
|
|
37
40
|
freezeRows?: number;
|
|
41
|
+
hideScrollBars?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface SheetProps {
|
|
38
44
|
cellWidth?: RowOrColumnProperty<number>;
|
|
39
45
|
cellHeight?: RowOrColumnProperty<number>;
|
|
40
46
|
columnHeaders?: RowOrColumnProperty<CellContentType>;
|
|
@@ -45,7 +51,7 @@ export interface SheetProps {
|
|
|
45
51
|
displayData?: CellProperty<CellContentType>;
|
|
46
52
|
editData?: CellProperty<string>;
|
|
47
53
|
editKeys?: CellProperty<string>;
|
|
48
|
-
|
|
54
|
+
sheetStyle?: SheetStyle;
|
|
49
55
|
inputComponent?: (x: number, y: number, props: SheetInputProps, commitEditingCell?: () => void) => ReactElement | undefined;
|
|
50
56
|
onSelectionChanged?: (x1: number, y1: number, x2: number, y2: number) => void;
|
|
51
57
|
onRightClick?: (e: SheetMouseEvent) => void;
|
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
|
|
|
@@ -589,105 +596,119 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
589
596
|
}
|
|
590
597
|
}
|
|
591
598
|
|
|
592
|
-
|
|
593
|
-
|
|
599
|
+
if (!sheetStyle.hideRowHeaders) {
|
|
600
|
+
context.fillStyle = rowHeaderBackgroundColor;
|
|
601
|
+
context.fillRect(0, 0, sheetStyle.rowHeaderWidth, context.canvas.height);
|
|
594
602
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
603
|
+
if (selectionActive) {
|
|
604
|
+
context.fillStyle = rowHeaderSelectedBackgroundColor;
|
|
605
|
+
context.fillRect(0, p1.y, sheetStyle.rowHeaderWidth, p2.y - p1.y);
|
|
606
|
+
}
|
|
598
607
|
}
|
|
599
608
|
|
|
600
|
-
|
|
601
|
-
|
|
609
|
+
if (!sheetStyle.hideColumnHeaders) {
|
|
610
|
+
context.fillStyle = columnHeaderBackgroundColor;
|
|
611
|
+
context.fillRect(0, 0, context.canvas.width, sheetStyle.columnHeaderHeight);
|
|
602
612
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
613
|
+
if (selectionActive) {
|
|
614
|
+
context.fillStyle = columnHeaderSelectedBackgroundColor;
|
|
615
|
+
context.fillRect(p1.x, 0, p2.x - p1.x, sheetStyle.columnHeaderHeight);
|
|
616
|
+
}
|
|
606
617
|
}
|
|
607
618
|
|
|
608
619
|
context.strokeStyle = gridColor;
|
|
609
620
|
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;
|
|
621
|
+
var startX = sheetStyle.rowHeaderWidth;
|
|
622
|
+
var startY = sheetStyle.columnHeaderHeight;
|
|
614
623
|
var first = true;
|
|
624
|
+
var yGridlineEnd = sheetStyle.hideGridlines ? sheetStyle.columnHeaderHeight : context.canvas.height;
|
|
615
625
|
|
|
616
626
|
for (var _iterator3 = _createForOfIteratorHelperLoose(columnSizes.index), _step3; !(_step3 = _iterator3()).done;) {
|
|
617
|
-
var
|
|
627
|
+
var _col = _step3.value;
|
|
618
628
|
context.beginPath();
|
|
619
629
|
context.moveTo(startX, 0);
|
|
620
630
|
|
|
621
631
|
if (first) {
|
|
622
|
-
|
|
632
|
+
if (!sheetStyle.hideRowHeaders) {
|
|
633
|
+
context.lineTo(startX, context.canvas.height);
|
|
634
|
+
}
|
|
635
|
+
|
|
623
636
|
first = false;
|
|
624
637
|
} else {
|
|
625
638
|
context.lineTo(startX, yGridlineEnd);
|
|
626
639
|
}
|
|
627
640
|
|
|
628
641
|
context.stroke();
|
|
629
|
-
startX += cellWidth(
|
|
642
|
+
startX += cellWidth(_col);
|
|
630
643
|
}
|
|
631
644
|
|
|
645
|
+
var xGridlineEnd = sheetStyle.hideGridlines ? sheetStyle.rowHeaderWidth : context.canvas.width;
|
|
632
646
|
first = true;
|
|
633
647
|
|
|
634
648
|
for (var _iterator4 = _createForOfIteratorHelperLoose(rowSizes.index), _step4; !(_step4 = _iterator4()).done;) {
|
|
635
|
-
var
|
|
649
|
+
var _row = _step4.value;
|
|
636
650
|
context.beginPath();
|
|
637
651
|
context.moveTo(0, startY);
|
|
638
652
|
|
|
639
653
|
if (first) {
|
|
640
|
-
|
|
654
|
+
if (!sheetStyle.hideColumnHeaders) {
|
|
655
|
+
context.lineTo(context.canvas.width, startY);
|
|
656
|
+
}
|
|
657
|
+
|
|
641
658
|
first = false;
|
|
642
659
|
} else {
|
|
643
660
|
context.lineTo(xGridlineEnd, startY);
|
|
644
661
|
}
|
|
645
662
|
|
|
646
663
|
context.stroke();
|
|
647
|
-
startY += cellHeight(
|
|
664
|
+
startY += cellHeight(_row);
|
|
648
665
|
}
|
|
649
666
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
var
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
667
|
+
if (!sheetStyle.hideRowHeaders) {
|
|
668
|
+
startY = sheetStyle.columnHeaderHeight;
|
|
669
|
+
context.textBaseline = 'middle';
|
|
670
|
+
context.textAlign = 'center';
|
|
671
|
+
context.font = defaultCellStyle.fontSize + 'px ' + defaultCellStyle.fontFamily;
|
|
672
|
+
context.fillStyle = rowHeaderTextColor;
|
|
673
|
+
|
|
674
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(rowSizes.index), _step5; !(_step5 = _iterator5()).done;) {
|
|
675
|
+
var row = _step5.value;
|
|
676
|
+
var cellContent = row + 1;
|
|
677
|
+
var chStyle = {};
|
|
678
|
+
|
|
679
|
+
if (rowSelectionActive && sely1 <= row && sely2 >= row) {
|
|
680
|
+
chStyle = _extends({}, chStyle, {
|
|
681
|
+
backgroundColor: rowColHeaderSelectionColor
|
|
682
|
+
});
|
|
683
|
+
}
|
|
666
684
|
|
|
667
|
-
|
|
668
|
-
|
|
685
|
+
drawCell(context, '' + cellContent, chStyle, defaultColumnHeaderStyle, 0, startY, sheetStyle.rowHeaderWidth, cellHeight(row));
|
|
686
|
+
startY += cellHeight(row);
|
|
687
|
+
}
|
|
669
688
|
}
|
|
670
689
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
690
|
+
if (!sheetStyle.hideColumnHeaders) {
|
|
691
|
+
startX = sheetStyle.rowHeaderWidth;
|
|
692
|
+
context.textBaseline = 'middle';
|
|
693
|
+
context.textAlign = 'center';
|
|
674
694
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
695
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(columnSizes.index), _step6; !(_step6 = _iterator6()).done;) {
|
|
696
|
+
var col = _step6.value;
|
|
697
|
+
var cw = cellWidth(col);
|
|
698
|
+
var ch = columnHeaders(col);
|
|
699
|
+
var chcontent = ch !== null ? ch : excelHeaderString(col + 1);
|
|
680
700
|
|
|
681
|
-
|
|
701
|
+
var _chStyle = columnHeaderStyle(col);
|
|
682
702
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
703
|
+
if (colSelectionActive && selx1 <= col && selx2 >= col) {
|
|
704
|
+
_chStyle = _extends({}, _chStyle, {
|
|
705
|
+
backgroundColor: rowColHeaderSelectionColor
|
|
706
|
+
});
|
|
707
|
+
}
|
|
688
708
|
|
|
689
|
-
|
|
690
|
-
|
|
709
|
+
drawCell(context, chcontent, _chStyle, defaultColumnHeaderStyle, startX, 0, cw, sheetStyle.columnHeaderHeight);
|
|
710
|
+
startX += cw;
|
|
711
|
+
}
|
|
691
712
|
}
|
|
692
713
|
|
|
693
714
|
if (selectionActive) {
|
|
@@ -731,8 +752,8 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
731
752
|
ky2 = knobArea.y1;
|
|
732
753
|
}
|
|
733
754
|
|
|
734
|
-
var knobPoint1 = cellToAbsCoordinate(kx1, ky1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
735
|
-
var knobPoint2 = cellToAbsCoordinate(kx2 + 1, ky2 + 1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
755
|
+
var knobPoint1 = cellToAbsCoordinate(kx1, ky1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
756
|
+
var knobPoint2 = cellToAbsCoordinate(kx2 + 1, ky2 + 1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
736
757
|
context.strokeStyle = knobAreaBorderColor;
|
|
737
758
|
context.setLineDash([3, 3]);
|
|
738
759
|
context.lineWidth = 1;
|
|
@@ -756,11 +777,11 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
756
777
|
}
|
|
757
778
|
|
|
758
779
|
context.textBaseline = 'middle';
|
|
759
|
-
var yCoord = columnHeaderHeight;
|
|
780
|
+
var yCoord = sheetStyle.columnHeaderHeight;
|
|
760
781
|
|
|
761
782
|
for (var _iterator7 = _createForOfIteratorHelperLoose(rowSizes.index), _step7; !(_step7 = _iterator7()).done;) {
|
|
762
783
|
var _y = _step7.value;
|
|
763
|
-
var xCoord = rowHeaderWidth;
|
|
784
|
+
var xCoord = sheetStyle.rowHeaderWidth;
|
|
764
785
|
|
|
765
786
|
var _ch = cellHeight(_y);
|
|
766
787
|
|
|
@@ -785,7 +806,7 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
785
806
|
}
|
|
786
807
|
|
|
787
808
|
function Sheet(props) {
|
|
788
|
-
var _props$inputComponent;
|
|
809
|
+
var _props$sheetStyle9, _props$sheetStyle10, _props$sheetStyle11, _props$sheetStyle12, _props$sheetStyle13, _props$sheetStyle14, _props$inputComponent;
|
|
789
810
|
|
|
790
811
|
var canvasRef = React.useRef(null);
|
|
791
812
|
var overlayRef = React.useRef(null);
|
|
@@ -886,8 +907,6 @@ function Sheet(props) {
|
|
|
886
907
|
_useResizeObserver$he = _useResizeObserver.height,
|
|
887
908
|
canvasHeight = _useResizeObserver$he === void 0 ? 3000 : _useResizeObserver$he;
|
|
888
909
|
|
|
889
|
-
var freezeColumns = props.freezeColumns || 0;
|
|
890
|
-
var freezeRows = props.freezeRows || 0;
|
|
891
910
|
var cellWidth = React.useMemo(function () {
|
|
892
911
|
return createRowOrColumnPropFunction(props.cellWidth, 100);
|
|
893
912
|
}, [props.cellWidth]);
|
|
@@ -918,6 +937,20 @@ function Sheet(props) {
|
|
|
918
937
|
var cellStyle = React.useMemo(function () {
|
|
919
938
|
return createCellPropFunction(props.cellStyle, defaultCellStyle);
|
|
920
939
|
}, [props.cellStyle]);
|
|
940
|
+
var sheetStyle = React.useMemo(function () {
|
|
941
|
+
var _props$sheetStyle, _props$sheetStyle2, _props$sheetStyle3, _props$sheetStyle4, _props$sheetStyle5, _props$sheetStyle6, _props$sheetStyle7, _props$sheetStyle8;
|
|
942
|
+
|
|
943
|
+
return {
|
|
944
|
+
freezeColumns: ((_props$sheetStyle = props.sheetStyle) === null || _props$sheetStyle === void 0 ? void 0 : _props$sheetStyle.freezeColumns) || 0,
|
|
945
|
+
freezeRows: ((_props$sheetStyle2 = props.sheetStyle) === null || _props$sheetStyle2 === void 0 ? void 0 : _props$sheetStyle2.freezeRows) || 0,
|
|
946
|
+
hideColumnHeaders: ((_props$sheetStyle3 = props.sheetStyle) === null || _props$sheetStyle3 === void 0 ? void 0 : _props$sheetStyle3.hideColumnHeaders) || false,
|
|
947
|
+
hideRowHeaders: ((_props$sheetStyle4 = props.sheetStyle) === null || _props$sheetStyle4 === void 0 ? void 0 : _props$sheetStyle4.hideRowHeaders) || false,
|
|
948
|
+
hideGridlines: ((_props$sheetStyle5 = props.sheetStyle) === null || _props$sheetStyle5 === void 0 ? void 0 : _props$sheetStyle5.hideGridlines) || false,
|
|
949
|
+
columnHeaderHeight: (_props$sheetStyle6 = props.sheetStyle) !== null && _props$sheetStyle6 !== void 0 && _props$sheetStyle6.hideColumnHeaders ? 1 : kColumnHeaderHeight,
|
|
950
|
+
rowHeaderWidth: (_props$sheetStyle7 = props.sheetStyle) !== null && _props$sheetStyle7 !== void 0 && _props$sheetStyle7.hideRowHeaders ? 1 : kRowHeaderWidth,
|
|
951
|
+
hideScrollBars: ((_props$sheetStyle8 = props.sheetStyle) === null || _props$sheetStyle8 === void 0 ? void 0 : _props$sheetStyle8.hideScrollBars) || false
|
|
952
|
+
};
|
|
953
|
+
}, [(_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
954
|
React.useEffect(function () {
|
|
922
955
|
var currEditKey = editKeys ? editKeys(editCell.x, editCell.y) : '';
|
|
923
956
|
|
|
@@ -930,11 +963,11 @@ function Sheet(props) {
|
|
|
930
963
|
}
|
|
931
964
|
}, [editKeys]);
|
|
932
965
|
var columnSizes = React.useMemo(function () {
|
|
933
|
-
return calculateRowsOrColsSizes(freezeColumns, cellWidth, rowHeaderWidth, dataOffset.x, canvasWidth);
|
|
934
|
-
}, [
|
|
966
|
+
return calculateRowsOrColsSizes(sheetStyle.freezeColumns, cellWidth, sheetStyle.rowHeaderWidth, dataOffset.x, canvasWidth);
|
|
967
|
+
}, [sheetStyle, cellWidth, dataOffset.x, canvasWidth]);
|
|
935
968
|
var rowSizes = React.useMemo(function () {
|
|
936
|
-
return calculateRowsOrColsSizes(freezeRows, cellHeight, columnHeaderHeight, dataOffset.y, canvasHeight);
|
|
937
|
-
}, [
|
|
969
|
+
return calculateRowsOrColsSizes(sheetStyle.freezeRows, cellHeight, sheetStyle.columnHeaderHeight, dataOffset.y, canvasHeight);
|
|
970
|
+
}, [sheetStyle, cellHeight, dataOffset.y, canvasHeight]);
|
|
938
971
|
|
|
939
972
|
var changeSelection = function changeSelection(x1, y1, x2, y2, scrollToP2) {
|
|
940
973
|
if (scrollToP2 === void 0) {
|
|
@@ -960,7 +993,7 @@ function Sheet(props) {
|
|
|
960
993
|
|
|
961
994
|
if (x2 !== -1 && (!columnSizes.index.includes(x2) || columnSizes.index[columnSizes.index.length - 1] === x2)) {
|
|
962
995
|
var lastVisibleColumnIndex = columnSizes.index[columnSizes.index.length - 1];
|
|
963
|
-
var firstVisibleColumnIndex = columnSizes.index[freezeColumns];
|
|
996
|
+
var firstVisibleColumnIndex = columnSizes.index[sheetStyle.freezeColumns];
|
|
964
997
|
var increment = 0;
|
|
965
998
|
|
|
966
999
|
if (x2 >= lastVisibleColumnIndex) {
|
|
@@ -969,13 +1002,13 @@ function Sheet(props) {
|
|
|
969
1002
|
increment = x2 - firstVisibleColumnIndex;
|
|
970
1003
|
}
|
|
971
1004
|
|
|
972
|
-
var newX = Math.max(dataOffset.x, freezeColumns) + increment;
|
|
1005
|
+
var newX = Math.max(dataOffset.x, sheetStyle.freezeColumns) + increment;
|
|
973
1006
|
newDataOffset.x = newX;
|
|
974
1007
|
newScrollLeft = newX * scrollSpeed;
|
|
975
1008
|
}
|
|
976
1009
|
|
|
977
1010
|
if (y2 !== -1 && (!rowSizes.index.includes(y2) || rowSizes.index[rowSizes.index.length - 1] === y2)) {
|
|
978
|
-
var firstVisibleRowIndex = rowSizes.index[freezeRows];
|
|
1011
|
+
var firstVisibleRowIndex = rowSizes.index[sheetStyle.freezeRows];
|
|
979
1012
|
var lastVisibleRowIndex = rowSizes.index[rowSizes.index.length - 1];
|
|
980
1013
|
var _increment = 0;
|
|
981
1014
|
|
|
@@ -985,7 +1018,7 @@ function Sheet(props) {
|
|
|
985
1018
|
_increment = y2 - firstVisibleRowIndex;
|
|
986
1019
|
}
|
|
987
1020
|
|
|
988
|
-
var newY = Math.max(dataOffset.y, freezeRows) + _increment;
|
|
1021
|
+
var newY = Math.max(dataOffset.y, sheetStyle.freezeRows) + _increment;
|
|
989
1022
|
|
|
990
1023
|
newDataOffset.y = newY;
|
|
991
1024
|
newScrollTop = newY * scrollSpeed;
|
|
@@ -1044,7 +1077,7 @@ function Sheet(props) {
|
|
|
1044
1077
|
sely2 = selection.y1;
|
|
1045
1078
|
}
|
|
1046
1079
|
|
|
1047
|
-
var c = cellToAbsCoordinate(0, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1080
|
+
var c = cellToAbsCoordinate(0, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
1048
1081
|
return {
|
|
1049
1082
|
x: c.x + knobSize * 0.5,
|
|
1050
1083
|
y: c.y + cellHeight(sely2)
|
|
@@ -1058,7 +1091,7 @@ function Sheet(props) {
|
|
|
1058
1091
|
selx2 = selection.x1;
|
|
1059
1092
|
}
|
|
1060
1093
|
|
|
1061
|
-
var _c = cellToAbsCoordinate(selx2, 0, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1094
|
+
var _c = cellToAbsCoordinate(selx2, 0, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
1062
1095
|
|
|
1063
1096
|
return {
|
|
1064
1097
|
x: _c.x + cellWidth(selx2),
|
|
@@ -1079,7 +1112,7 @@ function Sheet(props) {
|
|
|
1079
1112
|
_sely = selection.y1;
|
|
1080
1113
|
}
|
|
1081
1114
|
|
|
1082
|
-
var _c2 = cellToAbsCoordinate(_selx, _sely, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1115
|
+
var _c2 = cellToAbsCoordinate(_selx, _sely, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
1083
1116
|
|
|
1084
1117
|
return {
|
|
1085
1118
|
x: _c2.x + cellWidth(_selx),
|
|
@@ -1091,7 +1124,7 @@ function Sheet(props) {
|
|
|
1091
1124
|
x: -1,
|
|
1092
1125
|
y: -1
|
|
1093
1126
|
};
|
|
1094
|
-
}, [selection, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight]);
|
|
1127
|
+
}, [selection, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle]);
|
|
1095
1128
|
var hitMap = React.useMemo(function () {
|
|
1096
1129
|
var hitM = {};
|
|
1097
1130
|
var canvas = canvasRef.current;
|
|
@@ -1101,8 +1134,8 @@ function Sheet(props) {
|
|
|
1101
1134
|
}
|
|
1102
1135
|
|
|
1103
1136
|
resizeCanvas(canvas);
|
|
1104
|
-
var yCoord = columnHeaderHeight;
|
|
1105
|
-
var xCoord = rowHeaderWidth;
|
|
1137
|
+
var yCoord = sheetStyle.columnHeaderHeight;
|
|
1138
|
+
var xCoord = sheetStyle.rowHeaderWidth;
|
|
1106
1139
|
|
|
1107
1140
|
for (var _iterator10 = _createForOfIteratorHelperLoose(columnSizes.index), _step10; !(_step10 = _iterator10()).done;) {
|
|
1108
1141
|
var x = _step10.value;
|
|
@@ -1122,7 +1155,7 @@ function Sheet(props) {
|
|
|
1122
1155
|
|
|
1123
1156
|
var w = obj.content instanceof HTMLImageElement ? obj.width || cellW : 0;
|
|
1124
1157
|
var absX1 = applyAlignment(xCoord, cellW, finalStyle, w, obj.horiozntalAlign) + obj.x;
|
|
1125
|
-
var absY1 = columnHeaderHeight * 0.5 + obj.y;
|
|
1158
|
+
var absY1 = sheetStyle.columnHeaderHeight * 0.5 + obj.y;
|
|
1126
1159
|
var absX2 = absX1 + (obj.width || 0);
|
|
1127
1160
|
var absY2 = absY1 + (obj.height || 0);
|
|
1128
1161
|
var hitTarget = {
|
|
@@ -1161,7 +1194,7 @@ function Sheet(props) {
|
|
|
1161
1194
|
|
|
1162
1195
|
for (var _iterator11 = _createForOfIteratorHelperLoose(rowSizes.index), _step11; !(_step11 = _iterator11()).done;) {
|
|
1163
1196
|
var y = _step11.value;
|
|
1164
|
-
xCoord = rowHeaderWidth;
|
|
1197
|
+
xCoord = sheetStyle.rowHeaderWidth;
|
|
1165
1198
|
|
|
1166
1199
|
for (var _iterator13 = _createForOfIteratorHelperLoose(columnSizes.index), _step13; !(_step13 = _iterator13()).done;) {
|
|
1167
1200
|
var _x2 = _step13.value;
|
|
@@ -1240,7 +1273,7 @@ function Sheet(props) {
|
|
|
1240
1273
|
}
|
|
1241
1274
|
|
|
1242
1275
|
return hitM;
|
|
1243
|
-
}, [displayData, props.cellWidth, props.cellHeight, canvasRef, columnSizes, rowSizes, dataOffset.x, dataOffset.y]);
|
|
1276
|
+
}, [displayData, props.cellWidth, props.cellHeight, canvasRef, columnSizes, rowSizes, dataOffset.x, dataOffset.y, sheetStyle]);
|
|
1244
1277
|
React.useEffect(function () {
|
|
1245
1278
|
var canvas = canvasRef.current;
|
|
1246
1279
|
|
|
@@ -1255,12 +1288,12 @@ function Sheet(props) {
|
|
|
1255
1288
|
}
|
|
1256
1289
|
|
|
1257
1290
|
var animationFrameId = window.requestAnimationFrame(function () {
|
|
1258
|
-
renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates,
|
|
1291
|
+
renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates, sheetStyle);
|
|
1259
1292
|
});
|
|
1260
1293
|
return function () {
|
|
1261
1294
|
window.cancelAnimationFrame(animationFrameId);
|
|
1262
1295
|
};
|
|
1263
|
-
}, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates,
|
|
1296
|
+
}, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates, sheetStyle]);
|
|
1264
1297
|
|
|
1265
1298
|
var setFocusToTextArea = function setFocusToTextArea() {
|
|
1266
1299
|
if (copyPasteTextAreaRef.current) {
|
|
@@ -1662,7 +1695,7 @@ function Sheet(props) {
|
|
|
1662
1695
|
}
|
|
1663
1696
|
}
|
|
1664
1697
|
|
|
1665
|
-
if (y < columnHeaderHeight) {
|
|
1698
|
+
if (!sheetStyle.hideColumnHeaders && y < sheetStyle.columnHeaderHeight) {
|
|
1666
1699
|
for (var colIdx = 0; colIdx < columnSizes.index.length; colIdx++) {
|
|
1667
1700
|
var start = columnSizes.start[colIdx];
|
|
1668
1701
|
var end = columnSizes.end[colIdx];
|
|
@@ -1695,7 +1728,7 @@ function Sheet(props) {
|
|
|
1695
1728
|
}
|
|
1696
1729
|
}
|
|
1697
1730
|
|
|
1698
|
-
if (x < rowHeaderWidth) {
|
|
1731
|
+
if (!sheetStyle.hideRowHeaders && x < sheetStyle.rowHeaderWidth) {
|
|
1699
1732
|
for (var rowIdx = 0; rowIdx < rowSizes.index.length; rowIdx++) {
|
|
1700
1733
|
var _start = rowSizes.start[rowIdx];
|
|
1701
1734
|
var _end = rowSizes.end[rowIdx];
|
|
@@ -1752,7 +1785,7 @@ function Sheet(props) {
|
|
|
1752
1785
|
|
|
1753
1786
|
var scrollToP2 = true;
|
|
1754
1787
|
|
|
1755
|
-
if (x < rowHeaderWidth) {
|
|
1788
|
+
if (!sheetStyle.hideRowHeaders && x < sheetStyle.rowHeaderWidth) {
|
|
1756
1789
|
scrollToP2 = false;
|
|
1757
1790
|
setRowSelectionInProgress(true);
|
|
1758
1791
|
sel1.x = -1;
|
|
@@ -1761,7 +1794,7 @@ function Sheet(props) {
|
|
|
1761
1794
|
setRowSelectionInProgress(false);
|
|
1762
1795
|
}
|
|
1763
1796
|
|
|
1764
|
-
if (y < columnHeaderHeight) {
|
|
1797
|
+
if (!sheetStyle.hideColumnHeaders && y < sheetStyle.columnHeaderHeight) {
|
|
1765
1798
|
scrollToP2 = false;
|
|
1766
1799
|
setColumnSelectionInProgress(true);
|
|
1767
1800
|
sel1.y = -1;
|
|
@@ -1953,8 +1986,8 @@ function Sheet(props) {
|
|
|
1953
1986
|
}
|
|
1954
1987
|
}
|
|
1955
1988
|
|
|
1956
|
-
if (props.onCellWidthChange && y < columnHeaderHeight) {
|
|
1957
|
-
var xx = rowHeaderWidth;
|
|
1989
|
+
if (!sheetStyle.hideColumnHeaders && props.onCellWidthChange && y < sheetStyle.columnHeaderHeight) {
|
|
1990
|
+
var xx = sheetStyle.rowHeaderWidth;
|
|
1958
1991
|
|
|
1959
1992
|
for (var _iterator21 = _createForOfIteratorHelperLoose(columnSizes.index), _step21; !(_step21 = _iterator21()).done;) {
|
|
1960
1993
|
var col = _step21.value;
|
|
@@ -1968,8 +2001,8 @@ function Sheet(props) {
|
|
|
1968
2001
|
}
|
|
1969
2002
|
}
|
|
1970
2003
|
|
|
1971
|
-
if (props.onCellHeightChange && x < rowHeaderWidth) {
|
|
1972
|
-
var yy = columnHeaderHeight;
|
|
2004
|
+
if (!sheetStyle.hideRowHeaders && props.onCellHeightChange && x < sheetStyle.rowHeaderWidth) {
|
|
2005
|
+
var yy = sheetStyle.columnHeaderHeight;
|
|
1973
2006
|
|
|
1974
2007
|
for (var _iterator22 = _createForOfIteratorHelperLoose(rowSizes.index), _step22; !(_step22 = _iterator22()).done;) {
|
|
1975
2008
|
var row = _step22.value;
|
|
@@ -2313,7 +2346,7 @@ function Sheet(props) {
|
|
|
2313
2346
|
y2 = _ref2[1];
|
|
2314
2347
|
}
|
|
2315
2348
|
|
|
2316
|
-
if (!(y > columnHeaderHeight && x > rowHeaderWidth)) {
|
|
2349
|
+
if (!(y > sheetStyle.columnHeaderHeight && x > sheetStyle.rowHeaderWidth)) {
|
|
2317
2350
|
return;
|
|
2318
2351
|
}
|
|
2319
2352
|
|
|
@@ -2341,7 +2374,7 @@ function Sheet(props) {
|
|
|
2341
2374
|
var editTextTextAlign = 'right';
|
|
2342
2375
|
|
|
2343
2376
|
if (editMode) {
|
|
2344
|
-
editTextPosition = cellToAbsCoordinate(editCell.x, editCell.y, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
2377
|
+
editTextPosition = cellToAbsCoordinate(editCell.x, editCell.y, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight, sheetStyle);
|
|
2345
2378
|
var style = cellStyle(editCell.x, editCell.y);
|
|
2346
2379
|
editTextPosition.x += 1;
|
|
2347
2380
|
editTextPosition.y += 1;
|
|
@@ -2371,17 +2404,36 @@ function Sheet(props) {
|
|
|
2371
2404
|
var input = (_props$inputComponent = props.inputComponent) === null || _props$inputComponent === void 0 ? void 0 : _props$inputComponent.call(props, editCell.x, editCell.y, _extends({}, inputProps, {
|
|
2372
2405
|
onChange: setEditValue
|
|
2373
2406
|
}), commitEditingCell);
|
|
2407
|
+
var overlayDivClassName = styles.sheetscroll;
|
|
2408
|
+
var overlayDivStyles = {
|
|
2409
|
+
position: 'absolute',
|
|
2410
|
+
width: '100%',
|
|
2411
|
+
height: '100%',
|
|
2412
|
+
top: 0,
|
|
2413
|
+
left: 0,
|
|
2414
|
+
overflow: 'scroll',
|
|
2415
|
+
borderBottom: '1px solid #ddd'
|
|
2416
|
+
};
|
|
2417
|
+
var canvasStyles = {
|
|
2418
|
+
width: 'calc(100% - 14px)',
|
|
2419
|
+
height: 'calc(100% - 15px)',
|
|
2420
|
+
outline: '1px solid #ddd'
|
|
2421
|
+
};
|
|
2422
|
+
|
|
2423
|
+
if (sheetStyle.hideScrollBars) {
|
|
2424
|
+
delete canvasStyles['outline'];
|
|
2425
|
+
delete overlayDivStyles['borderBottom'];
|
|
2426
|
+
overlayDivClassName = '';
|
|
2427
|
+
canvasStyles.width = 'calc(100%)';
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2374
2430
|
return React__default.createElement("div", {
|
|
2375
2431
|
style: {
|
|
2376
2432
|
position: 'relative',
|
|
2377
2433
|
height: '100%'
|
|
2378
2434
|
}
|
|
2379
2435
|
}, React__default.createElement("canvas", {
|
|
2380
|
-
style:
|
|
2381
|
-
width: 'calc(100% - 14px)',
|
|
2382
|
-
height: 'calc(100% - 15px)',
|
|
2383
|
-
outline: '1px solid #ddd'
|
|
2384
|
-
},
|
|
2436
|
+
style: canvasStyles,
|
|
2385
2437
|
ref: canvasRef
|
|
2386
2438
|
}), React__default.createElement("div", {
|
|
2387
2439
|
ref: overlayRef,
|
|
@@ -2391,16 +2443,8 @@ function Sheet(props) {
|
|
|
2391
2443
|
onMouseLeave: onMouseLeave,
|
|
2392
2444
|
onContextMenu: onContextMenu,
|
|
2393
2445
|
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
|
-
}
|
|
2446
|
+
className: overlayDivClassName,
|
|
2447
|
+
style: overlayDivStyles
|
|
2404
2448
|
}, React__default.createElement("div", {
|
|
2405
2449
|
style: {
|
|
2406
2450
|
position: 'absolute',
|