@wordpress/block-library
Version:
Block library for the WordPress editor.
74 lines (70 loc) • 2.35 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = save;
var _clsx = _interopRequireDefault(require("clsx"));
var _blockEditor = require("@wordpress/block-editor");
var _jsxRuntime = require("react/jsx-runtime");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
function save({
attributes
}) {
const {
href,
fileId,
fileName,
textLinkHref,
textLinkTarget,
showDownloadButton,
downloadButtonText,
displayPreview,
previewHeight
} = attributes;
const pdfEmbedLabel = _blockEditor.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 = !_blockEditor.RichText.isEmpty(fileName);
// Only output an `aria-describedby` when the element it's referring to is
// actually rendered.
const describedById = hasFilename ? fileId : undefined;
return href && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
..._blockEditor.useBlockProps.save(),
children: [displayPreview && /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("object", {
className: "wp-block-file__embed",
data: href,
type: "application/pdf",
style: {
width: '100%',
height: `${previewHeight}px`
},
"aria-label": pdfEmbedLabel
})
}), hasFilename && /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
id: describedById,
href: textLinkHref,
target: textLinkTarget,
rel: textLinkTarget ? 'noreferrer noopener' : undefined,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.RichText.Content, {
value: fileName
})
}), showDownloadButton && /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
href: href,
className: (0, _clsx.default)('wp-block-file__button', (0, _blockEditor.__experimentalGetElementClassName)('button')),
download: true,
"aria-describedby": describedById,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.RichText.Content, {
value: downloadButtonText
})
})]
});
}
//# sourceMappingURL=save.js.map
;