grid-cell-selection 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -58,14 +58,21 @@ function App() {
58
58
 
59
59
  ```tsx
60
60
  function App() {
61
- const columns = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"];
62
- const rows = 20;
61
+ const columns = ["A", "B", "C", "D", "E", "F", "G"];
62
+ const rows = 100;
63
63
 
64
64
  const { isCellSelected, handleMouseDown, handleMouseEnter, handleMouseUp, handleTouchMove, handleTouchStart } =
65
- useGridCellSelection();
65
+ useGridCellSelection({
66
+ options: { allowYScrollSelection: true, clearSelectionOnScroll: true, scrollThreshold: 100 },
67
+ });
66
68
 
67
69
  return (
68
- <table onMouseUp={handleMouseUp} onTouchMove={handleTouchMove} style={{ touchAction: "none" }}>
70
+ <table
71
+ onMouseUp={handleMouseUp}
72
+ onTouchMove={handleTouchMove}
73
+ onTouchEnd={handleMouseUp}
74
+ style={{ touchAction: "none" }}
75
+ >
69
76
  <tbody>
70
77
  {Array.from({ length: rows }, (_, row) => (
71
78
  <tr key={row}>
@@ -92,6 +99,13 @@ function App() {
92
99
  }
93
100
  ```
94
101
 
102
+ ```
103
+ Options:
104
+ - allowYScrollSelection: boolean - Whether to allow vertical scrolling selection
105
+ - clearSelectionOnScroll: boolean - Whether to clear the selection when the user scrolls
106
+ - scrollThreshold: number - The number of pixels the user must scroll before the selection is cleared
107
+ ```
108
+
95
109
  ## Cell Selection Behavior
96
110
 
97
111
  ### Single Cell Selection
@@ -1,6 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { CellIdentifier } from "../types";
3
- export declare const useGridCellSelection: (allCells?: CellIdentifier[]) => {
2
+ import { CellIdentifier, SelectionOptions } from "../types";
3
+ export declare const useGridCellSelection: ({ allCells, options, }: {
4
+ allCells?: CellIdentifier[] | undefined;
5
+ options?: SelectionOptions | undefined;
6
+ }) => {
4
7
  selectedCells: Map<string, CellIdentifier>;
5
8
  isCellSelected: (cell: CellIdentifier) => boolean;
6
9
  handleMouseDown: (cell: CellIdentifier, event: import("react").MouseEvent<Element, MouseEvent> | import("react").TouchEvent<Element>) => void;
@@ -1,5 +1,5 @@
1
- import { CellIdentifier } from "../types";
2
- export declare const useMouseDragSelection: (toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void) => {
1
+ import { CellIdentifier, SelectionOptions } from "../types";
2
+ export declare const useMouseDragSelection: (toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void, resetSelection: () => void, options: SelectionOptions) => {
3
3
  handleMouseDown: (cell: CellIdentifier, event: React.MouseEvent | React.TouchEvent) => void;
4
4
  handleMouseEnter: (cell: CellIdentifier, event: React.MouseEvent | React.TouchEvent) => void;
5
5
  handleMouseUp: () => void;
package/dist/index.esm.js CHANGED
@@ -31,27 +31,43 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
31
31
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
32
  };
33
33
 
34
- var useMouseDragSelection = function (toggleCellSelection) {
34
+ var useMouseDragSelection = function (toggleCellSelection, resetSelection, options) {
35
35
  var _a = useState(false), isDragging = _a[0], setIsDragging = _a[1];
36
- var touchMoveTriggeredRef = useRef({});
36
+ var selectionStartScrollY = useRef(null);
37
+ var initialCellRef = useRef(null);
37
38
  var handleTouchStart = function (cell, event) {
38
39
  setIsDragging(true);
40
+ initialCellRef.current = cell;
41
+ selectionStartScrollY.current = window.scrollY;
39
42
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);
40
43
  };
41
44
  var handleMouseEnter = function (cell, event) {
42
45
  if (isDragging) {
46
+ // Check if the user is dragging vertically
47
+ var isDraggingVertically = initialCellRef.current && cell.row !== initialCellRef.current.row;
48
+ // If the user is dragging vertically, prevent the selection
49
+ if (!options.allowYScrollSelection && isDraggingVertically) {
50
+ return;
51
+ }
43
52
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, false);
44
53
  }
45
54
  };
46
55
  var handleMouseDown = function (cell, event) {
47
56
  if (!isDragging) {
48
57
  setIsDragging(true);
58
+ initialCellRef.current = cell;
49
59
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);
50
60
  }
51
61
  };
52
62
  var handleMouseUp = function () {
53
63
  setIsDragging(false);
54
- touchMoveTriggeredRef.current = {};
64
+ if (selectionStartScrollY.current !== null && options.clearSelectionOnScroll) {
65
+ console.log("scrollY", window.scrollY, "selectionStartScrollY", selectionStartScrollY.current);
66
+ if (Math.abs(window.scrollY - selectionStartScrollY.current) > options.scrollThreshold) {
67
+ resetSelection();
68
+ }
69
+ }
70
+ selectionStartScrollY.current = null;
55
71
  };
56
72
  return {
57
73
  handleMouseDown: handleMouseDown,
@@ -64,10 +80,15 @@ var useMouseDragSelection = function (toggleCellSelection) {
64
80
  var getCellKey = function (cell) {
65
81
  return "".concat(cell.row, "-").concat(cell.col);
66
82
  };
67
- var useGridCellSelection = function (allCells) {
68
- var _a = useState({
83
+ var useGridCellSelection = function (_a) {
84
+ var allCells = _a.allCells, _b = _a.options, options = _b === void 0 ? {
85
+ allowYScrollSelection: true,
86
+ clearSelectionOnScroll: false,
87
+ scrollThreshold: 100,
88
+ } : _b;
89
+ var _c = useState({
69
90
  selectedCells: new Map(),
70
- }), selectionState = _a[0], setSelectionState = _a[1];
91
+ }), selectionState = _c[0], setSelectionState = _c[1];
71
92
  var toggleCellSelection = function (cell, ctrlKey, shiftKey, newSelection) {
72
93
  if (ctrlKey === void 0) { ctrlKey = false; }
73
94
  if (shiftKey === void 0) { shiftKey = false; }
@@ -115,7 +136,7 @@ var useGridCellSelection = function (allCells) {
115
136
  }
116
137
  }
117
138
  }, [selectionState.selectedCells]);
118
- var _b = useMouseDragSelection(toggleCellSelection), handleMouseDown = _b.handleMouseDown, handleMouseEnter = _b.handleMouseEnter, handleMouseUp = _b.handleMouseUp, handleTouchStart = _b.handleTouchStart;
139
+ var _d = useMouseDragSelection(toggleCellSelection, resetSelection, options), handleMouseDown = _d.handleMouseDown, handleMouseEnter = _d.handleMouseEnter, handleMouseUp = _d.handleMouseUp, handleTouchStart = _d.handleTouchStart;
119
140
  return {
120
141
  selectedCells: selectionState.selectedCells,
121
142
  isCellSelected: isCellSelected,
@@ -1 +1 @@
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;AA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,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, SelectionOptions } from \"../types\";\n\nexport const useMouseDragSelection = (\n toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void,\n resetSelection: () => void,\n options: SelectionOptions\n) => {\n const [isDragging, setIsDragging] = useState(false);\n\n const selectionStartScrollY = useRef<number | null>(null);\n const initialCellRef = useRef<CellIdentifier | null>(null);\n\n const handleTouchStart = (cell: CellIdentifier, event: React.TouchEvent) => {\n setIsDragging(true);\n initialCellRef.current = cell;\n selectionStartScrollY.current = window.scrollY;\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 // Check if the user is dragging vertically\n const isDraggingVertically = initialCellRef.current && cell.row !== initialCellRef.current.row;\n\n // If the user is dragging vertically, prevent the selection\n if (!options.allowYScrollSelection && isDraggingVertically) {\n return;\n }\n\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 initialCellRef.current = cell;\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);\n }\n };\n\n const handleMouseUp = () => {\n setIsDragging(false);\n if (selectionStartScrollY.current !== null && options.clearSelectionOnScroll) {\n console.log(\"scrollY\", window.scrollY, \"selectionStartScrollY\", selectionStartScrollY.current);\n if (Math.abs(window.scrollY - selectionStartScrollY.current) > options.scrollThreshold) {\n resetSelection();\n }\n }\n selectionStartScrollY.current = null;\n };\n\n return {\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n handleTouchStart,\n };\n};\n","import { useCallback, useState } from \"react\";\nimport { CellIdentifier, SelectionOptions, 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 = ({\n allCells,\n options = {\n allowYScrollSelection: true,\n clearSelectionOnScroll: false,\n scrollThreshold: 100,\n },\n}: {\n allCells?: CellIdentifier[];\n options?: SelectionOptions;\n}) => {\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 } = useMouseDragSelection(\n toggleCellSelection,\n resetSelection,\n options\n );\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGa,qBAAqB,GAAG,UACnC,mBAA+G,EAC/G,cAA0B,EAC1B,OAAyB,EAAA;IAEnB,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,qBAAqB,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;AAC1D,IAAA,IAAM,cAAc,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;AAE3D,IAAA,IAAM,gBAAgB,GAAG,UAAC,IAAoB,EAAE,KAAuB,EAAA;QACrE,aAAa,CAAC,IAAI,CAAC,CAAC;AACpB,QAAA,cAAc,CAAC,OAAO,GAAG,IAAI,CAAC;AAC9B,QAAA,qBAAqB,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AAC/C,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;;AAEd,YAAA,IAAM,oBAAoB,GAAG,cAAc,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,KAAK,cAAc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,CAAC;AAClC,KAAA;AACH;;;;"}
package/dist/index.js CHANGED
@@ -35,27 +35,43 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
35
35
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
36
36
  };
37
37
 
38
- var useMouseDragSelection = function (toggleCellSelection) {
38
+ var useMouseDragSelection = function (toggleCellSelection, resetSelection, options) {
39
39
  var _a = react.useState(false), isDragging = _a[0], setIsDragging = _a[1];
40
- var touchMoveTriggeredRef = react.useRef({});
40
+ var selectionStartScrollY = react.useRef(null);
41
+ var initialCellRef = react.useRef(null);
41
42
  var handleTouchStart = function (cell, event) {
42
43
  setIsDragging(true);
44
+ initialCellRef.current = cell;
45
+ selectionStartScrollY.current = window.scrollY;
43
46
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);
44
47
  };
45
48
  var handleMouseEnter = function (cell, event) {
46
49
  if (isDragging) {
50
+ // Check if the user is dragging vertically
51
+ var isDraggingVertically = initialCellRef.current && cell.row !== initialCellRef.current.row;
52
+ // If the user is dragging vertically, prevent the selection
53
+ if (!options.allowYScrollSelection && isDraggingVertically) {
54
+ return;
55
+ }
47
56
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, false);
48
57
  }
49
58
  };
50
59
  var handleMouseDown = function (cell, event) {
51
60
  if (!isDragging) {
52
61
  setIsDragging(true);
62
+ initialCellRef.current = cell;
53
63
  toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);
54
64
  }
55
65
  };
56
66
  var handleMouseUp = function () {
57
67
  setIsDragging(false);
58
- touchMoveTriggeredRef.current = {};
68
+ if (selectionStartScrollY.current !== null && options.clearSelectionOnScroll) {
69
+ console.log("scrollY", window.scrollY, "selectionStartScrollY", selectionStartScrollY.current);
70
+ if (Math.abs(window.scrollY - selectionStartScrollY.current) > options.scrollThreshold) {
71
+ resetSelection();
72
+ }
73
+ }
74
+ selectionStartScrollY.current = null;
59
75
  };
60
76
  return {
61
77
  handleMouseDown: handleMouseDown,
@@ -68,10 +84,15 @@ var useMouseDragSelection = function (toggleCellSelection) {
68
84
  var getCellKey = function (cell) {
69
85
  return "".concat(cell.row, "-").concat(cell.col);
70
86
  };
71
- var useGridCellSelection = function (allCells) {
72
- var _a = react.useState({
87
+ var useGridCellSelection = function (_a) {
88
+ var allCells = _a.allCells, _b = _a.options, options = _b === void 0 ? {
89
+ allowYScrollSelection: true,
90
+ clearSelectionOnScroll: false,
91
+ scrollThreshold: 100,
92
+ } : _b;
93
+ var _c = react.useState({
73
94
  selectedCells: new Map(),
74
- }), selectionState = _a[0], setSelectionState = _a[1];
95
+ }), selectionState = _c[0], setSelectionState = _c[1];
75
96
  var toggleCellSelection = function (cell, ctrlKey, shiftKey, newSelection) {
76
97
  if (ctrlKey === void 0) { ctrlKey = false; }
77
98
  if (shiftKey === void 0) { shiftKey = false; }
@@ -119,7 +140,7 @@ var useGridCellSelection = function (allCells) {
119
140
  }
120
141
  }
121
142
  }, [selectionState.selectedCells]);
122
- var _b = useMouseDragSelection(toggleCellSelection), handleMouseDown = _b.handleMouseDown, handleMouseEnter = _b.handleMouseEnter, handleMouseUp = _b.handleMouseUp, handleTouchStart = _b.handleTouchStart;
143
+ var _d = useMouseDragSelection(toggleCellSelection, resetSelection, options), handleMouseDown = _d.handleMouseDown, handleMouseEnter = _d.handleMouseEnter, handleMouseUp = _d.handleMouseUp, handleTouchStart = _d.handleTouchStart;
123
144
  return {
124
145
  selectedCells: selectionState.selectedCells,
125
146
  isCellSelected: isCellSelected,
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 { 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,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a,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, SelectionOptions } from \"../types\";\n\nexport const useMouseDragSelection = (\n toggleCellSelection: (cell: CellIdentifier, ctrlKey: boolean, shiftKey: boolean, newSelection: boolean) => void,\n resetSelection: () => void,\n options: SelectionOptions\n) => {\n const [isDragging, setIsDragging] = useState(false);\n\n const selectionStartScrollY = useRef<number | null>(null);\n const initialCellRef = useRef<CellIdentifier | null>(null);\n\n const handleTouchStart = (cell: CellIdentifier, event: React.TouchEvent) => {\n setIsDragging(true);\n initialCellRef.current = cell;\n selectionStartScrollY.current = window.scrollY;\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 // Check if the user is dragging vertically\n const isDraggingVertically = initialCellRef.current && cell.row !== initialCellRef.current.row;\n\n // If the user is dragging vertically, prevent the selection\n if (!options.allowYScrollSelection && isDraggingVertically) {\n return;\n }\n\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 initialCellRef.current = cell;\n toggleCellSelection(cell, event.ctrlKey || event.metaKey, event.shiftKey, true);\n }\n };\n\n const handleMouseUp = () => {\n setIsDragging(false);\n if (selectionStartScrollY.current !== null && options.clearSelectionOnScroll) {\n console.log(\"scrollY\", window.scrollY, \"selectionStartScrollY\", selectionStartScrollY.current);\n if (Math.abs(window.scrollY - selectionStartScrollY.current) > options.scrollThreshold) {\n resetSelection();\n }\n }\n selectionStartScrollY.current = null;\n };\n\n return {\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n handleTouchStart,\n };\n};\n","import { useCallback, useState } from \"react\";\nimport { CellIdentifier, SelectionOptions, 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 = ({\n allCells,\n options = {\n allowYScrollSelection: true,\n clearSelectionOnScroll: false,\n scrollThreshold: 100,\n },\n}: {\n allCells?: CellIdentifier[];\n options?: SelectionOptions;\n}) => {\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 } = useMouseDragSelection(\n toggleCellSelection,\n resetSelection,\n options\n );\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGa,qBAAqB,GAAG,UACnC,mBAA+G,EAC/G,cAA0B,EAC1B,OAAyB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G,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;;;;;"}
@@ -3,6 +3,11 @@ export type CellIdentifier = {
3
3
  row: number;
4
4
  col: number;
5
5
  };
6
+ export interface SelectionOptions {
7
+ allowYScrollSelection: boolean;
8
+ clearSelectionOnScroll: boolean;
9
+ scrollThreshold: number;
10
+ }
6
11
  export interface SelectionState {
7
12
  selectedCells: Map<string, CellIdentifier>;
8
13
  startCell?: CellIdentifier;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grid-cell-selection",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "A React hook for grid cell selection",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",