sheet-happens 0.0.35 → 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.
@@ -1,4 +1,4 @@
1
1
  import { CellPropertyFunction, Change, Rectangle } from './types';
2
2
  import { RefObject } from 'react';
3
3
  export declare const useClipboardCopy: (textAreaRef: RefObject<HTMLTextAreaElement>, selection: Rectangle, editMode: boolean, editData: CellPropertyFunction<string>) => void;
4
- export declare const useClipboardPaste: (textAreaRef: RefObject<HTMLTextAreaElement>, selection: Rectangle, onSelectionChange?: ((selection: Rectangle) => void) | undefined, onChange?: ((changes: Array<Change>) => void) | undefined) => void;
4
+ export declare const useClipboardPaste: (textAreaRef: RefObject<HTMLTextAreaElement>, selection: Rectangle, onSelectionChange?: ((selection: Rectangle) => void) | undefined, onChange?: ((changes: Array<Change>) => void) | undefined, isReadOnly?: CellPropertyFunction<boolean> | undefined) => void;
package/dist/index.js CHANGED
@@ -1422,7 +1422,7 @@ var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMod
1422
1422
  }
1423
1423
  });
1424
1424
  };
1425
- var useClipboardPaste = function useClipboardPaste(textAreaRef, selection, onSelectionChange, onChange) {
1425
+ var useClipboardPaste = function useClipboardPaste(textAreaRef, selection, onSelectionChange, onChange, isReadOnly) {
1426
1426
  React.useEffect(function () {
1427
1427
  var onPaste = function onPaste(e) {
1428
1428
  var textArea = textAreaRef.current;
@@ -1435,10 +1435,10 @@ var useClipboardPaste = function useClipboardPaste(textAreaRef, selection, onSel
1435
1435
 
1436
1436
  if (types.includes('text/html')) {
1437
1437
  var pastedHtml = clipboardData.getData('text/html');
1438
- parsed = parsePastedHtml(selection, pastedHtml);
1438
+ parsed = parsePastedHtml(selection, pastedHtml, isReadOnly);
1439
1439
  } else if (types.includes('text/plain')) {
1440
1440
  var text = clipboardData.getData('text/plain');
1441
- parsed = parsePastedText(selection, text);
1441
+ parsed = parsePastedText(selection, text, isReadOnly);
1442
1442
  }
1443
1443
 
1444
1444
  if (!parsed) return;
@@ -1524,7 +1524,7 @@ var findTable = function findTable(element) {
1524
1524
  }
1525
1525
  };
1526
1526
 
1527
- var parsePastedHtml = function parsePastedHtml(selection, html) {
1527
+ var parsePastedHtml = function parsePastedHtml(selection, html, isReadOnly) {
1528
1528
  var div = document.createElement('div');
1529
1529
  div.innerHTML = html.trim();
1530
1530
 
@@ -1575,7 +1575,7 @@ var parsePastedHtml = function parsePastedHtml(selection, html) {
1575
1575
 
1576
1576
  str = str.replaceAll('\n', '');
1577
1577
  str = str.replaceAll(/\s\s+/g, ' ');
1578
- changes.push({
1578
+ if (!(isReadOnly !== null && isReadOnly !== void 0 && isReadOnly(x, y))) changes.push({
1579
1579
  x: x,
1580
1580
  y: y,
1581
1581
  value: str
@@ -1599,7 +1599,7 @@ var parsePastedHtml = function parsePastedHtml(selection, html) {
1599
1599
  };
1600
1600
  };
1601
1601
 
1602
- var parsePastedText = function parsePastedText(selection, text) {
1602
+ var parsePastedText = function parsePastedText(selection, text, isReadOnly) {
1603
1603
  var _normalizeSelection3 = normalizeSelection(selection),
1604
1604
  _normalizeSelection3$ = _normalizeSelection3[0],
1605
1605
  minX = _normalizeSelection3$[0],
@@ -1617,9 +1617,11 @@ var parsePastedText = function parsePastedText(selection, text) {
1617
1617
  right = Math.max(right, left + cols.length - 1);
1618
1618
 
1619
1619
  for (var x = 0; x < cols.length; x++) {
1620
- changes.push({
1621
- x: left + x,
1622
- y: top + y,
1620
+ var X = left + x;
1621
+ var Y = top + y;
1622
+ if (!(isReadOnly !== null && isReadOnly !== void 0 && isReadOnly(X, Y))) changes.push({
1623
+ x: X,
1624
+ y: Y,
1623
1625
  value: cols[x]
1624
1626
  });
1625
1627
  }
@@ -2815,7 +2817,7 @@ var Sheet = React.forwardRef(function (props, ref) {
2815
2817
  var hitmapRef = React.useRef(NO_CLICKABLES);
2816
2818
  var textAreaRef = React.useRef(null);
2817
2819
  useClipboardCopy(textAreaRef, selection, editMode, editData);
2818
- useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange);
2820
+ useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
2819
2821
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
2820
2822
 
2821
2823
  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),