UNPKG

2.19 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2import _createClass from "@babel/runtime/helpers/esm/createClass";
3import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
4import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
5import _inherits from "@babel/runtime/helpers/esm/inherits";
6import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
7import { createElement } from "@wordpress/element";
8
9/**
10 * WordPress dependencies
11 */
12import { Component, createRef } from '@wordpress/element';
13import { withGlobalEvents } from '@wordpress/compose';
14/**
15 * Browser dependencies
16 */
17
18var _window = window,
19 FocusEvent = _window.FocusEvent;
20
21var WpEmbedPreview =
22/*#__PURE__*/
23function (_Component) {
24 _inherits(WpEmbedPreview, _Component);
25
26 function WpEmbedPreview() {
27 var _this;
28
29 _classCallCheck(this, WpEmbedPreview);
30
31 _this = _possibleConstructorReturn(this, _getPrototypeOf(WpEmbedPreview).apply(this, arguments));
32 _this.checkFocus = _this.checkFocus.bind(_assertThisInitialized(_assertThisInitialized(_this)));
33 _this.node = createRef();
34 return _this;
35 }
36 /**
37 * Checks whether the wp embed iframe is the activeElement,
38 * if it is dispatch a focus event.
39 */
40
41
42 _createClass(WpEmbedPreview, [{
43 key: "checkFocus",
44 value: function checkFocus() {
45 var _document = document,
46 activeElement = _document.activeElement;
47
48 if (activeElement.tagName !== 'IFRAME' || activeElement.parentNode !== this.node.current) {
49 return;
50 }
51
52 var focusEvent = new FocusEvent('focus', {
53 bubbles: true
54 });
55 activeElement.dispatchEvent(focusEvent);
56 }
57 }, {
58 key: "render",
59 value: function render() {
60 var html = this.props.html;
61 return createElement("div", {
62 ref: this.node,
63 className: "wp-block-embed__wrapper",
64 dangerouslySetInnerHTML: {
65 __html: html
66 }
67 });
68 }
69 }]);
70
71 return WpEmbedPreview;
72}(Component);
73
74export default withGlobalEvents({
75 blur: 'checkFocus'
76})(WpEmbedPreview);
77//# sourceMappingURL=wp-embed-preview.js.map
\No newline at end of file