@wordpress/components
Version:
UI components for WordPress.
64 lines • 2.84 kB
TypeScript
import type { SandBoxProps } from './types';
/**
* Matches CSS viewport-relative length values such as `100vh`, `50.5vw`,
* and `.5dvh`. Used to strip viewport units from user-supplied HTML inside
* the sandbox iframe, because those units are relative to the iframe's
* own size and would create a measurement feedback loop with the
* resize observer.
*
* Exported for tests. NOTE: an identical regex literal is duplicated
* inside `observeAndResizeJS` below because that function is serialized
* via `.toString()` and embedded into the iframe's `srcdoc` — it has no
* access to this module's scope at runtime. If you change one, change
* the other; the "is embedded in the sandbox iframe srcdoc" test
* guards against drift.
*/
export declare const VIEWPORT_UNIT_VALUE_REGEX: RegExp;
/**
* Builds the full HTML document string for the sandbox iframe content. Shared
* by both the isolated (`srcdoc`) and same-origin (`contentDocument.write`)
* sandboxes so the two paths always emit the same markup — notably keeping the
* resize script in `<head>`, ahead of the user content, on both. A single
* builder means the write path cannot drift back to putting the script in
* `<body>` while the `srcdoc` path keeps it in `<head>`.
*
* `lang` is passed in rather than read here because the two callers source it
* from different documents: the isolated sandbox uses the module's `document`,
* while the same-origin sandbox uses the iframe's `ownerDocument`. They are
* normally the same document, but keeping the argument preserves each path's
* exact prior behavior.
*
* Exported for tests.
*
* @param props
* @param props.html User-supplied HTML for the iframe body.
* @param props.title Document title.
* @param props.type Optional class name for the `<html>`/`<body>` elements.
* @param props.styles CSS rule strings, injected as `<style>` tags in the head.
* @param props.scripts External script URLs, injected as `<script src>` in the
* body (embeds expect their scripts there).
* @param props.lang Language for the `<html lang>` attribute.
* @return The full `<!DOCTYPE html>…` document string.
*/
export declare function buildSandBoxDocument({ html, title, type, styles, scripts, lang, }: {
html: string;
title: string;
type?: string;
styles: string[];
scripts: string[];
lang: string;
}): string;
/**
* This component provides an isolated environment for arbitrary HTML via iframes.
*
* ```jsx
* import { SandBox } from '@wordpress/components';
*
* const MySandBox = () => (
* <SandBox html="<p>Content</p>" title="SandBox" type="embed" />
* );
* ```
*/
declare function SandBox({ allowSameOrigin, ...contentProps }: SandBoxProps): import("react").JSX.Element;
export default SandBox;
//# sourceMappingURL=index.d.ts.map