samandesk 1.1.2 → 1.2.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.
@@ -79,7 +79,7 @@ function handleEvents(interoperation) {
79
79
  const data = event.data;
80
80
  const id = data.id;
81
81
  const run2 = getRun();
82
- if (id in run2.promises) {
82
+ if (id in run2.promises && run2.promises[id]) {
83
83
  run2.promises[id](data);
84
84
  delete run2.promises[id];
85
85
  } else if (!handledByInterOperation) {
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SamanDesk={})}(this,(function(e){"use strict";let t;const o=document.createElement("iframe");let n,i,s,a=e=>window.open(e,"_blank","noopener");const d=document.createElement("div"),l={count:0,promises:{}};function r(){o.src=""}function c(e){o.src=e}function p(){return o}function m(){return d}const g=new Event("ready"),h=new Event("open"),f=new Event("close"),u=new Event("guest-ready");function y(e){window.addEventListener("message",(t=>{if(!t.data.from||"SamanDesk"!==t.data.from)return;let o=!1;console.log(`message from (${t.origin})`,t);try{e[t.data.action](t.data),o=!0}catch(a){console.error("error while run event action")}const n=t.data,i=n.id,s=l;i in s.promises?(s.promises[i](n),delete s.promises[i]):o||console.error("Message from outside of frame is invalid")}))}class v{async init(){y(this)}setToken(e){var o;o=e.data.token,t=o,r(),window.dispatchEvent(g)}close(){r();const e=m();document.body.removeChild(e),e.onclick=null,document.body.removeChild(p()),window.dispatchEvent(f)}getConfig(e){const t={theme:n,color:i},o={language:s};!function(e,t,o){var n;const i={from:"SamanDesk",action:o,data:t,id:e};null==(n=p().contentWindow)||n.postMessage(i,"*")}(e.id,{color:t.color,theme:t.theme,language:o.language},e.action)}openLink(e){a(e.data.link)}setGuestReadyEvent(){window.dispatchEvent(u)}}const w="https://samandesk.com";e.SamanDesk=class{async init(e,t){this.interoperation=new v,this.interoperation.init();const o=p(),d=m();var l,r,g;l={darkMode:e.theme.darkMode??"light",color:e.theme.color??"default"},n=l.darkMode,i=l.color,r=e.language??"fa",s=r,(g=e.linkHandler)&&(a=g),this.config=e,t?(c(`${w}/setup-interoperation/${t}`),o.width="0",o.style.width="0"):(this.setStyle(),c(`${w}/guest-login/${e.workspaceID}`)),document.body.appendChild(d),document.body.appendChild(o)}setStyle(){var e,t,o,n;const i=p(),s=m();i.style.position="fixed",i.style.zIndex="1000";if(Object.assign(s.style,{position:"fixed",top:"0",bottom:"0",left:"0",right:"0",backgroundColor:"rgba(0,0,0,0.5)",zIndex:"1000"}),this.config.fullScreen){const s=((null==(e=this.config.style)?void 0:e.marginTop)??0)+((null==(t=this.config.style)?void 0:t.marginBottom)??0);Object.assign(i.style,{bottom:(null==(o=this.config.style)?void 0:o.marginBottom)?`${this.config.style.marginBottom.toString()}px`:"0",left:"0",top:(null==(n=this.config.style)?void 0:n.marginTop)?`${this.config.style.marginTop.toString()}px`:"0",right:"0",width:"100%",height:`calc(100% - ${s}px)`})}else Object.assign(i.style,{top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"100%",maxWidth:"500px",boxShadow:"0px 0px 100px 0px rgba(0,0,0,0.48)",borderRadius:"24px",height:"100%",maxHeight:"660px"});document.body.appendChild(s),document.body.appendChild(i),s.onclick=()=>{this.close()}}open(e){const o=e||`${w}/department-selection?token=${t}`;this.setStyle(),c(o),window.dispatchEvent(h)}close(){var e;null==(e=this.interoperation)||e.close()}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SamanDesk={})}(this,(function(e){"use strict";let t;const o=document.createElement("iframe");let n,i,s,a=e=>window.open(e,"_blank","noopener");const d=document.createElement("div"),l={count:0,promises:{}};function r(){o.src=""}function c(e){o.src=e}function p(){return o}function m(){return d}const g=new Event("ready"),h=new Event("open"),f=new Event("close"),u=new Event("guest-ready");function y(e){window.addEventListener("message",(t=>{if(!t.data.from||"SamanDesk"!==t.data.from)return;let o=!1;console.log(`message from (${t.origin})`,t);try{e[t.data.action](t.data),o=!0}catch(a){console.error("error while run event action")}const n=t.data,i=n.id,s=l;i in s.promises&&s.promises[i]?(s.promises[i](n),delete s.promises[i]):o||console.error("Message from outside of frame is invalid")}))}class v{async init(){y(this)}setToken(e){var o;o=e.data.token,t=o,r(),window.dispatchEvent(g)}close(){r();const e=m();document.body.removeChild(e),e.onclick=null,document.body.removeChild(p()),window.dispatchEvent(f)}getConfig(e){const t={theme:n,color:i},o={language:s};!function(e,t,o){var n;const i={from:"SamanDesk",action:o,data:t,id:e};null==(n=p().contentWindow)||n.postMessage(i,"*")}(e.id,{color:t.color,theme:t.theme,language:o.language},e.action)}openLink(e){a(e.data.link)}setGuestReadyEvent(){window.dispatchEvent(u)}}const w="https://samandesk.com";e.SamanDesk=class{async init(e,t){this.interoperation=new v,this.interoperation.init();const o=p(),d=m();var l,r,g;l={darkMode:e.theme.darkMode??"light",color:e.theme.color??"default"},n=l.darkMode,i=l.color,r=e.language??"fa",s=r,(g=e.linkHandler)&&(a=g),this.config=e,t?(c(`${w}/setup-interoperation/${t}`),o.width="0",o.style.width="0"):(this.setStyle(),c(`${w}/guest-login/${e.workspaceID}`)),document.body.appendChild(d),document.body.appendChild(o)}setStyle(){var e,t,o,n;const i=p(),s=m();i.style.position="fixed",i.style.zIndex="1000";if(Object.assign(s.style,{position:"fixed",top:"0",bottom:"0",left:"0",right:"0",backgroundColor:"rgba(0,0,0,0.5)",zIndex:"1000"}),this.config.fullScreen){const s=((null==(e=this.config.style)?void 0:e.marginTop)??0)+((null==(t=this.config.style)?void 0:t.marginBottom)??0);Object.assign(i.style,{bottom:(null==(o=this.config.style)?void 0:o.marginBottom)?`${this.config.style.marginBottom.toString()}px`:"0",left:"0",top:(null==(n=this.config.style)?void 0:n.marginTop)?`${this.config.style.marginTop.toString()}px`:"0",right:"0",width:"100%",height:`calc(100% - ${s}px)`})}else Object.assign(i.style,{top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"100%",maxWidth:"500px",boxShadow:"0px 0px 100px 0px rgba(0,0,0,0.48)",borderRadius:"24px",height:"100%",maxHeight:"660px"});document.body.appendChild(s),document.body.appendChild(i),s.onclick=()=>{this.close()}}open(e){const o=e||`${w}/department-selection?token=${t}`;this.setStyle(),c(o),window.dispatchEvent(h)}close(){var e;null==(e=this.interoperation)||e.close()}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samandesk",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [