@rowsncolumns/grid 8.0.7 → 9.0.0

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.
Files changed (72) hide show
  1. package/dist/Cell.d.ts +1 -1
  2. package/dist/Cell.js +10 -6
  3. package/dist/Cell.js.map +1 -1
  4. package/dist/CellOverlay.js +17 -12
  5. package/dist/CellOverlay.js.map +1 -1
  6. package/dist/FillHandle.d.ts +1 -1
  7. package/dist/FillHandle.js +2 -2
  8. package/dist/FillHandle.js.map +1 -1
  9. package/dist/Grid.d.ts +17 -15
  10. package/dist/Grid.js +139 -133
  11. package/dist/Grid.js.map +1 -1
  12. package/dist/GridLine.d.ts +1 -1
  13. package/dist/GridLine.js.map +1 -1
  14. package/dist/Image.d.ts +2 -2
  15. package/dist/Image.js +13 -7
  16. package/dist/Image.js.map +1 -1
  17. package/dist/Selection.js +2 -2
  18. package/dist/Selection.js.map +1 -1
  19. package/dist/helpers.d.ts +6 -7
  20. package/dist/helpers.js +139 -100
  21. package/dist/helpers.js.map +1 -1
  22. package/dist/hooks/useCopyPaste.js +12 -12
  23. package/dist/hooks/useCopyPaste.js.map +1 -1
  24. package/dist/hooks/useEditable.d.ts +3 -3
  25. package/dist/hooks/useEditable.js +57 -52
  26. package/dist/hooks/useEditable.js.map +1 -1
  27. package/dist/hooks/useFilter.d.ts +7 -7
  28. package/dist/hooks/useFilter.js +17 -13
  29. package/dist/hooks/useFilter.js.map +1 -1
  30. package/dist/hooks/useImage.js +2 -2
  31. package/dist/hooks/useImage.js.map +1 -1
  32. package/dist/hooks/usePagination.d.ts +1 -1
  33. package/dist/hooks/usePagination.js +8 -4
  34. package/dist/hooks/usePagination.js.map +1 -1
  35. package/dist/hooks/useSelection.d.ts +2 -2
  36. package/dist/hooks/useSelection.js +69 -68
  37. package/dist/hooks/useSelection.js.map +1 -1
  38. package/dist/hooks/useSizer.d.ts +3 -3
  39. package/dist/hooks/useSizer.js +19 -19
  40. package/dist/hooks/useSizer.js.map +1 -1
  41. package/dist/hooks/useTooltip.js +22 -18
  42. package/dist/hooks/useTooltip.js.map +1 -1
  43. package/dist/hooks/useTouch.js +12 -11
  44. package/dist/hooks/useTouch.js.map +1 -1
  45. package/dist/hooks/useUndo.js +9 -9
  46. package/dist/hooks/useUndo.js.map +1 -1
  47. package/dist/index.js +6 -2
  48. package/dist/index.js.map +1 -1
  49. package/dist/types.d.ts +1 -1
  50. package/dist/utils.d.ts +1 -1
  51. package/dist/utils.js +25 -23
  52. package/dist/utils.js.map +1 -1
  53. package/package.json +9 -9
  54. package/src/Cell.tsx +1 -1
  55. package/src/FillHandle.tsx +2 -2
  56. package/src/Grid.tsx +27 -31
  57. package/src/GridLine.tsx +3 -3
  58. package/src/Image.tsx +31 -18
  59. package/src/helpers.ts +2 -2
  60. package/src/hooks/useCopyPaste.ts +2 -2
  61. package/src/hooks/useEditable.tsx +8 -10
  62. package/src/hooks/useFilter.tsx +3 -3
  63. package/src/hooks/useSelection.ts +17 -28
  64. package/src/hooks/useSizer.ts +2 -2
  65. package/src/hooks/useTooltip.tsx +2 -3
  66. package/src/hooks/useTouch.ts +14 -6
  67. package/src/tests/Grid.spec.tsx +2 -3
  68. package/src/tests/usePagination.test.ts +1 -1
  69. package/src/tests/useSelection.test.ts +3 -1
  70. package/src/utils.tsx +2 -2
  71. package/src/.DS_Store +0 -0
  72. package/src/hooks/.DS_Store +0 -0
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { ShapeConfig } from "konva/types/Shape";
2
+ import { ShapeConfig } from "konva/lib/Shape";
3
3
 
