@wordpress/block-library
Version:
Block library for the WordPress editor.
50 lines (49 loc) • 1.46 kB
JavaScript
import { _x, sprintf } from "@wordpress/i18n";
import { customLink } 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";
// packages/block-library/src/navigation-link/index.js
const { name } = metadata;
const settings = {
icon: customLink,
__experimentalLabel(attributes, { context }) {
if (context === "list-view") return attributes?.label;
if (context === "appender") {
const type = attributes?.type || "link";
return sprintf(_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
};
const init = () => {
addFilter("blocks.registerBlockType", "core/navigation-link", enhanceNavigationLinkVariations);
return initBlock({
name,
metadata,
settings
});
};
export { init, metadata, name, settings };
//# sourceMappingURL=index.mjs.map