sheet-happens 0.0.52 → 0.0.53
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.js +113 -77
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +113 -77
- package/dist/index.modern.js.map +1 -1
- package/dist/mouse.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -645,7 +645,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
|
|
|
645
645
|
return maxXY(cell, [0, 0]);
|
|
646
646
|
};
|
|
647
647
|
|
|
648
|
-
var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onFocusChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
|
|
648
|
+
var useMouse = function useMouse(elementRef, dataOffset, hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onFocusChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
|
|
649
649
|
var _useState = useState(null),
|
|
650
650
|
columnResize = _useState[0],
|
|
651
651
|
setColumnResize = _useState[1];
|
|
@@ -661,18 +661,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
661
661
|
var _useState5 = useState(null),
|
|
662
662
|
hitTestDown = _useState5[0],
|
|
663
663
|
setHitTestDown = _useState5[1];
|
|
664
|
-
var _useState6 = useState(
|
|
665
|
-
|
|
666
|
-
|
|
664
|
+
var _useState6 = useState(null),
|
|
665
|
+
autoScroll = _useState6[0],
|
|
666
|
+
setAutoScroll = _useState6[1];
|
|
667
667
|
var _useState7 = useState(false),
|
|
668
|
-
|
|
669
|
-
|
|
668
|
+
draggingKnob = _useState7[0],
|
|
669
|
+
setDraggingKnob = _useState7[1];
|
|
670
670
|
var _useState8 = useState(false),
|
|
671
|
-
|
|
672
|
-
|
|
671
|
+
draggingSelection = _useState8[0],
|
|
672
|
+
setDraggingSelection = _useState8[1];
|
|
673
673
|
var _useState9 = useState(false),
|
|
674
|
-
|
|
675
|
-
|
|
674
|
+
draggingRowSelection = _useState9[0],
|
|
675
|
+
setDraggingRowSelection = _useState9[1];
|
|
676
|
+
var _useState10 = useState(false),
|
|
677
|
+
draggingColumnSelection = _useState10[0],
|
|
678
|
+
setDraggingColumnSelection = _useState10[1];
|
|
676
679
|
var hideRowHeaders = sheetStyle.hideRowHeaders,
|
|
677
680
|
hideColumnHeaders = sheetStyle.hideColumnHeaders;
|
|
678
681
|
var cellToPixel = cellLayout.cellToPixel,
|
|
@@ -696,6 +699,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
696
699
|
}, [selection, cellToPixel, version]);
|
|
697
700
|
var refState = {
|
|
698
701
|
selection: selection,
|
|
702
|
+
dataOffset: dataOffset,
|
|
699
703
|
knobArea: knobArea,
|
|
700
704
|
editMode: editMode,
|
|
701
705
|
editData: editData,
|
|
@@ -714,27 +718,29 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
714
718
|
};
|
|
715
719
|
var ref = useRef(refState);
|
|
716
720
|
ref.current = refState;
|
|
717
|
-
var getMousePosition = useCallback(function (e) {
|
|
721
|
+
var getMousePosition = useCallback(function (e, strict) {
|
|
718
722
|
if (!e.target || !(e.target instanceof Element)) {
|
|
719
723
|
return null;
|
|
720
724
|
}
|
|
721
725
|
var rect = e.target.getBoundingClientRect();
|
|
722
726
|
var xy = [e.clientX - rect.left, e.clientY - rect.top];
|
|
723
|
-
if (xy[0] > e.target.clientWidth || xy[1] > e.target.clientHeight) {
|
|
727
|
+
if (strict && (xy[0] > e.target.clientWidth || xy[1] > e.target.clientHeight)) {
|
|
724
728
|
return null;
|
|
725
729
|
}
|
|
726
730
|
return xy;
|
|
727
731
|
}, []);
|
|
728
|
-
var
|
|
732
|
+
var getMouseOutOfBounds = useCallback(function (e, allowX, allowY) {
|
|
729
733
|
if (!e.target || !(e.target instanceof Element)) {
|
|
730
|
-
return
|
|
734
|
+
return null;
|
|
731
735
|
}
|
|
732
|
-
var
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
var
|
|
736
|
-
|
|
737
|
-
|
|
736
|
+
var rect = e.target.getBoundingClientRect();
|
|
737
|
+
var xy = [e.clientX - rect.left, e.clientY - rect.top];
|
|
738
|
+
var indentX = cellLayout.getIndentX();
|
|
739
|
+
var indentY = cellLayout.getIndentY();
|
|
740
|
+
var xSign = allowX ? xy[0] < indentX ? -1 : xy[0] > e.target.clientWidth ? 1 : 0 : 0;
|
|
741
|
+
var ySign = allowY ? xy[1] < indentY ? -1 : xy[1] > e.target.clientHeight ? 1 : 0 : 0;
|
|
742
|
+
return xSign || ySign ? [xSign, ySign] : null;
|
|
743
|
+
}, [cellLayout]);
|
|
738
744
|
var getMouseHit = useCallback(function (xy) {
|
|
739
745
|
var hitmap = hitmapRef.current;
|
|
740
746
|
if (!hitmap) return null;
|
|
@@ -751,9 +757,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
751
757
|
window.document.body.style.cursor = 'auto';
|
|
752
758
|
}, []);
|
|
753
759
|
var onPointerDown = useCallback(function (e) {
|
|
754
|
-
var _e$
|
|
760
|
+
var _e$target, _e$target$setPointerC;
|
|
755
761
|
var _ref$current = ref.current,
|
|
756
762
|
selection = _ref$current.selection,
|
|
763
|
+
dataOffset = _ref$current.dataOffset,
|
|
757
764
|
_ref$current$cellLayo = _ref$current.cellLayout,
|
|
758
765
|
columnToPixel = _ref$current$cellLayo.columnToPixel,
|
|
759
766
|
rowToPixel = _ref$current$cellLayo.rowToPixel,
|
|
@@ -766,8 +773,8 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
766
773
|
knobPosition = _ref$current.knobPosition;
|
|
767
774
|
onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
|
|
768
775
|
if (e.button !== 0) return;
|
|
769
|
-
(_e$
|
|
770
|
-
var xy = getMousePosition(e);
|
|
776
|
+
(_e$target = e.target) === null || _e$target === void 0 ? void 0 : (_e$target$setPointerC = _e$target.setPointerCapture) === null || _e$target$setPointerC === void 0 ? void 0 : _e$target$setPointerC.call(_e$target, e.pointerId);
|
|
777
|
+
var xy = getMousePosition(e, true);
|
|
771
778
|
if (!xy) return;
|
|
772
779
|
var hitTarget = getMouseHit(xy);
|
|
773
780
|
setHitTestDown(hitTarget);
|
|
@@ -817,11 +824,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
817
824
|
dragIndices = seq(dragEnd - dragStart + 1, dragStart);
|
|
818
825
|
}
|
|
819
826
|
var size = columnToPixel(maxX, 1) - columnToPixel(minX);
|
|
820
|
-
var _getScrollPosition = getScrollPosition(e),
|
|
821
|
-
scroll = _getScrollPosition[0];
|
|
822
827
|
setColumnDrag({
|
|
823
|
-
anchor:
|
|
824
|
-
|
|
828
|
+
anchor: xy,
|
|
829
|
+
offset: dataOffset,
|
|
825
830
|
size: size,
|
|
826
831
|
indices: indices
|
|
827
832
|
});
|
|
@@ -841,11 +846,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
841
846
|
var asGroup = isColumnSelection(selection) && maxX === _index;
|
|
842
847
|
var _indices = asGroup ? selectedColumns : [_index];
|
|
843
848
|
var _size = asGroup ? columnToPixel(maxX, 1) - columnToPixel(minX) : columnToPixel(_index, 1) - columnToPixel(_index);
|
|
844
|
-
var _getScrollPosition2 = getScrollPosition(e),
|
|
845
|
-
_scroll = _getScrollPosition2[0];
|
|
846
849
|
setColumnResize({
|
|
847
|
-
anchor:
|
|
848
|
-
|
|
850
|
+
anchor: xy,
|
|
851
|
+
offset: dataOffset,
|
|
849
852
|
size: _size,
|
|
850
853
|
indices: _indices
|
|
851
854
|
});
|
|
@@ -887,11 +890,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
887
890
|
_dragIndices = seq(_dragEnd - _dragStart + 1, _dragStart);
|
|
888
891
|
}
|
|
889
892
|
var _size2 = rowToPixel(maxY, 1) - rowToPixel(minY);
|
|
890
|
-
var _getScrollPosition3 = getScrollPosition(e),
|
|
891
|
-
_scroll2 = _getScrollPosition3[1];
|
|
892
893
|
setRowDrag({
|
|
893
|
-
anchor:
|
|
894
|
-
|
|
894
|
+
anchor: xy,
|
|
895
|
+
offset: dataOffset,
|
|
895
896
|
size: _size2,
|
|
896
897
|
indices: _indices2
|
|
897
898
|
});
|
|
@@ -911,11 +912,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
911
912
|
var _asGroup = isRowSelection(selection) && maxY === _index3;
|
|
912
913
|
var _indices3 = _asGroup ? selectedRows : [_index3];
|
|
913
914
|
var _size3 = _asGroup ? rowToPixel(maxY, 1) - rowToPixel(minY) : rowToPixel(_index3, 1) - rowToPixel(_index3);
|
|
914
|
-
var _getScrollPosition4 = getScrollPosition(e),
|
|
915
|
-
_scroll3 = _getScrollPosition4[1];
|
|
916
915
|
setRowResize({
|
|
917
|
-
anchor:
|
|
918
|
-
|
|
916
|
+
anchor: xy,
|
|
917
|
+
offset: dataOffset,
|
|
919
918
|
size: _size3,
|
|
920
919
|
indices: _indices3
|
|
921
920
|
});
|
|
@@ -955,7 +954,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
955
954
|
}
|
|
956
955
|
setDraggingSelection(true);
|
|
957
956
|
onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], scrollTo, true);
|
|
958
|
-
}, [getMousePosition,
|
|
957
|
+
}, [getMousePosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, dontCommitEditOnSelectionChange, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups]);
|
|
959
958
|
var onPointerUp = useCallback(function (e) {
|
|
960
959
|
var _ref$current2 = ref.current,
|
|
961
960
|
knobArea = _ref$current2.knobArea,
|
|
@@ -990,8 +989,8 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
990
989
|
_normalizeSelection2$2 = _normalizeSelection2[1],
|
|
991
990
|
maxX = _normalizeSelection2$2[0],
|
|
992
991
|
maxY = _normalizeSelection2$2[1];
|
|
993
|
-
var cellX =
|
|
994
|
-
var cellY =
|
|
992
|
+
var cellX = pixelToColumn(x, 0.5);
|
|
993
|
+
var cellY = pixelToRow(y, 0.5);
|
|
995
994
|
if (columnDrag) {
|
|
996
995
|
var indices = columnDrag.indices;
|
|
997
996
|
var insideSelection = cellX >= minX && cellX <= maxX + 1;
|
|
@@ -1029,10 +1028,12 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1029
1028
|
setColumnDrag(null);
|
|
1030
1029
|
setRowResize(null);
|
|
1031
1030
|
setRowDrag(null);
|
|
1031
|
+
setAutoScroll(null);
|
|
1032
1032
|
}, [getMousePosition, getMouseHit, onChange, onSelectionChange, onKnobAreaChange, onDropTargetChange, onColumnOrderChange, onRowOrderChange, dontChangeSelectionOnOrderChange]);
|
|
1033
1033
|
var onPointerMove = useCallback(function (e) {
|
|
1034
1034
|
var _ref$current3 = ref.current,
|
|
1035
1035
|
selection = _ref$current3.selection,
|
|
1036
|
+
dataOffset = _ref$current3.dataOffset,
|
|
1036
1037
|
visibleCells = _ref$current3.visibleCells,
|
|
1037
1038
|
knobPosition = _ref$current3.knobPosition,
|
|
1038
1039
|
columnResize = _ref$current3.columnResize,
|
|
@@ -1044,6 +1045,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1044
1045
|
draggingColumnSelection = _ref$current3.draggingColumnSelection,
|
|
1045
1046
|
draggingRowSelection = _ref$current3.draggingRowSelection,
|
|
1046
1047
|
_ref$current3$cellLay = _ref$current3.cellLayout,
|
|
1048
|
+
cellToPixel = _ref$current3$cellLay.cellToPixel,
|
|
1047
1049
|
columnToPixel = _ref$current3$cellLay.columnToPixel,
|
|
1048
1050
|
rowToPixel = _ref$current3$cellLay.rowToPixel,
|
|
1049
1051
|
pixelToCell = _ref$current3$cellLay.pixelToCell,
|
|
@@ -1052,6 +1054,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1052
1054
|
getIndentX = _ref$current3$cellLay.getIndentX,
|
|
1053
1055
|
getIndentY = _ref$current3$cellLay.getIndentY;
|
|
1054
1056
|
window.document.body.style.cursor = 'auto';
|
|
1057
|
+
var isDraggingX = !!columnResize || !!columnDrag || draggingColumnSelection || draggingSelection || draggingKnob;
|
|
1058
|
+
var isDraggingY = !!rowResize || !!rowDrag || draggingRowSelection || draggingSelection || draggingKnob;
|
|
1059
|
+
var isDragging = isDraggingX || isDraggingY;
|
|
1060
|
+
var outOfBounds = getMouseOutOfBounds(e, isDraggingX, isDraggingY);
|
|
1061
|
+
if (isDragging) setAutoScroll(outOfBounds);
|
|
1055
1062
|
var xy = getMousePosition(e);
|
|
1056
1063
|
if (!xy) return;
|
|
1057
1064
|
var hitTarget = getMouseHit(xy);
|
|
@@ -1079,7 +1086,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1079
1086
|
_normalizeSelection3$2 = _normalizeSelection3[1],
|
|
1080
1087
|
maxX = _normalizeSelection3$2[0],
|
|
1081
1088
|
maxY = _normalizeSelection3$2[1];
|
|
1082
|
-
var
|
|
1089
|
+
var getDragScrollOffset = function getDragScrollOffset(startOffset) {
|
|
1090
|
+
return subXY(cellToPixel(dataOffset), cellToPixel(startOffset));
|
|
1091
|
+
};
|
|
1083
1092
|
if (!isDragging) {
|
|
1084
1093
|
if (!hideColumnHeaders && y < getIndentY()) {
|
|
1085
1094
|
if (onColumnOrderChange) {
|
|
@@ -1148,11 +1157,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1148
1157
|
if (onCellWidthChange) {
|
|
1149
1158
|
var size = columnResize.size,
|
|
1150
1159
|
anchor = columnResize.anchor,
|
|
1151
|
-
|
|
1160
|
+
offset = columnResize.offset,
|
|
1152
1161
|
indices = columnResize.indices;
|
|
1153
|
-
var
|
|
1154
|
-
|
|
1155
|
-
var newWidth = Math.round(Math.max(size + x - anchor +
|
|
1162
|
+
var _getDragScrollOffset = getDragScrollOffset(offset),
|
|
1163
|
+
scrollOffset = _getDragScrollOffset[0];
|
|
1164
|
+
var newWidth = Math.round(Math.max(size + x - anchor[0] + scrollOffset, SIZES.minimumWidth * indices.length));
|
|
1156
1165
|
onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(indices[0] - 1);
|
|
1157
1166
|
onCellWidthChange(indices, indices.map(function (_) {
|
|
1158
1167
|
return Math.round(newWidth / indices.length);
|
|
@@ -1164,11 +1173,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1164
1173
|
if (onCellHeightChange) {
|
|
1165
1174
|
var _size4 = rowResize.size,
|
|
1166
1175
|
_anchor = rowResize.anchor,
|
|
1167
|
-
|
|
1176
|
+
_offset = rowResize.offset,
|
|
1168
1177
|
_indices5 = rowResize.indices;
|
|
1169
|
-
var
|
|
1170
|
-
|
|
1171
|
-
var newHeight = Math.round(Math.max(_size4 + y - _anchor +
|
|
1178
|
+
var _getDragScrollOffset2 = getDragScrollOffset(_offset),
|
|
1179
|
+
_scrollOffset = _getDragScrollOffset2[1];
|
|
1180
|
+
var newHeight = Math.round(Math.max(_size4 + y - _anchor[1] + _scrollOffset, SIZES.minimumHeight * _indices5.length));
|
|
1172
1181
|
onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(_indices5[0] - 1);
|
|
1173
1182
|
onCellHeightChange(_indices5, _indices5.map(function (_) {
|
|
1174
1183
|
return newHeight / _indices5.length;
|
|
@@ -1178,7 +1187,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1178
1187
|
}
|
|
1179
1188
|
if (draggingSelection) {
|
|
1180
1189
|
var _anchor2 = selection[0];
|
|
1181
|
-
var head = pixelToCell(xy);
|
|
1190
|
+
var head = maxXY(dataOffset, pixelToCell(xy));
|
|
1182
1191
|
var anchorX = _anchor2[0],
|
|
1183
1192
|
anchorY = _anchor2[1];
|
|
1184
1193
|
var headX = head[0],
|
|
@@ -1224,31 +1233,31 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1224
1233
|
var _x = xy[0],
|
|
1225
1234
|
_y = xy[1];
|
|
1226
1235
|
if (columnDrag) {
|
|
1227
|
-
var _cellX =
|
|
1236
|
+
var _cellX = pixelToColumn(_x, 0.5);
|
|
1228
1237
|
var insideSelection = _cellX >= minX && _cellX <= maxX + 1;
|
|
1229
1238
|
var insideGroup = isBoundaryInsideGroup(_cellX, columnGroupKeys);
|
|
1230
1239
|
var _anchor3 = columnDrag.anchor,
|
|
1231
|
-
|
|
1232
|
-
var shift = _x - _anchor3;
|
|
1233
|
-
var
|
|
1234
|
-
|
|
1235
|
-
onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([shift +
|
|
1240
|
+
_offset2 = columnDrag.offset;
|
|
1241
|
+
var shift = _x - _anchor3[0];
|
|
1242
|
+
var _getDragScrollOffset3 = getDragScrollOffset(_offset2),
|
|
1243
|
+
_scrollOffset2 = _getDragScrollOffset3[0];
|
|
1244
|
+
onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([shift + _scrollOffset2, 0]);
|
|
1236
1245
|
onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(insideSelection || insideGroup ? null : [[_cellX, -1], [_cellX, -1]]);
|
|
1237
1246
|
}
|
|
1238
1247
|
if (rowDrag) {
|
|
1239
|
-
var _cellY =
|
|
1248
|
+
var _cellY = pixelToRow(_y, 0.5);
|
|
1240
1249
|
var _insideSelection2 = _cellY >= minY && _cellY <= maxY + 1;
|
|
1241
1250
|
var _insideGroup2 = isBoundaryInsideGroup(_cellY, rowGroupKeys);
|
|
1242
1251
|
var _anchor4 = rowDrag.anchor,
|
|
1243
|
-
|
|
1244
|
-
var _shift = _y - _anchor4;
|
|
1245
|
-
var
|
|
1246
|
-
|
|
1247
|
-
onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, _shift +
|
|
1252
|
+
_offset3 = rowDrag.offset;
|
|
1253
|
+
var _shift = _y - _anchor4[1];
|
|
1254
|
+
var _getDragScrollOffset4 = getDragScrollOffset(_offset3),
|
|
1255
|
+
_scrollOffset3 = _getDragScrollOffset4[1];
|
|
1256
|
+
onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, _shift + _scrollOffset3]);
|
|
1248
1257
|
onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(_insideSelection2 || _insideGroup2 ? null : [[-1, _cellY], [-1, _cellY]]);
|
|
1249
1258
|
}
|
|
1250
1259
|
}
|
|
1251
|
-
}, [getMousePosition,
|
|
1260
|
+
}, [getMousePosition, getMouseOutOfBounds, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
|
|
1252
1261
|
var onClick = useCallback(function (e) {
|
|
1253
1262
|
var xy = getMousePosition(e);
|
|
1254
1263
|
if (!xy) return;
|
|
@@ -1366,6 +1375,23 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1366
1375
|
});
|
|
1367
1376
|
onRightClick === null || onRightClick === void 0 ? void 0 : onRightClick(event);
|
|
1368
1377
|
}, [getMousePosition, onSelectionChange, onPointerMove, onRightClick]);
|
|
1378
|
+
useLayoutEffect(function () {
|
|
1379
|
+
if (!autoScroll) return;
|
|
1380
|
+
var loop = function loop() {
|
|
1381
|
+
var element = elementRef.current;
|
|
1382
|
+
if (!element) return;
|
|
1383
|
+
var x = autoScroll[0],
|
|
1384
|
+
y = autoScroll[1];
|
|
1385
|
+
var speed = 4;
|
|
1386
|
+
element.scrollLeft += x * speed * 2;
|
|
1387
|
+
element.scrollTop += y * speed;
|
|
1388
|
+
};
|
|
1389
|
+
var timer = setInterval(loop, 33);
|
|
1390
|
+
loop();
|
|
1391
|
+
return function () {
|
|
1392
|
+
clearInterval(timer);
|
|
1393
|
+
};
|
|
1394
|
+
}, [elementRef, autoScroll]);
|
|
1369
1395
|
var mouseHandlers = {
|
|
1370
1396
|
onPointerLeave: onPointerLeave,
|
|
1371
1397
|
onPointerDown: onPointerDown,
|
|
@@ -2221,7 +2247,8 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
|
|
|
2221
2247
|
var rows = table.rows,
|
|
2222
2248
|
payload = table.payload;
|
|
2223
2249
|
var _normalizeSelection = normalizeSelection(selection),
|
|
2224
|
-
min = _normalizeSelection[0]
|
|
2250
|
+
min = _normalizeSelection[0],
|
|
2251
|
+
max = _normalizeSelection[1];
|
|
2225
2252
|
var minX = min[0],
|
|
2226
2253
|
minY = min[1];
|
|
2227
2254
|
var left = Math.max(0, minX);
|
|
@@ -2230,18 +2257,27 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
|
|
|
2230
2257
|
return Math.max(a, b.length);
|
|
2231
2258
|
}, 0);
|
|
2232
2259
|
var height = rows.length;
|
|
2233
|
-
var
|
|
2260
|
+
var selectionSize = mulXY(addXY(subXY(max, min), [1, 1]), [1 / width, 1 / height]);
|
|
2261
|
+
var repeatX = Math.max(1, Math.floor(selectionSize[0]));
|
|
2262
|
+
var repeatY = Math.max(1, Math.floor(selectionSize[1]));
|
|
2263
|
+
var newSelection = [min, addXY(min, [width * repeatX - 1, height * repeatY - 1])];
|
|
2234
2264
|
return Promise.resolve(onPaste === null || onPaste === void 0 ? void 0 : onPaste(newSelection, rows, payload)).then(function (shouldPaste) {
|
|
2235
2265
|
if (shouldPaste !== false) {
|
|
2236
2266
|
var changes = rows.flatMap(function (row, j) {
|
|
2237
|
-
return row.
|
|
2238
|
-
var
|
|
2239
|
-
var
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2267
|
+
return row.flatMap(function (value, i) {
|
|
2268
|
+
var cells = [];
|
|
2269
|
+
for (var rx = 0; rx < repeatX; ++rx) {
|
|
2270
|
+
for (var ry = 0; ry < repeatY; ++ry) {
|
|
2271
|
+
var x = left + i + rx * width;
|
|
2272
|
+
var y = top + j + ry * height;
|
|
2273
|
+
if (!(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y))) cells.push({
|
|
2274
|
+
x: x,
|
|
2275
|
+
y: y,
|
|
2276
|
+
value: value
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
return cells;
|
|
2245
2281
|
});
|
|
2246
2282
|
}).filter(function (change) {
|
|
2247
2283
|
return !!change;
|
|
@@ -2607,7 +2643,7 @@ var makeCellLayout = function makeCellLayout(freeze, offset, columns, rows) {
|
|
|
2607
2643
|
var getStart = layout.getStart,
|
|
2608
2644
|
lookupIndex = layout.lookupIndex;
|
|
2609
2645
|
var indent = getStart(0);
|
|
2610
|
-
if (pixel < indent) return
|
|
2646
|
+
if (pixel < indent) return 0;
|
|
2611
2647
|
var frozen = getStart(freeze);
|
|
2612
2648
|
if (pixel < frozen) {
|
|
2613
2649
|
return lookupIndex(pixel, anchor);
|
|
@@ -3633,7 +3669,7 @@ var Sheet = forwardRef(function (props, ref) {
|
|
|
3633
3669
|
var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
|
|
3634
3670
|
var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, freezeColumns);
|
|
3635
3671
|
var getAutoSizeHeight = useAutoSizeRow(visibleCells.columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, freezeRows);
|
|
3636
|
-
var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
|
|
3672
|
+
var _useMouse = useMouse(overlayRef, dataOffset, hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
|
|
3637
3673
|
mouseHandlers = _useMouse.mouseHandlers,
|
|
3638
3674
|
knobPosition = _useMouse.knobPosition;
|
|
3639
3675
|
var _useKeyboard = useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, startEditingCell, commitEditingCell, cancelEditingCell, changeSelection, setFocused, onClipboardCopy, props.onChange),
|