UNPKG

@wordpress/block-library

Version:
71 lines (70 loc) 1.97 kB
// packages/block-library/src/file/save.js import clsx from "clsx"; import { RichText, useBlockProps, __experimentalGetElementClassName } from "@wordpress/block-editor"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; function save({ attributes }) { const { href, fileId, fileName, textLinkHref, textLinkTarget, showDownloadButton, downloadButtonText, displayPreview, previewHeight } = attributes; const pdfEmbedLabel = RichText.isEmpty(fileName) ? "PDF embed" : ( // To do: use toPlainText, but we need ensure it's RichTextData. See // https://github.com/WordPress/gutenberg/pull/56710. 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.js.map