4
4
  /**
5
5
  * Fill handle component
@@ -25,7 +25,7 @@ const FillHandle: React.FC<ShapeConfig> = ({
25
25
  border: `${strokeWidth}px ${borderColor} solid`,
26
26
  borderRightWidth: 0,
27
27
  borderBottomWidth: 0,
28
- background: stroke,
28
+ background: stroke as string,
29
29
  cursor: "crosshair",
30
30
  pointerEvents: "all",
31
31
  }}
package/src/Grid.tsx CHANGED
@@ -9,8 +9,9 @@ import React, {
9
9
  memo,
10
10
  useEffect,
11
11
  Key,
12
+ UIEvent,
12
13
  } from "react";
13
- import { Stage, Layer, Group, Line } from "react-konva/lib/ReactKonvaCore";
14
+ import { Stage, Layer, Group, Line } from "react-konva";
14
15
  import {
15
16
  getRowStartIndexForOffset,
16
17
  getRowStopIndexForStartIndex,
@@ -35,7 +36,7 @@ import {
35
36
  clampIndex,
36
37
  canUseDOM,
37
38
  } from "./helpers";
38
- import { ShapeConfig } from "konva/types/Shape";
39
+ import type { ShapeConfig } from "konva/lib/Shape";
39
40
  import { CellRenderer as defaultItemRenderer } from "./Cell";
40
41
  import { CellRenderer as defaultOverlayRenderer } from "./CellOverlay";
41
42
  import Selection from "./Selection";
@@ -43,12 +44,12 @@ import FillHandle from "./FillHandle";
43
44
  import GridLine from "./GridLine";
44
45
  import { createHTMLBox } from "./utils";
45
46
  import invariant from "tiny-invariant";
46
- import { StageConfig } from "konva/types/Stage";
47
+ import type { StageConfig } from "konva/lib/Stage";
47
48
  import { Direction } from "./types";
48
49
  import Konva from "konva";
49
50
 
50
51
  export interface GridProps
51
- extends Omit<React.HTMLAttributes<HTMLDivElement>, "onScroll"> {
52
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, "onScroll" | "children"> {
52
53
  /**
53
54
  * Width of the grid
54
55
  */
@@ -304,8 +305,10 @@ export interface ScrollState extends ScrollCoords {
304
305
  }
305
306
 
306
307
  export type RenderComponent = React.FC<RendererProps>;
307
- export interface CellPosition
308
- extends Pick<ShapeConfig, "x" | "y" | "width" | "height"> {}
308
+ export interface CellPosition extends Pick<ShapeConfig, "x" | "y"> {
309
+ width?: ShapeConfig["width"];
310
+ height?: ShapeConfig["height"];
311
+ }
309
312
  export interface RendererProps
310
313
  extends CellInterface,
311
314
  CellPosition,
@@ -621,7 +624,7 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
621
624
  * Get top offset of rowIndex
622
625
  */
