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