import { NodePos } from "./../../tiptap/core/index.js";
const findNodeClosestToSelection = (editor, nodeType) => {
  const { selection } = editor.state;
  const startNodePos = new NodePos(selection.$from, editor);
  const startNode = startNodePos.closest(nodeType);
  if (!startNode?.pos) {
    return null;
  }
  const isRangeSelection = selection.$from.pos !== selection.$to.pos;
  if (!isRangeSelection) {
    return startNode;
  }
  const endNodePos = new NodePos(selection.$to, editor);
  const endNode = endNodePos.closest(nodeType);
  if (!endNode?.pos || endNode.pos !== startNode.pos) {
    return null;
  }
  return startNode;
};
export {
  findNodeClosestToSelection
};
//# sourceMappingURL=find-node-closest-to-selection.js.map
