import { Editor, Text } from "slate";
import { Slate } from "@makeswift/controls";
import { getSelection } from "../selectors";
import { filterForSubtreeRoots } from "../BlockPlugin/utils/filterForSubtreeRoots";
import deepEqual from "../../utils/deepEqual";
function getLinksAndTextInSelection(editor) {
  return Array.from(
    Editor.nodes(editor, {
      at: getSelection(editor),
      match: (node) => Slate.isInline(node) && Slate.isLink(node) || Text.isText(node)
    })
  );
}
const getValue = (editor) => {
  const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor));
  const areAllRootsLinks = roots.every(([root]) => Slate.isLink(root) || Text.isText(root));
  if (!areAllRootsLinks)
    return void 0;
  const matchingValues = roots.map(([node]) => node).filter(Slate.isLink);
  const match = matchingValues.reduce(
    (a, b) => deepEqual(a?.link, b?.link) ? b : null,
    matchingValues.at(0) ?? void 0
  );
  return match == null ? match : match.link;
};
export {
  getLinksAndTextInSelection,
  getValue
};
//# sourceMappingURL=getValue.js.map