@wordpress/block-library
Version:
Block library for the WordPress editor.
50 lines (49 loc) • 1.28 kB
JavaScript
// packages/block-library/src/html/preview.js
import { useMemo } from "@wordpress/element";
import {
transformStyles,
store as blockEditorStore
} from "@wordpress/block-editor";
import { SandBox } from "@wordpress/components";
import { useSelect } from "@wordpress/data";
import { __ } from "@wordpress/i18n";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var DEFAULT_STYLES = `
html,body,:root {
margin: 0 !important;
padding: 0 !important;
overflow: visible !important;
min-height: auto !important;
}
`;
function HTMLEditPreview({ content, isSelected }) {
const settingStyles = useSelect(
(select) => select(blockEditorStore).getSettings().styles,
[]
);
const styles = useMemo(
() => [
DEFAULT_STYLES,
...transformStyles(
(settingStyles ?? []).filter((style) => style.css)
)
],
[settingStyles]
);
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(
SandBox,
{
html: content,
styles,
title: __("Custom HTML Preview"),
tabIndex: -1
}
),
!isSelected && /* @__PURE__ */ jsx("div", { className: "block-library-html__preview-overlay" })
] });
}
export {
HTMLEditPreview as default
};
//# sourceMappingURL=preview.js.map