sheet-happens 0.0.42 → 0.0.44

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
@@ -69,13 +69,13 @@ var styles = {"sheetscroll":"_PxIi8"};
69
69
  var INITIAL_MAX_SCROLL = [2000, 1000];
70
70
  var ORIGIN = [0, 0];
71
71
  var ONE_ONE = [1, 1];
72
+ var NEG_NEG = [-1, -1];
72
73
  var NO_CELL = [-1, -1];
73
74
  var NO_SELECTION = [NO_CELL, NO_CELL];
74
75
  var NO_SELECTIONS = [];
75
76
  var NO_CLICKABLES = [];
76
77
  var NO_STYLE = {};
77
- var MAX_SEARCHABLE_INDEX = 65536;
78
- var MAX_XY = [MAX_SEARCHABLE_INDEX, MAX_SEARCHABLE_INDEX];
78
+ var MAX_SEARCHABLE_INDEX = 100000;
79
79
  var COLORS = {
80
80
  selectionBorder: '#1a66ff',
81
81
  selectionBackground: '#d8e6ff80',
@@ -145,9 +145,6 @@ var ARROW_KEYS = {
145
145
  ArrowDown: 'down'
146
146
  };
147
147
 
148
- var clamp = function clamp(x, min, max) {
149
- return Math.max(Math.min(max, x), min);
150
- };
151
148
  var seq = function seq(n, s, d) {
152
149
  if (s === void 0) {
153
150
  s = 0;
@@ -188,13 +185,6 @@ var maxXY = function maxXY(a, b) {
188
185
  var minXY = function minXY(a, b) {
189
186
  return [Math.min(a[0], b[0]), Math.min(a[1], b[1])];
190
187
  };
191
- var clampXY = function clampXY(p, min, max) {
192
- if (max === void 0) {
193
- max = [Infinity, Infinity];
194
- }
195
-
196
- return [clamp(p[0], min[0], max[0]), clamp(p[1], min[1], max[1])];
197
- };
198
188
  var getDirectionStep = function getDirectionStep(direction) {
199
189
  if (direction === 'left') return [-1, 0];
200
190
  if (direction === 'right') return [1, 0];
@@ -435,6 +425,52 @@ var createCellProp = function createCellProp(cellProp, defaultValue) {
435
425
  };
436
426
  }
437
427
  };
428
+ var createRowOrColumnStyledProp = function createRowOrColumnStyledProp(rowColProp, defaultValue) {
429
+ if (Array.isArray(rowColProp)) {
430
+ return function (rowOrColIndex) {
431
+ if (rowOrColIndex >= 0 && rowOrColIndex < rowColProp.length) {
432
+ return rowColProp[rowOrColIndex];
433
+ } else {
434
+ return defaultValue;
435
+ }
436
+ };
437
+ } else if (typeof rowColProp === 'function') {
438
+ return rowColProp;
439
+ } else if (rowColProp !== null && rowColProp !== undefined) {
440
+ return function () {
441
+ return rowColProp;
442
+ };
443
+ } else {
444
+ return function () {
445
+ return defaultValue;
446
+ };
447
+ }
448
+ };
449
+ var createCellStyledProp = function createCellStyledProp(cellProp, defaultValue) {
450
+ if (Array.isArray(cellProp)) {
451
+ return function (x, y) {
452
+ if (y >= 0 && y < cellProp.length) {
453
+ if (x >= 0 && x < cellProp[y].length) {
454
+ return cellProp[y][x];
455
+ } else {
456
+ return defaultValue;
457
+ }
458
+ } else {
459
+ return defaultValue;
460
+ }
461
+ };
462
+ } else if (typeof cellProp === 'function') {
463
+ return cellProp;
464
+ } else if (cellProp !== null && cellProp !== undefined) {
465
+ return function () {
466
+ return cellProp;
467
+ };
468
+ } else {
469
+ return function () {
470
+ return defaultValue;
471
+ };
472
+ }
473
+ };
438
474
  var findApproxMaxEditDataIndex = function findApproxMaxEditDataIndex(editData) {
439
475
  var x = 0;
440
476
  var y = 0;
@@ -500,8 +536,13 @@ var findApproxMaxEditDataIndex = function findApproxMaxEditDataIndex(editData) {
500
536
  };
501
537
  var findInDisplayData = function findInDisplayData(displayData, start, direction) {
502
538
  var step = getDirectionStep(direction);
503
- var cell = clampXY(start, ORIGIN, MAX_XY);
504
- var first = displayData.apply(void 0, addXY(cell, step));
539
+ var cell = maxXY(start, ORIGIN);
540
+
541
+ var _addXY = addXY(cell, step),
542
+ x = _addXY[0],
543
+ y = _addXY[1];
544
+
545
+ var first = displayData(x, y, DEFAULT_CELL_STYLE);
505
546
  var firstFilled = first !== '' && first !== null && first !== undefined;
506
547
 
507
548
  if (!firstFilled) {
@@ -511,9 +552,11 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
511
552
  var _cell = cell,
512
553
  cellX = _cell[0],
513
554
  cellY = _cell[1];
555
+ var maxX = cellX + MAX_SEARCHABLE_INDEX - 1;
556
+ var maxY = cellY + MAX_SEARCHABLE_INDEX - 1;
514
557
 
515
- while (cellX <= MAX_SEARCHABLE_INDEX && cellY <= MAX_SEARCHABLE_INDEX && cellX >= 0 && cellY >= 0) {
516
- var data = displayData(cellX, cellY);
558
+ while (cellX < maxX && cellY < maxY && cellX >= 0 && cellY >= 0) {
559
+ var data = displayData(cellX, cellY, DEFAULT_CELL_STYLE);
517
560
 
518
561
  if (firstFilled && (data === '' || data === null || data === undefined)) {
519
562
  return subXY(cell, step);
@@ -532,7 +575,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
532
575
  return maxXY(cell, [0, 0]);
533
576
  };
534
577
 
535
- var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
578
+ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onFocusChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
536
579
  var _useState = React.useState(null),
537
580
  hitTarget = _useState[0],
538
581
  setHitTarget = _useState[1];
@@ -673,6 +716,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
673
716
  columns = _ref$current$visibleC.columns,
674
717
  rows = _ref$current$visibleC.rows,
675
718
  knobPosition = _ref$current.knobPosition;
719
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
676
720
  if (e.button !== 0) return;
677
721
  (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : (_e$target2$setPointer = _e$target2.setPointerCapture) === null || _e$target2$setPointer === void 0 ? void 0 : _e$target2$setPointer.call(_e$target2, e.pointerId);
678
722
  var xy = getMousePosition(e);
@@ -939,6 +983,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
939
983
  pixelToRow = _ref$current2$cellLay.pixelToRow,
940
984
  getIndentX = _ref$current2$cellLay.getIndentX,
941
985
  getIndentY = _ref$current2$cellLay.getIndentY;
986
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
942
987
 
943
988
  if (knobArea && draggingKnob) {
944
989
  var changes = parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly);
@@ -1174,7 +1219,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1174
1219
 
1175
1220
  var newWidth = Math.max(size + x - anchor + scroll - currentScroll, SIZES.minimumWidth * indices.length);
1176
1221
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(indices[0] - 1);
1177
- onCellWidthChange(indices, newWidth / indices.length);
1222
+ onCellWidthChange(indices, indices.map(function (_) {
1223
+ return newWidth / indices.length;
1224
+ }));
1178
1225
  }
1179
1226
 
1180
1227
  return;
@@ -1192,7 +1239,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1192
1239
 
1193
1240
  var newHeight = Math.max(_size4 + y - _anchor + _scroll4 - _currentScroll, SIZES.minimumHeight * _indices5.length);
1194
1241
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(_indices5[0] - 1);
1195
- onCellHeightChange(_indices5, newHeight / _indices5.length);
1242
+ onCellHeightChange(_indices5, _indices5.map(function (_) {
1243
+ return newHeight / _indices5.length;
1244
+ }));
1196
1245
  }
1197
1246
 
1198
1247
  return;
@@ -1327,9 +1376,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1327
1376
  for (var _i = 0, _autosized = autosized; _i < _autosized.length; _i++) {
1328
1377
  var column = _autosized[_i];
1329
1378
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(column - 1);
1330
- onCellWidthChange([column], getAutoSizeWidth(column));
1331
1379
  }
1332
1380
 
1381
+ onCellWidthChange(autosized, autosized.map(function (column) {
1382
+ return getAutoSizeWidth(column);
1383
+ }));
1333
1384
  if (autosized.length) return;
1334
1385
  }
1335
1386
 
@@ -1497,6 +1548,162 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1497
1548
  return changes;
1498
1549
  };
1499
1550
 
1551
+ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, onEdit, onCommit, onCancel, onSelectionChange, onFocusChange, onClipboardCopy, onChange) {
1552
+ var onInputKeyDown = function onInputKeyDown(e) {
1553
+ if (e.key === 'Escape') {
1554
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel();
1555
+ return;
1556
+ }
1557
+
1558
+ var direction = e.key === 'Enter' ? 'down' : e.key === 'Tab' ? 'right' : arrowKeyCommitMode ? ARROW_KEYS[e.key] : null;
1559
+
1560
+ if (direction) {
1561
+ e.preventDefault();
1562
+ var step = getDirectionStep(direction);
1563
+ var head = maxXY(addXY(editCell, step), ORIGIN);
1564
+ onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1565
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([head, head]);
1566
+ }
1567
+ };
1568
+
1569
+ var onGridKeyDown = function onGridKeyDown(e) {
1570
+ if (editMode && arrowKeyCommitMode && e.key in ARROW_KEYS) {
1571
+ onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1572
+ return;
1573
+ }
1574
+
1575
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'v') {
1576
+ return;
1577
+ }
1578
+
1579
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'c') {
1580
+ onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(false);
1581
+ return;
1582
+ }
1583
+
1584
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'x') {
1585
+ onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(true);
1586
+ return;
1587
+ }
1588
+
1589
+ if (e.key === 'Backspace' || e.key === 'Delete') {
1590
+ var _normalizeSelection = normalizeSelection(selection),
1591
+ _normalizeSelection$ = _normalizeSelection[0],
1592
+ x1 = _normalizeSelection$[0],
1593
+ y1 = _normalizeSelection$[1],
1594
+ _normalizeSelection$2 = _normalizeSelection[1],
1595
+ x2 = _normalizeSelection$2[0],
1596
+ y2 = _normalizeSelection$2[1];
1597
+
1598
+ if (isRowSelection(selection)) {
1599
+ x1 = 0;
1600
+ x2 = MAX_SEARCHABLE_INDEX;
1601
+ }
1602
+
1603
+ if (isColumnSelection(selection)) {
1604
+ y1 = 0;
1605
+ y2 = MAX_SEARCHABLE_INDEX;
1606
+ }
1607
+
1608
+ var changes = [];
1609
+
1610
+ for (var y = y1; y <= y2; y++) {
1611
+ for (var x = x1; x <= x2; x++) {
1612
+ if (!cellReadOnly(x, y)) {
1613
+ changes.push({
1614
+ x: x,
1615
+ y: y,
1616
+ value: null
1617
+ });
1618
+ }
1619
+ }
1620
+ }
1621
+
1622
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
1623
+ return;
1624
+ }
1625
+
1626
+ if (isEmptySelection(selection)) {
1627
+ return;
1628
+ }
1629
+
1630
+ if (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90 || e.key === 'Enter' || e.key === '-' || e.key === '.' || e.key === ',') {
1631
+ var cell = selection[0];
1632
+ var cellX = cell[0],
1633
+ cellY = cell[1];
1634
+
1635
+ if (cellReadOnly(cellX, cellY)) {
1636
+ return;
1637
+ }
1638
+
1639
+ onEdit === null || onEdit === void 0 ? void 0 : onEdit(cell, e.key !== 'Enter');
1640
+ return;
1641
+ }
1642
+
1643
+ e.preventDefault();
1644
+
1645
+ if (e.key in ARROW_KEYS) {
1646
+ var anchor = rawSelection[0],
1647
+ head = rawSelection[1];
1648
+ var direction = ARROW_KEYS[e.key];
1649
+ var step = getDirectionStep(direction);
1650
+ var shift = e.shiftKey;
1651
+
1652
+ if (e.metaKey || e.ctrlKey) {
1653
+ head = findInDisplayData(displayData, head, direction);
1654
+ } else {
1655
+ var limit = shift ? isRowSelection(selection) ? [-1, 0] : isColumnSelection(selection) ? [0, -1] : NEG_NEG : ORIGIN;
1656
+ head = maxXY(addXY(head, step), limit);
1657
+ }
1658
+
1659
+ if (!shift) {
1660
+ anchor = head;
1661
+ }
1662
+
1663
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], true, true);
1664
+ return;
1665
+ }
1666
+ };
1667
+
1668
+ var onGridFocus = function onGridFocus() {
1669
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
1670
+ };
1671
+
1672
+ var onGridBlur = function onGridBlur() {
1673
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(false);
1674
+ };
1675
+
1676
+ React.useLayoutEffect(function () {
1677
+ var overlay = overlayRef.current;
1678
+
1679
+ if (!overlay) {
1680
+ return;
1681
+ }
1682
+
1683
+ if (editMode || !focused) {
1684
+ return;
1685
+ }
1686
+
1687
+ if (document.activeElement === overlay) {
1688
+ return;
1689
+ }
1690
+
1691
+ var activeTagName = document.activeElement.tagName.toLowerCase();
1692
+
1693
+ if (!(activeTagName === 'div' && document.activeElement.contentEditable === 'true' || activeTagName === 'input' || activeTagName === 'textarea' || activeTagName === 'select')) {
1694
+ overlay.focus({
1695
+ preventScroll: true
1696
+ });
1697
+ }
1698
+ }, [editMode, focused]);
1699
+ return {
1700
+ onInputKeyDown: onInputKeyDown,
1701
+ onGridFocus: onGridFocus,
1702
+ onGridBlur: onGridBlur,
1703
+ onGridKeyDown: onGridKeyDown
1704
+ };
1705
+ };
1706
+
1500
1707
  var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange, onMaxScrollChange) {
1501
1708
  return React.useCallback(function (e) {
1502
1709
  if (!e.target || !(e.target instanceof Element)) {
@@ -1654,42 +1861,6 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1654
1861
  }
1655
1862
  };
1656
1863
 
1657
- var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
1658
- var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
1659
-
1660
- return {
1661
- freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
1662
- freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
1663
- hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
1664
- hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
1665
- hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
1666
- hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
1667
- columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
1668
- rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
1669
- shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
1670
- shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
1671
- shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
1672
- };
1673
- };
1674
- var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
1675
- return _extends({}, defaultStyle, optionalStyle);
1676
- };
1677
- var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
1678
- if (alignment === void 0) {
1679
- alignment = style.textAlign;
1680
- }
1681
-
1682
- if (alignment === 'left') {
1683
- return start + style.marginLeft;
1684
- } else if (alignment === 'center') {
1685
- return start + cellSize * 0.5 - imageWidth / 2;
1686
- } else if (alignment === 'right') {
1687
- return start + (cellSize - style.marginRight - imageWidth);
1688
- }
1689
-
1690
- return start;
1691
- };
1692
-
1693
1864
  var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
