"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/block-list/use-block-props/use-firefox-draggable-compatibility.js
var use_firefox_draggable_compatibility_exports = {};
__export(use_firefox_draggable_compatibility_exports, {
  useFirefoxDraggableCompatibility: () => useFirefoxDraggableCompatibility
});
module.exports = __toCommonJS(use_firefox_draggable_compatibility_exports);
var import_compose = require("@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 (0, import_compose.useRefEffect)((node) => {
    add(node.ownerDocument, node);
    return () => {
      remove(node.ownerDocument, node);
    };
  }, []);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useFirefoxDraggableCompatibility
});
//# sourceMappingURL=use-firefox-draggable-compatibility.js.map
