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