"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-library/src/list-item/hooks/use-space.js
var use_space_exports = {};
__export(use_space_exports, {
  default: () => useSpace
});
module.exports = __toCommonJS(use_space_exports);
var import_compose = require("@wordpress/compose");
var import_keycodes = require("@wordpress/keycodes");
var import_block_editor = require("@wordpress/block-editor");
var import_data = require("@wordpress/data");
var import_use_indent_list_item = __toESM(require("./use-indent-list-item"));
var import_use_outdent_list_item = __toESM(require("./use-outdent-list-item"));
function useSpace(clientId) {
  const { getSelectionStart, getSelectionEnd, getBlockIndex } = (0, import_data.useSelect)(import_block_editor.store);
  const indentListItem = (0, import_use_indent_list_item.default)(clientId);
  const outdentListItem = (0, import_use_outdent_list_item.default)();
  return (0, import_compose.useRefEffect)(
    (element) => {
      function onKeyDown(event) {
        const { keyCode, shiftKey, altKey, metaKey, ctrlKey } = event;
        if (event.defaultPrevented || keyCode !== import_keycodes.SPACE && keyCode !== import_keycodes.TAB || // Only override when no modifiers are pressed.
        altKey || metaKey || ctrlKey) {
          return;
        }
        const selectionStart = getSelectionStart();
        const selectionEnd = getSelectionEnd();
        if (selectionStart.offset === 0 && selectionEnd.offset === 0) {
          if (shiftKey) {
            if (keyCode === import_keycodes.TAB) {
              if (outdentListItem()) {
                event.preventDefault();
              }
            }
          } else if (getBlockIndex(clientId) !== 0) {
            if (indentListItem()) {
              event.preventDefault();
            }
          }
        }
      }
      element.addEventListener("keydown", onKeyDown);
      return () => {
        element.removeEventListener("keydown", onKeyDown);
      };
    },
    [clientId, indentListItem]
  );
}
//# sourceMappingURL=use-space.js.map
