@wordpress/block-library
Version:
Block library for the WordPress editor.
63 lines (62 loc) • 1.65 kB
JavaScript
// packages/block-library/src/navigation-link/index.js
import { _x, sprintf } from "@wordpress/i18n";
import { customLink as linkIcon } from "@wordpress/icons";
import { addFilter } from "@wordpress/hooks";
import deprecated from "./deprecated.mjs";
import initBlock from "../utils/init-block.mjs";
import metadata from "./block.json";
import edit from "./edit.mjs";
import save from "./save.mjs";
import { enhanceNavigationLinkVariations } from "./hooks.mjs";
import transforms from "./transforms.mjs";
import variations from "./variations.mjs";
var { name } = metadata;
var settings = {
icon: linkIcon,
__experimentalLabel(attributes, { context }) {
if (context === "list-view") {
return attributes?.label;
}
if (context === "appender") {
const type = attributes?.type || "link";
return sprintf(
/* translators: %s: block type (e.g., 'page', 'post', 'category') */
_x("Add %s", "add default block type"),
type
);
}
return attributes?.label;
},
merge(leftAttributes, { label: rightLabel = "" }) {
return {
...leftAttributes,
label: leftAttributes.label + rightLabel
};
},
edit,
save,
example: {
attributes: {
label: _x("Example Link", "navigation link preview example"),
url: "https://example.com"
}
},
deprecated,
transforms,
variations
};
var init = () => {
addFilter(
"blocks.registerBlockType",
"core/navigation-link",
enhanceNavigationLinkVariations
);
return initBlock({ name, metadata, settings });
};
export {
init,
metadata,
name,
settings
};
//# sourceMappingURL=index.mjs.map