import { Editor } from "slate";
import { useState, useCallback } from "react";
import { useDesugaredRelativeEntityList, useEntityPersistSuccess } from "@contember/react-binding";
const useBlockElementPathRefs = ({ editor, blockList }) => {
  const [blockElementPathRefs] = useState(() => /* @__PURE__ */ new Map());
  const desugaredBlockList = useDesugaredRelativeEntityList(blockList);
  useEntityPersistSuccess(
    useCallback(
      (getEntity) => {
        for (const ref of blockElementPathRefs.values()) {
          ref.unref();
        }
        blockElementPathRefs.clear();
        const blocks = getEntity().getRelativeEntityList(desugaredBlockList);
        let blockIndex = 0;
        for (const topLevelBlock of blocks) {
          blockElementPathRefs.set(topLevelBlock.id, Editor.pathRef(editor, [blockIndex++], { affinity: "backward" }));
        }
      },
      [blockElementPathRefs, desugaredBlockList, editor]
    )
  );
  return blockElementPathRefs;
};
export {
  useBlockElementPathRefs
};
//# sourceMappingURL=useBlockElementPathRefs.js.map
