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.modern.js
CHANGED
|
@@ -81,6 +81,8 @@ var scrollSpeed = 30;
|
|
|
81
81
|
var resizeColumnRowMouseThreshold = 4;
|
|
82
82
|
var minimumColumnWidth = 50;
|
|
83
83
|
var minimumRowHeight = 22;
|
|
84
|
+
var rowColHeaderSelectionColor = '#AAAAAA';
|
|
85
|
+
var maxSearchableRowOrCol = 65536;
|
|
84
86
|
var defaultCellStyle = {
|
|
85
87
|
textAlign: 'left',
|
|
86
88
|
fontSize: 13,
|
|
@@ -371,7 +373,124 @@ function cellToAbsCoordinate(cellX, cellY, rowSizes, columnSizes, dataOffset, ce
|
|
|
371
373
|
};
|
|
372
374
|
}
|
|
373
375
|
|
|
374
|
-
function
|
|
376
|
+
function findApproxMaxEditDataIndex(editData) {
|
|
377
|
+
var x = 0;
|
|
378
|
+
var y = 0;
|
|
379
|
+
var howManyEmpty = 0;
|
|
380
|
+
var growthIncrement = 10;
|
|
381
|
+
var growthIncrementFactor = 1.5;
|
|
382
|
+
|
|
383
|
+
while (howManyEmpty < 4) {
|
|
384
|
+
var allEmpty = true;
|
|
385
|
+
|
|
386
|
+
for (var yy = 0; yy < 10; yy++) {
|
|
387
|
+
var data = editData(x, yy);
|
|
388
|
+
|
|
389
|
+
if (data !== null && data !== undefined && data !== '') {
|
|
390
|
+
allEmpty = false;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (allEmpty) {
|
|
396
|
+
howManyEmpty += 1;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
x += growthIncrement;
|
|
400
|
+
growthIncrement = Math.floor(growthIncrement * growthIncrementFactor);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
howManyEmpty = 0;
|
|
404
|
+
growthIncrement = 10;
|
|
405
|
+
growthIncrementFactor = 1.5;
|
|
406
|
+
|
|
407
|
+
while (howManyEmpty < 4) {
|
|
408
|
+
var _allEmpty = true;
|
|
409
|
+
|
|
410
|
+
for (var xx = 0; xx < 10; xx++) {
|
|
411
|
+
var _data = editData(xx, y);
|
|
412
|
+
|
|
413
|
+
if (_data !== null && _data !== undefined && _data !== '') {
|
|
414
|
+
_allEmpty = false;
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (_allEmpty) {
|
|
420
|
+
howManyEmpty += 1;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
y += growthIncrement;
|
|
424
|
+
growthIncrement = Math.floor(growthIncrement * growthIncrementFactor);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
x: x,
|
|
429
|
+
y: y
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function findInDisplayData(displayData, start, direction) {
|
|
434
|
+
var i = _extends({}, start);
|
|
435
|
+
|
|
436
|
+
var increment = {
|
|
437
|
+
x: 0,
|
|
438
|
+
y: 0
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
if (direction === 'up') {
|
|
442
|
+
increment.y = -1;
|
|
443
|
+
} else if (direction === 'down') {
|
|
444
|
+
increment.y = 1;
|
|
445
|
+
} else if (direction === 'left') {
|
|
446
|
+
increment.x = -1;
|
|
447
|
+
} else if (direction === 'right') {
|
|
448
|
+
increment.x = 1;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
var max = {
|
|
452
|
+
x: maxSearchableRowOrCol,
|
|
453
|
+
y: maxSearchableRowOrCol
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
if (i.x > max.x) {
|
|
457
|
+
i.x = max.x;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (i.y > max.y) {
|
|
461
|
+
i.y = max.y;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
var first = displayData(i.x + increment.x, i.y + increment.y);
|
|
465
|
+
var firstFilled = first !== '' && first !== null && first !== undefined;
|
|
466
|
+
|
|
467
|
+
if (!firstFilled) {
|
|
468
|
+
i.x += increment.x;
|
|
469
|
+
i.y += increment.y;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
while (i.x <= max.x && i.y <= max.y && i.x >= 0 && i.y >= 0) {
|
|
473
|
+
var data = displayData(i.x, i.y);
|
|
474
|
+
|
|
475
|
+
if (firstFilled && (data === '' || data === null || data === undefined)) {
|
|
476
|
+
return {
|
|
477
|
+
x: i.x - increment.x,
|
|
478
|
+
y: i.y - increment.y
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (!firstFilled && data !== '' && data !== null && data !== undefined) {
|
|
483
|
+
return _extends({}, i);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
i.x += increment.x;
|
|
487
|
+
i.y += increment.y;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return i;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates) {
|
|
375
494
|
resizeCanvas(context.canvas);
|
|
376
495
|
context.clearRect(0, 0, context.canvas.width, context.canvas.height);
|
|
377
496
|
context.fillStyle = 'white';
|
|
@@ -414,7 +533,9 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
414
533
|
sely2 = selection.y1;
|
|
415
534
|
}
|
|
416
535
|
|
|
417
|
-
var selectionActive = selx1 !== -1 && selx2 !== -1
|
|
536
|
+
var selectionActive = selx1 !== -1 && selx2 !== -1 || sely1 !== -1 && sely2 !== -1;
|
|
537
|
+
var rowSelectionActive = selx1 === -1 && selx2 === -1 && sely1 !== -1 && sely2 !== -1;
|
|
538
|
+
var colSelectionActive = selx1 !== -1 && selx2 !== -1 && sely1 === -1 && sely2 === -1;
|
|
418
539
|
var p1 = cellToAbsCoordinate(selx1, sely1, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
419
540
|
var p2 = cellToAbsCoordinate(selx2, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
420
541
|
p2.x += cellWidth(selx2);
|
|
@@ -446,7 +567,16 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
446
567
|
|
|
447
568
|
if (selectionActive) {
|
|
448
569
|
context.fillStyle = selBackColor;
|
|
449
|
-
|
|
570
|
+
var p1x = Math.max(-100, p1.x);
|
|
571
|
+
var p1y = Math.max(-100, p1.y);
|
|
572
|
+
|
|
573
|
+
if (rowSelectionActive) {
|
|
574
|
+
context.fillRect(p1x, p1y, 100000, p2.y - p1.y);
|
|
575
|
+
} else if (colSelectionActive) {
|
|
576
|
+
context.fillRect(p1x, p1y, p2.x - p1.x, 100000);
|
|
577
|
+
} else {
|
|
578
|
+
context.fillRect(p1x, p1y, p2.x - p1.x, p2.y - p1.y);
|
|
579
|
+
}
|
|
450
580
|
}
|
|
451
581
|
|
|
452
582
|
context.fillStyle = rowHeaderBackgroundColor;
|
|
@@ -497,10 +627,16 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
497
627
|
|
|
498
628
|
for (var _iterator5 = _createForOfIteratorHelperLoose(rowSizes.index), _step5; !(_step5 = _iterator5()).done;) {
|
|
499
629
|
var _row = _step5.value;
|
|
500
|
-
var xx = rowHeaderWidth * 0.5;
|
|
501
|
-
var yy = startY + cellHeight(_row) * 0.5;
|
|
502
630
|
var cellContent = _row + 1;
|
|
503
|
-
|
|
631
|
+
var chStyle = {};
|
|
632
|
+
|
|
633
|
+
if (rowSelectionActive && sely1 <= _row && sely2 >= _row) {
|
|
634
|
+
chStyle = _extends({}, chStyle, {
|
|
635
|
+
backgroundColor: rowColHeaderSelectionColor
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
drawCell(context, '' + cellContent, chStyle, defaultColumnHeaderStyle, 0, startY, rowHeaderWidth, cellHeight(_row));
|
|
504
640
|
startY += cellHeight(_row);
|
|
505
641
|
}
|
|
506
642
|
|
|
@@ -513,16 +649,37 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
513
649
|
var cw = cellWidth(_col);
|
|
514
650
|
var ch = columnHeaders(_col);
|
|
515
651
|
var chcontent = ch !== null ? ch : excelHeaderString(_col + 1);
|
|
516
|
-
|
|
517
|
-
|
|
652
|
+
|
|
653
|
+
var _chStyle = columnHeaderStyle(_col);
|
|
654
|
+
|
|
655
|
+
if (colSelectionActive && selx1 <= _col && selx2 >= _col) {
|
|
656
|
+
_chStyle = _extends({}, _chStyle, {
|
|
657
|
+
backgroundColor: rowColHeaderSelectionColor
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
drawCell(context, chcontent, _chStyle, defaultColumnHeaderStyle, startX, 0, cw, columnHeaderHeight);
|
|
518
662
|
startX += cw;
|
|
519
663
|
}
|
|
520
664
|
|
|
521
665
|
if (selectionActive) {
|
|
522
666
|
context.strokeStyle = selBorderColor;
|
|
523
667
|
context.lineWidth = 1;
|
|
668
|
+
|
|
669
|
+
var _p1x = Math.max(-100, p1.x);
|
|
670
|
+
|
|
671
|
+
var _p1y = Math.max(-100, p1.y);
|
|
672
|
+
|
|
524
673
|
context.beginPath();
|
|
525
|
-
|
|
674
|
+
|
|
675
|
+
if (rowSelectionActive) {
|
|
676
|
+
context.rect(_p1x, _p1y, 100000, p2.y - p1.y);
|
|
677
|
+
} else if (colSelectionActive) {
|
|
678
|
+
context.rect(_p1x, _p1y, p2.x - p1.x, 100000);
|
|
679
|
+
} else {
|
|
680
|
+
context.rect(_p1x, _p1y, p2.x - p1.x, p2.y - p1.y);
|
|
681
|
+
}
|
|
682
|
+
|
|
526
683
|
context.stroke();
|
|
527
684
|
}
|
|
528
685
|
|
|
@@ -549,14 +706,22 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
549
706
|
context.setLineDash([3, 3]);
|
|
550
707
|
context.lineWidth = 1;
|
|
551
708
|
context.beginPath();
|
|
552
|
-
|
|
709
|
+
|
|
710
|
+
if (rowSelectionActive) {
|
|
711
|
+
context.rect(knobPoint1.x, knobPoint1.y - 1, 100000, knobPoint2.y - knobPoint1.y);
|
|
712
|
+
} else if (colSelectionActive) {
|
|
713
|
+
context.rect(knobPoint1.x, knobPoint1.y - 1, knobPoint2.x - knobPoint1.x, 100000);
|
|
714
|
+
} else {
|
|
715
|
+
context.rect(knobPoint1.x, knobPoint1.y - 1, knobPoint2.x - knobPoint1.x, knobPoint2.y - knobPoint1.y);
|
|
716
|
+
}
|
|
717
|
+
|
|
553
718
|
context.stroke();
|
|
554
719
|
context.setLineDash([]);
|
|
555
720
|
}
|
|
556
721
|
|
|
557
722
|
if (selectionActive && !hideKnob) {
|
|
558
723
|
context.fillStyle = selBorderColor;
|
|
559
|
-
context.fillRect(
|
|
724
|
+
context.fillRect(knobCoordinates.x - knobSize * 0.5, knobCoordinates.y - knobSize * 0.5, knobSize, knobSize);
|
|
560
725
|
}
|
|
561
726
|
|
|
562
727
|
context.textBaseline = 'middle';
|
|
@@ -745,12 +910,14 @@ function Sheet(props) {
|
|
|
745
910
|
scrollToP2 = true;
|
|
746
911
|
}
|
|
747
912
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
913
|
+
if (selection.x1 !== x1 || selection.x2 !== x2 || selection.y1 !== y1 || selection.y2 !== y2) {
|
|
914
|
+
setSelection({
|
|
915
|
+
x1: x1,
|
|
916
|
+
y1: y1,
|
|
917
|
+
x2: x2,
|
|
918
|
+
y2: y2
|
|
919
|
+
});
|
|
920
|
+
}
|
|
754
921
|
|
|
755
922
|
if (scrollToP2) {
|
|
756
923
|
var newDataOffset = {
|
|
@@ -760,15 +927,32 @@ function Sheet(props) {
|
|
|
760
927
|
var newScrollLeft = -1;
|
|
761
928
|
var newScrollTop = -1;
|
|
762
929
|
|
|
763
|
-
if (!columnSizes.index.includes(x2) || columnSizes.index[columnSizes.index.length - 1] === x2) {
|
|
764
|
-
var
|
|
930
|
+
if (x2 !== -1 && (!columnSizes.index.includes(x2) || columnSizes.index[columnSizes.index.length - 1] === x2)) {
|
|
931
|
+
var lastVisibleColumnIndex = columnSizes.index[columnSizes.index.length - 1];
|
|
932
|
+
var firstVisibleColumnIndex = columnSizes.index[freezeColumns];
|
|
933
|
+
var increment = 0;
|
|
934
|
+
|
|
935
|
+
if (x2 >= lastVisibleColumnIndex) {
|
|
936
|
+
increment = 1 + x2 - lastVisibleColumnIndex;
|
|
937
|
+
} else if (x2 < firstVisibleColumnIndex) {
|
|
938
|
+
increment = x2 - firstVisibleColumnIndex;
|
|
939
|
+
}
|
|
940
|
+
|
|
765
941
|
var newX = Math.max(dataOffset.x, freezeColumns) + increment;
|
|
766
942
|
newDataOffset.x = newX;
|
|
767
943
|
newScrollLeft = newX * scrollSpeed;
|
|
768
944
|
}
|
|
769
945
|
|
|
770
|
-
if (!rowSizes.index.includes(y2) || rowSizes.index[rowSizes.index.length - 1] === y2) {
|
|
771
|
-
var
|
|
946
|
+
if (y2 !== -1 && (!rowSizes.index.includes(y2) || rowSizes.index[rowSizes.index.length - 1] === y2)) {
|
|
947
|
+
var firstVisibleRowIndex = rowSizes.index[freezeRows];
|
|
948
|
+
var lastVisibleRowIndex = rowSizes.index[rowSizes.index.length - 1];
|
|
949
|
+
var _increment = 0;
|
|
950
|
+
|
|
951
|
+
if (y2 >= lastVisibleRowIndex) {
|
|
952
|
+
_increment = 1 + y2 - lastVisibleRowIndex;
|
|
953
|
+
} else if (y2 < firstVisibleRowIndex) {
|
|
954
|
+
_increment = y2 - firstVisibleRowIndex;
|
|
955
|
+
}
|
|
772
956
|
|
|
773
957
|
var newY = Math.max(dataOffset.y, freezeRows) + _increment;
|
|
774
958
|
|
|
@@ -781,6 +965,12 @@ function Sheet(props) {
|
|
|
781
965
|
x: newDataOffset.x,
|
|
782
966
|
y: newDataOffset.y
|
|
783
967
|
});
|
|
968
|
+
|
|
969
|
+
var newMaxScroll = _extends({}, maxScroll);
|
|
970
|
+
|
|
971
|
+
newMaxScroll.x = Math.max(newMaxScroll.x, newScrollLeft);
|
|
972
|
+
newMaxScroll.y = Math.max(newMaxScroll.y, newScrollTop);
|
|
973
|
+
setMaxScroll(newMaxScroll);
|
|
784
974
|
setTimeout(function () {
|
|
785
975
|
if (overlayRef.current) {
|
|
786
976
|
if (newScrollLeft !== -1) {
|
|
@@ -816,23 +1006,53 @@ function Sheet(props) {
|
|
|
816
1006
|
};
|
|
817
1007
|
|
|
818
1008
|
var knobCoordinates = useMemo(function () {
|
|
819
|
-
if (selection.x2 !== -1 && selection.y2 !== -1) {
|
|
1009
|
+
if (selection.x1 === -1 && selection.x2 === -1 && selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1010
|
+
var sely2 = selection.y2;
|
|
1011
|
+
|
|
1012
|
+
if (selection.y1 > selection.y2) {
|
|
1013
|
+
sely2 = selection.y1;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
var c = cellToAbsCoordinate(0, sely2, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1017
|
+
return {
|
|
1018
|
+
x: c.x + knobSize * 0.5,
|
|
1019
|
+
y: c.y + cellHeight(sely2)
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
if (selection.x1 !== -1 && selection.x2 !== -1 && selection.y1 === -1 && selection.y2 === -1) {
|
|
820
1024
|
var selx2 = selection.x2;
|
|
821
1025
|
|
|
822
1026
|
if (selection.x1 > selection.x2) {
|
|
823
1027
|
selx2 = selection.x1;
|
|
824
1028
|
}
|
|
825
1029
|
|
|
826
|
-
var
|
|
1030
|
+
var _c = cellToAbsCoordinate(selx2, 0, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1031
|
+
|
|
1032
|
+
return {
|
|
1033
|
+
x: _c.x + cellWidth(selx2),
|
|
1034
|
+
y: _c.y + knobSize * 0.5
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
if (selection.x2 !== -1 && selection.y2 !== -1) {
|
|
1039
|
+
var _selx = selection.x2;
|
|
1040
|
+
|
|
1041
|
+
if (selection.x1 > selection.x2) {
|
|
1042
|
+
_selx = selection.x1;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
var _sely = selection.y2;
|
|
827
1046
|
|
|
828
1047
|
if (selection.y1 > selection.y2) {
|
|
829
|
-
|
|
1048
|
+
_sely = selection.y1;
|
|
830
1049
|
}
|
|
831
1050
|
|
|
832
|
-
var
|
|
1051
|
+
var _c2 = cellToAbsCoordinate(_selx, _sely, rowSizes, columnSizes, dataOffset, cellWidth, cellHeight);
|
|
1052
|
+
|
|
833
1053
|
return {
|
|
834
|
-
x:
|
|
835
|
-
y:
|
|
1054
|
+
x: _c2.x + cellWidth(_selx),
|
|
1055
|
+
y: _c2.y + cellHeight(_sely)
|
|
836
1056
|
};
|
|
837
1057
|
}
|
|
838
1058
|
|
|
@@ -1004,12 +1224,12 @@ function Sheet(props) {
|
|
|
1004
1224
|
}
|
|
1005
1225
|
|
|
1006
1226
|
var animationFrameId = window.requestAnimationFrame(function () {
|
|
1007
|
-
renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset);
|
|
1227
|
+
renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates);
|
|
1008
1228
|
});
|
|
1009
1229
|
return function () {
|
|
1010
1230
|
window.cancelAnimationFrame(animationFrameId);
|
|
1011
1231
|
};
|
|
1012
|
-
}, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset]);
|
|
1232
|
+
}, [canvasRef, rowSizes, columnSizes, cellStyle, cellWidth, cellHeight, selection, knobDragInProgress, columnHeaders, columnHeaderStyle, knobArea, displayData, dataOffset, knobCoordinates]);
|
|
1013
1233
|
|
|
1014
1234
|
var setFocusToTextArea = function setFocusToTextArea() {
|
|
1015
1235
|
if (copyPasteTextAreaRef.current) {
|
|
@@ -1023,7 +1243,10 @@ function Sheet(props) {
|
|
|
1023
1243
|
useEffect(function () {
|
|
1024
1244
|
if (!editMode) {
|
|
1025
1245
|
setCopyPasteText();
|
|
1026
|
-
|
|
1246
|
+
}
|
|
1247
|
+
}, [selection, editData]);
|
|
1248
|
+
useEffect(function () {
|
|
1249
|
+
if (!editMode) {
|
|
1027
1250
|
if (document.activeElement === copyPasteTextAreaRef.current) {
|
|
1028
1251
|
setFocusToTextArea();
|
|
1029
1252
|
} else {
|
|
@@ -1177,18 +1400,26 @@ function Sheet(props) {
|
|
|
1177
1400
|
pasteLocX = selection.x1;
|
|
1178
1401
|
}
|
|
1179
1402
|
|
|
1180
|
-
if (selection.y1 !== -1 && selection.y2 === -1) {
|
|
1181
|
-
pasteLocY = selection.y1;
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
1403
|
if (selection.x1 !== -1 && selection.x2 !== -1) {
|
|
1185
1404
|
pasteLocX = Math.min(selection.x1, selection.x2);
|
|
1186
1405
|
}
|
|
1187
1406
|
|
|
1407
|
+
if (selection.x1 === -1 && selection.x2 === -1 && selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1408
|
+
pasteLocX = 0;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
if (selection.y1 !== -1 && selection.y2 === -1) {
|
|
1412
|
+
pasteLocY = selection.y1;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1188
1415
|
if (selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1189
1416
|
pasteLocY = Math.min(selection.y1, selection.y2);
|
|
1190
1417
|
}
|
|
1191
1418
|
|
|
1419
|
+
if (selection.y1 === -1 && selection.y2 === -1 && selection.x2 !== -1 && selection.x2 !== -1) {
|
|
1420
|
+
pasteLocY = 0;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1192
1423
|
if (pasteLocX === -1 || pasteLocY === -1) {
|
|
1193
1424
|
return;
|
|
1194
1425
|
}
|
|
@@ -1222,7 +1453,7 @@ function Sheet(props) {
|
|
|
1222
1453
|
};
|
|
1223
1454
|
|
|
1224
1455
|
var setCopyPasteText = function setCopyPasteText() {
|
|
1225
|
-
if (selection.x1 === -1
|
|
1456
|
+
if (selection.x1 === -1 && selection.y1 === -1 && selection.x2 === -1 && selection.y2 === -1) {
|
|
1226
1457
|
return;
|
|
1227
1458
|
}
|
|
1228
1459
|
|
|
@@ -1242,25 +1473,46 @@ function Sheet(props) {
|
|
|
1242
1473
|
dx2 = selection.x1;
|
|
1243
1474
|
}
|
|
1244
1475
|
|
|
1245
|
-
var
|
|
1476
|
+
var max = findApproxMaxEditDataIndex(editData);
|
|
1477
|
+
|
|
1478
|
+
if (dx1 === -1 && dx2 === -1) {
|
|
1479
|
+
dx1 = 0;
|
|
1480
|
+
dx2 = max.x;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
if (dy1 === -1 && dy2 === -1) {
|
|
1484
|
+
dy1 = 0;
|
|
1485
|
+
dy2 = max.y;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
var cptext = '';
|
|
1489
|
+
var cptextTemp = '';
|
|
1246
1490
|
|
|
1247
1491
|
for (var y = dy1; y <= dy2; y++) {
|
|
1248
|
-
var
|
|
1492
|
+
var nonEmpty = false;
|
|
1249
1493
|
|
|
1250
1494
|
for (var x = dx1; x <= dx2; x++) {
|
|
1251
1495
|
var value = editData(x, y);
|
|
1252
1496
|
|
|
1253
1497
|
if (value !== null && value !== undefined) {
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1498
|
+
cptextTemp += value;
|
|
1499
|
+
nonEmpty = true;
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
if (x !== dx2) {
|
|
1503
|
+
cptextTemp += '\t';
|
|
1257
1504
|
}
|
|
1258
1505
|
}
|
|
1259
1506
|
|
|
1260
|
-
|
|
1261
|
-
|
|
1507
|
+
if (y !== dy2) {
|
|
1508
|
+
cptextTemp += '\n';
|
|
1509
|
+
}
|
|
1262
1510
|
|
|
1263
|
-
|
|
1511
|
+
if (nonEmpty) {
|
|
1512
|
+
cptext += cptextTemp;
|
|
1513
|
+
cptextTemp = '';
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1264
1516
|
|
|
1265
1517
|
if (copyPasteTextAreaRef.current) {
|
|
1266
1518
|
copyPasteTextAreaRef.current.value = cptext;
|
|
@@ -1272,7 +1524,7 @@ function Sheet(props) {
|
|
|
1272
1524
|
props.onChange([{
|
|
1273
1525
|
x: editCell.x,
|
|
1274
1526
|
y: editCell.y,
|
|
1275
|
-
value: value
|
|
1527
|
+
value: value !== undefined ? value : editValue
|
|
1276
1528
|
}]);
|
|
1277
1529
|
}
|
|
1278
1530
|
|
|
@@ -1299,6 +1551,7 @@ function Sheet(props) {
|
|
|
1299
1551
|
setEditCell(editCell);
|
|
1300
1552
|
setEditKey(editDataKey);
|
|
1301
1553
|
setEditValue(val);
|
|
1554
|
+
setShiftKeyDown(false);
|
|
1302
1555
|
};
|
|
1303
1556
|
|
|
1304
1557
|
var onScroll = function onScroll(e) {
|
|
@@ -1385,10 +1638,25 @@ function Sheet(props) {
|
|
|
1385
1638
|
|
|
1386
1639
|
if (Math.abs(start - x) < resizeColumnRowMouseThreshold || Math.abs(end - x) < resizeColumnRowMouseThreshold) {
|
|
1387
1640
|
window.document.body.style.cursor = 'col-resize';
|
|
1641
|
+
var indices = [];
|
|
1642
|
+
|
|
1643
|
+
if (selection.x1 !== -1 && selection.x2 !== -1 && selection.y1 === -1 && selection.y2 === -1) {
|
|
1644
|
+
var min = Math.min(selection.x1, selection.x2);
|
|
1645
|
+
var max = Math.max(selection.x1, selection.x2);
|
|
1646
|
+
|
|
1647
|
+
for (var i = min; i <= max; i++) {
|
|
1648
|
+
indices.push(i);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
if (indices.length === 0) {
|
|
1653
|
+
indices.push(index);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1388
1656
|
setColumnResize({
|
|
1389
1657
|
startX: end,
|
|
1390
1658
|
oldWidth: cellWidth(index),
|
|
1391
|
-
|
|
1659
|
+
colIndices: indices
|
|
1392
1660
|
});
|
|
1393
1661
|
return;
|
|
1394
1662
|
}
|
|
@@ -1403,10 +1671,26 @@ function Sheet(props) {
|
|
|
1403
1671
|
|
|
1404
1672
|
if (Math.abs(_start - y) < resizeColumnRowMouseThreshold || Math.abs(_end - y) < resizeColumnRowMouseThreshold) {
|
|
1405
1673
|
window.document.body.style.cursor = 'row-resize';
|
|
1674
|
+
var _indices = [];
|
|
1675
|
+
|
|
1676
|
+
if (selection.x1 === -1 && selection.x2 === -1 && selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1677
|
+
var _min = Math.min(selection.y1, selection.y2);
|
|
1678
|
+
|
|
1679
|
+
var _max = Math.max(selection.y1, selection.y2);
|
|
1680
|
+
|
|
1681
|
+
for (var _i5 = _min; _i5 <= _max; _i5++) {
|
|
1682
|
+
_indices.push(_i5);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
if (_indices.length === 0) {
|
|
1687
|
+
_indices.push(_index);
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1406
1690
|
setRowResize({
|
|
1407
1691
|
startY: _end,
|
|
1408
1692
|
oldHeight: cellHeight(_index),
|
|
1409
|
-
|
|
1693
|
+
rowIndices: _indices
|
|
1410
1694
|
});
|
|
1411
1695
|
return;
|
|
1412
1696
|
}
|
|
@@ -1437,17 +1721,19 @@ function Sheet(props) {
|
|
|
1437
1721
|
var scrollToP2 = true;
|
|
1438
1722
|
|
|
1439
1723
|
if (x < rowHeaderWidth) {
|
|
1440
|
-
sel2.x = dataOffset.x + 100;
|
|
1441
1724
|
scrollToP2 = false;
|
|
1442
1725
|
setRowSelectionInProgress(true);
|
|
1726
|
+
sel1.x = -1;
|
|
1727
|
+
sel2.x = -1;
|
|
1443
1728
|
} else {
|
|
1444
1729
|
setRowSelectionInProgress(false);
|
|
1445
1730
|
}
|
|
1446
1731
|
|
|
1447
1732
|
if (y < columnHeaderHeight) {
|
|
1448
|
-
sel2.y = dataOffset.y + 100;
|
|
1449
1733
|
scrollToP2 = false;
|
|
1450
1734
|
setColumnSelectionInProgress(true);
|
|
1735
|
+
sel1.y = -1;
|
|
1736
|
+
sel2.y = -1;
|
|
1451
1737
|
} else {
|
|
1452
1738
|
setColumnSelectionInProgress(false);
|
|
1453
1739
|
}
|
|
@@ -1508,6 +1794,11 @@ function Sheet(props) {
|
|
|
1508
1794
|
fy2 = sy1 - 1;
|
|
1509
1795
|
}
|
|
1510
1796
|
|
|
1797
|
+
if (fx1 === -1 && fx2 === -1) {
|
|
1798
|
+
fx1 = 0;
|
|
1799
|
+
fx2 = maxSearchableRowOrCol;
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1511
1802
|
var srcY = sy1;
|
|
1512
1803
|
|
|
1513
1804
|
for (var y = fy1; y <= fy2; y++) {
|
|
@@ -1533,6 +1824,11 @@ function Sheet(props) {
|
|
|
1533
1824
|
fx2 = sx1 - 1;
|
|
1534
1825
|
}
|
|
1535
1826
|
|
|
1827
|
+
if (fy1 === -1 && fy2 === -1) {
|
|
1828
|
+
fy1 = 0;
|
|
1829
|
+
fy2 = maxSearchableRowOrCol;
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1536
1832
|
var srcX = sx1;
|
|
1537
1833
|
|
|
1538
1834
|
for (var _x3 = fx1; _x3 <= fx2; _x3++) {
|
|
@@ -1659,7 +1955,7 @@ function Sheet(props) {
|
|
|
1659
1955
|
if (columnResize) {
|
|
1660
1956
|
if (props.onCellWidthChange) {
|
|
1661
1957
|
var newWidth = Math.max(columnResize.oldWidth + x - columnResize.startX, minimumColumnWidth);
|
|
1662
|
-
props.onCellWidthChange(columnResize.
|
|
1958
|
+
props.onCellWidthChange(columnResize.colIndices, newWidth);
|
|
1663
1959
|
}
|
|
1664
1960
|
|
|
1665
1961
|
return;
|
|
@@ -1668,7 +1964,7 @@ function Sheet(props) {
|
|
|
1668
1964
|
if (rowResize) {
|
|
1669
1965
|
if (props.onCellHeightChange) {
|
|
1670
1966
|
var newHeight = Math.max(rowResize.oldHeight + y - rowResize.startY, minimumRowHeight);
|
|
1671
|
-
props.onCellHeightChange(rowResize.
|
|
1967
|
+
props.onCellHeightChange(rowResize.rowIndices, newHeight);
|
|
1672
1968
|
}
|
|
1673
1969
|
|
|
1674
1970
|
return;
|
|
@@ -1678,9 +1974,9 @@ function Sheet(props) {
|
|
|
1678
1974
|
var sel2 = absCoordianteToCell(x, y, rowSizes, columnSizes);
|
|
1679
1975
|
|
|
1680
1976
|
if (rowSelectionInProgress) {
|
|
1681
|
-
changeSelection(
|
|
1977
|
+
changeSelection(-1, selection.y1, -1, sel2.y, false);
|
|
1682
1978
|
} else if (columnSelectionInProgress) {
|
|
1683
|
-
changeSelection(selection.x1,
|
|
1979
|
+
changeSelection(selection.x1, -1, sel2.x, -1, false);
|
|
1684
1980
|
} else {
|
|
1685
1981
|
changeSelection(selection.x1, selection.y1, sel2.x, sel2.y);
|
|
1686
1982
|
}
|
|
@@ -1711,7 +2007,7 @@ function Sheet(props) {
|
|
|
1711
2007
|
if (cell.y < y1) yCellDiff = cell.y - y1;
|
|
1712
2008
|
if (cell.y > y2) yCellDiff = y2 - cell.y;
|
|
1713
2009
|
|
|
1714
|
-
if (xCellDiff > yCellDiff) {
|
|
2010
|
+
if (x1 === -1 && x2 === -1 || xCellDiff > yCellDiff) {
|
|
1715
2011
|
if (cell.y < y1) {
|
|
1716
2012
|
y1 = cell.y;
|
|
1717
2013
|
} else {
|
|
@@ -1844,6 +2140,16 @@ function Sheet(props) {
|
|
|
1844
2140
|
y2 = selection.y1;
|
|
1845
2141
|
}
|
|
1846
2142
|
|
|
2143
|
+
if (x1 === -1 && x2 === -1 && y1 !== -1 && y2 !== -1) {
|
|
2144
|
+
x1 = 0;
|
|
2145
|
+
x2 = maxSearchableRowOrCol;
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
if (x1 !== -1 && x2 !== -1 && y1 === -1 && y2 === -1) {
|
|
2149
|
+
y1 = 0;
|
|
2150
|
+
y2 = maxSearchableRowOrCol;
|
|
2151
|
+
}
|
|
2152
|
+
|
|
1847
2153
|
var changes = [];
|
|
1848
2154
|
|
|
1849
2155
|
for (var y = y1; y <= y2; y++) {
|
|
@@ -1890,17 +2196,35 @@ function Sheet(props) {
|
|
|
1890
2196
|
x: selection.x2,
|
|
1891
2197
|
y: selection.y2
|
|
1892
2198
|
};
|
|
2199
|
+
var incr = {
|
|
2200
|
+
x: 0,
|
|
2201
|
+
y: 0
|
|
2202
|
+
};
|
|
2203
|
+
var direction = 'right';
|
|
1893
2204
|
|
|
1894
2205
|
if (e.key === 'ArrowRight' || e.key === 'Tab') {
|
|
1895
|
-
|
|
2206
|
+
incr.x = 1;
|
|
2207
|
+
direction = 'right';
|
|
1896
2208
|
} else if (e.key === 'ArrowLeft') {
|
|
1897
|
-
|
|
2209
|
+
incr.x = -1;
|
|
2210
|
+
direction = 'left';
|
|
1898
2211
|
} else if (e.key === 'ArrowUp') {
|
|
1899
|
-
|
|
2212
|
+
incr.y = -1;
|
|
2213
|
+
direction = 'up';
|
|
1900
2214
|
} else if (e.key === 'ArrowDown') {
|
|
1901
|
-
|
|
2215
|
+
incr.y = 1;
|
|
2216
|
+
direction = 'down';
|
|
1902
2217
|
}
|
|
1903
2218
|
|
|
2219
|
+
if (e.metaKey || e.ctrlKey) {
|
|
2220
|
+
var val = findInDisplayData(displayData, sel2, direction);
|
|
2221
|
+
incr.x = val.x - sel2.x;
|
|
2222
|
+
incr.y = val.y - sel2.y;
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
sel2.x += incr.x;
|
|
2226
|
+
sel2.y += incr.y;
|
|
2227
|
+
|
|
1904
2228
|
if (sel2.x < 0) {
|
|
1905
2229
|
sel2.x = 0;
|
|
1906
2230
|
}
|
|
@@ -2070,13 +2394,17 @@ function Sheet(props) {
|
|
|
2070
2394
|
opacity: 0.01
|
|
2071
2395
|
},
|
|
2072
2396
|
ref: copyPasteTextAreaRef,
|
|
2397
|
+
autoComplete: "off",
|
|
2398
|
+
autoCorrect: "off",
|
|
2399
|
+
autoCapitalize: "off",
|
|
2400
|
+
spellCheck: "false",
|
|
2073
2401
|
onFocus: function onFocus(e) {
|
|
2074
2402
|
return e.target.select();
|
|
2075
2403
|
},
|
|
2076
2404
|
tabIndex: 0,
|
|
2077
2405
|
onKeyDown: onGridKeyDown,
|
|
2078
2406
|
onKeyUp: onGridKeyUp
|
|
2079
|
-
}), editMode && (input
|
|
2407
|
+
}), editMode && (input !== undefined ? input : React.createElement("input", Object.assign({}, inputProps, {
|
|
2080
2408
|
type: "text",
|
|
2081
2409
|
onFocus: function onFocus(e) {
|
|
2082
2410
|
return e.target.select();
|