samandesk 1.0.7 → 1.0.8

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