1694
1865
  var context = React.useMemo(function () {
1695
1866
  return document.createElement('canvas').getContext('2d');
@@ -1698,9 +1869,8 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1698
1869
  if (!context) return 0;
1699
1870
 
1700
1871
  var getWidth = function getWidth(cellContent, style) {
1701
- var finalStyle = resolveCellStyle(style, DEFAULT_CELL_STYLE);
1702
- context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
1703
- var inlineMargin = finalStyle.marginLeft + finalStyle.marginRight;
1872
+ context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
1873
+ var inlineMargin = style.marginLeft + style.marginRight;
1704
1874
 
1705
1875
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1706
1876
  var _context$measureText = context.measureText(cellContent.toString()),
@@ -1725,7 +1895,7 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1725
1895
  }
1726
1896
 
1727
1897
  if (obj.horizontalAlign === 'right') {
1728
- extraWidth += _width;
1898
+ extraWidth += style.textAlign === 'right' ? _width * 2 : _width;
1729
1899
  } else {
1730
1900
  _maxWidth = Math.max(_maxWidth, _width);
1731
1901
  }
@@ -1738,19 +1908,23 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1738
1908
  };
1739
1909
 
1740
1910
  var maxWidth = SIZES.minimumWidth;
1741
- var headerContent = columnHeaders(x);
1911
+
1912
+ var headerStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(x));
1913
+
1914
+ var headerContent = columnHeaders(x, headerStyle);
1742
1915
 
