// packages/block-editor/src/components/block-list/use-block-props/use-firefox-draggable-compatibility.js
import { useRefEffect } from "@wordpress/compose";
var nodesByDocument = /* @__PURE__ */ new Map();
function add(doc, node) {
  let set = nodesByDocument.get(doc);
  if (!set) {
    set = /* @__PURE__ */ new Set();
    nodesByDocument.set(doc, set);
    doc.addEventListener("pointerdown", down);
  }
  set.add(node);
}
function remove(doc, node) {
  const set = nodesByDocument.get(doc);
  if (set) {
    set.delete(node);
    restore(node);
    if (set.size === 0) {
      nodesByDocument.delete(doc);
      doc.removeEventListener("pointerdown", down);
    }
  }
}
function restore(node) {
  const prevDraggable = node.getAttribute("data-draggable");
  if (prevDraggable) {
    node.removeAttribute("data-draggable");
    if (prevDraggable === "true" && !node.getAttribute("draggable")) {
      node.setAttribute("draggable", "true");
    }
  }
}
function down(event) {
  const { target } = event;
  const { ownerDocument, isContentEditable, tagName } = target;
  const isInputOrTextArea = ["INPUT", "TEXTAREA"].includes(tagName);
  const nodes = nodesByDocument.get(ownerDocument);
  if (isContentEditable || isInputOrTextArea) {
    for (const node of nodes) {
      if (node.getAttribute("draggable") === "true" && node.contains(target)) {
        node.removeAttribute("draggable");
        node.setAttribute("data-draggable", "true");
      }
    }
  } else {
    for (const node of nodes) {
      restore(node);
    }
  }
}
function useFirefoxDraggableCompatibility() {
  return useRefEffect((node) => {
    add(node.ownerDocument, node);
    return () => {
      remove(node.ownerDocument, node);
    };
  }, []);
}
export {
  useFirefoxDraggableCompatibility
};
//# sourceMappingURL=use-firefox-draggable-compatibility.js.map
