react-frame-component 5.2.2 → 5.2.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -31
- package/lib/Frame.js +18 -6
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
declare module 'react-frame-component'
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
export interface FrameComponentProps
|
|
5
|
-
extends React.IframeHTMLAttributes<HTMLIFrameElement> {
|
|
6
|
-
head?: React.ReactNode | undefined;
|
|
7
|
-
mountTarget?: string | undefined;
|
|
8
|
-
initialContent?: string | undefined;
|
|
9
|
-
contentDidMount?: (() => void) | undefined;
|
|
10
|
-
contentDidUpdate?: (() => void) | undefined;
|
|
11
|
-
children: React.ReactNode;
|
|
12
|
-
ref?: React.Ref<FrameComponent>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default class FrameComponent extends React.Component<
|
|
16
|
-
FrameComponentProps
|
|
17
|
-
> {}
|
|
18
|
-
|
|
19
|
-
export interface FrameContextProps {
|
|
20
|
-
document?: HTMLDocument;
|
|
21
|
-
window?: Window;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const FrameContext: React.Context<FrameContextProps>;
|
|
25
|
-
|
|
26
|
-
export const FrameContextProvider: React.Provider<FrameContextProps>;
|
|
27
|
-
|
|
28
|
-
export const FrameContextConsumer: React.Consumer<FrameContextProps>;
|
|
29
|
-
|
|
30
|
-
export function useFrame(): FrameContextProps;
|
|
31
|
-
}
|
|
1
|
+
declare module 'react-frame-component';
|
package/lib/Frame.js
CHANGED
|
@@ -60,9 +60,17 @@ var Frame = exports.Frame = function (_Component) {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
_this.handleLoad = function () {
|
|
63
|
-
_this.
|
|
63
|
+
clearInterval(_this.loadCheck);
|
|
64
|
+
// Bail update as some browsers will trigger on both DOMContentLoaded & onLoad ala firefox
|
|
65
|
+
if (!_this.state.iframeLoaded) {
|
|
66
|
+
_this.setState({ iframeLoaded: true });
|
|
67
|
+
}
|
|
64
68
|
};
|
|
65
69
|
|
|
70
|
+
_this.loadCheck = setInterval(function loadCheckCallback() {
|
|
71
|
+
this.handleLoad();
|
|
72
|
+
}, 500);
|
|
73
|
+
|
|
66
74
|
_this._isMounted = false;
|
|
67
75
|
_this.nodeRef = _react2.default.createRef();
|
|
68
76
|
_this.state = { iframeLoaded: false };
|
|
@@ -75,10 +83,9 @@ var Frame = exports.Frame = function (_Component) {
|
|
|
75
83
|
this._isMounted = true;
|
|
76
84
|
|
|
77
85
|
var doc = this.getDoc();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.nodeRef.current.addEventListener('load', this.handleLoad);
|
|
86
|
+
|
|
87
|
+
if (doc) {
|
|
88
|
+
this.nodeRef.current.contentWindow.addEventListener('DOMContentLoaded', this.handleLoad);
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
}, {
|
|
@@ -86,7 +93,7 @@ var Frame = exports.Frame = function (_Component) {
|
|
|
86
93
|
value: function componentWillUnmount() {
|
|
87
94
|
this._isMounted = false;
|
|
88
95
|
|
|
89
|
-
this.nodeRef.current.removeEventListener('
|
|
96
|
+
this.nodeRef.current.removeEventListener('DOMContentLoaded', this.handleLoad);
|
|
90
97
|
}
|
|
91
98
|
}, {
|
|
92
99
|
key: 'getDoc',
|
|
@@ -102,6 +109,10 @@ var Frame = exports.Frame = function (_Component) {
|
|
|
102
109
|
}
|
|
103
110
|
return doc.body.children[0];
|
|
104
111
|
}
|
|
112
|
+
|
|
113
|
+
// In certain situations on a cold cache DOMContentLoaded never gets called
|
|
114
|
+
// fallback to an interval to check if that's the case
|
|
115
|
+
|
|
105
116
|
}, {
|
|
106
117
|
key: 'renderFrameContents',
|
|
107
118
|
value: function renderFrameContents() {
|
|
@@ -153,6 +164,7 @@ var Frame = exports.Frame = function (_Component) {
|
|
|
153
164
|
delete props.contentDidMount;
|
|
154
165
|
delete props.contentDidUpdate;
|
|
155
166
|
delete props.forwardedRef;
|
|
167
|
+
|
|
156
168
|
return _react2.default.createElement(
|
|
157
169
|
'iframe',
|
|
158
170
|
_extends({}, props, { ref: this.setRef, onLoad: this.handleLoad }),
|
package/package.json
CHANGED