import { pipe } from "fp-ts-esm/function";
import React, { useEffect, useState } from "react";
import { createRicosFunctionalExtension } from "./create-ricos-extension/index.js";
const isInSelection = (selection) => (position) => position >= selection.$from.pos && position <= selection.$to.pos;
const useIsSelected = (editor, getPos) => {
  const [isSelected, setSelected] = useState(false);
  useEffect(() => {
    const onSelectionUpdate = ({ editor: editor2 }) => pipe(getPos(), isInSelection(editor2.state.selection), setSelected);
    editor.on("selectionUpdate", onSelectionUpdate);
    return () => {
      editor.off("selectionUpdate", onSelectionUpdate);
    };
  }, []);
  return isSelected;
};
const FocusHoc = (Component) => {
  const Focus = (props) => /* @__PURE__ */ React.createElement(Component, { ...props, isFocused: useIsSelected(props.editor, props.getPos) });
  Focus.displayName = "FocusHoc";
  return Focus;
};
const focus = createRicosFunctionalExtension({
  type: "extension",
  groups: [],
  name: "focus",
  createExtensionConfig() {
    return {
      name: this.name,
      priority: 20,
      addNodeHoc: () => ({
        priority: 100,
        nodeTypes: ["*"],
        getNodeHoc: () => FocusHoc
      })
    };
  }
});
export {
  focus
};
//# sourceMappingURL=focus.js.map
