import React, { useContext, useEffect, useState } from "react";
import { createContext, useContextSelector } from "./../_shared/use-context-selector.js";
import { EditorContext } from "./editor-context.js";
const SelectionContext = createContext({});
const SelectionContextProvider = ({
  children,
  onSelectorContextValue
}) => {
  const {
    adapter: { tiptapEditor }
  } = useContext(EditorContext);
  const [selection, setSelection] = useState(null);
  useEffect(() => {
    const updateSelection = () => {
      setSelection(tiptapEditor.state.selection);
    };
    tiptapEditor.on("selectionUpdate", updateSelection);
    return () => {
      tiptapEditor.off("selectionUpdate", updateSelection);
    };
  }, []);
  return /* @__PURE__ */ React.createElement(SelectionContext.Provider, { value: React.useMemo(() => ({ selection }), [selection]) }, /* @__PURE__ */ React.createElement(SelectorContextValuePasser, { onSelectorContextValue }), children);
};
const useSelection = () => {
  return useContextSelector(SelectionContext, (id) => id, Object.is);
};
const SelectorContextValuePasser = ({
  onSelectorContextValue
}) => {
  const contextValue = useContext(
    SelectionContext
  );
  onSelectorContextValue(contextValue);
  return null;
};
export {
  SelectionContextProvider,
  useSelection
};
//# sourceMappingURL=selection-context.js.map
