@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 4.99 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/embed/embed-preview.js"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getPhotoHtml } from './util';\n\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\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';\n\n/**\n * Internal dependencies\n */\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\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA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