UNPKG

8.17 kBSource Map (JSON)View Raw
1{"version":3,"sources":["@wordpress/block-library/src/embed/embed-preview.js"],"names":["HOSTS_NO_PREVIEWS","getPhotoHtml","parse","includes","classnames","__","sprintf","Placeholder","SandBox","RichText","BlockIcon","Component","WpEmbedPreview","EmbedPreview","arguments","hideOverlay","bind","state","interactive","setState","props","preview","url","type","caption","onCaptionChange","isSelected","className","icon","label","scripts","html","parsedHost","host","split","parsedHostBaseUrl","splice","length","join","cannotPreview","iframeTitle","sandboxClassnames","embedWrapper","isEmpty","nextProps"],"mappings":";;;;;;;;AAAA;;;AAGA,SAASA,iBAAT,QAAkC,aAAlC;AACA,SAASC,YAAT,QAA6B,QAA7B;AAEA;;;;AAGA,SAASC,KAAT,QAAsB,KAAtB;AACA,SAASC,QAAT,QAAyB,QAAzB;AACA,OAAOC,UAAP,MAAuB,mBAAvB;AAEA;;;;AAGA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,uBAArC;AACA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,yBAApC;AACA,SAASC,SAAT,QAA0B,oBAA1B;AAEA;;;;AAGA,OAAOC,cAAP,MAA2B,oBAA3B;;IAEMC,Y;;;;;AACL,0BAAc;AAAA;;AAAA;;AACb,uFAAUC,SAAV;AACA,UAAKC,WAAL,GAAmB,MAAKA,WAAL,CAAiBC,IAAjB,uDAAnB;AACA,UAAKC,KAAL,GAAa;AACZC,MAAAA,WAAW,EAAE;AADD,KAAb;AAHa;AAMb;;;;kCAaa;AACb;AACA;AACA;AACA;AACA;AACA,WAAKC,QAAL,CAAe;AAAED,QAAAA,WAAW,EAAE;AAAf,OAAf;AACA;;;6BAEQ;AAAA,wBACqF,KAAKE,KAD1F;AAAA,UACAC,OADA,eACAA,OADA;AAAA,UACSC,GADT,eACSA,GADT;AAAA,UACcC,IADd,eACcA,IADd;AAAA,UACoBC,OADpB,eACoBA,OADpB;AAAA,UAC6BC,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_NO_PREVIEWS } from './constants';\nimport { getPhotoHtml } from './util';\n\n/**\n * External dependencies\n */\nimport { parse } from 'url';\nimport { includes } from 'lodash';\nimport classnames from 'classnames/dedupe';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Placeholder, SandBox } from '@wordpress/components';\nimport { RichText, BlockIcon } from '@wordpress/block-editor';\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport WpEmbedPreview from './wp-embed-preview';\n\nclass EmbedPreview extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\t\tthis.hideOverlay = this.hideOverlay.bind( this );\n\t\tthis.state = {\n\t\t\tinteractive: false,\n\t\t};\n\t}\n\n\tstatic getDerivedStateFromProps( nextProps, state ) {\n\t\tif ( ! nextProps.isSelected && state.interactive ) {\n\t\t\t// We only want to change this when the block is not selected, because changing it when\n\t\t\t// the block becomes selected makes the overlap disappear too early. Hiding the overlay\n\t\t\t// happens on mouseup when the overlay is clicked.\n\t\t\treturn { interactive: false };\n\t\t}\n\n\t\treturn null;\n\t}\n\n\thideOverlay() {\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\tthis.setState( { interactive: true } );\n\t}\n\n\trender() {\n\t\tconst { preview, url, type, caption, onCaptionChange, isSelected, className, icon, label } = this.props;\n\t\tconst { scripts } = preview;\n\t\tconst { interactive } = this.state;\n\n\t\tconst html = 'photo' === type ? getPhotoHtml( preview ) : preview.html;\n\t\tconst parsedHost = parse( url ).host.split( '.' );\n\t\tconst parsedHostBaseUrl = parsedHost.splice( parsedHost.length - 2, parsedHost.length - 1 ).join( '.' );\n\t\tconst cannotPreview = includes( HOSTS_NO_PREVIEWS, parsedHostBaseUrl );\n\t\t// translators: %s: host providing embed content e.g: www.youtube.com\n\t\tconst iframeTitle = sprintf( __( 'Embedded content from %s' ), parsedHostBaseUrl );\n\t\tconst sandboxClassnames = classnames( type, className, 'wp-block-embed__wrapper' );\n\n\t\t// Disabled because the overlay div doesn't actually have a role or functionality\n\t\t// as far as the user is concerned. We're just catching the first click so that\n\t\t// the block can be selected without interacting with the embed preview that the overlay covers.\n\t\t/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */\n\t\t/* eslint-disable jsx-a11y/no-static-element-interactions */\n\t\tconst embedWrapper = 'wp-embed' === type ? (\n\t\t\t<WpEmbedPreview\n\t\t\t\thtml={ html }\n\t\t\t/>\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={ this.hideOverlay }\n\t\t\t\t/>\n\t\t\t\t{ ! interactive && <div\n\t\t\t\t\tclassName=\"block-library-embed__interactive-overlay\"\n\t\t\t\t\tonMouseUp={ this.hideOverlay } /> }\n\t\t\t</div>\n\t\t);\n\t\t/* eslint-enable jsx-a11y/no-static-element-interactions */\n\t\t/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */\n\n\t\treturn (\n\t\t\t<figure className={ classnames( className, 'wp-block-embed', { 'is-type-video': 'video' === type } ) }>\n\t\t\t\t{ ( cannotPreview ) ? (\n\t\t\t\t\t<Placeholder icon={ <BlockIcon icon={ icon } showColors /> } label={ label }>\n\t\t\t\t\t\t<p className=\"components-placeholder__error\"><a href={ url }>{ url }</a></p>\n\t\t\t\t\t\t<p className=\"components-placeholder__error\">\n\t\t\t\t\t\t\t{\n\t\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\tsprintf( __( \"Embedded content from %s can't be previewed in the editor.\" ), parsedHostBaseUrl )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</p>\n\t\t\t\t\t</Placeholder>\n\t\t\t\t) : embedWrapper }\n\t\t\t\t{ ( ! RichText.isEmpty( caption ) || isSelected ) && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\t\tplaceholder={ __( 'Write caption…' ) }\n\t\t\t\t\t\tvalue={ caption }\n\t\t\t\t\t\tonChange={ onCaptionChange }\n\t\t\t\t\t\tinlineToolbar\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</figure>\n\t\t);\n\t}\n}\n\nexport default EmbedPreview;\n"]}
\No newline at end of file