{"version":3,"file":"embed-preview.cjs","names":["useState","getPhotoHtml","getAuthority","sprintf","__","WpEmbedPreview","SandBox","Placeholder","BlockIcon"],"sources":["../../src/embed/embed-preview.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Placeholder, SandBox } from '@wordpress/components';\nimport { BlockIcon } from '@wordpress/block-editor';\nimport { useState } from '@wordpress/element';\nimport { getAuthority } from '@wordpress/url';\nimport { getPhotoHtml } from './util';\nimport WpEmbedPreview from './wp-embed-preview';\n\nexport default function EmbedPreview( {\n\tpreview,\n\tpreviewable,\n\turl,\n\ttype,\n\tisSelected,\n\tclassName,\n\ticon,\n\tlabel,\n} ) {\n\tconst [ interactive, setInteractive ] = useState( false );\n\n\tif ( ! isSelected && interactive ) {\n\t\t// We only want to change this when the block is not selected, because changing it when\n\t\t// the block becomes selected makes the overlap disappear too early. Hiding the overlay\n\t\t// happens on mouseup when the overlay is clicked.\n\t\tsetInteractive( false );\n\t}\n\n\tconst hideOverlay = () => {\n\t\t// This is called onMouseUp on the overlay. We can't respond to the `isSelected` prop\n\t\t// changing, because that happens on mouse down, and the overlay immediately disappears,\n\t\t// and the mouse event can end up in the preview content. We can't use onClick on\n\t\t// the overlay to hide it either, because then the editor misses the mouseup event, and\n\t\t// thinks we're multi-selecting blocks.\n\t\tsetInteractive( true );\n\t};\n\n\tconst { scripts } = preview;\n\n\tconst html = 'photo' === type ? getPhotoHtml( preview ) : preview.html;\n\tconst embedSourceUrl = getAuthority( url );\n\tconst iframeTitle = sprintf(\n\t\t// translators: %s: host providing embed content e.g: www.youtube.com\n\t\t__( 'Embedded content from %s' ),\n\t\tembedSourceUrl\n\t);\n\tconst sandboxClassnames = clsx(\n\t\ttype,\n\t\tclassName,\n\t\t'wp-block-embed__wrapper'\n\t);\n\n\t// Disabled because the overlay div doesn't actually have a role or functionality\n\t// as far as the user is concerned. We're just catching the first click so that\n\t// the block can be selected without interacting with the embed preview that the overlay covers.\n\t/* eslint-disable jsx-a11y/no-static-element-interactions */\n\tconst embedWrapper =\n\t\t'wp-embed' === type ? (\n\t\t\t<WpEmbedPreview html={ html } />\n\t\t) : (\n\t\t\t<div className=\"wp-block-embed__wrapper\">\n\t\t\t\t<SandBox\n\t\t\t\t\tallowSameOrigin\n\t\t\t\t\thtml={ html }\n\t\t\t\t\tscripts={ scripts }\n\t\t\t\t\ttitle={ iframeTitle }\n\t\t\t\t\ttype={ sandboxClassnames }\n\t\t\t\t\tonFocus={ hideOverlay }\n\t\t\t\t/>\n\t\t\t\t{ ! interactive && (\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"block-library-embed__interactive-overlay\"\n\t\t\t\t\t\tonMouseUp={ hideOverlay }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t);\n\t/* eslint-enable jsx-a11y/no-static-element-interactions */\n\n\treturn (\n\t\t<>\n\t\t\t{ previewable ? (\n\t\t\t\tembedWrapper\n\t\t\t) : (\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } showColors /> }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t>\n\t\t\t\t\t<p className=\"components-placeholder__error\">\n\t\t\t\t\t\t<a href={ url }>{ url }</a>\n\t\t\t\t\t</p>\n\t\t\t\t\t<p className=\"components-placeholder__error\">\n\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t/* translators: %s: host providing embed content e.g: www.youtube.com */\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\"Embedded content from %s can't be previewed in the editor.\"\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tembedSourceUrl\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</Placeholder>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,SAAwB,aAAc,EACrC,SACA,aACA,KACA,MACA,YACA,WACA,MACA,SACG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