@wordpress/block-library
Version:
Block library for the WordPress editor.
113 lines (112 loc) • 2.57 kB
JavaScript
// packages/block-library/src/navigation-link/index.js
import { _x, __ } from "@wordpress/i18n";
import { customLink as linkIcon } from "@wordpress/icons";
import { InnerBlocks } from "@wordpress/block-editor";
import { addFilter } from "@wordpress/hooks";
import { privateApis as blocksPrivateApis } from "@wordpress/blocks";
import initBlock from "../utils/init-block";
import metadata from "./block.json";
import edit from "./edit";
import save from "./save";
import { enhanceNavigationLinkVariations } from "./hooks";
import transforms from "./transforms";
import { unlock } from "../lock-unlock";
import { jsx } from "react/jsx-runtime";
var { fieldsKey, formKey } = unlock(blocksPrivateApis);
var { name } = metadata;
var settings = {
icon: linkIcon,
__experimentalLabel: ({ label }) => 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: [
{
isEligible(attributes) {
return attributes.nofollow;
},
attributes: {
label: {
type: "string"
},
type: {
type: "string"
},
nofollow: {
type: "boolean"
},
description: {
type: "string"
},
id: {
type: "number"
},
opensInNewTab: {
type: "boolean",
default: false
},
url: {
type: "string"
}
},
migrate({ nofollow, ...rest }) {
return {
rel: nofollow ? "nofollow" : "",
...rest
};
},
save() {
return /* @__PURE__ */ jsx(InnerBlocks.Content, {});
}
}
],
transforms
};
if (window.__experimentalContentOnlyInspectorFields) {
settings[fieldsKey] = [
{
id: "label",
label: __("Label"),
type: "richtext"
},
{
id: "link",
label: __("Link"),
type: "link",
mapping: {
href: "url",
rel: "rel"
// TODO - opens in new tab? id?
}
}
];
settings[formKey] = {
fields: ["label"]
};
}
var init = () => {
addFilter(
"blocks.registerBlockType",
"core/navigation-link",
enhanceNavigationLinkVariations
);
return initBlock({ name, metadata, settings });
};
export {
init,
metadata,
name,
settings
};
//# sourceMappingURL=index.js.map