grid-cell-selection 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -22,7 +22,7 @@ function App() {
22
22
  const columns = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"];
23
23
  const rows = 20;
24
24
 
25
- const { isCellSelected, handleMouseDown, handleMouseEnter, handleMouseUp } = useGridCellSelection("multiple");
25
+ const { isCellSelected, handleMouseDown, handleMouseEnter, handleMouseUp } = useGridCellSelection();
26
26
 
27
27
  return (
28
28
  <>
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { CellIdentifier } from "../types";
3
3
  export declare const useGridCellSelection: () => {
4
- selectedCells: Set<string>;
4
+ selectedCells: Map<string, CellIdentifier>;
5
5
  isCellSelected: (cell: CellIdentifier) => boolean;
6
6
  handleMouseDown: (cell: CellIdentifier, event: import("react").MouseEvent<Element, MouseEvent>) => void;
7
7
  handleMouseEnter: (cell: CellIdentifier, event: import("react").MouseEvent<Element, MouseEvent>) => void;
package/dist/index.esm.js CHANGED
@@ -57,24 +57,24 @@ var getCellKey = function (cell) {
57
57
  };
58
58
  var useGridCellSelection = function () {
59
59
  var _a = useState({
60
- selectedCells: new Set(),
60
+ selectedCells: new Map(),
61
61
  }), selectionState = _a[0], setSelectionState = _a[1];
62
62
  var toggleCellSelection = function (cell, ctrlKey, shiftKey, newSelection) {
63
63
  if (ctrlKey === void 0) { ctrlKey = false; }
64
64
  if (shiftKey === void 0) { shiftKey = false; }
65
65
  if (newSelection === void 0) { newSelection = false; }
66
66
  setSelectionState(function (prevState) {
67
- var selectedCells = new Set(prevState.selectedCells);
67
+ var selectedCells = new Map(prevState.selectedCells);
68
68
  var cellKey = getCellKey(cell);
69
69
  if (prevState.startCell && !newSelection) {
70
70
  handleRangeSelection(selectedCells, prevState.startCell, cell);
71
71
  }
72
72
  else if ((shiftKey || ctrlKey) && newSelection) {
73
- handleSingleOrMultipleSelection(selectedCells, cellKey);
73
+ handleSingleOrMultipleSelection(selectedCells, cellKey, cell);
74
74
  }
75
75
  else {
76
76
  selectedCells.clear();
77
- selectedCells.add(cellKey);
77
+ selectedCells.set(cellKey, cell);
78
78
  }
79
79
  return __assign(__assign({}, prevState), { selectedCells: selectedCells, startCell: newSelection ? cell : prevState.startCell });
80
80
  });
@@ -91,9 +91,9 @@ var useGridCellSelection = function () {
91
91
  handleMouseUp: handleMouseUp,
92
92
  };
93
93
  };
94
- // New helper functions
94
+ // Updated helper functions
95
95
  function handleRangeSelection(selectedCells, startCell, endCell) {
96
- var action = selectedCells.has(getCellKey(startCell)) ? "add" : "delete";
96
+ var action = selectedCells.has(getCellKey(startCell)) ? "set" : "delete";
97
97
  var _a = [startCell.row, startCell.col], startRow = _a[0], startCol = _a[1];
98
98
  var _b = [endCell.row, endCell.col], endRow = _b[0], endCol = _b[1];
99
99
  var minRow = Math.min(startRow, endRow);
@@ -102,16 +102,22 @@ function handleRangeSelection(selectedCells, startCell, endCell) {
102
102
  var maxCol = Math.max(startCol, endCol);
103
103
  for (var row = minRow; row <= maxRow; row++) {
104
104
  for (var col = minCol; col <= maxCol; col++) {
105
- selectedCells[action](getCellKey({ row: row, col: col }));
105
+ var cellKey = getCellKey({ row: row, col: col });
106
+ if (action === "set") {
107
+ selectedCells.set(cellKey, { row: row, col: col });
108
+ }
109
+ else {
110
+ selectedCells.delete(cellKey);
111
+ }
106
112
  }
107
113
  }
108
114
  }
109
- function handleSingleOrMultipleSelection(selectedCells, cellKey) {
115
+ function handleSingleOrMultipleSelection(selectedCells, cellKey, cell) {
110
116
  if (selectedCells.has(cellKey)) {
111
117
  selectedCells.delete(cellKey);
112
118
  }
113
119
  else {
114
- selectedCells.add(cellKey);
120
+ selectedCells.set(cellKey, cell);
115
121
  }
116
122
  }
117
123
 
@@ -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 = () => {\n const [selectionState, setSelectionState] = useState<SelectionState>({\n selectedCells: new Set(),\n });\n\n const toggleCellSelection = (cell: CellIdentifier, ctrlKey = false, shiftKey = false, newSelection = false) => {\n setSelectionState((prevState) => {\n const selectedCells = new Set(prevState.selectedCells);\n const cellKey = getCellKey(cell);\n\n if (prevState.startCell && !newSelection) {\n handleRangeSelection(selectedCells, prevState.startCell, cell);\n } else if ((shiftKey || ctrlKey) && newSelection) {\n handleSingleOrMultipleSelection(selectedCells, cellKey);\n } else {\n selectedCells.clear();\n selectedCells.add(cellKey);\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 { handleMouseDown, handleMouseEnter, handleMouseUp } = useMouseDragSelection(toggleCellSelection);\n\n return {\n selectedCells: selectionState.selectedCells,\n isCellSelected,\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n };\n};\n\n// New helper functions\nfunction handleRangeSelection(selectedCells: Set<string>, startCell: CellIdentifier, endCell: CellIdentifier) {\n const action = selectedCells.has(getCellKey(startCell)) ? \"add\" : \"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 selectedCells[action](getCellKey({ row, col }));\n }\n }\n}\n\nfunction handleSingleOrMultipleSelection(selectedCells: Set<string>, cellKey: string) {\n if (selectedCells.has(cellKey)) {\n selectedCells.delete(cellKey);\n } else {\n selectedCells.add(cellKey);\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,KAAK,CAAC,CAAC;AAClF,SA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ent":["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 = () => {\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);\n } else if ((shiftKey || ctrlKey) && newSelection) {\n handleSingleOrMultipleSelection(selectedCells, cellKey, cell);\n } else {\n selectedCells.clear();\n selectedCells.set(cellKey, cell);\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 { handleMouseDown, handleMouseEnter, handleMouseUp } = useMouseDragSelection(toggleCellSelection);\n\n return {\n selectedCells: selectionState.selectedCells,\n isCellSelected,\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n };\n};\n\n// Updated helper functions\nfunction handleRangeSelection(\n selectedCells: Map<string, CellIdentifier>,\n startCell: CellIdentifier,\n endCell: 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 selectedCells.set(cellKey, { row, col });\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,EAA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a,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC/B,aAAA;AACF,SAAA;AACF,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;;;;"}
package/dist/index.js CHANGED
@@ -61,24 +61,24 @@ var getCellKey = function (cell) {
61
61
  };
62
62
  var useGridCellSelection = function () {
63
63
  var _a = react.useState({
64
- selectedCells: new Set(),
64
+ selectedCells: new Map(),
65
65
  }), selectionState = _a[0], setSelectionState = _a[1];
66
66
  var toggleCellSelection = function (cell, ctrlKey, shiftKey, newSelection) {
67
67
  if (ctrlKey === void 0) { ctrlKey = false; }
68
68
  if (shiftKey === void 0) { shiftKey = false; }
69
69
  if (newSelection === void 0) { newSelection = false; }
70
70
  setSelectionState(function (prevState) {
71
- var selectedCells = new Set(prevState.selectedCells);
71
+ var selectedCells = new Map(prevState.selectedCells);
72
72
  var cellKey = getCellKey(cell);
73
73
  if (prevState.startCell && !newSelection) {
74
74
  handleRangeSelection(selectedCells, prevState.startCell, cell);
75
75
  }
76
76
  else if ((shiftKey || ctrlKey) && newSelection) {
77
- handleSingleOrMultipleSelection(selectedCells, cellKey);
77
+ handleSingleOrMultipleSelection(selectedCells, cellKey, cell);
78
78
  }
79
79
  else {
80
80
  selectedCells.clear();
81
- selectedCells.add(cellKey);
81
+ selectedCells.set(cellKey, cell);
82
82
  }
83
83
  return __assign(__assign({}, prevState), { selectedCells: selectedCells, startCell: newSelection ? cell : prevState.startCell });
84
84
  });
@@ -95,9 +95,9 @@ var useGridCellSelection = function () {
95
95
  handleMouseUp: handleMouseUp,
96
96
  };
97
97
  };
98
- // New helper functions
98
+ // Updated helper functions
99
99
  function handleRangeSelection(selectedCells, startCell, endCell) {
100
- var action = selectedCells.has(getCellKey(startCell)) ? "add" : "delete";
100
+ var action = selectedCells.has(getCellKey(startCell)) ? "set" : "delete";
101
101
  var _a = [startCell.row, startCell.col], startRow = _a[0], startCol = _a[1];
102
102
  var _b = [endCell.row, endCell.col], endRow = _b[0], endCol = _b[1];
103
103
  var minRow = Math.min(startRow, endRow);
@@ -106,16 +106,22 @@ function handleRangeSelection(selectedCells, startCell, endCell) {
106
106
  var maxCol = Math.max(startCol, endCol);
107
107
  for (var row = minRow; row <= maxRow; row++) {
108
108
  for (var col = minCol; col <= maxCol; col++) {
109
- selectedCells[action](getCellKey({ row: row, col: col }));
109
+ var cellKey = getCellKey({ row: row, col: col });
110
+ if (action === "set") {
111
+ selectedCells.set(cellKey, { row: row, col: col });
112
+ }
113
+ else {
114
+ selectedCells.delete(cellKey);
115
+ }
110
116
  }
111
117
  }
112
118
  }
113
- function handleSingleOrMultipleSelection(selectedCells, cellKey) {
119
+ function handleSingleOrMultipleSelection(selectedCells, cellKey, cell) {
114
120
  if (selectedCells.has(cellKey)) {
115
121
  selectedCells.delete(cellKey);
116
122
  }
117
123
  else {
118
- selectedCells.add(cellKey);
124
+ selectedCells.set(cellKey, cell);
119
125
  }
120
126
  }
121
127
 
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 = () => {\n const [selectionState, setSelectionState] = useState<SelectionState>({\n selectedCells: new Set(),\n });\n\n const toggleCellSelection = (cell: CellIdentifier, ctrlKey = false, shiftKey = false, newSelection = false) => {\n setSelectionState((prevState) => {\n const selectedCells = new Set(prevState.selectedCells);\n const cellKey = getCellKey(cell);\n\n if (prevState.startCell && !newSelection) {\n handleRangeSelection(selectedCells, prevState.startCell, cell);\n } else if ((shiftKey || ctrlKey) && newSelection) {\n handleSingleOrMultipleSelection(selectedCells, cellKey);\n } else {\n selectedCells.clear();\n selectedCells.add(cellKey);\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 { handleMouseDown, handleMouseEnter, handleMouseUp } = useMouseDragSelection(toggleCellSelection);\n\n return {\n selectedCells: selectionState.selectedCells,\n isCellSelected,\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n };\n};\n\n// New helper functions\nfunction handleRangeSelection(selectedCells: Set<string>, startCell: CellIdentifier, endCell: CellIdentifier) {\n const action = selectedCells.has(getCellKey(startCell)) ? \"add\" : \"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 selectedCells[action](getCellKey({ row, col }));\n }\n }\n}\n\nfunction handleSingleOrMultipleSelection(selectedCells: Set<string>, cellKey: string) {\n if (selectedCells.has(cellKey)) {\n selectedCells.delete(cellKey);\n } else {\n selectedCells.add(cellKey);\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,CAAC,CAAC;AAClF,SAAA;AACH,KAAC,CAAC;AAEF,IAAA,IAAM,aAAa,GAAG,YAAA;QACpB,aAAa,CAAC,KAAK,CAAC,CAAC;AACvB,KAAC,CAAC;IAEF,OAAO;AACL,QAAA,eAAe,EAAA,eAAA;AACf,QAAA,gBAAgB,EAAA,gBAAA;AAChB,QAAA,aAAa,EAAA,aAAA;KACd,CAAC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C;IAEpD,IAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1C,IAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1C,IAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1C,IAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE1C,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAE;QAC3C,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAE;AAC3C,YAAA,aAAa,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,EAAE,GAAG,EAAA,GAAA,EAAE,GAAG,EAAA,GAAA,EAAE,CAAC,CAAC,CAAC;AACjD,SAAA;AACF,KAAA;AACH,CAAC;AAED,SAAS,+BAA+B,CAAC,aAA0B,EAAE,OAAe,EAAA;AAClF,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,CAAC,CAAC;AAC5B,KAAA;AACH;;;;;"}
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 = () => {\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);\n } else if ((shiftKey || ctrlKey) && newSelection) {\n handleSingleOrMultipleSelection(selectedCells, cellKey, cell);\n } else {\n selectedCells.clear();\n selectedCells.set(cellKey, cell);\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 { handleMouseDown, handleMouseEnter, handleMouseUp } = useMouseDragSelection(toggleCellSelection);\n\n return {\n selectedCells: selectionState.selectedCells,\n isCellSelected,\n handleMouseDown,\n handleMouseEnter,\n handleMouseUp,\n };\n};\n\n// Updated helper functions\nfunction handleRangeSelection(\n selectedCells: Map<string, CellIdentifier>,\n startCell: CellIdentifier,\n endCell: 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 selectedCells.set(cellKey, { row, col });\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,CAAC,CAAC;AAClF,SAAA;AACH,KAAC,CAAC;AAEF,IAAA,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B,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,6 @@ export type CellIdentifier = {
3
3
  col: number;
4
4
  };
5
5
  export interface SelectionState {
6
- selectedCells: Set<string>;
6
+ selectedCells: Map<string, CellIdentifier>;
7
7
  startCell?: CellIdentifier;
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grid-cell-selection",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A React hook for grid cell selection",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",