JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr{ gilour

File "update-rects.ts"

Full Path: /home/markqprx/iniasli.pro/client/ui/interactions/dnd/update-rects.ts
File size: 1.11 KB
MIME-type: text/plain
Charset: utf-8

// use intersection observer instead of getBoundingClientRect for better performance as this will be called in onPointerMove event
import {InteractableRect} from '../interactable-event';
import {ConnectedMouseSelectable} from './mouse-selection/use-mouse-selectable';
import {DraggableId} from './use-draggable';
import {ConnectedDroppable} from './use-droppable';

export function updateRects(
  targets: Map<DraggableId, ConnectedDroppable | ConnectedMouseSelectable>
) {
  const observer = new IntersectionObserver(entries => {
    entries.forEach(entry => {
      const {width, height, left, top} = entry.boundingClientRect;
      const [id, target] =
        [...targets].find(
          ([, target]) => target.ref.current === entry.target
        ) || [];
      if (id == null || target == null) return;

      const rect: InteractableRect = {
        width,
        height,
        left,
        top,
      };
      targets.set(id, {...target, rect});
    });
    observer.disconnect();
  });

  [...targets.values()].forEach(target => {
    if (target.ref.current) {
      observer.observe(target.ref.current);
    }
  });
}