samandesk 1.0.7 → 1.0.9

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/dist/events.d.ts CHANGED
@@ -3,6 +3,14 @@ import { InterOperation } from './interoperation';
3
3
  * ایونت آماده‌شدن توکن را بر می‌گرداند
4
4
  */
5
5
  export declare function getReadyEvent(): Event;
6
+ /**
7
+ * ایونت بازشدن کتابخانه را بر می‌گرداند
8
+ */
9
+ export declare function getOpenEvent(): Event;
10
+ /**
11
+ * ایونت بسته‌شدن کتابخانه را بر می‌گرداند
12
+ */
13
+ export declare function getCloseEvent(): Event;
6
14
  /**
7
15
  * ⁧eventهایی که از بیرون به داخل می‌ایند را اعتبار سنجی و سپس کار خواسته شده را انجام می‌دهد
8
16
  */
package/dist/index.d.ts CHANGED
@@ -1,15 +1,32 @@
1
+ export interface OpenConfig {
2
+ /**
3
+ * اگر لینک مستقیما از بیرون آمده باشد همان را باز می‌کند
4
+ * این اتفاق در شرایطی رخ می‌دهد که میزبان می‌خواهد از لینکی که در اختیارش قرار گرفته است مستقیما استفاده کند
5
+ * اگر لینک را در ورودی ارسال نکند، خودکار به صفحه‌ی انتخاب دپارتمان می‌رویم و ادامه‌ی کار توسط سامان دسک صورت می‌گیرد
6
+ */
7
+ link?: string;
8
+ /**
9
+ * کتابخانه به صورت تمام صفحه باز شود یا خیر
10
+ *
11
+ * اگر تمام صفحه شود، از اطراف هیچ فضای خالی‌ای وجود نخواهد داشت و در غیر اینصورت، در وسط صفحه قرار خواهدگرفت
12
+ * ⁧در این حالت یک overlay پشت کتابخانه قرار خواهد گرفت
13
+ */
14
+ fullScreen: boolean;
15
+ }
1
16
  export declare class SamanDesk {
2
17
  /**
3
18
  * ⁧این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token‌ را دریافت و سپس آن را ذخیره می‌کند
4
19
  */
5
20
  init(verifiedToken: string): Promise<void>;
6
- /** استایل مربوط به آیفریم را تنظیم می‌کند */
21
+ /**
22
+ * استایل مربوط به آیفریم را تنظیم می‌کند
23
+ *
24
+ * @param fullScreen - تمام صفحه باز شود یا خیر
25
+ *
26
+ */
7
27
  private setStyle;
8
28
  /**
9
29
  * این تابع آیفریم را باز می‌کند.
10
- * اگر لینک مستقیما از بیرون آمده باشد همان را باز می‌کند
11
- * این اتفاق در شرایطی رخ می‌دهد که میزبان می‌خواهد از لینکی که در اختیارش قرار گرفته است مستقیما استفاده کند
12
- * اگر لینک را در ورودی ارسال نکند، خودکار به صفحه‌ی انتخاب دپارتمان می‌رویم و ادامه‌ی کار توسط سامان دسک صورت می‌گیرد
13
30
  */
14
- open(link?: string): void;
31
+ open(config: OpenConfig): void;
15
32
  }
@@ -11,4 +11,6 @@ export declare class InterOperation {
11
11
  init(): Promise<void>;
12
12
  /** توکن را از میزبان دریافت کرده و آن را ذخیره می‌کند. سپس به میزبان اعلام می‌کند که آماده‌ی ادامه‌ی کار است */
13
13
  setToken(data: any): void;
14
+ /** بستن کتابخانه */
15
+ close(): void;
14
16
  }
@@ -1,79 +1,106 @@
1
- let d;
2
- const i = document.createElement("iframe"), l = {
1
+ let l;
2
+ const a = document.createElement("iframe"), m = {
3
3
  count: 0,
4
4
  promises: {}
5
5
  };
6
- function m() {
7
- return l;
6
+ function p() {
7
+ return m;
8
8
  }
9
- function p(t) {
10
- d = t;
9
+ function u(n) {
10
+ l = n;
11
11
  }
12
12
  function f() {
13
- return d;
13
+ return l;
14
14
  }
15
- function u() {
16
- i.src = "";
15
+ function c() {
16
+ a.src = "";
17
17
  }
18
- function c(t) {
19
- i.src = t;
18
+ function d(n) {
19
+ a.src = n;
20
20
  }
21
- function a() {
22
- return i;
21
+ function s() {
22
+ return a;
23
23
  }
24
- const h = new Event("ready");
24
+ const h = new Event("ready"), g = new Event("open"), w = new Event("close");
25
25
  function y() {
26
26
  return h;
27
27
  }
28
- function x(t) {
28
+ function E() {
29
+ return g;
30
+ }
31
+ function x() {
32
+ return w;
33
+ }
34
+ function k(n) {
29
35
  window.addEventListener("message", (e) => {
30
36
  if (!e.data.from || e.data.from !== "SamanDesk")
31
37
  return;
32
- let o = !1;
38
+ let t = !1;
33
39
  console.log(`message from (${e.origin})`, e);
34
40
  try {
35
- t[e.data.action](e.data.data), o = !0;
41
+ n[e.data.action](e.data.data), t = !0;
36
42
  } catch {
37
43
  console.error("error while run event action");
38
44
  }
39
- const n = e.data, s = n.id, r = m();
40
- s in r.promises ? (r.promises[s](n), delete r.promises[s]) : o || console.error("Message from outside of frame is invalid");
45
+ const o = e.data, r = o.id, i = p();
46
+ r in i.promises ? (i.promises[r](o), delete i.promises[r]) : t || console.error("Message from outside of frame is invalid");
41
47
  });
42
48
  }
43
- class g {
49
+ class v {
44
50
  async init() {
45
- x(this);
51
+ k(this);
46
52
  }
47
53
  /** توکن را از میزبان دریافت کرده و آن را ذخیره می‌کند. سپس به میزبان اعلام می‌کند که آماده‌ی ادامه‌ی کار است */
48
54
  setToken(e) {
49
- p(e.token), u(), window.dispatchEvent(y());
55
+ u(e.token), c(), window.dispatchEvent(y());
56
+ }
57
+ /** بستن کتابخانه */
58
+ close() {
59
+ c(), document.body.removeChild(s()), window.dispatchEvent(x());
50
60
  }
51
61
  }
52
- class k {
62
+ class S {
53
63
  /**
54
64
  * ⁧این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token‌ را دریافت و سپس آن را ذخیره می‌کند
55
65
  */
56
66
  async init(e) {
57
- new g().init();
58
- const n = a();
59
- c(`https://samandesk.com/setup-interoperation/${e}`), n.width = "0", document.body.appendChild(n);
67
+ new v().init();
68
+ const o = s();
69
+ d(`https://samandesk.com/setup-interoperation/${e}`), o.width = "0", document.body.appendChild(o);
60
70
  }
61
- /** استایل مربوط به آیفریم را تنظیم می‌کند */
62
- setStyle() {
63
- const e = a();
64
- e.style.position = "fixed", e.style.bottom = "12px", e.style.left = "12px", e.style.boxShadow = "0px 0px 100px 0px rgba(0,0,0,0.48)", e.style.maxWidth = "500px", e.style.width = "100%", e.style.maxHeight = "640px", e.style.height = "100%", e.style.zIndex = "1000", e.style.borderRadius = "24px", e.width = "500px", e.height = "640px";
71
+ /**
72
+ * استایل مربوط به آیفریم را تنظیم می‌کند
73
+ *
74
+ * @param fullScreen - تمام صفحه باز شود یا خیر
75
+ *
76
+ */
77
+ setStyle(e) {
78
+ const t = s();
79
+ t.style.position = "fixed", t.style.zIndex = "1000", e ? (Object.assign(t.style, {
80
+ bottom: "0",
81
+ left: "0",
82
+ top: "0",
83
+ right: "0"
84
+ }), t.width = "100%", t.height = "100%") : Object.assign(t.style, {
85
+ top: "50%",
86
+ left: "50%",
87
+ transform: "translate(-50%, -50%)",
88
+ width: "100%",
89
+ maxWidth: "450px",
90
+ boxShadow: "0px 0px 100px 0px rgba(0,0,0,0.48)",
91
+ borderRadius: "24px",
92
+ height: "100%",
93
+ maxHeight: "660px"
94
+ });
65
95
  }
66
96
  /**
67
97
  * این تابع آیفریم را باز می‌کند.
68
- * اگر لینک مستقیما از بیرون آمده باشد همان را باز می‌کند
69
- * این اتفاق در شرایطی رخ می‌دهد که میزبان می‌خواهد از لینکی که در اختیارش قرار گرفته است مستقیما استفاده کند
70
- * اگر لینک را در ورودی ارسال نکند، خودکار به صفحه‌ی انتخاب دپارتمان می‌رویم و ادامه‌ی کار توسط سامان دسک صورت می‌گیرد
71
98
  */
72
99
  open(e) {
73
- const o = a(), n = e || `https://samandesk.com/department-selection?token=${f()}`;
74
- c(n), this.setStyle(), document.body.appendChild(o);
100
+ const t = s(), o = e.link || `https://samandesk.com/department-selection?token=${f()}`;
101
+ d(o), this.setStyle(e.fullScreen), document.body.appendChild(t), window.dispatchEvent(E());
75
102
  }
76
103
  }
77
104
  export {
78
- k as SamanDesk
105
+ S as SamanDesk
79
106
  };
@@ -1 +1 @@
1
- (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.SamanDesk={}))})(this,function(o){"use strict";let s;const r=document.createElement("iframe"),m={count:0,promises:{}};function p(){return m}function f(t){s=t}function u(){return s}function y(){r.src=""}function l(t){r.src=t}function a(){return r}const h=new Event("ready");function x(){return h}function g(t){window.addEventListener("message",e=>{if(!e.data.from||e.data.from!=="SamanDesk")return;let i=!1;console.log(`message from (${e.origin})`,e);try{t[e.data.action](e.data.data),i=!0}catch{console.error("error while run event action")}const n=e.data,d=n.id,c=p();d in c.promises?(c.promises[d](n),delete c.promises[d]):i||console.error("Message from outside of frame is invalid")})}class k{async init(){g(this)}setToken(e){f(e.token),y(),window.dispatchEvent(x())}}class w{async init(e){new k().init();const n=a();l(`https://samandesk.com/setup-interoperation/${e}`),n.width="0",document.body.appendChild(n)}setStyle(){const e=a();e.style.position="fixed",e.style.bottom="12px",e.style.left="12px",e.style.boxShadow="0px 0px 100px 0px rgba(0,0,0,0.48)",e.style.maxWidth="500px",e.style.width="100%",e.style.maxHeight="640px",e.style.height="100%",e.style.zIndex="1000",e.style.borderRadius="24px",e.width="500px",e.height="640px"}open(e){const i=a(),n=e||`https://samandesk.com/department-selection?token=${u()}`;l(n),this.setStyle(),document.body.appendChild(i)}}o.SamanDesk=w,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s.SamanDesk={}))})(this,function(s){"use strict";let i;const a=document.createElement("iframe"),m={count:0,promises:{}};function p(){return m}function u(n){i=n}function h(){return i}function l(){a.src=""}function f(n){a.src=n}function r(){return a}const y=new Event("ready"),g=new Event("open"),w=new Event("close");function E(){return y}function x(){return g}function k(){return w}function b(n){window.addEventListener("message",e=>{if(!e.data.from||e.data.from!=="SamanDesk")return;let t=!1;console.log(`message from (${e.origin})`,e);try{n[e.data.action](e.data.data),t=!0}catch{console.error("error while run event action")}const o=e.data,d=o.id,c=p();d in c.promises?(c.promises[d](o),delete c.promises[d]):t||console.error("Message from outside of frame is invalid")})}class v{async init(){b(this)}setToken(e){u(e.token),l(),window.dispatchEvent(E())}close(){l(),document.body.removeChild(r()),window.dispatchEvent(k())}}class S{async init(e){new v().init();const o=r();f(`https://samandesk.com/setup-interoperation/${e}`),o.width="0",document.body.appendChild(o)}setStyle(e){const t=r();t.style.position="fixed",t.style.zIndex="1000",e?(Object.assign(t.style,{bottom:"0",left:"0",top:"0",right:"0"}),t.width="100%",t.height="100%"):Object.assign(t.style,{top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"100%",maxWidth:"450px",boxShadow:"0px 0px 100px 0px rgba(0,0,0,0.48)",borderRadius:"24px",height:"100%",maxHeight:"660px"})}open(e){const t=r(),o=e.link||`https://samandesk.com/department-selection?token=${h()}`;f(o),this.setStyle(e.fullScreen),document.body.appendChild(t),window.dispatchEvent(x())}}s.SamanDesk=S,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samandesk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [