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 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
- footerHeight="750px" //底部高度
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
 
@@ -1,4 +1,4 @@
1
- import React from 'react';
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>;
@@ -1,53 +1,132 @@
1
- import { jsx as o, Fragment as w } from "react/jsx-runtime";
2
- import { useState as b, useEffect as x } from "react";
3
- const E = (g) => {
4
- const [u, l] = b(""), { zIndex: f, footerHeight: i, newWindow: s, url: c, basicHeight: e, iframeDomain: n, currentDomain: p, types: D, src: d, title: h, width: m, height: r } = g;
5
- return x(
6
- () => {
7
- const a = document.getElementById("iframePlugin");
8
- console.log(87878787, a.contentWindow, p, n, c, r, e, s), a.addEventListener("load", function() {
9
- console.log("currentDomain────────────", e), l(e || "250px");
10
- const t = window.location.origin;
11
- t && a.contentWindow.postMessage(
12
- {
13
- currentDomain: t || "http://localhost:8081",
14
- iframeDomain: n || "http://localhost:8086",
15
- url: c || "http://localhost:8081",
16
- height: r || "800px",
17
- basicHeight: e,
18
- newWindow: s || !0
19
- },
20
- n || "http://localhost:8086"
21
- );
22
- }), window.addEventListener("message", function(t) {
23
- console.log(123123123123, t), console.log("Fetch iframe:", t.data.height), t.data && l(t.data.height);
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
- ), /* @__PURE__ */ o(w, { children: /* @__PURE__ */ o("div", { style: { width: "100%", position: "relative", paddingBottom: "250px", zIndex: f }, children: i ? /* @__PURE__ */ o(
28
- "iframe",
29
- {
30
- id: "iframeFooter",
31
- src: d,
32
- title: h,
33
- width: m,
34
- height: i,
35
- style: { border: "none", height: i, width: "100vw", background: "transparent", position: "absolute" },
36
- allowFullScreen: !0
37
- }
38
- ) : /* @__PURE__ */ o(
39
- "iframe",
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
- id: "iframePlugin",
42
- src: d,
43
- title: h,
44
- width: m,
45
- height: r,
46
- style: { border: "none", height: u, width: "100vw", background: "transparent", position: "absolute" },
47
- allowFullScreen: !0
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
- E as default
131
+ T as default
53
132
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-iframe-plugin",
3
3
  "private": false,
4
- "version": "0.0.20",
4
+ "version": "0.1.0",
5
5
  "scripts": {
6
6
  "dev": "vite",
7
7
  "lint": "eslint .",