@wordpress/block-library
Version:
Block library for the WordPress editor.
42 lines (41 loc) • 1.61 kB
JavaScript
import clsx from "clsx";
import { RichText, __experimentalGetElementClassName, useBlockProps } from "@wordpress/block-editor";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/file/save.jsx
function save({ attributes }) {
const { href, fileId, fileName, textLinkHref, textLinkTarget, showDownloadButton, downloadButtonText, displayPreview, previewHeight } = attributes;
const pdfEmbedLabel = RichText.isEmpty(fileName) ? "PDF embed" : fileName.toString();
const hasFilename = !RichText.isEmpty(fileName);
const describedById = hasFilename ? fileId : void 0;
return href && /* @__PURE__ */ jsxs("div", {
...useBlockProps.save(),
children: [
displayPreview && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("object", {
className: "wp-block-file__embed",
data: href,
type: "application/pdf",
style: {
width: "100%",
height: `${previewHeight}px`
},
"aria-label": pdfEmbedLabel
}) }),
hasFilename && /* @__PURE__ */ jsx("a", {
id: describedById,
href: textLinkHref,
target: textLinkTarget,
rel: textLinkTarget ? "noreferrer noopener" : void 0,
children: /* @__PURE__ */ jsx(RichText.Content, { value: fileName })
}),
showDownloadButton && /* @__PURE__ */ jsx("a", {
href,
className: clsx("wp-block-file__button", __experimentalGetElementClassName("button")),
download: true,
"aria-describedby": describedById,
children: /* @__PURE__ */ jsx(RichText.Content, { value: downloadButtonText })
})
]
});
}
export { save as default };
//# sourceMappingURL=save.mjs.map