1743
1916
  if (headerContent) {
1744
- var headerStyle = columnHeaderStyle(x);
1745
1917
  maxWidth = Math.max(maxWidth, getWidth(headerContent, headerStyle));
1746
1918
  }
1747
1919
 
1748
1920
  for (var _iterator2 = _createForOfIteratorHelperLoose(rows), _step2; !(_step2 = _iterator2()).done;) {
1749
1921
  var y = _step2.value;
1750
- var cellContent = displayData(x, y);
1922
+
1923
+ var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle(x, y));
1924
+
1925
+ var cellContent = displayData(x, y, style);
1751
1926
 
1752
1927
  if (cellContent != null) {
1753
- var style = cellStyle(x, y);
1754
1928
  maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
1755
1929
  }
1756
1930
  }
@@ -1760,90 +1934,349 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1760
1934
  return getAutoSizeWidth;
1761
1935
  };
1762
1936
 
1763
- var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMode, editData) {
1937
+ // A type of promise-like that resolves synchronously and supports only one observer
1938
+
1939
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
1940
+
1941
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
1942
+
1943
+ // Asynchronously call a function and send errors to recovery continuation
1944
+ function _catch(body, recover) {
1945
+ try {
1946
+ var result = body();
1947
+ } catch(e) {
1948
+ return recover(e);
1949
+ }
1950
+ if (result && result.then) {
1951
+ return result.then(void 0, recover);
1952
+ }
1953
+ return result;
1954
+ }
1955
+
1956
+ var EMPTY_TABLE = {
1957
+ rows: []
1958
+ };
1959
+ var useClipboardTable = function useClipboardTable() {
1960
+ var _useState = React.useState(),
1961
+ peek = _useState[0],
1962
+ setPeek = _useState[1];
1963
+
1764
1964
  React.useLayoutEffect(function () {
1765
- var textArea = textAreaRef.current;
1766
- if (!textArea) return;
1767
- if (editMode) return;
1768
- if (isEmptySelection(selection)) return;
1769
- var v = formatSelectionAsTSV(selection, editData);
1965
+ var softRefresh = function softRefresh() {
1966
+ return Promise.resolve(_catch(function () {
1967
+ return Promise.resolve(navigator.permissions.query({
1968
+ name: 'clipboard-read'
1969
+ })).then(function (status) {
1970
+ if (status.state !== 'granted') return;
1971
+ hardRefresh();
1972
+ });
1973
+ }, function () {}));
1974
+ };
1975
+
1976
+ var hardRefresh = function hardRefresh() {
1977
+ try {
1978
+ var _temp3 = _catch(function () {
1979
+ return Promise.resolve(navigator.clipboard.read()).then(function (items) {
1980
+ var item = items[0];
1981
+
1982
+ var _temp = function () {
1983
+ if (item) {
1984
+ return Promise.resolve(parseClipboardTable(item)).then(function (peek) {
1985
+ setPeek(peek);
1986
+ });
1987
+ } else {
1988
+ setPeek(EMPTY_TABLE);
1989
+ }
1990
+ }();
1991
+
1992
+ if (_temp && _temp.then) return _temp.then(function () {});
1993
+ });
1994
+ }, function () {});
1995
+
1996
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
1997
+ } catch (e) {
1998
+ return Promise.reject(e);
1999
+ }
2000
+ };
2001
+
2002
+ var delayedRefresh = function delayedRefresh() {
2003
+ return setTimeout(hardRefresh);
2004
+ };
2005
+
2006
+ window.document.addEventListener('cut', delayedRefresh);
2007
+ window.document.addEventListener('copy', delayedRefresh);
2008
+ window.document.addEventListener('focus', softRefresh);
2009
+ softRefresh();
2010
+ return function () {
2011
+ window.document.removeEventListener('cut', delayedRefresh);
2012
+ window.document.removeEventListener('copy', delayedRefresh);
2013
+ window.document.removeEventListener('focus', softRefresh);
2014
+ };
2015
+ }, []);
2016
+ var canPaste = React.useCallback(function () {
2017
+ var _peek$rows;
1770
2018
 
1771
- if (v.match(/^[\t\n]*$/)) {
1772
- v = ' ' + v;
2019
+ return !!(peek == null || (_peek$rows = peek.rows) !== null && _peek$rows !== void 0 && _peek$rows.length);
2020
+ }, [peek]);
2021
+ return {
2022
+ peek: peek,
2023
+ canPaste: canPaste,
2024
+ copyTable: copyClipboardTable,
2025
+ pasteTable: pasteClipboardTable
2026
+ };
2027
+ };
2028
+ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly, addListener, onSelectionChange, onChange, onCopy, onPaste) {
2029
+ var _useClipboardTable = useClipboardTable(),
2030
+ canPaste = _useClipboardTable.canPaste,
2031
+ copyTable = _useClipboardTable.copyTable,
2032
+ pasteTable = _useClipboardTable.pasteTable;
2033
+
2034
+ var pasteIntoSelection = React.useCallback(function (selection, table) {
2035
+ try {
2036
+ var rows = table.rows,
2037
+ payload = table.payload;
2038
+
2039
+ var _normalizeSelection = normalizeSelection(selection),
2040
+ min = _normalizeSelection[0];
2041
+
2042
+ var minX = min[0],
2043
+ minY = min[1];
2044
+ var left = Math.max(0, minX);
2045
+ var top = Math.max(0, minY);
2046
+ var width = rows.reduce(function (a, b) {
2047
+ return Math.max(a, b.length);
2048
+ }, 0);
2049
+ var height = rows.length;
2050
+ var newSelection = [min, addXY(min, [width - 1, height - 1])];
2051
+ return Promise.resolve(onPaste === null || onPaste === void 0 ? void 0 : onPaste(newSelection, rows, payload)).then(function (shouldPaste) {
2052
+ if (shouldPaste !== false) {
2053
+ var changes = rows.flatMap(function (row, j) {
2054
+ return row.map(function (value, i) {
2055
+ var x = left + i;
2056
+ var y = top + j;
2057
+ return !(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y)) ? {
2058
+ x: x,
2059
+ y: y,
2060
+ value: value
2061
+ } : null;
2062
+ });
2063
+ }).filter(function (change) {
2064
+ return !!change;
2065
+ });
2066
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
2067
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newSelection);
2068
+ }
2069
+ });
2070
+ } catch (e) {
2071
+ return Promise.reject(e);
2072
+ }
2073
+ }, [onChange, onSelectionChange, cellReadOnly]);
2074
+ var copySelection = React.useCallback(function (selection, cut) {
2075
+ if (cut === void 0) {
2076
+ cut = false;
1773
2077
  }
1774
2078
 
1775
- textArea.value = v;
1776
- }, [selection, editMode, editData, textAreaRef]);
1777
- React.useLayoutEffect(function () {
1778
- var textArea = textAreaRef.current;
1779
- if (!textArea) return;
2079
+ try {
2080
+ var _payload$cut;
1780
2081
 
1781
- var focus = function focus() {
1782
- textArea.focus({
1783
- preventScroll: true
2082
+ var rows = formatSelectionAsRows(selection, editData);
2083
+ var payload = onCopy === null || onCopy === void 0 ? void 0 : onCopy(selection, rows, cut);
2084
+ copyTable(rows, payload);
2085
+
2086
+ if ((_payload$cut = payload === null || payload === void 0 ? void 0 : payload.cut) != null ? _payload$cut : cut) {
2087
+ var changes = [];
2088
+ forSelectionRows(selection)(function (y) {
2089
+ forSelectionColumns(selection)(function (x) {
2090
+ if (!(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y))) {
2091
+ var change = {
2092
+ x: x,
2093
+ y: y,
2094
+ value: ''
2095
+ };
2096
+ changes.push(change);
2097
+ }
2098
+ });
2099
+ });
2100
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
2101
+ }
2102
+
2103
+ return Promise.resolve();
2104
+ } catch (e) {
2105
+ return Promise.reject(e);
2106
+ }
2107
+ }, [onCopy, onChange, cellReadOnly]);
2108
+ var pasteSelection = React.useCallback(function (selection) {
2109
+ try {
2110
+ return Promise.resolve(pasteTable()).then(function (table) {
2111
+ if (table) pasteIntoSelection(selection, table);
1784
2112
  });
1785
- textArea.select();
1786
- };
2113
+ } catch (e) {
2114
+ return Promise.reject(e);
2115
+ }
2116
+ }, [pasteIntoSelection]);
1787
2117
 
1788
- if (editMode) return;
1789
- if (document.activeElement === textArea) return;
1790
- var activeTagName = document.activeElement.tagName.toLowerCase();
2118
+ var onClipboardCopy = function onClipboardCopy(cut) {
2119
+ if (isEmptySelection(selection)) return;
2120
+ return copySelection(selection, cut);
2121
+ };
1791
2122
 
1792
- if (!(activeTagName === 'div' && document.activeElement.contentEditable === 'true' || activeTagName === 'input' || activeTagName === 'textarea' || activeTagName === 'select')) {
1793
- focus();
2123
+ var onClipboardPaste = function onClipboardPaste(e) {
2124
+ try {
2125
+ e.preventDefault();
2126
+ var clipboardData = e.clipboardData || window.clipboardData;
2127
+ return Promise.resolve(parseClipboardTable(clipboardData)).then(function (table) {
2128
+ if (table) pasteIntoSelection(selection, table);
2129
+ });
2130
+ } catch (e) {
2131
+ return Promise.reject(e);
1794
2132
  }
2133
+ };
2134
+
2135
+ React.useLayoutEffect(function () {
2136
+ if (!addListener) return;
2137
+ window.document.addEventListener('paste', onClipboardPaste);
2138
+ return function () {
2139
+ window.document.removeEventListener('paste', onClipboardPaste);
2140
+ };
1795
2141
  });
2142
+ var clipboardApi = React.useMemo(function () {
2143
+ return {
2144
+ copySelection: copySelection,
2145
+ pasteSelection: pasteSelection,
2146
+ canPasteSelection: canPaste
2147
+ };
2148
+ }, [copySelection, pasteSelection, canPaste]);
2149
+ return {
2150
+ clipboardApi: clipboardApi,
2151
+ onClipboardCopy: onClipboardCopy,
2152
+ onClipboardPaste: onClipboardPaste
2153
+ };
2154
+ };
2155
+
2156
+ var copyClipboardTable = function copyClipboardTable(rows, payload) {
2157
+ try {
2158
+ var text = formatRowsAsTSV(rows);
2159
+ var html = formatRowsAsHTML(rows, payload != null ? payload : undefined);
2160
+ return Promise.resolve(navigator.clipboard.write([new ClipboardItem({
2161
+ 'text/html': new Blob([html], {
2162
+ type: 'text/html'
2163
+ }),
2164
+ 'text/plain': new Blob([text], {
2165
+ type: 'text/plain'
2166
+ })
2167
+ })])).then(function () {
2168
+ var event = new Event('copy');
2169
+ document.dispatchEvent(event);
2170
+ });
2171
+ } catch (e) {
2172
+ return Promise.reject(e);
2173
+ }
1796
2174
  };
1797
- var useClipboardPaste = function useClipboardPaste(textAreaRef, selection, onSelectionChange, onChange, isReadOnly) {
1798
- React.useEffect(function () {
1799
- var onPaste = function onPaste(e) {
1800
- var textArea = textAreaRef.current;
1801
- if (!textArea) return;
1802
- if (e.target !== textArea) return;
1803
- e.preventDefault();
1804
- var clipboardData = e.clipboardData || window.clipboardData;
1805
- var types = clipboardData.types;
1806
- var parsed;
1807
-
1808
- if (types.includes('text/html')) {
1809
- var pastedHtml = clipboardData.getData('text/html');
1810
- parsed = parsePastedHtml(selection, pastedHtml, isReadOnly);
1811
- } else if (types.includes('text/plain')) {
1812
- var text = clipboardData.getData('text/plain');
1813
- parsed = parsePastedText(selection, text, isReadOnly);
1814
- }
1815
2175
 
1816
- if (!parsed) return;
1817
- var _parsed = parsed,
1818
- s = _parsed.selection,
1819
- changes = _parsed.changes;
1820
- onChange === null || onChange === void 0 ? void 0 : onChange(changes);
1821
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(s);
2176
+ var pasteClipboardTable = function pasteClipboardTable() {
2177
+ try {
2178
+ return Promise.resolve(navigator.clipboard.read()).then(function (items) {
2179
+ var item = items[0];
2180
+ if (!item) return;
2181
+ return parseClipboardTable(item);
2182
+ });
2183
+ } catch (e) {
2184
+ return Promise.reject(e);
2185
+ }
2186
+ };
2187
+
2188
+ var parseClipboardTable = function parseClipboardTable(item) {
2189
+ try {
2190
+ var _temp7 = function _temp7() {
2191
+ return rows ? {
2192
+ rows: rows,
2193
+ payload: payload
2194
+ } : {
2195
+ rows: []
2196
+ };
1822
2197
  };
1823
2198
 
1824
- window.document.addEventListener('paste', onPaste);
1825
- return function () {
1826
- window.document.removeEventListener('paste', onPaste);
2199
+ var has = function has(type) {
2200
+ return item.types.includes(type);
2201
+ };
2202
+
2203
+ var get = function get(type) {
2204
+ if ('getData' in item) return item.getData(type);else if ('getType' in item) return item.getType(type).then(function (blob) {
2205
+ return blob.text();
2206
+ });
2207
+ return '';
1827
2208
  };
1828
- }, [textAreaRef, selection]);
2209
+
2210
+ var rows, payload;
2211
+
2212
+ var _temp8 = function () {
2213
+ if (has('text/html')) {
2214
+ return Promise.resolve(get('text/html')).then(function (pastedHtml) {
2215
+ var _parsePastedHtml = parsePastedHtml(pastedHtml);
2216
+
2217
+ rows = _parsePastedHtml.rows;
2218
+ payload = _parsePastedHtml.payload;
2219
+ });
2220
+ } else {
2221
+ var _temp9 = function () {
2222
+ if (has('text/plain')) {
2223
+ return Promise.resolve(get('text/plain')).then(function (text) {
2224
+ rows = parsePastedText(text);
2225
+ });
2226
+ }
2227
+ }();
2228
+
2229
+ if (_temp9 && _temp9.then) return _temp9.then(function () {});
2230
+ }
2231
+ }();
2232
+
2233
+ return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8));
2234
+ } catch (e) {
2235
+ return Promise.reject(e);
2236
+ }
1829
2237
  };
1830
2238
 
1831
- var formatTSV = function formatTSV(rows) {
2239
+ var formatRowsAsTSV = function formatRowsAsTSV(rows) {
1832
2240
  return rows.map(function (row) {
1833
2241
  return row.join('\t');
1834
2242
  }).join('\n');
1835
2243
  };
1836
2244
 
1837
- var formatSelectionAsTSV = function formatSelectionAsTSV(selection, editData) {
1838
- if (isEmptySelection(selection)) return '';
2245
+ var formatRowsAsHTML = function formatRowsAsHTML(rows, payload) {
2246
+ var trs = rows.map(function (row) {
2247
+ var tds = row.map(formatTextAsHTML).map(function (cell) {
2248
+ return "<td>" + cell + "</td>";
2249
+ });
2250
+ return tds.join('');
2251
+ }).map(function (row) {
2252
+ return "<tr>" + row + "</tr>";
2253
+ }).join('\n');
2254
+ var table = "<table>" + trs + "</table>";
1839
2255
 
1840
- var _normalizeSelection = normalizeSelection(selection),
1841
- _normalizeSelection$ = _normalizeSelection[0],
1842
- minX = _normalizeSelection$[0],
1843
- minY = _normalizeSelection$[1],
1844
- _normalizeSelection$2 = _normalizeSelection[1],
1845
- maxX = _normalizeSelection$2[0],
1846
- maxY = _normalizeSelection$2[1];
2256
+ if (payload) {
2257
+ var extra = "<SheetHappens payload=\"" + formatTextAsHTML(JSON.stringify(payload)) + "\"></SheetHappens>";
2258
+ return extra + table;
2259
+ }
2260
+
2261
+ return table;
2262
+ };
2263
+
2264
+ var formatTextAsHTML = function formatTextAsHTML(s) {
2265
+ return s.replace(/[&"'<>]/g, function (i) {
2266
+ return "&#" + i.charCodeAt(0) + ";";
2267
+ });
2268
+ };
2269
+
2270
+ var formatSelectionAsRows = function formatSelectionAsRows(selection, editData) {
2271
+ if (isEmptySelection(selection)) return [];
2272
+
2273
+ var _normalizeSelection2 = normalizeSelection(selection),
2274
+ _normalizeSelection2$ = _normalizeSelection2[0],
2275
+ minX = _normalizeSelection2$[0],
2276
+ minY = _normalizeSelection2$[1],
2277
+ _normalizeSelection2$2 = _normalizeSelection2[1],
2278
+ maxX = _normalizeSelection2$2[0],
2279
+ maxY = _normalizeSelection2$2[1];
1847
2280
 
1848
2281
  if (isMaybeRowSelection(selection)) {
1849
2282
  var _findApproxMaxEditDat = findApproxMaxEditDataIndex(editData),
@@ -1877,132 +2310,94 @@ var formatSelectionAsTSV = function formatSelectionAsTSV(selection, editData) {
1877
2310
  rows.push(row);
1878
2311
  }
1879
2312
 
1880
- return formatTSV(rows);
2313
+ return rows;
1881
2314
  };
1882
2315
 
1883
- var findTable = function findTable(element) {
2316
+ var findTag = function findTag(element, tagName) {
1884
2317
  for (var _iterator = _createForOfIteratorHelperLoose(element.children), _step; !(_step = _iterator()).done;) {
1885
2318
  var child = _step.value;
1886
2319
 
1887
- if (child.nodeName === 'TABLE') {
2320
+ if (child.nodeName === tagName) {
1888
2321
  return child;
1889
2322
  }
1890
2323
 
1891
- var maybeTable = findTable(child);
2324
+ var maybeTag = findTag(child, tagName);
1892
2325
 
1893
- if (maybeTable) {
1894
- return maybeTable;
2326
+ if (maybeTag) {
2327
+ return maybeTag;
1895
2328
  }
1896
2329
  }
1897
2330
  };
1898
2331
 
1899
- var parsePastedHtml = function parsePastedHtml(selection, html, isReadOnly) {
2332
+ var parsePastedHtml = function parsePastedHtml(html) {
1900
2333
  var div = document.createElement('div');
1901
2334
  div.innerHTML = html.trim();
2335
+ var rows = [];
2336
+ var payload = undefined;
2337
+ var sheetNode = findTag(div, 'SHEETHAPPENS');
1902
2338
 
1903
- var _normalizeSelection2 = normalizeSelection(selection),
1904
- _normalizeSelection2$ = _normalizeSelection2[0],
1905
- minX = _normalizeSelection2$[0],
1906
- minY = _normalizeSelection2$[1];
1907
-
1908
- var left = isMaybeRowSelection(selection) ? 0 : minX;
1909
- var top = isMaybeColumnSelection(selection) ? 0 : minY;
1910
- var changes = [];
1911
- var tableNode = findTable(div);
2339
+ if (sheetNode) {
2340
+ var json = sheetNode.getAttribute('payload');
1912
2341
 
1913
- if (!tableNode) {
1914
- return null;
2342
+ try {
2343
+ payload = JSON.parse(json);
2344
+ } catch (e) {}
1915
2345
  }
1916
2346
 
1917
- var right = left;
1918
- var bottom = top;
1919
- var y = top;
2347
+ var tableNode = findTag(div, 'TABLE');
1920
2348
 
1921
- for (var _iterator2 = _createForOfIteratorHelperLoose(tableNode.children), _step2; !(_step2 = _iterator2()).done;) {
1922
- var tableChild = _step2.value;
2349
+ if (tableNode) {
2350
+ for (var _iterator2 = _createForOfIteratorHelperLoose(tableNode.children), _step2; !(_step2 = _iterator2()).done;) {
2351
+ var tableChild = _step2.value;
1923
2352
 
1924
- if (tableChild.nodeName === 'TBODY') {
1925
- for (var _iterator3 = _createForOfIteratorHelperLoose(tableChild.children), _step3; !(_step3 = _iterator3()).done;) {
1926
- var tr = _step3.value;
1927
- var x = left;
2353
+ if (tableChild.nodeName === 'TBODY') {
2354
+ for (var _iterator3 = _createForOfIteratorHelperLoose(tableChild.children), _step3; !(_step3 = _iterator3()).done;) {
2355
+ var tr = _step3.value;
1928
2356
 
1929
- if (tr.nodeName === 'TR') {
1930
- for (var _iterator4 = _createForOfIteratorHelperLoose(tr.children), _step4; !(_step4 = _iterator4()).done;) {
1931
- var td = _step4.value;
2357
+ if (tr.nodeName === 'TR') {
2358
+ var row = [];
1932
2359
 
1933
- if (td.nodeName === 'TD') {
1934
- var str = '';
2360
+ for (var _iterator4 = _createForOfIteratorHelperLoose(tr.children), _step4; !(_step4 = _iterator4()).done;) {
2361
+ var td = _step4.value;
1935
2362
 
1936
- if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
1937
- var p = td.children[0];
2363
+ if (td.nodeName === 'TD') {
2364
+ var str = '';
1938
2365
 
1939
- if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
1940
- str = p.children[0].textContent.trim();
2366
+ if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
2367
+ var p = td.children[0];
2368
+
2369
+ if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
2370
+ str = p.children[0].textContent.trim();
2371
+ } else {
2372
+ str = p.textContent.trim();
2373
+ }
1941
2374
  } else {
1942
- str = p.textContent.trim();
2375
+ str = td.textContent.trim();
1943
2376
  }
1944
- } else {
1945
- str = td.textContent.trim();
1946
- }
1947
2377
 
1948
- str = str.replaceAll('\n', '');
1949
- str = str.replaceAll(/\s\s+/g, ' ');
1950
- if (!(isReadOnly !== null && isReadOnly !== void 0 && isReadOnly(x, y))) changes.push({
1951
- x: x,
1952
- y: y,
1953
- value: str
1954
- });
1955
- x++;
2378
+ str = str.replaceAll('\n', '');
2379
+ str = str.replaceAll(/\s\s+/g, ' ');
2380
+ row.push(str);
2381
+ }
1956
2382
  }
1957
- }
1958
2383
 
1959
- y++;
2384
+ rows.push(row);
2385
+ }
1960
2386
  }
1961
-
1962
- right = Math.max(right, x - 1);
1963
2387
  }
1964
2388
  }
1965
2389
  }
1966
2390
 
1967
- bottom = Math.max(top, y - 1);
1968
2391
  return {
1969
- selection: [[left, top], [right, bottom]],
1970
- changes: changes
2392
+ rows: rows,
2393
+ payload: payload
1971
2394
  };
1972
2395
  };
1973
2396
 
1974
- var parsePastedText = function parsePastedText(selection, text, isReadOnly) {
1975
- var _normalizeSelection3 = normalizeSelection(selection),
1976
- _normalizeSelection3$ = _normalizeSelection3[0],
1977
- minX = _normalizeSelection3$[0],
1978
- minY = _normalizeSelection3$[1];
1979
-
1980
- var left = isMaybeRowSelection(selection) ? 0 : minX;
1981
- var top = isMaybeColumnSelection(selection) ? 0 : minY;
1982
- var rows = text.split(/\r?\n/);
1983
- var right = left;
1984
- var bottom = top + rows.length - 1;
1985
- var changes = [];
1986
-
1987
- for (var y = 0; y < rows.length; y++) {
1988
- var cols = rows[y].split('\t');
1989
- right = Math.max(right, left + cols.length - 1);
1990
-
1991
- for (var x = 0; x < cols.length; x++) {
1992
- var X = left + x;
1993
- var Y = top + y;
1994
- if (!(isReadOnly !== null && isReadOnly !== void 0 && isReadOnly(X, Y))) changes.push({
1995
- x: X,
1996
- y: Y,
1997
- value: cols[x]
1998
- });
1999
- }
2000
- }
2001
-
2002
- return {
2003
- selection: [[left, top], [right, bottom]],
2004
- changes: changes
2005
- };
2397
+ var parsePastedText = function parsePastedText(text) {
2398
+ return text.split(/\r?\n/).map(function (line) {
2399
+ return line.split('\t');
2400
+ });
2006
2401
  };
2007
2402
 
2008
2403
  var INITIAL_SIZE = 256;
@@ -2178,10 +2573,13 @@ var makeCellLayout = function makeCellLayout(freeze, indent, offset, columns, ro
2178
2573
 
2179
2574
  var getVisibleIndices = function getVisibleIndices(view, indent, freeze, offset, layout) {
2180
2575
  var indices = [].concat(seq(freeze));
2181
- var getStart = layout.getStart;
2182
- var relative = view - indent + getStart(offset);
2576
+ var getStart = layout.getStart,
2577
+ getEnd = layout.getEnd;
2578
+ var frozen = getEnd(freeze - 1);
2579
+ var notFrozen = getStart(offset + freeze);
2580
+ var relative = view - indent - frozen;
2183
2581
 
2184
- for (var i = offset + freeze; getStart(i) <= relative; ++i) {
2582
+ for (var i = offset + freeze; getStart(i) - notFrozen <= relative; ++i) {
2185
2583
  indices.push(i);
2186
2584
  }
2187
2585
 
@@ -2382,7 +2780,40 @@ var makeIntMap = function makeIntMap(initialSize) {
2382
2780
  };
2383
2781
  };
2384
2782
 
2385
- var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2783
+ var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2784
+ var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
2785
+
2786
+ return {
2787
+ freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
2788
+ freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
2789
+ hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
2790
+ hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
2791
+ hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
2792
+ hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
2793
+ columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
2794
+ rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
2795
+ shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
2796
+ shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
2797
+ shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
2798
+ };
2799
+ };
2800
+ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
2801
+ if (alignment === void 0) {
2802
+ alignment = style.textAlign;
2803
+ }
2804
+
2805
+ if (alignment === 'left') {
2806
+ return start + style.marginLeft;
2807
+ } else if (alignment === 'center') {
2808
+ return start + cellSize * 0.5 - imageWidth / 2;
2809
+ } else if (alignment === 'right') {
2810
+ return start + (cellSize - style.marginRight - imageWidth);
2811
+ }
2812
+
2813
+ return start;
2814
+ };
2815
+
2816
+ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2386
2817
  var canvas = context.canvas;
2387
2818
  var width = canvas.width,
2388
2819
  height = canvas.height;
@@ -2544,11 +2975,13 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2544
2975
  var isGroupSelected = rowSelectionActive && isInRowGroup;
2545
2976
  var style = isSelfSelected ? HEADER_SELECTED_STYLE : isGroupSelected ? HEADER_GROUP_SELECTED_STYLE : isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2546
2977
 
2978
+ var resolvedStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, style);
2979
+
2547
2980
  var _top2 = rowToPixel(row);
2548
2981
 
2549
2982
  var _bottom2 = rowToPixel(row, 1);
2550
2983
 
2551
- clickables.push.apply(clickables, renderCell(context, content, style, DEFAULT_COLUMN_HEADER_STYLE, 0, _top2, rowHeaderWidth, _bottom2 - _top2));
2984
+ clickables.push.apply(clickables, renderCell(context, content, resolvedStyle, 0, _top2, rowHeaderWidth, _bottom2 - _top2));
2552
2985
  }
2553
2986
  }
2554
2987
 
@@ -2561,8 +2994,6 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2561
2994
 
2562
2995
  var column = _step5.value;
2563
2996
 
2564
- var _content = (_columnHeaders = columnHeaders(column)) != null ? _columnHeaders : excelHeaderString(column + 1);
2565
-
2566
2997
  var _isActive = isInRange(column, minX, maxX);
2567
2998
 
2568
2999
  var _groupKey = columnGroupKeys(column);
@@ -2572,19 +3003,22 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2572
3003
  var selectedStyle = isSelected ? HEADER_SELECTED_STYLE : NO_STYLE;
2573
3004
  var activeStyle = _isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2574
3005
 
2575
- var _style = _extends({}, columnHeaderStyle(column), activeStyle, selectedStyle);
3006
+ var _style = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(column), activeStyle, selectedStyle);
2576
3007
 
2577
3008
  var _left2 = columnToPixel(column);
2578
3009
 
2579
3010
  var _right2 = columnToPixel(column, 1);
2580
3011
 
2581
- clickables.push.apply(clickables, renderCell(context, _content, _style, DEFAULT_COLUMN_HEADER_STYLE, _left2, 0, _right2 - _left2, columnHeaderHeight));
3012
+ var _content = (_columnHeaders = columnHeaders(column, _style)) != null ? _columnHeaders : excelHeaderString(column + 1);
3013
+
3014
+ clickables.push.apply(clickables, renderCell(context, _content, _style, _left2, 0, _right2 - _left2, columnHeaderHeight));
2582
3015
  }
2583
3016
  }
2584
3017
 
2585
3018
  if (selectionActive) {
2586
3019
  context.strokeStyle = COLORS.selectionBorder;
2587
3020
  context.lineWidth = 2;
3021
+ context.globalAlpha = isFocused ? 1 : 0.5;
2588
3022
  var _selected$7 = selected[0],
2589
3023
  _left3 = _selected$7[0],
2590
3024
  _top3 = _selected$7[1],
@@ -2592,6 +3026,7 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2592
3026
  _right3 = _selected$8[0],
2593
3027
  _bottom3 = _selected$8[1];
2594
3028
  context.strokeRect(_left3, _top3, _right3 - _left3 - 1, _bottom3 - _top3 - 1);
3029
+ context.globalAlpha = 1;
2595
3030
  }
2596
3031
 
2597
3032
  for (var _iterator6 = _createForOfIteratorHelperLoose(secondarySelections), _step6; !(_step6 = _iterator6()).done;) {
@@ -2741,43 +3176,42 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2741
3176
 
2742
3177
  var _bottom10 = rowToPixel(_y, 1);
2743
3178
 
2744
- var cellContent = displayData(_x, _y);
3179
+ var _style2 = _extends({}, DEFAULT_CELL_STYLE, cellStyle(_x, _y));
2745
3180
 
2746
- if (cellContent !== null && cellContent !== undefined) {
2747
- var _style2 = cellStyle(_x, _y);
3181
+ var cellContent = displayData(_x, _y, _style2);
2748
3182
 
2749
- clickables.push.apply(clickables, renderCell(context, cellContent, _style2, DEFAULT_CELL_STYLE, _left9, _top9, _right10 - _left9, _bottom10 - _top9));
3183
+ if (cellContent !== null && cellContent !== undefined) {
3184
+ clickables.push.apply(clickables, renderCell(context, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9));
2750
3185
  }
2751
3186
  }
2752
3187
  }
2753
3188
 
2754
3189
  return clickables;
2755
3190
  };
2756
- var renderCell = function renderCell(context, cellContent, style, defaultCellStyle, xCoord, yCoord, cellWidth, cellHeight) {
3191
+ var renderCell = function renderCell(context, cellContent, style, xCoord, yCoord, cellWidth, cellHeight) {
2757
3192
  var clickables = [];
2758
3193
 
2759
3194
  if (cellContent === null) {
2760
3195
  return clickables;
2761
3196
  }
2762
3197
 
2763
- var finalStyle = resolveCellStyle(style, defaultCellStyle);
2764
- context.fillStyle = finalStyle.color;
2765
- context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
2766
- context.textAlign = finalStyle.textAlign;
3198
+ context.fillStyle = style.color;
3199
+ context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
3200
+ context.textAlign = style.textAlign;
2767
3201
  var yy = Math.floor(yCoord + cellHeight * 0.5);
2768
3202
  context.save();
2769
3203
  context.beginPath();
2770
3204
  context.rect(xCoord, yCoord, cellWidth, cellHeight);
2771
3205
  context.clip();
2772
3206
 
2773
- if (finalStyle.backgroundColor !== '') {
2774
- context.fillStyle = finalStyle.backgroundColor;
3207
+ if (style.backgroundColor !== '') {
3208
+ context.fillStyle = style.backgroundColor;
2775
3209
  context.fillRect(xCoord, yCoord, cellWidth, cellHeight);
2776
- context.fillStyle = finalStyle.color;
3210
+ context.fillStyle = style.color;
2777
3211
  }
2778
3212
 
2779
3213
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
2780
- var xx = applyAlignment(xCoord, cellWidth, finalStyle, 0);
3214
+ var xx = applyAlignment(xCoord, cellWidth, style, 0);
2781
3215
  var text = '' + cellContent;
2782
3216
  context.fillText(text, xx, yy);
2783
3217
  } else if (typeof cellContent === 'object') {
@@ -2791,7 +3225,7 @@ var renderCell = function renderCell(context, cellContent, style, defaultCellSty
2791
3225
  if (obj.content instanceof HTMLImageElement) {
2792
3226
  w = obj.width || cellWidth;
2793
3227
  h = obj.height || cellHeight;
2794
- var finalX = applyAlignment(xCoord, cellWidth, finalStyle, w, obj.horizontalAlign);
3228
+ var finalX = applyAlignment(xCoord, cellWidth, style, w, obj.horizontalAlign);
2795
3229
  x = finalX + obj.x;
2796
3230
  y = yy + obj.y;
2797
3231
  context.drawImage(obj.content, x, y, w, h);
@@ -2800,7 +3234,7 @@ var renderCell = function renderCell(context, cellContent, style, defaultCellSty
2800
3234
  context.textAlign = obj.horizontalAlign;
2801
3235
  }
2802
3236
 
2803
- var _finalX = applyAlignment(xCoord, cellWidth, finalStyle, 0, obj.horizontalAlign);
3237
+ var _finalX = applyAlignment(xCoord, cellWidth, style, 0, obj.horizontalAlign);
2804
3238
 
2805
3239
  var _text = '' + obj.content;
2806
3240
 
@@ -3026,8 +3460,8 @@ var Sheet = React.forwardRef(function (props, ref) {
3026
3460
  var selectionProp = (_props$selection = props.selection) != null ? _props$selection : NO_SELECTION;
3027
3461
 
3028
3462
  var _useState3 = React.useState(selectionProp),
3029
- selection = _useState3[0],
3030
- setSelection = _useState3[1];
3463
+ rawSelection = _useState3[0],
3464
+ setRawSelection = _useState3[1];
3031
3465
 
3032
3466
  var _useState4 = React.useState(null),
3033
3467
  knobArea = _useState4[0],
@@ -3049,22 +3483,26 @@ var Sheet = React.forwardRef(function (props, ref) {
3049
3483
  editCell = _useState8[0],
3050
3484
  setEditCell = _useState8[1];
3051
3485
 
3052
- var _useState9 = React.useState(selectionProp),
3053
- lastSelectionProp = _useState9[0],
3054
- setLastSelectionProp = _useState9[1];
3486
+ var _useState9 = React.useState(!!props.autoFocus),
3487
+ focused = _useState9[0],
3488
+ setFocused = _useState9[1];
3489
+
3490
+ var _useState10 = React.useState(selectionProp),
3491
+ lastSelectionProp = _useState10[0],
3492
+ setLastSelectionProp = _useState10[1];
3055
3493
 
3056
3494
  if (lastSelectionProp !== selectionProp) {
3057
3495
  setLastSelectionProp(selectionProp);
3058
- setSelection(selectionProp);
3496
+ setRawSelection(selectionProp);
3059
3497
  }
3060
3498
 
3061
- var _useState10 = React.useState(''),
3062
- editValue = _useState10[0],
3063
- setEditValue = _useState10[1];
3499
+ var _useState11 = React.useState(''),
3500
+ editValue = _useState11[0],
3501
+ setEditValue = _useState11[1];
3064
3502
 
3065
- var _useState11 = React.useState(false),
3066
- arrowKeyCommitMode = _useState11[0],
3067
- setArrowKeyCommitMode = _useState11[1];
3503
+ var _useState12 = React.useState(false),
3504
+ arrowKeyCommitMode = _useState12[0],
3505
+ setArrowKeyCommitMode = _useState12[1];
3068
3506
 
3069
3507
  var _useResizeObserver = useResizeObserver({
3070
3508
  ref: overlayRef
@@ -3081,7 +3519,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3081
3519
  return createRowOrColumnProp(props.cellHeight, 22);
3082
3520
  }, [props.cellHeight]);
3083
3521
  var columnHeaders = React.useMemo(function () {
3084
- return createRowOrColumnProp(props.columnHeaders, null);
3522
+ return createRowOrColumnStyledProp(props.columnHeaders, null);
3085
3523
  }, [props.columnHeaders]);
3086
3524
  var columnHeaderStyle = React.useMemo(function () {
3087
3525
  return createRowOrColumnProp(props.columnHeaderStyle, {});
@@ -3111,7 +3549,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3111
3549
  return createCellProp(props.sourceData, null);
3112
3550
  }, [props.sourceData]);
3113
3551
  var displayData = React.useMemo(function () {
3114
- return createCellProp(props.displayData, '');
3552
+ return createCellStyledProp(props.displayData, '');
3115
3553
  }, [props.displayData]);
3116
3554
  var editData = React.useMemo(function () {
3117
3555
  return createCellProp(props.editData, '');
@@ -3126,6 +3564,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3126
3564
  return resolveSheetStyle(props.sheetStyle);
3127
3565
  }, [props.sheetStyle]);
3128
3566
  var secondarySelections = (_props$secondarySelec = props.secondarySelections) != null ? _props$secondarySelec : NO_SELECTIONS;
3567
+ var selection = React.useMemo(function () {
3568
+ return validateSelection(rawSelection);
3569
+ }, [rawSelection]);
3129
3570
  var selectedColumnGroups = React.useMemo(function () {
3130
3571
  return props.columnGroupKeys ? new Set(mapSelectionColumns(selection)(function (x) {
3131
3572
  return columnGroupKeys(x);
@@ -3204,7 +3645,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3204
3645
  }
3205
3646
 
3206
3647
  if (!isSameSelection(selection, newSelection)) {
3207
- setSelection(validateSelection(newSelection));
3648
+ setRawSelection(newSelection);
3208
3649
  }
3209
3650
 
3210
3651
  var overlay = overlayRef.current;
@@ -3215,7 +3656,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3215
3656
  }
3216
3657
 
3217
3658
  if (props.onSelectionChanged) {
3218
- var _normalizeSelection = normalizeSelection(newSelection),
3659
+ var _normalizeSelection = normalizeSelection(validateSelection(newSelection)),
3219
3660
  _normalizeSelection$ = _normalizeSelection[0],
3220
3661
  minX = _normalizeSelection$[0],
3221
3662
  minY = _normalizeSelection$[1],
@@ -3227,6 +3668,11 @@ var Sheet = React.forwardRef(function (props, ref) {
3227
3668
  }
3228
3669
  };
3229
3670
 
3671
+ var cancelEditingCell = function cancelEditingCell() {
3672
+ setEditCell(NO_CELL);
3673
+ setFocused(true);
3674
+ };
3675
+
3230
3676
  var commitEditingCell = function commitEditingCell(value) {
3231
3677
  if (props.onChange) {
3232
3678
  var cellX = editCell[0],
@@ -3239,6 +3685,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3239
3685
  }
3240
3686
 
3241
3687
  setEditCell(NO_CELL);
3688
+ setFocused(true);
3242
3689
  };
3243
3690
 
3244
3691
  var startEditingCell = function startEditingCell(editCell, arrowKeyCommitMode) {
@@ -3276,16 +3723,25 @@ var Sheet = React.forwardRef(function (props, ref) {
3276
3723
  setDataOffset(clipDataOffset(view, dataOffset, freeze, [maxColumns, maxRows], cellLayout));
3277
3724
  }, [maxRows, maxColumns]);
3278
3725
  var hitmapRef = React.useRef(NO_CLICKABLES);
3279
- var textAreaRef = React.useRef(null);
3280
- useClipboardCopy(textAreaRef, selection, editMode, editData);
3281
- useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
3726
+ var isFocused = focused || editMode;
3727
+
3728
+ var _useClipboardAPI = useClipboardAPI(selection, editData, cellReadOnly, isFocused, changeSelection, props.onChange, props.onCopy, props.onPaste),
3729
+ clipboardApi = _useClipboardAPI.clipboardApi,
3730
+ onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3731
+
3282
3732
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3283
3733
  var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3284
3734
 
3285
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, 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, props.dontChangeSelectionOnOrderChange),
3735
+ var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, 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),
3286
3736
  mouseHandlers = _useMouse.mouseHandlers,
3287
3737
  knobPosition = _useMouse.knobPosition;
3288
3738
 
3739
+ var _useKeyboard = useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, startEditingCell, commitEditingCell, cancelEditingCell, changeSelection, setFocused, onClipboardCopy, props.onChange),
3740
+ onInputKeyDown = _useKeyboard.onInputKeyDown,
3741
+ onGridKeyDown = _useKeyboard.onGridKeyDown,
3742
+ onGridFocus = _useKeyboard.onGridFocus,
3743
+ onGridBlur = _useKeyboard.onGridBlur;
3744
+
3289
3745
  React.useLayoutEffect(function () {
3290
3746
  var canvas = canvasRef.current;
3291
3747
 
@@ -3300,130 +3756,16 @@ var Sheet = React.forwardRef(function (props, ref) {
3300
3756
  }
3301
3757
 
3302
3758
  var animationFrameId = window.requestAnimationFrame(function () {
3303
- hitmapRef.current = renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
3759
+ hitmapRef.current = renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
3304
3760
  });
3305
3761
  return function () {
3306
3762
  window.cancelAnimationFrame(animationFrameId);
3307
3763
  };
3308
- }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset]);
3309
-
3310
- var onKeyDown = function onKeyDown(e) {
3311
- if (e.key === 'Escape') {
3312
- setEditCell(NO_CELL);
3313
- return;
3314
- }
3315
-
3316
- var direction = e.key === 'Enter' ? 'down' : e.key === 'Tab' ? 'right' : arrowKeyCommitMode ? ARROW_KEYS[e.key] : null;
3317
-
3318
- if (direction) {
3319
- e.preventDefault();
3320
- var step = getDirectionStep(direction);
3321
- var head = maxXY(addXY(editCell, step), ORIGIN);
3322
- commitEditingCell();
3323
- changeSelection([head, head]);
3324
- }
3325
- };
3326
-
3327
- var onGridKeyDown = function onGridKeyDown(e) {
3328
- if (editMode && arrowKeyCommitMode && e.key in ARROW_KEYS) {
3329
- commitEditingCell();
3330
- return;
3331
- }
3332
-
3333
- if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'v') {
3334
- return;
3335
- }
3336
-
3337
- if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'c') {
3338
- var textArea = textAreaRef.current;
3339
- textArea === null || textArea === void 0 ? void 0 : textArea.select();
3340
- return;
3341
- }
3342
-
3343
- if (e.key === 'Backspace' || e.key === 'Delete') {
3344
- var _normalizeSelection2 = normalizeSelection(selection),
3345
- _normalizeSelection2$ = _normalizeSelection2[0],
3346
- x1 = _normalizeSelection2$[0],
3347
- y1 = _normalizeSelection2$[1],
3348
- _normalizeSelection2$2 = _normalizeSelection2[1],
3349
- x2 = _normalizeSelection2$2[0],
3350
- y2 = _normalizeSelection2$2[1];
3351
-
3352
- if (isRowSelection(selection)) {
3353
- x1 = 0;
3354
- x2 = MAX_SEARCHABLE_INDEX;
3355
- }
3356
-
3357
- if (isColumnSelection(selection)) {
3358
- y1 = 0;
3359
- y2 = MAX_SEARCHABLE_INDEX;
3360
- }
3361
-
3362
- var changes = [];
3363
-
3364
- for (var y = y1; y <= y2; y++) {
3365
- for (var x = x1; x <= x2; x++) {
3366
- if (!cellReadOnly(x, y)) {
3367
- changes.push({
3368
- x: x,
3369
- y: y,
3370
- value: null
3371
- });
3372
- }
3373
- }
3374
- }
3375
-
3376
- if (props.onChange) {
3377
- props.onChange(changes);
3378
- }
3379
-
3380
- return;
3381
- }
3382
-
3383
- if (isEmptySelection(selection)) {
3384
- return;
3385
- }
3386
-
3387
- if (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90 || e.key === 'Enter' || e.key === '-' || e.key === '.' || e.key === ',') {
3388
- var cell = selection[0];
3389
- var cellX = cell[0],
3390
- cellY = cell[1];
3391
-
3392
- if (cellReadOnly(cellX, cellY)) {
3393
- e.preventDefault();
3394
- return;
3395
- }
3396
-
3397
- startEditingCell(cell, e.key !== 'Enter');
3398
- return;
3399
- }
3400
-
3401
- if (e.key in ARROW_KEYS) {
3402
- var anchor = selection[0],
3403
- head = selection[1];
3404
- var direction = ARROW_KEYS[e.key];
3405
- var step = getDirectionStep(direction);
3406
-
3407
- if (e.metaKey || e.ctrlKey) {
3408
- head = findInDisplayData(displayData, head, direction);
3409
- } else {
3410
- head = maxXY(addXY(head, step), ORIGIN);
3411
- }
3412
-
3413
- if (!e.shiftKey) {
3414
- anchor = head;
3415
- }
3764
+ }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset]);
3416
3765
 
3417
- changeSelection([anchor, head], true, true);
3418
- return;
3419
- }
3420
-
3421
- e.preventDefault();
3422
- };
3423
-
3424
- var _useState12 = React.useState(''),
3425
- lastEditKey = _useState12[0],
3426
- setLastEditKey = _useState12[1];
3766
+ var _useState13 = React.useState(''),
3767
+ lastEditKey = _useState13[0],
3768
+ setLastEditKey = _useState13[1];
3427
3769
 
3428
3770
  var editTextPosition = ORIGIN;
3429
3771
  var editTextWidth = 0;
@@ -3451,7 +3793,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3451
3793
  var inputProps = {
3452
3794
  value: editValue,
3453
3795
  autoFocus: true,
3454
- onKeyDown: onKeyDown,
3796
+ onKeyDown: onInputKeyDown,
3455
3797
  style: {
3456
3798
  position: 'absolute',
3457
3799
  left: textX,
@@ -3478,6 +3820,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3478
3820
  top: 0,
3479
3821
  left: 0,
3480
3822
  overflow: 'scroll',
3823
+ outline: 0,
3481
3824
  borderBottom: '1px solid #ddd'
3482
3825
  };
3483
3826
  var canvasStyles = {
@@ -3513,10 +3856,10 @@ var Sheet = React.forwardRef(function (props, ref) {
3513
3856
  });
3514
3857
  }, [props.renderOutside, visibleCells, cellLayout, selection, editMode]);
3515
3858
  React.useImperativeHandle(ref, function () {
3516
- return _extends({}, cellLayout, {
3859
+ return _extends({}, cellLayout, clipboardApi, {
3517
3860
  startEditingCell: startEditingCell
3518
3861
  });
3519
- }, [cellLayout, startEditingCell]);
3862
+ }, [cellLayout, clipboardApi, startEditingCell]);
3520
3863
  return React__default.createElement("div", {
3521
3864
  style: {
3522
3865
  position: 'relative',
@@ -3529,6 +3872,10 @@ var Sheet = React.forwardRef(function (props, ref) {
3529
3872
  }), React__default.createElement("div", Object.assign({
3530
3873
  ref: overlayRef
3531
3874
  }, mouseHandlers, {
3875
+ onKeyDown: onGridKeyDown,
3876
+ onFocus: onGridFocus,
3877
+ onBlur: onGridBlur,
3878
+ tabIndex: 0,
3532
3879
  onScroll: onScroll,
3533
3880
  className: overlayDivClassName,
3534
3881
  style: overlayDivStyles
@@ -3565,26 +3912,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3565
3912
  height: '100%',
3566
3913
  pointerEvents: 'none'
3567
3914
  }
3568
- }, renderedOutside) : null, React__default.createElement("textarea", {
3569
- style: {
3570
- position: 'absolute',
3571
- top: 0,
3572
- left: 0,
3573
- width: 1,
3574
- height: 1,
3575
- opacity: 0.01
3576
- },
3577
- ref: textAreaRef,
3578
- autoComplete: "off",
3579
- autoCorrect: "off",
3580
- autoCapitalize: "off",
3581
- spellCheck: "false",
3582
- onFocus: function onFocus(e) {
3583
- return e.target.select();
3584
- },
3585
- tabIndex: 0,
3586
- onKeyDown: onGridKeyDown
3587
- }), editMode && (input !== undefined ? input : React__default.createElement("input", Object.assign({}, inputProps, {
3915
+ }, renderedOutside) : null, editMode && (input !== undefined ? input : React__default.createElement("input", Object.assign({}, inputProps, {
3588
3916
  type: "text",
3589
3917
  onFocus: function onFocus(e) {
3590
3918
  return e.target.select();
@@ -3595,5 +3923,6 @@ var Sheet = React.forwardRef(function (props, ref) {
3595
3923
  }))));
3596
3924
  });
3597
3925
 
3598
- module.exports = Sheet;
3926
+ exports.default = Sheet;
3927
+ exports.useClipboardTable = useClipboardTable;
3599
3928
  //# sourceMappingURL=index.js.map