sheet-happens 0.0.33 → 0.0.35

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 CHANGED
@@ -429,7 +429,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
429
429
  return maxXY(cell, [0, 0]);
430
430
  };
431
431
 
432
- var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, onEdit, onCommit, onKnobAreaChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange) {
432
+ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, onEdit, onCommit, onKnobAreaChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange) {
433
433
  var _useState = React.useState(null),
434
434
  hitTarget = _useState[0],
435
435
  setHitTarget = _useState[1];
@@ -499,6 +499,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
499
499
  sourceData: sourceData,
500
500
  cellLayout: cellLayout,
501
501
  visibleCells: visibleCells,
502
+ hitTarget: hitTarget,
502
503
  knobPosition: knobPosition,
503
504
  columnResize: columnResize,
504
505
  rowResize: rowResize,
@@ -574,6 +575,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
574
575
 
575
576
  if (hitTarget) {
576
577
  setHitTarget(hitTarget);
578
+ ref.current.hitTarget = hitTarget;
577
579
  return;
578
580
  }
579
581
 
@@ -765,6 +767,8 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
765
767
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], scrollTo, true);
766
768
  }, [getMousePosition, getScrollPosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow]);
767
769
  var onPointerUp = React.useCallback(function (e) {
770
+ var _getMouseHit;
771
+
768
772
  var _ref$current2 = ref.current,
769
773
  knobArea = _ref$current2.knobArea,
770
774
  selection = _ref$current2.selection,
@@ -773,6 +777,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
773
777
  columnDrag = _ref$current2.columnDrag,
774
778
  rowDrag = _ref$current2.rowDrag,
775
779
  draggingKnob = _ref$current2.draggingKnob,
780
+ hitTarget = _ref$current2.hitTarget,
776
781
  _ref$current2$cellLay = _ref$current2.cellLayout,
777
782
  pixelToColumn = _ref$current2$cellLay.pixelToColumn,
778
783
  pixelToRow = _ref$current2$cellLay.pixelToRow,
@@ -780,7 +785,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
780
785
  getIndentY = _ref$current2$cellLay.getIndentY;
781
786
 
782
787
  if (knobArea && draggingKnob) {
783
- var changes = parseKnobOperation(knobArea, selection, sourceData, editData);
788
+ var changes = parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly);
784
789
  onChange === null || onChange === void 0 ? void 0 : onChange(changes);
785
790
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(knobArea, true, true);
786
791
  onKnobAreaChange === null || onKnobAreaChange === void 0 ? void 0 : onKnobAreaChange(null);
@@ -843,8 +848,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
843
848
  setRowDrag(null);
844
849
  if (!xy || !hitTarget) return;
845
850
  setHitTarget(null);
851
+ var previousRect = JSON.stringify(hitTarget.rect);
852
+ var currentRect = JSON.stringify((_getMouseHit = getMouseHit(xy)) === null || _getMouseHit === void 0 ? void 0 : _getMouseHit.rect);
846
853
 
847
- if (hitTarget === getMouseHit(xy)) {
854
+ if (previousRect === currentRect) {
848
855
  var _obj$onClick;
849
856
 
850
857
  var obj = hitTarget.obj;
@@ -1175,7 +1182,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1175
1182
  };
1176
1183
  };
1177
1184
 
1178
- var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData) {
1185
+ var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
1179
1186
  var _normalizeSelection6 = normalizeSelection(knobArea),
1180
1187
  _normalizeSelection6$ = _normalizeSelection6[0],
1181
1188
  kx1 = _normalizeSelection6$[0],
@@ -1218,15 +1225,18 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1218
1225
  for (var y = fy1; y <= fy2; y++) {
1219
1226
  for (var x = fx1; x <= fx2; x++) {
1220
1227
  var value = sourceData(x, srcY);
1221
- changes.push({
1222
- x: x,
1223
- y: y,
1224
- value: value,
1225
- source: {
1228
+
1229
+ if (!cellReadOnly(x, y)) {
1230
+ changes.push({
1226
1231
  x: x,
1227
- y: srcY
1228
- }
1229
- });
1232
+ y: y,
1233
+ value: value,
1234
+ source: {
1235
+ x: x,
1236
+ y: srcY
1237
+ }
1238
+ });
1239
+ }
1230
1240
  }
1231
1241
 
1232
1242
  srcY = srcY + 1;
@@ -1256,15 +1266,17 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1256
1266
  for (var _y2 = fy1; _y2 <= fy2; _y2++) {
1257
1267
  var _value = sourceData(srcX, _y2);
1258
1268
 
1259
- changes.push({
1260
- x: _x2,
1261
- y: _y2,
1262
- value: _value,
1263
- source: {
1264
- x: srcX,
1265
- y: _y2
1266
- }
1267
- });
1269
+ if (!cellReadOnly(_x2, _y2)) {
1270
+ changes.push({
1271
+ x: _x2,
1272
+ y: _y2,
1273
+ value: _value,
1274
+ source: {
1275
+ x: srcX,
1276
+ y: _y2
1277
+ }
1278
+ });
1279
+ }
1268
1280
  }
1269
1281
 
1270
1282
  srcX = srcX + 1;
@@ -2806,7 +2818,7 @@ var Sheet = React.forwardRef(function (props, ref) {
2806
2818
  useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange);
2807
2819
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
2808
2820
 
2809
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, startEditingCell, commitEditingCell, setKnobArea, setDragOffset, setDropTarget, changeSelection, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange),
2821
+ var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, startEditingCell, commitEditingCell, setKnobArea, setDragOffset, setDropTarget, changeSelection, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange),
2810
2822
  mouseHandlers = _useMouse.mouseHandlers,
2811
2823
  knobPosition = _useMouse.knobPosition;
2812
2824
 
@@ -2887,11 +2899,13 @@ var Sheet = React.forwardRef(function (props, ref) {
2887
2899
 
2888
2900
  for (var y = y1; y <= y2; y++) {
2889
2901
  for (var x = x1; x <= x2; x++) {
2890
- changes.push({
2891
- x: x,
2892
- y: y,
2893
- value: null
2894
- });
2902
+ if (!cellReadOnly(x, y)) {
2903
+ changes.push({
2904
+ x: x,
2905
+ y: y,
2906
+ value: null
2907
+ });
2908
+ }
2895
2909
  }
2896
2910
  }
2897
2911