sheet-happens 0.0.13 → 0.0.15
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 +2 -2
- package/dist/index.js +386 -58
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +386 -58
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -84,6 +84,8 @@ var scrollSpeed = 30;
|
|
|
84
84
|
var resizeColumnRowMouseThreshold = 4;
|
|
85
85
|
var minimumColumnWidth = 50;
|
|
86
86
|
var minimumRowHeight = 22;
|
|
87
|
+
var rowColHeaderSelectionColor = '#AAAAAA';
|
|
88
|
+
var maxSearchableRowOrCol = 65536;
|
|
87
89
|
var defaultCellStyle = {
|
|
88
90
|
textAlign: 'left',
|
|
89
91
|
fontSize: 13,
|
|
@@ -374,7 +376,124 @@ function cellToAbsCoordinate(cellX, cellY, rowSizes, columnSizes, dataOffset, ce
|
|
|
374
376
|
};
|
|
375
377
|
}
|
|
376
378
|
|
|
377
|
-
function
|
|
379
|
+
function findApproxMaxEditDataIndex(editData) {
|
|
380
|
+
var x = 0;
|
|
381
|
+
var y = 0;
|
|
382
|
+
var howManyEmpty = 0;
|
|
383
|
+
var growthIncrement = 10;
|
|
384
|
+
var growthIncrementFactor = 1.5;
|
|
385
|
+
|
|
386
|
+
while (howManyEmpty < 4) {
|
|
387
|
+
var allEmpty = true;
|
|
388
|
+
|
|
389
|
+
for (var yy = 0; yy < 10; yy++) {
|
|
390
|
+
var data = editData(x, yy);
|
|
391
|
+
|
|
392
|
+
if (data !== null && data !== undefined && data !== '') {
|
|
393
|
+
allEmpty = false;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (allEmpty) {
|
|
399
|
+
howManyEmpty += 1;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
x += growthIncrement;
|
|
403
|
+
growthIncrement = Math.floor(growthIncrement * growthIncrementFactor);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
howManyEmpty = 0;
|
|
407
|
+
growthIncrement = 10;
|
|
408
|
+
growthIncrementFactor = 1.5;
|
|
409
|
+
|
|
410
|
+
while (howManyEmpty < 4) {
|
|
411
|
+
var _allEmpty = true;
|
|
412
|
+
|
|
413
|
+
for (var xx = 0; xx < 10; xx++) {
|
|
414
|
+
var _data = editData(xx, y);
|
|
415
|
+
|
|
416
|
+
if (_data !== null && _data !== undefined && _data !== '') {
|
|
417
|
+
_allEmpty = false;
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (_allEmpty) {
|
|
423
|
+
howManyEmpty += 1;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
y += growthIncrement;
|
|
427
|
+
growthIncrement = Math.floor(growthIncrement * growthIncrementFactor);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return {
|
|
431
|
+
x: x,
|
|
432
|
+
y: y
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function findInDisplayData(displayData, start, direction) {
|
|
437
|
+
var i = _extends({}, start);
|
|
438
|
+
|
|
439
|
+
var increment = {
|
|
440
|
+
x: 0,
|
|
441
|
+
y: 0
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
if (direction === 'up') {
|
|
445
|
+
increment.y = -1;
|
|
446
|
+
} else if (direction === 'down') {
|
|
447
|
+
increment.y = 1;
|
|
448
|
+
} else if (direction === 'left') {
|
|
449
|
+
increment.x = -1;
|
|
450
|
+
} else if (direction === 'right') {
|
|
451
|
+
increment.x = 1;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
var max = {
|
|
455
|
+
x: maxSearchableRowOrCol,
|
|
456
|
+
y: maxSearchableRowOrCol
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
if (i.x > max.x) {
|
|
460
|
+
i.x = max.x;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (i.y > max.y) {
|
|
464
|
+
i.y = max.y;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
var first = displayData(i.x + increment.x, i.y + increment.y);
|
|
468
|
+
var firstFilled = first !== '' && first !== null && first !== undefined;
|
|
469
|
+
|
|
470
|
+
if (!firstFilled) {
|
|
471
|
+
i.x += increment.x;
|
|
472
|
+
i.y += increment.y;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
while (i.x <= max.x && i.y <= max.y && i.x >= 0 && i.y >= 0) {
|
|
476
|
+
var data = displayData(i.x, i.y);
|
|
477
|
+
|
|
478
|
+
if (firstFilled && (data === '' || data === null || data === undefined)) {
|
|
479
|
+
return {
|
|
480
|
+
x: i.x - increment.x,
|
|
481
|
+
y: i.y - increment.y
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (!firstFilled && data !== '' && data !== null && data !== undefined) {
|
|
486
|
+
return _extends({}, i);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
i.x += increment.x;
|
|
490
|
+
i.y += increment.y;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return i;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates) {
|
|
378
497
|
resizeCanvas(context.canvas);
|
|
379
498
|
context.clearRect(0, 0, context.canvas.width, context.canvas.height);
|
|
380
499
|
context.fillStyle = 'white';
|
|
@@ -417,7 +536,9 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
417
536
|
sely2 = selection.y1;
|
|
418
537
|
}
|
|
419
538
|
|
|
420
|
-
var selectionActive = selx1 !== -1 && selx2 !== -1
|
|
539
|
+
var selectionActive = selx1 !== -1 && selx2 !== -1 || sely1 !== -1 && sely2 !== -1;
|
|
540
|
+
var rowSelectionActive = selx1 === -1 && selx2 === -1 && sely1 !== -1 && sely2 !== -1;
|
|
541
|
+
var colSelectionActive = selx1 !== -1 && selx2 !== -1 && sely1 === -1 && sely2 === -1;
|
|
421
542
|
var p1 = cellToAbsCoordinate(selx1, sely1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
422
543
|
var p2 = cellToAbsCoordinate(selx2, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
423
544
|
p2.x += cellWidth(selx2);
|
|
@@ -449,7 +570,16 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
449
570
|
|
|
450
571
|
if (selectionActive) {
|
|
451
572
|
context.fillStyle = selBackColor;
|
|
452
|
-
|
|
573
|
+
var p1x = Math.max(-100, p1.x);
|
|
574
|
+
var p1y = Math.max(-100, p1.y);
|
|
575
|
+
|
|
576
|
+
if (rowSelectionActive) {
|
|
577
|
+
context.fillRect(p1x, p1y, 100000, p2.y - p1.y);
|
|
578
|
+
} else if (colSelectionActive) {
|
|
579
|
+
context.fillRect(p1x, p1y, p2.x - p1.x, 100000);
|
|
580
|
+
} else {
|
|
581
|
+
context.fillRect(p1x, p1y, p2.x - p1.x, p2.y - p1.y);
|
|
582
|
+
}
|
|
453
583
|
}
|
|
454
584
|
|
|
455
585
|
context.fillStyle = rowHeaderBackgroundColor;
|
|
@@ -500,10 +630,16 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
500
630
|
|
|
501
631
|
for (var _iterator5 = _createForOfIteratorHelperLoose(rowSizes.index), _step5; !(_step5 = _iterator5()).done;) {
|
|
502
632
|
var _row = _step5.value;
|
|
503
|
-
var xx = rowHeaderWidth * 0.5;
|
|
504
|
-
var yy = startY + cellHeight(_row) * 0.5;
|
|
505
633
|
var cellContent = _row + 1;
|
|
506
|
-
|
|
634
|
+
var chStyle = {};
|
|
635
|
+
|
|
636
|
+
if (rowSelectionActive && sely1 <= _row && sely2 >= _row) {
|
|
637
|
+
chStyle = _extends({}, chStyle, {
|
|
638
|
+
backgroundColor: rowColHeaderSelectionColor
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
drawCell(context, '' + cellContent, chStyle, defaultColumnHeaderStyle, 0, startY, rowHeaderWidth, cellHeight(_row));
|
|
507
643
|
startY += cellHeight(_row);
|
|
508
644
|
}
|
|
509
645
|
|
|
@@ -516,16 +652,37 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
516
652
|
var cw = cellWidth(_col);
|
|
517
653
|
var ch = columnHeaders(_col);
|
|
518
654
|
var chcontent = ch !== null ? ch : excelHeaderString(_col + 1);
|
|
519
|
-
|
|
520
|
-
|
|
655
|
+
|
|
656
|
+
var _chStyle = columnHeaderStyle(_col);
|
|
657
|
+
|
|
658
|
+
if (colSelectionActive && selx1 <= _col && selx2 >= _col) {
|
|
659
|
+
_chStyle = _extends({}, _chStyle, {
|
|
660
|
+
backgroundColor: rowColHeaderSelectionColor
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
drawCell(context, chcontent, _chStyle, defaultColumnHeaderStyle, startX, 0, cw, columnHeaderHeight);
|
|
521
665
|
startX += cw;
|
|
522
666
|
}
|
|
523
667
|
|
|
524
668
|
if (selectionActive) {
|
|
525
669
|
context.strokeStyle = selBorderColor;
|
|
526
670
|
context.lineWidth = 1;
|
|
671
|
+
|
|
672
|
+
var _p1x = Math.max(-100, p1.x);
|
|
673
|
+
|
|
674
|
+
var _p1y = Math.max(-100, p1.y);
|
|
675
|
+
|
|
527
676
|
context.beginPath();
|
|
528
|
-
|
|
677
|
+
|
|
678
|
+
if (rowSelectionActive) {
|
|
679
|
+
context.rect(_p1x, _p1y, 100000, p2.y - p1.y);
|
|
680
|
+
} else if (colSelectionActive) {
|
|
681
|
+
context.rect(_p1x, _p1y, p2.x - p1.x, 100000);
|
|
682
|
+
} else {
|
|
683
|
+
context.rect(_p1x, _p1y, p2.x - p1.x, p2.y - p1.y);
|
|
684
|
+
}
|
|
685
|
+
|
|
529
686
|
context.stroke();
|
|
530
687
|
}
|
|
531
688
|
|
|
@@ -552,14 +709,22 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
552
709
|
context.setLineDash([3, 3]);
|
|
553
710
|
context.lineWidth = 1;
|
|
554
711
|
context.beginPath();
|
|
555
|
-
|
|
712
|
+
|
|
713
|
+
if (rowSelectionActive) {
|
|
714
|
+
context.rect(knobPoint1.x, knobPoint1.y - 1, 100000, knobPoint2.y - knobPoint1.y);
|
|
715
|
+
} else if (colSelectionActive) {
|
|
716
|
+
context.rect(knobPoint1.x, knobPoint1.y - 1, knobPoint2.x - knobPoint1.x, 100000);
|
|
717
|
+
} else {
|
|
718
|
+
context.rect(knobPoint1.x, knobPoint1.y - 1, knobPoint2.x - knobPoint1.x, knobPoint2.y - knobPoint1.y);
|
|
719
|
+
}
|
|
720
|
+
|
|
556
721
|
context.stroke();
|
|
557
722
|
context.setLineDash([]);
|
|
558
723
|
}
|
|
559
724
|
|
|
560
725
|
if (selectionActive && !hideKnob) {
|
|
561
726
|
context.fillStyle = selBorderColor;
|
|
562
|
-
context.fillRect(
|
|
727
|
+
context.fillRect(knobCoordinates.x - knobSize * 0.5, knobCoordinates.y - knobSize * 0.5, knobSize, knobSize);
|
|
563
728
|
}
|
|
564
729
|
|
|
565
730
|
context.textBaseline = 'middle';
|
|
@@ -748,12 +913,14 @@ function Sheet(props) {
|
|
|
748
913
|
scrollToP2 = true;
|
|
749
914
|
}
|
|
750
915
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
916
|
+
if (selection.x1 !== x1 || selection.x2 !== x2 || selection.y1 !== y1 || selection.y2 !== y2) {
|
|
917
|
+
setSelection({
|
|
918
|
+
x1: x1,
|
|
919
|
+
y1: y1,
|
|
920
|
+
x2: x2,
|
|
921
|
+
y2: y2
|
|
922
|
+
});
|
|
923
|
+
}
|
|
757
924
|
|
|
758
925
|
if (scrollToP2) {
|
|
759
926
|
var newDataOffset = {
|
|
@@ -763,15 +930,32 @@ function Sheet(props) {
|
|
|
763
930
|
var newScrollLeft = -1;
|
|
764
931
|
var newScrollTop = -1;
|
|
765
932
|
|
|
766
|
-
if (!columnSizes.index.includes(x2) || columnSizes.index[columnSizes.index.length - 1] === x2) {
|
|
767
|
-
var
|
|
933
|
+
if (x2 !== -1 && (!columnSizes.index.includes(x2) || columnSizes.index[columnSizes.index.length - 1] === x2)) {
|
|
934
|
+
var lastVisibleColumnIndex = columnSizes.index[columnSizes.index.length - 1];
|
|
935
|
+
var firstVisibleColumnIndex = columnSizes.index[freezeColumns];
|
|
936
|
+
var increment = 0;
|
|
937
|
+
|
|
938
|
+
if (x2 >= lastVisibleColumnIndex) {
|
|
939
|
+
increment = 1 + x2 - lastVisibleColumnIndex;
|
|
940
|
+
} else if (x2 < firstVisibleColumnIndex) {
|
|
941
|
+
increment = x2 - firstVisibleColumnIndex;
|
|
942
|
+
}
|
|
943
|
+
|
|
768
944
|
var newX = Math.max(dataOffset.x, freezeColumns) + increment;
|
|
769
945
|
newDataOffset.x = newX;
|
|
770
946
|
newScrollLeft = newX * scrollSpeed;
|
|
771
947
|
}
|
|
772
948
|
|
|
773
|
-
if (!rowSizes.index.includes(y2) || rowSizes.index[rowSizes.index.length - 1] === y2) {
|
|
774
|
-
var
|
|
949
|
+
if (y2 !== -1 && (!rowSizes.index.includes(y2) || rowSizes.index[rowSizes.index.length - 1] === y2)) {
|
|
950
|
+
var firstVisibleRowIndex = rowSizes.index[freezeRows];
|
|
951
|
+
var lastVisibleRowIndex = rowSizes.index[rowSizes.index.length - 1];
|
|
952
|
+
var _increment = 0;
|
|
953
|
+
|
|
954
|
+
if (y2 >= lastVisibleRowIndex) {
|
|
955
|
+
_increment = 1 + y2 - lastVisibleRowIndex;
|
|
956
|
+
} else if (y2 < firstVisibleRowIndex) {
|
|
957
|
+
_increment = y2 - firstVisibleRowIndex;
|
|
958
|
+
}
|
|
775
959
|
|
|
776
960
|
var newY = Math.max(dataOffset.y, freezeRows) + _increment;
|
|
777
961
|
|
|
@@ -784,6 +968,12 @@ function Sheet(props) {
|
|
|
784
968
|
x: newDataOffset.x,
|
|
785
969
|
y: newDataOffset.y
|
|
786
970
|
});
|
|
971
|
+
|
|
972
|
+
var newMaxScroll = _extends({}, maxScroll);
|
|
973
|
+
|
|
974
|
+
newMaxScroll.x = Math.max(newMaxScroll.x, newScrollLeft);
|
|
975
|
+
newMaxScroll.y = Math.max(newMaxScroll.y, newScrollTop);
|
|
976
|
+
setMaxScroll(newMaxScroll);
|
|
787
977
|
setTimeout(function () {
|
|
788
978
|
if (overlayRef.current) {
|
|
789
979
|
if (newScrollLeft !== -1) {
|
|
@@ -819,23 +1009,53 @@ function Sheet(props) {
|
|
|
819
1009
|
};
|
|
820
1010
|
|
|
821
1011
|
var knobCoordinates = React.useMemo(function () {
|
|
822
|
-
if (selection.x2 !== -1 && selection.y2 !== -1) {
|
|
1012
|
+
if (selection.x1 === -1 && selection.x2 === -1 && selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1013
|
+
var sely2 = selection.y2;
|
|
1014
|
+
|
|
1015
|
+
if (selection.y1 > selection.y2) {
|
|
1016
|
+
sely2 = selection.y1;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
var c = cellToAbsCoordinate(0, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1020
|
+
return {
|
|
1021
|
+
x: c.x + knobSize * 0.5,
|
|
1022
|
+
y: c.y + cellHeight(sely2)
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
if (selection.x1 !== -1 && selection.x2 !== -1 && selection.y1 === -1 && selection.y2 === -1) {
|
|
823
1027
|
var selx2 = selection.x2;
|
|
824
1028
|
|
|
825
1029
|
if (selection.x1 > selection.x2) {
|
|
826
1030
|
selx2 = selection.x1;
|
|
827
1031
|
}
|
|
828
1032
|
|
|
829
|
-
var
|
|
1033
|
+
var _c = cellToAbsCoordinate(selx2, 0, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1034
|
+
|
|
1035
|
+
return {
|
|
1036
|
+
x: _c.x + cellWidth(selx2),
|
|
1037
|
+
y: _c.y + knobSize * 0.5
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
if (selection.x2 !== -1 && selection.y2 !== -1) {
|
|
1042
|
+
var _selx = selection.x2;
|
|
1043
|
+
|
|
1044
|
+
if (selection.x1 > selection.x2) {
|
|
1045
|
+
_selx = selection.x1;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
var _sely = selection.y2;
|
|
830
1049
|
|
|
831
1050
|
if (selection.y1 > selection.y2) {
|
|
832
|
-
|
|
1051
|
+
_sely = selection.y1;
|
|
833
1052
|
}
|
|
834
1053
|
|
|
835
|
-
var
|
|
1054
|
+
var _c2 = cellToAbsCoordinate(_selx, _sely, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1055
|
+
|
|
836
1056
|
return {
|
|
837
|
-
x:
|
|
838
|
-
y:
|
|
1057
|
+
x: _c2.x + cellWidth(_selx),
|
|
1058
|
+
y: _c2.y + cellHeight(_sely)
|
|
839
1059
|
};
|
|
840
1060
|
}
|
|
841
1061
|
|
|
@@ -1007,12 +1227,12 @@ function Sheet(props) {
|
|
|
1007
1227
|
}
|
|
1008
1228
|
|
|
1009
1229
|
var animationFrameId = window.requestAnimationFrame(function () {
|
|
1010
|
-
renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset);
|
|
1230
|
+
renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates);
|
|
1011
1231
|
});
|
|
1012
1232
|
return function () {
|
|
1013
1233
|
window.cancelAnimationFrame(animationFrameId);
|
|
1014
1234
|
};
|
|
1015
|
-
}, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset]);
|
|
1235
|
+
}, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates]);
|
|
1016
1236
|
|
|
1017
1237
|
var setFocusToTextArea = function setFocusToTextArea() {
|
|
1018
1238
|
if (copyPasteTextAreaRef.current) {
|
|
@@ -1026,7 +1246,10 @@ function Sheet(props) {
|
|
|
1026
1246
|
React.useEffect(function () {
|
|
1027
1247
|
if (!editMode) {
|
|
1028
1248
|
setCopyPasteText();
|
|
1029
|
-
|
|
1249
|
+
}
|
|
1250
|
+
}, [selection, editData]);
|
|
1251
|
+
React.useEffect(function () {
|
|
1252
|
+
if (!editMode) {
|
|
1030
1253
|
if (document.activeElement === copyPasteTextAreaRef.current) {
|
|
1031
1254
|
setFocusToTextArea();
|
|
1032
1255
|
} else {
|
|
@@ -1180,18 +1403,26 @@ function Sheet(props) {
|
|
|
1180
1403
|
pasteLocX = selection.x1;
|
|
1181
1404
|
}
|
|
1182
1405
|
|
|
1183
|
-
if (selection.y1 !== -1 && selection.y2 === -1) {
|
|
1184
|
-
pasteLocY = selection.y1;
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
1406
|
if (selection.x1 !== -1 && selection.x2 !== -1) {
|
|
1188
1407
|
pasteLocX = Math.min(selection.x1, selection.x2);
|
|
1189
1408
|
}
|
|
1190
1409
|
|
|
1410
|
+
if (selection.x1 === -1 && selection.x2 === -1 && selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1411
|
+
pasteLocX = 0;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
if (selection.y1 !== -1 && selection.y2 === -1) {
|
|
1415
|
+
pasteLocY = selection.y1;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1191
1418
|
if (selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1192
1419
|
pasteLocY = Math.min(selection.y1, selection.y2);
|
|
1193
1420
|
}
|
|
1194
1421
|
|
|
1422
|
+
if (selection.y1 === -1 && selection.y2 === -1 && selection.x2 !== -1 && selection.x2 !== -1) {
|
|
1423
|
+
pasteLocY = 0;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1195
1426
|
if (pasteLocX === -1 || pasteLocY === -1) {
|
|
1196
1427
|
return;
|
|
1197
1428
|
}
|
|
@@ -1225,7 +1456,7 @@ function Sheet(props) {
|
|
|
1225
1456
|
};
|
|
1226
1457
|
|
|
1227
1458
|
var setCopyPasteText = function setCopyPasteText() {
|
|
1228
|
-
if (selection.x1 === -1
|
|
1459
|
+
if (selection.x1 === -1 && selection.y1 === -1 && selection.x2 === -1 && selection.y2 === -1) {
|
|
1229
1460
|
return;
|
|
1230
1461
|
}
|
|
1231
1462
|
|
|
@@ -1245,25 +1476,46 @@ function Sheet(props) {
|
|
|
1245
1476
|
dx2 = selection.x1;
|
|
1246
1477
|
}
|
|
1247
1478
|
|
|
1248
|
-
var
|
|
1479
|
+
var max = findApproxMaxEditDataIndex(editData);
|
|
1480
|
+
|
|
1481
|
+
if (dx1 === -1 && dx2 === -1) {
|
|
1482
|
+
dx1 = 0;
|
|
1483
|
+
dx2 = max.x;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
if (dy1 === -1 && dy2 === -1) {
|
|
1487
|
+
dy1 = 0;
|
|
1488
|
+
dy2 = max.y;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
var cptext = '';
|
|
1492
|
+
var cptextTemp = '';
|
|
1249
1493
|
|
|
1250
1494
|
for (var y = dy1; y <= dy2; y++) {
|
|
1251
|
-
var
|
|
1495
|
+
var nonEmpty = false;
|
|
1252
1496
|
|
|
1253
1497
|
for (var x = dx1; x <= dx2; x++) {
|
|
1254
1498
|
var value = editData(x, y);
|
|
1255
1499
|
|
|
1256
1500
|
if (value !== null && value !== undefined) {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1501
|
+
cptextTemp += value;
|
|
1502
|
+
nonEmpty = true;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
if (x !== dx2) {
|
|
1506
|
+
cptextTemp += '\t';
|
|
1260
1507
|
}
|
|
1261
1508
|
}
|
|
1262
1509
|
|
|
1263
|
-
|
|
1264
|
-
|
|
1510
|
+
if (y !== dy2) {
|
|
1511
|
+
cptextTemp += '\n';
|
|
1512
|
+
}
|
|
1265
1513
|
|
|
1266
|
-
|
|
1514
|
+
if (nonEmpty) {
|
|
1515
|
+
cptext += cptextTemp;
|
|
1516
|
+
cptextTemp = '';
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1267
1519
|
|
|
1268
1520
|
if (copyPasteTextAreaRef.current) {
|
|
1269
1521
|
copyPasteTextAreaRef.current.value = cptext;
|
|
@@ -1275,7 +1527,7 @@ function Sheet(props) {
|
|
|
1275
1527
|
props.onChange([{
|
|
1276
1528
|
x: editCell.x,
|
|
1277
1529
|
y: editCell.y,
|
|
1278
|
-
value: value
|
|
1530
|
+
value: value !== undefined ? value : editValue
|
|
1279
1531
|
}]);
|
|
1280
1532
|
}
|
|
1281
1533
|
|
|
@@ -1302,6 +1554,7 @@ function Sheet(props) {
|
|
|
1302
1554
|
setEditCell(editCell);
|
|
1303
1555
|
setEditKey(editDataKey);
|
|
1304
1556
|
setEditValue(val);
|
|
1557
|
+
setShiftKeyDown(false);
|
|
1305
1558
|
};
|
|
1306
1559
|
|
|
1307
1560
|
var onScroll = function onScroll(e) {
|
|
@@ -1388,10 +1641,25 @@ function Sheet(props) {
|
|
|
1388
1641
|
|
|
1389
1642
|
if (Math.abs(start - x) < resizeColumnRowMouseThreshold || Math.abs(end - x) < resizeColumnRowMouseThreshold) {
|
|
1390
1643
|
window.document.body.style.cursor = 'col-resize';
|
|
1644
|
+
var indices = [];
|
|
1645
|
+
|
|
1646
|
+
if (selection.x1 !== -1 && selection.x2 !== -1 && selection.y1 === -1 && selection.y2 === -1) {
|
|
1647
|
+
var min = Math.min(selection.x1, selection.x2);
|
|
1648
|
+
var max = Math.max(selection.x1, selection.x2);
|
|
1649
|
+
|
|
1650
|
+
for (var i = min; i <= max; i++) {
|
|
1651
|
+
indices.push(i);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
if (indices.length === 0) {
|
|
1656
|
+
indices.push(index);
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1391
1659
|
setColumnResize({
|
|
1392
1660
|
startX: end,
|
|
1393
1661
|
oldWidth: cellWidth(index),
|
|
1394
|
-
|
|
1662
|
+
colIndices: indices
|
|
1395
1663
|
});
|
|
1396
1664
|
return;
|
|
1397
1665
|
}
|
|
@@ -1406,10 +1674,26 @@ function Sheet(props) {
|
|
|
1406
1674
|
|
|
1407
1675
|
if (Math.abs(_start - y) < resizeColumnRowMouseThreshold || Math.abs(_end - y) < resizeColumnRowMouseThreshold) {
|
|
1408
1676
|
window.document.body.style.cursor = 'row-resize';
|
|
1677
|
+
var _indices = [];
|
|
1678
|
+
|
|
1679
|
+
if (selection.x1 === -1 && selection.x2 === -1 && selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1680
|
+
var _min = Math.min(selection.y1, selection.y2);
|
|
1681
|
+
|
|
1682
|
+
var _max = Math.max(selection.y1, selection.y2);
|
|
1683
|
+
|
|
1684
|
+
for (var _i5 = _min; _i5 <= _max; _i5++) {
|
|
1685
|
+
_indices.push(_i5);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
if (_indices.length === 0) {
|
|
1690
|
+
_indices.push(_index);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1409
1693
|
setRowResize({
|
|
1410
1694
|
startY: _end,
|
|
1411
1695
|
oldHeight: cellHeight(_index),
|
|
1412
|
-
|
|
1696
|
+
rowIndices: _indices
|
|
1413
1697
|
});
|
|
1414
1698
|
return;
|
|
1415
1699
|
}
|
|
@@ -1440,17 +1724,19 @@ function Sheet(props) {
|
|
|
1440
1724
|
var scrollToP2 = true;
|
|
1441
1725
|
|
|
1442
1726
|
if (x < rowHeaderWidth) {
|
|
1443
|
-
sel2.x = dataOffset.x + 100;
|
|
1444
1727
|
scrollToP2 = false;
|
|
1445
1728
|
setRowSelectionInProgress(true);
|
|
1729
|
+
sel1.x = -1;
|
|
1730
|
+
sel2.x = -1;
|
|
1446
1731
|
} else {
|
|
1447
1732
|
setRowSelectionInProgress(false);
|
|
1448
1733
|
}
|
|
1449
1734
|
|
|
1450
1735
|
if (y < columnHeaderHeight) {
|
|
1451
|
-
sel2.y = dataOffset.y + 100;
|
|
1452
1736
|
scrollToP2 = false;
|
|
1453
1737
|
setColumnSelectionInProgress(true);
|
|
1738
|
+
sel1.y = -1;
|
|
1739
|
+
sel2.y = -1;
|
|
1454
1740
|
} else {
|
|
1455
1741
|
setColumnSelectionInProgress(false);
|
|
1456
1742
|
}
|
|
@@ -1511,6 +1797,11 @@ function Sheet(props) {
|
|
|
1511
1797
|
fy2 = sy1 - 1;
|
|
1512
1798
|
}
|
|
1513
1799
|
|
|
1800
|
+
if (fx1 === -1 && fx2 === -1) {
|
|
1801
|
+
fx1 = 0;
|
|
1802
|
+
fx2 = maxSearchableRowOrCol;
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1514
1805
|
var srcY = sy1;
|
|
1515
1806
|
|
|
1516
1807
|
for (var y = fy1; y <= fy2; y++) {
|
|
@@ -1536,6 +1827,11 @@ function Sheet(props) {
|
|
|
1536
1827
|
fx2 = sx1 - 1;
|
|
1537
1828
|
}
|
|
1538
1829
|
|
|
1830
|
+
if (fy1 === -1 && fy2 === -1) {
|
|
1831
|
+
fy1 = 0;
|
|
1832
|
+
fy2 = maxSearchableRowOrCol;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1539
1835
|
var srcX = sx1;
|
|
1540
1836
|
|
|
1541
1837
|
for (var _x3 = fx1; _x3 <= fx2; _x3++) {
|
|
@@ -1662,7 +1958,7 @@ function Sheet(props) {
|
|
|
1662
1958
|
if (columnResize) {
|
|
1663
1959
|
if (props.onCellWidthChange) {
|
|
1664
1960
|
var newWidth = Math.max(columnResize.oldWidth + x - columnResize.startX, minimumColumnWidth);
|
|
1665
|
-
props.onCellWidthChange(columnResize.
|
|
1961
|
+
props.onCellWidthChange(columnResize.colIndices, newWidth);
|
|
1666
1962
|
}
|
|
1667
1963
|
|
|
1668
1964
|
return;
|
|
@@ -1671,7 +1967,7 @@ function Sheet(props) {
|
|
|
1671
1967
|
if (rowResize) {
|
|
1672
1968
|
if (props.onCellHeightChange) {
|
|
1673
1969
|
var newHeight = Math.max(rowResize.oldHeight + y - rowResize.startY, minimumRowHeight);
|
|
1674
|
-
props.onCellHeightChange(rowResize.
|
|
1970
|
+
props.onCellHeightChange(rowResize.rowIndices, newHeight);
|
|
1675
1971
|
}
|
|
1676
1972
|
|
|
1677
1973
|
return;
|
|
@@ -1681,9 +1977,9 @@ function Sheet(props) {
|
|
|
1681
1977
|
var sel2 = absCoordianteToCell(x, y, rowSizes, columnSizes);
|
|
1682
1978
|
|
|
1683
1979
|
if (rowSelectionInProgress) {
|
|
1684
|
-
changeSelection(
|
|
1980
|
+
changeSelection(-1, selection.y1, -1, sel2.y, false);
|
|
1685
1981
|
} else if (columnSelectionInProgress) {
|
|
1686
|
-
changeSelection(selection.x1,
|
|
1982
|
+
changeSelection(selection.x1, -1, sel2.x, -1, false);
|
|
1687
1983
|
} else {
|
|
1688
1984
|
changeSelection(selection.x1, selection.y1, sel2.x, sel2.y);
|
|
1689
1985
|
}
|
|
@@ -1714,7 +2010,7 @@ function Sheet(props) {
|
|
|
1714
2010
|
if (cell.y < y1) yCellDiff = cell.y - y1;
|
|
1715
2011
|
if (cell.y > y2) yCellDiff = y2 - cell.y;
|
|
1716
2012
|
|
|
1717
|
-
if (xCellDiff > yCellDiff) {
|
|
2013
|
+
if (x1 === -1 && x2 === -1 || xCellDiff > yCellDiff) {
|
|
1718
2014
|
if (cell.y < y1) {
|
|
1719
2015
|
y1 = cell.y;
|
|
1720
2016
|
} else {
|
|
@@ -1847,6 +2143,16 @@ function Sheet(props) {
|
|
|
1847
2143
|
y2 = selection.y1;
|
|
1848
2144
|
}
|
|
1849
2145
|
|
|
2146
|
+
if (x1 === -1 && x2 === -1 && y1 !== -1 && y2 !== -1) {
|
|
2147
|
+
x1 = 0;
|
|
2148
|
+
x2 = maxSearchableRowOrCol;
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
if (x1 !== -1 && x2 !== -1 && y1 === -1 && y2 === -1) {
|
|
2152
|
+
y1 = 0;
|
|
2153
|
+
y2 = maxSearchableRowOrCol;
|
|
2154
|
+
}
|
|
2155
|
+
|
|
1850
2156
|
var changes = [];
|
|
1851
2157
|
|
|
1852
2158
|
for (var y = y1; y <= y2; y++) {
|
|
@@ -1893,17 +2199,35 @@ function Sheet(props) {
|
|
|
1893
2199
|
x: selection.x2,
|
|
1894
2200
|
y: selection.y2
|
|
1895
2201
|
};
|
|
2202
|
+
var incr = {
|
|
2203
|
+
x: 0,
|
|
2204
|
+
y: 0
|
|
2205
|
+
};
|
|
2206
|
+
var direction = 'right';
|
|
1896
2207
|
|
|
1897
2208
|
if (e.key === 'ArrowRight' || e.key === 'Tab') {
|
|
1898
|
-
|
|
2209
|
+
incr.x = 1;
|
|
2210
|
+
direction = 'right';
|
|
1899
2211
|
} else if (e.key === 'ArrowLeft') {
|
|
1900
|
-
|
|
2212
|
+
incr.x = -1;
|
|
2213
|
+
direction = 'left';
|
|
1901
2214
|
} else if (e.key === 'ArrowUp') {
|
|
1902
|
-
|
|
2215
|
+
incr.y = -1;
|
|
2216
|
+
direction = 'up';
|
|
1903
2217
|
} else if (e.key === 'ArrowDown') {
|
|
1904
|
-
|
|
2218
|
+
incr.y = 1;
|
|
2219
|
+
direction = 'down';
|
|
1905
2220
|
}
|
|
1906
2221
|
|
|
2222
|
+
if (e.metaKey || e.ctrlKey) {
|
|
2223
|
+
var val = findInDisplayData(displayData, sel2, direction);
|
|
2224
|
+
incr.x = val.x - sel2.x;
|
|
2225
|
+
incr.y = val.y - sel2.y;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
sel2.x += incr.x;
|
|
2229
|
+
sel2.y += incr.y;
|
|
2230
|
+
|
|
1907
2231
|
if (sel2.x < 0) {
|
|
1908
2232
|
sel2.x = 0;
|
|
1909
2233
|
}
|
|
@@ -2073,13 +2397,17 @@ function Sheet(props) {
|
|
|
2073
2397
|
opacity: 0.01
|
|
2074
2398
|
},
|
|
2075
2399
|
ref: copyPasteTextAreaRef,
|
|
2400
|
+
autoComplete: "off",
|
|
2401
|
+
autoCorrect: "off",
|
|
2402
|
+
autoCapitalize: "off",
|
|
2403
|
+
spellCheck: "false",
|
|
2076
2404
|
onFocus: function onFocus(e) {
|
|
2077
2405
|
return e.target.select();
|
|
2078
2406
|
},
|
|
2079
2407
|
tabIndex: 0,
|
|
2080
2408
|
onKeyDown: onGridKeyDown,
|
|
2081
2409
|
onKeyUp: onGridKeyUp
|
|
2082
|
-
}), editMode && (input
|
|
2410
|
+
}), editMode && (input !== undefined ? input : React__default.createElement("input", Object.assign({}, inputProps, {
|
|
2083
2411
|
type: "text",
|
|
2084
2412
|
onFocus: function onFocus(e) {
|
|
2085
2413
|
return e.target.select();
|