// packages/rich-text/src/component/event-listeners/index.js
import { useMemo, useRef, useInsertionEffect } from "@wordpress/element";
import { useRefEffect } from "@wordpress/compose";
import copyHandler from "./copy-handler.mjs";
import selectObject from "./select-object.mjs";
import formatBoundaries from "./format-boundaries.mjs";
import deleteHandler from "./delete.mjs";
import inputAndSelection from "./input-and-selection.mjs";
import selectionChangeCompat from "./selection-change-compat.mjs";
import { preventFocusCapture } from "./prevent-focus-capture.mjs";
var allEventListeners = [
  copyHandler,
  selectObject,
  formatBoundaries,
  deleteHandler,
  inputAndSelection,
  selectionChangeCompat,
  preventFocusCapture
];
function useEventListeners(props) {
  const propsRef = useRef(props);
  useInsertionEffect(() => {
    propsRef.current = props;
  });
  const refEffects = useMemo(
    () => allEventListeners.map((refEffect) => refEffect(propsRef)),
    [propsRef]
  );
  return useRefEffect(
    (element) => {
      const cleanups = refEffects.map((effect) => effect(element));
      return () => {
        cleanups.forEach((cleanup) => cleanup());
      };
    },
    [refEffects]
  );
}
export {
  useEventListeners
};
//# sourceMappingURL=index.mjs.map
