@wordpress/block-library
Version:
Block library for the WordPress editor.
55 lines (54 loc) • 2.13 kB
JavaScript
import clsx from "clsx";
import { __, sprintf } from "@wordpress/i18n";
import { Placeholder, SandBox } from "@wordpress/components";
import { BlockIcon } from "@wordpress/block-editor";
import { useState } from "@wordpress/element";
import { getAuthority } from "@wordpress/url";
import { getPhotoHtml } from "./util.mjs";
import WpEmbedPreview from "./wp-embed-preview.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/embed/embed-preview.jsx
function EmbedPreview({ preview, previewable, url, type, isSelected, className, icon, label }) {
const [interactive, setInteractive] = useState(false);
if (!isSelected && interactive) setInteractive(false);
const hideOverlay = () => {
setInteractive(true);
};
const { scripts } = preview;
const html = "photo" === type ? getPhotoHtml(preview) : preview.html;
const embedSourceUrl = getAuthority(url);
const iframeTitle = sprintf(__("Embedded content from %s"), embedSourceUrl);
const sandboxClassnames = clsx(type, className, "wp-block-embed__wrapper");
return /* @__PURE__ */ jsx(Fragment, { children: previewable ? "wp-embed" === type ? /* @__PURE__ */ jsx(WpEmbedPreview, { html }) : /* @__PURE__ */ jsxs("div", {
className: "wp-block-embed__wrapper",
children: [/* @__PURE__ */ jsx(SandBox, {
allowSameOrigin: true,
html,
scripts,
title: iframeTitle,
type: sandboxClassnames,
onFocus: hideOverlay
}), !interactive && /* @__PURE__ */ jsx("div", {
className: "block-library-embed__interactive-overlay",
onMouseUp: hideOverlay
})]
}) : /* @__PURE__ */ jsxs(Placeholder, {
icon: /* @__PURE__ */ jsx(BlockIcon, {
icon,
showColors: true
}),
label,
children: [/* @__PURE__ */ jsx("p", {
className: "components-placeholder__error",
children: /* @__PURE__ */ jsx("a", {
href: url,
children: url
})
}), /* @__PURE__ */ jsx("p", {
className: "components-placeholder__error",
children: sprintf(__("Embedded content from %s can't be previewed in the editor."), embedSourceUrl)
})]
}) });
}
export { EmbedPreview as default };
//# sourceMappingURL=embed-preview.mjs.map