import { useCallback } from "react";
import { Editor, Transforms } from "slate";
import { prepareElementForInsertion } from "../utils/prepareElementForInsertion.js";
const useInsertElementWithReference = ({ editor, createElementReference }) => {
  return useCallback((element, referenceDiscriminant, initialize) => {
    Editor.withoutNormalizing(editor, () => {
      const preppedPath = prepareElementForInsertion(editor, element);
      Transforms.insertNodes(editor, editor.createDefaultElement([{ text: "" }]), { at: preppedPath });
      const referenceId = createElementReference(editor, preppedPath, referenceDiscriminant, initialize).id;
      const newNode = { ...element, referenceId };
      Transforms.setNodes(editor, newNode, { at: preppedPath });
    });
  }, [createElementReference, editor]);
};
export { useInsertElementWithReference };
//# sourceMappingURL=useInsertElementWithReference.js.map
