@alaarab/ogrid-react 2.1.8 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -2278,30 +2278,62 @@ function useCellSelection(params) {
2278
2278
  useEffect(() => {
2279
2279
  const markedCells = /* @__PURE__ */ new Set();
2280
2280
  let cellIndex = null;
2281
- const styleCellInRange = (el, r, c, minR, maxR, minC, maxC, anchor) => {
2281
+ let overlayEl = null;
2282
+ let overlayContainer = null;
2283
+ const styleCellInRange = (el, r, _c, _minR, _maxR, _minC, _maxC, anchor) => {
2282
2284
  if (!el.hasAttribute(DRAG_ATTR)) el.setAttribute(DRAG_ATTR, "");
2283
- const isAnchor = anchor && r === anchor.row && c === anchor.col;
2285
+ const isAnchor = anchor && r === anchor.row && _c === anchor.col;
2284
2286
  if (isAnchor) {
2285
2287
  if (!el.hasAttribute(DRAG_ANCHOR_ATTR)) el.setAttribute(DRAG_ANCHOR_ATTR, "");
2286
2288
  } else {
2287
2289
  if (el.hasAttribute(DRAG_ANCHOR_ATTR)) el.removeAttribute(DRAG_ANCHOR_ATTR);
2288
2290
  }
2289
- const shadows = [];
2290
- if (r === minR) shadows.push("inset 0 2px 0 0 var(--ogrid-selection, #217346)");
2291
- if (r === maxR) shadows.push("inset 0 -2px 0 0 var(--ogrid-selection, #217346)");
2292
- if (c === minC) shadows.push("inset 2px 0 0 0 var(--ogrid-selection, #217346)");
2293
- if (c === maxC) shadows.push("inset -2px 0 0 0 var(--ogrid-selection, #217346)");
2294
- el.style.boxShadow = shadows.length > 0 ? shadows.join(", ") : "";
2295
2291
  markedCells.add(el);
2296
2292
  };
2297
2293
  const unstyleCell = (el) => {
2298
2294
  el.removeAttribute(DRAG_ATTR);
2299
2295
  el.removeAttribute(DRAG_ANCHOR_ATTR);
2300
- el.style.boxShadow = "";
2296
+ };
2297
+ const positionOverlay = (minR, maxR, minC, maxC, colOff) => {
2298
+ const topLeftEl = cellIndex?.get(`${minR},${minC + colOff}`);
2299
+ const bottomRightEl = cellIndex?.get(`${maxR},${maxC + colOff}`);
2300
+ if (!topLeftEl || !bottomRightEl) return;
2301
+ const topLeftTd = topLeftEl.closest("td");
2302
+ const bottomRightTd = bottomRightEl.closest("td");
2303
+ if (!topLeftTd || !bottomRightTd) return;
2304
+ if (!overlayContainer) {
2305
+ overlayContainer = topLeftEl.closest("table")?.parentElement;
2306
+ if (!overlayContainer) return;
2307
+ }
2308
+ if (!overlayEl) {
2309
+ overlayEl = document.createElement("div");
2310
+ overlayEl.style.position = "absolute";
2311
+ overlayEl.style.border = "2px solid var(--ogrid-selection, #217346)";
2312
+ overlayEl.style.pointerEvents = "none";
2313
+ overlayEl.style.zIndex = "4";
2314
+ overlayEl.style.boxSizing = "border-box";
2315
+ overlayContainer.appendChild(overlayEl);
2316
+ }
2317
+ const cRect = overlayContainer.getBoundingClientRect();
2318
+ const tlRect = topLeftTd.getBoundingClientRect();
2319
+ const brRect = bottomRightTd.getBoundingClientRect();
2320
+ overlayEl.style.top = `${Math.round(tlRect.top - cRect.top)}px`;
2321
+ overlayEl.style.left = `${Math.round(tlRect.left - cRect.left)}px`;
2322
+ overlayEl.style.width = `${Math.round(brRect.right - tlRect.left)}px`;
2323
+ overlayEl.style.height = `${Math.round(brRect.bottom - tlRect.top)}px`;
2324
+ overlayEl.style.display = "block";
2325
+ };
2326
+ const hideOverlay = () => {
2327
+ if (overlayEl) overlayEl.style.display = "none";
2328
+ };
2329
+ const removeOverlay = () => {
2330
+ overlayEl?.remove();
2331
+ overlayEl = null;
2332
+ overlayContainer = null;
2301
2333
  };
2302
2334
  const applyDragAttrs = (range) => {
2303
2335
  const wrapper = wrapperRef.current;
2304
- if (!wrapper) return;
2336
+ if (!wrapper || !isDraggingRef.current) return;
2305
2337
  const minR = Math.min(range.startRow, range.endRow);
2306
2338
  const maxR = Math.max(range.startRow, range.endRow);
2307
2339
  const minC = Math.min(range.startCol, range.endCol);
@@ -2331,6 +2363,7 @@ function useCellSelection(params) {
2331
2363
  }
2332
2364
  }
2333
2365
  }
2366
+ positionOverlay(minR, maxR, minC, maxC, colOff);
2334
2367
  };
2335
2368
  applyDragAttrsRef.current = applyDragAttrs;
2336
2369
  const clearDragAttrs = () => {
@@ -2339,6 +2372,7 @@ function useCellSelection(params) {
2339
2372
  }
2340
2373
  markedCells.clear();
2341
2374
  cellIndex = null;
2375
+ hideOverlay();
2342
2376
  };
2343
2377
  const resolveRange = (cx, cy) => {
2344
2378
  if (!dragStartRef.current) return null;
@@ -2478,6 +2512,7 @@ function useCellSelection(params) {
2478
2512
  window.removeEventListener("mouseup", onUp, true);
2479
2513
  if (rafRef.current) cancelAnimationFrame(rafRef.current);
2480
2514
  stopAutoScroll();
2515
+ removeOverlay();
2481
2516
  };
2482
2517
  }, [setActiveCell, colOffsetRef, setSelectionRange, wrapperRef]);
2483
2518
  return {
@@ -3477,7 +3512,7 @@ function useDataGridLayout(params) {
3477
3512
  if (Object.keys(prev).length !== Object.keys(measured).length) return measured;
3478
3513
  return prev;
3479
3514
  });
3480
- }, [visibleCols, containerWidth, columnSizingOverrides, wrapperRef]);
3515
+ }, [visibleCols, columnSizingOverrides, wrapperRef]);
3481
3516
  const columnWidthMap = useMemo(() => {
3482
3517
  const map = {};
3483
3518
  for (const col of visibleCols) {
@@ -6814,7 +6849,8 @@ function MarchingAntsOverlay({
6814
6849
  items,
6815
6850
  visibleColumns,
6816
6851
  columnSizingOverrides,
6817
- columnOrder
6852
+ columnOrder,
6853
+ isDragging
6818
6854
  }) {
6819
6855
  const [selRect, setSelRect] = useState(null);
6820
6856
  const [clipRect, setClipRect] = useState(null);
@@ -6862,7 +6898,7 @@ function MarchingAntsOverlay({
6862
6898
  const selR = selRect ? roundRect(selRect) : null;
6863
6899
  const clipR = clipRect ? roundRect(clipRect) : null;
6864
6900
  return /* @__PURE__ */ jsxs(Fragment, { children: [
6865
- selR && !clipRangeMatchesSel && /* @__PURE__ */ jsx(
6901
+ selR && !isDragging && !clipRangeMatchesSel && /* @__PURE__ */ jsx(
6866
6902
  "svg",
6867
6903
  {
6868
6904
  style: {
@@ -21,5 +21,7 @@ export interface MarchingAntsOverlayProps {
21
21
  }>;
22
22
  /** Column order — triggers re-measurement when columns are reordered */
23
23
  columnOrder: readonly string[] | undefined;
24
+ /** True while the user is drag-selecting — hides the selection SVG (drag overlay handles it) */
25
+ isDragging?: boolean;
24
26
  }
25
- export declare function MarchingAntsOverlay({ containerRef, selectionRange, copyRange, cutRange, colOffset, items, visibleColumns, columnSizingOverrides, columnOrder, }: MarchingAntsOverlayProps): React.ReactElement | null;
27
+ export declare function MarchingAntsOverlay({ containerRef, selectionRange, copyRange, cutRange, colOffset, items, visibleColumns, columnSizingOverrides, columnOrder, isDragging, }: MarchingAntsOverlayProps): React.ReactElement | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-react",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "description": "OGrid React – React hooks, headless components, and utilities for OGrid data grids.",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -39,7 +39,7 @@
39
39
  "node": ">=18"
40
40
  },
41
41
  "dependencies": {
42
- "@alaarab/ogrid-core": "2.1.8",
42
+ "@alaarab/ogrid-core": "2.1.9",
43
43
  "@tanstack/react-virtual": "^3.0.0"
44
44
  },
45
45
  "peerDependencies": {