"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/rich-text/event-listeners/index.js
var event_listeners_exports = {};
__export(event_listeners_exports, {
  useEventListeners: () => useEventListeners
});
module.exports = __toCommonJS(event_listeners_exports);
var import_element = require("@wordpress/element");
var import_compose = require("@wordpress/compose");
var import_before_input_rules = __toESM(require("./before-input-rules"));
var import_input_rules = __toESM(require("./input-rules"));
var import_insert_replacement_text = __toESM(require("./insert-replacement-text"));
var import_remove_browser_shortcuts = __toESM(require("./remove-browser-shortcuts"));
var import_shortcuts = __toESM(require("./shortcuts"));
var import_input_events = __toESM(require("./input-events"));
var import_undo_automatic_change = __toESM(require("./undo-automatic-change"));
var import_paste_handler = __toESM(require("./paste-handler"));
var import_delete = __toESM(require("./delete"));
var import_enter = __toESM(require("./enter"));
var import_firefox_compat = __toESM(require("./firefox-compat"));
var allEventListeners = [
  import_before_input_rules.default,
  import_input_rules.default,
  import_insert_replacement_text.default,
  import_remove_browser_shortcuts.default,
  import_shortcuts.default,
  import_input_events.default,
  import_undo_automatic_change.default,
  import_paste_handler.default,
  import_delete.default,
  import_enter.default,
  import_firefox_compat.default
];
function useEventListeners(props) {
  const propsRef = (0, import_element.useRef)(props);
  (0, import_element.useInsertionEffect)(() => {
    propsRef.current = props;
  });
  const refEffects = (0, import_element.useMemo)(
    () => allEventListeners.map((refEffect) => refEffect(propsRef)),
    [propsRef]
  );
  return (0, import_compose.useRefEffect)(
    (element) => {
      if (!props.isSelected) {
        return;
      }
      const cleanups = refEffects.map((effect) => effect(element));
      return () => {
        cleanups.forEach((cleanup) => cleanup());
      };
    },
    [refEffects, props.isSelected]
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useEventListeners
});
//# sourceMappingURL=index.js.map
