qlfy-postmate 1.1.6 → 1.1.7

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
@@ -191,7 +191,7 @@ new ChildPostmate({
191
191
  },
192
192
 
193
193
  // 异步方法
194
- receive: async (dataInfo) => {
194
+ receive: (dataInfo) => {
195
195
  console.log('-----------------接收数据-----------------')
196
196
  console.log(dataInfo)
197
197
  if (dataInfo.status !== 200) return
package/lib/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- var f = Object.defineProperty;
2
- var g = (r, t, e) => t in r ? f(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
1
+ var p = Object.defineProperty;
2
+ var g = (r, t, e) => t in r ? p(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
3
  var l = (r, t, e) => g(r, typeof t != "symbol" ? t + "" : t, e);
4
4
  const h = "application/x-postmate-v1+json";
5
5
  let y = 0;
6
- const P = {
6
+ const w = {
7
7
  handshake: 1,
8
8
  "handshake-reply": 1,
9
9
  call: 1,
@@ -11,23 +11,23 @@ const P = {
11
11
  reply: 1,
12
12
  request: 1
13
13
  };
14
- function p(r, t) {
15
- return (typeof t != "string" || r.origin === t) && !!r.data && (typeof r.data != "object" || "postmate" in r.data) && r.data.type === h && !!P[r.data.postmate];
14
+ function f(r, t) {
15
+ return (typeof t != "string" || r.origin === t) && !!r.data && (typeof r.data != "object" || "postmate" in r.data) && r.data.type === h && !!w[r.data.postmate];
16
16
  }
17
- class w {
17
+ class P {
18
18
  constructor(t) {
19
19
  this.parent = t.parent, this.frame = t.frame, this.child = t.child, this.childOrigin = t.childOrigin, this.events = {}, this.listener = (e) => {
20
- if (!p(e, this.childOrigin)) return;
21
- const { value: s = {} } = e.data, { name: a, data: i } = s;
22
- e.data.postmate === "emit" && a in this.events && this.events[a].call(this, i);
20
+ if (!f(e, this.childOrigin)) return;
21
+ const { value: s = {} } = e.data, { name: i, data: a } = s;
22
+ e.data.postmate === "emit" && i in this.events && this.events[i].call(this, a);
23
23
  }, this.parent.addEventListener("message", this.listener, !1);
24
24
  }
25
25
  get(t) {
26
26
  return new o.Promise((e) => {
27
- const s = ++y, a = (i) => {
28
- i.data.uid === s && i.data.postmate === "reply" && (this.parent.removeEventListener("message", a, !1), e(i.data.value));
27
+ const s = ++y, i = (a) => {
28
+ a.data.uid === s && a.data.postmate === "reply" && (this.parent.removeEventListener("message", i, !1), e(a.data.value));
29
29
  };
30
- this.parent.addEventListener("message", a, !1), this.child.postMessage(
30
+ this.parent.addEventListener("message", i, !1), this.child.postMessage(
31
31
  {
32
32
  postmate: "request",
33
33
  type: h,
@@ -59,23 +59,23 @@ class w {
59
59
  class E {
60
60
  constructor(t) {
61
61
  this.model = t.model, this.parent = t.parent, this.parentOrigin = t.parentOrigin, this.child = t.child, this.child.addEventListener("message", (e) => {
62
- if (!p(e, this.parentOrigin)) return;
63
- const { postmate: s, property: a, uid: i, data: d } = e.data, n = this.model[a];
62
+ if (!f(e, this.parentOrigin)) return;
63
+ const { postmate: s, property: i, uid: a, data: d } = e.data, n = this.model[i];
64
64
  if (s !== "call") {
65
65
  const c = typeof n == "function" ? n() : n;
66
66
  o.Promise.resolve(c).then((m) => {
67
67
  e.source.postMessage(
68
68
  {
69
- property: a,
69
+ property: i,
70
70
  postmate: "reply",
71
71
  type: h,
72
- uid: i,
72
+ uid: a,
73
73
  value: m
74
74
  },
75
75
  e.origin
76
76
  );
77
77
  });
78
- } else a in this.model && typeof n == "function" && n(d);
78
+ } else i in this.model && typeof n == "function" && n(d);
79
79
  });
80
80
  }
81
81
  emit(t, e) {
@@ -90,21 +90,21 @@ class E {
90
90
  }
91
91
  }
92
92
  class o {
93
- constructor({ container: t = document.body, model: e, url: s, name: a, classListArray: i = [] }) {
94
- return this.parent = window, this.frame = document.createElement("iframe"), this.frame.name = a || "", this.frame.classList.add(...i), t.appendChild(this.frame), this.child = this.frame.contentWindow, this.model = e || {}, this.sendHandshake(s);
93
+ constructor({ container: t = document.body, model: e, url: s, name: i, classListArray: a = [] }) {
94
+ return this.parent = window, this.frame = document.createElement("iframe"), this.frame.name = i || "", this.frame.classList.add(...a), t.appendChild(this.frame), this.child = this.frame.contentWindow, this.model = e || {}, this.sendHandshake(s);
95
95
  }
96
96
  sendHandshake(t) {
97
97
  const e = (() => {
98
- const i = document.createElement("a");
99
- i.href = t;
100
- const d = i.protocol.length > 4 ? i.protocol : window.location.protocol, n = i.host.length ? i.port === "80" || i.port === "443" ? i.hostname : i.host : window.location.host;
101
- return i.origin || `${d}//${n}`;
98
+ const a = document.createElement("a");
99
+ a.href = t;
100
+ const d = a.protocol.length > 4 ? a.protocol : window.location.protocol, n = a.host.length ? a.port === "80" || a.port === "443" ? a.hostname : a.host : window.location.host;
101
+ return a.origin || `${d}//${n}`;
102
102
  })();
103
- let s = 0, a;
104
- return new o.Promise((i, d) => {
103
+ let s = 0, i;
104
+ return new o.Promise((a, d) => {
105
105
  const n = (u) => {
106
- if (!p(u, e)) return !1;
107
- u.data.postmate === "handshake-reply" ? (clearInterval(a), this.parent.removeEventListener("message", n, !1), this.childOrigin = u.origin, i(new w(this))) : d("Failed handshake");
106
+ if (!f(u, e)) return !1;
107
+ u.data.postmate === "handshake-reply" ? (clearInterval(i), this.parent.removeEventListener("message", n, !1), this.childOrigin = u.origin, a(new P(this))) : d("Failed handshake");
108
108
  };
109
109
  this.parent.addEventListener("message", n, !1);
110
110
  const c = () => {
@@ -115,9 +115,9 @@ class o {
115
115
  model: this.model
116
116
  },
117
117
  e
118
- ), s === 5 && clearInterval(a);
118
+ ), s === 5 && clearInterval(i);
119
119
  }, m = () => {
120
- c(), a = setInterval(c, 500);
120
+ c(), i = setInterval(c, 500);
121
121
  };
122
122
  this.frame.onload = m, this.frame.attachEvent && this.frame.attachEvent("onload", m), this.frame.src = t;
123
123
  });
@@ -139,9 +139,9 @@ class I {
139
139
  },
140
140
  s.origin
141
141
  ), this.parentOrigin = s.origin;
142
- const a = s.data.model;
143
- a && Object.keys(a).forEach((i) => {
144
- this.model[i] = a[i];
142
+ const i = s.data.model;
143
+ i && Object.keys(i).forEach((a) => {
144
+ this.model[a] = i[a];
145
145
  }), t(new E(this));
146
146
  }
147
147
  }, !1);
@@ -239,14 +239,14 @@ class v {
239
239
  container: e,
240
240
  url: this.currentUrl
241
241
  });
242
- this.currentIframe = e.querySelector("iframe"), this.currentIframe.addEventListener("load", () => {
242
+ this.currentIframe = e.querySelector("iframe"), this.currentIframe.setAttribute("frameborder", "0"), this.currentIframe.setAttribute("allow", "fullscreen"), this.currentIframe.addEventListener("load", () => {
243
243
  this.loadFunction();
244
- }), s.then((a) => {
245
- console.log("parent", a), this.postmateParent = a, a.on("requestBaseData", (i) => {
244
+ }), s.then((i) => {
245
+ this.postmateParent = i, i.on("requestBaseData", (a) => {
246
246
  this.sendData();
247
247
  }), typeof t == "function" && t();
248
- }).catch((a) => {
249
- console.error("Postmate 连接失败:", a);
248
+ }).catch((i) => {
249
+ console.error("Postmate 连接失败:", i);
250
250
  });
251
251
  }
252
252
  /** 设置load执行事件 */
package/lib/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(n,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(n=typeof globalThis<"u"?globalThis:n||self,r(n["qlfy-postmate"]={}))})(this,function(n){"use strict";var k=Object.defineProperty;var v=(n,r,c)=>r in n?k(n,r,{enumerable:!0,configurable:!0,writable:!0,value:c}):n[r]=c;var d=(n,r,c)=>v(n,typeof r!="symbol"?r+"":r,c);const r="application/x-postmate-v1+json";let c=0;const y={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1};function p(o,t){return(typeof t!="string"||o.origin===t)&&!!o.data&&(typeof o.data!="object"||"postmate"in o.data)&&o.data.type===r&&!!y[o.data.postmate]}class P{constructor(t){this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=e=>{if(!p(e,this.childOrigin))return;const{value:s={}}=e.data,{name:a,data:i}=s;e.data.postmate==="emit"&&a in this.events&&this.events[a].call(this,i)},this.parent.addEventListener("message",this.listener,!1)}get(t){return new l.Promise(e=>{const s=++c,a=i=>{i.data.uid===s&&i.data.postmate==="reply"&&(this.parent.removeEventListener("message",a,!1),e(i.data.value))};this.parent.addEventListener("message",a,!1),this.child.postMessage({postmate:"request",type:r,property:t,uid:s},this.childOrigin)})}call(t,e){this.child.postMessage({postmate:"call",type:r,property:t,data:e},this.childOrigin)}on(t,e){this.events[t]=e}destroy(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)}}class w{constructor(t){this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",e=>{if(!p(e,this.parentOrigin))return;const{postmate:s,property:a,uid:i,data:m}=e.data,h=this.model[a];if(s!=="call"){const u=typeof h=="function"?h():h;l.Promise.resolve(u).then(f=>{e.source.postMessage({property:a,postmate:"reply",type:r,uid:i,value:f},e.origin)})}else a in this.model&&typeof h=="function"&&h(m)})}emit(t,e){this.parent.postMessage({postmate:"emit",type:r,value:{name:t,data:e}},this.parentOrigin)}}class l{constructor({container:t=document.body,model:e,url:s,name:a,classListArray:i=[]}){return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=a||"",this.frame.classList.add(...i),t.appendChild(this.frame),this.child=this.frame.contentWindow,this.model=e||{},this.sendHandshake(s)}sendHandshake(t){const e=(()=>{const i=document.createElement("a");i.href=t;const m=i.protocol.length>4?i.protocol:window.location.protocol,h=i.host.length?i.port==="80"||i.port==="443"?i.hostname:i.host:window.location.host;return i.origin||`${m}//${h}`})();let s=0,a;return new l.Promise((i,m)=>{const h=g=>{if(!p(g,e))return!1;g.data.postmate==="handshake-reply"?(clearInterval(a),this.parent.removeEventListener("message",h,!1),this.childOrigin=g.origin,i(new P(this))):m("Failed handshake")};this.parent.addEventListener("message",h,!1);const u=()=>{s++,this.child.postMessage({postmate:"handshake",type:r,model:this.model},e),s===5&&clearInterval(a)},f=()=>{u(),a=setInterval(u,500)};this.frame.onload=f,this.frame.attachEvent&&this.frame.attachEvent("onload",f),this.frame.src=t})}}class E{constructor(t){return this.child=window,this.model=t,this.parent=window.parent,this.sendHandshakeReply()}sendHandshakeReply(){return new l.Promise((t,e)=>{this.child.addEventListener("message",s=>{if(s.data.postmate){if(s.data.postmate!=="handshake")return e("Handshake Reply Failed");this.child.removeEventListener("message",this,!1),s.source.postMessage({postmate:"handshake-reply",type:r},s.origin),this.parentOrigin=s.origin;const a=s.data.model;a&&Object.keys(a).forEach(i=>{this.model[i]=a[i]}),t(new w(this))}},!1)})}}l.debug=!1,l.Promise=(()=>{try{return typeof window<"u"?window.Promise:Promise}catch{return Promise}})(),l.Model=E;class I{constructor(t){this.childPostmate=null,this.parentPostmate=null,this.isGetData=!1,this.getDataCllBack=null,window.top!==window.self?this.init(t):t.error({status:500,data:null,message:"未在一体化平台中运行"})}init(t){const e=this;this.childPostmate=new l.Model({baseData(s){s=JSON.parse(s),e.isGetData?e.getDataCllBack&&e.getDataCllBack({status:200,message:"success",data:s}):t.receive({status:200,message:"success",data:s}),e.isGetData=!1}}).then(s=>{e.parentPostmate=s,e.getData(),t.success({status:200,message:"success",data:{ChildPostmate:s}})}).catch(s=>{t.error({status:500,data:null,message:s})})}getData(t){if(!this.parentPostmate){t({status:500,message:"父页面未连接",data:null});return}t?(this.isGetData=!0,this.getDataCllBack=t):(this.isGetData=!1,this.getDataCllBack=null),this.parentPostmate.emit("requestBaseData")}}class D{constructor(t,e=null,s=""){d(this,"postmateParent",null);d(this,"dataInfo",{loginInfo:null,token:"",isHideHeader:!0});d(this,"iframeEle",null);d(this,"currentUrl","");d(this,"currentIframe",null);d(this,"loadFunction",null);this.dataInfo=t||this.dataInfo,this.setIframeEle(e),this.setIframeUrl(s)}clear(){this.postmateParent&&(this.postmateParent.destroy(),this.postmateParent=null),this.currentIframe&&this.currentIframe.parentNode&&this.currentIframe.parentNode.removeChild(this.currentIframe),this.currentIframe=null}async init(t=null){if(this.clear(),!this.iframeEle||!this.currentUrl){console.warn("iframeEle 和 currentUrl 是必需的");return}const e=typeof this.iframeEle=="function"?this.iframeEle():this.iframeEle;if(!e){console.warn("无法获取 iframe 容器");return}const s=new l({container:e,url:this.currentUrl});this.currentIframe=e.querySelector("iframe"),this.currentIframe.addEventListener("load",()=>{this.loadFunction()}),s.then(a=>{console.log("parent",a),this.postmateParent=a,a.on("requestBaseData",i=>{this.sendData()}),typeof t=="function"&&t()}).catch(a=>{console.error("Postmate 连接失败:",a)})}setLoadFunction(t){this.loadFunction=t}setIframeEle(t){this.iframeEle!==t&&(this.iframeEle=t,this.iframeEle&&this.currentUrl&&this.init())}setIframeUrl(t){this.currentUrl!==t&&(this.currentUrl=t,this.iframeEle&&this.currentUrl&&this.init())}sendData(){this.postmateParent&&this.postmateParent.call("baseData",JSON.stringify(this.dataInfo))}destroy(){this.clear()}}n.ChildPostmate=I,n.ParentPostmate=D,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(n,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(n=typeof globalThis<"u"?globalThis:n||self,r(n["qlfy-postmate"]={}))})(this,function(n){"use strict";var k=Object.defineProperty;var v=(n,r,c)=>r in n?k(n,r,{enumerable:!0,configurable:!0,writable:!0,value:c}):n[r]=c;var d=(n,r,c)=>v(n,typeof r!="symbol"?r+"":r,c);const r="application/x-postmate-v1+json";let c=0;const y={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1};function p(o,t){return(typeof t!="string"||o.origin===t)&&!!o.data&&(typeof o.data!="object"||"postmate"in o.data)&&o.data.type===r&&!!y[o.data.postmate]}class P{constructor(t){this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=e=>{if(!p(e,this.childOrigin))return;const{value:s={}}=e.data,{name:i,data:a}=s;e.data.postmate==="emit"&&i in this.events&&this.events[i].call(this,a)},this.parent.addEventListener("message",this.listener,!1)}get(t){return new l.Promise(e=>{const s=++c,i=a=>{a.data.uid===s&&a.data.postmate==="reply"&&(this.parent.removeEventListener("message",i,!1),e(a.data.value))};this.parent.addEventListener("message",i,!1),this.child.postMessage({postmate:"request",type:r,property:t,uid:s},this.childOrigin)})}call(t,e){this.child.postMessage({postmate:"call",type:r,property:t,data:e},this.childOrigin)}on(t,e){this.events[t]=e}destroy(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)}}class w{constructor(t){this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",e=>{if(!p(e,this.parentOrigin))return;const{postmate:s,property:i,uid:a,data:m}=e.data,h=this.model[i];if(s!=="call"){const u=typeof h=="function"?h():h;l.Promise.resolve(u).then(f=>{e.source.postMessage({property:i,postmate:"reply",type:r,uid:a,value:f},e.origin)})}else i in this.model&&typeof h=="function"&&h(m)})}emit(t,e){this.parent.postMessage({postmate:"emit",type:r,value:{name:t,data:e}},this.parentOrigin)}}class l{constructor({container:t=document.body,model:e,url:s,name:i,classListArray:a=[]}){return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=i||"",this.frame.classList.add(...a),t.appendChild(this.frame),this.child=this.frame.contentWindow,this.model=e||{},this.sendHandshake(s)}sendHandshake(t){const e=(()=>{const a=document.createElement("a");a.href=t;const m=a.protocol.length>4?a.protocol:window.location.protocol,h=a.host.length?a.port==="80"||a.port==="443"?a.hostname:a.host:window.location.host;return a.origin||`${m}//${h}`})();let s=0,i;return new l.Promise((a,m)=>{const h=g=>{if(!p(g,e))return!1;g.data.postmate==="handshake-reply"?(clearInterval(i),this.parent.removeEventListener("message",h,!1),this.childOrigin=g.origin,a(new P(this))):m("Failed handshake")};this.parent.addEventListener("message",h,!1);const u=()=>{s++,this.child.postMessage({postmate:"handshake",type:r,model:this.model},e),s===5&&clearInterval(i)},f=()=>{u(),i=setInterval(u,500)};this.frame.onload=f,this.frame.attachEvent&&this.frame.attachEvent("onload",f),this.frame.src=t})}}class E{constructor(t){return this.child=window,this.model=t,this.parent=window.parent,this.sendHandshakeReply()}sendHandshakeReply(){return new l.Promise((t,e)=>{this.child.addEventListener("message",s=>{if(s.data.postmate){if(s.data.postmate!=="handshake")return e("Handshake Reply Failed");this.child.removeEventListener("message",this,!1),s.source.postMessage({postmate:"handshake-reply",type:r},s.origin),this.parentOrigin=s.origin;const i=s.data.model;i&&Object.keys(i).forEach(a=>{this.model[a]=i[a]}),t(new w(this))}},!1)})}}l.debug=!1,l.Promise=(()=>{try{return typeof window<"u"?window.Promise:Promise}catch{return Promise}})(),l.Model=E;class I{constructor(t){this.childPostmate=null,this.parentPostmate=null,this.isGetData=!1,this.getDataCllBack=null,window.top!==window.self?this.init(t):t.error({status:500,data:null,message:"未在一体化平台中运行"})}init(t){const e=this;this.childPostmate=new l.Model({baseData(s){s=JSON.parse(s),e.isGetData?e.getDataCllBack&&e.getDataCllBack({status:200,message:"success",data:s}):t.receive({status:200,message:"success",data:s}),e.isGetData=!1}}).then(s=>{e.parentPostmate=s,e.getData(),t.success({status:200,message:"success",data:{ChildPostmate:s}})}).catch(s=>{t.error({status:500,data:null,message:s})})}getData(t){if(!this.parentPostmate){t({status:500,message:"父页面未连接",data:null});return}t?(this.isGetData=!0,this.getDataCllBack=t):(this.isGetData=!1,this.getDataCllBack=null),this.parentPostmate.emit("requestBaseData")}}class D{constructor(t,e=null,s=""){d(this,"postmateParent",null);d(this,"dataInfo",{loginInfo:null,token:"",isHideHeader:!0});d(this,"iframeEle",null);d(this,"currentUrl","");d(this,"currentIframe",null);d(this,"loadFunction",null);this.dataInfo=t||this.dataInfo,this.setIframeEle(e),this.setIframeUrl(s)}clear(){this.postmateParent&&(this.postmateParent.destroy(),this.postmateParent=null),this.currentIframe&&this.currentIframe.parentNode&&this.currentIframe.parentNode.removeChild(this.currentIframe),this.currentIframe=null}async init(t=null){if(this.clear(),!this.iframeEle||!this.currentUrl){console.warn("iframeEle 和 currentUrl 是必需的");return}const e=typeof this.iframeEle=="function"?this.iframeEle():this.iframeEle;if(!e){console.warn("无法获取 iframe 容器");return}const s=new l({container:e,url:this.currentUrl});this.currentIframe=e.querySelector("iframe"),this.currentIframe.setAttribute("frameborder","0"),this.currentIframe.setAttribute("allow","fullscreen"),this.currentIframe.addEventListener("load",()=>{this.loadFunction()}),s.then(i=>{this.postmateParent=i,i.on("requestBaseData",a=>{this.sendData()}),typeof t=="function"&&t()}).catch(i=>{console.error("Postmate 连接失败:",i)})}setLoadFunction(t){this.loadFunction=t}setIframeEle(t){this.iframeEle!==t&&(this.iframeEle=t,this.iframeEle&&this.currentUrl&&this.init())}setIframeUrl(t){this.currentUrl!==t&&(this.currentUrl=t,this.iframeEle&&this.currentUrl&&this.init())}sendData(){this.postmateParent&&this.postmateParent.call("baseData",JSON.stringify(this.dataInfo))}destroy(){this.clear()}}n.ChildPostmate=I,n.ParentPostmate=D,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qlfy-postmate",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "types": "lib/index.d.ts",
6
6
  "module": "lib/index.umd.js",