1 | import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
2 | import _createClass from "@babel/runtime/helpers/esm/createClass";
|
3 | import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
4 | import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
5 | import _inherits from "@babel/runtime/helpers/esm/inherits";
|
6 | import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
7 | import { createElement } from "@wordpress/element";
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | import { Component, createRef } from '@wordpress/element';
|
13 | import { withGlobalEvents } from '@wordpress/compose';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var _window = window,
|
19 | FocusEvent = _window.FocusEvent;
|
20 |
|
21 | var WpEmbedPreview =
|
22 |
|
23 | function (_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 |
|
38 |
|
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 |
|
74 | export default withGlobalEvents({
|
75 | blur: 'checkFocus'
|
76 | })(WpEmbedPreview);
|
77 |
|
\ | No newline at end of file |