grid-cell-selection 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -14,6 +14,8 @@ npm install grid-cell-selection
14
14
 
15
15
  ## Usage
16
16
 
17
+ ### Mouse Only
18
+
17
19
  ```tsx
18
20
  import React from "react";
19
21
  import { useGridCellSelection } from "grid-cell-selection";
@@ -32,6 +34,7 @@ function App() {
32
34
  <tr key={row}>
33
35
  {columns.map((column, col) => (
34
36
  <td
37
+ key={`${row}-${col}`}
35
38
  onMouseEnter={(event) => handleMouseEnter({ id: `${row}-${col}`, row, col }, event)}
36
39
  onMouseDown={(event) => handleMouseDown({ id: `${row}-${col}`, row, col }, event)}
37
40
  className={`${isCellSelected({ id: `${row}-${col}`, row, col }) ? "selected" : ""}`}
@@ -49,6 +52,46 @@ function App() {
49
52
  }
50
53
  ```
51
54
 
55
+ ### Mouse + Touch
56
+
57
+ > Note that data-cell-id, data-cell-row, and data-cell-col are required for touch events to work.
58
+
59
+ ```tsx
60
+ function App() {
61
+ const columns = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"];
62
+ const rows = 20;
63
+
64
+ const { isCellSelected, handleMouseDown, handleMouseEnter, handleMouseUp, handleTouchMove, handleTouchStart } =
65
+ useGridCellSelection();
66
+
67
+ return (
68
+ <table onMouseUp={handleMouseUp} onTouchMove={handleTouchMove} style={{ touchAction: "none" }}>
69
+ <tbody>
70
+ {Array.from({ length: rows }, (_, row) => (
71
+ <tr key={row}>
72
+ {columns.map((column, col) => (
73
+ <td
74
+ key={`${row}-${col}`}
75
+ onMouseEnter={(event) => handleMouseEnter({ id: `${row}-${col}`, row, col }, event)}
76
+ onMouseDown={(event) => handleMouseDown({ id: `${row}-${col}`, row, col }, event)}
77
+ onTouchStart={(event) => handleTouchStart({ id: `${row}-${col}`, row, col }, event)}
78
+ className={`${isCellSelected({ id: `${row}-${col}`, row, col }) ? "selected" : ""}`}
79
+ data-cell-id={`${row}-${col}`} // Required for touch events
80
+ data-cell-row={row} // Required for touch events
81
+ data-cell-col={col} // Required for touch events
82
+ >
83
+ {column}
84
+ {row}
85
+ </td>
86
+ ))}
87
+ </tr>
88
+ ))}
89
+ </tbody>
90
+ </table>
91
+ );
92
+ }
93
+ ```
94
+
52
95
  ## Cell Selection Behavior
53
96
 
54
97
  ### Single Cell Selection
@@ -3,8 +3,10 @@ import { CellIdentifier } from "../types";
3
3
  export declare const useGridCellSelection: (allCells?: CellIdentifier[]) => {
4
4
  selectedCells: Map<string, CellIdentifier>;
5
5
  isCellSelected: (cell: CellIdentifier) => boolean;
6
- handleMouseDown: (cell: CellIdentifier, event: import("react").MouseEvent<Element, MouseEvent>) => void;
7
- handleMouseEnter: (cell: CellIdentifier, event: import("react").MouseEvent<Element, MouseEvent>) => void;
6
+ handleMouseDown: (cell: CellIdentifier, event: import("react").MouseEvent<Element, MouseEvent> | import("react").TouchEvent<Element>) => void;
7
+ handleMouseEnter: (cell: CellIdentifier, event: import("react").MouseEvent<Element, MouseEvent> | import("react").TouchEvent<Element>) => void;
8
8
  handleMouseUp: () => void;
9
+ handleTouchMove: (event: React.TouchEvent) => void;
10
+ handleTouchStart: (cell: CellIdentifier, event: import("react").TouchEvent<Element>) => void;
9
11
  resetSelection: () => void;
10
12
  };
@@ -1,6 +1,7 @@
1
1
  import { CellIdentifier } from "../types";
2
2
  export declare const useMouseDragSelection: (toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void) => {
3
- handleMouseDown: (cell: CellIdentifier, event: React.MouseEvent) => void;
4
- handleMouseEnter: (cell: CellIdentifier, event: React.MouseEvent) => void;
3
+ handleMouseDown: (cell: CellIdentifier, event: React.MouseEvent | React.TouchEvent) => void;
4
+ handleMouseEnter: (cell: CellIdentifier, event: React.MouseEvent | React.TouchEvent) => void;
5
5
  handleMouseUp: () => void;
6
+ handleTouchStart: (cell: CellIdentifier, event: React.TouchEvent) => void;
6
7
  };
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useState } from 'react';
1
+ import { useState, useRef, useCallback } from 'react';
2
2
 
3
3
  /******************************************************************************
4
4
  Copyright (c) Microsoft Corporation.
@@ -33,7 +33,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
33
33
 
34
34
  var useMouseDragSelection = function (toggleCellSelection) {
35
35
  var _a = useState(false), isDragging = _a[0], setIsDragging = _a[1];
36
- var handleMouseDown = function (cell, event) {
36
+ var touchMoveTriggeredRef = useRef({});
37
+ var handleTouchStart = function (cell, event) {
37
38
  setIsDragging(true);
38
39
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);
39
40
  };
@@ -42,13 +43,21 @@ var useMouseDragSelection = function (toggleCellSelection) {
42
43
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, false);
43
44
  }
44
45
  };
46
+ var handleMouseDown = function (cell, event) {
47
+ if (!isDragging) {
48
+ setIsDragging(true);
49
+ toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);
50
+ }
51
+ };
45
52
  var handleMouseUp = function () {
46
53
  setIsDragging(false);
54
+ touchMoveTriggeredRef.current = {};
47
55
  };
48
56
  return {
49
57
  handleMouseDown: handleMouseDown,
50
58
  handleMouseEnter: handleMouseEnter,
51
59
  handleMouseUp: handleMouseUp,
60
+ handleTouchStart: handleTouchStart,
52
61
  };
53
62
  };
54
63
 
@@ -90,13 +99,31 @@ var useGridCellSelection = function (allCells) {
90
99
  var resetSelection = function () {
91
100
  setSelectionState({ selectedCells: new Map() });
92
101
  };
93
- var _b = useMouseDragSelection(toggleCellSelection), handleMouseDown = _b.handleMouseDown, handleMouseEnter = _b.handleMouseEnter, handleMouseUp = _b.handleMouseUp;
102
+ var handleTouchMove = useCallback(function (event) {
103
+ // Get the touch point
104
+ console.log("selectedCells", selectionState.selectedCells);
105
+ if (selectionState.selectedCells.size > 0) {
106
+ var touch = event.touches[0];
107
+ var target = document.elementFromPoint(touch.clientX, touch.clientY);
108
+ // Get closest cell
109
+ var closest = target === null || target === void 0 ? void 0 : target.closest("[data-cell-id]");
110
+ var cellId = closest === null || closest === void 0 ? void 0 : closest.getAttribute("data-cell-id");
111
+ var cellRow = closest === null || closest === void 0 ? void 0 : closest.getAttribute("data-cell-row");
112
+ var cellCol = closest === null || closest === void 0 ? void 0 : closest.getAttribute("data-cell-col");
113
+ if (cellId && cellRow && cellCol && !selectionState.selectedCells.has(cellId)) {
114
+ handleMouseEnter({ id: cellId, row: parseInt(cellRow), col: parseInt(cellCol) }, event);
115
+ }
116
+ }
117
+ }, [selectionState.selectedCells]);
118
+ var _b = useMouseDragSelection(toggleCellSelection), handleMouseDown = _b.handleMouseDown, handleMouseEnter = _b.handleMouseEnter, handleMouseUp = _b.handleMouseUp, handleTouchStart = _b.handleTouchStart;
94
119
  return {
95
120
  selectedCells: selectionState.selectedCells,
96
121
  isCellSelected: isCellSelected,
97
122
  handleMouseDown: handleMouseDown,
98
123
  handleMouseEnter: handleMouseEnter,
99
124
  handleMouseUp: handleMouseUp,
125
+ handleTouchMove: handleTouchMove,
126
+ handleTouchStart: handleTouchStart,
100
127
  resetSelection: resetSelection,
101
128
  };
102
129
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/hooks/useMouseDragSelection.ts","../src/hooks/useCellSelection.ts"],"sourcesContent":["import { useState } from \"react\";\nimport { CellIdentifier } from \"../types\";\n\nexport const useMouseDragSelection = (\n toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void\n) => {\n const [isDragging, setIsDragging] = useState(false);\n\n const handleMouseDown = (cell: CellIdentifier, event: React.MouseEvent) => {\n setIsDragging(true);\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);\n };\n\n const handleMouseEnter = (cell: CellIdentifier, event: React.MouseEvent) => {\n if (isDragging) {\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, false);\n }\n };\n\n const handleMouseUp = () => {\n setIsDragging(false);\n };\n\n return {\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n };\n};\n","import { useState } from \"react\";\nimport { CellIdentifier, SelectionState } from \"../types\";\nimport { useMouseDragSelection } from \"./useMouseDragSelection\";\n\nconst getCellKey = (cell: Omit<CellIdentifier, \"id\">): string => {\n return `${cell.row}-${cell.col}`;\n};\n\nexport const useGridCellSelection = (allCells?: CellIdentifier[]) => {\n const [selectionState, setSelectionState] = useState<SelectionState>({\n selectedCells: new Map<string, CellIdentifier>(),\n });\n\n const toggleCellSelection = (cell: CellIdentifier, ctrlKey = false, shiftKey = false, newSelection = false) => {\n setSelectionState((prevState) => {\n const selectedCells = new Map(prevState.selectedCells);\n const cellKey = getCellKey(cell);\n\n if (prevState.startCell && !newSelection) {\n handleRangeSelection(selectedCells, prevState.startCell, cell, allCells);\n } else if ((shiftKey || ctrlKey) && newSelection) {\n handleSingleOrMultipleSelection(selectedCells, cellKey, cell);\n } else {\n if (selectedCells.has(cellKey)) {\n selectedCells.clear();\n } else {\n selectedCells.clear();\n selectedCells.set(cellKey, cell);\n }\n }\n\n return {\n ...prevState,\n selectedCells,\n startCell: newSelection ? cell : prevState.startCell,\n };\n });\n };\n\n const isCellSelected = (cell: CellIdentifier) => {\n return selectionState.selectedCells.has(getCellKey(cell));\n };\n\n const resetSelection = () => {\n setSelectionState({ selectedCells: new Map<string, CellIdentifier>() });\n };\n\n const { handleMouseDown, handleMouseEnter, handleMouseUp } = useMouseDragSelection(toggleCellSelection);\n\n return {\n selectedCells: selectionState.selectedCells,\n isCellSelected,\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n resetSelection,\n };\n};\n\n// Updated helper functions\nfunction handleRangeSelection(\n selectedCells: Map<string, CellIdentifier>,\n startCell: CellIdentifier,\n endCell: CellIdentifier,\n allCells?: CellIdentifier[]\n) {\n const action = selectedCells.has(getCellKey(startCell)) ? \"set\" : \"delete\";\n const [startRow, startCol] = [startCell.row, startCell.col];\n const [endRow, endCol] = [endCell.row, endCell.col];\n\n const minRow = Math.min(startRow, endRow);\n const maxRow = Math.max(startRow, endRow);\n const minCol = Math.min(startCol, endCol);\n const maxCol = Math.max(startCol, endCol);\n\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n const cellKey = getCellKey({ row, col });\n if (action === \"set\") {\n if (allCells) {\n const cell = allCells.find((c) => c.row === row && c.col === col);\n cell && selectedCells.set(cellKey, cell);\n } else {\n selectedCells.set(cellKey, { id: cellKey, row, col });\n }\n } else {\n selectedCells.delete(cellKey);\n }\n }\n }\n}\n\nfunction handleSingleOrMultipleSelection(\n selectedCells: Map<string, CellIdentifier>,\n cellKey: string,\n cell: CellIdentifier\n) {\n if (selectedCells.has(cellKey)) {\n selectedCells.delete(cellKey);\n } else {\n selectedCells.set(cellKey, cell);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,qBAAqB,GAAG,UACnC,mBAA+G,EAAA;IAEzG,IAAA,EAAA,GAA8B,QAAQ,CAAC,KAAK,CAAC,EAA5C,UAAU,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,aAAa,GAAA,EAAA,CAAA,CAAA,CAAmB,CAAC;AAEpD,IAAA,IAAM,eAAe,GAAG,UAAC,IAAoB,EAAE,KAAuB,EAAA;QACpE,aAAa,CAAC,IAAI,CAAC,CAAC;AACpB,QAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAClF,KAAC,CAAC;AAEF,IAAA,IAAM,gBAAgB,GAAG,UAAC,IAAoB,EAAE,KAAuB,EAAA;AACrE,QAAA,IAAI,UAAU,EAAE;AACd,YAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KA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AAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAA,EAAA,CAAC,CAAC;oBAClE,IAAI,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1C,iBAAA;AAAM,qBAAA;AACL,oBAAA,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAA,GAAA,EAAE,GAAG,EAAA,GAAA,EAAE,CAAC,CAAC;AACvD,iBAAA;AACF,aAAA;AAAM,iBAAA;AACL,gBAAA,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC/B,aAAA;;QAXH,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAA;oBAAlC,GAAG,CAAA,CAAA;AAYX,SAAA;;IAbH,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAA;gBAAlC,GAAG,CAAA,CAAA;AAcX,KAAA;AACH,CAAC;AAED,SAAS,+BAA+B,CACtC,aAA0C,EAC1C,OAAe,EACf,IAAoB,EAAA;AAEpB,IAAA,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;AAC9B,QAAA,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC/B,KAAA;AAAM,SAAA;AACL,QAAA,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAClC,KAAA;AACH;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/hooks/useMouseDragSelection.ts","../src/hooks/useCellSelection.ts"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { CellIdentifier } from \"../types\";\n\nexport const useMouseDragSelection = (\n toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void\n) => {\n const [isDragging, setIsDragging] = useState(false);\n const touchMoveTriggeredRef = useRef<Record<string, boolean>>({});\n\n const handleTouchStart = (cell: CellIdentifier, event: React.TouchEvent) => {\n setIsDragging(true);\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);\n };\n\n const handleMouseEnter = (cell: CellIdentifier, event: React.MouseEvent | React.TouchEvent) => {\n if (isDragging) {\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, false);\n }\n };\n\n const handleMouseDown = (cell: CellIdentifier, event: React.MouseEvent | React.TouchEvent) => {\n if (!isDragging) {\n setIsDragging(true);\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);\n }\n };\n\n const handleMouseUp = () => {\n setIsDragging(false);\n touchMoveTriggeredRef.current = {};\n };\n\n return {\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n handleTouchStart,\n };\n};\n","import { useCallback, useState } from \"react\";\nimport { CellIdentifier, SelectionState } from \"../types\";\nimport { useMouseDragSelection } from \"./useMouseDragSelection\";\n\nconst getCellKey = (cell: Omit<CellIdentifier, \"id\">): string => {\n return `${cell.row}-${cell.col}`;\n};\n\nexport const useGridCellSelection = (allCells?: CellIdentifier[]) => {\n const [selectionState, setSelectionState] = useState<SelectionState>({\n selectedCells: new Map<string, CellIdentifier>(),\n });\n\n const toggleCellSelection = (cell: CellIdentifier, ctrlKey = false, shiftKey = false, newSelection = false) => {\n setSelectionState((prevState) => {\n const selectedCells = new Map(prevState.selectedCells);\n const cellKey = getCellKey(cell);\n\n if (prevState.startCell && !newSelection) {\n handleRangeSelection(selectedCells, prevState.startCell, cell, allCells);\n } else if ((shiftKey || ctrlKey) && newSelection) {\n handleSingleOrMultipleSelection(selectedCells, cellKey, cell);\n } else {\n if (selectedCells.has(cellKey)) {\n selectedCells.clear();\n } else {\n selectedCells.clear();\n selectedCells.set(cellKey, cell);\n }\n }\n\n return {\n ...prevState,\n selectedCells,\n startCell: newSelection ? cell : prevState.startCell,\n };\n });\n };\n\n const isCellSelected = (cell: CellIdentifier) => {\n return selectionState.selectedCells.has(getCellKey(cell));\n };\n\n const resetSelection = () => {\n setSelectionState({ selectedCells: new Map<string, CellIdentifier>() });\n };\n\n const handleTouchMove = useCallback(\n (event: React.TouchEvent) => {\n // Get the touch point\n console.log(\"selectedCells\", selectionState.selectedCells);\n if (selectionState.selectedCells.size > 0) {\n const touch = event.touches[0];\n const target = document.elementFromPoint(touch.clientX, touch.clientY);\n // Get closest cell\n const closest = target?.closest(\"[data-cell-id]\");\n const cellId = closest?.getAttribute(\"data-cell-id\");\n const cellRow = closest?.getAttribute(\"data-cell-row\");\n const cellCol = closest?.getAttribute(\"data-cell-col\");\n if (cellId && cellRow && cellCol && !selectionState.selectedCells.has(cellId)) {\n handleMouseEnter({ id: cellId, row: parseInt(cellRow), col: parseInt(cellCol) }, event);\n }\n }\n },\n [selectionState.selectedCells]\n );\n\n const { handleMouseDown, handleMouseEnter, handleMouseUp, handleTouchStart } =\n useMouseDragSelection(toggleCellSelection);\n\n return {\n selectedCells: selectionState.selectedCells,\n isCellSelected,\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n handleTouchMove,\n handleTouchStart,\n resetSelection,\n };\n};\n\n// Updated helper functions\nfunction handleRangeSelection(\n selectedCells: Map<string, CellIdentifier>,\n startCell: CellIdentifier,\n endCell: CellIdentifier,\n allCells?: CellIdentifier[]\n) {\n const action = selectedCells.has(getCellKey(startCell)) ? \"set\" : \"delete\";\n const [startRow, startCol] = [startCell.row, startCell.col];\n const [endRow, endCol] = [endCell.row, endCell.col];\n\n const minRow = Math.min(startRow, endRow);\n const maxRow = Math.max(startRow, endRow);\n const minCol = Math.min(startCol, endCol);\n const maxCol = Math.max(startCol, endCol);\n\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n const cellKey = getCellKey({ row, col });\n if (action === \"set\") {\n if (allCells) {\n const cell = allCells.find((c) => c.row === row && c.col === col);\n cell && selectedCells.set(cellKey, cell);\n } else {\n selectedCells.set(cellKey, { id: cellKey, row, col });\n }\n } else {\n selectedCells.delete(cellKey);\n }\n }\n }\n}\n\nfunction handleSingleOrMultipleSelection(\n selectedCells: Map<string, CellIdentifier>,\n cellKey: string,\n cell: CellIdentifier\n) {\n if (selectedCells.has(cellKey)) {\n selectedCells.delete(cellKey);\n } else {\n selectedCells.set(cellKey, cell);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,qBAAqB,GAAG,UACnC,mBAA+G,EAAA;IAEzG,IAAA,EAAA,GAA8B,QAAQ,CAAC,KAAK,CAAC,EAA5C,UAAU,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,aAAa,GAAA,EAAA,CAAA,CAAA,CAAmB,CAAC;AACpD,IAAA,IAAM,qBAAqB,GAAG,MAAM,CAA0B,EAAE,CAAC,CAAC;AAElE,IAAA,IAAM,gBAAgB,GAAG,UAAC,IAAoB,EAAE,KAAuB,EAAA;QACrE,aAAa,CAAC,IAAI,CAAC,CAAC;AACpB,QAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAClF,KAAC,CAAC;AAEF,IAAA,IAAM,gBAAgB,GAAG,UAAC,IAAoB,EAAE,KAA0C,EAAA;AACxF,QAAA,IAAI,UAAU,EAAE;AACd,YAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAClF,SAAA;AACH,KAAC,CAAC;AAEF,IAAA,IAAM,eAAe,GAAG,UAAC,IAAoB,EAAE,KAA0C,EAAA;QACvF,IAAI,CAAC,UAAU,EAAE;YACf,aAAa,CAAC,IAAI,CAAC,CAAC;AACpB,YAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAA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,EAAE,IAAI,CAAC,CAAC;AAClC,KAAA;AACH;;;;"}
package/dist/index.js CHANGED
@@ -37,7 +37,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
37
37
 
38
38
  var useMouseDragSelection = function (toggleCellSelection) {
39
39
  var _a = react.useState(false), isDragging = _a[0], setIsDragging = _a[1];
40
- var handleMouseDown = function (cell, event) {
40
+ var touchMoveTriggeredRef = react.useRef({});
41
+ var handleTouchStart = function (cell, event) {
41
42
  setIsDragging(true);
42
43
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);
43
44
  };
@@ -46,13 +47,21 @@ var useMouseDragSelection = function (toggleCellSelection) {
46
47
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, false);
47
48
  }
48
49
  };
50
+ var handleMouseDown = function (cell, event) {
51
+ if (!isDragging) {
52
+ setIsDragging(true);
53
+ toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);
54
+ }
55
+ };
49
56
  var handleMouseUp = function () {
50
57
  setIsDragging(false);
58
+ touchMoveTriggeredRef.current = {};
51
59
  };
52
60
  return {
53
61
  handleMouseDown: handleMouseDown,
54
62
  handleMouseEnter: handleMouseEnter,
55
63
  handleMouseUp: handleMouseUp,
64
+ handleTouchStart: handleTouchStart,
56
65
  };
57
66
  };
58
67
 
@@ -94,13 +103,31 @@ var useGridCellSelection = function (allCells) {
94
103
  var resetSelection = function () {
95
104
  setSelectionState({ selectedCells: new Map() });
96
105
  };
97
- var _b = useMouseDragSelection(toggleCellSelection), handleMouseDown = _b.handleMouseDown, handleMouseEnter = _b.handleMouseEnter, handleMouseUp = _b.handleMouseUp;
106
+ var handleTouchMove = react.useCallback(function (event) {
107
+ // Get the touch point
108
+ console.log("selectedCells", selectionState.selectedCells);
109
+ if (selectionState.selectedCells.size > 0) {
110
+ var touch = event.touches[0];
111
+ var target = document.elementFromPoint(touch.clientX, touch.clientY);
112
+ // Get closest cell
113
+ var closest = target === null || target === void 0 ? void 0 : target.closest("[data-cell-id]");
114
+ var cellId = closest === null || closest === void 0 ? void 0 : closest.getAttribute("data-cell-id");
115
+ var cellRow = closest === null || closest === void 0 ? void 0 : closest.getAttribute("data-cell-row");
116
+ var cellCol = closest === null || closest === void 0 ? void 0 : closest.getAttribute("data-cell-col");
117
+ if (cellId && cellRow && cellCol && !selectionState.selectedCells.has(cellId)) {
118
+ handleMouseEnter({ id: cellId, row: parseInt(cellRow), col: parseInt(cellCol) }, event);
119
+ }
120
+ }
121
+ }, [selectionState.selectedCells]);
122
+ var _b = useMouseDragSelection(toggleCellSelection), handleMouseDown = _b.handleMouseDown, handleMouseEnter = _b.handleMouseEnter, handleMouseUp = _b.handleMouseUp, handleTouchStart = _b.handleTouchStart;
98
123
  return {
99
124
  selectedCells: selectionState.selectedCells,
100
125
  isCellSelected: isCellSelected,
101
126
  handleMouseDown: handleMouseDown,
102
127
  handleMouseEnter: handleMouseEnter,
103
128
  handleMouseUp: handleMouseUp,
129
+ handleTouchMove: handleTouchMove,
130
+ handleTouchStart: handleTouchStart,
104
131
  resetSelection: resetSelection,
105
132
  };
106
133
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/hooks/useMouseDragSelection.ts","../src/hooks/useCellSelection.ts"],"sourcesContent":["import { useState } from \"react\";\nimport { CellIdentifier } from \"../types\";\n\nexport const useMouseDragSelection = (\n toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void\n) => {\n const [isDragging, setIsDragging] = useState(false);\n\n const handleMouseDown = (cell: CellIdentifier, event: React.MouseEvent) => {\n setIsDragging(true);\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);\n };\n\n const handleMouseEnter = (cell: CellIdentifier, event: React.MouseEvent) => {\n if (isDragging) {\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, false);\n }\n };\n\n const handleMouseUp = () => {\n setIsDragging(false);\n };\n\n return {\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n };\n};\n","import { useState } from \"react\";\nimport { CellIdentifier, SelectionState } from \"../types\";\nimport { useMouseDragSelection } from \"./useMouseDragSelection\";\n\nconst getCellKey = (cell: Omit<CellIdentifier, \"id\">): string => {\n return `${cell.row}-${cell.col}`;\n};\n\nexport const useGridCellSelection = (allCells?: CellIdentifier[]) => {\n const [selectionState, setSelectionState] = useState<SelectionState>({\n selectedCells: new Map<string, CellIdentifier>(),\n });\n\n const toggleCellSelection = (cell: CellIdentifier, ctrlKey = false, shiftKey = false, newSelection = false) => {\n setSelectionState((prevState) => {\n const selectedCells = new Map(prevState.selectedCells);\n const cellKey = getCellKey(cell);\n\n if (prevState.startCell && !newSelection) {\n handleRangeSelection(selectedCells, prevState.startCell, cell, allCells);\n } else if ((shiftKey || ctrlKey) && newSelection) {\n handleSingleOrMultipleSelection(selectedCells, cellKey, cell);\n } else {\n if (selectedCells.has(cellKey)) {\n selectedCells.clear();\n } else {\n selectedCells.clear();\n selectedCells.set(cellKey, cell);\n }\n }\n\n return {\n ...prevState,\n selectedCells,\n startCell: newSelection ? cell : prevState.startCell,\n };\n });\n };\n\n const isCellSelected = (cell: CellIdentifier) => {\n return selectionState.selectedCells.has(getCellKey(cell));\n };\n\n const resetSelection = () => {\n setSelectionState({ selectedCells: new Map<string, CellIdentifier>() });\n };\n\n const { handleMouseDown, handleMouseEnter, handleMouseUp } = useMouseDragSelection(toggleCellSelection);\n\n return {\n selectedCells: selectionState.selectedCells,\n isCellSelected,\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n resetSelection,\n };\n};\n\n// Updated helper functions\nfunction handleRangeSelection(\n selectedCells: Map<string, CellIdentifier>,\n startCell: CellIdentifier,\n endCell: CellIdentifier,\n allCells?: CellIdentifier[]\n) {\n const action = selectedCells.has(getCellKey(startCell)) ? \"set\" : \"delete\";\n const [startRow, startCol] = [startCell.row, startCell.col];\n const [endRow, endCol] = [endCell.row, endCell.col];\n\n const minRow = Math.min(startRow, endRow);\n const maxRow = Math.max(startRow, endRow);\n const minCol = Math.min(startCol, endCol);\n const maxCol = Math.max(startCol, endCol);\n\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n const cellKey = getCellKey({ row, col });\n if (action === \"set\") {\n if (allCells) {\n const cell = allCells.find((c) => c.row === row && c.col === col);\n cell && selectedCells.set(cellKey, cell);\n } else {\n selectedCells.set(cellKey, { id: cellKey, row, col });\n }\n } else {\n selectedCells.delete(cellKey);\n }\n }\n }\n}\n\nfunction handleSingleOrMultipleSelection(\n selectedCells: Map<string, CellIdentifier>,\n cellKey: string,\n cell: CellIdentifier\n) {\n if (selectedCells.has(cellKey)) {\n selectedCells.delete(cellKey);\n } else {\n selectedCells.set(cellKey, cell);\n }\n}\n"],"names":["useState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,qBAAqB,GAAG,UACnC,mBAA+G,EAAA;IAEzG,IAAA,EAAA,GAA8BA,cAAQ,CAAC,KAAK,CAAC,EAA5C,UAAU,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,aAAa,GAAA,EAAA,CAAA,CAAA,CAAmB,CAAC;AAEpD,IAAA,IAAM,eAAe,GAAG,UAAC,IAAoB,EAAE,KAAuB,EAAA;QACpE,aAAa,CAAC,IAAI,CAAC,CAAC;AACpB,QAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAClF,KAAC,CAAC;AAEF,IAAA,IAAM,gBAAgB,GAAG,UAAC,IAAoB,EAAE,KAAuB,EAAA;AACrE,QAAA,IAAI,UAAU,EAAE;AACd,YAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAA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AAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAA,EAAA,CAAC,CAAC;oBAClE,IAAI,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1C,iBAAA;AAAM,qBAAA;AACL,oBAAA,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAA,GAAA,EAAE,GAAG,EAAA,GAAA,EAAE,CAAC,CAAC;AACvD,iBAAA;AACF,aAAA;AAAM,iBAAA;AACL,gBAAA,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC/B,aAAA;;QAXH,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAA;oBAAlC,GAAG,CAAA,CAAA;AAYX,SAAA;;IAbH,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAA;gBAAlC,GAAG,CAAA,CAAA;AAcX,KAAA;AACH,CAAC;AAED,SAAS,+BAA+B,CACtC,aAA0C,EAC1C,OAAe,EACf,IAAoB,EAAA;AAEpB,IAAA,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;AAC9B,QAAA,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC/B,KAAA;AAAM,SAAA;AACL,QAAA,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAClC,KAAA;AACH;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/hooks/useMouseDragSelection.ts","../src/hooks/useCellSelection.ts"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { CellIdentifier } from \"../types\";\n\nexport const useMouseDragSelection = (\n toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void\n) => {\n const [isDragging, setIsDragging] = useState(false);\n const touchMoveTriggeredRef = useRef<Record<string, boolean>>({});\n\n const handleTouchStart = (cell: CellIdentifier, event: React.TouchEvent) => {\n setIsDragging(true);\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);\n };\n\n const handleMouseEnter = (cell: CellIdentifier, event: React.MouseEvent | React.TouchEvent) => {\n if (isDragging) {\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, false);\n }\n };\n\n const handleMouseDown = (cell: CellIdentifier, event: React.MouseEvent | React.TouchEvent) => {\n if (!isDragging) {\n setIsDragging(true);\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);\n }\n };\n\n const handleMouseUp = () => {\n setIsDragging(false);\n touchMoveTriggeredRef.current = {};\n };\n\n return {\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n handleTouchStart,\n };\n};\n","import { useCallback, useState } from \"react\";\nimport { CellIdentifier, SelectionState } from \"../types\";\nimport { useMouseDragSelection } from \"./useMouseDragSelection\";\n\nconst getCellKey = (cell: Omit<CellIdentifier, \"id\">): string => {\n return `${cell.row}-${cell.col}`;\n};\n\nexport const useGridCellSelection = (allCells?: CellIdentifier[]) => {\n const [selectionState, setSelectionState] = useState<SelectionState>({\n selectedCells: new Map<string, CellIdentifier>(),\n });\n\n const toggleCellSelection = (cell: CellIdentifier, ctrlKey = false, shiftKey = false, newSelection = false) => {\n setSelectionState((prevState) => {\n const selectedCells = new Map(prevState.selectedCells);\n const cellKey = getCellKey(cell);\n\n if (prevState.startCell && !newSelection) {\n handleRangeSelection(selectedCells, prevState.startCell, cell, allCells);\n } else if ((shiftKey || ctrlKey) && newSelection) {\n handleSingleOrMultipleSelection(selectedCells, cellKey, cell);\n } else {\n if (selectedCells.has(cellKey)) {\n selectedCells.clear();\n } else {\n selectedCells.clear();\n selectedCells.set(cellKey, cell);\n }\n }\n\n return {\n ...prevState,\n selectedCells,\n startCell: newSelection ? cell : prevState.startCell,\n };\n });\n };\n\n const isCellSelected = (cell: CellIdentifier) => {\n return selectionState.selectedCells.has(getCellKey(cell));\n };\n\n const resetSelection = () => {\n setSelectionState({ selectedCells: new Map<string, CellIdentifier>() });\n };\n\n const handleTouchMove = useCallback(\n (event: React.TouchEvent) => {\n // Get the touch point\n console.log(\"selectedCells\", selectionState.selectedCells);\n if (selectionState.selectedCells.size > 0) {\n const touch = event.touches[0];\n const target = document.elementFromPoint(touch.clientX, touch.clientY);\n // Get closest cell\n const closest = target?.closest(\"[data-cell-id]\");\n const cellId = closest?.getAttribute(\"data-cell-id\");\n const cellRow = closest?.getAttribute(\"data-cell-row\");\n const cellCol = closest?.getAttribute(\"data-cell-col\");\n if (cellId && cellRow && cellCol && !selectionState.selectedCells.has(cellId)) {\n handleMouseEnter({ id: cellId, row: parseInt(cellRow), col: parseInt(cellCol) }, event);\n }\n }\n },\n [selectionState.selectedCells]\n );\n\n const { handleMouseDown, handleMouseEnter, handleMouseUp, handleTouchStart } =\n useMouseDragSelection(toggleCellSelection);\n\n return {\n selectedCells: selectionState.selectedCells,\n isCellSelected,\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n handleTouchMove,\n handleTouchStart,\n resetSelection,\n };\n};\n\n// Updated helper functions\nfunction handleRangeSelection(\n selectedCells: Map<string, CellIdentifier>,\n startCell: CellIdentifier,\n endCell: CellIdentifier,\n allCells?: CellIdentifier[]\n) {\n const action = selectedCells.has(getCellKey(startCell)) ? \"set\" : \"delete\";\n const [startRow, startCol] = [startCell.row, startCell.col];\n const [endRow, endCol] = [endCell.row, endCell.col];\n\n const minRow = Math.min(startRow, endRow);\n const maxRow = Math.max(startRow, endRow);\n const minCol = Math.min(startCol, endCol);\n const maxCol = Math.max(startCol, endCol);\n\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n const cellKey = getCellKey({ row, col });\n if (action === \"set\") {\n if (allCells) {\n const cell = allCells.find((c) => c.row === row && c.col === col);\n cell && selectedCells.set(cellKey, cell);\n } else {\n selectedCells.set(cellKey, { id: cellKey, row, col });\n }\n } else {\n selectedCells.delete(cellKey);\n }\n }\n }\n}\n\nfunction handleSingleOrMultipleSelection(\n selectedCells: Map<string, CellIdentifier>,\n cellKey: string,\n cell: CellIdentifier\n) {\n if (selectedCells.has(cellKey)) {\n selectedCells.delete(cellKey);\n } else {\n selectedCells.set(cellKey, cell);\n }\n}\n"],"names":["useState","useRef","useCallback"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,qBAAqB,GAAG,UACnC,mBAA+G,EAAA;IAEzG,IAAA,EAAA,GAA8BA,cAAQ,CAAC,KAAK,CAAC,EAA5C,UAAU,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,aAAa,GAAA,EAAA,CAAA,CAAA,CAAmB,CAAC;AACpD,IAAA,IAAM,qBAAqB,GAAGC,YAAM,CAA0B,EAAE,CAAC,CAAC;AAElE,IAAA,IAAM,gBAAgB,GAAG,UAAC,IAAoB,EAAE,KAAuB,EAAA;QACrE,aAAa,CAAC,IAAI,CAAC,CAAC;AACpB,QAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAClF,KAAC,CAAC;AAEF,IAAA,IAAM,gBAAgB,GAAG,UAAC,IAAoB,EAAE,KAA0C,EAAA;AACxF,QAAA,IAAI,UAAU,EAAE;AACd,YAAA,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAClF,SAAA;AACH,KAAC,CAAC;AAEF,IAAA,IAAM,eAAe,GAAG,UAAC,IAAoB,EAAE,KAA0C,EAAA;QACvF,IAAI,CAAC,UAAU,EAAE;YACf,aAAa,CAAC,IAAI,CAAC,CAAC;AACpB,YAAA,mBAAmB,CAAC,IAAI,EAAE,KA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GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAClC,KAAA;AACH;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grid-cell-selection",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A React hook for grid cell selection",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",