sheet-happens 0.0.19 → 0.0.21

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.d.ts CHANGED
@@ -15,6 +15,10 @@ export interface Change {
15
15
  x: number;
16
16
  y: number;
17
17
  value: string | number | null;
18
+ source?: {
19
+ x: number;
20
+ y: number;
21
+ };
18
22
  }
19
23
  export interface CellContentItem {
20
24
  content: HTMLImageElement | string | number;
@@ -52,6 +56,7 @@ export interface SheetProps {
52
56
  editData?: CellProperty<string>;
53
57
  editKeys?: CellProperty<string>;
54
58
  sheetStyle?: SheetStyle;
59
+ dontCommitEditOnSelectionChange?: boolean;
55
60
  inputComponent?: (x: number, y: number, props: SheetInputProps, commitEditingCell?: () => void) => ReactElement | undefined;
56
61
  onSelectionChanged?: (x1: number, y1: number, x2: number, y2: number) => void;
57
62
  onRightClick?: (e: SheetMouseEvent) => void;
package/dist/index.js CHANGED
@@ -583,14 +583,10 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
583
583
 
584
584
  if (rowSelectionActive) {
585
585
  var p1x = Math.max(-100, p1.x);
586
- var p1y = Math.max(-100, p1.y);
587
- context.fillRect(p1x, p1y, 100000, p2.y - p1.y);
586
+ context.fillRect(p1x, p1.y, 100000, p2.y - p1.y);
588
587
  } else if (colSelectionActive) {
589
- var _p1x = Math.max(-100, p1.x);
590
-
591
- var _p1y = Math.max(-100, p1.y);
592
-
593
- context.fillRect(_p1x, _p1y, p2.x - p1.x, 100000);
588
+ var p1y = Math.max(0, p1.y);
589
+ context.fillRect(p1.x, p1y, p2.x - p1.x, 100000);
594
590
  } else {
595
591
  context.fillRect(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
596
592
  }
@@ -717,17 +713,13 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
717
713
  context.beginPath();
718
714
 
719
715
  if (rowSelectionActive) {
720
- var _p1x2 = Math.max(-100, p1.x);
721
-
722
- var _p1y2 = Math.max(-100, p1.y);
716
+ var _p1x = Math.max(-100, p1.x);
723
717
 
724
- context.rect(_p1x2, _p1y2, 100000, p2.y - p1.y);
718
+ context.rect(_p1x, p1.y, 100000, p2.y - p1.y);
725
719
  } else if (colSelectionActive) {
726
- var _p1x3 = Math.max(-100, p1.x);
727
-
728
- var _p1y3 = Math.max(-100, p1.y);
720
+ var _p1y = Math.max(-100, p1.y);
729
721
 
730
- context.rect(_p1x3, _p1y3, p2.x - p1.x, 100000);
722
+ context.rect(p1.x, _p1y, p2.x - p1.x, 100000);
731
723
  } else {
732
724
  context.rect(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
733
725
  }
@@ -1336,12 +1328,12 @@ function Sheet(props) {
1336
1328
  var clipboardData = e.clipboardData || window.clipboardData;
1337
1329
  var types = clipboardData.types;
1338
1330
 
1339
- if (types.includes('text/rtf') && types.includes('text/plain') || types.includes('text/plain') && !types.includes('text/html')) {
1340
- var text = clipboardData.getData('text/plain');
1341
- parsePastedText(text);
1342
- } else if (types.includes('text/html')) {
1331
+ if (types.includes('text/html')) {
1343
1332
  var pastedHtml = clipboardData.getData('text/html');
1344
1333
  parsePastedHtml(pastedHtml);
1334
+ } else if (types.includes('text/plain')) {
1335
+ var text = clipboardData.getData('text/plain');
1336
+ parsePastedText(text);
1345
1337
  }
1346
1338
  };
1347
1339
 
@@ -1422,12 +1414,12 @@ function Sheet(props) {
1422
1414
  var p = td.children[0];
1423
1415
 
1424
1416
  if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
1425
- str = p.children[0].innerHTML;
1417
+ str = p.children[0].textContent.trim();
1426
1418
  } else {
1427
- str = p.innerHTML;
1419
+ str = p.textContent.trim();
1428
1420
  }
1429
1421
  } else {
1430
- str = td.innerHTML;
1422
+ str = td.textContent.trim();
1431
1423
  }
1432
1424
 
1433
1425
  str = str.replaceAll('\n', '');
@@ -1780,7 +1772,9 @@ function Sheet(props) {
1780
1772
  } : _extends({}, sel2);
1781
1773
 
1782
1774
  if (editMode) {
1783
- commitEditingCell();
1775
+ if (!props.dontCommitEditOnSelectionChange) {
1776
+ commitEditingCell();
1777
+ }
1784
1778
  }
1785
1779
 
1786
1780
  var scrollToP2 = true;
@@ -1805,11 +1799,14 @@ function Sheet(props) {
1805
1799
 
1806
1800
  setSelectionInProgress(true);
1807
1801
  changeSelection(sel1.x, sel1.y, sel2.x, sel2.y, scrollToP2);
1808
- setEditCell({
1809
- x: -1,
1810
- y: -1
1811
- });
1812
- setEditKey('');
1802
+
1803
+ if (!props.dontCommitEditOnSelectionChange) {
1804
+ setEditCell({
1805
+ x: -1,
1806
+ y: -1
1807
+ });
1808
+ setEditKey('');
1809
+ }
1813
1810
  };
1814
1811
 
1815
1812
  var onMouseUp = function onMouseUp(e) {
@@ -1873,7 +1870,11 @@ function Sheet(props) {
1873
1870
  changes.push({
1874
1871
  x: x,
1875
1872
  y: y,
1876
- value: value
1873
+ value: value,
1874
+ source: {
1875
+ x: x,
1876
+ y: srcY
1877
+ }
1877
1878
  });
1878
1879
  }
1879
1880
 
@@ -1906,7 +1907,11 @@ function Sheet(props) {
1906
1907
  changes.push({
1907
1908
  x: _x3,
1908
1909
  y: _y2,
1909
- value: _value
1910
+ value: _value,
1911
+ source: {
1912
+ x: srcX,
1913
+ y: _y2
1914
+ }
1910
1915
  });
1911
1916
  }
1912
1917
 
@@ -2123,6 +2128,11 @@ function Sheet(props) {
2123
2128
 
2124
2129
  var editCell = absCoordianteToCell(x, y, rowSizes, columnSizes);
2125
2130
  setArrowKeyCommitMode(false);
2131
+
2132
+ if (editMode) {
2133
+ commitEditingCell();
2134
+ }
2135
+
2126
2136
  startEditingCell(editCell);
2127
2137
  };
2128
2138