sheet-happens 0.0.34 → 0.0.36

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.
@@ -426,7 +426,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
426
426
  return maxXY(cell, [0, 0]);
427
427
  };
428
428
 
429
- 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) {
429
+ 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) {
430
430
  var _useState = useState(null),
431
431
  hitTarget = _useState[0],
432
432
  setHitTarget = _useState[1];
@@ -782,7 +782,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
782
782
  getIndentY = _ref$current2$cellLay.getIndentY;
783
783
 
784
784
  if (knobArea && draggingKnob) {
785
- var changes = parseKnobOperation(knobArea, selection, sourceData, editData);
785
+ var changes = parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly);
786
786
  onChange === null || onChange === void 0 ? void 0 : onChange(changes);
787
787
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(knobArea, true, true);
788
788
  onKnobAreaChange === null || onKnobAreaChange === void 0 ? void 0 : onKnobAreaChange(null);
@@ -1179,7 +1179,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1179
1179
  };
1180
1180
  };
1181
1181
 
1182
- var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData) {
1182
+ var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
1183
1183
  var _normalizeSelection6 = normalizeSelection(knobArea),
1184
1184
  _normalizeSelection6$ = _normalizeSelection6[0],
1185
1185
  kx1 = _normalizeSelection6$[0],
@@ -1222,15 +1222,18 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1222
1222
  for (var y = fy1; y <= fy2; y++) {
1223
1223
  for (var x = fx1; x <= fx2; x++) {
1224
1224
  var value = sourceData(x, srcY);
1225
- changes.push({
1226
- x: x,
1227
- y: y,
1228
- value: value,
1229
- source: {
1225
+
1226
+ if (!cellReadOnly(x, y)) {
1227
+ changes.push({
1230
1228
  x: x,
1231
- y: srcY
1232
- }
1233
- });
1229
+ y: y,
1230
+ value: value,
1231
+ source: {
1232
+ x: x,
1233
+ y: srcY
1234
+ }
1235
+ });
1236
+ }
1234
1237
  }
1235
1238
 
1236
1239
  srcY = srcY + 1;
@@ -1260,15 +1263,17 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1260
1263
  for (var _y2 = fy1; _y2 <= fy2; _y2++) {
1261
1264
  var _value = sourceData(srcX, _y2);
1262
1265
 
1263
- changes.push({
1264
- x: _x2,
1265
- y: _y2,
1266
- value: _value,
1267
- source: {
1268
- x: srcX,
1269
- y: _y2
1270
- }
1271
- });
1266
+ if (!cellReadOnly(_x2, _y2)) {
1267
+ changes.push({
1268
+ x: _x2,
1269
+ y: _y2,
1270
+ value: _value,
1271
+ source: {
1272
+ x: srcX,
1273
+ y: _y2
1274
+ }
1275
+ });
1276
+ }
1272
1277
  }
1273
1278
 
1274
1279
  srcX = srcX + 1;
@@ -1414,7 +1419,7 @@ var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMod
1414
1419
  }
1415
1420
  });
1416
1421
  };
1417
- var useClipboardPaste = function useClipboardPaste(textAreaRef, selection, onSelectionChange, onChange) {
1422
+ var useClipboardPaste = function useClipboardPaste(textAreaRef, selection, onSelectionChange, onChange, isReadOnly) {
1418
1423
  useEffect(function () {
1419
1424
  var onPaste = function onPaste(e) {
1420
1425
  var textArea = textAreaRef.current;
@@ -1427,10 +1432,10 @@ var useClipboardPaste = function useClipboardPaste(textAreaRef, selection, onSel
1427
1432
 
1428
1433
  if (types.includes('text/html')) {
1429
1434
  var pastedHtml = clipboardData.getData('text/html');
1430
- parsed = parsePastedHtml(selection, pastedHtml);
1435
+ parsed = parsePastedHtml(selection, pastedHtml, isReadOnly);
1431
1436
  } else if (types.includes('text/plain')) {
1432
1437
  var text = clipboardData.getData('text/plain');
1433
- parsed = parsePastedText(selection, text);
1438
+ parsed = parsePastedText(selection, text, isReadOnly);
1434
1439
  }
1435
1440
 
1436
1441
  if (!parsed) return;
@@ -1516,7 +1521,7 @@ var findTable = function findTable(element) {
1516
1521
  }
1517
1522
  };
1518
1523
 
1519
- var parsePastedHtml = function parsePastedHtml(selection, html) {
1524
+ var parsePastedHtml = function parsePastedHtml(selection, html, isReadOnly) {
1520
1525
  var div = document.createElement('div');
1521
1526
  div.innerHTML = html.trim();
1522
1527
 
@@ -1567,7 +1572,7 @@ var parsePastedHtml = function parsePastedHtml(selection, html) {
1567
1572
 
1568
1573
  str = str.replaceAll('\n', '');
1569
1574
  str = str.replaceAll(/\s\s+/g, ' ');
1570
- changes.push({
1575
+ if (!(isReadOnly !== null && isReadOnly !== void 0 && isReadOnly(x, y))) changes.push({
1571
1576
  x: x,
1572
1577
  y: y,
1573
1578
  value: str
@@ -1591,7 +1596,7 @@ var parsePastedHtml = function parsePastedHtml(selection, html) {
1591
1596
  };
1592
1597
  };
1593
1598
 
1594
- var parsePastedText = function parsePastedText(selection, text) {
1599
+ var parsePastedText = function parsePastedText(selection, text, isReadOnly) {
1595
1600
  var _normalizeSelection3 = normalizeSelection(selection),
1596
1601
  _normalizeSelection3$ = _normalizeSelection3[0],
1597
1602
  minX = _normalizeSelection3$[0],
@@ -1609,9 +1614,11 @@ var parsePastedText = function parsePastedText(selection, text) {
1609
1614
  right = Math.max(right, left + cols.length - 1);
1610
1615
 
1611
1616
  for (var x = 0; x < cols.length; x++) {
1612
- changes.push({
1613
- x: left + x,
1614
- y: top + y,
1617
+ var X = left + x;
1618
+ var Y = top + y;
1619
+ if (!(isReadOnly !== null && isReadOnly !== void 0 && isReadOnly(X, Y))) changes.push({
1620
+ x: X,
1621
+ y: Y,
1615
1622
  value: cols[x]
1616
1623
  });
1617
1624
  }
@@ -2807,10 +2814,10 @@ var Sheet = forwardRef(function (props, ref) {
2807
2814
  var hitmapRef = useRef(NO_CLICKABLES);
2808
2815
  var textAreaRef = useRef(null);
2809
2816
  useClipboardCopy(textAreaRef, selection, editMode, editData);
2810
- useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange);
2817
+ useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
2811
2818
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
2812
2819
 
2813
- 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),
2820
+ 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),
2814
2821
  mouseHandlers = _useMouse.mouseHandlers,
2815
2822
  knobPosition = _useMouse.knobPosition;
2816
2823
 
@@ -2891,11 +2898,13 @@ var Sheet = forwardRef(function (props, ref) {
2891
2898
 
2892
2899
  for (var y = y1; y <= y2; y++) {
2893
2900
  for (var x = x1; x <= x2; x++) {
2894
- changes.push({
2895
- x: x,
2896
- y: y,
2897
- value: null
2898
- });
2901
+ if (!cellReadOnly(x, y)) {
2902
+ changes.push({
2903
+ x: x,
2904
+ y: y,
2905
+ value: null
2906
+ });
2907
+ }
2899
2908
  }
2900
2909
  }
2901
2910