"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/hooks/anchor.js
var anchor_exports = {};
__export(anchor_exports, {
  addAttribute: () => addAttribute,
  addSaveProps: () => addSaveProps,
  default: () => anchor_default
});
module.exports = __toCommonJS(anchor_exports);
var import_hooks = require("@wordpress/hooks");
var import_components = require("@wordpress/components");
var import_i18n = require("@wordpress/i18n");
var import_blocks = require("@wordpress/blocks");
var import_components2 = require("../components/index.cjs");
var import_block_editing_mode = require("../components/block-editing-mode/index.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var ANCHOR_REGEX = /[\s#]/g;
function addAttribute(settings) {
  if ("type" in (settings.attributes?.anchor ?? {})) {
    return settings;
  }
  if ((0, import_blocks.hasBlockSupport)(settings, "anchor")) {
    settings.attributes = {
      ...settings.attributes,
      anchor: {
        type: "string"
      }
    };
  }
  return settings;
}
function BlockEditAnchorControlPure({ anchor, setAttributes }) {
  const blockEditingMode = (0, import_block_editing_mode.useBlockEditingMode)();
  if (blockEditingMode !== "default") {
    return null;
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components2.InspectorControls, { group: "advanced", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.TextControl,
    {
      className: "html-anchor-control",
      label: (0, import_i18n.__)("HTML anchor"),
      help: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
        (0, import_i18n.__)(
          "Enter a word or two—without spaces—to make a unique web address just for this block, called an “anchor”. Then, you’ll be able to link directly to this section of your page."
        ),
        " ",
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_components.ExternalLink,
          {
            href: (0, import_i18n.__)(
              "https://wordpress.org/documentation/article/page-jumps/"
            ),
            children: (0, import_i18n.__)("Learn more about anchors")
          }
        )
      ] }),
      value: anchor || "",
      placeholder: null,
      onChange: (nextValue) => {
        nextValue = nextValue.replace(ANCHOR_REGEX, "-");
        setAttributes({
          anchor: nextValue !== "" ? nextValue : void 0
        });
      },
      autoCapitalize: "none",
      autoComplete: "off"
    }
  ) });
}
var anchor_default = {
  addSaveProps,
  edit: BlockEditAnchorControlPure,
  attributeKeys: ["anchor"],
  hasSupport(name) {
    return (0, import_blocks.hasBlockSupport)(name, "anchor");
  }
};
function addSaveProps(extraProps, blockType, attributes) {
  if ((0, import_blocks.hasBlockSupport)(blockType, "anchor")) {
    extraProps.id = attributes.anchor === "" ? null : attributes.anchor;
  }
  return extraProps;
}
(0, import_hooks.addFilter)("blocks.registerBlockType", "core/anchor/attribute", addAttribute);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  addAttribute,
  addSaveProps
});
//# sourceMappingURL=anchor.cjs.map
