sheet-happens 0.0.8 → 0.0.11
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/README.md +30 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +88 -28
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +88 -28
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -638,45 +638,49 @@ function Sheet(props) {
|
|
|
638
638
|
editValue = _useState6[0],
|
|
639
639
|
setEditValue = _useState6[1];
|
|
640
640
|
|
|
641
|
-
var _useState7 = useState(
|
|
642
|
-
|
|
643
|
-
|
|
641
|
+
var _useState7 = useState(''),
|
|
642
|
+
editKey = _useState7[0],
|
|
643
|
+
setEditKey = _useState7[1];
|
|
644
644
|
|
|
645
645
|
var _useState8 = useState(false),
|
|
646
|
-
|
|
647
|
-
|
|
646
|
+
arrowKeyCommitMode = _useState8[0],
|
|
647
|
+
setArrowKeyCommitMode = _useState8[1];
|
|
648
648
|
|
|
649
649
|
var _useState9 = useState(false),
|
|
650
|
-
|
|
651
|
-
|
|
650
|
+
shiftKeyDown = _useState9[0],
|
|
651
|
+
setShiftKeyDown = _useState9[1];
|
|
652
652
|
|
|
653
653
|
var _useState10 = useState(false),
|
|
654
|
-
|
|
655
|
-
|
|
654
|
+
knobDragInProgress = _useState10[0],
|
|
655
|
+
setKnobDragInProgress = _useState10[1];
|
|
656
656
|
|
|
657
|
-
var _useState11 = useState(
|
|
658
|
-
|
|
659
|
-
|
|
657
|
+
var _useState11 = useState(false),
|
|
658
|
+
selectionInProgress = _useState11[0],
|
|
659
|
+
setSelectionInProgress = _useState11[1];
|
|
660
660
|
|
|
661
661
|
var _useState12 = useState(null),
|
|
662
|
-
|
|
663
|
-
|
|
662
|
+
columnResize = _useState12[0],
|
|
663
|
+
setColumnResize = _useState12[1];
|
|
664
664
|
|
|
665
|
-
var _useState13 = useState(
|
|
666
|
-
|
|
667
|
-
|
|
665
|
+
var _useState13 = useState(null),
|
|
666
|
+
rowResize = _useState13[0],
|
|
667
|
+
setRowResize = _useState13[1];
|
|
668
668
|
|
|
669
669
|
var _useState14 = useState(false),
|
|
670
|
-
|
|
671
|
-
|
|
670
|
+
rowSelectionInProgress = _useState14[0],
|
|
671
|
+
setRowSelectionInProgress = _useState14[1];
|
|
672
672
|
|
|
673
|
-
var _useState15 = useState(
|
|
673
|
+
var _useState15 = useState(false),
|
|
674
|
+
columnSelectionInProgress = _useState15[0],
|
|
675
|
+
setColumnSelectionInProgress = _useState15[1];
|
|
676
|
+
|
|
677
|
+
var _useState16 = useState({
|
|
674
678
|
x: -1,
|
|
675
679
|
y: -1,
|
|
676
680
|
hitTarget: null
|
|
677
681
|
}),
|
|
678
|
-
buttonClickMouseDownCoordinates =
|
|
679
|
-
setButtonClickMouseDownCoordinates =
|
|
682
|
+
buttonClickMouseDownCoordinates = _useState16[0],
|
|
683
|
+
setButtonClickMouseDownCoordinates = _useState16[1];
|
|
680
684
|
|
|
681
685
|
var _useResizeObserver = useResizeObserver({
|
|
682
686
|
ref: canvasRef
|
|
@@ -712,9 +716,23 @@ function Sheet(props) {
|
|
|
712
716
|
var editData = useMemo(function () {
|
|
713
717
|
return createCellPropFunction(props.editData, '');
|
|
714
718
|
}, [props.editData]);
|
|
719
|
+
var editKeys = useMemo(function () {
|
|
720
|
+
return createCellPropFunction(props.editKeys, '');
|
|
721
|
+
}, [props.editKeys]);
|
|
715
722
|
var cellStyle = useMemo(function () {
|
|
716
723
|
return createCellPropFunction(props.cellStyle, defaultCellStyle);
|
|
717
724
|
}, [props.cellStyle]);
|
|
725
|
+
useEffect(function () {
|
|
726
|
+
var currEditKey = editKeys ? editKeys(editCell.x, editCell.y) : '';
|
|
727
|
+
|
|
728
|
+
if (currEditKey !== editKey) {
|
|
729
|
+
setEditCell({
|
|
730
|
+
x: -1,
|
|
731
|
+
y: -1
|
|
732
|
+
});
|
|
733
|
+
setEditKey('');
|
|
734
|
+
}
|
|
735
|
+
}, [editKeys]);
|
|
718
736
|
var columnSizes = useMemo(function () {
|
|
719
737
|
return calculateRowsOrColsSizes(freezeColumns, cellWidth, rowHeaderWidth, dataOffset.x, canvasWidth);
|
|
720
738
|
}, [props.freezeColumns, cellWidth, dataOffset.x, canvasWidth]);
|
|
@@ -1111,10 +1129,26 @@ function Sheet(props) {
|
|
|
1111
1129
|
var td = _step18.value;
|
|
1112
1130
|
|
|
1113
1131
|
if (td.nodeName === 'TD') {
|
|
1132
|
+
var str = '';
|
|
1133
|
+
|
|
1134
|
+
if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
|
|
1135
|
+
var p = td.children[0];
|
|
1136
|
+
|
|
1137
|
+
if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
|
|
1138
|
+
str = p.children[0].innerHTML;
|
|
1139
|
+
} else {
|
|
1140
|
+
str = p.innerHTML;
|
|
1141
|
+
}
|
|
1142
|
+
} else {
|
|
1143
|
+
str = td.innerHTML;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
str = str.replaceAll('\n', '');
|
|
1147
|
+
str = str.replaceAll(/\s\s+/g, ' ');
|
|
1114
1148
|
changes.push({
|
|
1115
1149
|
y: y,
|
|
1116
1150
|
x: x,
|
|
1117
|
-
value:
|
|
1151
|
+
value: str
|
|
1118
1152
|
});
|
|
1119
1153
|
x++;
|
|
1120
1154
|
}
|
|
@@ -1246,6 +1280,7 @@ function Sheet(props) {
|
|
|
1246
1280
|
x: -1,
|
|
1247
1281
|
y: -1
|
|
1248
1282
|
});
|
|
1283
|
+
setEditKey('');
|
|
1249
1284
|
};
|
|
1250
1285
|
|
|
1251
1286
|
var startEditingCell = function startEditingCell(editCell) {
|
|
@@ -1260,7 +1295,9 @@ function Sheet(props) {
|
|
|
1260
1295
|
val = editDataValue;
|
|
1261
1296
|
}
|
|
1262
1297
|
|
|
1298
|
+
var editDataKey = editKeys ? editKeys(editCell.x, editCell.y) : '';
|
|
1263
1299
|
setEditCell(editCell);
|
|
1300
|
+
setEditKey(editDataKey);
|
|
1264
1301
|
setEditValue(val);
|
|
1265
1302
|
};
|
|
1266
1303
|
|
|
@@ -1396,7 +1433,7 @@ function Sheet(props) {
|
|
|
1396
1433
|
var scrollToP2 = true;
|
|
1397
1434
|
|
|
1398
1435
|
if (x < rowHeaderWidth) {
|
|
1399
|
-
sel2.x = 100;
|
|
1436
|
+
sel2.x = dataOffset.x + 100;
|
|
1400
1437
|
scrollToP2 = false;
|
|
1401
1438
|
setRowSelectionInProgress(true);
|
|
1402
1439
|
} else {
|
|
@@ -1404,7 +1441,7 @@ function Sheet(props) {
|
|
|
1404
1441
|
}
|
|
1405
1442
|
|
|
1406
1443
|
if (y < columnHeaderHeight) {
|
|
1407
|
-
sel2.y = 100;
|
|
1444
|
+
sel2.y = dataOffset.y + 100;
|
|
1408
1445
|
scrollToP2 = false;
|
|
1409
1446
|
setColumnSelectionInProgress(true);
|
|
1410
1447
|
} else {
|
|
@@ -1417,6 +1454,7 @@ function Sheet(props) {
|
|
|
1417
1454
|
x: -1,
|
|
1418
1455
|
y: -1
|
|
1419
1456
|
});
|
|
1457
|
+
setEditKey('');
|
|
1420
1458
|
};
|
|
1421
1459
|
|
|
1422
1460
|
var onMouseUp = function onMouseUp(e) {
|
|
@@ -1540,7 +1578,7 @@ function Sheet(props) {
|
|
|
1540
1578
|
var hitTarget = buttonClickMouseDownCoordinates.hitTarget;
|
|
1541
1579
|
|
|
1542
1580
|
if (hitTarget.x <= _x4 && _x4 <= hitTarget.x + hitTarget.w && hitTarget.y <= _y3 && _y3 <= hitTarget.y + hitTarget.h) {
|
|
1543
|
-
hitTarget.onClick();
|
|
1581
|
+
hitTarget.onClick(e);
|
|
1544
1582
|
}
|
|
1545
1583
|
|
|
1546
1584
|
setButtonClickMouseDownCoordinates({
|
|
@@ -1662,7 +1700,14 @@ function Sheet(props) {
|
|
|
1662
1700
|
y2 = selection.y1;
|
|
1663
1701
|
}
|
|
1664
1702
|
|
|
1665
|
-
|
|
1703
|
+
var xCellDiff = 0;
|
|
1704
|
+
if (cell.x < x1) xCellDiff = cell.x - x1;
|
|
1705
|
+
if (cell.x > x2) xCellDiff = x2 - cell.x;
|
|
1706
|
+
var yCellDiff = 0;
|
|
1707
|
+
if (cell.y < y1) yCellDiff = cell.y - y1;
|
|
1708
|
+
if (cell.y > y2) yCellDiff = y2 - cell.y;
|
|
1709
|
+
|
|
1710
|
+
if (xCellDiff > yCellDiff) {
|
|
1666
1711
|
if (cell.y < y1) {
|
|
1667
1712
|
y1 = cell.y;
|
|
1668
1713
|
} else {
|
|
@@ -1686,7 +1731,9 @@ function Sheet(props) {
|
|
|
1686
1731
|
};
|
|
1687
1732
|
|
|
1688
1733
|
var onDoubleClick = function onDoubleClick(e) {
|
|
1689
|
-
|
|
1734
|
+
e.preventDefault();
|
|
1735
|
+
|
|
1736
|
+
if (!e.target || !(e.target instanceof Element) || shiftKeyDown) {
|
|
1690
1737
|
return;
|
|
1691
1738
|
}
|
|
1692
1739
|
|
|
@@ -1717,6 +1764,7 @@ function Sheet(props) {
|
|
|
1717
1764
|
x: -1,
|
|
1718
1765
|
y: -1
|
|
1719
1766
|
});
|
|
1767
|
+
setEditKey('');
|
|
1720
1768
|
return;
|
|
1721
1769
|
}
|
|
1722
1770
|
|
|
@@ -1890,6 +1938,18 @@ function Sheet(props) {
|
|
|
1890
1938
|
y1 = selection.y1,
|
|
1891
1939
|
y2 = selection.y2;
|
|
1892
1940
|
|
|
1941
|
+
if (x1 > x2) {
|
|
1942
|
+
var _ref = [x2, x1];
|
|
1943
|
+
x1 = _ref[0];
|
|
1944
|
+
x2 = _ref[1];
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
if (y1 > y2) {
|
|
1948
|
+
var _ref2 = [y2, y1];
|
|
1949
|
+
y1 = _ref2[0];
|
|
1950
|
+
y2 = _ref2[1];
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1893
1953
|
if (!(y > columnHeaderHeight && x > rowHeaderWidth)) {
|
|
1894
1954
|
return;
|
|
1895
1955
|
}
|