react-iframe-plugin 0.0.20 → 0.1.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/README.md +8 -4
- package/dist/IframePlugin.d.ts +1 -2
- package/dist/IframePlugin.es.js +126 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,16 +16,20 @@ or pnpm i react-iframe-plugin
|
|
|
16
16
|
- import IframePlugin from 'react-iframe-plugin';
|
|
17
17
|
```
|
|
18
18
|
```bash
|
|
19
|
-
- <IframePlugin
|
|
20
|
-
currentDomain="http://localhost:3000" //當前domain
|
|
19
|
+
- <IframePlugin
|
|
21
20
|
iframeDomain="https://xxxxxxxxxxx.com" //加載domain
|
|
22
21
|
src="https://xxxxxxxxxx.com/zh-hant/header" //加載地址
|
|
23
22
|
url="https://xxxxxxxxxx.com" //點擊跳轉地址
|
|
24
23
|
basicHeight="250px" //初始高度
|
|
25
24
|
height="800px" //展開高度
|
|
26
|
-
width="100%" //寬度
|
|
27
25
|
zIndex="999" //層級
|
|
28
|
-
|
|
26
|
+
/>
|
|
27
|
+
﹣ <IframePlugin
|
|
28
|
+
types='footer' //底部
|
|
29
|
+
iframeDomain="http://localhost:8086"
|
|
30
|
+
src="http://localhost:8086/zh-hant/footer"
|
|
31
|
+
url="http://localhost:8086"
|
|
32
|
+
zIndex="999"
|
|
29
33
|
/>
|
|
30
34
|
```
|
|
31
35
|
|
package/dist/IframePlugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from "react";
|
|
2
2
|
interface IframePluginProps {
|
|
3
3
|
src: string;
|
|
4
4
|
title: string;
|
|
@@ -10,7 +10,6 @@ interface IframePluginProps {
|
|
|
10
10
|
basicHeight: string;
|
|
11
11
|
url: string;
|
|
12
12
|
newWindow: boolean;
|
|
13
|
-
footerHeight: string;
|
|
14
13
|
zIndex: string;
|
|
15
14
|
}
|
|
16
15
|
declare const IframePlugin: React.FC<IframePluginProps>;
|
package/dist/IframePlugin.es.js
CHANGED
|
@@ -1,53 +1,132 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
const
|
|
4
|
-
const [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { jsx as l, Fragment as b, jsxs as B } from "react/jsx-runtime";
|
|
2
|
+
import { useState as m, useRef as W, useEffect as E } from "react";
|
|
3
|
+
const T = (S) => {
|
|
4
|
+
const [a, h] = m("250px"), [u, F] = m("250px"), {
|
|
5
|
+
zIndex: f,
|
|
6
|
+
newWindow: c,
|
|
7
|
+
url: s,
|
|
8
|
+
basicHeight: o,
|
|
9
|
+
iframeDomain: n,
|
|
10
|
+
currentDomain: g,
|
|
11
|
+
types: r,
|
|
12
|
+
src: p,
|
|
13
|
+
title: w,
|
|
14
|
+
width: x,
|
|
15
|
+
height: d
|
|
16
|
+
} = S, i = W(!1), [I, D] = m(!1);
|
|
17
|
+
E(() => {
|
|
18
|
+
const t = r == "footer" ? document.getElementById("iframeFooter") : document.getElementById("iframePlugin");
|
|
19
|
+
console.log(
|
|
20
|
+
87878787,
|
|
21
|
+
t.contentWindow,
|
|
22
|
+
g,
|
|
23
|
+
n,
|
|
24
|
+
s,
|
|
25
|
+
d,
|
|
26
|
+
o,
|
|
27
|
+
c
|
|
28
|
+
), t.addEventListener("load", function() {
|
|
29
|
+
console.log("currentDomain────────────", o), h(o || "250px");
|
|
30
|
+
const e = window.location.origin;
|
|
31
|
+
e && t.contentWindow.postMessage(
|
|
32
|
+
{
|
|
33
|
+
currentDomain: e || window.location.origin,
|
|
34
|
+
iframeDomain: n || "http://localhost:8086",
|
|
35
|
+
url: s || "http://localhost:8081",
|
|
36
|
+
height: d || "800px",
|
|
37
|
+
basicHeight: o,
|
|
38
|
+
newWindow: c || !0
|
|
39
|
+
},
|
|
40
|
+
n || "http://localhost:8086"
|
|
41
|
+
), y(), window.addEventListener("scroll", (P) => {
|
|
42
|
+
y();
|
|
24
43
|
});
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
}), window.addEventListener("message", function(e) {
|
|
45
|
+
console.log("message", e), console.log(
|
|
46
|
+
"plugin Fetch iframe:",
|
|
47
|
+
e.data.height,
|
|
48
|
+
e.data.footerHeight
|
|
49
|
+
), e.data && (e.data.height && h(e.data.height || o), e.data.footerHeight && F(e.data.footerHeight));
|
|
50
|
+
});
|
|
51
|
+
}, []);
|
|
52
|
+
const H = () => (document.scrollingElement || document.documentElement).scrollTop, y = () => {
|
|
53
|
+
var t = H();
|
|
54
|
+
t > Number(a.replace("px", "")) ? i.current = !0 : i.current = !1, D(i.current);
|
|
55
|
+
};
|
|
56
|
+
return E(() => {
|
|
57
|
+
console.log("isScroll", i.current), (r == "footer" ? document.getElementById("iframeFooter") : document.getElementById("iframePlugin")).contentWindow.postMessage(
|
|
58
|
+
{
|
|
59
|
+
currentDomain: g || window.location.origin,
|
|
60
|
+
iframeDomain: n || "http://localhost:8086",
|
|
61
|
+
url: s || "http://localhost:8081",
|
|
62
|
+
height: d || "800px",
|
|
63
|
+
basicHeight: o,
|
|
64
|
+
newWindow: c || !0,
|
|
65
|
+
isScroll: i.current
|
|
66
|
+
},
|
|
67
|
+
n || "http://localhost:8086"
|
|
68
|
+
);
|
|
69
|
+
}, [I]), /* @__PURE__ */ l(b, { children: /* @__PURE__ */ B(
|
|
70
|
+
"div",
|
|
40
71
|
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
style: {
|
|
73
|
+
width: "100%",
|
|
74
|
+
position: "relative",
|
|
75
|
+
zIndex: f || 999,
|
|
76
|
+
paddingBottom: r === "footer" ? "0px" : "250px"
|
|
77
|
+
},
|
|
78
|
+
children: [
|
|
79
|
+
/* @__PURE__ */ l(
|
|
80
|
+
"div",
|
|
81
|
+
{
|
|
82
|
+
style: {
|
|
83
|
+
position: "absolute",
|
|
84
|
+
left: "30%",
|
|
85
|
+
top: 0,
|
|
86
|
+
color: "white",
|
|
87
|
+
zIndex: f || 999
|
|
88
|
+
},
|
|
89
|
+
children: r === "footer" ? u : a
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
r === "footer" ? /* @__PURE__ */ l(
|
|
93
|
+
"iframe",
|
|
94
|
+
{
|
|
95
|
+
id: "iframeFooter",
|
|
96
|
+
src: p,
|
|
97
|
+
title: w,
|
|
98
|
+
width: x,
|
|
99
|
+
height: u,
|
|
100
|
+
style: {
|
|
101
|
+
border: "none",
|
|
102
|
+
width: "100vw",
|
|
103
|
+
background: "transparent"
|
|
104
|
+
},
|
|
105
|
+
allowFullScreen: !0
|
|
106
|
+
}
|
|
107
|
+
) : /* @__PURE__ */ l(
|
|
108
|
+
"iframe",
|
|
109
|
+
{
|
|
110
|
+
id: "iframePlugin",
|
|
111
|
+
src: p,
|
|
112
|
+
title: w,
|
|
113
|
+
width: x,
|
|
114
|
+
height: a,
|
|
115
|
+
style: {
|
|
116
|
+
border: "none",
|
|
117
|
+
width: "100vw",
|
|
118
|
+
background: "transparent",
|
|
119
|
+
position: "fixed",
|
|
120
|
+
top: 0,
|
|
121
|
+
left: 0
|
|
122
|
+
},
|
|
123
|
+
allowFullScreen: !0
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
]
|
|
48
127
|
}
|
|
49
|
-
) })
|
|
128
|
+
) });
|
|
50
129
|
};
|
|
51
130
|
export {
|
|
52
|
-
|
|
131
|
+
T as default
|
|
53
132
|
};
|