623
626
  const getRowOffset = useCallback(
624
- (index) => {
627
+ (index: number) => {
625
628
  return getRowOffsetHelper({
626
629
  index,
627
630
  rowHeight,
@@ -637,7 +640,7 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
637
640
  * Get lefft offset of columnIndex
638
641
  */
639
642
  const getColumnOffset = useCallback(
640
- (index) => {
643
+ (index: number) => {
641
644
  return getColumnOffsetHelper({
642
645
  index,
643
646
  rowHeight,
@@ -653,7 +656,7 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
653
656
  * Get height of rowIndex
654
657
  */
655
658
  const getRowHeight = useCallback(
656
- (index) => {
659
+ (index: number) => {
657
660
  return getRowHeightHelper(index, instanceProps.current);
658
661
  },
659
662
  [instanceProps.current]
@@ -663,7 +666,7 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
663
666
  * Get height of columNiondex
664
667
  */
665
668
  const getColumnWidth = useCallback(
666
- (index) => {
669
+ (index: number) => {
667
670
  return getColumnWidthHelper(index, instanceProps.current);
668
671
  },
669
672
  [instanceProps.current]
@@ -967,11 +970,8 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
967
970
  if (!verticalScrollRef.current || !scrollSnapRefs.current) return;
968
971
  if (deltaY !== 0) {
969
972
  const direction = deltaY < 0 ? Direction.Up : Direction.Down;
970
- const {
971
- visibleRowStartIndex,
972
- rowCount,
973
- isHiddenRow,
974
- } = scrollSnapRefs.current;
973
+ const { visibleRowStartIndex, rowCount, isHiddenRow } =
974
+ scrollSnapRefs.current;
975
975
  let nextRowIndex =
976
976
  direction === Direction.Up
977
977
  ? // User is scrolling up
@@ -991,11 +991,8 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
991
991
  const snapToColumnFn = useCallback(({ deltaX }: SnapColumnProps) => {
992
992
  if (!horizontalScrollRef.current || !scrollSnapRefs.current) return;
993
993
  if (deltaX !== 0) {
994
- const {
995
- visibleColumnStartIndex,
996
- columnCount,
997
- isHiddenColumn,
998
- } = scrollSnapRefs.current;
994
+ const { visibleColumnStartIndex, columnCount, isHiddenColumn } =
995
+ scrollSnapRefs.current;
999
996
  const direction = deltaX < 0 ? Direction.Left : Direction.Right;
1000
997
  let nextColumnIndex =
1001
998
  direction === Direction.Left
@@ -1013,9 +1010,8 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
1013
1010
  }
1014
1011
  }, []);
1015
1012
  const snapToRowThrottler = useRef<({ deltaY }: SnapRowProps) => void>();
1016
- const snapToColumnThrottler = useRef<
1017
- ({ deltaX }: SnapColumnProps) => void
1018
- >();
1013
+ const snapToColumnThrottler =
1014
+ useRef<({ deltaX }: SnapColumnProps) => void>();
1019
1015
 
1020
1016
  /**
1021
1017
  * Register snap throttlers
@@ -1247,8 +1243,8 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
1247
1243
 
1248
1244
  /* Handle vertical scroll */
1249
1245
  const handleScroll = useCallback(
1250
- (e) => {
1251
- const { scrollTop } = e.target;
1246
+ (e: UIEvent<Element>) => {
1247
+ const { scrollTop } = e.currentTarget;
1252
1248
 
1253
1249
  setScrollState((prev) => ({
1254
1250
  ...prev,
@@ -1269,8 +1265,8 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
1269
1265
 
1270
1266
  /* Handle horizontal scroll */
1271
1267
  const handleScrollLeft = useCallback(
1272
- (e) => {
1273
- const { scrollLeft } = e.target;
1268
+ (e: UIEvent<Element>) => {
1269
+ const { scrollLeft } = e.currentTarget;
1274
1270
  setScrollState((prev) => ({
1275
1271
  ...prev,
1276
1272
  isScrolling: true,
@@ -1441,7 +1437,7 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
1441
1437
  /**
1442
1438
  * Fired when user tries to scroll the canvas
1443
1439
  */
1444
- const handleWheel = useCallback((event: globalThis.MouseWheelEvent) => {
1440
+ const handleWheel = useCallback((event: WheelEvent) => {
1445
1441
  /* If user presses shift key, scroll horizontally */
1446
1442
  const isScrollingHorizontally = event.shiftKey;
1447
1443
 
@@ -1638,11 +1634,11 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
1638
1634
 
1639
1635
  const mergedCellRenderMap = new Set();
1640
1636
  /* Draw all cells */
1641
- const cells: React.ReactNodeArray = [];
1637
+ const cells: React.ReactNode[] = [];
1642
1638
  /**
1643
1639
  * Lets users draw cells on top of existing canvas
1644
1640
  */
1645
- const cellOverlays: React.ReactNodeArray = [];
1641
+ const cellOverlays: React.ReactNode[] = [];
1646
1642
 
1647
1643
  if (columnCount > 0 && rowCount) {
1648
1644
  for (let rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
@@ -1770,7 +1766,7 @@ const Grid: React.FC<GridProps & RefAttribute> = memo(
1770
1766
 
1771
1767
  /* Draw frozen rows */
1772
1768
  const frozenRowCells = [];
1773
- const frozenRowCellOverlays: React.ReactNodeArray = [];
1769
+ const frozenRowCellOverlays: React.ReactNode[] = [];
1774
1770
  for (
1775
1771
  let rowIndex = 0;
1776
1772
  rowIndex < Math.min(rowStopIndex, frozenRows);
package/src/GridLine.tsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import React from "react";
2
- import { ShapeConfig } from "konva/types/Shape";
2
+ import { ShapeConfig } from "konva/lib/Shape";
3
3
  import { Line } from "react-konva";
4
4
 
5
5
  const GridLine: React.FC<ShapeConfig> = (props) => {
6
- const { points, stroke, strokeWidth, offsetY, offsetX } = props
6
+ const { points, stroke, strokeWidth, offsetY, offsetX } = props;
7
7
  return (
8
8
  <Line
9
9
  points={points}
@@ -17,7 +17,7 @@ const GridLine: React.FC<ShapeConfig> = (props) => {
17
17
  listening={false}
18
18
  perfectDrawEnabled={false}
19
19
  />
20
- )
20
+ );
21
21
  };
22
22
 
23
23
  export default GridLine;
package/src/Image.tsx CHANGED
@@ -1,30 +1,43 @@
1
- import React, { useMemo, memo } from 'react';
2
- import { Image } from 'react-konva';
3
- import useImage from './hooks/useImage';
4
- import { ShapeConfig } from 'konva/types/Shape';
1
+ import React, { useMemo, memo } from "react";
2
+ import { Image } from "react-konva";
3
+ import useImage from "./hooks/useImage";
4
+ import { ShapeConfig } from "konva/lib/Shape";
5
5
 
6
6
  export interface ImageProps extends ShapeConfig {
7
7
  url: string;
8
- spacing?: number
8
+ spacing?: number;
9
9
  }
10
10
 
11
11
  const ImageComponent: React.FC<ImageProps> = memo((props) => {
12
- let { url, width = 0, height = 0, x = 0, y = 0, spacing = 1, ...rest } = props
13
- const { image, width: imageWidth, height: imageHeight, status } = useImage({ url });
12
+ let {
13
+ url,
14
+ width = 0,
15
+ height = 0,
16
+ x = 0,
17
+ y = 0,
18
+ spacing = 1,
19
+ ...rest
20
+ } = props;
21
+ const { image, width: imageWidth, height: imageHeight, status } = useImage({
22
+ url,
23
+ });
14
24
  const aspectRatio = useMemo(() => {
15
- return Math.min((width - spacing) / imageWidth, (height - spacing) / imageHeight)
16
- }, [ imageWidth, imageHeight, width, height, spacing])
17
- x = x + spacing
18
- y = y + spacing
19
-
20
- width = Math.min(imageWidth, aspectRatio * imageWidth)
21
- height = Math.min(imageHeight, aspectRatio * imageHeight)
22
- if (status !== 'loaded') {
23
- return null
25
+ return Math.min(
26
+ (width - spacing) / imageWidth,
27
+ (height - spacing) / imageHeight
28
+ );
29
+ }, [imageWidth, imageHeight, width, height, spacing]);
30
+ x = x + spacing;
31
+ y = y + spacing;
32
+
33
+ width = Math.min(imageWidth, aspectRatio * imageWidth);
34
+ height = Math.min(imageHeight, aspectRatio * imageHeight);
35
+ if (status !== "loaded") {
36
+ return null;
24
37
  }
25
38
  return (
26
39
  <Image {...rest} x={x} y={y} height={height} width={width} image={image} />
27
40
  );
28
- })
41
+ });
29
42
 
30
- export default ImageComponent
43
+ export default ImageComponent;
package/src/helpers.ts CHANGED
@@ -1063,7 +1063,7 @@ export const AutoSizerCanvas = (defaults: AutoSizerProps = {}) => {
1063
1063
  }
1064
1064
  return { width: Math.ceil(width), height: Math.ceil(height) };
1065
1065
  };
1066
- const measureText = (text: React.ReactText) =>
1066
+ const measureText = (text: string | number) =>
1067
1067
  getWidthOfLongestText(castToString(text));
1068
1068
  const reset = () => setFont(defaults);
1069
1069
  /* Set font in constructor */
@@ -1139,7 +1139,7 @@ export const clampIndex = (
1139
1139
  return index;
1140
1140
  };
1141
1141
 
1142
- type ValueGetter = (cell: CellInterface) => React.ReactText | undefined;
1142
+ type ValueGetter = (cell: CellInterface) => string | number | undefined;
1143
1143
 
1144
1144
  /**
1145
1145
  * Find a cell with content if the current cell is out of the current dataregion
@@ -57,7 +57,7 @@ type SupportedType =
57
57
  | "text/html"
58
58
  | "text/xml";
59
59
 
60
- const defaultGetText = (text: any) => text;
60
+ const defaultGetText = (config: { text: string }) => config.text;
61
61
 
62
62
  /**
63
63
  * Copy paste hook
@@ -134,7 +134,7 @@ const useCopyPaste = ({
134
134
  columnIndex: j,
135
135
  };
136
136
  const config = {
137
- ...selectionRef.current.getValue(coords),
137
+ text: selectionRef.current.getValue(coords),
138
138
  sourceCell: coords,
139
139
  };
140
140
  const value = getText(config);
@@ -53,7 +53,7 @@ export interface UseEditableOptions {
53
53
  * Callback when user submits a value. Use this to update state
54
54
  */
55
55
  onSubmit?: (
56
- value: React.ReactText,
56
+ value: string,
57
57
  activeCell: CellInterface,
58
58
  nextActiveCell?: CellInterface | null
59
59
  ) => void;
@@ -211,7 +211,7 @@ export interface EditorProps {
211
211
  /**
212
212
  * Initial value of the cell
213
213
  */
214
- value?: React.ReactText;
214
+ value?: string | number;
215
215
  /**
216
216
  * Callback when a value has changed.
217
217
  */
@@ -220,7 +220,7 @@ export interface EditorProps {
220
220
  * Callback to submit the value back to data store
221
221
  */
222
222
  onSubmit?: (
223
- value: React.ReactText,
223
+ value: string | number,
224
224
  activeCell: CellInterface,
225
225
  nextActiveCell?: CellInterface | null
226
226
  ) => void;
@@ -324,7 +324,7 @@ const DefaultEditor: React.FC<EditorProps> = (props) => {
324
324
  const inputRef = useRef<HTMLTextAreaElement | null>(null);
325
325
  const { x = 0, y = 0, width = 0, height = 0 } = position;
326
326
  const getWidth = useCallback(
327
- (text) => {
327
+ (text: string | number) => {
328
328
  const textWidth = autoSizerCanvas.measureText(text)?.width || 0;
329
329
  return Math.max(textWidth + padding, width + borderWidth / 2);
330
330
  },
@@ -541,10 +541,8 @@ const useEditable = ({
541
541
  /**
542
542
  * Set max editor ref based on grid container
543
543
  */
544
- const {
545
- containerWidth,
546
- containerHeight,
547
- } = gridRef.current.getDimensions();
544
+ const { containerWidth, containerHeight } =
545
+ gridRef.current.getDimensions();
548
546
  maxEditorDimensionsRef.current = {
549
547
  height: containerHeight - (cellPosition.y ?? 0),
550
548
  width: containerWidth - (cellPosition.x ?? 0),
@@ -784,7 +782,7 @@ const useEditable = ({
784
782
  /* Save the value */
785
783
  const handleSubmit = useCallback(
786
784
  (
787
- value: React.ReactText,
785
+ value: string,
788
786
  activeCell: CellInterface,
789
787
  nextActiveCell?: CellInterface | null
790
788
  ) => {
@@ -834,7 +832,7 @@ const useEditable = ({
834
832
  );
835
833
 
836
834
  const handleChange = useCallback(
837
- (newValue: string, activeCell) => {
835
+ (newValue: string, activeCell: CellInterface) => {
838
836
  /**
839
837
  * Make sure we dont call onChange if initialValue is set
840
838
  * This is to accomodate for editor that fire onChange during initialvalue
@@ -16,13 +16,13 @@ export interface FilterView {
16
16
  }
17
17
 
18
18
  export type Filter = Record<string, FilterDefinition>;
19
- export type FilterDefinition<T = React.ReactText> = {
19
+ export type FilterDefinition<T = string | number> = {
20
20
  condition?: FilterConditionDefinition<T>;
21
21
  equals?: T[];
22
22
  sort?: SortDirection;
23
23
  };
24
24
  export type FilterOperators = ContainsTextOperators | DataValidationOperator;
25
- export type FilterConditionDefinition<T = React.ReactText> = {
25
+ export type FilterConditionDefinition<T = string | number> = {
26
26
  operator?: FilterOperators;
27
27
  values?: T[];
28
28
  };
@@ -150,7 +150,7 @@ const useFilter = ({
150
150
  const isFrozenRow = coords.rowIndex < frozenRows;
151
151
 
152
152
  /* Set cell position */
153
- setPosition((prev) => {
153
+ setPosition(() => {
154
154
  const left = pos.x as number;
155
155
  const top = pos.y as number;
156
156
  const cellWidth = pos.width as number;
@@ -119,7 +119,7 @@ export interface UseSelectionOptions {
119
119
  /**
120
120
  * Value getter
121
121
  */
122
- getValue: (cell: CellInterface) => React.ReactText | undefined;
122
+ getValue: (cell: CellInterface) => string | number | undefined;
123
123
  /**
124
124
  * New selection mode
125
125
  */
@@ -257,9 +257,8 @@ const useSelection = ({
257
257
  const [activeCell, setActiveCell] = useState<CellInterface | null>(
258
258
  initialActiveCell
259
259
  );
260
- const [selections, setSelections] = useState<SelectionArea[]>(
261
- initialSelections
262
- );
260
+ const [selections, setSelections] =
261
+ useState<SelectionArea[]>(initialSelections);
263
262
  const [fillSelection, setFillSelection] = useState<SelectionArea | null>(
264
263
  null
265
264
  );
@@ -543,9 +542,8 @@ const useSelection = ({
543
542
  const cellIndex = cellIndexInSelection(coords, selections);
544
543
  if (cellIndex !== -1) {
545
544
  const newSelection = removeSelectionByIndex(cellIndex);
546
- const nextActiveCell = getPossibleActiveCellFromSelections(
547
- newSelection
548
- );
545
+ const nextActiveCell =
546
+ getPossibleActiveCellFromSelections(newSelection);
549
547
  if (nextActiveCell !== null) {
550
548
  setActiveCell(nextActiveCell);
551
549
  }
@@ -607,8 +605,7 @@ const useSelection = ({
607
605
 
608
606
  const coords = gridRef.current.getCellCoordsFromOffset(
609
607
  e.clientX,
610
- e.clientY,
611
- true
608
+ e.clientY
612
609
  );
613
610
 
614
611
  if (!coords) return;
@@ -909,10 +906,8 @@ const useSelection = ({
909
906
  // Page down
910
907
  const pageDown = () => {
911
908
  if (!activeCell || !gridRef?.current) return;
912
- const {
913
- visibleRowStartIndex,
914
- visibleRowStopIndex,
915
- } = gridRef.current.getViewPort();
909
+ const { visibleRowStartIndex, visibleRowStopIndex } =
910
+ gridRef.current.getViewPort();
916
911
  const pageSize = visibleRowStopIndex - visibleRowStartIndex;
917
912
  const rowIndex = Math.min(activeCell.rowIndex + pageSize, rowCount - 1);
918
913
  const newActiveCell = {
@@ -927,10 +922,8 @@ const useSelection = ({
927
922
  // Page up
928
923
  const pageUp = () => {
929
924
  if (!activeCell || !gridRef?.current) return;
930
- const {
931
- visibleRowStartIndex,
932
- visibleRowStopIndex,
933
- } = gridRef.current.getViewPort();
925
+ const { visibleRowStartIndex, visibleRowStopIndex } =
926
+ gridRef.current.getViewPort();
934
927
  const pageSize = visibleRowStopIndex - visibleRowStartIndex;
935
928
  const rowIndex = Math.max(
936
929
  activeCell.rowIndex - pageSize,
@@ -948,10 +941,8 @@ const useSelection = ({
948
941
  // Page right
949
942
  const pageRight = () => {
950
943
  if (!activeCell || !gridRef?.current) return;
951
- const {
952
- visibleColumnStartIndex,
953
- visibleColumnStopIndex,
954
- } = gridRef.current.getViewPort();
944
+ const { visibleColumnStartIndex, visibleColumnStopIndex } =
945
+ gridRef.current.getViewPort();
955
946
  const pageSize = visibleColumnStopIndex - visibleColumnStartIndex;
956
947
  const columnIndex = Math.min(
957
948
  activeCell.columnIndex + pageSize,
@@ -969,10 +960,8 @@ const useSelection = ({
969
960
  // Page left
970
961
  const pageLeft = () => {
971
962
  if (!activeCell || !gridRef?.current) return;
972
- const {
973
- visibleColumnStartIndex,
974
- visibleColumnStopIndex,
975
- } = gridRef.current.getViewPort();
963
+ const { visibleColumnStartIndex, visibleColumnStopIndex } =
964
+ gridRef.current.getViewPort();
976
965
  const pageSize = visibleColumnStopIndex - visibleColumnStartIndex;
977
966
  const columnIndex = Math.max(
978
967
  activeCell.columnIndex - pageSize,
@@ -1285,7 +1274,8 @@ const useSelection = ({
1285
1274
  }
1286
1275
  let coords = gridRef.current.getCellCoordsFromOffset(
1287
1276
  e.nativeEvent.clientX,
1288
- e.nativeEvent.clientY
1277
+ e.nativeEvent.clientY,
1278
+ false // Todo
1289
1279
  );
1290
1280
  if (!coords) {
1291
1281
  return;
@@ -1329,8 +1319,7 @@ const useSelection = ({
1329
1319
  if (!gridRef?.current) return;
1330
1320
  const coords = gridRef.current.getCellCoordsFromOffset(
1331
1321
  e.clientX,
1332
- e.clientY,
1333
- false
1322
+ e.clientY
1334
1323
  );
1335
1324
  if (!coords) {
1336
1325
  return;
@@ -106,7 +106,7 @@ export interface AutoResizerResults {
106
106
  /**
107
107
  * Text size getter
108
108
  */
109
- getTextMetrics: (text: React.ReactText) => TextDimensions;
109
+ getTextMetrics: (text: string | number) => TextDimensions;
110
110
  }
111
111
 
112
112
  export interface TextDimensions {
@@ -194,7 +194,7 @@ const useAutoSizer = ({
194
194
  autoSizer.current.setFont({ fontFamily, fontSize, fontWeight, fontStyle });
195
195
  }, [fontFamily, fontSize, fontWeight, fontStyle]);
196
196
 
197
- const getTextMetrics = useCallback((text: React.ReactText) => {
197
+ const getTextMetrics = useCallback((text: string | number) => {
198
198
  return autoSizer.current.measureText(castToString(text) as string);
199
199
  }, []);
200
200
 
@@ -149,9 +149,8 @@ const useTooltip = ({
149
149
  }, []);
150
150
 
151
151
  /* Raf throttler */
152
- const mouseMoveThrottler = useRef<
153
- (e: React.MouseEvent<HTMLElement>) => void
154
- >();
152
+ const mouseMoveThrottler =
153
+ useRef<(e: React.MouseEvent<HTMLElement>) => void>();
155
154
  const mouseLeaveThrottler = useRef<() => void>();
156
155
  useEffect(() => {
157
156
  mouseMoveThrottler.current = throttle(handleMouseMove, 100);
@@ -53,12 +53,12 @@ const useTouch = ({ gridRef }: TouchProps): TouchResults => {
53
53
 
54
54
  const dims = gridRef.current?.getDimensions();
55
55
  /* Update dimensions */
56
- updateScrollDimensions(dims);
56
+ if (dims) updateScrollDimensions(dims);
57
57
  }
58
58
  }, []);
59
59
 
60
60
  /* Scroll to x, y coordinate */
61
- const scrollTo = useCallback(({ scrollLeft, scrollTop }) => {
61
+ const scrollTo = useCallback(({ scrollLeft, scrollTop }: ScrollCoords) => {
62
62
  if (scrollerRef.current)
63
63
  scrollerRef.current.scrollTo(scrollLeft, scrollTop);
64
64
  }, []);
@@ -73,6 +73,11 @@ const useTouch = ({ gridRef }: TouchProps): TouchResults => {
73
73
  containerHeight,
74
74
  estimatedTotalWidth,
75
75
  estimatedTotalHeight,
76
+ }: {
77
+ containerWidth: number;
78
+ containerHeight: number;
79
+ estimatedTotalWidth: number;
80
+ estimatedTotalHeight: number;
76
81
  }) => {
77
82
  scrollerRef.current.setDimensions(
78
83
  containerWidth,
@@ -84,9 +89,12 @@ const useTouch = ({ gridRef }: TouchProps): TouchResults => {
84
89
  []
85
90
  );
86
91
 
87
- const handleTouchScroll = useCallback((scrollLeft, scrollTop) => {
88
- gridRef.current?.scrollTo({ scrollTop, scrollLeft });
89
- }, []);
92
+ const handleTouchScroll = useCallback(
93
+ (scrollLeft: number, scrollTop: number) => {
94
+ gridRef.current?.scrollTo({ scrollTop, scrollLeft });
95
+ },
96
+ []
97
+ );
90
98
  const handleTouchStart = useCallback((e: globalThis.TouchEvent) => {
91
99
  scrollerRef.current.doTouchStart(e.touches, e.timeStamp);
92
100
  }, []);
@@ -94,7 +102,7 @@ const useTouch = ({ gridRef }: TouchProps): TouchResults => {
94
102
  e.preventDefault();
95
103
  scrollerRef.current.doTouchMove(e.touches, e.timeStamp);
96
104
  }, []);
97
- const handleTouchEnd = useCallback((e) => {
105
+ const handleTouchEnd = useCallback((e: globalThis.TouchEvent) => {
98
106
  scrollerRef.current.doTouchEnd(e.timeStamp);
99
107
  }, []);
100
108
 
@@ -1,13 +1,12 @@
1
1
  // @ts-nocheck
2
2
  import React from "react";
3
3
  import Grid from "../Grid";
4
+ import "konva/lib/shapes/Rect";
4
5
  import { Rect } from "react-konva";
5
- import { render, fireEvent, screen } from "@testing-library/react";
6
+ import { render } from "@testing-library/react";
6
7
 
7
8
  describe("Grid", () => {
8
9
  let itemRenderer;
9
- let rowCount;
10
- let columnCount;
11
10
  let rowHeight;
12
11
  let columnWidth;
13
12
 
@@ -11,7 +11,7 @@ describe("usePagination", () => {
11
11
  it("throw error if pageSize and total is not provided", () => {
12
12
  const { result } = renderHook(() => usePagination());
13
13
  expect(result.error.message).toBe(
14
- "Cannot read property 'initialCurrentPage' of undefined"
14
+ "Cannot read properties of undefined (reading 'initialCurrentPage')"
15
15
  );
16
16
  });
17
17
 
@@ -1,4 +1,4 @@
1
- import { renderHook, act } from "@testing-library/react-hooks";
1
+ import { renderHook } from "@testing-library/react-hooks";
2
2
  import useSelection from "./../hooks/useSelection";
3
3
 
4
4
  describe("useSelection", () => {
@@ -7,6 +7,7 @@ describe("useSelection", () => {
7
7
  });
8
8
 
9
9
  it("sets initialselection to be empty", () => {
10
+ // @ts-ignore
10
11
  const { result } = renderHook(() => useSelection({}));
11
12
  expect(result.current.selections).toStrictEqual([]);
12
13
  });
@@ -16,6 +17,7 @@ describe("useSelection", () => {
16
17
  { bounds: { top: 0, left: 0, right: 0, bottom: 0 } },
17
18
  ];
18
19
  const { result } = renderHook(() =>
20
+ // @ts-ignore
19
21
  useSelection({
20
22
  initialSelections,
21
23
  })
package/src/utils.tsx CHANGED
@@ -1,5 +1,5 @@
1
- import React, { useState, useCallback } from "react";
2
- import { ShapeConfig } from "konva/types/Shape";
1
+ import React from "react";
2
+ import { ShapeConfig } from "konva/lib/Shape";
3
3
  import { Line, Rect } from "react-konva";
4
4
  import { SelectionProps } from "./Grid";
5
5
 
package/src/.DS_Store DELETED
Binary file
Binary file