sheet-happens 0.0.12 → 0.0.14
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 +3 -2
- package/dist/index.js +393 -62
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +393 -62
- 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 {
|
|
@@ -1052,12 +1275,12 @@ function Sheet(props) {
|
|
|
1052
1275
|
var clipboardData = e.clipboardData || window.clipboardData;
|
|
1053
1276
|
var types = clipboardData.types;
|
|
1054
1277
|
|
|
1055
|
-
if (types.includes('text/html')) {
|
|
1056
|
-
var pastedHtml = clipboardData.getData('text/html');
|
|
1057
|
-
parsePastedHtml(pastedHtml);
|
|
1058
|
-
} else if (types.includes('text/plain')) {
|
|
1278
|
+
if (types.includes('text/rtf') && types.includes('text/plain') || types.includes('text/plain') && !types.includes('text/html')) {
|
|
1059
1279
|
var text = clipboardData.getData('text/plain');
|
|
1060
1280
|
parsePastedText(text);
|
|
1281
|
+
} else if (types.includes('text/html')) {
|
|
1282
|
+
var pastedHtml = clipboardData.getData('text/html');
|
|
1283
|
+
parsePastedHtml(pastedHtml);
|
|
1061
1284
|
}
|
|
1062
1285
|
};
|
|
1063
1286
|
|
|
@@ -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
|
|
|
@@ -1319,6 +1571,10 @@ function Sheet(props) {
|
|
|
1319
1571
|
x: cellX,
|
|
1320
1572
|
y: cellY
|
|
1321
1573
|
});
|
|
1574
|
+
|
|
1575
|
+
if (props.onScrollChange) {
|
|
1576
|
+
props.onScrollChange(cellX, cellY);
|
|
1577
|
+
}
|
|
1322
1578
|
}
|
|
1323
1579
|
|
|
1324
1580
|
var newMaxScroll = _extends({}, maxScroll);
|
|
@@ -1384,10 +1640,25 @@ function Sheet(props) {
|
|
|
1384
1640
|
|
|
1385
1641
|
if (Math.abs(start - x) < resizeColumnRowMouseThreshold || Math.abs(end - x) < resizeColumnRowMouseThreshold) {
|
|
1386
1642
|
window.document.body.style.cursor = 'col-resize';
|
|
1643
|
+
var indices = [];
|
|
1644
|
+
|
|
1645
|
+
if (selection.x1 !== -1 && selection.x2 !== -1 && selection.y1 === -1 && selection.y2 === -1) {
|
|
1646
|
+
var min = Math.min(selection.x1, selection.x2);
|
|
1647
|
+
var max = Math.max(selection.x1, selection.x2);
|
|
1648
|
+
|
|
1649
|
+
for (var i = min; i <= max; i++) {
|
|
1650
|
+
indices.push(i);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
if (indices.length === 0) {
|
|
1655
|
+
indices.push(index);
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1387
1658
|
setColumnResize({
|
|
1388
1659
|
startX: end,
|
|
1389
1660
|
oldWidth: cellWidth(index),
|
|
1390
|
-
|
|
1661
|
+
colIndices: indices
|
|
1391
1662
|
});
|
|
1392
1663
|
return;
|
|
1393
1664
|
}
|
|
@@ -1402,10 +1673,26 @@ function Sheet(props) {
|
|
|
1402
1673
|
|
|
1403
1674
|
if (Math.abs(_start - y) < resizeColumnRowMouseThreshold || Math.abs(_end - y) < resizeColumnRowMouseThreshold) {
|
|
1404
1675
|
window.document.body.style.cursor = 'row-resize';
|
|
1676
|
+
var _indices = [];
|
|
1677
|
+
|
|
1678
|
+
if (selection.x1 === -1 && selection.x2 === -1 && selection.y1 !== -1 && selection.y2 !== -1) {
|
|
1679
|
+
var _min = Math.min(selection.y1, selection.y2);
|
|
1680
|
+
|
|
1681
|
+
var _max = Math.max(selection.y1, selection.y2);
|
|
1682
|
+
|
|
1683
|
+
for (var _i5 = _min; _i5 <= _max; _i5++) {
|
|
1684
|
+
_indices.push(_i5);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
if (_indices.length === 0) {
|
|
1689
|
+
_indices.push(_index);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1405
1692
|
setRowResize({
|
|
1406
1693
|
startY: _end,
|
|
1407
1694
|
oldHeight: cellHeight(_index),
|
|
1408
|
-
|
|
1695
|
+
rowIndices: _indices
|
|
1409
1696
|
});
|
|
1410
1697
|
return;
|
|
1411
1698
|
}
|
|
@@ -1436,17 +1723,19 @@ function Sheet(props) {
|
|
|
1436
1723
|
var scrollToP2 = true;
|
|
1437
1724
|
|
|
1438
1725
|
if (x < rowHeaderWidth) {
|
|
1439
|
-
sel2.x = dataOffset.x + 100;
|
|
1440
1726
|
scrollToP2 = false;
|
|
1441
1727
|
setRowSelectionInProgress(true);
|
|
1728
|
+
sel1.x = -1;
|
|
1729
|
+
sel2.x = -1;
|
|
1442
1730
|
} else {
|
|
1443
1731
|
setRowSelectionInProgress(false);
|
|
1444
1732
|
}
|
|
1445
1733
|
|
|
1446
1734
|
if (y < columnHeaderHeight) {
|
|
1447
|
-
sel2.y = dataOffset.y + 100;
|
|
1448
1735
|
scrollToP2 = false;
|
|
1449
1736
|
setColumnSelectionInProgress(true);
|
|
1737
|
+
sel1.y = -1;
|
|
1738
|
+
sel2.y = -1;
|
|
1450
1739
|
} else {
|
|
1451
1740
|
setColumnSelectionInProgress(false);
|
|
1452
1741
|
}
|
|
@@ -1507,6 +1796,11 @@ function Sheet(props) {
|
|
|
1507
1796
|
fy2 = sy1 - 1;
|
|
1508
1797
|
}
|
|
1509
1798
|
|
|
1799
|
+
if (fx1 === -1 && fx2 === -1) {
|
|
1800
|
+
fx1 = 0;
|
|
1801
|
+
fx2 = maxSearchableRowOrCol;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1510
1804
|
var srcY = sy1;
|
|
1511
1805
|
|
|
1512
1806
|
for (var y = fy1; y <= fy2; y++) {
|
|
@@ -1532,6 +1826,11 @@ function Sheet(props) {
|
|
|
1532
1826
|
fx2 = sx1 - 1;
|
|
1533
1827
|
}
|
|
1534
1828
|
|
|
1829
|
+
if (fy1 === -1 && fy2 === -1) {
|
|
1830
|
+
fy1 = 0;
|
|
1831
|
+
fy2 = maxSearchableRowOrCol;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1535
1834
|
var srcX = sx1;
|
|
1536
1835
|
|
|
1537
1836
|
for (var _x3 = fx1; _x3 <= fx2; _x3++) {
|
|
@@ -1658,7 +1957,7 @@ function Sheet(props) {
|
|
|
1658
1957
|
if (columnResize) {
|
|
1659
1958
|
if (props.onCellWidthChange) {
|
|
1660
1959
|
var newWidth = Math.max(columnResize.oldWidth + x - columnResize.startX, minimumColumnWidth);
|
|
1661
|
-
props.onCellWidthChange(columnResize.
|
|
1960
|
+
props.onCellWidthChange(columnResize.colIndices, newWidth);
|
|
1662
1961
|
}
|
|
1663
1962
|
|
|
1664
1963
|
return;
|
|
@@ -1667,7 +1966,7 @@ function Sheet(props) {
|
|
|
1667
1966
|
if (rowResize) {
|
|
1668
1967
|
if (props.onCellHeightChange) {
|
|
1669
1968
|
var newHeight = Math.max(rowResize.oldHeight + y - rowResize.startY, minimumRowHeight);
|
|
1670
|
-
props.onCellHeightChange(rowResize.
|
|
1969
|
+
props.onCellHeightChange(rowResize.rowIndices, newHeight);
|
|
1671
1970
|
}
|
|
1672
1971
|
|
|
1673
1972
|
return;
|
|
@@ -1677,9 +1976,9 @@ function Sheet(props) {
|
|
|
1677
1976
|
var sel2 = absCoordianteToCell(x, y, rowSizes, columnSizes);
|
|
1678
1977
|
|
|
1679
1978
|
if (rowSelectionInProgress) {
|
|
1680
|
-
changeSelection(
|
|
1979
|
+
changeSelection(-1, selection.y1, -1, sel2.y, false);
|
|
1681
1980
|
} else if (columnSelectionInProgress) {
|
|
1682
|
-
changeSelection(selection.x1,
|
|
1981
|
+
changeSelection(selection.x1, -1, sel2.x, -1, false);
|
|
1683
1982
|
} else {
|
|
1684
1983
|
changeSelection(selection.x1, selection.y1, sel2.x, sel2.y);
|
|
1685
1984
|
}
|
|
@@ -1710,7 +2009,7 @@ function Sheet(props) {
|
|
|
1710
2009
|
if (cell.y < y1) yCellDiff = cell.y - y1;
|
|
1711
2010
|
if (cell.y > y2) yCellDiff = y2 - cell.y;
|
|
1712
2011
|
|
|
1713
|
-
if (xCellDiff > yCellDiff) {
|
|
2012
|
+
if (x1 === -1 && x2 === -1 || xCellDiff > yCellDiff) {
|
|
1714
2013
|
if (cell.y < y1) {
|
|
1715
2014
|
y1 = cell.y;
|
|
1716
2015
|
} else {
|
|
@@ -1843,6 +2142,16 @@ function Sheet(props) {
|
|
|
1843
2142
|
y2 = selection.y1;
|
|
1844
2143
|
}
|
|
1845
2144
|
|
|
2145
|
+
if (x1 === -1 && x2 === -1 && y1 !== -1 && y2 !== -1) {
|
|
2146
|
+
x1 = 0;
|
|
2147
|
+
x2 = maxSearchableRowOrCol;
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
if (x1 !== -1 && x2 !== -1 && y1 === -1 && y2 === -1) {
|
|
2151
|
+
y1 = 0;
|
|
2152
|
+
y2 = maxSearchableRowOrCol;
|
|
2153
|
+
}
|
|
2154
|
+
|
|
1846
2155
|
var changes = [];
|
|
1847
2156
|
|
|
1848
2157
|
for (var y = y1; y <= y2; y++) {
|
|
@@ -1889,17 +2198,35 @@ function Sheet(props) {
|
|
|
1889
2198
|
x: selection.x2,
|
|
1890
2199
|
y: selection.y2
|
|
1891
2200
|
};
|
|
2201
|
+
var incr = {
|
|
2202
|
+
x: 0,
|
|
2203
|
+
y: 0
|
|
2204
|
+
};
|
|
2205
|
+
var direction = 'right';
|
|
1892
2206
|
|
|
1893
2207
|
if (e.key === 'ArrowRight' || e.key === 'Tab') {
|
|
1894
|
-
|
|
2208
|
+
incr.x = 1;
|
|
2209
|
+
direction = 'right';
|
|
1895
2210
|
} else if (e.key === 'ArrowLeft') {
|
|
1896
|
-
|
|
2211
|
+
incr.x = -1;
|
|
2212
|
+
direction = 'left';
|
|
1897
2213
|
} else if (e.key === 'ArrowUp') {
|
|
1898
|
-
|
|
2214
|
+
incr.y = -1;
|
|
2215
|
+
direction = 'up';
|
|
1899
2216
|
} else if (e.key === 'ArrowDown') {
|
|
1900
|
-
|
|
2217
|
+
incr.y = 1;
|
|
2218
|
+
direction = 'down';
|
|
1901
2219
|
}
|
|
1902
2220
|
|
|
2221
|
+
if (e.metaKey || e.ctrlKey) {
|
|
2222
|
+
var val = findInDisplayData(displayData, sel2, direction);
|
|
2223
|
+
incr.x = val.x - sel2.x;
|
|
2224
|
+
incr.y = val.y - sel2.y;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
sel2.x += incr.x;
|
|
2228
|
+
sel2.y += incr.y;
|
|
2229
|
+
|
|
1903
2230
|
if (sel2.x < 0) {
|
|
1904
2231
|
sel2.x = 0;
|
|
1905
2232
|
}
|
|
@@ -2069,13 +2396,17 @@ function Sheet(props) {
|
|
|
2069
2396
|
opacity: 0.01
|
|
2070
2397
|
},
|
|
2071
2398
|
ref: copyPasteTextAreaRef,
|
|
2399
|
+
autoComplete: "off",
|
|
2400
|
+
autoCorrect: "off",
|
|
2401
|
+
autoCapitalize: "off",
|
|
2402
|
+
spellCheck: "false",
|
|
2072
2403
|
onFocus: function onFocus(e) {
|
|
2073
2404
|
return e.target.select();
|
|
2074
2405
|
},
|
|
2075
2406
|
tabIndex: 0,
|
|
2076
2407
|
onKeyDown: onGridKeyDown,
|
|
2077
2408
|
onKeyUp: onGridKeyUp
|
|
2078
|
-
}), editMode && (input
|
|
2409
|
+
}), editMode && (input !== undefined ? input : React__default.createElement("input", Object.assign({}, inputProps, {
|
|
2079
2410
|
type: "text",
|
|
2080
2411
|
onFocus: function onFocus(e) {
|
|
2081
2412
|
return e.target.select();
|